From 209c1156ac6dd7107d871b57cb9bffe48e2c447a Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:49:02 +0100 Subject: [PATCH 01/10] fix(web): pull request replies can be added to chat Reply cards in the Summary and Timeline tabs had no Add to chat button, so a reply in a GitLab overview thread never reached the composer. Every reply now has the button and sends its whole conversation. Each comment gets its own length bound, with collapsed details after the visible text, so a long bot report no longer cuts the replies out. Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestDetailPanel.tsx | 7 +- .../pullRequest/PullRequestSummaryTab.tsx | 11 ++- .../pullRequest/PullRequestTimelineTab.tsx | 6 +- .../pullRequestDetail.logic.test.ts | 55 ++++++++++++ .../pullRequest/pullRequestDetail.logic.ts | 85 +++++++++++++------ 5 files changed, 126 insertions(+), 38 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx index 1e14ab19d901..349bf0f09d86 100644 --- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx +++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx @@ -27,6 +27,7 @@ import { type PullRequestSummary, resolveEnvironmentMachineKind, type ScopedThreadRef, + pullRequestConversationThreads, } from "@t3tools/contracts"; import { ArrowDownUpIcon, @@ -1278,14 +1279,14 @@ export function PullRequestDetailPanel({ /** * Brings a remark into the composer beside this panel, with the pull request it belongs to, - * and nothing else: what to ask about it is the reader's to write. A remark on a line travels - * as its whole conversation, the way fixing one does. + * and nothing else: what to ask about it is the reader's to write. A remark in a thread travels + * as its whole conversation, so a reply arrives with what it answers. */ const addCommentToChat = (subject: PullRequestChatSubject) => { if (!detail || attachTarget === null) return; const thread = subject.kind === "comment" - ? detail.reviewThreads.find((candidate) => + ? pullRequestConversationThreads(detail).find((candidate) => candidate.comments.some((comment) => comment.id === subject.comment.id), ) : undefined; diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 1f409d282ecc..0b231e65e557 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -248,15 +248,14 @@ function CommentBody({ } /** - * What Add to chat hands over for a remark: a remark on a line goes as its whole conversation, - * the way fixing one does. Null when there are no words in it to talk about. + * What Add to chat hands over for a remark: a remark in a thread goes as its whole conversation. + * Null when there are no words in it to talk about. */ function chatSubject( comment: PullRequestComment, thread: PullRequestConversationThread | undefined, ): PullRequestChatSubject | null { - // An overview thread has no line to attach, so it goes as its opening remark, as fixing it does. - if (thread !== undefined && thread.path !== null) { + if (thread !== undefined) { return thread.comments.some((entry) => visibleBody(entry.body) !== null) ? { kind: "thread", thread } : null; @@ -768,8 +767,8 @@ export function PullRequestSummaryTab({ ? null : { kind: "comment", comment } : { kind: "thread", thread }; - // A reply goes with its conversation, from the card that heads it. - const chat = reply ? null : chatSubject(comment, thread); + // A reply's card has no thread of its own; the panel sends it with its conversation. + const chat = chatSubject(comment, thread); return (
void; reactions: ReactionSurface; showPath?: boolean; - /** A reply goes with its conversation, from the card that heads it. */ - reply?: boolean; resolveButton?: ReactNode; }) { const gt = useGT(); @@ -335,7 +332,7 @@ function ConversationCard({ /> ) : null} {resolveButton} - {event.body && event.comment && !reply ? ( + {event.body && event.comment ? ( ) : null} {canReact || event.reactions.length > 0 ? ( @@ -600,7 +597,6 @@ function ReviewThreadEvent({ onOpen={onOpen} reactions={reactions} showPath={false} - reply /> ))} diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 3d0ae22b1501..0be8d7dc2761 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1241,6 +1241,61 @@ describe("adding a remark to the chat", () => { expect(sent).toContain("more characters of the review summary are omitted"); }); + it("brings an overview thread's replies along with its opening remark", () => { + const context = buildPullRequestCommentContext(pullRequest, { + kind: "thread", + thread: { + id: "t1", + path: null, + line: null, + side: "right", + isResolved: false, + isOutdated: false, + comments: [ + remark("c1", "Does this skip the prompt?"), + { + ...remark("c2", "One concern remains."), + author: { login: "coderabbit", name: null, avatarUrl: null }, + }, + ], + }, + }); + + expect(context && reviewCommentContextLabel(context)).toBe("#42 @octocat thread"); + expect(context?.text).toBe( + "octocat: Does this skip the prompt?\ncoderabbit: One concern remains.", + ); + }); + + it("keeps a reply when the remark it answers runs past the length bound", () => { + const context = buildPullRequestCommentContext(pullRequest, { + kind: "thread", + thread: { + id: "t1", + path: "src/app.ts", + line: 3, + side: "right", + isResolved: false, + isOutdated: false, + comments: [remark("c1", "x".repeat(5_000)), remark("c2", "One concern remains.")], + }, + }); + + expect(context?.text).toMatch(/\.\.\.\noctocat: One concern remains\.$/u); + }); + + it("puts a remark's visible text ahead of its collapsed details", () => { + const context = buildPullRequestCommentContext(pullRequest, { + kind: "comment", + comment: remark( + "c1", + `
\nAnalysis chain\n\n${"script ".repeat(400)}\n
\n\nOne concern remains.`, + ), + }); + + expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n
/u); + }); + it("keeps every added remark when a later hand-off lands", () => { const added = ["c1", "c2"].flatMap( (id) => diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index d98ec3ff114e..03cd6f5e86bc 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -713,6 +713,20 @@ function readableBody(raw: string): string | null { return readable === "" ? null : readable; } +/** Moves collapsed `
` sections after the text a reader sees, so a bound keeps that text first. */ +function visibleTextFirst(body: string): string { + const shown: string[] = []; + const folded: string[] = []; + let depth = 0; + for (const line of body.split("\n")) { + const opens = /^\s*]/iu.test(line); + if (opens) depth += 1; + (depth > 0 ? folded : shown).push(line); + if (depth > 0 && /<\/details>\s*$/iu.test(line)) depth -= 1; + } + return folded.length === 0 ? body : [...shown, "", ...folded].join("\n").trim(); +} + /** * Merged wins over closed: GitHub sets both timestamps on a merge, and reporting "closed" for a * merged pull request would misstate what happened. @@ -1290,8 +1304,10 @@ export function buildPullRequestContext(input: PullRequestContextMetadata): Revi return pullRequestContextComment(input, []); } -/** A remark the reader can bring into the chat: a conversation on a line, or one comment. */ -export type PullRequestChatSubject = Extract; +/** A remark the reader can bring into the chat: a whole conversation, or one comment. */ +export type PullRequestChatSubject = + | { readonly kind: "thread"; readonly thread: PullRequestConversationThread } + | { readonly kind: "comment"; readonly comment: PullRequestComment }; /** * A remark or conversation brought into the chat to talk about, not to fix. Its id carries the @@ -1307,36 +1323,57 @@ export function buildPullRequestCommentContext( subject: PullRequestChatSubject, ): ReviewCommentContext | null { const pullRequestNumber = pullRequest.number; - // Unlike a batch fix, one remark brought in to talk about travels whole. - if (subject.kind === "thread") { - const text = reviewThreadText(subject.thread); - return text === "" - ? null - : { - ...reviewThreadContext(subject.thread, pullRequestNumber), - id: `pr-comment:${pullRequest.url}:thread:${subject.thread.id}`, - text, - }; + if (subject.kind === "comment") { + const comment = subject.comment; + const body = readableBody(comment.body); + if (body === null) return null; + const author = comment.author?.login ?? "ghost"; + return { + id: `pr-comment:${pullRequest.url}:comment:${comment.id}`, + sectionId: `pull-request:${pullRequestNumber}`, + sectionTitle: `PR #${pullRequestNumber} conversation`, + // The chip wears `filePath rangeLabel`: the file a remark names, or who wrote one that names none. + filePath: comment.path ?? `@${author}`, + startIndex: 0, + endIndex: 0, + rangeLabel: "comment", + text: remarkText(`${author}: ${body}`.trim(), reviewLineComments(comment, pullRequest)), + diff: "", + ...(comment.path === null + ? {} + : { fenceLanguage: inferReviewCommentFenceLanguage(comment.path) }), + }; + } + const comments = subject.thread.comments; + // Bounded per comment so a long bot report cannot crowd the replies out of the thread. + const lines = comments.flatMap((comment) => { + const body = readableBody(comment.body); + return body === null + ? [] + : [bounded(`${comment.author?.login ?? "ghost"}: ${visibleTextFirst(body)}`)]; + }); + const first = comments[0]; + if (lines.length === 0 || first === undefined) return null; + const text = lines.join("\n"); + if (subject.thread.path !== null) { + return { + ...reviewThreadContext(subject.thread, pullRequestNumber), + id: `pr-comment:${pullRequest.url}:thread:${subject.thread.id}`, + text, + }; } - const comment = subject.comment; - const body = readableBody(comment.body); - if (body === null) return null; - const author = comment.author?.login ?? "ghost"; return { - id: `pr-comment:${pullRequest.url}:comment:${comment.id}`, + id: `pr-comment:${pullRequest.url}:thread:${subject.thread.id}`, sectionId: `pull-request:${pullRequestNumber}`, // oxlint-disable-next-line t3code/no-untranslated-copy -- context title sent to the agent sectionTitle: `PR #${pullRequestNumber} conversation`, - // The chip wears `filePath rangeLabel`: the file a remark names, or who wrote one that names none. - filePath: comment.path ?? `@${author}`, + // The chip wears `filePath rangeLabel`: who opened a thread that names no file. + filePath: `@${first.author?.login ?? "ghost"}`, startIndex: 0, endIndex: 0, - rangeLabel: "comment", - text: remarkText(`${author}: ${body}`.trim(), reviewLineComments(comment, pullRequest)), + rangeLabel: "thread", + text, diff: "", - ...(comment.path === null - ? {} - : { fenceLanguage: inferReviewCommentFenceLanguage(comment.path) }), }; } From d0b4204ac2de300674140a826a3a3a9e6b4b79d6 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 21:56:01 +0100 Subject: [PATCH 02/10] fix(web): leave details tags inside code where they are Co-Authored-By: Claude Opus 5.5 --- .../pullRequestDetail.logic.test.ts | 10 ++++++++ .../pullRequest/pullRequestDetail.logic.ts | 24 +++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 0be8d7dc2761..d2ab513a02bb 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1296,6 +1296,16 @@ describe("adding a remark to the chat", () => { expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n
/u); }); + it("leaves a details tag shown inside code where it is", () => { + const body = `\`\`\`html\n
\nExample\n
\n\`\`\`\n${"Explanation. ".repeat(100)}`; + const context = buildPullRequestCommentContext(pullRequest, { + kind: "comment", + comment: remark("c1", body), + }); + + expect(context?.text).toMatch(/^octocat: ```html\n
/u); + }); + it("keeps every added remark when a later hand-off lands", () => { const added = ["c1", "c2"].flatMap( (id) => diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 03cd6f5e86bc..da430eb6b2d7 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -713,16 +713,30 @@ function readableBody(raw: string): string | null { return readable === "" ? null : readable; } -/** Moves collapsed `
` sections after the text a reader sees, so a bound keeps that text first. */ +/** + * A body too long for the bound, with collapsed `
` sections moved after the text a + * reader sees so the bound keeps that text. Details shown inside code are source and stay put. + */ function visibleTextFirst(body: string): string { + if (body.length <= FINDING_BODY_MAX_LENGTH) return body; + const codeLines = new Set(); + const visit = (node: MdastNodes) => { + if (node.type === "code" && node.position !== undefined) { + for (let line = node.position.start.line; line <= node.position.end.line; line += 1) { + codeLines.add(line); + } + } + if ("children" in node) for (const child of node.children) visit(child); + }; + visit(fromMarkdown(body)); const shown: string[] = []; const folded: string[] = []; let depth = 0; - for (const line of body.split("\n")) { - const opens = /^\s*]/iu.test(line); - if (opens) depth += 1; + for (const [index, line] of body.split("\n").entries()) { + const inCode = codeLines.has(index + 1); + if (!inCode && /^\s*]/iu.test(line)) depth += 1; (depth > 0 ? folded : shown).push(line); - if (depth > 0 && /<\/details>\s*$/iu.test(line)) depth -= 1; + if (!inCode && depth > 0 && /<\/details>\s*$/iu.test(line)) depth -= 1; } return folded.length === 0 ? body : [...shown, "", ...folded].join("\n").trim(); } From 3a16d01af8250f7ef62115919d3b510ecab54c9e Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:01:10 +0100 Subject: [PATCH 03/10] fix(web): keep details sections that start open in place Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/pullRequestDetail.logic.test.ts | 12 ++++++++++++ .../pullRequest/pullRequestDetail.logic.ts | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index d2ab513a02bb..68c1f9d7cce4 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1296,6 +1296,18 @@ describe("adding a remark to the chat", () => { expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n
/u); }); + it("keeps a details section that starts open in place", () => { + const context = buildPullRequestCommentContext(pullRequest, { + kind: "comment", + comment: remark( + "c1", + `
\nFinding\n\nRename x.\n
\n\n${"Context. ".repeat(200)}`, + ), + }); + + expect(context?.text).toMatch(/^octocat:
/u); + }); + it("leaves a details tag shown inside code where it is", () => { const body = `\`\`\`html\n
\nExample\n
\n\`\`\`\n${"Explanation. ".repeat(100)}`; const context = buildPullRequestCommentContext(pullRequest, { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index da430eb6b2d7..315c6e38a4a6 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -731,12 +731,14 @@ function visibleTextFirst(body: string): string { visit(fromMarkdown(body)); const shown: string[] = []; const folded: string[] = []; - let depth = 0; + // Whether each open section starts collapsed; `
` reads as visible text. + const sections: boolean[] = []; for (const [index, line] of body.split("\n").entries()) { const inCode = codeLines.has(index + 1); - if (!inCode && /^\s*]/iu.test(line)) depth += 1; - (depth > 0 ? folded : shown).push(line); - if (!inCode && depth > 0 && /<\/details>\s*$/iu.test(line)) depth -= 1; + const opener = inCode ? null : /^\s*])([^>]*)/iu.exec(line); + if (opener) sections.push(!/\bopen\b/iu.test(opener[1] ?? "")); + (sections.includes(true) ? folded : shown).push(line); + if (!inCode && sections.length > 0 && /<\/details>\s*$/iu.test(line)) sections.pop(); } return folded.length === 0 ? body : [...shown, "", ...folded].join("\n").trim(); } From 0e0401766de0d4778ed3d6b1755737598f70fc39 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:05:12 +0100 Subject: [PATCH 04/10] fix(web): chat threads fit what the composer sends and say what is missing Co-Authored-By: Claude Opus 5.5 --- .../pullRequestDetail.logic.test.ts | 34 +++++++++++++++++++ .../pullRequest/pullRequestDetail.logic.ts | 32 +++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 68c1f9d7cce4..bc57336e63f8 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1,5 +1,6 @@ import { SourceControlProviderKind } from "@t3tools/contracts"; import { + COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS, GitCommandError, ProjectId, type PullRequestCheck, @@ -1296,6 +1297,39 @@ describe("adding a remark to the chat", () => { expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n
/u); }); + it("closes a details section whose closing tag has text after it", () => { + const context = buildPullRequestCommentContext(pullRequest, { + kind: "comment", + comment: remark("c1", `
\n${"script ".repeat(400)}
Tail.\nVisible.`), + }); + + expect(context?.text).toMatch(/^octocat: Visible\./u); + }); + + it("gives way to the newest replies when a thread outgrows what the composer sends", () => { + const comments = Array.from({ length: 20 }, (_, index) => + remark(`c${index}`, `${index} ${"x".repeat(990)}`), + ); + const context = buildPullRequestCommentContext(pullRequest, { + kind: "thread", + thread: { + id: "t1", + path: null, + line: null, + side: "right", + isResolved: false, + isOutdated: false, + comments, + nextCommentsCursor: "more", + }, + }); + + expect(context?.text.length).toBeLessThanOrEqual(COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS); + expect(context?.text).toMatch(/^octocat: 0 /u); + expect(context?.text).toMatch(/\n\(5 earlier replies omitted\.\)\noctocat: 6 /u); + expect(context?.text).toMatch(/octocat: 19 x+\.\.\.\n\(More replies are on the host/u); + }); + it("keeps a details section that starts open in place", () => { const context = buildPullRequestCommentContext(pullRequest, { kind: "comment", diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 315c6e38a4a6..17c13dd8f8f4 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -738,7 +738,7 @@ function visibleTextFirst(body: string): string { const opener = inCode ? null : /^\s*])([^>]*)/iu.exec(line); if (opener) sections.push(!/\bopen\b/iu.test(opener[1] ?? "")); (sections.includes(true) ? folded : shown).push(line); - if (!inCode && sections.length > 0 && /<\/details>\s*$/iu.test(line)) sections.pop(); + if (!inCode && sections.length > 0 && /<\/details>/iu.test(line)) sections.pop(); } return folded.length === 0 ? body : [...shown, "", ...folded].join("\n").trim(); } @@ -1320,6 +1320,30 @@ export function buildPullRequestContext(input: PullRequestContextMetadata): Revi return pullRequestContextComment(input, []); } +/** + * A conversation's lines within what the composer sends. Earlier replies give way first, since a + * reader reaches for the latest one, and the agent is told what it is not seeing. + */ +function threadText(lines: ReadonlyArray, moreOnHost: boolean): string { + const tail = moreOnHost ? ["(More replies are on the host and not included here.)"] : []; + let kept = lines; + let omitted = 0; + const join = () => + [ + ...kept.slice(0, 1), + ...(omitted > 0 + ? [`(${omitted} earlier ${omitted === 1 ? "reply" : "replies"} omitted.)`] + : []), + ...kept.slice(1), + ...tail, + ].join("\n"); + while (kept.length > 2 && join().length > COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS) { + kept = [kept[0]!, ...kept.slice(2)]; + omitted += 1; + } + return join(); +} + /** A remark the reader can bring into the chat: a whole conversation, or one comment. */ export type PullRequestChatSubject = | { readonly kind: "thread"; readonly thread: PullRequestConversationThread } @@ -1370,7 +1394,11 @@ export function buildPullRequestCommentContext( }); const first = comments[0]; if (lines.length === 0 || first === undefined) return null; - const text = lines.join("\n"); + const text = threadText( + lines, + (subject.thread.commentCount ?? 0) > comments.length || + subject.thread.nextCommentsCursor !== undefined, + ); if (subject.thread.path !== null) { return { ...reviewThreadContext(subject.thread, pullRequestNumber), From dc2692461a30d094c52a5621c05db3f04a22c019 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:20:58 +0100 Subject: [PATCH 05/10] fix(web): read the details open attribute, not words inside other attributes Co-Authored-By: Claude Opus 5.5 --- .../components/pullRequest/pullRequestDetail.logic.test.ts | 4 ++-- .../web/src/components/pullRequest/pullRequestDetail.logic.ts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index bc57336e63f8..102d8401781f 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1290,11 +1290,11 @@ describe("adding a remark to the chat", () => { kind: "comment", comment: remark( "c1", - `
\nAnalysis chain\n\n${"script ".repeat(400)}\n
\n\nOne concern remains.`, + `
\nAnalysis chain\n\n${"script ".repeat(400)}\n
\n\nOne concern remains.`, ), }); - expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n
/u); + expect(context?.text).toMatch(/^octocat: One concern remains\.\n\n
{ diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 17c13dd8f8f4..419870ea86ab 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -736,7 +736,9 @@ function visibleTextFirst(body: string): string { for (const [index, line] of body.split("\n").entries()) { const inCode = codeLines.has(index + 1); const opener = inCode ? null : /^\s*])([^>]*)/iu.exec(line); - if (opener) sections.push(!/\bopen\b/iu.test(opener[1] ?? "")); + // Quoted values are dropped first so `title="open logs"` does not read as the attribute. + const attributes = opener?.[1]?.replace(/"[^"]*"|'[^']*'/gu, "") ?? ""; + if (opener) sections.push(!/(?:^|\s)open(?:[\s=/]|$)/iu.test(attributes)); (sections.includes(true) ? folded : shown).push(line); if (!inCode && sections.length > 0 && /<\/details>/iu.test(line)) sections.pop(); } From 4022e1d3a0455c22fb5f23d6539ada10fd8eb26f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 18:38:47 +0000 Subject: [PATCH 06/10] fix(web): keep text after a closing details tag with the visible text Co-Authored-By: Claude Opus 5.5 --- .../pullRequest/PullRequestSummaryTab.tsx | 1 - .../pullRequest/pullRequestDetail.logic.test.ts | 2 +- .../pullRequest/pullRequestDetail.logic.ts | 13 +++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index 0b231e65e557..e5441ec3fd90 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -767,7 +767,6 @@ export function PullRequestSummaryTab({ ? null : { kind: "comment", comment } : { kind: "thread", thread }; - // A reply's card has no thread of its own; the panel sends it with its conversation. const chat = chatSubject(comment, thread); return (
{ comment: remark("c1", `
\n${"script ".repeat(400)}
Tail.\nVisible.`), }); - expect(context?.text).toMatch(/^octocat: Visible\./u); + expect(context?.text).toMatch(/^octocat: Tail\.\nVisible\./u); }); it("gives way to the newest replies when a thread outgrows what the composer sends", () => { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 419870ea86ab..e848a8f345c6 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -739,8 +739,17 @@ function visibleTextFirst(body: string): string { // Quoted values are dropped first so `title="open logs"` does not read as the attribute. const attributes = opener?.[1]?.replace(/"[^"]*"|'[^']*'/gu, "") ?? ""; if (opener) sections.push(!/(?:^|\s)open(?:[\s=/]|$)/iu.test(attributes)); - (sections.includes(true) ? folded : shown).push(line); - if (!inCode && sections.length > 0 && /<\/details>/iu.test(line)) sections.pop(); + const closer = inCode || sections.length === 0 ? null : /<\/details>/iu.exec(line); + if (closer === null) { + (sections.includes(true) ? folded : shown).push(line); + continue; + } + // Text after the closing tag is outside the section, so it goes with what follows. + const end = closer.index + closer[0].length; + (sections.includes(true) ? folded : shown).push(line.slice(0, end)); + sections.pop(); + const after = line.slice(end).trim(); + if (after !== "") (sections.includes(true) ? folded : shown).push(after); } return folded.length === 0 ? body : [...shown, "", ...folded].join("\n").trim(); } From f763ed502ea83f1d6bb3f129e8470827cb2fda10 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:55:32 +0100 Subject: [PATCH 07/10] fix(web): close every details section that ends on the same line Co-Authored-By: Claude Opus 5.5 --- .../pullRequestDetail.logic.test.ts | 8 ++++++++ .../pullRequest/pullRequestDetail.logic.ts | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 59c7b3350429..3df048b2f06d 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1302,8 +1302,16 @@ describe("adding a remark to the chat", () => { kind: "comment", comment: remark("c1", `
\n${"script ".repeat(400)}
Tail.\nVisible.`), }); + const nested = buildPullRequestCommentContext(pullRequest, { + kind: "comment", + comment: remark( + "c2", + `
\n
\n${"script ".repeat(400)}
\nFinding.`, + ), + }); expect(context?.text).toMatch(/^octocat: Tail\.\nVisible\./u); + expect(nested?.text).toMatch(/^octocat: Finding\./u); }); it("gives way to the newest replies when a thread outgrows what the composer sends", () => { diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index e848a8f345c6..48e90ed96460 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -739,17 +739,21 @@ function visibleTextFirst(body: string): string { // Quoted values are dropped first so `title="open logs"` does not read as the attribute. const attributes = opener?.[1]?.replace(/"[^"]*"|'[^']*'/gu, "") ?? ""; if (opener) sections.push(!/(?:^|\s)open(?:[\s=/]|$)/iu.test(attributes)); - const closer = inCode || sections.length === 0 ? null : /<\/details>/iu.exec(line); - if (closer === null) { + // Each closing tag ends a section; text after it goes with what follows. + let rest = line; + let closer = inCode ? null : /<\/details>/iu.exec(rest); + if (sections.length === 0 || closer === null) { (sections.includes(true) ? folded : shown).push(line); continue; } - // Text after the closing tag is outside the section, so it goes with what follows. - const end = closer.index + closer[0].length; - (sections.includes(true) ? folded : shown).push(line.slice(0, end)); - sections.pop(); - const after = line.slice(end).trim(); - if (after !== "") (sections.includes(true) ? folded : shown).push(after); + while (sections.length > 0 && closer !== null) { + const end = closer.index + closer[0].length; + (sections.includes(true) ? folded : shown).push(rest.slice(0, end)); + sections.pop(); + rest = rest.slice(end); + closer = /<\/details>/iu.exec(rest); + } + if (rest.trim() !== "") (sections.includes(true) ? folded : shown).push(rest.trim()); } return folded.length === 0 ? body : [...shown, "", ...folded].join("\n").trim(); } From a181da79249675937ee7187898c318ac868f6d78 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:41:19 +0100 Subject: [PATCH 08/10] fix(web): count every details tag on a line in order Co-Authored-By: Claude Opus 5.5 --- .../pullRequestDetail.logic.test.ts | 2 +- .../pullRequest/pullRequestDetail.logic.ts | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index 3df048b2f06d..d6d3c74d04bd 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -1306,7 +1306,7 @@ describe("adding a remark to the chat", () => { kind: "comment", comment: remark( "c2", - `
\n
\n${"script ".repeat(400)}
\nFinding.`, + `
\n
\n${"script ".repeat(400)}
\n${"more ".repeat(400)}\n
\nFinding.`, ), }); diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 48e90ed96460..2e238043b157 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -735,25 +735,26 @@ function visibleTextFirst(body: string): string { const sections: boolean[] = []; for (const [index, line] of body.split("\n").entries()) { const inCode = codeLines.has(index + 1); - const opener = inCode ? null : /^\s*])([^>]*)/iu.exec(line); - // Quoted values are dropped first so `title="open logs"` does not read as the attribute. - const attributes = opener?.[1]?.replace(/"[^"]*"|'[^']*'/gu, "") ?? ""; - if (opener) sections.push(!/(?:^|\s)open(?:[\s=/]|$)/iu.test(attributes)); - // Each closing tag ends a section; text after it goes with what follows. - let rest = line; - let closer = inCode ? null : /<\/details>/iu.exec(rest); - if (sections.length === 0 || closer === null) { - (sections.includes(true) ? folded : shown).push(line); - continue; - } - while (sections.length > 0 && closer !== null) { - const end = closer.index + closer[0].length; - (sections.includes(true) ? folded : shown).push(rest.slice(0, end)); - sections.pop(); - rest = rest.slice(end); - closer = /<\/details>/iu.exec(rest); + // Only a line that starts as a details block opens sections; a tag named in prose does not. + const opens = !inCode && /^\s*])/iu.test(line); + let from = 0; + for (const tag of inCode ? [] : line.matchAll(/])([^>]*)>?|<\/details>/giu)) { + if (tag[0].startsWith(" Date: Tue, 17 Nov 2026 20:28:25 +0100 Subject: [PATCH 09/10] fix(web): a single remark keeps its visible text ahead of collapsed details Co-Authored-By: Claude Sonnet 5.5 --- .../src/components/pullRequest/pullRequestDetail.logic.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 2e238043b157..5947bd485bf9 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -1393,7 +1393,10 @@ export function buildPullRequestCommentContext( startIndex: 0, endIndex: 0, rangeLabel: "comment", - text: remarkText(`${author}: ${body}`.trim(), reviewLineComments(comment, pullRequest)), + text: remarkText( + `${author}: ${visibleTextFirst(body)}`.trim(), + reviewLineComments(comment, pullRequest), + ), diff: "", ...(comment.path === null ? {} From 61c543d85980620f4832cfacca124b22b2f9ca71 Mon Sep 17 00:00:00 2001 From: Tony <97451137+TonybynMp4@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:45:30 +0100 Subject: [PATCH 10/10] fix(web): read code block lines from Words' tree after the remark removal Co-Authored-By: Claude Sonnet 5.5 --- .../pullRequest/pullRequestDetail.logic.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 5947bd485bf9..b9501ba2b27e 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -719,22 +719,32 @@ function readableBody(raw: string): string | null { */ function visibleTextFirst(body: string): string { if (body.length <= FINDING_BODY_MAX_LENGTH) return body; + const lines = body.split("\n"); + const lineStarts: number[] = []; + let offset = 0; + for (const line of lines) { + lineStarts.push(offset); + offset += line.length + 1; + } const codeLines = new Set(); - const visit = (node: MdastNodes) => { - if (node.type === "code" && node.position !== undefined) { - for (let line = node.position.start.line; line <= node.position.end.line; line += 1) { - codeLines.add(line); - } + const visit = (node: Nodes) => { + // Words' source positions carry offsets only; their line numbers are not source lines. + const start = node.position?.start.offset; + const end = node.position?.end.offset; + if (node.type === "element" && node.tagName === "pre" && start != null && end != null) { + lineStarts.forEach((lineStart, index) => { + if (lineStart < end && lineStart + lines[index]!.length >= start) codeLines.add(index); + }); } if ("children" in node) for (const child of node.children) visit(child); }; - visit(fromMarkdown(body)); + visit(markdownTree(body, { skipHtml: true })); const shown: string[] = []; const folded: string[] = []; // Whether each open section starts collapsed; `
` reads as visible text. const sections: boolean[] = []; - for (const [index, line] of body.split("\n").entries()) { - const inCode = codeLines.has(index + 1); + for (const [index, line] of lines.entries()) { + const inCode = codeLines.has(index); // Only a line that starts as a details block opens sections; a tag named in prose does not. const opens = !inCode && /^\s*])/iu.test(line); let from = 0; @@ -1387,6 +1397,7 @@ export function buildPullRequestCommentContext( return { id: `pr-comment:${pullRequest.url}:comment:${comment.id}`, sectionId: `pull-request:${pullRequestNumber}`, + // oxlint-disable-next-line t3code/no-untranslated-copy -- context title sent to the agent sectionTitle: `PR #${pullRequestNumber} conversation`, // The chip wears `filePath rangeLabel`: the file a remark names, or who wrote one that names none. filePath: comment.path ?? `@${author}`,