pi-agent-ide 0.6.3 → 0.6.4

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 (355) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +8 -1
  3. package/dist/chunk-2P2OGO3G.js +2 -0
  4. package/dist/{chunk-5QQABP47.js → chunk-3BBJZSMS.js} +1 -1
  5. package/dist/chunk-5J43L2RL.js +11 -0
  6. package/dist/{chunk-ITSNK5YG.js → chunk-7AVXUV4A.js} +2 -2
  7. package/dist/chunk-BAYETTZZ.js +16 -0
  8. package/dist/{chunk-VCTK4JSN.js → chunk-BSICWXMH.js} +1 -1
  9. package/dist/chunk-BVK5A7ED.js +28 -0
  10. package/dist/{chunk-ZM4L5AGN.js → chunk-EDURPQAV.js} +3 -2
  11. package/dist/{chunk-L7JMDDSD.js → chunk-FBOW7XOV.js} +1 -1
  12. package/dist/{chunk-25CZ5ZIU.js → chunk-FUG2TEKI.js} +1 -1
  13. package/dist/chunk-FZBCKIJJ.js +1 -0
  14. package/dist/chunk-HPUAIWIH.js +25 -0
  15. package/dist/chunk-I5JLCFUX.js +1 -0
  16. package/dist/chunk-KUPHNMUK.js +2 -0
  17. package/dist/{chunk-NTYXZ3EL.js → chunk-KVHDMIZS.js} +1 -1
  18. package/dist/{chunk-QDST6VIU.js → chunk-KZC7TI5M.js} +1 -1
  19. package/dist/chunk-MIZAFRDR.js +1 -0
  20. package/dist/chunk-PJPA5EEE.js +2 -0
  21. package/dist/{chunk-GUTQ3PWL.js → chunk-PLKYHUNT.js} +1 -1
  22. package/dist/chunk-QEJGED4V.js +28 -0
  23. package/dist/chunk-SILJ3OL4.js +9 -0
  24. package/dist/{chunk-VXD6FZP5.js → chunk-TQZBVOTT.js} +3 -3
  25. package/dist/chunk-VBICI5YA.js +1 -0
  26. package/dist/chunk-VWW3RLUX.js +12 -0
  27. package/dist/{chunk-O6LE42GK.js → chunk-WJTHY6AG.js} +1 -1
  28. package/dist/chunk-YGGKGZO2.js +1 -0
  29. package/dist/chunk-ZODCBFBL.js +2 -0
  30. package/dist/chunk-ZPT5D4VP.js +2 -0
  31. package/dist/entry-0.js +1 -1
  32. package/dist/entry-11.js +1 -1
  33. package/dist/entry-13.js +1 -1
  34. package/dist/entry-14.js +1 -1
  35. package/dist/entry-15.js +1 -1
  36. package/dist/entry-16.js +1 -1
  37. package/dist/entry-17.js +1 -1
  38. package/dist/entry-25.js +2 -2
  39. package/dist/entry-26.js +1 -1
  40. package/dist/entry-27.js +1 -1
  41. package/dist/entry-28.js +1 -1
  42. package/dist/entry-29.js +1 -1
  43. package/dist/entry-30.js +1 -1
  44. package/dist/entry-31.js +11 -11
  45. package/dist/entry-33.js +1 -1
  46. package/dist/entry-37.js +2 -2
  47. package/dist/entry-42.js +1 -1
  48. package/dist/entry-44.js +1 -1
  49. package/dist/entry-45.js +13 -12
  50. package/dist/entry-46.js +1 -1
  51. package/dist/entry-49.js +1 -1
  52. package/dist/entry-50.js +4 -4
  53. package/dist/entry-51.js +9 -9
  54. package/dist/entry-52.js +1 -1
  55. package/dist/entry-53.js +1 -1
  56. package/dist/entry-55.js +1 -1
  57. package/dist/entry-56.js +1 -1
  58. package/dist/entry-57.js +1 -1
  59. package/dist/entry-58.js +1 -1
  60. package/dist/entry-59.js +1 -1
  61. package/dist/entry-60.js +1 -1
  62. package/dist/entry-61.js +1 -1
  63. package/dist/entry-63.js +1 -1
  64. package/dist/entry-66.js +1 -1
  65. package/dist/entry-68.js +1 -1
  66. package/dist/entry-69.js +1 -1
  67. package/dist/entry-70.js +1 -1
  68. package/dist/entry-71.js +1 -0
  69. package/dist/entry-72.js +0 -1
  70. package/dist/entry-73.js +1 -0
  71. package/dist/entry-74.js +0 -1
  72. package/dist/entry-75.js +1 -1
  73. package/dist/entry-76.js +1 -1
  74. package/dist/entry-77.js +1 -324
  75. package/dist/entry-78.js +324 -25
  76. package/dist/entry-79.js +18 -2
  77. package/dist/entry-80.js +2 -1
  78. package/dist/entry-81.js +1 -1
  79. package/dist/entry-82.js +1 -3
  80. package/dist/entry-83.js +5 -3
  81. package/dist/entry-84.js +3 -1
  82. package/dist/entry-85.js +1 -1
  83. package/dist/entry-86.js +1 -1
  84. package/dist/entry-87.js +1 -0
  85. package/dist/pi-agent-ide.js +15 -3
  86. package/docs/agent-guides/editing.md +12 -0
  87. package/docs/agent-guides/json-reading.md +19 -3
  88. package/docs/agent-guides/read-resources.md +6 -0
  89. package/docs/agent-guides/search-code.md +5 -1
  90. package/docs/agent-guides/terminal.md +1 -1
  91. package/docs/code-review.md +99 -0
  92. package/docs/configuration.md +34 -0
  93. package/docs/development.md +15 -19
  94. package/docs/nightly.md +7 -0
  95. package/docs/releases.md +42 -0
  96. package/docs/research/native-codemode-batch-decision.md +27 -0
  97. package/docs/research/native-codemode-batching.md +65 -0
  98. package/docs/structured-results.md +59 -0
  99. package/docs/tools.md +18 -2
  100. package/node_modules/pi-agent-doctor/package.json +1 -1
  101. package/node_modules/pi-agent-documentation/package.json +1 -1
  102. package/node_modules/pi-agent-documentation/src/index.ts +1 -1
  103. package/node_modules/pi-agent-filesystem/index.ts +6 -1
  104. package/node_modules/pi-agent-filesystem/package.json +7 -6
  105. package/node_modules/pi-agent-filesystem/src/path-recovery.ts +109 -0
  106. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  107. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  108. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  109. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  110. package/node_modules/pi-agent-ide-ast/package.json +10 -10
  111. package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
  112. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +6 -2
  113. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +17 -0
  114. package/node_modules/pi-agent-ide-changes/index.ts +3 -9
  115. package/node_modules/pi-agent-ide-changes/package.json +8 -7
  116. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
  117. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +125 -47
  118. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  119. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  120. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  121. package/node_modules/pi-agent-ide-lsp/package.json +9 -9
  122. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +19 -0
  123. package/node_modules/pi-agent-image/package.json +2 -2
  124. package/node_modules/pi-agent-invariant/package.json +1 -1
  125. package/node_modules/pi-agent-pdf/package.json +2 -2
  126. package/node_modules/pi-agent-read/package.json +7 -7
  127. package/node_modules/pi-agent-read/src/api/tools/read.ts +31 -2
  128. package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
  129. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
  130. package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +216 -0
  131. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +119 -72
  132. package/node_modules/pi-agent-resource/package.json +1 -1
  133. package/node_modules/pi-agent-resource/src/index.ts +12 -0
  134. package/node_modules/pi-agent-resource/src/resource-access.ts +55 -0
  135. package/node_modules/pi-agent-resource/src/resource-scheduler.ts +204 -0
  136. package/node_modules/pi-agent-resource/src/tool-result.ts +125 -0
  137. package/node_modules/pi-agent-search/package.json +5 -4
  138. package/node_modules/pi-agent-search/src/api/search-parameters.ts +6 -5
  139. package/node_modules/pi-agent-search/src/api/search.ts +11 -0
  140. package/node_modules/pi-agent-search/src/api/structured-result.ts +93 -0
  141. package/node_modules/pi-agent-search/src/core/extension.ts +40 -14
  142. package/node_modules/pi-agent-search/src/core/search-core.ts +136 -77
  143. package/node_modules/pi-agent-search-text/index.ts +3 -0
  144. package/node_modules/pi-agent-search-text/package.json +6 -6
  145. package/node_modules/pi-agent-search-text/src/resolvers.ts +17 -0
  146. package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -8
  147. package/node_modules/pi-agent-search-text/src/search-query.ts +42 -34
  148. package/node_modules/pi-agent-search-text/src/search-recipe.ts +18 -4
  149. package/node_modules/pi-agent-search-text/src/search-renderer.ts +37 -3
  150. package/node_modules/pi-agent-search-text/src/search-session.ts +21 -13
  151. package/node_modules/pi-agent-text/package.json +2 -2
  152. package/node_modules/pi-agent-text/src/text-document.ts +15 -10
  153. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  154. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  155. package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +4 -3
  156. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  157. package/node_modules/pi-agent-text-editor/index.ts +4 -2
  158. package/node_modules/pi-agent-text-editor/package.json +21 -17
  159. package/node_modules/pi-agent-text-editor/runtime/entry-77.js +0 -1
  160. package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
  161. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
  162. package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
  163. package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +4 -0
  164. package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +95 -34
  165. package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +4 -0
  166. package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +251 -0
  167. package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +32 -12
  168. package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +154 -132
  169. package/node_modules/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
  170. package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +74 -18
  171. package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
  172. package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +6 -0
  173. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
  174. package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +640 -0
  175. package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
  176. package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +314 -0
  177. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +143 -138
  178. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
  179. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +242 -116
  180. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +109 -47
  181. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
  182. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
  183. package/node_modules/pi-agent-text-editor-renderer/index.ts +8 -1
  184. package/node_modules/pi-agent-text-editor-renderer/package.json +7 -6
  185. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +262 -129
  186. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
  187. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
  188. package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
  189. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +16 -1
  190. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  191. package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +2 -0
  192. package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
  193. package/node_modules/pi-agent-tool-ui/package.json +2 -2
  194. package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +1 -0
  195. package/node_modules/pi-agent-web/index.ts +20 -0
  196. package/node_modules/pi-agent-web/package.json +8 -7
  197. package/node_modules/pi-agent-web/src/search.ts +112 -0
  198. package/node_modules/pi-agent-web-html/package.json +3 -3
  199. package/node_modules/pi-agent-web-image/package.json +4 -4
  200. package/node_modules/pi-agent-web-pdf/package.json +4 -4
  201. package/node_modules/pi-agent-web-text/package.json +4 -4
  202. package/node_modules/pi-agent-web-text/runtime/entry-87.js +2 -0
  203. package/package.json +42 -36
  204. package/skills/capture-code-review-rule/SKILL.md +60 -0
  205. package/src/code-review/config.ts +68 -0
  206. package/src/code-review/extension.ts +105 -0
  207. package/src/code-review/fragments.ts +26 -0
  208. package/src/code-review/reviewer.ts +198 -0
  209. package/src/composite/host-version.ts +13 -0
  210. package/src/composite/nested-tool-rendering.ts +298 -0
  211. package/src/composite/tool-availability.ts +90 -0
  212. package/src/core/extension.ts +2 -0
  213. package/src/documentation/extension.ts +81 -145
  214. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +6 -1
  215. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -6
  216. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  217. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  218. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  219. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  220. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/path-recovery.ts +109 -0
  221. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +20 -0
  222. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -7
  223. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
  224. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
  225. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
  226. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
  227. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +2 -0
  228. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +2 -0
  229. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +112 -0
  230. package/src/extensions/pi-agent-read/package.json +7 -7
  231. package/src/extensions/pi-agent-read/src/api/tools/read.ts +31 -2
  232. package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
  233. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
  234. package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +216 -0
  235. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +119 -72
  236. package/src/extensions/pi-agent-search/package.json +5 -4
  237. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -0
  238. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
  239. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +17 -0
  240. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -8
  241. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +42 -34
  242. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +18 -4
  243. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +37 -3
  244. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +21 -13
  245. package/src/extensions/pi-agent-search/src/api/search-parameters.ts +6 -5
  246. package/src/extensions/pi-agent-search/src/api/search.ts +11 -0
  247. package/src/extensions/pi-agent-search/src/api/structured-result.ts +93 -0
  248. package/src/extensions/pi-agent-search/src/core/extension.ts +40 -14
  249. package/src/extensions/pi-agent-search/src/core/search-core.ts +136 -77
  250. package/src/extensions/pi-agent-text-editor/index.ts +4 -2
  251. package/src/extensions/pi-agent-text-editor/package.json +21 -17
  252. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  253. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  254. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +4 -3
  255. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  256. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +8 -1
  257. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +7 -6
  258. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +262 -129
  259. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
  260. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
  261. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
  262. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +16 -1
  263. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  264. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +2 -0
  265. package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +0 -1
  266. package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +2 -0
  267. package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
  268. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
  269. package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
  270. package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +4 -0
  271. package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +95 -34
  272. package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +4 -0
  273. package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +251 -0
  274. package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +32 -12
  275. package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +154 -132
  276. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
  277. package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +74 -18
  278. package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
  279. package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +6 -0
  280. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
  281. package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +640 -0
  282. package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
  283. package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +314 -0
  284. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +143 -138
  285. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
  286. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +242 -116
  287. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +109 -47
  288. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
  289. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
  290. package/src/pi-agent-ide.ts +61 -2
  291. package/src/plugins/pi-agent-ide-ast/package.json +10 -10
  292. package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
  293. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +6 -2
  294. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +17 -0
  295. package/src/plugins/pi-agent-ide-changes/index.ts +3 -9
  296. package/src/plugins/pi-agent-ide-changes/package.json +8 -7
  297. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
  298. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +125 -47
  299. package/src/plugins/pi-agent-ide-debugger/index.ts +63 -17
  300. package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +18 -2
  301. package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +24 -4
  302. package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +68 -2
  303. package/src/plugins/pi-agent-ide-debugger/src/java-runtime.ts +357 -0
  304. package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +55 -3
  305. package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +13 -13
  306. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  307. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  308. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  309. package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
  310. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +19 -0
  311. package/src/plugins/pi-agent-ide-terminal/index.ts +12 -2
  312. package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +1 -1
  313. package/src/plugins/pi-agent-ide-terminal/src/resources.ts +65 -30
  314. package/src/plugins/pi-agent-ide-terminal/src/search.ts +13 -8
  315. package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +1 -0
  316. package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +100 -0
  317. package/src/plugins/pi-agent-ide-terminal/src/steering.ts +62 -0
  318. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +97 -45
  319. package/src/plugins/pi-agent-ide-terminal/src/types.ts +3 -1
  320. package/src/plugins/pi-agent-ide-terminal/src/ui.ts +15 -6
  321. package/src/plugins/pi-agent-ide-vision/index.ts +16 -1
  322. package/dist/chunk-3E2NTWCN.js +0 -2
  323. package/dist/chunk-4LUW26BX.js +0 -10
  324. package/dist/chunk-5VSE5X5R.js +0 -2
  325. package/dist/chunk-CEX3VOJ7.js +0 -2
  326. package/dist/chunk-FA6BKC5Y.js +0 -1
  327. package/dist/chunk-FEDVTZJG.js +0 -1
  328. package/dist/chunk-HMLH43ZS.js +0 -4
  329. package/dist/chunk-KII2JQC5.js +0 -1
  330. package/dist/chunk-LVWMWWWF.js +0 -28
  331. package/dist/chunk-P7XO5CIP.js +0 -2
  332. package/dist/chunk-PZFOOHY2.js +0 -15
  333. package/dist/chunk-S3ZPXWX7.js +0 -2
  334. package/dist/chunk-T7CZIACQ.js +0 -27
  335. package/dist/chunk-YT42LKFV.js +0 -16
  336. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
  337. package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +0 -1
  338. package/node_modules/pi-agent-web/runtime/entry-82.js +0 -2
  339. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +0 -2
  340. package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +0 -2
  341. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +0 -2
  342. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
  343. /package/dist/{chunk-4U2GUKNJ.js → chunk-F7NVAC4Q.js} +0 -0
  344. /package/dist/{chunk-ROXXK6TW.js → chunk-PXWDDBBC.js} +0 -0
  345. /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-78.js +0 -0
  346. /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-79.js +0 -0
  347. /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-81.js +0 -0
  348. /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-83.js +0 -0
  349. /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-84.js +0 -0
  350. /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-85.js +0 -0
  351. /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-86.js +0 -0
  352. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-84.js +0 -0
  353. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-85.js +0 -0
  354. /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-86.js +0 -0
  355. /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-79.js +0 -0
@@ -0,0 +1,640 @@
1
+ import path from "node:path";
2
+ import { requiredValue } from "pi-agent-invariant";
3
+ import { fileURLToPath } from "node:url";
4
+ import type {
5
+ AgentToolResult,
6
+ ExtensionAPI,
7
+ ExtensionContext,
8
+ } from "@earendil-works/pi-coding-agent";
9
+ import type { AnyTextMutationToolRegistration } from "#src/api/mutation-tool.js";
10
+ import { getLastResolvedResource } from "#src/api/last-resolved-resource.js";
11
+ import { isMutationAnchorValue } from "#src/api/mutation-tool.js";
12
+ import type { FileMutationBatchResult, FileMutationResult } from "#src/api/mutation-result.js";
13
+ import type { TextBatchEntry } from "./text-edit-batch.js";
14
+ import type { TextEditorCore, TextResourceEditRequest } from "./text-editor-core.js";
15
+ import { BatchExecutionJournal } from "./text-edit-batch-execution.js";
16
+ import {
17
+ executeRegisteredTextBatch,
18
+ planRegisteredTextBatch,
19
+ type PlannedTextBatch,
20
+ } from "./text-edit-batch-registrar.js";
21
+ import { buildFailedTextMutationResult, mutationSources } from "./text-mutation.js";
22
+ import { isWholeFileInvocation } from "./file-operation-tools.js";
23
+ import { FileMutationAgentResult } from "./mutation-result/file-mutation-agent-result.js";
24
+ import { Type } from "typebox";
25
+ import {
26
+ ResourceScheduler,
27
+ resourceAccesses,
28
+ resultError,
29
+ withStructuredResult,
30
+ type StructuredResult,
31
+ } from "pi-agent-resource";
32
+ import { captureScriptMutation } from "./text-mutation.js";
33
+ import {
34
+ NATIVE_EDIT_BATCH_EVENT,
35
+ type NativeEditBatchEvent,
36
+ } from "#src/api/native-edit-batch-event.js";
37
+ import {
38
+ mutationDataSchema,
39
+ mutationOutputSchema,
40
+ mutationOutcome,
41
+ type MutationData,
42
+ } from "./structured-result.js";
43
+
44
+ interface PendingBatch {
45
+ readonly entries: TextBatchEntry[];
46
+ readonly snapshots: Map<string, string>;
47
+ readonly existence: Map<string, boolean>;
48
+ readonly requests: Map<string, TextResourceEditRequest>;
49
+ plan: PlannedTextBatch;
50
+ }
51
+
52
+ interface BatchSummary {
53
+ readonly calls: readonly { readonly id: string; readonly state: string }[];
54
+ readonly applied: boolean;
55
+ }
56
+
57
+ interface ScriptBatch {
58
+ readonly reports: StructuredResult<MutationData>[];
59
+ reportCursor: number;
60
+ readonly id: string;
61
+ readonly context: ExtensionContext;
62
+ readonly summaries: BatchSummary[];
63
+ readonly results: FileMutationResult[];
64
+ readonly errors: string[];
65
+ readonly cancellation: AbortController;
66
+ tail: Promise<void>;
67
+ readonly scheduler: ResourceScheduler;
68
+ readonly callOrder: Map<string, number>;
69
+ pending: PendingBatch;
70
+ closed: boolean;
71
+ }
72
+
73
+ function mergedFiles(files: MutationData["files"]): MutationData["files"] {
74
+ const merged = new Map<string, MutationData["files"][number]>();
75
+ for (const file of files) {
76
+ const previous = merged.get(file.source);
77
+ const effect =
78
+ previous?.effect === "unknown" || file.effect === "unknown"
79
+ ? "unknown"
80
+ : previous?.effect === "applied" || file.effect === "applied"
81
+ ? "applied"
82
+ : file.effect;
83
+ merged.set(file.source, { ...file, effect });
84
+ }
85
+ return [...merged.values()];
86
+ }
87
+
88
+ function receiptEffect(files: MutationData["files"]): MutationData["effect"] {
89
+ return files.some((file) => file.effect === "unknown")
90
+ ? "unknown"
91
+ : files.some((file) => file.effect === "applied")
92
+ ? "applied"
93
+ : "not-applied";
94
+ }
95
+
96
+ function receiptStatus(
97
+ errors: readonly unknown[],
98
+ operations: NonNullable<MutationData["operations"]>,
99
+ ) {
100
+ return errors.length === 0
101
+ ? ("success" as const)
102
+ : operations.some(
103
+ (operation) => operation.effect === "applied" && operation.errors.length === 0,
104
+ ) &&
105
+ operations.some(
106
+ (operation) => operation.errors.length > 0 || operation.effect !== "applied",
107
+ )
108
+ ? ("partial" as const)
109
+ : ("error" as const);
110
+ }
111
+
112
+ function assertOpen(script: ScriptBatch): void {
113
+ if (script.closed) throw new Error("Codemode editor batch is closed.");
114
+ }
115
+ function pendingBatch(): PendingBatch {
116
+ return {
117
+ entries: [],
118
+ snapshots: new Map(),
119
+ existence: new Map(),
120
+ requests: new Map(),
121
+ plan: { changes: new Map(), mutations: [], failures: [] },
122
+ };
123
+ }
124
+
125
+ function isBatchable(
126
+ core: TextEditorCore,
127
+ registration: AnyTextMutationToolRegistration,
128
+ input: Readonly<Record<string, unknown>>,
129
+ ): boolean {
130
+ if (
131
+ registration.direct?.matches(input) ||
132
+ registration.intent === "restore" ||
133
+ isWholeFileInvocation(registration.wholeFileOperation, input) ||
134
+ core.getSemanticMutationHandler(registration.name, input)
135
+ )
136
+ return false;
137
+ const fields = [
138
+ registration.source.field,
139
+ ...(registration.source.targets ?? []).map((target) => target.field),
140
+ ...(registration.anchors ?? []).map((anchor) => anchor.field),
141
+ ];
142
+ return (
143
+ fields.every((field) => {
144
+ const value = input[field];
145
+ return (
146
+ typeof value !== "string" ||
147
+ !/^[a-z][a-z\d+.-]+:/iu.test(value) ||
148
+ value.startsWith("file://")
149
+ );
150
+ }) &&
151
+ typeof input[registration.source.field] === "string" &&
152
+ String(input[registration.source.field]).length > 0
153
+ );
154
+ }
155
+
156
+ class NativeTextEditBatchCoordinator {
157
+ private readonly scripts = new Map<string, ScriptBatch>();
158
+ private readonly invocations = new Map<string, ScriptBatch>();
159
+
160
+ constructor(
161
+ private readonly core: TextEditorCore,
162
+ private readonly pi: ExtensionAPI,
163
+ ) {
164
+ pi.registerTool({
165
+ name: "flush",
166
+ exposure: "codemode",
167
+ namespace: {
168
+ name: "ide_edit",
169
+ description: "Edit files and live IDE resources with guarded operations.",
170
+ },
171
+ annotations: {
172
+ readOnlyHint: false,
173
+ destructiveHint: true,
174
+ idempotentHint: false,
175
+ openWorldHint: false,
176
+ },
177
+ label: "Flush",
178
+ description:
179
+ "Use flush to commit pending native Codemode text edits and return their observed effects. Await tools.flush({}) before depending on a completed write. A failed flush retains applied effects and does not replay edits. Call it only inside native Codemode.",
180
+ promptSnippet: "Commit pending native editor changes and inspect their effects",
181
+ parameters: Type.Object({}, { additionalProperties: false }),
182
+ outputSchema: mutationOutputSchema,
183
+ execute: async (id) => {
184
+ const script = this.invocations.get(id);
185
+ if (!script) throw new Error("Flush requires an active native Codemode script");
186
+ const work = script.scheduler.run(undefined, async () => {
187
+ await this.commit(script);
188
+ const reports = script.reports.slice(script.reportCursor);
189
+ script.reportCursor = script.reports.length;
190
+ const files = mergedFiles(reports.flatMap((report) => report.data?.files ?? []));
191
+ const errors = reports.flatMap((report) => report.errors);
192
+ const operations = reports.flatMap((report) => report.data?.operations ?? []);
193
+ const effect = receiptEffect(files);
194
+ return withStructuredResult(
195
+ {
196
+ content: [
197
+ {
198
+ type: "text",
199
+ text:
200
+ errors.length === 0
201
+ ? `Flushed ${operations.length} editor operations; ${effect}.`
202
+ : `Editor flush failed; ${effect}.\n${errors.map((error) => error.message).join("\n")}`,
203
+ },
204
+ ],
205
+ details: { results: [] },
206
+ },
207
+ mutationDataSchema,
208
+ {
209
+ status: receiptStatus(errors, operations),
210
+ data: { operation: "flush", effect, files, operations },
211
+ errors,
212
+ },
213
+ );
214
+ });
215
+ script.tail = work.then(
216
+ () => undefined,
217
+ () => undefined,
218
+ );
219
+ return work;
220
+ },
221
+ });
222
+ pi.on("tool_call", async (event, context) => {
223
+ if (event.toolName === "codemode" && event.parentToolCallId === undefined) {
224
+ this.scripts.set(event.toolCallId, {
225
+ id: event.toolCallId,
226
+ context,
227
+ summaries: [],
228
+ reports: [],
229
+ reportCursor: 0,
230
+ results: [],
231
+ errors: [],
232
+ cancellation: new AbortController(),
233
+ tail: Promise.resolve(),
234
+ scheduler: new ResourceScheduler(),
235
+ callOrder: new Map(),
236
+ pending: pendingBatch(),
237
+ closed: false,
238
+ });
239
+ return;
240
+ }
241
+ const script =
242
+ event.parentToolCallId === undefined ? undefined : this.scripts.get(event.parentToolCallId);
243
+ if (!script) return;
244
+ if (event.toolName === "flush") {
245
+ this.invocations.set(event.toolCallId, script);
246
+ return;
247
+ }
248
+ const registration = this.core
249
+ .getMutationTools()
250
+ .find((tool) => tool.name === event.toolName);
251
+ const input: Record<string, unknown> = event.input;
252
+ let ownsSource = false;
253
+ if (registration && !isWholeFileInvocation(registration.wholeFileOperation, input)) {
254
+ const resolverContext = {
255
+ cwd: context.cwd,
256
+ ...(context.signal !== undefined && { signal: context.signal }),
257
+ };
258
+ for (const descriptor of [registration.source, ...(registration.source.targets ?? [])]) {
259
+ const value = input[descriptor.field];
260
+ if (typeof value === "string" && value.length > 0) {
261
+ const result = await this.core.textTargetResolver().tryResolve(value, resolverContext);
262
+ if (result.kind !== "not-handled") ownsSource = true;
263
+ }
264
+ }
265
+ for (const anchor of registration.anchors ?? []) {
266
+ const value = input[anchor.field];
267
+ if (
268
+ isMutationAnchorValue(anchor, value) &&
269
+ (await this.core.resolveTextAnchorResources(value, anchor.kinds, resolverContext)) !==
270
+ undefined
271
+ )
272
+ ownsSource = true;
273
+ }
274
+ if (registration.source.inherited && !input[registration.source.field] && !ownsSource) {
275
+ const source = script.pending.entries.at(-1)?.path ?? getLastResolvedResource(pi)?.source;
276
+ if (source !== undefined) input[registration.source.field] = source;
277
+ }
278
+ }
279
+ if (registration && !ownsSource && isBatchable(this.core, registration, input)) {
280
+ this.invocations.set(event.toolCallId, script);
281
+ return;
282
+ }
283
+ const work = script.scheduler.run(undefined, () => this.commit(script));
284
+ script.tail = work.then(
285
+ () => undefined,
286
+ () => undefined,
287
+ );
288
+ if (!(await work))
289
+ return {
290
+ block: true,
291
+ reason:
292
+ "Editor batch failed before this tool. See the Codemode result; do not replay accepted edits automatically.",
293
+ };
294
+ return;
295
+ });
296
+ pi.on("tool_result", async (event) => {
297
+ this.invocations.delete(event.toolCallId);
298
+ const script = this.scripts.get(event.toolCallId);
299
+ if (!script) return;
300
+ script.closed = true;
301
+ const interrupted =
302
+ script.context.signal?.aborted ||
303
+ (event.isError &&
304
+ event.content.some(
305
+ (block) =>
306
+ block.type === "text" &&
307
+ /^Script error:\nScript (?:aborted|timed out):/u.test(block.text),
308
+ ));
309
+ if (interrupted) script.cancellation.abort();
310
+ await script.tail;
311
+ if (interrupted) {
312
+ if (script.pending.entries.length > 0) {
313
+ const error = resultError(
314
+ "Pending editor batch cancelled; no pending edits were written.",
315
+ "CANCELLED",
316
+ );
317
+ const operations = script.pending.entries.map((entry) => ({
318
+ id: entry.callId,
319
+ operation: entry.op,
320
+ effect: "not-applied" as const,
321
+ errors: [error],
322
+ }));
323
+ script.reports.push({
324
+ status: "error",
325
+ errors: [error],
326
+ data: {
327
+ operation: "flush",
328
+ effect: "not-applied",
329
+ operations,
330
+ files: [...script.pending.snapshots.keys()].map((source) => ({
331
+ source,
332
+ effect: "not-applied",
333
+ })),
334
+ },
335
+ });
336
+ script.errors.push(error.message);
337
+ script.pending = pendingBatch();
338
+ }
339
+ } else await this.commit(script);
340
+ this.scripts.delete(event.toolCallId);
341
+ if (script.summaries.length === 0 && script.errors.length === 0) return;
342
+ const failed = script.errors.length > 0;
343
+ const content = event.content.map((block) =>
344
+ failed && block.type === "text"
345
+ ? { ...block, text: block.text.replace(/^Script completed\n/u, "Script failed\n") }
346
+ : block,
347
+ );
348
+ content.push({
349
+ type: "text",
350
+ text: `Editor batches: ${script.summaries.filter((batch) => batch.applied).length} committed.${failed ? "\n" + script.errors.join("\n") : ""}`,
351
+ });
352
+ if (script.results.length > 0)
353
+ content.push(new FileMutationAgentResult(script.results).toTextContent());
354
+ const details =
355
+ typeof event.details === "object" && event.details !== null ? event.details : {};
356
+ return {
357
+ content,
358
+ details: {
359
+ ...details,
360
+ editorBatches: script.summaries,
361
+ editorBatchResults: script.reports,
362
+ },
363
+ ...(event.structuredContent === undefined
364
+ ? {}
365
+ : { structuredContent: event.structuredContent }),
366
+ isError: event.isError || failed,
367
+ };
368
+ });
369
+ const clear = () => {
370
+ for (const script of this.scripts.values()) {
371
+ script.closed = true;
372
+ script.cancellation.abort();
373
+ }
374
+ this.scripts.clear();
375
+ this.invocations.clear();
376
+ };
377
+ pi.on("agent_end", clear);
378
+ pi.on("session_shutdown", clear);
379
+ }
380
+
381
+ execute(
382
+ id: string,
383
+ registration: AnyTextMutationToolRegistration,
384
+ input: Readonly<Record<string, unknown>>,
385
+ signal: AbortSignal | undefined,
386
+ context: ExtensionContext,
387
+ ): Promise<AgentToolResult<FileMutationBatchResult>> | undefined {
388
+ const script = this.invocations.get(id);
389
+ if (!script) return undefined;
390
+ script.callOrder.set(id, script.callOrder.size);
391
+ const sources = [...mutationSources(registration, input).values()].map((source) =>
392
+ source.startsWith("file://")
393
+ ? fileURLToPath(source)
394
+ : path.resolve(context.cwd, source.startsWith("@") ? source.slice(1) : source),
395
+ );
396
+ const effectiveSignal =
397
+ signal === undefined
398
+ ? script.cancellation.signal
399
+ : AbortSignal.any([signal, script.cancellation.signal]);
400
+ const work = script.scheduler.run(
401
+ Promise.all(sources.map((source) => resourceAccesses(source, context.cwd, "write"))).then(
402
+ (sets) => sets.flat(),
403
+ ),
404
+ () => this.accept(script, id, registration, input, effectiveSignal, context),
405
+ effectiveSignal,
406
+ );
407
+ script.tail = Promise.allSettled([script.tail, work]).then(() => undefined);
408
+ return work;
409
+ }
410
+
411
+ private async accept(
412
+ script: ScriptBatch,
413
+ id: string,
414
+ registration: AnyTextMutationToolRegistration,
415
+ input: Readonly<Record<string, unknown>>,
416
+ signal: AbortSignal | undefined,
417
+ context: ExtensionContext,
418
+ ): Promise<AgentToolResult<FileMutationBatchResult>> {
419
+ signal?.throwIfAborted();
420
+ assertOpen(script);
421
+ const normalized = { ...input };
422
+ for (const descriptor of [registration.source, ...(registration.source.targets ?? [])]) {
423
+ const source = normalized[descriptor.field];
424
+ if (typeof source === "string" && source.length > 0)
425
+ normalized[descriptor.field] = source.startsWith("file://")
426
+ ? fileURLToPath(source)
427
+ : path.resolve(context.cwd, source.startsWith("@") ? source.slice(1) : source);
428
+ }
429
+ const entry: TextBatchEntry = {
430
+ ...normalized,
431
+ callId: id,
432
+ op: registration.name,
433
+ path: String(normalized[registration.source.field]),
434
+ };
435
+ const batch = script.pending;
436
+ const requests = new Map<string, TextResourceEditRequest>();
437
+ for (const source of mutationSources(registration, entry).values())
438
+ requests.set(source, {
439
+ source,
440
+ read: true,
441
+ ...(registration.name === "write" && { allowReadFailure: true }),
442
+ ...(batch.existence.has(source) && { expectedExistence: batch.existence.get(source) }),
443
+ });
444
+ const planning: { plan?: PlannedTextBatch; cause?: unknown } = {};
445
+ const preview = await this.core.previewTexts(
446
+ [...requests.values()],
447
+ { cwd: context.cwd, ...(signal !== undefined && { signal }) },
448
+ async (texts, resolveAnchor) => {
449
+ try {
450
+ for (const [source, expected] of batch.snapshots)
451
+ if (requests.has(source) && texts.get(source) !== expected)
452
+ throw new Error(`Snapshot source ${source} changed before the edit batch.`);
453
+ planning.plan = await planRegisteredTextBatch(
454
+ new Map([[registration.name, registration]]),
455
+ { edits: [entry], failureMode: "abort" },
456
+ texts,
457
+ resolveAnchor,
458
+ context,
459
+ signal,
460
+ () => {},
461
+ new Map([...batch.plan.changes].filter(([source]) => requests.has(source))),
462
+ );
463
+ return { changes: planning.plan.changes, result: planning.plan };
464
+ } catch (error) {
465
+ planning.cause = error;
466
+ throw error;
467
+ }
468
+ },
469
+ );
470
+ if (preview.kind === "failed") {
471
+ const result = await buildFailedTextMutationResult(
472
+ this.core,
473
+ {
474
+ code: "INVALID_REQUEST",
475
+ source: entry.path,
476
+ message: preview.reason,
477
+ cause: planning.cause,
478
+ },
479
+ context,
480
+ );
481
+ return { ...result, isError: true };
482
+ }
483
+ signal?.throwIfAborted();
484
+ assertOpen(script);
485
+ if (!planning.plan) throw new Error("Editor batch planning did not complete.");
486
+ for (const resource of preview.resources) {
487
+ batch.snapshots.set(resource.path, resource.beforeContent);
488
+ batch.existence.set(resource.path, resource.existed ?? true);
489
+ }
490
+ for (const [source, request] of requests) batch.requests.set(source, request);
491
+ batch.entries.push(entry);
492
+ const order = (left: { callId: string }, right: { callId: string }) =>
493
+ requiredValue(script.callOrder.get(left.callId)) -
494
+ requiredValue(script.callOrder.get(right.callId));
495
+ batch.entries.sort(order);
496
+ batch.plan = {
497
+ changes: new Map([...batch.plan.changes, ...planning.plan.changes]),
498
+ mutations: [...batch.plan.mutations, ...planning.plan.mutations].sort(order),
499
+ failures: [...batch.plan.failures, ...planning.plan.failures],
500
+ };
501
+ const details = {
502
+ results: [],
503
+ source: entry.path,
504
+ resolvedBy: preview.resources.find((resource) => resource.path === entry.path)?.resolvedBy,
505
+ nativeEditBatch: { parentToolCallId: script.id, state: "accepted" },
506
+ };
507
+ return {
508
+ content: [
509
+ {
510
+ type: "text",
511
+ text: `Accepted ${registration.name} for ${entry.path}; not yet applied. The editor batch commits before another tool or when this script ends.`,
512
+ },
513
+ ],
514
+ details,
515
+ };
516
+ }
517
+
518
+ private async commit(script: ScriptBatch): Promise<boolean> {
519
+ const batch = script.pending;
520
+ if (batch.entries.length === 0) return true;
521
+ script.pending = pendingBatch();
522
+ const journal = new BatchExecutionJournal(batch.entries.map((entry) => entry.callId));
523
+ const registrations = new Map(this.core.getMutationTools().map((tool) => [tool.name, tool]));
524
+ const signal =
525
+ script.context.signal === undefined
526
+ ? script.cancellation.signal
527
+ : AbortSignal.any([script.context.signal, script.cancellation.signal]);
528
+ let observedSources: string[] = [];
529
+ const record = (outcome: StructuredResult<MutationData>): boolean => {
530
+ const calls = journal.snapshot();
531
+ const operations = calls.map((call) => ({
532
+ id: call.callId,
533
+ operation: requiredValue(batch.entries.find((entry) => entry.callId === call.callId)).op,
534
+ effect:
535
+ call.state === "completed" || call.state === "failed-applied"
536
+ ? ("applied" as const)
537
+ : call.state === "failed-unknown" || call.state === "running"
538
+ ? ("unknown" as const)
539
+ : ("not-applied" as const),
540
+ errors: call.failure === undefined ? [] : [resultError(call.failure.error)],
541
+ }));
542
+ const files = mergedFiles([
543
+ ...operations.flatMap((operation) => {
544
+ const entry = requiredValue(batch.entries.find((entry) => entry.callId === operation.id));
545
+ const registration = requiredValue(registrations.get(entry.op));
546
+ return [...mutationSources(registration, entry).values()].map((source) => ({
547
+ source,
548
+ effect: operation.effect,
549
+ }));
550
+ }),
551
+ ...observedSources.map((source) => ({ source, effect: "applied" as const })),
552
+ ]).map((file) =>
553
+ observedSources.includes(file.source) ? { ...file, effect: "applied" as const } : file,
554
+ );
555
+ const errors = [
556
+ ...new Map(
557
+ [...outcome.errors, ...operations.flatMap((operation) => operation.errors)].map(
558
+ (error) => [JSON.stringify(error), error],
559
+ ),
560
+ ).values(),
561
+ ];
562
+ const completed = calls.every((call) => call.state === "completed");
563
+ if (!completed && errors.length === 0)
564
+ errors.push(resultError("Editor batch did not complete", "BATCH_FAILED"));
565
+ script.reports.push({
566
+ status: receiptStatus(errors, operations),
567
+ errors,
568
+ data: {
569
+ ...outcome.data,
570
+ operation: "flush",
571
+ effect: receiptEffect(files),
572
+ files,
573
+ operations,
574
+ },
575
+ });
576
+ script.summaries.push({
577
+ calls: calls.map((call) => ({ id: call.callId, state: call.state })),
578
+ applied:
579
+ operations.some((operation) => operation.effect === "applied") ||
580
+ observedSources.length > 0,
581
+ });
582
+ if (!completed)
583
+ script.errors.push(
584
+ "Editor batch failed; inspect its final file results. Accepted edits were not replayed.",
585
+ );
586
+ return completed;
587
+ };
588
+ try {
589
+ signal.throwIfAborted();
590
+ const captured = await captureScriptMutation(this.core, () =>
591
+ executeRegisteredTextBatch(
592
+ this.core,
593
+ registrations,
594
+ {
595
+ edits: batch.entries,
596
+ expectedContent: batch.snapshots,
597
+ expectedExistence: batch.existence,
598
+ },
599
+ signal,
600
+ undefined,
601
+ script.context,
602
+ journal.reporter(),
603
+ () => {},
604
+ batch.plan,
605
+ ),
606
+ );
607
+ observedSources = captured.completions.map((completion) => completion.resourceSource);
608
+ if (captured.kind === "failed") throw captured.error;
609
+ script.results.push(...(captured.value.details.results ?? []));
610
+ this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, {
611
+ parentToolCallId: script.id,
612
+ calls: batch.entries.map((entry) => entry.callId),
613
+ result: captured.value,
614
+ } satisfies NativeEditBatchEvent);
615
+ return record(mutationOutcome(captured.value, "flush", captured.completions));
616
+ } catch (error) {
617
+ journal.markRunningUnknown(error);
618
+ return record({ status: "error", errors: [resultError(error)] });
619
+ }
620
+ }
621
+ }
622
+
623
+ const coordinators = new WeakMap<TextEditorCore, NativeTextEditBatchCoordinator>();
624
+
625
+ /** Attach accumulating editor batches to native Codemode's public parent/child lifecycle. */
626
+ export function registerNativeTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void {
627
+ coordinators.set(core, new NativeTextEditBatchCoordinator(core, pi));
628
+ }
629
+
630
+ /** Accept one nested text mutation, or leave a non-batched call on its normal execution path. */
631
+ export function executeNativeTextEditBatch(
632
+ core: TextEditorCore,
633
+ id: string,
634
+ registration: AnyTextMutationToolRegistration,
635
+ input: Readonly<Record<string, unknown>>,
636
+ signal: AbortSignal | undefined,
637
+ context: ExtensionContext,
638
+ ): Promise<AgentToolResult<FileMutationBatchResult>> | undefined {
639
+ return coordinators.get(core)?.execute(id, registration, input, signal, context);
640
+ }
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { ResourceScheduler, resourceAccesses } from "pi-agent-resource";
2
3
  import type { TextResourceEditOutcome } from "./text-editor-core.js";
3
4
 
4
5
  type Completed = Exclude<TextResourceEditOutcome<unknown>, { readonly kind: "failed" }>;
@@ -42,7 +43,7 @@ export function forgetDeferredPostEdit(source: string): void {
42
43
  active.getStore()?.delete(source);
43
44
  }
44
45
  /** Writes stay immediate; finishing drains each surviving final resource once. */
45
- export function createPostEditScope() {
46
+ export function createPostEditScope(cwd = process.cwd()) {
46
47
  const pending = new Map<string, Finalize>();
47
48
  return {
48
49
  run<T>(operation: () => T): T {
@@ -51,17 +52,30 @@ export function createPostEditScope() {
51
52
  forget(source: string): void {
52
53
  pending.delete(source);
53
54
  },
55
+ /** Complete resource set that finish may modify. */
56
+ sources(): readonly string[] {
57
+ return [...pending.keys()];
58
+ },
54
59
  async finish(onCompleted?: (outcome: Completed) => void): Promise<Completed[]> {
55
- const work = [...pending.values()];
60
+ const work = [...pending];
56
61
  pending.clear();
57
62
  const completed: Completed[] = [];
58
63
  const errors: unknown[] = [];
59
64
  await collectPostEditNotifications(async () => {
60
- for (const finalize of work) {
65
+ const scheduler = new ResourceScheduler();
66
+ const outcomes = await Promise.allSettled(
67
+ work.map(([source, finalize]) =>
68
+ scheduler.run(resourceAccesses(source, cwd, "write"), finalize),
69
+ ),
70
+ );
71
+ for (const outcome of outcomes) {
72
+ if (outcome.status === "rejected") {
73
+ errors.push(outcome.reason);
74
+ continue;
75
+ }
76
+ completed.push(outcome.value);
61
77
  try {
62
- const outcome = await finalize();
63
- completed.push(outcome);
64
- onCompleted?.(outcome);
78
+ onCompleted?.(outcome.value);
65
79
  } catch (error) {
66
80
  errors.push(error);
67
81
  }