pi-agent-ide 0.1.0 → 0.1.1

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 (511) hide show
  1. package/README.md +31 -9
  2. package/docs/architecture.md +18 -6
  3. package/docs/configuration.md +70 -40
  4. package/docs/development.md +14 -2
  5. package/docs/extensions.md +132 -150
  6. package/docs/generated/tool-catalog/c.md +9 -0
  7. package/docs/generated/tool-catalog/cmake.md +9 -0
  8. package/docs/generated/tool-catalog/cpp.md +9 -0
  9. package/docs/generated/tool-catalog/csharp.md +9 -0
  10. package/docs/generated/tool-catalog/css.md +10 -0
  11. package/docs/generated/tool-catalog/dockerfile.md +9 -0
  12. package/docs/generated/tool-catalog/go.md +10 -0
  13. package/docs/generated/tool-catalog/html.md +9 -0
  14. package/docs/generated/tool-catalog/index.md +30 -0
  15. package/docs/generated/tool-catalog/java.md +9 -0
  16. package/docs/generated/tool-catalog/javascript.md +10 -0
  17. package/docs/generated/tool-catalog/json.md +10 -0
  18. package/docs/generated/tool-catalog/kotlin.md +9 -0
  19. package/docs/generated/tool-catalog/lua.md +9 -0
  20. package/docs/generated/tool-catalog/markdown.md +9 -0
  21. package/docs/generated/tool-catalog/php.md +9 -0
  22. package/docs/generated/tool-catalog/python.md +10 -0
  23. package/docs/generated/tool-catalog/ruby.md +9 -0
  24. package/docs/generated/tool-catalog/rust.md +9 -0
  25. package/docs/generated/tool-catalog/shell.md +9 -0
  26. package/docs/generated/tool-catalog/sql.md +9 -0
  27. package/docs/generated/tool-catalog/swift.md +9 -0
  28. package/docs/generated/tool-catalog/terraform.md +9 -0
  29. package/docs/generated/tool-catalog/toml.md +9 -0
  30. package/docs/generated/tool-catalog/typescript.md +10 -0
  31. package/docs/generated/tool-catalog/xml.md +9 -0
  32. package/docs/generated/tool-catalog/yaml.md +9 -0
  33. package/node_modules/pi-agent-doctor/package.json +26 -0
  34. package/node_modules/pi-agent-doctor/src/catalog.ts +55 -0
  35. package/node_modules/pi-agent-doctor/src/connect-plugin.ts +53 -0
  36. package/node_modules/pi-agent-doctor/src/executable.ts +47 -0
  37. package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +121 -0
  38. package/node_modules/pi-agent-filesystem/index.ts +42 -44
  39. package/node_modules/pi-agent-filesystem/package.json +11 -11
  40. package/node_modules/pi-agent-filesystem/src/resolver.ts +112 -135
  41. package/node_modules/pi-agent-filesystem-image/index.ts +5 -6
  42. package/node_modules/pi-agent-filesystem-image/package.json +8 -8
  43. package/node_modules/pi-agent-filesystem-pdf/index.ts +5 -6
  44. package/node_modules/pi-agent-filesystem-pdf/package.json +5 -5
  45. package/node_modules/pi-agent-filesystem-text/index.ts +11 -12
  46. package/node_modules/pi-agent-filesystem-text/package.json +8 -8
  47. package/node_modules/pi-agent-ide-ast/index.ts +1 -1
  48. package/node_modules/pi-agent-ide-ast/package.json +13 -12
  49. package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
  50. package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +292 -322
  51. package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +591 -656
  52. package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
  53. package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +105 -0
  54. package/node_modules/pi-agent-ide-ast/src/extension.ts +67 -64
  55. package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
  56. package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +168 -185
  57. package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +30 -36
  58. package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +118 -129
  59. package/node_modules/pi-agent-ide-changes/index.ts +53 -51
  60. package/node_modules/pi-agent-ide-changes/package.json +12 -11
  61. package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +68 -78
  62. package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
  63. package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
  64. package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
  65. package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +258 -276
  66. package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
  67. package/node_modules/pi-agent-ide-changes/src/doctor-plugin.ts +29 -0
  68. package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
  69. package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
  70. package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +93 -93
  71. package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +124 -126
  72. package/node_modules/pi-agent-ide-formatter/index.ts +22 -23
  73. package/node_modules/pi-agent-ide-formatter/package.json +5 -2
  74. package/node_modules/pi-agent-ide-formatter/src/catalog.ts +247 -0
  75. package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +104 -0
  76. package/node_modules/pi-agent-ide-formatter/src/formatter.ts +38 -40
  77. package/node_modules/pi-agent-ide-formatter/src/registry.ts +45 -21
  78. package/node_modules/pi-agent-ide-languages/index.ts +24 -0
  79. package/node_modules/pi-agent-ide-languages/package.json +16 -0
  80. package/node_modules/pi-agent-ide-languages/src/languages.ts +84 -0
  81. package/node_modules/pi-agent-ide-lint/index.ts +164 -198
  82. package/node_modules/pi-agent-ide-lint/package.json +8 -7
  83. package/node_modules/pi-agent-ide-lint/src/catalog.ts +283 -0
  84. package/node_modules/pi-agent-ide-lint/src/command-linter.ts +50 -152
  85. package/node_modules/pi-agent-ide-lint/src/diagnostics.ts +180 -0
  86. package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +104 -0
  87. package/node_modules/pi-agent-ide-lint/src/registry.ts +43 -21
  88. package/node_modules/pi-agent-ide-lsp/index.ts +187 -208
  89. package/node_modules/pi-agent-ide-lsp/package.json +12 -11
  90. package/node_modules/pi-agent-ide-lsp/src/catalog.ts +248 -0
  91. package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
  92. package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -0
  93. package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +361 -385
  94. package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +420 -458
  95. package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +128 -137
  96. package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
  97. package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
  98. package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +48 -56
  99. package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +369 -411
  100. package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
  101. package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +153 -70
  102. package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
  103. package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +117 -127
  104. package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
  105. package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +74 -57
  106. package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
  107. package/node_modules/pi-agent-image/package.json +2 -2
  108. package/node_modules/pi-agent-image/src/image-converter.ts +210 -249
  109. package/node_modules/pi-agent-image/src/index.ts +4 -4
  110. package/node_modules/pi-agent-pdf/package.json +2 -2
  111. package/node_modules/pi-agent-pdf/src/index.ts +1 -5
  112. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +130 -153
  113. package/node_modules/pi-agent-read/index.ts +1 -1
  114. package/node_modules/pi-agent-read/package.json +9 -9
  115. package/node_modules/pi-agent-read/src/api/connect-plugin.ts +38 -51
  116. package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +26 -32
  117. package/node_modules/pi-agent-read/src/api/rendering.ts +3 -4
  118. package/node_modules/pi-agent-read/src/api/tools/read.ts +124 -132
  119. package/node_modules/pi-agent-read/src/core/extension.ts +28 -29
  120. package/node_modules/pi-agent-read/src/core/read-core.ts +281 -330
  121. package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +153 -156
  122. package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +294 -316
  123. package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +146 -155
  124. package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
  125. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +644 -693
  126. package/node_modules/pi-agent-resource/package.json +1 -1
  127. package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +50 -62
  128. package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +27 -33
  129. package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +16 -20
  130. package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +52 -57
  131. package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +115 -134
  132. package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +38 -39
  133. package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +117 -107
  134. package/node_modules/pi-agent-resource/src/content.ts +5 -9
  135. package/node_modules/pi-agent-resource/src/index.ts +51 -40
  136. package/node_modules/pi-agent-resource/src/resolver.ts +11 -13
  137. package/node_modules/pi-agent-resource/src/resource.ts +17 -24
  138. package/node_modules/pi-agent-resource/src/validation.ts +106 -92
  139. package/node_modules/pi-agent-search/package.json +7 -7
  140. package/node_modules/pi-agent-search/src/api/connect-plugin.ts +37 -47
  141. package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +26 -30
  142. package/node_modules/pi-agent-search/src/api/search.ts +61 -67
  143. package/node_modules/pi-agent-search/src/core/extension.ts +112 -92
  144. package/node_modules/pi-agent-search/src/core/search-core.ts +330 -359
  145. package/node_modules/pi-agent-search-semantic/index.ts +75 -83
  146. package/node_modules/pi-agent-search-semantic/package.json +5 -5
  147. package/node_modules/pi-agent-search-text/index.ts +40 -38
  148. package/node_modules/pi-agent-search-text/package.json +10 -9
  149. package/node_modules/pi-agent-search-text/src/doctor-plugin.ts +29 -0
  150. package/node_modules/pi-agent-search-text/src/file-search.ts +90 -86
  151. package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +17 -19
  152. package/node_modules/pi-agent-search-text/src/resolvers.ts +152 -157
  153. package/node_modules/pi-agent-search-text/src/ripgrep.ts +16 -0
  154. package/node_modules/pi-agent-search-text/src/search-backend.ts +215 -249
  155. package/node_modules/pi-agent-search-text/src/search-query.ts +85 -108
  156. package/node_modules/pi-agent-search-text/src/search-renderer.ts +310 -334
  157. package/node_modules/pi-agent-search-text/src/search-result.ts +151 -157
  158. package/node_modules/pi-agent-search-text/src/search-session.ts +255 -261
  159. package/node_modules/pi-agent-search-web/index.ts +65 -57
  160. package/node_modules/pi-agent-search-web/package.json +8 -7
  161. package/node_modules/pi-agent-search-web/src/config.ts +470 -409
  162. package/node_modules/pi-agent-search-web/src/doctor-plugin.ts +40 -0
  163. package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +56 -60
  164. package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +60 -68
  165. package/node_modules/pi-agent-search-web/src/providers/request.ts +359 -362
  166. package/node_modules/pi-agent-search-web/src/providers/response.ts +296 -345
  167. package/node_modules/pi-agent-search-web/src/search-format.ts +15 -20
  168. package/node_modules/pi-agent-search-web/src/search.ts +289 -347
  169. package/node_modules/pi-agent-search-web/src/types.ts +99 -111
  170. package/node_modules/pi-agent-text/package.json +2 -2
  171. package/node_modules/pi-agent-text/src/index.ts +30 -22
  172. package/node_modules/pi-agent-text/src/presented-text.ts +15 -17
  173. package/node_modules/pi-agent-text/src/source-line.ts +33 -36
  174. package/node_modules/pi-agent-text/src/text-anchor.ts +120 -117
  175. package/node_modules/pi-agent-text/src/text-converter.ts +71 -84
  176. package/node_modules/pi-agent-text/src/text-document.ts +99 -110
  177. package/node_modules/pi-agent-text-anchor-constant/index.ts +18 -20
  178. package/node_modules/pi-agent-text-anchor-constant/package.json +5 -5
  179. package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +29 -36
  180. package/node_modules/pi-agent-text-anchor-line-hash/index.ts +34 -36
  181. package/node_modules/pi-agent-text-anchor-line-hash/package.json +11 -11
  182. package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +75 -85
  183. package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +35 -42
  184. package/node_modules/pi-agent-text-editor/index.ts +7 -9
  185. package/node_modules/pi-agent-text-editor/package.json +10 -10
  186. package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +16 -18
  187. package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
  188. package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
  189. package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
  190. package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
  191. package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
  192. package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
  193. package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +19 -19
  194. package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +117 -132
  195. package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +155 -141
  196. package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +93 -103
  197. package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
  198. package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +84 -95
  199. package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +9 -9
  200. package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
  201. package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +41 -47
  202. package/node_modules/pi-agent-text-editor/src/core/extension.ts +115 -120
  203. package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +273 -311
  204. package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
  205. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +232 -289
  206. package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +534 -580
  207. package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
  208. package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
  209. package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +282 -336
  210. package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +181 -214
  211. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
  212. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
  213. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
  214. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +367 -372
  215. package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +82 -88
  216. package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +1837 -2035
  217. package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +19 -22
  218. package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +629 -631
  219. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +982 -1031
  220. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
  221. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
  222. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -2
  223. package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
  224. package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +9 -11
  225. package/node_modules/pi-agent-text-editor/src/tools/extension.ts +7 -8
  226. package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +69 -77
  227. package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +109 -95
  228. package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +69 -61
  229. package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +52 -39
  230. package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +121 -115
  231. package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +71 -54
  232. package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +24 -17
  233. package/node_modules/pi-agent-text-editor-argument-order/index.ts +16 -19
  234. package/node_modules/pi-agent-text-editor-argument-order/package.json +4 -4
  235. package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
  236. package/node_modules/pi-agent-text-editor-overwrite/index.ts +297 -323
  237. package/node_modules/pi-agent-text-editor-overwrite/package.json +4 -4
  238. package/node_modules/pi-agent-text-editor-renderer/index.ts +11 -12
  239. package/node_modules/pi-agent-text-editor-renderer/package.json +7 -7
  240. package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
  241. package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +203 -219
  242. package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
  243. package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
  244. package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
  245. package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +170 -182
  246. package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +330 -340
  247. package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +115 -118
  248. package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +3 -4
  249. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +582 -629
  250. package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +144 -167
  251. package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +317 -333
  252. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  253. package/node_modules/pi-agent-tool-call-interception/package.json +1 -1
  254. package/node_modules/pi-agent-tool-call-interception/src/index.ts +334 -354
  255. package/node_modules/pi-agent-web/index.ts +24 -25
  256. package/node_modules/pi-agent-web/package.json +10 -10
  257. package/node_modules/pi-agent-web/src/resolver.ts +133 -155
  258. package/node_modules/pi-agent-web-html/index.ts +5 -6
  259. package/node_modules/pi-agent-web-html/package.json +6 -6
  260. package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +58 -76
  261. package/node_modules/pi-agent-web-html/src/html-converter.ts +62 -75
  262. package/node_modules/pi-agent-web-image/index.ts +5 -6
  263. package/node_modules/pi-agent-web-image/package.json +5 -5
  264. package/node_modules/pi-agent-web-pdf/index.ts +5 -6
  265. package/node_modules/pi-agent-web-pdf/package.json +5 -5
  266. package/node_modules/pi-agent-web-text/index.ts +5 -6
  267. package/node_modules/pi-agent-web-text/package.json +5 -5
  268. package/package.json +72 -52
  269. package/src/api/code-view.ts +17 -17
  270. package/src/api/connect-doctor-plugin.ts +1 -0
  271. package/src/api/connect-plugin.ts +38 -48
  272. package/src/api/doctor.ts +1 -0
  273. package/src/api/plugin-protocol.ts +30 -38
  274. package/src/api/read.ts +6 -1
  275. package/src/api/resource.ts +3 -1
  276. package/src/api/search.ts +5 -1
  277. package/src/api/text-editor.ts +4 -1
  278. package/src/api/text.ts +3 -1
  279. package/src/api/tool-catalog.ts +1 -0
  280. package/src/api/tool-config.ts +365 -0
  281. package/src/api/toolchain.ts +18 -18
  282. package/src/code-view/diagnostic-view.ts +59 -58
  283. package/src/code-view/reference.ts +64 -82
  284. package/src/code-view/source-view.ts +159 -180
  285. package/src/composite/builtin-extensions.ts +39 -35
  286. package/src/composite/config.ts +75 -69
  287. package/src/composite/selection.ts +54 -52
  288. package/src/core/extension.ts +32 -36
  289. package/src/core/ide-core.ts +76 -93
  290. package/src/doctor/config-writer.ts +115 -0
  291. package/src/doctor/core.ts +174 -0
  292. package/src/doctor/discovery.ts +215 -0
  293. package/src/doctor/extension.ts +108 -0
  294. package/src/doctor/index.ts +1 -0
  295. package/src/doctor/inventory.ts +91 -0
  296. package/src/doctor/run.ts +196 -0
  297. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +42 -44
  298. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +11 -11
  299. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +5 -6
  300. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +8 -8
  301. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +5 -6
  302. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +5 -5
  303. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +11 -12
  304. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +8 -8
  305. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +112 -135
  306. package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +24 -25
  307. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +10 -10
  308. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +5 -6
  309. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +6 -6
  310. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +58 -76
  311. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +62 -75
  312. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +5 -6
  313. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +5 -5
  314. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +5 -6
  315. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +5 -5
  316. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +5 -6
  317. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +5 -5
  318. package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +133 -155
  319. package/src/extensions/pi-agent-read/index.ts +1 -1
  320. package/src/extensions/pi-agent-read/package.json +9 -9
  321. package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +38 -51
  322. package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +26 -32
  323. package/src/extensions/pi-agent-read/src/api/rendering.ts +3 -4
  324. package/src/extensions/pi-agent-read/src/api/tools/read.ts +124 -132
  325. package/src/extensions/pi-agent-read/src/core/extension.ts +28 -29
  326. package/src/extensions/pi-agent-read/src/core/read-core.ts +281 -330
  327. package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +153 -156
  328. package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +294 -316
  329. package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +146 -155
  330. package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
  331. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +644 -693
  332. package/src/extensions/pi-agent-search/package.json +7 -7
  333. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +75 -83
  334. package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +5 -5
  335. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +40 -38
  336. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -9
  337. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/doctor-plugin.ts +29 -0
  338. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +90 -86
  339. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +17 -19
  340. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +152 -157
  341. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +16 -0
  342. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +215 -249
  343. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +85 -108
  344. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +310 -334
  345. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +151 -157
  346. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +255 -261
  347. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +65 -57
  348. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +8 -7
  349. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +470 -409
  350. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/doctor-plugin.ts +40 -0
  351. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +56 -60
  352. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +60 -68
  353. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +359 -362
  354. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +296 -345
  355. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +15 -20
  356. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +289 -347
  357. package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +99 -111
  358. package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +37 -47
  359. package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +26 -30
  360. package/src/extensions/pi-agent-search/src/api/search.ts +61 -67
  361. package/src/extensions/pi-agent-search/src/core/extension.ts +112 -92
  362. package/src/extensions/pi-agent-search/src/core/search-core.ts +330 -359
  363. package/src/extensions/pi-agent-text-editor/index.ts +7 -9
  364. package/src/extensions/pi-agent-text-editor/package.json +10 -10
  365. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +18 -20
  366. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +5 -5
  367. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +29 -36
  368. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +34 -36
  369. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +11 -11
  370. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +75 -85
  371. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +35 -42
  372. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +16 -19
  373. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +4 -4
  374. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
  375. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +297 -323
  376. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +4 -4
  377. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +11 -12
  378. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +7 -7
  379. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
  380. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +203 -219
  381. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
  382. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
  383. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
  384. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +170 -182
  385. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +330 -340
  386. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +115 -118
  387. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +3 -4
  388. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +582 -629
  389. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +144 -167
  390. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +317 -333
  391. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  392. package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +16 -18
  393. package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
  394. package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
  395. package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
  396. package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
  397. package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
  398. package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
  399. package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +19 -19
  400. package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +117 -132
  401. package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +155 -141
  402. package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +93 -103
  403. package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
  404. package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +84 -95
  405. package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +9 -9
  406. package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
  407. package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +41 -47
  408. package/src/extensions/pi-agent-text-editor/src/core/extension.ts +115 -120
  409. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +273 -311
  410. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
  411. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +232 -289
  412. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +534 -580
  413. package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
  414. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
  415. package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +282 -336
  416. package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +181 -214
  417. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
  418. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
  419. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
  420. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +367 -372
  421. package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +82 -88
  422. package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +1837 -2035
  423. package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +19 -22
  424. package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +629 -631
  425. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +982 -1031
  426. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
  427. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
  428. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -2
  429. package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
  430. package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +9 -11
  431. package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +7 -8
  432. package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +69 -77
  433. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +109 -95
  434. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +69 -61
  435. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +52 -39
  436. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +121 -115
  437. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +71 -54
  438. package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +24 -17
  439. package/src/pi-agent-ide.ts +10 -10
  440. package/src/plugins/pi-agent-ide-ast/index.ts +1 -1
  441. package/src/plugins/pi-agent-ide-ast/package.json +13 -12
  442. package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
  443. package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +292 -322
  444. package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +591 -656
  445. package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
  446. package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +105 -0
  447. package/src/plugins/pi-agent-ide-ast/src/extension.ts +67 -64
  448. package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
  449. package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +168 -185
  450. package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +30 -36
  451. package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +118 -129
  452. package/src/plugins/pi-agent-ide-changes/index.ts +53 -51
  453. package/src/plugins/pi-agent-ide-changes/package.json +12 -11
  454. package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +68 -78
  455. package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
  456. package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
  457. package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
  458. package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +258 -276
  459. package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
  460. package/src/plugins/pi-agent-ide-changes/src/doctor-plugin.ts +29 -0
  461. package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
  462. package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
  463. package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +93 -93
  464. package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +124 -126
  465. package/src/plugins/pi-agent-ide-formatter/index.ts +22 -23
  466. package/src/plugins/pi-agent-ide-formatter/package.json +5 -2
  467. package/src/plugins/pi-agent-ide-formatter/src/catalog.ts +247 -0
  468. package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +104 -0
  469. package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +38 -40
  470. package/src/plugins/pi-agent-ide-formatter/src/registry.ts +45 -21
  471. package/src/plugins/pi-agent-ide-languages/index.ts +24 -0
  472. package/src/plugins/pi-agent-ide-languages/package.json +16 -0
  473. package/src/plugins/pi-agent-ide-languages/src/languages.ts +84 -0
  474. package/src/plugins/pi-agent-ide-lint/index.ts +164 -198
  475. package/src/plugins/pi-agent-ide-lint/package.json +8 -7
  476. package/src/plugins/pi-agent-ide-lint/src/catalog.ts +283 -0
  477. package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +50 -152
  478. package/src/plugins/pi-agent-ide-lint/src/diagnostics.ts +180 -0
  479. package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +104 -0
  480. package/src/plugins/pi-agent-ide-lint/src/registry.ts +43 -21
  481. package/src/plugins/pi-agent-ide-lsp/index.ts +187 -208
  482. package/src/plugins/pi-agent-ide-lsp/package.json +12 -11
  483. package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +248 -0
  484. package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
  485. package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -0
  486. package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +361 -385
  487. package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +420 -458
  488. package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +128 -137
  489. package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
  490. package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
  491. package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +48 -56
  492. package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +369 -411
  493. package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
  494. package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +153 -70
  495. package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
  496. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +117 -127
  497. package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
  498. package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +74 -57
  499. package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
  500. package/src/post-edit/gate.ts +114 -122
  501. package/src/toolchain/diagnostic.ts +3 -4
  502. package/src/toolchain/gate.ts +278 -295
  503. package/src/toolchain/registry.ts +143 -165
  504. package/src/toolchain/types.ts +126 -103
  505. package/src/utils/required-value.ts +8 -0
  506. package/node_modules/pi-agent-ide-formatter/src/types.ts +0 -10
  507. package/node_modules/pi-agent-ide-lint/src/command-runner.ts +0 -51
  508. package/node_modules/pi-agent-ide-lint/src/types.ts +0 -10
  509. package/src/plugins/pi-agent-ide-formatter/src/types.ts +0 -10
  510. package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +0 -51
  511. package/src/plugins/pi-agent-ide-lint/src/types.ts +0 -10
@@ -1,607 +1,572 @@
1
+ import { requiredValue } from "../../../../utils/required-value.js";
1
2
  import { BatchExecutionJournal, type BatchExecutionReporter } from "./text-edit-batch-execution.js";
2
3
 
3
4
  import type { BlockedToolCall, ToolBatchRecoveryDefinition } from "./text-edit-batch-recovery.js";
4
5
  import type {
5
- AgentToolResult,
6
- AgentToolUpdateCallback,
7
- ExtensionAPI,
8
- ExtensionContext,
6
+ AgentToolResult,
7
+ AgentToolUpdateCallback,
8
+ ExtensionAPI,
9
+ ExtensionContext,
9
10
  } from "@earendil-works/pi-coding-agent";
10
11
 
11
- function isObjectNotArray(value: unknown): value is Record<string, unknown>
12
- {
13
- return typeof value === "object" && value !== null && !Array.isArray(value);
12
+ function isObjectNotArray(value: unknown): value is Record<string, unknown> {
13
+ return typeof value === "object" && value !== null && !Array.isArray(value);
14
14
  }
15
15
 
16
- export interface OriginalToolCall
17
- {
18
- readonly id: string;
19
- readonly name: string;
20
- readonly arguments: Record<string, unknown>;
16
+ export interface OriginalToolCall {
17
+ readonly id: string;
18
+ readonly name: string;
19
+ readonly arguments: Record<string, unknown>;
21
20
  }
22
21
 
23
- export interface BatchCallCandidate<TState = unknown>
24
- {
25
- readonly call: OriginalToolCall;
26
- readonly state: TState;
27
- readonly renderArgumentPatch?: Readonly<Record<string, unknown>>;
22
+ export interface BatchCallCandidate<TState = unknown> {
23
+ readonly call: OriginalToolCall;
24
+ readonly state: TState;
25
+ readonly renderArgumentPatch?: Readonly<Record<string, unknown>>;
28
26
  }
29
27
 
30
- export interface ToolBatchDefinition<TState = unknown>
31
- {
32
- readonly sourceTools: readonly string[];
33
- readonly syntheticTool: string;
34
- readonly resolveCall: (
35
- call: OriginalToolCall,
36
- inheritedState: TState | undefined,
37
- ) => BatchCallCandidate<TState> | undefined;
38
- readonly buildArguments: (calls: readonly BatchCallCandidate<TState>[]) => Record<string, unknown>;
39
- readonly execute: (
40
- toolCallId: string,
41
- params: Record<string, unknown>,
42
- signal: AbortSignal | undefined,
43
- onUpdate: AgentToolUpdateCallback<unknown> | undefined,
44
- ctx: ExtensionContext,
45
- reporter: BatchExecutionReporter,
46
- ) => Promise<AgentToolResult<unknown>>;
47
- readonly splitResult?: (
48
- aggregate: AgentToolResult<unknown>,
49
- calls: readonly OriginalToolCall[],
50
- candidates: readonly BatchCallCandidate<TState>[],
51
- ) => ReadonlyMap<string, AgentToolResult<unknown>>;
52
- readonly onRenderArguments?: (
53
- toolCallId: string,
54
- patch: Readonly<Record<string, unknown>>,
55
- ) => void;
56
- readonly recovery?: ToolBatchRecoveryDefinition<TState>;
28
+ export interface ToolBatchDefinition<TState = unknown> {
29
+ readonly sourceTools: readonly string[];
30
+ readonly syntheticTool: string;
31
+ readonly resolveCall: (
32
+ call: OriginalToolCall,
33
+ inheritedState: TState | undefined,
34
+ ) => BatchCallCandidate<TState> | undefined;
35
+ readonly buildArguments: (
36
+ calls: readonly BatchCallCandidate<TState>[],
37
+ ) => Record<string, unknown>;
38
+ readonly execute: (
39
+ toolCallId: string,
40
+ parameters: Record<string, unknown>,
41
+ signal: AbortSignal | undefined,
42
+ onUpdate: AgentToolUpdateCallback<unknown> | undefined,
43
+ context: ExtensionContext,
44
+ reporter: BatchExecutionReporter,
45
+ ) => Promise<AgentToolResult<unknown>>;
46
+ readonly splitResult?: (
47
+ aggregate: AgentToolResult<unknown>,
48
+ calls: readonly OriginalToolCall[],
49
+ candidates: readonly BatchCallCandidate<TState>[],
50
+ ) => ReadonlyMap<string, AgentToolResult<unknown>>;
51
+ readonly onRenderArguments?: (
52
+ toolCallId: string,
53
+ patch: Readonly<Record<string, unknown>>,
54
+ ) => void;
55
+ readonly recovery?: ToolBatchRecoveryDefinition<TState>;
57
56
  }
58
57
 
59
- interface RawToolCall
60
- {
61
- readonly id: string;
62
- readonly name: string;
63
- readonly arguments: Record<string, unknown>;
58
+ interface RawToolCall {
59
+ readonly id: string;
60
+ readonly name: string;
61
+ readonly arguments: Record<string, unknown>;
64
62
  }
65
63
 
66
- interface CoordinatorState
67
- {
68
- readonly definitions: ToolBatchDefinition[];
69
- registered: boolean;
70
- nextBatchId: number;
64
+ interface CoordinatorState {
65
+ readonly definitions: ToolBatchDefinition[];
66
+ registered: boolean;
67
+ nextBatchId: number;
71
68
  }
72
69
 
73
- interface BatchExecution
74
- {
75
- readonly aggregate?: AgentToolResult<unknown>;
76
- readonly perCallResults?: ReadonlyMap<string, AgentToolResult<unknown>>;
70
+ interface BatchExecution {
71
+ readonly aggregate?: AgentToolResult<unknown>;
72
+ readonly perCallResults?: ReadonlyMap<string, AgentToolResult<unknown>>;
77
73
  }
78
74
 
79
- interface BatchPlan
80
- {
81
- readonly definition: ToolBatchDefinition;
82
- readonly candidates: readonly BatchCallCandidate[];
83
- readonly calls: readonly OriginalToolCall[];
84
- readonly carrierId: string;
85
- readonly batchId: string;
86
- readonly remainingCallIds: Set<string>;
87
- readonly journal: BatchExecutionJournal;
88
- readonly blockedCalls: BlockedToolCall[];
89
- execution?: Promise<BatchExecution>;
75
+ interface BatchPlan {
76
+ readonly definition: ToolBatchDefinition;
77
+ readonly candidates: readonly BatchCallCandidate[];
78
+ readonly calls: readonly OriginalToolCall[];
79
+ readonly carrierId: string;
80
+ readonly batchId: string;
81
+ readonly remainingCallIds: Set<string>;
82
+ readonly journal: BatchExecutionJournal;
83
+ readonly blockedCalls: BlockedToolCall[];
84
+ execution?: Promise<BatchExecution>;
90
85
  }
91
86
 
92
87
  const batchPlans = new Map<string, BatchPlan>();
93
88
  const coordinators = new WeakMap<object, CoordinatorState>();
94
89
  const blockedToolCalls = new Map<string, BlockedToolCall>();
95
90
 
96
- export function registerBlockedToolCall(blocked: BlockedToolCall): void
97
- {
98
- blockedToolCalls.set(blocked.callId, blocked);
99
- const plan = batchPlans.get(blocked.callId);
91
+ export function registerBlockedToolCall(blocked: BlockedToolCall): void {
92
+ blockedToolCalls.set(blocked.callId, blocked);
93
+ const plan = batchPlans.get(blocked.callId);
100
94
 
101
- if (plan && !plan.blockedCalls.some((item) => item.callId === blocked.callId))
102
- {
103
- plan.blockedCalls.push(blocked);
104
- plan.journal.block(blocked.callId, blocked.result, blocked.details);
105
- }
95
+ if (plan?.blockedCalls.every((item) => item.callId !== blocked.callId)) {
96
+ plan.blockedCalls.push(blocked);
97
+ plan.journal.block(blocked.callId, blocked.result, blocked.details);
98
+ }
106
99
  }
107
100
 
108
- function clearCoordinatorCalls(): void
109
- {
110
- batchPlans.clear();
111
- blockedToolCalls.clear();
101
+ function clearCoordinatorCalls(): void {
102
+ batchPlans.clear();
103
+ blockedToolCalls.clear();
112
104
  }
113
105
 
114
- function asRawToolCall(value: unknown): RawToolCall | undefined
115
- {
116
- if (
117
- !isObjectNotArray(value) || value.type !== "toolCall" || typeof value.id !== "string"
118
- || typeof value.name !== "string"
119
- )
120
- {
121
- return undefined;
122
- }
106
+ function asRawToolCall(value: unknown): RawToolCall | undefined {
107
+ if (
108
+ !isObjectNotArray(value) ||
109
+ value.type !== "toolCall" ||
110
+ typeof value.id !== "string" ||
111
+ typeof value.name !== "string"
112
+ ) {
113
+ return undefined;
114
+ }
123
115
 
124
- if (!isObjectNotArray(value.arguments))
125
- {
126
- return undefined;
127
- }
116
+ if (!isObjectNotArray(value.arguments)) {
117
+ return undefined;
118
+ }
128
119
 
129
- return { id: value.id, name: value.name, arguments: value.arguments };
120
+ return { id: value.id, name: value.name, arguments: value.arguments };
130
121
  }
131
122
 
132
- function definitionFor(state: CoordinatorState, name: string): ToolBatchDefinition | undefined
133
- {
134
- return state.definitions.find((definition) => definition.sourceTools.includes(name));
123
+ function definitionFor(state: CoordinatorState, name: string): ToolBatchDefinition | undefined {
124
+ return state.definitions.find((definition) => definition.sourceTools.includes(name));
135
125
  }
136
126
 
137
- function publishRenderArguments(definition: ToolBatchDefinition, candidate: BatchCallCandidate): void
138
- {
139
- if (candidate.renderArgumentPatch !== undefined)
140
- {
141
- definition.onRenderArguments?.(candidate.call.id, candidate.renderArgumentPatch);
142
- }
127
+ function publishRenderArguments(
128
+ definition: ToolBatchDefinition,
129
+ candidate: BatchCallCandidate,
130
+ ): void {
131
+ if (candidate.renderArgumentPatch !== undefined) {
132
+ definition.onRenderArguments?.(candidate.call.id, candidate.renderArgumentPatch);
133
+ }
143
134
  }
144
135
 
145
- function rewriteMessage(state: CoordinatorState, message: unknown, createPlans: boolean): unknown
146
- {
147
- if (!isObjectNotArray(message) || message.role !== "assistant" || !Array.isArray(message.content))
148
- {
149
- return undefined;
136
+ function rewriteMessage(state: CoordinatorState, message: unknown, createPlans: boolean): unknown {
137
+ if (
138
+ !isObjectNotArray(message) ||
139
+ message.role !== "assistant" ||
140
+ !Array.isArray(message.content)
141
+ ) {
142
+ return undefined;
143
+ }
144
+
145
+ const content = message.content;
146
+ let inheritedDefinition: ToolBatchDefinition | undefined;
147
+ let inheritedState: unknown;
148
+
149
+ for (let index = 0; index < content.length;) {
150
+ const first = asRawToolCall(content[index]);
151
+ const definition = first ? definitionFor(state, first.name) : undefined;
152
+ const firstCandidate =
153
+ first && definition
154
+ ? definition.resolveCall(
155
+ first,
156
+ inheritedDefinition === definition ? inheritedState : undefined,
157
+ )
158
+ : undefined;
159
+
160
+ if (!definition || !firstCandidate) {
161
+ inheritedDefinition = undefined;
162
+ inheritedState = undefined;
163
+ index += 1;
164
+ continue;
150
165
  }
151
166
 
152
- const content = message.content;
153
- let inheritedDefinition: ToolBatchDefinition | undefined;
154
- let inheritedState: unknown;
155
-
156
- for (let index = 0; index < content.length;)
157
- {
158
- const first = asRawToolCall(content[index]);
159
- const definition = first ? definitionFor(state, first.name) : undefined;
160
- const firstCandidate = first && definition
161
- ? definition.resolveCall(
162
- first,
163
- inheritedDefinition === definition ? inheritedState : undefined,
164
- )
165
- : undefined;
166
-
167
- if (!definition || !firstCandidate)
168
- {
169
- inheritedDefinition = undefined;
170
- inheritedState = undefined;
171
- index += 1;
172
- continue;
173
- }
174
-
175
- publishRenderArguments(definition, firstCandidate);
176
-
177
- const run: BatchCallCandidate[] = [firstCandidate];
178
- let nextIndex = index + 1;
167
+ publishRenderArguments(definition, firstCandidate);
179
168
 
180
- while (nextIndex < content.length)
181
- {
182
- const next = asRawToolCall(content[nextIndex]);
183
-
184
- if (!next || definitionFor(state, next.name) !== definition)
185
- {
186
- break;
187
- }
169
+ const run: BatchCallCandidate[] = [firstCandidate];
170
+ let nextIndex = index + 1;
188
171
 
189
- const candidate = definition.resolveCall(next, run.at(-1)!.state);
172
+ while (nextIndex < content.length) {
173
+ const next = asRawToolCall(content[nextIndex]);
190
174
 
191
- if (!candidate)
192
- {
193
- break;
194
- }
175
+ if (!next || definitionFor(state, next.name) !== definition) {
176
+ break;
177
+ }
195
178
 
196
- publishRenderArguments(definition, candidate);
197
- run.push(candidate);
198
- nextIndex += 1;
199
- }
179
+ const candidate = definition.resolveCall(next, requiredValue(run.at(-1)).state);
200
180
 
201
- const last = run.at(-1)!;
181
+ if (!candidate) {
182
+ break;
183
+ }
202
184
 
203
- if (createPlans && run.length >= 2)
204
- {
205
- const calls = run.map(({ call }) => call);
206
- const journal = new BatchExecutionJournal(calls.map((call) => call.id));
207
- const blockedCalls = calls.flatMap((call) =>
208
- {
209
- const blocked = blockedToolCalls.get(call.id);
210
- return blocked === undefined ? [] : [blocked];
211
- });
212
- const plan: BatchPlan = {
213
- definition,
214
- candidates: run,
215
- calls,
216
- carrierId: last.call.id,
217
- batchId: `${String(Date.now())}-${String(state.nextBatchId++)}`,
218
- remainingCallIds: new Set(calls.map((call) => call.id)),
219
- journal,
220
- blockedCalls,
221
- };
222
-
223
- for (const blocked of blockedCalls)
224
- {
225
- journal.block(blocked.callId, blocked.result, blocked.details);
226
- }
227
-
228
- for (const call of calls)
229
- {
230
- batchPlans.set(call.id, plan);
231
- }
232
- }
185
+ publishRenderArguments(definition, candidate);
186
+ run.push(candidate);
187
+ nextIndex += 1;
188
+ }
233
189
 
234
- inheritedDefinition = definition;
235
- inheritedState = last.state;
236
- index = nextIndex;
190
+ const last = requiredValue(run.at(-1));
191
+
192
+ if (createPlans && run.length >= 2) {
193
+ const calls = run.map(({ call }) => call);
194
+ const journal = new BatchExecutionJournal(calls.map((call) => call.id));
195
+ const blockedCalls = calls.flatMap((call) => {
196
+ const blocked = blockedToolCalls.get(call.id);
197
+ return blocked === undefined ? [] : [blocked];
198
+ });
199
+ const plan: BatchPlan = {
200
+ definition,
201
+ candidates: run,
202
+ calls,
203
+ carrierId: last.call.id,
204
+ batchId: `${String(Date.now())}-${String(state.nextBatchId++)}`,
205
+ remainingCallIds: new Set(calls.map((call) => call.id)),
206
+ journal,
207
+ blockedCalls,
208
+ };
209
+
210
+ for (const blocked of blockedCalls) {
211
+ journal.block(blocked.callId, blocked.result, blocked.details);
212
+ }
213
+
214
+ for (const call of calls) {
215
+ batchPlans.set(call.id, plan);
216
+ }
237
217
  }
238
218
 
239
- // Keep the assistant message exactly as produced by the model. The batch
240
- // exists only in the execution plan, never as a persisted synthetic call.
241
- return undefined;
242
- }
219
+ inheritedDefinition = definition;
220
+ inheritedState = last.state;
221
+ index = nextIndex;
222
+ }
243
223
 
244
- function filterProviderTools(state: CoordinatorState, event: { payload?: unknown; }): unknown
245
- {
246
- const payload = event.payload;
224
+ // Keep the assistant message exactly as produced by the model. The batch
225
+ // exists only in the execution plan, never as a persisted synthetic call.
226
+ return undefined;
227
+ }
247
228
 
248
- if (!isObjectNotArray(payload) || !Array.isArray(payload.tools))
249
- {
250
- return undefined;
251
- }
229
+ function filterProviderTools(state: CoordinatorState, event: { payload?: unknown }): unknown {
230
+ const payload = event.payload;
252
231
 
253
- const syntheticTools = new Set(state.definitions.map((definition) => definition.syntheticTool));
254
- return {
255
- ...payload,
256
- tools: payload.tools.filter((tool) =>
257
- {
258
- if (!isObjectNotArray(tool))
259
- {
260
- return true;
261
- }
262
-
263
- const toolName = typeof tool.name === "string" ? tool.name : undefined;
264
- const functionName = isObjectNotArray(tool.function) && typeof tool.function.name === "string"
265
- ? tool.function.name
266
- : undefined;
267
-
268
- if (toolName === undefined && functionName === undefined)
269
- {
270
- return true;
271
- }
272
-
273
- return (toolName === undefined || !syntheticTools.has(toolName))
274
- && (functionName === undefined || !syntheticTools.has(functionName));
275
- }),
276
- };
232
+ if (!isObjectNotArray(payload) || !Array.isArray(payload.tools)) {
233
+ return undefined;
234
+ }
235
+
236
+ const syntheticTools = new Set(state.definitions.map((definition) => definition.syntheticTool));
237
+ return {
238
+ ...payload,
239
+ tools: payload.tools.filter((tool) => {
240
+ if (!isObjectNotArray(tool)) {
241
+ return true;
242
+ }
243
+
244
+ const toolName = typeof tool.name === "string" ? tool.name : undefined;
245
+ const functionName =
246
+ isObjectNotArray(tool.function) && typeof tool.function.name === "string"
247
+ ? tool.function.name
248
+ : undefined;
249
+
250
+ if (toolName === undefined && functionName === undefined) {
251
+ return true;
252
+ }
253
+
254
+ return (
255
+ (toolName === undefined || !syntheticTools.has(toolName)) &&
256
+ (functionName === undefined || !syntheticTools.has(functionName))
257
+ );
258
+ }),
259
+ };
277
260
  }
278
261
 
279
- interface BatchDisplayCall
280
- {
281
- readonly id: string;
282
- readonly name: string;
262
+ interface BatchDisplayCall {
263
+ readonly id: string;
264
+ readonly name: string;
283
265
  }
284
266
 
285
267
  function markBatchResult<TDetails>(
286
- result: AgentToolResult<TDetails>,
287
- batchId: string,
288
- calls: readonly BatchDisplayCall[],
289
- ): AgentToolResult<TDetails>
290
- {
291
- const details = isObjectNotArray(result.details) ? result.details : {};
292
- return { ...result, details: { ...details, agenticIdeBatch: { batchId, calls } } as TDetails };
268
+ result: AgentToolResult<TDetails>,
269
+ batchId: string,
270
+ calls: readonly BatchDisplayCall[],
271
+ ): AgentToolResult<TDetails> {
272
+ const details = isObjectNotArray(result.details) ? result.details : {};
273
+ return { ...result, details: { ...details, agenticIdeBatch: { batchId, calls } } as TDetails };
293
274
  }
294
275
 
295
- function batchDisplayCalls(plan: BatchPlan): BatchDisplayCall[]
296
- {
297
- return plan.calls.map((call) => ({ id: call.id, name: call.name }));
276
+ function batchDisplayCalls(plan: BatchPlan): BatchDisplayCall[] {
277
+ return plan.calls.map((call) => ({ id: call.id, name: call.name }));
298
278
  }
299
279
 
300
280
  function ensureBatchExecution(
301
- plan: BatchPlan,
302
- signal: AbortSignal | undefined,
303
- onUpdate: AgentToolUpdateCallback<unknown> | undefined,
304
- ctx: ExtensionContext,
305
- ): Promise<BatchExecution>
306
- {
307
- plan.execution ??= (async () =>
308
- {
309
- let aggregate: AgentToolResult<unknown> | undefined;
310
- let executionError: unknown;
311
-
312
- try
313
- {
314
- const executable = plan.candidates.filter(({ call }) => plan.journal.get(call.id).state !== "blocked");
315
- const params = plan.definition.buildArguments(executable);
316
- aggregate = await plan.definition.execute(
317
- plan.carrierId,
318
- params,
319
- signal,
320
- onUpdate,
321
- ctx,
322
- plan.journal.reporter(),
323
- );
324
- const split = plan.definition.splitResult?.(aggregate, plan.calls, plan.candidates);
325
-
326
- for (const [callId, result] of split ?? [])
327
- {
328
- if (plan.journal.get(callId).state === "completed")
329
- {
330
- plan.journal.reporter().complete(callId, result);
331
- }
332
- }
333
- }
334
- catch (error)
335
- {
336
- executionError = error;
337
- plan.journal.markRunningUnknown(error);
281
+ plan: BatchPlan,
282
+ signal: AbortSignal | undefined,
283
+ onUpdate: AgentToolUpdateCallback<unknown> | undefined,
284
+ context: ExtensionContext,
285
+ ): Promise<BatchExecution> {
286
+ plan.execution ??= (async () => {
287
+ let aggregate: AgentToolResult<unknown> | undefined;
288
+ let executionError: unknown;
289
+
290
+ try {
291
+ const executable = plan.candidates.filter(
292
+ ({ call }) => plan.journal.get(call.id).state !== "blocked",
293
+ );
294
+ const parameters = plan.definition.buildArguments(executable);
295
+ aggregate = await plan.definition.execute(
296
+ plan.carrierId,
297
+ parameters,
298
+ signal,
299
+ onUpdate,
300
+ context,
301
+ plan.journal.reporter(),
302
+ );
303
+ const split = plan.definition.splitResult?.(aggregate, plan.calls, plan.candidates);
304
+
305
+ for (const [callId, result] of split ?? []) {
306
+ if (plan.journal.get(callId).state === "completed") {
307
+ plan.journal.reporter().complete(callId, result);
338
308
  }
309
+ }
310
+ } catch (error) {
311
+ executionError = error;
312
+ plan.journal.markRunningUnknown(error);
313
+ }
339
314
 
340
- await recoverBatch(plan, signal, ctx);
341
- const perCallResults = finalBatchResults(plan, executionError);
342
- return aggregate === undefined ? { perCallResults } : { aggregate, perCallResults };
343
- })();
315
+ await recoverBatch(plan, signal, context);
316
+ const perCallResults = finalBatchResults(plan, executionError);
317
+ return aggregate === undefined ? { perCallResults } : { aggregate, perCallResults };
318
+ })();
344
319
 
345
- return plan.execution;
320
+ return plan.execution;
346
321
  }
347
322
 
348
- async function recoverBatch(plan: BatchPlan, signal: AbortSignal | undefined, ctx: ExtensionContext): Promise<void>
349
- {
350
- const recovery = plan.definition.recovery;
351
-
352
- if (!recovery)
353
- {
354
- return;
355
- }
356
-
357
- const input = {
358
- batchId: plan.batchId,
359
- calls: plan.calls,
360
- candidates: plan.candidates,
361
- journal: plan.journal.snapshot(),
362
- blockedCalls: plan.blockedCalls,
363
- cwd: ctx.cwd,
364
- signal,
365
- ctx,
366
- };
367
- const requested = new Set(recovery.select(input));
368
- const selected = plan.candidates.filter(({ call }) =>
369
- {
370
- const state = plan.journal.get(call.id).state;
371
- return requested.has(call.id) && (state === "pending" || state === "failed-not-applied");
323
+ async function recoverBatch(
324
+ plan: BatchPlan,
325
+ signal: AbortSignal | undefined,
326
+ context: ExtensionContext,
327
+ ): Promise<void> {
328
+ const recovery = plan.definition.recovery;
329
+
330
+ if (!recovery) {
331
+ return;
332
+ }
333
+
334
+ const input = {
335
+ batchId: plan.batchId,
336
+ calls: plan.calls,
337
+ candidates: plan.candidates,
338
+ journal: plan.journal.snapshot(),
339
+ blockedCalls: plan.blockedCalls,
340
+ cwd: context.cwd,
341
+ signal,
342
+ ctx: context,
343
+ };
344
+ const requested = new Set(recovery.select(input));
345
+ const selected = plan.candidates.filter(({ call }) => {
346
+ const state = plan.journal.get(call.id).state;
347
+ return requested.has(call.id) && (state === "pending" || state === "failed-not-applied");
348
+ });
349
+
350
+ if (selected.length === 0) {
351
+ return;
352
+ }
353
+
354
+ try {
355
+ const outcome = await recovery.execute({
356
+ ...input,
357
+ selected,
358
+ reporter: plan.journal.reporter(true),
372
359
  });
373
360
 
374
- if (selected.length === 0)
375
- {
376
- return;
361
+ for (const [callId, result] of outcome.results) {
362
+ if (selected.some(({ call }) => call.id === callId)) {
363
+ plan.journal.reporter(true).complete(callId, result);
364
+ } else if (plan.journal.get(callId).state === "completed") {
365
+ plan.journal.reporter().complete(callId, result);
366
+ }
377
367
  }
378
368
 
379
- try
380
- {
381
- const outcome = await recovery.execute({
382
- ...input,
383
- selected,
384
- reporter: plan.journal.reporter(true),
385
- });
386
-
387
- for (const [callId, result] of outcome.results)
388
- {
389
- if (selected.some(({ call }) => call.id === callId))
390
- {
391
- plan.journal.reporter(true).complete(callId, result);
392
- }
393
- else if (plan.journal.get(callId).state === "completed")
394
- {
395
- plan.journal.reporter().complete(callId, result);
396
- }
397
- }
398
-
399
- for (const [callId, reason] of outcome.skipped ?? [])
400
- {
401
- plan.journal.skip(callId, reason);
402
- }
369
+ for (const [callId, reason] of outcome.skipped ?? []) {
370
+ plan.journal.skip(callId, reason);
403
371
  }
404
- catch (error)
405
- {
406
- for (const { call } of selected)
407
- {
408
- const state = plan.journal.get(call.id).state;
409
-
410
- if (state === "pending" || state === "running" || state === "failed-not-applied")
411
- {
412
- plan.journal.reporter(true).fail(call.id, {
413
- error,
414
- effect: state === "running" ? "unknown" : "not-applied",
415
- });
416
- }
417
- }
372
+ } catch (error) {
373
+ for (const { call } of selected) {
374
+ const state = plan.journal.get(call.id).state;
375
+
376
+ if (state === "pending" || state === "running" || state === "failed-not-applied") {
377
+ plan.journal.reporter(true).fail(call.id, {
378
+ error,
379
+ effect: state === "running" ? "unknown" : "not-applied",
380
+ });
381
+ }
418
382
  }
383
+ }
419
384
  }
420
385
 
421
- function finalBatchResults(plan: BatchPlan, executionError: unknown): ReadonlyMap<string, AgentToolResult<unknown>>
422
- {
423
- return new Map(plan.calls.map((call) =>
424
- {
425
- const entry = plan.journal.get(call.id);
426
-
427
- if (entry.result)
428
- {
429
- const details = isObjectNotArray(entry.result.details) ? entry.result.details : {};
430
- return [call.id, {
431
- ...entry.result,
432
- details: {
433
- ...details,
434
- batchRecovery: {
435
- batchId: plan.batchId,
436
- state: entry.state,
437
- recovered: entry.recovered,
438
- ...(entry.reason === undefined ? {} : { reason: entry.reason }),
439
- },
440
- },
441
- }];
442
- }
443
-
444
- const cause = entry.failure?.error ?? executionError ?? entry.reason;
445
- const message = cause instanceof Error
446
- ? cause.message
447
- : typeof cause === "string"
386
+ function finalBatchResults(
387
+ plan: BatchPlan,
388
+ executionError: unknown,
389
+ ): ReadonlyMap<string, AgentToolResult<unknown>> {
390
+ return new Map(
391
+ plan.calls.map((call) => {
392
+ const entry = plan.journal.get(call.id);
393
+
394
+ if (entry.result) {
395
+ const details = isObjectNotArray(entry.result.details) ? entry.result.details : {};
396
+ return [
397
+ call.id,
398
+ {
399
+ ...entry.result,
400
+ details: {
401
+ ...details,
402
+ batchRecovery: {
403
+ batchId: plan.batchId,
404
+ state: entry.state,
405
+ recovered: entry.recovered,
406
+ ...(entry.reason !== undefined && { reason: entry.reason }),
407
+ },
408
+ },
409
+ },
410
+ ];
411
+ }
412
+
413
+ const cause = entry.failure?.error ?? executionError ?? entry.reason;
414
+ const message =
415
+ cause instanceof Error
416
+ ? cause.message
417
+ : typeof cause === "string"
448
418
  ? cause
449
419
  : "call did not execute";
450
- return [call.id, {
451
- content: [{ type: "text" as const, text: `${call.name} failed: ${message}` }],
452
- details: {
453
- batchRecovery: {
454
- batchId: plan.batchId,
455
- state: entry.state,
456
- recovered: entry.recovered,
457
- ...(entry.reason === undefined ? {} : { reason: entry.reason }),
458
- },
420
+ return [
421
+ call.id,
422
+ {
423
+ content: [{ type: "text" as const, text: `${call.name} failed: ${message}` }],
424
+ details: {
425
+ batchRecovery: {
426
+ batchId: plan.batchId,
427
+ state: entry.state,
428
+ recovered: entry.recovered,
429
+ ...(entry.reason !== undefined && { reason: entry.reason }),
459
430
  },
460
- isError: true,
461
- }];
462
- }));
431
+ },
432
+ isError: true,
433
+ },
434
+ ];
435
+ }),
436
+ );
463
437
  }
464
438
 
465
- function releaseBatchCall(plan: BatchPlan, toolCallId: string): void
466
- {
467
- plan.remainingCallIds.delete(toolCallId);
439
+ function releaseBatchCall(plan: BatchPlan, toolCallId: string): void {
440
+ plan.remainingCallIds.delete(toolCallId);
468
441
 
469
- if (plan.remainingCallIds.size > 0)
470
- {
471
- return;
472
- }
442
+ if (plan.remainingCallIds.size > 0) {
443
+ return;
444
+ }
473
445
 
474
- for (const call of plan.calls)
475
- {
476
- batchPlans.delete(call.id);
477
- blockedToolCalls.delete(call.id);
478
- }
446
+ for (const call of plan.calls) {
447
+ batchPlans.delete(call.id);
448
+ blockedToolCalls.delete(call.id);
449
+ }
479
450
  }
480
451
 
481
- /** Execute a planned batch once and return the result belonging to this call. */
452
+ /**
453
+ Execute a planned batch once and return the result belonging to this call.
454
+ */
482
455
  export async function executeWithBatchCoordinator<TDetails>(
483
- toolCallId: string,
484
- directExecute: () => Promise<AgentToolResult<TDetails>>,
485
- signal: AbortSignal | undefined,
486
- onUpdate: AgentToolUpdateCallback<TDetails> | undefined,
487
- ctx: ExtensionContext,
488
- ): Promise<AgentToolResult<TDetails>>
489
- {
490
- const plan = batchPlans.get(toolCallId);
491
-
492
- if (!plan)
493
- {
494
- return directExecute();
456
+ toolCallId: string,
457
+ directExecute: () => Promise<AgentToolResult<TDetails>>,
458
+ signal: AbortSignal | undefined,
459
+ onUpdate: AgentToolUpdateCallback<TDetails> | undefined,
460
+ context: ExtensionContext,
461
+ ): Promise<AgentToolResult<TDetails>> {
462
+ const plan = batchPlans.get(toolCallId);
463
+
464
+ if (!plan) {
465
+ return directExecute();
466
+ }
467
+
468
+ try {
469
+ if (plan.definition.splitResult === undefined && plan.carrierId !== toolCallId) {
470
+ return {
471
+ content: [{ type: "text", text: "" }],
472
+ details: { agenticIdeBatchSuppressed: true },
473
+ } as AgentToolResult<TDetails>;
495
474
  }
496
475
 
497
- try
498
- {
499
- if (
500
- plan.definition.splitResult === undefined
501
- && plan.carrierId !== toolCallId
502
- )
503
- {
504
- return {
505
- content: [{ type: "text", text: "" }],
506
- details: { agenticIdeBatchSuppressed: true },
507
- } as AgentToolResult<TDetails>;
508
- }
509
-
510
- const execution = await ensureBatchExecution(
511
- plan,
512
- signal,
513
- onUpdate as AgentToolUpdateCallback<unknown> | undefined,
514
- ctx,
515
- );
516
-
517
- if (plan.definition.splitResult !== undefined)
518
- {
519
- const result = execution.perCallResults?.get(toolCallId);
520
-
521
- if (!result)
522
- {
523
- throw new Error(`Missing split batch result for tool call ${toolCallId}.`);
524
- }
525
-
526
- return markBatchResult(result as AgentToolResult<TDetails>, plan.batchId, batchDisplayCalls(plan));
527
- }
528
-
529
- if (!execution.aggregate)
530
- {
531
- return await directExecute();
532
- }
533
-
534
- return execution.aggregate as AgentToolResult<TDetails>;
476
+ const execution = await ensureBatchExecution(
477
+ plan,
478
+ signal,
479
+ onUpdate as AgentToolUpdateCallback<unknown> | undefined,
480
+ context,
481
+ );
482
+
483
+ if (plan.definition.splitResult !== undefined) {
484
+ const result = execution.perCallResults?.get(toolCallId);
485
+
486
+ if (!result) {
487
+ throw new Error(`Missing split batch result for tool call ${toolCallId}.`);
488
+ }
489
+
490
+ return markBatchResult(
491
+ result as AgentToolResult<TDetails>,
492
+ plan.batchId,
493
+ batchDisplayCalls(plan),
494
+ );
535
495
  }
536
- finally
537
- {
538
- releaseBatchCall(plan, toolCallId);
539
- }
540
- }
541
496
 
542
- /** Get or create the coordinator state for one extension instance. */
543
- function coordinatorFor(pi: ExtensionAPI): CoordinatorState
544
- {
545
- let state = coordinators.get(pi);
546
-
547
- if (!state)
548
- {
549
- const created: CoordinatorState = {
550
- definitions: [],
551
- registered: false,
552
- nextBatchId: 1,
553
- };
554
- coordinators.set(pi, created);
555
- state = created;
556
- }
557
-
558
- if (!state.registered)
559
- {
560
- state.registered = true;
561
- pi.on("message_update", (event) =>
562
- {
563
- rewriteMessage(state, event.message, false);
564
- return;
565
- });
566
- pi.on("message_end", (event) =>
567
- {
568
- rewriteMessage(state, event.message, true);
569
- return;
570
- });
571
- pi.on("before_provider_request", (event) => filterProviderTools(state, event));
572
- pi.on("agent_end", () =>
573
- {
574
- clearCoordinatorCalls();
575
- });
497
+ if (!execution.aggregate) {
498
+ return await directExecute();
576
499
  }
577
500
 
578
- return state;
501
+ return execution.aggregate as AgentToolResult<TDetails>;
502
+ } finally {
503
+ releaseBatchCall(plan, toolCallId);
504
+ }
579
505
  }
580
506
 
581
- /** Register one batch family with the coordinator. */
582
- export function registerToolBatch<TState>(pi: ExtensionAPI, definition: ToolBatchDefinition<TState>): void
583
- {
584
- const state = coordinatorFor(pi);
585
- const definitionForCoordinator: ToolBatchDefinition = {
586
- sourceTools: definition.sourceTools,
587
- syntheticTool: definition.syntheticTool,
588
- resolveCall: (call, inheritedState) => definition.resolveCall(call, inheritedState as TState | undefined),
589
- buildArguments: (calls) => definition.buildArguments(calls as readonly BatchCallCandidate<TState>[]),
590
- execute: definition.execute,
591
- ...(definition.onRenderArguments === undefined
592
- ? {}
593
- : { onRenderArguments: definition.onRenderArguments }),
594
- ...(definition.recovery === undefined ? {} : { recovery: definition.recovery }),
595
- ...(definition.splitResult === undefined
596
- ? {}
597
- : {
598
- splitResult: (aggregate, calls, candidates) =>
599
- definition.splitResult!(
600
- aggregate,
601
- calls,
602
- candidates as readonly BatchCallCandidate<TState>[],
603
- ),
604
- }),
507
+ /**
508
+ Get or create the coordinator state for one extension instance.
509
+ */
510
+ function coordinatorFor(pi: ExtensionAPI): CoordinatorState {
511
+ let state = coordinators.get(pi);
512
+
513
+ if (!state) {
514
+ const created: CoordinatorState = {
515
+ definitions: [],
516
+ registered: false,
517
+ nextBatchId: 1,
605
518
  };
606
- state.definitions.push(definitionForCoordinator);
519
+ coordinators.set(pi, created);
520
+ state = created;
521
+ }
522
+
523
+ if (!state.registered) {
524
+ state.registered = true;
525
+ pi.on("message_update", (event) => {
526
+ rewriteMessage(state, event.message, false);
527
+ return;
528
+ });
529
+ pi.on("message_end", (event) => {
530
+ rewriteMessage(state, event.message, true);
531
+ return;
532
+ });
533
+ pi.on("before_provider_request", (event) => filterProviderTools(state, event));
534
+ pi.on("agent_end", () => {
535
+ clearCoordinatorCalls();
536
+ });
537
+ }
538
+
539
+ return state;
540
+ }
541
+
542
+ /**
543
+ Register one batch family with the coordinator.
544
+ */
545
+ export function registerToolBatch<TState>(
546
+ pi: ExtensionAPI,
547
+ definition: ToolBatchDefinition<TState>,
548
+ ): void {
549
+ const state = coordinatorFor(pi);
550
+ const definitionForCoordinator: ToolBatchDefinition = {
551
+ sourceTools: definition.sourceTools,
552
+ syntheticTool: definition.syntheticTool,
553
+ resolveCall: (call, inheritedState) =>
554
+ definition.resolveCall(call, inheritedState as TState | undefined),
555
+ buildArguments: (calls) =>
556
+ definition.buildArguments(calls as readonly BatchCallCandidate<TState>[]),
557
+ execute: definition.execute,
558
+ ...(definition.onRenderArguments !== undefined && {
559
+ onRenderArguments: definition.onRenderArguments,
560
+ }),
561
+ ...(definition.recovery !== undefined && { recovery: definition.recovery }),
562
+ ...(definition.splitResult !== undefined && {
563
+ splitResult: (aggregate, calls, candidates) =>
564
+ requiredValue(definition.splitResult)(
565
+ aggregate,
566
+ calls,
567
+ candidates as readonly BatchCallCandidate<TState>[],
568
+ ),
569
+ }),
570
+ };
571
+ state.definitions.push(definitionForCoordinator);
607
572
  }