pi-agent-ide 0.1.0 → 0.2.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.
- package/CHANGELOG.md +27 -0
- package/README.md +38 -10
- package/dist/chunk-266RH77Z.js +1 -0
- package/dist/chunk-2SKAED2I.js +2 -0
- package/dist/chunk-2ZMYT6ZC.js +1 -0
- package/dist/chunk-34ZQTTU2.js +2 -0
- package/dist/chunk-3H2EU7VQ.js +0 -0
- package/dist/chunk-3YK4XMWB.js +0 -0
- package/dist/chunk-476MR2QB.js +1 -0
- package/dist/chunk-4KQOODGE.js +13 -0
- package/dist/chunk-4SQQKEVD.js +16 -0
- package/dist/chunk-52BM6J6I.js +6 -0
- package/dist/chunk-5A25RATC.js +3 -0
- package/dist/chunk-5BWUVAR4.js +1 -0
- package/dist/chunk-6DN7NO7L.js +1 -0
- package/dist/chunk-6SMFVLTY.js +1 -0
- package/dist/chunk-7NDBZ4WX.js +1 -0
- package/dist/chunk-AP7Z3VWC.js +1 -0
- package/dist/chunk-BYWAG6X3.js +6 -0
- package/dist/chunk-DEP55R35.js +1 -0
- package/dist/chunk-E2RESHYR.js +1 -0
- package/dist/chunk-E4SECPF4.js +1 -0
- package/dist/chunk-EEH4WYI7.js +1 -0
- package/dist/chunk-EI7MMDWY.js +1 -0
- package/dist/chunk-ERVMDQGX.js +1 -0
- package/dist/chunk-EW2KVKCN.js +2 -0
- package/dist/chunk-F6SESI3P.js +4 -0
- package/dist/chunk-GTK5AREE.js +2 -0
- package/dist/chunk-HOBTFFQR.js +1 -0
- package/dist/chunk-IMVCVPMP.js +3 -0
- package/dist/chunk-IOCABSRL.js +1 -0
- package/dist/chunk-JASLOB2X.js +1 -0
- package/dist/chunk-JMVDFOTQ.js +1 -0
- package/dist/chunk-K4ZMRDEI.js +0 -0
- package/dist/chunk-KINKBPPX.js +1 -0
- package/dist/chunk-KNMWCDDK.js +7 -0
- package/dist/chunk-KP37XTDI.js +1 -0
- package/dist/chunk-KYVOMBO5.js +1 -0
- package/dist/chunk-KZBAJFCV.js +1 -0
- package/dist/chunk-LFV6G5Z3.js +1 -0
- package/dist/chunk-MB6VVVAF.js +2 -0
- package/dist/chunk-MBUXFKIW.js +3 -0
- package/dist/chunk-MTTKFJV6.js +1 -0
- package/dist/chunk-NI2NK4JU.js +1 -0
- package/dist/chunk-NNCZYO4Q.js +0 -0
- package/dist/chunk-OBWZ5RYN.js +1 -0
- package/dist/chunk-OIL6BB2S.js +33 -0
- package/dist/chunk-ORAPGW7W.js +1 -0
- package/dist/chunk-OVUYPHDE.js +1 -0
- package/dist/chunk-PETQCA7G.js +1 -0
- package/dist/chunk-PODWLGNO.js +6 -0
- package/dist/chunk-QNZVPFSP.js +3 -0
- package/dist/chunk-QW5O42QJ.js +2 -0
- package/dist/chunk-SJYDLHEF.js +108 -0
- package/dist/chunk-SSZB66C3.js +3 -0
- package/dist/chunk-STUZZM5B.js +1 -0
- package/dist/chunk-T2RPMEM2.js +1 -0
- package/dist/chunk-TG6H6EOI.js +1 -0
- package/dist/chunk-TNWYEXFG.js +1 -0
- package/dist/chunk-U4D6FT66.js +1 -0
- package/dist/chunk-VCCMVQXU.js +1 -0
- package/dist/chunk-VFBLX4TG.js +1 -0
- package/dist/chunk-VSP2QQPQ.js +2 -0
- package/dist/chunk-VUNCBASK.js +10 -0
- package/dist/chunk-VWVLBOMU.js +8 -0
- package/dist/chunk-W3XYKJ5H.js +1 -0
- package/dist/chunk-XGUAL3CA.js +1 -0
- package/dist/chunk-XNXQYPVT.js +10 -0
- package/dist/chunk-YHUTTZC6.js +2 -0
- package/dist/chunk-YPHXLAQF.js +1 -0
- package/dist/chunk-YQTLJ5ZV.js +58 -0
- package/dist/chunk-ZC65Z3CK.js +1 -0
- package/dist/entry-0.js +1 -0
- package/dist/entry-1.js +1 -0
- package/dist/entry-10.js +1 -0
- package/dist/entry-11.js +1 -0
- package/dist/entry-12.js +1 -0
- package/dist/entry-13.js +1 -0
- package/dist/entry-14.js +1 -0
- package/dist/entry-16.js +1 -0
- package/dist/entry-17.js +1 -0
- package/dist/entry-18.js +1 -0
- package/dist/entry-19.js +1 -0
- package/dist/entry-2.js +1 -0
- package/dist/entry-20.js +1 -0
- package/dist/entry-21.js +1 -0
- package/dist/entry-22.js +1 -0
- package/dist/entry-23.js +1 -0
- package/dist/entry-24.js +1 -0
- package/dist/entry-25.js +1 -0
- package/dist/entry-26.js +1 -0
- package/dist/entry-27.js +1 -0
- package/dist/entry-28.js +1 -0
- package/dist/entry-29.js +1 -0
- package/dist/entry-3.js +1 -0
- package/dist/entry-30.js +1 -0
- package/dist/entry-31.js +1 -0
- package/dist/entry-32.js +1 -0
- package/dist/entry-33.js +1 -0
- package/dist/entry-34.js +1 -0
- package/dist/entry-35.js +1 -0
- package/dist/entry-36.js +1 -0
- package/dist/entry-37.js +1 -0
- package/dist/entry-38.js +1 -0
- package/dist/entry-39.js +1 -0
- package/dist/entry-4.js +1 -0
- package/dist/entry-40.js +1 -0
- package/dist/entry-41.js +1 -0
- package/dist/entry-42.js +1 -0
- package/dist/entry-43.js +1 -0
- package/dist/entry-44.js +1 -0
- package/dist/entry-45.js +1 -0
- package/dist/entry-46.js +1 -0
- package/dist/entry-47.js +1 -0
- package/dist/entry-48.js +1 -0
- package/dist/entry-49.js +1 -0
- package/dist/entry-5.js +1 -0
- package/dist/entry-50.js +1 -0
- package/dist/entry-51.js +1 -0
- package/dist/entry-52.js +1 -0
- package/dist/entry-53.js +0 -0
- package/dist/entry-54.js +1 -0
- package/dist/entry-55.js +0 -0
- package/dist/entry-56.js +1 -0
- package/dist/entry-57.js +1 -0
- package/dist/entry-58.js +1 -0
- package/dist/entry-59.js +1 -0
- package/dist/entry-6.js +1 -0
- package/dist/entry-60.js +1 -0
- package/dist/entry-61.js +1 -0
- package/dist/entry-62.js +0 -0
- package/dist/entry-63.js +1 -0
- package/dist/entry-64.js +0 -0
- package/dist/entry-65.js +1 -0
- package/dist/entry-66.js +1 -0
- package/dist/entry-67.js +1 -0
- package/dist/entry-68.js +1 -0
- package/dist/entry-69.js +1 -0
- package/dist/entry-7.js +1 -0
- package/dist/entry-70.js +1 -0
- package/dist/entry-71.js +1 -0
- package/dist/entry-72.js +1 -0
- package/dist/entry-73.js +1 -0
- package/dist/entry-74.js +1 -0
- package/dist/entry-75.js +1 -0
- package/dist/entry-76.js +1 -0
- package/dist/entry-77.js +1 -0
- package/dist/entry-78.js +1 -0
- package/dist/entry-79.js +1 -0
- package/dist/entry-8.js +1 -0
- package/dist/entry-9.js +1 -0
- package/dist/pi-agent-ide.js +13 -0
- package/docs/architecture.md +30 -14
- package/docs/configuration.md +180 -53
- package/docs/development.md +116 -4
- package/docs/extensions.md +196 -154
- package/docs/generated/tool-catalog/c.md +9 -0
- package/docs/generated/tool-catalog/cmake.md +9 -0
- package/docs/generated/tool-catalog/cpp.md +9 -0
- package/docs/generated/tool-catalog/csharp.md +9 -0
- package/docs/generated/tool-catalog/css.md +11 -0
- package/docs/generated/tool-catalog/dockerfile.md +9 -0
- package/docs/generated/tool-catalog/go.md +10 -0
- package/docs/generated/tool-catalog/html.md +10 -0
- package/docs/generated/tool-catalog/index.md +30 -0
- package/docs/generated/tool-catalog/java.md +9 -0
- package/docs/generated/tool-catalog/javascript.md +12 -0
- package/docs/generated/tool-catalog/json.md +11 -0
- package/docs/generated/tool-catalog/kotlin.md +9 -0
- package/docs/generated/tool-catalog/lua.md +9 -0
- package/docs/generated/tool-catalog/markdown.md +10 -0
- package/docs/generated/tool-catalog/php.md +9 -0
- package/docs/generated/tool-catalog/python.md +10 -0
- package/docs/generated/tool-catalog/ruby.md +9 -0
- package/docs/generated/tool-catalog/rust.md +9 -0
- package/docs/generated/tool-catalog/shell.md +9 -0
- package/docs/generated/tool-catalog/sql.md +9 -0
- package/docs/generated/tool-catalog/swift.md +9 -0
- package/docs/generated/tool-catalog/terraform.md +9 -0
- package/docs/generated/tool-catalog/toml.md +10 -0
- package/docs/generated/tool-catalog/typescript.md +12 -0
- package/docs/generated/tool-catalog/xml.md +9 -0
- package/docs/generated/tool-catalog/yaml.md +10 -0
- package/docs/tools.md +88 -6
- package/node_modules/pi-agent-doctor/package.json +29 -0
- package/node_modules/pi-agent-doctor/runtime/entry-16.js +1 -0
- package/node_modules/pi-agent-doctor/runtime/entry-17.js +1 -0
- package/node_modules/pi-agent-doctor/runtime/entry-18.js +1 -0
- package/node_modules/pi-agent-doctor/runtime/entry-19.js +1 -0
- package/node_modules/pi-agent-doctor/src/catalog.ts +55 -0
- package/node_modules/pi-agent-doctor/src/connect-plugin.ts +53 -0
- package/node_modules/pi-agent-doctor/src/executable.ts +80 -0
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +147 -0
- package/node_modules/pi-agent-filesystem/index.ts +43 -44
- package/node_modules/pi-agent-filesystem/package.json +11 -11
- package/node_modules/pi-agent-filesystem/runtime/entry-20.js +2 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +112 -135
- package/node_modules/pi-agent-filesystem-image/index.ts +5 -6
- package/node_modules/pi-agent-filesystem-image/package.json +8 -8
- package/node_modules/pi-agent-filesystem-image/runtime/entry-21.js +2 -0
- package/node_modules/pi-agent-filesystem-pdf/index.ts +5 -6
- package/node_modules/pi-agent-filesystem-pdf/package.json +6 -6
- package/node_modules/pi-agent-filesystem-pdf/runtime/entry-22.js +2 -0
- package/node_modules/pi-agent-filesystem-text/index.ts +11 -12
- package/node_modules/pi-agent-filesystem-text/package.json +8 -8
- package/node_modules/pi-agent-filesystem-text/runtime/entry-23.js +2 -0
- package/node_modules/pi-agent-ide-ast/index.ts +1 -1
- package/node_modules/pi-agent-ide-ast/package.json +15 -13
- package/node_modules/pi-agent-ide-ast/runtime/entry-24.js +1 -0
- package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +2 -0
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +292 -322
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +591 -656
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +130 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +75 -64
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +168 -185
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +36 -36
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +118 -129
- package/node_modules/pi-agent-ide-changes/index.ts +57 -51
- package/node_modules/pi-agent-ide-changes/package.json +14 -12
- package/node_modules/pi-agent-ide-changes/runtime/entry-26.js +1 -0
- package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +2 -0
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +74 -78
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +259 -276
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
- package/node_modules/pi-agent-ide-changes/src/doctor-plugin.ts +59 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +98 -93
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +131 -126
- package/node_modules/pi-agent-ide-formatter/index.ts +22 -23
- package/node_modules/pi-agent-ide-formatter/package.json +6 -3
- package/node_modules/pi-agent-ide-formatter/runtime/entry-28.js +2 -0
- package/node_modules/pi-agent-ide-formatter/src/catalog.ts +281 -0
- package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +156 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +38 -40
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +94 -27
- package/node_modules/pi-agent-ide-languages/index.ts +24 -0
- package/{src/extensions/pi-agent-search/plugins/pi-agent-search-semantic → node_modules/pi-agent-ide-languages}/package.json +6 -7
- package/node_modules/pi-agent-ide-languages/runtime/entry-29.js +2 -0
- package/node_modules/pi-agent-ide-languages/src/languages.ts +84 -0
- package/node_modules/pi-agent-ide-lint/index.ts +66 -225
- package/node_modules/pi-agent-ide-lint/package.json +10 -8
- package/node_modules/pi-agent-ide-lint/runtime/entry-30.js +2 -0
- package/node_modules/pi-agent-ide-lint/src/catalog.ts +295 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +98 -144
- package/node_modules/pi-agent-ide-lint/src/diagnostics.ts +182 -0
- package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +155 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +94 -27
- package/node_modules/pi-agent-ide-lsp/index.ts +111 -231
- package/node_modules/pi-agent-ide-lsp/package.json +13 -11
- package/node_modules/pi-agent-ide-lsp/runtime/entry-31.js +2 -0
- package/node_modules/pi-agent-ide-lsp/src/catalog.ts +248 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
- package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +113 -0
- package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +163 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +439 -396
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +421 -458
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostic-adapters.ts +76 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +143 -159
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +49 -57
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +350 -415
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +196 -77
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +118 -127
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +76 -57
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
- package/node_modules/pi-agent-image/package.json +3 -3
- package/node_modules/pi-agent-image/runtime/entry-32.js +1 -0
- package/node_modules/pi-agent-image/src/image-converter.ts +210 -249
- package/node_modules/pi-agent-image/src/index.ts +4 -4
- package/node_modules/pi-agent-invariant/package.json +12 -0
- package/node_modules/pi-agent-invariant/runtime/entry-33.js +1 -0
- package/node_modules/pi-agent-invariant/src/index.ts +8 -0
- package/node_modules/pi-agent-pdf/package.json +3 -3
- package/node_modules/pi-agent-pdf/runtime/entry-34.js +1 -0
- package/node_modules/pi-agent-pdf/src/index.ts +1 -5
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +133 -155
- package/node_modules/pi-agent-read/index.ts +1 -1
- package/node_modules/pi-agent-read/package.json +15 -13
- package/node_modules/pi-agent-read/runtime/entry-35.js +1 -0
- package/node_modules/pi-agent-read/runtime/entry-36.js +1 -0
- package/node_modules/pi-agent-read/runtime/entry-37.js +1 -0
- package/node_modules/pi-agent-read/runtime/entry-38.js +1 -0
- package/node_modules/pi-agent-read/runtime/entry-39.js +2 -0
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +38 -51
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +27 -33
- package/node_modules/pi-agent-read/src/api/rendering.ts +3 -4
- package/node_modules/pi-agent-read/src/api/tools/read.ts +237 -134
- package/node_modules/pi-agent-read/src/core/extension.ts +51 -33
- package/node_modules/pi-agent-read/src/core/read-core.ts +353 -330
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +169 -156
- package/node_modules/pi-agent-read/src/core/tools/read/persisted-result.ts +72 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +381 -313
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +169 -154
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
- package/node_modules/pi-agent-read/src/core/tools/read/views.ts +29 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +1117 -680
- package/node_modules/pi-agent-resource/package.json +5 -2
- package/node_modules/pi-agent-resource/runtime/entry-40.js +1 -0
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +50 -62
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +28 -34
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +16 -20
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +53 -58
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +116 -135
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +38 -39
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +118 -108
- package/node_modules/pi-agent-resource/src/content.ts +5 -9
- package/node_modules/pi-agent-resource/src/index.ts +51 -40
- package/node_modules/pi-agent-resource/src/resolver.ts +11 -13
- package/node_modules/pi-agent-resource/src/resource.ts +17 -24
- package/node_modules/pi-agent-resource/src/validation.ts +106 -92
- package/node_modules/pi-agent-search/package.json +11 -10
- package/node_modules/pi-agent-search/runtime/entry-41.js +1 -0
- package/node_modules/pi-agent-search/runtime/entry-42.js +1 -0
- package/node_modules/pi-agent-search/runtime/entry-43.js +1 -0
- package/node_modules/pi-agent-search/runtime/entry-44.js +2 -0
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +37 -47
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +26 -30
- package/node_modules/pi-agent-search/src/api/search.ts +65 -67
- package/node_modules/pi-agent-search/src/core/extension.ts +184 -92
- package/node_modules/pi-agent-search/src/core/search-config.ts +98 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +332 -357
- package/node_modules/pi-agent-search/src/core/search-timeout.ts +54 -0
- package/node_modules/pi-agent-search-text/index.ts +90 -38
- package/node_modules/pi-agent-search-text/package.json +13 -12
- package/node_modules/pi-agent-search-text/runtime/entry-45.js +2 -0
- package/node_modules/pi-agent-search-text/runtime/entry-46.js +1 -0
- package/node_modules/pi-agent-search-text/src/doctor-plugin.ts +48 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +90 -86
- package/node_modules/pi-agent-search-text/src/persisted-result.ts +56 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +158 -161
- package/node_modules/pi-agent-search-text/src/ripgrep.ts +16 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +215 -249
- package/node_modules/pi-agent-search-text/src/search-query.ts +262 -102
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +68 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +275 -345
- package/node_modules/pi-agent-search-text/src/search-result.ts +152 -157
- package/node_modules/pi-agent-search-text/src/search-session.ts +438 -278
- package/node_modules/pi-agent-text/package.json +6 -3
- package/node_modules/pi-agent-text/runtime/entry-47.js +1 -0
- package/node_modules/pi-agent-text/src/index.ts +53 -22
- package/node_modules/pi-agent-text/src/presented-text.ts +15 -17
- package/node_modules/pi-agent-text/src/source-line.ts +33 -36
- package/node_modules/pi-agent-text/src/stored-text.ts +14 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +264 -117
- package/node_modules/pi-agent-text/src/text-converter.ts +71 -84
- package/node_modules/pi-agent-text/src/text-document.ts +120 -110
- package/node_modules/pi-agent-text/src/text-target.ts +105 -0
- package/node_modules/pi-agent-text-anchor-constant/index.ts +18 -20
- package/node_modules/pi-agent-text-anchor-constant/package.json +9 -6
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-48.js +2 -0
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +35 -36
- package/node_modules/pi-agent-text-anchor-exact/index.ts +34 -0
- package/node_modules/pi-agent-text-anchor-exact/package.json +27 -0
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-49.js +1 -0
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +230 -0
- package/node_modules/pi-agent-text-anchor-exact/src/config.ts +159 -0
- package/node_modules/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +100 -0
- package/node_modules/pi-agent-text-anchor-exact/src/recovery.ts +151 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +40 -36
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +16 -12
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-51.js +1 -0
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +2 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +105 -84
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +43 -42
- package/node_modules/pi-agent-text-editor/index.ts +7 -9
- package/node_modules/pi-agent-text-editor/package.json +26 -25
- package/node_modules/pi-agent-text-editor/runtime/entry-53.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-54.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-55.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-56.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-57.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-58.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-59.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-60.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-61.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-62.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-63.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-64.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-65.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-66.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-67.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-68.js +2 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +18 -18
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +20 -19
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +154 -131
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +173 -144
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +93 -103
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +85 -99
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +10 -10
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +49 -48
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +136 -127
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +279 -313
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +233 -289
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +553 -582
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +64 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
- package/node_modules/pi-agent-text-editor/src/core/read-fragment-resolver.ts +83 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +369 -335
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +184 -214
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +526 -372
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +111 -87
- package/node_modules/pi-agent-text-editor/src/core/text-editor-config.ts +95 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +1899 -2027
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +26 -22
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +1043 -634
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +979 -1032
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -2
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +9 -11
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +7 -8
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +289 -75
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +100 -106
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +73 -66
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +64 -42
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +116 -124
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +78 -58
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +26 -17
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +16 -19
- package/node_modules/pi-agent-text-editor-argument-order/package.json +5 -5
- package/node_modules/pi-agent-text-editor-argument-order/runtime/entry-69.js +2 -0
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +297 -323
- package/node_modules/pi-agent-text-editor-overwrite/package.json +6 -5
- package/node_modules/pi-agent-text-editor-overwrite/runtime/entry-70.js +2 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +31 -12
- package/node_modules/pi-agent-text-editor-renderer/package.json +10 -7
- package/node_modules/pi-agent-text-editor-renderer/runtime/entry-71.js +2 -0
- package/node_modules/pi-agent-text-editor-renderer/src/animation-pressure.ts +50 -0
- package/node_modules/pi-agent-text-editor-renderer/src/config.ts +73 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +255 -216
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +284 -180
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +550 -329
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +142 -118
- package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +47 -0
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +10 -4
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +744 -631
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +215 -157
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +335 -335
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +7 -6
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-72.js +2 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +5 -2
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +473 -350
- package/node_modules/pi-agent-tool-ui/package.json +15 -0
- package/node_modules/pi-agent-tool-ui/runtime/entry-74.js +1 -0
- package/node_modules/pi-agent-tool-ui/src/index.ts +318 -0
- package/node_modules/pi-agent-web/index.ts +35 -26
- package/node_modules/pi-agent-web/package.json +12 -10
- package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
- package/node_modules/pi-agent-web/src/browser-loader.ts +180 -0
- package/node_modules/pi-agent-web/src/doctor-plugin.ts +41 -0
- package/node_modules/pi-agent-web/src/resolver.ts +228 -146
- package/node_modules/pi-agent-web-html/index.ts +5 -6
- package/node_modules/pi-agent-web-html/package.json +9 -6
- package/node_modules/pi-agent-web-html/runtime/entry-76.js +2 -0
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +72 -77
- package/node_modules/pi-agent-web-html/src/html-converter.ts +62 -75
- package/node_modules/pi-agent-web-image/index.ts +5 -6
- package/node_modules/pi-agent-web-image/package.json +6 -6
- package/node_modules/pi-agent-web-image/runtime/entry-77.js +2 -0
- package/node_modules/pi-agent-web-pdf/index.ts +5 -6
- package/node_modules/pi-agent-web-pdf/package.json +6 -6
- package/node_modules/pi-agent-web-pdf/runtime/entry-78.js +2 -0
- package/node_modules/pi-agent-web-text/index.ts +5 -6
- package/node_modules/pi-agent-web-text/package.json +6 -6
- package/node_modules/pi-agent-web-text/runtime/entry-79.js +2 -0
- package/package.json +101 -67
- package/src/api/code-view.ts +21 -17
- package/src/api/connect-doctor-plugin.ts +1 -0
- package/src/api/connect-plugin.ts +38 -48
- package/src/api/connect-tip-provider.ts +49 -0
- package/src/api/doctor.ts +1 -0
- package/src/api/plugin-protocol.ts +71 -40
- package/src/api/read.ts +6 -1
- package/src/api/resource.ts +3 -1
- package/src/api/search.ts +5 -1
- package/src/api/text-editor.ts +4 -1
- package/src/api/text.ts +3 -1
- package/src/api/tips.ts +77 -0
- package/src/api/tool-catalog.ts +1 -0
- package/src/api/tool-config/formatters.json +215 -0
- package/src/api/tool-config/linters.json +257 -0
- package/src/api/tool-config/lsp-servers.json +275 -0
- package/src/api/tool-config.ts +569 -0
- package/src/api/toolchain.ts +13 -18
- package/src/code-view/diagnostic-view.ts +150 -58
- package/src/code-view/reference.ts +64 -82
- package/src/code-view/source-view.ts +159 -180
- package/src/composite/builtin-extensions.ts +47 -37
- package/src/composite/extensions-config.ts +137 -0
- package/src/composite/selection.ts +109 -52
- package/src/core/diagnostic-store.ts +244 -0
- package/src/core/extension.ts +71 -35
- package/src/core/ide-core.ts +126 -98
- package/src/doctor/config-writer.ts +115 -0
- package/src/doctor/core.ts +221 -0
- package/src/doctor/discovery.ts +223 -0
- package/src/doctor/extension.ts +119 -0
- package/src/doctor/index.ts +1 -0
- package/src/doctor/inventory.ts +109 -0
- package/src/doctor/run.ts +177 -0
- package/src/doctor/tip-provider.ts +92 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +43 -44
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +11 -11
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-21.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/runtime/entry-22.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +11 -12
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-23.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-20.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +112 -135
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +35 -26
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +12 -10
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +9 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +72 -77
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +62 -75
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-77.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-78.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +5 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-79.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +180 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/doctor-plugin.ts +41 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +228 -146
- package/src/extensions/pi-agent-read/index.ts +1 -1
- package/src/extensions/pi-agent-read/package.json +15 -13
- package/src/extensions/pi-agent-read/runtime/entry-35.js +1 -0
- package/src/extensions/pi-agent-read/runtime/entry-36.js +1 -0
- package/src/extensions/pi-agent-read/runtime/entry-37.js +1 -0
- package/src/extensions/pi-agent-read/runtime/entry-38.js +1 -0
- package/src/extensions/pi-agent-read/runtime/entry-39.js +2 -0
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +38 -51
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +27 -33
- package/src/extensions/pi-agent-read/src/api/rendering.ts +3 -4
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +237 -134
- package/src/extensions/pi-agent-read/src/core/extension.ts +51 -33
- package/src/extensions/pi-agent-read/src/core/read-core.ts +353 -330
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +169 -156
- package/src/extensions/pi-agent-read/src/core/tools/read/persisted-result.ts +72 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +381 -313
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +169 -154
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +165 -187
- package/src/extensions/pi-agent-read/src/core/tools/read/views.ts +29 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +1117 -680
- package/src/extensions/pi-agent-search/package.json +11 -10
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +90 -38
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +13 -12
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-45.js +2 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/doctor-plugin.ts +48 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +90 -86
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/persisted-result.ts +56 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +158 -161
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +16 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +215 -249
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +262 -102
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +68 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +275 -345
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +152 -157
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +438 -278
- package/src/extensions/pi-agent-search/runtime/entry-41.js +1 -0
- package/src/extensions/pi-agent-search/runtime/entry-42.js +1 -0
- package/src/extensions/pi-agent-search/runtime/entry-43.js +1 -0
- package/src/extensions/pi-agent-search/runtime/entry-44.js +2 -0
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +37 -47
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +26 -30
- package/src/extensions/pi-agent-search/src/api/search.ts +65 -67
- package/src/extensions/pi-agent-search/src/core/extension.ts +184 -92
- package/src/extensions/pi-agent-search/src/core/search-config.ts +98 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +332 -357
- package/src/extensions/pi-agent-search/src/core/search-timeout.ts +54 -0
- package/src/extensions/pi-agent-text-editor/index.ts +7 -9
- package/src/extensions/pi-agent-text-editor/package.json +26 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +18 -20
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +9 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-48.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +35 -36
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +34 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +27 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-49.js +1 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +230 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/config.ts +159 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +100 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/recovery.ts +151 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +40 -36
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +16 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-51.js +1 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +105 -84
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +43 -42
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +16 -19
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-69.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +79 -91
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +297 -323
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +6 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/runtime/entry-70.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +31 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +10 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/animation-pressure.ts +50 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/config.ts +73 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +347 -359
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +255 -216
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +297 -329
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +19 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +160 -168
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +284 -180
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +550 -329
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +142 -118
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +10 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +744 -631
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +215 -157
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +335 -335
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +7 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-72.js +2 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-53.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-55.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-56.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-57.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-58.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-59.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-60.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-61.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-62.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-63.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-64.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-65.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-66.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-67.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-68.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +18 -18
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +40 -50
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +10 -13
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +31 -36
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +25 -27
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +26 -31
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +18 -21
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +20 -19
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +154 -131
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +173 -144
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +93 -103
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -14
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +85 -99
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +10 -10
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +18 -22
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +49 -48
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +136 -127
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +279 -313
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +85 -95
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +233 -289
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +553 -582
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +64 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +86 -98
- package/src/extensions/pi-agent-text-editor/src/core/read-fragment-resolver.ts +83 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +12 -11
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +369 -335
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +184 -214
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +476 -511
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +93 -105
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +31 -33
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +526 -372
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +111 -87
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-config.ts +95 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +1899 -2027
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +26 -22
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +1043 -634
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +979 -1032
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +19 -23
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +270 -273
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -2
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +353 -403
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +9 -11
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +7 -8
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +289 -75
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +100 -106
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +73 -66
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +64 -42
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +116 -124
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +78 -58
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +26 -17
- package/src/pi-agent-ide.ts +22 -10
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/package.json +15 -13
- package/src/plugins/pi-agent-ide-ast/runtime/entry-24.js +1 -0
- package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +2 -0
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +11 -16
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +292 -322
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +591 -656
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +15 -19
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +130 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +75 -64
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +51 -54
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +168 -185
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +36 -36
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +118 -129
- package/src/plugins/pi-agent-ide-changes/index.ts +57 -51
- package/src/plugins/pi-agent-ide-changes/package.json +14 -12
- package/src/plugins/pi-agent-ide-changes/runtime/entry-26.js +1 -0
- package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +2 -0
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +74 -78
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +230 -245
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +189 -192
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +75 -79
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +259 -276
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +164 -190
- package/src/plugins/pi-agent-ide-changes/src/doctor-plugin.ts +59 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +10 -9
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +49 -62
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +98 -93
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +131 -126
- package/src/plugins/pi-agent-ide-diagnostics/index.ts +1 -0
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +191 -0
- package/src/plugins/pi-agent-ide-formatter/index.ts +22 -23
- package/src/plugins/pi-agent-ide-formatter/package.json +6 -3
- package/src/plugins/pi-agent-ide-formatter/runtime/entry-28.js +2 -0
- package/src/plugins/pi-agent-ide-formatter/src/catalog.ts +281 -0
- package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +156 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +38 -40
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +94 -27
- package/src/plugins/pi-agent-ide-languages/index.ts +24 -0
- package/{node_modules/pi-agent-search-semantic → src/plugins/pi-agent-ide-languages}/package.json +6 -7
- package/src/plugins/pi-agent-ide-languages/runtime/entry-29.js +2 -0
- package/src/plugins/pi-agent-ide-languages/src/languages.ts +84 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +66 -225
- package/src/plugins/pi-agent-ide-lint/package.json +10 -8
- package/src/plugins/pi-agent-ide-lint/runtime/entry-30.js +2 -0
- package/src/plugins/pi-agent-ide-lint/src/catalog.ts +295 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +98 -144
- package/src/plugins/pi-agent-ide-lint/src/diagnostics.ts +182 -0
- package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +155 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +94 -27
- package/src/plugins/pi-agent-ide-lsp/index.ts +111 -231
- package/src/plugins/pi-agent-ide-lsp/package.json +13 -11
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-31.js +2 -0
- package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +248 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +109 -116
- package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +113 -0
- package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +163 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +439 -396
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +421 -458
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostic-adapters.ts +76 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +143 -159
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +25 -20
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +31 -33
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +49 -57
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +350 -415
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +58 -63
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +196 -77
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +36 -36
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +118 -127
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +108 -107
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +76 -57
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +36 -32
- package/src/post-edit/gate.ts +18 -150
- package/src/tips/core.ts +86 -0
- package/src/tips/extension.ts +115 -0
- package/src/tips/persistence.ts +225 -0
- package/src/tips/tip-callout.ts +77 -0
- package/src/toolchain/diagnostic.ts +3 -4
- package/src/toolchain/registry.ts +133 -170
- package/src/toolchain/types.ts +83 -128
- package/node_modules/pi-agent-ide-formatter/src/types.ts +0 -10
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +0 -51
- package/node_modules/pi-agent-ide-lint/src/types.ts +0 -10
- package/node_modules/pi-agent-search-semantic/index.ts +0 -105
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +0 -22
- package/node_modules/pi-agent-search-web/index.ts +0 -74
- package/node_modules/pi-agent-search-web/package.json +0 -19
- package/node_modules/pi-agent-search-web/src/config.ts +0 -499
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +0 -78
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +0 -89
- package/node_modules/pi-agent-search-web/src/providers/request.ts +0 -430
- package/node_modules/pi-agent-search-web/src/providers/response.ts +0 -402
- package/node_modules/pi-agent-search-web/src/search-format.ts +0 -29
- package/node_modules/pi-agent-search-web/src/search.ts +0 -434
- package/node_modules/pi-agent-search-web/src/types.ts +0 -153
- package/src/composite/config.ts +0 -94
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +0 -105
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +0 -22
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +0 -74
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +0 -19
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +0 -499
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +0 -78
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +0 -89
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +0 -430
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +0 -402
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +0 -29
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +0 -434
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +0 -153
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +0 -10
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +0 -51
- package/src/plugins/pi-agent-ide-lint/src/types.ts +0 -10
- package/src/toolchain/gate.ts +0 -322
|
@@ -1,45 +1,48 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
Runtime for intercepting streamed Pi tool calls.
|
|
3
|
+
*/
|
|
2
4
|
|
|
3
5
|
import { Allow } from "partial-json";
|
|
4
6
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
isToolCallAnnotation,
|
|
8
|
+
type ToolCallAnnotation,
|
|
9
|
+
withToolCallInterceptionDetails,
|
|
8
10
|
} from "pi-agent-tool-call-interception";
|
|
9
11
|
import { Guard } from "typebox-guard/guard";
|
|
10
12
|
|
|
11
13
|
import { resolvePartial } from "./partial-json-resolver.js";
|
|
12
14
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
type PartialToolRecoveryBatchEntry,
|
|
16
|
+
PartialToolRecoveryRegistry,
|
|
17
|
+
type PartialToolRecoveryResult,
|
|
16
18
|
} from "./partial-tool-recovery.js";
|
|
17
19
|
import { registerStreamingInterceptorProvider } from "./streaming-provider.js";
|
|
18
20
|
|
|
19
21
|
import type {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
AgentToolResult,
|
|
23
|
+
ExtensionAPI,
|
|
24
|
+
ExtensionContext,
|
|
25
|
+
MessageUpdateEvent,
|
|
24
26
|
} from "@earendil-works/pi-coding-agent";
|
|
25
27
|
|
|
26
28
|
export {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
getToolCallInterception,
|
|
30
|
+
type ToolCallAnnotation,
|
|
31
|
+
type ToolCallInterceptionDetails,
|
|
30
32
|
} from "pi-agent-tool-call-interception";
|
|
31
33
|
|
|
32
34
|
type AssistantStreamEvent = MessageUpdateEvent["assistantMessageEvent"];
|
|
33
35
|
|
|
34
|
-
interface PendingRecoveryBlock
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
readonly ctx: InterceptorContext;
|
|
36
|
+
interface PendingRecoveryBlock {
|
|
37
|
+
readonly blocked: InterceptResult;
|
|
38
|
+
readonly ctx: InterceptorContext;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
// ── Utility type ──────────────────────────────────────────────────────
|
|
41
42
|
|
|
42
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
Value or Promise of value — for sync/async interop.
|
|
45
|
+
*/
|
|
43
46
|
export type Awaitable<T> = T | Promise<T>;
|
|
44
47
|
|
|
45
48
|
export const PARTIAL_TOOL_RECOVERY_CUSTOM_TYPE = "agentic-ide-partial-tool-recovery";
|
|
@@ -51,1185 +54,1129 @@ export type ToolCallAnnotationSink = (toolCallId: string, annotation: ToolCallAn
|
|
|
51
54
|
const TOOL_CALL_ANNOTATION_EVENT = "pi-agent-text-editor/tool-call-annotation";
|
|
52
55
|
const toolCallAnnotationSinkUnsubscribers = new WeakMap<ExtensionAPI, () => void>();
|
|
53
56
|
|
|
54
|
-
interface ToolCallAnnotationEvent
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
readonly annotation: ToolCallAnnotation;
|
|
57
|
+
interface ToolCallAnnotationEvent {
|
|
58
|
+
readonly toolCallId: string;
|
|
59
|
+
readonly annotation: ToolCallAnnotation;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
export interface BlockedToolCallFact
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly nativeExecutionBlocked: boolean;
|
|
62
|
+
export interface BlockedToolCallFact {
|
|
63
|
+
readonly callId: string;
|
|
64
|
+
readonly toolName: string;
|
|
65
|
+
readonly arguments: Record<string, unknown>;
|
|
66
|
+
readonly contentIndex?: number;
|
|
67
|
+
readonly batchEntryIndex?: number;
|
|
68
|
+
readonly details?: unknown;
|
|
69
|
+
readonly result: AgentToolResult<unknown>;
|
|
70
|
+
readonly nativeExecutionBlocked: boolean;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
export type BlockedToolCallSink = (blocked: BlockedToolCallFact) => void;
|
|
73
74
|
|
|
74
75
|
// ── Public types ──────────────────────────────────────────────────────────
|
|
75
76
|
|
|
76
|
-
export interface InterceptResult
|
|
77
|
-
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
annotation?: ToolCallAnnotation;
|
|
77
|
+
export interface InterceptResult {
|
|
78
|
+
message: {
|
|
79
|
+
customType: string;
|
|
80
|
+
content: string;
|
|
81
|
+
display: boolean;
|
|
82
|
+
details?: unknown;
|
|
83
|
+
};
|
|
84
|
+
annotation?: ToolCallAnnotation;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
export interface GuardCallRecord
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
readonly blockExecution?: boolean;
|
|
87
|
+
export interface GuardCallRecord {
|
|
88
|
+
readonly originalArguments: Record<string, unknown>;
|
|
89
|
+
readonly guardResult?: AgentToolResult<unknown>;
|
|
90
|
+
readonly blockExecution?: boolean;
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
export interface GuardInterception
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
readonly result: AgentToolResult<unknown>;
|
|
93
|
+
export interface GuardInterception {
|
|
94
|
+
readonly toolCallId: string;
|
|
95
|
+
readonly arguments: Record<string, unknown>;
|
|
96
|
+
readonly result: AgentToolResult<unknown>;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
export interface InterceptorContext
|
|
102
|
-
{
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
99
|
+
export interface InterceptorContext {
|
|
100
|
+
toolCall: {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
arguments: Record<string, unknown>;
|
|
104
|
+
thoughtSignature?: string;
|
|
105
|
+
};
|
|
106
|
+
args: Record<string, unknown>;
|
|
107
|
+
/**
|
|
108
|
+
Stream content index, used to isolate interceptor state.
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
Position and calls within the current streamed tool-call batch.
|
|
112
|
+
*/
|
|
113
|
+
batchEntryIndex?: number;
|
|
114
|
+
batchEntries?: readonly PartialToolRecoveryBatchEntry[];
|
|
115
|
+
contentIndex?: number;
|
|
116
|
+
/**
|
|
117
|
+
Best-effort parsed arguments during streaming (set on toolcall_delta).
|
|
118
|
+
*/
|
|
119
|
+
partialArgs?: Record<string, unknown>;
|
|
120
|
+
cwd: string;
|
|
121
|
+
signal: AbortSignal | undefined;
|
|
122
|
+
/**
|
|
123
|
+
Extension context with UI methods (select, input, editor, confirm, etc.).
|
|
124
|
+
*/
|
|
125
|
+
ctx: ExtensionContext;
|
|
121
126
|
}
|
|
122
127
|
|
|
123
|
-
export interface ToolCallInterceptorHandler
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
export interface ToolCallInterceptorHandler {
|
|
129
|
+
/**
|
|
130
|
+
Unique handler name (for debug/removal).
|
|
131
|
+
*/
|
|
132
|
+
name: string;
|
|
133
|
+
toolNames: string[];
|
|
134
|
+
/**
|
|
135
|
+
Block Pi's native tool_call before execution. Existing cooperative executors may leave this disabled.
|
|
136
|
+
*/
|
|
137
|
+
blockExecution?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Optional lifecycle hooks for handlers that keep per-content state.
|
|
140
|
+
*/
|
|
141
|
+
onContentEnd?(contentIndex: number): void;
|
|
142
|
+
onAgentEnd?(): void;
|
|
143
|
+
onAbort?(contentIndex: number): void;
|
|
144
|
+
/**
|
|
145
|
+
* Predicate. Called on each toolcall_start/delta/end for toolNames.
|
|
146
|
+
* Return InterceptResult — intercept (abort; return the result through tool_result).
|
|
147
|
+
* Return undefined — skip, next handler.
|
|
148
|
+
* Can be sync or async (returns Awaitable).
|
|
149
|
+
*/
|
|
150
|
+
intercept(context: InterceptorContext): Awaitable<InterceptResult | undefined>;
|
|
143
151
|
}
|
|
144
152
|
|
|
145
|
-
export interface ToolCallInterceptor
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
export interface ToolCallInterceptor {
|
|
154
|
+
register(handler: ToolCallInterceptorHandler): void;
|
|
155
|
+
unregister(name: string): void;
|
|
156
|
+
registerRecovery(registration: Parameters<PartialToolRecoveryRegistry["register"]>[0]): void;
|
|
157
|
+
unregisterRecovery(toolName: string): void;
|
|
158
|
+
registerBlockedCallSink(sink: BlockedToolCallSink | undefined): void;
|
|
159
|
+
processStreamEvent(
|
|
160
|
+
event: AssistantStreamEvent,
|
|
161
|
+
context: ExtensionContext,
|
|
162
|
+
): Promise<GuardInterception | undefined>;
|
|
163
|
+
markStreamEventProcessed(event: AssistantStreamEvent): void;
|
|
164
|
+
finalizeStreamInterception(contentIndex: number): void;
|
|
165
|
+
getToolCallRecord(toolCallId: string): GuardCallRecord | undefined;
|
|
156
166
|
}
|
|
157
167
|
|
|
158
168
|
// ── Implementation ────────────────────────────────────────────────────────
|
|
159
169
|
|
|
160
|
-
class InterceptorImpl implements ToolCallInterceptor
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
170
|
+
class InterceptorImpl implements ToolCallInterceptor {
|
|
171
|
+
/**
|
|
172
|
+
toolName → handler[]
|
|
173
|
+
*/
|
|
174
|
+
private readonly handlers = new Map<string, ToolCallInterceptorHandler[]>();
|
|
175
|
+
private readonly recoveryRegistry = new PartialToolRecoveryRegistry();
|
|
176
|
+
/**
|
|
177
|
+
All blocked calls collected during the current assistant batch.
|
|
178
|
+
*/
|
|
179
|
+
private readonly pendingRecoveryBlocks: PendingRecoveryBlock[] = [];
|
|
180
|
+
/**
|
|
181
|
+
Short reason for the guard that aborted the current assistant message.
|
|
182
|
+
*/
|
|
183
|
+
private pendingAbortReason: string | undefined;
|
|
184
|
+
/**
|
|
185
|
+
Source batch indexes that recovery actually applied.
|
|
186
|
+
*/
|
|
187
|
+
private readonly recoveryAppliedBatchIndexes = new Set<number>();
|
|
188
|
+
/**
|
|
189
|
+
Accumulated raw partial JSON arguments per contentIndex.
|
|
190
|
+
*/
|
|
191
|
+
private readonly partialBuffers = new Map<number, string>();
|
|
192
|
+
/**
|
|
193
|
+
Content items whose complete JSON arguments were already intercepted.
|
|
194
|
+
*/
|
|
195
|
+
private readonly completeArgumentContentIndices = new Set<number>();
|
|
196
|
+
/**
|
|
197
|
+
Content items whose complete JSON arguments were already intercepted.
|
|
198
|
+
*/
|
|
199
|
+
/**
|
|
200
|
+
Completed/partial calls in the current assistant batch.
|
|
201
|
+
*/
|
|
202
|
+
private readonly streamedBatchEntries = new Map<number, PartialToolRecoveryBatchEntry>();
|
|
203
|
+
/**
|
|
204
|
+
contentIndex → local position within the current edit batch.
|
|
205
|
+
*/
|
|
206
|
+
private readonly batchEntryIndexes = new Map<number, number>();
|
|
207
|
+
/**
|
|
208
|
+
toolCallId → local batch entry index, retained until tool_result arrives.
|
|
209
|
+
*/
|
|
210
|
+
private readonly toolCallBatchEntryIndexes = new Map<string, number>();
|
|
211
|
+
/**
|
|
212
|
+
Batch entries whose tool execution has already returned a result.
|
|
213
|
+
*/
|
|
214
|
+
private readonly completedBatchEntryIndexes = new Set<number>();
|
|
215
|
+
private nextBatchEntryIndex = 0;
|
|
216
|
+
/**
|
|
217
|
+
contentIndex → toolName (recorded on toolcall_start).
|
|
218
|
+
*/
|
|
219
|
+
private readonly contentNames = new Map<number, string>();
|
|
220
|
+
/**
|
|
221
|
+
contentIndex → renderer/tool call id.
|
|
222
|
+
*/
|
|
223
|
+
private readonly contentToolCallIds = new Map<number, string>();
|
|
224
|
+
/**
|
|
225
|
+
Annotations queued until a streamed content item exposes its id.
|
|
226
|
+
*/
|
|
227
|
+
private readonly pendingToolCallAnnotations = new Map<number, ToolCallAnnotation[]>();
|
|
228
|
+
private readonly emittedToolCallAnnotationKinds = new Map<
|
|
229
|
+
number,
|
|
230
|
+
Set<ToolCallAnnotation["kind"]>
|
|
231
|
+
>();
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
contentIndex → tool was aborted in toolcall_delta (skip toolcall_end dispatch).
|
|
235
|
+
*/
|
|
236
|
+
private readonly abortedContentIndices = new Set<number>();
|
|
237
|
+
/**
|
|
238
|
+
Serialize asynchronous handler dispatch for each streamed content item.
|
|
239
|
+
*/
|
|
240
|
+
private readonly dispatchQueues = new Map<number, Promise<GuardInterception | undefined>>();
|
|
241
|
+
/**
|
|
242
|
+
Abort listeners installed for active content items.
|
|
243
|
+
*/
|
|
244
|
+
private readonly abortCleanups = new Map<number, () => void>();
|
|
245
|
+
/**
|
|
246
|
+
Stream events already dispatched by the provider wrapper.
|
|
247
|
+
*/
|
|
248
|
+
private readonly processedStreamEvents = new WeakSet<object>();
|
|
249
|
+
/**
|
|
250
|
+
Provider events may be cloned before message_update; track tool events by stable identity too.
|
|
251
|
+
*/
|
|
252
|
+
private readonly processedStreamEventKeys = new Map<string, number>();
|
|
253
|
+
/**
|
|
254
|
+
Original streamed arguments and the result returned by a guard.
|
|
255
|
+
*/
|
|
256
|
+
private readonly toolCallRecords = new Map<string, GuardCallRecord>();
|
|
257
|
+
private blockedCallSink: BlockedToolCallSink | undefined;
|
|
258
|
+
constructor(private readonly pi: ExtensionAPI) {
|
|
259
|
+
pi.on("tool_call", (event) => {
|
|
260
|
+
const record = this.toolCallRecords.get(event.toolCallId);
|
|
261
|
+
const guardResult = record?.blockExecution ? record.guardResult : undefined;
|
|
262
|
+
|
|
263
|
+
if (!guardResult) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
254
266
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
267
|
+
const reason = guardResult.content
|
|
268
|
+
.filter((content) => content.type === "text")
|
|
269
|
+
.map((content) => content.text)
|
|
270
|
+
.join("\n");
|
|
259
271
|
|
|
260
|
-
|
|
261
|
-
|
|
272
|
+
return {
|
|
273
|
+
block: true,
|
|
274
|
+
reason: reason || `Tool call ${event.toolName} was blocked by a streaming interceptor.`,
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
pi.on("tool_result", (event) => {
|
|
278
|
+
const batchEntryIndex = this.toolCallBatchEntryIndexes.get(event.toolCallId);
|
|
262
279
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this.annotateIncompleteCalls();
|
|
267
|
-
|
|
268
|
-
if (event.message.role !== "assistant")
|
|
269
|
-
{
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const reason = this.pendingAbortReason;
|
|
274
|
-
this.pendingAbortReason = undefined;
|
|
275
|
-
|
|
276
|
-
if (reason === undefined || event.message.stopReason !== "aborted")
|
|
277
|
-
{
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return {
|
|
282
|
-
message: {
|
|
283
|
-
...event.message,
|
|
284
|
-
errorMessage: reason,
|
|
285
|
-
},
|
|
286
|
-
};
|
|
287
|
-
});
|
|
280
|
+
if (batchEntryIndex !== undefined) {
|
|
281
|
+
this.completedBatchEntryIndexes.add(batchEntryIndex);
|
|
282
|
+
}
|
|
288
283
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
await this.finalizeRecovery();
|
|
292
|
-
|
|
293
|
-
for (const [contentIndex, entry] of this.streamedBatchEntries)
|
|
294
|
-
{
|
|
295
|
-
if (
|
|
296
|
-
!entry.complete
|
|
297
|
-
&& !this.recoveryAppliedBatchIndexes.has(entry.index)
|
|
298
|
-
&& !this.emittedToolCallAnnotationKinds.get(contentIndex)?.has("stale-anchor")
|
|
299
|
-
)
|
|
300
|
-
{
|
|
301
|
-
this.annotateContent(contentIndex, { kind: "aborted" });
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
this.cleanupAll();
|
|
306
|
-
});
|
|
307
|
-
}
|
|
284
|
+
const guardResult = this.toolCallRecords.get(event.toolCallId)?.guardResult;
|
|
285
|
+
this.toolCallRecords.delete(event.toolCallId);
|
|
308
286
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
{
|
|
317
|
-
const batchEntryIndex = this.getOrCreateBatchEntryIndex(event.contentIndex);
|
|
318
|
-
this.contentNames.set(event.contentIndex, block.name);
|
|
319
|
-
|
|
320
|
-
if (typeof block.id === "string")
|
|
321
|
-
{
|
|
322
|
-
this.bindToolCallId(event.contentIndex, block.id);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
this.partialBuffers.set(event.contentIndex, "");
|
|
326
|
-
this.streamedBatchEntries.set(event.contentIndex, {
|
|
327
|
-
index: batchEntryIndex,
|
|
328
|
-
toolName: block.name,
|
|
329
|
-
args: {},
|
|
330
|
-
complete: false,
|
|
331
|
-
});
|
|
332
|
-
this.installAbortCleanup(event.contentIndex, ctx.signal);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return Promise.resolve(undefined as GuardInterception | undefined);
|
|
336
|
-
}
|
|
287
|
+
if (guardResult) {
|
|
288
|
+
return {
|
|
289
|
+
content: guardResult.content,
|
|
290
|
+
details: guardResult.details,
|
|
291
|
+
isError: true,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
337
294
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
const toolName = this.contentNames.get(event.contentIndex);
|
|
343
|
-
const toolCallId = this.contentToolCallIds.get(event.contentIndex);
|
|
344
|
-
|
|
345
|
-
if (!toolName)
|
|
346
|
-
{
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const buffer = (this.partialBuffers.get(event.contentIndex) ?? "") + event.delta;
|
|
351
|
-
this.partialBuffers.set(event.contentIndex, buffer);
|
|
352
|
-
this.installAbortCleanup(event.contentIndex, ctx.signal);
|
|
353
|
-
const partialArgs = resolvePartial(buffer, Allow.OBJ | Allow.ARR) ?? {};
|
|
354
|
-
const completeArgs = parseCompleteArguments(buffer);
|
|
355
|
-
const batchEntryIndex = this.getOrCreateBatchEntryIndex(event.contentIndex);
|
|
356
|
-
this.streamedBatchEntries.set(event.contentIndex, {
|
|
357
|
-
index: batchEntryIndex,
|
|
358
|
-
toolName,
|
|
359
|
-
args: partialArgs,
|
|
360
|
-
complete: completeArgs !== undefined,
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
const handlers = this.handlers.get(toolName);
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
!toolCallId || !handlers || handlers.length === 0
|
|
367
|
-
|| (!completeArgs && Object.keys(partialArgs).length === 0)
|
|
368
|
-
)
|
|
369
|
-
{
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const hasCompleteArgs = completeArgs !== undefined;
|
|
374
|
-
|
|
375
|
-
if (hasCompleteArgs && this.completeArgumentContentIndices.has(event.contentIndex))
|
|
376
|
-
{
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (hasCompleteArgs)
|
|
381
|
-
{
|
|
382
|
-
this.completeArgumentContentIndices.add(event.contentIndex);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const args = completeArgs ?? partialArgs;
|
|
386
|
-
const interception = await this.dispatchHandlers(handlers, {
|
|
387
|
-
toolCall: { id: toolCallId, name: toolName, arguments: args },
|
|
388
|
-
args,
|
|
389
|
-
...(hasCompleteArgs ? {} : { partialArgs }),
|
|
390
|
-
batchEntryIndex,
|
|
391
|
-
batchEntries: this.getBatchEntries(batchEntryIndex),
|
|
392
|
-
contentIndex: event.contentIndex,
|
|
393
|
-
cwd: ctx.cwd,
|
|
394
|
-
signal: ctx.signal,
|
|
395
|
-
ctx,
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
if (interception)
|
|
399
|
-
{
|
|
400
|
-
this.rememberOriginalArguments(interception.toolCallId, interception.arguments);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return interception;
|
|
404
|
-
});
|
|
405
|
-
}
|
|
295
|
+
return;
|
|
296
|
+
});
|
|
297
|
+
pi.on("message_update", async (event, context) => {
|
|
298
|
+
const streamEvent = event.assistantMessageEvent;
|
|
406
299
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
{
|
|
411
|
-
const toolName = event.toolCall.name;
|
|
412
|
-
const handlers = this.handlers.get(toolName);
|
|
413
|
-
const batchEntryIndex = this.getOrCreateBatchEntryIndex(event.contentIndex);
|
|
414
|
-
this.bindToolCallId(event.contentIndex, event.toolCall.id);
|
|
415
|
-
const previous = this.toolCallRecords.get(event.toolCall.id);
|
|
416
|
-
this.toolCallRecords.set(event.toolCall.id, {
|
|
417
|
-
originalArguments: structuredClone(event.toolCall.arguments),
|
|
418
|
-
...(previous?.guardResult ? { guardResult: previous.guardResult } : {}),
|
|
419
|
-
...(previous?.blockExecution ? { blockExecution: true } : {}),
|
|
420
|
-
});
|
|
421
|
-
this.streamedBatchEntries.set(event.contentIndex, {
|
|
422
|
-
index: batchEntryIndex,
|
|
423
|
-
toolName,
|
|
424
|
-
args: event.toolCall.arguments,
|
|
425
|
-
complete: false,
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
const shouldIntercept = !this.completeArgumentContentIndices.has(event.contentIndex);
|
|
429
|
-
let interception: GuardInterception | undefined;
|
|
430
|
-
|
|
431
|
-
if (shouldIntercept)
|
|
432
|
-
{
|
|
433
|
-
this.completeArgumentContentIndices.add(event.contentIndex);
|
|
434
|
-
interception = handlers && handlers.length > 0
|
|
435
|
-
? await this.dispatchHandlers(handlers, {
|
|
436
|
-
toolCall: event.toolCall,
|
|
437
|
-
args: event.toolCall.arguments,
|
|
438
|
-
batchEntryIndex,
|
|
439
|
-
batchEntries: this.getBatchEntries(batchEntryIndex),
|
|
440
|
-
contentIndex: event.contentIndex,
|
|
441
|
-
cwd: ctx.cwd,
|
|
442
|
-
signal: ctx.signal,
|
|
443
|
-
ctx,
|
|
444
|
-
})
|
|
445
|
-
: undefined;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
const batchEntry = this.streamedBatchEntries.get(event.contentIndex);
|
|
449
|
-
|
|
450
|
-
if (batchEntry)
|
|
451
|
-
{
|
|
452
|
-
this.streamedBatchEntries.set(event.contentIndex, { ...batchEntry, complete: true });
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
this.cleanupContent(event.contentIndex, toolName);
|
|
456
|
-
return interception;
|
|
457
|
-
});
|
|
458
|
-
}
|
|
300
|
+
if (this.consumeProcessedStreamEvent(streamEvent)) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
459
303
|
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
markStreamEventProcessed(event: AssistantStreamEvent): void
|
|
463
|
-
{
|
|
464
|
-
this.processedStreamEvents.add(event);
|
|
465
|
-
const key = toolStreamEventKey(event);
|
|
466
|
-
|
|
467
|
-
if (key !== undefined)
|
|
468
|
-
{
|
|
469
|
-
this.processedStreamEventKeys.set(key, (this.processedStreamEventKeys.get(key) ?? 0) + 1);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
304
|
+
await this.processStreamEvent(streamEvent, context);
|
|
305
|
+
});
|
|
472
306
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
const key = toolStreamEventKey(event);
|
|
307
|
+
pi.on("message_end", async (event) => {
|
|
308
|
+
await this.finalizeRecovery();
|
|
309
|
+
this.annotateIncompleteCalls();
|
|
477
310
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
311
|
+
if (event.message.role !== "assistant") {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
482
314
|
|
|
483
|
-
|
|
315
|
+
const reason = this.pendingAbortReason;
|
|
316
|
+
this.pendingAbortReason = undefined;
|
|
484
317
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
318
|
+
if (reason === undefined || event.message.stopReason !== "aborted") {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
489
321
|
|
|
490
|
-
|
|
491
|
-
{
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
322
|
+
return {
|
|
323
|
+
message: {
|
|
324
|
+
...event.message,
|
|
325
|
+
errorMessage: reason,
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
});
|
|
498
329
|
|
|
499
|
-
|
|
500
|
-
|
|
330
|
+
pi.on("agent_end", async () => {
|
|
331
|
+
await this.finalizeRecovery();
|
|
501
332
|
|
|
502
|
-
|
|
503
|
-
{
|
|
504
|
-
this.cleanupTransientContent(contentIndex, undefined, true);
|
|
505
|
-
}
|
|
333
|
+
this.annotateIncompleteCalls();
|
|
506
334
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
335
|
+
this.cleanupAll();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
511
338
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
this.toolCallRecords.set(toolCallId, {
|
|
519
|
-
originalArguments: structuredClone(originalArguments),
|
|
520
|
-
...(record.guardResult ? { guardResult: record.guardResult } : {}),
|
|
521
|
-
...(record.blockExecution ? { blockExecution: true } : {}),
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
}
|
|
339
|
+
processStreamEvent(
|
|
340
|
+
event: AssistantStreamEvent,
|
|
341
|
+
context: ExtensionContext,
|
|
342
|
+
): Promise<GuardInterception | undefined> {
|
|
343
|
+
if (event.type === "toolcall_start") {
|
|
344
|
+
const block = event.partial.content[event.contentIndex];
|
|
525
345
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
{
|
|
533
|
-
const result = await handler.intercept(ctx);
|
|
534
|
-
|
|
535
|
-
if (result !== undefined)
|
|
536
|
-
{
|
|
537
|
-
this.pendingRecoveryBlocks.push({ blocked: result, ctx });
|
|
538
|
-
const guardResult: AgentToolResult<unknown> = {
|
|
539
|
-
content: [{ type: "text", text: result.message.content }],
|
|
540
|
-
details: result.message.details ?? null,
|
|
541
|
-
};
|
|
542
|
-
this.blockedCallSink?.({
|
|
543
|
-
callId: ctx.toolCall.id,
|
|
544
|
-
toolName: ctx.toolCall.name,
|
|
545
|
-
arguments: structuredClone(ctx.args),
|
|
546
|
-
...(ctx.contentIndex === undefined ? {} : { contentIndex: ctx.contentIndex }),
|
|
547
|
-
...(ctx.batchEntryIndex === undefined ? {} : { batchEntryIndex: ctx.batchEntryIndex }),
|
|
548
|
-
...(result.message.details === undefined ? {} : { details: result.message.details }),
|
|
549
|
-
result: guardResult,
|
|
550
|
-
nativeExecutionBlocked: handler.blockExecution === true,
|
|
551
|
-
});
|
|
552
|
-
return {
|
|
553
|
-
toolCallId: ctx.toolCall.id,
|
|
554
|
-
arguments: structuredClone(ctx.args),
|
|
555
|
-
result: this.abortToolCall(result, ctx, handler.name, handler.blockExecution === true),
|
|
556
|
-
};
|
|
557
|
-
}
|
|
346
|
+
if (block?.type === "toolCall") {
|
|
347
|
+
const batchEntryIndex = this.getOrCreateBatchEntryIndex(event.contentIndex);
|
|
348
|
+
this.contentNames.set(event.contentIndex, block.name);
|
|
349
|
+
|
|
350
|
+
if (typeof block.id === "string") {
|
|
351
|
+
this.bindToolCallId(event.contentIndex, block.id);
|
|
558
352
|
}
|
|
559
353
|
|
|
560
|
-
|
|
354
|
+
this.partialBuffers.set(event.contentIndex, "");
|
|
355
|
+
this.streamedBatchEntries.set(event.contentIndex, {
|
|
356
|
+
index: batchEntryIndex,
|
|
357
|
+
toolName: block.name,
|
|
358
|
+
args: {},
|
|
359
|
+
complete: false,
|
|
360
|
+
});
|
|
361
|
+
this.installAbortCleanup(event.contentIndex, context.signal);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return Promise.resolve(undefined as GuardInterception | undefined);
|
|
561
365
|
}
|
|
562
|
-
|
|
563
|
-
{
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
)
|
|
571
|
-
{
|
|
572
|
-
this.annotateContent(contentIndex, { kind: "aborted" });
|
|
573
|
-
}
|
|
366
|
+
|
|
367
|
+
if (event.type === "toolcall_delta") {
|
|
368
|
+
return this.enqueue(event.contentIndex, async () => {
|
|
369
|
+
const toolName = this.contentNames.get(event.contentIndex);
|
|
370
|
+
const toolCallId = this.contentToolCallIds.get(event.contentIndex);
|
|
371
|
+
|
|
372
|
+
if (!toolName) {
|
|
373
|
+
return;
|
|
574
374
|
}
|
|
575
|
-
}
|
|
576
375
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
this.
|
|
580
|
-
const
|
|
376
|
+
const buffer = (this.partialBuffers.get(event.contentIndex) ?? "") + event.delta;
|
|
377
|
+
this.partialBuffers.set(event.contentIndex, buffer);
|
|
378
|
+
this.installAbortCleanup(event.contentIndex, context.signal);
|
|
379
|
+
const partialArguments = resolvePartial(buffer, Allow.OBJ | Allow.ARR) ?? {};
|
|
380
|
+
const completeArguments = parseCompleteArguments(buffer);
|
|
381
|
+
const batchEntryIndex = this.getOrCreateBatchEntryIndex(event.contentIndex);
|
|
382
|
+
this.streamedBatchEntries.set(event.contentIndex, {
|
|
383
|
+
index: batchEntryIndex,
|
|
384
|
+
toolName,
|
|
385
|
+
args: partialArguments,
|
|
386
|
+
complete: completeArguments !== undefined,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
const handlers = this.handlers.get(toolName);
|
|
581
390
|
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
|
|
391
|
+
if (
|
|
392
|
+
!toolCallId ||
|
|
393
|
+
!handlers ||
|
|
394
|
+
handlers.length === 0 ||
|
|
395
|
+
(!completeArguments && Object.keys(partialArguments).length === 0)
|
|
396
|
+
) {
|
|
397
|
+
return;
|
|
585
398
|
}
|
|
586
399
|
|
|
587
|
-
const
|
|
400
|
+
const hasCompleteArguments = completeArguments !== undefined;
|
|
401
|
+
|
|
402
|
+
if (hasCompleteArguments && this.completeArgumentContentIndices.has(event.contentIndex)) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
588
405
|
|
|
589
|
-
if (
|
|
590
|
-
|
|
591
|
-
return;
|
|
406
|
+
if (hasCompleteArguments) {
|
|
407
|
+
this.completeArgumentContentIndices.add(event.contentIndex);
|
|
592
408
|
}
|
|
593
409
|
|
|
594
|
-
|
|
595
|
-
{
|
|
596
|
-
|
|
410
|
+
const arguments_ = completeArguments ?? partialArguments;
|
|
411
|
+
const interception = await this.dispatchHandlers(handlers, {
|
|
412
|
+
toolCall: { id: toolCallId, name: toolName, arguments: arguments_ },
|
|
413
|
+
args: arguments_,
|
|
414
|
+
...(!hasCompleteArguments && { partialArgs: partialArguments }),
|
|
415
|
+
batchEntryIndex,
|
|
416
|
+
batchEntries: this.getBatchEntries(batchEntryIndex),
|
|
417
|
+
contentIndex: event.contentIndex,
|
|
418
|
+
cwd: context.cwd,
|
|
419
|
+
signal: context.signal,
|
|
420
|
+
ctx: context,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
if (interception) {
|
|
424
|
+
this.rememberOriginalArguments(interception.toolCallId, interception.arguments);
|
|
597
425
|
}
|
|
598
426
|
|
|
599
|
-
|
|
427
|
+
return interception;
|
|
428
|
+
});
|
|
600
429
|
}
|
|
601
430
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const
|
|
431
|
+
if (event.type === "toolcall_end") {
|
|
432
|
+
return this.enqueue(event.contentIndex, async () => {
|
|
433
|
+
const toolName = event.toolCall.name;
|
|
434
|
+
const handlers = this.handlers.get(toolName);
|
|
435
|
+
const batchEntryIndex = this.getOrCreateBatchEntryIndex(event.contentIndex);
|
|
436
|
+
this.bindToolCallId(event.contentIndex, event.toolCall.id);
|
|
437
|
+
const previous = this.toolCallRecords.get(event.toolCall.id);
|
|
438
|
+
this.toolCallRecords.set(event.toolCall.id, {
|
|
439
|
+
originalArguments: structuredClone(event.toolCall.arguments),
|
|
440
|
+
...(previous?.guardResult && { guardResult: previous.guardResult }),
|
|
441
|
+
...(previous?.blockExecution && { blockExecution: true }),
|
|
442
|
+
});
|
|
443
|
+
this.streamedBatchEntries.set(event.contentIndex, {
|
|
444
|
+
index: batchEntryIndex,
|
|
445
|
+
toolName,
|
|
446
|
+
args: event.toolCall.arguments,
|
|
447
|
+
complete: false,
|
|
448
|
+
});
|
|
605
449
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
450
|
+
const shouldIntercept = !this.completeArgumentContentIndices.has(event.contentIndex);
|
|
451
|
+
let interception: GuardInterception | undefined;
|
|
452
|
+
|
|
453
|
+
if (shouldIntercept) {
|
|
454
|
+
this.completeArgumentContentIndices.add(event.contentIndex);
|
|
455
|
+
interception =
|
|
456
|
+
handlers && handlers.length > 0
|
|
457
|
+
? await this.dispatchHandlers(handlers, {
|
|
458
|
+
toolCall: event.toolCall,
|
|
459
|
+
args: event.toolCall.arguments,
|
|
460
|
+
batchEntryIndex,
|
|
461
|
+
batchEntries: this.getBatchEntries(batchEntryIndex),
|
|
462
|
+
contentIndex: event.contentIndex,
|
|
463
|
+
cwd: context.cwd,
|
|
464
|
+
signal: context.signal,
|
|
465
|
+
ctx: context,
|
|
466
|
+
})
|
|
467
|
+
: undefined;
|
|
609
468
|
}
|
|
610
469
|
|
|
611
|
-
|
|
612
|
-
this.emittedToolCallAnnotationKinds.set(contentIndex, emitted);
|
|
613
|
-
|
|
614
|
-
const toolCallId = this.contentToolCallIds.get(contentIndex);
|
|
470
|
+
const batchEntry = this.streamedBatchEntries.get(event.contentIndex);
|
|
615
471
|
|
|
616
|
-
if (
|
|
617
|
-
|
|
618
|
-
this.emitToolCallAnnotation(toolCallId, annotation);
|
|
619
|
-
return;
|
|
472
|
+
if (batchEntry) {
|
|
473
|
+
this.streamedBatchEntries.set(event.contentIndex, { ...batchEntry, complete: true });
|
|
620
474
|
}
|
|
621
475
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
476
|
+
this.cleanupContent(event.contentIndex, toolName);
|
|
477
|
+
return interception;
|
|
478
|
+
});
|
|
625
479
|
}
|
|
626
480
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
481
|
+
return Promise.resolve(undefined as GuardInterception | undefined);
|
|
482
|
+
}
|
|
483
|
+
markStreamEventProcessed(event: AssistantStreamEvent): void {
|
|
484
|
+
this.processedStreamEvents.add(event);
|
|
485
|
+
const key = toolStreamEventKey(event);
|
|
486
|
+
|
|
487
|
+
if (key !== undefined) {
|
|
488
|
+
this.processedStreamEventKeys.set(key, (this.processedStreamEventKeys.get(key) ?? 0) + 1);
|
|
631
489
|
}
|
|
490
|
+
}
|
|
632
491
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
492
|
+
private consumeProcessedStreamEvent(event: AssistantStreamEvent): boolean {
|
|
493
|
+
const isSameEvent = this.processedStreamEvents.delete(event);
|
|
494
|
+
const key = toolStreamEventKey(event);
|
|
636
495
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
496
|
+
if (key === undefined) {
|
|
497
|
+
return isSameEvent;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const count = this.processedStreamEventKeys.get(key) ?? 0;
|
|
641
501
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
this.batchEntryIndexes.set(contentIndex, created);
|
|
645
|
-
return created;
|
|
502
|
+
if (count === 0) {
|
|
503
|
+
return isSameEvent;
|
|
646
504
|
}
|
|
647
505
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
.sort((left, right) => left.index - right.index);
|
|
506
|
+
if (count === 1) {
|
|
507
|
+
this.processedStreamEventKeys.delete(key);
|
|
508
|
+
} else {
|
|
509
|
+
this.processedStreamEventKeys.set(key, count - 1);
|
|
653
510
|
}
|
|
654
511
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
finalizeStreamInterception(contentIndex: number): void {
|
|
516
|
+
this.cleanupTransientContent(contentIndex, undefined, true);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
getToolCallRecord(toolCallId: string): GuardCallRecord | undefined {
|
|
520
|
+
return this.toolCallRecords.get(toolCallId);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private rememberOriginalArguments(
|
|
524
|
+
toolCallId: string,
|
|
525
|
+
originalArguments: Record<string, unknown>,
|
|
526
|
+
): void {
|
|
527
|
+
const record = this.toolCallRecords.get(toolCallId);
|
|
528
|
+
|
|
529
|
+
if (record) {
|
|
530
|
+
this.toolCallRecords.set(toolCallId, {
|
|
531
|
+
originalArguments: structuredClone(originalArguments),
|
|
532
|
+
...(record.guardResult && { guardResult: record.guardResult }),
|
|
533
|
+
...(record.blockExecution && { blockExecution: true }),
|
|
534
|
+
});
|
|
659
535
|
}
|
|
536
|
+
}
|
|
660
537
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
{
|
|
668
|
-
const reason = abortReason(result, handlerName);
|
|
669
|
-
const annotation: ToolCallAnnotation = result.annotation
|
|
670
|
-
? result.annotation.kind === "aborted" && result.annotation.label === undefined
|
|
671
|
-
? { ...result.annotation, label: reason }
|
|
672
|
-
: result.annotation
|
|
673
|
-
: (result.message.customType === "text-editor-stale-anchor-block"
|
|
674
|
-
? { kind: "stale-anchor", label: reason }
|
|
675
|
-
: { kind: "aborted", label: reason, color: "error" });
|
|
676
|
-
|
|
677
|
-
if (ctx.contentIndex !== undefined)
|
|
678
|
-
{
|
|
679
|
-
this.abortedContentIndices.add(ctx.contentIndex);
|
|
680
|
-
this.annotateContent(ctx.contentIndex, annotation);
|
|
681
|
-
}
|
|
538
|
+
private async dispatchHandlers(
|
|
539
|
+
handlers: readonly ToolCallInterceptorHandler[],
|
|
540
|
+
context: InterceptorContext,
|
|
541
|
+
): Promise<GuardInterception | undefined> {
|
|
542
|
+
for (const handler of handlers) {
|
|
543
|
+
const result = await handler.intercept(context);
|
|
682
544
|
|
|
545
|
+
if (result !== undefined) {
|
|
546
|
+
this.pendingRecoveryBlocks.push({ blocked: result, ctx: context });
|
|
683
547
|
const guardResult: AgentToolResult<unknown> = {
|
|
684
|
-
|
|
685
|
-
|
|
548
|
+
content: [{ type: "text", text: result.message.content }],
|
|
549
|
+
details: result.message.details ?? null,
|
|
686
550
|
};
|
|
687
|
-
this.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
551
|
+
this.blockedCallSink?.({
|
|
552
|
+
callId: context.toolCall.id,
|
|
553
|
+
toolName: context.toolCall.name,
|
|
554
|
+
arguments: structuredClone(context.args),
|
|
555
|
+
...(context.contentIndex !== undefined && { contentIndex: context.contentIndex }),
|
|
556
|
+
...(context.batchEntryIndex !== undefined && {
|
|
557
|
+
batchEntryIndex: context.batchEntryIndex,
|
|
558
|
+
}),
|
|
559
|
+
...(result.message.details !== undefined && { details: result.message.details }),
|
|
560
|
+
result: guardResult,
|
|
561
|
+
nativeExecutionBlocked: handler.blockExecution === true,
|
|
691
562
|
});
|
|
692
|
-
return
|
|
563
|
+
return {
|
|
564
|
+
toolCallId: context.toolCall.id,
|
|
565
|
+
arguments: structuredClone(context.args),
|
|
566
|
+
result: this.abortToolCall(
|
|
567
|
+
result,
|
|
568
|
+
context,
|
|
569
|
+
handler.name,
|
|
570
|
+
handler.blockExecution === true,
|
|
571
|
+
),
|
|
572
|
+
};
|
|
573
|
+
}
|
|
693
574
|
}
|
|
694
575
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
576
|
+
return undefined;
|
|
577
|
+
}
|
|
578
|
+
private annotateIncompleteCalls(): void {
|
|
579
|
+
for (const [contentIndex, entry] of this.streamedBatchEntries) {
|
|
580
|
+
// Contents whose transient state was already cleaned up ended one way or
|
|
581
|
+
// another; re-annotating them would leak the annotation onto the next
|
|
582
|
+
// call that reuses the same content index.
|
|
583
|
+
if (
|
|
584
|
+
!entry.complete &&
|
|
585
|
+
this.contentNames.has(contentIndex) &&
|
|
586
|
+
!this.recoveryAppliedBatchIndexes.has(entry.index) &&
|
|
587
|
+
!this.emittedToolCallAnnotationKinds.get(contentIndex)?.has("stale-anchor")
|
|
588
|
+
) {
|
|
589
|
+
this.annotateContent(contentIndex, { kind: "aborted" });
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
705
593
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
594
|
+
private bindToolCallId(contentIndex: number, toolCallId: string): void {
|
|
595
|
+
this.contentToolCallIds.set(contentIndex, toolCallId);
|
|
596
|
+
const batchEntryIndex = this.batchEntryIndexes.get(contentIndex);
|
|
709
597
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
598
|
+
if (batchEntryIndex !== undefined) {
|
|
599
|
+
this.toolCallBatchEntryIndexes.set(toolCallId, batchEntryIndex);
|
|
600
|
+
}
|
|
714
601
|
|
|
715
|
-
|
|
716
|
-
group.push(block);
|
|
717
|
-
groups.set(recoveryKey, group);
|
|
718
|
-
}
|
|
602
|
+
const pending = this.pendingToolCallAnnotations.get(contentIndex);
|
|
719
603
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const first = group[0];
|
|
723
|
-
|
|
724
|
-
if (!first)
|
|
725
|
-
{
|
|
726
|
-
continue;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
const finalResult = await this.recoverIfNeeded(
|
|
730
|
-
first.blocked,
|
|
731
|
-
first.ctx,
|
|
732
|
-
this.getAllBatchEntries(),
|
|
733
|
-
group,
|
|
734
|
-
);
|
|
735
|
-
|
|
736
|
-
if (finalResult === first.blocked)
|
|
737
|
-
{
|
|
738
|
-
continue;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
const details = finalResult.message.details;
|
|
742
|
-
const recovery = Guard.IsObjectNotArray(details) && Guard.IsObjectNotArray(details.recovery)
|
|
743
|
-
? details.recovery
|
|
744
|
-
: undefined;
|
|
745
|
-
const appliedEntries = recovery?.appliedEntries;
|
|
746
|
-
|
|
747
|
-
if (Array.isArray(appliedEntries))
|
|
748
|
-
{
|
|
749
|
-
for (const index of appliedEntries)
|
|
750
|
-
{
|
|
751
|
-
if (typeof index === "number")
|
|
752
|
-
{
|
|
753
|
-
this.recoveryAppliedBatchIndexes.add(index);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
}
|
|
604
|
+
if (!pending) {
|
|
605
|
+
return;
|
|
758
606
|
}
|
|
759
607
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
finalBatchEntries: readonly PartialToolRecoveryBatchEntry[],
|
|
764
|
-
blocks: readonly PendingRecoveryBlock[],
|
|
765
|
-
): Promise<InterceptResult>
|
|
766
|
-
{
|
|
767
|
-
if (ctx.contentIndex === undefined)
|
|
768
|
-
{
|
|
769
|
-
return result;
|
|
770
|
-
}
|
|
608
|
+
for (const annotation of pending) {
|
|
609
|
+
this.emitToolCallAnnotation(toolCallId, annotation);
|
|
610
|
+
}
|
|
771
611
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
? details.entryIndex
|
|
775
|
-
: undefined;
|
|
776
|
-
const blockedEntryIndexes = [
|
|
777
|
-
...new Set(
|
|
778
|
-
blocks
|
|
779
|
-
.map((block) => block.ctx.batchEntryIndex)
|
|
780
|
-
.filter((index): index is number => index !== undefined),
|
|
781
|
-
),
|
|
782
|
-
];
|
|
783
|
-
const blockedToolCallIds = [...new Set(blocks.map((block) => block.ctx.toolCall.id))];
|
|
784
|
-
const blockedDetails = blocks.map((block) => block.blocked.message.details);
|
|
785
|
-
const first = blocks[0];
|
|
786
|
-
const recoveryKey = first
|
|
787
|
-
? this.recoveryRegistry.recoveryKeyFor(first.ctx.toolCall.name)
|
|
788
|
-
: undefined;
|
|
789
|
-
|
|
790
|
-
if (!recoveryKey)
|
|
791
|
-
{
|
|
792
|
-
return result;
|
|
793
|
-
}
|
|
612
|
+
this.pendingToolCallAnnotations.delete(contentIndex);
|
|
613
|
+
}
|
|
794
614
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
...(staleEntryIndex === undefined ? {} : { staleEntryIndex }),
|
|
800
|
-
staleDetails: details,
|
|
801
|
-
...(ctx.partialArgs ? { partialArgs: ctx.partialArgs } : {}),
|
|
802
|
-
args: ctx.args,
|
|
803
|
-
batchEntries: finalBatchEntries,
|
|
804
|
-
...(ctx.batchEntryIndex === undefined ? {} : { batchEntryIndex: ctx.batchEntryIndex }),
|
|
805
|
-
recoverCompleteBatch: true,
|
|
806
|
-
completedEntryIndexes: [...this.completedBatchEntryIndexes],
|
|
807
|
-
blockedEntryIndexes,
|
|
808
|
-
blockedToolCallIds,
|
|
809
|
-
blockedDetails,
|
|
810
|
-
recoveryKey,
|
|
811
|
-
cwd: ctx.cwd,
|
|
812
|
-
ctx: ctx.ctx,
|
|
813
|
-
});
|
|
615
|
+
private annotateContent(contentIndex: number, annotation: ToolCallAnnotation): void {
|
|
616
|
+
const emitted =
|
|
617
|
+
this.emittedToolCallAnnotationKinds.get(contentIndex) ??
|
|
618
|
+
new Set<ToolCallAnnotation["kind"]>();
|
|
814
619
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
: result;
|
|
620
|
+
if (emitted.has(annotation.kind)) {
|
|
621
|
+
return;
|
|
818
622
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
try
|
|
830
|
-
{
|
|
831
|
-
return await current;
|
|
832
|
-
}
|
|
833
|
-
finally
|
|
834
|
-
{
|
|
835
|
-
if (this.dispatchQueues.get(contentIndex) === current)
|
|
836
|
-
{
|
|
837
|
-
this.dispatchQueues.delete(contentIndex);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
623
|
+
|
|
624
|
+
emitted.add(annotation.kind);
|
|
625
|
+
this.emittedToolCallAnnotationKinds.set(contentIndex, emitted);
|
|
626
|
+
|
|
627
|
+
const toolCallId = this.contentToolCallIds.get(contentIndex);
|
|
628
|
+
|
|
629
|
+
if (toolCallId) {
|
|
630
|
+
this.emitToolCallAnnotation(toolCallId, annotation);
|
|
631
|
+
return;
|
|
840
632
|
}
|
|
841
633
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
634
|
+
const pending = this.pendingToolCallAnnotations.get(contentIndex) ?? [];
|
|
635
|
+
pending.push(annotation);
|
|
636
|
+
this.pendingToolCallAnnotations.set(contentIndex, pending);
|
|
637
|
+
}
|
|
848
638
|
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
639
|
+
private emitToolCallAnnotation(toolCallId: string, annotation: ToolCallAnnotation): void {
|
|
640
|
+
const event = { toolCallId, annotation } satisfies ToolCallAnnotationEvent;
|
|
641
|
+
this.pi.events.emit(TOOL_CALL_ANNOTATION_EVENT, event);
|
|
642
|
+
}
|
|
853
643
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
handler.onAbort?.(contentIndex);
|
|
857
|
-
}
|
|
858
|
-
};
|
|
644
|
+
private getOrCreateBatchEntryIndex(contentIndex: number): number {
|
|
645
|
+
const existing = this.batchEntryIndexes.get(contentIndex);
|
|
859
646
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
{
|
|
863
|
-
signal.removeEventListener("abort", listener);
|
|
864
|
-
});
|
|
647
|
+
if (existing !== undefined) {
|
|
648
|
+
return existing;
|
|
865
649
|
}
|
|
866
650
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
651
|
+
const created = this.nextBatchEntryIndex;
|
|
652
|
+
this.nextBatchEntryIndex += 1;
|
|
653
|
+
this.batchEntryIndexes.set(contentIndex, created);
|
|
654
|
+
return created;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
private getBatchEntries(batchEntryIndex: number): readonly PartialToolRecoveryBatchEntry[] {
|
|
658
|
+
return [...this.streamedBatchEntries.values()]
|
|
659
|
+
.filter((entry) => entry.index <= batchEntryIndex)
|
|
660
|
+
.sort((left, right) => left.index - right.index);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
private getAllBatchEntries(): readonly PartialToolRecoveryBatchEntry[] {
|
|
664
|
+
return [...this.streamedBatchEntries.values()].sort((left, right) => left.index - right.index);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
private abortToolCall(
|
|
668
|
+
result: InterceptResult,
|
|
669
|
+
context: InterceptorContext,
|
|
670
|
+
handlerName: string,
|
|
671
|
+
blockExecution: boolean,
|
|
672
|
+
): AgentToolResult<unknown> {
|
|
673
|
+
const reason = abortReason(result, handlerName);
|
|
674
|
+
const annotation: ToolCallAnnotation = result.annotation
|
|
675
|
+
? result.annotation.kind === "aborted" && result.annotation.label === undefined
|
|
676
|
+
? { ...result.annotation, label: reason }
|
|
677
|
+
: result.annotation
|
|
678
|
+
: result.message.customType === "text-editor-stale-anchor-block"
|
|
679
|
+
? { kind: "stale-anchor", label: reason }
|
|
680
|
+
: { kind: "aborted", label: reason, color: "error" };
|
|
681
|
+
|
|
682
|
+
if (context.contentIndex !== undefined) {
|
|
683
|
+
this.abortedContentIndices.add(context.contentIndex);
|
|
684
|
+
this.annotateContent(context.contentIndex, annotation);
|
|
871
685
|
}
|
|
872
686
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
687
|
+
const guardResult: AgentToolResult<unknown> = {
|
|
688
|
+
content: [{ type: "text", text: result.message.content }],
|
|
689
|
+
details: withToolCallInterceptionDetails(result.message.details, annotation, reason),
|
|
690
|
+
};
|
|
691
|
+
this.toolCallRecords.set(context.toolCall.id, {
|
|
692
|
+
originalArguments: structuredClone(context.args),
|
|
693
|
+
guardResult,
|
|
694
|
+
...(blockExecution && { blockExecution: true }),
|
|
695
|
+
});
|
|
696
|
+
return guardResult;
|
|
697
|
+
}
|
|
884
698
|
|
|
885
|
-
|
|
886
|
-
|
|
699
|
+
private async finalizeRecovery(): Promise<void> {
|
|
700
|
+
const pending = this.pendingRecoveryBlocks.splice(0);
|
|
887
701
|
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
this.contentNames.delete(contentIndex);
|
|
891
|
-
this.contentToolCallIds.delete(contentIndex);
|
|
892
|
-
this.pendingToolCallAnnotations.delete(contentIndex);
|
|
893
|
-
this.emittedToolCallAnnotationKinds.delete(contentIndex);
|
|
894
|
-
this.completeArgumentContentIndices.delete(contentIndex);
|
|
895
|
-
this.partialBuffers.delete(contentIndex);
|
|
896
|
-
this.abortedContentIndices.delete(contentIndex);
|
|
702
|
+
if (pending.length === 0) {
|
|
703
|
+
return;
|
|
897
704
|
}
|
|
898
705
|
|
|
899
|
-
|
|
900
|
-
{
|
|
901
|
-
for (const handlers of this.handlers.values())
|
|
902
|
-
{
|
|
903
|
-
for (const handler of handlers)
|
|
904
|
-
{
|
|
905
|
-
handler.onAgentEnd?.();
|
|
906
|
-
}
|
|
907
|
-
}
|
|
706
|
+
const groups = new Map<string, PendingRecoveryBlock[]>();
|
|
908
707
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
cleanup();
|
|
912
|
-
}
|
|
708
|
+
for (const block of pending) {
|
|
709
|
+
const recoveryKey = this.recoveryRegistry.recoveryKeyFor(block.ctx.toolCall.name);
|
|
913
710
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
this.pendingToolCallAnnotations.clear();
|
|
918
|
-
this.completeArgumentContentIndices.clear();
|
|
919
|
-
this.emittedToolCallAnnotationKinds.clear();
|
|
920
|
-
this.partialBuffers.clear();
|
|
921
|
-
this.streamedBatchEntries.clear();
|
|
922
|
-
this.batchEntryIndexes.clear();
|
|
923
|
-
this.toolCallBatchEntryIndexes.clear();
|
|
924
|
-
this.toolCallRecords.clear();
|
|
925
|
-
this.completedBatchEntryIndexes.clear();
|
|
926
|
-
this.nextBatchEntryIndex = 0;
|
|
927
|
-
this.abortedContentIndices.clear();
|
|
928
|
-
this.pendingAbortReason = undefined;
|
|
929
|
-
this.dispatchQueues.clear();
|
|
930
|
-
this.processedStreamEventKeys.clear();
|
|
931
|
-
this.recoveryRegistry.cleanupAll();
|
|
932
|
-
this.pendingRecoveryBlocks.length = 0;
|
|
933
|
-
this.recoveryAppliedBatchIndexes.clear();
|
|
934
|
-
}
|
|
711
|
+
if (recoveryKey === undefined) {
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
935
714
|
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
715
|
+
const group = groups.get(recoveryKey) ?? [];
|
|
716
|
+
group.push(block);
|
|
717
|
+
groups.set(recoveryKey, group);
|
|
939
718
|
}
|
|
940
719
|
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
720
|
+
for (const group of groups.values()) {
|
|
721
|
+
const first = group[0];
|
|
722
|
+
|
|
723
|
+
if (!first) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
const finalResult = await this.recoverIfNeeded(
|
|
728
|
+
first.blocked,
|
|
729
|
+
first.ctx,
|
|
730
|
+
this.getAllBatchEntries(),
|
|
731
|
+
group,
|
|
732
|
+
);
|
|
733
|
+
|
|
734
|
+
if (finalResult === first.blocked) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const details = finalResult.message.details;
|
|
739
|
+
const recovery =
|
|
740
|
+
Guard.IsObjectNotArray(details) && Guard.IsObjectNotArray(details.recovery)
|
|
741
|
+
? details.recovery
|
|
742
|
+
: undefined;
|
|
743
|
+
const appliedEntries = recovery?.appliedEntries;
|
|
744
|
+
|
|
745
|
+
if (Array.isArray(appliedEntries)) {
|
|
746
|
+
for (const index of appliedEntries) {
|
|
747
|
+
if (typeof index === "number") {
|
|
748
|
+
this.recoveryAppliedBatchIndexes.add(index);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
private async recoverIfNeeded(
|
|
756
|
+
result: InterceptResult,
|
|
757
|
+
context: InterceptorContext,
|
|
758
|
+
finalBatchEntries: readonly PartialToolRecoveryBatchEntry[],
|
|
759
|
+
blocks: readonly PendingRecoveryBlock[],
|
|
760
|
+
): Promise<InterceptResult> {
|
|
761
|
+
if (context.contentIndex === undefined) {
|
|
762
|
+
return result;
|
|
944
763
|
}
|
|
945
764
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
765
|
+
const details = result.message.details;
|
|
766
|
+
const staleEntryIndex =
|
|
767
|
+
Guard.IsObjectNotArray(details) && typeof details.entryIndex === "number"
|
|
768
|
+
? details.entryIndex
|
|
769
|
+
: undefined;
|
|
770
|
+
const blockedEntryIndexes = [
|
|
771
|
+
...new Set(
|
|
772
|
+
blocks
|
|
773
|
+
.map((block) => block.ctx.batchEntryIndex)
|
|
774
|
+
.filter((index): index is number => index !== undefined),
|
|
775
|
+
),
|
|
776
|
+
];
|
|
777
|
+
const blockedToolCallIds = [...new Set(blocks.map((block) => block.ctx.toolCall.id))];
|
|
778
|
+
const blockedDetails = blocks.map((block) => block.blocked.message.details);
|
|
779
|
+
const first = blocks[0];
|
|
780
|
+
const recoveryKey = first
|
|
781
|
+
? this.recoveryRegistry.recoveryKeyFor(first.ctx.toolCall.name)
|
|
782
|
+
: undefined;
|
|
783
|
+
|
|
784
|
+
if (!recoveryKey) {
|
|
785
|
+
return result;
|
|
949
786
|
}
|
|
950
787
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
{
|
|
971
|
-
handlers.splice(index, 1);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
788
|
+
const recovery = await this.recoveryRegistry.recover({
|
|
789
|
+
contentIndex: context.contentIndex,
|
|
790
|
+
toolCallId: context.toolCall.id,
|
|
791
|
+
toolName: context.toolCall.name,
|
|
792
|
+
...(staleEntryIndex !== undefined && { staleEntryIndex }),
|
|
793
|
+
staleDetails: details,
|
|
794
|
+
...(context.partialArgs && { partialArgs: context.partialArgs }),
|
|
795
|
+
args: context.args,
|
|
796
|
+
batchEntries: finalBatchEntries,
|
|
797
|
+
...(context.batchEntryIndex !== undefined && { batchEntryIndex: context.batchEntryIndex }),
|
|
798
|
+
recoverCompleteBatch: true,
|
|
799
|
+
completedEntryIndexes: [...this.completedBatchEntryIndexes],
|
|
800
|
+
blockedEntryIndexes,
|
|
801
|
+
blockedToolCallIds,
|
|
802
|
+
blockedDetails,
|
|
803
|
+
recoveryKey,
|
|
804
|
+
cwd: context.cwd,
|
|
805
|
+
ctx: context.ctx,
|
|
806
|
+
});
|
|
974
807
|
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
808
|
+
return recovery && (recovery.appliedEntries.length > 0 || recovery.skippedEntries.length > 0)
|
|
809
|
+
? makeRecoveryResult(result, recovery)
|
|
810
|
+
: result;
|
|
811
|
+
}
|
|
812
|
+
private async enqueue(
|
|
813
|
+
contentIndex: number,
|
|
814
|
+
task: () => Promise<GuardInterception | undefined>,
|
|
815
|
+
): Promise<GuardInterception | undefined> {
|
|
816
|
+
const previous = this.dispatchQueues.get(contentIndex) ?? Promise.resolve();
|
|
817
|
+
const current = previous.catch(() => {}).then(task);
|
|
818
|
+
this.dispatchQueues.set(contentIndex, current);
|
|
819
|
+
|
|
820
|
+
try {
|
|
821
|
+
return await current;
|
|
822
|
+
} finally {
|
|
823
|
+
if (this.dispatchQueues.get(contentIndex) === current) {
|
|
824
|
+
this.dispatchQueues.delete(contentIndex);
|
|
825
|
+
}
|
|
981
826
|
}
|
|
827
|
+
}
|
|
982
828
|
|
|
983
|
-
|
|
984
|
-
{
|
|
985
|
-
|
|
986
|
-
{
|
|
987
|
-
this.handlers.set(toolName, handlers.filter((handler) => handler.name !== name));
|
|
988
|
-
}
|
|
829
|
+
private installAbortCleanup(contentIndex: number, signal: AbortSignal | undefined): void {
|
|
830
|
+
if (!signal || this.abortCleanups.has(contentIndex)) {
|
|
831
|
+
return;
|
|
989
832
|
}
|
|
990
|
-
}
|
|
991
833
|
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
{
|
|
996
|
-
return `${event.type}\u0000${event.contentIndex}\u0000${event.toolCall.id}`;
|
|
997
|
-
}
|
|
834
|
+
const listener = () => {
|
|
835
|
+
const toolName = this.contentNames.get(contentIndex);
|
|
836
|
+
const handlers = toolName ? this.handlers.get(toolName) : undefined;
|
|
998
837
|
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
}
|
|
838
|
+
for (const handler of handlers ?? []) {
|
|
839
|
+
handler.onAbort?.(contentIndex);
|
|
840
|
+
}
|
|
841
|
+
};
|
|
1003
842
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
}
|
|
843
|
+
signal.addEventListener("abort", listener, { once: true });
|
|
844
|
+
this.abortCleanups.set(contentIndex, () => {
|
|
845
|
+
signal.removeEventListener("abort", listener);
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
private cleanupContent(contentIndex: number, toolName?: string): void {
|
|
850
|
+
this.cleanupTransientContent(contentIndex, toolName);
|
|
851
|
+
this.recoveryRegistry.cleanup(contentIndex);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
private cleanupTransientContent(contentIndex: number, toolName?: string, aborted = false): void {
|
|
855
|
+
const name = toolName ?? this.contentNames.get(contentIndex);
|
|
856
|
+
const handlers = name ? this.handlers.get(name) : undefined;
|
|
857
|
+
|
|
858
|
+
for (const handler of handlers ?? []) {
|
|
859
|
+
if (aborted) {
|
|
860
|
+
handler.onAbort?.(contentIndex);
|
|
861
|
+
}
|
|
1009
862
|
|
|
1010
|
-
|
|
1011
|
-
{
|
|
1012
|
-
if (result.annotation?.reason)
|
|
1013
|
-
{
|
|
1014
|
-
return result.annotation.reason;
|
|
863
|
+
handler.onContentEnd?.(contentIndex);
|
|
1015
864
|
}
|
|
1016
865
|
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
866
|
+
this.abortCleanups.get(contentIndex)?.();
|
|
867
|
+
this.abortCleanups.delete(contentIndex);
|
|
868
|
+
this.contentNames.delete(contentIndex);
|
|
869
|
+
this.contentToolCallIds.delete(contentIndex);
|
|
870
|
+
this.pendingToolCallAnnotations.delete(contentIndex);
|
|
871
|
+
this.emittedToolCallAnnotationKinds.delete(contentIndex);
|
|
872
|
+
this.completeArgumentContentIndices.delete(contentIndex);
|
|
873
|
+
this.partialBuffers.delete(contentIndex);
|
|
874
|
+
this.abortedContentIndices.delete(contentIndex);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
private cleanupAll(): void {
|
|
878
|
+
for (const handlers of this.handlers.values()) {
|
|
879
|
+
for (const handler of handlers) {
|
|
880
|
+
handler.onAgentEnd?.();
|
|
881
|
+
}
|
|
1020
882
|
}
|
|
1021
883
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
return "Stale Anchor";
|
|
884
|
+
for (const cleanup of this.abortCleanups.values()) {
|
|
885
|
+
cleanup();
|
|
1025
886
|
}
|
|
1026
887
|
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
888
|
+
this.abortCleanups.clear();
|
|
889
|
+
this.contentNames.clear();
|
|
890
|
+
this.contentToolCallIds.clear();
|
|
891
|
+
this.pendingToolCallAnnotations.clear();
|
|
892
|
+
this.completeArgumentContentIndices.clear();
|
|
893
|
+
this.emittedToolCallAnnotationKinds.clear();
|
|
894
|
+
this.partialBuffers.clear();
|
|
895
|
+
this.streamedBatchEntries.clear();
|
|
896
|
+
this.batchEntryIndexes.clear();
|
|
897
|
+
this.toolCallBatchEntryIndexes.clear();
|
|
898
|
+
this.toolCallRecords.clear();
|
|
899
|
+
this.completedBatchEntryIndexes.clear();
|
|
900
|
+
this.nextBatchEntryIndex = 0;
|
|
901
|
+
this.abortedContentIndices.clear();
|
|
902
|
+
this.pendingAbortReason = undefined;
|
|
903
|
+
this.dispatchQueues.clear();
|
|
904
|
+
this.processedStreamEventKeys.clear();
|
|
905
|
+
this.recoveryRegistry.cleanupAll();
|
|
906
|
+
this.pendingRecoveryBlocks.length = 0;
|
|
907
|
+
this.recoveryAppliedBatchIndexes.clear();
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
registerRecovery(registration: Parameters<PartialToolRecoveryRegistry["register"]>[0]): void {
|
|
911
|
+
this.recoveryRegistry.register(registration);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
unregisterRecovery(toolName: string): void {
|
|
915
|
+
this.recoveryRegistry.unregister(toolName);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
registerBlockedCallSink(sink: BlockedToolCallSink | undefined): void {
|
|
919
|
+
this.blockedCallSink = sink;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
register(handler: ToolCallInterceptorHandler): void {
|
|
923
|
+
const targetTools = new Set(handler.toolNames);
|
|
924
|
+
|
|
925
|
+
for (const [toolName, handlers] of this.handlers) {
|
|
926
|
+
const index = handlers.findIndex((current) => current.name === handler.name);
|
|
927
|
+
|
|
928
|
+
if (index === -1) {
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
if (targetTools.has(toolName)) {
|
|
933
|
+
handlers[index] = handler;
|
|
934
|
+
targetTools.delete(toolName);
|
|
935
|
+
} else {
|
|
936
|
+
handlers.splice(index, 1);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
1034
939
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
const value: unknown = JSON.parse(json);
|
|
1040
|
-
return Guard.IsObjectNotArray(value) ? value : undefined;
|
|
940
|
+
for (const toolName of targetTools) {
|
|
941
|
+
const handlers = this.handlers.get(toolName) ?? [];
|
|
942
|
+
handlers.push(handler);
|
|
943
|
+
this.handlers.set(toolName, handlers);
|
|
1041
944
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
unregister(name: string): void {
|
|
948
|
+
for (const [toolName, handlers] of this.handlers) {
|
|
949
|
+
this.handlers.set(
|
|
950
|
+
toolName,
|
|
951
|
+
handlers.filter((handler) => handler.name !== name),
|
|
952
|
+
);
|
|
1045
953
|
}
|
|
954
|
+
}
|
|
1046
955
|
}
|
|
1047
956
|
|
|
1048
|
-
function
|
|
1049
|
-
{
|
|
1050
|
-
|
|
957
|
+
function toolStreamEventKey(event: AssistantStreamEvent): string | undefined {
|
|
958
|
+
if (event.type === "toolcall_end") {
|
|
959
|
+
return `${event.type}\u{0}${event.contentIndex}\u{0}${event.toolCall.id}`;
|
|
960
|
+
}
|
|
1051
961
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
962
|
+
if (event.type !== "toolcall_start" && event.type !== "toolcall_delta") {
|
|
963
|
+
return undefined;
|
|
964
|
+
}
|
|
1056
965
|
|
|
1057
|
-
|
|
966
|
+
const block = event.partial.content[event.contentIndex];
|
|
967
|
+
const toolCallId = block?.type === "toolCall" ? block.id : "";
|
|
968
|
+
const delta = event.type === "toolcall_delta" ? event.delta : "";
|
|
969
|
+
return `${event.type}\u{0}${event.contentIndex}\u{0}${toolCallId}\u{0}${delta}`;
|
|
970
|
+
}
|
|
1058
971
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
972
|
+
function abortReason(result: InterceptResult, handlerName: string): string {
|
|
973
|
+
if (result.annotation?.reason) {
|
|
974
|
+
return result.annotation.reason;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
if (result.annotation?.label) {
|
|
978
|
+
return result.annotation.label;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
if (result.message.customType === "text-editor-stale-anchor-block") {
|
|
982
|
+
return "Stale Anchor";
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
return (
|
|
986
|
+
handlerName
|
|
987
|
+
.replace(/[-_]+/g, " ")
|
|
988
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
989
|
+
.replace(/\s+/g, " ")
|
|
990
|
+
.trim()
|
|
991
|
+
.replace(/\b\w/g, (letter) => letter.toUpperCase()) || "Blocked"
|
|
992
|
+
);
|
|
993
|
+
}
|
|
1063
994
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
: candidates.filter((result) => result.path === stalePath);
|
|
1073
|
-
const selected = matching.length > 0 ? matching : candidates;
|
|
1074
|
-
const anchors = selected.flatMap((result) =>
|
|
1075
|
-
{
|
|
1076
|
-
const freshAnchors = result.freshAnchors;
|
|
1077
|
-
return Array.isArray(freshAnchors)
|
|
1078
|
-
? freshAnchors.filter((anchor): anchor is string => typeof anchor === "string")
|
|
1079
|
-
: [];
|
|
1080
|
-
});
|
|
995
|
+
function parseCompleteArguments(json: string): Record<string, unknown> | undefined {
|
|
996
|
+
try {
|
|
997
|
+
const value: unknown = JSON.parse(json);
|
|
998
|
+
return Guard.IsObjectNotArray(value) ? value : undefined;
|
|
999
|
+
} catch {
|
|
1000
|
+
return undefined;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1081
1003
|
|
|
1082
|
-
|
|
1004
|
+
function freshAnchorsAfterRecovery(recovery: PartialToolRecoveryResult): string[] {
|
|
1005
|
+
const normalResult = recovery.normalResult;
|
|
1006
|
+
|
|
1007
|
+
if (!Guard.IsObjectNotArray(normalResult) || !Guard.IsObjectNotArray(normalResult.details)) {
|
|
1008
|
+
return [];
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
const results = normalResult.details.results;
|
|
1012
|
+
|
|
1013
|
+
if (!Array.isArray(results)) {
|
|
1014
|
+
return [];
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
const stalePath =
|
|
1018
|
+
Guard.IsObjectNotArray(recovery.staleDetails) && typeof recovery.staleDetails.path === "string"
|
|
1019
|
+
? recovery.staleDetails.path
|
|
1020
|
+
: undefined;
|
|
1021
|
+
const candidates = results
|
|
1022
|
+
.filter(Guard.IsObjectNotArray)
|
|
1023
|
+
.map((result) => (Guard.IsObjectNotArray(result.data) ? result.data : result));
|
|
1024
|
+
const matching =
|
|
1025
|
+
stalePath === undefined ? candidates : candidates.filter((result) => result.path === stalePath);
|
|
1026
|
+
const selected = matching.length > 0 ? matching : candidates;
|
|
1027
|
+
const anchors = selected.flatMap((result) => {
|
|
1028
|
+
const freshAnchors = result.freshAnchors;
|
|
1029
|
+
return Array.isArray(freshAnchors)
|
|
1030
|
+
? freshAnchors.filter((anchor): anchor is string => typeof anchor === "string")
|
|
1031
|
+
: [];
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
return [...new Set(anchors)];
|
|
1083
1035
|
}
|
|
1084
1036
|
|
|
1085
|
-
function replaceCurrentAnchors(content: string, freshAnchors: readonly string[]): string
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
return `${base}\n\nCurrent nearby anchors:\n${freshAnchors.map((anchor) => ` ${anchor}`).join("\n")}`;
|
|
1037
|
+
function replaceCurrentAnchors(content: string, freshAnchors: readonly string[]): string {
|
|
1038
|
+
const marker = "\n\nCurrent nearby anchors:";
|
|
1039
|
+
const markerIndex = content.indexOf(marker);
|
|
1040
|
+
const base = markerIndex === -1 ? content : content.slice(0, markerIndex);
|
|
1041
|
+
return `${base}\n\nCurrent nearby anchors:\n${freshAnchors.map((anchor) => ` ${anchor}`).join("\n")}`;
|
|
1091
1042
|
}
|
|
1092
1043
|
|
|
1093
1044
|
function makeRecoveryResult(
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
): InterceptResult
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1045
|
+
blocked: InterceptResult,
|
|
1046
|
+
recovery: PartialToolRecoveryResult,
|
|
1047
|
+
): InterceptResult {
|
|
1048
|
+
const appliedCount = recovery.appliedEntries.length;
|
|
1049
|
+
const applied =
|
|
1050
|
+
appliedCount > 0 ? `${appliedCount} (indices: ${recovery.appliedEntries.join(", ")})` : "0";
|
|
1051
|
+
const skipped =
|
|
1052
|
+
recovery.skippedEntries.length > 0
|
|
1053
|
+
? recovery.skippedEntries.map((entry) => `${entry.index} (${entry.reason})`).join(", ")
|
|
1054
|
+
: "none";
|
|
1055
|
+
const execution = recovery.error
|
|
1056
|
+
? `Recovery execution failed: ${recovery.error}.`
|
|
1057
|
+
: "Recovery execution completed.";
|
|
1058
|
+
const freshAnchors = freshAnchorsAfterRecovery(recovery);
|
|
1059
|
+
const blockedDetails =
|
|
1060
|
+
freshAnchors.length > 0 && Guard.IsObjectNotArray(blocked.message.details)
|
|
1061
|
+
? { ...blocked.message.details, freshAnchors }
|
|
1062
|
+
: blocked.message.details;
|
|
1063
|
+
const blockedContent =
|
|
1064
|
+
freshAnchors.length > 0
|
|
1065
|
+
? replaceCurrentAnchors(blocked.message.content, freshAnchors)
|
|
1066
|
+
: blocked.message.content;
|
|
1067
|
+
const displayedRecovery =
|
|
1068
|
+
freshAnchors.length > 0 && Guard.IsObjectNotArray(recovery.staleDetails)
|
|
1069
|
+
? { ...recovery, staleDetails: { ...recovery.staleDetails, freshAnchors } }
|
|
1070
|
+
: recovery;
|
|
1071
|
+
|
|
1072
|
+
return {
|
|
1073
|
+
message: {
|
|
1074
|
+
customType: PARTIAL_TOOL_RECOVERY_CUSTOM_TYPE,
|
|
1075
|
+
content:
|
|
1076
|
+
`${blockedContent}\n\n[RECOVERY] Status: ${recovery.status}. Applied entries: ${applied}. ` +
|
|
1077
|
+
`Skipped entries: ${skipped}. ${execution}`,
|
|
1078
|
+
display: false,
|
|
1079
|
+
details: { blocked: blockedDetails, recovery: displayedRecovery },
|
|
1080
|
+
},
|
|
1081
|
+
};
|
|
1128
1082
|
}
|
|
1129
1083
|
|
|
1130
1084
|
const coordinators = new WeakMap<ExtensionAPI, ToolCallInterceptor>();
|
|
1131
1085
|
|
|
1132
|
-
function coordinatorFor(pi: ExtensionAPI): ToolCallInterceptor
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
coordinator.finalizeStreamInterception(contentIndex);
|
|
1153
|
-
},
|
|
1154
|
-
);
|
|
1155
|
-
return coordinator;
|
|
1086
|
+
function coordinatorFor(pi: ExtensionAPI): ToolCallInterceptor {
|
|
1087
|
+
const existing = coordinators.get(pi);
|
|
1088
|
+
|
|
1089
|
+
if (existing) {
|
|
1090
|
+
return existing;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
const coordinator = new InterceptorImpl(pi);
|
|
1094
|
+
coordinators.set(pi, coordinator);
|
|
1095
|
+
registerStreamingInterceptorProvider(
|
|
1096
|
+
pi,
|
|
1097
|
+
(event, context) => coordinator.processStreamEvent(event, context),
|
|
1098
|
+
(event) => {
|
|
1099
|
+
coordinator.markStreamEventProcessed(event);
|
|
1100
|
+
},
|
|
1101
|
+
(contentIndex) => {
|
|
1102
|
+
coordinator.finalizeStreamInterception(contentIndex);
|
|
1103
|
+
},
|
|
1104
|
+
);
|
|
1105
|
+
return coordinator;
|
|
1156
1106
|
}
|
|
1157
1107
|
|
|
1158
|
-
export function registerToolCallInterceptor(
|
|
1159
|
-
|
|
1160
|
-
|
|
1108
|
+
export function registerToolCallInterceptor(
|
|
1109
|
+
pi: ExtensionAPI,
|
|
1110
|
+
handler: ToolCallInterceptorHandler,
|
|
1111
|
+
): void {
|
|
1112
|
+
coordinatorFor(pi).register(handler);
|
|
1161
1113
|
}
|
|
1162
1114
|
|
|
1163
|
-
export function unregisterToolCallInterceptor(pi: ExtensionAPI, handlerName: string): void
|
|
1164
|
-
|
|
1165
|
-
coordinatorFor(pi).unregister(handlerName);
|
|
1115
|
+
export function unregisterToolCallInterceptor(pi: ExtensionAPI, handlerName: string): void {
|
|
1116
|
+
coordinatorFor(pi).unregister(handlerName);
|
|
1166
1117
|
}
|
|
1167
1118
|
|
|
1168
1119
|
export function registerToolCallRecovery(
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
): void
|
|
1172
|
-
|
|
1173
|
-
coordinatorFor(pi).registerRecovery(registration);
|
|
1120
|
+
pi: ExtensionAPI,
|
|
1121
|
+
registration: Parameters<PartialToolRecoveryRegistry["register"]>[0],
|
|
1122
|
+
): void {
|
|
1123
|
+
coordinatorFor(pi).registerRecovery(registration);
|
|
1174
1124
|
}
|
|
1175
1125
|
|
|
1176
|
-
export function unregisterToolCallRecovery(pi: ExtensionAPI, toolName: string): void
|
|
1177
|
-
|
|
1178
|
-
coordinatorFor(pi).unregisterRecovery(toolName);
|
|
1126
|
+
export function unregisterToolCallRecovery(pi: ExtensionAPI, toolName: string): void {
|
|
1127
|
+
coordinatorFor(pi).unregisterRecovery(toolName);
|
|
1179
1128
|
}
|
|
1180
1129
|
|
|
1181
1130
|
export function registerToolCallAnnotationSink(
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
): void
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1131
|
+
pi: ExtensionAPI,
|
|
1132
|
+
sink?: ToolCallAnnotationSink,
|
|
1133
|
+
): void {
|
|
1134
|
+
toolCallAnnotationSinkUnsubscribers.get(pi)?.();
|
|
1135
|
+
toolCallAnnotationSinkUnsubscribers.delete(pi);
|
|
1136
|
+
|
|
1137
|
+
if (sink === undefined) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
const unsubscribe = pi.events.on(TOOL_CALL_ANNOTATION_EVENT, (event) => {
|
|
1142
|
+
if (
|
|
1143
|
+
!Guard.IsObjectNotArray(event) ||
|
|
1144
|
+
typeof event.toolCallId !== "string" ||
|
|
1145
|
+
!isToolCallAnnotation(event.annotation)
|
|
1146
|
+
) {
|
|
1147
|
+
return;
|
|
1192
1148
|
}
|
|
1193
1149
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
!Guard.IsObjectNotArray(event)
|
|
1198
|
-
|| typeof event.toolCallId !== "string"
|
|
1199
|
-
|| !isToolCallAnnotation(event.annotation)
|
|
1200
|
-
)
|
|
1201
|
-
{
|
|
1202
|
-
return;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
sink(event.toolCallId, event.annotation);
|
|
1206
|
-
});
|
|
1207
|
-
toolCallAnnotationSinkUnsubscribers.set(pi, unsubscribe);
|
|
1150
|
+
sink(event.toolCallId, event.annotation);
|
|
1151
|
+
});
|
|
1152
|
+
toolCallAnnotationSinkUnsubscribers.set(pi, unsubscribe);
|
|
1208
1153
|
}
|
|
1209
1154
|
|
|
1210
1155
|
export function registerBlockedToolCallSink(
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
): void
|
|
1214
|
-
|
|
1215
|
-
coordinatorFor(pi).registerBlockedCallSink(sink);
|
|
1156
|
+
pi: ExtensionAPI,
|
|
1157
|
+
sink: BlockedToolCallSink | undefined,
|
|
1158
|
+
): void {
|
|
1159
|
+
coordinatorFor(pi).registerBlockedCallSink(sink);
|
|
1216
1160
|
}
|
|
1217
1161
|
|
|
1218
1162
|
export function processToolCallStreamEvent(
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
): Promise<GuardInterception | undefined>
|
|
1223
|
-
|
|
1224
|
-
return coordinatorFor(pi).processStreamEvent(event, ctx);
|
|
1163
|
+
pi: ExtensionAPI,
|
|
1164
|
+
event: AssistantStreamEvent,
|
|
1165
|
+
context: ExtensionContext,
|
|
1166
|
+
): Promise<GuardInterception | undefined> {
|
|
1167
|
+
return coordinatorFor(pi).processStreamEvent(event, context);
|
|
1225
1168
|
}
|
|
1226
1169
|
|
|
1227
|
-
export function markToolCallStreamEventProcessed(
|
|
1228
|
-
|
|
1229
|
-
|
|
1170
|
+
export function markToolCallStreamEventProcessed(
|
|
1171
|
+
pi: ExtensionAPI,
|
|
1172
|
+
event: AssistantStreamEvent,
|
|
1173
|
+
): void {
|
|
1174
|
+
coordinatorFor(pi).markStreamEventProcessed(event);
|
|
1230
1175
|
}
|
|
1231
1176
|
|
|
1232
|
-
export function getToolCallRecord(
|
|
1233
|
-
|
|
1234
|
-
|
|
1177
|
+
export function getToolCallRecord(
|
|
1178
|
+
pi: ExtensionAPI,
|
|
1179
|
+
toolCallId: string,
|
|
1180
|
+
): GuardCallRecord | undefined {
|
|
1181
|
+
return coordinatorFor(pi).getToolCallRecord(toolCallId);
|
|
1235
1182
|
}
|