@jaggerxtrm/specialists 3.16.0 → 3.18.0

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 (257) hide show
  1. package/README.md +268 -132
  2. package/config/mandatory-rules/json-only-final-output.md +13 -0
  3. package/config/mandatory-rules/research-tool-routing.md +4 -0
  4. package/config/mandatory-rules/service-skills-diff-scan-mandatory.md +26 -0
  5. package/config/mandatory-rules/service-skills-gitnexus-triage.md +5 -0
  6. package/config/mandatory-rules/test-runner-execution-scope.md +1 -1
  7. package/config/skills/setup-specialists/SKILL.md +556 -0
  8. package/config/skills/specialists-creator/SKILL.md +160 -5
  9. package/config/skills/specialists-creator/scripts/audit-spec-uniformity.mjs +1 -1
  10. package/config/skills/using-specialists-auto/SKILL.md +1 -1
  11. package/config/skills/using-specialists-v2/SKILL.md +7 -7
  12. package/config/skills/using-specialists-v3/SKILL.md +223 -147
  13. package/config/specialists/bare.specialist.json +3 -3
  14. package/config/specialists/changelog-drafter.specialist.json +9 -6
  15. package/config/specialists/changelog-keeper.specialist.json +10 -7
  16. package/config/specialists/debugger.specialist.json +8 -6
  17. package/config/specialists/executor.specialist.json +9 -7
  18. package/config/specialists/explorer.specialist.json +8 -6
  19. package/config/specialists/memory-processor.specialist.json +7 -5
  20. package/config/specialists/node-coordinator.specialist.json +7 -5
  21. package/config/specialists/obligations-scanner.specialist.json +149 -0
  22. package/config/specialists/overthinker.specialist.json +7 -5
  23. package/config/specialists/planner.specialist.json +8 -6
  24. package/config/specialists/quant-methodologist.specialist.json +145 -0
  25. package/config/specialists/quant-researcher.specialist.json +144 -0
  26. package/config/specialists/researcher.specialist.json +14 -9
  27. package/config/specialists/reviewer.specialist.json +11 -9
  28. package/config/specialists/seconder.specialist.json +170 -0
  29. package/config/specialists/security-auditor.specialist.json +6 -4
  30. package/config/specialists/service-skills-sync.specialist.json +93 -0
  31. package/config/specialists/specialists-creator.specialist.json +9 -7
  32. package/config/specialists/sync-docs.specialist.json +6 -4
  33. package/config/specialists/test-engineer.specialist.json +134 -0
  34. package/config/specialists/test-runner.specialist.json +11 -9
  35. package/config/specialists/transcriber.specialist.json +59 -0
  36. package/config/specialists/xt-merge.specialist.json +7 -5
  37. package/dist/asset-contract.json +39 -8
  38. package/dist/index.js +37083 -26912
  39. package/dist/lib.js +9850 -6147
  40. package/dist/types/cli/console/components.d.ts +83 -0
  41. package/dist/types/cli/console/components.d.ts.map +1 -0
  42. package/dist/types/cli/console/config-source.d.ts +58 -0
  43. package/dist/types/cli/console/config-source.d.ts.map +1 -0
  44. package/dist/types/cli/console/forensic.d.ts +11 -0
  45. package/dist/types/cli/console/forensic.d.ts.map +1 -0
  46. package/dist/types/cli/console/git.d.ts +28 -0
  47. package/dist/types/cli/console/git.d.ts.map +1 -0
  48. package/dist/types/cli/console/help.d.ts +2 -0
  49. package/dist/types/cli/console/help.d.ts.map +1 -0
  50. package/dist/types/cli/console/log.d.ts +13 -0
  51. package/dist/types/cli/console/log.d.ts.map +1 -0
  52. package/dist/types/cli/console/repo-config.d.ts +26 -0
  53. package/dist/types/cli/console/repo-config.d.ts.map +1 -0
  54. package/dist/types/cli/console/repo-discovery.d.ts +12 -0
  55. package/dist/types/cli/console/repo-discovery.d.ts.map +1 -0
  56. package/dist/types/cli/console/runtime.d.ts +12 -0
  57. package/dist/types/cli/console/runtime.d.ts.map +1 -0
  58. package/dist/types/cli/console/subscribe-prototype.d.ts +18 -0
  59. package/dist/types/cli/console/subscribe-prototype.d.ts.map +1 -0
  60. package/dist/types/cli/console/theme.d.ts +91 -0
  61. package/dist/types/cli/console/theme.d.ts.map +1 -0
  62. package/dist/types/cli/console/types.d.ts +231 -0
  63. package/dist/types/cli/console/types.d.ts.map +1 -0
  64. package/dist/types/cli/console/view-model.d.ts +252 -0
  65. package/dist/types/cli/console/view-model.d.ts.map +1 -0
  66. package/dist/types/cli/console.d.ts +2 -0
  67. package/dist/types/cli/console.d.ts.map +1 -0
  68. package/dist/types/cli/db.d.ts.map +1 -1
  69. package/dist/types/cli/doctor.d.ts.map +1 -1
  70. package/dist/types/cli/edit.d.ts.map +1 -1
  71. package/dist/types/cli/epic.d.ts.map +1 -1
  72. package/dist/types/cli/feed.d.ts.map +1 -1
  73. package/dist/types/cli/forensic.d.ts +2 -0
  74. package/dist/types/cli/forensic.d.ts.map +1 -0
  75. package/dist/types/cli/format-helpers.d.ts +4 -2
  76. package/dist/types/cli/format-helpers.d.ts.map +1 -1
  77. package/dist/types/cli/help.d.ts.map +1 -1
  78. package/dist/types/cli/init.d.ts +10 -0
  79. package/dist/types/cli/init.d.ts.map +1 -1
  80. package/dist/types/cli/list.d.ts.map +1 -1
  81. package/dist/types/cli/log.d.ts +2 -0
  82. package/dist/types/cli/log.d.ts.map +1 -0
  83. package/dist/types/cli/metrics.d.ts +2 -0
  84. package/dist/types/cli/metrics.d.ts.map +1 -0
  85. package/dist/types/cli/ps.d.ts.map +1 -1
  86. package/dist/types/cli/result.d.ts.map +1 -1
  87. package/dist/types/cli/resume.d.ts.map +1 -1
  88. package/dist/types/cli/run.d.ts +1 -0
  89. package/dist/types/cli/run.d.ts.map +1 -1
  90. package/dist/types/cli/script.d.ts +3 -0
  91. package/dist/types/cli/script.d.ts.map +1 -1
  92. package/dist/types/cli/serve.d.ts.map +1 -1
  93. package/dist/types/cli/setup.d.ts +19 -1
  94. package/dist/types/cli/setup.d.ts.map +1 -1
  95. package/dist/types/cli/status.d.ts.map +1 -1
  96. package/dist/types/cli/steer.d.ts.map +1 -1
  97. package/dist/types/cli/version-check.d.ts +1 -0
  98. package/dist/types/cli/version-check.d.ts.map +1 -1
  99. package/dist/types/index.d.ts +1 -1
  100. package/dist/types/pi/session.d.ts +11 -1
  101. package/dist/types/pi/session.d.ts.map +1 -1
  102. package/dist/types/server.d.ts +15 -0
  103. package/dist/types/server.d.ts.map +1 -1
  104. package/dist/types/specialist/benchmarks.d.ts +37 -0
  105. package/dist/types/specialist/benchmarks.d.ts.map +1 -0
  106. package/dist/types/specialist/chain-identity.d.ts +7 -1
  107. package/dist/types/specialist/chain-identity.d.ts.map +1 -1
  108. package/dist/types/specialist/control.d.ts.map +1 -1
  109. package/dist/types/specialist/forensic-events.d.ts +138 -0
  110. package/dist/types/specialist/forensic-events.d.ts.map +1 -0
  111. package/dist/types/specialist/forensic-renderer.d.ts +34 -0
  112. package/dist/types/specialist/forensic-renderer.d.ts.map +1 -0
  113. package/dist/types/specialist/git-diff-evidence.d.ts +28 -0
  114. package/dist/types/specialist/git-diff-evidence.d.ts.map +1 -0
  115. package/dist/types/specialist/global-config.d.ts +389 -0
  116. package/dist/types/specialist/global-config.d.ts.map +1 -0
  117. package/dist/types/specialist/job-file-output.d.ts +2 -0
  118. package/dist/types/specialist/job-file-output.d.ts.map +1 -1
  119. package/dist/types/specialist/launch.d.ts +1 -0
  120. package/dist/types/specialist/launch.d.ts.map +1 -1
  121. package/dist/types/specialist/live-aggregates.d.ts +46 -0
  122. package/dist/types/specialist/live-aggregates.d.ts.map +1 -0
  123. package/dist/types/specialist/loader.d.ts +50 -1
  124. package/dist/types/specialist/loader.d.ts.map +1 -1
  125. package/dist/types/specialist/model-chain.d.ts +7 -0
  126. package/dist/types/specialist/model-chain.d.ts.map +1 -0
  127. package/dist/types/specialist/model-probes.d.ts +28 -0
  128. package/dist/types/specialist/model-probes.d.ts.map +1 -0
  129. package/dist/types/specialist/node-contract.d.ts +18 -18
  130. package/dist/types/specialist/node-supervisor.d.ts.map +1 -1
  131. package/dist/types/specialist/observability-db.d.ts +1 -1
  132. package/dist/types/specialist/observability-db.d.ts.map +1 -1
  133. package/dist/types/specialist/observability-sqlite.d.ts +25 -0
  134. package/dist/types/specialist/observability-sqlite.d.ts.map +1 -1
  135. package/dist/types/specialist/preset-resolver.d.ts +56 -0
  136. package/dist/types/specialist/preset-resolver.d.ts.map +1 -0
  137. package/dist/types/specialist/prometheus-projection.d.ts +25 -0
  138. package/dist/types/specialist/prometheus-projection.d.ts.map +1 -0
  139. package/dist/types/specialist/runner.d.ts +29 -1
  140. package/dist/types/specialist/runner.d.ts.map +1 -1
  141. package/dist/types/specialist/schema.d.ts +181 -63
  142. package/dist/types/specialist/schema.d.ts.map +1 -1
  143. package/dist/types/specialist/script-runner.d.ts +5 -1
  144. package/dist/types/specialist/script-runner.d.ts.map +1 -1
  145. package/dist/types/specialist/snapshot-diff.d.ts +8 -0
  146. package/dist/types/specialist/snapshot-diff.d.ts.map +1 -0
  147. package/dist/types/specialist/source-queue.d.ts +13 -0
  148. package/dist/types/specialist/source-queue.d.ts.map +1 -0
  149. package/dist/types/specialist/supervisor.d.ts +39 -2
  150. package/dist/types/specialist/supervisor.d.ts.map +1 -1
  151. package/dist/types/specialist/timeline-events.d.ts +88 -2
  152. package/dist/types/specialist/timeline-events.d.ts.map +1 -1
  153. package/dist/types/tools/specialist/resume_specialist.tool.d.ts +4 -4
  154. package/dist/types/tools/specialist/specialist_status.tool.d.ts +1 -1
  155. package/dist/types/tools/specialist/steer_specialist.tool.d.ts +4 -4
  156. package/dist/types/tools/specialist/use_specialist.tool.d.ts +16 -16
  157. package/docs/ARCHITECTURE.md +1176 -0
  158. package/docs/TODO.md +9 -0
  159. package/docs/architecture.md +11 -0
  160. package/docs/archive/2026-03-13-bd-decision-context-template-plan.md +96 -0
  161. package/docs/archive/AGENT-HANDOFF.md +351 -0
  162. package/docs/archive/PARITY-ANALYSIS.md +296 -0
  163. package/docs/archive/SPECIALISTS_REFACTOR.md.md +30 -0
  164. package/docs/archive/cc-programmatic.md +216 -0
  165. package/docs/archive/claude-agent-sdk.md +594 -0
  166. package/docs/archive/decision-specialist-directory.md +41 -0
  167. package/docs/archive/discoveries.md +148 -0
  168. package/docs/archive/executor-benchmark-protocol.md +198 -0
  169. package/docs/archive/future-features.md +66 -0
  170. package/docs/archive/gzrx-completion-critique.md +183 -0
  171. package/docs/archive/gzrx-research-notes.md +401 -0
  172. package/docs/archive/gzrx-tool-catalog.md +760 -0
  173. package/docs/archive/iron-review-hardening-qa-chain-substrate.md +322 -0
  174. package/docs/archive/iron-review-hardening.html +1004 -0
  175. package/docs/archive/issuetracking.md +312 -0
  176. package/docs/archive/qa-v3.0.2.md +220 -0
  177. package/docs/archive/restructure.md +231 -0
  178. package/docs/archive/script-specialists.md +1254 -0
  179. package/docs/archive/spec-v3.md +792 -0
  180. package/docs/archive/specialist-stats.md +127 -0
  181. package/docs/archive/specialists-friction-audit.md +1347 -0
  182. package/docs/archive/specialists-runtime-critique.md +170 -0
  183. package/docs/archive/specialists-service-evaluation.md +713 -0
  184. package/docs/archive/specialists-substrate-alignment.md +255 -0
  185. package/docs/archive/substrate-review.md +1288 -0
  186. package/docs/archive/test-writer-specialist.md +254 -0
  187. package/docs/archive/using-specialists-v3-improvements-2026-05-09.md +600 -0
  188. package/docs/archive/xtrm-specialists-analysis.md +314 -0
  189. package/docs/authoring.md +701 -0
  190. package/docs/background-jobs.md +203 -0
  191. package/docs/bare-specialists.md +83 -0
  192. package/docs/benchmarks/executor-benchmark-runner.md +66 -0
  193. package/docs/bootstrap.md +161 -0
  194. package/docs/cli-reference.md +1645 -0
  195. package/docs/deploying-alongside.md +155 -0
  196. package/docs/design/README.md +36 -0
  197. package/docs/design/darth-feedor-migration.md +290 -0
  198. package/docs/design/roadmap/README.md +32 -0
  199. package/docs/design/roadmap/chain-templates/README.md +146 -0
  200. package/docs/design/roadmap/chain-templates/code-quick.formula.json +27 -0
  201. package/docs/design/roadmap/chain-templates/code-standard.formula.json +126 -0
  202. package/docs/design/roadmap/chain-templates/code-with-advisors.formula.json +128 -0
  203. package/docs/design/roadmap/chain-templates/code-with-tests.formula.json +76 -0
  204. package/docs/design/roadmap/chain-templates/debug.formula.json +128 -0
  205. package/docs/design/roadmap/chain-templates/doc-sync.formula.json +28 -0
  206. package/docs/design/roadmap/chain-templates/memory-hygiene.formula.json +27 -0
  207. package/docs/design/roadmap/chain-templates/planning.formula.json +27 -0
  208. package/docs/design/roadmap/chain-templates/premortem.formula.json +26 -0
  209. package/docs/design/roadmap/chain-templates/release-prep.formula.json +36 -0
  210. package/docs/design/roadmap/chain-templates/research-only.formula.json +28 -0
  211. package/docs/design/roadmap/chain-templates/restitch.formula.json +125 -0
  212. package/docs/design/roadmap/chain-templates/security-deep.formula.json +161 -0
  213. package/docs/design/roadmap/chain-templates/test-only.formula.json +52 -0
  214. package/docs/design/roadmap/chain-templates/triage.formula.json +35 -0
  215. package/docs/design/roadmap/history/handoff-from-substrate-design.md +87 -0
  216. package/docs/design/roadmap/history/substrate-reconciliation.md +105 -0
  217. package/docs/design/roadmap/specialists-roadmap.md +1193 -0
  218. package/docs/design/sp-console-subscribe-via-materializer.md +231 -0
  219. package/docs/design/sp-console-tui-mock-v2.html +293 -0
  220. package/docs/design/sp-console-tui-mock.html +120 -0
  221. package/docs/design/sp-console-tui.md +340 -0
  222. package/docs/design/specialist-agentops-suite.md +323 -0
  223. package/docs/design/substrate/channels.md +14 -0
  224. package/docs/design/substrate/devops-platform-engineering-prd.md +446 -0
  225. package/docs/design/substrate/html-design-example.md +339 -0
  226. package/docs/design/xtrm-tiers-architecture.svg +132 -0
  227. package/docs/devops/dependency-verdict-materialization.md +46 -0
  228. package/docs/epic-readiness.md +75 -0
  229. package/docs/examples/mercury-atomic-summarizer.specialist.json +26 -0
  230. package/docs/examples/smoke-echo-text-expected-keys.specialist.json +25 -0
  231. package/docs/examples/smoke-echo.specialist.json +25 -0
  232. package/docs/features.md +1577 -0
  233. package/docs/hooks.md +81 -0
  234. package/docs/installation.md +142 -0
  235. package/docs/manifest.md +184 -0
  236. package/docs/mcp-servers.md +73 -0
  237. package/docs/mcp-tools.md +71 -0
  238. package/docs/nodes.md +231 -0
  239. package/docs/observability-metrics.md +152 -0
  240. package/docs/operator/sp-console-v2-walkthrough.md +410 -0
  241. package/docs/overrides-guide.md +306 -0
  242. package/docs/pi-rpc-boundary.md +118 -0
  243. package/docs/pi-session.md +195 -0
  244. package/docs/release.md +22 -0
  245. package/docs/skills.md +132 -0
  246. package/docs/specialists/handoff-schema.md +181 -0
  247. package/docs/specialists-catalog.md +99 -0
  248. package/docs/specialists-service-install.md +226 -0
  249. package/docs/specialists-service.md +363 -0
  250. package/docs/surface-ownership.md +138 -0
  251. package/docs/upgrade-notes/kan-90-global-user-config.md +114 -0
  252. package/docs/upgrade-notes/kan-91-expanded-overrides.md +261 -0
  253. package/docs/workflow.md +114 -0
  254. package/docs/worktree.md +71 -0
  255. package/docs/worktrees.md +309 -0
  256. package/package.json +17 -12
  257. package/config/specialists/code-sanity.specialist.json +0 -108
@@ -0,0 +1,231 @@
1
+ ---
2
+ title: Specialists System — Restructure Findings
3
+ scope: restructure
4
+ category: reference
5
+ version: 1.0.0
6
+ updated: 2026-03-19
7
+ domain: []
8
+ ---
9
+
10
+ <!-- INDEX: auto-generated by validate_doc.py — do not edit manually -->
11
+ | Section | Summary |
12
+ |---|---|
13
+ | [1. The Core Problem](#1-the-core-problem) | The current execution layer has two issues: |
14
+ | [2. What Pi Actually Provides](#2-what-pi-actually-provides) | Source: `badlogic/pi-mono/packages/coding-agent` wiki + direct spec analysis |
15
+ | [3. The Polling Problem](#3-the-polling-problem) | MCP is request-response |
16
+ | [4. How Overstory Solves It (Reference)](#4-how-overstory-solves-it-reference) | Overstory bypasses MCP for execution: |
17
+ | [5. Architecture Options Evaluated](#5-architecture-options-evaluated) | **Rejected because** (from adversarial critique): |
18
+ | [6. Adversarial Critique — Overthinker Output](#6-adversarial-critique-overthinker-output) | > Full run: job `50bbf162`, Sonnet 4 |
19
+ | [7. Decision — The Chosen Path](#7-decision-the-chosen-path) | `JobRegistry` stays in memory |
20
+ | [8. What Does NOT Change](#8-what-does-not-change) | - The 8 MCP tool signatures — identical to consumers |
21
+ | [9. Open Questions (Remaining)](#9-open-questions-remaining) | - Is `RpcClient`/`AgentSession` a stable public export? → Verify against `@mariozechner/pi-coding-agent` package |
22
+ <!-- END INDEX -->
23
+
24
+ # Specialists System — Restructure Findings
25
+
26
+ > Status: Decision reached. See Section 7 for the chosen path.
27
+ > Updated: 2026-03-10
28
+ > Adversarial critique: overthinker specialist, job `50bbf162`, Sonnet 4.6, 169s
29
+
30
+ ---
31
+
32
+ ## 1. The Core Problem
33
+
34
+ The current execution layer has two issues:
35
+
36
+ 1. **`PiAgentSession` manually reimplements what pi already provides** — raw subprocess + manual NDJSON line buffering, custom `agent_end` detection, `proc.stdin.end()` hack. Source of the split-chunk bug (2.1.5 hotfix) and fragility against any pi protocol change.
37
+
38
+ 2. **MCP is request-response only** — no server-push. `poll_specialist` requires Claude to call repeatedly, generating tool call noise, burning context window, cluttering the UI.
39
+
40
+ ---
41
+
42
+ ## 2. What Pi Actually Provides
43
+
44
+ Source: `badlogic/pi-mono/packages/coding-agent` wiki + direct spec analysis.
45
+
46
+ ### RpcClient (subprocess wrapper)
47
+
48
+ ```typescript
49
+ import { RpcClient } from '@mariozechner/pi/rpc';
50
+
51
+ const pi = new RpcClient({ provider: 'anthropic', cwd: sessionDir });
52
+ await pi.start();
53
+ await pi.prompt('Do the task');
54
+ await pi.waitForIdle();
55
+ const { data } = await pi.send({ type: 'get_last_assistant_text' });
56
+ ```
57
+
58
+ Methods the current code reimplements manually:
59
+ - `onEvent(listener)` — subscribe to all pi events as they arrive
60
+ - `waitForIdle(timeout?)` — waits for `agent_end`, no manual polling
61
+ - `collectEvents(timeout?)` — gathers all events until completion
62
+ - `getLastAssistantText()` — clean output retrieval
63
+
64
+ ### AgentSession SDK (in-process, no subprocess)
65
+
66
+ ```typescript
67
+ import { createAgentSession } from '@mariozechner/pi-coding-agent';
68
+
69
+ const session = await createAgentSession({ provider: 'anthropic', cwd: '.' });
70
+ session.subscribe((event) => { /* native TypeScript callbacks */ });
71
+ await session.prompt('Do the task');
72
+ ```
73
+
74
+ `AgentSession` is the core that all pi modes (interactive, print, RPC) attach to. **Verification required**: whether this is a stable public export or internal only — this determines whether `PiAgentSession` can be replaced cleanly or just improved.
75
+
76
+ ### Session Persistence
77
+
78
+ - Sessions stored as branching JSONL in `~/.pi/agent/sessions/`
79
+ - `get_state` RPC → returns `sessionFile` path
80
+ - Resume: `pi --session <path>` CLI flag, or `switch_session` RPC command
81
+ - Multi-turn: call `prompt()` multiple times on same instance — full context retained
82
+
83
+ ---
84
+
85
+ ## 3. The Polling Problem
86
+
87
+ ### Why it exists
88
+
89
+ MCP is request-response. No server-push mechanism. Claude calls `poll_specialist` → MCP server responds → Claude calls again. A 30-second specialist produces 30+ tool calls, each appearing in the conversation history.
90
+
91
+ ### wait_ms (long-polling) — does NOT solve async
92
+
93
+ Reduces frequency but Claude still blocks during each poll. From Claude's perspective it's `use_specialist` cut into N-second chunks. Specialist runs async; Claude does not.
94
+
95
+ ### MCP cannot be fixed at the protocol level
96
+
97
+ MCP notifications exist but cover meta-level events only. This is a constraint, not an implementation gap.
98
+
99
+ ---
100
+
101
+ ## 4. How Overstory Solves It (Reference)
102
+
103
+ Overstory bypasses MCP for execution:
104
+ - `Bash(ov sling ...)` → spawns agent in tmux (returns immediately)
105
+ - SQLite mail for inter-agent communication
106
+ - `UserPromptSubmit` hook injects completion notifications
107
+ - Watchdog daemon for health monitoring
108
+
109
+ Key insight: hooks are a push channel MCP doesn't have. But the architecture requires tmux, a watchdog daemon, and a SQLite mail system — significant infrastructure.
110
+
111
+ ---
112
+
113
+ ## 5. Architecture Options Evaluated
114
+
115
+ ### Option A: Daemon + JSONL files ❌ REJECTED
116
+
117
+ ```
118
+ specialists daemon → owns RpcClient instances → writes events.jsonl
119
+ MCP tools → thin file readers
120
+ specialists feed → tails JSONL
121
+ ```
122
+
123
+ **Rejected because** (from adversarial critique):
124
+ - Two processes = two failure modes + one interaction failure mode
125
+ - File-based IPC (`queue.jsonl`) is non-atomic, misses events, reinvents a message queue badly. Unix socket is the right tool; function calls are better still.
126
+ - `poll_specialist` as file reader is strictly worse than memory reads (O(1) → O(n) per poll)
127
+ - Daemon startup question unsolved: child of MCP = dies with MCP (no gain); system service = breaks the "just add to .mcp.json" UX
128
+ - Event file accumulation with no GC is silent technical debt
129
+ - Complexity budget: 3–5x more code for problems that are partially invented
130
+
131
+ ### Option B: AgentSession SDK in-process + file-backed registry ✅ CHOSEN
132
+
133
+ See Section 7.
134
+
135
+ ### Option C: CLI background + hook notification (Overstory-inspired) — Deferred
136
+
137
+ ```bash
138
+ specialists run <name> --prompt "..." > .specialists/jobs/<id>/output.jsonl &
139
+ # UserPromptSubmit hook reads .specialists/ready/, injects banner
140
+ # Claude calls poll_specialist ONCE to retrieve
141
+ ```
142
+
143
+ Valid for true fire-and-forget background jobs. Deferred — not a prerequisite for the core rewrite.
144
+
145
+ ---
146
+
147
+ ## 6. Adversarial Critique — Overthinker Output
148
+
149
+ > Full run: job `50bbf162`, Sonnet 4.6, 169 seconds, ~12% context used.
150
+
151
+ ### Key findings from Phase 2 (Devil's Advocate)
152
+
153
+ **Against the daemon:**
154
+ 1. Two processes, two failure modes, one interaction failure mode — reconnection protocol unspecified
155
+ 2. File-based IPC non-atomic, inotify unreliable, no delivery guarantee
156
+ 3. Writing 15,000+ events/run to disk: thousands of syscalls vs current zero I/O
157
+ 4. `poll_specialist` as file reader: `open + lseek + read + close + JSONL parse` vs `hashmap lookup + string.slice`
158
+ 5. Claude Code IS the scheduler — polling is how it works for long-running operations
159
+ 6. Pi SDK may be internal, not exported — assumption may be a mirage
160
+ 7. No GC for job files — silent technical debt
161
+
162
+ ### Phase 4 verdict (verbatim)
163
+
164
+ > **Do not build the daemon.** It solves real problems with a solution whose complexity budget far exceeds the problems' severity.
165
+ >
166
+ > **One-line verdict:** The daemon is a distributed system solution to a persistence problem. Persistence is solved by writing files. Write files from where you already are.
167
+
168
+ ---
169
+
170
+ ## 7. Decision — The Chosen Path
171
+
172
+ ### File-backed in-memory registry (Priority 1 — low risk, high value)
173
+
174
+ `JobRegistry` stays in memory. Add file writes as a non-blocking side-effect:
175
+
176
+ ```
177
+ On job start: open .specialists/jobs/<id>/events.jsonl for append
178
+ On every event: fs.appendFile(eventsPath, JSON.stringify(event) + '\n') ← async, non-blocking
179
+ On completion: write .specialists/jobs/<id>/result.json
180
+ On MCP startup: scan job files → recover done jobs → mark in-progress as crashed
181
+ poll_specialist: memory (fast path) → result.json fallback for post-restart reads
182
+ ```
183
+
184
+ **What this gives for free:**
185
+ - ✅ `specialists feed` CLI: formatted `tail -f .specialists/jobs/*/events.jsonl`
186
+ - ✅ Audit trail and debugging
187
+ - ✅ Completed job recovery across MCP restarts
188
+ - ✅ O(1) polling preserved (in-memory primary, file is secondary)
189
+ - ✅ Zero daemon, zero IPC, zero lifecycle complexity
190
+ - ✅ GC: TTL-based cleanup on MCP startup (e.g. delete job files >7 days)
191
+
192
+ ### Replace PiAgentSession with RpcClient/SDK (Priority 2 — verify first)
193
+
194
+ **Before touching code:** confirm whether `RpcClient` or `AgentSession` is a stable public export from `@mariozechner/pi-coding-agent`.
195
+
196
+ - If **exported**: clean swap — same subprocess behavior, native event callbacks, `waitForIdle()` replaces manual detection, `getLastAssistantText()` replaces output accumulation. Eliminates the split-chunk class of bugs.
197
+ - If **internal only**: keep the subprocess, clean up the NDJSON parsing with a proper line buffer utility. Still worthwhile.
198
+
199
+ ### `specialists feed` CLI (Priority 3 — falls out from Priority 1)
200
+
201
+ Once events.jsonl exists per job:
202
+ ```bash
203
+ specialists feed # all active jobs, formatted event stream
204
+ specialists feed --job <id> # single job
205
+ specialists feed --follow # live tail
206
+ ```
207
+
208
+ Shows per job: specialist name, beadId, model, tool calls (type only), duration, status.
209
+
210
+ ### Polling UX (Priority 4 — defer)
211
+
212
+ The adversarial critique is right: Claude polling IS the pattern for long-running MCP operations. The UX problem is real but not blocking. Hook notification (Option C) remains available as a follow-up once the core rewrite is stable.
213
+
214
+ ---
215
+
216
+ ## 8. What Does NOT Change
217
+
218
+ - The 8 MCP tool signatures — identical to consumers
219
+ - `SpecialistRunner` orchestration logic
220
+ - `CircuitBreaker`
221
+ - Beads lifecycle integration
222
+ - The `.specialist.yaml` schema
223
+
224
+ ---
225
+
226
+ ## 9. Open Questions (Remaining)
227
+
228
+ - Is `RpcClient`/`AgentSession` a stable public export? → Verify against `@mariozechner/pi-coding-agent` package.json `exports` field
229
+ - What event granularity to write to events.jsonl? All events (including thinking deltas) or only lifecycle events? Thinking deltas at 50/sec = significant I/O. Likely: lifecycle + tool events only, full text on completion.
230
+ - `specialists feed` output format — match `specialists status` style or a new live-updating TUI?
231
+ - Multi-turn (`resume_specialist` tool) — separate milestone once session file path is saved at job creation