@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,381 @@
1
+ # Phase 4 Plan — Opt-in Main-Session Broad Exploration Guard
2
+
3
+ ## Scope and decision
4
+
5
+ Implement a **main-session-only**, disabled-by-default guard in `pi-subagents`. It nudges or, only when explicitly configured, blocks repeated **broad** `read`/`grep`/`find`/`ls` exploration. It must not affect child sessions, bash, edits/writes, small targeted reads, or excluded metadata/documentation paths.
6
+
7
+ Use the existing extension `tool_call` hook; a `{ block: true, reason }` result is returned to the model as an error tool result without executing the call. Do not change core tool registration, SDK allowlists, child tool budgets, or the subagent launch contract.
8
+
9
+ ## Preconditions and telemetry gate
10
+
11
+ Phase 4 must not start implementation until all are true:
12
+
13
+ 1. **Phase 1 is released:** dynamic catalog and delegation contract are visible to the main model.
14
+ 2. **Phase 2 is released:** delegated output/context controls are available so delegation does not create unbounded parent context.
15
+ 3. **Phase 3 is released:** advisory routing remains explicit, honors dynamic/capability-restricted agents, and emits aggregate advisory/delegation outcome telemetry.
16
+ 4. **Telemetry gate:** after at least 14 days and 100 root-session advisory opportunities:
17
+ - At least 20% of opportunities reach four broad exploration operations without a successful non-management subagent launch after advisory.
18
+ - Warn-only beta has at least 25 opted-in sessions and 50 warnings.
19
+ - Explicit user bypasses (`allow`/`off`) occur in at most 5% of warning sessions after triage; each exception is reviewed for classifier defects.
20
+ - No child-session guard activation, no handler exception, and no blocked `write`, `edit`, or `bash` event is recorded.
21
+
22
+ If the threshold is not met, stop at Phase 3; do not ship blocking behavior. A warn-only implementation may still be used by opt-in testers to refine false-positive rules.
23
+
24
+ ## Detection policy
25
+
26
+ ### Configuration
27
+
28
+ Add this optional field to `ExtensionConfig`:
29
+
30
+ ```json
31
+ {
32
+ "broadExplorationGuard": {
33
+ "mode": "warn",
34
+ "warnAfter": 2,
35
+ "blockAfter": 4,
36
+ "smallReadMaxLines": 400
37
+ }
38
+ }
39
+ ```
40
+
41
+ Rules:
42
+
43
+ - Missing `broadExplorationGuard`, `false`, or `mode: "off"`: no handler, no command, no telemetry.
44
+ - `mode: "warn"`: emits one nudge at `warnAfter`; never blocks.
45
+ - `mode: "block"`: emits the same nudge at `warnAfter`, then blocks only isolated broad calls after `blockAfter`.
46
+ - Defaults when enabled: `warnAfter: 2`, `blockAfter: 4`, `smallReadMaxLines: 400`.
47
+ - Validation:
48
+ - `warnAfter`: integer `1..20`.
49
+ - `blockAfter`: integer `warnAfter + 1..50`.
50
+ - `smallReadMaxLines`: integer `1..1000`.
51
+ - Invalid guard config disables only this guard, logs a concise configuration error, and fails open.
52
+
53
+ ### Broad-operation classifier
54
+
55
+ Count only `read`, `grep`, `find`, and `ls`. Never inspect or regulate `bash`, `write`, `edit`, custom tools, or `subagent`.
56
+
57
+ Exclude from counting:
58
+
59
+ - Any child process (`SELESAI_SUBAGENT_CHILD=1`).
60
+ - Explicit targeted `read` calls with a non-empty path and `limit <= smallReadMaxLines`.
61
+ - Reads of `SKILL.md`, `AGENTS.md`, `CLAUDE.md`, package manifests/lockfiles, and paths under `docs/`, `.selesai/`, `.pi-subagents/`, `node_modules/`, or `dist/`.
62
+ - Searches/listings whose path is explicitly narrow rather than omitted/current-directory scope.
63
+ - Any broad candidate in a multi-tool batch for blocking purposes.
64
+
65
+ Count as broad:
66
+
67
+ - A non-exempt `read` without an explicit small `limit`.
68
+ - `grep`, `find`, or `ls` scoped to omitted path, `"."`, or the session cwd, with omitted/default-large result limits.
69
+ - At most one broad event per assistant multi-tool batch. A batch may produce a warning but must never be blocked, because sibling results are unavailable during sequential preflight.
70
+
71
+ This is an exploration pacing mechanism, not an authorization boundary. A model can choose narrower operations; that is acceptable and safer than blocking legitimate targeted investigation.
72
+
73
+ ## State machine
74
+
75
+ Maintain state only in memory per root session:
76
+
77
+ | State | Entry | Behavior |
78
+ |---|---|---|
79
+ | `tracking` | enabled session starts | Count eligible broad operations. |
80
+ | `warned` | count reaches `warnAfter` | Send one steer nudge and visible UI notification; allow current call. |
81
+ | `delegation-pending` | a non-management `subagent` call follows a warning | Wait for its `tool_result`. |
82
+ | `tracking` | delegated call succeeds | Reset the current broad-operation streak and warning latch. |
83
+ | `fallback-warn-only` | `subagent` is inactive, or the pending delegated call errors | Never block for the rest of the session; continue warnings/observability. |
84
+ | `bypassed` | user runs session `off` | Permit all calls for the rest of the session. |
85
+ | `blocking` | isolated call would exceed `blockAfter` in `mode: "block"` | Return `{ block: true, reason }`; remain eligible for later explicit user override. |
86
+
87
+ Additional state: broad attempts, allowed broad calls, blocked broad calls, warning count, bypass allowance, and delegation outcome. Do not retain paths, search patterns, task text, tool arguments, tool-call IDs, model output, or child output.
88
+
89
+ Before blocking, check `pi.getActiveTools()` includes `subagent`. If it does not, transition to `fallback-warn-only` and permit the call. When a non-management delegated launch after warning returns `isError`, also transition to `fallback-warn-only`; do not parse its content or guess whether an agent is suitable.
90
+
91
+ ## User escape hatch
92
+
93
+ Register a **user-only slash command** only when the guard is enabled:
94
+
95
+ ```text
96
+ /subagents-exploration-guard status
97
+ /subagents-exploration-guard allow [1..20]
98
+ /subagents-exploration-guard off
99
+ ```
100
+
101
+ - `status` exposes effective mode, state, counters, next threshold, and whether delegation fallback is active; it never displays paths or queries.
102
+ - `allow` permits the requested number of otherwise-blocked broad operations for this session only; default is one, maximum is 20.
103
+ - `off` disables the guard for the current session only.
104
+ - Persistent enablement/disablement remains config-file controlled and takes effect after `/reload` or restart.
105
+ - Do not add a model-callable `subagent` action for bypass. The model must not grant itself an override.
106
+ - Block reasons must name the delegation alternative and the exact user escape command.
107
+
108
+ ## Ordered implementation tasks
109
+
110
+ ### 1. Verify prerequisites and establish the implementation boundary
111
+
112
+ **Discovery**
113
+ - Confirm Phase 1–3 artifacts, release state, and telemetry schema with their owners.
114
+ - Inspect `src/extensions/pi-subagents/src/extension/index.ts`, `src/extensions/pi-subagents/src/extension/tool-description.ts`, and Phase 3 telemetry implementation.
115
+ - Confirm the telemetry-gate report satisfies the numeric criteria above.
116
+
117
+ **Identification**
118
+ - No source change in this task.
119
+ - Phase 4 is owned by `pi-subagents`, because `src/extensions/pi-subagents/src/extension/index.ts` is the host/main-session registration point and owns the `subagent` capability.
120
+
121
+ **Change**
122
+ - Record the go/no-go decision before enabling any block-mode beta.
123
+ - Do not modify Phase 1–3 code, public RPC/preflight versions, child runtime budgets, or core tool definitions.
124
+
125
+ **Verification**
126
+ - Success: telemetry shows advisory routing is insufficient under the declared gate.
127
+ - Failure: if metrics are absent, under-sampled, or show low residual broad exploration, do not implement/enable blocking.
128
+ - Regression: Phase 1–3 behavior remains independently deployable.
129
+
130
+ ### 2. Add validated opt-in guard configuration
131
+
132
+ **Discovery**
133
+ - Inspect `src/extensions/pi-subagents/src/shared/types.ts` `ExtensionConfig`.
134
+ - Inspect `src/extensions/pi-subagents/src/extension/config.ts` load/error behavior.
135
+ - Reuse the existing config-file location and startup loading in `extension/index.ts`; do not add a second settings file.
136
+
137
+ **Identification**
138
+ - Modify `src/extensions/pi-subagents/src/shared/types.ts` to add `BroadExplorationGuardConfig` and `ExtensionConfig.broadExplorationGuard`.
139
+ - Add `src/extensions/pi-subagents/src/extension/exploration-guard.ts` for guard-specific parsing/defaulting.
140
+ - Add `src/extensions/pi-subagents/test/unit/main-exploration-guard.test.ts`.
141
+
142
+ **Change**
143
+ - Export exact symbols from the new module:
144
+ - `resolveBroadExplorationGuardConfig(raw)`
145
+ - `classifyBroadExplorationCall(event, cwd, smallReadMaxLines)`
146
+ - `registerMainExplorationGuard(pi, config)`
147
+ - Make `resolveBroadExplorationGuardConfig` return either normalized config or a concise error. Invalid input must result in disabled guard behavior, not a thrown `tool_call` handler error.
148
+ - Keep guard config separate from child `ToolBudgetConfig`; it has different scope and semantics.
149
+ - Do not add environment-variable overrides, global telemetry dependencies, or new package dependencies.
150
+
151
+ **Verification**
152
+ - Success: absent/`false`/`off` configuration yields inactive behavior; valid warn and block configurations normalize defaults.
153
+ - Failure: malformed objects, non-integers, inverted thresholds, and out-of-range values fail open with an error.
154
+ - Regression: existing config keys, especially `toolBudget`, remain unchanged.
155
+
156
+ ### 3. Implement classifier and state-machine behavior
157
+
158
+ **Discovery**
159
+ - Inspect `src/core/tools/read.ts`, `grep.ts`, `find.ts`, and `ls.ts` input shapes and default limits.
160
+ - Inspect `src/extensions/workflow/adapter.ts` `isSoleToolCall` and `transitionBatchBlock`.
161
+ - Inspect `src/core/extensions/types.ts` `ToolCallEvent`, `ToolCallEventResult`, and `ExtensionAPI.getActiveTools()`.
162
+
163
+ **Identification**
164
+ - Modify only `src/extensions/pi-subagents/src/extension/exploration-guard.ts` and its new unit test.
165
+ - Do not export or change private core read-classification helpers; implement the narrow guard classifier locally from typed event inputs.
166
+
167
+ **Change**
168
+ - Implement the exclusion and broad-operation rules above.
169
+ - Inspect `ctx.sessionManager.getBranch()` only to determine whether the current assistant message has multiple tool calls; never persist branch contents.
170
+ - Deduplicate to one counted event per batch.
171
+ - Implement the documented state transitions, including:
172
+ - single soft nudge through `pi.sendUserMessage(..., { deliverAs: "steer" })`;
173
+ - best-effort `ctx.ui.notify` when UI exists;
174
+ - block response only for isolated broad calls in block mode;
175
+ - active-tool and failed-delegation fallback to warn-only;
176
+ - successful non-management delegated execution resets the current streak.
177
+ - Wrap all event-handler logic in `try/catch`; on any unexpected error, emit a concise local diagnostic and return `undefined` so the tool executes.
178
+ - Keep block/nudge strings short and stable. Example block reason:
179
+
180
+ ```text
181
+ Exploration guard: repeated broad repo exploration is paused. Delegate the remaining survey with subagent, or ask the user to run /subagents-exploration-guard allow or off. Small targeted reads remain allowed.
182
+ ```
183
+
184
+ **Verification**
185
+ - Success cases:
186
+ - Two broad operations warn once with default thresholds.
187
+ - In block mode, four broad operations are allowed and the next isolated broad operation is blocked.
188
+ - A successful delegated execution resets the streak.
189
+ - A successful `subagent({ action: "list" })` does not reset the streak.
190
+ - Failure/fallback cases:
191
+ - Inactive `subagent` tool or failed delegated execution permits continued exploration in warn-only fallback.
192
+ - Handler exceptions fail open.
193
+ - Multi-tool batches are not blocked.
194
+ - Regression checks:
195
+ - `bash`, `write`, `edit`, custom tools, small targeted reads, excluded documentation/resource paths, and narrow searches are never blocked.
196
+
197
+ ### 4. Register the guard at the main host lifecycle boundary
198
+
199
+ **Discovery**
200
+ - Inspect `src/extensions/pi-subagents/src/extension/index.ts` startup cleanup (`__piSubagentRuntimeCleanup`), `session_start`, and `session_shutdown`.
201
+ - Inspect `src/extensions/pi-subagents/src/runs/shared/pi-args.ts` `SUBAGENT_CHILD_ENV`.
202
+ - Inspect `test/unit/index-child-registration.test.ts` child-registration assertions.
203
+
204
+ **Identification**
205
+ - Modify `src/extensions/pi-subagents/src/extension/index.ts`.
206
+ - Reuse the new `registerMainExplorationGuard` from `exploration-guard.ts`.
207
+ - Do not modify `subagent-prompt-runtime.ts`, `tool-budget.ts`, `pi-args.ts`, or `src/core/agent-session.ts`.
208
+
209
+ **Change**
210
+ - After `const config = loadConfig()`, resolve/register the main guard.
211
+ - Ensure `registerMainExplorationGuard` independently returns without registration when `SUBAGENT_CHILD_ENV === "1"`.
212
+ - Add its `dispose()` call to the existing reload cleanup path. Disposal must make stale callbacks inert because `pi.on` handlers may remain registered after reload.
213
+ - Reset only in-memory guard counters on `session_start` and clear them on `session_shutdown`.
214
+ - Register the slash command only for enabled configurations and only in the main process.
215
+
216
+ **Verification**
217
+ - Success: enabled root session registers one `tool_call`, one `tool_result`, lifecycle handlers, and the user command.
218
+ - Failure: disabled config registers no guard handler; guard initialization error cannot prevent the rest of `pi-subagents` from loading.
219
+ - Regression: existing child-mode early-return test still proves no parent extension registrations occur in normal or fanout child sessions.
220
+
221
+ ### 5. Add privacy-preserving observability
222
+
223
+ **Discovery**
224
+ - Inspect `ExtensionAPI.appendEntry` in `src/core/extensions/types.ts`.
225
+ - Inspect existing custom-entry and notification practices in `extension/index.ts` and watchdog runtime code.
226
+
227
+ **Identification**
228
+ - Modify `src/extensions/pi-subagents/src/extension/exploration-guard.ts`.
229
+ - Extend `src/extensions/pi-subagents/test/unit/main-exploration-guard.test.ts`.
230
+
231
+ **Change**
232
+ - Emit local aggregate transition entries only for:
233
+ - activated,
234
+ - warned,
235
+ - blocked,
236
+ - user-allow,
237
+ - user-off,
238
+ - delegation-started,
239
+ - delegation-succeeded,
240
+ - delegation-failed,
241
+ - delegation-unavailable,
242
+ - config-invalid.
243
+ - Entry payload may include mode, state, aggregate counters, and classifier category (`read`, `grep`, `find`, `ls`), but must exclude paths, patterns, tool arguments, task text, raw errors, model output, and identifiers.
244
+ - Do not send network telemetry, write a new log file, or store raw branch/session contents.
245
+ - Ensure status output uses only the same aggregate fields.
246
+
247
+ **Verification**
248
+ - Success: transition entries are sufficient to produce telemetry-gate aggregates.
249
+ - Privacy failure: tests assert no source path or grep pattern is present in appended data, notifications, or command status.
250
+ - Regression: no entries are emitted when config is absent/off.
251
+
252
+ ### 6. Document configuration, behavior, and rollback
253
+
254
+ **Discovery**
255
+ - Inspect `src/extensions/pi-subagents/README.md` Configuration and watchdog command sections.
256
+ - Confirm the documented config path matches `getConfigPath()`.
257
+
258
+ **Identification**
259
+ - Modify `src/extensions/pi-subagents/README.md`.
260
+ - Do not change the always-visible subagent tool description: the guard is off by default and block reasons already instruct the model when it is active.
261
+
262
+ **Change**
263
+ - Add a `broadExplorationGuard` configuration section with:
264
+ - disabled-by-default statement;
265
+ - warn/block examples;
266
+ - broad-operation and exclusion definitions;
267
+ - child exclusion;
268
+ - fallback when delegation is unavailable;
269
+ - slash-command escape hatch;
270
+ - privacy statement;
271
+ - `/reload` requirement;
272
+ - rollback instructions: set `mode: "off"` or remove the block, then reload.
273
+ - State explicitly that this is not a security boundary and does not regulate bash commands.
274
+
275
+ **Verification**
276
+ - Success: copyable JSON examples validate under the new parser.
277
+ - Regression: documentation does not imply auto-delegation, automatic user consent, or child enforcement.
278
+
279
+ ### 7. Complete tests and release validation
280
+
281
+ **Discovery**
282
+ - Inspect `src/extensions/pi-subagents/package.json` test scripts and root `package.json` build script.
283
+ - Confirm `@selesai/code` alias/build requirements before testing extension code.
284
+
285
+ **Identification**
286
+ - Add/update:
287
+ - `src/extensions/pi-subagents/test/unit/main-exploration-guard.test.ts`
288
+ - `src/extensions/pi-subagents/test/unit/index-child-registration.test.ts` only if existing child early-return coverage cannot exercise the new registration path.
289
+
290
+ **Change**
291
+ - Test config parsing, classifier boundaries, state transitions, batch behavior, delegation success/failure fallback, user bypass, observability redaction, reload disposal, disabled default, and child exclusion.
292
+ - Use fake `pi`, fake `ctx`, and fake `sessionManager.getBranch()`; no real tools or child processes are required for core state-machine tests.
293
+ - Do not add end-to-end model tests or modify core Vitest harnesses.
294
+
295
+ **Commands**
296
+ ```bash
297
+ cd src/extensions/pi-subagents && npm run test:unit
298
+ npm run build
299
+ npx vitest run src/__tests__/task-workflow.test.ts
300
+ ```
301
+
302
+ The final Vitest command is a regression check for the shared `tool_call` block contract. If a targeted extension test command is desired during iteration:
303
+
304
+ ```bash
305
+ cd src/extensions/pi-subagents && node --experimental-strip-types --test test/unit/main-exploration-guard.test.ts
306
+ ```
307
+
308
+ ## Acceptance criteria
309
+
310
+ - Guard is absent/inert by default.
311
+ - Guard runs only in root/main sessions and never in normal or fanout children.
312
+ - Only `read`, `grep`, `find`, and `ls` are considered; `bash`, writes, edits, and custom tools are never blocked.
313
+ - Small explicit reads and listed documentation/resource/excluded paths are never counted.
314
+ - Block mode always warns before blocking and never blocks a multi-tool batch.
315
+ - Delegation unavailable or failed after a warning transitions to warn-only fallback, not hard blocking.
316
+ - User-only session `allow` and `off` escape hatches work without persistent config mutation.
317
+ - Handler failures fail open.
318
+ - Observability is aggregate-only and contains no paths, patterns, prompts, tool arguments, or outputs.
319
+ - README documents enablement, thresholds, fallback, privacy, and rollback.
320
+ - All specified unit tests, root build, and workflow regression test pass.
321
+
322
+ ## Risks and mitigations
323
+
324
+ | Severity | Risk | Mitigation |
325
+ |---|---|---|
326
+ | High | A throwing `tool_call` handler blocks execution through the host fail-safe path. | Catch all guard errors and return `undefined`; keep parser/classifier synchronous and dependency-free. |
327
+ | High | Parallel preflight cannot see sibling results, creating unjustified blocks. | Never block a multi-tool batch; count at most one broad event for warning purposes. |
328
+ | Medium | Legitimate repository investigation may resemble broad browsing. | Narrow classifier, explicit small-read/resource exclusions, warn-only rollout, and user-only temporary/session bypasses. |
329
+ | Medium | A suitable specialist may be unavailable despite advisory text. | Check active `subagent`; downgrade to warn-only after a failed delegated execution; never parse or guess agent suitability. |
330
+ | Medium | Persisted observability may leak source details. | Persist only aggregate state/category/counters; prohibit raw args, paths, patterns, task content, output, and errors. |
331
+ | Low | Config changes are not live. | Document `/reload`/restart and provide session-only escape commands. |
332
+
333
+ ## Rollout and rollback
334
+
335
+ 1. Land code with config absent/off by default.
336
+ 2. Enable only `mode: "warn"` for volunteer sessions after the telemetry prerequisite is met.
337
+ 3. Review aggregate false positives and bypasses after the warn-only cohort gate.
338
+ 4. Permit `mode: "block"` only as explicit opt-in; never auto-upgrade existing warn users.
339
+ 5. Roll back immediately by setting `broadExplorationGuard.mode` to `"off"` or removing the block and reloading. This removes enforcement without data migration or child-process impact.
340
+
341
+ ```acceptance-report
342
+ {
343
+ "criteriaSatisfied": [
344
+ {
345
+ "id": "criterion-1",
346
+ "status": "satisfied",
347
+ "evidence": "Verified concrete ownership and hook findings: src/extensions/pi-subagents/src/extension/index.ts registers the root extension and returns early for SUBAGENT_CHILD_ENV; src/core/agent-session.ts and src/core/extensions/runner.ts route tool_call blocks; src/core/extensions/types.ts defines ToolCallEvent/ToolCallEventResult and getActiveTools(); src/extensions/workflow/adapter.ts provides the main-session blocking and batch-inspection precedent; src/extensions/pi-subagents/src/runs/shared/tool-budget.ts provides soft-nudge/hard-block wording and counter precedent."
348
+ }
349
+ ],
350
+ "changedFiles": [],
351
+ "testsAddedOrUpdated": [],
352
+ "commandsRun": [
353
+ {
354
+ "command": "read/grep over Phase 1-4 reconnaissance, extension registration/config, tool schemas, hook types, workflow adapter, and unit-test harnesses",
355
+ "result": "passed",
356
+ "summary": "Static source verification completed; no implementation commands were run because this task is planning-only."
357
+ }
358
+ ],
359
+ "validationOutput": [
360
+ "Confirmed the safest host hook is the pi-subagents main-session tool_call handler, not core tool registration or child tool-budget code.",
361
+ "Confirmed child exclusion is already structurally supported by src/extensions/pi-subagents/src/extension/index.ts early return and existing index-child-registration tests.",
362
+ "Confirmed read/grep/find/ls schemas expose the path/limit signals required for a conservative broad-operation classifier."
363
+ ],
364
+ "residualRisks": [
365
+ "Phase 1-3 implementation and telemetry availability were not verified as released in this planning task; Phase 4 is gated on their completion and measured advisory insufficiency.",
366
+ "The host's sequential parallel-tool preflight makes result-aware batch enforcement unsafe; this plan intentionally permits all multi-tool batches.",
367
+ "No raw telemetry service was found in the inspected Phase 4 surfaces; aggregate local transition entries must be mapped to the Phase 3 telemetry process before rollout."
368
+ ],
369
+ "noStagedFiles": true,
370
+ "diffSummary": "No files modified; implementation-ready Phase 4 opt-in enforcement plan only.",
371
+ "reviewFindings": [
372
+ "high: src/core/extensions/runner.ts:933-954 and src/core/agent-session.ts:484-513 - handler exceptions propagate into tool blocking; guard implementation must fail open.",
373
+ "high: docs/extensions.md:711-713 and src/extensions/workflow/adapter.ts:402-426 - sibling results are unavailable during parallel preflight; broad-operation blocking must exclude multi-tool batches.",
374
+ "medium: src/extensions/pi-subagents/src/runs/shared/tool-budget.ts - existing tool budget applies to child runtime only and must not be reused as parent enforcement without child/main isolation and false-positive controls.",
375
+ "medium: src/core/tools/read.ts, grep.ts, find.ts, and ls.ts - naive counting would classify normal targeted investigation as broad; classifier must require the documented path/limit conditions."
376
+ ],
377
+ "manualNotes": "No implementation or edits were performed. The recommended design adds one main-only pi-subagents extension module, one optional ExtensionConfig field, focused node:test coverage, and README documentation; it deliberately avoids core, SDK, RPC, preflight, schema, and child-runtime changes."
378
+ }
379
+ ```
380
+
381
+ ⧉ copy assistant: /cp 35abed
package/docs/providers.md CHANGED
@@ -18,8 +18,11 @@ Use `/login` in interactive mode, then select a provider:
18
18
  - ChatGPT Plus/Pro (Codex)
19
19
  - Claude Pro/Max
20
20
  - GitHub Copilot
21
+ - xAI (Grok/X subscription)
22
+ - OpenRouter (OAuth-minted API key billed from OpenRouter credits)
23
+ - Radius
21
24
 
22
- Use `/logout` to clear credentials. Tokens are stored in `~/.pi/agent/auth.json` and auto-refresh when expired.
25
+ Use `/logout` to clear credentials. Tokens are stored in `~/.selesai/agent/auth.json` and auto-refresh when expired. OpenRouter instead mints a user-controlled API key that does not expire automatically.
23
26
 
24
27
  ### OpenAI Codex
25
28
 
@@ -35,6 +38,22 @@ Anthropic subscription auth is active for Claude Pro/Max accounts. Third-party h
35
38
  - Press Enter for github.com, or enter your GitHub Enterprise Server domain
36
39
  - If you get "model not supported", enable it in VS Code: Copilot Chat → model selector → select model → "Enable"
37
40
 
41
+ ### xAI (Grok/X subscription)
42
+
43
+ - Run `/login xai`, then select **Use a subscription**
44
+ - `XAI_API_KEY` remains available through **Use an API key**
45
+
46
+ ### OpenRouter
47
+
48
+ - Run `/login openrouter`, then select **Sign in with OpenRouter** to open the OpenRouter PKCE authorization flow
49
+ - The authorization creates a user-controlled OpenRouter API key billed from your OpenRouter credits
50
+ - On remote/headless machines (e.g. over SSH) the browser cannot reach the loopback callback; paste the final redirect URL (or the authorization code) into the login prompt instead
51
+ - `OPENROUTER_API_KEY` remains available through **Use an API key**
52
+
53
+ ### Radius
54
+
55
+ Radius is a dynamic `pi-messages` gateway. `/login radius` stores OAuth tokens in `auth.json`; the gateway catalog is refreshed independently and cached in `models-store.json`. Custom Radius gateways can be declared in `models.json` with `"oauth": "radius"` and a gateway `baseUrl`.
56
+
38
57
  ## API Keys
39
58
 
40
59
  ### Environment Variables or Auth File
@@ -82,7 +101,7 @@ Reference for environment variables and `auth.json` keys: [`const envMap`](https
82
101
 
83
102
  #### Auth File
84
103
 
85
- Store credentials in `~/.pi/agent/auth.json`:
104
+ Store credentials in `~/.selesai/agent/auth.json`:
86
105
 
87
106
  ```json
88
107
  {
package/docs/rpc.md CHANGED
@@ -23,7 +23,7 @@ Common options:
23
23
  - **Responses**: JSON objects with `type: "response"` indicating command success/failure
24
24
  - **Events**: Agent events streamed to stdout as JSON lines
25
25
 
26
- All commands support an optional `id` field for request/response correlation. If provided, the corresponding response will include the same `id`.
26
+ All commands support an optional `id` field for request/response correlation. If provided, the corresponding response will include the same `id`. `bash_execution_update` events also include the `id` of their originating `bash` command.
27
27
 
28
28
  ### Framing
29
29
 
@@ -427,15 +427,18 @@ Response:
427
427
 
428
428
  #### bash
429
429
 
430
- Execute a shell command and add output to conversation context.
430
+ Execute a shell command and add output to conversation context. Output streams as `bash_execution_update` events while the command runs; the response contains the final result.
431
431
 
432
432
  ```json
433
- {"type": "bash", "command": "ls -la"}
433
+ {"id": "req-1", "type": "bash", "command": "ls -la"}
434
434
  ```
435
435
 
436
+ Include an `id` to associate streamed `bash_execution_update` events with this command.
437
+
436
438
  Response:
437
439
  ```json
438
440
  {
441
+ "id": "req-1",
439
442
  "type": "response",
440
443
  "command": "bash",
441
444
  "success": true,
@@ -466,7 +469,7 @@ If output was truncated, includes `fullOutputPath`:
466
469
 
467
470
  **How bash results reach the LLM:**
468
471
 
469
- The `bash` command executes immediately and returns a `BashResult`. Internally, a `BashExecutionMessage` is created and stored in the agent's message state. This message does NOT emit an event.
472
+ The `bash` command executes immediately and returns a `BashResult`. Internally, a `BashExecutionMessage` is created and stored in the agent's message state.
470
473
 
471
474
  When the next `prompt` command is sent, all messages (including `BashExecutionMessage`) are transformed before being sent to the LLM. The `BashExecutionMessage` is converted to a `UserMessage` with this format:
472
475
 
@@ -481,7 +484,6 @@ drwxr-xr-x ...
481
484
  This means:
482
485
  1. Bash output is included in the LLM context on the **next prompt**, not immediately
483
486
  2. Multiple bash commands can be executed before a prompt; all outputs will be included
484
- 3. No event is emitted for the `BashExecutionMessage` itself
485
487
 
486
488
  #### abort_bash
487
489
 
@@ -743,7 +745,7 @@ Each command has:
743
745
 
744
746
  ## Events
745
747
 
746
- Events are streamed to stdout as JSON lines during agent operation. Events do NOT include an `id` field (only responses do).
748
+ Events are streamed to stdout as JSON lines during agent operation. Events do not generally include an `id` field; `bash_execution_update` includes the `id` of its originating `bash` command when one was provided.
747
749
 
748
750
  ### Event Types
749
751
 
@@ -756,6 +758,7 @@ Events are streamed to stdout as JSON lines during agent operation. Events do NO
756
758
  | `message_start` | Message begins |
757
759
  | `message_update` | Streaming update (text/thinking/toolcall deltas) |
758
760
  | `message_end` | Message completes |
761
+ | `bash_execution_update` | Direct RPC bash command output chunk |
759
762
  | `tool_execution_start` | Tool begins execution |
760
763
  | `tool_execution_update` | Tool execution progress (streaming output) |
761
764
  | `tool_execution_end` | Tool completes |
@@ -852,6 +855,20 @@ Example streaming a text response:
852
855
  {"type":"message_update","message":{...},"assistantMessageEvent":{"type":"text_end","contentIndex":0,"content":"Hello world","partial":{...}}}
853
856
  ```
854
857
 
858
+ ### bash_execution_update
859
+
860
+ Emitted once for each output chunk from a direct `bash` command. `id` matches the command's `id`, allowing clients to associate output with the correct command.
861
+
862
+ Events stream all output while the command runs, even if the final `bash` response's `output` is truncated.
863
+
864
+ ```json
865
+ {
866
+ "type": "bash_execution_update",
867
+ "id": "req-1",
868
+ "delta": "total 48\n"
869
+ }
870
+ ```
871
+
855
872
  ### tool_execution_start / tool_execution_update / tool_execution_end
856
873
 
857
874
  Emitted when a tool begins, streams progress, and completes execution.
@@ -116,6 +116,8 @@ interface Usage {
116
116
  }
117
117
  ```
118
118
 
119
+ The exported pi-ai `StopReason` type also includes `"pending"`, but that value is reserved for partial messages in streaming events. Terminal `done`/`error` messages replace it with a completion reason before pi persists the assistant message, so `"pending"` should never appear in session JSONL.
120
+
119
121
  ### Extended Message Types (from pi-coding-agent)
120
122
 
121
123
  ```typescript
package/docs/settings.md CHANGED
@@ -131,7 +131,7 @@ Set `PI_SKIP_VERSION_CHECK=1` to disable the Pi version update check. Use `--off
131
131
  | `retry.provider.maxRetries` | number | `0` | Provider/SDK retry attempts |
132
132
  | `retry.provider.maxRetryDelayMs` | number | `60000` | Max server-requested delay before failing (60s) |
133
133
 
134
- When a provider requests a retry delay longer than `retry.provider.maxRetryDelayMs` (e.g., Google's "quota will reset after 5h"), the request fails immediately with an informative error instead of waiting silently. Set to `0` to disable the cap.
134
+ When a provider requests a retry delay longer than `retry.provider.maxRetryDelayMs`, the request fails immediately with an informative error instead of waiting silently. Set it to `0` to disable the limit.
135
135
 
136
136
  Keep `retry.provider.maxRetries` at `0` unless provider-level retries are explicitly needed. Setting it above `0` can make SDK/provider retries handle out-of-usage-limit errors before Pi sees them, which may block the agent until the provider quota resets in some circumstances.
137
137
 
package/docs/usage.md CHANGED
@@ -286,19 +286,6 @@ pi --tools read,grep,find,ls -p "Review the code"
286
286
  pi --exclude-tools ask_question
287
287
  ```
288
288
 
289
- ### Environment Variables
290
-
291
- | Variable | Description |
292
- |----------|-------------|
293
- | `PI_CODING_AGENT_DIR` | Override config directory; default is `~/.pi/agent` |
294
- | `PI_CODING_AGENT_SESSION_DIR` | Override session storage directory; overridden by `--session-dir` |
295
- | `PI_PACKAGE_DIR` | Override package directory, useful for Nix/Guix store paths |
296
- | `PI_OFFLINE` | Disable startup network operations, including update checks, package update checks, and install/update telemetry |
297
- | `PI_SKIP_VERSION_CHECK` | Skip the Pi version update check at startup. This prevents the `pi.dev` latest-version request |
298
- | `PI_TELEMETRY` | Override install/update telemetry and provider attribution headers: `1`/`true`/`yes` or `0`/`false`/`no`. This does not disable update checks |
299
- | `PI_CACHE_RETENTION` | Set to `long` for extended prompt cache where supported |
300
- | `VISUAL`, `EDITOR` | External editor for Ctrl+G |
301
-
302
289
  ## Design Principles
303
290
 
304
291
  Pi keeps the core small and pushes workflow-specific behavior into extensions, skills, prompt templates, and packages.
@@ -13,9 +13,10 @@
13
13
  * pi --extension examples/extensions/custom-compaction.ts
14
14
  */
15
15
 
16
+ import { uuidv7 } from "@earendil-works/pi-ai";
16
17
  import { complete } from "@earendil-works/pi-ai/compat";
17
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
18
- import { convertToLlm, serializeConversation } from "@earendil-works/pi-coding-agent";
18
+ import type { ExtensionAPI } from "@selesai/code";
19
+ import { convertToLlm, serializeConversation } from "@selesai/code";
19
20
 
20
21
  export default function (pi: ExtensionAPI) {
21
22
  pi.on("session_before_compact", async (event, ctx) => {
@@ -95,6 +96,8 @@ ${conversationText}
95
96
  headers: auth.headers,
96
97
  maxTokens: 8192,
97
98
  signal,
99
+ cacheRetention: "none",
100
+ sessionId: uuidv7(),
98
101
  },
99
102
  );
100
103
 
@@ -43,7 +43,7 @@ import {
43
43
  type ToolCall,
44
44
  type ToolResultMessage,
45
45
  } from "@earendil-works/pi-ai";
46
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
46
+ import type { ExtensionAPI } from "@selesai/code";
47
47
 
48
48
  // =============================================================================
49
49
  // OAuth Implementation (copied from packages/ai/src/utils/oauth/anthropic.ts)
@@ -353,7 +353,7 @@ function streamCustomAnthropic(
353
353
  totalTokens: 0,
354
354
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
355
355
  },
356
- stopReason: "stop",
356
+ stopReason: "pending",
357
357
  timestamp: Date.now(),
358
358
  };
359
359
 
@@ -546,8 +546,14 @@ function streamCustomAnthropic(
546
546
  if (options?.signal?.aborted) {
547
547
  throw new Error("Request was aborted");
548
548
  }
549
+ if (output.stopReason === "pending") {
550
+ throw new Error("Anthropic stream ended without a stop reason");
551
+ }
552
+ if (output.stopReason === "error" || output.stopReason === "aborted") {
553
+ throw new Error(output.errorMessage || "An unknown error occurred");
554
+ }
549
555
 
550
- stream.push({ type: "done", reason: output.stopReason as "stop" | "length" | "toolUse", message: output });
556
+ stream.push({ type: "done", reason: output.stopReason, message: output });
551
557
  stream.end();
552
558
  } catch (error) {
553
559
  for (const block of output.content) delete (block as any).index;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider",
3
- "version": "0.80.2",
3
+ "version": "0.83.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pi-extension-custom-provider",
9
- "version": "0.80.2",
9
+ "version": "0.83.0",
10
10
  "dependencies": {
11
11
  "@anthropic-ai/sdk": "^0.52.0"
12
12
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-anthropic",
3
3
  "private": true,
4
- "version": "0.80.2",
4
+ "version": "0.83.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-extension-custom-provider-gitlab-duo",
3
3
  "private": true,
4
- "version": "0.80.2",
4
+ "version": "0.83.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "clean": "echo 'nothing to clean'",