Skip to content

Commit d27c606

Browse files
feat: show automation messages as compact timeline rows (#22638)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4196708 commit d27c606

4 files changed

Lines changed: 397 additions & 43 deletions

File tree

‎apps/mobile/src/components/ui/AppSymbol.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import IconAlertCircle from "@tabler/icons-react-native/IconAlertCircle";
99
import IconAlertTriangle from "@tabler/icons-react-native/IconAlertTriangle";
1010
import IconApps from "@tabler/icons-react-native/IconApps";
1111
import IconArchive from "@tabler/icons-react-native/IconArchive";
12+
import IconCalendarClock from "@tabler/icons-react-native/IconCalendarClock";
1213
import IconArrowBackUp from "@tabler/icons-react-native/IconArrowBackUp";
1314
import IconArrowDown from "@tabler/icons-react-native/IconArrowDown";
1415
import IconArrowForwardUp from "@tabler/icons-react-native/IconArrowForwardUp";
@@ -178,6 +179,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
178179
"circle.dashed": IconCircleDashed,
179180
"circle.inset.filled": IconCircleDot,
180181
"circle.dashed.inset.filled": IconCircleDot,
182+
"calendar.badge.clock": IconCalendarClock,
181183
clock: IconClock,
182184
timer: IconClock,
183185
ticket: IconTicket,

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

Lines changed: 151 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
type MessageId,
4141
type OrchestrationV2ProjectedTurnItem,
4242
type RunId,
43+
type ScheduledTaskId,
4344
} from "@t3tools/contracts";
4445
import { renderAssistantCitationsAsText } from "@t3tools/shared/assistantCitations";
4546
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
@@ -236,6 +237,8 @@ import {
236237
} from "@t3tools/client-runtime/workspace-basename-lookup";
237238
import { useLiveThreadLinkLabels } from "../../state/entities";
238239
import { useThreadSelection } from "../../state/use-thread-selection";
240+
import { useEnvironmentQuery } from "../../state/query";
241+
import { serverEnvironment } from "../../state/server";
239242
import { composerDocumentAttachmentRecord } from "../../lib/composerContext";
240243
import * as Option from "effect/Option";
241244
import { appAtomRegistry } from "../../state/atom-registry";
@@ -983,6 +986,125 @@ function AgentMessageAttribution(props: {
983986
);
984987
}
985988

989+
/** Automation prompts are long, repeated runbooks; a folded bubble keeps them out of the way. */
990+
function ThreadAutomationMessageRow(props: {
991+
readonly environmentId: EnvironmentId;
992+
readonly text: string;
993+
readonly context?: OrchestrationMessageContext;
994+
readonly scheduledTaskId: ScheduledTaskId | undefined;
995+
readonly timestampLabel: string;
996+
readonly expanded: boolean;
997+
readonly onToggle: () => void;
998+
readonly bubbleColor: ColorValue;
999+
readonly bubbleMaxWidth: number | "85%";
1000+
readonly contentMaxWidth: number;
1001+
readonly iconSubtleColor: ColorValue;
1002+
readonly markdownStyles: MarkdownStyleSet;
1003+
readonly reviewCommentColors: ReviewCommentColors;
1004+
readonly skills?: ReadonlyArray<SelectableMarkdownSkill>;
1005+
readonly linkHandlers: MarkdownLinkHandlers;
1006+
readonly renderImage: MarkdownImageRenderer;
1007+
}) {
1008+
const navigation = useNavigation();
1009+
const tasks = useEnvironmentQuery(
1010+
props.scheduledTaskId
1011+
? serverEnvironment.scheduledTasksLive({ environmentId: props.environmentId, input: {} })
1012+
: null,
1013+
);
1014+
const taskTitle = tasks.data?.tasks.find((task) => task.id === props.scheduledTaskId)?.title;
1015+
const summary = taskTitle ?? props.text.trim().split(/\r?\n/, 1)[0] ?? "";
1016+
1017+
return (
1018+
<View className="mb-5 items-end">
1019+
<View
1020+
className="min-w-0 rounded-[20px]"
1021+
style={{
1022+
backgroundColor: props.bubbleColor,
1023+
maxWidth: props.bubbleMaxWidth,
1024+
...(props.expanded ? { width: props.bubbleMaxWidth } : null),
1025+
}}
1026+
>
1027+
<Pressable
1028+
accessibilityRole="button"
1029+
accessibilityLabel={`Automation: ${summary}`}
1030+
accessibilityHint={`Double tap to ${props.expanded ? "hide" : "show"} the prompt.`}
1031+
accessibilityState={{ expanded: props.expanded }}
1032+
hitSlop={4}
1033+
className="min-h-10 flex-row items-center gap-1.5 px-3.5 py-2"
1034+
onPress={() => {
1035+
void Haptics.selectionAsync();
1036+
props.onToggle();
1037+
}}
1038+
>
1039+
<SymbolView
1040+
name="calendar.badge.clock"
1041+
size={14}
1042+
weight="medium"
1043+
tintColorClassName="accent-user-bubble-foreground-muted"
1044+
type="monochrome"
1045+
/>
1046+
<Text className="font-t3-medium text-sm text-user-bubble-foreground-muted">
1047+
Automation
1048+
</Text>
1049+
<Text numberOfLines={1} className="min-w-0 shrink text-sm text-user-bubble-foreground">
1050+
{summary}
1051+
</Text>
1052+
<ThreadDisclosureChevron
1053+
expanded={props.expanded}
1054+
collapsedDirection="down"
1055+
size={11}
1056+
tintColor={props.iconSubtleColor}
1057+
/>
1058+
</Pressable>
1059+
{props.expanded ? (
1060+
<View className="px-3.5 pb-2.5">
1061+
<MarkdownImageAvailableWidthContext value={props.contentMaxWidth}>
1062+
<UserMessageContent
1063+
text={renderAssistantCitationsAsText(props.text)}
1064+
environmentId={props.environmentId}
1065+
context={props.context}
1066+
markdownStyles={props.markdownStyles}
1067+
reviewCommentColors={props.reviewCommentColors}
1068+
skills={props.skills}
1069+
linkHandlers={props.linkHandlers}
1070+
renderImage={props.renderImage}
1071+
/>
1072+
</MarkdownImageAvailableWidthContext>
1073+
</View>
1074+
) : null}
1075+
</View>
1076+
{props.expanded ? (
1077+
<View className="mt-1 flex-row items-center justify-end gap-2 pr-0.5">
1078+
{props.scheduledTaskId ? (
1079+
<Pressable
1080+
accessibilityRole="link"
1081+
hitSlop={6}
1082+
onPress={() =>
1083+
navigation.navigate("SettingsSheet", {
1084+
screen: "SettingsContent",
1085+
params: { screen: "SettingsScheduledTasks" },
1086+
})
1087+
}
1088+
>
1089+
<Text className="font-t3-medium text-xs text-foreground-secondary">
1090+
Open automation
1091+
</Text>
1092+
</Pressable>
1093+
) : null}
1094+
<Text className="font-t3-medium text-xs tabular-nums text-foreground-secondary">
1095+
{props.timestampLabel}
1096+
</Text>
1097+
<UserMessageCopyButton
1098+
text={props.text}
1099+
onCopy={undefined}
1100+
tintColor={props.iconSubtleColor}
1101+
/>
1102+
</View>
1103+
) : null}
1104+
</View>
1105+
);
1106+
}
1107+
9861108
function renderFeedEntry(
9871109
info: { item: PendingThreadFeedEntry; index: number },
9881110
props: Pick<
@@ -1200,6 +1322,29 @@ function renderFeedEntry(
12001322
/>
12011323
);
12021324
}
1325+
if (isUser && presentation.attribution === "automation") {
1326+
const rowId = `automation:${message.id}`;
1327+
return (
1328+
<ThreadAutomationMessageRow
1329+
environmentId={props.environmentId}
1330+
text={presentation.text}
1331+
context={message.context}
1332+
scheduledTaskId={presentation.scheduledTaskId}
1333+
timestampLabel={timestampLabel}
1334+
expanded={props.expandedWorkRows[rowId] ?? false}
1335+
onToggle={() => props.onToggleWorkRow(rowId, entry.id)}
1336+
bubbleColor={userBubbleColor}
1337+
bubbleMaxWidth={props.duoColumns ? "85%" : props.userBubbleMaxWidth}
1338+
contentMaxWidth={props.userBubbleMaxWidth - USER_BUBBLE_HORIZONTAL_PADDING * 2}
1339+
iconSubtleColor={iconSubtleColor}
1340+
markdownStyles={markdownStyles.user}
1341+
reviewCommentColors={props.reviewCommentColors}
1342+
skills={props.skills}
1343+
linkHandlers={props.markdownLinkHandlers}
1344+
renderImage={props.renderMarkdownImage}
1345+
/>
1346+
);
1347+
}
12031348
if (isUser) {
12041349
const enterAnimated = isFreshTimestamp(message.createdAt);
12051350
const intentBadge = resolveUserMessageIntentBadge(message.inputIntent);
@@ -1221,11 +1366,7 @@ function renderFeedEntry(
12211366
className="mb-5 items-end"
12221367
{...(enterAnimated ? { entering: FadeInUp.duration(220) } : {})}
12231368
>
1224-
{presentation.attribution === "automation" ? (
1225-
<Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
1226-
Sent by automation
1227-
</Text>
1228-
) : presentation.attribution === "t3code" ? (
1369+
{presentation.attribution === "t3code" ? (
12291370
<Text className="mb-1 pr-1 font-t3-medium text-2xs text-foreground-muted opacity-60">
12301371
Sent by T3 Code
12311372
</Text>
@@ -2739,7 +2880,11 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
27392880
viewabilityConfig={THREAD_MEDIA_VIEWABILITY_CONFIG}
27402881
keyExtractor={(entry) => entry.id}
27412882
getItemType={(entry) =>
2742-
entry.type === "message" ? `message:${entry.message.role}` : entry.type
2883+
entry.type !== "message"
2884+
? entry.type
2885+
: resolveUserMessagePresentation(entry.message).attribution === "automation"
2886+
? "message:automation"
2887+
: `message:${entry.message.role}`
27432888
}
27442889
getFixedItemSize={getFixedItemSize}
27452890
// Virtualized rows must move with their measurements. Native layout

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

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentId, MessageId } from "@t3tools/contracts";
1+
import { EnvironmentId, MessageId, RunId, ScheduledTaskId } from "@t3tools/contracts";
22
import type { LegendListRef } from "@legendapp/list/react";
33
import { createRef, type ComponentProps, type ReactElement } from "react";
44
import { describe, expect, it, vi } from "vite-plus/test";
@@ -9,14 +9,18 @@ import { act, render } from "../../../test/render";
99
import { MessagesTimeline } from "./MessagesTimeline";
1010
import { remarkThoughtPreview } from "./TimelineWorkEntryRow.logic";
1111
import { parseMarkdownWithMath } from "@t3tools/shared/markdownMath";
12+
import { collectThreadFindRanges } from "./threadFindHighlights";
1213

13-
const pullRequestQuery = vi.hoisted(() => ({ error: "Pull request not found" }));
14+
const environmentQuery = vi.hoisted(() => ({
15+
error: "Pull request not found",
16+
data: null as unknown,
17+
}));
1418
vi.mock(import("~/state/query"), async (original) => ({
1519
...(await original()),
1620
useEnvironmentQuery: (() => ({
17-
data: null,
21+
data: environmentQuery.data,
1822
dataUpdatedAt: 0,
19-
error: pullRequestQuery.error,
23+
error: environmentQuery.error,
2024
failure: null,
2125
isPending: false,
2226
isSuccess: false,
@@ -117,6 +121,13 @@ async function click(element: HTMLElement) {
117121
await act(async () => element.click());
118122
}
119123

124+
function setup({ scheduledTasks = [] as ReadonlyArray<{ id: string; title: string }> } = {}) {
125+
environmentQuery.data = { tasks: scheduledTasks };
126+
}
127+
128+
const TASK_ID = ScheduledTaskId.make("task-1");
129+
const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates.";
130+
120131
describe("MessagesTimeline messages", () => {
121132
it("preserves XML-like tags and comparisons in user messages as text", async () => {
122133
const source = [
@@ -164,6 +175,96 @@ describe("MessagesTimeline messages", () => {
164175
});
165176
});
166177

178+
describe("MessagesTimeline automation prompts", () => {
179+
it("folds an automation prompt into a bubble titled by its task", async () => {
180+
setup({ scheduledTasks: [{ id: TASK_ID, title: "Nightly triage" }] });
181+
await using screen = await renderTimeline([
182+
message(AUTOMATION_PROMPT, { scheduledTaskId: TASK_ID }),
183+
]);
184+
const row = screen.button(/^Automation/);
185+
expect(row.textContent).toContain("Nightly triage");
186+
expect(row.getAttribute("aria-expanded")).toBe("false");
187+
expect(screen.text()).not.toContain("close duplicates");
188+
189+
await click(row);
190+
expect(screen.text()).toContain("Label every new issue and close duplicates.");
191+
const link = [...screen.container.querySelectorAll("a")].find(
192+
(anchor) => anchor.textContent === "Open automation",
193+
);
194+
expect(link?.getAttribute("href")).toContain(`taskId=${TASK_ID}`);
195+
expect(screen.buttons(/copy/i)).not.toHaveLength(0);
196+
});
197+
198+
it("falls back to the prompt's first line without a task title", async () => {
199+
setup();
200+
await using screen = await renderTimeline([
201+
message(AUTOMATION_PROMPT, { scheduledTaskId: TASK_ID }),
202+
]);
203+
expect(screen.button(/^Automation/).textContent).toContain("Triage the inbox");
204+
});
205+
206+
it("leaves ordinary user messages as full bubbles", async () => {
207+
setup();
208+
await using screen = await renderTimeline([message(AUTOMATION_PROMPT)]);
209+
expect(screen.buttons(/^Automation/)).toHaveLength(0);
210+
expect(screen.text()).toContain("Label every new issue and close duplicates.");
211+
});
212+
213+
it("reveals a find match beyond the folded automation prompt's initial viewport", async () => {
214+
setup();
215+
const prompt = `${"Inspect the next item.\n\n".repeat(16)}Close duplicates.`;
216+
await using screen = await renderTimeline([message(prompt, { scheduledTaskId: TASK_ID })], {
217+
findExpanded: true,
218+
findQuery: "duplicates",
219+
activeFindMatch: { entryId: "entry-message-1", runId: null, occurrence: 0 },
220+
});
221+
await vi.waitFor(() =>
222+
expect(screen.button(/^Automation/).getAttribute("aria-expanded")).toBe("true"),
223+
);
224+
const { range } = collectThreadFindRanges(screen.container, "duplicates")[0]!;
225+
const details = screen.container.querySelector("[data-thread-find-text]")!;
226+
expect(range.getBoundingClientRect().top - details.getBoundingClientRect().top).toBeGreaterThan(
227+
384,
228+
);
229+
expect(range.getBoundingClientRect().bottom).toBeLessThanOrEqual(
230+
details.getBoundingClientRect().bottom,
231+
);
232+
});
233+
234+
it("shows edit-from-here once an automation prompt is expanded", async () => {
235+
setup();
236+
const runId = RunId.make("run-1");
237+
await using screen = await renderTimeline(
238+
[
239+
message(
240+
AUTOMATION_PROMPT,
241+
{ scheduledTaskId: TASK_ID, runId, inputIntent: "turn_start" },
242+
"user-1",
243+
),
244+
message("Done", { role: "assistant", runId }, "assistant-1"),
245+
],
246+
{
247+
supportsConversationRollback: true,
248+
threadStartCheckpointReady: true,
249+
turnDiffSummaries: [
250+
{
251+
runId,
252+
checkpointTurnCount: 1,
253+
checkpointRef: "checkpoint-1" as never,
254+
status: "ready",
255+
files: [],
256+
assistantMessageId: MessageId.make("assistant-1"),
257+
completedAt: CREATED_AT,
258+
},
259+
],
260+
},
261+
);
262+
expect(screen.buttons("Edit from here")).toHaveLength(0);
263+
await click(screen.button(/^Automation/));
264+
expect(screen.buttons("Edit from here")).toHaveLength(1);
265+
});
266+
});
267+
167268
describe("compact reasoning math", () => {
168269
it("keeps formulas while flattening compact reasoning previews", () => {
169270
const tree = parseMarkdownWithMath("## Reasoning\n\nUse **norm** $|x|$ and \\[x^2\\]");

0 commit comments

Comments
 (0)