From 683ec02349e18c4c7ba29ad898fd4c66e9b301fc Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:55:11 +0100 Subject: [PATCH 01/10] test(server): cover Claude questions after quoted command output Co-authored-by: GPT 6.2 Sol --- .../src/project/AgentSessionScanner.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index adc34b2348cb..489737bcc1f9 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -3687,6 +3687,34 @@ describe("parseAgentSessionTranscript", () => { }); }); + it("preserves a Claude question after quoted command output", () => { + const question = "Why did this change?"; + const prompt = `Enabled plan mode\n${question}`; + const thread = AgentSessionScanner.parseAgentSessionTranscript({ + contents: [ + ["user", "Help me understand plan mode"], + ["assistant", "What did the command print?"], + ["user", prompt], + ["assistant", "The command enabled plan mode."], + ] + .map(([role, content]) => + encodeTranscriptRecord({ type: role, message: { role, content } }), + ) + .join("\n"), + source: "claudeAgent", + providerInstanceId: ProviderInstanceId.make("claudeAgent"), + fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", + lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), + }); + + expect( + thread?.messages + .filter((message) => message.role === "user") + .map((message) => message.text) + .join("\n"), + ).toContain(question); + }); + it.each([ { customTitles: ["Refactor auth module"], expected: "Refactor auth module" }, // Claude writes an empty customTitle when the user clears a rename. From 66c8b14bd1f317fbe28a0defb1a38bae54f898c8 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:55:57 +0100 Subject: [PATCH 02/10] fix(server): Claude imports keep questions after quoted command output Co-authored-by: GPT 6.2 Sol --- apps/server/src/project/AgentSessionScanner.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index f45c8fcf2a83..1354157e91f1 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -422,8 +422,17 @@ function codexHistoryBase(records: ReadonlyArray) { // Claude Code records its own UI as user turns: slash commands, `!` shell runs and // their output, task notifications. Keep what the user typed, as they typed it. -const CLAUDE_UI_OUTPUT = - /^(?:<(?:task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>|\[Request interrupted by user(?: for tool use)?\]$)/; +function isClaudeUiOutput(text: string): boolean { + if (/^\[Request interrupted by user(?: for tool use)?\]$/.test(text)) return true; + if (!text.startsWith("<")) return false; + const block = + /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>\s*/y; + // Consume each block at its first closing tag so prose between blocks stays visible. + while (block.test(text)) { + if (block.lastIndex === text.length) return true; + } + return false; +} /** * A slash command as typed. Its arguments may name the thread; a bare command @@ -440,7 +449,7 @@ function claudeCommand(text: string): { readonly text: string; readonly titleTex /** What a Claude user turn shows the user typed, and the part of it that may name the thread. */ function claudeUserText(text: string): { readonly text: string; readonly titleText: string } { - if (CLAUDE_UI_OUTPUT.test(text)) return { text: "", titleText: "" }; + if (isClaudeUiOutput(text)) return { text: "", titleText: "" }; const shellInput = /^([\s\S]*)<\/bash-input>$/.exec(text)?.[1]; if (shellInput !== undefined) return { text: `!${shellInput}`, titleText: "" }; return claudeCommand(text) ?? { text, titleText: text }; From 8af66b40aa684296c958c70ae0ade248f452c0cc Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:00:04 +0100 Subject: [PATCH 03/10] refactor(server): drop redundant leading-tag fast path in isClaudeUiOutput The sticky block regex already fails at index 0 when the text does not start with a tag. Co-authored-by: Claude Opus 5.5 --- apps/server/src/project/AgentSessionScanner.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 1354157e91f1..9528d9ec8cbf 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -424,7 +424,6 @@ function codexHistoryBase(records: ReadonlyArray) { // their output, task notifications. Keep what the user typed, as they typed it. function isClaudeUiOutput(text: string): boolean { if (/^\[Request interrupted by user(?: for tool use)?\]$/.test(text)) return true; - if (!text.startsWith("<")) return false; const block = /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>\s*/y; // Consume each block at its first closing tag so prose between blocks stays visible. From f812bd2376c359045ab05a72208201cbb1506e1e Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:09:02 +0100 Subject: [PATCH 04/10] fix(server): distinguish Claude markup from quoted prompts Co-authored-by: GPT 6.2 Sol --- .../AgentSessionScanner.claudeMarkup.test.ts | 48 +++++++++++++++++++ .../server/src/project/AgentSessionScanner.ts | 28 +++++++---- 2 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts diff --git a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts new file mode 100644 index 000000000000..5eeb629cad8c --- /dev/null +++ b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts @@ -0,0 +1,48 @@ +import { expect, it } from "@effect/vitest"; +import { ProviderInstanceId } from "@t3tools/contracts"; +import { parseAgentSessionTranscript } from "./AgentSessionScanner.ts"; + +function parseClaudeTurns(userTurns: ReadonlyArray) { + return parseAgentSessionTranscript({ + contents: [ + ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), + { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, + ] + .map((record) => JSON.stringify(record)) + .join("\n"), + source: "claudeAgent", + providerInstanceId: ProviderInstanceId.make("claudeAgent"), + fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", + lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), + }); +} + +it("hides shell output that ends with its own closing tag", () => { + const thread = parseClaudeTurns([ + "\n", + "What happened?", + ]); + + expect( + thread?.messages.filter((message) => message.role === "user").map((message) => message.text), + ).toEqual(["What happened?"]); +}); + +it("uses the prose after quoted command output to name the thread", () => { + const question = "Why did this change?"; + const prompt = `Enabled plan mode\n${question}`; + + expect(parseClaudeTurns([prompt])).toMatchObject({ + title: question, + messages: [{ role: "user", text: prompt }, { role: "assistant" }], + }); +}); + +it.each(["/review", "review"])( + "keeps a prompt that quotes %s before a question", + (quote) => { + const prompt = `${quote}\nWhy did this fail?`; + + expect(parseClaudeTurns([prompt])?.messages[0]).toMatchObject({ role: "user", text: prompt }); + }, +); diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 9528d9ec8cbf..db0f808afb90 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -422,15 +422,15 @@ function codexHistoryBase(records: ReadonlyArray) { // Claude Code records its own UI as user turns: slash commands, `!` shell runs and // their output, task notifications. Keep what the user typed, as they typed it. -function isClaudeUiOutput(text: string): boolean { - if (/^\[Request interrupted by user(?: for tool use)?\]$/.test(text)) return true; +function claudeUiOutputEnd(text: string): number { const block = - /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>\s*/y; - // Consume each block at its first closing tag so prose between blocks stays visible. + /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>(?:\s*<\/\1>)*\s*/y; + // Shell output can end with a literal copy of its wrapper's closing tag. + let end = 0; while (block.test(text)) { - if (block.lastIndex === text.length) return true; + end = block.lastIndex; } - return false; + return end; } /** @@ -439,6 +439,12 @@ function isClaudeUiOutput(text: string): boolean { */ function claudeCommand(text: string): { readonly text: string; readonly titleText: string } | null { if (!/^/.test(text)) return null; + const block = /[\s\S]*?<\/command-\1>\s*/y; + let end = 0; + while (block.test(text)) { + end = block.lastIndex; + } + if (end !== text.length) return null; const name = /([^<]*)<\/command-name>/.exec(text)?.[1]?.trim() || `/${/([^<]*)<\/command-message>/.exec(text)?.[1]?.trim() ?? ""}`; @@ -448,10 +454,16 @@ function claudeCommand(text: string): { readonly text: string; readonly titleTex /** What a Claude user turn shows the user typed, and the part of it that may name the thread. */ function claudeUserText(text: string): { readonly text: string; readonly titleText: string } { - if (isClaudeUiOutput(text)) return { text: "", titleText: "" }; + const outputEnd = claudeUiOutputEnd(text); + if ( + outputEnd === text.length || + /^\[Request interrupted by user(?: for tool use)?\]$/.test(text) + ) { + return { text: "", titleText: "" }; + } const shellInput = /^([\s\S]*)<\/bash-input>$/.exec(text)?.[1]; if (shellInput !== undefined) return { text: `!${shellInput}`, titleText: "" }; - return claudeCommand(text) ?? { text, titleText: text }; + return claudeCommand(text) ?? { text, titleText: text.slice(outputEnd) }; } function claudeVisibleText(record: DecodedTranscriptRecord) { From f52481cff15211981f0f9b4d5d5a832271f99786 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:10:55 +0100 Subject: [PATCH 05/10] test(server): fold Claude markup cases into the transcript parser suite Drops the separate test file and its own copy of the transcript setup. Co-authored-by: Claude Opus 5.5 --- .../AgentSessionScanner.claudeMarkup.test.ts | 48 ------------------- .../src/project/AgentSessionScanner.test.ts | 44 +++++++++++++++++ 2 files changed, 44 insertions(+), 48 deletions(-) delete mode 100644 apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts diff --git a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts deleted file mode 100644 index 5eeb629cad8c..000000000000 --- a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { expect, it } from "@effect/vitest"; -import { ProviderInstanceId } from "@t3tools/contracts"; -import { parseAgentSessionTranscript } from "./AgentSessionScanner.ts"; - -function parseClaudeTurns(userTurns: ReadonlyArray) { - return parseAgentSessionTranscript({ - contents: [ - ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), - { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, - ] - .map((record) => JSON.stringify(record)) - .join("\n"), - source: "claudeAgent", - providerInstanceId: ProviderInstanceId.make("claudeAgent"), - fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", - lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), - }); -} - -it("hides shell output that ends with its own closing tag", () => { - const thread = parseClaudeTurns([ - "\n", - "What happened?", - ]); - - expect( - thread?.messages.filter((message) => message.role === "user").map((message) => message.text), - ).toEqual(["What happened?"]); -}); - -it("uses the prose after quoted command output to name the thread", () => { - const question = "Why did this change?"; - const prompt = `Enabled plan mode\n${question}`; - - expect(parseClaudeTurns([prompt])).toMatchObject({ - title: question, - messages: [{ role: "user", text: prompt }, { role: "assistant" }], - }); -}); - -it.each(["/review", "review"])( - "keeps a prompt that quotes %s before a question", - (quote) => { - const prompt = `${quote}\nWhy did this fail?`; - - expect(parseClaudeTurns([prompt])?.messages[0]).toMatchObject({ role: "user", text: prompt }); - }, -); diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 489737bcc1f9..b096b9592b54 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -3715,6 +3715,50 @@ describe("parseAgentSessionTranscript", () => { ).toContain(question); }); + const parseClaudeTurns = (userTurns: ReadonlyArray) => + AgentSessionScanner.parseAgentSessionTranscript({ + contents: [ + ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), + { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, + ] + .map((record) => encodeTranscriptRecord(record)) + .join("\n"), + source: "claudeAgent", + providerInstanceId: ProviderInstanceId.make("claudeAgent"), + fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", + lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), + }); + + it("hides shell output that ends with its own closing tag", () => { + const thread = parseClaudeTurns([ + "\n", + "What happened?", + ]); + + expect( + thread?.messages.filter((message) => message.role === "user").map((message) => message.text), + ).toEqual(["What happened?"]); + }); + + it("uses the prose after quoted command output to name the thread", () => { + const question = "Why did this change?"; + const prompt = `Enabled plan mode\n${question}`; + + expect(parseClaudeTurns([prompt])).toMatchObject({ + title: question, + messages: [{ role: "user", text: prompt }, { role: "assistant" }], + }); + }); + + it.each(["/review", "review"])( + "keeps a prompt that quotes %s before a question", + (quote) => { + const prompt = `${quote}\nWhy did this fail?`; + + expect(parseClaudeTurns([prompt])?.messages[0]).toMatchObject({ role: "user", text: prompt }); + }, + ); + it.each([ { customTitles: ["Refactor auth module"], expected: "Refactor auth module" }, // Claude writes an empty customTitle when the user clears a rename. From e44f39217655f1efb01b2083999ac99faa93690d Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:11:44 +0100 Subject: [PATCH 06/10] refactor(server): share one leading-block scan for Claude UI output and commands Co-authored-by: Claude Opus 5.5 --- .../server/src/project/AgentSessionScanner.ts | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index db0f808afb90..30a932db92f1 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -420,12 +420,8 @@ function codexHistoryBase(records: ReadonlyArray) { : undefined; } -// Claude Code records its own UI as user turns: slash commands, `!` shell runs and -// their output, task notifications. Keep what the user typed, as they typed it. -function claudeUiOutputEnd(text: string): number { - const block = - /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>(?:\s*<\/\1>)*\s*/y; - // Shell output can end with a literal copy of its wrapper's closing tag. +// Where the run of sticky `block` matches at the start of `text` ends. +function leadingBlocksEnd(text: string, block: RegExp): number { let end = 0; while (block.test(text)) { end = block.lastIndex; @@ -433,18 +429,27 @@ function claudeUiOutputEnd(text: string): number { return end; } +// Claude Code records its own UI as user turns: slash commands, `!` shell runs and +// their output, task notifications. Keep what the user typed, as they typed it. +function claudeUiOutputEnd(text: string): number { + // Shell output can end with a literal copy of its wrapper's closing tag. + return leadingBlocksEnd( + text, + /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>(?:\s*<\/\1>)*\s*/y, + ); +} + /** * A slash command as typed. Its arguments may name the thread; a bare command * leaves that to a later prompt. Null for any other text. */ function claudeCommand(text: string): { readonly text: string; readonly titleText: string } | null { if (!/^/.test(text)) return null; - const block = /[\s\S]*?<\/command-\1>\s*/y; - let end = 0; - while (block.test(text)) { - end = block.lastIndex; - } - if (end !== text.length) return null; + if ( + leadingBlocksEnd(text, /[\s\S]*?<\/command-\1>\s*/y) !== + text.length + ) + return null; const name = /([^<]*)<\/command-name>/.exec(text)?.[1]?.trim() || `/${/([^<]*)<\/command-message>/.exec(text)?.[1]?.trim() ?? ""}`; From 9d047d0e085092c8d042cf09c7f06c10b1647d44 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:12:28 +0100 Subject: [PATCH 07/10] Revert "test(server): fold Claude markup cases into the transcript parser suite" The gate keeps the repro test file as the test commit added it, so the new cases live in their own file. Co-authored-by: Claude Opus 5.5 --- .../AgentSessionScanner.claudeMarkup.test.ts | 48 +++++++++++++++++++ .../src/project/AgentSessionScanner.test.ts | 44 ----------------- 2 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts diff --git a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts new file mode 100644 index 000000000000..5eeb629cad8c --- /dev/null +++ b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts @@ -0,0 +1,48 @@ +import { expect, it } from "@effect/vitest"; +import { ProviderInstanceId } from "@t3tools/contracts"; +import { parseAgentSessionTranscript } from "./AgentSessionScanner.ts"; + +function parseClaudeTurns(userTurns: ReadonlyArray) { + return parseAgentSessionTranscript({ + contents: [ + ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), + { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, + ] + .map((record) => JSON.stringify(record)) + .join("\n"), + source: "claudeAgent", + providerInstanceId: ProviderInstanceId.make("claudeAgent"), + fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", + lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), + }); +} + +it("hides shell output that ends with its own closing tag", () => { + const thread = parseClaudeTurns([ + "\n", + "What happened?", + ]); + + expect( + thread?.messages.filter((message) => message.role === "user").map((message) => message.text), + ).toEqual(["What happened?"]); +}); + +it("uses the prose after quoted command output to name the thread", () => { + const question = "Why did this change?"; + const prompt = `Enabled plan mode\n${question}`; + + expect(parseClaudeTurns([prompt])).toMatchObject({ + title: question, + messages: [{ role: "user", text: prompt }, { role: "assistant" }], + }); +}); + +it.each(["/review", "review"])( + "keeps a prompt that quotes %s before a question", + (quote) => { + const prompt = `${quote}\nWhy did this fail?`; + + expect(parseClaudeTurns([prompt])?.messages[0]).toMatchObject({ role: "user", text: prompt }); + }, +); diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index b096b9592b54..489737bcc1f9 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -3715,50 +3715,6 @@ describe("parseAgentSessionTranscript", () => { ).toContain(question); }); - const parseClaudeTurns = (userTurns: ReadonlyArray) => - AgentSessionScanner.parseAgentSessionTranscript({ - contents: [ - ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), - { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, - ] - .map((record) => encodeTranscriptRecord(record)) - .join("\n"), - source: "claudeAgent", - providerInstanceId: ProviderInstanceId.make("claudeAgent"), - fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", - lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), - }); - - it("hides shell output that ends with its own closing tag", () => { - const thread = parseClaudeTurns([ - "\n", - "What happened?", - ]); - - expect( - thread?.messages.filter((message) => message.role === "user").map((message) => message.text), - ).toEqual(["What happened?"]); - }); - - it("uses the prose after quoted command output to name the thread", () => { - const question = "Why did this change?"; - const prompt = `Enabled plan mode\n${question}`; - - expect(parseClaudeTurns([prompt])).toMatchObject({ - title: question, - messages: [{ role: "user", text: prompt }, { role: "assistant" }], - }); - }); - - it.each(["/review", "review"])( - "keeps a prompt that quotes %s before a question", - (quote) => { - const prompt = `${quote}\nWhy did this fail?`; - - expect(parseClaudeTurns([prompt])?.messages[0]).toMatchObject({ role: "user", text: prompt }); - }, - ); - it.each([ { customTitles: ["Refactor auth module"], expected: "Refactor auth module" }, // Claude writes an empty customTitle when the user clears a rename. From 0502adb753323c3a52f852007db76fbb72b914b7 Mon Sep 17 00:00:00 2001 From: Wout Stiens <71498452+StiensWout@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:18:54 +0100 Subject: [PATCH 08/10] fix(server): hide Claude shell output with embedded closing tags Co-authored-by: GPT 6.2 Sol --- .../project/AgentSessionScanner.claudeMarkup.test.ts | 11 ++++++----- apps/server/src/project/AgentSessionScanner.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts index 5eeb629cad8c..9856ebf918bf 100644 --- a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts +++ b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts @@ -17,11 +17,12 @@ function parseClaudeTurns(userTurns: ReadonlyArray) { }); } -it("hides shell output that ends with its own closing tag", () => { - const thread = parseClaudeTurns([ - "\n", - "What happened?", - ]); +it.each([ + "\n", + "\nfinished\n", + "\nfinished\n", +])("hides shell output that prints its own closing tag (%s)", (output) => { + const thread = parseClaudeTurns([output, "What happened?"]); expect( thread?.messages.filter((message) => message.role === "user").map((message) => message.text), diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 30a932db92f1..b8fb6b1d6998 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -432,13 +432,17 @@ function leadingBlocksEnd(text: string, block: RegExp): number { // Claude Code records its own UI as user turns: slash commands, `!` shell runs and // their output, task notifications. Keep what the user typed, as they typed it. function claudeUiOutputEnd(text: string): number { - // Shell output can end with a literal copy of its wrapper's closing tag. return leadingBlocksEnd( text, - /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>(?:\s*<\/\1>)*\s*/y, + /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>\s*/y, ); } +// Shell payloads can print closing tags verbatim. Only use the outer closing +// tag for a complete envelope so prose after a quoted block stays visible. +const CLAUDE_SHELL_OUTPUT = + /^(?:[\s\S]*<\/bash-stdout>(?:\s*[\s\S]*<\/bash-stderr>)?|[\s\S]*<\/bash-stderr>)$/; + /** * A slash command as typed. Its arguments may name the thread; a bare command * leaves that to a later prompt. Null for any other text. @@ -462,6 +466,7 @@ function claudeUserText(text: string): { readonly text: string; readonly titleTe const outputEnd = claudeUiOutputEnd(text); if ( outputEnd === text.length || + CLAUDE_SHELL_OUTPUT.test(text) || /^\[Request interrupted by user(?: for tool use)?\]$/.test(text) ) { return { text: "", titleText: "" }; From 3151cb7c43976ed02c21d1e9f112e1fa565b708a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 25 Nov 2026 07:40:45 +0000 Subject: [PATCH 09/10] fix(server): name Claude threads after prose following quoted command markup A prompt that quotes markup before a question now takes its title from the question instead of the markup line. The Claude markup cases move into the transcript parser suite, which replaces the separate file and the overlapping repro test. Co-Authored-By: Claude Opus 5.5 --- .../AgentSessionScanner.claudeMarkup.test.ts | 49 ------------------- .../src/project/AgentSessionScanner.test.ts | 41 ++++++++++------ .../server/src/project/AgentSessionScanner.ts | 15 +++--- 3 files changed, 34 insertions(+), 71 deletions(-) delete mode 100644 apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts diff --git a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts b/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts deleted file mode 100644 index 9856ebf918bf..000000000000 --- a/apps/server/src/project/AgentSessionScanner.claudeMarkup.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { expect, it } from "@effect/vitest"; -import { ProviderInstanceId } from "@t3tools/contracts"; -import { parseAgentSessionTranscript } from "./AgentSessionScanner.ts"; - -function parseClaudeTurns(userTurns: ReadonlyArray) { - return parseAgentSessionTranscript({ - contents: [ - ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), - { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, - ] - .map((record) => JSON.stringify(record)) - .join("\n"), - source: "claudeAgent", - providerInstanceId: ProviderInstanceId.make("claudeAgent"), - fallbackSessionId: "62c057bb-b316-4b29-be2c-140090d71254", - lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), - }); -} - -it.each([ - "\n", - "\nfinished\n", - "\nfinished\n", -])("hides shell output that prints its own closing tag (%s)", (output) => { - const thread = parseClaudeTurns([output, "What happened?"]); - - expect( - thread?.messages.filter((message) => message.role === "user").map((message) => message.text), - ).toEqual(["What happened?"]); -}); - -it("uses the prose after quoted command output to name the thread", () => { - const question = "Why did this change?"; - const prompt = `Enabled plan mode\n${question}`; - - expect(parseClaudeTurns([prompt])).toMatchObject({ - title: question, - messages: [{ role: "user", text: prompt }, { role: "assistant" }], - }); -}); - -it.each(["/review", "review"])( - "keeps a prompt that quotes %s before a question", - (quote) => { - const prompt = `${quote}\nWhy did this fail?`; - - expect(parseClaudeTurns([prompt])?.messages[0]).toMatchObject({ role: "user", text: prompt }); - }, -); diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 489737bcc1f9..1ac5624df938 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -3687,19 +3687,13 @@ describe("parseAgentSessionTranscript", () => { }); }); - it("preserves a Claude question after quoted command output", () => { - const question = "Why did this change?"; - const prompt = `Enabled plan mode\n${question}`; - const thread = AgentSessionScanner.parseAgentSessionTranscript({ + const parseClaudeUserTurns = (userTurns: ReadonlyArray) => + AgentSessionScanner.parseAgentSessionTranscript({ contents: [ - ["user", "Help me understand plan mode"], - ["assistant", "What did the command print?"], - ["user", prompt], - ["assistant", "The command enabled plan mode."], + ...userTurns.map((content) => ({ type: "user", message: { role: "user", content } })), + { type: "assistant", message: { role: "assistant", content: "Here is what happened." } }, ] - .map(([role, content]) => - encodeTranscriptRecord({ type: role, message: { role, content } }), - ) + .map((record) => encodeTranscriptRecord(record)) .join("\n"), source: "claudeAgent", providerInstanceId: ProviderInstanceId.make("claudeAgent"), @@ -3707,12 +3701,27 @@ describe("parseAgentSessionTranscript", () => { lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"), }); + it.each([ + "Enabled plan mode", + "/review\nreview", + ])("keeps a Claude question after quoted %s and names the thread after it", (quote) => { + const prompt = `${quote}\nWhy did this change?`; + + expect(parseClaudeUserTurns([prompt])).toMatchObject({ + title: "Why did this change?", + messages: [{ role: "user", text: prompt }, { role: "assistant" }], + }); + }); + + it.each([ + "\nfinished\n", + "\nfinished\n", + ])("hides Claude shell output that prints its own closing tag (%s)", (output) => { expect( - thread?.messages - .filter((message) => message.role === "user") - .map((message) => message.text) - .join("\n"), - ).toContain(question); + parseClaudeUserTurns([output, "What happened?"]) + ?.messages.filter((message) => message.role === "user") + .map((message) => message.text), + ).toEqual(["What happened?"]); }); it.each([ diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index b8fb6b1d6998..3e9586c4f1e8 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -443,17 +443,15 @@ function claudeUiOutputEnd(text: string): number { const CLAUDE_SHELL_OUTPUT = /^(?:[\s\S]*<\/bash-stdout>(?:\s*[\s\S]*<\/bash-stderr>)?|[\s\S]*<\/bash-stderr>)$/; +const CLAUDE_COMMAND_BLOCK = /[\s\S]*?<\/command-\1>\s*/y; + /** * A slash command as typed. Its arguments may name the thread; a bare command * leaves that to a later prompt. Null for any other text. */ function claudeCommand(text: string): { readonly text: string; readonly titleText: string } | null { if (!/^/.test(text)) return null; - if ( - leadingBlocksEnd(text, /[\s\S]*?<\/command-\1>\s*/y) !== - text.length - ) - return null; + if (leadingBlocksEnd(text, CLAUDE_COMMAND_BLOCK) !== text.length) return null; const name = /([^<]*)<\/command-name>/.exec(text)?.[1]?.trim() || `/${/([^<]*)<\/command-message>/.exec(text)?.[1]?.trim() ?? ""}`; @@ -473,7 +471,12 @@ function claudeUserText(text: string): { readonly text: string; readonly titleTe } const shellInput = /^([\s\S]*)<\/bash-input>$/.exec(text)?.[1]; if (shellInput !== undefined) return { text: `!${shellInput}`, titleText: "" }; - return claudeCommand(text) ?? { text, titleText: text.slice(outputEnd) }; + return ( + claudeCommand(text) ?? { + text, + titleText: text.slice(outputEnd || leadingBlocksEnd(text, CLAUDE_COMMAND_BLOCK)), + } + ); } function claudeVisibleText(record: DecodedTranscriptRecord) { From b4fcd912fa2aacb8a3f8d9cbaddc9278445046d7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 25 Nov 2026 08:02:38 +0000 Subject: [PATCH 10/10] fix(server): scan Claude shell envelopes linearly and keep task notifications hidden The complete-envelope regex backtracked quadratically on quoted output full of shell closing tags, stalling the server for seconds. It is now a prefix and suffix check plus one linear search for the stdout/stderr seam. Task notifications can carry markup Claude appends after the closing tag, so any turn that starts with is hidden again, as on main. Co-Authored-By: Claude Opus 5.5 --- .../src/project/AgentSessionScanner.test.ts | 12 ++++++++++- .../server/src/project/AgentSessionScanner.ts | 20 +++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/server/src/project/AgentSessionScanner.test.ts b/apps/server/src/project/AgentSessionScanner.test.ts index 1ac5624df938..acda443fd58a 100644 --- a/apps/server/src/project/AgentSessionScanner.test.ts +++ b/apps/server/src/project/AgentSessionScanner.test.ts @@ -3713,10 +3713,20 @@ describe("parseAgentSessionTranscript", () => { }); }); + it("keeps a Claude question after quoted output full of shell closing tags", () => { + const prompt = `${"".repeat(16_000)}\nWhy did this change?`; + + expect(parseClaudeUserTurns([prompt])).toMatchObject({ + title: "Why did this change?", + messages: [{ role: "user", text: prompt }, { role: "assistant" }], + }); + }); + it.each([ "\nfinished\n", "\nfinished\n", - ])("hides Claude shell output that prints its own closing tag (%s)", (output) => { + "\na1\ncompleted\n\nBash, Read", + ])("hides Claude output with trailing markup of its own (%s)", (output) => { expect( parseClaudeUserTurns([output, "What happened?"]) ?.messages.filter((message) => message.role === "user") diff --git a/apps/server/src/project/AgentSessionScanner.ts b/apps/server/src/project/AgentSessionScanner.ts index 3e9586c4f1e8..0f492c6c04db 100644 --- a/apps/server/src/project/AgentSessionScanner.ts +++ b/apps/server/src/project/AgentSessionScanner.ts @@ -434,14 +434,20 @@ function leadingBlocksEnd(text: string, block: RegExp): number { function claudeUiOutputEnd(text: string): number { return leadingBlocksEnd( text, - /<(task-notification|local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>\s*/y, + /<(local-command-stdout|local-command-stderr|local-command-caveat|bash-stdout|bash-stderr)>[\s\S]*?<\/\1>\s*/y, ); } -// Shell payloads can print closing tags verbatim. Only use the outer closing -// tag for a complete envelope so prose after a quoted block stays visible. -const CLAUDE_SHELL_OUTPUT = - /^(?:[\s\S]*<\/bash-stdout>(?:\s*[\s\S]*<\/bash-stderr>)?|[\s\S]*<\/bash-stderr>)$/; +// Shell payloads can print closing tags verbatim, so a complete envelope is +// judged by its outer tags; prose after a quoted block stays visible. +function isClaudeShellOutput(text: string): boolean { + if (text.startsWith("")) return text.endsWith(""); + if (!text.startsWith("")) return false; + return ( + text.endsWith("") || + (text.endsWith("") && /<\/bash-stdout>\s*/.test(text)) + ); +} const CLAUDE_COMMAND_BLOCK = /[\s\S]*?<\/command-\1>\s*/y; @@ -464,7 +470,9 @@ function claudeUserText(text: string): { readonly text: string; readonly titleTe const outputEnd = claudeUiOutputEnd(text); if ( outputEnd === text.length || - CLAUDE_SHELL_OUTPUT.test(text) || + // Only Claude writes task notifications, sometimes with trailing markup of its own. + text.startsWith("") || + isClaudeShellOutput(text) || /^\[Request interrupted by user(?: for tool use)?\]$/.test(text) ) { return { text: "", titleText: "" };