@fitchmultz/pi-subagents 0.0.0-stage → 0.44.4

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 (342) hide show
  1. package/CHANGELOG.md +1645 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1529 -2
  4. package/agents/context-builder.md +97 -0
  5. package/agents/debugger.md +51 -0
  6. package/agents/delegate.md +13 -0
  7. package/agents/fixer.md +37 -0
  8. package/agents/oracle.md +71 -0
  9. package/agents/planner.md +72 -0
  10. package/agents/researcher.md +51 -0
  11. package/agents/reviewer-claude.md +69 -0
  12. package/agents/reviewer-gpt.md +68 -0
  13. package/agents/reviewer-ponytail.md +82 -0
  14. package/agents/reviewer-security.md +81 -0
  15. package/agents/reviewer.md +69 -0
  16. package/agents/scout.md +66 -0
  17. package/agents/ui-designer.md +51 -0
  18. package/agents/watcher.md +26 -0
  19. package/agents/worker.md +46 -0
  20. package/agents/writer.md +36 -0
  21. package/dist/agents/agent-management.js +923 -0
  22. package/dist/agents/agent-scope.js +7 -0
  23. package/dist/agents/agent-selection.js +20 -0
  24. package/dist/agents/agent-serializer.js +100 -0
  25. package/dist/agents/agents.js +752 -0
  26. package/dist/agents/chain-serializer.js +367 -0
  27. package/dist/agents/frontmatter.js +21 -0
  28. package/dist/agents/identity.js +29 -0
  29. package/dist/agents/skills.js +570 -0
  30. package/dist/extension/build-info.js +1 -0
  31. package/dist/extension/compact-tools.js +112 -0
  32. package/dist/extension/config.js +22 -0
  33. package/dist/extension/control-notices.js +29 -0
  34. package/dist/extension/doctor.js +143 -0
  35. package/dist/extension/fanout-child.js +326 -0
  36. package/dist/extension/index.js +577 -0
  37. package/dist/extension/schemas.js +416 -0
  38. package/dist/extension/tool-input.js +20 -0
  39. package/dist/extension/tool-result.js +14 -0
  40. package/dist/history/canonical-result.js +81 -0
  41. package/dist/history/database.js +72 -0
  42. package/dist/history/index.js +194 -0
  43. package/dist/history/ingest.js +447 -0
  44. package/dist/history/queries.js +350 -0
  45. package/dist/history/store.js +216 -0
  46. package/dist/history/types.js +4 -0
  47. package/dist/history/worker.js +461 -0
  48. package/dist/intercom/intercom-bridge.js +112 -0
  49. package/dist/intercom/live-intercom.js +94 -0
  50. package/dist/intercom/result-intercom.js +373 -0
  51. package/dist/pi-intercom/agent-dir.js +10 -0
  52. package/dist/pi-intercom/broker/broker.js +426 -0
  53. package/dist/pi-intercom/broker/client.js +492 -0
  54. package/dist/pi-intercom/broker/framing.js +65 -0
  55. package/dist/pi-intercom/broker/paths.js +42 -0
  56. package/dist/pi-intercom/broker/pid.js +66 -0
  57. package/dist/pi-intercom/broker/spawn.js +221 -0
  58. package/dist/pi-intercom/config.js +102 -0
  59. package/dist/pi-intercom/index.js +2942 -0
  60. package/dist/pi-intercom/reply-tracker.js +182 -0
  61. package/dist/pi-intercom/session-targets.js +128 -0
  62. package/dist/pi-intercom/subagent-live-events.js +132 -0
  63. package/dist/pi-intercom/topics.js +157 -0
  64. package/dist/pi-intercom/types.js +163 -0
  65. package/dist/pi-intercom/ui/compose.js +269 -0
  66. package/dist/pi-intercom/ui/inline-message.js +80 -0
  67. package/dist/pi-intercom/ui/session-list.js +124 -0
  68. package/dist/runs/background/async-control.js +95 -0
  69. package/dist/runs/background/async-execution.js +676 -0
  70. package/dist/runs/background/async-job-tracker.js +383 -0
  71. package/dist/runs/background/async-result-file.js +58 -0
  72. package/dist/runs/background/async-resume.js +305 -0
  73. package/dist/runs/background/async-status.js +442 -0
  74. package/dist/runs/background/completion-dedupe.js +69 -0
  75. package/dist/runs/background/completion-delivery.js +245 -0
  76. package/dist/runs/background/notify.js +71 -0
  77. package/dist/runs/background/parallel-groups.js +55 -0
  78. package/dist/runs/background/result-watcher.js +426 -0
  79. package/dist/runs/background/run-id-resolver.js +64 -0
  80. package/dist/runs/background/run-status.js +382 -0
  81. package/dist/runs/background/stale-run-reconciler.js +335 -0
  82. package/dist/runs/background/subagent-runner-launcher.js +55 -0
  83. package/dist/runs/background/subagent-runner.js +1872 -0
  84. package/dist/runs/background/top-level-async.js +5 -0
  85. package/dist/runs/foreground/chain-clarify.js +1152 -0
  86. package/dist/runs/foreground/clarify-invocation.js +72 -0
  87. package/dist/runs/foreground/execution-input.js +423 -0
  88. package/dist/runs/foreground/foreground-control.js +817 -0
  89. package/dist/runs/foreground/question-control.js +77 -0
  90. package/dist/runs/foreground/run-async-path.js +205 -0
  91. package/dist/runs/foreground/subagent-executor.js +442 -0
  92. package/dist/runs/foreground/subagent-params.js +165 -0
  93. package/dist/runs/foreground/wait-run.js +139 -0
  94. package/dist/runs/shared/acceptance-contract.js +253 -0
  95. package/dist/runs/shared/acceptance-evaluation.js +256 -0
  96. package/dist/runs/shared/acceptance-finalization.js +280 -0
  97. package/dist/runs/shared/acceptance-reports.js +147 -0
  98. package/dist/runs/shared/acceptance.js +4 -0
  99. package/dist/runs/shared/chain-outputs.js +110 -0
  100. package/dist/runs/shared/child-attempt.js +693 -0
  101. package/dist/runs/shared/child-execution-cwd.js +96 -0
  102. package/dist/runs/shared/child-observations.js +114 -0
  103. package/dist/runs/shared/claude-code.js +199 -0
  104. package/dist/runs/shared/completion-guard.js +31 -0
  105. package/dist/runs/shared/dynamic-fanout.js +274 -0
  106. package/dist/runs/shared/history-index.js +72 -0
  107. package/dist/runs/shared/mcp-direct-tool-allowlist.js +334 -0
  108. package/dist/runs/shared/model-fallback.js +185 -0
  109. package/dist/runs/shared/mutating-tool-guard.js +170 -0
  110. package/dist/runs/shared/native-finalization.js +101 -0
  111. package/dist/runs/shared/native-usage.js +153 -0
  112. package/dist/runs/shared/nested-events.js +700 -0
  113. package/dist/runs/shared/nested-path.js +48 -0
  114. package/dist/runs/shared/nested-render.js +108 -0
  115. package/dist/runs/shared/parallel-utils.js +61 -0
  116. package/dist/runs/shared/parent-receipts.js +68 -0
  117. package/dist/runs/shared/parent-usage.js +121 -0
  118. package/dist/runs/shared/pi-args.js +310 -0
  119. package/dist/runs/shared/pi-spawn.js +52 -0
  120. package/dist/runs/shared/run-history-queries.js +45 -0
  121. package/dist/runs/shared/run-history.js +103 -0
  122. package/dist/runs/shared/run-id-ambiguity.js +4 -0
  123. package/dist/runs/shared/run-records.js +679 -0
  124. package/dist/runs/shared/session-cwd-preload.js +33 -0
  125. package/dist/runs/shared/single-output.js +222 -0
  126. package/dist/runs/shared/streaming-text.js +15 -0
  127. package/dist/runs/shared/structured-output.js +55 -0
  128. package/dist/runs/shared/subagent-control.js +179 -0
  129. package/dist/runs/shared/subagent-prompt-runtime.js +197 -0
  130. package/dist/runs/shared/subagent-tool-loop-guard.js +66 -0
  131. package/dist/runs/shared/supervisor-questions.js +320 -0
  132. package/dist/runs/shared/workflow-graph.js +214 -0
  133. package/dist/runs/shared/workflow-policy.js +84 -0
  134. package/dist/runs/shared/worktree.js +525 -0
  135. package/dist/shared/agent-context-policy.js +126 -0
  136. package/dist/shared/artifacts.js +96 -0
  137. package/dist/shared/atomic-json.js +13 -0
  138. package/dist/shared/cooperative.js +20 -0
  139. package/dist/shared/execution-cwd.js +14 -0
  140. package/dist/shared/file-coalescer.js +21 -0
  141. package/dist/shared/fork-context.js +49 -0
  142. package/dist/shared/formatters.js +85 -0
  143. package/dist/shared/journal-reader.js +407 -0
  144. package/dist/shared/lazy-tools.js +32 -0
  145. package/dist/shared/model-info.js +68 -0
  146. package/dist/shared/native-session.js +15 -0
  147. package/dist/shared/native-tui.js +18 -0
  148. package/dist/shared/native-typebox.js +20 -0
  149. package/dist/shared/post-exit-stdio-guard.js +197 -0
  150. package/dist/shared/prompt-sections.js +8 -0
  151. package/dist/shared/session-entries.js +52 -0
  152. package/dist/shared/session-identity.js +14 -0
  153. package/dist/shared/settings.js +254 -0
  154. package/dist/shared/status-format.js +111 -0
  155. package/dist/shared/temp-root.js +114 -0
  156. package/dist/shared/types.js +207 -0
  157. package/dist/shared/ui-mode.js +3 -0
  158. package/dist/shared/utils.js +334 -0
  159. package/dist/slash/prompt-template-bridge.js +298 -0
  160. package/dist/slash/slash-bridge.js +116 -0
  161. package/dist/slash/slash-commands.js +607 -0
  162. package/dist/slash/slash-live-state.js +246 -0
  163. package/dist/tui/action-hints.js +75 -0
  164. package/dist/tui/agent-history.js +197 -0
  165. package/dist/tui/agent-view.js +1656 -0
  166. package/dist/tui/render.js +1515 -0
  167. package/docs/intercom.md +579 -0
  168. package/docs/performance.md +121 -0
  169. package/package.json +101 -4
  170. package/prompts/gather-context-and-clarify.md +14 -0
  171. package/prompts/parallel-cleanup.md +62 -0
  172. package/prompts/parallel-context-build.md +56 -0
  173. package/prompts/parallel-handoff-plan.md +62 -0
  174. package/prompts/parallel-research.md +51 -0
  175. package/prompts/parallel-review.md +59 -0
  176. package/prompts/review-loop.md +42 -0
  177. package/scripts/build.mjs +134 -0
  178. package/scripts/check-compat.mjs +48 -0
  179. package/scripts/compat-host.mjs +19 -0
  180. package/scripts/linux-smoke.sh +51 -0
  181. package/scripts/local-install-smoke.mjs +66 -0
  182. package/scripts/native-package-smoke.mjs +82 -0
  183. package/scripts/package-smoke.mjs +205 -0
  184. package/scripts/prepare.mjs +67 -0
  185. package/scripts/real-pi-smoke.mjs +415 -0
  186. package/scripts/run-tests.mjs +149 -0
  187. package/skills/pi-intercom/SKILL.md +113 -0
  188. package/skills/pi-intercom/evals/evals.json +29 -0
  189. package/skills/pi-intercom/evals/trigger-evals.json +47 -0
  190. package/skills/pi-intercom/references/peer-sessions.md +69 -0
  191. package/skills/pi-subagents/SKILL.md +76 -0
  192. package/skills/pi-subagents/evals/evals.json +29 -0
  193. package/skills/pi-subagents/evals/trigger-evals.json +42 -0
  194. package/skills/pi-subagents/references/full-orchestration-guide.md +863 -0
  195. package/src/agents/agent-management.ts +813 -0
  196. package/src/agents/agent-scope.ts +7 -0
  197. package/src/agents/agent-selection.ts +23 -0
  198. package/src/agents/agent-serializer.ts +99 -0
  199. package/src/agents/agents.ts +916 -0
  200. package/src/agents/chain-serializer.ts +329 -0
  201. package/src/agents/frontmatter.ts +21 -0
  202. package/src/agents/identity.ts +30 -0
  203. package/src/agents/skills.ts +637 -0
  204. package/src/extension/build-info.ts +2 -0
  205. package/src/extension/compact-tools.ts +114 -0
  206. package/src/extension/config.ts +23 -0
  207. package/src/extension/control-notices.ts +47 -0
  208. package/src/extension/doctor.ts +171 -0
  209. package/src/extension/fanout-child.ts +312 -0
  210. package/src/extension/index.ts +649 -0
  211. package/src/extension/schemas.ts +444 -0
  212. package/src/extension/tool-input.ts +19 -0
  213. package/src/extension/tool-result.ts +16 -0
  214. package/src/history/canonical-result.ts +62 -0
  215. package/src/history/database.ts +59 -0
  216. package/src/history/index.ts +152 -0
  217. package/src/history/ingest.ts +332 -0
  218. package/src/history/queries.ts +241 -0
  219. package/src/history/store.ts +203 -0
  220. package/src/history/types.ts +166 -0
  221. package/src/history/worker.ts +317 -0
  222. package/src/intercom/intercom-bridge.ts +123 -0
  223. package/src/intercom/live-intercom.ts +104 -0
  224. package/src/intercom/result-intercom.ts +429 -0
  225. package/src/pi-intercom/agent-dir.ts +9 -0
  226. package/src/pi-intercom/broker/broker.ts +463 -0
  227. package/src/pi-intercom/broker/client.ts +558 -0
  228. package/src/pi-intercom/broker/framing.ts +77 -0
  229. package/src/pi-intercom/broker/paths.ts +47 -0
  230. package/src/pi-intercom/broker/pid.ts +59 -0
  231. package/src/pi-intercom/broker/spawn.ts +248 -0
  232. package/src/pi-intercom/config.ts +142 -0
  233. package/src/pi-intercom/index.ts +2929 -0
  234. package/src/pi-intercom/reply-tracker.ts +211 -0
  235. package/src/pi-intercom/session-targets.ts +172 -0
  236. package/src/pi-intercom/subagent-live-events.ts +133 -0
  237. package/src/pi-intercom/topics.ts +125 -0
  238. package/src/pi-intercom/types.ts +271 -0
  239. package/src/pi-intercom/ui/compose.ts +289 -0
  240. package/src/pi-intercom/ui/inline-message.ts +92 -0
  241. package/src/pi-intercom/ui/session-list.ts +139 -0
  242. package/src/runs/background/async-control.ts +89 -0
  243. package/src/runs/background/async-execution.ts +850 -0
  244. package/src/runs/background/async-job-tracker.ts +385 -0
  245. package/src/runs/background/async-result-file.ts +62 -0
  246. package/src/runs/background/async-resume.ts +333 -0
  247. package/src/runs/background/async-status.ts +481 -0
  248. package/src/runs/background/completion-dedupe.ts +79 -0
  249. package/src/runs/background/completion-delivery.ts +195 -0
  250. package/src/runs/background/notify.ts +123 -0
  251. package/src/runs/background/parallel-groups.ts +53 -0
  252. package/src/runs/background/result-watcher.ts +423 -0
  253. package/src/runs/background/run-id-resolver.ts +69 -0
  254. package/src/runs/background/run-status.ts +384 -0
  255. package/src/runs/background/stale-run-reconciler.ts +369 -0
  256. package/src/runs/background/subagent-runner-launcher.ts +56 -0
  257. package/src/runs/background/subagent-runner.ts +2053 -0
  258. package/src/runs/background/top-level-async.ts +13 -0
  259. package/src/runs/foreground/chain-clarify.ts +1340 -0
  260. package/src/runs/foreground/clarify-invocation.ts +77 -0
  261. package/src/runs/foreground/execution-input.ts +467 -0
  262. package/src/runs/foreground/foreground-control.ts +821 -0
  263. package/src/runs/foreground/question-control.ts +70 -0
  264. package/src/runs/foreground/run-async-path.ts +243 -0
  265. package/src/runs/foreground/subagent-executor.ts +501 -0
  266. package/src/runs/foreground/subagent-params.ts +320 -0
  267. package/src/runs/foreground/wait-run.ts +121 -0
  268. package/src/runs/shared/acceptance-contract.ts +257 -0
  269. package/src/runs/shared/acceptance-evaluation.ts +275 -0
  270. package/src/runs/shared/acceptance-finalization.ts +353 -0
  271. package/src/runs/shared/acceptance-reports.ts +152 -0
  272. package/src/runs/shared/acceptance.ts +33 -0
  273. package/src/runs/shared/chain-outputs.ts +114 -0
  274. package/src/runs/shared/child-attempt.ts +623 -0
  275. package/src/runs/shared/child-execution-cwd.ts +91 -0
  276. package/src/runs/shared/child-observations.ts +99 -0
  277. package/src/runs/shared/claude-code.ts +243 -0
  278. package/src/runs/shared/completion-guard.ts +35 -0
  279. package/src/runs/shared/dynamic-fanout.ts +295 -0
  280. package/src/runs/shared/history-index.ts +69 -0
  281. package/src/runs/shared/mcp-direct-tool-allowlist.ts +376 -0
  282. package/src/runs/shared/model-fallback.ts +219 -0
  283. package/src/runs/shared/mutating-tool-guard.ts +194 -0
  284. package/src/runs/shared/native-finalization.ts +128 -0
  285. package/src/runs/shared/native-usage.ts +113 -0
  286. package/src/runs/shared/nested-events.ts +752 -0
  287. package/src/runs/shared/nested-path.ts +52 -0
  288. package/src/runs/shared/nested-render.ts +119 -0
  289. package/src/runs/shared/parallel-utils.ts +153 -0
  290. package/src/runs/shared/parent-receipts.ts +59 -0
  291. package/src/runs/shared/parent-usage.ts +121 -0
  292. package/src/runs/shared/pi-args.ts +350 -0
  293. package/src/runs/shared/pi-spawn.ts +52 -0
  294. package/src/runs/shared/run-history-queries.ts +44 -0
  295. package/src/runs/shared/run-history.ts +93 -0
  296. package/src/runs/shared/run-id-ambiguity.ts +4 -0
  297. package/src/runs/shared/run-records.ts +607 -0
  298. package/src/runs/shared/session-cwd-preload.ts +27 -0
  299. package/src/runs/shared/single-output.ts +267 -0
  300. package/src/runs/shared/streaming-text.ts +18 -0
  301. package/src/runs/shared/structured-output.ts +68 -0
  302. package/src/runs/shared/subagent-control.ts +219 -0
  303. package/src/runs/shared/subagent-prompt-runtime.ts +201 -0
  304. package/src/runs/shared/subagent-tool-loop-guard.ts +89 -0
  305. package/src/runs/shared/supervisor-questions.ts +372 -0
  306. package/src/runs/shared/workflow-graph.ts +220 -0
  307. package/src/runs/shared/workflow-policy.ts +125 -0
  308. package/src/runs/shared/worktree.ts +635 -0
  309. package/src/shared/agent-context-policy.ts +184 -0
  310. package/src/shared/artifacts.ts +95 -0
  311. package/src/shared/atomic-json.ts +16 -0
  312. package/src/shared/cooperative.ts +21 -0
  313. package/src/shared/execution-cwd.ts +14 -0
  314. package/src/shared/file-coalescer.ts +29 -0
  315. package/src/shared/fork-context.ts +68 -0
  316. package/src/shared/formatters.ts +84 -0
  317. package/src/shared/journal-reader.ts +333 -0
  318. package/src/shared/lazy-tools.ts +36 -0
  319. package/src/shared/model-info.ts +81 -0
  320. package/src/shared/native-session.ts +8 -0
  321. package/src/shared/native-tui.ts +10 -0
  322. package/src/shared/native-typebox.ts +14 -0
  323. package/src/shared/post-exit-stdio-guard.ts +204 -0
  324. package/src/shared/prompt-sections.ts +10 -0
  325. package/src/shared/session-entries.ts +49 -0
  326. package/src/shared/session-identity.ts +18 -0
  327. package/src/shared/settings.ts +384 -0
  328. package/src/shared/status-format.ts +123 -0
  329. package/src/shared/temp-root.ts +107 -0
  330. package/src/shared/types.ts +1259 -0
  331. package/src/shared/ui-mode.ts +5 -0
  332. package/src/shared/utils.ts +342 -0
  333. package/src/slash/prompt-template-bridge.ts +408 -0
  334. package/src/slash/slash-bridge.ts +178 -0
  335. package/src/slash/slash-commands.ts +617 -0
  336. package/src/slash/slash-live-state.ts +292 -0
  337. package/src/tui/action-hints.ts +69 -0
  338. package/src/tui/agent-history.ts +210 -0
  339. package/src/tui/agent-view.ts +1323 -0
  340. package/src/tui/render.ts +1550 -0
  341. package/tsconfig.build.json +12 -0
  342. package/tsconfig.json +19 -0
@@ -0,0 +1,121 @@
1
+ # Long-session performance
2
+
3
+ ## Current behavior
4
+
5
+ Native journals and canonical run/control/receipt files remain the sources of truth. SQLite supplies private browse observations, not a new execution owner, completion receipt, billing authority or transcript format. Installing the extension does not adopt unrelated archives or remove provider and queue waits.
6
+
7
+ Startup recovers saved ownership, unanswered questions and Intercom receipts in small batches, allowing input between batches. Queued Intercom delivery also yields between batches, preserving followers before the final wake-up and staging new arrivals durably until the batch finishes. Retention cleanup uses asynchronous filesystem operations. Tools capture their invocation directory before awaiting restoration, and coordination publishes the current session name even if it changes during recovery. Checkpoint reconciliation remains synchronous and strict. Recovery still checks the complete eligible history and legacy records, without increasing or suppressing the host's performance-warning budget. A single recovery record, native append/projection or integrity scan remains atomic.
8
+
9
+ ### Indexed browsing and lazy Agents work
10
+
11
+ - A separate Node process incrementally indexes only the current saved parent's admitted runs and linked native sources. A fresh session with no owned work starts no history process or database until it browses. No directory-wide transcript backfill runs at startup.
12
+ - List filters and attention/newest/oldest ordering apply globally before a bounded page. Ordinary tool lists return 20 runs by default, at most 100; the Agents picker loads 50 runs and searches full assignments, not just shortened labels. Latest-assignment queries retain unsuperseded siblings while hiding older continuation attempts.
13
+ - The parent UI does not scan child journals on startup, ticks, filtering or pagination. Only an opened conversation loads a 100-physical-record page; components are retained for that page. Full details and contextual Reply validate selected native byte references off-thread, including paired tool results outside the current page. Explicit navigation supersedes older requests; background refreshes are coalesced and retain the settled display rather than briefly adding loading rows. Reopening the picker restores its visible filter and page.
14
+ - Catch-up, degraded sources, loading, no matches and unavailable history are distinct states. F5 explicitly retries. Drafts, reading anchors, unread boundaries and pins survive same-parent reopen; a changed owner or abandoned overlay cannot accept late results.
15
+ - Search indexes saved visible text, not thinking, tool arguments, image payloads, hidden custom data or provider fields. Terminal sequences are removed incrementally before tokenization, including sequences split across read/parser chunks. Its grammar is lexical words or one quoted phrase. Unquoted words must all occur in the same native record, across any of its visible fields/windows; quoted phrases must remain contiguous in one field. Each record contributes one excerpt per matching child attempt. Filters and attempt terminal/time boundaries apply before ranking/paging. Common terms may still require broad matching and sorting: a small result page is not a constant-work guarantee. Deadlines and cancellation stop the owned history process, which can reopen and replay committed index progress.
16
+ - Browse freshness is never authoritative. Selected controls recheck canonical owner facts before acting. Human-message delivery and a later nonempty assistant reply are separate observations. Receipt integrity and native accounting safeguards remain unchanged.
17
+
18
+ ### Storage, budgets and recovery
19
+
20
+ History projections use the built-in `node:sqlite` binding, qualified at SQLite **3.53.4** with Node **24.21.0**, WAL and `synchronous=FULL`. Other binding versions fail explicitly rather than fall back to synchronous journal queries. Databases live in a private local-filesystem `history-index` directory; symlinked databases/directories are rejected. Each owner selects a disposable generation through its manifest. Corrupt browse generations are replaced without renaming/unlinking an open SQLite database or rewriting native sources; old generations remain private for diagnosis.
21
+
22
+ Incremental ingestion has one writer per database generation, coordinated by a SQLite transaction in a separate private `.ingest.sqlite` database. The lock spans staging and publication but never locks the browse database between pump steps. Competing workers keep serving queries and retry without busy-spinning. Process exit releases the lock through SQLite; the next writer discards unpublished staging and resumes at the committed cursor, without PID leases, time-based lock stealing or unlinking open databases. Schema upgrades rebuild older derived indexes, including apparently current indexes affected by lost staging in schema 4.
23
+
24
+ A published source cursor and its indexed entries commit together, and publication must actually update the staged entry before advancing the cursor. LF framing controls publication independently of malformed-record tolerance. Replacement, truncation, deletion and prefix changes invalidate observations. Ingestion scans bytes in bounded chunks and limits assembled previews to 64 levels, 16,384 nodes, 4,096 array positions and 512-character keys. Over-budget records are explicitly degraded, not silently converted into trustworthy evidence; later complete records still index. Selected full native records and canonical saved output have a **16 MiB** detail budget. Concurrent output growth cannot expand a selected read beyond its validated snapshot.
25
+
26
+ Best-effort timeout samples use a separate `run-timing.sqlite` metadata database. Writer transactions serialize import, insertion and per-agent retention of the latest **1,000** samples. Read-only indexed queries never rotate storage. The old `run-history.jsonl` remains untouched; reads and the first actual writer's import use at most the latest **1 MiB** of complete LF records. This replaces the unlocked reader-side rotation that could erase concurrent writes or another agent's samples. It is a metadata migration, not a canonical run-state migration; older legacy samples remain on disk outside the estimation window.
27
+
28
+ ### Regression proof
29
+
30
+ The changed boundaries are exercised through real extension functions and registered SDK tools with synthetic isolated data, not personal transcripts or provider inference:
31
+
32
+ - 20 and 227 genuinely owned runs beside 8,000 unrelated records: Agents startup does no parent-thread child transcript reads or global question listing; only the selected conversation is formatted.
33
+ - Native extension startup beside 2,048 foreign owner directories services input during discovery and restores only the current parent's saved runs and unanswered questions.
34
+ - Native Intercom reload restores all 1,024 historical receipts while servicing input. Cleared-queue recovery also services input before its 100 followers finish appending, retaining each message once and one final wake-up across an in-flight reload or a cleared busy handoff. New results and explicit steers are staged before acknowledgement and handed to native steering for the next tool boundary; ordinary queued and passive arrivals wait.
35
+ - 125 owned assignments: global filtering finds an item beyond the first two picker pages; all later pages remain reachable without UI-thread source access.
36
+ - 65 retained runs: off-page reads/stats and migration scans are zero while displayed controls, questions, review and continuation identities remain fresh.
37
+ - Warm indexed list/search queries perform no source checks, opens or canonical projections. Cold ingestion and explicit refresh still do necessary verification off-thread.
38
+ - A 512 MiB discarded native field preserves exact eligible usage/IDs/configuration/history, with unchanged source bytes, under a **96 MiB** heap limit. Structural over-budget image/deep/key records degrade explicitly while later visible text remains searchable.
39
+ - Completed-attempt search cannot return a successor's later text from a shared physical source. Full selected details reject missing/replaced/truncated sources; canonical output reads reject concurrent growth beyond their snapshot.
40
+ - Competing history processes preserve staged configuration/text on normal completion and recover after a writer is killed. Schema-4 indexes with intact cursors but missing entries rebuild from unchanged journals.
41
+ - Search covers ANSI-colored words, multi-chunk control sequences, distant terms in a single record, separate visible fields, phrase boundaries and record-level pagination. Picker reopen/clear retains a visible filter; delayed idle refreshes leave dock height unchanged.
42
+ - Four independent timing writers preserve each completed sample, another agent's samples, per-agent retained row counts and database integrity. A legacy snapshot read cannot erase an acknowledged write.
43
+ - Native tool loading covers list/history/search validation, owned paging and same-parent reload on both compact and advanced routes. UI regressions cover narrow/wide native layouts, full reports/Reply, loading navigation, saved anchors and disposal.
44
+
45
+ Primary owners are `test/integration/{history-index,owned-run-list,agent-interaction,tool-activation,lazy-coordination,session-resume-cost}.test.ts` and `test/unit/{run-history,journal-reader,temp-root-cleanup}.test.ts`. Run the [local validation](../README.md#local-validation) against an explicitly selected coherent host graph. Operation counts are more repeatable than timing thresholds.
46
+
47
+ ## Receipt and loadout work
48
+
49
+ A completion-recovery batch shares one SHA-verified parent receipt snapshot only within its synchronous stack. Parent append/count/leaf changes refresh that snapshot, and it is discarded before any awaited delivery resumes. Receipt identities are indexed once per snapshot; unchanged hits do not each hash the whole journal. The eight-hit regression beside a 1,051,980-byte parent reads at most three journal lengths (initial parse/hash, then verification per yielded batch), instead of verification per hit. Awaited delivery rechecks external journal changes even when the in-memory count and leaf are unchanged. SHA, LF publication, replacement/truncation and same-stamp-edit guards remain mandatory.
50
+
51
+ Native default-active declarations keep advanced orchestration and Intercom lazy without startup deactivation. A small initial-SDK-resume fallback restores this package's declared tools because official 1.0 does not restore its saved loadout during creation. Native tree/reload selection remains authoritative, and activation only adds available owned tools, never excluded ones.
52
+
53
+ The Agents dock polls while live work, questions, selected/pinned conversations or delivery outboxes need observation. Visited terminal rows reuse their observed metadata until their run changes; full completed history loads on selection. With 50 visited rows (49 terminal), two unchanged refreshes query only the live row; pinned, selected, question, outbox and changed terminal metadata remain observable. The 20/227-terminal-row fixtures also prove three idle ticks request no parent redraw. These are bounded-work optimizations, not archive-size or provider-latency guarantees.
54
+
55
+ ## Historical 0.43.1 baseline
56
+
57
+ The earlier 0.43.1 fixes removed repeated completed-history projections, continuation recursion, native observation matching, nested polling, and result/receipt polling. Their same-host recheck on fork `76dfe3d1` (Node 24.21.0) remains useful historical evidence; it is not a measurement of the new SQLite browse implementation:
58
+
59
+ | Synthetic operation | Before 0.43.1 | 0.43.1 |
60
+ | --- | --- | --- |
61
+ | 100 completed 2,000-entry histories, five refreshes | 1,000,000 timestamp parses; 1,005 ms | 0 timestamp parses; 1.6 ms |
62
+ | 1,000 continuations, one visible task | 500,500 identity resolutions | 1,000 |
63
+ | 10,000 delivered/billed runs, three polls | 30,003 existence checks | 3 directory checks |
64
+ | 40 unchanged foreign files, three polls | 120 decodes | 40 initial decodes |
65
+ | 20,000 parent entries, ten owner checks | 400,020 visits, 20 scans | 40,002 visits, two startup scans |
66
+ | 1,500 retained nested events, unchanged poll | 500 event rereads and one registry rewrite | Neither |
67
+ | Nested projection in one job poll | Three registry reads | One |
68
+ | Ten 100-card history windows | 1,001 cached components | 101, including the assignment |
69
+
70
+ Cold factory startup did not measurably change in that comparison: five isolated offline CLI launches ranged from 410–605 ms before and 411–437 ms after. The minimum difference was below run-to-run variation.
71
+
72
+ ## Necessary costs and limits
73
+
74
+ Cold recovery still enumerates genuine owner handles and verifies relevant published bytes. Mutable native prefixes require integrity validation before appended suffix reuse; stat-only caches or unchecked SQL negative receipt lookups cannot replace that safeguard. Selected controls and canonical receipt/accounting reconciliation remain separate from browsing.
75
+
76
+ Pi 1.0 still eagerly loads native session bodies at its own startup; extension installation alone cannot remove that host cost. Explicit fork context still copies and publishes each sibling, with required fsync. An explicit full individual record must fit its detail budget and the consumer's heap.
77
+
78
+ Full-archive backfill/capacity, sustained contention, power-loss durability and cross-platform performance are not qualified by these macOS/APFS synthetic regressions. No journal deletion, live archive migration, installed-runtime activation or inference request is part of this work. Intentional tool/queue boundaries, provider response time, host rendering and other extensions remain separate possible costs.
79
+
80
+ ## Cached-input traffic and delegation
81
+
82
+ This section supersedes the investigation in [PR #112](https://github.com/fitchmultz/pi-subagents/pull/112), which inspected `29903ad` before Pi 1.0 modernization. The architecture below was checked against released `4f288484` (0.44.0). No private session journals, invoices or provider requests were inspected. It explains possible traffic, not the cause of a particular account's usage or its dollar cost.
83
+
84
+ ### What grows the provider input
85
+
86
+ - **Fresh is the default.** A fresh child starts without the parent's conversation. Project context, skills and the child's system prompt can still add substantial input. Explicit `context` overrides the profile; the bundled oracle alone defaults to `fork`. Inspect effective profiles and user/project overrides rather than assuming installed defaults.
87
+ - **Fork is a branch, not a summary.** `src/shared/fork-context.ts` creates a separate native branched session per child index. The child uses inherited conversation context plus its new task, subject to Pi's native context/compaction rules and child filtering. Fork failure is explicit, not a fallback to the parent's file.
88
+ - **Each child is a separate CLI tool loop.** Pi-backed children use `pi --mode json -p`; Claude-backed children use `claude -p`. Later model turns can send a large stable input prefix again. The extension does not implement provider prompt caching.
89
+ - **Async work can overlap.** The root defaults to async, so the parent can continue making requests while children run. A fork is a launch-time snapshot; later parent turns do not update an already-running child.
90
+ - **Filtering can change cache sharing.** Child context filtering removes parent-only orchestration messages and tool history where applicable. Native prompt fixtures prove unchanged-history prefix preservation and a changed prefix after filtering; neither is a guarantee that a provider will reuse a cache. A changed prefix does not establish that the entire context must be cache-written.
91
+ - **Results can enlarge later input.** Inline results, chain substitutions, completion messages and supervisor notices add parent/next-child text. Some notices or deliveries can trigger a parent turn. Parallel completion is grouped; terminal async completion-guard notices leave the automatic wakeup to their matching result.
92
+ - **Fanout is not a daily budget.** Top-level `tasks` uses `parallel.maxTasks` (default 8) after repeat expansion, with default concurrency 4. Static chain `parallel`/`count` is not covered by that top-level size limit. Dynamic fanout requires `expand.maxItems` or `config.chain.dynamicFanout.maxItems`; the per-step limit takes precedence. Bundled profiles disallow nested delegation; explicit opt-in remains depth-bounded. Successful sequential launches are not subject to a daily launch quota.
93
+
94
+ Sources: `src/runs/{foreground/run-async-path,foreground/execution-input,shared/child-attempt,shared/subagent-prompt-runtime}.ts`, `src/shared/agent-context-policy.ts`, `agents/oracle.md`, and `test/fixtures/native-prompt-sections.mjs`.
95
+
96
+ ### Arithmetic, not attribution
97
+
98
+ For a hypothetical constant **500,000 cached tokens per request**:
99
+
100
+ ```text
101
+ 4.26 billion cache-read tokens / 500,000 = 8,520 requests
102
+ 11.2 million output tokens / 8,520 = 1,314.55 output tokens/request
103
+ ```
104
+
105
+ If "97% hit" means cached tokens divided by cached plus uncached input tokens, the corresponding uncached input is `4.26 billion × 0.03 / 0.97 = 131.75 million`, or about `15,463.92` per request. A request-based hit percentage would not support that calculation.
106
+
107
+ | Hypothetical steady workload | Cache-read tokens |
108
+ | --- | ---: |
109
+ | One 500k-prefix session, one request/10 seconds for 24 hours | 4.32 billion |
110
+ | Parent plus eight 500k-prefix children, one request/30 seconds each for 8 hours | 4.32 billion |
111
+ | Eight 50k-prefix fresh children, one request/30 seconds each for 8 hours | 384 million |
112
+
113
+ These assumptions include sustained activity and a full cache hit on that prefix; they are not measured workloads, throughput guarantees or pricing estimates. Token counts alone cannot establish dollars, double billing, a spawn loop, or which sessions made the requests.
114
+
115
+ ### Accounting and useful checks
116
+
117
+ `src/runs/shared/native-usage.ts` excludes inherited launch-baseline entries and nonbillable checkpoints, then validates and deduplicates new native contributions. Excluding old journal usage does **not** make newly sending inherited context free. Pi 1.0 attribution uses finalized execution/wait tool results, not the removed `recordUsage` hook. Background notifications alone do not enter parent totals. Claude totals may remain explicitly accounting-incomplete when per-category evidence is unavailable. See [usage accounting](../README.md#usage-accounting); local attribution is not an additional provider request.
118
+
119
+ To investigate an actual spike, compare provider usage for the relevant time/model/account with parent and child native usage, launch counts, effective `fresh`/`fork` settings and context sizes. Do not sum attributed parent totals and the same child totals as independent traffic. Keep private prompts, journals and credentials out of public issues.
120
+
121
+ Use existing controls deliberately: prefer fresh context when a bounded handoff suffices, use file-only output when the parent needs references rather than full text, and set suitable concurrency and child runtime/token limits. `maxTokens` is best-effort and is not an invoice or whole-account spending cap. This investigation changes no profile defaults, fork capability, notice routing or quotas.
package/package.json CHANGED
@@ -1,6 +1,103 @@
1
1
  {
2
2
  "name": "@fitchmultz/pi-subagents",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.44.4",
4
+ "description": "Pi extension for subagent orchestration and local session coordination",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/fitchmultz/pi-subagents.git"
10
+ },
11
+ "homepage": "https://github.com/fitchmultz/pi-subagents#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/fitchmultz/pi-subagents/issues"
14
+ },
15
+ "keywords": [
16
+ "pi-package",
17
+ "pi",
18
+ "pi-coding-agent",
19
+ "subagents",
20
+ "ai",
21
+ "agents",
22
+ "cli",
23
+ "intercom",
24
+ "coordination"
25
+ ],
26
+ "files": [
27
+ "dist",
28
+ "src/**/*.ts",
29
+ "tsconfig.build.json",
30
+ "tsconfig.json",
31
+ "scripts/",
32
+ "agents/",
33
+ "skills/**/*",
34
+ "prompts/**/*",
35
+ "docs/intercom.md",
36
+ "docs/performance.md",
37
+ "README.md",
38
+ "CHANGELOG.md"
39
+ ],
40
+ "scripts": {
41
+ "build": "node ./scripts/build.mjs",
42
+ "prepare": "node ./scripts/prepare.mjs",
43
+ "test": "npm run test:unit",
44
+ "test:unit": "node scripts/run-tests.mjs unit",
45
+ "test:integration": "node scripts/run-tests.mjs integration",
46
+ "test:all": "node scripts/run-tests.mjs all",
47
+ "check:compat": "node scripts/check-compat.mjs",
48
+ "typecheck": "tsc --noEmit",
49
+ "smoke:package": "node scripts/package-smoke.mjs",
50
+ "smoke:install": "node scripts/local-install-smoke.mjs",
51
+ "ci": "npm run typecheck && npm run smoke:package && npm run smoke:install && npm run test:all",
52
+ "smoke:real-pi": "node scripts/real-pi-smoke.mjs"
53
+ },
54
+ "pi": {
55
+ "extensions": [
56
+ "./dist/extension/index.js",
57
+ "./dist/pi-intercom/index.js"
58
+ ],
59
+ "skills": [
60
+ "./skills"
61
+ ]
62
+ },
63
+ "peerDependencies": {
64
+ "@earendil-works/pi-agent-core": "*",
65
+ "@earendil-works/pi-ai": "*",
66
+ "@earendil-works/pi-coding-agent": "*",
67
+ "@earendil-works/pi-tui": "*",
68
+ "typebox": "*"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "@earendil-works/pi-agent-core": {
72
+ "optional": true
73
+ },
74
+ "@earendil-works/pi-ai": {
75
+ "optional": true
76
+ },
77
+ "@earendil-works/pi-coding-agent": {
78
+ "optional": true
79
+ },
80
+ "@earendil-works/pi-tui": {
81
+ "optional": true
82
+ },
83
+ "typebox": {
84
+ "optional": true
85
+ }
86
+ },
87
+ "devDependencies": {
88
+ "@earendil-works/pi-agent-core": "1.0.0",
89
+ "@earendil-works/pi-ai": "1.0.0",
90
+ "@earendil-works/pi-coding-agent": "1.0.0",
91
+ "@earendil-works/pi-tui": "1.0.0",
92
+ "@types/node": "24.19.1",
93
+ "typebox": "1.3.34",
94
+ "typescript": "7.0.2"
95
+ },
96
+ "publishConfig": { "access": "public" },
97
+ "engines": {
98
+ "node": ">=24.21.0"
99
+ },
100
+ "dependencies": {
101
+ "stream-json": "3.7.0"
102
+ }
103
+ }
@@ -0,0 +1,14 @@
1
+ ---
2
+ description: Use subagents to gather context, then ask clarifying questions
3
+ argument-hint: "[request]"
4
+ ---
5
+
6
+ Based on our discussion and my intent, launch focused context-gathering subagents before planning or implementing.
7
+
8
+ Use `scout` to inspect the relevant local files, existing patterns, constraints, tests, and likely integration points. Use `researcher` when external docs, recent sources, ecosystem context, or primary evidence would improve the answer.
9
+
10
+ Give each subagent a specific meta prompt. Ask them to return concise findings plus the remaining clarification questions that matter for implementation confidence.
11
+
12
+ After they return, synthesize what we know and use the available clarification tool (`ask_question` in pi) to ask only unresolved questions that affect scope, acceptance, constraints, or implementation.
13
+
14
+ ${ARGUMENTS:-infer the request from the current conversation and repository context}
@@ -0,0 +1,62 @@
1
+ ---
2
+ description: Parallel cleanup review
3
+ argument-hint: "[scope]"
4
+ ---
5
+
6
+ Run a fresh-context parallel cleanup review of the current work.
7
+
8
+ Use the `subagent` tool. First inspect available agents/skills if needed, then launch two reviewer subagents in parallel with `context: "fresh"`. Do not use forked context unless I explicitly ask for it. Reviewers must inspect the repository, relevant instructions, and current diff directly from files and commands. They must not rely on the main conversation history.
9
+
10
+ Launch cleanup reviewers as separate async runs so each completion wakes the parent. Continue useful parent work while they run; if none remains, end the turn and wait instead of polling. This also applies when an incomplete active Pi goal needs cleanup review: resume the goal after automatic completion delivery, not before the evidence arrives. Omit `acceptance` from these review-only tasks unless I explicitly request a same-session acceptance contract; it adds a finalization turn and does not provide independent review. A timed-out reviewer is incomplete review, never sign-off.
11
+
12
+ Do not write reviewer output files into the repository unless I explicitly ask for artifacts. Prefer `output: false` for each reviewer task.
13
+
14
+ Reviewer 1: deslop pass.
15
+
16
+ If the `deslop` skill is available, pass it to this reviewer. If not, inline the guidance below. Ask this reviewer to look for AI-slop patterns in the changed scope:
17
+ - comments that restate code, placeholder text, stale rationale, or debug leftovers;
18
+ - defensive checks that hide useful errors, return vague defaults, or validate trusted internal data after a real boundary was already crossed;
19
+ - type escapes, broad casts, duplicated type definitions, or object-bag typing where a local source-of-truth type exists;
20
+ - style drift from nearby non-slop code and project instructions;
21
+ - generated-sounding docs, changelog text, UI copy, status text, or test names;
22
+ - pass-through wrappers, dead helpers, duplicate helper signatures, duplicated test harness setup, or abstractions that do not enforce an invariant;
23
+ - UI or CLI copy that is noisy, vague, brittle, or makes the user do extra interpretation.
24
+
25
+ Tell this reviewer to treat tool output and slop-scan-style findings as leads, not verdicts. It should flag only concrete issues in the requested scope with evidence, severity, file/line references, and the smallest safe fix.
26
+
27
+ Reviewer 2: verbosity pass.
28
+
29
+ If the `verbosity-cleaner` skill is available, pass it to this reviewer. If not, inline the guidance below. Ask this reviewer to look for needless verbosity in code, tests, docs, status text, grouped messages, receipts, and changelog wording:
30
+ - single-use helpers that merely paraphrase an expression;
31
+ - temporary variables that only name obvious expressions;
32
+ - nested returns or branches that can become direct returns without hiding intent;
33
+ - multi-line cleanup scaffolding that can use a local direct pattern while preserving cleanup semantics;
34
+ - repeated boilerplate that can use an existing local fixture or a small local helper;
35
+ - tests that restate formatter details already covered at a cheaper layer;
36
+ - regression tests where one focused assertion would cover the bug but wrapper/API-adjacent tests only repeat the same claim;
37
+ - prose that says the same thing twice, sounds generic, or buries the important rule.
38
+
39
+ Tell this reviewer that shorter is only better when it is clearer and preserves behavior, error signals, cleanup semantics, useful invariants, and local style.
40
+
41
+ Both reviewers are review-only. They must not edit files unless I explicitly ask for a writer pass. Their response should be review feedback, not a context summary. Ask them to return concise, evidence-backed findings with file/line references and suggested fixes.
42
+
43
+ While reviewers run, do your own narrow inspection if useful. After they return, synthesize the feedback into:
44
+ - fixes worth doing now;
45
+ - optional improvements;
46
+ - feedback to ignore or defer, with a short reason.
47
+
48
+ Do not blindly apply every reviewer suggestion.
49
+
50
+ Autofix mode: if the invocation contains the exact word `autofix`, treat it as workflow control, not cleanup scope. Remove it before deciding the cleanup target. After synthesis, apply only fixes worth doing now, validate, and summarize. Do not apply optional improvements unless explicitly requested. If there are no fixes worth doing now, do not edit.
51
+
52
+ Without autofix mode, ask before applying fixes unless I already told you to address review feedback. When you ask, end with a compact numbered menu so I can respond with a number. Use wording suited to the findings, but include these choices when applicable:
53
+
54
+ ```text
55
+ Reply with [1], [2], or further instructions:
56
+ [1] Apply only the fixes worth doing now.
57
+ [2] Apply the fixes worth doing now plus optional improvements.
58
+ ```
59
+
60
+ Additional scope or focus from the template invocation:
61
+
62
+ $@
@@ -0,0 +1,56 @@
1
+ ---
2
+ description: Parallel context builders for planning handoff
3
+ argument-hint: "[request]"
4
+ ---
5
+
6
+ Launch fresh-context `context-builder` subagents in parallel to build grounded handoff context for planning or implementation.
7
+
8
+ Use the `subagent` tool in chain mode with a single parallel step, not top-level parallel tasks, so relative output files live under the temporary chain directory. Use `context: "fresh"` unless I explicitly ask for forked context. Give every parallel task a distinct `output` path, `label`, and `as` name, for example:
9
+
10
+ - `context-build/request-and-scope.md`
11
+ - `context-build/codebase-and-patterns.md`
12
+ - `context-build/validation-and-risks.md`
13
+
14
+ Use one phase such as `phase: "Context build"` for the parallel tasks so async status is readable. A later synthesis step can reference specific outputs with `{outputs.requestScope}`, `{outputs.codebasePatterns}`, and `{outputs.validationRisks}` instead of relying only on `{previous}`.
15
+
16
+ Do not write these context artifacts into the repository unless I explicitly ask for persistent files.
17
+
18
+ Treat the template arguments as the primary request, target, or focus:
19
+
20
+ ${ARGUMENTS:-infer the planning handoff scope from the current conversation and repository context}
21
+
22
+ If the invocation provides a URL, issue link, file path, plan path, or freeform request, read or fetch that target before assigning builder angles, then pass the target explicitly into every `context-builder` task.
23
+
24
+ Choose two or three strong builders based on the request. Prefer three only when the scope benefits from independent context slices. These are examples, not fixed defaults:
25
+
26
+ 1. Request and scope
27
+ Clarify the actual goal, user intent, constraints, non-goals, open questions, and decisions that affect the handoff.
28
+
29
+ 2. Codebase and patterns
30
+ Inspect relevant files, call paths, existing abstractions, tests, package constraints, and local conventions that the next agent must follow.
31
+
32
+ 3. Validation and risks
33
+ Identify likely failure modes, edge cases, test strategy, commands to run, dependency/API concerns, and escalation rules.
34
+
35
+ Adapt the angles when the request calls for it:
36
+ - Issue or PR URL: include issue requirements, acceptance criteria, linked discussion, and likely affected files.
37
+ - Plan file: include plan consistency, missing context, implementation sequence, and validation readiness.
38
+ - External API/library work: include current docs or primary sources through `web_search` when needed.
39
+ - Large refactor: include module boundaries, dependency direction, migration/cutover risks, and testability.
40
+ - UI/product work: include user flow, accessibility, copy, visual constraints, and implementation touchpoints.
41
+
42
+ Ask each builder to produce a compact handoff file with:
43
+ - relevant files and line ranges;
44
+ - key snippets or patterns, not full dumps;
45
+ - constraints and invariants;
46
+ - risks and unknowns;
47
+ - validation commands or next-best checks;
48
+ - a `meta-prompt` section for the next planner or role subagent.
49
+
50
+ After the builders return, synthesize their outputs into:
51
+ - the most important context the next agent needs;
52
+ - the recommended meta-prompt to use next;
53
+ - open questions or assumptions;
54
+ - the output artifact paths.
55
+
56
+ Do not start implementation from this command unless I explicitly ask for it.
@@ -0,0 +1,62 @@
1
+ ---
2
+ description: Parallel research/context builders into an implementation handoff plan
3
+ argument-hint: "[request]"
4
+ ---
5
+
6
+ Use parallel subagents to understand the request, compare any external references, inspect the local codebase, and produce a grounded implementation handoff plan with a final implementation-ready meta-prompt.
7
+
8
+ Primary request, target, or focus:
9
+
10
+ ${ARGUMENTS:-infer the implementation handoff scope from the current conversation and repository context}
11
+
12
+ Use `context: "fresh"` unless I explicitly ask for forked context. First read or fetch any URLs, issue links, PRs, screenshots, plans, docs, or local files mentioned in the request. Treat them as primary scope, not optional context.
13
+
14
+ Use the `subagent` tool in chain mode:
15
+
16
+ 1. First step: a parallel group.
17
+ - `researcher`, when the request includes external references, APIs, libraries, docs, current best practices, or prompt-guidance research.
18
+ - `context-builder` for local codebase context.
19
+ - Add a second `context-builder` only when the scope is large enough to benefit from a separate implementation-strategy pass.
20
+
21
+ 2. Second step: a synthesis `context-builder` that reads the parallel findings and writes the final handoff plan and meta-prompt.
22
+
23
+ Use distinct output paths, `label` values, and `as` names under the chain directory. Example outputs:
24
+ - `handoff/external-reference.md`
25
+ - `handoff/local-context.md`
26
+ - `handoff/implementation-strategy.md`
27
+ - `handoff/final-handoff-plan.md`
28
+
29
+ Use phases such as `Research`, `Local context`, and `Synthesis` so async status is readable. Prefer `{outputs.externalReference}`, `{outputs.localContext}`, and `{outputs.implementationStrategy}` in the synthesis task when those specific inputs are available; keep `{previous}` only when the whole parallel fan-in summary is the desired input.
30
+
31
+ Do not write these artifacts into the repository unless I explicitly ask for persistent files.
32
+
33
+ Role guidance:
34
+
35
+ External reference researcher:
36
+ - Study linked projects, docs, issues, examples, source code, or prompt guidance.
37
+ - Identify the behavior, API, implementation files, constraints, and transferable ideas.
38
+ - Conduct web research if needed. Use `web_search` if it is available; otherwise use whatever equivalent research capability is available.
39
+ - Return source links, repo paths, key evidence, risks, and what matters for this implementation.
40
+
41
+ Local context-builder:
42
+ - Read all files needed to fully understand the local issue, not just the first match.
43
+ - Follow imports, callers, tests, fixtures, configuration, docs, and adjacent patterns until the local problem, solution space, and validation path are clear.
44
+ - Return relevant file paths and line ranges, current architecture, constraints, tests, risks, and open questions.
45
+
46
+ Implementation-strategy context-builder, when used:
47
+ - Compare the external evidence against the local architecture.
48
+ - Propose the safest implementation shape, files likely to change, edge cases, validation commands, and decisions that need approval.
49
+ - Stay review/planning-only unless I explicitly ask for implementation.
50
+
51
+ Final synthesis context-builder:
52
+ - Read the parallel outputs and produce one concise handoff plan.
53
+ - Include what the feature/change should do, what the external reference teaches, what the local codebase implies, the recommended approach, likely files to change, constraints, non-goals, validation, risks, and unresolved questions.
54
+ - End with a compact implementation-ready meta-prompt for the next worker/planner.
55
+
56
+ After the chain returns, synthesize the result for me with:
57
+ - the recommended approach;
58
+ - artifact paths;
59
+ - the final meta-prompt;
60
+ - any questions or assumptions that remain.
61
+
62
+ Do not start implementation from this command unless I explicitly ask for it.
@@ -0,0 +1,51 @@
1
+ ---
2
+ description: Parallel subagents research
3
+ argument-hint: "[question]"
4
+ ---
5
+
6
+ Launch parallel research subagents to build a grounded answer to the current question or decision.
7
+
8
+ Use fresh context, not forked context, unless I explicitly ask for forked context. Researchers and scouts should inspect sources directly instead of relying on the main conversation history.
9
+
10
+ Use a combination of `researcher` and `scout` subagents:
11
+ - Use `researcher` for web, docs, standards, ecosystem, recent changes, benchmarks, and primary-source evidence.
12
+ - Use `scout` for local codebase context, existing implementation patterns, repo constraints, and files that would be affected.
13
+
14
+ Give each subagent a distinct angle. Unless I specify angles, use these three:
15
+
16
+ 1. External evidence
17
+ Use `researcher` to find current, authoritative sources: official docs, specs, release notes, benchmarks, issue threads, or primary explanations.
18
+
19
+ 2. Local code context
20
+ Use `scout` to inspect the repository for relevant files, existing patterns, constraints, tests, and likely integration points.
21
+
22
+ 3. Practical tradeoffs
23
+ Use `researcher` or `scout`, whichever fits the question, to compare options, risks, edge cases, maintenance cost, and what would be easiest to validate.
24
+
25
+ Adapt the angles when the question calls for it:
26
+ - Library/API questions: include official docs and recent examples.
27
+ - Architecture decisions: include local module boundaries, dependency direction, and migration cost.
28
+ - Debugging questions: include likely failure modes, local call paths, and exact error evidence.
29
+ - UI/product questions: include user flow, accessibility, design precedent, and implementation constraints.
30
+ - Time-sensitive topics: include a recent-developments angle and prefer 2026/2025 sources.
31
+
32
+ Prefer two or three strong subagents over many vague ones. The parent agent should frame the question and assign angles; the child agents should research or scout, not invent broad plans.
33
+
34
+ Ask each subagent to return concise findings with evidence:
35
+ - file paths and line ranges for local findings
36
+ - source links for external findings
37
+ - confidence level and gaps
38
+ - recommended next step or decision implication
39
+
40
+ Do not ask subagents to edit files. This is a research pass only unless I explicitly ask for implementation.
41
+
42
+ After the subagents return, synthesize the answer into:
43
+ - what we know
44
+ - what the local codebase implies
45
+ - tradeoffs and risks
46
+ - gaps or assumptions
47
+ - the recommended next move
48
+
49
+ If findings disagree, call out the disagreement instead of smoothing it over.
50
+
51
+ $@
@@ -0,0 +1,59 @@
1
+ ---
2
+ description: Parallel subagents review
3
+ argument-hint: "[scope]"
4
+ ---
5
+
6
+ Launch parallel reviewers for an adversarial review of the current work.
7
+
8
+ Use fresh context, not forked context, unless I explicitly ask for forked context. Reviewers should inspect the repository, relevant instructions, and current diff directly from files and commands. Do not rely on the main conversation history.
9
+
10
+ Prefer separate async reviewer runs so each completion wakes the parent instead of waiting for the whole panel. Continue useful parent work while they run; if none remains, end the turn and wait instead of polling. This also applies when an incomplete active Pi goal needs reviewer evidence: resume the goal after automatic completion delivery, not before the evidence arrives. A timed-out reviewer is incomplete review, never sign-off; rerun, resume, or split the review.
11
+
12
+ Omit `acceptance` from review-only tasks unless I explicitly request a same-session acceptance contract. Acceptance adds a finalization turn and does not provide independent review.
13
+
14
+ Give each reviewer a distinct angle. Generate the angles dynamically from the user's intent, the plan, the implemented code, and the current diff. If I specify angles, use mine. Otherwise, choose the highest-value review angles for this specific work.
15
+
16
+ These are examples, not fixed defaults:
17
+
18
+ 1. Correctness and regressions
19
+ Check whether the change satisfies the request, preserves existing behavior, handles edge cases, and avoids hidden runtime failures.
20
+
21
+ 2. Tests and validation
22
+ Check whether tests or validation were added at the right layer, whether assertions are meaningful, and whether the chosen verification commands are enough.
23
+
24
+ 3. Simplicity and maintainability
25
+ Check for unnecessary complexity, duplicate structure, single-use wrappers, brittle abstractions, confusing names, verbosity, and cleanup that is clearly worth doing.
26
+
27
+ Choose or adapt angles when the work calls for it:
28
+ - TypeScript-heavy changes: include type safety, source-of-truth types, casts, and error-boundary discipline.
29
+ - UI-heavy changes: include UX, accessibility, copy, and visual quality.
30
+ - Security-sensitive changes: include unsafe input/output handling, auth boundaries, privacy, and data exposure.
31
+ - Docs-heavy changes: include clarity, accuracy, completeness, reader flow, and non-robotic prose.
32
+ - Large multi-file changes: consider a fourth reviewer for structural friction, module boundaries, and testability.
33
+
34
+ Prefer three strong reviewers over many vague reviewers.
35
+
36
+ Give every reviewer a specific task prompt naming its angle. Ask reviewers to return concise, evidence-backed findings with file/line references and suggested fixes. The response should be review feedback, not a context summary. Reviewers must not edit files unless I explicitly ask for a writer pass.
37
+
38
+ While reviewers run, do your own narrow inspection if useful. After they return, synthesize the feedback into:
39
+ - fixes worth doing now
40
+ - optional improvements
41
+ - feedback to ignore or defer, with a short reason
42
+
43
+ Do not blindly apply every reviewer suggestion.
44
+
45
+ Autofix mode: if the invocation contains the exact word `autofix`, treat it as workflow control, not review scope. Remove it before deciding the review target. After synthesis, apply only fixes worth doing now, validate, and summarize. Do not apply optional improvements unless explicitly requested. If there are no fixes worth doing now, do not edit.
46
+
47
+ Without autofix mode, ask before applying fixes unless I already told you to address review feedback. When you ask, end with a compact numbered menu so I can respond with a number. Use wording suited to the findings, but include these choices when applicable:
48
+
49
+ ```text
50
+ Reply with [1], [2], or further instructions:
51
+ [1] Apply only the fixes worth doing now.
52
+ [2] Apply the fixes worth doing now plus optional improvements.
53
+ ```
54
+
55
+ Additional review target or focus from the template invocation:
56
+
57
+ $@
58
+
59
+ If the invocation provides a URL, issue link, file path, plan path, or freeform focus, treat it as the primary review scope. Read or fetch that target before assigning reviewer angles, and pass the target explicitly into each reviewer task.
@@ -0,0 +1,42 @@
1
+ ---
2
+ description: Review/fix loop until clean
3
+ argument-hint: "[work-scope]"
4
+ ---
5
+
6
+ Run a parent-orchestrated review loop for the requested work.
7
+
8
+ Use the `subagent` tool. Keep the parent session as the loop controller and final decision-maker. Child subagents must receive concrete role-specific tasks. Bundled profiles are leaf agents, so routine fanout stays in the parent. Only an explicitly delegation-enabled profile may use helpers within its assigned scope, role authority, and native depth budget; it must not take over the parent's review loop.
9
+
10
+ Default to a maximum of 3 review rounds unless I specify a different cap. Count a review round each time fresh-context reviewers inspect the current diff after a worker pass. Stop early when reviewers find no blockers or fixes worth doing now.
11
+
12
+ If the invocation includes an implementation request, first launch one default-async `worker` to implement the approved scope. If the current diff is already the target, start with review. Keep the loop in the parent as follow-up runs after each completion; do not put reviewer panels inside one async chain because the aggregate result hides individual reviewer completions. Use only one writer against a shared active worktree at a time; use isolated worktrees for independent parallel writers when helpful.
13
+
14
+ For each review round, launch fresh-context `reviewer` agents as separate async runs so each completion wakes the parent. Continue useful parent work while they run; if none remains, end the turn and wait instead of polling. This also applies when an incomplete active Pi goal needs reviewer evidence: resume the goal after automatic completion delivery, not before the evidence arrives. Omit `acceptance` from review-only tasks unless I explicitly request a same-session acceptance contract; it adds a finalization turn and does not provide independent review. A timed-out reviewer is incomplete review, never sign-off. Reviewers must inspect the repository, relevant instructions, and current diff directly from files and commands. They must not rely on the main conversation history and must not edit files.
15
+
16
+ Choose review angles from the actual change. Common angles are correctness/regressions, tests/validation, and simplicity/maintainability. Add security, performance, docs/API contracts, or user-flow validation when the work calls for it. Prefer three strong reviewers over many vague reviewers.
17
+
18
+ After reviewers return, synthesize their feedback into:
19
+ - concrete blockers or decisions outside the existing authority;
20
+ - fixes worth doing now;
21
+ - optional improvements;
22
+ - feedback to ignore or defer, with a short reason.
23
+
24
+ Do not blindly apply every reviewer suggestion. Make ordinary reversible fix decisions within the existing implementation authority. Ask only when a finding requires unavailable information or authority, changes the owner's settled outcome or scope, or crosses a concrete irreversible-loss, private-data, or substantial new-cost boundary.
25
+
26
+ When an async implementation worker completes, treat its handoff as the transition into review, not as final completion, unless I explicitly asked for worker-only work, review-only output, or to stop after implementation.
27
+
28
+ When there are fixes worth doing now and the workflow is implementation-authorized, launch one default-async `worker` to apply only those synthesized fixes. Ask it to preserve the approved scope, run focused validation, and report changed files, commands run with exit codes, validation evidence, surprises, and anything left undone.
29
+
30
+ After a fix worker returns, run another review round only when it made material changes or addressed non-trivial findings. Do not keep looping for optional polish, speculative improvements, or findings already deferred by the parent.
31
+
32
+ Stop and summarize when one of these is true:
33
+ - reviewers find no blockers or fixes worth doing now;
34
+ - remaining feedback is optional, speculative, or intentionally deferred;
35
+ - reviewers surface a concrete decision outside the existing authority that needs me;
36
+ - the max review-round cap is reached.
37
+
38
+ On completion, inspect the final diff yourself, run or confirm focused validation where appropriate, and summarize the loop: rounds run, fixes applied, validation, remaining deferred items, and why the loop stopped.
39
+
40
+ Additional target, implementation request, max-iteration cap, or review focus from the template invocation:
41
+
42
+ $@