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
@@ -1,2 +1 @@
1
1
  export * from "../../../../../../dist/entry-53.js";
2
- export { default } from "../../../../../../dist/entry-53.js";
@@ -0,0 +1,2 @@
1
+ export * from "../../../../../../dist/entry-54.js";
2
+ export { default } from "../../../../../../dist/entry-54.js";
@@ -72,6 +72,11 @@ export default async function registerTextEditorRenderer(pi: ExtensionAPI): Prom
72
72
  .map(([key, value]) => `${key}: ${display(value)}`)
73
73
  .join(" · ");
74
74
  const suffix = parameters ? ` ${theme.fg("dim", parameters)}` : "";
75
+ if (call.name === "result")
76
+ return `${theme.fg("toolTitle", theme.bold("result"))} ${theme.fg(
77
+ "accent",
78
+ call.arguments.arguments ? display(call.arguments.arguments) : parameters,
79
+ )}`;
75
80
  if (registration)
76
81
  return (
77
82
  renderWrittenMutationHeader(
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor-renderer",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "#src/*": "./src/*"
7
7
  },
8
8
  "dependencies": {
9
9
  "diff": "^9.0.0",
10
- "pi-agent-invariant": "0.4.0",
11
- "pi-agent-text-editor": "0.4.0",
12
- "pi-agent-tool-call-interception": "0.4.0",
13
- "pi-agent-tool-ui": "0.4.0"
10
+ "pi-agent-invariant": "0.5.0",
11
+ "pi-agent-text-editor": "0.5.0",
12
+ "pi-agent-tool-call-interception": "0.5.0",
13
+ "pi-agent-tool-ui": "0.5.0"
14
14
  },
15
15
  "pi": {
16
16
  "extensions": [
17
- "./runtime/entry-71.js"
17
+ "./runtime/entry-72.js"
18
18
  ]
19
19
  },
20
20
  "peerDependencies": {
@@ -256,6 +256,33 @@ function createRenderer(
256
256
  );
257
257
  state.panel?.setPreviewResources([]);
258
258
 
259
+ if (registration.name === "undo" && typeof state.input?.transaction === "string") {
260
+ const restored = restoredApplyPathCount(result.details);
261
+ const succeeded = restored !== undefined && !context.isError;
262
+ return new Text(
263
+ theme.fg(
264
+ succeeded ? "success" : "error",
265
+ succeeded
266
+ ? `✓ Undo applied · ${String(restored)} ${restored === 1 ? "file" : "files"}`
267
+ : "✗ Undo not applied",
268
+ ),
269
+ 0,
270
+ 0,
271
+ );
272
+ }
273
+
274
+ const wholeFileSucceeded = wholeFileOperationSucceeded(result.details);
275
+ if (wholeFileSucceeded !== undefined) {
276
+ return new Text(
277
+ theme.fg(
278
+ wholeFileSucceeded ? "success" : "error",
279
+ wholeFileSucceeded ? "✓ Applied" : "✗ Not applied",
280
+ ),
281
+ 0,
282
+ 0,
283
+ );
284
+ }
285
+
259
286
  const output = result.content
260
287
  .filter(
261
288
  (item): item is { readonly type: "text"; readonly text: string } => item.type === "text",
@@ -718,6 +745,8 @@ function renderHeader(
718
745
  expanded: boolean,
719
746
  ): string {
720
747
  const source = registration.source;
748
+ if (registration.name === "undo" && typeof input.transaction === "string")
749
+ return `${theme.fg("toolTitle", theme.bold("undo"))} ${theme.fg("muted", "· Apply transaction")}`;
721
750
  const path = stringValue(input[source.field]);
722
751
  const previewResources = preview?.kind === "completed" ? preview.resources : [];
723
752
  const displayedPath =
@@ -830,6 +859,36 @@ function semanticRange(start: string, end: string): string {
830
859
  : `${start}–${end}`;
831
860
  }
832
861
 
862
+ function restoredApplyPathCount(details: unknown): number | undefined {
863
+ if (details === null || typeof details !== "object" || !("metadata" in details)) return undefined;
864
+ const metadata = details.metadata;
865
+ if (metadata === null || typeof metadata !== "object" || !("semanticAction" in metadata))
866
+ return undefined;
867
+ const action = metadata.semanticAction;
868
+ if (
869
+ action === null ||
870
+ typeof action !== "object" ||
871
+ !("kind" in action) ||
872
+ action.kind !== "apply-undo" ||
873
+ !("restored" in action) ||
874
+ !Array.isArray(action.restored)
875
+ )
876
+ return undefined;
877
+ return action.restored.length;
878
+ }
879
+
880
+ function wholeFileOperationSucceeded(details: unknown): boolean | undefined {
881
+ if (details === null || typeof details !== "object" || !("metadata" in details)) return undefined;
882
+ const metadata = details.metadata;
883
+ if (metadata === null || typeof metadata !== "object" || !("semanticAction" in metadata))
884
+ return undefined;
885
+ const action = metadata.semanticAction;
886
+ if (action === null || typeof action !== "object" || !("kind" in action)) return undefined;
887
+ return action.kind === "file-operation" && "ok" in action && typeof action.ok === "boolean"
888
+ ? action.ok
889
+ : undefined;
890
+ }
891
+
833
892
  function userFacingFailure(agentOutput: string): string {
834
893
  if (/\banchor\b[\s\S]*\bis ambiguous\./iu.test(agentOutput)) {
835
894
  return "Not changed · selection is ambiguous";
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "pi-agent-text-editor-stale-anchor",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
- "pi-agent-invariant": "0.4.0",
7
- "pi-agent-read": "0.4.0",
8
- "pi-agent-text-editor": "0.4.0"
6
+ "pi-agent-invariant": "0.5.0",
7
+ "pi-agent-read": "0.5.0",
8
+ "pi-agent-text-editor": "0.5.0"
9
9
  },
10
10
  "pi": {
11
11
  "extensions": [
12
- "./runtime/entry-72.js"
12
+ "./runtime/entry-73.js"
13
13
  ]
14
14
  },
15
15
  "peerDependencies": {
@@ -0,0 +1,2 @@
1
+ export * from "../../../../../../dist/entry-73.js";
2
+ export { default } from "../../../../../../dist/entry-73.js";
@@ -1,2 +1 @@
1
1
  export * from "../../../../dist/entry-70.js";
2
- export { default } from "../../../../dist/entry-70.js";
@@ -0,0 +1,2 @@
1
+ export * from "../../../../dist/entry-71.js";
2
+ export { default } from "../../../../dist/entry-71.js";
@@ -15,4 +15,10 @@ export interface TextEditCompletion {
15
15
  readonly intent: TextEditIntent;
16
16
  }
17
17
 
18
- export type TextEditCompletionListener = (completion: TextEditCompletion) => void | Promise<void>;
18
+ export interface TextEditCompletionFeedback {
19
+ readonly feedback: string;
20
+ readonly tone?: "info" | "warning" | "error";
21
+ }
22
+ export type TextEditCompletionListener = (
23
+ completion: TextEditCompletion,
24
+ ) => void | TextEditCompletionFeedback | Promise<void | TextEditCompletionFeedback>;
@@ -2,6 +2,7 @@ import { Type } from "typebox";
2
2
  import { Value } from "typebox/value";
3
3
 
4
4
  import type { TextEditorToolId } from "#src/api/plugin-protocol.js";
5
+ import type { TextSemanticMutationHandler } from "#src/api/mutation-tool.js";
5
6
 
6
7
  export type TextEditPipelineStage = "text-pre-edit" | "text-edit" | "text-post-edit";
7
8
 
@@ -43,6 +44,8 @@ export type TextEditHandlerRegistration =
43
44
  | { readonly stage: "text-post-edit"; readonly handler: TextEditHandler };
44
45
 
45
46
  export interface TextEditorToolPluginApi {
47
+ /** Handle selected invocations as anchored non-file effects before document writes. */
48
+ addSemanticHandler(handler: TextSemanticMutationHandler): void;
46
49
  addHandler(registration: TextEditHandlerRegistration): void;
47
50
  describe(description: string): void;
48
51
  }
@@ -1,5 +1,6 @@
1
1
  import type { TextEditIntent } from "#src/api/edit-completion.js";
2
2
  import type { AppliedTextChange } from "#src/core/text-change-engine.js";
3
+ export type { AppliedTextChange } from "#src/core/text-change-engine.js";
3
4
  import type { TextDocument } from "pi-agent-text";
4
5
 
5
6
  export interface TextMutationPlanResource {
@@ -9,6 +9,8 @@ export interface TextMutationEdit {
9
9
  }
10
10
 
11
11
  export interface TextMutation {
12
+ /** Non-file action completed through this mutation invocation. */
13
+ readonly semanticAction?: TextSemanticMutationResult;
12
14
  readonly edits: ReadonlyMap<string, TextMutationEdit>;
13
15
  readonly afterWrite?: () => void | Promise<void>;
14
16
  }
@@ -56,6 +58,40 @@ export function isMutationAnchorValue(
56
58
  );
57
59
  }
58
60
 
61
+ /** A non-file effect performed through an existing text mutation tool. */
62
+ export interface TextSemanticMutationResult {
63
+ /** Addressable resource created or changed by the action. */
64
+ readonly source: string;
65
+ /** Compact agent-facing outcome. */
66
+ readonly summary: string;
67
+ /** Structured receipt shared by standalone tools and Apply. */
68
+ readonly data: Readonly<Record<string, unknown>>;
69
+ }
70
+
71
+ /** Handles one tool invocation after its current source and anchors are available. */
72
+ export interface TextSemanticMutationHandler {
73
+ /** Select invocations owned by this handler without performing side effects. */
74
+ readonly matches: (input: unknown) => boolean;
75
+ /** Perform the non-file effect against the fresh source snapshot. */
76
+ readonly execute: (
77
+ context: TextMutationContext,
78
+ input: unknown,
79
+ ) => TextSemanticMutationResult | Promise<TextSemanticMutationResult>;
80
+ }
81
+ export interface DirectTextMutationContext {
82
+ readonly cwd: string;
83
+ readonly signal?: AbortSignal;
84
+ }
85
+
86
+ /** A mutation mode that owns its complete multi-resource transaction. */
87
+ export interface DirectTextMutationHandler {
88
+ readonly matches: (input: unknown) => boolean;
89
+ readonly execute: (
90
+ context: DirectTextMutationContext,
91
+ input: unknown,
92
+ ) => TextSemanticMutationResult | Promise<TextSemanticMutationResult>;
93
+ }
94
+
59
95
  export type TextMutationIntent = Exclude<TextEditIntent, "mixed">;
60
96
 
61
97
  export interface TextMutationToolRegistration<TParameters extends TSchema = TSchema> {
@@ -71,6 +107,10 @@ export interface TextMutationToolRegistration<TParameters extends TSchema = TSch
71
107
  readonly source: TextMutationSourceDescriptor;
72
108
  readonly anchors?: readonly TextMutationAnchorField[];
73
109
  readonly pair?: readonly [string, string];
110
+ /** Execute a host transaction without opening one primary text resource. */
111
+ readonly direct?: DirectTextMutationHandler;
112
+ /** Whole-file operation used when the invocation contains no text selectors. */
113
+ readonly wholeFileOperation?: "copy" | "move" | "delete";
74
114
  readonly mutate: (
75
115
  context: TextMutationContext,
76
116
  parameters: Static<TParameters>,
@@ -90,6 +130,13 @@ export function assertTextMutationToolRegistration(value: AnyTextMutationToolReg
90
130
  throw new TypeError(`Mutation tool ${value.name} has an invalid description or operation`);
91
131
  }
92
132
 
133
+ if (
134
+ value.direct !== undefined &&
135
+ (typeof value.direct.matches !== "function" || typeof value.direct.execute !== "function")
136
+ ) {
137
+ throw new TypeError(`Mutation tool ${value.name} has an invalid direct operation`);
138
+ }
139
+
93
140
  const intent: unknown = (value as { readonly intent?: unknown }).intent;
94
141
 
95
142
  if (intent !== undefined && intent !== "edit" && intent !== "restore") {
@@ -40,7 +40,7 @@ export interface ScriptIndexOperation {
40
40
  }
41
41
  export const TEXT_EDITOR_PROTOCOL = "pi-agent-text-editor";
42
42
 
43
- export const TEXT_EDITOR_API_VERSION = 21;
43
+ export const TEXT_EDITOR_API_VERSION = 22;
44
44
 
45
45
  export const TEXT_POSITION_ANCHOR_KIND = "pi-agent-text-editor/position";
46
46
 
@@ -92,6 +92,11 @@ export interface TextEditorRecoveryConfigSection {
92
92
  readonly settings: unknown;
93
93
  }
94
94
  export interface TextEditorPluginApi {
95
+ /** Restore a session-scoped Apply transaction receipt atomically. */
96
+ restoreApplyUndo(
97
+ transaction: string,
98
+ signal?: AbortSignal,
99
+ ): Promise<{ readonly transaction: string; readonly restored: readonly string[] }>;
95
100
  addResolver(registration: ResourceResolverRegistration): void;
96
101
  inspectTextAnchors(request: TextAnchorInspectionRequest): Promise<TextAnchorInspectionOutcome>;
97
102
  addAnchorResolver(registration: TextAnchorResolverRegistration): void;
@@ -0,0 +1,155 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+
5
+ export interface ApplyUndoBeforeState {
6
+ readonly path: string;
7
+ readonly existed: boolean;
8
+ readonly bytes?: Uint8Array;
9
+ }
10
+
11
+ interface ApplyUndoPathState extends ApplyUndoBeforeState {
12
+ after: string;
13
+ }
14
+
15
+ interface ApplyUndoReceipt {
16
+ readonly paths: readonly ApplyUndoPathState[];
17
+ }
18
+
19
+ export interface ApplyUndoResult {
20
+ readonly transaction: string;
21
+ readonly restored: readonly string[];
22
+ }
23
+
24
+ /** Session-local, single-use receipts for atomic Apply rollback. */
25
+ export class ApplyUndoStore {
26
+ readonly #receipts = new Map<string, ApplyUndoReceipt>();
27
+ readonly #restoreState: (state: ApplyUndoBeforeState) => Promise<void>;
28
+
29
+ public constructor(restore = restoreState) {
30
+ this.#restoreState = restore;
31
+ }
32
+
33
+ public async record(before: readonly ApplyUndoBeforeState[]): Promise<string> {
34
+ const touched = new Set(before.map((state) => path.normalize(state.path)));
35
+ this.invalidate(touched);
36
+ const paths = await Promise.all(
37
+ before.map(async (state) => ({ ...state, after: await fingerprint(state.path) })),
38
+ );
39
+ const transaction = `APPLY#${randomBytes(6).toString("hex").toUpperCase()}`;
40
+ this.#receipts.set(transaction, { paths });
41
+ return transaction;
42
+ }
43
+
44
+ public observeTextChange(
45
+ file: string,
46
+ before: string,
47
+ after: string,
48
+ postProcessing: "deferred" | "complete" | "final",
49
+ ): void {
50
+ const normalized = path.normalize(file);
51
+ if (postProcessing === "final") {
52
+ const beforeFingerprint = textFingerprint(before);
53
+ for (const receipt of this.#receipts.values()) {
54
+ const state = receipt.paths.find(
55
+ (candidate) => path.normalize(candidate.path) === normalized,
56
+ );
57
+ if (state?.after === beforeFingerprint) state.after = textFingerprint(after);
58
+ }
59
+ return;
60
+ }
61
+ this.invalidate(new Set([normalized]));
62
+ }
63
+
64
+ public invalidate(paths: ReadonlySet<string>): void {
65
+ for (const [transaction, receipt] of this.#receipts) {
66
+ if (receipt.paths.some((state) => paths.has(path.normalize(state.path))))
67
+ this.#receipts.delete(transaction);
68
+ }
69
+ }
70
+
71
+ public has(transaction: string): boolean {
72
+ return this.#receipts.has(transaction);
73
+ }
74
+
75
+ public async restore(transaction: string): Promise<ApplyUndoResult> {
76
+ const receipt = this.#receipts.get(transaction);
77
+ if (receipt === undefined)
78
+ throw coded("APPLY_UNDO_UNAVAILABLE", `No undo receipt is available for ${transaction}.`);
79
+
80
+ for (const state of receipt.paths) {
81
+ if ((await fingerprint(state.path)) !== state.after) {
82
+ this.#receipts.delete(transaction);
83
+ throw coded(
84
+ "APPLY_UNDO_STALE",
85
+ `${state.path} changed after ${transaction}; refusing to overwrite newer content.`,
86
+ );
87
+ }
88
+ }
89
+
90
+ const current = await Promise.all(receipt.paths.map((state) => save(state.path)));
91
+ try {
92
+ for (const state of receipt.paths) await this.#restoreState(state);
93
+ } catch (error) {
94
+ const rollbackErrors: string[] = [];
95
+ for (const state of current) {
96
+ try {
97
+ await this.#restoreState(state);
98
+ } catch (rollbackError) {
99
+ rollbackErrors.push(
100
+ `${state.path}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,
101
+ );
102
+ }
103
+ }
104
+ throw Object.assign(
105
+ coded("APPLY_UNDO_FAILED", error instanceof Error ? error.message : String(error)),
106
+ { rollbackErrors },
107
+ );
108
+ }
109
+
110
+ this.#receipts.delete(transaction);
111
+ return { transaction, restored: receipt.paths.map((state) => state.path) };
112
+ }
113
+ }
114
+
115
+ async function save(file: string): Promise<ApplyUndoBeforeState> {
116
+ try {
117
+ const stat = await lstat(file);
118
+ if (!stat.isFile() || stat.isSymbolicLink())
119
+ throw coded("INVALID_FILE_TYPE", `${file} is not a regular file.`);
120
+ return { path: file, existed: true, bytes: await readFile(file) };
121
+ } catch (error) {
122
+ if (hasCode(error, "ENOENT")) return { path: file, existed: false };
123
+ throw error;
124
+ }
125
+ }
126
+
127
+ function textFingerprint(content: string): string {
128
+ return `file:${createHash("sha256").update(content).digest("hex")}`;
129
+ }
130
+
131
+ async function fingerprint(file: string): Promise<string> {
132
+ const state = await save(file);
133
+ return state.existed
134
+ ? `file:${createHash("sha256")
135
+ .update(state.bytes ?? new Uint8Array())
136
+ .digest("hex")}`
137
+ : "absent";
138
+ }
139
+
140
+ async function restoreState(state: ApplyUndoBeforeState): Promise<void> {
141
+ if (!state.existed) {
142
+ await rm(state.path, { force: true });
143
+ return;
144
+ }
145
+ await mkdir(path.dirname(state.path), { recursive: true });
146
+ await writeFile(state.path, state.bytes ?? new Uint8Array());
147
+ }
148
+
149
+ function coded(code: string, message: string): Error {
150
+ return Object.assign(new Error(message), { code });
151
+ }
152
+
153
+ function hasCode(error: unknown, code: string): boolean {
154
+ return error !== null && typeof error === "object" && "code" in error && error.code === code;
155
+ }
@@ -8,14 +8,9 @@ import { readParameters, type ReadToolResult } from "pi-agent-read/api/tools/rea
8
8
  import { searchSchema, type SearchPluginApi, type SearchRequest } from "pi-agent-search/api/search";
9
9
  import { Value } from "typebox/value";
10
10
  import type { TextEditorCore } from "#src/core/text-editor-core.js";
11
- import { executeScriptMutation } from "#src/core/text-mutation.js";
12
11
  import { ApplyResults } from "#src/core/apply/results.js";
13
- import {
14
- executeFileOperation,
15
- fileOperations,
16
- type FileOperation,
17
- } from "#src/core/file-operations.js";
18
12
  import { serializeApplyError, type ApplyRuntimeHost } from "#src/core/apply/runtime.js";
13
+ import { executeEditorTransaction } from "#src/core/apply/transaction.js";
19
14
 
20
15
  /** Configured IDE services and ordinary tool schemas, shared with the standalone tools. */
21
16
  export interface ApplyServices {
@@ -40,87 +35,71 @@ export function createApplyExecution(
40
35
  let lastSource = services.lastResolvedSource;
41
36
  const host: ApplyRuntimeHost = {
42
37
  async execute(operation, arguments_, signal, id) {
43
- const tool = operation === "remove" ? "delete" : operation;
44
- const kind = tool === "read" || tool === "search" || tool === "diff" ? "read" : "mutation";
38
+ const tool = operation;
39
+ const kind =
40
+ tool === "read" || tool === "search" || tool === "diff" || tool === "editorOpen"
41
+ ? "read"
42
+ : "mutation";
45
43
  let recorded = false;
46
44
  try {
47
- if (tool === "stage" || tool === "unstage") {
48
- const operation = services.editor.getScriptIndexOperation(tool);
49
- if (!operation)
50
- throw failure("OPERATION_UNAVAILABLE", `${tool} requires the Git changes module`);
51
- if (!Value.Check(operation.parameters, arguments_))
52
- throw failure("INVALID_ARGUMENTS", `Invalid ${tool} arguments`);
53
- const outcome = await operation.execute(arguments_, signal, context);
54
- const value = {
55
- operation: tool,
56
- ok: true,
57
- effect: "index-only",
58
- kind: "index-operation",
59
- ...(outcome.details as object),
60
- };
61
- results.record(id, "mutation", value, { content: outcome.content, details: {} });
62
- recorded = true;
63
- return value;
64
- }
65
- if (tool === "diff") {
66
- const value = await executeDiff(services.read, arguments_, { cwd: context.cwd, signal });
67
- results.record(id, "read", value, diffReadResult(value));
68
- return value;
69
- }
70
- if ((fileOperations as readonly string[]).includes(operation)) {
71
- const value = await services.editor.enqueueFileOperation(
72
- () => executeFileOperation(operation as FileOperation, arguments_, context.cwd, signal),
73
- signal,
74
- );
45
+ if (tool === "editorApply") {
46
+ let value;
47
+ try {
48
+ value = await executeEditorTransaction(services.editor, arguments_, signal, context);
49
+ } catch (error) {
50
+ const details =
51
+ error !== null && typeof error === "object" && "details" in error
52
+ ? error.details
53
+ : undefined;
54
+ if (
55
+ details !== null &&
56
+ typeof details === "object" &&
57
+ "files" in details &&
58
+ Array.isArray(details.files)
59
+ )
60
+ for (const source of details.files)
61
+ if (typeof source === "string") scope.forget(source);
62
+ throw error;
63
+ }
75
64
  results.record(id, "mutation", value);
76
65
  recorded = true;
77
- if (value.effect !== "not-applied") {
78
- if (value.path !== undefined && operation !== "copy_file") {
79
- results.forgetFile(value.path);
80
- scope.forget(value.path);
81
- }
82
- if (value.target !== undefined) {
83
- results.forgetFile(value.target);
84
- scope.forget(value.target);
85
- }
66
+ for (const file of value.files) {
67
+ results.updateFile(file.source, file.before, file.after);
68
+ lastSource = file.source;
86
69
  }
87
- if (value.ok && value.target !== undefined)
88
- await services.editor.postProcessFile(value.target, { cwd: context.cwd, signal });
89
- if (!value.ok)
90
- throw failure(
91
- value.error?.code ?? "FILE_OPERATION_FAILED",
92
- value.error?.message ?? "File operation failed",
93
- value,
94
- );
95
70
  return value;
96
71
  }
97
- if (kind === "mutation") {
98
- const definition = services.editor
99
- .getMutationTools()
100
- .find((candidate) => candidate.name === tool);
101
- if (definition === undefined)
102
- throw failure("UNAVAILABLE_OPERATION", `IDE operation ${tool} is unavailable`);
103
- const value = await executeScriptMutation(
104
- services.editor,
105
- definition,
72
+ if (tool === "editorOpen") {
73
+ if (!Value.Check(readParameters, arguments_))
74
+ throw failure("INVALID_ARGUMENTS", "Invalid arguments for open");
75
+ const outcome = await services.read.read(
106
76
  arguments_,
107
- signal,
108
- context,
109
- lastSource,
110
- (source, presentation) => results.rememberMutation(source, presentation),
77
+ { cwd: context.cwd, signal },
78
+ "script",
111
79
  );
112
- results.record(id, kind, value);
80
+ const value = outcome.script;
81
+ if (
82
+ outcome.isError ||
83
+ outcome.details.resolvedBy !== "filesystem" ||
84
+ value?.kind !== "text" ||
85
+ typeof value.content !== "string"
86
+ )
87
+ throw failure("NOT_EDITABLE_TEXT", "open() requires one local text file");
88
+ const snapshot = {
89
+ id,
90
+ source: outcome.details.source ?? value.source,
91
+ content: value.content,
92
+ lines: value.lines,
93
+ };
94
+ results.record(id, "read", snapshot, outcome);
113
95
  recorded = true;
114
- for (const file of value.files) {
115
- results.updateFile(file.source, file.before, file.after);
116
- lastSource = file.source;
117
- }
118
- if (!value.ok)
119
- throw failure(
120
- value.errors[0]?.code ?? "OPERATION_FAILED",
121
- value.errors[0]?.message ?? "Mutation failed",
122
- value,
123
- );
96
+ lastSource = snapshot.source;
97
+ services.rememberRead?.(outcome);
98
+ return snapshot;
99
+ }
100
+ if (tool === "diff") {
101
+ const value = await executeDiff(services.read, arguments_, { cwd: context.cwd, signal });
102
+ results.record(id, "read", value, diffReadResult(value));
124
103
  return value;
125
104
  }
126
105
  const schema = tool === "read" ? readParameters : searchSchema;
@@ -5,18 +5,13 @@ const helpers = new Set([
5
5
  "read",
6
6
  "search",
7
7
  "diff",
8
- "write",
9
- "replace",
10
- "insert",
11
- "remove",
12
- "copy",
13
- "move",
14
- "undo",
15
- "stage",
16
- "unstage",
17
- "delete_file",
18
- "copy_file",
19
- "move_file",
8
+ "open",
9
+ "createFile",
10
+ "deleteFile",
11
+ "copyFile",
12
+ "moveFile",
13
+ "apply",
14
+ "result",
20
15
  ]);
21
16
 
22
17
  /** Bounded source expression; literal does not imply the operation has executed. */
@@ -28,6 +28,8 @@ export interface ScriptMutationOutcome {
28
28
  readonly effect: "not-applied" | "applied" | "unknown";
29
29
  readonly files: readonly ScriptMutationFile[];
30
30
  readonly completed: readonly string[];
31
+ /** Session-scoped receipt accepted by undo. */
32
+ readonly transaction?: string;
31
33
  readonly recoveries?: readonly ScriptAnchorRecovery[];
32
34
  /** Structured contributions from configured IDE mutation handlers. */
33
35
  readonly metadata?: Readonly<Record<string, unknown>>;