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,132 @@
1
+ import { formatApplySource } from "./format-source.js";
2
+ import { applyHelperGuide } from "#src/core/apply/prompt.js";
3
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
+ import { connectReadPlugin } from "pi-agent-read/api/connect-plugin";
5
+ import {
6
+ READ_API_VERSION,
7
+ READ_PROTOCOL,
8
+ type ReadPluginApi,
9
+ } from "pi-agent-read/api/plugin-protocol";
10
+ import { connectSearchPlugin } from "pi-agent-search/api/connect-plugin";
11
+ import { SEARCH_API_VERSION, SEARCH_PROTOCOL } from "pi-agent-search/api/plugin-protocol";
12
+ import type { SearchPluginApi } from "pi-agent-search/api/search";
13
+ import { Type } from "typebox";
14
+ import {
15
+ getLastResolvedResource,
16
+ rememberLastResolvedResource,
17
+ } from "#src/api/last-resolved-resource.js";
18
+ import type { TextEditorCore } from "#src/core/text-editor-core.js";
19
+ import { createApplyExecution } from "#src/core/apply/execution.js";
20
+ import { executeApplySource } from "#src/core/apply/runtime.js";
21
+ import { renderApplyOutput } from "#src/core/apply/output.js";
22
+ import {
23
+ createApplyDisplay,
24
+ renderApplyCall,
25
+ renderApplyResult,
26
+ } from "#src/core/apply/renderer.js";
27
+
28
+ /** Registers composed IDE operations using the owning extensions' configured services. */
29
+ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): Promise<void> {
30
+ let read: ReadPluginApi | undefined;
31
+ let search: SearchPluginApi | undefined;
32
+ await connectReadPlugin(pi, {
33
+ id: "apply",
34
+ protocol: READ_PROTOCOL,
35
+ apiVersion: READ_API_VERSION,
36
+ setup(api) {
37
+ read = api;
38
+ },
39
+ });
40
+ await connectSearchPlugin(pi, {
41
+ id: "apply",
42
+ protocol: SEARCH_PROTOCOL,
43
+ apiVersion: SEARCH_API_VERSION,
44
+ setup(api) {
45
+ search = api;
46
+ },
47
+ });
48
+ pi.registerTool({
49
+ name: "apply",
50
+ label: "Apply",
51
+ renderShell: "self",
52
+ renderCall: (args, theme, context) => {
53
+ (context.state as { codeView?: boolean }).codeView =
54
+ pi.getFlag("pi-agent-ide-apply-code") === true;
55
+ const render = editor.getToolRenderer("apply")?.renderCall ?? renderApplyCall;
56
+ return render(args, theme, context);
57
+ },
58
+ renderResult: (...args) => {
59
+ const render = (editor.getToolRenderer("apply")?.renderResult ??
60
+ renderApplyResult) as typeof renderApplyResult;
61
+ return render(...args);
62
+ },
63
+ promptSnippet: "Compose dependent IDE reads and edits in one JavaScript call",
64
+ description:
65
+ "Use apply to combine IDE operations with JavaScript loops and conditions. Direct synchronous functions (no await): read, search, diff, write, replace, insert, remove (delete), copy, move, delete_file, copy_file, move_file, undo, stage, unstage. Pass the same argument objects as standalone tools. Calls execute sequentially, including Promise.all. Text reads return source, raw content and lines with anchors and view metadata. Multi-resource reads return resources; native reads return blocks. Search returns resolverId, raw data and registered selection details. Ordinary reads do not wait for diagnostics; explicit diagnostics requests wait for completed checks and throw if unavailable or timed out. Mutations return final file data. Use result(value) to select extra output; return is not required. Mutations suppress automatic read output. Final per-file changes use the same result format as standalone edits. Applied changes survive errors; catch operation errors by code/details. Output has one 2000-line/50KB budget. Overflow uses compact source views or a summary with a full temp reference. No shell, imports or resume. Undo restores one selected file transaction or Git change, never the whole Apply call." +
66
+ applyHelperGuide,
67
+ promptGuidelines: [
68
+ "Use apply for dependent combinations of IDE operations. Use standalone tools for a single operation. Check reported effects before retrying a failed apply; earlier edits are not rolled back.",
69
+ ],
70
+ parameters: Type.Object({
71
+ source: Type.String({
72
+ description:
73
+ "JavaScript function body. Call IDE functions directly without await; each call finishes before the next statement. Use result(value) for explicit output. The UI may compact written tool calls or format a display copy; execution uses this source unchanged.",
74
+ }),
75
+ }),
76
+ async execute(_id, { source }, signal, _onUpdate, context) {
77
+ if (read === undefined || search === undefined)
78
+ throw new Error("Apply requires the read and search extensions");
79
+ const execution = createApplyExecution(
80
+ {
81
+ editor,
82
+ read,
83
+ search,
84
+ lastResolvedSource: getLastResolvedResource(pi)?.source,
85
+ rememberRead: (outcome) => rememberLastResolvedResource(pi, outcome.details),
86
+ },
87
+ context,
88
+ );
89
+ const displaySource = formatApplySource(source);
90
+ let failed = false;
91
+ let error: unknown;
92
+ try {
93
+ await executeApplySource(source, execution.host, signal);
94
+ } catch (cause) {
95
+ failed = true;
96
+ error = cause;
97
+ }
98
+ try {
99
+ await execution.finish();
100
+ } catch (cause) {
101
+ failed = true;
102
+ error ??= cause;
103
+ }
104
+ const output = await renderApplyOutput(execution.results, read, error, {
105
+ cwd: context.cwd,
106
+ signal,
107
+ });
108
+ return {
109
+ content: output.content,
110
+ details: {
111
+ failed,
112
+ displaySource: await displaySource,
113
+ outputLevel: output.level,
114
+ display: createApplyDisplay(execution.results, output, error, context.cwd),
115
+ temporarySource: output.temporarySource,
116
+ files: execution.results.select().files.map(({ source: file }) => file),
117
+ },
118
+ };
119
+ },
120
+ });
121
+ pi.on("tool_result", (event) => {
122
+ if (
123
+ event.toolName === "apply" &&
124
+ event.details &&
125
+ typeof event.details === "object" &&
126
+ "failed" in event.details &&
127
+ event.details.failed
128
+ )
129
+ return { isError: true };
130
+ return;
131
+ });
132
+ }
@@ -0,0 +1,205 @@
1
+ import path from "node:path";
2
+ import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
3
+ import {
4
+ truncateHead,
5
+ DEFAULT_MAX_BYTES,
6
+ DEFAULT_MAX_LINES,
7
+ } from "@earendil-works/pi-coding-agent";
8
+ import { Text } from "@earendil-works/pi-tui";
9
+ import { Type, type Static } from "typebox";
10
+ import { Value } from "typebox/value";
11
+ import {
12
+ readParameters,
13
+ type ReadScriptData,
14
+ type ReadToolResult,
15
+ } from "pi-agent-read/api/tools/read";
16
+ import type { ReadPluginApi } from "pi-agent-read/api/plugin-protocol";
17
+ import type { TextEditorCore } from "#src/core/text-editor-core.js";
18
+ import { createUnifiedDiff, type DiffStats } from "#src/core/mutation-result/diff.js";
19
+ import { FileMutationResult } from "#src/core/mutation-result/file-mutation-result.js";
20
+
21
+ const source = Type.Union([Type.String({ minLength: 1 }), readParameters]);
22
+ /** Each side accepts a source string or the same request object as read. */
23
+ export const diffParameters = Type.Object(
24
+ { before: source, after: source },
25
+ { additionalProperties: false },
26
+ );
27
+ export type DiffRequest = Static<typeof diffParameters>;
28
+ interface ComparisonText {
29
+ readonly source: string;
30
+ readonly sources: readonly string[];
31
+ readonly content: string;
32
+ }
33
+ /** Full comparison data for Apply; this is not an edit receipt. */
34
+ export interface DiffOutcome {
35
+ readonly kind: "diff";
36
+ readonly ok: true;
37
+ readonly equal: boolean;
38
+ readonly before: ComparisonText;
39
+ readonly after: ComparisonText;
40
+ readonly diff: string;
41
+ readonly stats: DiffStats;
42
+ }
43
+
44
+ /** Read both sides through the configured read pipeline without presentation clipping. */
45
+ export async function executeDiff(
46
+ read: ReadPluginApi,
47
+ input: unknown,
48
+ context: { cwd: string; signal?: AbortSignal },
49
+ ): Promise<DiffOutcome> {
50
+ if (!Value.Check(diffParameters, input))
51
+ throw Object.assign(new Error("Use before and after source strings or read request objects"), {
52
+ code: "INVALID_ARGUMENTS",
53
+ });
54
+ const request = input;
55
+ const resolve = async (side: DiffRequest["before"]) => {
56
+ const request = typeof side === "string" ? { path: side } : side;
57
+ const outcome = await read.read(request, context, "script");
58
+ if (outcome.isError || outcome.details.failure)
59
+ throw Object.assign(new Error(outcome.details.failure?.message ?? "Comparison read failed"), {
60
+ code: outcome.details.failure?.code ?? "READ_FAILED",
61
+ details: outcome.details.failure,
62
+ });
63
+ if (outcome.script === undefined)
64
+ throw Object.assign(new Error("Source has no comparable text data"), {
65
+ code: "UNSUPPORTED_CONTENT",
66
+ });
67
+ return comparisonText(outcome.script, request.path ?? "source");
68
+ };
69
+ const before = await resolve(request.before);
70
+ const after = await resolve(request.after);
71
+ const result = createUnifiedDiff(before.source, before.content, after.content, after.source);
72
+ return {
73
+ kind: "diff",
74
+ ok: true,
75
+ equal: before.content === after.content,
76
+ before,
77
+ after,
78
+ ...result,
79
+ };
80
+ }
81
+
82
+ /** Preserve canonical text, joining multiple resolved resources with one newline separator. */
83
+ export function comparisonText(data: ReadScriptData, requested: string): ComparisonText {
84
+ if (data.kind === "text")
85
+ return { source: data.source, sources: [data.source], content: data.content };
86
+ if (data.kind === "resources") {
87
+ const texts = data.resources.map((resource) => comparisonText(resource, requested));
88
+ return {
89
+ source: data.source ?? requested,
90
+ sources: texts.flatMap((text) => text.sources),
91
+ content: texts.map((text) => text.content).join("\n"),
92
+ };
93
+ }
94
+ if (data.kind === "bytes")
95
+ throw Object.assign(new Error(`Byte sources are not text: ${data.source}`), {
96
+ code: "UNSUPPORTED_CONTENT",
97
+ });
98
+ if (data.blocks.length === 0 || data.blocks.some((block) => block.type !== "text"))
99
+ throw Object.assign(new Error(`Source is not text: ${data.source}`), {
100
+ code: "UNSUPPORTED_CONTENT",
101
+ });
102
+ return {
103
+ source: data.source,
104
+ sources: [data.source],
105
+ content: data.blocks.flatMap((block) => (block.type === "text" ? [block.text] : [])).join("\n"),
106
+ };
107
+ }
108
+
109
+ /** Recognize comparison results without confusing them with mutations. */
110
+ export function isDiffOutcome(value: unknown): value is DiffOutcome {
111
+ return (
112
+ value !== null &&
113
+ typeof value === "object" &&
114
+ "kind" in value &&
115
+ value.kind === "diff" &&
116
+ "ok" in value &&
117
+ value.ok === true
118
+ );
119
+ }
120
+ /** Reuse the editor panel's existing before/after presentation contract, without executing edits. */
121
+ export function diffPresentation(value: DiffOutcome, cwd = process.cwd()) {
122
+ const displaySource = (source: string) =>
123
+ path.isAbsolute(source) ? path.relative(cwd, source) || "." : source;
124
+ const label = `Diff: ${displaySource(value.before.source)} → ${displaySource(value.after.source)}`;
125
+ return {
126
+ results: [
127
+ new FileMutationResult({
128
+ ok: true,
129
+ path: label,
130
+ beforeContentMap: { [label]: value.before.content },
131
+ afterContent: value.after.content,
132
+ diffs: [value.diff],
133
+ }),
134
+ ],
135
+ };
136
+ }
137
+ /** The agent sees the existing unified text diff with both source names. */
138
+ export function diffText(value: DiffOutcome): string {
139
+ return value.equal
140
+ ? `No differences: ${value.before.source} → ${value.after.source}`
141
+ : value.diff;
142
+ }
143
+ /** Presentation remains separate from complete comparison data. */
144
+ export function diffReadResult(value: DiffOutcome): ReadToolResult {
145
+ return { content: [{ type: "text", text: diffText(value) }], details: {} };
146
+ }
147
+
148
+ /** Standalone diff uses the same read service and configured editor renderer as Apply. */
149
+ export function registerDiff(
150
+ pi: ExtensionAPI,
151
+ editor: TextEditorCore,
152
+ getRead: () => ReadPluginApi | undefined,
153
+ ): void {
154
+ pi.registerTool({
155
+ name: "diff",
156
+ label: "Diff",
157
+ parameters: diffParameters,
158
+ promptSnippet: "Compare two text-readable sources without changing them",
159
+ description:
160
+ "Use diff to compare two sources without modifying them. before and after accept a source string or a read request {path, offset?, limit?, views?}. Use any source that read can resolve as text. Omit limit to compare complete resolved text; read presentation limits do not clip comparison inputs. Multiple resolved resources are joined with one newline separator in resolver order. Diff line numbers are relative to each selected text, not the original file when a window is selected. Native non-text content is rejected. Output uses the existing text diff and a shared output budget; oversized output has a full temporary reference. The same diff function is available inside Apply.",
161
+ renderCall(_args, theme) {
162
+ return new Text(theme.fg("toolTitle", theme.bold("Diff")), 0, 0);
163
+ },
164
+ renderResult(result, options, theme, context) {
165
+ const details = result.details as { comparison?: DiffOutcome } | undefined;
166
+ if (details?.comparison?.equal) return new Text(diffText(details.comparison), 0, 0);
167
+ const renderer = editor.getToolRenderer("diff")
168
+ ?.renderResult as ToolDefinition["renderResult"];
169
+ return renderer
170
+ ? renderer(result, options, theme, context)
171
+ : new Text(
172
+ result.content
173
+ .filter((block) => block.type === "text")
174
+ .map((block) => block.text)
175
+ .join("\n"),
176
+ 0,
177
+ 0,
178
+ );
179
+ },
180
+ async execute(_id, args, signal, _update, context) {
181
+ const read = getRead();
182
+ if (read === undefined) throw new Error("Diff requires the read extension");
183
+ const comparison = await executeDiff(read, args, { cwd: context.cwd, signal });
184
+ const full = diffText(comparison);
185
+ const bounded = truncateHead(full);
186
+ const temporarySource = bounded.truncated ? await read.saveTemporary(full) : undefined;
187
+ const footer = temporarySource === undefined ? "" : `\nFull diff: ${temporarySource}`;
188
+ return {
189
+ content: [
190
+ {
191
+ type: "text" as const,
192
+ text:
193
+ temporarySource === undefined
194
+ ? full
195
+ : truncateHead(full, {
196
+ maxLines: DEFAULT_MAX_LINES - 2,
197
+ maxBytes: DEFAULT_MAX_BYTES - Buffer.byteLength(footer),
198
+ }).content + footer,
199
+ },
200
+ ],
201
+ details: { ...diffPresentation(comparison, context.cwd), comparison, temporarySource },
202
+ };
203
+ },
204
+ });
205
+ }
@@ -27,6 +27,9 @@ import { setTextEditBatchRenderArgumentSink } from "#src/core/text-edit-batch-re
27
27
  import { createTextEditorCore } from "#src/core/text-editor-core.js";
28
28
  import { createReadFragmentResolver } from "#src/core/read-fragment-resolver.js";
29
29
  import { createTextTool } from "#src/core/text-mutation.js";
30
+ import { registerApply } from "#src/core/apply/tool.js";
31
+ import { registerDiff } from "#src/core/diff-tool.js";
32
+ import { registerFileOperationTools } from "#src/core/file-operation-tools.js";
30
33
  import { ToolCallInterceptionRenderStore } from "#src/core/tool-call-interceptor/rendering.js";
31
34
  import { registerToolCallAnnotationSink } from "pi-agent-text-editor/api/tool-call-interceptor";
32
35
 
@@ -124,6 +127,9 @@ export default async function registerTextEditorCore(
124
127
  });
125
128
 
126
129
  await core.waitForPendingPlugins();
130
+ if (pi.getFlag("pi-agent-ide-no-apply") !== true) await registerApply(pi, core);
131
+ registerFileOperationTools(pi, core);
132
+ registerDiff(pi, core, () => readApi);
127
133
  return core;
128
134
  }
129
135
 
@@ -0,0 +1,76 @@
1
+ import type { TextEditorCore } from "#src/core/text-editor-core.js";
2
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
3
+ import { Text } from "@earendil-works/pi-tui";
4
+ import {
5
+ deleteFileParameters,
6
+ transferFileParameters,
7
+ executeFileOperation,
8
+ } from "#src/core/file-operations.js";
9
+
10
+ /** Register whole-file tools using the same execution service as Apply. */
11
+ export function registerFileOperationTools(pi: ExtensionAPI, core: TextEditorCore): void {
12
+ for (const [name, description] of [
13
+ [
14
+ "delete_file",
15
+ "Use delete_file to permanently delete one regular file. Reject directories and symlinks. This deletes the file, unlike delete which removes selected text.",
16
+ ],
17
+ [
18
+ "move_file",
19
+ "Use move_file to move or rename one regular file. Reject directories and symlinks. Existing targets require overwrite: true. Works across devices. Configured post-processing can format UTF-8 text targets; binary contents remain unchanged.",
20
+ ],
21
+ [
22
+ "copy_file",
23
+ "Use copy_file to copy one regular file. Reject directories and symlinks. Existing targets require overwrite: true. Configured post-processing can format UTF-8 text targets; binary contents remain unchanged.",
24
+ ],
25
+ ] as const) {
26
+ pi.registerTool({
27
+ name,
28
+ label: name.replaceAll("_", " "),
29
+ renderCall(_args, theme) {
30
+ return new Text(theme.fg("toolTitle", theme.bold(name.replaceAll("_", " "))), 0, 0);
31
+ },
32
+ description,
33
+ promptSnippet: description,
34
+ parameters: name === "delete_file" ? deleteFileParameters : transferFileParameters,
35
+ async execute(_id, args, signal, _update, context) {
36
+ const outcome = await core.enqueueFileOperation(
37
+ () => executeFileOperation(name, args, context.cwd, signal),
38
+ signal,
39
+ );
40
+ let postProcessingError: string | undefined;
41
+ if (outcome.ok && outcome.target !== undefined) {
42
+ try {
43
+ await core.postProcessFile(outcome.target, { cwd: context.cwd, signal });
44
+ } catch (error) {
45
+ postProcessingError = error instanceof Error ? error.message : String(error);
46
+ }
47
+ }
48
+ return {
49
+ content: [
50
+ {
51
+ type: "text" as const,
52
+ text: [
53
+ `${name.replaceAll("_", " ")}: ${outcome.effect}`,
54
+ outcome.path,
55
+ postProcessingError === undefined
56
+ ? undefined
57
+ : `Post-processing failed: ${postProcessingError}`,
58
+ outcome.target === undefined ? undefined : `Target: ${outcome.target}`,
59
+ outcome.error === undefined
60
+ ? undefined
61
+ : `${outcome.error.code}: ${outcome.error.message}`,
62
+ ]
63
+ .filter((line) => line !== undefined)
64
+ .join("\n"),
65
+ },
66
+ ],
67
+ details: {
68
+ ...outcome,
69
+ ...(postProcessingError === undefined ? {} : { postProcessingError }),
70
+ },
71
+ isError: !outcome.ok,
72
+ };
73
+ },
74
+ });
75
+ }
76
+ }
@@ -0,0 +1,153 @@
1
+ import { lstat, unlink } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import fs from "fs-extra";
4
+ import { Type } from "typebox";
5
+ import { Value } from "typebox/value";
6
+
7
+ /** Whole-file operations, distinct from text-selection copy/move/remove. */
8
+ export const fileOperations = ["delete_file", "move_file", "copy_file"] as const;
9
+ export type FileOperation = (typeof fileOperations)[number];
10
+ const filePath = Type.String({
11
+ minLength: 1,
12
+ description: "Local regular file path, relative to cwd or absolute.",
13
+ });
14
+ export const deleteFileParameters = Type.Object(
15
+ { path: filePath },
16
+ { additionalProperties: false },
17
+ );
18
+ export const transferFileParameters = Type.Object(
19
+ {
20
+ path: filePath,
21
+ target: filePath,
22
+ overwrite: Type.Optional(
23
+ Type.Boolean({
24
+ description: "Allow replacing an existing regular target file. Defaults to false.",
25
+ }),
26
+ ),
27
+ },
28
+ { additionalProperties: false },
29
+ );
30
+
31
+ /** Plain receipt; unknown means the filesystem call failed after execution began. */
32
+ export interface FileOperationResult {
33
+ readonly kind: "file-operation";
34
+ readonly operation: FileOperation;
35
+ readonly ok: boolean;
36
+ readonly effect: "applied" | "not-applied" | "unknown";
37
+ readonly path?: string;
38
+ readonly target?: string;
39
+ readonly error?: { readonly code: string; readonly message: string };
40
+ }
41
+
42
+ /** Recognize a host-owned whole-file receipt for shared output rendering. */
43
+ export function isFileOperationResult(value: unknown): value is FileOperationResult {
44
+ return (
45
+ value !== null &&
46
+ typeof value === "object" &&
47
+ "kind" in value &&
48
+ value.kind === "file-operation"
49
+ );
50
+ }
51
+
52
+ /** Compact operation summary shared by standalone and Apply output. */
53
+ export function formatFileOperation(value: FileOperationResult): string {
54
+ return [
55
+ `${value.operation}: ${value.effect}`,
56
+ value.path,
57
+ value.target === undefined ? undefined : `Target: ${value.target}`,
58
+ value.error === undefined ? undefined : `${value.error.code}: ${value.error.message}`,
59
+ ]
60
+ .filter((line) => line !== undefined)
61
+ .join("\n");
62
+ }
63
+ /** Uses maintained filesystem primitives; never decodes file contents or recursively deletes. */
64
+ export async function executeFileOperation(
65
+ operation: FileOperation,
66
+ input: unknown,
67
+ cwd: string,
68
+ signal?: AbortSignal,
69
+ ): Promise<FileOperationResult> {
70
+ let started = false;
71
+ let source: string | undefined;
72
+ let target: string | undefined;
73
+ try {
74
+ const schema = operation === "delete_file" ? deleteFileParameters : transferFileParameters;
75
+ if (!Value.Check(schema, input))
76
+ throw Object.assign(new Error("Invalid file operation arguments"), {
77
+ code: "INVALID_ARGUMENTS",
78
+ });
79
+ const args = input as { path: string; target?: string; overwrite?: boolean };
80
+ source = path.resolve(cwd, args.path);
81
+ target = args.target === undefined ? undefined : path.resolve(cwd, args.target);
82
+ signal?.throwIfAborted();
83
+ const sourceStat = await regularFile(source);
84
+ if (target !== undefined) {
85
+ const targetStat = await optionalStat(target);
86
+ if (targetStat !== undefined) {
87
+ if (!targetStat.isFile() || targetStat.isSymbolicLink())
88
+ throw Object.assign(new Error("Target must be a regular file"), {
89
+ code: "INVALID_FILE_TYPE",
90
+ });
91
+ if (
92
+ source === target ||
93
+ (sourceStat.ino === targetStat.ino && sourceStat.dev === targetStat.dev)
94
+ )
95
+ throw Object.assign(new Error("Source and target are the same file"), {
96
+ code: "SAME_FILE",
97
+ });
98
+ if (args.overwrite !== true)
99
+ throw Object.assign(new Error("Target exists; use overwrite: true to replace it"), {
100
+ code: "EEXIST",
101
+ });
102
+ }
103
+ }
104
+ signal?.throwIfAborted();
105
+ started = true;
106
+ if (operation === "delete_file") await unlink(source);
107
+ else if (target !== undefined) {
108
+ if (operation === "copy_file")
109
+ await fs.copy(source, target, { overwrite: args.overwrite === true, errorOnExist: true });
110
+ else await fs.move(source, target, { overwrite: args.overwrite === true });
111
+ }
112
+ return {
113
+ kind: "file-operation",
114
+ operation,
115
+ ok: true,
116
+ effect: "applied",
117
+ path: source,
118
+ ...(target === undefined ? {} : { target }),
119
+ };
120
+ } catch (error) {
121
+ return {
122
+ kind: "file-operation",
123
+ operation,
124
+ ok: false,
125
+ effect: started ? "unknown" : "not-applied",
126
+ ...(source === undefined ? {} : { path: source }),
127
+ ...(target === undefined ? {} : { target }),
128
+ error: {
129
+ code:
130
+ error !== null && typeof error === "object" && "code" in error
131
+ ? String(error.code)
132
+ : "FILE_OPERATION_FAILED",
133
+ message: error instanceof Error ? error.message : String(error),
134
+ },
135
+ };
136
+ }
137
+ }
138
+
139
+ async function regularFile(file: string) {
140
+ const stat = await lstat(file);
141
+ if (!stat.isFile() || stat.isSymbolicLink())
142
+ throw Object.assign(new Error("Source must be a regular file"), { code: "INVALID_FILE_TYPE" });
143
+ return stat;
144
+ }
145
+ async function optionalStat(file: string) {
146
+ try {
147
+ return await lstat(file);
148
+ } catch (error) {
149
+ if (error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT")
150
+ return undefined;
151
+ throw error;
152
+ }
153
+ }
@@ -15,9 +15,12 @@ export function createUnifiedDiff(
15
15
  path: string,
16
16
  beforeContent: string,
17
17
  afterContent: string,
18
+ afterPath = path,
18
19
  ): UnifiedDiffResult {
19
- const diff = createTwoFilesPatch(path, path, beforeContent, afterContent, "", "", { context: 3 })
20
- .replace(/^Index: .*\n={3,}\n?/m, "")
20
+ const diff = createTwoFilesPatch(path, afterPath, beforeContent, afterContent, "", "", {
21
+ context: 3,
22
+ })
23
+ .replace(/^(?:Index: .*\n)?={3,}\n?/m, "")
21
24
  .trimEnd();
22
25
 
23
26
  return { diff, stats: computeStats(beforeContent, afterContent) };
@@ -312,6 +312,7 @@ export class FileMutationAgentResult {
312
312
  `Formatting: ${fmr.data.formatting?.status ?? "not-reported"}${fmr.data.formatting?.formatter === undefined ? "" : ` (${fmr.data.formatting.formatter})`}.`,
313
313
  ];
314
314
 
315
+ for (const status of fmr.data.diffStatuses ?? []) blocks.push(status.text);
315
316
  for (const diff of fmr.diffs) {
316
317
  const path = /^--- (.+)$/m.exec(diff)?.[1] ?? fmr.path ?? "<unknown file>";
317
318
  blocks.push(renderFinalStateFragment(fmr, path).join("\n"));
@@ -20,12 +20,15 @@ export interface MutationFormatting {
20
20
  | "unchanged"
21
21
  | "changed"
22
22
  | "failed"
23
- | "not-reported";
23
+ | "not-reported"
24
+ | "deferred";
24
25
  readonly formatter?: string;
25
26
  }
26
27
 
27
28
  /** Plain-text, per-file status shown beside diff counts and retained in history. */
28
29
  export interface MutationDiffStatus {
30
+ /** Formatter identity allows multi-file summaries without parsing display text. */
31
+ readonly formatter?: string;
29
32
  readonly text: string;
30
33
  readonly tone?: "muted" | "success" | "warning" | "error";
31
34
  }
@@ -264,6 +267,8 @@ export interface FileMutationData {
264
267
  * Phases are batch-wide (gate runs once for all files), not per-FMR.
265
268
  */
266
269
  export interface FileMutationBatchResult {
270
+ /** Structured contributions from configured IDE mutation handlers. */
271
+ readonly metadata?: Readonly<Record<string, unknown>>;
267
272
  /**
268
273
  Per-file mutation results (undefined when tool aborted).
269
274
  */