@explyt/ai-agent 0.1.0-rc.1 → 0.1.3

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 (1219) hide show
  1. package/README.md +14 -15
  2. package/THIRD-PARTY-NOTICES.md +153 -5
  3. package/agent-docs/README.md +43 -0
  4. package/agent-docs/mcp.md +111 -0
  5. package/agent-docs/rules.md +92 -0
  6. package/agent-docs/settings.md +54 -0
  7. package/agent-docs/skills.md +90 -0
  8. package/dist/app-bridge.bundle.js +67 -0
  9. package/dist/cli/engine.js +680 -135
  10. package/dist/cli/index.js +152 -194
  11. package/dist/extensions/bash.js +1 -0
  12. package/dist/extensions/custom-provider.js +1 -0
  13. package/dist/extensions/hello.js +1 -1
  14. package/dist/extensions/identity.js +1 -0
  15. package/dist/extensions/mcp.js +1 -0
  16. package/dist/extensions/misc-hacks.js +1 -0
  17. package/dist/extensions/policy.js +1 -1
  18. package/dist/extensions/rules.js +1 -0
  19. package/dist/extensions/skills.js +1 -0
  20. package/dist/mcp-adapter.js +602 -0
  21. package/dist/mcp-keyring-helper.cjs +89 -0
  22. package/dist/mcp-script-worker.mjs +130 -0
  23. package/node_modules/acorn/CHANGELOG.md +998 -0
  24. package/node_modules/acorn/LICENSE +21 -0
  25. package/node_modules/acorn/README.md +309 -0
  26. package/node_modules/acorn/bin/acorn +4 -0
  27. package/node_modules/acorn/dist/acorn.d.mts +897 -0
  28. package/node_modules/acorn/dist/acorn.d.ts +897 -0
  29. package/node_modules/acorn/dist/acorn.js +6342 -0
  30. package/node_modules/acorn/dist/acorn.mjs +6313 -0
  31. package/node_modules/acorn/dist/bin.js +90 -0
  32. package/node_modules/acorn/package.json +50 -0
  33. package/node_modules/default-browser/package.json +1 -1
  34. package/node_modules/default-browser/windows.js +3 -1
  35. package/node_modules/fast-uri/index.js +221 -49
  36. package/node_modules/fast-uri/lib/schemes.js +9 -4
  37. package/node_modules/fast-uri/lib/utils.js +396 -92
  38. package/node_modules/fast-uri/package.json +1 -1
  39. package/node_modules/fast-uri/test/component-safe-serialization.test.js +163 -0
  40. package/node_modules/fast-uri/test/equal.test.js +31 -3
  41. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
  42. package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
  43. package/node_modules/fast-uri/test/ipv6-validation.test.js +124 -0
  44. package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
  45. package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
  46. package/node_modules/fast-uri/test/parse.test.js +7 -3
  47. package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
  48. package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
  49. package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
  50. package/node_modules/fast-uri/test/security-normalization.test.js +139 -0
  51. package/node_modules/fast-uri/test/security.test.js +75 -3
  52. package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
  53. package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
  54. package/node_modules/jose/dist/types/index.d.ts +1 -2
  55. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +12 -25
  56. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +18 -31
  57. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +12 -25
  58. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +24 -49
  59. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +15 -30
  60. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +29 -51
  61. package/node_modules/jose/dist/types/jwk/embedded.d.ts +5 -8
  62. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +7 -9
  63. package/node_modules/jose/dist/types/jwks/local.d.ts +10 -13
  64. package/node_modules/jose/dist/types/jwks/remote.d.ts +30 -42
  65. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +8 -13
  66. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +14 -26
  67. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +10 -19
  68. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +14 -26
  69. package/node_modules/jose/dist/types/jws/general/sign.d.ts +19 -33
  70. package/node_modules/jose/dist/types/jws/general/verify.d.ts +17 -32
  71. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +20 -27
  72. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +32 -42
  73. package/node_modules/jose/dist/types/jwt/sign.d.ts +10 -21
  74. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +13 -28
  75. package/node_modules/jose/dist/types/jwt/verify.d.ts +19 -22
  76. package/node_modules/jose/dist/types/key/export.d.ts +10 -10
  77. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +15 -22
  78. package/node_modules/jose/dist/types/key/generate_secret.d.ts +12 -19
  79. package/node_modules/jose/dist/types/key/import.d.ts +25 -31
  80. package/node_modules/jose/dist/types/types.d.ts +186 -319
  81. package/node_modules/jose/dist/types/util/base64url.d.ts +7 -7
  82. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +5 -7
  83. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +6 -5
  84. package/node_modules/jose/dist/types/util/errors.d.ts +50 -88
  85. package/node_modules/jose/dist/webapi/index.js +70 -32
  86. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +6 -8
  87. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +25 -26
  88. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +14 -10
  89. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +34 -71
  90. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +38 -49
  91. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +100 -161
  92. package/node_modules/jose/dist/webapi/jwk/embedded.js +29 -18
  93. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +51 -64
  94. package/node_modules/jose/dist/webapi/jwks/local.js +55 -74
  95. package/node_modules/jose/dist/webapi/jwks/remote.js +91 -160
  96. package/node_modules/jose/dist/webapi/jws/compact/sign.js +19 -20
  97. package/node_modules/jose/dist/webapi/jws/compact/verify.js +7 -8
  98. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +22 -30
  99. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +11 -23
  100. package/node_modules/jose/dist/webapi/jws/general/sign.js +55 -71
  101. package/node_modules/jose/dist/webapi/jws/general/verify.js +45 -41
  102. package/node_modules/jose/dist/webapi/jwt/decrypt.js +12 -22
  103. package/node_modules/jose/dist/webapi/jwt/encrypt.js +44 -100
  104. package/node_modules/jose/dist/webapi/jwt/sign.js +18 -50
  105. package/node_modules/jose/dist/webapi/jwt/unsecured.js +33 -63
  106. package/node_modules/jose/dist/webapi/jwt/verify.js +12 -14
  107. package/node_modules/jose/dist/webapi/key/export.js +32 -41
  108. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +32 -45
  109. package/node_modules/jose/dist/webapi/key/generate_secret.js +35 -39
  110. package/node_modules/jose/dist/webapi/key/import.js +48 -52
  111. package/node_modules/jose/dist/webapi/lib/asn1.js +128 -164
  112. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +72 -41
  113. package/node_modules/jose/dist/webapi/lib/content_encryption.js +75 -127
  114. package/node_modules/jose/dist/webapi/lib/deflate.js +36 -40
  115. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +102 -93
  116. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +178 -177
  117. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +72 -107
  118. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +62 -61
  119. package/node_modules/jose/dist/webapi/lib/jws_sign.js +44 -72
  120. package/node_modules/jose/dist/webapi/lib/jws_verify.js +82 -103
  121. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +134 -185
  122. package/node_modules/jose/dist/webapi/lib/key.js +147 -124
  123. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +13 -8
  124. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +8 -6
  125. package/node_modules/jose/dist/webapi/lib/key_management.js +169 -229
  126. package/node_modules/jose/dist/webapi/lib/validate.js +122 -0
  127. package/node_modules/jose/dist/webapi/util/base64url.js +14 -37
  128. package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -31
  129. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +18 -23
  130. package/node_modules/jose/dist/webapi/util/errors.js +94 -84
  131. package/node_modules/jose/package.json +17 -81
  132. package/node_modules/pi-mcp-adapter/CHANGELOG.md +156 -0
  133. package/node_modules/pi-mcp-adapter/README.md +121 -13
  134. package/node_modules/pi-mcp-adapter/agent-dir.ts +12 -4
  135. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +1 -1
  136. package/node_modules/pi-mcp-adapter/cli.js +188 -5
  137. package/node_modules/pi-mcp-adapter/commands.ts +136 -20
  138. package/node_modules/pi-mcp-adapter/config.ts +74 -15
  139. package/node_modules/pi-mcp-adapter/direct-tools.ts +134 -72
  140. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +10 -0
  141. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +63 -0
  142. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +1 -0
  143. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +8 -0
  144. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +356 -0
  145. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +1 -0
  146. package/node_modules/pi-mcp-adapter/dist/config.d.ts +123 -0
  147. package/node_modules/pi-mcp-adapter/dist/config.js +1088 -0
  148. package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -0
  149. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +24 -0
  150. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +336 -0
  151. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -0
  152. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +19 -0
  153. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +319 -0
  154. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +1 -0
  155. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +2 -0
  156. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +156 -0
  157. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +1 -0
  158. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +1 -0
  159. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +15 -0
  160. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +1 -0
  161. package/node_modules/pi-mcp-adapter/dist/types.d.ts +566 -0
  162. package/node_modules/pi-mcp-adapter/dist/types.js +287 -0
  163. package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -0
  164. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +6 -0
  165. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +37 -0
  166. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +1 -0
  167. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +104 -0
  168. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +59 -0
  169. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +1 -0
  170. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +4 -0
  171. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +27 -0
  172. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +1 -0
  173. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +32 -0
  174. package/node_modules/pi-mcp-adapter/dist/utils.js +338 -0
  175. package/node_modules/pi-mcp-adapter/dist/utils.js.map +1 -0
  176. package/node_modules/pi-mcp-adapter/failure-backoff.ts +23 -0
  177. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -8
  178. package/node_modules/pi-mcp-adapter/index.ts +434 -36
  179. package/node_modules/pi-mcp-adapter/init.ts +102 -35
  180. package/node_modules/pi-mcp-adapter/lifecycle.ts +323 -28
  181. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +161 -37
  182. package/node_modules/pi-mcp-adapter/mcp-auth.ts +60 -2
  183. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +385 -0
  184. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +27 -3
  185. package/node_modules/pi-mcp-adapter/mcp-code.ts +6 -0
  186. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +155 -16
  187. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +95 -7
  188. package/node_modules/pi-mcp-adapter/mcp-panel.ts +87 -22
  189. package/node_modules/pi-mcp-adapter/mcp-probe.ts +18 -4
  190. package/node_modules/pi-mcp-adapter/mcp-references.ts +376 -0
  191. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +22 -20
  192. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +2 -1
  193. package/node_modules/pi-mcp-adapter/mcp-status.ts +8 -19
  194. package/node_modules/pi-mcp-adapter/metadata-cache.ts +66 -14
  195. package/node_modules/pi-mcp-adapter/namespace-tools.ts +276 -0
  196. package/node_modules/pi-mcp-adapter/npx-resolver.ts +81 -26
  197. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +168 -0
  198. package/node_modules/pi-mcp-adapter/package.json +29 -8
  199. package/node_modules/pi-mcp-adapter/proxy-modes.ts +229 -50
  200. package/node_modules/pi-mcp-adapter/request-headers-command.ts +330 -0
  201. package/node_modules/pi-mcp-adapter/search-ranking.ts +167 -16
  202. package/node_modules/pi-mcp-adapter/server-manager.ts +243 -14
  203. package/node_modules/pi-mcp-adapter/session-recovery.ts +15 -2
  204. package/node_modules/pi-mcp-adapter/state.ts +1 -3
  205. package/node_modules/pi-mcp-adapter/tool-approval.ts +63 -9
  206. package/node_modules/pi-mcp-adapter/tool-metadata.ts +62 -4
  207. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +195 -15
  208. package/node_modules/pi-mcp-adapter/types.ts +229 -29
  209. package/node_modules/pi-mcp-adapter/ui-server.ts +41 -36
  210. package/node_modules/pi-mcp-adapter/ui-session.ts +2 -1
  211. package/node_modules/pi-mcp-adapter/utils.ts +91 -19
  212. package/node_modules/pi-subagents/CHANGELOG.md +582 -0
  213. package/node_modules/pi-subagents/README.md +6 -0
  214. package/node_modules/pi-subagents/agents/claude-code-writer.md +15 -0
  215. package/node_modules/pi-subagents/agents/claude-code.md +15 -0
  216. package/node_modules/pi-subagents/agents/codex-exec-writer.md +15 -0
  217. package/node_modules/pi-subagents/agents/codex-exec.md +15 -0
  218. package/node_modules/pi-subagents/agents/cursor-agent-writer.md +14 -0
  219. package/node_modules/pi-subagents/agents/cursor-agent.md +14 -0
  220. package/node_modules/pi-subagents/agents/oracle.md +9 -5
  221. package/node_modules/pi-subagents/agents/researcher.md +1 -1
  222. package/node_modules/pi-subagents/agents/reviewer.md +15 -4
  223. package/node_modules/pi-subagents/agents/scout.md +3 -3
  224. package/node_modules/pi-subagents/agents/worker.md +3 -2
  225. package/node_modules/pi-subagents/async-retention-discovery-worker.mjs +180 -0
  226. package/node_modules/pi-subagents/docs/agents.md +164 -14
  227. package/node_modules/pi-subagents/docs/configuration.md +204 -24
  228. package/node_modules/pi-subagents/docs/extension-api.md +146 -11
  229. package/node_modules/pi-subagents/docs/missions.md +5 -3
  230. package/node_modules/pi-subagents/docs/models.md +74 -8
  231. package/node_modules/pi-subagents/docs/observability.md +100 -12
  232. package/node_modules/pi-subagents/docs/tool-reference.md +185 -46
  233. package/node_modules/pi-subagents/docs/workflows.md +317 -5
  234. package/node_modules/pi-subagents/index.ts +10 -1
  235. package/node_modules/pi-subagents/install.mjs +1 -1
  236. package/node_modules/pi-subagents/package.json +7 -2
  237. package/node_modules/pi-subagents/prompts/council.md +60 -0
  238. package/node_modules/pi-subagents/prompts/parallel-review.md +5 -1
  239. package/node_modules/pi-subagents/prompts/review-loop.md +11 -7
  240. package/node_modules/pi-subagents/skills/council-mode/SKILL.md +59 -0
  241. package/node_modules/pi-subagents/skills/council-mode/references/pass-contracts.md +150 -0
  242. package/node_modules/pi-subagents/skills/pi-subagents/SKILL.md +87 -25
  243. package/node_modules/pi-subagents/skills/pi-subagents/references/constraints-and-recipes.md +40 -221
  244. package/node_modules/pi-subagents/skills/pi-subagents/references/execution-controls.md +136 -26
  245. package/node_modules/pi-subagents/skills/pi-subagents/references/management-authoring-rpc.md +8 -8
  246. package/node_modules/pi-subagents/skills/pi-subagents/references/multi-lane-orchestration.md +51 -0
  247. package/node_modules/pi-subagents/skills/pi-subagents/references/prompting-and-roles.md +99 -46
  248. package/node_modules/pi-subagents/skills/pi-subagents/references/review-and-validation.md +73 -0
  249. package/node_modules/pi-subagents/src/agents/agent-management.ts +541 -442
  250. package/node_modules/pi-subagents/src/agents/agent-refinements.ts +4 -4
  251. package/node_modules/pi-subagents/src/agents/agent-serializer.ts +20 -4
  252. package/node_modules/pi-subagents/src/agents/agents.ts +1177 -267
  253. package/node_modules/pi-subagents/src/agents/builtin-names.ts +15 -0
  254. package/node_modules/pi-subagents/src/agents/runtime-agent-events.ts +70 -0
  255. package/node_modules/pi-subagents/src/agents/runtime-agent-registry.ts +429 -0
  256. package/node_modules/pi-subagents/src/agents/skills.ts +1 -1
  257. package/node_modules/pi-subagents/src/api/agents.ts +12 -0
  258. package/node_modules/pi-subagents/src/api/background-work.ts +12 -3
  259. package/node_modules/pi-subagents/src/api/delegation.ts +0 -7
  260. package/node_modules/pi-subagents/src/api/external-job-provider.ts +195 -0
  261. package/node_modules/pi-subagents/src/api/external-runs.ts +237 -84
  262. package/node_modules/pi-subagents/src/api/preflight.ts +140 -42
  263. package/node_modules/pi-subagents/src/api/project-panes.ts +2 -0
  264. package/node_modules/pi-subagents/src/api/shared-types.ts +5 -0
  265. package/node_modules/pi-subagents/src/extension/config.ts +134 -2
  266. package/node_modules/pi-subagents/src/extension/doctor.ts +54 -6
  267. package/node_modules/pi-subagents/src/extension/fanout-child.ts +9 -6
  268. package/node_modules/pi-subagents/src/extension/index.ts +361 -118
  269. package/node_modules/pi-subagents/src/extension/public-execution.ts +149 -10
  270. package/node_modules/pi-subagents/src/extension/rpc.ts +229 -23
  271. package/node_modules/pi-subagents/src/extension/schemas.ts +81 -58
  272. package/node_modules/pi-subagents/src/extension/tool-description.ts +70 -31
  273. package/node_modules/pi-subagents/src/extension/tool-result.ts +19 -0
  274. package/node_modules/pi-subagents/src/inspectors/herdr/actions.ts +16 -10
  275. package/node_modules/pi-subagents/src/inspectors/herdr/client.ts +3 -3
  276. package/node_modules/pi-subagents/src/inspectors/herdr/focus.ts +55 -0
  277. package/node_modules/pi-subagents/src/inspectors/herdr/inspector-runner.ts +10 -4
  278. package/node_modules/pi-subagents/src/inspectors/herdr/project-panes.ts +230 -50
  279. package/node_modules/pi-subagents/src/inspectors/herdr/session-roots-codec.ts +42 -0
  280. package/node_modules/pi-subagents/src/inspectors/herdr/shell-command.ts +16 -0
  281. package/node_modules/pi-subagents/src/integrations/herdr-status.ts +75 -5
  282. package/node_modules/pi-subagents/src/intercom/intercom-bridge.ts +9 -5
  283. package/node_modules/pi-subagents/src/intercom/native-supervisor-channel.ts +51 -52
  284. package/node_modules/pi-subagents/src/intercom/result-intercom.ts +2 -0
  285. package/node_modules/pi-subagents/src/missions/goal-driver.ts +3 -1
  286. package/node_modules/pi-subagents/src/missions/lifecycle.ts +10 -8
  287. package/node_modules/pi-subagents/src/missions/store.ts +16 -16
  288. package/node_modules/pi-subagents/src/missions/workflow-state.ts +8 -4
  289. package/node_modules/pi-subagents/src/profiles/profiles.ts +8 -7
  290. package/node_modules/pi-subagents/src/runs/background/active-async-capacity.ts +517 -0
  291. package/node_modules/pi-subagents/src/runs/background/active-run-index.ts +100 -3
  292. package/node_modules/pi-subagents/src/runs/background/async-execution.ts +630 -184
  293. package/node_modules/pi-subagents/src/runs/background/async-job-tracker.ts +143 -33
  294. package/node_modules/pi-subagents/src/runs/background/async-resume.ts +117 -44
  295. package/node_modules/pi-subagents/src/runs/background/async-retention.ts +903 -0
  296. package/node_modules/pi-subagents/src/runs/background/async-status-snapshot.ts +48 -0
  297. package/node_modules/pi-subagents/src/runs/background/async-status.ts +235 -69
  298. package/node_modules/pi-subagents/src/runs/background/auto-drain.ts +2 -1
  299. package/node_modules/pi-subagents/src/runs/background/chain-append.ts +44 -51
  300. package/node_modules/pi-subagents/src/runs/background/chain-root-attachment.ts +79 -8
  301. package/node_modules/pi-subagents/src/runs/background/completion-dedupe.ts +5 -1
  302. package/node_modules/pi-subagents/src/runs/background/completion-replay.ts +33 -13
  303. package/node_modules/pi-subagents/src/runs/background/control-channel.ts +108 -73
  304. package/node_modules/pi-subagents/src/runs/background/fleet-view.ts +125 -45
  305. package/node_modules/pi-subagents/src/runs/background/index-segment.ts +59 -0
  306. package/node_modules/pi-subagents/src/runs/background/inspect-rpc.ts +443 -0
  307. package/node_modules/pi-subagents/src/runs/background/notify.ts +272 -10
  308. package/node_modules/pi-subagents/src/runs/background/owned-process-tree.ts +104 -0
  309. package/node_modules/pi-subagents/src/runs/background/process-terminal.ts +33 -3
  310. package/node_modules/pi-subagents/src/runs/background/result-delivery-ownership.ts +45 -0
  311. package/node_modules/pi-subagents/src/runs/background/result-files.ts +519 -0
  312. package/node_modules/pi-subagents/src/runs/background/result-watcher.ts +329 -54
  313. package/node_modules/pi-subagents/src/runs/background/resume-guidance.ts +35 -12
  314. package/node_modules/pi-subagents/src/runs/background/retained-children.ts +85 -18
  315. package/node_modules/pi-subagents/src/runs/background/run-id-query.ts +7 -0
  316. package/node_modules/pi-subagents/src/runs/background/run-id-resolver.ts +37 -29
  317. package/node_modules/pi-subagents/src/runs/background/run-status.ts +204 -32
  318. package/node_modules/pi-subagents/src/runs/background/scheduled-runs.ts +228 -40
  319. package/node_modules/pi-subagents/src/runs/background/stale-run-reconciler.ts +42 -16
  320. package/node_modules/pi-subagents/src/runs/background/steering.ts +18 -15
  321. package/node_modules/pi-subagents/src/runs/background/subagent-runner.ts +1419 -546
  322. package/node_modules/pi-subagents/src/runs/background/subagent-wait.ts +105 -44
  323. package/node_modules/pi-subagents/src/runs/background/terminal-run-index.ts +138 -0
  324. package/node_modules/pi-subagents/src/runs/background/wait-completions.ts +54 -4
  325. package/node_modules/pi-subagents/src/runs/background/wait-config.ts +23 -9
  326. package/node_modules/pi-subagents/src/runs/background/wait-subscriptions.ts +81 -2
  327. package/node_modules/pi-subagents/src/runs/background/wait-tool.ts +28 -19
  328. package/node_modules/pi-subagents/src/runs/foreground/async-dismiss-action.ts +2 -1
  329. package/node_modules/pi-subagents/src/runs/foreground/async-steering-action.ts +23 -16
  330. package/node_modules/pi-subagents/src/runs/foreground/async-stop-action.ts +23 -2
  331. package/node_modules/pi-subagents/src/runs/foreground/execution.ts +730 -168
  332. package/node_modules/pi-subagents/src/runs/foreground/foreground-control.ts +21 -0
  333. package/node_modules/pi-subagents/src/runs/foreground/foreground-history.ts +26 -3
  334. package/node_modules/pi-subagents/src/runs/foreground/prompt-audit.ts +172 -0
  335. package/node_modules/pi-subagents/src/runs/foreground/subagent-executor.ts +2705 -1726
  336. package/node_modules/pi-subagents/src/runs/foreground/workflow-detach-reconcile.ts +299 -0
  337. package/node_modules/pi-subagents/src/runs/foreground/workflow-foreground-steering.ts +6 -5
  338. package/node_modules/pi-subagents/src/runs/shared/abort-recovery.ts +119 -0
  339. package/node_modules/pi-subagents/src/runs/shared/acceptance.ts +183 -39
  340. package/node_modules/pi-subagents/src/runs/shared/agent-contract.ts +1 -1
  341. package/node_modules/pi-subagents/src/runs/shared/async-status-projection.ts +597 -0
  342. package/node_modules/pi-subagents/src/runs/shared/background-process-options.ts +9 -0
  343. package/node_modules/pi-subagents/src/runs/shared/capability-ceiling.ts +1 -0
  344. package/node_modules/pi-subagents/src/runs/shared/chain-outputs.ts +1 -3
  345. package/node_modules/pi-subagents/src/runs/shared/child-identity.ts +51 -0
  346. package/node_modules/pi-subagents/src/runs/shared/child-launch-plan.ts +151 -0
  347. package/node_modules/pi-subagents/src/runs/shared/child-protocol.ts +21 -7
  348. package/node_modules/pi-subagents/src/runs/shared/claude-code-adapter.ts +129 -0
  349. package/node_modules/pi-subagents/src/runs/shared/codex-exec-adapter.ts +129 -0
  350. package/node_modules/pi-subagents/src/runs/shared/completion-evidence.ts +89 -0
  351. package/node_modules/pi-subagents/src/runs/shared/completion-guard.ts +163 -6
  352. package/node_modules/pi-subagents/src/runs/shared/cursor-agent-adapter.ts +114 -0
  353. package/node_modules/pi-subagents/src/runs/shared/dynamic-fanout.ts +4 -4
  354. package/node_modules/pi-subagents/src/runs/shared/extension-bindings.ts +78 -0
  355. package/node_modules/pi-subagents/src/runs/shared/external-cli-contract.ts +167 -0
  356. package/node_modules/pi-subagents/src/runs/shared/external-cli-preflight.ts +122 -0
  357. package/node_modules/pi-subagents/src/runs/shared/external-cli-runner.ts +353 -54
  358. package/node_modules/pi-subagents/src/runs/shared/external-job-bridge.ts +460 -0
  359. package/node_modules/pi-subagents/src/runs/shared/external-job-runner.ts +389 -0
  360. package/node_modules/pi-subagents/src/runs/shared/fast-mode-extension.ts +10 -0
  361. package/node_modules/pi-subagents/src/runs/shared/host-step-status.ts +231 -0
  362. package/node_modules/pi-subagents/src/runs/shared/lane-metadata.ts +105 -0
  363. package/node_modules/pi-subagents/src/runs/shared/launch-cwd.ts +16 -0
  364. package/node_modules/pi-subagents/src/runs/shared/llm-intent-arbiter.ts +302 -0
  365. package/node_modules/pi-subagents/src/runs/shared/long-running-guard.ts +2 -1
  366. package/node_modules/pi-subagents/src/runs/shared/mcp-config-sources.ts +422 -0
  367. package/node_modules/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +230 -153
  368. package/node_modules/pi-subagents/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
  369. package/node_modules/pi-subagents/src/runs/shared/model-exclusions.ts +305 -0
  370. package/node_modules/pi-subagents/src/runs/shared/model-fallback.ts +300 -62
  371. package/node_modules/pi-subagents/src/runs/shared/model-scope.ts +106 -39
  372. package/node_modules/pi-subagents/src/runs/shared/mutation-evidence.ts +199 -0
  373. package/node_modules/pi-subagents/src/runs/shared/nested-events.ts +75 -65
  374. package/node_modules/pi-subagents/src/runs/shared/nested-render.ts +9 -5
  375. package/node_modules/pi-subagents/src/runs/shared/orca-progress-tabs.ts +499 -0
  376. package/node_modules/pi-subagents/src/runs/shared/parallel-handoff.ts +464 -10
  377. package/node_modules/pi-subagents/src/runs/shared/parallel-utils.ts +38 -20
  378. package/node_modules/pi-subagents/src/runs/shared/permissions.ts +6 -2
  379. package/node_modules/pi-subagents/src/runs/shared/pi-args.ts +279 -21
  380. package/node_modules/pi-subagents/src/runs/shared/pi-spawn.ts +69 -35
  381. package/node_modules/pi-subagents/src/runs/shared/process-signal.ts +13 -0
  382. package/node_modules/pi-subagents/src/runs/shared/run-fanout-budget.ts +280 -0
  383. package/node_modules/pi-subagents/src/runs/shared/run-history.ts +21 -1
  384. package/node_modules/pi-subagents/src/runs/shared/session-lease.ts +0 -6
  385. package/node_modules/pi-subagents/src/runs/shared/single-output.ts +93 -24
  386. package/node_modules/pi-subagents/src/runs/shared/structured-output.ts +46 -5
  387. package/node_modules/pi-subagents/src/runs/shared/subagent-control.ts +66 -7
  388. package/node_modules/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +195 -44
  389. package/node_modules/pi-subagents/src/runs/shared/subagent-startup-retry.ts +12 -0
  390. package/node_modules/pi-subagents/src/runs/shared/task-intent.ts +36 -9
  391. package/node_modules/pi-subagents/src/runs/shared/tool-availability.ts +1 -3
  392. package/node_modules/pi-subagents/src/runs/shared/tool-timeout.ts +93 -0
  393. package/node_modules/pi-subagents/src/runs/shared/workflow-graph.ts +17 -23
  394. package/node_modules/pi-subagents/src/runs/shared/worktree-cleanup-plan.ts +847 -0
  395. package/node_modules/pi-subagents/src/runs/shared/worktree.ts +49 -7
  396. package/node_modules/pi-subagents/src/shared/agent-stream-options.ts +5 -0
  397. package/node_modules/pi-subagents/src/shared/artifacts.ts +2 -6
  398. package/node_modules/pi-subagents/src/shared/atomic-json.ts +24 -2
  399. package/node_modules/pi-subagents/src/shared/capacity-resilient-json.ts +102 -0
  400. package/node_modules/pi-subagents/src/shared/child-session-name.ts +46 -0
  401. package/node_modules/pi-subagents/src/shared/completion-owner.ts +14 -0
  402. package/node_modules/pi-subagents/src/shared/display-text.ts +50 -0
  403. package/node_modules/pi-subagents/src/shared/extension-context.ts +24 -0
  404. package/node_modules/pi-subagents/src/shared/file-system-retry.ts +49 -1
  405. package/node_modules/pi-subagents/src/shared/fork-context.ts +80 -13
  406. package/node_modules/pi-subagents/src/shared/fork-session-cwd.ts +27 -0
  407. package/node_modules/pi-subagents/src/shared/formatters.ts +18 -3
  408. package/node_modules/pi-subagents/src/shared/launch-contract.ts +20 -6
  409. package/node_modules/pi-subagents/src/shared/model-info.ts +20 -0
  410. package/node_modules/pi-subagents/src/shared/node-executable.ts +21 -0
  411. package/node_modules/pi-subagents/src/shared/prompt-resources.ts +0 -40
  412. package/node_modules/pi-subagents/src/shared/pruned-fork.ts +450 -0
  413. package/node_modules/pi-subagents/src/shared/session-file-trust.ts +19 -0
  414. package/node_modules/pi-subagents/src/shared/session-tokens.ts +14 -3
  415. package/node_modules/pi-subagents/src/shared/settings.ts +25 -130
  416. package/node_modules/pi-subagents/src/shared/shortcuts.ts +17 -0
  417. package/node_modules/pi-subagents/src/shared/thinking-ceiling.ts +52 -0
  418. package/node_modules/pi-subagents/src/shared/types.ts +788 -64
  419. package/node_modules/pi-subagents/src/shared/utils.ts +52 -85
  420. package/node_modules/pi-subagents/src/shared/watch-strategy.ts +10 -0
  421. package/node_modules/pi-subagents/src/shared/workflow-child-permit.ts +207 -0
  422. package/node_modules/pi-subagents/src/slash/delegation-adapters.ts +1 -9
  423. package/node_modules/pi-subagents/src/slash/delegation-request.ts +0 -4
  424. package/node_modules/pi-subagents/src/slash/prompt-template-bridge.ts +37 -1
  425. package/node_modules/pi-subagents/src/slash/slash-commands.ts +457 -135
  426. package/node_modules/pi-subagents/src/slash/slash-live-state.ts +28 -14
  427. package/node_modules/pi-subagents/src/slash/subagents-admin.ts +5 -0
  428. package/node_modules/pi-subagents/src/tui/fleet-status.ts +402 -71
  429. package/node_modules/pi-subagents/src/tui/fleet-transcript.ts +12 -53
  430. package/node_modules/pi-subagents/src/tui/fleet.ts +500 -53
  431. package/node_modules/pi-subagents/src/tui/render-helpers.ts +31 -0
  432. package/node_modules/pi-subagents/src/tui/render.ts +1192 -192
  433. package/node_modules/pi-subagents/src/watchdog/change-signature.ts +41 -2
  434. package/node_modules/pi-subagents/src/watchdog/lsp-diagnostics.ts +1 -0
  435. package/node_modules/pi-subagents/src/watchdog/permission-arbiter.ts +60 -51
  436. package/node_modules/pi-subagents/src/watchdog/review.ts +4 -3
  437. package/node_modules/pi-subagents/src/watchdog/turn-delta.ts +1 -1
  438. package/node_modules/pi-subagents/src/workflows/chat-progress.ts +17 -6
  439. package/node_modules/pi-subagents/src/workflows/host-command.ts +235 -0
  440. package/node_modules/pi-subagents/src/workflows/scripted-workflow.ts +1654 -174
  441. package/node_modules/pi-subagents/src/workflows/workflow-child-summary.ts +121 -0
  442. package/node_modules/pi-subagents/src/workflows/workflow-preflight.ts +270 -0
  443. package/node_modules/pi-subagents/src/workflows/workflow-receipt.ts +366 -0
  444. package/node_modules/pi-subagents/src/workflows/workflow-resources.ts +150 -0
  445. package/node_modules/pi-subagents/src/workflows/workflow-settlement.ts +246 -0
  446. package/node_modules/zod/README.md +29 -2
  447. package/node_modules/zod/compile.cjs +96 -0
  448. package/node_modules/zod/compile.d.cts +1 -0
  449. package/node_modules/zod/compile.d.ts +1 -0
  450. package/node_modules/zod/compile.js +52 -0
  451. package/node_modules/zod/index.cjs +21 -2
  452. package/node_modules/zod/index.d.cts +1 -2
  453. package/node_modules/zod/index.d.ts +1 -2
  454. package/node_modules/zod/index.js +5 -2
  455. package/node_modules/zod/locales/index.cjs +19 -0
  456. package/node_modules/zod/mini/index.cjs +19 -0
  457. package/node_modules/zod/package.json +20 -8
  458. package/node_modules/zod/src/compile.ts +56 -0
  459. package/node_modules/zod/src/index.ts +5 -2
  460. package/node_modules/zod/src/v3/ZodError.ts +22 -12
  461. package/node_modules/zod/src/v3/helpers/errorUtil.ts +1 -1
  462. package/node_modules/zod/src/v3/tests/error.test.ts +35 -0
  463. package/node_modules/zod/src/v3/tests/intersection.test.ts +18 -0
  464. package/node_modules/zod/src/v3/tests/language-server.test.ts +1 -2
  465. package/node_modules/zod/src/v3/tests/object.test.ts +3 -6
  466. package/node_modules/zod/src/v3/tests/readonly.test.ts +0 -80
  467. package/node_modules/zod/src/v3/tests/string.test.ts +6 -0
  468. package/node_modules/zod/src/v3/types.ts +5 -5
  469. package/node_modules/zod/src/v4/classic/checks.ts +1 -0
  470. package/node_modules/zod/src/v4/classic/compat.ts +26 -18
  471. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  472. package/node_modules/zod/src/v4/classic/errors.ts +59 -44
  473. package/node_modules/zod/src/v4/classic/external.ts +14 -9
  474. package/node_modules/zod/src/v4/classic/from-json-schema.ts +363 -78
  475. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  476. package/node_modules/zod/src/v4/classic/index.ts +2 -2
  477. package/node_modules/zod/src/v4/classic/iso.ts +2 -72
  478. package/node_modules/zod/src/v4/classic/parse.ts +10 -4
  479. package/node_modules/zod/src/v4/classic/schemas.ts +640 -375
  480. package/node_modules/zod/src/v4/classic/tests/apply.test.ts +27 -0
  481. package/node_modules/zod/src/v4/classic/tests/array.test.ts +2 -2
  482. package/node_modules/zod/src/v4/classic/tests/assignability.test.ts +186 -0
  483. package/node_modules/zod/src/v4/classic/tests/bigint.test.ts +36 -1
  484. package/node_modules/zod/src/v4/classic/tests/catch.test.ts +278 -0
  485. package/node_modules/zod/src/v4/classic/tests/codec-examples.test.ts +1 -2
  486. package/node_modules/zod/src/v4/classic/tests/codec.test.ts +2 -1
  487. package/node_modules/zod/src/v4/classic/tests/continuability.test.ts +3 -3
  488. package/node_modules/zod/src/v4/classic/tests/credit-card.test.ts +76 -0
  489. package/node_modules/zod/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  490. package/node_modules/zod/src/v4/classic/tests/date.test.ts +30 -0
  491. package/node_modules/zod/src/v4/classic/tests/datetime.test.ts +32 -18
  492. package/node_modules/zod/src/v4/classic/tests/deep-partial.test.ts +380 -0
  493. package/node_modules/zod/src/v4/classic/tests/default-locale.test.ts +32 -0
  494. package/node_modules/zod/src/v4/classic/tests/default.test.ts +46 -0
  495. package/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +31 -7
  496. package/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +261 -13
  497. package/node_modules/zod/src/v4/classic/tests/enum.test.ts +20 -0
  498. package/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +112 -2
  499. package/node_modules/zod/src/v4/classic/tests/error.test.ts +403 -6
  500. package/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +582 -10
  501. package/node_modules/zod/src/v4/classic/tests/function.test.ts +31 -0
  502. package/node_modules/zod/src/v4/classic/tests/global-config.test.ts +2 -9
  503. package/node_modules/zod/src/v4/classic/tests/hash.test.ts +1 -2
  504. package/node_modules/zod/src/v4/classic/tests/iban.test.ts +81 -0
  505. package/node_modules/zod/src/v4/classic/tests/in-out.test.ts +159 -0
  506. package/node_modules/zod/src/v4/classic/tests/index.test.ts +21 -2
  507. package/node_modules/zod/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  508. package/node_modules/zod/src/v4/classic/tests/instanceof.test.ts +67 -0
  509. package/node_modules/zod/src/v4/classic/tests/intersection.test.ts +136 -0
  510. package/node_modules/zod/src/v4/classic/tests/issue-schema.test.ts +215 -0
  511. package/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +3 -10
  512. package/node_modules/zod/src/v4/classic/tests/lazy.test.ts +36 -1
  513. package/node_modules/zod/src/v4/classic/tests/literal.test.ts +12 -1
  514. package/node_modules/zod/src/v4/classic/tests/map.test.ts +12 -0
  515. package/node_modules/zod/src/v4/classic/tests/number.test.ts +85 -9
  516. package/node_modules/zod/src/v4/classic/tests/object.test.ts +301 -12
  517. package/node_modules/zod/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  518. package/node_modules/zod/src/v4/classic/tests/optional.test.ts +49 -16
  519. package/node_modules/zod/src/v4/classic/tests/partial.test.ts +51 -4
  520. package/node_modules/zod/src/v4/classic/tests/prefault.test.ts +70 -0
  521. package/node_modules/zod/src/v4/classic/tests/preprocess-types.test.ts +20 -2
  522. package/node_modules/zod/src/v4/classic/tests/properties.test.ts +141 -0
  523. package/node_modules/zod/src/v4/classic/tests/readonly.test.ts +0 -68
  524. package/node_modules/zod/src/v4/classic/tests/record.test.ts +186 -18
  525. package/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +79 -3
  526. package/node_modules/zod/src/v4/classic/tests/redos.test.ts +68 -0
  527. package/node_modules/zod/src/v4/classic/tests/refine.test.ts +60 -0
  528. package/node_modules/zod/src/v4/classic/tests/set.test.ts +9 -0
  529. package/node_modules/zod/src/v4/classic/tests/standard-schema.test.ts +19 -0
  530. package/node_modules/zod/src/v4/classic/tests/string.test.ts +222 -6
  531. package/node_modules/zod/src/v4/classic/tests/stringbool.test.ts +18 -0
  532. package/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +44 -3
  533. package/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +1812 -204
  534. package/node_modules/zod/src/v4/classic/tests/tuple.test.ts +45 -30
  535. package/node_modules/zod/src/v4/classic/tests/union.test.ts +39 -2
  536. package/node_modules/zod/src/v4/classic/tests/validate.test.ts +645 -0
  537. package/node_modules/zod/src/v4/classic/tests/validations.test.ts +2 -2
  538. package/node_modules/zod/src/v4/core/api.ts +87 -35
  539. package/node_modules/zod/src/v4/core/checks.ts +119 -146
  540. package/node_modules/zod/src/v4/core/compile.ts +2313 -0
  541. package/node_modules/zod/src/v4/core/core.ts +99 -22
  542. package/node_modules/zod/src/v4/core/doc.ts +17 -9
  543. package/node_modules/zod/src/v4/core/errors.ts +113 -25
  544. package/node_modules/zod/src/v4/core/index.ts +3 -0
  545. package/node_modules/zod/src/v4/core/json-schema-generator.ts +8 -3
  546. package/node_modules/zod/src/v4/core/json-schema-processors.ts +424 -156
  547. package/node_modules/zod/src/v4/core/json-schema.ts +2 -1
  548. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  549. package/node_modules/zod/src/v4/core/parse.ts +164 -50
  550. package/node_modules/zod/src/v4/core/regexes.ts +42 -15
  551. package/node_modules/zod/src/v4/core/registries.ts +2 -2
  552. package/node_modules/zod/src/v4/core/schemas.ts +1000 -538
  553. package/node_modules/zod/src/v4/core/tests/cached.test.ts +54 -0
  554. package/node_modules/zod/src/v4/core/tests/compile-differential.test.ts +1004 -0
  555. package/node_modules/zod/src/v4/core/tests/compile-generative.test.ts +445 -0
  556. package/node_modules/zod/src/v4/core/tests/compile-global.test.ts +89 -0
  557. package/node_modules/zod/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  558. package/node_modules/zod/src/v4/core/tests/compile-stats.test.ts +34 -0
  559. package/node_modules/zod/src/v4/core/tests/compile.test.ts +2036 -0
  560. package/node_modules/zod/src/v4/core/tests/email-regex.test.ts +140 -0
  561. package/node_modules/zod/src/v4/core/tests/locales/el.test.ts +1 -2
  562. package/node_modules/zod/src/v4/core/tests/locales/es.test.ts +1 -2
  563. package/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +3 -3
  564. package/node_modules/zod/src/v4/core/tests/locales/parity.test.ts +42 -0
  565. package/node_modules/zod/src/v4/core/tests/locales/tg.test.ts +85 -0
  566. package/node_modules/zod/src/v4/core/tests/locales/tk.test.ts +69 -0
  567. package/node_modules/zod/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  568. package/node_modules/zod/src/v4/core/tests/treeshake.test.ts +51 -0
  569. package/node_modules/zod/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  570. package/node_modules/zod/src/v4/core/to-json-schema.ts +283 -48
  571. package/node_modules/zod/src/v4/core/util.ts +454 -157
  572. package/node_modules/zod/src/v4/core/versions.ts +2 -2
  573. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  574. package/node_modules/zod/src/v4/index.ts +3 -3
  575. package/node_modules/zod/src/v4/locales/ar.ts +5 -0
  576. package/node_modules/zod/src/v4/locales/az.ts +5 -0
  577. package/node_modules/zod/src/v4/locales/be.ts +12 -0
  578. package/node_modules/zod/src/v4/locales/bg.ts +5 -0
  579. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  580. package/node_modules/zod/src/v4/locales/ca.ts +5 -0
  581. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  582. package/node_modules/zod/src/v4/locales/cs.ts +5 -0
  583. package/node_modules/zod/src/v4/locales/da.ts +7 -2
  584. package/node_modules/zod/src/v4/locales/de.ts +5 -0
  585. package/node_modules/zod/src/v4/locales/el.ts +3 -0
  586. package/node_modules/zod/src/v4/locales/en.ts +17 -4
  587. package/node_modules/zod/src/v4/locales/eo.ts +5 -0
  588. package/node_modules/zod/src/v4/locales/es.ts +4 -0
  589. package/node_modules/zod/src/v4/locales/fa.ts +5 -0
  590. package/node_modules/zod/src/v4/locales/fi.ts +5 -0
  591. package/node_modules/zod/src/v4/locales/fr-CA.ts +5 -0
  592. package/node_modules/zod/src/v4/locales/fr.ts +21 -14
  593. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  594. package/node_modules/zod/src/v4/locales/he.ts +8 -1
  595. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  596. package/node_modules/zod/src/v4/locales/hr.ts +4 -0
  597. package/node_modules/zod/src/v4/locales/hu.ts +5 -0
  598. package/node_modules/zod/src/v4/locales/hy.ts +11 -0
  599. package/node_modules/zod/src/v4/locales/id.ts +5 -0
  600. package/node_modules/zod/src/v4/locales/index.ts +11 -0
  601. package/node_modules/zod/src/v4/locales/is.ts +5 -0
  602. package/node_modules/zod/src/v4/locales/it.ts +5 -0
  603. package/node_modules/zod/src/v4/locales/ja.ts +5 -0
  604. package/node_modules/zod/src/v4/locales/ka.ts +5 -0
  605. package/node_modules/zod/src/v4/locales/km.ts +5 -0
  606. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  607. package/node_modules/zod/src/v4/locales/ko.ts +5 -0
  608. package/node_modules/zod/src/v4/locales/lt.ts +4 -0
  609. package/node_modules/zod/src/v4/locales/mk.ts +5 -0
  610. package/node_modules/zod/src/v4/locales/ms.ts +5 -0
  611. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  612. package/node_modules/zod/src/v4/locales/nl.ts +5 -0
  613. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  614. package/node_modules/zod/src/v4/locales/no.ts +7 -2
  615. package/node_modules/zod/src/v4/locales/ota.ts +5 -0
  616. package/node_modules/zod/src/v4/locales/pl.ts +5 -0
  617. package/node_modules/zod/src/v4/locales/ps.ts +5 -0
  618. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  619. package/node_modules/zod/src/v4/locales/pt.ts +101 -58
  620. package/node_modules/zod/src/v4/locales/ro.ts +3 -0
  621. package/node_modules/zod/src/v4/locales/ru.ts +12 -0
  622. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  623. package/node_modules/zod/src/v4/locales/sl.ts +5 -0
  624. package/node_modules/zod/src/v4/locales/sv.ts +7 -2
  625. package/node_modules/zod/src/v4/locales/ta.ts +5 -0
  626. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  627. package/node_modules/zod/src/v4/locales/th.ts +5 -0
  628. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  629. package/node_modules/zod/src/v4/locales/tr.ts +5 -0
  630. package/node_modules/zod/src/v4/locales/uk.ts +5 -0
  631. package/node_modules/zod/src/v4/locales/ur.ts +5 -0
  632. package/node_modules/zod/src/v4/locales/uz.ts +3 -0
  633. package/node_modules/zod/src/v4/locales/vi.ts +5 -0
  634. package/node_modules/zod/src/v4/locales/yo.ts +5 -0
  635. package/node_modules/zod/src/v4/locales/zh-CN.ts +5 -0
  636. package/node_modules/zod/src/v4/locales/zh-TW.ts +5 -0
  637. package/node_modules/zod/src/v4/mini/checks.ts +1 -0
  638. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  639. package/node_modules/zod/src/v4/mini/external.ts +12 -1
  640. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  641. package/node_modules/zod/src/v4/mini/parse.ts +2 -0
  642. package/node_modules/zod/src/v4/mini/schemas.ts +167 -63
  643. package/node_modules/zod/src/v4/mini/tests/apply.test.ts +33 -0
  644. package/node_modules/zod/src/v4/mini/tests/assignability.test.ts +62 -1
  645. package/node_modules/zod/src/v4/mini/tests/checks.test.ts +14 -0
  646. package/node_modules/zod/src/v4/mini/tests/codec.test.ts +35 -1
  647. package/node_modules/zod/src/v4/mini/tests/computed.test.ts +11 -17
  648. package/node_modules/zod/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  649. package/node_modules/zod/src/v4/mini/tests/deep-partial.test.ts +54 -0
  650. package/node_modules/zod/src/v4/mini/tests/error.test.ts +23 -4
  651. package/node_modules/zod/src/v4/mini/tests/functions.test.ts +9 -0
  652. package/node_modules/zod/src/v4/mini/tests/index.test.ts +158 -5
  653. package/node_modules/zod/src/v4/mini/tests/number.test.ts +14 -0
  654. package/node_modules/zod/src/v4/mini/tests/object.test.ts +65 -0
  655. package/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +16 -0
  656. package/node_modules/zod/src/v4/mini/tests/string.test.ts +44 -0
  657. package/node_modules/zod/v3/ZodError.cjs +41 -12
  658. package/node_modules/zod/v3/ZodError.d.cts +1 -1
  659. package/node_modules/zod/v3/ZodError.d.ts +1 -1
  660. package/node_modules/zod/v3/ZodError.js +22 -12
  661. package/node_modules/zod/v3/errors.cjs +19 -0
  662. package/node_modules/zod/v3/external.cjs +19 -0
  663. package/node_modules/zod/v3/helpers/enumUtil.cjs +19 -0
  664. package/node_modules/zod/v3/helpers/errorUtil.cjs +20 -1
  665. package/node_modules/zod/v3/helpers/errorUtil.js +1 -1
  666. package/node_modules/zod/v3/helpers/parseUtil.cjs +19 -0
  667. package/node_modules/zod/v3/helpers/partialUtil.cjs +19 -0
  668. package/node_modules/zod/v3/helpers/typeAliases.cjs +19 -0
  669. package/node_modules/zod/v3/helpers/util.cjs +19 -0
  670. package/node_modules/zod/v3/index.cjs +19 -0
  671. package/node_modules/zod/v3/standard-schema.cjs +19 -0
  672. package/node_modules/zod/v3/types.cjs +26 -5
  673. package/node_modules/zod/v3/types.js +7 -5
  674. package/node_modules/zod/v4/classic/checks.cjs +21 -1
  675. package/node_modules/zod/v4/classic/checks.d.cts +1 -1
  676. package/node_modules/zod/v4/classic/checks.d.ts +1 -1
  677. package/node_modules/zod/v4/classic/checks.js +1 -1
  678. package/node_modules/zod/v4/classic/coerce.cjs +19 -0
  679. package/node_modules/zod/v4/classic/compat.cjs +19 -0
  680. package/node_modules/zod/v4/classic/compat.d.cts +9 -11
  681. package/node_modules/zod/v4/classic/compat.d.ts +9 -11
  682. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  683. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  684. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  685. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  686. package/node_modules/zod/v4/classic/errors.cjs +62 -34
  687. package/node_modules/zod/v4/classic/errors.d.cts +3 -4
  688. package/node_modules/zod/v4/classic/errors.d.ts +3 -4
  689. package/node_modules/zod/v4/classic/errors.js +43 -34
  690. package/node_modules/zod/v4/classic/external.cjs +51 -27
  691. package/node_modules/zod/v4/classic/external.d.cts +5 -2
  692. package/node_modules/zod/v4/classic/external.d.ts +5 -2
  693. package/node_modules/zod/v4/classic/external.js +5 -8
  694. package/node_modules/zod/v4/classic/from-json-schema.cjs +376 -75
  695. package/node_modules/zod/v4/classic/from-json-schema.js +357 -75
  696. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  697. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  698. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  699. package/node_modules/zod/v4/classic/in-out.js +36 -0
  700. package/node_modules/zod/v4/classic/index.cjs +21 -2
  701. package/node_modules/zod/v4/classic/index.d.cts +1 -2
  702. package/node_modules/zod/v4/classic/index.d.ts +1 -2
  703. package/node_modules/zod/v4/classic/index.js +2 -2
  704. package/node_modules/zod/v4/classic/iso.cjs +30 -22
  705. package/node_modules/zod/v4/classic/iso.d.cts +2 -17
  706. package/node_modules/zod/v4/classic/iso.d.ts +2 -17
  707. package/node_modules/zod/v4/classic/iso.js +2 -17
  708. package/node_modules/zod/v4/classic/parse.cjs +23 -1
  709. package/node_modules/zod/v4/classic/parse.d.cts +17 -4
  710. package/node_modules/zod/v4/classic/parse.d.ts +17 -4
  711. package/node_modules/zod/v4/classic/parse.js +1 -0
  712. package/node_modules/zod/v4/classic/schemas.cjs +591 -426
  713. package/node_modules/zod/v4/classic/schemas.d.cts +68 -19
  714. package/node_modules/zod/v4/classic/schemas.d.ts +68 -19
  715. package/node_modules/zod/v4/classic/schemas.js +564 -424
  716. package/node_modules/zod/v4/core/api.cjs +66 -24
  717. package/node_modules/zod/v4/core/api.d.cts +22 -12
  718. package/node_modules/zod/v4/core/api.d.ts +22 -12
  719. package/node_modules/zod/v4/core/api.js +44 -24
  720. package/node_modules/zod/v4/core/checks.cjs +88 -128
  721. package/node_modules/zod/v4/core/checks.d.cts +29 -13
  722. package/node_modules/zod/v4/core/checks.d.ts +29 -13
  723. package/node_modules/zod/v4/core/checks.js +68 -127
  724. package/node_modules/zod/v4/core/compile.cjs +1908 -0
  725. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  726. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  727. package/node_modules/zod/v4/core/compile.js +1858 -0
  728. package/node_modules/zod/v4/core/core.cjs +101 -19
  729. package/node_modules/zod/v4/core/core.d.cts +16 -4
  730. package/node_modules/zod/v4/core/core.d.ts +16 -4
  731. package/node_modules/zod/v4/core/core.js +83 -20
  732. package/node_modules/zod/v4/core/doc.cjs +31 -9
  733. package/node_modules/zod/v4/core/doc.d.cts +3 -1
  734. package/node_modules/zod/v4/core/doc.d.ts +3 -1
  735. package/node_modules/zod/v4/core/doc.js +12 -9
  736. package/node_modules/zod/v4/core/errors.cjs +126 -25
  737. package/node_modules/zod/v4/core/errors.d.cts +4 -0
  738. package/node_modules/zod/v4/core/errors.d.ts +4 -0
  739. package/node_modules/zod/v4/core/errors.js +107 -25
  740. package/node_modules/zod/v4/core/index.cjs +24 -1
  741. package/node_modules/zod/v4/core/index.d.cts +3 -0
  742. package/node_modules/zod/v4/core/index.d.ts +3 -0
  743. package/node_modules/zod/v4/core/index.js +3 -0
  744. package/node_modules/zod/v4/core/json-schema-generator.cjs +24 -1
  745. package/node_modules/zod/v4/core/json-schema-generator.d.cts +2 -2
  746. package/node_modules/zod/v4/core/json-schema-generator.d.ts +2 -2
  747. package/node_modules/zod/v4/core/json-schema-generator.js +6 -2
  748. package/node_modules/zod/v4/core/json-schema-processors.cjs +441 -156
  749. package/node_modules/zod/v4/core/json-schema-processors.d.cts +16 -0
  750. package/node_modules/zod/v4/core/json-schema-processors.d.ts +16 -0
  751. package/node_modules/zod/v4/core/json-schema-processors.js +400 -158
  752. package/node_modules/zod/v4/core/json-schema.cjs +19 -0
  753. package/node_modules/zod/v4/core/json-schema.d.cts +2 -1
  754. package/node_modules/zod/v4/core/json-schema.d.ts +2 -1
  755. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  756. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  757. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  758. package/node_modules/zod/v4/core/memoizer.js +311 -0
  759. package/node_modules/zod/v4/core/parse.cjs +148 -46
  760. package/node_modules/zod/v4/core/parse.d.cts +14 -11
  761. package/node_modules/zod/v4/core/parse.d.ts +14 -11
  762. package/node_modules/zod/v4/core/parse.js +127 -45
  763. package/node_modules/zod/v4/core/regexes.cjs +54 -17
  764. package/node_modules/zod/v4/core/regexes.d.cts +5 -0
  765. package/node_modules/zod/v4/core/regexes.d.ts +5 -0
  766. package/node_modules/zod/v4/core/regexes.js +32 -15
  767. package/node_modules/zod/v4/core/registries.cjs +19 -0
  768. package/node_modules/zod/v4/core/registries.js +2 -2
  769. package/node_modules/zod/v4/core/schemas.cjs +785 -386
  770. package/node_modules/zod/v4/core/schemas.d.cts +123 -34
  771. package/node_modules/zod/v4/core/schemas.d.ts +123 -34
  772. package/node_modules/zod/v4/core/schemas.js +753 -386
  773. package/node_modules/zod/v4/core/standard-schema.cjs +19 -0
  774. package/node_modules/zod/v4/core/to-json-schema.cjs +269 -45
  775. package/node_modules/zod/v4/core/to-json-schema.d.cts +45 -5
  776. package/node_modules/zod/v4/core/to-json-schema.d.ts +45 -5
  777. package/node_modules/zod/v4/core/to-json-schema.js +247 -44
  778. package/node_modules/zod/v4/core/util.cjs +372 -157
  779. package/node_modules/zod/v4/core/util.d.cts +79 -1
  780. package/node_modules/zod/v4/core/util.d.ts +79 -1
  781. package/node_modules/zod/v4/core/util.js +341 -156
  782. package/node_modules/zod/v4/core/versions.cjs +21 -2
  783. package/node_modules/zod/v4/core/versions.d.cts +1 -1
  784. package/node_modules/zod/v4/core/versions.d.ts +1 -1
  785. package/node_modules/zod/v4/core/versions.js +2 -2
  786. package/node_modules/zod/v4/core/visit.cjs +214 -0
  787. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  788. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  789. package/node_modules/zod/v4/core/visit.js +169 -0
  790. package/node_modules/zod/v4/index.cjs +34 -5
  791. package/node_modules/zod/v4/index.d.cts +2 -2
  792. package/node_modules/zod/v4/index.d.ts +2 -2
  793. package/node_modules/zod/v4/index.js +3 -2
  794. package/node_modules/zod/v4/locales/ar.cjs +5 -0
  795. package/node_modules/zod/v4/locales/ar.js +5 -0
  796. package/node_modules/zod/v4/locales/az.cjs +5 -0
  797. package/node_modules/zod/v4/locales/az.js +5 -0
  798. package/node_modules/zod/v4/locales/be.cjs +12 -0
  799. package/node_modules/zod/v4/locales/be.js +12 -0
  800. package/node_modules/zod/v4/locales/bg.cjs +5 -0
  801. package/node_modules/zod/v4/locales/bg.js +5 -0
  802. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  803. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  804. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  805. package/node_modules/zod/v4/locales/bn.js +113 -0
  806. package/node_modules/zod/v4/locales/ca.cjs +5 -0
  807. package/node_modules/zod/v4/locales/ca.js +5 -0
  808. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  809. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  810. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  811. package/node_modules/zod/v4/locales/ckb.js +133 -0
  812. package/node_modules/zod/v4/locales/cs.cjs +5 -0
  813. package/node_modules/zod/v4/locales/cs.js +5 -0
  814. package/node_modules/zod/v4/locales/da.cjs +7 -2
  815. package/node_modules/zod/v4/locales/da.js +7 -2
  816. package/node_modules/zod/v4/locales/de.cjs +5 -0
  817. package/node_modules/zod/v4/locales/de.js +5 -0
  818. package/node_modules/zod/v4/locales/el.cjs +3 -0
  819. package/node_modules/zod/v4/locales/el.js +3 -0
  820. package/node_modules/zod/v4/locales/en.cjs +16 -4
  821. package/node_modules/zod/v4/locales/en.js +16 -4
  822. package/node_modules/zod/v4/locales/eo.cjs +5 -0
  823. package/node_modules/zod/v4/locales/eo.js +5 -0
  824. package/node_modules/zod/v4/locales/es.cjs +4 -0
  825. package/node_modules/zod/v4/locales/es.js +4 -0
  826. package/node_modules/zod/v4/locales/fa.cjs +5 -0
  827. package/node_modules/zod/v4/locales/fa.js +5 -0
  828. package/node_modules/zod/v4/locales/fi.cjs +5 -0
  829. package/node_modules/zod/v4/locales/fi.js +5 -0
  830. package/node_modules/zod/v4/locales/fr-CA.cjs +5 -0
  831. package/node_modules/zod/v4/locales/fr-CA.js +5 -0
  832. package/node_modules/zod/v4/locales/fr.cjs +18 -14
  833. package/node_modules/zod/v4/locales/fr.js +18 -14
  834. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  835. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  836. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  837. package/node_modules/zod/v4/locales/gu.js +113 -0
  838. package/node_modules/zod/v4/locales/he.cjs +7 -0
  839. package/node_modules/zod/v4/locales/he.js +7 -0
  840. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  841. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  842. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  843. package/node_modules/zod/v4/locales/hi.js +111 -0
  844. package/node_modules/zod/v4/locales/hr.cjs +4 -0
  845. package/node_modules/zod/v4/locales/hr.js +4 -0
  846. package/node_modules/zod/v4/locales/hu.cjs +5 -0
  847. package/node_modules/zod/v4/locales/hu.js +5 -0
  848. package/node_modules/zod/v4/locales/hy.cjs +11 -0
  849. package/node_modules/zod/v4/locales/hy.js +11 -0
  850. package/node_modules/zod/v4/locales/id.cjs +5 -0
  851. package/node_modules/zod/v4/locales/id.js +5 -0
  852. package/node_modules/zod/v4/locales/index.cjs +43 -2
  853. package/node_modules/zod/v4/locales/index.d.cts +11 -0
  854. package/node_modules/zod/v4/locales/index.d.ts +11 -0
  855. package/node_modules/zod/v4/locales/index.js +11 -0
  856. package/node_modules/zod/v4/locales/is.cjs +5 -0
  857. package/node_modules/zod/v4/locales/is.js +5 -0
  858. package/node_modules/zod/v4/locales/it.cjs +5 -0
  859. package/node_modules/zod/v4/locales/it.js +5 -0
  860. package/node_modules/zod/v4/locales/ja.cjs +5 -0
  861. package/node_modules/zod/v4/locales/ja.js +5 -0
  862. package/node_modules/zod/v4/locales/ka.cjs +5 -0
  863. package/node_modules/zod/v4/locales/ka.js +5 -0
  864. package/node_modules/zod/v4/locales/km.cjs +5 -0
  865. package/node_modules/zod/v4/locales/km.js +5 -0
  866. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  867. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  868. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  869. package/node_modules/zod/v4/locales/kn.js +116 -0
  870. package/node_modules/zod/v4/locales/ko.cjs +5 -0
  871. package/node_modules/zod/v4/locales/ko.js +5 -0
  872. package/node_modules/zod/v4/locales/lt.cjs +4 -0
  873. package/node_modules/zod/v4/locales/lt.js +4 -0
  874. package/node_modules/zod/v4/locales/mk.cjs +5 -0
  875. package/node_modules/zod/v4/locales/mk.js +5 -0
  876. package/node_modules/zod/v4/locales/ms.cjs +5 -0
  877. package/node_modules/zod/v4/locales/ms.js +5 -0
  878. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  879. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  880. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  881. package/node_modules/zod/v4/locales/ne.js +111 -0
  882. package/node_modules/zod/v4/locales/nl.cjs +5 -0
  883. package/node_modules/zod/v4/locales/nl.js +5 -0
  884. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  885. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  886. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  887. package/node_modules/zod/v4/locales/nn.js +113 -0
  888. package/node_modules/zod/v4/locales/no.cjs +7 -2
  889. package/node_modules/zod/v4/locales/no.js +7 -2
  890. package/node_modules/zod/v4/locales/ota.cjs +5 -0
  891. package/node_modules/zod/v4/locales/ota.js +5 -0
  892. package/node_modules/zod/v4/locales/pl.cjs +5 -0
  893. package/node_modules/zod/v4/locales/pl.js +5 -0
  894. package/node_modules/zod/v4/locales/ps.cjs +5 -0
  895. package/node_modules/zod/v4/locales/ps.js +5 -0
  896. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  897. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  898. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  899. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  900. package/node_modules/zod/v4/locales/pt.cjs +89 -55
  901. package/node_modules/zod/v4/locales/pt.js +89 -55
  902. package/node_modules/zod/v4/locales/ro.cjs +3 -0
  903. package/node_modules/zod/v4/locales/ro.js +3 -0
  904. package/node_modules/zod/v4/locales/ru.cjs +12 -0
  905. package/node_modules/zod/v4/locales/ru.js +12 -0
  906. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  907. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  908. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  909. package/node_modules/zod/v4/locales/sk.js +116 -0
  910. package/node_modules/zod/v4/locales/sl.cjs +5 -0
  911. package/node_modules/zod/v4/locales/sl.js +5 -0
  912. package/node_modules/zod/v4/locales/sv.cjs +7 -2
  913. package/node_modules/zod/v4/locales/sv.js +7 -2
  914. package/node_modules/zod/v4/locales/ta.cjs +5 -0
  915. package/node_modules/zod/v4/locales/ta.js +5 -0
  916. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  917. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  918. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  919. package/node_modules/zod/v4/locales/tg.js +117 -0
  920. package/node_modules/zod/v4/locales/th.cjs +5 -0
  921. package/node_modules/zod/v4/locales/th.js +5 -0
  922. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  923. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  924. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  925. package/node_modules/zod/v4/locales/tk.js +107 -0
  926. package/node_modules/zod/v4/locales/tr.cjs +5 -0
  927. package/node_modules/zod/v4/locales/tr.js +5 -0
  928. package/node_modules/zod/v4/locales/uk.cjs +5 -0
  929. package/node_modules/zod/v4/locales/uk.js +5 -0
  930. package/node_modules/zod/v4/locales/ur.cjs +5 -0
  931. package/node_modules/zod/v4/locales/ur.js +5 -0
  932. package/node_modules/zod/v4/locales/uz.cjs +3 -0
  933. package/node_modules/zod/v4/locales/uz.js +3 -0
  934. package/node_modules/zod/v4/locales/vi.cjs +5 -0
  935. package/node_modules/zod/v4/locales/vi.js +5 -0
  936. package/node_modules/zod/v4/locales/yo.cjs +5 -0
  937. package/node_modules/zod/v4/locales/yo.js +5 -0
  938. package/node_modules/zod/v4/locales/zh-CN.cjs +5 -0
  939. package/node_modules/zod/v4/locales/zh-CN.js +5 -0
  940. package/node_modules/zod/v4/locales/zh-TW.cjs +5 -0
  941. package/node_modules/zod/v4/locales/zh-TW.js +5 -0
  942. package/node_modules/zod/v4/mini/checks.cjs +21 -1
  943. package/node_modules/zod/v4/mini/checks.d.cts +1 -1
  944. package/node_modules/zod/v4/mini/checks.d.ts +1 -1
  945. package/node_modules/zod/v4/mini/checks.js +1 -1
  946. package/node_modules/zod/v4/mini/coerce.cjs +19 -0
  947. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  948. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  949. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  950. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  951. package/node_modules/zod/v4/mini/external.cjs +33 -1
  952. package/node_modules/zod/v4/mini/external.d.cts +5 -2
  953. package/node_modules/zod/v4/mini/external.d.ts +5 -2
  954. package/node_modules/zod/v4/mini/external.js +3 -1
  955. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  956. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  957. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  958. package/node_modules/zod/v4/mini/in-out.js +36 -0
  959. package/node_modules/zod/v4/mini/index.cjs +19 -0
  960. package/node_modules/zod/v4/mini/iso.cjs +19 -0
  961. package/node_modules/zod/v4/mini/parse.cjs +22 -1
  962. package/node_modules/zod/v4/mini/parse.d.cts +1 -1
  963. package/node_modules/zod/v4/mini/parse.d.ts +1 -1
  964. package/node_modules/zod/v4/mini/parse.js +1 -1
  965. package/node_modules/zod/v4/mini/schemas.cjs +117 -53
  966. package/node_modules/zod/v4/mini/schemas.d.cts +49 -14
  967. package/node_modules/zod/v4/mini/schemas.d.ts +49 -14
  968. package/node_modules/zod/v4/mini/schemas.js +92 -51
  969. package/node_modules/zod/v4-mini/index.cjs +19 -0
  970. package/package.json +172 -11
  971. package/dist/acp/index.js +0 -62
  972. package/dist/extensions/tool-gradle.js +0 -1
  973. package/dist/extensions/usage.js +0 -1
  974. package/node_modules/jose/dist/webapi/lib/base64.js +0 -22
  975. package/node_modules/jose/dist/webapi/lib/crypto_key.js +0 -28
  976. package/node_modules/jose/dist/webapi/lib/helpers.js +0 -42
  977. package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +0 -26
  978. package/node_modules/jose/dist/webapi/lib/is_key_like.js +0 -17
  979. package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +0 -17
  980. package/node_modules/jose/dist/webapi/lib/options.js +0 -48
  981. package/node_modules/jose/dist/webapi/lib/signing.js +0 -26
  982. package/node_modules/jose/dist/webapi/lib/type_checks.js +0 -35
  983. package/node_modules/pi-subagents/src/runs/foreground/chain-clarify.ts +0 -1354
  984. package/node_modules/pi-subagents/src/runs/foreground/chain-execution.ts +0 -1530
  985. package/node_modules/pi-subagents/src/runs/shared/turn-budget.ts +0 -98
  986. package/node_modules/zod/src/v4/core/config.ts +0 -15
  987. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/LICENSE +0 -0
  988. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/README.md +0 -0
  989. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/bin.mjs +0 -0
  990. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/compose-collection.js +0 -0
  991. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/compose-doc.js +0 -0
  992. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/compose-node.js +0 -0
  993. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/compose-scalar.js +0 -0
  994. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/composer.js +0 -0
  995. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-block-map.js +0 -0
  996. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-block-scalar.js +0 -0
  997. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-block-seq.js +0 -0
  998. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-end.js +0 -0
  999. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-flow-collection.js +0 -0
  1000. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-flow-scalar.js +0 -0
  1001. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/resolve-props.js +0 -0
  1002. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/util-contains-newline.js +0 -0
  1003. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/util-empty-scalar-position.js +0 -0
  1004. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/util-flow-indent-check.js +0 -0
  1005. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/compose/util-map-includes.js +0 -0
  1006. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/doc/Document.js +0 -0
  1007. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/doc/anchors.js +0 -0
  1008. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/doc/applyReviver.js +0 -0
  1009. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/doc/createNode.js +0 -0
  1010. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/doc/directives.js +0 -0
  1011. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/errors.js +0 -0
  1012. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/index.js +0 -0
  1013. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/log.js +0 -0
  1014. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/Alias.js +0 -0
  1015. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/Collection.js +0 -0
  1016. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/Node.js +0 -0
  1017. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/Pair.js +0 -0
  1018. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/Scalar.js +0 -0
  1019. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/YAMLMap.js +0 -0
  1020. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/YAMLSeq.js +0 -0
  1021. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/addPairToJSMap.js +0 -0
  1022. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/identity.js +0 -0
  1023. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/nodes/toJS.js +0 -0
  1024. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/cst-scalar.js +0 -0
  1025. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/cst-stringify.js +0 -0
  1026. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/cst-visit.js +0 -0
  1027. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/cst.js +0 -0
  1028. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/lexer.js +0 -0
  1029. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/line-counter.js +0 -0
  1030. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/parse/parser.js +0 -0
  1031. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/public-api.js +0 -0
  1032. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/Schema.js +0 -0
  1033. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/common/map.js +0 -0
  1034. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/common/null.js +0 -0
  1035. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/common/seq.js +0 -0
  1036. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/common/string.js +0 -0
  1037. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/core/bool.js +0 -0
  1038. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/core/float.js +0 -0
  1039. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/core/int.js +0 -0
  1040. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/core/schema.js +0 -0
  1041. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/json/schema.js +0 -0
  1042. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/tags.js +0 -0
  1043. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/binary.js +0 -0
  1044. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/bool.js +0 -0
  1045. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/float.js +0 -0
  1046. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/int.js +0 -0
  1047. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/merge.js +0 -0
  1048. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/omap.js +0 -0
  1049. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/pairs.js +0 -0
  1050. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/schema.js +0 -0
  1051. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/set.js +0 -0
  1052. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/schema/yaml-1.1/timestamp.js +0 -0
  1053. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/foldFlowLines.js +0 -0
  1054. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringify.js +0 -0
  1055. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringifyCollection.js +0 -0
  1056. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringifyComment.js +0 -0
  1057. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringifyDocument.js +0 -0
  1058. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringifyNumber.js +0 -0
  1059. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringifyPair.js +0 -0
  1060. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/stringify/stringifyString.js +0 -0
  1061. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/util.js +0 -0
  1062. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/dist/visit.js +0 -0
  1063. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/index.js +0 -0
  1064. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/browser/package.json +0 -0
  1065. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/cli.d.ts +0 -0
  1066. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/cli.mjs +0 -0
  1067. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-collection.d.ts +0 -0
  1068. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-collection.js +0 -0
  1069. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-doc.d.ts +0 -0
  1070. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-doc.js +0 -0
  1071. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-node.d.ts +0 -0
  1072. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-node.js +0 -0
  1073. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-scalar.d.ts +0 -0
  1074. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/compose-scalar.js +0 -0
  1075. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/composer.d.ts +0 -0
  1076. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/composer.js +0 -0
  1077. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-block-map.d.ts +0 -0
  1078. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-block-map.js +0 -0
  1079. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-block-scalar.d.ts +0 -0
  1080. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-block-scalar.js +0 -0
  1081. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-block-seq.d.ts +0 -0
  1082. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-block-seq.js +0 -0
  1083. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-end.d.ts +0 -0
  1084. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-end.js +0 -0
  1085. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-flow-collection.d.ts +0 -0
  1086. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-flow-collection.js +0 -0
  1087. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-flow-scalar.d.ts +0 -0
  1088. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-flow-scalar.js +0 -0
  1089. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-props.d.ts +0 -0
  1090. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/resolve-props.js +0 -0
  1091. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-contains-newline.d.ts +0 -0
  1092. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-contains-newline.js +0 -0
  1093. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-empty-scalar-position.d.ts +0 -0
  1094. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-empty-scalar-position.js +0 -0
  1095. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-flow-indent-check.d.ts +0 -0
  1096. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-flow-indent-check.js +0 -0
  1097. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-map-includes.d.ts +0 -0
  1098. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/compose/util-map-includes.js +0 -0
  1099. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/Document.d.ts +0 -0
  1100. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/Document.js +0 -0
  1101. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/anchors.d.ts +0 -0
  1102. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/anchors.js +0 -0
  1103. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/applyReviver.d.ts +0 -0
  1104. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/applyReviver.js +0 -0
  1105. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/createNode.d.ts +0 -0
  1106. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/createNode.js +0 -0
  1107. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/directives.d.ts +0 -0
  1108. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/doc/directives.js +0 -0
  1109. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/errors.d.ts +0 -0
  1110. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/errors.js +0 -0
  1111. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/index.d.ts +0 -0
  1112. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/index.js +0 -0
  1113. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/log.d.ts +0 -0
  1114. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/log.js +0 -0
  1115. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Alias.d.ts +0 -0
  1116. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Alias.js +0 -0
  1117. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Collection.d.ts +0 -0
  1118. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Collection.js +0 -0
  1119. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Node.d.ts +0 -0
  1120. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Node.js +0 -0
  1121. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Pair.d.ts +0 -0
  1122. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Pair.js +0 -0
  1123. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Scalar.d.ts +0 -0
  1124. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/Scalar.js +0 -0
  1125. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/YAMLMap.d.ts +0 -0
  1126. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/YAMLMap.js +0 -0
  1127. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/YAMLSeq.d.ts +0 -0
  1128. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/YAMLSeq.js +0 -0
  1129. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/addPairToJSMap.d.ts +0 -0
  1130. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/addPairToJSMap.js +0 -0
  1131. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/identity.d.ts +0 -0
  1132. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/identity.js +0 -0
  1133. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/toJS.d.ts +0 -0
  1134. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/nodes/toJS.js +0 -0
  1135. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/options.d.ts +0 -0
  1136. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst-scalar.d.ts +0 -0
  1137. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst-scalar.js +0 -0
  1138. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst-stringify.d.ts +0 -0
  1139. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst-stringify.js +0 -0
  1140. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst-visit.d.ts +0 -0
  1141. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst-visit.js +0 -0
  1142. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst.d.ts +0 -0
  1143. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/cst.js +0 -0
  1144. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/lexer.d.ts +0 -0
  1145. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/lexer.js +0 -0
  1146. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/line-counter.d.ts +0 -0
  1147. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/line-counter.js +0 -0
  1148. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/parser.d.ts +0 -0
  1149. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/parse/parser.js +0 -0
  1150. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/public-api.d.ts +0 -0
  1151. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/public-api.js +0 -0
  1152. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/Schema.d.ts +0 -0
  1153. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/Schema.js +0 -0
  1154. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/map.d.ts +0 -0
  1155. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/map.js +0 -0
  1156. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/null.d.ts +0 -0
  1157. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/null.js +0 -0
  1158. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/seq.d.ts +0 -0
  1159. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/seq.js +0 -0
  1160. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/string.d.ts +0 -0
  1161. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/common/string.js +0 -0
  1162. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/bool.d.ts +0 -0
  1163. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/bool.js +0 -0
  1164. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/float.d.ts +0 -0
  1165. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/float.js +0 -0
  1166. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/int.d.ts +0 -0
  1167. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/int.js +0 -0
  1168. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/schema.d.ts +0 -0
  1169. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/core/schema.js +0 -0
  1170. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/json/schema.d.ts +0 -0
  1171. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/json/schema.js +0 -0
  1172. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/json-schema.d.ts +0 -0
  1173. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/tags.d.ts +0 -0
  1174. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/tags.js +0 -0
  1175. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/types.d.ts +0 -0
  1176. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/binary.d.ts +0 -0
  1177. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/binary.js +0 -0
  1178. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/bool.d.ts +0 -0
  1179. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/bool.js +0 -0
  1180. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/float.d.ts +0 -0
  1181. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/float.js +0 -0
  1182. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/int.d.ts +0 -0
  1183. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/int.js +0 -0
  1184. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/merge.d.ts +0 -0
  1185. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/merge.js +0 -0
  1186. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/omap.d.ts +0 -0
  1187. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/omap.js +0 -0
  1188. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/pairs.d.ts +0 -0
  1189. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/pairs.js +0 -0
  1190. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/schema.d.ts +0 -0
  1191. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/schema.js +0 -0
  1192. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/set.d.ts +0 -0
  1193. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/set.js +0 -0
  1194. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/timestamp.d.ts +0 -0
  1195. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/schema/yaml-1.1/timestamp.js +0 -0
  1196. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/foldFlowLines.d.ts +0 -0
  1197. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/foldFlowLines.js +0 -0
  1198. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringify.d.ts +0 -0
  1199. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringify.js +0 -0
  1200. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyCollection.d.ts +0 -0
  1201. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyCollection.js +0 -0
  1202. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyComment.d.ts +0 -0
  1203. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyComment.js +0 -0
  1204. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyDocument.d.ts +0 -0
  1205. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyDocument.js +0 -0
  1206. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyNumber.d.ts +0 -0
  1207. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyNumber.js +0 -0
  1208. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyPair.d.ts +0 -0
  1209. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyPair.js +0 -0
  1210. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyString.d.ts +0 -0
  1211. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/stringify/stringifyString.js +0 -0
  1212. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/test-events.d.ts +0 -0
  1213. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/test-events.js +0 -0
  1214. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/util.d.ts +0 -0
  1215. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/util.js +0 -0
  1216. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/visit.d.ts +0 -0
  1217. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/dist/visit.js +0 -0
  1218. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/package.json +0 -0
  1219. /package/node_modules/{yaml → pi-subagents/node_modules/yaml}/util.js +0 -0
@@ -8,7 +8,8 @@ import { parse as parseYaml } from "yaml";
8
8
  import * as os from "node:os";
9
9
  import * as path from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
- import type { AcceptanceInput, AcceptanceRole, AgentRunnerConfig, OutputMode, ToolBudgetConfig, TurnBudgetConfig } from "../shared/types.ts";
11
+ import type { AcceptanceInput, AcceptanceRole, AgentRunnerConfig, OutputMode, ToolBudgetConfig } from "../shared/types.ts";
12
+ import { CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL, isCodeOwnedExternalCliAdapterId, parseExternalCliCapabilityNarrowing, validateCodeOwnedProfileRunner } from "../runs/shared/external-cli-contract.ts";
12
13
  import { getAgentDir, getProjectConfigDir } from "../shared/utils.ts";
13
14
  import { KNOWN_FIELDS } from "./agent-serializer.ts";
14
15
  import { parseChain, parseJsonChain } from "./chain-serializer.ts";
@@ -16,15 +17,16 @@ import { mergeAgentsForScope } from "./agent-selection.ts";
16
17
  import { parseFrontmatter, parseFrontmatterList } from "./frontmatter.ts";
17
18
  import { buildRuntimeName, parsePackageName } from "./identity.ts";
18
19
  import { parseModelScopeConfig, type ModelScopeConfig } from "../runs/shared/model-scope.ts";
20
+ export { BUILTIN_AGENT_NAMES } from "./builtin-names.ts";
19
21
  export { buildRuntimeName, frontmatterNameForConfig, parsePackageName } from "./identity.ts";
20
22
  import { parseMemoryFrontmatter } from "./agent-memory.ts";
21
- import { resolveTurnBudgetConfig } from "../runs/shared/turn-budget.ts";
22
23
  import { validateAcceptanceInput } from "../runs/shared/acceptance.ts";
23
24
  import { validatePermissionRules, type PermissionRules } from "../runs/shared/permissions.ts";
25
+ import { parseThinkingLevel, type ThinkingLevel } from "../shared/thinking-ceiling.ts";
24
26
 
25
27
  export type AgentScope = "user" | "project" | "both";
26
28
 
27
- export type AgentSource = "builtin" | "package" | "user" | "project";
29
+ export type AgentSource = "builtin" | "package" | "user" | "project" | "runtime";
28
30
  type SystemPromptMode = "append" | "replace";
29
31
  export type AgentDefaultContext = "fresh" | "fork";
30
32
 
@@ -35,16 +37,6 @@ export interface AgentMemoryConfig {
35
37
  path: string;
36
38
  }
37
39
 
38
- export const BUILTIN_AGENT_NAMES = [
39
- "advisor",
40
- "delegate",
41
- "oracle",
42
- "researcher",
43
- "reviewer",
44
- "scout",
45
- "worker",
46
- ] as const;
47
-
48
40
  export function defaultSystemPromptMode(name: string): SystemPromptMode {
49
41
  return name === "delegate" ? "append" : "replace";
50
42
  }
@@ -59,11 +51,17 @@ export function defaultInheritSkills(): boolean {
59
51
 
60
52
  export interface BuiltinAgentOverrideBase {
61
53
  description?: string;
54
+ output?: string;
55
+ outputMode?: OutputMode;
56
+ defaultReads?: string[];
62
57
  model?: string;
58
+ modelProvider?: string;
63
59
  fallbackModels?: string[];
60
+ fast?: boolean;
64
61
  thinking?: string | false;
65
62
  systemPromptMode: SystemPromptMode;
66
63
  inheritProjectContext: boolean;
64
+ inheritGlobalContext: boolean;
67
65
  inheritSkills: boolean;
68
66
  defaultContext?: AgentDefaultContext;
69
67
  acceptanceRole?: AcceptanceRole;
@@ -72,29 +70,41 @@ export interface BuiltinAgentOverrideBase {
72
70
  skills?: string[];
73
71
  skillPath?: string[];
74
72
  tools?: string[];
73
+ excludeTools?: string[];
74
+ allowNestedSubagents?: boolean;
75
75
  mcpDirectTools?: string[];
76
76
  extensions?: string[];
77
77
  subagentOnlyExtensions?: string[];
78
+ mutationTools?: string[];
78
79
  completionGuard?: boolean;
79
80
  toolBudget?: ToolBudgetConfig;
80
81
  }
81
82
 
82
83
  interface BuiltinAgentOverrideConfig {
83
84
  description?: string;
85
+ output?: string | false;
86
+ outputMode?: OutputMode;
87
+ defaultReads?: string[] | false;
84
88
  model?: string | false;
89
+ defaultProvider?: string | false;
85
90
  fallbackModels?: string[] | false;
91
+ fast?: boolean;
86
92
  thinking?: string | false;
87
93
  systemPromptMode?: SystemPromptMode;
88
94
  inheritProjectContext?: boolean;
95
+ inheritGlobalContext?: boolean;
89
96
  inheritSkills?: boolean;
90
97
  defaultContext?: AgentDefaultContext | false;
91
98
  acceptanceRole?: AcceptanceRole | false;
92
99
  disabled?: boolean;
93
100
  systemPrompt?: string;
94
101
  skills?: string[] | false;
95
- tools?: string[] | false;
102
+ tools?: string[] | false | "inherit";
103
+ excludeTools?: string[] | false;
104
+ allowNestedSubagents?: boolean;
96
105
  extensions?: string[] | false;
97
106
  subagentOnlyExtensions?: string[] | false;
107
+ mutationTools?: string[] | false;
98
108
  completionGuard?: boolean;
99
109
  toolBudget?: ToolBudgetConfig | false;
100
110
  }
@@ -110,6 +120,7 @@ export interface AgentModelSourceInfo {
110
120
  scope: "user" | "project";
111
121
  path: string;
112
122
  model: string;
123
+ defaultProvider?: string;
113
124
  }
114
125
 
115
126
  export interface AgentConfig {
@@ -117,31 +128,42 @@ export interface AgentConfig {
117
128
  runner?: AgentRunnerConfig;
118
129
  localName?: string;
119
130
  packageName?: string;
131
+ packageSourceName?: string;
132
+ packageSourceVersion?: string;
133
+ packageSourceRoot?: string;
120
134
  description: string;
121
135
  aliases?: string[];
122
136
  tools?: string[];
137
+ excludeTools?: string[];
138
+ allowNestedSubagents?: boolean;
123
139
  mcpDirectTools?: string[];
124
140
  model?: string;
141
+ modelProvider?: string;
125
142
  fallbackModels?: string[];
143
+ fast?: boolean;
126
144
  thinking?: string | false;
127
145
  systemPromptMode: SystemPromptMode;
128
146
  inheritProjectContext: boolean;
147
+ inheritGlobalContext: boolean;
129
148
  inheritSkills: boolean;
130
149
  defaultContext?: AgentDefaultContext;
131
150
  defaultAsync?: boolean;
132
151
  defaultTimeoutMs?: number;
133
- defaultTurnBudget?: TurnBudgetConfig;
152
+ defaultToolTimeoutMs?: number;
134
153
  defaultAcceptance?: AcceptanceInput;
135
154
  acceptanceRole?: AcceptanceRole;
136
155
  systemPrompt: string;
137
156
  source: AgentSource;
138
157
  filePath: string;
158
+ discoveryPriority?: number;
139
159
  skills?: string[];
140
160
  skillPath?: string[];
141
161
  extensions?: string[];
142
162
  extensionsFromDefault?: boolean;
143
163
  subagentOnlyExtensions?: string[];
164
+ mutationTools?: string[];
144
165
  output?: string;
166
+ outputMode?: OutputMode;
145
167
  defaultReads?: string[];
146
168
  defaultProgress?: boolean;
147
169
  interactive?: boolean;
@@ -154,21 +176,25 @@ export interface AgentConfig {
154
176
  extraFields?: Record<string, string>;
155
177
  override?: BuiltinAgentOverrideInfo;
156
178
  modelSource?: AgentModelSourceInfo;
179
+ maxThinking?: ThinkingLevel;
157
180
  }
158
181
 
159
182
  type ProjectRootResolution = "nearest" | "git-root";
160
183
 
161
184
  interface SubagentSettings {
162
185
  overrides: Record<string, BuiltinAgentOverrideConfig>;
186
+ providerOverrides: Record<string, Record<string, BuiltinAgentOverrideConfig>>;
163
187
  defaultModel?: string;
188
+ defaultProvider?: string;
164
189
  defaultThinking?: string;
190
+ maxThinking?: ThinkingLevel;
165
191
  defaultExtensions?: string[];
166
192
  disableBuiltins?: boolean;
167
193
  disableThinking?: boolean;
168
194
  modelScope?: ModelScopeConfig;
169
195
  }
170
196
 
171
- const EMPTY_SUBAGENT_SETTINGS: SubagentSettings = { overrides: {} };
197
+ const EMPTY_SUBAGENT_SETTINGS: SubagentSettings = { overrides: {}, providerOverrides: {} };
172
198
  const agentFrontmatterFields = new WeakMap<AgentConfig, Set<string>>();
173
199
 
174
200
  export interface ChainStepConfig {
@@ -211,19 +237,137 @@ export interface ChainDiscoveryDiagnostic {
211
237
  error: string;
212
238
  }
213
239
 
214
- interface AgentDiscoveryResult {
240
+ export interface AgentDiscoveryDiagnostic extends ChainDiscoveryDiagnostic {
241
+ name?: string;
242
+ runtimeName?: string;
243
+ packageSpecified?: boolean;
244
+ discoveryPriority?: number;
245
+ }
246
+
247
+ const AGENT_SOURCE_PRIORITY: Record<AgentSource, number> = {
248
+ builtin: 0,
249
+ package: 1,
250
+ user: 2,
251
+ project: 3,
252
+ runtime: 4,
253
+ };
254
+
255
+ function agentDefinitionPriority(definition: Pick<AgentConfig | AgentDiscoveryDiagnostic, "source" | "discoveryPriority">): number {
256
+ return AGENT_SOURCE_PRIORITY[definition.source] * 1_000_000
257
+ + (definition.discoveryPriority ?? 0);
258
+ }
259
+
260
+ export function findBlockingAgentDiagnostic(name: string, agent: AgentConfig | readonly AgentConfig[] | undefined, diagnostics: AgentDiscoveryDiagnostic[] | undefined): AgentDiscoveryDiagnostic | undefined {
261
+ const normalizedName = name.trim();
262
+ const agents = Array.isArray(agent) ? agent : agent ? [agent] : [];
263
+ let match: AgentDiscoveryDiagnostic | undefined;
264
+ for (const diagnostic of diagnostics ?? []) {
265
+ if ((diagnostic.runtimeName === normalizedName
266
+ || (diagnostic.name === normalizedName && (!diagnostic.packageSpecified
267
+ || diagnostic.runtimeName === undefined
268
+ || agents.some((agent) => agent.name === diagnostic.runtimeName && agent.localName === diagnostic.name))))
269
+ && (!match || agentDefinitionPriority(diagnostic) > agentDefinitionPriority(match))) {
270
+ match = diagnostic;
271
+ }
272
+ }
273
+ const highestPriority = Math.max(...agents.map(agentDefinitionPriority), -Infinity);
274
+ return !agents.length || (match && agentDefinitionPriority(match) > highestPriority) ? match : undefined;
275
+ }
276
+
277
+ export type AgentDefinitionDirectoryState = "absent" | "empty" | "candidates" | "unreadable" | "not-directory";
278
+
279
+ /** A definition directory actually inspected during one agent-discovery operation. */
280
+ export interface AgentDefinitionDirectoryReport {
281
+ source: AgentSource;
282
+ path: string;
283
+ state: AgentDefinitionDirectoryState;
284
+ candidateCount?: number;
285
+ }
286
+
287
+ /**
288
+ * Filesystem provenance for a failed agent resolution. Context is created from
289
+ * the discovery result that supplied the effective agents; callers must not
290
+ * pair arbitrary agent arrays with these directory reports.
291
+ */
292
+ export interface UnknownAgentDiagnosticContext {
293
+ cwd: string;
294
+ scope: AgentScope;
295
+ directories: readonly AgentDefinitionDirectoryReport[];
296
+ agents: readonly AgentConfig[];
297
+ }
298
+
299
+ export interface AgentDiscoveryResult {
215
300
  agents: AgentConfig[];
301
+ agentDiagnostics?: AgentDiscoveryDiagnostic[];
216
302
  projectAgentsDir: string | null;
303
+ cwd: string;
304
+ scope: AgentScope;
305
+ directories: readonly AgentDefinitionDirectoryReport[];
217
306
  modelScope?: ModelScopeConfig;
307
+ maxThinking?: ThinkingLevel;
308
+ }
309
+
310
+ /** Create formatter input from the exact discovery operation used for resolution. */
311
+ export function unknownAgentDiagnosticContext(discovered: Pick<AgentDiscoveryResult, "cwd" | "scope" | "directories" | "agents">): UnknownAgentDiagnosticContext {
312
+ return {
313
+ cwd: discovered.cwd,
314
+ scope: discovered.scope,
315
+ directories: discovered.directories,
316
+ agents: discovered.agents,
317
+ };
318
+ }
319
+
320
+ /** Render local discovery evidence without exposing filesystem error details. */
321
+ export function formatUnknownAgentError(name: string, context: UnknownAgentDiagnosticContext, prefix = "Unknown agent"): string {
322
+ const directories = context.directories.map((directory) => {
323
+ const state = directory.state === "candidates"
324
+ ? `${directory.candidateCount ?? 0} candidate${directory.candidateCount === 1 ? "" : "s"}`
325
+ : directory.state === "empty" ? "present but empty"
326
+ : directory.state === "not-directory" ? "not a directory"
327
+ : directory.state;
328
+ return `- ${directory.source}: ${directory.path} (${state})`;
329
+ });
330
+ const agents = [...context.agents]
331
+ .sort((left, right) => left.name.localeCompare(right.name) || left.source.localeCompare(right.source))
332
+ .map((agent) => `- ${agent.name} (${agent.source})`);
333
+ return [
334
+ `${prefix}: ${name}`,
335
+ `Effective cwd: ${path.resolve(context.cwd)}`,
336
+ "Consulted agent-definition directories:",
337
+ ...(directories.length ? directories : ["- (none)"]),
338
+ "Discovered agents:",
339
+ ...(agents.length ? agents : ["- (none)"]),
340
+ ].join("\n");
218
341
  }
219
342
 
220
343
  function getUserChainDir(): string {
221
344
  return path.join(getAgentDir(), "chains");
222
345
  }
223
346
 
347
+ type PackageScope = "root" | "user" | "project";
348
+ type PackageSettingsScope = Exclude<PackageScope, "root">;
349
+
350
+ interface PackageSubagentPath {
351
+ dir: string;
352
+ // A package can be reachable from more than one settings scope. Keep the
353
+ // actual memberships instead of promoting a mixed-scope path to root.
354
+ scope: Set<PackageScope>;
355
+ packageName?: string;
356
+ packageVersion?: string;
357
+ packageRoot: string;
358
+ }
359
+
360
+ interface PackageChainPath {
361
+ dir: string;
362
+ scope: Set<PackageScope>;
363
+ packageRoot: string;
364
+ }
365
+
224
366
  interface PackageSubagentPaths {
225
- agents: string[];
226
- chains: string[];
367
+ agents: PackageSubagentPath[];
368
+ chains: PackageChainPath[];
369
+ watchPaths: string[];
370
+ settingsErrors: Partial<Record<PackageSettingsScope, Error>>;
227
371
  }
228
372
 
229
373
  let cachedGlobalNpmRoot: string | null = null;
@@ -238,18 +382,6 @@ function readJsonFileBestEffort(filePath: string): unknown {
238
382
  }
239
383
  }
240
384
 
241
- function readOptionalJsonFile(filePath: string): unknown {
242
- try {
243
- return JSON.parse(fs.readFileSync(filePath, "utf-8"));
244
- } catch (error) {
245
- const code = typeof error === "object" && error !== null && "code" in error
246
- ? (error as { code?: unknown }).code
247
- : undefined;
248
- if (code === "ENOENT") return null;
249
- throw error;
250
- }
251
- }
252
-
253
385
  function isSafePackagePath(value: string): boolean {
254
386
  return value.length > 0
255
387
  && !path.isAbsolute(value)
@@ -321,6 +453,10 @@ function resolveSettingsPackageRoot(source: string, baseDir: string): string | u
321
453
  if (normalized === "." || normalized === ".." || normalized.startsWith("./") || normalized.startsWith("../")) {
322
454
  return path.resolve(baseDir, normalized);
323
455
  }
456
+ if (/^https?:\/\//i.test(trimmed)) {
457
+ const parsed = parseGitPackagePath(`git:${trimmed}`);
458
+ return parsed ? path.join(baseDir, "git", parsed.host, parsed.repoPath) : undefined;
459
+ }
324
460
  return undefined;
325
461
  }
326
462
 
@@ -344,7 +480,7 @@ function getGlobalNpmRoot(): string | null {
344
480
  }
345
481
 
346
482
  try {
347
- cachedGlobalNpmRoot = fs.realpathSync(execSync("npm root -g", { encoding: "utf-8", timeout: 5000 }).trim());
483
+ cachedGlobalNpmRoot = fs.realpathSync(execSync("npm root -g", { encoding: "utf-8", timeout: 5000, windowsHide: true }).trim());
348
484
  return cachedGlobalNpmRoot;
349
485
  } catch {
350
486
  cachedGlobalNpmRoot = "";
@@ -357,18 +493,30 @@ function stringArray(value: unknown): string[] {
357
493
  return value.filter((entry): entry is string => typeof entry === "string" && entry.trim().length > 0);
358
494
  }
359
495
 
360
- function extractSubagentPathsFromPackageRoot(packageRoot: string): PackageSubagentPaths {
496
+ function packageMetadata(pkg: Record<string, unknown>, packageRoot: string): Omit<PackageSubagentPath, "dir" | "scope"> {
497
+ const name = typeof pkg.name === "string" && pkg.name.trim() ? pkg.name.trim() : undefined;
498
+ const version = typeof pkg.version === "string" && pkg.version.trim() ? pkg.version.trim() : undefined;
499
+ return {
500
+ packageRoot,
501
+ ...(name ? { packageName: name } : {}),
502
+ ...(version ? { packageVersion: version } : {}),
503
+ };
504
+ }
505
+
506
+ function extractSubagentPathsFromPackageRoot(packageRoot: string, scope: Set<PackageScope>): PackageSubagentPaths {
361
507
  const packageJsonPath = path.join(packageRoot, "package.json");
362
508
  const pkg = readJsonFileBestEffort(packageJsonPath);
363
- if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) return { agents: [], chains: [] };
509
+ if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) return { agents: [], chains: [], watchPaths: [packageJsonPath], settingsErrors: {} };
510
+ const pkgRecord = pkg as Record<string, unknown>;
511
+ const metadata = packageMetadata(pkgRecord, packageRoot);
364
512
 
365
513
  const roots: Record<string, unknown>[] = [];
366
- const piSubagents = (pkg as { "pi-subagents"?: unknown })["pi-subagents"];
514
+ const piSubagents = pkgRecord["pi-subagents"];
367
515
  if (piSubagents && typeof piSubagents === "object" && !Array.isArray(piSubagents)) {
368
516
  roots.push(piSubagents as Record<string, unknown>);
369
517
  }
370
518
 
371
- const pi = (pkg as { pi?: unknown }).pi;
519
+ const pi = pkgRecord.pi;
372
520
  if (pi && typeof pi === "object" && !Array.isArray(pi)) {
373
521
  const subagents = (pi as { subagents?: unknown }).subagents;
374
522
  if (subagents && typeof subagents === "object" && !Array.isArray(subagents)) {
@@ -376,17 +524,18 @@ function extractSubagentPathsFromPackageRoot(packageRoot: string): PackageSubage
376
524
  }
377
525
  }
378
526
 
379
- const agents: string[] = [];
380
- const chains: string[] = [];
527
+ const agents: PackageSubagentPath[] = [];
528
+ const chains: PackageChainPath[] = [];
381
529
  for (const root of roots) {
382
- for (const entry of stringArray(root.agents)) agents.push(path.resolve(packageRoot, entry));
383
- for (const entry of stringArray(root.chains)) chains.push(path.resolve(packageRoot, entry));
530
+ for (const entry of stringArray(root.agents)) agents.push({ dir: path.resolve(packageRoot, entry), scope, ...metadata });
531
+ for (const entry of stringArray(root.chains)) chains.push({ dir: path.resolve(packageRoot, entry), scope, packageRoot });
384
532
  }
385
- return { agents, chains };
533
+ return { agents, chains, watchPaths: [packageJsonPath], settingsErrors: {} };
386
534
  }
387
535
 
388
- function collectPackageRootsFromNodeModules(nodeModulesDir: string): string[] {
536
+ function collectPackageRootsFromNodeModules(nodeModulesDir: string, watchPaths?: string[]): string[] {
389
537
  const roots: string[] = [];
538
+ watchPaths?.push(nodeModulesDir);
390
539
  if (!fs.existsSync(nodeModulesDir)) return roots;
391
540
 
392
541
  let entries: fs.Dirent[];
@@ -402,6 +551,7 @@ function collectPackageRootsFromNodeModules(nodeModulesDir: string): string[] {
402
551
 
403
552
  if (entry.name.startsWith("@")) {
404
553
  const scopeDir = path.join(nodeModulesDir, entry.name);
554
+ watchPaths?.push(scopeDir);
405
555
  let scopeEntries: fs.Dirent[];
406
556
  try {
407
557
  scopeEntries = fs.readdirSync(scopeDir, { withFileTypes: true });
@@ -422,8 +572,7 @@ function collectPackageRootsFromNodeModules(nodeModulesDir: string): string[] {
422
572
  }
423
573
 
424
574
  function collectSettingsPackageRoots(settingsFile: string, baseDir: string): string[] {
425
- const settings = readOptionalJsonFile(settingsFile);
426
- if (!settings || typeof settings !== "object" || Array.isArray(settings)) return [];
575
+ const settings = readSettingsFileStrict(settingsFile);
427
576
  const packages = (settings as { packages?: unknown }).packages;
428
577
  if (!Array.isArray(packages)) return [];
429
578
 
@@ -444,52 +593,82 @@ function collectSettingsPackageRoots(settingsFile: string, baseDir: string): str
444
593
  function collectPackageSubagentPaths(cwd: string, options: { includeUser: boolean; includeProject: boolean } = { includeUser: true, includeProject: true }): PackageSubagentPaths {
445
594
  const agentDir = getAgentDir();
446
595
  const projectRoot = findConfiguredProjectRoot(cwd) ?? cwd;
447
- const packageRoots = [
448
- projectRoot,
596
+ const packageRoots: Array<{ root: string; scope: PackageScope }> = [
597
+ { root: projectRoot, scope: "root" },
449
598
  ];
450
-
599
+ const watchPaths: string[] = [path.join(projectRoot, "package.json")];
600
+ const settingsErrors: Partial<Record<PackageSettingsScope, Error>> = {};
601
+ const collectScopedSettingsRoots = (scope: PackageSettingsScope, settingsFile: string, baseDir: string): string[] => {
602
+ try {
603
+ return collectSettingsPackageRoots(settingsFile, baseDir);
604
+ } catch (error) {
605
+ // The raw source snapshot includes both settings scopes. Defer a
606
+ // strict failure until a projection actually selects this scope so an
607
+ // unrelated malformed settings file stays out of scoped discovery.
608
+ settingsErrors[scope] = error instanceof Error
609
+ ? error
610
+ : new Error(`Failed to read settings file '${settingsFile}': ${String(error)}`, { cause: error });
611
+ return [];
612
+ }
613
+ };
451
614
  if (options.includeProject) {
452
615
  const projectConfigDir = getProjectConfigDir(projectRoot);
453
- packageRoots.push(
454
- ...collectPackageRootsFromNodeModules(path.join(projectConfigDir, "npm", "node_modules")),
455
- ...collectSettingsPackageRoots(path.join(projectConfigDir, "settings.json"), projectConfigDir),
456
- );
616
+ const nodeModulesDir = path.join(projectConfigDir, "npm", "node_modules");
617
+ packageRoots.push(...collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths).map((root) => ({ root, scope: "project" as const })));
618
+ packageRoots.push(...collectScopedSettingsRoots("project", path.join(projectConfigDir, "settings.json"), projectConfigDir).map((root) => ({ root, scope: "project" as const })));
457
619
  }
458
620
 
459
621
  if (options.includeUser) {
460
- packageRoots.push(
461
- ...collectPackageRootsFromNodeModules(path.join(agentDir, "npm", "node_modules")),
462
- ...collectSettingsPackageRoots(path.join(agentDir, "settings.json"), agentDir),
463
- );
622
+ const nodeModulesDir = path.join(agentDir, "npm", "node_modules");
623
+ packageRoots.push(...collectPackageRootsFromNodeModules(nodeModulesDir, watchPaths).map((root) => ({ root, scope: "user" as const })));
624
+ packageRoots.push(...collectScopedSettingsRoots("user", path.join(agentDir, "settings.json"), agentDir).map((root) => ({ root, scope: "user" as const })));
464
625
  }
465
626
 
466
627
  if (options.includeUser) {
467
628
  const globalRoot = getGlobalNpmRoot();
468
- if (globalRoot) packageRoots.push(...collectPackageRootsFromNodeModules(globalRoot));
629
+ if (globalRoot) {
630
+ packageRoots.push(...collectPackageRootsFromNodeModules(globalRoot, watchPaths).map((root) => ({ root, scope: "user" as const })));
631
+ }
469
632
  }
470
633
 
471
- const seenRoots = new Set<string>();
472
- const seenAgents = new Set<string>();
473
- const seenChains = new Set<string>();
474
- const agents: string[] = [];
475
- const chains: string[] = [];
476
- for (const packageRoot of packageRoots) {
634
+ const seenRoots = new Map<string, Set<PackageScope>>();
635
+ const seenAgents = new Map<string, PackageSubagentPath>();
636
+ const seenChains = new Map<string, PackageChainPath>();
637
+ const agents: PackageSubagentPath[] = [];
638
+ const chains: PackageChainPath[] = [];
639
+ for (const { root: packageRoot, scope } of packageRoots) {
477
640
  const resolvedRoot = path.resolve(packageRoot);
478
- if (seenRoots.has(resolvedRoot)) continue;
479
- seenRoots.add(resolvedRoot);
480
- const paths = extractSubagentPathsFromPackageRoot(resolvedRoot);
481
- for (const agentDir of paths.agents) {
482
- if (seenAgents.has(agentDir)) continue;
483
- seenAgents.add(agentDir);
484
- agents.push(agentDir);
641
+ const scopes = seenRoots.get(resolvedRoot);
642
+ if (scopes !== undefined) {
643
+ scopes.add(scope);
644
+ continue;
645
+ }
646
+ const packageScopes = new Set<PackageScope>([scope]);
647
+ seenRoots.set(resolvedRoot, packageScopes);
648
+ const paths = extractSubagentPathsFromPackageRoot(resolvedRoot, packageScopes);
649
+ watchPaths.push(...paths.watchPaths);
650
+ for (const agentPath of paths.agents) {
651
+ const agentKey = `${agentPath.dir}\u0000${agentPath.packageRoot}`;
652
+ const existing = seenAgents.get(agentKey);
653
+ if (existing) {
654
+ for (const packageScope of agentPath.scope) existing.scope.add(packageScope);
655
+ continue;
656
+ }
657
+ seenAgents.set(agentKey, agentPath);
658
+ agents.push(agentPath);
485
659
  }
486
660
  for (const chainDir of paths.chains) {
487
- if (seenChains.has(chainDir)) continue;
488
- seenChains.add(chainDir);
661
+ const chainKey = `${chainDir.dir}\u0000${chainDir.packageRoot}`;
662
+ const existing = seenChains.get(chainKey);
663
+ if (existing) {
664
+ for (const packageScope of chainDir.scope) existing.scope.add(packageScope);
665
+ continue;
666
+ }
667
+ seenChains.set(chainKey, chainDir);
489
668
  chains.push(chainDir);
490
669
  }
491
670
  }
492
- return { agents, chains };
671
+ return { agents, chains, watchPaths, settingsErrors };
493
672
  }
494
673
 
495
674
  function normalizeAgentAliases(rawAliases: string[] | undefined, agentName: string): string[] | undefined {
@@ -501,7 +680,7 @@ function normalizeAgentAliases(rawAliases: string[] | undefined, agentName: stri
501
680
  function effectiveAgentMatch(matches: AgentConfig[]): { agent?: AgentConfig; error?: string } {
502
681
  const distinctNames = [...new Set(matches.map((agent) => agent.name))];
503
682
  if (distinctNames.length === 1) {
504
- const sourceRank = new Map<AgentConfig["source"], number>([["builtin", 0], ["package", 1], ["user", 2], ["project", 3]]);
683
+ const sourceRank = new Map<AgentConfig["source"], number>([["builtin", 0], ["package", 1], ["user", 2], ["project", 3], ["runtime", 4]]);
505
684
  const agent = [...matches].sort((a, b) => (sourceRank.get(b.source) ?? 0) - (sourceRank.get(a.source) ?? 0))[0];
506
685
  return agent ? { agent } : {};
507
686
  }
@@ -565,11 +744,17 @@ function arraysEqual(a: string[] | undefined, b: string[] | undefined): boolean
565
744
  function cloneOverrideBase(agent: AgentConfig): BuiltinAgentOverrideBase {
566
745
  return {
567
746
  description: agent.description,
747
+ ...(agent.output !== undefined ? { output: agent.output } : {}),
748
+ ...(agent.outputMode !== undefined ? { outputMode: agent.outputMode } : {}),
749
+ ...(agent.defaultReads !== undefined ? { defaultReads: [...agent.defaultReads] } : {}),
568
750
  ...(agent.model !== undefined ? { model: agent.model } : {}),
751
+ ...(agent.modelProvider !== undefined ? { modelProvider: agent.modelProvider } : {}),
569
752
  ...(agent.fallbackModels ? { fallbackModels: [...agent.fallbackModels] } : {}),
753
+ ...(agent.fast !== undefined ? { fast: agent.fast } : {}),
570
754
  ...(agent.thinking !== undefined ? { thinking: agent.thinking } : {}),
571
755
  systemPromptMode: agent.systemPromptMode,
572
756
  inheritProjectContext: agent.inheritProjectContext,
757
+ inheritGlobalContext: agent.inheritGlobalContext,
573
758
  inheritSkills: agent.inheritSkills,
574
759
  ...(agent.defaultContext !== undefined ? { defaultContext: agent.defaultContext } : {}),
575
760
  ...(agent.acceptanceRole !== undefined ? { acceptanceRole: agent.acceptanceRole } : {}),
@@ -578,9 +763,12 @@ function cloneOverrideBase(agent: AgentConfig): BuiltinAgentOverrideBase {
578
763
  ...(agent.skills ? { skills: [...agent.skills] } : {}),
579
764
  ...(agent.skillPath ? { skillPath: [...agent.skillPath] } : {}),
580
765
  ...(agent.tools ? { tools: [...agent.tools] } : {}),
766
+ ...(agent.excludeTools ? { excludeTools: [...agent.excludeTools] } : {}),
767
+ ...(agent.allowNestedSubagents !== undefined ? { allowNestedSubagents: agent.allowNestedSubagents } : {}),
581
768
  ...(agent.mcpDirectTools ? { mcpDirectTools: [...agent.mcpDirectTools] } : {}),
582
769
  ...(!agent.extensionsFromDefault && agent.extensions ? { extensions: [...agent.extensions] } : {}),
583
770
  ...(agent.subagentOnlyExtensions ? { subagentOnlyExtensions: [...agent.subagentOnlyExtensions] } : {}),
771
+ ...(agent.mutationTools ? { mutationTools: [...agent.mutationTools] } : {}),
584
772
  ...(agent.completionGuard !== undefined ? { completionGuard: agent.completionGuard } : {}),
585
773
  ...(agent.toolBudget !== undefined ? { toolBudget: agent.toolBudget } : {}),
586
774
  };
@@ -589,22 +777,31 @@ function cloneOverrideBase(agent: AgentConfig): BuiltinAgentOverrideBase {
589
777
  function cloneOverrideValue(override: BuiltinAgentOverrideConfig): BuiltinAgentOverrideConfig {
590
778
  return {
591
779
  ...(override.description !== undefined ? { description: override.description } : {}),
780
+ ...(override.output !== undefined ? { output: override.output } : {}),
781
+ ...(override.outputMode !== undefined ? { outputMode: override.outputMode } : {}),
782
+ ...(override.defaultReads !== undefined ? { defaultReads: override.defaultReads === false ? false : [...override.defaultReads] } : {}),
592
783
  ...(override.model !== undefined ? { model: override.model } : {}),
784
+ ...(override.defaultProvider !== undefined ? { defaultProvider: override.defaultProvider } : {}),
593
785
  ...(override.fallbackModels !== undefined
594
786
  ? { fallbackModels: override.fallbackModels === false ? false : [...override.fallbackModels] }
595
787
  : {}),
788
+ ...(override.fast !== undefined ? { fast: override.fast } : {}),
596
789
  ...(override.thinking !== undefined ? { thinking: override.thinking } : {}),
597
790
  ...(override.systemPromptMode !== undefined ? { systemPromptMode: override.systemPromptMode } : {}),
598
791
  ...(override.inheritProjectContext !== undefined ? { inheritProjectContext: override.inheritProjectContext } : {}),
792
+ ...(override.inheritGlobalContext !== undefined ? { inheritGlobalContext: override.inheritGlobalContext } : {}),
599
793
  ...(override.inheritSkills !== undefined ? { inheritSkills: override.inheritSkills } : {}),
600
794
  ...(override.defaultContext !== undefined ? { defaultContext: override.defaultContext } : {}),
601
795
  ...(override.acceptanceRole !== undefined ? { acceptanceRole: override.acceptanceRole } : {}),
602
796
  ...(override.disabled !== undefined ? { disabled: override.disabled } : {}),
603
797
  ...(override.systemPrompt !== undefined ? { systemPrompt: override.systemPrompt } : {}),
604
798
  ...(override.skills !== undefined ? { skills: override.skills === false ? false : [...override.skills] } : {}),
605
- ...(override.tools !== undefined ? { tools: override.tools === false ? false : [...override.tools] } : {}),
799
+ ...(override.tools !== undefined ? { tools: Array.isArray(override.tools) ? [...override.tools] : override.tools } : {}),
800
+ ...(override.excludeTools !== undefined ? { excludeTools: override.excludeTools === false ? false : [...override.excludeTools] } : {}),
801
+ ...(override.allowNestedSubagents !== undefined ? { allowNestedSubagents: override.allowNestedSubagents } : {}),
606
802
  ...(override.extensions !== undefined ? { extensions: override.extensions === false ? false : [...override.extensions] } : {}),
607
803
  ...(override.subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions: override.subagentOnlyExtensions === false ? false : [...override.subagentOnlyExtensions] } : {}),
804
+ ...(override.mutationTools !== undefined ? { mutationTools: override.mutationTools === false ? false : [...override.mutationTools] } : {}),
608
805
  ...(override.completionGuard !== undefined ? { completionGuard: override.completionGuard } : {}),
609
806
  ...(override.toolBudget !== undefined ? { toolBudget: override.toolBudget === false ? false : { ...override.toolBudget, ...(Array.isArray(override.toolBudget.block) ? { block: [...override.toolBudget.block] } : {}) } } : {}),
610
807
  };
@@ -654,7 +851,7 @@ export function findNearestProjectRoot(cwd: string): string | null {
654
851
  return findProjectRootCandidates(cwd)[0] ?? null;
655
852
  }
656
853
 
657
- function findConfiguredProjectRoot(cwd: string): string | null {
854
+ export function findConfiguredProjectRoot(cwd: string): string | null {
658
855
  const candidates = findProjectRootCandidates(cwd);
659
856
  const nearestRoot = candidates[0];
660
857
  if (!nearestRoot) return null;
@@ -738,6 +935,17 @@ function parseOverrideStringArrayOrFalse(
738
935
  return items;
739
936
  }
740
937
 
938
+ function parseToolsOverride(
939
+ value: unknown,
940
+ meta: { filePath: string; name: string },
941
+ ): BuiltinAgentOverrideConfig["tools"] | undefined {
942
+ if (typeof value === "string" && value.trim() === "inherit") return "inherit";
943
+ if (value === undefined || value === false || Array.isArray(value)) {
944
+ return parseOverrideStringArrayOrFalse(value, { ...meta, field: "tools" });
945
+ }
946
+ throw new Error(`Builtin override '${meta.name}' in '${meta.filePath}' has invalid 'tools'; expected an array of strings, "inherit", or false.`);
947
+ }
948
+
741
949
  function parseBuiltinOverrideEntry(
742
950
  name: string,
743
951
  value: unknown,
@@ -758,11 +966,29 @@ function parseBuiltinOverrideEntry(
758
966
  }
759
967
  }
760
968
 
969
+ if ("output" in input) {
970
+ if ((typeof input.output === "string" && input.output.trim()) || input.output === false) override.output = input.output;
971
+ else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'output'; expected a non-empty string or false.`);
972
+ }
973
+
974
+ if ("outputMode" in input) {
975
+ if (input.outputMode === "inline" || input.outputMode === "file-only") {
976
+ override.outputMode = input.outputMode;
977
+ } else {
978
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'outputMode'; expected 'inline' or 'file-only'.`);
979
+ }
980
+ }
981
+
761
982
  if ("model" in input) {
762
983
  if (typeof input.model === "string" || input.model === false) override.model = input.model;
763
984
  else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'model'; expected a string or false.`);
764
985
  }
765
986
 
987
+ if ("fast" in input) {
988
+ if (typeof input.fast === "boolean") override.fast = input.fast;
989
+ else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'fast'; expected a boolean.`);
990
+ }
991
+
766
992
  if ("thinking" in input) {
767
993
  if (typeof input.thinking === "string" || input.thinking === false) override.thinking = input.thinking;
768
994
  else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'thinking'; expected a string or false.`);
@@ -784,6 +1010,14 @@ function parseBuiltinOverrideEntry(
784
1010
  }
785
1011
  }
786
1012
 
1013
+ if ("inheritGlobalContext" in input) {
1014
+ if (typeof input.inheritGlobalContext === "boolean") {
1015
+ override.inheritGlobalContext = input.inheritGlobalContext;
1016
+ } else {
1017
+ throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'inheritGlobalContext'; expected a boolean.`);
1018
+ }
1019
+ }
1020
+
787
1021
  if ("inheritSkills" in input) {
788
1022
  if (typeof input.inheritSkills === "boolean") {
789
1023
  override.inheritSkills = input.inheritSkills;
@@ -839,14 +1073,29 @@ function parseBuiltinOverrideEntry(
839
1073
  else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'systemPrompt'; expected a string.`);
840
1074
  }
841
1075
 
1076
+ const defaultReads = parseOverrideStringArrayOrFalse(input.defaultReads, { filePath, name, field: "defaultReads" });
1077
+ if (defaultReads !== undefined) override.defaultReads = defaultReads;
1078
+
842
1079
  const fallbackModels = parseOverrideStringArrayOrFalse(input.fallbackModels, { filePath, name, field: "fallbackModels" });
843
1080
  if (fallbackModels !== undefined) override.fallbackModels = fallbackModels;
844
1081
 
1082
+ if ("defaultProvider" in input) {
1083
+ if (input.defaultProvider === false) override.defaultProvider = false;
1084
+ else if (typeof input.defaultProvider === "string" && input.defaultProvider.trim()) override.defaultProvider = input.defaultProvider.trim();
1085
+ else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'defaultProvider'; expected a non-empty string or false.`);
1086
+ }
1087
+
845
1088
  const skills = parseOverrideStringArrayOrFalse(input.skills, { filePath, name, field: "skills" });
846
1089
  if (skills !== undefined) override.skills = skills;
847
1090
 
848
- const tools = parseOverrideStringArrayOrFalse(input.tools, { filePath, name, field: "tools" });
1091
+ const tools = parseToolsOverride(input.tools, { filePath, name });
849
1092
  if (tools !== undefined) override.tools = tools;
1093
+ const excludeTools = parseOverrideStringArrayOrFalse(input.excludeTools, { filePath, name, field: "excludeTools" });
1094
+ if (excludeTools !== undefined) override.excludeTools = excludeTools;
1095
+ if ("allowNestedSubagents" in input) {
1096
+ if (typeof input.allowNestedSubagents === "boolean") override.allowNestedSubagents = input.allowNestedSubagents;
1097
+ else throw new Error(`Builtin override '${name}' in '${filePath}' has invalid 'allowNestedSubagents'; expected a boolean.`);
1098
+ }
850
1099
 
851
1100
  const extensions = parseOverrideStringArrayOrFalse(input.extensions, { filePath, name, field: "extensions" });
852
1101
  if (extensions !== undefined) override.extensions = extensions;
@@ -854,6 +1103,9 @@ function parseBuiltinOverrideEntry(
854
1103
  const subagentOnlyExtensions = parseOverrideStringArrayOrFalse(input.subagentOnlyExtensions, { filePath, name, field: "subagentOnlyExtensions" });
855
1104
  if (subagentOnlyExtensions !== undefined) override.subagentOnlyExtensions = subagentOnlyExtensions;
856
1105
 
1106
+ const mutationTools = parseOverrideStringArrayOrFalse(input.mutationTools, { filePath, name, field: "mutationTools" });
1107
+ if (mutationTools !== undefined) override.mutationTools = mutationTools;
1108
+
857
1109
  return Object.keys(override).length > 0 ? override : undefined;
858
1110
  }
859
1111
 
@@ -888,6 +1140,14 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
888
1140
  throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultModel'; expected a non-empty string.`);
889
1141
  }
890
1142
  }
1143
+ let defaultProvider: string | undefined;
1144
+ if ("defaultProvider" in subagentsObject) {
1145
+ if (typeof subagentsObject.defaultProvider === "string" && subagentsObject.defaultProvider.trim()) {
1146
+ defaultProvider = subagentsObject.defaultProvider.trim();
1147
+ } else {
1148
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultProvider'; expected a non-empty string.`);
1149
+ }
1150
+ }
891
1151
  let defaultThinking: string | undefined;
892
1152
  if ("defaultThinking" in subagentsObject) {
893
1153
  if (typeof subagentsObject.defaultThinking === "string" && subagentsObject.defaultThinking.trim()) {
@@ -896,6 +1156,14 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
896
1156
  throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultThinking'; expected a non-empty string.`);
897
1157
  }
898
1158
  }
1159
+ let maxThinking: ThinkingLevel | undefined;
1160
+ if ("maxThinking" in subagentsObject) {
1161
+ try {
1162
+ maxThinking = parseThinkingLevel(subagentsObject.maxThinking, `'${filePath}' subagents.maxThinking`);
1163
+ } catch (error) {
1164
+ 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 });
1165
+ }
1166
+ }
899
1167
  let defaultExtensions: string[] | undefined;
900
1168
  if ("defaultExtensions" in subagentsObject) {
901
1169
  if (!Array.isArray(subagentsObject.defaultExtensions)
@@ -907,45 +1175,90 @@ function readSubagentSettings(filePath: string | null): SubagentSettings {
907
1175
  const modelScope = parseModelScopeConfig(subagentsObject.modelScope, { filePath });
908
1176
 
909
1177
  const parsed: Record<string, BuiltinAgentOverrideConfig> = {};
1178
+ const providerOverrides: Record<string, Record<string, BuiltinAgentOverrideConfig>> = {};
910
1179
  const agentOverrides = subagentsObject.agentOverrides;
1180
+ const agentOverridesByProvider = subagentsObject.agentOverridesByProvider;
911
1181
  const parsedSettings: SubagentSettings = {
912
1182
  overrides: parsed,
1183
+ providerOverrides,
913
1184
  ...(defaultModel !== undefined ? { defaultModel } : {}),
1185
+ ...(defaultProvider !== undefined ? { defaultProvider } : {}),
914
1186
  ...(defaultThinking !== undefined ? { defaultThinking } : {}),
1187
+ ...(maxThinking !== undefined ? { maxThinking } : {}),
915
1188
  ...(defaultExtensions !== undefined ? { defaultExtensions } : {}),
916
1189
  ...(disableBuiltins !== undefined ? { disableBuiltins } : {}),
917
1190
  ...(disableThinking !== undefined ? { disableThinking } : {}),
918
1191
  ...(modelScope !== undefined ? { modelScope } : {}),
919
1192
  };
920
- if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides)) {
921
- return parsedSettings;
1193
+ if (agentOverrides && typeof agentOverrides === "object" && !Array.isArray(agentOverrides)) {
1194
+ for (const [name, value] of Object.entries(agentOverrides)) {
1195
+ const override = parseBuiltinOverrideEntry(name, value, filePath);
1196
+ if (override) parsed[name] = override;
1197
+ }
922
1198
  }
923
- for (const [name, value] of Object.entries(agentOverrides)) {
924
- const override = parseBuiltinOverrideEntry(name, value, filePath);
925
- if (override) parsed[name] = override;
1199
+ if (agentOverridesByProvider !== undefined) {
1200
+ if (!agentOverridesByProvider || typeof agentOverridesByProvider !== "object" || Array.isArray(agentOverridesByProvider)) {
1201
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'agentOverridesByProvider'; expected an object keyed by provider.`);
1202
+ }
1203
+ for (const [provider, value] of Object.entries(agentOverridesByProvider)) {
1204
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1205
+ throw new Error(`Subagent settings in '${filePath}' have invalid 'agentOverridesByProvider.${provider}'; expected an object keyed by agent.`);
1206
+ }
1207
+ const entries: Record<string, BuiltinAgentOverrideConfig> = {};
1208
+ for (const [agentName, agentValue] of Object.entries(value)) {
1209
+ const override = parseBuiltinOverrideEntry(`agentOverridesByProvider.${provider}.${agentName}`, agentValue, filePath);
1210
+ if (override) entries[agentName] = override;
1211
+ }
1212
+ providerOverrides[provider] = entries;
1213
+ }
926
1214
  }
927
1215
  return parsedSettings;
928
1216
  }
929
1217
 
1218
+ function selectProviderOverrides(settings: SubagentSettings, provider: string | undefined): SubagentSettings {
1219
+ if (!provider) return settings;
1220
+ const selected = settings.providerOverrides[provider];
1221
+ if (!selected) return settings;
1222
+ const overrides = { ...settings.overrides };
1223
+ for (const [name, override] of Object.entries(selected)) {
1224
+ overrides[name] = { ...overrides[name], ...override };
1225
+ }
1226
+ return { ...settings, overrides };
1227
+ }
1228
+
1229
+ function resolveSubagentDefaultProvider(
1230
+ userSettings: SubagentSettings,
1231
+ projectSettings: SubagentSettings,
1232
+ projectSettingsPath: string | null,
1233
+ ): string | undefined {
1234
+ if (projectSettingsPath && projectSettings.defaultProvider !== undefined) return projectSettings.defaultProvider;
1235
+ return userSettings.defaultProvider;
1236
+ }
1237
+
930
1238
  function resolveSubagentDefaultModel(
931
1239
  userSettings: SubagentSettings,
932
1240
  projectSettings: SubagentSettings,
933
1241
  userSettingsPath: string,
934
1242
  projectSettingsPath: string | null,
1243
+ defaultProvider: string | undefined,
935
1244
  ): AgentModelSourceInfo | undefined {
936
1245
  if (projectSettingsPath && projectSettings.defaultModel !== undefined) {
937
- return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel };
1246
+ return { type: "subagents.defaultModel", scope: "project", path: projectSettingsPath, model: projectSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) };
938
1247
  }
939
1248
  return userSettings.defaultModel !== undefined
940
- ? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel }
1249
+ ? { type: "subagents.defaultModel", scope: "user", path: userSettingsPath, model: userSettings.defaultModel, ...(defaultProvider ? { defaultProvider } : {}) }
941
1250
  : undefined;
942
1251
  }
943
1252
 
944
- function applySubagentDefaultModel(agents: AgentConfig[], defaultModel: AgentModelSourceInfo | undefined): AgentConfig[] {
945
- if (!defaultModel) return agents;
1253
+ function applySubagentDefaultModel(agents: AgentConfig[], defaultModel: AgentModelSourceInfo | undefined, defaultProvider: string | undefined): AgentConfig[] {
1254
+ if (!defaultModel && !defaultProvider) return agents;
946
1255
  return agents.map((agent) => {
947
- if (agent.model !== undefined) return agent;
948
- const next = { ...agent, model: defaultModel.model, modelSource: defaultModel };
1256
+ if (agent.model !== undefined && (agent.modelProvider !== undefined || !defaultProvider)) return agent;
1257
+ const next = {
1258
+ ...agent,
1259
+ ...(agent.model === undefined && defaultModel ? { model: defaultModel.model, modelSource: defaultModel } : {}),
1260
+ ...(defaultProvider ? { modelProvider: defaultProvider } : {}),
1261
+ };
949
1262
  const frontmatterFields = agentFrontmatterFields.get(agent);
950
1263
  if (frontmatterFields) agentFrontmatterFields.set(next, frontmatterFields);
951
1264
  return next;
@@ -972,6 +1285,20 @@ function applySubagentDefaultThinking(agents: AgentConfig[], defaultThinking: st
972
1285
  });
973
1286
  }
974
1287
 
1288
+ function resolveSubagentMaxThinking(
1289
+ userSettings: SubagentSettings,
1290
+ projectSettings: SubagentSettings,
1291
+ projectSettingsPath: string | null,
1292
+ ): ThinkingLevel | undefined {
1293
+ if (projectSettingsPath && projectSettings.maxThinking !== undefined) return projectSettings.maxThinking;
1294
+ return userSettings.maxThinking;
1295
+ }
1296
+
1297
+ function applySubagentMaxThinking(agents: AgentConfig[], maxThinking: ThinkingLevel | undefined): AgentConfig[] {
1298
+ if (maxThinking === undefined) return agents;
1299
+ return agents.map((agent) => agent.maxThinking === maxThinking ? agent : { ...agent, maxThinking });
1300
+ }
1301
+
975
1302
  function resolveSubagentDefaultExtensions(
976
1303
  userSettings: SubagentSettings,
977
1304
  projectSettings: SubagentSettings,
@@ -995,15 +1322,27 @@ function applySubagentDefaultExtensions(agents: AgentConfig[], defaultExtensions
995
1322
  function applySubagentDefaults(
996
1323
  agents: AgentConfig[],
997
1324
  defaultModel: AgentModelSourceInfo | undefined,
1325
+ defaultProvider: string | undefined,
998
1326
  defaultThinking: string | undefined,
999
1327
  defaultExtensions: string[] | undefined,
1000
1328
  ): AgentConfig[] {
1001
1329
  return applySubagentDefaultExtensions(
1002
- applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel), defaultThinking),
1330
+ applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking),
1003
1331
  defaultExtensions,
1004
1332
  );
1005
1333
  }
1006
1334
 
1335
+ function applyToolsOverride(target: AgentConfig, toolsOverride: string[] | false | "inherit"): void {
1336
+ if (toolsOverride === "inherit") {
1337
+ delete target.tools;
1338
+ delete target.mcpDirectTools;
1339
+ return;
1340
+ }
1341
+ const { tools, mcpDirectTools } = splitToolList(toolsOverride === false ? [] : toolsOverride);
1342
+ if (tools === undefined) delete target.tools; else target.tools = tools;
1343
+ if (mcpDirectTools === undefined) delete target.mcpDirectTools; else target.mcpDirectTools = mcpDirectTools;
1344
+ }
1345
+
1007
1346
  function applyBuiltinOverride(
1008
1347
  agent: AgentConfig,
1009
1348
  override: BuiltinAgentOverrideConfig,
@@ -1015,24 +1354,35 @@ function applyBuiltinOverride(
1015
1354
  };
1016
1355
 
1017
1356
  if (override.description !== undefined) next.description = override.description;
1018
- if (override.model !== undefined) { if (override.model === false) delete next.model; else next.model = override.model; }
1357
+ if (override.output !== undefined) { if (override.output === false) delete next.output; else next.output = override.output; }
1358
+ if (override.outputMode !== undefined) next.outputMode = override.outputMode;
1359
+ if (override.defaultReads !== undefined) { if (override.defaultReads === false) delete next.defaultReads; else next.defaultReads = [...override.defaultReads]; }
1360
+ if (override.model !== undefined) {
1361
+ if (override.model === false) delete next.model; else next.model = override.model;
1362
+ delete next.modelSource;
1363
+ }
1364
+ if (override.defaultProvider !== undefined) {
1365
+ if (override.defaultProvider === false) delete next.modelProvider;
1366
+ else next.modelProvider = override.defaultProvider;
1367
+ }
1019
1368
  if (override.fallbackModels !== undefined) { if (override.fallbackModels === false) delete next.fallbackModels; else next.fallbackModels = [...override.fallbackModels]; }
1369
+ if (override.fast !== undefined) next.fast = override.fast;
1020
1370
  if (override.thinking !== undefined) { if (override.thinking === false) delete next.thinking; else next.thinking = override.thinking; }
1021
1371
  if (override.systemPromptMode !== undefined) next.systemPromptMode = override.systemPromptMode;
1022
1372
  if (override.inheritProjectContext !== undefined) next.inheritProjectContext = override.inheritProjectContext;
1373
+ if (override.inheritGlobalContext !== undefined) next.inheritGlobalContext = override.inheritGlobalContext;
1023
1374
  if (override.inheritSkills !== undefined) next.inheritSkills = override.inheritSkills;
1024
1375
  if (override.defaultContext !== undefined) { if (override.defaultContext === false) delete next.defaultContext; else next.defaultContext = override.defaultContext; }
1025
1376
  if (override.acceptanceRole !== undefined) { if (override.acceptanceRole === false) delete next.acceptanceRole; else next.acceptanceRole = override.acceptanceRole; }
1026
1377
  if (override.disabled !== undefined) next.disabled = override.disabled;
1027
1378
  if (override.systemPrompt !== undefined) next.systemPrompt = override.systemPrompt;
1028
1379
  if (override.skills !== undefined) { if (override.skills === false) delete next.skills; else next.skills = [...override.skills]; }
1029
- if (override.tools !== undefined) {
1030
- const { tools, mcpDirectTools } = splitToolList(override.tools === false ? [] : override.tools);
1031
- if (tools === undefined) delete next.tools; else next.tools = tools;
1032
- if (mcpDirectTools === undefined) delete next.mcpDirectTools; else next.mcpDirectTools = mcpDirectTools;
1033
- }
1380
+ if (override.tools !== undefined) applyToolsOverride(next, override.tools);
1381
+ if (override.excludeTools !== undefined) { if (override.excludeTools === false) delete next.excludeTools; else next.excludeTools = [...override.excludeTools]; }
1382
+ if (override.allowNestedSubagents !== undefined) next.allowNestedSubagents = override.allowNestedSubagents;
1034
1383
  if (override.extensions !== undefined) { if (override.extensions === false) delete next.extensions; else next.extensions = [...override.extensions]; }
1035
1384
  if (override.subagentOnlyExtensions !== undefined) { if (override.subagentOnlyExtensions === false) delete next.subagentOnlyExtensions; else next.subagentOnlyExtensions = [...override.subagentOnlyExtensions]; }
1385
+ if (override.mutationTools !== undefined) { if (override.mutationTools === false) delete next.mutationTools; else next.mutationTools = [...override.mutationTools]; }
1036
1386
  if (override.completionGuard !== undefined) next.completionGuard = override.completionGuard;
1037
1387
  if (override.toolBudget !== undefined) { if (override.toolBudget === false) delete next.toolBudget; else next.toolBudget = override.toolBudget; }
1038
1388
 
@@ -1133,8 +1483,23 @@ function applyCustomAgentOverride(
1133
1483
  mutable().description = override.description;
1134
1484
  anyFilled = true;
1135
1485
  }
1136
- if (override.model !== undefined) {
1137
- fill("model", ["model"], override.model === false ? undefined : override.model);
1486
+ if (override.output !== undefined) {
1487
+ fill("output", ["output"], override.output === false ? undefined : override.output);
1488
+ }
1489
+ if (override.outputMode !== undefined) {
1490
+ fill("outputMode", ["outputMode"], override.outputMode);
1491
+ }
1492
+ if (override.defaultReads !== undefined) {
1493
+ fill("defaultReads", ["defaultReads"], override.defaultReads === false ? undefined : [...override.defaultReads]);
1494
+ }
1495
+ if (override.model !== undefined && !agentHasFrontmatterField(agent, "model")) {
1496
+ const target = mutable();
1497
+ if (override.model === false) delete target.model; else target.model = override.model;
1498
+ delete target.modelSource;
1499
+ anyFilled = true;
1500
+ }
1501
+ if (override.defaultProvider !== undefined) {
1502
+ fill("modelProvider", ["modelProvider", "defaultProvider"], override.defaultProvider === false ? undefined : override.defaultProvider);
1138
1503
  }
1139
1504
  if (override.fallbackModels !== undefined) {
1140
1505
  fill(
@@ -1143,6 +1508,9 @@ function applyCustomAgentOverride(
1143
1508
  override.fallbackModels === false ? undefined : [...override.fallbackModels],
1144
1509
  );
1145
1510
  }
1511
+ if (override.fast !== undefined) {
1512
+ fill("fast", ["fast"], override.fast);
1513
+ }
1146
1514
  if (override.thinking !== undefined) {
1147
1515
  fill("thinking", ["thinking"], override.thinking === false ? undefined : override.thinking);
1148
1516
  }
@@ -1152,6 +1520,9 @@ function applyCustomAgentOverride(
1152
1520
  if (override.inheritProjectContext !== undefined) {
1153
1521
  fill("inheritProjectContext", ["inheritProjectContext"], override.inheritProjectContext);
1154
1522
  }
1523
+ if (override.inheritGlobalContext !== undefined) {
1524
+ fill("inheritGlobalContext", ["inheritGlobalContext"], override.inheritGlobalContext);
1525
+ }
1155
1526
  if (override.inheritSkills !== undefined) {
1156
1527
  fill("inheritSkills", ["inheritSkills"], override.inheritSkills);
1157
1528
  }
@@ -1161,7 +1532,8 @@ function applyCustomAgentOverride(
1161
1532
  if (override.acceptanceRole !== undefined) {
1162
1533
  fill("acceptanceRole", ["acceptanceRole"], override.acceptanceRole === false ? undefined : override.acceptanceRole);
1163
1534
  }
1164
- if (override.disabled !== undefined && agent.disabled === undefined) {
1535
+ if (override.disabled !== undefined) {
1536
+ // Custom agent files cannot set `disabled`, so project overrides replace user overrides.
1165
1537
  mutable().disabled = override.disabled;
1166
1538
  anyFilled = true;
1167
1539
  }
@@ -1169,12 +1541,15 @@ function applyCustomAgentOverride(
1169
1541
  fill("skills", ["skill", "skills"], override.skills === false ? undefined : [...override.skills]);
1170
1542
  }
1171
1543
  if (override.tools !== undefined && !agentHasFrontmatterField(agent, "tools")) {
1172
- const { tools, mcpDirectTools } = splitToolList(override.tools === false ? [] : override.tools);
1173
- const target = mutable();
1174
- if (tools === undefined) delete target.tools; else target.tools = tools;
1175
- if (mcpDirectTools === undefined) delete target.mcpDirectTools; else target.mcpDirectTools = mcpDirectTools;
1544
+ applyToolsOverride(mutable(), override.tools);
1176
1545
  anyFilled = true;
1177
1546
  }
1547
+ if (override.excludeTools !== undefined) {
1548
+ fill("excludeTools", ["excludeTools"], override.excludeTools === false ? undefined : [...override.excludeTools]);
1549
+ }
1550
+ if (override.allowNestedSubagents !== undefined) {
1551
+ fill("allowNestedSubagents", ["allowNestedSubagents"], override.allowNestedSubagents);
1552
+ }
1178
1553
  if (override.extensions !== undefined) {
1179
1554
  fill("extensions", ["extensions"], override.extensions === false ? undefined : [...override.extensions]);
1180
1555
  }
@@ -1185,6 +1560,9 @@ function applyCustomAgentOverride(
1185
1560
  override.subagentOnlyExtensions === false ? undefined : [...override.subagentOnlyExtensions],
1186
1561
  );
1187
1562
  }
1563
+ if (override.mutationTools !== undefined) {
1564
+ fill("mutationTools", ["mutationTools"], override.mutationTools === false ? undefined : [...override.mutationTools]);
1565
+ }
1188
1566
  if (override.completionGuard !== undefined) {
1189
1567
  fill("completionGuard", ["completionGuard"], override.completionGuard);
1190
1568
  }
@@ -1193,7 +1571,7 @@ function applyCustomAgentOverride(
1193
1571
  }
1194
1572
 
1195
1573
  if (!anyFilled || !next) return agent;
1196
- next.override = { ...meta, base: cloneOverrideBase(agent) };
1574
+ next.override = { ...meta, base: agent.override?.base ?? cloneOverrideBase(agent) };
1197
1575
  const frontmatterFields = agentFrontmatterFields.get(agent);
1198
1576
  if (frontmatterFields) agentFrontmatterFields.set(next, frontmatterFields);
1199
1577
  return next;
@@ -1206,24 +1584,25 @@ function applyCustomAgentOverrides(
1206
1584
  userSettingsPath: string,
1207
1585
  projectSettingsPath: string | null,
1208
1586
  ): AgentConfig[] {
1587
+ // Apply user then project so project fields win without dropping user-only fields.
1209
1588
  return agents.map((agent) => {
1589
+ const userOverride = userSettings.overrides[agent.name];
1590
+ const withUserOverride = userOverride
1591
+ ? applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath })
1592
+ : agent;
1593
+
1210
1594
  const projectOverride = projectSettings.overrides[agent.name];
1211
1595
  if (projectOverride && projectSettingsPath) {
1212
- return applyCustomAgentOverride(agent, projectOverride, { scope: "project", path: projectSettingsPath });
1596
+ return applyCustomAgentOverride(withUserOverride, projectOverride, { scope: "project", path: projectSettingsPath });
1213
1597
  }
1214
1598
 
1215
- const userOverride = userSettings.overrides[agent.name];
1216
- if (userOverride) {
1217
- return applyCustomAgentOverride(agent, userOverride, { scope: "user", path: userSettingsPath });
1218
- }
1219
-
1220
- return agent;
1599
+ return withUserOverride;
1221
1600
  });
1222
1601
  }
1223
1602
 
1224
1603
  export function buildBuiltinOverrideConfig(
1225
1604
  base: BuiltinAgentOverrideBase,
1226
- draft: Pick<AgentConfig, "model" | "fallbackModels" | "thinking" | "systemPromptMode" | "inheritProjectContext" | "inheritSkills" | "defaultContext" | "acceptanceRole" | "disabled" | "systemPrompt" | "skills" | "tools" | "mcpDirectTools" | "extensions" | "subagentOnlyExtensions" | "completionGuard" | "toolBudget"> & Partial<Pick<AgentConfig, "description">>,
1605
+ draft: Pick<AgentConfig, "model" | "modelProvider" | "fallbackModels" | "fast" | "thinking" | "systemPromptMode" | "inheritProjectContext" | "inheritGlobalContext" | "inheritSkills" | "defaultContext" | "acceptanceRole" | "disabled" | "systemPrompt" | "skills" | "tools" | "allowNestedSubagents" | "mcpDirectTools" | "extensions" | "subagentOnlyExtensions" | "mutationTools" | "completionGuard" | "toolBudget"> & Partial<Pick<AgentConfig, "description" | "output" | "outputMode" | "defaultReads" | "excludeTools">>,
1227
1606
  ): BuiltinAgentOverrideConfig | undefined {
1228
1607
  const override: BuiltinAgentOverrideConfig = {};
1229
1608
 
@@ -1231,11 +1610,17 @@ export function buildBuiltinOverrideConfig(
1231
1610
  const description = draft.description.trim();
1232
1611
  if (description && description !== base.description) override.description = description;
1233
1612
  }
1613
+ if (draft.output !== base.output) override.output = draft.output ?? false;
1614
+ if (draft.outputMode !== undefined && draft.outputMode !== base.outputMode) override.outputMode = draft.outputMode;
1615
+ if (!arraysEqual(draft.defaultReads, base.defaultReads)) override.defaultReads = draft.defaultReads ? [...draft.defaultReads] : false;
1234
1616
  if (draft.model !== base.model) override.model = draft.model ?? false;
1617
+ if (draft.modelProvider !== base.modelProvider) override.defaultProvider = draft.modelProvider ?? false;
1235
1618
  if (!arraysEqual(draft.fallbackModels, base.fallbackModels)) override.fallbackModels = draft.fallbackModels ? [...draft.fallbackModels] : false;
1619
+ if (draft.fast !== base.fast) override.fast = draft.fast === true;
1236
1620
  if (draft.thinking !== base.thinking) override.thinking = draft.thinking ?? false;
1237
1621
  if (draft.systemPromptMode !== base.systemPromptMode) override.systemPromptMode = draft.systemPromptMode;
1238
1622
  if (draft.inheritProjectContext !== base.inheritProjectContext) override.inheritProjectContext = draft.inheritProjectContext;
1623
+ if (draft.inheritGlobalContext !== base.inheritGlobalContext) override.inheritGlobalContext = draft.inheritGlobalContext;
1239
1624
  if (draft.inheritSkills !== base.inheritSkills) override.inheritSkills = draft.inheritSkills;
1240
1625
  if (draft.defaultContext !== base.defaultContext) override.defaultContext = draft.defaultContext ?? false;
1241
1626
  if (draft.acceptanceRole !== base.acceptanceRole) override.acceptanceRole = draft.acceptanceRole ?? false;
@@ -1246,10 +1631,13 @@ export function buildBuiltinOverrideConfig(
1246
1631
  const baseTools = joinToolList(base);
1247
1632
  const draftTools = joinToolList(draft);
1248
1633
  if (!arraysEqual(draftTools, baseTools)) override.tools = draftTools ? [...draftTools] : false;
1634
+ if (!arraysEqual(draft.excludeTools, base.excludeTools)) override.excludeTools = draft.excludeTools ? [...draft.excludeTools] : false;
1635
+ if (draft.allowNestedSubagents !== base.allowNestedSubagents) override.allowNestedSubagents = draft.allowNestedSubagents === true;
1249
1636
  if (!arraysEqual(draft.extensions, base.extensions)) override.extensions = draft.extensions ? [...draft.extensions] : false;
1250
1637
  if (!arraysEqual(draft.subagentOnlyExtensions, base.subagentOnlyExtensions)) {
1251
1638
  override.subagentOnlyExtensions = draft.subagentOnlyExtensions ? [...draft.subagentOnlyExtensions] : false;
1252
1639
  }
1640
+ if (!arraysEqual(draft.mutationTools, base.mutationTools)) override.mutationTools = draft.mutationTools ? [...draft.mutationTools] : false;
1253
1641
  if ((draft.completionGuard !== false) !== (base.completionGuard !== false)) {
1254
1642
  override.completionGuard = draft.completionGuard !== false;
1255
1643
  }
@@ -1379,7 +1767,7 @@ export function removeBuiltinAgentOverrideFields(
1379
1767
  return { path: filePath, removed: true };
1380
1768
  }
1381
1769
 
1382
- const DISCOVERY_PRUNED_DIR_NAMES = new Set([".git", "node_modules"]);
1770
+ const DISCOVERY_PRUNED_DIR_NAMES = new Set([".git", "node_modules", ".pi", "sync-backups"]);
1383
1771
 
1384
1772
  function isDiscoveryNestedProjectRoot(dir: string): boolean {
1385
1773
  return isDirectory(getProjectConfigDir(dir)) || isDirectory(path.join(dir, ".agents"));
@@ -1391,9 +1779,24 @@ function shouldPruneDiscoveryDir(rootDir: string, dir: string, dirName: string):
1391
1779
  return path.resolve(dir) !== path.resolve(rootDir) && isDiscoveryNestedProjectRoot(dir);
1392
1780
  }
1393
1781
 
1394
- function listFilesRecursive(dir: string, predicate: (fileName: string) => boolean, rootDir = dir): string[] {
1782
+ function listFilesRecursive(
1783
+ dir: string,
1784
+ predicate: (fileName: string) => boolean,
1785
+ rootDir = dir,
1786
+ visitedDirectories = new Set<string>(),
1787
+ inspectedDirectories = new Set<string>(),
1788
+ ): string[] {
1395
1789
  const files: string[] = [];
1396
1790
  if (!fs.existsSync(dir)) return files;
1791
+ inspectedDirectories.add(path.resolve(dir));
1792
+ let realDir: string;
1793
+ try {
1794
+ realDir = fs.realpathSync(dir);
1795
+ } catch {
1796
+ return files;
1797
+ }
1798
+ if (visitedDirectories.has(realDir)) return files;
1799
+ visitedDirectories.add(realDir);
1397
1800
 
1398
1801
  let entries: fs.Dirent[];
1399
1802
  try {
@@ -1404,9 +1807,17 @@ function listFilesRecursive(dir: string, predicate: (fileName: string) => boolea
1404
1807
 
1405
1808
  for (const entry of entries) {
1406
1809
  const filePath = path.join(dir, entry.name);
1407
- if (entry.isDirectory()) {
1810
+ let isDirectory = entry.isDirectory();
1811
+ if (entry.isSymbolicLink()) {
1812
+ try {
1813
+ isDirectory = fs.statSync(filePath).isDirectory();
1814
+ } catch {
1815
+ isDirectory = false;
1816
+ }
1817
+ }
1818
+ if (isDirectory) {
1408
1819
  if (!shouldPruneDiscoveryDir(rootDir, filePath, entry.name)) {
1409
- files.push(...listFilesRecursive(filePath, predicate, rootDir));
1820
+ files.push(...listFilesRecursive(filePath, predicate, rootDir, visitedDirectories, inspectedDirectories));
1410
1821
  }
1411
1822
  continue;
1412
1823
  }
@@ -1417,6 +1828,94 @@ function listFilesRecursive(dir: string, predicate: (fileName: string) => boolea
1417
1828
  return files;
1418
1829
  }
1419
1830
 
1831
+ export interface AgentDefinitionInspection {
1832
+ files: string[];
1833
+ state: AgentDefinitionDirectoryState;
1834
+ }
1835
+
1836
+ const agentDefinitionInspectionDirectories = new WeakMap<AgentDefinitionInspection, string[]>();
1837
+
1838
+ function rememberAgentDefinitionInspection(inspection: AgentDefinitionInspection, directories: Iterable<string>): AgentDefinitionInspection {
1839
+ agentDefinitionInspectionDirectories.set(inspection, [...new Set([...directories].map((directory) => path.resolve(directory)))]);
1840
+ return inspection;
1841
+ }
1842
+
1843
+ function inspectedAgentDefinitionDirectories(inspection: AgentDefinitionInspection, root: string): string[] {
1844
+ return agentDefinitionInspectionDirectories.get(inspection) ?? [path.resolve(root)];
1845
+ }
1846
+
1847
+ /** Narrow filesystem seam so unavailable paths can be tested without permissions. */
1848
+ export interface AgentDefinitionInspectionFs {
1849
+ existsSync(filePath: string): boolean;
1850
+ realpathSync?(filePath: string): string;
1851
+ statSync(filePath: string): { isDirectory(): boolean };
1852
+ readdirSync(dir: string): fs.Dirent[];
1853
+ }
1854
+
1855
+ const DEFAULT_AGENT_DEFINITION_INSPECTION_FS: AgentDefinitionInspectionFs = {
1856
+ existsSync: fs.existsSync,
1857
+ realpathSync: fs.realpathSync,
1858
+ statSync: fs.statSync,
1859
+ readdirSync: (dir) => fs.readdirSync(dir, { withFileTypes: true }),
1860
+ };
1861
+
1862
+ /**
1863
+ * Inspect one agent-definition directory while retaining traversal failure
1864
+ * state. A nested unreadable directory makes the whole inspection unavailable,
1865
+ * preventing a partial traversal from being reported as empty or complete.
1866
+ */
1867
+ export function inspectAgentDefinitionDirectory(dir: string, operations: AgentDefinitionInspectionFs = DEFAULT_AGENT_DEFINITION_INSPECTION_FS): AgentDefinitionInspection {
1868
+ const root = path.resolve(dir);
1869
+ try {
1870
+ if (!operations.existsSync(root)) return rememberAgentDefinitionInspection({ files: [], state: "absent" }, [root]);
1871
+ if (!operations.statSync(root).isDirectory()) return rememberAgentDefinitionInspection({ files: [], state: "not-directory" }, [root]);
1872
+ } catch {
1873
+ return rememberAgentDefinitionInspection({ files: [], state: "unreadable" }, [root]);
1874
+ }
1875
+ const files: string[] = [];
1876
+ let unreadable = false;
1877
+ const visitedDirectories = new Set<string>();
1878
+ const inspectedDirectories = new Set<string>();
1879
+ const visit = (current: string): void => {
1880
+ inspectedDirectories.add(path.resolve(current));
1881
+ let realDir: string;
1882
+ try {
1883
+ realDir = operations.realpathSync?.(current) ?? path.resolve(current);
1884
+ } catch {
1885
+ unreadable = true;
1886
+ return;
1887
+ }
1888
+ if (visitedDirectories.has(realDir)) return;
1889
+ visitedDirectories.add(realDir);
1890
+
1891
+ let entries: fs.Dirent[];
1892
+ try {
1893
+ entries = operations.readdirSync(current).sort((a, b) => a.name.localeCompare(b.name));
1894
+ } catch {
1895
+ unreadable = true;
1896
+ return;
1897
+ }
1898
+ for (const entry of entries) {
1899
+ const filePath = path.join(current, entry.name);
1900
+ let isDirectory = entry.isDirectory();
1901
+ if (entry.isSymbolicLink()) {
1902
+ try {
1903
+ isDirectory = operations.statSync(filePath).isDirectory();
1904
+ } catch {
1905
+ isDirectory = false;
1906
+ }
1907
+ }
1908
+ if (isDirectory) {
1909
+ if (!shouldPruneDiscoveryDir(root, filePath, entry.name)) visit(filePath);
1910
+ continue;
1911
+ }
1912
+ if ((entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".md") && !entry.name.endsWith(".chain.md") && !isLegacyAgentSkillPath(root, filePath)) files.push(filePath);
1913
+ }
1914
+ };
1915
+ visit(root);
1916
+ return rememberAgentDefinitionInspection({ files, state: unreadable ? "unreadable" : files.length ? "candidates" : "empty" }, inspectedDirectories);
1917
+ }
1918
+
1420
1919
  function isLegacyAgentSkillPath(rootDir: string, filePath: string): boolean {
1421
1920
  const relative = path.relative(rootDir, filePath);
1422
1921
  const parts = relative.split(path.sep).map((part) => part.toLowerCase());
@@ -1426,6 +1925,14 @@ function isLegacyAgentSkillPath(rootDir: string, filePath: string): boolean {
1426
1925
  return parts.some((part, index) => part === ".agents" && parts[index + 1] === "skills");
1427
1926
  }
1428
1927
 
1928
+ function isJsonSerializable(value: unknown): boolean {
1929
+ if (value === null || typeof value === "string" || typeof value === "boolean") return true;
1930
+ if (typeof value === "number") return Number.isFinite(value);
1931
+ if (Array.isArray(value)) return value.every(isJsonSerializable);
1932
+ if (value && typeof value === "object") return Object.values(value).every(isJsonSerializable);
1933
+ return false;
1934
+ }
1935
+
1429
1936
  function parseAgentRunnerFrontmatter(raw: string | undefined, agentName: string): AgentRunnerConfig | undefined {
1430
1937
  if (raw === undefined || !raw.trim()) return undefined;
1431
1938
  let parsed: unknown;
@@ -1442,8 +1949,24 @@ function parseAgentRunnerFrontmatter(raw: string | undefined, agentName: string)
1442
1949
  if (Object.keys(runner).some((key) => key !== "type")) throw new Error(`Agent '${agentName}' has invalid Pi runner frontmatter; only 'type' is supported.`);
1443
1950
  return { type: "pi" };
1444
1951
  }
1952
+ if (runner.type === "external-job") {
1953
+ if (typeof runner.provider !== "string" || !runner.provider.trim() || runner.provider.trim() !== runner.provider) {
1954
+ throw new Error(`Agent '${agentName}' external-job runner requires a non-empty trimmed provider string.`);
1955
+ }
1956
+ if (runner.options !== undefined && (!runner.options || typeof runner.options !== "object" || Array.isArray(runner.options) || !isJsonSerializable(runner.options))) {
1957
+ throw new Error(`Agent '${agentName}' external-job runner options must be a JSON-serializable object.`);
1958
+ }
1959
+ const supported = new Set(["type", "provider", "options"]);
1960
+ const unknown = Object.keys(runner).filter((key) => !supported.has(key));
1961
+ if (unknown.length > 0) throw new Error(`Agent '${agentName}' external-job runner has unsupported fields: ${unknown.join(", ")}.`);
1962
+ return {
1963
+ type: "external-job",
1964
+ provider: runner.provider,
1965
+ ...(runner.options ? { options: runner.options as Record<string, unknown> } : {}),
1966
+ };
1967
+ }
1445
1968
  if (runner.type !== "external-cli") {
1446
- throw new Error(`Agent '${agentName}' has invalid runner.type; expected 'pi' or 'external-cli'.`);
1969
+ throw new Error(`Agent '${agentName}' has invalid runner.type; expected 'pi', 'external-cli', or 'external-job'.`);
1447
1970
  }
1448
1971
  if (typeof runner.command !== "string" || !runner.command.trim()) {
1449
1972
  throw new Error(`Agent '${agentName}' external-cli runner requires a non-empty command string.`);
@@ -1451,27 +1974,32 @@ function parseAgentRunnerFrontmatter(raw: string | undefined, agentName: string)
1451
1974
  if (runner.args !== undefined && (!Array.isArray(runner.args) || runner.args.some((arg) => typeof arg !== "string"))) {
1452
1975
  throw new Error(`Agent '${agentName}' external-cli runner args must be an array of strings.`);
1453
1976
  }
1977
+ if (runner.adapter !== undefined && !isCodeOwnedExternalCliAdapterId(runner.adapter)) throw new Error(`Agent '${agentName}' external-cli runner adapter must be ${CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL}.`);
1978
+ if (runner.adapter !== undefined && Array.isArray(runner.args) && runner.args.length > 0) throw new Error(`Agent '${agentName}' ${runner.adapter} adapter owns its argv; runner args are not supported.`);
1454
1979
  if (runner.promptDelivery !== undefined && runner.promptDelivery !== "stdin") {
1455
1980
  throw new Error(`Agent '${agentName}' external-cli runner promptDelivery must be 'stdin'.`);
1456
1981
  }
1457
- const supported = new Set(["type", "command", "args", "promptDelivery"]);
1982
+ const capabilities = parseExternalCliCapabilityNarrowing(runner.capabilities, `Agent '${agentName}' external-cli runner capabilities`);
1983
+ const supported = new Set(["type", "adapter", "command", "args", "promptDelivery", "capabilities"]);
1458
1984
  const unknown = Object.keys(runner).filter((key) => !supported.has(key));
1459
1985
  if (unknown.length > 0) throw new Error(`Agent '${agentName}' external-cli runner has unsupported fields: ${unknown.join(", ")}.`);
1460
1986
  const runnerArgs = Array.isArray(runner.args) ? runner.args.filter((arg): arg is string => typeof arg === "string") : undefined;
1461
1987
  return {
1462
1988
  type: "external-cli",
1989
+ ...(isCodeOwnedExternalCliAdapterId(runner.adapter) ? { adapter: runner.adapter } : {}),
1463
1990
  command: runner.command.trim(),
1464
1991
  ...(runnerArgs?.length ? { args: runnerArgs } : {}),
1465
1992
  ...(runner.promptDelivery ? { promptDelivery: "stdin" as const } : {}),
1993
+ ...(capabilities ? { capabilities } : {}),
1466
1994
  };
1467
1995
  }
1468
1996
 
1469
1997
  function validateExternalRunnerProfile(frontmatter: Record<string, string>, agentName: string, runner: AgentRunnerConfig | undefined): void {
1470
- if (runner?.type !== "external-cli") return;
1471
- const unsupported = ["tools", "model", "fallbackModels", "thinking", "extensions", "subagentOnlyExtensions", "maxSubagentDepth", "completionGuard", "skills", "skill", "skillPath", "toolBudget", "permission", "permissions"]
1998
+ if (runner?.type !== "external-cli" && runner?.type !== "external-job") return;
1999
+ const unsupported = ["tools", "excludeTools", "allowNestedSubagents", "model", "fallbackModels", "thinking", "extensions", "subagentOnlyExtensions", "mutationTools", "maxSubagentDepth", "completionGuard", "skills", "skill", "skillPath", "toolBudget", "permission", "permissions"]
1472
2000
  .filter((field) => frontmatter[field] !== undefined);
1473
2001
  if (unsupported.length > 0) {
1474
- throw new Error(`Agent '${agentName}' uses runner.type='external-cli' and declares unsupported Pi-only fields: ${unsupported.join(", ")}.`);
2002
+ throw new Error(`Agent '${agentName}' uses runner.type='${runner.type}' and declares unsupported Pi-only fields: ${unsupported.join(", ")}.`);
1475
2003
  }
1476
2004
  }
1477
2005
 
@@ -1488,21 +2016,48 @@ function parseAgentAcceptanceFrontmatter(raw: string | undefined, agentName: str
1488
2016
  return parsed as AcceptanceInput;
1489
2017
  }
1490
2018
 
1491
- function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1492
- const agents: AgentConfig[] = [];
2019
+ interface AgentDefinitionFile {
2020
+ filePath: string;
2021
+ content: string;
2022
+ }
1493
2023
 
1494
- for (const filePath of listFilesRecursive(dir, (fileName) => fileName.endsWith(".md") && !fileName.endsWith(".chain.md"))) {
2024
+ function readAgentDefinitionFiles(dir: string, inspection = inspectAgentDefinitionDirectory(dir)): AgentDefinitionFile[] {
2025
+ const files: AgentDefinitionFile[] = [];
2026
+ for (const filePath of inspection.files) {
1495
2027
  if (isLegacyAgentSkillPath(dir, filePath)) {
1496
2028
  continue;
1497
2029
  }
1498
2030
 
1499
- let content: string;
1500
2031
  try {
1501
- content = fs.readFileSync(filePath, "utf-8");
2032
+ files.push({ filePath, content: fs.readFileSync(filePath, "utf-8") });
1502
2033
  } catch {
1503
2034
  continue;
1504
2035
  }
2036
+ }
2037
+ return files;
2038
+ }
2039
+
2040
+ function resolveAgentRelativeExtensionPaths(paths: string[] | undefined, agentFilePath: string): string[] | undefined {
2041
+ if (paths === undefined) return undefined;
2042
+ const baseDir = path.dirname(agentFilePath);
2043
+ return paths.map((entry) => {
2044
+ const trimmed = entry.trim();
2045
+ if (trimmed === "." || trimmed === ".." || trimmed.startsWith("./") || trimmed.startsWith("../")) {
2046
+ return path.resolve(baseDir, trimmed);
2047
+ }
2048
+ return entry;
2049
+ });
2050
+ }
1505
2051
 
2052
+ function loadAgentsFromDefinitionFiles(files: AgentDefinitionFile[], source: AgentSource, discoveryPriority?: number, packageSource?: Omit<PackageSubagentPath, "dir" | "scope">): { agents: AgentConfig[]; diagnostics: AgentDiscoveryDiagnostic[] } {
2053
+ const agents: AgentConfig[] = [];
2054
+ const diagnostics: AgentDiscoveryDiagnostic[] = [];
2055
+
2056
+ for (const { filePath, content } of files) {
2057
+ let name: string | undefined;
2058
+ let runtimeName: string | undefined;
2059
+ let packageSpecified = false;
2060
+ try {
1506
2061
  const { frontmatter, body } = parseFrontmatter(content);
1507
2062
 
1508
2063
  if (!frontmatter.name || !frontmatter.description) {
@@ -1510,10 +2065,12 @@ function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1510
2065
  }
1511
2066
 
1512
2067
  const localName = frontmatter.name;
2068
+ name = localName;
1513
2069
  const parsedPackage = parsePackageName(frontmatter.package, `Agent '${localName}' package`);
1514
- if (parsedPackage.error) continue;
2070
+ packageSpecified = parsedPackage.packageName !== undefined || parsedPackage.error !== undefined;
2071
+ if (parsedPackage.error) throw new Error(parsedPackage.error);
1515
2072
  const packageName = parsedPackage.packageName;
1516
- const runtimeName = buildRuntimeName(localName, packageName);
2073
+ runtimeName = buildRuntimeName(localName, packageName);
1517
2074
 
1518
2075
  const runner = parseAgentRunnerFrontmatter(frontmatter.runner, localName);
1519
2076
  validateExternalRunnerProfile(frontmatter, localName, runner);
@@ -1521,8 +2078,11 @@ function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1521
2078
  const parsedTools = splitToolList(rawTools);
1522
2079
  const tools = parsedTools.tools ?? [];
1523
2080
  const mcpDirectTools = parsedTools.mcpDirectTools ?? [];
2081
+ const excludeTools = parseFrontmatterList(frontmatter.excludeTools);
1524
2082
  const defaultReads = parseFrontmatterList(frontmatter.defaultReads);
1525
2083
  const aliases = normalizeAgentAliases(parseFrontmatterList(frontmatter.aliases ?? frontmatter.alias), runtimeName);
2084
+ const profileError = validateCodeOwnedProfileRunner({ name: runtimeName, localName, aliases, runner });
2085
+ if (profileError) throw new Error(profileError);
1526
2086
  const skillStr = frontmatter.skill || frontmatter.skills;
1527
2087
  const skills = parseFrontmatterList(skillStr);
1528
2088
  const skillPath = parseFrontmatterList(frontmatter.skillPath);
@@ -1537,6 +2097,7 @@ function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1537
2097
  : frontmatter.inheritProjectContext === "false"
1538
2098
  ? false
1539
2099
  : defaultInheritProjectContext(localName);
2100
+ const inheritGlobalContext = frontmatter.inheritGlobalContext === "true";
1540
2101
  const inheritSkills = frontmatter.inheritSkills === "true"
1541
2102
  ? true
1542
2103
  : frontmatter.inheritSkills === "false"
@@ -1561,22 +2122,41 @@ function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1561
2122
  }
1562
2123
  defaultTimeoutMs = parsed;
1563
2124
  }
1564
- let defaultTurnBudget: TurnBudgetConfig | undefined;
1565
- if (frontmatter.turnBudget !== undefined && frontmatter.turnBudget.trim()) {
1566
- const parsed = JSON.parse(frontmatter.turnBudget) as unknown;
1567
- const resolved = resolveTurnBudgetConfig(parsed, `Agent '${localName}' turnBudget frontmatter`);
1568
- if (resolved.error) throw new Error(resolved.error);
1569
- defaultTurnBudget = resolved.turnBudget;
2125
+ let defaultToolTimeoutMs: number | undefined;
2126
+ if (frontmatter.toolTimeoutMs !== undefined) {
2127
+ const parsed = Number(frontmatter.toolTimeoutMs);
2128
+ if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 2_147_483_647) {
2129
+ throw new Error(`Agent '${localName}' has invalid toolTimeoutMs frontmatter; expected a positive integer no larger than 2147483647.`);
2130
+ }
2131
+ defaultToolTimeoutMs = parsed;
1570
2132
  }
1571
2133
  const defaultAcceptance = parseAgentAcceptanceFrontmatter(frontmatter.acceptance, localName);
2134
+ let outputMode: OutputMode | undefined;
2135
+ if (frontmatter.outputMode !== undefined) {
2136
+ if (frontmatter.outputMode === "inline" || frontmatter.outputMode === "file-only") outputMode = frontmatter.outputMode;
2137
+ else throw new Error(`Agent '${localName}' has invalid outputMode frontmatter; expected 'inline' or 'file-only'.`);
2138
+ }
1572
2139
  let acceptanceRole: AcceptanceRole | undefined;
1573
2140
  if (frontmatter.acceptanceRole !== undefined && frontmatter.acceptanceRole.trim()) {
1574
2141
  if (frontmatter.acceptanceRole === "read-only" || frontmatter.acceptanceRole === "writer") acceptanceRole = frontmatter.acceptanceRole;
1575
2142
  else throw new Error(`Agent '${localName}' has invalid acceptanceRole frontmatter; expected 'read-only' or 'writer'.`);
1576
2143
  }
1577
2144
 
1578
- const extensions = parseFrontmatterList(frontmatter.extensions);
1579
- const subagentOnlyExtensions = parseFrontmatterList(frontmatter.subagentOnlyExtensions);
2145
+ const extensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.extensions), filePath);
2146
+ const subagentOnlyExtensions = resolveAgentRelativeExtensionPaths(parseFrontmatterList(frontmatter.subagentOnlyExtensions), filePath);
2147
+ const mutationTools = parseFrontmatterList(frontmatter.mutationTools);
2148
+ let fast: boolean | undefined;
2149
+ if (frontmatter.fast !== undefined) {
2150
+ if (frontmatter.fast === "true") fast = true;
2151
+ else if (frontmatter.fast === "false") fast = false;
2152
+ else throw new Error(`Agent '${localName}' has invalid fast frontmatter; expected true or false.`);
2153
+ }
2154
+ let allowNestedSubagents: boolean | undefined;
2155
+ if (frontmatter.allowNestedSubagents !== undefined) {
2156
+ if (frontmatter.allowNestedSubagents === "true") allowNestedSubagents = true;
2157
+ else if (frontmatter.allowNestedSubagents === "false") allowNestedSubagents = false;
2158
+ else throw new Error(`Agent '${localName}' has invalid allowNestedSubagents frontmatter; expected true or false.`);
2159
+ }
1580
2160
 
1581
2161
  const extraFields: Record<string, string> = {};
1582
2162
  for (const [key, value] of Object.entries(frontmatter)) {
@@ -1614,30 +2194,40 @@ function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1614
2194
  ...(runner !== undefined ? { runner } : {}),
1615
2195
  localName,
1616
2196
  ...(packageName !== undefined ? { packageName } : {}),
2197
+ ...(packageSource?.packageName ? { packageSourceName: packageSource.packageName } : {}),
2198
+ ...(packageSource?.packageVersion ? { packageSourceVersion: packageSource.packageVersion } : {}),
2199
+ ...(packageSource?.packageRoot ? { packageSourceRoot: packageSource.packageRoot } : {}),
1617
2200
  description: frontmatter.description,
1618
2201
  ...(aliases !== undefined ? { aliases } : {}),
1619
2202
  ...(rawTools !== undefined ? { tools } : {}),
2203
+ ...(excludeTools !== undefined ? { excludeTools } : {}),
2204
+ ...(allowNestedSubagents !== undefined ? { allowNestedSubagents } : {}),
1620
2205
  ...(mcpDirectTools.length > 0 ? { mcpDirectTools } : {}),
1621
2206
  ...(frontmatter.model !== undefined ? { model: frontmatter.model } : {}),
1622
2207
  ...(fallbackModels?.length ? { fallbackModels } : {}),
2208
+ ...(fast !== undefined ? { fast } : {}),
1623
2209
  ...(frontmatter.thinking !== undefined ? { thinking: frontmatter.thinking === "false" ? false : frontmatter.thinking } : {}),
1624
2210
  systemPromptMode,
1625
2211
  inheritProjectContext,
2212
+ inheritGlobalContext,
1626
2213
  inheritSkills,
1627
2214
  ...(defaultContext !== undefined ? { defaultContext } : {}),
1628
2215
  ...(defaultAsync !== undefined ? { defaultAsync } : {}),
1629
2216
  ...(defaultTimeoutMs !== undefined ? { defaultTimeoutMs } : {}),
1630
- ...(defaultTurnBudget !== undefined ? { defaultTurnBudget } : {}),
2217
+ ...(defaultToolTimeoutMs !== undefined ? { defaultToolTimeoutMs } : {}),
1631
2218
  ...(defaultAcceptance !== undefined ? { defaultAcceptance } : {}),
1632
2219
  ...(acceptanceRole !== undefined ? { acceptanceRole } : {}),
1633
2220
  systemPrompt: body,
1634
2221
  source,
1635
2222
  filePath,
2223
+ ...(discoveryPriority !== undefined ? { discoveryPriority } : {}),
1636
2224
  ...(skills?.length ? { skills } : {}),
1637
2225
  ...(skillPath?.length ? { skillPath } : {}),
1638
2226
  ...(extensions !== undefined ? { extensions } : {}),
1639
2227
  ...(subagentOnlyExtensions !== undefined ? { subagentOnlyExtensions } : {}),
2228
+ ...(mutationTools?.length ? { mutationTools } : {}),
1640
2229
  ...(frontmatter.output !== undefined ? { output: frontmatter.output } : {}),
2230
+ ...(outputMode !== undefined ? { outputMode } : {}),
1641
2231
  ...(defaultReads?.length ? { defaultReads } : {}),
1642
2232
  defaultProgress: frontmatter.defaultProgress === "true",
1643
2233
  interactive: frontmatter.interactive === "true",
@@ -1650,16 +2240,34 @@ function loadAgentsFromDir(dir: string, source: AgentSource): AgentConfig[] {
1650
2240
  };
1651
2241
  agentFrontmatterFields.set(agent, new Set(Object.keys(frontmatter)));
1652
2242
  agents.push(agent);
2243
+ } catch (error) {
2244
+ diagnostics.push({ source, filePath, ...(name ? { name } : {}), ...(runtimeName && runtimeName !== name ? { runtimeName } : {}), ...(packageSpecified ? { packageSpecified: true } : {}), ...(discoveryPriority !== undefined ? { discoveryPriority } : {}), error: error instanceof Error ? error.message : String(error) });
2245
+ }
1653
2246
  }
1654
2247
 
1655
- return agents;
2248
+ return { agents, diagnostics };
2249
+ }
2250
+
2251
+ function loadAgentsFromDir(dir: string, source: AgentSource, discoveryPriority?: number, packageSource?: Omit<PackageSubagentPath, "dir" | "scope">, inspection = inspectAgentDefinitionDirectory(dir)): { agents: AgentConfig[]; diagnostics: AgentDiscoveryDiagnostic[] } {
2252
+ return loadAgentsFromDefinitionFiles(readAgentDefinitionFiles(dir, inspection), source, discoveryPriority, packageSource);
2253
+ }
2254
+
2255
+ function reportAgentDefinitionDirectory(source: AgentSource, dir: string, inspection: AgentDefinitionInspection): AgentDefinitionDirectoryReport {
2256
+ return {
2257
+ source,
2258
+ path: path.resolve(dir),
2259
+ state: inspection.state,
2260
+ ...(inspection.state === "candidates" ? { candidateCount: inspection.files.length } : {}),
2261
+ };
1656
2262
  }
1657
2263
 
1658
- function loadChainsFromDir(dir: string, source: AgentSource): { chains: ChainConfig[]; diagnostics: ChainDiscoveryDiagnostic[] } {
2264
+ function loadChainsFromDir(dir: string, source: AgentSource): { chains: ChainConfig[]; diagnostics: ChainDiscoveryDiagnostic[]; files: string[]; directories: string[] } {
1659
2265
  const chains = new Map<string, ChainConfig>();
1660
2266
  const diagnostics: ChainDiscoveryDiagnostic[] = [];
2267
+ const directories = new Set<string>();
2268
+ const files = listFilesRecursive(dir, (fileName) => fileName.endsWith(".chain.md") || fileName.endsWith(".chain.json"), dir, new Set<string>(), directories);
1661
2269
 
1662
- for (const filePath of listFilesRecursive(dir, (fileName) => fileName.endsWith(".chain.md") || fileName.endsWith(".chain.json"))) {
2270
+ for (const filePath of files) {
1663
2271
  let content: string;
1664
2272
  try {
1665
2273
  content = fs.readFileSync(filePath, "utf-8");
@@ -1678,7 +2286,7 @@ function loadChainsFromDir(dir: string, source: AgentSource): { chains: ChainCon
1678
2286
  }
1679
2287
  }
1680
2288
 
1681
- return { chains: Array.from(chains.values()), diagnostics };
2289
+ return { chains: Array.from(chains.values()), diagnostics, files, directories: [...directories] };
1682
2290
  }
1683
2291
 
1684
2292
  function isDirectory(p: string): boolean {
@@ -1689,20 +2297,18 @@ function isDirectory(p: string): boolean {
1689
2297
  }
1690
2298
  }
1691
2299
 
1692
- function resolveNearestProjectAgentDirs(cwd: string): { readDirs: string[]; preferredDir: string | null } {
2300
+ function resolveNearestProjectAgentDirs(cwd: string): { readDirs: string[]; candidateDirs: string[]; preferredDir: string | null } {
1693
2301
  const projectRoot = findConfiguredProjectRoot(cwd);
1694
- if (!projectRoot) return { readDirs: [], preferredDir: null };
2302
+ if (!projectRoot) return { readDirs: [], candidateDirs: [], preferredDir: null };
1695
2303
 
1696
2304
  const legacyDir = path.join(projectRoot, ".agents");
1697
2305
  const preferredDir = path.join(getProjectConfigDir(projectRoot), "agents");
2306
+ const candidateDirs = [legacyDir, preferredDir];
1698
2307
  const readDirs: string[] = [];
1699
2308
  if (isDirectory(legacyDir)) readDirs.push(legacyDir);
1700
2309
  if (isDirectory(preferredDir)) readDirs.push(preferredDir);
1701
2310
 
1702
- return {
1703
- readDirs,
1704
- preferredDir,
1705
- };
2311
+ return { readDirs, candidateDirs, preferredDir };
1706
2312
  }
1707
2313
 
1708
2314
  function resolveNearestProjectChainDirs(cwd: string): { readDirs: string[]; preferredDir: string | null } {
@@ -1716,6 +2322,9 @@ function resolveNearestProjectChainDirs(cwd: string): { readDirs: string[]; pref
1716
2322
  };
1717
2323
  }
1718
2324
  const BUILTIN_AGENTS_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "agents");
2325
+ // Candidate files and inspection state must describe the same cached builtin scan.
2326
+ const BUILTIN_AGENT_DEFINITION_INSPECTION = inspectAgentDefinitionDirectory(BUILTIN_AGENTS_DIR);
2327
+ const BUILTIN_AGENT_DEFINITION_FILES = readAgentDefinitionFiles(BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION);
1719
2328
 
1720
2329
  export const EXTRA_AGENT_DIRS_ENV = "PI_SUBAGENT_EXTRA_AGENT_DIRS";
1721
2330
 
@@ -1733,67 +2342,12 @@ function extraUserAgentDirs(): string[] {
1733
2342
  .filter((dir) => dir.length > 0);
1734
2343
  }
1735
2344
 
1736
- export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryResult {
1737
- const userDirOld = path.join(getAgentDir(), "agents");
1738
- const userDirNew = path.join(os.homedir(), ".agents");
1739
- const { readDirs: projectAgentDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(cwd);
1740
- const userSettingsPath = getUserAgentSettingsPath();
1741
- const projectSettingsPath = getProjectAgentSettingsPath(cwd);
1742
- const userSettings = scope === "project" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(userSettingsPath);
1743
- const projectSettings = scope === "user" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(projectSettingsPath);
1744
- const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath);
1745
- const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
1746
- const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
1747
- const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
1748
- const packageSubagentPaths = collectPackageSubagentPaths(cwd, {
1749
- includeUser: scope !== "project",
1750
- includeProject: scope !== "user",
1751
- });
1752
-
1753
- const builtinAgents = applyBuiltinOverrides(
1754
- applySubagentDefaults(loadAgentsFromDir(BUILTIN_AGENTS_DIR, "builtin"), defaultModel, defaultThinking, defaultExtensions),
1755
- userSettings,
1756
- projectSettings,
1757
- userSettingsPath,
1758
- projectSettingsPath,
1759
- );
1760
-
1761
- const userAgentsExtra = scope === "project" ? [] : extraUserAgentDirs().flatMap((dir) => loadAgentsFromDir(dir, "user"));
1762
- const userAgentsOld = scope === "project" ? [] : loadAgentsFromDir(userDirOld, "user");
1763
- const userAgentsNew = scope === "project" ? [] : loadAgentsFromDir(userDirNew, "user");
1764
- const userAgents = applyCustomAgentOverrides(
1765
- applySubagentDefaults([...userAgentsExtra, ...userAgentsOld, ...userAgentsNew], defaultModel, defaultThinking, defaultExtensions),
1766
- userSettings,
1767
- projectSettings,
1768
- userSettingsPath,
1769
- projectSettingsPath,
1770
- );
1771
-
1772
- const projectAgents = applyCustomAgentOverrides(
1773
- applySubagentDefaults(scope === "user" ? [] : projectAgentDirs.flatMap((dir) => loadAgentsFromDir(dir, "project")), defaultModel, defaultThinking, defaultExtensions),
1774
- userSettings,
1775
- projectSettings,
1776
- userSettingsPath,
1777
- projectSettingsPath,
1778
- );
1779
- const packageAgents = applyCustomAgentOverrides(
1780
- applySubagentDefaults(packageSubagentPaths.agents.flatMap((dir) => loadAgentsFromDir(dir, "package")), defaultModel, defaultThinking, defaultExtensions),
1781
- userSettings,
1782
- projectSettings,
1783
- userSettingsPath,
1784
- projectSettingsPath,
1785
- );
1786
- const agents = mergeAgentsForScope(scope, userAgents, projectAgents, builtinAgents, packageAgents)
1787
- .filter((agent) => agent.disabled !== true);
1788
-
1789
- return { agents, projectAgentsDir, ...(modelScope !== undefined ? { modelScope } : {}) };
1790
- }
1791
-
1792
- export function discoverAgentsAll(cwd: string): {
2345
+ export interface AgentDiscoveryAllResult {
1793
2346
  builtin: AgentConfig[];
1794
2347
  package: AgentConfig[];
1795
2348
  user: AgentConfig[];
1796
2349
  project: AgentConfig[];
2350
+ agentDiagnostics?: AgentDiscoveryDiagnostic[];
1797
2351
  chains: ChainConfig[];
1798
2352
  chainDiagnostics: ChainDiscoveryDiagnostic[];
1799
2353
  userDir: string;
@@ -1802,97 +2356,453 @@ export function discoverAgentsAll(cwd: string): {
1802
2356
  projectChainDir: string | null;
1803
2357
  userSettingsPath: string;
1804
2358
  projectSettingsPath: string | null;
1805
- } {
2359
+ maxThinking?: ThinkingLevel;
2360
+ }
2361
+
2362
+ /**
2363
+ * A single fresh source scan with both projections retained. The effective
2364
+ * projection intentionally remains separate from the all-source projection:
2365
+ * disabled and shadowed definitions are needed for diagnostics and runtime
2366
+ * collision checks even when they are not launchable.
2367
+ */
2368
+ export interface AgentDiscoverySnapshot {
2369
+ effective: AgentDiscoveryResult;
2370
+ all: AgentDiscoveryAllResult;
2371
+ }
2372
+
2373
+ interface LoadedAgentDirectory {
2374
+ dir: string;
2375
+ inspection: AgentDefinitionInspection;
2376
+ loaded: ReturnType<typeof loadAgentsFromDir>;
2377
+ packageEntry?: PackageSubagentPath;
2378
+ }
2379
+
2380
+ interface AgentDiscoverySources {
2381
+ cwd: string;
2382
+ preferredModelProvider?: string;
2383
+ userDir: string;
2384
+ userDirOld: string;
2385
+ userDirNew: string;
2386
+ userChainDir: string;
2387
+ projectAgentDirs: string[];
2388
+ projectCandidateDirs: string[];
2389
+ projectAgentsDir: string | null;
2390
+ projectChainDirs: string[];
2391
+ projectChainDir: string | null;
2392
+ userSettingsPath: string;
2393
+ projectSettingsPath: string | null;
2394
+ userSettings?: SubagentSettings;
2395
+ projectSettings?: SubagentSettings;
2396
+ packageSubagentPaths: PackageSubagentPaths;
2397
+ builtinLoaded: ReturnType<typeof loadAgentsFromDefinitionFiles>;
2398
+ userLoaded: LoadedAgentDirectory[];
2399
+ projectLoaded: LoadedAgentDirectory[];
2400
+ projectInspections: Map<string, AgentDefinitionInspection>;
2401
+ packageLoaded: LoadedAgentDirectory[];
2402
+ userChains?: ReturnType<typeof loadChainsFromDir>;
2403
+ projectChainLoaded?: Array<{ dir: string; loaded: ReturnType<typeof loadChainsFromDir> }>;
2404
+ packageChainLoaded?: Array<{ entry: PackageChainPath; loaded: ReturnType<typeof loadChainsFromDir> }>;
2405
+ watchPaths: string[];
2406
+ }
2407
+
2408
+ interface AgentDiscoveryCacheEntry {
2409
+ sources: AgentDiscoverySources;
2410
+ fingerprint: string;
2411
+ }
2412
+
2413
+ const agentDiscoveryCache = new Map<string, AgentDiscoveryCacheEntry>();
2414
+
2415
+ function isPathWithin(root: string, candidate: string): boolean {
2416
+ const relative = path.relative(path.resolve(root), path.resolve(candidate));
2417
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
2418
+ }
2419
+
2420
+ function addDirectoryWatchPaths(paths: Set<string>, root: string, files: readonly string[], directories: readonly string[] = []): void {
2421
+ const resolvedRoot = path.resolve(root);
2422
+ paths.add(resolvedRoot);
2423
+ // The initial recursive inspection is already bounded to this discovery
2424
+ // root. Keep every visited directory in the fingerprint so a file added to
2425
+ // an existing empty nested directory invalidates the snapshot too.
2426
+ for (const directory of directories) {
2427
+ if (isPathWithin(resolvedRoot, directory)) paths.add(path.resolve(directory));
2428
+ }
2429
+ for (const file of files) {
2430
+ paths.add(path.resolve(file));
2431
+ let current = path.resolve(path.dirname(file));
2432
+ while (isPathWithin(resolvedRoot, current)) {
2433
+ paths.add(current);
2434
+ if (current === resolvedRoot) break;
2435
+ current = path.dirname(current);
2436
+ }
2437
+ }
2438
+ }
2439
+
2440
+ function watchPathSignature(filePath: string): string {
2441
+ try {
2442
+ const stat = fs.statSync(filePath);
2443
+ if (stat.isDirectory()) {
2444
+ const entries = fs.readdirSync(filePath, { withFileTypes: true })
2445
+ .sort((left, right) => left.name.localeCompare(right.name))
2446
+ .map((entry) => `${entry.name}:${entry.isDirectory() ? "d" : entry.isSymbolicLink() ? "l" : "f"}`)
2447
+ .join("|");
2448
+ return `directory:${entries}`;
2449
+ }
2450
+ return `file:${stat.size}:${stat.mtimeMs}`;
2451
+ } catch {
2452
+ return "missing";
2453
+ }
2454
+ }
2455
+
2456
+ function discoveryFingerprint(paths: readonly string[]): string {
2457
+ return [...new Set(paths)]
2458
+ .sort((left, right) => left.localeCompare(right))
2459
+ .map((filePath) => `${filePath}:${watchPathSignature(filePath)}`)
2460
+ .join("\n");
2461
+ }
2462
+
2463
+ function discoveryCacheKey(cwd: string, preferredModelProvider: string | undefined): string {
2464
+ return JSON.stringify([
2465
+ path.resolve(cwd),
2466
+ preferredModelProvider ?? null,
2467
+ getProjectConfigDir(path.resolve(cwd)),
2468
+ getAgentDir(),
2469
+ os.homedir(),
2470
+ process.env.HOME ?? "",
2471
+ process.env.USERPROFILE ?? "",
2472
+ process.env[EXTRA_AGENT_DIRS_ENV] ?? "",
2473
+ process.env.PI_OFFLINE ?? "",
2474
+ process.env.APPDATA ?? "",
2475
+ ]);
2476
+ }
2477
+
2478
+ function projectDiscoveryWatchPaths(cwd: string): string[] {
2479
+ const paths: string[] = [];
2480
+ let current = path.resolve(cwd);
2481
+ while (true) {
2482
+ paths.push(getProjectConfigDir(current), path.join(current, ".agents"), path.join(current, ".git"));
2483
+ const parent = path.dirname(current);
2484
+ if (parent === current) break;
2485
+ current = parent;
2486
+ }
2487
+ return paths;
2488
+ }
2489
+
2490
+ function packageEntryIncluded(scope: AgentScope, packageScopes: PackageSubagentPath["scope"]): boolean {
2491
+ if (scope === "both" || packageScopes.has("root")) return true;
2492
+ return packageScopes.has(scope);
2493
+ }
2494
+
2495
+ function buildAgentDiscoverySources(cwd: string, preferredModelProvider?: string): AgentDiscoverySources {
2496
+ const effectiveCwd = path.resolve(cwd);
1806
2497
  const userDirOld = path.join(getAgentDir(), "agents");
1807
2498
  const userDirNew = path.join(os.homedir(), ".agents");
1808
2499
  const userChainDir = getUserChainDir();
1809
- const { readDirs: projectDirs, preferredDir: projectDir } = resolveNearestProjectAgentDirs(cwd);
1810
- const { readDirs: projectChainDirs, preferredDir: projectChainDir } = resolveNearestProjectChainDirs(cwd);
2500
+ const { readDirs: projectAgentDirs, candidateDirs: projectCandidateDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(effectiveCwd);
2501
+ const { readDirs: projectChainDirs, preferredDir: projectChainDir } = resolveNearestProjectChainDirs(effectiveCwd);
1811
2502
  const userSettingsPath = getUserAgentSettingsPath();
1812
- const projectSettingsPath = getProjectAgentSettingsPath(cwd);
1813
- const userSettings = readSubagentSettings(userSettingsPath);
1814
- const projectSettings = readSubagentSettings(projectSettingsPath);
1815
- const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath);
1816
- const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
1817
- const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
1818
- const packageSubagentPaths = collectPackageSubagentPaths(cwd);
2503
+ const projectSettingsPath = getProjectAgentSettingsPath(effectiveCwd);
2504
+ const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd);
1819
2505
 
1820
- const builtin = applyBuiltinOverrides(
1821
- applySubagentDefaults(loadAgentsFromDir(BUILTIN_AGENTS_DIR, "builtin"), defaultModel, defaultThinking, defaultExtensions),
1822
- userSettings,
1823
- projectSettings,
2506
+ const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
2507
+ const userLoaded = [...extraUserAgentDirs(), userDirOld, userDirNew].map((dir, discoveryPriority): LoadedAgentDirectory => {
2508
+ const inspection = inspectAgentDefinitionDirectory(dir);
2509
+ return { dir, inspection, loaded: loadAgentsFromDir(dir, "user", discoveryPriority, undefined, inspection) };
2510
+ });
2511
+ const projectInspections = new Map(projectCandidateDirs.map((dir) => [dir, inspectAgentDefinitionDirectory(dir)]));
2512
+ const projectLoaded = projectAgentDirs.map((dir): LoadedAgentDirectory => {
2513
+ const inspection = projectInspections.get(dir)!;
2514
+ return { dir, inspection, loaded: loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : 0, undefined, inspection) };
2515
+ });
2516
+ const packageLoaded = packageSubagentPaths.agents.map((entry, index): LoadedAgentDirectory => {
2517
+ const inspection = inspectAgentDefinitionDirectory(entry.dir);
2518
+ return { dir: entry.dir, inspection, packageEntry: entry, loaded: loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry, inspection) };
2519
+ });
2520
+
2521
+ const watchPaths = new Set<string>([
1824
2522
  userSettingsPath,
1825
- projectSettingsPath,
1826
- );
1827
- const user = applyCustomAgentOverrides(
1828
- applySubagentDefaults([
1829
- ...extraUserAgentDirs().flatMap((dir) => loadAgentsFromDir(dir, "user")),
1830
- ...loadAgentsFromDir(userDirOld, "user"),
1831
- ...loadAgentsFromDir(userDirNew, "user"),
1832
- ], defaultModel, defaultThinking, defaultExtensions),
1833
- userSettings,
1834
- projectSettings,
2523
+ ...(projectSettingsPath ? [projectSettingsPath] : []),
2524
+ ...projectDiscoveryWatchPaths(effectiveCwd),
2525
+ ...findProjectRootCandidates(effectiveCwd).map((root) => path.join(getProjectConfigDir(root), "settings.json")),
2526
+ ...packageSubagentPaths.watchPaths,
2527
+ ]);
2528
+ for (const directory of userLoaded) addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
2529
+ for (const dir of projectCandidateDirs) {
2530
+ const inspection = projectInspections.get(dir);
2531
+ addDirectoryWatchPaths(watchPaths, dir, inspection?.files ?? [], inspection ? inspectedAgentDefinitionDirectories(inspection, dir) : []);
2532
+ }
2533
+ for (const directory of packageLoaded) addDirectoryWatchPaths(watchPaths, directory.dir, directory.inspection.files, inspectedAgentDefinitionDirectories(directory.inspection, directory.dir));
2534
+
2535
+ const userDir = process.env.PI_CODING_AGENT_DIR ? userDirOld : fs.existsSync(userDirNew) ? userDirNew : userDirOld;
2536
+ return {
2537
+ cwd: effectiveCwd,
2538
+ ...(preferredModelProvider !== undefined ? { preferredModelProvider } : {}),
2539
+ userDir,
2540
+ userDirOld,
2541
+ userDirNew,
2542
+ userChainDir,
2543
+ projectAgentDirs,
2544
+ projectCandidateDirs,
2545
+ projectAgentsDir,
2546
+ projectChainDirs,
2547
+ projectChainDir,
1835
2548
  userSettingsPath,
1836
2549
  projectSettingsPath,
1837
- );
1838
- const packageMap = new Map<string, AgentConfig>();
1839
- for (const dir of packageSubagentPaths.agents) {
1840
- for (const agent of loadAgentsFromDir(dir, "package")) {
1841
- if (!packageMap.has(agent.name)) packageMap.set(agent.name, agent);
2550
+ packageSubagentPaths,
2551
+ builtinLoaded,
2552
+ userLoaded,
2553
+ projectLoaded,
2554
+ projectInspections,
2555
+ packageLoaded,
2556
+ watchPaths: [...watchPaths],
2557
+ };
2558
+ }
2559
+
2560
+ function ensureDiscoveryChains(sources: AgentDiscoverySources): void {
2561
+ if (sources.userChains) return;
2562
+ sources.packageChainLoaded = sources.packageSubagentPaths.chains.map((entry) => ({ entry, loaded: loadChainsFromDir(entry.dir, "package") }));
2563
+ sources.userChains = loadChainsFromDir(sources.userChainDir, "user");
2564
+ sources.projectChainLoaded = sources.projectChainDirs.map((dir) => ({ dir, loaded: loadChainsFromDir(dir, "project") }));
2565
+ const watchPaths = new Set(sources.watchPaths);
2566
+ addDirectoryWatchPaths(watchPaths, sources.userChainDir, sources.userChains.files, sources.userChains.directories);
2567
+ for (const chain of sources.projectChainLoaded) addDirectoryWatchPaths(watchPaths, chain.dir, chain.loaded.files, chain.loaded.directories);
2568
+ for (const chain of sources.packageChainLoaded) addDirectoryWatchPaths(watchPaths, chain.entry.dir, chain.loaded.files, chain.loaded.directories);
2569
+ sources.watchPaths = [...watchPaths];
2570
+ }
2571
+
2572
+ function getAgentDiscoverySources(cwd: string, preferredModelProvider?: string, includeChains = false): AgentDiscoverySources {
2573
+ const key = discoveryCacheKey(cwd, preferredModelProvider);
2574
+ const cached = agentDiscoveryCache.get(key);
2575
+ if (cached && cached.fingerprint === discoveryFingerprint(cached.sources.watchPaths)) {
2576
+ if (includeChains) {
2577
+ ensureDiscoveryChains(cached.sources);
2578
+ cached.fingerprint = discoveryFingerprint(cached.sources.watchPaths);
1842
2579
  }
2580
+ return cached.sources;
2581
+ }
2582
+ const sources = buildAgentDiscoverySources(cwd, preferredModelProvider);
2583
+ const entry = { sources, fingerprint: discoveryFingerprint(sources.watchPaths) };
2584
+ agentDiscoveryCache.set(key, entry);
2585
+ if (includeChains) {
2586
+ ensureDiscoveryChains(sources);
2587
+ entry.fingerprint = discoveryFingerprint(sources.watchPaths);
2588
+ }
2589
+ return sources;
2590
+ }
2591
+
2592
+ /** Clear process-local discovery snapshots, primarily for hosts that reload settings in place. */
2593
+ export function clearAgentDiscoveryCache(): void {
2594
+ agentDiscoveryCache.clear();
2595
+ }
2596
+
2597
+ function ensureSettingsForScope(sources: AgentDiscoverySources, scope: AgentScope, preferredModelProvider?: string): void {
2598
+ if (scope !== "project" && sources.userSettings === undefined) {
2599
+ if (sources.packageSubagentPaths.settingsErrors.user) throw sources.packageSubagentPaths.settingsErrors.user;
2600
+ sources.userSettings = selectProviderOverrides(readSubagentSettings(sources.userSettingsPath), preferredModelProvider);
2601
+ }
2602
+ if (scope !== "user" && sources.projectSettings === undefined) {
2603
+ if (sources.packageSubagentPaths.settingsErrors.project) throw sources.packageSubagentPaths.settingsErrors.project;
2604
+ sources.projectSettings = selectProviderOverrides(readSubagentSettings(sources.projectSettingsPath), preferredModelProvider);
1843
2605
  }
1844
- const packageAgents = applyCustomAgentOverrides(
1845
- applySubagentDefaults(Array.from(packageMap.values()), defaultModel, defaultThinking, defaultExtensions),
2606
+ }
2607
+
2608
+ function settingsForScope(sources: AgentDiscoverySources, scope: AgentScope): { user: SubagentSettings; project: SubagentSettings } {
2609
+ // Parse only settings that participate in this projection. The source cache
2610
+ // still retains both source trees, while malformed out-of-scope settings do
2611
+ // not make an otherwise valid scoped projection fail.
2612
+ ensureSettingsForScope(sources, scope, sources.preferredModelProvider);
2613
+ return {
2614
+ user: scope === "project" ? EMPTY_SUBAGENT_SETTINGS : sources.userSettings ?? EMPTY_SUBAGENT_SETTINGS,
2615
+ project: scope === "user" ? EMPTY_SUBAGENT_SETTINGS : sources.projectSettings ?? EMPTY_SUBAGENT_SETTINGS,
2616
+ };
2617
+ }
2618
+
2619
+ function configuredAgentsForScope(sources: AgentDiscoverySources, scope: AgentScope, settingsScope = scope): {
2620
+ builtin: AgentConfig[];
2621
+ package: AgentConfig[];
2622
+ user: AgentConfig[];
2623
+ project: AgentConfig[];
2624
+ userSettings: SubagentSettings;
2625
+ projectSettings: SubagentSettings;
2626
+ maxThinking?: ThinkingLevel;
2627
+ modelScope?: ModelScopeConfig;
2628
+ } {
2629
+ const { user: userSettings, project: projectSettings } = settingsForScope(sources, settingsScope);
2630
+ const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, sources.projectSettingsPath);
2631
+ const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath, defaultProvider);
2632
+ const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, sources.projectSettingsPath);
2633
+ const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, sources.projectSettingsPath);
2634
+ const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, sources.projectSettingsPath);
2635
+ const applyDefaults = (agents: AgentConfig[]): AgentConfig[] => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions);
2636
+ const builtin = applyBuiltinOverrides(applyDefaults(sources.builtinLoaded.agents), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2637
+ const user = applyCustomAgentOverrides(
2638
+ applyDefaults(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.agents)),
1846
2639
  userSettings,
1847
2640
  projectSettings,
1848
- userSettingsPath,
1849
- projectSettingsPath,
2641
+ sources.userSettingsPath,
2642
+ sources.projectSettingsPath,
1850
2643
  );
1851
2644
  const projectMap = new Map<string, AgentConfig>();
1852
- for (const dir of projectDirs) {
1853
- for (const agent of loadAgentsFromDir(dir, "project")) {
1854
- projectMap.set(agent.name, agent);
1855
- }
2645
+ if (scope !== "user") for (const loaded of sources.projectLoaded) for (const agent of loaded.loaded.agents) projectMap.set(agent.name, agent);
2646
+ const project = applyCustomAgentOverrides(applyDefaults(Array.from(projectMap.values())), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2647
+ const packageMap = new Map<string, AgentConfig>();
2648
+ for (const loaded of sources.packageLoaded) {
2649
+ if (!loaded.packageEntry || !packageEntryIncluded(scope, loaded.packageEntry.scope)) continue;
2650
+ for (const agent of loaded.loaded.agents) if (!packageMap.has(agent.name)) packageMap.set(agent.name, agent);
1856
2651
  }
1857
- const project = applyCustomAgentOverrides(
1858
- applySubagentDefaults(Array.from(projectMap.values()), defaultModel, defaultThinking, defaultExtensions),
2652
+ const packageAgents = applyCustomAgentOverrides(applyDefaults(Array.from(packageMap.values())), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
2653
+ return {
2654
+ builtin,
2655
+ package: packageAgents,
2656
+ user,
2657
+ project,
1859
2658
  userSettings,
1860
2659
  projectSettings,
1861
- userSettingsPath,
1862
- projectSettingsPath,
2660
+ maxThinking,
2661
+ modelScope: projectSettings.modelScope ?? userSettings.modelScope,
2662
+ };
2663
+ }
2664
+
2665
+ function discoveryDirectories(sources: AgentDiscoverySources, scope: AgentScope): AgentDefinitionDirectoryReport[] {
2666
+ const directories: AgentDefinitionDirectoryReport[] = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
2667
+ if (scope !== "project") for (const directory of sources.userLoaded) directories.push(reportAgentDefinitionDirectory("user", directory.dir, directory.inspection));
2668
+ if (scope !== "user") for (const dir of sources.projectCandidateDirs) directories.push(reportAgentDefinitionDirectory("project", dir, sources.projectInspections.get(dir)!));
2669
+ for (const directory of sources.packageLoaded) {
2670
+ if (directory.packageEntry && packageEntryIncluded(scope, directory.packageEntry.scope)) directories.push(reportAgentDefinitionDirectory("package", directory.dir, directory.inspection));
2671
+ }
2672
+ return directories;
2673
+ }
2674
+
2675
+ function discoveryDiagnostics(sources: AgentDiscoverySources, scope: AgentScope): AgentDiscoveryDiagnostic[] {
2676
+ return [
2677
+ ...sources.builtinLoaded.diagnostics,
2678
+ ...(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.diagnostics)),
2679
+ ...(scope === "user" ? [] : sources.projectLoaded.flatMap((loaded) => loaded.loaded.diagnostics)),
2680
+ ...sources.packageLoaded
2681
+ .filter((loaded) => loaded.packageEntry && packageEntryIncluded(scope, loaded.packageEntry.scope))
2682
+ .flatMap((loaded) => loaded.loaded.diagnostics),
2683
+ ];
2684
+ }
2685
+
2686
+ function buildEffectiveDiscovery(sources: AgentDiscoverySources, scope: AgentScope): AgentDiscoveryResult {
2687
+ const configured = configuredAgentsForScope(sources, scope);
2688
+ const agents = applySubagentMaxThinking(
2689
+ mergeAgentsForScope(scope, configured.user, configured.project, configured.builtin, configured.package).filter((agent) => agent.disabled !== true),
2690
+ configured.maxThinking,
1863
2691
  );
2692
+ return {
2693
+ agents,
2694
+ agentDiagnostics: discoveryDiagnostics(sources, scope),
2695
+ projectAgentsDir: sources.projectAgentsDir,
2696
+ cwd: sources.cwd,
2697
+ scope,
2698
+ directories: discoveryDirectories(sources, scope),
2699
+ ...(configured.modelScope !== undefined ? { modelScope: configured.modelScope } : {}),
2700
+ ...(configured.maxThinking !== undefined ? { maxThinking: configured.maxThinking } : {}),
2701
+ };
2702
+ }
1864
2703
 
1865
- const chainMap = new Map<string, ChainConfig>();
1866
- const packageChainDiagnostics: ChainDiscoveryDiagnostic[] = [];
2704
+ function buildAllDiscovery(sources: AgentDiscoverySources, includeChains: boolean, settingsScope: AgentScope): AgentDiscoveryAllResult {
2705
+ if (includeChains) ensureDiscoveryChains(sources);
2706
+ const configured = configuredAgentsForScope(sources, "both", settingsScope);
1867
2707
  const packageChainMap = new Map<string, ChainConfig>();
1868
- for (const dir of packageSubagentPaths.chains) {
1869
- const loaded = loadChainsFromDir(dir, "package");
1870
- packageChainDiagnostics.push(...loaded.diagnostics);
1871
- for (const chain of loaded.chains) {
1872
- if (!packageChainMap.has(chain.name)) packageChainMap.set(chain.name, chain);
1873
- }
2708
+ const packageChainDiagnostics: ChainDiscoveryDiagnostic[] = [];
2709
+ for (const chain of sources.packageChainLoaded ?? []) {
2710
+ packageChainDiagnostics.push(...chain.loaded.diagnostics);
2711
+ for (const definition of chain.loaded.chains) if (!packageChainMap.has(definition.name)) packageChainMap.set(definition.name, definition);
1874
2712
  }
2713
+ const projectChainMap = new Map<string, ChainConfig>();
1875
2714
  const projectChainDiagnostics: ChainDiscoveryDiagnostic[] = [];
1876
- for (const dir of projectChainDirs) {
1877
- const loaded = loadChainsFromDir(dir, "project");
1878
- projectChainDiagnostics.push(...loaded.diagnostics);
1879
- for (const chain of loaded.chains) {
1880
- chainMap.set(chain.name, chain);
1881
- }
2715
+ for (const chain of sources.projectChainLoaded ?? []) {
2716
+ projectChainDiagnostics.push(...chain.loaded.diagnostics);
2717
+ for (const definition of chain.loaded.chains) projectChainMap.set(definition.name, definition);
1882
2718
  }
1883
- const userChains = loadChainsFromDir(userChainDir, "user");
1884
2719
  const chains = [
1885
2720
  ...Array.from(packageChainMap.values()),
1886
- ...userChains.chains,
1887
- ...Array.from(chainMap.values()),
1888
- ];
1889
- const chainDiagnostics = [
1890
- ...packageChainDiagnostics,
1891
- ...userChains.diagnostics,
1892
- ...projectChainDiagnostics,
2721
+ ...(sources.userChains?.chains ?? []),
2722
+ ...Array.from(projectChainMap.values()),
1893
2723
  ];
2724
+ return {
2725
+ builtin: applySubagentMaxThinking(configured.builtin, configured.maxThinking),
2726
+ package: applySubagentMaxThinking(configured.package, configured.maxThinking),
2727
+ user: applySubagentMaxThinking(configured.user, configured.maxThinking),
2728
+ project: applySubagentMaxThinking(configured.project, configured.maxThinking),
2729
+ agentDiagnostics: [
2730
+ ...sources.builtinLoaded.diagnostics,
2731
+ ...sources.userLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
2732
+ ...sources.packageLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
2733
+ ...sources.projectLoaded.flatMap((loaded) => loaded.loaded.diagnostics),
2734
+ ],
2735
+ chains,
2736
+ chainDiagnostics: [...packageChainDiagnostics, ...(sources.userChains?.diagnostics ?? []), ...projectChainDiagnostics],
2737
+ userDir: sources.userDir,
2738
+ projectDir: sources.projectAgentsDir,
2739
+ userChainDir: sources.userChainDir,
2740
+ projectChainDir: sources.projectChainDir,
2741
+ userSettingsPath: sources.userSettingsPath,
2742
+ projectSettingsPath: sources.projectSettingsPath,
2743
+ ...(configured.maxThinking !== undefined ? { maxThinking: configured.maxThinking } : {}),
2744
+ };
2745
+ }
1894
2746
 
1895
- const userDir = process.env.PI_CODING_AGENT_DIR ? userDirOld : fs.existsSync(userDirNew) ? userDirNew : userDirOld;
2747
+ export function discoverAgentSnapshot(
2748
+ cwd: string,
2749
+ scope: AgentScope,
2750
+ preferredModelProvider?: string,
2751
+ options: { includeChains?: boolean } = {},
2752
+ ): AgentDiscoverySnapshot {
2753
+ const includeChains = options.includeChains !== false;
2754
+ const sources = getAgentDiscoverySources(cwd, preferredModelProvider, includeChains);
2755
+ return { effective: buildEffectiveDiscovery(sources, scope), all: buildAllDiscovery(sources, includeChains, scope) };
2756
+ }
2757
+
2758
+ function discoverAgentsUncached(cwd: string, scope: AgentScope, preferredModelProvider?: string): AgentDiscoveryResult {
2759
+ const effectiveCwd = path.resolve(cwd);
2760
+ const userDirOld = path.join(getAgentDir(), "agents");
2761
+ const userDirNew = path.join(os.homedir(), ".agents");
2762
+ const { readDirs: projectAgentDirs, candidateDirs: projectCandidateDirs, preferredDir: projectAgentsDir } = resolveNearestProjectAgentDirs(effectiveCwd);
2763
+ const userSettingsPath = getUserAgentSettingsPath();
2764
+ const projectSettingsPath = getProjectAgentSettingsPath(effectiveCwd);
2765
+ const userSettings = selectProviderOverrides(scope === "project" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(userSettingsPath), preferredModelProvider);
2766
+ const projectSettings = selectProviderOverrides(scope === "user" ? EMPTY_SUBAGENT_SETTINGS : readSubagentSettings(projectSettingsPath), preferredModelProvider);
2767
+ const defaultProvider = resolveSubagentDefaultProvider(userSettings, projectSettings, projectSettingsPath);
2768
+ const defaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath, defaultProvider);
2769
+ const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
2770
+ const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
2771
+ const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
2772
+ const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
2773
+ const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd, { includeUser: scope !== "project", includeProject: scope !== "user" });
2774
+ const directories: AgentDefinitionDirectoryReport[] = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
2775
+ const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
2776
+ const builtinAgents = applyBuiltinOverrides(applySubagentDefaults(builtinLoaded.agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2777
+ const userLoaded = scope === "project" ? [] : [...extraUserAgentDirs(), userDirOld, userDirNew].map((dir, discoveryPriority) => {
2778
+ const inspection = inspectAgentDefinitionDirectory(dir);
2779
+ directories.push(reportAgentDefinitionDirectory("user", dir, inspection));
2780
+ return loadAgentsFromDir(dir, "user", discoveryPriority, undefined, inspection);
2781
+ });
2782
+ const userAgents = applyCustomAgentOverrides(applySubagentDefaults(userLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultProvider, defaultThinking, defaultExtensions), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2783
+ const projectInspections = scope === "user" ? new Map<string, AgentDefinitionInspection>() : new Map(projectCandidateDirs.map((dir) => [dir, inspectAgentDefinitionDirectory(dir)]));
2784
+ if (scope !== "user") for (const dir of projectCandidateDirs) directories.push(reportAgentDefinitionDirectory("project", dir, projectInspections.get(dir)!));
2785
+ const projectLoaded = scope === "user" ? [] : projectAgentDirs.map((dir) => loadAgentsFromDir(dir, "project", dir === projectAgentsDir ? 1 : 0, undefined, projectInspections.get(dir)!));
2786
+ const projectAgents = applyCustomAgentOverrides(applySubagentDefaults(projectLoaded.flatMap((loaded) => loaded.agents), defaultModel, defaultProvider, defaultThinking, defaultExtensions), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2787
+ const packageLoaded = packageSubagentPaths.agents.map((entry, index) => {
2788
+ const inspection = inspectAgentDefinitionDirectory(entry.dir);
2789
+ directories.push(reportAgentDefinitionDirectory("package", entry.dir, inspection));
2790
+ return loadAgentsFromDir(entry.dir, "package", packageSubagentPaths.agents.length - index, entry, inspection);
2791
+ });
2792
+ const packageMap = new Map<string, AgentConfig>();
2793
+ for (const loaded of packageLoaded) for (const agent of loaded.agents) if (!packageMap.has(agent.name)) packageMap.set(agent.name, agent);
2794
+ const packageAgents = applyCustomAgentOverrides(applySubagentDefaults(Array.from(packageMap.values()), defaultModel, defaultProvider, defaultThinking, defaultExtensions), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
2795
+ const agents = applySubagentMaxThinking(mergeAgentsForScope(scope, userAgents, projectAgents, builtinAgents, packageAgents).filter((agent) => agent.disabled !== true), maxThinking);
2796
+ const agentDiagnostics = [...builtinLoaded.diagnostics, ...userLoaded.flatMap((loaded) => loaded.diagnostics), ...projectLoaded.flatMap((loaded) => loaded.diagnostics), ...packageLoaded.flatMap((loaded) => loaded.diagnostics)];
2797
+ return { agents, agentDiagnostics, projectAgentsDir, cwd: effectiveCwd, scope, directories, ...(modelScope !== undefined ? { modelScope } : {}), ...(maxThinking !== undefined ? { maxThinking } : {}) };
2798
+ }
2799
+
2800
+ export function discoverAgents(cwd: string, scope: AgentScope, preferredModelProvider?: string): AgentDiscoveryResult {
2801
+ if (scope !== "both") return discoverAgentsUncached(cwd, scope, preferredModelProvider);
2802
+ const sources = getAgentDiscoverySources(cwd, preferredModelProvider);
2803
+ return buildEffectiveDiscovery(sources, scope);
2804
+ }
1896
2805
 
1897
- return { builtin, package: packageAgents, user, project, chains, chainDiagnostics, userDir, projectDir, userChainDir, projectChainDir, userSettingsPath, projectSettingsPath };
2806
+ export function discoverAgentsAll(cwd: string, preferredModelProvider?: string): AgentDiscoveryAllResult {
2807
+ return discoverAgentSnapshot(cwd, "both", preferredModelProvider).all;
1898
2808
  }