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(visualization): extract reasoning, spawn kind and task lanes from run transcripts

rubenluetke10-beepb2aca9dfed59
diff --git a/jarvis/ui/web/mission_graph.py b/jarvis/ui/web/mission_graph.py
index 829cdcec8b..0fcbf12021 100644
--- a/jarvis/ui/web/mission_graph.py
+++ b/jarvis/ui/web/mission_graph.py
@@ -146,6 +146,10 @@ def build_mission_graph(
calls_by_task: dict[str, int] = {}
failed_by_task: dict[str, int] = {}
for plan_step in plan_steps:
+ # Reasoning steps are the worker's own thoughts, not tool calls — the
+ # per-task call count stays a count of ACTIONS.
+ if plan_step.get("kind") == "reasoning":
+ continue
step_id = str(plan_step.get("step_id", ""))
task_id, _, _seq = step_id.partition(":")
if not task_id:
diff --git a/jarvis/ui/web/run_plan.py b/jarvis/ui/web/run_plan.py
index 852448152b..6f597084ef 100644
--- a/jarvis/ui/web/run_plan.py
+++ b/jarvis/ui/web/run_plan.py
@@ -19,6 +19,21 @@ Anti-hearsay discipline carries over too: a ``tool_use`` becomes a ``done`` or
``failed`` step only when its correlated ``tool_result`` frame was observed;
a call whose result never arrived (truncated stream, killed worker) is
reported as ``skipped`` rather than silently trusted.
+
+Steps carry a ``kind`` so the graph can draw the run the way it actually
+unfolded, not just as a chain of tool calls:
+
+* ``"reasoning"`` — the worker's own thinking/commentary between actions.
+ Consecutive thinking/text blocks collapse into ONE step per gap (a run with
+ fifty thoughts stays readable), and trailing text is never emitted as a
+ step — it IS the final answer, not a step toward it.
+* ``"spawn"`` — a tool call that launches a sub-agent (Task/Agent/…), worth
+ its own visual grammar in the graph.
+* ``"tool"`` — every other tool call.
+
+``task_key`` names the worker (task dir) a step belongs to, so a mission that
+ran several workers in parallel is drawn as parallel branches, not one
+falsely-linear chain.
"""
from __future__ import annotations
@@ -70,6 +85,12 @@ _WRITE_TOOL_NAMES: Final[frozenset[str]] = frozenset(
{"Write", "Edit", "MultiEdit", "NotebookEdit", "file_write", "write_file", "create_file"}
)
+# Tool names (lowercased) that launch a sub-agent rather than acting directly.
+# They become ``kind: "spawn"`` steps — the graph gives them branch grammar.
+_SPAWN_TOOL_NAMES: Final[frozenset[str]] = frozenset(
+ {"task", "agent", "subagent", "spawn_worker", "spawn_subagent", "dispatch_agent"}
+)
+
def _clip(text: str, cap: int) -> str:
text = " ".join(text.split())
@@ -133,6 +154,35 @@ def _walk_stream(stream_text: str, task_key: str) -> tuple[list[dict[str, Any]],
final_answer = ""
last_assistant_text = ""
seq = 0
+ # Thinking/commentary blocks observed since the last action, in order.
+ # Each entry is (is_thinking, text): the flag decides whether a TRAILING
+ # entry may still become a step (thinking yes, text no — trailing text is
+ # the final answer, and must not appear twice).
+ reasoning: list[tuple[bool, str]] = []
+
+ def _flush_reasoning(*, thinking_only: bool = False) -> None:
+ nonlocal seq
+ kept = [t for is_thinking, t in reasoning if is_thinking or not thinking_only]
+ reasoning.clear()
+ text = " ".join(kept).strip()
+ if not text:
+ return
+ steps.append(
+ {
+ "step_id": f"{task_key}:{seq}",
+ "name": _clip(text, _DETAIL_CHARS),
+ "tool_name": None,
+ "kind": "reasoning",
+ "task_key": task_key,
+ # Reasoning has no result frame to wait for — it was observed
+ # verbatim in the stream, so it is simply "done".
+ "status": "done",
+ "output": _clip(text, _OUTPUT_CHARS),
+ "error": None,
+ "writes": [],
+ }
+ )
+ seq += 1
for raw in stream_text.splitlines():
line = raw.strip()
@@ -152,6 +202,10 @@ def _walk_stream(stream_text: str, task_key: str) -> tuple[list[dict[str, Any]],
if not isinstance(blk, dict):
continue
if blk.get("type") == "tool_use":
+ # The thoughts that led to this action become ONE step in
+ # front of it — the graph reads Think → Act, never a wall
+ # of fifty thought cards.
+ _flush_reasoning()
name = str(blk.get("name", "")).strip() or "tool"
tool_input = blk.get("input") or {}
if not isinstance(tool_input, dict):
@@ -160,6 +214,8 @@ def _walk_stream(stream_text: str, task_key: str) -> tuple[list[dict[str, Any]],
"step_id": f"{task_key}:{seq}",
"name": _tool_detail(name, tool_input) or name,
"tool_name": name,
+ "kind": "spawn" if name.lower() in _SPAWN_TOOL_NAMES else "tool",
+ "task_key": task_key,
# Anti-hearsay default — upgraded to done/failed only
# by a correlated result frame below.
"status": "skipped",
@@ -178,10 +234,15 @@ def _walk_stream(stream_text: str, task_key: str) -> tuple[list[dict[str, Any]],
tid = str(blk.get("id", "")).strip()
if tid:
pending[tid] = step
+ elif blk.get("type") == "thinking":
+ txt = str(blk.get("thinking", "")).strip()
+ if txt:
+ reasoning.append((True, txt))
elif blk.get("type") == "text":
txt = str(blk.get("text", "")).strip()
if txt:
last_assistant_text = txt
+ reasoning.append((False, txt))
elif otype == "user":
for blk in (obj.get("message", {}) or {}).get("content", []) or []:
if not isinstance(blk, dict) or blk.get("type") != "tool_result":
@@ -202,6 +263,11 @@ def _walk_stream(stream_text: str, task_key: str) -> tuple[list[dict[str, Any]],
if isinstance(res, str) and res.strip():
final_answer = res.strip()
+ # Trailing thoughts (a run that reasoned its way straight to the answer,
+ # or thought after its last action) still become a step — but trailing
+ # TEXT stays out: it is the final answer, not a step toward it.
+ _flush_reasoning(thinking_only=True)
+
if not final_answer:
final_answer = last_assistant_text
return steps, final_answer
@@ -244,11 +310,14 @@ def build_run_plan(session_dir: Path, *, utterance: str | None = None) -> dict[s
if not steps and not final_answer:
return {"plan": None, "steps": []}
- failed = sum(1 for s in steps if s["status"] == "failed")
+ # Reasoning steps are always "done" and must not dilute the verdict —
+ # "every action failed" is judged over the actions alone.
+ actions = [s for s in steps if s.get("kind") != "reasoning"]
+ failed = sum(1 for s in actions if s["status"] == "failed")
plan = {
"plan_id": session_dir.name,
"vision": utterance or "",
- "status": "failed" if failed and failed == len(steps) else "complete",
+ "status": "failed" if failed and failed == len(actions) else "complete",
"total_steps": len(steps) + dropped,
}
return {
diff --git a/tests/unit/ui/web/test_run_plan.py b/tests/unit/ui/web/test_run_plan.py
index f006f807f6..f19e6ca095 100644
--- a/tests/unit/ui/web/test_run_plan.py
+++ b/tests/unit/ui/web/test_run_plan.py
@@ -49,6 +49,20 @@ def _result(text: str) -> str:
return json.dumps({"type": "result", "result": text})
+def _assistant_blocks(*blocks: dict) -> str:
+ return json.dumps(
+ {"type": "assistant", "message": {"role": "assistant", "content": list(blocks)}}
+ )
+
+
+def _thinking(text: str) -> dict:
+ return {"type": "thinking", "thinking": text}
+
+
+def _text(text: str) -> dict:
+ return {"type": "text", "text": text}
+
+
def test_no_stream_keeps_stub_contract(tmp_path: Path) -> None:
assert build_run_plan(tmp_path) == {"plan": None, "steps": []}
@@ -89,6 +103,81 @@ def test_steps_carry_correlated_status_and_final_answer(tmp_path: Path) -> None:
assert by_tool["Read"]["status"] == "skipped"
+def test_thinking_between_actions_collapses_into_one_reasoning_step(tmp_path: Path) -> None:
+ lines = [
+ _assistant_blocks(_thinking("Plan: run the script."), _thinking("Then verify.")),
+ _tool_use("t1", "Bash", {"command": "python plot.py"}),
+ _tool_result("t1", "ok"),
+ _assistant_blocks(_thinking("Looks good, write it out.")),
+ _tool_use("t2", "Write", {"file_path": "out.md", "content": "…"}),
+ _tool_result("t2", "written"),
+ _result("Done."),
+ ]
+ (_stream_dir(tmp_path) / "stream.jsonl").write_text("\n".join(lines), encoding="utf-8")
+
+ payload = build_run_plan(tmp_path)
+
+ kinds = [(s.get("kind"), s.get("tool_name")) for s in payload["steps"]]
+ assert kinds == [
+ ("reasoning", None),
+ ("tool", "Bash"),
+ ("reasoning", None),
+ ("tool", "Write"),
+ ]
+ # Two consecutive thinking blocks became ONE step, in reading order.
+ first = payload["steps"][0]
+ assert first["name"] == "Plan: run the script. Then verify."
+ assert first["status"] == "done"
+ assert first["task_key"] == "task-1"
+
+
+def test_trailing_text_is_the_answer_never_a_reasoning_step(tmp_path: Path) -> None:
+ lines = [
+ _tool_use("t1", "Bash", {"command": "ls"}),
+ _tool_result("t1", "ok"),
+ # Thinking after the last action still counts as a step; the final
+ # text does not — it IS the answer, and must not appear twice.
+ _assistant_blocks(_thinking("Summarise for the user."), _text("Here is the list.")),
+ ]
+ (_stream_dir(tmp_path) / "stream.jsonl").write_text("\n".join(lines), encoding="utf-8")
+
+ payload = build_run_plan(tmp_path)
+
+ assert [s.get("kind") for s in payload["steps"]] == ["tool", "reasoning"]
+ assert payload["steps"][1]["name"] == "Summarise for the user."
+ assert payload["final_answer"] == "Here is the list."
+
+
+def test_spawn_tools_carry_the_spawn_kind(tmp_path: Path) -> None:
+ lines = [
+ _tool_use("t1", "Task", {"prompt": "Audit shard A", "description": "Audit shard A"}),
+ _tool_result("t1", "spawned"),
+ _tool_use("t2", "Bash", {"command": "echo hi"}),
+ _tool_result("t2", "hi"),
+ ]
+ (_stream_dir(tmp_path) / "stream.jsonl").write_text("\n".join(lines), encoding="utf-8")
+
+ payload = build_run_plan(tmp_path)
+
+ by_tool = {s["tool_name"]: s for s in payload["steps"]}
+ assert by_tool["Task"]["kind"] == "spawn"
+ assert by_tool["Bash"]["kind"] == "tool"
+
+
+def test_all_actions_failed_verdict_ignores_reasoning_steps(tmp_path: Path) -> None:
+ lines = [
+ _assistant_blocks(_thinking("Try the deploy.")),
+ _tool_use("t1", "Bash", {"command": "npm run deploy"}),
+ _tool_result("t1", "boom", is_error=True),
+ ]
+ (_stream_dir(tmp_path) / "stream.jsonl").write_text("\n".join(lines), encoding="utf-8")
+
+ payload = build_run_plan(tmp_path)
+
+ # The reasoning step is "done", but the verdict is judged over actions.
+ assert payload["plan"]["status"] == "failed"
+
+
def test_codex_stream_is_normalized_before_walking(tmp_path: Path) -> None:
lines = [
json.dumps(