Skip to content
TypeScript

feat(web,mobile): messages from other agents fold into one-line rows (#23135)

shivamf054d1b80187
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index a076924202b..9988debe2a0 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -240,7 +240,7 @@ import {
pickWorkspaceBasenameMatch,
WORKSPACE_BASENAME_LOOKUP_LIMIT,
} from "@t3tools/client-runtime/workspace-basename-lookup";
-import { useLiveThreadLinkLabels } from "../../state/entities";
+import { useLiveThreadLinkLabels, useQuietThreadShell } from "../../state/entities";
import { useThreadSelection } from "../../state/use-thread-selection";
import { useEnvironmentQuery } from "../../state/query";
import { serverEnvironment } from "../../state/server";
@@ -969,33 +969,76 @@ function useMarkdownStyles(): MarkdownStyleSets {
]);
}
-function AgentMessageAttribution(props: {
+/** Messages from other agents fold to one line so the user's own messages stay easy to find. */
+function AgentMessageFoldHeader(props: {
readonly environmentId: EnvironmentId;
readonly senderThreadId?: ThreadId;
+ readonly summary: string;
+ readonly expanded: boolean;
+ readonly onToggle: () => void;
+ readonly iconSubtleColor: ColorValue;
}) {
- const navigation = useNavigation();
- const senderThreadId = props.senderThreadId;
- const label = (
- <Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
- Sent by another agent
- </Text>
+ const senderShell = useQuietThreadShell(
+ props.senderThreadId ? scopeThreadRef(props.environmentId, props.senderThreadId) : null,
);
- return senderThreadId ? (
+ const label = senderShell?.title.trim() || "Agent";
+ return (
<Pressable
accessibilityRole="button"
- accessibilityLabel="Open sending thread"
+ accessibilityLabel={`${label}: ${props.summary}`}
+ accessibilityHint={`Double tap to ${props.expanded ? "hide" : "show"} the message.`}
+ accessibilityState={{ expanded: props.expanded }}
hitSlop={4}
+ className="min-h-10 flex-row items-center gap-1.5 px-3.5 py-2"
+ onPress={() => {
+ void Haptics.selectionAsync();
+ props.onToggle();
+ }}
+ >
+ <SymbolView
+ name="bubble.left.and.bubble.right"
+ size={14}
+ weight="medium"
+ tintColorClassName="accent-user-bubble-foreground-muted"
+ type="monochrome"
+ />
+ <Text
+ numberOfLines={1}
+ className="max-w-[50%] shrink-0 font-t3-medium text-sm text-user-bubble-foreground-muted"
+ >
+ {label}
+ </Text>
+ <Text numberOfLines={1} className="min-w-0 shrink text-sm text-user-bubble-foreground">
+ {props.summary}
+ </Text>
+ <ThreadDisclosureChevron
+ expanded={props.expanded}
+ collapsedDirection="down"
+ size={11}
+ tintColor={props.iconSubtleColor}
+ />
+ </Pressable>
+ );
+}
+
+function OpenSenderThreadButton(props: {
+ readonly environmentId: EnvironmentId;
+ readonly senderThreadId: ThreadId;
+}) {
+ const navigation = useNavigation();
+ return (
+ <Pressable
+ accessibilityRole="link"
+ hitSlop={6}
onPress={() =>
navigation.navigate("Thread", {
environmentId: String(props.environmentId),
- threadId: String(senderThreadId),
+ threadId: String(props.senderThreadId),
})
}
>
- {label}
+ <Text className="font-t3-medium text-xs text-foreground-secondary">Open thread</Text>
</Pressable>
- ) : (
- label
);
}
@@ -1360,6 +1403,9 @@ function renderFeedEntry(
}
if (isUser) {
const enterAnimated = isFreshTimestamp(message.createdAt);
+ const foldRowId = presentation.attribution === "agent" ? `agent:${message.id}` : null;
+ const foldExpanded = foldRowId !== null && (props.expandedWorkRows[foldRowId] ?? false);
+ const bubbleBodyVisible = foldRowId === null || foldExpanded;
const intentBadge = resolveUserMessageIntentBadge(message.inputIntent);
const referenceIds = new Set(
collectComposerContextReferences(message.text).map((reference) => reference.contextId),
@@ -1383,169 +1429,193 @@ function renderFeedEntry(
<Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
Sent by T3 Code
</Text>
- ) : presentation.attribution === "agent" ? (
- <AgentMessageAttribution
- environmentId={props.environmentId}
- senderThreadId={message.senderThreadId}
- />
) : null}
<View
- className="min-w-0 gap-2 rounded-[20px] px-3.5 py-2.5"
+ className="min-w-0 rounded-[20px]"
style={{
backgroundColor: userBubbleColor,
maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
- ...(hasReviewCommentContext
- ? { width: props.reviewCommentBubbleWidth }
- : hasWideBlock
- ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
- : null),
+ ...(!bubbleBodyVisible
+ ? null
+ : hasReviewCommentContext
+ ? { width: props.reviewCommentBubbleWidth }
+ : hasWideBlock || foldExpanded
+ ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
+ : null),
}}
>
- {entry.pendingMessage?.attachments.map((attachment) =>
- attachment.type === "image" && attachment.uploadedAttachmentId ? (
- <MessageAttachmentImage
- key={attachment.id}
- environmentId={props.environmentId}
- attachmentId={attachment.uploadedAttachmentId}
- name={attachment.name}
- mimeType={attachment.mimeType}
- className="h-[140px] w-[180px] rounded-[14px]"
- onPressPreview={props.onPressPreview}
- />
- ) : attachment.type === "image" ? (
- <Pressable
- key={attachment.id}
- accessibilityRole="imagebutton"
- accessibilityLabel={`Open ${attachment.name}`}
- onPress={() =>
- props.onPressPreview({
- kind: "image",
- name: attachment.name,
- uri: attachment.dataUrl ?? attachment.previewUri,
- gallery: composerImageGallery(entry.pendingMessage?.attachments ?? []),
- })
- }
- >
- <Image
- source={{ uri: attachment.previewUri }}
- style={{ width: 180, height: 140, borderRadius: 14 }}
- />
- </Pressable>
- ) : (
- <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
- ),
- )}
- {/* An empty container still takes a gap, which pads every attachment-free bubble. */}
- {visibleAttachments.length > 0 ? (
- <View className={inlineAttachmentIds.size ? "flex-row flex-wrap gap-2" : "gap-2"}>
- {visibleAttachments.map((attachment) => {
- return isImageAttachment(attachment) ? (
+ {foldRowId !== null ? (
+ <AgentMessageFoldHeader
+ environmentId={props.environmentId}
+ senderThreadId={message.senderThreadId}
+ summary={
+ replaceComposerContextReferences(presentation.text, (ref) => ref.label)
+ .split(/\r?\n/)
+ .find((line) => line.trim().length > 0)
+ ?.trim() ?? ""
+ }
+ expanded={foldExpanded}
+ onToggle={() => props.onToggleWorkRow(foldRowId, entry.id)}
+ iconSubtleColor={iconSubtleColor}
+ />
+ ) : null}
+ {bubbleBodyVisible ? (
+ <View className={cn("gap-2 px-3.5 pb-2.5", foldRowId === null && "pt-2.5")}>
+ {entry.pendingMessage?.attachments.map((attachment) =>
+ attachment.type === "image" && attachment.uploadedAttachmentId ? (
<MessageAttachmentImage
key={attachment.id}
environmentId={props.environmentId}
- attachmentId={attachment.id}
+ attachmentId={attachment.uploadedAttachmentId}
name={attachment.name}
mimeType={attachment.mimeType}
- className={
- inlineAttachmentIds.size
- ? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
- : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
- }
+ className="h-[140px] w-[180px] rounded-[14px]"
onPressPreview={props.onPressPreview}
/>
- ) : isFileAttachment(attachment) ? (
- <MessageAttachmentFile
+ ) : attachment.type === "image" ? (
+ <Pressable
key={attachment.id}
- environmentId={props.environmentId}
- attachment={attachment}
- onPressPreview={props.onPressPreview}
- onPressVideo={props.onPressVideo}
- />
+ accessibilityRole="imagebutton"
+ accessibilityLabel={`Open ${attachment.name}`}
+ onPress={() =>
+ props.onPressPreview({
+ kind: "image",
+ name: attachment.name,
+ uri: attachment.dataUrl ?? attachment.previewUri,
+ gallery: composerImageGallery(entry.pendingMessage?.attachments ?? []),
+ })
+ }
+ >
+ <Image
+ source={{ uri: attachment.previewUri }}
+ style={{ width: 180, height: 140, borderRadius: 14 }}
+ />
+ </Pressable>
) : (
<MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
- );
- })}
+ ),
+ )}
+ {/* An empty container still takes a gap, which pads every attachment-free bubble. */}
+ {visibleAttachments.length > 0 ? (
+ <View className={inlineAttachmentIds.size ? "flex-row flex-wrap gap-2" : "gap-2"}>
+ {visibleAttachments.map((attachment) => {
+ return isImageAttachment(attachment) ? (
+ <MessageAttachmentImage
+ key={attachment.id}
+ environmentId={props.environmentId}
+ attachmentId={attachment.id}
+ name={attachment.name}
+ mimeType={attachment.mimeType}
+ className={
+ inlineAttachmentIds.size
+ ? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
+ : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
+ }
+ onPressPreview={props.onPressPreview}
+ />
+ ) : isFileAttachment(attachment) ? (
+ <MessageAttachmentFile
+ key={attachment.id}
+ environmentId={props.environmentId}
+ attachment={attachment}
+ onPressPreview={props.onPressPreview}
+ onPressVideo={props.onPressVideo}
+ />
+ ) : (
+ <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
+ );
+ })}
+ </View>
+ ) : null}
+ {message.text.trim().length > 0 ? (
+ <MarkdownImageAvailableWidthContext
+ value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
+ >
+ <UserMessageContent
+ text={renderedText}
+ environmentId={props.environmentId}
+ context={message.context}
+ markdownStyles={styles}
+ reviewCommentColors={props.reviewCommentColors}
+ skills={props.skills}
+ linkHandlers={props.markdownLinkHandlers}
+ renderImage={props.renderMarkdownImage}
+ />
+ </MarkdownImageAvailableWidthContext>
+ ) : null}
</View>
) : null}
- {message.text.trim().length > 0 ? (
- <MarkdownImageAvailableWidthContext
- value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
- >
- <UserMessageContent
- text={renderedText}
+ </View>
+ {bubbleBodyVisible ? (
+ <View className="mt-1 flex-row items-center justify-end gap-1 pr-0.5">
+ {foldRowId !== null && message.senderThreadId ? (
+ <OpenSenderThreadButton
environmentId={props.environmentId}
- context={message.context}
- markdownStyles={styles}
- reviewCommentColors={props.reviewCommentColors}
- skills={props.skills}
- linkHandlers={props.markdownLinkHandlers}
- renderImage={props.renderMarkdownImage}
+ senderThreadId={message.senderThreadId}
/>
- </MarkdownImageAvailableWidthContext>
- ) : null}
- </View>
- <View className="mt-1 flex-row items-center justify-end gap-1 pr-0.5">
- {intentBadge ? (
- <View
- accessible
- accessibilityLabel={intentBadge.accessibilityLabel}
- className="flex-row items-center gap-1"
- >
- <SymbolView name="arrow.uturn.forward" size={12} tintColor={iconSubtleColor} />
- <Text className="font-t3-medium text-xs text-foreground-secondary">
- {intentBadge.label}
+ ) : null}
+ {intentBadge ? (
+ <View
+ accessible
+ accessibilityLabel={intentBadge.accessibilityLabel}
+ className="flex-row items-center gap-1"
+ >
+ <SymbolView name="arrow.uturn.forward" size={12} tintColor={iconSubtleColor} />
+ <Text className="font-t3-medium text-xs text-foreground-secondary">
+ {intentBadge.label}
+ </Text>
+ </View>
+ ) : null}
+ {intentBadge ? (
+ <Text
+ accessible={false}
+ accessibilityElementsHidden
+ importantForAccessibility="no"
+ className="font-t3-medium text-xs text-foreground-secondary"
+ >
+ ·
</Text>
- </View>
- ) : null}
- {intentBadge ? (
- <Text
- accessible={false}
- accessibilityElementsHidden
- importantForAccessibility="no"
- className="font-t3-medium text-xs text-foreground-secondary"
- >
- ·
+ ) : null}
+ <Text className="font-t3-medium text-xs tabular-nums text-foreground-secondary">
+ {entry.pendingMessage && !entry.acknowledged ? "Pending" : timestampLabel}
</Text>
- ) : null}
- <Text className="font-t3-medium text-xs tabular-nums text-foreground-secondary">
- {entry.pendingMessage && !entry.acknowledged ? "Pending" : timestampLabel}
- </Text>
- {props.onEditPendingMessage !== null &&
- entry.pendingMessage &&
- !entry.acknowledged &&
- !entry.pendingMessage.creation &&
- entry.pendingMessage.messageId !== props.dispatchingMessageId ? (
- <Pressable
- accessibilityRole="button"
- accessibilityLabel="Edit pending message"
- hitSlop={8}
- className="size-7 items-center justify-center"
- onPress={() => {
- if (entry.pendingMessage && props.onEditPendingMessage) {
- props.onEditPendingMessage(entry.pendingMessage);
+ {props.onEditPendingMessage !== null &&
+ entry.pendingMessage &&
+ !entry.acknowledged &&
+ !entry.pendingMessage.creation &&
+ entry.pendingMessage.messageId !== props.dispatchingMessageId ? (
+ <Pressable
+ accessibilityRole="button"
+ accessibilityLabel="Edit pending message"
+ hitSlop={8}
+ className="size-7 items-center justify-center"
+ onPress={() => {
+ if (entry.pendingMessage && props.onEditPendingMessage) {
+ props.onEditPendingMessage(entry.pendingMessage);
+ }
+ }}
+ >
+ <SymbolView name="pencil" size={14} tintColor={iconSubtleColor} />
+ </Pressable>
+ ) : null}
+ {presentation.text.trim().length > 0 ? (
+ <UserMessageCopyButton
+ text={presentation.text}
+ onCopy={
+ message.context
+ ? () =>
+ writeComposerContextClipboard(message.text, {
+ version: 1,
+ source: { environmentId: props.environmentId, messageId: message.id },
+ records: message.context!.records,
+ })
+ : undefined
}
- }}
- >
- <SymbolView name="pencil" size={14} tintColor={iconSubtleColor} />
- </Pressable>
- ) : null}
- {presentation.text.trim().length > 0 ? (
- <UserMessageCopyButton
- text={presentation.text}
- onCopy={
- message.context
- ? () =>
- writeComposerContextClipboard(message.text, {
- version: 1,
- source: { environmentId: props.environmentId, messageId: message.id },
- records: message.context!.records,
- })
- : undefined
- }
- tintColor={iconSubtleColor}
- />
- ) : null}
- </View>
+ tintColor={iconSubtleColor}
+ />
+ ) : null}
+ </View>
+ ) : null}
</Animated.View>
);
}
@@ -2974,13 +3044,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
renderItem={renderItem}
viewabilityConfig={THREAD_MEDIA_VIEWABILITY_CONFIG}
keyExtractor={(entry) => entry.id}
- getItemType={(entry) =>
- entry.type !== "message"
- ? entry.type
- : resolveUserMessagePresentation(entry.message).attribution === "automation"
- ? "message:automation"
- : `message:${entry.message.role}`
- }
+ getItemType={(entry) => {
+ if (entry.type !== "message") return entry.type;
+ const { attribution } = resolveUserMessagePresentation(entry.message);
+ return attribution === "automation" || attribution === "agent"
+ ? `message:${attribution}`
+ : `message:${entry.message.role}`;
+ }}
getFixedItemSize={getFixedItemSize}
// Virtualized rows must move with their measurements. Native layout
// transitions can retain stale positions during sync, even at duration 0.
diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
index 227a0cda730..616650f5461 100644
--- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
@@ -1,4 +1,4 @@
-import { EnvironmentId, MessageId, RunId, ScheduledTaskId } from "@t3tools/contracts";
+import { EnvironmentId, MessageId, RunId, ScheduledTaskId, ThreadId } from "@t3tools/contracts";
import type { LegendListRef } from "@legendapp/list/react";
import { createRef, Profiler, type ComponentProps, type ReactElement } from "react";
import { describe, expect, it, vi } from "vite-plus/test";
@@ -310,6 +310,64 @@ describe("MessagesTimeline automation prompts", () => {
});
});
+const SENDER_THREAD_ID = ThreadId.make("thread-sender");
+const AGENT_MESSAGE = "Review finished\n\nThe migration drops the index before backfilling it.";
+
+describe("MessagesTimeline agent messages", () => {
+ it("folds a message from another agent into a one-line preview", async () => {
+ setup();
+ const onOpenThread = vi.fn();
+ await using screen = await renderTimeline(
+ [message(AGENT_MESSAGE, { createdBy: "agent", senderThreadId: SENDER_THREAD_ID })],
+ { onOpenThread },
+ );
+ const row = screen.button(/^Agent/);
+ expect(row.textContent).toContain("Review finished");
+ expect(row.getAttribute("aria-expanded")).toBe("false");
+ expect(screen.text()).not.toContain("drops the index");
+ expect(screen.buttons("Open thread")).toHaveLength(0);
+
+ await click(row);
+ expect(screen.text()).toContain("The migration drops the index before backfilling it.");
+ await click(screen.button("Open thread"));
+ expect(onOpenThread).toHaveBeenCalledWith(SENDER_THREAD_ID);
+
+ await click(screen.button(/^Agent/));
+ expect(screen.text()).not.toContain("drops the index");
+ });
+
+ it("leaves messages sent by T3 Code as full bubbles", async () => {
+ setup();
+ await using screen = await renderTimeline([
+ message(AGENT_MESSAGE, { createdBy: "agent", creationSource: "server" }),
+ ]);
+ expect(screen.buttons(/^Agent/)).toHaveLength(0);
+ expect(screen.text()).toContain("drops the index");
+ });
+
+ it("reveals a find match inside a folded agent message", async () => {
+ setup();
+ const text = `${"Checked the next file.\n\n".repeat(16)}The migration drops the index.`;
+ await using screen = await renderTimeline(
+ [message(text, { createdBy: "agent", senderThreadId: SENDER_THREAD_ID })],
+ {
+ findExpanded: true,
+ findQuery: "drops the index",
+ activeFindMatch: { entryId: "entry-message-1", runId: null, occurrence: 0 },
+ },
+ );
+ await vi.waitFor(() =>
+ expect(screen.button(/^Agent/).getAttribute("aria-expanded")).toBe("true"),
+ );
+ const { range } = collectThreadFindRanges(screen.container, "drops the index")[0]!;
+ const body = screen.container.querySelector("[data-user-message-body]")!;
+ expect(range.getBoundingClientRect().height).toBeGreaterThan(0);
+ expect(range.getBoundingClientRect().bottom).toBeLessThanOrEqual(
+ body.getBoundingClientRect().bottom,
+ );
+ });
+});
+
describe("compact reasoning math", () => {
it("keeps formulas while flattening compact reasoning previews", () => {
const tree = parseMarkdownWithMath("## Reasoning\n\nUse **norm** $|x|$ and \\[x^2\\]");
diff --git a/apps/web/src/components/chat/TimelineUserMessageRow.tsx b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
index 2f2f2063a41..0fb9ac7f66c 100644
--- a/apps/web/src/components/chat/TimelineUserMessageRow.tsx
+++ b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
@@ -2,6 +2,7 @@ import { findRevealRef } from "./markdownFindContext";
import { type MessageId, type ServerProviderSkill, ThreadId } from "@t3tools/contracts";
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
import { Link } from "@tanstack/react-router";
+import { useQuietThreadShell } from "../../state/entities";
import { useEnvironmentQuery } from "../../state/query";
import { serverEnvironment } from "../../state/server";
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
@@ -22,6 +23,8 @@ import {
ChevronDownIcon,
DownloadIcon,
EyeIcon,
+ type LucideIcon,
+ MessagesSquareIcon,
Redo2Icon,
Undo2Icon,
} from "lucide-react";
@@ -162,23 +165,13 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
expanded && "w-full",
)}
>
- <button
- type="button"
- aria-expanded={expanded}
- data-scroll-anchor-ignore
- onClick={() => setExpanded((value) => !value)}
- className="flex w-full min-w-0 items-center gap-1.5 rounded-2xl px-3 py-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-ring"
- >
- <CalendarClockIcon className="size-4 shrink-0 stroke-2 text-muted-foreground" />
- <span className="shrink-0 text-muted-foreground">Automation</span>
- <span className="min-w-0 flex-1 truncate">{summary}</span>
- <ChevronDownIcon
- className={cn(
- "size-3.5 shrink-0 text-muted-foreground transition-transform",
- expanded && "rotate-180",
- )}
- />
- </button>
+ <FoldedMessageHeader
+ icon={CalendarClockIcon}
+ label="Automation"
+ summary={summary}
+ expanded={expanded}
+ onToggle={() => setExpanded((value) => !value)}
+ />
{bodyMounted ? (
// `beforematch` does not bubble, so the reveal listener sits on the hidden fold itself.
<div
@@ -230,6 +223,35 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
);
}
+function FoldedMessageHeader(props: {
+ icon: LucideIcon;
+ label: string;
+ summary: string;
+ expanded: boolean;
+ onToggle: () => void;
+}) {
+ const Icon = props.icon;
+ return (
+ <button
+ type="button"
+ aria-expanded={props.expanded}
+ data-scroll-anchor-ignore
+ onClick={props.onToggle}
+ className="flex w-full min-w-0 items-center gap-1.5 rounded-2xl px-3 py-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-ring"
+ >
+ <Icon className="size-4 shrink-0 stroke-2 text-muted-foreground" />
+ <span className="max-w-1/2 shrink-0 truncate text-muted-foreground">{props.label}</span>
+ <span className="min-w-0 flex-1 truncate">{props.summary}</span>
+ <ChevronDownIcon
+ className={cn(
+ "size-3.5 shrink-0 text-muted-foreground transition-transform",
+ props.expanded && "rotate-180",
+ )}
+ />
+ </button>
+ );
+}
+
function UserMessageProjectedStatus({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
const status = row.projectedItem?.item.status;
if (
@@ -272,6 +294,15 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
(attachment) => !isImageAttachment(attachment) && !isFileAttachment(attachment),
);
const userMessage = resolveUserMessagePresentation(row.message);
+ // Messages from other agents fold to one line so the user's own messages stay easy to find.
+ const folded = userMessage.attribution === "agent";
+ const [expanded, setExpanded] = useState(false);
+ const revealFoldRef = findRevealRef(() => setExpanded(true));
+ const senderShell = useQuietThreadShell(
+ folded && senderThreadId
+ ? { environmentId: ctx.activeThreadEnvironmentId, threadId: senderThreadId }
+ : null,
+ );
const resolvedContext = resolveUserMessageContext(row.message);
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
const revertTurnCount = row.revertTurnCount;
@@ -291,6 +322,11 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
(reference) => reference.label,
);
const promptLink = promptLinkFor(plainText);
+ const foldSummary =
+ plainText
+ .split(/\r?\n/)
+ .find((line) => line.trim().length > 0)
+ ?.trim() ?? "";
const contextClipboardFragment =
resolvedContext.records.length === 0
? null
@@ -379,7 +415,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
};
return (
- <div className="group flex flex-col items-end gap-1">
+ <div
+ className="group flex flex-col items-end gap-1"
+ data-user-message-attribution={folded ? "agent" : undefined}
+ >
{userMessage.attribution === "t3code" ? (
<p
className="me-1 text-2xs text-muted-foreground/70"
@@ -387,178 +426,205 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
>
Sent by T3 Code
</p>
- ) : userMessage.attribution === "agent" ? (
- <p className="me-1 text-2xs text-muted-foreground/70" data-user-message-attribution="agent">
- {senderThreadId ? (
- <InlineButton
- onClick={() => ctx.onOpenThread(senderThreadId)}
- tone="muted"
- aria-label="Open sending thread"
- >
- Sent by another agent
- </InlineButton>
- ) : (
- "Sent by another agent"
- )}
- </p>
) : null}
{row.message.inputIntent === "steer" ||
row.message.inputIntent === "promoted_queued_to_steer" ? (
<UserMessageIntentMarker intent={row.message.inputIntent} />
) : null}
- <div className="relative max-w-[80%] rounded-2xl bg-message p-3 text-message-foreground">
- <MessageAuthorHeading>You</MessageAuthorHeading>
- {(regularImages.length > 0 || userVideos.length > 0) && (
- <div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
- {regularImages.map((image) => (
- <div
- key={image.id}
- className={cn(
- "bg-background/70",
- image.source?.kind === "snap-shot" && image.previewUrl
- ? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
- : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
- )}
- >
- {image.previewUrl ? (
- <button
- type="button"
- className="block h-full w-full cursor-zoom-in"
- aria-label={`Preview ${image.name}`}
- onClick={() => {
- const preview = buildExpandedImagePreview(regularImages, image.id);
- if (!preview) return;
- ctx.onImageExpand(preview);
- }}
+ <div
+ className={cn(
+ "relative min-w-0 max-w-[80%] rounded-2xl bg-message text-message-foreground",
+ !folded && "p-3",
+ folded && expanded && "w-full",
+ )}
+ >
+ {folded ? (
+ <FoldedMessageHeader
+ icon={MessagesSquareIcon}
+ label={senderShell?.title.trim() || "Agent"}
+ summary={foldSummary}
+ expanded={expanded}
+ onToggle={() => setExpanded((value) => !value)}
+ />
+ ) : null}
+ {/* Find reads the DOM, so a folded message stays mounted but hidden while find is open. */}
+ {!folded || expanded || ctx.findActive ? (
+ <div
+ ref={folded ? revealFoldRef : undefined}
+ hidden={folded && !expanded}
+ className={cn(
+ folded && "px-3 pb-3",
+ folded && !ctx.findActive && "max-h-96 overflow-auto",
+ )}
+ >
+ <MessageAuthorHeading>You</MessageAuthorHeading>
+ {(regularImages.length > 0 || userVideos.length > 0) && (
+ <div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
+ {regularImages.map((image) => (
+ <div
+ key={image.id}
+ className={cn(
+ "bg-background/70",
+ image.source?.kind === "snap-shot" && image.previewUrl
+ ? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
+ : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
+ )}
>
- <AttachmentImage
- name={image.name}
- mimeType={image.mimeType}
- src={image.previewUrl}
- alt={image.name}
- decoding="async"
- className="block size-full object-cover"
- />
- </button>
- ) : (
- <div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70">
- {image.name}
+ {image.previewUrl ? (
+ <button
+ type="button"
+ className="block h-full w-full cursor-zoom-in"
+ aria-label={`Preview ${image.name}`}
+ onClick={() => {
+ const preview = buildExpandedImagePreview(regularImages, image.id);
+ if (!preview) return;
+ ctx.onImageExpand(preview);
+ }}
+ >
+ <AttachmentImage
+ name={image.name}
+ mimeType={image.mimeType}
+ src={image.previewUrl}
+ alt={image.name}
+ decoding="async"
+ className="block size-full object-cover"
+ />
+ </button>
+ ) : (
+ <div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70">
+ {image.name}
+ </div>
+ )}
+ {image.previewUrl && image.source?.kind === "snap-shot" ? (
+ <SnapShotAttachmentDetails source={image.source} />
+ ) : null}
</div>
- )}
- {image.previewUrl && image.source?.kind === "snap-shot" ? (
- <SnapShotAttachmentDetails source={image.source} />
- ) : null}
+ ))}
+ {userVideos.map((file) => (
+ <UserVideoAttachment key={file.id} file={file} />
+ ))}
</div>
- ))}
- {userVideos.map((file) => (
- <UserVideoAttachment key={file.id} file={file} />
- ))}
- </div>
- )}
- {unchippedFiles.length > 0 || unknownAttachments.length > 0 ? (
- <div className="mb-2 flex flex-col gap-1">
- {unchippedFiles.map((file) => {
- const fileIdentity = (
- <>
- <PierreEntryIcon pathValue={file.name} kind="file" theme={ctx.resolvedTheme} />
- <span className="min-w-0 flex-1 truncate">{file.name}</span>
- </>
- );
- if (file.downloadable !== false) {
- return (
- <div key={file.id} className="flex min-w-0 items-center gap-1">
- <button
- type="button"
- aria-label={`Preview ${file.name}`}
- onClick={() => ctx.onFileOpen(file)}
- className="focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md py-1 text-left text-sm hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
- >
+ )}
+ {unchippedFiles.length > 0 || unknownAttachments.length > 0 ? (
+ <div className="mb-2 flex flex-col gap-1">
+ {unchippedFiles.map((file) => {
+ const fileIdentity = (
+ <>
+ <PierreEntryIcon
+ pathValue={file.name}
+ kind="file"
+ theme={ctx.resolvedTheme}
+ />
+ <span className="min-w-0 flex-1 truncate">{file.name}</span>
+ </>
+ );
+ if (file.downloadable !== false) {
+ return (
+ <div key={file.id} className="flex min-w-0 items-center gap-1">
+ <button
+ type="button"
+ aria-label={`Preview ${file.name}`}
+ onClick={() => ctx.onFileOpen(file)}
+ className="focus-visible:ring-ring/70 flex min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-md py-1 text-left text-sm hover:underline focus-visible:ring-2 focus-visible:ring-inset focus-visible:outline-none"
+ >
+ {fileIdentity}
+ <EyeIcon className="size-4 shrink-0" />
+ </button>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ size="icon-xs"
+ variant="ghost-muted"
+ aria-label={`Download ${file.name}`}
+ onClick={() => ctx.onFileDownload(file)}
+ />
+ }
+ >
+ <DownloadIcon />
+ </TooltipTrigger>
+ <TooltipPopup side="top">Download {file.name}</TooltipPopup>
+ </Tooltip>
+ </div>
+ );
+ }
+
+ return (
+ <div key={file.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
{fileIdentity}
- <EyeIcon className="size-4 shrink-0" />
- </button>
- <Tooltip>
- <TooltipTrigger
- render={
- <Button
- size="icon-xs"
- variant="ghost-muted"
- aria-label={`Download ${file.name}`}
- onClick={() => ctx.onFileDownload(file)}
- />
- }
- >
- <DownloadIcon />
- </TooltipTrigger>
- <TooltipPopup side="top">Download {file.name}</TooltipPopup>
- </Tooltip>
+ </div>
+ );
+ })}
+ {unknownAttachments.map((attachment) => (
+ <div key={attachment.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
+ <PierreEntryIcon
+ pathValue={attachment.name}
+ kind="file"
+ theme={ctx.resolvedTheme}
+ />
+ <span className="min-w-0 flex-1 truncate">{attachment.name}</span>
</div>
- );
- }
-
- return (
- <div key={file.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
- {fileIdentity}
- </div>
- );
- })}
- {unknownAttachments.map((attachment) => (
- <div key={attachment.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
- <PierreEntryIcon
- pathValue={attachment.name}
- kind="file"
- theme={ctx.resolvedTheme}
- />
- <span className="min-w-0 flex-1 truncate">{attachment.name}</span>
+ ))}
</div>
- ))}
+ ) : null}
+ <div onCopyCapture={onBodyCopyCapture}>
+ <CollapsibleUserMessageBody
+ text={resolvedContext.text}
+ renderContextReference={renderContextReference}
+ skills={ctx.skills}
+ markdownCwd={ctx.markdownCwd}
+ collapsible={!folded}
+ />
+ </div>
</div>
) : null}
- <div onCopyCapture={onBodyCopyCapture}>
- <CollapsibleUserMessageBody
- text={resolvedContext.text}
- renderContextReference={renderContextReference}
- skills={ctx.skills}
- markdownCwd={ctx.markdownCwd}
- />
- </div>
</div>
<UserMessageProjectedStatus row={row} />
- <div className="flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover:opacity-100">
- <div className="flex shrink-0 items-center gap-2">
- <Tooltip>
- <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
- {formatDayAwareTimestamp(row.message.createdAt, ctx.timestampFormat)}
- </TooltipTrigger>
- <TooltipPopup>
- {formatChatTimestampTooltip(row.message.createdAt, ctx.timestampFormat)}
- </TooltipPopup>
- </Tooltip>
- <div className="flex items-center gap-0.5">
- {typeof revertTurnCount === "number" && (
- <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
- )}
- {resolvedContext.text && (
- <MessageCopyButton
- text={contextClipboardFragment ? resolvedContext.text : plainText}
- {...(contextClipboardFragment
- ? {
- extraFlavors: { [COMPOSER_CONTEXT_CLIPBOARD_MIME]: contextClipboardFragment },
- }
- : {})}
- variant="ghost"
- />
- )}
- {promptLink !== null && (
- <MessageCopyButton
- text={promptLink}
- label="Copy prompt link"
- icon={LinkIconNode}
- variant="ghost"
- />
- )}
+ {!folded || expanded ? (
+ <div className="flex w-full max-w-[80%] items-center justify-end pe-1 text-xs tabular-nums opacity-0 transition-opacity duration-200 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover:opacity-100">
+ <div className="flex shrink-0 items-center gap-2">
+ {folded && senderThreadId ? (
+ <InlineButton onClick={() => ctx.onOpenThread(senderThreadId)} tone="muted">
+ Open thread
+ </InlineButton>
+ ) : null}
+ <Tooltip>
+ <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
+ {formatDayAwareTimestamp(row.message.createdAt, ctx.timestampFormat)}
+ </TooltipTrigger>
+ <TooltipPopup>
+ {formatChatTimestampTooltip(row.message.createdAt, ctx.timestampFormat)}
+ </TooltipPopup>
+ </Tooltip>
+ <div className="flex items-center gap-0.5">
+ {typeof revertTurnCount === "number" && (
+ <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
+ )}
+ {resolvedContext.text && (
+ <MessageCopyButton
+ text={contextClipboardFragment ? resolvedContext.text : plainText}
+ {...(contextClipboardFragment
+ ? {
+ extraFlavors: {
+ [COMPOSER_CONTEXT_CLIPBOARD_MIME]: contextClipboardFragment,
+ },
+ }
+ : {})}
+ variant="ghost"
+ />
+ )}
+ {promptLink !== null && (
+ <MessageCopyButton
+ text={promptLink}
+ label="Copy prompt link"
+ icon={LinkIconNode}
+ variant="ghost"
+ />
+ )}
+ </div>
</div>
</div>
- </div>
+ ) : null}
</div>
);
}
@@ -630,13 +696,15 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
renderContextReference: (reference: ChatMarkdownContextReference) => ReactNode;
skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
markdownCwd: string | undefined;
+ collapsible?: boolean;
footer?: ReactNode;
}) {
const [expanded, setExpanded] = useState(false);
const revealForFind = () => setExpanded(true);
const revealRef = findRevealRef(revealForFind);
const hasVisibleBody = props.text.trim().length > 0;
- const canCollapse = hasVisibleBody && shouldCollapseUserMessage(props.text);
+ const canCollapse =
+ props.collapsible !== false && hasVisibleBody && shouldCollapseUserMessage(props.text);
const isCollapsed = canCollapse && !expanded;
const showCollapseControl = canCollapse;