pi-agent-ide 0.6.4 → 0.7.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 (395) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
  4. package/dist/{chunk-QEJGED4V.js → chunk-3HYXQ4YA.js} +1 -1
  5. package/dist/chunk-3JO7QFIL.js +1 -0
  6. package/dist/{chunk-5J43L2RL.js → chunk-4NIFBFFR.js} +1 -1
  7. package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
  8. package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
  9. package/dist/chunk-7LZKOHH2.js +1 -0
  10. package/dist/chunk-AJRIASPQ.js +2 -0
  11. package/dist/chunk-EAZGN5ND.js +7 -0
  12. package/dist/{chunk-GIRAEVUJ.js → chunk-F5YZG77W.js} +1 -1
  13. package/dist/chunk-FK42RSF4.js +1 -0
  14. package/dist/{chunk-WJTHY6AG.js → chunk-FXNKMNSJ.js} +1 -1
  15. package/dist/chunk-GBLKIB6O.js +2 -0
  16. package/dist/{chunk-KUPHNMUK.js → chunk-KBP3QUDT.js} +1 -1
  17. package/dist/{chunk-VBICI5YA.js → chunk-KR36BT5E.js} +1 -1
  18. package/dist/chunk-OE7QVAI2.js +5 -0
  19. package/dist/chunk-PNU3E7IO.js +3 -0
  20. package/dist/chunk-PS2B6THP.js +3 -0
  21. package/dist/{chunk-HPUAIWIH.js → chunk-PYPPV2F5.js} +1 -1
  22. package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
  23. package/dist/chunk-S5LXX32D.js +28 -0
  24. package/dist/chunk-SQKAXYIR.js +2 -0
  25. package/dist/chunk-VCGNVTXQ.js +1 -0
  26. package/dist/chunk-XYS4FSCC.js +12 -0
  27. package/dist/{chunk-FBOW7XOV.js → chunk-YRF7OATP.js} +1 -1
  28. package/dist/entry-11.js +1 -1
  29. package/dist/entry-13.js +1 -1
  30. package/dist/entry-14.js +1 -1
  31. package/dist/entry-15.js +1 -1
  32. package/dist/entry-17.js +1 -1
  33. package/dist/entry-25.js +1 -1
  34. package/dist/entry-26.js +1 -1
  35. package/dist/entry-28.js +1 -1
  36. package/dist/entry-29.js +1 -1
  37. package/dist/entry-30.js +1 -1
  38. package/dist/entry-31.js +13 -11
  39. package/dist/entry-33.js +1 -1
  40. package/dist/entry-37.js +6 -6
  41. package/dist/entry-42.js +1 -1
  42. package/dist/entry-44.js +1 -1
  43. package/dist/entry-45.js +13 -13
  44. package/dist/entry-46.js +1 -1
  45. package/dist/entry-49.js +1 -1
  46. package/dist/entry-50.js +3 -6
  47. package/dist/entry-51.js +11 -9
  48. package/dist/entry-52.js +1 -1
  49. package/dist/entry-53.js +1 -1
  50. package/dist/entry-54.js +1 -1
  51. package/dist/entry-56.js +1 -1
  52. package/dist/entry-58.js +1 -1
  53. package/dist/entry-60.js +1 -1
  54. package/dist/entry-61.js +0 -1
  55. package/dist/entry-62.js +1 -0
  56. package/dist/entry-63.js +0 -1
  57. package/dist/entry-64.js +1 -0
  58. package/dist/entry-65.js +1 -1
  59. package/dist/entry-66.js +1 -1
  60. package/dist/entry-67.js +1 -1
  61. package/dist/entry-68.js +1 -1
  62. package/dist/entry-69.js +1 -1
  63. package/dist/entry-70.js +1 -1
  64. package/dist/entry-71.js +0 -1
  65. package/dist/entry-72.js +1 -0
  66. package/dist/entry-73.js +0 -1
  67. package/dist/entry-74.js +1 -0
  68. package/dist/entry-75.js +1 -1
  69. package/dist/entry-76.js +1 -1
  70. package/dist/entry-77.js +67 -1
  71. package/dist/entry-78.js +14 -325
  72. package/dist/entry-79.js +2 -18
  73. package/dist/entry-80.js +1 -2
  74. package/dist/entry-81.js +1 -1
  75. package/dist/entry-82.js +5 -1
  76. package/dist/entry-83.js +3 -5
  77. package/dist/entry-84.js +1 -3
  78. package/dist/entry-85.js +1 -1
  79. package/dist/entry-86.js +1 -1
  80. package/dist/pi-agent-ide.js +5 -5
  81. package/docs/agent-guides/editing.md +20 -4
  82. package/docs/agent-guides/git-changes.md +1 -1
  83. package/docs/agent-guides/read-resources.md +9 -1
  84. package/docs/agent-guides/search-code.md +38 -1
  85. package/docs/agent-guides/select-code.md +194 -0
  86. package/docs/configuration.md +12 -17
  87. package/docs/development.md +2 -1
  88. package/docs/releases.md +1 -1
  89. package/docs/research/apply-native-capability-matrix.md +174 -0
  90. package/docs/research/apply-read-latency.md +2 -0
  91. package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
  92. package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
  93. package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
  94. package/docs/research/native-codemode-batch-decision.md +2 -0
  95. package/docs/research/native-codemode-batching.md +1 -1
  96. package/docs/structured-results.md +32 -5
  97. package/docs/tools.md +6 -2
  98. package/docs/user-hooks.md +1 -1
  99. package/node_modules/pi-agent-doctor/package.json +1 -1
  100. package/node_modules/pi-agent-documentation/package.json +1 -1
  101. package/node_modules/pi-agent-filesystem/package.json +7 -7
  102. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  103. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  104. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  105. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  106. package/node_modules/pi-agent-ide-ast/package.json +15 -10
  107. package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  108. package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  109. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  110. package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  111. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  112. package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -2
  113. package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  114. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +107 -21
  115. package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  116. package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
  117. package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
  118. package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
  119. package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
  120. package/node_modules/pi-agent-ide-ast/src/tool-select.ts +251 -0
  121. package/node_modules/pi-agent-ide-changes/index.ts +2 -18
  122. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  123. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  124. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  125. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  126. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  127. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  128. package/node_modules/pi-agent-ide-lsp/index.ts +2 -2
  129. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  130. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  131. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  132. package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  133. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  134. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  135. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +88 -45
  136. package/node_modules/pi-agent-image/package.json +2 -2
  137. package/node_modules/pi-agent-invariant/package.json +1 -1
  138. package/node_modules/pi-agent-pdf/package.json +2 -2
  139. package/node_modules/pi-agent-read/package.json +7 -7
  140. package/node_modules/pi-agent-read/src/api/read-parameters.ts +2 -2
  141. package/node_modules/pi-agent-read/src/api/tools/read.ts +4 -0
  142. package/node_modules/pi-agent-read/src/core/extension.ts +11 -0
  143. package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  144. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +2 -0
  145. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +8 -1
  146. package/node_modules/pi-agent-resource/package.json +1 -1
  147. package/node_modules/pi-agent-resource/src/index.ts +10 -0
  148. package/node_modules/pi-agent-resource/src/result-targets.ts +233 -0
  149. package/node_modules/pi-agent-search/package.json +5 -5
  150. package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
  151. package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
  152. package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
  153. package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
  154. package/node_modules/pi-agent-search/src/api/search.ts +28 -0
  155. package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
  156. package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
  157. package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
  158. package/node_modules/pi-agent-search-text/index.ts +3 -1
  159. package/node_modules/pi-agent-search-text/package.json +7 -6
  160. package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  161. package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
  162. package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
  163. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
  164. package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
  165. package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
  166. package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
  167. package/node_modules/pi-agent-text/package.json +2 -2
  168. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  169. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  170. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  171. package/node_modules/pi-agent-text-editor/index.ts +0 -5
  172. package/node_modules/pi-agent-text-editor/package.json +26 -31
  173. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
  174. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  175. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  176. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  177. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  178. package/node_modules/pi-agent-text-editor/src/core/extension.ts +12 -2
  179. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  180. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +1 -1
  181. package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  182. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  183. package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  184. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +199 -19
  185. package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
  186. package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  187. package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  188. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +109 -11
  189. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  190. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  191. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +211 -223
  192. package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  195. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  196. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  197. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  198. package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
  199. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  200. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  201. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  202. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  203. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  204. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
  205. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  206. package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
  207. package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
  208. package/node_modules/pi-agent-web/index.ts +3 -0
  209. package/node_modules/pi-agent-web/package.json +8 -8
  210. package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
  211. package/node_modules/pi-agent-web/src/search.ts +111 -2
  212. package/node_modules/pi-agent-web-html/package.json +3 -3
  213. package/node_modules/pi-agent-web-image/package.json +4 -4
  214. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  215. package/node_modules/pi-agent-web-text/package.json +4 -4
  216. package/package.json +35 -36
  217. package/src/composite/module-labels.ts +1 -1
  218. package/src/composite/preferences.ts +0 -5
  219. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  220. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  221. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  222. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  223. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  224. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +3 -0
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  230. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  231. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
  232. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
  233. package/src/extensions/pi-agent-read/package.json +7 -7
  234. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
  235. package/src/extensions/pi-agent-read/src/api/tools/read.ts +4 -0
  236. package/src/extensions/pi-agent-read/src/core/extension.ts +11 -0
  237. package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
  238. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +2 -0
  239. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +8 -1
  240. package/src/extensions/pi-agent-search/package.json +5 -5
  241. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
  242. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
  243. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
  244. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
  245. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
  246. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
  247. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
  248. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
  249. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
  250. package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
  251. package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
  252. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
  253. package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
  254. package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
  255. package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
  256. package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
  257. package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
  258. package/src/extensions/pi-agent-text-editor/index.ts +0 -5
  259. package/src/extensions/pi-agent-text-editor/package.json +26 -31
  260. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  261. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  262. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
  268. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  269. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
  270. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
  271. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
  272. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
  273. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
  274. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +12 -2
  275. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
  276. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +1 -1
  277. package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
  278. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
  279. package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
  280. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +199 -19
  281. package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
  282. package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
  283. package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
  284. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +109 -11
  285. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
  286. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
  287. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +211 -223
  288. package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
  289. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
  290. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
  291. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
  292. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
  293. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
  294. package/src/pi-agent-ide.ts +0 -6
  295. package/src/plugins/pi-agent-ide-ast/package.json +15 -10
  296. package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
  297. package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
  298. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
  299. package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
  300. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
  301. package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -2
  302. package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
  303. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +107 -21
  304. package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
  305. package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
  306. package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
  307. package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
  308. package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
  309. package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +251 -0
  310. package/src/plugins/pi-agent-ide-changes/index.ts +2 -18
  311. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  312. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
  313. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
  314. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  315. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  316. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  317. package/src/plugins/pi-agent-ide-lsp/index.ts +2 -2
  318. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  319. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
  320. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
  321. package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
  322. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
  323. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
  324. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +88 -45
  325. package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
  326. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
  327. package/src/plugins/pi-agent-ide-vision/index.ts +19 -0
  328. package/dist/chunk-2P2OGO3G.js +0 -2
  329. package/dist/chunk-6EYWFBNG.js +0 -0
  330. package/dist/chunk-7AVXUV4A.js +0 -7
  331. package/dist/chunk-7WCZOO5I.js +0 -1
  332. package/dist/chunk-BAYETTZZ.js +0 -16
  333. package/dist/chunk-BVK5A7ED.js +0 -28
  334. package/dist/chunk-F7NVAC4Q.js +0 -0
  335. package/dist/chunk-FZBCKIJJ.js +0 -1
  336. package/dist/chunk-I5JLCFUX.js +0 -1
  337. package/dist/chunk-MIZAFRDR.js +0 -1
  338. package/dist/chunk-PJPA5EEE.js +0 -2
  339. package/dist/chunk-PXWDDBBC.js +0 -0
  340. package/dist/chunk-TQZBVOTT.js +0 -5
  341. package/dist/chunk-VWW3RLUX.js +0 -12
  342. package/dist/chunk-YHUTTZC6.js +0 -2
  343. package/dist/chunk-ZODCBFBL.js +0 -2
  344. package/dist/entry-87.js +0 -1
  345. package/docs/agent-guides/apply.md +0 -333
  346. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  347. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  348. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  349. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  350. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  351. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  352. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  353. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  354. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  355. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  356. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  357. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  358. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  359. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  360. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  361. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  362. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  363. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
  364. package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
  365. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
  366. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
  367. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
  368. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
  369. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
  370. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
  371. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
  372. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
  373. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
  374. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
  375. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
  376. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
  377. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
  378. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
  379. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
  380. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
  381. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
  382. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
  383. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
  384. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
  385. /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
  386. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
  387. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
  388. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
  389. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
  390. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
  391. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
  392. /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
  393. /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
  394. /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
  395. /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
@@ -1,203 +0,0 @@
1
- import { parser } from "@lezer/javascript";
2
- import { TreeFragment, type Tree } from "@lezer/common";
3
-
4
- const helpers = new Set([
5
- "read",
6
- "search",
7
- "diff",
8
- "open",
9
- "createFile",
10
- "deleteFile",
11
- "copyFile",
12
- "moveFile",
13
- "flush",
14
- "result",
15
- ]);
16
-
17
- /** Bounded source expression; literal does not imply the operation has executed. */
18
- export interface PreviewArgument {
19
- readonly text: string;
20
- readonly literal: boolean;
21
- }
22
- /** A written call preview, never evidence that the call executed. */
23
- export interface ApplyCallPreview {
24
- readonly name: string;
25
- readonly from: number;
26
- readonly to: number;
27
- readonly path?: PreviewArgument;
28
- readonly query?: PreviewArgument;
29
- readonly target?: PreviewArgument;
30
- readonly before?: PreviewArgument;
31
- readonly after?: PreviewArgument;
32
- readonly arguments: Readonly<Record<string, PreviewArgument>>;
33
- }
34
-
35
- /** Recover helper calls from incomplete JavaScript without evaluating arguments. */
36
- export function parseApplyCalls(
37
- source: string,
38
- tree: Tree = parser.parse(source),
39
- ): ApplyCallPreview[] {
40
- const shadows: { name: string; from: number; to: number }[] = [];
41
- tree.iterate({
42
- enter(node) {
43
- if (node.name === "AssignmentExpression") {
44
- const target = node.node.firstChild;
45
- if (target?.name === "VariableName")
46
- shadows.push({ name: source.slice(target.from, target.to), from: 0, to: source.length });
47
- }
48
- if (node.name !== "VariableDefinition") return;
49
- let declaration = node.node.parent;
50
- while (
51
- declaration?.parent &&
52
- !["VariableDeclaration", "ParamList", "Block", "Script"].includes(declaration.name)
53
- )
54
- declaration = declaration.parent;
55
- const hoisted =
56
- declaration?.name === "VariableDeclaration" && declaration.firstChild?.name === "var";
57
- const boundaries = new Set([
58
- "Script",
59
- "FunctionDeclaration",
60
- "FunctionExpression",
61
- "ArrowFunction",
62
- ...(hoisted ? [] : ["Block"]),
63
- ]);
64
- let scope = node.node.parent;
65
- if (scope?.name === "FunctionDeclaration") scope = scope.parent;
66
- while (scope?.parent && !boundaries.has(scope.name)) scope = scope.parent;
67
- shadows.push({
68
- name: source.slice(node.from, node.to),
69
- from: scope?.from ?? 0,
70
- to: scope?.to ?? source.length,
71
- });
72
- },
73
- });
74
- const calls: ApplyCallPreview[] = [];
75
- tree.iterate({
76
- enter(node) {
77
- if (node.name !== "CallExpression") return;
78
- const callee = node.node.firstChild;
79
- if (callee?.name !== "VariableName") return;
80
- const name = source.slice(callee.from, callee.to);
81
- if (
82
- !helpers.has(name) ||
83
- shadows.some(
84
- (binding) => binding.name === name && binding.from <= node.from && binding.to >= node.to,
85
- )
86
- )
87
- return;
88
- const object = node.node.getChild("ArgList")?.getChild("ObjectExpression");
89
- const fields = Object.create(null) as Record<string, PreviewArgument>;
90
- if (!object) {
91
- const args = node.node.getChild("ArgList");
92
- const raw = args ? source.slice(args.from + 1, args.to).replace(/\)$/, "") : "";
93
- if (raw)
94
- fields.arguments = {
95
- text: raw.length > 160 ? raw.slice(0, 120) + "…" : raw,
96
- literal: false,
97
- };
98
- }
99
- for (const property of object?.getChildren("Property") ?? []) {
100
- const key = property.firstChild;
101
- const rawKey = key ? source.slice(key.from, key.to) : "";
102
- const field = rawKey.replace(/^["']|["']$/g, "");
103
- if (!/^[a-zA-Z_$][\w$]*$/.test(field)) {
104
- // Computed keys and spreads can replace any earlier identity argument.
105
- for (const identity of ["path", "query", "target", "before", "after"])
106
- delete fields[identity];
107
- const raw = source.slice(property.from, property.to);
108
- fields[`argument@${property.from}`] = {
109
- text: raw.length > 160 ? raw.slice(0, 160) + "…" : raw,
110
- literal: false,
111
- };
112
- continue;
113
- }
114
- const value = property.lastChild;
115
- if (!value || value.type.isError || value.name === ":") continue;
116
- const raw = source.slice(value.from, value.to);
117
- const singleLine = raw.replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\t/g, "\\t");
118
- const anchor =
119
- /^(?:["'])(?:\d+#[0-9A-F]+|CHANGE#[0-9A-F]+|begin|end|scope-(?:begin|end)-[^"']+)["']$/.test(
120
- raw,
121
- );
122
- fields[field] = {
123
- text:
124
- singleLine.length > 160 && !anchor
125
- ? `${singleLine.slice(0, 100)}…${singleLine.slice(-40)} (${raw.length} source chars)`
126
- : singleLine,
127
- literal:
128
- ["String", "Number", "BooleanLiteral", "Null"].includes(value.name) &&
129
- value.lastChild?.type.isError !== true,
130
- };
131
- }
132
- calls.push({
133
- name,
134
- from: node.from,
135
- to: node.to,
136
- path: fields.path,
137
- query: fields.query,
138
- target: fields.target,
139
- before: fields.before,
140
- after: fields.after,
141
- arguments: fields,
142
- });
143
- return false;
144
- },
145
- });
146
- return calls;
147
- }
148
-
149
- /** Compact written calls only; source and execution are never changed. */
150
- export function compactApplySource(
151
- source: string,
152
- calls = parseApplyCalls(source),
153
- renderCall?: (call: ApplyCallPreview) => string,
154
- renderCode: (source: string) => string = (source) => source,
155
- ): string {
156
- let cursor = 0;
157
- const parts: string[] = [];
158
- const codePreview = (text: string) =>
159
- renderCode(
160
- text
161
- .split("\n")
162
- .map((line) => (line.length > 200 ? line.slice(0, 200) + "…" : line))
163
- .join("\n"),
164
- );
165
- for (const call of calls) {
166
- parts.push(codePreview(source.slice(cursor, call.from)));
167
- parts.push(
168
- renderCall?.(call) ??
169
- `${call.name}(${call.path ? (call.path.literal ? call.path.text : `‹${call.path.text}›`) : "…"})`,
170
- );
171
- cursor = call.to;
172
- }
173
- parts.push(codePreview(source.slice(cursor)));
174
- return parts.join("");
175
- }
176
-
177
- /** Reuse syntax trees across streamed argument updates and repeated terminal paints. */
178
- export function createApplySourceProjection(
179
- renderCall?: (call: ApplyCallPreview) => string,
180
- renderCode?: (source: string) => string,
181
- ): (source: string) => string {
182
- let previous = "";
183
- let output = "";
184
- let fragments: readonly TreeFragment[] = [];
185
- return (source) => {
186
- if (source === previous) return output;
187
- let shared = 0;
188
- while (
189
- shared < previous.length &&
190
- shared < source.length &&
191
- previous[shared] === source[shared]
192
- )
193
- shared++;
194
- fragments = TreeFragment.applyChanges(fragments, [
195
- { fromA: shared, toA: previous.length, fromB: shared, toB: source.length },
196
- ]);
197
- const tree = parser.parse(source, fragments);
198
- fragments = TreeFragment.addTree(tree);
199
- output = compactApplySource(source, parseApplyCalls(source, tree), renderCall, renderCode);
200
- previous = source;
201
- return output;
202
- };
203
- }
@@ -1,55 +0,0 @@
1
- import type { TextAnchorRecoveryCandidate } from "pi-agent-text";
2
- import type { MutationFormatting, AppliedTextChange } from "#src/api/mutation-result.js";
3
-
4
- /** Plain recovery data from the same anchor resolver used by standalone mutations. */
5
- export interface ScriptAnchorRecovery {
6
- readonly path: string;
7
- readonly field: string;
8
- readonly anchor: string;
9
- readonly status: "candidates" | "unavailable" | "timed-out" | "failed";
10
- readonly candidates: readonly TextAnchorRecoveryCandidate[];
11
- readonly total: number;
12
- }
13
-
14
- /** Plain resource data crossing the script bridge, independent of renderer objects. */
15
- export interface ScriptMutationFile {
16
- readonly source: string;
17
- readonly before: string | null;
18
- readonly after: string;
19
- readonly action: string;
20
- readonly changes: readonly AppliedTextChange[];
21
- readonly formatting: MutationFormatting;
22
- }
23
-
24
- /** Shared mutation execution outcome before model-facing formatting. */
25
- export interface ScriptMutationOutcome {
26
- readonly operation: string;
27
- readonly ok: boolean;
28
- readonly effect: "not-applied" | "applied" | "unknown";
29
- readonly files: readonly ScriptMutationFile[];
30
- readonly completed: readonly string[];
31
- /** Per-operation outcomes in staging order for Apply transactions. */
32
- readonly operations?: readonly {
33
- readonly index: number;
34
- readonly kind: string;
35
- readonly status: "applied" | "warning" | "failed" | "unknown" | "blocked";
36
- readonly effect: "not-applied" | "applied" | "unknown";
37
- readonly resources: readonly string[];
38
- readonly error?: { readonly code: string; readonly message: string };
39
- readonly warning?: {
40
- readonly code: string;
41
- readonly message: string;
42
- readonly presentation?: unknown;
43
- };
44
- }[];
45
- /** Session-scoped receipt accepted by undo. */
46
- readonly transaction?: string;
47
- readonly recoveries?: readonly ScriptAnchorRecovery[];
48
- /** Structured contributions from configured IDE mutation handlers. */
49
- readonly metadata?: Readonly<Record<string, unknown>>;
50
- readonly errors: readonly {
51
- readonly source: string;
52
- readonly code: string;
53
- readonly message: string;
54
- }[];
55
- }
@@ -1,276 +0,0 @@
1
- import {
2
- DEFAULT_MAX_BYTES,
3
- DEFAULT_MAX_LINES,
4
- truncateHead,
5
- } from "@earendil-works/pi-coding-agent";
6
- import { isAgentContent } from "pi-agent-resource";
7
- import type { ReadPluginApi } from "pi-agent-read/api/plugin-protocol";
8
- import type { ReadToolResult, ReadResultDetails } from "pi-agent-read/api/tools/read";
9
- import type { ResourceResolverContext } from "pi-agent-resource";
10
- import type { ApplyResults } from "#src/core/apply/results.js";
11
- import { FileMutationAgentResult } from "#src/core/mutation-result/file-mutation-agent-result.js";
12
- import { finalApplyMutations } from "./final-mutations.js";
13
- import { serializeApplyError } from "#src/core/apply/runtime.js";
14
-
15
- type Content = ReadToolResult["content"];
16
- /** Output level is presentation only; full data stays in the host ledger. */
17
- export interface ApplyOutput {
18
- readonly content: Content;
19
- readonly level: "full" | "compact" | "summary";
20
- readonly temporarySource?: string;
21
- readonly mutations?: ReturnType<typeof finalApplyMutations>;
22
- }
23
-
24
- /** Presents net file effects once, preserving native images and one combined text budget. */
25
- export async function renderApplyOutput(
26
- results: ApplyResults,
27
- read: Pick<ReadPluginApi, "saveTemporary"> & Partial<Pick<ReadPluginApi, "reduceOutput">>,
28
- error?: unknown,
29
- context: ResourceResolverContext = { cwd: process.cwd() },
30
- ): Promise<ApplyOutput> {
31
- const selected = results.select();
32
- const sections: { content: Content; read?: ReadToolResult }[] = selected.explicit.map(
33
- (entry) => ({
34
- content: renderValue(
35
- entry.kind === "operation" ? (entry.presentation ?? entry.value) : entry.value,
36
- ),
37
- read:
38
- entry.kind === "operation" ? (entry.presentation ?? asReadResult(entry.value)) : undefined,
39
- }),
40
- );
41
- const content: Content = sections.flatMap((section) => section.content);
42
- const mutations = selected.automatic.filter(({ kind }) => kind === "mutation");
43
- for (const operation of selected.automatic) {
44
- if (
45
- operation.kind === "read" ||
46
- hasOperationWarnings(operation.value) ||
47
- isFailure(operation.value) ||
48
- (operation.value !== null &&
49
- typeof operation.value === "object" &&
50
- "kind" in operation.value &&
51
- (operation.value.kind === "file-operation" || operation.value.kind === "index-operation"))
52
- ) {
53
- const section = {
54
- content: renderValue(operation.presentation ?? operation.value),
55
- read:
56
- operation.kind === "read"
57
- ? (operation.presentation ?? asReadResult(operation.value))
58
- : undefined,
59
- };
60
- sections.push(section);
61
- content.push(...section.content);
62
- }
63
- }
64
- for (const operation of mutations) {
65
- const value = operation.value;
66
- if (!isFailure(value) && value !== null && typeof value === "object" && "metadata" in value) {
67
- const section = { content: renderValue(value.metadata), read: undefined };
68
- sections.push(section);
69
- content.push(...section.content);
70
- }
71
- }
72
- const suffixStart = content.length;
73
- const finalMutations = finalApplyMutations(results);
74
- if (finalMutations.length > 0)
75
- content.push(new FileMutationAgentResult(finalMutations).toTextContent());
76
- if (error !== undefined) content.push(text(formatError(error)));
77
- if (content.length === 0) content.push(text("No operations or explicit results."));
78
- const full = textContent(content);
79
- if (!truncateHead(full).truncated) return { content, level: "full", mutations: finalMutations };
80
- const temporarySource = await read.saveTemporary(full);
81
- const footer = `\n\nFull Apply output: ${temporarySource}. Read this reference with offset/limit for more.`;
82
- if (read.reduceOutput !== undefined && !context.signal?.aborted) {
83
- const compact: Content = [];
84
- const reducibleSections = sections.flatMap(expandReadSection);
85
- const quota = Math.max(
86
- 1,
87
- reducibleSections.filter((section) => section.read !== undefined).length,
88
- );
89
- for (const section of reducibleSections) {
90
- let reduced: ReadToolResult | undefined;
91
- if (section.read !== undefined) {
92
- try {
93
- reduced = await read.reduceOutput(section.read, context, {
94
- maxBytes: Math.floor((DEFAULT_MAX_BYTES - Buffer.byteLength(footer)) / quota),
95
- maxLines: Math.floor((DEFAULT_MAX_LINES - 3) / quota),
96
- });
97
- } catch {
98
- /* Reduction is optional; keep the recorded result when it fails. */
99
- }
100
- }
101
- compact.push(...(reduced?.content ?? section.content));
102
- }
103
- compact.push(...content.slice(suffixStart));
104
- compact.push(text(footer.trimStart()));
105
- if (!truncateHead(textContent(compact)).truncated)
106
- return { content: compact, level: "compact", temporarySource, mutations: finalMutations };
107
- }
108
- const summary = [
109
- `Apply output reduced: ${selected.automatic.length} automatic results, ${selected.explicit.length} explicit results, ${selected.files.length} final files.`,
110
- ...(error === undefined ? [] : [formatError(error)]),
111
- ...selected.automatic
112
- .filter(({ value }) => isFailure(value))
113
- .map(({ value, presentation }) => textContent(renderValue(presentation ?? value))),
114
- ...selected.files.map(({ source }) => source),
115
- ].join("\n");
116
- const bounded = truncateHead(summary, {
117
- maxBytes: DEFAULT_MAX_BYTES - Buffer.byteLength(footer),
118
- maxLines: DEFAULT_MAX_LINES - 3,
119
- }).content;
120
- return {
121
- content: [text(bounded + footer), ...content.filter((block) => block.type === "image")],
122
- level: "summary",
123
- temporarySource,
124
- mutations: finalMutations,
125
- };
126
- }
127
-
128
- function text(value: string): Content[number] {
129
- return { type: "text", text: value };
130
- }
131
- function textContent(content: Content): string {
132
- return content
133
- .filter((block) => block.type === "text")
134
- .map((block) => block.text)
135
- .join("\n\n");
136
- }
137
- function expandReadSection(section: {
138
- content: Content;
139
- read?: ReadToolResult;
140
- }): { content: Content; read?: ReadToolResult }[] {
141
- const resources = section.read?.details.resources;
142
- return resources?.length
143
- ? resources.flatMap((read) => expandReadSection({ content: read.content, read }))
144
- : [section];
145
- }
146
- function hasOperationWarnings(value: unknown): boolean {
147
- return (
148
- value !== null &&
149
- typeof value === "object" &&
150
- "operations" in value &&
151
- Array.isArray(value.operations) &&
152
- (value.operations as unknown[]).some(
153
- (item) =>
154
- item !== null && typeof item === "object" && "status" in item && item.status === "warning",
155
- )
156
- );
157
- }
158
- function isFailure(value: unknown): boolean {
159
- return value !== null && typeof value === "object" && "ok" in value && value.ok === false;
160
- }
161
- function formatError(error: unknown): string {
162
- const failure = serializeApplyError(error);
163
- return formatApplyFailure(failure.code, failure.message);
164
- }
165
-
166
- function formatApplyFailure(code: string, message: string): string {
167
- const guidance: Readonly<Record<string, string>> = {
168
- NOT_FOUND:
169
- "The requested text or selection was not found. Read the current file and select existing text.",
170
- AMBIGUOUS_MATCH:
171
- "The selection matched more than once. Use a larger unique fragment or a current candidate anchor.",
172
- STALE_EDITOR:
173
- "This editor handle was already committed. Open the file again before staging more changes.",
174
- STALE_SELECTION:
175
- "The search selection no longer matches the file. Search again and use the fresh match.",
176
- INVALID_SELECTION:
177
- "The selected line or range is invalid. Read the file and select a range inside its current bounds.",
178
- STALE_SNAPSHOT:
179
- "A touched file changed after it was opened. Open it again and rebuild the transaction.",
180
- INVALID_TRANSACTION:
181
- "The staged operations conflict or overlap. Build non-overlapping selections from the original snapshots.",
182
- TRANSACTION_FAILED:
183
- "The commit failed after it started. Check the reported rollback state before retrying.",
184
- EEXIST: "The destination already exists. Choose another path or explicitly enable overwrite.",
185
- ENOENT: "A source path does not exist. Check the path and retry.",
186
- RUN_PARSE_ERROR:
187
- "The Apply JavaScript could not be parsed. Fix the reported syntax and run it again.",
188
- RUN_RUNTIME_ERROR:
189
- "The Apply JavaScript failed. Fix the reported operation or API usage and run it again.",
190
- };
191
- const hint = guidance[code];
192
- return hint === undefined
193
- ? `${code}: ${message}`
194
- : `${code}: ${message}
195
- ${hint}`;
196
- }
197
-
198
- function renderValue(value: unknown): Content {
199
- if (isAgentContent(value))
200
- return value.map((block) => (block.type === "custom" ? text(JSON.stringify(block)) : block));
201
- if (
202
- value !== null &&
203
- typeof value === "object" &&
204
- "operation" in value &&
205
- typeof value.operation === "string"
206
- ) {
207
- const lines = [
208
- `${value.operation}: ${isFailure(value) && "effect" in value && value.effect === "applied" ? "partially applied" : "effect" in value ? String(value.effect) : isFailure(value) ? "failed" : "completed"}`,
209
- ];
210
- if ("path" in value && typeof value.path === "string") lines.push(value.path);
211
- if ("target" in value && typeof value.target === "string")
212
- lines.push(`Target: ${value.target}`);
213
- if ("operations" in value && Array.isArray(value.operations))
214
- lines.push(...value.operations.map(formatOperationOutcome));
215
- else if ("errors" in value && Array.isArray(value.errors))
216
- lines.push(...value.errors.map(formatReceiptError));
217
- if ("error" in value) lines.push(formatReceiptError(value.error));
218
- if (
219
- isFailure(value) &&
220
- "completed" in value &&
221
- Array.isArray(value.completed) &&
222
- value.completed.length > 0
223
- )
224
- lines.push(`Affected resources: ${value.completed.join(", ")}`);
225
- return [text(lines.join("\n")), ...("metadata" in value ? renderValue(value.metadata) : [])];
226
- }
227
- if (typeof value === "string") return [text(value)];
228
- if (
229
- value !== null &&
230
- typeof value === "object" &&
231
- "content" in value &&
232
- isAgentContent(value.content)
233
- ) {
234
- return value.content.map((block) =>
235
- block.type === "custom" ? text(JSON.stringify(block)) : block,
236
- );
237
- }
238
- return [text(value === undefined ? "undefined" : JSON.stringify(value, null, 2))];
239
- }
240
-
241
- function asReadResult(value: unknown): ReadToolResult | undefined {
242
- if (
243
- value === null ||
244
- typeof value !== "object" ||
245
- !("source" in value) ||
246
- typeof value.source !== "string" ||
247
- !("lines" in value) ||
248
- !Array.isArray(value.lines) ||
249
- !("content" in value) ||
250
- !isAgentContent(value.content)
251
- )
252
- return undefined;
253
- return { content: renderValue(value), details: value as ReadResultDetails };
254
- }
255
-
256
- function formatOperationOutcome(value: unknown): string {
257
- if (value === null || typeof value !== "object") return String(value);
258
- const index = "index" in value ? Number(value.index) + 1 : "?";
259
- const kind = "kind" in value ? String(value.kind) : "operation";
260
- const status = "status" in value ? String(value.status) : "unknown";
261
- const detail =
262
- "warning" in value
263
- ? ` — ${formatReceiptError(value.warning)}`
264
- : "error" in value
265
- ? ` — ${formatReceiptError(value.error)}`
266
- : "";
267
- return `${index}. ${kind}: ${status}${detail}`;
268
- }
269
-
270
- function formatReceiptError(value: unknown): string {
271
- if (value === null || typeof value !== "object") return String(value);
272
- const source = "source" in value ? String(value.source) : undefined;
273
- const code = "code" in value ? String(value.code) : "OPERATION_FAILED";
274
- const message = "message" in value ? String(value.message) : "The operation failed.";
275
- return [source, formatApplyFailure(code, message)].filter(Boolean).join(": ");
276
- }
@@ -1,13 +0,0 @@
1
- const editorGuide = `
2
- Read-only helpers use the standalone-tool arguments: read({...}), search({...}), and diff({before, after}). Their results are recorded automatically.
3
-
4
- Transactional helpers:
5
- open(path | {path, views?}); file.find(text); file.select(searchMatch); file.between(start, end, {inside?, lines?}); file.line(first, last?); file.start(); file.end(); file.before(selection); file.after(selection); file.slice(selection, start?, end?); file.union(...selections); file.within(candidates, scopes); file.linesOf(selection); file.replace(selection, text); file.remove(selection); file.insertBefore(selection, text, {separation?: "line" | "blank-line"}); file.insertAfter(selection, text, {separation?: "line" | "blank-line"}); file.flush(); file.delete(); replace(selection, text); remove(selection); insertBefore(selection, text, {separation?: "line" | "blank-line"}); insertAfter(selection, text, {separation?: "line" | "blank-line"}); copy(source, destination); move(source, destination); createFile(path, content); deleteFile(path); copyFile(path, target, {overwrite?}); moveFile(path, target, {overwrite?}); flush().
6
-
7
- Selections are immutable and snapshot-bound. Use slice to select occurrences by position, union to combine non-overlapping sets, within to keep candidates contained by scopes, and linesOf to expand matches to whole lines. between accepts strings or SelectionSets as either boundary; {lines:true} expands through both containing lines. Prefer it for blocks identified by content; use line(first,last) only for exact verified line bounds. Use start/end or before/after as zero-width destinations when copy or move should insert instead of replace. Normal completion commits staged operations once; a thrown script commits none. flush() commits every staged operation; file.flush() commits only independent operations for that file while cross-file transfers stay pending. Successful checkpoints can return an APPLY# receipt. Failed operations report structured errors and do not silently guess a recovery.
8
- `;
9
-
10
- /** Compact callable contract for the guarded Apply editor. */
11
- export function applyHelperGuide(): string {
12
- return editorGuide;
13
- }
@@ -1,25 +0,0 @@
1
- /** Serializes one Apply invocation, including calls submitted through Promise.all. */
2
- export class ApplyQueue {
3
- #tail: Promise<void> = Promise.resolve();
4
- #closed = false;
5
-
6
- /** Runs after earlier operations settle; a refusal does not poison later calls. */
7
- submit<T>(operation: () => Promise<T>): Promise<T> {
8
- if (this.#closed) return Promise.reject(new Error("Apply execution has ended"));
9
- const pending = this.#tail.then(() => {
10
- if (this.#closed) throw new Error("Apply execution has ended");
11
- return operation();
12
- });
13
- this.#tail = pending.then(
14
- () => undefined,
15
- () => undefined,
16
- );
17
- return pending;
18
- }
19
-
20
- /** Stops queued calls and waits for active host work before reporting final effects. */
21
- async close(): Promise<void> {
22
- this.#closed = true;
23
- await this.#tail;
24
- }
25
- }