@devries-cameron20 / t3code Mirror · read-only / commits / 523a98447e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

fix(web): files under "Also in this stop" in a review guide can be commented on (#38858)

Julius Marminge committed Nov 18, 2026 at 18:59 UTC 523a98447eaa1167ba4affe2270768e25f7565c2
3 files changed +187 -60
apps/web/src/components/pullRequest/guide/GuideExcerpt.tsx
+89 -58
@@ -73,7 +73,7 @@ interface ExcerptAnnotation {
73 readonly draft: boolean;
74 }
75
76 -interface ExcerptDraft {
76 +export interface CommentDraft {
77 readonly range: SelectedLineRange;
78 readonly position: PullRequestReviewPosition;
79 readonly startPosition?: PullRequestReviewPosition;
@@ -117,7 +117,7 @@ export function GuideExcerpt({
117 onOpenFile: (path: string) => void;
118 }) {
119 // Keep selections outside ExcerptDiff to survive head reloads.
120 - const [draft, setDraft] = useState<ExcerptDraft | null>(null);
120 + const [draft, setDraft] = useState<CommentDraft | null>(null);
121 const slice = excerptSlice(file, excerpt);
122
123 return (
@@ -178,8 +178,8 @@ function ExcerptDiff({
178 excerpt: PullRequestReviewGuideExcerpt;
179 file: FileDiffMetadata;
180 slice: ExcerptSlice;
181 - draft: ExcerptDraft | null;
182 - setDraft: (draft: ExcerptDraft | null) => void;
181 + draft: CommentDraft | null;
182 + setDraft: (draft: CommentDraft | null) => void;
183 loadDiffFiles: FileDiffContentsLoader;
184 notes: ReadonlyArray<ExcerptNoteMarker>;
185 commenting: ExcerptCommenting | null;
@@ -235,29 +235,11 @@ function ExcerptDiff({
235 })();
236
237 const beginComment = (range: SelectedLineRange | null) => {
238 - if (range === null) return;
239 - const anchor = resolveDiffReviewAnchor(file, range, commenting?.rangeComments === true);
240 - if (anchor === null) return;
241 - setDraft({ range, ...anchor });
238 + const next = commentDraftFor(file, range, commenting);
239 + if (next !== null) setDraft(next);
240 };
241 const gt = useGT();
242 const interactive = commenting !== null && draft === null;
245 - const onAskAgent = commenting?.onAskAgent ?? null;
246 - const askAgent = (request: string) => {
247 - if (draft === null || onAskAgent === null) return;
248 - const comment = buildDiffReviewComment({
249 - id: `pull-request-guide:${diffReviewSelectionId(excerpt.path, draft.range)}`,
250 - sectionId: `pull-request-guide:${excerpt.path}`,
251 - // oxlint-disable-next-line t3code/no-untranslated-copy -- context title sent to the agent
252 - sectionTitle: "Review guide",
253 - filePath: excerpt.path,
254 - fileDiff: file,
255 - range: draft.range,
256 - text: request,
257 - });
258 - setDraft(null);
259 - if (comment !== null) onAskAgent(comment, request);
260 - };
243
244 const options = {
245 diffStyle: "unified" as const,
@@ -303,40 +285,12 @@ function ExcerptDiff({
285 />
286 ))}
287 {annotation.metadata.draft && draft !== null && commenting !== null ? (
306 - <DiffCommentAnnotation
307 - kind="draft"
308 - rangeLabel={`${excerpt.path}:${getReviewPositionAnchor(draft.position).line}`}
309 - text=""
310 - completionScope={commenting.canComment ? commenting.completionScope : null}
311 - placeholder={
312 - commenting.canComment
313 - ? gt("Add a comment…")
314 - : gt("Ask the agent about these lines…")
315 - }
316 - submitLabel={commenting.canComment ? gt("Add to review") : gt("Ask agent")}
317 - {...(commenting.canComment && onAskAgent !== null
318 - ? {
319 - secondaryAction: {
320 - label: gt("Ask agent"),
321 - onAction: (text: string) => askAgent(text),
322 - },
323 - }
324 - : {})}
325 - onCancel={() => setDraft(null)}
326 - onComment={(body) => {
327 - if (!commenting.canComment) {
328 - askAgent(body);
329 - return;
330 - }
331 - commenting.onComment({
332 - path: excerpt.path,
333 - oldPath: previousPathOf(file, excerpt.path),
334 - position: draft.position,
335 - startPosition: draft.startPosition,
336 - body,
337 - });
338 - setDraft(null);
339 - }}
288 + <GuideCommentDraft
289 + path={excerpt.path}
290 + file={file}
291 + draft={draft}
292 + commenting={commenting}
293 + onClose={() => setDraft(null)}
294 />
295 ) : null}
296 </div>
@@ -379,3 +333,80 @@ function previousPathOf(file: FileDiffMetadata, path: string): string | null {
333 const previous = resolveFileDiffPreviousPath(file);
334 return previous === path ? null : previous;
335 }
336 +
337 +export function commentDraftFor(
338 + file: FileDiffMetadata,
339 + range: SelectedLineRange | null,
340 + commenting: ExcerptCommenting | null,
341 +): CommentDraft | null {
342 + if (range === null || commenting === null) return null;
343 + const anchor = resolveDiffReviewAnchor(file, range, commenting.rangeComments);
344 + return anchor === null ? null : { range, ...anchor };
345 +}
346 +
347 +export function GuideCommentDraft({
348 + path,
349 + file,
350 + draft,
351 + commenting,
352 + onClose,
353 +}: {
354 + path: string;
355 + file: FileDiffMetadata;
356 + draft: CommentDraft;
357 + commenting: ExcerptCommenting;
358 + onClose: () => void;
359 +}) {
360 + const gt = useGT();
361 + const onAskAgent = commenting.onAskAgent;
362 + const askAgent = (request: string) => {
363 + if (onAskAgent === null) return;
364 + const comment = buildDiffReviewComment({
365 + id: `pull-request-guide:${diffReviewSelectionId(path, draft.range)}`,
366 + sectionId: `pull-request-guide:${path}`,
367 + // oxlint-disable-next-line t3code/no-untranslated-copy -- context title sent to the agent
368 + sectionTitle: "Review guide",
369 + filePath: path,
370 + fileDiff: file,
371 + range: draft.range,
372 + text: request,
373 + });
374 + onClose();
375 + if (comment !== null) onAskAgent(comment, request);
376 + };
377 + return (
378 + <DiffCommentAnnotation
379 + kind="draft"
380 + rangeLabel={`${path}:${getReviewPositionAnchor(draft.position).line}`}
381 + text=""
382 + completionScope={commenting.canComment ? commenting.completionScope : null}
383 + placeholder={
384 + commenting.canComment ? gt("Add a comment…") : gt("Ask the agent about these lines…")
385 + }
386 + submitLabel={commenting.canComment ? gt("Add to review") : gt("Ask agent")}
387 + {...(commenting.canComment && onAskAgent !== null
388 + ? {
389 + secondaryAction: {
390 + label: gt("Ask agent"),
391 + onAction: (text: string) => askAgent(text),
392 + },
393 + }
394 + : {})}
395 + onCancel={onClose}
396 + onComment={(body) => {
397 + if (!commenting.canComment) {
398 + askAgent(body);
399 + return;
400 + }
401 + commenting.onComment({
402 + path,
403 + oldPath: previousPathOf(file, path),
404 + position: draft.position,
405 + startPosition: draft.startPosition,
406 + body,
407 + });
408 + onClose();
409 + }}
410 + />
411 + );
412 +}
apps/web/src/components/pullRequest/guide/GuideFileDiff.tsx
+92 -1
@@ -1,27 +1,89 @@
1 import {
2 cloneFileDiffMetadata,
3 + type DiffLineAnnotation,
4 type FileDiffContentsLoader,
5 type FileDiffMetadata,
6 + type SelectedLineRange,
7 } from "@pierre/diffs";
8 import { FileDiff } from "@pierre/diffs/react";
9 +import { useState } from "react";
10
11 import { useRenderedAppearance } from "~/hooks/useTheme";
12 import { resolveDiffThemeName } from "~/lib/diffRendering";
13 import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
14
15 import { DIFF_VIEW_UNSAFE_CSS } from "../../diffs/StyledDiffCodeView";
16 +import {
17 + getReviewPositionAnchor,
18 + PendingReviewCommentCard,
19 + toViewerSide,
20 +} from "../PullRequestReviewAnnotation";
21 +import type { PendingReviewComment } from "../pullRequestReviewStore";
22 +import {
23 + commentDraftFor,
24 + GuideCommentDraft,
25 + type CommentDraft,
26 + type ExcerptCommenting,
27 +} from "./GuideExcerpt";
28 +
29 +interface FileAnnotation {
30 + readonly pending: ReadonlyArray<PendingReviewComment>;
31 + readonly draft: boolean;
32 +}
33
34 export function GuideFileDiff({
35 + path,
36 file,
37 + commenting,
38 loadDiffFiles,
39 }: {
40 + path: string;
41 file: FileDiffMetadata;
42 + commenting: ExcerptCommenting | null;
43 loadDiffFiles: FileDiffContentsLoader;
44 }) {
45 const resolvedTheme = useRenderedAppearance();
46 + const [draft, setDraft] = useState<CommentDraft | null>(null);
47 // Loading the unchanged lines rewrites the diff it is given; the excerpts read the same file
48 // as a patch, so this view expands a copy of its own.
49 const expandable = cloneFileDiffMetadata(file);
50 +
51 + const annotations = (() => {
52 + const groups = new Map<string, DiffLineAnnotation<FileAnnotation>>();
53 + const update = (
54 + side: "additions" | "deletions",
55 + line: number,
56 + change: (metadata: FileAnnotation) => FileAnnotation,
57 + ) => {
58 + const key = `${side}:${line}`;
59 + const group = groups.get(key) ?? {
60 + side,
61 + lineNumber: line,
62 + metadata: { pending: [], draft: false },
63 + };
64 + groups.set(key, { ...group, metadata: change(group.metadata) });
65 + };
66 + for (const comment of commenting?.pending ?? []) {
67 + if (comment.path !== path) continue;
68 + const anchor = getReviewPositionAnchor(comment.position);
69 + update(toViewerSide(anchor.side), anchor.line, (metadata) => ({
70 + ...metadata,
71 + pending: [...metadata.pending, comment],
72 + }));
73 + }
74 + if (draft !== null) {
75 + const anchor = getReviewPositionAnchor(draft.position);
76 + update(toViewerSide(anchor.side), anchor.line, (metadata) => ({ ...metadata, draft: true }));
77 + }
78 + return [...groups.values()];
79 + })();
80 +
81 + const beginComment = (range: SelectedLineRange | null) => {
82 + const next = commentDraftFor(file, range, commenting);
83 + if (next !== null) setDraft(next);
84 + };
85 + const interactive = commenting !== null && draft === null;
86 +
87 const options = {
88 diffStyle: "unified" as const,
89 lineDiffType: "none" as const,
@@ -31,11 +93,40 @@ export function GuideFileDiff({
93 themeType: resolvedTheme,
94 preferredHighlighter: PREFERRED_HIGHLIGHTER,
95 unsafeCSS: DIFF_VIEW_UNSAFE_CSS,
96 + enableGutterUtility: interactive,
97 + enableLineSelection: interactive,
98 + onGutterUtilityClick: beginComment,
99 + onLineSelectionEnd: beginComment,
100 loadDiffFiles,
101 };
102 return (
103 <div className="border-t border-border/60">
38 - <FileDiff fileDiff={expandable} options={options} />
104 + <FileDiff<FileAnnotation>
105 + fileDiff={expandable}
106 + options={options}
107 + lineAnnotations={annotations}
108 + selectedLines={draft?.range ?? null}
109 + renderAnnotation={(annotation) => (
110 + <div className="font-sans">
111 + {annotation.metadata.pending.map((comment) => (
112 + <PendingReviewCommentCard
113 + key={comment.id}
114 + comment={comment}
115 + onRemove={() => commenting?.onRemove(comment.id)}
116 + />
117 + ))}
118 + {annotation.metadata.draft && draft !== null && commenting !== null ? (
119 + <GuideCommentDraft
120 + path={path}
121 + file={file}
122 + draft={draft}
123 + commenting={commenting}
124 + onClose={() => setDraft(null)}
125 + />
126 + ) : null}
127 + </div>
128 + )}
129 + />
130 </div>
131 );
132 }
apps/web/src/components/pullRequest/guide/GuideStop.tsx
+6 -1
@@ -218,7 +218,12 @@ export function GuideStop({
218 </CollapsibleTrigger>
219 <CollapsiblePanel animate={false}>
220 {diff !== undefined ? (
221 - <GuideFileDiff file={diff} loadDiffFiles={loadDiffFiles} />
221 + <GuideFileDiff
222 + path={file.path}
223 + file={diff}
224 + commenting={commenting}
225 + loadDiffFiles={loadDiffFiles}
226 + />
227 ) : (
228 <p className="px-3 py-2 text-xs text-muted-foreground">
229 {diffLoading