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 22, 19:30 UTC
feat(web,mobile): messages from other agents fold into one-line rows (#23135)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 22, 2026 at 18:17 UTC
f054d1b8018721bd997d99cbb918a7b17bf098a4
3 files changed
+531
-335
apps/mobile/src/features/threads/ThreadFeed.tsx
+230
-160
@@ -240,7 +240,7 @@ import {
240
pickWorkspaceBasenameMatch,
241
WORKSPACE_BASENAME_LOOKUP_LIMIT,
242
} from "@t3tools/client-runtime/workspace-basename-lookup";
243
-import { useLiveThreadLinkLabels } from "../../state/entities";
243
+import { useLiveThreadLinkLabels, useQuietThreadShell } from "../../state/entities";
244
import { useThreadSelection } from "../../state/use-thread-selection";
245
import { useEnvironmentQuery } from "../../state/query";
246
import { serverEnvironment } from "../../state/server";
@@ -969,33 +969,76 @@ function useMarkdownStyles(): MarkdownStyleSets {
969
]);
970
}
971
972
-function AgentMessageAttribution(props: {
972
+/** Messages from other agents fold to one line so the user's own messages stay easy to find. */
973
+function AgentMessageFoldHeader(props: {
974
readonly environmentId: EnvironmentId;
975
readonly senderThreadId?: ThreadId;
976
+ readonly summary: string;
977
+ readonly expanded: boolean;
978
+ readonly onToggle: () => void;
979
+ readonly iconSubtleColor: ColorValue;
980
}) {
976
- const navigation = useNavigation();
977
- const senderThreadId = props.senderThreadId;
978
- const label = (
979
- <Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
980
- Sent by another agent
981
- </Text>
981
+ const senderShell = useQuietThreadShell(
982
+ props.senderThreadId ? scopeThreadRef(props.environmentId, props.senderThreadId) : null,
983
);
983
- return senderThreadId ? (
984
+ const label = senderShell?.title.trim() || "Agent";
985
+ return (
986
<Pressable
987
accessibilityRole="button"
986
- accessibilityLabel="Open sending thread"
988
+ accessibilityLabel={`${label}: ${props.summary}`}
989
+ accessibilityHint={`Double tap to ${props.expanded ? "hide" : "show"} the message.`}
990
+ accessibilityState={{ expanded: props.expanded }}
991
hitSlop={4}
992
+ className="min-h-10 flex-row items-center gap-1.5 px-3.5 py-2"
993
+ onPress={() => {
994
+ void Haptics.selectionAsync();
995
+ props.onToggle();
996
+ }}
997
+ >
998
+ <SymbolView
999
+ name="bubble.left.and.bubble.right"
1000
+ size={14}
1001
+ weight="medium"
1002
+ tintColorClassName="accent-user-bubble-foreground-muted"
1003
+ type="monochrome"
1004
+ />
1005
+ <Text
1006
+ numberOfLines={1}
1007
+ className="max-w-[50%] shrink-0 font-t3-medium text-sm text-user-bubble-foreground-muted"
1008
+ >
1009
+ {label}
1010
+ </Text>
1011
+ <Text numberOfLines={1} className="min-w-0 shrink text-sm text-user-bubble-foreground">
1012
+ {props.summary}
1013
+ </Text>
1014
+ <ThreadDisclosureChevron
1015
+ expanded={props.expanded}
1016
+ collapsedDirection="down"
1017
+ size={11}
1018
+ tintColor={props.iconSubtleColor}
1019
+ />
1020
+ </Pressable>
1021
+ );
1022
+}
1023
+
1024
+function OpenSenderThreadButton(props: {
1025
+ readonly environmentId: EnvironmentId;
1026
+ readonly senderThreadId: ThreadId;
1027
+}) {
1028
+ const navigation = useNavigation();
1029
+ return (
1030
+ <Pressable
1031
+ accessibilityRole="link"
1032
+ hitSlop={6}
1033
onPress={() =>
1034
navigation.navigate("Thread", {
1035
environmentId: String(props.environmentId),
991
- threadId: String(senderThreadId),
1036
+ threadId: String(props.senderThreadId),
1037
})
1038
}
1039
>
995
- {label}
1040
+ <Text className="font-t3-medium text-xs text-foreground-secondary">Open thread</Text>
1041
</Pressable>
997
- ) : (
998
- label
1042
);
1043
}
1044
@@ -1360,6 +1403,9 @@ function renderFeedEntry(
1403
}
1404
if (isUser) {
1405
const enterAnimated = isFreshTimestamp(message.createdAt);
1406
+ const foldRowId = presentation.attribution === "agent" ? `agent:${message.id}` : null;
1407
+ const foldExpanded = foldRowId !== null && (props.expandedWorkRows[foldRowId] ?? false);
1408
+ const bubbleBodyVisible = foldRowId === null || foldExpanded;
1409
const intentBadge = resolveUserMessageIntentBadge(message.inputIntent);
1410
const referenceIds = new Set(
1411
collectComposerContextReferences(message.text).map((reference) => reference.contextId),
@@ -1383,169 +1429,193 @@ function renderFeedEntry(
1429
<Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
1430
Sent by T3 Code
1431
</Text>
1386
- ) : presentation.attribution === "agent" ? (
1387
- <AgentMessageAttribution
1388
- environmentId={props.environmentId}
1389
- senderThreadId={message.senderThreadId}
1390
- />
1432
) : null}
1433
<View
1393
- className="min-w-0 gap-2 rounded-[20px] px-3.5 py-2.5"
1434
+ className="min-w-0 rounded-[20px]"
1435
style={{
1436
backgroundColor: userBubbleColor,
1437
maxWidth: props.duoColumns ? "85%" : props.userBubbleMaxWidth,
1397
- ...(hasReviewCommentContext
1398
- ? { width: props.reviewCommentBubbleWidth }
1399
- : hasWideBlock
1400
- ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
1401
- : null),
1438
+ ...(!bubbleBodyVisible
1439
+ ? null
1440
+ : hasReviewCommentContext
1441
+ ? { width: props.reviewCommentBubbleWidth }
1442
+ : hasWideBlock || foldExpanded
1443
+ ? { width: props.duoColumns ? "85%" : props.userBubbleMaxWidth }
1444
+ : null),
1445
}}
1446
>
1404
- {entry.pendingMessage?.attachments.map((attachment) =>
1405
- attachment.type === "image" && attachment.uploadedAttachmentId ? (
1406
- <MessageAttachmentImage
1407
- key={attachment.id}
1408
- environmentId={props.environmentId}
1409
- attachmentId={attachment.uploadedAttachmentId}
1410
- name={attachment.name}
1411
- mimeType={attachment.mimeType}
1412
- className="h-[140px] w-[180px] rounded-[14px]"
1413
- onPressPreview={props.onPressPreview}
1414
- />
1415
- ) : attachment.type === "image" ? (
1416
- <Pressable
1417
- key={attachment.id}
1418
- accessibilityRole="imagebutton"
1419
- accessibilityLabel={`Open ${attachment.name}`}
1420
- onPress={() =>
1421
- props.onPressPreview({
1422
- kind: "image",
1423
- name: attachment.name,
1424
- uri: attachment.dataUrl ?? attachment.previewUri,
1425
- gallery: composerImageGallery(entry.pendingMessage?.attachments ?? []),
1426
- })
1427
- }
1428
- >
1429
- <Image
1430
- source={{ uri: attachment.previewUri }}
1431
- style={{ width: 180, height: 140, borderRadius: 14 }}
1432
- />
1433
- </Pressable>
1434
- ) : (
1435
- <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
1436
- ),
1437
- )}
1438
- {/* An empty container still takes a gap, which pads every attachment-free bubble. */}
1439
- {visibleAttachments.length > 0 ? (
1440
- <View className={inlineAttachmentIds.size ? "flex-row flex-wrap gap-2" : "gap-2"}>
1441
- {visibleAttachments.map((attachment) => {
1442
- return isImageAttachment(attachment) ? (
1447
+ {foldRowId !== null ? (
1448
+ <AgentMessageFoldHeader
1449
+ environmentId={props.environmentId}
1450
+ senderThreadId={message.senderThreadId}
1451
+ summary={
1452
+ replaceComposerContextReferences(presentation.text, (ref) => ref.label)
1453
+ .split(/\r?\n/)
1454
+ .find((line) => line.trim().length > 0)
1455
+ ?.trim() ?? ""
1456
+ }
1457
+ expanded={foldExpanded}
1458
+ onToggle={() => props.onToggleWorkRow(foldRowId, entry.id)}
1459
+ iconSubtleColor={iconSubtleColor}
1460
+ />
1461
+ ) : null}
1462
+ {bubbleBodyVisible ? (
1463
+ <View className={cn("gap-2 px-3.5 pb-2.5", foldRowId === null && "pt-2.5")}>
1464
+ {entry.pendingMessage?.attachments.map((attachment) =>
1465
+ attachment.type === "image" && attachment.uploadedAttachmentId ? (
1466
<MessageAttachmentImage
1467
key={attachment.id}
1468
environmentId={props.environmentId}
1446
- attachmentId={attachment.id}
1469
+ attachmentId={attachment.uploadedAttachmentId}
1470
name={attachment.name}
1471
mimeType={attachment.mimeType}
1449
- className={
1450
- inlineAttachmentIds.size
1451
- ? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
1452
- : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
1453
- }
1472
+ className="h-[140px] w-[180px] rounded-[14px]"
1473
onPressPreview={props.onPressPreview}
1474
/>
1456
- ) : isFileAttachment(attachment) ? (
1457
- <MessageAttachmentFile
1475
+ ) : attachment.type === "image" ? (
1476
+ <Pressable
1477
key={attachment.id}
1459
- environmentId={props.environmentId}
1460
- attachment={attachment}
1461
- onPressPreview={props.onPressPreview}
1462
- onPressVideo={props.onPressVideo}
1463
- />
1478
+ accessibilityRole="imagebutton"
1479
+ accessibilityLabel={`Open ${attachment.name}`}
1480
+ onPress={() =>
1481
+ props.onPressPreview({
1482
+ kind: "image",
1483
+ name: attachment.name,
1484
+ uri: attachment.dataUrl ?? attachment.previewUri,
1485
+ gallery: composerImageGallery(entry.pendingMessage?.attachments ?? []),
1486
+ })
1487
+ }
1488
+ >
1489
+ <Image
1490
+ source={{ uri: attachment.previewUri }}
1491
+ style={{ width: 180, height: 140, borderRadius: 14 }}
1492
+ />
1493
+ </Pressable>
1494
) : (
1495
<MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
1466
- );
1467
- })}
1496
+ ),
1497
+ )}
1498
+ {/* An empty container still takes a gap, which pads every attachment-free bubble. */}
1499
+ {visibleAttachments.length > 0 ? (
1500
+ <View className={inlineAttachmentIds.size ? "flex-row flex-wrap gap-2" : "gap-2"}>
1501
+ {visibleAttachments.map((attachment) => {
1502
+ return isImageAttachment(attachment) ? (
1503
+ <MessageAttachmentImage
1504
+ key={attachment.id}
1505
+ environmentId={props.environmentId}
1506
+ attachmentId={attachment.id}
1507
+ name={attachment.name}
1508
+ mimeType={attachment.mimeType}
1509
+ className={
1510
+ inlineAttachmentIds.size
1511
+ ? "h-24 w-24 rounded-[14px] bg-user-bubble-foreground/15"
1512
+ : "aspect-[1.3] w-full rounded-[14px] bg-user-bubble-foreground/15"
1513
+ }
1514
+ onPressPreview={props.onPressPreview}
1515
+ />
1516
+ ) : isFileAttachment(attachment) ? (
1517
+ <MessageAttachmentFile
1518
+ key={attachment.id}
1519
+ environmentId={props.environmentId}
1520
+ attachment={attachment}
1521
+ onPressPreview={props.onPressPreview}
1522
+ onPressVideo={props.onPressVideo}
1523
+ />
1524
+ ) : (
1525
+ <MessageAttachmentUnknown key={attachment.id} name={attachment.name} />
1526
+ );
1527
+ })}
1528
+ </View>
1529
+ ) : null}
1530
+ {message.text.trim().length > 0 ? (
1531
+ <MarkdownImageAvailableWidthContext
1532
+ value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
1533
+ >
1534
+ <UserMessageContent
1535
+ text={renderedText}
1536
+ environmentId={props.environmentId}
1537
+ context={message.context}
1538
+ markdownStyles={styles}
1539
+ reviewCommentColors={props.reviewCommentColors}
1540
+ skills={props.skills}
1541
+ linkHandlers={props.markdownLinkHandlers}
1542
+ renderImage={props.renderMarkdownImage}
1543
+ />
1544
+ </MarkdownImageAvailableWidthContext>
1545
+ ) : null}
1546
</View>
1547
) : null}
1470
- {message.text.trim().length > 0 ? (
1471
- <MarkdownImageAvailableWidthContext
1472
- value={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
1473
- >
1474
- <UserMessageContent
1475
- text={renderedText}
1548
+ </View>
1549
+ {bubbleBodyVisible ? (
1550
+ <View className="mt-1 flex-row items-center justify-end gap-1 pr-0.5">
1551
+ {foldRowId !== null && message.senderThreadId ? (
1552
+ <OpenSenderThreadButton
1553
environmentId={props.environmentId}
1477
- context={message.context}
1478
- markdownStyles={styles}
1479
- reviewCommentColors={props.reviewCommentColors}
1480
- skills={props.skills}
1481
- linkHandlers={props.markdownLinkHandlers}
1482
- renderImage={props.renderMarkdownImage}
1554
+ senderThreadId={message.senderThreadId}
1555
/>
1484
- </MarkdownImageAvailableWidthContext>
1485
- ) : null}
1486
- </View>
1487
- <View className="mt-1 flex-row items-center justify-end gap-1 pr-0.5">
1488
- {intentBadge ? (
1489
- <View
1490
- accessible
1491
- accessibilityLabel={intentBadge.accessibilityLabel}
1492
- className="flex-row items-center gap-1"
1493
- >
1494
- <SymbolView name="arrow.uturn.forward" size={12} tintColor={iconSubtleColor} />
1495
- <Text className="font-t3-medium text-xs text-foreground-secondary">
1496
- {intentBadge.label}
1556
+ ) : null}
1557
+ {intentBadge ? (
1558
+ <View
1559
+ accessible
1560
+ accessibilityLabel={intentBadge.accessibilityLabel}
1561
+ className="flex-row items-center gap-1"
1562
+ >
1563
+ <SymbolView name="arrow.uturn.forward" size={12} tintColor={iconSubtleColor} />
1564
+ <Text className="font-t3-medium text-xs text-foreground-secondary">
1565
+ {intentBadge.label}
1566
+ </Text>
1567
+ </View>
1568
+ ) : null}
1569
+ {intentBadge ? (
1570
+ <Text
1571
+ accessible={false}
1572
+ accessibilityElementsHidden
1573
+ importantForAccessibility="no"
1574
+ className="font-t3-medium text-xs text-foreground-secondary"
1575
+ >
1576
+ ·
1577
</Text>
1498
- </View>
1499
- ) : null}
1500
- {intentBadge ? (
1501
- <Text
1502
- accessible={false}
1503
- accessibilityElementsHidden
1504
- importantForAccessibility="no"
1505
- className="font-t3-medium text-xs text-foreground-secondary"
1506
- >
1507
- ·
1578
+ ) : null}
1579
+ <Text className="font-t3-medium text-xs tabular-nums text-foreground-secondary">
1580
+ {entry.pendingMessage && !entry.acknowledged ? "Pending" : timestampLabel}
1581
</Text>
1509
- ) : null}
1510
- <Text className="font-t3-medium text-xs tabular-nums text-foreground-secondary">
1511
- {entry.pendingMessage && !entry.acknowledged ? "Pending" : timestampLabel}
1512
- </Text>
1513
- {props.onEditPendingMessage !== null &&
1514
- entry.pendingMessage &&
1515
- !entry.acknowledged &&
1516
- !entry.pendingMessage.creation &&
1517
- entry.pendingMessage.messageId !== props.dispatchingMessageId ? (
1518
- <Pressable
1519
- accessibilityRole="button"
1520
- accessibilityLabel="Edit pending message"
1521
- hitSlop={8}
1522
- className="size-7 items-center justify-center"
1523
- onPress={() => {
1524
- if (entry.pendingMessage && props.onEditPendingMessage) {
1525
- props.onEditPendingMessage(entry.pendingMessage);
1582
+ {props.onEditPendingMessage !== null &&
1583
+ entry.pendingMessage &&
1584
+ !entry.acknowledged &&
1585
+ !entry.pendingMessage.creation &&
1586
+ entry.pendingMessage.messageId !== props.dispatchingMessageId ? (
1587
+ <Pressable
1588
+ accessibilityRole="button"
1589
+ accessibilityLabel="Edit pending message"
1590
+ hitSlop={8}
1591
+ className="size-7 items-center justify-center"
1592
+ onPress={() => {
1593
+ if (entry.pendingMessage && props.onEditPendingMessage) {
1594
+ props.onEditPendingMessage(entry.pendingMessage);
1595
+ }
1596
+ }}
1597
+ >
1598
+ <SymbolView name="pencil" size={14} tintColor={iconSubtleColor} />
1599
+ </Pressable>
1600
+ ) : null}
1601
+ {presentation.text.trim().length > 0 ? (
1602
+ <UserMessageCopyButton
1603
+ text={presentation.text}
1604
+ onCopy={
1605
+ message.context
1606
+ ? () =>
1607
+ writeComposerContextClipboard(message.text, {
1608
+ version: 1,
1609
+ source: { environmentId: props.environmentId, messageId: message.id },
1610
+ records: message.context!.records,
1611
+ })
1612
+ : undefined
1613
}
1527
- }}
1528
- >
1529
- <SymbolView name="pencil" size={14} tintColor={iconSubtleColor} />
1530
- </Pressable>
1531
- ) : null}
1532
- {presentation.text.trim().length > 0 ? (
1533
- <UserMessageCopyButton
1534
- text={presentation.text}
1535
- onCopy={
1536
- message.context
1537
- ? () =>
1538
- writeComposerContextClipboard(message.text, {
1539
- version: 1,
1540
- source: { environmentId: props.environmentId, messageId: message.id },
1541
- records: message.context!.records,
1542
- })
1543
- : undefined
1544
- }
1545
- tintColor={iconSubtleColor}
1546
- />
1547
- ) : null}
1548
- </View>
1614
+ tintColor={iconSubtleColor}
1615
+ />
1616
+ ) : null}
1617
+ </View>
1618
+ ) : null}
1619
</Animated.View>
1620
);
1621
}
@@ -2974,13 +3044,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3044
renderItem={renderItem}
3045
viewabilityConfig={THREAD_MEDIA_VIEWABILITY_CONFIG}
3046
keyExtractor={(entry) => entry.id}
2977
- getItemType={(entry) =>
2978
- entry.type !== "message"
2979
- ? entry.type
2980
- : resolveUserMessagePresentation(entry.message).attribution === "automation"
2981
- ? "message:automation"
2982
- : `message:${entry.message.role}`
2983
- }
3047
+ getItemType={(entry) => {
3048
+ if (entry.type !== "message") return entry.type;
3049
+ const { attribution } = resolveUserMessagePresentation(entry.message);
3050
+ return attribution === "automation" || attribution === "agent"
3051
+ ? `message:${attribution}`
3052
+ : `message:${entry.message.role}`;
3053
+ }}
3054
getFixedItemSize={getFixedItemSize}
3055
// Virtualized rows must move with their measurements. Native layout
3056
// transitions can retain stale positions during sync, even at duration 0.
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+59
-1
@@ -1,4 +1,4 @@
1
-import { EnvironmentId, MessageId, RunId, ScheduledTaskId } from "@t3tools/contracts";
1
+import { EnvironmentId, MessageId, RunId, ScheduledTaskId, ThreadId } from "@t3tools/contracts";
2
import type { LegendListRef } from "@legendapp/list/react";
3
import { createRef, Profiler, type ComponentProps, type ReactElement } from "react";
4
import { describe, expect, it, vi } from "vite-plus/test";
@@ -310,6 +310,64 @@ describe("MessagesTimeline automation prompts", () => {
310
});
311
});
312
313
+const SENDER_THREAD_ID = ThreadId.make("thread-sender");
314
+const AGENT_MESSAGE = "Review finished\n\nThe migration drops the index before backfilling it.";
315
+
316
+describe("MessagesTimeline agent messages", () => {
317
+ it("folds a message from another agent into a one-line preview", async () => {
318
+ setup();
319
+ const onOpenThread = vi.fn();
320
+ await using screen = await renderTimeline(
321
+ [message(AGENT_MESSAGE, { createdBy: "agent", senderThreadId: SENDER_THREAD_ID })],
322
+ { onOpenThread },
323
+ );
324
+ const row = screen.button(/^Agent/);
325
+ expect(row.textContent).toContain("Review finished");
326
+ expect(row.getAttribute("aria-expanded")).toBe("false");
327
+ expect(screen.text()).not.toContain("drops the index");
328
+ expect(screen.buttons("Open thread")).toHaveLength(0);
329
+
330
+ await click(row);
331
+ expect(screen.text()).toContain("The migration drops the index before backfilling it.");
332
+ await click(screen.button("Open thread"));
333
+ expect(onOpenThread).toHaveBeenCalledWith(SENDER_THREAD_ID);
334
+
335
+ await click(screen.button(/^Agent/));
336
+ expect(screen.text()).not.toContain("drops the index");
337
+ });
338
+
339
+ it("leaves messages sent by T3 Code as full bubbles", async () => {
340
+ setup();
341
+ await using screen = await renderTimeline([
342
+ message(AGENT_MESSAGE, { createdBy: "agent", creationSource: "server" }),
343
+ ]);
344
+ expect(screen.buttons(/^Agent/)).toHaveLength(0);
345
+ expect(screen.text()).toContain("drops the index");
346
+ });
347
+
348
+ it("reveals a find match inside a folded agent message", async () => {
349
+ setup();
350
+ const text = `${"Checked the next file.\n\n".repeat(16)}The migration drops the index.`;
351
+ await using screen = await renderTimeline(
352
+ [message(text, { createdBy: "agent", senderThreadId: SENDER_THREAD_ID })],
353
+ {
354
+ findExpanded: true,
355
+ findQuery: "drops the index",
356
+ activeFindMatch: { entryId: "entry-message-1", runId: null, occurrence: 0 },
357
+ },
358
+ );
359
+ await vi.waitFor(() =>
360
+ expect(screen.button(/^Agent/).getAttribute("aria-expanded")).toBe("true"),
361
+ );
362
+ const { range } = collectThreadFindRanges(screen.container, "drops the index")[0]!;
363
+ const body = screen.container.querySelector("[data-user-message-body]")!;
364
+ expect(range.getBoundingClientRect().height).toBeGreaterThan(0);
365
+ expect(range.getBoundingClientRect().bottom).toBeLessThanOrEqual(
366
+ body.getBoundingClientRect().bottom,
367
+ );
368
+ });
369
+});
370
+
371
describe("compact reasoning math", () => {
372
it("keeps formulas while flattening compact reasoning previews", () => {
373
const tree = parseMarkdownWithMath("## Reasoning\n\nUse **norm** $|x|$ and \\[x^2\\]");
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+242
-174
@@ -2,6 +2,7 @@ import { findRevealRef } from "./markdownFindContext";
2
import { type MessageId, type ServerProviderSkill, ThreadId } from "@t3tools/contracts";
3
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
4
import { Link } from "@tanstack/react-router";
5
+import { useQuietThreadShell } from "../../state/entities";
6
import { useEnvironmentQuery } from "../../state/query";
7
import { serverEnvironment } from "../../state/server";
8
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
@@ -22,6 +23,8 @@ import {
23
ChevronDownIcon,
24
DownloadIcon,
25
EyeIcon,
26
+ type LucideIcon,
27
+ MessagesSquareIcon,
28
Redo2Icon,
29
Undo2Icon,
30
} from "lucide-react";
@@ -162,23 +165,13 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
165
expanded && "w-full",
166
)}
167
>
165
- <button
166
- type="button"
167
- aria-expanded={expanded}
168
- data-scroll-anchor-ignore
169
- onClick={() => setExpanded((value) => !value)}
170
- 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"
171
- >
172
- <CalendarClockIcon className="size-4 shrink-0 stroke-2 text-muted-foreground" />
173
- <span className="shrink-0 text-muted-foreground">Automation</span>
174
- <span className="min-w-0 flex-1 truncate">{summary}</span>
175
- <ChevronDownIcon
176
- className={cn(
177
- "size-3.5 shrink-0 text-muted-foreground transition-transform",
178
- expanded && "rotate-180",
179
- )}
180
- />
181
- </button>
168
+ <FoldedMessageHeader
169
+ icon={CalendarClockIcon}
170
+ label="Automation"
171
+ summary={summary}
172
+ expanded={expanded}
173
+ onToggle={() => setExpanded((value) => !value)}
174
+ />
175
{bodyMounted ? (
176
// `beforematch` does not bubble, so the reveal listener sits on the hidden fold itself.
177
<div
@@ -230,6 +223,35 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
223
);
224
}
225
226
+function FoldedMessageHeader(props: {
227
+ icon: LucideIcon;
228
+ label: string;
229
+ summary: string;
230
+ expanded: boolean;
231
+ onToggle: () => void;
232
+}) {
233
+ const Icon = props.icon;
234
+ return (
235
+ <button
236
+ type="button"
237
+ aria-expanded={props.expanded}
238
+ data-scroll-anchor-ignore
239
+ onClick={props.onToggle}
240
+ 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"
241
+ >
242
+ <Icon className="size-4 shrink-0 stroke-2 text-muted-foreground" />
243
+ <span className="max-w-1/2 shrink-0 truncate text-muted-foreground">{props.label}</span>
244
+ <span className="min-w-0 flex-1 truncate">{props.summary}</span>
245
+ <ChevronDownIcon
246
+ className={cn(
247
+ "size-3.5 shrink-0 text-muted-foreground transition-transform",
248
+ props.expanded && "rotate-180",
249
+ )}
250
+ />
251
+ </button>
252
+ );
253
+}
254
+
255
function UserMessageProjectedStatus({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
256
const status = row.projectedItem?.item.status;
257
if (
@@ -272,6 +294,15 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
294
(attachment) => !isImageAttachment(attachment) && !isFileAttachment(attachment),
295
);
296
const userMessage = resolveUserMessagePresentation(row.message);
297
+ // Messages from other agents fold to one line so the user's own messages stay easy to find.
298
+ const folded = userMessage.attribution === "agent";
299
+ const [expanded, setExpanded] = useState(false);
300
+ const revealFoldRef = findRevealRef(() => setExpanded(true));
301
+ const senderShell = useQuietThreadShell(
302
+ folded && senderThreadId
303
+ ? { environmentId: ctx.activeThreadEnvironmentId, threadId: senderThreadId }
304
+ : null,
305
+ );
306
const resolvedContext = resolveUserMessageContext(row.message);
307
const previewImages = userImages.filter((image) => image.name.startsWith("preview-annotation-"));
308
const revertTurnCount = row.revertTurnCount;
@@ -291,6 +322,11 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
322
(reference) => reference.label,
323
);
324
const promptLink = promptLinkFor(plainText);
325
+ const foldSummary =
326
+ plainText
327
+ .split(/\r?\n/)
328
+ .find((line) => line.trim().length > 0)
329
+ ?.trim() ?? "";
330
const contextClipboardFragment =
331
resolvedContext.records.length === 0
332
? null
@@ -379,7 +415,10 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
415
};
416
417
return (
382
- <div className="group flex flex-col items-end gap-1">
418
+ <div
419
+ className="group flex flex-col items-end gap-1"
420
+ data-user-message-attribution={folded ? "agent" : undefined}
421
+ >
422
{userMessage.attribution === "t3code" ? (
423
<p
424
className="me-1 text-2xs text-muted-foreground/70"
@@ -387,178 +426,205 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
426
>
427
Sent by T3 Code
428
</p>
390
- ) : userMessage.attribution === "agent" ? (
391
- <p className="me-1 text-2xs text-muted-foreground/70" data-user-message-attribution="agent">
392
- {senderThreadId ? (
393
- <InlineButton
394
- onClick={() => ctx.onOpenThread(senderThreadId)}
395
- tone="muted"
396
- aria-label="Open sending thread"
397
- >
398
- Sent by another agent
399
- </InlineButton>
400
- ) : (
401
- "Sent by another agent"
402
- )}
403
- </p>
429
) : null}
430
{row.message.inputIntent === "steer" ||
431
row.message.inputIntent === "promoted_queued_to_steer" ? (
432
<UserMessageIntentMarker intent={row.message.inputIntent} />
433
) : null}
409
- <div className="relative max-w-[80%] rounded-2xl bg-message p-3 text-message-foreground">
410
- <MessageAuthorHeading>You</MessageAuthorHeading>
411
- {(regularImages.length > 0 || userVideos.length > 0) && (
412
- <div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
413
- {regularImages.map((image) => (
414
- <div
415
- key={image.id}
416
- className={cn(
417
- "bg-background/70",
418
- image.source?.kind === "snap-shot" && image.previewUrl
419
- ? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
420
- : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
421
- )}
422
- >
423
- {image.previewUrl ? (
424
- <button
425
- type="button"
426
- className="block h-full w-full cursor-zoom-in"
427
- aria-label={`Preview ${image.name}`}
428
- onClick={() => {
429
- const preview = buildExpandedImagePreview(regularImages, image.id);
430
- if (!preview) return;
431
- ctx.onImageExpand(preview);
432
- }}
434
+ <div
435
+ className={cn(
436
+ "relative min-w-0 max-w-[80%] rounded-2xl bg-message text-message-foreground",
437
+ !folded && "p-3",
438
+ folded && expanded && "w-full",
439
+ )}
440
+ >
441
+ {folded ? (
442
+ <FoldedMessageHeader
443
+ icon={MessagesSquareIcon}
444
+ label={senderShell?.title.trim() || "Agent"}
445
+ summary={foldSummary}
446
+ expanded={expanded}
447
+ onToggle={() => setExpanded((value) => !value)}
448
+ />
449
+ ) : null}
450
+ {/* Find reads the DOM, so a folded message stays mounted but hidden while find is open. */}
451
+ {!folded || expanded || ctx.findActive ? (
452
+ <div
453
+ ref={folded ? revealFoldRef : undefined}
454
+ hidden={folded && !expanded}
455
+ className={cn(
456
+ folded && "px-3 pb-3",
457
+ folded && !ctx.findActive && "max-h-96 overflow-auto",
458
+ )}
459
+ >
460
+ <MessageAuthorHeading>You</MessageAuthorHeading>
461
+ {(regularImages.length > 0 || userVideos.length > 0) && (
462
+ <div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
463
+ {regularImages.map((image) => (
464
+ <div
465
+ key={image.id}
466
+ className={cn(
467
+ "bg-background/70",
468
+ image.source?.kind === "snap-shot" && image.previewUrl
469
+ ? cn(SNAP_SHOT_ATTACHMENT_FRAME_CLASS, "col-span-2")
470
+ : "aspect-[4/3] overflow-hidden rounded-lg border border-border/80",
471
+ )}
472
>
434
- <AttachmentImage
435
- name={image.name}
436
- mimeType={image.mimeType}
437
- src={image.previewUrl}
438
- alt={image.name}
439
- decoding="async"
440
- className="block size-full object-cover"
441
- />
442
- </button>
443
- ) : (
444
- <div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70">
445
- {image.name}
473
+ {image.previewUrl ? (
474
+ <button
475
+ type="button"
476
+ className="block h-full w-full cursor-zoom-in"
477
+ aria-label={`Preview ${image.name}`}
478
+ onClick={() => {
479
+ const preview = buildExpandedImagePreview(regularImages, image.id);
480
+ if (!preview) return;
481
+ ctx.onImageExpand(preview);
482
+ }}
483
+ >
484
+ <AttachmentImage
485
+ name={image.name}
486
+ mimeType={image.mimeType}
487
+ src={image.previewUrl}
488
+ alt={image.name}
489
+ decoding="async"
490
+ className="block size-full object-cover"
491
+ />
492
+ </button>
493
+ ) : (
494
+ <div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-2xs text-muted-foreground/70">
495
+ {image.name}
496
+ </div>
497
+ )}
498
+ {image.previewUrl && image.source?.kind === "snap-shot" ? (
499
+ <SnapShotAttachmentDetails source={image.source} />
500
+ ) : null}
501
</div>
447
- )}
448
- {image.previewUrl && image.source?.kind === "snap-shot" ? (
449
- <SnapShotAttachmentDetails source={image.source} />
450
- ) : null}
502
+ ))}
503
+ {userVideos.map((file) => (
504
+ <UserVideoAttachment key={file.id} file={file} />
505
+ ))}
506
</div>
452
- ))}
453
- {userVideos.map((file) => (
454
- <UserVideoAttachment key={file.id} file={file} />
455
- ))}
456
- </div>
457
- )}
458
- {unchippedFiles.length > 0 || unknownAttachments.length > 0 ? (
459
- <div className="mb-2 flex flex-col gap-1">
460
- {unchippedFiles.map((file) => {
461
- const fileIdentity = (
462
- <>
463
- <PierreEntryIcon pathValue={file.name} kind="file" theme={ctx.resolvedTheme} />
464
- <span className="min-w-0 flex-1 truncate">{file.name}</span>
465
- </>
466
- );
467
- if (file.downloadable !== false) {
468
- return (
469
- <div key={file.id} className="flex min-w-0 items-center gap-1">
470
- <button
471
- type="button"
472
- aria-label={`Preview ${file.name}`}
473
- onClick={() => ctx.onFileOpen(file)}
474
- 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"
475
- >
507
+ )}
508
+ {unchippedFiles.length > 0 || unknownAttachments.length > 0 ? (
509
+ <div className="mb-2 flex flex-col gap-1">
510
+ {unchippedFiles.map((file) => {
511
+ const fileIdentity = (
512
+ <>
513
+ <PierreEntryIcon
514
+ pathValue={file.name}
515
+ kind="file"
516
+ theme={ctx.resolvedTheme}
517
+ />
518
+ <span className="min-w-0 flex-1 truncate">{file.name}</span>
519
+ </>
520
+ );
521
+ if (file.downloadable !== false) {
522
+ return (
523
+ <div key={file.id} className="flex min-w-0 items-center gap-1">
524
+ <button
525
+ type="button"
526
+ aria-label={`Preview ${file.name}`}
527
+ onClick={() => ctx.onFileOpen(file)}
528
+ 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"
529
+ >
530
+ {fileIdentity}
531
+ <EyeIcon className="size-4 shrink-0" />
532
+ </button>
533
+ <Tooltip>
534
+ <TooltipTrigger
535
+ render={
536
+ <Button
537
+ size="icon-xs"
538
+ variant="ghost-muted"
539
+ aria-label={`Download ${file.name}`}
540
+ onClick={() => ctx.onFileDownload(file)}
541
+ />
542
+ }
543
+ >
544
+ <DownloadIcon />
545
+ </TooltipTrigger>
546
+ <TooltipPopup side="top">Download {file.name}</TooltipPopup>
547
+ </Tooltip>
548
+ </div>
549
+ );
550
+ }
551
+
552
+ return (
553
+ <div key={file.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
554
{fileIdentity}
477
- <EyeIcon className="size-4 shrink-0" />
478
- </button>
479
- <Tooltip>
480
- <TooltipTrigger
481
- render={
482
- <Button
483
- size="icon-xs"
484
- variant="ghost-muted"
485
- aria-label={`Download ${file.name}`}
486
- onClick={() => ctx.onFileDownload(file)}
487
- />
488
- }
489
- >
490
- <DownloadIcon />
491
- </TooltipTrigger>
492
- <TooltipPopup side="top">Download {file.name}</TooltipPopup>
493
- </Tooltip>
555
+ </div>
556
+ );
557
+ })}
558
+ {unknownAttachments.map((attachment) => (
559
+ <div key={attachment.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
560
+ <PierreEntryIcon
561
+ pathValue={attachment.name}
562
+ kind="file"
563
+ theme={ctx.resolvedTheme}
564
+ />
565
+ <span className="min-w-0 flex-1 truncate">{attachment.name}</span>
566
</div>
495
- );
496
- }
497
-
498
- return (
499
- <div key={file.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
500
- {fileIdentity}
501
- </div>
502
- );
503
- })}
504
- {unknownAttachments.map((attachment) => (
505
- <div key={attachment.id} className="flex min-w-0 items-center gap-2 py-1 text-sm">
506
- <PierreEntryIcon
507
- pathValue={attachment.name}
508
- kind="file"
509
- theme={ctx.resolvedTheme}
510
- />
511
- <span className="min-w-0 flex-1 truncate">{attachment.name}</span>
567
+ ))}
568
</div>
513
- ))}
569
+ ) : null}
570
+ <div onCopyCapture={onBodyCopyCapture}>
571
+ <CollapsibleUserMessageBody
572
+ text={resolvedContext.text}
573
+ renderContextReference={renderContextReference}
574
+ skills={ctx.skills}
575
+ markdownCwd={ctx.markdownCwd}
576
+ collapsible={!folded}
577
+ />
578
+ </div>
579
</div>
580
) : null}
516
- <div onCopyCapture={onBodyCopyCapture}>
517
- <CollapsibleUserMessageBody
518
- text={resolvedContext.text}
519
- renderContextReference={renderContextReference}
520
- skills={ctx.skills}
521
- markdownCwd={ctx.markdownCwd}
522
- />
523
- </div>
581
</div>
582
<UserMessageProjectedStatus row={row} />
526
- <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">
527
- <div className="flex shrink-0 items-center gap-2">
528
- <Tooltip>
529
- <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
530
- {formatDayAwareTimestamp(row.message.createdAt, ctx.timestampFormat)}
531
- </TooltipTrigger>
532
- <TooltipPopup>
533
- {formatChatTimestampTooltip(row.message.createdAt, ctx.timestampFormat)}
534
- </TooltipPopup>
535
- </Tooltip>
536
- <div className="flex items-center gap-0.5">
537
- {typeof revertTurnCount === "number" && (
538
- <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
539
- )}
540
- {resolvedContext.text && (
541
- <MessageCopyButton
542
- text={contextClipboardFragment ? resolvedContext.text : plainText}
543
- {...(contextClipboardFragment
544
- ? {
545
- extraFlavors: { [COMPOSER_CONTEXT_CLIPBOARD_MIME]: contextClipboardFragment },
546
- }
547
- : {})}
548
- variant="ghost"
549
- />
550
- )}
551
- {promptLink !== null && (
552
- <MessageCopyButton
553
- text={promptLink}
554
- label="Copy prompt link"
555
- icon={LinkIconNode}
556
- variant="ghost"
557
- />
558
- )}
583
+ {!folded || expanded ? (
584
+ <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">
585
+ <div className="flex shrink-0 items-center gap-2">
586
+ {folded && senderThreadId ? (
587
+ <InlineButton onClick={() => ctx.onOpenThread(senderThreadId)} tone="muted">
588
+ Open thread
589
+ </InlineButton>
590
+ ) : null}
591
+ <Tooltip>
592
+ <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
593
+ {formatDayAwareTimestamp(row.message.createdAt, ctx.timestampFormat)}
594
+ </TooltipTrigger>
595
+ <TooltipPopup>
596
+ {formatChatTimestampTooltip(row.message.createdAt, ctx.timestampFormat)}
597
+ </TooltipPopup>
598
+ </Tooltip>
599
+ <div className="flex items-center gap-0.5">
600
+ {typeof revertTurnCount === "number" && (
601
+ <RevertUserMessageButton turnCount={revertTurnCount} messageId={row.message.id} />
602
+ )}
603
+ {resolvedContext.text && (
604
+ <MessageCopyButton
605
+ text={contextClipboardFragment ? resolvedContext.text : plainText}
606
+ {...(contextClipboardFragment
607
+ ? {
608
+ extraFlavors: {
609
+ [COMPOSER_CONTEXT_CLIPBOARD_MIME]: contextClipboardFragment,
610
+ },
611
+ }
612
+ : {})}
613
+ variant="ghost"
614
+ />
615
+ )}
616
+ {promptLink !== null && (
617
+ <MessageCopyButton
618
+ text={promptLink}
619
+ label="Copy prompt link"
620
+ icon={LinkIconNode}
621
+ variant="ghost"
622
+ />
623
+ )}
624
+ </div>
625
</div>
626
</div>
561
- </div>
627
+ ) : null}
628
</div>
629
);
630
}
@@ -630,13 +696,15 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
696
renderContextReference: (reference: ChatMarkdownContextReference) => ReactNode;
697
skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
698
markdownCwd: string | undefined;
699
+ collapsible?: boolean;
700
footer?: ReactNode;
701
}) {
702
const [expanded, setExpanded] = useState(false);
703
const revealForFind = () => setExpanded(true);
704
const revealRef = findRevealRef(revealForFind);
705
const hasVisibleBody = props.text.trim().length > 0;
639
- const canCollapse = hasVisibleBody && shouldCollapseUserMessage(props.text);
706
+ const canCollapse =
707
+ props.collapsible !== false && hasVisibleBody && shouldCollapseUserMessage(props.text);
708
const isCollapsed = canCollapse && !expanded;
709
const showCollapseControl = canCollapse;
710