pi-agent-ide 0.2.2 → 0.4.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 (403) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +13 -8
  3. package/dist/chunk-3SE372WC.js +3 -0
  4. package/dist/chunk-5MSNYFDE.js +1 -0
  5. package/dist/chunk-5VSE5X5R.js +2 -0
  6. package/dist/chunk-6DZA4CLO.js +4 -0
  7. package/dist/chunk-6EYWFBNG.js +0 -0
  8. package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
  9. package/dist/chunk-7JYQMAEL.js +14 -0
  10. package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
  11. package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
  12. package/dist/{chunk-XF5PVZOS.js → chunk-B5KB2I7J.js} +1 -1
  13. package/dist/chunk-DQF5QMJ2.js +1 -0
  14. package/dist/chunk-EJ5OACQM.js +1 -0
  15. package/dist/chunk-GFW5QPQV.js +2 -0
  16. package/dist/{chunk-LQYZG62K.js → chunk-GUTQ3PWL.js} +1 -1
  17. package/dist/chunk-HGPUI7F3.js +1 -0
  18. package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
  19. package/dist/chunk-ITSNK5YG.js +7 -0
  20. package/dist/chunk-J34VKQGJ.js +1 -0
  21. package/dist/chunk-KAB3AYA2.js +1 -0
  22. package/dist/{chunk-76WHES5H.js → chunk-M5L42DWE.js} +5 -5
  23. package/dist/chunk-M5MJP7Z2.js +1 -0
  24. package/dist/chunk-NMFQGKPE.js +2 -0
  25. package/dist/chunk-NTYXZ3EL.js +3 -0
  26. package/dist/{chunk-P6T3Q7LB.js → chunk-QDST6VIU.js} +1 -1
  27. package/dist/chunk-ROXXK6TW.js +0 -0
  28. package/dist/{chunk-WNMGUALD.js → chunk-TI5GMJ7Q.js} +1 -1
  29. package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
  30. package/dist/chunk-XSTHESNR.js +25 -0
  31. package/dist/{chunk-THSCUT2L.js → chunk-Y7ZMR4LT.js} +1 -1
  32. package/dist/chunk-YHADTHQM.js +1 -0
  33. package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
  34. package/dist/{chunk-ZXN3TWWW.js → chunk-ZM4L5AGN.js} +1 -1
  35. package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
  36. package/dist/entry-0.js +1 -1
  37. package/dist/entry-1.js +1 -1
  38. package/dist/entry-10.js +1 -1
  39. package/dist/entry-12.js +1 -1
  40. package/dist/entry-13.js +1 -1
  41. package/dist/entry-14.js +1 -1
  42. package/dist/entry-2.js +1 -1
  43. package/dist/entry-21.js +1 -1
  44. package/dist/entry-24.js +1 -1
  45. package/dist/entry-25.js +1 -1
  46. package/dist/entry-26.js +10 -5
  47. package/dist/entry-28.js +1 -1
  48. package/dist/entry-29.js +1 -1
  49. package/dist/entry-31.js +3 -3
  50. package/dist/entry-32.js +6 -5
  51. package/dist/entry-36.js +1 -1
  52. package/dist/entry-37.js +1 -1
  53. package/dist/entry-38.js +1 -1
  54. package/dist/entry-39.js +1 -1
  55. package/dist/entry-4.js +1 -1
  56. package/dist/entry-40.js +12 -8
  57. package/dist/entry-42.js +1 -1
  58. package/dist/entry-43.js +1 -1
  59. package/dist/entry-44.js +1 -1
  60. package/dist/entry-45.js +4 -4
  61. package/dist/entry-46.js +10 -10
  62. package/dist/entry-47.js +1 -1
  63. package/dist/entry-48.js +1 -1
  64. package/dist/entry-49.js +1 -1
  65. package/dist/entry-50.js +1 -1
  66. package/dist/entry-51.js +1 -1
  67. package/dist/entry-52.js +1 -1
  68. package/dist/entry-53.js +1 -1
  69. package/dist/entry-54.js +1 -0
  70. package/dist/entry-55.js +0 -1
  71. package/dist/entry-56.js +1 -0
  72. package/dist/entry-57.js +0 -1
  73. package/dist/entry-58.js +1 -1
  74. package/dist/entry-59.js +1 -1
  75. package/dist/entry-60.js +1 -1
  76. package/dist/entry-61.js +1 -1
  77. package/dist/entry-62.js +1 -1
  78. package/dist/entry-63.js +1 -0
  79. package/dist/entry-64.js +0 -1
  80. package/dist/entry-65.js +1 -0
  81. package/dist/entry-66.js +0 -1
  82. package/dist/entry-67.js +1 -1
  83. package/dist/entry-68.js +1 -1
  84. package/dist/entry-69.js +1 -59
  85. package/dist/entry-70.js +123 -4
  86. package/dist/entry-71.js +30 -1
  87. package/dist/entry-72.js +2 -29
  88. package/dist/entry-73.js +1 -2
  89. package/dist/entry-74.js +1 -1
  90. package/dist/entry-75.js +1 -1
  91. package/dist/entry-76.js +3 -1
  92. package/dist/entry-77.js +1 -3
  93. package/dist/entry-78.js +1 -1
  94. package/dist/entry-79.js +1 -1
  95. package/dist/pi-agent-ide.js +3 -2
  96. package/docs/configuration.md +32 -11
  97. package/docs/tools.md +17 -0
  98. package/node_modules/pi-agent-doctor/package.json +1 -1
  99. package/node_modules/pi-agent-filesystem/package.json +6 -6
  100. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  101. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  102. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  103. package/node_modules/pi-agent-ide-ast/package.json +9 -9
  104. package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -3
  105. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
  106. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  107. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  108. package/node_modules/pi-agent-ide-changes/index.ts +21 -5
  109. package/node_modules/pi-agent-ide-changes/package.json +6 -6
  110. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  111. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
  112. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  113. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +26 -8
  114. package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
  115. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  116. package/node_modules/pi-agent-ide-lint/index.ts +46 -17
  117. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  118. package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
  119. package/node_modules/pi-agent-ide-lsp/index.ts +126 -8
  120. package/node_modules/pi-agent-ide-lsp/package.json +9 -8
  121. package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  122. package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
  123. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
  124. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  125. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  126. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  127. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  128. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  129. package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  130. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  131. package/node_modules/pi-agent-image/package.json +2 -2
  132. package/node_modules/pi-agent-invariant/package.json +1 -1
  133. package/node_modules/pi-agent-pdf/package.json +2 -2
  134. package/node_modules/pi-agent-read/package.json +6 -6
  135. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  136. package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
  137. package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
  138. package/node_modules/pi-agent-read/src/core/read-core.ts +26 -2
  139. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  140. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  141. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
  142. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  143. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  144. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +73 -44
  145. package/node_modules/pi-agent-resource/package.json +1 -1
  146. package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
  147. package/node_modules/pi-agent-resource/src/resource.ts +2 -0
  148. package/node_modules/pi-agent-search/package.json +3 -3
  149. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  150. package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
  151. package/node_modules/pi-agent-search/src/api/search.ts +55 -1
  152. package/node_modules/pi-agent-search/src/core/extension.ts +2 -23
  153. package/node_modules/pi-agent-search/src/core/search-core.ts +28 -3
  154. package/node_modules/pi-agent-search-text/index.ts +44 -4
  155. package/node_modules/pi-agent-search-text/package.json +6 -6
  156. package/node_modules/pi-agent-search-text/src/search-session.ts +65 -25
  157. package/node_modules/pi-agent-text/package.json +2 -2
  158. package/node_modules/pi-agent-text/src/text-document.ts +5 -0
  159. package/node_modules/pi-agent-text/src/text-target.ts +4 -0
  160. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  161. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  162. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  163. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  164. package/node_modules/pi-agent-text-editor/index.ts +1 -3
  165. package/node_modules/pi-agent-text-editor/package.json +34 -24
  166. package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
  167. package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  168. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  169. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  170. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  171. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  172. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +3 -0
  173. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  174. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  175. package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  176. package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  177. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  178. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  179. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  180. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  181. package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  182. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  183. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  184. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  185. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  186. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  187. package/node_modules/pi-agent-text-editor/src/core/extension.ts +6 -0
  188. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  189. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  190. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  191. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
  192. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
  193. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  194. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  195. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
  196. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
  197. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
  198. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  199. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
  200. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  201. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  202. package/node_modules/pi-agent-text-editor-renderer/index.ts +88 -1
  203. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  204. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
  205. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
  206. package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  207. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  208. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  209. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
  210. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  211. package/node_modules/pi-agent-web/package.json +7 -7
  212. package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
  213. package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
  214. package/node_modules/pi-agent-web-html/package.json +3 -3
  215. package/node_modules/pi-agent-web-image/package.json +4 -4
  216. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  217. package/node_modules/pi-agent-web-text/package.json +4 -4
  218. package/package.json +41 -38
  219. package/src/api/plugin-protocol.ts +10 -2
  220. package/src/api/tool-config.ts +73 -2
  221. package/src/code-view/diagnostic-view.ts +22 -3
  222. package/src/composite/builtin-extensions.ts +10 -15
  223. package/src/composite/extensions-config.ts +59 -0
  224. package/src/composite/feature-flags.ts +32 -0
  225. package/src/composite/module-labels.ts +59 -0
  226. package/src/composite/module-settings-store.ts +60 -0
  227. package/src/composite/module-settings.ts +162 -0
  228. package/src/composite/preferences.ts +26 -0
  229. package/src/composite/selection.ts +4 -4
  230. package/src/composite/settings-panel.ts +103 -0
  231. package/src/core/diagnostic-delivery.ts +29 -0
  232. package/src/core/diagnostic-entry.ts +51 -3
  233. package/src/core/diagnostic-store.ts +56 -5
  234. package/src/core/extension.ts +34 -33
  235. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
  236. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  237. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  238. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  239. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  240. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  241. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
  242. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  243. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  244. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  245. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
  246. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
  247. package/src/extensions/pi-agent-read/package.json +6 -6
  248. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  249. package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
  250. package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
  251. package/src/extensions/pi-agent-read/src/core/read-core.ts +26 -2
  252. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
  253. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
  254. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
  255. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
  256. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
  257. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +73 -44
  258. package/src/extensions/pi-agent-search/package.json +3 -3
  259. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +44 -4
  260. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  261. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +65 -25
  262. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
  263. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
  264. package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
  265. package/src/extensions/pi-agent-search/src/core/extension.ts +2 -23
  266. package/src/extensions/pi-agent-search/src/core/search-core.ts +28 -3
  267. package/src/extensions/pi-agent-text-editor/index.ts +1 -3
  268. package/src/extensions/pi-agent-text-editor/package.json +34 -24
  269. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  270. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  271. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  272. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
  273. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +88 -1
  274. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  275. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
  276. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
  277. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
  278. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  279. package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
  280. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
  281. package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
  282. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
  283. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
  284. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
  285. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
  286. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +3 -0
  287. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
  288. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
  289. package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
  290. package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
  291. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
  292. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
  293. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
  294. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
  295. package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
  296. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
  297. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
  298. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
  299. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
  300. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
  301. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +6 -0
  302. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
  303. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
  304. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
  305. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
  306. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
  307. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
  308. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
  309. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
  310. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
  311. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
  312. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
  313. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
  314. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
  315. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
  316. package/src/pi-agent-ide.ts +43 -8
  317. package/src/plugins/pi-agent-ide-ast/package.json +9 -9
  318. package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -3
  319. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
  320. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
  321. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
  322. package/src/plugins/pi-agent-ide-changes/index.ts +21 -5
  323. package/src/plugins/pi-agent-ide-changes/package.json +6 -6
  324. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
  325. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
  326. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -11
  327. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  328. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +26 -8
  329. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
  330. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  331. package/src/plugins/pi-agent-ide-lint/index.ts +46 -17
  332. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  333. package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
  334. package/src/plugins/pi-agent-ide-lsp/index.ts +126 -8
  335. package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
  336. package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
  337. package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
  338. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
  339. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
  340. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
  341. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
  342. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
  343. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
  344. package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
  345. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
  346. package/src/plugins/pi-agent-ide-terminal/index.ts +34 -0
  347. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +238 -0
  348. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +461 -0
  349. package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +127 -0
  350. package/src/plugins/pi-agent-ide-terminal/src/search.ts +159 -0
  351. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +529 -0
  352. package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +56 -0
  353. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +157 -0
  354. package/src/plugins/pi-agent-ide-terminal/src/types.ts +66 -0
  355. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +336 -0
  356. package/src/post-edit/gate.ts +15 -2
  357. package/dist/chunk-4U6KGABH.js +0 -1
  358. package/dist/chunk-6ACQQBUY.js +0 -7
  359. package/dist/chunk-GFWDXTOB.js +0 -4
  360. package/dist/chunk-JASLOB2X.js +0 -1
  361. package/dist/chunk-JJVXUL5U.js +0 -2
  362. package/dist/chunk-KCEOTU5Z.js +0 -3
  363. package/dist/chunk-KVGQG43U.js +0 -1
  364. package/dist/chunk-QJFRAMK7.js +0 -2
  365. package/dist/chunk-RAZOACDD.js +0 -2
  366. package/dist/chunk-RIGRP3FD.js +0 -1
  367. package/dist/chunk-VCCMVQXU.js +0 -1
  368. package/dist/chunk-X6MPU7UO.js +0 -3
  369. package/dist/chunk-YPHXLAQF.js +0 -1
  370. package/dist/entry-80.js +0 -1
  371. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  372. package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
  373. package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
  374. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  375. package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
  376. package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
  377. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  378. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
  379. package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
  380. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
  381. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
  382. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
  383. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
  384. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
  385. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
  386. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
  387. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
  388. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
  389. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
  390. /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
  391. /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
  392. /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  393. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
  394. /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
  395. /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
  396. /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  397. /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  398. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  399. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
  400. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
  401. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
  402. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
  403. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
@@ -0,0 +1,208 @@
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
+ "write",
9
+ "replace",
10
+ "insert",
11
+ "remove",
12
+ "copy",
13
+ "move",
14
+ "undo",
15
+ "stage",
16
+ "unstage",
17
+ "delete_file",
18
+ "copy_file",
19
+ "move_file",
20
+ ]);
21
+
22
+ /** Bounded source expression; literal does not imply the operation has executed. */
23
+ export interface PreviewArgument {
24
+ readonly text: string;
25
+ readonly literal: boolean;
26
+ }
27
+ /** A written call preview, never evidence that the call executed. */
28
+ export interface ApplyCallPreview {
29
+ readonly name: string;
30
+ readonly from: number;
31
+ readonly to: number;
32
+ readonly path?: PreviewArgument;
33
+ readonly query?: PreviewArgument;
34
+ readonly target?: PreviewArgument;
35
+ readonly before?: PreviewArgument;
36
+ readonly after?: PreviewArgument;
37
+ readonly arguments: Readonly<Record<string, PreviewArgument>>;
38
+ }
39
+
40
+ /** Recover helper calls from incomplete JavaScript without evaluating arguments. */
41
+ export function parseApplyCalls(
42
+ source: string,
43
+ tree: Tree = parser.parse(source),
44
+ ): ApplyCallPreview[] {
45
+ const shadows: { name: string; from: number; to: number }[] = [];
46
+ tree.iterate({
47
+ enter(node) {
48
+ if (node.name === "AssignmentExpression") {
49
+ const target = node.node.firstChild;
50
+ if (target?.name === "VariableName")
51
+ shadows.push({ name: source.slice(target.from, target.to), from: 0, to: source.length });
52
+ }
53
+ if (node.name !== "VariableDefinition") return;
54
+ let declaration = node.node.parent;
55
+ while (
56
+ declaration?.parent &&
57
+ !["VariableDeclaration", "ParamList", "Block", "Script"].includes(declaration.name)
58
+ )
59
+ declaration = declaration.parent;
60
+ const hoisted =
61
+ declaration?.name === "VariableDeclaration" && declaration.firstChild?.name === "var";
62
+ const boundaries = new Set([
63
+ "Script",
64
+ "FunctionDeclaration",
65
+ "FunctionExpression",
66
+ "ArrowFunction",
67
+ ...(hoisted ? [] : ["Block"]),
68
+ ]);
69
+ let scope = node.node.parent;
70
+ if (scope?.name === "FunctionDeclaration") scope = scope.parent;
71
+ while (scope?.parent && !boundaries.has(scope.name)) scope = scope.parent;
72
+ shadows.push({
73
+ name: source.slice(node.from, node.to),
74
+ from: scope?.from ?? 0,
75
+ to: scope?.to ?? source.length,
76
+ });
77
+ },
78
+ });
79
+ const calls: ApplyCallPreview[] = [];
80
+ tree.iterate({
81
+ enter(node) {
82
+ if (node.name !== "CallExpression") return;
83
+ const callee = node.node.firstChild;
84
+ if (callee?.name !== "VariableName") return;
85
+ const name = source.slice(callee.from, callee.to);
86
+ if (
87
+ !helpers.has(name) ||
88
+ shadows.some(
89
+ (binding) => binding.name === name && binding.from <= node.from && binding.to >= node.to,
90
+ )
91
+ )
92
+ return;
93
+ const object = node.node.getChild("ArgList")?.getChild("ObjectExpression");
94
+ const fields = Object.create(null) as Record<string, PreviewArgument>;
95
+ if (!object) {
96
+ const args = node.node.getChild("ArgList");
97
+ const raw = args ? source.slice(args.from + 1, args.to).replace(/\)$/, "") : "";
98
+ if (raw)
99
+ fields.arguments = {
100
+ text: raw.length > 160 ? raw.slice(0, 120) + "…" : raw,
101
+ literal: false,
102
+ };
103
+ }
104
+ for (const property of object?.getChildren("Property") ?? []) {
105
+ const key = property.firstChild;
106
+ const rawKey = key ? source.slice(key.from, key.to) : "";
107
+ const field = rawKey.replace(/^["']|["']$/g, "");
108
+ if (!/^[a-zA-Z_$][\w$]*$/.test(field)) {
109
+ // Computed keys and spreads can replace any earlier identity argument.
110
+ for (const identity of ["path", "query", "target", "before", "after"])
111
+ delete fields[identity];
112
+ const raw = source.slice(property.from, property.to);
113
+ fields[`argument@${property.from}`] = {
114
+ text: raw.length > 160 ? raw.slice(0, 160) + "…" : raw,
115
+ literal: false,
116
+ };
117
+ continue;
118
+ }
119
+ const value = property.lastChild;
120
+ if (!value || value.type.isError || value.name === ":") continue;
121
+ const raw = source.slice(value.from, value.to);
122
+ const singleLine = raw.replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\t/g, "\\t");
123
+ const anchor =
124
+ /^(?:["'])(?:\d+#[0-9A-F]+|CHANGE#[0-9A-F]+|begin|end|scope-(?:begin|end)-[^"']+)["']$/.test(
125
+ raw,
126
+ );
127
+ fields[field] = {
128
+ text:
129
+ singleLine.length > 160 && !anchor
130
+ ? `${singleLine.slice(0, 100)}…${singleLine.slice(-40)} (${raw.length} source chars)`
131
+ : singleLine,
132
+ literal:
133
+ ["String", "Number", "BooleanLiteral", "Null"].includes(value.name) &&
134
+ value.lastChild?.type.isError !== true,
135
+ };
136
+ }
137
+ calls.push({
138
+ name,
139
+ from: node.from,
140
+ to: node.to,
141
+ path: fields.path,
142
+ query: fields.query,
143
+ target: fields.target,
144
+ before: fields.before,
145
+ after: fields.after,
146
+ arguments: fields,
147
+ });
148
+ return false;
149
+ },
150
+ });
151
+ return calls;
152
+ }
153
+
154
+ /** Compact written calls only; source and execution are never changed. */
155
+ export function compactApplySource(
156
+ source: string,
157
+ calls = parseApplyCalls(source),
158
+ renderCall?: (call: ApplyCallPreview) => string,
159
+ renderCode: (source: string) => string = (source) => source,
160
+ ): string {
161
+ let cursor = 0;
162
+ const parts: string[] = [];
163
+ const codePreview = (text: string) =>
164
+ renderCode(
165
+ text
166
+ .split("\n")
167
+ .map((line) => (line.length > 200 ? line.slice(0, 200) + "…" : line))
168
+ .join("\n"),
169
+ );
170
+ for (const call of calls) {
171
+ parts.push(codePreview(source.slice(cursor, call.from)));
172
+ parts.push(
173
+ renderCall?.(call) ??
174
+ `${call.name}(${call.path ? (call.path.literal ? call.path.text : `‹${call.path.text}›`) : "…"})`,
175
+ );
176
+ cursor = call.to;
177
+ }
178
+ parts.push(codePreview(source.slice(cursor)));
179
+ return parts.join("");
180
+ }
181
+
182
+ /** Reuse syntax trees across streamed argument updates and repeated terminal paints. */
183
+ export function createApplySourceProjection(
184
+ renderCall?: (call: ApplyCallPreview) => string,
185
+ renderCode?: (source: string) => string,
186
+ ): (source: string) => string {
187
+ let previous = "";
188
+ let output = "";
189
+ let fragments: readonly TreeFragment[] = [];
190
+ return (source) => {
191
+ if (source === previous) return output;
192
+ let shared = 0;
193
+ while (
194
+ shared < previous.length &&
195
+ shared < source.length &&
196
+ previous[shared] === source[shared]
197
+ )
198
+ shared++;
199
+ fragments = TreeFragment.applyChanges(fragments, [
200
+ { fromA: shared, toA: previous.length, fromB: shared, toB: source.length },
201
+ ]);
202
+ const tree = parser.parse(source, fragments);
203
+ fragments = TreeFragment.addTree(tree);
204
+ output = compactApplySource(source, parseApplyCalls(source, tree), renderCall, renderCode);
205
+ previous = source;
206
+ return output;
207
+ };
208
+ }
@@ -0,0 +1,39 @@
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
+ readonly recoveries?: readonly ScriptAnchorRecovery[];
32
+ /** Structured contributions from configured IDE mutation handlers. */
33
+ readonly metadata?: Readonly<Record<string, unknown>>;
34
+ readonly errors: readonly {
35
+ readonly source: string;
36
+ readonly code: string;
37
+ readonly message: string;
38
+ }[];
39
+ }
@@ -0,0 +1,216 @@
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
+ }
22
+
23
+ /** Presents net file effects once, preserving native images and one combined text budget. */
24
+ export async function renderApplyOutput(
25
+ results: ApplyResults,
26
+ read: Pick<ReadPluginApi, "saveTemporary"> & Partial<Pick<ReadPluginApi, "reduceOutput">>,
27
+ error?: unknown,
28
+ context: ResourceResolverContext = { cwd: process.cwd() },
29
+ ): Promise<ApplyOutput> {
30
+ const selected = results.select();
31
+ const sections: { content: Content; read?: ReadToolResult }[] = selected.explicit.map(
32
+ (entry) => ({
33
+ content: renderValue(
34
+ entry.kind === "operation" ? (entry.presentation ?? entry.value) : entry.value,
35
+ ),
36
+ read:
37
+ entry.kind === "operation" ? (entry.presentation ?? asReadResult(entry.value)) : undefined,
38
+ }),
39
+ );
40
+ const content: Content = sections.flatMap((section) => section.content);
41
+ const mutations = selected.automatic.filter(({ kind }) => kind === "mutation");
42
+ for (const operation of selected.automatic) {
43
+ if (
44
+ operation.kind === "read" ||
45
+ isFailure(operation.value) ||
46
+ (operation.value !== null &&
47
+ typeof operation.value === "object" &&
48
+ "kind" in operation.value &&
49
+ (operation.value.kind === "file-operation" || operation.value.kind === "index-operation"))
50
+ ) {
51
+ const section = {
52
+ content: renderValue(operation.presentation ?? operation.value),
53
+ read:
54
+ operation.kind === "read"
55
+ ? (operation.presentation ?? asReadResult(operation.value))
56
+ : undefined,
57
+ };
58
+ sections.push(section);
59
+ content.push(...section.content);
60
+ }
61
+ }
62
+ for (const operation of mutations) {
63
+ const value = operation.value;
64
+ if (!isFailure(value) && value !== null && typeof value === "object" && "metadata" in value) {
65
+ const section = { content: renderValue(value.metadata), read: undefined };
66
+ sections.push(section);
67
+ content.push(...section.content);
68
+ }
69
+ }
70
+ const suffixStart = content.length;
71
+ const finalMutations = finalApplyMutations(results);
72
+ if (finalMutations.length > 0)
73
+ content.push(new FileMutationAgentResult(finalMutations).toTextContent());
74
+ if (error !== undefined) content.push(text(formatError(error)));
75
+ if (content.length === 0) content.push(text("No operations or explicit results."));
76
+ const full = textContent(content);
77
+ if (!truncateHead(full).truncated) return { content, level: "full" };
78
+ const temporarySource = await read.saveTemporary(full);
79
+ const footer = `\n\nFull Apply output: ${temporarySource}. Read this reference with offset/limit for more.`;
80
+ if (read.reduceOutput !== undefined && !context.signal?.aborted) {
81
+ const compact: Content = [];
82
+ const reducibleSections = sections.flatMap(expandReadSection);
83
+ const quota = Math.max(
84
+ 1,
85
+ reducibleSections.filter((section) => section.read !== undefined).length,
86
+ );
87
+ for (const section of reducibleSections) {
88
+ let reduced: ReadToolResult | undefined;
89
+ if (section.read !== undefined) {
90
+ try {
91
+ reduced = await read.reduceOutput(section.read, context, {
92
+ maxBytes: Math.floor((DEFAULT_MAX_BYTES - Buffer.byteLength(footer)) / quota),
93
+ maxLines: Math.floor((DEFAULT_MAX_LINES - 3) / quota),
94
+ });
95
+ } catch {
96
+ /* Reduction is optional; keep the recorded result when it fails. */
97
+ }
98
+ }
99
+ compact.push(...(reduced?.content ?? section.content));
100
+ }
101
+ compact.push(...content.slice(suffixStart));
102
+ compact.push(text(footer.trimStart()));
103
+ if (!truncateHead(textContent(compact)).truncated)
104
+ return { content: compact, level: "compact", temporarySource };
105
+ }
106
+ const summary = [
107
+ `Apply output reduced: ${selected.automatic.length} automatic results, ${selected.explicit.length} explicit results, ${selected.files.length} final files.`,
108
+ ...(error === undefined ? [] : [formatError(error)]),
109
+ ...selected.automatic
110
+ .filter(({ value }) => isFailure(value))
111
+ .map(({ value, presentation }) => textContent(renderValue(presentation ?? value))),
112
+ ...selected.files.map(({ source }) => source),
113
+ ].join("\n");
114
+ const bounded = truncateHead(summary, {
115
+ maxBytes: DEFAULT_MAX_BYTES - Buffer.byteLength(footer),
116
+ maxLines: DEFAULT_MAX_LINES - 3,
117
+ }).content;
118
+ return {
119
+ content: [text(bounded + footer), ...content.filter((block) => block.type === "image")],
120
+ level: "summary",
121
+ temporarySource,
122
+ };
123
+ }
124
+
125
+ function text(value: string): Content[number] {
126
+ return { type: "text", text: value };
127
+ }
128
+ function textContent(content: Content): string {
129
+ return content
130
+ .filter((block) => block.type === "text")
131
+ .map((block) => block.text)
132
+ .join("\n\n");
133
+ }
134
+ function expandReadSection(section: {
135
+ content: Content;
136
+ read?: ReadToolResult;
137
+ }): { content: Content; read?: ReadToolResult }[] {
138
+ const resources = section.read?.details.resources;
139
+ return resources?.length
140
+ ? resources.flatMap((read) => expandReadSection({ content: read.content, read }))
141
+ : [section];
142
+ }
143
+ function isFailure(value: unknown): boolean {
144
+ return value !== null && typeof value === "object" && "ok" in value && value.ok === false;
145
+ }
146
+ function formatError(error: unknown): string {
147
+ const failure = serializeApplyError(error);
148
+ return `${failure.code}: ${failure.message}`;
149
+ }
150
+
151
+ function renderValue(value: unknown): Content {
152
+ if (isAgentContent(value))
153
+ return value.map((block) => (block.type === "custom" ? text(JSON.stringify(block)) : block));
154
+ if (
155
+ value !== null &&
156
+ typeof value === "object" &&
157
+ "operation" in value &&
158
+ typeof value.operation === "string"
159
+ ) {
160
+ const lines = [
161
+ `${value.operation}: ${"effect" in value ? String(value.effect) : isFailure(value) ? "failed" : "completed"}`,
162
+ ];
163
+ if ("path" in value && typeof value.path === "string") lines.push(value.path);
164
+ if ("target" in value && typeof value.target === "string")
165
+ lines.push(`Target: ${value.target}`);
166
+ if ("errors" in value && Array.isArray(value.errors))
167
+ lines.push(...value.errors.map(formatReceiptError));
168
+ if ("error" in value) lines.push(formatReceiptError(value.error));
169
+ if (
170
+ isFailure(value) &&
171
+ "completed" in value &&
172
+ Array.isArray(value.completed) &&
173
+ value.completed.length > 0
174
+ )
175
+ lines.push(`Affected resources: ${value.completed.join(", ")}`);
176
+ return [text(lines.join("\n")), ...("metadata" in value ? renderValue(value.metadata) : [])];
177
+ }
178
+ if (typeof value === "string") return [text(value)];
179
+ if (
180
+ value !== null &&
181
+ typeof value === "object" &&
182
+ "content" in value &&
183
+ isAgentContent(value.content)
184
+ ) {
185
+ return value.content.map((block) =>
186
+ block.type === "custom" ? text(JSON.stringify(block)) : block,
187
+ );
188
+ }
189
+ return [text(value === undefined ? "undefined" : JSON.stringify(value, null, 2))];
190
+ }
191
+
192
+ function asReadResult(value: unknown): ReadToolResult | undefined {
193
+ if (
194
+ value === null ||
195
+ typeof value !== "object" ||
196
+ !("source" in value) ||
197
+ typeof value.source !== "string" ||
198
+ !("lines" in value) ||
199
+ !Array.isArray(value.lines) ||
200
+ !("content" in value) ||
201
+ !isAgentContent(value.content)
202
+ )
203
+ return undefined;
204
+ return { content: renderValue(value), details: value as ReadResultDetails };
205
+ }
206
+
207
+ function formatReceiptError(value: unknown): string {
208
+ if (value === null || typeof value !== "object") return String(value);
209
+ return [
210
+ "source" in value ? String(value.source) : undefined,
211
+ "code" in value ? String(value.code) : undefined,
212
+ "message" in value ? String(value.message) : undefined,
213
+ ]
214
+ .filter(Boolean)
215
+ .join(": ");
216
+ }
@@ -0,0 +1,45 @@
1
+ /** Standalone-independent guide for the JavaScript helpers exposed by Apply. */
2
+ export const applyHelperGuide = `
3
+ Helper arguments (one object per call; ? means optional):
4
+ read({path: string, offset?: number, limit?: number, views?: string[]})
5
+ search({query: string, path?: string, include?: string, exclude?: string, caseSensitive?: boolean, wholeWord?: boolean, limit?: number})
6
+ diff({before: string | {path: string, offset?: number, limit?: number, views?: string[]}, after: string | {path: string, offset?: number, limit?: number, views?: string[]}})
7
+ write({path: string, content: string})
8
+ replace({path?: string, start?: string, end?: string, text: string})
9
+ insert({path?: string, anchor?: string, text: string, before?: boolean})
10
+ remove({path?: string, start?: string, end?: string})
11
+ copy({path?: string, start?: string, end?: string, target?: string, targetStart?: string, targetEnd?: string})
12
+ move({path?: string, start?: string, end?: string, target?: string, targetStart?: string, targetEnd?: string})
13
+ delete_file({path: string})
14
+ copy_file({path: string, target: string, overwrite?: boolean})
15
+ move_file({path: string, target: string, overwrite?: boolean})
16
+ undo({file?: string, change: string})
17
+ stage({file: string, change: string})
18
+ unstage({file: string, change: string})
19
+ result(value)
20
+
21
+ Whole-file helpers operate on local regular files. Configured post-processing can format copied or moved UTF-8 text targets; binary contents remain unchanged. delete_file permanently deletes a file; copy_file copies it; move_file moves or renames it. Directories and symlinks are rejected. Existing targets require overwrite: true. Use the same names and arguments for standalone calls and inside Apply; only the text delete tool is named remove inside JavaScript. Receipts contain kind: "file-operation", operation, ok, effect, path, target?, error?. An unknown effect requires inspection before retry; no automatic rollback.
22
+
23
+ Writes take effect immediately. Final post-processing runs once per surviving changed file when Apply finishes, including after a script error; automatic diagnostics follow final processing. Reads inside the script see current, not yet finally formatted text. Re-read final anchors in a later call when needed. Stage captures the current bytes, before end-of-Apply formatting. Explicit diagnostic reads still request checks at their call site.
24
+
25
+ Use path, not file_path. Pass a source to read; offset/limit select lines, not character ranges, except raw: sources where they select bytes. Negative offsets start from the end. Use views such as anchors, ast, diagnostics or changes. Sources also accept file://, HTTP(S), temp:, SEARCH#, ast:, diagnostics:, symbol: and graph: forms supported by read. Explicit diagnostic requests wait; an ordinary read does not.
26
+ Use read({path: "raw:local-file", offset: 0, limit: 64}) to inspect original bytes without conversion. In raw: reads, offset is a zero-based byte position (negative from EOF) and limit is a non-negative byte count; omit limit for all remaining bytes in the script. Raw reads return {kind: "bytes", source, byteOffset, byteLength, totalBytes, bytes: number[], ok}. Use result(doc) to display hex + ASCII. No views, text anchors or byte editing are supported.
27
+ Search query accepts literal text, Boolean conditions, regex:, files:, ast: and symbols:. limit is 1–1000. Reuse returned SEARCH references; do not invent session IDs. Search returns {resolverId, data, details, ok}; details contains resolver-specific selection metadata.
28
+ Use ast:<pattern> search for structural edits. Pass its returned SEARCH#...:N:match as path to replace, copy, move or remove; the selection covers the exact node, including multiline boundaries. Single references become stale after file changes; all selections rerun the original AST query and require complete results. Use data.matches and their metaVariables to compute replacement text. These are text edits, not reference-aware refactors. Use path/include/exclude to scope symbols: searches before the result limit is applied.
29
+ Text read returns {kind: "text", source, content: string, lines, startLine, endLine, totalLines, ok}. Each line contains content, lineNumber, lineEnding, anchors and available metadata. Native reads return {kind: "native", source, blocks, ok}; multi-source reads return {kind: "resources", resources, ok}. Check kind before using text-only fields.
30
+ Use unique exact text or an anchor returned by read/search for start, end and anchor. A whole-line anchor selects its line; end includes its final line. Omit end for a single selected fragment. begin/end are file-boundary anchors. Omit path only when a previous read/edit or a SEARCH reference identifies the source. A SEARCH selection may also supply the range without start/end. Insert goes after the selected line unless before:true. Copy/move target defaults to source; targetStart selects the destination, and targetEnd replaces an inclusive target line range instead of inserting after targetStart. remove deletes selected text, not a file. write creates or replaces the entire file.
31
+ Use symbol:<file>#<selector> as a declaration selection for copy, move, remove or replace when the LSP plugin is available. For example, copy({path: "symbol:src/a.ts#Example", target: "src/b.ts", targetStart: "end"}). Select parent/child for ambiguous names. Supply an explicit target for copy/move. This declaration-text fallback does not update imports or references; metadata.semanticEdit reports that limitation. Semantic insert is unsupported. Do not treat declaration replacement as a semantic rename.
32
+ Use replace({path: "symbol:src/a.ts#Example#name", text: "NewName"}) for native LSP rename, including references. Omit start/end. The #name suffix selects semantic rename rather than declaration replacement. If the server cannot rename, handle the failure; no identifier-text fallback is applied.
33
+ Use result(doc) to explicitly keep a read result with its source and presentation. Do not use result(doc.content) merely to display a read: it adds a separate raw string and loses the source/view information. Read-only calls are shown automatically, so mass reads need no result calls. Use result(value) for additional computed data; explicit additions survive mutations. Mutations return {operation, ok, effect, files, completed, errors, recoveries?, metadata?}; files contain source, before, after, changes and formatting. They are reported automatically as final per-file changes.
34
+
35
+ Use diff to compare text-readable sources without editing them. Each side accepts a source string or read request. The result is {kind: "diff", ok, equal, before: {source, sources, content}, after: {source, sources, content}, diff, stats: {added, removed}}. Multiple resources are joined with one newline in resolver order. Patch line numbers are relative to the selected text. Comparisons are automatic read-only output; use result(comparison) to keep one when the script also edits files.
36
+ Use stage/unstage with a current CHANGE# anchor from read({path: file, views: ["changes"]}) to change only the Git index. These operations return {kind: "index-operation", operation, ok, effect: "index-only", file, change, state, unchanged} and keep worktree content. Use undo({file, change: "last"}) to restore that file before its latest text-editor transaction, not the entire Apply call. Use undo({file, change: "CHANGE#..."}) to restore a selected change to HEAD in both worktree and index. Git operations require the Git changes module. Re-read stale changes before retrying; completed operations survive later failures.
37
+ Examples:
38
+ const doc = read({path: "src/example.ts"});
39
+ const line = doc.lines.find(line => line.content.includes("oldValue"));
40
+ if (line) replace({path: doc.source, start: line.anchors[0], text: line.content.replace("oldValue", "newValue")});
41
+
42
+ for (const path of ["README.md", "package.json"]) read({path});
43
+
44
+ Do not retry by guessing different argument names. Catch errors and inspect code/details; distinguish invalid arguments, unavailable services and stale/ambiguous anchors. Already applied edits remain applied.
45
+ `;
@@ -0,0 +1,25 @@
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
+ }