The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 17:15 UTC
fix(clients): answer history no longer shows provider context from review comments (#35897)
Julius Marminge committed
Nov 12, 2026 at 19:45 UTC
afff0d3efe6f9ad22df9aebb3acb07bb144b49cd
3 files changed
+69
-1
packages/client-runtime/src/work-log/userInput.test.ts
new
+39
@@ -0,0 +1,39 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { getQuestionAnswerPreview, getQuestionAnswerText } from "./userInput.js";
4
+
5
+// Shape the web client submits for an answer holding a review-comment chip.
6
+const answerWithReviewComment = [
7
+ "See my note: [Review comment: notes.md L2; ref=review-comment_c1]",
8
+ "",
9
+ '<t3_context version="1">',
10
+ '<context kind="review-comment" id="review-comment_c1">',
11
+ "file: notes.md",
12
+ "range: L2 (2-2)",
13
+ "comment:",
14
+ " Rename this",
15
+ "diff:",
16
+ " +line changed",
17
+ "</context>",
18
+ "</t3_context>",
19
+].join("\n");
20
+
21
+describe("question answer display", () => {
22
+ it("keeps the provider context envelope out of answer history and preview", () => {
23
+ const history = getQuestionAnswerText(answerWithReviewComment);
24
+ const preview = getQuestionAnswerPreview({
25
+ requestId: "request-1",
26
+ answers: { q1: answerWithReviewComment },
27
+ attachmentsByQuestionId: {},
28
+ questionTextById: { q1: "What should change?" },
29
+ });
30
+
31
+ expect(history).toBe("See my note: [Review comment: notes.md L2]");
32
+ expect(preview).toContain("See my note:");
33
+ expect(preview).not.toContain("<t3_context");
34
+
35
+ const typedXml =
36
+ 'Use this XML literally: <t3_context version="1"><context kind="review-comment" id="example">keep me</context></t3_context>';
37
+ expect(getQuestionAnswerText(typedXml)).toBe(typedXml);
38
+ });
39
+});
packages/client-runtime/src/work-log/userInput.ts
+3
-1
@@ -1,4 +1,5 @@
1
import { type UserInputAttachmentAnswerPayload } from "@t3tools/contracts";
2
+import { composerContextProviderTextForDisplay } from "@t3tools/shared/composerContextReferences";
3
4
function record(value: unknown): Record<string, unknown> | undefined {
5
return value !== null && typeof value === "object" && !Array.isArray(value)
@@ -7,7 +8,8 @@ function record(value: unknown): Record<string, unknown> | undefined {
8
}
9
10
export function getQuestionAnswerText(value: unknown): string {
10
- if (typeof value === "string") return value;
11
+ // Answers holding context chips are stored in provider form.
12
+ if (typeof value === "string") return composerContextProviderTextForDisplay(value);
13
if (Array.isArray(value)) return value.map(getQuestionAnswerText).filter(Boolean).join(", ");
14
const nested = record(value);
15
return nested ? getQuestionAnswerText(nested.answers) : "";
packages/shared/src/composerContextReferences.ts
+27
@@ -427,6 +427,33 @@ export function projectComposerContextForProvider(input: {
427
return `${body}\n\n<${CONTEXT_ENVELOPE_TAG} version="1">\n${entries.join("\n")}\n</${CONTEXT_ENVELOPE_TAG}>`;
428
}
429
430
+const ENVELOPE_CLOSE = `</${CONTEXT_ENVELOPE_TAG}>`;
431
+const PROVIDER_MARKER = /\[([A-Z][^[\]:;\n]*): ([^[\];\n]*); ref=([^[\]\s]+)\]/g;
432
+const MARKER_ENVELOPE_PREFIX = `\n\n<${CONTEXT_ENVELOPE_TAG} version="1">\n<${CONTEXT_ENTRY_TAG} kind="`;
433
+
434
+/**
435
+ * Readable form of a single-reference `projectComposerContextForProvider` output, as question
436
+ * answers store it. Only an envelope right after its own marker is removed; typed XML stays.
437
+ */
438
+export function composerContextProviderTextForDisplay(text: string): string {
439
+ let result = "";
440
+ let cursor = 0;
441
+ for (const match of text.matchAll(PROVIDER_MARKER)) {
442
+ if (match.index < cursor) continue;
443
+ const markerEnd = match.index + match[0].length;
444
+ if (!text.startsWith(MARKER_ENVELOPE_PREFIX, markerEnd)) continue;
445
+ const kindEnd = text.indexOf('"', markerEnd + MARKER_ENVELOPE_PREFIX.length);
446
+ if (kindEnd === -1 || !text.startsWith(` id="${escapeAttribute(match[3]!)}"`, kindEnd + 1)) {
447
+ continue;
448
+ }
449
+ const close = text.indexOf(ENVELOPE_CLOSE, kindEnd);
450
+ if (close === -1) continue;
451
+ result += `${text.slice(cursor, match.index)}[${match[1]}: ${match[2]}]`;
452
+ cursor = close + ENVELOPE_CLOSE.length;
453
+ }
454
+ return result + text.slice(cursor);
455
+}
456
+
457
// An agent reads threads on its own machine and on those it links to, even when a draft
458
// moves between machines.
459
export function threadContextsOutsideEnvironment(input: {