Skip to content

Commit 2ea11fe

Browse files
tlcondeclaude
andcommitted
feat(web,mobile): image-only messages show a quiet caption instead of the agent prompt
A message sent with only attachments is stored with the bootstrap prompt "[User attached one or more files without additional text. ...]" so the agent knows to respond. Chat rendered that sentence as if the user had typed it. Clients now show a small "Image only" caption in its place (or "Attachment only" when files are included). Clicking it reveals the exact instruction and "Hide" closes it. A lone photo fills the bubble and stays at its right edge while the bubble grows. The stored message and the agent payload are unchanged, and a message that adds text after the prompt still renders as typed. Follows #16480, which made the prompt part of the image-only send path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent ed3f965 commit 2ea11fe

5 files changed

Lines changed: 162 additions & 8 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
collectComposerContextReferences,
5252
replaceComposerContextReferences,
5353
formatComposerContextReference,
54+
isAttachmentOnlyBootstrapText,
5455
} from "@t3tools/shared/composerContextReferences";
5556
import { ComposerContextSheet } from "../../components/ComposerContextSheet";
5657
import { writeComposerContextClipboard } from "../../lib/composerContextClipboard";
@@ -1361,6 +1362,8 @@ function renderFeedEntry(
13611362
if (isUser) {
13621363
const enterAnimated = isFreshTimestamp(message.createdAt);
13631364
const intentBadge = resolveUserMessageIntentBadge(message.inputIntent);
1365+
// The bootstrap prompt is for the agent, not the reader: the bubble shows only the attachments.
1366+
const attachmentOnly = isAttachmentOnlyBootstrapText(message.text);
13641367
const referenceIds = new Set(
13651368
collectComposerContextReferences(message.text).map((reference) => reference.contextId),
13661369
);
@@ -1467,7 +1470,8 @@ function renderFeedEntry(
14671470
})}
14681471
</View>
14691472
) : null}
1470-
{message.text.trim().length > 0 ? (
1473+
{attachmentOnly ? <AttachmentOnlyCaption instruction={message.text.trim()} /> : null}
1474+
{message.text.trim().length > 0 && !attachmentOnly ? (
14711475
<MarkdownImageAvailableWidthContext
14721476
value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
14731477
>
@@ -1529,7 +1533,7 @@ function renderFeedEntry(
15291533
<SymbolView name="pencil" size={14} tintColor={iconSubtleColor} />
15301534
</Pressable>
15311535
) : null}
1532-
{presentation.text.trim().length > 0 ? (
1536+
{presentation.text.trim().length > 0 && !attachmentOnly ? (
15331537
<UserMessageCopyButton
15341538
text={presentation.text}
15351539
onCopy={
@@ -1694,6 +1698,31 @@ type UserMessageContentProps = {
16941698
readonly renderImage: MarkdownImageRenderer;
16951699
};
16961700

1701+
/** Sent with no text: a quiet caption stands in for the agent's bootstrap prompt, and a tap reveals it. */
1702+
function AttachmentOnlyCaption(props: { readonly instruction: string }) {
1703+
const [expanded, setExpanded] = useState(false);
1704+
return (
1705+
<View className="gap-1">
1706+
<Pressable
1707+
accessibilityRole="button"
1708+
accessibilityLabel={expanded ? "Hide agent instruction" : "Image only"}
1709+
accessibilityState={{ expanded }}
1710+
hitSlop={8}
1711+
onPress={() => setExpanded((value) => !value)}
1712+
>
1713+
<Text className="text-xs italic text-user-bubble-foreground-muted">
1714+
{expanded ? "Hide" : "Image only"}
1715+
</Text>
1716+
</Pressable>
1717+
{expanded ? (
1718+
<Text className="text-xs leading-relaxed text-user-bubble-foreground-muted">
1719+
{props.instruction}
1720+
</Text>
1721+
) : null}
1722+
</View>
1723+
);
1724+
}
1725+
16971726
function UserMessageContent(props: UserMessageContentProps) {
16981727
const [selected, setSelected] = useState<{ contextId: string; label: string } | null>(null);
16991728
const navigation = useNavigation();

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { EnvironmentId, MessageId, RunId, ScheduledTaskId } from "@t3tools/contracts";
1+
import {
2+
ChatAttachmentId,
3+
EnvironmentId,
4+
MessageId,
5+
RunId,
6+
ScheduledTaskId,
7+
} from "@t3tools/contracts";
28
import type { LegendListRef } from "@legendapp/list/react";
39
import { createRef, Profiler, type ComponentProps, type ReactElement } from "react";
410
import { describe, expect, it, vi } from "vite-plus/test";
@@ -9,6 +15,7 @@ import { act, render } from "../../../test/render";
915
import { MessagesTimeline } from "./MessagesTimeline";
1016
import { remarkThoughtPreview } from "./TimelineWorkEntryRow.logic";
1117
import { parseMarkdownWithMath } from "@t3tools/shared/markdownMath";
18+
import { ATTACHMENT_ONLY_BOOTSTRAP_PROMPT } from "@t3tools/shared/composerContextReferences";
1219
import { collectThreadFindRanges } from "./threadFindHighlights";
1320

1421
const environmentQuery = vi.hoisted(() => ({
@@ -310,6 +317,53 @@ describe("MessagesTimeline automation prompts", () => {
310317
});
311318
});
312319

320+
describe("MessagesTimeline attachment-only messages", () => {
321+
const photo = {
322+
type: "image" as const,
323+
id: ChatAttachmentId.make("attachment-1"),
324+
name: "photo.png",
325+
mimeType: "image/png",
326+
sizeBytes: 1024,
327+
previewUrl:
328+
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='180'><rect width='240' height='180' fill='%23888'/></svg>",
329+
};
330+
331+
it("stands in for the bootstrap prompt with a caption that reveals it on click", async () => {
332+
setup();
333+
await using screen = await renderTimeline([
334+
message(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT, { attachments: [photo] }),
335+
]);
336+
expect(screen.text()).not.toContain("without additional text");
337+
expect(screen.container.querySelector("[data-user-message-body]")).toBeNull();
338+
expect(screen.buttons(/^Copy message$/i)).toHaveLength(0);
339+
expect(screen.buttons(/^Copy prompt link$/)).toHaveLength(0);
340+
341+
const caption = screen.button("Image only");
342+
expect(caption.getAttribute("aria-expanded")).toBe("false");
343+
const photoRight = () => screen.container.querySelector("img")?.getBoundingClientRect().right;
344+
const rightBefore = photoRight();
345+
expect(rightBefore).toBeDefined();
346+
await click(caption);
347+
// The bubble grows with the text, but the photo stays where it was.
348+
expect(photoRight()).toBe(rightBefore);
349+
expect(screen.text()).toContain(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT);
350+
await click(screen.button("Hide"));
351+
expect(screen.text()).not.toContain("without additional text");
352+
expect(screen.buttons("Image only")).toHaveLength(1);
353+
});
354+
355+
it("keeps a message that adds text to the bootstrap prompt as a full bubble", async () => {
356+
setup();
357+
await using screen = await renderTimeline([
358+
message(`${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT} Also check the colors.`, {
359+
attachments: [photo],
360+
}),
361+
]);
362+
expect(screen.text()).not.toContain("Sent without text");
363+
expect(screen.text()).toContain("Also check the colors.");
364+
});
365+
});
366+
313367
describe("compact reasoning math", () => {
314368
it("keeps formulas while flattening compact reasoning previews", () => {
315369
const tree = parseMarkdownWithMath("## Reasoning\n\nUse **norm** $|x|$ and \\[x^2\\]");

‎apps/web/src/components/chat/TimelineUserMessageRow.tsx‎

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ import {
4949
resolveUserMessageContext,
5050
selectedMessageContextFragment,
5151
} from "~/lib/composerContextRecords";
52-
import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
52+
import {
53+
collectComposerContextReferences,
54+
isAttachmentOnlyBootstrapText,
55+
} from "@t3tools/shared/composerContextReferences";
5356
import {
5457
COMPOSER_CONTEXT_CLIPBOARD_MIME,
5558
encodeComposerContextClipboardHtml,
@@ -273,6 +276,9 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
273276
);
274277
const userMessage = resolveUserMessagePresentation(row.message);
275278
const resolvedContext = resolveUserMessageContext(row.message);
279+
// The bootstrap prompt is for the agent, not the reader: the bubble shows only the attachments.
280+
const attachmentOnly = isAttachmentOnlyBootstrapText(resolvedContext.text);
281+
const bodyText = attachmentOnly ? "" : resolvedContext.text;
276282
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
277283
const revertTurnCount = row.revertTurnCount;
278284
const chippedAttachmentIds = new Set(
@@ -290,7 +296,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
290296
resolvedContext.text,
291297
(reference) => reference.label,
292298
);
293-
const promptLink = promptLinkFor(plainText);
299+
const promptLink = attachmentOnly ? null : promptLinkFor(plainText);
294300
const contextClipboardFragment =
295301
resolvedContext.records.length === 0
296302
? null
@@ -409,7 +415,17 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
409415
<div className="relative max-w-[80%] rounded-2xl bg-message p-3 text-message-foreground">
410416
<MessageAuthorHeading>You</MessageAuthorHeading>
411417
{(regularImages.length > 0 || userVideos.length > 0) && (
412-
<div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
418+
<div
419+
className={cn(
420+
"mb-2 grid gap-2",
421+
// A lone photo sent without text fills its bubble instead of leaving half of it empty.
422+
// It sits at the bubble's right edge so opening the caption grows the bubble leftward
423+
// without moving the photo.
424+
attachmentOnly && regularImages.length + userVideos.length === 1
425+
? "ms-auto max-w-[240px] grid-cols-1"
426+
: "max-w-[210px] grid-cols-2",
427+
)}
428+
>
413429
{regularImages.map((image) => (
414430
<div
415431
key={image.id}
@@ -513,9 +529,19 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
513529
))}
514530
</div>
515531
) : null}
532+
{attachmentOnly ? (
533+
<AttachmentOnlyCaption
534+
label={
535+
unchippedFiles.length + unknownAttachments.length > 0
536+
? "Attachment only"
537+
: "Image only"
538+
}
539+
instruction={resolvedContext.text}
540+
/>
541+
) : null}
516542
<div onCopyCapture={onBodyCopyCapture}>
517543
<CollapsibleUserMessageBody
518-
text={resolvedContext.text}
544+
text={bodyText}
519545
renderContextReference={renderContextReference}
520546
skills={ctx.skills}
521547
markdownCwd={ctx.markdownCwd}
@@ -537,7 +563,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
537563
{typeof revertTurnCount === "number" && (
538564
<RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
539565
)}
540-
{resolvedContext.text && (
566+
{bodyText && (
541567
<MessageCopyButton
542568
text={contextClipboardFragment ? resolvedContext.text : plainText}
543569
{...(contextClipboardFragment
@@ -563,6 +589,31 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
563589
);
564590
}
565591

592+
/** Sent with no text: a quiet caption stands in for the agent's bootstrap prompt, and a click reveals it. */
593+
function AttachmentOnlyCaption({
594+
label,
595+
instruction,
596+
}: {
597+
readonly label: string;
598+
readonly instruction: string;
599+
}) {
600+
const [expanded, setExpanded] = useState(false);
601+
return (
602+
<div className="text-xs text-muted-foreground" data-user-message-attachment-only="true">
603+
<button
604+
type="button"
605+
aria-expanded={expanded}
606+
data-scroll-anchor-ignore
607+
onClick={() => setExpanded((value) => !value)}
608+
className="cursor-pointer rounded-sm italic hover:underline focus-visible:outline-2 focus-visible:outline-ring"
609+
>
610+
{expanded ? "Hide" : label}
611+
</button>
612+
{expanded ? <p className="mt-1 leading-relaxed">{instruction}</p> : null}
613+
</div>
614+
);
615+
}
616+
566617
function UserMessageIntentMarker({
567618
intent,
568619
}: {

‎packages/shared/src/composerContextReferences.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { describe, expect, it } from "vite-plus/test";
99
import {
1010
collectComposerContextReferences,
1111
formatComposerContextHref,
12+
ATTACHMENT_ONLY_BOOTSTRAP_PROMPT,
13+
isAttachmentOnlyBootstrapText,
1214
isImageReferencesOnly,
1315
parseComposerContextHref,
1416
projectComposerContextForProvider,
@@ -81,6 +83,15 @@ describe("labels and reference links", () => {
8183
expect(isImageReferencesOnly(`${image} ${file}`)).toBe(false);
8284
expect(isImageReferencesOnly(" ")).toBe(false);
8385
});
86+
87+
it("recognizes the stored bootstrap prompt for an attachment-only message", () => {
88+
expect(isAttachmentOnlyBootstrapText(ATTACHMENT_ONLY_BOOTSTRAP_PROMPT)).toBe(true);
89+
expect(isAttachmentOnlyBootstrapText(` ${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT}\n`)).toBe(true);
90+
expect(isAttachmentOnlyBootstrapText(`${ATTACHMENT_ONLY_BOOTSTRAP_PROMPT} look at this`)).toBe(
91+
false,
92+
);
93+
expect(isAttachmentOnlyBootstrapText("")).toBe(false);
94+
});
8495
});
8596

8697
describe("provider projection", () => {

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ export function collectComposerContextReferences(
120120
export const ATTACHMENT_ONLY_BOOTSTRAP_PROMPT =
121121
"[User attached one or more files without additional text. Respond using the conversation context and the attached files.]";
122122

123+
/**
124+
* True when a stored user message is only the bootstrap prompt T3 Code sends in place of
125+
* empty text. Clients hide that prompt in the chat and show a status line instead; the
126+
* message itself, and what the agent received, stay untouched.
127+
*/
128+
export function isAttachmentOnlyBootstrapText(text: string): boolean {
129+
return text.trim() === ATTACHMENT_ONLY_BOOTSTRAP_PROMPT;
130+
}
131+
123132
export function isImageReferencesOnly(text: string): boolean {
124133
const references = collectComposerContextReferences(text);
125134
return (

0 commit comments

Comments
 (0)