The best way to control Claude Code, Codex and more from any computer or phone
fix(web): Cite is offered for text an agent sent with send_to_user (#36858)
Julius Marminge committed
Nov 14, 2026 at 10:11 UTC
3238db7a867a4ad5931ebf03d6a771f7d57e3f81
5 files changed
+79
-22
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+21
@@ -1209,6 +1209,27 @@ const CITATION_REQUEST = {
1209
} satisfies NonNullable<TimelineProps["citationRequest"]>;
1210
1211
describe("MessagesTimeline citations", () => {
1212
+ it("offers Cite for text an agent sent with send_to_user", async () => {
1213
+ const text = "The draft the next question refers to";
1214
+ await using screen = await renderTimeline(
1215
+ [
1216
+ {
1217
+ id: "sent",
1218
+ kind: "sent-message",
1219
+ createdAt: CREATED_AT,
1220
+ runId: RunId.make("run-sent"),
1221
+ text,
1222
+ },
1223
+ ],
1224
+ { onCiteAssistantText: () => true },
1225
+ );
1226
+ await expect.element(screen.getByText(text)).toHaveStyle({ pointerEvents: "auto" });
1227
+ await userEvent.tripleClick(screen.getByText(text));
1228
+ await expect
1229
+ .element(page.getByRole("button", { name: "Cite selection in composer" }))
1230
+ .toBeVisible();
1231
+ });
1232
+
1233
it("lands a citation present at mount under StrictMode", async () => {
1234
await using _screen = await renderElement(
1235
<StrictMode>
apps/web/src/components/chat/MessagesTimeline.tsx
+4
-3
@@ -676,9 +676,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
676
citationHistory._tag !== "failed"
677
? timelineEntries.find(
678
(entry) =>
679
- entry.kind === "message" &&
680
- entry.message.role === "assistant" &&
681
- entry.message.id === citationRequest.citation.messageId,
679
+ (entry.kind === "message" &&
680
+ entry.message.role === "assistant" &&
681
+ entry.message.id === citationRequest.citation.messageId) ||
682
+ (entry.kind === "sent-message" && entry.id === citationRequest.citation.messageId),
683
)
684
: undefined;
685
if (citationRequest && citedEntry) {
apps/web/src/components/chat/TimelineAssistantRows.tsx
+21
-12
@@ -1,5 +1,5 @@
1
import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
2
-import { type RunId, type TurnItemId } from "@t3tools/contracts";
2
+import { MessageId, type RunId, type TurnItemId } from "@t3tools/contracts";
3
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
4
import { agentWorkingDirectories } from "@t3tools/client-runtime/workspace-basename-lookup";
5
import { memo, use, useState } from "react";
@@ -114,17 +114,26 @@ export function SentMessageTimelineRow({
114
return (
115
<div className="min-w-0 px-1 py-0.5">
116
<MessageAuthorHeading>T3 Code</MessageAuthorHeading>
117
- <ChatMarkdown
118
- text={row.text}
119
- cwd={ctx.markdownCwd}
120
- threadRef={ctx.threadRef ?? undefined}
121
- lineBreaks={shouldPreserveAssistantLineBreaks(row.text)}
122
- skills={ctx.skills}
123
- headingLevelOffset={MESSAGE_HEADING_LEVEL}
124
- onUseArtifactTemplate={ctx.onUseArtifactTemplate}
125
- onRunShellCommand={ctx.onRunShellCommand}
126
- onImageExpand={ctx.onImageExpand}
127
- />
117
+ {/* Sent messages have no message id; citations name their turn item instead. */}
118
+ <AssistantCitationSource
119
+ messageId={MessageId.make(row.id)}
120
+ {...(ctx.threadRef ? { threadRef: ctx.threadRef } : {})}
121
+ itemKey={row.id}
122
+ request={ctx.citationRequest}
123
+ listRef={ctx.listRef}
124
+ >
125
+ <ChatMarkdown
126
+ text={row.text}
127
+ cwd={ctx.markdownCwd}
128
+ threadRef={ctx.threadRef ?? undefined}
129
+ lineBreaks={shouldPreserveAssistantLineBreaks(row.text)}
130
+ skills={ctx.skills}
131
+ headingLevelOffset={MESSAGE_HEADING_LEVEL}
132
+ onUseArtifactTemplate={ctx.onUseArtifactTemplate}
133
+ onRunShellCommand={ctx.onRunShellCommand}
134
+ onImageExpand={ctx.onImageExpand}
135
+ />
136
+ </AssistantCitationSource>
137
</div>
138
);
139
}
apps/web/src/components/chat/citationProcedure.test.ts
+17
@@ -181,6 +181,23 @@ describe("resolveCitationPhase", () => {
181
});
182
});
183
184
+ it("finds text an agent sent with send_to_user by its item id", () => {
185
+ const sent: TimelineEntry = {
186
+ kind: "sent-message",
187
+ id: messageId,
188
+ createdAt: at,
189
+ runId,
190
+ text: "Draft",
191
+ };
192
+ expect(phase({ entries: [sent] })).toEqual({ _tag: "expanding" });
193
+ expect(
194
+ phase({
195
+ entries: [sent],
196
+ rows: [{ kind: "sent-message", id: messageId, createdAt: at, text: "Draft" }],
197
+ }),
198
+ ).toEqual({ _tag: "ready", rowId: messageId });
199
+ });
200
+
201
it("fails for a citation that names a user message", () => {
202
const userEntry: TimelineEntry = {
203
...entry,
apps/web/src/components/chat/citationProcedure.ts
+16
-7
@@ -1,5 +1,6 @@
1
import { useAtomValue } from "@effect/atom-react";
2
import { type AtomCommandSuccess, runAtomCommand } from "@t3tools/client-runtime/state/runtime";
3
+import { sentMessageFromToolItem } from "@t3tools/shared/toolOutput";
4
import { Atom, type AtomRegistry } from "effect/reactivity";
5
import type { TimelineEntry } from "../../session-logic";
6
import { environmentThreadDetails, threadEnvironment } from "../../state/threads";
@@ -92,13 +93,17 @@ export function resolveCitationPhase(input: {
93
}): CitationPhase {
94
if (input.history._tag === "failed") return { _tag: "failed" };
95
const source = input.entries.find(
95
- (entry) => entry.kind === "message" && entry.message.id === input.messageId,
96
+ (entry) =>
97
+ (entry.kind === "message" && entry.message.id === input.messageId) ||
98
+ (entry.kind === "sent-message" && entry.id === input.messageId),
99
);
100
// The history store can hold the message a render before the entries do.
101
if (!source) return { _tag: "loading" };
99
- if (source.kind !== "message" || source.message.role !== "assistant") return { _tag: "failed" };
102
+ if (source.kind === "message" && source.message.role !== "assistant") return { _tag: "failed" };
103
const row = input.rows.find(
101
- (candidate) => candidate.kind === "message" && candidate.message.id === input.messageId,
104
+ (candidate) =>
105
+ (candidate.kind === "message" && candidate.message.id === input.messageId) ||
106
+ (candidate.kind === "sent-message" && candidate.id === input.messageId),
107
);
108
if (row) return { _tag: "ready", rowId: row.id };
109
return { _tag: "expanding" };
@@ -127,12 +132,16 @@ export function citedThreadSnapshot(input: {
132
}
133
// Older pages merge into the visible turn items, not the message list.
134
const item = input.thread.projection.visibleTurnItems.find(
130
- (row) =>
131
- (row.item.type === "assistant_message" || row.item.type === "user_message") &&
132
- row.item.messageId === input.messageId,
135
+ ({ item }) =>
136
+ ((item.type === "assistant_message" || item.type === "user_message") &&
137
+ item.messageId === input.messageId) ||
138
+ (item.type === "dynamic_tool" &&
139
+ item.id === input.messageId &&
140
+ item.status === "completed" &&
141
+ sentMessageFromToolItem(item) !== undefined),
142
)?.item;
143
return {
135
- message: item === undefined ? null : item.type === "assistant_message" ? "assistant" : "other",
144
+ message: item === undefined ? null : item.type === "user_message" ? "other" : "assistant",
145
hasMoreHistory: input.history.hasMoreHistory,
146
};
147
}