From b56ca1865a5c7de54b1b710e3a18648751db4a14 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 1/9] 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 611185ec9f308..0034313fd8d42 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, @@ -1151,14 +1152,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 efc94af2ace37..1e6f753171648 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -230,15 +230,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; @@ -732,8 +731,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 canReact = reactions.canReact(event); @@ -307,7 +304,7 @@ function ConversationCard({ setEditing(true)} /> ) : null} {resolveButton} - {event.body && event.comment && !reply ? ( + {event.body && event.comment ? ( ) : null} {canReact || event.reactions.length > 0 ? ( @@ -550,7 +547,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 4f25b26f3276e..58a54ac2c301e 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 94677bce8eee7..53f20fab80797 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -703,6 +703,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. @@ -1259,8 +1273,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 @@ -1276,35 +1292,56 @@ 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}`, 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 bec96cd785f00a95a8fda87817e372fbd10c86f7 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 2/9] 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 58a54ac2c301e..45f4e73b10a5b 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 53f20fab80797..0dcf721cdc91e 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -703,16 +703,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 3634279f5460c7ae98c8a494ba35633a91f91f29 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 3/9] 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 45f4e73b10a5b..890f78f2cbf29 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 0dcf721cdc91e..c50156f9924fa 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -721,12 +721,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 f866393ba5317108d651919b9a54ee8b0833092c 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 4/9] 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 890f78f2cbf29..14d487f7f5a30 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 c50156f9924fa..8bb8ee361dde4 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -728,7 +728,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(); } @@ -1289,6 +1289,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 } @@ -1339,7 +1363,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 86d11ffeb220fa34499ef672762f2ecd9930b3f2 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 5/9] 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 14d487f7f5a30..abcb11dc1c125 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 8bb8ee361dde4..df6ce9ba32e0d 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -726,7 +726,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 e64a9b522d090f7595707135aa60d8b12dbaaa2e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 18:38:47 +0000 Subject: [PATCH 6/9] 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 1e6f753171648..bd86ac7ac481f 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -731,7 +731,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 df6ce9ba32e0d..ab1506d5ab47a 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -729,8 +729,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 833543f803d1fc596ecac1cf04bafeaf22bd46ad 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 7/9] 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 cbfb5092e39fb..e19cb7c179664 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 ab1506d5ab47a..9d7d954fae7e2 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -729,17 +729,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 d447fca674f0594ffa6b6affffc9ade40a9fc652 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 8/9] 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 e19cb7c179664..2bcf1c6521ab7 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 9d7d954fae7e2..32d07e4669613 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -725,25 +725,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 9/9] 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 32d07e4669613..56bdc36f54f39 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -1362,7 +1362,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 ? {}