@devries-cameron20 / t3code Mirror · read-only / commits / de26b6db3c
Fork 0

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, 22:15 UTC

fix(server): providers read cited assistant text again (#32702)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Szőke Péter committed Nov 12, 2026 at 00:08 UTC de26b6db3c1044af1fb622baa32748bd2701d63d
3 files changed +44 -7
docs/internals/composer-context-references.md
+2 -1
@@ -66,9 +66,10 @@ links, so a context link is never mistaken for a mention.
66 records produce a marker but no entry. Unknown kinds emit their payload as JSON.
67 3. Captured text is data: any `<` that would open or close `t3_context` or `context` is escaped,
68 so a terminal line or PR comment cannot forge a record.
69 +4. Assistant citation links are expanded too (`expandAssistantCitationsForProvider`).
70
71 Attachment bytes travel on the existing attachment channel; the envelope only carries metadata.
71 -Text without references is returned unchanged.
72 +Text without references or citations is returned unchanged.
73
74 ## Legacy messages
75
packages/shared/src/composerContextReferences.test.ts
+33
@@ -2,10 +2,12 @@ import {
2 ComposerContextId,
3 type ComposerContextRecord,
4 EnvironmentId,
5 + MessageId,
6 ThreadId,
7 } from "@t3tools/contracts";
8 import { describe, expect, it } from "vite-plus/test";
9
10 +import { serializeAssistantCitation } from "./assistantCitations.ts";
11 import {
12 ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
13 collectComposerContextReferences,
@@ -196,6 +198,37 @@ describe("provider projection", () => {
198 expect(projected).toContain("- font-size: 12px → 20px");
199 });
200
201 + it("expands assistant citations with and without context references", () => {
202 + const citation = serializeAssistantCitation({
203 + version: 1,
204 + environmentId: EnvironmentId.make("env"),
205 + threadId: ThreadId.make("thread"),
206 + messageId: MessageId.make("message"),
207 + text: "Use a mutex here",
208 + comment: "Why not a channel?",
209 + start: 0,
210 + end: 16,
211 + prefix: "",
212 + suffix: "",
213 + });
214 + for (const text of [
215 + `See ${citation} ok`,
216 + `See ${citation} ok [Preview annotation: Checkout](t3-context://v1/preview-annotation/ctx_p)`,
217 + ]) {
218 + const projected = projectComposerContextForProvider({ text, records: [] });
219 + expect(projected).not.toContain("t3-citation:");
220 + expect(projected).toContain("See [assistant-quote-1]");
221 + expect(projected).toContain('"text": "Use a mutex here"');
222 + expect(projected).toContain('"comment": "Why not a channel?"');
223 + }
224 + const captured = projectComposerContextForProvider({
225 + text: "[Terminal 1 lines 3-4](t3-context://v1/terminal/ctx_t)",
226 + records: [{ ...terminal, lineStart: 1, lineEnd: 1, text: citation }],
227 + });
228 + expect(captured).toContain(citation);
229 + expect(captured).not.toContain("assistant_citations");
230 + });
231 +
232 it("uses the payload kind when a reference disagrees with its record", () => {
233 const projected = projectComposerContextForProvider({
234 text: "[log](t3-context://v1/image/ctx_t)",
packages/shared/src/composerContextReferences.ts
+9 -6
@@ -10,6 +10,7 @@ import {
10 type ThreadContextRecord,
11 } from "@t3tools/contracts";
12
13 +import { expandAssistantCitationsForProvider } from "./assistantCitations.ts";
14 import { replaceThreadLinks, threadLinkCandidates } from "./threadLinks.ts";
15
16 const CONTEXT_PROTOCOL = "t3-context:";
@@ -377,16 +378,18 @@ export function projectComposerContextForProvider(input: {
378 records: ReadonlyArray<ComposerContextRecord>;
379 }): string {
380 const occurrences = collectComposerContextReferences(input.text);
380 - if (occurrences.length === 0) return input.text;
381 + if (occurrences.length === 0) return expandAssistantCitationsForProvider(input.text);
382 const recordsById = new Map<ComposerContextId, ComposerContextRecord | undefined>();
383 for (const record of input.records) {
384 recordsById.set(record.contextId, recordsById.has(record.contextId) ? undefined : record);
385 }
385 - const body = replaceComposerContextReferences(input.text, (occurrence) =>
386 - formatComposerContextProviderMarker(
387 - recordsById.get(occurrence.contextId)?.kind ?? occurrence.kind,
388 - occurrence.label,
389 - occurrence.contextId,
386 + const body = expandAssistantCitationsForProvider(
387 + replaceComposerContextReferences(input.text, (occurrence) =>
388 + formatComposerContextProviderMarker(
389 + recordsById.get(occurrence.contextId)?.kind ?? occurrence.kind,
390 + occurrence.label,
391 + occurrence.contextId,
392 + ),
393 ),
394 );
395 const seen = new Set<ComposerContextId>();