@puzzmo/cli 1.0.71 → 1.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/lib/agents/claude.d.ts +2 -2
  2. package/lib/agents/claude.js +67 -16
  3. package/lib/agents/claude.js.map +1 -1
  4. package/lib/agents/codex.js +12 -1
  5. package/lib/agents/codex.js.map +1 -1
  6. package/lib/agents/copilot.js +10 -1
  7. package/lib/agents/copilot.js.map +1 -1
  8. package/lib/agents/gemini.js +9 -1
  9. package/lib/agents/gemini.js.map +1 -1
  10. package/lib/agents/index.d.ts +1 -1
  11. package/lib/agents/stream-json-cli.d.ts +5 -4
  12. package/lib/agents/stream-json-cli.js +29 -4
  13. package/lib/agents/stream-json-cli.js.map +1 -1
  14. package/lib/agents/types.d.ts +15 -0
  15. package/lib/commands/game/create.js +46 -18
  16. package/lib/commands/game/create.js.map +1 -1
  17. package/lib/commands/game/seedImport.d.ts +13 -0
  18. package/lib/commands/game/seedImport.js +25 -0
  19. package/lib/commands/game/seedImport.js.map +1 -0
  20. package/lib/download/page-downloader.js +20 -7
  21. package/lib/download/page-downloader.js.map +1 -1
  22. package/lib/skills/context.d.ts +6 -0
  23. package/lib/skills/context.js +74 -0
  24. package/lib/skills/context.js.map +1 -0
  25. package/lib/skills/mcp-client.d.ts +5 -0
  26. package/lib/skills/mcp-client.js +21 -0
  27. package/lib/skills/mcp-client.js.map +1 -1
  28. package/lib/skills/registry.d.ts +24 -3
  29. package/lib/skills/registry.js +47 -11
  30. package/lib/skills/registry.js.map +1 -1
  31. package/lib/skills/runner.d.ts +3 -6
  32. package/lib/skills/runner.js +45 -94
  33. package/lib/skills/runner.js.map +1 -1
  34. package/lib/skills/step.d.ts +25 -0
  35. package/lib/skills/step.js +29 -0
  36. package/lib/skills/step.js.map +1 -0
  37. package/lib/tui/pipeline.d.ts +3 -1
  38. package/lib/tui/pipeline.js +138 -65
  39. package/lib/tui/pipeline.js.map +1 -1
  40. package/lib/util/duration.d.ts +7 -0
  41. package/lib/util/duration.js +25 -0
  42. package/lib/util/duration.js.map +1 -0
  43. package/lib/util/exec.d.ts +15 -3
  44. package/lib/util/exec.js +37 -7
  45. package/lib/util/exec.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/agents/__fixtures__/README.md +1 -0
  48. package/src/agents/__fixtures__/claude-bash.jsonl +114 -0
  49. package/src/agents/claude.ts +64 -16
  50. package/src/agents/codex.ts +12 -1
  51. package/src/agents/copilot.ts +10 -1
  52. package/src/agents/gemini.ts +9 -1
  53. package/src/agents/index.ts +1 -1
  54. package/src/agents/parse-line.test.ts +40 -6
  55. package/src/agents/stream-json-cli.ts +32 -8
  56. package/src/agents/types.ts +16 -0
  57. package/src/commands/game/create.ts +47 -18
  58. package/src/commands/game/seedImport.ts +30 -0
  59. package/src/download/page-downloader.ts +22 -7
  60. package/src/skills/context.ts +75 -0
  61. package/src/skills/mcp-client.ts +24 -0
  62. package/src/skills/registry.ts +66 -11
  63. package/src/skills/runner.ts +52 -103
  64. package/src/skills/step.ts +47 -0
  65. package/src/tui/pipeline.ts +141 -61
  66. package/src/util/duration.test.ts +37 -0
  67. package/src/util/duration.ts +25 -0
  68. package/src/util/exec.ts +40 -7
  69. package/templates/minesweeper/README.md +3 -1
  70. package/templates/minesweeper/package.json +3 -1
@@ -0,0 +1,114 @@
1
+ {"type": "system", "subtype": "init", "cwd": "/tmp/game", "session_id": "a1b2c3d4", "tools": ["Bash", "Read", "Write", "Edit"], "model": "claude-haiku-4-5-20251001", "permissionMode": "bypassPermissions", "terminal_slash_commands": ["doctor", "color"], "apiKeySource": "none", "claude_code_version": "2.1.234", "plugins": [{"name": "claude-opus-4-5-migration", "path": "/home/orta/.claude/plugins/cache/claude-code-plugins/claude-opus-4-5-migration/1.0.0", "source": "claude-opus-4-5-migration@claude-code-plugins", "version": "1.0.0"}, {"name": "rust-analyzer-lsp", "path": "/home/orta/.claude/plugins/cache/claude-plugins-official/rust-analyzer-lsp/1.0.0", "source": "rust-analyzer-lsp@claude-plugins-official", "version": "1.0.0"}, {"name": "ralph-loop", "path": "/home/orta/.claude/plugins/cache/claude-plugins-official/ralph-loop/1.0.0", "source": "ralph-loop@claude-plugins-official", "version": "1.0.0"}], "capabilities": ["interrupt_receipt_v1", "interrupt_cancel_queued_v1", "msg_lifecycle_v1"], "analytics_disabled": true, "product_feedback_disabled": false, "uuid": "u-0000", "memory_paths": {"auto": "/home/orta/.claude/projects/-tmp-claude-1000--home-orta-dev-puzmo-app2-5f22686a-33f3-4f16-8404-c8af9d3652ae-scratchpad-capture/memory/"}, "fast_mode_state": "off", "fast_mode_disabled_reason": "unknown"}
2
+ {"type": "system", "subtype": "status", "status": "requesting", "uuid": "u-0000", "session_id": "a1b2c3d4"}
3
+ {"type": "rate_limit_event", "rate_limit_info": {"status": "allowed", "resetsAt": 1787245200, "rateLimitType": "five_hour", "overageStatus": "rejected", "overageDisabledReason": "org_level_disabled", "isUsingOverage": false}, "uuid": "u-0000", "session_id": "a1b2c3d4"}
4
+ {"type": "stream_event", "event": {"type": "message_start", "message": {"model": "claude-haiku-4-5-20251001", "id": "msg_011CeE76xncc73g6fyzQYB4E", "type": "message", "role": "assistant", "content": [], "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 10, "cache_creation_input_tokens": 27540, "cache_read_input_tokens": 0, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 27540}, "output_tokens": 3, "service_tier": "standard", "inference_geo": "not_available"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000", "ttft_ms": 1014}
5
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 0, "content_block": {"type": "thinking", "thinking": "", "signature": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
6
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 4, "estimated_tokens_delta": 4, "uuid": "u-0000", "session_id": "a1b2c3d4"}
7
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "The user wants", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
8
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 40, "estimated_tokens_delta": 36, "uuid": "u-0000", "session_id": "a1b2c3d4"}
9
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " me to:\n1. Run 'ls -la' and 'node --version' in parallel\n2. Write a file notes.txt containing the node version\n3. Run a command that fails: 'cat", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
10
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 72, "estimated_tokens_delta": 32, "uuid": "u-0000", "session_id": "a1b2c3d4"}
11
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " /nope/missing.txt'\n\nThey want me to be brief.\n\nLet me start by running the two commands in parallel using the Bash tool. I can", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
12
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 87, "estimated_tokens_delta": 15, "uuid": "u-0000", "session_id": "a1b2c3d4"}
13
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " make two calls simultaneously since they're independent.", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
14
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 156, "estimated_tokens_delta": 69, "uuid": "u-0000", "session_id": "a1b2c3d4"}
15
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "signature_delta", "signature": "sig-trimmed"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
16
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "The user wants me to:\n1. Run 'ls -la' and 'node --version' in parallel\n2. Write a file notes.txt containing the node version\n3. Run a command that fails: 'cat /nope/missing.txt'\n\nThey want me to be brief.\n\nLet me start by running the two commands in parallel using the Bash tool. I can make two calls simultaneously since they're independent.", "signature": "sig-trimmed"}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:44.709Z", "request_id": "req_0000"}
17
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 0}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
18
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 1, "content_block": {"type": "tool_use", "id": "toolu_SR34ue", "name": "Bash", "input": {}, "caller": {"type": "direct"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
19
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
20
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"com"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
21
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "man"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
22
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_SR34ue", "name": "Bash", "input": {"command": "ls -la", "description": "List files in current directory"}, "caller": {"type": "direct"}}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:45.411Z", "request_id": "req_0000"}
23
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 1}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
24
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 2, "content_block": {"type": "tool_use", "id": "toolu_Rsvgcm", "name": "Bash", "input": {}, "caller": {"type": "direct"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
25
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 2, "delta": {"type": "input_json_delta", "partial_json": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
26
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 2, "delta": {"type": "input_json_delta", "partial_json": "{\"com"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
27
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 2, "delta": {"type": "input_json_delta", "partial_json": "mand\": \"n"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
28
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_Rsvgcm", "name": "Bash", "input": {"command": "node --version", "description": "Get node version"}, "caller": {"type": "direct"}}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:45.486Z", "request_id": "req_0000"}
29
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 2}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
30
+ {"type": "stream_event", "event": {"type": "message_delta", "delta": {"stop_reason": "tool_use", "stop_sequence": null, "stop_details": null}, "context_management": {"applied_edits": []}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
31
+ {"type": "stream_event", "event": {"type": "message_stop"}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
32
+ {"type": "user", "message": {"role": "user", "content": [{"tool_use_id": "toolu_SR34ue", "type": "tool_result", "content": "(Bash completed with no output)", "is_error": false}]}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:45.882Z", "tool_use_result": {"stdout": "", "stderr": "", "interrupted": false, "isImage": false, "noOutputExpected": false}}
33
+ {"type": "user", "message": {"role": "user", "content": [{"tool_use_id": "toolu_Rsvgcm", "type": "tool_result", "content": "v24.19.0", "is_error": false}]}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:45.885Z", "tool_use_result": {"stdout": "v24.19.0", "stderr": "", "interrupted": false, "isImage": false, "noOutputExpected": false}}
34
+ {"type": "system", "subtype": "status", "status": "requesting", "uuid": "u-0000", "session_id": "a1b2c3d4"}
35
+ {"type": "stream_event", "event": {"type": "message_start", "message": {"model": "claude-haiku-4-5-20251001", "id": "msg_011CeE77CVcpZH3v8fWXTKjC", "type": "message", "role": "assistant", "content": [], "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 8, "cache_creation_input_tokens": 1449, "cache_read_input_tokens": 27540, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 1449}, "output_tokens": 1, "service_tier": "standard", "inference_geo": "not_available"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000", "ttft_ms": 833}
36
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 0, "content_block": {"type": "thinking", "thinking": "", "signature": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
37
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 1, "estimated_tokens_delta": 1, "uuid": "u-0000", "session_id": "a1b2c3d4"}
38
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "Good", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
39
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 2, "estimated_tokens_delta": 1, "uuid": "u-0000", "session_id": "a1b2c3d4"}
40
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": ",", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
41
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 3, "estimated_tokens_delta": 1, "uuid": "u-0000", "session_id": "a1b2c3d4"}
42
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " I", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
43
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 4, "estimated_tokens_delta": 1, "uuid": "u-0000", "session_id": "a1b2c3d4"}
44
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " got", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
45
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 7, "estimated_tokens_delta": 3, "uuid": "u-0000", "session_id": "a1b2c3d4"}
46
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " the node", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
47
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 9, "estimated_tokens_delta": 2, "uuid": "u-0000", "session_id": "a1b2c3d4"}
48
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " version", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
49
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 10, "estimated_tokens_delta": 1, "uuid": "u-0000", "session_id": "a1b2c3d4"}
50
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": ":", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
51
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 26, "estimated_tokens_delta": 16, "uuid": "u-0000", "session_id": "a1b2c3d4"}
52
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " v24.19.0. The ls -la had no output (probably empty directory", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
53
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 47, "estimated_tokens_delta": 21, "uuid": "u-0000", "session_id": "a1b2c3d4"}
54
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "). Now I need to write the node version to notes.txt, then run the failing command", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
55
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 48, "estimated_tokens_delta": 1, "uuid": "u-0000", "session_id": "a1b2c3d4"}
56
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": ".", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
57
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 114, "estimated_tokens_delta": 66, "uuid": "u-0000", "session_id": "a1b2c3d4"}
58
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "signature_delta", "signature": "sig-trimmed"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
59
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "Good, I got the node version: v24.19.0. The ls -la had no output (probably empty directory). Now I need to write the node version to notes.txt, then run the failing command.", "signature": "sig-trimmed"}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:47.895Z", "request_id": "req_0000"}
60
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 0}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
61
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 1, "content_block": {"type": "tool_use", "id": "toolu_W2cjBE", "name": "Write", "input": {}, "caller": {"type": "direct"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
62
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
63
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"file_pat"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
64
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "h\": \"/"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
65
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_W2cjBE", "name": "Write", "input": {"file_path": "/tmp/game/notes.txt", "content": "v24.19.0"}, "caller": {"type": "direct"}}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:49.883Z", "request_id": "req_0000"}
66
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 1}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
67
+ {"type": "stream_event", "event": {"type": "message_delta", "delta": {"stop_reason": "tool_use", "stop_sequence": null, "stop_details": null}, "context_management": {"applied_edits": []}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
68
+ {"type": "stream_event", "event": {"type": "message_stop"}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
69
+ {"type": "user", "message": {"role": "user", "content": [{"tool_use_id": "toolu_W2cjBE", "type": "tool_result", "content": "File created successfully at: /tmp/game/notes.txt (file state is current in your context \u2014 no need to Read it back)"}]}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:49.923Z", "tool_use_result": {"type": "create", "filePath": "/tmp/game/notes.txt", "content": "v24.19.0", "structuredPatch": [], "originalFile": null, "userModified": false}}
70
+ {"type": "system", "subtype": "status", "status": "requesting", "uuid": "u-0000", "session_id": "a1b2c3d4"}
71
+ {"type": "stream_event", "event": {"type": "message_start", "message": {"model": "claude-haiku-4-5-20251001", "id": "msg_011CeE77VzqBQqmxh3ue1ytN", "type": "message", "role": "assistant", "content": [], "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 8, "cache_creation_input_tokens": 382, "cache_read_input_tokens": 28989, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 382}, "output_tokens": 3, "service_tier": "standard", "inference_geo": "not_available"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000", "ttft_ms": 937}
72
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 0, "content_block": {"type": "thinking", "thinking": "", "signature": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
73
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 3, "estimated_tokens_delta": 3, "uuid": "u-0000", "session_id": "a1b2c3d4"}
74
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "Now I need", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
75
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 21, "estimated_tokens_delta": 18, "uuid": "u-0000", "session_id": "a1b2c3d4"}
76
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " to run the failing command: 'cat /nope/missing.txt'. This should fail", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
77
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 29, "estimated_tokens_delta": 8, "uuid": "u-0000", "session_id": "a1b2c3d4"}
78
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": " since the file doesn't exist.", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
79
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 98, "estimated_tokens_delta": 69, "uuid": "u-0000", "session_id": "a1b2c3d4"}
80
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "signature_delta", "signature": "sig-trimmed"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
81
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "Now I need to run the failing command: 'cat /nope/missing.txt'. This should fail since the file doesn't exist.", "signature": "sig-trimmed"}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:51.558Z", "request_id": "req_0000"}
82
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 0}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
83
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 1, "content_block": {"type": "tool_use", "id": "toolu_VSKbcC", "name": "Bash", "input": {}, "caller": {"type": "direct"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
84
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
85
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": "{\"command\":"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
86
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "input_json_delta", "partial_json": " \""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
87
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "tool_use", "id": "toolu_VSKbcC", "name": "Bash", "input": {"command": "cat /nope/missing.txt", "description": "Attempt to read a non-existent file"}, "caller": {"type": "direct"}}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:51.984Z", "request_id": "req_0000"}
88
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 1}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
89
+ {"type": "stream_event", "event": {"type": "message_delta", "delta": {"stop_reason": "tool_use", "stop_sequence": null, "stop_details": null}, "context_management": {"applied_edits": []}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
90
+ {"type": "stream_event", "event": {"type": "message_stop"}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
91
+ {"type": "user", "message": {"role": "user", "content": [{"type": "tool_result", "content": "Exit code 1\ncat: /nope/missing.txt: No such file or directory", "is_error": true, "tool_use_id": "toolu_VSKbcC"}]}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:52.020Z", "tool_use_result": "Error: Exit code 1\ncat: /nope/missing.txt: No such file or directory"}
92
+ {"type": "system", "subtype": "status", "status": "requesting", "uuid": "u-0000", "session_id": "a1b2c3d4"}
93
+ {"type": "stream_event", "event": {"type": "message_start", "message": {"model": "claude-haiku-4-5-20251001", "id": "msg_011CeE77emBWNQCp3dvEh45h", "type": "message", "role": "assistant", "content": [], "stop_reason": null, "stop_sequence": null, "stop_details": null, "usage": {"input_tokens": 8, "cache_creation_input_tokens": 198, "cache_read_input_tokens": 29371, "cache_creation": {"ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 198}, "output_tokens": 1, "service_tier": "standard", "inference_geo": "not_available"}}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000", "ttft_ms": 723}
94
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 0, "content_block": {"type": "thinking", "thinking": "", "signature": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
95
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 2, "estimated_tokens_delta": 2, "uuid": "u-0000", "session_id": "a1b2c3d4"}
96
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "Perfect", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
97
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 19, "estimated_tokens_delta": 17, "uuid": "u-0000", "session_id": "a1b2c3d4"}
98
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": ". All tasks completed:\n1. Ran ls -la and node --version in parallel ", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
99
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 47, "estimated_tokens_delta": 28, "uuid": "u-0000", "session_id": "a1b2c3d4"}
100
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "\u2713\n2. Wrote node version to notes.txt \u2713\n3. Ran the failing command, which exited with code 1 and error message ", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
101
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 59, "estimated_tokens_delta": 12, "uuid": "u-0000", "session_id": "a1b2c3d4"}
102
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "thinking_delta", "thinking": "\u2713\n\nUser asked for brief, so I'll keep it short.", "estimated_tokens": null}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
103
+ {"type": "system", "subtype": "thinking_tokens", "estimated_tokens": 130, "estimated_tokens_delta": 71, "uuid": "u-0000", "session_id": "a1b2c3d4"}
104
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 0, "delta": {"type": "signature_delta", "signature": "sig-trimmed"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
105
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "thinking", "thinking": "Perfect. All tasks completed:\n1. Ran ls -la and node --version in parallel \u2713\n2. Wrote node version to notes.txt \u2713\n3. Ran the failing command, which exited with code 1 and error message \u2713\n\nUser asked for brief, so I'll keep it short.", "signature": "sig-trimmed"}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:53.730Z", "request_id": "req_0000"}
106
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 0}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
107
+ {"type": "stream_event", "event": {"type": "content_block_start", "index": 1, "content_block": {"type": "text", "text": ""}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
108
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "text_delta", "text": "Done. Node"}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
109
+ {"type": "stream_event", "event": {"type": "content_block_delta", "index": 1, "delta": {"type": "text_delta", "text": " v24.19.0 written to notes.txt, and the cat command failed as expected with \"No such file or directory\"."}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
110
+ {"type": "assistant", "message": {"type": "message", "role": "assistant", "content": [{"type": "text", "text": "Done. Node v24.19.0 written to notes.txt, and the cat command failed as expected with \"No such file or directory\"."}], "stop_reason": null, "stop_sequence": null, "stop_details": null, "context_management": null}, "parent_tool_use_id": null, "session_id": "a1b2c3d4", "uuid": "u-0000", "timestamp": "2026-08-20T13:48:54.003Z", "request_id": "req_0000"}
111
+ {"type": "stream_event", "event": {"type": "content_block_stop", "index": 1}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
112
+ {"type": "stream_event", "event": {"type": "message_delta", "delta": {"stop_reason": "end_turn", "stop_sequence": null, "stop_details": null}, "context_management": {"applied_edits": []}}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
113
+ {"type": "stream_event", "event": {"type": "message_stop"}, "session_id": "a1b2c3d4", "parent_tool_use_id": null, "uuid": "u-0000"}
114
+ {"is_error": false, "duration_api_ms": 12541, "num_turns": 5, "stop_reason": "end_turn", "session_id": "a1b2c3d4", "total_cost_usd": 0.072234, "usage": {"input_tokens": 34, "cache_creation_input_tokens": 29569, "cache_read_input_tokens": 85900, "output_tokens": 692, "output_tokens_details": {"thinking_tokens": 263}, "server_tool_use": {"web_search_requests": 0, "web_fetch_requests": 0}, "service_tier": "standard", "cache_creation": {"ephemeral_1h_input_tokens": 29569, "ephemeral_5m_input_tokens": 0}, "inference_geo": "not_available", "iterations": [], "speed": "standard"}, "modelUsage": {"claude-haiku-4-5-20251001": {"inputTokens": 976, "outputTokens": 706, "cacheReadInputTokens": 85900, "cacheCreationInputTokens": 29569, "webSearchRequests": 0, "costUSD": 0.072234, "contextWindow": 200000, "maxOutputTokens": 32000, "canonicalModel": "claude-haiku-4-5", "provider": "firstParty"}}, "permission_denials": [], "terminal_reason": "completed", "fast_mode_state": "off", "fast_mode_disabled_reason": "extra_usage_disabled", "subtype": "success", "api_error_status": null, "result": "Done. Node v24.19.0 written to notes.txt, and the cat command failed as expected with \"No such file or directory\".", "ttft_ms": 2420, "ttft_stream_ms": 1360, "time_to_request_ms": 347, "type": "result", "duration_ms": 11756, "uuid": "u-0000"}
@@ -1,5 +1,5 @@
1
1
  import { runStreamJsonCli } from "./stream-json-cli.js"
2
- import type { Agent, AgentEvent } from "./types.js"
2
+ import type { Agent, AgentEvent, AgentSession } from "./types.js"
3
3
 
4
4
  /**
5
5
  * Claude adapter — wraps the local `claude` CLI in subprocess + stream-json mode
@@ -12,7 +12,19 @@ export const claudeAgent: Agent = {
12
12
  runStreamJsonCli(
13
13
  {
14
14
  cmd: "claude",
15
- buildArgs: (prompt) => ["-p", "--output-format", "stream-json", "--include-partial-messages", "--verbose", prompt],
15
+ buildArgs: (prompt, session) => [
16
+ "-p",
17
+ "--output-format",
18
+ "stream-json",
19
+ "--include-partial-messages",
20
+ "--verbose",
21
+ // Nothing can answer a permission prompt in headless mode, so the default mode
22
+ // silently denies the installs and file writes the migration is made of.
23
+ "--permission-mode",
24
+ "bypassPermissions",
25
+ ...sessionArgs(session),
26
+ prompt,
27
+ ],
16
28
  parseLine: parseClaudeLine,
17
29
  env: (base) => {
18
30
  delete base.CLAUDECODE // claude refuses to start nested otherwise
@@ -23,8 +35,14 @@ export const claudeAgent: Agent = {
23
35
  ),
24
36
  }
25
37
 
26
- /** Map one stream-json line from claude to an AgentEvent (or null to skip). */
27
- export const parseClaudeLine = (line: string): AgentEvent | null => {
38
+ /** Names the session on the first run so later runs can resume it by id. */
39
+ const sessionArgs = (session?: AgentSession): string[] => {
40
+ if (!session) return []
41
+ return session.started ? ["--resume", session.id] : ["--session-id", session.id]
42
+ }
43
+
44
+ /** Map one stream-json line from claude to AgentEvents (or null to skip). */
45
+ export const parseClaudeLine = (line: string): AgentEvent | AgentEvent[] | null => {
28
46
  let obj: any
29
47
  try {
30
48
  obj = JSON.parse(line)
@@ -37,23 +55,24 @@ export const parseClaudeLine = (line: string): AgentEvent | null => {
37
55
  const ev = obj.event
38
56
  if (ev.type === "content_block_delta" && ev.delta?.type === "text_delta") return { type: "text", text: ev.delta.text }
39
57
  if (ev.type === "content_block_delta" && ev.delta?.type === "thinking_delta") return { type: "thinking", text: ev.delta.thinking ?? "" }
40
- if (ev.type === "content_block_start" && ev.content_block?.type === "tool_use")
41
- return {
42
- type: "tool_use",
43
- name: ev.content_block.name,
44
- summary: summarizeToolInput(ev.content_block.name, ev.content_block.input ?? {}),
45
- }
58
+ // A tool call is announced here with an empty `input` — its arguments only follow as
59
+ // input_json_delta fragments, so the call is reported from the assistant message instead.
46
60
  return null
47
61
  }
48
62
 
49
- // Per-turn full messages — suppress to avoid duplicating the deltas
50
- if (obj.type === "assistant" && obj.message?.content) return null
63
+ // Per-turn messages repeat text we already streamed, but they are the one place a tool
64
+ // call's arguments arrive assembled. A turn can open several tools, hence an array.
65
+ if (obj.type === "assistant" && Array.isArray(obj.message?.content))
66
+ return obj.message.content
67
+ .filter((block: any) => block?.type === "tool_use")
68
+ .map((block: any): AgentEvent => ({ type: "tool_use", name: block.name, summary: summarizeToolInput(block.name, block.input) }))
51
69
 
52
70
  if (obj.type === "user") {
53
71
  const r = obj.tool_use_result
54
72
  if (r?.type === "create") return { type: "tool_result", ok: true, summary: `Created ${r.filePath}` }
55
73
  if (r?.type === "update") return { type: "tool_result", ok: true, summary: `Updated ${r.filePath}` }
56
- return null
74
+ const blocks = Array.isArray(obj.message?.content) ? obj.message.content : []
75
+ return blocks.filter((block: any) => block?.type === "tool_result").map(toolResultEvent)
57
76
  }
58
77
 
59
78
  if (obj.type === "result") {
@@ -66,9 +85,38 @@ export const parseClaudeLine = (line: string): AgentEvent | null => {
66
85
  return null
67
86
  }
68
87
 
88
+ /** What the tool is actually doing, as one line — a bare "Bash" tells the reader nothing. */
69
89
  const summarizeToolInput = (name: string, input: any): string => {
70
- if (name === "Edit" || name === "Write" || name === "Read") return input.file_path ?? ""
71
- if (name === "Bash") return String(input.command ?? "").slice(0, 200)
72
- if (name === "Glob" || name === "Grep") return String(input.pattern ?? "")
90
+ if (!input || typeof input !== "object") return ""
91
+ if (name === "Bash" || name === "BashOutput") return oneLine(input.command ?? input.description)
92
+ if (name === "Edit" || name === "Write" || name === "Read") return oneLine(input.file_path)
93
+ if (name === "NotebookEdit") return oneLine(input.notebook_path)
94
+ if (name === "Glob" || name === "Grep") return oneLine([input.pattern, input.path].filter(Boolean).join(" in "))
95
+ if (name === "WebFetch") return oneLine(input.url)
96
+ if (name === "WebSearch") return oneLine(input.query)
97
+ if (name === "TodoWrite") return oneLine(`${input.todos?.length ?? 0} todos`)
98
+ // Task and any MCP tool: the description is the only human-readable field they share.
99
+ return oneLine(input.description)
100
+ }
101
+
102
+ /** Renders a tool result as one line, so a failed command isn't silent in the output */
103
+ const toolResultEvent = (block: any): AgentEvent => ({
104
+ type: "tool_result",
105
+ ok: block.is_error !== true,
106
+ summary: oneLine(blockText(block.content)),
107
+ })
108
+
109
+ /** Tool results are usually a string, but can be content blocks when a tool returns images */
110
+ const blockText = (content: unknown): string => {
111
+ if (typeof content === "string") return content
112
+ if (Array.isArray(content)) return content.map((part: any) => (typeof part?.text === "string" ? part.text : "")).join(" ")
73
113
  return ""
74
114
  }
115
+
116
+ /** Collapses whitespace and clips, so a heredoc or multi-line output can't break the TUI's rows */
117
+ const oneLine = (value: unknown, max = 160): string => {
118
+ const text = String(value ?? "")
119
+ .replace(/\s+/g, " ")
120
+ .trim()
121
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text
122
+ }
@@ -11,7 +11,18 @@ export const codexAgent: Agent = {
11
11
  runStreamJsonCli(
12
12
  {
13
13
  cmd: "codex",
14
- buildArgs: (prompt) => ["exec", "--json", "--skip-git-repo-check", prompt],
14
+ buildArgs: (prompt, session) => [
15
+ "exec",
16
+ ...(session?.started ? ["resume", "--last"] : []),
17
+ "--json",
18
+ "--skip-git-repo-check",
19
+ // exec sandboxes to read-only with no network; the pipeline writes files and installs deps.
20
+ "-c",
21
+ 'sandbox_mode="workspace-write"',
22
+ "-c",
23
+ "sandbox_workspace_write.network_access=true",
24
+ prompt,
25
+ ],
15
26
  parseLine: parseCodexLine,
16
27
  },
17
28
  input,
@@ -12,7 +12,16 @@ export const copilotAgent: Agent = {
12
12
  runStreamJsonCli(
13
13
  {
14
14
  cmd: "copilot",
15
- buildArgs: (prompt) => ["-p", prompt, "--output-format", "json", "--stream", "on", "--allow-all-tools"],
15
+ buildArgs: (prompt, session) => [
16
+ "-p",
17
+ prompt,
18
+ "--output-format",
19
+ "json",
20
+ "--stream",
21
+ "on",
22
+ "--allow-all-tools",
23
+ ...(session?.started ? ["--continue"] : []),
24
+ ],
16
25
  parseLine: parseCopilotLine,
17
26
  },
18
27
  input,
@@ -12,7 +12,15 @@ export const geminiAgent: Agent = {
12
12
  runStreamJsonCli(
13
13
  {
14
14
  cmd: "gemini",
15
- buildArgs: (prompt) => ["-p", prompt, "--output-format", "stream-json"],
15
+ // --yolo auto-approves tool use; headless runs have no one to approve it.
16
+ buildArgs: (prompt, session) => [
17
+ "-p",
18
+ prompt,
19
+ "--output-format",
20
+ "stream-json",
21
+ "--yolo",
22
+ ...(session?.started ? ["--resume", "latest"] : []),
23
+ ],
16
24
  parseLine: parseGeminiLine,
17
25
  },
18
26
  input,
@@ -5,7 +5,7 @@ import { geminiAgent } from "./gemini.js"
5
5
  import { opencodeAgent } from "./opencode.js"
6
6
  import type { Agent } from "./types.js"
7
7
 
8
- export type { Agent, AgentEvent, RunInput } from "./types.js"
8
+ export type { Agent, AgentEvent, AgentSession, RunInput } from "./types.js"
9
9
 
10
10
  export const AGENTS: Record<string, Agent> = {
11
11
  claude: claudeAgent,
@@ -8,14 +8,19 @@ import { parseGeminiLine } from "./gemini.js"
8
8
  import { mapOpencodeEvent } from "./opencode.js"
9
9
  import type { AgentEvent } from "./types.js"
10
10
 
11
- /** Reads a fixture .jsonl, running `parser` over each line and keeping the non-null events. */
12
- const parseFixture = (name: string, parser: (line: string) => AgentEvent | null): AgentEvent[] => {
11
+ type LineParser = (line: string) => AgentEvent | AgentEvent[] | null
12
+
13
+ /** Reads a fixture .jsonl, running `parser` over each line and keeping the events it yields. */
14
+ const parseFixture = (name: string, parser: LineParser): AgentEvent[] => {
13
15
  const raw = fs.readFileSync(new URL(`./__fixtures__/${name}`, import.meta.url), "utf-8")
14
16
  return raw
15
17
  .split("\n")
16
18
  .filter((l) => l.trim())
17
- .map(parser)
18
- .filter((e): e is AgentEvent => e !== null)
19
+ .flatMap((line) => {
20
+ const parsed = parser(line)
21
+ if (!parsed) return []
22
+ return Array.isArray(parsed) ? parsed : [parsed]
23
+ })
19
24
  }
20
25
 
21
26
  describe("parseClaudeLine (real capture)", () => {
@@ -24,11 +29,39 @@ describe("parseClaudeLine (real capture)", () => {
24
29
  { type: "system", text: "Session started" },
25
30
  { type: "text", text: "p" },
26
31
  { type: "text", text: "ong" },
27
- { type: "tool_use", name: "Write", summary: "" },
32
+ { type: "tool_use", name: "Write", summary: "/tmp/game/ping.txt" },
28
33
  { type: "tool_result", ok: true, summary: "Created /tmp/game/ping.txt" },
29
34
  { type: "result", ok: true, costUSD: 0.061597 },
30
35
  ])
31
36
  })
37
+
38
+ // content_block_start announces each tool with an empty `input`, so a summary can only come
39
+ // from the assistant message. Two Bash calls in one turn also exercise the multi-event return.
40
+ it("summarizes bash commands and surfaces failed tools", () => {
41
+ const events = parseFixture("claude-bash.jsonl", parseClaudeLine)
42
+ expect(events.filter((e) => e.type !== "text" && e.type !== "thinking")).toEqual([
43
+ { type: "system", text: "Session started" },
44
+ { type: "tool_use", name: "Bash", summary: "ls -la" },
45
+ { type: "tool_use", name: "Bash", summary: "node --version" },
46
+ { type: "tool_result", ok: true, summary: "(Bash completed with no output)" },
47
+ { type: "tool_result", ok: true, summary: "v24.19.0" },
48
+ { type: "tool_use", name: "Write", summary: "/tmp/game/notes.txt" },
49
+ { type: "tool_result", ok: true, summary: "Created /tmp/game/notes.txt" },
50
+ { type: "tool_use", name: "Bash", summary: "cat /nope/missing.txt" },
51
+ { type: "tool_result", ok: false, summary: "Exit code 1 cat: /nope/missing.txt: No such file or directory" },
52
+ { type: "result", ok: true, costUSD: 0.072234 },
53
+ ])
54
+ })
55
+
56
+ it("keeps multi-line commands and output on one line", () => {
57
+ const toolUse = parseClaudeLine(
58
+ JSON.stringify({
59
+ type: "assistant",
60
+ message: { content: [{ type: "tool_use", name: "Bash", input: { command: "cat <<'EOF' > a.txt\nhello\nEOF" } }] },
61
+ }),
62
+ )
63
+ expect(toolUse).toEqual([{ type: "tool_use", name: "Bash", summary: "cat <<'EOF' > a.txt hello EOF" }])
64
+ })
32
65
  })
33
66
 
34
67
  describe("parseCodexLine", () => {
@@ -92,8 +125,9 @@ describe("mapOpencodeEvent (SSE objects, not JSONL)", () => {
92
125
  // Contract shared by every line-based adapter: parsing never throws, unknown
93
126
  // lines are dropped (not crashed on), and a transcript ends in exactly one result.
94
127
  describe("parser contract", () => {
95
- const cases: [string, string, (line: string) => AgentEvent | null][] = [
128
+ const cases: [string, string, LineParser][] = [
96
129
  ["claude", "claude.jsonl", parseClaudeLine],
130
+ ["claude (bash)", "claude-bash.jsonl", parseClaudeLine],
97
131
  ["codex", "codex.jsonl", parseCodexLine],
98
132
  ["gemini", "gemini.jsonl", parseGeminiLine],
99
133
  ["copilot", "copilot.jsonl", parseCopilotLine],
@@ -1,6 +1,6 @@
1
1
  import { spawn, type ChildProcess } from "node:child_process"
2
2
 
3
- import type { AgentEvent, RunInput } from "./types.js"
3
+ import type { AgentEvent, AgentSession, RunInput } from "./types.js"
4
4
 
5
5
  /**
6
6
  * Shared driver for any CLI that emits NDJSON over stdout when given a prompt
@@ -8,15 +8,16 @@ import type { AgentEvent, RunInput } from "./types.js"
8
8
  */
9
9
  export type StreamJsonCliConfig = {
10
10
  cmd: string
11
- buildArgs: (prompt: string) => string[]
12
- /** Map one parsed JSON line to an AgentEvent (or null to drop). */
13
- parseLine: (line: string) => AgentEvent | null
11
+ /** Build argv for a run. `session` is set when the caller wants this run to continue an earlier one. */
12
+ buildArgs: (prompt: string, session?: AgentSession) => string[]
13
+ /** Map one parsed JSON line to an AgentEvent, several (a turn can start multiple tools), or null to drop. */
14
+ parseLine: (line: string) => AgentEvent | AgentEvent[] | null
14
15
  /** Optional env mutator. Receives a copy of process.env. */
15
16
  env?: (base: NodeJS.ProcessEnv) => NodeJS.ProcessEnv
16
17
  }
17
18
 
18
19
  export const runStreamJsonCli = async function* (config: StreamJsonCliConfig, input: RunInput): AsyncIterable<AgentEvent> {
19
- const args = config.buildArgs(input.prompt)
20
+ const args = config.buildArgs(input.prompt, input.session)
20
21
  const env = config.env ? config.env({ ...process.env }) : { ...process.env }
21
22
 
22
23
  let proc: ChildProcess
@@ -40,17 +41,34 @@ export const runStreamJsonCli = async function* (config: StreamJsonCliConfig, in
40
41
  let buf = ""
41
42
  let sawResult = false
42
43
 
44
+ let idleTimer: NodeJS.Timeout | null = null
45
+ let idleFired = false
46
+
47
+ // Agents can think for minutes at a time, so cap silence rather than total runtime:
48
+ // a wedged run dies quickly while a productive long one is left alone.
49
+ const armIdleTimer = () => {
50
+ if (!input.idleTimeoutMs || idleFired || done) return
51
+ if (idleTimer) clearTimeout(idleTimer)
52
+ idleTimer = setTimeout(() => {
53
+ idleFired = true
54
+ push({ type: "error", message: `No output for ${Math.round(input.idleTimeoutMs! / 1000)}s, stopping the agent` })
55
+ proc.kill()
56
+ }, input.idleTimeoutMs)
57
+ }
58
+
43
59
  const push = (e: AgentEvent) => {
44
60
  if (e.type === "result") sawResult = true
45
61
  queue.push(e)
62
+ armIdleTimer()
46
63
  resolveWaiting?.()
47
64
  resolveWaiting = null
48
65
  }
49
66
 
50
67
  const flushLine = (line: string) => {
51
68
  if (!line.trim()) return
52
- const event = config.parseLine(line)
53
- if (event) push(event)
69
+ const parsed = config.parseLine(line)
70
+ if (!parsed) return
71
+ for (const event of Array.isArray(parsed) ? parsed : [parsed]) push(event)
54
72
  }
55
73
 
56
74
  proc.stdout?.on("data", (chunk: Buffer) => {
@@ -60,15 +78,18 @@ export const runStreamJsonCli = async function* (config: StreamJsonCliConfig, in
60
78
  for (const line of lines) flushLine(line)
61
79
  })
62
80
 
81
+ // Warnings on stderr are noise, not failure — a run is judged by its result event
82
+ // and exit code, so a deprecation notice can't trigger a spurious retry.
63
83
  proc.stderr?.on("data", (chunk: Buffer) => {
64
84
  const text = chunk.toString("utf8").trim()
65
- if (text) push({ type: "error", message: text })
85
+ if (text) push({ type: "system", text })
66
86
  })
67
87
 
68
88
  proc.on("close", (code) => {
69
89
  if (buf.trim()) flushLine(buf)
70
90
  if (code !== 0 && !sawResult) push({ type: "result", ok: false })
71
91
  done = true
92
+ if (idleTimer) clearTimeout(idleTimer)
72
93
  resolveWaiting?.()
73
94
  resolveWaiting = null
74
95
  })
@@ -76,10 +97,13 @@ export const runStreamJsonCli = async function* (config: StreamJsonCliConfig, in
76
97
  proc.on("error", (err) => {
77
98
  push({ type: "error", message: err.message })
78
99
  done = true
100
+ if (idleTimer) clearTimeout(idleTimer)
79
101
  resolveWaiting?.()
80
102
  resolveWaiting = null
81
103
  })
82
104
 
105
+ armIdleTimer()
106
+
83
107
  while (true) {
84
108
  if (queue.length > 0) yield queue.shift()!
85
109
  else if (done) return
@@ -11,10 +11,26 @@ export type AgentEvent =
11
11
  | { type: "result"; ok: boolean; costUSD?: number }
12
12
  | { type: "error"; message: string }
13
13
 
14
+ /**
15
+ * A conversation carried across several agent invocations. Reusing one keeps the
16
+ * agent's knowledge of the project (and its prompt cache) between pipeline steps
17
+ * instead of paying for a cold re-read of the codebase every time.
18
+ */
19
+ export type AgentSession = {
20
+ /** Stable id, for CLIs that let us name the session up front */
21
+ id: string
22
+ /** Set once a run has established the session; later runs resume rather than start cold */
23
+ started: boolean
24
+ }
25
+
14
26
  export type RunInput = {
15
27
  prompt: string
16
28
  cwd?: string
17
29
  signal?: AbortSignal
30
+ /** Continue this conversation instead of starting a fresh one, where the agent supports it */
31
+ session?: AgentSession
32
+ /** Abort the run when the agent has produced no output for this long */
33
+ idleTimeoutMs?: number
18
34
  }
19
35
 
20
36
  export interface Agent {