Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(agentic-ide): show worded thoughts as paragraphs between grouped work in threads

rubenluetke10-beep292de3dba5e8
diff --git a/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.test.tsx
index 2410e6e279..592895a742 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.test.tsx
@@ -21,40 +21,39 @@ const show = (item: TurnItem) => render(<ThreadTimeline items={[item]} sessionId
afterEach(cleanup);
describe("thread work log", () => {
- it("folds a finished stretch to one counted line that opens to its steps", () => {
+ it("folds a finished stretch to one named group that opens to its steps", () => {
show(turn([thought("r1", "**Checking the build**"), tool("c1", "npm run build"), tool("c2", "npm test"), { kind: "text", id: "n1", text: "All green." }]));
// A finished turn folds its work behind one "Worked for" line; the answer stays.
expect(screen.getByText("All green.")).toBeTruthy();
- expect(screen.queryByRole("button", { name: /Ran 2 commands/ })).toBeNull();
+ expect(screen.queryByRole("button", { name: /^Ran commands/ })).toBeNull();
fireEvent.click(screen.getByTestId("thread-worked-for"));
- const header = screen.getByRole("button", { name: /Ran 2 commands/ });
+ // The thought reads as a paragraph of its own, not hidden in the group.
+ expect(screen.getByTestId("thread-thought").textContent).toContain("Checking the build");
+ const header = screen.getByRole("button", { name: /^Ran commands/ });
expect(screen.queryByText("npm test")).toBeNull();
fireEvent.click(header);
expect(screen.getByText("npm test")).toBeTruthy();
- // The thought reads as its own words, without the Markdown marks.
- expect(screen.getByText("Checking the build")).toBeTruthy();
expect(screen.getByText("All green.")).toBeTruthy();
});
- it("opens a thought to its full text under a timed heading", () => {
- show(turn([thought("r1", "First idea.\n\nSecond idea.")]));
- fireEvent.click(screen.getByTestId("thread-worked-for"));
- fireEvent.click(screen.getByRole("button", { name: /First idea\. Second idea\./ }));
- expect(screen.getByText("Thought for 4.2s")).toBeTruthy();
- expect(screen.getByText("Second idea.")).toBeTruthy();
- });
-
- it("names the newest step of the running stretch and keeps the turn clock", () => {
+ it("keeps the running group open with every step so far and the turn clock", () => {
show(turn([tool("c1", "npm run build"), tool("c2", "npm test", { output: null, durationMs: null })], "running"));
+ expect(screen.getByRole("button", { name: /steps so far/ }).getAttribute("aria-expanded")).toBe("true");
expect(screen.getByText("npm test")).toBeTruthy();
- expect(screen.queryByText("npm run build")).toBeNull();
+ expect(screen.getByText("npm run build")).toBeTruthy();
expect(screen.getByTestId("thread-working").textContent).toMatch(/^Working for /);
});
- it("follows a live thought by its newest paragraph", () => {
+ it("writes a live thought out as it comes in", () => {
show(turn([thought("r1", "Reading the config.\n\nNow the router.", true)], "running"));
+ expect(screen.getByText("Reading the config.")).toBeTruthy();
expect(screen.getByText("Now the router.")).toBeTruthy();
});
+
+ it("shows wordless live thinking as one Thinking step", () => {
+ show(turn([thought("r1", "", true)], "running"));
+ expect(screen.getByText("Thinking")).toBeTruthy();
+ });
});
describe("changed files card", () => {
diff --git a/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.tsx b/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.tsx
index a368709301..6620db86e4 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/threads/ThreadTimeline.tsx
@@ -1,25 +1,25 @@
import { createContext, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { ArrowDown, Brain, Check, ChevronDown, ChevronRight, Copy, Diff, FileText, Hammer, MessageCircleQuestion, ShieldAlert, X } from "lucide-react";
import { ChatMarkdown } from "@/components/agentchat/ChatMarkdown";
-import type { ReasoningBlock, TextBlock, TimelineItem, ToolBlock, TurnBlock, TurnItem, UserItem } from "@/components/agentchat/reduce";
+import type { TextBlock, TimelineItem, ToolBlock, TurnBlock, TurnItem, UserItem } from "@/components/agentchat/reduce";
import { toolDiff, type DiffFile } from "@/components/agentchat/toolDiff";
import { CallMark, StretchMark } from "@/components/agentchat/TraceTimeline";
import { readableOutput, traceDuration, type Call } from "@/components/agentchat/traceEntries";
import { useT } from "@/i18n";
import { robustCopy } from "@/lib/clipboard";
import { cn } from "@/lib/utils";
-import { buildThreadRows, isFailed, liveItem, thoughtPreview, type ThreadRow, type WorkGroup, type WorkItem } from "./threadWork";
+import { buildThreadRows, isFailed, type ThreadRow, type WorkGroup, type WorkItem } from "./threadWork";
/**
* A thread's conversation: the person's messages on the right, the agent's
* answer as plain reading text on the left, and the work in between as a
- * quiet log. Each stretch of thinking and tool calls is one line — "Ran 3
- * commands and read 2 files" once it is done, the newest step with a moving
- * shine while it runs — that opens to the single steps. A thought shows as
- * one line of its own words and opens to all of them; a call opens to what
- * it ran, the diff it made or what came back. A running turn ends in
- * "Working for 12s"; a finished one says how long it worked and which files
- * it changed.
+ * quiet log. Every thought the agent put into words reads as a paragraph of
+ * its own, a step quieter than the answer. The tool calls between two
+ * paragraphs are one group — "Edited files, ran commands" — that opens to a
+ * short scrolling list of the single steps; the group the running turn is in
+ * stays open and follows its newest step. A call opens to what it ran, the
+ * diff it made or what came back. A running turn ends in "Working for 12s";
+ * a finished one says how long it worked and which files it changed.
*
* The work-log geometry and the live shine are adapted from pingdotgg/t3code
* @ e22c880 (apps/web/src/components/chat/WorkLog.tsx, MessagesTimeline.tsx),
@@ -27,7 +27,7 @@ import { buildThreadRows, isFailed, liveItem, thoughtPreview, type ThreadRow, ty
*/
const PROSE = cn(
- "prose prose-neutral max-w-none text-base leading-6 text-foreground dark:prose-invert dark:text-foreground [overflow-wrap:anywhere]",
+ "py-1 prose prose-neutral max-w-none text-base leading-6 text-foreground dark:prose-invert dark:text-foreground [overflow-wrap:anywhere]",
"[&>div>:first-child]:mt-0 [&>div>:last-child]:mb-0",
"prose-p:my-2 prose-p:text-foreground prose-li:text-foreground prose-strong:text-foreground-strong",
"prose-headings:mb-1.5 prose-headings:mt-4 prose-headings:font-semibold prose-headings:tracking-normal prose-headings:text-foreground-strong",
@@ -40,15 +40,16 @@ const PROSE = cn(
);
/**
- * One row of the work log: a 24 px line — a 16 px mark centred in a 24 px
- * box, the words, then a trailing note. Rows inside an opened group sit
- * tight; a row on its own gets a little air. The words of a live row carry
- * the shine; a row that opens shows its chevron.
+ * One row of the work log, set like a line of the answer: body size, a 16 px
+ * mark flush with the text's left edge, the words in the quiet tone, then a
+ * trailing note. A row on its own gets the air of a paragraph; rows inside an
+ * opened group sit tight. The words of a live row carry the shine. The
+ * chevron of a row that opens shows only on hover, focus or while open, so a
+ * finished log reads as plain grey lines between the agent's words.
*/
function WorkRow({
icon,
label,
- labelTone = "muted",
trailing,
expanded,
onToggle,
@@ -60,8 +61,6 @@ function WorkRow({
}: {
icon: ReactNode;
label: ReactNode;
- /** Thoughts read a step brighter than tool calls. */
- labelTone?: "muted" | "thought";
trailing?: ReactNode;
expanded?: boolean;
onToggle?: () => void;
@@ -72,16 +71,24 @@ function WorkRow({
ariaLabel?: string;
children?: ReactNode;
}) {
- const line = <span className="flex min-h-6 min-w-0 items-center gap-1.5 text-sm leading-relaxed">
- <span aria-hidden className="flex h-6 w-6 shrink-0 items-center justify-center text-muted-foreground [&_svg]:h-4 [&_svg]:w-4">{icon}</span>
- <span className={cn("min-w-0 flex-1 truncate", labelTone === "thought" ? "text-foreground-secondary" : "text-muted-foreground", live && "live-tool-shine")}>{label}</span>
+ const line = <span className={cn("flex min-h-6 min-w-0 items-center gap-2.5 leading-6", grouped ? "text-sm" : "text-base")}>
+ <span aria-hidden className="flex h-6 w-4 shrink-0 items-center justify-center text-muted-foreground [&_svg]:h-4 [&_svg]:w-4">{icon}</span>
+ <span className={cn(
+ "min-w-0 truncate transition-colors",
+ "text-muted-foreground",
+ onToggle && !live && "group-hover/row:text-foreground",
+ live && "live-tool-shine",
+ )}>{label}</span>
{trailing}
- {stamp ? <span className="shrink-0 text-xs tabular-nums text-muted-foreground opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100">{clock(stamp)}</span> : null}
{onToggle && <span aria-hidden className="flex h-4 w-4 shrink-0 items-center justify-center">
- <ChevronRight className={cn("h-3 w-3 text-muted-foreground opacity-70 transition-transform duration-200", expanded && "rotate-90")} />
+ <ChevronRight className={cn(
+ "h-3.5 w-3.5 text-muted-foreground opacity-0 transition duration-200 group-hover/row:opacity-70 group-focus-visible/row:opacity-70",
+ expanded && "rotate-90 opacity-70",
+ )} />
</span>}
+ {stamp ? <span className="ml-auto shrink-0 pl-2 text-xs tabular-nums text-muted-foreground opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100">{clock(stamp)}</span> : null}
</span>;
- const row = cn("group/row relative block w-full min-w-0 rounded-md px-0.5 text-left", grouped ? "py-0" : "py-0.5");
+ const row = cn("group/row relative block w-full min-w-0 rounded-md text-left", grouped ? "py-0" : "py-1.5");
return <div className="min-w-0">
{onToggle
? <button type="button" aria-expanded={expanded} aria-label={ariaLabel} onClick={onToggle}
@@ -196,7 +203,7 @@ function CallRow({ call, stamp, grouped = false, onOpenChange }: { call: Call; s
const label = running
? [call.text, detail].filter(Boolean).join(" ")
: <>
- <span className={cn(call.kind === "command" && "font-mono text-[0.8125rem]")}>{call.text}</span>
+ <span>{call.text}</span>
{detail && <span className="ml-1.5 text-muted-foreground/70">{detail}</span>}
{tail && <span className="ml-1.5 text-muted-foreground/70">— {tail}</span>}
</>;
@@ -217,38 +224,16 @@ function CallRow({ call, stamp, grouped = false, onOpenChange }: { call: Call; s
</WorkRow>;
}
-/** The newest paragraph of a thought, for a live line that follows the thinking. */
-function latestThought(text: string): string {
- const paragraphs = text.split(/\n\s*\n/).map((part) => thoughtPreview(part)).filter(Boolean);
- return paragraphs[paragraphs.length - 1] ?? "";
-}
+const THOUGHT_PROSE = cn(PROSE, "text-foreground-secondary dark:text-foreground-secondary prose-p:text-foreground-secondary prose-li:text-foreground-secondary");
-const THOUGHT_PROSE = cn(PROSE, "text-sm leading-6 text-foreground-secondary prose-p:my-1.5 prose-p:text-foreground-secondary prose-li:text-foreground-secondary");
+/** A thought in the agent's own words: a paragraph between its work, a step quieter than the answer. */
+function ThoughtView({ text }: { text: string }) {
+ return <div className={THOUGHT_PROSE} data-testid="thread-thought"><ChatMarkdown text={text} /></div>;
+}
-/**
- * A thought folded to one line of its own words; opened, the line names it
- * ("Thought for 4.2s") and the whole text reads below.
- */
-function ThoughtRow({ block, live, stamp, grouped = false, onOpenChange }: {
- block: ReasoningBlock; live: boolean; stamp?: number; grouped?: boolean; onOpenChange?: OpenChange;
-}) {
- const [open, toggle] = useDisclosure(onOpenChange);
- const text = block.text.trim();
- const heading = live ? "Thinking" : block.durationMs ? `Thought for ${traceDuration(block.durationMs)}` : "Thought";
- const preview = useMemo(() => thoughtPreview(text), [text]);
- return <WorkRow
- icon={<Brain strokeWidth={1.75} />}
- label={open ? heading : preview || heading}
- labelTone="thought"
- stamp={stamp}
- grouped={grouped}
- live={live}
- expanded={open}
- onToggle={text ? toggle : undefined}>
- <div className="ml-7 flex max-h-96 flex-col overflow-auto px-0.5 py-1 select-text scrollbar-jarvis">
- <div className={THOUGHT_PROSE}><ChatMarkdown text={text} /></div>
- </div>
- </WorkRow>;
+/** The wordless thought the running turn is having: one live "Thinking" step. */
+function ThinkingRow({ grouped = false }: { grouped?: boolean }) {
+ return <WorkRow icon={<Brain strokeWidth={1.75} />} label="Thinking" grouped={grouped} live />;
}
/**
@@ -259,7 +244,7 @@ const THREAD_MEDIA = "[&_[data-kind=image]_img]:max-h-48 [&_[data-kind=image]_im
function StepRow({ item, running, grouped, onOpenChange }: { item: WorkItem; running: boolean; grouped?: boolean; onOpenChange?: OpenChange }) {
if (item.kind === "call") return <CallRow call={item.call} stamp={item.startedMs} grouped={grouped} onOpenChange={onOpenChange} />;
- return <ThoughtRow block={item.block} live={running && item.block.live} stamp={item.startedMs} grouped={grouped} onOpenChange={onOpenChange} />;
+ return running ? <ThinkingRow grouped={grouped} /> : null;
}
const FADE = "1.5rem";
@@ -326,41 +311,24 @@ function GroupMark({ group }: { group: WorkGroup }) {
}
/**
- * The stretch the running turn is in: one line naming its newest step with
- * the shine — the command it runs, the thought it is having — that opens to
- * every step so far.
+ * The calls between two paragraphs: a lone step on its own line, else one
+ * line naming what they did that opens to every step. The group the running
+ * turn is in opens by itself and follows its newest step; the reader can
+ * still close it.
*/
-function LiveGroup({ group }: { group: WorkGroup }) {
- const [open, toggle] = useDisclosure();
- const item = liveItem(group);
- const label = item.kind === "call"
- ? [item.call.text, item.call.detail].filter(Boolean).join(" ")
- : latestThought(item.block.text) || "Thinking";
- return <WorkRow
- icon={item.kind === "call" ? <CallMark call={item.call} /> : <Brain strokeWidth={1.75} />}
- label={label}
- labelTone={item.kind === "thought" ? "thought" : "muted"}
- ariaLabel={group.items.length > 1 ? `${label}, ${group.items.length} steps so far` : undefined}
- live
- expanded={open}
- onToggle={toggle}>
- <StepList items={group.items} running follow />
- </WorkRow>;
-}
-
-/** A finished stretch: its one step on its own, or one counted line that opens to them. */
function WorkGroupView({ group, running }: { group: WorkGroup; running: boolean }) {
- const [open, toggle] = useDisclosure();
- if (group.live) return <LiveGroup group={group} />;
+ const [open, setOpen] = useState(group.live);
if (group.items.length === 1) return <StepRow item={group.items[0]} running={running} />;
return <WorkRow
icon={<GroupMark group={group} />}
label={group.summary}
+ ariaLabel={group.live ? `${group.summary}, ${group.items.length} steps so far` : undefined}
trailing={<DiffStat added={group.added} removed={group.removed} />}
stamp={group.startedMs}
+ live={group.live}
expanded={open}
- onToggle={toggle}>
- <StepList items={group.items} running={running} follow={false} />
+ onToggle={() => setOpen((value) => !value)}>
+ <StepList items={group.items} running={running} follow={group.live} />
</WorkRow>;
}
@@ -557,7 +525,7 @@ function pendingLabel(block: ToolBlock): { icon: ReactNode; text: string } | nul
*/
export function foldFinished(rows: ThreadRow[]): { work: ThreadRow[]; answer: ThreadRow[] } {
let last = -1;
- rows.forEach((row, index) => { if (row.kind === "work") last = index; });
+ rows.forEach((row, index) => { if (row.kind === "work" || row.kind === "thought") last = index; });
return { work: rows.slice(0, last + 1), answer: rows.slice(last + 1) };
}
@@ -581,6 +549,7 @@ const TurnView = memo(function TurnView({ turn }: { turn: TurnItem }) {
: `Worked${duration ? ` for ${duration}` : ""}`;
const renderRow = (row: ThreadRow) => {
if (row.kind === "work") return <WorkGroupView key={row.id} group={row} running={running} />;
+ if (row.kind === "thought") return <ThoughtView key={row.id} text={row.text} />;
if (row.kind === "text") return <div key={row.id} className={cn(PROSE, THREAD_MEDIA)}><ChatMarkdown text={row.text} /></div>;
const pending = pendingLabel(row.block);
return pending ? <WorkRow key={row.id} icon={pending.icon} label={pending.text} live /> : null;
diff --git a/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.test.ts b/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.test.ts
index 3125ac0774..b3c599d4bd 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.test.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import en from "@/i18n/locales/en.json";
import type { ToolBlock, TurnBlock, TurnStatus } from "@/components/agentchat/reduce";
-import { buildThreadRows, liveItem, thoughtPreview, type ThreadRow, type WorkGroup } from "./threadWork";
+import { buildThreadRows, type ThreadRow, type WorkGroup } from "./threadWork";
type Dict = Record<string, unknown>;
const t = (key: string): string => {
@@ -22,45 +22,39 @@ const rows = (blocks: TurnBlock[], status: TurnStatus = "done"): ThreadRow[] =>
const groups = (list: ThreadRow[]) => list.filter((row): row is WorkGroup => row.kind === "work");
describe("thread work groups", () => {
- it("folds thinking and calls up to the next prose into one group", () => {
+ it("reads every worded thought as a paragraph that splits the work around it", () => {
const list = rows([
thought("r1", "Looking at the repo"),
tool("c1"),
- thought("r2", "Now the tests"),
tool("c2", { input: { command: "npm test" } }),
+ thought("r2", "Now the source"),
read("f1", "src/a.ts"),
+ tool("c3", { input: { command: "npm run build" } }),
text("n1", "Tests pass."),
]);
- expect(list.map((row) => row.kind)).toEqual(["work", "text"]);
- const [group] = groups(list);
- expect(group.items.map((item) => item.kind)).toEqual(["thought", "call", "thought", "call", "call"]);
- expect(group.summary).toBe("Ran 2 commands and read 1 file");
- expect(group.live).toBe(false);
+ expect(list.map((row) => row.kind)).toEqual(["thought", "work", "thought", "work", "text"]);
+ const [commands, mixed] = groups(list);
+ expect(commands.items.map((item) => item.kind)).toEqual(["call", "call"]);
+ expect(commands.summary).toBe("Ran commands");
+ expect(mixed.items).toHaveLength(2);
+ expect(mixed.sole).toBeNull();
+ expect(commands.live).toBe(false);
});
- it("counts what it leaves out instead of dropping it", () => {
- const [group] = groups(rows([
- tool("c1"),
- read("f1", "a.ts"),
- tool("l1", { name: "LS", input: { path: "src" }, output: "x" }),
- tool("e1", { name: "Edit", input: { file_path: "b.ts", old_string: "a", new_string: "b" }, output: "ok" }),
- ]));
- expect(group.summary).toBe("Ran 1 command, edited 1 file, and performed 2 other actions");
+ it("keeps every kind of call between two paragraphs in one group", () => {
+ const list = groups(rows([tool("c1"), read("f1", "a.ts"), tool("c2")]));
+ expect(list).toHaveLength(1);
+ expect(list[0].items).toHaveLength(3);
});
- it("names a lone call by itself and a lone thought as a thought", () => {
+ it("names a lone call by itself", () => {
expect(groups(rows([tool("c1", { input: { command: "npm run build" } })]))[0].summary).toBe("npm run build");
- const [solo] = groups(rows([thought("r1", "Plan the change")]));
- expect(solo.summary).toBe("Thought");
- expect(solo.sole).toBe("thought");
});
- it("keeps the running turn's newest group live and points at its running call", () => {
+ it("keeps the running turn's newest group live", () => {
const list = rows([text("n1", "Starting."), tool("c1"), tool("c2", { input: { command: "npm test" }, output: null, durationMs: null })], "running");
const [group] = groups(list);
expect(group.live).toBe(true);
- const item = liveItem(group);
- expect(item.kind === "call" && item.call.text).toBe("npm test");
});
it("is not live once prose follows the group", () => {
@@ -68,10 +62,18 @@ describe("thread work groups", () => {
expect(group.live).toBe(false);
});
+ it("marks the thought the running turn is still writing as live", () => {
+ const list = rows([tool("c1"), thought("r1", "Weighing it", true)], "running");
+ expect(list.map((row) => row.kind)).toEqual(["work", "thought"]);
+ expect(list[1].kind === "thought" && list[1].live).toBe(true);
+ });
+
it("drops wordless thinking unless it is the turn's live thought", () => {
expect(rows([thought("r1", "")])).toEqual([]);
+ expect(rows([tool("c1"), thought("r1", ""), tool("c2")]).map((row) => row.kind)).toEqual(["work"]);
const [group] = groups(rows([thought("r1", "", true)], "running"));
- expect(group.items).toHaveLength(1);
+ expect(group.sole).toBe("thought");
+ expect(group.summary).toBe("Thinking");
});
it("breaks a group at a card that waits for the person", () => {
@@ -83,10 +85,3 @@ describe("thread work groups", () => {
expect(list.map((row) => row.kind)).toEqual(["work", "pending", "work"]);
});
});
-
-describe("thought preview", () => {
- it("reads a Markdown thought as one plain line", () => {
- expect(thoughtPreview("**Inspecting the repo**\n\nI need to read `src/app.ts` and [the docs](https://x.y).\n- one\n- two"))
- .toBe("Inspecting the repo I need to read src/app.ts and the docs. one two");
- });
-});
diff --git a/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.ts b/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.ts
index b78a13365d..f1847aa0e1 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/threads/threadWork.ts
@@ -4,18 +4,20 @@
* Copyright (c) 2026 T3 Tools Inc. Full text: third_party/t3code/LICENSE.
*
* The pure model behind a thread turn's work log. A turn reads as the
- * agent's answer with its work folded in between: every stretch of thinking
- * and tool calls up to the next piece of prose becomes ONE group. A finished
- * group is one line that counts what happened ("Ran 3 commands and read 2
- * files"); the group the running turn is still in is one live line that
- * names the newest step ("Thinking", the command it runs). Both open to the
- * single steps, and a step opens to its thought, diff or output.
+ * agent's own words — its answer and every thought it put into words — with
+ * its work in between: ONE group per run of tool calls between two
+ * paragraphs, named by what it did ("Edited files, ran commands", the call
+ * itself when it ran alone). A thought with words is a paragraph of its own
+ * and splits the work around it; wordless (redacted) thinking is no row,
+ * except the thought the running turn is having, which shows as a live
+ * "Thinking" step so the turn never looks idle. The group the running turn is
+ * still in is live.
*/
import type { ReasoningBlock, TextBlock, ToolBlock, TurnBlock, TurnStatus } from "@/components/agentchat/reduce";
-import { buildTimeline, type Call, type CallKind, type Translate } from "@/components/agentchat/traceEntries";
+import { buildTimeline, summarize, type Call, type CallKind, type Translate } from "@/components/agentchat/traceEntries";
-/** One step of a group: a tool call or a stretch of thinking. */
+/** One step of a group: a tool call, or the wordless thought a running turn is having. */
export type WorkItem =
| { kind: "call"; id: string; call: Call; startedMs: number }
| { kind: "thought"; id: string; block: ReasoningBlock; startedMs: number };
@@ -24,20 +26,22 @@ export interface WorkGroup {
kind: "work";
id: string;
items: WorkItem[];
- /** "Ran 3 commands and read 2 files", "Thought". */
+ /** "Edited files, ran commands", the command itself, "Thinking". */
summary: string;
- /** The single kind of call the group made, "thought" when it only thought, else null. */
+ /** The single kind of call the group made, "thought" when it only thinks, else null. */
sole: CallKind | "thought" | null;
added: number;
removed: number;
startedMs: number;
- /** The running turn's newest group: drawn as one live line. */
+ /** The running turn's newest group: it stays open and follows its newest step. */
live: boolean;
}
export type ThreadRow =
| WorkGroup
| { kind: "text"; id: string; text: string; block: TextBlock }
+ /** A thought in the agent's own words, read as a paragraph between its work. */
+ | { kind: "thought"; id: string; text: string; block: ReasoningBlock; live: boolean }
/** A call that waits for the person: an approval or a question card. */
| { kind: "pending"; id: string; block: ToolBlock };
@@ -45,93 +49,6 @@ export function isFailed(call: Call): boolean {
return call.status === "failed" || call.status === "blocked" || call.status === "declined";
}
-/** A thought's text as one plain line: no Markdown marks, no line breaks. */
-export function thoughtPreview(text: string): string {
- return text
- .replace(/```[^\n]*\n?/g, " ")
- .replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1")
- .replace(/\[([^\]]+)\]\([^)]*\)/g, "$1")
- .replace(/^\s{0,3}(#{1,6}|>|[-*+]|\d+[.)])\s+/gm, "")
- .replace(/(\*\*|__|~~|`)/g, "")
- .replace(/(^|\s)[*_](\S[^*_]*\S|\S)[*_](?=\s|[.,;:!?]|$)/g, "$1$2")
- .replace(/\s+/g, " ")
- .trim();
-}
-
-function plural(count: number, one: string, other: string): string {
- return `${count} ${count === 1 ? one : other}`;
-}
-
-/** What a set of calls of one bucket did, counted. */
-function bucketLabel(bucket: string, calls: Call[]): string {
- const n = calls.length;
- switch (bucket) {
- case "command": return `Ran ${plural(n, "command", "commands")}`;
- case "read": return `Read ${plural(new Set(calls.map((call) => call.text)).size, "file", "files")}`;
- case "list": return `Listed ${plural(n, "folder", "folders")}`;
- case "search": return n === 1 ? "Searched the code" : `Searched the code ${n} times`;
- case "edit": return `Edited ${plural(new Set(calls.map((call) => call.text)).size, "file", "files")}`;
- case "write": return `Created ${plural(n, "file", "files")}`;
- case "image": return `Viewed ${plural(n, "image", "images")}`;
- case "family:web": return n === 1 ? "Searched the web" : `Searched the web ${n} times`;
- default: return n === 1 ? calls[0].text : `${calls[0].text} ${n} times`;
- }
-}
-
-/** Commands and file changes say the most about a stretch; they lead. */
-function priority(bucket: string): number {
- if (bucket === "command" || bucket === "edit" || bucket === "write") return 0;
- return 1;
-}
-
-function sentence(parts: string[]): string {
- const lowered = parts.map((part, index) => index === 0 ? part : part.charAt(0).toLowerCase() + part.slice(1));
- if (lowered.length < 3) return lowered.join(" and ");
- return `${lowered.slice(0, -1).join(", ")}, and ${lowered.at(-1)}`;
-}
-
-function names(list: string[]): string {
- if (list.length < 3) return list.join(" and ");
- return `${list.slice(0, -1).join(", ")}, and ${list.at(-1)}`;
-}
-
-/**
- * A group in one line: the services it used, then at most two kinds of
- * work, and every call left over still counted.
- */
-export function summarizeWork(items: WorkItem[]): string {
- const calls = items.flatMap((item) => item.kind === "call" ? [item.call] : []);
- if (calls.length === 0) {
- const thoughts = items.length;
- return thoughts <= 1 ? "Thought" : `Thought ${thoughts} times`;
- }
- if (calls.length === 1 && calls[0].bucket !== "edit") return calls[0].text;
- const services: string[] = [];
- const buckets = new Map<string, Call[]>();
- for (const call of calls) {
- if (call.bucket.startsWith("used:")) {
- const name = call.bucket.slice(5);
- if (!services.includes(name)) services.push(name);
- continue;
- }
- const list = buckets.get(call.bucket);
- if (list) list.push(call);
- else buckets.set(call.bucket, [call]);
- }
- const ranked = [...buckets].map(([bucket, list], index) => ({ bucket, list, index }));
- const chosen = [...ranked]
- .sort((a, b) => priority(a.bucket) - priority(b.bucket) || a.index - b.index)
- .slice(0, 2)
- .sort((a, b) => a.index - b.index);
- const parts = chosen.map(({ bucket, list }) => bucketLabel(bucket, list));
- if (services.length) parts.unshift(`Used ${names(services.slice(0, 3))}${services.length > 3 ? ` and ${services.length - 3} more` : ""}`);
- const told = chosen.reduce((sum, { list }) => sum + list.length, 0);
- const serviceCalls = calls.filter((call) => call.bucket.startsWith("used:")).length;
- const rest = calls.length - told - serviceCalls;
- if (rest > 0) parts.push(`Performed ${plural(rest, "other action", "other actions")}`);
- return sentence(parts);
-}
-
function soleKind(items: WorkItem[]): WorkGroup["sole"] {
const calls = items.flatMap((item) => item.kind === "call" ? [item.call] : []);
if (calls.length === 0) return "thought";
@@ -139,16 +56,7 @@ function soleKind(items: WorkItem[]): WorkGroup["sole"] {
return kinds.size === 1 ? calls[0].kind : null;
}
-/** The step the live line names: the newest running call, else the newest step. */
-export function liveItem(group: WorkGroup): WorkItem {
- for (let i = group.items.length - 1; i >= 0; i -= 1) {
- const item = group.items[i];
- if (item.kind === "call" && item.call.status === "running") return item;
- }
- return group.items[group.items.length - 1];
-}
-
-/** Lay out a turn's blocks as text, waiting cards and work groups. */
+/** Lay out a turn's blocks as text, thoughts, waiting cards and work groups. */
export function buildThreadRows(blocks: TurnBlock[], options: { t: Translate; lang: string; status: TurnStatus }): ThreadRow[] {
const timeline = buildTimeline(blocks, { ...options, live: true });
const started = new Map<string, number>();
@@ -156,8 +64,10 @@ export function buildThreadRows(blocks: TurnBlock[], options: { t: Translate; la
if (block.kind === "tool") started.set(block.callId, block.startedMs);
else if (block.kind === "reasoning") started.set(block.id, block.startedMs);
}
+ const running = options.status === "running";
const rows: ThreadRow[] = [];
let items: WorkItem[] = [];
+
const flush = () => {
if (!items.length) return;
const calls = items.flatMap((item) => item.kind === "call" ? [item.call] : []);
@@ -165,7 +75,7 @@ export function buildThreadRows(blocks: TurnBlock[], options: { t: Translate; la
kind: "work",
id: `work:${items[0].id}`,
items,
- summary: summarizeWork(items),
+ summary: calls.length ? summarize(calls, options.t, options.lang) : "Thinking",
sole: soleKind(items),
added: calls.reduce((sum, call) => sum + call.added, 0),
removed: calls.reduce((sum, call) => sum + call.removed, 0),
@@ -174,11 +84,6 @@ export function buildThreadRows(blocks: TurnBlock[], options: { t: Translate; la
});
items = [];
};
- const thought = (block: ReasoningBlock) => {
- // Wordless (redacted) thinking is no step; a live one still shows the turn thinks.
- if (!block.text.trim() && !(block.live && options.status === "running")) return;
- items.push({ kind: "thought", id: block.id, block, startedMs: started.get(block.id) ?? 0 });
- };
for (const entry of timeline.entries) {
if (entry.kind === "activity") {
@@ -187,7 +92,14 @@ export function buildThreadRows(blocks: TurnBlock[], options: { t: Translate; la
}
const block = entry.block;
if (block.kind === "reasoning") {
- thought(block);
+ const live = running && block.live;
+ const text = block.text.trim();
+ if (text) {
+ flush();
+ rows.push({ kind: "thought", id: block.id, text, block, live });
+ } else if (live) {
+ items.push({ kind: "thought", id: block.id, block, startedMs: started.get(block.id) ?? 0 });
+ }
continue;
}
flush();
@@ -196,6 +108,6 @@ export function buildThreadRows(blocks: TurnBlock[], options: { t: Translate; la
}
flush();
const last = rows[rows.length - 1];
- if (options.status === "running" && last?.kind === "work") last.live = true;
+ if (running && last?.kind === "work") last.live = true;
return rows;
}