pi-agent-ide 0.1.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 (446) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/assets/banner.png +0 -0
  4. package/docs/architecture.md +100 -0
  5. package/docs/configuration.md +104 -0
  6. package/docs/development.md +102 -0
  7. package/docs/evaluation.md +14 -0
  8. package/docs/extensions.md +298 -0
  9. package/docs/tools.md +104 -0
  10. package/node_modules/pi-agent-filesystem/index.ts +60 -0
  11. package/node_modules/pi-agent-filesystem/package.json +23 -0
  12. package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
  13. package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
  14. package/node_modules/pi-agent-filesystem-image/package.json +20 -0
  15. package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
  16. package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
  17. package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
  18. package/node_modules/pi-agent-filesystem-text/package.json +20 -0
  19. package/node_modules/pi-agent-ide-ast/index.ts +1 -0
  20. package/node_modules/pi-agent-ide-ast/package.json +39 -0
  21. package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
  22. package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
  23. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
  24. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
  25. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
  26. package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
  27. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
  28. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
  29. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
  30. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
  31. package/node_modules/pi-agent-ide-changes/index.ts +68 -0
  32. package/node_modules/pi-agent-ide-changes/package.json +29 -0
  33. package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
  34. package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
  35. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
  36. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
  37. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
  38. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
  39. package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
  40. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
  41. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
  42. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
  43. package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
  44. package/node_modules/pi-agent-ide-formatter/package.json +14 -0
  45. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
  46. package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
  47. package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
  48. package/node_modules/pi-agent-ide-lint/index.ts +237 -0
  49. package/node_modules/pi-agent-ide-lint/package.json +19 -0
  50. package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
  51. package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
  52. package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
  53. package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
  54. package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
  55. package/node_modules/pi-agent-ide-lsp/package.json +23 -0
  56. package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
  57. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
  58. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
  59. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
  60. package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
  61. package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
  62. package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
  63. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
  64. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
  65. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
  66. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
  67. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
  68. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
  69. package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
  70. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
  71. package/node_modules/pi-agent-image/package.json +18 -0
  72. package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
  73. package/node_modules/pi-agent-image/src/index.ts +6 -0
  74. package/node_modules/pi-agent-pdf/package.json +16 -0
  75. package/node_modules/pi-agent-pdf/src/index.ts +5 -0
  76. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
  77. package/node_modules/pi-agent-read/index.ts +1 -0
  78. package/node_modules/pi-agent-read/package.json +41 -0
  79. package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
  80. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
  81. package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
  82. package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
  83. package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
  84. package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
  85. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
  86. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
  87. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
  88. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
  89. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
  90. package/node_modules/pi-agent-resource/package.json +17 -0
  91. package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
  92. package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
  93. package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
  94. package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
  95. package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
  96. package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
  97. package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
  98. package/node_modules/pi-agent-resource/src/content.ts +17 -0
  99. package/node_modules/pi-agent-resource/src/index.ts +65 -0
  100. package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
  101. package/node_modules/pi-agent-resource/src/resource.ts +41 -0
  102. package/node_modules/pi-agent-resource/src/validation.ts +139 -0
  103. package/node_modules/pi-agent-search/index.ts +1 -0
  104. package/node_modules/pi-agent-search/package.json +35 -0
  105. package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
  106. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
  107. package/node_modules/pi-agent-search/src/api/search.ts +91 -0
  108. package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
  109. package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
  110. package/node_modules/pi-agent-search-semantic/index.ts +105 -0
  111. package/node_modules/pi-agent-search-semantic/package.json +17 -0
  112. package/node_modules/pi-agent-search-text/index.ts +54 -0
  113. package/node_modules/pi-agent-search-text/package.json +33 -0
  114. package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
  115. package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
  116. package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
  117. package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
  118. package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
  119. package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
  120. package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
  121. package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
  122. package/node_modules/pi-agent-search-web/index.ts +74 -0
  123. package/node_modules/pi-agent-search-web/package.json +19 -0
  124. package/node_modules/pi-agent-search-web/src/config.ts +499 -0
  125. package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
  126. package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
  127. package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
  128. package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
  129. package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
  130. package/node_modules/pi-agent-search-web/src/search.ts +434 -0
  131. package/node_modules/pi-agent-search-web/src/types.ts +153 -0
  132. package/node_modules/pi-agent-text/package.json +18 -0
  133. package/node_modules/pi-agent-text/src/index.ts +31 -0
  134. package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
  135. package/node_modules/pi-agent-text/src/source-line.ts +49 -0
  136. package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
  137. package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
  138. package/node_modules/pi-agent-text/src/text-document.ts +149 -0
  139. package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
  140. package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
  141. package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
  142. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
  143. package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
  144. package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
  145. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
  146. package/node_modules/pi-agent-text-editor/index.ts +19 -0
  147. package/node_modules/pi-agent-text-editor/package.json +92 -0
  148. package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
  149. package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
  150. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
  151. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
  152. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
  153. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
  154. package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
  155. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
  156. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
  157. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
  158. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
  159. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
  160. package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
  161. package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
  162. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
  163. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
  164. package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
  165. package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
  166. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
  167. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
  168. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
  169. package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
  170. package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
  171. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
  172. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
  173. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
  174. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
  175. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
  176. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
  177. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
  178. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
  179. package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
  180. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
  181. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
  182. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
  183. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
  184. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
  185. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
  186. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
  187. package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
  188. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
  189. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
  190. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
  191. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
  192. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
  193. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
  194. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
  195. package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
  196. package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
  197. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
  198. package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
  199. package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
  200. package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
  201. package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
  202. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
  203. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
  204. package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
  205. package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
  206. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
  207. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
  208. package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
  209. package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
  210. package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
  211. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
  212. package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
  213. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
  214. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
  215. package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
  216. package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
  217. package/node_modules/pi-agent-web/index.ts +37 -0
  218. package/node_modules/pi-agent-web/package.json +24 -0
  219. package/node_modules/pi-agent-web/src/resolver.ts +182 -0
  220. package/node_modules/pi-agent-web-html/index.ts +15 -0
  221. package/node_modules/pi-agent-web-html/package.json +18 -0
  222. package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
  223. package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
  224. package/node_modules/pi-agent-web-image/index.ts +14 -0
  225. package/node_modules/pi-agent-web-image/package.json +17 -0
  226. package/node_modules/pi-agent-web-pdf/index.ts +14 -0
  227. package/node_modules/pi-agent-web-pdf/package.json +17 -0
  228. package/node_modules/pi-agent-web-text/index.ts +14 -0
  229. package/node_modules/pi-agent-web-text/package.json +17 -0
  230. package/package.json +176 -0
  231. package/src/api/code-view.ts +25 -0
  232. package/src/api/connect-plugin.ts +64 -0
  233. package/src/api/plugin-protocol.ts +63 -0
  234. package/src/api/read.ts +5 -0
  235. package/src/api/resource.ts +2 -0
  236. package/src/api/search.ts +4 -0
  237. package/src/api/text-editor.ts +3 -0
  238. package/src/api/text.ts +2 -0
  239. package/src/api/toolchain.ts +24 -0
  240. package/src/code-view/diagnostic-view.ts +82 -0
  241. package/src/code-view/reference.ts +113 -0
  242. package/src/code-view/source-view.ts +229 -0
  243. package/src/composite/builtin-extensions.ts +68 -0
  244. package/src/composite/config.ts +94 -0
  245. package/src/composite/selection.ts +66 -0
  246. package/src/core/extension.ts +48 -0
  247. package/src/core/ide-core.ts +117 -0
  248. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
  249. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
  250. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
  251. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
  252. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
  253. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
  254. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
  255. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
  256. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
  257. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
  258. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
  259. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
  260. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
  261. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
  262. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
  263. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
  264. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
  265. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
  266. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
  267. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
  268. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
  269. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
  270. package/src/extensions/pi-agent-read/index.ts +1 -0
  271. package/src/extensions/pi-agent-read/package.json +41 -0
  272. package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
  273. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
  274. package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
  275. package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
  276. package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
  277. package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
  278. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
  279. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
  280. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
  281. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
  282. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
  283. package/src/extensions/pi-agent-search/index.ts +1 -0
  284. package/src/extensions/pi-agent-search/package.json +35 -0
  285. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
  286. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
  287. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
  288. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
  289. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
  290. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
  291. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
  292. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
  293. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
  294. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
  295. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
  296. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
  297. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
  298. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
  299. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
  300. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
  301. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
  302. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
  303. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
  304. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
  305. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
  306. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
  307. package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
  308. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
  309. package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
  310. package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
  311. package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
  312. package/src/extensions/pi-agent-text-editor/index.ts +19 -0
  313. package/src/extensions/pi-agent-text-editor/package.json +92 -0
  314. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
  315. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
  316. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
  317. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
  318. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
  319. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
  320. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
  321. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
  322. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
  323. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
  324. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
  325. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
  326. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
  327. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
  328. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
  329. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
  330. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
  331. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
  332. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
  333. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
  334. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
  335. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
  336. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
  337. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
  338. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
  339. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
  340. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
  341. package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
  342. package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
  343. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
  344. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
  345. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
  346. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
  347. package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
  348. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
  349. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
  350. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
  351. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
  352. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
  353. package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
  354. package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
  355. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
  356. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
  357. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
  358. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
  359. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
  360. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
  361. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
  362. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
  363. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
  364. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
  365. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
  366. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
  367. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
  368. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
  369. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
  370. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
  371. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
  372. package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
  373. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
  374. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
  375. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
  376. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
  377. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
  378. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
  379. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
  380. package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
  381. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
  382. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
  383. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
  384. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
  385. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
  386. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
  387. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
  388. package/src/index.ts +1 -0
  389. package/src/pi-agent-ide.ts +17 -0
  390. package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
  391. package/src/plugins/pi-agent-ide-ast/package.json +39 -0
  392. package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
  393. package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
  394. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
  395. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
  396. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
  397. package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
  398. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
  399. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
  400. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
  401. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
  402. package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
  403. package/src/plugins/pi-agent-ide-changes/package.json +29 -0
  404. package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
  405. package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
  406. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
  407. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
  408. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
  409. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
  410. package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
  411. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
  412. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
  413. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
  414. package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
  415. package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
  416. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
  417. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
  418. package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
  419. package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
  420. package/src/plugins/pi-agent-ide-lint/package.json +19 -0
  421. package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
  422. package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
  423. package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
  424. package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
  425. package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
  426. package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
  427. package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
  428. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
  429. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
  430. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
  431. package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
  432. package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
  433. package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
  434. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
  435. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
  436. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
  437. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
  438. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
  439. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
  440. package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
  441. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
  442. package/src/post-edit/gate.ts +153 -0
  443. package/src/toolchain/diagnostic.ts +7 -0
  444. package/src/toolchain/gate.ts +322 -0
  445. package/src/toolchain/registry.ts +223 -0
  446. package/src/toolchain/types.ts +164 -0
@@ -0,0 +1,127 @@
1
+ import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
2
+
3
+ export type BatchCallEffect = "not-applied" | "applied" | "unknown";
4
+
5
+ export type BatchCallExecutionState =
6
+ | "pending"
7
+ | "running"
8
+ | "completed"
9
+ | "failed-not-applied"
10
+ | "failed-applied"
11
+ | "failed-unknown"
12
+ | "blocked";
13
+
14
+ export interface BatchCallFailure
15
+ {
16
+ readonly error: unknown;
17
+ readonly effect: BatchCallEffect;
18
+ readonly result?: AgentToolResult<unknown>;
19
+ }
20
+
21
+ export interface BatchCallExecutionEntry
22
+ {
23
+ readonly callId: string;
24
+ readonly state: BatchCallExecutionState;
25
+ readonly result?: AgentToolResult<unknown>;
26
+ readonly failure?: BatchCallFailure;
27
+ readonly blockedDetails?: unknown;
28
+ readonly recovered: boolean;
29
+ readonly reason?: string;
30
+ }
31
+
32
+ export interface BatchExecutionReporter<TDetails = unknown>
33
+ {
34
+ start(callId: string): void;
35
+ complete(callId: string, result: AgentToolResult<TDetails>): void;
36
+ fail(callId: string, failure: BatchCallFailure): void;
37
+ }
38
+
39
+ export class BatchExecutionJournal
40
+ {
41
+ private readonly entries: Map<string, BatchCallExecutionEntry>;
42
+
43
+ constructor(callIds: readonly string[])
44
+ {
45
+ this.entries = new Map(callIds.map((callId) => [callId, { callId, state: "pending", recovered: false }]));
46
+ }
47
+
48
+ reporter(recovered = false): BatchExecutionReporter
49
+ {
50
+ return {
51
+ start: (callId) =>
52
+ {
53
+ this.transition(callId, { state: "running", recovered });
54
+ },
55
+ complete: (callId, result) =>
56
+ {
57
+ this.transition(callId, { state: "completed", result, recovered });
58
+ },
59
+ fail: (callId, failure) =>
60
+ {
61
+ this.transition(callId, {
62
+ state: `failed-${failure.effect}`,
63
+ failure,
64
+ ...(failure.result === undefined ? {} : { result: failure.result }),
65
+ recovered,
66
+ });
67
+ },
68
+ };
69
+ }
70
+
71
+ block(callId: string, result: AgentToolResult<unknown>, details?: unknown): void
72
+ {
73
+ this.transition(callId, { state: "blocked", result, blockedDetails: details, recovered: false });
74
+ }
75
+
76
+ skip(callId: string, reason: string): void
77
+ {
78
+ this.transition(callId, {
79
+ state: "failed-not-applied",
80
+ failure: { error: new Error(reason), effect: "not-applied" },
81
+ recovered: false,
82
+ reason,
83
+ });
84
+ }
85
+
86
+ markRunningUnknown(error: unknown): void
87
+ {
88
+ for (const entry of this.entries.values())
89
+ {
90
+ if (entry.state === "running")
91
+ {
92
+ this.transition(entry.callId, {
93
+ state: "failed-unknown",
94
+ failure: { error, effect: "unknown" },
95
+ recovered: entry.recovered,
96
+ });
97
+ }
98
+ }
99
+ }
100
+
101
+ get(callId: string): BatchCallExecutionEntry
102
+ {
103
+ const entry = this.entries.get(callId);
104
+
105
+ if (!entry)
106
+ {
107
+ throw new Error(`Unknown batch call ${callId}.`);
108
+ }
109
+
110
+ return entry;
111
+ }
112
+
113
+ snapshot(): readonly BatchCallExecutionEntry[]
114
+ {
115
+ return [...this.entries.values()].map((entry) => ({ ...entry }));
116
+ }
117
+
118
+ private transition(callId: string, update: Omit<BatchCallExecutionEntry, "callId">): void
119
+ {
120
+ if (!this.entries.has(callId))
121
+ {
122
+ throw new Error(`Unknown batch call ${callId}.`);
123
+ }
124
+
125
+ this.entries.set(callId, { callId, ...update });
126
+ }
127
+ }
@@ -0,0 +1,45 @@
1
+ import type { BatchCallCandidate, OriginalToolCall } from "./text-edit-batch-coordinator.js";
2
+ import type { BatchCallExecutionEntry, BatchExecutionReporter } from "./text-edit-batch-execution.js";
3
+ import type { AgentToolResult, ExtensionContext } from "@earendil-works/pi-coding-agent";
4
+
5
+ export interface BlockedToolCall
6
+ {
7
+ readonly callId: string;
8
+ readonly toolName: string;
9
+ readonly arguments: Record<string, unknown>;
10
+ readonly contentIndex?: number;
11
+ readonly batchEntryIndex?: number;
12
+ readonly details?: unknown;
13
+ readonly result: AgentToolResult<unknown>;
14
+ readonly nativeExecutionBlocked: boolean;
15
+ }
16
+
17
+ export interface BatchRecoveryInput<TState = unknown>
18
+ {
19
+ readonly batchId: string;
20
+ readonly calls: readonly OriginalToolCall[];
21
+ readonly candidates: readonly BatchCallCandidate<TState>[];
22
+ readonly journal: readonly BatchCallExecutionEntry[];
23
+ readonly blockedCalls: readonly BlockedToolCall[];
24
+ readonly cwd: string;
25
+ readonly signal: AbortSignal | undefined;
26
+ readonly ctx: ExtensionContext;
27
+ }
28
+
29
+ export interface BatchRecoveryExecutionInput<TState = unknown> extends BatchRecoveryInput<TState>
30
+ {
31
+ readonly selected: readonly BatchCallCandidate<TState>[];
32
+ readonly reporter: BatchExecutionReporter;
33
+ }
34
+
35
+ export interface BatchRecoveryOutcome
36
+ {
37
+ readonly results: ReadonlyMap<string, AgentToolResult<unknown>>;
38
+ readonly skipped?: ReadonlyMap<string, string>;
39
+ }
40
+
41
+ export interface ToolBatchRecoveryDefinition<TState = unknown>
42
+ {
43
+ select(input: BatchRecoveryInput<TState>): readonly string[];
44
+ execute(input: BatchRecoveryExecutionInput<TState>): Promise<BatchRecoveryOutcome>;
45
+ }
@@ -0,0 +1,432 @@
1
+ import { FileMutationAgentResult } from "#src/core/mutation-result/file-mutation-agent-result.js";
2
+ import { applyTextChanges, type TextChange, TextChangeDocument } from "#src/core/text-change-engine.js";
3
+ import {
4
+ executeWithBatchCoordinator,
5
+ registerBlockedToolCall,
6
+ registerToolBatch,
7
+ type ToolBatchDefinition,
8
+ } from "#src/core/text-edit-batch-coordinator.js";
9
+ import {
10
+ splitTextBatchResult,
11
+ type TextBatchDetails,
12
+ type TextBatchEntry,
13
+ type TextBatchParams,
14
+ } from "#src/core/text-edit-batch.js";
15
+ import { contextualizeTextMutationAnchorError } from "#src/core/text-mutation-anchor-error.js";
16
+ import {
17
+ buildFailedTextMutationResult,
18
+ buildSuccessfulTextMutationResult,
19
+ mutationSources,
20
+ } from "#src/core/text-mutation.js";
21
+ import { registerBlockedToolCallSink } from "#src/core/tool-call-interceptor/coordinator.js";
22
+
23
+ import type { TextEditIntent } from "#src/api/edit-completion.js";
24
+ import type { FileMutationResult } from "#src/api/mutation-result.js";
25
+ import type { AnyTextMutationToolRegistration, TextMutation } from "#src/api/mutation-tool.js";
26
+ import type { BatchExecutionReporter } from "#src/core/text-edit-batch-execution.js";
27
+ import type { TextEditorCore, TextResourceEditFailure, TextResourcesEditOutcome } from "#src/core/text-editor-core.js";
28
+ import type {
29
+ AgentToolResult,
30
+ AgentToolUpdateCallback,
31
+ ExtensionAPI,
32
+ ExtensionContext,
33
+ } from "@earendil-works/pi-coding-agent";
34
+
35
+ interface TextBatchState
36
+ {
37
+ readonly source: string;
38
+ readonly registration: AnyTextMutationToolRegistration;
39
+ }
40
+
41
+ interface PlannedTextBatch
42
+ {
43
+ readonly mutations: readonly { readonly callId: string; readonly mutation: TextMutation; }[];
44
+ readonly failures: readonly {
45
+ readonly callId: string;
46
+ readonly source: string;
47
+ readonly error: unknown;
48
+ readonly effect: "applied" | "not-applied";
49
+ }[];
50
+ }
51
+
52
+ const renderArgumentSinks = new WeakMap<
53
+ TextEditorCore,
54
+ (toolCallId: string, patch: Readonly<Record<string, unknown>>) => void
55
+ >();
56
+
57
+ export function setTextEditBatchRenderArgumentSink(
58
+ core: TextEditorCore,
59
+ sink: (toolCallId: string, patch: Readonly<Record<string, unknown>>) => void,
60
+ ): void
61
+ {
62
+ renderArgumentSinks.set(core, sink);
63
+ }
64
+
65
+ export function registerTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void
66
+ {
67
+ const sourceTools: string[] = [];
68
+ const registrations = new Map<string, AnyTextMutationToolRegistration>();
69
+ const renderArguments = (toolCallId: string, patch: Readonly<Record<string, unknown>>): void =>
70
+ renderArgumentSinks.get(core)?.(toolCallId, patch);
71
+ const definition: ToolBatchDefinition<TextBatchState> = {
72
+ sourceTools,
73
+ syntheticTool: "__pi_agent_text_editor_batch",
74
+ resolveCall(call, inherited)
75
+ {
76
+ const registration = registrations.get(call.name);
77
+
78
+ if (registration === undefined)
79
+ {
80
+ return;
81
+ }
82
+
83
+ const explicit = call.arguments[registration.source.field];
84
+ const inheritedSource = !(typeof explicit === "string" && explicit.length > 0)
85
+ && registration.source.inherited
86
+ ? inherited?.source
87
+ : undefined;
88
+ const source = typeof explicit === "string" && explicit.length > 0 ? explicit : inheritedSource;
89
+
90
+ return source === undefined
91
+ ? undefined
92
+ : {
93
+ call,
94
+ state: { source, registration },
95
+ ...(inheritedSource === undefined
96
+ ? {}
97
+ : { renderArgumentPatch: { [registration.source.field]: inheritedSource } }),
98
+ };
99
+ },
100
+ buildArguments(calls)
101
+ {
102
+ const edits: TextBatchEntry[] = calls.map(({ call, state }) => ({
103
+ ...call.arguments,
104
+ [state.registration.source.field]: state.source,
105
+ callId: call.id,
106
+ op: state.registration.name,
107
+ path: state.source,
108
+ }));
109
+ return { edits } satisfies TextBatchParams;
110
+ },
111
+ execute: (_toolCallId, params, signal, onUpdate, context, reporter) =>
112
+ executeRegisteredTextBatch(
113
+ core,
114
+ registrations,
115
+ params as unknown as TextBatchParams,
116
+ signal,
117
+ onUpdate,
118
+ context,
119
+ reporter,
120
+ ),
121
+ splitResult: splitTextBatchResult,
122
+ onRenderArguments: renderArguments,
123
+ };
124
+
125
+ core.onMutationTool((registration) =>
126
+ {
127
+ registrations.set(registration.name, registration);
128
+ sourceTools.push(registration.name);
129
+ });
130
+ registerBlockedToolCallSink(pi, registerBlockedToolCall);
131
+ registerToolBatch(pi, definition);
132
+ }
133
+
134
+ export async function executeRegisteredTextBatch(
135
+ core: TextEditorCore,
136
+ registrations: ReadonlyMap<string, AnyTextMutationToolRegistration>,
137
+ params: TextBatchParams,
138
+ signal: AbortSignal | undefined,
139
+ onUpdate: AgentToolUpdateCallback<TextBatchDetails> | undefined,
140
+ context: ExtensionContext,
141
+ reporter: BatchExecutionReporter,
142
+ ): Promise<AgentToolResult<TextBatchDetails>>
143
+ {
144
+ const prepared = params.edits.map((entry) =>
145
+ {
146
+ const registration = registrations.get(entry.op);
147
+
148
+ if (registration === undefined)
149
+ {
150
+ throw new Error(`Unknown text mutation tool: ${entry.op}.`);
151
+ }
152
+
153
+ const { callId, op: _op, ...input } = entry;
154
+ return { callId, input, registration, sources: mutationSources(registration, input) };
155
+ });
156
+ const intents = new Set(prepared.map(({ registration }) => registration.intent ?? "edit"));
157
+ const intent: TextEditIntent = intents.size > 1 ? "mixed" : intents.values().next().value ?? "edit";
158
+ const requests = new Map<string, { source: string; read: true; allowReadFailure?: true; }>();
159
+
160
+ for (const item of prepared)
161
+ {
162
+ for (const source of item.sources.values())
163
+ {
164
+ const current = requests.get(source);
165
+ const allowReadFailure = item.registration.name === "write"
166
+ && source === item.sources.get(item.registration.source.field);
167
+ requests.set(source, {
168
+ source,
169
+ read: true,
170
+ ...(current?.allowReadFailure === true || allowReadFailure ? { allowReadFailure: true } : {}),
171
+ });
172
+ }
173
+
174
+ reporter.start(item.callId);
175
+ }
176
+
177
+ let outcome: TextResourcesEditOutcome<PlannedTextBatch>;
178
+
179
+ try
180
+ {
181
+ outcome = await core.editTexts(
182
+ [...requests.values()],
183
+ { cwd: context.cwd, intent, ...(signal === undefined ? {} : { signal }) },
184
+ async (texts, resolveAnchor) =>
185
+ {
186
+ const mutations: { readonly callId: string; readonly mutation: TextMutation; }[] = [];
187
+ const failures: PlannedTextBatch["failures"][number][] = [];
188
+ const changes = new Map<string, TextChange[]>();
189
+
190
+ for (const item of prepared)
191
+ {
192
+ const sourceFor = (field: string): string =>
193
+ {
194
+ const source = item.sources.get(field);
195
+
196
+ if (source === undefined)
197
+ {
198
+ throw new Error(`Unknown mutation source field ${field}`);
199
+ }
200
+
201
+ return source;
202
+ };
203
+ const documentFor = (source: string): TextChangeDocument =>
204
+ {
205
+ const text = texts.get(source);
206
+
207
+ if (text === undefined)
208
+ {
209
+ throw new Error(`Unknown mutation resource ${source}`);
210
+ }
211
+
212
+ return new TextChangeDocument(text);
213
+ };
214
+ const resolveAnchors = async (field: string) =>
215
+ {
216
+ const descriptor = (item.registration.anchors ?? []).find((anchor) => anchor.field === field);
217
+ const value = item.input[field];
218
+ const source = descriptor === undefined ? undefined : item.sources.get(descriptor.sourceField);
219
+
220
+ if (descriptor === undefined || typeof value !== "string" || source === undefined)
221
+ {
222
+ throw new Error(`Unable to resolve mutation anchor ${field}`);
223
+ }
224
+
225
+ try
226
+ {
227
+ return new Map([[source, await resolveAnchor(source, value, descriptor.kinds)]]);
228
+ }
229
+ catch (error)
230
+ {
231
+ throw contextualizeTextMutationAnchorError(
232
+ error,
233
+ item.registration.name,
234
+ field,
235
+ source,
236
+ value,
237
+ );
238
+ }
239
+ };
240
+
241
+ try
242
+ {
243
+ const mutation = await item.registration.mutate({
244
+ cwd: context.cwd,
245
+ ...(signal === undefined ? {} : { signal }),
246
+ sourceDocument: documentFor(sourceFor(item.registration.source.field)),
247
+ sourceFor,
248
+ documentFor,
249
+ targetDocument: (field) => documentFor(sourceFor(field)),
250
+ resolveAnchors,
251
+ async resolveAnchor(field)
252
+ {
253
+ const resolved = await resolveAnchors(field);
254
+ return resolved.values().next().value!;
255
+ },
256
+ }, item.input);
257
+ mutations.push({ callId: item.callId, mutation });
258
+
259
+ for (const [source, edit] of mutation.edits)
260
+ {
261
+ changes.set(source, [...(changes.get(source) ?? []), ...edit.changes]);
262
+ }
263
+ }
264
+ catch (error)
265
+ {
266
+ failures.push({
267
+ callId: item.callId,
268
+ source: item.sources.get(item.registration.source.field) ?? "",
269
+ error,
270
+ effect: "not-applied",
271
+ });
272
+ }
273
+ }
274
+
275
+ return { changes, result: { mutations, failures } };
276
+ },
277
+ );
278
+ }
279
+ catch (error)
280
+ {
281
+ return failTextBatch(core, prepared.map(({ callId }) => callId), error, context, reporter);
282
+ }
283
+
284
+ if (outcome.kind === "failed")
285
+ {
286
+ return failTextBatch(
287
+ core,
288
+ prepared.map(({ callId }) => callId),
289
+ outcome.failure,
290
+ context,
291
+ reporter,
292
+ );
293
+ }
294
+
295
+ const completedMutations: PlannedTextBatch["mutations"][number][] = [];
296
+ const failures = [...outcome.result.failures];
297
+
298
+ for (const entry of outcome.result.mutations)
299
+ {
300
+ try
301
+ {
302
+ await entry.mutation.afterWrite?.();
303
+ completedMutations.push(entry);
304
+ }
305
+ catch (error)
306
+ {
307
+ failures.push({
308
+ callId: entry.callId,
309
+ source: entry.mutation.edits.keys().next().value ?? "",
310
+ error,
311
+ effect: "applied",
312
+ });
313
+ }
314
+ }
315
+
316
+ const results: FileMutationResult[] = [];
317
+ const callIdsByResult: string[] = [];
318
+
319
+ for (const { callId, mutation } of completedMutations)
320
+ {
321
+ const callResults = [...mutation.edits].flatMap(([source, edit]) =>
322
+ {
323
+ const resource = outcome.resources.find((candidate) => candidate.source === source);
324
+
325
+ if (resource === undefined)
326
+ {
327
+ return [];
328
+ }
329
+
330
+ const ownAfter = applyTextChanges(resource.before.content, edit.changes).content;
331
+ return [buildSuccessfulTextMutationResult(resource, source, edit, ownAfter)];
332
+ });
333
+ const callResult = textBatchResult(callResults, callResults.map(() => callId));
334
+ reporter.complete(callId, callResult);
335
+ results.push(...callResults);
336
+ callIdsByResult.push(...callResults.map(() => callId));
337
+ }
338
+
339
+ for (const failure of failures)
340
+ {
341
+ const failedResult = await buildFailedTextMutationResult(
342
+ core,
343
+ {
344
+ code: failure.effect === "applied" ? "POST_WRITE_FAILED" : "INVALID_REQUEST",
345
+ source: failure.source,
346
+ message: errorMessage(failure.error),
347
+ cause: failure.error,
348
+ },
349
+ context,
350
+ failure.effect,
351
+ );
352
+ const failureResults = failedResult.details.results ?? [];
353
+ reporter.fail(failure.callId, { error: failure.error, effect: failure.effect, result: failedResult });
354
+ results.push(...failureResults);
355
+ callIdsByResult.push(...failureResults.map(() => failure.callId));
356
+ }
357
+
358
+ onUpdate?.({
359
+ content: [{ type: "text", text: "post-edit progress" }],
360
+ details: { results: [...results], callIdsByResult: [...callIdsByResult] },
361
+ });
362
+ return textBatchResult(results, callIdsByResult);
363
+ }
364
+
365
+ async function failTextBatch(
366
+ core: TextEditorCore,
367
+ callIds: readonly string[],
368
+ error: unknown,
369
+ context: ExtensionContext,
370
+ reporter: BatchExecutionReporter,
371
+ ): Promise<AgentToolResult<TextBatchDetails>>
372
+ {
373
+ const cause = error;
374
+ const failure = isTextResourceEditFailure(error)
375
+ ? error
376
+ : {
377
+ code: "INVALID_REQUEST" as const,
378
+ source: "",
379
+ message: errorMessage(cause),
380
+ cause,
381
+ };
382
+ const failedCallId = callIds[0];
383
+ const failedResult = await buildFailedTextMutationResult(core, failure, context);
384
+
385
+ for (const callId of callIds)
386
+ {
387
+ reporter.fail(callId, {
388
+ error: cause,
389
+ effect: "not-applied",
390
+ ...(callId === failedCallId ? { result: failedResult } : {}),
391
+ });
392
+ }
393
+
394
+ const results = failedResult.details.results ?? [];
395
+ return textBatchResult(results, results.map(() => failedCallId ?? ""));
396
+ }
397
+
398
+ function isTextResourceEditFailure(value: unknown): value is TextResourceEditFailure
399
+ {
400
+ return typeof value === "object"
401
+ && value !== null
402
+ && typeof (value as Partial<TextResourceEditFailure>).code === "string"
403
+ && typeof (value as Partial<TextResourceEditFailure>).source === "string"
404
+ && typeof (value as Partial<TextResourceEditFailure>).message === "string";
405
+ }
406
+
407
+ function errorMessage(error: unknown): string
408
+ {
409
+ return error instanceof Error ? error.message : String(error);
410
+ }
411
+
412
+ function textBatchResult(
413
+ results: FileMutationResult[],
414
+ callIdsByResult: string[],
415
+ ): AgentToolResult<TextBatchDetails>
416
+ {
417
+ return {
418
+ content: [new FileMutationAgentResult(results).toTextContent()],
419
+ details: { results, callIdsByResult },
420
+ };
421
+ }
422
+
423
+ export function executeTextToolWithBatch<Result>(
424
+ toolCallId: string,
425
+ execute: () => Promise<AgentToolResult<Result>>,
426
+ signal: AbortSignal | undefined,
427
+ onUpdate: AgentToolUpdateCallback<Result> | undefined,
428
+ context: ExtensionContext,
429
+ ): Promise<AgentToolResult<Result>>
430
+ {
431
+ return executeWithBatchCoordinator(toolCallId, execute, signal, onUpdate, context);
432
+ }