@bevel-software/platform-core-frontend 0.7.0 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,292 +1,395 @@
1
- import { useCallback, useEffect, useRef, useState } from 'react';
2
- import { Check, Trash2, Eye, ChevronDown, X } from 'lucide-react';
3
- import type { PendingChange } from '@bevel-software/platform-shared';
4
- import { useReview } from '../state/review.context';
5
- import { useWorkspace } from '../../workspace/state/workspace.context';
6
- import {
7
- useFileNav,
8
- useNodeIdNav,
9
- resolveRelativePath,
10
- KB_ROUTE_PREFIX,
11
- } from '../../workspace/routing/kb-routes';
12
- import { ReviewFileRow } from './ReviewFileRow';
13
- import { DiffViewer } from './DiffViewer';
14
- import { MarkdownDiffViewer } from './MarkdownDiffViewer';
15
- import { BinaryChangePlaceholder } from './BinaryChangePlaceholder';
16
-
17
- function isMarkdownPath(p: string): boolean {
18
- return /\.md$/i.test(p);
19
- }
20
-
21
- function basename(p: string): string {
22
- const i = p.lastIndexOf('/');
23
- return i >= 0 ? p.slice(i + 1) : p;
24
- }
25
-
26
- function kindLabel(kind: PendingChange['kind']): string {
27
- switch (kind) {
28
- case 'added': return 'Added';
29
- case 'deleted': return 'Deleted';
30
- case 'renamed': return 'Renamed';
31
- case 'modified': return 'Modified';
32
- }
33
- }
34
-
35
- /**
36
- * Review panel for pending agent changes. **Opt-in, not a takeover.** The
37
- * caller (FileViewer) decides when to mount it — the user opens it from the
38
- * review badge and can dismiss it via `onClose`. It no longer auto-mounts on
39
- * the existence of changes; that "existence" fact drives the badge instead,
40
- * keeping "are there changes" and "is the panel open" as separate concerns.
41
- *
42
- * Layout: a single top bar with a file-picker dropdown + global actions,
43
- * then the diff fills the rest. The dropdown replaces the earlier left
44
- * sidebar so the diff always gets full width — important on mobile where
45
- * the sidebar was eating most of the screen.
46
- */
47
- export function ReviewPanel({ onClose }: { onClose?: () => void }) {
48
- const review = useReview();
49
- const { refreshFileTree } = useWorkspace();
50
- const { openFile } = useFileNav();
51
- // Links inside a rendered diff. Both resolvers navigate relative to
52
- // `git.status.branch`, which is CORRECT here and only here: this panel
53
- // reviews the agent's uncommitted changes on the branch you are already
54
- // standing on, so "the diff's branch" and "the current branch" are the same
55
- // thing. (The change-request dialog is not in that position, which is why it
56
- // passes no resolvers — see the comment at its MarkdownDiffViewer call.)
57
- const { openNodeId } = useNodeIdNav();
58
- const diffPath = review.fileDiff?.path ?? '';
59
- const openDiffLink = useCallback(
60
- (href: string) => {
61
- // Absolute workspace URLs carry their own branch; running them through
62
- // resolveRelativePath would treat them as relative to the diffed file
63
- // and mangle the path. Same guard as MarkdownRenderer's handleFileLink.
64
- if (href.startsWith(`${KB_ROUTE_PREFIX}/`)) {
65
- openFile(href);
66
- return;
67
- }
68
- let decoded = href;
69
- try { decoded = decodeURIComponent(href); } catch { /* leave as-is */ }
70
- openFile(resolveRelativePath(diffPath, decoded));
71
- },
72
- [openFile, diffPath],
73
- );
74
- const [busy, setBusy] = useState(false);
75
- // `busy` alone is not re-entrant-safe: two rapid clicks (or a click + a
76
- // keyboard activation of the same button) can both read `busy === false`
77
- // before React schedules the state update. A synchronous ref flips the
78
- // lock in the same tick so the second invocation sees the first one.
79
- const busyRef = useRef(false);
80
- const [pickerOpen, setPickerOpen] = useState(false);
81
- const pickerRef = useRef<HTMLDivElement>(null);
82
- // Default action scope is the single selected file. The "Apply to all"
83
- // checkbox (off by default) widens Accept/Delete to every pending change.
84
- const [applyToAll, setApplyToAll] = useState(false);
85
-
86
- const { session, selectedPath, fileDiff, isLoadingDiff, selectPath } = review;
87
-
88
- // Auto-select the first change whenever the selection is empty but changes exist.
89
- // Keeps the diff pane populated after an accept/reject collapses the selected row.
90
- useEffect(() => {
91
- if (!session || session.changes.length === 0) return;
92
- if (selectedPath) return;
93
- const first = session.changes[0];
94
- selectPath(first.path);
95
- }, [session, selectedPath, selectPath]);
96
-
97
- // Close the picker on outside click / ESC.
98
- useEffect(() => {
99
- if (!pickerOpen) return;
100
- const onMouseDown = (e: MouseEvent) => {
101
- if (pickerRef.current && !pickerRef.current.contains(e.target as Node)) {
102
- setPickerOpen(false);
103
- }
104
- };
105
- const onKey = (e: KeyboardEvent) => {
106
- if (e.key === 'Escape') setPickerOpen(false);
107
- };
108
- document.addEventListener('mousedown', onMouseDown);
109
- document.addEventListener('keydown', onKey);
110
- return () => {
111
- document.removeEventListener('mousedown', onMouseDown);
112
- document.removeEventListener('keydown', onKey);
113
- };
114
- }, [pickerOpen]);
115
-
116
- const handleSelect = useCallback(
117
- async (path: string) => {
118
- setPickerOpen(false);
119
- await selectPath(path);
120
- // Also surface the file in the editor so the user can see context alongside
121
- // the diff. Skip for deleted files — navigating to a missing path would
122
- // land FileRoute on the file-not-found state.
123
- const change = session?.changes.find((c) => c.path === path);
124
- if (change && change.kind !== 'deleted') {
125
- openFile(path);
126
- }
127
- },
128
- [selectPath, openFile, session],
129
- );
130
-
131
- const withBusy = useCallback(
132
- async (fn: () => Promise<void>) => {
133
- if (busyRef.current) return;
134
- busyRef.current = true;
135
- setBusy(true);
136
- try {
137
- await fn();
138
- // Any accept/reject changes disk state, so refresh the tree in case
139
- // files were added/removed.
140
- await refreshFileTree();
141
- } finally {
142
- busyRef.current = false;
143
- setBusy(false);
144
- }
145
- },
146
- [refreshFileTree],
147
- );
148
-
149
- if (!session || session.changes.length === 0) return null;
150
-
151
- const count = session.changes.length;
152
- const selected = session.changes.find((c) => c.path === selectedPath);
153
- const selectedLabel = selected ? basename(selected.path) : 'Select a file';
154
- const selectedKind = selected ? kindLabel(selected.kind) : null;
155
-
156
- return (
157
- <div className="absolute inset-0 z-20 flex flex-col bg-white">
158
- <div className="min-h-10 border-b border-line flex flex-wrap items-center px-3 py-1.5 gap-2 shrink-0">
159
- <Eye size={14} className="text-emerald-600 shrink-0" />
160
- <span className="text-sm font-medium text-ink shrink-0">
161
- Review agent changes
162
- </span>
163
- <span className="text-xs text-ink-muted shrink-0">
164
- {count} file{count === 1 ? '' : 's'} pending
165
- </span>
166
-
167
- <div ref={pickerRef} className="relative flex-1 min-w-[10rem] max-w-md">
168
- <button
169
- type="button"
170
- onClick={() => setPickerOpen((v) => !v)}
171
- aria-haspopup="listbox"
172
- aria-expanded={pickerOpen}
173
- className="w-full flex items-center gap-2 px-2.5 py-1 rounded border border-line-strong bg-white hover:bg-hover text-left"
174
- >
175
- <span className="text-xs text-ink truncate flex-1" title={selected?.path}>
176
- {selectedLabel}
177
- </span>
178
- {selectedKind && (
179
- <span className="text-[10px] uppercase tracking-wider text-ink-muted shrink-0">
180
- {selectedKind}
181
- </span>
182
- )}
183
- <ChevronDown
184
- size={12}
185
- className={`text-ink-muted shrink-0 transition-transform ${pickerOpen ? 'rotate-180' : ''}`}
186
- />
187
- </button>
188
-
189
- {pickerOpen && (
190
- <div
191
- role="listbox"
192
- className="absolute left-0 right-0 top-full mt-1 max-h-[60vh] overflow-y-auto bg-white border border-line rounded-md shadow-xl z-30 p-1 space-y-1"
193
- >
194
- {session.changes.map((change) => (
195
- <ReviewFileRow
196
- key={`${change.kind}:${change.oldPath ?? ''}:${change.path}`}
197
- change={change}
198
- active={selectedPath === change.path}
199
- busy={busy}
200
- onSelect={() => handleSelect(change.path)}
201
- onAccept={() => withBusy(() => review.acceptOne(change.path))}
202
- onReject={() => review.rejectOne(change.path)}
203
- />
204
- ))}
205
- </div>
206
- )}
207
- </div>
208
-
209
- <button
210
- type="button"
211
- disabled={busy || (!applyToAll && !selected)}
212
- onClick={() =>
213
- withBusy(() =>
214
- applyToAll
215
- ? review.rejectAll()
216
- : selected ? review.rejectOne(selected.path) : Promise.resolve(),
217
- )
218
- }
219
- title={applyToAll ? 'Delete every pending change. Restore the originals' : 'Delete this change. Restore the original'}
220
- className="flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium text-ink hover:text-red-700 hover:bg-red-100 disabled:opacity-40"
221
- >
222
- <Trash2 size={12} />
223
- Delete
224
- </button>
225
- <button
226
- type="button"
227
- disabled={busy || (!applyToAll && !selected)}
228
- onClick={() =>
229
- withBusy(() =>
230
- applyToAll
231
- ? review.acceptAll()
232
- : selected ? review.acceptOne(selected.path) : Promise.resolve(),
233
- )
234
- }
235
- title={applyToAll ? 'Accept every pending change' : 'Accept this change'}
236
- className="flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium bg-emerald-700 hover:bg-emerald-600 text-white disabled:opacity-40"
237
- >
238
- <Check size={12} />
239
- Accept
240
- </button>
241
- <label className="flex items-center gap-1.5 text-xs text-ink select-none shrink-0 cursor-pointer">
242
- <input
243
- type="checkbox"
244
- checked={applyToAll}
245
- onChange={(e) => setApplyToAll(e.target.checked)}
246
- disabled={busy}
247
- className="cursor-pointer"
248
- />
249
- Apply to all
250
- </label>
251
- {onClose && (
252
- <button
253
- type="button"
254
- onClick={onClose}
255
- title="Close review: changes stay pending"
256
- aria-label="Close review"
257
- className="ml-1 p-1 rounded text-ink-muted hover:text-ink hover:bg-hover shrink-0"
258
- >
259
- <X size={16} />
260
- </button>
261
- )}
262
- </div>
263
-
264
- <div className="flex-1 min-w-0 min-h-0">
265
- {isLoadingDiff && (
266
- <div className="h-full flex items-center justify-center text-xs text-ink-muted">
267
- Loading diff…
268
- </div>
269
- )}
270
- {!isLoadingDiff && !fileDiff && (
271
- <div className="h-full flex items-center justify-center text-xs text-ink-muted">
272
- Select a file to see the diff.
273
- </div>
274
- )}
275
- {!isLoadingDiff && fileDiff && fileDiff.isBinary && (
276
- <BinaryChangePlaceholder payload={fileDiff} />
277
- )}
278
- {!isLoadingDiff && fileDiff && !fileDiff.isBinary && (
279
- isMarkdownPath(fileDiff.path) ? (
280
- <MarkdownDiffViewer
281
- payload={fileDiff}
282
- onOpenFile={openDiffLink}
283
- onOpenNodeId={openNodeId}
284
- />
285
- ) : (
286
- <DiffViewer payload={fileDiff} />
287
- )
288
- )}
289
- </div>
290
- </div>
291
- );
292
- }
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { Check, Trash2, Eye, ChevronDown, X } from 'lucide-react';
3
+ import type { PendingChange } from '@bevel-software/platform-shared';
4
+ import { useReview } from '../state/review.context';
5
+ import { useWorkspace } from '../../workspace/state/workspace.context';
6
+ import {
7
+ useFileNav,
8
+ useNodeIdNav,
9
+ resolveRelativePath,
10
+ stripJunkBeforeKbDir,
11
+ KB_ROUTE_PREFIX,
12
+ } from '../../workspace/routing/kb-routes';
13
+ import { groupOfPath, DEFAULT_BRANCH } from '@bevel-software/platform-shared';
14
+ import { cn } from '../../../lib/utils';
15
+ import { DOCUMENT_COLUMN, documentGutters } from '../../../shared/theme/measure';
16
+ import { ReviewFileRow } from './ReviewFileRow';
17
+ import { DiffViewer } from './DiffViewer';
18
+ import { MarkdownDiffViewer } from './MarkdownDiffViewer';
19
+ import { BinaryChangePlaceholder } from './BinaryChangePlaceholder';
20
+
21
+ function isMarkdownPath(p: string): boolean {
22
+ return /\.md$/i.test(p);
23
+ }
24
+
25
+ /**
26
+ * Whether a review-session path is a skill or tool — anything under `Groups/`.
27
+ *
28
+ * The paths in a review session are WORKSPACE-relative: the diff module
29
+ * resolves them against the workspace directory, so they arrive carrying the
30
+ * KB clone as their first segment (`knowledge-base/Groups/GTM/x/SKILL.md`).
31
+ * `groupOfPath` wants them REPO-relative, and `stripJunkBeforeKbDir` does not
32
+ * get there on its own — it only drops junk BEFORE the kb dir and keeps the
33
+ * segment itself, so it returns an already-well-formed path unchanged. Asking
34
+ * `groupOfPath` about the workspace-relative form gets `null` for every path,
35
+ * group or not, which is a check that silently never fires.
36
+ *
37
+ * Exported so it can be tested directly. The behaviour it guards lives behind
38
+ * a dropdown the component tests cannot open, and a first attempt at covering
39
+ * it through the UI passed with the guard deleted.
40
+ */
41
+ export function isGroupItemPath(path: string, kbDirName: string | null): boolean {
42
+ const withoutJunk = stripJunkBeforeKbDir(path, kbDirName);
43
+ const repoRelative =
44
+ kbDirName && withoutJunk.startsWith(`${kbDirName}/`)
45
+ ? withoutJunk.slice(kbDirName.length + 1)
46
+ : withoutJunk;
47
+ return groupOfPath(repoRelative) !== null;
48
+ }
49
+
50
+ /**
51
+ * Whether selecting `change` should also open its file beside the diff.
52
+ *
53
+ * The whole decision in one place, and exported, because the call site sits
54
+ * behind a dropdown the component harness cannot open — everything asserted
55
+ * about it through the UI passed with the guard deleted.
56
+ *
57
+ * Two reasons not to:
58
+ * - DELETED: navigating to a missing path lands FileRoute on its
59
+ * file-not-found state.
60
+ * - a group item ON THE DEFAULT BRANCH: that URL is a library location, so
61
+ * opening it switches the whole shell to Skills & Tools and the panel,
62
+ * the diff and the review vanish because someone clicked a row in a list.
63
+ *
64
+ * The branch is part of it, and this is the easy half to get wrong: only the
65
+ * DEFAULT branch's `Groups/` URLs are library locations (`isLibraryLocation`
66
+ * tests `segments[1] === DEFAULT_BRANCH`). The same skill on a draft branch
67
+ * opens in Knowledge like any other file and switches nothing, so refusing to
68
+ * open it there would cost the context this call exists to give and buy
69
+ * nothing.
70
+ *
71
+ * `DEFAULT_BRANCH` is read here rather than captured at module scope — it is
72
+ * a live binding configured during boot.
73
+ */
74
+ export function shouldOpenBesideDiff(input: {
75
+ kind: PendingChange['kind'];
76
+ path: string;
77
+ kbDirName: string | null;
78
+ branch: string | null;
79
+ }): boolean {
80
+ if (input.kind === 'deleted') return false;
81
+ const switchesApp = input.branch === DEFAULT_BRANCH && isGroupItemPath(input.path, input.kbDirName);
82
+ return !switchesApp;
83
+ }
84
+
85
+ function basename(p: string): string {
86
+ const i = p.lastIndexOf('/');
87
+ return i >= 0 ? p.slice(i + 1) : p;
88
+ }
89
+
90
+ function kindLabel(kind: PendingChange['kind']): string {
91
+ switch (kind) {
92
+ case 'added': return 'Added';
93
+ case 'deleted': return 'Deleted';
94
+ case 'renamed': return 'Renamed';
95
+ case 'modified': return 'Modified';
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Review panel for pending agent changes. **Opt-in, not a takeover.** The
101
+ * caller (FileViewer) decides when to mount it — the user opens it from the
102
+ * review badge and can dismiss it via `onClose`. It no longer auto-mounts on
103
+ * the existence of changes; that "existence" fact drives the badge instead,
104
+ * keeping "are there changes" and "is the panel open" as separate concerns.
105
+ *
106
+ * Layout: a single top bar with a file-picker dropdown + global actions,
107
+ * then the diff fills the rest. The dropdown replaces the earlier left
108
+ * sidebar so the diff always gets full width — important on mobile where
109
+ * the sidebar was eating most of the screen.
110
+ */
111
+ export function ReviewPanel({ onClose }: { onClose?: () => void }) {
112
+ const review = useReview();
113
+ const { refreshFileTree, kbDirName } = useWorkspace();
114
+ const { openFile } = useFileNav();
115
+ // Links inside a rendered diff. Both resolvers navigate relative to
116
+ // `git.status.branch`, which is CORRECT here and only here: this panel
117
+ // reviews the agent's uncommitted changes on the branch you are already
118
+ // standing on, so "the diff's branch" and "the current branch" are the same
119
+ // thing. (The change-request dialog is not in that position, which is why it
120
+ // passes no resolvers — see the comment at its MarkdownDiffViewer call.)
121
+ const { openNodeId } = useNodeIdNav();
122
+ const diffPath = review.fileDiff?.path ?? '';
123
+ const openDiffLink = useCallback(
124
+ (href: string) => {
125
+ // Absolute workspace URLs carry their own branch; running them through
126
+ // resolveRelativePath would treat them as relative to the diffed file
127
+ // and mangle the path. Same guard as MarkdownRenderer's handleFileLink.
128
+ if (href.startsWith(`${KB_ROUTE_PREFIX}/`)) {
129
+ openFile(href);
130
+ return;
131
+ }
132
+ let decoded = href;
133
+ try { decoded = decodeURIComponent(href); } catch { /* leave as-is */ }
134
+ openFile(resolveRelativePath(diffPath, decoded));
135
+ },
136
+ [openFile, diffPath],
137
+ );
138
+ const [busy, setBusy] = useState(false);
139
+ // `busy` alone is not re-entrant-safe: two rapid clicks (or a click + a
140
+ // keyboard activation of the same button) can both read `busy === false`
141
+ // before React schedules the state update. A synchronous ref flips the
142
+ // lock in the same tick so the second invocation sees the first one.
143
+ const busyRef = useRef(false);
144
+ const [pickerOpen, setPickerOpen] = useState(false);
145
+ const pickerRef = useRef<HTMLDivElement>(null);
146
+ // Default action scope is the single selected file. The "Apply to all"
147
+ // checkbox (off by default) widens Accept/Delete to every pending change.
148
+ const [applyToAll, setApplyToAll] = useState(false);
149
+
150
+ const { session, selectedPath, fileDiff, isLoadingDiff, selectPath } = review;
151
+
152
+ // Auto-select the first change whenever the selection is empty but changes exist.
153
+ // Keeps the diff pane populated after an accept/reject collapses the selected row.
154
+ useEffect(() => {
155
+ if (!session || session.changes.length === 0) return;
156
+ if (selectedPath) return;
157
+ const first = session.changes[0];
158
+ selectPath(first.path);
159
+ }, [session, selectedPath, selectPath]);
160
+
161
+ // Close the picker on outside click / ESC.
162
+ useEffect(() => {
163
+ if (!pickerOpen) return;
164
+ const onMouseDown = (e: MouseEvent) => {
165
+ if (pickerRef.current && !pickerRef.current.contains(e.target as Node)) {
166
+ setPickerOpen(false);
167
+ }
168
+ };
169
+ const onKey = (e: KeyboardEvent) => {
170
+ if (e.key === 'Escape') setPickerOpen(false);
171
+ };
172
+ document.addEventListener('mousedown', onMouseDown);
173
+ document.addEventListener('keydown', onKey);
174
+ return () => {
175
+ document.removeEventListener('mousedown', onMouseDown);
176
+ document.removeEventListener('keydown', onKey);
177
+ };
178
+ }, [pickerOpen]);
179
+
180
+ const handleSelect = useCallback(
181
+ async (path: string) => {
182
+ setPickerOpen(false);
183
+ await selectPath(path);
184
+ // Also surface the file in the editor so the user can see context
185
+ // alongside the diff — unless doing so would take the reader somewhere
186
+ // they did not ask to go. See `shouldOpenBesideDiff`.
187
+ const change = session?.changes.find((c) => c.path === path);
188
+ if (
189
+ change &&
190
+ shouldOpenBesideDiff({
191
+ kind: change.kind,
192
+ path,
193
+ kbDirName,
194
+ branch: session?.branchName ?? null,
195
+ })
196
+ ) {
197
+ openFile(path);
198
+ }
199
+ },
200
+ [selectPath, openFile, session, kbDirName],
201
+ );
202
+
203
+ const withBusy = useCallback(
204
+ async (fn: () => Promise<void>) => {
205
+ if (busyRef.current) return;
206
+ busyRef.current = true;
207
+ setBusy(true);
208
+ try {
209
+ await fn();
210
+ // Any accept/reject changes disk state, so refresh the tree in case
211
+ // files were added/removed.
212
+ await refreshFileTree();
213
+ } finally {
214
+ busyRef.current = false;
215
+ setBusy(false);
216
+ }
217
+ },
218
+ [refreshFileTree],
219
+ );
220
+
221
+ if (!session || session.changes.length === 0) return null;
222
+
223
+ const count = session.changes.length;
224
+ const selected = session.changes.find((c) => c.path === selectedPath);
225
+ const selectedLabel = selected ? basename(selected.path) : 'Select a file';
226
+ const selectedKind = selected ? kindLabel(selected.kind) : null;
227
+
228
+ return (
229
+ <div className="absolute inset-0 z-20 flex flex-col bg-white">
230
+ <div className="min-h-10 border-b border-line flex flex-wrap items-center px-3 py-1.5 gap-2 shrink-0">
231
+ <Eye size={14} className="text-emerald-600 shrink-0" />
232
+ <span className="text-sm font-medium text-ink shrink-0">
233
+ Review agent changes
234
+ </span>
235
+ <span className="text-xs text-ink-muted shrink-0">
236
+ {count} file{count === 1 ? '' : 's'} pending
237
+ </span>
238
+
239
+ <div ref={pickerRef} className="relative flex-1 min-w-[10rem] max-w-md">
240
+ <button
241
+ type="button"
242
+ onClick={() => setPickerOpen((v) => !v)}
243
+ aria-haspopup="listbox"
244
+ aria-expanded={pickerOpen}
245
+ className="w-full flex items-center gap-2 px-2.5 py-1 rounded border border-line-strong bg-white hover:bg-hover text-left"
246
+ >
247
+ <span className="text-xs text-ink truncate flex-1" title={selected?.path}>
248
+ {selectedLabel}
249
+ </span>
250
+ {selectedKind && (
251
+ <span className="text-[10px] uppercase tracking-wider text-ink-muted shrink-0">
252
+ {selectedKind}
253
+ </span>
254
+ )}
255
+ <ChevronDown
256
+ size={12}
257
+ className={`text-ink-muted shrink-0 transition-transform ${pickerOpen ? 'rotate-180' : ''}`}
258
+ />
259
+ </button>
260
+
261
+ {pickerOpen && (
262
+ <div
263
+ role="listbox"
264
+ className="absolute left-0 right-0 top-full mt-1 max-h-[60vh] overflow-y-auto bg-white border border-line rounded-md shadow-xl z-30 p-1 space-y-1"
265
+ >
266
+ {session.changes.map((change) => (
267
+ <ReviewFileRow
268
+ key={`${change.kind}:${change.oldPath ?? ''}:${change.path}`}
269
+ change={change}
270
+ active={selectedPath === change.path}
271
+ busy={busy}
272
+ onSelect={() => handleSelect(change.path)}
273
+ onAccept={() => withBusy(() => review.acceptOne(change.path))}
274
+ onReject={() => review.rejectOne(change.path)}
275
+ />
276
+ ))}
277
+ </div>
278
+ )}
279
+ </div>
280
+
281
+ <button
282
+ type="button"
283
+ disabled={busy || (!applyToAll && !selected)}
284
+ onClick={() =>
285
+ withBusy(() =>
286
+ applyToAll
287
+ ? review.rejectAll()
288
+ : selected ? review.rejectOne(selected.path) : Promise.resolve(),
289
+ )
290
+ }
291
+ title={applyToAll ? 'Delete every pending change. Restore the originals' : 'Delete this change. Restore the original'}
292
+ className="flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium text-ink hover:text-red-700 hover:bg-red-100 disabled:opacity-40"
293
+ >
294
+ <Trash2 size={12} />
295
+ Delete
296
+ </button>
297
+ <button
298
+ type="button"
299
+ disabled={busy || (!applyToAll && !selected)}
300
+ onClick={() =>
301
+ withBusy(() =>
302
+ applyToAll
303
+ ? review.acceptAll()
304
+ : selected ? review.acceptOne(selected.path) : Promise.resolve(),
305
+ )
306
+ }
307
+ title={applyToAll ? 'Accept every pending change' : 'Accept this change'}
308
+ className="flex items-center gap-1.5 px-2.5 py-1 rounded text-xs font-medium bg-emerald-700 hover:bg-emerald-600 text-white disabled:opacity-40"
309
+ >
310
+ <Check size={12} />
311
+ Accept
312
+ </button>
313
+ <label className="flex items-center gap-1.5 text-xs text-ink select-none shrink-0 cursor-pointer">
314
+ <input
315
+ type="checkbox"
316
+ checked={applyToAll}
317
+ onChange={(e) => setApplyToAll(e.target.checked)}
318
+ disabled={busy}
319
+ className="cursor-pointer"
320
+ />
321
+ Apply to all
322
+ </label>
323
+ {onClose && (
324
+ <button
325
+ type="button"
326
+ onClick={onClose}
327
+ title="Close review: changes stay pending"
328
+ aria-label="Close review"
329
+ className="ml-1 p-1 rounded text-ink-muted hover:text-ink hover:bg-hover shrink-0"
330
+ >
331
+ <X size={16} />
332
+ </button>
333
+ )}
334
+ </div>
335
+
336
+ <div className="flex-1 min-w-0 min-h-0">
337
+ {isLoadingDiff && (
338
+ <div className="h-full flex items-center justify-center text-xs text-ink-muted">
339
+ Loading diff…
340
+ </div>
341
+ )}
342
+ {!isLoadingDiff && !fileDiff && (
343
+ <div className="h-full flex items-center justify-center text-xs text-ink-muted">
344
+ Select a file to see the diff.
345
+ </div>
346
+ )}
347
+ {!isLoadingDiff && fileDiff && fileDiff.isBinary && (
348
+ <BinaryChangePlaceholder payload={fileDiff} />
349
+ )}
350
+ {!isLoadingDiff && fileDiff && !fileDiff.isBinary && (
351
+ isMarkdownPath(fileDiff.path) ? (
352
+ // Panel-width SCROLLER, measured INNER column.
353
+ //
354
+ // The scroller has to be the outer box: when the centred column
355
+ // scrolled instead, the gutters either side sat outside its hit
356
+ // area and the wheel did nothing over them — a dead margin on
357
+ // exactly the wide screens the measure exists for.
358
+ //
359
+ // With the outer scrolling, the inner column can carry the real
360
+ // Knowledge contract: `DOCUMENT_COLUMN` + `documentGutters`, which
361
+ // bundles the 40px sides AND the 110px bottom rhythm. Both now sit
362
+ // INSIDE the scroller, where they belong — the earlier version had
363
+ // to skip the gutters entirely because that bottom padding would
364
+ // have become permanent dead space below a child-owned scroll.
365
+ // The line lands at 800px, the same as the document two clicks
366
+ // away, rather than the 848px approximation.
367
+ //
368
+ // `scroll={false}` is what makes it possible: two nested
369
+ // `h-full overflow-auto` boxes leave the outer unable to scroll
370
+ // and stack both paddings.
371
+ //
372
+ // `roomy` is false — this panel covers the viewer, not the nav, so
373
+ // the file tree is still on screen beside it.
374
+ <div className="h-full overflow-auto bg-white">
375
+ <div className={cn(DOCUMENT_COLUMN, documentGutters(false))}>
376
+ <MarkdownDiffViewer
377
+ payload={fileDiff}
378
+ onOpenFile={openDiffLink}
379
+ onOpenNodeId={openNodeId}
380
+ scroll={false}
381
+ />
382
+ </div>
383
+ </div>
384
+ ) : (
385
+ // Left full-bleed on purpose. This is the marked-SOURCE view for
386
+ // yaml, scripts and config, where a line is a line of code and
387
+ // wrapping it to a prose measure helps nobody — the same call
388
+ // `getRendererLayout` makes for those types in the file viewer.
389
+ <DiffViewer payload={fileDiff} />
390
+ )
391
+ )}
392
+ </div>
393
+ </div>
394
+ );
395
+ }