Skip to content

Commit eb48947

Browse files
committed
fix(chat): hide attachment prompts in previews
1 parent e79ca95 commit eb48947

4 files changed

Lines changed: 100 additions & 3 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { MessageId } from "@t3tools/contracts";
2+
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
3+
import { applyClaudePromptEffortPrefix } from "@t3tools/shared/model";
4+
import { describe, expect, it } from "vite-plus/test";
5+
6+
import type { MessagesTimelineRow } from "./MessagesTimeline.logic";
7+
import { deriveTimelineMinimapItems, resolveTimelineMinimapPreview } from "./timelineMinimapItems";
8+
9+
function messageRow(
10+
role: "user" | "assistant",
11+
text: string,
12+
): Extract<MessagesTimelineRow, { kind: "message" }> {
13+
const createdAt = "2026-01-01T00:00:00.000Z";
14+
return {
15+
kind: "message",
16+
id: role,
17+
createdAt,
18+
message: {
19+
id: MessageId.make(role),
20+
role,
21+
text,
22+
runId: null,
23+
createdAt,
24+
updatedAt: createdAt,
25+
streaming: false,
26+
},
27+
durationStart: createdAt,
28+
showAssistantMeta: false,
29+
showAssistantCopyButton: false,
30+
assistantCopyStreaming: false,
31+
};
32+
}
33+
34+
describe("deriveTimelineMinimapItems", () => {
35+
it.each([
36+
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
37+
applyClaudePromptEffortPrefix(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, "ultrathink"),
38+
])("hides attachment-only text from minimap previews: %s", (text) => {
39+
const rows = [messageRow("user", text), messageRow("assistant", "Image received.")];
40+
const items = deriveTimelineMinimapItems(rows);
41+
42+
expect(items).toEqual([
43+
{ id: "user", rowIndex: 0, userText: "", assistantText: "Image received." },
44+
]);
45+
expect(resolveTimelineMinimapPreview(items[0] ?? null)).toEqual({
46+
id: "user",
47+
rowIndex: 0,
48+
userText: null,
49+
assistantText: "Image received.",
50+
});
51+
expect(rows[0]?.message.text).toBe(text);
52+
});
53+
54+
it("preserves typed text and assistant text", () => {
55+
const text = "Ultrathink:\n Check this image.\n";
56+
const items = deriveTimelineMinimapItems([
57+
messageRow("user", text),
58+
messageRow("assistant", ATTACHMENT_ONLY_BOOTSTRAP_PROMPT),
59+
]);
60+
61+
expect(items).toEqual([
62+
{ id: "user", rowIndex: 0, userText: text, assistantText: ATTACHMENT_ONLY_BOOTSTRAP_PROMPT },
63+
]);
64+
});
65+
});

‎apps/web/src/components/chat/timelineMinimapItems.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { userVisibleMessageText } from "@t3tools/client-runtime/user-message";
12
import type { Nodes } from "mdast";
23
import remarkGfm from "remark-gfm";
34
import remarkParse from "remark-parse";
@@ -25,7 +26,7 @@ export function deriveTimelineMinimapItems(
2526
items.push({
2627
id: row.id,
2728
rowIndex: index,
28-
userText: row.message.text,
29+
userText: userVisibleMessageText(row.message.text),
2930
assistantText: resolveFinalAssistantTextForTurn(rows, index),
3031
});
3132
}

‎packages/client-runtime/src/userMessage.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@ import { describe, expect, it } from "vite-plus/test";
22

33
import { GuestMessageId } from "@t3tools/contracts";
44
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
5+
import { applyClaudePromptEffortPrefix } from "@t3tools/shared/model";
56

6-
import { resolveUserMessagePresentation } from "./userMessage.ts";
7+
import { resolveUserMessagePresentation, userVisibleMessageText } from "./userMessage.ts";
8+
9+
describe("userVisibleMessageText", () => {
10+
it.each([
11+
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
12+
applyClaudePromptEffortPrefix(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, "ultrathink"),
13+
])("hides an attachment-only prompt, including surrounding whitespace: %s", (text) => {
14+
expect(userVisibleMessageText(text)).toBe("");
15+
expect(userVisibleMessageText(` \n${text}\n\t`)).toBe("");
16+
expect(resolveUserMessagePresentation({ role: "user", text }).text).toBe("");
17+
});
18+
19+
it.each([
20+
"",
21+
" \n",
22+
" Check this image.\n",
23+
"Ultrathink:\nCheck this image.\n",
24+
`Explain ${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}`,
25+
`${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}\nCheck this image.`,
26+
`Ultrathink:\n${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}\nCheck this image.`,
27+
])("preserves all other text exactly: %s", (text) => {
28+
expect(userVisibleMessageText(text)).toBe(text);
29+
});
30+
});
731

832
describe("resolveUserMessagePresentation", () => {
933
const legacyText = "[Triggered by schedule task: Daily audit]\n\nCheck for crashes.\n";

‎packages/client-runtime/src/userMessage.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
} from "@t3tools/contracts";
88
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
99

10+
import { ULTRATHINK_PROMPT_PREFIX } from "./modelTraits.ts";
11+
1012
/** The working row while T3 Code's own compaction runs. */
1113
export const IDLE_COMPACTING_LABELS = {
1214
beforeCacheExpires: "Compacting before the cache expires…",
@@ -21,7 +23,12 @@ export const IDLE_COMPACTION_TITLES = {
2123

2224
/** Attachment-only sends carry a prompt for the agent; people see only the attachments. */
2325
export function userVisibleMessageText(text: string): string {
24-
return text.trim() === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT ? "" : text;
26+
const trimmed = text.trim();
27+
// Claude's Ultrathink effort prefixes the outgoing prompt, including this one.
28+
const prompt = trimmed.startsWith(ULTRATHINK_PROMPT_PREFIX)
29+
? trimmed.slice(ULTRATHINK_PROMPT_PREFIX.length)
30+
: trimmed;
31+
return prompt === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT ? "" : text;
2532
}
2633

2734
const LEGACY_AUTOMATION_PREFIX = /^\[Triggered by schedule task: [^\r\n]+\]\r?\n\r?\n/;

0 commit comments

Comments
 (0)