The best way to control Claude Code, Codex and more from any computer or phone
fix(web): preview annotations in question answers reach the agent with their text (#36357)
Julius Marminge committed
Nov 13, 2026 at 12:46 UTC
cfc71e1a9962114dee9fdf1855c07fc85adcdcd1
3 files changed
+71
-20
apps/web/src/components/chat/usePendingThreadRequests.ts
+6
-9
@@ -22,7 +22,6 @@ import { useShallow } from "zustand/react/shallow";
22
import { type DraftId, useComposerDraftStore } from "../../composerDraftStore";
23
import { useStableCallback } from "../../hooks/useStableCallback";
24
import { getUploadedAttachments, useAttachmentUploadStore } from "../../lib/attachmentUploadQueue";
25
-import { reviewCommentContextRecord } from "../../lib/composerContextRecords";
25
import {
26
buildPendingUserInputAnswers,
27
setPendingUserInputCustomAnswer,
@@ -33,6 +32,7 @@ import {
32
carryDisplacedCustomAnswerIntoPrompt,
33
withdrawDisplacedCustomAnswerFromPrompt,
34
derivePendingUserInputProgress,
35
+ answerContextRecords,
36
projectPendingUserInputAnswer,
37
threadContextsReferencedByAnswer,
38
} from "../../pendingUserInput";
@@ -300,10 +300,7 @@ export function usePendingThreadRequests(input: {
300
if (userInputResponsesInFlight.current.has(responseKey)) return;
301
const attachmentsByQuestionId = new Map<string, UserInputAttachments[string]>();
302
const providerAnswers = { ...answers };
303
- // Diff comments land in the thread draft even when their chip is in an answer.
304
- const reviewCommentRecords = (
305
- useComposerDraftStore.getState().getComposerDraft(composerDraftTarget)?.reviewComments ?? []
306
- ).map(reviewCommentContextRecord);
303
+ const threadDraft = useComposerDraftStore.getState().getComposerDraft(composerDraftTarget);
304
for (const question of pendingInput.questions) {
305
const target = questionAttachmentDraftId(
306
environmentId,
@@ -313,10 +310,10 @@ export function usePendingThreadRequests(input: {
310
);
311
if ((useQuestionAttachmentPreparation.getState().counts[target] ?? 0) > 0) return;
312
const draft = useComposerDraftStore.getState().getComposerDraft(target);
316
- providerAnswers[question.id] = projectPendingUserInputAnswer(answers[question.id], [
317
- ...(draft?.threadContexts ?? []),
318
- ...reviewCommentRecords,
319
- ]);
313
+ providerAnswers[question.id] = projectPendingUserInputAnswer(
314
+ answers[question.id],
315
+ answerContextRecords(draft, threadDraft),
316
+ );
317
const attachments = draft ? [...draft.images, ...draft.files] : [];
318
if (attachments.length === 0) continue;
319
const uploaded = getUploadedAttachments({ environmentId, images: attachments });
apps/web/src/pendingUserInput.test.ts
+32
-10
@@ -1,10 +1,11 @@
1
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
import { describe, expect, it } from "vite-plus/test";
3
import { formatInlineContextReference } from "./lib/composerContextReferences";
4
-import { reviewCommentContextRecord, threadContextReference } from "./lib/composerContextRecords";
4
+import { threadContextReference } from "./lib/composerContextRecords";
5
import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
6
7
import {
8
+ answerContextRecords,
9
carryDisplacedCustomAnswerIntoPrompt,
10
derivePendingUserInputProgress,
11
projectPendingUserInputAnswer,
@@ -28,9 +29,9 @@ describe("projectPendingUserInputAnswer", () => {
29
);
30
});
31
31
- // regression: #28022 a review comment chip in an answer reached the agent as a bare link
32
- it("sends review comment chips with the comment text and diff", () => {
33
- const comment = reviewCommentContextRecord({
32
+ // regression: #28022, #36293 review comment and preview annotation chips in an answer reached the agent as bare links
33
+ it("sends thread draft chips with their full content", () => {
34
+ const reviewComment = {
35
id: "file-comment-1",
36
sectionId: "branch",
37
sectionTitle: "Changes",
@@ -41,15 +42,36 @@ describe("projectPendingUserInputAnswer", () => {
42
text: "Rename this to line two updated",
43
diff: "@@ -0,0 +2,1 @@\n+line two changed",
44
fenceLanguage: "diff",
45
+ };
46
+ const annotation = {
47
+ id: "annotation-1",
48
+ pageUrl: "http://localhost:3000/",
49
+ pageTitle: "Home",
50
+ comment: "FIRST NOTE: this features section looks too bare; add three feature cards",
51
+ elements: [],
52
+ regions: [],
53
+ strokes: [],
54
+ styleChanges: [],
55
+ screenshot: null,
56
+ createdAt: "2026-01-01T00:00:00.000Z",
57
+ };
58
+ const records = answerContextRecords(undefined, {
59
+ reviewComments: [reviewComment],
60
+ previewAnnotations: [annotation],
61
});
45
- const answer = `See my note: ${formatInlineContextReference({
46
- kind: "review-comment",
47
- contextId: comment.contextId,
48
- label: comment.label,
49
- })}`;
50
- const projected = projectPendingUserInputAnswer(answer, [comment]);
62
+ const answer = `See my notes: ${records
63
+ .map((record) =>
64
+ formatInlineContextReference({
65
+ kind: record.kind,
66
+ contextId: record.contextId,
67
+ label: record.label,
68
+ }),
69
+ )
70
+ .join(" ")}`;
71
+ const projected = projectPendingUserInputAnswer(answer, records);
72
expect(projected).toContain("Rename this to line two updated");
73
expect(projected).toContain("+line two changed");
74
+ expect(projected).toContain(`comment: ${annotation.comment}`);
75
});
76
77
// regression: #18789 answers to pending questions lost exact text and option values
apps/web/src/pendingUserInput.ts
+33
-1
@@ -1,4 +1,6 @@
1
import type {
2
+ PreviewAnnotationContextRecord,
3
+ PreviewAnnotationPayload,
4
ReviewCommentContextRecord,
5
ThreadContextRecord,
6
UserInputQuestion,
@@ -17,10 +19,40 @@ import {
19
} from "@t3tools/client-runtime/state/pending-user-input";
20
21
import { collectInlineContextIds } from "./lib/composerContextReferences";
22
+import {
23
+ previewAnnotationContextRecord,
24
+ reviewCommentContextRecord,
25
+} from "./lib/composerContextRecords";
26
+import type { ReviewCommentContext } from "./reviewCommentContext";
27
+
28
+type AnswerContextRecord =
29
+ | ThreadContextRecord
30
+ | ReviewCommentContextRecord
31
+ | PreviewAnnotationContextRecord;
32
+
33
+// Diff comments and preview annotations land in the thread draft even when their chip is in an answer.
34
+export function answerContextRecords(
35
+ questionDraft: { threadContexts: ReadonlyArray<ThreadContextRecord> } | null | undefined,
36
+ threadDraft:
37
+ | {
38
+ reviewComments: ReadonlyArray<ReviewCommentContext>;
39
+ previewAnnotations: ReadonlyArray<PreviewAnnotationPayload>;
40
+ }
41
+ | null
42
+ | undefined,
43
+): AnswerContextRecord[] {
44
+ return [
45
+ ...(questionDraft?.threadContexts ?? []),
46
+ ...(threadDraft?.reviewComments ?? []).map(reviewCommentContextRecord),
47
+ ...(threadDraft?.previewAnnotations ?? []).map((annotation) =>
48
+ previewAnnotationContextRecord(annotation),
49
+ ),
50
+ ];
51
+}
52
53
export function projectPendingUserInputAnswer(
54
answer: unknown,
23
- records: ReadonlyArray<ThreadContextRecord | ReviewCommentContextRecord>,
55
+ records: ReadonlyArray<AnswerContextRecord>,
56
) {
57
if (typeof answer !== "string" || records.length === 0) return answer;
58
const recordsById = new Map(records.map((record) => [record.contextId, record]));