pi-agent-ide 0.6.4 → 0.7.1

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 (431) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
  4. package/dist/chunk-2TRHFMCZ.js +11 -0
  5. package/dist/{chunk-WJTHY6AG.js → chunk-4GCWGE2C.js} +1 -1
  6. package/dist/chunk-4XMY4H4V.js +1 -0
  7. package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
  8. package/dist/{chunk-QEJGED4V.js → chunk-76ZK5ODR.js} +2 -2
  9. package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
  10. package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
  11. package/dist/chunk-CWD4O5PM.js +3 -0
  12. package/dist/chunk-D3WTDA6V.js +2 -0
  13. package/dist/chunk-EAZGN5ND.js +7 -0
  14. package/dist/chunk-GXEGY7GV.js +1 -0
  15. package/dist/chunk-HZEY4GT4.js +2 -0
  16. package/dist/chunk-LEEQIQ7D.js +28 -0
  17. package/dist/chunk-NRZO5KJT.js +9 -0
  18. package/dist/chunk-OMVRLWMX.js +5 -0
  19. package/dist/{chunk-VBICI5YA.js → chunk-PGIVHICI.js} +1 -1
  20. package/dist/{chunk-FBOW7XOV.js → chunk-PKKDDIWW.js} +1 -1
  21. package/dist/chunk-PNU3E7IO.js +3 -0
  22. package/dist/chunk-PS2B6THP.js +3 -0
  23. package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
  24. package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
  25. package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
  26. package/dist/chunk-VMTR74FF.js +2 -0
  27. package/dist/{chunk-HPUAIWIH.js → chunk-WMO6RNE2.js} +1 -1
  28. package/dist/chunk-WU6ZK6YD.js +1 -0
  29. package/dist/{chunk-GIRAEVUJ.js → chunk-XH5WN5XA.js} +1 -1
  30. package/dist/chunk-XYS4FSCC.js +12 -0
  31. package/dist/chunk-YP46DVVP.js +2 -0
  32. package/dist/entry-11.js +1 -1
  33. package/dist/entry-13.js +1 -1
  34. package/dist/entry-14.js +1 -1
  35. package/dist/entry-15.js +1 -1
  36. package/dist/entry-17.js +1 -1
  37. package/dist/entry-25.js +2 -2
  38. package/dist/entry-26.js +1 -1
  39. package/dist/entry-27.js +2 -2
  40. package/dist/entry-28.js +1 -1
  41. package/dist/entry-29.js +1 -1
  42. package/dist/entry-30.js +1 -1
  43. package/dist/entry-31.js +12 -9
  44. package/dist/entry-33.js +1 -1
  45. package/dist/entry-37.js +6 -6
  46. package/dist/entry-41.js +1 -1
  47. package/dist/entry-42.js +1 -1
  48. package/dist/entry-43.js +1 -1
  49. package/dist/entry-44.js +1 -1
  50. package/dist/entry-45.js +13 -14
  51. package/dist/entry-46.js +1 -1
  52. package/dist/entry-49.js +1 -1
  53. package/dist/entry-50.js +3 -6
  54. package/dist/entry-51.js +11 -9
  55. package/dist/entry-52.js +1 -1
  56. package/dist/entry-53.js +1 -1
  57. package/dist/entry-54.js +1 -1
  58. package/dist/entry-56.js +1 -1
  59. package/dist/entry-57.js +1 -1
  60. package/dist/entry-58.js +1 -1
  61. package/dist/entry-60.js +1 -1
  62. package/dist/entry-61.js +0 -1
  63. package/dist/entry-62.js +1 -0
  64. package/dist/entry-63.js +0 -1
  65. package/dist/entry-64.js +1 -0
  66. package/dist/entry-65.js +1 -1
  67. package/dist/entry-66.js +1 -1
  68. package/dist/entry-67.js +1 -1
  69. package/dist/entry-68.js +1 -1
  70. package/dist/entry-69.js +1 -1
  71. package/dist/entry-70.js +1 -1
  72. package/dist/entry-71.js +0 -1
  73. package/dist/entry-72.js +1 -0
  74. package/dist/entry-73.js +0 -1
  75. package/dist/entry-74.js +1 -0
  76. package/dist/entry-75.js +1 -1
  77. package/dist/entry-76.js +1 -1
  78. package/dist/entry-77.js +66 -1
  79. package/dist/entry-78.js +14 -325
  80. package/dist/entry-79.js +2 -18
  81. package/dist/entry-80.js +1 -2
  82. package/dist/entry-81.js +1 -1
  83. package/dist/entry-82.js +5 -1
  84. package/dist/entry-83.js +3 -5
  85. package/dist/entry-84.js +1 -3
  86. package/dist/entry-85.js +1 -1
  87. package/dist/entry-86.js +1 -1
  88. package/dist/pi-agent-ide.js +14 -9
  89. package/docs/agent-guides/editing.md +38 -33
  90. package/docs/agent-guides/git-changes.md +1 -1
  91. package/docs/agent-guides/read-resources.md +8 -4
  92. package/docs/agent-guides/search-code.md +34 -2
  93. package/docs/agent-guides/select-code.md +115 -0
  94. package/docs/configuration.md +12 -17
  95. package/docs/development.md +2 -1
  96. package/docs/releases.md +1 -1
  97. package/docs/research/apply-native-capability-matrix.md +174 -0
  98. package/docs/research/apply-read-latency.md +2 -0
  99. package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
  100. package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
  101. package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
  102. package/docs/research/native-codemode-batch-decision.md +2 -0
  103. package/docs/research/native-codemode-batching.md +1 -1
  104. package/docs/structured-results.md +30 -38
  105. package/docs/tools.md +11 -11
  106. package/docs/user-hooks.md +1 -1
  107. package/node_modules/pi-agent-doctor/package.json +1 -1
  108. package/node_modules/pi-agent-documentation/package.json +1 -1
  109. package/node_modules/pi-agent-filesystem/index.ts +7 -6
  110. package/node_modules/pi-agent-filesystem/package.json +7 -7
  111. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  112. package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
  113. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  114. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  115. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  116. package/node_modules/pi-agent-ide-ast/package.json +15 -10
  117. package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  118. package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  119. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  120. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  121. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  122. package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -5
  123. package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  124. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  125. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  126. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
  127. package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
  128. package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
  129. package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
  130. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +268 -0
  131. package/node_modules/pi-agent-ide-changes/index.ts +6 -21
  132. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  133. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  134. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  135. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  136. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  137. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  138. package/node_modules/pi-agent-ide-lsp/index.ts +5 -5
  139. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  140. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  141. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  142. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  143. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  144. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  145. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  146. package/node_modules/pi-agent-image/package.json +2 -2
  147. package/node_modules/pi-agent-invariant/package.json +1 -1
  148. package/node_modules/pi-agent-pdf/package.json +2 -2
  149. package/node_modules/pi-agent-read/package.json +7 -7
  150. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  151. package/node_modules/pi-agent-read/src/api/read-parameters.ts +40 -3
  152. package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -1
  153. package/node_modules/pi-agent-read/src/core/extension.ts +18 -1
  154. package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
  155. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  156. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  157. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  158. package/node_modules/pi-agent-resource/package.json +1 -1
  159. package/node_modules/pi-agent-resource/src/index.ts +10 -0
  160. package/node_modules/pi-agent-resource/src/result-targets.ts +407 -0
  161. package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
  162. package/node_modules/pi-agent-search/package.json +5 -5
  163. package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
  164. package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
  165. package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
  166. package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
  167. package/node_modules/pi-agent-search/src/api/search.ts +28 -0
  168. package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
  169. package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
  170. package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
  171. package/node_modules/pi-agent-search-text/index.ts +3 -1
  172. package/node_modules/pi-agent-search-text/package.json +7 -6
  173. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  174. package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
  175. package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
  176. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
  177. package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
  178. package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
  179. package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
  180. package/node_modules/pi-agent-text/package.json +2 -2
  181. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  182. package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
  183. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  184. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  185. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
  186. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  187. package/node_modules/pi-agent-text-editor/index.ts +0 -5
  188. package/node_modules/pi-agent-text-editor/package.json +26 -31
  189. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
  190. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  191. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  192. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  193. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  194. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  195. package/node_modules/pi-agent-text-editor/src/core/extension.ts +22 -5
  196. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  197. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  198. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  199. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  200. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  201. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  202. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
  203. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  204. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  205. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  206. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  207. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  208. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  209. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  210. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  211. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  212. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  213. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  214. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  215. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  216. package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
  217. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  218. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  219. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  220. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  221. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  222. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  223. package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
  224. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  225. package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
  226. package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
  227. package/node_modules/pi-agent-web/index.ts +7 -3
  228. package/node_modules/pi-agent-web/package.json +8 -8
  229. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  230. package/node_modules/pi-agent-web/src/search.ts +111 -2
  231. package/node_modules/pi-agent-web-html/package.json +3 -3
  232. package/node_modules/pi-agent-web-image/package.json +4 -4
  233. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  234. package/node_modules/pi-agent-web-text/package.json +4 -4
  235. package/package.json +35 -36
  236. package/src/composite/module-labels.ts +1 -1
  237. package/src/composite/preferences.ts +0 -5
  238. package/src/composite/text-results.ts +221 -0
  239. package/src/documentation/extension.ts +11 -9
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  247. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +7 -3
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
  256. package/src/extensions/pi-agent-read/package.json +7 -7
  257. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  258. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +40 -3
  259. package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -1
  260. package/src/extensions/pi-agent-read/src/core/extension.ts +18 -1
  261. package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
  262. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  263. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
  264. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +17 -3
  265. package/src/extensions/pi-agent-search/package.json +5 -5
  266. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
  267. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
  268. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  269. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
  270. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
  271. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
  272. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
  273. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
  274. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
  275. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
  276. package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
  277. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
  278. package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
  279. package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
  280. package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
  281. package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
  282. package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
  283. package/src/extensions/pi-agent-text-editor/index.ts +0 -5
  284. package/src/extensions/pi-agent-text-editor/package.json +26 -31
  285. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  286. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
  287. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  288. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
  289. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
  290. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  291. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
  292. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  293. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  294. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  295. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  296. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  297. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
  298. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
  299. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  300. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  301. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  302. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  303. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +22 -5
  304. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  305. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -14
  306. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  307. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  308. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  309. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
  310. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
  311. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  312. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  313. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +86 -154
  314. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  315. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  316. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
  317. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
  318. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
  319. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  320. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  321. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  322. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  323. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  324. package/src/pi-agent-ide.ts +4 -7
  325. package/src/plugins/pi-agent-ide-ast/package.json +15 -10
  326. package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  327. package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  328. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  329. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  330. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  331. package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -5
  332. package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  333. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +142 -27
  334. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  335. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
  336. package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
  337. package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
  338. package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
  339. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +268 -0
  340. package/src/plugins/pi-agent-ide-changes/index.ts +6 -21
  341. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  342. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  343. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  344. package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
  345. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
  346. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  347. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  348. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  349. package/src/plugins/pi-agent-ide-lsp/index.ts +5 -5
  350. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  351. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  352. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  353. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  354. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  355. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  356. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
  357. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
  358. package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
  359. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
  360. package/src/plugins/pi-agent-ide-vision/index.ts +31 -4
  361. package/dist/chunk-2P2OGO3G.js +0 -2
  362. package/dist/chunk-5J43L2RL.js +0 -11
  363. package/dist/chunk-6EYWFBNG.js +0 -0
  364. package/dist/chunk-7AVXUV4A.js +0 -7
  365. package/dist/chunk-7WCZOO5I.js +0 -1
  366. package/dist/chunk-BAYETTZZ.js +0 -16
  367. package/dist/chunk-BVK5A7ED.js +0 -28
  368. package/dist/chunk-F7NVAC4Q.js +0 -0
  369. package/dist/chunk-FZBCKIJJ.js +0 -1
  370. package/dist/chunk-I5JLCFUX.js +0 -1
  371. package/dist/chunk-KUPHNMUK.js +0 -2
  372. package/dist/chunk-MIZAFRDR.js +0 -1
  373. package/dist/chunk-PJPA5EEE.js +0 -2
  374. package/dist/chunk-PXWDDBBC.js +0 -0
  375. package/dist/chunk-SILJ3OL4.js +0 -9
  376. package/dist/chunk-TQZBVOTT.js +0 -5
  377. package/dist/chunk-VWW3RLUX.js +0 -12
  378. package/dist/chunk-YHUTTZC6.js +0 -2
  379. package/dist/chunk-ZODCBFBL.js +0 -2
  380. package/dist/entry-87.js +0 -1
  381. package/docs/agent-guides/apply.md +0 -333
  382. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  383. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  384. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  385. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  386. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  387. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  388. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  389. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  390. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  391. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  392. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  393. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  394. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  395. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  396. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  397. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  398. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  399. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
  400. package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
  401. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
  402. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
  403. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  404. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
  405. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  406. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  407. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  408. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  409. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  410. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  411. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  412. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  413. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  414. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  415. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  416. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  417. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  418. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  419. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  420. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  421. /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  422. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  423. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
  424. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
  425. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  426. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  427. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  428. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  429. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  430. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  431. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
@@ -0,0 +1,22 @@
1
+ import type { ResolvedResultTargets } from "pi-agent-resource";
2
+ import { TextChangeDocument } from "./text-change-engine.js";
3
+
4
+ /** Require a verified selection of one complete file before a whole-file operation. */
5
+ export function wholeFileResultSource(result: ResolvedResultTargets): string {
6
+ const target = result.targets[0];
7
+ const range = target?.ranges[0];
8
+ if (result.targets.length !== 1 || target?.ranges.length !== 1 || range === undefined)
9
+ throw new Error("This operation requires one whole-file result target.");
10
+ const document = new TextChangeDocument(target.expectedContent);
11
+ const selected = document.range(
12
+ range.start.lineNumber,
13
+ range.start.column,
14
+ range.end.lineNumber,
15
+ range.end.column,
16
+ );
17
+ if (selected.from !== 0 || selected.to !== document.length)
18
+ throw new Error(
19
+ "This operation requires one whole-file result target; partial scopes are not widened.",
20
+ );
21
+ return target.source;
22
+ }
@@ -0,0 +1,78 @@
1
+ import type { ResultTargetStore } from "pi-agent-resource";
2
+ import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
3
+ import {
4
+ TEXT_SEARCH_ANCHOR_KIND,
5
+ type TextAnchorResolverRegistration,
6
+ } from "#src/api/plugin-protocol.js";
7
+
8
+ /** Resolve registered snapshot targets through the editor's normal source and anchor guards. */
9
+ export function createResultTargetAnchors(
10
+ store: ResultTargetStore,
11
+ ): TextAnchorResolverRegistration {
12
+ return {
13
+ kind: TEXT_SEARCH_ANCHOR_KIND,
14
+ type: "auxiliary",
15
+ describeInPrompt: false,
16
+ resolver: {
17
+ id: "result-targets",
18
+ description: "Use returned RESULT# references to target exact source snapshots.",
19
+ renderFull: (value) => value,
20
+ renderCompact: () => "result targets",
21
+ async tryResolve(value, context) {
22
+ if (!value.startsWith("RESULT#")) return { kind: "not-handled" };
23
+ try {
24
+ const target = store
25
+ .resolve(value, context.cwd)
26
+ .targets.find((target) => target.source === context.source);
27
+ if (target === undefined)
28
+ return {
29
+ kind: "rejected",
30
+ rejection: { code: "missing", reason: "Result does not select this source." },
31
+ };
32
+ if (target.expectedContent !== context.content)
33
+ return {
34
+ kind: "rejected",
35
+ rejection: { code: "stale", reason: "Result target is stale; repeat Read/Search." },
36
+ };
37
+ return {
38
+ kind: "resolved",
39
+ anchor: new TextSelectionAnchor(value, target.source, target.ranges),
40
+ };
41
+ } catch (error) {
42
+ return {
43
+ kind: "rejected",
44
+ rejection: {
45
+ code: "invalid",
46
+ reason: error instanceof Error ? error.message : String(error),
47
+ },
48
+ };
49
+ }
50
+ },
51
+ },
52
+ resources: {
53
+ id: "result-target-sources",
54
+ async tryResolve(value, context) {
55
+ if (!value.startsWith("RESULT#")) return { kind: "not-handled" };
56
+ try {
57
+ const selected = store.resolve(value, context.cwd);
58
+ await store.verify(selected, context.signal);
59
+ return selected.targets.length === 0
60
+ ? {
61
+ kind: "rejected",
62
+ rejection: { code: "missing", reason: "Empty result target set." },
63
+ }
64
+ : { kind: "resolved", targets: selected.targets };
65
+ } catch (error) {
66
+ context.signal?.throwIfAborted();
67
+ return {
68
+ kind: "rejected",
69
+ rejection: {
70
+ code: "stale",
71
+ reason: error instanceof Error ? error.message : String(error),
72
+ },
73
+ };
74
+ }
75
+ },
76
+ },
77
+ };
78
+ }
@@ -0,0 +1,175 @@
1
+ import type { ResolvedResultTargets, ResultTargetStore } from "pi-agent-resource";
2
+ import type {
3
+ TextMutation,
4
+ TextMutationContext,
5
+ TextMutationEdit,
6
+ } from "#src/api/mutation-tool.js";
7
+ import type { TextChange } from "./text-change-engine.js";
8
+ import {
9
+ anchorSpanRange,
10
+ insertionAfterAnchor,
11
+ replaceAnchorSpan,
12
+ } from "#src/tools/text-selection.js";
13
+ import { wholeFileResultSource } from "./result-input.js";
14
+
15
+ /** Distinguish structured source authority from ordinary paths and legacy anchors. */
16
+ export function isResultInput(value: unknown): boolean {
17
+ return value !== undefined && (typeof value !== "string" || value.startsWith("RESULT#"));
18
+ }
19
+
20
+ interface TransferSpan {
21
+ readonly source: string;
22
+ readonly from: number;
23
+ readonly to: number;
24
+ }
25
+
26
+ interface PreparedTransfer {
27
+ readonly input: Readonly<Record<string, unknown>>;
28
+ readonly empty: boolean;
29
+ readonly verifyFileSource?: () => Promise<void>;
30
+ readonly mutate?: (context: TextMutationContext) => Promise<TextMutation>;
31
+ }
32
+
33
+ /** Resolve ordered pairs once; execute them inside the editor's existing guarded snapshots. */
34
+ export async function prepareResultTransfer(
35
+ operation: "copy" | "move",
36
+ parameters: Readonly<Record<string, unknown>>,
37
+ store: ResultTargetStore,
38
+ cwd: string,
39
+ signal?: AbortSignal,
40
+ ): Promise<PreparedTransfer> {
41
+ const input = { ...parameters };
42
+ const resolve = async (field: "path" | "target", start: string, end: string) => {
43
+ if (!isResultInput(input[field])) return undefined;
44
+ if (input[start] !== undefined || input[end] !== undefined)
45
+ throw new Error(`Do not combine structured ${field} with ${start}/${end}.`);
46
+ const selected = store.resolveOrdered(input[field], cwd);
47
+ if (!selected.complete)
48
+ throw new Error(
49
+ "Incomplete result targets cannot establish a complete transfer; repeat Search.",
50
+ );
51
+ await store.verify(selected, signal);
52
+ input[field] = store.register(selected.targets, cwd);
53
+ return selected;
54
+ };
55
+ const source = await resolve("path", "start", "end");
56
+ const destination = await resolve("target", "targetStart", "targetEnd");
57
+ if (source === undefined && destination === undefined) return { input, empty: false };
58
+ if (
59
+ source !== undefined &&
60
+ destination === undefined &&
61
+ input.targetStart === undefined &&
62
+ input.targetEnd === undefined
63
+ ) {
64
+ // A structured source may use the byte-preserving file operation only when it really selects a whole file.
65
+ input.path = wholeFileResultSource(store.resolve(parameters.path, cwd));
66
+ return { input, empty: false, verifyFileSource: () => store.verify(source, signal) };
67
+ }
68
+ if (
69
+ source !== undefined &&
70
+ destination !== undefined &&
71
+ source.targets.length !== destination.targets.length
72
+ )
73
+ throw new Error(
74
+ "Transfer source and destination selection counts must match; no broadcast or concatenation.",
75
+ );
76
+ const empty = source?.targets.length === 0 || destination?.targets.length === 0;
77
+ return {
78
+ input,
79
+ empty,
80
+ async mutate(context) {
81
+ const spans = (selected: ResolvedResultTargets): TransferSpan[] =>
82
+ selected.targets.map((target) => {
83
+ const document = context.documentFor(target.source);
84
+ if (document.content !== target.expectedContent)
85
+ throw new Error("Transfer result target is stale; repeat Read/Search.");
86
+ const range = target.ranges[0];
87
+ if (range === undefined) throw new Error("Transfer selection has no range.");
88
+ return {
89
+ source: target.source,
90
+ ...document.range(
91
+ range.start.lineNumber,
92
+ range.start.column,
93
+ range.end.lineNumber,
94
+ range.end.column,
95
+ ),
96
+ };
97
+ });
98
+ const sources =
99
+ source === undefined
100
+ ? [
101
+ input.start === undefined
102
+ ? { source: context.sourceFor("path"), from: 0, to: context.sourceDocument.length }
103
+ : anchorSpanRange(
104
+ context,
105
+ await context.resolveAnchors("start"),
106
+ input.end === undefined ? undefined : await context.resolveAnchors("end"),
107
+ "start",
108
+ "end",
109
+ ),
110
+ ]
111
+ : spans(source);
112
+ const destinations = destination === undefined ? undefined : spans(destination);
113
+ if (sources.length !== (destinations?.length ?? 1))
114
+ throw new Error(
115
+ "Transfer source and destination selection counts must match; no broadcast or concatenation.",
116
+ );
117
+ const edits = new Map<string, TextMutationEdit>();
118
+ const append = (span: TransferSpan, change: TextChange, producesTarget: boolean) => {
119
+ const edit = edits.get(span.source);
120
+ const changes = [...(edit?.changes ?? []), change];
121
+ const resultChanges = [
122
+ ...(edit?.resultChanges ?? []),
123
+ ...(producesTarget ? [changes.length - 1] : []),
124
+ ];
125
+ edits.set(span.source, { action: "edited", changes, resultChanges });
126
+ };
127
+ const planned: { target: TransferSpan; change: TextChange }[] = [];
128
+ for (const [index, span] of sources.entries()) {
129
+ const copied = context.documentFor(span.source).text(span);
130
+ const destinationSpan = destinations?.[index];
131
+ if (destinationSpan !== undefined) {
132
+ planned.push({
133
+ target: destinationSpan,
134
+ change: { from: destinationSpan.from, to: destinationSpan.to, insert: copied },
135
+ });
136
+ continue;
137
+ }
138
+ const starts = await context.resolveAnchors("targetStart");
139
+ if (input.targetEnd === undefined) {
140
+ const [target, change] = insertionAfterAnchor(context, starts, "targetStart", copied);
141
+ planned.push({
142
+ target: { source: target, from: change.from, to: change.to },
143
+ change,
144
+ });
145
+ } else {
146
+ const target = anchorSpanRange(
147
+ context,
148
+ starts,
149
+ await context.resolveAnchors("targetEnd"),
150
+ "targetStart",
151
+ "targetEnd",
152
+ );
153
+ planned.push({
154
+ target,
155
+ change: replaceAnchorSpan(context, target, copied),
156
+ });
157
+ }
158
+ }
159
+ if (operation === "move") {
160
+ for (const sourceSpan of sources)
161
+ for (const transfer of planned)
162
+ if (
163
+ sourceSpan.source === transfer.target.source &&
164
+ sourceSpan.from <= transfer.target.to &&
165
+ transfer.target.from <= sourceSpan.to
166
+ )
167
+ throw new Error("Move target must not overlap or touch any source range.");
168
+ for (const span of sources)
169
+ append(span, { from: span.from, to: span.to, insert: "" }, false);
170
+ }
171
+ for (const transfer of planned) append(transfer.target, transfer.change, true);
172
+ return { edits };
173
+ },
174
+ };
175
+ }
@@ -1,5 +1,4 @@
1
1
  import { Type, type Static } from "typebox";
2
- import { Value } from "typebox/value";
3
2
  import {
4
3
  resultError,
5
4
  resultErrorSchema,
@@ -19,103 +18,58 @@ const effect = Type.Union([
19
18
  Type.Literal("unknown"),
20
19
  ]);
21
20
  const file = Type.Object(
22
- { source: Type.String(), effect, action: Type.Optional(Type.String()) },
23
- { additionalProperties: false },
24
- );
25
- const operation = Type.Object(
26
21
  {
27
- id: Type.String(),
28
- operation: Type.String(),
22
+ source: Type.String(),
29
23
  effect,
30
- errors: Type.Array(resultErrorSchema),
31
- status: Type.Optional(
32
- Type.Union([
33
- Type.Literal("success"),
34
- Type.Literal("error"),
35
- Type.Literal("warning"),
36
- Type.Literal("unknown"),
37
- ]),
24
+ state: Type.Optional(
25
+ Type.Union([Type.Literal("present"), Type.Literal("absent"), Type.Literal("unknown")]),
38
26
  ),
39
- sources: Type.Optional(Type.Array(Type.String())),
40
- warnings: Type.Optional(Type.Array(resultErrorSchema)),
41
27
  },
42
28
  { additionalProperties: false },
43
29
  );
44
- export const mutationDataSchema = Type.Object(
45
- {
46
- operation: Type.String(),
47
- effect,
48
- operationId: Type.Optional(Type.String()),
49
- files: Type.Array(file),
50
- operations: Type.Optional(Type.Array(operation)),
51
- parentToolCallId: Type.Optional(Type.String()),
52
- transaction: Type.Optional(Type.String()),
53
- transactions: Type.Optional(Type.Array(Type.String())),
54
- recovery: Type.Optional(
55
- Type.Array(
56
- Type.Object({
57
- source: Type.String(),
58
- field: Type.String(),
59
- anchor: Type.String(),
60
- total: Type.Integer(),
61
- candidates: Type.Array(
62
- Type.Object({
63
- rank: Type.Integer(),
64
- range: Type.Object({
65
- start: Type.Object({ lineNumber: Type.Integer(), column: Type.Integer() }),
66
- end: Type.Object({ lineNumber: Type.Integer(), column: Type.Integer() }),
67
- }),
68
- }),
69
- ),
70
- }),
71
- ),
72
- ),
73
- action: Type.Optional(
74
- Type.Object(
75
- {
76
- source: Type.String(),
77
- kind: Type.Optional(Type.String()),
78
- status: Type.Optional(Type.String()),
79
- command: Type.Optional(Type.String()),
80
- deleted: Type.Optional(Type.Boolean()),
81
- session: Type.Optional(Type.String()),
82
- file: Type.Optional(Type.String()),
83
- line: Type.Optional(Type.Integer()),
84
- verified: Type.Optional(Type.Boolean()),
85
- evaluation: Type.Optional(
86
- Type.Object(
87
- {
88
- expression: Type.String(),
89
- result: Type.String(),
90
- type: Type.Optional(Type.String()),
91
- variablesReference: Type.Integer(),
92
- },
93
- { additionalProperties: false },
94
- ),
95
- ),
96
- breakpoints: Type.Optional(
97
- Type.Array(
98
- Type.Object(
99
- {
100
- source: Type.String(),
101
- file: Type.String(),
102
- line: Type.Integer(),
103
- verified: Type.Boolean(),
104
- },
105
- { additionalProperties: false },
106
- ),
107
- ),
108
- ),
109
- },
110
- { additionalProperties: false },
111
- ),
112
- ),
113
- },
30
+ const receipt = { effect, files: Type.Array(file) };
31
+
32
+ /** Validate one file tool's result. Recovery, rendering and resource actions stay in details. */
33
+ export function mutationDataSchema(operation: string) {
34
+ return Type.Object(
35
+ {
36
+ operation: Type.Literal(operation),
37
+ ...receipt,
38
+ operationId: Type.Optional(Type.String()),
39
+ ...(operation === "delete" || operation === "flush"
40
+ ? {}
41
+ : {
42
+ target: Type.Optional(Type.String()),
43
+ targetUnavailable: Type.Optional(Type.String()),
44
+ }),
45
+ },
46
+ { additionalProperties: false },
47
+ );
48
+ }
49
+ /** Internal validation schema for a single tool, not an agent-facing return declaration. */
50
+ export function mutationResultSchema(operation: string) {
51
+ return structuredResultSchema(mutationDataSchema(operation));
52
+ }
53
+ const batchOperation = Type.Object(
54
+ { id: Type.String(), operation: Type.String(), effect, errors: Type.Array(resultErrorSchema) },
55
+ { additionalProperties: false },
56
+ );
57
+ /** Flush owns the batch journal; individual file tools do not carry it. */
58
+ export const flushDataSchema = Type.Object(
59
+ { operation: Type.Literal("flush"), ...receipt, operations: Type.Array(batchOperation) },
114
60
  { additionalProperties: false },
115
61
  );
116
- export const mutationOutputSchema = structuredResultSchema(mutationDataSchema);
117
- /** Public receipt fields are defined by the native output schema. */
118
- export type MutationData = Static<typeof mutationDataSchema>;
62
+ export const flushOutputSchema = structuredResultSchema(flushDataSchema);
63
+ export type FlushData = Static<typeof flushDataSchema>;
64
+ /** Small internal receipt used to collect observed file effects. */
65
+ export interface MutationData {
66
+ operation: string;
67
+ effect: Static<typeof effect>;
68
+ files: Static<typeof file>[];
69
+ operationId?: string;
70
+ target?: string;
71
+ targetUnavailable?: string;
72
+ }
119
73
  type MutationFile = MutationData["files"][number];
120
74
  function record(value: unknown): value is Record<string, unknown> {
121
75
  return typeof value === "object" && value !== null;
@@ -137,13 +91,13 @@ export function mutationOutcome(
137
91
  data: {
138
92
  operation,
139
93
  effect: "pending",
94
+ ...(operation !== "delete" && typeof details.metadata?.resultTarget === "string"
95
+ ? { target: details.metadata.resultTarget }
96
+ : {}),
140
97
  files:
141
98
  typeof detailRecord.source === "string"
142
99
  ? [{ source: detailRecord.source, effect: "pending" }]
143
100
  : [],
144
- ...(typeof native.parentToolCallId === "string"
145
- ? { parentToolCallId: native.parentToolCallId }
146
- : {}),
147
101
  },
148
102
  };
149
103
  const observed = new Set(completions.map((completion) => completion.resourceSource));
@@ -161,6 +115,7 @@ export function mutationOutcome(
161
115
  for (const source of sources)
162
116
  files.push({
163
117
  source,
118
+ ...(observed.has(source) ? { state: "present" as const } : {}),
164
119
  effect:
165
120
  observed.has(source) ||
166
121
  (data.ok === true && data.files?.some((file) => file.path === source))
@@ -181,7 +136,8 @@ export function mutationOutcome(
181
136
  });
182
137
  }
183
138
  for (const source of observed)
184
- if (!files.some((file) => file.source === source)) files.push({ source, effect: "applied" });
139
+ if (!files.some((file) => file.source === source))
140
+ files.push({ source, effect: "applied", state: "present" });
185
141
  const semantic =
186
142
  record(details.metadata) && record(details.metadata.semanticAction)
187
143
  ? details.metadata.semanticAction
@@ -194,19 +150,30 @@ export function mutationOutcome(
194
150
  ? "unknown"
195
151
  : "applied";
196
152
  const source = typeof semantic.source === "string" ? semantic.source : undefined;
197
- if (source && !Array.isArray(semantic.restored))
153
+ if (source)
198
154
  files.push({
199
155
  source,
156
+ ...(semantic.kind === "file-operation" && semantic.ok === true
157
+ ? {
158
+ state:
159
+ operation === "delete" || operation === "move"
160
+ ? ("absent" as const)
161
+ : ("present" as const),
162
+ }
163
+ : {}),
200
164
  effect:
201
165
  operation === "copy" && typeof semantic.target === "string" && semantic.target !== source
202
166
  ? "not-applied"
203
167
  : semanticEffect,
204
168
  });
205
- if (Array.isArray(semantic.restored))
206
- for (const source of semantic.restored)
207
- if (typeof source === "string") files.push({ source, effect: semanticEffect });
208
169
  if (typeof semantic.target === "string")
209
- files.push({ source: semantic.target, effect: semanticEffect });
170
+ files.push({
171
+ source: semantic.target,
172
+ effect: semanticEffect,
173
+ ...(semantic.kind === "file-operation" && semantic.ok === true
174
+ ? { state: "present" as const }
175
+ : {}),
176
+ });
210
177
  if (record(semantic.error))
211
178
  errors.push(
212
179
  resultError(
@@ -221,10 +188,22 @@ export function mutationOutcome(
221
188
  errors.push(resultError("Resource operation failed", "MUTATION_FAILED", source));
222
189
  }
223
190
  const unique = [...new Map(files.map((file) => [file.source, file])).values()];
191
+ if (Array.isArray(details.metadata?.resultFileStates))
192
+ for (const state of details.metadata.resultFileStates) {
193
+ if (!record(state)) continue;
194
+ const file = unique.find((file) => file.source === state.source);
195
+ if (file && (state.state === "present" || state.state === "absent")) file.state = state.state;
196
+ }
224
197
  const known = unique.some((file) => file.effect === "applied");
225
198
  if (result.isError && errors.length === 0)
226
199
  errors.push({ code: "MUTATION_FAILED", message: "Mutation failed" });
227
- if ((results?.length ?? 0) === 0 && !semantic && observed.size === 0 && errors.length === 0)
200
+ if (
201
+ (results?.length ?? 0) === 0 &&
202
+ !semantic &&
203
+ observed.size === 0 &&
204
+ errors.length === 0 &&
205
+ details.effect !== "not-applied"
206
+ )
228
207
  errors.push({ code: "UNKNOWN_RESULT", message: "Mutation effects were not reported" });
229
208
  const effect =
230
209
  unique.some((file) => file.effect === "unknown") ||
@@ -233,46 +212,6 @@ export function mutationOutcome(
233
212
  : known
234
213
  ? "applied"
235
214
  : "not-applied";
236
- const action =
237
- semantic && typeof semantic.source === "string"
238
- ? {
239
- source: semantic.source,
240
- ...(typeof semantic.kind === "string" ? { kind: semantic.kind } : {}),
241
- ...(typeof semantic.status === "string" ? { status: semantic.status } : {}),
242
- ...(typeof semantic.command === "string" ? { command: semantic.command } : {}),
243
- ...(typeof semantic.deleted === "boolean" ? { deleted: semantic.deleted } : {}),
244
- ...(typeof semantic.session === "string" ? { session: semantic.session } : {}),
245
- ...(typeof semantic.file === "string" ? { file: semantic.file } : {}),
246
- ...(typeof semantic.line === "number" ? { line: semantic.line } : {}),
247
- ...(typeof semantic.verified === "boolean" ? { verified: semantic.verified } : {}),
248
- ...(record(semantic.evaluation)
249
- ? {
250
- evaluation: {
251
- expression: semantic.evaluation.expression,
252
- result: semantic.evaluation.result,
253
- variablesReference: semantic.evaluation.variablesReference,
254
- ...(typeof semantic.evaluation.type === "string"
255
- ? { type: semantic.evaluation.type }
256
- : {}),
257
- },
258
- }
259
- : {}),
260
- ...(Array.isArray(semantic.breakpoints)
261
- ? {
262
- breakpoints: semantic.breakpoints.filter(record).map((breakpoint) => ({
263
- source: breakpoint.source,
264
- file: breakpoint.file,
265
- line: breakpoint.line,
266
- verified: breakpoint.verified,
267
- })),
268
- }
269
- : {}),
270
- }
271
- : undefined;
272
- const checkedAction =
273
- action && Value.Check(mutationDataSchema.properties.action, action) ? action : undefined;
274
- if (action && !checkedAction)
275
- errors.push(resultError("Action adapter returned invalid fields", "INVALID_STRUCTURED_RESULT"));
276
215
  return {
277
216
  status:
278
217
  errors.length === 0
@@ -284,19 +223,12 @@ export function mutationOutcome(
284
223
  operation,
285
224
  effect,
286
225
  files: unique,
287
- ...(details.anchorRecoveries === undefined
288
- ? {}
289
- : {
290
- recovery: details.anchorRecoveries.map((item) => ({
291
- source: item.path,
292
- field: item.field,
293
- anchor: item.anchor,
294
- total: item.total,
295
- candidates: [...item.candidates],
296
- })),
297
- }),
298
- ...(typeof semantic?.transaction === "string" ? { transaction: semantic.transaction } : {}),
299
- ...(checkedAction ? { action: checkedAction } : {}),
226
+ ...(operation !== "delete" && typeof details.metadata?.resultTarget === "string"
227
+ ? { target: details.metadata.resultTarget }
228
+ : {}),
229
+ ...(operation !== "delete" && typeof details.metadata?.targetUnavailable === "string"
230
+ ? { targetUnavailable: details.metadata.targetUnavailable }
231
+ : {}),
300
232
  },
301
233
  errors,
302
234
  };
@@ -310,5 +242,5 @@ export function structuredMutation(
310
242
  ) {
311
243
  const outcome = mutationOutcome(result, operation, completions);
312
244
  if (outcome.data && operationId !== undefined) outcome.data.operationId = operationId;
313
- return withStructuredResult(result, mutationDataSchema, outcome);
245
+ return withStructuredResult(result, mutationDataSchema(operation), outcome);
314
246
  }
@@ -418,7 +418,12 @@ export async function executeRegisteredTextBatch(
418
418
  return [];
419
419
  }
420
420
 
421
- const ownAfter = applyTextChanges(resource.before.content, edit.changes).content;
421
+ // The core already validated the write; a created empty resource has no text delta.
422
+ const ownAfter = applyTextChanges(
423
+ resource.before.content,
424
+ edit.changes,
425
+ resource.before.content.length === 0,
426
+ ).content;
422
427
  return [
423
428
  buildSuccessfulTextMutationResult(
424
429
  resource,