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
feat(visualization): pure node-graph model for a run's step timeline
rubenluetke10-beepd923e2d6c168
diff --git a/jarvis/ui/web/frontend/src/hooks/useOutputs.ts b/jarvis/ui/web/frontend/src/hooks/useOutputs.tsindex 299b24850d..2ecb106aa0 100644--- a/jarvis/ui/web/frontend/src/hooks/useOutputs.ts+++ b/jarvis/ui/web/frontend/src/hooks/useOutputs.ts@@ -18,13 +18,15 @@ export interface PlanStep {step_id: string;name: string;status: PlanStepStatus;- output?: string;+ output?: string | null;error?: string | null;duration_s?: number;attempts?: number;tool_name?: string | null;depends_on?: string[];parallel_ok?: boolean;+ /** File paths this step wrote (write-tool calls with a confirmed target). */+ writes?: string[];}export interface PlanSummary {@@ -37,6 +39,12 @@ export interface PlanSummary {export interface PlanResponse {plan: PlanSummary | null;steps: PlanStep[];+ /** The worker's terminal reply, when the archived stream recorded one. */+ final_answer?: string | null;+ /** True when the stream was larger than the backend's bounded read. */+ truncated?: boolean;+ /** Steps beyond the backend's cap — stated so the timeline reads honest. */+ dropped_steps?: number;}/** Must stay in parity with `OUTPUT_STATUSES` in `outputs_routes.py`. */diff --git a/jarvis/ui/web/frontend/src/lib/runGraph.test.ts b/jarvis/ui/web/frontend/src/lib/runGraph.test.tsnew file mode 100644index 0000000000..49f8deb65d--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/runGraph.test.ts@@ -0,0 +1,190 @@+/**+ * The run graph model — what becomes a node, what connects to what.+ *+ * Contracts worth pinning:+ * - the main track is start → steps in order → result, each linked to its+ * predecessor, so the flow reads left to right like a workflow editor,+ * - an artifact hangs off the step that wrote it (matched by filename),+ * and off the result/start node when no step claims it — an archived run+ * with no surviving stream still gets a complete, honest graph,+ * - a live run's newest unconfirmed call renders as "running", while the+ * same shape in a finished run stays "skipped" (anti-hearsay).+ */+import { describe, expect, it } from "vitest";++import type { ArtifactSummary, PlanStep } from "@/hooks/useOutputs";+import { buildRunGraph, edgePath, NODE_H, NODE_W } from "@/lib/runGraph";++function step(over: Partial<PlanStep> & { step_id: string }): PlanStep {+ return {+ name: "do something",+ status: "done",+ tool_name: "Bash",+ ...over,+ };+}++function file(path: string): ArtifactSummary {+ return { path, size: 10, mtime: 1, is_text: false, preview: null };+}++describe("buildRunGraph", () => {+ it("lays the main track start → steps → result, connected in order", () => {+ const graph = buildRunGraph({+ slug: "run-1",+ utterance: "draw a chart",+ runStatus: "success",+ plan: {+ plan: { plan_id: "run-1", vision: "draw a chart", status: "complete" },+ steps: [step({ step_id: "a" }), step({ step_id: "b" })],+ final_answer: "Chart drawn.",+ },+ files: [],+ });++ expect(graph.nodes.map((n) => n.id)).toEqual([+ "start",+ "step:a",+ "step:b",+ "result",+ ]);+ expect(graph.edges.map((e) => `${e.from}->${e.to}`)).toEqual([+ "start->step:a",+ "step:a->step:b",+ "step:b->result",+ ]);+ // One row: the main track shares a y, x strictly increases.+ const [s, a, b, r] = graph.nodes;+ expect(new Set([s.y, a.y, b.y, r.y]).size).toBe(1);+ expect(a.x).toBeGreaterThan(s.x);+ expect(r.x).toBeGreaterThan(b.x);+ });++ it("hangs an artifact off the step that wrote it, matched by filename", () => {+ const graph = buildRunGraph({+ slug: "run-1",+ runStatus: "success",+ plan: {+ plan: { plan_id: "run-1", vision: "", status: "complete" },+ steps: [+ step({ step_id: "a", tool_name: "Write", writes: ["out/chart.png"] }),+ step({ step_id: "b" }),+ ],+ final_answer: "done",+ },+ files: [file("tasks/t1/artifacts/files/out/chart.png")],+ });++ const edge = graph.edges.find((e) =>+ e.to.startsWith("artifact:"),+ );+ expect(edge?.from).toBe("step:a");+ // Second track: the artifact sits below the main track.+ const artifact = graph.nodes.find((n) => n.kind === "artifact");+ expect(artifact!.y).toBeGreaterThan(graph.nodes[0].y);+ });++ it("gives an unclaimed artifact to the result node, or start without one", () => {+ const withResult = buildRunGraph({+ slug: "run-1",+ runStatus: "success",+ plan: {+ plan: { plan_id: "run-1", vision: "", status: "complete" },+ steps: [step({ step_id: "a" })],+ final_answer: "done",+ },+ files: [file("tasks/t1/artifacts/files/report.md")],+ });+ expect(+ withResult.edges.find((e) => e.to.startsWith("artifact:"))?.from,+ ).toBe("result");++ // Pre-feature archive: no plan at all — the deliverables still show.+ const bare = buildRunGraph({+ slug: "run-old",+ runStatus: "unknown",+ plan: { plan: null, steps: [] },+ files: [file("tasks/t1/artifacts/files/report.md")],+ });+ expect(bare.nodes.map((n) => n.kind)).toEqual(["start", "artifact"]);+ expect(bare.edges[0]).toMatchObject({ from: "start" });+ });++ it("shows the newest unconfirmed call as running only while the run lives", () => {+ const plan = {+ plan: { plan_id: "r", vision: "", status: "complete" },+ steps: [+ step({ step_id: "a", status: "skipped" as const }),+ step({ step_id: "b", status: "skipped" as const }),+ ],+ };+ const live = buildRunGraph({ slug: "r", runStatus: "running", plan, files: [] });+ expect(live.nodes.find((n) => n.id === "step:b")?.status).toBe("running");+ expect(live.nodes.find((n) => n.id === "step:a")?.status).toBe("skipped");++ const done = buildRunGraph({ slug: "r", runStatus: "error", plan, files: [] });+ expect(done.nodes.find((n) => n.id === "step:b")?.status).toBe("skipped");+ });++ it("marks the edge into a failed step so the track can alarm", () => {+ const graph = buildRunGraph({+ slug: "r",+ runStatus: "error",+ plan: {+ plan: { plan_id: "r", vision: "", status: "failed" },+ steps: [step({ step_id: "a", status: "failed", error: "boom" })],+ },+ files: [],+ });+ expect(graph.edges[0].failed).toBe(true);+ });++ it("sizes the canvas to hold every node plus padding", () => {+ const graph = buildRunGraph({+ slug: "r",+ runStatus: "success",+ plan: {+ plan: { plan_id: "r", vision: "", status: "complete" },+ steps: [step({ step_id: "a" })],+ final_answer: "ok",+ },+ files: [file("tasks/t1/artifacts/files/a.md")],+ });+ for (const node of graph.nodes) {+ expect(node.x + NODE_W).toBeLessThanOrEqual(graph.width);+ expect(node.y + NODE_H).toBeLessThanOrEqual(graph.height);+ }+ });+});++describe("edgePath", () => {+ it("connects same-row nodes port to port, horizontally", () => {+ const graph = buildRunGraph({+ slug: "r",+ runStatus: "success",+ plan: {+ plan: { plan_id: "r", vision: "", status: "complete" },+ steps: [step({ step_id: "a" })],+ final_answer: "ok",+ },+ files: [],+ });+ const [from, to] = graph.nodes;+ const path = edgePath(from, to);+ expect(path).toContain(`M ${from.x + NODE_W} ${from.y + NODE_H / 2}`);+ expect(path.endsWith(`${to.x} ${to.y + NODE_H / 2}`)).toBe(true);+ });++ it("connects cross-row nodes bottom to top, vertically", () => {+ const graph = buildRunGraph({+ slug: "r",+ runStatus: "success",+ plan: { plan: null, steps: [] },+ files: [file("tasks/t1/artifacts/files/a.md")],+ });+ const [start, artifact] = graph.nodes;+ const path = edgePath(start, artifact);+ expect(path).toContain(`M ${start.x + NODE_W / 2} ${start.y + NODE_H}`);+ expect(path.endsWith(`${artifact.x + NODE_W / 2} ${artifact.y}`)).toBe(true);+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/runGraph.ts b/jarvis/ui/web/frontend/src/lib/runGraph.tsnew file mode 100644index 0000000000..d5b4026de5--- /dev/null+++ b/jarvis/ui/web/frontend/src/lib/runGraph.ts@@ -0,0 +1,256 @@+/**+ * The node-graph model behind the Visualization section.+ *+ * A run is drawn the way a workflow editor would draw it: what was asked+ * (start node), what the worker actually did (one node per tool call, in+ * order, on the main track), what it said at the end (result node), and what+ * it left behind (one node per deliverable, on a second track, connected to+ * the step that wrote it). The data comes from two reads the app already+ * makes — `/api/outputs/{slug}/plan` and `/api/outputs/{slug}/artifacts` —+ * so a run archived long before this feature existed still gets its graph.+ *+ * Everything here is pure: build the nodes, lay them out, hand back+ * positions. The view only renders. That split is what keeps the layout+ * testable without a DOM and lets the numbers below be tuned in one place.+ */++import type {+ ArtifactSummary,+ OutputStatus,+ PlanResponse,+ PlanStep,+} from "@/hooks/useOutputs";++export type RunNodeKind = "start" | "step" | "result" | "artifact";++/** Node state, unified across kinds so one dot component can render them. */+export type RunNodeStatus = "done" | "failed" | "skipped" | "running" | "none";++export interface RunGraphNode {+ /** Stable id — selection key, React key and edge endpoint. */+ id: string;+ kind: RunNodeKind;+ /** Card headline (tool name, "Request", "Result", filename). */+ title: string;+ /** Card detail line (command, path, answer preview) — may be empty. */+ subtitle: string;+ status: RunNodeStatus;+ /** For `step` nodes: the full backend step, for the inspector. */+ step?: PlanStep;+ /** For `artifact` nodes: the listed file, for preview + actions. */+ artifact?: ArtifactSummary;+ /** Layout position (top-left corner) in unscaled canvas pixels. */+ x: number;+ y: number;+}++export interface RunGraphEdge {+ id: string;+ from: string;+ to: string;+ /** Whether the edge leads to a failed node — drawn in the alarm colour. */+ failed: boolean;+}++export interface RunGraph {+ nodes: RunGraphNode[];+ edges: RunGraphEdge[];+ /** Unscaled canvas extents, padding included. */+ width: number;+ height: number;+ /** Steps the backend dropped beyond its cap — stated, never hidden. */+ droppedSteps: number;+}++/* Layout constants — one place to tune the whole canvas. */+export const NODE_W = 216;+export const NODE_H = 76;+const GAP_X = 56;+const ROW_GAP = 72;+const PADDING = 24;++/** Last path segment, tolerant of both separators. */+function basename(path: string): string {+ const parts = path.split(/[\\/]/);+ return parts[parts.length - 1] || path;+}++/**+ * The step that produced this artifact, by write-target basename.+ *+ * The worker wrote to a worktree path ("report/chart.png", often absolute)+ * while the archive lists "tasks/<id>/artifacts/files/report/chart.png" —+ * the two only reliably share their filename. When several steps wrote the+ * same name, the LAST one wins (it is the surviving content).+ */+function findSourceStep(steps: PlanStep[], artifactPath: string): PlanStep | null {+ const name = basename(artifactPath);+ for (let i = steps.length - 1; i >= 0; i -= 1) {+ const writes = steps[i].writes ?? [];+ if (writes.some((target) => basename(target) === name)) return steps[i];+ }+ return null;+}++function stepStatus(+ step: PlanStep,+ isLastUnconfirmed: boolean,+ runStatus: OutputStatus | undefined,+): RunNodeStatus {+ if (step.status === "failed") return "failed";+ if (step.status === "done") return "done";+ // The backend reports an uncorrelated tool call as "skipped" (its result+ // frame never arrived). While the mission is still live, the newest such+ // call is not lost — it is the one in flight right now.+ if (isLastUnconfirmed && runStatus === "running") return "running";+ return "skipped";+}++export interface RunGraphInput {+ slug: string;+ utterance?: string;+ runStatus?: OutputStatus;+ plan: PlanResponse | undefined;+ files: ArtifactSummary[];+}++/** Build the fully laid-out graph for one run. Pure. */+export function buildRunGraph(input: RunGraphInput): RunGraph {+ const steps = input.plan?.steps ?? [];+ const finalAnswer = input.plan?.final_answer ?? null;+ const nodes: RunGraphNode[] = [];+ const edges: RunGraphEdge[] = [];++ const lastUnconfirmed = [...steps].reverse().find((s) => s.status === "skipped");++ /* Main track: start → steps → result. */+ let x = PADDING;+ const mainY = PADDING;++ nodes.push({+ id: "start",+ kind: "start",+ title: input.utterance?.trim() || input.slug,+ subtitle: input.slug,+ status:+ input.runStatus === "running"+ ? "running"+ : input.runStatus === "error"+ ? "failed"+ : "none",+ x,+ y: mainY,+ });+ let previousId = "start";+ x += NODE_W + GAP_X;++ for (const step of steps) {+ const id = `step:${step.step_id}`;+ const status = stepStatus(step, step === lastUnconfirmed, input.runStatus);+ nodes.push({+ id,+ kind: "step",+ title: step.tool_name || step.name,+ subtitle: step.tool_name && step.name !== step.tool_name ? step.name : "",+ status,+ step,+ x,+ y: mainY,+ });+ edges.push({+ id: `${previousId}->${id}`,+ from: previousId,+ to: id,+ failed: status === "failed",+ });+ previousId = id;+ x += NODE_W + GAP_X;+ }++ /* The result node closes the track whenever there is anything to close it+ * with — an answer, or a terminal run outcome worth naming. */+ const terminal =+ input.runStatus === "success" ||+ input.runStatus === "error" ||+ input.runStatus === "cancelled";+ if (finalAnswer || (steps.length > 0 && terminal)) {+ nodes.push({+ id: "result",+ kind: "result",+ title: "result",+ subtitle: finalAnswer ?? "",+ status: input.runStatus === "error" ? "failed" : "done",+ x,+ y: mainY,+ });+ edges.push({+ id: `${previousId}->result`,+ from: previousId,+ to: "result",+ failed: input.runStatus === "error",+ });+ }+ const hasResult = nodes[nodes.length - 1].id === "result";++ /* Deliverables track: one node per archived file, connected to the step+ * that wrote it (result/start node when no step claims it). */+ const artifactY = mainY + NODE_H + ROW_GAP;+ let artifactX = PADDING;+ for (const file of input.files) {+ const id = `artifact:${file.path}`;+ const source = findSourceStep(steps, file.path);+ const from = source ? `step:${source.step_id}` : hasResult ? "result" : "start";+ nodes.push({+ id,+ kind: "artifact",+ title: basename(file.path),+ subtitle: file.path,+ status: "none",+ artifact: file,+ x: artifactX,+ y: artifactY,+ });+ edges.push({ id: `${from}->${id}`, from, to: id, failed: false });+ artifactX += NODE_W + GAP_X;+ }++ const width =+ Math.max(...nodes.map((n) => n.x + NODE_W), PADDING + NODE_W) + PADDING;+ const height =+ Math.max(...nodes.map((n) => n.y + NODE_H), PADDING + NODE_H) + PADDING;++ return {+ nodes,+ edges,+ width,+ height,+ droppedSteps: input.plan?.dropped_steps ?? 0,+ };+}++/**+ * The SVG path of one edge, n8n-style.+ *+ * Same-row edges leave the source's right port and enter the target's left+ * port with a horizontal S-curve; cross-row edges leave the source's bottom+ * and enter the target's top with a vertical one. Ports, not centers: an edge+ * that visibly leaves a card edge is what makes the cards read as connected+ * nodes rather than decorated boxes.+ */+export function edgePath(from: RunGraphNode, to: RunGraphNode): string {+ if (from.y === to.y) {+ const x1 = from.x + NODE_W;+ const y1 = from.y + NODE_H / 2;+ const x2 = to.x;+ const y2 = to.y + NODE_H / 2;+ const bend = Math.max(24, (x2 - x1) / 2);+ return `M ${x1} ${y1} C ${x1 + bend} ${y1}, ${x2 - bend} ${y2}, ${x2} ${y2}`;+ }+ const downward = to.y > from.y;+ const x1 = from.x + NODE_W / 2;+ const y1 = downward ? from.y + NODE_H : from.y;+ const x2 = to.x + NODE_W / 2;+ const y2 = downward ? to.y : to.y + NODE_H;+ const bend = Math.max(28, Math.abs(y2 - y1) / 2) * (downward ? 1 : -1);+ return `M ${x1} ${y1} C ${x1} ${y1 + bend}, ${x2} ${y2 - bend}, ${x2} ${y2}`;+}