pi-agent-ide 0.4.0 → 0.5.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 (399) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +7 -7
  3. package/dist/chunk-25CZ5ZIU.js +3 -0
  4. package/dist/chunk-526E364R.js +3 -0
  5. package/dist/chunk-5PLV4HLG.js +1 -0
  6. package/dist/chunk-5QQABP47.js +14 -0
  7. package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
  8. package/dist/chunk-AWXVJ5AC.js +1 -0
  9. package/dist/chunk-BGUSBUUD.js +26 -0
  10. package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
  11. package/dist/chunk-ESPNEJHK.js +1 -0
  12. package/dist/chunk-G725MARR.js +16 -0
  13. package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
  14. package/dist/chunk-IQD6PON5.js +0 -0
  15. package/dist/chunk-J4RTW44E.js +1 -0
  16. package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
  17. package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
  18. package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
  19. package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
  20. package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
  21. package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
  22. package/dist/chunk-QH4ZUDOD.js +1 -0
  23. package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
  24. package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
  25. package/dist/chunk-U2JKHKLK.js +0 -0
  26. package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.js} +1 -1
  27. package/dist/chunk-ZG2MWXCR.js +2 -0
  28. package/dist/chunk-ZUMN6U77.js +27 -0
  29. package/dist/entry-10.js +1 -1
  30. package/dist/entry-11.js +1 -1
  31. package/dist/entry-12.js +1 -1
  32. package/dist/entry-13.js +1 -1
  33. package/dist/entry-14.js +1 -1
  34. package/dist/entry-15.js +1 -0
  35. package/dist/entry-17.js +1 -1
  36. package/dist/entry-18.js +1 -1
  37. package/dist/entry-19.js +1 -1
  38. package/dist/entry-20.js +1 -1
  39. package/dist/entry-21.js +1 -2
  40. package/dist/entry-22.js +2 -1
  41. package/dist/entry-23.js +1 -1
  42. package/dist/entry-24.js +1 -1
  43. package/dist/entry-25.js +1 -1
  44. package/dist/entry-26.js +1 -12
  45. package/dist/entry-27.js +12 -1
  46. package/dist/entry-28.js +1 -1
  47. package/dist/entry-29.js +1 -1
  48. package/dist/entry-30.js +1 -1
  49. package/dist/entry-31.js +1 -4
  50. package/dist/entry-32.js +3 -8
  51. package/dist/entry-33.js +9 -1
  52. package/dist/entry-34.js +1 -1
  53. package/dist/entry-35.js +1 -1
  54. package/dist/entry-36.js +1 -1
  55. package/dist/entry-37.js +1 -1
  56. package/dist/entry-38.js +1 -1
  57. package/dist/entry-39.js +1 -1
  58. package/dist/entry-40.js +1 -18
  59. package/dist/entry-41.js +18 -1
  60. package/dist/entry-42.js +1 -1
  61. package/dist/entry-43.js +1 -1
  62. package/dist/entry-44.js +1 -1
  63. package/dist/entry-45.js +1 -7
  64. package/dist/entry-46.js +7 -11
  65. package/dist/entry-47.js +11 -1
  66. package/dist/entry-48.js +1 -1
  67. package/dist/entry-49.js +1 -1
  68. package/dist/entry-50.js +1 -1
  69. package/dist/entry-51.js +1 -1
  70. package/dist/entry-52.js +1 -1
  71. package/dist/entry-53.js +1 -1
  72. package/dist/entry-54.js +1 -1
  73. package/dist/entry-55.js +1 -0
  74. package/dist/entry-56.js +0 -1
  75. package/dist/entry-57.js +1 -0
  76. package/dist/entry-58.js +0 -1
  77. package/dist/entry-59.js +1 -1
  78. package/dist/entry-60.js +1 -1
  79. package/dist/entry-61.js +1 -1
  80. package/dist/entry-62.js +1 -1
  81. package/dist/entry-63.js +1 -1
  82. package/dist/entry-64.js +1 -0
  83. package/dist/entry-65.js +0 -1
  84. package/dist/entry-66.js +1 -0
  85. package/dist/entry-67.js +0 -1
  86. package/dist/entry-68.js +1 -1
  87. package/dist/entry-69.js +1 -1
  88. package/dist/entry-70.js +1 -123
  89. package/dist/entry-71.js +198 -25
  90. package/dist/entry-72.js +30 -2
  91. package/dist/entry-73.js +2 -1
  92. package/dist/entry-74.js +1 -1
  93. package/dist/entry-75.js +1 -1
  94. package/dist/entry-76.js +1 -3
  95. package/dist/entry-77.js +3 -1
  96. package/dist/entry-78.js +1 -1
  97. package/dist/entry-79.js +1 -1
  98. package/dist/entry-8.js +1 -1
  99. package/dist/entry-80.js +1 -0
  100. package/dist/entry-9.js +1 -1
  101. package/dist/pi-agent-ide.js +3 -3
  102. package/docs/configuration.md +1 -1
  103. package/docs/user-hooks.md +68 -0
  104. package/node_modules/pi-agent-doctor/package.json +6 -6
  105. package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
  106. package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
  107. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -0
  108. package/node_modules/pi-agent-filesystem/package.json +7 -7
  109. package/node_modules/pi-agent-filesystem-image/package.json +4 -4
  110. package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
  111. package/node_modules/pi-agent-filesystem-text/package.json +4 -4
  112. package/node_modules/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  113. package/node_modules/pi-agent-ide-ast/package.json +32 -11
  114. package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  115. package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  116. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  117. package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  118. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  119. package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  120. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  121. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  122. package/node_modules/pi-agent-ide-changes/index.ts +3 -1
  123. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  124. package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  125. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  126. package/node_modules/pi-agent-ide-formatter/package.json +9 -4
  127. package/node_modules/pi-agent-ide-languages/package.json +3 -3
  128. package/node_modules/pi-agent-ide-lint/package.json +13 -8
  129. package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
  130. package/node_modules/pi-agent-ide-lsp/package.json +15 -10
  131. package/node_modules/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  132. package/node_modules/pi-agent-image/package.json +3 -3
  133. package/node_modules/pi-agent-invariant/package.json +2 -2
  134. package/node_modules/pi-agent-pdf/package.json +3 -3
  135. package/node_modules/pi-agent-read/package.json +11 -11
  136. package/node_modules/pi-agent-read/runtime/entry-40.js +0 -1
  137. package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
  138. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  139. package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
  140. package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
  141. package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
  142. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  143. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  144. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  145. package/node_modules/pi-agent-resource/package.json +2 -2
  146. package/node_modules/pi-agent-search/package.json +7 -7
  147. package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
  148. package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
  149. package/node_modules/pi-agent-search-text/index.ts +1 -1
  150. package/node_modules/pi-agent-search-text/package.json +9 -9
  151. package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
  152. package/node_modules/pi-agent-search-text/src/resolvers.ts +47 -19
  153. package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
  154. package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
  155. package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
  156. package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
  157. package/node_modules/pi-agent-search-text/src/search-session.ts +6 -3
  158. package/node_modules/pi-agent-text/package.json +3 -3
  159. package/node_modules/pi-agent-text/runtime/entry-49.js +1 -0
  160. package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
  161. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  162. package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
  163. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  164. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  165. package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
  166. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  167. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  168. package/node_modules/pi-agent-text-editor/package.json +25 -25
  169. package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
  170. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  171. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  172. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  173. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  174. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  175. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  176. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  177. package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  178. package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  179. package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  180. package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  181. package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  182. package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  183. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  184. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  185. package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
  186. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  187. package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  188. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  189. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  190. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  191. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  192. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  195. package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
  196. package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
  197. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  198. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  199. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  200. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  201. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  202. package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +1 -0
  203. package/node_modules/pi-agent-web/package.json +7 -7
  204. package/node_modules/pi-agent-web-html/package.json +3 -3
  205. package/node_modules/pi-agent-web-image/package.json +4 -4
  206. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  207. package/node_modules/pi-agent-web-text/package.json +4 -4
  208. package/node_modules/pi-agent-web-text/runtime/entry-80.js +2 -0
  209. package/package.json +58 -38
  210. package/src/api/hooks.ts +168 -0
  211. package/src/api/text-editor.ts +2 -0
  212. package/src/composite/builtin-extensions.ts +7 -0
  213. package/src/composite/module-labels.ts +8 -0
  214. package/src/composite/preferences.ts +3 -3
  215. package/src/core/reload-resource-store.ts +34 -0
  216. package/src/doctor/tip-provider.ts +1 -0
  217. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  218. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
  219. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
  220. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
  221. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
  222. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +2 -0
  223. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  224. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +2 -0
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
  230. package/src/extensions/pi-agent-read/package.json +11 -11
  231. package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
  232. package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
  233. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
  234. package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
  235. package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
  236. package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
  237. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
  238. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
  239. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
  240. package/src/extensions/pi-agent-search/package.json +7 -7
  241. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
  242. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
  243. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
  244. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
  245. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +47 -19
  246. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
  247. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
  248. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
  249. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
  250. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +6 -3
  251. package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
  252. package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
  253. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
  254. package/src/extensions/pi-agent-text-editor/package.json +25 -25
  255. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
  256. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
  257. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
  258. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
  259. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
  260. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
  261. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
  262. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -0
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
  265. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
  266. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  267. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
  268. package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
  269. package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
  270. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
  271. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
  272. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
  273. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
  274. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
  275. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
  276. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
  277. package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
  278. package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
  279. package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
  280. package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
  281. package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
  282. package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
  283. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
  284. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
  285. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
  286. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
  287. package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
  288. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
  289. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
  290. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
  291. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
  292. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
  293. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
  294. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
  295. package/src/plugins/pi-agent-ide-ast/package.json +32 -11
  296. package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
  297. package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
  298. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
  299. package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
  300. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
  301. package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
  302. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
  303. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
  304. package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
  305. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  306. package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
  307. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
  308. package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
  309. package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
  310. package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
  311. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
  312. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
  313. package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
  314. package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
  315. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
  316. package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
  317. package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
  318. package/src/plugins/pi-agent-ide-languages/package.json +3 -3
  319. package/src/plugins/pi-agent-ide-lint/package.json +13 -8
  320. package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
  321. package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
  322. package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
  323. package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
  324. package/src/plugins/pi-agent-ide-processes/src/registry.ts +81 -0
  325. package/src/plugins/pi-agent-ide-processes/src/ui.ts +252 -0
  326. package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
  327. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
  328. package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +30 -0
  329. package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
  330. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
  331. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
  332. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
  333. package/src/plugins/pi-agent-ide-terminal/src/types.ts +13 -1
  334. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
  335. package/dist/chunk-3SE372WC.js +0 -3
  336. package/dist/chunk-5MSNYFDE.js +0 -1
  337. package/dist/chunk-7JYQMAEL.js +0 -14
  338. package/dist/chunk-B5KB2I7J.js +0 -3
  339. package/dist/chunk-NMFQGKPE.js +0 -2
  340. package/dist/chunk-OVUYPHDE.js +0 -1
  341. package/dist/chunk-TPIHQYK2.js +0 -14
  342. package/dist/chunk-XSTHESNR.js +0 -25
  343. package/dist/entry-16.js +0 -1
  344. package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
  345. package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
  346. package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  347. package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  348. package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
  349. package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
  350. package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  351. package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  352. package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  353. package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
  354. package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
  355. package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
  356. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
  357. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
  358. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
  359. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
  360. package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
  361. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
  362. package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
  363. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
  364. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
  365. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
  366. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
  367. package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
  368. package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
  369. package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
  370. /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
  371. /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
  372. /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
  373. /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  374. /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  375. /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  376. /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
  377. /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
  378. /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
  379. /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
  380. /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
  381. /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
  382. /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
  383. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
  384. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
  385. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
  386. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
  387. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
  388. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
  389. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
  390. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
  391. /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
  392. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
  393. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
  394. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
  395. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
  396. /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
  397. /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
  398. /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
  399. /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
@@ -0,0 +1,387 @@
1
+ import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import fs from "fs-extra";
4
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
5
+ import { applyTextChanges, type TextChange } from "#src/core/text-change-engine.js";
6
+ import type { TextEditorCore } from "#src/core/text-editor-core.js";
7
+ import type {
8
+ ScriptMutationFile,
9
+ ScriptMutationOutcome,
10
+ } from "#src/core/apply/mutation-outcome.js";
11
+
12
+ export interface EditorSnapshot {
13
+ readonly id: string;
14
+ readonly source: string;
15
+ readonly content: string;
16
+ }
17
+
18
+ interface Selection {
19
+ readonly document: string;
20
+ readonly from: number;
21
+ readonly to: number;
22
+ readonly text: string;
23
+ }
24
+
25
+ interface TextOperation {
26
+ readonly kind: "replace";
27
+ readonly selection: Selection;
28
+ readonly text: string;
29
+ }
30
+
31
+ interface CreateOperation {
32
+ readonly kind: "create";
33
+ readonly path: string;
34
+ readonly content: string;
35
+ }
36
+
37
+ interface FileOperation {
38
+ readonly kind: "delete" | "copy" | "move";
39
+ readonly path: string;
40
+ readonly target?: string;
41
+ readonly overwrite?: boolean;
42
+ }
43
+
44
+ export interface EditorTransactionRequest {
45
+ readonly snapshots: readonly EditorSnapshot[];
46
+ readonly operations: readonly (TextOperation | CreateOperation | FileOperation)[];
47
+ }
48
+
49
+ interface SavedPath {
50
+ readonly path: string;
51
+ readonly existed: boolean;
52
+ readonly bytes?: Uint8Array;
53
+ }
54
+
55
+ /** Commit one snapshot-guarded Apply transaction and restore touched paths after a write failure. */
56
+ export async function executeEditorTransaction(
57
+ editor: TextEditorCore,
58
+ input: unknown,
59
+ signal: AbortSignal,
60
+ context: ExtensionContext,
61
+ ): Promise<ScriptMutationOutcome> {
62
+ const request = parseRequest(input);
63
+ if (request.operations.length === 0) throw invalid("apply() requires at least one staged change");
64
+
65
+ const snapshots = new Map(request.snapshots.map((snapshot) => [snapshot.id, snapshot]));
66
+ if (snapshots.size !== request.snapshots.length) throw invalid("Duplicate editor snapshot id");
67
+ const textChanges = new Map<string, TextChange[]>();
68
+ const creates: CreateOperation[] = [];
69
+ const fileOperations: FileOperation[] = [];
70
+
71
+ for (const operation of request.operations) {
72
+ if (operation.kind === "replace") {
73
+ const snapshot = snapshots.get(operation.selection.document);
74
+ if (snapshot === undefined) throw invalid("Selection belongs to an unknown editor snapshot");
75
+ const { from, to, text } = operation.selection;
76
+ if (
77
+ !Number.isInteger(from) ||
78
+ !Number.isInteger(to) ||
79
+ from < 0 ||
80
+ to < from ||
81
+ to > snapshot.content.length
82
+ )
83
+ throw invalid(`Selection ${from}-${to} is outside ${snapshot.source}`);
84
+ if (snapshot.content.slice(from, to) !== text)
85
+ throw invalid(`Selection text does not match ${snapshot.source}`);
86
+ const changes = textChanges.get(snapshot.source) ?? [];
87
+ changes.push({ from, to, insert: operation.text });
88
+ textChanges.set(snapshot.source, changes);
89
+ } else if (operation.kind === "create") creates.push(operation);
90
+ else fileOperations.push(operation);
91
+ }
92
+
93
+ validateTextChanges(textChanges);
94
+ const cwd = context.cwd;
95
+ const touched = touchedPaths(cwd, textChanges, creates, fileOperations);
96
+ await preflight(touched, snapshots, textChanges, creates, fileOperations, cwd);
97
+ const saved = await Promise.all([...touched].map(savePath));
98
+ const files: ScriptMutationFile[] = [];
99
+
100
+ try {
101
+ if (textChanges.size > 0 || creates.length > 0) {
102
+ const createMap = new Map(
103
+ creates.map((item) => [path.resolve(cwd, item.path), item.content]),
104
+ );
105
+ const sources = new Set([...textChanges.keys(), ...createMap.keys()]);
106
+ const outcome = await editor.editTexts(
107
+ [...sources].map((source) => ({
108
+ source,
109
+ read: true,
110
+ ...(createMap.has(source) && { allowReadFailure: true }),
111
+ })),
112
+ { cwd, signal, intent: "edit" },
113
+ (texts) => {
114
+ for (const snapshot of snapshots.values()) {
115
+ if (textChanges.has(snapshot.source) && texts.get(snapshot.source) !== snapshot.content)
116
+ throw stale(snapshot.source);
117
+ }
118
+ const changes = new Map<string, readonly TextChange[]>();
119
+ for (const source of sources) {
120
+ const before = texts.get(source) ?? "";
121
+ const planned = textChanges.get(source) ?? [
122
+ { from: 0, to: 0, insert: createMap.get(source) ?? "" },
123
+ ];
124
+ changes.set(source, planned);
125
+ const applied = applyTextChanges(before, planned, createMap.has(source));
126
+ files.push({
127
+ source,
128
+ before: createMap.has(source) ? null : before,
129
+ after: applied.content,
130
+ action: createMap.has(source) ? "created" : "edited",
131
+ changes: applied.changes.map((change, editIndex) => ({
132
+ editIndex,
133
+ fromA: change.fromBefore,
134
+ toA: change.toBefore,
135
+ fromB: change.fromAfter,
136
+ toB: change.toAfter,
137
+ removedText: change.removedText,
138
+ insertedText: change.insertedText,
139
+ })),
140
+ formatting: { status: "not-reported" },
141
+ });
142
+ }
143
+ return { changes, result: undefined };
144
+ },
145
+ );
146
+ if (outcome.kind === "failed")
147
+ throw outcome.failure.cause instanceof Error
148
+ ? outcome.failure.cause
149
+ : new Error(outcome.failure.message);
150
+ }
151
+
152
+ for (const operation of fileOperations) await performFileOperation(operation, cwd);
153
+ for (const target of fileOperations.flatMap((operation) =>
154
+ operation.target === undefined ? [] : [path.resolve(cwd, operation.target)],
155
+ )) {
156
+ if ((await optionalStat(target)) !== undefined)
157
+ await editor.postProcessFile(target, { cwd, signal });
158
+ }
159
+ const transaction = await editor.recordApplyUndo(saved);
160
+ return {
161
+ operation: "apply",
162
+ transaction,
163
+ ok: true,
164
+ effect: "applied",
165
+ files,
166
+ completed: [...touched],
167
+ errors: [],
168
+ };
169
+ } catch (error) {
170
+ const rollbackErrors = await rollback(saved);
171
+ throw Object.assign(new Error(error instanceof Error ? error.message : String(error)), {
172
+ code: "TRANSACTION_FAILED",
173
+ details: {
174
+ effect: rollbackErrors.length === 0 ? "rolled-back" : "rollback-incomplete",
175
+ files: [...touched],
176
+ rollbackErrors,
177
+ },
178
+ });
179
+ }
180
+ }
181
+
182
+ function parseRequest(value: unknown): EditorTransactionRequest {
183
+ const request = record(value, "apply() transaction");
184
+ const rawSnapshots = array(request.snapshots, "snapshots");
185
+ const rawOperations = array(request.operations, "operations");
186
+ const snapshots = rawSnapshots.map((value, index) => {
187
+ const item = record(value, `snapshot ${index + 1}`);
188
+ return {
189
+ id: string(item.id, "snapshot id"),
190
+ source: string(item.source, "snapshot source"),
191
+ content: text(item.content, "snapshot content"),
192
+ };
193
+ });
194
+ const operations = rawOperations.map(
195
+ (value, index): TextOperation | CreateOperation | FileOperation => {
196
+ const item = record(value, `operation ${index + 1}`);
197
+ const kind = string(item.kind, "operation kind");
198
+ if (kind === "replace") {
199
+ const selected = record(item.selection, "selection");
200
+ return {
201
+ kind,
202
+ selection: {
203
+ document: string(selected.document, "selection document"),
204
+ from: integer(selected.from, "selection from"),
205
+ to: integer(selected.to, "selection to"),
206
+ text: text(selected.text, "selection text"),
207
+ },
208
+ text: text(item.text, "replacement text"),
209
+ };
210
+ }
211
+ if (kind === "create")
212
+ return {
213
+ kind,
214
+ path: string(item.path, "create path"),
215
+ content: text(item.content, "create content"),
216
+ };
217
+ if (kind === "delete") return { kind, path: string(item.path, "delete path") };
218
+ if (kind === "copy" || kind === "move")
219
+ return {
220
+ kind,
221
+ path: string(item.path, `${kind} path`),
222
+ target: string(item.target, `${kind} target`),
223
+ ...(item.overwrite === true && { overwrite: true }),
224
+ };
225
+ throw invalid(`Unknown transaction operation: ${kind}`);
226
+ },
227
+ );
228
+ return { snapshots, operations };
229
+ }
230
+
231
+ function record(value: unknown, label: string): Record<string, unknown> {
232
+ if (value === null || typeof value !== "object" || Array.isArray(value))
233
+ throw invalid(`${label} must be an object`);
234
+ return value as Record<string, unknown>;
235
+ }
236
+ function array(value: unknown, label: string): readonly unknown[] {
237
+ if (!Array.isArray(value)) throw invalid(`${label} must be an array`);
238
+ return value;
239
+ }
240
+ function string(value: unknown, label: string): string {
241
+ if (typeof value !== "string" || value.length === 0)
242
+ throw invalid(`${label} must be a non-empty string`);
243
+ return value;
244
+ }
245
+ function text(value: unknown, label: string): string {
246
+ if (typeof value !== "string") throw invalid(`${label} must be a string`);
247
+ return value;
248
+ }
249
+ function integer(value: unknown, label: string): number {
250
+ if (!Number.isInteger(value)) throw invalid(`${label} must be an integer`);
251
+ return value as number;
252
+ }
253
+
254
+ function validateTextChanges(changes: ReadonlyMap<string, readonly TextChange[]>): void {
255
+ for (const [source, items] of changes) {
256
+ const ordered = [...items].sort((a, b) => a.from - b.from || a.to - b.to);
257
+ for (let index = 1; index < ordered.length; index += 1) {
258
+ const previous = ordered[index - 1];
259
+ const current = ordered[index];
260
+ if (previous !== undefined && current !== undefined && current.from < previous.to)
261
+ throw invalid(`Overlapping selections in ${source}`);
262
+ }
263
+ }
264
+ }
265
+
266
+ function touchedPaths(
267
+ cwd: string,
268
+ changes: ReadonlyMap<string, unknown>,
269
+ creates: readonly CreateOperation[],
270
+ operations: readonly FileOperation[],
271
+ ): Set<string> {
272
+ const result = new Set([...changes.keys()].map((source) => path.resolve(cwd, source)));
273
+ for (const item of creates) result.add(path.resolve(cwd, item.path));
274
+ for (const item of operations) {
275
+ result.add(path.resolve(cwd, item.path));
276
+ if (item.target !== undefined) result.add(path.resolve(cwd, item.target));
277
+ }
278
+ return result;
279
+ }
280
+
281
+ async function preflight(
282
+ touched: ReadonlySet<string>,
283
+ snapshots: ReadonlyMap<string, EditorSnapshot>,
284
+ changes: ReadonlyMap<string, unknown>,
285
+ creates: readonly CreateOperation[],
286
+ operations: readonly FileOperation[],
287
+ cwd: string,
288
+ ): Promise<void> {
289
+ for (const file of touched) {
290
+ const stat = await optionalStat(file);
291
+ if (stat !== undefined && (!stat.isFile() || stat.isSymbolicLink()))
292
+ throw invalid(`${file} is not a regular file`);
293
+ }
294
+ for (const snapshot of snapshots.values()) {
295
+ if (!changes.has(snapshot.source)) continue;
296
+ let current: string;
297
+ try {
298
+ current = await readFile(snapshot.source, "utf8");
299
+ } catch {
300
+ throw stale(snapshot.source);
301
+ }
302
+ if (current !== snapshot.content) throw stale(snapshot.source);
303
+ }
304
+ const createPaths = creates.map((item) => path.resolve(cwd, item.path));
305
+ if (new Set(createPaths).size !== createPaths.length)
306
+ throw invalid("A transaction cannot create the same path more than once");
307
+ for (const item of creates)
308
+ if ((await optionalStat(path.resolve(cwd, item.path))) !== undefined)
309
+ throw invalid(`Create target exists: ${item.path}`);
310
+ const existence = new Map<string, boolean>();
311
+ for (const file of touched) existence.set(file, (await optionalStat(file)) !== undefined);
312
+ for (const item of creates) existence.set(path.resolve(cwd, item.path), true);
313
+ for (const item of operations) {
314
+ const source = path.resolve(cwd, item.path);
315
+ if (existence.get(source) !== true) throw invalid(`Source does not exist: ${item.path}`);
316
+ if (item.kind === "delete") {
317
+ existence.set(source, false);
318
+ continue;
319
+ }
320
+ const target = path.resolve(cwd, item.target ?? "");
321
+ if (source === target) throw invalid("Source and target are the same file");
322
+ if (existence.get(target) === true && item.overwrite !== true)
323
+ throw invalid(`Target exists: ${item.target}`);
324
+ existence.set(target, true);
325
+ if (item.kind === "move") existence.set(source, false);
326
+ }
327
+ }
328
+
329
+ async function performFileOperation(operation: FileOperation, cwd: string): Promise<void> {
330
+ const source = path.resolve(cwd, operation.path);
331
+ if (operation.kind === "delete") {
332
+ await rm(source);
333
+ return;
334
+ }
335
+ const target = path.resolve(cwd, operation.target ?? "");
336
+ await mkdir(path.dirname(target), { recursive: true });
337
+ if (operation.kind === "copy")
338
+ await fs.copy(source, target, { overwrite: operation.overwrite === true, errorOnExist: true });
339
+ else await fs.move(source, target, { overwrite: operation.overwrite === true });
340
+ }
341
+
342
+ async function savePath(file: string): Promise<SavedPath> {
343
+ try {
344
+ return { path: file, existed: true, bytes: await readFile(file) };
345
+ } catch (error) {
346
+ if (isCode(error, "ENOENT")) return { path: file, existed: false };
347
+ throw error;
348
+ }
349
+ }
350
+
351
+ async function rollback(saved: readonly SavedPath[]): Promise<readonly string[]> {
352
+ const errors: string[] = [];
353
+ for (const item of [...saved].reverse()) {
354
+ try {
355
+ if (item.existed) {
356
+ await mkdir(path.dirname(item.path), { recursive: true });
357
+ await writeFile(item.path, item.bytes ?? new Uint8Array());
358
+ } else await rm(item.path, { force: true });
359
+ } catch (error) {
360
+ if (!item.existed && (isCode(error, "ENOENT") || isCode(error, "ENOTDIR"))) continue;
361
+ errors.push(`${item.path}: ${error instanceof Error ? error.message : String(error)}`);
362
+ }
363
+ }
364
+ return errors;
365
+ }
366
+
367
+ async function optionalStat(file: string) {
368
+ try {
369
+ return await lstat(file);
370
+ } catch (error) {
371
+ if (isCode(error, "ENOENT")) return undefined;
372
+ throw error;
373
+ }
374
+ }
375
+
376
+ function isCode(error: unknown, code: string): boolean {
377
+ return error !== null && typeof error === "object" && "code" in error && error.code === code;
378
+ }
379
+
380
+ function invalid(message: string): Error {
381
+ return Object.assign(new Error(message), { code: "INVALID_TRANSACTION" });
382
+ }
383
+ function stale(source: string): Error {
384
+ return Object.assign(new Error(`Snapshot changed before apply(): ${source}`), {
385
+ code: "STALE_SNAPSHOT",
386
+ });
387
+ }
@@ -29,7 +29,6 @@ import { createReadFragmentResolver } from "#src/core/read-fragment-resolver.js"
29
29
  import { createTextTool } from "#src/core/text-mutation.js";
30
30
  import { registerApply } from "#src/core/apply/tool.js";
31
31
  import { registerDiff } from "#src/core/diff-tool.js";
32
- import { registerFileOperationTools } from "#src/core/file-operation-tools.js";
33
32
  import { ToolCallInterceptionRenderStore } from "#src/core/tool-call-interceptor/rendering.js";
34
33
  import { registerToolCallAnnotationSink } from "pi-agent-text-editor/api/tool-call-interceptor";
35
34
 
@@ -128,7 +127,6 @@ export default async function registerTextEditorCore(
128
127
 
129
128
  await core.waitForPendingPlugins();
130
129
  if (pi.getFlag("pi-agent-ide-no-apply") !== true) await registerApply(pi, core);
131
- registerFileOperationTools(pi, core);
132
130
  registerDiff(pi, core, () => readApi);
133
131
  return core;
134
132
  }
@@ -144,6 +142,9 @@ function isFailedTextMutationResult(details: unknown): boolean {
144
142
  return true;
145
143
  }
146
144
 
145
+ const semanticAction = isRecord(details.metadata) ? details.metadata.semanticAction : undefined;
146
+ if (isRecord(semanticAction) && semanticAction.ok === false) return true;
147
+
147
148
  const results = details.results;
148
149
  return (
149
150
  Array.isArray(results) &&
@@ -1,76 +1,73 @@
1
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";
2
+ import type { FileOperation } from "#src/core/file-operations.js";
3
+ import { executeFileOperation } from "#src/core/file-operations.js";
4
+ import type { AgentToolResult, ExtensionContext } from "@earendil-works/pi-coding-agent";
5
+ import type { FileMutationBatchResult } from "#src/core/mutation-result/file-mutation-result.js";
9
6
 
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);
7
+ /** Return whether a hybrid text tool invocation addresses a complete file. */
8
+ export function isWholeFileInvocation(
9
+ operation: FileOperation | undefined,
10
+ input: Readonly<Record<string, unknown>>,
11
+ ): operation is FileOperation {
12
+ if (
13
+ operation === undefined ||
14
+ typeof input.path !== "string" ||
15
+ input.path.length === 0 ||
16
+ input.path.startsWith("SEARCH#")
17
+ )
18
+ return false;
19
+ if (["start", "end", "targetStart", "targetEnd"].some((field) => field in input)) return false;
20
+ return operation === "delete" || (typeof input.target === "string" && input.target.length > 0);
21
+ }
22
+
23
+ /** Execute the complete-file mode shared by copy, move, and delete. */
24
+ export async function executeWholeFileTool(
25
+ core: TextEditorCore,
26
+ operation: FileOperation,
27
+ input: Readonly<Record<string, unknown>>,
28
+ signal: AbortSignal | undefined,
29
+ context: ExtensionContext,
30
+ ): Promise<AgentToolResult<FileMutationBatchResult>> {
31
+ const outcome = await core.enqueueFileOperation(
32
+ () => executeFileOperation(operation, input, context.cwd, signal),
33
+ signal,
34
+ );
35
+ let postProcessingError: string | undefined;
36
+ if (outcome.ok && outcome.target !== undefined) {
37
+ try {
38
+ await core.postProcessFile(outcome.target, { cwd: context.cwd, signal });
39
+ } catch (error) {
40
+ postProcessingError = error instanceof Error ? error.message : String(error);
41
+ }
42
+ }
43
+ return {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: [
48
+ `${operation}: ${outcome.effect}`,
49
+ outcome.path,
50
+ outcome.target === undefined ? undefined : `Target: ${outcome.target}`,
51
+ postProcessingError === undefined
52
+ ? undefined
53
+ : `Post-processing failed: ${postProcessingError}`,
54
+ outcome.error === undefined
55
+ ? undefined
56
+ : `${outcome.error.code}: ${outcome.error.message}`,
57
+ ]
58
+ .filter((line) => line !== undefined)
59
+ .join("\n"),
31
60
  },
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
- };
61
+ ],
62
+ details: {
63
+ results: [],
64
+ metadata: {
65
+ semanticAction: {
66
+ ...outcome,
67
+ ...(postProcessingError === undefined ? {} : { postProcessingError }),
68
+ source: outcome.path,
69
+ },
73
70
  },
74
- });
75
- }
71
+ },
72
+ };
76
73
  }
@@ -5,7 +5,7 @@ import { Type } from "typebox";
5
5
  import { Value } from "typebox/value";
6
6
 
7
7
  /** Whole-file operations, distinct from text-selection copy/move/remove. */
8
- export const fileOperations = ["delete_file", "move_file", "copy_file"] as const;
8
+ export const fileOperations = ["delete", "move", "copy"] as const;
9
9
  export type FileOperation = (typeof fileOperations)[number];
10
10
  const filePath = Type.String({
11
11
  minLength: 1,
@@ -71,7 +71,7 @@ export async function executeFileOperation(
71
71
  let source: string | undefined;
72
72
  let target: string | undefined;
73
73
  try {
74
- const schema = operation === "delete_file" ? deleteFileParameters : transferFileParameters;
74
+ const schema = operation === "delete" ? deleteFileParameters : transferFileParameters;
75
75
  if (!Value.Check(schema, input))
76
76
  throw Object.assign(new Error("Invalid file operation arguments"), {
77
77
  code: "INVALID_ARGUMENTS",
@@ -103,9 +103,9 @@ export async function executeFileOperation(
103
103
  }
104
104
  signal?.throwIfAborted();
105
105
  started = true;
106
- if (operation === "delete_file") await unlink(source);
106
+ if (operation === "delete") await unlink(source);
107
107
  else if (target !== undefined) {
108
- if (operation === "copy_file")
108
+ if (operation === "copy")
109
109
  await fs.copy(source, target, { overwrite: args.overwrite === true, errorOnExist: true });
110
110
  else await fs.move(source, target, { overwrite: args.overwrite === true });
111
111
  }
@@ -222,6 +222,16 @@ export async function executeRegisteredTextBatch(
222
222
  const mutations: PlannedTextBatch["mutations"][number][] = [];
223
223
  const failures: PlannedTextBatch["failures"][number][] = [];
224
224
  const changes = new Map<string, TextChange[]>();
225
+ if (parameters.expectedContent !== undefined) {
226
+ for (const [source, expected] of parameters.expectedContent) {
227
+ if (!texts.has(source)) {
228
+ throw new Error(`Snapshot source ${source} is not part of this edit batch.`);
229
+ }
230
+ if (texts.get(source) !== expected) {
231
+ throw new Error(`Snapshot source ${source} changed before the edit batch.`);
232
+ }
233
+ }
234
+ }
225
235
 
226
236
  for (const item of prepared) {
227
237
  const sourceFor = (field: string): string => {
@@ -336,6 +346,7 @@ export async function executeRegisteredTextBatch(
336
346
  changes.set(source, [...(changes.get(source) ?? []), ...edit.changes]);
337
347
  }
338
348
  } catch (error) {
349
+ if (parameters.failureMode === "abort") throw error;
339
350
  failures.push({
340
351
  callId: item.callId,
341
352
  source: item.sources.get(item.registration.source.field) ?? "",
@@ -8,6 +8,10 @@ import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
8
8
 
9
9
  export interface TextBatchParams {
10
10
  readonly edits: readonly TextBatchEntry[];
11
+ /** Optional whole-file revisions that every affected source must still match. */
12
+ readonly expectedContent?: ReadonlyMap<string, string>;
13
+ /** Abort the complete plan when any entry is invalid instead of applying valid peers. */
14
+ readonly failureMode?: "continue" | "abort";
11
15
  }
12
16
 
13
17
  export interface TextBatchEntry extends Record<string, unknown> {