@selesai/code 0.5.28 → 0.6.1

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 (341) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1 -1
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +9 -1
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/config-selector.d.ts.map +1 -1
  7. package/dist/cli/config-selector.js +1 -1
  8. package/dist/cli/config-selector.js.map +1 -1
  9. package/dist/cli/credential-print.d.ts +23 -0
  10. package/dist/cli/credential-print.d.ts.map +1 -0
  11. package/dist/cli/credential-print.js +117 -0
  12. package/dist/cli/credential-print.js.map +1 -0
  13. package/dist/cli/startup-ui.d.ts.map +1 -1
  14. package/dist/cli/startup-ui.js +1 -1
  15. package/dist/cli/startup-ui.js.map +1 -1
  16. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  17. package/dist/core/agent-session-runtime.js +3 -0
  18. package/dist/core/agent-session-runtime.js.map +1 -1
  19. package/dist/core/agent-session.d.ts +12 -1
  20. package/dist/core/agent-session.d.ts.map +1 -1
  21. package/dist/core/agent-session.js +20 -14
  22. package/dist/core/agent-session.js.map +1 -1
  23. package/dist/core/compaction/compaction.d.ts.map +1 -1
  24. package/dist/core/compaction/compaction.js +11 -3
  25. package/dist/core/compaction/compaction.js.map +1 -1
  26. package/dist/core/extensions/runner.d.ts +1 -0
  27. package/dist/core/extensions/runner.d.ts.map +1 -1
  28. package/dist/core/extensions/runner.js +11 -0
  29. package/dist/core/extensions/runner.js.map +1 -1
  30. package/dist/core/extensions/types.d.ts +14 -1
  31. package/dist/core/extensions/types.d.ts.map +1 -1
  32. package/dist/core/extensions/types.js.map +1 -1
  33. package/dist/core/footer-data-provider.d.ts +10 -0
  34. package/dist/core/footer-data-provider.d.ts.map +1 -1
  35. package/dist/core/footer-data-provider.js +1 -1
  36. package/dist/core/footer-data-provider.js.map +1 -1
  37. package/dist/core/llama/provider.d.ts.map +1 -1
  38. package/dist/core/llama/provider.js +8 -3
  39. package/dist/core/llama/provider.js.map +1 -1
  40. package/dist/core/model-config.d.ts +30 -0
  41. package/dist/core/model-config.d.ts.map +1 -1
  42. package/dist/core/model-config.js +6 -0
  43. package/dist/core/model-config.js.map +1 -1
  44. package/dist/core/model-registry.d.ts.map +1 -1
  45. package/dist/core/model-registry.js +2 -2
  46. package/dist/core/model-registry.js.map +1 -1
  47. package/dist/core/model-resolver.d.ts +1 -0
  48. package/dist/core/model-resolver.d.ts.map +1 -1
  49. package/dist/core/model-resolver.js +20 -3
  50. package/dist/core/model-resolver.js.map +1 -1
  51. package/dist/core/model-runtime.d.ts +2 -0
  52. package/dist/core/model-runtime.d.ts.map +1 -1
  53. package/dist/core/model-runtime.js +5 -4
  54. package/dist/core/model-runtime.js.map +1 -1
  55. package/dist/core/package-manager.d.ts.map +1 -1
  56. package/dist/core/package-manager.js +13 -6
  57. package/dist/core/package-manager.js.map +1 -1
  58. package/dist/core/remote-catalog-provider.d.ts +1 -1
  59. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  60. package/dist/core/remote-catalog-provider.js +24 -11
  61. package/dist/core/remote-catalog-provider.js.map +1 -1
  62. package/dist/core/resource-loader.d.ts +15 -0
  63. package/dist/core/resource-loader.d.ts.map +1 -1
  64. package/dist/core/resource-loader.js +66 -9
  65. package/dist/core/resource-loader.js.map +1 -1
  66. package/dist/core/settings-manager.d.ts +1 -1
  67. package/dist/core/settings-manager.d.ts.map +1 -1
  68. package/dist/core/settings-manager.js.map +1 -1
  69. package/dist/core/system-prompt.d.ts.map +1 -1
  70. package/dist/core/system-prompt.js +19 -1
  71. package/dist/core/system-prompt.js.map +1 -1
  72. package/dist/core/system-prompt.test.d.ts +2 -0
  73. package/dist/core/system-prompt.test.d.ts.map +1 -0
  74. package/dist/core/system-prompt.test.js +89 -0
  75. package/dist/core/system-prompt.test.js.map +1 -0
  76. package/dist/core/tools/bash.d.ts +2 -0
  77. package/dist/core/tools/bash.d.ts.map +1 -1
  78. package/dist/core/tools/bash.js +34 -5
  79. package/dist/core/tools/bash.js.map +1 -1
  80. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  81. package/dist/core/tools/tool-definition-wrapper.js +3 -1
  82. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  83. package/dist/defaults/models.json +13 -45
  84. package/dist/defaults/settings.json +1 -2
  85. package/dist/extensions/copy-turn.test.ts +131 -0
  86. package/dist/extensions/copy-turn.ts +6 -1
  87. package/dist/extensions/package.json +0 -1
  88. package/dist/extensions/pi-intercom/CHANGELOG.md +249 -0
  89. package/dist/extensions/pi-intercom/README.md +102 -39
  90. package/dist/extensions/pi-intercom/broker/broker.ts +1233 -36
  91. package/dist/extensions/pi-intercom/broker/client.test.ts +83 -0
  92. package/dist/extensions/pi-intercom/broker/client.ts +315 -12
  93. package/dist/extensions/pi-intercom/broker/extension-state.ts +186 -0
  94. package/dist/extensions/pi-intercom/broker/extension.test.ts +387 -0
  95. package/dist/extensions/pi-intercom/broker/framing.test.ts +114 -0
  96. package/dist/extensions/pi-intercom/broker/framing.ts +82 -24
  97. package/dist/extensions/pi-intercom/broker/paths.test.ts +153 -0
  98. package/dist/extensions/pi-intercom/broker/paths.ts +117 -8
  99. package/dist/extensions/pi-intercom/broker/runtime-claim.test.ts +34 -0
  100. package/dist/extensions/pi-intercom/broker/runtime-claim.ts +21 -0
  101. package/dist/extensions/pi-intercom/broker/spawn.test.ts +160 -23
  102. package/dist/extensions/pi-intercom/broker/spawn.ts +113 -27
  103. package/dist/extensions/pi-intercom/config.test.ts +93 -0
  104. package/dist/extensions/pi-intercom/config.ts +55 -6
  105. package/dist/extensions/pi-intercom/cwd.test.ts +40 -0
  106. package/dist/extensions/pi-intercom/cwd.ts +31 -0
  107. package/dist/extensions/pi-intercom/extension-api.ts +44 -0
  108. package/dist/extensions/pi-intercom/format-context.test.ts +31 -0
  109. package/dist/extensions/pi-intercom/format-context.ts +32 -0
  110. package/dist/extensions/pi-intercom/index.ts +742 -145
  111. package/dist/extensions/pi-intercom/intercom.integration.test.ts +2646 -0
  112. package/dist/extensions/pi-intercom/package.json +15 -5
  113. package/dist/extensions/pi-intercom/reply-tracker.test.ts +134 -0
  114. package/dist/extensions/pi-intercom/reply-tracker.ts +31 -13
  115. package/dist/extensions/pi-intercom/skills/pi-intercom/SKILL.md +13 -11
  116. package/dist/extensions/pi-intercom/test/inline-message.test.ts +184 -0
  117. package/dist/extensions/pi-intercom/test/overlay-width.test.ts +66 -0
  118. package/dist/extensions/pi-intercom/types.ts +94 -4
  119. package/dist/extensions/pi-intercom/ui/compose.ts +8 -4
  120. package/dist/extensions/pi-intercom/ui/inline-message.ts +61 -25
  121. package/dist/extensions/pi-intercom/ui/session-list.ts +7 -3
  122. package/dist/extensions/pi-subagents/CHANGELOG.md +88 -0
  123. package/dist/extensions/pi-subagents/LICENSE +21 -0
  124. package/dist/extensions/pi-subagents/README.md +158 -69
  125. package/dist/extensions/pi-subagents/agents/architect.md +5 -4
  126. package/dist/extensions/pi-subagents/agents/builder.md +6 -4
  127. package/dist/extensions/pi-subagents/agents/commentator.md +3 -2
  128. package/dist/extensions/pi-subagents/agents/explorer.md +3 -2
  129. package/dist/extensions/pi-subagents/agents/recapper.md +3 -2
  130. package/dist/extensions/pi-subagents/agents/researcher.md +4 -3
  131. package/dist/extensions/pi-subagents/package-lock.json +2 -2
  132. package/dist/extensions/pi-subagents/package.json +3 -3
  133. package/dist/extensions/pi-subagents/prompts/review-loop.md +1 -1
  134. package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +22 -988
  135. package/dist/extensions/pi-subagents/skills/pi-subagents/references/constraints-and-recipes.md +257 -0
  136. package/dist/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md +431 -0
  137. package/dist/extensions/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +144 -0
  138. package/dist/extensions/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +281 -0
  139. package/dist/extensions/pi-subagents/src/agents/agent-management.ts +125 -37
  140. package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +4 -0
  141. package/dist/extensions/pi-subagents/src/agents/agents.ts +118 -9
  142. package/dist/extensions/pi-subagents/src/agents/skills.ts +14 -12
  143. package/dist/extensions/pi-subagents/src/agents/task-aware-routing.ts +125 -0
  144. package/dist/extensions/pi-subagents/src/api/delegation.ts +3 -0
  145. package/dist/extensions/pi-subagents/src/api/preflight.ts +17 -13
  146. package/dist/extensions/pi-subagents/src/extension/chain-validation.ts +17 -1
  147. package/dist/extensions/pi-subagents/src/extension/index.ts +22 -8
  148. package/dist/extensions/pi-subagents/src/extension/rpc.ts +248 -6
  149. package/dist/extensions/pi-subagents/src/extension/schemas.ts +33 -8
  150. package/dist/extensions/pi-subagents/src/extension/tool-description.ts +32 -14
  151. package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +9 -4
  152. package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +33 -4
  153. package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +86 -21
  154. package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +24 -13
  155. package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +7 -5
  156. package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +18 -2
  157. package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +48 -5
  158. package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +68 -1
  159. package/dist/extensions/pi-subagents/src/runs/background/notify.ts +56 -5
  160. package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +92 -11
  161. package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +29 -3
  162. package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +388 -29
  163. package/dist/extensions/pi-subagents/src/runs/foreground/async-stop-action.ts +65 -0
  164. package/dist/extensions/pi-subagents/src/runs/foreground/chain-clarify.ts +3 -3
  165. package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +214 -60
  166. package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +546 -252
  167. package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +42 -0
  168. package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +553 -154
  169. package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +19 -13
  170. package/dist/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts +51 -19
  171. package/dist/extensions/pi-subagents/src/runs/shared/chain-outputs.ts +3 -1
  172. package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +1 -1
  173. package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +44 -11
  174. package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +8 -0
  175. package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +97 -20
  176. package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +43 -12
  177. package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +52 -4
  178. package/dist/extensions/pi-subagents/src/runs/shared/process-signal.ts +19 -0
  179. package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +45 -9
  180. package/dist/extensions/pi-subagents/src/runs/shared/runtime-acknowledged-extensions.ts +71 -0
  181. package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +63 -9
  182. package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +31 -1
  183. package/dist/extensions/pi-subagents/src/runs/shared/subagent-startup-retry.ts +101 -0
  184. package/dist/extensions/pi-subagents/src/runs/shared/task-intent.ts +22 -1
  185. package/dist/extensions/pi-subagents/src/runs/shared/usage-budget.ts +65 -0
  186. package/dist/extensions/pi-subagents/src/runs/shared/workflow-graph.ts +26 -1
  187. package/dist/extensions/pi-subagents/src/shared/settings.ts +17 -1
  188. package/dist/extensions/pi-subagents/src/shared/types.ts +196 -12
  189. package/dist/extensions/pi-subagents/src/shared/utils.ts +102 -5
  190. package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +10 -1
  191. package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +46 -4
  192. package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +5 -3
  193. package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +87 -24
  194. package/dist/extensions/pi-subagents/src/tui/fleet.ts +182 -9
  195. package/dist/extensions/pi-subagents/src/tui/render.ts +55 -34
  196. package/dist/extensions/pi-subagents/src/watchdog/register-main.ts +14 -7
  197. package/dist/extensions/pi-subagents/src/watchdog/review.ts +5 -4
  198. package/dist/extensions/pi-subagents/src/watchdog/runtime.ts +170 -17
  199. package/dist/extensions/pi-subagents/src/watchdog/scope.ts +62 -0
  200. package/dist/extensions/pi-subagents/src/watchdog/settings.ts +41 -1
  201. package/dist/extensions/pi-subagents/src/watchdog/types.ts +10 -0
  202. package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +113 -8
  203. package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +419 -47
  204. package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +84 -0
  205. package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +4 -2
  206. package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +51 -2
  207. package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +62 -22
  208. package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +48 -0
  209. package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +8 -6
  210. package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +231 -19
  211. package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +48 -7
  212. package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +44 -0
  213. package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +199 -17
  214. package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +898 -16
  215. package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +112 -23
  216. package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +17 -5
  217. package/dist/extensions/pi-subagents/test/support/mock-pi.ts +2 -0
  218. package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +18 -2
  219. package/dist/extensions/pi-subagents/test/support/register-loader.mjs +3 -3
  220. package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +3 -1
  221. package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +1 -1
  222. package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +198 -6
  223. package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +161 -1
  224. package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +47 -2
  225. package/dist/extensions/pi-subagents/test/unit/async-recovery-descriptor.test.ts +60 -0
  226. package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +8 -0
  227. package/dist/extensions/pi-subagents/test/unit/builtin-agent-documentation.test.ts +63 -0
  228. package/dist/extensions/pi-subagents/test/unit/capability-ceiling-agent-allowlist.test.ts +136 -0
  229. package/dist/extensions/pi-subagents/test/unit/capability-ceiling.test.ts +1 -1
  230. package/dist/extensions/pi-subagents/test/unit/chain-append.test.ts +6 -0
  231. package/dist/extensions/pi-subagents/test/unit/chain-validation.test.ts +1 -1
  232. package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +48 -48
  233. package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +23 -0
  234. package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +27 -0
  235. package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +28 -2
  236. package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +1 -0
  237. package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +176 -8
  238. package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +164 -5
  239. package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +41 -1
  240. package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +17 -12
  241. package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +18 -2
  242. package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +20 -1
  243. package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +30 -2
  244. package/dist/extensions/pi-subagents/test/unit/notify.test.ts +39 -2
  245. package/dist/extensions/pi-subagents/test/unit/parallel-utils.test.ts +22 -0
  246. package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +103 -0
  247. package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +18 -0
  248. package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +48 -0
  249. package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +13 -1
  250. package/dist/extensions/pi-subagents/test/unit/result-intercom.test.ts +29 -4
  251. package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +223 -4
  252. package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +30 -0
  253. package/dist/extensions/pi-subagents/test/unit/runtime-acknowledged-extensions.test.ts +52 -0
  254. package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +46 -2
  255. package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +91 -1
  256. package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +1 -1
  257. package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +1 -1
  258. package/dist/extensions/pi-subagents/test/unit/streamed-progress-bounds.test.ts +78 -0
  259. package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +41 -0
  260. package/dist/extensions/pi-subagents/test/unit/subagent-startup-retry.test.ts +77 -0
  261. package/dist/extensions/pi-subagents/test/unit/task-aware-routing.test.ts +213 -0
  262. package/dist/extensions/pi-subagents/test/unit/task-intent.test.ts +26 -1
  263. package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +61 -10
  264. package/dist/extensions/pi-subagents/test/unit/total-cost.test.ts +1 -0
  265. package/dist/extensions/pi-subagents/test/unit/watchdog-runtime.test.ts +210 -1
  266. package/dist/extensions/pi-subagents/test/unit/watchdog-scope.test.ts +33 -0
  267. package/dist/extensions/pi-subagents/test/unit/watchdog-settings.test.ts +32 -0
  268. package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +1 -1
  269. package/dist/main.d.ts.map +1 -1
  270. package/dist/main.js +43 -0
  271. package/dist/main.js.map +1 -1
  272. package/dist/modes/interactive/components/custom-message.d.ts +3 -1
  273. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  274. package/dist/modes/interactive/components/custom-message.js +10 -2
  275. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  276. package/dist/modes/interactive/components/extension-editor.d.ts +1 -2
  277. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  278. package/dist/modes/interactive/components/extension-editor.js +16 -46
  279. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  280. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  281. package/dist/modes/interactive/components/model-selector.js +4 -1
  282. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  283. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  284. package/dist/modes/interactive/components/scoped-models-selector.js +22 -13
  285. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  286. package/dist/modes/interactive/external-editor.d.ts +12 -0
  287. package/dist/modes/interactive/external-editor.d.ts.map +1 -0
  288. package/dist/modes/interactive/external-editor.js +37 -0
  289. package/dist/modes/interactive/external-editor.js.map +1 -0
  290. package/dist/modes/interactive/interactive-mode.d.ts +1 -1
  291. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  292. package/dist/modes/interactive/interactive-mode.js +72 -64
  293. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  294. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  295. package/dist/modes/rpc/rpc-mode.js +14 -0
  296. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  297. package/dist/skills/ponytail/SKILL.md +1 -3
  298. package/dist/utils/clipboard.d.ts.map +1 -1
  299. package/dist/utils/clipboard.js +19 -8
  300. package/dist/utils/clipboard.js.map +1 -1
  301. package/dist/utils/version-check.d.ts.map +1 -1
  302. package/dist/utils/version-check.js +1 -1
  303. package/dist/utils/version-check.js.map +1 -1
  304. package/docs/compaction.md +1 -1
  305. package/docs/custom-provider.md +14 -5
  306. package/docs/environment-variables.md +86 -0
  307. package/docs/extensions.md +15 -5
  308. package/docs/index.md +1 -0
  309. package/docs/models.md +9 -2
  310. package/docs/plans/subagent-delegation/phase-0-correctness.md +265 -0
  311. package/docs/plans/subagent-delegation/phase-1-behavioral-contract.md +486 -0
  312. package/docs/plans/subagent-delegation/phase-2-context-controls.md +282 -0
  313. package/docs/plans/subagent-delegation/phase-3-advisory-routing.md +362 -0
  314. package/docs/plans/subagent-delegation/phase-4-optional-enforcement.md +381 -0
  315. package/docs/providers.md +21 -2
  316. package/docs/rpc.md +23 -6
  317. package/docs/session-format.md +2 -0
  318. package/docs/settings.md +1 -1
  319. package/docs/usage.md +0 -13
  320. package/examples/extensions/custom-compaction.ts +5 -2
  321. package/examples/extensions/custom-provider-anthropic/index.ts +9 -3
  322. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  323. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  324. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  325. package/examples/extensions/gondolin/package-lock.json +2 -2
  326. package/examples/extensions/gondolin/package.json +1 -1
  327. package/examples/extensions/handoff.ts +11 -3
  328. package/examples/extensions/message-renderer.ts +3 -3
  329. package/examples/extensions/sandbox/package-lock.json +2 -2
  330. package/examples/extensions/sandbox/package.json +1 -1
  331. package/examples/extensions/summarize.ts +5 -2
  332. package/examples/extensions/with-deps/package-lock.json +2 -2
  333. package/examples/extensions/with-deps/package.json +1 -1
  334. package/examples/sdk/12-full-control.ts +3 -1
  335. package/package.json +16 -7
  336. package/dist/extensions/caveman/caveman-instructions.cjs +0 -11
  337. package/dist/extensions/caveman/index.js +0 -118
  338. package/dist/extensions/caveman/package.json +0 -8
  339. package/dist/extensions/caveman/test/extension.test.js +0 -203
  340. package/dist/extensions/caveman/test/helpers.test.js +0 -58
  341. package/dist/skills/caveman/SKILL.md +0 -50
@@ -0,0 +1,282 @@
1
+ # Phase 2 Plan — Minimize Parent Context from Delegated Work
2
+
3
+ ## Verified findings
4
+
5
+ - **High — foreground non-intercom results leak full child output:** `src/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts:3237-3245` aggregates full parallel output; `runSinglePath` returns `finalizeSingleOutput(...).displayOutput`; `compactForegroundDetails()` retains `results[].finalOutput`.
6
+ - **High — intercom moves, rather than minimizes, full output:** `src/extensions/pi-subagents/src/intercom/result-intercom.ts:244-269` places full `summary` text in the grouped event. The compact receipt only applies after acknowledged delivery.
7
+ - **High — async notifications expose full summaries:** `background/subagent-runner.ts:4135-4146` builds a full-output summary; `background/notify.ts:137-151` sends it as a model-visible `subagent-notify` message.
8
+ - **Medium — durable non-debug paths already exist:** explicit `output` persistence in `single-output.ts:173-208` works independently of `artifacts`; async always writes `asyncDir/output-<index>.log`.
9
+ - **Medium — chain terminal content is already concise, but details/intercom are not:** `shared/formatters.ts:58-90` emits a chain summary, while `details.results`/`details.outputs` and grouped intercom payloads can retain child text.
10
+ - **Medium — file-only is reusable but opt-in:** `finalizeSingleOutput()` emits only `SavedOutputReference.message` for `file-only`; tests cover read-only runtime persistence in `single-execution.test.ts:2478`.
11
+
12
+ ## Design decision
13
+
14
+ Use the existing `output`, `outputMode: "file-only"`, saved-output reference, async output logs, `status`, transcript, and `resume` mechanisms. Do **not** add a new public “summary delivery” API, new artifact service, or dependency.
15
+
16
+ New default policy:
17
+
18
+ 1. Every delegated child gets a durable result path unless the caller explicitly uses `output: false`.
19
+ 2. Omitted `outputMode` resolves to `file-only` when a result path exists; explicit `outputMode: "inline"` retains legacy full-output delivery.
20
+ 3. Full output is persisted independently of `artifacts: true`; debug artifacts remain opt-in.
21
+ 4. Successful normal delivery contains references and lifecycle/status information, not child prose.
22
+ 5. If persistence or reference reading fails, return a bounded fallback only: first **80 lines / 4 KiB**, prefixed with the persistence error and stating that full output is unavailable. Reuse `truncateOutput`; do not fall back to unbounded output.
23
+
24
+ `output: false` remains a compatibility escape hatch: no generated output file and bounded inline delivery. Explicit `outputMode: "file-only"` plus `output: false` remains a pre-spawn validation error.
25
+
26
+ ## Data contract
27
+
28
+ No new public tool parameter is required.
29
+
30
+ | Field/surface | Contract |
31
+ |---|---|
32
+ | `SingleResult.savedOutputPath` / `outputReference` | Authoritative full-output location and byte/line metadata. Present for generated or explicit saved outputs, including failed children that produced output. |
33
+ | `SingleResult.finalOutput` | `Output saved to: …` reference for default/file-only delivery; bounded fallback only when persistence failed; full text only with explicit `outputMode:"inline"`. |
34
+ | `Details.results[]` | Terminal parent-facing details must omit raw `messages`, raw `finalOutput`, `truncation`, and chain `outputs` text. Keep status, error, output reference/path, session, transcript, acceptance, and compact tool-call metadata. |
35
+ | Foreground tool-result `content` | Compact run receipt/reference list. No child prose by default. |
36
+ | Intercom payload child `summary` | Saved-output/async-log reference plus process status; never full child output by default. |
37
+ | Async `result.json` | May retain internal result text until watcher delivery, but parent-facing notifier/intercom delivery must use references to `asyncDir/output-<index>.log` or explicit saved outputs. |
38
+ | Failure fallback | A bounded context slice with the write/read error and intended path. It must not claim a full artifact exists. |
39
+
40
+ ## Ordered implementation tasks
41
+
42
+ ### 1. Make saved-output persistence usable for default and failed delivery
43
+
44
+ **Discovery**
45
+ - Re-read `runs/shared/single-output.ts`, especially `resolveSingleOutput()` and `finalizeSingleOutput()`.
46
+ - Trace all callers in `foreground/execution.ts` and background runner step execution before editing.
47
+ - Confirm async `output-<index>.log` contains the child’s final output, not merely progress.
48
+
49
+ **Files**
50
+ - Modify `src/extensions/pi-subagents/src/runs/shared/single-output.ts`.
51
+ - Modify `src/extensions/pi-subagents/src/runs/foreground/execution.ts`.
52
+ - Update `src/extensions/pi-subagents/test/unit/single-output.test.ts`.
53
+ - Update focused cases in `test/integration/single-execution.test.ts`.
54
+
55
+ **Change**
56
+ - Export a small internal context-fallback limit (`bytes: 4096`, `lines: 80`) beside existing output helpers; reuse existing `truncateOutput()`.
57
+ - Add a formatter that produces a bounded persistence-failure fallback containing:
58
+ - process error/status,
59
+ - intended output path,
60
+ - persistence/read error,
61
+ - bounded output slice.
62
+ - Call `resolveSingleOutput()` whenever an output path is configured and meaningful child output exists, not only for `exitCode === 0`.
63
+ - Preserve existing child-authored-file precedence and snapshot safety.
64
+ - Update `finalizeSingleOutput()` so failed runs with a successfully persisted result return error/status plus the saved-output reference, rather than raw output.
65
+ - Do not change `formatSavedOutputReference()` wording or make debug artifacts mandatory.
66
+
67
+ **Verification**
68
+ - Successful child-written and runtime-persisted outputs retain full file contents.
69
+ - Failed child with output gets a reference and readable file.
70
+ - Failed write/read produces only the bounded fallback.
71
+ - Existing explicit inline behavior remains unchanged when selected.
72
+
73
+ ### 2. Resolve generated paths and default delivery consistently by execution mode
74
+
75
+ **Discovery**
76
+ - Trace `resolveSingleRunOutputBaseDir()` and top-level parallel path namespacing in `subagent-executor.ts`.
77
+ - Trace foreground chain output resolution in `chain-execution.ts`.
78
+ - Trace async step construction in `async-execution.ts` and result-log creation in `subagent-runner.ts`.
79
+
80
+ **Files**
81
+ - Modify `src/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts`.
82
+ - Modify `src/extensions/pi-subagents/src/runs/foreground/chain-execution.ts`.
83
+ - Modify `src/extensions/pi-subagents/src/runs/background/async-execution.ts`.
84
+ - Modify only necessary type declarations in `src/extensions/pi-subagents/src/shared/types.ts` and `runs/shared/parallel-utils.ts`.
85
+ - Update `test/integration/single-execution.test.ts`, `parallel-execution.test.ts`, and `async-execution.test.ts`.
86
+
87
+ **Change**
88
+ - Resolve omitted output as a generated per-child relative file name:
89
+ - foreground single: `<singleRunOutputBaseDir>/<runId>/result.md`;
90
+ - foreground top-level parallel: existing per-task namespace plus `result.md`;
91
+ - foreground chain: `<chainDir>/outputs/<flat-index>-<agent>.md`;
92
+ - async single/parallel/chain: `<asyncDir>/outputs/<flat-index>-<agent>.md`, while retaining existing `output-<index>.log` as status/transcript recovery.
93
+ - Preserve explicit absolute and relative `output` paths, existing duplicate-path validation, and `output: false`.
94
+ - Resolve omitted `outputMode` to `file-only` when an output path is active. Preserve explicit `"inline"` exactly.
95
+ - Keep chain handoff semantics valid: later `{previous}`/`{outputs.name}` consumers receive the existing file reference for file-only steps and can read the named path; do not re-inline child prose merely for chaining.
96
+ - Ensure generated output paths are passed to child task and system-prompt instructions through existing `injectSingleOutputInstruction()` / `injectOutputPathSystemPrompt()`.
97
+ - Do not add frontmatter-only defaults to builtin agents: those would collide in chains and fail to cover custom agents. Runtime-generated per-run paths own this behavior.
98
+
99
+ **Mode acceptance matrix**
100
+ - **Foreground single:** compact saved-output reference; explicit inline opt-out remains full text.
101
+ - **Foreground parallel:** one compact result per child, each with status and output reference.
102
+ - **Foreground chain:** existing chain completion summary plus chain/output paths; no step prose in terminal parent result.
103
+ - **Async launch:** existing concise launch receipt unchanged.
104
+ - **Async completion:** compact references to explicit saved output or `asyncDir/output-<index>.log`.
105
+ - **Status/transcript:** remain the path to inspect output; `resume` continues using existing session persistence.
106
+ - **Errors, pause, stop, timeout:** retain process error/status and recovery instructions; attach a saved-output/log reference if available, otherwise bounded fallback.
107
+
108
+ ### 3. Strip terminal foreground details and intercom payloads of raw output
109
+
110
+ **Discovery**
111
+ - Inspect `compactForegroundDetails()` in `shared/utils.ts`.
112
+ - Inspect `maybeBuildForegroundIntercomReceipt()` and `resultSummaryForIntercom()` in `subagent-executor.ts`.
113
+ - Inspect `stripDetailsOutputsForIntercomReceipt()` in `intercom/result-intercom.ts`.
114
+
115
+ **Files**
116
+ - Modify `src/extensions/pi-subagents/src/shared/utils.ts`.
117
+ - Modify `src/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts`.
118
+ - Modify `src/extensions/pi-subagents/src/intercom/result-intercom.ts`.
119
+ - Update `test/integration/foreground-result-size.test.ts`.
120
+ - Update `test/integration/intercom-result-delivery.test.ts`.
121
+
122
+ **Change**
123
+ - Add one shared terminal-result projection based on the existing intercom stripping pattern. It must remove raw child output from terminal `Details`, including chain `details.outputs` text/structured payloads, while retaining references and operational metadata.
124
+ - Apply that projection for all completed foreground modes, not just acknowledged intercom receipts.
125
+ - Keep remembered foreground state able to recover output from `savedOutputPath` first; do not retain full `finalOutput` in memory when an authoritative path exists.
126
+ - Change foreground intercom child summaries from `getSingleResultOutput()` to the saved-output reference. Include error/status before the reference for failed children.
127
+ - Keep the current 500 ms intercom acknowledgement behavior:
128
+ - acknowledged relay: compact receipt and stripped details;
129
+ - unavailable/unacknowledged relay: compact native foreground receipt, not legacy full child output;
130
+ - explicit `outputMode:"inline"` is the sole compatibility opt-out for full foreground output.
131
+ - Do not alter supervisor-request/detached-run routing.
132
+
133
+ **Verification**
134
+ - Bridge-on and bridge-off foreground single, parallel, and chain responses contain no child prose by default.
135
+ - Intercom payloads contain references, not full output.
136
+ - Explicit inline still exposes legacy content.
137
+ - `JSON.stringify(result)` remains below current payload-size protections.
138
+
139
+ ### 4. Make async notifier and grouped intercom delivery reference-only
140
+
141
+ **Discovery**
142
+ - Trace `summary` creation in `background/subagent-runner.ts`.
143
+ - Trace result-file normalization and delivery in `background/result-watcher.ts`.
144
+ - Trace `buildCompletionDetails()`, `formatSingleCompletion()`, and `formatGroupedCompletion()` in `background/notify.ts`.
145
+
146
+ **Files**
147
+ - Modify `src/extensions/pi-subagents/src/runs/background/subagent-runner.ts`.
148
+ - Modify `src/extensions/pi-subagents/src/runs/background/result-watcher.ts`.
149
+ - Modify `src/extensions/pi-subagents/src/runs/background/notify.ts`.
150
+ - Update `test/integration/async-execution.test.ts`.
151
+ - Update `test/integration/result-watcher.test.ts`.
152
+ - Update `test/unit/notify.test.ts`.
153
+
154
+ **Change**
155
+ - Persist/retain each async child’s authoritative output location in the result payload: explicit `savedOutputPath` when present, otherwise its existing `asyncDir/output-<index>.log`.
156
+ - At watcher delivery time, build compact child summaries from that path using `formatSavedOutputReference()`; do not use `results[].output` or run `summary` as parent-facing text.
157
+ - Build the local `subagent-notify` content from the same compact run receipt so notification and intercom behavior match.
158
+ - Preserve grouped intercom acknowledgement semantics:
159
+ - acknowledged grouped delivery suppresses duplicate local notification;
160
+ - unacknowledged or disabled grouped delivery sends the compact local notifier;
161
+ - session-lease and result-file retry/unlink behavior remains unchanged.
162
+ - On absent/unreadable output log, include process error and bounded fallback only; do not emit raw `result.json.summary`.
163
+ - Preserve full internal `result.json` data only until watcher consumption; the durable parent reference must be the output path/log, not the deletable result queue file.
164
+
165
+ **Verification**
166
+ - Async success emits a notification/intercom message with output-log or saved-output reference only.
167
+ - Async failed, paused, stopped, and timed-out cases retain status, error, and recovery guidance.
168
+ - Intercom acknowledgement still suppresses duplicate notifier delivery.
169
+ - Watcher retry on notifier failure leaves the result file intact.
170
+
171
+ ### 5. Document migration and rebuild packaged assets
172
+
173
+ **Discovery**
174
+ - Re-read current output instructions in:
175
+ - `src/extensions/pi-subagents/README.md:647-671,1446-1486`;
176
+ - `src/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md:91,140-156`;
177
+ - `src/extensions/pi-subagents/src/extension/tool-description.ts`.
178
+ - Coordinate with Phase 0/1 edits before resolving overlapping wording.
179
+
180
+ **Files**
181
+ - Modify `src/extensions/pi-subagents/README.md`.
182
+ - Modify `src/extensions/pi-subagents/skills/pi-subagents/references/execution-controls.md`.
183
+ - Modify `src/extensions/pi-subagents/src/extension/tool-description.ts` only if Phase 1 has not already incorporated the final contract.
184
+ - Regenerate `dist/extensions/pi-subagents/**` with the root build; do not hand-edit generated copies.
185
+
186
+ **Change**
187
+ - State that normal delegated results are reference-first and full output is inspected through saved output, async status/transcript, or resume.
188
+ - Document explicit `outputMode:"inline"` as compatibility opt-out.
189
+ - Document `output:false` as disabling durable result persistence and causing bounded fallback visibility.
190
+ - State that generated output paths persist with `artifacts:false`; debug `_input`, `_output`, metadata, and transcript artifacts remain opt-in.
191
+ - Correct old claims that failed runs always return full inline debugging output.
192
+ - Keep examples using explicit output paths where humans or later processes need stable project-owned names.
193
+
194
+ ## Migration and compatibility
195
+
196
+ - This is an intentional behavior change for omitted `outputMode`: default delivery becomes file-only/reference-first.
197
+ - Existing callers requiring full terminal text must set `outputMode:"inline"`.
198
+ - Existing callers with explicit `output` keep that path; generated paths affect only omitted output.
199
+ - Existing `output:false` behavior remains available, but loses full durable recovery by design.
200
+ - No external protocol version bump is needed if new fields are additive and result files remain backward-readable. Treat absent saved-path fields as legacy and use bounded fallback.
201
+ - Do not expose `maxOutput` as a new Phase 2 API; its current undocumented semantics are unrelated. Use a fixed internal fallback cap only.
202
+
203
+ ## Phase dependencies
204
+
205
+ - **Phase 0:** must land its corrected role/output documentation first, or Phase 2 documentation will conflict with stale “write/no-write” and context claims. Runtime work is otherwise independent.
206
+ - **Phase 1:** should land before the final `tool-description.ts` wording so the always-visible delegation contract can describe reference-first completion once, without duplicate edits. Runtime Phase 2 code does not depend on Phase 1 catalog changes.
207
+ - **No dependency on Phase 3/4:** advisory routing and enforcement must not be coupled to output delivery.
208
+
209
+ ## Test commands
210
+
211
+ ```sh
212
+ cd src/extensions/pi-subagents
213
+ node --experimental-strip-types --test test/unit/single-output.test.ts test/unit/notify.test.ts
214
+ node --experimental-strip-types --import ./test/support/register-loader.mjs --test \
215
+ test/integration/single-execution.test.ts \
216
+ test/integration/parallel-execution.test.ts \
217
+ test/integration/foreground-result-size.test.ts \
218
+ test/integration/intercom-result-delivery.test.ts \
219
+ test/integration/async-execution.test.ts \
220
+ test/integration/result-watcher.test.ts
221
+ npm run test:all
222
+
223
+ cd ../../..
224
+ npm run build
225
+ ```
226
+
227
+ ## Acceptance criteria
228
+
229
+ - Default foreground single, parallel, and chain completion contains no raw child output in `content`, terminal `details`, or intercom delivery.
230
+ - Default async completion notification/intercom contains no raw child output.
231
+ - Each successful child has a readable, authoritative result reference with byte/line metadata while `artifacts:false`.
232
+ - Failure/timeout/stop/pause preserves status and recovery information and never emits unbounded output.
233
+ - Persistence failure produces the specified 80-line/4-KiB fallback and does not falsely claim a full reference exists.
234
+ - Explicit `outputMode:"inline"` preserves legacy inline delivery.
235
+ - `output:false`, status, transcript, resume, intercom acknowledgement, session leases, chain output bindings, and structured output behavior remain covered by regression tests.
236
+ - Root build regenerates `dist` from source.
237
+
238
+ ## Risks and rollback
239
+
240
+ - **Risk:** reference-only chains require downstream children to read referenced outputs deliberately. Mitigate with injected authoritative output-path instructions and chain tests.
241
+ - **Risk:** generated output files increase `.pi-subagents` disk use despite debug artifacts being disabled. Mitigate through documented paths and existing project/session/temp placement; do not silently delete authoritative outputs in this phase.
242
+ - **Risk:** host behavior for tool `details` is not fully controlled. Mitigate by removing terminal raw output from details rather than relying on renderer behavior.
243
+ - **Rollback:** restore omitted-mode resolution to `"inline"` and remove generated-path assignment; explicit output/file-only callers remain functional. Leave already-written result files in place; they are harmless and should not be deleted automatically.
244
+
245
+ ```acceptance-report
246
+ {
247
+ "criteriaSatisfied": [
248
+ {
249
+ "id": "criterion-1",
250
+ "status": "satisfied",
251
+ "evidence": "Concrete findings verified in source and tests: high-risk raw-output surfaces in foreground executor, result-intercom, async runner, notifier, and details; reusable file-only, async-log, status, transcript, resume, and artifact-default-off mechanisms cited with exact paths."
252
+ }
253
+ ],
254
+ "changedFiles": [],
255
+ "testsAddedOrUpdated": [],
256
+ "commandsRun": [
257
+ {
258
+ "command": "read/grep static inspection of pi-subagents source, docs, and tests",
259
+ "result": "passed",
260
+ "summary": "Verified cited symbols, current mode behavior, artifact-default-off gates, and existing test seams. No implementation commands were run."
261
+ }
262
+ ],
263
+ "validationOutput": [
264
+ "Plan is implementation-ready and limited to Phase 2.",
265
+ "No files were edited."
266
+ ],
267
+ "residualRisks": [
268
+ "Reference-first defaults intentionally change omitted outputMode behavior; callers needing inline output must migrate.",
269
+ "Generated authoritative outputs require a retention policy decision outside this phase if disk growth becomes material."
270
+ ],
271
+ "noStagedFiles": false,
272
+ "diffSummary": "No diff produced; planning-only task.",
273
+ "reviewFindings": [
274
+ "high: foreground executor and intercom payloads currently expose full child output by default.",
275
+ "high: async completion notifier currently forwards full runner summaries.",
276
+ "medium: existing explicit output persistence and async output logs can satisfy Phase 2 without enabling debug artifacts."
277
+ ],
278
+ "manualNotes": "Staged-file state was not inspected because this session has no shell execution tool."
279
+ }
280
+ ```
281
+
282
+ ⧉ copy assistant: /cp 5224d1
@@ -0,0 +1,362 @@
1
+ # Phase 3 Plan — Optional Task-Aware Advisory Routing
2
+
3
+ ## Decision
4
+
5
+ Use **`subagent({ action: "list", task?, agentScope? })`** as the only Phase 3 advisory surface.
6
+
7
+ It is the smallest robust design because `task` and `action:"list"` already exist in `SubagentParams`, list already discovers the effective runnable agent set, and it already emits advisory text. This adds no launch path, RPC method, preflight-contract field, persistence, metadata schema, or new action.
8
+
9
+ ### Alternatives rejected
10
+
11
+ | Option | Decision | Reason |
12
+ |---|---|---|
13
+ | Extend `action:"list"` with optional `task` | **Select** | Existing schema/action/output surface; model already instructed to call list; no API-version changes. |
14
+ | Add `action:"recommend"` or `action:"route"` | Reject | Adds action registry, dispatch, child-safe policy, docs, and a second advisory surface without a functional benefit. |
15
+ | Add generic role aliases such as `writer`/`reviewer` as runnable aliases | Reject | Would alter `resolveAgentName` ambiguity/precedence behavior and can collide with user/package aliases. Existing `acceptanceRole` plus established name heuristics are sufficient. |
16
+ | Add recommendation to launch preflight/RPC | Reject | Would require public contract/protocol version changes and digest compatibility work for advisory-only behavior. |
17
+
18
+ ## Public behavior and API
19
+
20
+ ### Supported call
21
+
22
+ ```ts
23
+ subagent({
24
+ action: "list",
25
+ task: "Inspect the authentication flow and report findings only.",
26
+ agentScope: "both", // optional; existing behavior
27
+ })
28
+ ```
29
+
30
+ - `task` remains optional.
31
+ - With no task, or a whitespace-only task, preserve current list output and behavior.
32
+ - With a non-empty task, append a text-only advisory section after the existing agents/chains/proactive-skill/diagnostic sections.
33
+ - The caller must make a separate explicit execution call to launch anything:
34
+
35
+ ```ts
36
+ subagent({ agent: "architect", task: "..." })
37
+ ```
38
+
39
+ ### Output shape
40
+
41
+ Keep the existing management result shape unchanged:
42
+
43
+ ```ts
44
+ {
45
+ content: [{ type: "text", text: "<existing list text plus optional advisory>" }],
46
+ isError: false,
47
+ details: { mode: "management", results: [] }
48
+ }
49
+ ```
50
+
51
+ Do **not** add a `recommendations` field to `Details`, a result-content JSON schema, telemetry payload, or launch contract.
52
+
53
+ For a safe recommendation, append exactly this conceptual structure:
54
+
55
+ ```text
56
+ Task-aware advisory routing:
57
+ - Intent: implementation | read-only
58
+ - Recommended: <canonical runtime agent name> (<source>)
59
+ - Reason: <declared/inferred role and safety basis>
60
+ - Advisory only: no subagent was launched. To proceed, explicitly call subagent with this canonical agent name and the task.
61
+ ```
62
+
63
+ For unclear intent or no safe candidate:
64
+
65
+ ```text
66
+ Task-aware advisory routing:
67
+ - Intent: unknown | implementation | read-only
68
+ - Recommendation: none
69
+ - Next: <clarification or configuration/capability explanation>
70
+ - Advisory only: no subagent was launched.
71
+ ```
72
+
73
+ Never echo the complete task in the response; this avoids enlarging output and reflecting untrusted text.
74
+
75
+ ## Eligibility and deterministic routing algorithm
76
+
77
+ Create a pure recommender that receives the already discovered effective agents and current capability ceiling. It must not read files, mutate discovery results, resolve aliases, modify params, or launch agents.
78
+
79
+ 1. **Normalize task**
80
+ - `task.trim() === ""` means no advisory section.
81
+ - Otherwise classify the task with `classifyTaskMutationIntent("builder", task)`.
82
+ - This deliberately uses the existing broad writer grammar as a task-level signal:
83
+ - `implementation`
84
+ - `read-only`
85
+ - `unknown`
86
+
87
+ 2. **Use only effective executable candidates**
88
+ - Start from the same `scopedAgents` produced by:
89
+ `mergeAgentsForScope(scope, d.user, d.project, d.builtin, d.package)`.
90
+ - Exclude `agent.disabled === true`.
91
+ - Exclude agents denied by `isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling)`.
92
+ - This preserves project > user > package > builtin collision resolution already performed by discovery/selection.
93
+ - Do not consider chains in Phase 3.
94
+ - Do not inspect or route individual chain steps/templates.
95
+
96
+ 3. **Determine candidate role without adding aliases or metadata**
97
+ - Reuse the existing `acceptanceRole` field where set:
98
+ - `"writer"` is a writer candidate.
99
+ - `"read-only"` is a read-only candidate.
100
+ - When it is unset, reuse the existing acceptance name heuristics:
101
+ - names matching `builder` are writer candidates;
102
+ - names matching `architect|commentator|explorer|recapper|researcher|analyst` are read-only candidates.
103
+ - Refactor this shared heuristic into one exported helper so advisory routing and acceptance inference cannot drift.
104
+ - Alias values are never used as role signals. They remain input-only name resolution sugar.
105
+
106
+ 4. **Apply conservative write safety**
107
+ - Reuse `agentHasWriteTools` from `src/agents/agent-memory.ts`.
108
+ - For an `implementation` task, retain only writer-role candidates with write capability.
109
+ - If `capabilityCeiling.allowedTools` is present, retain a writer only when its allowlist includes at least one recognized writer tool: `edit`, `write`, or `bash`.
110
+ - For a `read-only` task, retain only read-only-role candidates for which `agentHasWriteTools(agent) === false`.
111
+ - This is intentionally conservative: an agent with unset tools or `bash` is not recommended as the safe read-only choice.
112
+ - Do not claim that arbitrary MCP/custom tools are provably non-mutating; actual launch preflight remains authoritative.
113
+
114
+ 5. **Select or recover**
115
+ - For `unknown`, return no recommendation and request clarification: whether the task is read-only analysis/review or implementation allowed to edit files.
116
+ - For a known intent with zero safe candidates, return no recommendation and explain the missing role/capability condition. Point to the executable/restricted sections already emitted by list.
117
+ - Sort valid candidates deterministically:
118
+ 1. source precedence: `project`, `user`, `package`, `builtin`;
119
+ 2. explicit `acceptanceRole` before inferred name heuristic;
120
+ 3. canonical runtime `agent.name` ascending with a fixed lexical comparator.
121
+ - Recommend `agent.name` only—the canonical runtime name accepted by execution. Never output an alias as the launch target.
122
+
123
+ 6. **Preserve user control**
124
+ - Do not write to `params.agent`.
125
+ - Do not touch `canonicalizeExecutionParams`.
126
+ - Do not invoke `resolveAgentName` for a generic role.
127
+ - An explicit later execution request remains authoritative, including existing canonical-name/alias handling and its ambiguity errors.
128
+ - Existing preflight and execution checks remain the final enforcement point for agent/tool restrictions.
129
+
130
+ ## Implementation tasks
131
+
132
+ ### Task 1 — Centralize the existing role heuristic
133
+
134
+ **Discovery**
135
+ - Inspect `src/extensions/pi-subagents/src/runs/shared/task-intent.ts`.
136
+ - Inspect `src/extensions/pi-subagents/src/runs/shared/acceptance.ts:76-134`.
137
+ - Confirm the current reviewer-name and builder-name regex behavior before changing it.
138
+
139
+ **Files**
140
+ - Modify `src/extensions/pi-subagents/src/runs/shared/task-intent.ts`.
141
+ - Modify `src/extensions/pi-subagents/src/runs/shared/acceptance.ts`.
142
+ - Update `src/extensions/pi-subagents/test/unit/task-intent.test.ts`.
143
+ - Existing `test/unit/acceptance.test.ts` is the regression suite; only alter it if current behavior needs an explicit regression assertion.
144
+
145
+ **Change**
146
+ - Add and export a narrow helper such as:
147
+ ```ts
148
+ resolveAgentRoutingRole(
149
+ agentName: string,
150
+ acceptanceRole?: AcceptanceRole,
151
+ ): "writer" | "read-only" | undefined
152
+ ```
153
+ - Preserve current acceptance semantics exactly:
154
+ - declared `acceptanceRole` wins;
155
+ - otherwise builder-name heuristic means writer;
156
+ - otherwise existing reviewer-name heuristic means read-only;
157
+ - otherwise undefined.
158
+ - Refactor `inferLevel` to use this helper in place of its duplicated `readOnlyAgent`/builder-name checks.
159
+ - Do not change task mutation grammar, acceptance levels, evidence requirements, or `acceptanceRole` schema.
160
+
161
+ **Verification**
162
+ - Declared writer/read-only roles still override name inference.
163
+ - `builder` remains a writer and `commentator` remains reviewer-style.
164
+ - Existing acceptance tests retain their current levels/reasons.
165
+
166
+ ### Task 2 — Add the pure advisory recommender
167
+
168
+ **Discovery**
169
+ - Inspect:
170
+ - `src/extensions/pi-subagents/src/agents/proactive-skills.ts` for pure-function/formatter conventions.
171
+ - `src/extensions/pi-subagents/src/agents/agent-memory.ts:33-39` for `agentHasWriteTools`.
172
+ - `src/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts:300-315` for allowlist checks.
173
+ - `src/extensions/pi-subagents/src/agents/agent-selection.ts` for effective-set precedence.
174
+ - Do not add frontmatter fields, settings fields, tags, or role aliases.
175
+
176
+ **Files**
177
+ - Add `src/extensions/pi-subagents/src/agents/task-aware-routing.ts`.
178
+ - Add `src/extensions/pi-subagents/test/unit/task-aware-routing.test.ts`.
179
+
180
+ **Change**
181
+ - Export a small typed pure API, for example:
182
+ - `recommendTaskAwareAgent({ task, agents, capabilityCeiling })`
183
+ - `formatTaskAwareAgentRecommendation(recommendation)`
184
+ - Keep returned data internal to the extension; do not add it to public `Details`.
185
+ - Implement the algorithm above, including:
186
+ - empty-task no-op;
187
+ - task intent;
188
+ - disabled and capability-agent filtering;
189
+ - conservative role/write-tool matching;
190
+ - capability `allowedTools` writer check;
191
+ - deterministic ordering;
192
+ - unknown/no-candidate recovery text.
193
+ - Include source, canonical agent name, role basis (`declared` or `inferred`), and reason in the returned recommendation object so formatting never reimplements selection logic.
194
+ - Do not access aliases, chains, filesystem discovery, executor APIs, RPC, preflight, telemetry, or user settings in this module.
195
+
196
+ **Verification**
197
+ - Implementation task recommends a canonical writer, never a reviewer.
198
+ - Read-only task recommends a role-compatible agent without known write tools, never a writer.
199
+ - Unknown intent yields no recommendation and a clarification message.
200
+ - Disabled agents and agents outside `allowedAgents` cannot be selected.
201
+ - A ceiling without `edit`, `write`, or `bash` prevents a writer recommendation.
202
+ - A project candidate outranks an otherwise-equivalent user/package/builtin candidate.
203
+ - Equal candidates sort by canonical name.
204
+ - An alias such as `developer` is never output as the recommended launch name.
205
+
206
+ ### Task 3 — Attach advice only to list management output
207
+
208
+ **Discovery**
209
+ - Inspect `handleList` in `src/extensions/pi-subagents/src/agents/agent-management.ts:675-714`.
210
+ - Inspect management dispatch at `handleManagementAction`.
211
+ - Inspect the executor management dispatch at `subagent-executor.ts:4064-4083` to confirm no execution path needs modification.
212
+
213
+ **Files**
214
+ - Modify `src/extensions/pi-subagents/src/agents/agent-management.ts`.
215
+ - Modify `src/extensions/pi-subagents/src/extension/schemas.ts`.
216
+ - Update `src/extensions/pi-subagents/test/unit/agent-management.test.ts`.
217
+ - Update `src/extensions/pi-subagents/test/unit/capability-ceiling-agent-allowlist.test.ts`.
218
+ - Update `src/extensions/pi-subagents/test/unit/schemas.test.ts`.
219
+ - Update `src/extensions/pi-subagents/test/unit/index-child-registration.test.ts`.
220
+
221
+ **Change**
222
+ - Extend internal `ManagementParams` with `task?: string`.
223
+ - In `handleList`, reuse its already computed `agents` array, `capabilityCeiling`, and scope-specific effective discovery.
224
+ - When `params.task?.trim()` is non-empty, call the new pure recommender and append its formatter lines after proactive-skill suggestions and before chain diagnostics.
225
+ - Leave no-task list output structurally unchanged.
226
+ - Update the top-level `task` schema description to state that it is a single-execution task **or an optional advisory intent for `action:"list"`; it never launches work in management mode**.
227
+ - Keep `action` as a free string schema; do not add an action enum.
228
+ - Keep `SUBAGENT_ACTIONS`, `ManagementAction`, mutating-action gates, and executor dispatch unchanged.
229
+
230
+ **Verification**
231
+ - `handleManagementAction("list", { task: "Implement the fix" }, ctx)` returns management details with `results: []`, no error, and an advisory recommendation.
232
+ - `handleManagementAction("list", { task: "Review only; do not edit files" }, ctx)` emits a read-only recommendation.
233
+ - `handleManagementAction("list", { task: "Look into this" }, ctx)` emits no agent name recommendation and asks for intent clarification.
234
+ - `handleManagementAction("list", {}, ctx)` retains current executable/restricted/chains/proactive output.
235
+ - Existing restricted-agent list behavior remains; a restricted builder must not be recommended.
236
+ - The fanout-child registration test calls list with a task and confirms it remains a permitted read-only management action.
237
+
238
+ ### Task 4 — Document explicit-only use
239
+
240
+ **Discovery**
241
+ - Inspect both built-in descriptions in `src/extensions/pi-subagents/src/extension/tool-description.ts`.
242
+ - Inspect management examples and parameter reference in `src/extensions/pi-subagents/README.md:1377-1442`.
243
+
244
+ **Files**
245
+ - Modify `src/extensions/pi-subagents/src/extension/tool-description.ts`.
246
+ - Modify `src/extensions/pi-subagents/README.md`.
247
+ - Update `src/extensions/pi-subagents/test/unit/tool-description.test.ts`.
248
+
249
+ **Change**
250
+ - In full and compact descriptions:
251
+ - show `{ action: "list", task: "..." }` as optional advice;
252
+ - state that it only recommends and never launches;
253
+ - state the caller must explicitly execute the returned canonical agent.
254
+ - Adjust “management action fields” wording so list’s optional task is documented as the sole exception.
255
+ - Add a README management example and revise the `task` parameter reference.
256
+ - Do not change custom-description loading behavior; mandatory safety guidance naturally remains appended to custom descriptions.
257
+
258
+ **Verification**
259
+ - Full and compact descriptions both mention task-aware list advice and explicit launch.
260
+ - Existing safety guidance, proactive-skill text, and no-hardcoded-builtin-name assertions remain valid.
261
+ - README does not imply automatic routing or execution.
262
+
263
+ ## Compatibility and dependency impact
264
+
265
+ - No dependency changes.
266
+ - No new config/settings schema.
267
+ - No agent frontmatter changes.
268
+ - No new aliases.
269
+ - No new tool action.
270
+ - No RPC version bump.
271
+ - No preflight contract version/digest change.
272
+ - No delegation API version change.
273
+ - No telemetry: the extension has no matching event/metric convention for advisory list reads, and telemetry would add privacy and API surface without an execution decision.
274
+
275
+ ## Commands
276
+
277
+ Run from `src/extensions/pi-subagents`:
278
+
279
+ ```bash
280
+ node --experimental-strip-types --test \
281
+ test/unit/task-intent.test.ts \
282
+ test/unit/acceptance.test.ts \
283
+ test/unit/task-aware-routing.test.ts \
284
+ test/unit/agent-management.test.ts \
285
+ test/unit/capability-ceiling-agent-allowlist.test.ts \
286
+ test/unit/schemas.test.ts \
287
+ test/unit/tool-description.test.ts \
288
+ test/unit/index-child-registration.test.ts
289
+ npm run test:unit
290
+ npm run test:integration
291
+ npm run test:all
292
+ ```
293
+
294
+ ## Acceptance criteria
295
+
296
+ 1. `action:"list"` accepts optional `task` advice without creating a new action or schema object.
297
+ 2. Recommendations use only the dynamically discovered, effective, enabled, capability-allowed set.
298
+ 3. Project/user/package/builtin precedence, canonical names, and existing alias resolution remain intact.
299
+ 4. A read-only task is never recommended to a known writer; an implementation task is never recommended to a read-only agent.
300
+ 5. Unknown intent and missing safe candidates produce recovery guidance, not guesses.
301
+ 6. List advice never launches, schedules, persists, mutates params, or changes executor agent selection.
302
+ 7. Existing list, acceptance, capability-ceiling, and child-safe management behavior pass regression tests.
303
+ 8. No metadata/tag schema, dependency, protocol, telemetry, or contract version is added.
304
+
305
+ ## Risks and rollback
306
+
307
+ - **Heuristic limitation:** task wording and name-based roles remain heuristic. Mitigation: no recommendation for unknown intent and existing `acceptanceRole` is preferred when configured.
308
+ - **Tool limitation:** `agentHasWriteTools` only recognizes core write tools; custom/MCP tools cannot be proven read-only. Mitigation: conservative filtering and explicit-launch/preflight enforcement.
309
+ - **Usability limitation:** a restrictive `allowedTools` ceiling can yield no writer recommendation. This is safer than recommending a writer that cannot write.
310
+ - **Rollback:** remove the `handleList` call/formatting and new routing module; leave the shared role-helper refactor only if acceptance behavior is verified identical. No stored data, API version, or migration requires cleanup.
311
+
312
+ ## Review findings
313
+
314
+ - **No blocker** — `src/extensions/pi-subagents/src/agents/agent-management.ts:675-714` already owns advisory list output and receives the effective executable/capability-filtered agent set.
315
+ - **No blocker** — `src/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts:4078-4083` routes management actions without invoking execution; leaving it unchanged preserves explicit-only launch behavior.
316
+ - **Finding (medium)** — `src/extensions/pi-subagents/src/runs/shared/acceptance.ts:89-101` duplicates role-name heuristics that a recommender would otherwise need to copy. Centralize the existing heuristic before using it for routing to prevent behavior drift.
317
+ - **Finding (medium)** — `src/extensions/pi-subagents/src/agents/agent-memory.ts:33-39` treats unset tools as write-capable and treats `bash` as write-capable. Advisory routing must retain this conservative interpretation for read-only recommendations.
318
+
319
+ ```acceptance-report
320
+ {
321
+ "criteriaSatisfied": [
322
+ {
323
+ "id": "criterion-1",
324
+ "status": "satisfied",
325
+ "evidence": "Verified concrete Phase 3 ownership and constraints in src/extensions/pi-subagents/src/agents/agent-management.ts:675-714, agents/agent-selection.ts, agents/agents.ts:477-510, runs/shared/task-intent.ts, runs/shared/acceptance.ts:76-134, runs/shared/capability-ceiling.ts:300-315, extension/schemas.ts:263-349, extension/tool-description.ts, and targeted unit tests."
326
+ }
327
+ ],
328
+ "changedFiles": [],
329
+ "testsAddedOrUpdated": [],
330
+ "commandsRun": [
331
+ {
332
+ "command": "Targeted read/grep inspection of Phase 3 source and tests",
333
+ "result": "passed",
334
+ "summary": "Verified list discovery, precedence, alias handling, capability ceilings, task-intent/acceptance heuristics, tool safety helper, schema, descriptions, and test seams."
335
+ },
336
+ {
337
+ "command": "npm run test:unit",
338
+ "result": "not-run",
339
+ "summary": "Planning-only task; no implementation was made."
340
+ }
341
+ ],
342
+ "validationOutput": [
343
+ "No code changes were made.",
344
+ "Selected extension of action:'list' with optional task because it avoids action, RPC, preflight-contract, digest, metadata, and dependency changes."
345
+ ],
346
+ "residualRisks": [
347
+ "Task and name-role classification is heuristic; unknown intent must remain non-recommending.",
348
+ "The existing core write-tool classifier cannot prove arbitrary MCP/custom tools are non-mutating.",
349
+ "A restrictive allowedTools ceiling can intentionally result in no writer recommendation."
350
+ ],
351
+ "noStagedFiles": true,
352
+ "diffSummary": "No diff; implementation-ready Phase 3 plan only.",
353
+ "reviewFindings": [
354
+ "no blocker: agent-management.ts:675-714 is the existing advisory list owner.",
355
+ "medium: acceptance.ts:89-101 duplicates role heuristics; centralize the existing rule before advisory routing uses it.",
356
+ "medium: agent-memory.ts:33-39 provides a conservative core-tool write signal and should be reused rather than reimplemented."
357
+ ],
358
+ "manualNotes": "Phase 3 deliberately remains advisory-only. No automatic execution, generic role aliases, telemetry, metadata schema, RPC/preflight surface, or contract-version changes are planned."
359
+ }
360
+ ```
361
+
362
+ ⧉ copy assistant: /cp 4055a2