pi-subagents 0.69.0 → 0.70.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1443) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +1 -1
  3. package/agents/claude-code-writer.md +1 -0
  4. package/agents/codex-exec-writer.md +1 -0
  5. package/agents/cursor-agent-writer.md +1 -0
  6. package/agents/reviewer.md +3 -2
  7. package/agents/worker.md +1 -0
  8. package/docs/agents.md +12 -9
  9. package/docs/configuration.md +3 -1
  10. package/docs/extension-api.md +3 -1
  11. package/docs/models.md +4 -2
  12. package/docs/observability.md +7 -1
  13. package/docs/standalone-background.md +4 -4
  14. package/docs/tool-reference.md +3 -7
  15. package/docs/watchdog.md +2 -0
  16. package/docs/workflows.md +6 -2
  17. package/index.d.ts +3 -0
  18. package/index.d.ts.map +1 -0
  19. package/index.js +10 -0
  20. package/index.js.map +1 -0
  21. package/inspector-runner.mjs +1 -1
  22. package/package.json +89 -73
  23. package/runner-peer-loader.mjs +4 -7
  24. package/runner-peer-preload.mjs +5 -7
  25. package/skills/pi-subagents/SKILL.md +1 -0
  26. package/skills/pi-subagents/references/management-authoring-rpc.md +1 -1
  27. package/skills/pi-subagents/references/multi-lane-orchestration.md +8 -0
  28. package/skills/pi-subagents/references/prompting-and-roles.md +16 -15
  29. package/src/agents/advertised-agent-prompt.d.ts +8 -0
  30. package/src/agents/advertised-agent-prompt.d.ts.map +1 -0
  31. package/src/agents/advertised-agent-prompt.js +77 -0
  32. package/src/agents/advertised-agent-prompt.js.map +1 -0
  33. package/src/agents/agent-management.d.ts +27 -0
  34. package/src/agents/agent-management.d.ts.map +1 -0
  35. package/src/agents/agent-management.js +1514 -0
  36. package/src/agents/agent-management.js.map +1 -0
  37. package/src/agents/agent-memory.d.ts +49 -0
  38. package/src/agents/agent-memory.d.ts.map +1 -0
  39. package/src/agents/agent-memory.js +349 -0
  40. package/src/agents/agent-memory.js.map +1 -0
  41. package/src/agents/agent-refinements.d.ts +100 -0
  42. package/src/agents/agent-refinements.d.ts.map +1 -0
  43. package/src/agents/agent-refinements.js +569 -0
  44. package/src/agents/agent-refinements.js.map +1 -0
  45. package/src/agents/agent-scope.d.ts +3 -0
  46. package/src/agents/agent-scope.d.ts.map +1 -0
  47. package/src/agents/agent-scope.js +6 -0
  48. package/src/agents/agent-scope.js.map +1 -0
  49. package/src/agents/agent-selection.d.ts +3 -0
  50. package/src/agents/agent-selection.d.ts.map +1 -0
  51. package/src/agents/agent-selection.js +23 -0
  52. package/src/agents/agent-selection.js.map +1 -0
  53. package/src/agents/agent-serializer.d.ts +8 -0
  54. package/src/agents/agent-serializer.d.ts.map +1 -0
  55. package/src/agents/agent-serializer.js +196 -0
  56. package/src/agents/agent-serializer.js.map +1 -0
  57. package/src/agents/agents.d.ts +326 -0
  58. package/src/agents/agents.d.ts.map +1 -0
  59. package/src/agents/agents.js +2639 -0
  60. package/src/agents/agents.js.map +1 -0
  61. package/src/agents/builtin-names.d.ts +2 -0
  62. package/src/agents/builtin-names.d.ts.map +1 -0
  63. package/src/agents/builtin-names.js +17 -0
  64. package/src/agents/builtin-names.js.map +1 -0
  65. package/src/agents/chain-serializer.d.ts +7 -0
  66. package/src/agents/chain-serializer.d.ts.map +1 -0
  67. package/src/agents/chain-serializer.js +319 -0
  68. package/src/agents/chain-serializer.js.map +1 -0
  69. package/src/agents/frontmatter.d.ts +16 -0
  70. package/src/agents/frontmatter.d.ts.map +1 -0
  71. package/src/agents/frontmatter.js +142 -0
  72. package/src/agents/frontmatter.js.map +1 -0
  73. package/src/agents/identity.d.ts +8 -0
  74. package/src/agents/identity.d.ts.map +1 -0
  75. package/src/agents/identity.js +30 -0
  76. package/src/agents/identity.js.map +1 -0
  77. package/src/agents/proactive-skills.d.ts +35 -0
  78. package/src/agents/proactive-skills.d.ts.map +1 -0
  79. package/src/agents/proactive-skills.js +154 -0
  80. package/src/agents/proactive-skills.js.map +1 -0
  81. package/src/agents/runtime-agent-events.d.ts +27 -0
  82. package/src/agents/runtime-agent-events.d.ts.map +1 -0
  83. package/src/agents/runtime-agent-events.js +53 -0
  84. package/src/agents/runtime-agent-events.js.map +1 -0
  85. package/src/agents/runtime-agent-registry.d.ts +64 -0
  86. package/src/agents/runtime-agent-registry.d.ts.map +1 -0
  87. package/src/agents/runtime-agent-registry.js +395 -0
  88. package/src/agents/runtime-agent-registry.js.map +1 -0
  89. package/src/agents/skills.d.ts +33 -0
  90. package/src/agents/skills.d.ts.map +1 -0
  91. package/src/agents/skills.js +685 -0
  92. package/src/agents/skills.js.map +1 -0
  93. package/src/api/agents.d.ts +5 -0
  94. package/src/api/agents.d.ts.map +1 -0
  95. package/src/api/agents.js +3 -0
  96. package/src/api/agents.js.map +1 -0
  97. package/src/api/background-work.d.ts +39 -0
  98. package/src/api/background-work.d.ts.map +1 -0
  99. package/src/api/background-work.js +165 -0
  100. package/src/api/background-work.js.map +1 -0
  101. package/src/api/capability-ceiling.d.ts +2 -0
  102. package/src/api/capability-ceiling.d.ts.map +1 -0
  103. package/src/api/capability-ceiling.js +2 -0
  104. package/src/api/capability-ceiling.js.map +1 -0
  105. package/src/api/child-tool-plan.d.ts +2 -0
  106. package/src/api/child-tool-plan.d.ts.map +1 -0
  107. package/src/api/child-tool-plan.js +2 -0
  108. package/src/api/child-tool-plan.js.map +1 -0
  109. package/src/api/control-channel.d.ts +2 -0
  110. package/src/api/control-channel.d.ts.map +1 -0
  111. package/src/api/control-channel.js +2 -0
  112. package/src/api/control-channel.js.map +1 -0
  113. package/src/api/delegation.d.ts +99 -0
  114. package/src/api/delegation.d.ts.map +1 -0
  115. package/src/api/delegation.js +9 -0
  116. package/src/api/delegation.js.map +1 -0
  117. package/src/api/external-job-provider.d.ts +58 -0
  118. package/src/api/external-job-provider.d.ts.map +1 -0
  119. package/src/api/external-job-provider.js +140 -0
  120. package/src/api/external-job-provider.js.map +1 -0
  121. package/src/api/external-runs.d.ts +48 -0
  122. package/src/api/external-runs.d.ts.map +1 -0
  123. package/src/api/external-runs.js +245 -0
  124. package/src/api/external-runs.js.map +1 -0
  125. package/src/api/intercom-bridge.d.ts +2 -0
  126. package/src/api/intercom-bridge.d.ts.map +1 -0
  127. package/src/api/intercom-bridge.js +2 -0
  128. package/src/api/intercom-bridge.js.map +1 -0
  129. package/src/api/preflight.d.ts +173 -0
  130. package/src/api/preflight.d.ts.map +1 -0
  131. package/src/api/preflight.js +362 -0
  132. package/src/api/preflight.js.map +1 -0
  133. package/src/api/project-panes.d.ts +8 -0
  134. package/src/api/project-panes.d.ts.map +1 -0
  135. package/src/api/project-panes.js +8 -0
  136. package/src/api/project-panes.js.map +1 -0
  137. package/src/api/required-child-extensions.d.ts +2 -0
  138. package/src/api/required-child-extensions.d.ts.map +1 -0
  139. package/src/api/required-child-extensions.js +2 -0
  140. package/src/api/required-child-extensions.js.map +1 -0
  141. package/src/api/shared-types.d.ts +2 -0
  142. package/src/api/shared-types.d.ts.map +1 -0
  143. package/src/api/shared-types.js +2 -0
  144. package/src/api/shared-types.js.map +1 -0
  145. package/src/api/workflow-resources.d.ts +3 -0
  146. package/src/api/workflow-resources.d.ts.map +1 -0
  147. package/src/api/workflow-resources.js +2 -0
  148. package/src/api/workflow-resources.js.map +1 -0
  149. package/src/extension/config.d.ts +8 -0
  150. package/src/extension/config.d.ts.map +1 -0
  151. package/src/extension/config.js +245 -0
  152. package/src/extension/config.js.map +1 -0
  153. package/src/extension/control-notices.d.ts +19 -0
  154. package/src/extension/control-notices.d.ts.map +1 -0
  155. package/src/extension/control-notices.js +34 -0
  156. package/src/extension/control-notices.js.map +1 -0
  157. package/src/extension/doctor.d.ts +33 -0
  158. package/src/extension/doctor.d.ts.map +1 -0
  159. package/src/extension/doctor.js +231 -0
  160. package/src/extension/doctor.js.map +1 -0
  161. package/src/extension/fanout-child.d.ts +7 -0
  162. package/src/extension/fanout-child.d.ts.map +1 -0
  163. package/src/extension/fanout-child.js +261 -0
  164. package/src/extension/fanout-child.js.map +1 -0
  165. package/src/extension/herdr-pi-bridge.d.ts +17 -0
  166. package/src/extension/herdr-pi-bridge.d.ts.map +1 -0
  167. package/src/extension/herdr-pi-bridge.js +243 -0
  168. package/src/extension/herdr-pi-bridge.js.map +1 -0
  169. package/src/extension/index.d.ts +20 -0
  170. package/src/extension/index.d.ts.map +1 -0
  171. package/src/extension/index.js +1108 -0
  172. package/src/extension/index.js.map +1 -0
  173. package/src/extension/public-execution.d.ts +62 -0
  174. package/src/extension/public-execution.d.ts.map +1 -0
  175. package/src/extension/public-execution.js +174 -0
  176. package/src/extension/public-execution.js.map +1 -0
  177. package/src/extension/rpc.d.ts +83 -0
  178. package/src/extension/rpc.d.ts.map +1 -0
  179. package/src/extension/rpc.js +687 -0
  180. package/src/extension/rpc.js.map +1 -0
  181. package/src/extension/schemas.d.ts +252 -0
  182. package/src/extension/schemas.d.ts.map +1 -0
  183. package/src/extension/schemas.js +396 -0
  184. package/src/extension/schemas.js.map +1 -0
  185. package/src/extension/steering-notices.d.ts +15 -0
  186. package/src/extension/steering-notices.d.ts.map +1 -0
  187. package/src/extension/steering-notices.js +23 -0
  188. package/src/extension/steering-notices.js.map +1 -0
  189. package/src/extension/subagent-guide.d.ts +4 -0
  190. package/src/extension/subagent-guide.d.ts.map +1 -0
  191. package/src/extension/subagent-guide.js +35 -0
  192. package/src/extension/subagent-guide.js.map +1 -0
  193. package/src/extension/tool-description.d.ts +20 -0
  194. package/src/extension/tool-description.d.ts.map +1 -0
  195. package/src/extension/tool-description.js +160 -0
  196. package/src/extension/tool-description.js.map +1 -0
  197. package/src/extension/tool-result.d.ts +10 -0
  198. package/src/extension/tool-result.d.ts.map +1 -0
  199. package/src/extension/tool-result.js +17 -0
  200. package/src/extension/tool-result.js.map +1 -0
  201. package/src/inspectors/actions.d.ts +23 -0
  202. package/src/inspectors/actions.d.ts.map +1 -0
  203. package/src/inspectors/actions.js +155 -0
  204. package/src/inspectors/actions.js.map +1 -0
  205. package/src/inspectors/ghostty/actions.d.ts +12 -0
  206. package/src/inspectors/ghostty/actions.d.ts.map +1 -0
  207. package/src/inspectors/ghostty/actions.js +63 -0
  208. package/src/inspectors/ghostty/actions.js.map +1 -0
  209. package/src/inspectors/ghostty/plugin.d.ts +8 -0
  210. package/src/inspectors/ghostty/plugin.d.ts.map +1 -0
  211. package/src/inspectors/ghostty/plugin.js +24 -0
  212. package/src/inspectors/ghostty/plugin.js.map +1 -0
  213. package/src/inspectors/herdr/actions.d.ts +26 -0
  214. package/src/inspectors/herdr/actions.d.ts.map +1 -0
  215. package/src/inspectors/herdr/actions.js +134 -0
  216. package/src/inspectors/herdr/actions.js.map +1 -0
  217. package/src/inspectors/herdr/client.d.ts +42 -0
  218. package/src/inspectors/herdr/client.d.ts.map +1 -0
  219. package/src/inspectors/herdr/client.js +130 -0
  220. package/src/inspectors/herdr/client.js.map +1 -0
  221. package/src/inspectors/herdr/focus.d.ts +25 -0
  222. package/src/inspectors/herdr/focus.d.ts.map +1 -0
  223. package/src/inspectors/herdr/focus.js +50 -0
  224. package/src/inspectors/herdr/focus.js.map +1 -0
  225. package/src/inspectors/herdr/plugin.d.ts +7 -0
  226. package/src/inspectors/herdr/plugin.d.ts.map +1 -0
  227. package/src/inspectors/herdr/plugin.js +15 -0
  228. package/src/inspectors/herdr/plugin.js.map +1 -0
  229. package/src/inspectors/herdr/project-panes.d.ts +137 -0
  230. package/src/inspectors/herdr/project-panes.d.ts.map +1 -0
  231. package/src/inspectors/herdr/project-panes.js +608 -0
  232. package/src/inspectors/herdr/project-panes.js.map +1 -0
  233. package/src/inspectors/inspector-runner.d.ts +24 -0
  234. package/src/inspectors/inspector-runner.d.ts.map +1 -0
  235. package/src/inspectors/inspector-runner.js +162 -0
  236. package/src/inspectors/inspector-runner.js.map +1 -0
  237. package/src/inspectors/plugins.d.ts +4 -0
  238. package/src/inspectors/plugins.d.ts.map +1 -0
  239. package/src/inspectors/plugins.js +7 -0
  240. package/src/inspectors/plugins.js.map +1 -0
  241. package/src/inspectors/session-roots-codec.d.ts +16 -0
  242. package/src/inspectors/session-roots-codec.d.ts.map +1 -0
  243. package/src/inspectors/session-roots-codec.js +33 -0
  244. package/src/inspectors/session-roots-codec.js.map +1 -0
  245. package/src/inspectors/shell-command.d.ts +2 -0
  246. package/src/inspectors/shell-command.d.ts.map +1 -0
  247. package/src/inspectors/shell-command.js +17 -0
  248. package/src/inspectors/shell-command.js.map +1 -0
  249. package/src/inspectors/types.d.ts +49 -0
  250. package/src/inspectors/types.d.ts.map +1 -0
  251. package/src/inspectors/types.js +2 -0
  252. package/src/inspectors/types.js.map +1 -0
  253. package/src/integrations/herdr-status.d.ts +46 -0
  254. package/src/integrations/herdr-status.d.ts.map +1 -0
  255. package/src/integrations/herdr-status.js +371 -0
  256. package/src/integrations/herdr-status.js.map +1 -0
  257. package/src/integrations/pi-web-session-liveness.d.ts +20 -0
  258. package/src/integrations/pi-web-session-liveness.d.ts.map +1 -0
  259. package/src/integrations/pi-web-session-liveness.js +54 -0
  260. package/src/integrations/pi-web-session-liveness.js.map +1 -0
  261. package/src/intercom/intercom-bridge.d.ts +59 -0
  262. package/src/intercom/intercom-bridge.d.ts.map +1 -0
  263. package/src/intercom/intercom-bridge.js +192 -0
  264. package/src/intercom/intercom-bridge.js.map +1 -0
  265. package/src/intercom/native-supervisor-channel.d.ts +64 -0
  266. package/src/intercom/native-supervisor-channel.d.ts.map +1 -0
  267. package/src/intercom/native-supervisor-channel.js +894 -0
  268. package/src/intercom/native-supervisor-channel.js.map +1 -0
  269. package/src/intercom/result-intercom.d.ts +36 -0
  270. package/src/intercom/result-intercom.d.ts.map +1 -0
  271. package/src/intercom/result-intercom.js +372 -0
  272. package/src/intercom/result-intercom.js.map +1 -0
  273. package/src/intercom/supervisor-ui.d.ts +40 -0
  274. package/src/intercom/supervisor-ui.d.ts.map +1 -0
  275. package/src/intercom/supervisor-ui.js +202 -0
  276. package/src/intercom/supervisor-ui.js.map +1 -0
  277. package/src/missions/actions.d.ts +55 -0
  278. package/src/missions/actions.d.ts.map +1 -0
  279. package/src/missions/actions.js +396 -0
  280. package/src/missions/actions.js.map +1 -0
  281. package/src/missions/goal-driver.d.ts +16 -0
  282. package/src/missions/goal-driver.d.ts.map +1 -0
  283. package/src/missions/goal-driver.js +157 -0
  284. package/src/missions/goal-driver.js.map +1 -0
  285. package/src/missions/lifecycle.d.ts +40 -0
  286. package/src/missions/lifecycle.d.ts.map +1 -0
  287. package/src/missions/lifecycle.js +352 -0
  288. package/src/missions/lifecycle.js.map +1 -0
  289. package/src/missions/store.d.ts +22 -0
  290. package/src/missions/store.d.ts.map +1 -0
  291. package/src/missions/store.js +573 -0
  292. package/src/missions/store.js.map +1 -0
  293. package/src/missions/types.d.ts +168 -0
  294. package/src/missions/types.d.ts.map +1 -0
  295. package/src/missions/types.js +10 -0
  296. package/src/missions/types.js.map +1 -0
  297. package/src/missions/workflow-state.d.ts +15 -0
  298. package/src/missions/workflow-state.d.ts.map +1 -0
  299. package/src/missions/workflow-state.js +274 -0
  300. package/src/missions/workflow-state.js.map +1 -0
  301. package/src/policy/authority.d.ts +10 -0
  302. package/src/policy/authority.d.ts.map +1 -0
  303. package/src/policy/authority.js +42 -0
  304. package/src/policy/authority.js.map +1 -0
  305. package/src/profiles/profiles.d.ts +135 -0
  306. package/src/profiles/profiles.d.ts.map +1 -0
  307. package/src/profiles/profiles.js +520 -0
  308. package/src/profiles/profiles.js.map +1 -0
  309. package/src/runs/background/active-async-capacity.d.ts +100 -0
  310. package/src/runs/background/active-async-capacity.d.ts.map +1 -0
  311. package/src/runs/background/active-async-capacity.js +492 -0
  312. package/src/runs/background/active-async-capacity.js.map +1 -0
  313. package/src/runs/background/active-run-index.d.ts +13 -0
  314. package/src/runs/background/active-run-index.d.ts.map +1 -0
  315. package/src/runs/background/active-run-index.js +158 -0
  316. package/src/runs/background/active-run-index.js.map +1 -0
  317. package/src/runs/background/async-execution.d.ts +274 -0
  318. package/src/runs/background/async-execution.d.ts.map +1 -0
  319. package/src/runs/background/async-execution.js +1955 -0
  320. package/src/runs/background/async-execution.js.map +1 -0
  321. package/src/runs/background/async-job-tracker.d.ts +28 -0
  322. package/src/runs/background/async-job-tracker.d.ts.map +1 -0
  323. package/src/runs/background/async-job-tracker.js +876 -0
  324. package/src/runs/background/async-job-tracker.js.map +1 -0
  325. package/src/runs/background/async-resume.d.ts +59 -0
  326. package/src/runs/background/async-resume.d.ts.map +1 -0
  327. package/src/runs/background/async-resume.js +667 -0
  328. package/src/runs/background/async-resume.js.map +1 -0
  329. package/src/runs/background/async-retention.d.ts +45 -0
  330. package/src/runs/background/async-retention.d.ts.map +1 -0
  331. package/src/runs/background/async-retention.js +884 -0
  332. package/src/runs/background/async-retention.js.map +1 -0
  333. package/src/runs/background/async-status-snapshot.d.ts +10 -0
  334. package/src/runs/background/async-status-snapshot.d.ts.map +1 -0
  335. package/src/runs/background/async-status-snapshot.js +25 -0
  336. package/src/runs/background/async-status-snapshot.js.map +1 -0
  337. package/src/runs/background/async-status.d.ts +169 -0
  338. package/src/runs/background/async-status.d.ts.map +1 -0
  339. package/src/runs/background/async-status.js +673 -0
  340. package/src/runs/background/async-status.js.map +1 -0
  341. package/src/runs/background/auto-drain.d.ts +17 -0
  342. package/src/runs/background/auto-drain.d.ts.map +1 -0
  343. package/src/runs/background/auto-drain.js +73 -0
  344. package/src/runs/background/auto-drain.js.map +1 -0
  345. package/src/runs/background/binary-bootstrap.d.ts +9 -0
  346. package/src/runs/background/binary-bootstrap.d.ts.map +1 -0
  347. package/src/runs/background/binary-bootstrap.js +41 -0
  348. package/src/runs/background/binary-bootstrap.js.map +1 -0
  349. package/src/runs/background/chain-append.d.ts +35 -0
  350. package/src/runs/background/chain-append.d.ts.map +1 -0
  351. package/src/runs/background/chain-append.js +300 -0
  352. package/src/runs/background/chain-append.js.map +1 -0
  353. package/src/runs/background/chain-root-attachment.d.ts +49 -0
  354. package/src/runs/background/chain-root-attachment.d.ts.map +1 -0
  355. package/src/runs/background/chain-root-attachment.js +184 -0
  356. package/src/runs/background/chain-root-attachment.js.map +1 -0
  357. package/src/runs/background/completion-batcher.d.ts +52 -0
  358. package/src/runs/background/completion-batcher.d.ts.map +1 -0
  359. package/src/runs/background/completion-batcher.js +120 -0
  360. package/src/runs/background/completion-batcher.js.map +1 -0
  361. package/src/runs/background/completion-dedupe.d.ts +14 -0
  362. package/src/runs/background/completion-dedupe.d.ts.map +1 -0
  363. package/src/runs/background/completion-dedupe.js +49 -0
  364. package/src/runs/background/completion-dedupe.js.map +1 -0
  365. package/src/runs/background/completion-replay.d.ts +48 -0
  366. package/src/runs/background/completion-replay.d.ts.map +1 -0
  367. package/src/runs/background/completion-replay.js +267 -0
  368. package/src/runs/background/completion-replay.js.map +1 -0
  369. package/src/runs/background/control-channel.d.ts +156 -0
  370. package/src/runs/background/control-channel.d.ts.map +1 -0
  371. package/src/runs/background/control-channel.js +521 -0
  372. package/src/runs/background/control-channel.js.map +1 -0
  373. package/src/runs/background/fleet-view.d.ts +64 -0
  374. package/src/runs/background/fleet-view.d.ts.map +1 -0
  375. package/src/runs/background/fleet-view.js +648 -0
  376. package/src/runs/background/fleet-view.js.map +1 -0
  377. package/src/runs/background/index-segment.d.ts +16 -0
  378. package/src/runs/background/index-segment.d.ts.map +1 -0
  379. package/src/runs/background/index-segment.js +59 -0
  380. package/src/runs/background/index-segment.js.map +1 -0
  381. package/src/runs/background/inspect-rpc.d.ts +60 -0
  382. package/src/runs/background/inspect-rpc.d.ts.map +1 -0
  383. package/src/runs/background/inspect-rpc.js +406 -0
  384. package/src/runs/background/inspect-rpc.js.map +1 -0
  385. package/src/runs/background/notify.d.ts +162 -0
  386. package/src/runs/background/notify.d.ts.map +1 -0
  387. package/src/runs/background/notify.js +665 -0
  388. package/src/runs/background/notify.js.map +1 -0
  389. package/src/runs/background/owned-process-tree.d.ts +11 -0
  390. package/src/runs/background/owned-process-tree.d.ts.map +1 -0
  391. package/src/runs/background/owned-process-tree.js +117 -0
  392. package/src/runs/background/owned-process-tree.js.map +1 -0
  393. package/src/runs/background/parallel-groups.d.ts +4 -0
  394. package/src/runs/background/parallel-groups.d.ts.map +1 -0
  395. package/src/runs/background/parallel-groups.js +47 -0
  396. package/src/runs/background/parallel-groups.js.map +1 -0
  397. package/src/runs/background/process-terminal.d.ts +34 -0
  398. package/src/runs/background/process-terminal.d.ts.map +1 -0
  399. package/src/runs/background/process-terminal.js +305 -0
  400. package/src/runs/background/process-terminal.js.map +1 -0
  401. package/src/runs/background/result-delivery-ownership.d.ts +11 -0
  402. package/src/runs/background/result-delivery-ownership.d.ts.map +1 -0
  403. package/src/runs/background/result-delivery-ownership.js +37 -0
  404. package/src/runs/background/result-delivery-ownership.js.map +1 -0
  405. package/src/runs/background/result-files.d.ts +33 -0
  406. package/src/runs/background/result-files.d.ts.map +1 -0
  407. package/src/runs/background/result-files.js +528 -0
  408. package/src/runs/background/result-files.js.map +1 -0
  409. package/src/runs/background/result-watcher.d.ts +87 -0
  410. package/src/runs/background/result-watcher.d.ts.map +1 -0
  411. package/src/runs/background/result-watcher.js +764 -0
  412. package/src/runs/background/result-watcher.js.map +1 -0
  413. package/src/runs/background/resume-guidance.d.ts +5 -0
  414. package/src/runs/background/resume-guidance.d.ts.map +1 -0
  415. package/src/runs/background/resume-guidance.js +57 -0
  416. package/src/runs/background/resume-guidance.js.map +1 -0
  417. package/src/runs/background/retained-children.d.ts +25 -0
  418. package/src/runs/background/retained-children.d.ts.map +1 -0
  419. package/src/runs/background/retained-children.js +128 -0
  420. package/src/runs/background/retained-children.js.map +1 -0
  421. package/src/runs/background/retained-nested-route-tracker.d.ts +13 -0
  422. package/src/runs/background/retained-nested-route-tracker.d.ts.map +1 -0
  423. package/src/runs/background/retained-nested-route-tracker.js +91 -0
  424. package/src/runs/background/retained-nested-route-tracker.js.map +1 -0
  425. package/src/runs/background/run-child-session.d.ts +123 -0
  426. package/src/runs/background/run-child-session.d.ts.map +1 -0
  427. package/src/runs/background/run-child-session.js +602 -0
  428. package/src/runs/background/run-child-session.js.map +1 -0
  429. package/src/runs/background/run-id-query.d.ts +4 -0
  430. package/src/runs/background/run-id-query.d.ts.map +1 -0
  431. package/src/runs/background/run-id-query.js +7 -0
  432. package/src/runs/background/run-id-query.js.map +1 -0
  433. package/src/runs/background/run-id-resolver.d.ts +23 -0
  434. package/src/runs/background/run-id-resolver.d.ts.map +1 -0
  435. package/src/runs/background/run-id-resolver.js +170 -0
  436. package/src/runs/background/run-id-resolver.js.map +1 -0
  437. package/src/runs/background/run-status.d.ts +26 -0
  438. package/src/runs/background/run-status.d.ts.map +1 -0
  439. package/src/runs/background/run-status.js +828 -0
  440. package/src/runs/background/run-status.js.map +1 -0
  441. package/src/runs/background/runner-aliases.d.ts +17 -0
  442. package/src/runs/background/runner-aliases.d.ts.map +1 -0
  443. package/src/runs/background/runner-aliases.js +152 -0
  444. package/src/runs/background/runner-aliases.js.map +1 -0
  445. package/src/runs/background/runner-child-launch.d.ts +24 -0
  446. package/src/runs/background/runner-child-launch.d.ts.map +1 -0
  447. package/src/runs/background/runner-child-launch.js +68 -0
  448. package/src/runs/background/runner-child-launch.js.map +1 -0
  449. package/src/runs/background/runner-child-sessions.d.ts +7 -0
  450. package/src/runs/background/runner-child-sessions.d.ts.map +1 -0
  451. package/src/runs/background/runner-child-sessions.js +35 -0
  452. package/src/runs/background/runner-child-sessions.js.map +1 -0
  453. package/src/runs/background/runner-http-dispatcher.d.ts +43 -0
  454. package/src/runs/background/runner-http-dispatcher.d.ts.map +1 -0
  455. package/src/runs/background/runner-http-dispatcher.js +114 -0
  456. package/src/runs/background/runner-http-dispatcher.js.map +1 -0
  457. package/src/runs/background/scheduled-runs.d.ts +116 -0
  458. package/src/runs/background/scheduled-runs.d.ts.map +1 -0
  459. package/src/runs/background/scheduled-runs.js +1024 -0
  460. package/src/runs/background/scheduled-runs.js.map +1 -0
  461. package/src/runs/background/stale-run-reconciler.d.ts +37 -0
  462. package/src/runs/background/stale-run-reconciler.d.ts.map +1 -0
  463. package/src/runs/background/stale-run-reconciler.js +393 -0
  464. package/src/runs/background/stale-run-reconciler.js.map +1 -0
  465. package/src/runs/background/steering.d.ts +52 -0
  466. package/src/runs/background/steering.d.ts.map +1 -0
  467. package/src/runs/background/steering.js +247 -0
  468. package/src/runs/background/steering.js.map +1 -0
  469. package/src/runs/background/subagent-runner.d.ts +197 -0
  470. package/src/runs/background/subagent-runner.d.ts.map +1 -0
  471. package/src/runs/background/subagent-runner.js +5052 -0
  472. package/src/runs/background/subagent-runner.js.map +1 -0
  473. package/src/runs/background/subagent-wait.d.ts +122 -0
  474. package/src/runs/background/subagent-wait.d.ts.map +1 -0
  475. package/src/runs/background/subagent-wait.js +735 -0
  476. package/src/runs/background/subagent-wait.js.map +1 -0
  477. package/src/runs/background/terminal-run-index.d.ts +8 -0
  478. package/src/runs/background/terminal-run-index.d.ts.map +1 -0
  479. package/src/runs/background/terminal-run-index.js +123 -0
  480. package/src/runs/background/terminal-run-index.js.map +1 -0
  481. package/src/runs/background/top-level-async.d.ts +8 -0
  482. package/src/runs/background/top-level-async.d.ts.map +1 -0
  483. package/src/runs/background/top-level-async.js +6 -0
  484. package/src/runs/background/top-level-async.js.map +1 -0
  485. package/src/runs/background/wait-completions.d.ts +29 -0
  486. package/src/runs/background/wait-completions.d.ts.map +1 -0
  487. package/src/runs/background/wait-completions.js +264 -0
  488. package/src/runs/background/wait-completions.js.map +1 -0
  489. package/src/runs/background/wait-config.d.ts +9 -0
  490. package/src/runs/background/wait-config.d.ts.map +1 -0
  491. package/src/runs/background/wait-config.js +47 -0
  492. package/src/runs/background/wait-config.js.map +1 -0
  493. package/src/runs/background/wait-subscriptions.d.ts +27 -0
  494. package/src/runs/background/wait-subscriptions.d.ts.map +1 -0
  495. package/src/runs/background/wait-subscriptions.js +337 -0
  496. package/src/runs/background/wait-subscriptions.js.map +1 -0
  497. package/src/runs/background/wait-tool.d.ts +7 -0
  498. package/src/runs/background/wait-tool.d.ts.map +1 -0
  499. package/src/runs/background/wait-tool.js +36 -0
  500. package/src/runs/background/wait-tool.js.map +1 -0
  501. package/src/runs/foreground/async-dismiss-action.d.ts +7 -0
  502. package/src/runs/foreground/async-dismiss-action.d.ts.map +1 -0
  503. package/src/runs/foreground/async-dismiss-action.js +82 -0
  504. package/src/runs/foreground/async-dismiss-action.js.map +1 -0
  505. package/src/runs/foreground/async-steering-action.d.ts +32 -0
  506. package/src/runs/foreground/async-steering-action.d.ts.map +1 -0
  507. package/src/runs/foreground/async-steering-action.js +270 -0
  508. package/src/runs/foreground/async-steering-action.js.map +1 -0
  509. package/src/runs/foreground/async-stop-action.d.ts +7 -0
  510. package/src/runs/foreground/async-stop-action.d.ts.map +1 -0
  511. package/src/runs/foreground/async-stop-action.js +171 -0
  512. package/src/runs/foreground/async-stop-action.js.map +1 -0
  513. package/src/runs/foreground/execution.d.ts +11 -0
  514. package/src/runs/foreground/execution.d.ts.map +1 -0
  515. package/src/runs/foreground/execution.js +2089 -0
  516. package/src/runs/foreground/execution.js.map +1 -0
  517. package/src/runs/foreground/foreground-control.d.ts +25 -0
  518. package/src/runs/foreground/foreground-control.d.ts.map +1 -0
  519. package/src/runs/foreground/foreground-control.js +139 -0
  520. package/src/runs/foreground/foreground-control.js.map +1 -0
  521. package/src/runs/foreground/foreground-history.d.ts +12 -0
  522. package/src/runs/foreground/foreground-history.d.ts.map +1 -0
  523. package/src/runs/foreground/foreground-history.js +165 -0
  524. package/src/runs/foreground/foreground-history.js.map +1 -0
  525. package/src/runs/foreground/prompt-audit.d.ts +33 -0
  526. package/src/runs/foreground/prompt-audit.d.ts.map +1 -0
  527. package/src/runs/foreground/prompt-audit.js +143 -0
  528. package/src/runs/foreground/prompt-audit.js.map +1 -0
  529. package/src/runs/foreground/subagent-executor.d.ts +296 -0
  530. package/src/runs/foreground/subagent-executor.d.ts.map +1 -0
  531. package/src/runs/foreground/subagent-executor.js +7045 -0
  532. package/src/runs/foreground/subagent-executor.js.map +1 -0
  533. package/src/runs/foreground/workflow-detach-reconcile.d.ts +16 -0
  534. package/src/runs/foreground/workflow-detach-reconcile.d.ts.map +1 -0
  535. package/src/runs/foreground/workflow-detach-reconcile.js +284 -0
  536. package/src/runs/foreground/workflow-detach-reconcile.js.map +1 -0
  537. package/src/runs/foreground/workflow-foreground-steering.d.ts +44 -0
  538. package/src/runs/foreground/workflow-foreground-steering.d.ts.map +1 -0
  539. package/src/runs/foreground/workflow-foreground-steering.js +149 -0
  540. package/src/runs/foreground/workflow-foreground-steering.js.map +1 -0
  541. package/src/runs/shared/abort-recovery.d.ts +27 -0
  542. package/src/runs/shared/abort-recovery.d.ts.map +1 -0
  543. package/src/runs/shared/abort-recovery.js +109 -0
  544. package/src/runs/shared/abort-recovery.js.map +1 -0
  545. package/src/runs/shared/acceptance.d.ts +145 -0
  546. package/src/runs/shared/acceptance.d.ts.map +1 -0
  547. package/src/runs/shared/acceptance.js +1617 -0
  548. package/src/runs/shared/acceptance.js.map +1 -0
  549. package/src/runs/shared/agent-contract.d.ts +6 -0
  550. package/src/runs/shared/agent-contract.d.ts.map +1 -0
  551. package/src/runs/shared/agent-contract.js +36 -0
  552. package/src/runs/shared/agent-contract.js.map +1 -0
  553. package/src/runs/shared/async-status-projection.d.ts +94 -0
  554. package/src/runs/shared/async-status-projection.d.ts.map +1 -0
  555. package/src/runs/shared/async-status-projection.js +542 -0
  556. package/src/runs/shared/async-status-projection.js.map +1 -0
  557. package/src/runs/shared/background-process-options.d.ts +5 -0
  558. package/src/runs/shared/background-process-options.d.ts.map +1 -0
  559. package/src/runs/shared/background-process-options.js +7 -0
  560. package/src/runs/shared/background-process-options.js.map +1 -0
  561. package/src/runs/shared/capability-ceiling.d.ts +58 -0
  562. package/src/runs/shared/capability-ceiling.d.ts.map +1 -0
  563. package/src/runs/shared/capability-ceiling.js +179 -0
  564. package/src/runs/shared/capability-ceiling.js.map +1 -0
  565. package/src/runs/shared/chain-outputs.d.ts +19 -0
  566. package/src/runs/shared/chain-outputs.d.ts.map +1 -0
  567. package/src/runs/shared/chain-outputs.js +105 -0
  568. package/src/runs/shared/chain-outputs.js.map +1 -0
  569. package/src/runs/shared/child-hooks.d.ts +32 -0
  570. package/src/runs/shared/child-hooks.d.ts.map +1 -0
  571. package/src/runs/shared/child-hooks.js +173 -0
  572. package/src/runs/shared/child-hooks.js.map +1 -0
  573. package/src/runs/shared/child-identity.d.ts +24 -0
  574. package/src/runs/shared/child-identity.d.ts.map +1 -0
  575. package/src/runs/shared/child-identity.js +41 -0
  576. package/src/runs/shared/child-identity.js.map +1 -0
  577. package/src/runs/shared/child-launch-plan.d.ts +71 -0
  578. package/src/runs/shared/child-launch-plan.d.ts.map +1 -0
  579. package/src/runs/shared/child-launch-plan.js +89 -0
  580. package/src/runs/shared/child-launch-plan.js.map +1 -0
  581. package/src/runs/shared/child-launch.d.ts +112 -0
  582. package/src/runs/shared/child-launch.d.ts.map +1 -0
  583. package/src/runs/shared/child-launch.js +230 -0
  584. package/src/runs/shared/child-launch.js.map +1 -0
  585. package/src/runs/shared/child-lifecycle.d.ts +14 -0
  586. package/src/runs/shared/child-lifecycle.d.ts.map +1 -0
  587. package/src/runs/shared/child-lifecycle.js +23 -0
  588. package/src/runs/shared/child-lifecycle.js.map +1 -0
  589. package/src/runs/shared/child-runtime-config.d.ts +102 -0
  590. package/src/runs/shared/child-runtime-config.d.ts.map +1 -0
  591. package/src/runs/shared/child-runtime-config.js +39 -0
  592. package/src/runs/shared/child-runtime-config.js.map +1 -0
  593. package/src/runs/shared/child-session.d.ts +154 -0
  594. package/src/runs/shared/child-session.d.ts.map +1 -0
  595. package/src/runs/shared/child-session.js +412 -0
  596. package/src/runs/shared/child-session.js.map +1 -0
  597. package/src/runs/shared/child-tool-plan.d.ts +73 -0
  598. package/src/runs/shared/child-tool-plan.d.ts.map +1 -0
  599. package/src/runs/shared/child-tool-plan.js +380 -0
  600. package/src/runs/shared/child-tool-plan.js.map +1 -0
  601. package/src/runs/shared/claude-code-adapter.d.ts +25 -0
  602. package/src/runs/shared/claude-code-adapter.d.ts.map +1 -0
  603. package/src/runs/shared/claude-code-adapter.js +120 -0
  604. package/src/runs/shared/claude-code-adapter.js.map +1 -0
  605. package/src/runs/shared/codex-exec-adapter.d.ts +26 -0
  606. package/src/runs/shared/codex-exec-adapter.d.ts.map +1 -0
  607. package/src/runs/shared/codex-exec-adapter.js +128 -0
  608. package/src/runs/shared/codex-exec-adapter.js.map +1 -0
  609. package/src/runs/shared/context-mode.d.ts +13 -0
  610. package/src/runs/shared/context-mode.d.ts.map +1 -0
  611. package/src/runs/shared/context-mode.js +39 -0
  612. package/src/runs/shared/context-mode.js.map +1 -0
  613. package/src/runs/shared/cursor-agent-adapter.d.ts +27 -0
  614. package/src/runs/shared/cursor-agent-adapter.d.ts.map +1 -0
  615. package/src/runs/shared/cursor-agent-adapter.js +100 -0
  616. package/src/runs/shared/cursor-agent-adapter.js.map +1 -0
  617. package/src/runs/shared/dynamic-fanout.d.ts +50 -0
  618. package/src/runs/shared/dynamic-fanout.d.ts.map +1 -0
  619. package/src/runs/shared/dynamic-fanout.js +274 -0
  620. package/src/runs/shared/dynamic-fanout.js.map +1 -0
  621. package/src/runs/shared/effective-system-prompt.d.ts +18 -0
  622. package/src/runs/shared/effective-system-prompt.d.ts.map +1 -0
  623. package/src/runs/shared/effective-system-prompt.js +23 -0
  624. package/src/runs/shared/effective-system-prompt.js.map +1 -0
  625. package/src/runs/shared/extension-bindings.d.ts +17 -0
  626. package/src/runs/shared/extension-bindings.d.ts.map +1 -0
  627. package/src/runs/shared/extension-bindings.js +83 -0
  628. package/src/runs/shared/extension-bindings.js.map +1 -0
  629. package/src/runs/shared/external-cli-contract.d.ts +30 -0
  630. package/src/runs/shared/external-cli-contract.d.ts.map +1 -0
  631. package/src/runs/shared/external-cli-contract.js +146 -0
  632. package/src/runs/shared/external-cli-contract.js.map +1 -0
  633. package/src/runs/shared/external-cli-preflight.d.ts +32 -0
  634. package/src/runs/shared/external-cli-preflight.d.ts.map +1 -0
  635. package/src/runs/shared/external-cli-preflight.js +116 -0
  636. package/src/runs/shared/external-cli-preflight.js.map +1 -0
  637. package/src/runs/shared/external-cli-runner.d.ts +66 -0
  638. package/src/runs/shared/external-cli-runner.d.ts.map +1 -0
  639. package/src/runs/shared/external-cli-runner.js +421 -0
  640. package/src/runs/shared/external-cli-runner.js.map +1 -0
  641. package/src/runs/shared/external-job-bridge.d.ts +18 -0
  642. package/src/runs/shared/external-job-bridge.d.ts.map +1 -0
  643. package/src/runs/shared/external-job-bridge.js +424 -0
  644. package/src/runs/shared/external-job-bridge.js.map +1 -0
  645. package/src/runs/shared/external-job-runner.d.ts +45 -0
  646. package/src/runs/shared/external-job-runner.d.ts.map +1 -0
  647. package/src/runs/shared/external-job-runner.js +353 -0
  648. package/src/runs/shared/external-job-runner.js.map +1 -0
  649. package/src/runs/shared/fast-mode-extension.d.ts +4 -0
  650. package/src/runs/shared/fast-mode-extension.d.ts.map +1 -0
  651. package/src/runs/shared/fast-mode-extension.js +9 -0
  652. package/src/runs/shared/fast-mode-extension.js.map +1 -0
  653. package/src/runs/shared/herdr-connection.d.ts +71 -0
  654. package/src/runs/shared/herdr-connection.d.ts.map +1 -0
  655. package/src/runs/shared/herdr-connection.js +258 -0
  656. package/src/runs/shared/herdr-connection.js.map +1 -0
  657. package/src/runs/shared/herdr-external-adapters.d.ts +148 -0
  658. package/src/runs/shared/herdr-external-adapters.d.ts.map +1 -0
  659. package/src/runs/shared/herdr-external-adapters.js +405 -0
  660. package/src/runs/shared/herdr-external-adapters.js.map +1 -0
  661. package/src/runs/shared/herdr-machine.d.ts +48 -0
  662. package/src/runs/shared/herdr-machine.d.ts.map +1 -0
  663. package/src/runs/shared/herdr-machine.js +247 -0
  664. package/src/runs/shared/herdr-machine.js.map +1 -0
  665. package/src/runs/shared/herdr-pi-protocol.d.ts +22 -0
  666. package/src/runs/shared/herdr-pi-protocol.d.ts.map +1 -0
  667. package/src/runs/shared/herdr-pi-protocol.js +58 -0
  668. package/src/runs/shared/herdr-pi-protocol.js.map +1 -0
  669. package/src/runs/shared/herdr-placed-run.d.ts +267 -0
  670. package/src/runs/shared/herdr-placed-run.d.ts.map +1 -0
  671. package/src/runs/shared/herdr-placed-run.js +716 -0
  672. package/src/runs/shared/herdr-placed-run.js.map +1 -0
  673. package/src/runs/shared/host-step-status.d.ts +34 -0
  674. package/src/runs/shared/host-step-status.d.ts.map +1 -0
  675. package/src/runs/shared/host-step-status.js +245 -0
  676. package/src/runs/shared/host-step-status.js.map +1 -0
  677. package/src/runs/shared/lane-metadata.d.ts +24 -0
  678. package/src/runs/shared/lane-metadata.d.ts.map +1 -0
  679. package/src/runs/shared/lane-metadata.js +127 -0
  680. package/src/runs/shared/lane-metadata.js.map +1 -0
  681. package/src/runs/shared/launch-cwd.d.ts +2 -0
  682. package/src/runs/shared/launch-cwd.d.ts.map +1 -0
  683. package/src/runs/shared/launch-cwd.js +17 -0
  684. package/src/runs/shared/launch-cwd.js.map +1 -0
  685. package/src/runs/shared/long-running-guard.d.ts +33 -0
  686. package/src/runs/shared/long-running-guard.d.ts.map +1 -0
  687. package/src/runs/shared/long-running-guard.js +199 -0
  688. package/src/runs/shared/long-running-guard.js.map +1 -0
  689. package/src/runs/shared/mcp-config-sources.d.ts +30 -0
  690. package/src/runs/shared/mcp-config-sources.d.ts.map +1 -0
  691. package/src/runs/shared/mcp-config-sources.js +419 -0
  692. package/src/runs/shared/mcp-config-sources.js.map +1 -0
  693. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +59 -0
  694. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts.map +1 -0
  695. package/src/runs/shared/mcp-direct-tool-allowlist.js +400 -0
  696. package/src/runs/shared/mcp-direct-tool-allowlist.js.map +1 -0
  697. package/src/runs/shared/mcp-direct-tool-grant.d.ts +41 -0
  698. package/src/runs/shared/mcp-direct-tool-grant.d.ts.map +1 -0
  699. package/src/runs/shared/mcp-direct-tool-grant.js +146 -0
  700. package/src/runs/shared/mcp-direct-tool-grant.js.map +1 -0
  701. package/src/runs/shared/model-resolution-diagnostic.d.ts +22 -0
  702. package/src/runs/shared/model-resolution-diagnostic.d.ts.map +1 -0
  703. package/src/runs/shared/model-resolution-diagnostic.js +65 -0
  704. package/src/runs/shared/model-resolution-diagnostic.js.map +1 -0
  705. package/src/runs/shared/model-resolution.d.ts +92 -0
  706. package/src/runs/shared/model-resolution.d.ts.map +1 -0
  707. package/src/runs/shared/model-resolution.js +343 -0
  708. package/src/runs/shared/model-resolution.js.map +1 -0
  709. package/src/runs/shared/model-scope.d.ts +68 -0
  710. package/src/runs/shared/model-scope.d.ts.map +1 -0
  711. package/src/runs/shared/model-scope.js +156 -0
  712. package/src/runs/shared/model-scope.js.map +1 -0
  713. package/src/runs/shared/mutation-evidence.d.ts +19 -0
  714. package/src/runs/shared/mutation-evidence.d.ts.map +1 -0
  715. package/src/runs/shared/mutation-evidence.js +199 -0
  716. package/src/runs/shared/mutation-evidence.js.map +1 -0
  717. package/src/runs/shared/nested-events.d.ts +134 -0
  718. package/src/runs/shared/nested-events.d.ts.map +1 -0
  719. package/src/runs/shared/nested-events.js +1056 -0
  720. package/src/runs/shared/nested-events.js.map +1 -0
  721. package/src/runs/shared/nested-path.d.ts +9 -0
  722. package/src/runs/shared/nested-path.d.ts.map +1 -0
  723. package/src/runs/shared/nested-path.js +35 -0
  724. package/src/runs/shared/nested-path.js.map +1 -0
  725. package/src/runs/shared/nested-render.d.ts +21 -0
  726. package/src/runs/shared/nested-render.d.ts.map +1 -0
  727. package/src/runs/shared/nested-render.js +116 -0
  728. package/src/runs/shared/nested-render.js.map +1 -0
  729. package/src/runs/shared/orca-progress-tabs.d.ts +33 -0
  730. package/src/runs/shared/orca-progress-tabs.d.ts.map +1 -0
  731. package/src/runs/shared/orca-progress-tabs.js +527 -0
  732. package/src/runs/shared/orca-progress-tabs.js.map +1 -0
  733. package/src/runs/shared/parallel-handoff.d.ts +73 -0
  734. package/src/runs/shared/parallel-handoff.d.ts.map +1 -0
  735. package/src/runs/shared/parallel-handoff.js +733 -0
  736. package/src/runs/shared/parallel-handoff.js.map +1 -0
  737. package/src/runs/shared/parallel-utils.d.ts +164 -0
  738. package/src/runs/shared/parallel-utils.d.ts.map +1 -0
  739. package/src/runs/shared/parallel-utils.js +126 -0
  740. package/src/runs/shared/parallel-utils.js.map +1 -0
  741. package/src/runs/shared/permissions.d.ts +13 -0
  742. package/src/runs/shared/permissions.d.ts.map +1 -0
  743. package/src/runs/shared/permissions.js +93 -0
  744. package/src/runs/shared/permissions.js.map +1 -0
  745. package/src/runs/shared/pi-spawn.d.ts +28 -0
  746. package/src/runs/shared/pi-spawn.d.ts.map +1 -0
  747. package/src/runs/shared/pi-spawn.js +156 -0
  748. package/src/runs/shared/pi-spawn.js.map +1 -0
  749. package/src/runs/shared/process-signal.d.ts +16 -0
  750. package/src/runs/shared/process-signal.d.ts.map +1 -0
  751. package/src/runs/shared/process-signal.js +22 -0
  752. package/src/runs/shared/process-signal.js.map +1 -0
  753. package/src/runs/shared/readonly-drain-observation.d.ts +26 -0
  754. package/src/runs/shared/readonly-drain-observation.d.ts.map +1 -0
  755. package/src/runs/shared/readonly-drain-observation.js +51 -0
  756. package/src/runs/shared/readonly-drain-observation.js.map +1 -0
  757. package/src/runs/shared/run-fanout-budget.d.ts +15 -0
  758. package/src/runs/shared/run-fanout-budget.d.ts.map +1 -0
  759. package/src/runs/shared/run-fanout-budget.js +259 -0
  760. package/src/runs/shared/run-fanout-budget.js.map +1 -0
  761. package/src/runs/shared/run-history.d.ts +20 -0
  762. package/src/runs/shared/run-history.d.ts.map +1 -0
  763. package/src/runs/shared/run-history.js +200 -0
  764. package/src/runs/shared/run-history.js.map +1 -0
  765. package/src/runs/shared/runtime-acknowledged-extensions.d.ts +8 -0
  766. package/src/runs/shared/runtime-acknowledged-extensions.d.ts.map +1 -0
  767. package/src/runs/shared/runtime-acknowledged-extensions.js +45 -0
  768. package/src/runs/shared/runtime-acknowledged-extensions.js.map +1 -0
  769. package/src/runs/shared/session-lease.d.ts +70 -0
  770. package/src/runs/shared/session-lease.d.ts.map +1 -0
  771. package/src/runs/shared/session-lease.js +251 -0
  772. package/src/runs/shared/session-lease.js.map +1 -0
  773. package/src/runs/shared/single-output.d.ts +61 -0
  774. package/src/runs/shared/single-output.d.ts.map +1 -0
  775. package/src/runs/shared/single-output.js +271 -0
  776. package/src/runs/shared/single-output.js.map +1 -0
  777. package/src/runs/shared/spawn-budget.d.ts +21 -0
  778. package/src/runs/shared/spawn-budget.d.ts.map +1 -0
  779. package/src/runs/shared/spawn-budget.js +94 -0
  780. package/src/runs/shared/spawn-budget.js.map +1 -0
  781. package/src/runs/shared/structured-output.d.ts +57 -0
  782. package/src/runs/shared/structured-output.d.ts.map +1 -0
  783. package/src/runs/shared/structured-output.js +391 -0
  784. package/src/runs/shared/structured-output.js.map +1 -0
  785. package/src/runs/shared/subagent-control.d.ts +50 -0
  786. package/src/runs/shared/subagent-control.d.ts.map +1 -0
  787. package/src/runs/shared/subagent-control.js +234 -0
  788. package/src/runs/shared/subagent-control.js.map +1 -0
  789. package/src/runs/shared/subagent-prompt-runtime.d.ts +28 -0
  790. package/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -0
  791. package/src/runs/shared/subagent-prompt-runtime.js +548 -0
  792. package/src/runs/shared/subagent-prompt-runtime.js.map +1 -0
  793. package/src/runs/shared/tool-availability.d.ts +17 -0
  794. package/src/runs/shared/tool-availability.d.ts.map +1 -0
  795. package/src/runs/shared/tool-availability.js +30 -0
  796. package/src/runs/shared/tool-availability.js.map +1 -0
  797. package/src/runs/shared/tool-budget.d.ts +22 -0
  798. package/src/runs/shared/tool-budget.d.ts.map +1 -0
  799. package/src/runs/shared/tool-budget.js +79 -0
  800. package/src/runs/shared/tool-budget.js.map +1 -0
  801. package/src/runs/shared/tool-timeout.d.ts +32 -0
  802. package/src/runs/shared/tool-timeout.d.ts.map +1 -0
  803. package/src/runs/shared/tool-timeout.js +74 -0
  804. package/src/runs/shared/tool-timeout.js.map +1 -0
  805. package/src/runs/shared/usage-budget.d.ts +8 -0
  806. package/src/runs/shared/usage-budget.d.ts.map +1 -0
  807. package/src/runs/shared/usage-budget.js +75 -0
  808. package/src/runs/shared/usage-budget.js.map +1 -0
  809. package/src/runs/shared/usage-reconciliation.d.ts +9 -0
  810. package/src/runs/shared/usage-reconciliation.d.ts.map +1 -0
  811. package/src/runs/shared/usage-reconciliation.js +72 -0
  812. package/src/runs/shared/usage-reconciliation.js.map +1 -0
  813. package/src/runs/shared/workflow-async-child-guidance.d.ts +4 -0
  814. package/src/runs/shared/workflow-async-child-guidance.d.ts.map +1 -0
  815. package/src/runs/shared/workflow-async-child-guidance.js +18 -0
  816. package/src/runs/shared/workflow-async-child-guidance.js.map +1 -0
  817. package/src/runs/shared/workflow-graph.d.ts +32 -0
  818. package/src/runs/shared/workflow-graph.d.ts.map +1 -0
  819. package/src/runs/shared/workflow-graph.js +222 -0
  820. package/src/runs/shared/workflow-graph.js.map +1 -0
  821. package/src/runs/shared/worktree-cleanup-plan.d.ts +78 -0
  822. package/src/runs/shared/worktree-cleanup-plan.d.ts.map +1 -0
  823. package/src/runs/shared/worktree-cleanup-plan.js +782 -0
  824. package/src/runs/shared/worktree-cleanup-plan.js.map +1 -0
  825. package/src/runs/shared/worktree-setup-command.d.ts +39 -0
  826. package/src/runs/shared/worktree-setup-command.d.ts.map +1 -0
  827. package/src/runs/shared/worktree-setup-command.js +201 -0
  828. package/src/runs/shared/worktree-setup-command.js.map +1 -0
  829. package/src/runs/shared/worktree.d.ts +179 -0
  830. package/src/runs/shared/worktree.d.ts.map +1 -0
  831. package/src/runs/shared/worktree.js +1333 -0
  832. package/src/runs/shared/worktree.js.map +1 -0
  833. package/src/shared/accessible-dir.d.ts +12 -0
  834. package/src/shared/accessible-dir.d.ts.map +1 -0
  835. package/src/shared/accessible-dir.js +37 -0
  836. package/src/shared/accessible-dir.js.map +1 -0
  837. package/src/shared/agent-stream-options.d.ts +6 -0
  838. package/src/shared/agent-stream-options.d.ts.map +1 -0
  839. package/src/shared/agent-stream-options.js +4 -0
  840. package/src/shared/agent-stream-options.js.map +1 -0
  841. package/src/shared/artifacts.d.ts +23 -0
  842. package/src/shared/artifacts.d.ts.map +1 -0
  843. package/src/shared/artifacts.js +273 -0
  844. package/src/shared/artifacts.js.map +1 -0
  845. package/src/shared/atomic-json.d.ts +19 -0
  846. package/src/shared/atomic-json.d.ts.map +1 -0
  847. package/src/shared/atomic-json.js +60 -0
  848. package/src/shared/atomic-json.js.map +1 -0
  849. package/src/shared/capacity-resilient-json.d.ts +27 -0
  850. package/src/shared/capacity-resilient-json.d.ts.map +1 -0
  851. package/src/shared/capacity-resilient-json.js +87 -0
  852. package/src/shared/capacity-resilient-json.js.map +1 -0
  853. package/src/shared/child-cache-retention.d.ts +30 -0
  854. package/src/shared/child-cache-retention.d.ts.map +1 -0
  855. package/src/shared/child-cache-retention.js +41 -0
  856. package/src/shared/child-cache-retention.js.map +1 -0
  857. package/src/shared/child-session-name.d.ts +9 -0
  858. package/src/shared/child-session-name.d.ts.map +1 -0
  859. package/src/shared/child-session-name.js +39 -0
  860. package/src/shared/child-session-name.js.map +1 -0
  861. package/src/shared/child-transcript.d.ts +38 -0
  862. package/src/shared/child-transcript.d.ts.map +1 -0
  863. package/src/shared/child-transcript.js +226 -0
  864. package/src/shared/child-transcript.js.map +1 -0
  865. package/src/shared/completion-owner.d.ts +3 -0
  866. package/src/shared/completion-owner.d.ts.map +1 -0
  867. package/src/shared/completion-owner.js +9 -0
  868. package/src/shared/completion-owner.js.map +1 -0
  869. package/src/shared/display-text.d.ts +6 -0
  870. package/src/shared/display-text.d.ts.map +1 -0
  871. package/src/shared/display-text.js +155 -0
  872. package/src/shared/display-text.js.map +1 -0
  873. package/src/shared/extension-context.d.ts +6 -0
  874. package/src/shared/extension-context.d.ts.map +1 -0
  875. package/src/shared/extension-context.js +22 -0
  876. package/src/shared/extension-context.js.map +1 -0
  877. package/src/shared/file-coalescer.d.ts +12 -0
  878. package/src/shared/file-coalescer.d.ts.map +1 -0
  879. package/src/shared/file-coalescer.js +35 -0
  880. package/src/shared/file-coalescer.js.map +1 -0
  881. package/src/shared/file-system-retry.d.ts +32 -0
  882. package/src/shared/file-system-retry.d.ts.map +1 -0
  883. package/src/shared/file-system-retry.js +85 -0
  884. package/src/shared/file-system-retry.js.map +1 -0
  885. package/src/shared/fork-context.d.ts +59 -0
  886. package/src/shared/fork-context.d.ts.map +1 -0
  887. package/src/shared/fork-context.js +171 -0
  888. package/src/shared/fork-context.js.map +1 -0
  889. package/src/shared/fork-session-cwd.d.ts +3 -0
  890. package/src/shared/fork-session-cwd.d.ts.map +1 -0
  891. package/src/shared/fork-session-cwd.js +24 -0
  892. package/src/shared/fork-session-cwd.js.map +1 -0
  893. package/src/shared/formatters.d.ts +36 -0
  894. package/src/shared/formatters.d.ts.map +1 -0
  895. package/src/shared/formatters.js +143 -0
  896. package/src/shared/formatters.js.map +1 -0
  897. package/src/shared/jsonl-writer.d.ts +21 -0
  898. package/src/shared/jsonl-writer.d.ts.map +1 -0
  899. package/src/shared/jsonl-writer.js +68 -0
  900. package/src/shared/jsonl-writer.js.map +1 -0
  901. package/src/shared/launch-contract.d.ts +64 -0
  902. package/src/shared/launch-contract.d.ts.map +1 -0
  903. package/src/shared/launch-contract.js +140 -0
  904. package/src/shared/launch-contract.js.map +1 -0
  905. package/src/shared/model-info.d.ts +44 -0
  906. package/src/shared/model-info.d.ts.map +1 -0
  907. package/src/shared/model-info.js +73 -0
  908. package/src/shared/model-info.js.map +1 -0
  909. package/src/shared/model-response-aliases.d.ts +2 -0
  910. package/src/shared/model-response-aliases.d.ts.map +1 -0
  911. package/src/shared/model-response-aliases.js +16 -0
  912. package/src/shared/model-response-aliases.js.map +1 -0
  913. package/src/shared/node-executable.d.ts +2 -0
  914. package/src/shared/node-executable.d.ts.map +1 -0
  915. package/src/shared/node-executable.js +21 -0
  916. package/src/shared/node-executable.js.map +1 -0
  917. package/src/shared/opencode-session-headers.d.ts +13 -0
  918. package/src/shared/opencode-session-headers.d.ts.map +1 -0
  919. package/src/shared/opencode-session-headers.js +27 -0
  920. package/src/shared/opencode-session-headers.js.map +1 -0
  921. package/src/shared/prompt-resources.d.ts +6 -0
  922. package/src/shared/prompt-resources.d.ts.map +1 -0
  923. package/src/shared/prompt-resources.js +11 -0
  924. package/src/shared/prompt-resources.js.map +1 -0
  925. package/src/shared/pruned-fork.d.ts +35 -0
  926. package/src/shared/pruned-fork.d.ts.map +1 -0
  927. package/src/shared/pruned-fork.js +417 -0
  928. package/src/shared/pruned-fork.js.map +1 -0
  929. package/src/shared/required-child-extensions.d.ts +20 -0
  930. package/src/shared/required-child-extensions.d.ts.map +1 -0
  931. package/src/shared/required-child-extensions.js +74 -0
  932. package/src/shared/required-child-extensions.js.map +1 -0
  933. package/src/shared/session-file-trust.d.ts +2 -0
  934. package/src/shared/session-file-trust.d.ts.map +1 -0
  935. package/src/shared/session-file-trust.js +21 -0
  936. package/src/shared/session-file-trust.js.map +1 -0
  937. package/src/shared/session-identity.d.ts +7 -0
  938. package/src/shared/session-identity.d.ts.map +1 -0
  939. package/src/shared/session-identity.js +7 -0
  940. package/src/shared/session-identity.js.map +1 -0
  941. package/src/shared/session-tokens.d.ts +3 -0
  942. package/src/shared/session-tokens.d.ts.map +1 -0
  943. package/src/shared/session-tokens.js +59 -0
  944. package/src/shared/session-tokens.js.map +1 -0
  945. package/src/shared/settings.d.ts +147 -0
  946. package/src/shared/settings.d.ts.map +1 -0
  947. package/src/shared/settings.js +248 -0
  948. package/src/shared/settings.js.map +1 -0
  949. package/src/shared/shortcuts.d.ts +2 -0
  950. package/src/shared/shortcuts.d.ts.map +1 -0
  951. package/src/shared/shortcuts.js +18 -0
  952. package/src/shared/shortcuts.js.map +1 -0
  953. package/src/shared/status-format.d.ts +10 -0
  954. package/src/shared/status-format.d.ts.map +1 -0
  955. package/src/shared/status-format.js +61 -0
  956. package/src/shared/status-format.js.map +1 -0
  957. package/src/shared/thinking-ceiling.d.ts +14 -0
  958. package/src/shared/thinking-ceiling.d.ts.map +1 -0
  959. package/src/shared/thinking-ceiling.js +38 -0
  960. package/src/shared/thinking-ceiling.js.map +1 -0
  961. package/src/shared/types.d.ts +2660 -0
  962. package/src/shared/types.d.ts.map +1 -0
  963. package/src/shared/types.js +265 -0
  964. package/src/shared/types.js.map +1 -0
  965. package/src/shared/utf8.d.ts +6 -0
  966. package/src/shared/utf8.d.ts.map +1 -0
  967. package/src/shared/utf8.js +13 -0
  968. package/src/shared/utf8.js.map +1 -0
  969. package/src/shared/utils.d.ts +71 -0
  970. package/src/shared/utils.d.ts.map +1 -0
  971. package/src/shared/utils.js +593 -0
  972. package/src/shared/utils.js.map +1 -0
  973. package/src/shared/watch-strategy.d.ts +3 -0
  974. package/src/shared/watch-strategy.d.ts.map +1 -0
  975. package/src/shared/watch-strategy.js +6 -0
  976. package/src/shared/watch-strategy.js.map +1 -0
  977. package/src/shared/workflow-child-permit.d.ts +59 -0
  978. package/src/shared/workflow-child-permit.d.ts.map +1 -0
  979. package/src/shared/workflow-child-permit.js +160 -0
  980. package/src/shared/workflow-child-permit.js.map +1 -0
  981. package/src/slash/delegation-adapters.d.ts +147 -0
  982. package/src/slash/delegation-adapters.d.ts.map +1 -0
  983. package/src/slash/delegation-adapters.js +293 -0
  984. package/src/slash/delegation-adapters.js.map +1 -0
  985. package/src/slash/delegation-json.d.ts +11 -0
  986. package/src/slash/delegation-json.d.ts.map +1 -0
  987. package/src/slash/delegation-json.js +118 -0
  988. package/src/slash/delegation-json.js.map +1 -0
  989. package/src/slash/delegation-request.d.ts +13 -0
  990. package/src/slash/delegation-request.d.ts.map +1 -0
  991. package/src/slash/delegation-request.js +175 -0
  992. package/src/slash/delegation-request.js.map +1 -0
  993. package/src/slash/prompt-template-bridge.d.ts +27 -0
  994. package/src/slash/prompt-template-bridge.d.ts.map +1 -0
  995. package/src/slash/prompt-template-bridge.js +380 -0
  996. package/src/slash/prompt-template-bridge.js.map +1 -0
  997. package/src/slash/prompt-workflows.d.ts +22 -0
  998. package/src/slash/prompt-workflows.d.ts.map +1 -0
  999. package/src/slash/prompt-workflows.js +261 -0
  1000. package/src/slash/prompt-workflows.js.map +1 -0
  1001. package/src/slash/selector.d.ts +48 -0
  1002. package/src/slash/selector.d.ts.map +1 -0
  1003. package/src/slash/selector.js +118 -0
  1004. package/src/slash/selector.js.map +1 -0
  1005. package/src/slash/slash-bridge.d.ts +31 -0
  1006. package/src/slash/slash-bridge.d.ts.map +1 -0
  1007. package/src/slash/slash-bridge.js +133 -0
  1008. package/src/slash/slash-bridge.js.map +1 -0
  1009. package/src/slash/slash-commands.d.ts +9 -0
  1010. package/src/slash/slash-commands.d.ts.map +1 -0
  1011. package/src/slash/slash-commands.js +1295 -0
  1012. package/src/slash/slash-commands.js.map +1 -0
  1013. package/src/slash/slash-live-state.d.ts +22 -0
  1014. package/src/slash/slash-live-state.d.ts.map +1 -0
  1015. package/src/slash/slash-live-state.js +264 -0
  1016. package/src/slash/slash-live-state.js.map +1 -0
  1017. package/src/slash/subagents-admin.d.ts +3 -0
  1018. package/src/slash/subagents-admin.d.ts.map +1 -0
  1019. package/src/slash/subagents-admin.js +453 -0
  1020. package/src/slash/subagents-admin.js.map +1 -0
  1021. package/src/tui/fleet-status.d.ts +86 -0
  1022. package/src/tui/fleet-status.d.ts.map +1 -0
  1023. package/src/tui/fleet-status.js +1083 -0
  1024. package/src/tui/fleet-status.js.map +1 -0
  1025. package/src/tui/fleet-transcript.d.ts +50 -0
  1026. package/src/tui/fleet-transcript.d.ts.map +1 -0
  1027. package/src/tui/fleet-transcript.js +497 -0
  1028. package/src/tui/fleet-transcript.js.map +1 -0
  1029. package/src/tui/fleet.d.ts +169 -0
  1030. package/src/tui/fleet.d.ts.map +1 -0
  1031. package/src/tui/fleet.js +1412 -0
  1032. package/src/tui/fleet.js.map +1 -0
  1033. package/src/tui/render-helpers.d.ts +24 -0
  1034. package/src/tui/render-helpers.d.ts.map +1 -0
  1035. package/src/tui/render-helpers.js +101 -0
  1036. package/src/tui/render-helpers.js.map +1 -0
  1037. package/src/tui/render.d.ts +61 -0
  1038. package/src/tui/render.d.ts.map +1 -0
  1039. package/src/tui/render.js +3608 -0
  1040. package/src/tui/render.js.map +1 -0
  1041. package/src/watchdog/change-signature.d.ts +8 -0
  1042. package/src/watchdog/change-signature.d.ts.map +1 -0
  1043. package/src/watchdog/change-signature.js +246 -0
  1044. package/src/watchdog/change-signature.js.map +1 -0
  1045. package/src/watchdog/child-status.d.ts +54 -0
  1046. package/src/watchdog/child-status.d.ts.map +1 -0
  1047. package/src/watchdog/child-status.js +188 -0
  1048. package/src/watchdog/child-status.js.map +1 -0
  1049. package/src/watchdog/diff-tool.d.ts +23 -0
  1050. package/src/watchdog/diff-tool.d.ts.map +1 -0
  1051. package/src/watchdog/diff-tool.js +84 -0
  1052. package/src/watchdog/diff-tool.js.map +1 -0
  1053. package/src/watchdog/emission-guard.d.ts +37 -0
  1054. package/src/watchdog/emission-guard.d.ts.map +1 -0
  1055. package/src/watchdog/emission-guard.js +98 -0
  1056. package/src/watchdog/emission-guard.js.map +1 -0
  1057. package/src/watchdog/guidance.d.ts +4 -0
  1058. package/src/watchdog/guidance.d.ts.map +1 -0
  1059. package/src/watchdog/guidance.js +20 -0
  1060. package/src/watchdog/guidance.js.map +1 -0
  1061. package/src/watchdog/lsp-diagnostics.d.ts +18 -0
  1062. package/src/watchdog/lsp-diagnostics.d.ts.map +1 -0
  1063. package/src/watchdog/lsp-diagnostics.js +490 -0
  1064. package/src/watchdog/lsp-diagnostics.js.map +1 -0
  1065. package/src/watchdog/model-selection.d.ts +25 -0
  1066. package/src/watchdog/model-selection.d.ts.map +1 -0
  1067. package/src/watchdog/model-selection.js +168 -0
  1068. package/src/watchdog/model-selection.js.map +1 -0
  1069. package/src/watchdog/permission-arbiter.d.ts +21 -0
  1070. package/src/watchdog/permission-arbiter.d.ts.map +1 -0
  1071. package/src/watchdog/permission-arbiter.js +141 -0
  1072. package/src/watchdog/permission-arbiter.js.map +1 -0
  1073. package/src/watchdog/register-child.d.ts +12 -0
  1074. package/src/watchdog/register-child.d.ts.map +1 -0
  1075. package/src/watchdog/register-child.js +120 -0
  1076. package/src/watchdog/register-child.js.map +1 -0
  1077. package/src/watchdog/register-main.d.ts +10 -0
  1078. package/src/watchdog/register-main.d.ts.map +1 -0
  1079. package/src/watchdog/register-main.js +419 -0
  1080. package/src/watchdog/register-main.js.map +1 -0
  1081. package/src/watchdog/render.d.ts +12 -0
  1082. package/src/watchdog/render.d.ts.map +1 -0
  1083. package/src/watchdog/render.js +52 -0
  1084. package/src/watchdog/render.js.map +1 -0
  1085. package/src/watchdog/review.d.ts +37 -0
  1086. package/src/watchdog/review.d.ts.map +1 -0
  1087. package/src/watchdog/review.js +325 -0
  1088. package/src/watchdog/review.js.map +1 -0
  1089. package/src/watchdog/rules.d.ts +22 -0
  1090. package/src/watchdog/rules.d.ts.map +1 -0
  1091. package/src/watchdog/rules.js +59 -0
  1092. package/src/watchdog/rules.js.map +1 -0
  1093. package/src/watchdog/runtime.d.ts +196 -0
  1094. package/src/watchdog/runtime.d.ts.map +1 -0
  1095. package/src/watchdog/runtime.js +862 -0
  1096. package/src/watchdog/runtime.js.map +1 -0
  1097. package/src/watchdog/scope.d.ts +15 -0
  1098. package/src/watchdog/scope.d.ts.map +1 -0
  1099. package/src/watchdog/scope.js +45 -0
  1100. package/src/watchdog/scope.js.map +1 -0
  1101. package/src/watchdog/settings.d.ts +30 -0
  1102. package/src/watchdog/settings.d.ts.map +1 -0
  1103. package/src/watchdog/settings.js +476 -0
  1104. package/src/watchdog/settings.js.map +1 -0
  1105. package/src/watchdog/tool-actions.d.ts +18 -0
  1106. package/src/watchdog/tool-actions.d.ts.map +1 -0
  1107. package/src/watchdog/tool-actions.js +151 -0
  1108. package/src/watchdog/tool-actions.js.map +1 -0
  1109. package/src/watchdog/turn-delta.d.ts +12 -0
  1110. package/src/watchdog/turn-delta.d.ts.map +1 -0
  1111. package/src/watchdog/turn-delta.js +185 -0
  1112. package/src/watchdog/turn-delta.js.map +1 -0
  1113. package/src/watchdog/types.d.ts +142 -0
  1114. package/src/watchdog/types.d.ts.map +1 -0
  1115. package/src/watchdog/types.js +28 -0
  1116. package/src/watchdog/types.js.map +1 -0
  1117. package/src/watchdog/warning-format.d.ts +8 -0
  1118. package/src/watchdog/warning-format.d.ts.map +1 -0
  1119. package/src/watchdog/warning-format.js +60 -0
  1120. package/src/watchdog/warning-format.js.map +1 -0
  1121. package/src/workflows/chat-progress.d.ts +38 -0
  1122. package/src/workflows/chat-progress.d.ts.map +1 -0
  1123. package/src/workflows/chat-progress.js +130 -0
  1124. package/src/workflows/chat-progress.js.map +1 -0
  1125. package/src/workflows/host-command.d.ts +31 -0
  1126. package/src/workflows/host-command.d.ts.map +1 -0
  1127. package/src/workflows/host-command.js +228 -0
  1128. package/src/workflows/host-command.js.map +1 -0
  1129. package/src/workflows/scripted-workflow.d.ts +195 -0
  1130. package/src/workflows/scripted-workflow.d.ts.map +1 -0
  1131. package/src/workflows/scripted-workflow.js +2634 -0
  1132. package/src/workflows/scripted-workflow.js.map +1 -0
  1133. package/src/workflows/workflow-checklist.d.ts +124 -0
  1134. package/src/workflows/workflow-checklist.d.ts.map +1 -0
  1135. package/src/workflows/workflow-checklist.js +312 -0
  1136. package/src/workflows/workflow-checklist.js.map +1 -0
  1137. package/src/workflows/workflow-child-summary.d.ts +20 -0
  1138. package/src/workflows/workflow-child-summary.d.ts.map +1 -0
  1139. package/src/workflows/workflow-child-summary.js +179 -0
  1140. package/src/workflows/workflow-child-summary.js.map +1 -0
  1141. package/src/workflows/workflow-preflight.d.ts +59 -0
  1142. package/src/workflows/workflow-preflight.d.ts.map +1 -0
  1143. package/src/workflows/workflow-preflight.js +289 -0
  1144. package/src/workflows/workflow-preflight.js.map +1 -0
  1145. package/src/workflows/workflow-receipt.d.ts +35 -0
  1146. package/src/workflows/workflow-receipt.d.ts.map +1 -0
  1147. package/src/workflows/workflow-receipt.js +449 -0
  1148. package/src/workflows/workflow-receipt.js.map +1 -0
  1149. package/src/workflows/workflow-resources.d.ts +43 -0
  1150. package/src/workflows/workflow-resources.d.ts.map +1 -0
  1151. package/src/workflows/workflow-resources.js +230 -0
  1152. package/src/workflows/workflow-resources.js.map +1 -0
  1153. package/src/workflows/workflow-settlement.d.ts +85 -0
  1154. package/src/workflows/workflow-settlement.d.ts.map +1 -0
  1155. package/src/workflows/workflow-settlement.js +204 -0
  1156. package/src/workflows/workflow-settlement.js.map +1 -0
  1157. package/index.ts +0 -13
  1158. package/src/agents/advertised-agent-prompt.ts +0 -94
  1159. package/src/agents/agent-management.ts +0 -1417
  1160. package/src/agents/agent-memory.ts +0 -254
  1161. package/src/agents/agent-refinements.ts +0 -624
  1162. package/src/agents/agent-scope.ts +0 -6
  1163. package/src/agents/agent-selection.ts +0 -25
  1164. package/src/agents/agent-serializer.ts +0 -182
  1165. package/src/agents/agents.ts +0 -2917
  1166. package/src/agents/builtin-names.ts +0 -16
  1167. package/src/agents/chain-serializer.ts +0 -285
  1168. package/src/agents/frontmatter.ts +0 -153
  1169. package/src/agents/identity.ts +0 -30
  1170. package/src/agents/proactive-skills.ts +0 -194
  1171. package/src/agents/runtime-agent-events.ts +0 -70
  1172. package/src/agents/runtime-agent-registry.ts +0 -430
  1173. package/src/agents/skills.ts +0 -754
  1174. package/src/api/agents.ts +0 -12
  1175. package/src/api/background-work.ts +0 -206
  1176. package/src/api/capability-ceiling.ts +0 -16
  1177. package/src/api/child-tool-plan.ts +0 -5
  1178. package/src/api/control-channel.ts +0 -4
  1179. package/src/api/delegation.ts +0 -116
  1180. package/src/api/external-job-provider.ts +0 -195
  1181. package/src/api/external-runs.ts +0 -282
  1182. package/src/api/intercom-bridge.ts +0 -3
  1183. package/src/api/preflight.ts +0 -539
  1184. package/src/api/project-panes.ts +0 -32
  1185. package/src/api/required-child-extensions.ts +0 -6
  1186. package/src/api/shared-types.ts +0 -29
  1187. package/src/api/workflow-resources.ts +0 -6
  1188. package/src/extension/config.ts +0 -230
  1189. package/src/extension/control-notices.ts +0 -58
  1190. package/src/extension/doctor.ts +0 -270
  1191. package/src/extension/fanout-child.ts +0 -265
  1192. package/src/extension/herdr-pi-bridge.ts +0 -160
  1193. package/src/extension/index.ts +0 -1205
  1194. package/src/extension/public-execution.ts +0 -225
  1195. package/src/extension/rpc.ts +0 -848
  1196. package/src/extension/schemas.ts +0 -428
  1197. package/src/extension/steering-notices.ts +0 -35
  1198. package/src/extension/subagent-guide.ts +0 -39
  1199. package/src/extension/tool-description.ts +0 -175
  1200. package/src/extension/tool-result.ts +0 -19
  1201. package/src/inspectors/actions.ts +0 -148
  1202. package/src/inspectors/ghostty/actions.ts +0 -74
  1203. package/src/inspectors/ghostty/plugin.ts +0 -29
  1204. package/src/inspectors/herdr/actions.ts +0 -155
  1205. package/src/inspectors/herdr/client.ts +0 -130
  1206. package/src/inspectors/herdr/focus.ts +0 -55
  1207. package/src/inspectors/herdr/plugin.ts +0 -20
  1208. package/src/inspectors/herdr/project-panes.ts +0 -730
  1209. package/src/inspectors/inspector-runner.ts +0 -153
  1210. package/src/inspectors/plugins.ts +0 -8
  1211. package/src/inspectors/session-roots-codec.ts +0 -31
  1212. package/src/inspectors/shell-command.ts +0 -16
  1213. package/src/inspectors/types.ts +0 -51
  1214. package/src/integrations/herdr-status.ts +0 -400
  1215. package/src/integrations/pi-web-session-liveness.ts +0 -73
  1216. package/src/intercom/intercom-bridge.ts +0 -233
  1217. package/src/intercom/native-supervisor-channel.ts +0 -917
  1218. package/src/intercom/result-intercom.ts +0 -423
  1219. package/src/intercom/supervisor-ui.ts +0 -244
  1220. package/src/missions/actions.ts +0 -433
  1221. package/src/missions/goal-driver.ts +0 -164
  1222. package/src/missions/lifecycle.ts +0 -367
  1223. package/src/missions/store.ts +0 -584
  1224. package/src/missions/types.ts +0 -190
  1225. package/src/missions/workflow-state.ts +0 -281
  1226. package/src/policy/authority.ts +0 -50
  1227. package/src/profiles/profiles.ts +0 -668
  1228. package/src/runs/background/active-async-capacity.ts +0 -520
  1229. package/src/runs/background/active-run-index.ts +0 -155
  1230. package/src/runs/background/async-execution.ts +0 -2278
  1231. package/src/runs/background/async-job-tracker.ts +0 -826
  1232. package/src/runs/background/async-resume.ts +0 -647
  1233. package/src/runs/background/async-retention.ts +0 -912
  1234. package/src/runs/background/async-status-snapshot.ts +0 -46
  1235. package/src/runs/background/async-status.ts +0 -771
  1236. package/src/runs/background/auto-drain.ts +0 -92
  1237. package/src/runs/background/binary-bootstrap.ts +0 -38
  1238. package/src/runs/background/chain-append.ts +0 -321
  1239. package/src/runs/background/chain-root-attachment.ts +0 -259
  1240. package/src/runs/background/completion-batcher.ts +0 -168
  1241. package/src/runs/background/completion-dedupe.ts +0 -58
  1242. package/src/runs/background/completion-replay.ts +0 -287
  1243. package/src/runs/background/control-channel.ts +0 -600
  1244. package/src/runs/background/fleet-view.ts +0 -648
  1245. package/src/runs/background/index-segment.ts +0 -59
  1246. package/src/runs/background/inspect-rpc.ts +0 -443
  1247. package/src/runs/background/notify.ts +0 -819
  1248. package/src/runs/background/owned-process-tree.ts +0 -131
  1249. package/src/runs/background/parallel-groups.ts +0 -45
  1250. package/src/runs/background/process-terminal.ts +0 -310
  1251. package/src/runs/background/result-delivery-ownership.ts +0 -45
  1252. package/src/runs/background/result-files.ts +0 -523
  1253. package/src/runs/background/result-watcher.ts +0 -809
  1254. package/src/runs/background/resume-guidance.ts +0 -56
  1255. package/src/runs/background/retained-children.ts +0 -135
  1256. package/src/runs/background/retained-nested-route-tracker.ts +0 -96
  1257. package/src/runs/background/run-child-session.ts +0 -690
  1258. package/src/runs/background/run-id-query.ts +0 -7
  1259. package/src/runs/background/run-id-resolver.ts +0 -175
  1260. package/src/runs/background/run-status.ts +0 -786
  1261. package/src/runs/background/runner-aliases.ts +0 -142
  1262. package/src/runs/background/runner-child-launch.ts +0 -91
  1263. package/src/runs/background/runner-child-sessions.ts +0 -32
  1264. package/src/runs/background/runner-http-dispatcher.ts +0 -119
  1265. package/src/runs/background/scheduled-runs.ts +0 -1012
  1266. package/src/runs/background/stale-run-reconciler.ts +0 -436
  1267. package/src/runs/background/steering.ts +0 -260
  1268. package/src/runs/background/subagent-runner.ts +0 -5357
  1269. package/src/runs/background/subagent-wait.ts +0 -876
  1270. package/src/runs/background/terminal-run-index.ts +0 -138
  1271. package/src/runs/background/top-level-async.ts +0 -14
  1272. package/src/runs/background/wait-completions.ts +0 -261
  1273. package/src/runs/background/wait-config.ts +0 -50
  1274. package/src/runs/background/wait-subscriptions.ts +0 -354
  1275. package/src/runs/background/wait-tool.ts +0 -45
  1276. package/src/runs/foreground/async-dismiss-action.ts +0 -86
  1277. package/src/runs/foreground/async-steering-action.ts +0 -276
  1278. package/src/runs/foreground/async-stop-action.ts +0 -176
  1279. package/src/runs/foreground/execution.ts +0 -2254
  1280. package/src/runs/foreground/foreground-control.ts +0 -157
  1281. package/src/runs/foreground/foreground-history.ts +0 -163
  1282. package/src/runs/foreground/prompt-audit.ts +0 -178
  1283. package/src/runs/foreground/subagent-executor.ts +0 -7526
  1284. package/src/runs/foreground/workflow-detach-reconcile.ts +0 -304
  1285. package/src/runs/foreground/workflow-foreground-steering.ts +0 -169
  1286. package/src/runs/shared/abort-recovery.ts +0 -119
  1287. package/src/runs/shared/acceptance.ts +0 -1698
  1288. package/src/runs/shared/agent-contract.ts +0 -38
  1289. package/src/runs/shared/async-status-projection.ts +0 -659
  1290. package/src/runs/shared/background-process-options.ts +0 -9
  1291. package/src/runs/shared/capability-ceiling.ts +0 -211
  1292. package/src/runs/shared/chain-outputs.ts +0 -116
  1293. package/src/runs/shared/child-hooks.ts +0 -189
  1294. package/src/runs/shared/child-identity.ts +0 -62
  1295. package/src/runs/shared/child-launch-plan.ts +0 -163
  1296. package/src/runs/shared/child-launch.ts +0 -342
  1297. package/src/runs/shared/child-lifecycle.ts +0 -28
  1298. package/src/runs/shared/child-runtime-config.ts +0 -133
  1299. package/src/runs/shared/child-session.ts +0 -448
  1300. package/src/runs/shared/child-tool-plan.ts +0 -661
  1301. package/src/runs/shared/claude-code-adapter.ts +0 -133
  1302. package/src/runs/shared/codex-exec-adapter.ts +0 -129
  1303. package/src/runs/shared/completion-evidence.ts +0 -89
  1304. package/src/runs/shared/completion-guard.ts +0 -255
  1305. package/src/runs/shared/context-mode.ts +0 -44
  1306. package/src/runs/shared/cursor-agent-adapter.ts +0 -114
  1307. package/src/runs/shared/dynamic-fanout.ts +0 -297
  1308. package/src/runs/shared/effective-system-prompt.ts +0 -33
  1309. package/src/runs/shared/extension-bindings.ts +0 -78
  1310. package/src/runs/shared/external-cli-contract.ts +0 -177
  1311. package/src/runs/shared/external-cli-preflight.ts +0 -142
  1312. package/src/runs/shared/external-cli-runner.ts +0 -431
  1313. package/src/runs/shared/external-job-bridge.ts +0 -460
  1314. package/src/runs/shared/external-job-runner.ts +0 -389
  1315. package/src/runs/shared/fast-mode-extension.ts +0 -10
  1316. package/src/runs/shared/herdr-connection.ts +0 -134
  1317. package/src/runs/shared/herdr-external-adapters.ts +0 -169
  1318. package/src/runs/shared/herdr-machine.ts +0 -279
  1319. package/src/runs/shared/herdr-pi-protocol.ts +0 -59
  1320. package/src/runs/shared/herdr-placed-run.ts +0 -263
  1321. package/src/runs/shared/host-step-status.ts +0 -231
  1322. package/src/runs/shared/lane-metadata.ts +0 -126
  1323. package/src/runs/shared/launch-cwd.ts +0 -16
  1324. package/src/runs/shared/llm-intent-arbiter.ts +0 -321
  1325. package/src/runs/shared/long-running-guard.ts +0 -221
  1326. package/src/runs/shared/mcp-config-sources.ts +0 -422
  1327. package/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -484
  1328. package/src/runs/shared/mcp-direct-tool-grant.ts +0 -194
  1329. package/src/runs/shared/model-resolution-diagnostic.ts +0 -76
  1330. package/src/runs/shared/model-resolution.ts +0 -441
  1331. package/src/runs/shared/model-scope.ts +0 -205
  1332. package/src/runs/shared/mutation-evidence.ts +0 -199
  1333. package/src/runs/shared/nested-events.ts +0 -1079
  1334. package/src/runs/shared/nested-path.ts +0 -38
  1335. package/src/runs/shared/nested-render.ts +0 -127
  1336. package/src/runs/shared/orca-progress-tabs.ts +0 -510
  1337. package/src/runs/shared/parallel-handoff.ts +0 -741
  1338. package/src/runs/shared/parallel-utils.ts +0 -279
  1339. package/src/runs/shared/permissions.ts +0 -86
  1340. package/src/runs/shared/pi-spawn.ts +0 -207
  1341. package/src/runs/shared/process-signal.ts +0 -35
  1342. package/src/runs/shared/readonly-drain-observation.ts +0 -42
  1343. package/src/runs/shared/run-fanout-budget.ts +0 -267
  1344. package/src/runs/shared/run-history.ts +0 -201
  1345. package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -44
  1346. package/src/runs/shared/session-lease.ts +0 -293
  1347. package/src/runs/shared/single-output.ts +0 -304
  1348. package/src/runs/shared/spawn-budget.ts +0 -128
  1349. package/src/runs/shared/structured-output.ts +0 -236
  1350. package/src/runs/shared/subagent-control.ts +0 -294
  1351. package/src/runs/shared/subagent-prompt-runtime.ts +0 -545
  1352. package/src/runs/shared/task-intent.ts +0 -244
  1353. package/src/runs/shared/tool-availability.ts +0 -37
  1354. package/src/runs/shared/tool-budget.ts +0 -66
  1355. package/src/runs/shared/tool-timeout.ts +0 -93
  1356. package/src/runs/shared/usage-budget.ts +0 -65
  1357. package/src/runs/shared/workflow-async-child-guidance.ts +0 -18
  1358. package/src/runs/shared/workflow-graph.ts +0 -225
  1359. package/src/runs/shared/worktree-cleanup-plan.ts +0 -869
  1360. package/src/runs/shared/worktree-setup-command.ts +0 -213
  1361. package/src/runs/shared/worktree.ts +0 -1538
  1362. package/src/shared/accessible-dir.ts +0 -47
  1363. package/src/shared/agent-stream-options.ts +0 -5
  1364. package/src/shared/artifacts.ts +0 -281
  1365. package/src/shared/atomic-json.ts +0 -83
  1366. package/src/shared/capacity-resilient-json.ts +0 -102
  1367. package/src/shared/child-cache-retention.ts +0 -43
  1368. package/src/shared/child-session-name.ts +0 -46
  1369. package/src/shared/child-transcript.ts +0 -264
  1370. package/src/shared/completion-owner.ts +0 -14
  1371. package/src/shared/display-text.ts +0 -150
  1372. package/src/shared/extension-context.ts +0 -24
  1373. package/src/shared/file-coalescer.ts +0 -49
  1374. package/src/shared/file-system-retry.ts +0 -95
  1375. package/src/shared/fork-context.ts +0 -236
  1376. package/src/shared/fork-session-cwd.ts +0 -27
  1377. package/src/shared/formatters.ts +0 -146
  1378. package/src/shared/jsonl-writer.ts +0 -92
  1379. package/src/shared/launch-contract.ts +0 -198
  1380. package/src/shared/model-info.ts +0 -101
  1381. package/src/shared/model-response-aliases.ts +0 -13
  1382. package/src/shared/node-executable.ts +0 -21
  1383. package/src/shared/opencode-session-headers.ts +0 -30
  1384. package/src/shared/prompt-resources.ts +0 -11
  1385. package/src/shared/pruned-fork.ts +0 -450
  1386. package/src/shared/required-child-extensions.ts +0 -81
  1387. package/src/shared/session-file-trust.ts +0 -19
  1388. package/src/shared/session-identity.ts +0 -10
  1389. package/src/shared/session-tokens.ts +0 -55
  1390. package/src/shared/settings.ts +0 -412
  1391. package/src/shared/shortcuts.ts +0 -13
  1392. package/src/shared/status-format.ts +0 -55
  1393. package/src/shared/thinking-ceiling.ts +0 -46
  1394. package/src/shared/types.ts +0 -2983
  1395. package/src/shared/utf8.ts +0 -11
  1396. package/src/shared/utils.ts +0 -608
  1397. package/src/shared/watch-strategy.ts +0 -12
  1398. package/src/shared/workflow-child-permit.ts +0 -212
  1399. package/src/slash/delegation-adapters.ts +0 -428
  1400. package/src/slash/delegation-json.ts +0 -108
  1401. package/src/slash/delegation-request.ts +0 -176
  1402. package/src/slash/prompt-template-bridge.ts +0 -419
  1403. package/src/slash/prompt-workflows.ts +0 -287
  1404. package/src/slash/selector.ts +0 -147
  1405. package/src/slash/slash-bridge.ts +0 -192
  1406. package/src/slash/slash-commands.ts +0 -1325
  1407. package/src/slash/slash-live-state.ts +0 -310
  1408. package/src/slash/subagents-admin.ts +0 -460
  1409. package/src/tui/fleet-status.ts +0 -1109
  1410. package/src/tui/fleet-transcript.ts +0 -536
  1411. package/src/tui/fleet.ts +0 -1448
  1412. package/src/tui/render-helpers.ts +0 -111
  1413. package/src/tui/render.ts +0 -3721
  1414. package/src/types/pi-runtime-compat.d.ts +0 -8
  1415. package/src/watchdog/change-signature.ts +0 -260
  1416. package/src/watchdog/child-status.ts +0 -225
  1417. package/src/watchdog/diff-tool.ts +0 -77
  1418. package/src/watchdog/emission-guard.ts +0 -125
  1419. package/src/watchdog/guidance.ts +0 -20
  1420. package/src/watchdog/lsp-diagnostics.ts +0 -538
  1421. package/src/watchdog/model-selection.ts +0 -187
  1422. package/src/watchdog/permission-arbiter.ts +0 -156
  1423. package/src/watchdog/register-child.ts +0 -128
  1424. package/src/watchdog/register-main.ts +0 -445
  1425. package/src/watchdog/render.ts +0 -53
  1426. package/src/watchdog/review.ts +0 -363
  1427. package/src/watchdog/rules.ts +0 -70
  1428. package/src/watchdog/runtime.ts +0 -924
  1429. package/src/watchdog/scope.ts +0 -51
  1430. package/src/watchdog/settings.ts +0 -515
  1431. package/src/watchdog/tool-actions.ts +0 -156
  1432. package/src/watchdog/turn-delta.ts +0 -184
  1433. package/src/watchdog/types.ts +0 -186
  1434. package/src/watchdog/warning-format.ts +0 -72
  1435. package/src/workflows/chat-progress.ts +0 -152
  1436. package/src/workflows/host-command.ts +0 -235
  1437. package/src/workflows/scripted-workflow.ts +0 -2575
  1438. package/src/workflows/workflow-checklist.ts +0 -436
  1439. package/src/workflows/workflow-child-summary.ts +0 -170
  1440. package/src/workflows/workflow-preflight.ts +0 -297
  1441. package/src/workflows/workflow-receipt.ts +0 -384
  1442. package/src/workflows/workflow-resources.ts +0 -236
  1443. package/src/workflows/workflow-settlement.ts +0 -249
@@ -0,0 +1,2639 @@
1
+ /**
2
+ * Agent discovery and configuration
3
+ */
4
+ import { execSync } from "node:child_process";
5
+ import * as fs from "node:fs";
6
+ import { parse as parseYaml } from "yaml";
7
+ import * as os from "node:os";
8
+ import * as path from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import { CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL, isCodeOwnedExternalCliAdapterId, parseExternalCliCapabilityNarrowing, validateCodeOwnedProfileRunner } from "../runs/shared/external-cli-contract.js";
11
+ import { getAgentDir, getProjectConfigDir } from "../shared/utils.js";
12
+ import { expandHomePath } from "../shared/settings.js";
13
+ import { KNOWN_FIELDS } from "./agent-serializer.js";
14
+ import { parseChain, parseJsonChain } from "./chain-serializer.js";
15
+ import { mergeAgentsForScope } from "./agent-selection.js";
16
+ import { parseFrontmatter, parseFrontmatterList } from "./frontmatter.js";
17
+ import { buildRuntimeName, parsePackageName } from "./identity.js";
18
+ import { parseModelScopeConfig } from "../runs/shared/model-scope.js";
19
+ export { BUILTIN_AGENT_NAMES } from "./builtin-names.js";
20
+ export { buildRuntimeName, frontmatterNameForConfig, parsePackageName } from "./identity.js";
21
+ import { parseMemoryFrontmatter } from "./agent-memory.js";
22
+ import { validateAcceptanceInput } from "../runs/shared/acceptance.js";
23
+ import { validatePermissionRules } from "../runs/shared/permissions.js";
24
+ import { parseThinkingLevel } from "../shared/thinking-ceiling.js";
25
+ import { assertJsonSchemaObject } from "../runs/shared/structured-output.js";
26
+ import { normalizeCapabilityCeilingAllowedAgents } from "../runs/shared/capability-ceiling.js";
27
+ export function defaultSystemPromptMode(name) {
28
+ return name === "delegate" ? "append" : "replace";
29
+ }
30
+ export function defaultInheritProjectContext(name) {
31
+ return name === "delegate";
32
+ }
33
+ export function defaultInheritSkills() {
34
+ return false;
35
+ }
36
+ const EMPTY_SUBAGENT_SETTINGS = { overrides: {}, providerOverrides: {} };
37
+ const agentFrontmatterFields = new WeakMap();
38
+ const AGENT_SOURCE_PRIORITY = {
39
+ builtin: 0,
40
+ package: 1,
41
+ user: 2,
42
+ project: 3,
43
+ runtime: 4,
44
+ };
45
+ function agentDefinitionPriority(definition) {
46
+ return AGENT_SOURCE_PRIORITY[definition.source] * 1_000_000
47
+ + (definition.discoveryPriority ?? 0);
48
+ }
49
+ export function findBlockingAgentDiagnostic(name, agent, diagnostics) {
50
+ const normalizedName = name.trim();
51
+ const agents = Array.isArray(agent) ? agent : agent ? [agent] : [];
52
+ let match;
53
+ for (const diagnostic of diagnostics ?? []) {
54
+ if ((diagnostic.runtimeName === normalizedName
55
+ || (diagnostic.name === normalizedName && (!diagnostic.packageSpecified
56
+ || diagnostic.runtimeName === undefined
57
+ || agents.some((agent) => agent.name === diagnostic.runtimeName && agent.localName === diagnostic.name))))
58
+ && (!match || agentDefinitionPriority(diagnostic) > agentDefinitionPriority(match))) {
59
+ match = diagnostic;
60
+ }
61
+ }
62
+ const highestPriority = Math.max(...agents.map(agentDefinitionPriority), -Infinity);
63
+ return !agents.length || (match && agentDefinitionPriority(match) > highestPriority) ? match : undefined;
64
+ }
65
+ /** Create formatter input from the exact discovery operation used for resolution. */
66
+ export function unknownAgentDiagnosticContext(discovered) {
67
+ return {
68
+ cwd: discovered.cwd,
69
+ scope: discovered.scope,
70
+ directories: discovered.directories,
71
+ agents: discovered.agents,
72
+ };
73
+ }
74
+ /** Render local discovery evidence without exposing filesystem error details. */
75
+ export function formatUnknownAgentError(name, context, prefix = "Unknown agent") {
76
+ const directories = context.directories.map((directory) => {
77
+ const state = directory.state === "candidates"
78
+ ? `${directory.candidateCount ?? 0} candidate${directory.candidateCount === 1 ? "" : "s"}`
79
+ : directory.state === "empty" ? "present but empty"
80
+ : directory.state === "not-directory" ? "not a directory"
81
+ : directory.state;
82
+ return `- ${directory.source}: ${directory.path} (${state})`;
83
+ });
84
+ const agents = [...context.agents]
85
+ .sort((left, right) => left.name.localeCompare(right.name) || left.source.localeCompare(right.source))
86
+ .map((agent) => `- ${agent.name} (${agent.source})`);
87
+ return [
88
+ `${prefix}: ${name}`,
89
+ `Effective cwd: ${path.resolve(context.cwd)}`,
90
+ "Consulted agent-definition directories:",
91
+ ...(directories.length ? directories : ["- (none)"]),
92
+ "Discovered agents:",
93
+ ...(agents.length ? agents : ["- (none)"]),
94
+ ].join("\n");
95
+ }
96
+ function getUserChainDir() {
97
+ return path.join(getAgentDir(), "chains");
98
+ }
99
+ let cachedGlobalNpmRoot = null;
100
+ function readJsonFileBestEffort(filePath) {
101
+ try {
102
+ return JSON.parse(fs.readFileSync(filePath, "utf-8"));
103
+ }
104
+ catch {
105
+ // Installed package scans are opportunistic; bad third-party manifests
106
+ // should not break local agent discovery.
107
+ return null;
108
+ }
109
+ }
110
+ function isSafePackagePath(value) {
111
+ return value.length > 0
112
+ && !path.isAbsolute(value)
113
+ && value.split(/[\\/]/).every((part) => part.length > 0 && part !== "." && part !== "..");
114
+ }
115
+ function parseNpmPackageName(source) {
116
+ const spec = source.slice(4).trim();
117
+ if (!spec)
118
+ return undefined;
119
+ const match = spec.match(/^(@?[^@]+(?:\/[^@]+)?)(?:@(.+))?$/);
120
+ const packageName = match?.[1] ?? spec;
121
+ return isSafePackagePath(packageName) ? packageName : undefined;
122
+ }
123
+ function stripGitRef(repoPath) {
124
+ const atIndex = repoPath.indexOf("@");
125
+ const hashIndex = repoPath.indexOf("#");
126
+ const refIndex = [atIndex, hashIndex].filter((index) => index >= 0).sort((a, b) => a - b)[0];
127
+ return refIndex === undefined ? repoPath : repoPath.slice(0, refIndex);
128
+ }
129
+ function parseGitPackagePath(source) {
130
+ const spec = source.slice(4).trim();
131
+ if (!spec)
132
+ return undefined;
133
+ let host = "";
134
+ let repoPath = "";
135
+ const scpLike = spec.match(/^git@([^:]+):(.+)$/);
136
+ if (scpLike) {
137
+ host = scpLike[1] ?? "";
138
+ repoPath = scpLike[2] ?? "";
139
+ }
140
+ else if (/^[a-z][a-z0-9+.-]*:\/\//i.test(spec)) {
141
+ try {
142
+ const url = new URL(spec);
143
+ host = url.hostname;
144
+ repoPath = url.pathname.replace(/^\/+/, "");
145
+ }
146
+ catch {
147
+ return undefined;
148
+ }
149
+ }
150
+ else {
151
+ const slashIndex = spec.indexOf("/");
152
+ if (slashIndex < 0)
153
+ return undefined;
154
+ host = spec.slice(0, slashIndex);
155
+ repoPath = spec.slice(slashIndex + 1);
156
+ }
157
+ const normalizedPath = stripGitRef(repoPath).replace(/\.git$/, "").replace(/^\/+/, "");
158
+ if (!host || !isSafePackagePath(host) || !isSafePackagePath(normalizedPath) || normalizedPath.split(/[\\/]/).length < 2) {
159
+ return undefined;
160
+ }
161
+ return { host, repoPath: normalizedPath };
162
+ }
163
+ function resolveSettingsPackageRoot(source, baseDir) {
164
+ const trimmed = source.trim();
165
+ if (!trimmed)
166
+ return undefined;
167
+ if (trimmed.startsWith("git:")) {
168
+ const parsed = parseGitPackagePath(trimmed);
169
+ return parsed ? path.join(baseDir, "git", parsed.host, parsed.repoPath) : undefined;
170
+ }
171
+ if (trimmed.startsWith("npm:")) {
172
+ const packageName = parseNpmPackageName(trimmed);
173
+ return packageName ? path.join(baseDir, "npm", "node_modules", packageName) : undefined;
174
+ }
175
+ const normalized = trimmed.startsWith("file:") ? trimmed.slice(5) : trimmed;
176
+ if (normalized === "~")
177
+ return os.homedir();
178
+ if (normalized.startsWith("~/"))
179
+ return path.join(os.homedir(), normalized.slice(2));
180
+ if (path.isAbsolute(normalized))
181
+ return normalized;
182
+ if (normalized === "." || normalized === ".." || normalized.startsWith("./") || normalized.startsWith("../")) {
183
+ return path.resolve(baseDir, normalized);
184
+ }
185
+ if (/^https?:\/\//i.test(trimmed)) {
186
+ const parsed = parseGitPackagePath(`git:${trimmed}`);
187
+ return parsed ? path.join(baseDir, "git", parsed.host, parsed.repoPath) : undefined;
188
+ }
189
+ return undefined;
190
+ }
191
+ function getGlobalNpmRoot() {
192
+ const offline = process.env.PI_OFFLINE?.toLowerCase();
193
+ if (offline === "1" || offline === "true" || offline === "yes")
194
+ return null;
195
+ if (cachedGlobalNpmRoot !== null)
196
+ return cachedGlobalNpmRoot;
197
+ const windowsGlobalRoot = process.platform === "win32" && process.env.APPDATA
198
+ ? path.join(process.env.APPDATA, "npm", "node_modules")
199
+ : undefined;
200
+ if (windowsGlobalRoot) {
201
+ try {
202
+ if (fs.statSync(windowsGlobalRoot).isDirectory()) {
203
+ cachedGlobalNpmRoot = fs.realpathSync(windowsGlobalRoot);
204
+ return cachedGlobalNpmRoot;
205
+ }
206
+ }
207
+ catch {
208
+ // Fall through if the directory disappears while resolving it.
209
+ }
210
+ }
211
+ try {
212
+ cachedGlobalNpmRoot = fs.realpathSync(execSync("npm root -g", { encoding: "utf-8", timeout: 5000, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }).trim());
213
+ return cachedGlobalNpmRoot;
214
+ }
215
+ catch {
216
+ cachedGlobalNpmRoot = "";
217
+ return null;
218
+ }
219
+ }
220
+ function stringArray(value) {
221
+ if (!Array.isArray(value))
222
+ return [];
223
+ return value.filter((entry) => typeof entry === "string" && entry.trim().length > 0);
224
+ }
225
+ function packageMetadata(pkg, packageRoot) {
226
+ const name = typeof pkg.name === "string" && pkg.name.trim() ? pkg.name.trim() : undefined;
227
+ const version = typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : undefined;
228
+ return {
229
+ packageRoot,
230
+ ...(name ? { packageName: name } : {}),
231
+ ...(version ? { packageVersion: version } : {}),
232
+ };
233
+ }
234
+ function extractSubagentPathsFromPackageRoot(packageRoot, scope) {
235
+ const packageJsonPath = path.join(packageRoot, "package.json");
236
+ const pkg = readJsonFileBestEffort(packageJsonPath);
237
+ if (!pkg || typeof pkg !== "object" || Array.isArray(pkg))
238
+ return { agents: [], chains: [], watchPaths: [packageJsonPath], settingsErrors: {} };
239
+ const pkgRecord = pkg;
240
+ const metadata = packageMetadata(pkgRecord, packageRoot);
241
+ const roots = [];
242
+ const piSubagents = pkgRecord["pi-subagents"];
243
+ if (piSubagents && typeof piSubagents === "object" && !Array.isArray(piSubagents)) {
244
+ roots.push(piSubagents);
245
+ }
246
+ const pi = pkgRecord.pi;
247
+ if (pi && typeof pi === "object" && !Array.isArray(pi)) {
248
+ const subagents = pi.subagents;
249
+ if (subagents && typeof subagents === "object" && !Array.isArray(subagents)) {
250
+ roots.push(subagents);
251
+ }
252
+ }
253
+ const agents = [];
254
+ const chains = [];
255
+ for (const root of roots) {
256
+ for (const entry of stringArray(root.agents))
257
+ agents.push({ dir: path.resolve(packageRoot, entry), scope, ...metadata });
258
+ for (const entry of stringArray(root.chains))
259
+ chains.push({ dir: path.resolve(packageRoot, entry), scope, packageRoot });
260
+ }
261
+ return { agents, chains, watchPaths: [packageJsonPath], settingsErrors: {} };
262
+ }
263
+ function collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths) {
264
+ const roots = [];
265
+ watchPaths?.push(nodeModulesDir);
266
+ if (!fs.existsSync(nodeModulesDir))
267
+ return roots;
268
+ let entries;
269
+ try {
270
+ entries = fs.readdirSync(nodeModulesDir, { withFileTypes: true });
271
+ }
272
+ catch {
273
+ return roots;
274
+ }
275
+ for (const entry of entries) {
276
+ if (entry.name.startsWith("."))
277
+ continue;
278
+ if (!entry.isDirectory() && !entry.isSymbolicLink())
279
+ continue;
280
+ if (entry.name.startsWith("@")) {
281
+ const scopeDir = path.join(nodeModulesDir, entry.name);
282
+ watchPaths?.push(scopeDir);
283
+ let scopeEntries;
284
+ try {
285
+ scopeEntries = fs.readdirSync(scopeDir, { withFileTypes: true });
286
+ }
287
+ catch {
288
+ continue;
289
+ }
290
+ for (const scopeEntry of scopeEntries) {
291
+ if (scopeEntry.name.startsWith("."))
292
+ continue;
293
+ if (!scopeEntry.isDirectory() && !scopeEntry.isSymbolicLink())
294
+ continue;
295
+ roots.push(path.join(scopeDir, scopeEntry.name));
296
+ }
297
+ continue;
298
+ }
299
+ roots.push(path.join(nodeModulesDir, entry.name));
300
+ }
301
+ return roots;
302
+ }
303
+ function collectSettingsPackageRoots(settingsFile, baseDir) {
304
+ const settings = readSettingsFileStrict(settingsFile);
305
+ const packages = settings.packages;
306
+ if (!Array.isArray(packages))
307
+ return [];
308
+ const roots = [];
309
+ for (const entry of packages) {
310
+ const packageSource = typeof entry === "string"
311
+ ? entry
312
+ : typeof entry === "object" && entry !== null && "source" in entry && typeof entry.source === "string"
313
+ ? entry.source
314
+ : undefined;
315
+ if (!packageSource)
316
+ continue;
317
+ const packageRoot = resolveSettingsPackageRoot(packageSource, baseDir);
318
+ if (packageRoot)
319
+ roots.push(packageRoot);
320
+ }
321
+ return roots;
322
+ }
323
+ function collectPackageSubagentPaths(cwd, options = { includeUser: true, includeProject: true }) {
324
+ const agentDir = getAgentDir();
325
+ const projectRoot = findConfiguredProjectRoot(cwd) ?? cwd;
326
+ const packageRoots = [
327
+ { root: projectRoot, scope: "root" },
328
+ ];
329
+ const watchPaths = [path.join(projectRoot, "package.json")];
330
+ const settingsErrors = {};
331
+ const collectScopedSettingsRoots = (scope, settingsFile, baseDir) => {
332
+ try {
333
+ return collectSettingsPackageRoots(settingsFile, baseDir);
334
+ }
335
+ catch (error) {
336
+ // The raw source snapshot includes both settings scopes. Defer a
337
+ // strict failure until a projection actually selects this scope so an
338
+ // unrelated malformed settings file stays out of scoped discovery.
339
+ settingsErrors[scope] = error instanceof Error
340
+ ? error
341
+ : new Error(`Failed to read settings file '${settingsFile}': ${String(error)}`, { cause: error });
342
+ return [];
343
+ }
344
+ };
345
+ if (options.includeProject) {
346
+ const projectConfigDir = getProjectConfigDir(projectRoot);
347
+ const nodeModulesDir = path.join(projectConfigDir, "npm", "node_modules");
348
+ packageRoots.push(...collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths).map((root) => ({ root, scope: "project" })));
349
+ packageRoots.push(...collectScopedSettingsRoots("project", path.join(projectConfigDir, "settings.json"), projectConfigDir).map((root) => ({ root, scope: "project" })));
350
+ }
351
+ if (options.includeUser) {
352
+ const nodeModulesDir = path.join(agentDir, "npm", "node_modules");
353
+ packageRoots.push(...collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths).map((root) => ({ root, scope: "user" })));
354
+ packageRoots.push(...collectScopedSettingsRoots("user", path.join(agentDir, "settings.json"), agentDir).map((root) => ({ root, scope: "user" })));
355
+ }
356
+ if (options.includeUser) {
357
+ const globalRoot = getGlobalNpmRoot();
358
+ if (globalRoot) {
359
+ packageRoots.push(...collectPackageRootsFromNodeModules(globalRoot, watchPaths).map((root) => ({ root, scope: "user" })));
360
+ }
361
+ }
362
+ const seenRoots = new Map();
363
+ const seenAgents = new Map();
364
+ const seenChains = new Map();
365
+ const agents = [];
366
+ const chains = [];
367
+ for (const { root: packageRoot, scope } of packageRoots) {
368
+ const resolvedRoot = path.resolve(packageRoot);
369
+ const scopes = seenRoots.get(resolvedRoot);
370
+ if (scopes !== undefined) {
371
+ scopes.add(scope);
372
+ continue;
373
+ }
374
+ const packageScopes = new Set([scope]);
375
+ seenRoots.set(resolvedRoot, packageScopes);
376
+ const paths = extractSubagentPathsFromPackageRoot(resolvedRoot, packageScopes);
377
+ watchPaths.push(...paths.watchPaths);
378
+ for (const agentPath of paths.agents) {
379
+ const agentKey = `${agentPath.dir}\u0000${agentPath.packageRoot}`;
380
+ const existing = seenAgents.get(agentKey);
381
+ if (existing) {
382
+ for (const packageScope of agentPath.scope)
383
+ existing.scope.add(packageScope);
384
+ continue;
385
+ }
386
+ seenAgents.set(agentKey, agentPath);
387
+ agents.push(agentPath);
388
+ }
389
+ for (const chainDir of paths.chains) {
390
+ const chainKey = `${chainDir.dir}\u0000${chainDir.packageRoot}`;
391
+ const existing = seenChains.get(chainKey);
392
+ if (existing) {
393
+ for (const packageScope of chainDir.scope)
394
+ existing.scope.add(packageScope);
395
+ continue;
396
+ }
397
+ seenChains.set(chainKey, chainDir);
398
+ chains.push(chainDir);
399
+ }
400
+ }
401
+ return { agents, chains, watchPaths, settingsErrors };
402
+ }
403
+ function normalizeAgentAliases(rawAliases, agentName) {
404
+ const aliases = [...new Set((rawAliases ?? []).map((alias) => alias.trim()).filter(Boolean))]
405
+ .filter((alias) => alias !== agentName);
406
+ return aliases.length > 0 ? aliases : undefined;
407
+ }
408
+ function effectiveAgentMatch(matches) {
409
+ const distinctNames = [...new Set(matches.map((agent) => agent.name))];
410
+ if (distinctNames.length === 1) {
411
+ const sourceRank = new Map([["builtin", 0], ["package", 1], ["user", 2], ["project", 3], ["runtime", 4]]);
412
+ const agent = [...matches].sort((a, b) => (sourceRank.get(b.source) ?? 0) - (sourceRank.get(a.source) ?? 0))[0];
413
+ return agent ? { agent } : {};
414
+ }
415
+ return {};
416
+ }
417
+ export function resolveAgentName(name, agents) {
418
+ const raw = name.trim();
419
+ const canonical = agents.filter((agent) => agent.name === raw);
420
+ if (canonical.length === 1)
421
+ return canonical[0] ? { agent: canonical[0] } : {};
422
+ if (canonical.length > 1) {
423
+ const effective = effectiveAgentMatch(canonical);
424
+ if (effective.agent)
425
+ return effective;
426
+ return { error: `Ambiguous agent name '${name}': ${canonical.map((agent) => agent.name).join(", ")}` };
427
+ }
428
+ const local = agents.filter((agent) => agent.localName === raw);
429
+ if (local.length === 1)
430
+ return local[0] ? { agent: local[0] } : {};
431
+ if (local.length > 1) {
432
+ const effective = effectiveAgentMatch(local);
433
+ if (effective.agent)
434
+ return effective;
435
+ return { error: `Ambiguous local agent name '${name}': ${local.map((agent) => agent.name).join(", ")}` };
436
+ }
437
+ const aliases = agents.filter((agent) => agent.aliases?.includes(raw));
438
+ if (aliases.length === 1)
439
+ return aliases[0] ? { agent: aliases[0] } : {};
440
+ if (aliases.length > 1) {
441
+ const effective = effectiveAgentMatch(aliases);
442
+ if (effective.agent)
443
+ return effective;
444
+ return { error: `Ambiguous agent alias '${name}': ${aliases.map((agent) => agent.name).join(", ")}` };
445
+ }
446
+ return {};
447
+ }
448
+ function splitToolList(rawTools) {
449
+ const mcpDirectTools = [];
450
+ const tools = [];
451
+ for (const tool of rawTools ?? []) {
452
+ if (tool.startsWith("mcp:")) {
453
+ mcpDirectTools.push(tool.slice(4));
454
+ }
455
+ else {
456
+ tools.push(tool);
457
+ }
458
+ }
459
+ return {
460
+ ...(rawTools !== undefined ? { tools } : {}),
461
+ ...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
462
+ };
463
+ }
464
+ function joinToolList(config) {
465
+ const joined = [
466
+ ...(config.tools ?? []),
467
+ ...(config.mcpDirectTools ?? []).map((tool) => `mcp:${tool}`),
468
+ ];
469
+ return joined.length > 0 ? joined : undefined;
470
+ }
471
+ function arraysEqual(a, b) {
472
+ if (!a && !b)
473
+ return true;
474
+ if (!a || !b)
475
+ return false;
476
+ if (a.length !== b.length)
477
+ return false;
478
+ for (let i = 0; i < a.length; i++) {
479
+ if (a[i] !== b[i])
480
+ return false;
481
+ }
482
+ return true;
483
+ }
484
+ function cloneOverrideBase(agent) {
485
+ return {
486
+ description: agent.description,
487
+ ...(agent.machine !== undefined ? { machine: agent.machine } : {}),
488
+ ...(agent.output !== undefined ? { output: agent.output } : {}),
489
+ ...(agent.outputMode !== undefined ? { outputMode: agent.outputMode } : {}),
490
+ ...(agent.defaultReads !== undefined ? { defaultReads: [...agent.defaultReads] } : {}),
491
+ ...(agent.model !== undefined ? { model: agent.model } : {}),
492
+ ...(agent.modelProvider !== undefined ? { modelProvider: agent.modelProvider } : {}),
493
+ ...(agent.fast !== undefined ? { fast: agent.fast } : {}),
494
+ ...(agent.thinking !== undefined ? { thinking: agent.thinking } : {}),
495
+ systemPromptMode: agent.systemPromptMode,
496
+ inheritProjectContext: agent.inheritProjectContext,
497
+ inheritGlobalContext: agent.inheritGlobalContext,
498
+ inheritSkills: agent.inheritSkills,
499
+ ...(agent.defaultContext !== undefined ? { defaultContext: agent.defaultContext } : {}),
500
+ ...(agent.acceptanceRole !== undefined ? { acceptanceRole: agent.acceptanceRole } : {}),
501
+ ...(agent.disabled !== undefined ? { disabled: agent.disabled } : {}),
502
+ systemPrompt: agent.systemPrompt,
503
+ ...(agent.skills ? { skills: [...agent.skills] } : {}),
504
+ ...(agent.skillPath ? { skillPath: [...agent.skillPath] } : {}),
505
+ ...(agent.tools ? { tools: [...agent.tools] } : {}),
506
+ ...(agent.excludeTools ? { excludeTools: [...agent.excludeTools] } : {}),
507
+ ...(agent.allowNestedSubagents !== undefined ? { allowNestedSubagents: agent.allowNestedSubagents } : {}),
508
+ ...(agent.allowedAgents !== undefined ? { allowedAgents: [...agent.allowedAgents] } : {}),
509
+ ...(agent.mcpDirectTools ? { mcpDirectTools: [...agent.mcpDirectTools] } : {}),
510
+ ...(!agent.extensionsFromDefault && agent.extensions ? { extensions: [...agent.extensions] } : {}),
511
+ ...(agent.subagentOnlyExtensions ? { subagentOnlyExtensions: [...agent.subagentOnlyExtensions] } : {}),
512
+ ...(agent.mutationTools ? { mutationTools: [...agent.mutationTools] } : {}),
513
+ ...(agent.toolBudget !== undefined ? { toolBudget: agent.toolBudget } : {}),
514
+ };
515
+ }
516
+ function cloneOverrideValue(override) {
517
+ return {
518
+ ...(override.description !== undefined ? { description: override.description } : {}),
519
+ ...(override.machine !== undefined ? { machine: override.machine } : {}),
520
+ ...(override.output !== undefined ? { output: override.output } : {}),
521
+ ...(override.outputMode !== undefined ? { outputMode: override.outputMode } : {}),
522
+ ...(override.defaultReads !== undefined ? { defaultReads: override.defaultReads === false ? false : [...override.defaultReads] } : {}),
523
+ ...(override.model !== undefined ? { model: override.model } : {}),
524
+ ...(override.defaultProvider !== undefined ? { defaultProvider: override.defaultProvider } : {}),
525
+ ...(override.fast !== undefined ? { fast: override.fast } : {}),
526
+ ...(override.thinking !== undefined ? { thinking: override.thinking } : {}),
527
+ ...(override.systemPromptMode !== undefined ? { systemPromptMode: override.systemPromptMode } : {}),
528
+ ...(override.inheritProjectContext !== undefined ? { inheritProjectContext: override.inheritProjectContext } : {}),
529
+ ...(override.inheritGlobalContext !== undefined ? { inheritGlobalContext: override.inheritGlobalContext } : {}),
530
+ ...(override.inheritSkills !== undefined ? { inheritSkills: override.inheritSkills } : {}),
531
+ ...(override.defaultContext !== undefined ? { defaultContext: override.defaultContext } : {}),
532
+ ...(override.acceptanceRole !== undefined ? { acceptanceRole: override.acceptanceRole } : {}),
533
+ ...(override.disabled !== undefined ? { disabled: override.disabled } : {}),
534
+ ...(override.systemPrompt !== undefined ? { systemPrompt: override.systemPrompt } : {}),
535
+ ...(override.skills !== undefined ? { skills: override.skills === false ? false : [...override.skills] } : {}),
536
+ ...(override.tools !== undefined ? { tools: Array.isArray(override.tools) ? [...override.tools] : override.tools } : {}),
537
+ ...(override.excludeTools !== undefined ? { excludeTools: override.excludeTools === false ? false : [...override.excludeTools] } : {}),
538
+ ...(override.allowNestedSubagents !== undefined ? { allowNestedSubagents: override.allowNestedSubagents } : {}),
539
+ ...(override.allowedAgents !== undefined ? { allowedAgents: override.allowedAgents === false ? false : [...override.allowedAgents] } : {}),
540
+ ...(override.extensions !== undefined ? { extensions: override.extensions === false ? false : [...override.extensions] } : {}),
541
+ ...(override.subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions: override.subagentOnlyExtensions === false ? false : [...override.subagentOnlyExtensions] } : {}),
542
+ ...(override.mutationTools !== undefined ? { mutationTools: override.mutationTools === false ? false : [...override.mutationTools] } : {}),
543
+ ...(override.toolBudget !== undefined ? { toolBudget: override.toolBudget === false ? false : { ...override.toolBudget, ...(Array.isArray(override.toolBudget.block) ? { block: [...override.toolBudget.block] } : {}) } } : {}),
544
+ };
545
+ }
546
+ function isProjectRootCandidate(dir) {
547
+ return isDirectory(getProjectConfigDir(dir)) || isDirectory(path.join(dir, ".agents"));
548
+ }
549
+ function findProjectRootCandidates(cwd) {
550
+ const roots = [];
551
+ const windowsProfile = process.env.HOMEDRIVE && process.env.HOMEPATH
552
+ ? `${process.env.HOMEDRIVE}${process.env.HOMEPATH}`
553
+ : undefined;
554
+ const homeDirs = new Set([os.homedir(), process.env.HOME, process.env.USERPROFILE, windowsProfile]
555
+ .filter((value) => Boolean(value?.trim()))
556
+ .filter(isDirectory)
557
+ .map((value) => fs.realpathSync.native(value)));
558
+ let currentDir = cwd;
559
+ while (true) {
560
+ // ~/.pi and ~/.agents are user configuration, never an implicit project.
561
+ if (isDirectory(currentDir) && homeDirs.has(fs.realpathSync.native(currentDir)))
562
+ return roots;
563
+ if (isProjectRootCandidate(currentDir))
564
+ roots.push(currentDir);
565
+ const parentDir = path.dirname(currentDir);
566
+ if (parentDir === currentDir)
567
+ return roots;
568
+ currentDir = parentDir;
569
+ }
570
+ }
571
+ export function findNearestGitRoot(cwd) {
572
+ let currentDir = cwd;
573
+ while (true) {
574
+ if (fs.existsSync(path.join(currentDir, ".git")))
575
+ return currentDir;
576
+ const parentDir = path.dirname(currentDir);
577
+ if (parentDir === currentDir)
578
+ return null;
579
+ currentDir = parentDir;
580
+ }
581
+ }
582
+ function readProjectRootResolution(projectRoot) {
583
+ const settingsPath = path.join(getProjectConfigDir(projectRoot), "settings.json");
584
+ if (!fs.existsSync(settingsPath))
585
+ return undefined;
586
+ const settings = readSettingsFileStrict(settingsPath);
587
+ const subagents = settings.subagents;
588
+ if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
589
+ return undefined;
590
+ const value = subagents.projectRootResolution;
591
+ if (value === undefined)
592
+ return undefined;
593
+ if (value === "nearest" || value === "git-root")
594
+ return value;
595
+ throw new Error(`Subagent settings in '${settingsPath}' have invalid 'projectRootResolution'; expected 'nearest' or 'git-root'.`);
596
+ }
597
+ export function findNearestProjectRoot(cwd) {
598
+ return findProjectRootCandidates(cwd)[0] ?? null;
599
+ }
600
+ export function findConfiguredProjectRoot(cwd) {
601
+ const candidates = findProjectRootCandidates(cwd);
602
+ const nearestRoot = candidates[0];
603
+ if (!nearestRoot)
604
+ return null;
605
+ let policyRoot;
606
+ let policyRootIndex = -1;
607
+ for (const [index, candidate] of candidates.entries()) {
608
+ const mode = readProjectRootResolution(candidate);
609
+ if (mode === "nearest")
610
+ return nearestRoot;
611
+ if (mode === "git-root") {
612
+ policyRoot = candidate;
613
+ policyRootIndex = index;
614
+ break;
615
+ }
616
+ }
617
+ if (!policyRoot)
618
+ return nearestRoot;
619
+ const gitRoot = findNearestGitRoot(cwd);
620
+ const gitProjectRoot = gitRoot
621
+ ? candidates.slice(policyRootIndex).find((candidate) => path.resolve(candidate) === path.resolve(gitRoot))
622
+ : undefined;
623
+ const configuredGitRoot = fs.existsSync(path.join(policyRoot, ".git")) ? policyRoot : undefined;
624
+ return gitProjectRoot ?? configuredGitRoot ?? nearestRoot;
625
+ }
626
+ function getUserAgentSettingsPath() {
627
+ return path.join(getAgentDir(), "settings.json");
628
+ }
629
+ function getProjectAgentSettingsPath(cwd) {
630
+ const projectRoot = findConfiguredProjectRoot(cwd);
631
+ return projectRoot ? path.join(getProjectConfigDir(projectRoot), "settings.json") : null;
632
+ }
633
+ function readSettingsFileStrict(filePath) {
634
+ if (!fs.existsSync(filePath))
635
+ return {};
636
+ let raw;
637
+ try {
638
+ raw = fs.readFileSync(filePath, "utf-8");
639
+ }
640
+ catch (error) {
641
+ const message = error instanceof Error ? error.message : String(error);
642
+ throw new Error(`Failed to read settings file '${filePath}': ${message}`, { cause: error });
643
+ }
644
+ let parsed;
645
+ try {
646
+ parsed = JSON.parse(raw);
647
+ }
648
+ catch (error) {
649
+ const message = error instanceof Error ? error.message : String(error);
650
+ throw new Error(`Failed to parse settings file '${filePath}': ${message}`, { cause: error });
651
+ }
652
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
653
+ throw new Error(`Settings file '${filePath}' must contain a JSON object.`);
654
+ }
655
+ return parsed;
656
+ }
657
+ function writeSettingsFile(filePath, settings) {
658
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
659
+ fs.writeFileSync(filePath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
660
+ }
661
+ function parseOverrideStringArrayOrFalse(value, meta) {
662
+ if (value === undefined)
663
+ return undefined;
664
+ if (value === false)
665
+ return false;
666
+ if (!Array.isArray(value)) {
667
+ throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid '${meta.field}'; expected an array of strings or false.`);
668
+ }
669
+ const items = [];
670
+ for (const item of value) {
671
+ if (typeof item !== "string") {
672
+ throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid '${meta.field}'; expected an array of strings or false.`);
673
+ }
674
+ const trimmed = item.trim();
675
+ if (trimmed)
676
+ items.push(trimmed);
677
+ }
678
+ return items;
679
+ }
680
+ function parseToolsOverride(value, meta) {
681
+ if (typeof value === "string" && value.trim() === "inherit")
682
+ return "inherit";
683
+ if (value === undefined || value === false || Array.isArray(value)) {
684
+ return parseOverrideStringArrayOrFalse(value, { ...meta, field: "tools" });
685
+ }
686
+ throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid 'tools'; expected an array of strings, "inherit", or false.`);
687
+ }
688
+ function validateOptionalMachine(value, label) {
689
+ if (value === undefined || value === false)
690
+ return undefined;
691
+ if (typeof value !== "string" || !value.trim())
692
+ throw new Error(label + " must be a non-empty string or false.");
693
+ const machine = value.trim();
694
+ if (machine.length > 128)
695
+ throw new Error(label + " must be 128 characters or fewer.");
696
+ if (/[\u0000-\u001f\u007f]/u.test(machine))
697
+ throw new Error(label + " contains control characters.");
698
+ return machine;
699
+ }
700
+ function parseBuiltinOverrideEntry(name, value, filePath) {
701
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
702
+ throw new Error(`Builtin override '${name}' in '${filePath}' must be an object.`);
703
+ }
704
+ const input = value;
705
+ if (Object.hasOwn(input, "fallbackModels")) {
706
+ throw new Error(`Builtin override '${name}' in '${filePath}' uses removed field 'fallbackModels'; configure one model instead.`);
707
+ }
708
+ const override = {};
709
+ if ("description" in input) {
710
+ if (typeof input.description === "string" && input.description.trim()) {
711
+ override.description = input.description.trim();
712
+ }
713
+ else {
714
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'description'; expected a non-empty string.`);
715
+ }
716
+ }
717
+ if ("output" in input) {
718
+ if ((typeof input.output === "string" && input.output.trim()) || input.output === false)
719
+ override.output = input.output;
720
+ else
721
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'output'; expected a non-empty string or false.`);
722
+ }
723
+ if ("outputMode" in input) {
724
+ if (input.outputMode === "inline" || input.outputMode === "file-only") {
725
+ override.outputMode = input.outputMode;
726
+ }
727
+ else {
728
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'outputMode'; expected 'inline' or 'file-only'.`);
729
+ }
730
+ }
731
+ if ("model" in input) {
732
+ if (typeof input.model === "string" || input.model === false)
733
+ override.model = input.model;
734
+ else
735
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'model'; expected a string or false.`);
736
+ }
737
+ if ("fast" in input) {
738
+ if (typeof input.fast === "boolean")
739
+ override.fast = input.fast;
740
+ else
741
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'fast'; expected a boolean.`);
742
+ }
743
+ if ("thinking" in input) {
744
+ if (typeof input.thinking === "string" || input.thinking === false)
745
+ override.thinking = input.thinking;
746
+ else
747
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected a string or false.`);
748
+ }
749
+ if ("systemPromptMode" in input) {
750
+ if (input.systemPromptMode === "append" || input.systemPromptMode === "replace") {
751
+ override.systemPromptMode = input.systemPromptMode;
752
+ }
753
+ else {
754
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPromptMode'; expected 'append' or 'replace'.`);
755
+ }
756
+ }
757
+ if ("inheritProjectContext" in input) {
758
+ if (typeof input.inheritProjectContext === "boolean") {
759
+ override.inheritProjectContext = input.inheritProjectContext;
760
+ }
761
+ else {
762
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritProjectContext'; expected a boolean.`);
763
+ }
764
+ }
765
+ if ("inheritGlobalContext" in input) {
766
+ if (typeof input.inheritGlobalContext === "boolean") {
767
+ override.inheritGlobalContext = input.inheritGlobalContext;
768
+ }
769
+ else {
770
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritGlobalContext'; expected a boolean.`);
771
+ }
772
+ }
773
+ if ("inheritSkills" in input) {
774
+ if (typeof input.inheritSkills === "boolean") {
775
+ override.inheritSkills = input.inheritSkills;
776
+ }
777
+ else {
778
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritSkills'; expected a boolean.`);
779
+ }
780
+ }
781
+ if ("defaultContext" in input) {
782
+ if (input.defaultContext === "fresh" || input.defaultContext === "fork" || input.defaultContext === false) {
783
+ override.defaultContext = input.defaultContext;
784
+ }
785
+ else {
786
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultContext'; expected 'fresh', 'fork', or false.`);
787
+ }
788
+ }
789
+ if ("acceptanceRole" in input) {
790
+ if (input.acceptanceRole === "read-only" || input.acceptanceRole === "writer" || input.acceptanceRole === false) {
791
+ override.acceptanceRole = input.acceptanceRole;
792
+ }
793
+ else {
794
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'acceptanceRole'; expected 'read-only', 'writer', or false.`);
795
+ }
796
+ }
797
+ if ("disabled" in input) {
798
+ if (typeof input.disabled === "boolean") {
799
+ override.disabled = input.disabled;
800
+ }
801
+ else {
802
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'disabled'; expected a boolean.`);
803
+ }
804
+ }
805
+ if ("toolBudget" in input) {
806
+ if (input.toolBudget === false) {
807
+ override.toolBudget = false;
808
+ }
809
+ else if (input.toolBudget && typeof input.toolBudget === "object" && !Array.isArray(input.toolBudget)) {
810
+ override.toolBudget = input.toolBudget;
811
+ }
812
+ else {
813
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'toolBudget'; expected an object or false.`);
814
+ }
815
+ }
816
+ if ("systemPrompt" in input) {
817
+ if (typeof input.systemPrompt === "string")
818
+ override.systemPrompt = input.systemPrompt;
819
+ else
820
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPrompt'; expected a string.`);
821
+ }
822
+ if (input.machine === false)
823
+ override.machine = false;
824
+ else {
825
+ const machine = validateOptionalMachine(input.machine, `Builtin override '${name}' in '${filePath}' field 'machine'`);
826
+ if (machine !== undefined)
827
+ override.machine = machine;
828
+ }
829
+ const defaultReads = parseOverrideStringArrayOrFalse(input.defaultReads, { filePath, name, field: "defaultReads" });
830
+ if (defaultReads !== undefined)
831
+ override.defaultReads = defaultReads;
832
+ if ("defaultProvider" in input) {
833
+ if (input.defaultProvider === false)
834
+ override.defaultProvider = false;
835
+ else if (typeof input.defaultProvider === "string" && input.defaultProvider.trim())
836
+ override.defaultProvider = input.defaultProvider.trim();
837
+ else
838
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultProvider'; expected a non-empty string or false.`);
839
+ }
840
+ const skills = parseOverrideStringArrayOrFalse(input.skills, { filePath, name, field: "skills" });
841
+ if (skills !== undefined)
842
+ override.skills = skills;
843
+ const tools = parseToolsOverride(input.tools, { filePath, name });
844
+ if (tools !== undefined)
845
+ override.tools = tools;
846
+ const excludeTools = parseOverrideStringArrayOrFalse(input.excludeTools, { filePath, name, field: "excludeTools" });
847
+ if (excludeTools !== undefined)
848
+ override.excludeTools = excludeTools;
849
+ if ("allowNestedSubagents" in input) {
850
+ if (typeof input.allowNestedSubagents === "boolean")
851
+ override.allowNestedSubagents = input.allowNestedSubagents;
852
+ else
853
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'allowNestedSubagents'; expected a boolean.`);
854
+ }
855
+ const allowedAgents = parseOverrideStringArrayOrFalse(input.allowedAgents, { filePath, name, field: "allowedAgents" });
856
+ if (allowedAgents !== undefined)
857
+ override.allowedAgents = allowedAgents === false ? false : normalizeCapabilityCeilingAllowedAgents(allowedAgents);
858
+ const extensions = parseOverrideStringArrayOrFalse(input.extensions, { filePath, name, field: "extensions" });
859
+ if (extensions !== undefined)
860
+ override.extensions = extensions;
861
+ const subagentOnlyExtensions = parseOverrideStringArrayOrFalse(input.subagentOnlyExtensions, { filePath, name, field: "subagentOnlyExtensions" });
862
+ if (subagentOnlyExtensions !== undefined)
863
+ override.subagentOnlyExtensions = subagentOnlyExtensions;
864
+ const mutationTools = parseOverrideStringArrayOrFalse(input.mutationTools, { filePath, name, field: "mutationTools" });
865
+ if (mutationTools !== undefined)
866
+ override.mutationTools = mutationTools;
867
+ return Object.keys(override).length > 0 ? override : undefined;
868
+ }
869
+ function readSubagentSettings(filePath) {
870
+ if (!filePath)
871
+ return EMPTY_SUBAGENT_SETTINGS;
872
+ const settings = readSettingsFileStrict(filePath);
873
+ const subagents = settings.subagents;
874
+ if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
875
+ return EMPTY_SUBAGENT_SETTINGS;
876
+ const subagentsObject = subagents;
877
+ let disableBuiltins;
878
+ if ("disableBuiltins" in subagentsObject) {
879
+ if (typeof subagentsObject.disableBuiltins === "boolean") {
880
+ disableBuiltins = subagentsObject.disableBuiltins;
881
+ }
882
+ else {
883
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'disableBuiltins'; expected a boolean.`);
884
+ }
885
+ }
886
+ let disableThinking;
887
+ if ("disableThinking" in subagentsObject) {
888
+ if (typeof subagentsObject.disableThinking === "boolean") {
889
+ disableThinking = subagentsObject.disableThinking;
890
+ }
891
+ else {
892
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'disableThinking'; expected a boolean.`);
893
+ }
894
+ }
895
+ let defaultModel;
896
+ if ("defaultModel" in subagentsObject) {
897
+ if (typeof subagentsObject.defaultModel === "string" && subagentsObject.defaultModel.trim()) {
898
+ defaultModel = subagentsObject.defaultModel.trim();
899
+ }
900
+ else {
901
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultModel'; expected a non-empty string.`);
902
+ }
903
+ }
904
+ let defaultProvider;
905
+ if ("defaultProvider" in subagentsObject) {
906
+ if (typeof subagentsObject.defaultProvider === "string" && subagentsObject.defaultProvider.trim()) {
907
+ defaultProvider = subagentsObject.defaultProvider.trim();
908
+ }
909
+ else {
910
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultProvider'; expected a non-empty string.`);
911
+ }
912
+ }
913
+ let defaultThinking;
914
+ if ("defaultThinking" in subagentsObject) {
915
+ if (typeof subagentsObject.defaultThinking === "string" && subagentsObject.defaultThinking.trim()) {
916
+ defaultThinking = subagentsObject.defaultThinking.trim();
917
+ }
918
+ else {
919
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultThinking'; expected a non-empty string.`);
920
+ }
921
+ }
922
+ let maxThinking;
923
+ if ("maxThinking" in subagentsObject) {
924
+ try {
925
+ maxThinking = parseThinkingLevel(subagentsObject.maxThinking, `'${filePath}' subagents.maxThinking`);
926
+ }
927
+ catch (error) {
928
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'maxThinking'; expected one of off, minimal, low, medium, high, xhigh, or max.`, { cause: error instanceof Error ? error : undefined });
929
+ }
930
+ }
931
+ let defaultExtensions;
932
+ if ("defaultExtensions" in subagentsObject) {
933
+ if (!Array.isArray(subagentsObject.defaultExtensions)
934
+ || subagentsObject.defaultExtensions.some((item) => typeof item !== "string" || !item.trim())) {
935
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultExtensions'; expected an array of non-empty strings.`);
936
+ }
937
+ defaultExtensions = subagentsObject.defaultExtensions.map((item) => item.trim());
938
+ }
939
+ let defaultSubagentOnlyExtensions;
940
+ if ("defaultSubagentOnlyExtensions" in subagentsObject) {
941
+ if (!Array.isArray(subagentsObject.defaultSubagentOnlyExtensions)
942
+ || subagentsObject.defaultSubagentOnlyExtensions.some((item) => typeof item !== "string" || !item.trim())) {
943
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultSubagentOnlyExtensions'; expected an array of non-empty strings.`);
944
+ }
945
+ defaultSubagentOnlyExtensions = subagentsObject.defaultSubagentOnlyExtensions.map((item) => item.trim());
946
+ }
947
+ let agentScanDirs;
948
+ if ("agentScanDirs" in subagentsObject) {
949
+ if (!Array.isArray(subagentsObject.agentScanDirs)
950
+ || subagentsObject.agentScanDirs.some((item) => typeof item !== "string" || !item.trim())) {
951
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'agentScanDirs'; expected an array of non-empty strings.`);
952
+ }
953
+ agentScanDirs = subagentsObject.agentScanDirs.map((item) => item.trim());
954
+ }
955
+ let agentExcludeDirs;
956
+ if ("agentExcludeDirs" in subagentsObject) {
957
+ if (!Array.isArray(subagentsObject.agentExcludeDirs)
958
+ || subagentsObject.agentExcludeDirs.some((item) => typeof item !== "string" || !item.trim())) {
959
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'agentExcludeDirs'; expected an array of non-empty strings.`);
960
+ }
961
+ agentExcludeDirs = subagentsObject.agentExcludeDirs.map((item) => item.trim());
962
+ }
963
+ const modelScope = parseModelScopeConfig(subagentsObject.modelScope, { filePath });
964
+ const parsed = {};
965
+ const providerOverrides = {};
966
+ const agentOverrides = subagentsObject.agentOverrides;
967
+ const agentOverridesByProvider = subagentsObject.agentOverridesByProvider;
968
+ const parsedSettings = {
969
+ overrides: parsed,
970
+ providerOverrides,
971
+ ...(defaultModel !== undefined ? { defaultModel } : {}),
972
+ ...(defaultProvider !== undefined ? { defaultProvider } : {}),
973
+ ...(defaultThinking !== undefined ? { defaultThinking } : {}),
974
+ ...(maxThinking !== undefined ? { maxThinking } : {}),
975
+ ...(defaultExtensions !== undefined ? { defaultExtensions } : {}),
976
+ ...(defaultSubagentOnlyExtensions !== undefined ? { defaultSubagentOnlyExtensions } : {}),
977
+ ...(agentScanDirs !== undefined ? { agentScanDirs } : {}),
978
+ ...(agentExcludeDirs !== undefined ? { agentExcludeDirs } : {}),
979
+ ...(disableBuiltins !== undefined ? { disableBuiltins } : {}),
980
+ ...(disableThinking !== undefined ? { disableThinking } : {}),
981
+ ...(modelScope !== undefined ? { modelScope } : {}),
982
+ };
983
+ if (agentOverrides && typeof agentOverrides === "object" && !Array.isArray(agentOverrides)) {
984
+ for (const [name, value] of Object.entries(agentOverrides)) {
985
+ const override = parseBuiltinOverrideEntry(name, value, filePath);
986
+ if (override)
987
+ parsed[name] = override;
988
+ }
989
+ }
990
+ if (agentOverridesByProvider !== undefined) {
991
+ if (!agentOverridesByProvider || typeof agentOverridesByProvider !== "object" || Array.isArray(agentOverridesByProvider)) {
992
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'agentOverridesByProvider'; expected an object keyed by provider.`);
993
+ }
994
+ for (const [provider, value] of Object.entries(agentOverridesByProvider)) {
995
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
996
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'agentOverridesByProvider.${provider}'; expected an object keyed by agent.`);
997
+ }
998
+ const entries = {};
999
+ for (const [agentName, agentValue] of Object.entries(value)) {
1000
+ const override = parseBuiltinOverrideEntry(`agentOverridesByProvider.${provider}.${agentName}`, agentValue, filePath);
1001
+ if (override)
1002
+ entries[agentName] = override;
1003
+ }
1004
+ providerOverrides[provider] = entries;
1005
+ }
1006
+ }
1007
+ return parsedSettings;
1008
+ }
1009
+ function selectProviderOverrides(settings, provider) {
1010
+ if (!provider)
1011
+ return settings;
1012
+ const selected = settings.providerOverrides[provider];
1013
+ if (!selected)
1014
+ return settings;
1015
+ const overrides = { ...settings.overrides };
1016
+ for (const [name, override] of Object.entries(selected)) {
1017
+ overrides[name] = { ...overrides[name], ...override };
1018
+ }
1019
+ return { ...settings, overrides };
1020
+ }
1021
+ function resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath) {
1022
+ if (projectSettingsPath && projectSettings.defaultProvider !== undefined)
1023
+ return projectSettings.defaultProvider;
1024
+ return userSettings.defaultProvider;
1025
+ }
1026
+ function resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider) {
1027
+ if (projectSettingsPath && projectSettings.defaultModel !== undefined) {
1028
+ return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) };
1029
+ }
1030
+ return userSettings.defaultModel !== undefined
1031
+ ? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) }
1032
+ : undefined;
1033
+ }
1034
+ function applySubagentDefaultModel(agents, defaultModel, defaultProvider) {
1035
+ if (!defaultModel && !defaultProvider)
1036
+ return agents;
1037
+ return agents.map((agent) => {
1038
+ if (agent.model !== undefined && (agent.modelProvider !== undefined || !defaultProvider))
1039
+ return agent;
1040
+ const next = {
1041
+ ...agent,
1042
+ ...(agent.model === undefined && defaultModel ? { model: defaultModel.model, modelSource: defaultModel } : {}),
1043
+ ...(defaultProvider ? { modelProvider: defaultProvider } : {}),
1044
+ };
1045
+ const frontmatterFields = agentFrontmatterFields.get(agent);
1046
+ if (frontmatterFields)
1047
+ agentFrontmatterFields.set(next, frontmatterFields);
1048
+ return next;
1049
+ });
1050
+ }
1051
+ function resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath) {
1052
+ if (projectSettingsPath && projectSettings.defaultThinking !== undefined)
1053
+ return projectSettings.defaultThinking;
1054
+ return userSettings.defaultThinking;
1055
+ }
1056
+ function applySubagentDefaultThinking(agents, defaultThinking) {
1057
+ if (defaultThinking === undefined)
1058
+ return agents;
1059
+ return agents.map((agent) => {
1060
+ if (agent.thinking !== undefined)
1061
+ return agent;
1062
+ const next = { ...agent, thinking: defaultThinking };
1063
+ const frontmatterFields = agentFrontmatterFields.get(agent);
1064
+ if (frontmatterFields)
1065
+ agentFrontmatterFields.set(next, frontmatterFields);
1066
+ return next;
1067
+ });
1068
+ }
1069
+ function resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath) {
1070
+ if (projectSettingsPath && projectSettings.maxThinking !== undefined)
1071
+ return projectSettings.maxThinking;
1072
+ return userSettings.maxThinking;
1073
+ }
1074
+ function applySubagentMaxThinking(agents, maxThinking) {
1075
+ if (maxThinking === undefined)
1076
+ return agents;
1077
+ return agents.map((agent) => agent.maxThinking === maxThinking ? agent : { ...agent, maxThinking });
1078
+ }
1079
+ function resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath) {
1080
+ if (projectSettingsPath && projectSettings.defaultExtensions !== undefined)
1081
+ return projectSettings.defaultExtensions;
1082
+ return userSettings.defaultExtensions;
1083
+ }
1084
+ function applySubagentDefaultExtensions(agents, defaultExtensions) {
1085
+ if (defaultExtensions === undefined)
1086
+ return agents;
1087
+ return agents.map((agent) => {
1088
+ if (agent.extensions !== undefined)
1089
+ return agent;
1090
+ const next = { ...agent, extensions: [...defaultExtensions], extensionsFromDefault: true };
1091
+ const frontmatterFields = agentFrontmatterFields.get(agent);
1092
+ if (frontmatterFields)
1093
+ agentFrontmatterFields.set(next, frontmatterFields);
1094
+ return next;
1095
+ });
1096
+ }
1097
+ function resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, projectSettingsPath) {
1098
+ if (projectSettingsPath && projectSettings.defaultSubagentOnlyExtensions !== undefined)
1099
+ return projectSettings.defaultSubagentOnlyExtensions;
1100
+ return userSettings.defaultSubagentOnlyExtensions;
1101
+ }
1102
+ function applySubagentDefaultSubagentOnlyExtensions(agents, defaultSubagentOnlyExtensions) {
1103
+ if (defaultSubagentOnlyExtensions === undefined)
1104
+ return agents;
1105
+ return agents.map((agent) => {
1106
+ if (agent.subagentOnlyExtensions !== undefined)
1107
+ return agent;
1108
+ const next = { ...agent, subagentOnlyExtensions: [...defaultSubagentOnlyExtensions] };
1109
+ const frontmatterFields = agentFrontmatterFields.get(agent);
1110
+ if (frontmatterFields)
1111
+ agentFrontmatterFields.set(next, frontmatterFields);
1112
+ return next;
1113
+ });
1114
+ }
1115
+ function applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions) {
1116
+ return applySubagentDefaultSubagentOnlyExtensions(applySubagentDefaultExtensions(applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking), defaultExtensions), defaultSubagentOnlyExtensions);
1117
+ }
1118
+ function applyToolsOverride(target, toolsOverride) {
1119
+ if (toolsOverride === "inherit") {
1120
+ delete target.tools;
1121
+ delete target.mcpDirectTools;
1122
+ return;
1123
+ }
1124
+ const { tools, mcpDirectTools } = splitToolList(toolsOverride === false ? [] : toolsOverride);
1125
+ if (tools === undefined)
1126
+ delete target.tools;
1127
+ else
1128
+ target.tools = tools;
1129
+ if (mcpDirectTools === undefined)
1130
+ delete target.mcpDirectTools;
1131
+ else
1132
+ target.mcpDirectTools = mcpDirectTools;
1133
+ }
1134
+ function applyBuiltinOverride(agent, override, meta) {
1135
+ const overrideInfo = {
1136
+ ...meta,
1137
+ base: agent.override?.base ?? cloneOverrideBase(agent),
1138
+ fields: [...new Set([...(agent.override?.fields ?? []), ...Object.keys(override)])].sort(),
1139
+ fieldScopes: Object.fromEntries(Object.entries({ ...(agent.override?.fieldScopes ?? {}) }).map(([field, scopes]) => [field, [...scopes]])),
1140
+ };
1141
+ for (const field of Object.keys(override)) {
1142
+ const scopes = overrideInfo.fieldScopes[field] ?? [];
1143
+ overrideInfo.fieldScopes[field] = [...new Set([...scopes, meta.scope])].sort();
1144
+ }
1145
+ const next = {
1146
+ ...agent,
1147
+ override: overrideInfo,
1148
+ };
1149
+ if (override.description !== undefined)
1150
+ next.description = override.description;
1151
+ if (override.machine !== undefined) {
1152
+ if (override.machine === false)
1153
+ delete next.machine;
1154
+ else
1155
+ next.machine = override.machine;
1156
+ }
1157
+ if (override.output !== undefined) {
1158
+ if (override.output === false)
1159
+ delete next.output;
1160
+ else
1161
+ next.output = override.output;
1162
+ }
1163
+ if (override.outputMode !== undefined)
1164
+ next.outputMode = override.outputMode;
1165
+ if (override.defaultReads !== undefined) {
1166
+ if (override.defaultReads === false)
1167
+ delete next.defaultReads;
1168
+ else
1169
+ next.defaultReads = [...override.defaultReads];
1170
+ }
1171
+ if (override.model !== undefined) {
1172
+ if (override.model === false)
1173
+ delete next.model;
1174
+ else
1175
+ next.model = override.model;
1176
+ delete next.modelSource;
1177
+ }
1178
+ if (override.defaultProvider !== undefined) {
1179
+ if (override.defaultProvider === false)
1180
+ delete next.modelProvider;
1181
+ else
1182
+ next.modelProvider = override.defaultProvider;
1183
+ }
1184
+ if (override.fast !== undefined)
1185
+ next.fast = override.fast;
1186
+ if (override.thinking !== undefined) {
1187
+ if (override.thinking === false)
1188
+ delete next.thinking;
1189
+ else
1190
+ next.thinking = override.thinking;
1191
+ }
1192
+ if (override.systemPromptMode !== undefined)
1193
+ next.systemPromptMode = override.systemPromptMode;
1194
+ if (override.inheritProjectContext !== undefined)
1195
+ next.inheritProjectContext = override.inheritProjectContext;
1196
+ if (override.inheritGlobalContext !== undefined)
1197
+ next.inheritGlobalContext = override.inheritGlobalContext;
1198
+ if (override.inheritSkills !== undefined)
1199
+ next.inheritSkills = override.inheritSkills;
1200
+ if (override.defaultContext !== undefined) {
1201
+ if (override.defaultContext === false)
1202
+ delete next.defaultContext;
1203
+ else
1204
+ next.defaultContext = override.defaultContext;
1205
+ }
1206
+ if (override.acceptanceRole !== undefined) {
1207
+ if (override.acceptanceRole === false)
1208
+ delete next.acceptanceRole;
1209
+ else
1210
+ next.acceptanceRole = override.acceptanceRole;
1211
+ }
1212
+ if (override.disabled !== undefined)
1213
+ next.disabled = override.disabled;
1214
+ if (override.systemPrompt !== undefined)
1215
+ next.systemPrompt = override.systemPrompt;
1216
+ if (override.skills !== undefined) {
1217
+ if (override.skills === false)
1218
+ delete next.skills;
1219
+ else
1220
+ next.skills = [...override.skills];
1221
+ }
1222
+ if (override.tools !== undefined)
1223
+ applyToolsOverride(next, override.tools);
1224
+ if (override.excludeTools !== undefined) {
1225
+ if (override.excludeTools === false)
1226
+ delete next.excludeTools;
1227
+ else
1228
+ next.excludeTools = [...override.excludeTools];
1229
+ }
1230
+ if (override.allowNestedSubagents !== undefined)
1231
+ next.allowNestedSubagents = override.allowNestedSubagents;
1232
+ if (override.allowedAgents !== undefined) {
1233
+ if (override.allowedAgents === false)
1234
+ delete next.allowedAgents;
1235
+ else
1236
+ next.allowedAgents = [...override.allowedAgents];
1237
+ }
1238
+ if (override.extensions !== undefined) {
1239
+ if (override.extensions === false)
1240
+ delete next.extensions;
1241
+ else
1242
+ next.extensions = [...override.extensions];
1243
+ }
1244
+ if (override.subagentOnlyExtensions !== undefined) {
1245
+ if (override.subagentOnlyExtensions === false)
1246
+ delete next.subagentOnlyExtensions;
1247
+ else
1248
+ next.subagentOnlyExtensions = [...override.subagentOnlyExtensions];
1249
+ }
1250
+ if (override.mutationTools !== undefined) {
1251
+ if (override.mutationTools === false)
1252
+ delete next.mutationTools;
1253
+ else
1254
+ next.mutationTools = [...override.mutationTools];
1255
+ }
1256
+ if (override.toolBudget !== undefined) {
1257
+ if (override.toolBudget === false)
1258
+ delete next.toolBudget;
1259
+ else
1260
+ next.toolBudget = override.toolBudget;
1261
+ }
1262
+ return next;
1263
+ }
1264
+ function clearBuiltinThinking(agent, meta) {
1265
+ if (agent.thinking === undefined)
1266
+ return agent;
1267
+ const { thinking: _thinking, ...next } = agent;
1268
+ return { ...next, override: agent.override ?? { ...meta, base: cloneOverrideBase(agent) } };
1269
+ }
1270
+ function applyBuiltinOverrides(builtinAgents, userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
1271
+ const projectBulkDisabled = projectSettings.disableBuiltins === true && projectSettingsPath !== null;
1272
+ const userBulkDisabled = projectSettings.disableBuiltins === undefined && userSettings.disableBuiltins === true;
1273
+ const projectThinkingConfigured = projectSettings.disableThinking !== undefined && projectSettingsPath !== null;
1274
+ const disableThinking = projectThinkingConfigured ? projectSettings.disableThinking === true : userSettings.disableThinking === true;
1275
+ const disableThinkingMeta = projectThinkingConfigured
1276
+ ? { scope: "project", path: projectSettingsPath }
1277
+ : { scope: "user", path: userSettingsPath };
1278
+ const applyGlobalThinking = (agent, hasExplicitThinkingOverride) => {
1279
+ if (!disableThinking || hasExplicitThinkingOverride)
1280
+ return agent;
1281
+ return clearBuiltinThinking(agent, disableThinkingMeta);
1282
+ };
1283
+ return builtinAgents.map((agent) => {
1284
+ const projectOverride = projectSettings.overrides[agent.name];
1285
+ if (projectOverride && projectSettingsPath) {
1286
+ return applyGlobalThinking(applyBuiltinOverride(agent, projectOverride, { scope: "project", path: projectSettingsPath }), projectOverride.thinking !== undefined);
1287
+ }
1288
+ if (projectBulkDisabled && projectSettingsPath) {
1289
+ return applyGlobalThinking(applyBuiltinOverride(agent, { disabled: true }, { scope: "project", path: projectSettingsPath }), false);
1290
+ }
1291
+ const userOverride = userSettings.overrides[agent.name];
1292
+ if (userOverride) {
1293
+ return applyGlobalThinking(applyBuiltinOverride(agent, userOverride, { scope: "user", path: userSettingsPath }), !projectThinkingConfigured && userOverride.thinking !== undefined);
1294
+ }
1295
+ if (userBulkDisabled) {
1296
+ return applyGlobalThinking(applyBuiltinOverride(agent, { disabled: true }, { scope: "user", path: userSettingsPath }), false);
1297
+ }
1298
+ return applyGlobalThinking(agent, false);
1299
+ });
1300
+ }
1301
+ function applyCustomAgentOverride(agent, override, meta) {
1302
+ const next = applyBuiltinOverride(agent, override, meta);
1303
+ const frontmatterFields = agentFrontmatterFields.get(agent);
1304
+ if (frontmatterFields)
1305
+ agentFrontmatterFields.set(next, frontmatterFields);
1306
+ return next;
1307
+ }
1308
+ function applyCustomAgentOverrides(agents, userSettings, projectSettings, userSettingsPath, projectSettingsPath) {
1309
+ // Apply user then project so project fields win without dropping user-only fields.
1310
+ return agents.map((agent) => {
1311
+ const userOverride = userSettings.overrides[agent.name];
1312
+ const withUserOverride = userOverride
1313
+ ? applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath })
1314
+ : agent;
1315
+ const projectOverride = projectSettings.overrides[agent.name];
1316
+ if (projectOverride && projectSettingsPath) {
1317
+ return applyCustomAgentOverride(withUserOverride, projectOverride, { scope: "project", path: projectSettingsPath });
1318
+ }
1319
+ return withUserOverride;
1320
+ });
1321
+ }
1322
+ function runtimeAgentOverrides(settings) {
1323
+ const overrides = {};
1324
+ for (const [name, override] of Object.entries(settings.overrides)) {
1325
+ const narrowed = {};
1326
+ if (override.model !== undefined)
1327
+ narrowed.model = override.model;
1328
+ if (override.defaultProvider !== undefined)
1329
+ narrowed.defaultProvider = override.defaultProvider;
1330
+ if (override.fast !== undefined)
1331
+ narrowed.fast = override.fast;
1332
+ if (override.thinking !== undefined)
1333
+ narrowed.thinking = override.thinking;
1334
+ if (Object.keys(narrowed).length > 0)
1335
+ overrides[name] = narrowed;
1336
+ }
1337
+ return { ...settings, overrides };
1338
+ }
1339
+ /**
1340
+ * Runtime-registered agents keep their extension-owned definition (prompt,
1341
+ * tools, context, budgets, and every other launch field) but follow the same
1342
+ * model-tier settings as every other agent: `subagents.defaultModel`,
1343
+ * `defaultProvider`, `defaultThinking`, and the `model`, `defaultProvider`,
1344
+ * `fast`, and `thinking` fields of `agentOverrides.<name>`, user then project,
1345
+ * provider-scoped overrides included. Other override fields are ignored for
1346
+ * runtime agents. A definition `model` still wins over `defaultModel`.
1347
+ */
1348
+ export function applyRuntimeAgentSettings(agents, context) {
1349
+ if (agents.length === 0)
1350
+ return agents;
1351
+ const sources = getAgentDiscoverySources(context.cwd, context.preferredModelProvider);
1352
+ const { user, project } = settingsForScope(sources, context.scope);
1353
+ const defaultProvider = resolveSubagentDefaultProvider(user, project, sources.projectSettingsPath);
1354
+ const defaultModel = resolveSubagentDefaultModel(user, project, sources.userSettingsPath, sources.projectSettingsPath, defaultProvider);
1355
+ const defaultThinking = resolveSubagentDefaultThinking(user, project, sources.projectSettingsPath);
1356
+ const withDefaults = applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking);
1357
+ return applyCustomAgentOverrides(withDefaults, runtimeAgentOverrides(user), runtimeAgentOverrides(project), sources.userSettingsPath, sources.projectSettingsPath);
1358
+ }
1359
+ export function buildBuiltinOverrideConfig(base, draft) {
1360
+ const override = {};
1361
+ if (draft.machine !== base.machine)
1362
+ override.machine = draft.machine ?? false;
1363
+ if (draft.description !== undefined) {
1364
+ const description = draft.description.trim();
1365
+ if (description && description !== base.description)
1366
+ override.description = description;
1367
+ }
1368
+ if (draft.output !== base.output)
1369
+ override.output = draft.output ?? false;
1370
+ if (draft.outputMode !== undefined && draft.outputMode !== base.outputMode)
1371
+ override.outputMode = draft.outputMode;
1372
+ if (!arraysEqual(draft.defaultReads, base.defaultReads))
1373
+ override.defaultReads = draft.defaultReads ? [...draft.defaultReads] : false;
1374
+ if (draft.model !== base.model)
1375
+ override.model = draft.model ?? false;
1376
+ if (draft.modelProvider !== base.modelProvider)
1377
+ override.defaultProvider = draft.modelProvider ?? false;
1378
+ if (draft.fast !== base.fast)
1379
+ override.fast = draft.fast === true;
1380
+ if (draft.thinking !== base.thinking)
1381
+ override.thinking = draft.thinking ?? false;
1382
+ if (draft.systemPromptMode !== base.systemPromptMode)
1383
+ override.systemPromptMode = draft.systemPromptMode;
1384
+ if (draft.inheritProjectContext !== base.inheritProjectContext)
1385
+ override.inheritProjectContext = draft.inheritProjectContext;
1386
+ if (draft.inheritGlobalContext !== base.inheritGlobalContext)
1387
+ override.inheritGlobalContext = draft.inheritGlobalContext;
1388
+ if (draft.inheritSkills !== base.inheritSkills)
1389
+ override.inheritSkills = draft.inheritSkills;
1390
+ if (draft.defaultContext !== base.defaultContext)
1391
+ override.defaultContext = draft.defaultContext ?? false;
1392
+ if (draft.acceptanceRole !== base.acceptanceRole)
1393
+ override.acceptanceRole = draft.acceptanceRole ?? false;
1394
+ if (draft.disabled !== base.disabled)
1395
+ override.disabled = draft.disabled ?? false;
1396
+ if (draft.systemPrompt !== base.systemPrompt)
1397
+ override.systemPrompt = draft.systemPrompt;
1398
+ if (!arraysEqual(draft.skills, base.skills))
1399
+ override.skills = draft.skills ? [...draft.skills] : false;
1400
+ const baseTools = joinToolList(base);
1401
+ const draftTools = joinToolList(draft);
1402
+ if (!arraysEqual(draftTools, baseTools))
1403
+ override.tools = draftTools ? [...draftTools] : false;
1404
+ if (!arraysEqual(draft.excludeTools, base.excludeTools))
1405
+ override.excludeTools = draft.excludeTools ? [...draft.excludeTools] : false;
1406
+ if (draft.allowNestedSubagents !== base.allowNestedSubagents)
1407
+ override.allowNestedSubagents = draft.allowNestedSubagents === true;
1408
+ if (!arraysEqual(draft.extensions, base.extensions))
1409
+ override.extensions = draft.extensions ? [...draft.extensions] : false;
1410
+ if (!arraysEqual(draft.subagentOnlyExtensions, base.subagentOnlyExtensions)) {
1411
+ override.subagentOnlyExtensions = draft.subagentOnlyExtensions ? [...draft.subagentOnlyExtensions] : false;
1412
+ }
1413
+ if (!arraysEqual(draft.mutationTools, base.mutationTools))
1414
+ override.mutationTools = draft.mutationTools ? [...draft.mutationTools] : false;
1415
+ if (JSON.stringify(draft.toolBudget) !== JSON.stringify(base.toolBudget))
1416
+ override.toolBudget = draft.toolBudget ?? false;
1417
+ return Object.keys(override).length > 0 ? override : undefined;
1418
+ }
1419
+ export function saveBuiltinAgentOverride(cwd, name, scope, override) {
1420
+ const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
1421
+ if (!filePath)
1422
+ throw new Error("Project override is not available here. No project config root was found.");
1423
+ const settings = readSettingsFileStrict(filePath);
1424
+ const subagents = settings.subagents && typeof settings.subagents === "object" && !Array.isArray(settings.subagents)
1425
+ ? { ...settings.subagents }
1426
+ : {};
1427
+ const agentOverrides = subagents.agentOverrides && typeof subagents.agentOverrides === "object" && !Array.isArray(subagents.agentOverrides)
1428
+ ? { ...subagents.agentOverrides }
1429
+ : {};
1430
+ agentOverrides[name] = cloneOverrideValue(override);
1431
+ subagents.agentOverrides = agentOverrides;
1432
+ settings.subagents = subagents;
1433
+ writeSettingsFile(filePath, settings);
1434
+ return filePath;
1435
+ }
1436
+ export function removeBuiltinAgentOverride(cwd, name, scope, options) {
1437
+ const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
1438
+ if (!filePath)
1439
+ throw new Error("Project override is not available here. No project config root was found.");
1440
+ if (!fs.existsSync(filePath))
1441
+ return { path: filePath, removed: false, machinePreserved: false };
1442
+ const settings = readSettingsFileStrict(filePath);
1443
+ const subagents = settings.subagents;
1444
+ if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
1445
+ return { path: filePath, removed: false, machinePreserved: false };
1446
+ const nextSubagents = { ...subagents };
1447
+ const agentOverrides = nextSubagents.agentOverrides;
1448
+ if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides))
1449
+ return { path: filePath, removed: false, machinePreserved: false };
1450
+ const nextOverrides = { ...agentOverrides };
1451
+ const current = nextOverrides[name];
1452
+ if (!Object.prototype.hasOwnProperty.call(nextOverrides, name))
1453
+ return { path: filePath, removed: false, machinePreserved: false };
1454
+ const configuredMachine = current && typeof current === "object" && !Array.isArray(current) ? current.machine : undefined;
1455
+ const machine = configuredMachine === false || (typeof configuredMachine === "string" && configuredMachine.trim()) ? configuredMachine : undefined;
1456
+ if (options?.preserveMachine && machine !== undefined)
1457
+ nextOverrides[name] = { machine };
1458
+ else
1459
+ delete nextOverrides[name];
1460
+ if (Object.keys(nextOverrides).length > 0)
1461
+ nextSubagents.agentOverrides = nextOverrides;
1462
+ else
1463
+ delete nextSubagents.agentOverrides;
1464
+ if (Object.keys(nextSubagents).length > 0)
1465
+ settings.subagents = nextSubagents;
1466
+ else
1467
+ delete settings.subagents;
1468
+ writeSettingsFile(filePath, settings);
1469
+ return { path: filePath, removed: true, machinePreserved: options?.preserveMachine === true && machine !== undefined };
1470
+ }
1471
+ export function mergeBuiltinAgentOverride(cwd, name, scope, fields) {
1472
+ const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
1473
+ if (!filePath)
1474
+ throw new Error("Project override is not available here. No project config root was found.");
1475
+ const settings = readSettingsFileStrict(filePath);
1476
+ const subagents = settings.subagents && typeof settings.subagents === "object" && !Array.isArray(settings.subagents)
1477
+ ? { ...settings.subagents }
1478
+ : {};
1479
+ const agentOverrides = subagents.agentOverrides && typeof subagents.agentOverrides === "object" && !Array.isArray(subagents.agentOverrides)
1480
+ ? { ...subagents.agentOverrides }
1481
+ : {};
1482
+ const existing = agentOverrides[name];
1483
+ const base = existing && typeof existing === "object" && !Array.isArray(existing)
1484
+ ? existing
1485
+ : {};
1486
+ agentOverrides[name] = { ...base, ...cloneOverrideValue(fields) };
1487
+ subagents.agentOverrides = agentOverrides;
1488
+ settings.subagents = subagents;
1489
+ writeSettingsFile(filePath, settings);
1490
+ return filePath;
1491
+ }
1492
+ export function removeBuiltinAgentOverrideFields(cwd, name, scope, fields) {
1493
+ const filePath = scope === "project" ? getProjectAgentSettingsPath(cwd) : getUserAgentSettingsPath();
1494
+ if (!filePath)
1495
+ throw new Error("Project override is not available here. No project config root was found.");
1496
+ if (!fs.existsSync(filePath))
1497
+ return { path: filePath, removed: false };
1498
+ const settings = readSettingsFileStrict(filePath);
1499
+ const subagents = settings.subagents;
1500
+ if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
1501
+ return { path: filePath, removed: false };
1502
+ const agentOverrides = subagents.agentOverrides;
1503
+ if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides))
1504
+ return { path: filePath, removed: false };
1505
+ const entry = agentOverrides[name];
1506
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
1507
+ return { path: filePath, removed: false };
1508
+ const nextEntry = { ...entry };
1509
+ let removed = false;
1510
+ for (const field of fields) {
1511
+ if (Object.prototype.hasOwnProperty.call(nextEntry, field)) {
1512
+ delete nextEntry[field];
1513
+ removed = true;
1514
+ }
1515
+ }
1516
+ if (!removed)
1517
+ return { path: filePath, removed: false };
1518
+ const nextSubagents = { ...subagents };
1519
+ if (Object.keys(nextEntry).length > 0) {
1520
+ nextSubagents.agentOverrides[name] = nextEntry;
1521
+ }
1522
+ else {
1523
+ const nextOverrides = { ...agentOverrides };
1524
+ delete nextOverrides[name];
1525
+ if (Object.keys(nextOverrides).length > 0)
1526
+ nextSubagents.agentOverrides = nextOverrides;
1527
+ else
1528
+ delete nextSubagents.agentOverrides;
1529
+ }
1530
+ if (Object.keys(nextSubagents).length > 0)
1531
+ settings.subagents = nextSubagents;
1532
+ else
1533
+ delete settings.subagents;
1534
+ writeSettingsFile(filePath, settings);
1535
+ return { path: filePath, removed: true };
1536
+ }
1537
+ const DISCOVERY_PRUNED_DIR_NAMES = new Set([".git", "node_modules", ".pi", "sync-backups"]);
1538
+ function isDiscoveryNestedProjectRoot(dir) {
1539
+ return isDirectory(getProjectConfigDir(dir)) || isDirectory(path.join(dir, ".agents"));
1540
+ }
1541
+ function shouldPruneDiscoveryDir(rootDir, dir, dirName) {
1542
+ if (DISCOVERY_PRUNED_DIR_NAMES.has(dirName))
1543
+ return true;
1544
+ if (fs.existsSync(path.join(dir, ".git")))
1545
+ return true;
1546
+ return path.resolve(dir) !== path.resolve(rootDir) && isDiscoveryNestedProjectRoot(dir);
1547
+ }
1548
+ function listFilesRecursive(dir, predicate, rootDir = dir, visitedDirectories = new Set(), inspectedDirectories = new Set()) {
1549
+ const files = [];
1550
+ if (!fs.existsSync(dir))
1551
+ return files;
1552
+ inspectedDirectories.add(path.resolve(dir));
1553
+ let realDir;
1554
+ try {
1555
+ realDir = fs.realpathSync(dir);
1556
+ }
1557
+ catch {
1558
+ return files;
1559
+ }
1560
+ if (visitedDirectories.has(realDir))
1561
+ return files;
1562
+ visitedDirectories.add(realDir);
1563
+ let entries;
1564
+ try {
1565
+ entries = fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
1566
+ }
1567
+ catch {
1568
+ return files;
1569
+ }
1570
+ for (const entry of entries) {
1571
+ const filePath = path.join(dir, entry.name);
1572
+ let isDirectory = entry.isDirectory();
1573
+ if (entry.isSymbolicLink()) {
1574
+ try {
1575
+ isDirectory = fs.statSync(filePath).isDirectory();
1576
+ }
1577
+ catch {
1578
+ isDirectory = false;
1579
+ }
1580
+ }
1581
+ if (isDirectory) {
1582
+ if (!shouldPruneDiscoveryDir(rootDir, filePath, entry.name)) {
1583
+ files.push(...listFilesRecursive(filePath, predicate, rootDir, visitedDirectories, inspectedDirectories));
1584
+ }
1585
+ continue;
1586
+ }
1587
+ if (!entry.isFile() && !entry.isSymbolicLink())
1588
+ continue;
1589
+ if (!predicate(entry.name))
1590
+ continue;
1591
+ files.push(filePath);
1592
+ }
1593
+ return files;
1594
+ }
1595
+ const agentDefinitionInspectionDirectories = new WeakMap();
1596
+ function rememberAgentDefinitionInspection(inspection, directories) {
1597
+ agentDefinitionInspectionDirectories.set(inspection, [...new Set([...directories].map((directory) => path.resolve(directory)))]);
1598
+ return inspection;
1599
+ }
1600
+ function inspectedAgentDefinitionDirectories(inspection, root) {
1601
+ return agentDefinitionInspectionDirectories.get(inspection) ?? [path.resolve(root)];
1602
+ }
1603
+ const DEFAULT_AGENT_DEFINITION_INSPECTION_FS = {
1604
+ existsSync: fs.existsSync,
1605
+ realpathSync: fs.realpathSync,
1606
+ statSync: fs.statSync,
1607
+ readdirSync: (dir) => fs.readdirSync(dir, { withFileTypes: true }),
1608
+ };
1609
+ /**
1610
+ * Inspect one agent-definition directory while retaining traversal failure
1611
+ * state. A nested unreadable directory makes the whole inspection unavailable,
1612
+ * preventing a partial traversal from being reported as empty or complete.
1613
+ */
1614
+ export function inspectAgentDefinitionDirectory(dir, operations = DEFAULT_AGENT_DEFINITION_INSPECTION_FS, isExcluded = () => false) {
1615
+ const root = path.resolve(dir);
1616
+ if (isExcluded(root))
1617
+ return rememberAgentDefinitionInspection({ files: [], state: "empty" }, []);
1618
+ try {
1619
+ if (!operations.existsSync(root))
1620
+ return rememberAgentDefinitionInspection({ files: [], state: "absent" }, [root]);
1621
+ if (!operations.statSync(root).isDirectory())
1622
+ return rememberAgentDefinitionInspection({ files: [], state: "not-directory" }, [root]);
1623
+ }
1624
+ catch {
1625
+ return rememberAgentDefinitionInspection({ files: [], state: "unreadable" }, [root]);
1626
+ }
1627
+ const files = [];
1628
+ let unreadable = false;
1629
+ const visitedDirectories = new Set();
1630
+ const inspectedDirectories = new Set();
1631
+ const visit = (current) => {
1632
+ inspectedDirectories.add(path.resolve(current));
1633
+ let realDir;
1634
+ try {
1635
+ realDir = operations.realpathSync?.(current) ?? path.resolve(current);
1636
+ }
1637
+ catch {
1638
+ unreadable = true;
1639
+ return;
1640
+ }
1641
+ if (visitedDirectories.has(realDir))
1642
+ return;
1643
+ visitedDirectories.add(realDir);
1644
+ let entries;
1645
+ try {
1646
+ entries = operations.readdirSync(current).sort((a, b) => a.name.localeCompare(b.name));
1647
+ }
1648
+ catch {
1649
+ unreadable = true;
1650
+ return;
1651
+ }
1652
+ for (const entry of entries) {
1653
+ const filePath = path.join(current, entry.name);
1654
+ if (isExcluded(filePath))
1655
+ continue;
1656
+ let isDirectory = entry.isDirectory();
1657
+ if (entry.isSymbolicLink()) {
1658
+ try {
1659
+ isDirectory = operations.statSync(filePath).isDirectory();
1660
+ }
1661
+ catch {
1662
+ isDirectory = false;
1663
+ }
1664
+ }
1665
+ if (isDirectory) {
1666
+ if (!shouldPruneDiscoveryDir(root, filePath, entry.name))
1667
+ visit(filePath);
1668
+ continue;
1669
+ }
1670
+ if ((entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".md") && !entry.name.endsWith(".chain.md") && !isLegacyAgentSkillPath(root, filePath))
1671
+ files.push(filePath);
1672
+ }
1673
+ };
1674
+ visit(root);
1675
+ return rememberAgentDefinitionInspection({ files, state: unreadable ? "unreadable" : files.length ? "candidates" : "empty" }, inspectedDirectories);
1676
+ }
1677
+ function isLegacyAgentSkillPath(rootDir, filePath) {
1678
+ const relative = path.relative(rootDir, filePath);
1679
+ const parts = relative.split(path.sep).map((part) => part.toLowerCase());
1680
+ if (path.basename(rootDir).toLowerCase() === ".agents") {
1681
+ parts.unshift(".agents");
1682
+ }
1683
+ return parts.some((part, index) => part === ".agents" && parts[index + 1] === "skills");
1684
+ }
1685
+ function isJsonSerializable(value) {
1686
+ if (value === null || typeof value === "string" || typeof value === "boolean")
1687
+ return true;
1688
+ if (typeof value === "number")
1689
+ return Number.isFinite(value);
1690
+ if (Array.isArray(value))
1691
+ return value.every(isJsonSerializable);
1692
+ if (value && typeof value === "object")
1693
+ return Object.values(value).every(isJsonSerializable);
1694
+ return false;
1695
+ }
1696
+ function parseAgentRunnerFrontmatter(raw, agentName) {
1697
+ if (raw === undefined || !raw.trim())
1698
+ return undefined;
1699
+ let parsed;
1700
+ try {
1701
+ parsed = parseYaml(raw);
1702
+ }
1703
+ catch (error) {
1704
+ throw new Error(`Agent '${agentName}' has invalid runner frontmatter: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1705
+ }
1706
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1707
+ throw new Error(`Agent '${agentName}' has invalid runner frontmatter; expected an object.`);
1708
+ }
1709
+ const runner = parsed;
1710
+ if (runner.type === "pi") {
1711
+ if (Object.keys(runner).some((key) => key !== "type"))
1712
+ throw new Error(`Agent '${agentName}' has invalid Pi runner frontmatter; only 'type' is supported.`);
1713
+ return { type: "pi" };
1714
+ }
1715
+ if (runner.type === "external-job") {
1716
+ if (typeof runner.provider !== "string" || !runner.provider.trim() || runner.provider.trim() !== runner.provider) {
1717
+ throw new Error(`Agent '${agentName}' external-job runner requires a non-empty trimmed provider string.`);
1718
+ }
1719
+ if (runner.options !== undefined && (!runner.options || typeof runner.options !== "object" || Array.isArray(runner.options) || !isJsonSerializable(runner.options))) {
1720
+ throw new Error(`Agent '${agentName}' external-job runner options must be a JSON-serializable object.`);
1721
+ }
1722
+ const supported = new Set(["type", "provider", "options"]);
1723
+ const unknown = Object.keys(runner).filter((key) => !supported.has(key));
1724
+ if (unknown.length > 0)
1725
+ throw new Error(`Agent '${agentName}' external-job runner has unsupported fields: ${unknown.join(", ")}.`);
1726
+ return {
1727
+ type: "external-job",
1728
+ provider: runner.provider,
1729
+ ...(runner.options ? { options: runner.options } : {}),
1730
+ };
1731
+ }
1732
+ if (runner.type !== "external-cli") {
1733
+ throw new Error(`Agent '${agentName}' has invalid runner.type; expected 'pi', 'external-cli', or 'external-job'.`);
1734
+ }
1735
+ if (typeof runner.command !== "string" || !runner.command.trim()) {
1736
+ throw new Error(`Agent '${agentName}' external-cli runner requires a non-empty command string.`);
1737
+ }
1738
+ if (runner.args !== undefined && (!Array.isArray(runner.args) || runner.args.some((arg) => typeof arg !== "string"))) {
1739
+ throw new Error(`Agent '${agentName}' external-cli runner args must be an array of strings.`);
1740
+ }
1741
+ if (runner.adapter !== undefined && !isCodeOwnedExternalCliAdapterId(runner.adapter))
1742
+ throw new Error(`Agent '${agentName}' external-cli runner adapter must be ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}.`);
1743
+ if (runner.adapter !== undefined && Array.isArray(runner.args) && runner.args.length > 0)
1744
+ throw new Error(`Agent '${agentName}' ${runner.adapter} adapter owns its argv; runner args are not supported.`);
1745
+ if (runner.promptDelivery !== undefined && runner.promptDelivery !== "stdin") {
1746
+ throw new Error(`Agent '${agentName}' external-cli runner promptDelivery must be 'stdin'.`);
1747
+ }
1748
+ const capabilities = parseExternalCliCapabilityNarrowing(runner.capabilities, `Agent '${agentName}' external-cli runner capabilities`);
1749
+ const supported = new Set(["type", "adapter", "command", "args", "promptDelivery", "capabilities"]);
1750
+ const unknown = Object.keys(runner).filter((key) => !supported.has(key));
1751
+ if (unknown.length > 0)
1752
+ throw new Error(`Agent '${agentName}' external-cli runner has unsupported fields: ${unknown.join(", ")}.`);
1753
+ const runnerArgs = Array.isArray(runner.args) ? runner.args.filter((arg) => typeof arg === "string") : undefined;
1754
+ return {
1755
+ type: "external-cli",
1756
+ ...(isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}),
1757
+ command: runner.command.trim(),
1758
+ ...(runnerArgs?.length ? { args: runnerArgs } : {}),
1759
+ ...(runner.promptDelivery ? { promptDelivery: "stdin" } : {}),
1760
+ ...(capabilities ? { capabilities } : {}),
1761
+ };
1762
+ }
1763
+ function validateExternalRunnerProfile(frontmatter, agentName, runner) {
1764
+ if (runner?.type !== "external-cli" && runner?.type !== "external-job")
1765
+ return;
1766
+ const unsupported = ["tools", "excludeTools", "allowNestedSubagents", "allowedAgents", "model", "thinking", "extensions", "subagentOnlyExtensions", "mutationTools", "maxSubagentDepth", "skills", "skill", "skillPath", "toolBudget", "permission", "permissions"]
1767
+ .filter((field) => frontmatter[field] !== undefined);
1768
+ if (unsupported.length > 0) {
1769
+ throw new Error(`Agent '${agentName}' uses runner.type='${runner.type}' and declares unsupported Pi-only fields: ${unsupported.join(", ")}.`);
1770
+ }
1771
+ }
1772
+ function parseAgentAcceptanceFrontmatter(raw, agentName) {
1773
+ if (raw === undefined || !raw.trim())
1774
+ return undefined;
1775
+ let parsed;
1776
+ try {
1777
+ parsed = parseYaml(raw);
1778
+ }
1779
+ catch (error) {
1780
+ throw new Error(`Agent '${agentName}' has invalid acceptance frontmatter: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1781
+ }
1782
+ const errors = validateAcceptanceInput(parsed, `Agent '${agentName}' acceptance frontmatter`);
1783
+ if (errors.length > 0)
1784
+ throw new Error(errors.join(" "));
1785
+ return parsed;
1786
+ }
1787
+ function readAgentDefinitionFiles(dir, inspection = inspectAgentDefinitionDirectory(dir)) {
1788
+ const files = [];
1789
+ for (const filePath of inspection.files) {
1790
+ if (isLegacyAgentSkillPath(dir, filePath)) {
1791
+ continue;
1792
+ }
1793
+ try {
1794
+ files.push({ filePath, content: fs.readFileSync(filePath, "utf-8") });
1795
+ }
1796
+ catch {
1797
+ continue;
1798
+ }
1799
+ }
1800
+ return files;
1801
+ }
1802
+ function resolveAgentRelativeExtensionPaths(paths, agentFilePath) {
1803
+ if (paths === undefined)
1804
+ return undefined;
1805
+ const baseDir = path.dirname(agentFilePath);
1806
+ return paths.map((entry) => {
1807
+ const trimmed = entry.trim();
1808
+ if (trimmed === "." || trimmed === ".." || trimmed.startsWith("./") || trimmed.startsWith("../")) {
1809
+ return path.resolve(baseDir, trimmed);
1810
+ }
1811
+ return entry;
1812
+ });
1813
+ }
1814
+ function loadAgentsFromDefinitionFiles(files, source, discoveryPriority, packageSource) {
1815
+ const agents = [];
1816
+ const diagnostics = [];
1817
+ for (const { filePath, content } of files) {
1818
+ let name;
1819
+ let runtimeName;
1820
+ let packageSpecified = false;
1821
+ try {
1822
+ const { frontmatter, body } = parseFrontmatter(content);
1823
+ if (!frontmatter.name || !frontmatter.description) {
1824
+ continue;
1825
+ }
1826
+ const localName = frontmatter.name;
1827
+ name = localName;
1828
+ const parsedPackage = parsePackageName(frontmatter.package, `Agent '${localName}' package`);
1829
+ packageSpecified = parsedPackage.packageName !== undefined || parsedPackage.error !== undefined;
1830
+ if (parsedPackage.error)
1831
+ throw new Error(parsedPackage.error);
1832
+ const packageName = parsedPackage.packageName;
1833
+ runtimeName = buildRuntimeName(localName, packageName);
1834
+ const runner = parseAgentRunnerFrontmatter(frontmatter.runner, localName);
1835
+ validateExternalRunnerProfile(frontmatter, localName, runner);
1836
+ let advertise;
1837
+ if (frontmatter.advertise !== undefined) {
1838
+ if (frontmatter.advertise === "true")
1839
+ advertise = true;
1840
+ else if (frontmatter.advertise === "false")
1841
+ advertise = false;
1842
+ else
1843
+ throw new Error(`Agent '${localName}' has invalid advertise frontmatter; expected true or false.`);
1844
+ }
1845
+ const rawTools = parseFrontmatterList(frontmatter.tools);
1846
+ const parsedTools = splitToolList(rawTools);
1847
+ const tools = parsedTools.tools ?? [];
1848
+ const mcpDirectTools = parsedTools.mcpDirectTools ?? [];
1849
+ const excludeTools = parseFrontmatterList(frontmatter.excludeTools);
1850
+ const parsedAllowedAgents = parseFrontmatterList(frontmatter.allowedAgents);
1851
+ const allowedAgents = parsedAllowedAgents === undefined ? undefined : normalizeCapabilityCeilingAllowedAgents(parsedAllowedAgents);
1852
+ const defaultReads = parseFrontmatterList(frontmatter.defaultReads);
1853
+ const aliases = normalizeAgentAliases(parseFrontmatterList(frontmatter.aliases ?? frontmatter.alias), runtimeName);
1854
+ const profileError = validateCodeOwnedProfileRunner({ name: runtimeName, localName, aliases, runner });
1855
+ if (profileError)
1856
+ throw new Error(profileError);
1857
+ const skillStr = frontmatter.skill || frontmatter.skills;
1858
+ const skills = parseFrontmatterList(skillStr);
1859
+ const skillPath = parseFrontmatterList(frontmatter.skillPath);
1860
+ if (frontmatter.fallbackModels !== undefined)
1861
+ throw new Error(`Agent '${filePath}' uses removed frontmatter field 'fallbackModels'. Configure one model instead.`);
1862
+ const systemPromptMode = frontmatter.systemPromptMode === "replace"
1863
+ ? "replace"
1864
+ : frontmatter.systemPromptMode === "append"
1865
+ ? "append"
1866
+ : defaultSystemPromptMode(localName);
1867
+ const inheritProjectContext = frontmatter.inheritProjectContext === "true"
1868
+ ? true
1869
+ : frontmatter.inheritProjectContext === "false"
1870
+ ? false
1871
+ : defaultInheritProjectContext(localName);
1872
+ const inheritGlobalContext = frontmatter.inheritGlobalContext === "true";
1873
+ const inheritSkills = frontmatter.inheritSkills === "true"
1874
+ ? true
1875
+ : frontmatter.inheritSkills === "false"
1876
+ ? false
1877
+ : defaultInheritSkills();
1878
+ const defaultContext = frontmatter.defaultContext === "fork"
1879
+ ? "fork"
1880
+ : frontmatter.defaultContext === "fresh"
1881
+ ? "fresh"
1882
+ : undefined;
1883
+ let defaultAsync;
1884
+ if (frontmatter.async !== undefined) {
1885
+ if (frontmatter.async === "true")
1886
+ defaultAsync = true;
1887
+ else if (frontmatter.async === "false")
1888
+ defaultAsync = false;
1889
+ else
1890
+ throw new Error(`Agent '${localName}' has invalid async frontmatter; expected true or false.`);
1891
+ }
1892
+ let defaultTimeoutMs;
1893
+ if (frontmatter.timeoutMs !== undefined) {
1894
+ const parsed = Number(frontmatter.timeoutMs);
1895
+ if (!Number.isInteger(parsed) || parsed <= 0) {
1896
+ throw new Error(`Agent '${localName}' has invalid timeoutMs frontmatter; expected a positive integer.`);
1897
+ }
1898
+ defaultTimeoutMs = parsed;
1899
+ }
1900
+ let defaultToolTimeoutMs;
1901
+ if (frontmatter.toolTimeoutMs !== undefined) {
1902
+ const parsed = Number(frontmatter.toolTimeoutMs);
1903
+ if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 2_147_483_647) {
1904
+ throw new Error(`Agent '${localName}' has invalid toolTimeoutMs frontmatter; expected a positive integer no larger than 2147483647.`);
1905
+ }
1906
+ defaultToolTimeoutMs = parsed;
1907
+ }
1908
+ const defaultAcceptance = parseAgentAcceptanceFrontmatter(frontmatter.acceptance, localName);
1909
+ let outputMode;
1910
+ if (frontmatter.outputMode !== undefined) {
1911
+ if (frontmatter.outputMode === "inline" || frontmatter.outputMode === "file-only")
1912
+ outputMode = frontmatter.outputMode;
1913
+ else
1914
+ throw new Error(`Agent '${localName}' has invalid outputMode frontmatter; expected 'inline' or 'file-only'.`);
1915
+ }
1916
+ let acceptanceRole;
1917
+ if (frontmatter.acceptanceRole !== undefined && frontmatter.acceptanceRole.trim()) {
1918
+ if (frontmatter.acceptanceRole === "read-only" || frontmatter.acceptanceRole === "writer")
1919
+ acceptanceRole = frontmatter.acceptanceRole;
1920
+ else
1921
+ throw new Error(`Agent '${localName}' has invalid acceptanceRole frontmatter; expected 'read-only' or 'writer'.`);
1922
+ }
1923
+ const extensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.extensions), filePath);
1924
+ const subagentOnlyExtensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.subagentOnlyExtensions), filePath);
1925
+ const mutationTools = parseFrontmatterList(frontmatter.mutationTools);
1926
+ let fast;
1927
+ if (frontmatter.fast !== undefined) {
1928
+ if (frontmatter.fast === "true")
1929
+ fast = true;
1930
+ else if (frontmatter.fast === "false")
1931
+ fast = false;
1932
+ else
1933
+ throw new Error(`Agent '${localName}' has invalid fast frontmatter; expected true or false.`);
1934
+ }
1935
+ let allowNestedSubagents;
1936
+ if (frontmatter.allowNestedSubagents !== undefined) {
1937
+ if (frontmatter.allowNestedSubagents === "true")
1938
+ allowNestedSubagents = true;
1939
+ else if (frontmatter.allowNestedSubagents === "false")
1940
+ allowNestedSubagents = false;
1941
+ else
1942
+ throw new Error(`Agent '${localName}' has invalid allowNestedSubagents frontmatter; expected true or false.`);
1943
+ }
1944
+ const extraFields = {};
1945
+ for (const [key, value] of Object.entries(frontmatter)) {
1946
+ if (!KNOWN_FIELDS.has(key))
1947
+ extraFields[key] = value;
1948
+ }
1949
+ const parsedMaxSubagentDepth = Number(frontmatter.maxSubagentDepth);
1950
+ if (frontmatter.permission !== undefined && frontmatter.permissions !== undefined) {
1951
+ throw new Error(`Agent '${localName}' cannot declare both permission and permissions frontmatter.`);
1952
+ }
1953
+ const permissionSource = frontmatter.permissions ?? frontmatter.permission;
1954
+ const permissions = permissionSource?.trim()
1955
+ ? validatePermissionRules(parseYaml(permissionSource), `Agent '${localName}' permissions`)
1956
+ : undefined;
1957
+ let toolBudget;
1958
+ if (frontmatter.toolBudget !== undefined && frontmatter.toolBudget.trim()) {
1959
+ const parsed = JSON.parse(frontmatter.toolBudget);
1960
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1961
+ throw new Error(`Agent '${localName}' has invalid toolBudget frontmatter; expected a JSON object.`);
1962
+ }
1963
+ toolBudget = parsed;
1964
+ }
1965
+ let outputSchema;
1966
+ if (frontmatter.outputSchema !== undefined && frontmatter.outputSchema.trim()) {
1967
+ const parsed = JSON.parse(frontmatter.outputSchema);
1968
+ assertJsonSchemaObject(parsed, `Agent '${localName}' outputSchema`);
1969
+ outputSchema = parsed;
1970
+ }
1971
+ const maxSubagentDepth = Number.isInteger(parsedMaxSubagentDepth) && parsedMaxSubagentDepth >= 0
1972
+ ? parsedMaxSubagentDepth
1973
+ : undefined;
1974
+ const memory = parseMemoryFrontmatter(frontmatter.memory);
1975
+ const machine = validateOptionalMachine(frontmatter.machine, `Agent '${runtimeName}' frontmatter 'machine'`);
1976
+ const agent = {
1977
+ name: runtimeName,
1978
+ ...(runner !== undefined ? { runner } : {}),
1979
+ localName,
1980
+ ...(packageName !== undefined ? { packageName } : {}),
1981
+ ...(packageSource?.packageName ? { packageSourceName: packageSource.packageName } : {}),
1982
+ ...(packageSource?.packageVersion ? { packageSourceVersion: packageSource.packageVersion } : {}),
1983
+ ...(packageSource?.packageRoot ? { packageSourceRoot: packageSource.packageRoot } : {}),
1984
+ description: frontmatter.description,
1985
+ ...(advertise !== undefined ? { advertise } : {}),
1986
+ ...(aliases !== undefined ? { aliases } : {}),
1987
+ ...(rawTools !== undefined ? { tools } : {}),
1988
+ ...(excludeTools !== undefined ? { excludeTools } : {}),
1989
+ ...(allowNestedSubagents !== undefined ? { allowNestedSubagents } : {}),
1990
+ ...(allowedAgents !== undefined ? { allowedAgents } : {}),
1991
+ ...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
1992
+ ...(frontmatter.model !== undefined ? { model: frontmatter.model } : {}),
1993
+ ...(fast !== undefined ? { fast } : {}),
1994
+ ...(frontmatter.thinking !== undefined ? { thinking: frontmatter.thinking === "false" ? false : frontmatter.thinking } : {}),
1995
+ systemPromptMode,
1996
+ inheritProjectContext,
1997
+ inheritGlobalContext,
1998
+ inheritSkills,
1999
+ ...(defaultContext !== undefined ? { defaultContext } : {}),
2000
+ ...(defaultAsync !== undefined ? { defaultAsync } : {}),
2001
+ ...(defaultTimeoutMs !== undefined ? { defaultTimeoutMs } : {}),
2002
+ ...(defaultToolTimeoutMs !== undefined ? { defaultToolTimeoutMs } : {}),
2003
+ ...(defaultAcceptance !== undefined ? { defaultAcceptance } : {}),
2004
+ ...(acceptanceRole !== undefined ? { acceptanceRole } : {}),
2005
+ systemPrompt: body,
2006
+ source,
2007
+ filePath,
2008
+ ...(discoveryPriority !== undefined ? { discoveryPriority } : {}),
2009
+ ...(skills?.length ? { skills } : {}),
2010
+ ...(skillPath?.length ? { skillPath } : {}),
2011
+ ...(extensions !== undefined ? { extensions } : {}),
2012
+ ...(subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions } : {}),
2013
+ ...(mutationTools?.length ? { mutationTools } : {}),
2014
+ ...(machine !== undefined ? { machine } : {}),
2015
+ ...(frontmatter.output !== undefined ? { output: frontmatter.output } : {}),
2016
+ ...(outputMode !== undefined ? { outputMode } : {}),
2017
+ ...(outputSchema !== undefined ? { outputSchema } : {}),
2018
+ ...(defaultReads?.length ? { defaultReads } : {}),
2019
+ defaultProgress: frontmatter.defaultProgress === "true",
2020
+ interactive: frontmatter.interactive === "true",
2021
+ ...(maxSubagentDepth !== undefined ? { maxSubagentDepth } : {}),
2022
+ ...(toolBudget !== undefined ? { toolBudget } : {}),
2023
+ ...(permissions !== undefined ? { permissions } : {}),
2024
+ ...(memory !== undefined ? { memory } : {}),
2025
+ ...(Object.keys(extraFields).length > 0 ? { extraFields } : {}),
2026
+ };
2027
+ agentFrontmatterFields.set(agent, new Set(Object.keys(frontmatter)));
2028
+ agents.push(agent);
2029
+ }
2030
+ catch (error) {
2031
+ diagnostics.push({ source, filePath, ...(name ? { name } : {}), ...(runtimeName && runtimeName !== name ? { runtimeName } : {}), ...(packageSpecified ? { packageSpecified: true } : {}), ...(discoveryPriority !== undefined ? { discoveryPriority } : {}), error: error instanceof Error ? error.message : String(error) });
2032
+ }
2033
+ }
2034
+ return { agents, diagnostics };
2035
+ }
2036
+ function loadAgentsFromDir(dir, source, discoveryPriority, packageSource, inspection = inspectAgentDefinitionDirectory(dir)) {
2037
+ return loadAgentsFromDefinitionFiles(readAgentDefinitionFiles(dir, inspection), source, discoveryPriority, packageSource);
2038
+ }
2039
+ function reportAgentDefinitionDirectory(source, dir, inspection) {
2040
+ return {
2041
+ source,
2042
+ path: path.resolve(dir),
2043
+ state: inspection.state,
2044
+ ...(inspection.state === "candidates" ? { candidateCount: inspection.files.length } : {}),
2045
+ };
2046
+ }
2047
+ function loadChainsFromDir(dir, source) {
2048
+ const chains = new Map();
2049
+ const diagnostics = [];
2050
+ const directories = new Set();
2051
+ const files = listFilesRecursive(dir, (fileName) => fileName.endsWith(".chain.md") || fileName.endsWith(".chain.json"), dir, new Set(), directories);
2052
+ for (const filePath of files) {
2053
+ let content;
2054
+ try {
2055
+ content = fs.readFileSync(filePath, "utf-8");
2056
+ }
2057
+ catch {
2058
+ continue;
2059
+ }
2060
+ try {
2061
+ const chain = filePath.endsWith(".chain.json") ? parseJsonChain(content, source, filePath) : parseChain(content, source, filePath);
2062
+ const existing = chains.get(chain.name);
2063
+ if (existing && existing.filePath.endsWith(".chain.json") && filePath.endsWith(".chain.md"))
2064
+ continue;
2065
+ chains.set(chain.name, chain);
2066
+ }
2067
+ catch (error) {
2068
+ diagnostics.push({ source, filePath, error: error instanceof Error ? error.message : String(error) });
2069
+ continue;
2070
+ }
2071
+ }
2072
+ return { chains: Array.from(chains.values()), diagnostics, files, directories: [...directories] };
2073
+ }
2074
+ function isDirectory(p) {
2075
+ try {
2076
+ return fs.statSync(p).isDirectory();
2077
+ }
2078
+ catch {
2079
+ return false;
2080
+ }
2081
+ }
2082
+ function resolveNearestProjectAgentDirs(cwd) {
2083
+ const projectRoot = findConfiguredProjectRoot(cwd);
2084
+ if (!projectRoot)
2085
+ return { readDirs: [], candidateDirs: [], preferredDir: null };
2086
+ const legacyDir = path.join(projectRoot, ".agents");
2087
+ const preferredDir = path.join(getProjectConfigDir(projectRoot), "agents");
2088
+ const candidateDirs = [legacyDir, preferredDir];
2089
+ const readDirs = [];
2090
+ if (isDirectory(legacyDir))
2091
+ readDirs.push(legacyDir);
2092
+ if (isDirectory(preferredDir))
2093
+ readDirs.push(preferredDir);
2094
+ return { readDirs, candidateDirs, preferredDir };
2095
+ }
2096
+ function resolveNearestProjectChainDirs(cwd) {
2097
+ const projectRoot = findConfiguredProjectRoot(cwd);
2098
+ if (!projectRoot)
2099
+ return { readDirs: [], preferredDir: null };
2100
+ const preferredDir = path.join(getProjectConfigDir(projectRoot), "chains");
2101
+ return {
2102
+ readDirs: isDirectory(preferredDir) ? [preferredDir] : [],
2103
+ preferredDir,
2104
+ };
2105
+ }
2106
+ const BUILTIN_AGENTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "agents");
2107
+ // Candidate files and inspection state must describe the same cached builtin scan.
2108
+ const BUILTIN_AGENT_DEFINITION_INSPECTION = inspectAgentDefinitionDirectory(BUILTIN_AGENTS_DIR);
2109
+ const BUILTIN_AGENT_DEFINITION_FILES = readAgentDefinitionFiles(BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION);
2110
+ export const EXTRA_AGENT_DIRS_ENV = "PI_SUBAGENT_EXTRA_AGENT_DIRS";
2111
+ // Additional read-only directories to scan for agent definitions, supplied by the
2112
+ // launcher via PI_SUBAGENT_EXTRA_AGENT_DIRS (PATH-style, split on os/path delimiter).
2113
+ // Lets a hermetic wrapper (e.g. a Nix-store install) expose bundled agents without
2114
+ // copying or symlinking them into the writable agent dir. Loaded as "user" source,
2115
+ // at lower precedence than agents the user placed in their own agent dir.
2116
+ function extraUserAgentDirs() {
2117
+ const raw = process.env[EXTRA_AGENT_DIRS_ENV];
2118
+ if (!raw)
2119
+ return [];
2120
+ return raw
2121
+ .split(path.delimiter)
2122
+ .map((dir) => dir.trim())
2123
+ .filter((dir) => dir.length > 0);
2124
+ }
2125
+ function readConfiguredAgentScanDirs(filePath, key = "agentScanDirs") {
2126
+ if (!filePath)
2127
+ return [];
2128
+ try {
2129
+ const settings = readSettingsFileStrict(filePath);
2130
+ const subagents = settings.subagents;
2131
+ if (!subagents || typeof subagents !== "object" || Array.isArray(subagents))
2132
+ return [];
2133
+ const dirs = subagents[key];
2134
+ return Array.isArray(dirs) ? dirs.filter((dir) => typeof dir === "string" && dir.trim().length > 0) : [];
2135
+ }
2136
+ catch {
2137
+ return [];
2138
+ }
2139
+ }
2140
+ // Resolve existing ancestors to canonicalize missing descendants of symlinks.
2141
+ function canonicalAgentPath(filePath) {
2142
+ const resolved = path.resolve(filePath);
2143
+ try {
2144
+ return fs.realpathSync(resolved);
2145
+ }
2146
+ catch {
2147
+ const parent = path.dirname(resolved);
2148
+ return parent === resolved ? resolved : path.join(canonicalAgentPath(parent), path.basename(resolved));
2149
+ }
2150
+ }
2151
+ function agentExclusionRoots(userSettingsPath, projectSettingsPath) {
2152
+ return [userSettingsPath, projectSettingsPath].flatMap((settingsPath) => settingsPath
2153
+ ? readConfiguredAgentScanDirs(settingsPath, "agentExcludeDirs").map((entry) => {
2154
+ const resolved = path.resolve(path.dirname(settingsPath), expandHomePath(entry.trim()).replace(/[\\/]+/g, path.sep));
2155
+ return { resolved, real: canonicalAgentPath(resolved) };
2156
+ }) : []);
2157
+ }
2158
+ function agentExclusions(roots) {
2159
+ return (filePath) => {
2160
+ if (!roots.length)
2161
+ return false;
2162
+ if (roots.some((root) => isPathWithin(root.resolved, filePath)))
2163
+ return true;
2164
+ const real = canonicalAgentPath(filePath);
2165
+ return roots.some((root) => isPathWithin(root.real, real));
2166
+ };
2167
+ }
2168
+ function expandAgentScanDirPattern(pattern, isExcluded) {
2169
+ const expanded = expandHomePath(pattern.trim()).replace(/[\\/]+/g, path.sep);
2170
+ if (!expanded)
2171
+ return { dirs: [], watchPaths: [] };
2172
+ const wildcardMatches = [...expanded.matchAll(/\*/g)];
2173
+ if (wildcardMatches.length === 0) {
2174
+ const dir = path.resolve(expanded);
2175
+ return { dirs: !isExcluded(dir) && fs.existsSync(dir) ? [dir] : [], watchPaths: [dir] };
2176
+ }
2177
+ const parts = expanded.split(path.sep);
2178
+ const wildcardIndex = parts.findIndex((part) => part.includes("*"));
2179
+ if (wildcardMatches.length !== 1 || wildcardIndex === -1 || parts[wildcardIndex] !== "*")
2180
+ return { dirs: [], watchPaths: [] };
2181
+ const base = path.resolve(parts.slice(0, wildcardIndex).join(path.sep) || path.sep);
2182
+ if (isExcluded(base))
2183
+ return { dirs: [], watchPaths: [base] };
2184
+ const rest = parts.slice(wildcardIndex + 1);
2185
+ let entries;
2186
+ try {
2187
+ entries = fs.readdirSync(base, { withFileTypes: true });
2188
+ }
2189
+ catch {
2190
+ return { dirs: [], watchPaths: [base] };
2191
+ }
2192
+ const candidateDirs = entries.filter((entry) => entry.isDirectory()).map((entry) => path.join(base, entry.name, ...rest));
2193
+ return {
2194
+ dirs: candidateDirs.filter((dir) => !isExcluded(dir) && fs.existsSync(dir)),
2195
+ watchPaths: [base, ...candidateDirs],
2196
+ };
2197
+ }
2198
+ function settingsAgentScanDirs(entries, isExcluded) {
2199
+ const dirs = new Set();
2200
+ const watchPaths = new Set();
2201
+ for (const entry of entries) {
2202
+ const expanded = expandAgentScanDirPattern(entry, isExcluded);
2203
+ for (const dir of expanded.dirs)
2204
+ dirs.add(dir);
2205
+ for (const watchPath of expanded.watchPaths)
2206
+ watchPaths.add(watchPath);
2207
+ }
2208
+ return { dirs: [...dirs], watchPaths: [...watchPaths] };
2209
+ }
2210
+ const agentDiscoveryCache = new Map();
2211
+ function isPathWithin(root, candidate) {
2212
+ const relative = path.relative(path.resolve(root), path.resolve(candidate));
2213
+ return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
2214
+ }
2215
+ function addDirectoryWatchPaths(paths, root, files, directories = []) {
2216
+ const resolvedRoot = path.resolve(root);
2217
+ paths.add(resolvedRoot);
2218
+ // The initial recursive inspection is already bounded to this discovery
2219
+ // root. Keep every visited directory in the fingerprint so a file added to
2220
+ // an existing empty nested directory invalidates the snapshot too.
2221
+ for (const directory of directories) {
2222
+ if (isPathWithin(resolvedRoot, directory))
2223
+ paths.add(path.resolve(directory));
2224
+ }
2225
+ for (const file of files) {
2226
+ paths.add(path.resolve(file));
2227
+ let current = path.resolve(path.dirname(file));
2228
+ while (isPathWithin(resolvedRoot, current)) {
2229
+ paths.add(current);
2230
+ if (current === resolvedRoot)
2231
+ break;
2232
+ current = path.dirname(current);
2233
+ }
2234
+ }
2235
+ }
2236
+ function watchPathSignature(filePath, isExcluded) {
2237
+ try {
2238
+ const stat = fs.statSync(filePath);
2239
+ if (stat.isDirectory()) {
2240
+ const entries = fs.readdirSync(filePath, { withFileTypes: true })
2241
+ .filter((entry) => !isExcluded || !isExcluded(path.join(filePath, entry.name)))
2242
+ .sort((left, right) => left.name.localeCompare(right.name))
2243
+ .map((entry) => `${entry.name}:${entry.isDirectory() ? "d" : entry.isSymbolicLink() ? (isExcluded ? `l:${canonicalAgentPath(path.join(filePath, entry.name))}` : "l") : "f"}`)
2244
+ .join("|");
2245
+ return `directory:${entries}`;
2246
+ }
2247
+ return `file:${stat.size}:${stat.mtimeMs}`;
2248
+ }
2249
+ catch {
2250
+ return "missing";
2251
+ }
2252
+ }
2253
+ function discoveryFingerprint(sources) {
2254
+ const exclusionIdentity = JSON.stringify(sources.exclusionRoots.map((root) => ({ resolved: root.resolved, real: canonicalAgentPath(root.resolved) })));
2255
+ // A retargeted exclusion needs a fresh scan before fingerprinting old roots.
2256
+ if (exclusionIdentity !== JSON.stringify(sources.exclusionRoots))
2257
+ return exclusionIdentity;
2258
+ const rootIdentities = JSON.stringify(sources.identityWatchPaths.map((root) => [root, canonicalAgentPath(root)]));
2259
+ // Package metadata can redirect agents outside an excluded tree without chains.
2260
+ const unfilteredPaths = new Set([...sources.packageSubagentPaths.watchPaths, ...(sources.chainWatchPaths ?? [])]);
2261
+ return exclusionIdentity + "\n" + rootIdentities + "\n" + [...new Set([...sources.watchPaths, ...unfilteredPaths])]
2262
+ .filter((filePath) => unfilteredPaths.has(filePath) || filePath === sources.userSettingsPath || filePath === sources.projectSettingsPath || !sources.isExcluded(filePath))
2263
+ .sort((left, right) => left.localeCompare(right))
2264
+ .map((filePath) => `${filePath}:${watchPathSignature(filePath, sources.exclusionRoots.length && !unfilteredPaths.has(filePath) ? sources.isExcluded : undefined)}`)
2265
+ .join("\n");
2266
+ }
2267
+ function discoveryCacheKey(cwd, preferredModelProvider) {
2268
+ return JSON.stringify([
2269
+ path.resolve(cwd),
2270
+ preferredModelProvider ?? null,
2271
+ getProjectConfigDir(path.resolve(cwd)),
2272
+ getAgentDir(),
2273
+ os.homedir(),
2274
+ process.env.HOME ?? "",
2275
+ process.env.USERPROFILE ?? "",
2276
+ process.env[EXTRA_AGENT_DIRS_ENV] ?? "",
2277
+ process.env.PI_OFFLINE ?? "",
2278
+ process.env.APPDATA ?? "",
2279
+ ]);
2280
+ }
2281
+ function projectDiscoveryWatchPaths(cwd) {
2282
+ const paths = [];
2283
+ let current = path.resolve(cwd);
2284
+ while (true) {
2285
+ paths.push(getProjectConfigDir(current), path.join(current, ".agents"), path.join(current, ".git"));
2286
+ const parent = path.dirname(current);
2287
+ if (parent === current)
2288
+ break;
2289
+ current = parent;
2290
+ }
2291
+ return paths;
2292
+ }
2293
+ function packageEntryIncluded(scope, packageScopes) {
2294
+ if (scope === "both" || packageScopes.has("root"))
2295
+ return true;
2296
+ return packageScopes.has(scope);
2297
+ }
2298
+ function buildAgentDiscoverySources(cwd, preferredModelProvider) {
2299
+ const effectiveCwd = path.resolve(cwd);
2300
+ const userDirOld = path.join(getAgentDir(), "agents");
2301
+ const userDirNew = path.join(os.homedir(), ".agents");
2302
+ const userChainDir = getUserChainDir();
2303
+ const { readDirs: projectAgentDirs, candidateDirs: projectCandidateDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(effectiveCwd);
2304
+ const { readDirs: projectChainDirs, preferredDir: projectChainDir } = resolveNearestProjectChainDirs(effectiveCwd);
2305
+ const userSettingsPath = getUserAgentSettingsPath();
2306
+ const projectSettingsPath = getProjectAgentSettingsPath(effectiveCwd);
2307
+ const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd);
2308
+ const exclusionRoots = agentExclusionRoots(userSettingsPath, projectSettingsPath);
2309
+ const isExcluded = agentExclusions(exclusionRoots);
2310
+ const userScanDirs = settingsAgentScanDirs(readConfiguredAgentScanDirs(userSettingsPath), isExcluded);
2311
+ const projectScanDirs = settingsAgentScanDirs(readConfiguredAgentScanDirs(projectSettingsPath), isExcluded);
2312
+ const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
2313
+ const userLoaded = [...extraUserAgentDirs(), ...userScanDirs.dirs, userDirOld, userDirNew].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
2314
+ const inspection = inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
2315
+ return { dir, inspection, loaded: loadAgentsFromDir(dir, "user", discoveryPriority, undefined, inspection) };
2316
+ });
2317
+ const projectInspections = new Map(projectCandidateDirs.filter((dir) => !isExcluded(dir)).map((dir) => [dir, inspectAgentDefinitionDirectory(dir, undefined, isExcluded)]));
2318
+ const projectLoaded = [...projectScanDirs.dirs, ...projectAgentDirs].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
2319
+ const inspection = projectInspections.get(dir) ?? inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
2320
+ return { dir, inspection, loaded: loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : discoveryPriority, undefined, inspection) };
2321
+ });
2322
+ const packageLoaded = packageSubagentPaths.agents.filter((entry) => !isExcluded(entry.dir)).map((entry, index) => {
2323
+ const inspection = inspectAgentDefinitionDirectory(entry.dir, undefined, isExcluded);
2324
+ return { dir: entry.dir, inspection, packageEntry: entry, loaded: loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry, inspection) };
2325
+ });
2326
+ const watchPaths = new Set([
2327
+ userSettingsPath,
2328
+ ...(projectSettingsPath ? [projectSettingsPath] : []),
2329
+ ...projectDiscoveryWatchPaths(effectiveCwd),
2330
+ ...findProjectRootCandidates(effectiveCwd).map((root) => path.join(getProjectConfigDir(root), "settings.json")),
2331
+ ...userScanDirs.watchPaths,
2332
+ ...projectScanDirs.watchPaths,
2333
+ ...packageSubagentPaths.watchPaths,
2334
+ ]);
2335
+ for (const directory of userLoaded)
2336
+ addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
2337
+ for (const dir of projectCandidateDirs) {
2338
+ const inspection = projectInspections.get(dir);
2339
+ addDirectoryWatchPaths(watchPaths, dir, inspection?.files ?? [], inspection ? inspectedAgentDefinitionDirectories(inspection, dir) : []);
2340
+ }
2341
+ for (const directory of projectLoaded)
2342
+ addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
2343
+ for (const directory of packageLoaded)
2344
+ addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
2345
+ const userDir = process.env.PI_CODING_AGENT_DIR ? userDirOld : fs.existsSync(userDirNew) ? userDirNew : userDirOld;
2346
+ return {
2347
+ cwd: effectiveCwd,
2348
+ ...(preferredModelProvider !== undefined ? { preferredModelProvider } : {}),
2349
+ userDir,
2350
+ userDirOld,
2351
+ userDirNew,
2352
+ userChainDir,
2353
+ projectAgentDirs,
2354
+ projectCandidateDirs: projectCandidateDirs.filter((dir) => !isExcluded(dir)),
2355
+ projectAgentsDir,
2356
+ projectChainDirs,
2357
+ projectChainDir,
2358
+ userSettingsPath,
2359
+ projectSettingsPath,
2360
+ packageSubagentPaths,
2361
+ builtinLoaded,
2362
+ userLoaded,
2363
+ projectLoaded,
2364
+ projectInspections,
2365
+ packageLoaded,
2366
+ isExcluded,
2367
+ exclusionRoots,
2368
+ // Aliases outside excluded lexical subtrees can be retargeted into allowed
2369
+ // storage. Watch only their identity, never the excluded target's contents.
2370
+ identityWatchPaths: [...new Set([
2371
+ ...userScanDirs.watchPaths, ...projectScanDirs.watchPaths,
2372
+ ...extraUserAgentDirs(), userDirOld, userDirNew, ...projectCandidateDirs,
2373
+ ...packageSubagentPaths.agents.map((entry) => entry.dir),
2374
+ ])]
2375
+ .filter((dir) => !exclusionRoots.some((root) => isPathWithin(root.resolved, dir)) && isExcluded(dir)),
2376
+ watchPaths: [...watchPaths].filter((filePath) => !isExcluded(filePath) || filePath === userSettingsPath || filePath === projectSettingsPath),
2377
+ };
2378
+ }
2379
+ function ensureDiscoveryChains(sources) {
2380
+ if (sources.userChains)
2381
+ return;
2382
+ sources.packageChainLoaded = sources.packageSubagentPaths.chains.map((entry) => ({ entry, loaded: loadChainsFromDir(entry.dir, "package") }));
2383
+ sources.userChains = loadChainsFromDir(sources.userChainDir, "user");
2384
+ sources.projectChainLoaded = sources.projectChainDirs.map((dir) => ({ dir, loaded: loadChainsFromDir(dir, "project") }));
2385
+ const watchPaths = new Set(sources.packageSubagentPaths.watchPaths);
2386
+ addDirectoryWatchPaths(watchPaths, sources.userChainDir, sources.userChains.files, sources.userChains.directories);
2387
+ for (const chain of sources.projectChainLoaded)
2388
+ addDirectoryWatchPaths(watchPaths, chain.dir, chain.loaded.files, chain.loaded.directories);
2389
+ for (const chain of sources.packageChainLoaded)
2390
+ addDirectoryWatchPaths(watchPaths, chain.entry.dir, chain.loaded.files, chain.loaded.directories);
2391
+ sources.chainWatchPaths = watchPaths;
2392
+ sources.watchPaths = [...new Set([...sources.watchPaths, ...watchPaths])];
2393
+ }
2394
+ function getAgentDiscoverySources(cwd, preferredModelProvider, includeChains = false) {
2395
+ const key = discoveryCacheKey(cwd, preferredModelProvider);
2396
+ const cached = agentDiscoveryCache.get(key);
2397
+ if (cached && cached.fingerprint === discoveryFingerprint(cached.sources)) {
2398
+ if (includeChains) {
2399
+ ensureDiscoveryChains(cached.sources);
2400
+ cached.fingerprint = discoveryFingerprint(cached.sources);
2401
+ }
2402
+ return cached.sources;
2403
+ }
2404
+ const sources = buildAgentDiscoverySources(cwd, preferredModelProvider);
2405
+ const entry = { sources, fingerprint: discoveryFingerprint(sources) };
2406
+ agentDiscoveryCache.set(key, entry);
2407
+ if (includeChains) {
2408
+ ensureDiscoveryChains(sources);
2409
+ entry.fingerprint = discoveryFingerprint(sources);
2410
+ }
2411
+ return sources;
2412
+ }
2413
+ /** Clear process-local discovery snapshots, primarily for hosts that reload settings in place. */
2414
+ export function clearAgentDiscoveryCache() {
2415
+ agentDiscoveryCache.clear();
2416
+ }
2417
+ function ensureSettingsForScope(sources, scope, preferredModelProvider) {
2418
+ if (scope !== "project" && sources.userSettings === undefined) {
2419
+ if (sources.packageSubagentPaths.settingsErrors.user)
2420
+ throw sources.packageSubagentPaths.settingsErrors.user;
2421
+ sources.userSettings = selectProviderOverrides(readSubagentSettings(sources.userSettingsPath), preferredModelProvider);
2422
+ }
2423
+ if (scope !== "user" && sources.projectSettings === undefined) {
2424
+ if (sources.packageSubagentPaths.settingsErrors.project)
2425
+ throw sources.packageSubagentPaths.settingsErrors.project;
2426
+ sources.projectSettings = selectProviderOverrides(readSubagentSettings(sources.projectSettingsPath), preferredModelProvider);
2427
+ }
2428
+ }
2429
+ function settingsForScope(sources, scope) {
2430
+ // Parse only settings that participate in this projection. The source cache
2431
+ // still retains both source trees, while malformed out-of-scope settings do
2432
+ // not make an otherwise valid scoped projection fail.
2433
+ ensureSettingsForScope(sources, scope, sources.preferredModelProvider);
2434
+ return {
2435
+ user: scope === "project" ? EMPTY_SUBAGENT_SETTINGS : sources.userSettings ?? EMPTY_SUBAGENT_SETTINGS,
2436
+ project: scope === "user" ? EMPTY_SUBAGENT_SETTINGS : sources.projectSettings ?? EMPTY_SUBAGENT_SETTINGS,
2437
+ };
2438
+ }
2439
+ function configuredAgentsForScope(sources, scope, settingsScope = scope) {
2440
+ const { user: userSettings, project: projectSettings } = settingsForScope(sources, settingsScope);
2441
+ const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, sources.projectSettingsPath);
2442
+ const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath, defaultProvider);
2443
+ const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, sources.projectSettingsPath);
2444
+ const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, sources.projectSettingsPath);
2445
+ const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, sources.projectSettingsPath);
2446
+ const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, sources.projectSettingsPath);
2447
+ const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions);
2448
+ const builtin = applyBuiltinOverrides(applyDefaults(sources.builtinLoaded.agents), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2449
+ const user = applyCustomAgentOverrides(applyDefaults(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.agents)), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2450
+ const projectMap = new Map();
2451
+ if (scope !== "user")
2452
+ for (const loaded of sources.projectLoaded)
2453
+ for (const agent of loaded.loaded.agents)
2454
+ projectMap.set(agent.name, agent);
2455
+ const project = applyCustomAgentOverrides(applyDefaults(Array.from(projectMap.values())), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2456
+ const packageMap = new Map();
2457
+ for (const loaded of sources.packageLoaded) {
2458
+ if (!loaded.packageEntry || !packageEntryIncluded(scope, loaded.packageEntry.scope))
2459
+ continue;
2460
+ for (const agent of loaded.loaded.agents)
2461
+ if (!packageMap.has(agent.name))
2462
+ packageMap.set(agent.name, agent);
2463
+ }
2464
+ const packageAgents = applyCustomAgentOverrides(applyDefaults(Array.from(packageMap.values())), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2465
+ return {
2466
+ builtin,
2467
+ package: packageAgents,
2468
+ user,
2469
+ project,
2470
+ userSettings,
2471
+ projectSettings,
2472
+ maxThinking,
2473
+ modelScope: projectSettings.modelScope ?? userSettings.modelScope,
2474
+ };
2475
+ }
2476
+ function discoveryDirectories(sources, scope) {
2477
+ const directories = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
2478
+ if (scope !== "project")
2479
+ for (const directory of sources.userLoaded)
2480
+ directories.push(reportAgentDefinitionDirectory("user", directory.dir, directory.inspection));
2481
+ if (scope !== "user") {
2482
+ const reported = new Set();
2483
+ for (const dir of sources.projectCandidateDirs) {
2484
+ reported.add(path.resolve(dir));
2485
+ directories.push(reportAgentDefinitionDirectory("project", dir, sources.projectInspections.get(dir)));
2486
+ }
2487
+ for (const directory of sources.projectLoaded) {
2488
+ if (!reported.has(path.resolve(directory.dir)))
2489
+ directories.push(reportAgentDefinitionDirectory("project", directory.dir, directory.inspection));
2490
+ }
2491
+ }
2492
+ for (const directory of sources.packageLoaded) {
2493
+ if (directory.packageEntry && packageEntryIncluded(scope, directory.packageEntry.scope))
2494
+ directories.push(reportAgentDefinitionDirectory("package", directory.dir, directory.inspection));
2495
+ }
2496
+ return directories;
2497
+ }
2498
+ function discoveryDiagnostics(sources, scope) {
2499
+ return [
2500
+ ...sources.builtinLoaded.diagnostics,
2501
+ ...(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.diagnostics)),
2502
+ ...(scope === "user" ? [] : sources.projectLoaded.flatMap((loaded) => loaded.loaded.diagnostics)),
2503
+ ...sources.packageLoaded
2504
+ .filter((loaded) => loaded.packageEntry && packageEntryIncluded(scope, loaded.packageEntry.scope))
2505
+ .flatMap((loaded) => loaded.loaded.diagnostics),
2506
+ ];
2507
+ }
2508
+ function buildEffectiveDiscovery(sources, scope) {
2509
+ const configured = configuredAgentsForScope(sources, scope);
2510
+ const agents = applySubagentMaxThinking(mergeAgentsForScope(scope, configured.user, configured.project, configured.builtin, configured.package).filter((agent) => agent.disabled !== true), configured.maxThinking);
2511
+ return {
2512
+ agents,
2513
+ agentDiagnostics: discoveryDiagnostics(sources, scope),
2514
+ projectAgentsDir: sources.projectAgentsDir,
2515
+ cwd: sources.cwd,
2516
+ scope,
2517
+ directories: discoveryDirectories(sources, scope),
2518
+ ...(configured.modelScope !== undefined ? { modelScope: configured.modelScope } : {}),
2519
+ ...(configured.maxThinking !== undefined ? { maxThinking: configured.maxThinking } : {}),
2520
+ };
2521
+ }
2522
+ function buildAllDiscovery(sources, includeChains, settingsScope) {
2523
+ if (includeChains)
2524
+ ensureDiscoveryChains(sources);
2525
+ const configured = configuredAgentsForScope(sources, "both", settingsScope);
2526
+ const packageChainMap = new Map();
2527
+ const packageChainDiagnostics = [];
2528
+ for (const chain of sources.packageChainLoaded ?? []) {
2529
+ packageChainDiagnostics.push(...chain.loaded.diagnostics);
2530
+ for (const definition of chain.loaded.chains)
2531
+ if (!packageChainMap.has(definition.name))
2532
+ packageChainMap.set(definition.name, definition);
2533
+ }
2534
+ const projectChainMap = new Map();
2535
+ const projectChainDiagnostics = [];
2536
+ for (const chain of sources.projectChainLoaded ?? []) {
2537
+ projectChainDiagnostics.push(...chain.loaded.diagnostics);
2538
+ for (const definition of chain.loaded.chains)
2539
+ projectChainMap.set(definition.name, definition);
2540
+ }
2541
+ const chains = [
2542
+ ...Array.from(packageChainMap.values()),
2543
+ ...(sources.userChains?.chains ?? []),
2544
+ ...Array.from(projectChainMap.values()),
2545
+ ];
2546
+ return {
2547
+ builtin: applySubagentMaxThinking(configured.builtin, configured.maxThinking),
2548
+ package: applySubagentMaxThinking(configured.package, configured.maxThinking),
2549
+ user: applySubagentMaxThinking(configured.user, configured.maxThinking),
2550
+ project: applySubagentMaxThinking(configured.project, configured.maxThinking),
2551
+ agentDiagnostics: [
2552
+ ...sources.builtinLoaded.diagnostics,
2553
+ ...sources.userLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
2554
+ ...sources.packageLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
2555
+ ...sources.projectLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
2556
+ ],
2557
+ chains,
2558
+ chainDiagnostics: [...packageChainDiagnostics, ...(sources.userChains?.diagnostics ?? []), ...projectChainDiagnostics],
2559
+ cwd: sources.cwd,
2560
+ userDir: sources.userDir,
2561
+ projectDir: sources.projectAgentsDir,
2562
+ userChainDir: sources.userChainDir,
2563
+ projectChainDir: sources.projectChainDir,
2564
+ userSettingsPath: sources.userSettingsPath,
2565
+ projectSettingsPath: sources.projectSettingsPath,
2566
+ ...(configured.maxThinking !== undefined ? { maxThinking: configured.maxThinking } : {}),
2567
+ };
2568
+ }
2569
+ export function discoverAgentSnapshot(cwd, scope, preferredModelProvider, options = {}) {
2570
+ const includeChains = options.includeChains !== false;
2571
+ const sources = getAgentDiscoverySources(cwd, preferredModelProvider, includeChains);
2572
+ return { effective: buildEffectiveDiscovery(sources, scope), all: buildAllDiscovery(sources, includeChains, scope) };
2573
+ }
2574
+ function discoverAgentsUncached(cwd, scope, preferredModelProvider) {
2575
+ const effectiveCwd = path.resolve(cwd);
2576
+ const userDirOld = path.join(getAgentDir(), "agents");
2577
+ const userDirNew = path.join(os.homedir(), ".agents");
2578
+ const { readDirs: projectAgentDirs, candidateDirs: projectCandidateDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(effectiveCwd);
2579
+ const userSettingsPath = getUserAgentSettingsPath();
2580
+ const projectSettingsPath = getProjectAgentSettingsPath(effectiveCwd);
2581
+ const userSettings = selectProviderOverrides(scope === "project" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(userSettingsPath), preferredModelProvider);
2582
+ const projectSettings = selectProviderOverrides(scope === "user" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(projectSettingsPath), preferredModelProvider);
2583
+ const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath);
2584
+ const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider);
2585
+ const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
2586
+ const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
2587
+ const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
2588
+ const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, projectSettingsPath);
2589
+ const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
2590
+ const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd, { includeUser: scope !== "project", includeProject: scope !== "user" });
2591
+ const isExcluded = agentExclusions(agentExclusionRoots(userSettingsPath, projectSettingsPath));
2592
+ const directories = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
2593
+ const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
2594
+ const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions);
2595
+ const builtinAgents = applyBuiltinOverrides(applyDefaults(builtinLoaded.agents), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2596
+ const userScanDirs = settingsAgentScanDirs(userSettings.agentScanDirs ?? [], isExcluded);
2597
+ const projectScanDirs = settingsAgentScanDirs(projectSettings.agentScanDirs ?? [], isExcluded);
2598
+ const userLoaded = scope === "project" ? [] : [...extraUserAgentDirs(), ...userScanDirs.dirs, userDirOld, userDirNew].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
2599
+ const inspection = inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
2600
+ directories.push(reportAgentDefinitionDirectory("user", dir, inspection));
2601
+ return loadAgentsFromDir(dir, "user", discoveryPriority, undefined, inspection);
2602
+ });
2603
+ const userAgents = applyCustomAgentOverrides(applyDefaults(userLoaded.flatMap((loaded) => loaded.agents)), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2604
+ const projectInspections = scope === "user" ? new Map() : new Map(projectCandidateDirs.filter((dir) => !isExcluded(dir)).map((dir) => [dir, inspectAgentDefinitionDirectory(dir, undefined, isExcluded)]));
2605
+ if (scope !== "user")
2606
+ for (const [dir, inspection] of projectInspections)
2607
+ directories.push(reportAgentDefinitionDirectory("project", dir, inspection));
2608
+ const projectLoaded = scope === "user" ? [] : [...projectScanDirs.dirs, ...projectAgentDirs].filter((dir) => !isExcluded(dir)).map((dir, discoveryPriority) => {
2609
+ const inspection = projectInspections.get(dir) ?? inspectAgentDefinitionDirectory(dir, undefined, isExcluded);
2610
+ if (!projectInspections.has(dir))
2611
+ directories.push(reportAgentDefinitionDirectory("project", dir, inspection));
2612
+ return loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : discoveryPriority, undefined, inspection);
2613
+ });
2614
+ const projectAgents = applyCustomAgentOverrides(applyDefaults(projectLoaded.flatMap((loaded) => loaded.agents)), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2615
+ const packageLoaded = packageSubagentPaths.agents.filter((entry) => !isExcluded(entry.dir)).map((entry, index) => {
2616
+ const inspection = inspectAgentDefinitionDirectory(entry.dir, undefined, isExcluded);
2617
+ directories.push(reportAgentDefinitionDirectory("package", entry.dir, inspection));
2618
+ return loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry, inspection);
2619
+ });
2620
+ const packageMap = new Map();
2621
+ for (const loaded of packageLoaded)
2622
+ for (const agent of loaded.agents)
2623
+ if (!packageMap.has(agent.name))
2624
+ packageMap.set(agent.name, agent);
2625
+ const packageAgents = applyCustomAgentOverrides(applyDefaults(Array.from(packageMap.values())), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2626
+ const agents = applySubagentMaxThinking(mergeAgentsForScope(scope, userAgents, projectAgents, builtinAgents, packageAgents).filter((agent) => agent.disabled !== true), maxThinking);
2627
+ const agentDiagnostics = [...builtinLoaded.diagnostics, ...userLoaded.flatMap((loaded) => loaded.diagnostics), ...projectLoaded.flatMap((loaded) => loaded.diagnostics), ...packageLoaded.flatMap((loaded) => loaded.diagnostics)];
2628
+ return { agents, agentDiagnostics, projectAgentsDir, cwd: effectiveCwd, scope, directories, ...(modelScope !== undefined ? { modelScope } : {}), ...(maxThinking !== undefined ? { maxThinking } : {}) };
2629
+ }
2630
+ export function discoverAgents(cwd, scope, preferredModelProvider) {
2631
+ if (scope !== "both")
2632
+ return discoverAgentsUncached(cwd, scope, preferredModelProvider);
2633
+ const sources = getAgentDiscoverySources(cwd, preferredModelProvider);
2634
+ return buildEffectiveDiscovery(sources, scope);
2635
+ }
2636
+ export function discoverAgentsAll(cwd, preferredModelProvider) {
2637
+ return discoverAgentSnapshot(cwd, "both", preferredModelProvider).all;
2638
+ }
2639
+ //# sourceMappingURL=agents.js.map