pi-agent-ide 0.9.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (900) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +5 -3
  3. package/dist/chunk-2EY3LEZ7.js +1 -0
  4. package/dist/chunk-2QCE7GOV.js +1 -0
  5. package/dist/chunk-3V3OQO5S.js +118 -0
  6. package/dist/chunk-45EJ4762.js +33 -0
  7. package/dist/chunk-4AEYLVSR.js +5 -0
  8. package/dist/chunk-4DLSZYUO.js +1 -0
  9. package/dist/chunk-54EFJYUB.js +1 -0
  10. package/dist/{chunk-5DN2XBVI.js → chunk-5TPYHUJV.js} +1 -1
  11. package/dist/{chunk-KQV2ZXLP.js → chunk-6DC2Q5BI.js} +1 -1
  12. package/dist/chunk-72WO7H5T.js +1 -0
  13. package/dist/chunk-72X24ARV.js +2 -0
  14. package/dist/chunk-AB6RSWMB.js +23 -0
  15. package/dist/chunk-AKUBFJAR.js +1 -0
  16. package/dist/chunk-ASVMQMPX.js +10 -0
  17. package/dist/chunk-BW3XONMZ.js +1 -0
  18. package/dist/{chunk-R2U5WXYR.js → chunk-D23NS4VV.js} +1 -1
  19. package/dist/chunk-DSB6A5P5.js +53 -0
  20. package/dist/chunk-E4V4VNRM.js +3 -0
  21. package/dist/chunk-E6G3UVS7.js +1 -0
  22. package/dist/chunk-E7JBYW43.js +1 -0
  23. package/dist/chunk-FVWMI4GP.js +1 -0
  24. package/dist/chunk-GDIF3WT6.js +12 -0
  25. package/dist/chunk-GNYFA6FS.js +2 -0
  26. package/dist/{chunk-DHOIQZUF.js → chunk-GQXZEOND.js} +1 -1
  27. package/dist/chunk-GT2JPOBM.js +1 -0
  28. package/dist/chunk-GTZOIJCH.js +1 -0
  29. package/dist/chunk-HRZAIZGR.js +1 -0
  30. package/dist/{chunk-H6FEBUAP.js → chunk-HSAGZWPO.js} +1 -1
  31. package/dist/chunk-HUICUICD.js +3 -0
  32. package/dist/{chunk-2DSY4U73.js → chunk-I3G6K7QU.js} +1 -1
  33. package/dist/chunk-IRLWXPL4.js +7 -0
  34. package/dist/chunk-IZTOXSTR.js +6 -0
  35. package/dist/chunk-J5CKSIH7.js +1 -0
  36. package/dist/chunk-JKM4E5VB.js +5 -0
  37. package/dist/chunk-JMCI2ZE2.js +3 -0
  38. package/dist/{chunk-YZTVC7ME.js → chunk-JY63UUC2.js} +1 -1
  39. package/dist/chunk-KJ6HZC6L.js +7 -0
  40. package/dist/chunk-LG22ELG4.js +2 -0
  41. package/dist/chunk-LRAMFOUP.js +37 -0
  42. package/dist/chunk-MJMRV76H.js +1 -0
  43. package/dist/chunk-MMQIHUU5.js +1 -0
  44. package/dist/chunk-MNAIMZRO.js +9 -0
  45. package/dist/chunk-NGWQRV25.js +13 -0
  46. package/dist/chunk-NKI4TZSS.js +2 -0
  47. package/dist/chunk-NWCTAVGR.js +4 -0
  48. package/dist/chunk-O2C3F3MA.js +1 -0
  49. package/dist/chunk-OA26FH5G.js +1 -0
  50. package/dist/chunk-OEEE5BLN.js +16 -0
  51. package/dist/chunk-OLMACWQX.js +11 -0
  52. package/dist/{chunk-72FL5FHZ.js → chunk-PBMHSK6J.js} +1 -1
  53. package/dist/chunk-QC6VFZSB.js +2 -0
  54. package/dist/chunk-QCAGAJHJ.js +1 -0
  55. package/dist/{chunk-P7FUD4WY.js → chunk-QR7JR3P2.js} +1 -1
  56. package/dist/chunk-QSU5AEKW.js +1 -0
  57. package/dist/chunk-R7576HPO.js +25 -0
  58. package/dist/{chunk-B5UJCNQU.js → chunk-RNDSWVJF.js} +1 -1
  59. package/dist/chunk-S4GTWS2J.js +6 -0
  60. package/dist/chunk-SF44YQCB.js +2 -0
  61. package/dist/chunk-SJQGFUXR.js +6 -0
  62. package/dist/chunk-SKHD2QIT.js +1 -0
  63. package/dist/chunk-SKZTIAE4.js +4 -0
  64. package/dist/chunk-SZRC24OB.js +1 -0
  65. package/dist/chunk-T5PXAYWC.js +1 -0
  66. package/dist/chunk-TIZ4QDF3.js +1 -0
  67. package/dist/chunk-UHGHVYAW.js +4 -0
  68. package/dist/chunk-V2LLMBTA.js +1 -0
  69. package/dist/chunk-VB5P3TXJ.js +111 -0
  70. package/dist/chunk-VNG4QPPT.js +12 -0
  71. package/dist/chunk-VNNAVC4S.js +15 -0
  72. package/dist/chunk-VPBGKSFI.js +3 -0
  73. package/dist/chunk-WZ7MNISG.js +5 -0
  74. package/dist/chunk-X4CU7CMR.js +19 -0
  75. package/dist/chunk-X7CHS7JB.js +1 -0
  76. package/dist/chunk-XEPCURYZ.js +1 -0
  77. package/dist/chunk-XKVU6AAS.js +7 -0
  78. package/dist/chunk-XLTAP5YC.js +24 -0
  79. package/dist/chunk-XQMNVPNS.js +1 -0
  80. package/dist/chunk-YI32H7Z2.js +4 -0
  81. package/dist/chunk-YSGPCH52.js +18 -0
  82. package/dist/chunk-ZYG5E3DI.js +9 -0
  83. package/dist/entry-0.js +1 -1
  84. package/dist/entry-12.js +1 -1
  85. package/dist/entry-15.js +1 -1
  86. package/dist/entry-17.js +1 -1
  87. package/dist/entry-18.js +1 -1
  88. package/dist/entry-19.js +1 -1
  89. package/dist/entry-20.js +1 -1
  90. package/dist/entry-21.js +1 -1
  91. package/dist/entry-22.js +1 -1
  92. package/dist/entry-27.js +1 -1
  93. package/dist/entry-28.js +1 -1
  94. package/dist/entry-31.js +2 -2
  95. package/dist/entry-32.js +1 -1
  96. package/dist/entry-33.js +1 -1
  97. package/dist/entry-34.js +1 -1
  98. package/dist/entry-35.js +1 -1
  99. package/dist/entry-36.js +1 -1
  100. package/dist/entry-37.js +1 -1
  101. package/dist/entry-38.js +19 -13
  102. package/dist/entry-4.js +1 -1
  103. package/dist/entry-40.js +1 -1
  104. package/dist/entry-41.js +1 -1
  105. package/dist/entry-43.js +1 -1
  106. package/dist/entry-44.js +1 -1
  107. package/dist/entry-45.js +1 -1
  108. package/dist/entry-48.js +1 -1
  109. package/dist/entry-49.js +1 -1
  110. package/dist/entry-50.js +1 -1
  111. package/dist/entry-51.js +1 -1
  112. package/dist/entry-52.js +1 -1
  113. package/dist/entry-53.js +1 -1
  114. package/dist/entry-54.js +1 -1
  115. package/dist/entry-55.js +1 -1
  116. package/dist/entry-56.js +1 -1
  117. package/dist/entry-57.js +1 -1
  118. package/dist/entry-58.js +1 -1
  119. package/dist/entry-59.js +1 -1
  120. package/dist/entry-60.js +1 -1
  121. package/dist/entry-61.js +1 -1
  122. package/dist/entry-62.js +1 -1
  123. package/dist/entry-63.js +1 -1
  124. package/dist/entry-64.js +1 -1
  125. package/dist/entry-65.js +1 -1
  126. package/dist/entry-66.js +1 -1
  127. package/dist/entry-67.js +1 -1
  128. package/dist/entry-68.js +1 -0
  129. package/dist/entry-69.js +1 -1
  130. package/dist/entry-71.js +1 -1
  131. package/dist/entry-72.js +0 -1
  132. package/dist/entry-73.js +1 -1
  133. package/dist/entry-74.js +1 -1
  134. package/dist/entry-75.js +1 -1
  135. package/dist/entry-76.js +1 -1
  136. package/dist/entry-77.js +1 -1
  137. package/dist/entry-78.js +1 -0
  138. package/dist/entry-79.js +1 -1
  139. package/dist/entry-8.js +1 -1
  140. package/dist/entry-80.js +1 -0
  141. package/dist/entry-81.js +0 -1
  142. package/dist/entry-82.js +1 -1
  143. package/dist/entry-83.js +1 -1
  144. package/dist/entry-84.js +0 -1
  145. package/dist/entry-85.js +1 -1
  146. package/dist/entry-86.js +1 -2
  147. package/dist/entry-87.js +1 -1
  148. package/dist/entry-88.js +1 -1
  149. package/dist/entry-89.js +1 -1
  150. package/dist/entry-90.js +1 -1
  151. package/dist/entry-91.js +1 -3
  152. package/dist/entry-92.js +1 -1
  153. package/dist/entry-93.js +1 -1
  154. package/dist/entry-94.js +1 -1
  155. package/dist/entry-95.js +3 -0
  156. package/dist/entry-96.js +1 -0
  157. package/dist/entry-97.js +1 -0
  158. package/dist/entry-98.js +1 -0
  159. package/dist/pi-agent-ide.js +26 -13
  160. package/docs/agent-guides/ast-search.md +15 -4
  161. package/docs/agent-guides/debugger.md +1 -1
  162. package/docs/agent-guides/git-changes.md +1 -0
  163. package/docs/agent-guides/ssh.md +27 -7
  164. package/docs/agent-guides/terminal.md +4 -0
  165. package/docs/configuration.md +65 -11
  166. package/docs/development.md +4 -0
  167. package/docs/extensions.md +6 -4
  168. package/docs/structured-results.md +29 -15
  169. package/docs/tools.md +95 -29
  170. package/docs/user-hooks.md +1 -1
  171. package/node_modules/pi-agent-doctor/package.json +1 -1
  172. package/node_modules/pi-agent-doctor/src/catalog.ts +2 -0
  173. package/node_modules/pi-agent-doctor/src/executable.ts +1 -1
  174. package/node_modules/pi-agent-documentation/package.json +1 -1
  175. package/node_modules/pi-agent-filesystem/package.json +7 -7
  176. package/node_modules/pi-agent-filesystem/src/file-write-lock.ts +6 -4
  177. package/node_modules/pi-agent-filesystem/src/replace-file.ts +5 -2
  178. package/node_modules/pi-agent-filesystem/src/resolver.ts +26 -10
  179. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  180. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  181. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  182. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  183. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  184. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +56 -65
  185. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +197 -130
  186. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +2 -1
  187. package/node_modules/pi-agent-ide-ast/src/ast-grep-binary.ts +46 -0
  188. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +119 -97
  189. package/node_modules/pi-agent-ide-ast/src/extension.ts +9 -24
  190. package/node_modules/pi-agent-ide-ast/src/outline-page.ts +96 -0
  191. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +42 -78
  192. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +5 -1
  193. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +2 -1
  194. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +24 -5
  195. package/node_modules/pi-agent-ide-ast/src/search-presentation.ts +2 -1
  196. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +406 -200
  197. package/node_modules/pi-agent-ide-ast/src/tool-ast-search.ts +27 -9
  198. package/node_modules/pi-agent-ide-ast/src/tool-outline.ts +191 -0
  199. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  200. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +63 -20
  201. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +1 -0
  202. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +25 -0
  203. package/node_modules/pi-agent-ide-changes/src/changes/git-paths.ts +13 -6
  204. package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +12 -8
  205. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +88 -78
  206. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +29 -3
  207. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  208. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +39 -3
  209. package/node_modules/pi-agent-ide-formatter/src/rustfmt.ts +101 -0
  210. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  211. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  212. package/node_modules/pi-agent-ide-lint/src/catalog.ts +20 -14
  213. package/node_modules/pi-agent-ide-lint/src/registry.ts +2 -2
  214. package/node_modules/pi-agent-ide-lsp/index.ts +15 -88
  215. package/node_modules/pi-agent-ide-lsp/package.json +12 -12
  216. package/node_modules/pi-agent-ide-lsp/src/catalog.ts +21 -9
  217. package/node_modules/pi-agent-ide-lsp/src/lsp/clang-coverage.ts +265 -0
  218. package/node_modules/pi-agent-ide-lsp/src/lsp/clangd-launch.ts +48 -0
  219. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +66 -11
  220. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +514 -207
  221. package/node_modules/pi-agent-ide-lsp/src/lsp/corrected-names.ts +211 -0
  222. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +20 -1
  223. package/node_modules/pi-agent-ide-lsp/src/lsp/files-containing.ts +70 -0
  224. package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +1 -1
  225. package/node_modules/pi-agent-ide-lsp/src/lsp/line-breaks.ts +16 -0
  226. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +60 -16
  227. package/node_modules/pi-agent-ide-lsp/src/lsp/missing-sources.ts +21 -0
  228. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +44 -0
  229. package/node_modules/pi-agent-ide-lsp/src/lsp/position-map.ts +17 -0
  230. package/node_modules/pi-agent-ide-lsp/src/lsp/range-match.ts +49 -0
  231. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +16 -5
  232. package/node_modules/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +7 -1
  233. package/node_modules/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +133 -37
  234. package/node_modules/pi-agent-ide-lsp/src/lsp/shared-servers.ts +164 -13
  235. package/node_modules/pi-agent-ide-lsp/src/lsp/source-changes.ts +18 -6
  236. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +346 -164
  237. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +376 -0
  238. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +6 -0
  239. package/node_modules/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +10 -0
  240. package/node_modules/pi-agent-ide-lsp/src/name-captures.ts +66 -0
  241. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +383 -92
  242. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +305 -77
  243. package/node_modules/pi-agent-ide-lsp/src/tool-lsp-search.ts +33 -11
  244. package/node_modules/pi-agent-image/package.json +2 -2
  245. package/node_modules/pi-agent-image/src/image-converter.ts +13 -2
  246. package/node_modules/pi-agent-invariant/package.json +1 -1
  247. package/node_modules/pi-agent-pdf/package.json +2 -2
  248. package/node_modules/pi-agent-read/package.json +7 -7
  249. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  250. package/node_modules/pi-agent-read/src/api/read-parameters.ts +51 -12
  251. package/node_modules/pi-agent-read/src/api/tools/read.ts +39 -3
  252. package/node_modules/pi-agent-read/src/core/extension.ts +80 -3
  253. package/node_modules/pi-agent-read/src/core/read-core.ts +6 -0
  254. package/node_modules/pi-agent-read/src/core/tools/read/list-result.ts +79 -0
  255. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +45 -4
  256. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +18 -9
  257. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +16 -3
  258. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +37 -9
  259. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +15 -4
  260. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +49 -18
  261. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +158 -51
  262. package/node_modules/pi-agent-resource/package.json +5 -1
  263. package/node_modules/pi-agent-resource/src/file-text-read.ts +86 -0
  264. package/node_modules/pi-agent-resource/src/index.ts +54 -0
  265. package/node_modules/pi-agent-resource/src/json-structured-arguments.ts +131 -0
  266. package/node_modules/pi-agent-resource/src/line-map.ts +750 -0
  267. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  268. package/node_modules/pi-agent-resource/src/resource-scheduler.ts +63 -23
  269. package/node_modules/pi-agent-resource/src/resource.ts +5 -0
  270. package/node_modules/pi-agent-resource/src/result-targets.ts +693 -66
  271. package/node_modules/pi-agent-resource/src/script-calls.ts +21 -0
  272. package/node_modules/pi-agent-resource/src/tool-deadline.ts +199 -0
  273. package/node_modules/pi-agent-resource/src/tool-result.ts +14 -5
  274. package/node_modules/pi-agent-resource/src/unchanged-read.ts +62 -0
  275. package/node_modules/pi-agent-search/package.json +8 -9
  276. package/node_modules/pi-agent-search/runtime/entry-57.js +0 -1
  277. package/node_modules/pi-agent-search/src/api/fuzzy.ts +2 -1
  278. package/node_modules/pi-agent-search/src/api/null-fields.ts +50 -0
  279. package/node_modules/pi-agent-search/src/api/path-list.ts +68 -0
  280. package/node_modules/pi-agent-search/src/api/presentation.ts +2 -1
  281. package/node_modules/pi-agent-search/src/api/search-call-policy.ts +16 -0
  282. package/node_modules/pi-agent-search/src/api/search-capture.ts +56 -0
  283. package/node_modules/pi-agent-search/src/api/search-parameters.ts +26 -4
  284. package/node_modules/pi-agent-search/src/api/search-scope.ts +38 -2
  285. package/node_modules/pi-agent-search/src/api/search.ts +46 -3
  286. package/node_modules/pi-agent-search/src/api/structured-result.ts +96 -25
  287. package/node_modules/pi-agent-search/src/core/extension.ts +75 -42
  288. package/node_modules/pi-agent-search/src/core/search-config.ts +2 -2
  289. package/node_modules/pi-agent-search/src/core/search-core.ts +103 -39
  290. package/node_modules/pi-agent-search-text/index.ts +62 -20
  291. package/node_modules/pi-agent-search-text/package.json +15 -15
  292. package/node_modules/pi-agent-search-text/runtime/entry-59.js +1 -0
  293. package/node_modules/pi-agent-search-text/src/current-matches.ts +314 -0
  294. package/node_modules/pi-agent-search-text/src/file-search.ts +178 -99
  295. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +40 -17
  296. package/node_modules/pi-agent-search-text/src/persisted-result.ts +3 -8
  297. package/node_modules/pi-agent-search-text/src/resolvers.ts +395 -103
  298. package/node_modules/pi-agent-search-text/src/ripgrep.ts +142 -0
  299. package/node_modules/pi-agent-search-text/src/scoped-search.ts +24 -12
  300. package/node_modules/pi-agent-search-text/src/search-backend.ts +333 -108
  301. package/node_modules/pi-agent-search-text/src/search-presentation.ts +6 -0
  302. package/node_modules/pi-agent-search-text/src/search-query.ts +69 -34
  303. package/node_modules/pi-agent-search-text/src/search-recipe.ts +80 -8
  304. package/node_modules/pi-agent-search-text/src/search-renderer.ts +2 -1
  305. package/node_modules/pi-agent-search-text/src/search-result.ts +10 -1
  306. package/node_modules/pi-agent-search-text/src/search-session.ts +449 -58
  307. package/node_modules/pi-agent-search-text/src/tool-file-search.ts +51 -6
  308. package/node_modules/pi-agent-text/package.json +3 -3
  309. package/node_modules/pi-agent-text/runtime/entry-63.js +1 -0
  310. package/node_modules/pi-agent-text/src/index.ts +18 -0
  311. package/node_modules/pi-agent-text/src/line-anchors.ts +211 -0
  312. package/node_modules/pi-agent-text/src/no-final-line-break.ts +12 -0
  313. package/node_modules/pi-agent-text/src/search-highlight.ts +8 -0
  314. package/node_modules/pi-agent-text/src/source-line.ts +7 -1
  315. package/node_modules/pi-agent-text/src/text-anchor.ts +34 -3
  316. package/node_modules/pi-agent-text/src/text-converter.ts +2 -1
  317. package/node_modules/pi-agent-text/src/text-document.ts +9 -23
  318. package/node_modules/pi-agent-text/src/text-target.ts +14 -6
  319. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  320. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-64.js +2 -0
  321. package/node_modules/pi-agent-text-anchor-exact/index.ts +1 -65
  322. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  323. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-65.js +0 -1
  324. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-66.js +2 -0
  325. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +185 -184
  326. package/node_modules/pi-agent-text-anchor-exact/src/anchored-literal-view.ts +122 -0
  327. package/node_modules/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +2 -1
  328. package/node_modules/pi-agent-text-anchor-exact/src/literal-match.ts +359 -0
  329. package/node_modules/pi-agent-text-anchor-exact/src/recovery.ts +1 -0
  330. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +5 -3
  331. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  332. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-67.js +0 -1
  333. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-68.js +2 -0
  334. package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +92 -67
  335. package/node_modules/pi-agent-text-anchor-line-hash/src/range-history.ts +105 -0
  336. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +22 -17
  337. package/node_modules/pi-agent-text-editor/index.ts +0 -10
  338. package/node_modules/pi-agent-text-editor/package.json +37 -26
  339. package/node_modules/pi-agent-text-editor/runtime/entry-84.js +0 -1
  340. package/node_modules/pi-agent-text-editor/runtime/entry-85.js +1 -0
  341. package/node_modules/pi-agent-text-editor/runtime/entry-86.js +1 -0
  342. package/node_modules/pi-agent-text-editor/runtime/entry-88.js +2 -0
  343. package/node_modules/pi-agent-text-editor/src/api/anchor-excerpt.ts +7 -0
  344. package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +2 -1
  345. package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +2 -0
  346. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +40 -8
  347. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -1
  348. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +37 -2
  349. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +2 -2
  350. package/node_modules/pi-agent-text-editor/src/api/native-files.ts +16 -2
  351. package/node_modules/pi-agent-text-editor/src/api/pi-edit-text.ts +82 -0
  352. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +9 -2
  353. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +1 -0
  354. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +13 -2
  355. package/node_modules/pi-agent-text-editor/src/api/text-selector-fields.ts +210 -0
  356. package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -0
  357. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  358. package/node_modules/pi-agent-text-editor/src/core/already-done.ts +123 -0
  359. package/node_modules/pi-agent-text-editor/src/core/anchor-candidates.ts +116 -0
  360. package/node_modules/pi-agent-text-editor/src/core/anchor-preview.ts +32 -0
  361. package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +109 -23
  362. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +19 -5
  363. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +6 -5
  364. package/node_modules/pi-agent-text-editor/src/core/extension.ts +54 -21
  365. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +7 -3
  366. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +14 -5
  367. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +32 -11
  368. package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +67 -38
  369. package/node_modules/pi-agent-text-editor/src/core/file-write-observations.ts +287 -0
  370. package/node_modules/pi-agent-text-editor/src/core/image-write.ts +16 -4
  371. package/node_modules/pi-agent-text-editor/src/core/lookalike-bytes.ts +254 -0
  372. package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +29 -12
  373. package/node_modules/pi-agent-text-editor/src/core/mutation-result/compact-receipt.ts +48 -0
  374. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +2 -1
  375. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +24 -34
  376. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +13 -20
  377. package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +32 -3
  378. package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +36 -2
  379. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +26 -19
  380. package/node_modules/pi-agent-text-editor/src/core/native-snapshot-source.ts +13 -0
  381. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +526 -148
  382. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +28 -3
  383. package/node_modules/pi-agent-text-editor/src/core/read-fragment-resolver.ts +34 -14
  384. package/node_modules/pi-agent-text-editor/src/core/reference-list.ts +95 -0
  385. package/node_modules/pi-agent-text-editor/src/core/result-scope.ts +129 -0
  386. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +20 -8
  387. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +86 -69
  388. package/node_modules/pi-agent-text-editor/src/core/source-aliases.ts +92 -0
  389. package/node_modules/pi-agent-text-editor/src/core/source-change-retry.ts +92 -7
  390. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +2 -0
  391. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +162 -47
  392. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +321 -101
  393. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +206 -134
  394. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -2
  395. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +133 -18
  396. package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +13 -0
  397. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +823 -226
  398. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +51 -1
  399. package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +7 -4
  400. package/node_modules/pi-agent-text-editor/src/tools/display-marker.ts +15 -0
  401. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +268 -159
  402. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +37 -32
  403. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +24 -70
  404. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +23 -36
  405. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +31 -45
  406. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +33 -65
  407. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +80 -42
  408. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +27 -16
  409. package/node_modules/pi-agent-text-editor-renderer/index.ts +0 -14
  410. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  411. package/node_modules/pi-agent-text-editor-renderer/runtime/entry-89.js +2 -0
  412. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +204 -78
  413. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +75 -8
  414. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +4 -1
  415. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -3
  416. package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +44 -30
  417. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +170 -26
  418. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +83 -83
  419. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -6
  420. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  421. package/node_modules/pi-agent-tool-call-interception/runtime/entry-91.js +1 -0
  422. package/node_modules/pi-agent-tool-ui/package.json +3 -3
  423. package/node_modules/pi-agent-tool-ui/runtime/entry-92.js +1 -0
  424. package/node_modules/pi-agent-tool-ui/runtime/entry-93.js +1 -0
  425. package/node_modules/pi-agent-web/index.ts +0 -3
  426. package/node_modules/pi-agent-web/package.json +8 -8
  427. package/node_modules/pi-agent-web/src/search.ts +1 -2
  428. package/node_modules/pi-agent-web-html/package.json +3 -3
  429. package/node_modules/pi-agent-web-html/runtime/entry-95.js +2 -0
  430. package/node_modules/pi-agent-web-image/package.json +4 -4
  431. package/node_modules/pi-agent-web-image/runtime/entry-96.js +2 -0
  432. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  433. package/node_modules/pi-agent-web-pdf/runtime/entry-97.js +2 -0
  434. package/node_modules/pi-agent-web-text/package.json +4 -4
  435. package/node_modules/pi-agent-web-text/runtime/entry-98.js +2 -0
  436. package/package.json +38 -38
  437. package/skills/capture-code-review-rule/SKILL.md +1 -1
  438. package/skills/configure-agent-ide/SKILL.md +1 -1
  439. package/src/api/code-view.ts +0 -2
  440. package/src/api/tool-config/linters.json +1 -0
  441. package/src/api/tool-config/lsp-servers.json +5 -0
  442. package/src/api/tool-config.ts +23 -2
  443. package/src/backend/config.ts +2 -0
  444. package/src/backend/configured-process.ts +1 -0
  445. package/src/backend/dap-java-transport.ts +4 -2
  446. package/src/backend/dap-java-worker.py +11 -4
  447. package/src/backend/dap-node-transport.ts +4 -2
  448. package/src/backend/dap-tcp-transport.ts +2 -3
  449. package/src/backend/debugger-workspace-owner.ts +6 -6
  450. package/src/backend/doctor-probe-worker.py +23 -15
  451. package/src/backend/doctor-workspace.ts +19 -18
  452. package/src/backend/file-transfer.ts +160 -56
  453. package/src/backend/formatter-registration.ts +54 -2
  454. package/src/backend/identity.ts +81 -12
  455. package/src/backend/lsp-file-watchers.ts +7 -9
  456. package/src/backend/lsp-workspace-owner.ts +25 -1
  457. package/src/backend/object-transfer.ts +28 -15
  458. package/src/backend/owned-command.ts +2 -1
  459. package/src/backend/owned-read-command.ts +2 -1
  460. package/src/backend/packaged-source.ts +12 -0
  461. package/src/backend/process-environment.ts +7 -9
  462. package/src/backend/process-metadata.ts +5 -5
  463. package/src/backend/recipe-evidence-worker.py +2 -0
  464. package/src/backend/recipe-evidence.ts +7 -8
  465. package/src/backend/registration.ts +2 -1
  466. package/src/backend/registry.ts +12 -2
  467. package/src/backend/resource-resolver.ts +11 -32
  468. package/src/backend/search-environment.ts +61 -4
  469. package/src/backend/ssh-channel-worker.py +6 -304
  470. package/src/backend/ssh-channel.ts +287 -36
  471. package/src/backend/ssh-connection-loss.ts +123 -0
  472. package/src/backend/ssh-file-stream.ts +216 -0
  473. package/src/backend/ssh-master.ts +443 -0
  474. package/src/backend/ssh-transfer-worker-windows.py +84 -0
  475. package/src/backend/ssh-transfer-worker.py +43 -10
  476. package/src/backend/ssh-transport.ts +238 -24
  477. package/src/backend/ssh-worker.py +7 -728
  478. package/src/backend/ssh.ts +83 -35
  479. package/src/backend/ssh_channel_common.py +68 -0
  480. package/src/backend/ssh_channel_posix.py +324 -0
  481. package/src/backend/ssh_channel_windows.py +527 -0
  482. package/src/backend/ssh_paths.py +23 -0
  483. package/src/backend/ssh_windows_files.py +254 -0
  484. package/src/backend/ssh_worker_common.py +96 -0
  485. package/src/backend/ssh_worker_posix.py +780 -0
  486. package/src/backend/ssh_worker_windows.py +687 -0
  487. package/src/backend/tool-config-access.ts +14 -11
  488. package/src/backend/tool-project.ts +4 -3
  489. package/src/backend/web-browser.ts +2 -3
  490. package/src/backend/web-http.ts +5 -5
  491. package/src/code-view/diagnostic-view.ts +12 -30
  492. package/src/code-view/reference.ts +9 -18
  493. package/src/code-view/source-view.ts +2 -1
  494. package/src/composite/codemode-tool-names.ts +79 -0
  495. package/src/composite/detached-results.ts +25 -6
  496. package/src/composite/ide-alias-rendering.ts +26 -4
  497. package/src/composite/module-labels.ts +2 -2
  498. package/src/composite/module-settings.ts +1 -0
  499. package/src/composite/nested-tool-rendering.ts +70 -24
  500. package/src/composite/output-limits.ts +12 -5
  501. package/src/composite/parallel-tool-guidance.ts +38 -0
  502. package/src/composite/script-values/ast-search.ts +56 -0
  503. package/src/composite/script-values/copy.ts +8 -0
  504. package/src/composite/script-values/delete.ts +5 -0
  505. package/src/composite/script-values/diff.ts +28 -0
  506. package/src/composite/script-values/edit-selection.ts +48 -0
  507. package/src/composite/script-values/failures.ts +170 -0
  508. package/src/composite/script-values/file-receipts.ts +63 -0
  509. package/src/composite/script-values/file-search.ts +10 -0
  510. package/src/composite/script-values/index.ts +55 -0
  511. package/src/composite/script-values/insert.ts +5 -0
  512. package/src/composite/script-values/lsp-search.ts +92 -0
  513. package/src/composite/script-values/match.ts +53 -0
  514. package/src/composite/script-values/move.ts +8 -0
  515. package/src/composite/script-values/path-list.ts +25 -0
  516. package/src/composite/script-values/provider-value.ts +21 -0
  517. package/src/composite/script-values/read.ts +206 -0
  518. package/src/composite/script-values/replace.ts +5 -0
  519. package/src/composite/script-values/result-reference.ts +9 -0
  520. package/src/composite/script-values/search-matches.ts +113 -0
  521. package/src/composite/script-values/search.ts +64 -0
  522. package/src/composite/script-values/semantic-search.ts +8 -0
  523. package/src/composite/script-values/terminal.ts +112 -0
  524. package/src/composite/script-values/text.ts +7 -0
  525. package/src/composite/script-values/types.ts +56 -0
  526. package/src/composite/script-values/undo.ts +5 -0
  527. package/src/composite/script-values/write.ts +8 -0
  528. package/src/composite/settings-panel.ts +18 -2
  529. package/src/composite/text-results.ts +488 -175
  530. package/src/composite/tool-availability.ts +29 -16
  531. package/src/composite/tool-discovery-guidance.ts +97 -0
  532. package/src/documentation/attachment.ts +31 -0
  533. package/src/documentation/extension.ts +6 -2
  534. package/src/documentation/search.ts +1 -7
  535. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  536. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  537. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  538. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  539. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  540. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/file-write-lock.ts +6 -4
  541. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/replace-file.ts +5 -2
  542. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +26 -10
  543. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +0 -3
  544. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  545. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  546. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-95.js +2 -0
  547. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  548. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-96.js +2 -0
  549. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  550. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-97.js +2 -0
  551. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  552. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-98.js +2 -0
  553. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-94.js +2 -0
  554. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +1 -2
  555. package/src/extensions/pi-agent-read/package.json +7 -7
  556. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  557. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +51 -12
  558. package/src/extensions/pi-agent-read/src/api/tools/read.ts +39 -3
  559. package/src/extensions/pi-agent-read/src/core/extension.ts +80 -3
  560. package/src/extensions/pi-agent-read/src/core/read-core.ts +6 -0
  561. package/src/extensions/pi-agent-read/src/core/tools/read/list-result.ts +79 -0
  562. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +45 -4
  563. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +18 -9
  564. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +16 -3
  565. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +37 -9
  566. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +15 -4
  567. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +49 -18
  568. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +158 -51
  569. package/src/extensions/pi-agent-search/package.json +8 -9
  570. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +62 -20
  571. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +15 -15
  572. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-59.js +1 -0
  573. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-62.js +1 -0
  574. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/current-matches.ts +314 -0
  575. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +178 -99
  576. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +40 -17
  577. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/persisted-result.ts +3 -8
  578. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +395 -103
  579. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +142 -0
  580. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +24 -12
  581. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +333 -108
  582. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +6 -0
  583. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +69 -34
  584. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +80 -8
  585. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +2 -1
  586. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +10 -1
  587. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +449 -58
  588. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/tool-file-search.ts +51 -6
  589. package/src/extensions/pi-agent-search/runtime/entry-57.js +0 -1
  590. package/src/extensions/pi-agent-search/runtime/entry-58.js +2 -0
  591. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +2 -1
  592. package/src/extensions/pi-agent-search/src/api/null-fields.ts +50 -0
  593. package/src/extensions/pi-agent-search/src/api/path-list.ts +68 -0
  594. package/src/extensions/pi-agent-search/src/api/presentation.ts +2 -1
  595. package/src/extensions/pi-agent-search/src/api/search-call-policy.ts +16 -0
  596. package/src/extensions/pi-agent-search/src/api/search-capture.ts +56 -0
  597. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +26 -4
  598. package/src/extensions/pi-agent-search/src/api/search-scope.ts +38 -2
  599. package/src/extensions/pi-agent-search/src/api/search.ts +46 -3
  600. package/src/extensions/pi-agent-search/src/api/structured-result.ts +96 -25
  601. package/src/extensions/pi-agent-search/src/core/extension.ts +75 -42
  602. package/src/extensions/pi-agent-search/src/core/search-config.ts +2 -2
  603. package/src/extensions/pi-agent-search/src/core/search-core.ts +103 -39
  604. package/src/extensions/pi-agent-text-editor/index.ts +0 -10
  605. package/src/extensions/pi-agent-text-editor/package.json +37 -26
  606. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  607. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-64.js +2 -0
  608. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +1 -65
  609. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  610. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-65.js +0 -1
  611. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-66.js +2 -0
  612. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +185 -184
  613. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchored-literal-view.ts +122 -0
  614. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +2 -1
  615. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/literal-match.ts +359 -0
  616. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/recovery.ts +1 -0
  617. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +5 -3
  618. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  619. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-67.js +0 -1
  620. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-68.js +2 -0
  621. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +92 -67
  622. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/range-history.ts +105 -0
  623. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +22 -17
  624. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +0 -14
  625. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  626. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-89.js +2 -0
  627. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +204 -78
  628. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +75 -8
  629. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +4 -1
  630. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -3
  631. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +44 -30
  632. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +170 -26
  633. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +83 -83
  634. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -6
  635. package/src/extensions/pi-agent-text-editor/runtime/entry-84.js +0 -1
  636. package/src/extensions/pi-agent-text-editor/runtime/entry-85.js +1 -0
  637. package/src/extensions/pi-agent-text-editor/runtime/entry-86.js +1 -0
  638. package/src/extensions/pi-agent-text-editor/runtime/entry-87.js +1 -0
  639. package/src/extensions/pi-agent-text-editor/runtime/entry-88.js +2 -0
  640. package/src/extensions/pi-agent-text-editor/src/api/anchor-excerpt.ts +7 -0
  641. package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +2 -1
  642. package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +2 -0
  643. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +40 -8
  644. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -1
  645. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +37 -2
  646. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +2 -2
  647. package/src/extensions/pi-agent-text-editor/src/api/native-files.ts +16 -2
  648. package/src/extensions/pi-agent-text-editor/src/api/pi-edit-text.ts +82 -0
  649. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +9 -2
  650. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +1 -0
  651. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +13 -2
  652. package/src/extensions/pi-agent-text-editor/src/api/text-selector-fields.ts +210 -0
  653. package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -0
  654. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  655. package/src/extensions/pi-agent-text-editor/src/core/already-done.ts +123 -0
  656. package/src/extensions/pi-agent-text-editor/src/core/anchor-candidates.ts +116 -0
  657. package/src/extensions/pi-agent-text-editor/src/core/anchor-preview.ts +32 -0
  658. package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +109 -23
  659. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +19 -5
  660. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +6 -5
  661. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +54 -21
  662. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +7 -3
  663. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +14 -5
  664. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +32 -11
  665. package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +67 -38
  666. package/src/extensions/pi-agent-text-editor/src/core/file-write-observations.ts +287 -0
  667. package/src/extensions/pi-agent-text-editor/src/core/image-write.ts +16 -4
  668. package/src/extensions/pi-agent-text-editor/src/core/lookalike-bytes.ts +254 -0
  669. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +29 -12
  670. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/compact-receipt.ts +48 -0
  671. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +2 -1
  672. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +24 -34
  673. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +13 -20
  674. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +32 -3
  675. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +36 -2
  676. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +26 -19
  677. package/src/extensions/pi-agent-text-editor/src/core/native-snapshot-source.ts +13 -0
  678. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +526 -148
  679. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +28 -3
  680. package/src/extensions/pi-agent-text-editor/src/core/read-fragment-resolver.ts +34 -14
  681. package/src/extensions/pi-agent-text-editor/src/core/reference-list.ts +95 -0
  682. package/src/extensions/pi-agent-text-editor/src/core/result-scope.ts +129 -0
  683. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +20 -8
  684. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +86 -69
  685. package/src/extensions/pi-agent-text-editor/src/core/source-aliases.ts +92 -0
  686. package/src/extensions/pi-agent-text-editor/src/core/source-change-retry.ts +92 -7
  687. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +2 -0
  688. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +162 -47
  689. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +321 -101
  690. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +206 -134
  691. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -2
  692. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +133 -18
  693. package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +13 -0
  694. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +823 -226
  695. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +51 -1
  696. package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +7 -4
  697. package/src/extensions/pi-agent-text-editor/src/tools/display-marker.ts +15 -0
  698. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +268 -159
  699. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +37 -32
  700. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +24 -70
  701. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +23 -36
  702. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +31 -45
  703. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +33 -65
  704. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +80 -42
  705. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +27 -16
  706. package/src/pi-agent-ide.ts +41 -32
  707. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  708. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +56 -65
  709. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +197 -130
  710. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +2 -1
  711. package/src/plugins/pi-agent-ide-ast/src/ast-grep-binary.ts +46 -0
  712. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +119 -97
  713. package/src/plugins/pi-agent-ide-ast/src/extension.ts +9 -24
  714. package/src/plugins/pi-agent-ide-ast/src/outline-page.ts +96 -0
  715. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +42 -78
  716. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +5 -1
  717. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +2 -1
  718. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +24 -5
  719. package/src/plugins/pi-agent-ide-ast/src/search-presentation.ts +2 -1
  720. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +406 -200
  721. package/src/plugins/pi-agent-ide-ast/src/tool-ast-search.ts +27 -9
  722. package/src/plugins/pi-agent-ide-ast/src/tool-outline.ts +191 -0
  723. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  724. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +63 -20
  725. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +1 -0
  726. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +25 -0
  727. package/src/plugins/pi-agent-ide-changes/src/changes/git-paths.ts +13 -6
  728. package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +12 -8
  729. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +88 -78
  730. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +29 -3
  731. package/src/plugins/pi-agent-ide-debugger/index.ts +42 -32
  732. package/src/plugins/pi-agent-ide-debugger/src/string-enum.ts +14 -0
  733. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +124 -79
  734. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  735. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +39 -3
  736. package/src/plugins/pi-agent-ide-formatter/src/rustfmt.ts +101 -0
  737. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  738. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  739. package/src/plugins/pi-agent-ide-lint/src/catalog.ts +20 -14
  740. package/src/plugins/pi-agent-ide-lint/src/registry.ts +2 -2
  741. package/src/plugins/pi-agent-ide-lsp/index.ts +15 -88
  742. package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
  743. package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +21 -9
  744. package/src/plugins/pi-agent-ide-lsp/src/lsp/clang-coverage.ts +265 -0
  745. package/src/plugins/pi-agent-ide-lsp/src/lsp/clangd-launch.ts +48 -0
  746. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +66 -11
  747. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +514 -207
  748. package/src/plugins/pi-agent-ide-lsp/src/lsp/corrected-names.ts +211 -0
  749. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +20 -1
  750. package/src/plugins/pi-agent-ide-lsp/src/lsp/files-containing.ts +70 -0
  751. package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +1 -1
  752. package/src/plugins/pi-agent-ide-lsp/src/lsp/line-breaks.ts +16 -0
  753. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +60 -16
  754. package/src/plugins/pi-agent-ide-lsp/src/lsp/missing-sources.ts +21 -0
  755. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +44 -0
  756. package/src/plugins/pi-agent-ide-lsp/src/lsp/position-map.ts +17 -0
  757. package/src/plugins/pi-agent-ide-lsp/src/lsp/range-match.ts +49 -0
  758. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +16 -5
  759. package/src/plugins/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +7 -1
  760. package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +133 -37
  761. package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-servers.ts +164 -13
  762. package/src/plugins/pi-agent-ide-lsp/src/lsp/source-changes.ts +18 -6
  763. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +346 -164
  764. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +376 -0
  765. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +6 -0
  766. package/src/plugins/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +10 -0
  767. package/src/plugins/pi-agent-ide-lsp/src/name-captures.ts +66 -0
  768. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +383 -92
  769. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +305 -77
  770. package/src/plugins/pi-agent-ide-lsp/src/tool-lsp-search.ts +33 -11
  771. package/src/plugins/pi-agent-ide-processes/src/registry.ts +64 -3
  772. package/src/plugins/pi-agent-ide-processes/src/ui.ts +57 -1
  773. package/src/plugins/pi-agent-ide-semantic/src/backend.ts +18 -6
  774. package/src/plugins/pi-agent-ide-semantic/src/vera-backend.ts +16 -9
  775. package/src/plugins/pi-agent-ide-terminal/index.ts +23 -7
  776. package/src/plugins/pi-agent-ide-terminal/src/list.ts +79 -0
  777. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +22 -0
  778. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +3 -0
  779. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +18 -6
  780. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +132 -18
  781. package/src/plugins/pi-agent-ide-terminal/src/search.ts +117 -50
  782. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +94 -10
  783. package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +24 -1
  784. package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +5 -2
  785. package/src/plugins/pi-agent-ide-terminal/src/terminal-text.ts +173 -0
  786. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +266 -112
  787. package/src/plugins/pi-agent-ide-terminal/src/types.ts +6 -1
  788. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +11 -6
  789. package/src/plugins/pi-agent-ide-terminal/src/unix-pty-output.ts +47 -0
  790. package/src/post-edit/gate.ts +16 -1
  791. package/src/semantic/extension.ts +8 -2
  792. package/src/standalone/scoped-api.ts +85 -18
  793. package/src/toolchain/types.ts +4 -0
  794. package/dist/chunk-2AANEKFS.js +0 -1
  795. package/dist/chunk-33U3RUM3.js +0 -12
  796. package/dist/chunk-34IYWKY5.js +0 -1
  797. package/dist/chunk-4CSNQX54.js +0 -23
  798. package/dist/chunk-53IV6EKV.js +0 -1
  799. package/dist/chunk-5AROEOJB.js +0 -1
  800. package/dist/chunk-5D4C225L.js +0 -1
  801. package/dist/chunk-5W6QQZFI.js +0 -2
  802. package/dist/chunk-6W4OJLCJ.js +0 -1
  803. package/dist/chunk-6ZYCTWQE.js +0 -1
  804. package/dist/chunk-756K3LJY.js +0 -1
  805. package/dist/chunk-AMSNDWBT.js +0 -2
  806. package/dist/chunk-APWMLLSE.js +0 -17
  807. package/dist/chunk-BMSAVDRD.js +0 -13
  808. package/dist/chunk-BRJIXNFU.js +0 -5
  809. package/dist/chunk-C2GZLLSP.js +0 -5
  810. package/dist/chunk-ECSMTGVM.js +0 -6
  811. package/dist/chunk-EWTVVPUA.js +0 -11
  812. package/dist/chunk-FBR7ZLLN.js +0 -1
  813. package/dist/chunk-FGN2ZMEN.js +0 -1
  814. package/dist/chunk-FJSYWOE6.js +0 -1
  815. package/dist/chunk-FTECKRK6.js +0 -1
  816. package/dist/chunk-GRZTKMXQ.js +0 -1
  817. package/dist/chunk-HFCHOFLV.js +0 -2
  818. package/dist/chunk-HFF4GY7R.js +0 -3
  819. package/dist/chunk-HJXSEPO7.js +0 -111
  820. package/dist/chunk-HSEDKYH4.js +0 -1
  821. package/dist/chunk-II7AOJNH.js +0 -9
  822. package/dist/chunk-J34VKQGJ.js +0 -1
  823. package/dist/chunk-J6CDIH3S.js +0 -84
  824. package/dist/chunk-JHWLRL4U.js +0 -1
  825. package/dist/chunk-JMQ67UNK.js +0 -3
  826. package/dist/chunk-JRIP33PC.js +0 -13
  827. package/dist/chunk-K5M65CAF.js +0 -1
  828. package/dist/chunk-KJAR2WDO.js +0 -1
  829. package/dist/chunk-KX7MG72M.js +0 -1
  830. package/dist/chunk-L2B4DTVS.js +0 -1
  831. package/dist/chunk-LEKC4GQK.js +0 -5
  832. package/dist/chunk-LIGOOMJS.js +0 -10
  833. package/dist/chunk-LY2UANKU.js +0 -6
  834. package/dist/chunk-M7P7V4WI.js +0 -25
  835. package/dist/chunk-MXLSGMRZ.js +0 -3
  836. package/dist/chunk-N2NEFXHB.js +0 -13
  837. package/dist/chunk-NF74ITWT.js +0 -2
  838. package/dist/chunk-NQYUIQRH.js +0 -1
  839. package/dist/chunk-OCU6NW5Y.js +0 -1
  840. package/dist/chunk-OIEA4QWF.js +0 -4
  841. package/dist/chunk-ON5HDFNL.js +0 -10
  842. package/dist/chunk-P43GGKUC.js +0 -28
  843. package/dist/chunk-PPCWY4BB.js +0 -1
  844. package/dist/chunk-QGXZ4RWX.js +0 -1
  845. package/dist/chunk-S3T5NOSL.js +0 -1
  846. package/dist/chunk-S7E2D5K7.js +0 -5
  847. package/dist/chunk-SIYPD5MM.js +0 -3
  848. package/dist/chunk-STUZZM5B.js +0 -1
  849. package/dist/chunk-T4FTT3U4.js +0 -1
  850. package/dist/chunk-T5ACAOKJ.js +0 -4
  851. package/dist/chunk-TILMPAF2.js +0 -1
  852. package/dist/chunk-TSNY2FSU.js +0 -1
  853. package/dist/chunk-TWJINFQB.js +0 -9
  854. package/dist/chunk-TWQ6ACOI.js +0 -1
  855. package/dist/chunk-UDVVKVG4.js +0 -1
  856. package/dist/chunk-V2D5MLGE.js +0 -1
  857. package/dist/chunk-VDSSAP6Y.js +0 -1
  858. package/dist/chunk-VHYJTAXX.js +0 -1
  859. package/dist/chunk-WCSWQDJ2.js +0 -22
  860. package/dist/chunk-WQTF6Q2X.js +0 -3
  861. package/dist/chunk-XE4W5YTE.js +0 -2
  862. package/dist/chunk-YFPU2LRR.js +0 -23
  863. package/dist/chunk-YLEERRX3.js +0 -33
  864. package/dist/chunk-YOJHCARZ.js +0 -1
  865. package/dist/chunk-YPTDPMK5.js +0 -1
  866. package/docs/agent-guides/editing.md +0 -43
  867. package/docs/agent-guides/search.md +0 -38
  868. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +0 -73
  869. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-63.js +0 -2
  870. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-64.js +0 -1
  871. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-66.js +0 -1
  872. package/node_modules/pi-agent-text-editor/runtime/entry-68.js +0 -1
  873. package/node_modules/pi-agent-text-editor-renderer/runtime/entry-85.js +0 -2
  874. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +0 -2
  875. package/node_modules/pi-agent-tool-ui/runtime/entry-88.js +0 -1
  876. package/node_modules/pi-agent-tool-ui/runtime/entry-89.js +0 -1
  877. package/node_modules/pi-agent-web-html/runtime/entry-91.js +0 -2
  878. package/node_modules/pi-agent-web-image/runtime/entry-92.js +0 -2
  879. package/node_modules/pi-agent-web-pdf/runtime/entry-93.js +0 -2
  880. package/src/composite/search-facts.ts +0 -45
  881. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-91.js +0 -2
  882. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-92.js +0 -2
  883. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-93.js +0 -2
  884. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-94.js +0 -2
  885. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-58.js +0 -2
  886. package/src/extensions/pi-agent-search/runtime/entry-54.js +0 -1
  887. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-63.js +0 -2
  888. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-64.js +0 -1
  889. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-66.js +0 -1
  890. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-85.js +0 -2
  891. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +0 -2
  892. package/src/extensions/pi-agent-text-editor/runtime/entry-68.js +0 -1
  893. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +0 -73
  894. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-54.js +0 -0
  895. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-58.js +0 -0
  896. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-62.js +0 -0
  897. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-text-editor}/runtime/entry-87.js +0 -0
  898. /package/node_modules/{pi-agent-web → pi-agent-text-editor-stale-anchor}/runtime/entry-90.js +0 -0
  899. /package/node_modules/{pi-agent-web-text → pi-agent-web}/runtime/entry-94.js +0 -0
  900. /package/src/extensions/{pi-agent-read/extensions/pi-agent-web → pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor}/runtime/entry-90.js +0 -0
@@ -1,19 +1,17 @@
1
1
  import { requiredValue } from "pi-agent-invariant";
2
+ import { MAX_ANCHOR_EXCERPT_LENGTH, quoteAnchorExcerpt } from "#src/api/anchor-excerpt.ts";
2
3
  import {
3
4
  ResourceError,
4
5
  resourceErrorMetadataOf,
6
+ reportToolEffect,
7
+ resultValueId,
8
+ resultValueReference,
5
9
  type ResourceErrorMetadata,
6
10
  } from "pi-agent-resource";
7
11
  import path from "node:path";
8
12
  import { AsyncLocalStorage } from "node:async_hooks";
9
13
  import type { TextEditCompletion } from "#src/api/edit-completion.ts";
10
- import type {
11
- TextAnchorRecoveryCandidateRange,
12
- TextAnchorRecoveryRange,
13
- TextAnchorRejection,
14
- TextSelectionRange,
15
- TextTarget,
16
- } from "pi-agent-text";
14
+ import type { TextAnchorRejection, TextSelectionRange, TextTarget } from "pi-agent-text";
17
15
 
18
16
  import {
19
17
  type AgentToolResult,
@@ -27,13 +25,17 @@ import {
27
25
  type FileMutationBatchResult,
28
26
  FileMutationResult,
29
27
  type MutationResultPresentation,
28
+ type MutationDiffStatus,
30
29
  type MutationOperationReceipt,
31
30
  } from "#src/api/mutation-result.ts";
32
31
  import {
33
32
  isMutationAnchorValue,
33
+ TextMutationInputError,
34
34
  mutationSource,
35
35
  type TextMutation,
36
+ type TextMutationAnchorField,
36
37
  type TextMutationContext,
38
+ type PairedAnchorStart,
37
39
  type TextMutationEdit,
38
40
  type TextMutationToolRegistration,
39
41
  type TextSemanticMutationResult,
@@ -52,9 +54,21 @@ import { createUnifiedDiff } from "#src/core/mutation-result/diff.ts";
52
54
  import { finalStateLineNumbers } from "#src/core/mutation-result/final-state-fragment.ts";
53
55
  import { imageWriteResult, planImageWrite } from "#src/core/image-write.ts";
54
56
  import { FileMutationAgentResult } from "#src/core/mutation-result/file-mutation-agent-result.ts";
57
+ import { presentAnchorCandidates, type AnchorCandidates } from "#src/core/anchor-candidates.ts";
55
58
  import { readTextAnchorRecovery } from "#src/core/text-anchor-recovery.ts";
56
59
  import { applyTextChanges, TextChangeDocument } from "#src/core/text-change-engine.ts";
57
- import { resolvedTextAnchorType } from "#src/core/text-anchor-registry.ts";
60
+ import {
61
+ resolvedTextAnchorNotice,
62
+ resolvedTextAnchorType,
63
+ TextAnchorResolutionError,
64
+ TextAnchorResourceResolutionError,
65
+ } from "#src/core/text-anchor-registry.ts";
66
+ import {
67
+ describeScope,
68
+ resolveResultScope,
69
+ scopeRangeIndices,
70
+ scopeWindow,
71
+ } from "./result-scope.ts";
58
72
  import { executeTextToolWithBatch } from "#src/core/text-edit-batch-registrar.ts";
59
73
  import { retryWhenSourceChanged, SOURCE_CHANGED } from "#src/core/source-change-retry.ts";
60
74
  import {
@@ -66,14 +80,30 @@ import {
66
80
  attachCommittedMutationTarget,
67
81
  attachWriteTarget,
68
82
  describeUnavailableCopyTarget,
69
- unchangedCopySources,
83
+ isAlreadyDoneMutation,
70
84
  } from "./mutation-result-targets.ts";
85
+ import {
86
+ alreadyDoneFileResult,
87
+ alreadyDoneTargets,
88
+ alreadyDoneToolResult,
89
+ isAlreadyDone,
90
+ } from "./already-done.ts";
71
91
  import { wholeFileResultSource } from "./result-input.ts";
92
+ import { guardWholeFileWrite, type FileWriteObservations } from "./file-write-observations.ts";
93
+ import {
94
+ bindContextAliases,
95
+ canonicalizeContextEdits,
96
+ findSourceAliases,
97
+ type SourceAliases,
98
+ } from "./source-aliases.ts";
72
99
  import { TEXT_SEARCH_ANCHOR_KIND } from "#src/api/plugin-protocol.ts";
100
+ import { checkRawEditingSelectorTypes, sourceSelectors } from "#src/api/text-selector-fields.ts";
73
101
  import { isResultInput, prepareResultTransfer } from "./result-transfer.ts";
102
+ import { expandReferenceList } from "./reference-list.ts";
74
103
  import {
75
104
  contextualizeTextMutationAnchorError,
76
105
  TextMutationAnchorAggregateError,
106
+ TextMutationAnchorCandidatesError,
77
107
  TextMutationAnchorResolutionError,
78
108
  } from "#src/core/text-mutation-anchor-error.ts";
79
109
  import {
@@ -92,16 +122,17 @@ import type {
92
122
  TextEditorCore,
93
123
  TextResourceEditFailure,
94
124
  TextResourceEditOutcome,
125
+ TextResourceEditRequest,
95
126
  TextPresentedLines,
96
127
  TextResourcesEditOutcome,
97
128
  } from "#src/core/text-editor-core.ts";
98
- import { renderTextAnchor, type TextAnchor } from "pi-agent-text";
129
+ import { renderTextAnchor, stripSearchHighlights, type TextAnchor } from "pi-agent-text";
99
130
  import { TextSelectionAnchor } from "#src/api/text-selection-anchor.ts";
100
131
  import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception";
101
132
  import type { Static, TSchema } from "typebox";
102
133
  import { executeWholeFileTool, isWholeFileInvocation } from "#src/core/file-operation-tools.ts";
103
- import { EDITING_GUIDELINES } from "#src/core/editing-guidelines.ts";
104
134
  import { writeAgentResult } from "./write-agent-result.ts";
135
+ import { assertToolCallArgumentsNotBlocked } from "./tool-call-interceptor/coordinator.ts";
105
136
  import { mutationResultSchema, structuredMutation } from "./structured-result.ts";
106
137
  import type { ResultImageStore, ResultTargetStore } from "pi-agent-resource";
107
138
 
@@ -114,6 +145,7 @@ export function createTextTool<TParameters extends TSchema>(
114
145
  resultTargets?: ResultTargetStore,
115
146
  events?: Pick<ExtensionAPI["events"], "emit">,
116
147
  resultImages?: ResultImageStore,
148
+ observations?: FileWriteObservations,
117
149
  ): ToolDefinition<TParameters, FileMutationBatchResult> {
118
150
  const renderer = core.getToolRenderer(definition.name);
119
151
  const initialRenderCall = renderer?.renderCall;
@@ -136,20 +168,23 @@ export function createTextTool<TParameters extends TSchema>(
136
168
  label: definition.name,
137
169
 
138
170
  promptSnippet: definition.promptSnippet,
139
- promptGuidelines: [...EDITING_GUIDELINES, ...(definition.promptGuidelines ?? [])],
171
+ promptGuidelines: definition.promptGuidelines && [...definition.promptGuidelines],
140
172
  description: definition.description,
141
173
  parameters: definition.parameters,
142
174
  outputSchema: mutationResultSchema(definition.name),
143
- // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
144
- prepareArguments: (arguments_) =>
145
- prepareGuardedArguments(
175
+ prepareArguments: (arguments_) => {
176
+ assertToolCallArgumentsNotBlocked(events, arguments_);
177
+ checkRawEditingSelectorTypes(definition.name, arguments_);
178
+ // oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
179
+ return prepareGuardedArguments(
146
180
  definition.parameters,
147
181
  arguments_,
148
182
  definition.source.inherited ? definition.source.field : undefined,
149
183
  getLastResolvedSource(),
150
184
  definition.anchors ?? [],
151
185
  definition.wholeFileOperation !== undefined,
152
- ),
186
+ );
187
+ },
153
188
  ...(renderer?.renderShell !== undefined && { renderShell: renderer.renderShell }),
154
189
  ...(initialRenderCall !== undefined && {
155
190
  renderCall: (...arguments_: Parameters<typeof initialRenderCall>) =>
@@ -162,8 +197,9 @@ export function createTextTool<TParameters extends TSchema>(
162
197
  ),
163
198
  }),
164
199
  async execute(toolCallId, parameters, signal, onUpdate, context) {
200
+ reportToolEffect("not-applied");
165
201
  let plannedEdits: ReadonlyMap<string, TextMutationEdit> | undefined;
166
- const copyPlan = { snapshots: new Map<string, string>(), unchanged: false };
202
+ const unchangedPlan = { snapshots: new Map<string, string>() };
167
203
  const captured = await runNativePostEditScope(
168
204
  core,
169
205
  toolCallId,
@@ -171,6 +207,45 @@ export function createTextTool<TParameters extends TSchema>(
171
207
  captureScriptMutation(core, async () => {
172
208
  const execute = async (): Promise<AgentToolResult<FileMutationBatchResult>> => {
173
209
  let input = asMutationParameters<TParameters>(parameters);
210
+ let expectedWriteContent: string | undefined;
211
+ try {
212
+ definition.validateInput?.(input);
213
+ } catch (error) {
214
+ return failureToolResult(
215
+ mutationSource(definition, input),
216
+ error instanceof TextMutationInputError ? error.code : "INVALID_MUTATION_INPUT",
217
+ errorMessage(error),
218
+ "not-applied",
219
+ );
220
+ }
221
+ // The IDE replaces a value with an id by its reference before the call; a host
222
+ // without its result store cannot, and must not ignore the selector.
223
+ const valueAnchors = (definition.anchors ?? []).filter(
224
+ ({ field }) => resultValueId(input[field]) !== undefined,
225
+ );
226
+ if (valueAnchors.length > 0) {
227
+ try {
228
+ if (resultTargets === undefined)
229
+ throw new Error("Result targets are unavailable.");
230
+ input = {
231
+ ...input,
232
+ ...Object.fromEntries(
233
+ valueAnchors.map(({ field }) => [
234
+ field,
235
+ resultValueReference(resultTargets, input[field], context.cwd),
236
+ ]),
237
+ ),
238
+ };
239
+ } catch (error) {
240
+ signal?.throwIfAborted();
241
+ return failureToolResult(
242
+ "",
243
+ "RESULT_INPUT_REJECTED",
244
+ errorMessage(error),
245
+ "not-applied",
246
+ );
247
+ }
248
+ }
174
249
  if (definition.name === "write") {
175
250
  const written = await writeImageContent(
176
251
  core,
@@ -188,19 +263,42 @@ export function createTextTool<TParameters extends TSchema>(
188
263
  try {
189
264
  if (resultTargets === undefined)
190
265
  throw new Error("Result targets are unavailable.");
191
- if (input.start !== undefined || input.end !== undefined)
192
- throw new Error("Do not combine result targets with start/end.");
193
- const selected = resultTargets.resolve(
194
- input[definition.source.field],
195
- context.cwd,
266
+ const sourceInput: unknown = input[definition.source.field];
267
+ const expanded = Array.isArray(sourceInput)
268
+ ? await expandReferenceList(
269
+ core,
270
+ resultTargets,
271
+ sourceInput,
272
+ context.cwd,
273
+ signal,
274
+ )
275
+ : sourceInput;
276
+ // With selectors, the result is only their scope.
277
+ const scoped = (definition.anchors ?? []).some(
278
+ (anchor) =>
279
+ anchor.sourceField === definition.source.field &&
280
+ isMutationAnchorValue(anchor, input[anchor.field]),
196
281
  );
282
+ if (scoped && Array.isArray(sourceInput) && sourceInput.length > 1)
283
+ throw new Error(
284
+ "A result list cannot be combined with explicit selectors. Omit text selectors to edit every listed target, or pass one result as path to select inside it. No targets were edited.",
285
+ );
286
+ const selected = scoped
287
+ ? resolveResultScope(resultTargets, expanded, context.cwd)
288
+ : resultTargets.resolve(expanded, context.cwd, { forEdit: true });
197
289
  if (!selected.complete)
198
290
  throw new Error(
199
291
  "Incomplete result targets cannot establish a complete edit. Run Search again with a higher limit or a narrower query, then use the complete result.",
200
292
  );
201
- await resultTargets.verify(selected, signal);
202
- if (definition.name === "write" || definition.name === "undo")
293
+ // A whole-file write needs the selected text now. Other edits compare it with
294
+ // the file under the file lock, and a write by another process in between
295
+ // runs the edit again on the current text instead of failing here.
296
+ if (definition.name === "write" || definition.name === "undo") {
297
+ await resultTargets.verify(selected, signal);
203
298
  wholeFileResultSource(selected, definition.name);
299
+ if (definition.name === "write")
300
+ expectedWriteContent = requiredValue(selected.targets[0]).expectedContent;
301
+ }
204
302
  if (selected.targets.length === 0)
205
303
  return {
206
304
  content: [{ type: "text", text: "Empty result target set; no changes." }],
@@ -212,17 +310,17 @@ export function createTextTool<TParameters extends TSchema>(
212
310
  };
213
311
  input = {
214
312
  ...input,
215
- [definition.source.field]: resultTargets.register(
216
- selected.targets,
217
- context.cwd,
218
- selected.complete,
219
- ),
313
+ [definition.source.field]:
314
+ (scoped || Array.isArray(expanded)) &&
315
+ !core.hasMatchingPreEditHandler(definition.name, input)
316
+ ? resultTargets.register(selected.targets, context.cwd, selected.complete)
317
+ : resultTargets.source(expanded, context.cwd),
220
318
  };
221
319
  } catch (error) {
222
320
  signal?.throwIfAborted();
223
321
  return failureToolResult(
224
322
  "",
225
- "RESULT_INPUT_REJECTED",
323
+ resultInputFailureCode(error),
226
324
  errorMessage(error),
227
325
  "not-applied",
228
326
  );
@@ -237,9 +335,29 @@ export function createTextTool<TParameters extends TSchema>(
237
335
  try {
238
336
  if (resultTargets === undefined)
239
337
  throw new Error("Result targets are unavailable.");
338
+ const expanded: Record<string, unknown> = { ...input };
339
+ // Source and destination lists report together, so one call shows every problem.
340
+ const problems: string[] = [];
341
+ for (const field of ["path", "target"]) {
342
+ const value = expanded[field];
343
+ if (!Array.isArray(value)) continue;
344
+ try {
345
+ expanded[field] = await expandReferenceList(
346
+ core,
347
+ resultTargets,
348
+ value,
349
+ context.cwd,
350
+ signal,
351
+ );
352
+ } catch (error) {
353
+ signal?.throwIfAborted();
354
+ problems.push(`${field}: ${errorMessage(error)}`);
355
+ }
356
+ }
357
+ if (problems.length > 0) throw new Error(problems.join("\n"));
240
358
  const prepared = await prepareResultTransfer(
241
359
  definition.name,
242
- input,
360
+ expanded,
243
361
  resultTargets,
244
362
  context.cwd,
245
363
  signal,
@@ -283,7 +401,7 @@ export function createTextTool<TParameters extends TSchema>(
283
401
  signal?.throwIfAborted();
284
402
  return failureToolResult(
285
403
  "",
286
- "RESULT_INPUT_REJECTED",
404
+ resultInputFailureCode(error),
287
405
  errorMessage(error),
288
406
  "not-applied",
289
407
  );
@@ -293,16 +411,16 @@ export function createTextTool<TParameters extends TSchema>(
293
411
  executionDefinition = {
294
412
  ...directDefinition,
295
413
  mutate: async (mutationContext, arguments_) => {
296
- const mutation = await directDefinition.mutate(mutationContext, arguments_);
414
+ const mutation = canonicalizeContextEdits(
415
+ await directDefinition.mutate(mutationContext, arguments_),
416
+ mutationContext,
417
+ );
297
418
  plannedEdits = mutation.edits;
298
- if (definition.name === "copy") {
299
- for (const source of mutation.edits.keys())
300
- copyPlan.snapshots.set(source, mutationContext.documentFor(source).content);
301
- copyPlan.unchanged =
302
- mutation.edits.size > 0 &&
303
- unchangedCopySources(mutation, copyPlan.snapshots).size ===
304
- mutation.edits.size;
305
- }
419
+ for (const source of mutation.edits.keys())
420
+ unchangedPlan.snapshots.set(
421
+ source,
422
+ mutationContext.documentFor(source).content,
423
+ );
306
424
  return mutation;
307
425
  },
308
426
  };
@@ -317,6 +435,8 @@ export function createTextTool<TParameters extends TSchema>(
317
435
  if (queued !== undefined) return queued;
318
436
  if (definition.direct?.matches(input) === true) {
319
437
  try {
438
+ signal?.throwIfAborted();
439
+ reportToolEffect("unknown");
320
440
  const action = await definition.direct.execute(
321
441
  { cwd: context.cwd, ...(signal !== undefined && { signal }) },
322
442
  input,
@@ -365,6 +485,10 @@ export function createTextTool<TParameters extends TSchema>(
365
485
  [TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
366
486
  }),
367
487
  getLastResolvedSource(),
488
+ definition.name === "write"
489
+ ? guardWholeFileWrite(observations, expectedWriteContent)
490
+ : undefined,
491
+ resultTargets,
368
492
  );
369
493
  return directExecute();
370
494
  };
@@ -395,16 +519,7 @@ export function createTextTool<TParameters extends TSchema>(
395
519
  toolCallId,
396
520
  );
397
521
  }
398
- const completedValue =
399
- copyPlan.unchanged && captured.completions.length === 0 && !captured.value.isError
400
- ? {
401
- ...captured.value,
402
- content: [
403
- { type: "text" as const, text: "No changes: destination already has this text." },
404
- ],
405
- details: { ...captured.value.details, effect: "not-applied" as const },
406
- }
407
- : captured.value;
522
+ const completedValue = captured.value;
408
523
  // Live-resource actions have their own receipts, not filesystem editor batches.
409
524
  if (
410
525
  captured.completions.every(
@@ -437,7 +552,7 @@ export function createTextTool<TParameters extends TSchema>(
437
552
  definition.name === "undo",
438
553
  plannedEdits,
439
554
  definition.name === "copy" || definition.name === "move",
440
- copyPlan.snapshots,
555
+ unchangedPlan.snapshots,
441
556
  )
442
557
  : completedValue;
443
558
  return structuredMutation(
@@ -525,8 +640,11 @@ function prepareGuardedArguments<TParameters extends TSchema>(
525
640
  const properties = (schema as { properties?: Record<string, { type?: unknown }> }).properties;
526
641
 
527
642
  // Anchor ownership is asynchronous; defer its source fallback until resources resolve.
528
- const hasExplicitAnchor = anchorFields.some((descriptor) =>
529
- isMutationAnchorValue(descriptor, prepared[descriptor.field]),
643
+ // A value with an id, such as a Search match in Codemode, becomes its RESULT# reference later.
644
+ const hasExplicitAnchor = anchorFields.some(
645
+ (descriptor) =>
646
+ isMutationAnchorValue(descriptor, prepared[descriptor.field]) ||
647
+ resultValueId(prepared[descriptor.field]) !== undefined,
530
648
  );
531
649
  if (
532
650
  sourceField !== undefined &&
@@ -562,6 +680,43 @@ interface ResolvedMutationSources {
562
680
  readonly implicitTargets: ReadonlyMap<string, readonly TextTarget[]>;
563
681
  readonly targets: readonly TextTarget[];
564
682
  readonly resources: readonly string[];
683
+ /** Other names of resources in `resources`, such as a relative path for an absolute one. */
684
+ readonly aliases: SourceAliases;
685
+ /**
686
+ * Selections of `RESULT#` sources passed together with anchors, by source field. The anchors of
687
+ * that field resolve inside these ranges instead of adding to them.
688
+ */
689
+ readonly scopes: ReadonlyMap<string, readonly TextTarget[]>;
690
+ }
691
+
692
+ /** A textual Search source supplies the implicit selection to the active opening selector. */
693
+ export function implicitSourceAnchor(
694
+ definition: TextMutationToolRegistration,
695
+ sourceField: string,
696
+ input: Readonly<Record<string, unknown>>,
697
+ ) {
698
+ const anchors = definition.anchors?.filter((anchor) => anchor.sourceField === sourceField);
699
+ return (
700
+ anchors?.find((anchor) => isMutationAnchorValue(anchor, input[anchor.field])) ?? anchors?.[0]
701
+ );
702
+ }
703
+
704
+ /** Whether a source field holds a result whose selection limits the field's anchors. */
705
+ function isScopedSourceField(
706
+ definition: TextMutationToolRegistration,
707
+ input: Readonly<Record<string, unknown>>,
708
+ field: string,
709
+ ): boolean {
710
+ const value = input[field];
711
+ return (
712
+ typeof value === "string" &&
713
+ value.startsWith("RESULT#") &&
714
+ (definition.anchors ?? []).some(
715
+ (descriptor) =>
716
+ descriptor.sourceField === field &&
717
+ isMutationAnchorValue(descriptor, input[descriptor.field]),
718
+ )
719
+ );
565
720
  }
566
721
 
567
722
  async function resolveMutationSources(
@@ -571,10 +726,12 @@ async function resolveMutationSources(
571
726
  context: { readonly cwd: string; readonly signal?: AbortSignal },
572
727
  lastResolvedSource?: string,
573
728
  ): Promise<ResolvedMutationSources> {
729
+ definition.validateInput?.(input);
574
730
  const expandedByAnchor = new Map<string, readonly TextTarget[]>();
575
731
  const expandedBySourceField = new Map<string, readonly TextTarget[]>();
576
732
  const expandedFromExplicitSource = new Set<string>();
577
733
  const sourceSelections = new Map<string, readonly TextTarget[]>();
734
+ const scopes = new Map<string, readonly TextTarget[]>();
578
735
  const explicitlyScopedSourceFields = new Set<string>();
579
736
  const allKinds = [
580
737
  ...new Set((definition.anchors ?? []).flatMap((descriptor) => descriptor.kinds)),
@@ -623,7 +780,9 @@ async function resolveMutationSources(
623
780
  const expanded = await resolveTargets(explicit, descriptor.field, explicit);
624
781
  if (expanded !== undefined) {
625
782
  expandedFromExplicitSource.add(descriptor.field);
626
- sourceSelections.set(descriptor.field, expanded);
783
+ if (isScopedSourceField(definition, input, descriptor.field))
784
+ scopes.set(descriptor.field, expanded);
785
+ else sourceSelections.set(descriptor.field, expanded);
627
786
  expandedBySourceField.set(
628
787
  descriptor.field,
629
788
  mergeTargets(expandedBySourceField.get(descriptor.field) ?? [], expanded),
@@ -674,9 +833,7 @@ async function resolveMutationSources(
674
833
  const implicitTargets = new Map<string, readonly TextTarget[]>();
675
834
  for (const descriptor of definition.anchors ?? []) {
676
835
  const targets = sourceSelections.get(descriptor.sourceField);
677
- const firstAnchor = definition.anchors?.find(
678
- (anchor) => anchor.sourceField === descriptor.sourceField,
679
- );
836
+ const firstAnchor = implicitSourceAnchor(definition, descriptor.sourceField, input);
680
837
 
681
838
  const hasExplicitAnchor = isMutationAnchorValue(descriptor, input[descriptor.field]);
682
839
  const hasImplicitSourceSelection = expandedFromExplicitSource.has(descriptor.sourceField);
@@ -717,16 +874,42 @@ async function resolveMutationSources(
717
874
  : [source],
718
875
  );
719
876
  }
877
+ // An anchor of a scoped source resolves in each file of the scope, whatever it names itself.
878
+ const scope = scopes.get(descriptor.sourceField);
879
+ if (scope !== undefined && isMutationAnchorValue(descriptor, value))
880
+ anchors.set(descriptor.field, [...new Set(scope.map((target) => target.source))]);
720
881
  }
721
882
  const targets = [...expandedBySourceField.values()]
722
883
  .flat()
723
884
  .reduce<TextTarget[]>((all, target) => mergeTargets(all, [target]), []);
885
+ // One file named differently by its fields and selections (relative, absolute or symlinked)
886
+ // is one resource: edits to it must share a single document.
887
+ const aliases = await findSourceAliases(
888
+ [...fields.values(), ...targets.map((target) => target.source)],
889
+ context.cwd,
890
+ );
891
+ const canonical = (source: string): string => aliases.get(source) ?? source;
892
+ const canonicalTargets = (selected: readonly TextTarget[]): TextTarget[] =>
893
+ selected.reduce<TextTarget[]>(
894
+ (all, target) => mergeTargets(all, [{ ...target, source: canonical(target.source) }]),
895
+ [],
896
+ );
897
+ const resolvedFields = new Map([...fields].map(([field, source]) => [field, canonical(source)]));
898
+ const resolvedTargets = canonicalTargets(targets);
724
899
  return {
725
- fields,
726
- anchors,
727
- implicitTargets,
728
- targets,
729
- resources: [...new Set([...fields.values(), ...targets.map((target) => target.source)])],
900
+ fields: resolvedFields,
901
+ anchors: new Map(
902
+ [...anchors].map(([field, sources]) => [field, [...new Set(sources.map(canonical))]]),
903
+ ),
904
+ implicitTargets: new Map(
905
+ [...implicitTargets].map(([field, selected]) => [field, canonicalTargets(selected)]),
906
+ ),
907
+ targets: resolvedTargets,
908
+ resources: [
909
+ ...new Set([...resolvedFields.values(), ...resolvedTargets.map((target) => target.source)]),
910
+ ],
911
+ aliases,
912
+ scopes: new Map([...scopes].map(([field, selected]) => [field, canonicalTargets(selected)])),
730
913
  };
731
914
  }
732
915
 
@@ -752,7 +935,12 @@ function mergeTargets(left: readonly TextTarget[], right: readonly TextTarget[])
752
935
  target.expectedContent !== undefined &&
753
936
  previous.expectedContent !== target.expectedContent
754
937
  )
755
- throw new Error("Selections refer to different source revisions. Read the source again.");
938
+ // Two references were resolved moments apart while another session wrote the file. Like
939
+ // any changed source, the edit runs again and resolves both on the current text.
940
+ throw Object.assign(
941
+ new Error("Selections refer to different source revisions. Read the source again."),
942
+ { code: SOURCE_CHANGED },
943
+ );
756
944
  const ranges = [...(previous.ranges ?? []), ...(target.ranges ?? [])];
757
945
  merged.set(target.source, {
758
946
  source: target.source,
@@ -781,7 +969,7 @@ function deduplicateRanges(ranges: readonly TextSelectionRange[]): readonly Text
781
969
  }
782
970
 
783
971
  function naturalLineSelection(content: string, lineNumber: number): TextSelectionRange {
784
- const lines = content.split(/\r\n|\r|\n/u);
972
+ const lines = content.split("\n");
785
973
  const line = lines[lineNumber - 1];
786
974
  if (line === undefined) {
787
975
  throw new Error(`Position anchor line ${lineNumber} is outside the source.`);
@@ -831,7 +1019,7 @@ function mergeResolvedAnchors(
831
1019
  throw new Error(`Anchor ${field} selections overlap or are ambiguous.`);
832
1020
  }
833
1021
  }
834
- // A typed source can duplicate an explicit literal's linewise selection.
1022
+ // A typed source can duplicate an explicit selection that carries endpoint ranges.
835
1023
  // Keep the explicit endpoint extent when deduplicating that selection.
836
1024
  const explicitEndpoints = explicitSelection.endpointRanges;
837
1025
  const endpoints =
@@ -859,14 +1047,17 @@ function mergeResolvedAnchors(
859
1047
  }
860
1048
  interface MutationExecutionContext extends TextMutationContext {
861
1049
  resultPresentationFor(source: string): MutationResultPresentation;
1050
+ readonly selectorNotices: readonly { source: string; field: string; notice: string }[];
862
1051
  }
863
1052
 
864
1053
  interface ExecutedTextMutation extends TextMutation {
865
1054
  readonly resultPresentations: ReadonlyMap<string, MutationResultPresentation>;
866
1055
  readonly unchangedWrite?: { readonly source: string; readonly content: string };
1056
+ /** Text of each edited source before the edit, to name targets that already had their text. */
1057
+ readonly snapshots?: ReadonlyMap<string, string>;
867
1058
  }
868
1059
 
869
- function createMutationContext(
1060
+ export function createMutationContext(
870
1061
  definition: TextMutationToolRegistration,
871
1062
  input: Readonly<Record<string, unknown>>,
872
1063
  invocation: { readonly cwd: string; readonly signal?: AbortSignal },
@@ -874,6 +1065,7 @@ function createMutationContext(
874
1065
  texts: ReadonlyMap<string, string>,
875
1066
  resolveResourceAnchor: ResolveResourceTextAnchor,
876
1067
  publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
1068
+ checkSpan?: TextEditorCore["checkSpan"],
877
1069
  ): MutationExecutionContext {
878
1070
  const documents = new Map(
879
1071
  [...texts].map(([source, text]) => [source, new TextChangeDocument(text)]),
@@ -881,6 +1073,24 @@ function createMutationContext(
881
1073
  const anchorCache = new Map<string, Promise<ReadonlyMap<string, TextAnchor>>>();
882
1074
 
883
1075
  const majorAnchorSources = new Set<string>();
1076
+ const selectorNotices: MutationExecutionContext["selectorNotices"][number][] = [];
1077
+ const recordResolvedAnchor = (
1078
+ field: string,
1079
+ source: string,
1080
+ value: string,
1081
+ anchor: TextAnchor,
1082
+ ) => {
1083
+ if (resolvedTextAnchorType(anchor) === "major") majorAnchorSources.add(source);
1084
+ const notice = resolvedTextAnchorNotice(anchor);
1085
+ if (notice !== undefined) selectorNotices.push({ source, field, notice });
1086
+ const rendered = renderTextAnchor(anchor, value, { source, anchor });
1087
+ publishAnchorRenderState?.(field, {
1088
+ kind: "resolved",
1089
+ full: rendered.full,
1090
+ compact: rendered.compact,
1091
+ resolverId: rendered.resolverId,
1092
+ });
1093
+ };
884
1094
  const sourceFor = (field: string): string => {
885
1095
  const source = sources.fields.get(field);
886
1096
 
@@ -890,7 +1100,8 @@ function createMutationContext(
890
1100
 
891
1101
  return source;
892
1102
  };
893
- const documentFor = (source: string): TextChangeDocument => {
1103
+ const documentFor = (requested: string): TextChangeDocument => {
1104
+ const source = sources.aliases.get(requested) ?? requested;
894
1105
  const document = documents.get(source);
895
1106
 
896
1107
  if (document === undefined) {
@@ -899,7 +1110,213 @@ function createMutationContext(
899
1110
 
900
1111
  return document;
901
1112
  };
902
- const resolveAnchors = (field: string): Promise<ReadonlyMap<string, TextAnchor>> => {
1113
+ /** Where each independent selection lies in the scoped source. */
1114
+ const scopedPlacements = new Map<
1115
+ string,
1116
+ { readonly source: string; readonly indices: readonly number[] }
1117
+ >();
1118
+ /** Resolve an anchor inside the selection of the result passed as its source. */
1119
+ const resolveScopedAnchor = async (
1120
+ field: string,
1121
+ descriptor: TextMutationAnchorField,
1122
+ value: string,
1123
+ scope: readonly TextTarget[],
1124
+ start?: PairedAnchorStart,
1125
+ ): Promise<ReadonlyMap<string, TextAnchor>> => {
1126
+ const describe = (target: TextTarget) =>
1127
+ describeScope(target.source, target.ranges ?? [], documentFor(target.source), invocation.cwd);
1128
+ const rejection = (
1129
+ target: TextTarget,
1130
+ code: TextAnchorRejection["code"],
1131
+ reason: string,
1132
+ searchHighlightRetry?: string,
1133
+ ): TextMutationAnchorResolutionError =>
1134
+ new TextMutationAnchorResolutionError(
1135
+ definition.name,
1136
+ field,
1137
+ target.source,
1138
+ value,
1139
+ new TextAnchorResolutionError(reason, "result-scope", undefined, {
1140
+ code,
1141
+ reason,
1142
+ ...(searchHighlightRetry === undefined ? {} : { searchHighlightRetry }),
1143
+ ...((target.ranges ?? []).length > 0 && {
1144
+ contextRange: scopeWindow(target.ranges ?? []),
1145
+ }),
1146
+ }),
1147
+ );
1148
+ const attempts = await Promise.allSettled(
1149
+ scope.map(async (target) => {
1150
+ const ranges = target.ranges ?? [];
1151
+ let anchor: TextAnchor;
1152
+ try {
1153
+ anchor = await resolveResourceAnchor(
1154
+ target.source,
1155
+ value,
1156
+ descriptor.kinds,
1157
+ ranges.length === 0 ? undefined : ranges,
1158
+ start?.source === target.source ? start.offset : undefined,
1159
+ );
1160
+ } catch (error) {
1161
+ // Don't change which literals are ambiguous. Only narrow the suggested retries to
1162
+ // where a closing anchor could pair with this opening anchor.
1163
+ let retryScope: readonly TextSelectionRange[] | undefined;
1164
+ if (start !== undefined) {
1165
+ if (start.source !== target.source) {
1166
+ retryScope = [];
1167
+ } else if (ranges.length > 1) {
1168
+ const opening = [...scopedPlacements].find(
1169
+ ([other, placement]) =>
1170
+ placement.source === start.source &&
1171
+ (definition.anchors ?? []).some(
1172
+ (sibling) =>
1173
+ sibling.field === other && sibling.sourceField === descriptor.sourceField,
1174
+ ),
1175
+ )?.[1];
1176
+ const range =
1177
+ opening?.indices.length === 1
1178
+ ? ranges[requiredValue(opening.indices[0])]
1179
+ : undefined;
1180
+ retryScope = range === undefined ? [] : [range];
1181
+ }
1182
+ }
1183
+ throw contextualizeTextMutationAnchorError(
1184
+ error instanceof TextAnchorResolutionError &&
1185
+ (ranges.length > 0 || retryScope !== undefined)
1186
+ ? error.withReason(
1187
+ ranges.length === 0
1188
+ ? error.message
1189
+ : `${error.message.replace(/\.?$/u, ".")} The result selects ${describe(target)}.`,
1190
+ ranges.length === 0
1191
+ ? undefined
1192
+ : (error.rejection?.contextRange ?? scopeWindow(ranges)),
1193
+ retryScope,
1194
+ )
1195
+ : error,
1196
+ definition.name,
1197
+ field,
1198
+ target.source,
1199
+ value,
1200
+ );
1201
+ }
1202
+ const indices =
1203
+ ranges.length === 0 ? [0] : scopeRangeIndices(documentFor(target.source), anchor, ranges);
1204
+ if (indices === undefined)
1205
+ throw rejection(
1206
+ target,
1207
+ "invalid",
1208
+ `The anchor is outside the result's selection: ${describe(target)}. Use an anchor inside it, or pass the file path to edit elsewhere.`,
1209
+ );
1210
+ return { target, anchor, indices };
1211
+ }),
1212
+ );
1213
+ const checked = attempts.map((attempt, index) => {
1214
+ const failure = attempt.status === "rejected" ? (attempt.reason as unknown) : undefined;
1215
+ const rejection =
1216
+ failure instanceof TextMutationAnchorResolutionError
1217
+ ? failure.resolution.rejection
1218
+ : undefined;
1219
+ return {
1220
+ attempt,
1221
+ target: requiredValue(scope[index]),
1222
+ failure,
1223
+ rejection,
1224
+ fallback:
1225
+ attempt.status === "fulfilled"
1226
+ ? resolvedTextAnchorNotice(attempt.value.anchor) !== undefined
1227
+ : rejection?.searchHighlightRetry !== undefined,
1228
+ };
1229
+ });
1230
+ // A real match in any scoped source wins over a presentation fallback in another.
1231
+ const hasOriginalMatch = checked.some(
1232
+ ({ attempt, fallback, rejection }) =>
1233
+ !fallback &&
1234
+ (attempt.status === "fulfilled" ||
1235
+ rejection?.code === "ambiguous" ||
1236
+ rejection?.code === "outside-scope" ||
1237
+ rejection?.code === "before-start"),
1238
+ );
1239
+ const preferred = hasOriginalMatch ? checked.filter(({ fallback }) => !fallback) : checked;
1240
+ const resolved = preferred.flatMap(({ attempt }) =>
1241
+ attempt.status === "fulfilled" ? [attempt.value] : [],
1242
+ );
1243
+ const failures = preferred.flatMap(({ attempt, failure }) =>
1244
+ attempt.status === "rejected" ? [failure] : [],
1245
+ );
1246
+ // A file whose selection holds the anchor more than once holds it too.
1247
+ const ambiguous = preferred.flatMap(({ target, failure, rejection }) =>
1248
+ failure instanceof TextMutationAnchorResolutionError && rejection?.code === "ambiguous"
1249
+ ? [{ target, error: failure }]
1250
+ : [],
1251
+ );
1252
+ const holding = [...resolved, ...ambiguous].map(({ target }) => target);
1253
+ const placed = resolved[0];
1254
+ if (resolved.length !== 1 || placed === undefined || holding.length > 1) {
1255
+ publishAnchorRenderState?.(field, { kind: "failed" });
1256
+ const first = requiredValue(scope[0]);
1257
+ const unexpected = failures.find(
1258
+ (failure) => !(failure instanceof TextMutationAnchorResolutionError),
1259
+ );
1260
+ if (unexpected !== undefined)
1261
+ throw unexpected instanceof Error ? unexpected : new Error(errorMessage(unexpected));
1262
+ if (holding.length > 1) {
1263
+ const notice = resolved.flatMap(({ anchor }) => resolvedTextAnchorNotice(anchor))[0];
1264
+ const retryReason = ambiguous.find(
1265
+ ({ error }) => error.resolution.rejection?.searchHighlightRetry !== undefined,
1266
+ )?.error.resolution.rejection?.reason;
1267
+ const retry = notice ?? retryReason;
1268
+ throw rejection(
1269
+ first,
1270
+ "ambiguous",
1271
+ `The anchor matches in several files of the result: ${holding.map(describe).join("; ")}. ${retry === undefined ? "" : `${retry.replace(/\.?$/u, ".")} `}Pass the result of one file, or its path.`,
1272
+ retry === undefined ? undefined : stripSearchHighlights(value),
1273
+ );
1274
+ }
1275
+ // Every failure is an anchor rejection here; one file has exactly one.
1276
+ if (scope.length === 1) throw requiredValue(failures[0]) as TextMutationAnchorResolutionError;
1277
+ // Only one file holds the anchor, more than once.
1278
+ if (ambiguous[0] !== undefined) throw ambiguous[0].error;
1279
+ const relevant = preferred.find(({ fallback, rejection }) =>
1280
+ hasOriginalMatch
1281
+ ? preferred.length < checked.length &&
1282
+ (rejection?.code === "outside-scope" || rejection?.code === "before-start")
1283
+ : fallback,
1284
+ )?.failure;
1285
+ if (relevant instanceof TextMutationAnchorResolutionError) throw relevant;
1286
+ throw rejection(
1287
+ first,
1288
+ "missing",
1289
+ `The anchor is not inside the result's selection in any of its files: ${scope.map(describe).join("; ")}.`,
1290
+ );
1291
+ }
1292
+ const { target, anchor, indices } = placed;
1293
+ // A lone selector may select independent ranges. Paired endpoints must each select one
1294
+ // part of the same scope range, never the unselected text between ranges.
1295
+ for (const [other, placement] of scopedPlacements) {
1296
+ const sibling = (definition.anchors ?? []).find((candidate) => candidate.field === other);
1297
+ if (
1298
+ sibling?.sourceField === descriptor.sourceField &&
1299
+ placement.source === target.source &&
1300
+ (placement.indices.length !== 1 ||
1301
+ indices.length !== 1 ||
1302
+ placement.indices[0] !== indices[0])
1303
+ ) {
1304
+ publishAnchorRenderState?.(field, { kind: "failed" });
1305
+ throw rejection(
1306
+ target,
1307
+ "invalid",
1308
+ `The anchors ${other} and ${field} lie in different ranges of the result's selection: ${describe(target)}. Use anchors inside one range.`,
1309
+ );
1310
+ }
1311
+ }
1312
+ scopedPlacements.set(field, { source: target.source, indices });
1313
+ recordResolvedAnchor(field, target.source, value, anchor);
1314
+ return new Map([[target.source, anchor]]);
1315
+ };
1316
+ const resolveAnchors = (
1317
+ field: string,
1318
+ start?: PairedAnchorStart,
1319
+ ): Promise<ReadonlyMap<string, TextAnchor>> => {
903
1320
  const cached = anchorCache.get(field);
904
1321
 
905
1322
  if (cached !== undefined) {
@@ -913,29 +1330,28 @@ function createMutationContext(
913
1330
  const implicitTargets = sources.implicitTargets.get(field);
914
1331
 
915
1332
  if (descriptor === undefined) {
916
- throw new Error(
917
- `Mutation tool ${definition.name} tried to resolve undeclared anchor ${field}`,
918
- );
1333
+ throw new Error(`The ${definition.name} tool does not support selector "${field}".`);
919
1334
  }
920
1335
 
1336
+ const scope = sources.scopes.get(descriptor.sourceField);
1337
+ if (typeof value === "string" && scope !== undefined)
1338
+ return resolveScopedAnchor(field, descriptor, value, scope, start);
1339
+
921
1340
  const explicitAnchors =
922
1341
  typeof value === "string" && anchorSources !== undefined
923
1342
  ? new Map(
924
1343
  await Promise.all(
925
1344
  anchorSources.map(async (source) => {
926
1345
  try {
927
- const anchor = await resolveResourceAnchor(source, value, descriptor.kinds);
1346
+ const anchor = await resolveResourceAnchor(
1347
+ source,
1348
+ value,
1349
+ descriptor.kinds,
1350
+ undefined,
1351
+ start?.source === source ? start.offset : undefined,
1352
+ );
928
1353
 
929
- if (resolvedTextAnchorType(anchor) === "major") {
930
- majorAnchorSources.add(source);
931
- }
932
- const rendered = renderTextAnchor(anchor, value, { source, anchor });
933
- publishAnchorRenderState?.(field, {
934
- kind: "resolved",
935
- full: rendered.full,
936
- compact: rendered.compact,
937
- resolverId: rendered.resolverId,
938
- });
1354
+ recordResolvedAnchor(field, source, value, anchor);
939
1355
  return [source, anchor] as const;
940
1356
  } catch (error) {
941
1357
  publishAnchorRenderState?.(field, { kind: "failed" });
@@ -967,8 +1383,28 @@ function createMutationContext(
967
1383
  }
968
1384
 
969
1385
  if (explicitAnchors === undefined) {
1386
+ const example: Record<string, string> = {
1387
+ [definition.source.field]: sourceFor(definition.source.field),
1388
+ };
1389
+ if (descriptor.sourceField !== definition.source.field)
1390
+ example[descriptor.sourceField] = sourceFor(descriptor.sourceField);
1391
+ for (const selector of definition.anchors ?? []) {
1392
+ if (selector.field === field || typeof input[selector.field] === "string")
1393
+ example[selector.field] = "exact existing text";
1394
+ }
1395
+ if (definition.name === "insert" || definition.name === "replace")
1396
+ example.text = "new text";
1397
+ const alternatives =
1398
+ field === "targetAt"
1399
+ ? " Pass targetAfter or targetBefore alone to insert instead."
1400
+ : definition.name === "insert"
1401
+ ? " Use before to insert on the other side."
1402
+ : "";
970
1403
  throw new Error(
971
- `Mutation tool ${definition.name} tried to resolve undeclared anchor ${field}`,
1404
+ `Missing "${field}" for ${definition.name} with a file path in "${descriptor.sourceField}". ` +
1405
+ `Read the file and supply "${field}" as exact existing text or an issued selection reference.${alternatives} ` +
1406
+ `Example shape: ${definition.name}(${JSON.stringify(example)}). ` +
1407
+ `Replace the example text with text from your file, or pass a Read/Search selection as "${descriptor.sourceField}" instead of a file path.`,
972
1408
  );
973
1409
  }
974
1410
  return explicitAnchors;
@@ -977,10 +1413,14 @@ function createMutationContext(
977
1413
  return pending;
978
1414
  };
979
1415
 
980
- return {
1416
+ const context: MutationExecutionContext = {
981
1417
  cwd: invocation.cwd,
982
1418
  ...(invocation.signal !== undefined && { signal: invocation.signal }),
983
1419
  sourceDocument: documentFor(sourceFor(definition.source.field)),
1420
+ ...(checkSpan !== undefined && {
1421
+ checkSpan: ({ source, from, to }) =>
1422
+ checkSpan(source, invocation.cwd, documentFor(source), from, to),
1423
+ }),
984
1424
  sourceFor,
985
1425
  documentFor,
986
1426
  targetDocument(field): TextChangeDocument {
@@ -1005,6 +1445,7 @@ function createMutationContext(
1005
1445
  return requiredValue(resolved.values().next().value);
1006
1446
  },
1007
1447
 
1448
+ selectorNotices,
1008
1449
  resultPresentationFor(source): MutationResultPresentation {
1009
1450
  return [...majorAnchorSources].some((candidate) =>
1010
1451
  sameResource(candidate, source, invocation.cwd),
@@ -1013,14 +1454,39 @@ function createMutationContext(
1013
1454
  : "plain";
1014
1455
  },
1015
1456
  };
1457
+ bindContextAliases(context, sources.aliases);
1458
+ return context;
1016
1459
  }
1017
1460
 
1018
- function withResultPresentations(
1461
+ /** Carries selector feedback forward to the committed direct or batched result. */
1462
+ export function withMutationResultMetadata(
1019
1463
  mutation: TextMutation,
1020
1464
  context: MutationExecutionContext,
1021
1465
  ): ExecutedTextMutation {
1466
+ const noticesByTarget = new Map<string, Map<string, Set<string>>>();
1467
+ for (const { source, field, notice } of context.selectorNotices) {
1468
+ // Copy can resolve a selector in a source it doesn't edit. Show that notice on its target.
1469
+ const target = mutation.edits.has(source) ? source : mutation.edits.keys().next().value;
1470
+ if (target === undefined) continue;
1471
+ const notices = noticesByTarget.get(target) ?? new Map<string, Set<string>>();
1472
+ noticesByTarget.set(target, notices);
1473
+ const fields = notices.get(notice) ?? new Set<string>();
1474
+ notices.set(notice, fields);
1475
+ fields.add(field);
1476
+ }
1022
1477
  return {
1023
1478
  ...mutation,
1479
+ edits: new Map(
1480
+ [...mutation.edits].map(([source, edit]) => {
1481
+ const notices = noticesByTarget.get(source);
1482
+ if (notices === undefined) return [source, edit];
1483
+ const selectorStatuses: MutationDiffStatus[] = [...notices].map(([notice, fields]) => ({
1484
+ origin: "pre-edit",
1485
+ text: `${notice} from ${[...fields].join(", ")}.`,
1486
+ }));
1487
+ return [source, { ...edit, selectorStatuses }];
1488
+ }),
1489
+ ),
1024
1490
  resultPresentations: new Map(
1025
1491
  [...mutation.edits.keys()].map((source) => [source, context.resultPresentationFor(source)]),
1026
1492
  ),
@@ -1028,7 +1494,7 @@ function withResultPresentations(
1028
1494
  }
1029
1495
 
1030
1496
  const preflightMutationTools = new Set(["replace", "delete", "insert", "copy", "move"]);
1031
- /** Resolves every supplied anchor field for built-in span mutation tools. */
1497
+ /** Resolves independent selectors. Paired ends need the first selector's boundary. */
1032
1498
  export async function preflightMutationAnchors(
1033
1499
  definition: TextMutationToolRegistration,
1034
1500
  input: Readonly<Record<string, unknown>>,
@@ -1037,10 +1503,24 @@ export async function preflightMutationAnchors(
1037
1503
  if (!preflightMutationTools.has(definition.name)) {
1038
1504
  return;
1039
1505
  }
1506
+ const empty = definition.anchors?.find(({ field }) => input[field] === "");
1507
+ if (empty !== undefined) {
1508
+ throw new TextMutationInputError(
1509
+ "EMPTY_SELECTOR",
1510
+ `${definition.name} selector "${empty.field}" is empty. Supply exact existing text or an issued anchor.`,
1511
+ );
1512
+ }
1040
1513
  const failures: TextMutationAnchorResolutionError[] = [];
1041
1514
  await Promise.all(
1042
1515
  (definition.anchors ?? []).map(async (descriptor) => {
1043
- if (!isMutationAnchorValue(descriptor, input[descriptor.field])) {
1516
+ if (
1517
+ (descriptor.pairedEnd &&
1518
+ (descriptor.field !== "targetBefore" ||
1519
+ input.targetFrom !== undefined ||
1520
+ input.targetAfter !== undefined)) ||
1521
+ descriptor.field === definition.pair?.[1] ||
1522
+ !isMutationAnchorValue(descriptor, input[descriptor.field])
1523
+ ) {
1044
1524
  return;
1045
1525
  }
1046
1526
  try {
@@ -1102,12 +1582,17 @@ export async function previewTextMutation(
1102
1582
  sources,
1103
1583
  texts,
1104
1584
  resolveAnchor,
1585
+ undefined,
1586
+ core.checkSpan,
1105
1587
  );
1106
1588
  await preflightMutationAnchors(definition, request.input, mutationContext);
1107
1589
  if (semanticHandler !== undefined) {
1108
1590
  return { changes: new Map(), result: { edits: new Map() } };
1109
1591
  }
1110
- const mutation = await definition.mutate(mutationContext, request.input);
1592
+ const mutation = canonicalizeContextEdits(
1593
+ await definition.mutate(mutationContext, request.input),
1594
+ mutationContext,
1595
+ );
1111
1596
 
1112
1597
  return {
1113
1598
  changes: new Map([...mutation.edits].map(([source, edit]) => [source, edit.changes])),
@@ -1129,6 +1614,8 @@ export async function executeTextMutation<TParameters extends TSchema>(
1129
1614
  context: ExtensionContext,
1130
1615
  publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
1131
1616
  lastResolvedSource?: string,
1617
+ checkSnapshot?: TextResourceEditRequest["checkSnapshot"],
1618
+ resultTargets?: ResultTargetStore,
1132
1619
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
1133
1620
  const execution = await executeTextMutationPipeline(
1134
1621
  core,
@@ -1138,6 +1625,7 @@ export async function executeTextMutation<TParameters extends TSchema>(
1138
1625
  context,
1139
1626
  publishAnchorRenderState,
1140
1627
  lastResolvedSource,
1628
+ checkSnapshot,
1141
1629
  );
1142
1630
  const result = await buildToolResult(
1143
1631
  core,
@@ -1145,6 +1633,7 @@ export async function executeTextMutation<TParameters extends TSchema>(
1145
1633
  execution.source,
1146
1634
  context,
1147
1635
  definition.name,
1636
+ allMatchesRetry(definition.name, parameters, resultTargets),
1148
1637
  );
1149
1638
  return execution.pipeline.kind === "completed" && execution.pipeline.state.metadata !== undefined
1150
1639
  ? { ...result, details: { ...result.details, metadata: execution.pipeline.state.metadata } }
@@ -1160,6 +1649,7 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1160
1649
  context: ExtensionContext,
1161
1650
  publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
1162
1651
  lastResolvedSource?: string,
1652
+ checkSnapshot?: TextResourceEditRequest["checkSnapshot"],
1163
1653
  ): Promise<{ readonly pipeline: TextEditExecutionOutcome; readonly source: string }> {
1164
1654
  const source = mutationSource(definition, parameters);
1165
1655
  const pipeline = await core.executeEdit(
@@ -1171,15 +1661,17 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1171
1661
  },
1172
1662
  // Another Pi process may write the file between this edit's read and its write. The write
1173
1663
  // is then refused, and the edit runs again on the current text, anchors included.
1174
- (state) => retryWhenSourceChanged(() => applyTextMutation(state)),
1664
+ (state) =>
1665
+ retryWhenSourceChanged(() => applyTextMutation(state), undefined, state.sourceChangeRetry),
1175
1666
  );
1176
1667
 
1177
1668
  async function applyTextMutation(
1178
1669
  state: TextPreEditState<Static<TParameters>>,
1179
1670
  ): Promise<TextResourcesEditOutcome<TextMutation>> {
1180
1671
  try {
1181
- if (state.editPlan !== undefined) {
1182
- const plan = state.editPlan;
1672
+ if (state.planEdit !== undefined) {
1673
+ // Ask the planner on each attempt. It may reuse its plan if the guarded snapshots still fit.
1674
+ const plan = await state.planEdit();
1183
1675
  if (
1184
1676
  plan.files.length === 0 ||
1185
1677
  new Set(plan.files.map((file) => file.source)).size !== plan.files.length
@@ -1193,22 +1685,28 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1193
1685
  ...(state.signal !== undefined && { signal: state.signal }),
1194
1686
  },
1195
1687
  (texts) => {
1196
- for (const file of plan.files) {
1197
- if (texts.get(file.source) !== file.expectedContent)
1198
- throw new Error(
1199
- "A semantic edit source changed. Resolve the symbol again before retrying.",
1200
- );
1201
- }
1202
1688
  const edits = new Map(
1203
- plan.files.map((file) => [
1204
- file.source,
1205
- { changes: file.changes, action: "edited" as const },
1206
- ]),
1689
+ plan.files.map((file) => {
1690
+ const current = texts.get(file.source);
1691
+ const changes =
1692
+ current === file.expectedContent
1693
+ ? file.changes
1694
+ : current === undefined
1695
+ ? undefined
1696
+ : file.rebase?.(current);
1697
+ if (changes === undefined)
1698
+ throw Object.assign(
1699
+ new Error("A planned file changed before the semantic edit wrote it."),
1700
+ { code: SOURCE_CHANGED },
1701
+ );
1702
+ return [file.source, { changes, action: "edited" as const }] as const;
1703
+ }),
1207
1704
  );
1208
1705
  return Promise.resolve({
1209
- changes: new Map(plan.files.map((file) => [file.source, file.changes])),
1706
+ changes: new Map([...edits].map(([source, edit]) => [source, edit.changes])),
1210
1707
  result: {
1211
1708
  edits,
1709
+ snapshots: texts,
1212
1710
  resultPresentations: new Map(
1213
1711
  plan.files.map((file) => [file.source, "plain" as const]),
1214
1712
  ),
@@ -1262,10 +1760,12 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1262
1760
  publishAnchorRenderState,
1263
1761
  );
1264
1762
  await preflightMutationAnchors(definition, state.input, mutationContext);
1763
+ state.signal?.throwIfAborted();
1764
+ reportToolEffect("unknown");
1265
1765
  const semanticAction = await semanticHandler.execute(mutationContext, state.input);
1266
1766
  return {
1267
1767
  changes: new Map(),
1268
- result: withResultPresentations(
1768
+ result: withMutationResultMetadata(
1269
1769
  { edits: new Map(), semanticAction },
1270
1770
  mutationContext,
1271
1771
  ),
@@ -1279,6 +1779,7 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1279
1779
  source: resourceSource,
1280
1780
  read: true,
1281
1781
  ...(definition.name === "write" && { allowReadFailure: true }),
1782
+ ...(checkSnapshot !== undefined && { checkSnapshot }),
1282
1783
  })),
1283
1784
  {
1284
1785
  cwd: state.cwd,
@@ -1304,11 +1805,16 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
1304
1805
  texts,
1305
1806
  resolveAnchor,
1306
1807
  publishAnchorRenderState,
1808
+ core.checkSpan,
1307
1809
  );
1308
1810
  await preflightMutationAnchors(definition, state.input, mutationContext);
1309
- const mutation = await definition.mutate(mutationContext, state.input);
1811
+ const mutation = canonicalizeContextEdits(
1812
+ await definition.mutate(mutationContext, state.input),
1813
+ mutationContext,
1814
+ );
1310
1815
  const executedMutation: ExecutedTextMutation = {
1311
- ...withResultPresentations(mutation, mutationContext),
1816
+ ...withMutationResultMetadata(mutation, mutationContext),
1817
+ snapshots: texts,
1312
1818
  ...(definition.name === "write" && {
1313
1819
  unchangedWrite: {
1314
1820
  source: mutationContext.sourceFor("path"),
@@ -1389,24 +1895,23 @@ type CompletedTextResource = Extract<
1389
1895
  { readonly kind: "completed" }
1390
1896
  >;
1391
1897
 
1392
- /** Count real Copy changes without counting retained identical destination ranges. */
1898
+ /** Count real changes; targets that already had their text are reported separately. */
1393
1899
  export function textMutationOperationReceipts(
1394
1900
  operation: string,
1395
1901
  edit: TextMutationEdit,
1396
1902
  before: string,
1397
1903
  ): readonly MutationOperationReceipt[] {
1904
+ // A created empty file is written although its text does not change.
1398
1905
  const changes =
1399
- operation === "copy"
1400
- ? edit.changes.filter(
1401
- (change) =>
1402
- !change.allowUnchanged || before.slice(change.from, change.to) !== change.insert,
1403
- ).length
1404
- : edit.changes.length;
1405
- return operation === "copy" && changes === 0 ? [] : [{ operation, changes }];
1906
+ operation === "write"
1907
+ ? edit.changes.length
1908
+ : edit.changes.filter((change) => !isAlreadyDone(before, change)).length;
1909
+ return changes === 0 ? [] : [{ operation, changes }];
1406
1910
  }
1407
1911
  function textMutationRawChanges(before: string, changes: TextMutationEdit["changes"]) {
1408
- return applyTextChanges(before, changes, before.length === 0).changes.map(
1409
- (change, editIndex) => ({
1912
+ return applyTextChanges(before, changes)
1913
+ .changes.filter((change) => change.removedText !== change.insertedText)
1914
+ .map((change, editIndex) => ({
1410
1915
  editIndex,
1411
1916
  fromA: change.fromBefore,
1412
1917
  toA: change.toBefore,
@@ -1414,13 +1919,12 @@ function textMutationRawChanges(before: string, changes: TextMutationEdit["chang
1414
1919
  toB: change.toAfter,
1415
1920
  removedText: change.removedText,
1416
1921
  insertedText: change.insertedText,
1417
- }),
1418
- );
1922
+ }));
1419
1923
  }
1420
1924
 
1421
1925
  /**
1422
1926
  * Selects the final lines that a successful result shows with presenter output. Only results of
1423
- * edits that used major anchors (LINE#HASH) show it, as fresh anchors for chaining edits.
1927
+ * edits that used major anchors (line anchors) show it, as fresh anchors for chaining edits.
1424
1928
  */
1425
1929
  export function presentedFinalStateLines(
1426
1930
  mutations: readonly {
@@ -1474,17 +1978,22 @@ export function buildSuccessfulTextMutationResult(
1474
1978
  .map((contribution) => contribution.data)
1475
1979
  .find(isTextMutationResultContributionData);
1476
1980
  const rawChanges = textMutationRawChanges(before, edit.changes);
1981
+ const alreadyDone = alreadyDoneTargets(before, edit.changes);
1477
1982
 
1478
1983
  return new FileMutationResult({
1479
1984
  ...mutationResultData,
1985
+ ...(alreadyDone.length > 0 && { alreadyDone }),
1480
1986
 
1481
1987
  ...(diffPeerRanges === undefined ? {} : { diffPeerRanges }),
1482
1988
 
1483
1989
  operations,
1484
- diffStatuses: resource.postEditContributions
1485
- .map((item) => item.data)
1486
- .filter(isDiffStatusContribution)
1487
- .flatMap((item) => item.diffStatuses),
1990
+ diffStatuses: [
1991
+ ...(edit.selectorStatuses ?? []),
1992
+ ...resource.postEditContributions
1993
+ .map((item) => item.data)
1994
+ .filter(isDiffStatusContribution)
1995
+ .flatMap((item) => item.diffStatuses),
1996
+ ],
1488
1997
  formatting: resource.postEditContributions
1489
1998
  .map((item) => item.data)
1490
1999
  .findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
@@ -1544,6 +2053,7 @@ async function buildToolResult(
1544
2053
  source: string,
1545
2054
  context: ExtensionContext,
1546
2055
  operation: string,
2056
+ retry?: AllMatchesRetry,
1547
2057
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
1548
2058
  if (pipeline.kind === "failed") {
1549
2059
  return failureToolResult(
@@ -1566,7 +2076,7 @@ async function buildToolResult(
1566
2076
  }
1567
2077
 
1568
2078
  if (outcome.kind === "failed") {
1569
- const recovery = await anchorFailureToolResult(core, outcome.failure, context);
2079
+ const recovery = await anchorFailureToolResult(core, outcome.failure, context, retry);
1570
2080
 
1571
2081
  if (recovery !== undefined) {
1572
2082
  return recovery;
@@ -1629,6 +2139,12 @@ async function buildToolResult(
1629
2139
  },
1630
2140
  };
1631
2141
  }
2142
+ if (
2143
+ outcome.resources.length === 0 &&
2144
+ mutation.snapshots !== undefined &&
2145
+ isAlreadyDoneMutation(mutation, mutation.snapshots)
2146
+ )
2147
+ return alreadyDoneToolResult([mutation], mutation.snapshots);
1632
2148
  const results = outcome.resources.flatMap((resource) => {
1633
2149
  const resultSource = resource.source;
1634
2150
  const edit = mutation.edits.get(resultSource);
@@ -1648,7 +2164,20 @@ async function buildToolResult(
1648
2164
  ];
1649
2165
  });
1650
2166
 
1651
- const presented = results.map((result) => withPipelineStatuses(result, pipeline.state.metadata));
2167
+ // A source whose every target already had its text is not written but is still reported.
2168
+ const untouched = [...mutation.edits].flatMap(([editSource, edit]) => {
2169
+ const content = mutation.snapshots?.get(editSource);
2170
+ if (
2171
+ content === undefined ||
2172
+ outcome.resources.some((resource) => resource.source === editSource)
2173
+ )
2174
+ return [];
2175
+ const result = alreadyDoneFileResult(editSource, content, edit.changes);
2176
+ return result === undefined ? [] : [result];
2177
+ });
2178
+ const presented = [...results, ...untouched].map((result) =>
2179
+ withPipelineStatuses(result, pipeline.state.metadata),
2180
+ );
1652
2181
  return {
1653
2182
  content: [new FileMutationAgentResult(presented).toTextContent()],
1654
2183
  details: { results: presented },
@@ -1659,7 +2188,10 @@ function withPipelineStatuses(result: FileMutationResult, metadata: unknown): Fi
1659
2188
  if (!isDiffStatusContribution(metadata)) return result;
1660
2189
  return new FileMutationResult({
1661
2190
  ...result.data,
1662
- diffStatuses: [...(result.data.diffStatuses ?? []), ...metadata.diffStatuses],
2191
+ diffStatuses: [
2192
+ ...(result.data.diffStatuses ?? []),
2193
+ ...metadata.diffStatuses.map((status) => ({ ...status, origin: "pre-edit" as const })),
2194
+ ],
1663
2195
  });
1664
2196
  }
1665
2197
  async function resolveAnchorRecovery(error: TextMutationAnchorResolutionError) {
@@ -1667,32 +2199,57 @@ async function resolveAnchorRecovery(error: TextMutationAnchorResolutionError) {
1667
2199
  return error.resolution.recovery;
1668
2200
  }
1669
2201
 
2202
+ interface AllMatchesRetry {
2203
+ readonly store: ResultTargetStore;
2204
+ readonly field: "at" | "after" | "before";
2205
+ }
2206
+
2207
+ /** Only selectors that edit each range independently can use an entire match set. */
2208
+ export function allMatchesRetry(
2209
+ operation: string,
2210
+ input: Readonly<Record<string, unknown>>,
2211
+ store?: ResultTargetStore,
2212
+ ): AllMatchesRetry | undefined {
2213
+ if (store === undefined) return undefined;
2214
+ if (operation === "insert") {
2215
+ if (input.after !== undefined && input.before !== undefined) return undefined;
2216
+ return { store, field: input.before === undefined ? "after" : "before" };
2217
+ }
2218
+ if (
2219
+ (operation === "replace" || operation === "delete") &&
2220
+ sourceSelectors.slice(1).every((field) => input[field] === undefined)
2221
+ )
2222
+ return { store, field: "at" };
2223
+ return undefined;
2224
+ }
2225
+
1670
2226
  async function anchorFailureToolResult(
1671
2227
  core: TextEditorCore,
1672
2228
  failure: TextResourceEditFailure,
1673
2229
  context: ExtensionContext,
2230
+ retry?: AllMatchesRetry,
1674
2231
  ): Promise<AgentToolResult<FileMutationBatchResult> | undefined> {
1675
2232
  if (failure.cause instanceof TextMutationAnchorAggregateError) {
2233
+ const failures = failure.cause.failures;
1676
2234
  const recovered = await Promise.all(
1677
- failure.cause.failures.map((cause) =>
1678
- anchorFailureToolResult(core, { ...failure, source: cause.source, cause }, context),
2235
+ failures.map((cause) =>
2236
+ anchorFailureToolResult(
2237
+ core,
2238
+ { ...failure, source: cause.source, cause },
2239
+ context,
2240
+ failures.length === 1 ? retry : undefined,
2241
+ ),
1679
2242
  ),
1680
2243
  );
1681
2244
  const results: FileMutationResult[] = [];
1682
2245
  const anchorRecoveries: NonNullable<FileMutationBatchResult["anchorRecoveries"]>[number][] = [];
1683
2246
  const messages: string[] = [];
1684
- const exactTextFailures: string[] = [];
1685
2247
  for (const item of recovered) {
1686
2248
  if (item === undefined) {
1687
2249
  continue;
1688
2250
  }
1689
2251
  results.push(...(item.details.results ?? []));
1690
2252
  anchorRecoveries.push(...(item.details.anchorRecoveries ?? []));
1691
- const failed = item.details.metadata?.exactTextFailures;
1692
- if (Array.isArray(failed))
1693
- exactTextFailures.push(
1694
- ...failed.filter((source): source is string => typeof source === "string"),
1695
- );
1696
2253
  for (const block of item.content) {
1697
2254
  if (block.type === "text") {
1698
2255
  messages.push(block.text);
@@ -1708,7 +2265,6 @@ async function anchorFailureToolResult(
1708
2265
  results,
1709
2266
  anchorRecoveries,
1710
2267
  effect: "not-applied",
1711
- metadata: { exactTextFailures },
1712
2268
  },
1713
2269
  };
1714
2270
  }
@@ -1718,45 +2274,45 @@ async function anchorFailureToolResult(
1718
2274
 
1719
2275
  const contextual = failure.cause;
1720
2276
  const resolution = contextual.resolution;
1721
- const recovery = await resolveAnchorRecovery(contextual).catch(() => {
1722
- context.signal?.throwIfAborted();
1723
- return undefined;
1724
- });
1725
-
1726
- const windows =
1727
- recovery?.kind === "candidates"
1728
- ? recoveryWindows(
1729
- recovery.candidates.map(({ range }) => range),
1730
- core.recoveryContextLines(),
1731
- )
1732
- : resolution.rejection?.contextRange === undefined
1733
- ? []
1734
- : [resolution.rejection.contextRange];
1735
- if (windows.length === 0) windows.push({ offset: 1, limit: 40 });
1736
-
1737
- const reads = await Promise.all(
1738
- windows.map((range) =>
1739
- readTextAnchorRecovery(
1740
- core,
1741
- { path: contextual.source, ...range },
1742
- {
1743
- cwd: context.cwd,
1744
- ...(context.signal !== undefined && { signal: context.signal }),
1745
- },
1746
- )?.catch(() => {
1747
- context.signal?.throwIfAborted();
1748
- return undefined;
1749
- }),
1750
- ),
1751
- );
1752
- const recoveryTexts: string[] = [];
1753
- for (const read of reads) {
1754
- if (read === undefined || read.isError === true) continue;
1755
- recoveryTexts.push(
1756
- ...read.content.filter((block) => block.type === "text").map((block) => block.text),
1757
- );
1758
- }
1759
-
2277
+ const showRecovery = contextual.anchor.length <= MAX_ANCHOR_EXCERPT_LENGTH;
2278
+ const canOfferAll =
2279
+ retry?.field === contextual.field && resolution.rejection?.code === "ambiguous";
2280
+ const ambiguous = resolution.rejection?.code === "ambiguous";
2281
+ const recovery =
2282
+ showRecovery || canOfferAll || ambiguous
2283
+ ? await resolveAnchorRecovery(contextual).catch(() => {
2284
+ context.signal?.throwIfAborted();
2285
+ return undefined;
2286
+ })
2287
+ : undefined;
2288
+
2289
+ const snapshot = resolution.snapshot();
2290
+ const recoveryContext =
2291
+ recovery?.kind === "candidates" && snapshot !== undefined
2292
+ ? await anchorCandidateContext(core, context, {
2293
+ field: contextual.field,
2294
+ source: snapshot.source,
2295
+ content: snapshot.content,
2296
+ ...(snapshot.endAfter !== undefined && { minimumOffset: snapshot.endAfter }),
2297
+ ...(snapshot.scope !== undefined && { scope: snapshot.scope }),
2298
+ candidates: recovery.candidates.map(({ range }) => range),
2299
+ total: recovery.total,
2300
+ })
2301
+ : undefined;
2302
+
2303
+ const allMatches = canOfferAll ? resolution.allMatchesTarget() : undefined;
2304
+ const offer: AllMatchesOffer | undefined =
2305
+ allMatches === undefined || retry === undefined
2306
+ ? undefined
2307
+ : {
2308
+ count: allMatches.ranges.length,
2309
+ reference: retry.store.registerAllMatchesReference(allMatches, context.cwd),
2310
+ field: retry.field,
2311
+ };
2312
+ const reason =
2313
+ offer === undefined
2314
+ ? resolution.message
2315
+ : `${resolution.message.replace(/[.!?]+$/u, "")}. To change all ${offer.count} matches, pass ${offer.reference} as ${offer.field}.`;
1760
2316
  const result = new FileMutationResult({
1761
2317
  ok: false,
1762
2318
  path: contextual.source,
@@ -1764,11 +2320,13 @@ async function anchorFailureToolResult(
1764
2320
  {
1765
2321
  path: contextual.source,
1766
2322
  code: resolution.rejection?.code ?? failure.code,
1767
- reason: resolution.message,
2323
+ reason,
2324
+ ...(resolution.rejection?.searchHighlightRetry !== undefined && {
2325
+ searchHighlightFallback: true,
2326
+ }),
1768
2327
  },
1769
2328
  ],
1770
2329
  });
1771
- const recoveryContext = recoveryTexts.join("\n");
1772
2330
  const rejectionCode = resolution.rejection?.code;
1773
2331
  const content =
1774
2332
  rejectionCode === "stale"
@@ -1780,11 +2338,11 @@ async function anchorFailureToolResult(
1780
2338
  field: contextual.field,
1781
2339
  path: contextual.source,
1782
2340
  anchor: contextual.anchor,
1783
- ...(recoveryContext.length > 0 && { context: recoveryContext }),
2341
+ ...(recoveryContext !== undefined && { context: recoveryContext }),
1784
2342
  } satisfies StaleAnchorMessageDetails,
1785
2343
  resolution.message,
1786
2344
  )
1787
- : formatRejectedAnchorMessage(contextual, rejectionCode, resolution.message, recoveryContext);
2345
+ : formatRejectedAnchorMessage(contextual, rejectionCode, reason, recoveryContext, offer);
1788
2346
 
1789
2347
  return {
1790
2348
  content: [{ type: "text", text: content }],
@@ -1792,14 +2350,6 @@ async function anchorFailureToolResult(
1792
2350
  results: [result],
1793
2351
  effect: "not-applied",
1794
2352
  anchorRecovery: true,
1795
- // A Copy destination failure must not block otherwise valid source selectors.
1796
- ...(resolution.resolverId === "exact-text" &&
1797
- !(
1798
- contextual.toolName === "copy" &&
1799
- (contextual.field === "targetStart" || contextual.field === "targetEnd")
1800
- ) && {
1801
- metadata: { exactTextFailures: [contextual.source] },
1802
- }),
1803
2353
  ...(recovery?.kind === "candidates" && {
1804
2354
  anchorRecoveries: [
1805
2355
  {
@@ -1815,51 +2365,78 @@ async function anchorFailureToolResult(
1815
2365
  };
1816
2366
  }
1817
2367
 
2368
+ /** A reference that selects every match of an ambiguous literal, and where to pass it. */
2369
+ interface AllMatchesOffer {
2370
+ readonly count: number;
2371
+ readonly reference: string;
2372
+ readonly field: AllMatchesRetry["field"];
2373
+ }
2374
+
2375
+ async function anchorCandidateContext(
2376
+ core: TextEditorCore,
2377
+ context: ExtensionContext,
2378
+ options: AnchorCandidates,
2379
+ ): Promise<string | undefined> {
2380
+ const presented = presentAnchorCandidates(options, core.recoveryContextLines());
2381
+ if (presented === undefined) return undefined;
2382
+ // Keep Read's guarded range history for the windows shown, but never use a later read
2383
+ // as the display snapshot for a refusal.
2384
+ await Promise.all(
2385
+ presented.windows.map(async (window) => {
2386
+ try {
2387
+ await readTextAnchorRecovery(
2388
+ core,
2389
+ { path: options.source, ...window },
2390
+ {
2391
+ cwd: context.cwd,
2392
+ ...(context.signal !== undefined && { signal: context.signal }),
2393
+ },
2394
+ );
2395
+ } catch {
2396
+ context.signal?.throwIfAborted();
2397
+ }
2398
+ }),
2399
+ );
2400
+ return presented.text;
2401
+ }
2402
+
1818
2403
  function formatRejectedAnchorMessage(
1819
2404
  failure: TextMutationAnchorResolutionError,
1820
2405
  code: TextAnchorRejection["code"] | undefined,
1821
2406
  reason: string,
1822
- recoveryContext: string,
2407
+ recoveryContext: string | undefined,
2408
+ offer?: AllMatchesOffer,
1823
2409
  ): string {
2410
+ const next =
2411
+ recoveryContext === undefined
2412
+ ? "No candidates to show. Use Read or Search to find a current anchor, or retry with unique exact text."
2413
+ : `\n\n${recoveryContext}`;
2414
+ if (offer !== undefined) {
2415
+ // The all-matches step leads: it is the step an agent asked to change every match needs.
2416
+ return (
2417
+ `[SYSTEM] ${failure.toolName} blocked: ${quoteAnchorExcerpt(failure.anchor)} matches ${offer.count} times in "${failure.source}". ` +
2418
+ `To change all of them, pass ${offer.reference} as ${offer.field}.${recoveryContext === undefined ? " " : ""}${next}`
2419
+ );
2420
+ }
1824
2421
  const state =
1825
2422
  code === "ambiguous"
1826
2423
  ? "is ambiguous"
1827
- : code === "missing"
1828
- ? "was not found"
1829
- : code === "invalid"
1830
- ? "was rejected"
1831
- : "could not be resolved";
1832
- const guidance =
1833
- failure.resolution.resolverId === "exact-text"
1834
- ? failure.toolName === "copy"
1835
- ? "Use an anchor below, or get a fresh Read/Search selection and pass it to Copy."
1836
- : "Exact-text edits are blocked for this file. Use a current anchor below for the intended edit, or get one with Read/Search. Exact text is available again after that edit succeeds."
1837
- : "If the intended text is represented below, use its candidate anchor. Otherwise, reread the relevant section and choose a current anchor.";
1838
- const context = recoveryContext.length === 0 ? "" : `\n\n${recoveryContext}`;
1839
- return `[SYSTEM] ${failure.toolName} blocked: ${failure.field === "anchor" ? "anchor" : `${failure.field} anchor`} "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
1840
- }
1841
-
1842
- function recoveryWindows(
1843
- ranges: readonly TextAnchorRecoveryCandidateRange[],
1844
- contextLines: number,
1845
- ): TextAnchorRecoveryRange[] {
1846
- const windows = ranges
1847
- .map((range) => ({
1848
- offset: Math.max(1, range.start.lineNumber - contextLines),
1849
- limit: range.end.lineNumber - range.start.lineNumber + 1 + contextLines * 2,
1850
- }))
1851
- .sort((left, right) => left.offset - right.offset);
1852
- const merged: TextAnchorRecoveryRange[] = [];
1853
- for (const window of windows) {
1854
- const previous = merged[merged.length - 1];
1855
- if (previous === undefined || window.offset > previous.offset + previous.limit) {
1856
- merged.push(window);
1857
- continue;
1858
- }
1859
- const end = Math.max(previous.offset + previous.limit, window.offset + window.limit);
1860
- merged[merged.length - 1] = { offset: previous.offset, limit: end - previous.offset };
1861
- }
1862
- return merged;
2424
+ : code === "before-start"
2425
+ ? "has no match after the start selector"
2426
+ : code === "missing"
2427
+ ? "was not found"
2428
+ : code === "invalid"
2429
+ ? "was rejected"
2430
+ : "could not be resolved";
2431
+ const subject = `[SYSTEM] ${failure.toolName} blocked: ${failure.field === "anchor" ? "anchor" : `${failure.field} anchor`} ${quoteAnchorExcerpt(failure.anchor)} ${state} in "${failure.source}"`;
2432
+ // Reference failures carry resolver-specific guidance; there is no single source snapshot.
2433
+ if (
2434
+ failure.resolution instanceof TextAnchorResourceResolutionError &&
2435
+ recoveryContext === undefined
2436
+ )
2437
+ return `${subject}: ${reason}`;
2438
+ const punctuated = /[.!?]$/u.test(reason) ? reason : `${reason}.`;
2439
+ return `${subject}: ${punctuated}${recoveryContext === undefined ? " " : ""}${next}`;
1863
2440
  }
1864
2441
 
1865
2442
  export async function buildFailedTextMutationResult(
@@ -1867,7 +2444,20 @@ export async function buildFailedTextMutationResult(
1867
2444
  failure: TextResourceEditFailure,
1868
2445
  context: ExtensionContext,
1869
2446
  effect: "applied" | "not-applied" | "unknown" = "not-applied",
2447
+ retry?: AllMatchesRetry,
1870
2448
  ): Promise<AgentToolResult<FileMutationBatchResult>> {
2449
+ if (failure.cause instanceof TextMutationInputError) {
2450
+ const inputError = failure.cause;
2451
+ let message = failure.message;
2452
+ if (inputError instanceof TextMutationAnchorCandidatesError && effect === "not-applied") {
2453
+ const candidates = await anchorCandidateContext(core, context, inputError.candidates);
2454
+ message +=
2455
+ candidates === undefined
2456
+ ? " No candidates to show. Use Read or Search to find a later match."
2457
+ : `\n\n${candidates}`;
2458
+ }
2459
+ return failureToolResult(failure.source, inputError.code, message, effect, failure.rollback);
2460
+ }
1871
2461
  if (failure.rollback !== undefined) {
1872
2462
  return failureToolResult(
1873
2463
  failure.source,
@@ -1880,7 +2470,7 @@ export async function buildFailedTextMutationResult(
1880
2470
  );
1881
2471
  }
1882
2472
  return effect === "not-applied"
1883
- ? ((await anchorFailureToolResult(core, failure, context)) ??
2473
+ ? ((await anchorFailureToolResult(core, failure, context, retry)) ??
1884
2474
  failureToolResult(failure.source, failure.code, failure.message, effect, failure.rollback))
1885
2475
  : failureToolResult(failure.source, failure.code, failure.message, effect, failure.rollback);
1886
2476
  }
@@ -1952,7 +2542,7 @@ function semanticActionResult(
1952
2542
  },
1953
2543
  };
1954
2544
  }
1955
- /** Write images named by Write content; returns undefined when the content is ordinary text. */
2545
+ /** Write the images named by Write `image`; returns undefined when the call writes text. */
1956
2546
  async function writeImageContent(
1957
2547
  core: TextEditorCore,
1958
2548
  store: ResultImageStore | undefined,
@@ -1962,7 +2552,7 @@ async function writeImageContent(
1962
2552
  ): Promise<AgentToolResult<FileMutationBatchResult> | undefined> {
1963
2553
  const target = typeof input.path === "string" ? input.path : "";
1964
2554
  try {
1965
- const files = await planImageWrite(input.path, input.content, store, cwd);
2555
+ const files = await planImageWrite(input.path, input.image, input.content, store, cwd);
1966
2556
  if (files === undefined) return undefined;
1967
2557
  await core.enqueueFileOperation(
1968
2558
  () => core.writeFiles(files, { cwd, ...(signal !== undefined && { signal }) }),
@@ -2087,6 +2677,13 @@ function asMutationParameters<TParameters extends TSchema>(value: unknown): Stat
2087
2677
  return value as Static<TParameters>;
2088
2678
  }
2089
2679
 
2680
+ function resultInputFailureCode(error: unknown): string {
2681
+ if (error instanceof ResourceError && error.code === "NO_EDITABLE_TEXT") return error.code;
2682
+ return (error as { code?: unknown } | null | undefined)?.code === "UNSAFE_TOKEN_SELECTION"
2683
+ ? "UNSAFE_TOKEN_SELECTION"
2684
+ : "RESULT_INPUT_REJECTED";
2685
+ }
2686
+
2090
2687
  function errorMessage(error: unknown): string {
2091
2688
  return error instanceof Error ? error.message : String(error);
2092
2689
  }