alchemylab-opencode 1.0.7 → 1.0.9

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 (391) hide show
  1. package/dist/{chunk-B3FN2B2N.js → chunk-3PZZ2D23.js} +7 -3
  2. package/dist/chunk-3PZZ2D23.js.map +7 -0
  3. package/dist/{chunk-LU5XVQUD.js → chunk-EGZMJTLE.js} +7 -7
  4. package/dist/{chunk-LU5XVQUD.js.map → chunk-EGZMJTLE.js.map} +2 -2
  5. package/dist/{chunk-23UYOGZG.js → chunk-ORHZOVWK.js} +6 -6
  6. package/dist/{chunk-TASPMBUL.js → chunk-SV5NEV33.js} +5 -5
  7. package/dist/{chunk-SM6WZDN6.js → chunk-UKQIL5XA.js} +18 -12
  8. package/dist/chunk-UKQIL5XA.js.map +7 -0
  9. package/dist/{chunk-GSE2T5UY.js → chunk-ZFHDPNFZ.js} +4 -4
  10. package/dist/{mcp-XFGN3FWW.js → mcp-66BBNSWA.js} +3 -3
  11. package/dist/{registry-W4MBVBYD.js → registry-YVL3V6Z6.js} +4 -4
  12. package/dist/{run-73HUV4H3.js → run-65PIGE2A.js} +7 -7
  13. package/dist/{run-service-LHEVFBIU.js → run-service-AYATGPA6.js} +2 -2
  14. package/dist/run.js +1 -1
  15. package/dist/serve.js +1 -1
  16. package/dist/{server-2CPOG3LS.js → server-KCG3B4WQ.js} +7 -7
  17. package/dist/{session-M6HOZ56B.js → session-BR5MTI3X.js} +4 -4
  18. package/dist/{share-next-QRBVSD37.js → share-next-EPYQDJ32.js} +5 -5
  19. package/dist/{worktree-3GUHT2P7.js → worktree-PIVTZBUE.js} +6 -6
  20. package/package.json +2 -15
  21. package/packages/opencode/migration/20260409000000_add_session_metadata/migration.sql +1 -0
  22. package/build.mjs +0 -192
  23. package/dist/chunk-B3FN2B2N.js.map +0 -7
  24. package/dist/chunk-SM6WZDN6.js.map +0 -7
  25. package/packages/opencode/package.json +0 -138
  26. package/packages/opencode/src/account/account.sql.ts +0 -39
  27. package/packages/opencode/src/account/index.ts +0 -463
  28. package/packages/opencode/src/account/repo.ts +0 -163
  29. package/packages/opencode/src/account/schema.ts +0 -91
  30. package/packages/opencode/src/acp/README.md +0 -174
  31. package/packages/opencode/src/acp/agent.ts +0 -1847
  32. package/packages/opencode/src/acp/session.ts +0 -116
  33. package/packages/opencode/src/acp/types.ts +0 -24
  34. package/packages/opencode/src/agent/agent.ts +0 -420
  35. package/packages/opencode/src/agent/generate.txt +0 -75
  36. package/packages/opencode/src/agent/prompt/compaction.txt +0 -15
  37. package/packages/opencode/src/agent/prompt/explore.txt +0 -18
  38. package/packages/opencode/src/agent/prompt/summary.txt +0 -11
  39. package/packages/opencode/src/agent/prompt/title.txt +0 -44
  40. package/packages/opencode/src/auth/index.ts +0 -110
  41. package/packages/opencode/src/bus/bus-event.ts +0 -40
  42. package/packages/opencode/src/bus/global.ts +0 -10
  43. package/packages/opencode/src/bus/index.ts +0 -185
  44. package/packages/opencode/src/cli/bootstrap.ts +0 -17
  45. package/packages/opencode/src/cli/cmd/cmd.ts +0 -7
  46. package/packages/opencode/src/cli/cmd/run.ts +0 -689
  47. package/packages/opencode/src/cli/cmd/serve.ts +0 -24
  48. package/packages/opencode/src/cli/cmd/tui/event.ts +0 -49
  49. package/packages/opencode/src/cli/effect/prompt.ts +0 -25
  50. package/packages/opencode/src/cli/error.ts +0 -46
  51. package/packages/opencode/src/cli/heap.ts +0 -59
  52. package/packages/opencode/src/cli/logo.ts +0 -6
  53. package/packages/opencode/src/cli/network.ts +0 -60
  54. package/packages/opencode/src/cli/ui.ts +0 -133
  55. package/packages/opencode/src/cli/upgrade.ts +0 -31
  56. package/packages/opencode/src/command/index.ts +0 -195
  57. package/packages/opencode/src/command/template/initialize.txt +0 -66
  58. package/packages/opencode/src/command/template/review.txt +0 -101
  59. package/packages/opencode/src/config/config.ts +0 -1599
  60. package/packages/opencode/src/config/console-state.ts +0 -15
  61. package/packages/opencode/src/config/markdown.ts +0 -99
  62. package/packages/opencode/src/config/paths.ts +0 -167
  63. package/packages/opencode/src/config/tui-migrate.ts +0 -155
  64. package/packages/opencode/src/config/tui-schema.ts +0 -37
  65. package/packages/opencode/src/config/tui.ts +0 -179
  66. package/packages/opencode/src/control-plane/adaptors/index.ts +0 -20
  67. package/packages/opencode/src/control-plane/adaptors/worktree.ts +0 -42
  68. package/packages/opencode/src/control-plane/schema.ts +0 -17
  69. package/packages/opencode/src/control-plane/sse.ts +0 -66
  70. package/packages/opencode/src/control-plane/types.ts +0 -32
  71. package/packages/opencode/src/control-plane/workspace.sql.ts +0 -17
  72. package/packages/opencode/src/control-plane/workspace.ts +0 -168
  73. package/packages/opencode/src/effect/cross-spawn-spawner.ts +0 -502
  74. package/packages/opencode/src/effect/instance-ref.ts +0 -6
  75. package/packages/opencode/src/effect/instance-registry.ts +0 -12
  76. package/packages/opencode/src/effect/instance-state.ts +0 -82
  77. package/packages/opencode/src/effect/run-service.ts +0 -33
  78. package/packages/opencode/src/effect/runner.ts +0 -216
  79. package/packages/opencode/src/env/index.ts +0 -28
  80. package/packages/opencode/src/file/ignore.ts +0 -82
  81. package/packages/opencode/src/file/index.ts +0 -686
  82. package/packages/opencode/src/file/protected.ts +0 -59
  83. package/packages/opencode/src/file/ripgrep.ts +0 -376
  84. package/packages/opencode/src/file/time.ts +0 -133
  85. package/packages/opencode/src/file/watcher.ts +0 -173
  86. package/packages/opencode/src/filesystem/index.ts +0 -236
  87. package/packages/opencode/src/flag/flag.ts +0 -156
  88. package/packages/opencode/src/format/formatter.ts +0 -413
  89. package/packages/opencode/src/format/index.ts +0 -203
  90. package/packages/opencode/src/git/index.ts +0 -303
  91. package/packages/opencode/src/global/index.ts +0 -56
  92. package/packages/opencode/src/id/id.ts +0 -85
  93. package/packages/opencode/src/ide/index.ts +0 -74
  94. package/packages/opencode/src/installation/index.ts +0 -355
  95. package/packages/opencode/src/installation/meta.ts +0 -7
  96. package/packages/opencode/src/lsp/client.ts +0 -252
  97. package/packages/opencode/src/lsp/index.ts +0 -558
  98. package/packages/opencode/src/lsp/language.ts +0 -120
  99. package/packages/opencode/src/lsp/launch.ts +0 -21
  100. package/packages/opencode/src/lsp/server.ts +0 -1968
  101. package/packages/opencode/src/mcp/auth.ts +0 -173
  102. package/packages/opencode/src/mcp/index.ts +0 -931
  103. package/packages/opencode/src/mcp/oauth-callback.ts +0 -216
  104. package/packages/opencode/src/mcp/oauth-provider.ts +0 -185
  105. package/packages/opencode/src/node-loader.mjs +0 -104
  106. package/packages/opencode/src/node-preload.mjs +0 -39
  107. package/packages/opencode/src/node.ts +0 -1
  108. package/packages/opencode/src/npm/index.ts +0 -188
  109. package/packages/opencode/src/patch/index.ts +0 -680
  110. package/packages/opencode/src/permission/arity.ts +0 -163
  111. package/packages/opencode/src/permission/evaluate.ts +0 -15
  112. package/packages/opencode/src/permission/index.ts +0 -325
  113. package/packages/opencode/src/permission/schema.ts +0 -17
  114. package/packages/opencode/src/plugin/cloudflare.ts +0 -67
  115. package/packages/opencode/src/plugin/codex.ts +0 -608
  116. package/packages/opencode/src/plugin/github-copilot/copilot.ts +0 -361
  117. package/packages/opencode/src/plugin/github-copilot/models.ts +0 -144
  118. package/packages/opencode/src/plugin/index.ts +0 -299
  119. package/packages/opencode/src/plugin/install.ts +0 -439
  120. package/packages/opencode/src/plugin/loader.ts +0 -174
  121. package/packages/opencode/src/plugin/meta.ts +0 -188
  122. package/packages/opencode/src/plugin/shared.ts +0 -323
  123. package/packages/opencode/src/project/bootstrap.ts +0 -31
  124. package/packages/opencode/src/project/instance.ts +0 -175
  125. package/packages/opencode/src/project/project.sql.ts +0 -16
  126. package/packages/opencode/src/project/project.ts +0 -519
  127. package/packages/opencode/src/project/schema.ts +0 -16
  128. package/packages/opencode/src/project/state.ts +0 -70
  129. package/packages/opencode/src/project/vcs.ts +0 -240
  130. package/packages/opencode/src/provider/auth.ts +0 -253
  131. package/packages/opencode/src/provider/error.ts +0 -197
  132. package/packages/opencode/src/provider/models.ts +0 -162
  133. package/packages/opencode/src/provider/provider.ts +0 -1709
  134. package/packages/opencode/src/provider/schema.ts +0 -38
  135. package/packages/opencode/src/provider/sdk/copilot/README.md +0 -5
  136. package/packages/opencode/src/provider/sdk/copilot/chat/convert-to-openai-compatible-chat-messages.ts +0 -170
  137. package/packages/opencode/src/provider/sdk/copilot/chat/get-response-metadata.ts +0 -15
  138. package/packages/opencode/src/provider/sdk/copilot/chat/map-openai-compatible-finish-reason.ts +0 -19
  139. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-api-types.ts +0 -64
  140. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-language-model.ts +0 -815
  141. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-chat-options.ts +0 -28
  142. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-metadata-extractor.ts +0 -44
  143. package/packages/opencode/src/provider/sdk/copilot/chat/openai-compatible-prepare-tools.ts +0 -83
  144. package/packages/opencode/src/provider/sdk/copilot/copilot-provider.ts +0 -100
  145. package/packages/opencode/src/provider/sdk/copilot/index.ts +0 -2
  146. package/packages/opencode/src/provider/sdk/copilot/openai-compatible-error.ts +0 -27
  147. package/packages/opencode/src/provider/sdk/copilot/responses/convert-to-openai-responses-input.ts +0 -335
  148. package/packages/opencode/src/provider/sdk/copilot/responses/map-openai-responses-finish-reason.ts +0 -22
  149. package/packages/opencode/src/provider/sdk/copilot/responses/openai-config.ts +0 -18
  150. package/packages/opencode/src/provider/sdk/copilot/responses/openai-error.ts +0 -22
  151. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-api-types.ts +0 -214
  152. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-language-model.ts +0 -1769
  153. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-prepare-tools.ts +0 -173
  154. package/packages/opencode/src/provider/sdk/copilot/responses/openai-responses-settings.ts +0 -1
  155. package/packages/opencode/src/provider/sdk/copilot/responses/tool/code-interpreter.ts +0 -87
  156. package/packages/opencode/src/provider/sdk/copilot/responses/tool/file-search.ts +0 -127
  157. package/packages/opencode/src/provider/sdk/copilot/responses/tool/image-generation.ts +0 -114
  158. package/packages/opencode/src/provider/sdk/copilot/responses/tool/local-shell.ts +0 -64
  159. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search-preview.ts +0 -103
  160. package/packages/opencode/src/provider/sdk/copilot/responses/tool/web-search.ts +0 -102
  161. package/packages/opencode/src/provider/transform.ts +0 -1050
  162. package/packages/opencode/src/pty/index.ts +0 -397
  163. package/packages/opencode/src/pty/pty.node.ts +0 -27
  164. package/packages/opencode/src/pty/pty.ts +0 -25
  165. package/packages/opencode/src/pty/schema.ts +0 -17
  166. package/packages/opencode/src/question/index.ts +0 -224
  167. package/packages/opencode/src/question/schema.ts +0 -17
  168. package/packages/opencode/src/run.ts +0 -28
  169. package/packages/opencode/src/serve.ts +0 -45
  170. package/packages/opencode/src/server/error.ts +0 -36
  171. package/packages/opencode/src/server/event.ts +0 -7
  172. package/packages/opencode/src/server/instance.ts +0 -324
  173. package/packages/opencode/src/server/mdns.ts +0 -60
  174. package/packages/opencode/src/server/middleware.ts +0 -33
  175. package/packages/opencode/src/server/projectors.ts +0 -28
  176. package/packages/opencode/src/server/proxy.ts +0 -131
  177. package/packages/opencode/src/server/router.ts +0 -105
  178. package/packages/opencode/src/server/routes/config.ts +0 -92
  179. package/packages/opencode/src/server/routes/event.ts +0 -83
  180. package/packages/opencode/src/server/routes/experimental.ts +0 -374
  181. package/packages/opencode/src/server/routes/file.ts +0 -197
  182. package/packages/opencode/src/server/routes/global.ts +0 -312
  183. package/packages/opencode/src/server/routes/mcp.ts +0 -225
  184. package/packages/opencode/src/server/routes/permission.ts +0 -69
  185. package/packages/opencode/src/server/routes/project.ts +0 -118
  186. package/packages/opencode/src/server/routes/provider.ts +0 -171
  187. package/packages/opencode/src/server/routes/pty.ts +0 -210
  188. package/packages/opencode/src/server/routes/question.ts +0 -99
  189. package/packages/opencode/src/server/routes/session.ts +0 -1030
  190. package/packages/opencode/src/server/routes/tui.ts +0 -379
  191. package/packages/opencode/src/server/routes/workspace.ts +0 -94
  192. package/packages/opencode/src/server/server.ts +0 -353
  193. package/packages/opencode/src/session/compaction.ts +0 -428
  194. package/packages/opencode/src/session/index.ts +0 -887
  195. package/packages/opencode/src/session/instruction.ts +0 -258
  196. package/packages/opencode/src/session/llm.ts +0 -354
  197. package/packages/opencode/src/session/message-v2.ts +0 -1031
  198. package/packages/opencode/src/session/message.ts +0 -191
  199. package/packages/opencode/src/session/overflow.ts +0 -22
  200. package/packages/opencode/src/session/processor.ts +0 -523
  201. package/packages/opencode/src/session/projectors.ts +0 -135
  202. package/packages/opencode/src/session/prompt/anthropic.txt +0 -105
  203. package/packages/opencode/src/session/prompt/beast.txt +0 -147
  204. package/packages/opencode/src/session/prompt/build-switch.txt +0 -5
  205. package/packages/opencode/src/session/prompt/codex.txt +0 -79
  206. package/packages/opencode/src/session/prompt/copilot-gpt-5.txt +0 -143
  207. package/packages/opencode/src/session/prompt/default.txt +0 -105
  208. package/packages/opencode/src/session/prompt/gemini.txt +0 -155
  209. package/packages/opencode/src/session/prompt/gpt.txt +0 -107
  210. package/packages/opencode/src/session/prompt/kimi.txt +0 -95
  211. package/packages/opencode/src/session/prompt/max-steps.txt +0 -16
  212. package/packages/opencode/src/session/prompt/plan-reminder-anthropic.txt +0 -67
  213. package/packages/opencode/src/session/prompt/plan.txt +0 -26
  214. package/packages/opencode/src/session/prompt/trinity.txt +0 -97
  215. package/packages/opencode/src/session/prompt.ts +0 -1911
  216. package/packages/opencode/src/session/retry.ts +0 -106
  217. package/packages/opencode/src/session/revert.ts +0 -176
  218. package/packages/opencode/src/session/schema.ts +0 -38
  219. package/packages/opencode/src/session/session.sql.ts +0 -103
  220. package/packages/opencode/src/session/status.ts +0 -102
  221. package/packages/opencode/src/session/summary.ts +0 -177
  222. package/packages/opencode/src/session/system.ts +0 -76
  223. package/packages/opencode/src/session/todo.ts +0 -95
  224. package/packages/opencode/src/share/share-next.ts +0 -369
  225. package/packages/opencode/src/share/share.sql.ts +0 -13
  226. package/packages/opencode/src/shell/shell.ts +0 -110
  227. package/packages/opencode/src/skill/discovery.ts +0 -116
  228. package/packages/opencode/src/skill/index.ts +0 -277
  229. package/packages/opencode/src/snapshot/index.ts +0 -726
  230. package/packages/opencode/src/sql.d.ts +0 -4
  231. package/packages/opencode/src/storage/db.node.ts +0 -8
  232. package/packages/opencode/src/storage/db.ts +0 -177
  233. package/packages/opencode/src/storage/json-migration.ts +0 -425
  234. package/packages/opencode/src/storage/schema.sql.ts +0 -10
  235. package/packages/opencode/src/storage/schema.ts +0 -5
  236. package/packages/opencode/src/storage/storage.ts +0 -353
  237. package/packages/opencode/src/sync/README.md +0 -179
  238. package/packages/opencode/src/sync/event.sql.ts +0 -16
  239. package/packages/opencode/src/sync/index.ts +0 -263
  240. package/packages/opencode/src/sync/schema.ts +0 -14
  241. package/packages/opencode/src/tool/apply_patch.ts +0 -281
  242. package/packages/opencode/src/tool/apply_patch.txt +0 -33
  243. package/packages/opencode/src/tool/bash.ts +0 -496
  244. package/packages/opencode/src/tool/bash.txt +0 -117
  245. package/packages/opencode/src/tool/batch.ts +0 -183
  246. package/packages/opencode/src/tool/batch.txt +0 -24
  247. package/packages/opencode/src/tool/codesearch.ts +0 -132
  248. package/packages/opencode/src/tool/codesearch.txt +0 -12
  249. package/packages/opencode/src/tool/edit.ts +0 -667
  250. package/packages/opencode/src/tool/edit.txt +0 -10
  251. package/packages/opencode/src/tool/external-directory.ts +0 -46
  252. package/packages/opencode/src/tool/glob.ts +0 -78
  253. package/packages/opencode/src/tool/glob.txt +0 -6
  254. package/packages/opencode/src/tool/grep.ts +0 -156
  255. package/packages/opencode/src/tool/grep.txt +0 -8
  256. package/packages/opencode/src/tool/invalid.ts +0 -17
  257. package/packages/opencode/src/tool/ls.ts +0 -121
  258. package/packages/opencode/src/tool/ls.txt +0 -1
  259. package/packages/opencode/src/tool/lsp.ts +0 -97
  260. package/packages/opencode/src/tool/lsp.txt +0 -19
  261. package/packages/opencode/src/tool/multiedit.ts +0 -46
  262. package/packages/opencode/src/tool/multiedit.txt +0 -41
  263. package/packages/opencode/src/tool/plan-enter.txt +0 -14
  264. package/packages/opencode/src/tool/plan-exit.txt +0 -13
  265. package/packages/opencode/src/tool/plan.ts +0 -131
  266. package/packages/opencode/src/tool/question.ts +0 -46
  267. package/packages/opencode/src/tool/question.txt +0 -10
  268. package/packages/opencode/src/tool/read.ts +0 -332
  269. package/packages/opencode/src/tool/read.txt +0 -14
  270. package/packages/opencode/src/tool/registry.ts +0 -265
  271. package/packages/opencode/src/tool/schema.ts +0 -17
  272. package/packages/opencode/src/tool/skill.ts +0 -105
  273. package/packages/opencode/src/tool/task.ts +0 -166
  274. package/packages/opencode/src/tool/task.txt +0 -60
  275. package/packages/opencode/src/tool/todo.ts +0 -48
  276. package/packages/opencode/src/tool/todowrite.txt +0 -167
  277. package/packages/opencode/src/tool/tool.ts +0 -112
  278. package/packages/opencode/src/tool/truncate.ts +0 -144
  279. package/packages/opencode/src/tool/truncation-dir.ts +0 -4
  280. package/packages/opencode/src/tool/webfetch.ts +0 -206
  281. package/packages/opencode/src/tool/webfetch.txt +0 -13
  282. package/packages/opencode/src/tool/websearch.ts +0 -150
  283. package/packages/opencode/src/tool/websearch.txt +0 -14
  284. package/packages/opencode/src/tool/write.ts +0 -84
  285. package/packages/opencode/src/tool/write.txt +0 -8
  286. package/packages/opencode/src/util/abort.ts +0 -35
  287. package/packages/opencode/src/util/archive.ts +0 -17
  288. package/packages/opencode/src/util/color.ts +0 -19
  289. package/packages/opencode/src/util/context.ts +0 -25
  290. package/packages/opencode/src/util/data-url.ts +0 -9
  291. package/packages/opencode/src/util/defer.ts +0 -12
  292. package/packages/opencode/src/util/effect-http-client.ts +0 -11
  293. package/packages/opencode/src/util/effect-zod.ts +0 -98
  294. package/packages/opencode/src/util/error.ts +0 -77
  295. package/packages/opencode/src/util/filesystem.ts +0 -245
  296. package/packages/opencode/src/util/flock.ts +0 -333
  297. package/packages/opencode/src/util/fn.ts +0 -21
  298. package/packages/opencode/src/util/format.ts +0 -20
  299. package/packages/opencode/src/util/glob.ts +0 -34
  300. package/packages/opencode/src/util/hash.ts +0 -7
  301. package/packages/opencode/src/util/iife.ts +0 -3
  302. package/packages/opencode/src/util/keybind.ts +0 -103
  303. package/packages/opencode/src/util/lazy.ts +0 -23
  304. package/packages/opencode/src/util/locale.ts +0 -81
  305. package/packages/opencode/src/util/lock.ts +0 -98
  306. package/packages/opencode/src/util/log.ts +0 -182
  307. package/packages/opencode/src/util/network.ts +0 -9
  308. package/packages/opencode/src/util/process.ts +0 -176
  309. package/packages/opencode/src/util/queue.ts +0 -32
  310. package/packages/opencode/src/util/record.ts +0 -3
  311. package/packages/opencode/src/util/rpc.ts +0 -66
  312. package/packages/opencode/src/util/schema.ts +0 -53
  313. package/packages/opencode/src/util/scrap.ts +0 -10
  314. package/packages/opencode/src/util/signal.ts +0 -12
  315. package/packages/opencode/src/util/timeout.ts +0 -14
  316. package/packages/opencode/src/util/token.ts +0 -7
  317. package/packages/opencode/src/util/update-schema.ts +0 -13
  318. package/packages/opencode/src/util/which.ts +0 -14
  319. package/packages/opencode/src/util/wildcard.ts +0 -59
  320. package/packages/opencode/src/worktree/index.ts +0 -612
  321. package/packages/plugin/package.json +0 -38
  322. package/packages/plugin/src/example.ts +0 -18
  323. package/packages/plugin/src/index.ts +0 -282
  324. package/packages/plugin/src/shell.ts +0 -136
  325. package/packages/plugin/src/tool.ts +0 -38
  326. package/packages/plugin/src/tui.ts +0 -508
  327. package/packages/script/package.json +0 -16
  328. package/packages/script/src/index.ts +0 -77
  329. package/packages/sdk/package.json +0 -33
  330. package/packages/sdk/src/client.ts +0 -55
  331. package/packages/sdk/src/gen/client/client.gen.ts +0 -212
  332. package/packages/sdk/src/gen/client/index.ts +0 -25
  333. package/packages/sdk/src/gen/client/types.gen.ts +0 -222
  334. package/packages/sdk/src/gen/client/utils.gen.ts +0 -287
  335. package/packages/sdk/src/gen/client.gen.ts +0 -22
  336. package/packages/sdk/src/gen/core/auth.gen.ts +0 -41
  337. package/packages/sdk/src/gen/core/bodySerializer.gen.ts +0 -74
  338. package/packages/sdk/src/gen/core/params.gen.ts +0 -144
  339. package/packages/sdk/src/gen/core/pathSerializer.gen.ts +0 -167
  340. package/packages/sdk/src/gen/core/queryKeySerializer.gen.ts +0 -111
  341. package/packages/sdk/src/gen/core/serverSentEvents.gen.ts +0 -210
  342. package/packages/sdk/src/gen/core/types.gen.ts +0 -91
  343. package/packages/sdk/src/gen/core/utils.gen.ts +0 -109
  344. package/packages/sdk/src/gen/sdk.gen.ts +0 -1197
  345. package/packages/sdk/src/gen/types.gen.ts +0 -3904
  346. package/packages/sdk/src/index.ts +0 -21
  347. package/packages/sdk/src/process.ts +0 -31
  348. package/packages/sdk/src/server.ts +0 -134
  349. package/packages/sdk/src/v2/client.ts +0 -81
  350. package/packages/sdk/src/v2/gen/client/client.gen.ts +0 -285
  351. package/packages/sdk/src/v2/gen/client/index.ts +0 -25
  352. package/packages/sdk/src/v2/gen/client/types.gen.ts +0 -202
  353. package/packages/sdk/src/v2/gen/client/utils.gen.ts +0 -289
  354. package/packages/sdk/src/v2/gen/client.gen.ts +0 -18
  355. package/packages/sdk/src/v2/gen/core/auth.gen.ts +0 -41
  356. package/packages/sdk/src/v2/gen/core/bodySerializer.gen.ts +0 -82
  357. package/packages/sdk/src/v2/gen/core/params.gen.ts +0 -169
  358. package/packages/sdk/src/v2/gen/core/pathSerializer.gen.ts +0 -167
  359. package/packages/sdk/src/v2/gen/core/queryKeySerializer.gen.ts +0 -111
  360. package/packages/sdk/src/v2/gen/core/serverSentEvents.gen.ts +0 -239
  361. package/packages/sdk/src/v2/gen/core/types.gen.ts +0 -86
  362. package/packages/sdk/src/v2/gen/core/utils.gen.ts +0 -137
  363. package/packages/sdk/src/v2/gen/sdk.gen.ts +0 -4223
  364. package/packages/sdk/src/v2/gen/types.gen.ts +0 -5265
  365. package/packages/sdk/src/v2/index.ts +0 -21
  366. package/packages/sdk/src/v2/server.ts +0 -134
  367. package/packages/util/package.json +0 -20
  368. package/packages/util/src/array.ts +0 -10
  369. package/packages/util/src/binary.ts +0 -41
  370. package/packages/util/src/encode.ts +0 -51
  371. package/packages/util/src/error.ts +0 -54
  372. package/packages/util/src/fn.ts +0 -11
  373. package/packages/util/src/identifier.ts +0 -48
  374. package/packages/util/src/iife.ts +0 -3
  375. package/packages/util/src/lazy.ts +0 -11
  376. package/packages/util/src/module.ts +0 -10
  377. package/packages/util/src/path.ts +0 -37
  378. package/packages/util/src/retry.ts +0 -41
  379. package/packages/util/src/slug.ts +0 -74
  380. package/postinstall.cjs +0 -55
  381. /package/dist/{chunk-23UYOGZG.js.map → chunk-ORHZOVWK.js.map} +0 -0
  382. /package/dist/{chunk-TASPMBUL.js.map → chunk-SV5NEV33.js.map} +0 -0
  383. /package/dist/{chunk-GSE2T5UY.js.map → chunk-ZFHDPNFZ.js.map} +0 -0
  384. /package/dist/{mcp-XFGN3FWW.js.map → mcp-66BBNSWA.js.map} +0 -0
  385. /package/dist/{registry-W4MBVBYD.js.map → registry-YVL3V6Z6.js.map} +0 -0
  386. /package/dist/{run-73HUV4H3.js.map → run-65PIGE2A.js.map} +0 -0
  387. /package/dist/{run-service-LHEVFBIU.js.map → run-service-AYATGPA6.js.map} +0 -0
  388. /package/dist/{server-2CPOG3LS.js.map → server-KCG3B4WQ.js.map} +0 -0
  389. /package/dist/{session-M6HOZ56B.js.map → session-BR5MTI3X.js.map} +0 -0
  390. /package/dist/{share-next-QRBVSD37.js.map → share-next-EPYQDJ32.js.map} +0 -0
  391. /package/dist/{worktree-3GUHT2P7.js.map → worktree-PIVTZBUE.js.map} +0 -0
@@ -1,667 +0,0 @@
1
- // the approaches in this edit tool are sourced from
2
- // https://github.com/cline/cline/blob/main/evals/diff-edits/diff-apply/diff-06-23-25.ts
3
- // https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/utils/editCorrector.ts
4
- // https://github.com/cline/cline/blob/main/evals/diff-edits/diff-apply/diff-06-26-25.ts
5
-
6
- import z from "zod"
7
- import * as path from "path"
8
- import { Tool } from "./tool"
9
- import { LSP } from "../lsp"
10
- import { createTwoFilesPatch, diffLines } from "diff"
11
- import DESCRIPTION from "./edit.txt"
12
- import { File } from "../file"
13
- import { FileWatcher } from "../file/watcher"
14
- import { Bus } from "../bus"
15
- import { Format } from "../format"
16
- import { FileTime } from "../file/time"
17
- import { Filesystem } from "../util/filesystem"
18
- import { Instance } from "../project/instance"
19
- import { Snapshot } from "@/snapshot"
20
- import { assertExternalDirectory } from "./external-directory"
21
-
22
- const MAX_DIAGNOSTICS_PER_FILE = 20
23
-
24
- function normalizeLineEndings(text: string): string {
25
- return text.replaceAll("\r\n", "\n")
26
- }
27
-
28
- function detectLineEnding(text: string): "\n" | "\r\n" {
29
- return text.includes("\r\n") ? "\r\n" : "\n"
30
- }
31
-
32
- function convertToLineEnding(text: string, ending: "\n" | "\r\n"): string {
33
- if (ending === "\n") return text
34
- return text.replaceAll("\n", "\r\n")
35
- }
36
-
37
- export const EditTool = Tool.define("edit", {
38
- description: DESCRIPTION,
39
- parameters: z.object({
40
- filePath: z.string().describe("The absolute path to the file to modify"),
41
- oldString: z.string().describe("The text to replace"),
42
- newString: z.string().describe("The text to replace it with (must be different from oldString)"),
43
- replaceAll: z.boolean().optional().describe("Replace all occurrences of oldString (default false)"),
44
- }),
45
- async execute(params, ctx) {
46
- if (!params.filePath) {
47
- throw new Error("filePath is required")
48
- }
49
-
50
- if (params.oldString === params.newString) {
51
- throw new Error("No changes to apply: oldString and newString are identical.")
52
- }
53
-
54
- const filePath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
55
- await assertExternalDirectory(ctx, filePath)
56
-
57
- let diff = ""
58
- let contentOld = ""
59
- let contentNew = ""
60
- await FileTime.withLock(filePath, async () => {
61
- if (params.oldString === "") {
62
- const existed = await Filesystem.exists(filePath)
63
- contentNew = params.newString
64
- diff = trimDiff(createTwoFilesPatch(filePath, filePath, contentOld, contentNew))
65
- await ctx.ask({
66
- permission: "edit",
67
- patterns: [path.relative(Instance.worktree, filePath)],
68
- always: ["*"],
69
- metadata: {
70
- filepath: filePath,
71
- diff,
72
- },
73
- })
74
- await Filesystem.write(filePath, params.newString)
75
- await Format.file(filePath)
76
- Bus.publish(File.Event.Edited, { file: filePath })
77
- await Bus.publish(FileWatcher.Event.Updated, {
78
- file: filePath,
79
- event: existed ? "change" : "add",
80
- })
81
- await FileTime.read(ctx.sessionID, filePath)
82
- return
83
- }
84
-
85
- const stats = Filesystem.stat(filePath)
86
- if (!stats) throw new Error(`File ${filePath} not found`)
87
- if (stats.isDirectory()) throw new Error(`Path is a directory, not a file: ${filePath}`)
88
- await FileTime.assert(ctx.sessionID, filePath)
89
- contentOld = await Filesystem.readText(filePath)
90
-
91
- const ending = detectLineEnding(contentOld)
92
- const old = convertToLineEnding(normalizeLineEndings(params.oldString), ending)
93
- const next = convertToLineEnding(normalizeLineEndings(params.newString), ending)
94
-
95
- contentNew = replace(contentOld, old, next, params.replaceAll)
96
-
97
- diff = trimDiff(
98
- createTwoFilesPatch(filePath, filePath, normalizeLineEndings(contentOld), normalizeLineEndings(contentNew)),
99
- )
100
- await ctx.ask({
101
- permission: "edit",
102
- patterns: [path.relative(Instance.worktree, filePath)],
103
- always: ["*"],
104
- metadata: {
105
- filepath: filePath,
106
- diff,
107
- },
108
- })
109
-
110
- await Filesystem.write(filePath, contentNew)
111
- await Format.file(filePath)
112
- Bus.publish(File.Event.Edited, { file: filePath })
113
- await Bus.publish(FileWatcher.Event.Updated, {
114
- file: filePath,
115
- event: "change",
116
- })
117
- contentNew = await Filesystem.readText(filePath)
118
- diff = trimDiff(
119
- createTwoFilesPatch(filePath, filePath, normalizeLineEndings(contentOld), normalizeLineEndings(contentNew)),
120
- )
121
- await FileTime.read(ctx.sessionID, filePath)
122
- })
123
-
124
- const filediff: Snapshot.FileDiff = {
125
- file: filePath,
126
- before: contentOld,
127
- after: contentNew,
128
- additions: 0,
129
- deletions: 0,
130
- }
131
- for (const change of diffLines(contentOld, contentNew)) {
132
- if (change.added) filediff.additions += change.count || 0
133
- if (change.removed) filediff.deletions += change.count || 0
134
- }
135
-
136
- ctx.metadata({
137
- metadata: {
138
- diff,
139
- filediff,
140
- diagnostics: {},
141
- },
142
- })
143
-
144
- let output = "Edit applied successfully."
145
- await LSP.touchFile(filePath, true)
146
- const diagnostics = await LSP.diagnostics()
147
- const normalizedFilePath = Filesystem.normalizePath(filePath)
148
- const issues = diagnostics[normalizedFilePath] ?? []
149
- const errors = issues.filter((item) => item.severity === 1)
150
- if (errors.length > 0) {
151
- const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)
152
- const suffix =
153
- errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
154
- output += `\n\nLSP errors detected in this file, please fix:\n<diagnostics file="${filePath}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`
155
- }
156
-
157
- return {
158
- metadata: {
159
- diagnostics,
160
- diff,
161
- filediff,
162
- },
163
- title: `${path.relative(Instance.worktree, filePath)}`,
164
- output,
165
- }
166
- },
167
- })
168
-
169
- export type Replacer = (content: string, find: string) => Generator<string, void, unknown>
170
-
171
- // Similarity thresholds for block anchor fallback matching
172
- const SINGLE_CANDIDATE_SIMILARITY_THRESHOLD = 0.0
173
- const MULTIPLE_CANDIDATES_SIMILARITY_THRESHOLD = 0.3
174
-
175
- /**
176
- * Levenshtein distance algorithm implementation
177
- */
178
- function levenshtein(a: string, b: string): number {
179
- // Handle empty strings
180
- if (a === "" || b === "") {
181
- return Math.max(a.length, b.length)
182
- }
183
- const matrix = Array.from({ length: a.length + 1 }, (_, i) =>
184
- Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)),
185
- )
186
-
187
- for (let i = 1; i <= a.length; i++) {
188
- for (let j = 1; j <= b.length; j++) {
189
- const cost = a[i - 1] === b[j - 1] ? 0 : 1
190
- matrix[i][j] = Math.min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost)
191
- }
192
- }
193
- return matrix[a.length][b.length]
194
- }
195
-
196
- export const SimpleReplacer: Replacer = function* (_content, find) {
197
- yield find
198
- }
199
-
200
- export const LineTrimmedReplacer: Replacer = function* (content, find) {
201
- const originalLines = content.split("\n")
202
- const searchLines = find.split("\n")
203
-
204
- if (searchLines[searchLines.length - 1] === "") {
205
- searchLines.pop()
206
- }
207
-
208
- for (let i = 0; i <= originalLines.length - searchLines.length; i++) {
209
- let matches = true
210
-
211
- for (let j = 0; j < searchLines.length; j++) {
212
- const originalTrimmed = originalLines[i + j].trim()
213
- const searchTrimmed = searchLines[j].trim()
214
-
215
- if (originalTrimmed !== searchTrimmed) {
216
- matches = false
217
- break
218
- }
219
- }
220
-
221
- if (matches) {
222
- let matchStartIndex = 0
223
- for (let k = 0; k < i; k++) {
224
- matchStartIndex += originalLines[k].length + 1
225
- }
226
-
227
- let matchEndIndex = matchStartIndex
228
- for (let k = 0; k < searchLines.length; k++) {
229
- matchEndIndex += originalLines[i + k].length
230
- if (k < searchLines.length - 1) {
231
- matchEndIndex += 1 // Add newline character except for the last line
232
- }
233
- }
234
-
235
- yield content.substring(matchStartIndex, matchEndIndex)
236
- }
237
- }
238
- }
239
-
240
- export const BlockAnchorReplacer: Replacer = function* (content, find) {
241
- const originalLines = content.split("\n")
242
- const searchLines = find.split("\n")
243
-
244
- if (searchLines.length < 3) {
245
- return
246
- }
247
-
248
- if (searchLines[searchLines.length - 1] === "") {
249
- searchLines.pop()
250
- }
251
-
252
- const firstLineSearch = searchLines[0].trim()
253
- const lastLineSearch = searchLines[searchLines.length - 1].trim()
254
- const searchBlockSize = searchLines.length
255
-
256
- // Collect all candidate positions where both anchors match
257
- const candidates: Array<{ startLine: number; endLine: number }> = []
258
- for (let i = 0; i < originalLines.length; i++) {
259
- if (originalLines[i].trim() !== firstLineSearch) {
260
- continue
261
- }
262
-
263
- // Look for the matching last line after this first line
264
- for (let j = i + 2; j < originalLines.length; j++) {
265
- if (originalLines[j].trim() === lastLineSearch) {
266
- candidates.push({ startLine: i, endLine: j })
267
- break // Only match the first occurrence of the last line
268
- }
269
- }
270
- }
271
-
272
- // Return immediately if no candidates
273
- if (candidates.length === 0) {
274
- return
275
- }
276
-
277
- // Handle single candidate scenario (using relaxed threshold)
278
- if (candidates.length === 1) {
279
- const { startLine, endLine } = candidates[0]
280
- const actualBlockSize = endLine - startLine + 1
281
-
282
- let similarity = 0
283
- let linesToCheck = Math.min(searchBlockSize - 2, actualBlockSize - 2) // Middle lines only
284
-
285
- if (linesToCheck > 0) {
286
- for (let j = 1; j < searchBlockSize - 1 && j < actualBlockSize - 1; j++) {
287
- const originalLine = originalLines[startLine + j].trim()
288
- const searchLine = searchLines[j].trim()
289
- const maxLen = Math.max(originalLine.length, searchLine.length)
290
- if (maxLen === 0) {
291
- continue
292
- }
293
- const distance = levenshtein(originalLine, searchLine)
294
- similarity += (1 - distance / maxLen) / linesToCheck
295
-
296
- // Exit early when threshold is reached
297
- if (similarity >= SINGLE_CANDIDATE_SIMILARITY_THRESHOLD) {
298
- break
299
- }
300
- }
301
- } else {
302
- // No middle lines to compare, just accept based on anchors
303
- similarity = 1.0
304
- }
305
-
306
- if (similarity >= SINGLE_CANDIDATE_SIMILARITY_THRESHOLD) {
307
- let matchStartIndex = 0
308
- for (let k = 0; k < startLine; k++) {
309
- matchStartIndex += originalLines[k].length + 1
310
- }
311
- let matchEndIndex = matchStartIndex
312
- for (let k = startLine; k <= endLine; k++) {
313
- matchEndIndex += originalLines[k].length
314
- if (k < endLine) {
315
- matchEndIndex += 1 // Add newline character except for the last line
316
- }
317
- }
318
- yield content.substring(matchStartIndex, matchEndIndex)
319
- }
320
- return
321
- }
322
-
323
- // Calculate similarity for multiple candidates
324
- let bestMatch: { startLine: number; endLine: number } | null = null
325
- let maxSimilarity = -1
326
-
327
- for (const candidate of candidates) {
328
- const { startLine, endLine } = candidate
329
- const actualBlockSize = endLine - startLine + 1
330
-
331
- let similarity = 0
332
- let linesToCheck = Math.min(searchBlockSize - 2, actualBlockSize - 2) // Middle lines only
333
-
334
- if (linesToCheck > 0) {
335
- for (let j = 1; j < searchBlockSize - 1 && j < actualBlockSize - 1; j++) {
336
- const originalLine = originalLines[startLine + j].trim()
337
- const searchLine = searchLines[j].trim()
338
- const maxLen = Math.max(originalLine.length, searchLine.length)
339
- if (maxLen === 0) {
340
- continue
341
- }
342
- const distance = levenshtein(originalLine, searchLine)
343
- similarity += 1 - distance / maxLen
344
- }
345
- similarity /= linesToCheck // Average similarity
346
- } else {
347
- // No middle lines to compare, just accept based on anchors
348
- similarity = 1.0
349
- }
350
-
351
- if (similarity > maxSimilarity) {
352
- maxSimilarity = similarity
353
- bestMatch = candidate
354
- }
355
- }
356
-
357
- // Threshold judgment
358
- if (maxSimilarity >= MULTIPLE_CANDIDATES_SIMILARITY_THRESHOLD && bestMatch) {
359
- const { startLine, endLine } = bestMatch
360
- let matchStartIndex = 0
361
- for (let k = 0; k < startLine; k++) {
362
- matchStartIndex += originalLines[k].length + 1
363
- }
364
- let matchEndIndex = matchStartIndex
365
- for (let k = startLine; k <= endLine; k++) {
366
- matchEndIndex += originalLines[k].length
367
- if (k < endLine) {
368
- matchEndIndex += 1
369
- }
370
- }
371
- yield content.substring(matchStartIndex, matchEndIndex)
372
- }
373
- }
374
-
375
- export const WhitespaceNormalizedReplacer: Replacer = function* (content, find) {
376
- const normalizeWhitespace = (text: string) => text.replace(/\s+/g, " ").trim()
377
- const normalizedFind = normalizeWhitespace(find)
378
-
379
- // Handle single line matches
380
- const lines = content.split("\n")
381
- for (let i = 0; i < lines.length; i++) {
382
- const line = lines[i]
383
- if (normalizeWhitespace(line) === normalizedFind) {
384
- yield line
385
- } else {
386
- // Only check for substring matches if the full line doesn't match
387
- const normalizedLine = normalizeWhitespace(line)
388
- if (normalizedLine.includes(normalizedFind)) {
389
- // Find the actual substring in the original line that matches
390
- const words = find.trim().split(/\s+/)
391
- if (words.length > 0) {
392
- const pattern = words.map((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("\\s+")
393
- try {
394
- const regex = new RegExp(pattern)
395
- const match = line.match(regex)
396
- if (match) {
397
- yield match[0]
398
- }
399
- } catch (e) {
400
- // Invalid regex pattern, skip
401
- }
402
- }
403
- }
404
- }
405
- }
406
-
407
- // Handle multi-line matches
408
- const findLines = find.split("\n")
409
- if (findLines.length > 1) {
410
- for (let i = 0; i <= lines.length - findLines.length; i++) {
411
- const block = lines.slice(i, i + findLines.length)
412
- if (normalizeWhitespace(block.join("\n")) === normalizedFind) {
413
- yield block.join("\n")
414
- }
415
- }
416
- }
417
- }
418
-
419
- export const IndentationFlexibleReplacer: Replacer = function* (content, find) {
420
- const removeIndentation = (text: string) => {
421
- const lines = text.split("\n")
422
- const nonEmptyLines = lines.filter((line) => line.trim().length > 0)
423
- if (nonEmptyLines.length === 0) return text
424
-
425
- const minIndent = Math.min(
426
- ...nonEmptyLines.map((line) => {
427
- const match = line.match(/^(\s*)/)
428
- return match ? match[1].length : 0
429
- }),
430
- )
431
-
432
- return lines.map((line) => (line.trim().length === 0 ? line : line.slice(minIndent))).join("\n")
433
- }
434
-
435
- const normalizedFind = removeIndentation(find)
436
- const contentLines = content.split("\n")
437
- const findLines = find.split("\n")
438
-
439
- for (let i = 0; i <= contentLines.length - findLines.length; i++) {
440
- const block = contentLines.slice(i, i + findLines.length).join("\n")
441
- if (removeIndentation(block) === normalizedFind) {
442
- yield block
443
- }
444
- }
445
- }
446
-
447
- export const EscapeNormalizedReplacer: Replacer = function* (content, find) {
448
- const unescapeString = (str: string): string => {
449
- return str.replace(/\\(n|t|r|'|"|`|\\|\n|\$)/g, (match, capturedChar) => {
450
- switch (capturedChar) {
451
- case "n":
452
- return "\n"
453
- case "t":
454
- return "\t"
455
- case "r":
456
- return "\r"
457
- case "'":
458
- return "'"
459
- case '"':
460
- return '"'
461
- case "`":
462
- return "`"
463
- case "\\":
464
- return "\\"
465
- case "\n":
466
- return "\n"
467
- case "$":
468
- return "$"
469
- default:
470
- return match
471
- }
472
- })
473
- }
474
-
475
- const unescapedFind = unescapeString(find)
476
-
477
- // Try direct match with unescaped find string
478
- if (content.includes(unescapedFind)) {
479
- yield unescapedFind
480
- }
481
-
482
- // Also try finding escaped versions in content that match unescaped find
483
- const lines = content.split("\n")
484
- const findLines = unescapedFind.split("\n")
485
-
486
- for (let i = 0; i <= lines.length - findLines.length; i++) {
487
- const block = lines.slice(i, i + findLines.length).join("\n")
488
- const unescapedBlock = unescapeString(block)
489
-
490
- if (unescapedBlock === unescapedFind) {
491
- yield block
492
- }
493
- }
494
- }
495
-
496
- export const MultiOccurrenceReplacer: Replacer = function* (content, find) {
497
- // This replacer yields all exact matches, allowing the replace function
498
- // to handle multiple occurrences based on replaceAll parameter
499
- let startIndex = 0
500
-
501
- while (true) {
502
- const index = content.indexOf(find, startIndex)
503
- if (index === -1) break
504
-
505
- yield find
506
- startIndex = index + find.length
507
- }
508
- }
509
-
510
- export const TrimmedBoundaryReplacer: Replacer = function* (content, find) {
511
- const trimmedFind = find.trim()
512
-
513
- if (trimmedFind === find) {
514
- // Already trimmed, no point in trying
515
- return
516
- }
517
-
518
- // Try to find the trimmed version
519
- if (content.includes(trimmedFind)) {
520
- yield trimmedFind
521
- }
522
-
523
- // Also try finding blocks where trimmed content matches
524
- const lines = content.split("\n")
525
- const findLines = find.split("\n")
526
-
527
- for (let i = 0; i <= lines.length - findLines.length; i++) {
528
- const block = lines.slice(i, i + findLines.length).join("\n")
529
-
530
- if (block.trim() === trimmedFind) {
531
- yield block
532
- }
533
- }
534
- }
535
-
536
- export const ContextAwareReplacer: Replacer = function* (content, find) {
537
- const findLines = find.split("\n")
538
- if (findLines.length < 3) {
539
- // Need at least 3 lines to have meaningful context
540
- return
541
- }
542
-
543
- // Remove trailing empty line if present
544
- if (findLines[findLines.length - 1] === "") {
545
- findLines.pop()
546
- }
547
-
548
- const contentLines = content.split("\n")
549
-
550
- // Extract first and last lines as context anchors
551
- const firstLine = findLines[0].trim()
552
- const lastLine = findLines[findLines.length - 1].trim()
553
-
554
- // Find blocks that start and end with the context anchors
555
- for (let i = 0; i < contentLines.length; i++) {
556
- if (contentLines[i].trim() !== firstLine) continue
557
-
558
- // Look for the matching last line
559
- for (let j = i + 2; j < contentLines.length; j++) {
560
- if (contentLines[j].trim() === lastLine) {
561
- // Found a potential context block
562
- const blockLines = contentLines.slice(i, j + 1)
563
- const block = blockLines.join("\n")
564
-
565
- // Check if the middle content has reasonable similarity
566
- // (simple heuristic: at least 50% of non-empty lines should match when trimmed)
567
- if (blockLines.length === findLines.length) {
568
- let matchingLines = 0
569
- let totalNonEmptyLines = 0
570
-
571
- for (let k = 1; k < blockLines.length - 1; k++) {
572
- const blockLine = blockLines[k].trim()
573
- const findLine = findLines[k].trim()
574
-
575
- if (blockLine.length > 0 || findLine.length > 0) {
576
- totalNonEmptyLines++
577
- if (blockLine === findLine) {
578
- matchingLines++
579
- }
580
- }
581
- }
582
-
583
- if (totalNonEmptyLines === 0 || matchingLines / totalNonEmptyLines >= 0.5) {
584
- yield block
585
- break // Only match the first occurrence
586
- }
587
- }
588
- break
589
- }
590
- }
591
- }
592
- }
593
-
594
- export function trimDiff(diff: string): string {
595
- const lines = diff.split("\n")
596
- const contentLines = lines.filter(
597
- (line) =>
598
- (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) &&
599
- !line.startsWith("---") &&
600
- !line.startsWith("+++"),
601
- )
602
-
603
- if (contentLines.length === 0) return diff
604
-
605
- let min = Infinity
606
- for (const line of contentLines) {
607
- const content = line.slice(1)
608
- if (content.trim().length > 0) {
609
- const match = content.match(/^(\s*)/)
610
- if (match) min = Math.min(min, match[1].length)
611
- }
612
- }
613
- if (min === Infinity || min === 0) return diff
614
- const trimmedLines = lines.map((line) => {
615
- if (
616
- (line.startsWith("+") || line.startsWith("-") || line.startsWith(" ")) &&
617
- !line.startsWith("---") &&
618
- !line.startsWith("+++")
619
- ) {
620
- const prefix = line[0]
621
- const content = line.slice(1)
622
- return prefix + content.slice(min)
623
- }
624
- return line
625
- })
626
-
627
- return trimmedLines.join("\n")
628
- }
629
-
630
- export function replace(content: string, oldString: string, newString: string, replaceAll = false): string {
631
- if (oldString === newString) {
632
- throw new Error("No changes to apply: oldString and newString are identical.")
633
- }
634
-
635
- let notFound = true
636
-
637
- for (const replacer of [
638
- SimpleReplacer,
639
- LineTrimmedReplacer,
640
- BlockAnchorReplacer,
641
- WhitespaceNormalizedReplacer,
642
- IndentationFlexibleReplacer,
643
- EscapeNormalizedReplacer,
644
- TrimmedBoundaryReplacer,
645
- ContextAwareReplacer,
646
- MultiOccurrenceReplacer,
647
- ]) {
648
- for (const search of replacer(content, oldString)) {
649
- const index = content.indexOf(search)
650
- if (index === -1) continue
651
- notFound = false
652
- if (replaceAll) {
653
- return content.replaceAll(search, newString)
654
- }
655
- const lastIndex = content.lastIndexOf(search)
656
- if (index !== lastIndex) continue
657
- return content.substring(0, index) + newString + content.substring(index + search.length)
658
- }
659
- }
660
-
661
- if (notFound) {
662
- throw new Error(
663
- "Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.",
664
- )
665
- }
666
- throw new Error("Found multiple matches for oldString. Provide more surrounding context to make the match unique.")
667
- }
@@ -1,10 +0,0 @@
1
- Performs exact string replacements in files.
2
-
3
- Usage:
4
- - You must use your `Read` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
5
- - When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: line number + colon + space (e.g., `1: `). Everything after that space is the actual file content to match. Never include any part of the line number prefix in the oldString or newString.
6
- - ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
7
- - Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
8
- - The edit will FAIL if `oldString` is not found in the file with an error "oldString not found in content".
9
- - The edit will FAIL if `oldString` is found multiple times in the file with an error "Found multiple matches for oldString. Provide more surrounding lines in oldString to identify the correct match." Either provide a larger string with more surrounding context to make it unique or use `replaceAll` to change every instance of `oldString`.
10
- - Use `replaceAll` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.