@xzzpig/pi-subagents 0.21.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1132) hide show
  1. package/CHANGELOG.md +356 -0
  2. package/README.md +2 -2
  3. package/agents/evidence-auditor.md +1 -0
  4. package/agents/oracle.md +1 -0
  5. package/agents/reviewer.md +1 -0
  6. package/bundle/agent-management.js +16 -0
  7. package/bundle/agents.js +41 -0
  8. package/bundle/background-work.js +16 -0
  9. package/bundle/capability-ceiling.js +22 -0
  10. package/bundle/child-tool-plan.js +11 -0
  11. package/bundle/chunk-355ECEP2.js +1321 -0
  12. package/bundle/chunk-35GII5EF.js +637 -0
  13. package/bundle/chunk-3G4JXNZ4.js +4130 -0
  14. package/bundle/chunk-3U633XDZ.js +749 -0
  15. package/bundle/chunk-4QFZZV3O.js +57 -0
  16. package/bundle/chunk-62OCY2S4.js +14 -0
  17. package/bundle/chunk-7J4ZXMY7.js +18 -0
  18. package/bundle/chunk-7K3Z6DM7.js +276 -0
  19. package/bundle/chunk-BGIYHF2W.js +138 -0
  20. package/bundle/chunk-CTPAE36Y.js +94 -0
  21. package/bundle/chunk-D4EHT5SJ.js +14 -0
  22. package/bundle/chunk-ED55MIC2.js +1681 -0
  23. package/bundle/chunk-F3NSN7UH.js +7331 -0
  24. package/bundle/chunk-FJWI64H7.js +490 -0
  25. package/bundle/chunk-H36HBZB2.js +753 -0
  26. package/bundle/chunk-ICNYIALB.js +7347 -0
  27. package/bundle/chunk-KD2IMFN4.js +1310 -0
  28. package/bundle/chunk-LCDJWBVM.js +57 -0
  29. package/bundle/chunk-LPVUHUZ7.js +5503 -0
  30. package/bundle/chunk-MYCL5QEJ.js +1372 -0
  31. package/bundle/chunk-NCWCVJLT.js +1768 -0
  32. package/bundle/chunk-NIXWDZZV.js +9 -0
  33. package/bundle/chunk-NTRJDXBC.js +4175 -0
  34. package/bundle/chunk-OFGSZBHP.js +16924 -0
  35. package/bundle/chunk-OTLRAB22.js +143 -0
  36. package/bundle/chunk-QXASAHIA.js +173 -0
  37. package/bundle/chunk-RB4GELQA.js +458 -0
  38. package/bundle/chunk-RK2HDPLK.js +1234 -0
  39. package/bundle/chunk-SW2VMNIU.js +526 -0
  40. package/bundle/chunk-T65XRVVM.js +940 -0
  41. package/bundle/chunk-U4ODUYAG.js +235 -0
  42. package/bundle/chunk-UFNSLL5D.js +9796 -0
  43. package/bundle/chunk-UKG4V45O.js +228 -0
  44. package/bundle/chunk-UQDHXMUG.js +264 -0
  45. package/bundle/chunk-V2KFIGFH.js +8774 -0
  46. package/bundle/chunk-VO3G7HI3.js +85 -0
  47. package/bundle/chunk-WPW4V6HM.js +227 -0
  48. package/bundle/chunk-WW76JRIX.js +175 -0
  49. package/bundle/chunk-XA3DY6UG.js +161 -0
  50. package/bundle/chunk-YFCK7H2S.js +129 -0
  51. package/bundle/chunk-YYREO77V.js +137 -0
  52. package/bundle/chunk-Z6TFJ6BR.js +400 -0
  53. package/bundle/control-channel.js +11 -0
  54. package/bundle/delegation.js +14 -0
  55. package/bundle/external-job-provider.js +20 -0
  56. package/bundle/external-runs.js +21 -0
  57. package/bundle/index.js +30 -0
  58. package/bundle/inspectors.js +8 -0
  59. package/bundle/intercom-bridge.js +11 -0
  60. package/bundle/preflight.js +468 -0
  61. package/bundle/project-panes.js +28 -0
  62. package/bundle/required-child-extensions.js +6 -0
  63. package/bundle/shared-types.js +8 -0
  64. package/bundle/supervisor-routing.js +12 -0
  65. package/bundle/workflow-resources.js +7 -0
  66. package/docs/agents.md +42 -10
  67. package/docs/configuration.md +59 -14
  68. package/docs/extension-api.md +61 -9
  69. package/docs/fork-supervisor-routing.md +77 -0
  70. package/docs/missions.md +2 -0
  71. package/docs/observability.md +20 -5
  72. package/docs/standalone-background.md +8 -6
  73. package/docs/tool-reference.md +18 -5
  74. package/docs/workflows.md +25 -7
  75. package/index.d.ts +3 -0
  76. package/index.js +14 -0
  77. package/node_modules/@xzzpig/pi-components/package.json +1 -2
  78. package/package.json +107 -86
  79. package/skills/council-mode/SKILL.md +1 -4
  80. package/skills/pi-subagents/SKILL.md +130 -106
  81. package/skills/pi-subagents/references/orchestration.md +124 -0
  82. package/skills/pi-subagents/references/prompting-and-roles.md +96 -291
  83. package/src/agents/advertised-agent-prompt.d.ts +13 -0
  84. package/src/agents/advertised-agent-prompt.js +68 -0
  85. package/src/agents/agent-eject.d.ts +39 -0
  86. package/src/agents/agent-eject.js +263 -0
  87. package/src/agents/agent-management.d.ts +33 -0
  88. package/src/agents/agent-management.js +1541 -0
  89. package/src/agents/agent-memory.d.ts +48 -0
  90. package/src/agents/agent-memory.js +350 -0
  91. package/src/agents/agent-refinements.d.ts +99 -0
  92. package/src/agents/agent-refinements.js +568 -0
  93. package/src/agents/agent-scope.d.ts +3 -0
  94. package/src/agents/agent-scope.js +8 -0
  95. package/src/agents/agent-selection.d.ts +2 -0
  96. package/src/agents/agent-selection.js +22 -0
  97. package/src/agents/agent-serializer.d.ts +7 -0
  98. package/src/agents/agent-serializer.js +213 -0
  99. package/src/agents/agents.d.ts +352 -0
  100. package/src/agents/agents.js +2817 -0
  101. package/src/agents/builtin-names.d.ts +1 -0
  102. package/src/agents/builtin-names.js +16 -0
  103. package/src/agents/chain-serializer.d.ts +6 -0
  104. package/src/agents/chain-serializer.js +318 -0
  105. package/src/agents/frontmatter.d.ts +19 -0
  106. package/src/agents/frontmatter.js +166 -0
  107. package/src/agents/global-npm-root.d.ts +6 -0
  108. package/src/agents/global-npm-root.js +57 -0
  109. package/src/agents/identity.d.ts +7 -0
  110. package/src/agents/identity.js +29 -0
  111. package/src/agents/proactive-skills.d.ts +35 -0
  112. package/src/agents/proactive-skills.js +155 -0
  113. package/src/agents/runtime-agent-events.d.ts +26 -0
  114. package/src/agents/runtime-agent-events.js +52 -0
  115. package/src/agents/runtime-agent-registry.d.ts +66 -0
  116. package/src/agents/runtime-agent-registry.js +415 -0
  117. package/src/agents/runtime-discovery.d.ts +13 -0
  118. package/src/agents/runtime-discovery.js +27 -0
  119. package/src/agents/skills.d.ts +34 -0
  120. package/src/agents/skills.js +718 -0
  121. package/src/api/agent-management.d.ts +2 -0
  122. package/src/api/agent-management.js +2 -0
  123. package/src/api/agents.d.ts +6 -0
  124. package/src/api/agents.js +3 -0
  125. package/src/api/background-work.d.ts +41 -0
  126. package/src/api/background-work.js +171 -0
  127. package/src/api/capability-ceiling.d.ts +1 -0
  128. package/src/api/capability-ceiling.js +1 -0
  129. package/src/api/child-tool-plan.d.ts +1 -0
  130. package/src/api/child-tool-plan.js +1 -0
  131. package/src/api/control-channel.d.ts +1 -0
  132. package/src/api/control-channel.js +1 -0
  133. package/src/api/delegation.d.ts +132 -0
  134. package/src/api/delegation.js +8 -0
  135. package/src/api/external-job-provider.d.ts +57 -0
  136. package/src/api/external-job-provider.js +139 -0
  137. package/src/api/external-runs.d.ts +47 -0
  138. package/src/api/external-runs.js +245 -0
  139. package/src/api/inspectors.d.ts +20 -0
  140. package/src/api/inspectors.js +11 -0
  141. package/src/api/intercom-bridge.d.ts +1 -0
  142. package/src/api/intercom-bridge.js +1 -0
  143. package/src/api/preflight.d.ts +183 -0
  144. package/src/api/preflight.js +455 -0
  145. package/src/api/project-panes.d.ts +7 -0
  146. package/src/api/project-panes.js +7 -0
  147. package/src/api/required-child-extensions.d.ts +1 -0
  148. package/src/api/required-child-extensions.js +1 -0
  149. package/src/api/shared-types.d.ts +1 -0
  150. package/src/api/shared-types.js +1 -0
  151. package/src/api/supervisor-routing.d.ts +110 -0
  152. package/src/api/supervisor-routing.js +95 -0
  153. package/src/api/workflow-resources.d.ts +2 -0
  154. package/src/api/workflow-resources.js +1 -0
  155. package/src/extension/active-runs-prompt.d.ts +7 -0
  156. package/src/extension/active-runs-prompt.js +29 -0
  157. package/src/extension/config.d.ts +7 -0
  158. package/src/extension/config.js +290 -0
  159. package/src/extension/context-injection.d.ts +52 -0
  160. package/src/extension/context-injection.js +102 -0
  161. package/src/extension/control-notices.d.ts +18 -0
  162. package/src/extension/control-notices.js +29 -0
  163. package/src/extension/declaration-pinning.d.ts +18 -0
  164. package/src/extension/declaration-pinning.js +167 -0
  165. package/src/extension/doctor.d.ts +34 -0
  166. package/src/extension/doctor.js +236 -0
  167. package/src/extension/fanout-child.d.ts +6 -0
  168. package/src/extension/fanout-child.js +278 -0
  169. package/src/extension/herdr-pi-bridge.d.ts +16 -0
  170. package/src/extension/herdr-pi-bridge.js +261 -0
  171. package/src/extension/index.d.ts +18 -0
  172. package/src/extension/index.js +1288 -0
  173. package/src/extension/public-execution.d.ts +71 -0
  174. package/src/extension/public-execution.js +214 -0
  175. package/src/extension/reply-workflow-script.d.ts +11 -0
  176. package/src/extension/reply-workflow-script.js +71 -0
  177. package/src/extension/rpc.d.ts +84 -0
  178. package/src/extension/rpc.js +729 -0
  179. package/src/extension/schemas.d.ts +276 -0
  180. package/src/extension/schemas.js +311 -0
  181. package/src/extension/steering-notices.d.ts +14 -0
  182. package/src/extension/steering-notices.js +22 -0
  183. package/src/extension/subagent-guide.d.ts +4 -0
  184. package/src/extension/subagent-guide.js +114 -0
  185. package/src/extension/subagent-options.d.ts +7 -0
  186. package/src/extension/subagent-options.js +64 -0
  187. package/src/extension/tool-activation.d.ts +7 -0
  188. package/src/extension/tool-activation.js +185 -0
  189. package/src/extension/tool-description.d.ts +19 -0
  190. package/src/extension/tool-description.js +169 -0
  191. package/src/extension/tool-result.d.ts +9 -0
  192. package/src/extension/tool-result.js +16 -0
  193. package/src/extension/upgrade-notice.d.ts +6 -0
  194. package/src/extension/upgrade-notice.js +42 -0
  195. package/src/inspectors/actions.d.ts +24 -0
  196. package/src/inspectors/actions.js +182 -0
  197. package/src/inspectors/ghostty/actions.d.ts +11 -0
  198. package/src/inspectors/ghostty/actions.js +62 -0
  199. package/src/inspectors/ghostty/plugin.d.ts +7 -0
  200. package/src/inspectors/ghostty/plugin.js +23 -0
  201. package/src/inspectors/herdr/actions.d.ts +25 -0
  202. package/src/inspectors/herdr/actions.js +133 -0
  203. package/src/inspectors/herdr/client.d.ts +41 -0
  204. package/src/inspectors/herdr/client.js +129 -0
  205. package/src/inspectors/herdr/focus.d.ts +24 -0
  206. package/src/inspectors/herdr/focus.js +49 -0
  207. package/src/inspectors/herdr/plugin.d.ts +6 -0
  208. package/src/inspectors/herdr/plugin.js +14 -0
  209. package/src/inspectors/herdr/project-panes.d.ts +136 -0
  210. package/src/inspectors/herdr/project-panes.js +610 -0
  211. package/src/inspectors/inspector-runner.d.ts +23 -0
  212. package/src/inspectors/inspector-runner.js +161 -0
  213. package/src/inspectors/plugins.d.ts +8 -0
  214. package/src/inspectors/plugins.js +82 -0
  215. package/src/inspectors/session-roots-codec.d.ts +15 -0
  216. package/src/inspectors/session-roots-codec.js +32 -0
  217. package/src/inspectors/shell-command.d.ts +1 -0
  218. package/src/inspectors/shell-command.js +16 -0
  219. package/src/inspectors/tmux/actions.d.ts +25 -0
  220. package/src/inspectors/tmux/actions.js +181 -0
  221. package/src/inspectors/tmux/client.d.ts +27 -0
  222. package/src/inspectors/tmux/client.js +64 -0
  223. package/src/inspectors/tmux/plugin.d.ts +7 -0
  224. package/src/inspectors/tmux/plugin.js +14 -0
  225. package/src/inspectors/types.d.ts +48 -0
  226. package/src/inspectors/types.js +1 -0
  227. package/src/integrations/herdr-status.d.ts +47 -0
  228. package/src/integrations/herdr-status.js +350 -0
  229. package/src/integrations/pi-web-session-liveness.d.ts +19 -0
  230. package/src/integrations/pi-web-session-liveness.js +53 -0
  231. package/src/integrations/program-status.d.ts +30 -0
  232. package/src/integrations/program-status.js +188 -0
  233. package/src/intercom/fork-supervisor-routing.d.ts +90 -0
  234. package/src/intercom/fork-supervisor-routing.js +392 -0
  235. package/src/intercom/intercom-bridge.d.ts +58 -0
  236. package/src/intercom/intercom-bridge.js +193 -0
  237. package/src/intercom/native-supervisor-channel.d.ts +97 -0
  238. package/src/intercom/native-supervisor-channel.js +1184 -0
  239. package/src/intercom/result-intercom.d.ts +35 -0
  240. package/src/intercom/result-intercom.js +376 -0
  241. package/src/intercom/supervisor-ui.d.ts +29 -0
  242. package/src/intercom/supervisor-ui.js +49 -0
  243. package/src/missions/actions.d.ts +54 -0
  244. package/src/missions/actions.js +400 -0
  245. package/src/missions/goal-driver.d.ts +16 -0
  246. package/src/missions/goal-driver.js +171 -0
  247. package/src/missions/lifecycle.d.ts +50 -0
  248. package/src/missions/lifecycle.js +388 -0
  249. package/src/missions/store.d.ts +21 -0
  250. package/src/missions/store.js +605 -0
  251. package/src/missions/types.d.ts +169 -0
  252. package/src/missions/types.js +9 -0
  253. package/src/missions/workflow-state.d.ts +14 -0
  254. package/src/missions/workflow-state.js +273 -0
  255. package/src/policy/authority.d.ts +9 -0
  256. package/src/policy/authority.js +41 -0
  257. package/src/profiles/profiles.d.ts +134 -0
  258. package/src/profiles/profiles.js +526 -0
  259. package/src/runs/background/active-async-capacity.d.ts +115 -0
  260. package/src/runs/background/active-async-capacity.js +517 -0
  261. package/src/runs/background/active-run-index.d.ts +12 -0
  262. package/src/runs/background/active-run-index.js +157 -0
  263. package/src/runs/background/async-execution.d.ts +304 -0
  264. package/src/runs/background/async-execution.js +2206 -0
  265. package/src/runs/background/async-job-tracker.d.ts +37 -0
  266. package/src/runs/background/async-job-tracker.js +921 -0
  267. package/src/runs/background/async-resume.d.ts +60 -0
  268. package/src/runs/background/async-resume.js +707 -0
  269. package/src/runs/background/async-retention.d.ts +45 -0
  270. package/src/runs/background/async-retention.js +932 -0
  271. package/src/runs/background/async-status-snapshot.d.ts +9 -0
  272. package/src/runs/background/async-status-snapshot.js +26 -0
  273. package/src/runs/background/async-status.d.ts +177 -0
  274. package/src/runs/background/async-status.js +710 -0
  275. package/src/runs/background/auto-drain.d.ts +16 -0
  276. package/src/runs/background/auto-drain.js +71 -0
  277. package/src/runs/background/await-async-run.d.ts +26 -0
  278. package/src/runs/background/await-async-run.js +83 -0
  279. package/src/runs/background/binary-bootstrap.d.ts +8 -0
  280. package/src/runs/background/binary-bootstrap.js +69 -0
  281. package/src/runs/background/boot-id.d.ts +12 -0
  282. package/src/runs/background/boot-id.js +47 -0
  283. package/src/runs/background/calendar-schedule.d.ts +26 -0
  284. package/src/runs/background/calendar-schedule.js +93 -0
  285. package/src/runs/background/chain-append.d.ts +34 -0
  286. package/src/runs/background/chain-append.js +299 -0
  287. package/src/runs/background/chain-root-attachment.d.ts +51 -0
  288. package/src/runs/background/chain-root-attachment.js +186 -0
  289. package/src/runs/background/completion-batcher.d.ts +51 -0
  290. package/src/runs/background/completion-batcher.js +119 -0
  291. package/src/runs/background/completion-dedupe.d.ts +13 -0
  292. package/src/runs/background/completion-dedupe.js +48 -0
  293. package/src/runs/background/completion-replay.d.ts +47 -0
  294. package/src/runs/background/completion-replay.js +266 -0
  295. package/src/runs/background/control-channel.d.ts +170 -0
  296. package/src/runs/background/control-channel.js +610 -0
  297. package/src/runs/background/fleet-view.d.ts +63 -0
  298. package/src/runs/background/fleet-view.js +666 -0
  299. package/src/runs/background/index-segment.d.ts +16 -0
  300. package/src/runs/background/index-segment.js +58 -0
  301. package/src/runs/background/inspect-rpc.d.ts +64 -0
  302. package/src/runs/background/inspect-rpc.js +422 -0
  303. package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
  304. package/src/runs/background/interrupted-elsewhere.js +68 -0
  305. package/src/runs/background/notify.d.ts +214 -0
  306. package/src/runs/background/notify.js +1001 -0
  307. package/src/runs/background/owned-process-tree.d.ts +10 -0
  308. package/src/runs/background/owned-process-tree.js +116 -0
  309. package/src/runs/background/parallel-groups.d.ts +3 -0
  310. package/src/runs/background/parallel-groups.js +46 -0
  311. package/src/runs/background/pid-namespace.d.ts +2 -0
  312. package/src/runs/background/pid-namespace.js +19 -0
  313. package/src/runs/background/process-terminal-candidate.d.ts +17 -0
  314. package/src/runs/background/process-terminal-candidate.js +96 -0
  315. package/src/runs/background/process-terminal.d.ts +21 -0
  316. package/src/runs/background/process-terminal.js +227 -0
  317. package/src/runs/background/result-delivery-ownership.d.ts +14 -0
  318. package/src/runs/background/result-delivery-ownership.js +38 -0
  319. package/src/runs/background/result-files.d.ts +63 -0
  320. package/src/runs/background/result-files.js +629 -0
  321. package/src/runs/background/result-watcher.d.ts +92 -0
  322. package/src/runs/background/result-watcher.js +819 -0
  323. package/src/runs/background/resume-guidance.d.ts +4 -0
  324. package/src/runs/background/resume-guidance.js +57 -0
  325. package/src/runs/background/retained-children.d.ts +24 -0
  326. package/src/runs/background/retained-children.js +128 -0
  327. package/src/runs/background/retained-nested-route-tracker.d.ts +12 -0
  328. package/src/runs/background/retained-nested-route-tracker.js +90 -0
  329. package/src/runs/background/run-child-session.d.ts +123 -0
  330. package/src/runs/background/run-child-session.js +670 -0
  331. package/src/runs/background/run-id-query.d.ts +3 -0
  332. package/src/runs/background/run-id-query.js +6 -0
  333. package/src/runs/background/run-id-resolver.d.ts +22 -0
  334. package/src/runs/background/run-id-resolver.js +172 -0
  335. package/src/runs/background/run-status.d.ts +25 -0
  336. package/src/runs/background/run-status.js +850 -0
  337. package/src/runs/background/runner-aliases.d.ts +17 -0
  338. package/src/runs/background/runner-aliases.js +191 -0
  339. package/src/runs/background/runner-child-launch.d.ts +24 -0
  340. package/src/runs/background/runner-child-launch.js +72 -0
  341. package/src/runs/background/runner-child-sessions.d.ts +6 -0
  342. package/src/runs/background/runner-child-sessions.js +34 -0
  343. package/src/runs/background/runner-http-dispatcher.d.ts +45 -0
  344. package/src/runs/background/runner-http-dispatcher.js +115 -0
  345. package/src/runs/background/runner-startup-failure.d.ts +13 -0
  346. package/src/runs/background/runner-startup-failure.js +46 -0
  347. package/src/runs/background/scheduled-runs.d.ts +127 -0
  348. package/src/runs/background/scheduled-runs.js +1265 -0
  349. package/src/runs/background/stale-run-reconciler.d.ts +62 -0
  350. package/src/runs/background/stale-run-reconciler.js +509 -0
  351. package/src/runs/background/steering.d.ts +51 -0
  352. package/src/runs/background/steering.js +246 -0
  353. package/src/runs/background/subagent-runner-bootstrap.d.ts +13 -0
  354. package/src/runs/background/subagent-runner-bootstrap.js +283 -0
  355. package/src/runs/background/subagent-runner.d.ts +210 -0
  356. package/src/runs/background/subagent-runner.js +4963 -0
  357. package/src/runs/background/subagent-wait.d.ts +124 -0
  358. package/src/runs/background/subagent-wait.js +756 -0
  359. package/src/runs/background/terminal-run-index.d.ts +10 -0
  360. package/src/runs/background/terminal-run-index.js +209 -0
  361. package/src/runs/background/top-level-async.d.ts +7 -0
  362. package/src/runs/background/top-level-async.js +5 -0
  363. package/src/runs/background/wait-completions.d.ts +28 -0
  364. package/src/runs/background/wait-completions.js +264 -0
  365. package/src/runs/background/wait-config.d.ts +8 -0
  366. package/src/runs/background/wait-config.js +46 -0
  367. package/src/runs/background/wait-subscriptions.d.ts +26 -0
  368. package/src/runs/background/wait-subscriptions.js +339 -0
  369. package/src/runs/background/wait-tool.d.ts +6 -0
  370. package/src/runs/background/wait-tool.js +48 -0
  371. package/src/runs/background/workflow-terminal-proof.d.ts +47 -0
  372. package/src/runs/background/workflow-terminal-proof.js +116 -0
  373. package/src/runs/foreground/async-dismiss-action.d.ts +6 -0
  374. package/src/runs/foreground/async-dismiss-action.js +82 -0
  375. package/src/runs/foreground/async-steering-action.d.ts +31 -0
  376. package/src/runs/foreground/async-steering-action.js +294 -0
  377. package/src/runs/foreground/async-stop-action.d.ts +13 -0
  378. package/src/runs/foreground/async-stop-action.js +213 -0
  379. package/src/runs/foreground/command-action.d.ts +12 -0
  380. package/src/runs/foreground/command-action.js +38 -0
  381. package/src/runs/foreground/execution.d.ts +10 -0
  382. package/src/runs/foreground/execution.js +2322 -0
  383. package/src/runs/foreground/foreground-control.d.ts +24 -0
  384. package/src/runs/foreground/foreground-control.js +138 -0
  385. package/src/runs/foreground/foreground-history.d.ts +25 -0
  386. package/src/runs/foreground/foreground-history.js +267 -0
  387. package/src/runs/foreground/prompt-audit.d.ts +32 -0
  388. package/src/runs/foreground/prompt-audit.js +138 -0
  389. package/src/runs/foreground/subagent-executor.d.ts +316 -0
  390. package/src/runs/foreground/subagent-executor.js +7986 -0
  391. package/src/runs/foreground/workflow-detach-reconcile.d.ts +15 -0
  392. package/src/runs/foreground/workflow-detach-reconcile.js +283 -0
  393. package/src/runs/foreground/workflow-foreground-steering.d.ts +43 -0
  394. package/src/runs/foreground/workflow-foreground-steering.js +148 -0
  395. package/src/runs/shared/abort-recovery.d.ts +26 -0
  396. package/src/runs/shared/abort-recovery.js +108 -0
  397. package/src/runs/shared/acceptance.d.ts +144 -0
  398. package/src/runs/shared/acceptance.js +1616 -0
  399. package/src/runs/shared/agent-contract.d.ts +5 -0
  400. package/src/runs/shared/agent-contract.js +35 -0
  401. package/src/runs/shared/async-status-projection.d.ts +100 -0
  402. package/src/runs/shared/async-status-projection.js +566 -0
  403. package/src/runs/shared/background-process-options.d.ts +4 -0
  404. package/src/runs/shared/background-process-options.js +6 -0
  405. package/src/runs/shared/capability-ceiling.d.ts +58 -0
  406. package/src/runs/shared/capability-ceiling.js +179 -0
  407. package/src/runs/shared/chain-outputs.d.ts +18 -0
  408. package/src/runs/shared/chain-outputs.js +104 -0
  409. package/src/runs/shared/child-commands.d.ts +29 -0
  410. package/src/runs/shared/child-commands.js +254 -0
  411. package/src/runs/shared/child-hooks.d.ts +31 -0
  412. package/src/runs/shared/child-hooks.js +173 -0
  413. package/src/runs/shared/child-identity.d.ts +23 -0
  414. package/src/runs/shared/child-identity.js +40 -0
  415. package/src/runs/shared/child-launch-plan.d.ts +70 -0
  416. package/src/runs/shared/child-launch-plan.js +88 -0
  417. package/src/runs/shared/child-launch.d.ts +128 -0
  418. package/src/runs/shared/child-launch.js +262 -0
  419. package/src/runs/shared/child-lifecycle.d.ts +13 -0
  420. package/src/runs/shared/child-lifecycle.js +22 -0
  421. package/src/runs/shared/child-runtime-config.d.ts +111 -0
  422. package/src/runs/shared/child-runtime-config.js +44 -0
  423. package/src/runs/shared/child-session.d.ts +178 -0
  424. package/src/runs/shared/child-session.js +726 -0
  425. package/src/runs/shared/child-tool-plan.d.ts +101 -0
  426. package/src/runs/shared/child-tool-plan.js +430 -0
  427. package/src/runs/shared/claude-code-adapter.d.ts +80 -0
  428. package/src/runs/shared/claude-code-adapter.js +255 -0
  429. package/src/runs/shared/codex-exec-adapter.d.ts +25 -0
  430. package/src/runs/shared/codex-exec-adapter.js +127 -0
  431. package/src/runs/shared/context-mode.d.ts +12 -0
  432. package/src/runs/shared/context-mode.js +38 -0
  433. package/src/runs/shared/cursor-agent-adapter.d.ts +26 -0
  434. package/src/runs/shared/cursor-agent-adapter.js +99 -0
  435. package/src/runs/shared/dynamic-fanout.d.ts +49 -0
  436. package/src/runs/shared/dynamic-fanout.js +273 -0
  437. package/src/runs/shared/effective-system-prompt.d.ts +17 -0
  438. package/src/runs/shared/effective-system-prompt.js +23 -0
  439. package/src/runs/shared/extension-bindings.d.ts +25 -0
  440. package/src/runs/shared/extension-bindings.js +96 -0
  441. package/src/runs/shared/external-cli-contract.d.ts +29 -0
  442. package/src/runs/shared/external-cli-contract.js +145 -0
  443. package/src/runs/shared/external-cli-preflight.d.ts +41 -0
  444. package/src/runs/shared/external-cli-preflight.js +159 -0
  445. package/src/runs/shared/external-cli-runner.d.ts +65 -0
  446. package/src/runs/shared/external-cli-runner.js +425 -0
  447. package/src/runs/shared/external-job-bridge.d.ts +24 -0
  448. package/src/runs/shared/external-job-bridge.js +486 -0
  449. package/src/runs/shared/external-job-runner.d.ts +44 -0
  450. package/src/runs/shared/external-job-runner.js +352 -0
  451. package/src/runs/shared/fast-mode-extension.d.ts +3 -0
  452. package/src/runs/shared/fast-mode-extension.js +8 -0
  453. package/src/runs/shared/fork-placed-env.d.ts +4 -0
  454. package/src/runs/shared/fork-placed-env.js +13 -0
  455. package/src/runs/shared/git-environment.d.ts +2 -0
  456. package/src/runs/shared/git-environment.js +27 -0
  457. package/src/runs/shared/herdr-connection.d.ts +79 -0
  458. package/src/runs/shared/herdr-connection.js +269 -0
  459. package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
  460. package/src/runs/shared/herdr-external-adapters.js +404 -0
  461. package/src/runs/shared/herdr-machine.d.ts +59 -0
  462. package/src/runs/shared/herdr-machine.js +294 -0
  463. package/src/runs/shared/herdr-pane-host.d.ts +88 -0
  464. package/src/runs/shared/herdr-pane-host.js +155 -0
  465. package/src/runs/shared/herdr-pi-protocol.d.ts +21 -0
  466. package/src/runs/shared/herdr-pi-protocol.js +57 -0
  467. package/src/runs/shared/herdr-placed-run.d.ts +144 -0
  468. package/src/runs/shared/herdr-placed-run.js +380 -0
  469. package/src/runs/shared/host-step-status.d.ts +33 -0
  470. package/src/runs/shared/host-step-status.js +244 -0
  471. package/src/runs/shared/lane-metadata.d.ts +23 -0
  472. package/src/runs/shared/lane-metadata.js +126 -0
  473. package/src/runs/shared/launch-cwd.d.ts +1 -0
  474. package/src/runs/shared/launch-cwd.js +16 -0
  475. package/src/runs/shared/local-machine-access.d.ts +5 -0
  476. package/src/runs/shared/local-machine-access.js +28 -0
  477. package/src/runs/shared/long-running-guard.d.ts +34 -0
  478. package/src/runs/shared/long-running-guard.js +256 -0
  479. package/src/runs/shared/mcp-config-sources.d.ts +33 -0
  480. package/src/runs/shared/mcp-config-sources.js +418 -0
  481. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +86 -0
  482. package/src/runs/shared/mcp-direct-tool-allowlist.js +477 -0
  483. package/src/runs/shared/mcp-direct-tool-grant.d.ts +42 -0
  484. package/src/runs/shared/mcp-direct-tool-grant.js +159 -0
  485. package/src/runs/shared/model-resolution-diagnostic.d.ts +44 -0
  486. package/src/runs/shared/model-resolution-diagnostic.js +116 -0
  487. package/src/runs/shared/model-resolution.d.ts +109 -0
  488. package/src/runs/shared/model-resolution.js +411 -0
  489. package/src/runs/shared/model-scope.d.ts +68 -0
  490. package/src/runs/shared/model-scope.js +171 -0
  491. package/src/runs/shared/mutation-evidence.d.ts +18 -0
  492. package/src/runs/shared/mutation-evidence.js +198 -0
  493. package/src/runs/shared/nested-events.d.ts +135 -0
  494. package/src/runs/shared/nested-events.js +1090 -0
  495. package/src/runs/shared/nested-path.d.ts +8 -0
  496. package/src/runs/shared/nested-path.js +34 -0
  497. package/src/runs/shared/nested-render.d.ts +20 -0
  498. package/src/runs/shared/nested-render.js +115 -0
  499. package/src/runs/shared/orca-progress-tabs.d.ts +31 -0
  500. package/src/runs/shared/orca-progress-tabs.js +503 -0
  501. package/src/runs/shared/parallel-handoff.d.ts +78 -0
  502. package/src/runs/shared/parallel-handoff.js +783 -0
  503. package/src/runs/shared/parallel-utils.d.ts +177 -0
  504. package/src/runs/shared/parallel-utils.js +125 -0
  505. package/src/runs/shared/partial-output.d.ts +24 -0
  506. package/src/runs/shared/partial-output.js +35 -0
  507. package/src/runs/shared/permissions.d.ts +12 -0
  508. package/src/runs/shared/permissions.js +92 -0
  509. package/src/runs/shared/pi-spawn.d.ts +31 -0
  510. package/src/runs/shared/pi-spawn.js +211 -0
  511. package/src/runs/shared/placed-run-owner.d.ts +49 -0
  512. package/src/runs/shared/placed-run-owner.js +93 -0
  513. package/src/runs/shared/placement-host.d.ts +99 -0
  514. package/src/runs/shared/placement-host.js +157 -0
  515. package/src/runs/shared/process-signal.d.ts +15 -0
  516. package/src/runs/shared/process-signal.js +21 -0
  517. package/src/runs/shared/profile-extensions.d.ts +21 -0
  518. package/src/runs/shared/profile-extensions.js +122 -0
  519. package/src/runs/shared/profile-launch-env.d.ts +26 -0
  520. package/src/runs/shared/profile-launch-env.js +90 -0
  521. package/src/runs/shared/readonly-drain-observation.d.ts +25 -0
  522. package/src/runs/shared/readonly-drain-observation.js +50 -0
  523. package/src/runs/shared/rex-machine.d.ts +25 -0
  524. package/src/runs/shared/rex-machine.js +83 -0
  525. package/src/runs/shared/rex-pane-host.d.ts +62 -0
  526. package/src/runs/shared/rex-pane-host.js +327 -0
  527. package/src/runs/shared/run-fanout-budget.d.ts +14 -0
  528. package/src/runs/shared/run-fanout-budget.js +258 -0
  529. package/src/runs/shared/run-ownership.d.ts +3 -0
  530. package/src/runs/shared/run-ownership.js +8 -0
  531. package/src/runs/shared/runner-launcher.d.ts +11 -0
  532. package/src/runs/shared/runner-launcher.js +24 -0
  533. package/src/runs/shared/runtime-acknowledged-extensions.d.ts +7 -0
  534. package/src/runs/shared/runtime-acknowledged-extensions.js +44 -0
  535. package/src/runs/shared/sandbox-profile-guard.d.ts +23 -0
  536. package/src/runs/shared/sandbox-profile-guard.js +106 -0
  537. package/src/runs/shared/sandbox-startup-diagnostics.d.ts +21 -0
  538. package/src/runs/shared/sandbox-startup-diagnostics.js +51 -0
  539. package/src/runs/shared/session-lease.d.ts +69 -0
  540. package/src/runs/shared/session-lease.js +250 -0
  541. package/src/runs/shared/single-output.d.ts +90 -0
  542. package/src/runs/shared/single-output.js +349 -0
  543. package/src/runs/shared/spawn-budget.d.ts +20 -0
  544. package/src/runs/shared/spawn-budget.js +93 -0
  545. package/src/runs/shared/structured-output.d.ts +66 -0
  546. package/src/runs/shared/structured-output.js +483 -0
  547. package/src/runs/shared/subagent-control.d.ts +50 -0
  548. package/src/runs/shared/subagent-control.js +247 -0
  549. package/src/runs/shared/subagent-prompt-runtime.d.ts +90 -0
  550. package/src/runs/shared/subagent-prompt-runtime.js +776 -0
  551. package/src/runs/shared/tool-availability.d.ts +16 -0
  552. package/src/runs/shared/tool-availability.js +29 -0
  553. package/src/runs/shared/tool-budget.d.ts +21 -0
  554. package/src/runs/shared/tool-budget.js +78 -0
  555. package/src/runs/shared/tool-timeout.d.ts +31 -0
  556. package/src/runs/shared/tool-timeout.js +73 -0
  557. package/src/runs/shared/usage-budget.d.ts +7 -0
  558. package/src/runs/shared/usage-budget.js +74 -0
  559. package/src/runs/shared/usage-reconciliation.d.ts +8 -0
  560. package/src/runs/shared/usage-reconciliation.js +71 -0
  561. package/src/runs/shared/workflow-async-child-guidance.d.ts +3 -0
  562. package/src/runs/shared/workflow-async-child-guidance.js +17 -0
  563. package/src/runs/shared/workflow-graph.d.ts +31 -0
  564. package/src/runs/shared/workflow-graph.js +221 -0
  565. package/src/runs/shared/worktree-cleanup-apply.d.ts +36 -0
  566. package/src/runs/shared/worktree-cleanup-apply.js +178 -0
  567. package/src/runs/shared/worktree-cleanup-plan.d.ts +84 -0
  568. package/src/runs/shared/worktree-cleanup-plan.js +803 -0
  569. package/src/runs/shared/worktree-lock.d.ts +5 -0
  570. package/src/runs/shared/worktree-lock.js +40 -0
  571. package/src/runs/shared/worktree-setup-command.d.ts +38 -0
  572. package/src/runs/shared/worktree-setup-command.js +200 -0
  573. package/src/runs/shared/worktree.d.ts +181 -0
  574. package/src/runs/shared/worktree.js +1346 -0
  575. package/src/shared/accessible-dir.d.ts +11 -0
  576. package/src/shared/accessible-dir.js +39 -0
  577. package/src/shared/agent-stream-options.d.ts +5 -0
  578. package/src/shared/agent-stream-options.js +3 -0
  579. package/src/shared/artifacts.d.ts +22 -0
  580. package/src/shared/artifacts.js +272 -0
  581. package/src/shared/atomic-json.d.ts +19 -0
  582. package/src/shared/atomic-json.js +61 -0
  583. package/src/shared/capacity-resilient-json.d.ts +26 -0
  584. package/src/shared/capacity-resilient-json.js +86 -0
  585. package/src/shared/child-cache-retention.d.ts +29 -0
  586. package/src/shared/child-cache-retention.js +40 -0
  587. package/src/shared/child-session-name.d.ts +8 -0
  588. package/src/shared/child-session-name.js +40 -0
  589. package/src/shared/child-transcript.d.ts +37 -0
  590. package/src/shared/child-transcript.js +225 -0
  591. package/src/shared/completion-owner.d.ts +7 -0
  592. package/src/shared/completion-owner.js +13 -0
  593. package/src/shared/disabled-features.d.ts +93 -0
  594. package/src/shared/disabled-features.js +120 -0
  595. package/src/shared/display-text.d.ts +5 -0
  596. package/src/shared/display-text.js +154 -0
  597. package/src/shared/edit-distance.d.ts +4 -0
  598. package/src/shared/edit-distance.js +32 -0
  599. package/src/shared/extension-context.d.ts +21 -0
  600. package/src/shared/extension-context.js +39 -0
  601. package/src/shared/file-coalescer.d.ts +11 -0
  602. package/src/shared/file-coalescer.js +34 -0
  603. package/src/shared/file-lease.d.ts +10 -0
  604. package/src/shared/file-lease.js +106 -0
  605. package/src/shared/file-system-retry.d.ts +31 -0
  606. package/src/shared/file-system-retry.js +84 -0
  607. package/src/shared/fork-context.d.ts +64 -0
  608. package/src/shared/fork-context.js +185 -0
  609. package/src/shared/fork-session-cwd.d.ts +2 -0
  610. package/src/shared/fork-session-cwd.js +23 -0
  611. package/src/shared/formatters.d.ts +35 -0
  612. package/src/shared/formatters.js +137 -0
  613. package/src/shared/jsonl-writer.d.ts +20 -0
  614. package/src/shared/jsonl-writer.js +67 -0
  615. package/src/shared/launch-contract.d.ts +65 -0
  616. package/src/shared/launch-contract.js +145 -0
  617. package/src/shared/model-info.d.ts +55 -0
  618. package/src/shared/model-info.js +103 -0
  619. package/src/shared/model-response-aliases.d.ts +1 -0
  620. package/src/shared/model-response-aliases.js +15 -0
  621. package/src/shared/node-executable.d.ts +1 -0
  622. package/src/shared/node-executable.js +20 -0
  623. package/src/shared/opencode-session-headers.d.ts +12 -0
  624. package/src/shared/opencode-session-headers.js +26 -0
  625. package/src/shared/package-version.d.ts +2 -0
  626. package/src/shared/package-version.js +14 -0
  627. package/src/shared/parent-wake.d.ts +26 -0
  628. package/src/shared/parent-wake.js +68 -0
  629. package/src/shared/permission-profile.d.ts +26 -0
  630. package/src/shared/permission-profile.js +49 -0
  631. package/src/shared/prompt-resources.d.ts +5 -0
  632. package/src/shared/prompt-resources.js +10 -0
  633. package/src/shared/provider-diagnostics.d.ts +9 -0
  634. package/src/shared/provider-diagnostics.js +75 -0
  635. package/src/shared/pruned-fork.d.ts +34 -0
  636. package/src/shared/pruned-fork.js +434 -0
  637. package/src/shared/required-child-extensions.d.ts +34 -0
  638. package/src/shared/required-child-extensions.js +105 -0
  639. package/src/shared/runtime-module-path.d.ts +10 -0
  640. package/src/shared/runtime-module-path.js +16 -0
  641. package/src/shared/sandbox-profile.d.ts +12 -0
  642. package/src/shared/sandbox-profile.js +35 -0
  643. package/src/shared/session-file-trust.d.ts +1 -0
  644. package/src/shared/session-file-trust.js +20 -0
  645. package/src/shared/session-identity.d.ts +8 -0
  646. package/src/shared/session-identity.js +32 -0
  647. package/src/shared/session-succession.d.ts +4 -0
  648. package/src/shared/session-succession.js +24 -0
  649. package/src/shared/session-tokens.d.ts +2 -0
  650. package/src/shared/session-tokens.js +58 -0
  651. package/src/shared/settings-file-lease.d.ts +4 -0
  652. package/src/shared/settings-file-lease.js +38 -0
  653. package/src/shared/settings.d.ts +146 -0
  654. package/src/shared/settings.js +247 -0
  655. package/src/shared/shortcuts.d.ts +1 -0
  656. package/src/shared/shortcuts.js +17 -0
  657. package/src/shared/status-format.d.ts +9 -0
  658. package/src/shared/status-format.js +60 -0
  659. package/src/shared/thinking-ceiling.d.ts +13 -0
  660. package/src/shared/thinking-ceiling.js +37 -0
  661. package/src/shared/types.d.ts +2840 -0
  662. package/src/shared/types.js +276 -0
  663. package/src/shared/utf8.d.ts +5 -0
  664. package/src/shared/utf8.js +12 -0
  665. package/src/shared/utils.d.ts +83 -0
  666. package/src/shared/utils.js +612 -0
  667. package/src/shared/watch-strategy.d.ts +2 -0
  668. package/src/shared/watch-strategy.js +5 -0
  669. package/src/shared/workflow-child-permit.d.ts +58 -0
  670. package/src/shared/workflow-child-permit.js +159 -0
  671. package/src/slash/delegation-adapters.d.ts +154 -0
  672. package/src/slash/delegation-adapters.js +316 -0
  673. package/src/slash/delegation-json.d.ts +10 -0
  674. package/src/slash/delegation-json.js +117 -0
  675. package/src/slash/delegation-request.d.ts +12 -0
  676. package/src/slash/delegation-request.js +174 -0
  677. package/src/slash/prompt-template-bridge.d.ts +29 -0
  678. package/src/slash/prompt-template-bridge.js +399 -0
  679. package/src/slash/prompt-workflows.d.ts +21 -0
  680. package/src/slash/prompt-workflows.js +274 -0
  681. package/src/slash/selector.d.ts +47 -0
  682. package/src/slash/selector.js +117 -0
  683. package/src/slash/slash-bridge.d.ts +30 -0
  684. package/src/slash/slash-bridge.js +132 -0
  685. package/src/slash/slash-commands.d.ts +10 -0
  686. package/src/slash/slash-commands.js +1059 -0
  687. package/src/slash/slash-live-state.d.ts +21 -0
  688. package/src/slash/slash-live-state.js +263 -0
  689. package/src/slash/subagent-cost.d.ts +29 -0
  690. package/src/slash/subagent-cost.js +310 -0
  691. package/src/slash/subagents-admin.d.ts +3 -0
  692. package/src/slash/subagents-admin.js +481 -0
  693. package/src/tui/fleet-layout.d.ts +20 -0
  694. package/src/tui/fleet-layout.js +17 -0
  695. package/src/tui/fleet-native-transcript.d.ts +53 -0
  696. package/src/tui/fleet-native-transcript.js +339 -0
  697. package/src/tui/fleet-status.d.ts +92 -0
  698. package/src/tui/fleet-status.js +1132 -0
  699. package/src/tui/fleet-transcript.d.ts +64 -0
  700. package/src/tui/fleet-transcript.js +544 -0
  701. package/src/tui/fleet-viewport.d.ts +12 -0
  702. package/src/tui/fleet-viewport.js +35 -0
  703. package/src/tui/fleet.d.ts +196 -0
  704. package/src/tui/fleet.js +1588 -0
  705. package/src/tui/mouse-events.d.ts +21 -0
  706. package/src/tui/mouse-events.js +26 -0
  707. package/src/tui/render-helpers.d.ts +23 -0
  708. package/src/tui/render-helpers.js +100 -0
  709. package/src/tui/render.d.ts +66 -0
  710. package/src/tui/render.js +3707 -0
  711. package/src/tui/running-tone.d.ts +10 -0
  712. package/src/tui/running-tone.js +22 -0
  713. package/src/tui/subagent-messages.d.ts +22 -0
  714. package/src/tui/subagent-messages.js +270 -0
  715. package/src/ui-silent-marker.d.ts +20 -0
  716. package/src/ui-silent-marker.js +25 -0
  717. package/src/watchdog/change-signature.d.ts +7 -0
  718. package/src/watchdog/change-signature.js +243 -0
  719. package/src/watchdog/child-status.d.ts +53 -0
  720. package/src/watchdog/child-status.js +187 -0
  721. package/src/watchdog/diff-tool.d.ts +25 -0
  722. package/src/watchdog/diff-tool.js +104 -0
  723. package/src/watchdog/emission-guard.d.ts +36 -0
  724. package/src/watchdog/emission-guard.js +97 -0
  725. package/src/watchdog/guidance.d.ts +3 -0
  726. package/src/watchdog/guidance.js +19 -0
  727. package/src/watchdog/lsp-diagnostics.d.ts +17 -0
  728. package/src/watchdog/lsp-diagnostics.js +489 -0
  729. package/src/watchdog/model-selection.d.ts +24 -0
  730. package/src/watchdog/model-selection.js +167 -0
  731. package/src/watchdog/permission-arbiter.d.ts +20 -0
  732. package/src/watchdog/permission-arbiter.js +135 -0
  733. package/src/watchdog/register-child.d.ts +13 -0
  734. package/src/watchdog/register-child.js +128 -0
  735. package/src/watchdog/register-main.d.ts +11 -0
  736. package/src/watchdog/register-main.js +400 -0
  737. package/src/watchdog/render.d.ts +3 -0
  738. package/src/watchdog/render.js +33 -0
  739. package/src/watchdog/review.d.ts +36 -0
  740. package/src/watchdog/review.js +319 -0
  741. package/src/watchdog/rules.d.ts +21 -0
  742. package/src/watchdog/rules.js +58 -0
  743. package/src/watchdog/runtime.d.ts +195 -0
  744. package/src/watchdog/runtime.js +864 -0
  745. package/src/watchdog/scope.d.ts +14 -0
  746. package/src/watchdog/scope.js +44 -0
  747. package/src/watchdog/settings.d.ts +29 -0
  748. package/src/watchdog/settings.js +480 -0
  749. package/src/watchdog/tool-actions.d.ts +17 -0
  750. package/src/watchdog/tool-actions.js +150 -0
  751. package/src/watchdog/turn-delta.d.ts +15 -0
  752. package/src/watchdog/turn-delta.js +188 -0
  753. package/src/watchdog/types.d.ts +141 -0
  754. package/src/watchdog/types.js +27 -0
  755. package/src/watchdog/warning-format.d.ts +7 -0
  756. package/src/watchdog/warning-format.js +59 -0
  757. package/src/workflows/chat-progress.d.ts +37 -0
  758. package/src/workflows/chat-progress.js +129 -0
  759. package/src/workflows/host-command.d.ts +30 -0
  760. package/src/workflows/host-command.js +227 -0
  761. package/src/workflows/scripted-workflow.d.ts +204 -0
  762. package/src/workflows/scripted-workflow.js +1673 -0
  763. package/src/workflows/structured-workflow-scripts.d.ts +10 -0
  764. package/src/workflows/structured-workflow-scripts.js +179 -0
  765. package/src/workflows/workflow-auto-resume.d.ts +32 -0
  766. package/src/workflows/workflow-auto-resume.js +102 -0
  767. package/src/workflows/workflow-checklist.d.ts +127 -0
  768. package/src/workflows/workflow-checklist.js +314 -0
  769. package/src/workflows/workflow-child-summary.d.ts +24 -0
  770. package/src/workflows/workflow-child-summary.js +195 -0
  771. package/src/workflows/workflow-launch-record.d.ts +27 -0
  772. package/src/workflows/workflow-launch-record.js +48 -0
  773. package/src/workflows/workflow-preflight.d.ts +58 -0
  774. package/src/workflows/workflow-preflight.js +288 -0
  775. package/src/workflows/workflow-receipt.d.ts +34 -0
  776. package/src/workflows/workflow-receipt.js +454 -0
  777. package/src/workflows/workflow-resources.d.ts +55 -0
  778. package/src/workflows/workflow-resources.js +271 -0
  779. package/src/workflows/workflow-resume-claim.d.ts +82 -0
  780. package/src/workflows/workflow-resume-claim.js +210 -0
  781. package/src/workflows/workflow-resume.d.ts +56 -0
  782. package/src/workflows/workflow-resume.js +106 -0
  783. package/src/workflows/workflow-reuse.d.ts +61 -0
  784. package/src/workflows/workflow-reuse.js +186 -0
  785. package/src/workflows/workflow-revival.d.ts +33 -0
  786. package/src/workflows/workflow-revival.js +111 -0
  787. package/src/workflows/workflow-settlement.d.ts +84 -0
  788. package/src/workflows/workflow-settlement.js +203 -0
  789. package/src/workflows/workflow-stop-cause.d.ts +6 -0
  790. package/src/workflows/workflow-stop-cause.js +8 -0
  791. package/workflow-script-worker.cjs +1342 -0
  792. package/index.ts +0 -18
  793. package/node_modules/@xzzpig/pi-components/src/transcript.ts +0 -1878
  794. package/skills/pi-subagents/references/constraints-and-recipes.md +0 -74
  795. package/skills/pi-subagents/references/execution-controls.md +0 -561
  796. package/skills/pi-subagents/references/management-authoring-rpc.md +0 -165
  797. package/skills/pi-subagents/references/multi-lane-orchestration.md +0 -61
  798. package/skills/pi-subagents/references/review-and-validation.md +0 -73
  799. package/src/agents/advertised-agent-prompt.ts +0 -82
  800. package/src/agents/agent-eject.ts +0 -339
  801. package/src/agents/agent-management.ts +0 -1442
  802. package/src/agents/agent-memory.ts +0 -341
  803. package/src/agents/agent-refinements.ts +0 -624
  804. package/src/agents/agent-scope.ts +0 -10
  805. package/src/agents/agent-selection.ts +0 -25
  806. package/src/agents/agent-serializer.ts +0 -195
  807. package/src/agents/agents.ts +0 -3169
  808. package/src/agents/builtin-names.ts +0 -16
  809. package/src/agents/chain-serializer.ts +0 -285
  810. package/src/agents/frontmatter.ts +0 -153
  811. package/src/agents/global-npm-root.ts +0 -58
  812. package/src/agents/identity.ts +0 -30
  813. package/src/agents/proactive-skills.ts +0 -197
  814. package/src/agents/runtime-agent-events.ts +0 -70
  815. package/src/agents/runtime-agent-registry.ts +0 -457
  816. package/src/agents/runtime-discovery.ts +0 -39
  817. package/src/agents/skills.ts +0 -787
  818. package/src/api/agent-management.ts +0 -9
  819. package/src/api/agents.ts +0 -19
  820. package/src/api/background-work.ts +0 -206
  821. package/src/api/capability-ceiling.ts +0 -16
  822. package/src/api/child-tool-plan.ts +0 -5
  823. package/src/api/control-channel.ts +0 -4
  824. package/src/api/delegation.ts +0 -131
  825. package/src/api/external-job-provider.ts +0 -195
  826. package/src/api/external-runs.ts +0 -282
  827. package/src/api/inspectors.ts +0 -27
  828. package/src/api/intercom-bridge.ts +0 -3
  829. package/src/api/preflight.ts +0 -641
  830. package/src/api/project-panes.ts +0 -32
  831. package/src/api/required-child-extensions.ts +0 -6
  832. package/src/api/shared-types.ts +0 -29
  833. package/src/api/workflow-resources.ts +0 -6
  834. package/src/extension/config.ts +0 -262
  835. package/src/extension/context-injection.ts +0 -123
  836. package/src/extension/control-notices.ts +0 -53
  837. package/src/extension/declaration-pinning.ts +0 -164
  838. package/src/extension/doctor.ts +0 -284
  839. package/src/extension/fanout-child.ts +0 -282
  840. package/src/extension/herdr-pi-bridge.ts +0 -166
  841. package/src/extension/index.ts +0 -1185
  842. package/src/extension/public-execution.ts +0 -262
  843. package/src/extension/reply-workflow-script.ts +0 -67
  844. package/src/extension/rpc.ts +0 -881
  845. package/src/extension/schemas.ts +0 -337
  846. package/src/extension/steering-notices.ts +0 -35
  847. package/src/extension/subagent-guide.ts +0 -127
  848. package/src/extension/subagent-options.ts +0 -47
  849. package/src/extension/tool-activation.ts +0 -147
  850. package/src/extension/tool-description.ts +0 -193
  851. package/src/extension/tool-result.ts +0 -19
  852. package/src/extension/upgrade-notice.ts +0 -40
  853. package/src/inspectors/actions.ts +0 -174
  854. package/src/inspectors/ghostty/actions.ts +0 -74
  855. package/src/inspectors/ghostty/plugin.ts +0 -29
  856. package/src/inspectors/herdr/actions.ts +0 -155
  857. package/src/inspectors/herdr/client.ts +0 -130
  858. package/src/inspectors/herdr/focus.ts +0 -55
  859. package/src/inspectors/herdr/plugin.ts +0 -20
  860. package/src/inspectors/herdr/project-panes.ts +0 -733
  861. package/src/inspectors/inspector-runner.ts +0 -153
  862. package/src/inspectors/plugins.ts +0 -76
  863. package/src/inspectors/session-roots-codec.ts +0 -31
  864. package/src/inspectors/shell-command.ts +0 -16
  865. package/src/inspectors/tmux/actions.ts +0 -204
  866. package/src/inspectors/tmux/client.ts +0 -85
  867. package/src/inspectors/tmux/plugin.ts +0 -21
  868. package/src/inspectors/types.ts +0 -51
  869. package/src/integrations/herdr-status.ts +0 -385
  870. package/src/integrations/pi-web-session-liveness.ts +0 -73
  871. package/src/integrations/program-status.ts +0 -215
  872. package/src/intercom/intercom-bridge.ts +0 -235
  873. package/src/intercom/native-supervisor-channel.ts +0 -1000
  874. package/src/intercom/result-intercom.ts +0 -433
  875. package/src/intercom/supervisor-ui.ts +0 -72
  876. package/src/missions/actions.ts +0 -433
  877. package/src/missions/goal-driver.ts +0 -177
  878. package/src/missions/lifecycle.ts +0 -367
  879. package/src/missions/store.ts +0 -613
  880. package/src/missions/types.ts +0 -190
  881. package/src/missions/workflow-state.ts +0 -281
  882. package/src/policy/authority.ts +0 -50
  883. package/src/profiles/profiles.ts +0 -674
  884. package/src/runs/background/active-async-capacity.ts +0 -548
  885. package/src/runs/background/active-run-index.ts +0 -155
  886. package/src/runs/background/async-execution.ts +0 -2479
  887. package/src/runs/background/async-job-tracker.ts +0 -869
  888. package/src/runs/background/async-resume.ts +0 -686
  889. package/src/runs/background/async-retention.ts +0 -953
  890. package/src/runs/background/async-status-snapshot.ts +0 -46
  891. package/src/runs/background/async-status.ts +0 -787
  892. package/src/runs/background/auto-drain.ts +0 -92
  893. package/src/runs/background/await-async-run.ts +0 -83
  894. package/src/runs/background/binary-bootstrap.ts +0 -67
  895. package/src/runs/background/calendar-schedule.ts +0 -90
  896. package/src/runs/background/chain-append.ts +0 -321
  897. package/src/runs/background/chain-root-attachment.ts +0 -263
  898. package/src/runs/background/completion-batcher.ts +0 -168
  899. package/src/runs/background/completion-dedupe.ts +0 -58
  900. package/src/runs/background/completion-replay.ts +0 -287
  901. package/src/runs/background/control-channel.ts +0 -659
  902. package/src/runs/background/fleet-view.ts +0 -692
  903. package/src/runs/background/index-segment.ts +0 -59
  904. package/src/runs/background/inspect-rpc.ts +0 -443
  905. package/src/runs/background/notify.ts +0 -1083
  906. package/src/runs/background/owned-process-tree.ts +0 -131
  907. package/src/runs/background/parallel-groups.ts +0 -45
  908. package/src/runs/background/pid-namespace.ts +0 -18
  909. package/src/runs/background/process-terminal-candidate.ts +0 -98
  910. package/src/runs/background/process-terminal.ts +0 -231
  911. package/src/runs/background/result-delivery-ownership.ts +0 -45
  912. package/src/runs/background/result-files.ts +0 -634
  913. package/src/runs/background/result-watcher.ts +0 -842
  914. package/src/runs/background/resume-guidance.ts +0 -56
  915. package/src/runs/background/retained-children.ts +0 -136
  916. package/src/runs/background/retained-nested-route-tracker.ts +0 -96
  917. package/src/runs/background/run-child-session.ts +0 -725
  918. package/src/runs/background/run-id-query.ts +0 -7
  919. package/src/runs/background/run-id-resolver.ts +0 -183
  920. package/src/runs/background/run-status.ts +0 -803
  921. package/src/runs/background/runner-aliases.ts +0 -183
  922. package/src/runs/background/runner-child-launch.ts +0 -96
  923. package/src/runs/background/runner-child-sessions.ts +0 -32
  924. package/src/runs/background/runner-http-dispatcher.ts +0 -122
  925. package/src/runs/background/runner-startup-failure.ts +0 -56
  926. package/src/runs/background/scheduled-runs.ts +0 -1222
  927. package/src/runs/background/stale-run-reconciler.ts +0 -463
  928. package/src/runs/background/steering.ts +0 -260
  929. package/src/runs/background/subagent-runner-bootstrap.ts +0 -279
  930. package/src/runs/background/subagent-runner.ts +0 -5251
  931. package/src/runs/background/subagent-wait.ts +0 -895
  932. package/src/runs/background/terminal-run-index.ts +0 -183
  933. package/src/runs/background/top-level-async.ts +0 -14
  934. package/src/runs/background/wait-completions.ts +0 -262
  935. package/src/runs/background/wait-config.ts +0 -50
  936. package/src/runs/background/wait-subscriptions.ts +0 -354
  937. package/src/runs/background/wait-tool.ts +0 -57
  938. package/src/runs/background/workflow-terminal-proof.ts +0 -85
  939. package/src/runs/foreground/async-dismiss-action.ts +0 -86
  940. package/src/runs/foreground/async-steering-action.ts +0 -276
  941. package/src/runs/foreground/async-stop-action.ts +0 -216
  942. package/src/runs/foreground/command-action.ts +0 -41
  943. package/src/runs/foreground/execution.ts +0 -2315
  944. package/src/runs/foreground/foreground-control.ts +0 -157
  945. package/src/runs/foreground/foreground-history.ts +0 -164
  946. package/src/runs/foreground/prompt-audit.ts +0 -172
  947. package/src/runs/foreground/subagent-executor.ts +0 -8227
  948. package/src/runs/foreground/workflow-detach-reconcile.ts +0 -304
  949. package/src/runs/foreground/workflow-foreground-steering.ts +0 -169
  950. package/src/runs/shared/abort-recovery.ts +0 -119
  951. package/src/runs/shared/acceptance.ts +0 -1664
  952. package/src/runs/shared/agent-contract.ts +0 -38
  953. package/src/runs/shared/async-status-projection.ts +0 -664
  954. package/src/runs/shared/background-process-options.ts +0 -9
  955. package/src/runs/shared/capability-ceiling.ts +0 -214
  956. package/src/runs/shared/chain-outputs.ts +0 -116
  957. package/src/runs/shared/child-commands.ts +0 -229
  958. package/src/runs/shared/child-hooks.ts +0 -175
  959. package/src/runs/shared/child-identity.ts +0 -62
  960. package/src/runs/shared/child-launch-plan.ts +0 -163
  961. package/src/runs/shared/child-launch.ts +0 -389
  962. package/src/runs/shared/child-lifecycle.ts +0 -28
  963. package/src/runs/shared/child-runtime-config.ts +0 -136
  964. package/src/runs/shared/child-session.ts +0 -699
  965. package/src/runs/shared/child-tool-plan.ts +0 -599
  966. package/src/runs/shared/claude-code-adapter.ts +0 -288
  967. package/src/runs/shared/codex-exec-adapter.ts +0 -129
  968. package/src/runs/shared/context-mode.ts +0 -44
  969. package/src/runs/shared/cursor-agent-adapter.ts +0 -114
  970. package/src/runs/shared/dynamic-fanout.ts +0 -297
  971. package/src/runs/shared/effective-system-prompt.ts +0 -33
  972. package/src/runs/shared/extension-bindings.ts +0 -103
  973. package/src/runs/shared/external-cli-contract.ts +0 -177
  974. package/src/runs/shared/external-cli-preflight.ts +0 -190
  975. package/src/runs/shared/external-cli-runner.ts +0 -437
  976. package/src/runs/shared/external-job-bridge.ts +0 -514
  977. package/src/runs/shared/external-job-runner.ts +0 -389
  978. package/src/runs/shared/fast-mode-extension.ts +0 -10
  979. package/src/runs/shared/fork-command-result.ts +0 -10
  980. package/src/runs/shared/git-environment.ts +0 -29
  981. package/src/runs/shared/herdr-connection.ts +0 -134
  982. package/src/runs/shared/herdr-external-adapters.ts +0 -169
  983. package/src/runs/shared/herdr-machine.ts +0 -279
  984. package/src/runs/shared/herdr-pi-protocol.ts +0 -59
  985. package/src/runs/shared/herdr-placed-run.ts +0 -264
  986. package/src/runs/shared/host-step-status.ts +0 -231
  987. package/src/runs/shared/lane-metadata.ts +0 -126
  988. package/src/runs/shared/launch-cwd.ts +0 -16
  989. package/src/runs/shared/long-running-guard.ts +0 -221
  990. package/src/runs/shared/mcp-config-sources.ts +0 -426
  991. package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -579
  992. package/src/runs/shared/mcp-direct-tool-grant.ts +0 -210
  993. package/src/runs/shared/model-resolution-diagnostic.ts +0 -101
  994. package/src/runs/shared/model-resolution.ts +0 -503
  995. package/src/runs/shared/model-scope.ts +0 -224
  996. package/src/runs/shared/mutation-evidence.ts +0 -199
  997. package/src/runs/shared/nested-events.ts +0 -1125
  998. package/src/runs/shared/nested-path.ts +0 -38
  999. package/src/runs/shared/nested-render.ts +0 -127
  1000. package/src/runs/shared/orca-progress-tabs.ts +0 -511
  1001. package/src/runs/shared/parallel-handoff.ts +0 -789
  1002. package/src/runs/shared/parallel-utils.ts +0 -292
  1003. package/src/runs/shared/partial-output.ts +0 -48
  1004. package/src/runs/shared/permissions.ts +0 -86
  1005. package/src/runs/shared/pi-spawn.ts +0 -205
  1006. package/src/runs/shared/process-signal.ts +0 -35
  1007. package/src/runs/shared/profile-extensions.ts +0 -134
  1008. package/src/runs/shared/profile-launch-env.ts +0 -121
  1009. package/src/runs/shared/readonly-drain-observation.ts +0 -42
  1010. package/src/runs/shared/run-fanout-budget.ts +0 -267
  1011. package/src/runs/shared/run-history.ts +0 -288
  1012. package/src/runs/shared/runner-launcher.ts +0 -25
  1013. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
  1014. package/src/runs/shared/sandbox-profile-guard.ts +0 -119
  1015. package/src/runs/shared/sandbox-startup-diagnostics.ts +0 -54
  1016. package/src/runs/shared/session-lease.ts +0 -293
  1017. package/src/runs/shared/single-output.ts +0 -366
  1018. package/src/runs/shared/spawn-budget.ts +0 -128
  1019. package/src/runs/shared/structured-output.ts +0 -463
  1020. package/src/runs/shared/subagent-control.ts +0 -295
  1021. package/src/runs/shared/subagent-prompt-runtime.ts +0 -598
  1022. package/src/runs/shared/tool-availability.ts +0 -37
  1023. package/src/runs/shared/tool-budget.ts +0 -87
  1024. package/src/runs/shared/tool-timeout.ts +0 -93
  1025. package/src/runs/shared/usage-budget.ts +0 -65
  1026. package/src/runs/shared/usage-reconciliation.ts +0 -73
  1027. package/src/runs/shared/workflow-async-child-guidance.ts +0 -18
  1028. package/src/runs/shared/workflow-graph.ts +0 -225
  1029. package/src/runs/shared/worktree-cleanup-apply.ts +0 -160
  1030. package/src/runs/shared/worktree-cleanup-plan.ts +0 -891
  1031. package/src/runs/shared/worktree-lock.ts +0 -29
  1032. package/src/runs/shared/worktree-setup-command.ts +0 -213
  1033. package/src/runs/shared/worktree.ts +0 -1554
  1034. package/src/shared/accessible-dir.ts +0 -47
  1035. package/src/shared/agent-stream-options.ts +0 -5
  1036. package/src/shared/artifacts.ts +0 -281
  1037. package/src/shared/atomic-json.ts +0 -85
  1038. package/src/shared/capacity-resilient-json.ts +0 -102
  1039. package/src/shared/child-cache-retention.ts +0 -43
  1040. package/src/shared/child-session-name.ts +0 -48
  1041. package/src/shared/child-transcript.ts +0 -264
  1042. package/src/shared/completion-owner.ts +0 -14
  1043. package/src/shared/disabled-features.ts +0 -123
  1044. package/src/shared/display-text.ts +0 -150
  1045. package/src/shared/edit-distance.ts +0 -33
  1046. package/src/shared/extension-context.ts +0 -37
  1047. package/src/shared/file-coalescer.ts +0 -49
  1048. package/src/shared/file-lease.ts +0 -74
  1049. package/src/shared/file-system-retry.ts +0 -95
  1050. package/src/shared/fork-context.ts +0 -243
  1051. package/src/shared/fork-session-cwd.ts +0 -27
  1052. package/src/shared/formatters.ts +0 -142
  1053. package/src/shared/jsonl-writer.ts +0 -92
  1054. package/src/shared/launch-contract.ts +0 -206
  1055. package/src/shared/model-info.ts +0 -132
  1056. package/src/shared/model-response-aliases.ts +0 -13
  1057. package/src/shared/node-executable.ts +0 -21
  1058. package/src/shared/opencode-session-headers.ts +0 -30
  1059. package/src/shared/package-version.ts +0 -17
  1060. package/src/shared/parent-wake.ts +0 -79
  1061. package/src/shared/permission-profile.ts +0 -56
  1062. package/src/shared/prompt-resources.ts +0 -11
  1063. package/src/shared/pruned-fork.ts +0 -469
  1064. package/src/shared/required-child-extensions.ts +0 -115
  1065. package/src/shared/runtime-module-path.ts +0 -19
  1066. package/src/shared/sandbox-profile.ts +0 -37
  1067. package/src/shared/session-file-trust.ts +0 -19
  1068. package/src/shared/session-identity.ts +0 -10
  1069. package/src/shared/session-tokens.ts +0 -55
  1070. package/src/shared/settings-file-lease.ts +0 -36
  1071. package/src/shared/settings.ts +0 -412
  1072. package/src/shared/shortcuts.ts +0 -13
  1073. package/src/shared/status-format.ts +0 -55
  1074. package/src/shared/thinking-ceiling.ts +0 -46
  1075. package/src/shared/types.ts +0 -3105
  1076. package/src/shared/utf8.ts +0 -11
  1077. package/src/shared/utils.ts +0 -610
  1078. package/src/shared/watch-strategy.ts +0 -12
  1079. package/src/shared/workflow-child-permit.ts +0 -212
  1080. package/src/slash/delegation-adapters.ts +0 -452
  1081. package/src/slash/delegation-json.ts +0 -108
  1082. package/src/slash/delegation-request.ts +0 -176
  1083. package/src/slash/prompt-template-bridge.ts +0 -434
  1084. package/src/slash/prompt-workflows.ts +0 -298
  1085. package/src/slash/selector.ts +0 -147
  1086. package/src/slash/slash-bridge.ts +0 -192
  1087. package/src/slash/slash-commands.ts +0 -1096
  1088. package/src/slash/slash-live-state.ts +0 -310
  1089. package/src/slash/subagent-cost.ts +0 -317
  1090. package/src/slash/subagents-admin.ts +0 -489
  1091. package/src/tui/fleet-native-transcript.ts +0 -424
  1092. package/src/tui/fleet-status.ts +0 -1139
  1093. package/src/tui/fleet-transcript.ts +0 -591
  1094. package/src/tui/fleet.ts +0 -1618
  1095. package/src/tui/mouse-events.ts +0 -42
  1096. package/src/tui/render-helpers.ts +0 -111
  1097. package/src/tui/render.ts +0 -3824
  1098. package/src/tui/running-tone.ts +0 -28
  1099. package/src/tui/subagent-messages.ts +0 -305
  1100. package/src/ui-silent-marker.ts +0 -32
  1101. package/src/watchdog/change-signature.ts +0 -260
  1102. package/src/watchdog/child-status.ts +0 -225
  1103. package/src/watchdog/diff-tool.ts +0 -112
  1104. package/src/watchdog/emission-guard.ts +0 -125
  1105. package/src/watchdog/guidance.ts +0 -20
  1106. package/src/watchdog/lsp-diagnostics.ts +0 -538
  1107. package/src/watchdog/model-selection.ts +0 -187
  1108. package/src/watchdog/permission-arbiter.ts +0 -154
  1109. package/src/watchdog/register-child.ts +0 -136
  1110. package/src/watchdog/register-main.ts +0 -425
  1111. package/src/watchdog/render.ts +0 -31
  1112. package/src/watchdog/review.ts +0 -362
  1113. package/src/watchdog/rules.ts +0 -70
  1114. package/src/watchdog/runtime.ts +0 -927
  1115. package/src/watchdog/scope.ts +0 -51
  1116. package/src/watchdog/settings.ts +0 -520
  1117. package/src/watchdog/tool-actions.ts +0 -156
  1118. package/src/watchdog/turn-delta.ts +0 -190
  1119. package/src/watchdog/types.ts +0 -186
  1120. package/src/watchdog/warning-format.ts +0 -72
  1121. package/src/workflows/chat-progress.ts +0 -152
  1122. package/src/workflows/host-command.ts +0 -235
  1123. package/src/workflows/scripted-workflow.ts +0 -2733
  1124. package/src/workflows/structured-workflow-scripts.ts +0 -177
  1125. package/src/workflows/workflow-checklist.ts +0 -442
  1126. package/src/workflows/workflow-child-summary.ts +0 -172
  1127. package/src/workflows/workflow-preflight.ts +0 -297
  1128. package/src/workflows/workflow-receipt.ts +0 -390
  1129. package/src/workflows/workflow-resources.ts +0 -275
  1130. package/src/workflows/workflow-reuse.ts +0 -120
  1131. package/src/workflows/workflow-revival.ts +0 -123
  1132. package/src/workflows/workflow-settlement.ts +0 -252
@@ -1,1442 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import type { AgentToolResult } from "@earendil-works/pi-agent-core";
4
- import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
5
- import {
6
- type AgentConfig,
7
- type AgentDiscoveryDiagnostic,
8
- type AgentDiscoveryAllResult,
9
- type AgentScope,
10
- type AgentSource,
11
- defaultInheritProjectContext,
12
- defaultInheritSkills,
13
- defaultSystemPromptMode,
14
- discoverAgentsAll,
15
- buildRuntimeName,
16
- findBlockingAgentDiagnostic,
17
- frontmatterNameForConfig,
18
- parsePackageName,
19
- mergeBuiltinAgentOverride,
20
- removeBuiltinAgentOverride,
21
- removeBuiltinAgentOverrideFields,
22
- resolveAgentName,
23
- } from "./agents.ts";
24
- import { serializeAgent } from "./agent-serializer.ts";
25
- import { mergeAgentsForScope } from "./agent-selection.ts";
26
- import { discoverAvailableSkills, resolveSkills } from "./skills.ts";
27
- import {
28
- buildProactiveSkillSubagentRecommendationLines,
29
- } from "./proactive-skills.ts";
30
- import { parseFrontmatter, parseFrontmatterList } from "./frontmatter.ts";
31
- import { resolveEffectiveThinking, toModelInfo } from "../shared/model-info.ts";
32
- import { resolveSubagentModelOverride, type ParentModel } from "../runs/shared/model-resolution.ts";
33
- import { validateToolBudgetConfig } from "../runs/shared/tool-budget.ts";
34
- import { formatReviewGateLabel, validateAcceptanceInput } from "../runs/shared/acceptance.ts";
35
- import { CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL, isCodeOwnedExternalCliAdapterId, resolveExternalCliRunnerStatus, validateCodeOwnedProfileRunner } from "../runs/shared/external-cli-contract.ts";
36
- import { resolveExternalCliBinaryAvailability, type ExternalCliBinaryAvailability } from "../runs/shared/external-cli-preflight.ts";
37
- import type { AcceptanceInput, AgentCapabilitiesSnapshot, AgentCapabilityRow, Details, ExtensionConfig, ToolBudgetConfig } from "../shared/types.ts";
38
- import { getProjectConfigDir } from "../shared/utils.ts";
39
- import { previewDisplayText } from "../shared/display-text.ts";
40
- import { capabilityCeilingAgentRestrictionSources, isAgentAllowedByCapabilityCeiling, resolveCurrentSubagentCapabilityCeiling } from "../runs/shared/capability-ceiling.ts";
41
- import { mergeRuntimeAgents, type RuntimeAgentOwner } from "./runtime-agent-registry.ts";
42
- import { listExternalJobProviders } from "../api/external-job-provider.ts";
43
- import { validateSandboxProfileName } from "../shared/sandbox-profile.ts";
44
- import { validatePermissionProfileName } from "../shared/permission-profile.ts";
45
- import { ejectAgentDefinition } from "./agent-eject.ts";
46
-
47
- export const AGENT_MANAGEMENT_API_VERSION = 1 as const;
48
-
49
- type ManagementAction = "list" | "get" | "models" | "create" | "update" | "delete" | "eject" | "disable" | "enable" | "reset";
50
- type ManagementScope = "user" | "project";
51
- type ManagementContext = Pick<ExtensionContext, "cwd" | "modelRegistry"> & { isProjectTrusted?: ExtensionContext["isProjectTrusted"]; model?: ExtensionContext["model"]; config?: ExtensionConfig; currentSessionId?: string; runtimeAgentOwner?: RuntimeAgentOwner; onAgentsChanged?: () => void; discoverAgentsAll?: typeof discoverAgentsAll };
52
-
53
- function discoverCatalog(ctx: ManagementContext, cwd: string = ctx.cwd, provider?: string): AgentDiscoveryAllResult {
54
- return (ctx.discoverAgentsAll ?? discoverAgentsAll)(cwd, provider);
55
- }
56
-
57
- interface ManagementParams {
58
- action?: string;
59
- agent?: string;
60
- agentScope?: unknown;
61
- capabilities?: unknown;
62
- config?: unknown;
63
- }
64
-
65
- function result(text: string, isError = false, details?: Partial<Details>): AgentToolResult<Details> {
66
- return { content: [{ type: "text", text }], isError, details: { mode: "management", results: [], ...details } };
67
- }
68
-
69
- function jsonDetails<T>(value: T): T {
70
- return JSON.parse(JSON.stringify(value)) as T;
71
- }
72
-
73
- function presentDetails<T extends Record<string, unknown>>(value: T): T | undefined {
74
- const cleaned = jsonDetails(value);
75
- return Object.keys(cleaned).length > 0 ? cleaned : undefined;
76
- }
77
-
78
- function parseCsv(value: string): string[] {
79
- return [...new Set(value.split(",").map((v) => v.trim()).filter(Boolean))];
80
- }
81
-
82
- type ConfigObjectResult =
83
- | { status: "ok"; value: Record<string, unknown> }
84
- | { status: "missing" }
85
- | { status: "error"; message: string };
86
-
87
- function configObject(config: unknown): ConfigObjectResult {
88
- let val = config;
89
- if (typeof val === "string") {
90
- try {
91
- val = JSON.parse(val);
92
- } catch (error) {
93
- const message = error instanceof Error ? error.message : String(error);
94
- return { status: "error", message: `config must be valid JSON: ${message}` };
95
- }
96
- }
97
- if (!val || typeof val !== "object" || Array.isArray(val)) return { status: "missing" };
98
- return { status: "ok", value: val as Record<string, unknown> };
99
- }
100
-
101
- function hasKey(obj: Record<string, unknown>, key: string): boolean {
102
- return Object.prototype.hasOwnProperty.call(obj, key);
103
- }
104
-
105
- function isJsonSerializable(value: unknown): boolean {
106
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
107
- if (typeof value === "number") return Number.isFinite(value);
108
- if (Array.isArray(value)) return value.every(isJsonSerializable);
109
- if (value && typeof value === "object") return Object.values(value).every(isJsonSerializable);
110
- return false;
111
- }
112
-
113
- function asDisambiguationScope(scope: unknown): ManagementScope | undefined {
114
- if (scope === "user" || scope === "project") return scope;
115
- return undefined;
116
- }
117
-
118
- function actionScope(scope: unknown, action: ManagementAction): { scope?: ManagementScope; error?: AgentToolResult<Details> } {
119
- if (scope === undefined) return { scope: "user" };
120
- const parsed = asDisambiguationScope(scope);
121
- return parsed ? { scope: parsed } : { error: result(`agentScope must be 'user' or 'project' for ${action}.`, true) };
122
- }
123
-
124
- function normalizeListScope(scope: unknown): AgentScope | undefined {
125
- if (scope === undefined) return "both";
126
- if (scope === "user" || scope === "project" || scope === "both") return scope;
127
- return undefined;
128
- }
129
-
130
- // [fork] Exported for agents/agent-eject.ts.
131
- export function sanitizeName(name: string): string {
132
- return name.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
133
- }
134
-
135
- function parsePackageConfig(value: unknown): { packageName?: string; error?: string } {
136
- return parsePackageName(value, "config.package");
137
- }
138
-
139
- type DiscoveredAgentSets = Pick<AgentDiscoveryAllResult, "builtin" | "package" | "user" | "project" | "cwd">;
140
-
141
- function allAgents(d: DiscoveredAgentSets): AgentConfig[] {
142
- return [...d.builtin, ...d.package, ...d.user, ...d.project];
143
- }
144
-
145
- function effectiveAgentsForScope(
146
- scope: AgentScope,
147
- d: DiscoveredAgentSets,
148
- runtimeAgentOwner?: RuntimeAgentOwner,
149
- preferredModelProvider?: string,
150
- ): AgentConfig[] {
151
- let agents = mergeAgentsForScope(scope, d.user, d.project, d.builtin, d.package);
152
- if (runtimeAgentOwner) {
153
- agents = mergeRuntimeAgents(runtimeAgentOwner, { agents }, allAgents(d), { cwd: d.cwd, scope, preferredModelProvider }).agents;
154
- }
155
- return agents;
156
- }
157
-
158
- function availableAgentNamesFromDiscovery(
159
- d: DiscoveredAgentSets,
160
- runtimeAgentOwner?: RuntimeAgentOwner,
161
- preferredModelProvider?: string,
162
- ): string[] {
163
- const agents = runtimeAgentOwner ? effectiveAgentsForScope("both", d, runtimeAgentOwner, preferredModelProvider) : allAgents(d);
164
- return [...new Set(agents.map((agent) => agent.name))].sort((a, b) => a.localeCompare(b));
165
- }
166
-
167
- function availableAgentNames(ctx: ManagementContext, cwd: string = ctx.cwd): string[] {
168
- return availableAgentNamesFromDiscovery(discoverCatalog(ctx, cwd));
169
- }
170
-
171
- // [fork] Exported for agents/agent-eject.ts.
172
- export function availableAgentNamesForCwd(cwd: string): string[] {
173
- return availableAgentNamesFromDiscovery(discoverAgentsAll(cwd));
174
- }
175
-
176
- function findAgentsInDiscovery(
177
- name: string,
178
- d: DiscoveredAgentSets,
179
- scope: AgentScope = "both",
180
- runtimeAgentOwner?: RuntimeAgentOwner,
181
- preferredModelProvider?: string,
182
- ): AgentConfig[] {
183
- const raw = name.trim();
184
- const sanitized = sanitizeName(raw);
185
- const scoped = effectiveAgentsForScope(scope, d, runtimeAgentOwner, preferredModelProvider);
186
- let resolved = resolveAgentName(raw, scoped);
187
- if (!resolved.agent && !resolved.error && sanitized !== raw) resolved = resolveAgentName(sanitized, scoped);
188
- if (resolved.agent) return scoped.filter((agent) => agent.name === resolved.agent!.name).sort((a, b) => a.source.localeCompare(b.source));
189
- return scoped
190
- .filter((agent) => Boolean(resolveAgentName(raw, [agent]).agent)
191
- || (sanitized !== raw && Boolean(resolveAgentName(sanitized, [agent]).agent)))
192
- .sort((a, b) => a.source.localeCompare(b.source));
193
- }
194
-
195
- function findAgents(name: string, ctx: ManagementContext, scope: AgentScope = "both"): AgentConfig[] {
196
- return findAgentsInDiscovery(name, discoverCatalog(ctx), scope);
197
- }
198
-
199
- function diagnosticsForScope(diagnostics: AgentDiscoveryDiagnostic[] | undefined, scope: AgentScope): AgentDiscoveryDiagnostic[] | undefined {
200
- if (scope === "both") return diagnostics;
201
- const excludedSource = scope === "user" ? "project" : "user";
202
- return diagnostics?.filter((diagnostic) => diagnostic.source !== excludedSource);
203
- }
204
-
205
- const AGENT_SOURCE_PRECEDENCE: Record<AgentSource, number> = { builtin: 0, package: 1, user: 2, project: 3, runtime: 4 };
206
-
207
- // Returns the highest-precedence definition for a resolved canonical name (project > user > package > builtin),
208
- // matching mergeAgentsForScope for "both", including disabled agents so disable/enable can locate hidden targets.
209
- function resolveEffectiveAgent(d: ReturnType<typeof discoverAgentsAll>, name: string): { agent?: AgentConfig; error?: string } {
210
- const raw = name.trim();
211
- const candidates = allAgents(d);
212
- let resolved = resolveAgentName(raw, candidates);
213
- if (!resolved.agent && !resolved.error) {
214
- const sanitized = sanitizeName(raw);
215
- if (sanitized !== raw) resolved = resolveAgentName(sanitized, candidates);
216
- }
217
- if (resolved.error) return { error: resolved.error };
218
- if (!resolved.agent) return {};
219
- const matches = candidates.filter((agent) => agent.name === resolved.agent!.name);
220
- return { agent: matches.reduce((best, agent) => (AGENT_SOURCE_PRECEDENCE[agent.source] > AGENT_SOURCE_PRECEDENCE[best.source] ? agent : best)) };
221
- }
222
-
223
- function nameExistsInScope(ctx: ManagementContext, scope: ManagementScope, name: string, excludePath?: string): boolean {
224
- const d = discoverCatalog(ctx);
225
- for (const a of scope === "user" ? d.user : d.project) {
226
- if (a.name === name && a.filePath !== excludePath) return true;
227
- }
228
- return false;
229
- }
230
-
231
- // [fork] Exported for agents/agent-eject.ts.
232
- export function nameExistsInScopeForCwd(cwd: string, scope: ManagementScope, name: string, excludePath?: string): boolean {
233
- const d = discoverAgentsAll(cwd);
234
- for (const a of scope === "user" ? d.user : d.project) {
235
- if (a.name === name && a.filePath !== excludePath) return true;
236
- }
237
- return false;
238
- }
239
-
240
- function isMutableSource(source: AgentSource): source is ManagementScope {
241
- return source === "user" || source === "project";
242
- }
243
-
244
- function modelWarning(ctx: ManagementContext, model: string | undefined): string | undefined {
245
- if (!model) return undefined;
246
- const found = ctx.modelRegistry.getAvailable().some((m) => `${m.provider}/${m.id}` === model || m.id === model);
247
- if (found) return undefined;
248
- return `Warning: model '${model}' is not in the current model registry. Run subagent({ action: "models" }) to list valid provider/id selectors, then use the exact provider/id form (bare ids resolve only when unique).`;
249
- }
250
-
251
- function skillsWarning(cwd: string, agent: Pick<AgentConfig, "skills" | "skillPath" | "filePath">): string | undefined {
252
- if (!agent.skills?.length) return undefined;
253
- const { missing } = resolveSkills(
254
- agent.skills,
255
- cwd,
256
- agent.skillPath,
257
- agent.filePath ? path.dirname(agent.filePath) : cwd,
258
- );
259
- return missing.length ? `Warning: skills not found: ${missing.join(", ")}.` : undefined;
260
- }
261
-
262
- function withDeclaredExtensionPaths(config: AgentConfig, filePath: string): AgentConfig {
263
- const { frontmatter } = parseFrontmatter(fs.readFileSync(filePath, "utf-8"));
264
- const { extensions: _extensions, subagentOnlyExtensions: _subagentOnlyExtensions, ...withoutResolvedExtensions } = config;
265
- return {
266
- ...withoutResolvedExtensions,
267
- ...(frontmatter.extensions !== undefined ? { extensions: parseFrontmatterList(frontmatter.extensions) } : {}),
268
- ...(frontmatter.subagentOnlyExtensions !== undefined
269
- ? { subagentOnlyExtensions: parseFrontmatterList(frontmatter.subagentOnlyExtensions) }
270
- : {}),
271
- };
272
- }
273
-
274
- export function editableAgentConfig(agent: AgentConfig): AgentConfig {
275
- const { extensions: _extensions, ...withoutExtensions } = agent;
276
- const base = agent.override?.base;
277
- const description = base?.description ?? agent.description;
278
- const frontmatterFields = agent.source === "builtin" || agent.source === "runtime" ? undefined : readAgentFrontmatterFields(agent.filePath);
279
- const hasDeclaredField = (...fields: string[]) => frontmatterFields === undefined || fields.some((field) => frontmatterFields.has(field));
280
- const withoutSettingsDefaults = (config: AgentConfig): AgentConfig => {
281
- if (!frontmatterFields) return config;
282
- const next = { ...config };
283
- if (!hasDeclaredField("model")) delete next.model;
284
- if (!hasDeclaredField("thinking")) delete next.thinking;
285
- return next;
286
- };
287
- const {
288
- override: _override,
289
- description: _description,
290
- output: _output,
291
- outputMode: _outputMode,
292
- defaultReads: _defaultReads,
293
- model: _model,
294
- fast: _fast,
295
- thinking: _thinking,
296
- systemPromptMode: _systemPromptMode,
297
- inheritProjectContext: _inheritProjectContext,
298
- inheritGlobalContext: _inheritGlobalContext,
299
- inheritSkills: _inheritSkills,
300
- defaultContext: _defaultContext,
301
- acceptanceRole: _acceptanceRole,
302
- disabled: _disabled,
303
- systemPrompt: _systemPrompt,
304
- skills: _skills,
305
- skillPath: _skillPath,
306
- tools: _tools,
307
- excludeTools: _excludeTools,
308
- mcpDirectTools: _mcpDirectTools,
309
- allowNestedSubagents: _allowNestedSubagents,
310
- allowedAgents: _allowedAgents,
311
- subagentOnlyExtensions: _subagentOnlyExtensions,
312
- mutationTools: _mutationTools,
313
- toolBudget: _toolBudget,
314
- ...editable
315
- } = withoutExtensions;
316
- if (!base) {
317
- return withDeclaredExtensionPaths(withoutSettingsDefaults({
318
- ...withoutExtensions,
319
- ...(agent.extensionsFromDefault ? {} : agent.extensions !== undefined ? { extensions: [...agent.extensions] } : {}),
320
- }), agent.filePath);
321
- }
322
-
323
- return withDeclaredExtensionPaths({
324
- ...editable,
325
- description,
326
- ...(base.output !== undefined ? { output: base.output } : {}),
327
- ...(base.outputMode !== undefined ? { outputMode: base.outputMode } : {}),
328
- ...(base.defaultReads !== undefined ? { defaultReads: [...base.defaultReads] } : {}),
329
- ...(base.model !== undefined && hasDeclaredField("model") ? { model: base.model } : {}),
330
- ...(base.fast !== undefined ? { fast: base.fast } : {}),
331
- ...(base.thinking !== undefined && hasDeclaredField("thinking") ? { thinking: base.thinking } : {}),
332
- systemPromptMode: base.systemPromptMode,
333
- inheritProjectContext: base.inheritProjectContext,
334
- inheritGlobalContext: base.inheritGlobalContext,
335
- inheritSkills: base.inheritSkills,
336
- ...(base.defaultContext !== undefined ? { defaultContext: base.defaultContext } : {}),
337
- ...(base.acceptanceRole !== undefined ? { acceptanceRole: base.acceptanceRole } : {}),
338
- ...(base.disabled !== undefined ? { disabled: base.disabled } : {}),
339
- systemPrompt: base.systemPrompt,
340
- ...(base.skills !== undefined ? { skills: [...base.skills] } : {}),
341
- ...(base.skillPath !== undefined ? { skillPath: [...base.skillPath] } : {}),
342
- ...(base.tools !== undefined ? { tools: [...base.tools] } : {}),
343
- ...(base.excludeTools !== undefined ? { excludeTools: [...base.excludeTools] } : {}),
344
- ...(base.mcpDirectTools !== undefined ? { mcpDirectTools: [...base.mcpDirectTools] } : {}),
345
- ...(base.allowNestedSubagents !== undefined ? { allowNestedSubagents: base.allowNestedSubagents } : {}),
346
- ...(base.allowedAgents !== undefined ? { allowedAgents: [...base.allowedAgents] } : {}),
347
- ...(base.extensions !== undefined ? { extensions: [...base.extensions] } : {}),
348
- ...(base.subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions: [...base.subagentOnlyExtensions] } : {}),
349
- ...(base.mutationTools !== undefined ? { mutationTools: [...base.mutationTools] } : {}),
350
- ...(base.toolBudget !== undefined ? { toolBudget: base.toolBudget } : {}),
351
- }, agent.filePath);
352
- }
353
-
354
- function readAgentFrontmatterFields(filePath: string): Set<string> {
355
- try {
356
- const { frontmatter } = parseFrontmatter(fs.readFileSync(filePath, "utf-8"));
357
- return new Set(Object.keys(frontmatter));
358
- } catch {
359
- return new Set();
360
- }
361
- }
362
-
363
- export function preservedAgentFrontmatterFields(agent: AgentConfig, cfg: Record<string, unknown>): Set<string> {
364
- const fields = readAgentFrontmatterFields(agent.filePath);
365
- const changed = (...names: string[]) => {
366
- for (const name of names) fields.delete(name);
367
- };
368
-
369
- if (hasKey(cfg, "name")) changed("name");
370
- if (hasKey(cfg, "package")) changed("package");
371
- if (hasKey(cfg, "description")) changed("description");
372
- if (hasKey(cfg, "advertise")) changed("advertise");
373
- if (hasKey(cfg, "aliases")) changed("alias", "aliases");
374
- if (hasKey(cfg, "systemPrompt")) changed("systemPrompt");
375
- if (hasKey(cfg, "runner")) changed("runner");
376
- if (hasKey(cfg, "model")) changed("model");
377
- if (hasKey(cfg, "tools")) changed("tools");
378
- if (hasKey(cfg, "excludeTools")) changed("excludeTools");
379
- if (hasKey(cfg, "skills")) changed("skill", "skills");
380
- if (hasKey(cfg, "skillPath")) changed("skillPath");
381
- if (hasKey(cfg, "extensions")) changed("extensions");
382
- if (hasKey(cfg, "subagentOnlyExtensions")) changed("subagentOnlyExtensions");
383
- if (hasKey(cfg, "mutationTools")) changed("mutationTools");
384
- if (hasKey(cfg, "thinking")) {
385
- changed("thinking");
386
- if (cfg.thinking === "off") fields.add("thinking");
387
- }
388
- if (hasKey(cfg, "systemPromptMode")) {
389
- changed("systemPromptMode");
390
- fields.add("systemPromptMode");
391
- }
392
- if (hasKey(cfg, "inheritProjectContext")) {
393
- changed("inheritProjectContext");
394
- fields.add("inheritProjectContext");
395
- }
396
- if (hasKey(cfg, "inheritGlobalContext")) {
397
- changed("inheritGlobalContext");
398
- fields.add("inheritGlobalContext");
399
- }
400
- if (hasKey(cfg, "inheritSkills")) {
401
- changed("inheritSkills");
402
- fields.add("inheritSkills");
403
- }
404
- if (hasKey(cfg, "defaultContext")) changed("defaultContext");
405
- if (hasKey(cfg, "async")) changed("async");
406
- if (hasKey(cfg, "timeoutMs")) changed("timeoutMs");
407
- if (hasKey(cfg, "acceptance")) changed("acceptance");
408
- if (hasKey(cfg, "acceptanceRole")) changed("acceptanceRole");
409
- if (hasKey(cfg, "output")) changed("output");
410
- if (hasKey(cfg, "outputMode")) changed("outputMode");
411
- if (hasKey(cfg, "reads")) changed("defaultReads");
412
- if (hasKey(cfg, "progress")) changed("defaultProgress");
413
- if (hasKey(cfg, "maxSubagentDepth")) changed("maxSubagentDepth");
414
- if (hasKey(cfg, "toolBudget")) changed("toolBudget");
415
- if (hasKey(cfg, "sandbox")) changed("sandbox");
416
- if (hasKey(cfg, "permissionProfile")) changed("permission-profile");
417
-
418
- return fields;
419
- }
420
-
421
- function parseTools(raw: string): { tools?: string[]; mcpDirectTools?: string[] } {
422
- const tools: string[] = [];
423
- const mcpDirectTools: string[] = [];
424
- for (const item of parseCsv(raw)) {
425
- if (item.startsWith("mcp:")) {
426
- const direct = item.slice(4).trim();
427
- if (direct) mcpDirectTools.push(direct);
428
- } else tools.push(item);
429
- }
430
- return {
431
- ...(tools.length ? { tools } : {}),
432
- ...(mcpDirectTools.length ? { mcpDirectTools } : {}),
433
- };
434
- }
435
-
436
- function applyAgentConfig(target: AgentConfig, cfg: Record<string, unknown>): string | undefined {
437
- if (hasKey(cfg, "advertise")) {
438
- if (cfg.advertise === "") delete target.advertise;
439
- else if (typeof cfg.advertise === "boolean") target.advertise = cfg.advertise;
440
- else return "config.advertise must be a boolean or empty string when provided.";
441
- }
442
- if (hasKey(cfg, "aliases")) {
443
- if (cfg.aliases === false || cfg.aliases === "") delete target.aliases;
444
- else if (typeof cfg.aliases === "string") {
445
- const aliases = parseCsv(cfg.aliases).filter((alias) => alias !== target.name);
446
- if (aliases.length) target.aliases = aliases;
447
- else delete target.aliases;
448
- } else if (Array.isArray(cfg.aliases) && cfg.aliases.every((entry) => typeof entry === "string")) {
449
- const aliases = [...new Set(cfg.aliases.map((entry) => entry.trim()).filter(Boolean).filter((alias) => alias !== target.name))];
450
- if (aliases.length) target.aliases = aliases;
451
- else delete target.aliases;
452
- } else return "config.aliases must be a comma-separated string, string array, or false when provided.";
453
- }
454
- if (hasKey(cfg, "systemPrompt")) {
455
- if (cfg.systemPrompt === false || cfg.systemPrompt === "") target.systemPrompt = "";
456
- else if (typeof cfg.systemPrompt === "string") target.systemPrompt = cfg.systemPrompt;
457
- else return "config.systemPrompt must be a string or false when provided.";
458
- }
459
- if (hasKey(cfg, "runner")) {
460
- if (cfg.runner === false || cfg.runner === "") delete target.runner;
461
- else if (cfg.runner && typeof cfg.runner === "object" && !Array.isArray(cfg.runner)) {
462
- const runner = cfg.runner as Record<string, unknown>;
463
- if (runner.type === "pi" && Object.keys(runner).every((key) => key === "type")) target.runner = { type: "pi" };
464
- else if (runner.type === "external-cli" && typeof runner.command === "string" && runner.command.trim()
465
- && (runner.args === undefined || (Array.isArray(runner.args) && runner.args.every((arg) => typeof arg === "string")))
466
- && (runner.adapter === undefined || isCodeOwnedExternalCliAdapterId(runner.adapter))
467
- && (runner.adapter === undefined || runner.args === undefined || runner.args.length === 0)
468
- && (runner.promptDelivery === undefined || runner.promptDelivery === "stdin")
469
- && Object.keys(runner).every((key) => ["type", "adapter", "command", "args", "promptDelivery"].includes(key))) {
470
- const runnerArgs = Array.isArray(runner.args) ? runner.args.filter((arg): arg is string => typeof arg === "string") : undefined;
471
- target.runner = { type: "external-cli", ...(isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}), command: runner.command.trim(), ...(runnerArgs?.length ? { args: runnerArgs } : {}), ...(runner.promptDelivery ? { promptDelivery: "stdin" } : {}) };
472
- } else if (runner.type === "external-job" && typeof runner.provider === "string" && runner.provider.trim() === runner.provider && runner.provider
473
- && (runner.options === undefined || (runner.options && typeof runner.options === "object" && !Array.isArray(runner.options) && isJsonSerializable(runner.options)))
474
- && Object.keys(runner).every((key) => ["type", "provider", "options"].includes(key))) {
475
- target.runner = { type: "external-job", provider: runner.provider, ...(runner.options ? { options: runner.options as Record<string, unknown> } : {}) };
476
- } else return `config.runner must be { type: 'pi' }, { type: 'external-cli', adapter?: ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}, command: string, args?: string[], promptDelivery?: 'stdin' }, or { type: 'external-job', provider: string, options?: object }.`;
477
- } else return "config.runner must be an object, false, or empty string when provided.";
478
- }
479
- if (hasKey(cfg, "launcher")) return "config.launcher is not supported by agent management; edit the agent file's 'launcher' frontmatter directly.";
480
- if (target.launcher && (target.runner?.type === "external-cli" || target.runner?.type === "external-job")) {
481
- return `config.runner type '${target.runner.type}' cannot be combined with this agent's 'launcher' frontmatter.`;
482
- }
483
- if (hasKey(cfg, "model")) {
484
- if (cfg.model === false || cfg.model === "") delete target.model;
485
- else if (typeof cfg.model === "string") {
486
- const model = cfg.model.trim();
487
- if (model) target.model = model;
488
- else delete target.model;
489
- } else return "config.model must be a string or false when provided.";
490
- }
491
- if (hasKey(cfg, "fallbackModels")) return "config.fallbackModels was removed; configure one model instead.";
492
- if (hasKey(cfg, "tools")) {
493
- if (cfg.tools === false || cfg.tools === "") { delete target.tools; delete target.mcpDirectTools; }
494
- else if (typeof cfg.tools === "string") {
495
- const parsed = parseTools(cfg.tools);
496
- if (parsed.tools) target.tools = parsed.tools;
497
- else delete target.tools;
498
- if (parsed.mcpDirectTools) target.mcpDirectTools = parsed.mcpDirectTools;
499
- else delete target.mcpDirectTools;
500
- } else return "config.tools must be a comma-separated string or false when provided.";
501
- }
502
- if (hasKey(cfg, "excludeTools")) {
503
- if (cfg.excludeTools === false || cfg.excludeTools === "") delete target.excludeTools;
504
- else if (typeof cfg.excludeTools === "string") {
505
- const excludeTools = parseCsv(cfg.excludeTools);
506
- if (excludeTools.length) target.excludeTools = [...new Set(excludeTools)];
507
- else delete target.excludeTools;
508
- } else if (Array.isArray(cfg.excludeTools) && cfg.excludeTools.every((entry) => typeof entry === "string")) {
509
- const excludeTools = [...new Set(cfg.excludeTools.map((entry) => entry.trim()).filter(Boolean))];
510
- if (excludeTools.length) target.excludeTools = excludeTools;
511
- else delete target.excludeTools;
512
- } else return "config.excludeTools must be a comma-separated string, string array, or false when provided.";
513
- }
514
- if (hasKey(cfg, "skills")) {
515
- if (cfg.skills === false || cfg.skills === "") delete target.skills;
516
- else if (typeof cfg.skills === "string") {
517
- const skills = parseCsv(cfg.skills);
518
- if (skills.length) target.skills = skills;
519
- else delete target.skills;
520
- } else return "config.skills must be a comma-separated string or false when provided.";
521
- }
522
- if (hasKey(cfg, "skillPath")) {
523
- if (cfg.skillPath === false || cfg.skillPath === "") delete target.skillPath;
524
- else if (typeof cfg.skillPath === "string") {
525
- const skillPath = parseCsv(cfg.skillPath);
526
- if (skillPath.length) target.skillPath = skillPath;
527
- else delete target.skillPath;
528
- } else if (Array.isArray(cfg.skillPath) && cfg.skillPath.every((entry) => typeof entry === "string")) {
529
- const skillPath = [...new Set(cfg.skillPath.map((entry) => entry.trim()).filter(Boolean))];
530
- if (skillPath.length) target.skillPath = skillPath;
531
- else delete target.skillPath;
532
- } else return "config.skillPath must be a comma-separated string, string array, or false when provided.";
533
- }
534
- if (hasKey(cfg, "extensions")) {
535
- if (cfg.extensions === false) delete target.extensions;
536
- else if (cfg.extensions === "") target.extensions = [];
537
- else if (typeof cfg.extensions === "string") target.extensions = parseCsv(cfg.extensions);
538
- else return "config.extensions must be a comma-separated string, empty string, or false when provided.";
539
- }
540
- if (hasKey(cfg, "subagentOnlyExtensions")) {
541
- if (cfg.subagentOnlyExtensions === false) delete target.subagentOnlyExtensions;
542
- else if (cfg.subagentOnlyExtensions === "") target.subagentOnlyExtensions = [];
543
- else if (typeof cfg.subagentOnlyExtensions === "string") target.subagentOnlyExtensions = parseCsv(cfg.subagentOnlyExtensions);
544
- else return "config.subagentOnlyExtensions must be a comma-separated string, empty string, or false when provided.";
545
- }
546
- if (hasKey(cfg, "mutationTools")) {
547
- if (cfg.mutationTools === false) delete target.mutationTools;
548
- else if (cfg.mutationTools === "") target.mutationTools = [];
549
- else if (typeof cfg.mutationTools === "string") target.mutationTools = parseCsv(cfg.mutationTools);
550
- else return "config.mutationTools must be a comma-separated string, empty string, or false when provided.";
551
- }
552
- if (hasKey(cfg, "thinking")) {
553
- if (cfg.thinking === false || cfg.thinking === "") delete target.thinking;
554
- else if (typeof cfg.thinking === "string") {
555
- const thinking = cfg.thinking.trim();
556
- if (thinking) target.thinking = thinking;
557
- else delete target.thinking;
558
- } else return "config.thinking must be a string or false when provided.";
559
- }
560
- if (hasKey(cfg, "systemPromptMode")) {
561
- if (cfg.systemPromptMode === "append" || cfg.systemPromptMode === "replace") target.systemPromptMode = cfg.systemPromptMode;
562
- else return "config.systemPromptMode must be 'append' or 'replace' when provided.";
563
- }
564
- if (hasKey(cfg, "inheritProjectContext")) {
565
- if (typeof cfg.inheritProjectContext !== "boolean") return "config.inheritProjectContext must be a boolean when provided.";
566
- target.inheritProjectContext = cfg.inheritProjectContext;
567
- }
568
- if (hasKey(cfg, "inheritGlobalContext")) {
569
- if (typeof cfg.inheritGlobalContext !== "boolean") return "config.inheritGlobalContext must be a boolean when provided.";
570
- target.inheritGlobalContext = cfg.inheritGlobalContext;
571
- }
572
- if (hasKey(cfg, "inheritSkills")) {
573
- if (typeof cfg.inheritSkills !== "boolean") return "config.inheritSkills must be a boolean when provided.";
574
- target.inheritSkills = cfg.inheritSkills;
575
- }
576
- if (hasKey(cfg, "defaultContext")) {
577
- if (cfg.defaultContext === false || cfg.defaultContext === "") delete target.defaultContext;
578
- else if (cfg.defaultContext === "fresh" || cfg.defaultContext === "fork") target.defaultContext = cfg.defaultContext;
579
- else return "config.defaultContext must be 'fresh', 'fork', or false when provided.";
580
- }
581
- if (hasKey(cfg, "async")) {
582
- if (cfg.async === "") delete target.defaultAsync;
583
- else if (typeof cfg.async === "boolean") target.defaultAsync = cfg.async;
584
- else return "config.async must be a boolean or empty string when provided.";
585
- }
586
- if (hasKey(cfg, "timeoutMs")) {
587
- if (cfg.timeoutMs === false || cfg.timeoutMs === "") delete target.defaultTimeoutMs;
588
- else if (typeof cfg.timeoutMs === "number" && Number.isInteger(cfg.timeoutMs) && cfg.timeoutMs > 0) target.defaultTimeoutMs = cfg.timeoutMs;
589
- else return "config.timeoutMs must be a positive integer or false when provided.";
590
- }
591
- if (hasKey(cfg, "acceptance")) {
592
- if (cfg.acceptance === "") delete target.defaultAcceptance;
593
- else {
594
- const errors = validateAcceptanceInput(cfg.acceptance, "config.acceptance");
595
- if (errors.length > 0) return errors.join(" ");
596
- target.defaultAcceptance = cfg.acceptance as AcceptanceInput;
597
- }
598
- }
599
- if (hasKey(cfg, "acceptanceRole")) {
600
- if (cfg.acceptanceRole === false || cfg.acceptanceRole === "") delete target.acceptanceRole;
601
- else if (cfg.acceptanceRole === "read-only" || cfg.acceptanceRole === "writer") target.acceptanceRole = cfg.acceptanceRole;
602
- else return "config.acceptanceRole must be 'read-only', 'writer', or false when provided.";
603
- }
604
- if (hasKey(cfg, "output")) {
605
- if (cfg.output === false || cfg.output === "") delete target.output;
606
- else if (typeof cfg.output === "string") target.output = cfg.output;
607
- else return "config.output must be a string or false when provided.";
608
- }
609
- if (hasKey(cfg, "outputMode")) {
610
- if (cfg.outputMode === "inline" || cfg.outputMode === "file-only") target.outputMode = cfg.outputMode;
611
- else return "config.outputMode must be 'inline' or 'file-only' when provided.";
612
- }
613
- if (hasKey(cfg, "reads")) {
614
- if (cfg.reads === false || cfg.reads === "") delete target.defaultReads;
615
- else if (typeof cfg.reads === "string") {
616
- const reads = parseCsv(cfg.reads);
617
- if (reads.length) target.defaultReads = reads;
618
- else delete target.defaultReads;
619
- } else return "config.reads must be a comma-separated string or false when provided.";
620
- }
621
- if (hasKey(cfg, "progress")) {
622
- if (typeof cfg.progress !== "boolean") return "config.progress must be a boolean when provided.";
623
- target.defaultProgress = cfg.progress;
624
- }
625
- if (hasKey(cfg, "maxSubagentDepth")) {
626
- if (cfg.maxSubagentDepth === false || cfg.maxSubagentDepth === "") delete target.maxSubagentDepth;
627
- else if (typeof cfg.maxSubagentDepth === "number" && Number.isInteger(cfg.maxSubagentDepth) && cfg.maxSubagentDepth >= 0) {
628
- target.maxSubagentDepth = cfg.maxSubagentDepth;
629
- } else return "config.maxSubagentDepth must be an integer >= 0 or false when provided.";
630
- }
631
- if (hasKey(cfg, "toolBudget")) {
632
- if (cfg.toolBudget === false || cfg.toolBudget === "") delete target.toolBudget;
633
- else {
634
- const validation = validateToolBudgetConfig(cfg.toolBudget, "config.toolBudget");
635
- if (validation.error) return validation.error;
636
- target.toolBudget = cfg.toolBudget as ToolBudgetConfig;
637
- }
638
- }
639
- if (hasKey(cfg, "sandbox")) {
640
- if (typeof cfg.sandbox !== "string") return "config.sandbox must be a non-empty sandbox profile name when provided.";
641
- try {
642
- target.sandbox = validateSandboxProfileName(cfg.sandbox, "config.sandbox");
643
- } catch (error) {
644
- return error instanceof Error ? error.message : String(error);
645
- }
646
- }
647
- if (hasKey(cfg, "permissionProfile")) {
648
- if (typeof cfg.permissionProfile !== "string") return "config.permissionProfile must be a non-empty permission profile name when provided.";
649
- try {
650
- target.permissionProfile = validatePermissionProfileName(cfg.permissionProfile, "config.permissionProfile");
651
- } catch (error) {
652
- return error instanceof Error ? error.message : String(error);
653
- }
654
- }
655
- if (target.runner?.type === "external-cli" || target.runner?.type === "external-job") {
656
- const unsupported = [
657
- target.tools?.length || target.mcpDirectTools?.length ? "tools" : undefined,
658
- target.excludeTools?.length ? "excludeTools" : undefined,
659
- target.model ? "model" : undefined,
660
- target.thinking ? "thinking" : undefined,
661
- target.extensions?.length ? "extensions" : undefined,
662
- target.subagentOnlyExtensions?.length ? "subagentOnlyExtensions" : undefined,
663
- target.mutationTools?.length ? "mutationTools" : undefined,
664
- target.skills?.length || target.skillPath?.length ? "skills" : undefined,
665
- target.maxSubagentDepth !== undefined ? "maxSubagentDepth" : undefined,
666
- target.toolBudget ? "toolBudget" : undefined,
667
- target.sandbox ? "sandbox" : undefined,
668
- target.permissionProfile ? "permissionProfile" : undefined,
669
- ].filter((field): field is string => Boolean(field));
670
- if (unsupported.length > 0) return `config.runner type '${target.runner.type}' does not support Pi-only fields: ${unsupported.join(", ")}.`;
671
- }
672
- return undefined;
673
- }
674
-
675
- function resolveTarget<T extends { name: string; source: AgentSource; filePath: string }>(
676
- name: string,
677
- matches: T[],
678
- cwd: string,
679
- ctx: ManagementContext,
680
- scopeHint?: string,
681
- ): T | AgentToolResult<Details> {
682
- const distinctNames = [...new Set(matches.map((match) => match.name))];
683
- if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${name}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
684
- const mutable = matches.filter((match): match is T & { source: ManagementScope } => isMutableSource(match.source));
685
- if (mutable.length === 0) {
686
- if (matches.length > 0) return result(`Agent '${name}' is read-only and cannot be modified. Create a same-named agent in user or project scope to override it.`, true);
687
- return result(`Agent '${name}' not found. Available: ${availableAgentNames(ctx, cwd).join(", ") || "none"}.`, true);
688
- }
689
- if (mutable.length === 1) return mutable[0]!;
690
- const scope = asDisambiguationScope(scopeHint);
691
- if (!scope) {
692
- const paths = mutable.map((match) => `${match.source}: ${match.filePath}`).join("\n");
693
- return result(`Agent '${name}' exists in both scopes. Specify agentScope: 'user' or 'project'.\n${paths}`, true);
694
- }
695
- const scoped = mutable.filter((match) => match.source === scope);
696
- if (scoped.length === 0) return result(`Agent '${name}' not found in scope '${scope}'.`, true);
697
- if (scoped.length > 1) return result(`Multiple agents named '${name}' found in scope '${scope}': ${scoped.map((match) => match.filePath).join(", ")}`, true);
698
- return scoped[0]!;
699
- }
700
-
701
- function renamePath(currentPath: string, newName: string, scope: ManagementScope, ctx: ManagementContext): { filePath?: string; error?: string } {
702
- if (nameExistsInScope(ctx, scope, newName, currentPath)) return { error: `Name '${newName}' already exists in ${scope} scope.` };
703
- const filePath = path.join(path.dirname(currentPath), `${newName}.md`);
704
- if (fs.existsSync(filePath) && filePath !== currentPath) return { error: `File already exists at ${filePath} but is not a valid agent definition. Remove or rename it first.` };
705
- fs.renameSync(currentPath, filePath);
706
- return { filePath };
707
- }
708
-
709
- function packageSourceLabel(agent: AgentConfig): string {
710
- if (!agent.packageSourceName) return agent.source;
711
- return agent.packageSourceVersion ? `${agent.packageSourceName}@${agent.packageSourceVersion}` : agent.packageSourceName;
712
- }
713
-
714
- type ExternalJobProviderStatus =
715
- | { ok: true; names: Set<string> }
716
- | { ok: false; error: string };
717
-
718
- function errorMessage(error: unknown): string {
719
- return error instanceof Error ? error.message : String(error);
720
- }
721
-
722
- function registeredExternalJobProviderStatus(): ExternalJobProviderStatus {
723
- try {
724
- return { ok: true, names: new Set(listExternalJobProviders().map((provider) => provider.name)) };
725
- } catch (error) {
726
- return { ok: false, error: errorMessage(error) };
727
- }
728
- }
729
-
730
- function externalJobProviderSuffix(provider: string, names: Set<string> | undefined): string {
731
- if (!names) return "?";
732
- return names.has(provider) ? "✓" : "missing";
733
- }
734
-
735
- type ExternalCliAvailabilityByCommand = ReadonlyMap<string, ExternalCliBinaryAvailability>;
736
-
737
- /** A placed agent checks only local ssh; machine catalog and remote CLI validation happen at launch. */
738
- function externalCliAvailabilityKey(command: string, machine: string | undefined): string {
739
- return machine ? `ssh@${machine}` : command;
740
- }
741
-
742
- function externalCliAvailabilityForAgents(agents: readonly AgentConfig[]): ExternalCliAvailabilityByCommand {
743
- const availability = new Map<string, ExternalCliBinaryAvailability>();
744
- for (const agent of agents) {
745
- const runner = agent.runner;
746
- if (runner?.type !== "external-cli") continue;
747
- const key = externalCliAvailabilityKey(runner.command, agent.machine);
748
- if (availability.has(key)) continue;
749
- availability.set(key, resolveExternalCliBinaryAvailability(agent.machine ? "ssh" : runner.command, process.env));
750
- }
751
- return availability;
752
- }
753
-
754
- function runnerListBadge(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability?: ExternalCliAvailabilityByCommand): string | undefined {
755
- if (agent.runner?.type === "external-job") return `external-job:${agent.runner.provider} ${externalJobProviderSuffix(agent.runner.provider, providerNames)}`;
756
- if (agent.runner?.type === "external-cli") {
757
- const placed = agent.machine ? `${agent.runner.command} @ ${agent.machine}` : agent.runner.command;
758
- const availability = externalCliAvailability?.get(externalCliAvailabilityKey(agent.runner.command, agent.machine));
759
- if (!availability) return `external-cli:${placed}`;
760
- if (agent.machine) return `external-cli:${placed} saved Herdr placement; transport ${availability.available ? "✓" : "missing"}; machine not preflighted`;
761
- return `external-cli:${placed} ${availability.available ? "✓" : "missing"}`;
762
- }
763
- if (agent.machine) return `machine: ${agent.machine} (saved Herdr placement)`;
764
- return undefined;
765
- }
766
-
767
- function agentListMetadata(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability?: ExternalCliAvailabilityByCommand): string {
768
- const source = agent.source === "package" ? packageSourceLabel(agent) : agent.source;
769
- return [
770
- source,
771
- runnerListBadge(agent, providerNames, externalCliAvailability),
772
- agent.defaultContext ? `context: ${agent.defaultContext}` : undefined,
773
- agent.aliases?.length ? `aliases: ${agent.aliases.join(", ")}` : undefined,
774
- ].filter((part): part is string => Boolean(part)).join(", ");
775
- }
776
-
777
- function formatAgentListLine(agent: AgentConfig, providerNames: Set<string> | undefined): string {
778
- return `- ${agent.name} (${agentListMetadata(agent, providerNames)}): ${agent.description}`;
779
- }
780
-
781
- function formatAgentCapabilitiesLine(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability?: ExternalCliAvailabilityByCommand): string {
782
- const declaredTools = [
783
- ...(agent.tools ?? []),
784
- ...(agent.mcpDirectTools ?? []).map((tool) => `mcp:${tool}`),
785
- ];
786
- let tools = "none";
787
- if (agent.tools === undefined && agent.mcpDirectTools === undefined) {
788
- tools = "default/ambient";
789
- } else if (declaredTools.length > 0) {
790
- tools = declaredTools.join(", ");
791
- }
792
- if (agent.excludeTools?.length) tools = `${tools}; excludes: ${agent.excludeTools.join(", ")}`;
793
- let model = "inherits current session";
794
- if (agent.model !== undefined) {
795
- model = agent.model;
796
- if (agent.modelProvider && !agent.model.includes("/")) model = `${agent.modelProvider}/${agent.model}`;
797
- }
798
- const thinking = agent.thinking === false ? "off" : agent.thinking ?? "default";
799
- const machine = agent.machine ? `; Machine: ${agent.machine} (saved Herdr placement)` : "";
800
- const acceptance = formatAcceptanceSummary(agent);
801
- return `- ${agent.name} (${agentListMetadata(agent, providerNames, externalCliAvailability)}): Description: ${previewDisplayText(agent.description, 240)}; Tools: ${tools}; Model: ${model}; Thinking: ${thinking}${machine}${acceptance ? `; ${acceptance}` : ""}`;
802
- }
803
-
804
- function formatAcceptanceSummary(agent: AgentConfig): string | undefined {
805
- const policy = agent.defaultAcceptance;
806
- const summary: string[] = [];
807
- if (policy === false) summary.push("Acceptance: disabled");
808
- else if (typeof policy === "string") summary.push(`Acceptance: ${policy}`);
809
- else if (policy) {
810
- const modifiers = [
811
- ...(policy.evidence ?? []),
812
- ...(policy.verify ?? []).map((command) => `verify: ${formatAcceptanceDisplayLabel(command.id)}`),
813
- ...(policy.criteria?.length ? [`criteria: ${policy.criteria.length}`] : []),
814
- ...(policy.stopRules?.length ? [`stopRules: ${policy.stopRules.length}`] : []),
815
- ];
816
- if (policy.review === false) modifiers.push("review: off");
817
- else if (policy.review) {
818
- const displayReview = policy.review.agent
819
- ? { ...policy.review, agent: formatAcceptanceDisplayLabel(policy.review.agent) }
820
- : policy.review;
821
- modifiers.push(`review: ${formatReviewGateLabel(displayReview)}`);
822
- }
823
- if (policy.report) modifiers.push(`report: ${policy.report}`);
824
- summary.push(`Acceptance: ${policy.level ?? "auto"}${modifiers.length > 0 ? ` (${modifiers.join(", ")})` : ""}`);
825
- }
826
- if (agent.acceptanceRole) summary.push(`Acceptance role: ${agent.acceptanceRole}`);
827
- return summary.length > 0 ? summary.join("; ") : undefined;
828
- }
829
-
830
- function formatAcceptanceDisplayLabel(value: string): string {
831
- return JSON.stringify(previewDisplayText(value, 80));
832
- }
833
-
834
- const EXTERNAL_JOB_CAPABILITIES = { stop: false, steer: false, resume: false, structuredOutput: false, toolEvents: false } as const;
835
- const PI_AGENT_RUNNER = { type: "pi" } as const;
836
-
837
- function listOrEmpty<T>(values: T[] | undefined): T[] {
838
- return values ?? [];
839
- }
840
-
841
- function agentCapabilityRunner(agent: AgentConfig, providerNames: Set<string> | undefined, externalCliAvailability: ExternalCliAvailabilityByCommand): AgentCapabilityRow["runner"] {
842
- const runner = agent.runner;
843
- if (!runner || runner.type === "pi") return PI_AGENT_RUNNER;
844
- if (runner.type === "external-cli") {
845
- const availability = externalCliAvailability.get(externalCliAvailabilityKey(runner.command, agent.machine))!;
846
- return {
847
- type: "external-cli",
848
- adapter: runner.adapter,
849
- command: runner.command,
850
- ...(agent.machine ? { machine: agent.machine } : {}),
851
- ...availability,
852
- capabilities: resolveExternalCliRunnerStatus(runner).capabilities,
853
- };
854
- }
855
- return { type: "external-job", provider: runner.provider, available: providerNames?.has(runner.provider), capabilities: EXTERNAL_JOB_CAPABILITIES };
856
- }
857
-
858
- function agentCapabilityTools(agent: AgentConfig): AgentCapabilityRow["tools"] {
859
- return {
860
- ambient: agent.tools === undefined && agent.mcpDirectTools === undefined,
861
- names: listOrEmpty(agent.tools),
862
- ...(agent.excludeTools !== undefined ? { excludeTools: [...agent.excludeTools] } : {}),
863
- mcpDirectTools: listOrEmpty(agent.mcpDirectTools),
864
- mutationTools: agent.mutationTools,
865
- };
866
- }
867
-
868
- function agentCapabilityRow(agent: AgentConfig, options: { executable: boolean; providerNames?: Set<string>; externalCliAvailability: ExternalCliAvailabilityByCommand; restrictionSources?: string[] }): AgentCapabilityRow {
869
- return {
870
- name: agent.name,
871
- description: previewDisplayText(agent.description, 1000),
872
- source: agent.source,
873
- executable: options.executable,
874
- restrictionSources: options.executable ? undefined : options.restrictionSources ?? [],
875
- aliases: agent.aliases ? [...agent.aliases] : undefined,
876
- runner: agentCapabilityRunner(agent, options.providerNames, options.externalCliAvailability),
877
- tools: agentCapabilityTools(agent),
878
- model: presentDetails({ value: agent.model, thinking: agent.thinking }),
879
- execution: presentDetails({ defaultAsync: agent.defaultAsync, timeoutMs: agent.defaultTimeoutMs }),
880
- acceptance: presentDetails({ policy: agent.defaultAcceptance, role: agent.acceptanceRole }),
881
- output: presentDetails({ path: agent.output, mode: agent.outputMode }),
882
- extensions: presentDetails({ names: agent.extensions, subagentOnly: agent.subagentOnlyExtensions, skills: agent.skills }),
883
- };
884
- }
885
-
886
- function agentCapabilitiesSnapshot(input: { agents: AgentConfig[]; restrictedAgents: AgentConfig[]; providerNames?: Set<string>; externalCliAvailability: ExternalCliAvailabilityByCommand; restrictedSources?: string[] }): AgentCapabilitiesSnapshot {
887
- return {
888
- agents: [
889
- ...input.agents.map((agent) => agentCapabilityRow(agent, { executable: true, providerNames: input.providerNames, externalCliAvailability: input.externalCliAvailability })),
890
- ...input.restrictedAgents.map((agent) => agentCapabilityRow(agent, { executable: false, providerNames: input.providerNames, externalCliAvailability: input.externalCliAvailability, restrictionSources: input.restrictedSources })),
891
- ],
892
- restrictedCount: input.restrictedAgents.length,
893
- ...(input.restrictedSources?.length ? { capabilityCeilingSources: [...input.restrictedSources] } : {}),
894
- };
895
- }
896
-
897
- function providerNames(status: ExternalJobProviderStatus): Set<string> | undefined {
898
- return status.ok ? status.names : undefined;
899
- }
900
-
901
- function appendRestrictedAgentLines(input: { lines: string[]; agents: AgentConfig[]; sources?: string[]; providerNames?: Set<string>; formatLine: (agent: AgentConfig, providerNames: Set<string> | undefined) => string }): void {
902
- if (input.agents.length === 0) return;
903
- input.lines.push(
904
- "",
905
- `Restricted agents (not executable in this session${input.sources?.length ? `; capability ceiling: ${input.sources.join(", ")}` : ""}):`,
906
- ...input.agents.map((agent) => input.formatLine(agent, input.providerNames)),
907
- );
908
- }
909
-
910
- function appendExternalJobRegistryLine(lines: string[], agents: AgentConfig[], status: ExternalJobProviderStatus): void {
911
- if (status.ok || !agents.some((agent) => agent.runner?.type === "external-job")) return;
912
- lines.push("", `External-job provider registry unavailable: ${status.error}`);
913
- }
914
-
915
- function appendAgentDiagnosticLines(lines: string[], diagnostics: AgentDiscoveryDiagnostic[] | undefined): void {
916
- if (!diagnostics?.length) return;
917
- lines.push(
918
- "",
919
- "Invalid agent definitions:",
920
- ...diagnostics.map((diagnostic) => `- ${diagnostic.name ?? diagnostic.filePath} (${diagnostic.source}): ${diagnostic.error}`),
921
- );
922
- }
923
-
924
- function agentCapabilityDetails(input: { capabilityMode: boolean; agents: AgentConfig[]; restrictedAgents: AgentConfig[]; providerNames?: Set<string>; externalCliAvailability: ExternalCliAvailabilityByCommand; restrictedSources?: string[] }): Partial<Details> | undefined {
925
- if (!input.capabilityMode) return undefined;
926
- return {
927
- agentCapabilities: jsonDetails(agentCapabilitiesSnapshot({
928
- agents: input.agents,
929
- restrictedAgents: input.restrictedAgents,
930
- providerNames: input.providerNames,
931
- externalCliAvailability: input.externalCliAvailability,
932
- restrictedSources: input.restrictedSources,
933
- })),
934
- };
935
- }
936
-
937
- function formatAgentListSections(
938
- agents: AgentConfig[],
939
- providerNames: Set<string> | undefined,
940
- formatLine: (agent: AgentConfig, providerNames: Set<string> | undefined) => string = formatAgentListLine,
941
- ): string[] {
942
- if (agents.length === 0) return ["- (none)"];
943
- const sections: Array<[AgentSource, string]> = [
944
- ["package", "Package agents"],
945
- ["user", "User agents"],
946
- ["project", "Project agents"],
947
- ["runtime", "Runtime agents"],
948
- ["builtin", "Builtin agents"],
949
- ];
950
- const lines: string[] = [];
951
- for (const [source, label] of sections) {
952
- const matches = agents.filter((agent) => agent.source === source);
953
- if (matches.length === 0) continue;
954
- if (lines.length > 0) lines.push("");
955
- lines.push(label, ...matches.map((agent) => formatLine(agent, providerNames)));
956
- }
957
- return lines;
958
- }
959
-
960
- function formatRunnerDetail(agent: AgentConfig, providerNames: Set<string> | undefined): string | undefined {
961
- if (!agent.runner) return undefined;
962
- if (agent.runner.type === "external-job") return `Runner: external-job via ${agent.runner.provider} ${externalJobProviderSuffix(agent.runner.provider, providerNames)}`;
963
- if (agent.runner.type === "external-cli") return `Runner: external-cli ${agent.runner.command}`;
964
- return `Runner: ${JSON.stringify(agent.runner)}`;
965
- }
966
-
967
- function formatAgentDetail(agent: AgentConfig): string {
968
- const tools = [...(agent.tools ?? []), ...(agent.mcpDirectTools ?? []).map((t) => `mcp:${t}`)];
969
- const providerStatus = registeredExternalJobProviderStatus();
970
- const lines: string[] = [`Agent: ${agent.name} (${agent.source})`, `Path: ${agent.filePath}`, `Description: ${agent.description}`];
971
- if (agent.source === "package" && agent.packageSourceName) {
972
- lines.push(`Source package: ${packageSourceLabel(agent)}`);
973
- if (agent.packageSourceRoot) lines.push(`Package root: ${agent.packageSourceRoot}`);
974
- }
975
- if (agent.packageName) {
976
- lines.push(`Local name: ${frontmatterNameForConfig(agent)}`);
977
- lines.push(`Package: ${agent.packageName}`);
978
- }
979
- if (agent.aliases?.length) lines.push(`Aliases: ${agent.aliases.join(", ")}`);
980
- if (agent.model) lines.push(`Model: ${agent.model}`);
981
- if (tools.length) lines.push(`Tools: ${tools.join(", ")}`);
982
- if (agent.excludeTools?.length) lines.push(`Excluded tools: ${agent.excludeTools.join(", ")}`);
983
- if (agent.skills?.length) lines.push(`Skills: ${agent.skills.join(", ")}`);
984
- if (agent.skillPath?.length) lines.push(`Skill paths: ${agent.skillPath.join(", ")}`);
985
- lines.push(`System prompt mode: ${agent.systemPromptMode}`);
986
- const runnerDetail = formatRunnerDetail(agent, providerStatus.ok ? providerStatus.names : undefined);
987
- if (runnerDetail) {
988
- lines.push(runnerDetail);
989
- if (agent.runner?.type === "external-job" && !providerStatus.ok) lines.push(`External-job provider registry unavailable: ${providerStatus.error}`);
990
- if (agent.runner?.type === "external-job" && agent.runner.options) lines.push(`Runner options: ${JSON.stringify(agent.runner.options)}`);
991
- }
992
- lines.push(`Inherit project context: ${agent.inheritProjectContext ? "true" : "false"}`);
993
- lines.push(`Inherit global context: ${agent.inheritGlobalContext ? "true" : "false"}`);
994
- lines.push(`Inherit skills: ${agent.inheritSkills ? "true" : "false"}`);
995
- if (agent.defaultContext) lines.push(`Default context: ${agent.defaultContext}`);
996
- if (agent.defaultAsync !== undefined) lines.push(`Async: ${agent.defaultAsync ? "true" : "false"}`);
997
- if (agent.defaultTimeoutMs !== undefined) lines.push(`Timeout: ${agent.defaultTimeoutMs}ms`);
998
- if (agent.defaultAcceptance !== undefined) lines.push(`Acceptance: ${typeof agent.defaultAcceptance === "object" ? JSON.stringify(agent.defaultAcceptance) : String(agent.defaultAcceptance)}`);
999
- if (agent.acceptanceRole) lines.push(`Acceptance role: ${agent.acceptanceRole}`);
1000
- if (agent.source === "builtin") lines.push(`Disabled: ${agent.disabled ? "true" : "false"}`);
1001
- if (agent.extensions !== undefined) lines.push(`Extensions: ${agent.extensions.length ? agent.extensions.join(", ") : "(none)"}`);
1002
- if (agent.subagentOnlyExtensions !== undefined) lines.push(`Subagent-only extensions: ${agent.subagentOnlyExtensions.length ? agent.subagentOnlyExtensions.join(", ") : "(none)"}`);
1003
- if (agent.mutationTools !== undefined) lines.push(`Mutation tools: ${agent.mutationTools.length ? agent.mutationTools.join(", ") : "(none)"}`);
1004
- if (agent.thinking) lines.push(`Thinking: ${agent.thinking}`);
1005
- if (agent.output) lines.push(`Output: ${agent.output}`);
1006
- if (agent.outputMode) lines.push(`Output mode: ${agent.outputMode}`);
1007
- if (agent.defaultReads?.length) lines.push(`Reads: ${agent.defaultReads.join(", ")}`);
1008
- if (agent.defaultProgress) lines.push("Progress: true");
1009
- if (agent.maxSubagentDepth !== undefined) lines.push(`Max subagent depth: ${agent.maxSubagentDepth}`);
1010
- if (agent.toolBudget) lines.push(`Tool budget: ${JSON.stringify(agent.toolBudget)}`);
1011
- if (agent.sandbox) lines.push(`Sandbox profile: ${agent.sandbox}`);
1012
- if (agent.permissionProfile) lines.push(`Permission profile: ${agent.permissionProfile}`);
1013
- if (agent.memory) lines.push(`Memory: ${agent.memory.scope} scope, path: ${agent.memory.path}`);
1014
- if (agent.systemPrompt.trim()) lines.push("", "System Prompt:", agent.systemPrompt);
1015
- return lines.join("\n");
1016
- }
1017
-
1018
- export function handleList(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1019
- const scope = normalizeListScope(params.agentScope) ?? "both";
1020
- const d = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
1021
- let scopedAgents = effectiveAgentsForScope(scope, d, ctx.runtimeAgentOwner, ctx.model?.provider);
1022
- scopedAgents = scopedAgents
1023
- .sort((a, b) => a.name.localeCompare(b.name));
1024
- const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
1025
- const visibleAgents = scopedAgents.filter((a) => !a.disabled);
1026
- const agents = visibleAgents.filter((a) => isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
1027
- const restrictedAgents = visibleAgents.filter((a) => !isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
1028
- const restrictedSources = capabilityCeilingAgentRestrictionSources(capabilityCeiling);
1029
- const proactiveSuggestions = buildProactiveSkillSubagentRecommendationLines({
1030
- agents,
1031
- ...(ctx.config?.proactiveSkillSubagents !== undefined ? { config: ctx.config.proactiveSkillSubagents } : {}),
1032
- discoverAvailableSkills: () => discoverAvailableSkills(ctx.cwd),
1033
- });
1034
- const providerStatus = registeredExternalJobProviderStatus();
1035
- const providerNameSet = providerNames(providerStatus);
1036
- const capabilityMode = params.capabilities === true;
1037
- const externalCliAvailability = capabilityMode ? externalCliAvailabilityForAgents([...agents, ...restrictedAgents]) : undefined;
1038
- const formatLine = capabilityMode
1039
- ? (agent: AgentConfig, names: Set<string> | undefined) => formatAgentCapabilitiesLine(agent, names, externalCliAvailability)
1040
- : formatAgentListLine;
1041
- const lines = [
1042
- capabilityMode ? "Executable agents (capabilities):" : "Executable agents:",
1043
- ...formatAgentListSections(agents, providerNameSet, formatLine),
1044
- ];
1045
- appendRestrictedAgentLines({ lines, agents: restrictedAgents, sources: restrictedSources, providerNames: providerNameSet, formatLine });
1046
- appendExternalJobRegistryLine(lines, [...agents, ...restrictedAgents], providerStatus);
1047
- appendAgentDiagnosticLines(lines, d.agentDiagnostics);
1048
- if (proactiveSuggestions.length) lines.push("", ...proactiveSuggestions);
1049
- return result(lines.join("\n"), false, agentCapabilityDetails({
1050
- capabilityMode,
1051
- agents,
1052
- restrictedAgents,
1053
- providerNames: providerNameSet,
1054
- externalCliAvailability: externalCliAvailability ?? new Map(),
1055
- restrictedSources,
1056
- }));
1057
- }
1058
-
1059
- function formatModelSource(agent: AgentConfig, currentModel: ParentModel | undefined): string {
1060
- if (agent.override && agent.model !== agent.override.base.model) {
1061
- return `${agent.override.scope} override`;
1062
- }
1063
- if (agent.modelSource?.type === "subagents.defaultModel" && agent.model === agent.modelSource.model) {
1064
- return `${agent.modelSource.scope} defaultModel`;
1065
- }
1066
- if (agent.model) return `${agent.source} agent config`;
1067
- if (currentModel) return "inherits current session model";
1068
- return "inherit requested, but no current session model is available";
1069
- }
1070
-
1071
- function handleModels(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1072
- const requestedAgent = params.agent?.trim();
1073
- const scope = normalizeListScope(params.agentScope);
1074
- if (!scope) return result("agentScope must be 'user', 'project', or 'both' for models.", true);
1075
-
1076
- const discovered = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
1077
- const effectiveAgents = effectiveAgentsForScope(scope, discovered, ctx.runtimeAgentOwner, ctx.model?.provider)
1078
- .sort((a, b) => a.name.localeCompare(b.name));
1079
- const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
1080
- const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined;
1081
- const preferredProvider = ctx.model?.provider;
1082
- const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.currentSessionId);
1083
-
1084
- let selectedAgents = effectiveAgents;
1085
- if (requestedAgent) {
1086
- const matches = findAgentsInDiscovery(requestedAgent, discovered, scope, ctx.runtimeAgentOwner, ctx.model?.provider);
1087
- const diagnostics = diagnosticsForScope(discovered.agentDiagnostics, scope);
1088
- const normalizedName = sanitizeName(requestedAgent);
1089
- const diagnostic = findBlockingAgentDiagnostic(requestedAgent, matches, diagnostics)
1090
- ?? (normalizedName !== requestedAgent ? findBlockingAgentDiagnostic(normalizedName, matches, diagnostics) : undefined);
1091
- if (diagnostic) return result(`Agent '${params.agent}' has invalid configuration: ${diagnostic.error}`, true);
1092
- const distinctNames = [...new Set(matches.map((agent) => agent.name))];
1093
- if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${params.agent}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
1094
- if (!matches.length) {
1095
- return result(`Agent '${params.agent}' not found. Available: ${availableAgentNamesFromDiscovery(discovered, ctx.runtimeAgentOwner, ctx.model?.provider).join(", ") || "none"}.`, true);
1096
- }
1097
- selectedAgents = [matches[0]!];
1098
- }
1099
-
1100
- const lines = [
1101
- requestedAgent ? "Subagent model" : "Subagent models",
1102
- "",
1103
- ...(requestedAgent ? [] : [
1104
- "Current session model:",
1105
- ` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`,
1106
- "",
1107
- ]),
1108
- ];
1109
-
1110
- const modelEntries = selectedAgents.flatMap((agent) => requestedAgent
1111
- ? [{ agent, name: requestedAgent }]
1112
- : [{ agent, name: agent.name }, ...(agent.aliases ?? []).map((name) => ({ agent, name }))]);
1113
- for (const { agent, name } of modelEntries) {
1114
- const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider);
1115
- const effectiveThinking = resolveEffectiveThinking(resolvedModel, agent.thinking)
1116
- ?? (agent.thinking === false ? "off" : undefined);
1117
- const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}${isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling) ? "" : "; restricted"}`;
1118
- if (requestedAgent) {
1119
- lines.push(`Agent: ${requestedAgent}`);
1120
- lines.push("Effective model:");
1121
- lines.push(` ${resolvedModel ?? "(unresolved)"}`);
1122
- lines.push(`Source: ${source}`);
1123
- lines.push(`Thinking: ${effectiveThinking ?? "default"}`);
1124
- if (agent.override) {
1125
- lines.push("Override file:");
1126
- lines.push(` ${agent.override.path}`);
1127
- }
1128
- if (agent.model && resolvedModel && agent.model !== resolvedModel) {
1129
- lines.push("Requested model setting:");
1130
- lines.push(` ${agent.model}`);
1131
- }
1132
- if (agent.disabled) lines.push("Disabled: true");
1133
- if (!isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling)) lines.push("Restricted: true");
1134
- lines.push("Current session model:");
1135
- lines.push(` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`);
1136
- break;
1137
- }
1138
- lines.push(name);
1139
- lines.push(" model:");
1140
- lines.push(` ${resolvedModel ?? "(unresolved)"}`);
1141
- lines.push(` source: ${source}`);
1142
- lines.push(` thinking: ${effectiveThinking ?? "default"}`);
1143
- if (agent.override) {
1144
- lines.push(" override file:");
1145
- lines.push(` ${agent.override.path}`);
1146
- }
1147
- if (agent.model && resolvedModel && agent.model !== resolvedModel) {
1148
- lines.push(" requested model setting:");
1149
- lines.push(` ${agent.model}`);
1150
- }
1151
- lines.push("");
1152
- }
1153
-
1154
- const availableFullIds = availableModels.map((m) => m.fullId).sort();
1155
- if (!requestedAgent && availableFullIds.length > 0) {
1156
- lines.push("Available models in this session's registry (copy an exact provider/id when passing model):");
1157
- lines.push("");
1158
- const shown = availableFullIds.slice(0, 80);
1159
- for (const fullId of shown) lines.push(` ${fullId}`);
1160
- if (availableFullIds.length > shown.length) lines.push(` ... and ${availableFullIds.length - shown.length} more`);
1161
- lines.push("");
1162
- lines.push("Use an exact provider/id from this list when you pass model; bare ids resolve only when unique in the registry.");
1163
- }
1164
- if (!requestedAgent) appendAgentDiagnosticLines(lines, diagnosticsForScope(discovered.agentDiagnostics, scope));
1165
- return result(lines.join("\n"));
1166
- }
1167
-
1168
- function handleGet(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1169
- if (!params.agent) return result("Specify 'agent' for get.", true);
1170
- const scope = normalizeListScope(params.agentScope);
1171
- if (!scope) return result("agentScope must be 'user', 'project', or 'both' for get.", true);
1172
- const discovered = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
1173
- const matches = findAgentsInDiscovery(params.agent, discovered, scope);
1174
- const diagnostics = diagnosticsForScope(discovered.agentDiagnostics, scope);
1175
- const rawName = params.agent.trim();
1176
- const normalizedName = sanitizeName(rawName);
1177
- const diagnostic = findBlockingAgentDiagnostic(rawName, matches, diagnostics)
1178
- ?? (normalizedName !== rawName ? findBlockingAgentDiagnostic(normalizedName, matches, diagnostics) : undefined);
1179
- if (diagnostic) return result(`Agent '${params.agent}' has invalid configuration: ${diagnostic.error}`, true);
1180
- const distinctNames = [...new Set(matches.map((agent) => agent.name))];
1181
- if (distinctNames.length > 1) return result(`Ambiguous agent alias or name '${params.agent}': ${distinctNames.sort((a, b) => a.localeCompare(b)).join(", ")}`, true);
1182
- if (!matches.length) {
1183
- return result(`Agent '${params.agent}' not found. Available: ${availableAgentNamesFromDiscovery(discovered).join(", ") || "none"}.`, true);
1184
- }
1185
- return result(matches.map(formatAgentDetail).join("\n\n"));
1186
- }
1187
-
1188
- export function handleCreate(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1189
- const parsedConfig = configObject(params.config);
1190
- if (parsedConfig.status === "error") return result(parsedConfig.message, true);
1191
- if (parsedConfig.status === "missing") return result("config required for create.", true);
1192
- const cfg = parsedConfig.value;
1193
- if (typeof cfg.name !== "string" || !cfg.name.trim()) return result("config.name is required and must be a non-empty string.", true);
1194
- if (typeof cfg.description !== "string" || !cfg.description.trim()) return result("config.description is required and must be a non-empty string.", true);
1195
- const name = sanitizeName(cfg.name);
1196
- if (!name) return result("config.name is invalid after sanitization. Use letters, numbers, spaces, or hyphens.", true);
1197
- const parsedPackage = parsePackageConfig(cfg.package);
1198
- if (parsedPackage.error) return result(parsedPackage.error, true);
1199
- const runtimeName = buildRuntimeName(name, parsedPackage.packageName);
1200
- const scopeRaw = cfg.scope ?? "user";
1201
- if (scopeRaw !== "user" && scopeRaw !== "project") return result("config.scope must be 'user' or 'project'.", true);
1202
- const scope = scopeRaw;
1203
- if (hasKey(cfg, "steps")) return result("Durable chain definitions were removed; use a workflow script or /prompt-workflow for repeatable workflows.", true);
1204
- const d = discoverCatalog(ctx);
1205
- const projectConfigDir = getProjectConfigDir(ctx.cwd);
1206
- const targetDir = scope === "user" ? d.userDir : d.projectDir ?? path.join(projectConfigDir, "agents");
1207
- fs.mkdirSync(targetDir, { recursive: true });
1208
- if (nameExistsInScope(ctx, scope, runtimeName)) return result(`Name '${runtimeName}' already exists in ${scope} scope. Use update instead.`, true);
1209
- const targetPath = path.join(targetDir, `${runtimeName}.md`);
1210
- if (fs.existsSync(targetPath)) return result(`File already exists at ${targetPath} but is not a valid agent definition. Remove or rename it first.`, true);
1211
- const warnings: string[] = [];
1212
- if (d.builtin.some((a) => a.name === runtimeName)) warnings.push(`Note: this shadows the builtin agent '${runtimeName}'.`);
1213
- const agent: AgentConfig = {
1214
- name: runtimeName,
1215
- localName: name,
1216
- ...(parsedPackage.packageName !== undefined ? { packageName: parsedPackage.packageName } : {}),
1217
- description: cfg.description.trim(),
1218
- source: scope,
1219
- filePath: targetPath,
1220
- systemPrompt: "",
1221
- systemPromptMode: defaultSystemPromptMode(name),
1222
- inheritProjectContext: defaultInheritProjectContext(name),
1223
- inheritGlobalContext: false,
1224
- inheritSkills: defaultInheritSkills(),
1225
- };
1226
- const applyError = applyAgentConfig(agent, cfg);
1227
- if (applyError) return result(applyError, true);
1228
- const profileError = validateCodeOwnedProfileRunner(agent);
1229
- if (profileError) return result(profileError, true);
1230
- const mw = modelWarning(ctx, agent.model);
1231
- if (mw) warnings.push(mw);
1232
- const sw = skillsWarning(ctx.cwd, agent);
1233
- if (sw) warnings.push(sw);
1234
- fs.writeFileSync(targetPath, serializeAgent(agent), "utf-8");
1235
- ctx.onAgentsChanged?.();
1236
- return result([`Created agent '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
1237
- }
1238
-
1239
- export function handleUpdate(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1240
- if (!params.agent) return result("Specify 'agent' for update.", true);
1241
- const parsedConfig = configObject(params.config);
1242
- if (parsedConfig.status === "error") return result(parsedConfig.message, true);
1243
- if (parsedConfig.status === "missing") return result("config required for update.", true);
1244
- const cfg = parsedConfig.value;
1245
- if (hasKey(cfg, "steps")) return result("Durable chain definitions were removed; use a workflow script or /prompt-workflow for repeatable workflows.", true);
1246
- const warnings: string[] = [];
1247
- const scopeHint = asDisambiguationScope(params.agentScope);
1248
- const targetOrError = resolveTarget(params.agent, findAgents(params.agent, ctx, scopeHint ?? "both"), ctx.cwd, ctx, scopeHint);
1249
- if ("content" in targetOrError) return targetOrError;
1250
- const target = targetOrError;
1251
- if (target.source !== "user" && target.source !== "project") return result(`Cannot update ${target.source} agent '${target.name}'. Eject it to user or project scope first.`, true);
1252
- let updated: AgentConfig;
1253
- try {
1254
- updated = editableAgentConfig(target);
1255
- } catch (error) {
1256
- const message = error instanceof Error ? error.message : String(error);
1257
- return result(`Could not reread agent definition ${target.filePath} before updating '${target.name}': ${message}`, true);
1258
- }
1259
- const oldName = target.name;
1260
- if (hasKey(cfg, "name") && (typeof cfg.name !== "string" || !cfg.name.trim())) return result("config.name must be a non-empty string when provided.", true);
1261
- if (hasKey(cfg, "description") && (typeof cfg.description !== "string" || !cfg.description.trim())) return result("config.description must be a non-empty string when provided.", true);
1262
- let newLocalName = target.localName ?? frontmatterNameForConfig(target);
1263
- if (hasKey(cfg, "name")) {
1264
- newLocalName = sanitizeName(cfg.name as string);
1265
- if (!newLocalName) return result("config.name is invalid after sanitization.", true);
1266
- }
1267
- let newPackageName = target.packageName;
1268
- if (hasKey(cfg, "package")) {
1269
- const parsedPackage = parsePackageConfig(cfg.package);
1270
- if (parsedPackage.error) return result(parsedPackage.error, true);
1271
- newPackageName = parsedPackage.packageName;
1272
- }
1273
- const applyError = applyAgentConfig(updated, cfg);
1274
- if (applyError) return result(applyError, true);
1275
- const preserveFrontmatterFields = preservedAgentFrontmatterFields(target, cfg);
1276
- updated.localName = newLocalName;
1277
- if (newPackageName !== undefined) updated.packageName = newPackageName;
1278
- else delete updated.packageName;
1279
- updated.name = buildRuntimeName(newLocalName, newPackageName);
1280
- const profileError = validateCodeOwnedProfileRunner(updated);
1281
- if (profileError) return result(profileError, true);
1282
- if (hasKey(cfg, "description")) updated.description = (cfg.description as string).trim();
1283
- if (hasKey(cfg, "model")) {
1284
- const mw = modelWarning(ctx, updated.model);
1285
- if (mw) warnings.push(mw);
1286
- }
1287
- if (hasKey(cfg, "skills") || hasKey(cfg, "skillPath")) {
1288
- const sw = skillsWarning(ctx.cwd, updated);
1289
- if (sw) warnings.push(sw);
1290
- }
1291
- if (updated.name !== oldName) {
1292
- const renamed = renamePath(target.filePath, updated.name, target.source, ctx);
1293
- if (renamed.error) return result(renamed.error, true);
1294
- updated.filePath = renamed.filePath!;
1295
- }
1296
- fs.writeFileSync(updated.filePath, serializeAgent(updated, { preserveFrontmatterFields }), "utf-8");
1297
- ctx.onAgentsChanged?.();
1298
- const headline = updated.name === oldName
1299
- ? `Updated agent '${updated.name}' at ${updated.filePath}.`
1300
- : `Updated agent '${oldName}' to '${updated.name}' at ${updated.filePath}.`;
1301
- return result([headline, ...warnings].join("\n"));
1302
- }
1303
-
1304
- function handleDelete(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1305
- if (!params.agent) return result("Specify 'agent' for delete.", true);
1306
- const scopeHint = asDisambiguationScope(params.agentScope);
1307
- const targetOrError = resolveTarget(params.agent, findAgents(params.agent, ctx, scopeHint ?? "both"), ctx.cwd, ctx, scopeHint);
1308
- if ("content" in targetOrError) return targetOrError;
1309
- const target = targetOrError;
1310
- fs.unlinkSync(target.filePath);
1311
- ctx.onAgentsChanged?.();
1312
- return result(`Deleted agent '${target.name}' at ${target.filePath}.`);
1313
- }
1314
-
1315
- function handleEject(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1316
- if (!params.agent) return result("Specify 'agent' for eject.", true);
1317
- const parsedScope = actionScope(params.agentScope, "eject");
1318
- if (parsedScope.error) return parsedScope.error;
1319
- const scope = parsedScope.scope!;
1320
- const ejected = ejectAgentDefinition({
1321
- cwd: ctx.cwd,
1322
- agent: params.agent,
1323
- scope,
1324
- // Preserve the existing management-action behavior. Direct public callers
1325
- // must supply affirmative project trust themselves.
1326
- ...(scope === "project" ? { projectTrusted: true } : {}),
1327
- });
1328
- if (ejected.ok) ctx.onAgentsChanged?.();
1329
- return result(ejected.message, !ejected.ok);
1330
- }
1331
-
1332
- function handleDisable(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1333
- if (!params.agent) return result("Specify 'agent' for disable.", true);
1334
- const raw = params.agent.trim();
1335
- const parsedScope = actionScope(params.agentScope, "disable");
1336
- if (parsedScope.error) return parsedScope.error;
1337
- const scope = parsedScope.scope!;
1338
- const d = discoverCatalog(ctx);
1339
- if (scope === "project" && d.projectSettingsPath === null) {
1340
- return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
1341
- }
1342
- const effective = resolveEffectiveAgent(d, raw);
1343
- if (effective.error) return result(effective.error, true);
1344
- if (!effective.agent) {
1345
- return result(`Agent '${raw}' not found. Available: ${availableAgentNames(ctx).join(", ") || "none"}.`, true);
1346
- }
1347
- const runtimeName = effective.agent.name;
1348
- const settingsPath = mergeBuiltinAgentOverride(ctx.cwd, runtimeName, scope, { disabled: true });
1349
- const after = resolveEffectiveAgent(discoverCatalog(ctx), raw).agent;
1350
- if (after?.disabled === true) {
1351
- ctx.onAgentsChanged?.();
1352
- return result(`Disabled agent '${runtimeName}' via ${scope} settings override at ${settingsPath}. It is now hidden from runtime discovery and { action: "list" }.`);
1353
- }
1354
- return result(`Wrote a disabled override for '${runtimeName}' at ${settingsPath}, but the agent is still enabled. A higher-precedence ${after?.override?.scope ?? "project"} override is likely winning. Try agentScope: '${after?.override?.scope ?? "project"}'.`, true);
1355
- }
1356
-
1357
- function handleEnable(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1358
- if (!params.agent) return result("Specify 'agent' for enable.", true);
1359
- const raw = params.agent.trim();
1360
- const parsedScope = actionScope(params.agentScope, "enable");
1361
- if (parsedScope.error) return parsedScope.error;
1362
- const scope = parsedScope.scope!;
1363
- const d = discoverCatalog(ctx);
1364
- if (scope === "project" && d.projectSettingsPath === null) {
1365
- return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
1366
- }
1367
- const effective = resolveEffectiveAgent(d, raw);
1368
- if (effective.error) return result(effective.error, true);
1369
- if (!effective.agent) {
1370
- return result(`Agent '${raw}' not found. Available: ${availableAgentNames(ctx).join(", ") || "none"}.`, true);
1371
- }
1372
- const runtimeName = effective.agent.name;
1373
- const { path: settingsPath, removed } = removeBuiltinAgentOverrideFields(ctx.cwd, runtimeName, scope, ["disabled"]);
1374
- const after = resolveEffectiveAgent(discoverCatalog(ctx), raw).agent;
1375
- if (after && after.disabled !== true) {
1376
- if (removed) ctx.onAgentsChanged?.();
1377
- if (removed) return result(`Enabled agent '${runtimeName}' (removed disabled override at ${settingsPath}).`);
1378
- return result(`Agent '${runtimeName}' is already enabled.`);
1379
- }
1380
- if (after?.override?.scope && after.override.scope !== scope) {
1381
- return result(`Agent '${runtimeName}' is still disabled via a ${after.override.scope} scope override at ${after.override.path}. Specify agentScope: '${after.override.scope}' to enable it.`, true);
1382
- }
1383
- return result(`Agent '${runtimeName}' is still disabled after removing the ${scope} disabled override. It may be hidden via subagents.disableBuiltins in ${after?.override?.scope ?? scope} settings at ${after?.override?.path ?? settingsPath}.`, true);
1384
- }
1385
-
1386
- function handleReset(params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1387
- if (!params.agent) return result("Specify 'agent' for reset.", true);
1388
- const raw = params.agent.trim();
1389
- const sanitized = sanitizeName(raw);
1390
- const parsedScope = actionScope(params.agentScope, "reset");
1391
- if (parsedScope.error) return parsedScope.error;
1392
- const scope = parsedScope.scope!;
1393
- const d = discoverCatalog(ctx);
1394
- if (scope === "project" && d.projectSettingsPath === null) {
1395
- return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
1396
- }
1397
- const bundled = [...d.package, ...d.builtin].find((a) => a.name === raw || a.name === sanitized);
1398
- if (!bundled) {
1399
- const custom = [...d.user, ...d.project].find((a) => a.name === raw || a.name === sanitized);
1400
- if (custom) {
1401
- return result(`Agent '${raw}' has no bundled default to reset to. Use { action: "delete", agent: "${custom.name}" } to remove the custom ${custom.source} agent.`, true);
1402
- }
1403
- return result(`Agent '${raw}' not found. Available: ${availableAgentNames(ctx).join(", ") || "none"}.`, true);
1404
- }
1405
- const runtimeName = bundled.name;
1406
- const custom = (scope === "user" ? d.user : d.project).find((a) => a.name === raw || a.name === sanitized);
1407
- const lines: string[] = [];
1408
- if (custom) {
1409
- fs.unlinkSync(custom.filePath);
1410
- lines.push(`Deleted custom ${scope} agent file at ${custom.filePath}.`);
1411
- }
1412
- const overrideRemoval = removeBuiltinAgentOverride(ctx.cwd, runtimeName, scope, { preserveMachine: true });
1413
- if (overrideRemoval.removed) lines.push(`${overrideRemoval.machinePreserved ? "Cleared customization in" : "Removed"} ${scope} settings override at ${overrideRemoval.path}.${overrideRemoval.machinePreserved ? " Retained machine placement." : ""}`);
1414
- if (lines.length === 0) {
1415
- const otherScope = scope === "user" ? "project" : "user";
1416
- const otherCustom = (otherScope === "user" ? d.user : d.project).find((a) => a.name === raw || a.name === sanitized);
1417
- const hasOtherOverride = bundled.override?.scope === otherScope;
1418
- const note = (otherCustom || hasOtherOverride)
1419
- ? ` Customization exists in ${otherScope} scope; specify agentScope: '${otherScope}' to reset it.`
1420
- : "";
1421
- return result(`Agent '${runtimeName}' has no ${scope} customization to reset.${note} It is at its bundled ${bundled.source} default.`);
1422
- }
1423
- lines.push(`Reset agent '${runtimeName}' to its bundled ${bundled.source} default.`);
1424
- ctx.onAgentsChanged?.();
1425
- return result(lines.join("\n"));
1426
- }
1427
-
1428
- export function handleManagementAction(action: string, params: ManagementParams, ctx: ManagementContext): AgentToolResult<Details> {
1429
- switch (action) {
1430
- case "list": return handleList(params, ctx);
1431
- case "get": return handleGet(params, ctx);
1432
- case "models": return handleModels(params, ctx);
1433
- case "create": return handleCreate(params, ctx);
1434
- case "update": return handleUpdate(params, ctx);
1435
- case "delete": return handleDelete(params, ctx);
1436
- case "eject": return handleEject(params, ctx);
1437
- case "disable": return handleDisable(params, ctx);
1438
- case "enable": return handleEnable(params, ctx);
1439
- case "reset": return handleReset(params, ctx);
1440
- default: return result(`Unknown action: ${action}`, true);
1441
- }
1442
- }