@diffra-ai/cli 0.1.1 → 0.1.2

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 (457) hide show
  1. package/CHANGELOG.md +47 -15
  2. package/dist/bundle/chunks/{anthropic-messages-M3HXJPTI.js → anthropic-messages-HME6WDIM.js} +1 -1
  3. package/dist/bundle/chunks/{azure-openai-responses-GIFO2563.js → azure-openai-responses-WKSFBZF5.js} +1 -1
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  5. package/dist/bundle/chunks/{chunk-GT3WTHFU.js → chunk-3MKQN3ZR.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-VJQ6ZYW4.js → chunk-4NMBWIZG.js} +5 -5
  7. package/dist/bundle/chunks/{chunk-INTHKDF2.js → chunk-65DC2T66.js} +1 -1
  8. package/dist/bundle/chunks/{chunk-N6QWAQ6I.js → chunk-6L2FT6AE.js} +1 -1
  9. package/dist/bundle/chunks/chunk-6ZD23B2R.js +2 -0
  10. package/dist/bundle/chunks/{chunk-OQFRYL4U.js → chunk-E3MJ4MPN.js} +1 -1
  11. package/dist/bundle/chunks/chunk-GRDBYTYT.js +2003 -0
  12. package/dist/bundle/chunks/{chunk-RJRIMI6M.js → chunk-GRYHVZSI.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-CCH74R6M.js → chunk-MITPYV3F.js} +1 -1
  14. package/dist/bundle/chunks/{chunk-WEJVQTLI.js → chunk-MJRIJM22.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-OOE7BGUD.js → chunk-PQGGR7SQ.js} +1 -1
  16. package/dist/bundle/chunks/{chunk-WAH3PGZX.js → chunk-PXE534VH.js} +2 -2
  17. package/dist/bundle/chunks/{chunk-262RLABF.js → chunk-QMZGTPRI.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-VSFRR6IC.js → chunk-QQ6NVGNW.js} +1 -1
  19. package/dist/bundle/chunks/{chunk-N6Q2WLPG.js → chunk-RUI3NOFB.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-6S2AQWGR.js → chunk-SI7T4LPD.js} +4 -4
  21. package/dist/bundle/chunks/{chunk-CVEPACZO.js → chunk-SMYD2SB5.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-B3FUE2LF.js → chunk-XAA355T2.js} +1 -1
  23. package/dist/bundle/chunks/{cli-EC3ZETTA.js → cli-GKHAGQO6.js} +1 -1
  24. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-YW7YYPAC.js → cloudflare-workers-ai-system-one-PVUECIVD.js} +1 -1
  25. package/dist/bundle/chunks/{easter-egg-3d-QN5RJMZR.js → easter-egg-3d-VAZ2JWDP.js} +1 -1
  26. package/dist/bundle/chunks/{execute-3J63CQJG.js → execute-OEFRHFHI.js} +1 -1
  27. package/dist/bundle/chunks/{google-generative-ai-F6DN2LQU.js → google-generative-ai-2YH7DK5J.js} +1 -1
  28. package/dist/bundle/chunks/{google-vertex-MDWFDVAW.js → google-vertex-QNIS4SPE.js} +1 -1
  29. package/dist/bundle/chunks/{llama-cpp-classify-XO72TVVH.js → llama-cpp-classify-EMBT3ZMY.js} +1 -1
  30. package/dist/bundle/chunks/{mistral-conversations-KYVGR5VN.js → mistral-conversations-RCHJWX2M.js} +1 -1
  31. package/dist/bundle/chunks/{openai-codex-responses-SIQN5LUE.js → openai-codex-responses-LBZQ7HUY.js} +1 -1
  32. package/dist/bundle/chunks/{openai-completions-B22DYT4F.js → openai-completions-U7NS5GFY.js} +1 -1
  33. package/dist/bundle/chunks/{openai-decisions-4GVNTR54.js → openai-decisions-YC4ZEGAR.js} +1 -1
  34. package/dist/bundle/chunks/{openai-responses-5DVNSQCE.js → openai-responses-4YX6XMEO.js} +1 -1
  35. package/dist/bundle/chunks/{openrouter-images-SQMQNKJU.js → openrouter-images-QPPGKFJY.js} +1 -1
  36. package/dist/bundle/chunks/{pi-messages-GZ4HZRKJ.js → pi-messages-5W3GZ7B6.js} +1 -1
  37. package/dist/bundle/chunks/{runtime-KEVIZBAR.js → runtime-SI4R3AXJ.js} +1 -1
  38. package/dist/bundle/chunks/{typesafe-system-one-GMPGMPLA.js → typesafe-system-one-GWMQ2NLX.js} +1 -1
  39. package/dist/bundle/chunks/virtual-modules-ENTYMDSQ.js +2 -0
  40. package/dist/bundle/cli-runtime.js +1 -1
  41. package/dist/bundle/index.js +1 -1
  42. package/dist/bundle/rpc-entry.js +1 -1
  43. package/dist/cli/args.d.ts +2 -0
  44. package/dist/cli/args.d.ts.map +1 -1
  45. package/dist/cli/args.js +13 -0
  46. package/dist/cli/args.js.map +1 -1
  47. package/dist/cli/sandbox-command.d.ts +8 -0
  48. package/dist/cli/sandbox-command.d.ts.map +1 -0
  49. package/dist/cli/sandbox-command.js +52 -0
  50. package/dist/cli/sandbox-command.js.map +1 -0
  51. package/dist/config.d.ts +7 -0
  52. package/dist/config.d.ts.map +1 -1
  53. package/dist/config.js +14 -0
  54. package/dist/config.js.map +1 -1
  55. package/dist/core/agent-session.d.ts +20 -0
  56. package/dist/core/agent-session.d.ts.map +1 -1
  57. package/dist/core/agent-session.js +72 -2
  58. package/dist/core/agent-session.js.map +1 -1
  59. package/dist/core/approval-mode.d.ts +28 -0
  60. package/dist/core/approval-mode.d.ts.map +1 -0
  61. package/dist/core/approval-mode.js +34 -0
  62. package/dist/core/approval-mode.js.map +1 -0
  63. package/dist/core/extensions/loader.d.ts.map +1 -1
  64. package/dist/core/extensions/loader.js +15 -0
  65. package/dist/core/extensions/loader.js.map +1 -1
  66. package/dist/core/extensions/runner.d.ts.map +1 -1
  67. package/dist/core/extensions/runner.js +3 -0
  68. package/dist/core/extensions/runner.js.map +1 -1
  69. package/dist/core/extensions/types.d.ts +28 -1
  70. package/dist/core/extensions/types.d.ts.map +1 -1
  71. package/dist/core/extensions/types.js.map +1 -1
  72. package/dist/core/fast-model.d.ts +10 -0
  73. package/dist/core/fast-model.d.ts.map +1 -0
  74. package/dist/core/fast-model.js +13 -0
  75. package/dist/core/fast-model.js.map +1 -0
  76. package/dist/core/keybindings.d.ts +8 -0
  77. package/dist/core/keybindings.d.ts.map +1 -1
  78. package/dist/core/keybindings.js +4 -0
  79. package/dist/core/keybindings.js.map +1 -1
  80. package/dist/core/sandbox/escalation.d.ts +32 -0
  81. package/dist/core/sandbox/escalation.d.ts.map +1 -0
  82. package/dist/core/sandbox/escalation.js +70 -0
  83. package/dist/core/sandbox/escalation.js.map +1 -0
  84. package/dist/core/sandbox/launch.d.ts +14 -0
  85. package/dist/core/sandbox/launch.d.ts.map +1 -0
  86. package/dist/core/sandbox/launch.js +18 -0
  87. package/dist/core/sandbox/launch.js.map +1 -0
  88. package/dist/core/sandbox/policy.d.ts +50 -0
  89. package/dist/core/sandbox/policy.d.ts.map +1 -0
  90. package/dist/core/sandbox/policy.js +96 -0
  91. package/dist/core/sandbox/policy.js.map +1 -0
  92. package/dist/core/sandbox/seatbelt.d.ts +17 -0
  93. package/dist/core/sandbox/seatbelt.d.ts.map +1 -0
  94. package/dist/core/sandbox/seatbelt.js +169 -0
  95. package/dist/core/sandbox/seatbelt.js.map +1 -0
  96. package/dist/core/sandbox/windows.d.ts +30 -0
  97. package/dist/core/sandbox/windows.d.ts.map +1 -0
  98. package/dist/core/sandbox/windows.js +104 -0
  99. package/dist/core/sandbox/windows.js.map +1 -0
  100. package/dist/core/settings-defaults.d.ts +28 -0
  101. package/dist/core/settings-defaults.d.ts.map +1 -1
  102. package/dist/core/settings-defaults.js +28 -0
  103. package/dist/core/settings-defaults.js.map +1 -1
  104. package/dist/core/settings-manager.d.ts +9 -1
  105. package/dist/core/settings-manager.d.ts.map +1 -1
  106. package/dist/core/settings-manager.js +58 -1
  107. package/dist/core/settings-manager.js.map +1 -1
  108. package/dist/core/settings-schema.d.ts +124 -0
  109. package/dist/core/settings-schema.d.ts.map +1 -1
  110. package/dist/core/settings-schema.js +177 -0
  111. package/dist/core/settings-schema.js.map +1 -1
  112. package/dist/core/tools/bash.d.ts +12 -2
  113. package/dist/core/tools/bash.d.ts.map +1 -1
  114. package/dist/core/tools/bash.js +27 -7
  115. package/dist/core/tools/bash.js.map +1 -1
  116. package/dist/core/tools/edit.d.ts +3 -0
  117. package/dist/core/tools/edit.d.ts.map +1 -1
  118. package/dist/core/tools/edit.js +2 -0
  119. package/dist/core/tools/edit.js.map +1 -1
  120. package/dist/core/tools/powershell.d.ts +3 -2
  121. package/dist/core/tools/powershell.d.ts.map +1 -1
  122. package/dist/core/tools/powershell.js +4 -6
  123. package/dist/core/tools/powershell.js.map +1 -1
  124. package/dist/core/tools/render-utils.d.ts +2 -2
  125. package/dist/core/tools/render-utils.js +5 -5
  126. package/dist/core/tools/render-utils.js.map +1 -1
  127. package/dist/core/tools/renderers/edit.d.ts.map +1 -1
  128. package/dist/core/tools/renderers/edit.js +16 -19
  129. package/dist/core/tools/renderers/edit.js.map +1 -1
  130. package/dist/core/tools/write.d.ts +3 -0
  131. package/dist/core/tools/write.d.ts.map +1 -1
  132. package/dist/core/tools/write.js +2 -0
  133. package/dist/core/tools/write.js.map +1 -1
  134. package/dist/extensions/agents/agent-tool.d.ts +61 -0
  135. package/dist/extensions/agents/agent-tool.d.ts.map +1 -0
  136. package/dist/extensions/agents/agent-tool.js +277 -0
  137. package/dist/extensions/agents/agent-tool.js.map +1 -0
  138. package/dist/extensions/agents/background.d.ts +56 -0
  139. package/dist/extensions/agents/background.d.ts.map +1 -0
  140. package/dist/extensions/agents/background.js +142 -0
  141. package/dist/extensions/agents/background.js.map +1 -0
  142. package/dist/extensions/agents/builtin-agents.d.ts +8 -0
  143. package/dist/extensions/agents/builtin-agents.d.ts.map +1 -0
  144. package/dist/extensions/agents/builtin-agents.js +38 -0
  145. package/dist/extensions/agents/builtin-agents.js.map +1 -0
  146. package/dist/extensions/agents/call-scopes.d.ts +34 -0
  147. package/dist/extensions/agents/call-scopes.d.ts.map +1 -0
  148. package/dist/extensions/agents/call-scopes.js +36 -0
  149. package/dist/extensions/agents/call-scopes.js.map +1 -0
  150. package/dist/extensions/agents/definitions.d.ts +64 -0
  151. package/dist/extensions/agents/definitions.d.ts.map +1 -0
  152. package/dist/extensions/agents/definitions.js +216 -0
  153. package/dist/extensions/agents/definitions.js.map +1 -0
  154. package/dist/extensions/agents/index.d.ts +15 -0
  155. package/dist/extensions/agents/index.d.ts.map +1 -0
  156. package/dist/extensions/agents/index.js +327 -0
  157. package/dist/extensions/agents/index.js.map +1 -0
  158. package/dist/extensions/agents/runner.d.ts +63 -0
  159. package/dist/extensions/agents/runner.d.ts.map +1 -0
  160. package/dist/extensions/agents/runner.js +156 -0
  161. package/dist/extensions/agents/runner.js.map +1 -0
  162. package/dist/extensions/approval/auto-classifier.d.ts +32 -0
  163. package/dist/extensions/approval/auto-classifier.d.ts.map +1 -0
  164. package/dist/extensions/approval/auto-classifier.js +116 -0
  165. package/dist/extensions/approval/auto-classifier.js.map +1 -0
  166. package/dist/extensions/approval/exit-plan-mode.d.ts +24 -0
  167. package/dist/extensions/approval/exit-plan-mode.d.ts.map +1 -0
  168. package/dist/extensions/approval/exit-plan-mode.js +99 -0
  169. package/dist/extensions/approval/exit-plan-mode.js.map +1 -0
  170. package/dist/extensions/approval/index.d.ts +15 -0
  171. package/dist/extensions/approval/index.d.ts.map +1 -0
  172. package/dist/extensions/approval/index.js +329 -0
  173. package/dist/extensions/approval/index.js.map +1 -0
  174. package/dist/extensions/approval/plan-reminders.d.ts +9 -0
  175. package/dist/extensions/approval/plan-reminders.d.ts.map +1 -0
  176. package/dist/extensions/approval/plan-reminders.js +42 -0
  177. package/dist/extensions/approval/plan-reminders.js.map +1 -0
  178. package/dist/extensions/approval/policy.d.ts +52 -0
  179. package/dist/extensions/approval/policy.d.ts.map +1 -0
  180. package/dist/extensions/approval/policy.js +124 -0
  181. package/dist/extensions/approval/policy.js.map +1 -0
  182. package/dist/extensions/approval/shell-safety.d.ts +11 -0
  183. package/dist/extensions/approval/shell-safety.d.ts.map +1 -0
  184. package/dist/extensions/approval/shell-safety.js +264 -0
  185. package/dist/extensions/approval/shell-safety.js.map +1 -0
  186. package/dist/extensions/cron/cron-expression.d.ts +30 -0
  187. package/dist/extensions/cron/cron-expression.d.ts.map +1 -0
  188. package/dist/extensions/cron/cron-expression.js +119 -0
  189. package/dist/extensions/cron/cron-expression.js.map +1 -0
  190. package/dist/extensions/cron/index.d.ts +19 -0
  191. package/dist/extensions/cron/index.d.ts.map +1 -0
  192. package/dist/extensions/cron/index.js +215 -0
  193. package/dist/extensions/cron/index.js.map +1 -0
  194. package/dist/extensions/cron/loop-args.d.ts +35 -0
  195. package/dist/extensions/cron/loop-args.d.ts.map +1 -0
  196. package/dist/extensions/cron/loop-args.js +95 -0
  197. package/dist/extensions/cron/loop-args.js.map +1 -0
  198. package/dist/extensions/cron/loop-texts.d.ts +29 -0
  199. package/dist/extensions/cron/loop-texts.d.ts.map +1 -0
  200. package/dist/extensions/cron/loop-texts.js +83 -0
  201. package/dist/extensions/cron/loop-texts.js.map +1 -0
  202. package/dist/extensions/cron/scheduler.d.ts +79 -0
  203. package/dist/extensions/cron/scheduler.d.ts.map +1 -0
  204. package/dist/extensions/cron/scheduler.js +146 -0
  205. package/dist/extensions/cron/scheduler.js.map +1 -0
  206. package/dist/extensions/cron/tools.d.ts +47 -0
  207. package/dist/extensions/cron/tools.d.ts.map +1 -0
  208. package/dist/extensions/cron/tools.js +141 -0
  209. package/dist/extensions/cron/tools.js.map +1 -0
  210. package/dist/extensions/goals/evidence.d.ts +20 -0
  211. package/dist/extensions/goals/evidence.d.ts.map +1 -0
  212. package/dist/extensions/goals/evidence.js +77 -0
  213. package/dist/extensions/goals/evidence.js.map +1 -0
  214. package/dist/extensions/goals/index.d.ts +45 -0
  215. package/dist/extensions/goals/index.d.ts.map +1 -0
  216. package/dist/extensions/goals/index.js +438 -0
  217. package/dist/extensions/goals/index.js.map +1 -0
  218. package/dist/extensions/goals/prompts.d.ts +15 -0
  219. package/dist/extensions/goals/prompts.d.ts.map +1 -0
  220. package/dist/extensions/goals/prompts.js +51 -0
  221. package/dist/extensions/goals/prompts.js.map +1 -0
  222. package/dist/extensions/goals/state.d.ts +88 -0
  223. package/dist/extensions/goals/state.d.ts.map +1 -0
  224. package/dist/extensions/goals/state.js +204 -0
  225. package/dist/extensions/goals/state.js.map +1 -0
  226. package/dist/extensions/goals/tools.d.ts +40 -0
  227. package/dist/extensions/goals/tools.d.ts.map +1 -0
  228. package/dist/extensions/goals/tools.js +118 -0
  229. package/dist/extensions/goals/tools.js.map +1 -0
  230. package/dist/extensions/goals/verifier.d.ts +30 -0
  231. package/dist/extensions/goals/verifier.d.ts.map +1 -0
  232. package/dist/extensions/goals/verifier.js +89 -0
  233. package/dist/extensions/goals/verifier.js.map +1 -0
  234. package/dist/extensions/hooks/aggregate.d.ts +30 -0
  235. package/dist/extensions/hooks/aggregate.d.ts.map +1 -0
  236. package/dist/extensions/hooks/aggregate.js +103 -0
  237. package/dist/extensions/hooks/aggregate.js.map +1 -0
  238. package/dist/extensions/hooks/config.d.ts +47 -0
  239. package/dist/extensions/hooks/config.d.ts.map +1 -0
  240. package/dist/extensions/hooks/config.js +169 -0
  241. package/dist/extensions/hooks/config.js.map +1 -0
  242. package/dist/extensions/hooks/file-watcher.d.ts +31 -0
  243. package/dist/extensions/hooks/file-watcher.d.ts.map +1 -0
  244. package/dist/extensions/hooks/file-watcher.js +106 -0
  245. package/dist/extensions/hooks/file-watcher.js.map +1 -0
  246. package/dist/extensions/hooks/index.d.ts +17 -0
  247. package/dist/extensions/hooks/index.d.ts.map +1 -0
  248. package/dist/extensions/hooks/index.js +349 -0
  249. package/dist/extensions/hooks/index.js.map +1 -0
  250. package/dist/extensions/hooks/matcher.d.ts +10 -0
  251. package/dist/extensions/hooks/matcher.d.ts.map +1 -0
  252. package/dist/extensions/hooks/matcher.js +85 -0
  253. package/dist/extensions/hooks/matcher.js.map +1 -0
  254. package/dist/extensions/hooks/runner.d.ts +54 -0
  255. package/dist/extensions/hooks/runner.d.ts.map +1 -0
  256. package/dist/extensions/hooks/runner.js +197 -0
  257. package/dist/extensions/hooks/runner.js.map +1 -0
  258. package/dist/extensions/index.d.ts.map +1 -1
  259. package/dist/extensions/index.js +29 -2
  260. package/dist/extensions/index.js.map +1 -1
  261. package/dist/extensions/lsp/config.d.ts +40 -0
  262. package/dist/extensions/lsp/config.d.ts.map +1 -0
  263. package/dist/extensions/lsp/config.js +92 -0
  264. package/dist/extensions/lsp/config.js.map +1 -0
  265. package/dist/extensions/lsp/connection.d.ts +32 -0
  266. package/dist/extensions/lsp/connection.d.ts.map +1 -0
  267. package/dist/extensions/lsp/connection.js +124 -0
  268. package/dist/extensions/lsp/connection.js.map +1 -0
  269. package/dist/extensions/lsp/index.d.ts +15 -0
  270. package/dist/extensions/lsp/index.d.ts.map +1 -0
  271. package/dist/extensions/lsp/index.js +103 -0
  272. package/dist/extensions/lsp/index.js.map +1 -0
  273. package/dist/extensions/lsp/server.d.ts +68 -0
  274. package/dist/extensions/lsp/server.d.ts.map +1 -0
  275. package/dist/extensions/lsp/server.js +373 -0
  276. package/dist/extensions/lsp/server.js.map +1 -0
  277. package/dist/extensions/lsp/tool.d.ts +43 -0
  278. package/dist/extensions/lsp/tool.d.ts.map +1 -0
  279. package/dist/extensions/lsp/tool.js +534 -0
  280. package/dist/extensions/lsp/tool.js.map +1 -0
  281. package/dist/extensions/memory/index.d.ts +15 -0
  282. package/dist/extensions/memory/index.d.ts.map +1 -0
  283. package/dist/extensions/memory/index.js +336 -0
  284. package/dist/extensions/memory/index.js.map +1 -0
  285. package/dist/extensions/memory/memory-agent.d.ts +29 -0
  286. package/dist/extensions/memory/memory-agent.d.ts.map +1 -0
  287. package/dist/extensions/memory/memory-agent.js +102 -0
  288. package/dist/extensions/memory/memory-agent.js.map +1 -0
  289. package/dist/extensions/memory/prompts.d.ts +18 -0
  290. package/dist/extensions/memory/prompts.d.ts.map +1 -0
  291. package/dist/extensions/memory/prompts.js +124 -0
  292. package/dist/extensions/memory/prompts.js.map +1 -0
  293. package/dist/extensions/memory/recall.d.ts +14 -0
  294. package/dist/extensions/memory/recall.d.ts.map +1 -0
  295. package/dist/extensions/memory/recall.js +80 -0
  296. package/dist/extensions/memory/recall.js.map +1 -0
  297. package/dist/extensions/memory/store.d.ts +48 -0
  298. package/dist/extensions/memory/store.d.ts.map +1 -0
  299. package/dist/extensions/memory/store.js +132 -0
  300. package/dist/extensions/memory/store.js.map +1 -0
  301. package/dist/extensions/skills/bundled/batch/SKILL.md +74 -0
  302. package/dist/extensions/skills/bundled/review/SKILL.md +93 -0
  303. package/dist/extensions/skills/index.d.ts +15 -0
  304. package/dist/extensions/skills/index.d.ts.map +1 -0
  305. package/dist/extensions/skills/index.js +68 -0
  306. package/dist/extensions/skills/index.js.map +1 -0
  307. package/dist/extensions/skills/learn.d.ts +9 -0
  308. package/dist/extensions/skills/learn.d.ts.map +1 -0
  309. package/dist/extensions/skills/learn.js +46 -0
  310. package/dist/extensions/skills/learn.js.map +1 -0
  311. package/dist/extensions/todo/index.d.ts +14 -0
  312. package/dist/extensions/todo/index.d.ts.map +1 -0
  313. package/dist/extensions/todo/index.js +55 -0
  314. package/dist/extensions/todo/index.js.map +1 -0
  315. package/dist/extensions/todo/todos.d.ts +64 -0
  316. package/dist/extensions/todo/todos.d.ts.map +1 -0
  317. package/dist/extensions/todo/todos.js +145 -0
  318. package/dist/extensions/todo/todos.js.map +1 -0
  319. package/dist/extensions/todo/tool.d.ts +23 -0
  320. package/dist/extensions/todo/tool.d.ts.map +1 -0
  321. package/dist/extensions/todo/tool.js +104 -0
  322. package/dist/extensions/todo/tool.js.map +1 -0
  323. package/dist/extensions/web-fetch/fetch-tool.d.ts +27 -0
  324. package/dist/extensions/web-fetch/fetch-tool.d.ts.map +1 -0
  325. package/dist/extensions/web-fetch/fetch-tool.js +319 -0
  326. package/dist/extensions/web-fetch/fetch-tool.js.map +1 -0
  327. package/dist/extensions/web-fetch/html-to-markdown.d.ts +7 -0
  328. package/dist/extensions/web-fetch/html-to-markdown.d.ts.map +1 -0
  329. package/dist/extensions/web-fetch/html-to-markdown.js +21 -0
  330. package/dist/extensions/web-fetch/html-to-markdown.js.map +1 -0
  331. package/dist/extensions/web-fetch/index.d.ts +10 -0
  332. package/dist/extensions/web-fetch/index.d.ts.map +1 -0
  333. package/dist/extensions/web-fetch/index.js +13 -0
  334. package/dist/extensions/web-fetch/index.js.map +1 -0
  335. package/dist/extensions/web-fetch/page-fetch.d.ts +45 -0
  336. package/dist/extensions/web-fetch/page-fetch.d.ts.map +1 -0
  337. package/dist/extensions/web-fetch/page-fetch.js +117 -0
  338. package/dist/extensions/web-fetch/page-fetch.js.map +1 -0
  339. package/dist/extensions/web-fetch/pdf-text.d.ts +29 -0
  340. package/dist/extensions/web-fetch/pdf-text.d.ts.map +1 -0
  341. package/dist/extensions/web-fetch/pdf-text.js +71 -0
  342. package/dist/extensions/web-fetch/pdf-text.js.map +1 -0
  343. package/dist/extensions/web-fetch/preapproved-hosts.d.ts +7 -0
  344. package/dist/extensions/web-fetch/preapproved-hosts.d.ts.map +1 -0
  345. package/dist/extensions/web-fetch/preapproved-hosts.js +110 -0
  346. package/dist/extensions/web-fetch/preapproved-hosts.js.map +1 -0
  347. package/dist/extensions/web-search/dashscope-search.d.ts +29 -0
  348. package/dist/extensions/web-search/dashscope-search.d.ts.map +1 -0
  349. package/dist/extensions/web-search/dashscope-search.js +279 -0
  350. package/dist/extensions/web-search/dashscope-search.js.map +1 -0
  351. package/dist/extensions/web-search/index.d.ts +15 -0
  352. package/dist/extensions/web-search/index.d.ts.map +1 -0
  353. package/dist/extensions/web-search/index.js +51 -0
  354. package/dist/extensions/web-search/index.js.map +1 -0
  355. package/dist/extensions/web-search/search-config.d.ts +53 -0
  356. package/dist/extensions/web-search/search-config.d.ts.map +1 -0
  357. package/dist/extensions/web-search/search-config.js +174 -0
  358. package/dist/extensions/web-search/search-config.js.map +1 -0
  359. package/dist/extensions/web-search/search-tool.d.ts +29 -0
  360. package/dist/extensions/web-search/search-tool.d.ts.map +1 -0
  361. package/dist/extensions/web-search/search-tool.js +149 -0
  362. package/dist/extensions/web-search/search-tool.js.map +1 -0
  363. package/dist/extensions/worktree/git-worktree.d.ts +69 -0
  364. package/dist/extensions/worktree/git-worktree.d.ts.map +1 -0
  365. package/dist/extensions/worktree/git-worktree.js +199 -0
  366. package/dist/extensions/worktree/git-worktree.js.map +1 -0
  367. package/dist/extensions/worktree/index.d.ts +27 -0
  368. package/dist/extensions/worktree/index.d.ts.map +1 -0
  369. package/dist/extensions/worktree/index.js +188 -0
  370. package/dist/extensions/worktree/index.js.map +1 -0
  371. package/dist/extensions/worktree/startup.d.ts +17 -0
  372. package/dist/extensions/worktree/startup.d.ts.map +1 -0
  373. package/dist/extensions/worktree/startup.js +56 -0
  374. package/dist/extensions/worktree/startup.js.map +1 -0
  375. package/dist/main.d.ts.map +1 -1
  376. package/dist/main.js +28 -4
  377. package/dist/main.js.map +1 -1
  378. package/dist/modes/interactive/components/custom-editor.d.ts +18 -0
  379. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  380. package/dist/modes/interactive/components/custom-editor.js +87 -20
  381. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  382. package/dist/modes/interactive/components/diffra-logo.d.ts +6 -0
  383. package/dist/modes/interactive/components/diffra-logo.d.ts.map +1 -1
  384. package/dist/modes/interactive/components/diffra-logo.js +30 -4
  385. package/dist/modes/interactive/components/diffra-logo.js.map +1 -1
  386. package/dist/modes/interactive/components/dynamic-border.d.ts +1 -1
  387. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  388. package/dist/modes/interactive/components/dynamic-border.js +3 -3
  389. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  390. package/dist/modes/interactive/components/footer.d.ts +16 -0
  391. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  392. package/dist/modes/interactive/components/footer.js +84 -46
  393. package/dist/modes/interactive/components/footer.js.map +1 -1
  394. package/dist/modes/interactive/components/tool-execution.d.ts +5 -2
  395. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  396. package/dist/modes/interactive/components/tool-execution.js +152 -62
  397. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  398. package/dist/modes/interactive/components/tool-status.d.ts +5 -0
  399. package/dist/modes/interactive/components/tool-status.d.ts.map +1 -0
  400. package/dist/modes/interactive/components/tool-status.js +15 -0
  401. package/dist/modes/interactive/components/tool-status.js.map +1 -0
  402. package/dist/modes/interactive/components/user-message.d.ts +4 -8
  403. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  404. package/dist/modes/interactive/components/user-message.js +38 -36
  405. package/dist/modes/interactive/components/user-message.js.map +1 -1
  406. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  407. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  408. package/dist/modes/interactive/interactive-mode.js +24 -8
  409. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  410. package/dist/modes/interactive/theme/dark.json +3 -2
  411. package/dist/modes/interactive/theme/light.json +3 -2
  412. package/dist/modes/interactive/theme/system-theme.d.ts +1 -0
  413. package/dist/modes/interactive/theme/system-theme.d.ts.map +1 -1
  414. package/dist/modes/interactive/theme/system-theme.js +41 -14
  415. package/dist/modes/interactive/theme/system-theme.js.map +1 -1
  416. package/dist/utils/shell.d.ts +1 -1
  417. package/dist/utils/shell.d.ts.map +1 -1
  418. package/dist/utils/shell.js +12 -2
  419. package/dist/utils/shell.js.map +1 -1
  420. package/dist/utils/tools-manager.d.ts +5 -0
  421. package/dist/utils/tools-manager.d.ts.map +1 -1
  422. package/dist/utils/tools-manager.js +48 -0
  423. package/dist/utils/tools-manager.js.map +1 -1
  424. package/docs/approval-modes.md +99 -0
  425. package/docs/builtin-skills.md +53 -0
  426. package/docs/cli.md +380 -356
  427. package/docs/docs.json +264 -220
  428. package/docs/environment-variables.md +110 -103
  429. package/docs/extensions.md +24 -0
  430. package/docs/goals.md +84 -0
  431. package/docs/hooks.md +112 -0
  432. package/docs/keybindings.md +1 -0
  433. package/docs/lsp.md +71 -0
  434. package/docs/memory.md +71 -0
  435. package/docs/sandbox.md +108 -0
  436. package/docs/scheduled-tasks.md +84 -0
  437. package/docs/security.md +100 -99
  438. package/docs/settings.md +198 -173
  439. package/docs/shell-aliases.md +1 -1
  440. package/docs/skills.md +4 -0
  441. package/docs/slash-commands.md +15 -0
  442. package/docs/subagents.md +102 -0
  443. package/docs/web-tools.md +83 -0
  444. package/docs/windows.md +2 -1
  445. package/docs/worktrees.md +52 -0
  446. package/examples/extensions/README.md +1 -1
  447. package/examples/extensions/plan-mode/README.md +2 -2
  448. package/examples/extensions/plan-mode/index.ts +7 -4
  449. package/examples/extensions/subagent/README.md +2 -0
  450. package/examples/extensions/subagent/index.ts +3 -0
  451. package/examples/extensions/todo.ts +4 -0
  452. package/package.json +9 -8
  453. package/schemas/keybindings.schema.json +4 -0
  454. package/schemas/settings.schema.json +421 -0
  455. package/dist/bundle/chunks/chunk-GCKVPVMH.js +0 -2
  456. package/dist/bundle/chunks/chunk-UNQMECQ4.js +0 -1240
  457. package/dist/bundle/chunks/virtual-modules-TRFD5ZOL.js +0 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background.d.ts","sourceRoot":"","sources":["../../../src/extensions/agents/background.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE3F,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,C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AAC,eAAe,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAW5F;AAED,oGAAoG;AACpG,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAqBpF"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Background subagents: runs the `agent` tool started without waiting for them. At most a set number
3
+ * run at once and the rest wait in order; each ends with a `<task-notification>` for the parent agent.
4
+ */
5
+ import { randomBytes } from "node:crypto";
6
+ /** Background agents of one session, with a cap on how many run at once. */
7
+ export class BackgroundAgents {
8
+ agents = new Map();
9
+ waiting = [];
10
+ getLimit;
11
+ onChange;
12
+ constructor(options) {
13
+ this.getLimit = options.getLimit;
14
+ this.onChange = options.onChange;
15
+ }
16
+ /** Register an agent and run it now, or once a slot frees. `run` must settle its status. */
17
+ launch(fields, run) {
18
+ const agent = {
19
+ ...fields,
20
+ id: `${fields.agentType}-${randomBytes(4).toString("hex")}`,
21
+ status: "queued",
22
+ queuedAt: Date.now(),
23
+ controller: new AbortController(),
24
+ };
25
+ this.agents.set(agent.id, agent);
26
+ this.waiting.push({ agent, run: () => run(agent) });
27
+ this.startWaiting();
28
+ return agent;
29
+ }
30
+ get(id) {
31
+ return this.agents.get(id);
32
+ }
33
+ list() {
34
+ return [...this.agents.values()];
35
+ }
36
+ /** Agents that have not finished yet. */
37
+ active() {
38
+ return this.list().filter((agent) => agent.status === "queued" || agent.status === "running");
39
+ }
40
+ /** Cancel a queued or running agent. Returns false when it already finished. */
41
+ stop(id) {
42
+ const agent = this.agents.get(id);
43
+ if (!agent || (agent.status !== "queued" && agent.status !== "running"))
44
+ return false;
45
+ agent.controller.abort();
46
+ const index = this.waiting.findIndex((entry) => entry.agent === agent);
47
+ if (index !== -1) {
48
+ this.waiting.splice(index, 1);
49
+ agent.status = "cancelled";
50
+ agent.endedAt = Date.now();
51
+ this.onChange();
52
+ }
53
+ return true;
54
+ }
55
+ /** Cancel every agent and forget them, for example when the session changes. */
56
+ stopAll() {
57
+ for (const agent of this.active())
58
+ agent.controller.abort();
59
+ this.waiting.length = 0;
60
+ this.agents.clear();
61
+ this.onChange();
62
+ }
63
+ /** Record progress of a running agent. */
64
+ update(agent) {
65
+ this.onChange();
66
+ if (agent.status !== "queued" && agent.status !== "running")
67
+ this.startWaiting();
68
+ }
69
+ startWaiting() {
70
+ while (this.waiting.length > 0 &&
71
+ this.list().filter((agent) => agent.status === "running").length < this.getLimit()) {
72
+ const next = this.waiting.shift();
73
+ if (!next)
74
+ break;
75
+ next.agent.status = "running";
76
+ next.agent.startedAt = Date.now();
77
+ const agent = next.agent;
78
+ next.run().catch((error) => {
79
+ agent.status = "failed";
80
+ agent.result = error instanceof Error ? error.message : String(error);
81
+ agent.endedAt = Date.now();
82
+ this.onChange();
83
+ });
84
+ }
85
+ this.onChange();
86
+ }
87
+ }
88
+ /** The status and result text of a finished run. */
89
+ export function settle(agent, outcome) {
90
+ agent.endedAt = Date.now();
91
+ if (outcome.kind === "goal") {
92
+ agent.status = "completed";
93
+ agent.result = outcome.text;
94
+ }
95
+ else if (outcome.kind === "cancelled") {
96
+ agent.status = "cancelled";
97
+ agent.result = outcome.partial;
98
+ }
99
+ else {
100
+ agent.status = outcome.kind === "error" ? "failed" : "completed";
101
+ agent.result = incompleteResult(outcome);
102
+ }
103
+ }
104
+ /** The model-facing text of an incomplete run: the reason, then what the agent produced. */
105
+ export function incompleteResult(outcome) {
106
+ switch (outcome.kind) {
107
+ case "error":
108
+ return `Subagent did not complete (terminate mode: ERROR). ${outcome.message}${outcome.partial ? `\nOutput captured before the failure follows:\n${outcome.partial}` : ""}`;
109
+ case "cancelled":
110
+ return `Agent was cancelled by the user.${outcome.partial ? `\nPartial result follows:\n${outcome.partial}` : ""}`;
111
+ case "timeout":
112
+ return `Subagent did not complete (terminate mode: TIMEOUT). It ran out of time, so re-running the same call will time out again; raise the agent's \`runConfig.max_time_minutes\` instead.${outcome.partial ? `\n${outcome.partial}` : ""}`;
113
+ case "max-turns":
114
+ return `Subagent did not complete (terminate mode: MAX_TURNS). It ran out of turns, so re-running the same call will stop at the same point; raise the agent's \`maxTurns\` (or \`runConfig.max_turns\`) instead.${outcome.partial ? `\n${outcome.partial}` : ""}`;
115
+ }
116
+ }
117
+ /** The `<task-notification>` message the parent agent receives when a background agent finishes. */
118
+ export function formatNotification(agent, remaining) {
119
+ const summary = agent.status === "cancelled"
120
+ ? `Agent "${agent.description}" was cancelled.`
121
+ : `Agent "${agent.description}" ${agent.status === "failed" ? "failed" : "completed"}.`;
122
+ const progress = agent.progress;
123
+ const duration = (agent.endedAt ?? Date.now()) - (agent.startedAt ?? agent.queuedAt);
124
+ const lines = [
125
+ "<task-notification>",
126
+ `<task-id>${escapeXml(agent.id)}</task-id>`,
127
+ `<tool-use-id>${escapeXml(agent.toolCallId)}</tool-use-id>`,
128
+ `<status>${agent.status}</status>`,
129
+ `<summary>${escapeXml(summary)}</summary>`,
130
+ `<remaining>${remaining}</remaining>`,
131
+ `<all-terminal>${remaining === 0}</all-terminal>`,
132
+ `<result>${escapeXml(agent.status === "failed" ? `Error: ${agent.result ?? ""}` : (agent.result ?? ""))}</result>`,
133
+ ...(agent.outputFile ? [`<output-file>${escapeXml(agent.outputFile)}</output-file>`] : []),
134
+ `<usage><total_tokens>${progress?.tokens ?? 0}</total_tokens><tool_uses>${progress?.toolUses ?? 0}</tool_uses><duration_ms>${duration}</duration_ms></usage>`,
135
+ "</task-notification>",
136
+ ];
137
+ return lines.join("\n");
138
+ }
139
+ function escapeXml(text) {
140
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
141
+ }
142
+ //# sourceMappingURL=background.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"background.js","sourceRoot":"","sources":["../../../src/extensions/agents/background.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAuB1C,4EAA4E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CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC","sourcesContent":["/**\n * Background subagents: runs the `agent` tool started without waiting for them. At most a set number\n * run at once and the rest wait in order; each ends with a `<task-notification>` for the parent agent.\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport type { SubagentOutcome, SubagentProgress } from \"./runner.ts\";\n\nexport type BackgroundStatus = \"queued\" | \"running\" | \"completed\" | \"failed\" | \"cancelled\";\n\n/** One background subagent and its live state. */\nexport interface BackgroundAgent {\n\tid: string;\n\tagentType: string;\n\tdescription: string;\n\t/** The `agent` call that started it. */\n\ttoolCallId: string;\n\tstatus: BackgroundStatus;\n\tqueuedAt: number;\n\tstartedAt?: number;\n\tendedAt?: number;\n\tprogress?: SubagentProgress;\n\t/** The final text, or the partial text and reason for an incomplete run. */\n\tresult?: string;\n\toutputFile?: string;\n\tcontroller: AbortController;\n}\n\n/** Background agents of one session, with a cap on how many run at once. */\nexport class BackgroundAgents {\n\tprivate readonly agents = new Map<string, BackgroundAgent>();\n\tprivate readonly waiting: Array<{ agent: BackgroundAgent; run: () => Promise<void> }> = [];\n\tprivate readonly getLimit: () => number;\n\tprivate readonly onChange: () => void;\n\n\tconstructor(options: { getLimit(): number; onChange(): void }) {\n\t\tthis.getLimit = options.getLimit;\n\t\tthis.onChange = options.onChange;\n\t}\n\n\t/** Register an agent and run it now, or once a slot frees. `run` must settle its status. */\n\tlaunch(\n\t\tfields: Pick<BackgroundAgent, \"agentType\" | \"description\" | \"toolCallId\">,\n\t\trun: (agent: BackgroundAgent) => Promise<void>,\n\t): BackgroundAgent {\n\t\tconst agent: BackgroundAgent = {\n\t\t\t...fields,\n\t\t\tid: `${fields.agentType}-${randomBytes(4).toString(\"hex\")}`,\n\t\t\tstatus: \"queued\",\n\t\t\tqueuedAt: Date.now(),\n\t\t\tcontroller: new AbortController(),\n\t\t};\n\t\tthis.agents.set(agent.id, agent);\n\t\tthis.waiting.push({ agent, run: () => run(agent) });\n\t\tthis.startWaiting();\n\t\treturn agent;\n\t}\n\n\tget(id: string): BackgroundAgent | undefined {\n\t\treturn this.agents.get(id);\n\t}\n\n\tlist(): BackgroundAgent[] {\n\t\treturn [...this.agents.values()];\n\t}\n\n\t/** Agents that have not finished yet. */\n\tactive(): BackgroundAgent[] {\n\t\treturn this.list().filter((agent) => agent.status === \"queued\" || agent.status === \"running\");\n\t}\n\n\t/** Cancel a queued or running agent. Returns false when it already finished. */\n\tstop(id: string): boolean {\n\t\tconst agent = this.agents.get(id);\n\t\tif (!agent || (agent.status !== \"queued\" && agent.status !== \"running\")) return false;\n\t\tagent.controller.abort();\n\t\tconst index = this.waiting.findIndex((entry) => entry.agent === agent);\n\t\tif (index !== -1) {\n\t\t\tthis.waiting.splice(index, 1);\n\t\t\tagent.status = \"cancelled\";\n\t\t\tagent.endedAt = Date.now();\n\t\t\tthis.onChange();\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Cancel every agent and forget them, for example when the session changes. */\n\tstopAll(): void {\n\t\tfor (const agent of this.active()) agent.controller.abort();\n\t\tthis.waiting.length = 0;\n\t\tthis.agents.clear();\n\t\tthis.onChange();\n\t}\n\n\t/** Record progress of a running agent. */\n\tupdate(agent: BackgroundAgent): void {\n\t\tthis.onChange();\n\t\tif (agent.status !== \"queued\" && agent.status !== \"running\") this.startWaiting();\n\t}\n\n\tprivate startWaiting(): void {\n\t\twhile (\n\t\t\tthis.waiting.length > 0 &&\n\t\t\tthis.list().filter((agent) => agent.status === \"running\").length < this.getLimit()\n\t\t) {\n\t\t\tconst next = this.waiting.shift();\n\t\t\tif (!next) break;\n\t\t\tnext.agent.status = \"running\";\n\t\t\tnext.agent.startedAt = Date.now();\n\t\t\tconst agent = next.agent;\n\t\t\tnext.run().catch((error: unknown) => {\n\t\t\t\tagent.status = \"failed\";\n\t\t\t\tagent.result = error instanceof Error ? error.message : String(error);\n\t\t\t\tagent.endedAt = Date.now();\n\t\t\t\tthis.onChange();\n\t\t\t});\n\t\t}\n\t\tthis.onChange();\n\t}\n}\n\n/** The status and result text of a finished run. */\nexport function settle(agent: BackgroundAgent, outcome: SubagentOutcome): void {\n\tagent.endedAt = Date.now();\n\tif (outcome.kind === \"goal\") {\n\t\tagent.status = \"completed\";\n\t\tagent.result = outcome.text;\n\t} else if (outcome.kind === \"cancelled\") {\n\t\tagent.status = \"cancelled\";\n\t\tagent.result = outcome.partial;\n\t} else {\n\t\tagent.status = outcome.kind === \"error\" ? \"failed\" : \"completed\";\n\t\tagent.result = incompleteResult(outcome);\n\t}\n}\n\n/** The model-facing text of an incomplete run: the reason, then what the agent produced. */\nexport function incompleteResult(outcome: Exclude<SubagentOutcome, { kind: \"goal\" }>): string {\n\tswitch (outcome.kind) {\n\t\tcase \"error\":\n\t\t\treturn `Subagent did not complete (terminate mode: ERROR). ${outcome.message}${outcome.partial ? `\\nOutput captured before the failure follows:\\n${outcome.partial}` : \"\"}`;\n\t\tcase \"cancelled\":\n\t\t\treturn `Agent was cancelled by the user.${outcome.partial ? `\\nPartial result follows:\\n${outcome.partial}` : \"\"}`;\n\t\tcase \"timeout\":\n\t\t\treturn `Subagent did not complete (terminate mode: TIMEOUT). It ran out of time, so re-running the same call will time out again; raise the agent's \\`runConfig.max_time_minutes\\` instead.${outcome.partial ? `\\n${outcome.partial}` : \"\"}`;\n\t\tcase \"max-turns\":\n\t\t\treturn `Subagent did not complete (terminate mode: MAX_TURNS). It ran out of turns, so re-running the same call will stop at the same point; raise the agent's \\`maxTurns\\` (or \\`runConfig.max_turns\\`) instead.${outcome.partial ? `\\n${outcome.partial}` : \"\"}`;\n\t}\n}\n\n/** The `<task-notification>` message the parent agent receives when a background agent finishes. */\nexport function formatNotification(agent: BackgroundAgent, remaining: number): string {\n\tconst summary =\n\t\tagent.status === \"cancelled\"\n\t\t\t? `Agent \"${agent.description}\" was cancelled.`\n\t\t\t: `Agent \"${agent.description}\" ${agent.status === \"failed\" ? \"failed\" : \"completed\"}.`;\n\tconst progress = agent.progress;\n\tconst duration = (agent.endedAt ?? Date.now()) - (agent.startedAt ?? agent.queuedAt);\n\tconst lines = [\n\t\t\"<task-notification>\",\n\t\t`<task-id>${escapeXml(agent.id)}</task-id>`,\n\t\t`<tool-use-id>${escapeXml(agent.toolCallId)}</tool-use-id>`,\n\t\t`<status>${agent.status}</status>`,\n\t\t`<summary>${escapeXml(summary)}</summary>`,\n\t\t`<remaining>${remaining}</remaining>`,\n\t\t`<all-terminal>${remaining === 0}</all-terminal>`,\n\t\t`<result>${escapeXml(agent.status === \"failed\" ? `Error: ${agent.result ?? \"\"}` : (agent.result ?? \"\"))}</result>`,\n\t\t...(agent.outputFile ? [`<output-file>${escapeXml(agent.outputFile)}</output-file>`] : []),\n\t\t`<usage><total_tokens>${progress?.tokens ?? 0}</total_tokens><tool_uses>${progress?.toolUses ?? 0}</tool_uses><duration_ms>${duration}</duration_ms></usage>`,\n\t\t\"</task-notification>\",\n\t];\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(text: string): string {\n\treturn text.replace(/&/g, \"&amp;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\");\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The built-in subagents: `general-purpose`, the default type, and `Explore`, a read-only searcher.
3
+ * A project or user file with the same name replaces one.
4
+ */
5
+ import type { AgentDefinition } from "./definitions.ts";
6
+ export declare const DEFAULT_AGENT_TYPE = "general-purpose";
7
+ export declare const BUILTIN_AGENTS: readonly AgentDefinition[];
8
+ //# sourceMappingURL=builtin-agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtin-agents.d.ts","sourceRoot":"","sources":["../../../src/extensions/agents/builtin-agents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,kBAAkB,oBAAoB,CAAC;AAEpD,eAAO,MAAM,cAAc,EAAE,SAAS,eAAe,EAiCpD,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The built-in subagents: `general-purpose`, the default type, and `Explore`, a read-only searcher.
3
+ * A project or user file with the same name replaces one.
4
+ */
5
+ export const DEFAULT_AGENT_TYPE = "general-purpose";
6
+ export const BUILTIN_AGENTS = [
7
+ {
8
+ name: DEFAULT_AGENT_TYPE,
9
+ description: "General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you.",
10
+ level: "builtin",
11
+ systemPrompt: `You are a general-purpose agent working on one scoped task for a coding agent that delegated it to you.
12
+
13
+ - Inspect the relevant code before changing anything, and keep to the scope of the task.
14
+ - Preserve changes you did not make, and prefer editing existing files to creating new ones. Do not create documentation files unless the task asks for them.
15
+ - Verify your claims against the code or command output, and state what you could not verify.
16
+
17
+ When you finish, reply with a concise report: the result and the key evidence, the files you changed, what you verified and how, and anything that blocked you. Use absolute paths when you mention files.`,
18
+ },
19
+ {
20
+ name: "Explore",
21
+ description: 'Fast read-only agent for exploring codebases: finding files by pattern, searching code for keywords, and answering questions about how the code works. Say how thorough it should be: "quick", "medium", or "very thorough".',
22
+ level: "builtin",
23
+ tools: ["read", "grep", "find", "ls", "bash", "web_fetch"],
24
+ systemPrompt: `You are a file search specialist. You explore codebases quickly and report what you find.
25
+
26
+ CRITICAL: READ-ONLY MODE
27
+ - Do not create, modify, delete, or move files, and do not create temporary files.
28
+ - Use the shell only for read-only commands (such as ls, git status, git log, git diff, cat, head); never redirect output into files.
29
+
30
+ How to work:
31
+ - Use find for file name patterns, grep for content, and read for files you know.
32
+ - Run independent searches in parallel tool calls to be fast.
33
+ - Adapt your depth to the thoroughness the caller asked for: "quick" for a targeted lookup, "medium" for a balanced search, "very thorough" for a comprehensive one.
34
+
35
+ Report your findings concisely, with absolute file paths and the relevant lines.`,
36
+ },
37
+ ];
38
+ //# sourceMappingURL=builtin-agents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtin-agents.js","sourceRoot":"","sources":["../../../src/extensions/agents/builtin-agents.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAEpD,MAAM,CAAC,MAAM,cAAc,GAA+B;IACzD;QACC,IAAI,EAAE,kBAAkB;QACxB,WAAW,EACV,yRAAyR;QAC1R,KAAK,EAAE,SAAS;QAChB,YAAY,EAAE;;;;;;2MAM2L;KACzM;IACD;QACC,IAAI,EAAE,SAAS;QACf,WAAW,EACV,8NAA8N;QAC/N,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC;QAC1D,YAAY,EAAE;;;;;;;;;;;iFAWiE;KAC/E;CACD,CAAC","sourcesContent":["/**\n * The built-in subagents: `general-purpose`, the default type, and `Explore`, a read-only searcher.\n * A project or user file with the same name replaces one.\n */\n\nimport type { AgentDefinition } from \"./definitions.ts\";\n\nexport const DEFAULT_AGENT_TYPE = \"general-purpose\";\n\nexport const BUILTIN_AGENTS: readonly AgentDefinition[] = [\n\t{\n\t\tname: DEFAULT_AGENT_TYPE,\n\t\tdescription:\n\t\t\t\"General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you.\",\n\t\tlevel: \"builtin\",\n\t\tsystemPrompt: `You are a general-purpose agent working on one scoped task for a coding agent that delegated it to you.\n\n- Inspect the relevant code before changing anything, and keep to the scope of the task.\n- Preserve changes you did not make, and prefer editing existing files to creating new ones. Do not create documentation files unless the task asks for them.\n- Verify your claims against the code or command output, and state what you could not verify.\n\nWhen you finish, reply with a concise report: the result and the key evidence, the files you changed, what you verified and how, and anything that blocked you. Use absolute paths when you mention files.`,\n\t},\n\t{\n\t\tname: \"Explore\",\n\t\tdescription:\n\t\t\t'Fast read-only agent for exploring codebases: finding files by pattern, searching code for keywords, and answering questions about how the code works. Say how thorough it should be: \"quick\", \"medium\", or \"very thorough\".',\n\t\tlevel: \"builtin\",\n\t\ttools: [\"read\", \"grep\", \"find\", \"ls\", \"bash\", \"web_fetch\"],\n\t\tsystemPrompt: `You are a file search specialist. You explore codebases quickly and report what you find.\n\nCRITICAL: READ-ONLY MODE\n- Do not create, modify, delete, or move files, and do not create temporary files.\n- Use the shell only for read-only commands (such as ls, git status, git log, git diff, cat, head); never redirect output into files.\n\nHow to work:\n- Use find for file name patterns, grep for content, and read for files you know.\n- Run independent searches in parallel tool calls to be fast.\n- Adapt your depth to the thoroughness the caller asked for: \"quick\" for a targeted lookup, \"medium\" for a balanced search, \"very thorough\" for a comprehensive one.\n\nReport your findings concisely, with absolute file paths and the relevant lines.`,\n\t},\n];\n"]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Subagent call scopes, announced on `diffra.events`: while a subagent runs, the tool calls it makes
3
+ * have ids below its `agent` call's id. The approval extension applies the subagent's approval mode
4
+ * to them, and denies calls that would need a dialog when the subagent runs in the background.
5
+ */
6
+ import { type ApprovalMode } from "../../core/approval-mode.ts";
7
+ /** Channel on `diffra.events` for {@link SubagentScopeEvent}s. */
8
+ export declare const SUBAGENT_SCOPE_CHANNEL = "diffra:subagent-scope";
9
+ /** A subagent started (its calls have ids `<callId>/...`) or ended, with its final text. */
10
+ export type SubagentScopeEvent = {
11
+ kind: "start";
12
+ callId: string;
13
+ agentType: string;
14
+ background: boolean;
15
+ approvalMode: ApprovalMode;
16
+ } | {
17
+ kind: "end";
18
+ callId: string;
19
+ agentType: string;
20
+ lastMessage: string;
21
+ };
22
+ /** The scope of one running subagent. */
23
+ export interface SubagentScope {
24
+ background: boolean;
25
+ approvalMode: ApprovalMode;
26
+ }
27
+ /** Whether event bus data is a scope event (a trust boundary: any extension can emit on the channel). */
28
+ export declare function isSubagentScopeEvent(value: unknown): value is SubagentScopeEvent;
29
+ /**
30
+ * The scope a call belongs to: the innermost running subagent whose call id prefixes `toolCallId`.
31
+ * A background ancestor makes the scope background too, since nobody can answer its dialogs.
32
+ */
33
+ export declare function findScope(scopes: ReadonlyMap<string, SubagentScope>, toolCallId: string): SubagentScope | undefined;
34
+ //# sourceMappingURL=call-scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-scopes.d.ts","sourceRoot":"","sources":["../../../src/extensions/agents/call-scopes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,6BAA6B,CAAC;AAEhF,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAE9D,4FAA4F;AAC5F,MAAM,MAAM,kBAAkB,GAC3B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAE,GACrG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3E,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;CAC3B;AAED,yGAAyG;AACzG,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAMhF;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CASnH"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Subagent call scopes, announced on `diffra.events`: while a subagent runs, the tool calls it makes
3
+ * have ids below its `agent` call's id. The approval extension applies the subagent's approval mode
4
+ * to them, and denies calls that would need a dialog when the subagent runs in the background.
5
+ */
6
+ import { isApprovalMode } from "../../core/approval-mode.js";
7
+ /** Channel on `diffra.events` for {@link SubagentScopeEvent}s. */
8
+ export const SUBAGENT_SCOPE_CHANNEL = "diffra:subagent-scope";
9
+ /** Whether event bus data is a scope event (a trust boundary: any extension can emit on the channel). */
10
+ export function isSubagentScopeEvent(value) {
11
+ if (typeof value !== "object" || value === null)
12
+ return false;
13
+ const event = value;
14
+ if (typeof event.callId !== "string" || typeof event.agentType !== "string")
15
+ return false;
16
+ if (event.kind === "end")
17
+ return typeof event.lastMessage === "string";
18
+ return event.kind === "start" && typeof event.background === "boolean" && isApprovalMode(event.approvalMode);
19
+ }
20
+ /**
21
+ * The scope a call belongs to: the innermost running subagent whose call id prefixes `toolCallId`.
22
+ * A background ancestor makes the scope background too, since nobody can answer its dialogs.
23
+ */
24
+ export function findScope(scopes, toolCallId) {
25
+ let innermost;
26
+ let background = false;
27
+ for (const [id, scope] of scopes) {
28
+ if (!toolCallId.startsWith(`${id}/`))
29
+ continue;
30
+ background ||= scope.background;
31
+ if (!innermost || id.length > innermost.id.length)
32
+ innermost = { id, scope };
33
+ }
34
+ return innermost ? { ...innermost.scope, background } : undefined;
35
+ }
36
+ //# sourceMappingURL=call-scopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call-scopes.js","sourceRoot":"","sources":["../../../src/extensions/agents/call-scopes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAEhF,kEAAkE;AAClE,MAAM,CAAC,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AAa9D,yGAAyG;AACzG,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,KAAK,GAAG,KAAgC,CAAC;IAC/C,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC1F,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK;QAAE,OAAO,OAAO,KAAK,CAAC,WAAW,KAAK,QAAQ,CAAC;IACvE,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,OAAO,KAAK,CAAC,UAAU,KAAK,SAAS,IAAI,cAAc,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAC9G,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,MAA0C,EAAE,UAAkB;IACvF,IAAI,SAA2D,CAAC;IAChE,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;YAAE,SAAS;QAC/C,UAAU,KAAK,KAAK,CAAC,UAAU,CAAC;QAChC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC,MAAM;YAAE,SAAS,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IAC9E,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACnE,CAAC","sourcesContent":["/**\n * Subagent call scopes, announced on `diffra.events`: while a subagent runs, the tool calls it makes\n * have ids below its `agent` call's id. The approval extension applies the subagent's approval mode\n * to them, and denies calls that would need a dialog when the subagent runs in the background.\n */\n\nimport { type ApprovalMode, isApprovalMode } from \"../../core/approval-mode.ts\";\n\n/** Channel on `diffra.events` for {@link SubagentScopeEvent}s. */\nexport const SUBAGENT_SCOPE_CHANNEL = \"diffra:subagent-scope\";\n\n/** A subagent started (its calls have ids `<callId>/...`) or ended, with its final text. */\nexport type SubagentScopeEvent =\n\t| { kind: \"start\"; callId: string; agentType: string; background: boolean; approvalMode: ApprovalMode }\n\t| { kind: \"end\"; callId: string; agentType: string; lastMessage: string };\n\n/** The scope of one running subagent. */\nexport interface SubagentScope {\n\tbackground: boolean;\n\tapprovalMode: ApprovalMode;\n}\n\n/** Whether event bus data is a scope event (a trust boundary: any extension can emit on the channel). */\nexport function isSubagentScopeEvent(value: unknown): value is SubagentScopeEvent {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst event = value as Record<string, unknown>;\n\tif (typeof event.callId !== \"string\" || typeof event.agentType !== \"string\") return false;\n\tif (event.kind === \"end\") return typeof event.lastMessage === \"string\";\n\treturn event.kind === \"start\" && typeof event.background === \"boolean\" && isApprovalMode(event.approvalMode);\n}\n\n/**\n * The scope a call belongs to: the innermost running subagent whose call id prefixes `toolCallId`.\n * A background ancestor makes the scope background too, since nobody can answer its dialogs.\n */\nexport function findScope(scopes: ReadonlyMap<string, SubagentScope>, toolCallId: string): SubagentScope | undefined {\n\tlet innermost: { id: string; scope: SubagentScope } | undefined;\n\tlet background = false;\n\tfor (const [id, scope] of scopes) {\n\t\tif (!toolCallId.startsWith(`${id}/`)) continue;\n\t\tbackground ||= scope.background;\n\t\tif (!innermost || id.length > innermost.id.length) innermost = { id, scope };\n\t}\n\treturn innermost ? { ...innermost.scope, background } : undefined;\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Subagent definitions: Markdown files with YAML frontmatter in `.diffra/agents/` (project) and
3
+ * `<agent dir>/agents/` (user), plus the built-in agents. The frontmatter configures the agent and the
4
+ * body is its system prompt.
5
+ */
6
+ import { type ApprovalMode } from "../../core/approval-mode.ts";
7
+ export type AgentLevel = "project" | "user" | "builtin";
8
+ /** A subagent ready to run. */
9
+ export interface AgentDefinition {
10
+ name: string;
11
+ description: string;
12
+ systemPrompt: string;
13
+ /** Tools the agent may use; undefined inherits every tool the parent can call. */
14
+ tools?: string[];
15
+ /** Tools removed after `tools` is applied. */
16
+ disallowedTools?: string[];
17
+ /** `inherit` (default), `fast`, or `provider/model-id`. */
18
+ model?: string;
19
+ approvalMode?: ApprovalMode;
20
+ /** Turn limit; none by default. */
21
+ maxTurns?: number;
22
+ /** Time limit in minutes; none by default. */
23
+ maxTimeMinutes?: number;
24
+ color?: string;
25
+ /** Whether calls run in the background unless `run_in_background` says otherwise. */
26
+ background?: boolean;
27
+ level: AgentLevel;
28
+ /** Undefined for built-in agents. */
29
+ filePath?: string;
30
+ }
31
+ /** A definition file that could not be loaded, with the reason. */
32
+ export interface AgentLoadError {
33
+ filePath: string;
34
+ message: string;
35
+ }
36
+ /** Directories definitions load from; `project` is undefined when the project is not trusted. */
37
+ export declare function agentDirectories(cwd: string, projectTrusted: boolean): {
38
+ project?: string;
39
+ user: string;
40
+ };
41
+ /**
42
+ * Every available agent, project first, then user, then built-in; a name defined at a higher level
43
+ * hides the same name below it (compared case-insensitively). Files that fail to load are reported.
44
+ */
45
+ export declare function loadAgents(dirs: {
46
+ project?: string;
47
+ user: string;
48
+ }): {
49
+ agents: AgentDefinition[];
50
+ errors: AgentLoadError[];
51
+ };
52
+ /** Find an agent by name, case-insensitively. */
53
+ export declare function findAgent(agents: readonly AgentDefinition[], name: string): AgentDefinition | undefined;
54
+ /** Parse and validate a definition file (a trust boundary: user-written files). Throws on invalid files. */
55
+ export declare function parseAgentFile(content: string, level: "project" | "user", filePath: string): AgentDefinition;
56
+ /** The problems that make a definition unusable; empty when it is valid. */
57
+ export declare function validateAgent(agent: Pick<AgentDefinition, "name" | "description" | "systemPrompt" | "tools">): string[];
58
+ /** The file content of a definition: frontmatter in a fixed key order, then the prompt. */
59
+ export declare function serializeAgent(agent: Omit<AgentDefinition, "level" | "filePath">): string;
60
+ /** Write a new definition file; refuses to replace an existing one unless `overwrite` is set. */
61
+ export declare function saveAgent(dir: string, agent: Omit<AgentDefinition, "level" | "filePath">, overwrite: boolean): string;
62
+ /** Delete a project or user definition file. */
63
+ export declare function deleteAgent(agent: AgentDefinition): void;
64
+ //# sourceMappingURL=definitions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../../src/extensions/agents/definitions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,6BAA6B,CAAC;AAIhF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAExD,+BAA+B;AAC/B,MAAM,WAAW,eAAe;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,UAAU,CAAC;IAClB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CAChB;AAKD,iGAAiG;AACjG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAKzG;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IACrE,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,MAAM,EAAE,cAAc,EAAE,CAAC;CACzB,CAeA;AAED,iDAAiD;AACjD,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAGvG;AAkBD,4GAA4G;AAC5G,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAkE5G;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAC5B,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,OAAO,CAAC,GAC7E,MAAM,EAAE,CAiBV;AAED,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG,MAAM,CAWzF;AAED,iGAAiG;AACjG,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,UAAU,CAAC,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAYrH;AAED,gDAAgD;AAChD,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAGxD"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Subagent definitions: Markdown files with YAML frontmatter in `.diffra/agents/` (project) and
3
+ * `<agent dir>/agents/` (user), plus the built-in agents. The frontmatter configures the agent and the
4
+ * body is its system prompt.
5
+ */
6
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import { stringify } from "yaml";
9
+ import { CONFIG_DIR_NAME, getAgentDir } from "../../config.js";
10
+ import { isApprovalMode } from "../../core/approval-mode.js";
11
+ import { parseFrontmatter } from "../../utils/frontmatter.js";
12
+ import { BUILTIN_AGENTS } from "./builtin-agents.js";
13
+ const COLORS = new Set(["red", "blue", "green", "yellow", "purple", "orange", "pink", "cyan"]);
14
+ const RESERVED_NAMES = new Set(["self", "system", "user", "model", "tool", "config", "default", "main"]);
15
+ /** Directories definitions load from; `project` is undefined when the project is not trusted. */
16
+ export function agentDirectories(cwd, projectTrusted) {
17
+ return {
18
+ ...(projectTrusted ? { project: join(cwd, CONFIG_DIR_NAME, "agents") } : {}),
19
+ user: join(getAgentDir(), "agents"),
20
+ };
21
+ }
22
+ /**
23
+ * Every available agent, project first, then user, then built-in; a name defined at a higher level
24
+ * hides the same name below it (compared case-insensitively). Files that fail to load are reported.
25
+ */
26
+ export function loadAgents(dirs) {
27
+ const errors = [];
28
+ const levels = [
29
+ ["project", dirs.project ? loadDirectory(dirs.project, "project", errors) : []],
30
+ ["user", loadDirectory(dirs.user, "user", errors)],
31
+ ["builtin", BUILTIN_AGENTS],
32
+ ];
33
+ const byName = new Map();
34
+ for (const [, agents] of levels) {
35
+ for (const agent of agents) {
36
+ const key = agent.name.toLowerCase();
37
+ if (!byName.has(key))
38
+ byName.set(key, agent);
39
+ }
40
+ }
41
+ return { agents: [...byName.values()], errors };
42
+ }
43
+ /** Find an agent by name, case-insensitively. */
44
+ export function findAgent(agents, name) {
45
+ const key = name.toLowerCase();
46
+ return agents.find((agent) => agent.name.toLowerCase() === key);
47
+ }
48
+ function loadDirectory(dir, level, errors) {
49
+ if (!existsSync(dir) || !statSync(dir).isDirectory())
50
+ return [];
51
+ const agents = [];
52
+ for (const entry of readdirSync(dir)
53
+ .filter((name) => name.endsWith(".md"))
54
+ .sort()) {
55
+ const filePath = join(dir, entry);
56
+ try {
57
+ agents.push(parseAgentFile(readFileSync(filePath, "utf-8"), level, filePath));
58
+ }
59
+ catch (error) {
60
+ errors.push({ filePath, message: error instanceof Error ? error.message : String(error) });
61
+ }
62
+ }
63
+ return agents;
64
+ }
65
+ /** Parse and validate a definition file (a trust boundary: user-written files). Throws on invalid files. */
66
+ export function parseAgentFile(content, level, filePath) {
67
+ const normalized = content.replace(/\r\n?/g, "\n");
68
+ if (!/^()?---\n[\s\S]*?\n---(\n|$)/.test(normalized)) {
69
+ throw new Error("Failed to parse subagent file: Invalid format: missing YAML frontmatter");
70
+ }
71
+ let parsed;
72
+ try {
73
+ parsed = parseFrontmatter(normalized);
74
+ }
75
+ catch (error) {
76
+ throw new Error(`Failed to parse subagent file: ${error instanceof Error ? error.message : String(error)}`);
77
+ }
78
+ const fm = parsed.frontmatter;
79
+ const name = fm.name === undefined || fm.name === null ? "" : String(fm.name).trim();
80
+ if (!name)
81
+ throw new Error('Failed to parse subagent file: Missing "name" in frontmatter');
82
+ const description = fm.description === undefined || fm.description === null ? "" : String(fm.description).trim();
83
+ if (!description)
84
+ throw new Error('Failed to parse subagent file: Missing "description" in frontmatter');
85
+ let approvalMode;
86
+ if (fm.approvalMode !== undefined) {
87
+ if (typeof fm.approvalMode !== "string") {
88
+ throw new Error(`Failed to parse subagent file: Invalid "approvalMode" value: expected a string, got ${typeof fm.approvalMode}. Valid values: plan, default, auto-edit, auto, yolo`);
89
+ }
90
+ if (!isApprovalMode(fm.approvalMode)) {
91
+ throw new Error(`Failed to parse subagent file: Invalid "approvalMode" value "${fm.approvalMode}". Valid values: plan, default, auto-edit, auto, yolo`);
92
+ }
93
+ approvalMode = fm.approvalMode;
94
+ }
95
+ const runConfig = typeof fm.runConfig === "object" && fm.runConfig !== null ? fm.runConfig : {};
96
+ const maxTurns = positiveInteger(fm.maxTurns) ?? positiveInteger(runConfig.max_turns);
97
+ const maxTimeMinutes = typeof runConfig.max_time_minutes === "number" && runConfig.max_time_minutes > 0
98
+ ? runConfig.max_time_minutes
99
+ : undefined;
100
+ const color = typeof fm.color === "string" && COLORS.has(fm.color) ? fm.color : undefined;
101
+ const background = fm.background === true || fm.background === "true"
102
+ ? true
103
+ : fm.background === false || fm.background === "false"
104
+ ? false
105
+ : undefined;
106
+ const model = typeof fm.model === "string" && fm.model.trim() && fm.model.trim() !== "inherit" ? fm.model.trim() : undefined;
107
+ const definition = {
108
+ name,
109
+ description,
110
+ systemPrompt: parsed.body.trim(),
111
+ ...optional("tools", toolList(fm.tools)),
112
+ ...optional("disallowedTools", toolList(fm.disallowedTools)),
113
+ ...optional("model", model),
114
+ ...optional("approvalMode", approvalMode),
115
+ ...optional("maxTurns", maxTurns),
116
+ ...optional("maxTimeMinutes", maxTimeMinutes),
117
+ ...optional("color", color),
118
+ ...optional("background", background),
119
+ level,
120
+ filePath,
121
+ };
122
+ const problems = validateAgent(definition);
123
+ if (problems.length > 0)
124
+ throw new Error(`Validation failed: ${problems.join(", ")}`);
125
+ return definition;
126
+ }
127
+ /** The problems that make a definition unusable; empty when it is valid. */
128
+ export function validateAgent(agent) {
129
+ const problems = [];
130
+ const name = agent.name.trim();
131
+ if (!name)
132
+ problems.push("Name is required and cannot be empty");
133
+ else if (name.length < 2)
134
+ problems.push("Name must be at least 2 characters long");
135
+ else if (name.length > 50)
136
+ problems.push("Name must be 50 characters or less");
137
+ else if (!/^[\p{L}\p{N}_-]+$/u.test(name))
138
+ problems.push("Name can only contain letters, numbers, hyphens, and underscores");
139
+ else if (/^[-_]/.test(name))
140
+ problems.push("Name cannot start with a hyphen or underscore");
141
+ else if (/[-_]$/.test(name))
142
+ problems.push("Name cannot end with a hyphen or underscore");
143
+ else if (RESERVED_NAMES.has(name.toLowerCase()))
144
+ problems.push(`"${name}" is a reserved name and cannot be used`);
145
+ if (!agent.description.trim())
146
+ problems.push("Description is required and cannot be empty");
147
+ const prompt = agent.systemPrompt.trim();
148
+ if (!prompt)
149
+ problems.push("System prompt is required and cannot be empty");
150
+ else if (prompt.length < 10)
151
+ problems.push("System prompt must be at least 10 characters long");
152
+ if (agent.tools?.some((tool) => !tool.trim()))
153
+ problems.push("Tool name cannot be empty");
154
+ return problems;
155
+ }
156
+ /** The file content of a definition: frontmatter in a fixed key order, then the prompt. */
157
+ export function serializeAgent(agent) {
158
+ const frontmatter = { name: agent.name, description: agent.description };
159
+ if (agent.tools)
160
+ frontmatter.tools = agent.tools;
161
+ if (agent.disallowedTools)
162
+ frontmatter.disallowedTools = agent.disallowedTools;
163
+ if (agent.model)
164
+ frontmatter.model = agent.model;
165
+ if (agent.maxTimeMinutes !== undefined)
166
+ frontmatter.runConfig = { max_time_minutes: agent.maxTimeMinutes };
167
+ if (agent.color)
168
+ frontmatter.color = agent.color;
169
+ if (agent.approvalMode)
170
+ frontmatter.approvalMode = agent.approvalMode;
171
+ if (agent.background !== undefined)
172
+ frontmatter.background = agent.background;
173
+ if (agent.maxTurns !== undefined)
174
+ frontmatter.maxTurns = agent.maxTurns;
175
+ return `---\n${stringify(frontmatter, { lineWidth: 0 }).trimEnd()}\n---\n\n${agent.systemPrompt.trim()}\n`;
176
+ }
177
+ /** Write a new definition file; refuses to replace an existing one unless `overwrite` is set. */
178
+ export function saveAgent(dir, agent, overwrite) {
179
+ const problems = validateAgent(agent);
180
+ if (problems.length > 0)
181
+ throw new Error(`Validation failed: ${problems.join(", ")}`);
182
+ const filePath = join(dir, `${agent.name}.md`);
183
+ if (existsSync(filePath) && !overwrite)
184
+ throw new Error(`Subagent "${agent.name}" already exists at ${filePath}`);
185
+ try {
186
+ mkdirSync(dirname(filePath), { recursive: true });
187
+ writeFileSync(filePath, serializeAgent(agent));
188
+ }
189
+ catch (error) {
190
+ throw new Error(`Failed to write subagent file: ${error instanceof Error ? error.message : String(error)}`);
191
+ }
192
+ return filePath;
193
+ }
194
+ /** Delete a project or user definition file. */
195
+ export function deleteAgent(agent) {
196
+ if (!agent.filePath)
197
+ throw new Error(`Built-in agent "${agent.name}" cannot be deleted`);
198
+ unlinkSync(agent.filePath);
199
+ }
200
+ /** `tools: read, bash` and `tools: [read, bash]` are both valid; other values are ignored. */
201
+ function toolList(value) {
202
+ const raw = Array.isArray(value) ? value : typeof value === "string" ? value.split(",") : undefined;
203
+ if (!raw)
204
+ return undefined;
205
+ const tools = raw.filter((item) => typeof item === "string").map((item) => item.trim());
206
+ // An empty list inherits every tool, like an omitted one.
207
+ return tools.length > 0 ? tools : undefined;
208
+ }
209
+ function positiveInteger(value) {
210
+ const number = typeof value === "string" ? Number(value) : value;
211
+ return typeof number === "number" && Number.isInteger(number) && number > 0 ? number : undefined;
212
+ }
213
+ function optional(key, value) {
214
+ return (value === undefined ? {} : { [key]: value });
215
+ }
216
+ //# sourceMappingURL=definitions.js.map