-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.html
More file actions
265 lines (248 loc) · 13.6 KB
/
Copy pathdiff.html
File metadata and controls
265 lines (248 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PR 评审 · diff 模板</title>
<!--
diff.html
用途:reviewer 视角的 PR 评审——风险地图 + 文件分组 + 行号 diff + 评论。
替换:所有 [...],数据通常由 agent 从 git diff / gh pr diff 拿到后填入。
-->
<style>
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
font-size: 16px; line-height: 1.55; color: #141413; background: #FAF9F5;
-webkit-font-smoothing: antialiased; }
:root {
--clay: #D97757; --slate: #141413; --ivory: #FAF9F5;
--white: #FFFFFF; --gray-100: #F0EEE6; --gray-300: #D1CFC5;
--gray-500: #87867F; --gray-700: #3D3D3A;
--success: #788C5D; --warning: #C78E3F; --danger: #B04A4A; --info: #5C7CA3;
--font-mono: ui-monospace, "SF Mono", Menlo, Monaco, monospace;
}
.container { max-width: 1100px; margin: 0 auto; padding: 48px 32px 96px; }
code { font-family: var(--font-mono); font-size: 0.88em;
background: var(--gray-100); padding: 2px 6px; border-radius: 4px; }
header.page { margin-bottom: 24px; padding-bottom: 16px;
border-bottom: 1px solid var(--gray-300); }
header.page h1 { font-size: 24px; font-weight: 500; margin: 0 0 8px; }
header.page p { color: var(--gray-700); margin: 0; max-width: 720px; }
/* Risk map */
.risk-map { background: var(--white); border: 1px solid var(--gray-300);
border-radius: 12px; padding: 24px; margin: 24px 0;
display: grid; grid-template-columns: 1fr auto; gap: 32px;
align-items: center; }
.risk-map svg { width: 100%; height: 140px; }
.risk-map circle.safe { fill: var(--success); }
.risk-map circle.worth-attn { fill: var(--warning); }
.risk-map circle.needs-attn { fill: var(--danger); }
.risk-map text { font-family: var(--font-mono); font-size: 11px; fill: var(--gray-700); }
.risk-map .legend { display: flex; flex-direction: column; gap: 12px;
font-size: 13px; min-width: 160px; }
.risk-map .legend > div { display: flex; align-items: center; gap: 10px; }
.risk-map .dot { width: 12px; height: 12px; border-radius: 50%; }
/* File list */
section.files { margin-top: 32px; }
section.files details {
margin-bottom: 12px; background: var(--white);
border: 1px solid var(--gray-300); border-radius: 10px; overflow: hidden;
}
section.files summary {
padding: 12px 16px; cursor: pointer; list-style: none;
display: flex; gap: 12px; align-items: center; font-size: 14px;
background: var(--gray-100); border-bottom: 1px solid transparent;
}
section.files details[open] summary { border-bottom-color: var(--gray-300); }
section.files summary::-webkit-details-marker { display: none; }
section.files summary::before { content: '▸'; color: var(--gray-500); flex-shrink: 0; }
section.files details[open] summary::before { content: '▾'; }
section.files summary code { font-size: 13px; background: none; padding: 0; flex: 1; }
.badge { padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
letter-spacing: 0.04em; }
.badge.safe { background: rgba(120,140,93,0.15); color: var(--success); }
.badge.worth-attn { background: rgba(199,142,63,0.15); color: var(--warning); }
.badge.needs-attn { background: rgba(176,74,74,0.15); color: var(--danger); }
.file-meta { color: var(--gray-500); font-family: var(--font-mono);
font-size: 12px; margin-left: 8px; }
/* Diff */
.diff { font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55;
margin: 0; padding: 0; background: none; }
.diff .line { display: grid; grid-template-columns: 56px 1fr; gap: 0; }
.diff .ln { color: var(--gray-500); padding: 0 12px; text-align: right;
background: var(--gray-100); user-select: none;
border-right: 1px solid var(--gray-300); }
.diff .content { padding: 0 12px; white-space: pre; }
.diff .added { background: rgba(120, 140, 93, 0.12); }
.diff .removed { background: rgba(176, 74, 74, 0.10); }
.diff .added .ln { background: rgba(120, 140, 93, 0.20); }
.diff .removed .ln { background: rgba(176, 74, 74, 0.15); }
.diff .hunk-header {
display: block; padding: 6px 16px; background: var(--gray-100);
color: var(--gray-700); font-size: 12px; border-bottom: 1px solid var(--gray-300);
}
/* Inline comment */
.comment {
margin: 4px 56px 4px 56px; padding: 12px 16px;
background: rgba(217, 119, 87, 0.08); border-left: 3px solid var(--clay);
border-radius: 0 8px 8px 0; font-family: var(--font-sans); font-size: 13.5px;
line-height: 1.55;
}
.comment .author { font-weight: 500; color: var(--clay); margin-bottom: 4px;
font-size: 12px; text-transform: uppercase;
letter-spacing: 0.04em; }
.file-summary { padding: 12px 16px; color: var(--gray-700); font-size: 14px;
border-bottom: 1px solid var(--gray-300);
background: var(--white); }
</style>
</head>
<body>
<div class="container">
<header class="page">
<h1>PR #[number] — [PR title, e.g. "Optimistic task updates"]</h1>
<p>[一段话总结这个 PR 做了什么,为评审者建立上下文。例如 "Replaces await-then-refetch in TaskList with optimistic cache writes; introduces useOptimisticTasks hook with snapshot+rollback. ~300ms perceived improvement."]</p>
</header>
<!-- Risk map -->
<section class="risk-map">
<svg viewBox="0 0 600 140" aria-label="File risk map">
<!-- 圆点:cx/cy 自由排列;r = 8 + log(LOC) -->
<g class="dot-group">
<circle cx="60" cy="70" r="14" class="needs-attn" />
<text x="60" y="105" text-anchor="middle">[useOptimisticTasks.ts]</text>
</g>
<g class="dot-group">
<circle cx="180" cy="70" r="20" class="worth-attn" />
<text x="180" y="105" text-anchor="middle">[TaskList.tsx]</text>
</g>
<g class="dot-group">
<circle cx="290" cy="70" r="11" class="worth-attn" />
<text x="290" y="105" text-anchor="middle">[api/tasks.ts]</text>
</g>
<g class="dot-group">
<circle cx="400" cy="70" r="9" class="safe" />
<text x="400" y="105" text-anchor="middle">[Toast.tsx]</text>
</g>
<g class="dot-group">
<circle cx="490" cy="70" r="7" class="safe" />
<text x="490" y="105" text-anchor="middle">[task.ts]</text>
</g>
<g class="dot-group">
<circle cx="560" cy="70" r="9" class="safe" />
<text x="560" y="105" text-anchor="middle">[TaskList.test.tsx]</text>
</g>
</svg>
<div class="legend">
<div><span class="dot" style="background:var(--success)"></span><span>safe — purely additive</span></div>
<div><span class="dot" style="background:var(--warning)"></span><span>worth a look — behavior shift</span></div>
<div><span class="dot" style="background:var(--danger)"></span><span>needs attention — new abstraction</span></div>
</div>
</section>
<!-- Files -->
<section class="files">
<details open>
<summary>
<code>[src/hooks/useOptimisticTasks.ts]</code>
<span class="badge needs-attn">needs attention</span>
<span class="file-meta">+58 −0</span>
</summary>
<div class="file-summary">
[一段话: agent 的判断。例如 "New hook. Snapshots cache, mutates optimistically, rolls back on error. The cache key derivation is the part most likely to drift if call sites change."]
</div>
<pre class="diff">
<span class="hunk-header">@@ -0,0 +1,20 @@</span>
<div class="line added"><span class="ln">1</span><span class="content">+import { useMutation, useQueryClient } from '@tanstack/react-query';</span></div>
<div class="line added"><span class="ln">2</span><span class="content">+import { updateTask, TaskPatch } from '../api/tasks';</span></div>
<div class="line added"><span class="ln">3</span><span class="content">+</span></div>
<div class="line added"><span class="ln">4</span><span class="content">+export function useOptimisticTasks(boardId: string) {</span></div>
<div class="line added"><span class="ln">5</span><span class="content">+ const qc = useQueryClient();</span></div>
<div class="line added"><span class="ln">6</span><span class="content">+ const key = ['tasks', boardId];</span></div>
<div class="line added"><span class="ln">7</span><span class="content">+ return useMutation({</span></div>
<div class="line added"><span class="ln">8</span><span class="content">+ mutationFn: (patch: TaskPatch) => updateTask(patch),</span></div>
<div class="line added"><span class="ln">9</span><span class="content">+ onMutate: async (patch) => {</span></div>
<div class="line added"><span class="ln">10</span><span class="content">+ const prev = qc.getQueryData(key);</span></div>
</pre>
<div class="comment">
<div class="author">Reviewer note · line 6</div>
<div>[具体评论:例如 "Cache key is hardcoded as ['tasks', boardId]. If TaskList ever uses a different key shape (e.g. nested board), this rolls back into the wrong slot. Worth either extracting a key factory or commenting the contract."]</div>
</div>
<pre class="diff">
<div class="line added"><span class="ln">11</span><span class="content">+ qc.setQueryData(key, (old = []) =></span></div>
<div class="line added"><span class="ln">12</span><span class="content">+ old.map(t => t.id === patch.id ? { ...t, ...patch } : t)</span></div>
<div class="line added"><span class="ln">13</span><span class="content">+ );</span></div>
<div class="line added"><span class="ln">14</span><span class="content">+ return { prev };</span></div>
<div class="line added"><span class="ln">15</span><span class="content">+ },</span></div>
<div class="line added"><span class="ln">16</span><span class="content">+ onError: (_e, _p, ctx) => qc.setQueryData(key, ctx?.prev),</span></div>
<div class="line added"><span class="ln">17</span><span class="content">+ });</span></div>
<div class="line added"><span class="ln">18</span><span class="content">+}</span></div>
</pre>
</details>
<details>
<summary>
<code>[src/components/TaskList.tsx]</code>
<span class="badge worth-attn">worth a look</span>
<span class="file-meta">+31 −24</span>
</summary>
<div class="file-summary">
[Replaces inline pending state with the new hook. Behavior shift: row updates synchronously now, no spinner.]
</div>
<pre class="diff">
<span class="hunk-header">@@ -42,14 +42,17 @@ export function TaskList({ boardId }: Props) {</span>
<div class="line"><span class="ln">42</span><span class="content"> const { data: tasks } = useTasks(boardId);</span></div>
<div class="line removed"><span class="ln">43</span><span class="content">- const [pending, setPending] = useState(null);</span></div>
<div class="line removed"><span class="ln">44</span><span class="content">-</span></div>
<div class="line removed"><span class="ln">45</span><span class="content">- async function toggle(task: Task) {</span></div>
<div class="line removed"><span class="ln">46</span><span class="content">- setPending(task.id);</span></div>
<div class="line removed"><span class="ln">47</span><span class="content">- await updateTask({ id: task.id, done: !task.done });</span></div>
<div class="line removed"><span class="ln">48</span><span class="content">- await refetch();</span></div>
<div class="line removed"><span class="ln">49</span><span class="content">- setPending(null);</span></div>
<div class="line removed"><span class="ln">50</span><span class="content">- }</span></div>
<div class="line added"><span class="ln">43</span><span class="content">+ const { mutate, isPending } = useOptimisticTasks(boardId);</span></div>
<div class="line added"><span class="ln">44</span><span class="content">+</span></div>
<div class="line added"><span class="ln">45</span><span class="content">+ const toggle = (task: Task) =></span></div>
<div class="line added"><span class="ln">46</span><span class="content">+ mutate({ id: task.id, done: !task.done });</span></div>
</pre>
</details>
<details>
<summary>
<code>[src/api/tasks.ts]</code>
<span class="badge worth-attn">worth a look</span>
<span class="file-meta">+19 −6</span>
</summary>
<div class="file-summary">
[Adds Idempotency-Key header. Generated per call by default; callers can pass an explicit key for retry equivalence.]
</div>
</details>
<details>
<summary>
<code>[src/components/Toast.tsx]</code>
<span class="badge safe">safe</span>
<span class="file-meta">+14 −2</span>
</summary>
<div class="file-summary">
[Adds <code>variant="warning"</code>. Purely additive, no behavior change for existing call sites.]
</div>
</details>
<details>
<summary>
<code>[src/types/task.ts]</code>
<span class="badge safe">safe</span>
<span class="file-meta">+6 −2</span>
</summary>
<div class="file-summary">
[Widens <code>Task.status</code> to include "archived" and adds optional <code>updatedAt</code>. Type-only change.]
</div>
</details>
<details>
<summary>
<code>[src/components/__tests__/TaskList.test.tsx]</code>
<span class="badge safe">safe</span>
<span class="file-meta">+14 −4</span>
</summary>
<div class="file-summary">
[Adds: (a) row updates synchronously after click, (b) rollback on rejection. Both pass.]
</div>
</details>
</section>
</div>
</body>
</html>