feat(web): group live tool activity
This commit is contained in:
1 parent
c7f2ce72a6
commit
a63bf965f8
11 files changed
+1862
-334
No files matched your search
@@ -23,14 +23,10 @@ describe("ChangedFilesCard", () => {
|
||||
expect(markup).toContain('data-changed-files-state="expanded"');
|
||||
expect(markup).toContain('aria-expanded="true"');
|
||||
expect(markup).toContain("whitespace-nowrap");
|
||||
expect(markup).toContain('class="group flex min-w-0 flex-1 items-center rounded-xl');
|
||||
expect(markup).not.toMatch(/class="group flex min-w-0 flex-1 items-center[^"]*overflow-hidden/);
|
||||
expect(markup).toContain('class="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden"');
|
||||
expect(markup).toContain('class="flex min-w-0 items-center gap-1.5 rounded-md px-1 py-1');
|
||||
expect(markup).toContain('class="flex shrink-0 items-center gap-1 whitespace-nowrap');
|
||||
expect(markup).toContain('class="ml-1 hidden min-w-0 flex-1 truncate');
|
||||
expect(markup).toContain("@[24rem]/changed-files:inline");
|
||||
expect(markup).not.toContain("sm:inline");
|
||||
expect(markup).toContain('class="flex shrink-0 items-center gap-1.5 pr-1"');
|
||||
expect(markup).toContain('class="hidden @[24rem]/changed-files:inline">Open diff</span>');
|
||||
expect(markup).toContain('class="flex shrink-0 items-center gap-1.5"');
|
||||
expect(markup).toContain("!size-[22px]");
|
||||
expect(markup).toContain("size-3");
|
||||
expect(markup).toContain('aria-label="Collapse all folders"');
|
||||
@@ -38,9 +34,11 @@ describe("ChangedFilesCard", () => {
|
||||
expect(markup).toContain('role="group" aria-label="2 additions, 1 deletions"');
|
||||
expect(markup).toContain("1 changed file");
|
||||
expect(markup).not.toContain("1 changed files");
|
||||
expect(markup).not.toContain("Hide files");
|
||||
expect(markup).not.toContain("ml-auto");
|
||||
});
|
||||
|
||||
it("renders a scope and representative-file preview for a large latest change", () => {
|
||||
it("renders a clean representative-file preview for a large latest change", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<ChangedFilesCard
|
||||
turnId={TurnId.make("turn-1")}
|
||||
@@ -67,14 +65,16 @@ describe("ChangedFilesCard", () => {
|
||||
|
||||
expect(markup).toContain('data-changed-files-state="preview"');
|
||||
expect(markup).toContain('aria-expanded="false"');
|
||||
expect(markup).toContain("apps");
|
||||
expect(markup).toContain("2 files");
|
||||
expect(markup).toContain("packages");
|
||||
expect(markup).toContain("root");
|
||||
expect(markup).toContain("apps/web/src/");
|
||||
expect(markup).toContain("packages/shared/src/");
|
||||
expect(markup).toContain("App.tsx");
|
||||
expect(markup).toContain("git.ts");
|
||||
expect(markup).toContain("README.md");
|
||||
expect(markup).toContain("Show all 4 files");
|
||||
expect(markup).not.toContain("basis-0");
|
||||
expect(markup).not.toContain("+1 more");
|
||||
expect(markup).not.toContain("Show files");
|
||||
expect(markup).toContain('aria-label="120 additions, 20 deletions"');
|
||||
expect(markup).toContain("focus-visible:ring-inset");
|
||||
expect(markup).not.toContain("App.test.tsx");
|
||||
});
|
||||
|
||||
|
||||
@@ -19,11 +19,7 @@ import { DiffStatLabel, hasNonZeroStat } from "./DiffStatLabel";
|
||||
import { PierreEntryIcon } from "./PierreEntryIcon";
|
||||
import { Button } from "../ui/button";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import {
|
||||
changedFileName,
|
||||
selectChangedFilePreview,
|
||||
summarizeChangedFileScopes,
|
||||
} from "./changedFilesPresentation";
|
||||
import { changedFileName, selectChangedFilePreview } from "./changedFilesPresentation";
|
||||
|
||||
const EMPTY_DIRECTORY_OVERRIDES: Record<string, boolean> = {};
|
||||
|
||||
@@ -50,13 +46,12 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
onOpenTurnDiff,
|
||||
} = props;
|
||||
const summaryStat = useMemo(() => summarizeTurnDiffStats(files), [files]);
|
||||
const scopeSummary = useMemo(() => summarizeChangedFileScopes(files), [files]);
|
||||
const previewFiles = useMemo(() => selectChangedFilePreview(files), [files]);
|
||||
const compactPreviewVisible = showCompactPreview && !expanded;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="@container/changed-files mt-4 rounded-2xl border border-border/70 bg-secondary p-2 dark:border-transparent dark:bg-input/32"
|
||||
className="@container/changed-files mt-4 rounded-xl border border-border/70 bg-secondary p-1.5 dark:border-transparent dark:bg-input/32"
|
||||
data-changed-files-state={
|
||||
expanded ? "expanded" : compactPreviewVisible ? "preview" : "collapsed"
|
||||
}
|
||||
@@ -64,7 +59,7 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
<div
|
||||
data-changed-files-header=""
|
||||
className={cn(
|
||||
"flex items-center justify-between gap-2 rounded-xl",
|
||||
"flex items-center justify-between gap-2 rounded-lg px-1",
|
||||
expanded &&
|
||||
"sticky top-2 z-10 mb-2 bg-secondary dark:bg-[color-mix(in_srgb,var(--foreground)_2.5%,var(--background))]",
|
||||
)}
|
||||
@@ -73,36 +68,31 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
type="button"
|
||||
aria-expanded={expanded}
|
||||
data-scroll-anchor-ignore
|
||||
className="group flex min-w-0 flex-1 items-center rounded-xl px-2 py-1.5 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
className="flex min-w-0 items-center gap-1.5 rounded-md px-1 py-1 text-left transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onExpandedChange(!expanded)}
|
||||
>
|
||||
<span className="flex min-w-0 flex-1 items-center gap-1.5 overflow-hidden">
|
||||
<ChevronRightIcon
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-90",
|
||||
)}
|
||||
/>
|
||||
<span className="flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-foreground text-xs leading-4">
|
||||
<span>
|
||||
{files.length} changed file{files.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
{hasNonZeroStat(summaryStat) && (
|
||||
<DiffStatLabel
|
||||
additions={summaryStat.additions}
|
||||
className="text-xs leading-4"
|
||||
deletions={summaryStat.deletions}
|
||||
layout="inline"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className="ml-1 hidden min-w-0 flex-1 truncate text-[11px] text-muted-foreground group-hover:text-foreground/80 @[24rem]/changed-files:inline">
|
||||
{expanded ? "Hide files" : "Show files"}
|
||||
<ChevronRightIcon
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 text-muted-foreground transition-transform",
|
||||
expanded && "rotate-90",
|
||||
)}
|
||||
/>
|
||||
<span className="flex shrink-0 items-center gap-1 whitespace-nowrap font-medium text-foreground text-xs leading-4">
|
||||
<span>
|
||||
{files.length} changed file{files.length === 1 ? "" : "s"}
|
||||
</span>
|
||||
{hasNonZeroStat(summaryStat) && (
|
||||
<DiffStatLabel
|
||||
additions={summaryStat.additions}
|
||||
className="text-xs leading-4"
|
||||
deletions={summaryStat.deletions}
|
||||
layout="inline"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
</button>
|
||||
<div className="flex shrink-0 items-center gap-1.5 pr-1">
|
||||
<div className="flex shrink-0 items-center gap-1.5">
|
||||
{expanded ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
@@ -160,43 +150,35 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
|
||||
onOpenTurnDiff={onOpenTurnDiff}
|
||||
/>
|
||||
) : compactPreviewVisible ? (
|
||||
<div className="px-2 pb-1.5 pt-1">
|
||||
<p className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-[11px] text-muted-foreground">
|
||||
{scopeSummary.map((scope, index) => (
|
||||
<span key={scope.label} className="inline-flex items-center gap-1">
|
||||
{index > 0 ? <span aria-hidden="true">·</span> : null}
|
||||
<span className="font-mono text-foreground/75">{scope.label}</span>
|
||||
<span>
|
||||
{scope.fileCount} file{scope.fileCount === 1 ? "" : "s"}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-1.5">
|
||||
<div className="px-1.5 pb-1 pt-0.5">
|
||||
<div className="flex min-w-0 items-center gap-x-3 overflow-hidden">
|
||||
{previewFiles.map((file) => (
|
||||
<button
|
||||
key={file.path}
|
||||
type="button"
|
||||
title={file.path}
|
||||
className="inline-flex max-w-48 items-center gap-1 rounded-md border border-border/70 bg-background/45 px-1.5 py-1 font-mono text-[10px] text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
className="group flex min-h-6 min-w-0 max-w-72 shrink items-center gap-1.5 rounded-md px-1 text-left transition-colors hover:bg-accent/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
|
||||
onClick={() => onOpenTurnDiff(turnId, file.path)}
|
||||
>
|
||||
<PierreEntryIcon
|
||||
pathValue={file.path}
|
||||
kind="file"
|
||||
theme={resolvedTheme}
|
||||
className="size-3 shrink-0 text-muted-foreground/70"
|
||||
className="size-3.5 shrink-0 text-muted-foreground/70"
|
||||
/>
|
||||
<span className="truncate">{changedFileName(file.path)}</span>
|
||||
<span className="min-w-0 truncate font-mono text-xs text-foreground/75 group-hover:text-foreground">
|
||||
{changedFileName(file.path)}
|
||||
</span>
|
||||
{hasNonZeroStat(file) ? (
|
||||
<DiffStatLabel
|
||||
additions={file.additions}
|
||||
deletions={file.deletions}
|
||||
layout="inline"
|
||||
className="shrink-0 text-[10px]"
|
||||
/>
|
||||
) : null}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-md px-1.5 py-1 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
onClick={() => onExpandedChange(true)}
|
||||
>
|
||||
Show all {files.length} files
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -272,11 +254,11 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
) : (
|
||||
<FolderClosedIcon className="size-3.5 shrink-0 text-muted-foreground/75" />
|
||||
)}
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground/90 group-hover:text-foreground/90">
|
||||
<span className="min-w-0 truncate font-mono text-[11px] text-muted-foreground/90 group-hover:text-foreground/90">
|
||||
{node.name}
|
||||
</span>
|
||||
{hasNonZeroStat(node.stat) && (
|
||||
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<span className="ml-1 shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
|
||||
</span>
|
||||
)}
|
||||
@@ -307,11 +289,11 @@ export const ChangedFilesTree = memo(function ChangedFilesTree(props: {
|
||||
theme={resolvedTheme}
|
||||
className="size-3.5 text-muted-foreground/70"
|
||||
/>
|
||||
<span className="truncate font-mono text-[11px] text-muted-foreground/80 group-hover:text-foreground/90">
|
||||
<span className="min-w-0 truncate font-mono text-[11px] text-muted-foreground/80 group-hover:text-foreground/90">
|
||||
{node.name}
|
||||
</span>
|
||||
{node.stat && (
|
||||
<span className="ml-auto shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<span className="ml-1 shrink-0 font-mono text-[10px] tabular-nums">
|
||||
<DiffStatLabel additions={node.stat.additions} deletions={node.stat.deletions} />
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
deriveMessagesTimelineRows,
|
||||
normalizeCompactToolLabel,
|
||||
resolveAssistantMessageCopyState,
|
||||
summarizeToolGroup,
|
||||
shouldPreserveAssistantLineBreaks,
|
||||
} from "./MessagesTimeline.logic";
|
||||
|
||||
@@ -218,6 +219,50 @@ describe("normalizeCompactToolLabel", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("summarizeToolGroup", () => {
|
||||
it("distinguishes local grep from web search", () => {
|
||||
expect(
|
||||
summarizeToolGroup([
|
||||
{
|
||||
id: "grep",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
label: "grep",
|
||||
toolTitle: "grep",
|
||||
tone: "tool",
|
||||
itemType: "web_search",
|
||||
},
|
||||
]),
|
||||
).toBe("Searched code 1 time");
|
||||
expect(
|
||||
summarizeToolGroup([
|
||||
{
|
||||
id: "web-search",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
label: "Web search",
|
||||
toolTitle: "Web search",
|
||||
tone: "tool",
|
||||
itemType: "web_search",
|
||||
},
|
||||
]),
|
||||
).toBe("Searched the web 1 time");
|
||||
});
|
||||
|
||||
it("recognizes provider-neutral read tool calls", () => {
|
||||
expect(
|
||||
summarizeToolGroup([
|
||||
{
|
||||
id: "read-file",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
label: "Read File",
|
||||
toolTitle: "Read File",
|
||||
tone: "tool",
|
||||
itemType: "dynamic_tool_call",
|
||||
},
|
||||
]),
|
||||
).toBe("Read 1 file");
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAssistantMessageCopyState", () => {
|
||||
it("returns enabled copy state for completed assistant messages", () => {
|
||||
expect(
|
||||
@@ -545,7 +590,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
"user-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-thought-entry",
|
||||
"work-entry-1",
|
||||
"work-toggle:work-entry-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
expect(
|
||||
@@ -650,6 +695,99 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(foldRow?.label).toBe("Worked for 12s");
|
||||
});
|
||||
|
||||
it("keeps a collapsed superseded turn fold by the response and expands it downward", () => {
|
||||
const timelineEntries = [
|
||||
{
|
||||
id: "initial-user-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
message: {
|
||||
id: "initial-user" as never,
|
||||
role: "user",
|
||||
text: "Start the work",
|
||||
turnId: null,
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
updatedAt: "2026-01-01T00:00:00Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "superseded-work-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:10Z",
|
||||
entry: {
|
||||
id: "superseded-work",
|
||||
createdAt: "2026-01-01T00:00:10Z",
|
||||
turnId: "turn-1" as never,
|
||||
label: "Ran command",
|
||||
tone: "tool",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "steer-user-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:12Z",
|
||||
message: {
|
||||
id: "steer-user" as never,
|
||||
role: "user",
|
||||
text: "Change the approach",
|
||||
turnId: null,
|
||||
createdAt: "2026-01-01T00:00:12Z",
|
||||
updatedAt: "2026-01-01T00:00:12Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-final-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:20Z",
|
||||
message: {
|
||||
id: "assistant-final" as never,
|
||||
role: "assistant",
|
||||
text: "Implemented locally, uncommitted.",
|
||||
turnId: "turn-2" as never,
|
||||
createdAt: "2026-01-01T00:00:20Z",
|
||||
updatedAt: "2026-01-01T00:00:21Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
] satisfies Parameters<typeof deriveMessagesTimelineRows>[0]["timelineEntries"];
|
||||
const input = {
|
||||
timelineEntries,
|
||||
latestTurn: {
|
||||
turnId: "turn-2" as never,
|
||||
state: "completed" as const,
|
||||
startedAt: "2026-01-01T00:00:12Z",
|
||||
completedAt: "2026-01-01T00:00:21Z",
|
||||
},
|
||||
isWorking: false,
|
||||
activeTurnStartedAt: null,
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
};
|
||||
const rows = deriveMessagesTimelineRows(input);
|
||||
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"initial-user-entry",
|
||||
"steer-user-entry",
|
||||
"turn-fold:turn-1",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
|
||||
const expandedRows = deriveMessagesTimelineRows({
|
||||
...input,
|
||||
expandedTurnIds: new Set(["turn-1" as never]),
|
||||
});
|
||||
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"initial-user-entry",
|
||||
"turn-fold:turn-1",
|
||||
"work-toggle:superseded-work-entry",
|
||||
"steer-user-entry",
|
||||
"assistant-final-entry",
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses latest-turn timings and the stopped label for an interrupted latest turn", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
@@ -756,6 +894,72 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(finalRow?.kind === "message" && finalRow.showAssistantMeta).toBe(true);
|
||||
});
|
||||
|
||||
it("places an unkeyed active plan below the working header", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "user-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
message: {
|
||||
id: "user" as never,
|
||||
role: "user",
|
||||
text: "Make a plan",
|
||||
turnId: null,
|
||||
createdAt: "2026-01-01T00:00:00Z",
|
||||
updatedAt: "2026-01-01T00:00:00Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "plan-entry",
|
||||
kind: "proposed-plan",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
proposedPlan: {
|
||||
id: "plan" as never,
|
||||
turnId: null,
|
||||
planMarkdown: "# Plan",
|
||||
implementedAt: null,
|
||||
implementationThreadId: null,
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
updatedAt: "2026-01-01T00:00:01Z",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
message: {
|
||||
id: "assistant" as never,
|
||||
role: "assistant",
|
||||
text: "Planning now.",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
updatedAt: "2026-01-01T00:00:02Z",
|
||||
streaming: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"user-entry",
|
||||
"working-indicator-row",
|
||||
"plan-entry",
|
||||
"assistant-entry",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not fold the active in-progress turn", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
@@ -783,6 +987,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
turnId: "turn-1" as never,
|
||||
label: "Ran command",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "inProgress" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -800,12 +1005,299 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
|
||||
expect(rows.some((row) => row.kind === "turn-fold")).toBe(false);
|
||||
expect(rows.map((row) => row.id)).toEqual([
|
||||
"assistant-thought-entry",
|
||||
"work-entry-1",
|
||||
"working-indicator-row",
|
||||
"assistant-thought-entry",
|
||||
"work-live:work-entry-1",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps the current tool batch expandable while live entries append", () => {
|
||||
const timelineEntries = [
|
||||
{
|
||||
id: "work-entry-1",
|
||||
kind: "work" as const,
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work-1",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-1",
|
||||
label: "Read file",
|
||||
tone: "tool" as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "work-entry-2",
|
||||
kind: "work" as const,
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
entry: {
|
||||
id: "work-2",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-2",
|
||||
label: "Run command",
|
||||
command: "vp test run",
|
||||
tone: "tool" as const,
|
||||
},
|
||||
},
|
||||
];
|
||||
const baseInput = {
|
||||
timelineEntries,
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running" as const,
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
};
|
||||
|
||||
const collapsedRows = deriveMessagesTimelineRows(baseInput);
|
||||
const expandedRows = deriveMessagesTimelineRows({
|
||||
...baseInput,
|
||||
expandedWorkGroupIds: new Set(["work-group:tool:call-1"]),
|
||||
});
|
||||
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual([
|
||||
"working-indicator-row",
|
||||
"work-live:tool:call-1",
|
||||
]);
|
||||
expect(collapsedRows.find((row) => row.kind === "work-live")).toMatchObject({
|
||||
groupId: "work-group:tool:call-1",
|
||||
expanded: false,
|
||||
groupedEntries: [{ id: "work-1" }, { id: "work-2" }],
|
||||
});
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"working-indicator-row",
|
||||
"work-live:tool:call-1",
|
||||
"work-1",
|
||||
"work-2",
|
||||
]);
|
||||
expect(expandedRows.find((row) => row.kind === "work-live")).toMatchObject({
|
||||
groupId: "work-group:tool:call-1",
|
||||
expanded: true,
|
||||
});
|
||||
|
||||
const appendedRows = deriveMessagesTimelineRows({
|
||||
...baseInput,
|
||||
timelineEntries: [
|
||||
...timelineEntries,
|
||||
{
|
||||
id: "work-entry-3",
|
||||
kind: "work" as const,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
entry: {
|
||||
id: "work-3",
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-3",
|
||||
label: "Changed file",
|
||||
tone: "tool" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
expandedWorkGroupIds: new Set(["work-group:tool:call-1"]),
|
||||
});
|
||||
|
||||
expect(appendedRows.map((row) => row.id)).toEqual([
|
||||
"working-indicator-row",
|
||||
"work-live:tool:call-1",
|
||||
"work-1",
|
||||
"work-2",
|
||||
"work-3",
|
||||
]);
|
||||
|
||||
const rowsWithLaterPlan = deriveMessagesTimelineRows({
|
||||
...baseInput,
|
||||
timelineEntries: [
|
||||
...timelineEntries,
|
||||
{
|
||||
id: "plan:thread-1:turn:turn-1",
|
||||
kind: "proposed-plan" as const,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
proposedPlan: {
|
||||
id: "plan:thread-1:turn:turn-1",
|
||||
turnId: "turn-1" as never,
|
||||
planMarkdown: "# Next steps",
|
||||
implementedAt: null,
|
||||
implementationThreadId: null,
|
||||
createdAt: "2026-01-01T00:00:03Z",
|
||||
updatedAt: "2026-01-01T00:00:03Z",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(rowsWithLaterPlan.some((row) => row.kind === "work-live")).toBe(false);
|
||||
expect(rowsWithLaterPlan.some((row) => row.kind === "proposed-plan")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps a running call visible when a parallel call completes", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "work-running-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work-running",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-running",
|
||||
label: "Search files",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "inProgress" as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "work-completed-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
entry: {
|
||||
id: "work-completed",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-completed",
|
||||
label: "Read file",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "completed" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.find((row) => row.kind === "work-live")).toMatchObject({
|
||||
entry: { id: "work-running", toolLifecycleStatus: "inProgress" },
|
||||
groupedEntries: [{ id: "work-running" }, { id: "work-completed" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a completed trailing call to history while the turn keeps thinking", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "work-completed-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work-completed",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-completed",
|
||||
label: "Ran tests",
|
||||
command: "vp test run",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "completed" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.some((row) => row.kind === "work-live")).toBe(false);
|
||||
expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: true });
|
||||
expect(rows.some((row) => row.kind === "work-toggle")).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps thinking visible after an informational work entry", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "context-compacted-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "context-compacted",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
label: "Context compacted",
|
||||
tone: "info" as const,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: true });
|
||||
});
|
||||
|
||||
it("keeps the current tool batch live before an empty assistant placeholder", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
{
|
||||
id: "work-entry",
|
||||
kind: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
entry: {
|
||||
id: "work",
|
||||
createdAt: "2026-01-01T00:00:01Z",
|
||||
turnId: "turn-1" as never,
|
||||
toolCallId: "call-1",
|
||||
label: "Run command",
|
||||
tone: "tool" as const,
|
||||
toolLifecycleStatus: "inProgress" as const,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "assistant-placeholder-entry",
|
||||
kind: "message",
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
message: {
|
||||
id: "assistant-placeholder" as never,
|
||||
role: "assistant",
|
||||
text: " ",
|
||||
turnId: "turn-1" as never,
|
||||
createdAt: "2026-01-01T00:00:02Z",
|
||||
updatedAt: "2026-01-01T00:00:02Z",
|
||||
streaming: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
latestTurn: {
|
||||
turnId: "turn-1" as never,
|
||||
state: "running",
|
||||
startedAt: "2026-01-01T00:00:00Z",
|
||||
completedAt: null,
|
||||
},
|
||||
isWorking: true,
|
||||
activeTurnStartedAt: "2026-01-01T00:00:00Z",
|
||||
turnDiffSummaryByAssistantMessageId: new Map(),
|
||||
revertTurnCountByUserMessageId: new Map(),
|
||||
});
|
||||
|
||||
expect(rows.map((row) => row.id)).toContain("work-live:tool:call-1");
|
||||
});
|
||||
|
||||
it("does not fold the session's running turn when latestTurn regresses", () => {
|
||||
const rows = deriveMessagesTimelineRows({
|
||||
timelineEntries: [
|
||||
@@ -864,7 +1356,7 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expect(rows.filter((row) => row.kind === "turn-fold").map((row) => row.turnId)).toEqual([
|
||||
"turn-1",
|
||||
]);
|
||||
expect(rows.map((row) => row.id)).toContain("running-work-entry");
|
||||
expect(rows.map((row) => row.id)).toContain("work-live:running-work-entry");
|
||||
});
|
||||
|
||||
it("only shows assistant metadata on the terminal assistant message", () => {
|
||||
@@ -1006,18 +1498,18 @@ describe("deriveMessagesTimelineRows", () => {
|
||||
expandedWorkGroupIds: new Set(["work-group:work-entry-1"]),
|
||||
});
|
||||
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual(["work-3", "work-toggle:work-entry-1"]);
|
||||
expect(collapsedRows.map((row) => row.id)).toEqual(["work-toggle:work-entry-1"]);
|
||||
expect(collapsedRows.find((row) => row.kind === "work-toggle")).toMatchObject({
|
||||
groupId: "work-group:work-entry-1",
|
||||
hiddenCount: 2,
|
||||
hiddenCount: 3,
|
||||
expanded: false,
|
||||
onlyToolEntries: true,
|
||||
});
|
||||
expect(expandedRows.map((row) => row.id)).toEqual([
|
||||
"work-toggle:work-entry-1",
|
||||
"work-1",
|
||||
"work-2",
|
||||
"work-3",
|
||||
"work-toggle:work-entry-1",
|
||||
]);
|
||||
expect(expandedRows.find((row) => row.kind === "work-toggle")).toMatchObject({
|
||||
expanded: true,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as Equal from "effect/Equal";
|
||||
import {
|
||||
formatDuration,
|
||||
workEntryIndicatesToolFailure,
|
||||
workEntryIndicatesToolNeutralStatus,
|
||||
workLogEntryIsToolLike,
|
||||
type TimelineEntry,
|
||||
@@ -170,6 +171,17 @@ export type MessagesTimelineRow =
|
||||
id: string;
|
||||
createdAt: string;
|
||||
groupedEntries: WorkLogEntry[];
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
isLastExpandedToolGroupEntry: boolean;
|
||||
}
|
||||
| {
|
||||
kind: "work-live";
|
||||
id: string;
|
||||
createdAt: string;
|
||||
entry: WorkLogEntry;
|
||||
groupedEntries: WorkLogEntry[];
|
||||
groupId: string;
|
||||
expanded: boolean;
|
||||
}
|
||||
| {
|
||||
kind: "work-toggle";
|
||||
@@ -179,6 +191,9 @@ export type MessagesTimelineRow =
|
||||
hiddenCount: number;
|
||||
expanded: boolean;
|
||||
onlyToolEntries: boolean;
|
||||
summary: string | null;
|
||||
summaryKind: ToolGroupAction | "mixed" | null;
|
||||
hasFailure: boolean;
|
||||
}
|
||||
| {
|
||||
kind: "turn-fold";
|
||||
@@ -212,7 +227,12 @@ export type MessagesTimelineRow =
|
||||
createdAt: string;
|
||||
turnPlan: TurnPlanEntry;
|
||||
}
|
||||
| { kind: "working"; id: string; createdAt: string | null };
|
||||
| {
|
||||
kind: "working";
|
||||
id: string;
|
||||
createdAt: string | null;
|
||||
showThinking: boolean;
|
||||
};
|
||||
|
||||
export interface StableMessagesTimelineRowsState {
|
||||
byId: Map<string, MessagesTimelineRow>;
|
||||
@@ -242,6 +262,106 @@ export function normalizeCompactToolLabel(value: string): string {
|
||||
return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
|
||||
}
|
||||
|
||||
type ToolGroupAction = "read" | "edit" | "command" | "code-search" | "search" | "other";
|
||||
|
||||
export function workLogEntryIsLocalCodeSearch(entry: WorkLogEntry): boolean {
|
||||
return (
|
||||
entry.itemType === "web_search" &&
|
||||
/\bgrep\b/i.test(normalizeCompactToolLabel(entry.toolTitle ?? entry.label))
|
||||
);
|
||||
}
|
||||
|
||||
function toolGroupAction(entry: WorkLogEntry): ToolGroupAction {
|
||||
if (
|
||||
entry.requestKind === "file-read" ||
|
||||
entry.itemType === "image_view" ||
|
||||
(entry.itemType === "dynamic_tool_call" && entry.toolTitle === "Read File")
|
||||
) {
|
||||
return "read";
|
||||
}
|
||||
if (
|
||||
entry.requestKind === "file-change" ||
|
||||
entry.itemType === "file_change" ||
|
||||
(entry.changedFiles?.length ?? 0) > 0
|
||||
) {
|
||||
return "edit";
|
||||
}
|
||||
if (entry.requestKind === "command" || entry.itemType === "command_execution" || entry.command) {
|
||||
return "command";
|
||||
}
|
||||
if (workLogEntryIsLocalCodeSearch(entry)) return "code-search";
|
||||
if (entry.itemType === "web_search") return "search";
|
||||
return "other";
|
||||
}
|
||||
|
||||
function toolGroupActionCount(
|
||||
action: ToolGroupAction,
|
||||
entries: ReadonlyArray<WorkLogEntry>,
|
||||
): number {
|
||||
if (action !== "edit") return entries.length;
|
||||
|
||||
const changedFiles = new Set<string>();
|
||||
let editsWithoutFileDetails = 0;
|
||||
for (const entry of entries) {
|
||||
if (!entry.changedFiles || entry.changedFiles.length === 0) {
|
||||
editsWithoutFileDetails += 1;
|
||||
continue;
|
||||
}
|
||||
for (const file of entry.changedFiles) changedFiles.add(file);
|
||||
}
|
||||
return changedFiles.size + editsWithoutFileDetails;
|
||||
}
|
||||
|
||||
function toolGroupActionLabel(action: ToolGroupAction, count: number): string {
|
||||
switch (action) {
|
||||
case "read":
|
||||
return `Read ${count} ${count === 1 ? "file" : "files"}`;
|
||||
case "edit":
|
||||
return `Changed ${count} ${count === 1 ? "file" : "files"}`;
|
||||
case "command":
|
||||
return `Ran ${count} ${count === 1 ? "command" : "commands"}`;
|
||||
case "search":
|
||||
return `Searched the web ${count} ${count === 1 ? "time" : "times"}`;
|
||||
case "code-search":
|
||||
return `Searched code ${count} ${count === 1 ? "time" : "times"}`;
|
||||
case "other":
|
||||
return `Used ${count} ${count === 1 ? "tool" : "tools"}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** Immediate, provider-neutral fallback while generated tool summaries are disabled or unavailable. */
|
||||
export function summarizeToolGroup(entries: ReadonlyArray<WorkLogEntry>): string {
|
||||
const groupedEntries = new Map<ToolGroupAction, WorkLogEntry[]>();
|
||||
for (const entry of entries) {
|
||||
const action = toolGroupAction(entry);
|
||||
const group = groupedEntries.get(action);
|
||||
if (group) group.push(entry);
|
||||
else groupedEntries.set(action, [entry]);
|
||||
}
|
||||
const labels = [...groupedEntries].map(([action, actionEntries]) =>
|
||||
toolGroupActionLabel(action, toolGroupActionCount(action, actionEntries)),
|
||||
);
|
||||
const sentenceLabels = labels.map((label, index) =>
|
||||
index === 0 ? label : label.charAt(0).toLowerCase() + label.slice(1),
|
||||
);
|
||||
if (sentenceLabels.length < 2) return sentenceLabels[0] ?? "";
|
||||
if (sentenceLabels.length === 2) return sentenceLabels.join(" and ");
|
||||
return `${sentenceLabels.slice(0, -1).join(", ")}, and ${sentenceLabels.at(-1)}`;
|
||||
}
|
||||
|
||||
function toolGroupSummaryKind(entries: ReadonlyArray<WorkLogEntry>): ToolGroupAction | "mixed" {
|
||||
const actions = new Set(entries.map(toolGroupAction));
|
||||
return actions.size === 1 ? actions.values().next().value! : "mixed";
|
||||
}
|
||||
|
||||
function workGroupIdentity(timelineEntryId: string, entry: WorkLogEntry): string {
|
||||
return entry.toolCallId ? `tool:${entry.toolCallId}` : timelineEntryId;
|
||||
}
|
||||
|
||||
function workGroupId(timelineEntryId: string, entry: WorkLogEntry): string {
|
||||
return `work-group:${workGroupIdentity(timelineEntryId, entry)}`;
|
||||
}
|
||||
|
||||
export function resolveAssistantMessageCopyState({
|
||||
text,
|
||||
showCopyButton,
|
||||
@@ -314,17 +434,36 @@ function deriveUnsettledTurnId(
|
||||
return isSettled ? null : latestTurn.turnId;
|
||||
}
|
||||
|
||||
function lastUserMessageIndex(timelineEntries: ReadonlyArray<TimelineEntry>): number {
|
||||
return timelineEntries.findLastIndex(
|
||||
(entry) => entry.kind === "message" && entry.message.role === "user",
|
||||
);
|
||||
}
|
||||
|
||||
function timelineEntryTurnId(entry: TimelineEntry): TurnId | null {
|
||||
if (entry.kind === "message") {
|
||||
return entry.message.role === "assistant" ? (entry.message.turnId ?? null) : null;
|
||||
}
|
||||
if (entry.kind === "turn-plan") {
|
||||
return entry.turnPlan.turnId;
|
||||
}
|
||||
return entry.kind === "work" ? (entry.entry.turnId ?? null) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settled turns fold their commentary and tool activity behind a
|
||||
* "Worked for ..." row anchored at the turn's first foldable entry; the
|
||||
* terminal assistant message stays visible below the fold.
|
||||
* "Worked for ..." row. While collapsed, the row stays immediately before the
|
||||
* next terminal assistant response so a steer cannot strand it above the
|
||||
* visible response. While expanded, it moves before the first hidden entry so
|
||||
* the revealed activity follows the disclosure in chronological order.
|
||||
*/
|
||||
function deriveTurnFolds(input: {
|
||||
timelineEntries: ReadonlyArray<TimelineEntry>;
|
||||
terminalAssistantMessageIds: ReadonlySet<string>;
|
||||
latestTurn: TimelineLatestTurn | null;
|
||||
unsettledTurnId: TurnId | null;
|
||||
}): ReadonlyMap<string, TurnFold> {
|
||||
expandedTurnIds: ReadonlySet<TurnId> | undefined;
|
||||
}): ReadonlyMap<string, ReadonlyArray<TurnFold>> {
|
||||
interface TurnGroup {
|
||||
entries: Array<TimelineEntry>;
|
||||
terminalEntry: Extract<TimelineEntry, { kind: "message" }> | null;
|
||||
@@ -379,7 +518,7 @@ function deriveTurnFolds(input: {
|
||||
}
|
||||
}
|
||||
|
||||
const foldsByAnchorEntryId = new Map<string, TurnFold>();
|
||||
const foldsByAnchorEntryId = new Map<string, TurnFold[]>();
|
||||
for (const [turnId, group] of groupsByTurnId) {
|
||||
if (turnId === input.unsettledTurnId) {
|
||||
continue;
|
||||
@@ -405,8 +544,31 @@ function deriveTurnFolds(input: {
|
||||
}
|
||||
|
||||
const firstEntry = group.entries[0];
|
||||
const firstHiddenEntry = group.entries.find((entry) => hiddenEntryIds.has(entry.id));
|
||||
const lastEntry = group.entries.at(-1);
|
||||
if (!firstEntry || !lastEntry) {
|
||||
if (!firstEntry || !firstHiddenEntry || !lastEntry) {
|
||||
continue;
|
||||
}
|
||||
const lastHiddenEntryIndex = input.timelineEntries.findLastIndex((entry) =>
|
||||
hiddenEntryIds.has(entry.id),
|
||||
);
|
||||
if (lastHiddenEntryIndex < 0) {
|
||||
continue;
|
||||
}
|
||||
const nextTerminalAssistantEntry = input.timelineEntries
|
||||
.slice(lastHiddenEntryIndex + 1)
|
||||
.find(
|
||||
(entry) =>
|
||||
entry.kind === "message" &&
|
||||
entry.message.role === "assistant" &&
|
||||
input.terminalAssistantMessageIds.has(entry.message.id),
|
||||
);
|
||||
const collapsedAnchorEntry =
|
||||
nextTerminalAssistantEntry ?? input.timelineEntries[lastHiddenEntryIndex];
|
||||
const anchorEntry = input.expandedTurnIds?.has(turnId)
|
||||
? firstHiddenEntry
|
||||
: collapsedAnchorEntry;
|
||||
if (!anchorEntry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -435,13 +597,16 @@ function deriveTurnFolds(input: {
|
||||
? `Worked for ${duration}`
|
||||
: "Worked";
|
||||
|
||||
foldsByAnchorEntryId.set(firstEntry.id, {
|
||||
const fold = {
|
||||
turnId,
|
||||
anchorEntryId: firstEntry.id,
|
||||
createdAt: firstEntry.createdAt,
|
||||
anchorEntryId: anchorEntry.id,
|
||||
createdAt: anchorEntry.createdAt,
|
||||
hiddenEntryIds,
|
||||
label,
|
||||
});
|
||||
};
|
||||
const anchoredFolds = foldsByAnchorEntryId.get(anchorEntry.id);
|
||||
if (anchoredFolds) anchoredFolds.push(fold);
|
||||
else foldsByAnchorEntryId.set(anchorEntry.id, [fold]);
|
||||
}
|
||||
return foldsByAnchorEntryId;
|
||||
}
|
||||
@@ -471,38 +636,206 @@ export function deriveMessagesTimelineRows(input: {
|
||||
terminalAssistantMessageIds,
|
||||
latestTurn: input.latestTurn ?? null,
|
||||
unsettledTurnId,
|
||||
expandedTurnIds: input.expandedTurnIds,
|
||||
});
|
||||
const collapsedEntryIds = new Set<string>();
|
||||
for (const fold of foldsByAnchorEntryId.values()) {
|
||||
if (!input.expandedTurnIds?.has(fold.turnId)) {
|
||||
for (const entryId of fold.hiddenEntryIds) {
|
||||
collapsedEntryIds.add(entryId);
|
||||
for (const folds of foldsByAnchorEntryId.values()) {
|
||||
for (const fold of folds) {
|
||||
if (!input.expandedTurnIds?.has(fold.turnId)) {
|
||||
for (const entryId of fold.hiddenEntryIds) {
|
||||
collapsedEntryIds.add(entryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let activeTurnHeaderIndex = input.timelineEntries.length;
|
||||
if (input.isWorking) {
|
||||
const latestUserMessageIndex = lastUserMessageIndex(input.timelineEntries);
|
||||
const firstOwnedAfterUser =
|
||||
unsettledTurnId === null
|
||||
? -1
|
||||
: input.timelineEntries.findIndex(
|
||||
(entry, index) =>
|
||||
index > latestUserMessageIndex &&
|
||||
(entry.kind === "proposed-plan" ||
|
||||
entry.kind === "turn-plan" ||
|
||||
timelineEntryTurnId(entry) === unsettledTurnId),
|
||||
);
|
||||
activeTurnHeaderIndex =
|
||||
firstOwnedAfterUser >= 0 ? firstOwnedAfterUser : latestUserMessageIndex + 1;
|
||||
}
|
||||
const entryBelongsToActiveTurn = (entry: TimelineEntry, index: number) =>
|
||||
input.isWorking &&
|
||||
index >= activeTurnHeaderIndex &&
|
||||
(unsettledTurnId === null || timelineEntryTurnId(entry) === unsettledTurnId);
|
||||
const isVisibleActiveToolEntry = (entry: WorkLogEntry) =>
|
||||
workLogEntryIsToolLike(entry) &&
|
||||
(entry.toolLifecycleStatus === "inProgress" || !workEntryIndicatesToolNeutralStatus(entry));
|
||||
const workEntryCouldBeInProgress = (entry: WorkLogEntry) =>
|
||||
entry.toolLifecycleStatus === undefined || entry.toolLifecycleStatus === "inProgress";
|
||||
const activeEntries = input.isWorking
|
||||
? input.timelineEntries.filter((entry, index) => entryBelongsToActiveTurn(entry, index))
|
||||
: [];
|
||||
const activeTurnHasVisibleContent =
|
||||
activeEntries.some((entry) => {
|
||||
if (entry.kind === "message") {
|
||||
return entry.message.role === "assistant" && (entry.message.text?.trim().length ?? 0) > 0;
|
||||
}
|
||||
if (entry.kind === "work") {
|
||||
return (
|
||||
entry.entry.agentSpawn === undefined &&
|
||||
workLogEntryIsToolLike(entry.entry) &&
|
||||
workEntryCouldBeInProgress(entry.entry)
|
||||
);
|
||||
}
|
||||
if (entry.kind === "turn-plan") return true;
|
||||
return false;
|
||||
}) ||
|
||||
input.timelineEntries
|
||||
.slice(activeTurnHeaderIndex)
|
||||
.some((entry) => entry.kind === "proposed-plan" || entry.kind === "turn-plan");
|
||||
|
||||
const activeWorkEntryIds = new Set<string>();
|
||||
const activeWorkRowsByAnchorId = new Map<
|
||||
string,
|
||||
Extract<MessagesTimelineRow, { kind: "work-live" }>
|
||||
>();
|
||||
const hasLaterTurnContent = Array.from({ length: input.timelineEntries.length + 1 }, () => false);
|
||||
for (let index = input.timelineEntries.length - 1; index >= 0; index -= 1) {
|
||||
const entry = input.timelineEntries[index];
|
||||
if (!entry) continue;
|
||||
const isVisibleTurnContent =
|
||||
(entry.kind === "message" && entry.message.role === "user") ||
|
||||
entry.kind === "proposed-plan" ||
|
||||
(entryBelongsToActiveTurn(entry, index) &&
|
||||
((entry.kind === "message" &&
|
||||
entry.message.role === "assistant" &&
|
||||
(entry.message.text?.trim().length ?? 0) > 0) ||
|
||||
entry.kind === "turn-plan" ||
|
||||
(entry.kind === "work" &&
|
||||
entry.entry.agentSpawn === undefined &&
|
||||
isVisibleActiveToolEntry(entry.entry))));
|
||||
hasLaterTurnContent[index] = isVisibleTurnContent || hasLaterTurnContent[index + 1] === true;
|
||||
}
|
||||
|
||||
for (let index = 0; index < input.timelineEntries.length; index += 1) {
|
||||
const entry = input.timelineEntries[index];
|
||||
if (
|
||||
!entry ||
|
||||
entry.kind !== "work" ||
|
||||
entry.entry.agentSpawn !== undefined ||
|
||||
!entryBelongsToActiveTurn(entry, index)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
if (!isVisibleActiveToolEntry(entry.entry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const anchorEntry = entry;
|
||||
let latestToolEntry = entry;
|
||||
const batchEntryIds = [entry.id];
|
||||
const visibleBatchEntries = [entry.entry];
|
||||
let cursor = index + 1;
|
||||
while (cursor < input.timelineEntries.length) {
|
||||
const nextEntry = input.timelineEntries[cursor];
|
||||
if (
|
||||
!nextEntry ||
|
||||
nextEntry.kind !== "work" ||
|
||||
nextEntry.entry.agentSpawn !== undefined ||
|
||||
!entryBelongsToActiveTurn(nextEntry, cursor)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
batchEntryIds.push(nextEntry.id);
|
||||
if (isVisibleActiveToolEntry(nextEntry.entry)) {
|
||||
if (
|
||||
nextEntry.entry.toolLifecycleStatus === "inProgress" ||
|
||||
latestToolEntry.entry.toolLifecycleStatus !== "inProgress"
|
||||
) {
|
||||
latestToolEntry = nextEntry;
|
||||
}
|
||||
visibleBatchEntries.push(nextEntry.entry);
|
||||
}
|
||||
cursor += 1;
|
||||
}
|
||||
|
||||
// Once newer commentary, a plan, or another tool batch exists, this batch
|
||||
// is history. Let the regular work-group path turn it into an expandable
|
||||
// summary so none of its calls disappear behind the live one-line view.
|
||||
if (
|
||||
hasLaterTurnContent[cursor] !== true &&
|
||||
visibleBatchEntries.some(workEntryCouldBeInProgress)
|
||||
) {
|
||||
for (const entryId of batchEntryIds) activeWorkEntryIds.add(entryId);
|
||||
const groupId = workGroupId(anchorEntry.id, anchorEntry.entry);
|
||||
activeWorkRowsByAnchorId.set(anchorEntry.id, {
|
||||
kind: "work-live",
|
||||
id: `work-live:${workGroupIdentity(anchorEntry.id, anchorEntry.entry)}`,
|
||||
createdAt: anchorEntry.createdAt,
|
||||
entry: latestToolEntry.entry,
|
||||
groupedEntries: visibleBatchEntries,
|
||||
groupId,
|
||||
expanded: input.expandedWorkGroupIds?.has(groupId) ?? false,
|
||||
});
|
||||
}
|
||||
index = cursor - 1;
|
||||
}
|
||||
|
||||
for (let index = 0; index < input.timelineEntries.length; index += 1) {
|
||||
const timelineEntry = input.timelineEntries[index];
|
||||
if (!timelineEntry) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const turnFold = foldsByAnchorEntryId.get(timelineEntry.id);
|
||||
if (turnFold) {
|
||||
if (input.isWorking && index === activeTurnHeaderIndex) {
|
||||
nextRows.push({
|
||||
kind: "turn-fold",
|
||||
id: `turn-fold:${turnFold.turnId}`,
|
||||
createdAt: turnFold.createdAt,
|
||||
turnId: turnFold.turnId,
|
||||
label: turnFold.label,
|
||||
expanded: input.expandedTurnIds?.has(turnFold.turnId) ?? false,
|
||||
kind: "working",
|
||||
id: "working-indicator-row",
|
||||
createdAt: input.activeTurnStartedAt,
|
||||
showThinking: !activeTurnHasVisibleContent,
|
||||
});
|
||||
}
|
||||
|
||||
const anchoredTurnFolds = foldsByAnchorEntryId.get(timelineEntry.id);
|
||||
if (anchoredTurnFolds) {
|
||||
for (const turnFold of anchoredTurnFolds) {
|
||||
nextRows.push({
|
||||
kind: "turn-fold",
|
||||
id: `turn-fold:${turnFold.turnId}`,
|
||||
createdAt: turnFold.createdAt,
|
||||
turnId: turnFold.turnId,
|
||||
label: turnFold.label,
|
||||
expanded: input.expandedTurnIds?.has(turnFold.turnId) ?? false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (collapsedEntryIds.has(timelineEntry.id)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (activeWorkEntryIds.has(timelineEntry.id)) {
|
||||
const activeWorkRow = activeWorkRowsByAnchorId.get(timelineEntry.id);
|
||||
if (activeWorkRow) {
|
||||
nextRows.push(activeWorkRow);
|
||||
if (activeWorkRow.expanded) {
|
||||
for (const [entryIndex, workEntry] of activeWorkRow.groupedEntries.entries()) {
|
||||
nextRows.push({
|
||||
kind: "work",
|
||||
id: workEntry.id,
|
||||
createdAt: workEntry.createdAt,
|
||||
groupedEntries: [workEntry],
|
||||
isExpandedToolGroupEntry: true,
|
||||
isLastExpandedToolGroupEntry: entryIndex === activeWorkRow.groupedEntries.length - 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (timelineEntry.kind === "work") {
|
||||
const groupedEntries = [timelineEntry.entry];
|
||||
let cursor = index + 1;
|
||||
@@ -511,6 +844,7 @@ export function deriveMessagesTimelineRows(input: {
|
||||
if (
|
||||
!nextEntry ||
|
||||
nextEntry.kind !== "work" ||
|
||||
activeWorkEntryIds.has(nextEntry.id) ||
|
||||
collapsedEntryIds.has(nextEntry.id) ||
|
||||
foldsByAnchorEntryId.has(nextEntry.id)
|
||||
) {
|
||||
@@ -523,15 +857,48 @@ export function deriveMessagesTimelineRows(input: {
|
||||
(entry) => !workEntryIndicatesToolNeutralStatus(entry),
|
||||
);
|
||||
if (visibleGroupedEntries.length > 0) {
|
||||
if (visibleGroupedEntries.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
|
||||
const onlyToolEntries = visibleGroupedEntries.every(
|
||||
(entry) => workLogEntryIsToolLike(entry) && entry.agentSpawn === undefined,
|
||||
);
|
||||
if (onlyToolEntries) {
|
||||
const groupId = workGroupId(timelineEntry.id, timelineEntry.entry);
|
||||
const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
|
||||
const summaryKind = toolGroupSummaryKind(visibleGroupedEntries);
|
||||
nextRows.push({
|
||||
kind: "work-toggle",
|
||||
id: `work-toggle:${timelineEntry.id}`,
|
||||
createdAt: timelineEntry.createdAt,
|
||||
groupId,
|
||||
hiddenCount: visibleGroupedEntries.length,
|
||||
expanded,
|
||||
onlyToolEntries: true,
|
||||
summary: summarizeToolGroup(visibleGroupedEntries),
|
||||
summaryKind,
|
||||
hasFailure: visibleGroupedEntries.some((entry) => workEntryIndicatesToolFailure(entry)),
|
||||
});
|
||||
if (expanded) {
|
||||
for (const [entryIndex, workEntry] of visibleGroupedEntries.entries()) {
|
||||
nextRows.push({
|
||||
kind: "work",
|
||||
id: workEntry.id,
|
||||
createdAt: workEntry.createdAt,
|
||||
groupedEntries: [workEntry],
|
||||
isExpandedToolGroupEntry: true,
|
||||
isLastExpandedToolGroupEntry: entryIndex === visibleGroupedEntries.length - 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (visibleGroupedEntries.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
|
||||
nextRows.push({
|
||||
kind: "work",
|
||||
id: timelineEntry.id,
|
||||
createdAt: timelineEntry.createdAt,
|
||||
groupedEntries: visibleGroupedEntries,
|
||||
isExpandedToolGroupEntry: false,
|
||||
isLastExpandedToolGroupEntry: false,
|
||||
});
|
||||
} else {
|
||||
const groupId = `work-group:${timelineEntry.id}`;
|
||||
const groupId = workGroupId(timelineEntry.id, timelineEntry.entry);
|
||||
const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
|
||||
// Agent-spawn CTA rows are always visible: a running fleet must
|
||||
// never hide behind a "+N tool calls" toggle. Selection is by
|
||||
@@ -555,6 +922,8 @@ export function deriveMessagesTimelineRows(input: {
|
||||
id: workEntry.id,
|
||||
createdAt: workEntry.createdAt,
|
||||
groupedEntries: [workEntry],
|
||||
isExpandedToolGroupEntry: false,
|
||||
isLastExpandedToolGroupEntry: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -566,8 +935,11 @@ export function deriveMessagesTimelineRows(input: {
|
||||
groupId,
|
||||
hiddenCount: hiddenEntries.length,
|
||||
expanded,
|
||||
onlyToolEntries: visibleGroupedEntries.every((entry) =>
|
||||
workLogEntryIsToolLike(entry),
|
||||
onlyToolEntries,
|
||||
summary: null,
|
||||
summaryKind: null,
|
||||
hasFailure: visibleGroupedEntries.some((entry) =>
|
||||
workEntryIndicatesToolFailure(entry),
|
||||
),
|
||||
});
|
||||
}
|
||||
@@ -633,11 +1005,12 @@ export function deriveMessagesTimelineRows(input: {
|
||||
});
|
||||
}
|
||||
|
||||
if (input.isWorking) {
|
||||
if (input.isWorking && activeTurnHeaderIndex === input.timelineEntries.length) {
|
||||
nextRows.push({
|
||||
kind: "working",
|
||||
id: "working-indicator-row",
|
||||
createdAt: input.activeTurnStartedAt,
|
||||
showThinking: !activeTurnHasVisibleContent,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -670,7 +1043,9 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
|
||||
|
||||
switch (a.kind) {
|
||||
case "working":
|
||||
return a.createdAt === (b as typeof a).createdAt;
|
||||
return (
|
||||
a.createdAt === (b as typeof a).createdAt && a.showThinking === (b as typeof a).showThinking
|
||||
);
|
||||
|
||||
case "turn-fold": {
|
||||
const bf = b as typeof a;
|
||||
@@ -687,8 +1062,25 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
|
||||
return a.createdAt === bp.createdAt && a.turnPlan.plan === bp.turnPlan.plan;
|
||||
}
|
||||
|
||||
case "work":
|
||||
return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);
|
||||
case "work": {
|
||||
const bw = b as typeof a;
|
||||
return (
|
||||
a.isExpandedToolGroupEntry === bw.isExpandedToolGroupEntry &&
|
||||
a.isLastExpandedToolGroupEntry === bw.isLastExpandedToolGroupEntry &&
|
||||
Equal.equals(a.groupedEntries, bw.groupedEntries)
|
||||
);
|
||||
}
|
||||
|
||||
case "work-live": {
|
||||
const bw = b as typeof a;
|
||||
return (
|
||||
a.createdAt === bw.createdAt &&
|
||||
a.groupId === bw.groupId &&
|
||||
a.expanded === bw.expanded &&
|
||||
Equal.equals(a.entry, bw.entry) &&
|
||||
Equal.equals(a.groupedEntries, bw.groupedEntries)
|
||||
);
|
||||
}
|
||||
|
||||
case "work-toggle": {
|
||||
const bw = b as typeof a;
|
||||
@@ -697,7 +1089,10 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
|
||||
a.groupId === bw.groupId &&
|
||||
a.hiddenCount === bw.hiddenCount &&
|
||||
a.expanded === bw.expanded &&
|
||||
a.onlyToolEntries === bw.onlyToolEntries
|
||||
a.onlyToolEntries === bw.onlyToolEntries &&
|
||||
a.summary === bw.summary &&
|
||||
a.summaryKind === bw.summaryKind &&
|
||||
a.hasFailure === bw.hasFailure
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,6 +238,47 @@ function buildAssistantTimelineEntry(text: string) {
|
||||
}
|
||||
|
||||
describe("MessagesTimeline", () => {
|
||||
it("sizes the subagent card from its own container", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "agent-spawn-entry",
|
||||
kind: "work",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
entry: {
|
||||
id: "agent-spawn",
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
label: "Spawned agent",
|
||||
tone: "info",
|
||||
agentSpawn: { workflowId: null, agentTaskIds: ["agent-1"] },
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("@container/agent-group");
|
||||
expect(markup).toContain("@[24rem]/agent-group:inline");
|
||||
expect(markup).toContain("@[32rem]/agent-group:flex");
|
||||
expect(markup).toContain("sr-only @[32rem]/agent-group:hidden");
|
||||
});
|
||||
|
||||
it("keeps the active plan step in the live thinking row", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
isWorking
|
||||
workingStepLabel="Write focused tests"
|
||||
timelineEntries={[]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("Thinking · Write focused tests");
|
||||
expect(markup).toContain('aria-hidden="true" class="size-6 shrink-0"');
|
||||
});
|
||||
|
||||
it("sizes expanded tool details with the configured code font size", () => {
|
||||
expect(toolCallExpandedBodyClassName).toContain("var(--font-size-code");
|
||||
expect(toolCallExpandedBodyClassName).not.toContain("text-[11px]");
|
||||
@@ -706,7 +747,50 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain("Work Log");
|
||||
});
|
||||
|
||||
it("formats changed file paths from the workspace root", () => {
|
||||
it("makes the whole live tool row expandable without adding a chevron", () => {
|
||||
const turnId = TurnId.make("turn-live-tools");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
isWorking
|
||||
activeTurnInProgress
|
||||
activeTurnStartedAt="2026-03-17T19:12:28.000Z"
|
||||
latestTurn={{
|
||||
turnId,
|
||||
state: "running",
|
||||
startedAt: "2026-03-17T19:12:28.000Z",
|
||||
completedAt: null,
|
||||
}}
|
||||
runningTurnId={turnId}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "entry-live-tool",
|
||||
kind: "work",
|
||||
createdAt: "2026-03-17T19:12:29.000Z",
|
||||
entry: {
|
||||
id: "work-live-tool",
|
||||
createdAt: "2026-03-17T19:12:29.000Z",
|
||||
turnId,
|
||||
toolCallId: "call-live-tool",
|
||||
label: "Running tests",
|
||||
command: 'FOO="hello world" /usr/bin/env -C /tmp /usr/bin/sudo -iu postgres psql',
|
||||
tone: "tool",
|
||||
toolLifecycleStatus: "inProgress",
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).not.toContain('aria-label="Expand current tool calls"');
|
||||
expect(markup).toContain('aria-expanded="false"');
|
||||
expect(markup).toContain("Running psql");
|
||||
expect(markup).not.toContain("lucide-chevron-right");
|
||||
expect(markup).not.toContain("lucide-chevron-down");
|
||||
expect(markup).not.toContain("hover:bg-accent/20");
|
||||
});
|
||||
|
||||
it("summarizes completed changed-file activity", () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
@@ -728,7 +812,7 @@ describe("MessagesTimeline", () => {
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("t3code/apps/web/src/session-logic.ts");
|
||||
expect(markup).toContain("Changed 1 file");
|
||||
expect(markup).not.toContain("C:/Users/mike/dev-stuff/t3code/apps/web/src/session-logic.ts");
|
||||
});
|
||||
|
||||
@@ -832,6 +916,8 @@ describe("MessagesTimeline", () => {
|
||||
);
|
||||
|
||||
expect(markup).toContain("lucide-x");
|
||||
expect(markup).toContain('aria-label="Used 1 tool, tool call failed"');
|
||||
expect(markup).toContain('role="img"');
|
||||
expect(markup).toContain('aria-label="Tool call failed"');
|
||||
});
|
||||
});
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
deriveTimelineEntries,
|
||||
workEntryIndicatesToolFailure,
|
||||
workEntryIndicatesToolNeutralStatus,
|
||||
workEntryIndicatesToolSuccess,
|
||||
workLogEntryIsToolLike,
|
||||
} from "../../session-logic";
|
||||
import { type TurnDiffSummary } from "../../types";
|
||||
@@ -57,7 +56,7 @@ import {
|
||||
MessageCircleIcon,
|
||||
MousePointerClickIcon,
|
||||
PaintbrushIcon,
|
||||
MinusIcon,
|
||||
SearchIcon,
|
||||
SquarePenIcon,
|
||||
TerminalIcon,
|
||||
Undo2Icon,
|
||||
@@ -84,6 +83,7 @@ import {
|
||||
resolveTimelineMinimapInteractiveWidth,
|
||||
resolveTimelineMinimapTopPercent,
|
||||
shouldPreserveAssistantLineBreaks,
|
||||
workLogEntryIsLocalCodeSearch,
|
||||
type StableMessagesTimelineRowsState,
|
||||
type MessagesTimelineRow,
|
||||
TIMELINE_MINIMAP_MIN_ITEMS,
|
||||
@@ -921,17 +921,34 @@ type TimelineWorkEntry = Extract<MessagesTimelineRow, { kind: "work" }>["grouped
|
||||
type TimelineRow = MessagesTimelineRow;
|
||||
|
||||
const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: TimelineRow }) {
|
||||
const isExpandedToolGroupEntry = row.kind === "work" && row.isExpandedToolGroupEntry;
|
||||
const isLastExpandedToolGroupEntry = row.kind === "work" && row.isLastExpandedToolGroupEntry;
|
||||
const isExpandedToolGroupHeader =
|
||||
(row.kind === "work-toggle" && row.onlyToolEntries && row.expanded) ||
|
||||
(row.kind === "work-live" && row.expanded);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
// Commentary (non-terminal assistant) rows carry no metadata row, so
|
||||
// they sit closer to the work that follows them.
|
||||
(row.kind === "message" && row.message.role === "assistant" && !row.showAssistantMeta) ||
|
||||
row.kind === "work" ||
|
||||
row.kind === "work-toggle" ||
|
||||
row.kind === "turn-plan"
|
||||
? "pb-2"
|
||||
: "pb-4",
|
||||
isExpandedToolGroupEntry
|
||||
? isLastExpandedToolGroupEntry
|
||||
? "pb-1"
|
||||
: "pb-0"
|
||||
: isExpandedToolGroupHeader
|
||||
? "pb-0"
|
||||
: row.kind === "turn-fold"
|
||||
? "pb-1.5"
|
||||
: (row.kind === "message" &&
|
||||
row.message.role === "assistant" &&
|
||||
!row.showAssistantMeta) ||
|
||||
row.kind === "work" ||
|
||||
row.kind === "work-live" ||
|
||||
row.kind === "work-toggle" ||
|
||||
row.kind === "turn-plan"
|
||||
? "pb-2"
|
||||
: "pb-4",
|
||||
row.kind === "message" && row.message.role === "assistant" ? "group/assistant" : null,
|
||||
)}
|
||||
data-timeline-row-id={row.id}
|
||||
@@ -939,7 +956,13 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
|
||||
data-message-id={row.kind === "message" ? row.message.id : undefined}
|
||||
data-message-role={row.kind === "message" ? row.message.role : undefined}
|
||||
>
|
||||
{row.kind === "work" ? <WorkGroupSection groupedEntries={row.groupedEntries} /> : null}
|
||||
{row.kind === "work" ? (
|
||||
<WorkGroupSection
|
||||
groupedEntries={row.groupedEntries}
|
||||
isExpandedToolGroupEntry={row.isExpandedToolGroupEntry}
|
||||
/>
|
||||
) : null}
|
||||
{row.kind === "work-live" ? <LiveWorkEntryTimelineRow row={row} /> : null}
|
||||
{row.kind === "work-toggle" ? <WorkGroupToggleTimelineRow row={row} /> : null}
|
||||
{row.kind === "turn-fold" ? <TurnFoldTimelineRow row={row} /> : null}
|
||||
{row.kind === "message" && row.message.role === "user" ? <UserTimelineRow row={row} /> : null}
|
||||
@@ -1093,7 +1116,7 @@ function TurnFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "turn-
|
||||
aria-expanded={row.expanded}
|
||||
data-scroll-anchor-ignore
|
||||
onClick={() => ctx.onToggleTurnFold(row.turnId)}
|
||||
className="flex cursor-pointer select-none items-center gap-1 rounded-md px-1 text-xs text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
className="flex cursor-pointer select-none items-center gap-1 rounded-md px-1 text-sm leading-relaxed text-muted-foreground tabular-nums transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
>
|
||||
<span>{row.label}</span>
|
||||
<Icon className="size-3.5" />
|
||||
@@ -1280,16 +1303,10 @@ const TurnPlanTimelineRow = memo(function TurnPlanTimelineRow({
|
||||
});
|
||||
|
||||
function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
|
||||
const { workingStepLabel } = use(TimelineRowActivityCtx);
|
||||
return (
|
||||
<div className="py-0.5 pl-1.5">
|
||||
<div className="flex min-w-0 items-center gap-2 pt-1 text-secondary-label text-[11px] tabular-nums">
|
||||
<span className="inline-flex items-center gap-[3px]">
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse" />
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse [animation-delay:200ms]" />
|
||||
<span className="h-1 w-1 rounded-full bg-muted-foreground/30 animate-status-pulse [animation-delay:400ms]" />
|
||||
</span>
|
||||
<span className="shrink-0">
|
||||
<div>
|
||||
<div className="border-b border-border/60 pb-2 pt-1">
|
||||
<div className="px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
|
||||
{row.createdAt ? (
|
||||
<>
|
||||
Working for <WorkingTimer createdAt={row.createdAt} />
|
||||
@@ -1297,11 +1314,13 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
|
||||
) : (
|
||||
"Working..."
|
||||
)}
|
||||
</span>
|
||||
{workingStepLabel ? (
|
||||
<span className="min-w-0 truncate text-muted-foreground/55">· {workingStepLabel}</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
{row.showThinking ? (
|
||||
<div className="mt-2">
|
||||
<ThinkingActivityRow />
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1342,13 +1361,20 @@ function WorkingTimer({ createdAt }: { createdAt: string }) {
|
||||
/** Renders one or more already-derived work log rows. Overflow expansion is modeled as LegendList data. */
|
||||
const WorkGroupSection = memo(function WorkGroupSection({
|
||||
groupedEntries,
|
||||
isExpandedToolGroupEntry,
|
||||
}: {
|
||||
groupedEntries: Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"];
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
}) {
|
||||
const { workspaceRoot } = use(TimelineRowCtx);
|
||||
const nonEmptyEntries = useMemo(
|
||||
() => groupedEntries.filter((entry) => !workEntryIndicatesToolNeutralStatus(entry)),
|
||||
[groupedEntries],
|
||||
() =>
|
||||
groupedEntries.filter(
|
||||
(entry) =>
|
||||
(isExpandedToolGroupEntry && entry.toolLifecycleStatus === "inProgress") ||
|
||||
!workEntryIndicatesToolNeutralStatus(entry),
|
||||
),
|
||||
[groupedEntries, isExpandedToolGroupEntry],
|
||||
);
|
||||
const onlyToolEntries = nonEmptyEntries.every((entry) => workLogEntryIsToolLike(entry));
|
||||
const groupLabel = onlyToolEntries
|
||||
@@ -1360,7 +1386,10 @@ const WorkGroupSection = memo(function WorkGroupSection({
|
||||
if (nonEmptyEntries.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section className="-mx-1 space-y-0.5 px-1 py-0.5" aria-label={groupLabel}>
|
||||
<section
|
||||
className={cn("-mx-1 px-1", isExpandedToolGroupEntry ? "py-0" : "space-y-0.5 py-0.5")}
|
||||
aria-label={groupLabel}
|
||||
>
|
||||
{!onlyToolEntries && (
|
||||
<p className="px-0.5 pb-0.5 font-medium text-secondary-label text-[11px]">{groupLabel}</p>
|
||||
)}
|
||||
@@ -1370,6 +1399,7 @@ const WorkGroupSection = memo(function WorkGroupSection({
|
||||
key={workEntry.id}
|
||||
workEntry={workEntry}
|
||||
workspaceRoot={workspaceRoot}
|
||||
isExpandedToolGroupEntry={isExpandedToolGroupEntry}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -1377,12 +1407,140 @@ const WorkGroupSection = memo(function WorkGroupSection({
|
||||
);
|
||||
});
|
||||
|
||||
function LiveActivityRow({ label, iconName }: { label: string; iconName?: WorkEntryIconName }) {
|
||||
return (
|
||||
<div className="relative min-h-6 w-fit max-w-full min-w-0 overflow-hidden rounded-md text-sm leading-relaxed">
|
||||
<LiveActivityContent label={label} iconName={iconName} />
|
||||
<div
|
||||
aria-hidden
|
||||
className="live-activity-focus pointer-events-none absolute inset-y-0 select-none"
|
||||
>
|
||||
<div className="live-activity-focus-counter">
|
||||
<div className="live-activity-focus-aligned">
|
||||
<LiveActivityContent label={label} iconName={iconName} highlighted />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ThinkingActivityRow() {
|
||||
const { workingStepLabel } = use(TimelineRowActivityCtx);
|
||||
return (
|
||||
<LiveActivityRow label={workingStepLabel ? `Thinking · ${workingStepLabel}` : "Thinking"} />
|
||||
);
|
||||
}
|
||||
|
||||
function LiveActivityContent({
|
||||
label,
|
||||
iconName,
|
||||
highlighted = false,
|
||||
}: {
|
||||
label: string;
|
||||
iconName: WorkEntryIconName | undefined;
|
||||
highlighted?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex min-h-6 min-w-0 items-center gap-1.5 px-1 py-0.5",
|
||||
highlighted ? "text-foreground" : "text-secondary-label",
|
||||
)}
|
||||
>
|
||||
{iconName ? (
|
||||
<span
|
||||
className={cn(
|
||||
"flex size-6 shrink-0 items-center justify-center",
|
||||
highlighted ? "text-foreground" : "text-icon-muted",
|
||||
)}
|
||||
>
|
||||
<WorkEntryIconSvg name={iconName} className="block size-4 shrink-0 stroke-[1.8]" />
|
||||
</span>
|
||||
) : (
|
||||
<span aria-hidden className="size-6 shrink-0" />
|
||||
)}
|
||||
<span className="min-w-0 flex-1 truncate">{label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "work-live" }> }) {
|
||||
const ctx = use(TimelineRowCtx);
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="group/live-work flex min-h-6 w-full max-w-full cursor-pointer items-center rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
aria-expanded={row.expanded}
|
||||
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
|
||||
>
|
||||
<LiveActivityRow
|
||||
label={liveWorkEntryLabel(row.entry, ctx.workspaceRoot)}
|
||||
iconName={workEntryIconName(row.entry)}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function toolGroupSummaryIconName(
|
||||
kind: Extract<TimelineRow, { kind: "work-toggle" }>["summaryKind"],
|
||||
): WorkEntryIconName {
|
||||
switch (kind) {
|
||||
case "read":
|
||||
return "eye";
|
||||
case "edit":
|
||||
return "square-pen";
|
||||
case "command":
|
||||
return "terminal";
|
||||
case "search":
|
||||
return "globe";
|
||||
case "code-search":
|
||||
return "search";
|
||||
case "other":
|
||||
return "wrench";
|
||||
case "mixed":
|
||||
case null:
|
||||
return "hammer";
|
||||
}
|
||||
}
|
||||
|
||||
function WorkGroupToggleTimelineRow({
|
||||
row,
|
||||
}: {
|
||||
row: Extract<TimelineRow, { kind: "work-toggle" }>;
|
||||
}) {
|
||||
const ctx = use(TimelineRowCtx);
|
||||
if (row.onlyToolEntries && row.summary) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="group/tool-group flex min-h-6 w-full cursor-pointer items-center gap-1.5 rounded-md px-0.5 py-0.5 text-left text-sm leading-relaxed transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
aria-label={row.hasFailure ? `${row.summary}, tool call failed` : undefined}
|
||||
aria-expanded={row.expanded}
|
||||
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"flex size-6 shrink-0 items-center justify-center",
|
||||
row.hasFailure ? "text-destructive" : "text-icon-muted",
|
||||
)}
|
||||
role={row.hasFailure ? "img" : undefined}
|
||||
aria-label={row.hasFailure ? "Tool call failed" : undefined}
|
||||
>
|
||||
{row.hasFailure ? (
|
||||
<XIcon className="size-4 shrink-0 stroke-[1.8]" aria-hidden />
|
||||
) : (
|
||||
<WorkEntryIconSvg
|
||||
name={toolGroupSummaryIconName(row.summaryKind)}
|
||||
className="size-4 shrink-0 stroke-[1.8] opacity-70"
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-label">{row.summary}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
const labelNoun = row.onlyToolEntries
|
||||
? row.hiddenCount === 1
|
||||
? "tool call"
|
||||
@@ -1394,14 +1552,14 @@ function WorkGroupToggleTimelineRow({
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="flex w-full cursor-pointer items-center gap-1.5 rounded-md px-0.5 py-0.5 text-left text-[12px] leading-5 transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
className="flex min-h-6 w-full cursor-pointer items-center gap-1.5 rounded-md px-0.5 py-0.5 text-left text-sm leading-relaxed transition-colors duration-150 hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
|
||||
aria-expanded={row.expanded}
|
||||
onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
|
||||
>
|
||||
<span className="flex size-5 shrink-0 items-center justify-center text-icon-muted">
|
||||
<span className="flex size-6 shrink-0 items-center justify-center text-icon-muted">
|
||||
<ChevronDownIcon
|
||||
className={cn(
|
||||
"size-3.5 shrink-0 opacity-70 transition-transform duration-200",
|
||||
"size-4 shrink-0 opacity-70 transition-transform duration-200",
|
||||
row.expanded && "rotate-180",
|
||||
)}
|
||||
/>
|
||||
@@ -1947,6 +2105,7 @@ type WorkEntryIconName =
|
||||
| "globe"
|
||||
| "hammer"
|
||||
| "message-circle"
|
||||
| "search"
|
||||
| "square-pen"
|
||||
| "terminal"
|
||||
| "wrench"
|
||||
@@ -1969,6 +2128,8 @@ function WorkEntryIconSvg({ name, className }: { name: WorkEntryIconName; classN
|
||||
return <HammerIcon className={className} aria-hidden />;
|
||||
case "message-circle":
|
||||
return <MessageCircleIcon className={className} aria-hidden />;
|
||||
case "search":
|
||||
return <SearchIcon className={className} aria-hidden />;
|
||||
case "square-pen":
|
||||
return <SquarePenIcon className={className} aria-hidden />;
|
||||
case "terminal":
|
||||
@@ -2025,32 +2186,159 @@ function workEntryPreview(
|
||||
: `${displayPath} +${workEntry.changedFiles!.length - 1} more`;
|
||||
}
|
||||
|
||||
function workEntryRawCommand(
|
||||
workEntry: Pick<TimelineWorkEntry, "command" | "rawCommand">,
|
||||
): string | null {
|
||||
const rawCommand = workEntry.rawCommand?.trim();
|
||||
if (!rawCommand || !workEntry.command) {
|
||||
return null;
|
||||
type CommandWrapper = "env" | "sudo";
|
||||
|
||||
const COMMAND_WRAPPER_OPTIONS_WITH_VALUE: Record<CommandWrapper, ReadonlySet<string>> = {
|
||||
env: new Set(["-C", "--chdir", "-S", "--split-string", "-u", "--unset"]),
|
||||
sudo: new Set(["-C", "--close-from", "-D", "--chdir", "-g", "--group", "-u", "--user"]),
|
||||
};
|
||||
|
||||
const COMMAND_WRAPPER_FLAGS: Record<CommandWrapper, ReadonlySet<string>> = {
|
||||
env: new Set(["-0", "--null", "-i", "--ignore-environment", "--debug"]),
|
||||
sudo: new Set(["-A", "--askpass", "-b", "--background", "-E", "-H", "-i", "-n", "-S"]),
|
||||
};
|
||||
|
||||
function tokenizeShellCommand(command: string): string[] | null {
|
||||
const tokens: string[] = [];
|
||||
let current = "";
|
||||
let quote: '"' | "'" | null = null;
|
||||
let escaping = false;
|
||||
let tokenStarted = false;
|
||||
|
||||
for (const character of command.trim()) {
|
||||
if (escaping) {
|
||||
current += character;
|
||||
escaping = false;
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (character === "\\" && quote !== "'") {
|
||||
escaping = true;
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (quote !== null) {
|
||||
if (character === quote) {
|
||||
quote = null;
|
||||
} else {
|
||||
current += character;
|
||||
}
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (character === '"' || character === "'") {
|
||||
quote = character;
|
||||
tokenStarted = true;
|
||||
continue;
|
||||
}
|
||||
if (/\s/u.test(character)) {
|
||||
if (tokenStarted) {
|
||||
tokens.push(current);
|
||||
current = "";
|
||||
tokenStarted = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
current += character;
|
||||
tokenStarted = true;
|
||||
}
|
||||
return rawCommand === workEntry.command.trim() ? null : rawCommand;
|
||||
|
||||
if (quote !== null || escaping) return null;
|
||||
if (tokenStarted) tokens.push(current);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function commandProgramName(command: string): string | null {
|
||||
const tokens = tokenizeShellCommand(command);
|
||||
if (tokens === null) return null;
|
||||
let index = 0;
|
||||
let wrapper: CommandWrapper | null = null;
|
||||
|
||||
while (index < tokens.length) {
|
||||
const token = tokens[index];
|
||||
if (!token) return null;
|
||||
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(token)) {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
const tokenProgram = token.split(/[\\/]/).at(-1);
|
||||
if (tokenProgram === "env" || tokenProgram === "sudo") {
|
||||
wrapper = tokenProgram;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (wrapper !== null && token === "--") {
|
||||
wrapper = null;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (wrapper !== null && token.startsWith("-")) {
|
||||
if (COMMAND_WRAPPER_OPTIONS_WITH_VALUE[wrapper].has(token)) {
|
||||
if (tokens[index + 1] === undefined) return null;
|
||||
index += 2;
|
||||
continue;
|
||||
}
|
||||
if (COMMAND_WRAPPER_FLAGS[wrapper].has(token) || /^--[^=]+=/.test(token)) {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (/^-[A-Za-z].+/.test(token) && !token.startsWith("--")) {
|
||||
let consumesNextToken = false;
|
||||
for (const [optionIndex, option] of token.slice(1).split("").entries()) {
|
||||
const shortOption = `-${option}`;
|
||||
if (COMMAND_WRAPPER_OPTIONS_WITH_VALUE[wrapper].has(shortOption)) {
|
||||
consumesNextToken = optionIndex === token.length - 2;
|
||||
break;
|
||||
}
|
||||
if (!COMMAND_WRAPPER_FLAGS[wrapper].has(shortOption)) return null;
|
||||
}
|
||||
if (consumesNextToken && tokens[index + 1] === undefined) return null;
|
||||
index += consumesNextToken ? 2 : 1;
|
||||
continue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return token.split(/[\\/]/).at(-1) || null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function liveWorkEntryLabel(
|
||||
workEntry: TimelineWorkEntry,
|
||||
workspaceRoot: string | undefined,
|
||||
): string {
|
||||
const command = workEntry.command?.trim();
|
||||
if (command) {
|
||||
const program = commandProgramName(command);
|
||||
const verb =
|
||||
workEntry.toolLifecycleStatus === "completed"
|
||||
? "Ran"
|
||||
: workEntry.toolLifecycleStatus === "failed"
|
||||
? "Failed"
|
||||
: "Running";
|
||||
if (program) return `${verb} ${program}`;
|
||||
return `${verb} command`;
|
||||
}
|
||||
|
||||
return workEntryPreview(workEntry, workspaceRoot) ?? toolWorkEntryHeading(workEntry);
|
||||
}
|
||||
|
||||
function buildToolCallExpandedBody(
|
||||
workEntry: TimelineWorkEntry,
|
||||
workspaceRoot: string | undefined,
|
||||
): string | null {
|
||||
const command = workEntry.rawCommand?.trim() || workEntry.command?.trim();
|
||||
const blocks: string[] = [];
|
||||
if (command) {
|
||||
blocks.push(command);
|
||||
}
|
||||
if (workEntry.itemType === "mcp_tool_call" && workEntry.toolData !== undefined) {
|
||||
blocks.push(`MCP call\n${JSON.stringify(workEntry.toolData, null, 2)}`);
|
||||
}
|
||||
const raw = workEntryRawCommand(workEntry);
|
||||
if (raw?.trim()) {
|
||||
blocks.push(raw.trim());
|
||||
} else if (workEntry.command?.trim()) {
|
||||
blocks.push(workEntry.command.trim());
|
||||
}
|
||||
if (workEntry.detail?.trim()) {
|
||||
blocks.push(workEntry.detail.trim());
|
||||
const detail = workEntry.detail?.trim();
|
||||
if (detail && detail !== command) {
|
||||
blocks.push(detail);
|
||||
}
|
||||
const changedFiles = workEntry.changedFiles ?? [];
|
||||
if (changedFiles.length > 0) {
|
||||
@@ -2083,6 +2371,7 @@ function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
|
||||
if (workEntry.itemType === "file_change" || (workEntry.changedFiles?.length ?? 0) > 0) {
|
||||
return "square-pen";
|
||||
}
|
||||
if (workLogEntryIsLocalCodeSearch(workEntry)) return "search";
|
||||
if (workEntry.itemType === "web_search") return "globe";
|
||||
if (workEntry.itemType === "image_view") return "eye";
|
||||
|
||||
@@ -2189,71 +2478,94 @@ const AgentSpawnCtaRow = memo(function AgentSpawnCtaRow(props: { workEntry: Time
|
||||
: "working"
|
||||
: failed > 0
|
||||
? `${failed} failed`
|
||||
: "✓ completed";
|
||||
: "Completed";
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenAgents}
|
||||
className="-mx-1 flex w-full items-center gap-2 rounded-md border border-border/60 bg-card/50 px-2.5 py-1.5 text-left text-[13px] transition hover:bg-accent/50"
|
||||
>
|
||||
<span aria-hidden className={cn("size-1.5 shrink-0 rounded-full", dotClass)} />
|
||||
<WorkEntryIconSvg name="bot" className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<span className="min-w-0 truncate">
|
||||
<span className="font-medium">{lead}</span>
|
||||
{workflowName ? <span className="text-muted-foreground"> · {workflowName}</span> : null}
|
||||
</span>
|
||||
<span className="ml-auto flex shrink-0 items-center gap-2 font-mono text-[.7rem] text-muted-foreground">
|
||||
<span>{status}</span>
|
||||
{totalTokens > 0 ? (
|
||||
<span className="tabular-nums">Σ {formatSubagentTokenCount(totalTokens)}</span>
|
||||
) : null}
|
||||
<span className="text-info-foreground">{live ? "Open Agents ▸" : "View ▸"}</span>
|
||||
</span>
|
||||
</button>
|
||||
<div className="@container/agent-group -mx-1 rounded-xl border border-border/70 bg-secondary p-1.5 dark:border-transparent dark:bg-input/32">
|
||||
<div className="flex items-center justify-between gap-2 px-1">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5 px-1 py-1 text-left text-xs leading-4">
|
||||
<span className="sr-only @[32rem]/agent-group:hidden">{status}</span>
|
||||
<span aria-hidden className={cn("size-1.5 shrink-0 rounded-full", dotClass)} />
|
||||
<WorkEntryIconSvg name="bot" className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<span className="min-w-0 truncate font-medium text-foreground">{lead}</span>
|
||||
{workflowName ? (
|
||||
<span className="hidden min-w-0 truncate text-[11px] text-muted-foreground @[40rem]/agent-group:inline">
|
||||
{workflowName}
|
||||
</span>
|
||||
) : null}
|
||||
<span className="ml-auto hidden shrink-0 items-center gap-2 text-[11px] text-muted-foreground @[32rem]/agent-group:flex">
|
||||
<span>{status}</span>
|
||||
{totalTokens > 0 ? (
|
||||
<span className="font-mono tabular-nums">
|
||||
Σ {formatSubagentTokenCount(totalTokens)}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
</div>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
aria-label={live ? "Open agents" : "View agents"}
|
||||
onClick={onOpenAgents}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<EyeIcon className="size-3" />
|
||||
<span className="hidden @[24rem]/agent-group:inline">
|
||||
{live ? "Open agents" : "View agents"}
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side="top">{live ? "Open agents" : "View agents"}</TooltipPopup>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: {
|
||||
workEntry: TimelineWorkEntry;
|
||||
workspaceRoot: string | undefined;
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
}) {
|
||||
const { workEntry, workspaceRoot } = props;
|
||||
const { workEntry, workspaceRoot, isExpandedToolGroupEntry } = props;
|
||||
// Before any hooks: spawn CTA rows render their own component.
|
||||
if (workEntry.agentSpawn) {
|
||||
return <AgentSpawnCtaRow workEntry={workEntry} />;
|
||||
}
|
||||
return <PlainWorkEntryRow workEntry={workEntry} workspaceRoot={workspaceRoot} />;
|
||||
return (
|
||||
<PlainWorkEntryRow
|
||||
workEntry={workEntry}
|
||||
workspaceRoot={workspaceRoot}
|
||||
isExpandedToolGroupEntry={isExpandedToolGroupEntry}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
workEntry: TimelineWorkEntry;
|
||||
workspaceRoot: string | undefined;
|
||||
isExpandedToolGroupEntry: boolean;
|
||||
}) {
|
||||
const { workEntry, workspaceRoot } = props;
|
||||
const activity = use(TimelineRowActivityCtx);
|
||||
const { workEntry, workspaceRoot, isExpandedToolGroupEntry } = props;
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const iconConfig = workToneIcon(workEntry.tone);
|
||||
const showWarningIndicator = workEntry.sourceActivityKind === "runtime.warning";
|
||||
const entryIconName = showWarningIndicator ? "x" : workEntryIconName(workEntry);
|
||||
const heading = toolWorkEntryHeading(workEntry);
|
||||
const rawPreview = workEntryPreview(workEntry, workspaceRoot);
|
||||
const preview =
|
||||
rawPreview &&
|
||||
normalizeCompactToolLabel(rawPreview).toLowerCase() ===
|
||||
normalizeCompactToolLabel(heading).toLowerCase()
|
||||
? null
|
||||
: rawPreview;
|
||||
const displayText = preview ? `${heading} - ${preview}` : heading;
|
||||
const showFailedIndicator = workEntryIndicatesToolFailure(workEntry);
|
||||
const entryIconName =
|
||||
showWarningIndicator || showFailedIndicator ? "x" : workEntryIconName(workEntry);
|
||||
const displayText = workEntryPreview(workEntry, workspaceRoot) ?? toolWorkEntryHeading(workEntry);
|
||||
const expandedBody = buildToolCallExpandedBody(workEntry, workspaceRoot);
|
||||
const canExpand = expandedBody !== null;
|
||||
const showFailedIndicator = workEntryIndicatesToolFailure(workEntry);
|
||||
const showDestructiveRowStyle =
|
||||
showFailedIndicator &&
|
||||
(workEntry.sourceActivityKind === "runtime.error" || !workLogEntryIsToolLike(workEntry));
|
||||
const iconWrapperClass = cn(
|
||||
"flex size-5 shrink-0 items-center justify-center",
|
||||
showWarningIndicator
|
||||
"flex size-6 shrink-0 items-center justify-center",
|
||||
showWarningIndicator || showFailedIndicator
|
||||
? "text-destructive"
|
||||
: showDestructiveRowStyle
|
||||
? "text-destructive"
|
||||
@@ -2265,17 +2577,19 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
? "font-medium text-warning"
|
||||
: showDestructiveRowStyle
|
||||
? "font-medium text-destructive"
|
||||
: "font-medium text-foreground";
|
||||
const turnSettled = !activity.activeTurnInProgress;
|
||||
const showNeutralIndicator = !turnSettled && workEntryIndicatesToolNeutralStatus(workEntry);
|
||||
const showSuccessIndicator =
|
||||
workEntryIndicatesToolSuccess(workEntry) ||
|
||||
(turnSettled && workEntryIndicatesToolNeutralStatus(workEntry));
|
||||
: workLogEntryIsToolLike(workEntry)
|
||||
? "text-secondary-label"
|
||||
: "text-foreground/80";
|
||||
const showEntryIcon = !isExpandedToolGroupEntry || showWarningIndicator || showFailedIndicator;
|
||||
const accessibleDisplayText = showFailedIndicator
|
||||
? `${displayText}, tool call failed`
|
||||
: displayText;
|
||||
const rowToggleProps = canExpand
|
||||
? {
|
||||
role: "button" as const,
|
||||
tabIndex: 0 as const,
|
||||
"aria-label": displayText,
|
||||
"aria-label": accessibleDisplayText,
|
||||
"aria-expanded": expanded,
|
||||
onClick: () => setExpanded((v) => !v),
|
||||
onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
@@ -2289,90 +2603,41 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex flex-col rounded-md px-0.5 py-0.5 transition-colors",
|
||||
"flex flex-col rounded-md px-0.5 transition-colors",
|
||||
isExpandedToolGroupEntry ? "py-0" : "py-0.5",
|
||||
canExpand &&
|
||||
"cursor-pointer hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
|
||||
)}
|
||||
{...rowToggleProps}
|
||||
>
|
||||
<div className="flex select-none items-center gap-1.5 transition-[opacity,translate] duration-200">
|
||||
<span className={iconWrapperClass}>
|
||||
<span
|
||||
className={cn(iconWrapperClass, !showEntryIcon && "invisible")}
|
||||
role={showFailedIndicator ? "img" : undefined}
|
||||
aria-label={showFailedIndicator ? "Tool call failed" : undefined}
|
||||
aria-hidden={!showEntryIcon}
|
||||
>
|
||||
<WorkEntryIconSvg
|
||||
name={entryIconName}
|
||||
className="block size-3.5 shrink-0 stroke-[1.8] opacity-80"
|
||||
className="block size-4 shrink-0 stroke-[1.8] opacity-70"
|
||||
/>
|
||||
</span>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<div className="min-w-0 flex-1 overflow-hidden">
|
||||
<p className="flex min-w-0 w-full items-baseline gap-1.5 text-[12px] leading-5">
|
||||
<span className={cn("min-w-0 shrink truncate", headingClass)}>{heading}</span>
|
||||
{preview && (
|
||||
<span className="min-w-0 flex-1 truncate text-secondary-label">{preview}</span>
|
||||
<p
|
||||
className={cn(
|
||||
"flex min-w-0 w-full items-baseline gap-1.5 leading-relaxed",
|
||||
isExpandedToolGroupEntry ? "text-[12px] leading-5" : "text-sm",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-px text-icon-muted">
|
||||
<span
|
||||
className="flex size-4 shrink-0 items-center justify-center"
|
||||
aria-hidden={!canExpand}
|
||||
>
|
||||
{canExpand ? (
|
||||
<ChevronDownIcon
|
||||
className={cn(
|
||||
"size-3 shrink-0 opacity-70 transition-transform duration-200",
|
||||
expanded && "rotate-180",
|
||||
)}
|
||||
aria-hidden
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="flex size-4 shrink-0 items-center justify-center">
|
||||
{showFailedIndicator ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<span
|
||||
className="flex size-4 items-center justify-center"
|
||||
aria-label="Tool call failed"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<XIcon className="block size-3 shrink-0 text-destructive" aria-hidden />
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Failed</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : showSuccessIndicator ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="flex size-4 items-center justify-center" />}
|
||||
>
|
||||
<span className="inline-flex size-4 items-center justify-center">
|
||||
<CheckIcon
|
||||
className="block size-3 shrink-0 stroke-current"
|
||||
stroke="currentColor"
|
||||
aria-hidden
|
||||
/>
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Completed</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : showNeutralIndicator ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={<span className="flex size-4 items-center justify-center" />}
|
||||
>
|
||||
<MinusIcon className="block size-3 shrink-0 opacity-70" aria-hidden />
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>Empty</TooltipPopup>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</span>
|
||||
<span className={cn("min-w-0 flex-1 truncate", headingClass)}>{displayText}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{expanded && canExpand && expandedBody ? (
|
||||
<div
|
||||
className="mt-1 ms-7 cursor-default border-s border-border/45 ps-3 pt-0.5"
|
||||
className="mt-1 ms-[1.875rem] cursor-default pt-0.5"
|
||||
onClick={stopRowToggle}
|
||||
onPointerDown={stopRowToggle}
|
||||
>
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
changedFileName,
|
||||
selectChangedFilePreview,
|
||||
shouldAutoExpandChangedFiles,
|
||||
summarizeChangedFileScopes,
|
||||
} from "./changedFilesPresentation";
|
||||
|
||||
describe("changed-files presentation", () => {
|
||||
@@ -35,22 +34,6 @@ describe("changed-files presentation", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("summarizes the most prominent top-level scopes", () => {
|
||||
const files = [
|
||||
{ path: "apps/web/src/App.tsx", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "README.md", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "apps/server/src/index.ts", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "packages/shared/src/git.ts", kind: "modified", additions: 1, deletions: 0 },
|
||||
{ path: "apps\\mobile\\App.tsx", kind: "modified", additions: 1, deletions: 0 },
|
||||
];
|
||||
|
||||
expect(summarizeChangedFileScopes(files)).toEqual([
|
||||
{ label: "apps", fileCount: 3 },
|
||||
{ label: "root", fileCount: 1 },
|
||||
{ label: "packages", fileCount: 1 },
|
||||
]);
|
||||
});
|
||||
|
||||
it("previews files across different scopes before filling from one scope", () => {
|
||||
const files = [
|
||||
{ path: "apps/web/src/App.tsx", kind: "modified", additions: 1, deletions: 0 },
|
||||
|
||||
@@ -4,12 +4,6 @@ import { summarizeTurnDiffStats } from "../../lib/turnDiffTree";
|
||||
export const CHANGED_FILES_AUTO_EXPAND_FILE_LIMIT = 5;
|
||||
export const CHANGED_FILES_AUTO_EXPAND_LINE_LIMIT = 200;
|
||||
export const CHANGED_FILES_PREVIEW_FILE_LIMIT = 3;
|
||||
export const CHANGED_FILES_PREVIEW_SCOPE_LIMIT = 4;
|
||||
|
||||
export interface ChangedFilesScopeSummary {
|
||||
readonly label: string;
|
||||
readonly fileCount: number;
|
||||
}
|
||||
|
||||
function pathSegments(pathValue: string): string[] {
|
||||
return pathValue
|
||||
@@ -38,35 +32,6 @@ export function shouldAutoExpandChangedFiles(
|
||||
return stat.additions + stat.deletions <= CHANGED_FILES_AUTO_EXPAND_LINE_LIMIT;
|
||||
}
|
||||
|
||||
export function summarizeChangedFileScopes(
|
||||
files: ReadonlyArray<TurnDiffFileChange>,
|
||||
limit = CHANGED_FILES_PREVIEW_SCOPE_LIMIT,
|
||||
): ChangedFilesScopeSummary[] {
|
||||
const scopes = new Map<string, { fileCount: number; firstIndex: number }>();
|
||||
files.forEach((file, index) => {
|
||||
const label = changedFileScope(file.path);
|
||||
const current = scopes.get(label);
|
||||
scopes.set(label, {
|
||||
fileCount: (current?.fileCount ?? 0) + 1,
|
||||
firstIndex: current?.firstIndex ?? index,
|
||||
});
|
||||
});
|
||||
|
||||
return Array.from(scopes, ([label, scope]) => ({
|
||||
label,
|
||||
fileCount: scope.fileCount,
|
||||
firstIndex: scope.firstIndex,
|
||||
}))
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
right.fileCount - left.fileCount ||
|
||||
left.firstIndex - right.firstIndex ||
|
||||
left.label.localeCompare(right.label),
|
||||
)
|
||||
.slice(0, limit)
|
||||
.map(({ label, fileCount }) => ({ label, fileCount }));
|
||||
}
|
||||
|
||||
export function selectChangedFilePreview(
|
||||
files: ReadonlyArray<TurnDiffFileChange>,
|
||||
limit = CHANGED_FILES_PREVIEW_FILE_LIMIT,
|
||||
|
||||
@@ -431,6 +431,80 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes live-activity-focus {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes live-activity-focus-counter {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
}
|
||||
|
||||
@utility live-activity-focus {
|
||||
--live-activity-focus-width: 4.5rem;
|
||||
|
||||
right: auto;
|
||||
left: calc(-1 * var(--live-activity-focus-width));
|
||||
width: calc(100% + var(--live-activity-focus-width) + var(--live-activity-focus-width));
|
||||
-webkit-mask-image: linear-gradient(
|
||||
to right,
|
||||
transparent 0,
|
||||
rgb(0 0 0 / 12%) 0.675rem,
|
||||
rgb(0 0 0 / 55%) 1.575rem,
|
||||
black 2.25rem,
|
||||
rgb(0 0 0 / 55%) 2.925rem,
|
||||
rgb(0 0 0 / 12%) 3.825rem,
|
||||
transparent var(--live-activity-focus-width),
|
||||
transparent 100%
|
||||
);
|
||||
-webkit-mask-repeat: no-repeat;
|
||||
mask-image: linear-gradient(
|
||||
to right,
|
||||
transparent 0,
|
||||
rgb(0 0 0 / 12%) 0.675rem,
|
||||
rgb(0 0 0 / 55%) 1.575rem,
|
||||
black 2.25rem,
|
||||
rgb(0 0 0 / 55%) 2.925rem,
|
||||
rgb(0 0 0 / 12%) 3.825rem,
|
||||
transparent var(--live-activity-focus-width),
|
||||
transparent 100%
|
||||
);
|
||||
mask-repeat: no-repeat;
|
||||
animation: live-activity-focus 2.2s steps(24) infinite;
|
||||
will-change: transform;
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
animation: none;
|
||||
opacity: 0;
|
||||
will-change: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@utility live-activity-focus-counter {
|
||||
width: 100%;
|
||||
animation: live-activity-focus-counter 2.2s steps(24) infinite;
|
||||
will-change: transform;
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
animation: none;
|
||||
will-change: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@utility live-activity-focus-aligned {
|
||||
width: calc(100% - var(--live-activity-focus-width) - var(--live-activity-focus-width));
|
||||
margin-left: var(--live-activity-focus-width);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
/* Keep the original T3 Code artwork palettes as the defaults. Built-in
|
||||
|
||||
@@ -722,24 +722,214 @@ describe("workEntryIndicatesToolFailure", () => {
|
||||
});
|
||||
|
||||
describe("deriveWorkLogEntries", () => {
|
||||
it("omits tool started entries and keeps completed entries", () => {
|
||||
it("shows a command from its start event while it is still running", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "tool-complete",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Tool call complete",
|
||||
kind: "tool.completed",
|
||||
}),
|
||||
makeActivity({
|
||||
id: "tool-start",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Tool call",
|
||||
summary: "Command run started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-1",
|
||||
status: "inProgress",
|
||||
title: "Command run",
|
||||
detail: "Bash: vp test run",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command: "vp test run" },
|
||||
},
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const [entry] = deriveWorkLogEntries(activities);
|
||||
expect(entry).toMatchObject({
|
||||
id: "tool-start",
|
||||
command: "vp test run",
|
||||
toolCallId: "call-1",
|
||||
toolLifecycleStatus: "inProgress",
|
||||
sourceActivityKind: "tool.started",
|
||||
});
|
||||
});
|
||||
|
||||
it("retains the start command when the matching completion omits it", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "tool-start",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Command run started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-1",
|
||||
status: "inProgress",
|
||||
title: "Command run",
|
||||
data: { input: { command: "vp test run" } },
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "other-tool-start",
|
||||
createdAt: "2026-02-23T00:00:02.500Z",
|
||||
summary: "Other command started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-2",
|
||||
status: "inProgress",
|
||||
title: "Other command",
|
||||
data: { input: { command: "vp lint" } },
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "tool-complete",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Command run",
|
||||
kind: "tool.completed",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-1",
|
||||
status: "completed",
|
||||
title: "Command run",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "other-tool-complete",
|
||||
createdAt: "2026-02-23T00:00:04.000Z",
|
||||
summary: "Other command",
|
||||
kind: "tool.completed",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-2",
|
||||
status: "completed",
|
||||
title: "Other command",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
const entries = deriveWorkLogEntries(activities);
|
||||
expect(entries.map((entry) => entry.id)).toEqual(["tool-complete"]);
|
||||
expect(entries).toHaveLength(2);
|
||||
expect(entries[0]).toMatchObject({
|
||||
id: "tool-complete",
|
||||
command: "vp test run",
|
||||
toolCallId: "call-1",
|
||||
toolLifecycleStatus: "completed",
|
||||
sourceActivityKind: "tool.completed",
|
||||
});
|
||||
expect(entries[1]).toMatchObject({
|
||||
id: "other-tool-complete",
|
||||
command: "vp lint",
|
||||
toolCallId: "call-2",
|
||||
toolLifecycleStatus: "completed",
|
||||
sourceActivityKind: "tool.completed",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not merge non-adjacent tool starts without stable call ids", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "unkeyed-start-1",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
makeActivity({
|
||||
id: "keyed-start",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Command started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
toolCallId: "call-between",
|
||||
title: "Command",
|
||||
status: "inProgress",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "unkeyed-start-2",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
];
|
||||
|
||||
expect(deriveWorkLogEntries(activities).map((entry) => entry.id)).toEqual([
|
||||
"unkeyed-start-1",
|
||||
"keyed-start",
|
||||
"unkeyed-start-2",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not merge adjacent tool starts without stable call ids", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "unkeyed-start-1",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
makeActivity({
|
||||
id: "unkeyed-start-2",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: { itemType: "search", title: "Search", status: "inProgress" },
|
||||
}),
|
||||
];
|
||||
|
||||
expect(deriveWorkLogEntries(activities).map((entry) => entry.id)).toEqual([
|
||||
"unkeyed-start-1",
|
||||
"unkeyed-start-2",
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not assign an unkeyed completion to an adjacent concurrent start", () => {
|
||||
const activities: OrchestrationThreadActivity[] = [
|
||||
makeActivity({
|
||||
id: "search-start-1",
|
||||
createdAt: "2026-02-23T00:00:01.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "search",
|
||||
toolCallId: "search-call-1",
|
||||
title: "Search",
|
||||
status: "inProgress",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "search-start-2",
|
||||
createdAt: "2026-02-23T00:00:02.000Z",
|
||||
summary: "Search started",
|
||||
kind: "tool.started",
|
||||
payload: {
|
||||
itemType: "search",
|
||||
toolCallId: "search-call-2",
|
||||
title: "Search",
|
||||
status: "inProgress",
|
||||
},
|
||||
}),
|
||||
makeActivity({
|
||||
id: "legacy-search-complete",
|
||||
createdAt: "2026-02-23T00:00:03.000Z",
|
||||
summary: "Search",
|
||||
kind: "tool.completed",
|
||||
payload: {
|
||||
itemType: "search",
|
||||
title: "Search",
|
||||
status: "completed",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
expect(deriveWorkLogEntries(activities).map((entry) => entry.id)).toEqual([
|
||||
"search-start-1",
|
||||
"search-start-2",
|
||||
"legacy-search-complete",
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits task.started but shows task.progress and task.completed", () => {
|
||||
@@ -1239,6 +1429,7 @@ describe("deriveWorkLogEntries", () => {
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0]).toMatchObject({
|
||||
id: "grep-complete",
|
||||
toolCallId: "tool-grep-1",
|
||||
toolTitle: "grep",
|
||||
detail: "19 files",
|
||||
itemType: "web_search",
|
||||
|
||||
@@ -65,6 +65,8 @@ export interface WorkLogEntry {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
turnId?: TurnId | null;
|
||||
/** Stable provider identity across in-progress and completed lifecycle updates. */
|
||||
toolCallId?: string;
|
||||
label: string;
|
||||
detail?: string;
|
||||
command?: string;
|
||||
@@ -748,7 +750,6 @@ export function deriveWorkLogEntries(
|
||||
const ordered = [...activities].toSorted(compareActivitiesByOrder);
|
||||
const entries: DerivedWorkLogEntry[] = [];
|
||||
for (const activity of ordered) {
|
||||
if (activity.kind === "tool.started") continue;
|
||||
// Agent task.started rows are CTA seeds: they carry the true spawn turn,
|
||||
// which is the batch key (completions of background subagents arrive
|
||||
// under later synthetic turns and must not start new batches). They
|
||||
@@ -757,8 +758,13 @@ export function deriveWorkLogEntries(
|
||||
if (activity.kind === "task.updated") continue;
|
||||
if (activity.kind === "tool.progress") continue;
|
||||
if (activity.kind === "context-window.updated") continue;
|
||||
// Plan updates have a dedicated task row. Keeping the raw activity here
|
||||
// duplicates it as a legacy "Work Log / Plan updated" row when history
|
||||
// is expanded.
|
||||
if (activity.kind === "turn.plan.updated") continue;
|
||||
if (activity.summary === "Checkpoint captured") continue;
|
||||
if (isPlanBoundaryToolActivity(activity)) continue;
|
||||
if (isCodexTerminalInteractionActivity(activity)) continue;
|
||||
if (isAgentInternalActivity(activity)) continue;
|
||||
entries.push(toDerivedWorkLogEntry(activity));
|
||||
}
|
||||
@@ -769,7 +775,11 @@ export function deriveWorkLogEntries(
|
||||
}
|
||||
|
||||
function isPlanBoundaryToolActivity(activity: OrchestrationThreadActivity): boolean {
|
||||
if (activity.kind !== "tool.updated" && activity.kind !== "tool.completed") {
|
||||
if (
|
||||
activity.kind !== "tool.started" &&
|
||||
activity.kind !== "tool.updated" &&
|
||||
activity.kind !== "tool.completed"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -780,6 +790,28 @@ function isPlanBoundaryToolActivity(activity: OrchestrationThreadActivity): bool
|
||||
return typeof payload?.detail === "string" && payload.detail.startsWith("ExitPlanMode:");
|
||||
}
|
||||
|
||||
/**
|
||||
* Codex terminal interactions report bytes written to an already-running PTY.
|
||||
* Some thread histories contain them as generic tool.updated rows, so filter
|
||||
* their exact wire shape from the presentation model. This repairs existing
|
||||
* history without deleting or rewriting persisted activities.
|
||||
*/
|
||||
function isCodexTerminalInteractionActivity(activity: OrchestrationThreadActivity): boolean {
|
||||
if (activity.kind !== "tool.updated") {
|
||||
return false;
|
||||
}
|
||||
const payload = asRecord(activity.payload);
|
||||
const data = asRecord(payload?.data);
|
||||
return (
|
||||
payload?.itemType === "command_execution" &&
|
||||
typeof data?.itemId === "string" &&
|
||||
typeof data.processId === "string" &&
|
||||
typeof data.stdin === "string" &&
|
||||
typeof data.threadId === "string" &&
|
||||
typeof data.turnId === "string"
|
||||
);
|
||||
}
|
||||
|
||||
function extractWorkLogToolLifecycleStatus(
|
||||
payload: Record<string, unknown> | null,
|
||||
): WorkLogToolLifecycleStatus | undefined {
|
||||
@@ -878,6 +910,9 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
|
||||
entry.toolCallId = toolCallId;
|
||||
}
|
||||
let toolLifecycleStatus = extractWorkLogToolLifecycleStatus(payload);
|
||||
if (!toolLifecycleStatus && activity.kind === "tool.started") {
|
||||
toolLifecycleStatus = "inProgress";
|
||||
}
|
||||
if (!toolLifecycleStatus && activity.kind === "tool.completed") {
|
||||
toolLifecycleStatus = "completed";
|
||||
}
|
||||
@@ -933,6 +968,17 @@ function agentSpawnGroupKey(entry: DerivedWorkLogEntry): string {
|
||||
return entry.turnId ? `direct:${entry.turnId}` : `direct:task:${taskId}`;
|
||||
}
|
||||
|
||||
function toolLifecycleCollapseMapKey(entry: DerivedWorkLogEntry): string | undefined {
|
||||
if (
|
||||
entry.activityKind !== "tool.started" &&
|
||||
entry.activityKind !== "tool.updated" &&
|
||||
entry.activityKind !== "tool.completed"
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return entry.toolCallId ? `tool:${entry.toolCallId}` : undefined;
|
||||
}
|
||||
|
||||
function collapseDerivedWorkLogEntries(
|
||||
entries: ReadonlyArray<DerivedWorkLogEntry>,
|
||||
): DerivedWorkLogEntry[] {
|
||||
@@ -949,6 +995,7 @@ function collapseDerivedWorkLogEntries(
|
||||
// own turn splintered one batch into a stream of "Kicked off N subagents"
|
||||
// rows (live-test finding, thread 7ac7ef05).
|
||||
const groupKeyByTaskId = new Map<string, string>();
|
||||
const toolLifecycleRowIndex = new Map<string, number>();
|
||||
for (const entry of entries) {
|
||||
const isTaskRow =
|
||||
entry.taskId !== undefined &&
|
||||
@@ -993,12 +1040,40 @@ function collapseDerivedWorkLogEntries(
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const lifecycleKey = toolLifecycleCollapseMapKey(entry);
|
||||
if (lifecycleKey !== undefined) {
|
||||
const matchingLifecycleIndex = toolLifecycleRowIndex.get(lifecycleKey);
|
||||
if (matchingLifecycleIndex !== undefined) {
|
||||
const matchingEntry = collapsed[matchingLifecycleIndex];
|
||||
if (matchingEntry && shouldCollapseToolLifecycleEntries(matchingEntry, entry)) {
|
||||
toolLifecycleRowIndex.delete(lifecycleKey);
|
||||
const merged = mergeDerivedWorkLogEntries(matchingEntry, entry);
|
||||
collapsed[matchingLifecycleIndex] = merged;
|
||||
if (merged.activityKind !== "tool.completed") {
|
||||
toolLifecycleRowIndex.set(lifecycleKey, matchingLifecycleIndex);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
toolLifecycleRowIndex.delete(lifecycleKey);
|
||||
}
|
||||
}
|
||||
const previous = collapsed.at(-1);
|
||||
if (previous && shouldCollapseToolLifecycleEntries(previous, entry)) {
|
||||
collapsed[collapsed.length - 1] = mergeDerivedWorkLogEntries(previous, entry);
|
||||
const previousIndex = collapsed.length - 1;
|
||||
const previousKey = toolLifecycleCollapseMapKey(previous);
|
||||
if (previousKey !== undefined) toolLifecycleRowIndex.delete(previousKey);
|
||||
const merged = mergeDerivedWorkLogEntries(previous, entry);
|
||||
collapsed[previousIndex] = merged;
|
||||
const mergedKey = toolLifecycleCollapseMapKey(merged);
|
||||
if (mergedKey !== undefined && merged.activityKind !== "tool.completed") {
|
||||
toolLifecycleRowIndex.set(mergedKey, previousIndex);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
collapsed.push(entry);
|
||||
if (lifecycleKey !== undefined && entry.activityKind !== "tool.completed") {
|
||||
toolLifecycleRowIndex.set(lifecycleKey, collapsed.length - 1);
|
||||
}
|
||||
}
|
||||
return collapsed;
|
||||
}
|
||||
@@ -1007,19 +1082,31 @@ function shouldCollapseToolLifecycleEntries(
|
||||
previous: DerivedWorkLogEntry,
|
||||
next: DerivedWorkLogEntry,
|
||||
): boolean {
|
||||
if (previous.activityKind !== "tool.updated" && previous.activityKind !== "tool.completed") {
|
||||
if (
|
||||
previous.activityKind !== "tool.started" &&
|
||||
previous.activityKind !== "tool.updated" &&
|
||||
previous.activityKind !== "tool.completed"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (next.activityKind !== "tool.updated" && next.activityKind !== "tool.completed") {
|
||||
if (
|
||||
next.activityKind !== "tool.started" &&
|
||||
next.activityKind !== "tool.updated" &&
|
||||
next.activityKind !== "tool.completed"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (previous.activityKind === "tool.completed") {
|
||||
return false;
|
||||
}
|
||||
if (next.activityKind === "tool.started") {
|
||||
return false;
|
||||
}
|
||||
if (previous.collapseKey !== undefined && previous.collapseKey === next.collapseKey) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
previous.activityKind !== "tool.started" &&
|
||||
previous.toolCallId !== undefined &&
|
||||
next.toolCallId === undefined &&
|
||||
previous.itemType === next.itemType &&
|
||||
@@ -1080,7 +1167,11 @@ function deriveToolLifecycleCollapseKey(entry: DerivedWorkLogEntry): string | un
|
||||
) {
|
||||
return `task${entry.taskId}`;
|
||||
}
|
||||
if (entry.activityKind !== "tool.updated" && entry.activityKind !== "tool.completed") {
|
||||
if (
|
||||
entry.activityKind !== "tool.started" &&
|
||||
entry.activityKind !== "tool.updated" &&
|
||||
entry.activityKind !== "tool.completed"
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
if (entry.toolCallId) {
|
||||
@@ -1283,6 +1374,8 @@ function extractToolCommand(payload: Record<string, unknown> | null): {
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const itemInput = asRecord(item?.input);
|
||||
const dataInput = asRecord(data?.input);
|
||||
const stateInput = asRecord(asRecord(data?.state)?.input);
|
||||
const itemType = asTrimmedString(payload?.itemType);
|
||||
const detail = asTrimmedString(payload?.detail);
|
||||
const candidates: unknown[] = [
|
||||
@@ -1290,6 +1383,8 @@ function extractToolCommand(payload: Record<string, unknown> | null): {
|
||||
itemInput?.command,
|
||||
itemResult?.command,
|
||||
data?.command,
|
||||
dataInput?.command,
|
||||
stateInput?.command,
|
||||
itemType === "command_execution" && detail ? stripTrailingExitCode(detail).output : null,
|
||||
];
|
||||
|
||||
@@ -1316,7 +1411,7 @@ function extractToolTitle(payload: Record<string, unknown> | null): string | nul
|
||||
|
||||
function extractToolCallId(payload: Record<string, unknown> | null): string | null {
|
||||
const data = asRecord(payload?.data);
|
||||
return asTrimmedString(data?.toolCallId);
|
||||
return asTrimmedString(payload?.toolCallId) ?? asTrimmedString(data?.toolCallId);
|
||||
}
|
||||
|
||||
function normalizeInlinePreview(value: string): string {
|
||||
|
||||
Reference in new issue
Block a user