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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(chat): fold finished traces behind a thought chevron
rubenluetke10-beep23adc3a56abe
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.test.tsxindex d1f3d3e3a5..eca4fc4b5b 100644--- a/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.test.tsx@@ -1,14 +1,15 @@import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";import { afterEach, describe, expect, it, vi } from "vitest";-import { groupTrace, groupActivityTrace, WorkTrace, traceDuration } from "./WorkTrace";+import { groupTrace, groupActivityTrace, splitConversationTurn, WorkTrace, traceDuration } from "./WorkTrace";import { traceToolIdentity } from "./traceActivity";-import type { ToolBlock, TurnBlock, TurnStatus } from "./reduce";+import type { TextBlock, ToolBlock, TurnBlock, TurnStatus } from "./reduce";const tool = (id: string, over: Partial<ToolBlock> = {}): ToolBlock => ({kind: "tool", callId: id, name: "read_file", input: { path: `${id}.ts` }, output: `Contents of ${id}`,isError: false, durationMs: 800, approval: null, startedMs: 1000, ...over,});const thought: TurnBlock = { kind: "reasoning", id: "reason", text: "**Check** the input.", live: false, durationMs: 8000, startedMs: 1000 };+const reply = (id: string, text: string): TextBlock => ({ kind: "text", id, text });const props = { startedMs: 1000, durationMs: 12000, status: "done" as TurnStatus };afterEach(() => { cleanup(); vi.useRealTimers(); });@@ -163,4 +164,22 @@ describe("work trace", () => {expect(screen.getByRole("button", { name: /Run command.*49ms/ })).toBeTruthy();expect(screen.queryByText("0.0s")).toBeNull();});++ it("keeps the last reply visible and treats earlier text as foldable work", () => {+ const blocks = [tool("a"), reply("plan", "I will inspect the files."), tool("b"), reply("done", "Everything is ready.")];+ expect(splitConversationTurn(blocks)).toEqual({+ work: [tool("a"), reply("plan", "I will inspect the files."), tool("b")],+ answer: [reply("done", "Everything is ready.")],+ after: [],+ });+ });++ it("keeps failures after the last reply in view", () => {+ const failed = tool("err", { isError: true, output: "Upload failed" });+ expect(splitConversationTurn([tool("a"), reply("done", "Ready."), failed]).after).toEqual([failed]);+ });++ it("treats a tool-only turn as work", () => {+ expect(splitConversationTurn([tool("a")])).toEqual({ work: [tool("a")], answer: [], after: [] });+ });});diff --git a/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.tsx b/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.tsxindex 5f1d3652b6..46149b49df 100644--- a/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.tsx+++ b/jarvis/ui/web/frontend/src/components/agentchat/WorkTrace.tsx@@ -308,7 +308,7 @@ function ConversationWorkFold({ durationMs, attention, children }: {return (<div className="min-w-0" data-testid="conversation-work-fold" data-open={open ? "true" : "false"}><button type="button" aria-expanded={open} aria-controls={id}- className="group/fold mb-1 inline-flex max-w-full items-center gap-1 rounded-md py-0.5 pr-1.5 text-left text-xs leading-5 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"+ className="group/fold mb-1 inline-flex max-w-full items-center gap-1 rounded-md px-1.5 py-1 text-left text-xs leading-5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"onClick={() => setOpen(!open)}><ChevronRight aria-hidden className={cn("h-3 w-3 shrink-0 opacity-70 transition-transform group-hover/fold:opacity-100", open && "rotate-90")} /><span className="truncate">{label}</span>@@ -318,6 +318,33 @@ function ConversationWorkFold({ durationMs, attention, children }: {);}+function TraceGroups({ groups, live, status, onDecide, renderText, conversation }: {+ groups: Group[]; live: boolean; status: TurnStatus; onDecide?: Decide;+ renderText?: (text: string, id: string) => ReactNode; conversation: boolean;+}) {+ const t = useT();+ return groups.map(group => {+ const first = group.blocks[0];+ if (group.family === "activity" && group.blocks.length > 1) return <div key={group.id} className={cn("py-1", conversation && "w-full max-w-xl")} data-trace-summary>+ <Disclosure label={<ActivitySummary blocks={group.blocks} live={live} />}+ icon={<ActivityIcon blocks={group.blocks} live={live} />} initiallyOpen={live}+ forced={live}>+ {group.blocks.map(block => block.kind === "tool"+ ? <TraceTool key={block.callId} block={block} status={status} onDecide={onDecide} />+ : block.kind === "reasoning" ? <ReasoningTrace key={block.id} block={block} turnLive={live} compact /> : null)}+ </Disclosure>+ </div>;+ if (group.blocks.length > 1) return <Disclosure key={group.id}+ label={t(`work_trace.group_${group.family}`).replace("{count}", String(group.blocks.length))}+ icon={<Check aria-hidden className={iconClass} />} initiallyOpen={live}>+ {group.blocks.map(block => <TraceTool key={(block as ToolBlock).callId} block={block as ToolBlock} status={status} onDecide={onDecide} />)}+ </Disclosure>;+ if (first.kind === "tool") return <div key={group.id} className={conversation ? "w-full max-w-xl py-1 text-xs [&_button]:text-xs" : undefined}><TraceTool block={first} status={status} onDecide={onDecide} /></div>;+ if (first.kind === "reasoning") return <div key={group.id} className={conversation ? "w-full max-w-xl text-xs [&_button]:text-xs" : undefined}><ReasoningTrace block={first} turnLive={live} compact={conversation} /></div>;+ return first.text.trim() ? <div key={group.id} className={cn("min-w-0 py-2", conversation && "w-fit max-w-[min(85%,42rem)] rounded-2xl rounded-bl-md bg-secondary px-4 py-2.5")}>{renderText ? renderText(first.text, first.id) : <div className="prose prose-sm max-w-none text-foreground dark:prose-invert [overflow-wrap:anywhere]"><ChatMarkdown text={first.text} /></div>}</div> : null;+ });+}+export function WorkTrace({ blocks, status, startedMs, durationMs, error, onDecide, renderText, className, receipt, completionLabel, conversation = false }: {blocks: TurnBlock[]; status: TurnStatus; startedMs: number; durationMs: number | null; error?: string | null;onDecide?: Decide; renderText?: (text: string, id: string) => ReactNode; className?: string;@@ -326,31 +353,22 @@ export function WorkTrace({ blocks, status, startedMs, durationMs, error, onDeciconst t = useT();const live = status === "running";const elapsed = useClock(startedMs, live);- const groups = useMemo(() => conversation ? groupConversationTrace(blocks) : groupActivityTrace(blocks), [blocks, conversation]);+ const split = useMemo(() => conversation && !live ? splitConversationTurn(blocks) : null, [blocks, conversation, live]);+ const fold = split && hasFoldableWork(split.work) ? split : null;+ const groups = useMemo(() => conversation ? groupConversationTrace(fold ? fold.work : blocks) : groupActivityTrace(blocks), [blocks, conversation, fold]);+ const restGroups = useMemo(() => fold ? groupConversationTrace([...fold.answer, ...fold.after]) : null, [fold]);const pending = blocks.some(block => block.kind === "tool" && block.approval?.decision === null);const outcome = pending ? "approval" : live ? "working" : status === "error" ? "failed" : status === "cancelled" ? "stopped" : "done";const Icon = pending ? ShieldQuestion : live ? CircleDashed : status === "error" ? CircleAlert : Check;+ const groupProps = { live, status, onDecide, renderText, conversation };return <div className={cn("min-w-0 space-y-0.5", className)} data-testid="work-trace" data-state={status}>- {groups.map(group => {- const first = group.blocks[0];- if (group.family === "activity" && group.blocks.length > 1) return <div key={group.id} className={cn("py-1", conversation && "w-full max-w-xl")} data-trace-summary>- <Disclosure label={<ActivitySummary blocks={group.blocks} live={live} />}- icon={<ActivityIcon blocks={group.blocks} live={live} />} initiallyOpen={live}- forced={live}>- {group.blocks.map(block => block.kind === "tool"- ? <TraceTool key={block.callId} block={block} status={status} onDecide={onDecide} />- : block.kind === "reasoning" ? <ReasoningTrace key={block.id} block={block} turnLive={live} compact /> : null)}- </Disclosure>- </div>;- if (group.blocks.length > 1) return <Disclosure key={group.id}- label={t(`work_trace.group_${group.family}`).replace("{count}", String(group.blocks.length))}- icon={<Check aria-hidden className={iconClass} />} initiallyOpen={live}>- {group.blocks.map(block => <TraceTool key={(block as ToolBlock).callId} block={block as ToolBlock} status={status} onDecide={onDecide} />)}- </Disclosure>;- if (first.kind === "tool") return <div key={group.id} className={conversation ? "w-full max-w-xl py-1 text-xs [&_button]:text-xs" : undefined}><TraceTool block={first} status={status} onDecide={onDecide} /></div>;- if (first.kind === "reasoning") return <div key={group.id} className={conversation ? "w-full max-w-xl text-xs [&_button]:text-xs" : undefined}><ReasoningTrace block={first} turnLive={live} compact={conversation} /></div>;- return first.text.trim() ? <div key={group.id} className={cn("min-w-0 py-2", conversation && "w-fit max-w-[min(85%,42rem)] rounded-2xl rounded-bl-md bg-secondary px-4 py-2.5")}>{renderText ? renderText(first.text, first.id) : <div className="prose prose-sm max-w-none text-foreground dark:prose-invert [overflow-wrap:anywhere]"><ChatMarkdown text={first.text} /></div>}</div> : null;- })}+ {fold ? <ConversationWorkFold durationMs={durationMs} attention={fold.work.filter(isAttentionBlock).map(block =>+ <div key={block.callId} className="w-full max-w-xl py-1 text-xs [&_button]:text-xs">+ <TraceTool block={block} status={status} onDecide={onDecide} />+ </div>)}>+ <TraceGroups groups={groups} {...groupProps} />+ </ConversationWorkFold> : <TraceGroups groups={groups} {...groupProps} />}+ {restGroups ? <TraceGroups groups={restGroups} {...groupProps} /> : null}{error ? <p role="alert" className="py-2 text-sm text-destructive [overflow-wrap:anywhere]">{error}</p> : null}<div role="status" aria-live="polite" className={cn("flex flex-wrap items-center gap-2 text-xs text-muted-foreground", conversation ? "px-1 pb-2 pt-1" : "border-t border-border pt-3", status === "error" && "text-destructive")}><Icon aria-hidden className={cn("h-3.5 w-3.5", live && !pending && "motion-safe:animate-spin")} />diff --git a/jarvis/ui/web/frontend/src/components/society/chat/ChatActivity.test.tsx b/jarvis/ui/web/frontend/src/components/society/chat/ChatActivity.test.tsxindex 1a6b14cc11..8ef7b0cdda 100644--- a/jarvis/ui/web/frontend/src/components/society/chat/ChatActivity.test.tsx+++ b/jarvis/ui/web/frontend/src/components/society/chat/ChatActivity.test.tsx@@ -57,6 +57,19 @@ it("keeps live conversation tool rows left-aligned instead of centering them", (expect(container.querySelectorAll(".mx-auto")).toHaveLength(0);});+it("keeps a failure visible when the surrounding work is folded", () => {+ const tool: ToolBlock = { kind: "tool", callId: "a", name: "read_file", input: { path: "report.csv" }, output: "Report contents", isError: false, durationMs: 100, approval: null, startedMs: 0 };+ render(<WorkTrace conversation status="done" startedMs={0} durationMs={2000} blocks={[+ tool,+ { ...tool, callId: "error", isError: true, output: "Upload failed" },+ { kind: "text", id: "reply", text: "I could not finish." },+ ]} />);+ expect(screen.getByText("Upload failed")).toBeTruthy();+ expect(screen.getByText("I could not finish.")).toBeTruthy();+ expect(screen.queryByText("Report contents")).toBeNull();+ expect(screen.getByRole("button", { name: "Thought for 2.0s" })).toBeTruthy();+});+it("keeps failures and approvals visible in the conversation style", () => {const base: ToolBlock = { kind: "tool", callId: "failure", name: "send_message", input: {}, output: "Delivery failed", isError: true, durationMs: 100, approval: null, startedMs: 0 };render(<WorkTrace conversation status="done" startedMs={0} durationMs={1000} blocks={[@@ -89,11 +102,42 @@ it("folds successful work between replies without swallowing an error or reorderfireEvent.click(activity);fireEvent.click(activity);rerender(<WorkTrace conversation status="done" startedMs={0} durationMs={1000} blocks={blocks} />);- expect(activity.getAttribute("aria-expanded")).toBe("false");+ expect(screen.queryByRole("button", { name: "Reading files Creating files" })).toBeNull();expect(screen.queryByRole("button", { name: /Write file/ })).toBeNull();expect(screen.getByText("Your report is ready.")).toBeTruthy();expect(screen.getByText("Upload failed")).toBeTruthy();- fireEvent.click(activity);+ fireEvent.click(screen.getByRole("button", { name: "Thought for 1.0s" }));+ fireEvent.click(screen.getByRole("button", { name: "Read files Created files" }));fireEvent.click(screen.getByRole("button", { name: /Write file/ }));expect(screen.getByText("Report contents")).toBeTruthy();});++it("does not offer a thought toggle when the turn is only a reply", () => {+ render(<WorkTrace conversation status="done" startedMs={0} durationMs={1000} blocks={[{ kind: "text", id: "a", text: "Hello." }]} />);+ expect(screen.queryByTestId("conversation-work-fold")).toBeNull();+ expect(screen.getByText("Hello.")).toBeTruthy();+});++it("hides intermediate replies behind one thought toggle once the turn completes", () => {+ const tool: ToolBlock = { kind: "tool", callId: "a", name: "read_file", input: { path: "report.csv" }, output: "Report contents", isError: false, durationMs: 100, approval: null, startedMs: 0 };+ const blocks = [+ tool,+ { kind: "text" as const, id: "think", text: "I will inspect the files first." },+ { ...tool, callId: "b", name: "list_dir" },+ { kind: "text" as const, id: "final", text: "The report is ready." },+ ];+ const { rerender } = render(<WorkTrace conversation status="running" startedMs={0} durationMs={null} blocks={blocks} />);+ expect(screen.getByText("I will inspect the files first.")).toBeTruthy();+ expect(screen.getByText("The report is ready.")).toBeTruthy();+ rerender(<WorkTrace conversation status="done" startedMs={0} durationMs={4000} blocks={blocks} />);+ expect(screen.queryByText("I will inspect the files first.")).toBeNull();+ expect(screen.queryByText("Used tools")).toBeNull();+ expect(screen.getByText("The report is ready.")).toBeTruthy();+ const toggle = screen.getByRole("button", { name: "Thought for 4.0s" });+ expect(toggle.getAttribute("aria-expanded")).toBe("false");+ fireEvent.click(toggle);+ expect(toggle.getAttribute("aria-expanded")).toBe("true");+ expect(screen.getByText("I will inspect the files first.")).toBeTruthy();+ fireEvent.click(toggle);+ expect(screen.queryByText("I will inspect the files first.")).toBeNull();+});