@machina.ai/cell-cli-core 1.22.5-rc1 → 1.25.0-rc2

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 (732) hide show
  1. package/dist/docs/AFTER_MERGE_PROMPT.md +26 -0
  2. package/dist/docs/CHANGES.md +124 -0
  3. package/dist/docs/api-proxy.md +27 -0
  4. package/dist/docs/architecture.md +80 -0
  5. package/dist/docs/assets/connected_devtools.png +0 -0
  6. package/dist/docs/assets/gemini-screenshot.png +0 -0
  7. package/dist/docs/assets/monitoring-dashboard-logs.png +0 -0
  8. package/dist/docs/assets/monitoring-dashboard-metrics.png +0 -0
  9. package/dist/docs/assets/monitoring-dashboard-overview.png +0 -0
  10. package/dist/docs/assets/release_patch.png +0 -0
  11. package/dist/docs/assets/theme-ansi-light.png +0 -0
  12. package/dist/docs/assets/theme-ansi.png +0 -0
  13. package/dist/docs/assets/theme-atom-one.png +0 -0
  14. package/dist/docs/assets/theme-ayu-light.png +0 -0
  15. package/dist/docs/assets/theme-ayu.png +0 -0
  16. package/dist/docs/assets/theme-custom.png +0 -0
  17. package/dist/docs/assets/theme-default-light.png +0 -0
  18. package/dist/docs/assets/theme-default.png +0 -0
  19. package/dist/docs/assets/theme-dracula.png +0 -0
  20. package/dist/docs/assets/theme-github-light.png +0 -0
  21. package/dist/docs/assets/theme-github.png +0 -0
  22. package/dist/docs/assets/theme-google-light.png +0 -0
  23. package/dist/docs/assets/theme-xcode-light.png +0 -0
  24. package/dist/docs/changelogs/index.md +612 -0
  25. package/dist/docs/changelogs/latest.md +153 -0
  26. package/dist/docs/changelogs/preview.md +131 -0
  27. package/dist/docs/changelogs/releases.md +1162 -0
  28. package/dist/docs/cli/authentication.md +3 -0
  29. package/dist/docs/cli/checkpointing.md +94 -0
  30. package/dist/docs/cli/commands.md +357 -0
  31. package/dist/docs/cli/custom-commands.md +315 -0
  32. package/dist/docs/cli/enterprise.md +564 -0
  33. package/dist/docs/cli/gemini-ignore.md +71 -0
  34. package/dist/docs/cli/gemini-md.md +109 -0
  35. package/dist/docs/cli/generation-settings.md +210 -0
  36. package/dist/docs/cli/headless.md +388 -0
  37. package/dist/docs/cli/index.md +63 -0
  38. package/dist/docs/cli/keyboard-shortcuts.md +136 -0
  39. package/dist/docs/cli/model-routing.md +37 -0
  40. package/dist/docs/cli/model.md +62 -0
  41. package/dist/docs/cli/sandbox.md +171 -0
  42. package/dist/docs/cli/session-management.md +158 -0
  43. package/dist/docs/cli/settings.md +148 -0
  44. package/dist/docs/cli/skills.md +188 -0
  45. package/dist/docs/cli/system-prompt.md +94 -0
  46. package/dist/docs/cli/telemetry.md +813 -0
  47. package/dist/docs/cli/themes.md +237 -0
  48. package/dist/docs/cli/token-caching.md +20 -0
  49. package/dist/docs/cli/trusted-folders.md +95 -0
  50. package/dist/docs/cli/tutorials/skills-getting-started.md +124 -0
  51. package/dist/docs/cli/tutorials.md +87 -0
  52. package/dist/docs/cli/uninstall.md +47 -0
  53. package/dist/docs/core/index.md +101 -0
  54. package/dist/docs/core/memport.md +246 -0
  55. package/dist/docs/core/policy-engine.md +268 -0
  56. package/dist/docs/core/tools-api.md +131 -0
  57. package/dist/docs/examples/proxy-script.md +83 -0
  58. package/dist/docs/extensions/extension-releasing.md +183 -0
  59. package/dist/docs/extensions/getting-started-extensions.md +244 -0
  60. package/dist/docs/extensions/index.md +343 -0
  61. package/dist/docs/faq.md +153 -0
  62. package/dist/docs/get-started/authentication.md +321 -0
  63. package/dist/docs/get-started/configuration-v1.md +890 -0
  64. package/dist/docs/get-started/configuration.md +1643 -0
  65. package/dist/docs/get-started/examples.md +218 -0
  66. package/dist/docs/get-started/gemini-3.md +101 -0
  67. package/dist/docs/get-started/index.md +71 -0
  68. package/dist/docs/get-started/installation.md +141 -0
  69. package/dist/docs/hooks/best-practices.md +856 -0
  70. package/dist/docs/hooks/index.md +723 -0
  71. package/dist/docs/hooks/reference.md +178 -0
  72. package/dist/docs/hooks/writing-hooks.md +1044 -0
  73. package/dist/docs/ide-integration/ide-companion-spec.md +267 -0
  74. package/dist/docs/ide-integration/index.md +201 -0
  75. package/dist/docs/index.md +147 -0
  76. package/dist/docs/integration-tests.md +211 -0
  77. package/dist/docs/issue-and-pr-automation.md +134 -0
  78. package/dist/docs/local-development.md +128 -0
  79. package/dist/docs/mcp_integration.md +160 -0
  80. package/dist/docs/mermaid/context.mmd +103 -0
  81. package/dist/docs/mermaid/render-path.mmd +64 -0
  82. package/dist/docs/npm.md +62 -0
  83. package/dist/docs/quota-and-pricing.md +158 -0
  84. package/dist/docs/release-confidence.md +164 -0
  85. package/dist/docs/releases.md +540 -0
  86. package/dist/docs/sidebar.json +301 -0
  87. package/dist/docs/tools/file-system.md +217 -0
  88. package/dist/docs/tools/index.md +95 -0
  89. package/dist/docs/tools/mcp-server.md +1045 -0
  90. package/dist/docs/tools/memory.md +54 -0
  91. package/dist/docs/tools/shell.md +260 -0
  92. package/dist/docs/tools/todos.md +56 -0
  93. package/dist/docs/tools/web-fetch.md +59 -0
  94. package/dist/docs/tools/web-search.md +42 -0
  95. package/dist/docs/tos-privacy.md +96 -0
  96. package/dist/docs/troubleshooting.md +162 -0
  97. package/dist/package.json +7 -4
  98. package/dist/src/agents/a2a-client-manager.d.ts +82 -0
  99. package/dist/src/agents/a2a-client-manager.js +295 -0
  100. package/dist/src/agents/a2a-client-manager.js.map +1 -0
  101. package/dist/src/agents/a2a-client-manager.test.js +281 -0
  102. package/dist/src/agents/a2a-client-manager.test.js.map +1 -0
  103. package/dist/src/agents/a2aUtils.d.ts +29 -0
  104. package/dist/src/agents/a2aUtils.js +113 -0
  105. package/dist/src/agents/a2aUtils.js.map +1 -0
  106. package/dist/src/agents/a2aUtils.test.js +147 -0
  107. package/dist/src/agents/a2aUtils.test.js.map +1 -0
  108. package/dist/src/agents/agentLoader.d.ts +68 -0
  109. package/dist/src/agents/agentLoader.js +255 -0
  110. package/dist/src/agents/agentLoader.js.map +1 -0
  111. package/dist/src/agents/agentLoader.test.js +307 -0
  112. package/dist/src/agents/agentLoader.test.js.map +1 -0
  113. package/dist/src/agents/cli-help-agent.d.ts +24 -0
  114. package/dist/src/agents/cli-help-agent.js +85 -0
  115. package/dist/src/agents/cli-help-agent.js.map +1 -0
  116. package/dist/src/agents/cli-help-agent.test.js +65 -0
  117. package/dist/src/agents/cli-help-agent.test.js.map +1 -0
  118. package/dist/src/agents/codebase-investigator.d.ts +2 -2
  119. package/dist/src/agents/codebase-investigator.js +14 -8
  120. package/dist/src/agents/codebase-investigator.js.map +1 -1
  121. package/dist/src/agents/delegate-to-agent-tool.d.ts +2 -2
  122. package/dist/src/agents/delegate-to-agent-tool.js +25 -14
  123. package/dist/src/agents/delegate-to-agent-tool.js.map +1 -1
  124. package/dist/src/agents/delegate-to-agent-tool.test.js +101 -21
  125. package/dist/src/agents/delegate-to-agent-tool.test.js.map +1 -1
  126. package/dist/src/agents/{executor.d.ts → local-executor.d.ts} +5 -11
  127. package/dist/src/agents/{executor.js → local-executor.js} +123 -62
  128. package/dist/src/agents/local-executor.js.map +1 -0
  129. package/dist/src/agents/local-executor.test.d.ts +6 -0
  130. package/dist/src/agents/{executor.test.js → local-executor.test.js} +136 -58
  131. package/dist/src/agents/local-executor.test.js.map +1 -0
  132. package/dist/src/agents/{invocation.d.ts → local-invocation.d.ts} +6 -7
  133. package/dist/src/agents/{invocation.js → local-invocation.js} +9 -10
  134. package/dist/src/agents/local-invocation.js.map +1 -0
  135. package/dist/src/agents/local-invocation.test.d.ts +6 -0
  136. package/dist/src/agents/{invocation.test.js → local-invocation.test.js} +29 -20
  137. package/dist/src/agents/local-invocation.test.js.map +1 -0
  138. package/dist/src/agents/registry.d.ts +22 -1
  139. package/dist/src/agents/registry.js +192 -35
  140. package/dist/src/agents/registry.js.map +1 -1
  141. package/dist/src/agents/registry.test.js +407 -33
  142. package/dist/src/agents/registry.test.js.map +1 -1
  143. package/dist/src/agents/remote-invocation.d.ts +35 -0
  144. package/dist/src/agents/remote-invocation.js +126 -0
  145. package/dist/src/agents/remote-invocation.js.map +1 -0
  146. package/dist/src/agents/remote-invocation.test.d.ts +6 -0
  147. package/dist/src/agents/remote-invocation.test.js +201 -0
  148. package/dist/src/agents/remote-invocation.test.js.map +1 -0
  149. package/dist/src/agents/subagent-tool-wrapper.d.ts +2 -2
  150. package/dist/src/agents/subagent-tool-wrapper.js +11 -6
  151. package/dist/src/agents/subagent-tool-wrapper.js.map +1 -1
  152. package/dist/src/agents/subagent-tool-wrapper.test.js +33 -19
  153. package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -1
  154. package/dist/src/agents/types.d.ts +21 -15
  155. package/dist/src/agents/types.js.map +1 -1
  156. package/dist/src/availability/fallbackIntegration.test.d.ts +6 -0
  157. package/dist/src/availability/fallbackIntegration.test.js +58 -0
  158. package/dist/src/availability/fallbackIntegration.test.js.map +1 -0
  159. package/dist/src/availability/modelAvailabilityService.d.ts +2 -1
  160. package/dist/src/availability/policyHelpers.d.ts +4 -3
  161. package/dist/src/availability/policyHelpers.js +13 -22
  162. package/dist/src/availability/policyHelpers.js.map +1 -1
  163. package/dist/src/availability/policyHelpers.test.js +28 -18
  164. package/dist/src/availability/policyHelpers.test.js.map +1 -1
  165. package/dist/src/code_assist/experiments/experiments.d.ts +1 -1
  166. package/dist/src/code_assist/experiments/experiments.js +21 -0
  167. package/dist/src/code_assist/experiments/experiments.js.map +1 -1
  168. package/dist/src/code_assist/experiments/experiments_local.test.d.ts +6 -0
  169. package/dist/src/code_assist/experiments/experiments_local.test.js +110 -0
  170. package/dist/src/code_assist/experiments/experiments_local.test.js.map +1 -0
  171. package/dist/src/code_assist/oauth-credential-storage.js +3 -4
  172. package/dist/src/code_assist/oauth-credential-storage.js.map +1 -1
  173. package/dist/src/code_assist/oauth2.js +32 -2
  174. package/dist/src/code_assist/oauth2.js.map +1 -1
  175. package/dist/src/code_assist/oauth2.test.js +111 -16
  176. package/dist/src/code_assist/oauth2.test.js.map +1 -1
  177. package/dist/src/code_assist/server.d.ts +9 -1
  178. package/dist/src/code_assist/server.js +74 -11
  179. package/dist/src/code_assist/server.js.map +1 -1
  180. package/dist/src/code_assist/server.test.js +199 -27
  181. package/dist/src/code_assist/server.test.js.map +1 -1
  182. package/dist/src/code_assist/setup.js +6 -4
  183. package/dist/src/code_assist/setup.js.map +1 -1
  184. package/dist/src/code_assist/setup.test.js +63 -0
  185. package/dist/src/code_assist/setup.test.js.map +1 -1
  186. package/dist/src/code_assist/telemetry.d.ts +14 -0
  187. package/dist/src/code_assist/telemetry.js +157 -0
  188. package/dist/src/code_assist/telemetry.js.map +1 -0
  189. package/dist/src/code_assist/telemetry.test.d.ts +6 -0
  190. package/dist/src/code_assist/telemetry.test.js +301 -0
  191. package/dist/src/code_assist/telemetry.test.js.map +1 -0
  192. package/dist/src/code_assist/types.d.ts +77 -1
  193. package/dist/src/code_assist/types.js +28 -0
  194. package/dist/src/code_assist/types.js.map +1 -1
  195. package/dist/src/commands/memory.d.ts +11 -0
  196. package/dist/src/commands/memory.js +80 -0
  197. package/dist/src/commands/memory.js.map +1 -0
  198. package/dist/src/commands/memory.test.d.ts +6 -0
  199. package/dist/src/commands/memory.test.js +155 -0
  200. package/dist/src/commands/memory.test.js.map +1 -0
  201. package/dist/src/config/config.d.ts +120 -26
  202. package/dist/src/config/config.js +241 -120
  203. package/dist/src/config/config.js.map +1 -1
  204. package/dist/src/config/config.test.js +215 -43
  205. package/dist/src/config/config.test.js.map +1 -1
  206. package/dist/src/config/flashFallback.test.js +11 -35
  207. package/dist/src/config/flashFallback.test.js.map +1 -1
  208. package/dist/src/config/models.d.ts +8 -9
  209. package/dist/src/config/models.js +18 -15
  210. package/dist/src/config/models.js.map +1 -1
  211. package/dist/src/config/models.test.js +52 -16
  212. package/dist/src/config/models.test.js.map +1 -1
  213. package/dist/src/config/storage.d.ts +5 -0
  214. package/dist/src/config/storage.js +17 -2
  215. package/dist/src/config/storage.js.map +1 -1
  216. package/dist/src/config/storage.test.js +16 -0
  217. package/dist/src/config/storage.test.js.map +1 -1
  218. package/dist/src/confirmation-bus/message-bus.js +2 -1
  219. package/dist/src/confirmation-bus/message-bus.js.map +1 -1
  220. package/dist/src/core/baseLlmClient.js +44 -43
  221. package/dist/src/core/baseLlmClient.js.map +1 -1
  222. package/dist/src/core/baseLlmClient.test.js +12 -19
  223. package/dist/src/core/baseLlmClient.test.js.map +1 -1
  224. package/dist/src/core/client.d.ts +7 -1
  225. package/dist/src/core/client.js +245 -114
  226. package/dist/src/core/client.js.map +1 -1
  227. package/dist/src/core/client.test.js +277 -74
  228. package/dist/src/core/client.test.js.map +1 -1
  229. package/dist/src/core/clientHookTriggers.js +2 -2
  230. package/dist/src/core/clientHookTriggers.js.map +1 -1
  231. package/dist/src/core/contentGenerator.js +3 -3
  232. package/dist/src/core/contentGenerator.js.map +1 -1
  233. package/dist/src/core/contentGenerator.test.js +1 -7
  234. package/dist/src/core/contentGenerator.test.js.map +1 -1
  235. package/dist/src/core/coreToolHookTriggers.d.ts +9 -5
  236. package/dist/src/core/coreToolHookTriggers.js +119 -21
  237. package/dist/src/core/coreToolHookTriggers.js.map +1 -1
  238. package/dist/src/core/coreToolHookTriggers.test.d.ts +6 -0
  239. package/dist/src/core/coreToolHookTriggers.test.js +191 -0
  240. package/dist/src/core/coreToolHookTriggers.test.js.map +1 -0
  241. package/dist/src/core/coreToolScheduler.d.ts +7 -93
  242. package/dist/src/core/coreToolScheduler.js +133 -369
  243. package/dist/src/core/coreToolScheduler.js.map +1 -1
  244. package/dist/src/core/coreToolScheduler.test.js +252 -394
  245. package/dist/src/core/coreToolScheduler.test.js.map +1 -1
  246. package/dist/src/core/geminiChat.d.ts +26 -1
  247. package/dist/src/core/geminiChat.js +112 -79
  248. package/dist/src/core/geminiChat.js.map +1 -1
  249. package/dist/src/core/geminiChat.test.js +125 -92
  250. package/dist/src/core/geminiChat.test.js.map +1 -1
  251. package/dist/src/core/geminiChatHookTriggers.d.ts +8 -4
  252. package/dist/src/core/geminiChatHookTriggers.js +34 -12
  253. package/dist/src/core/geminiChatHookTriggers.js.map +1 -1
  254. package/dist/src/core/geminiChatHookTriggers.test.d.ts +6 -0
  255. package/dist/src/core/geminiChatHookTriggers.test.js +153 -0
  256. package/dist/src/core/geminiChatHookTriggers.test.js.map +1 -0
  257. package/dist/src/core/geminiChat_network_retry.test.js +4 -6
  258. package/dist/src/core/geminiChat_network_retry.test.js.map +1 -1
  259. package/dist/src/core/loggingContentGenerator.js +19 -2
  260. package/dist/src/core/loggingContentGenerator.js.map +1 -1
  261. package/dist/src/core/loggingContentGenerator.test.js +30 -0
  262. package/dist/src/core/loggingContentGenerator.test.js.map +1 -1
  263. package/dist/src/core/nonInteractiveToolExecutor.test.js +4 -4
  264. package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
  265. package/dist/src/core/prompts.js +37 -13
  266. package/dist/src/core/prompts.js.map +1 -1
  267. package/dist/src/core/prompts.test.js +47 -3
  268. package/dist/src/core/prompts.test.js.map +1 -1
  269. package/dist/src/core/tokenLimits.js +6 -12
  270. package/dist/src/core/tokenLimits.js.map +1 -1
  271. package/dist/src/core/tokenLimits.test.js +8 -4
  272. package/dist/src/core/tokenLimits.test.js.map +1 -1
  273. package/dist/src/core/turn.d.ts +21 -22
  274. package/dist/src/core/turn.js +31 -21
  275. package/dist/src/core/turn.js.map +1 -1
  276. package/dist/src/core/turn.test.js +79 -5
  277. package/dist/src/core/turn.test.js.map +1 -1
  278. package/dist/src/fallback/handler.js +1 -7
  279. package/dist/src/fallback/handler.js.map +1 -1
  280. package/dist/src/fallback/handler.test.js +10 -29
  281. package/dist/src/fallback/handler.test.js.map +1 -1
  282. package/dist/src/generated/git-commit.d.ts +3 -3
  283. package/dist/src/generated/git-commit.js +3 -3
  284. package/dist/src/hooks/hookAggregator.js +7 -0
  285. package/dist/src/hooks/hookAggregator.js.map +1 -1
  286. package/dist/src/hooks/hookEventHandler.d.ts +9 -5
  287. package/dist/src/hooks/hookEventHandler.js +61 -15
  288. package/dist/src/hooks/hookEventHandler.js.map +1 -1
  289. package/dist/src/hooks/hookEventHandler.test.js +223 -8
  290. package/dist/src/hooks/hookEventHandler.test.js.map +1 -1
  291. package/dist/src/hooks/hookPlanner.d.ts +1 -5
  292. package/dist/src/hooks/hookPlanner.js +2 -7
  293. package/dist/src/hooks/hookPlanner.js.map +1 -1
  294. package/dist/src/hooks/hookPlanner.test.js +62 -2
  295. package/dist/src/hooks/hookPlanner.test.js.map +1 -1
  296. package/dist/src/hooks/hookRegistry.d.ts +6 -11
  297. package/dist/src/hooks/hookRegistry.js +41 -14
  298. package/dist/src/hooks/hookRegistry.js.map +1 -1
  299. package/dist/src/hooks/hookRegistry.test.js +166 -2
  300. package/dist/src/hooks/hookRegistry.test.js.map +1 -1
  301. package/dist/src/hooks/hookRunner.d.ts +5 -3
  302. package/dist/src/hooks/hookRunner.js +57 -17
  303. package/dist/src/hooks/hookRunner.js.map +1 -1
  304. package/dist/src/hooks/hookRunner.test.js +172 -35
  305. package/dist/src/hooks/hookRunner.test.js.map +1 -1
  306. package/dist/src/hooks/hookSystem.d.ts +12 -0
  307. package/dist/src/hooks/hookSystem.js +39 -1
  308. package/dist/src/hooks/hookSystem.js.map +1 -1
  309. package/dist/src/hooks/hookTranslator.js +2 -1
  310. package/dist/src/hooks/hookTranslator.js.map +1 -1
  311. package/dist/src/hooks/index.d.ts +1 -2
  312. package/dist/src/hooks/index.js +1 -3
  313. package/dist/src/hooks/index.js.map +1 -1
  314. package/dist/src/hooks/trustedHooks.d.ts +28 -0
  315. package/dist/src/hooks/trustedHooks.js +90 -0
  316. package/dist/src/hooks/trustedHooks.js.map +1 -0
  317. package/dist/src/hooks/trustedHooks.test.d.ts +6 -0
  318. package/dist/src/hooks/trustedHooks.test.js +154 -0
  319. package/dist/src/hooks/trustedHooks.test.js.map +1 -0
  320. package/dist/src/hooks/types.d.ts +41 -9
  321. package/dist/src/hooks/types.js +31 -41
  322. package/dist/src/hooks/types.js.map +1 -1
  323. package/dist/src/hooks/types.test.js +9 -52
  324. package/dist/src/hooks/types.test.js.map +1 -1
  325. package/dist/src/ide/detect-ide.d.ts +4 -0
  326. package/dist/src/ide/detect-ide.js +7 -2
  327. package/dist/src/ide/detect-ide.js.map +1 -1
  328. package/dist/src/ide/detect-ide.test.js +10 -0
  329. package/dist/src/ide/detect-ide.test.js.map +1 -1
  330. package/dist/src/ide/ide-client.js +4 -1
  331. package/dist/src/ide/ide-client.js.map +1 -1
  332. package/dist/src/ide/ide-installer.js +2 -2
  333. package/dist/src/ide/ide-installer.js.map +1 -1
  334. package/dist/src/ide/ide-installer.test.js +11 -2
  335. package/dist/src/ide/ide-installer.test.js.map +1 -1
  336. package/dist/src/index.d.ts +16 -2
  337. package/dist/src/index.js +18 -3
  338. package/dist/src/index.js.map +1 -1
  339. package/dist/src/mcp/oauth-provider.js +7 -3
  340. package/dist/src/mcp/oauth-provider.js.map +1 -1
  341. package/dist/src/mcp/oauth-provider.test.js +4 -1
  342. package/dist/src/mcp/oauth-provider.test.js.map +1 -1
  343. package/dist/src/mcp/oauth-utils.d.ts +8 -1
  344. package/dist/src/mcp/oauth-utils.js +31 -2
  345. package/dist/src/mcp/oauth-utils.js.map +1 -1
  346. package/dist/src/mcp/oauth-utils.test.js +42 -0
  347. package/dist/src/mcp/oauth-utils.test.js.map +1 -1
  348. package/dist/src/mcp/token-storage/file-token-storage.js +2 -2
  349. package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -1
  350. package/dist/src/mcp/token-storage/keychain-token-storage.js +1 -1
  351. package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -1
  352. package/dist/src/policy/config.js +62 -23
  353. package/dist/src/policy/config.js.map +1 -1
  354. package/dist/src/policy/config.test.js +24 -2
  355. package/dist/src/policy/config.test.js.map +1 -1
  356. package/dist/src/policy/persistence.test.js +1 -1
  357. package/dist/src/policy/persistence.test.js.map +1 -1
  358. package/dist/src/policy/policies/agent.toml +1 -1
  359. package/dist/src/policy/policies/write.toml +5 -0
  360. package/dist/src/policy/policies/yolo.toml +1 -0
  361. package/dist/src/policy/policy-engine.d.ts +4 -0
  362. package/dist/src/policy/policy-engine.js +137 -53
  363. package/dist/src/policy/policy-engine.js.map +1 -1
  364. package/dist/src/policy/policy-engine.test.js +289 -1
  365. package/dist/src/policy/policy-engine.test.js.map +1 -1
  366. package/dist/src/policy/policy-updater.test.js +5 -5
  367. package/dist/src/policy/policy-updater.test.js.map +1 -1
  368. package/dist/src/policy/shell-safety.test.js +371 -8
  369. package/dist/src/policy/shell-safety.test.js.map +1 -1
  370. package/dist/src/policy/toml-loader.d.ts +0 -8
  371. package/dist/src/policy/toml-loader.js +13 -45
  372. package/dist/src/policy/toml-loader.js.map +1 -1
  373. package/dist/src/policy/toml-loader.test.js +13 -0
  374. package/dist/src/policy/toml-loader.test.js.map +1 -1
  375. package/dist/src/policy/types.d.ts +10 -0
  376. package/dist/src/policy/utils.d.ts +21 -0
  377. package/dist/src/policy/utils.js +45 -0
  378. package/dist/src/policy/utils.js.map +1 -0
  379. package/dist/src/policy/utils.test.d.ts +6 -0
  380. package/dist/src/policy/utils.test.js +92 -0
  381. package/dist/src/policy/utils.test.js.map +1 -0
  382. package/dist/src/routing/routingStrategy.d.ts +2 -0
  383. package/dist/src/routing/strategies/classifierStrategy.js +1 -1
  384. package/dist/src/routing/strategies/classifierStrategy.js.map +1 -1
  385. package/dist/src/routing/strategies/classifierStrategy.test.js +16 -0
  386. package/dist/src/routing/strategies/classifierStrategy.test.js.map +1 -1
  387. package/dist/src/routing/strategies/compositeStrategy.js +4 -2
  388. package/dist/src/routing/strategies/compositeStrategy.js.map +1 -1
  389. package/dist/src/routing/strategies/compositeStrategy.test.js +11 -10
  390. package/dist/src/routing/strategies/compositeStrategy.test.js.map +1 -1
  391. package/dist/src/routing/strategies/fallbackStrategy.d.ts +1 -1
  392. package/dist/src/routing/strategies/fallbackStrategy.js +2 -5
  393. package/dist/src/routing/strategies/fallbackStrategy.js.map +1 -1
  394. package/dist/src/routing/strategies/fallbackStrategy.test.js +13 -6
  395. package/dist/src/routing/strategies/fallbackStrategy.test.js.map +1 -1
  396. package/dist/src/routing/strategies/overrideStrategy.d.ts +1 -1
  397. package/dist/src/routing/strategies/overrideStrategy.js +6 -6
  398. package/dist/src/routing/strategies/overrideStrategy.js.map +1 -1
  399. package/dist/src/routing/strategies/overrideStrategy.test.js +14 -0
  400. package/dist/src/routing/strategies/overrideStrategy.test.js.map +1 -1
  401. package/dist/src/scheduler/tool-executor.d.ts +22 -0
  402. package/dist/src/scheduler/tool-executor.js +198 -0
  403. package/dist/src/scheduler/tool-executor.js.map +1 -0
  404. package/dist/src/scheduler/tool-executor.test.d.ts +6 -0
  405. package/dist/src/scheduler/tool-executor.test.js +231 -0
  406. package/dist/src/scheduler/tool-executor.test.js.map +1 -0
  407. package/dist/src/scheduler/tool-modifier.d.ts +23 -0
  408. package/dist/src/scheduler/tool-modifier.js +50 -0
  409. package/dist/src/scheduler/tool-modifier.js.map +1 -0
  410. package/dist/src/scheduler/tool-modifier.test.d.ts +6 -0
  411. package/dist/src/scheduler/tool-modifier.test.js +159 -0
  412. package/dist/src/scheduler/tool-modifier.test.js.map +1 -0
  413. package/dist/src/scheduler/types.d.ts +95 -0
  414. package/dist/src/scheduler/types.js +7 -0
  415. package/dist/src/scheduler/types.js.map +1 -0
  416. package/dist/src/services/chatCompressionService.js +3 -10
  417. package/dist/src/services/chatCompressionService.js.map +1 -1
  418. package/dist/src/services/chatCompressionService.test.js +1 -0
  419. package/dist/src/services/chatCompressionService.test.js.map +1 -1
  420. package/dist/src/services/chatRecordingService.d.ts +7 -1
  421. package/dist/src/services/chatRecordingService.js +20 -2
  422. package/dist/src/services/chatRecordingService.js.map +1 -1
  423. package/dist/src/services/chatRecordingService.test.js +43 -0
  424. package/dist/src/services/chatRecordingService.test.js.map +1 -1
  425. package/dist/src/services/contextManager.d.ts +5 -11
  426. package/dist/src/services/contextManager.js +20 -17
  427. package/dist/src/services/contextManager.js.map +1 -1
  428. package/dist/src/services/contextManager.test.js +40 -41
  429. package/dist/src/services/contextManager.test.js.map +1 -1
  430. package/dist/src/services/environmentSanitization.d.ts +15 -0
  431. package/dist/src/services/environmentSanitization.js +142 -0
  432. package/dist/src/services/environmentSanitization.js.map +1 -0
  433. package/dist/src/services/environmentSanitization.test.d.ts +6 -0
  434. package/dist/src/services/environmentSanitization.test.js +284 -0
  435. package/dist/src/services/environmentSanitization.test.js.map +1 -0
  436. package/dist/src/services/gitService.js +10 -1
  437. package/dist/src/services/gitService.js.map +1 -1
  438. package/dist/src/services/gitService.test.js +28 -2
  439. package/dist/src/services/gitService.test.js.map +1 -1
  440. package/dist/src/services/loopDetectionService.js +2 -1
  441. package/dist/src/services/loopDetectionService.js.map +1 -1
  442. package/dist/src/services/loopDetectionService.test.js +14 -8
  443. package/dist/src/services/loopDetectionService.test.js.map +1 -1
  444. package/dist/src/services/modelConfig.integration.test.js +3 -3
  445. package/dist/src/services/modelConfig.integration.test.js.map +1 -1
  446. package/dist/src/services/modelConfigService.d.ts +38 -4
  447. package/dist/src/services/modelConfigService.js +135 -76
  448. package/dist/src/services/modelConfigService.js.map +1 -1
  449. package/dist/src/services/modelConfigService.test.js +116 -0
  450. package/dist/src/services/modelConfigService.test.js.map +1 -1
  451. package/dist/src/services/shellExecutionService.d.ts +2 -0
  452. package/dist/src/services/shellExecutionService.js +6 -50
  453. package/dist/src/services/shellExecutionService.js.map +1 -1
  454. package/dist/src/services/shellExecutionService.test.js +68 -4
  455. package/dist/src/services/shellExecutionService.test.js.map +1 -1
  456. package/dist/src/skills/skillLoader.d.ts +31 -0
  457. package/dist/src/skills/skillLoader.js +77 -0
  458. package/dist/src/skills/skillLoader.js.map +1 -0
  459. package/dist/src/skills/skillLoader.test.d.ts +6 -0
  460. package/dist/src/skills/skillLoader.test.js +75 -0
  461. package/dist/src/skills/skillLoader.test.js.map +1 -0
  462. package/dist/src/skills/skillManager.d.ts +69 -0
  463. package/dist/src/skills/skillManager.js +127 -0
  464. package/dist/src/skills/skillManager.js.map +1 -0
  465. package/dist/src/skills/skillManager.test.d.ts +6 -0
  466. package/dist/src/skills/skillManager.test.js +210 -0
  467. package/dist/src/skills/skillManager.test.js.map +1 -0
  468. package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +18 -9
  469. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +234 -160
  470. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  471. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +162 -32
  472. package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
  473. package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +11 -3
  474. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +24 -5
  475. package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
  476. package/dist/src/telemetry/loggers.d.ts +3 -3
  477. package/dist/src/telemetry/loggers.js +6 -5
  478. package/dist/src/telemetry/loggers.js.map +1 -1
  479. package/dist/src/telemetry/loggers.test.circular.js +1 -0
  480. package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
  481. package/dist/src/telemetry/loggers.test.js +51 -10
  482. package/dist/src/telemetry/loggers.test.js.map +1 -1
  483. package/dist/src/telemetry/sdk.js +5 -6
  484. package/dist/src/telemetry/sdk.js.map +1 -1
  485. package/dist/src/telemetry/types.d.ts +7 -7
  486. package/dist/src/telemetry/types.js +14 -12
  487. package/dist/src/telemetry/types.js.map +1 -1
  488. package/dist/src/test-utils/mock-message-bus.d.ts +1 -0
  489. package/dist/src/test-utils/mock-message-bus.js +29 -0
  490. package/dist/src/test-utils/mock-message-bus.js.map +1 -1
  491. package/dist/src/test-utils/mock-tool.d.ts +5 -3
  492. package/dist/src/test-utils/mock-tool.js +11 -10
  493. package/dist/src/test-utils/mock-tool.js.map +1 -1
  494. package/dist/src/tools/activate-skill.d.ts +27 -0
  495. package/dist/src/tools/activate-skill.js +133 -0
  496. package/dist/src/tools/activate-skill.js.map +1 -0
  497. package/dist/src/tools/activate-skill.test.d.ts +6 -0
  498. package/dist/src/tools/activate-skill.test.js +113 -0
  499. package/dist/src/tools/activate-skill.test.js.map +1 -0
  500. package/dist/src/tools/confirmation-policy.test.js +3 -12
  501. package/dist/src/tools/confirmation-policy.test.js.map +1 -1
  502. package/dist/src/tools/edit.d.ts +27 -5
  503. package/dist/src/tools/edit.js +455 -136
  504. package/dist/src/tools/edit.js.map +1 -1
  505. package/dist/src/tools/edit.test.js +292 -526
  506. package/dist/src/tools/edit.test.js.map +1 -1
  507. package/dist/src/tools/get-internal-docs.d.ts +27 -0
  508. package/dist/src/tools/get-internal-docs.js +122 -0
  509. package/dist/src/tools/get-internal-docs.js.map +1 -0
  510. package/dist/src/tools/get-internal-docs.test.d.ts +6 -0
  511. package/dist/src/tools/get-internal-docs.test.js +57 -0
  512. package/dist/src/tools/get-internal-docs.test.js.map +1 -0
  513. package/dist/src/tools/glob.d.ts +2 -2
  514. package/dist/src/tools/glob.js +1 -1
  515. package/dist/src/tools/glob.js.map +1 -1
  516. package/dist/src/tools/glob.test.js +2 -1
  517. package/dist/src/tools/glob.test.js.map +1 -1
  518. package/dist/src/tools/grep.d.ts +2 -2
  519. package/dist/src/tools/grep.js +1 -1
  520. package/dist/src/tools/grep.js.map +1 -1
  521. package/dist/src/tools/grep.test.js +5 -4
  522. package/dist/src/tools/grep.test.js.map +1 -1
  523. package/dist/src/tools/ls.d.ts +2 -2
  524. package/dist/src/tools/ls.js +2 -2
  525. package/dist/src/tools/ls.js.map +1 -1
  526. package/dist/src/tools/ls.test.js +2 -1
  527. package/dist/src/tools/ls.test.js.map +1 -1
  528. package/dist/src/tools/mcp-client-manager.js +14 -7
  529. package/dist/src/tools/mcp-client-manager.js.map +1 -1
  530. package/dist/src/tools/mcp-client-manager.test.js +28 -0
  531. package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
  532. package/dist/src/tools/mcp-client.d.ts +5 -4
  533. package/dist/src/tools/mcp-client.js +10 -8
  534. package/dist/src/tools/mcp-client.js.map +1 -1
  535. package/dist/src/tools/mcp-client.test.js +47 -42
  536. package/dist/src/tools/mcp-client.test.js.map +1 -1
  537. package/dist/src/tools/mcp-tool.d.ts +20 -5
  538. package/dist/src/tools/mcp-tool.js +8 -8
  539. package/dist/src/tools/mcp-tool.js.map +1 -1
  540. package/dist/src/tools/mcp-tool.test.js +11 -6
  541. package/dist/src/tools/mcp-tool.test.js.map +1 -1
  542. package/dist/src/tools/memoryTool.d.ts +3 -3
  543. package/dist/src/tools/memoryTool.js +2 -4
  544. package/dist/src/tools/memoryTool.js.map +1 -1
  545. package/dist/src/tools/memoryTool.test.js +5 -2
  546. package/dist/src/tools/memoryTool.test.js.map +1 -1
  547. package/dist/src/tools/message-bus-integration.test.js +10 -37
  548. package/dist/src/tools/message-bus-integration.test.js.map +1 -1
  549. package/dist/src/tools/read-file.d.ts +2 -2
  550. package/dist/src/tools/read-file.js +1 -1
  551. package/dist/src/tools/read-file.js.map +1 -1
  552. package/dist/src/tools/read-file.test.js +3 -2
  553. package/dist/src/tools/read-file.test.js.map +1 -1
  554. package/dist/src/tools/read-many-files.d.ts +2 -2
  555. package/dist/src/tools/read-many-files.js +2 -3
  556. package/dist/src/tools/read-many-files.js.map +1 -1
  557. package/dist/src/tools/read-many-files.test.js +3 -2
  558. package/dist/src/tools/read-many-files.test.js.map +1 -1
  559. package/dist/src/tools/ripGrep.d.ts +3 -2
  560. package/dist/src/tools/ripGrep.js +18 -7
  561. package/dist/src/tools/ripGrep.js.map +1 -1
  562. package/dist/src/tools/ripGrep.test.js +60 -4
  563. package/dist/src/tools/ripGrep.test.js.map +1 -1
  564. package/dist/src/tools/shell.d.ts +3 -6
  565. package/dist/src/tools/shell.js +21 -49
  566. package/dist/src/tools/shell.js.map +1 -1
  567. package/dist/src/tools/shell.test.js +35 -59
  568. package/dist/src/tools/shell.test.js.map +1 -1
  569. package/dist/src/tools/tool-error.d.ts +6 -1
  570. package/dist/src/tools/tool-error.js +6 -0
  571. package/dist/src/tools/tool-error.js.map +1 -1
  572. package/dist/src/tools/tool-names.d.ts +15 -0
  573. package/dist/src/tools/tool-names.js +57 -0
  574. package/dist/src/tools/tool-names.js.map +1 -1
  575. package/dist/src/tools/tool-names.test.d.ts +6 -0
  576. package/dist/src/tools/tool-names.test.js +43 -0
  577. package/dist/src/tools/tool-names.test.js.map +1 -0
  578. package/dist/src/tools/tool-registry.d.ts +11 -7
  579. package/dist/src/tools/tool-registry.js +15 -10
  580. package/dist/src/tools/tool-registry.js.map +1 -1
  581. package/dist/src/tools/tool-registry.test.js +16 -11
  582. package/dist/src/tools/tool-registry.test.js.map +1 -1
  583. package/dist/src/tools/tools.d.ts +8 -6
  584. package/dist/src/tools/tools.js +16 -18
  585. package/dist/src/tools/tools.js.map +1 -1
  586. package/dist/src/tools/tools.test.js +3 -1
  587. package/dist/src/tools/tools.test.js.map +1 -1
  588. package/dist/src/tools/web-fetch.d.ts +2 -2
  589. package/dist/src/tools/web-fetch.js +4 -4
  590. package/dist/src/tools/web-fetch.js.map +1 -1
  591. package/dist/src/tools/web-fetch.test.js +17 -19
  592. package/dist/src/tools/web-fetch.test.js.map +1 -1
  593. package/dist/src/tools/web-search.d.ts +2 -2
  594. package/dist/src/tools/web-search.js +5 -5
  595. package/dist/src/tools/web-search.js.map +1 -1
  596. package/dist/src/tools/web-search.test.js +2 -1
  597. package/dist/src/tools/web-search.test.js.map +1 -1
  598. package/dist/src/tools/write-file.d.ts +2 -2
  599. package/dist/src/tools/write-file.js +9 -6
  600. package/dist/src/tools/write-file.js.map +1 -1
  601. package/dist/src/tools/write-file.test.js +49 -7
  602. package/dist/src/tools/write-file.test.js.map +1 -1
  603. package/dist/src/tools/write-todos.d.ts +2 -2
  604. package/dist/src/tools/write-todos.js +5 -4
  605. package/dist/src/tools/write-todos.js.map +1 -1
  606. package/dist/src/tools/write-todos.test.js +2 -1
  607. package/dist/src/tools/write-todos.test.js.map +1 -1
  608. package/dist/src/utils/apiConversionUtils.d.ts +12 -0
  609. package/dist/src/utils/apiConversionUtils.js +46 -0
  610. package/dist/src/utils/apiConversionUtils.js.map +1 -0
  611. package/dist/src/utils/apiConversionUtils.test.d.ts +6 -0
  612. package/dist/src/utils/apiConversionUtils.test.js +150 -0
  613. package/dist/src/utils/apiConversionUtils.test.js.map +1 -0
  614. package/dist/src/utils/checkpointUtils.d.ts +1 -1
  615. package/dist/src/utils/checkpointUtils.js +1 -1
  616. package/dist/src/utils/checkpointUtils.js.map +1 -1
  617. package/dist/src/utils/checkpointUtils.test.js +1 -1
  618. package/dist/src/utils/checkpointUtils.test.js.map +1 -1
  619. package/dist/src/utils/debugLogger.js +1 -0
  620. package/dist/src/utils/debugLogger.js.map +1 -1
  621. package/dist/src/utils/editCorrector.d.ts +3 -3
  622. package/dist/src/utils/editCorrector.js +27 -10
  623. package/dist/src/utils/editCorrector.js.map +1 -1
  624. package/dist/src/utils/editCorrector.test.js +23 -23
  625. package/dist/src/utils/editCorrector.test.js.map +1 -1
  626. package/dist/src/utils/editor.d.ts +3 -2
  627. package/dist/src/utils/editor.js +26 -6
  628. package/dist/src/utils/editor.js.map +1 -1
  629. package/dist/src/utils/editor.test.js +27 -4
  630. package/dist/src/utils/editor.test.js.map +1 -1
  631. package/dist/src/utils/environmentContext.d.ts +1 -0
  632. package/dist/src/utils/environmentContext.js +4 -0
  633. package/dist/src/utils/environmentContext.js.map +1 -1
  634. package/dist/src/utils/environmentContext.test.js +2 -0
  635. package/dist/src/utils/environmentContext.test.js.map +1 -1
  636. package/dist/src/utils/errorReporting.d.ts +1 -1
  637. package/dist/src/utils/errorReporting.js +13 -12
  638. package/dist/src/utils/errorReporting.js.map +1 -1
  639. package/dist/src/utils/errorReporting.test.js +17 -14
  640. package/dist/src/utils/errorReporting.test.js.map +1 -1
  641. package/dist/src/utils/events.d.ts +71 -19
  642. package/dist/src/utils/events.js +35 -9
  643. package/dist/src/utils/events.js.map +1 -1
  644. package/dist/src/utils/events.test.js +25 -0
  645. package/dist/src/utils/events.test.js.map +1 -1
  646. package/dist/src/utils/fileDiffUtils.d.ts +18 -0
  647. package/dist/src/utils/fileDiffUtils.js +37 -0
  648. package/dist/src/utils/fileDiffUtils.js.map +1 -0
  649. package/dist/src/utils/fileDiffUtils.test.d.ts +6 -0
  650. package/dist/src/utils/fileDiffUtils.test.js +84 -0
  651. package/dist/src/utils/fileDiffUtils.test.js.map +1 -0
  652. package/dist/src/utils/fileUtils.d.ts +4 -0
  653. package/dist/src/utils/fileUtils.js +53 -0
  654. package/dist/src/utils/fileUtils.js.map +1 -1
  655. package/dist/src/utils/fileUtils.test.js +112 -1
  656. package/dist/src/utils/fileUtils.test.js.map +1 -1
  657. package/dist/src/utils/geminiIgnoreParser.d.ts +11 -0
  658. package/dist/src/utils/geminiIgnoreParser.js +20 -0
  659. package/dist/src/utils/geminiIgnoreParser.js.map +1 -1
  660. package/dist/src/utils/geminiIgnoreParser.test.js +48 -0
  661. package/dist/src/utils/geminiIgnoreParser.test.js.map +1 -1
  662. package/dist/src/utils/generateContentResponseUtilities.d.ts +3 -1
  663. package/dist/src/utils/generateContentResponseUtilities.js +106 -0
  664. package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
  665. package/dist/src/utils/generateContentResponseUtilities.test.js +279 -2
  666. package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -1
  667. package/dist/src/utils/getFolderStructure.js +7 -2
  668. package/dist/src/utils/getFolderStructure.js.map +1 -1
  669. package/dist/src/utils/gitIgnoreParser.js +9 -10
  670. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  671. package/dist/src/utils/installationManager.test.js +11 -3
  672. package/dist/src/utils/installationManager.test.js.map +1 -1
  673. package/dist/src/utils/memoryDiscovery.js +3 -4
  674. package/dist/src/utils/memoryDiscovery.js.map +1 -1
  675. package/dist/src/utils/memoryDiscovery.test.js +12 -1
  676. package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
  677. package/dist/src/utils/partUtils.js +1 -1
  678. package/dist/src/utils/partUtils.js.map +1 -1
  679. package/dist/src/utils/paths.d.ts +10 -0
  680. package/dist/src/utils/paths.js +20 -1
  681. package/dist/src/utils/paths.js.map +1 -1
  682. package/dist/src/utils/retry.d.ts +1 -0
  683. package/dist/src/utils/retry.js +17 -5
  684. package/dist/src/utils/retry.js.map +1 -1
  685. package/dist/src/utils/retry.test.js +11 -11
  686. package/dist/src/utils/retry.test.js.map +1 -1
  687. package/dist/src/utils/shell-utils.d.ts +6 -0
  688. package/dist/src/utils/shell-utils.js +97 -12
  689. package/dist/src/utils/shell-utils.js.map +1 -1
  690. package/dist/src/utils/shell-utils.test.js +99 -1
  691. package/dist/src/utils/shell-utils.test.js.map +1 -1
  692. package/dist/src/utils/summarizer.test.js +3 -2
  693. package/dist/src/utils/summarizer.test.js.map +1 -1
  694. package/dist/src/utils/terminal.d.ts +4 -0
  695. package/dist/src/utils/terminal.js +12 -0
  696. package/dist/src/utils/terminal.js.map +1 -1
  697. package/dist/src/utils/tokenCalculation.js +20 -5
  698. package/dist/src/utils/tokenCalculation.js.map +1 -1
  699. package/dist/src/utils/tokenCalculation.test.js +11 -2
  700. package/dist/src/utils/tokenCalculation.test.js.map +1 -1
  701. package/dist/src/utils/tool-utils.d.ts +9 -0
  702. package/dist/src/utils/tool-utils.js +29 -0
  703. package/dist/src/utils/tool-utils.js.map +1 -1
  704. package/dist/src/utils/tool-utils.test.js +17 -2
  705. package/dist/src/utils/tool-utils.test.js.map +1 -1
  706. package/dist/src/utils/userAccountManager.test.js +5 -5
  707. package/dist/src/utils/userAccountManager.test.js.map +1 -1
  708. package/dist/src/utils/workspaceContext.test.js +1 -1
  709. package/dist/src/utils/workspaceContext.test.js.map +1 -1
  710. package/dist/tsconfig.tsbuildinfo +1 -1
  711. package/package.json +8 -6
  712. package/dist/src/agents/executor.js.map +0 -1
  713. package/dist/src/agents/executor.test.js.map +0 -1
  714. package/dist/src/agents/invocation.js.map +0 -1
  715. package/dist/src/agents/invocation.test.js.map +0 -1
  716. package/dist/src/core/sessionHookTriggers.d.ts +0 -28
  717. package/dist/src/core/sessionHookTriggers.js +0 -68
  718. package/dist/src/core/sessionHookTriggers.js.map +0 -1
  719. package/dist/src/tools/smart-edit.d.ts +0 -78
  720. package/dist/src/tools/smart-edit.js +0 -722
  721. package/dist/src/tools/smart-edit.js.map +0 -1
  722. package/dist/src/tools/smart-edit.test.js +0 -592
  723. package/dist/src/tools/smart-edit.test.js.map +0 -1
  724. package/dist/src/utils/shell-permissions.d.ts +0 -52
  725. package/dist/src/utils/shell-permissions.js +0 -188
  726. package/dist/src/utils/shell-permissions.js.map +0 -1
  727. package/dist/src/utils/shell-permissions.test.js +0 -347
  728. package/dist/src/utils/shell-permissions.test.js.map +0 -1
  729. /package/dist/src/agents/{executor.test.d.ts → a2a-client-manager.test.d.ts} +0 -0
  730. /package/dist/src/agents/{invocation.test.d.ts → a2aUtils.test.d.ts} +0 -0
  731. /package/dist/src/{tools/smart-edit.test.d.ts → agents/agentLoader.test.d.ts} +0 -0
  732. /package/dist/src/{utils/shell-permissions.test.d.ts → agents/cli-help-agent.test.d.ts} +0 -0
@@ -5,21 +5,23 @@
5
5
  */
6
6
  import * as fs from 'node:fs';
7
7
  import * as path from 'node:path';
8
+ import * as crypto from 'node:crypto';
8
9
  import * as Diff from 'diff';
9
10
  import { BaseDeclarativeTool, BaseToolInvocation, Kind, ToolConfirmationOutcome, } from './tools.js';
10
11
  import { ToolErrorType } from './tool-error.js';
11
12
  import { makeRelative, shortenPath } from '../utils/paths.js';
12
13
  import { isNodeError } from '../utils/errors.js';
13
14
  import { ApprovalMode } from '../policy/types.js';
14
- import { ensureCorrectEdit } from '../utils/editCorrector.js';
15
15
  import { DEFAULT_DIFF_OPTIONS, getDiffStat } from './diffOptions.js';
16
- import { logFileOperation } from '../telemetry/loggers.js';
17
- import { FileOperationEvent } from '../telemetry/types.js';
18
- import { FileOperation } from '../telemetry/metrics.js';
19
- import { getSpecificMimeType } from '../utils/fileUtils.js';
20
- import { getLanguageFromFilePath } from '../utils/language-detection.js';
16
+ import {} from './modifiable-tool.js';
21
17
  import { IdeClient } from '../ide/ide-client.js';
18
+ import { FixLLMEditWithInstruction } from '../utils/llm-edit-fixer.js';
22
19
  import { safeLiteralReplace } from '../utils/textUtils.js';
20
+ import { EditStrategyEvent } from '../telemetry/types.js';
21
+ import { logEditStrategy } from '../telemetry/loggers.js';
22
+ import { EditCorrectionEvent } from '../telemetry/types.js';
23
+ import { logEditCorrectionEvent } from '../telemetry/loggers.js';
24
+ import { correctPath } from '../utils/pathCorrector.js';
23
25
  import { EDIT_TOOL_NAME, READ_FILE_TOOL_NAME } from './tool-names.js';
24
26
  import { debugLogger } from '../utils/debugLogger.js';
25
27
  export function applyReplacement(currentContent, oldString, newString, isNewFile) {
@@ -37,16 +39,295 @@ export function applyReplacement(currentContent, oldString, newString, isNewFile
37
39
  // Use intelligent replacement that handles $ sequences safely
38
40
  return safeLiteralReplace(currentContent, oldString, newString);
39
41
  }
42
+ /**
43
+ * Creates a SHA256 hash of the given content.
44
+ * @param content The string content to hash.
45
+ * @returns A hex-encoded hash string.
46
+ */
47
+ function hashContent(content) {
48
+ return crypto.createHash('sha256').update(content).digest('hex');
49
+ }
50
+ function restoreTrailingNewline(originalContent, modifiedContent) {
51
+ const hadTrailingNewline = originalContent.endsWith('\n');
52
+ if (hadTrailingNewline && !modifiedContent.endsWith('\n')) {
53
+ return modifiedContent + '\n';
54
+ }
55
+ else if (!hadTrailingNewline && modifiedContent.endsWith('\n')) {
56
+ return modifiedContent.replace(/\n$/, '');
57
+ }
58
+ return modifiedContent;
59
+ }
60
+ /**
61
+ * Escapes characters with special meaning in regular expressions.
62
+ * @param str The string to escape.
63
+ * @returns The escaped string.
64
+ */
65
+ function escapeRegex(str) {
66
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
67
+ }
68
+ async function calculateExactReplacement(context) {
69
+ const { currentContent, params } = context;
70
+ const { old_string, new_string } = params;
71
+ const normalizedCode = currentContent;
72
+ const normalizedSearch = old_string.replace(/\r\n/g, '\n');
73
+ const normalizedReplace = new_string.replace(/\r\n/g, '\n');
74
+ const exactOccurrences = normalizedCode.split(normalizedSearch).length - 1;
75
+ if (exactOccurrences > 0) {
76
+ let modifiedCode = safeLiteralReplace(normalizedCode, normalizedSearch, normalizedReplace);
77
+ modifiedCode = restoreTrailingNewline(currentContent, modifiedCode);
78
+ return {
79
+ newContent: modifiedCode,
80
+ occurrences: exactOccurrences,
81
+ finalOldString: normalizedSearch,
82
+ finalNewString: normalizedReplace,
83
+ };
84
+ }
85
+ return null;
86
+ }
87
+ async function calculateFlexibleReplacement(context) {
88
+ const { currentContent, params } = context;
89
+ const { old_string, new_string } = params;
90
+ const normalizedCode = currentContent;
91
+ const normalizedSearch = old_string.replace(/\r\n/g, '\n');
92
+ const normalizedReplace = new_string.replace(/\r\n/g, '\n');
93
+ const sourceLines = normalizedCode.match(/.*(?:\n|$)/g)?.slice(0, -1) ?? [];
94
+ const searchLinesStripped = normalizedSearch
95
+ .split('\n')
96
+ .map((line) => line.trim());
97
+ const replaceLines = normalizedReplace.split('\n');
98
+ let flexibleOccurrences = 0;
99
+ let i = 0;
100
+ while (i <= sourceLines.length - searchLinesStripped.length) {
101
+ const window = sourceLines.slice(i, i + searchLinesStripped.length);
102
+ const windowStripped = window.map((line) => line.trim());
103
+ const isMatch = windowStripped.every((line, index) => line === searchLinesStripped[index]);
104
+ if (isMatch) {
105
+ flexibleOccurrences++;
106
+ const firstLineInMatch = window[0];
107
+ const indentationMatch = firstLineInMatch.match(/^(\s*)/);
108
+ const indentation = indentationMatch ? indentationMatch[1] : '';
109
+ const newBlockWithIndent = replaceLines.map((line) => `${indentation}${line}`);
110
+ sourceLines.splice(i, searchLinesStripped.length, newBlockWithIndent.join('\n'));
111
+ i += replaceLines.length;
112
+ }
113
+ else {
114
+ i++;
115
+ }
116
+ }
117
+ if (flexibleOccurrences > 0) {
118
+ let modifiedCode = sourceLines.join('');
119
+ modifiedCode = restoreTrailingNewline(currentContent, modifiedCode);
120
+ return {
121
+ newContent: modifiedCode,
122
+ occurrences: flexibleOccurrences,
123
+ finalOldString: normalizedSearch,
124
+ finalNewString: normalizedReplace,
125
+ };
126
+ }
127
+ return null;
128
+ }
129
+ async function calculateRegexReplacement(context) {
130
+ const { currentContent, params } = context;
131
+ const { old_string, new_string } = params;
132
+ // Normalize line endings for consistent processing.
133
+ const normalizedSearch = old_string.replace(/\r\n/g, '\n');
134
+ const normalizedReplace = new_string.replace(/\r\n/g, '\n');
135
+ // This logic is ported from your Python implementation.
136
+ // It builds a flexible, multi-line regex from a search string.
137
+ const delimiters = ['(', ')', ':', '[', ']', '{', '}', '>', '<', '='];
138
+ let processedString = normalizedSearch;
139
+ for (const delim of delimiters) {
140
+ processedString = processedString.split(delim).join(` ${delim} `);
141
+ }
142
+ // Split by any whitespace and remove empty strings.
143
+ const tokens = processedString.split(/\s+/).filter(Boolean);
144
+ if (tokens.length === 0) {
145
+ return null;
146
+ }
147
+ const escapedTokens = tokens.map(escapeRegex);
148
+ // Join tokens with `\s*` to allow for flexible whitespace between them.
149
+ const pattern = escapedTokens.join('\\s*');
150
+ // The final pattern captures leading whitespace (indentation) and then matches the token pattern.
151
+ // 'm' flag enables multi-line mode, so '^' matches the start of any line.
152
+ const finalPattern = `^(\\s*)${pattern}`;
153
+ const flexibleRegex = new RegExp(finalPattern, 'm');
154
+ const match = flexibleRegex.exec(currentContent);
155
+ if (!match) {
156
+ return null;
157
+ }
158
+ const indentation = match[1] || '';
159
+ const newLines = normalizedReplace.split('\n');
160
+ const newBlockWithIndent = newLines
161
+ .map((line) => `${indentation}${line}`)
162
+ .join('\n');
163
+ // Use replace with the regex to substitute the matched content.
164
+ // Since the regex doesn't have the 'g' flag, it will only replace the first occurrence.
165
+ const modifiedCode = currentContent.replace(flexibleRegex, newBlockWithIndent);
166
+ return {
167
+ newContent: restoreTrailingNewline(currentContent, modifiedCode),
168
+ occurrences: 1, // This method is designed to find and replace only the first occurrence.
169
+ finalOldString: normalizedSearch,
170
+ finalNewString: normalizedReplace,
171
+ };
172
+ }
173
+ /**
174
+ * Detects the line ending style of a string.
175
+ * @param content The string content to analyze.
176
+ * @returns '\r\n' for Windows-style, '\n' for Unix-style.
177
+ */
178
+ function detectLineEnding(content) {
179
+ // If a Carriage Return is found, assume Windows-style endings.
180
+ // This is a simple but effective heuristic.
181
+ return content.includes('\r\n') ? '\r\n' : '\n';
182
+ }
183
+ export async function calculateReplacement(config, context) {
184
+ const { currentContent, params } = context;
185
+ const { old_string, new_string } = params;
186
+ const normalizedSearch = old_string.replace(/\r\n/g, '\n');
187
+ const normalizedReplace = new_string.replace(/\r\n/g, '\n');
188
+ if (normalizedSearch === '') {
189
+ return {
190
+ newContent: currentContent,
191
+ occurrences: 0,
192
+ finalOldString: normalizedSearch,
193
+ finalNewString: normalizedReplace,
194
+ };
195
+ }
196
+ const exactResult = await calculateExactReplacement(context);
197
+ if (exactResult) {
198
+ const event = new EditStrategyEvent('exact');
199
+ logEditStrategy(config, event);
200
+ return exactResult;
201
+ }
202
+ const flexibleResult = await calculateFlexibleReplacement(context);
203
+ if (flexibleResult) {
204
+ const event = new EditStrategyEvent('flexible');
205
+ logEditStrategy(config, event);
206
+ return flexibleResult;
207
+ }
208
+ const regexResult = await calculateRegexReplacement(context);
209
+ if (regexResult) {
210
+ const event = new EditStrategyEvent('regex');
211
+ logEditStrategy(config, event);
212
+ return regexResult;
213
+ }
214
+ return {
215
+ newContent: currentContent,
216
+ occurrences: 0,
217
+ finalOldString: normalizedSearch,
218
+ finalNewString: normalizedReplace,
219
+ };
220
+ }
221
+ export function getErrorReplaceResult(params, occurrences, expectedReplacements, finalOldString, finalNewString) {
222
+ let error = undefined;
223
+ if (occurrences === 0) {
224
+ error = {
225
+ display: `Failed to edit, could not find the string to replace.`,
226
+ raw: `Failed to edit, 0 occurrences found for old_string (${finalOldString}). Original old_string was (${params.old_string}) in ${params.file_path}. No edits made. The exact text in old_string was not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context. Use ${READ_FILE_TOOL_NAME} tool to verify.`,
227
+ type: ToolErrorType.EDIT_NO_OCCURRENCE_FOUND,
228
+ };
229
+ }
230
+ else if (occurrences !== expectedReplacements) {
231
+ const occurrenceTerm = expectedReplacements === 1 ? 'occurrence' : 'occurrences';
232
+ error = {
233
+ display: `Failed to edit, expected ${expectedReplacements} ${occurrenceTerm} but found ${occurrences}.`,
234
+ raw: `Failed to edit, Expected ${expectedReplacements} ${occurrenceTerm} but found ${occurrences} for old_string in file: ${params.file_path}`,
235
+ type: ToolErrorType.EDIT_EXPECTED_OCCURRENCE_MISMATCH,
236
+ };
237
+ }
238
+ else if (finalOldString === finalNewString) {
239
+ error = {
240
+ display: `No changes to apply. The old_string and new_string are identical.`,
241
+ raw: `No changes to apply. The old_string and new_string are identical in file: ${params.file_path}`,
242
+ type: ToolErrorType.EDIT_NO_CHANGE,
243
+ };
244
+ }
245
+ return error;
246
+ }
40
247
  class EditToolInvocation extends BaseToolInvocation {
41
248
  config;
42
- resolvedPath;
43
249
  constructor(config, params, messageBus, toolName, displayName) {
44
250
  super(params, messageBus, toolName, displayName);
45
251
  this.config = config;
46
- this.resolvedPath = path.resolve(this.config.getTargetDir(), this.params.file_path);
47
252
  }
48
253
  toolLocations() {
49
- return [{ path: this.resolvedPath }];
254
+ return [{ path: this.params.file_path }];
255
+ }
256
+ async attemptSelfCorrection(params, currentContent, initialError, abortSignal, originalLineEnding) {
257
+ // In order to keep from clobbering edits made outside our system,
258
+ // check if the file has been modified since we first read it.
259
+ let errorForLlmEditFixer = initialError.raw;
260
+ let contentForLlmEditFixer = currentContent;
261
+ const initialContentHash = hashContent(currentContent);
262
+ const onDiskContent = await this.config
263
+ .getFileSystemService()
264
+ .readTextFile(params.file_path);
265
+ const onDiskContentHash = hashContent(onDiskContent.replace(/\r\n/g, '\n'));
266
+ if (initialContentHash !== onDiskContentHash) {
267
+ // The file has changed on disk since we first read it.
268
+ // Use the latest content for the correction attempt.
269
+ contentForLlmEditFixer = onDiskContent.replace(/\r\n/g, '\n');
270
+ errorForLlmEditFixer = `The initial edit attempt failed with the following error: "${initialError.raw}". However, the file has been modified by either the user or an external process since that edit attempt. The file content provided to you is the latest version. Please base your correction on this new content.`;
271
+ }
272
+ const fixedEdit = await FixLLMEditWithInstruction(params.instruction ?? 'Apply the requested edit.', params.old_string, params.new_string, errorForLlmEditFixer, contentForLlmEditFixer, this.config.getBaseLlmClient(), abortSignal);
273
+ // If the self-correction attempt timed out, return the original error.
274
+ if (fixedEdit === null) {
275
+ return {
276
+ currentContent: contentForLlmEditFixer,
277
+ newContent: currentContent,
278
+ occurrences: 0,
279
+ isNewFile: false,
280
+ error: initialError,
281
+ originalLineEnding,
282
+ };
283
+ }
284
+ if (fixedEdit.noChangesRequired) {
285
+ return {
286
+ currentContent,
287
+ newContent: currentContent,
288
+ occurrences: 0,
289
+ isNewFile: false,
290
+ error: {
291
+ display: `No changes required. The file already meets the specified conditions.`,
292
+ raw: `A secondary check by an LLM determined that no changes were necessary to fulfill the instruction. Explanation: ${fixedEdit.explanation}. Original error with the parameters given: ${initialError.raw}`,
293
+ type: ToolErrorType.EDIT_NO_CHANGE_LLM_JUDGEMENT,
294
+ },
295
+ originalLineEnding,
296
+ };
297
+ }
298
+ const secondAttemptResult = await calculateReplacement(this.config, {
299
+ params: {
300
+ ...params,
301
+ old_string: fixedEdit.search,
302
+ new_string: fixedEdit.replace,
303
+ },
304
+ currentContent: contentForLlmEditFixer,
305
+ abortSignal,
306
+ });
307
+ const secondError = getErrorReplaceResult(params, secondAttemptResult.occurrences, params.expected_replacements ?? 1, secondAttemptResult.finalOldString, secondAttemptResult.finalNewString);
308
+ if (secondError) {
309
+ // The fix failed, log failure and return the original error
310
+ const event = new EditCorrectionEvent('failure');
311
+ logEditCorrectionEvent(this.config, event);
312
+ return {
313
+ currentContent: contentForLlmEditFixer,
314
+ newContent: currentContent,
315
+ occurrences: 0,
316
+ isNewFile: false,
317
+ error: initialError,
318
+ originalLineEnding,
319
+ };
320
+ }
321
+ const event = new EditCorrectionEvent('success');
322
+ logEditCorrectionEvent(this.config, event);
323
+ return {
324
+ currentContent: contentForLlmEditFixer,
325
+ newContent: secondAttemptResult.newContent,
326
+ occurrences: secondAttemptResult.occurrences,
327
+ isNewFile: false,
328
+ error: undefined,
329
+ originalLineEnding,
330
+ };
50
331
  }
51
332
  /**
52
333
  * Calculates the potential outcome of an edit operation.
@@ -58,100 +339,103 @@ class EditToolInvocation extends BaseToolInvocation {
58
339
  const expectedReplacements = params.expected_replacements ?? 1;
59
340
  let currentContent = null;
60
341
  let fileExists = false;
61
- let isNewFile = false;
62
- let finalNewString = params.new_string;
63
- let finalOldString = params.old_string;
64
- let occurrences = 0;
65
- let error = undefined;
342
+ let originalLineEnding = '\n'; // Default for new files
66
343
  try {
67
344
  currentContent = await this.config
68
345
  .getFileSystemService()
69
- .readTextFile(this.resolvedPath);
70
- // Normalize line endings to LF for consistent processing.
346
+ .readTextFile(params.file_path);
347
+ originalLineEnding = detectLineEnding(currentContent);
71
348
  currentContent = currentContent.replace(/\r\n/g, '\n');
72
349
  fileExists = true;
73
350
  }
74
351
  catch (err) {
75
352
  if (!isNodeError(err) || err.code !== 'ENOENT') {
76
- // Rethrow unexpected FS errors (permissions, etc.)
77
353
  throw err;
78
354
  }
79
355
  fileExists = false;
80
356
  }
81
- if (params.old_string === '' && !fileExists) {
82
- // Creating a new file
83
- isNewFile = true;
357
+ const isNewFile = params.old_string === '' && !fileExists;
358
+ if (isNewFile) {
359
+ return {
360
+ currentContent,
361
+ newContent: params.new_string,
362
+ occurrences: 1,
363
+ isNewFile: true,
364
+ error: undefined,
365
+ originalLineEnding,
366
+ };
367
+ }
368
+ // after this point, it's not a new file/edit
369
+ if (!fileExists) {
370
+ return {
371
+ currentContent,
372
+ newContent: '',
373
+ occurrences: 0,
374
+ isNewFile: false,
375
+ error: {
376
+ display: `File not found. Cannot apply edit. Use an empty old_string to create a new file.`,
377
+ raw: `File not found: ${params.file_path}`,
378
+ type: ToolErrorType.FILE_NOT_FOUND,
379
+ },
380
+ originalLineEnding,
381
+ };
84
382
  }
85
- else if (!fileExists) {
86
- // Trying to edit a nonexistent file (and old_string is not empty)
87
- error = {
88
- display: `File not found. Cannot apply edit. Use an empty old_string to create a new file.`,
89
- raw: `File not found: ${this.resolvedPath}`,
90
- type: ToolErrorType.FILE_NOT_FOUND,
383
+ if (currentContent === null) {
384
+ return {
385
+ currentContent,
386
+ newContent: '',
387
+ occurrences: 0,
388
+ isNewFile: false,
389
+ error: {
390
+ display: `Failed to read content of file.`,
391
+ raw: `Failed to read content of existing file: ${params.file_path}`,
392
+ type: ToolErrorType.READ_CONTENT_FAILURE,
393
+ },
394
+ originalLineEnding,
91
395
  };
92
396
  }
93
- else if (currentContent !== null) {
94
- // Editing an existing file
95
- const correctedEdit = await ensureCorrectEdit(this.resolvedPath, currentContent, params, this.config.getGeminiClient(), this.config.getBaseLlmClient(), abortSignal);
96
- finalOldString = correctedEdit.params.old_string;
97
- finalNewString = correctedEdit.params.new_string;
98
- occurrences = correctedEdit.occurrences;
99
- if (params.old_string === '') {
100
- // Error: Trying to create a file that already exists
101
- error = {
397
+ if (params.old_string === '') {
398
+ return {
399
+ currentContent,
400
+ newContent: currentContent,
401
+ occurrences: 0,
402
+ isNewFile: false,
403
+ error: {
102
404
  display: `Failed to edit. Attempted to create a file that already exists.`,
103
- raw: `File already exists, cannot create: ${this.resolvedPath}`,
405
+ raw: `File already exists, cannot create: ${params.file_path}`,
104
406
  type: ToolErrorType.ATTEMPT_TO_CREATE_EXISTING_FILE,
105
- };
106
- }
107
- else if (occurrences === 0) {
108
- error = {
109
- display: `Failed to edit, could not find the string to replace.`,
110
- raw: `Failed to edit, 0 occurrences found for old_string in ${this.resolvedPath}. No edits made. The exact text in old_string was not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context. Use ${READ_FILE_TOOL_NAME} tool to verify.`,
111
- type: ToolErrorType.EDIT_NO_OCCURRENCE_FOUND,
112
- };
113
- }
114
- else if (occurrences !== expectedReplacements) {
115
- const occurrenceTerm = expectedReplacements === 1 ? 'occurrence' : 'occurrences';
116
- error = {
117
- display: `Failed to edit, expected ${expectedReplacements} ${occurrenceTerm} but found ${occurrences}.`,
118
- raw: `Failed to edit, Expected ${expectedReplacements} ${occurrenceTerm} but found ${occurrences} for old_string in file: ${this.resolvedPath}`,
119
- type: ToolErrorType.EDIT_EXPECTED_OCCURRENCE_MISMATCH,
120
- };
121
- }
122
- else if (finalOldString === finalNewString) {
123
- error = {
124
- display: `No changes to apply. The old_string and new_string are identical.`,
125
- raw: `No changes to apply. The old_string and new_string are identical in file: ${this.resolvedPath}`,
126
- type: ToolErrorType.EDIT_NO_CHANGE,
127
- };
128
- }
407
+ },
408
+ originalLineEnding,
409
+ };
129
410
  }
130
- else {
131
- // Should not happen if fileExists and no exception was thrown, but defensively:
132
- error = {
133
- display: `Failed to read content of file.`,
134
- raw: `Failed to read content of existing file: ${this.resolvedPath}`,
135
- type: ToolErrorType.READ_CONTENT_FAILURE,
411
+ const replacementResult = await calculateReplacement(this.config, {
412
+ params,
413
+ currentContent,
414
+ abortSignal,
415
+ });
416
+ const initialError = getErrorReplaceResult(params, replacementResult.occurrences, expectedReplacements, replacementResult.finalOldString, replacementResult.finalNewString);
417
+ if (!initialError) {
418
+ return {
419
+ currentContent,
420
+ newContent: replacementResult.newContent,
421
+ occurrences: replacementResult.occurrences,
422
+ isNewFile: false,
423
+ error: undefined,
424
+ originalLineEnding,
136
425
  };
137
426
  }
138
- const newContent = !error
139
- ? applyReplacement(currentContent, finalOldString, finalNewString, isNewFile)
140
- : (currentContent ?? '');
141
- if (!error && fileExists && currentContent === newContent) {
142
- error = {
143
- display: 'No changes to apply. The new content is identical to the current content.',
144
- raw: `No changes to apply. The new content is identical to the current content in file: ${this.resolvedPath}`,
145
- type: ToolErrorType.EDIT_NO_CHANGE,
427
+ if (this.config.getDisableLLMCorrection()) {
428
+ return {
429
+ currentContent,
430
+ newContent: currentContent,
431
+ occurrences: replacementResult.occurrences,
432
+ isNewFile: false,
433
+ error: initialError,
434
+ originalLineEnding,
146
435
  };
147
436
  }
148
- return {
149
- currentContent,
150
- newContent,
151
- occurrences,
152
- error,
153
- isNewFile,
154
- };
437
+ // If there was an error, try to self-correct.
438
+ return this.attemptSelfCorrection(params, currentContent, initialError, abortSignal, originalLineEnding);
155
439
  }
156
440
  /**
157
441
  * Handles the confirmation prompt for the Edit tool in the CLI.
@@ -177,17 +461,17 @@ class EditToolInvocation extends BaseToolInvocation {
177
461
  debugLogger.log(`Error: ${editData.error.display}`);
178
462
  return false;
179
463
  }
180
- const fileName = path.basename(this.resolvedPath);
464
+ const fileName = path.basename(this.params.file_path);
181
465
  const fileDiff = Diff.createPatch(fileName, editData.currentContent ?? '', editData.newContent, 'Current', 'Proposed', DEFAULT_DIFF_OPTIONS);
182
466
  const ideClient = await IdeClient.getInstance();
183
467
  const ideConfirmation = this.config.getIdeMode() && ideClient.isDiffingEnabled()
184
- ? ideClient.openDiff(this.resolvedPath, editData.newContent)
468
+ ? ideClient.openDiff(this.params.file_path, editData.newContent)
185
469
  : undefined;
186
470
  const confirmationDetails = {
187
471
  type: 'edit',
188
472
  title: `Confirm Edit: ${shortenPath(makeRelative(this.params.file_path, this.config.getTargetDir()))}`,
189
473
  fileName,
190
- filePath: this.resolvedPath,
474
+ filePath: this.params.file_path,
191
475
  fileDiff,
192
476
  originalContent: editData.currentContent,
193
477
  newContent: editData.newContent,
@@ -263,34 +547,40 @@ class EditToolInvocation extends BaseToolInvocation {
263
547
  };
264
548
  }
265
549
  try {
266
- this.ensureParentDirectoriesExist(this.resolvedPath);
550
+ this.ensureParentDirectoriesExist(this.params.file_path);
551
+ let finalContent = editData.newContent;
552
+ // Restore original line endings if they were CRLF
553
+ if (!editData.isNewFile && editData.originalLineEnding === '\r\n') {
554
+ finalContent = finalContent.replace(/\n/g, '\r\n');
555
+ }
267
556
  await this.config
268
557
  .getFileSystemService()
269
- .writeTextFile(this.resolvedPath, editData.newContent);
270
- const fileName = path.basename(this.resolvedPath);
271
- const originallyProposedContent = this.params.ai_proposed_content || editData.newContent;
272
- const diffStat = getDiffStat(fileName, editData.currentContent ?? '', originallyProposedContent, editData.newContent);
273
- const fileDiff = Diff.createPatch(fileName, editData.currentContent ?? '', // Should not be null here if not isNewFile
274
- editData.newContent, 'Current', 'Proposed', DEFAULT_DIFF_OPTIONS);
275
- const displayResult = {
276
- fileDiff,
277
- fileName,
278
- originalContent: editData.currentContent,
279
- newContent: editData.newContent,
280
- diffStat,
281
- };
282
- // Log file operation for telemetry (without diff_stat to avoid double-counting)
283
- const mimetype = getSpecificMimeType(this.resolvedPath);
284
- const programmingLanguage = getLanguageFromFilePath(this.resolvedPath);
285
- const extension = path.extname(this.resolvedPath);
286
- const operation = editData.isNewFile
287
- ? FileOperation.CREATE
288
- : FileOperation.UPDATE;
289
- logFileOperation(this.config, new FileOperationEvent(EDIT_TOOL_NAME, operation, editData.newContent.split('\n').length, mimetype, extension, programmingLanguage));
558
+ .writeTextFile(this.params.file_path, finalContent);
559
+ let displayResult;
560
+ if (editData.isNewFile) {
561
+ displayResult = `Created ${shortenPath(makeRelative(this.params.file_path, this.config.getTargetDir()))}`;
562
+ }
563
+ else {
564
+ // Generate diff for display, even though core logic doesn't technically need it
565
+ // The CLI wrapper will use this part of the ToolResult
566
+ const fileName = path.basename(this.params.file_path);
567
+ const fileDiff = Diff.createPatch(fileName, editData.currentContent ?? '', // Should not be null here if not isNewFile
568
+ editData.newContent, 'Current', 'Proposed', DEFAULT_DIFF_OPTIONS);
569
+ const diffStat = getDiffStat(fileName, editData.currentContent ?? '', editData.newContent, this.params.new_string);
570
+ displayResult = {
571
+ fileDiff,
572
+ fileName,
573
+ filePath: this.params.file_path,
574
+ originalContent: editData.currentContent,
575
+ newContent: editData.newContent,
576
+ diffStat,
577
+ isNewFile: editData.isNewFile,
578
+ };
579
+ }
290
580
  const llmSuccessMessageParts = [
291
581
  editData.isNewFile
292
- ? `Created new file: ${this.resolvedPath} with provided content.`
293
- : `Successfully modified file: ${this.resolvedPath} (${editData.occurrences} replacements).`,
582
+ ? `Created new file: ${this.params.file_path} with provided content.`
583
+ : `Successfully modified file: ${this.params.file_path} (${editData.occurrences} replacements).`,
294
584
  ];
295
585
  if (this.params.modified_by_user) {
296
586
  llmSuccessMessageParts.push(`User modified the \`new_string\` content to be: ${this.params.new_string}.`);
@@ -330,23 +620,42 @@ export class EditTool extends BaseDeclarativeTool {
330
620
  static Name = EDIT_TOOL_NAME;
331
621
  constructor(config, messageBus) {
332
622
  super(EditTool.Name, 'Edit', `Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when \`expected_replacements\` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the ${READ_FILE_TOOL_NAME} tool to examine the file's current content before attempting a text replacement.
333
-
623
+
334
624
  The user has the ability to modify the \`new_string\` content. If modified, this will be stated in the response.
335
-
336
- Expectation for required parameters:
337
- 1. \`file_path\` is the path to the file to modify.
338
- 2. \`old_string\` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).
339
- 3. \`new_string\` MUST be the exact literal text to replace \`old_string\` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic.
340
- 4. NEVER escape \`old_string\` or \`new_string\`, that would break the exact literal text requirement.
341
- **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for \`old_string\`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.
342
- **Multiple replacements:** Set \`expected_replacements\` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match \`old_string\` exactly. Ensure the number of replacements matches your expectation.`, Kind.Edit, {
625
+
626
+ Expectation for required parameters:
627
+ 1. \`old_string\` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).
628
+ 2. \`new_string\` MUST be the exact literal text to replace \`old_string\` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that \`old_string\` and \`new_string\` are different.
629
+ 3. \`instruction\` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary.
630
+ 4. NEVER escape \`old_string\` or \`new_string\`, that would break the exact literal text requirement.
631
+ **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for \`old_string\`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.
632
+ 5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.
633
+ **Multiple replacements:** Set \`expected_replacements\` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match \`old_string\` exactly. Ensure the number of replacements matches your expectation.`, Kind.Edit, {
343
634
  properties: {
344
635
  file_path: {
345
636
  description: 'The path to the file to modify.',
346
637
  type: 'string',
347
638
  },
639
+ instruction: {
640
+ description: `A clear, semantic instruction for the code change, acting as a high-quality prompt for an expert LLM assistant. It must be self-contained and explain the goal of the change.
641
+
642
+ A good instruction should concisely answer:
643
+ 1. WHY is the change needed? (e.g., "To fix a bug where users can be null...")
644
+ 2. WHERE should the change happen? (e.g., "...in the 'renderUserProfile' function...")
645
+ 3. WHAT is the high-level change? (e.g., "...add a null check for the 'user' object...")
646
+ 4. WHAT is the desired outcome? (e.g., "...so that it displays a loading spinner instead of crashing.")
647
+
648
+ **GOOD Example:** "In the 'calculateTotal' function, correct the sales tax calculation by updating the 'taxRate' constant from 0.05 to 0.075 to reflect the new regional tax laws."
649
+
650
+ **BAD Examples:**
651
+ - "Change the text." (Too vague)
652
+ - "Fix the bug." (Doesn't explain the bug or the fix)
653
+ - "Replace the line with this new line." (Brittle, just repeats the other parameters)
654
+ `,
655
+ type: 'string',
656
+ },
348
657
  old_string: {
349
- description: 'The exact literal text to replace, preferably unescaped. For single replacements (default), include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. For multiple replacements, specify expected_replacements parameter. If this string is not the exact literal text (i.e. you escaped it) or does not match exactly, the tool will fail.',
658
+ description: 'The exact literal text to replace, preferably unescaped. For single replacements (default), include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string is not the exact literal text (i.e. you escaped it) or does not match exactly, the tool will fail.',
350
659
  type: 'string',
351
660
  },
352
661
  new_string: {
@@ -359,11 +668,10 @@ Expectation for required parameters:
359
668
  minimum: 1,
360
669
  },
361
670
  },
362
- required: ['file_path', 'old_string', 'new_string'],
671
+ required: ['file_path', 'instruction', 'old_string', 'new_string'],
363
672
  type: 'object',
364
- }, true, // isOutputMarkdown
365
- false, // canUpdateOutput
366
- messageBus);
673
+ }, messageBus, true, // isOutputMarkdown
674
+ false);
367
675
  this.config = config;
368
676
  }
369
677
  /**
@@ -375,26 +683,34 @@ Expectation for required parameters:
375
683
  if (!params.file_path) {
376
684
  return "The 'file_path' parameter must be non-empty.";
377
685
  }
378
- const resolvedPath = path.resolve(this.config.getTargetDir(), params.file_path);
686
+ let filePath = params.file_path;
687
+ if (!path.isAbsolute(filePath)) {
688
+ // Attempt to auto-correct to an absolute path
689
+ const result = correctPath(filePath, this.config);
690
+ if (!result.success) {
691
+ return result.error;
692
+ }
693
+ filePath = result.correctedPath;
694
+ }
695
+ params.file_path = filePath;
379
696
  const workspaceContext = this.config.getWorkspaceContext();
380
- if (!workspaceContext.isPathWithinWorkspace(resolvedPath)) {
697
+ if (!workspaceContext.isPathWithinWorkspace(params.file_path)) {
381
698
  const directories = workspaceContext.getDirectories();
382
699
  return `File path must be within one of the workspace directories: ${directories.join(', ')}`;
383
700
  }
384
701
  return null;
385
702
  }
386
- createInvocation(params, messageBus, toolName, displayName) {
387
- return new EditToolInvocation(this.config, params, messageBus ?? this.messageBus, toolName ?? this.name, displayName ?? this.displayName);
703
+ createInvocation(params, messageBus) {
704
+ return new EditToolInvocation(this.config, params, messageBus, this.name, this.displayName);
388
705
  }
389
706
  getModifyContext(_) {
390
- const resolvePath = (filePath) => path.resolve(this.config.getTargetDir(), filePath);
391
707
  return {
392
708
  getFilePath: (params) => params.file_path,
393
709
  getCurrentContent: async (params) => {
394
710
  try {
395
711
  return await this.config
396
712
  .getFileSystemService()
397
- .readTextFile(resolvePath(params.file_path));
713
+ .readTextFile(params.file_path);
398
714
  }
399
715
  catch (err) {
400
716
  if (!isNodeError(err) || err.code !== 'ENOENT')
@@ -406,7 +722,7 @@ Expectation for required parameters:
406
722
  try {
407
723
  const currentContent = await this.config
408
724
  .getFileSystemService()
409
- .readTextFile(resolvePath(params.file_path));
725
+ .readTextFile(params.file_path);
410
726
  return applyReplacement(currentContent, params.old_string, params.new_string, params.old_string === '' && currentContent === '');
411
727
  }
412
728
  catch (err) {
@@ -415,13 +731,16 @@ Expectation for required parameters:
415
731
  return '';
416
732
  }
417
733
  },
418
- createUpdatedParams: (oldContent, modifiedProposedContent, originalParams) => ({
419
- ...originalParams,
420
- ai_proposed_content: oldContent,
421
- old_string: oldContent,
422
- new_string: modifiedProposedContent,
423
- modified_by_user: true,
424
- }),
734
+ createUpdatedParams: (oldContent, modifiedProposedContent, originalParams) => {
735
+ const content = originalParams.new_string;
736
+ return {
737
+ ...originalParams,
738
+ ai_proposed_content: content,
739
+ old_string: oldContent,
740
+ new_string: modifiedProposedContent,
741
+ modified_by_user: true,
742
+ };
743
+ },
425
744
  };
426
745
  }
427
746
  }