@dirgha/code 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/LICENSE +101 -0
  2. package/README.md +674 -0
  3. package/dist/dirgha.mjs +2185 -0
  4. package/dist_v2/acp/index.d.ts +1 -0
  5. package/dist_v2/acp/index.js +2 -0
  6. package/dist_v2/acp/server.d.ts +31 -0
  7. package/dist_v2/acp/server.js +137 -0
  8. package/dist_v2/cli/auth-cmd.d.ts +10 -0
  9. package/dist_v2/cli/auth-cmd.js +69 -0
  10. package/dist_v2/cli/config.d.ts +46 -0
  11. package/dist_v2/cli/config.js +70 -0
  12. package/dist_v2/cli/flags.d.ts +10 -0
  13. package/dist_v2/cli/flags.js +49 -0
  14. package/dist_v2/cli/flows/full-cycle.d.ts +30 -0
  15. package/dist_v2/cli/flows/full-cycle.js +39 -0
  16. package/dist_v2/cli/flows/index.d.ts +2 -0
  17. package/dist_v2/cli/flows/index.js +3 -0
  18. package/dist_v2/cli/flows/tarball.d.ts +10 -0
  19. package/dist_v2/cli/flows/tarball.js +47 -0
  20. package/dist_v2/cli/index.d.ts +4 -0
  21. package/dist_v2/cli/index.js +5 -0
  22. package/dist_v2/cli/interactive.d.ts +21 -0
  23. package/dist_v2/cli/interactive.js +207 -0
  24. package/dist_v2/cli/main.d.ts +10 -0
  25. package/dist_v2/cli/main.js +173 -0
  26. package/dist_v2/cli/models-cmd.d.ts +6 -0
  27. package/dist_v2/cli/models-cmd.js +50 -0
  28. package/dist_v2/cli/setup.d.ts +13 -0
  29. package/dist_v2/cli/setup.js +128 -0
  30. package/dist_v2/cli/slash/account.d.ts +10 -0
  31. package/dist_v2/cli/slash/account.js +59 -0
  32. package/dist_v2/cli/slash/clear.d.ts +8 -0
  33. package/dist_v2/cli/slash/clear.js +15 -0
  34. package/dist_v2/cli/slash/compact.d.ts +7 -0
  35. package/dist_v2/cli/slash/compact.js +13 -0
  36. package/dist_v2/cli/slash/config.d.ts +8 -0
  37. package/dist_v2/cli/slash/config.js +49 -0
  38. package/dist_v2/cli/slash/exit.d.ts +7 -0
  39. package/dist_v2/cli/slash/exit.js +16 -0
  40. package/dist_v2/cli/slash/fleet.d.ts +7 -0
  41. package/dist_v2/cli/slash/fleet.js +22 -0
  42. package/dist_v2/cli/slash/help.d.ts +9 -0
  43. package/dist_v2/cli/slash/help.js +31 -0
  44. package/dist_v2/cli/slash/history.d.ts +7 -0
  45. package/dist_v2/cli/slash/history.js +42 -0
  46. package/dist_v2/cli/slash/index.d.ts +30 -0
  47. package/dist_v2/cli/slash/index.js +52 -0
  48. package/dist_v2/cli/slash/init.d.ts +8 -0
  49. package/dist_v2/cli/slash/init.js +57 -0
  50. package/dist_v2/cli/slash/keys.d.ts +8 -0
  51. package/dist_v2/cli/slash/keys.js +101 -0
  52. package/dist_v2/cli/slash/login.d.ts +10 -0
  53. package/dist_v2/cli/slash/login.js +47 -0
  54. package/dist_v2/cli/slash/memory.d.ts +8 -0
  55. package/dist_v2/cli/slash/memory.js +101 -0
  56. package/dist_v2/cli/slash/mode.d.ts +8 -0
  57. package/dist_v2/cli/slash/mode.js +30 -0
  58. package/dist_v2/cli/slash/models.d.ts +8 -0
  59. package/dist_v2/cli/slash/models.js +73 -0
  60. package/dist_v2/cli/slash/resume.d.ts +8 -0
  61. package/dist_v2/cli/slash/resume.js +24 -0
  62. package/dist_v2/cli/slash/session.d.ts +8 -0
  63. package/dist_v2/cli/slash/session.js +74 -0
  64. package/dist_v2/cli/slash/setup.d.ts +8 -0
  65. package/dist_v2/cli/slash/setup.js +50 -0
  66. package/dist_v2/cli/slash/status.d.ts +7 -0
  67. package/dist_v2/cli/slash/status.js +37 -0
  68. package/dist_v2/cli/slash/theme.d.ts +9 -0
  69. package/dist_v2/cli/slash/theme.js +53 -0
  70. package/dist_v2/cli/slash/types.d.ts +14 -0
  71. package/dist_v2/cli/slash/types.js +9 -0
  72. package/dist_v2/cli/slash/upgrade.d.ts +9 -0
  73. package/dist_v2/cli/slash/upgrade.js +66 -0
  74. package/dist_v2/cli/slash.d.ts +72 -0
  75. package/dist_v2/cli/slash.js +77 -0
  76. package/dist_v2/cli/subcommands/ask.d.ts +17 -0
  77. package/dist_v2/cli/subcommands/ask.js +76 -0
  78. package/dist_v2/cli/subcommands/audit.d.ts +15 -0
  79. package/dist_v2/cli/subcommands/audit.js +128 -0
  80. package/dist_v2/cli/subcommands/chat.d.ts +13 -0
  81. package/dist_v2/cli/subcommands/chat.js +72 -0
  82. package/dist_v2/cli/subcommands/compact.d.ts +14 -0
  83. package/dist_v2/cli/subcommands/compact.js +114 -0
  84. package/dist_v2/cli/subcommands/doctor.d.ts +11 -0
  85. package/dist_v2/cli/subcommands/doctor.js +103 -0
  86. package/dist_v2/cli/subcommands/export-session.d.ts +10 -0
  87. package/dist_v2/cli/subcommands/export-session.js +60 -0
  88. package/dist_v2/cli/subcommands/import-session.d.ts +11 -0
  89. package/dist_v2/cli/subcommands/import-session.js +77 -0
  90. package/dist_v2/cli/subcommands/index.d.ts +40 -0
  91. package/dist_v2/cli/subcommands/index.js +38 -0
  92. package/dist_v2/cli/subcommands/init.d.ts +10 -0
  93. package/dist_v2/cli/subcommands/init.js +74 -0
  94. package/dist_v2/cli/subcommands/keys.d.ts +12 -0
  95. package/dist_v2/cli/subcommands/keys.js +136 -0
  96. package/dist_v2/cli/subcommands/login.d.ts +10 -0
  97. package/dist_v2/cli/subcommands/login.js +60 -0
  98. package/dist_v2/cli/subcommands/logout.d.ts +10 -0
  99. package/dist_v2/cli/subcommands/logout.js +21 -0
  100. package/dist_v2/cli/subcommands/models.d.ts +14 -0
  101. package/dist_v2/cli/subcommands/models.js +144 -0
  102. package/dist_v2/cli/subcommands/setup.d.ts +11 -0
  103. package/dist_v2/cli/subcommands/setup.js +107 -0
  104. package/dist_v2/cli/subcommands/stats.d.ts +13 -0
  105. package/dist_v2/cli/subcommands/stats.js +148 -0
  106. package/dist_v2/cli/subcommands/status.d.ts +14 -0
  107. package/dist_v2/cli/subcommands/status.js +91 -0
  108. package/dist_v2/cli/submit-paper.d.ts +15 -0
  109. package/dist_v2/cli/submit-paper.js +68 -0
  110. package/dist_v2/context/_fts.d.ts +62 -0
  111. package/dist_v2/context/_fts.js +195 -0
  112. package/dist_v2/context/branch.d.ts +18 -0
  113. package/dist_v2/context/branch.js +66 -0
  114. package/dist_v2/context/compaction.d.ts +26 -0
  115. package/dist_v2/context/compaction.js +120 -0
  116. package/dist_v2/context/index.d.ts +5 -0
  117. package/dist_v2/context/index.js +6 -0
  118. package/dist_v2/context/knowledge.d.ts +38 -0
  119. package/dist_v2/context/knowledge.js +146 -0
  120. package/dist_v2/context/memory.d.ts +80 -0
  121. package/dist_v2/context/memory.js +276 -0
  122. package/dist_v2/context/mode.d.ts +25 -0
  123. package/dist_v2/context/mode.js +81 -0
  124. package/dist_v2/context/session.d.ts +56 -0
  125. package/dist_v2/context/session.js +108 -0
  126. package/dist_v2/daemon/index.d.ts +2 -0
  127. package/dist_v2/daemon/index.js +3 -0
  128. package/dist_v2/daemon/protocol.d.ts +73 -0
  129. package/dist_v2/daemon/protocol.js +6 -0
  130. package/dist_v2/daemon/server.d.ts +35 -0
  131. package/dist_v2/daemon/server.js +191 -0
  132. package/dist_v2/eval/index.d.ts +5 -0
  133. package/dist_v2/eval/index.js +6 -0
  134. package/dist_v2/eval/regression.d.ts +14 -0
  135. package/dist_v2/eval/regression.js +106 -0
  136. package/dist_v2/eval/reporter.d.ts +7 -0
  137. package/dist_v2/eval/reporter.js +34 -0
  138. package/dist_v2/eval/swe-bench.d.ts +18 -0
  139. package/dist_v2/eval/swe-bench.js +23 -0
  140. package/dist_v2/eval/terminal-bench.d.ts +13 -0
  141. package/dist_v2/eval/terminal-bench.js +19 -0
  142. package/dist_v2/eval/types.d.ts +36 -0
  143. package/dist_v2/eval/types.js +5 -0
  144. package/dist_v2/fleet/apply-back.d.ts +27 -0
  145. package/dist_v2/fleet/apply-back.js +191 -0
  146. package/dist_v2/fleet/cli-command.d.ts +61 -0
  147. package/dist_v2/fleet/cli-command.js +329 -0
  148. package/dist_v2/fleet/index.d.ts +21 -0
  149. package/dist_v2/fleet/index.js +21 -0
  150. package/dist_v2/fleet/runner.d.ts +28 -0
  151. package/dist_v2/fleet/runner.js +347 -0
  152. package/dist_v2/fleet/tripleshot.d.ts +21 -0
  153. package/dist_v2/fleet/tripleshot.js +222 -0
  154. package/dist_v2/fleet/types.d.ts +193 -0
  155. package/dist_v2/fleet/types.js +24 -0
  156. package/dist_v2/fleet/worktree.d.ts +51 -0
  157. package/dist_v2/fleet/worktree.js +176 -0
  158. package/dist_v2/hooks/index.d.ts +1 -0
  159. package/dist_v2/hooks/index.js +2 -0
  160. package/dist_v2/hooks/registry.d.ts +21 -0
  161. package/dist_v2/hooks/registry.js +40 -0
  162. package/dist_v2/index.d.ts +12 -0
  163. package/dist_v2/index.js +11 -0
  164. package/dist_v2/integrations/arniko-client.d.ts +42 -0
  165. package/dist_v2/integrations/arniko-client.js +86 -0
  166. package/dist_v2/integrations/auth.d.ts +45 -0
  167. package/dist_v2/integrations/auth.js +54 -0
  168. package/dist_v2/integrations/billing.d.ts +71 -0
  169. package/dist_v2/integrations/billing.js +107 -0
  170. package/dist_v2/integrations/bucky-client.d.ts +105 -0
  171. package/dist_v2/integrations/bucky-client.js +76 -0
  172. package/dist_v2/integrations/deploy-client.d.ts +60 -0
  173. package/dist_v2/integrations/deploy-client.js +87 -0
  174. package/dist_v2/integrations/device-auth.d.ts +48 -0
  175. package/dist_v2/integrations/device-auth.js +192 -0
  176. package/dist_v2/integrations/entitlements.d.ts +34 -0
  177. package/dist_v2/integrations/entitlements.js +43 -0
  178. package/dist_v2/integrations/http.d.ts +22 -0
  179. package/dist_v2/integrations/http.js +114 -0
  180. package/dist_v2/integrations/index.d.ts +8 -0
  181. package/dist_v2/integrations/index.js +15 -0
  182. package/dist_v2/intelligence/cost.d.ts +28 -0
  183. package/dist_v2/intelligence/cost.js +58 -0
  184. package/dist_v2/intelligence/error-classifier.d.ts +8 -0
  185. package/dist_v2/intelligence/error-classifier.js +71 -0
  186. package/dist_v2/intelligence/index.d.ts +5 -0
  187. package/dist_v2/intelligence/index.js +6 -0
  188. package/dist_v2/intelligence/prices.d.ts +13 -0
  189. package/dist_v2/intelligence/prices.js +26 -0
  190. package/dist_v2/intelligence/smart-router.d.ts +21 -0
  191. package/dist_v2/intelligence/smart-router.js +59 -0
  192. package/dist_v2/intelligence/telemetry.d.ts +22 -0
  193. package/dist_v2/intelligence/telemetry.js +31 -0
  194. package/dist_v2/kernel/agent-loop.d.ts +32 -0
  195. package/dist_v2/kernel/agent-loop.js +151 -0
  196. package/dist_v2/kernel/event-stream.d.ts +18 -0
  197. package/dist_v2/kernel/event-stream.js +102 -0
  198. package/dist_v2/kernel/index.d.ts +4 -0
  199. package/dist_v2/kernel/index.js +5 -0
  200. package/dist_v2/kernel/message.d.ts +29 -0
  201. package/dist_v2/kernel/message.js +118 -0
  202. package/dist_v2/kernel/types.d.ts +206 -0
  203. package/dist_v2/kernel/types.js +9 -0
  204. package/dist_v2/mcp/client.d.ts +44 -0
  205. package/dist_v2/mcp/client.js +63 -0
  206. package/dist_v2/mcp/index.d.ts +3 -0
  207. package/dist_v2/mcp/index.js +4 -0
  208. package/dist_v2/mcp/tool-bridge.d.ts +11 -0
  209. package/dist_v2/mcp/tool-bridge.js +33 -0
  210. package/dist_v2/mcp/transport.d.ts +29 -0
  211. package/dist_v2/mcp/transport.js +73 -0
  212. package/dist_v2/parity/index.d.ts +3 -0
  213. package/dist_v2/parity/index.js +4 -0
  214. package/dist_v2/parity/mock-openai-compat.d.ts +15 -0
  215. package/dist_v2/parity/mock-openai-compat.js +35 -0
  216. package/dist_v2/parity/runner.d.ts +21 -0
  217. package/dist_v2/parity/runner.js +76 -0
  218. package/dist_v2/parity/scenarios.d.ts +20 -0
  219. package/dist_v2/parity/scenarios.js +70 -0
  220. package/dist_v2/providers/anthropic.d.ts +21 -0
  221. package/dist_v2/providers/anthropic.js +191 -0
  222. package/dist_v2/providers/dispatch.d.ts +11 -0
  223. package/dist_v2/providers/dispatch.js +45 -0
  224. package/dist_v2/providers/fireworks.d.ts +18 -0
  225. package/dist_v2/providers/fireworks.js +44 -0
  226. package/dist_v2/providers/gemini.d.ts +19 -0
  227. package/dist_v2/providers/gemini.js +188 -0
  228. package/dist_v2/providers/http.d.ts +41 -0
  229. package/dist_v2/providers/http.js +188 -0
  230. package/dist_v2/providers/iface.d.ts +18 -0
  231. package/dist_v2/providers/iface.js +18 -0
  232. package/dist_v2/providers/index.d.ts +39 -0
  233. package/dist_v2/providers/index.js +51 -0
  234. package/dist_v2/providers/nvidia.d.ts +27 -0
  235. package/dist_v2/providers/nvidia.js +142 -0
  236. package/dist_v2/providers/ollama.d.ts +15 -0
  237. package/dist_v2/providers/ollama.js +37 -0
  238. package/dist_v2/providers/openai-compat.d.ts +29 -0
  239. package/dist_v2/providers/openai-compat.js +239 -0
  240. package/dist_v2/providers/openai.d.ts +20 -0
  241. package/dist_v2/providers/openai.js +107 -0
  242. package/dist_v2/providers/openrouter.d.ts +24 -0
  243. package/dist_v2/providers/openrouter.js +69 -0
  244. package/dist_v2/safety/approval-bus.d.ts +26 -0
  245. package/dist_v2/safety/approval-bus.js +48 -0
  246. package/dist_v2/safety/audit-log.d.ts +27 -0
  247. package/dist_v2/safety/audit-log.js +71 -0
  248. package/dist_v2/safety/index.d.ts +4 -0
  249. package/dist_v2/safety/index.js +5 -0
  250. package/dist_v2/safety/policy.d.ts +32 -0
  251. package/dist_v2/safety/policy.js +131 -0
  252. package/dist_v2/safety/sandbox/bwrap.d.ts +11 -0
  253. package/dist_v2/safety/sandbox/bwrap.js +52 -0
  254. package/dist_v2/safety/sandbox/iface.d.ts +29 -0
  255. package/dist_v2/safety/sandbox/iface.js +8 -0
  256. package/dist_v2/safety/sandbox/index.d.ts +7 -0
  257. package/dist_v2/safety/sandbox/index.js +8 -0
  258. package/dist_v2/safety/sandbox/landlock.d.ts +17 -0
  259. package/dist_v2/safety/sandbox/landlock.js +26 -0
  260. package/dist_v2/safety/sandbox/noop.d.ts +12 -0
  261. package/dist_v2/safety/sandbox/noop.js +52 -0
  262. package/dist_v2/safety/sandbox/seatbelt.d.ts +11 -0
  263. package/dist_v2/safety/sandbox/seatbelt.js +49 -0
  264. package/dist_v2/safety/sandbox/select.d.ts +6 -0
  265. package/dist_v2/safety/sandbox/select.js +42 -0
  266. package/dist_v2/safety/sandbox/windows.d.ts +13 -0
  267. package/dist_v2/safety/sandbox/windows.js +22 -0
  268. package/dist_v2/skills/index.d.ts +3 -0
  269. package/dist_v2/skills/index.js +4 -0
  270. package/dist_v2/skills/loader.d.ts +38 -0
  271. package/dist_v2/skills/loader.js +102 -0
  272. package/dist_v2/skills/matcher.d.ts +14 -0
  273. package/dist_v2/skills/matcher.js +72 -0
  274. package/dist_v2/skills/runtime.d.ts +13 -0
  275. package/dist_v2/skills/runtime.js +40 -0
  276. package/dist_v2/subagents/delegator.d.ts +36 -0
  277. package/dist_v2/subagents/delegator.js +82 -0
  278. package/dist_v2/subagents/index.d.ts +2 -0
  279. package/dist_v2/subagents/index.js +3 -0
  280. package/dist_v2/subagents/pool.d.ts +18 -0
  281. package/dist_v2/subagents/pool.js +31 -0
  282. package/dist_v2/tools/browser.d.ts +27 -0
  283. package/dist_v2/tools/browser.js +179 -0
  284. package/dist_v2/tools/checkpoint.d.ts +25 -0
  285. package/dist_v2/tools/checkpoint.js +222 -0
  286. package/dist_v2/tools/cron.d.ts +32 -0
  287. package/dist_v2/tools/cron.js +160 -0
  288. package/dist_v2/tools/diff.d.ts +18 -0
  289. package/dist_v2/tools/diff.js +117 -0
  290. package/dist_v2/tools/exec.d.ts +19 -0
  291. package/dist_v2/tools/exec.js +49 -0
  292. package/dist_v2/tools/fs-edit.d.ts +11 -0
  293. package/dist_v2/tools/fs-edit.js +81 -0
  294. package/dist_v2/tools/fs-ls.d.ts +7 -0
  295. package/dist_v2/tools/fs-ls.js +57 -0
  296. package/dist_v2/tools/fs-read.d.ts +7 -0
  297. package/dist_v2/tools/fs-read.js +60 -0
  298. package/dist_v2/tools/fs-write.d.ts +8 -0
  299. package/dist_v2/tools/fs-write.js +46 -0
  300. package/dist_v2/tools/git.d.ts +8 -0
  301. package/dist_v2/tools/git.js +57 -0
  302. package/dist_v2/tools/index.d.ts +25 -0
  303. package/dist_v2/tools/index.js +39 -0
  304. package/dist_v2/tools/multimodal.d.ts +41 -0
  305. package/dist_v2/tools/multimodal.js +381 -0
  306. package/dist_v2/tools/permission.d.ts +27 -0
  307. package/dist_v2/tools/permission.js +43 -0
  308. package/dist_v2/tools/registry.d.ts +44 -0
  309. package/dist_v2/tools/registry.js +62 -0
  310. package/dist_v2/tools/search-glob.d.ts +7 -0
  311. package/dist_v2/tools/search-glob.js +98 -0
  312. package/dist_v2/tools/search-grep.d.ts +7 -0
  313. package/dist_v2/tools/search-grep.js +109 -0
  314. package/dist_v2/tools/shell.d.ts +10 -0
  315. package/dist_v2/tools/shell.js +76 -0
  316. package/dist_v2/tools/task.d.ts +8 -0
  317. package/dist_v2/tools/task.js +37 -0
  318. package/dist_v2/tui/approval.d.ts +7 -0
  319. package/dist_v2/tui/approval.js +55 -0
  320. package/dist_v2/tui/index.d.ts +4 -0
  321. package/dist_v2/tui/index.js +5 -0
  322. package/dist_v2/tui/ink/App.d.ts +39 -0
  323. package/dist_v2/tui/ink/App.js +206 -0
  324. package/dist_v2/tui/ink/components/AtFileComplete.d.ts +25 -0
  325. package/dist_v2/tui/ink/components/AtFileComplete.js +158 -0
  326. package/dist_v2/tui/ink/components/HelpOverlay.d.ts +24 -0
  327. package/dist_v2/tui/ink/components/HelpOverlay.js +130 -0
  328. package/dist_v2/tui/ink/components/InputBox.d.ts +35 -0
  329. package/dist_v2/tui/ink/components/InputBox.js +153 -0
  330. package/dist_v2/tui/ink/components/Logo.d.ts +12 -0
  331. package/dist_v2/tui/ink/components/Logo.js +27 -0
  332. package/dist_v2/tui/ink/components/ModelPicker.d.ts +26 -0
  333. package/dist_v2/tui/ink/components/ModelPicker.js +80 -0
  334. package/dist_v2/tui/ink/components/PasteCollapse.d.ts +36 -0
  335. package/dist_v2/tui/ink/components/PasteCollapse.js +59 -0
  336. package/dist_v2/tui/ink/components/StatusBar.d.ts +18 -0
  337. package/dist_v2/tui/ink/components/StatusBar.js +41 -0
  338. package/dist_v2/tui/ink/components/StreamingText.d.ts +14 -0
  339. package/dist_v2/tui/ink/components/StreamingText.js +11 -0
  340. package/dist_v2/tui/ink/components/ThinkingBlock.d.ts +13 -0
  341. package/dist_v2/tui/ink/components/ThinkingBlock.js +13 -0
  342. package/dist_v2/tui/ink/components/ToolBox.d.ts +20 -0
  343. package/dist_v2/tui/ink/components/ToolBox.js +63 -0
  344. package/dist_v2/tui/ink/components/vim-bindings.d.ts +43 -0
  345. package/dist_v2/tui/ink/components/vim-bindings.js +135 -0
  346. package/dist_v2/tui/ink/index.d.ts +39 -0
  347. package/dist_v2/tui/ink/index.js +47 -0
  348. package/dist_v2/tui/ink/use-event-projection.d.ts +51 -0
  349. package/dist_v2/tui/ink/use-event-projection.js +126 -0
  350. package/dist_v2/tui/ink/use-overlays.d.ts +24 -0
  351. package/dist_v2/tui/ink/use-overlays.js +50 -0
  352. package/dist_v2/tui/renderer.d.ts +19 -0
  353. package/dist_v2/tui/renderer.js +64 -0
  354. package/dist_v2/tui/status-bar.d.ts +12 -0
  355. package/dist_v2/tui/status-bar.js +16 -0
  356. package/dist_v2/tui/theme.d.ts +27 -0
  357. package/dist_v2/tui/theme.js +56 -0
  358. package/dist_v2/utils/json-repair.d.ts +7 -0
  359. package/dist_v2/utils/json-repair.js +45 -0
  360. package/package.json +113 -0
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Multimodal tool: a minimal surface for describing images, transcribing
3
+ * audio, and generating images. The tool is shaped as a single entry
4
+ * point (`action: 'describe_image' | 'transcribe_audio' | 'generate_image'`)
5
+ * so the agent only learns one name and the provider plumbing stays
6
+ * internal.
7
+ *
8
+ * Status of the three actions:
9
+ * - describe_image / transcribe_audio: best-effort. They route through
10
+ * the active provider's `stream` API with a multimodal payload when
11
+ * the model advertises support; otherwise they return a clear
12
+ * "provider lacks multimodal capability" result. They are NOT stubs —
13
+ * they will do real work on capable providers (Gemini, Claude vision,
14
+ * OpenAI gpt-4o) — but they can fail politely elsewhere.
15
+ * - generate_image: real. Routes through the active provider's
16
+ * optional `generateImage()` method (NVIDIA Flux Schnell by default,
17
+ * OpenAI DALL-E 3 as fallback when NVIDIA is unavailable and
18
+ * OPENAI_API_KEY is set). The decoded PNG is written to disk and
19
+ * the tool returns the absolute path.
20
+ *
21
+ * This file imports two provider classes lazily for fallback construction
22
+ * when the active provider doesn't expose `generateImage`. It does not
23
+ * pull in any streaming/chat-completions internals.
24
+ */
25
+ import { readFile, stat, writeFile, mkdir } from 'node:fs/promises';
26
+ import { resolve, extname, dirname } from 'node:path';
27
+ import { OpenAIProvider } from '../providers/openai.js';
28
+ import { NvidiaProvider } from '../providers/nvidia.js';
29
+ const MAX_IMAGE_BYTES = 8 * 1024 * 1024;
30
+ const MAX_AUDIO_BYTES = 16 * 1024 * 1024;
31
+ const IMAGE_EXT = {
32
+ '.png': 'image/png',
33
+ '.jpg': 'image/jpeg',
34
+ '.jpeg': 'image/jpeg',
35
+ '.gif': 'image/gif',
36
+ '.webp': 'image/webp',
37
+ };
38
+ const AUDIO_EXT = {
39
+ '.mp3': 'audio/mpeg',
40
+ '.wav': 'audio/wav',
41
+ '.m4a': 'audio/mp4',
42
+ '.ogg': 'audio/ogg',
43
+ '.flac': 'audio/flac',
44
+ };
45
+ const DEFAULT_IMAGE_WIDTH = 1024;
46
+ const DEFAULT_IMAGE_HEIGHT = 1024;
47
+ const NVIDIA_IMAGE_MODEL_HINTS = new Set([
48
+ 'flux.1-schnell',
49
+ 'flux-schnell',
50
+ 'nvidia/flux',
51
+ 'flux',
52
+ 'black-forest-labs/flux.1-schnell',
53
+ ]);
54
+ const OPENAI_IMAGE_MODEL_HINTS = new Set([
55
+ 'dall-e-3',
56
+ 'dall-e-2',
57
+ 'dall-e',
58
+ 'dalle',
59
+ 'openai/dall-e-3',
60
+ ]);
61
+ export function createMultimodalTool(opts) {
62
+ const supportsMultimodal = opts.supportsMultimodal
63
+ ?? ((modelId) => opts.provider.supportsTools(modelId));
64
+ return {
65
+ name: 'multimodal',
66
+ description: 'Describe an image, transcribe audio, or generate an image. Pass action="describe_image" with path to an image, action="transcribe_audio" with path to an audio file, or action="generate_image" with a prompt (NVIDIA Flux Schnell by default, OpenAI DALL-E 3 fallback).',
67
+ inputSchema: {
68
+ type: 'object',
69
+ properties: {
70
+ action: {
71
+ type: 'string',
72
+ enum: ['describe_image', 'transcribe_audio', 'generate_image'],
73
+ description: 'Which multimodal operation to perform.',
74
+ },
75
+ path: { type: 'string', description: 'Filesystem path to the image/audio file (required for describe/transcribe).' },
76
+ prompt: { type: 'string', description: 'Prompt text — used as the question for describe_image or the generation prompt.' },
77
+ model: { type: 'string', description: 'Override the model id. For generate_image, "flux.1-schnell" forces NVIDIA, "dall-e-3" forces OpenAI.' },
78
+ outputPath: { type: 'string', description: 'For generate_image: where to write the PNG. Defaults to ./dirgha-image-<timestamp>.png in the session cwd.' },
79
+ width: { type: 'number', description: 'Image width in pixels (default 1024).' },
80
+ height: { type: 'number', description: 'Image height in pixels (default 1024).' },
81
+ seed: { type: 'number', description: 'Optional deterministic seed (NVIDIA only).' },
82
+ steps: { type: 'number', description: 'Sampling steps (NVIDIA only, default 4 for Flux Schnell).' },
83
+ },
84
+ required: ['action'],
85
+ },
86
+ async execute(rawInput, ctx) {
87
+ const input = rawInput;
88
+ const model = input.model ?? opts.defaultModel;
89
+ if (input.action === 'generate_image') {
90
+ return generateImage({ input, ctx, activeProvider: opts.provider });
91
+ }
92
+ if (input.action === 'describe_image') {
93
+ return describeImage({
94
+ path: input.path,
95
+ prompt: input.prompt ?? 'Describe this image in detail.',
96
+ ctx,
97
+ provider: opts.provider,
98
+ model,
99
+ capable: supportsMultimodal(model),
100
+ });
101
+ }
102
+ if (input.action === 'transcribe_audio') {
103
+ return transcribeAudio({
104
+ path: input.path,
105
+ prompt: input.prompt ?? 'Transcribe this audio verbatim. Preserve speaker turns if distinguishable.',
106
+ ctx,
107
+ provider: opts.provider,
108
+ model,
109
+ capable: supportsMultimodal(model),
110
+ });
111
+ }
112
+ return {
113
+ content: `Unknown multimodal action: ${String(input.action)}`,
114
+ isError: true,
115
+ };
116
+ },
117
+ };
118
+ }
119
+ async function describeImage(a) {
120
+ if (!a.path)
121
+ return { content: 'describe_image requires a `path` to an image file.', isError: true };
122
+ const loaded = await loadMedia(a.path, a.ctx.cwd, IMAGE_EXT, MAX_IMAGE_BYTES, 'image');
123
+ if ('error' in loaded)
124
+ return { content: loaded.error, isError: true };
125
+ if (!a.capable) {
126
+ return {
127
+ content: multimodalCapabilityNotice('describe_image', a.model, loaded.mime, loaded.bytes),
128
+ isError: false,
129
+ metadata: { stub: true, reason: 'provider-multimodal-capability', model: a.model },
130
+ };
131
+ }
132
+ const messages = multimodalMessage({
133
+ instruction: a.prompt,
134
+ mediaKind: 'image',
135
+ dataUrl: loaded.dataUrl,
136
+ mime: loaded.mime,
137
+ });
138
+ return streamProviderText(a.provider, a.model, messages, 'describe_image');
139
+ }
140
+ async function transcribeAudio(a) {
141
+ if (!a.path)
142
+ return { content: 'transcribe_audio requires a `path` to an audio file.', isError: true };
143
+ const loaded = await loadMedia(a.path, a.ctx.cwd, AUDIO_EXT, MAX_AUDIO_BYTES, 'audio');
144
+ if ('error' in loaded)
145
+ return { content: loaded.error, isError: true };
146
+ if (!a.capable) {
147
+ return {
148
+ content: multimodalCapabilityNotice('transcribe_audio', a.model, loaded.mime, loaded.bytes),
149
+ isError: false,
150
+ metadata: { stub: true, reason: 'provider-multimodal-capability', model: a.model },
151
+ };
152
+ }
153
+ const messages = multimodalMessage({
154
+ instruction: a.prompt,
155
+ mediaKind: 'audio',
156
+ dataUrl: loaded.dataUrl,
157
+ mime: loaded.mime,
158
+ });
159
+ return streamProviderText(a.provider, a.model, messages, 'transcribe_audio');
160
+ }
161
+ async function loadMedia(path, cwd, allowed, maxBytes, kind) {
162
+ const abs = resolve(cwd, path);
163
+ const info = await stat(abs).catch(() => undefined);
164
+ if (!info || !info.isFile())
165
+ return { error: `No such ${kind} file: ${path}` };
166
+ if (info.size > maxBytes) {
167
+ return { error: `${kind} too large: ${info.size} bytes (max ${maxBytes}).` };
168
+ }
169
+ const ext = extname(abs).toLowerCase();
170
+ const mime = allowed[ext];
171
+ if (!mime) {
172
+ const supported = Object.keys(allowed).join(', ');
173
+ return { error: `Unsupported ${kind} extension "${ext}". Supported: ${supported}` };
174
+ }
175
+ const buf = await readFile(abs);
176
+ const dataUrl = `data:${mime};base64,${buf.toString('base64')}`;
177
+ return { dataUrl, mime, bytes: info.size };
178
+ }
179
+ function multimodalCapabilityNotice(action, model, mime, bytes) {
180
+ return [
181
+ `Active model "${model}" does not expose a multimodal capability in this build.`,
182
+ `The ${action === 'describe_image' ? 'image' : 'audio'} was loaded successfully (${mime}, ${bytes} bytes)`,
183
+ `but the request was not sent. Switch to a vision- or audio-capable model`,
184
+ `(e.g. gemini-1.5-pro, claude-3-5-sonnet, gpt-4o) and retry.`,
185
+ ].join(' ');
186
+ }
187
+ /**
188
+ * Build a provider-agnostic multimodal message. We stuff the data URL
189
+ * into a tagged text part — providers that natively understand
190
+ * `image_url` style content are expected to adapt via their own
191
+ * serialisation layer; providers that don't will at least see the
192
+ * instruction and a base64 blob and may handle it or return an error
193
+ * the agent loop can surface.
194
+ */
195
+ function multimodalMessage(args) {
196
+ return [
197
+ {
198
+ role: 'user',
199
+ content: [
200
+ { type: 'text', text: args.instruction },
201
+ {
202
+ type: 'text',
203
+ text: `[${args.mediaKind.toUpperCase()} ATTACHMENT mime=${args.mime}]\n${args.dataUrl}\n[/${args.mediaKind.toUpperCase()} ATTACHMENT]`,
204
+ },
205
+ ],
206
+ },
207
+ ];
208
+ }
209
+ async function streamProviderText(provider, model, messages, action) {
210
+ const req = { model, messages };
211
+ let text = '';
212
+ let errored = false;
213
+ let errMsg = '';
214
+ try {
215
+ for await (const ev of provider.stream(req)) {
216
+ if (ev.type === 'text_delta')
217
+ text += ev.delta;
218
+ if (ev.type === 'error') {
219
+ errored = true;
220
+ errMsg = ev.message;
221
+ }
222
+ }
223
+ }
224
+ catch (e) {
225
+ errored = true;
226
+ errMsg = e instanceof Error ? e.message : String(e);
227
+ }
228
+ const trimmed = text.trim();
229
+ if (errored && !trimmed) {
230
+ return { content: `multimodal/${action} failed: ${errMsg || 'provider error'}`, isError: true };
231
+ }
232
+ return {
233
+ content: trimmed || '(empty response)',
234
+ isError: false,
235
+ metadata: { action, model, provider: provider.id },
236
+ };
237
+ }
238
+ async function generateImage(a) {
239
+ const prompt = a.input.prompt?.trim();
240
+ if (!prompt) {
241
+ return { content: 'generate_image requires a `prompt`.', isError: true };
242
+ }
243
+ const modelHint = a.input.model?.toLowerCase();
244
+ const forcedProvider = resolveForcedProvider(modelHint);
245
+ const width = a.input.width ?? DEFAULT_IMAGE_WIDTH;
246
+ const height = a.input.height ?? DEFAULT_IMAGE_HEIGHT;
247
+ const req = {
248
+ prompt,
249
+ model: a.input.model,
250
+ width,
251
+ height,
252
+ seed: a.input.seed,
253
+ steps: a.input.steps,
254
+ };
255
+ const attempts = buildProviderAttempts({
256
+ active: a.activeProvider,
257
+ env: a.ctx.env,
258
+ forced: forcedProvider,
259
+ });
260
+ if (attempts.length === 0) {
261
+ return {
262
+ content: 'generate_image: no image-capable provider available. Set NVIDIA_API_KEY or OPENAI_API_KEY.',
263
+ isError: true,
264
+ };
265
+ }
266
+ const errors = [];
267
+ let result;
268
+ let servingProvider;
269
+ for (const attempt of attempts) {
270
+ try {
271
+ if (!attempt.provider.generateImage)
272
+ continue;
273
+ result = await attempt.provider.generateImage(req, a.ctx.signal);
274
+ servingProvider = attempt.provider;
275
+ break;
276
+ }
277
+ catch (err) {
278
+ errors.push(`${attempt.label}: ${err instanceof Error ? err.message : String(err)}`);
279
+ }
280
+ }
281
+ if (!result || !servingProvider) {
282
+ return {
283
+ content: `generate_image failed. Attempts: ${errors.join(' | ') || 'no provider exposed generateImage'}`,
284
+ isError: true,
285
+ };
286
+ }
287
+ const outputPath = resolveOutputPath(a.input.outputPath, a.ctx.cwd);
288
+ try {
289
+ await mkdir(dirname(outputPath), { recursive: true });
290
+ await writeFile(outputPath, Buffer.from(result.base64, 'base64'));
291
+ }
292
+ catch (err) {
293
+ return {
294
+ content: `generate_image: decoded image but failed to write ${outputPath}: ${err instanceof Error ? err.message : String(err)}`,
295
+ isError: true,
296
+ };
297
+ }
298
+ const data = {
299
+ path: outputPath,
300
+ model: result.model,
301
+ width,
302
+ height,
303
+ provider: servingProvider.id,
304
+ };
305
+ return {
306
+ content: `Saved: ${outputPath}`,
307
+ isError: false,
308
+ data,
309
+ metadata: {
310
+ action: 'generate_image',
311
+ model: result.model,
312
+ provider: servingProvider.id,
313
+ mimeType: result.mimeType,
314
+ },
315
+ };
316
+ }
317
+ function resolveForcedProvider(modelHint) {
318
+ if (!modelHint)
319
+ return undefined;
320
+ if (NVIDIA_IMAGE_MODEL_HINTS.has(modelHint))
321
+ return 'nvidia';
322
+ if (OPENAI_IMAGE_MODEL_HINTS.has(modelHint))
323
+ return 'openai';
324
+ return undefined;
325
+ }
326
+ function buildProviderAttempts(args) {
327
+ const attempts = [];
328
+ const seen = new Set();
329
+ const push = (p, label) => {
330
+ if (!p || !p.generateImage)
331
+ return;
332
+ if (seen.has(p.id))
333
+ return;
334
+ seen.add(p.id);
335
+ attempts.push({ provider: p, label });
336
+ };
337
+ if (args.forced === 'nvidia') {
338
+ const nvidia = tryBuildNvidia(args.env) ?? (args.active.id === 'nvidia' ? args.active : undefined);
339
+ push(nvidia, 'nvidia');
340
+ return attempts;
341
+ }
342
+ if (args.forced === 'openai') {
343
+ const openai = tryBuildOpenAI(args.env) ?? (args.active.id === 'openai' ? args.active : undefined);
344
+ push(openai, 'openai');
345
+ return attempts;
346
+ }
347
+ // Default order: active provider (if it supports image gen), then NVIDIA, then OpenAI.
348
+ push(args.active, `active(${args.active.id})`);
349
+ push(tryBuildNvidia(args.env), 'nvidia');
350
+ push(tryBuildOpenAI(args.env), 'openai');
351
+ return attempts;
352
+ }
353
+ function tryBuildNvidia(env) {
354
+ const key = env.NVIDIA_API_KEY ?? process.env.NVIDIA_API_KEY;
355
+ if (!key)
356
+ return undefined;
357
+ try {
358
+ return new NvidiaProvider({ apiKey: key });
359
+ }
360
+ catch {
361
+ return undefined;
362
+ }
363
+ }
364
+ function tryBuildOpenAI(env) {
365
+ const key = env.OPENAI_API_KEY ?? process.env.OPENAI_API_KEY;
366
+ if (!key)
367
+ return undefined;
368
+ try {
369
+ return new OpenAIProvider({ apiKey: key });
370
+ }
371
+ catch {
372
+ return undefined;
373
+ }
374
+ }
375
+ function resolveOutputPath(requested, cwd) {
376
+ if (requested && requested.length > 0)
377
+ return resolve(cwd, requested);
378
+ const ts = new Date().toISOString().replace(/[:.]/g, '-');
379
+ return resolve(cwd, `dirgha-image-${ts}.png`);
380
+ }
381
+ //# sourceMappingURL=multimodal.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Permission seam.
3
+ *
4
+ * L2 tools do not implement policy; they ask this seam whether a given
5
+ * action on a given target is permitted in the current context. The
6
+ * default engine here is permissive-with-approvals (writes, shell, and
7
+ * outside-cwd access all require approval). The production engine is
8
+ * injected from L6 (safety/policy.ts) which reads declarative rules.
9
+ */
10
+ export interface PermissionCheck {
11
+ tool: string;
12
+ action: 'read' | 'write' | 'exec' | 'delete' | 'network';
13
+ target: string;
14
+ }
15
+ export interface PermissionDecision {
16
+ allowed: boolean;
17
+ reason: string;
18
+ requiresApproval: boolean;
19
+ }
20
+ export interface PermissionEngine {
21
+ check(req: PermissionCheck): PermissionDecision;
22
+ }
23
+ export declare class DefaultPermissionEngine implements PermissionEngine {
24
+ private readonly cwd;
25
+ constructor(cwd: string);
26
+ check(req: PermissionCheck): PermissionDecision;
27
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Permission seam.
3
+ *
4
+ * L2 tools do not implement policy; they ask this seam whether a given
5
+ * action on a given target is permitted in the current context. The
6
+ * default engine here is permissive-with-approvals (writes, shell, and
7
+ * outside-cwd access all require approval). The production engine is
8
+ * injected from L6 (safety/policy.ts) which reads declarative rules.
9
+ */
10
+ export class DefaultPermissionEngine {
11
+ cwd;
12
+ constructor(cwd) {
13
+ this.cwd = cwd;
14
+ }
15
+ check(req) {
16
+ const insideCwd = isInside(this.cwd, req.target);
17
+ switch (req.action) {
18
+ case 'read':
19
+ return insideCwd
20
+ ? { allowed: true, reason: 'read inside cwd', requiresApproval: false }
21
+ : { allowed: true, reason: 'read outside cwd', requiresApproval: true };
22
+ case 'write':
23
+ return insideCwd
24
+ ? { allowed: true, reason: 'write inside cwd', requiresApproval: true }
25
+ : { allowed: true, reason: 'write outside cwd', requiresApproval: true };
26
+ case 'delete':
27
+ return { allowed: true, reason: 'delete', requiresApproval: true };
28
+ case 'exec':
29
+ return { allowed: true, reason: 'exec', requiresApproval: true };
30
+ case 'network':
31
+ return { allowed: true, reason: 'network', requiresApproval: true };
32
+ }
33
+ }
34
+ }
35
+ function isInside(root, target) {
36
+ if (!target)
37
+ return false;
38
+ const normRoot = root.replace(/\/+$/, '');
39
+ if (!target.startsWith('/'))
40
+ return true;
41
+ return target === normRoot || target.startsWith(`${normRoot}/`);
42
+ }
43
+ //# sourceMappingURL=permission.js.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Tool registry.
3
+ *
4
+ * Two concerns:
5
+ * (a) Hold the set of registered Tools and expose them to the agent
6
+ * loop as bare ToolDefinitions (the provider-visible subset).
7
+ * (b) Sanitise the outbound tool set per model — some hosted models
8
+ * reject very long descriptions or lack tool-use capability
9
+ * entirely.
10
+ */
11
+ import type { JsonSchema, ToolDefinition, ToolResult } from '../kernel/types.js';
12
+ export interface ToolContext {
13
+ cwd: string;
14
+ env: Record<string, string>;
15
+ sessionId: string;
16
+ signal: AbortSignal;
17
+ log?: (level: 'debug' | 'info' | 'warn' | 'error', msg: string, meta?: Record<string, unknown>) => void;
18
+ }
19
+ export interface Tool {
20
+ name: string;
21
+ description: string;
22
+ inputSchema: JsonSchema;
23
+ requiresApproval?: (input: unknown) => boolean;
24
+ execute(input: unknown, ctx: ToolContext): Promise<ToolResult>;
25
+ }
26
+ export interface SanitizedToolSet {
27
+ definitions: ToolDefinition[];
28
+ nameSet: Set<string>;
29
+ }
30
+ export interface SanitizeOptions {
31
+ descriptionLimit?: number;
32
+ allowlist?: Set<string>;
33
+ denylist?: Set<string>;
34
+ }
35
+ export declare class ToolRegistry {
36
+ private readonly tools;
37
+ register(tool: Tool): void;
38
+ unregister(name: string): boolean;
39
+ has(name: string): boolean;
40
+ get(name: string): Tool | undefined;
41
+ list(): Tool[];
42
+ sanitize(opts?: SanitizeOptions): SanitizedToolSet;
43
+ }
44
+ export declare function createToolRegistry(tools?: Tool[]): ToolRegistry;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Tool registry.
3
+ *
4
+ * Two concerns:
5
+ * (a) Hold the set of registered Tools and expose them to the agent
6
+ * loop as bare ToolDefinitions (the provider-visible subset).
7
+ * (b) Sanitise the outbound tool set per model — some hosted models
8
+ * reject very long descriptions or lack tool-use capability
9
+ * entirely.
10
+ */
11
+ export class ToolRegistry {
12
+ tools = new Map();
13
+ register(tool) {
14
+ if (!tool.name || !/^[a-zA-Z][a-zA-Z0-9_\-]*$/.test(tool.name)) {
15
+ throw new Error(`Invalid tool name: ${tool.name}`);
16
+ }
17
+ if (this.tools.has(tool.name)) {
18
+ throw new Error(`Tool "${tool.name}" is already registered`);
19
+ }
20
+ this.tools.set(tool.name, tool);
21
+ }
22
+ unregister(name) {
23
+ return this.tools.delete(name);
24
+ }
25
+ has(name) {
26
+ return this.tools.has(name);
27
+ }
28
+ get(name) {
29
+ return this.tools.get(name);
30
+ }
31
+ list() {
32
+ return [...this.tools.values()];
33
+ }
34
+ sanitize(opts = {}) {
35
+ const limit = opts.descriptionLimit ?? Number.POSITIVE_INFINITY;
36
+ const definitions = [];
37
+ const nameSet = new Set();
38
+ for (const tool of this.tools.values()) {
39
+ if (opts.allowlist && !opts.allowlist.has(tool.name))
40
+ continue;
41
+ if (opts.denylist && opts.denylist.has(tool.name))
42
+ continue;
43
+ const description = tool.description.length > limit
44
+ ? `${tool.description.slice(0, limit - 3)}...`
45
+ : tool.description;
46
+ definitions.push({
47
+ name: tool.name,
48
+ description,
49
+ inputSchema: tool.inputSchema,
50
+ });
51
+ nameSet.add(tool.name);
52
+ }
53
+ return { definitions, nameSet };
54
+ }
55
+ }
56
+ export function createToolRegistry(tools = []) {
57
+ const registry = new ToolRegistry();
58
+ for (const t of tools)
59
+ registry.register(t);
60
+ return registry;
61
+ }
62
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * File discovery by glob pattern. Honours .gitignore-style directory
3
+ * skips (node_modules, .git, dist by default). Returns matching paths
4
+ * relative to the search root, sorted for determinism.
5
+ */
6
+ import type { Tool } from './registry.js';
7
+ export declare const searchGlobTool: Tool;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * File discovery by glob pattern. Honours .gitignore-style directory
3
+ * skips (node_modules, .git, dist by default). Returns matching paths
4
+ * relative to the search root, sorted for determinism.
5
+ */
6
+ import { readdir, stat } from 'node:fs/promises';
7
+ import { join, relative, resolve } from 'node:path';
8
+ const DEFAULT_LIMIT = 500;
9
+ const DEFAULT_SKIP = new Set(['node_modules', '.git', 'dist', 'build', '.next', '.turbo']);
10
+ export const searchGlobTool = {
11
+ name: 'search_glob',
12
+ description: 'Find files by glob pattern (e.g., "**/*.ts"). Skips node_modules, .git, dist by default.',
13
+ inputSchema: {
14
+ type: 'object',
15
+ properties: {
16
+ pattern: { type: 'string' },
17
+ path: { type: 'string' },
18
+ resultLimit: { type: 'integer', minimum: 1 },
19
+ },
20
+ required: ['pattern'],
21
+ },
22
+ async execute(rawInput, ctx) {
23
+ const input = rawInput;
24
+ const root = resolve(ctx.cwd, input.path ?? '.');
25
+ const limit = input.resultLimit ?? DEFAULT_LIMIT;
26
+ const matcher = globToRegex(input.pattern);
27
+ const files = [];
28
+ let truncated = false;
29
+ async function walk(dir) {
30
+ if (files.length >= limit) {
31
+ truncated = true;
32
+ return;
33
+ }
34
+ const names = await readdir(dir).catch(() => []);
35
+ for (const name of names) {
36
+ if (DEFAULT_SKIP.has(name))
37
+ continue;
38
+ const abs = join(dir, name);
39
+ const info = await stat(abs).catch(() => undefined);
40
+ if (!info)
41
+ continue;
42
+ if (info.isDirectory())
43
+ await walk(abs);
44
+ else if (info.isFile()) {
45
+ const rel = relative(root, abs);
46
+ if (matcher.test(rel)) {
47
+ files.push(rel);
48
+ if (files.length >= limit) {
49
+ truncated = true;
50
+ return;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+ await walk(root);
57
+ files.sort();
58
+ return {
59
+ content: files.length > 0 ? files.join('\n') : '(no matches)',
60
+ data: { files: files.length, truncated },
61
+ isError: false,
62
+ };
63
+ },
64
+ };
65
+ function globToRegex(pattern) {
66
+ let rx = '^';
67
+ let i = 0;
68
+ while (i < pattern.length) {
69
+ const ch = pattern[i];
70
+ if (ch === '*') {
71
+ if (pattern[i + 1] === '*') {
72
+ rx += '.*';
73
+ i += 2;
74
+ if (pattern[i] === '/')
75
+ i++;
76
+ }
77
+ else {
78
+ rx += '[^/]*';
79
+ i++;
80
+ }
81
+ }
82
+ else if (ch === '?') {
83
+ rx += '[^/]';
84
+ i++;
85
+ }
86
+ else if (/[.+^${}()|[\]\\]/.test(ch)) {
87
+ rx += `\\${ch}`;
88
+ i++;
89
+ }
90
+ else {
91
+ rx += ch;
92
+ i++;
93
+ }
94
+ }
95
+ rx += '$';
96
+ return new RegExp(rx);
97
+ }
98
+ //# sourceMappingURL=search-glob.js.map
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Code search using ripgrep when available, with a conservative fallback
3
+ * to a Node-native line scan. Always returns file:line:match triples,
4
+ * capped by resultLimit to keep the LLM reply compact.
5
+ */
6
+ import type { Tool } from './registry.js';
7
+ export declare const searchGrepTool: Tool;