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,828 +1,1265 @@
|
|
|
1
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
1
2
|
import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
isAgentContent,
|
|
5
|
+
isResourceResolutionAttempt,
|
|
6
|
+
type ResourceResolver,
|
|
7
|
+
type ResourceResolverContext,
|
|
7
8
|
} from "pi-agent-resource";
|
|
8
9
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
type PresentedTextRow,
|
|
11
|
+
type TextDocument,
|
|
12
|
+
type TextLine,
|
|
13
|
+
type TextLinePresentation,
|
|
14
|
+
type TextPresentationContext,
|
|
15
|
+
isTextTargetResolutionAttempt,
|
|
16
|
+
type TextTargetResolver,
|
|
17
|
+
type TextTargetResolutionAttempt,
|
|
16
18
|
} from "pi-agent-text";
|
|
17
19
|
import { withBlockedToolResult } from "pi-agent-tool-call-interception";
|
|
18
20
|
import { Type } from "typebox";
|
|
19
21
|
|
|
20
22
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
isFragmentResolverRegistration,
|
|
24
|
+
isReadFragmentResolution,
|
|
25
|
+
isReadHandlerRegistration,
|
|
26
|
+
isReadViewRegistration,
|
|
27
|
+
isResourceResolverRegistration,
|
|
28
|
+
isTextTargetResolverRegistration,
|
|
29
|
+
type FragmentResolverRegistration,
|
|
30
|
+
type ReadHandlerRegistration,
|
|
31
|
+
type ReadPipelineContext,
|
|
32
|
+
type ReadFailure,
|
|
33
|
+
type ReadPipelineStage,
|
|
34
|
+
type ReadResultDetails,
|
|
35
|
+
type ReadResultRenderer,
|
|
36
|
+
type ReadStageOutcome,
|
|
37
|
+
type ReadState,
|
|
38
|
+
type ReadToolResult,
|
|
39
|
+
type ReadViewRegistration,
|
|
40
|
+
type ResourceResolverRegistration,
|
|
41
|
+
type TextTargetResolverRegistration,
|
|
32
42
|
} from "#src/api/tools/read.js";
|
|
33
43
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
limitReadOutput,
|
|
45
|
+
READ_OUTPUT_MAX_BYTES,
|
|
46
|
+
READ_OUTPUT_MAX_LINES,
|
|
37
47
|
} from "#src/core/tools/read/output-truncation.js";
|
|
38
|
-
import { createReadResultRenderer } from "#src/core/tools/read/read-renderer.js";
|
|
39
|
-
import {
|
|
48
|
+
import { createReadResultRenderer, renderReadCall } from "#src/core/tools/read/read-renderer.js";
|
|
49
|
+
import { createLineNumberPresenter } from "#src/core/tools/read/views.js";
|
|
50
|
+
import {
|
|
51
|
+
createReadState,
|
|
52
|
+
failureResult,
|
|
53
|
+
projectReadState,
|
|
54
|
+
} from "#src/core/tools/read/read-result.js";
|
|
40
55
|
import { TempResourceStore } from "#src/core/tools/read/temp-resource-store.js";
|
|
41
56
|
|
|
42
57
|
const readParameters = Type.Object({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
path: Type.Optional(
|
|
59
|
+
Type.String({
|
|
60
|
+
description:
|
|
61
|
+
"Complete source resource reference: a filesystem path, URL, protocol source, temporary resource, or typed SEARCH#... selection.",
|
|
62
|
+
}),
|
|
63
|
+
),
|
|
64
|
+
offset: Type.Optional(Type.Number()),
|
|
65
|
+
limit: Type.Optional(Type.Number()),
|
|
66
|
+
views: Type.Optional(Type.Array(Type.String())),
|
|
46
67
|
});
|
|
47
68
|
|
|
48
69
|
const fallbackReadRenderer = createReadResultRenderer({ kind: "source" });
|
|
49
70
|
|
|
50
|
-
interface RegisteredResolver
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
readonly order: number;
|
|
71
|
+
interface RegisteredResolver {
|
|
72
|
+
readonly resolver: ResourceResolver;
|
|
73
|
+
readonly renderResult?: ReadResultRenderer;
|
|
74
|
+
readonly preserveTruncatedOutput: boolean;
|
|
75
|
+
readonly priority: number;
|
|
76
|
+
readonly order: number;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
interface RegisteredHandler
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
readonly registration: ReadHandlerRegistration;
|
|
79
|
+
interface RegisteredHandler {
|
|
80
|
+
readonly pluginId: string;
|
|
81
|
+
readonly registration: ReadHandlerRegistration;
|
|
63
82
|
}
|
|
64
83
|
|
|
65
|
-
interface
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
readonly order: number;
|
|
84
|
+
interface RegisteredView {
|
|
85
|
+
readonly pluginId: string;
|
|
86
|
+
readonly registration: ReadViewRegistration;
|
|
87
|
+
readonly order: number;
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
interface
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
interface RegisteredFragment {
|
|
91
|
+
readonly registration: FragmentResolverRegistration;
|
|
92
|
+
readonly priority: number;
|
|
93
|
+
readonly order: number;
|
|
76
94
|
}
|
|
77
95
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
readonly handlers?: readonly ReadHandlerRegistration[];
|
|
82
|
-
readonly presenters?: readonly TextPresenterRegistration[];
|
|
96
|
+
interface ViewContribution {
|
|
97
|
+
readonly presenterId: string;
|
|
98
|
+
readonly document: TextDocument;
|
|
83
99
|
}
|
|
84
100
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
readonly tool: ToolDefinition<typeof readParameters, ReadResultDetails>;
|
|
88
|
-
execute(request: ReadPipelineContext["request"], context: ResourceResolverContext): Promise<ReadToolResult>;
|
|
89
|
-
registerContributions(pluginId: string, contributions: ReadToolContributions): void;
|
|
90
|
-
dispose(): Promise<void>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function createReadTool(
|
|
94
|
-
pluginPromptGuideline?: () => string | undefined,
|
|
95
|
-
): ReadTool
|
|
96
|
-
{
|
|
97
|
-
const tempResources = new TempResourceStore();
|
|
98
|
-
const resolvers: RegisteredResolver[] = [{
|
|
99
|
-
resolver: tempResources.resolver,
|
|
100
|
-
preserveTruncatedOutput: false,
|
|
101
|
-
priority: Number.MIN_SAFE_INTEGER,
|
|
102
|
-
order: 0,
|
|
103
|
-
}];
|
|
104
|
-
const handlers: RegisteredHandler[] = [];
|
|
105
|
-
const presenters: RegisteredPresenter[] = [];
|
|
106
|
-
const toolId = "read";
|
|
101
|
+
/** Built-in view names that exist without any plugin registration. */
|
|
102
|
+
const BUILTIN_VIEWS = ["lines"] as const;
|
|
107
103
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
label: toolId,
|
|
112
|
-
description:
|
|
113
|
-
`Resolve a supported source into agent-native content. Text output is truncated to ${READ_OUTPUT_MAX_LINES} lines or ${
|
|
114
|
-
READ_OUTPUT_MAX_BYTES / 1024
|
|
115
|
-
}KB, whichever is reached first. Use offset/limit to read a line range and continue large sources; a negative offset reads from the end.`,
|
|
116
|
-
get promptGuidelines(): string[]
|
|
117
|
-
{
|
|
118
|
-
const pluginGuideline = pluginPromptGuideline?.();
|
|
119
|
-
return [
|
|
120
|
-
"For large sources, prefer focused or structural reads over full content.",
|
|
121
|
-
...(pluginGuideline === undefined ? [] : [pluginGuideline]),
|
|
122
|
-
];
|
|
123
|
-
},
|
|
124
|
-
parameters: readParameters,
|
|
125
|
-
renderShell: "self",
|
|
126
|
-
renderResult(result, options, theme, context)
|
|
127
|
-
{
|
|
128
|
-
const resolvedBy = result.details.resolvedBy;
|
|
129
|
-
const renderer = resolvedBy === undefined
|
|
130
|
-
? undefined
|
|
131
|
-
: resolvers.find(({ resolver }) => resolver.id === resolvedBy)?.renderResult;
|
|
132
|
-
return (renderer ?? fallbackReadRenderer)(result, options, theme, context);
|
|
133
|
-
},
|
|
134
|
-
async execute(_toolCallId, params, signal, _onUpdate, context)
|
|
135
|
-
{
|
|
136
|
-
const resolverContext: ResourceResolverContext = {
|
|
137
|
-
cwd: context.cwd,
|
|
138
|
-
...(signal === undefined ? {} : { signal }),
|
|
139
|
-
};
|
|
140
|
-
return executeRead(params, resolverContext, resolvers, handlers, presenters, tempResources);
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
execute(request, context): Promise<ReadToolResult>
|
|
144
|
-
{
|
|
145
|
-
return executeRead(request, context, resolvers, handlers, presenters, tempResources);
|
|
146
|
-
},
|
|
147
|
-
registerContributions(pluginId, contributions): void
|
|
148
|
-
{
|
|
149
|
-
const incomingResolvers = [...(contributions.resolvers ?? [])];
|
|
150
|
-
const incomingHandlers = [...(contributions.handlers ?? [])];
|
|
151
|
-
const incomingPresenters = [...(contributions.presenters ?? [])];
|
|
152
|
-
validateContributions(pluginId, incomingResolvers, incomingHandlers, resolvers, handlers);
|
|
153
|
-
const presenterIds = new Set(presenters.map(({ registration }) => registration.presenter.id));
|
|
154
|
-
|
|
155
|
-
for (const registration of incomingPresenters)
|
|
156
|
-
{
|
|
157
|
-
if (!isTextPresenterRegistration(registration))
|
|
158
|
-
{
|
|
159
|
-
throw new TypeError(`Plugin ${pluginId} provided an invalid text presenter`);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (presenterIds.has(registration.presenter.id))
|
|
163
|
-
{
|
|
164
|
-
throw new Error(`Text presenter ${registration.presenter.id} is already registered`);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
presenterIds.add(registration.presenter.id);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
for (const registration of incomingResolvers)
|
|
171
|
-
{
|
|
172
|
-
resolvers.push({
|
|
173
|
-
resolver: registration.resolver,
|
|
174
|
-
...(registration.renderResult === undefined ? {} : { renderResult: registration.renderResult }),
|
|
175
|
-
priority: registration.priority ?? 0,
|
|
176
|
-
preserveTruncatedOutput: registration.preserveTruncatedOutput ?? false,
|
|
177
|
-
order: resolvers.length,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
for (const registration of incomingHandlers)
|
|
182
|
-
{
|
|
183
|
-
handlers.push({ pluginId, registration });
|
|
184
|
-
}
|
|
104
|
+
function createBuiltinViewRegistrations(): ReadViewRegistration[] {
|
|
105
|
+
return [{ view: "lines", presenter: createLineNumberPresenter() }];
|
|
106
|
+
}
|
|
185
107
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
{
|
|
193
|
-
return tempResources.dispose();
|
|
194
|
-
},
|
|
195
|
-
};
|
|
108
|
+
export interface ReadToolContributions {
|
|
109
|
+
readonly resolvers?: readonly ResourceResolverRegistration[];
|
|
110
|
+
readonly targetResolvers?: readonly TextTargetResolverRegistration[];
|
|
111
|
+
readonly handlers?: readonly ReadHandlerRegistration[];
|
|
112
|
+
readonly views?: readonly ReadViewRegistration[];
|
|
113
|
+
readonly fragments?: readonly FragmentResolverRegistration[];
|
|
196
114
|
}
|
|
197
115
|
|
|
198
|
-
|
|
116
|
+
export interface ReadTool {
|
|
117
|
+
readonly tool: ToolDefinition<typeof readParameters, ReadResultDetails>;
|
|
118
|
+
execute(
|
|
199
119
|
request: ReadPipelineContext["request"],
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
): Promise<ReadToolResult>
|
|
206
|
-
{
|
|
207
|
-
const resolverSnapshot = [...resolvers].sort((left, right) =>
|
|
208
|
-
left.priority - right.priority || left.order - right.order
|
|
209
|
-
);
|
|
210
|
-
const handlerSnapshot = [...handlers];
|
|
211
|
-
const presenterSnapshot = [...presenters].sort((left, right) =>
|
|
212
|
-
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) || left.order - right.order
|
|
213
|
-
);
|
|
214
|
-
let pipeline: ReadPipelineContext = { request: { ...request }, resolverContext };
|
|
120
|
+
context: ResourceResolverContext,
|
|
121
|
+
): Promise<ReadToolResult>;
|
|
122
|
+
registerContributions(pluginId: string, contributions: ReadToolContributions): void;
|
|
123
|
+
dispose(): Promise<void>;
|
|
124
|
+
}
|
|
215
125
|
|
|
216
|
-
|
|
126
|
+
export function createReadTool(pluginPromptGuidelines?: () => readonly string[]): ReadTool {
|
|
127
|
+
const temporaryResources = new TempResourceStore();
|
|
128
|
+
const resolvers: RegisteredResolver[] = [
|
|
217
129
|
{
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
130
|
+
resolver: temporaryResources.resolver,
|
|
131
|
+
preserveTruncatedOutput: false,
|
|
132
|
+
priority: Number.MIN_SAFE_INTEGER,
|
|
133
|
+
order: 0,
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
const handlers: RegisteredHandler[] = [];
|
|
137
|
+
const views: RegisteredView[] = createBuiltinViewRegistrations().map((registration, order) => ({
|
|
138
|
+
pluginId: "core",
|
|
139
|
+
registration,
|
|
140
|
+
order,
|
|
141
|
+
}));
|
|
142
|
+
const fragments: RegisteredFragment[] = [];
|
|
143
|
+
const targetResolvers: {
|
|
144
|
+
readonly resolver: TextTargetResolver;
|
|
145
|
+
readonly priority: number;
|
|
146
|
+
readonly order: number;
|
|
147
|
+
}[] = [];
|
|
148
|
+
const toolId = "read";
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
tool: {
|
|
152
|
+
name: toolId,
|
|
153
|
+
label: toolId,
|
|
154
|
+
|
|
155
|
+
promptSnippet:
|
|
156
|
+
"Read files, URLs, temporary resources, search selections, and protocol sources, with optional views projected onto text content",
|
|
157
|
+
description: `Resolve a supported source into agent-native content. Text output is raw by default; pass optional views (string array) to add annotations: "lines" for a line-number column, or plugin views such as "anchors" (LINE#HASH), "ast", "diagnostics", and "changes" when their extensions are installed. Text output is truncated to ${READ_OUTPUT_MAX_LINES} lines or ${
|
|
158
|
+
READ_OUTPUT_MAX_BYTES / 1024
|
|
159
|
+
}KB, whichever is reached first. Use offset/limit to read a line range and continue large sources; a negative offset reads from the end. A \`path#anchor\` suffix (for example \`src/x.ts#function main\`) starts reading at the anchor's line: offset/limit then count from that line while output keeps absolute line numbers. For anchored reads, omitted offset, offset 0, and offset 1 are equivalent; positive offsets greater than one count forward and negative offsets count upward.`,
|
|
160
|
+
get promptGuidelines(): string[] {
|
|
161
|
+
return [
|
|
162
|
+
"Use read to examine files and other supported sources instead of cat, sed, head, tail, or similar shell commands.",
|
|
163
|
+
'You can use read with `views: ["lines"]` to add a line-number column.',
|
|
164
|
+
"You can use read with `offset` and `limit` to inspect a line range or continue a large source, and with a negative `offset` to read from the end.",
|
|
165
|
+
"You can combine compatible read views in one request.",
|
|
166
|
+
"When a read result is truncated and provides a `temp:` source, you can use read with that source to continue reading the saved full output.",
|
|
167
|
+
...(pluginPromptGuidelines?.() ?? []),
|
|
168
|
+
];
|
|
169
|
+
},
|
|
170
|
+
parameters: readParameters,
|
|
171
|
+
renderCall: renderReadCall,
|
|
172
|
+
renderResult(result, options, theme, context) {
|
|
173
|
+
const resolvedBy = result.details.resolvedBy;
|
|
174
|
+
const renderer =
|
|
175
|
+
resolvedBy === undefined
|
|
176
|
+
? undefined
|
|
177
|
+
: resolvers.find(({ resolver }) => resolver.id === resolvedBy)?.renderResult;
|
|
178
|
+
return (renderer ?? fallbackReadRenderer)(result, options, theme, context);
|
|
179
|
+
},
|
|
180
|
+
async execute(_toolCallId, parameters, signal, _onUpdate, context) {
|
|
181
|
+
const resolverContext: ResourceResolverContext = {
|
|
182
|
+
cwd: context.cwd,
|
|
183
|
+
...(signal !== undefined && { signal }),
|
|
184
|
+
};
|
|
185
|
+
return executeRead(
|
|
186
|
+
parameters,
|
|
187
|
+
resolverContext,
|
|
188
|
+
resolvers,
|
|
189
|
+
handlers,
|
|
190
|
+
views,
|
|
191
|
+
temporaryResources,
|
|
192
|
+
fragments,
|
|
193
|
+
targetResolvers,
|
|
194
|
+
);
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
execute(request, context): Promise<ReadToolResult> {
|
|
198
|
+
return executeRead(
|
|
199
|
+
request,
|
|
200
|
+
context,
|
|
201
|
+
resolvers,
|
|
202
|
+
handlers,
|
|
203
|
+
views,
|
|
204
|
+
temporaryResources,
|
|
205
|
+
fragments,
|
|
206
|
+
targetResolvers,
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
registerContributions(pluginId, contributions): void {
|
|
210
|
+
const incomingResolvers = [...(contributions.resolvers ?? [])];
|
|
211
|
+
const incomingTargetResolvers = [...(contributions.targetResolvers ?? [])];
|
|
212
|
+
const incomingHandlers = [...(contributions.handlers ?? [])];
|
|
213
|
+
const incomingViews = [...(contributions.views ?? [])];
|
|
214
|
+
const incomingFragments = [...(contributions.fragments ?? [])];
|
|
215
|
+
validateContributions(pluginId, incomingResolvers, incomingHandlers, resolvers, handlers);
|
|
216
|
+
validateFragmentRegistrations(pluginId, incomingFragments, fragments);
|
|
217
|
+
const targetResolverIds = new Set(targetResolvers.map(({ resolver }) => resolver.id));
|
|
218
|
+
for (const registration of incomingTargetResolvers) {
|
|
219
|
+
if (!isTextTargetResolverRegistration(registration)) {
|
|
220
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid text target resolver`);
|
|
221
|
+
}
|
|
222
|
+
if (targetResolverIds.has(registration.resolver.id)) {
|
|
223
|
+
throw new Error(`Text target resolver ${registration.resolver.id} is already registered`);
|
|
224
|
+
}
|
|
225
|
+
targetResolverIds.add(registration.resolver.id);
|
|
226
|
+
}
|
|
227
|
+
const viewNames = new Set(views.map(({ registration }) => registration.view));
|
|
228
|
+
const presenterIds = new Set(
|
|
229
|
+
views.map(({ registration }) => `${registration.view}/${registration.presenter.id}`),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
for (const registration of incomingViews) {
|
|
233
|
+
if (!isReadViewRegistration(registration)) {
|
|
234
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid view registration`);
|
|
223
235
|
}
|
|
224
236
|
|
|
225
|
-
|
|
226
|
-
}
|
|
237
|
+
const key = `${registration.view}/${registration.presenter.id}`;
|
|
227
238
|
|
|
228
|
-
|
|
239
|
+
if (presenterIds.has(key)) {
|
|
240
|
+
throw new Error(
|
|
241
|
+
`View ${registration.view} already has a presenter ${registration.presenter.id}`,
|
|
242
|
+
);
|
|
243
|
+
}
|
|
229
244
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
245
|
+
viewNames.add(registration.view);
|
|
246
|
+
presenterIds.add(key);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for (const registration of incomingResolvers) {
|
|
250
|
+
resolvers.push({
|
|
251
|
+
resolver: registration.resolver,
|
|
252
|
+
...(registration.renderResult !== undefined && {
|
|
253
|
+
renderResult: registration.renderResult,
|
|
254
|
+
}),
|
|
255
|
+
priority: registration.priority ?? 0,
|
|
256
|
+
preserveTruncatedOutput: registration.preserveTruncatedOutput ?? false,
|
|
257
|
+
order: resolvers.length,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
for (const registration of incomingTargetResolvers) {
|
|
262
|
+
targetResolvers.push({
|
|
263
|
+
resolver: registration.resolver,
|
|
264
|
+
priority: registration.priority ?? 0,
|
|
265
|
+
order: targetResolvers.length,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
for (const registration of incomingHandlers) {
|
|
270
|
+
handlers.push({ pluginId, registration });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
for (const registration of incomingViews) {
|
|
274
|
+
views.push({ pluginId, registration, order: views.length });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
for (const registration of incomingFragments) {
|
|
278
|
+
fragments.push({
|
|
279
|
+
registration,
|
|
280
|
+
priority: registration.priority ?? 0,
|
|
281
|
+
order: fragments.length,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
dispose(): Promise<void> {
|
|
286
|
+
return temporaryResources.dispose();
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
234
290
|
|
|
235
|
-
|
|
291
|
+
async function executeRead(
|
|
292
|
+
request: ReadPipelineContext["request"],
|
|
293
|
+
resolverContext: ResourceResolverContext,
|
|
294
|
+
resolvers: readonly RegisteredResolver[],
|
|
295
|
+
handlers: readonly RegisteredHandler[],
|
|
296
|
+
views: readonly RegisteredView[],
|
|
297
|
+
temporaryResources: TempResourceStore,
|
|
298
|
+
fragmentResolvers: readonly RegisteredFragment[],
|
|
299
|
+
targetResolvers: readonly {
|
|
300
|
+
readonly resolver: TextTargetResolver;
|
|
301
|
+
readonly priority: number;
|
|
302
|
+
readonly order: number;
|
|
303
|
+
}[],
|
|
304
|
+
): Promise<ReadToolResult> {
|
|
305
|
+
const resolverSnapshot = [...resolvers].sort(
|
|
306
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
307
|
+
);
|
|
308
|
+
const handlerSnapshot = [...handlers];
|
|
309
|
+
const viewSnapshot = [...views].sort(
|
|
310
|
+
(left, right) =>
|
|
311
|
+
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) ||
|
|
312
|
+
left.order - right.order,
|
|
313
|
+
);
|
|
314
|
+
const fragmentSnapshot = [...fragmentResolvers].sort(
|
|
315
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
316
|
+
);
|
|
317
|
+
const targetSnapshot = [...targetResolvers].sort(
|
|
318
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
319
|
+
);
|
|
320
|
+
const requestedViews = new Set(request.views ?? []);
|
|
321
|
+
const knownViews = new Set([
|
|
322
|
+
...BUILTIN_VIEWS,
|
|
323
|
+
...viewSnapshot.map(({ registration }) => registration.view),
|
|
324
|
+
]);
|
|
325
|
+
const ignoredViews = [...requestedViews].filter((view) => !knownViews.has(view));
|
|
326
|
+
if (request.path !== undefined && targetSnapshot.length > 0) {
|
|
327
|
+
const targeted = await resolveTextTargets(
|
|
328
|
+
request,
|
|
329
|
+
resolverContext,
|
|
330
|
+
targetSnapshot,
|
|
331
|
+
resolverSnapshot,
|
|
332
|
+
handlerSnapshot,
|
|
333
|
+
viewSnapshot,
|
|
334
|
+
requestedViews,
|
|
335
|
+
ignoredViews,
|
|
336
|
+
);
|
|
337
|
+
if (targeted !== undefined) return targeted;
|
|
338
|
+
}
|
|
339
|
+
let pipeline: ReadPipelineContext = { request: { ...request }, resolverContext };
|
|
340
|
+
|
|
341
|
+
if (!pipeline.request.path?.startsWith("temp:")) {
|
|
342
|
+
const preRead = await runPreReadHandlers(pipeline, handlerSnapshot);
|
|
343
|
+
|
|
344
|
+
if (preRead.kind === "return") {
|
|
345
|
+
return withIgnoredViews(
|
|
346
|
+
await limitReadOutput(preRead.result, pipeline.request),
|
|
347
|
+
ignoredViews,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
236
350
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
351
|
+
pipeline = preRead.context;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const source = pipeline.request.path;
|
|
355
|
+
|
|
356
|
+
if (source === undefined || source.length === 0) {
|
|
357
|
+
return failureResult({ code: "INVALID_REQUEST", message: "No source was provided" });
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let resolved = await resolveSource(pipeline, resolverSnapshot);
|
|
361
|
+
let anchoredFragment: string | undefined;
|
|
362
|
+
|
|
363
|
+
// Resource-first rule: when reading the whole source fails, split off an anchor fragment
|
|
364
|
+
// and try the bare source. If the bare source fails too, keep the original error: a
|
|
365
|
+
// resolver that claimed the full source owns its own read errors, and replacing its
|
|
366
|
+
// message with the bare-source error would be misleading.
|
|
367
|
+
if (
|
|
368
|
+
resolved.kind === "return" &&
|
|
369
|
+
resolved.result.isError === true &&
|
|
370
|
+
isRetryableFailure(resolved.result) &&
|
|
371
|
+
!source.startsWith("temp:")
|
|
372
|
+
) {
|
|
373
|
+
const split = splitAnchoredSource(source);
|
|
374
|
+
|
|
375
|
+
if (split !== undefined) {
|
|
376
|
+
const wholeSource = { result: resolved, pipeline };
|
|
377
|
+
const barePipeline = { ...pipeline, request: { ...pipeline.request, path: split.source } };
|
|
378
|
+
const retried = await resolveSource(barePipeline, resolverSnapshot);
|
|
379
|
+
|
|
380
|
+
if (retried.kind === "continue") {
|
|
381
|
+
resolved = retried;
|
|
382
|
+
pipeline = barePipeline;
|
|
383
|
+
anchoredFragment = split.fragment;
|
|
384
|
+
} else {
|
|
385
|
+
resolved = wholeSource.result;
|
|
386
|
+
}
|
|
240
387
|
}
|
|
388
|
+
}
|
|
389
|
+
if (resolved.kind === "return") {
|
|
390
|
+
return limitReadOutput(resolved.result, pipeline.request);
|
|
391
|
+
}
|
|
241
392
|
|
|
242
|
-
|
|
393
|
+
pipeline = resolved.context;
|
|
243
394
|
|
|
244
|
-
|
|
245
|
-
{
|
|
246
|
-
return limitReadOutput(projectReadState(pipeline.state, pipeline.request), pipeline.request);
|
|
247
|
-
}
|
|
395
|
+
let origin: number | undefined;
|
|
248
396
|
|
|
249
|
-
|
|
397
|
+
if (anchoredFragment !== undefined) {
|
|
398
|
+
const outcome = await resolveAnchoredOrigin(pipeline, fragmentSnapshot, anchoredFragment);
|
|
250
399
|
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
return limitReadOutput(processed.result, pipeline.request);
|
|
400
|
+
if (typeof outcome !== "number") {
|
|
401
|
+
return outcome;
|
|
254
402
|
}
|
|
255
403
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
404
|
+
origin = outcome;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (pipeline.state?.textMode === "final") {
|
|
408
|
+
return withIgnoredViews(
|
|
409
|
+
await limitReadOutput(
|
|
410
|
+
projectReadState(pipeline.state, pipeline.request, { originLine: origin }),
|
|
411
|
+
pipeline.request,
|
|
412
|
+
undefined,
|
|
413
|
+
{ originLine: origin },
|
|
414
|
+
),
|
|
415
|
+
ignoredViews,
|
|
416
|
+
);
|
|
417
|
+
}
|
|
267
418
|
|
|
268
|
-
|
|
269
|
-
initialContext: ReadPipelineContext,
|
|
270
|
-
resolvers: readonly RegisteredResolver[],
|
|
271
|
-
): Promise<ReadStageOutcome>
|
|
272
|
-
{
|
|
273
|
-
const source = initialContext.request.path!;
|
|
274
|
-
const resolverContext = initialContext.resolverContext;
|
|
275
|
-
|
|
276
|
-
for (const registeredResolver of resolvers)
|
|
277
|
-
{
|
|
278
|
-
const { resolver } = registeredResolver;
|
|
279
|
-
let attempt: unknown;
|
|
419
|
+
const processed = await runReadHandlers(pipeline, handlerSnapshot);
|
|
280
420
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
421
|
+
if (processed.kind === "return") {
|
|
422
|
+
return withIgnoredViews(
|
|
423
|
+
await limitReadOutput(processed.result, pipeline.request, undefined, { originLine: origin }),
|
|
424
|
+
ignoredViews,
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
pipeline = processed.context;
|
|
429
|
+
pipeline = await runTextPresenters(pipeline, viewSnapshot, requestedViews);
|
|
430
|
+
const projected = projectReadState(requiredValue(pipeline.state), pipeline.request, {
|
|
431
|
+
originLine: origin,
|
|
432
|
+
});
|
|
433
|
+
pipeline = { ...pipeline, result: projected };
|
|
434
|
+
const postRead = await runPostReadHandlers(pipeline, handlerSnapshot);
|
|
435
|
+
const result =
|
|
436
|
+
postRead.kind === "return" ? postRead.result : requiredValue(postRead.context.result);
|
|
437
|
+
const saveFullOutput =
|
|
438
|
+
pipeline.request.limit === undefined && pipeline.state?.preserveTruncatedOutput === true
|
|
439
|
+
? (text: string): Promise<string> => temporaryResources.save(text)
|
|
440
|
+
: undefined;
|
|
441
|
+
return withIgnoredViews(
|
|
442
|
+
await limitReadOutput(result, pipeline.request, saveFullOutput, { originLine: origin }),
|
|
443
|
+
ignoredViews,
|
|
444
|
+
);
|
|
445
|
+
}
|
|
298
446
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
447
|
+
/**
|
|
448
|
+
* Failures that allow the anchored-source retry. READ_FAILED is included because
|
|
449
|
+
* filesystem-style resolvers read lazily inside resolution, so a missing
|
|
450
|
+
* `<path>#<anchor>` file surfaces as READ_FAILED.
|
|
451
|
+
*/
|
|
452
|
+
const RETRYABLE_FAILURE_CODES: ReadonlySet<ReadFailure["code"]> = new Set([
|
|
453
|
+
"INVALID_RESOLVER_RESULT",
|
|
454
|
+
"NO_RESOLVER",
|
|
455
|
+
"READ_FAILED",
|
|
456
|
+
"RESOLVE_FAILED",
|
|
457
|
+
]);
|
|
458
|
+
|
|
459
|
+
/** True when reading the whole source failed for a reason an anchor split might fix. */
|
|
460
|
+
function isRetryableFailure(result: ReadToolResult): boolean {
|
|
461
|
+
const code = result.details.failure?.code;
|
|
462
|
+
return code !== undefined && RETRYABLE_FAILURE_CODES.has(code);
|
|
463
|
+
}
|
|
312
464
|
|
|
313
|
-
|
|
314
|
-
|
|
465
|
+
async function resolveTextTargets(
|
|
466
|
+
request: ReadPipelineContext["request"],
|
|
467
|
+
resolverContext: ResourceResolverContext,
|
|
468
|
+
targetResolvers: readonly {
|
|
469
|
+
readonly resolver: TextTargetResolver;
|
|
470
|
+
readonly priority: number;
|
|
471
|
+
readonly order: number;
|
|
472
|
+
}[],
|
|
473
|
+
resolvers: readonly RegisteredResolver[],
|
|
474
|
+
handlers: readonly RegisteredHandler[],
|
|
475
|
+
views: readonly RegisteredView[],
|
|
476
|
+
requestedViews: ReadonlySet<string>,
|
|
477
|
+
ignoredViews: readonly string[],
|
|
478
|
+
): Promise<ReadToolResult | undefined> {
|
|
479
|
+
for (const { resolver } of targetResolvers) {
|
|
480
|
+
let rawAttempt: unknown;
|
|
481
|
+
try {
|
|
482
|
+
rawAttempt = await resolver.tryResolve(request.path ?? "", resolverContext);
|
|
483
|
+
} catch (error) {
|
|
484
|
+
return failureResult({
|
|
485
|
+
code: "RESOLVE_FAILED",
|
|
486
|
+
source: request.path,
|
|
487
|
+
message: appendErrorMessage(`Text target resolver ${resolver.id} failed`, error),
|
|
488
|
+
cause: error,
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (!isTextTargetResolutionAttempt(rawAttempt)) {
|
|
492
|
+
return failureResult({
|
|
493
|
+
code: "INVALID_RESOLVER_RESULT",
|
|
494
|
+
source: request.path,
|
|
495
|
+
message: `Text target resolver ${resolver.id} returned an invalid result`,
|
|
496
|
+
cause: rawAttempt,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
const attempt: TextTargetResolutionAttempt = rawAttempt;
|
|
500
|
+
if (attempt.kind === "not-handled") continue;
|
|
501
|
+
if (attempt.kind === "rejected")
|
|
502
|
+
return failureResult({
|
|
503
|
+
code: "RESOLVE_FAILED",
|
|
504
|
+
source: request.path,
|
|
505
|
+
message: attempt.rejection.reason,
|
|
506
|
+
});
|
|
507
|
+
if (attempt.kind === "failed")
|
|
508
|
+
return failureResult({
|
|
509
|
+
code: "RESOLVE_FAILED",
|
|
510
|
+
source: request.path,
|
|
511
|
+
message: attempt.error instanceof Error ? attempt.error.message : String(attempt.error),
|
|
512
|
+
});
|
|
513
|
+
if (attempt.targets.length === 0)
|
|
514
|
+
return failureResult({
|
|
515
|
+
code: "RESOLVE_FAILED",
|
|
516
|
+
source: request.path,
|
|
517
|
+
message: "Text target resolver returned no targets",
|
|
518
|
+
});
|
|
519
|
+
const chunks: string[] = [];
|
|
520
|
+
let firstDetails: ReadResultDetails | undefined;
|
|
521
|
+
for (const target of attempt.targets) {
|
|
522
|
+
const ranges = target.ranges ?? [
|
|
523
|
+
{ start: { lineNumber: 1, column: 0 }, end: { lineNumber: 1, column: 1 } },
|
|
524
|
+
];
|
|
525
|
+
for (const range of ranges) {
|
|
526
|
+
const rangeLimit = Math.max(1, range.end.lineNumber - range.start.lineNumber);
|
|
527
|
+
let rangePipeline: ReadPipelineContext = {
|
|
528
|
+
request: {
|
|
529
|
+
...request,
|
|
530
|
+
path: target.source,
|
|
531
|
+
limit: request.limit ?? rangeLimit,
|
|
532
|
+
},
|
|
533
|
+
resolverContext,
|
|
534
|
+
};
|
|
535
|
+
if (!target.source.startsWith("temp:")) {
|
|
536
|
+
const preRead = await runPreReadHandlers(rangePipeline, handlers);
|
|
537
|
+
if (preRead.kind === "return") {
|
|
538
|
+
if (preRead.result.isError === true)
|
|
539
|
+
return withIgnoredViews(preRead.result, ignoredViews);
|
|
540
|
+
for (const block of preRead.result.content) {
|
|
541
|
+
if (block.type === "text") chunks.push(block.text);
|
|
542
|
+
}
|
|
543
|
+
firstDetails ??= preRead.result.details;
|
|
315
544
|
continue;
|
|
545
|
+
}
|
|
546
|
+
rangePipeline = preRead.context;
|
|
316
547
|
}
|
|
317
|
-
|
|
318
|
-
if (
|
|
319
|
-
|
|
320
|
-
return {
|
|
321
|
-
kind: "return",
|
|
322
|
-
result: failureResult({
|
|
323
|
-
code: "RESOLVE_FAILED",
|
|
324
|
-
source,
|
|
325
|
-
resolverId: resolver.id,
|
|
326
|
-
message: appendErrorMessage(`Resolver ${resolver.id} failed`, attempt.error),
|
|
327
|
-
cause: attempt.error,
|
|
328
|
-
}),
|
|
329
|
-
};
|
|
548
|
+
const resolved = await resolveSource(rangePipeline, resolvers);
|
|
549
|
+
if (resolved.kind === "return") {
|
|
550
|
+
return withIgnoredViews(resolved.result, ignoredViews);
|
|
330
551
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
source: resource.source,
|
|
341
|
-
resolverId: resolver.id,
|
|
342
|
-
message: `Resource ${resource.source} does not support reading`,
|
|
343
|
-
}),
|
|
344
|
-
};
|
|
552
|
+
const processed = await runReadHandlers(resolved.context, handlers);
|
|
553
|
+
if (processed.kind === "return") {
|
|
554
|
+
if (processed.result.isError === true)
|
|
555
|
+
return withIgnoredViews(processed.result, ignoredViews);
|
|
556
|
+
for (const block of processed.result.content) {
|
|
557
|
+
if (block.type === "text") chunks.push(block.text);
|
|
558
|
+
}
|
|
559
|
+
firstDetails ??= processed.result.details;
|
|
560
|
+
continue;
|
|
345
561
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
return {
|
|
358
|
-
kind: "return",
|
|
359
|
-
result: failureResult({
|
|
360
|
-
code: "READ_FAILED",
|
|
361
|
-
source: resource.source,
|
|
362
|
-
resolverId: resolver.id,
|
|
363
|
-
message: appendErrorMessage(`Unable to read ${resource.source}`, error),
|
|
364
|
-
cause: error,
|
|
365
|
-
}),
|
|
366
|
-
};
|
|
562
|
+
const presented = await runTextPresenters(processed.context, views, requestedViews);
|
|
563
|
+
const projected = projectReadState(requiredValue(presented.state), presented.request, {
|
|
564
|
+
originLine: range.start.lineNumber,
|
|
565
|
+
});
|
|
566
|
+
const postRead = await runPostReadHandlers({ ...presented, result: projected }, handlers);
|
|
567
|
+
if (projected.isError === true) return withIgnoredViews(projected, ignoredViews);
|
|
568
|
+
const result =
|
|
569
|
+
postRead.kind === "return" ? postRead.result : requiredValue(postRead.context.result);
|
|
570
|
+
if (result.isError === true) return withIgnoredViews(result, ignoredViews);
|
|
571
|
+
for (const block of result.content) {
|
|
572
|
+
if (block.type === "text") chunks.push(block.text);
|
|
367
573
|
}
|
|
574
|
+
firstDetails ??= result.details;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const aggregate = {
|
|
578
|
+
content: [{ type: "text", text: chunks.join("\n") }],
|
|
579
|
+
details: firstDetails ?? { source: request.path },
|
|
580
|
+
} satisfies ReadToolResult;
|
|
581
|
+
return withIgnoredViews(
|
|
582
|
+
await limitReadOutput(aggregate, { path: request.path, views: request.views }),
|
|
583
|
+
ignoredViews,
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
368
588
|
|
|
369
|
-
|
|
370
|
-
{
|
|
371
|
-
return {
|
|
372
|
-
kind: "return",
|
|
373
|
-
result: failureResult({
|
|
374
|
-
code: "INVALID_RESOURCE_CONTENT",
|
|
375
|
-
source: resource.source,
|
|
376
|
-
resolverId: resolver.id,
|
|
377
|
-
message: `Resource ${resource.source} returned invalid content`,
|
|
378
|
-
cause: content,
|
|
379
|
-
}),
|
|
380
|
-
};
|
|
381
|
-
}
|
|
589
|
+
const ANCHOR_SEPARATOR = "#";
|
|
382
590
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
preserveTruncatedOutput: registeredResolver.preserveTruncatedOutput,
|
|
389
|
-
textMode: resolver.id === "temp" ? "final" : "normal",
|
|
390
|
-
}),
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
}
|
|
591
|
+
/** Splits `path#fragment`; returns undefined when there is nothing to anchor. */
|
|
592
|
+
function splitAnchoredSource(
|
|
593
|
+
source: string,
|
|
594
|
+
): { readonly source: string; readonly fragment: string } | undefined {
|
|
595
|
+
const index = source.indexOf(ANCHOR_SEPARATOR);
|
|
394
596
|
|
|
395
|
-
|
|
396
|
-
return
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}),
|
|
404
|
-
reason,
|
|
405
|
-
),
|
|
406
|
-
};
|
|
597
|
+
if (index <= 0 || index === source.length - 1) {
|
|
598
|
+
return undefined;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return {
|
|
602
|
+
source: source.slice(0, index),
|
|
603
|
+
fragment: source.slice(index + ANCHOR_SEPARATOR.length),
|
|
604
|
+
};
|
|
407
605
|
}
|
|
408
606
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
607
|
+
type AnchoredOriginOutcome = number | ReadToolResult;
|
|
608
|
+
|
|
609
|
+
async function resolveAnchoredOrigin(
|
|
610
|
+
pipeline: ReadPipelineContext,
|
|
611
|
+
fragments: readonly RegisteredFragment[],
|
|
612
|
+
fragment: string,
|
|
613
|
+
): Promise<AnchoredOriginOutcome> {
|
|
614
|
+
const state = requiredValue(pipeline.state);
|
|
615
|
+
|
|
616
|
+
if (state.contentKind !== "text") {
|
|
617
|
+
return failureResult({
|
|
618
|
+
code: "UNSUPPORTED_RANGE",
|
|
619
|
+
source: state.source,
|
|
620
|
+
resolverId: state.resolvedBy,
|
|
621
|
+
message: "Anchored reads require textual content",
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
if (fragments.length === 0) {
|
|
626
|
+
return failureResult({
|
|
627
|
+
code: "NO_FRAGMENT_RESOLVER",
|
|
628
|
+
source: state.source,
|
|
629
|
+
message: `No fragment resolver is registered for anchor "${fragment}"`,
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
for (const { registration } of fragments) {
|
|
634
|
+
let outcome: unknown;
|
|
635
|
+
|
|
636
|
+
try {
|
|
637
|
+
outcome = await registration.resolve({
|
|
638
|
+
source: state.source,
|
|
639
|
+
fragment,
|
|
640
|
+
text: state.text,
|
|
641
|
+
cwd: pipeline.resolverContext.cwd,
|
|
642
|
+
...(pipeline.resolverContext.signal !== undefined && {
|
|
643
|
+
signal: pipeline.resolverContext.signal,
|
|
644
|
+
}),
|
|
645
|
+
});
|
|
646
|
+
} catch (error) {
|
|
647
|
+
return failureResult({
|
|
648
|
+
code: "FRAGMENT_FAILED",
|
|
649
|
+
source: state.source,
|
|
650
|
+
resolverId: registration.id,
|
|
651
|
+
message: appendErrorMessage(`Fragment resolver ${registration.id} failed`, error),
|
|
652
|
+
cause: error,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
415
655
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
656
|
+
if (!isReadFragmentResolution(outcome)) {
|
|
657
|
+
return failureResult({
|
|
658
|
+
code: "INVALID_RESOLVER_RESULT",
|
|
659
|
+
source: state.source,
|
|
660
|
+
resolverId: registration.id,
|
|
661
|
+
message: `Fragment resolver ${registration.id} returned an invalid result`,
|
|
662
|
+
cause: outcome,
|
|
663
|
+
});
|
|
664
|
+
}
|
|
422
665
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
registered.pluginId,
|
|
427
|
-
"pre-read",
|
|
428
|
-
);
|
|
666
|
+
if (outcome.kind === "not-handled") {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
429
669
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
670
|
+
if (outcome.kind === "failed") {
|
|
671
|
+
return failureResult({
|
|
672
|
+
code: "FRAGMENT_FAILED",
|
|
673
|
+
source: state.source,
|
|
674
|
+
resolverId: registration.id,
|
|
675
|
+
message: outcome.message,
|
|
676
|
+
});
|
|
677
|
+
}
|
|
434
678
|
|
|
435
|
-
|
|
679
|
+
if (
|
|
680
|
+
!Number.isInteger(outcome.originLine) ||
|
|
681
|
+
outcome.originLine < 1 ||
|
|
682
|
+
outcome.originLine > state.text.lines.length
|
|
683
|
+
) {
|
|
684
|
+
return failureResult({
|
|
685
|
+
code: "INVALID_RESOLVER_RESULT",
|
|
686
|
+
source: state.source,
|
|
687
|
+
resolverId: registration.id,
|
|
688
|
+
message: `Fragment resolver ${registration.id} returned out-of-range origin line ${outcome.originLine}`,
|
|
689
|
+
});
|
|
436
690
|
}
|
|
437
691
|
|
|
438
|
-
return
|
|
692
|
+
return outcome.originLine;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return failureResult({
|
|
696
|
+
code: "NO_FRAGMENT_RESOLVER",
|
|
697
|
+
source: state.source,
|
|
698
|
+
message: `No fragment resolver handled anchor "${fragment}"`,
|
|
699
|
+
});
|
|
439
700
|
}
|
|
440
701
|
|
|
441
|
-
async function
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
): Promise<ReadStageOutcome>
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
702
|
+
async function resolveSource(
|
|
703
|
+
initialContext: ReadPipelineContext,
|
|
704
|
+
resolvers: readonly RegisteredResolver[],
|
|
705
|
+
): Promise<ReadStageOutcome> {
|
|
706
|
+
const source = requiredValue(initialContext.request.path);
|
|
707
|
+
const resolverContext = initialContext.resolverContext;
|
|
708
|
+
|
|
709
|
+
for (const registeredResolver of resolvers) {
|
|
710
|
+
const { resolver } = registeredResolver;
|
|
711
|
+
let attempt: unknown;
|
|
712
|
+
|
|
713
|
+
try {
|
|
714
|
+
attempt = await resolver.tryResolve(source, resolverContext);
|
|
715
|
+
} catch (error) {
|
|
716
|
+
return {
|
|
717
|
+
kind: "return",
|
|
718
|
+
result: failureResult({
|
|
719
|
+
code: "RESOLVE_FAILED",
|
|
720
|
+
source,
|
|
721
|
+
resolverId: resolver.id,
|
|
722
|
+
message: appendErrorMessage(`Resolver ${resolver.id} failed`, error),
|
|
723
|
+
cause: error,
|
|
724
|
+
}),
|
|
725
|
+
};
|
|
726
|
+
}
|
|
454
727
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
728
|
+
if (!isResourceResolutionAttempt(attempt)) {
|
|
729
|
+
return {
|
|
730
|
+
kind: "return",
|
|
731
|
+
result: failureResult({
|
|
732
|
+
code: "INVALID_RESOLVER_RESULT",
|
|
733
|
+
source,
|
|
734
|
+
resolverId: resolver.id,
|
|
735
|
+
message: `Resolver ${resolver.id} returned an invalid result`,
|
|
736
|
+
cause: attempt,
|
|
737
|
+
}),
|
|
738
|
+
};
|
|
739
|
+
}
|
|
458
740
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
741
|
+
if (attempt.kind === "not-handled") {
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
463
744
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
745
|
+
if (attempt.kind === "failed") {
|
|
746
|
+
return {
|
|
747
|
+
kind: "return",
|
|
748
|
+
result: failureResult({
|
|
749
|
+
code: "RESOLVE_FAILED",
|
|
750
|
+
source,
|
|
751
|
+
resolverId: resolver.id,
|
|
752
|
+
message: appendErrorMessage(`Resolver ${resolver.id} failed`, attempt.error),
|
|
753
|
+
cause: attempt.error,
|
|
754
|
+
}),
|
|
755
|
+
};
|
|
756
|
+
}
|
|
470
757
|
|
|
471
|
-
|
|
472
|
-
{
|
|
473
|
-
return outcome;
|
|
474
|
-
}
|
|
758
|
+
const resource = attempt.resource;
|
|
475
759
|
|
|
476
|
-
|
|
760
|
+
if (resource.read === undefined) {
|
|
761
|
+
return {
|
|
762
|
+
kind: "return",
|
|
763
|
+
result: failureResult({
|
|
764
|
+
code: "UNSUPPORTED_CAPABILITY",
|
|
765
|
+
source: resource.source,
|
|
766
|
+
resolverId: resolver.id,
|
|
767
|
+
message: `Resource ${resource.source} does not support reading`,
|
|
768
|
+
}),
|
|
769
|
+
};
|
|
477
770
|
}
|
|
478
771
|
|
|
479
|
-
|
|
480
|
-
}
|
|
772
|
+
let content: unknown;
|
|
481
773
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
)
|
|
486
|
-
{
|
|
487
|
-
|
|
774
|
+
try {
|
|
775
|
+
content = await resource.read({
|
|
776
|
+
...(resolverContext.signal !== undefined && { signal: resolverContext.signal }),
|
|
777
|
+
});
|
|
778
|
+
} catch (error) {
|
|
779
|
+
return {
|
|
780
|
+
kind: "return",
|
|
781
|
+
result: failureResult({
|
|
782
|
+
code: "READ_FAILED",
|
|
783
|
+
source: resource.source,
|
|
784
|
+
resolverId: resolver.id,
|
|
785
|
+
message: appendErrorMessage(`Unable to read ${resource.source}`, error),
|
|
786
|
+
cause: error,
|
|
787
|
+
}),
|
|
788
|
+
};
|
|
789
|
+
}
|
|
488
790
|
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
return
|
|
791
|
+
if (!isAgentContent(content)) {
|
|
792
|
+
return {
|
|
793
|
+
kind: "return",
|
|
794
|
+
result: failureResult({
|
|
795
|
+
code: "INVALID_RESOURCE_CONTENT",
|
|
796
|
+
source: resource.source,
|
|
797
|
+
resolverId: resolver.id,
|
|
798
|
+
message: `Resource ${resource.source} returned invalid content`,
|
|
799
|
+
cause: content,
|
|
800
|
+
}),
|
|
801
|
+
};
|
|
492
802
|
}
|
|
493
803
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
804
|
+
return {
|
|
805
|
+
kind: "continue",
|
|
806
|
+
context: {
|
|
807
|
+
...initialContext,
|
|
808
|
+
state: createReadState(content, resource.source, resolver.id, {
|
|
809
|
+
preserveTruncatedOutput: registeredResolver.preserveTruncatedOutput,
|
|
810
|
+
textMode: resolver.id === "temp" ? "final" : "normal",
|
|
811
|
+
}),
|
|
812
|
+
},
|
|
501
813
|
};
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
const reason = `No resolver handled ${source}`;
|
|
817
|
+
return {
|
|
818
|
+
kind: "return",
|
|
819
|
+
result: withBlockedToolResult(
|
|
820
|
+
failureResult({
|
|
821
|
+
code: "NO_RESOLVER",
|
|
822
|
+
source,
|
|
823
|
+
message: reason,
|
|
824
|
+
}),
|
|
825
|
+
reason,
|
|
826
|
+
),
|
|
827
|
+
};
|
|
509
828
|
}
|
|
510
829
|
|
|
511
|
-
function
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
):
|
|
515
|
-
|
|
516
|
-
|
|
830
|
+
async function runPreReadHandlers(
|
|
831
|
+
initialContext: ReadPipelineContext,
|
|
832
|
+
handlers: readonly RegisteredHandler[],
|
|
833
|
+
): Promise<ReadStageOutcome> {
|
|
834
|
+
let context = initialContext;
|
|
835
|
+
|
|
836
|
+
for (const registered of handlers) {
|
|
837
|
+
if (registered.registration.stage !== "pre-read") {
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
517
840
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
841
|
+
const outcome = await invokeHandler(
|
|
842
|
+
registered.registration.handler,
|
|
843
|
+
context,
|
|
844
|
+
registered.pluginId,
|
|
845
|
+
"pre-read",
|
|
846
|
+
);
|
|
847
|
+
|
|
848
|
+
if (outcome.kind === "return") {
|
|
849
|
+
return outcome;
|
|
524
850
|
}
|
|
525
851
|
|
|
526
|
-
|
|
852
|
+
context = outcome.context;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
return { kind: "continue", context };
|
|
527
856
|
}
|
|
528
857
|
|
|
529
|
-
function
|
|
530
|
-
|
|
531
|
-
|
|
858
|
+
async function runReadHandlers(
|
|
859
|
+
initialContext: ReadPipelineContext,
|
|
860
|
+
handlers: readonly RegisteredHandler[],
|
|
861
|
+
): Promise<ReadStageOutcome> {
|
|
862
|
+
const initialState = initialContext.state;
|
|
863
|
+
const matchingHandlers =
|
|
864
|
+
initialState === undefined
|
|
865
|
+
? []
|
|
866
|
+
: handlers.filter(
|
|
867
|
+
(registered) =>
|
|
868
|
+
registered.registration.stage === "read" &&
|
|
869
|
+
matchesReadState(registered.registration, initialState),
|
|
870
|
+
);
|
|
871
|
+
let context = initialContext;
|
|
532
872
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|| presented.content !== base.content
|
|
536
|
-
|| presented.lines.length !== base.lines.length
|
|
537
|
-
)
|
|
538
|
-
{
|
|
539
|
-
throw new Error(`Text presenter ${contribution.presenterId} changed canonical text`);
|
|
540
|
-
}
|
|
873
|
+
for (const registered of matchingHandlers) {
|
|
874
|
+
const registration = registered.registration;
|
|
541
875
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const baseLine = base.lines[index]!;
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
-
line.lineNumber !== baseLine.lineNumber
|
|
548
|
-
|| line.content !== baseLine.content
|
|
549
|
-
|| line.lineEnding !== baseLine.lineEnding
|
|
550
|
-
)
|
|
551
|
-
{
|
|
552
|
-
throw new Error(`Text presenter ${contribution.presenterId} changed canonical text`);
|
|
553
|
-
}
|
|
876
|
+
if (registration.stage !== "read") {
|
|
877
|
+
continue;
|
|
554
878
|
}
|
|
555
|
-
}
|
|
556
879
|
|
|
557
|
-
|
|
558
|
-
{
|
|
559
|
-
const presentation = mergeLinePresentation(base.presentation, current.presentation, contribution.presentation);
|
|
560
|
-
const metadata = mergeLineMetadata(base.metadata, current.metadata, contribution.metadata);
|
|
880
|
+
const outcome = await invokeHandler(registration.handler, context, registered.pluginId, "read");
|
|
561
881
|
|
|
562
|
-
if (
|
|
563
|
-
|
|
564
|
-
return current;
|
|
882
|
+
if (outcome.kind === "return") {
|
|
883
|
+
return outcome;
|
|
565
884
|
}
|
|
566
885
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
};
|
|
886
|
+
context = outcome.context;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
return { kind: "continue", context };
|
|
572
890
|
}
|
|
573
891
|
|
|
574
|
-
function
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
):
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
892
|
+
async function runTextPresenters(
|
|
893
|
+
context: ReadPipelineContext,
|
|
894
|
+
views: readonly RegisteredView[],
|
|
895
|
+
requestedViews: ReadonlySet<string>,
|
|
896
|
+
): Promise<ReadPipelineContext> {
|
|
897
|
+
const state = context.state;
|
|
898
|
+
|
|
899
|
+
if (state?.contentKind !== "text" || requestedViews.size === 0) {
|
|
900
|
+
return context;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
const document = state.text;
|
|
904
|
+
const presentationContext: TextPresentationContext = {
|
|
905
|
+
purpose: "read",
|
|
906
|
+
source: state.source,
|
|
907
|
+
cwd: context.resolverContext.cwd,
|
|
908
|
+
resolvedBy: state.resolvedBy,
|
|
909
|
+
...(context.resolverContext.signal !== undefined && { signal: context.resolverContext.signal }),
|
|
910
|
+
};
|
|
911
|
+
const requestedRegistrations = views.filter(({ registration }) =>
|
|
912
|
+
requestedViews.has(registration.view),
|
|
913
|
+
);
|
|
914
|
+
const includedViews = new Set(
|
|
915
|
+
requestedRegistrations.flatMap(({ registration }) => registration.includes ?? []),
|
|
916
|
+
);
|
|
917
|
+
const activeViews = requestedRegistrations.filter(
|
|
918
|
+
({ registration }) => !includedViews.has(registration.view),
|
|
919
|
+
);
|
|
920
|
+
const contributions = await Promise.all(
|
|
921
|
+
activeViews.map(async ({ registration }) => ({
|
|
922
|
+
presenterId: registration.presenter.id,
|
|
923
|
+
document: await registration.presenter.present(document, presentationContext),
|
|
924
|
+
})),
|
|
925
|
+
);
|
|
926
|
+
const presented = mergeViewContributions(document, contributions);
|
|
927
|
+
|
|
928
|
+
return { ...context, state: { ...state, text: presented } };
|
|
929
|
+
}
|
|
584
930
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
931
|
+
/** Prepends a note listing unknown view names so the agent can correct the request. */
|
|
932
|
+
function withIgnoredViews(result: ReadToolResult, ignoredViews: readonly string[]): ReadToolResult {
|
|
933
|
+
if (ignoredViews.length === 0) {
|
|
934
|
+
return result;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
const note = `note: ignored unknown views: ${ignoredViews.join(", ")}`;
|
|
938
|
+
const block = result.content[0];
|
|
939
|
+
const content =
|
|
940
|
+
block?.type === "text" ? [{ ...block, text: `${note}\n${block.text}` }] : [...result.content];
|
|
941
|
+
|
|
942
|
+
return {
|
|
943
|
+
...result,
|
|
944
|
+
content,
|
|
945
|
+
details: { ...result.details, ignoredViews },
|
|
946
|
+
};
|
|
947
|
+
}
|
|
590
948
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
949
|
+
function mergeViewContributions(
|
|
950
|
+
base: TextDocument,
|
|
951
|
+
contributions: readonly ViewContribution[],
|
|
952
|
+
): TextDocument {
|
|
953
|
+
let lines = base.lines;
|
|
954
|
+
|
|
955
|
+
for (const contribution of contributions) {
|
|
956
|
+
assertPresentationOnly(base, contribution);
|
|
957
|
+
lines = lines.map((line, index) =>
|
|
958
|
+
mergePresentedLine(
|
|
959
|
+
requiredValue(base.lines[index]),
|
|
960
|
+
line,
|
|
961
|
+
requiredValue(contribution.document.lines[index]),
|
|
962
|
+
),
|
|
963
|
+
);
|
|
964
|
+
}
|
|
601
965
|
|
|
602
|
-
|
|
603
|
-
...current,
|
|
604
|
-
...(prefix === undefined ? {} : { prefix }),
|
|
605
|
-
...(suffix === undefined ? {} : { suffix }),
|
|
606
|
-
...(before === undefined ? {} : { before }),
|
|
607
|
-
...(after === undefined ? {} : { after }),
|
|
608
|
-
...(marker === undefined ? {} : { marker }),
|
|
609
|
-
};
|
|
966
|
+
return lines === base.lines ? base : { ...base, lines };
|
|
610
967
|
}
|
|
611
968
|
|
|
612
|
-
function
|
|
613
|
-
|
|
614
|
-
current: string | undefined,
|
|
615
|
-
contribution: string | undefined,
|
|
616
|
-
): string | undefined
|
|
617
|
-
{
|
|
618
|
-
if (contribution === base)
|
|
619
|
-
{
|
|
620
|
-
return current;
|
|
621
|
-
}
|
|
969
|
+
function assertPresentationOnly(base: TextDocument, contribution: ViewContribution): void {
|
|
970
|
+
const presented = contribution.document;
|
|
622
971
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
972
|
+
if (
|
|
973
|
+
presented.source !== base.source ||
|
|
974
|
+
presented.content !== base.content ||
|
|
975
|
+
presented.lines.length !== base.lines.length
|
|
976
|
+
) {
|
|
977
|
+
throw new Error(`Text presenter ${contribution.presenterId} changed canonical text`);
|
|
978
|
+
}
|
|
626
979
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
return `${currentText}${contributionText.slice(baseText.length)}`;
|
|
630
|
-
}
|
|
980
|
+
for (const [index, line] of presented.lines.entries()) {
|
|
981
|
+
const baseLine = requiredValue(base.lines[index]);
|
|
631
982
|
|
|
632
|
-
if (
|
|
633
|
-
|
|
634
|
-
|
|
983
|
+
if (
|
|
984
|
+
line.lineNumber !== baseLine.lineNumber ||
|
|
985
|
+
line.content !== baseLine.content ||
|
|
986
|
+
line.lineEnding !== baseLine.lineEnding
|
|
987
|
+
) {
|
|
988
|
+
throw new Error(`Text presenter ${contribution.presenterId} changed canonical text`);
|
|
635
989
|
}
|
|
636
|
-
|
|
637
|
-
return `${currentText}${contributionText}`;
|
|
990
|
+
}
|
|
638
991
|
}
|
|
639
992
|
|
|
640
|
-
function
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
993
|
+
function mergePresentedLine(base: TextLine, current: TextLine, contribution: TextLine): TextLine {
|
|
994
|
+
const presentation = mergeLinePresentation(
|
|
995
|
+
base.presentation,
|
|
996
|
+
current.presentation,
|
|
997
|
+
contribution.presentation,
|
|
998
|
+
);
|
|
999
|
+
const metadata = mergeLineMetadata(base.metadata, current.metadata, contribution.metadata);
|
|
1000
|
+
|
|
1001
|
+
if (presentation === current.presentation && metadata === current.metadata) {
|
|
1002
|
+
return current;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
return {
|
|
1006
|
+
...current,
|
|
1007
|
+
...(presentation !== undefined && { presentation }),
|
|
1008
|
+
...(metadata !== undefined && { metadata }),
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
654
1011
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
1012
|
+
function mergeLinePresentation(
|
|
1013
|
+
base: TextLinePresentation | undefined,
|
|
1014
|
+
current: TextLinePresentation | undefined,
|
|
1015
|
+
contribution: TextLinePresentation | undefined,
|
|
1016
|
+
): TextLinePresentation | undefined {
|
|
1017
|
+
if (contribution === base) {
|
|
1018
|
+
return current;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
const prefix = mergePresentedText(base?.prefix, current?.prefix, contribution?.prefix);
|
|
1022
|
+
const suffix = mergePresentedText(base?.suffix, current?.suffix, contribution?.suffix);
|
|
1023
|
+
const before = mergePresentedRows(base?.before, current?.before, contribution?.before);
|
|
1024
|
+
const after = mergePresentedRows(base?.after, current?.after, contribution?.after);
|
|
1025
|
+
const marker = contribution?.marker === base?.marker ? current?.marker : contribution?.marker;
|
|
1026
|
+
|
|
1027
|
+
if (
|
|
1028
|
+
prefix === current?.prefix &&
|
|
1029
|
+
suffix === current?.suffix &&
|
|
1030
|
+
before === current?.before &&
|
|
1031
|
+
after === current?.after &&
|
|
1032
|
+
marker === current?.marker
|
|
1033
|
+
) {
|
|
1034
|
+
return current;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
return {
|
|
1038
|
+
...current,
|
|
1039
|
+
...(prefix !== undefined && { prefix }),
|
|
1040
|
+
...(suffix !== undefined && { suffix }),
|
|
1041
|
+
...(before !== undefined && { before }),
|
|
1042
|
+
...(after !== undefined && { after }),
|
|
1043
|
+
...(marker !== undefined && { marker }),
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
659
1046
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
1047
|
+
function mergePresentedText(
|
|
1048
|
+
base: string | undefined,
|
|
1049
|
+
current: string | undefined,
|
|
1050
|
+
contribution: string | undefined,
|
|
1051
|
+
): string | undefined {
|
|
1052
|
+
if (contribution === base) {
|
|
1053
|
+
return current;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
const baseText = base ?? "";
|
|
1057
|
+
const currentText = current ?? "";
|
|
1058
|
+
const contributionText = contribution ?? "";
|
|
1059
|
+
|
|
1060
|
+
if (baseText.length > 0 && contributionText.startsWith(baseText)) {
|
|
1061
|
+
return `${currentText}${contributionText.slice(baseText.length)}`;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
if (baseText.length > 0 && contributionText.endsWith(baseText)) {
|
|
1065
|
+
return `${contributionText.slice(0, -baseText.length)}${currentText}`;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
return `${currentText}${contributionText}`;
|
|
1069
|
+
}
|
|
664
1070
|
|
|
665
|
-
|
|
1071
|
+
function mergePresentedRows(
|
|
1072
|
+
base: readonly PresentedTextRow[] | undefined,
|
|
1073
|
+
current: readonly PresentedTextRow[] | undefined,
|
|
1074
|
+
contribution: readonly PresentedTextRow[] | undefined,
|
|
1075
|
+
): readonly PresentedTextRow[] | undefined {
|
|
1076
|
+
if (contribution === base) {
|
|
1077
|
+
return current;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
const baseRows = base ?? [];
|
|
1081
|
+
const currentRows = current ?? [];
|
|
1082
|
+
const contributionRows = contribution ?? [];
|
|
1083
|
+
|
|
1084
|
+
if (startsWithRows(contributionRows, baseRows)) {
|
|
1085
|
+
return [...currentRows, ...contributionRows.slice(baseRows.length)];
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
if (endsWithRows(contributionRows, baseRows)) {
|
|
1089
|
+
return [
|
|
1090
|
+
...contributionRows.slice(0, contributionRows.length - baseRows.length),
|
|
1091
|
+
...currentRows,
|
|
1092
|
+
];
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
return [...currentRows, ...contributionRows];
|
|
666
1096
|
}
|
|
667
1097
|
|
|
668
|
-
function startsWithRows(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
1098
|
+
function startsWithRows(
|
|
1099
|
+
rows: readonly PresentedTextRow[],
|
|
1100
|
+
prefix: readonly PresentedTextRow[],
|
|
1101
|
+
): boolean {
|
|
1102
|
+
return (
|
|
1103
|
+
prefix.length > 0 &&
|
|
1104
|
+
prefix.length <= rows.length &&
|
|
1105
|
+
prefix.every((row, index) => rows[index] === row)
|
|
1106
|
+
);
|
|
673
1107
|
}
|
|
674
1108
|
|
|
675
|
-
function endsWithRows(
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
1109
|
+
function endsWithRows(
|
|
1110
|
+
rows: readonly PresentedTextRow[],
|
|
1111
|
+
suffix: readonly PresentedTextRow[],
|
|
1112
|
+
): boolean {
|
|
1113
|
+
const offset = rows.length - suffix.length;
|
|
1114
|
+
return (
|
|
1115
|
+
suffix.length > 0 && offset >= 0 && suffix.every((row, index) => rows[offset + index] === row)
|
|
1116
|
+
);
|
|
681
1117
|
}
|
|
682
1118
|
|
|
683
1119
|
function mergeLineMetadata(
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
): TextLine["metadata"]
|
|
688
|
-
{
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
return Object.keys(additions).length === 0 ? current : { ...current, ...additions };
|
|
1120
|
+
base: TextLine["metadata"],
|
|
1121
|
+
current: TextLine["metadata"],
|
|
1122
|
+
contribution: TextLine["metadata"],
|
|
1123
|
+
): TextLine["metadata"] {
|
|
1124
|
+
if (contribution === base || contribution === undefined) {
|
|
1125
|
+
return current;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
const additions = Object.fromEntries(
|
|
1129
|
+
Object.entries(contribution).filter(([key, value]) => base?.[key] !== value),
|
|
1130
|
+
);
|
|
1131
|
+
|
|
1132
|
+
return Object.keys(additions).length === 0 ? current : { ...current, ...additions };
|
|
699
1133
|
}
|
|
700
1134
|
|
|
701
1135
|
async function runPostReadHandlers(
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
): Promise<ReadStageOutcome>
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
{
|
|
712
|
-
continue;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
const outcome = await invokeHandler(
|
|
716
|
-
registered.registration.handler,
|
|
717
|
-
context,
|
|
718
|
-
registered.pluginId,
|
|
719
|
-
"post-read",
|
|
720
|
-
);
|
|
1136
|
+
initialContext: ReadPipelineContext,
|
|
1137
|
+
handlers: readonly RegisteredHandler[],
|
|
1138
|
+
): Promise<ReadStageOutcome> {
|
|
1139
|
+
let context = initialContext;
|
|
1140
|
+
|
|
1141
|
+
for (const registered of handlers) {
|
|
1142
|
+
if (registered.registration.stage !== "post-read") {
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
721
1145
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
1146
|
+
const outcome = await invokeHandler(
|
|
1147
|
+
registered.registration.handler,
|
|
1148
|
+
context,
|
|
1149
|
+
registered.pluginId,
|
|
1150
|
+
"post-read",
|
|
1151
|
+
);
|
|
726
1152
|
|
|
727
|
-
|
|
1153
|
+
if (outcome.kind === "return") {
|
|
1154
|
+
return outcome;
|
|
728
1155
|
}
|
|
729
1156
|
|
|
730
|
-
|
|
1157
|
+
context = outcome.context;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
return { kind: "continue", context };
|
|
731
1161
|
}
|
|
732
1162
|
|
|
733
1163
|
async function invokeHandler(
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
): Promise<ReadStageOutcome>
|
|
739
|
-
{
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
cause: error,
|
|
759
|
-
}),
|
|
760
|
-
};
|
|
761
|
-
}
|
|
1164
|
+
handler: (context: ReadPipelineContext) => ReadStageOutcome | Promise<ReadStageOutcome>,
|
|
1165
|
+
context: ReadPipelineContext,
|
|
1166
|
+
pluginId: string,
|
|
1167
|
+
stage: ReadPipelineStage,
|
|
1168
|
+
): Promise<ReadStageOutcome> {
|
|
1169
|
+
try {
|
|
1170
|
+
return await handler(context);
|
|
1171
|
+
} catch (error) {
|
|
1172
|
+
return {
|
|
1173
|
+
kind: "return",
|
|
1174
|
+
result: failureResult({
|
|
1175
|
+
code: "PIPELINE_FAILED",
|
|
1176
|
+
...(context.state?.source === undefined
|
|
1177
|
+
? context.result?.details.source === undefined
|
|
1178
|
+
? {}
|
|
1179
|
+
: { source: context.result.details.source }
|
|
1180
|
+
: { source: context.state.source }),
|
|
1181
|
+
pluginId,
|
|
1182
|
+
stage,
|
|
1183
|
+
message: `Plugin ${pluginId} failed during ${stage}`,
|
|
1184
|
+
cause: error,
|
|
1185
|
+
}),
|
|
1186
|
+
};
|
|
1187
|
+
}
|
|
762
1188
|
}
|
|
763
1189
|
|
|
764
1190
|
function matchesReadState(
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
): boolean
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
1191
|
+
registration: Extract<ReadHandlerRegistration, { readonly stage: "read" }>,
|
|
1192
|
+
state: ReadState,
|
|
1193
|
+
): boolean {
|
|
1194
|
+
return (
|
|
1195
|
+
(registration.when.resolvedBy === "any" || registration.when.resolvedBy === state.resolvedBy) &&
|
|
1196
|
+
(registration.when.contentKind === "any" || registration.when.contentKind === state.contentKind)
|
|
1197
|
+
);
|
|
771
1198
|
}
|
|
772
1199
|
|
|
773
1200
|
function validateContributions(
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
): void
|
|
780
|
-
{
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
{
|
|
787
|
-
throw new TypeError(`Plugin ${pluginId} provided an invalid resource resolver`);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
if (resolverIds.has(registration.resolver.id))
|
|
791
|
-
{
|
|
792
|
-
throw new Error(`Resource resolver ${registration.resolver.id} is already registered`);
|
|
793
|
-
}
|
|
1201
|
+
pluginId: string,
|
|
1202
|
+
incomingResolvers: readonly ResourceResolverRegistration[],
|
|
1203
|
+
incomingHandlers: readonly ReadHandlerRegistration[],
|
|
1204
|
+
registeredResolvers: readonly RegisteredResolver[],
|
|
1205
|
+
registeredHandlers: readonly RegisteredHandler[],
|
|
1206
|
+
): void {
|
|
1207
|
+
const resolverIds = new Set(registeredResolvers.map(({ resolver }) => resolver.id));
|
|
1208
|
+
|
|
1209
|
+
for (const registration of incomingResolvers) {
|
|
1210
|
+
if (!isResourceResolverRegistration(registration)) {
|
|
1211
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid resource resolver`);
|
|
1212
|
+
}
|
|
794
1213
|
|
|
795
|
-
|
|
1214
|
+
if (resolverIds.has(registration.resolver.id)) {
|
|
1215
|
+
throw new Error(`Resource resolver ${registration.resolver.id} is already registered`);
|
|
796
1216
|
}
|
|
797
1217
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
.filter((handler) => handler.pluginId === pluginId)
|
|
801
|
-
.map((handler) => handler.registration.stage),
|
|
802
|
-
);
|
|
1218
|
+
resolverIds.add(registration.resolver.id);
|
|
1219
|
+
}
|
|
803
1220
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
}
|
|
1221
|
+
const stages = new Set(
|
|
1222
|
+
registeredHandlers
|
|
1223
|
+
.filter((handler) => handler.pluginId === pluginId)
|
|
1224
|
+
.map((handler) => handler.registration.stage),
|
|
1225
|
+
);
|
|
810
1226
|
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1227
|
+
for (const registration of incomingHandlers) {
|
|
1228
|
+
if (!isReadHandlerRegistration(registration)) {
|
|
1229
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid read handler`);
|
|
1230
|
+
}
|
|
815
1231
|
|
|
816
|
-
|
|
1232
|
+
if (stages.has(registration.stage)) {
|
|
1233
|
+
throw new Error(`Plugin ${pluginId} already handles ${registration.stage}`);
|
|
817
1234
|
}
|
|
1235
|
+
|
|
1236
|
+
stages.add(registration.stage);
|
|
1237
|
+
}
|
|
818
1238
|
}
|
|
819
1239
|
|
|
820
|
-
function
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1240
|
+
function validateFragmentRegistrations(
|
|
1241
|
+
pluginId: string,
|
|
1242
|
+
incoming: readonly FragmentResolverRegistration[],
|
|
1243
|
+
registered: readonly RegisteredFragment[],
|
|
1244
|
+
): void {
|
|
1245
|
+
const ids = new Set(registered.map(({ registration }) => registration.id));
|
|
1246
|
+
|
|
1247
|
+
for (const registration of incoming) {
|
|
1248
|
+
if (!isFragmentResolverRegistration(registration)) {
|
|
1249
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid fragment resolver`);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
if (ids.has(registration.id)) {
|
|
1253
|
+
throw new Error(`Fragment resolver ${registration.id} is already registered`);
|
|
825
1254
|
}
|
|
826
1255
|
|
|
827
|
-
|
|
1256
|
+
ids.add(registration.id);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
function appendErrorMessage(message: string, cause: unknown): string {
|
|
1260
|
+
if (!(cause instanceof Error) || cause.message.length === 0) {
|
|
1261
|
+
return message;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
return `${message}: ${cause.message}`;
|
|
828
1265
|
}
|