@greppleai/grip 0.0.0-stage → 0.1.3

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 (1119) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +731 -2
  3. package/dist/bun/cli.d.ts +3 -0
  4. package/dist/bun/cli.d.ts.map +1 -0
  5. package/dist/bun/cli.js +13 -0
  6. package/dist/bun/cli.js.map +1 -0
  7. package/dist/bun/embedded-assets.d.ts +3 -0
  8. package/dist/bun/embedded-assets.d.ts.map +1 -0
  9. package/dist/bun/embedded-assets.js +52 -0
  10. package/dist/bun/embedded-assets.js.map +1 -0
  11. package/dist/bun/register-bedrock.d.ts +2 -0
  12. package/dist/bun/register-bedrock.d.ts.map +1 -0
  13. package/dist/bun/register-bedrock.js +4 -0
  14. package/dist/bun/register-bedrock.js.map +1 -0
  15. package/dist/bun/restore-sandbox-env.d.ts +13 -0
  16. package/dist/bun/restore-sandbox-env.d.ts.map +1 -0
  17. package/dist/bun/restore-sandbox-env.js +32 -0
  18. package/dist/bun/restore-sandbox-env.js.map +1 -0
  19. package/dist/cli/args.d.ts +70 -0
  20. package/dist/cli/args.d.ts.map +1 -0
  21. package/dist/cli/args.js +442 -0
  22. package/dist/cli/args.js.map +1 -0
  23. package/dist/cli/config-selector.d.ts +14 -0
  24. package/dist/cli/config-selector.d.ts.map +1 -0
  25. package/dist/cli/config-selector.js +31 -0
  26. package/dist/cli/config-selector.js.map +1 -0
  27. package/dist/cli/file-processor.d.ts +15 -0
  28. package/dist/cli/file-processor.d.ts.map +1 -0
  29. package/dist/cli/file-processor.js +60 -0
  30. package/dist/cli/file-processor.js.map +1 -0
  31. package/dist/cli/initial-message.d.ts +18 -0
  32. package/dist/cli/initial-message.d.ts.map +1 -0
  33. package/dist/cli/initial-message.js +22 -0
  34. package/dist/cli/initial-message.js.map +1 -0
  35. package/dist/cli/list-models.d.ts +9 -0
  36. package/dist/cli/list-models.d.ts.map +1 -0
  37. package/dist/cli/list-models.js +98 -0
  38. package/dist/cli/list-models.js.map +1 -0
  39. package/dist/cli/session-picker.d.ts +9 -0
  40. package/dist/cli/session-picker.d.ts.map +1 -0
  41. package/dist/cli/session-picker.js +35 -0
  42. package/dist/cli/session-picker.js.map +1 -0
  43. package/dist/cli.d.ts +3 -0
  44. package/dist/cli.d.ts.map +1 -0
  45. package/dist/cli.js +14 -0
  46. package/dist/cli.js.map +1 -0
  47. package/dist/config.d.ts +82 -0
  48. package/dist/config.d.ts.map +1 -0
  49. package/dist/config.js +406 -0
  50. package/dist/config.js.map +1 -0
  51. package/dist/core/agent-session.d.ts +970 -0
  52. package/dist/core/agent-session.d.ts.map +1 -0
  53. package/dist/core/agent-session.js +5191 -0
  54. package/dist/core/agent-session.js.map +1 -0
  55. package/dist/core/auth-guidance.d.ts +5 -0
  56. package/dist/core/auth-guidance.d.ts.map +1 -0
  57. package/dist/core/auth-guidance.js +21 -0
  58. package/dist/core/auth-guidance.js.map +1 -0
  59. package/dist/core/auth-storage.d.ts +150 -0
  60. package/dist/core/auth-storage.d.ts.map +1 -0
  61. package/dist/core/auth-storage.js +557 -0
  62. package/dist/core/auth-storage.js.map +1 -0
  63. package/dist/core/bash-executor.d.ts +26 -0
  64. package/dist/core/bash-executor.d.ts.map +1 -0
  65. package/dist/core/bash-executor.js +99 -0
  66. package/dist/core/bash-executor.js.map +1 -0
  67. package/dist/core/compaction/branch-summarization.d.ts +83 -0
  68. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  69. package/dist/core/compaction/branch-summarization.js +220 -0
  70. package/dist/core/compaction/branch-summarization.js.map +1 -0
  71. package/dist/core/compaction/compaction.d.ts +65 -0
  72. package/dist/core/compaction/compaction.d.ts.map +1 -0
  73. package/dist/core/compaction/compaction.js +550 -0
  74. package/dist/core/compaction/compaction.js.map +1 -0
  75. package/dist/core/compaction/compression-detection-ledger.d.ts +34 -0
  76. package/dist/core/compaction/compression-detection-ledger.d.ts.map +1 -0
  77. package/dist/core/compaction/compression-detection-ledger.js +52 -0
  78. package/dist/core/compaction/compression-detection-ledger.js.map +1 -0
  79. package/dist/core/compaction/compression-detector.d.ts +71 -0
  80. package/dist/core/compaction/compression-detector.d.ts.map +1 -0
  81. package/dist/core/compaction/compression-detector.js +407 -0
  82. package/dist/core/compaction/compression-detector.js.map +1 -0
  83. package/dist/core/compaction/compression-economics.d.ts +55 -0
  84. package/dist/core/compaction/compression-economics.d.ts.map +1 -0
  85. package/dist/core/compaction/compression-economics.js +151 -0
  86. package/dist/core/compaction/compression-economics.js.map +1 -0
  87. package/dist/core/compaction/utils.d.ts +28 -0
  88. package/dist/core/compaction/utils.d.ts.map +1 -0
  89. package/dist/core/compaction/utils.js +165 -0
  90. package/dist/core/compaction/utils.js.map +1 -0
  91. package/dist/core/defaults.d.ts +3 -0
  92. package/dist/core/defaults.d.ts.map +1 -0
  93. package/dist/core/defaults.js +2 -0
  94. package/dist/core/defaults.js.map +1 -0
  95. package/dist/core/diagnostics.d.ts +18 -0
  96. package/dist/core/diagnostics.d.ts.map +1 -0
  97. package/dist/core/diagnostics.js +2 -0
  98. package/dist/core/diagnostics.js.map +1 -0
  99. package/dist/core/event-bus.d.ts +9 -0
  100. package/dist/core/event-bus.d.ts.map +1 -0
  101. package/dist/core/event-bus.js +25 -0
  102. package/dist/core/event-bus.js.map +1 -0
  103. package/dist/core/exec.d.ts +29 -0
  104. package/dist/core/exec.d.ts.map +1 -0
  105. package/dist/core/exec.js +75 -0
  106. package/dist/core/exec.js.map +1 -0
  107. package/dist/core/export-html/ansi-to-html.d.ts +22 -0
  108. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  109. package/dist/core/export-html/ansi-to-html.js +245 -0
  110. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  111. package/dist/core/export-html/index.d.ts +21 -0
  112. package/dist/core/export-html/index.d.ts.map +1 -0
  113. package/dist/core/export-html/index.js +230 -0
  114. package/dist/core/export-html/index.js.map +1 -0
  115. package/dist/core/export-html/template.css +1066 -0
  116. package/dist/core/export-html/template.html +55 -0
  117. package/dist/core/export-html/template.js +1864 -0
  118. package/dist/core/export-html/tool-renderer.d.ts +32 -0
  119. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  120. package/dist/core/export-html/tool-renderer.js +108 -0
  121. package/dist/core/export-html/tool-renderer.js.map +1 -0
  122. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  123. package/dist/core/export-html/vendor/marked.min.js +78 -0
  124. package/dist/core/extensions/loader.d.ts +24 -0
  125. package/dist/core/extensions/loader.d.ts.map +1 -0
  126. package/dist/core/extensions/loader.js +613 -0
  127. package/dist/core/extensions/loader.js.map +1 -0
  128. package/dist/core/extensions/runner.d.ts +160 -0
  129. package/dist/core/extensions/runner.d.ts.map +1 -0
  130. package/dist/core/extensions/runner.js +962 -0
  131. package/dist/core/extensions/runner.js.map +1 -0
  132. package/dist/core/extensions/types.d.ts +1311 -0
  133. package/dist/core/extensions/types.d.ts.map +1 -0
  134. package/dist/core/extensions/types.js +51 -0
  135. package/dist/core/extensions/types.js.map +1 -0
  136. package/dist/core/extensions/wrapper.d.ts +20 -0
  137. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  138. package/dist/core/extensions/wrapper.js +22 -0
  139. package/dist/core/extensions/wrapper.js.map +1 -0
  140. package/dist/core/footer-data-provider.d.ts +52 -0
  141. package/dist/core/footer-data-provider.d.ts.map +1 -0
  142. package/dist/core/footer-data-provider.js +318 -0
  143. package/dist/core/footer-data-provider.js.map +1 -0
  144. package/dist/core/grip-agent.d.ts +240 -0
  145. package/dist/core/grip-agent.d.ts.map +1 -0
  146. package/dist/core/grip-agent.js +1243 -0
  147. package/dist/core/grip-agent.js.map +1 -0
  148. package/dist/core/grip-manifest.d.ts +9 -0
  149. package/dist/core/grip-manifest.d.ts.map +1 -0
  150. package/dist/core/grip-manifest.js +25 -0
  151. package/dist/core/grip-manifest.js.map +1 -0
  152. package/dist/core/hooks/aggregate.d.ts +5 -0
  153. package/dist/core/hooks/aggregate.d.ts.map +1 -0
  154. package/dist/core/hooks/aggregate.js +226 -0
  155. package/dist/core/hooks/aggregate.js.map +1 -0
  156. package/dist/core/hooks/config.d.ts +14 -0
  157. package/dist/core/hooks/config.d.ts.map +1 -0
  158. package/dist/core/hooks/config.js +372 -0
  159. package/dist/core/hooks/config.js.map +1 -0
  160. package/dist/core/hooks/executor.d.ts +12 -0
  161. package/dist/core/hooks/executor.d.ts.map +1 -0
  162. package/dist/core/hooks/executor.js +708 -0
  163. package/dist/core/hooks/executor.js.map +1 -0
  164. package/dist/core/hooks/index.d.ts +9 -0
  165. package/dist/core/hooks/index.d.ts.map +1 -0
  166. package/dist/core/hooks/index.js +14 -0
  167. package/dist/core/hooks/index.js.map +1 -0
  168. package/dist/core/hooks/matcher.d.ts +10 -0
  169. package/dist/core/hooks/matcher.d.ts.map +1 -0
  170. package/dist/core/hooks/matcher.js +70 -0
  171. package/dist/core/hooks/matcher.js.map +1 -0
  172. package/dist/core/hooks/trust-store.d.ts +38 -0
  173. package/dist/core/hooks/trust-store.d.ts.map +1 -0
  174. package/dist/core/hooks/trust-store.js +167 -0
  175. package/dist/core/hooks/trust-store.js.map +1 -0
  176. package/dist/core/hooks/types.d.ts +234 -0
  177. package/dist/core/hooks/types.d.ts.map +1 -0
  178. package/dist/core/hooks/types.js +52 -0
  179. package/dist/core/hooks/types.js.map +1 -0
  180. package/dist/core/http-dispatcher.d.ts +21 -0
  181. package/dist/core/http-dispatcher.d.ts.map +1 -0
  182. package/dist/core/http-dispatcher.js +82 -0
  183. package/dist/core/http-dispatcher.js.map +1 -0
  184. package/dist/core/instruction-resource-loader.d.ts +81 -0
  185. package/dist/core/instruction-resource-loader.d.ts.map +1 -0
  186. package/dist/core/instruction-resource-loader.js +574 -0
  187. package/dist/core/instruction-resource-loader.js.map +1 -0
  188. package/dist/core/keybindings.d.ts +399 -0
  189. package/dist/core/keybindings.d.ts.map +1 -0
  190. package/dist/core/keybindings.js +299 -0
  191. package/dist/core/keybindings.js.map +1 -0
  192. package/dist/core/lsp/abort.d.ts +3 -0
  193. package/dist/core/lsp/abort.d.ts.map +1 -0
  194. package/dist/core/lsp/abort.js +28 -0
  195. package/dist/core/lsp/abort.js.map +1 -0
  196. package/dist/core/lsp/client.d.ts +108 -0
  197. package/dist/core/lsp/client.d.ts.map +1 -0
  198. package/dist/core/lsp/client.js +586 -0
  199. package/dist/core/lsp/client.js.map +1 -0
  200. package/dist/core/lsp/config-loader.d.ts +44 -0
  201. package/dist/core/lsp/config-loader.d.ts.map +1 -0
  202. package/dist/core/lsp/config-loader.js +223 -0
  203. package/dist/core/lsp/config-loader.js.map +1 -0
  204. package/dist/core/lsp/config.d.ts +134 -0
  205. package/dist/core/lsp/config.d.ts.map +1 -0
  206. package/dist/core/lsp/config.js +682 -0
  207. package/dist/core/lsp/config.js.map +1 -0
  208. package/dist/core/lsp/diagnostics.d.ts +18 -0
  209. package/dist/core/lsp/diagnostics.d.ts.map +1 -0
  210. package/dist/core/lsp/diagnostics.js +311 -0
  211. package/dist/core/lsp/diagnostics.js.map +1 -0
  212. package/dist/core/lsp/file-sync.d.ts +58 -0
  213. package/dist/core/lsp/file-sync.d.ts.map +1 -0
  214. package/dist/core/lsp/file-sync.js +432 -0
  215. package/dist/core/lsp/file-sync.js.map +1 -0
  216. package/dist/core/lsp/integration.d.ts +62 -0
  217. package/dist/core/lsp/integration.d.ts.map +1 -0
  218. package/dist/core/lsp/integration.js +145 -0
  219. package/dist/core/lsp/integration.js.map +1 -0
  220. package/dist/core/lsp/language-map.d.ts +54 -0
  221. package/dist/core/lsp/language-map.d.ts.map +1 -0
  222. package/dist/core/lsp/language-map.js +300 -0
  223. package/dist/core/lsp/language-map.js.map +1 -0
  224. package/dist/core/lsp/manager.d.ts +120 -0
  225. package/dist/core/lsp/manager.d.ts.map +1 -0
  226. package/dist/core/lsp/manager.js +636 -0
  227. package/dist/core/lsp/manager.js.map +1 -0
  228. package/dist/core/lsp/navigation.d.ts +32 -0
  229. package/dist/core/lsp/navigation.d.ts.map +1 -0
  230. package/dist/core/lsp/navigation.js +327 -0
  231. package/dist/core/lsp/navigation.js.map +1 -0
  232. package/dist/core/lsp/portable-path.d.ts +18 -0
  233. package/dist/core/lsp/portable-path.d.ts.map +1 -0
  234. package/dist/core/lsp/portable-path.js +83 -0
  235. package/dist/core/lsp/portable-path.js.map +1 -0
  236. package/dist/core/lsp/refactor.d.ts +32 -0
  237. package/dist/core/lsp/refactor.d.ts.map +1 -0
  238. package/dist/core/lsp/refactor.js +519 -0
  239. package/dist/core/lsp/refactor.js.map +1 -0
  240. package/dist/core/lsp/transport.d.ts +39 -0
  241. package/dist/core/lsp/transport.d.ts.map +1 -0
  242. package/dist/core/lsp/transport.js +261 -0
  243. package/dist/core/lsp/transport.js.map +1 -0
  244. package/dist/core/messages.d.ts +34 -0
  245. package/dist/core/messages.d.ts.map +1 -0
  246. package/dist/core/messages.js +140 -0
  247. package/dist/core/messages.js.map +1 -0
  248. package/dist/core/model-registry.d.ts +148 -0
  249. package/dist/core/model-registry.d.ts.map +1 -0
  250. package/dist/core/model-registry.js +812 -0
  251. package/dist/core/model-registry.js.map +1 -0
  252. package/dist/core/model-resolver.d.ts +115 -0
  253. package/dist/core/model-resolver.d.ts.map +1 -0
  254. package/dist/core/model-resolver.js +498 -0
  255. package/dist/core/model-resolver.js.map +1 -0
  256. package/dist/core/output-guard.d.ts +7 -0
  257. package/dist/core/output-guard.d.ts.map +1 -0
  258. package/dist/core/output-guard.js +89 -0
  259. package/dist/core/output-guard.js.map +1 -0
  260. package/dist/core/package-manager.d.ts +209 -0
  261. package/dist/core/package-manager.d.ts.map +1 -0
  262. package/dist/core/package-manager.js +2341 -0
  263. package/dist/core/package-manager.js.map +1 -0
  264. package/dist/core/prompt-templates.d.ts +57 -0
  265. package/dist/core/prompt-templates.d.ts.map +1 -0
  266. package/dist/core/prompt-templates.js +353 -0
  267. package/dist/core/prompt-templates.js.map +1 -0
  268. package/dist/core/provider-display-names.d.ts +2 -0
  269. package/dist/core/provider-display-names.d.ts.map +1 -0
  270. package/dist/core/provider-display-names.js +33 -0
  271. package/dist/core/provider-display-names.js.map +1 -0
  272. package/dist/core/remote-workspace-protocol/contract.d.ts +465 -0
  273. package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -0
  274. package/dist/core/remote-workspace-protocol/contract.js +825 -0
  275. package/dist/core/remote-workspace-protocol/contract.js.map +1 -0
  276. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts +16 -0
  277. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts.map +1 -0
  278. package/dist/core/remote-workspace-protocol/guest-shared-client.js +54 -0
  279. package/dist/core/remote-workspace-protocol/guest-shared-client.js.map +1 -0
  280. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts +23 -0
  281. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts.map +1 -0
  282. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js +112 -0
  283. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js.map +1 -0
  284. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts +30 -0
  285. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts.map +1 -0
  286. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js +243 -0
  287. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js.map +1 -0
  288. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts +3 -0
  289. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts.map +1 -0
  290. package/dist/core/remote-workspace-protocol/lima-owner-directory.js +31 -0
  291. package/dist/core/remote-workspace-protocol/lima-owner-directory.js.map +1 -0
  292. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts +9 -0
  293. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts.map +1 -0
  294. package/dist/core/remote-workspace-protocol/lima-owner-lock.js +89 -0
  295. package/dist/core/remote-workspace-protocol/lima-owner-lock.js.map +1 -0
  296. package/dist/core/remote-workspace-protocol/session.d.ts +249 -0
  297. package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -0
  298. package/dist/core/remote-workspace-protocol/session.js +1842 -0
  299. package/dist/core/remote-workspace-protocol/session.js.map +1 -0
  300. package/dist/core/remote-workspace-protocol/shared-transport.d.ts +71 -0
  301. package/dist/core/remote-workspace-protocol/shared-transport.d.ts.map +1 -0
  302. package/dist/core/remote-workspace-protocol/shared-transport.js +68 -0
  303. package/dist/core/remote-workspace-protocol/shared-transport.js.map +1 -0
  304. package/dist/core/resolve-config-value.d.ts +32 -0
  305. package/dist/core/resolve-config-value.d.ts.map +1 -0
  306. package/dist/core/resolve-config-value.js +257 -0
  307. package/dist/core/resolve-config-value.js.map +1 -0
  308. package/dist/core/resource-loader.d.ts +200 -0
  309. package/dist/core/resource-loader.d.ts.map +1 -0
  310. package/dist/core/resource-loader.js +1209 -0
  311. package/dist/core/resource-loader.js.map +1 -0
  312. package/dist/core/rules.d.ts +40 -0
  313. package/dist/core/rules.d.ts.map +1 -0
  314. package/dist/core/rules.js +57 -0
  315. package/dist/core/rules.js.map +1 -0
  316. package/dist/core/sandbox/command.d.ts +25 -0
  317. package/dist/core/sandbox/command.d.ts.map +1 -0
  318. package/dist/core/sandbox/command.js +102 -0
  319. package/dist/core/sandbox/command.js.map +1 -0
  320. package/dist/core/sandbox/config.d.ts +91 -0
  321. package/dist/core/sandbox/config.d.ts.map +1 -0
  322. package/dist/core/sandbox/config.js +88 -0
  323. package/dist/core/sandbox/config.js.map +1 -0
  324. package/dist/core/sandbox/lima-guest-binary.d.ts +11 -0
  325. package/dist/core/sandbox/lima-guest-binary.d.ts.map +1 -0
  326. package/dist/core/sandbox/lima-guest-binary.js +140 -0
  327. package/dist/core/sandbox/lima-guest-binary.js.map +1 -0
  328. package/dist/core/sandbox/lima.d.ts +57 -0
  329. package/dist/core/sandbox/lima.d.ts.map +1 -0
  330. package/dist/core/sandbox/lima.js +716 -0
  331. package/dist/core/sandbox/lima.js.map +1 -0
  332. package/dist/core/sandbox/shared-lima-roots.d.ts +11 -0
  333. package/dist/core/sandbox/shared-lima-roots.d.ts.map +1 -0
  334. package/dist/core/sandbox/shared-lima-roots.js +25 -0
  335. package/dist/core/sandbox/shared-lima-roots.js.map +1 -0
  336. package/dist/core/sandbox/update-shared-guest-binary.d.ts +8 -0
  337. package/dist/core/sandbox/update-shared-guest-binary.d.ts.map +1 -0
  338. package/dist/core/sandbox/update-shared-guest-binary.js +100 -0
  339. package/dist/core/sandbox/update-shared-guest-binary.js.map +1 -0
  340. package/dist/core/session/constants.d.ts +2 -0
  341. package/dist/core/session/constants.d.ts.map +1 -0
  342. package/dist/core/session/constants.js +2 -0
  343. package/dist/core/session/constants.js.map +1 -0
  344. package/dist/core/session/context-metadata.d.ts +5 -0
  345. package/dist/core/session/context-metadata.d.ts.map +1 -0
  346. package/dist/core/session/context-metadata.js +55 -0
  347. package/dist/core/session/context-metadata.js.map +1 -0
  348. package/dist/core/session/context.d.ts +14 -0
  349. package/dist/core/session/context.d.ts.map +1 -0
  350. package/dist/core/session/context.js +117 -0
  351. package/dist/core/session/context.js.map +1 -0
  352. package/dist/core/session/ids.d.ts +9 -0
  353. package/dist/core/session/ids.d.ts.map +1 -0
  354. package/dist/core/session/ids.js +21 -0
  355. package/dist/core/session/ids.js.map +1 -0
  356. package/dist/core/session/in-memory-session-manager.d.ts +17 -0
  357. package/dist/core/session/in-memory-session-manager.d.ts.map +1 -0
  358. package/dist/core/session/in-memory-session-manager.js +40 -0
  359. package/dist/core/session/in-memory-session-manager.js.map +1 -0
  360. package/dist/core/session/in-memory-session.d.ts +7 -0
  361. package/dist/core/session/in-memory-session.d.ts.map +1 -0
  362. package/dist/core/session/in-memory-session.js +11 -0
  363. package/dist/core/session/in-memory-session.js.map +1 -0
  364. package/dist/core/session/jsonl-errors.d.ts +36 -0
  365. package/dist/core/session/jsonl-errors.d.ts.map +1 -0
  366. package/dist/core/session/jsonl-errors.js +49 -0
  367. package/dist/core/session/jsonl-errors.js.map +1 -0
  368. package/dist/core/session/jsonl-helpers.d.ts +20 -0
  369. package/dist/core/session/jsonl-helpers.d.ts.map +1 -0
  370. package/dist/core/session/jsonl-helpers.js +21 -0
  371. package/dist/core/session/jsonl-helpers.js.map +1 -0
  372. package/dist/core/session/local-session-manager.d.ts +30 -0
  373. package/dist/core/session/local-session-manager.d.ts.map +1 -0
  374. package/dist/core/session/local-session-manager.js +205 -0
  375. package/dist/core/session/local-session-manager.js.map +1 -0
  376. package/dist/core/session/local-session.d.ts +9 -0
  377. package/dist/core/session/local-session.d.ts.map +1 -0
  378. package/dist/core/session/local-session.js +15 -0
  379. package/dist/core/session/local-session.js.map +1 -0
  380. package/dist/core/session/migrations.d.ts +11 -0
  381. package/dist/core/session/migrations.d.ts.map +1 -0
  382. package/dist/core/session/migrations.js +78 -0
  383. package/dist/core/session/migrations.js.map +1 -0
  384. package/dist/core/session/remote-session-client.d.ts +83 -0
  385. package/dist/core/session/remote-session-client.d.ts.map +1 -0
  386. package/dist/core/session/remote-session-client.js +224 -0
  387. package/dist/core/session/remote-session-client.js.map +1 -0
  388. package/dist/core/session/remote-session-manager.d.ts +32 -0
  389. package/dist/core/session/remote-session-manager.d.ts.map +1 -0
  390. package/dist/core/session/remote-session-manager.js +124 -0
  391. package/dist/core/session/remote-session-manager.js.map +1 -0
  392. package/dist/core/session/remote-session.d.ts +20 -0
  393. package/dist/core/session/remote-session.d.ts.map +1 -0
  394. package/dist/core/session/remote-session.js +33 -0
  395. package/dist/core/session/remote-session.js.map +1 -0
  396. package/dist/core/session/session-manager.d.ts +18 -0
  397. package/dist/core/session/session-manager.d.ts.map +1 -0
  398. package/dist/core/session/session-manager.js +2 -0
  399. package/dist/core/session/session-manager.js.map +1 -0
  400. package/dist/core/session/session.d.ts +140 -0
  401. package/dist/core/session/session.d.ts.map +1 -0
  402. package/dist/core/session/session.js +461 -0
  403. package/dist/core/session/session.js.map +1 -0
  404. package/dist/core/session/stores/in-memory-session-store.d.ts +39 -0
  405. package/dist/core/session/stores/in-memory-session-store.d.ts.map +1 -0
  406. package/dist/core/session/stores/in-memory-session-store.js +168 -0
  407. package/dist/core/session/stores/in-memory-session-store.js.map +1 -0
  408. package/dist/core/session/stores/jsonl-session-store.d.ts +97 -0
  409. package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -0
  410. package/dist/core/session/stores/jsonl-session-store.js +1140 -0
  411. package/dist/core/session/stores/jsonl-session-store.js.map +1 -0
  412. package/dist/core/session/stores/remote-session-store.d.ts +44 -0
  413. package/dist/core/session/stores/remote-session-store.d.ts.map +1 -0
  414. package/dist/core/session/stores/remote-session-store.js +159 -0
  415. package/dist/core/session/stores/remote-session-store.js.map +1 -0
  416. package/dist/core/session/stores/session-store.d.ts +42 -0
  417. package/dist/core/session/stores/session-store.d.ts.map +1 -0
  418. package/dist/core/session/stores/session-store.js +2 -0
  419. package/dist/core/session/stores/session-store.js.map +1 -0
  420. package/dist/core/session/types.d.ts +141 -0
  421. package/dist/core/session/types.d.ts.map +1 -0
  422. package/dist/core/session/types.js +2 -0
  423. package/dist/core/session/types.js.map +1 -0
  424. package/dist/core/session/usage-ledger.d.ts +18 -0
  425. package/dist/core/session/usage-ledger.d.ts.map +1 -0
  426. package/dist/core/session/usage-ledger.js +68 -0
  427. package/dist/core/session/usage-ledger.js.map +1 -0
  428. package/dist/core/session-cwd.d.ts +19 -0
  429. package/dist/core/session-cwd.d.ts.map +1 -0
  430. package/dist/core/session-cwd.js +38 -0
  431. package/dist/core/session-cwd.js.map +1 -0
  432. package/dist/core/settings-manager.d.ts +314 -0
  433. package/dist/core/settings-manager.d.ts.map +1 -0
  434. package/dist/core/settings-manager.js +991 -0
  435. package/dist/core/settings-manager.js.map +1 -0
  436. package/dist/core/skills.d.ts +40 -0
  437. package/dist/core/skills.d.ts.map +1 -0
  438. package/dist/core/skills.js +57 -0
  439. package/dist/core/skills.js.map +1 -0
  440. package/dist/core/slash-commands.d.ts +15 -0
  441. package/dist/core/slash-commands.d.ts.map +1 -0
  442. package/dist/core/slash-commands.js +36 -0
  443. package/dist/core/slash-commands.js.map +1 -0
  444. package/dist/core/source-info.d.ts +26 -0
  445. package/dist/core/source-info.d.ts.map +1 -0
  446. package/dist/core/source-info.js +27 -0
  447. package/dist/core/source-info.js.map +1 -0
  448. package/dist/core/system-prompt.d.ts +32 -0
  449. package/dist/core/system-prompt.d.ts.map +1 -0
  450. package/dist/core/system-prompt.js +131 -0
  451. package/dist/core/system-prompt.js.map +1 -0
  452. package/dist/core/telemetry.d.ts +3 -0
  453. package/dist/core/telemetry.d.ts.map +1 -0
  454. package/dist/core/telemetry.js +9 -0
  455. package/dist/core/telemetry.js.map +1 -0
  456. package/dist/core/timings.d.ts +10 -0
  457. package/dist/core/timings.d.ts.map +1 -0
  458. package/dist/core/timings.js +41 -0
  459. package/dist/core/timings.js.map +1 -0
  460. package/dist/core/tools/bash.d.ts +51 -0
  461. package/dist/core/tools/bash.d.ts.map +1 -0
  462. package/dist/core/tools/bash.js +321 -0
  463. package/dist/core/tools/bash.js.map +1 -0
  464. package/dist/core/tools/compress-context.d.ts +27 -0
  465. package/dist/core/tools/compress-context.d.ts.map +1 -0
  466. package/dist/core/tools/compress-context.js +142 -0
  467. package/dist/core/tools/compress-context.js.map +1 -0
  468. package/dist/core/tools/edit-diff.d.ts +82 -0
  469. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  470. package/dist/core/tools/edit-diff.js +327 -0
  471. package/dist/core/tools/edit-diff.js.map +1 -0
  472. package/dist/core/tools/edit.d.ts +50 -0
  473. package/dist/core/tools/edit.d.ts.map +1 -0
  474. package/dist/core/tools/edit.js +324 -0
  475. package/dist/core/tools/edit.js.map +1 -0
  476. package/dist/core/tools/file-mutation-queue.d.ts +8 -0
  477. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -0
  478. package/dist/core/tools/file-mutation-queue.js +69 -0
  479. package/dist/core/tools/file-mutation-queue.js.map +1 -0
  480. package/dist/core/tools/find.d.ts +22 -0
  481. package/dist/core/tools/find.d.ts.map +1 -0
  482. package/dist/core/tools/find.js +268 -0
  483. package/dist/core/tools/find.js.map +1 -0
  484. package/dist/core/tools/grep.d.ts +27 -0
  485. package/dist/core/tools/grep.d.ts.map +1 -0
  486. package/dist/core/tools/grep.js +332 -0
  487. package/dist/core/tools/grep.js.map +1 -0
  488. package/dist/core/tools/hash-store.d.ts +12 -0
  489. package/dist/core/tools/hash-store.d.ts.map +1 -0
  490. package/dist/core/tools/hash-store.js +48 -0
  491. package/dist/core/tools/hash-store.js.map +1 -0
  492. package/dist/core/tools/hashline/apply.d.ts +40 -0
  493. package/dist/core/tools/hashline/apply.d.ts.map +1 -0
  494. package/dist/core/tools/hashline/apply.js +261 -0
  495. package/dist/core/tools/hashline/apply.js.map +1 -0
  496. package/dist/core/tools/hashline/hash.d.ts +56 -0
  497. package/dist/core/tools/hashline/hash.d.ts.map +1 -0
  498. package/dist/core/tools/hashline/hash.js +196 -0
  499. package/dist/core/tools/hashline/hash.js.map +1 -0
  500. package/dist/core/tools/hashline/parse.d.ts +8 -0
  501. package/dist/core/tools/hashline/parse.d.ts.map +1 -0
  502. package/dist/core/tools/hashline/parse.js +41 -0
  503. package/dist/core/tools/hashline/parse.js.map +1 -0
  504. package/dist/core/tools/hashline/resolve.d.ts +51 -0
  505. package/dist/core/tools/hashline/resolve.d.ts.map +1 -0
  506. package/dist/core/tools/hashline/resolve.js +187 -0
  507. package/dist/core/tools/hashline/resolve.js.map +1 -0
  508. package/dist/core/tools/hashline-utils.d.ts +6 -0
  509. package/dist/core/tools/hashline-utils.d.ts.map +1 -0
  510. package/dist/core/tools/hashline-utils.js +23 -0
  511. package/dist/core/tools/hashline-utils.js.map +1 -0
  512. package/dist/core/tools/index.d.ts +36 -0
  513. package/dist/core/tools/index.d.ts.map +1 -0
  514. package/dist/core/tools/index.js +141 -0
  515. package/dist/core/tools/index.js.map +1 -0
  516. package/dist/core/tools/ls.d.ts +21 -0
  517. package/dist/core/tools/ls.d.ts.map +1 -0
  518. package/dist/core/tools/ls.js +156 -0
  519. package/dist/core/tools/ls.js.map +1 -0
  520. package/dist/core/tools/operations.d.ts +212 -0
  521. package/dist/core/tools/operations.d.ts.map +1 -0
  522. package/dist/core/tools/operations.js +793 -0
  523. package/dist/core/tools/operations.js.map +1 -0
  524. package/dist/core/tools/output-accumulator.d.ts +54 -0
  525. package/dist/core/tools/output-accumulator.d.ts.map +1 -0
  526. package/dist/core/tools/output-accumulator.js +184 -0
  527. package/dist/core/tools/output-accumulator.js.map +1 -0
  528. package/dist/core/tools/path-utils.d.ts +9 -0
  529. package/dist/core/tools/path-utils.d.ts.map +1 -0
  530. package/dist/core/tools/path-utils.js +99 -0
  531. package/dist/core/tools/path-utils.js.map +1 -0
  532. package/dist/core/tools/read.d.ts +32 -0
  533. package/dist/core/tools/read.d.ts.map +1 -0
  534. package/dist/core/tools/read.js +318 -0
  535. package/dist/core/tools/read.js.map +1 -0
  536. package/dist/core/tools/render-utils.d.ts +33 -0
  537. package/dist/core/tools/render-utils.d.ts.map +1 -0
  538. package/dist/core/tools/render-utils.js +61 -0
  539. package/dist/core/tools/render-utils.js.map +1 -0
  540. package/dist/core/tools/replace-diff.d.ts +16 -0
  541. package/dist/core/tools/replace-diff.d.ts.map +1 -0
  542. package/dist/core/tools/replace-diff.js +117 -0
  543. package/dist/core/tools/replace-diff.js.map +1 -0
  544. package/dist/core/tools/replace-normalize.d.ts +2 -0
  545. package/dist/core/tools/replace-normalize.d.ts.map +1 -0
  546. package/dist/core/tools/replace-normalize.js +73 -0
  547. package/dist/core/tools/replace-normalize.js.map +1 -0
  548. package/dist/core/tools/replace-render.d.ts +51 -0
  549. package/dist/core/tools/replace-render.d.ts.map +1 -0
  550. package/dist/core/tools/replace-render.js +162 -0
  551. package/dist/core/tools/replace-render.js.map +1 -0
  552. package/dist/core/tools/runtime.d.ts +2 -0
  553. package/dist/core/tools/runtime.d.ts.map +1 -0
  554. package/dist/core/tools/runtime.js +6 -0
  555. package/dist/core/tools/runtime.js.map +1 -0
  556. package/dist/core/tools/session-history.d.ts +55 -0
  557. package/dist/core/tools/session-history.d.ts.map +1 -0
  558. package/dist/core/tools/session-history.js +649 -0
  559. package/dist/core/tools/session-history.js.map +1 -0
  560. package/dist/core/tools/subagent-agents.d.ts +29 -0
  561. package/dist/core/tools/subagent-agents.d.ts.map +1 -0
  562. package/dist/core/tools/subagent-agents.js +223 -0
  563. package/dist/core/tools/subagent-agents.js.map +1 -0
  564. package/dist/core/tools/subagent.d.ts +185 -0
  565. package/dist/core/tools/subagent.d.ts.map +1 -0
  566. package/dist/core/tools/subagent.js +1309 -0
  567. package/dist/core/tools/subagent.js.map +1 -0
  568. package/dist/core/tools/tool-definition-wrapper.d.ts +14 -0
  569. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -0
  570. package/dist/core/tools/tool-definition-wrapper.js +34 -0
  571. package/dist/core/tools/tool-definition-wrapper.js.map +1 -0
  572. package/dist/core/tools/truncate.d.ts +39 -0
  573. package/dist/core/tools/truncate.d.ts.map +1 -0
  574. package/dist/core/tools/truncate.js +215 -0
  575. package/dist/core/tools/truncate.js.map +1 -0
  576. package/dist/core/tools/websearch.d.ts +33 -0
  577. package/dist/core/tools/websearch.d.ts.map +1 -0
  578. package/dist/core/tools/websearch.js +341 -0
  579. package/dist/core/tools/websearch.js.map +1 -0
  580. package/dist/core/tools/workspace-tool-host.d.ts +102 -0
  581. package/dist/core/tools/workspace-tool-host.d.ts.map +1 -0
  582. package/dist/core/tools/workspace-tool-host.js +348 -0
  583. package/dist/core/tools/workspace-tool-host.js.map +1 -0
  584. package/dist/core/tools/write.d.ts +16 -0
  585. package/dist/core/tools/write.d.ts.map +1 -0
  586. package/dist/core/tools/write.js +204 -0
  587. package/dist/core/tools/write.js.map +1 -0
  588. package/dist/core/workspace-identity.d.ts +7 -0
  589. package/dist/core/workspace-identity.d.ts.map +1 -0
  590. package/dist/core/workspace-identity.js +2 -0
  591. package/dist/core/workspace-identity.js.map +1 -0
  592. package/dist/daemon/activity-budget.d.ts +10 -0
  593. package/dist/daemon/activity-budget.d.ts.map +1 -0
  594. package/dist/daemon/activity-budget.js +34 -0
  595. package/dist/daemon/activity-budget.js.map +1 -0
  596. package/dist/daemon/command.d.ts +6 -0
  597. package/dist/daemon/command.d.ts.map +1 -0
  598. package/dist/daemon/command.js +58 -0
  599. package/dist/daemon/command.js.map +1 -0
  600. package/dist/daemon/config.d.ts +45 -0
  601. package/dist/daemon/config.d.ts.map +1 -0
  602. package/dist/daemon/config.js +319 -0
  603. package/dist/daemon/config.js.map +1 -0
  604. package/dist/daemon/help.d.ts +2 -0
  605. package/dist/daemon/help.d.ts.map +1 -0
  606. package/dist/daemon/help.js +42 -0
  607. package/dist/daemon/help.js.map +1 -0
  608. package/dist/daemon/lsp-config.d.ts +4 -0
  609. package/dist/daemon/lsp-config.d.ts.map +1 -0
  610. package/dist/daemon/lsp-config.js +155 -0
  611. package/dist/daemon/lsp-config.js.map +1 -0
  612. package/dist/daemon/outbound-budget.d.ts +10 -0
  613. package/dist/daemon/outbound-budget.d.ts.map +1 -0
  614. package/dist/daemon/outbound-budget.js +30 -0
  615. package/dist/daemon/outbound-budget.js.map +1 -0
  616. package/dist/daemon/security.d.ts +19 -0
  617. package/dist/daemon/security.d.ts.map +1 -0
  618. package/dist/daemon/security.js +177 -0
  619. package/dist/daemon/security.js.map +1 -0
  620. package/dist/daemon/server.d.ts +20 -0
  621. package/dist/daemon/server.d.ts.map +1 -0
  622. package/dist/daemon/server.js +480 -0
  623. package/dist/daemon/server.js.map +1 -0
  624. package/dist/daemon/shared-connection.d.ts +33 -0
  625. package/dist/daemon/shared-connection.d.ts.map +1 -0
  626. package/dist/daemon/shared-connection.js +271 -0
  627. package/dist/daemon/shared-connection.js.map +1 -0
  628. package/dist/daemon/shared-revision.d.ts +5 -0
  629. package/dist/daemon/shared-revision.d.ts.map +1 -0
  630. package/dist/daemon/shared-revision.js +61 -0
  631. package/dist/daemon/shared-revision.js.map +1 -0
  632. package/dist/daemon/shared-roots.d.ts +9 -0
  633. package/dist/daemon/shared-roots.d.ts.map +1 -0
  634. package/dist/daemon/shared-roots.js +33 -0
  635. package/dist/daemon/shared-roots.js.map +1 -0
  636. package/dist/daemon/workspace-runtime.d.ts +46 -0
  637. package/dist/daemon/workspace-runtime.d.ts.map +1 -0
  638. package/dist/daemon/workspace-runtime.js +705 -0
  639. package/dist/daemon/workspace-runtime.js.map +1 -0
  640. package/dist/index.d.ts +109 -0
  641. package/dist/index.d.ts.map +1 -0
  642. package/dist/index.js +107 -0
  643. package/dist/index.js.map +1 -0
  644. package/dist/main.d.ts +39 -0
  645. package/dist/main.d.ts.map +1 -0
  646. package/dist/main.js +765 -0
  647. package/dist/main.js.map +1 -0
  648. package/dist/migrations.d.ts +35 -0
  649. package/dist/migrations.d.ts.map +1 -0
  650. package/dist/migrations.js +412 -0
  651. package/dist/migrations.js.map +1 -0
  652. package/dist/modes/interactive/components/assistant-message.d.ts +30 -0
  653. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  654. package/dist/modes/interactive/components/assistant-message.js +159 -0
  655. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  656. package/dist/modes/interactive/components/bash-execution.d.ts +36 -0
  657. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  658. package/dist/modes/interactive/components/bash-execution.js +173 -0
  659. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  660. package/dist/modes/interactive/components/bordered-loader.d.ts +18 -0
  661. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  662. package/dist/modes/interactive/components/bordered-loader.js +54 -0
  663. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  664. package/dist/modes/interactive/components/branch-summary-message.d.ts +17 -0
  665. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  666. package/dist/modes/interactive/components/branch-summary-message.js +45 -0
  667. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  668. package/dist/modes/interactive/components/compaction-summary-message.d.ts +17 -0
  669. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  670. package/dist/modes/interactive/components/compaction-summary-message.js +46 -0
  671. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  672. package/dist/modes/interactive/components/config-selector.d.ts +74 -0
  673. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  674. package/dist/modes/interactive/components/config-selector.js +514 -0
  675. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  676. package/dist/modes/interactive/components/countdown-timer.d.ts +14 -0
  677. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  678. package/dist/modes/interactive/components/countdown-timer.js +33 -0
  679. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  680. package/dist/modes/interactive/components/custom-editor.d.ts +25 -0
  681. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  682. package/dist/modes/interactive/components/custom-editor.js +85 -0
  683. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  684. package/dist/modes/interactive/components/custom-message.d.ts +20 -0
  685. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  686. package/dist/modes/interactive/components/custom-message.js +81 -0
  687. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  688. package/dist/modes/interactive/components/diff.d.ts +12 -0
  689. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  690. package/dist/modes/interactive/components/diff.js +118 -0
  691. package/dist/modes/interactive/components/diff.js.map +1 -0
  692. package/dist/modes/interactive/components/dynamic-border.d.ts +15 -0
  693. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  694. package/dist/modes/interactive/components/dynamic-border.js +21 -0
  695. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  696. package/dist/modes/interactive/components/extension-editor.d.ts +22 -0
  697. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  698. package/dist/modes/interactive/components/extension-editor.js +128 -0
  699. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  700. package/dist/modes/interactive/components/extension-input.d.ts +23 -0
  701. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  702. package/dist/modes/interactive/components/extension-input.js +61 -0
  703. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  704. package/dist/modes/interactive/components/extension-selector.d.ts +26 -0
  705. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  706. package/dist/modes/interactive/components/extension-selector.js +83 -0
  707. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  708. package/dist/modes/interactive/components/footer.d.ts +36 -0
  709. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  710. package/dist/modes/interactive/components/footer.js +227 -0
  711. package/dist/modes/interactive/components/footer.js.map +1 -0
  712. package/dist/modes/interactive/components/hook-execution.d.ts +19 -0
  713. package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -0
  714. package/dist/modes/interactive/components/hook-execution.js +185 -0
  715. package/dist/modes/interactive/components/hook-execution.js.map +1 -0
  716. package/dist/modes/interactive/components/keybinding-hints.d.ts +13 -0
  717. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  718. package/dist/modes/interactive/components/keybinding-hints.js +36 -0
  719. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  720. package/dist/modes/interactive/components/login-dialog.d.ts +55 -0
  721. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  722. package/dist/modes/interactive/components/login-dialog.js +176 -0
  723. package/dist/modes/interactive/components/login-dialog.js.map +1 -0
  724. package/dist/modes/interactive/components/markdown-transform.d.ts +4 -0
  725. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  726. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  727. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  728. package/dist/modes/interactive/components/mermaid.d.ts +14 -0
  729. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  730. package/dist/modes/interactive/components/mermaid.js +228 -0
  731. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  732. package/dist/modes/interactive/components/message-card.d.ts +9 -0
  733. package/dist/modes/interactive/components/message-card.d.ts.map +1 -0
  734. package/dist/modes/interactive/components/message-card.js +24 -0
  735. package/dist/modes/interactive/components/message-card.js.map +1 -0
  736. package/dist/modes/interactive/components/model-selector.d.ts +52 -0
  737. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  738. package/dist/modes/interactive/components/model-selector.js +296 -0
  739. package/dist/modes/interactive/components/model-selector.js.map +1 -0
  740. package/dist/modes/interactive/components/oauth-selector.d.ts +33 -0
  741. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  742. package/dist/modes/interactive/components/oauth-selector.js +165 -0
  743. package/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  744. package/dist/modes/interactive/components/scoped-models-selector.d.ts +50 -0
  745. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  746. package/dist/modes/interactive/components/scoped-models-selector.js +300 -0
  747. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  748. package/dist/modes/interactive/components/session-selector-search.d.ts +22 -0
  749. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  750. package/dist/modes/interactive/components/session-selector-search.js +144 -0
  751. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  752. package/dist/modes/interactive/components/session-selector.d.ts +108 -0
  753. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  754. package/dist/modes/interactive/components/session-selector.js +835 -0
  755. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  756. package/dist/modes/interactive/components/settings-selector.d.ts +81 -0
  757. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  758. package/dist/modes/interactive/components/settings-selector.js +455 -0
  759. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  760. package/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  761. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  762. package/dist/modes/interactive/components/show-images-selector.js +39 -0
  763. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  764. package/dist/modes/interactive/components/skill-invocation-message.d.ts +18 -0
  765. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  766. package/dist/modes/interactive/components/skill-invocation-message.js +48 -0
  767. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  768. package/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  769. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  770. package/dist/modes/interactive/components/theme-selector.js +50 -0
  771. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  772. package/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  773. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  774. package/dist/modes/interactive/components/thinking-selector.js +51 -0
  775. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  776. package/dist/modes/interactive/components/tool-execution.d.ts +67 -0
  777. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  778. package/dist/modes/interactive/components/tool-execution.js +312 -0
  779. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  780. package/dist/modes/interactive/components/tree-selector.d.ts +127 -0
  781. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  782. package/dist/modes/interactive/components/tree-selector.js +1098 -0
  783. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  784. package/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  785. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  786. package/dist/modes/interactive/components/user-message-selector.js +114 -0
  787. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  788. package/dist/modes/interactive/components/user-message.d.ts +16 -0
  789. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  790. package/dist/modes/interactive/components/user-message.js +50 -0
  791. package/dist/modes/interactive/components/user-message.js.map +1 -0
  792. package/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  793. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  794. package/dist/modes/interactive/components/visual-truncate.js +33 -0
  795. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  796. package/dist/modes/interactive/interactive-mode.d.ts +554 -0
  797. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  798. package/dist/modes/interactive/interactive-mode.js +5870 -0
  799. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  800. package/dist/modes/interactive/theme/dark.json +86 -0
  801. package/dist/modes/interactive/theme/light.json +85 -0
  802. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  803. package/dist/modes/interactive/theme/theme.d.ts +109 -0
  804. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  805. package/dist/modes/interactive/theme/theme.js +1040 -0
  806. package/dist/modes/interactive/theme/theme.js.map +1 -0
  807. package/dist/modes/json-event.d.ts +28 -0
  808. package/dist/modes/json-event.d.ts.map +1 -0
  809. package/dist/modes/json-event.js +12 -0
  810. package/dist/modes/json-event.js.map +1 -0
  811. package/dist/modes/print-mode.d.ts +29 -0
  812. package/dist/modes/print-mode.d.ts.map +1 -0
  813. package/dist/modes/print-mode.js +142 -0
  814. package/dist/modes/print-mode.js.map +1 -0
  815. package/dist/modes/rpc/jsonl.d.ts +17 -0
  816. package/dist/modes/rpc/jsonl.d.ts.map +1 -0
  817. package/dist/modes/rpc/jsonl.js +49 -0
  818. package/dist/modes/rpc/jsonl.js.map +1 -0
  819. package/dist/modes/rpc/rpc-client.d.ts +321 -0
  820. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  821. package/dist/modes/rpc/rpc-client.js +755 -0
  822. package/dist/modes/rpc/rpc-client.js.map +1 -0
  823. package/dist/modes/rpc/rpc-mode.d.ts +20 -0
  824. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  825. package/dist/modes/rpc/rpc-mode.js +963 -0
  826. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  827. package/dist/modes/rpc/rpc-types.d.ts +652 -0
  828. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  829. package/dist/modes/rpc/rpc-types.js +8 -0
  830. package/dist/modes/rpc/rpc-types.js.map +1 -0
  831. package/dist/package-manager-cli.d.ts +4 -0
  832. package/dist/package-manager-cli.d.ts.map +1 -0
  833. package/dist/package-manager-cli.js +488 -0
  834. package/dist/package-manager-cli.js.map +1 -0
  835. package/dist/utils/ansi.d.ts +2 -0
  836. package/dist/utils/ansi.d.ts.map +1 -0
  837. package/dist/utils/ansi.js +25 -0
  838. package/dist/utils/ansi.js.map +1 -0
  839. package/dist/utils/changelog.d.ts +23 -0
  840. package/dist/utils/changelog.d.ts.map +1 -0
  841. package/dist/utils/changelog.js +74 -0
  842. package/dist/utils/changelog.js.map +1 -0
  843. package/dist/utils/child-process.d.ts +15 -0
  844. package/dist/utils/child-process.d.ts.map +1 -0
  845. package/dist/utils/child-process.js +88 -0
  846. package/dist/utils/child-process.js.map +1 -0
  847. package/dist/utils/clipboard-image.d.ts +13 -0
  848. package/dist/utils/clipboard-image.d.ts.map +1 -0
  849. package/dist/utils/clipboard-image.js +248 -0
  850. package/dist/utils/clipboard-image.js.map +1 -0
  851. package/dist/utils/clipboard-native.d.ts +11 -0
  852. package/dist/utils/clipboard-native.d.ts.map +1 -0
  853. package/dist/utils/clipboard-native.js +20 -0
  854. package/dist/utils/clipboard-native.js.map +1 -0
  855. package/dist/utils/clipboard.d.ts +4 -0
  856. package/dist/utils/clipboard.d.ts.map +1 -0
  857. package/dist/utils/clipboard.js +171 -0
  858. package/dist/utils/clipboard.js.map +1 -0
  859. package/dist/utils/deprecation.d.ts +4 -0
  860. package/dist/utils/deprecation.d.ts.map +1 -0
  861. package/dist/utils/deprecation.js +13 -0
  862. package/dist/utils/deprecation.js.map +1 -0
  863. package/dist/utils/directory-completions.d.ts +5 -0
  864. package/dist/utils/directory-completions.d.ts.map +1 -0
  865. package/dist/utils/directory-completions.js +64 -0
  866. package/dist/utils/directory-completions.js.map +1 -0
  867. package/dist/utils/exif-orientation.d.ts +6 -0
  868. package/dist/utils/exif-orientation.d.ts.map +1 -0
  869. package/dist/utils/exif-orientation.js +166 -0
  870. package/dist/utils/exif-orientation.js.map +1 -0
  871. package/dist/utils/frontmatter.d.ts +8 -0
  872. package/dist/utils/frontmatter.d.ts.map +1 -0
  873. package/dist/utils/frontmatter.js +26 -0
  874. package/dist/utils/frontmatter.js.map +1 -0
  875. package/dist/utils/fs-watch.d.ts +5 -0
  876. package/dist/utils/fs-watch.d.ts.map +1 -0
  877. package/dist/utils/fs-watch.js +25 -0
  878. package/dist/utils/fs-watch.js.map +1 -0
  879. package/dist/utils/git.d.ts +27 -0
  880. package/dist/utils/git.d.ts.map +1 -0
  881. package/dist/utils/git.js +237 -0
  882. package/dist/utils/git.js.map +1 -0
  883. package/dist/utils/grip-user-agent.d.ts +2 -0
  884. package/dist/utils/grip-user-agent.d.ts.map +1 -0
  885. package/dist/utils/grip-user-agent.js +5 -0
  886. package/dist/utils/grip-user-agent.js.map +1 -0
  887. package/dist/utils/html.d.ts +7 -0
  888. package/dist/utils/html.d.ts.map +1 -0
  889. package/dist/utils/html.js +40 -0
  890. package/dist/utils/html.js.map +1 -0
  891. package/dist/utils/image-convert.d.ts +12 -0
  892. package/dist/utils/image-convert.d.ts.map +1 -0
  893. package/dist/utils/image-convert.js +43 -0
  894. package/dist/utils/image-convert.js.map +1 -0
  895. package/dist/utils/image-process.d.ts +18 -0
  896. package/dist/utils/image-process.d.ts.map +1 -0
  897. package/dist/utils/image-process.js +83 -0
  898. package/dist/utils/image-process.js.map +1 -0
  899. package/dist/utils/image-resize-core.d.ts +30 -0
  900. package/dist/utils/image-resize-core.d.ts.map +1 -0
  901. package/dist/utils/image-resize-core.js +133 -0
  902. package/dist/utils/image-resize-core.js.map +1 -0
  903. package/dist/utils/image-resize-worker.d.ts +2 -0
  904. package/dist/utils/image-resize-worker.d.ts.map +1 -0
  905. package/dist/utils/image-resize-worker.js +31 -0
  906. package/dist/utils/image-resize-worker.js.map +1 -0
  907. package/dist/utils/image-resize.d.ts +19 -0
  908. package/dist/utils/image-resize.d.ts.map +1 -0
  909. package/dist/utils/image-resize.js +86 -0
  910. package/dist/utils/image-resize.js.map +1 -0
  911. package/dist/utils/json.d.ts +3 -0
  912. package/dist/utils/json.d.ts.map +1 -0
  913. package/dist/utils/json.js +7 -0
  914. package/dist/utils/json.js.map +1 -0
  915. package/dist/utils/mime.d.ts +3 -0
  916. package/dist/utils/mime.d.ts.map +1 -0
  917. package/dist/utils/mime.js +110 -0
  918. package/dist/utils/mime.js.map +1 -0
  919. package/dist/utils/open-browser.d.ts +9 -0
  920. package/dist/utils/open-browser.d.ts.map +1 -0
  921. package/dist/utils/open-browser.js +22 -0
  922. package/dist/utils/open-browser.js.map +1 -0
  923. package/dist/utils/paths.d.ts +31 -0
  924. package/dist/utils/paths.d.ts.map +1 -0
  925. package/dist/utils/paths.js +87 -0
  926. package/dist/utils/paths.js.map +1 -0
  927. package/dist/utils/photon.d.ts +22 -0
  928. package/dist/utils/photon.d.ts.map +1 -0
  929. package/dist/utils/photon.js +126 -0
  930. package/dist/utils/photon.js.map +1 -0
  931. package/dist/utils/shell.d.ts +28 -0
  932. package/dist/utils/shell.d.ts.map +1 -0
  933. package/dist/utils/shell.js +188 -0
  934. package/dist/utils/shell.js.map +1 -0
  935. package/dist/utils/sleep.d.ts +5 -0
  936. package/dist/utils/sleep.d.ts.map +1 -0
  937. package/dist/utils/sleep.js +17 -0
  938. package/dist/utils/sleep.js.map +1 -0
  939. package/dist/utils/syntax-highlight.d.ts +12 -0
  940. package/dist/utils/syntax-highlight.d.ts.map +1 -0
  941. package/dist/utils/syntax-highlight.js +125 -0
  942. package/dist/utils/syntax-highlight.js.map +1 -0
  943. package/dist/utils/tools-manager.d.ts +5 -0
  944. package/dist/utils/tools-manager.d.ts.map +1 -0
  945. package/dist/utils/tools-manager.js +329 -0
  946. package/dist/utils/tools-manager.js.map +1 -0
  947. package/dist/utils/version-check.d.ts +14 -0
  948. package/dist/utils/version-check.d.ts.map +1 -0
  949. package/dist/utils/version-check.js +91 -0
  950. package/dist/utils/version-check.js.map +1 -0
  951. package/dist/utils/windows-self-update.d.ts +3 -0
  952. package/dist/utils/windows-self-update.d.ts.map +1 -0
  953. package/dist/utils/windows-self-update.js +77 -0
  954. package/dist/utils/windows-self-update.js.map +1 -0
  955. package/docs/compaction.md +408 -0
  956. package/docs/custom-provider.md +714 -0
  957. package/docs/daemon-architecture.md +399 -0
  958. package/docs/daemon.md +112 -0
  959. package/docs/development.md +72 -0
  960. package/docs/docs.json +164 -0
  961. package/docs/extensions.md +2745 -0
  962. package/docs/hooks.md +85 -0
  963. package/docs/images/doom-extension.png +0 -0
  964. package/docs/images/exy.png +0 -0
  965. package/docs/images/interactive-mode.png +0 -0
  966. package/docs/images/tree-view.png +0 -0
  967. package/docs/index.md +77 -0
  968. package/docs/json.md +89 -0
  969. package/docs/keybindings.md +230 -0
  970. package/docs/lsp.md +499 -0
  971. package/docs/migrating-to-grip.md +18 -0
  972. package/docs/models.md +496 -0
  973. package/docs/packages.md +228 -0
  974. package/docs/prompt-templates.md +88 -0
  975. package/docs/providers.md +251 -0
  976. package/docs/quickstart.md +159 -0
  977. package/docs/rpc.md +1492 -0
  978. package/docs/rules.md +117 -0
  979. package/docs/sandbox.md +104 -0
  980. package/docs/sdk.md +360 -0
  981. package/docs/session-format.md +414 -0
  982. package/docs/sessions.md +137 -0
  983. package/docs/settings.md +372 -0
  984. package/docs/shell-aliases.md +13 -0
  985. package/docs/skills.md +246 -0
  986. package/docs/terminal-setup.md +112 -0
  987. package/docs/termux.md +112 -0
  988. package/docs/themes.md +295 -0
  989. package/docs/tmux.md +61 -0
  990. package/docs/tui.md +918 -0
  991. package/docs/usage.md +304 -0
  992. package/docs/windows.md +17 -0
  993. package/examples/README.md +29 -0
  994. package/examples/daemon-docker/Dockerfile +43 -0
  995. package/examples/daemon-docker/README.md +45 -0
  996. package/examples/extensions/README.md +208 -0
  997. package/examples/extensions/auto-commit-on-exit.ts +46 -0
  998. package/examples/extensions/bash-spawn-hook.ts +30 -0
  999. package/examples/extensions/bookmark.ts +50 -0
  1000. package/examples/extensions/border-status-editor.ts +145 -0
  1001. package/examples/extensions/built-in-tool-renderer.ts +259 -0
  1002. package/examples/extensions/claude-rules.ts +86 -0
  1003. package/examples/extensions/commands.ts +82 -0
  1004. package/examples/extensions/confirm-destructive.ts +59 -0
  1005. package/examples/extensions/custom-compaction.ts +131 -0
  1006. package/examples/extensions/custom-footer.ts +79 -0
  1007. package/examples/extensions/custom-header.ts +73 -0
  1008. package/examples/extensions/custom-provider-anthropic/index.ts +707 -0
  1009. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  1010. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  1011. package/examples/extensions/custom-provider-gitlab-duo/index.ts +402 -0
  1012. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  1013. package/examples/extensions/custom-provider-gitlab-duo/test.ts +104 -0
  1014. package/examples/extensions/dirty-repo-guard.ts +59 -0
  1015. package/examples/extensions/doom-overlay/README.md +46 -0
  1016. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  1017. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  1018. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  1019. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  1020. package/examples/extensions/doom-overlay/doom-component.ts +133 -0
  1021. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  1022. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  1023. package/examples/extensions/doom-overlay/index.ts +74 -0
  1024. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  1025. package/examples/extensions/dynamic-resources/RULES.md +8 -0
  1026. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  1027. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  1028. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  1029. package/examples/extensions/dynamic-resources/index.ts +16 -0
  1030. package/examples/extensions/dynamic-tools.ts +74 -0
  1031. package/examples/extensions/event-bus.ts +43 -0
  1032. package/examples/extensions/file-trigger.ts +41 -0
  1033. package/examples/extensions/git-checkpoint.ts +53 -0
  1034. package/examples/extensions/git-merge-and-resolve.ts +125 -0
  1035. package/examples/extensions/github-issue-autocomplete.ts +191 -0
  1036. package/examples/extensions/handoff.ts +191 -0
  1037. package/examples/extensions/hello.ts +26 -0
  1038. package/examples/extensions/hidden-thinking-label.ts +53 -0
  1039. package/examples/extensions/inline-bash.ts +104 -0
  1040. package/examples/extensions/input-transform.ts +43 -0
  1041. package/examples/extensions/interactive-shell.ts +194 -0
  1042. package/examples/extensions/mac-system-theme.ts +47 -0
  1043. package/examples/extensions/message-renderer.ts +59 -0
  1044. package/examples/extensions/minimal-mode.ts +428 -0
  1045. package/examples/extensions/modal-editor.ts +86 -0
  1046. package/examples/extensions/model-status.ts +31 -0
  1047. package/examples/extensions/notify.ts +55 -0
  1048. package/examples/extensions/overlay-qa-tests.ts +1374 -0
  1049. package/examples/extensions/overlay-test.ts +171 -0
  1050. package/examples/extensions/permission-gate.ts +34 -0
  1051. package/examples/extensions/pirate.ts +47 -0
  1052. package/examples/extensions/plan-mode/README.md +65 -0
  1053. package/examples/extensions/plan-mode/index.ts +346 -0
  1054. package/examples/extensions/plan-mode/utils.ts +172 -0
  1055. package/examples/extensions/preset.ts +426 -0
  1056. package/examples/extensions/prompt-customizer.ts +97 -0
  1057. package/examples/extensions/protected-paths.ts +29 -0
  1058. package/examples/extensions/provider-payload.ts +18 -0
  1059. package/examples/extensions/qna.ts +125 -0
  1060. package/examples/extensions/question.ts +294 -0
  1061. package/examples/extensions/questionnaire.ts +459 -0
  1062. package/examples/extensions/rainbow-editor.ts +88 -0
  1063. package/examples/extensions/reload-runtime.ts +37 -0
  1064. package/examples/extensions/rpc-demo.ts +118 -0
  1065. package/examples/extensions/sandbox/index.ts +320 -0
  1066. package/examples/extensions/sandbox/package-lock.json +92 -0
  1067. package/examples/extensions/sandbox/package.json +19 -0
  1068. package/examples/extensions/send-user-message.ts +97 -0
  1069. package/examples/extensions/session-name.ts +27 -0
  1070. package/examples/extensions/shutdown-command.ts +63 -0
  1071. package/examples/extensions/snake.ts +381 -0
  1072. package/examples/extensions/space-invaders.ts +597 -0
  1073. package/examples/extensions/status-line.ts +32 -0
  1074. package/examples/extensions/structured-output.ts +65 -0
  1075. package/examples/extensions/subagent/README.md +175 -0
  1076. package/examples/extensions/subagent/agents/planner.md +37 -0
  1077. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  1078. package/examples/extensions/subagent/agents/scout.md +50 -0
  1079. package/examples/extensions/subagent/agents/worker.md +24 -0
  1080. package/examples/extensions/subagent/agents.ts +126 -0
  1081. package/examples/extensions/subagent/index.ts +1083 -0
  1082. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  1083. package/examples/extensions/subagent/prompts/implement.md +10 -0
  1084. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  1085. package/examples/extensions/summarize.ts +186 -0
  1086. package/examples/extensions/system-prompt-header.ts +17 -0
  1087. package/examples/extensions/tic-tac-toe.ts +1091 -0
  1088. package/examples/extensions/timed-confirm.ts +70 -0
  1089. package/examples/extensions/titlebar-spinner.ts +58 -0
  1090. package/examples/extensions/todo.ts +306 -0
  1091. package/examples/extensions/tool-override.ts +144 -0
  1092. package/examples/extensions/tools.ts +141 -0
  1093. package/examples/extensions/trigger-compact.ts +50 -0
  1094. package/examples/extensions/truncated-tool.ts +200 -0
  1095. package/examples/extensions/widget-placement.ts +9 -0
  1096. package/examples/extensions/with-deps/index.ts +32 -0
  1097. package/examples/extensions/with-deps/package-lock.json +31 -0
  1098. package/examples/extensions/with-deps/package.json +22 -0
  1099. package/examples/extensions/working-indicator.ts +123 -0
  1100. package/examples/extensions/working-message-test.ts +25 -0
  1101. package/examples/remote-session-server/README.md +71 -0
  1102. package/examples/remote-session-server/server.ts +353 -0
  1103. package/examples/rpc-extension-ui.ts +642 -0
  1104. package/examples/sdk/01-minimal.ts +27 -0
  1105. package/examples/sdk/02-custom-model.ts +54 -0
  1106. package/examples/sdk/03-custom-prompt.ts +76 -0
  1107. package/examples/sdk/04-skills.ts +60 -0
  1108. package/examples/sdk/05-tools.ts +55 -0
  1109. package/examples/sdk/06-extensions.ts +94 -0
  1110. package/examples/sdk/07-context-files.ts +47 -0
  1111. package/examples/sdk/08-prompt-templates.ts +56 -0
  1112. package/examples/sdk/09-api-keys-and-oauth.ts +50 -0
  1113. package/examples/sdk/10-settings.ts +58 -0
  1114. package/examples/sdk/11-sessions.ts +54 -0
  1115. package/examples/sdk/12-full-control.ts +79 -0
  1116. package/examples/sdk/13-session-runtime.ts +49 -0
  1117. package/examples/sdk/README.md +94 -0
  1118. package/npm-shrinkwrap.json +1878 -0
  1119. package/package.json +101 -5
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Shared diff computation utilities for the edit tool.
3
+ * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).
4
+ */
5
+ import type { ToolOperations } from "./operations.ts";
6
+ import { type LineEnding, stripBOM } from "./replace-diff.ts";
7
+ export { stripBOM as stripBom };
8
+ export declare function detectLineEnding(content: string): LineEnding;
9
+ export declare function normalizeToLF(text: string): string;
10
+ export declare function restoreLineEndings(text: string, ending: LineEnding): string;
11
+ /**
12
+ * Normalize text for fuzzy matching. Applies progressive transformations:
13
+ * - Strip trailing whitespace from each line
14
+ * - Normalize smart quotes to ASCII equivalents
15
+ * - Normalize Unicode dashes/hyphens to ASCII hyphen
16
+ * - Normalize special Unicode spaces to regular space
17
+ */
18
+ export declare function normalizeForFuzzyMatch(text: string): string;
19
+ export interface FuzzyMatchResult {
20
+ /** Whether a match was found */
21
+ found: boolean;
22
+ /** The index where the match starts (in the content that should be used for replacement) */
23
+ index: number;
24
+ /** Length of the matched text */
25
+ matchLength: number;
26
+ /** Whether fuzzy matching was used (false = exact match) */
27
+ usedFuzzyMatch: boolean;
28
+ /**
29
+ * The content to use for replacement operations.
30
+ * When exact match: original content. When fuzzy match: normalized content.
31
+ */
32
+ contentForReplacement: string;
33
+ }
34
+ export interface Edit {
35
+ oldText: string;
36
+ newText: string;
37
+ }
38
+ export interface AppliedEditsResult {
39
+ baseContent: string;
40
+ newContent: string;
41
+ }
42
+ /**
43
+ * Find oldText in content, trying exact match first, then fuzzy match.
44
+ * When fuzzy matching is used, the returned contentForReplacement is the
45
+ * fuzzy-normalized version of the content (trailing whitespace stripped,
46
+ * Unicode quotes/dashes normalized to ASCII).
47
+ */
48
+ export declare function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult;
49
+ /**
50
+ * Apply one or more exact-text replacements to LF-normalized content.
51
+ *
52
+ * All edits are matched against the same original content. Replacements are
53
+ * then applied in reverse order so offsets remain stable. If any edit needs
54
+ * fuzzy matching, the operation runs in fuzzy-normalized content space to
55
+ * preserve current single-edit behavior.
56
+ */
57
+ export declare function applyEditsToNormalizedContent(normalizedContent: string, edits: Edit[], path: string): AppliedEditsResult;
58
+ /** Generate a standard unified patch. */
59
+ export declare function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines?: number): string;
60
+ /**
61
+ * Generate a display-oriented diff string with line numbers and context.
62
+ * Returns both the diff string and the first changed line number (in the new file).
63
+ */
64
+ export declare function generateDiffString(oldContent: string, newContent: string, contextLines?: number): EditDiffResult;
65
+ export interface EditDiffResult {
66
+ diff: string;
67
+ firstChangedLine: number | undefined;
68
+ }
69
+ export interface EditDiffError {
70
+ error: string;
71
+ }
72
+ /**
73
+ * Compute the diff for one or more edit operations without applying them.
74
+ * Used for preview rendering in the TUI before the tool executes.
75
+ */
76
+ export declare function computeEditsDiff(path: string, edits: Edit[], operations: ToolOperations): Promise<EditDiffResult | EditDiffError>;
77
+ /**
78
+ * Compute the diff for a single edit operation without applying it.
79
+ * Kept as a convenience wrapper for single-edit callers.
80
+ */
81
+ export declare function computeEditDiff(path: string, oldText: string, newText: string, operations: ToolOperations): Promise<EditDiffResult | EditDiffError>;
82
+ //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,EACzB,KAAK,EAAE,IAAI,EAAE,EACb,IAAI,EAAE,MAAM,GACV,kBAAkB,CA+DpB;AAED,yCAAyC;AACzC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,SAAI,GAAG,MAAM,CAKnH;AA8FD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,SAAI,GAAG,cAAc,CAgC3G;AAGD,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,IAAI,EAAE,EACb,UAAU,EAAE,cAAc,GACxB,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAyBzC;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,cAAc,GACxB,OAAO,CAAC,cAAc,GAAG,aAAa,CAAC,CAEzC","sourcesContent":["/**\n * Shared diff computation utilities for the edit tool.\n * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).\n */\n\nimport * as Diff from \"diff\";\nimport type { ToolOperations } from \"./operations.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { type LineEnding, stripBOM } from \"./replace-diff.ts\";\n\nexport { stripBOM as stripBom };\n\nexport function detectLineEnding(content: string): LineEnding {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: LineEnding): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\ninterface MatchedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content (trailing whitespace stripped,\n * Unicode quotes/dashes normalized to ASCII).\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// When fuzzy matching, we work in the normalized space for replacement.\n\t// This means the output will have normalized whitespace/quotes/dashes,\n\t// which is acceptable since we're fixing minor formatting differences anyway.\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: fuzzyContent,\n\t};\n}\nfunction countOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. If any edit needs\n * fuzzy matching, the operation runs in fuzzy-normalized content space to\n * preserve current single-edit behavior.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));\n\tconst baseContent = initialMatches.some((match) => match.usedFuzzyMatch)\n\t\t? normalizeForFuzzyMatch(normalizedContent)\n\t\t: normalizedContent;\n\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(baseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t}\n\n\t\tconst occurrences = countOccurrences(baseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: matchResult.index,\n\t\t\tmatchLength: matchResult.matchLength,\n\t\t\tnewText: edit.newText,\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tlet newContent = baseContent;\n\tfor (let i = matchedEdits.length - 1; i >= 0; i--) {\n\t\tconst edit = matchedEdits[i];\n\t\tnewContent =\n\t\t\tnewContent.substring(0, edit.matchIndex) +\n\t\t\tedit.newText +\n\t\t\tnewContent.substring(edit.matchIndex + edit.matchLength);\n\t}\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\ninterface DiffRenderState {\n\toutput: string[];\n\toldLineNumber: number;\n\tnewLineNumber: number;\n\tlineNumberWidth: number;\n\tfirstChangedLine: number | undefined;\n}\n\nfunction getDiffPartLines(part: Diff.Change): string[] {\n\tconst lines = part.value.split(\"\\n\");\n\tif (lines.at(-1) === \"\") lines.pop();\n\treturn lines;\n}\n\nfunction appendChangedDiffLines(state: DiffRenderState, part: Diff.Change, lines: string[]): void {\n\tstate.firstChangedLine ??= state.newLineNumber;\n\tfor (const line of lines) {\n\t\tif (part.added) {\n\t\t\tconst lineNumber = String(state.newLineNumber).padStart(state.lineNumberWidth, \" \");\n\t\t\tstate.output.push(`+${lineNumber} ${line}`);\n\t\t\tstate.newLineNumber++;\n\t\t} else {\n\t\t\tconst lineNumber = String(state.oldLineNumber).padStart(state.lineNumberWidth, \" \");\n\t\t\tstate.output.push(`-${lineNumber} ${line}`);\n\t\t\tstate.oldLineNumber++;\n\t\t}\n\t}\n}\n\nfunction appendContextDiffLines(state: DiffRenderState, lines: string[]): void {\n\tfor (const line of lines) {\n\t\tconst lineNumber = String(state.oldLineNumber).padStart(state.lineNumberWidth, \" \");\n\t\tstate.output.push(` ${lineNumber} ${line}`);\n\t\tstate.oldLineNumber++;\n\t\tstate.newLineNumber++;\n\t}\n}\n\nfunction appendSkippedDiffLines(state: DiffRenderState, count: number): void {\n\tif (count <= 0) return;\n\tstate.output.push(` ${\"\".padStart(state.lineNumberWidth, \" \")} ...`);\n\tstate.oldLineNumber += count;\n\tstate.newLineNumber += count;\n}\n\nfunction appendContextBetweenChanges(state: DiffRenderState, lines: string[], contextLines: number): void {\n\tif (lines.length <= contextLines * 2) {\n\t\tappendContextDiffLines(state, lines);\n\t\treturn;\n\t}\n\tconst leadingLines = lines.slice(0, contextLines);\n\tconst trailingLines = lines.slice(lines.length - contextLines);\n\tappendContextDiffLines(state, leadingLines);\n\tappendSkippedDiffLines(state, lines.length - leadingLines.length - trailingLines.length);\n\tappendContextDiffLines(state, trailingLines);\n}\n\nfunction appendContextAfterChange(state: DiffRenderState, lines: string[], contextLines: number): void {\n\tconst shownLines = lines.slice(0, contextLines);\n\tappendContextDiffLines(state, shownLines);\n\tappendSkippedDiffLines(state, lines.length - shownLines.length);\n}\n\nfunction appendContextBeforeChange(state: DiffRenderState, lines: string[], contextLines: number): void {\n\tconst skippedLines = Math.max(0, lines.length - contextLines);\n\tappendSkippedDiffLines(state, skippedLines);\n\tappendContextDiffLines(state, lines.slice(skippedLines));\n}\n\nfunction appendUnchangedDiffPart(\n\tstate: DiffRenderState,\n\tlines: string[],\n\thasLeadingChange: boolean,\n\thasTrailingChange: boolean,\n\tcontextLines: number,\n): void {\n\tif (hasLeadingChange && hasTrailingChange) {\n\t\tappendContextBetweenChanges(state, lines, contextLines);\n\t\treturn;\n\t}\n\tif (hasLeadingChange) {\n\t\tappendContextAfterChange(state, lines, contextLines);\n\t\treturn;\n\t}\n\tif (hasTrailingChange) {\n\t\tappendContextBeforeChange(state, lines, contextLines);\n\t\treturn;\n\t}\n\tstate.oldLineNumber += lines.length;\n\tstate.newLineNumber += lines.length;\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(oldContent: string, newContent: string, contextLines = 4): EditDiffResult {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst maxLineNumber = Math.max(oldContent.split(\"\\n\").length, newContent.split(\"\\n\").length);\n\tconst state: DiffRenderState = {\n\t\toutput: [],\n\t\toldLineNumber: 1,\n\t\tnewLineNumber: 1,\n\t\tlineNumberWidth: String(maxLineNumber).length,\n\t\tfirstChangedLine: undefined,\n\t};\n\tlet lastWasChange = false;\n\n\tfor (let index = 0; index < parts.length; index++) {\n\t\tconst part = parts[index];\n\t\tconst lines = getDiffPartLines(part);\n\t\tif (part.added || part.removed) {\n\t\t\tappendChangedDiffLines(state, part, lines);\n\t\t\tlastWasChange = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst nextPart = parts[index + 1];\n\t\tappendUnchangedDiffPart(\n\t\t\tstate,\n\t\t\tlines,\n\t\t\tlastWasChange,\n\t\t\tindex < parts.length - 1 && Boolean(nextPart.added || nextPart.removed),\n\t\t\tcontextLines,\n\t\t);\n\t\tlastWasChange = false;\n\t}\n\n\treturn { diff: state.output.join(\"\\n\"), firstChangedLine: state.firstChangedLine };\n}\n\n// grip-ignore noNearIdenticalDataStructures: Plain line-number diffs and hashline-anchored diffs use distinct rendering formats and evolve independently.\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\toperations: ToolOperations,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, operations.cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait operations.access(absolutePath, \"read\");\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = (await operations.readFile(absolutePath)).toString(\"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBOM(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\toperations: ToolOperations,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], operations);\n}\n"]}
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Shared diff computation utilities for the edit tool.
3
+ * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).
4
+ */
5
+ import * as Diff from "diff";
6
+ import { resolveToCwd } from "./path-utils.js";
7
+ import { stripBOM } from "./replace-diff.js";
8
+ export { stripBOM as stripBom };
9
+ export function detectLineEnding(content) {
10
+ const crlfIdx = content.indexOf("\r\n");
11
+ const lfIdx = content.indexOf("\n");
12
+ if (lfIdx === -1)
13
+ return "\n";
14
+ if (crlfIdx === -1)
15
+ return "\n";
16
+ return crlfIdx < lfIdx ? "\r\n" : "\n";
17
+ }
18
+ export function normalizeToLF(text) {
19
+ return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
20
+ }
21
+ export function restoreLineEndings(text, ending) {
22
+ return ending === "\r\n" ? text.replace(/\n/g, "\r\n") : text;
23
+ }
24
+ /**
25
+ * Normalize text for fuzzy matching. Applies progressive transformations:
26
+ * - Strip trailing whitespace from each line
27
+ * - Normalize smart quotes to ASCII equivalents
28
+ * - Normalize Unicode dashes/hyphens to ASCII hyphen
29
+ * - Normalize special Unicode spaces to regular space
30
+ */
31
+ export function normalizeForFuzzyMatch(text) {
32
+ return (text
33
+ .normalize("NFKC")
34
+ // Strip trailing whitespace per line
35
+ .split("\n")
36
+ .map((line) => line.trimEnd())
37
+ .join("\n")
38
+ // Smart single quotes → '
39
+ .replace(/[\u2018\u2019\u201A\u201B]/g, "'")
40
+ // Smart double quotes → "
41
+ .replace(/[\u201C\u201D\u201E\u201F]/g, '"')
42
+ // Various dashes/hyphens → -
43
+ // U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,
44
+ // U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus
45
+ .replace(/[\u2010\u2011\u2012\u2013\u2014\u2015\u2212]/g, "-")
46
+ // Special spaces → regular space
47
+ // U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,
48
+ // U+205F medium math space, U+3000 ideographic space
49
+ .replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " "));
50
+ }
51
+ /**
52
+ * Find oldText in content, trying exact match first, then fuzzy match.
53
+ * When fuzzy matching is used, the returned contentForReplacement is the
54
+ * fuzzy-normalized version of the content (trailing whitespace stripped,
55
+ * Unicode quotes/dashes normalized to ASCII).
56
+ */
57
+ export function fuzzyFindText(content, oldText) {
58
+ // Try exact match first
59
+ const exactIndex = content.indexOf(oldText);
60
+ if (exactIndex !== -1) {
61
+ return {
62
+ found: true,
63
+ index: exactIndex,
64
+ matchLength: oldText.length,
65
+ usedFuzzyMatch: false,
66
+ contentForReplacement: content,
67
+ };
68
+ }
69
+ // Try fuzzy match - work entirely in normalized space
70
+ const fuzzyContent = normalizeForFuzzyMatch(content);
71
+ const fuzzyOldText = normalizeForFuzzyMatch(oldText);
72
+ const fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);
73
+ if (fuzzyIndex === -1) {
74
+ return {
75
+ found: false,
76
+ index: -1,
77
+ matchLength: 0,
78
+ usedFuzzyMatch: false,
79
+ contentForReplacement: content,
80
+ };
81
+ }
82
+ // When fuzzy matching, we work in the normalized space for replacement.
83
+ // This means the output will have normalized whitespace/quotes/dashes,
84
+ // which is acceptable since we're fixing minor formatting differences anyway.
85
+ return {
86
+ found: true,
87
+ index: fuzzyIndex,
88
+ matchLength: fuzzyOldText.length,
89
+ usedFuzzyMatch: true,
90
+ contentForReplacement: fuzzyContent,
91
+ };
92
+ }
93
+ function countOccurrences(content, oldText) {
94
+ const fuzzyContent = normalizeForFuzzyMatch(content);
95
+ const fuzzyOldText = normalizeForFuzzyMatch(oldText);
96
+ return fuzzyContent.split(fuzzyOldText).length - 1;
97
+ }
98
+ function getNotFoundError(path, editIndex, totalEdits) {
99
+ if (totalEdits === 1) {
100
+ return new Error(`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`);
101
+ }
102
+ return new Error(`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`);
103
+ }
104
+ function getDuplicateError(path, editIndex, totalEdits, occurrences) {
105
+ if (totalEdits === 1) {
106
+ return new Error(`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`);
107
+ }
108
+ return new Error(`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`);
109
+ }
110
+ function getEmptyOldTextError(path, editIndex, totalEdits) {
111
+ if (totalEdits === 1) {
112
+ return new Error(`oldText must not be empty in ${path}.`);
113
+ }
114
+ return new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);
115
+ }
116
+ function getNoChangeError(path, totalEdits) {
117
+ if (totalEdits === 1) {
118
+ return new Error(`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`);
119
+ }
120
+ return new Error(`No changes made to ${path}. The replacements produced identical content.`);
121
+ }
122
+ /**
123
+ * Apply one or more exact-text replacements to LF-normalized content.
124
+ *
125
+ * All edits are matched against the same original content. Replacements are
126
+ * then applied in reverse order so offsets remain stable. If any edit needs
127
+ * fuzzy matching, the operation runs in fuzzy-normalized content space to
128
+ * preserve current single-edit behavior.
129
+ */
130
+ export function applyEditsToNormalizedContent(normalizedContent, edits, path) {
131
+ const normalizedEdits = edits.map((edit) => ({
132
+ oldText: normalizeToLF(edit.oldText),
133
+ newText: normalizeToLF(edit.newText),
134
+ }));
135
+ for (let i = 0; i < normalizedEdits.length; i++) {
136
+ if (normalizedEdits[i].oldText.length === 0) {
137
+ throw getEmptyOldTextError(path, i, normalizedEdits.length);
138
+ }
139
+ }
140
+ const initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));
141
+ const baseContent = initialMatches.some((match) => match.usedFuzzyMatch)
142
+ ? normalizeForFuzzyMatch(normalizedContent)
143
+ : normalizedContent;
144
+ const matchedEdits = [];
145
+ for (let i = 0; i < normalizedEdits.length; i++) {
146
+ const edit = normalizedEdits[i];
147
+ const matchResult = fuzzyFindText(baseContent, edit.oldText);
148
+ if (!matchResult.found) {
149
+ throw getNotFoundError(path, i, normalizedEdits.length);
150
+ }
151
+ const occurrences = countOccurrences(baseContent, edit.oldText);
152
+ if (occurrences > 1) {
153
+ throw getDuplicateError(path, i, normalizedEdits.length, occurrences);
154
+ }
155
+ matchedEdits.push({
156
+ editIndex: i,
157
+ matchIndex: matchResult.index,
158
+ matchLength: matchResult.matchLength,
159
+ newText: edit.newText,
160
+ });
161
+ }
162
+ matchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);
163
+ for (let i = 1; i < matchedEdits.length; i++) {
164
+ const previous = matchedEdits[i - 1];
165
+ const current = matchedEdits[i];
166
+ if (previous.matchIndex + previous.matchLength > current.matchIndex) {
167
+ throw new Error(`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`);
168
+ }
169
+ }
170
+ let newContent = baseContent;
171
+ for (let i = matchedEdits.length - 1; i >= 0; i--) {
172
+ const edit = matchedEdits[i];
173
+ newContent =
174
+ newContent.substring(0, edit.matchIndex) +
175
+ edit.newText +
176
+ newContent.substring(edit.matchIndex + edit.matchLength);
177
+ }
178
+ if (baseContent === newContent) {
179
+ throw getNoChangeError(path, normalizedEdits.length);
180
+ }
181
+ return { baseContent, newContent };
182
+ }
183
+ /** Generate a standard unified patch. */
184
+ export function generateUnifiedPatch(path, oldContent, newContent, contextLines = 4) {
185
+ return Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {
186
+ context: contextLines,
187
+ headerOptions: Diff.FILE_HEADERS_ONLY,
188
+ });
189
+ }
190
+ function getDiffPartLines(part) {
191
+ const lines = part.value.split("\n");
192
+ if (lines.at(-1) === "")
193
+ lines.pop();
194
+ return lines;
195
+ }
196
+ function appendChangedDiffLines(state, part, lines) {
197
+ state.firstChangedLine ??= state.newLineNumber;
198
+ for (const line of lines) {
199
+ if (part.added) {
200
+ const lineNumber = String(state.newLineNumber).padStart(state.lineNumberWidth, " ");
201
+ state.output.push(`+${lineNumber} ${line}`);
202
+ state.newLineNumber++;
203
+ }
204
+ else {
205
+ const lineNumber = String(state.oldLineNumber).padStart(state.lineNumberWidth, " ");
206
+ state.output.push(`-${lineNumber} ${line}`);
207
+ state.oldLineNumber++;
208
+ }
209
+ }
210
+ }
211
+ function appendContextDiffLines(state, lines) {
212
+ for (const line of lines) {
213
+ const lineNumber = String(state.oldLineNumber).padStart(state.lineNumberWidth, " ");
214
+ state.output.push(` ${lineNumber} ${line}`);
215
+ state.oldLineNumber++;
216
+ state.newLineNumber++;
217
+ }
218
+ }
219
+ function appendSkippedDiffLines(state, count) {
220
+ if (count <= 0)
221
+ return;
222
+ state.output.push(` ${"".padStart(state.lineNumberWidth, " ")} ...`);
223
+ state.oldLineNumber += count;
224
+ state.newLineNumber += count;
225
+ }
226
+ function appendContextBetweenChanges(state, lines, contextLines) {
227
+ if (lines.length <= contextLines * 2) {
228
+ appendContextDiffLines(state, lines);
229
+ return;
230
+ }
231
+ const leadingLines = lines.slice(0, contextLines);
232
+ const trailingLines = lines.slice(lines.length - contextLines);
233
+ appendContextDiffLines(state, leadingLines);
234
+ appendSkippedDiffLines(state, lines.length - leadingLines.length - trailingLines.length);
235
+ appendContextDiffLines(state, trailingLines);
236
+ }
237
+ function appendContextAfterChange(state, lines, contextLines) {
238
+ const shownLines = lines.slice(0, contextLines);
239
+ appendContextDiffLines(state, shownLines);
240
+ appendSkippedDiffLines(state, lines.length - shownLines.length);
241
+ }
242
+ function appendContextBeforeChange(state, lines, contextLines) {
243
+ const skippedLines = Math.max(0, lines.length - contextLines);
244
+ appendSkippedDiffLines(state, skippedLines);
245
+ appendContextDiffLines(state, lines.slice(skippedLines));
246
+ }
247
+ function appendUnchangedDiffPart(state, lines, hasLeadingChange, hasTrailingChange, contextLines) {
248
+ if (hasLeadingChange && hasTrailingChange) {
249
+ appendContextBetweenChanges(state, lines, contextLines);
250
+ return;
251
+ }
252
+ if (hasLeadingChange) {
253
+ appendContextAfterChange(state, lines, contextLines);
254
+ return;
255
+ }
256
+ if (hasTrailingChange) {
257
+ appendContextBeforeChange(state, lines, contextLines);
258
+ return;
259
+ }
260
+ state.oldLineNumber += lines.length;
261
+ state.newLineNumber += lines.length;
262
+ }
263
+ /**
264
+ * Generate a display-oriented diff string with line numbers and context.
265
+ * Returns both the diff string and the first changed line number (in the new file).
266
+ */
267
+ export function generateDiffString(oldContent, newContent, contextLines = 4) {
268
+ const parts = Diff.diffLines(oldContent, newContent);
269
+ const maxLineNumber = Math.max(oldContent.split("\n").length, newContent.split("\n").length);
270
+ const state = {
271
+ output: [],
272
+ oldLineNumber: 1,
273
+ newLineNumber: 1,
274
+ lineNumberWidth: String(maxLineNumber).length,
275
+ firstChangedLine: undefined,
276
+ };
277
+ let lastWasChange = false;
278
+ for (let index = 0; index < parts.length; index++) {
279
+ const part = parts[index];
280
+ const lines = getDiffPartLines(part);
281
+ if (part.added || part.removed) {
282
+ appendChangedDiffLines(state, part, lines);
283
+ lastWasChange = true;
284
+ continue;
285
+ }
286
+ const nextPart = parts[index + 1];
287
+ appendUnchangedDiffPart(state, lines, lastWasChange, index < parts.length - 1 && Boolean(nextPart.added || nextPart.removed), contextLines);
288
+ lastWasChange = false;
289
+ }
290
+ return { diff: state.output.join("\n"), firstChangedLine: state.firstChangedLine };
291
+ }
292
+ /**
293
+ * Compute the diff for one or more edit operations without applying them.
294
+ * Used for preview rendering in the TUI before the tool executes.
295
+ */
296
+ export async function computeEditsDiff(path, edits, operations) {
297
+ const absolutePath = resolveToCwd(path, operations.cwd);
298
+ try {
299
+ // Check if file exists and is readable
300
+ try {
301
+ await operations.access(absolutePath, "read");
302
+ }
303
+ catch (error) {
304
+ const errorMessage = error instanceof Error && "code" in error ? `Error code: ${error.code}` : String(error);
305
+ return { error: `Could not edit file: ${path}. ${errorMessage}.` };
306
+ }
307
+ // Read the file
308
+ const rawContent = (await operations.readFile(absolutePath)).toString("utf-8");
309
+ // Strip BOM before matching (LLM won't include invisible BOM in oldText)
310
+ const { text: content } = stripBOM(rawContent);
311
+ const normalizedContent = normalizeToLF(content);
312
+ const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
313
+ // Generate the diff
314
+ return generateDiffString(baseContent, newContent);
315
+ }
316
+ catch (err) {
317
+ return { error: err instanceof Error ? err.message : String(err) };
318
+ }
319
+ }
320
+ /**
321
+ * Compute the diff for a single edit operation without applying it.
322
+ * Kept as a convenience wrapper for single-edit callers.
323
+ */
324
+ export async function computeEditDiff(path, oldText, newText, operations) {
325
+ return computeEditsDiff(path, [{ oldText, newText }], operations);
326
+ }
327
+ //# sourceMappingURL=edit-diff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAmB,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,CAAC;AAEhC,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAc;IAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG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CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE/E,yEAAyE;QACzE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC/C,MAAM,iBAAiB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,6BAA6B,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAElG,oBAAoB;QACpB,OAAO,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AAAA,CACD;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,IAAY,EACZ,OAAe,EACf,OAAe,EACf,UAA0B,EACgB;IAC1C,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;AAAA,CAClE","sourcesContent":["/**\n * Shared diff computation utilities for the edit tool.\n * Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).\n */\n\nimport * as Diff from \"diff\";\nimport type { ToolOperations } from \"./operations.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { type LineEnding, stripBOM } from \"./replace-diff.ts\";\n\nexport { stripBOM as stripBom };\n\nexport function detectLineEnding(content: string): LineEnding {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: LineEnding): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\ninterface MatchedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content (trailing whitespace stripped,\n * Unicode quotes/dashes normalized to ASCII).\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// When fuzzy matching, we work in the normalized space for replacement.\n\t// This means the output will have normalized whitespace/quotes/dashes,\n\t// which is acceptable since we're fixing minor formatting differences anyway.\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: fuzzyContent,\n\t};\n}\nfunction countOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. If any edit needs\n * fuzzy matching, the operation runs in fuzzy-normalized content space to\n * preserve current single-edit behavior.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));\n\tconst baseContent = initialMatches.some((match) => match.usedFuzzyMatch)\n\t\t? normalizeForFuzzyMatch(normalizedContent)\n\t\t: normalizedContent;\n\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(baseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t}\n\n\t\tconst occurrences = countOccurrences(baseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: matchResult.index,\n\t\t\tmatchLength: matchResult.matchLength,\n\t\t\tnewText: edit.newText,\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tlet newContent = baseContent;\n\tfor (let i = matchedEdits.length - 1; i >= 0; i--) {\n\t\tconst edit = matchedEdits[i];\n\t\tnewContent =\n\t\t\tnewContent.substring(0, edit.matchIndex) +\n\t\t\tedit.newText +\n\t\t\tnewContent.substring(edit.matchIndex + edit.matchLength);\n\t}\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\ninterface DiffRenderState {\n\toutput: string[];\n\toldLineNumber: number;\n\tnewLineNumber: number;\n\tlineNumberWidth: number;\n\tfirstChangedLine: number | undefined;\n}\n\nfunction getDiffPartLines(part: Diff.Change): string[] {\n\tconst lines = part.value.split(\"\\n\");\n\tif (lines.at(-1) === \"\") lines.pop();\n\treturn lines;\n}\n\nfunction appendChangedDiffLines(state: DiffRenderState, part: Diff.Change, lines: string[]): void {\n\tstate.firstChangedLine ??= state.newLineNumber;\n\tfor (const line of lines) {\n\t\tif (part.added) {\n\t\t\tconst lineNumber = String(state.newLineNumber).padStart(state.lineNumberWidth, \" \");\n\t\t\tstate.output.push(`+${lineNumber} ${line}`);\n\t\t\tstate.newLineNumber++;\n\t\t} else {\n\t\t\tconst lineNumber = String(state.oldLineNumber).padStart(state.lineNumberWidth, \" \");\n\t\t\tstate.output.push(`-${lineNumber} ${line}`);\n\t\t\tstate.oldLineNumber++;\n\t\t}\n\t}\n}\n\nfunction appendContextDiffLines(state: DiffRenderState, lines: string[]): void {\n\tfor (const line of lines) {\n\t\tconst lineNumber = String(state.oldLineNumber).padStart(state.lineNumberWidth, \" \");\n\t\tstate.output.push(` ${lineNumber} ${line}`);\n\t\tstate.oldLineNumber++;\n\t\tstate.newLineNumber++;\n\t}\n}\n\nfunction appendSkippedDiffLines(state: DiffRenderState, count: number): void {\n\tif (count <= 0) return;\n\tstate.output.push(` ${\"\".padStart(state.lineNumberWidth, \" \")} ...`);\n\tstate.oldLineNumber += count;\n\tstate.newLineNumber += count;\n}\n\nfunction appendContextBetweenChanges(state: DiffRenderState, lines: string[], contextLines: number): void {\n\tif (lines.length <= contextLines * 2) {\n\t\tappendContextDiffLines(state, lines);\n\t\treturn;\n\t}\n\tconst leadingLines = lines.slice(0, contextLines);\n\tconst trailingLines = lines.slice(lines.length - contextLines);\n\tappendContextDiffLines(state, leadingLines);\n\tappendSkippedDiffLines(state, lines.length - leadingLines.length - trailingLines.length);\n\tappendContextDiffLines(state, trailingLines);\n}\n\nfunction appendContextAfterChange(state: DiffRenderState, lines: string[], contextLines: number): void {\n\tconst shownLines = lines.slice(0, contextLines);\n\tappendContextDiffLines(state, shownLines);\n\tappendSkippedDiffLines(state, lines.length - shownLines.length);\n}\n\nfunction appendContextBeforeChange(state: DiffRenderState, lines: string[], contextLines: number): void {\n\tconst skippedLines = Math.max(0, lines.length - contextLines);\n\tappendSkippedDiffLines(state, skippedLines);\n\tappendContextDiffLines(state, lines.slice(skippedLines));\n}\n\nfunction appendUnchangedDiffPart(\n\tstate: DiffRenderState,\n\tlines: string[],\n\thasLeadingChange: boolean,\n\thasTrailingChange: boolean,\n\tcontextLines: number,\n): void {\n\tif (hasLeadingChange && hasTrailingChange) {\n\t\tappendContextBetweenChanges(state, lines, contextLines);\n\t\treturn;\n\t}\n\tif (hasLeadingChange) {\n\t\tappendContextAfterChange(state, lines, contextLines);\n\t\treturn;\n\t}\n\tif (hasTrailingChange) {\n\t\tappendContextBeforeChange(state, lines, contextLines);\n\t\treturn;\n\t}\n\tstate.oldLineNumber += lines.length;\n\tstate.newLineNumber += lines.length;\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(oldContent: string, newContent: string, contextLines = 4): EditDiffResult {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst maxLineNumber = Math.max(oldContent.split(\"\\n\").length, newContent.split(\"\\n\").length);\n\tconst state: DiffRenderState = {\n\t\toutput: [],\n\t\toldLineNumber: 1,\n\t\tnewLineNumber: 1,\n\t\tlineNumberWidth: String(maxLineNumber).length,\n\t\tfirstChangedLine: undefined,\n\t};\n\tlet lastWasChange = false;\n\n\tfor (let index = 0; index < parts.length; index++) {\n\t\tconst part = parts[index];\n\t\tconst lines = getDiffPartLines(part);\n\t\tif (part.added || part.removed) {\n\t\t\tappendChangedDiffLines(state, part, lines);\n\t\t\tlastWasChange = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst nextPart = parts[index + 1];\n\t\tappendUnchangedDiffPart(\n\t\t\tstate,\n\t\t\tlines,\n\t\t\tlastWasChange,\n\t\t\tindex < parts.length - 1 && Boolean(nextPart.added || nextPart.removed),\n\t\t\tcontextLines,\n\t\t);\n\t\tlastWasChange = false;\n\t}\n\n\treturn { diff: state.output.join(\"\\n\"), firstChangedLine: state.firstChangedLine };\n}\n\n// grip-ignore noNearIdenticalDataStructures: Plain line-number diffs and hashline-anchored diffs use distinct rendering formats and evolve independently.\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\toperations: ToolOperations,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, operations.cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait operations.access(absolutePath, \"read\");\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = (await operations.readFile(absolutePath)).toString(\"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBOM(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\toperations: ToolOperations,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], operations);\n}\n"]}
@@ -0,0 +1,50 @@
1
+ import type { AgentTool, AgentToolResult, AgentToolUpdateCallback } from "@greppleai/grip-agent-core";
2
+ import { type Static, Type } from "typebox";
3
+ import type { ToolDefinition } from "../extensions/types.ts";
4
+ import { type HTEdit } from "./hashline/resolve.ts";
5
+ import type { ToolOperations } from "./operations.ts";
6
+ import { type RRState } from "./replace-render.ts";
7
+ declare const editSchema: Type.TObject<{
8
+ path: Type.TString;
9
+ changes: Type.TArray<Type.TObject<{
10
+ hash_range_inclusive: Type.TArray<Type.TString>;
11
+ content_lines: Type.TArray<Type.TString>;
12
+ }>>;
13
+ }>;
14
+ export type EditToolInput = Static<typeof editSchema>;
15
+ export type ReqParams = {
16
+ path: string;
17
+ changes: HTEdit[];
18
+ };
19
+ interface EditChangedLineRange {
20
+ first: number;
21
+ last: number;
22
+ }
23
+ export type RMetrics = {
24
+ edits_attempted: number;
25
+ edits_noop: number;
26
+ warnings: number;
27
+ classification: "applied" | "noop";
28
+ changed_lines?: EditChangedLineRange;
29
+ added_lines?: number;
30
+ removed_lines?: number;
31
+ };
32
+ export interface ReplaceDetails {
33
+ diff: string;
34
+ patch: string;
35
+ firstChangedLine?: number;
36
+ classification?: "noop";
37
+ metrics?: RMetrics;
38
+ }
39
+ export type EditToolDetails = ReplaceDetails;
40
+ export interface EditToolOptions {
41
+ }
42
+ type EditRenderState = RRState;
43
+ export type EditToolDefinition = ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState>;
44
+ export declare function createEditToolDefinition(operations: ToolOperations, _options?: EditToolOptions): EditToolDefinition;
45
+ type CompatibleEditAgentTool = AgentTool<typeof editSchema, EditToolDetails> & {
46
+ execute: (toolCallId: string, params: Record<string, unknown>, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<EditToolDetails>) => Promise<AgentToolResult<EditToolDetails>>;
47
+ };
48
+ export declare function createEditTool(operations: ToolOperations, options?: EditToolOptions): CompatibleEditAgentTool;
49
+ export {};
50
+ //# sourceMappingURL=edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAGtG,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI7D,OAAO,EAAc,KAAK,MAAM,EAAY,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKvE,OAAO,EAA2C,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAuB5F,QAAA,MAAM,UAAU;;;;;;EAQf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AACF,UAAU,oBAAoB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,QAAQ,GAAG;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,SAAS,GAAG,MAAM,CAAC;IACnC,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACnB;AAED,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC;AAE7C,MAAM,WAAW,eAAe;CAAG;AAEnC,KAAK,eAAe,GAAG,OAAO,CAAC;AA2R/B,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CAAC;AAEjH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,eAAe,GAAG,kBAAkB,CA2EnH;AAED,KAAK,uBAAuB,GAAG,SAAS,CAAC,OAAO,UAAU,EAAE,eAAe,CAAC,GAAG;IAC9E,OAAO,EAAE,CACR,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,CAAC,EAAE,WAAW,EACpB,QAAQ,CAAC,EAAE,uBAAuB,CAAC,eAAe,CAAC,KAC/C,OAAO,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,wBAAgB,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,uBAAuB,CAE7G","sourcesContent":["import type { AgentTool, AgentToolResult, AgentToolUpdateCallback } from \"@greppleai/grip-agent-core\";\nimport { Text } from \"@greppleai/grip-tui\";\nimport { createTwoFilesPatch } from \"diff\";\nimport { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { type ApplyEditsResult, applyEdits, fmtBoundaryWarning } from \"./hashline/apply.ts\";\nimport { initHasher, lineHashes } from \"./hashline/hash.ts\";\nimport { type HEdit, type HTEdit, resEdits } from \"./hashline/resolve.ts\";\nimport type { ToolBackendInfo, ToolOperations } from \"./operations.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { formatBackendIcon, invalidArgText, shortenPath, str } from \"./render-utils.ts\";\nimport { detectEnding, genDiff, type LineEnding, restoreEndings, stripBOM, toLF } from \"./replace-diff.ts\";\nimport { normReq } from \"./replace-normalize.ts\";\nimport { fmtCall, getPreviewInput, type RPreview, type RRState } from \"./replace-render.ts\";\nimport { abortIf } from \"./runtime.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst contentLinesSchema = Type.Array(Type.String(), {\n\tdescription:\n\t\t\"Literal replacement content, one string per line. Use [] to delete the range. Do not include HASH│ prefixes from read output.\",\n});\n\nconst hashRangeInclusiveSchema = Type.Array(Type.String(), {\n\tdescription: \"Inclusive hash range to replace [start_hash, end_hash]. Use hash anchors only.\",\n\tminItems: 2,\n\tmaxItems: 2,\n});\n\nconst editItemSchema = Type.Object(\n\t{\n\t\thash_range_inclusive: hashRangeInclusiveSchema,\n\t\tcontent_lines: contentLinesSchema,\n\t},\n\t{ additionalProperties: false },\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tchanges: Type.Array(editItemSchema, {\n\t\t\tdescription: \"One or more hash-anchored replacements. All anchors must come from the same read snapshot.\",\n\t\t}),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type EditToolInput = Static<typeof editSchema>;\n\nexport type ReqParams = {\n\tpath: string;\n\tchanges: HTEdit[];\n};\ninterface EditChangedLineRange {\n\tfirst: number;\n\tlast: number;\n}\n\nexport type RMetrics = {\n\tedits_attempted: number;\n\tedits_noop: number;\n\twarnings: number;\n\tclassification: \"applied\" | \"noop\";\n\tchanged_lines?: EditChangedLineRange;\n\tadded_lines?: number;\n\tremoved_lines?: number;\n};\n\nexport interface ReplaceDetails {\n\tdiff: string;\n\tpatch: string;\n\tfirstChangedLine?: number;\n\tclassification?: \"noop\";\n\tmetrics?: RMetrics;\n}\n\nexport type EditToolDetails = ReplaceDetails;\n\nexport interface EditToolOptions {}\n\ntype EditRenderState = RRState;\ntype DiffLineMarker = \"+\" | \"-\";\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tchanges?: HTEdit[];\n\tedits?: HTEdit[];\n\thash_range_inclusive?: [string, string];\n\tcontent_lines?: string[];\n};\n\nfunction countDiffLines(diff: string, marker: DiffLineMarker): number {\n\tlet count = 0;\n\tfor (const line of diff.split(\"\\n\")) {\n\t\tif (line.startsWith(marker) && !line.startsWith(`${marker}${marker}${marker}`)) {\n\t\t\tcount++;\n\t\t}\n\t}\n\treturn count;\n}\n\nfunction hashStoreKey(operations: ToolOperations, absolutePath: string): string {\n\tconst backend = operations.getBackendInfo?.();\n\tif (!backend) return absolutePath;\n\tif (backend.type === \"remote\" && backend.configured) return `remote:${backend.url}:${absolutePath}`;\n\treturn absolutePath;\n}\n\nfunction formatEditCall(\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tbackendInfo: ToolBackendInfo | undefined,\n): string {\n\tconst previewInput = getPreviewInput(args);\n\tif (previewInput) {\n\t\treturn formatBackendIcon(backendInfo, theme) + fmtCall(previewInput, {}, false, theme).replace(\"replace\", \"edit\");\n\t}\n\tconst invalidArg = invalidArgText(theme);\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath) : null;\n\tconst pathDisplay = path === null ? invalidArg : path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\treturn `${formatBackendIcon(backendInfo, theme)}${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nasync function computePreview(request: ReqParams, operations: ToolOperations): Promise<RPreview> {\n\ttry {\n\t\tawait initHasher();\n\t\tconst absolutePath = resolveToCwd(request.path, operations.cwd);\n\t\tawait operations.access(absolutePath, \"read\");\n\t\tconst rawContent = (await operations.readFile(absolutePath)).toString(\"utf-8\");\n\t\tconst { text } = stripBOM(rawContent);\n\t\tconst originalNormalized = toLF(text);\n\t\tconst originalHashes = await lineHashes(originalNormalized, hashStoreKey(operations, absolutePath));\n\t\tconst result = applyEdits(\n\t\t\toriginalNormalized,\n\t\t\tresEdits(request.changes),\n\t\t\tundefined,\n\t\t\toriginalHashes,\n\t\t\trequest.path,\n\t\t).content;\n\t\tif (originalNormalized === result) {\n\t\t\treturn { error: `No changes made to ${request.path}. The edits produced identical content.` };\n\t\t}\n\t\tconst resultHashes = await lineHashes(result);\n\t\treturn { diff: genDiff(originalNormalized, result, 4, resultHashes, originalHashes).diff };\n\t} catch (error) {\n\t\treturn { error: error instanceof Error ? error.message : String(error) };\n\t}\n}\n\nfunction normalizeEditArguments(input: unknown): EditToolInput {\n\treturn normReq(input) as EditToolInput;\n}\n\nfunction assertReq(request: unknown): asserts request is ReqParams {\n\tif (!request || typeof request !== \"object\" || Array.isArray(request)) {\n\t\tthrow new Error(\"[E_BAD_SHAPE] Edit request must be an object.\");\n\t}\n\tconst record = request as Record<string, unknown>;\n\tfor (const legacyKey of [\"oldText\", \"newText\", \"old_text\", \"new_text\", \"old_range\", \"start\", \"end\", \"lines\"]) {\n\t\tif (Object.hasOwn(record, legacyKey)) {\n\t\t\tthrow new Error(\n\t\t\t\t`[E_LEGACY_SHAPE] \"${legacyKey}\" is not supported. Call read first, then use {hash_range_inclusive: [\"<START>\", \"<END>\"], content_lines: [...]}.`,\n\t\t\t);\n\t\t}\n\t}\n\tconst unknown = Object.keys(record).filter((key) => key !== \"path\" && key !== \"changes\");\n\tif (unknown.length > 0) {\n\t\tthrow new Error(`[E_BAD_SHAPE] Edit request contains unknown or unsupported fields: ${unknown.join(\", \")}.`);\n\t}\n\tif (typeof record.path !== \"string\" || record.path.length === 0) {\n\t\tthrow new Error('[E_BAD_SHAPE] Edit request requires a non-empty \"path\" string.');\n\t}\n\tif (!Array.isArray(record.changes) || record.changes.length === 0) {\n\t\tthrow new Error('[E_BAD_SHAPE] Edit request requires a non-empty \"changes\" array.');\n\t}\n}\ninterface EditSourceSnapshot {\n\tbom: string;\n\toriginalEnding: LineEnding;\n\toriginalContent: string;\n\toriginalHashes: string[];\n\tstoreKey: string;\n}\n\ninterface AppliedEditResultOptions {\n\tpath: string;\n\teditCount: number;\n\tanchorResult: ApplyEditsResult;\n\twarnings: string[];\n\toriginalContent: string;\n\tresultContent: string;\n\toriginalHashes: string[];\n\tresultHashes: string[];\n}\n\nasync function readEditSource(\n\tpath: string,\n\tabsolutePath: string,\n\toperations: ToolOperations,\n): Promise<EditSourceSnapshot> {\n\ttry {\n\t\tawait operations.access(absolutePath, \"readwrite\");\n\t} catch (error) {\n\t\tconst message = error instanceof Error && \"code\" in error ? `Error code: ${String(error.code)}` : String(error);\n\t\tthrow new Error(`Could not edit file: ${path}. ${message}.`);\n\t}\n\tconst rawContent = (await operations.readFile(absolutePath)).toString(\"utf-8\");\n\tconst { bom, text } = stripBOM(rawContent);\n\tconst originalContent = toLF(text);\n\tconst storeKey = hashStoreKey(operations, absolutePath);\n\treturn {\n\t\tbom,\n\t\toriginalEnding: detectEnding(text),\n\t\toriginalContent,\n\t\toriginalHashes: await lineHashes(originalContent, storeKey),\n\t\tstoreKey,\n\t};\n}\n\nfunction collectRemovedHashes(edits: HEdit[], originalHashes: string[]): Set<string> {\n\tconst hashIndexes = new Map<string, number>();\n\tfor (let index = 0; index < originalHashes.length; index++) {\n\t\tconst hash = originalHashes[index];\n\t\tif (hash !== undefined && !hashIndexes.has(hash)) hashIndexes.set(hash, index);\n\t}\n\tconst removedHashes = new Set<string>();\n\tfor (const edit of edits) {\n\t\tconst startLine = hashIndexes.get(edit.hash_range_inclusive[0].hash) ?? -1;\n\t\tconst endLine = hashIndexes.get(edit.hash_range_inclusive[1].hash) ?? -1;\n\t\tif (startLine < 0 || endLine < 0) continue;\n\t\tfor (let index = startLine; index <= endLine; index++) {\n\t\t\tconst hash = originalHashes[index];\n\t\t\tif (hash) removedHashes.add(hash);\n\t\t}\n\t}\n\treturn removedHashes;\n}\n\nfunction indexLineOccurrences(lines: string[]): Map<string, number[]> {\n\tconst indexesByLine = new Map<string, number[]>();\n\tfor (let index = 0; index < lines.length; index++) {\n\t\tconst line = lines[index];\n\t\tconst indexes = indexesByLine.get(line);\n\t\tif (indexes) indexes.push(index);\n\t\telse indexesByLine.set(line, [index]);\n\t}\n\treturn indexesByLine;\n}\n\nfunction collectEditWarnings(anchorResult: ApplyEditsResult, resultContent: string, resultHashes: string[]): string[] {\n\tconst warnings = [...(anchorResult.warnings ?? [])];\n\tconst resultLines = resultContent.split(\"\\n\");\n\tconst indexesByLine = indexLineOccurrences(resultLines);\n\tfor (const warning of anchorResult.boundaryWarnings ?? []) {\n\t\tconst matchIndex = indexesByLine.get(warning.survivingLineContent)?.[warning.occurrence] ?? -1;\n\t\tif (matchIndex < 0) continue;\n\t\twarnings.push(\n\t\t\tfmtBoundaryWarning({\n\t\t\t\tkind: warning.kind,\n\t\t\t\tsurvivingContent: warning.survivingLineContent,\n\t\t\t\tmatchIndex,\n\t\t\t\tresultLines,\n\t\t\t\tresultHashes,\n\t\t\t}),\n\t\t);\n\t}\n\treturn warnings;\n}\n\nfunction buildNoopEditResult(\n\tpath: string,\n\teditCount: number,\n\tanchorResult: ApplyEditsResult,\n\twarnings: string[],\n): AgentToolResult<EditToolDetails> {\n\treturn {\n\t\tcontent: [{ type: \"text\", text: `No changes made to ${path}. The edits produced identical content.` }],\n\t\tdetails: {\n\t\t\tdiff: \"\",\n\t\t\tpatch: \"\",\n\t\t\tclassification: \"noop\",\n\t\t\tmetrics: {\n\t\t\t\tedits_attempted: editCount,\n\t\t\t\tedits_noop: anchorResult.noopEdits?.length ?? 0,\n\t\t\t\twarnings: warnings.length,\n\t\t\t\tclassification: \"noop\",\n\t\t\t},\n\t\t},\n\t};\n}\n\nfunction buildAppliedEditResult(options: AppliedEditResultOptions): AgentToolResult<EditToolDetails> {\n\tconst diffResult = genDiff(\n\t\toptions.originalContent,\n\t\toptions.resultContent,\n\t\t2,\n\t\toptions.resultHashes,\n\t\toptions.originalHashes,\n\t);\n\tconst warningBlock = options.warnings.length > 0 ? `\\n\\nWarnings:\\n${options.warnings.join(\"\\n\")}` : \"\";\n\tconst changedLines =\n\t\toptions.anchorResult.firstChangedLine !== undefined && options.anchorResult.lastChangedLine !== undefined\n\t\t\t? {\n\t\t\t\t\tfirst: options.anchorResult.firstChangedLine,\n\t\t\t\t\tlast: options.anchorResult.lastChangedLine,\n\t\t\t\t}\n\t\t\t: undefined;\n\treturn {\n\t\tcontent: [{ type: \"text\", text: `Successfully replaced in ${options.path}.${warningBlock}` }],\n\t\tdetails: {\n\t\t\tdiff: diffResult.diff,\n\t\t\tpatch: createTwoFilesPatch(options.path, options.path, options.originalContent, options.resultContent),\n\t\t\tfirstChangedLine: options.anchorResult.firstChangedLine ?? diffResult.firstChangedLine,\n\t\t\tmetrics: {\n\t\t\t\tedits_attempted: options.editCount,\n\t\t\t\tedits_noop: options.anchorResult.noopEdits?.length ?? 0,\n\t\t\t\twarnings: options.warnings.length,\n\t\t\t\tclassification: \"applied\",\n\t\t\t\t...(changedLines ? { changed_lines: changedLines } : {}),\n\t\t\t\tadded_lines: countDiffLines(diffResult.diff, \"+\"),\n\t\t\t\tremoved_lines: countDiffLines(diffResult.diff, \"-\"),\n\t\t\t},\n\t\t},\n\t};\n}\n\nasync function executeEditMutation(\n\trequest: ReqParams,\n\tabsolutePath: string,\n\toperations: ToolOperations,\n\tsignal: AbortSignal | undefined,\n): Promise<AgentToolResult<EditToolDetails>> {\n\tabortIf(signal);\n\tawait initHasher();\n\tconst source = await readEditSource(request.path, absolutePath, operations);\n\tconst resolvedEdits = resEdits(request.changes);\n\tconst anchorResult = applyEdits(source.originalContent, resolvedEdits, signal, source.originalHashes, request.path);\n\tconst resultContent = anchorResult.content;\n\tconst resultHashes = await lineHashes(resultContent, source.storeKey, {\n\t\tcontent: source.originalContent,\n\t\thashes: source.originalHashes,\n\t\tremovedHashes: collectRemovedHashes(resolvedEdits, source.originalHashes),\n\t});\n\tconst warnings = collectEditWarnings(anchorResult, resultContent, resultHashes);\n\tif (source.originalContent === resultContent) {\n\t\treturn buildNoopEditResult(request.path, request.changes.length, anchorResult, warnings);\n\t}\n\tabortIf(signal);\n\tawait operations.writeFile(absolutePath, source.bom + restoreEndings(resultContent, source.originalEnding));\n\treturn buildAppliedEditResult({\n\t\tpath: request.path,\n\t\teditCount: request.changes.length,\n\t\tanchorResult,\n\t\twarnings,\n\t\toriginalContent: source.originalContent,\n\t\tresultContent,\n\t\toriginalHashes: source.originalHashes,\n\t\tresultHashes,\n\t});\n}\n\nexport type EditToolDefinition = ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState>;\n\nexport function createEditToolDefinition(operations: ToolOperations, _options?: EditToolOptions): EditToolDefinition {\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a file using hash-anchored line replacements. Call read first; it returns HASH│content lines. Use hash_range_inclusive with the 3-character start/end hashes and content_lines with literal replacement lines only.\",\n\t\tpromptSnippet: \"Edit files using hashline anchors from read output\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use read before edit to get HASH│content anchors.\",\n\t\t\t\"Use edit with changes: [{ hash_range_inclusive: [startHash, endHash], content_lines: [...] }].\",\n\t\t\t\"hash_range_inclusive contains only the 3-character hashes, not line numbers and not HASH│content.\",\n\t\t\t\"content_lines contains literal file content only; do not include HASH│ prefixes. Use [] to delete a range.\",\n\t\t\t\"After a successful edit, call read again before follow-up edits unless the response includes current warning anchors.\",\n\t\t],\n\t\tparameters: editSchema,\n\t\trenderShell: \"default\",\n\t\tprepareArguments: normalizeEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal) {\n\t\t\tconst normalized = normReq(input);\n\t\t\tassertReq(normalized);\n\t\t\tconst absolutePath = resolveToCwd(normalized.path, operations.cwd);\n\t\t\treturn withFileMutationQueue(absolutePath, () =>\n\t\t\t\texecuteEditMutation(normalized, absolutePath, operations, signal),\n\t\t\t);\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tconst previewInput = getPreviewInput(args);\n\t\t\tif (!context.executionStarted && context.argsComplete && previewInput) {\n\t\t\t\tconst argsKey = JSON.stringify(previewInput);\n\t\t\t\tif (context.state.argsKey !== argsKey) {\n\t\t\t\t\tcontext.state.argsKey = argsKey;\n\t\t\t\t\tcontext.state.preview = undefined;\n\t\t\t\t\tconst generation = (context.state.previewGeneration ?? 0) + 1;\n\t\t\t\t\tcontext.state.previewGeneration = generation;\n\t\t\t\t\tvoid computePreview(previewInput, operations).then((preview) => {\n\t\t\t\t\t\tif (context.state.argsKey === argsKey && context.state.previewGeneration === generation) {\n\t\t\t\t\t\t\tcontext.state.preview = preview;\n\t\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\ttext.setText(\n\t\t\t\t\tformatBackendIcon(operations.getBackendInfo?.(), theme) +\n\t\t\t\t\t\tfmtCall(previewInput, context.state, context.expanded, theme).replace(\"replace\", \"edit\"),\n\t\t\t\t);\n\t\t\t\treturn text;\n\t\t\t}\n\t\t\ttext.setText(formatEditCall(args as RenderableEditArgs | undefined, theme, operations.getBackendInfo?.()));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\tif (context.isError) {\n\t\t\t\tconst errorText = result.content\n\t\t\t\t\t?.filter((entry) => entry.type === \"text\")\n\t\t\t\t\t.map((entry) => entry.text ?? \"\")\n\t\t\t\t\t.join(\"\\n\");\n\t\t\t\ttext.setText(errorText ? `\\n${theme.fg(\"error\", errorText)}` : \"\");\n\t\t\t\treturn text;\n\t\t\t}\n\t\t\tconst diff = result.details?.diff;\n\t\t\tif (!diff) {\n\t\t\t\ttext.setText(\"\");\n\t\t\t\treturn text;\n\t\t\t}\n\t\t\tconst lines = diff.split(\"\\n\").map((line) => {\n\t\t\t\tif (line.startsWith(\"+\") && !line.startsWith(\"+++\")) return theme.fg(\"success\", line);\n\t\t\t\tif (line.startsWith(\"-\") && !line.startsWith(\"---\")) return theme.fg(\"error\", line);\n\t\t\t\treturn theme.fg(\"dim\", line);\n\t\t\t});\n\t\t\ttext.setText(`\\n${lines.join(\"\\n\")}`);\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\ntype CompatibleEditAgentTool = AgentTool<typeof editSchema, EditToolDetails> & {\n\texecute: (\n\t\ttoolCallId: string,\n\t\tparams: Record<string, unknown>,\n\t\tsignal?: AbortSignal,\n\t\tonUpdate?: AgentToolUpdateCallback<EditToolDetails>,\n\t) => Promise<AgentToolResult<EditToolDetails>>;\n};\n\nexport function createEditTool(operations: ToolOperations, options?: EditToolOptions): CompatibleEditAgentTool {\n\treturn wrapToolDefinition(createEditToolDefinition(operations, options)) as CompatibleEditAgentTool;\n}\n"]}