@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,222 @@
1
+ /**
2
+ * Session checkpoint tool.
3
+ *
4
+ * Snapshots the current session (messages + cwd + timestamp) into
5
+ * `~/.dirgha/checkpoints/<sessionId>-<timestamp>.json` so a user can
6
+ * rewind to a known-good agent state. The v1 checkpoint tool used a
7
+ * shadow-git bare repo to snapshot project files on disk; v2 inverts
8
+ * that — the session log is the source of truth, so we snapshot the
9
+ * *conversation* and leave filesystem state to the user's own VCS.
10
+ *
11
+ * Subcommands:
12
+ * save — write a snapshot file, returns its id.
13
+ * restore — load a snapshot and re-emit its messages into the
14
+ * active session log as system entries so later replay
15
+ * picks them up. Does NOT rewrite history in place.
16
+ * list — enumerate snapshots for the active session, or all.
17
+ * delete — remove a snapshot file by id.
18
+ *
19
+ * Note: restore is additive (appends the snapshot back onto the live
20
+ * session log). The kernel decides whether to prune older turns on a
21
+ * subsequent compaction — we don't truncate files here.
22
+ */
23
+ import { mkdir, readdir, readFile, stat, unlink, writeFile } from 'node:fs/promises';
24
+ import { homedir } from 'node:os';
25
+ import { join, basename } from 'node:path';
26
+ import { SessionStore } from '../context/session.js';
27
+ const CHECKPOINT_DIR = join(homedir(), '.dirgha', 'checkpoints');
28
+ async function ensureDir() {
29
+ await mkdir(CHECKPOINT_DIR, { recursive: true }).catch(() => undefined);
30
+ }
31
+ function checkpointPath(id) {
32
+ return join(CHECKPOINT_DIR, `${id}.json`);
33
+ }
34
+ function newCheckpointId(sessionId) {
35
+ return `${sessionId}-${Date.now()}`;
36
+ }
37
+ function ok(content, data) {
38
+ return { content, data, isError: false };
39
+ }
40
+ function fail(content) {
41
+ return { content, isError: true };
42
+ }
43
+ async function readCheckpoint(id) {
44
+ const p = checkpointPath(id);
45
+ const raw = await readFile(p, 'utf8').catch(() => undefined);
46
+ if (!raw)
47
+ return undefined;
48
+ try {
49
+ return JSON.parse(raw);
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
55
+ async function listCheckpointFiles() {
56
+ await ensureDir();
57
+ const names = await readdir(CHECKPOINT_DIR).catch(() => []);
58
+ return names.filter(n => n.endsWith('.json'));
59
+ }
60
+ async function summarise(fileName) {
61
+ const id = fileName.replace(/\.json$/, '');
62
+ const cp = await readCheckpoint(id);
63
+ if (!cp)
64
+ return undefined;
65
+ const info = await stat(checkpointPath(id)).catch(() => undefined);
66
+ return {
67
+ id: cp.id,
68
+ sessionId: cp.sessionId,
69
+ createdAt: cp.createdAt,
70
+ label: cp.label,
71
+ cwd: cp.cwd,
72
+ messageCount: cp.messageCount,
73
+ path: checkpointPath(id),
74
+ bytes: info?.size ?? 0,
75
+ };
76
+ }
77
+ async function doSave(input, ctx) {
78
+ await ensureDir();
79
+ const store = new SessionStore();
80
+ const session = await store.open(ctx.sessionId);
81
+ if (!session)
82
+ return fail(`session not found: ${ctx.sessionId}`);
83
+ const messages = await session.messages();
84
+ const id = newCheckpointId(ctx.sessionId);
85
+ const payload = {
86
+ id,
87
+ sessionId: ctx.sessionId,
88
+ createdAt: new Date().toISOString(),
89
+ label: input.label,
90
+ cwd: ctx.cwd,
91
+ messageCount: messages.length,
92
+ messages,
93
+ };
94
+ const path = checkpointPath(id);
95
+ await writeFile(path, JSON.stringify(payload, null, 2), 'utf8');
96
+ const info = await stat(path).catch(() => undefined);
97
+ const summary = {
98
+ id,
99
+ sessionId: ctx.sessionId,
100
+ createdAt: payload.createdAt,
101
+ label: input.label,
102
+ cwd: ctx.cwd,
103
+ messageCount: messages.length,
104
+ path,
105
+ bytes: info?.size ?? 0,
106
+ };
107
+ return ok(`saved checkpoint ${id} (${messages.length} messages, ${summary.bytes} bytes)\npath: ${path}`, summary);
108
+ }
109
+ async function doRestore(input, ctx) {
110
+ if (!input.id)
111
+ return fail('id required for restore');
112
+ const cp = await readCheckpoint(input.id);
113
+ if (!cp)
114
+ return fail(`checkpoint not found: ${input.id}`);
115
+ const store = new SessionStore();
116
+ const session = await store.open(ctx.sessionId);
117
+ if (!session)
118
+ return fail(`session not found: ${ctx.sessionId}`);
119
+ // Record the restore in the append-only session log. We emit a system
120
+ // marker first so replay can see when the splice happened, then one
121
+ // message entry per snapshot message. The kernel treats these as
122
+ // normal transcript entries on next replay.
123
+ const markerTs = new Date().toISOString();
124
+ const marker = {
125
+ type: 'system',
126
+ ts: markerTs,
127
+ event: 'checkpoint_restore',
128
+ data: {
129
+ checkpointId: cp.id,
130
+ messageCount: cp.messageCount,
131
+ originSessionId: cp.sessionId,
132
+ originCwd: cp.cwd,
133
+ },
134
+ };
135
+ await session.append(marker);
136
+ for (const message of cp.messages) {
137
+ const entry = { type: 'message', ts: markerTs, message };
138
+ await session.append(entry);
139
+ }
140
+ const info = await stat(checkpointPath(cp.id)).catch(() => undefined);
141
+ const summary = {
142
+ id: cp.id,
143
+ sessionId: cp.sessionId,
144
+ createdAt: cp.createdAt,
145
+ label: cp.label,
146
+ cwd: cp.cwd,
147
+ messageCount: cp.messageCount,
148
+ path: checkpointPath(cp.id),
149
+ bytes: info?.size ?? 0,
150
+ };
151
+ return ok(`restored checkpoint ${cp.id} into session ${ctx.sessionId} (+${cp.messageCount} messages)`, summary);
152
+ }
153
+ async function doList(input, ctx) {
154
+ const files = await listCheckpointFiles();
155
+ const all = await Promise.all(files.map(f => summarise(basename(f))));
156
+ const items = all
157
+ .filter((x) => x !== undefined)
158
+ .filter(item => (input.all ? true : item.sessionId === ctx.sessionId))
159
+ .sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1));
160
+ if (items.length === 0) {
161
+ return ok(input.all
162
+ ? '(no checkpoints on disk)'
163
+ : `(no checkpoints for session ${ctx.sessionId})`, { count: 0, items });
164
+ }
165
+ const lines = items.map(i => {
166
+ const label = i.label ? ` "${i.label}"` : '';
167
+ return `${i.id}${label}\t${i.createdAt}\tsession=${i.sessionId}\tmsgs=${i.messageCount}\t${i.bytes}B`;
168
+ });
169
+ return ok(lines.join('\n'), { count: items.length, items });
170
+ }
171
+ async function doDelete(input) {
172
+ if (!input.id)
173
+ return fail('id required for delete');
174
+ const p = checkpointPath(input.id);
175
+ const info = await stat(p).catch(() => undefined);
176
+ if (!info)
177
+ return fail(`checkpoint not found: ${input.id}`);
178
+ await unlink(p);
179
+ return ok(`deleted checkpoint ${input.id}`, { deleted: input.id });
180
+ }
181
+ export const checkpointTool = {
182
+ name: 'checkpoint',
183
+ description: 'Save, list, restore, and delete session checkpoints. Snapshots the transcript (messages + cwd + timestamp) to ~/.dirgha/checkpoints so the user can rewind to a known-good agent state.',
184
+ inputSchema: {
185
+ type: 'object',
186
+ properties: {
187
+ action: {
188
+ type: 'string',
189
+ enum: ['save', 'restore', 'list', 'delete'],
190
+ },
191
+ id: { type: 'string', description: 'Checkpoint id for restore/delete.' },
192
+ label: { type: 'string', description: 'Optional human label attached to a save.' },
193
+ all: { type: 'boolean', description: 'List checkpoints from every session, not just current.' },
194
+ },
195
+ required: ['action'],
196
+ },
197
+ requiresApproval: (raw) => {
198
+ const input = raw;
199
+ // Writes (save, restore, delete) require approval; list is read-only.
200
+ return input.action !== 'list';
201
+ },
202
+ async execute(rawInput, ctx) {
203
+ const input = rawInput;
204
+ if (!input || typeof input.action !== 'string') {
205
+ return fail('action required');
206
+ }
207
+ try {
208
+ switch (input.action) {
209
+ case 'save': return await doSave(input, ctx);
210
+ case 'restore': return await doRestore(input, ctx);
211
+ case 'list': return await doList(input, ctx);
212
+ case 'delete': return await doDelete(input);
213
+ default: return fail(`unknown action: ${String(input.action)}`);
214
+ }
215
+ }
216
+ catch (err) {
217
+ return fail(`checkpoint ${input.action} failed: ${err.message}`);
218
+ }
219
+ },
220
+ };
221
+ export default checkpointTool;
222
+ //# sourceMappingURL=checkpoint.js.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Cron tool — minimal CRUD over a JSON-backed job list at
3
+ * `~/.dirgha/cron/jobs.json`.
4
+ *
5
+ * Scope is deliberately narrow: this tool stores declarations. It does
6
+ * NOT run a scheduler, does NOT spawn processes, and does NOT execute
7
+ * jobs. A separate daemon (out of scope for this port) owns execution.
8
+ * The `run_now` action is a placeholder: it records a manual-run intent
9
+ * and bumps `lastRunAt` so the caller can hand the job to whatever
10
+ * executor they want.
11
+ *
12
+ * Job shape (stored as JSON):
13
+ * { id, schedule, command, nextRunAt?, lastRunAt?, createdAt }
14
+ *
15
+ * `schedule` is stored verbatim — callers decide whether to parse 5/6
16
+ * field cron expressions, human strings like "every 1h", or ISO dates.
17
+ * We only validate that it is non-empty.
18
+ */
19
+ import type { Tool } from './registry.js';
20
+ export interface CronJob {
21
+ id: string;
22
+ schedule: string;
23
+ command: string;
24
+ nextRunAt?: string;
25
+ lastRunAt?: string;
26
+ createdAt: string;
27
+ }
28
+ export interface CronToolOptions {
29
+ /** Override the jobs file location (default: `~/.dirgha/cron/jobs.json`). */
30
+ filePath?: string;
31
+ }
32
+ export declare function createCronTool(opts?: CronToolOptions): Tool;
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Cron tool — minimal CRUD over a JSON-backed job list at
3
+ * `~/.dirgha/cron/jobs.json`.
4
+ *
5
+ * Scope is deliberately narrow: this tool stores declarations. It does
6
+ * NOT run a scheduler, does NOT spawn processes, and does NOT execute
7
+ * jobs. A separate daemon (out of scope for this port) owns execution.
8
+ * The `run_now` action is a placeholder: it records a manual-run intent
9
+ * and bumps `lastRunAt` so the caller can hand the job to whatever
10
+ * executor they want.
11
+ *
12
+ * Job shape (stored as JSON):
13
+ * { id, schedule, command, nextRunAt?, lastRunAt?, createdAt }
14
+ *
15
+ * `schedule` is stored verbatim — callers decide whether to parse 5/6
16
+ * field cron expressions, human strings like "every 1h", or ISO dates.
17
+ * We only validate that it is non-empty.
18
+ */
19
+ import { readFile, writeFile, mkdir, stat } from 'node:fs/promises';
20
+ import { join } from 'node:path';
21
+ import { homedir } from 'node:os';
22
+ import { randomUUID } from 'node:crypto';
23
+ const DEFAULT_PATH = join(homedir(), '.dirgha', 'cron', 'jobs.json');
24
+ export function createCronTool(opts = {}) {
25
+ const filePath = opts.filePath ?? DEFAULT_PATH;
26
+ return {
27
+ name: 'cron',
28
+ description: 'Manage scheduled job declarations (add/remove/list/run_now). This tool only stores job declarations — a separate daemon is responsible for running them.',
29
+ inputSchema: {
30
+ type: 'object',
31
+ properties: {
32
+ action: { type: 'string', enum: ['add', 'remove', 'list', 'run_now'] },
33
+ id: { type: 'string', description: 'Job id (required for remove/run_now).' },
34
+ schedule: { type: 'string', description: 'Schedule string (cron expression, ISO date, or human phrase). Required for add.' },
35
+ command: { type: 'string', description: 'Shell command or agent prompt to run. Required for add.' },
36
+ nextRunAt: { type: 'string', description: 'Optional ISO timestamp of next run. Defaults to now.' },
37
+ },
38
+ required: ['action'],
39
+ },
40
+ async execute(rawInput, _ctx) {
41
+ const input = rawInput;
42
+ if (input.action === 'list') {
43
+ const jobs = await readJobs(filePath);
44
+ return {
45
+ content: formatJobList(jobs),
46
+ data: { action: 'list', count: jobs.length },
47
+ isError: false,
48
+ };
49
+ }
50
+ if (input.action === 'add') {
51
+ if (!input.schedule || !input.schedule.trim()) {
52
+ return { content: 'add requires a non-empty `schedule`.', isError: true };
53
+ }
54
+ if (!input.command || !input.command.trim()) {
55
+ return { content: 'add requires a non-empty `command`.', isError: true };
56
+ }
57
+ const jobs = await readJobs(filePath);
58
+ const job = {
59
+ id: randomUUID().slice(0, 8),
60
+ schedule: input.schedule.trim(),
61
+ command: input.command.trim(),
62
+ nextRunAt: input.nextRunAt ?? new Date().toISOString(),
63
+ createdAt: new Date().toISOString(),
64
+ };
65
+ jobs.push(job);
66
+ await writeJobs(filePath, jobs);
67
+ return {
68
+ content: `Added cron job ${job.id} (${job.schedule}): ${job.command}`,
69
+ data: { action: 'add', job },
70
+ isError: false,
71
+ };
72
+ }
73
+ if (input.action === 'remove') {
74
+ if (!input.id)
75
+ return { content: 'remove requires an `id`.', isError: true };
76
+ const jobs = await readJobs(filePath);
77
+ const next = jobs.filter(j => j.id !== input.id);
78
+ if (next.length === jobs.length) {
79
+ return { content: `No job with id "${input.id}".`, isError: true };
80
+ }
81
+ await writeJobs(filePath, next);
82
+ return {
83
+ content: `Removed cron job ${input.id}.`,
84
+ data: { action: 'remove', count: next.length },
85
+ isError: false,
86
+ };
87
+ }
88
+ if (input.action === 'run_now') {
89
+ if (!input.id)
90
+ return { content: 'run_now requires an `id`.', isError: true };
91
+ const jobs = await readJobs(filePath);
92
+ const job = jobs.find(j => j.id === input.id);
93
+ if (!job)
94
+ return { content: `No job with id "${input.id}".`, isError: true };
95
+ job.lastRunAt = new Date().toISOString();
96
+ await writeJobs(filePath, jobs);
97
+ return {
98
+ content: [
99
+ `Marked cron job ${job.id} as manually run.`,
100
+ `This tool does not execute the command; a scheduler daemon`,
101
+ `should pick it up. Command was: ${job.command}`,
102
+ ].join(' '),
103
+ data: { action: 'run_now', job },
104
+ isError: false,
105
+ };
106
+ }
107
+ return {
108
+ content: `Unknown cron action: ${String(input.action)}`,
109
+ isError: true,
110
+ };
111
+ },
112
+ };
113
+ }
114
+ async function readJobs(filePath) {
115
+ const raw = await readFile(filePath, 'utf8').catch(() => null);
116
+ if (raw === null)
117
+ return [];
118
+ try {
119
+ const parsed = JSON.parse(raw);
120
+ if (!Array.isArray(parsed))
121
+ return [];
122
+ return parsed.filter(isCronJob);
123
+ }
124
+ catch {
125
+ return [];
126
+ }
127
+ }
128
+ async function writeJobs(filePath, jobs) {
129
+ await ensureParent(filePath);
130
+ await writeFile(filePath, `${JSON.stringify(jobs, null, 2)}\n`, 'utf8');
131
+ }
132
+ async function ensureParent(filePath) {
133
+ const dir = filePath.slice(0, filePath.lastIndexOf('/'));
134
+ if (!dir)
135
+ return;
136
+ const info = await stat(dir).catch(() => undefined);
137
+ if (!info)
138
+ await mkdir(dir, { recursive: true });
139
+ }
140
+ function isCronJob(value) {
141
+ if (!value || typeof value !== 'object')
142
+ return false;
143
+ const v = value;
144
+ return (typeof v.id === 'string'
145
+ && typeof v.schedule === 'string'
146
+ && typeof v.command === 'string'
147
+ && typeof v.createdAt === 'string');
148
+ }
149
+ function formatJobList(jobs) {
150
+ if (jobs.length === 0)
151
+ return '(no cron jobs — add one with action="add").';
152
+ const lines = [`${jobs.length} cron job${jobs.length === 1 ? '' : 's'}:`];
153
+ for (const job of jobs) {
154
+ const next = job.nextRunAt ? ` next=${job.nextRunAt}` : '';
155
+ const last = job.lastRunAt ? ` last=${job.lastRunAt}` : '';
156
+ lines.push(` ${job.id} [${job.schedule}]${next}${last} ${job.command}`);
157
+ }
158
+ return lines.join('\n');
159
+ }
160
+ //# sourceMappingURL=cron.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Unified diff helper used by fs-edit and the TUI's approval modal.
3
+ *
4
+ * Produces a line-oriented unified diff plus optional word-level inline
5
+ * deltas for display. The algorithm is a straightforward longest-common-
6
+ * subsequence walk; it is not minimised for very large files. Callers
7
+ * should cap inputs at ~200 KB to keep latency interactive.
8
+ */
9
+ export interface UnifiedDiffOptions {
10
+ context?: number;
11
+ fromLabel?: string;
12
+ toLabel?: string;
13
+ }
14
+ export declare function unifiedDiff(before: string, after: string, opts?: UnifiedDiffOptions): string;
15
+ export declare function summariseDiff(diff: string): {
16
+ added: number;
17
+ removed: number;
18
+ };
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Unified diff helper used by fs-edit and the TUI's approval modal.
3
+ *
4
+ * Produces a line-oriented unified diff plus optional word-level inline
5
+ * deltas for display. The algorithm is a straightforward longest-common-
6
+ * subsequence walk; it is not minimised for very large files. Callers
7
+ * should cap inputs at ~200 KB to keep latency interactive.
8
+ */
9
+ export function unifiedDiff(before, after, opts = {}) {
10
+ const ctx = opts.context ?? 3;
11
+ const a = before.split('\n');
12
+ const b = after.split('\n');
13
+ const ops = lcsOps(a, b);
14
+ const header = [
15
+ `--- ${opts.fromLabel ?? 'before'}`,
16
+ `+++ ${opts.toLabel ?? 'after'}`,
17
+ ];
18
+ const hunks = [];
19
+ let i = 0;
20
+ while (i < ops.length) {
21
+ if (ops[i].kind === 'eq') {
22
+ i++;
23
+ continue;
24
+ }
25
+ let start = i;
26
+ while (start > 0 && ops[start - 1].kind === 'eq' && i - start < ctx)
27
+ start--;
28
+ let end = i;
29
+ while (end < ops.length && (ops[end].kind !== 'eq' || end - i < ctx))
30
+ end++;
31
+ while (end < ops.length && ops[end].kind === 'eq' && end - i < ctx * 2)
32
+ end++;
33
+ let aCount = 0;
34
+ let bCount = 0;
35
+ const lines = [];
36
+ let aStart = -1;
37
+ let bStart = -1;
38
+ for (let k = start; k < end; k++) {
39
+ const op = ops[k];
40
+ if (aStart < 0 && op.aLine !== undefined)
41
+ aStart = op.aLine;
42
+ if (bStart < 0 && op.bLine !== undefined)
43
+ bStart = op.bLine;
44
+ if (op.kind === 'eq') {
45
+ lines.push(` ${op.text}`);
46
+ aCount++;
47
+ bCount++;
48
+ }
49
+ else if (op.kind === 'del') {
50
+ lines.push(`-${op.text}`);
51
+ aCount++;
52
+ }
53
+ else {
54
+ lines.push(`+${op.text}`);
55
+ bCount++;
56
+ }
57
+ }
58
+ hunks.push(`@@ -${(aStart < 0 ? 0 : aStart + 1)},${aCount} +${(bStart < 0 ? 0 : bStart + 1)},${bCount} @@`);
59
+ hunks.push(...lines);
60
+ i = end;
61
+ }
62
+ if (hunks.length === 0)
63
+ return '';
64
+ return [...header, ...hunks].join('\n');
65
+ }
66
+ function lcsOps(a, b) {
67
+ const m = a.length;
68
+ const n = b.length;
69
+ const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
70
+ for (let i = m - 1; i >= 0; i--) {
71
+ for (let j = n - 1; j >= 0; j--) {
72
+ if (a[i] === b[j])
73
+ dp[i][j] = dp[i + 1][j + 1] + 1;
74
+ else
75
+ dp[i][j] = Math.max(dp[i + 1][j], dp[i][j + 1]);
76
+ }
77
+ }
78
+ const out = [];
79
+ let i = 0;
80
+ let j = 0;
81
+ while (i < m && j < n) {
82
+ if (a[i] === b[j]) {
83
+ out.push({ kind: 'eq', text: a[i], aLine: i, bLine: j });
84
+ i++;
85
+ j++;
86
+ }
87
+ else if (dp[i + 1][j] >= dp[i][j + 1]) {
88
+ out.push({ kind: 'del', text: a[i], aLine: i });
89
+ i++;
90
+ }
91
+ else {
92
+ out.push({ kind: 'add', text: b[j], bLine: j });
93
+ j++;
94
+ }
95
+ }
96
+ while (i < m) {
97
+ out.push({ kind: 'del', text: a[i], aLine: i });
98
+ i++;
99
+ }
100
+ while (j < n) {
101
+ out.push({ kind: 'add', text: b[j], bLine: j });
102
+ j++;
103
+ }
104
+ return out;
105
+ }
106
+ export function summariseDiff(diff) {
107
+ let added = 0;
108
+ let removed = 0;
109
+ for (const line of diff.split('\n')) {
110
+ if (line.startsWith('+') && !line.startsWith('+++'))
111
+ added++;
112
+ else if (line.startsWith('-') && !line.startsWith('---'))
113
+ removed++;
114
+ }
115
+ return { added, removed };
116
+ }
117
+ //# sourceMappingURL=diff.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Central tool executor used by the agent loop.
3
+ *
4
+ * Looks up the tool by name, validates input shape best-effort, runs
5
+ * the tool's execute() under the caller's AbortSignal, and returns a
6
+ * ToolResult. Tools themselves own their error handling; the executor
7
+ * converts unexpected exceptions into a uniform error result.
8
+ */
9
+ import type { ToolExecutor } from '../kernel/types.js';
10
+ import type { ToolContext, ToolRegistry } from './registry.js';
11
+ export type { ToolExecutor } from '../kernel/types.js';
12
+ export interface ToolExecutorOptions {
13
+ registry: ToolRegistry;
14
+ cwd: string;
15
+ env?: Record<string, string>;
16
+ sessionId: string;
17
+ log?: ToolContext['log'];
18
+ }
19
+ export declare function createToolExecutor(opts: ToolExecutorOptions): ToolExecutor;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Central tool executor used by the agent loop.
3
+ *
4
+ * Looks up the tool by name, validates input shape best-effort, runs
5
+ * the tool's execute() under the caller's AbortSignal, and returns a
6
+ * ToolResult. Tools themselves own their error handling; the executor
7
+ * converts unexpected exceptions into a uniform error result.
8
+ */
9
+ export function createToolExecutor(opts) {
10
+ const env = opts.env ?? sanitiseEnv(process.env);
11
+ return {
12
+ async execute(call, signal) {
13
+ const tool = opts.registry.get(call.name);
14
+ if (!tool) {
15
+ return { content: `Tool "${call.name}" is not registered.`, isError: true };
16
+ }
17
+ const ctx = {
18
+ cwd: opts.cwd,
19
+ env,
20
+ sessionId: opts.sessionId,
21
+ signal,
22
+ log: opts.log,
23
+ };
24
+ try {
25
+ return await runTool(tool, call.input, ctx);
26
+ }
27
+ catch (err) {
28
+ const msg = err instanceof Error ? err.message : String(err);
29
+ return { content: `Tool "${call.name}" failed: ${msg}`, isError: true };
30
+ }
31
+ },
32
+ };
33
+ }
34
+ async function runTool(tool, input, ctx) {
35
+ const started = Date.now();
36
+ const result = await tool.execute(input, ctx);
37
+ result.durationMs = result.durationMs ?? Date.now() - started;
38
+ return result;
39
+ }
40
+ function sanitiseEnv(source) {
41
+ const out = {};
42
+ for (const [k, v] of Object.entries(source)) {
43
+ if (v === undefined)
44
+ continue;
45
+ out[k] = v;
46
+ }
47
+ return out;
48
+ }
49
+ //# sourceMappingURL=exec.js.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * String-replace edit with exact and fuzzy matching.
3
+ *
4
+ * Exact match is the fast path. When the exact string is missing, the
5
+ * tool falls back to whitespace-normalised matching and, if still
6
+ * ambiguous, returns an error with the candidate contexts so the agent
7
+ * can retry with more specific anchors. This is deterministic and
8
+ * auditable — no "nearest fuzzy match" guessing.
9
+ */
10
+ import type { Tool } from './registry.js';
11
+ export declare const fsEditTool: Tool;