@ashx-j/lunr 0.2.11 → 0.2.13

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 (342) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +211 -236
  3. package/dist/builtin-extensions/ashxj-tui.d.ts +3 -0
  4. package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
  5. package/dist/builtin-extensions/ashxj-tui.js +28 -11
  6. package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
  7. package/dist/builtin-extensions/index.d.ts.map +1 -1
  8. package/dist/builtin-extensions/index.js +0 -2
  9. package/dist/builtin-extensions/index.js.map +1 -1
  10. package/dist/builtin-extensions/lunr-cron.d.ts +1 -1
  11. package/dist/builtin-extensions/lunr-cron.d.ts.map +1 -1
  12. package/dist/builtin-extensions/lunr-cron.js +1 -1
  13. package/dist/builtin-extensions/lunr-cron.js.map +1 -1
  14. package/dist/builtin-extensions/pi-subagents/src/extension/chain-validation.d.ts.map +1 -1
  15. package/dist/builtin-extensions/pi-subagents/src/extension/chain-validation.js +3 -3
  16. package/dist/builtin-extensions/pi-subagents/src/extension/chain-validation.js.map +1 -1
  17. package/dist/builtin-extensions/pi-subagents/src/extension/doctor.d.ts +0 -2
  18. package/dist/builtin-extensions/pi-subagents/src/extension/doctor.d.ts.map +1 -1
  19. package/dist/builtin-extensions/pi-subagents/src/extension/doctor.js +1 -23
  20. package/dist/builtin-extensions/pi-subagents/src/extension/doctor.js.map +1 -1
  21. package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.d.ts.map +1 -1
  22. package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js +6 -7
  23. package/dist/builtin-extensions/pi-subagents/src/extension/fanout-child.js.map +1 -1
  24. package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts +1 -1
  25. package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
  26. package/dist/builtin-extensions/pi-subagents/src/extension/index.js +7 -14
  27. package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
  28. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts +12 -9
  29. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.d.ts.map +1 -1
  30. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js +38 -34
  31. package/dist/builtin-extensions/pi-subagents/src/extension/schemas.js.map +1 -1
  32. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts +3 -3
  33. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.d.ts.map +1 -1
  34. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js +32 -47
  35. package/dist/builtin-extensions/pi-subagents/src/extension/tool-description.js.map +1 -1
  36. package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts +2 -2
  37. package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.d.ts.map +1 -1
  38. package/dist/builtin-extensions/pi-subagents/src/intercom/intercom-bridge.js.map +1 -1
  39. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts +7 -10
  40. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.d.ts.map +1 -1
  41. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js +90 -109
  42. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-execution.js.map +1 -1
  43. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.d.ts +3 -2
  44. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.d.ts.map +1 -1
  45. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.js +37 -50
  46. package/dist/builtin-extensions/pi-subagents/src/runs/background/async-resume.js.map +1 -1
  47. package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.d.ts.map +1 -1
  48. package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.js +1 -1
  49. package/dist/builtin-extensions/pi-subagents/src/runs/background/run-status.js.map +1 -1
  50. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.d.ts +4 -0
  51. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.d.ts.map +1 -1
  52. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.js +5 -5
  53. package/dist/builtin-extensions/pi-subagents/src/runs/background/scheduled-runs.js.map +1 -1
  54. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
  55. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +31 -13
  56. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
  57. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.d.ts +2 -2
  58. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.d.ts.map +1 -1
  59. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-clarify.js.map +1 -1
  60. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts +4 -3
  61. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
  62. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +48 -20
  63. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
  64. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts +2 -2
  65. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
  66. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +90 -64
  67. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
  68. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts +6 -8
  69. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
  70. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +262 -161
  71. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
  72. package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.d.ts +2 -1
  73. package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.d.ts.map +1 -1
  74. package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.js +24 -33
  75. package/dist/builtin-extensions/pi-subagents/src/runs/shared/acceptance.js.map +1 -1
  76. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts +25 -0
  77. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.d.ts.map +1 -0
  78. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js +51 -0
  79. package/dist/builtin-extensions/pi-subagents/src/runs/shared/child-tools.js.map +1 -0
  80. package/dist/builtin-extensions/pi-subagents/src/runs/shared/dynamic-fanout.d.ts.map +1 -1
  81. package/dist/builtin-extensions/pi-subagents/src/runs/shared/dynamic-fanout.js +20 -3
  82. package/dist/builtin-extensions/pi-subagents/src/runs/shared/dynamic-fanout.js.map +1 -1
  83. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts +4 -1
  84. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts.map +1 -1
  85. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.js.map +1 -1
  86. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts +5 -0
  87. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.d.ts.map +1 -1
  88. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js +9 -3
  89. package/dist/builtin-extensions/pi-subagents/src/runs/shared/pi-args.js.map +1 -1
  90. package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.d.ts.map +1 -1
  91. package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js +2 -2
  92. package/dist/builtin-extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.js.map +1 -1
  93. package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.d.ts +2 -2
  94. package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.d.ts.map +1 -1
  95. package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.js +20 -17
  96. package/dist/builtin-extensions/pi-subagents/src/runs/shared/task-intent.js.map +1 -1
  97. package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts +70 -0
  98. package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.d.ts.map +1 -0
  99. package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js +153 -0
  100. package/dist/builtin-extensions/pi-subagents/src/shared/child-spec.js.map +1 -0
  101. package/dist/builtin-extensions/pi-subagents/src/shared/settings.d.ts +13 -8
  102. package/dist/builtin-extensions/pi-subagents/src/shared/settings.d.ts.map +1 -1
  103. package/dist/builtin-extensions/pi-subagents/src/shared/settings.js +20 -51
  104. package/dist/builtin-extensions/pi-subagents/src/shared/settings.js.map +1 -1
  105. package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +80 -20
  106. package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
  107. package/dist/builtin-extensions/pi-subagents/src/shared/types.js +10 -2
  108. package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
  109. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts +2 -2
  110. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts.map +1 -1
  111. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js +20 -32
  112. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js.map +1 -1
  113. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts +2 -1
  114. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
  115. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +23 -449
  116. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
  117. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +2 -1
  118. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
  119. package/dist/builtin-extensions/pi-subagents/src/tui/render.js +13 -11
  120. package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
  121. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.d.ts +2 -1
  122. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.d.ts.map +1 -1
  123. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.js +18 -17
  124. package/dist/builtin-extensions/pi-subagents/src/watchdog/runtime.js.map +1 -1
  125. package/dist/builtin-extensions/simple-pi-memory.d.ts +2 -2
  126. package/dist/builtin-extensions/simple-pi-memory.d.ts.map +1 -1
  127. package/dist/builtin-extensions/simple-pi-memory.js +41 -17
  128. package/dist/builtin-extensions/simple-pi-memory.js.map +1 -1
  129. package/dist/catalog/models.json +1 -1
  130. package/dist/catalog/providers/amazon-bedrock.json +1 -1
  131. package/dist/catalog/providers/azure-openai-responses.json +1 -1
  132. package/dist/catalog/providers/cloudflare-ai-gateway.json +1 -1
  133. package/dist/catalog/providers/cloudflare-workers-ai.json +1 -1
  134. package/dist/catalog/providers/fireworks.json +1 -1
  135. package/dist/catalog/providers/github-copilot.json +1 -1
  136. package/dist/catalog/providers/huggingface.json +1 -1
  137. package/dist/catalog/providers/minimax-cn.json +1 -1
  138. package/dist/catalog/providers/minimax.json +1 -1
  139. package/dist/catalog/providers/mistral.json +1 -1
  140. package/dist/catalog/providers/nvidia.json +1 -1
  141. package/dist/catalog/providers/openai.json +1 -1
  142. package/dist/catalog/providers/opencode-go.json +1 -1
  143. package/dist/catalog/providers/opencode.json +1 -1
  144. package/dist/catalog/providers/openrouter.json +1 -1
  145. package/dist/catalog/providers/qwen-cloud-cn.json +1 -1
  146. package/dist/catalog/providers/qwen-cloud.json +1 -1
  147. package/dist/catalog/providers/qwen-token-plan-cn.json +1 -1
  148. package/dist/catalog/providers/qwen-token-plan.json +1 -1
  149. package/dist/catalog/providers/together.json +1 -1
  150. package/dist/catalog/providers/vercel-ai-gateway.json +1 -1
  151. package/dist/catalog/providers/zai-coding-cn.json +1 -1
  152. package/dist/catalog/providers/zai.json +1 -1
  153. package/dist/catalog/publication.json +3 -3
  154. package/dist/core/agent-session.d.ts +7 -1
  155. package/dist/core/agent-session.d.ts.map +1 -1
  156. package/dist/core/agent-session.js +34 -4
  157. package/dist/core/agent-session.js.map +1 -1
  158. package/dist/core/context-breakdown.d.ts +3 -1
  159. package/dist/core/context-breakdown.d.ts.map +1 -1
  160. package/dist/core/context-breakdown.js +5 -2
  161. package/dist/core/context-breakdown.js.map +1 -1
  162. package/dist/core/customize.d.ts +2 -0
  163. package/dist/core/customize.d.ts.map +1 -1
  164. package/dist/core/customize.js +6 -0
  165. package/dist/core/customize.js.map +1 -1
  166. package/dist/core/memory-cap.d.ts +4 -8
  167. package/dist/core/memory-cap.d.ts.map +1 -1
  168. package/dist/core/memory-cap.js +8 -8
  169. package/dist/core/memory-cap.js.map +1 -1
  170. package/dist/core/permissions.d.ts +2 -0
  171. package/dist/core/permissions.d.ts.map +1 -1
  172. package/dist/core/permissions.js +30 -14
  173. package/dist/core/permissions.js.map +1 -1
  174. package/dist/core/plan-mode.d.ts.map +1 -1
  175. package/dist/core/plan-mode.js +1 -9
  176. package/dist/core/plan-mode.js.map +1 -1
  177. package/dist/core/rollback.d.ts.map +1 -1
  178. package/dist/core/rollback.js +1 -1
  179. package/dist/core/rollback.js.map +1 -1
  180. package/dist/core/settings-manager.d.ts +16 -5
  181. package/dist/core/settings-manager.d.ts.map +1 -1
  182. package/dist/core/settings-manager.js +37 -10
  183. package/dist/core/settings-manager.js.map +1 -1
  184. package/dist/core/slash-commands.d.ts.map +1 -1
  185. package/dist/core/slash-commands.js +1 -5
  186. package/dist/core/slash-commands.js.map +1 -1
  187. package/dist/core/subagent-permission-inherit.d.ts +34 -22
  188. package/dist/core/subagent-permission-inherit.d.ts.map +1 -1
  189. package/dist/core/subagent-permission-inherit.js +37 -80
  190. package/dist/core/subagent-permission-inherit.js.map +1 -1
  191. package/dist/core/swarm.d.ts.map +1 -1
  192. package/dist/core/swarm.js +13 -7
  193. package/dist/core/swarm.js.map +1 -1
  194. package/dist/core/system-prompt.d.ts +6 -4
  195. package/dist/core/system-prompt.d.ts.map +1 -1
  196. package/dist/core/system-prompt.js +38 -48
  197. package/dist/core/system-prompt.js.map +1 -1
  198. package/dist/core/usage-adapters/openai-codex.d.ts +1 -1
  199. package/dist/core/usage-adapters/openai-codex.d.ts.map +1 -1
  200. package/dist/core/usage-adapters/openai-codex.js +22 -17
  201. package/dist/core/usage-adapters/openai-codex.js.map +1 -1
  202. package/dist/core/usage-service.d.ts +10 -1
  203. package/dist/core/usage-service.d.ts.map +1 -1
  204. package/dist/core/usage-service.js +17 -6
  205. package/dist/core/usage-service.js.map +1 -1
  206. package/dist/gateway/agent-bridge.d.ts.map +1 -1
  207. package/dist/gateway/agent-bridge.js +1 -4
  208. package/dist/gateway/agent-bridge.js.map +1 -1
  209. package/dist/gateway/cron.d.ts.map +1 -1
  210. package/dist/gateway/cron.js +1 -4
  211. package/dist/gateway/cron.js.map +1 -1
  212. package/dist/index.d.ts +1 -1
  213. package/dist/index.d.ts.map +1 -1
  214. package/dist/index.js.map +1 -1
  215. package/dist/main.d.ts.map +1 -1
  216. package/dist/main.js +0 -5
  217. package/dist/main.js.map +1 -1
  218. package/dist/migrations.d.ts +2 -0
  219. package/dist/migrations.d.ts.map +1 -1
  220. package/dist/migrations.js +21 -0
  221. package/dist/migrations.js.map +1 -1
  222. package/dist/modes/interactive/components/settings-selector.d.ts +7 -4
  223. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  224. package/dist/modes/interactive/components/settings-selector.js +122 -162
  225. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  226. package/dist/modes/interactive/components/usage-view.d.ts +1 -1
  227. package/dist/modes/interactive/components/usage-view.d.ts.map +1 -1
  228. package/dist/modes/interactive/components/usage-view.js +7 -4
  229. package/dist/modes/interactive/components/usage-view.js.map +1 -1
  230. package/dist/modes/interactive/interactive-mode.d.ts +1 -2
  231. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  232. package/dist/modes/interactive/interactive-mode.js +55 -96
  233. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  234. package/dist/modes/interactive/skill-tag-autocomplete.d.ts +13 -0
  235. package/dist/modes/interactive/skill-tag-autocomplete.d.ts.map +1 -0
  236. package/dist/modes/interactive/skill-tag-autocomplete.js +72 -0
  237. package/dist/modes/interactive/skill-tag-autocomplete.js.map +1 -0
  238. package/docs/compaction.md +23 -23
  239. package/docs/containerization.md +24 -24
  240. package/docs/custom-provider.md +18 -18
  241. package/docs/development.md +16 -15
  242. package/docs/docs.json +6 -2
  243. package/docs/extensions.md +82 -80
  244. package/docs/features.md +102 -0
  245. package/docs/index.md +25 -19
  246. package/docs/json.md +7 -7
  247. package/docs/keybindings.md +4 -4
  248. package/docs/models.md +2 -2
  249. package/docs/packages.md +38 -42
  250. package/docs/prompt-templates.md +4 -4
  251. package/docs/providers.md +22 -10
  252. package/docs/quickstart.md +81 -46
  253. package/docs/rpc.md +7 -13
  254. package/docs/sdk.md +43 -41
  255. package/docs/security.md +18 -18
  256. package/docs/session-format.md +9 -9
  257. package/docs/sessions.md +13 -12
  258. package/docs/settings.md +63 -24
  259. package/docs/shell-aliases.md +2 -2
  260. package/docs/skills.md +21 -11
  261. package/docs/terminal-setup.md +5 -5
  262. package/docs/termux.md +7 -7
  263. package/docs/themes.md +12 -14
  264. package/docs/tmux.md +4 -4
  265. package/docs/tui.md +23 -23
  266. package/docs/usage.md +112 -87
  267. package/docs/windows.md +10 -2
  268. package/examples/README.md +3 -1
  269. package/examples/extensions/README.md +6 -6
  270. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  271. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  272. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  273. package/examples/extensions/doom-overlay/README.md +2 -2
  274. package/examples/extensions/gondolin/package-lock.json +2 -2
  275. package/examples/extensions/gondolin/package.json +1 -1
  276. package/examples/extensions/plan-mode/README.md +3 -1
  277. package/examples/extensions/sandbox/package-lock.json +2 -2
  278. package/examples/extensions/sandbox/package.json +1 -1
  279. package/examples/extensions/subagent/README.md +13 -11
  280. package/examples/extensions/todo.ts +2 -1
  281. package/examples/extensions/with-deps/package-lock.json +2 -2
  282. package/examples/extensions/with-deps/package.json +1 -1
  283. package/examples/sdk/README.md +9 -5
  284. package/package.json +6 -7
  285. package/dist/builtin-extensions/lunr-behavior.d.ts +0 -44
  286. package/dist/builtin-extensions/lunr-behavior.d.ts.map +0 -1
  287. package/dist/builtin-extensions/lunr-behavior.js +0 -213
  288. package/dist/builtin-extensions/lunr-behavior.js.map +0 -1
  289. package/dist/builtin-extensions/pi-subagents/agents/context-builder.md +0 -46
  290. package/dist/builtin-extensions/pi-subagents/agents/deep-researcher.md +0 -36
  291. package/dist/builtin-extensions/pi-subagents/agents/delegate.md +0 -12
  292. package/dist/builtin-extensions/pi-subagents/agents/oracle.md +0 -73
  293. package/dist/builtin-extensions/pi-subagents/agents/planner.md +0 -55
  294. package/dist/builtin-extensions/pi-subagents/agents/research-writer.md +0 -37
  295. package/dist/builtin-extensions/pi-subagents/agents/researcher.md +0 -52
  296. package/dist/builtin-extensions/pi-subagents/agents/reviewer.md +0 -79
  297. package/dist/builtin-extensions/pi-subagents/agents/scout.md +0 -50
  298. package/dist/builtin-extensions/pi-subagents/agents/worker.md +0 -55
  299. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.d.ts +0 -20
  300. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.d.ts.map +0 -1
  301. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.js +0 -1273
  302. package/dist/builtin-extensions/pi-subagents/src/agents/agent-management.js.map +0 -1
  303. package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.d.ts +0 -49
  304. package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.d.ts.map +0 -1
  305. package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.js +0 -252
  306. package/dist/builtin-extensions/pi-subagents/src/agents/agent-memory.js.map +0 -1
  307. package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.d.ts +0 -3
  308. package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.d.ts.map +0 -1
  309. package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.js +0 -6
  310. package/dist/builtin-extensions/pi-subagents/src/agents/agent-scope.js.map +0 -1
  311. package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.d.ts +0 -3
  312. package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.d.ts.map +0 -1
  313. package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.js +0 -23
  314. package/dist/builtin-extensions/pi-subagents/src/agents/agent-selection.js.map +0 -1
  315. package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.d.ts +0 -8
  316. package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.d.ts.map +0 -1
  317. package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.js +0 -143
  318. package/dist/builtin-extensions/pi-subagents/src/agents/agent-serializer.js.map +0 -1
  319. package/dist/builtin-extensions/pi-subagents/src/agents/agents.d.ts +0 -176
  320. package/dist/builtin-extensions/pi-subagents/src/agents/agents.d.ts.map +0 -1
  321. package/dist/builtin-extensions/pi-subagents/src/agents/agents.js +0 -1326
  322. package/dist/builtin-extensions/pi-subagents/src/agents/agents.js.map +0 -1
  323. package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.d.ts +0 -7
  324. package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.d.ts.map +0 -1
  325. package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.js +0 -307
  326. package/dist/builtin-extensions/pi-subagents/src/agents/chain-serializer.js.map +0 -1
  327. package/dist/builtin-extensions/pi-subagents/src/agents/identity.d.ts +0 -8
  328. package/dist/builtin-extensions/pi-subagents/src/agents/identity.d.ts.map +0 -1
  329. package/dist/builtin-extensions/pi-subagents/src/agents/identity.js +0 -30
  330. package/dist/builtin-extensions/pi-subagents/src/agents/identity.js.map +0 -1
  331. package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.d.ts +0 -35
  332. package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.d.ts.map +0 -1
  333. package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.js +0 -151
  334. package/dist/builtin-extensions/pi-subagents/src/agents/proactive-skills.js.map +0 -1
  335. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.d.ts +0 -131
  336. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.d.ts.map +0 -1
  337. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.js +0 -491
  338. package/dist/builtin-extensions/pi-subagents/src/profiles/profiles.js.map +0 -1
  339. package/dist/core/behavior-preset.d.ts +0 -60
  340. package/dist/core/behavior-preset.d.ts.map +0 -1
  341. package/dist/core/behavior-preset.js +0 -257
  342. package/dist/core/behavior-preset.js.map +0 -1
@@ -1,1273 +0,0 @@
1
- // @ts-nocheck
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import { BUILTIN_AGENT_NAMES, defaultInheritProjectContext, defaultInheritSkills, defaultSystemPromptMode, discoverAgentsAll, buildRuntimeName, frontmatterNameForConfig, parsePackageName, mergeBuiltinAgentOverride, removeBuiltinAgentOverride, removeBuiltinAgentOverrideFields, } from "./agents.js";
5
- import { serializeAgent } from "./agent-serializer.js";
6
- import { advertisedDefaultContext } from "../shared/lunr-child-context.js";
7
- import { mergeAgentsForScope } from "./agent-selection.js";
8
- import { serializeChain, serializeJsonChain } from "./chain-serializer.js";
9
- import { discoverAvailableSkills, resolveSkills } from "./skills.js";
10
- import { buildProactiveSkillSubagentRecommendationLines, } from "./proactive-skills.js";
11
- import { parseFrontmatter } from "./frontmatter.js";
12
- import { toModelInfo } from "../shared/model-info.js";
13
- import { resolveSubagentModelOverride } from "../runs/shared/model-fallback.js";
14
- import { validateToolBudgetConfig } from "../runs/shared/tool-budget.js";
15
- import { resolveTurnBudgetConfig } from "../runs/shared/turn-budget.js";
16
- import { validateAcceptanceInput } from "../runs/shared/acceptance.js";
17
- import { getProjectConfigDir } from "../shared/utils.js";
18
- function result(text, isError = false) {
19
- return { content: [{ type: "text", text }], isError, details: { mode: "management", results: [] } };
20
- }
21
- function parseCsv(value) {
22
- return [...new Set(value.split(",").map((v) => v.trim()).filter(Boolean))];
23
- }
24
- function configObject(config) {
25
- let val = config;
26
- if (typeof val === "string") {
27
- try {
28
- val = JSON.parse(val);
29
- }
30
- catch (error) {
31
- const message = error instanceof Error ? error.message : String(error);
32
- return { error: `config must be valid JSON: ${message}` };
33
- }
34
- }
35
- if (!val || typeof val !== "object" || Array.isArray(val))
36
- return {};
37
- return { value: val };
38
- }
39
- function hasKey(obj, key) {
40
- return Object.prototype.hasOwnProperty.call(obj, key);
41
- }
42
- function asDisambiguationScope(scope) {
43
- if (scope === "user" || scope === "project")
44
- return scope;
45
- return undefined;
46
- }
47
- function actionScope(scope, action) {
48
- if (scope === undefined)
49
- return { scope: "user" };
50
- const parsed = asDisambiguationScope(scope);
51
- return parsed ? { scope: parsed } : { error: result(`agentScope must be 'user' or 'project' for ${action}.`, true) };
52
- }
53
- function normalizeListScope(scope) {
54
- if (scope === undefined)
55
- return "both";
56
- if (scope === "user" || scope === "project" || scope === "both")
57
- return scope;
58
- return undefined;
59
- }
60
- function sanitizeName(name) {
61
- return name.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
62
- }
63
- function parsePackageConfig(value) {
64
- return parsePackageName(value, "config.package");
65
- }
66
- function allAgents(d) {
67
- return [...d.builtin, ...d.package, ...d.user, ...d.project];
68
- }
69
- function availableNames(cwd, kind) {
70
- const d = discoverAgentsAll(cwd);
71
- const items = kind === "agent" ? allAgents(d) : d.chains;
72
- return [...new Set(items.map((x) => x.name))].sort((a, b) => a.localeCompare(b));
73
- }
74
- function findAgents(name, cwd, scope = "both") {
75
- const d = discoverAgentsAll(cwd);
76
- const raw = name.trim();
77
- const sanitized = sanitizeName(raw);
78
- return allAgents(d)
79
- .filter((a) => (scope === "both" || a.source === scope) && (a.name === raw || a.name === sanitized))
80
- .sort((a, b) => a.source.localeCompare(b.source));
81
- }
82
- function findChains(name, cwd, scope = "both") {
83
- const raw = name.trim();
84
- const sanitized = sanitizeName(raw);
85
- return discoverAgentsAll(cwd).chains
86
- .filter((c) => (scope === "both" || c.source === scope) && (c.name === raw || c.name === sanitized))
87
- .sort((a, b) => a.source.localeCompare(b.source));
88
- }
89
- const AGENT_SOURCE_PRECEDENCE = { builtin: 0, package: 1, user: 2, project: 3 };
90
- // Returns the highest-precedence agent for a name (project > user > package > builtin,
91
- // matching mergeAgentsForScope for "both"), including disabled agents so disable/enable/reset
92
- // can locate agents that runtime discovery filters out.
93
- function pickEffectiveAgent(d, name) {
94
- const raw = name.trim();
95
- const sanitized = sanitizeName(raw);
96
- const matches = allAgents(d).filter((a) => a.name === raw || a.name === sanitized);
97
- if (matches.length === 0)
98
- return undefined;
99
- return matches.reduce((best, agent) => (AGENT_SOURCE_PRECEDENCE[agent.source] > AGENT_SOURCE_PRECEDENCE[best.source] ? agent : best));
100
- }
101
- function nameExistsInScope(cwd, scope, name, excludePath) {
102
- const d = discoverAgentsAll(cwd);
103
- for (const a of scope === "user" ? d.user : d.project) {
104
- if (a.name === name && a.filePath !== excludePath)
105
- return true;
106
- }
107
- for (const c of d.chains) {
108
- if (c.source === scope && c.name === name && c.filePath !== excludePath)
109
- return true;
110
- }
111
- return false;
112
- }
113
- function isMutableSource(source) {
114
- return source === "user" || source === "project";
115
- }
116
- function unknownChainAgents(cwd, steps) {
117
- const d = discoverAgentsAll(cwd);
118
- const known = new Set(allAgents(d).map((a) => a.name));
119
- return [...new Set(steps.map((s) => s.agent).filter((a) => !known.has(a)))].sort((a, b) => a.localeCompare(b));
120
- }
121
- function chainStepWarnings(ctx, steps) {
122
- const warnings = [];
123
- const available = new Set(discoverAvailableSkills(ctx.cwd).map((s) => s.name));
124
- for (let i = 0; i < steps.length; i++) {
125
- const s = steps[i];
126
- if (s.model) {
127
- const found = ctx.modelRegistry.getAvailable().some((m) => `${m.provider}/${m.id}` === s.model || m.id === s.model);
128
- if (!found)
129
- warnings.push(`Warning: step ${i + 1} (${s.agent}): model '${s.model}' is not in the current model registry.`);
130
- }
131
- if (Array.isArray(s.skills) && s.skills.length > 0) {
132
- const missing = s.skills.filter((sk) => !available.has(sk));
133
- if (missing.length)
134
- warnings.push(`Warning: step ${i + 1} (${s.agent}): skills not found: ${missing.join(", ")}.`);
135
- }
136
- }
137
- return warnings;
138
- }
139
- function modelWarning(ctx, model) {
140
- if (!model)
141
- return undefined;
142
- const found = ctx.modelRegistry.getAvailable().some((m) => `${m.provider}/${m.id}` === model || m.id === model);
143
- return found ? undefined : `Warning: model '${model}' is not in the current model registry.`;
144
- }
145
- function fallbackModelsWarning(ctx, fallbackModels) {
146
- if (!fallbackModels || fallbackModels.length === 0)
147
- return undefined;
148
- const available = new Set(ctx.modelRegistry.getAvailable().flatMap((m) => [`${m.provider}/${m.id}`, m.id]));
149
- const missing = fallbackModels.filter((model) => !available.has(model));
150
- return missing.length ? `Warning: fallback models not in the current model registry: ${missing.join(", ")}.` : undefined;
151
- }
152
- function skillsWarning(cwd, agent) {
153
- if (!agent.skills?.length)
154
- return undefined;
155
- const { missing } = resolveSkills(agent.skills, cwd, agent.skillPath, agent.filePath ? path.dirname(agent.filePath) : cwd);
156
- return missing.length ? `Warning: skills not found: ${missing.join(", ")}.` : undefined;
157
- }
158
- function editableAgentConfig(agent) {
159
- const base = agent.override?.base;
160
- if (!base)
161
- return { ...agent };
162
- return {
163
- ...agent,
164
- model: base.model,
165
- fallbackModels: base.fallbackModels ? [...base.fallbackModels] : undefined,
166
- thinking: base.thinking,
167
- systemPromptMode: base.systemPromptMode,
168
- inheritProjectContext: base.inheritProjectContext,
169
- inheritSkills: base.inheritSkills,
170
- defaultContext: base.defaultContext,
171
- acceptanceRole: base.acceptanceRole,
172
- disabled: base.disabled,
173
- systemPrompt: base.systemPrompt,
174
- skills: base.skills ? [...base.skills] : undefined,
175
- skillPath: base.skillPath ? [...base.skillPath] : undefined,
176
- tools: base.tools ? [...base.tools] : undefined,
177
- mcpDirectTools: base.mcpDirectTools ? [...base.mcpDirectTools] : undefined,
178
- subagentOnlyExtensions: base.subagentOnlyExtensions ? [...base.subagentOnlyExtensions] : undefined,
179
- completionGuard: base.completionGuard,
180
- override: undefined,
181
- };
182
- }
183
- function readAgentFrontmatterFields(filePath) {
184
- try {
185
- const { frontmatter } = parseFrontmatter(fs.readFileSync(filePath, "utf-8"));
186
- return new Set(Object.keys(frontmatter));
187
- }
188
- catch {
189
- return new Set();
190
- }
191
- }
192
- function preservedAgentFrontmatterFields(agent, cfg) {
193
- const fields = readAgentFrontmatterFields(agent.filePath);
194
- const changed = (...names) => {
195
- for (const name of names)
196
- fields.delete(name);
197
- };
198
- if (hasKey(cfg, "name"))
199
- changed("name");
200
- if (hasKey(cfg, "package"))
201
- changed("package");
202
- if (hasKey(cfg, "description"))
203
- changed("description");
204
- if (hasKey(cfg, "systemPrompt"))
205
- changed("systemPrompt");
206
- if (hasKey(cfg, "model"))
207
- changed("model");
208
- if (hasKey(cfg, "fallbackModels"))
209
- changed("fallbackModels");
210
- if (hasKey(cfg, "tools"))
211
- changed("tools");
212
- if (hasKey(cfg, "skills"))
213
- changed("skill", "skills");
214
- if (hasKey(cfg, "skillPath"))
215
- changed("skillPath");
216
- if (hasKey(cfg, "extensions"))
217
- changed("extensions");
218
- if (hasKey(cfg, "subagentOnlyExtensions"))
219
- changed("subagentOnlyExtensions");
220
- if (hasKey(cfg, "thinking")) {
221
- changed("thinking");
222
- if (cfg.thinking === "off")
223
- fields.add("thinking");
224
- }
225
- if (hasKey(cfg, "systemPromptMode")) {
226
- changed("systemPromptMode");
227
- fields.add("systemPromptMode");
228
- }
229
- if (hasKey(cfg, "inheritProjectContext")) {
230
- changed("inheritProjectContext");
231
- fields.add("inheritProjectContext");
232
- }
233
- if (hasKey(cfg, "inheritSkills")) {
234
- changed("inheritSkills");
235
- fields.add("inheritSkills");
236
- }
237
- if (hasKey(cfg, "defaultContext"))
238
- changed("defaultContext");
239
- if (hasKey(cfg, "async"))
240
- changed("async");
241
- if (hasKey(cfg, "timeoutMs"))
242
- changed("timeoutMs");
243
- if (hasKey(cfg, "turnBudget"))
244
- changed("turnBudget");
245
- if (hasKey(cfg, "acceptance"))
246
- changed("acceptance");
247
- if (hasKey(cfg, "acceptanceRole"))
248
- changed("acceptanceRole");
249
- if (hasKey(cfg, "output"))
250
- changed("output");
251
- if (hasKey(cfg, "reads"))
252
- changed("defaultReads");
253
- if (hasKey(cfg, "progress"))
254
- changed("defaultProgress");
255
- if (hasKey(cfg, "maxSubagentDepth"))
256
- changed("maxSubagentDepth");
257
- if (hasKey(cfg, "completionGuard")) {
258
- changed("completionGuard");
259
- if (cfg.completionGuard === true)
260
- fields.add("completionGuard");
261
- }
262
- if (hasKey(cfg, "toolBudget"))
263
- changed("toolBudget");
264
- return fields;
265
- }
266
- function parseStepList(raw) {
267
- if (!Array.isArray(raw))
268
- return { error: "config.steps must be an array." };
269
- if (raw.length === 0)
270
- return { error: "config.steps must include at least one step." };
271
- const steps = [];
272
- for (let i = 0; i < raw.length; i++) {
273
- const item = raw[i];
274
- if (!item || typeof item !== "object" || Array.isArray(item))
275
- return { error: `config.steps[${i}] must be an object.` };
276
- const s = item;
277
- if (typeof s.agent !== "string" || !s.agent.trim())
278
- return { error: `config.steps[${i}].agent must be a non-empty string.` };
279
- const step = { agent: s.agent.trim(), task: typeof s.task === "string" ? s.task : "" };
280
- if (hasKey(s, "phase")) {
281
- if (typeof s.phase === "string")
282
- step.phase = s.phase;
283
- else
284
- return { error: `config.steps[${i}].phase must be a string.` };
285
- }
286
- if (hasKey(s, "label")) {
287
- if (typeof s.label === "string")
288
- step.label = s.label;
289
- else
290
- return { error: `config.steps[${i}].label must be a string.` };
291
- }
292
- if (hasKey(s, "as")) {
293
- if (typeof s.as === "string")
294
- step.as = s.as;
295
- else
296
- return { error: `config.steps[${i}].as must be a string.` };
297
- }
298
- if (hasKey(s, "outputSchema")) {
299
- if (typeof s.outputSchema === "string")
300
- step.outputSchema = s.outputSchema;
301
- else
302
- return { error: `config.steps[${i}].outputSchema must be a schema file path string for saved chains.` };
303
- }
304
- if (hasKey(s, "output")) {
305
- if (s.output === false)
306
- step.output = false;
307
- else if (typeof s.output === "string")
308
- step.output = s.output;
309
- else
310
- return { error: `config.steps[${i}].output must be a string or false.` };
311
- }
312
- if (hasKey(s, "outputMode")) {
313
- if (s.outputMode === "inline" || s.outputMode === "file-only")
314
- step.outputMode = s.outputMode;
315
- else
316
- return { error: `config.steps[${i}].outputMode must be 'inline' or 'file-only'.` };
317
- }
318
- if (hasKey(s, "reads")) {
319
- if (s.reads === false)
320
- step.reads = false;
321
- else if (Array.isArray(s.reads))
322
- step.reads = s.reads.filter((v) => typeof v === "string").map((v) => v.trim()).filter(Boolean);
323
- else
324
- return { error: `config.steps[${i}].reads must be an array or false.` };
325
- }
326
- if (hasKey(s, "model")) {
327
- if (typeof s.model === "string")
328
- step.model = s.model;
329
- else
330
- return { error: `config.steps[${i}].model must be a string.` };
331
- }
332
- if (hasKey(s, "skills")) {
333
- if (s.skills === false)
334
- step.skills = false;
335
- else if (Array.isArray(s.skills))
336
- step.skills = s.skills.filter((v) => typeof v === "string").map((v) => v.trim()).filter(Boolean);
337
- else
338
- return { error: `config.steps[${i}].skills must be an array or false.` };
339
- }
340
- if (hasKey(s, "progress")) {
341
- if (typeof s.progress === "boolean")
342
- step.progress = s.progress;
343
- else
344
- return { error: `config.steps[${i}].progress must be a boolean.` };
345
- }
346
- if (hasKey(s, "toolBudget")) {
347
- const validation = validateToolBudgetConfig(s.toolBudget, `config.steps[${i}].toolBudget`);
348
- if (validation.error)
349
- return { error: validation.error };
350
- step.toolBudget = s.toolBudget;
351
- }
352
- steps.push(step);
353
- }
354
- return { steps };
355
- }
356
- function parseTools(raw) {
357
- const tools = [];
358
- const mcpDirectTools = [];
359
- for (const item of parseCsv(raw)) {
360
- if (item.startsWith("mcp:")) {
361
- const direct = item.slice(4).trim();
362
- if (direct)
363
- mcpDirectTools.push(direct);
364
- }
365
- else
366
- tools.push(item);
367
- }
368
- return { tools: tools.length ? tools : undefined, mcpDirectTools: mcpDirectTools.length ? mcpDirectTools : undefined };
369
- }
370
- function applyAgentConfig(target, cfg) {
371
- if (hasKey(cfg, "systemPrompt")) {
372
- if (cfg.systemPrompt === false || cfg.systemPrompt === "")
373
- target.systemPrompt = "";
374
- else if (typeof cfg.systemPrompt === "string")
375
- target.systemPrompt = cfg.systemPrompt;
376
- else
377
- return "config.systemPrompt must be a string or false when provided.";
378
- }
379
- if (hasKey(cfg, "model")) {
380
- if (cfg.model === false || cfg.model === "")
381
- target.model = undefined;
382
- else if (typeof cfg.model === "string")
383
- target.model = cfg.model.trim() || undefined;
384
- else
385
- return "config.model must be a string or false when provided.";
386
- }
387
- if (hasKey(cfg, "fallbackModels")) {
388
- if (cfg.fallbackModels === false || cfg.fallbackModels === "")
389
- target.fallbackModels = undefined;
390
- else if (typeof cfg.fallbackModels === "string") {
391
- const models = parseCsv(cfg.fallbackModels);
392
- target.fallbackModels = models.length ? models : undefined;
393
- }
394
- else if (Array.isArray(cfg.fallbackModels)) {
395
- const models = cfg.fallbackModels
396
- .filter((value) => typeof value === "string")
397
- .map((value) => value.trim())
398
- .filter(Boolean);
399
- target.fallbackModels = models.length ? [...new Set(models)] : undefined;
400
- }
401
- else
402
- return "config.fallbackModels must be a comma-separated string, string array, or false when provided.";
403
- }
404
- if (hasKey(cfg, "tools")) {
405
- if (cfg.tools === false || cfg.tools === "") {
406
- target.tools = undefined;
407
- target.mcpDirectTools = undefined;
408
- }
409
- else if (typeof cfg.tools === "string") {
410
- const parsed = parseTools(cfg.tools);
411
- target.tools = parsed.tools;
412
- target.mcpDirectTools = parsed.mcpDirectTools;
413
- }
414
- else
415
- return "config.tools must be a comma-separated string or false when provided.";
416
- }
417
- if (hasKey(cfg, "skills")) {
418
- if (cfg.skills === false || cfg.skills === "")
419
- target.skills = undefined;
420
- else if (typeof cfg.skills === "string") {
421
- const skills = parseCsv(cfg.skills);
422
- target.skills = skills.length ? skills : undefined;
423
- }
424
- else
425
- return "config.skills must be a comma-separated string or false when provided.";
426
- }
427
- if (hasKey(cfg, "skillPath")) {
428
- if (cfg.skillPath === false || cfg.skillPath === "")
429
- target.skillPath = undefined;
430
- else if (typeof cfg.skillPath === "string") {
431
- const skillPath = parseCsv(cfg.skillPath);
432
- target.skillPath = skillPath.length ? skillPath : undefined;
433
- }
434
- else if (Array.isArray(cfg.skillPath) && cfg.skillPath.every((entry) => typeof entry === "string")) {
435
- const skillPath = [...new Set(cfg.skillPath.map((entry) => entry.trim()).filter(Boolean))];
436
- target.skillPath = skillPath.length ? skillPath : undefined;
437
- }
438
- else
439
- return "config.skillPath must be a comma-separated string, string array, or false when provided.";
440
- }
441
- if (hasKey(cfg, "extensions")) {
442
- if (cfg.extensions === false)
443
- target.extensions = undefined;
444
- else if (cfg.extensions === "")
445
- target.extensions = [];
446
- else if (typeof cfg.extensions === "string")
447
- target.extensions = parseCsv(cfg.extensions);
448
- else
449
- return "config.extensions must be a comma-separated string, empty string, or false when provided.";
450
- }
451
- if (hasKey(cfg, "subagentOnlyExtensions")) {
452
- if (cfg.subagentOnlyExtensions === false)
453
- target.subagentOnlyExtensions = undefined;
454
- else if (cfg.subagentOnlyExtensions === "")
455
- target.subagentOnlyExtensions = [];
456
- else if (typeof cfg.subagentOnlyExtensions === "string")
457
- target.subagentOnlyExtensions = parseCsv(cfg.subagentOnlyExtensions);
458
- else
459
- return "config.subagentOnlyExtensions must be a comma-separated string, empty string, or false when provided.";
460
- }
461
- if (hasKey(cfg, "thinking")) {
462
- if (cfg.thinking === false || cfg.thinking === "")
463
- target.thinking = undefined;
464
- else if (typeof cfg.thinking === "string")
465
- target.thinking = cfg.thinking.trim() || undefined;
466
- else
467
- return "config.thinking must be a string or false when provided.";
468
- }
469
- if (hasKey(cfg, "systemPromptMode")) {
470
- if (cfg.systemPromptMode === "append" || cfg.systemPromptMode === "replace")
471
- target.systemPromptMode = cfg.systemPromptMode;
472
- else
473
- return "config.systemPromptMode must be 'append' or 'replace' when provided.";
474
- }
475
- if (hasKey(cfg, "inheritProjectContext")) {
476
- if (typeof cfg.inheritProjectContext !== "boolean")
477
- return "config.inheritProjectContext must be a boolean when provided.";
478
- target.inheritProjectContext = cfg.inheritProjectContext;
479
- }
480
- if (hasKey(cfg, "inheritSkills")) {
481
- if (typeof cfg.inheritSkills !== "boolean")
482
- return "config.inheritSkills must be a boolean when provided.";
483
- target.inheritSkills = cfg.inheritSkills;
484
- }
485
- if (hasKey(cfg, "defaultContext")) {
486
- if (cfg.defaultContext === false || cfg.defaultContext === "")
487
- target.defaultContext = undefined;
488
- else if (cfg.defaultContext === "fresh" || cfg.defaultContext === "fork")
489
- target.defaultContext = cfg.defaultContext;
490
- else
491
- return "config.defaultContext must be 'fresh', 'fork', or false when provided.";
492
- }
493
- if (hasKey(cfg, "async")) {
494
- if (cfg.async === "")
495
- target.defaultAsync = undefined;
496
- else if (typeof cfg.async === "boolean")
497
- target.defaultAsync = cfg.async;
498
- else
499
- return "config.async must be a boolean or empty string when provided.";
500
- }
501
- if (hasKey(cfg, "timeoutMs")) {
502
- if (cfg.timeoutMs === false || cfg.timeoutMs === "")
503
- target.defaultTimeoutMs = undefined;
504
- else if (typeof cfg.timeoutMs === "number" && Number.isInteger(cfg.timeoutMs) && cfg.timeoutMs > 0)
505
- target.defaultTimeoutMs = cfg.timeoutMs;
506
- else
507
- return "config.timeoutMs must be a positive integer or false when provided.";
508
- }
509
- if (hasKey(cfg, "turnBudget")) {
510
- if (cfg.turnBudget === false || cfg.turnBudget === "")
511
- target.defaultTurnBudget = undefined;
512
- else {
513
- const resolved = resolveTurnBudgetConfig(cfg.turnBudget, "config.turnBudget");
514
- if (resolved.error)
515
- return resolved.error;
516
- target.defaultTurnBudget = resolved.turnBudget;
517
- }
518
- }
519
- if (hasKey(cfg, "acceptance")) {
520
- if (cfg.acceptance === "")
521
- target.defaultAcceptance = undefined;
522
- else {
523
- const errors = validateAcceptanceInput(cfg.acceptance, "config.acceptance");
524
- if (errors.length > 0)
525
- return errors.join(" ");
526
- target.defaultAcceptance = cfg.acceptance;
527
- }
528
- }
529
- if (hasKey(cfg, "acceptanceRole")) {
530
- if (cfg.acceptanceRole === false || cfg.acceptanceRole === "")
531
- target.acceptanceRole = undefined;
532
- else if (cfg.acceptanceRole === "read-only" || cfg.acceptanceRole === "writer")
533
- target.acceptanceRole = cfg.acceptanceRole;
534
- else
535
- return "config.acceptanceRole must be 'read-only', 'writer', or false when provided.";
536
- }
537
- if (hasKey(cfg, "output")) {
538
- if (cfg.output === false || cfg.output === "")
539
- target.output = undefined;
540
- else if (typeof cfg.output === "string")
541
- target.output = cfg.output;
542
- else
543
- return "config.output must be a string or false when provided.";
544
- }
545
- if (hasKey(cfg, "reads")) {
546
- if (cfg.reads === false || cfg.reads === "")
547
- target.defaultReads = undefined;
548
- else if (typeof cfg.reads === "string") {
549
- const reads = parseCsv(cfg.reads);
550
- target.defaultReads = reads.length ? reads : undefined;
551
- }
552
- else
553
- return "config.reads must be a comma-separated string or false when provided.";
554
- }
555
- if (hasKey(cfg, "progress")) {
556
- if (typeof cfg.progress !== "boolean")
557
- return "config.progress must be a boolean when provided.";
558
- target.defaultProgress = cfg.progress;
559
- }
560
- if (hasKey(cfg, "maxSubagentDepth")) {
561
- if (cfg.maxSubagentDepth === false || cfg.maxSubagentDepth === "")
562
- target.maxSubagentDepth = undefined;
563
- else if (typeof cfg.maxSubagentDepth === "number" && Number.isInteger(cfg.maxSubagentDepth) && cfg.maxSubagentDepth >= 0) {
564
- target.maxSubagentDepth = cfg.maxSubagentDepth;
565
- }
566
- else
567
- return "config.maxSubagentDepth must be an integer >= 0 or false when provided.";
568
- }
569
- if (hasKey(cfg, "completionGuard")) {
570
- if (typeof cfg.completionGuard !== "boolean")
571
- return "config.completionGuard must be a boolean when provided.";
572
- target.completionGuard = cfg.completionGuard;
573
- }
574
- if (hasKey(cfg, "toolBudget")) {
575
- if (cfg.toolBudget === false || cfg.toolBudget === "")
576
- target.toolBudget = undefined;
577
- else {
578
- const validation = validateToolBudgetConfig(cfg.toolBudget, "config.toolBudget");
579
- if (validation.error)
580
- return validation.error;
581
- target.toolBudget = cfg.toolBudget;
582
- }
583
- }
584
- return undefined;
585
- }
586
- function resolveTarget(kind, name, matches, cwd, scopeHint) {
587
- const mutable = matches.filter((m) => isMutableSource(m.source));
588
- if (mutable.length === 0) {
589
- if (matches.length > 0) {
590
- return result(`${kind === "agent" ? "Agent" : "Chain"} '${name}' is read-only and cannot be modified. Create a same-named ${kind} in user or project scope to override it.`, true);
591
- }
592
- const available = availableNames(cwd, kind);
593
- return result(`${kind === "agent" ? "Agent" : "Chain"} '${name}' not found. Available: ${available.join(", ") || "none"}.`, true);
594
- }
595
- if (mutable.length === 1)
596
- return mutable[0];
597
- const scope = asDisambiguationScope(scopeHint);
598
- if (!scope) {
599
- const paths = mutable.map((m) => `${m.source}: ${m.filePath}`).join("\n");
600
- return result(`${kind === "agent" ? "Agent" : "Chain"} '${name}' exists in both scopes. Specify agentScope: 'user' or 'project'.\n${paths}`, true);
601
- }
602
- const scoped = mutable.filter((m) => m.source === scope);
603
- if (scoped.length === 0)
604
- return result(`${kind === "agent" ? "Agent" : "Chain"} '${name}' not found in scope '${scope}'.`, true);
605
- if (scoped.length > 1)
606
- return result(`Multiple ${kind}s named '${name}' found in scope '${scope}': ${scoped.map((m) => m.filePath).join(", ")}`, true);
607
- return scoped[0];
608
- }
609
- function renamePath(kind, currentPath, newName, scope, cwd) {
610
- if (nameExistsInScope(cwd, scope, newName, currentPath))
611
- return { error: `Name '${newName}' already exists in ${scope} scope.` };
612
- const ext = kind === "agent" ? ".md" : currentPath.endsWith(".chain.json") ? ".chain.json" : ".chain.md";
613
- const filePath = path.join(path.dirname(currentPath), `${newName}${ext}`);
614
- if (fs.existsSync(filePath) && filePath !== currentPath) {
615
- return { error: `File already exists at ${filePath} but is not a valid ${kind} definition. Remove or rename it first.` };
616
- }
617
- fs.renameSync(currentPath, filePath);
618
- return { filePath };
619
- }
620
- function formatAgentDetail(agent) {
621
- const tools = [...(agent.tools ?? []), ...(agent.mcpDirectTools ?? []).map((t) => `mcp:${t}`)];
622
- const lines = [`Agent: ${agent.name} (${agent.source})`, `Path: ${agent.filePath}`, `Description: ${agent.description}`];
623
- if (agent.packageName) {
624
- lines.push(`Local name: ${frontmatterNameForConfig(agent)}`);
625
- lines.push(`Package: ${agent.packageName}`);
626
- }
627
- if (agent.model)
628
- lines.push(`Model: ${agent.model}`);
629
- if (agent.fallbackModels?.length)
630
- lines.push(`Fallback models: ${agent.fallbackModels.join(", ")}`);
631
- if (tools.length)
632
- lines.push(`Tools: ${tools.join(", ")}`);
633
- if (agent.skills?.length)
634
- lines.push(`Skills: ${agent.skills.join(", ")}`);
635
- if (agent.skillPath?.length)
636
- lines.push(`Skill paths: ${agent.skillPath.join(", ")}`);
637
- lines.push(`System prompt mode: ${agent.systemPromptMode}`);
638
- lines.push(`Inherit project context: ${agent.inheritProjectContext ? "true" : "false"}`);
639
- lines.push(`Inherit skills: ${agent.inheritSkills ? "true" : "false"}`);
640
- lines.push(`Default context: ${advertisedDefaultContext(agent.defaultContext)}`);
641
- if (agent.defaultAsync !== undefined)
642
- lines.push(`Async: ${agent.defaultAsync ? "true" : "false"}`);
643
- if (agent.defaultTimeoutMs !== undefined)
644
- lines.push(`Timeout: ${agent.defaultTimeoutMs}ms`);
645
- if (agent.defaultTurnBudget)
646
- lines.push(`Turn budget: ${JSON.stringify(agent.defaultTurnBudget)}`);
647
- if (agent.defaultAcceptance !== undefined)
648
- lines.push(`Acceptance: ${typeof agent.defaultAcceptance === "object" ? JSON.stringify(agent.defaultAcceptance) : String(agent.defaultAcceptance)}`);
649
- if (agent.acceptanceRole)
650
- lines.push(`Acceptance role: ${agent.acceptanceRole}`);
651
- if (agent.source === "builtin")
652
- lines.push(`Disabled: ${agent.disabled ? "true" : "false"}`);
653
- if (agent.extensions !== undefined)
654
- lines.push(`Extensions: ${agent.extensions.length ? agent.extensions.join(", ") : "(none)"}`);
655
- if (agent.subagentOnlyExtensions !== undefined)
656
- lines.push(`Subagent-only extensions: ${agent.subagentOnlyExtensions.length ? agent.subagentOnlyExtensions.join(", ") : "(none)"}`);
657
- if (agent.thinking)
658
- lines.push(`Thinking: ${agent.thinking}`);
659
- if (agent.output)
660
- lines.push(`Output: ${agent.output}`);
661
- if (agent.defaultReads?.length)
662
- lines.push(`Reads: ${agent.defaultReads.join(", ")}`);
663
- if (agent.defaultProgress)
664
- lines.push("Progress: true");
665
- if (agent.maxSubagentDepth !== undefined)
666
- lines.push(`Max subagent depth: ${agent.maxSubagentDepth}`);
667
- if (agent.completionGuard === false)
668
- lines.push("Completion guard: false");
669
- if (agent.toolBudget)
670
- lines.push(`Tool budget: ${JSON.stringify(agent.toolBudget)}`);
671
- if (agent.memory)
672
- lines.push(`Memory: ${agent.memory.scope} scope, path: ${agent.memory.path}`);
673
- if (agent.systemPrompt.trim())
674
- lines.push("", "System Prompt:", agent.systemPrompt);
675
- return lines.join("\n");
676
- }
677
- function formatChainStepDetail(step, index) {
678
- const lines = [];
679
- if (step.expand || step.collect) {
680
- const parallel = step.parallel && !Array.isArray(step.parallel) && typeof step.parallel === "object" ? step.parallel : undefined;
681
- const expand = step.expand && typeof step.expand === "object" ? step.expand : undefined;
682
- const collect = step.collect && typeof step.collect === "object" ? step.collect : undefined;
683
- lines.push(`${index + 1}. Dynamic fanout${typeof collect?.as === "string" ? ` -> ${collect.as}` : ""}`);
684
- if (expand?.from)
685
- lines.push(` Expand: ${String(expand.from.output ?? "?")}${String(expand.from.path ?? "")}`);
686
- if (typeof expand?.item === "string")
687
- lines.push(` Item variable: ${expand.item}`);
688
- if (typeof expand?.key === "string")
689
- lines.push(` Key: ${expand.key}`);
690
- if (typeof expand?.maxItems === "number")
691
- lines.push(` Max items: ${expand.maxItems}`);
692
- if (typeof expand?.onEmpty === "string")
693
- lines.push(` On empty: ${expand.onEmpty}`);
694
- if (parallel?.agent)
695
- lines.push(` Agent: ${String(parallel.agent)}`);
696
- if (typeof parallel?.label === "string")
697
- lines.push(` Label: ${parallel.label}`);
698
- if (typeof parallel?.task === "string" && parallel.task.trim())
699
- lines.push(` Task: ${parallel.task}`);
700
- if (parallel?.outputSchema)
701
- lines.push(" Structured output: true");
702
- if (parallel && "toolBudget" in parallel)
703
- lines.push(` Tool budget: ${JSON.stringify(parallel.toolBudget)}`);
704
- if (collect?.outputSchema)
705
- lines.push(" Collect schema: true");
706
- if (step.concurrency !== undefined)
707
- lines.push(` Concurrency: ${step.concurrency}`);
708
- if (step.failFast !== undefined)
709
- lines.push(` Fail fast: ${step.failFast ? "true" : "false"}`);
710
- return lines;
711
- }
712
- lines.push(`${index + 1}. ${step.agent}`);
713
- if (step.task?.trim())
714
- lines.push(` Task: ${step.task}`);
715
- if (step.output === false)
716
- lines.push(" Output: false");
717
- else if (step.output)
718
- lines.push(` Output: ${step.output}`);
719
- if (step.outputMode)
720
- lines.push(` Output mode: ${step.outputMode}`);
721
- if (step.toolBudget)
722
- lines.push(` Tool budget: ${JSON.stringify(step.toolBudget)}`);
723
- if (step.reads === false)
724
- lines.push(" Reads: false");
725
- else if (Array.isArray(step.reads) && step.reads.length > 0)
726
- lines.push(` Reads: ${step.reads.join(", ")}`);
727
- if (step.model)
728
- lines.push(` Model: ${step.model}`);
729
- if (step.skills === false)
730
- lines.push(" Skills: false");
731
- else if (Array.isArray(step.skills) && step.skills.length > 0)
732
- lines.push(` Skills: ${step.skills.join(", ")}`);
733
- if (step.progress !== undefined)
734
- lines.push(` Progress: ${step.progress ? "true" : "false"}`);
735
- return lines;
736
- }
737
- function formatChainDetail(chain) {
738
- const lines = [`Chain: ${chain.name} (${chain.source})`, `Path: ${chain.filePath}`, `Description: ${chain.description}`];
739
- if (chain.packageName) {
740
- lines.push(`Local name: ${frontmatterNameForConfig(chain)}`);
741
- lines.push(`Package: ${chain.packageName}`);
742
- }
743
- lines.push("", "Steps:");
744
- for (let i = 0; i < chain.steps.length; i++) {
745
- lines.push(...formatChainStepDetail(chain.steps[i], i));
746
- }
747
- return lines.join("\n");
748
- }
749
- export function handleList(params, ctx) {
750
- const scope = normalizeListScope(params.agentScope) ?? "both";
751
- const d = discoverAgentsAll(ctx.cwd);
752
- const scopedAgents = mergeAgentsForScope(scope, d.user, d.project, d.builtin, d.package)
753
- .sort((a, b) => a.name.localeCompare(b.name));
754
- const agents = scopedAgents.filter((a) => !a.disabled);
755
- const chains = d.chains.filter((c) => scope === "both" || c.source === "package" || c.source === scope).sort((a, b) => a.name.localeCompare(b.name));
756
- const diagnostics = d.chainDiagnostics.filter((entry) => scope === "both" || entry.source === scope);
757
- const proactiveSuggestions = buildProactiveSkillSubagentRecommendationLines({
758
- agents,
759
- chains,
760
- config: ctx.config?.proactiveSkillSubagents,
761
- discoverAvailableSkills: () => discoverAvailableSkills(ctx.cwd),
762
- });
763
- const lines = [
764
- "Executable agents:",
765
- ...(agents.length
766
- ? agents.map((a) => `- ${a.name} (${a.source}, context: ${advertisedDefaultContext(a.defaultContext)}): ${a.description}`)
767
- : ["- (none)"]),
768
- "",
769
- "Chains:",
770
- ...(chains.length ? chains.map((c) => `- ${c.name} (${c.source}): ${c.description}`) : ["- (none)"]),
771
- ...(proactiveSuggestions.length ? ["", ...proactiveSuggestions] : []),
772
- ...(diagnostics.length ? ["", "Chain diagnostics:", ...diagnostics.map((entry) => `- ${entry.filePath}: ${entry.error}`)] : []),
773
- ];
774
- return result(lines.join("\n"));
775
- }
776
- function formatModelSource(agent, currentModel) {
777
- if (agent.override && agent.model !== agent.override.base.model) {
778
- return `${agent.override.scope} override`;
779
- }
780
- if (agent.modelSource?.type === "subagents.defaultModel" && agent.model === agent.modelSource.model) {
781
- return `${agent.modelSource.scope} defaultModel`;
782
- }
783
- if (agent.model)
784
- return "builtin agent config";
785
- if (currentModel)
786
- return "inherits current session model";
787
- return "inherit requested, but no current session model is available";
788
- }
789
- function handleModels(params, ctx) {
790
- const requestedAgent = params.agent?.trim();
791
- if (requestedAgent && !BUILTIN_AGENT_NAMES.includes(requestedAgent)) {
792
- return result(`Builtin agent '${requestedAgent}' not found. Available: ${BUILTIN_AGENT_NAMES.join(", ")}.`, true);
793
- }
794
- const discovered = discoverAgentsAll(ctx.cwd);
795
- const builtinByName = new Map(discovered.builtin.map((agent) => [agent.name, agent]));
796
- const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
797
- const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined;
798
- const preferredProvider = ctx.model?.provider;
799
- const names = requestedAgent ? [requestedAgent] : [...BUILTIN_AGENT_NAMES];
800
- if (requestedAgent) {
801
- const agent = builtinByName.get(requestedAgent);
802
- if (!agent)
803
- return result(`Builtin agent '${requestedAgent}' not found.`, true);
804
- const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, preferredProvider);
805
- const lines = [
806
- "Builtin subagent model",
807
- "",
808
- `Agent: ${requestedAgent}`,
809
- "Effective model:",
810
- ` ${resolvedModel ?? "(unresolved)"}`,
811
- `Source: ${formatModelSource(agent, currentModel)}`,
812
- ];
813
- if (agent.override) {
814
- lines.push("Override file:");
815
- lines.push(` ${agent.override.path}`);
816
- }
817
- if (agent.model && resolvedModel && agent.model !== resolvedModel) {
818
- lines.push("Requested model setting:");
819
- lines.push(` ${agent.model}`);
820
- }
821
- if (agent.disabled)
822
- lines.push("Disabled: true");
823
- lines.push("Current session model:");
824
- lines.push(` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`);
825
- return result(lines.join("\n"));
826
- }
827
- const lines = [
828
- "Builtin subagent models",
829
- "",
830
- "Current session model:",
831
- ` ${currentModel ? `${currentModel.provider}/${currentModel.id}` : "(unavailable)"}`,
832
- "",
833
- ];
834
- for (const name of names) {
835
- const agent = builtinByName.get(name);
836
- if (!agent) {
837
- lines.push(name);
838
- lines.push(" model:");
839
- lines.push(" (builtin definition not found)");
840
- lines.push(" source: missing");
841
- lines.push("");
842
- continue;
843
- }
844
- const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, preferredProvider);
845
- const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}`;
846
- lines.push(name);
847
- lines.push(" model:");
848
- lines.push(` ${resolvedModel ?? "(unresolved)"}`);
849
- lines.push(` source: ${source}`);
850
- lines.push("");
851
- }
852
- return result(lines.join("\n"));
853
- }
854
- function handleGet(params, ctx) {
855
- if (!params.agent && !params.chainName)
856
- return result("Specify 'agent' or 'chainName' for get.", true);
857
- const hasBoth = Boolean(params.agent && params.chainName);
858
- const blocks = [];
859
- let anyFound = false;
860
- if (params.agent) {
861
- const matches = findAgents(params.agent, ctx.cwd, "both");
862
- if (!matches.length) {
863
- const msg = `Agent '${params.agent}' not found. Available: ${availableNames(ctx.cwd, "agent").join(", ") || "none"}.`;
864
- if (!hasBoth)
865
- return result(msg, true);
866
- blocks.push(msg);
867
- }
868
- else {
869
- anyFound = true;
870
- blocks.push(...matches.map(formatAgentDetail));
871
- }
872
- }
873
- if (params.chainName) {
874
- const matches = findChains(params.chainName, ctx.cwd, "both");
875
- if (!matches.length) {
876
- const msg = `Chain '${params.chainName}' not found. Available: ${availableNames(ctx.cwd, "chain").join(", ") || "none"}.`;
877
- if (!hasBoth)
878
- return result(msg, true);
879
- blocks.push(msg);
880
- }
881
- else {
882
- anyFound = true;
883
- blocks.push(...matches.map(formatChainDetail));
884
- }
885
- }
886
- return result(blocks.join("\n\n"), !anyFound);
887
- }
888
- export function handleCreate(params, ctx) {
889
- const parsedConfig = configObject(params.config);
890
- if (parsedConfig.error)
891
- return result(parsedConfig.error, true);
892
- const cfg = parsedConfig.value;
893
- if (!cfg)
894
- return result("config required for create.", true);
895
- if (typeof cfg.name !== "string" || !cfg.name.trim())
896
- return result("config.name is required and must be a non-empty string.", true);
897
- if (typeof cfg.description !== "string" || !cfg.description.trim())
898
- return result("config.description is required and must be a non-empty string.", true);
899
- const name = sanitizeName(cfg.name);
900
- if (!name)
901
- return result("config.name is invalid after sanitization. Use letters, numbers, spaces, or hyphens.", true);
902
- const parsedPackage = parsePackageConfig(cfg.package);
903
- if (parsedPackage.error)
904
- return result(parsedPackage.error, true);
905
- const runtimeName = buildRuntimeName(name, parsedPackage.packageName);
906
- const scopeRaw = cfg.scope ?? "user";
907
- if (scopeRaw !== "user" && scopeRaw !== "project")
908
- return result("config.scope must be 'user' or 'project'.", true);
909
- const scope = scopeRaw;
910
- const isChain = hasKey(cfg, "steps");
911
- const d = discoverAgentsAll(ctx.cwd);
912
- const projectConfigDir = getProjectConfigDir(ctx.cwd);
913
- const targetDir = isChain
914
- ? scope === "user" ? d.userChainDir : d.projectChainDir ?? path.join(projectConfigDir, "chains")
915
- : scope === "user" ? d.userDir : d.projectDir ?? path.join(projectConfigDir, "agents");
916
- fs.mkdirSync(targetDir, { recursive: true });
917
- if (nameExistsInScope(ctx.cwd, scope, runtimeName))
918
- return result(`Name '${runtimeName}' already exists in ${scope} scope. Use update instead.`, true);
919
- const targetPath = path.join(targetDir, isChain ? `${runtimeName}.chain.md` : `${runtimeName}.md`);
920
- if (fs.existsSync(targetPath))
921
- return result(`File already exists at ${targetPath} but is not a valid ${isChain ? "chain" : "agent"} definition. Remove or rename it first.`, true);
922
- const warnings = [];
923
- if (!isChain && d.builtin.some((a) => a.name === runtimeName))
924
- warnings.push(`Note: this shadows the builtin agent '${runtimeName}'.`);
925
- if (isChain) {
926
- const parsed = parseStepList(cfg.steps);
927
- if (parsed.error)
928
- return result(parsed.error, true);
929
- const chain = { name: runtimeName, localName: name, packageName: parsedPackage.packageName, description: cfg.description.trim(), source: scope, filePath: targetPath, steps: parsed.steps };
930
- fs.writeFileSync(targetPath, serializeChain(chain), "utf-8");
931
- const missing = unknownChainAgents(ctx.cwd, chain.steps);
932
- if (missing.length)
933
- warnings.push(`Warning: chain steps reference unknown agents: ${missing.join(", ")}.`);
934
- warnings.push(...chainStepWarnings(ctx, chain.steps));
935
- return result([`Created chain '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
936
- }
937
- const agent = {
938
- name: runtimeName,
939
- localName: name,
940
- packageName: parsedPackage.packageName,
941
- description: cfg.description.trim(),
942
- source: scope,
943
- filePath: targetPath,
944
- systemPrompt: "",
945
- systemPromptMode: defaultSystemPromptMode(name),
946
- inheritProjectContext: defaultInheritProjectContext(name),
947
- inheritSkills: defaultInheritSkills(),
948
- };
949
- const applyError = applyAgentConfig(agent, cfg);
950
- if (applyError)
951
- return result(applyError, true);
952
- const mw = modelWarning(ctx, agent.model);
953
- if (mw)
954
- warnings.push(mw);
955
- const fmw = fallbackModelsWarning(ctx, agent.fallbackModels);
956
- if (fmw)
957
- warnings.push(fmw);
958
- const sw = skillsWarning(ctx.cwd, agent);
959
- if (sw)
960
- warnings.push(sw);
961
- fs.writeFileSync(targetPath, serializeAgent(agent), "utf-8");
962
- return result([`Created agent '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
963
- }
964
- export function handleUpdate(params, ctx) {
965
- if (!params.agent && !params.chainName)
966
- return result("Specify 'agent' or 'chainName' for update.", true);
967
- if (params.agent && params.chainName)
968
- return result("Specify either 'agent' or 'chainName', not both.", true);
969
- const parsedConfig = configObject(params.config);
970
- if (parsedConfig.error)
971
- return result(parsedConfig.error, true);
972
- const cfg = parsedConfig.value;
973
- if (!cfg)
974
- return result("config required for update.", true);
975
- const warnings = [];
976
- if (params.agent) {
977
- const scopeHint = asDisambiguationScope(params.agentScope);
978
- const targetOrError = resolveTarget("agent", params.agent, findAgents(params.agent, ctx.cwd, scopeHint ?? "both"), ctx.cwd, params.agentScope);
979
- if ("content" in targetOrError)
980
- return targetOrError;
981
- const target = targetOrError;
982
- const updated = editableAgentConfig(target);
983
- const oldName = target.name;
984
- if (hasKey(cfg, "name") && (typeof cfg.name !== "string" || !cfg.name.trim()))
985
- return result("config.name must be a non-empty string when provided.", true);
986
- if (hasKey(cfg, "description") && (typeof cfg.description !== "string" || !cfg.description.trim()))
987
- return result("config.description must be a non-empty string when provided.", true);
988
- let newLocalName = target.localName ?? frontmatterNameForConfig(target);
989
- if (hasKey(cfg, "name")) {
990
- newLocalName = sanitizeName(cfg.name);
991
- if (!newLocalName)
992
- return result("config.name is invalid after sanitization.", true);
993
- }
994
- let newPackageName = target.packageName;
995
- if (hasKey(cfg, "package")) {
996
- const parsedPackage = parsePackageConfig(cfg.package);
997
- if (parsedPackage.error)
998
- return result(parsedPackage.error, true);
999
- newPackageName = parsedPackage.packageName;
1000
- }
1001
- const applyError = applyAgentConfig(updated, cfg);
1002
- if (applyError)
1003
- return result(applyError, true);
1004
- const preserveFrontmatterFields = preservedAgentFrontmatterFields(target, cfg);
1005
- updated.localName = newLocalName;
1006
- updated.packageName = newPackageName;
1007
- updated.name = buildRuntimeName(newLocalName, newPackageName);
1008
- if (hasKey(cfg, "description"))
1009
- updated.description = cfg.description.trim();
1010
- if (hasKey(cfg, "model")) {
1011
- const mw = modelWarning(ctx, updated.model);
1012
- if (mw)
1013
- warnings.push(mw);
1014
- }
1015
- if (hasKey(cfg, "fallbackModels")) {
1016
- const fmw = fallbackModelsWarning(ctx, updated.fallbackModels);
1017
- if (fmw)
1018
- warnings.push(fmw);
1019
- }
1020
- if (hasKey(cfg, "skills") || hasKey(cfg, "skillPath")) {
1021
- const sw = skillsWarning(ctx.cwd, updated);
1022
- if (sw)
1023
- warnings.push(sw);
1024
- }
1025
- if (updated.name !== oldName) {
1026
- const renamed = renamePath("agent", target.filePath, updated.name, target.source, ctx.cwd);
1027
- if (renamed.error)
1028
- return result(renamed.error, true);
1029
- updated.filePath = renamed.filePath;
1030
- }
1031
- fs.writeFileSync(updated.filePath, serializeAgent(updated, { preserveFrontmatterFields }), "utf-8");
1032
- if (updated.name !== oldName) {
1033
- const refs = discoverAgentsAll(ctx.cwd).chains.filter((c) => c.steps.some((s) => s.agent === oldName)).map((c) => `${c.name} (${c.source})`);
1034
- if (refs.length)
1035
- warnings.push(`Warning: chains still reference '${oldName}': ${refs.join(", ")}.`);
1036
- }
1037
- const headline = updated.name === oldName
1038
- ? `Updated agent '${updated.name}' at ${updated.filePath}.`
1039
- : `Updated agent '${oldName}' to '${updated.name}' at ${updated.filePath}.`;
1040
- return result([headline, ...warnings].join("\n"));
1041
- }
1042
- const scopeHint = asDisambiguationScope(params.agentScope);
1043
- const targetOrError = resolveTarget("chain", params.chainName, findChains(params.chainName, ctx.cwd, scopeHint ?? "both"), ctx.cwd, params.agentScope);
1044
- if ("content" in targetOrError)
1045
- return targetOrError;
1046
- const target = targetOrError;
1047
- const updated = { ...target, steps: [...target.steps] };
1048
- const oldName = target.name;
1049
- if (hasKey(cfg, "name") && (typeof cfg.name !== "string" || !cfg.name.trim()))
1050
- return result("config.name must be a non-empty string when provided.", true);
1051
- if (hasKey(cfg, "description") && (typeof cfg.description !== "string" || !cfg.description.trim()))
1052
- return result("config.description must be a non-empty string when provided.", true);
1053
- let newLocalName = target.localName ?? frontmatterNameForConfig(target);
1054
- if (hasKey(cfg, "name")) {
1055
- newLocalName = sanitizeName(cfg.name);
1056
- if (!newLocalName)
1057
- return result("config.name is invalid after sanitization.", true);
1058
- }
1059
- let newPackageName = target.packageName;
1060
- if (hasKey(cfg, "package")) {
1061
- const parsedPackage = parsePackageConfig(cfg.package);
1062
- if (parsedPackage.error)
1063
- return result(parsedPackage.error, true);
1064
- newPackageName = parsedPackage.packageName;
1065
- }
1066
- let parsedSteps;
1067
- if (hasKey(cfg, "steps")) {
1068
- const parsed = parseStepList(cfg.steps);
1069
- if (parsed.error)
1070
- return result(parsed.error, true);
1071
- parsedSteps = parsed.steps;
1072
- }
1073
- updated.localName = newLocalName;
1074
- updated.packageName = newPackageName;
1075
- updated.name = buildRuntimeName(newLocalName, newPackageName);
1076
- if (hasKey(cfg, "description"))
1077
- updated.description = cfg.description.trim();
1078
- if (parsedSteps) {
1079
- updated.steps = parsedSteps;
1080
- const missing = unknownChainAgents(ctx.cwd, updated.steps);
1081
- if (missing.length)
1082
- warnings.push(`Warning: chain steps reference unknown agents: ${missing.join(", ")}.`);
1083
- warnings.push(...chainStepWarnings(ctx, updated.steps));
1084
- }
1085
- if (updated.name !== oldName) {
1086
- const renamed = renamePath("chain", target.filePath, updated.name, target.source, ctx.cwd);
1087
- if (renamed.error)
1088
- return result(renamed.error, true);
1089
- updated.filePath = renamed.filePath;
1090
- }
1091
- fs.writeFileSync(updated.filePath, updated.filePath.endsWith(".chain.json") ? serializeJsonChain(updated) : serializeChain(updated), "utf-8");
1092
- const headline = updated.name === oldName
1093
- ? `Updated chain '${updated.name}' at ${updated.filePath}.`
1094
- : `Updated chain '${oldName}' to '${updated.name}' at ${updated.filePath}.`;
1095
- return result([headline, ...warnings].join("\n"));
1096
- }
1097
- function handleDelete(params, ctx) {
1098
- if (!params.agent && !params.chainName)
1099
- return result("Specify 'agent' or 'chainName' for delete.", true);
1100
- if (params.agent && params.chainName)
1101
- return result("Specify either 'agent' or 'chainName', not both.", true);
1102
- const scopeHint = asDisambiguationScope(params.agentScope);
1103
- if (params.agent) {
1104
- const targetOrError = resolveTarget("agent", params.agent, findAgents(params.agent, ctx.cwd, scopeHint ?? "both"), ctx.cwd, params.agentScope);
1105
- if ("content" in targetOrError)
1106
- return targetOrError;
1107
- const target = targetOrError;
1108
- fs.unlinkSync(target.filePath);
1109
- const refs = discoverAgentsAll(ctx.cwd).chains.filter((c) => c.steps.some((s) => s.agent === target.name)).map((c) => `${c.name} (${c.source})`);
1110
- const lines = [`Deleted agent '${target.name}' at ${target.filePath}.`];
1111
- if (refs.length)
1112
- lines.push(`Warning: chains reference deleted agent '${target.name}': ${refs.join(", ")}.`);
1113
- return result(lines.join("\n"));
1114
- }
1115
- const targetOrError = resolveTarget("chain", params.chainName, findChains(params.chainName, ctx.cwd, scopeHint ?? "both"), ctx.cwd, params.agentScope);
1116
- if ("content" in targetOrError)
1117
- return targetOrError;
1118
- const target = targetOrError;
1119
- fs.unlinkSync(target.filePath);
1120
- return result(`Deleted chain '${target.name}' at ${target.filePath}.`);
1121
- }
1122
- function handleEject(params, ctx) {
1123
- if (!params.agent)
1124
- return result("Specify 'agent' for eject.", true);
1125
- const raw = params.agent.trim();
1126
- const sanitized = sanitizeName(raw);
1127
- const parsedScope = actionScope(params.agentScope, "eject");
1128
- if (parsedScope.error)
1129
- return parsedScope.error;
1130
- const scope = parsedScope.scope;
1131
- const d = discoverAgentsAll(ctx.cwd);
1132
- const source = [...d.package, ...d.builtin].find((a) => a.name === raw || a.name === sanitized);
1133
- if (!source) {
1134
- return result(`Agent '${raw}' not found or is not a bundled/package agent. eject copies a builtin or package agent to ${scope} scope so it can be customized. Available: ${availableNames(ctx.cwd, "agent").join(", ") || "none"}.`, true);
1135
- }
1136
- const runtimeName = source.name;
1137
- const existingCustom = (scope === "user" ? d.user : d.project).find((a) => a.name === runtimeName);
1138
- if (existingCustom) {
1139
- return result(`Agent '${runtimeName}' is already a custom ${scope} agent at ${existingCustom.filePath}. Edit it with { action: "update", agent: "${runtimeName}" } or delete it first.`, true);
1140
- }
1141
- if (nameExistsInScope(ctx.cwd, scope, runtimeName)) {
1142
- return result(`An agent or chain named '${runtimeName}' already exists in ${scope} scope. Remove or rename it first.`, true);
1143
- }
1144
- const projectConfigDir = getProjectConfigDir(ctx.cwd);
1145
- const targetDir = scope === "user" ? d.userDir : d.projectDir ?? path.join(projectConfigDir, "agents");
1146
- fs.mkdirSync(targetDir, { recursive: true });
1147
- const targetPath = path.join(targetDir, `${runtimeName}.md`);
1148
- if (fs.existsSync(targetPath)) {
1149
- return result(`File already exists at ${targetPath} but is not a valid agent definition. Remove or rename it first.`, true);
1150
- }
1151
- let content;
1152
- try {
1153
- content = fs.readFileSync(source.filePath, "utf-8");
1154
- }
1155
- catch (error) {
1156
- const message = error instanceof Error ? error.message : String(error);
1157
- return result(`Failed to read source agent at ${source.filePath}: ${message}`, true);
1158
- }
1159
- fs.writeFileSync(targetPath, content, "utf-8");
1160
- return result(`Ejected agent '${runtimeName}' from ${source.source} to ${scope} scope at ${targetPath}. Edit it there to customize; it shadows the bundled ${source.source} agent of the same name.`);
1161
- }
1162
- function handleDisable(params, ctx) {
1163
- if (!params.agent)
1164
- return result("Specify 'agent' for disable.", true);
1165
- const raw = params.agent.trim();
1166
- const parsedScope = actionScope(params.agentScope, "disable");
1167
- if (parsedScope.error)
1168
- return parsedScope.error;
1169
- const scope = parsedScope.scope;
1170
- const d = discoverAgentsAll(ctx.cwd);
1171
- if (scope === "project" && d.projectSettingsPath === null) {
1172
- return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
1173
- }
1174
- const effective = pickEffectiveAgent(d, raw);
1175
- if (!effective) {
1176
- return result(`Agent '${raw}' not found. Available: ${availableNames(ctx.cwd, "agent").join(", ") || "none"}.`, true);
1177
- }
1178
- const runtimeName = effective.name;
1179
- const settingsPath = mergeBuiltinAgentOverride(ctx.cwd, runtimeName, scope, { disabled: true });
1180
- const after = pickEffectiveAgent(discoverAgentsAll(ctx.cwd), raw);
1181
- if (after?.disabled === true) {
1182
- return result(`Disabled agent '${runtimeName}' via ${scope} settings override at ${settingsPath}. It is now hidden from runtime discovery and { action: "list" }.`);
1183
- }
1184
- return result(`Wrote a disabled override for '${runtimeName}' at ${settingsPath}, but the agent is still enabled. A higher-precedence ${after?.override?.scope ?? "project"} override is likely winning. Try agentScope: '${after?.override?.scope ?? "project"}'.`, true);
1185
- }
1186
- function handleEnable(params, ctx) {
1187
- if (!params.agent)
1188
- return result("Specify 'agent' for enable.", true);
1189
- const raw = params.agent.trim();
1190
- const parsedScope = actionScope(params.agentScope, "enable");
1191
- if (parsedScope.error)
1192
- return parsedScope.error;
1193
- const scope = parsedScope.scope;
1194
- const d = discoverAgentsAll(ctx.cwd);
1195
- if (scope === "project" && d.projectSettingsPath === null) {
1196
- return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
1197
- }
1198
- const effective = pickEffectiveAgent(d, raw);
1199
- if (!effective) {
1200
- return result(`Agent '${raw}' not found. Available: ${availableNames(ctx.cwd, "agent").join(", ") || "none"}.`, true);
1201
- }
1202
- const runtimeName = effective.name;
1203
- const { path: settingsPath, removed } = removeBuiltinAgentOverrideFields(ctx.cwd, runtimeName, scope, ["disabled"]);
1204
- const after = pickEffectiveAgent(discoverAgentsAll(ctx.cwd), raw);
1205
- if (after && after.disabled !== true) {
1206
- if (removed)
1207
- return result(`Enabled agent '${runtimeName}' (removed disabled override at ${settingsPath}).`);
1208
- return result(`Agent '${runtimeName}' is already enabled.`);
1209
- }
1210
- if (after?.override?.scope && after.override.scope !== scope) {
1211
- return result(`Agent '${runtimeName}' is still disabled via a ${after.override.scope} scope override at ${after.override.path}. Specify agentScope: '${after.override.scope}' to enable it.`, true);
1212
- }
1213
- return result(`Agent '${runtimeName}' is still disabled after removing the ${scope} disabled override. It may be hidden via subagents.disableBuiltins in ${after?.override?.scope ?? scope} settings at ${after?.override?.path ?? settingsPath}.`, true);
1214
- }
1215
- function handleReset(params, ctx) {
1216
- if (!params.agent)
1217
- return result("Specify 'agent' for reset.", true);
1218
- const raw = params.agent.trim();
1219
- const sanitized = sanitizeName(raw);
1220
- const parsedScope = actionScope(params.agentScope, "reset");
1221
- if (parsedScope.error)
1222
- return parsedScope.error;
1223
- const scope = parsedScope.scope;
1224
- const d = discoverAgentsAll(ctx.cwd);
1225
- if (scope === "project" && d.projectSettingsPath === null) {
1226
- return result("Project override is not available here: no project config root (.pi or .agents) was found above the cwd. Use agentScope: 'user' or run from inside a project.", true);
1227
- }
1228
- const bundled = [...d.package, ...d.builtin].find((a) => a.name === raw || a.name === sanitized);
1229
- if (!bundled) {
1230
- const custom = [...d.user, ...d.project].find((a) => a.name === raw || a.name === sanitized);
1231
- if (custom) {
1232
- return result(`Agent '${raw}' has no bundled default to reset to. Use { action: "delete", agent: "${custom.name}" } to remove the custom ${custom.source} agent.`, true);
1233
- }
1234
- return result(`Agent '${raw}' not found. Available: ${availableNames(ctx.cwd, "agent").join(", ") || "none"}.`, true);
1235
- }
1236
- const runtimeName = bundled.name;
1237
- const custom = (scope === "user" ? d.user : d.project).find((a) => a.name === raw || a.name === sanitized);
1238
- const lines = [];
1239
- if (custom) {
1240
- fs.unlinkSync(custom.filePath);
1241
- lines.push(`Deleted custom ${scope} agent file at ${custom.filePath}.`);
1242
- }
1243
- const overrideRemoval = removeBuiltinAgentOverride(ctx.cwd, runtimeName, scope);
1244
- if (overrideRemoval.removed)
1245
- lines.push(`Removed ${scope} settings override at ${overrideRemoval.path}.`);
1246
- if (lines.length === 0) {
1247
- const otherScope = scope === "user" ? "project" : "user";
1248
- const otherCustom = (otherScope === "user" ? d.user : d.project).find((a) => a.name === raw || a.name === sanitized);
1249
- const hasOtherOverride = bundled.override?.scope === otherScope;
1250
- const note = (otherCustom || hasOtherOverride)
1251
- ? ` Customization exists in ${otherScope} scope; specify agentScope: '${otherScope}' to reset it.`
1252
- : "";
1253
- return result(`Agent '${runtimeName}' has no ${scope} customization to reset.${note} It is at its bundled ${bundled.source} default.`);
1254
- }
1255
- lines.push(`Reset agent '${runtimeName}' to its bundled ${bundled.source} default.`);
1256
- return result(lines.join("\n"));
1257
- }
1258
- export function handleManagementAction(action, params, ctx) {
1259
- switch (action) {
1260
- case "list": return handleList(params, ctx);
1261
- case "get": return handleGet(params, ctx);
1262
- case "models": return handleModels(params, ctx);
1263
- case "create": return handleCreate(params, ctx);
1264
- case "update": return handleUpdate(params, ctx);
1265
- case "delete": return handleDelete(params, ctx);
1266
- case "eject": return handleEject(params, ctx);
1267
- case "disable": return handleDisable(params, ctx);
1268
- case "enable": return handleEnable(params, ctx);
1269
- case "reset": return handleReset(params, ctx);
1270
- default: return result(`Unknown action: ${action}`, true);
1271
- }
1272
- }
1273
- //# sourceMappingURL=agent-management.js.map