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,2348 +1,2220 @@
|
|
|
1
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
isAgentContent,
|
|
4
|
+
isResourceResolutionAttempt,
|
|
5
|
+
type Resource,
|
|
6
|
+
type ResourceResolver,
|
|
7
|
+
type ResourceResolverContext,
|
|
8
|
+
type ResourceWrite,
|
|
8
9
|
} from "pi-agent-resource";
|
|
9
10
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
createTextDocument,
|
|
12
|
+
isTextPresenterRegistration,
|
|
13
|
+
type TextAnchor,
|
|
14
|
+
type TextAnchorResolverContext,
|
|
15
|
+
type TextDocument,
|
|
16
|
+
type TextPresentationContext,
|
|
17
|
+
type TextPresenterRegistration,
|
|
18
|
+
type TextTarget,
|
|
19
|
+
type TextTargetResolver,
|
|
17
20
|
} from "pi-agent-text";
|
|
18
21
|
|
|
19
22
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
isTextEditHandlerRegistration,
|
|
24
|
+
type TextEditExecutionOutcome,
|
|
25
|
+
type TextEditHandlerRegistration,
|
|
26
|
+
type TextEditorToolPluginApi,
|
|
27
|
+
type TextEditPipelineFailure,
|
|
28
|
+
type TextEditPipelineStage,
|
|
29
|
+
type TextEditState,
|
|
30
|
+
type TextPreEditState,
|
|
28
31
|
} from "#src/api/edit-pipeline.js";
|
|
29
32
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
type AnyTextMutationToolRegistration,
|
|
34
|
+
assertTextMutationToolRegistration,
|
|
35
|
+
type TextMutationToolListener,
|
|
33
36
|
} from "#src/api/mutation-tool.js";
|
|
34
37
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
isResourceResolverRegistration,
|
|
39
|
+
isTextAnchorResolverRegistration,
|
|
40
|
+
isTextEditorToolId,
|
|
41
|
+
type PromptDescriptionSource,
|
|
42
|
+
type ResourceResolverRegistration,
|
|
43
|
+
TEXT_EDITOR_API_VERSION,
|
|
44
|
+
TEXT_EDITOR_PROTOCOL,
|
|
45
|
+
type TextAnchorResolverRegistration,
|
|
46
|
+
type TextAnchorResourceResolverContext,
|
|
47
|
+
type TextEditorPlugin,
|
|
48
|
+
type TextEditorPluginApi,
|
|
49
|
+
type TextEditorRecoveryConfigSection,
|
|
50
|
+
type TextEditorToolId,
|
|
47
51
|
} from "#src/api/plugin-protocol.js";
|
|
48
52
|
import {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
isTextPostEditHandlerRegistration,
|
|
54
|
+
type TextPostEditContribution,
|
|
55
|
+
type TextPostEditHandlerRegistration,
|
|
56
|
+
type TextPostEditTransaction,
|
|
53
57
|
} from "#src/api/post-edit.js";
|
|
54
58
|
import {
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
isTextEditorToolRendererRegistration,
|
|
60
|
+
type TextEditorToolRendererRegistration,
|
|
57
61
|
} from "#src/api/tool-renderer.js";
|
|
58
|
-
import {
|
|
59
|
-
|
|
62
|
+
import {
|
|
63
|
+
TextAnchorRegistry,
|
|
64
|
+
type TextAnchorRegistrySnapshot,
|
|
65
|
+
} from "#src/core/text-anchor-registry.js";
|
|
66
|
+
import {
|
|
67
|
+
applyTextChanges,
|
|
68
|
+
type TextChange,
|
|
69
|
+
type TextChangeResult,
|
|
70
|
+
} from "#src/core/text-change-engine.js";
|
|
60
71
|
import { previewTextMutation } from "#src/core/text-mutation.js";
|
|
72
|
+
import { loadTextEditorConfig, recoverySection } from "#src/core/text-editor-config.js";
|
|
61
73
|
|
|
62
|
-
import type { TextAnchorInspectionOutcome, TextAnchorInspectionRequest } from "#src/api/anchor-inspection.js";
|
|
63
|
-
import type { TextEditCompletion, TextEditCompletionListener, TextEditIntent } from "#src/api/edit-completion.js";
|
|
64
74
|
import type {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
TextAnchorInspectionOutcome,
|
|
76
|
+
TextAnchorInspectionRequest,
|
|
77
|
+
} from "#src/api/anchor-inspection.js";
|
|
78
|
+
import type {
|
|
79
|
+
TextEditCompletion,
|
|
80
|
+
TextEditCompletionListener,
|
|
81
|
+
TextEditIntent,
|
|
82
|
+
} from "#src/api/edit-completion.js";
|
|
83
|
+
import type {
|
|
84
|
+
TextMutationGuardContext,
|
|
85
|
+
TextMutationGuardRegistration,
|
|
86
|
+
TextMutationPlan,
|
|
68
87
|
} from "#src/api/mutation-guard.js";
|
|
69
|
-
import type {
|
|
88
|
+
import type {
|
|
89
|
+
TextMutationPreviewOutcome,
|
|
90
|
+
TextMutationPreviewRequest,
|
|
91
|
+
} from "#src/api/mutation-preview.js";
|
|
70
92
|
|
|
71
93
|
type PluginStatus = "active" | "pending";
|
|
72
94
|
|
|
73
|
-
interface PluginLifecycle
|
|
74
|
-
|
|
75
|
-
status: PluginStatus;
|
|
95
|
+
interface PluginLifecycle {
|
|
96
|
+
status: PluginStatus;
|
|
76
97
|
}
|
|
77
98
|
|
|
78
|
-
interface RegisteredPlugin
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
readonly ready: Promise<void>;
|
|
99
|
+
interface RegisteredPlugin {
|
|
100
|
+
readonly lifecycle: PluginLifecycle;
|
|
101
|
+
readonly plugin: TextEditorPlugin;
|
|
102
|
+
readonly ready: Promise<void>;
|
|
83
103
|
}
|
|
84
104
|
|
|
85
|
-
interface RegisteredHandler
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
readonly tool: TextEditorToolId;
|
|
105
|
+
interface RegisteredHandler {
|
|
106
|
+
readonly pluginId: string;
|
|
107
|
+
readonly registration: TextEditHandlerRegistration;
|
|
108
|
+
readonly tool: TextEditorToolId;
|
|
90
109
|
}
|
|
91
110
|
|
|
92
|
-
interface RegisteredResolver
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
readonly order: number;
|
|
111
|
+
interface RegisteredResolver {
|
|
112
|
+
readonly resolver: ResourceResolver;
|
|
113
|
+
readonly priority: number;
|
|
114
|
+
readonly order: number;
|
|
97
115
|
}
|
|
98
116
|
|
|
99
|
-
interface ResolverContribution
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
readonly registration: ResourceResolverRegistration;
|
|
117
|
+
interface ResolverContribution {
|
|
118
|
+
readonly pluginId: string;
|
|
119
|
+
readonly registration: ResourceResolverRegistration;
|
|
103
120
|
}
|
|
104
121
|
|
|
105
|
-
interface TextAnchorResolverContribution
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
readonly registration: TextAnchorResolverRegistration;
|
|
122
|
+
interface TextAnchorResolverContribution {
|
|
123
|
+
readonly pluginId: string;
|
|
124
|
+
readonly registration: TextAnchorResolverRegistration;
|
|
109
125
|
}
|
|
110
126
|
|
|
111
|
-
interface TextPresenterContribution
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
readonly registration: TextPresenterRegistration;
|
|
127
|
+
interface TextPresenterContribution {
|
|
128
|
+
readonly pluginId: string;
|
|
129
|
+
readonly registration: TextPresenterRegistration;
|
|
115
130
|
}
|
|
116
131
|
|
|
117
|
-
interface RegisteredPresenter extends TextPresenterContribution
|
|
118
|
-
|
|
119
|
-
readonly order: number;
|
|
132
|
+
interface RegisteredPresenter extends TextPresenterContribution {
|
|
133
|
+
readonly order: number;
|
|
120
134
|
}
|
|
121
|
-
interface PromptContribution
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
readonly tool: TextEditorToolId;
|
|
135
|
+
interface PromptContribution {
|
|
136
|
+
readonly description: string;
|
|
137
|
+
readonly pluginId: string;
|
|
138
|
+
readonly tool: TextEditorToolId;
|
|
126
139
|
}
|
|
127
140
|
|
|
128
|
-
interface WritablePromptContribution
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
readonly pluginId: string;
|
|
141
|
+
interface WritablePromptContribution {
|
|
142
|
+
readonly description: PromptDescriptionSource;
|
|
143
|
+
readonly pluginId: string;
|
|
132
144
|
}
|
|
133
145
|
|
|
134
|
-
interface PluginContributionDraft
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
readonly toolRenderers?: TextEditorToolRendererRegistration[];
|
|
146
|
+
interface PluginContributionDraft {
|
|
147
|
+
readonly resolvers: ResolverContribution[];
|
|
148
|
+
readonly anchorResolvers: TextAnchorResolverContribution[];
|
|
149
|
+
readonly presenters?: TextPresenterContribution[];
|
|
150
|
+
readonly handlers: RegisteredHandler[];
|
|
151
|
+
readonly promptContributions: PromptContribution[];
|
|
152
|
+
readonly writablePromptContributions: WritablePromptContribution[];
|
|
153
|
+
readonly tools: TextEditorToolId[];
|
|
154
|
+
readonly mutationTools?: AnyTextMutationToolRegistration[];
|
|
155
|
+
readonly mutationToolListeners?: TextMutationToolListener[];
|
|
156
|
+
readonly editCompletionListeners?: TextEditCompletionListener[];
|
|
157
|
+
readonly mutationGuards?: TextMutationGuardRegistration[];
|
|
158
|
+
readonly toolRenderers?: TextEditorToolRendererRegistration[];
|
|
148
159
|
}
|
|
149
160
|
|
|
150
|
-
interface PluginContributionController
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
commit(): void;
|
|
161
|
+
interface PluginContributionController {
|
|
162
|
+
readonly api: TextEditorPluginApi;
|
|
163
|
+
close(): void;
|
|
164
|
+
commit(): void;
|
|
155
165
|
}
|
|
156
166
|
|
|
157
|
-
interface StageRunCompleted<State>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
readonly state: State;
|
|
167
|
+
interface StageRunCompleted<State> {
|
|
168
|
+
readonly kind: "completed";
|
|
169
|
+
readonly state: State;
|
|
161
170
|
}
|
|
162
171
|
|
|
163
|
-
type StageRunOutcome<State> =
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
172
|
+
type StageRunOutcome<State> =
|
|
173
|
+
| StageRunCompleted<State>
|
|
174
|
+
| {
|
|
175
|
+
readonly kind: "failed";
|
|
176
|
+
readonly failure: TextEditPipelineFailure;
|
|
177
|
+
};
|
|
167
178
|
|
|
168
|
-
export interface TextMutationResult<Result>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
readonly result: Result;
|
|
179
|
+
export interface TextMutationResult<Result> {
|
|
180
|
+
readonly text: string;
|
|
181
|
+
readonly result: Result;
|
|
172
182
|
}
|
|
173
183
|
|
|
174
|
-
export interface TextResourceEditFailure
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
readonly cause?: unknown;
|
|
184
|
+
export interface TextResourceEditFailure {
|
|
185
|
+
readonly code:
|
|
186
|
+
| "INVALID_REQUEST"
|
|
187
|
+
| "INVALID_RESOLVER_RESULT"
|
|
188
|
+
| "INVALID_RESOURCE_CONTENT"
|
|
189
|
+
| "INVALID_WRITE_CONTENT"
|
|
190
|
+
| "PLUGIN_FAILED"
|
|
191
|
+
| "MUTATION_REJECTED"
|
|
192
|
+
| "NO_RESOLVER"
|
|
193
|
+
| "POST_WRITE_FAILED"
|
|
194
|
+
| "READ_FAILED"
|
|
195
|
+
| "RESOLVE_FAILED"
|
|
196
|
+
| "UNSUPPORTED_CAPABILITY"
|
|
197
|
+
| "UNSUPPORTED_CONTENT"
|
|
198
|
+
| "WRITE_FAILED";
|
|
199
|
+
readonly source: string;
|
|
200
|
+
readonly resolverId?: string;
|
|
201
|
+
readonly message: string;
|
|
202
|
+
readonly cause?: unknown;
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
export type TextResourceEditOutcome<Result> =
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
206
|
+
| {
|
|
207
|
+
readonly kind: "completed";
|
|
208
|
+
readonly source: string;
|
|
209
|
+
readonly resolvedBy: string;
|
|
210
|
+
readonly before: TextDocument;
|
|
211
|
+
readonly after: TextDocument;
|
|
212
|
+
readonly result: Result;
|
|
213
|
+
readonly postEditContributions: readonly TextPostEditContribution[];
|
|
205
214
|
}
|
|
206
|
-
|
|
215
|
+
| { readonly kind: "failed"; readonly failure: TextResourceEditFailure };
|
|
207
216
|
|
|
208
|
-
export interface TextResourceEditRequest
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
readonly allowReadFailure?: boolean;
|
|
217
|
+
export interface TextResourceEditRequest {
|
|
218
|
+
readonly source: string;
|
|
219
|
+
readonly read: boolean;
|
|
220
|
+
readonly allowReadFailure?: boolean;
|
|
213
221
|
}
|
|
214
222
|
|
|
215
|
-
export interface TextResourcesMutationResult<Result>
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
readonly result: Result;
|
|
223
|
+
export interface TextResourcesMutationResult<Result> {
|
|
224
|
+
readonly changes: ReadonlyMap<string, readonly TextChange[]>;
|
|
225
|
+
readonly result: Result;
|
|
219
226
|
}
|
|
220
227
|
|
|
221
228
|
export type TextResourcesEditOutcome<Result> =
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
| {
|
|
230
|
+
readonly kind: "completed";
|
|
231
|
+
readonly resources: readonly Exclude<
|
|
232
|
+
TextResourceEditOutcome<unknown>,
|
|
233
|
+
{ readonly kind: "failed" }
|
|
234
|
+
>[];
|
|
235
|
+
readonly result: Result;
|
|
226
236
|
}
|
|
227
|
-
|
|
237
|
+
| {
|
|
238
|
+
readonly kind: "failed";
|
|
239
|
+
readonly failure: TextResourceEditFailure;
|
|
240
|
+
readonly completed: readonly string[];
|
|
241
|
+
};
|
|
228
242
|
|
|
229
243
|
export type ResolveTextAnchor = (value: string, kinds?: readonly string[]) => Promise<TextAnchor>;
|
|
230
244
|
|
|
231
245
|
export type ResolveResourceTextAnchor = (
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
246
|
+
source: string,
|
|
247
|
+
value: string,
|
|
248
|
+
kinds?: readonly string[],
|
|
235
249
|
) => Promise<TextAnchor>;
|
|
236
250
|
|
|
237
|
-
|
|
238
|
-
{
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
resolveTextAnchorResources(
|
|
245
|
-
value: string,
|
|
246
|
-
kinds: readonly string[],
|
|
247
|
-
context: TextAnchorResourceResolverContext,
|
|
248
|
-
): Promise<readonly string[] | undefined>;
|
|
249
|
-
editText<Result>(
|
|
250
|
-
source: string,
|
|
251
|
-
context: ResourceResolverContext,
|
|
252
|
-
operation: (
|
|
253
|
-
text: string,
|
|
254
|
-
resolveAnchor: ResolveTextAnchor,
|
|
255
|
-
) => TextMutationResult<Result> | Promise<TextMutationResult<Result>>,
|
|
256
|
-
): Promise<TextResourceEditOutcome<Result>>;
|
|
257
|
-
editTexts<Result>(
|
|
258
|
-
sources: readonly TextResourceEditRequest[],
|
|
259
|
-
context: TextResourcesEditContext,
|
|
260
|
-
operation: (
|
|
261
|
-
texts: ReadonlyMap<string, string>,
|
|
262
|
-
resolveAnchor: ResolveResourceTextAnchor,
|
|
263
|
-
) => TextResourcesMutationResult<Result> | Promise<TextResourcesMutationResult<Result>>,
|
|
264
|
-
): Promise<TextResourcesEditOutcome<Result>>;
|
|
265
|
-
previewTexts(
|
|
266
|
-
sources: readonly TextResourceEditRequest[],
|
|
267
|
-
context: ResourceResolverContext,
|
|
268
|
-
operation: (
|
|
269
|
-
texts: ReadonlyMap<string, string>,
|
|
270
|
-
resolveAnchor: ResolveResourceTextAnchor,
|
|
271
|
-
) => TextResourcesMutationResult<unknown> | Promise<TextResourcesMutationResult<unknown>>,
|
|
272
|
-
): Promise<TextMutationPreviewOutcome>;
|
|
273
|
-
executeEdit<Input, Result>(
|
|
274
|
-
tool: TextEditorToolId,
|
|
275
|
-
initialState: TextPreEditState<Input>,
|
|
276
|
-
operation: (state: TextPreEditState<Input>) => Result | Promise<Result>,
|
|
277
|
-
): Promise<TextEditExecutionOutcome<Input, Result>>;
|
|
278
|
-
addMutationTool(registration: AnyTextMutationToolRegistration): void;
|
|
279
|
-
getMutationTools(): readonly AnyTextMutationToolRegistration[];
|
|
280
|
-
onMutationTool(listener: TextMutationToolListener): () => void;
|
|
281
|
-
onDidEdit(listener: TextEditCompletionListener): () => void;
|
|
282
|
-
getToolRenderer(tool: TextEditorToolId): TextEditorToolRendererRegistration | undefined;
|
|
283
|
-
registerPlugin(plugin: TextEditorPlugin): Promise<void>;
|
|
284
|
-
registerPostEditHandler(registration: TextPostEditHandlerRegistration): () => void;
|
|
285
|
-
registerTool(tool: TextEditorToolId): void;
|
|
286
|
-
waitForPendingPlugins(): Promise<void>;
|
|
287
|
-
renderGeneralPromptGuideline(): string | undefined;
|
|
288
|
-
renderToolPromptGuideline(tool: TextEditorToolId): string | undefined;
|
|
251
|
+
/** Input for resolving an anchor value against already-available text content. */
|
|
252
|
+
export interface TextAnchorInTextRequest {
|
|
253
|
+
readonly source: string;
|
|
254
|
+
readonly content: string;
|
|
255
|
+
readonly value: string;
|
|
256
|
+
readonly cwd: string;
|
|
257
|
+
readonly signal?: AbortSignal;
|
|
289
258
|
}
|
|
290
259
|
|
|
291
|
-
export
|
|
292
|
-
|
|
293
|
-
): TextEditorCore
|
|
294
|
-
{
|
|
295
|
-
const resolvers: RegisteredResolver[] = [];
|
|
296
|
-
const anchorRegistry = new TextAnchorRegistry();
|
|
297
|
-
const handlers: RegisteredHandler[] = [];
|
|
298
|
-
const presenters: RegisteredPresenter[] = [];
|
|
299
|
-
const postEditHandlers = new Map<string, TextPostEditHandlerRegistration>();
|
|
300
|
-
const pendingPlugins = new Set<Promise<void>>();
|
|
301
|
-
const plugins = new Map<string, RegisteredPlugin>();
|
|
302
|
-
const promptContributions: PromptContribution[] = [];
|
|
303
|
-
const writablePromptContributions: WritablePromptContribution[] = [];
|
|
304
|
-
const registeredTools = new Set<TextEditorToolId>();
|
|
305
|
-
const mutationTools = new Map<string, AnyTextMutationToolRegistration>();
|
|
306
|
-
const mutationListeners = new Set<TextMutationToolListener>();
|
|
307
|
-
const editCompletionListeners = new Set<TextEditCompletionListener>();
|
|
308
|
-
const mutationGuards: TextMutationGuardRegistration[] = [];
|
|
309
|
-
const toolRenderers = new Map<TextEditorToolId, TextEditorToolRendererRegistration>();
|
|
310
|
-
let registrationQueue = Promise.resolve();
|
|
311
|
-
const registerContributions = (draft: PluginContributionDraft): void =>
|
|
312
|
-
{
|
|
313
|
-
validateContributionDraft(
|
|
314
|
-
draft,
|
|
315
|
-
resolvers,
|
|
316
|
-
handlers,
|
|
317
|
-
promptContributions,
|
|
318
|
-
writablePromptContributions,
|
|
319
|
-
);
|
|
260
|
+
export interface TextResourcesEditContext
|
|
261
|
+
extends ResourceResolverContext, TextMutationGuardContext {}
|
|
320
262
|
|
|
321
|
-
|
|
263
|
+
export interface TextEditorCore {
|
|
264
|
+
inspectTextAnchors(request: TextAnchorInspectionRequest): Promise<TextAnchorInspectionOutcome>;
|
|
265
|
+
addAnchorResolver(registration: TextAnchorResolverRegistration): void;
|
|
266
|
+
resolveTextAnchorResources(
|
|
267
|
+
value: string,
|
|
268
|
+
kinds: readonly string[],
|
|
269
|
+
context: TextAnchorResourceResolverContext,
|
|
270
|
+
): Promise<readonly TextTarget[] | undefined>;
|
|
271
|
+
textTargetResolver(): TextTargetResolver;
|
|
272
|
+
/** Resolves one anchor value against provided text content without reading resources. */
|
|
273
|
+
resolveAnchorInText(request: TextAnchorInTextRequest): Promise<TextAnchor>;
|
|
274
|
+
editText<Result>(
|
|
275
|
+
source: string,
|
|
276
|
+
context: ResourceResolverContext,
|
|
277
|
+
operation: (
|
|
278
|
+
text: string,
|
|
279
|
+
resolveAnchor: ResolveTextAnchor,
|
|
280
|
+
) => TextMutationResult<Result> | Promise<TextMutationResult<Result>>,
|
|
281
|
+
): Promise<TextResourceEditOutcome<Result>>;
|
|
282
|
+
editTexts<Result>(
|
|
283
|
+
sources: readonly TextResourceEditRequest[],
|
|
284
|
+
context: TextResourcesEditContext,
|
|
285
|
+
operation: (
|
|
286
|
+
texts: ReadonlyMap<string, string>,
|
|
287
|
+
resolveAnchor: ResolveResourceTextAnchor,
|
|
288
|
+
) => TextResourcesMutationResult<Result> | Promise<TextResourcesMutationResult<Result>>,
|
|
289
|
+
): Promise<TextResourcesEditOutcome<Result>>;
|
|
290
|
+
previewTexts(
|
|
291
|
+
sources: readonly TextResourceEditRequest[],
|
|
292
|
+
context: ResourceResolverContext,
|
|
293
|
+
operation: (
|
|
294
|
+
texts: ReadonlyMap<string, string>,
|
|
295
|
+
resolveAnchor: ResolveResourceTextAnchor,
|
|
296
|
+
) => TextResourcesMutationResult<unknown> | Promise<TextResourcesMutationResult<unknown>>,
|
|
297
|
+
): Promise<TextMutationPreviewOutcome>;
|
|
298
|
+
executeEdit<Input, Result>(
|
|
299
|
+
tool: TextEditorToolId,
|
|
300
|
+
initialState: TextPreEditState<Input>,
|
|
301
|
+
operation: (state: TextPreEditState<Input>) => Result | Promise<Result>,
|
|
302
|
+
): Promise<TextEditExecutionOutcome<Input, Result>>;
|
|
303
|
+
addMutationTool(registration: AnyTextMutationToolRegistration): void;
|
|
304
|
+
getMutationTools(): readonly AnyTextMutationToolRegistration[];
|
|
305
|
+
onMutationTool(listener: TextMutationToolListener): () => void;
|
|
306
|
+
onDidEdit(listener: TextEditCompletionListener): () => void;
|
|
307
|
+
getToolRenderer(tool: TextEditorToolId): TextEditorToolRendererRegistration | undefined;
|
|
308
|
+
registerPlugin(plugin: TextEditorPlugin): Promise<void>;
|
|
309
|
+
registerPostEditHandler(registration: TextPostEditHandlerRegistration): () => void;
|
|
310
|
+
registerTool(tool: TextEditorToolId): void;
|
|
311
|
+
waitForPendingPlugins(): Promise<void>;
|
|
312
|
+
renderGeneralPromptGuideline(): string | undefined;
|
|
313
|
+
/** Returns the configured number of lines around recovery candidates. */
|
|
314
|
+
recoveryContextLines(): number;
|
|
315
|
+
renderToolPromptGuideline(tool: TextEditorToolId): string | undefined;
|
|
316
|
+
}
|
|
322
317
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
318
|
+
export function createTextEditorCore(
|
|
319
|
+
registerMutationTool?: (
|
|
320
|
+
registration: AnyTextMutationToolRegistration,
|
|
321
|
+
core: TextEditorCore,
|
|
322
|
+
) => void,
|
|
323
|
+
): TextEditorCore {
|
|
324
|
+
const projectConfig = loadTextEditorConfig(process.cwd());
|
|
325
|
+
const resolvers: RegisteredResolver[] = [];
|
|
326
|
+
const anchorRegistry = new TextAnchorRegistry();
|
|
327
|
+
const handlers: RegisteredHandler[] = [];
|
|
328
|
+
const presenters: RegisteredPresenter[] = [];
|
|
329
|
+
const postEditHandlers = new Map<string, TextPostEditHandlerRegistration>();
|
|
330
|
+
const pendingPlugins = new Set<Promise<void>>();
|
|
331
|
+
const plugins = new Map<string, RegisteredPlugin>();
|
|
332
|
+
const promptContributions: PromptContribution[] = [];
|
|
333
|
+
const writablePromptContributions: WritablePromptContribution[] = [];
|
|
334
|
+
const registeredTools = new Set<TextEditorToolId>();
|
|
335
|
+
const mutationTools = new Map<string, AnyTextMutationToolRegistration>();
|
|
336
|
+
const mutationListeners = new Set<TextMutationToolListener>();
|
|
337
|
+
const editCompletionListeners = new Set<TextEditCompletionListener>();
|
|
338
|
+
const mutationGuards: TextMutationGuardRegistration[] = [];
|
|
339
|
+
const toolRenderers = new Map<TextEditorToolId, TextEditorToolRendererRegistration>();
|
|
340
|
+
let registrationQueue = Promise.resolve();
|
|
341
|
+
const registerContributions = (draft: PluginContributionDraft): void => {
|
|
342
|
+
validateContributionDraft(
|
|
343
|
+
draft,
|
|
344
|
+
resolvers,
|
|
345
|
+
handlers,
|
|
346
|
+
promptContributions,
|
|
347
|
+
writablePromptContributions,
|
|
348
|
+
);
|
|
326
349
|
|
|
327
|
-
|
|
328
|
-
{
|
|
329
|
-
throw new Error(`Mutation tool ${registration.name} is already registered`);
|
|
330
|
-
}
|
|
350
|
+
const incomingMutationNames = new Set<string>();
|
|
331
351
|
|
|
332
|
-
|
|
333
|
-
|
|
352
|
+
for (const registration of draft.mutationTools ?? []) {
|
|
353
|
+
assertTextMutationToolRegistration(registration);
|
|
334
354
|
|
|
335
|
-
|
|
336
|
-
{
|
|
337
|
-
|
|
338
|
-
{
|
|
339
|
-
throw new TypeError("Plugin provided an invalid text editor tool renderer");
|
|
340
|
-
}
|
|
341
|
-
}
|
|
355
|
+
if (mutationTools.has(registration.name) || incomingMutationNames.has(registration.name)) {
|
|
356
|
+
throw new Error(`Mutation tool ${registration.name} is already registered`);
|
|
357
|
+
}
|
|
342
358
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const presenterIds = new Set(presenters.map(({ registration }) => registration.presenter.id));
|
|
359
|
+
incomingMutationNames.add(registration.name);
|
|
360
|
+
}
|
|
346
361
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
362
|
+
for (const registration of draft.toolRenderers ?? []) {
|
|
363
|
+
if (!isTextEditorToolRendererRegistration(registration)) {
|
|
364
|
+
throw new TypeError("Plugin provided an invalid text editor tool renderer");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
353
367
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
368
|
+
anchorRegistry.assertCanAdd(draft.anchorResolvers.map(({ registration }) => registration));
|
|
369
|
+
const incomingPresenters = draft.presenters ?? [];
|
|
370
|
+
const presenterIds = new Set(presenters.map(({ registration }) => registration.presenter.id));
|
|
358
371
|
|
|
359
|
-
|
|
360
|
-
|
|
372
|
+
for (const contribution of incomingPresenters) {
|
|
373
|
+
if (!isTextPresenterRegistration(contribution.registration)) {
|
|
374
|
+
throw new TypeError(`Plugin ${contribution.pluginId} provided an invalid text presenter`);
|
|
375
|
+
}
|
|
361
376
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
order: resolvers.length,
|
|
368
|
-
});
|
|
369
|
-
}
|
|
377
|
+
if (presenterIds.has(contribution.registration.presenter.id)) {
|
|
378
|
+
throw new Error(
|
|
379
|
+
`Text presenter ${contribution.registration.presenter.id} is already registered`,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
370
382
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
anchorRegistry.add(contribution.registration);
|
|
374
|
-
}
|
|
383
|
+
presenterIds.add(contribution.registration.presenter.id);
|
|
384
|
+
}
|
|
375
385
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
386
|
+
for (const contribution of draft.resolvers) {
|
|
387
|
+
resolvers.push({
|
|
388
|
+
resolver: contribution.registration.resolver,
|
|
389
|
+
priority: contribution.registration.priority ?? 0,
|
|
390
|
+
order: resolvers.length,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
380
393
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
writablePromptContributions.push(...draft.writablePromptContributions);
|
|
394
|
+
for (const contribution of draft.anchorResolvers) {
|
|
395
|
+
anchorRegistry.add(contribution.registration);
|
|
396
|
+
}
|
|
385
397
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
toolRenderers.set(registration.tool, mergeToolRenderer(current, registration));
|
|
390
|
-
}
|
|
398
|
+
for (const contribution of incomingPresenters) {
|
|
399
|
+
presenters.push({ ...contribution, order: presenters.length });
|
|
400
|
+
}
|
|
391
401
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
402
|
+
handlers.push(...draft.handlers);
|
|
403
|
+
mutationGuards.push(...(draft.mutationGuards ?? []));
|
|
404
|
+
promptContributions.push(...draft.promptContributions);
|
|
405
|
+
writablePromptContributions.push(...draft.writablePromptContributions);
|
|
396
406
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
mutationTools,
|
|
402
|
-
registeredTools,
|
|
403
|
-
mutationListeners,
|
|
404
|
-
registerMutationTool,
|
|
405
|
-
core,
|
|
406
|
-
);
|
|
407
|
-
}
|
|
407
|
+
for (const registration of draft.toolRenderers ?? []) {
|
|
408
|
+
const current = toolRenderers.get(registration.tool);
|
|
409
|
+
toolRenderers.set(registration.tool, mergeToolRenderer(current, registration));
|
|
410
|
+
}
|
|
408
411
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
mutationListeners.add(listener);
|
|
413
|
-
}
|
|
412
|
+
for (const tool of draft.tools) {
|
|
413
|
+
registeredTools.add(tool);
|
|
414
|
+
}
|
|
414
415
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
416
|
+
for (const registration of draft.mutationTools ?? []) {
|
|
417
|
+
addMutationRegistration(
|
|
418
|
+
registration,
|
|
419
|
+
mutationTools,
|
|
420
|
+
registeredTools,
|
|
421
|
+
mutationListeners,
|
|
422
|
+
registerMutationTool,
|
|
423
|
+
core,
|
|
424
|
+
);
|
|
425
|
+
}
|
|
420
426
|
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
{
|
|
426
|
-
throw new TypeError("Invalid text anchor resolver");
|
|
427
|
-
}
|
|
427
|
+
for (const listener of draft.mutationToolListeners ?? []) {
|
|
428
|
+
replayMutationTools(listener, mutationTools);
|
|
429
|
+
mutationListeners.add(listener);
|
|
430
|
+
}
|
|
428
431
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
left.priority - right.priority || left.order - right.order
|
|
480
|
-
);
|
|
481
|
-
const presenterSnapshot = [...presenters].sort((left, right) =>
|
|
482
|
-
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) || left.order - right.order
|
|
483
|
-
);
|
|
484
|
-
return editTextResource(
|
|
485
|
-
source,
|
|
486
|
-
context,
|
|
487
|
-
resolverSnapshot,
|
|
488
|
-
anchorRegistry.snapshot(),
|
|
489
|
-
presenterSnapshot,
|
|
490
|
-
[...postEditHandlers.values()],
|
|
491
|
-
[...editCompletionListeners],
|
|
492
|
-
operation,
|
|
493
|
-
);
|
|
494
|
-
},
|
|
495
|
-
editTexts<Result>(
|
|
496
|
-
sources: readonly TextResourceEditRequest[],
|
|
497
|
-
context: TextResourcesEditContext,
|
|
498
|
-
operation: (
|
|
499
|
-
texts: ReadonlyMap<string, string>,
|
|
500
|
-
resolveAnchor: ResolveResourceTextAnchor,
|
|
501
|
-
) => TextResourcesMutationResult<Result> | Promise<TextResourcesMutationResult<Result>>,
|
|
502
|
-
): Promise<TextResourcesEditOutcome<Result>>
|
|
503
|
-
{
|
|
504
|
-
const resolverSnapshot = [...resolvers].sort((left, right) =>
|
|
505
|
-
left.priority - right.priority || left.order - right.order
|
|
506
|
-
);
|
|
507
|
-
const presenterSnapshot = [...presenters].sort((left, right) =>
|
|
508
|
-
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) || left.order - right.order
|
|
509
|
-
);
|
|
510
|
-
return editTextResources(
|
|
511
|
-
sources,
|
|
512
|
-
context,
|
|
513
|
-
resolverSnapshot,
|
|
514
|
-
anchorRegistry.snapshot(),
|
|
515
|
-
presenterSnapshot,
|
|
516
|
-
[...postEditHandlers.values()],
|
|
517
|
-
[...editCompletionListeners],
|
|
518
|
-
[...mutationGuards],
|
|
519
|
-
operation,
|
|
520
|
-
);
|
|
521
|
-
},
|
|
522
|
-
previewTexts(sources, context, operation): Promise<TextMutationPreviewOutcome>
|
|
523
|
-
{
|
|
524
|
-
const resolverSnapshot = [...resolvers].sort((left, right) =>
|
|
525
|
-
left.priority - right.priority || left.order - right.order
|
|
526
|
-
);
|
|
527
|
-
return previewTextResources(sources, context, resolverSnapshot, anchorRegistry.snapshot(), operation);
|
|
432
|
+
for (const listener of draft.editCompletionListeners ?? []) {
|
|
433
|
+
editCompletionListeners.add(listener);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
const core: TextEditorCore = {
|
|
438
|
+
addAnchorResolver(registration): void {
|
|
439
|
+
if (!isTextAnchorResolverRegistration(registration)) {
|
|
440
|
+
throw new TypeError("Invalid text anchor resolver");
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
anchorRegistry.add(registration);
|
|
444
|
+
},
|
|
445
|
+
addMutationTool(registration): void {
|
|
446
|
+
addMutationRegistration(
|
|
447
|
+
registration,
|
|
448
|
+
mutationTools,
|
|
449
|
+
registeredTools,
|
|
450
|
+
mutationListeners,
|
|
451
|
+
registerMutationTool,
|
|
452
|
+
core,
|
|
453
|
+
);
|
|
454
|
+
},
|
|
455
|
+
getMutationTools(): readonly AnyTextMutationToolRegistration[] {
|
|
456
|
+
return [...mutationTools.values()];
|
|
457
|
+
},
|
|
458
|
+
onMutationTool(listener): () => void {
|
|
459
|
+
replayMutationTools(listener, mutationTools);
|
|
460
|
+
mutationListeners.add(listener);
|
|
461
|
+
return () => mutationListeners.delete(listener);
|
|
462
|
+
},
|
|
463
|
+
onDidEdit(listener): () => void {
|
|
464
|
+
editCompletionListeners.add(listener);
|
|
465
|
+
return () => editCompletionListeners.delete(listener);
|
|
466
|
+
},
|
|
467
|
+
getToolRenderer(tool): TextEditorToolRendererRegistration | undefined {
|
|
468
|
+
return toolRenderers.get(tool);
|
|
469
|
+
},
|
|
470
|
+
inspectTextAnchors(request): Promise<TextAnchorInspectionOutcome> {
|
|
471
|
+
return inspectTextResource(request, [...resolvers], anchorRegistry.snapshot());
|
|
472
|
+
},
|
|
473
|
+
resolveTextAnchorResources(value, kinds, context): Promise<readonly TextTarget[] | undefined> {
|
|
474
|
+
return anchorRegistry.snapshot().resolveResources(value, context, new Set(kinds));
|
|
475
|
+
},
|
|
476
|
+
textTargetResolver(): TextTargetResolver {
|
|
477
|
+
return {
|
|
478
|
+
id: "text-editor-anchors",
|
|
479
|
+
tryResolve: async (value, context) => {
|
|
480
|
+
const targets = await anchorRegistry.snapshot().resolveResources(value, context);
|
|
481
|
+
return targets === undefined ? { kind: "not-handled" } : { kind: "resolved", targets };
|
|
528
482
|
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const invocationHandlers = handlers.filter((registered) => registered.tool === tool);
|
|
541
|
-
const preEdit = await runPreEditHandlers(initialState, invocationHandlers, tool);
|
|
542
|
-
|
|
543
|
-
if (preEdit.kind === "failed")
|
|
544
|
-
{
|
|
545
|
-
return preEdit;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
const result = await operation(preEdit.state);
|
|
549
|
-
const editState: TextEditState<Input, Result> = {
|
|
550
|
-
...preEdit.state,
|
|
551
|
-
result,
|
|
552
|
-
};
|
|
553
|
-
const edit = await runResultHandlers("text-edit", editState, invocationHandlers, tool);
|
|
554
|
-
|
|
555
|
-
if (edit.kind === "failed")
|
|
556
|
-
{
|
|
557
|
-
return edit;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const postEdit = await runResultHandlers("text-post-edit", edit.state, invocationHandlers, tool);
|
|
561
|
-
|
|
562
|
-
if (postEdit.kind === "failed")
|
|
563
|
-
{
|
|
564
|
-
return postEdit;
|
|
565
|
-
}
|
|
483
|
+
};
|
|
484
|
+
},
|
|
485
|
+
resolveAnchorInText(request: TextAnchorInTextRequest): Promise<TextAnchor> {
|
|
486
|
+
const context: TextAnchorResolverContext = {
|
|
487
|
+
source: request.source,
|
|
488
|
+
content: request.content,
|
|
489
|
+
lines: request.content.length === 0 ? [] : request.content.split(/\r?\n/u),
|
|
490
|
+
cwd: request.cwd,
|
|
491
|
+
...(request.signal !== undefined && { signal: request.signal }),
|
|
492
|
+
};
|
|
566
493
|
|
|
567
|
-
|
|
494
|
+
return anchorRegistry.snapshot().resolve(request.value, context);
|
|
495
|
+
},
|
|
496
|
+
editText<Result>(
|
|
497
|
+
source: string,
|
|
498
|
+
context: ResourceResolverContext,
|
|
499
|
+
operation: (
|
|
500
|
+
text: string,
|
|
501
|
+
resolveAnchor: ResolveTextAnchor,
|
|
502
|
+
) => TextMutationResult<Result> | Promise<TextMutationResult<Result>>,
|
|
503
|
+
): Promise<TextResourceEditOutcome<Result>> {
|
|
504
|
+
const resolverSnapshot = [...resolvers].sort(
|
|
505
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
506
|
+
);
|
|
507
|
+
const presenterSnapshot = [...presenters].sort(
|
|
508
|
+
(left, right) =>
|
|
509
|
+
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) ||
|
|
510
|
+
left.order - right.order,
|
|
511
|
+
);
|
|
512
|
+
return editTextResource(
|
|
513
|
+
source,
|
|
514
|
+
context,
|
|
515
|
+
resolverSnapshot,
|
|
516
|
+
anchorRegistry.snapshot(),
|
|
517
|
+
presenterSnapshot,
|
|
518
|
+
[...postEditHandlers.values()],
|
|
519
|
+
[...editCompletionListeners],
|
|
520
|
+
operation,
|
|
521
|
+
);
|
|
522
|
+
},
|
|
523
|
+
editTexts<Result>(
|
|
524
|
+
sources: readonly TextResourceEditRequest[],
|
|
525
|
+
context: TextResourcesEditContext,
|
|
526
|
+
operation: (
|
|
527
|
+
texts: ReadonlyMap<string, string>,
|
|
528
|
+
resolveAnchor: ResolveResourceTextAnchor,
|
|
529
|
+
) => TextResourcesMutationResult<Result> | Promise<TextResourcesMutationResult<Result>>,
|
|
530
|
+
): Promise<TextResourcesEditOutcome<Result>> {
|
|
531
|
+
const resolverSnapshot = [...resolvers].sort(
|
|
532
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
533
|
+
);
|
|
534
|
+
const presenterSnapshot = [...presenters].sort(
|
|
535
|
+
(left, right) =>
|
|
536
|
+
(left.registration.priority ?? 0) - (right.registration.priority ?? 0) ||
|
|
537
|
+
left.order - right.order,
|
|
538
|
+
);
|
|
539
|
+
return editTextResources(
|
|
540
|
+
sources,
|
|
541
|
+
context,
|
|
542
|
+
resolverSnapshot,
|
|
543
|
+
anchorRegistry.snapshot(),
|
|
544
|
+
presenterSnapshot,
|
|
545
|
+
[...postEditHandlers.values()],
|
|
546
|
+
[...editCompletionListeners],
|
|
547
|
+
[...mutationGuards],
|
|
548
|
+
operation,
|
|
549
|
+
);
|
|
550
|
+
},
|
|
551
|
+
previewTexts(sources, context, operation): Promise<TextMutationPreviewOutcome> {
|
|
552
|
+
const resolverSnapshot = [...resolvers].sort(
|
|
553
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
554
|
+
);
|
|
555
|
+
return previewTextResources(
|
|
556
|
+
sources,
|
|
557
|
+
context,
|
|
558
|
+
resolverSnapshot,
|
|
559
|
+
anchorRegistry.snapshot(),
|
|
560
|
+
operation,
|
|
561
|
+
);
|
|
562
|
+
},
|
|
563
|
+
async executeEdit<Input, Result>(
|
|
564
|
+
tool: TextEditorToolId,
|
|
565
|
+
initialState: TextPreEditState<Input>,
|
|
566
|
+
operation: (state: TextPreEditState<Input>) => Result | Promise<Result>,
|
|
567
|
+
): Promise<TextEditExecutionOutcome<Input, Result>> {
|
|
568
|
+
if (!isTextEditorToolId(tool)) {
|
|
569
|
+
throw new Error(`Unsupported text editor tool ${String(tool)}`);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const invocationHandlers = handlers.filter((registered) => registered.tool === tool);
|
|
573
|
+
const preEdit = await runPreEditHandlers(initialState, invocationHandlers, tool);
|
|
574
|
+
|
|
575
|
+
if (preEdit.kind === "failed") {
|
|
576
|
+
return preEdit;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const result = await operation(preEdit.state);
|
|
580
|
+
const editState: TextEditState<Input, Result> = {
|
|
581
|
+
...preEdit.state,
|
|
582
|
+
result,
|
|
583
|
+
};
|
|
584
|
+
const edit = await runResultHandlers("text-edit", editState, invocationHandlers, tool);
|
|
585
|
+
|
|
586
|
+
if (edit.kind === "failed") {
|
|
587
|
+
return edit;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const postEdit = await runResultHandlers(
|
|
591
|
+
"text-post-edit",
|
|
592
|
+
edit.state,
|
|
593
|
+
invocationHandlers,
|
|
594
|
+
tool,
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
if (postEdit.kind === "failed") {
|
|
598
|
+
return postEdit;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
return { kind: "completed", state: postEdit.state };
|
|
602
|
+
},
|
|
603
|
+
registerPostEditHandler(registration): () => void {
|
|
604
|
+
if (!isTextPostEditHandlerRegistration(registration)) {
|
|
605
|
+
throw new TypeError("Invalid text editor post-edit handler registration");
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (postEditHandlers.has(registration.id)) {
|
|
609
|
+
throw new Error(`Post-edit handler ${registration.id} is already registered`);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
postEditHandlers.set(registration.id, registration);
|
|
613
|
+
return () => {
|
|
614
|
+
if (postEditHandlers.get(registration.id) === registration) {
|
|
615
|
+
postEditHandlers.delete(registration.id);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
},
|
|
619
|
+
registerTool(tool): void {
|
|
620
|
+
if (!isTextEditorToolId(tool)) {
|
|
621
|
+
throw new TypeError("Invalid text editor tool ID");
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
registeredTools.add(tool);
|
|
625
|
+
},
|
|
626
|
+
registerPlugin(plugin): Promise<void> {
|
|
627
|
+
const validationError = getPluginValidationError(plugin);
|
|
628
|
+
|
|
629
|
+
if (validationError !== undefined) {
|
|
630
|
+
return Promise.reject(validationError);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const existing = plugins.get(plugin.id);
|
|
634
|
+
|
|
635
|
+
if (existing?.plugin === plugin) {
|
|
636
|
+
return existing.ready;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (existing !== undefined) {
|
|
640
|
+
return Promise.reject(new Error(`Plugin ${plugin.id} is already registered`));
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const lifecycle: PluginLifecycle = { status: "pending" };
|
|
644
|
+
const contributions = createPluginContributionController(
|
|
645
|
+
plugin.id,
|
|
646
|
+
registerContributions,
|
|
647
|
+
(request) => inspectTextResource(request, [...resolvers], anchorRegistry.snapshot()),
|
|
648
|
+
(listener) => core.onMutationTool(listener),
|
|
649
|
+
(listener) => core.onDidEdit(listener),
|
|
650
|
+
(request) => previewTextMutation(core, request),
|
|
651
|
+
(section) => recoverySection(projectConfig, section),
|
|
652
|
+
);
|
|
653
|
+
const ready = registrationQueue.then(async () => {
|
|
654
|
+
try {
|
|
655
|
+
await plugin.setup(contributions.api);
|
|
656
|
+
contributions.commit();
|
|
657
|
+
lifecycle.status = "active";
|
|
658
|
+
return;
|
|
659
|
+
} catch (error) {
|
|
660
|
+
contributions.close();
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
const registeredPlugin: RegisteredPlugin = { lifecycle, plugin, ready };
|
|
665
|
+
|
|
666
|
+
plugins.set(plugin.id, registeredPlugin);
|
|
667
|
+
pendingPlugins.add(ready);
|
|
668
|
+
registrationQueue = ready.catch(() => {});
|
|
669
|
+
void ready.then(
|
|
670
|
+
() => {
|
|
671
|
+
pendingPlugins.delete(ready);
|
|
672
|
+
return;
|
|
568
673
|
},
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (!isTextPostEditHandlerRegistration(registration))
|
|
572
|
-
{
|
|
573
|
-
throw new TypeError("Invalid text editor post-edit handler registration");
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
if (postEditHandlers.has(registration.id))
|
|
577
|
-
{
|
|
578
|
-
throw new Error(`Post-edit handler ${registration.id} is already registered`);
|
|
579
|
-
}
|
|
674
|
+
() => {
|
|
675
|
+
pendingPlugins.delete(ready);
|
|
580
676
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
if (postEditHandlers.get(registration.id) === registration)
|
|
585
|
-
{
|
|
586
|
-
postEditHandlers.delete(registration.id);
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
},
|
|
590
|
-
registerTool(tool): void
|
|
591
|
-
{
|
|
592
|
-
if (!isTextEditorToolId(tool))
|
|
593
|
-
{
|
|
594
|
-
throw new TypeError("Invalid text editor tool ID");
|
|
595
|
-
}
|
|
677
|
+
if (plugins.get(plugin.id) === registeredPlugin) {
|
|
678
|
+
plugins.delete(plugin.id);
|
|
679
|
+
}
|
|
596
680
|
|
|
597
|
-
|
|
681
|
+
return;
|
|
598
682
|
},
|
|
599
|
-
|
|
600
|
-
{
|
|
601
|
-
const validationError = getPluginValidationError(plugin);
|
|
683
|
+
);
|
|
602
684
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
685
|
+
return ready;
|
|
686
|
+
},
|
|
687
|
+
recoveryContextLines(): number {
|
|
688
|
+
return projectConfig.contextLines;
|
|
689
|
+
},
|
|
690
|
+
renderGeneralPromptGuideline(): string | undefined {
|
|
691
|
+
const sections: string[] = [];
|
|
692
|
+
const writableEntries: string[] = [];
|
|
609
693
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
694
|
+
for (const registeredPlugin of plugins.values()) {
|
|
695
|
+
if (registeredPlugin.lifecycle.status !== "active") {
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
614
698
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
const lifecycle: PluginLifecycle = { status: "pending" };
|
|
621
|
-
const contributions = createPluginContributionController(
|
|
622
|
-
plugin.id,
|
|
623
|
-
registerContributions,
|
|
624
|
-
(request) => inspectTextResource(request, [...resolvers], anchorRegistry.snapshot()),
|
|
625
|
-
(listener) => core.onMutationTool(listener),
|
|
626
|
-
(listener) => core.onDidEdit(listener),
|
|
627
|
-
(request) => previewTextMutation(core, request),
|
|
628
|
-
);
|
|
629
|
-
const ready = registrationQueue.then(async () =>
|
|
630
|
-
{
|
|
631
|
-
try
|
|
632
|
-
{
|
|
633
|
-
await plugin.setup(contributions.api);
|
|
634
|
-
contributions.commit();
|
|
635
|
-
lifecycle.status = "active";
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
catch (error)
|
|
639
|
-
{
|
|
640
|
-
contributions.close();
|
|
641
|
-
throw error;
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
const registeredPlugin: RegisteredPlugin = { lifecycle, plugin, ready };
|
|
645
|
-
|
|
646
|
-
plugins.set(plugin.id, registeredPlugin);
|
|
647
|
-
pendingPlugins.add(ready);
|
|
648
|
-
registrationQueue = ready.catch(() =>
|
|
649
|
-
{});
|
|
650
|
-
void ready.then(
|
|
651
|
-
() =>
|
|
652
|
-
{
|
|
653
|
-
pendingPlugins.delete(ready);
|
|
654
|
-
return;
|
|
655
|
-
},
|
|
656
|
-
() =>
|
|
657
|
-
{
|
|
658
|
-
pendingPlugins.delete(ready);
|
|
659
|
-
|
|
660
|
-
if (plugins.get(plugin.id) === registeredPlugin)
|
|
661
|
-
{
|
|
662
|
-
plugins.delete(plugin.id);
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
return;
|
|
666
|
-
},
|
|
667
|
-
);
|
|
668
|
-
|
|
669
|
-
return ready;
|
|
670
|
-
},
|
|
671
|
-
renderGeneralPromptGuideline(): string | undefined
|
|
672
|
-
{
|
|
673
|
-
const sections: string[] = [];
|
|
674
|
-
const writableEntries: string[] = [];
|
|
699
|
+
const contribution = writablePromptContributions.find(
|
|
700
|
+
(candidate) => candidate.pluginId === registeredPlugin.plugin.id,
|
|
701
|
+
);
|
|
675
702
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
{
|
|
680
|
-
continue;
|
|
681
|
-
}
|
|
703
|
+
if (contribution === undefined) {
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
682
706
|
|
|
683
|
-
|
|
684
|
-
candidate.pluginId === registeredPlugin.plugin.id
|
|
685
|
-
);
|
|
707
|
+
const description = renderDescriptionSource(contribution.description);
|
|
686
708
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
709
|
+
if (description !== undefined) {
|
|
710
|
+
writableEntries.push(renderPromptEntry(registeredPlugin.plugin.id, description));
|
|
711
|
+
}
|
|
712
|
+
}
|
|
691
713
|
|
|
692
|
-
|
|
714
|
+
if (writableEntries.length > 0) {
|
|
715
|
+
sections.push(
|
|
716
|
+
["Text edits support these writable resources:", ...writableEntries].join("\n"),
|
|
717
|
+
);
|
|
718
|
+
}
|
|
693
719
|
|
|
694
|
-
|
|
695
|
-
{
|
|
696
|
-
writableEntries.push(renderPromptEntry(registeredPlugin.plugin.id, description));
|
|
697
|
-
}
|
|
698
|
-
}
|
|
720
|
+
const anchorSection = anchorRegistry.renderPromptSection();
|
|
699
721
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
}
|
|
722
|
+
if (anchorSection !== undefined) {
|
|
723
|
+
sections.push(anchorSection);
|
|
724
|
+
}
|
|
704
725
|
|
|
705
|
-
|
|
726
|
+
return sections.length === 0 ? undefined : indentGuidelineContinuation(sections.join("\n\n"));
|
|
727
|
+
},
|
|
728
|
+
renderToolPromptGuideline(tool): string | undefined {
|
|
729
|
+
const entries: string[] = [];
|
|
706
730
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
731
|
+
for (const registeredPlugin of plugins.values()) {
|
|
732
|
+
if (registeredPlugin.lifecycle.status !== "active") {
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
711
735
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
const entries: string[] = [];
|
|
736
|
+
const contribution = promptContributions.find(
|
|
737
|
+
(candidate) =>
|
|
738
|
+
candidate.pluginId === registeredPlugin.plugin.id && candidate.tool === tool,
|
|
739
|
+
);
|
|
717
740
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
continue;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
const contribution = promptContributions.find((candidate) =>
|
|
726
|
-
candidate.pluginId === registeredPlugin.plugin.id && candidate.tool === tool
|
|
727
|
-
);
|
|
728
|
-
|
|
729
|
-
if (contribution !== undefined)
|
|
730
|
-
{
|
|
731
|
-
entries.push(renderPromptEntry(registeredPlugin.plugin.id, contribution.description));
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
return entries.length === 0
|
|
736
|
-
? undefined
|
|
737
|
-
: indentGuidelineContinuation([`${tool} supports these installed extensions:`, ...entries].join("\n"));
|
|
738
|
-
},
|
|
739
|
-
async waitForPendingPlugins(): Promise<void>
|
|
740
|
-
{
|
|
741
|
-
await Promise.all(pendingPlugins);
|
|
742
|
-
},
|
|
743
|
-
};
|
|
741
|
+
if (contribution !== undefined) {
|
|
742
|
+
entries.push(renderPromptEntry(registeredPlugin.plugin.id, contribution.description));
|
|
743
|
+
}
|
|
744
|
+
}
|
|
744
745
|
|
|
745
|
-
|
|
746
|
+
return entries.length === 0
|
|
747
|
+
? undefined
|
|
748
|
+
: indentGuidelineContinuation(
|
|
749
|
+
[`${tool} supports these installed extensions:`, ...entries].join("\n"),
|
|
750
|
+
);
|
|
751
|
+
},
|
|
752
|
+
async waitForPendingPlugins(): Promise<void> {
|
|
753
|
+
await Promise.all(pendingPlugins);
|
|
754
|
+
},
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
return core;
|
|
746
758
|
}
|
|
747
759
|
|
|
748
760
|
async function inspectTextResource(
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
): Promise<TextAnchorInspectionOutcome>
|
|
753
|
-
{
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
{
|
|
769
|
-
attempt = await resolver.tryResolve(request.source, context);
|
|
770
|
-
}
|
|
771
|
-
catch (error)
|
|
772
|
-
{
|
|
773
|
-
return { kind: "failed", reason: `Resolver ${resolver.id} failed`, cause: error };
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
if (!isResourceResolutionAttempt(attempt))
|
|
777
|
-
{
|
|
778
|
-
return { kind: "failed", reason: `Resolver ${resolver.id} returned an invalid result`, cause: attempt };
|
|
779
|
-
}
|
|
761
|
+
request: TextAnchorInspectionRequest,
|
|
762
|
+
resolvers: readonly RegisteredResolver[],
|
|
763
|
+
anchors: TextAnchorRegistrySnapshot,
|
|
764
|
+
): Promise<TextAnchorInspectionOutcome> {
|
|
765
|
+
const context: ResourceResolverContext = {
|
|
766
|
+
cwd: request.cwd,
|
|
767
|
+
...(request.signal !== undefined && { signal: request.signal }),
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
for (const { resolver } of [...resolvers].sort(
|
|
771
|
+
(left, right) => left.priority - right.priority || left.order - right.order,
|
|
772
|
+
)) {
|
|
773
|
+
let attempt: unknown;
|
|
774
|
+
|
|
775
|
+
try {
|
|
776
|
+
attempt = await resolver.tryResolve(request.source, context);
|
|
777
|
+
} catch (error) {
|
|
778
|
+
return { kind: "failed", reason: `Resolver ${resolver.id} failed`, cause: error };
|
|
779
|
+
}
|
|
780
780
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}
|
|
781
|
+
if (!isResourceResolutionAttempt(attempt)) {
|
|
782
|
+
return {
|
|
783
|
+
kind: "failed",
|
|
784
|
+
reason: `Resolver ${resolver.id} returned an invalid result`,
|
|
785
|
+
cause: attempt,
|
|
786
|
+
};
|
|
787
|
+
}
|
|
785
788
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
789
|
+
if (attempt.kind === "not-handled") {
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
790
792
|
|
|
791
|
-
|
|
793
|
+
if (attempt.kind === "failed") {
|
|
794
|
+
return { kind: "failed", reason: `Resolver ${resolver.id} failed`, cause: attempt.error };
|
|
795
|
+
}
|
|
792
796
|
|
|
793
|
-
|
|
794
|
-
{
|
|
795
|
-
return { kind: "failed", reason: `Resource ${resource.source} is not readable text` };
|
|
796
|
-
}
|
|
797
|
+
const { resource } = attempt;
|
|
797
798
|
|
|
798
|
-
|
|
799
|
+
if (resource.read === undefined) {
|
|
800
|
+
return { kind: "failed", reason: `Resource ${resource.source} is not readable text` };
|
|
801
|
+
}
|
|
799
802
|
|
|
800
|
-
|
|
801
|
-
{
|
|
802
|
-
content = await resource.read(request.signal === undefined ? {} : { signal: request.signal });
|
|
803
|
-
}
|
|
804
|
-
catch (error)
|
|
805
|
-
{
|
|
806
|
-
return { kind: "failed", reason: `Unable to read ${resource.source}`, cause: error };
|
|
807
|
-
}
|
|
803
|
+
let content: unknown;
|
|
808
804
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
805
|
+
try {
|
|
806
|
+
content = await resource.read(request.signal === undefined ? {} : { signal: request.signal });
|
|
807
|
+
} catch (error) {
|
|
808
|
+
return { kind: "failed", reason: `Unable to read ${resource.source}`, cause: error };
|
|
809
|
+
}
|
|
813
810
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
});
|
|
811
|
+
if (!isAgentContent(content) || content.length !== 1 || content[0].type !== "text") {
|
|
812
|
+
return {
|
|
813
|
+
kind: "failed",
|
|
814
|
+
reason: `Resource ${resource.source} is not readable text`,
|
|
815
|
+
cause: content,
|
|
816
|
+
};
|
|
821
817
|
}
|
|
822
818
|
|
|
823
|
-
return
|
|
819
|
+
return anchors.inspect(request.anchors, request.kinds, {
|
|
820
|
+
source: resource.source,
|
|
821
|
+
content: content[0].text,
|
|
822
|
+
lines: content[0].text.length === 0 ? [] : content[0].text.split(/\r?\n/u),
|
|
823
|
+
cwd: request.cwd,
|
|
824
|
+
...(request.signal !== undefined && { signal: request.signal }),
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return { kind: "failed", reason: `No resolver handled ${request.source}` };
|
|
824
829
|
}
|
|
825
830
|
|
|
826
831
|
async function previewTextResources(
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
): Promise<TextMutationPreviewOutcome>
|
|
836
|
-
{
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
const requestBySource = new Map(requests.map((request) => [request.source, request]));
|
|
840
|
-
const sources = [...requestBySource.keys()];
|
|
841
|
-
|
|
842
|
-
if (sources.length === 0 || sources.some((source) => source.length === 0))
|
|
843
|
-
{
|
|
844
|
-
return { kind: "failed", reason: "No source was provided" };
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
const prepared = new Map<string, PreparedTextResource>();
|
|
848
|
-
|
|
849
|
-
for (const source of sources)
|
|
850
|
-
{
|
|
851
|
-
const request = requestBySource.get(source)!;
|
|
852
|
-
const outcome = await prepareTextResource(
|
|
853
|
-
source,
|
|
854
|
-
request.read,
|
|
855
|
-
request.allowReadFailure ?? false,
|
|
856
|
-
context,
|
|
857
|
-
resolvers,
|
|
858
|
-
);
|
|
859
|
-
|
|
860
|
-
if ("failure" in outcome)
|
|
861
|
-
{
|
|
862
|
-
return { kind: "failed", reason: outcome.failure.message };
|
|
863
|
-
}
|
|
832
|
+
requests: readonly TextResourceEditRequest[],
|
|
833
|
+
context: ResourceResolverContext,
|
|
834
|
+
resolvers: readonly RegisteredResolver[],
|
|
835
|
+
anchorResolvers: TextAnchorRegistrySnapshot,
|
|
836
|
+
operation: (
|
|
837
|
+
texts: ReadonlyMap<string, string>,
|
|
838
|
+
resolveAnchor: ResolveResourceTextAnchor,
|
|
839
|
+
) => TextResourcesMutationResult<unknown> | Promise<TextResourcesMutationResult<unknown>>,
|
|
840
|
+
): Promise<TextMutationPreviewOutcome> {
|
|
841
|
+
try {
|
|
842
|
+
const requestBySource = new Map(requests.map((request) => [request.source, request]));
|
|
843
|
+
const sources = [...requestBySource.keys()];
|
|
864
844
|
|
|
865
|
-
|
|
866
|
-
|
|
845
|
+
if (sources.length === 0 || sources.some((source) => source.length === 0)) {
|
|
846
|
+
return { kind: "failed", reason: "No source was provided" };
|
|
847
|
+
}
|
|
867
848
|
|
|
868
|
-
|
|
869
|
-
const mutation = await operation(texts, (source, value, kinds) =>
|
|
870
|
-
{
|
|
871
|
-
const item = prepared.get(source);
|
|
849
|
+
const prepared = new Map<string, PreparedTextResource>();
|
|
872
850
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
851
|
+
for (const source of sources) {
|
|
852
|
+
const request = requiredValue(requestBySource.get(source));
|
|
853
|
+
const outcome = await prepareTextResource(
|
|
854
|
+
source,
|
|
855
|
+
request.read,
|
|
856
|
+
request.allowReadFailure ?? false,
|
|
857
|
+
context,
|
|
858
|
+
resolvers,
|
|
859
|
+
);
|
|
860
|
+
|
|
861
|
+
if ("failure" in outcome) {
|
|
862
|
+
return { kind: "failed", reason: outcome.failure.message };
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
prepared.set(source, outcome);
|
|
866
|
+
}
|
|
877
867
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
868
|
+
const texts = new Map([...prepared].map(([source, item]) => [source, item.before.content]));
|
|
869
|
+
const mutation = await operation(texts, (source, value, kinds) => {
|
|
870
|
+
const item = prepared.get(source);
|
|
871
|
+
|
|
872
|
+
if (item === undefined) {
|
|
873
|
+
throw new Error(`Anchor refers to undeclared resource ${source}`);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
return anchorResolvers.resolve(
|
|
877
|
+
value,
|
|
878
|
+
item.anchorContext,
|
|
879
|
+
kinds === undefined ? undefined : new Set(kinds),
|
|
880
|
+
);
|
|
881
|
+
});
|
|
882
|
+
const resources = sources.map((source) => {
|
|
883
|
+
const item = requiredValue(prepared.get(source));
|
|
884
|
+
const changes = mutation.changes.get(source);
|
|
885
|
+
const applied =
|
|
886
|
+
changes === undefined
|
|
887
|
+
? { content: item.before.content, changes: [] }
|
|
888
|
+
: applyTextChanges(item.before.content, changes);
|
|
889
|
+
return {
|
|
890
|
+
path: source,
|
|
891
|
+
existed: item.existed,
|
|
892
|
+
beforeRanges: applied.changes.map(({ fromBefore: from, toBefore: to }) => ({ from, to })),
|
|
893
|
+
...(item.resource.link !== undefined && { link: item.resource.link }),
|
|
894
|
+
beforeContent: item.before.content,
|
|
895
|
+
afterContent: applied.content,
|
|
896
|
+
ranges: applied.changes.map(({ fromAfter: from, toAfter: to }) => ({ from, to })),
|
|
897
|
+
};
|
|
898
|
+
});
|
|
897
899
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
return { kind: "failed", reason: error instanceof Error ? error.message : String(error) };
|
|
903
|
-
}
|
|
900
|
+
return { kind: "completed", resources };
|
|
901
|
+
} catch (error) {
|
|
902
|
+
return { kind: "failed", reason: error instanceof Error ? error.message : String(error) };
|
|
903
|
+
}
|
|
904
904
|
}
|
|
905
905
|
|
|
906
|
-
interface PreparedTextResource
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
readonly anchorContext: TextAnchorResolverContext;
|
|
906
|
+
interface PreparedTextResource {
|
|
907
|
+
readonly requestedSource: string;
|
|
908
|
+
readonly resource: Resource & { readonly write: ResourceWrite };
|
|
909
|
+
readonly resolverId: string;
|
|
910
|
+
readonly existed: boolean;
|
|
911
|
+
readonly before: TextDocument;
|
|
912
|
+
readonly anchorContext: TextAnchorResolverContext;
|
|
914
913
|
}
|
|
915
914
|
|
|
916
915
|
async function editTextResources<Result>(
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
): Promise<TextResourcesEditOutcome<Result>>
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
916
|
+
requests: readonly TextResourceEditRequest[],
|
|
917
|
+
context: TextResourcesEditContext,
|
|
918
|
+
resolvers: readonly RegisteredResolver[],
|
|
919
|
+
anchorResolvers: TextAnchorRegistrySnapshot,
|
|
920
|
+
presenters: readonly RegisteredPresenter[],
|
|
921
|
+
postEditHandlers: readonly TextPostEditHandlerRegistration[],
|
|
922
|
+
editCompletionListeners: readonly TextEditCompletionListener[],
|
|
923
|
+
mutationGuards: readonly TextMutationGuardRegistration[],
|
|
924
|
+
operation: (
|
|
925
|
+
texts: ReadonlyMap<string, string>,
|
|
926
|
+
resolveAnchor: ResolveResourceTextAnchor,
|
|
927
|
+
) => TextResourcesMutationResult<Result> | Promise<TextResourcesMutationResult<Result>>,
|
|
928
|
+
): Promise<TextResourcesEditOutcome<Result>> {
|
|
929
|
+
const requestBySource = new Map(requests.map((request) => [request.source, request]));
|
|
930
|
+
const sources = [...requestBySource.keys()];
|
|
931
|
+
|
|
932
|
+
if (sources.length === 0 || sources.some((source) => source.length === 0)) {
|
|
933
|
+
const source = sources.find((candidate) => candidate.length === 0) ?? "";
|
|
934
|
+
return {
|
|
935
|
+
kind: "failed",
|
|
936
|
+
failure: { code: "INVALID_REQUEST", source, message: "No source was provided" },
|
|
937
|
+
completed: [],
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const prepared = new Map<string, PreparedTextResource>();
|
|
942
|
+
|
|
943
|
+
for (const source of sources) {
|
|
944
|
+
const request = requiredValue(requestBySource.get(source));
|
|
945
|
+
const outcome = await prepareTextResource(
|
|
946
|
+
source,
|
|
947
|
+
request.read,
|
|
948
|
+
request.allowReadFailure ?? false,
|
|
949
|
+
context,
|
|
950
|
+
resolvers,
|
|
951
|
+
);
|
|
933
952
|
|
|
934
|
-
if (
|
|
935
|
-
|
|
936
|
-
const source = sources.find((candidate) => candidate.length === 0) ?? "";
|
|
937
|
-
return {
|
|
938
|
-
kind: "failed",
|
|
939
|
-
failure: { code: "INVALID_REQUEST", source, message: "No source was provided" },
|
|
940
|
-
completed: [],
|
|
941
|
-
};
|
|
953
|
+
if ("failure" in outcome) {
|
|
954
|
+
return { kind: "failed", failure: outcome.failure, completed: [] };
|
|
942
955
|
}
|
|
943
956
|
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
for (const source of sources)
|
|
947
|
-
{
|
|
948
|
-
const request = requestBySource.get(source)!;
|
|
949
|
-
const outcome = await prepareTextResource(
|
|
950
|
-
source,
|
|
951
|
-
request.read,
|
|
952
|
-
request.allowReadFailure ?? false,
|
|
953
|
-
context,
|
|
954
|
-
resolvers,
|
|
955
|
-
);
|
|
957
|
+
prepared.set(source, outcome);
|
|
958
|
+
}
|
|
956
959
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
960
|
+
const texts = new Map([...prepared].map(([source, item]) => [source, item.before.content]));
|
|
961
|
+
const mutation = await operation(texts, (source, value, kinds) => {
|
|
962
|
+
const item = prepared.get(source);
|
|
961
963
|
|
|
962
|
-
|
|
964
|
+
if (item === undefined) {
|
|
965
|
+
throw new Error(`Anchor refers to undeclared resource ${source}`);
|
|
963
966
|
}
|
|
964
967
|
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
{
|
|
972
|
-
throw new Error(`Anchor refers to undeclared resource ${source}`);
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
return anchorResolvers.resolve(value, item.anchorContext, kinds === undefined ? undefined : new Set(kinds));
|
|
976
|
-
});
|
|
968
|
+
return anchorResolvers.resolve(
|
|
969
|
+
value,
|
|
970
|
+
item.anchorContext,
|
|
971
|
+
kinds === undefined ? undefined : new Set(kinds),
|
|
972
|
+
);
|
|
973
|
+
});
|
|
977
974
|
|
|
978
|
-
|
|
979
|
-
{
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
completed: [],
|
|
990
|
-
};
|
|
991
|
-
}
|
|
975
|
+
for (const source of mutation.changes.keys()) {
|
|
976
|
+
if (!prepared.has(source)) {
|
|
977
|
+
return {
|
|
978
|
+
kind: "failed",
|
|
979
|
+
failure: {
|
|
980
|
+
code: "INVALID_WRITE_CONTENT",
|
|
981
|
+
source,
|
|
982
|
+
message: `Text edit produced an undeclared resource ${source}`,
|
|
983
|
+
},
|
|
984
|
+
completed: [],
|
|
985
|
+
};
|
|
992
986
|
}
|
|
987
|
+
}
|
|
993
988
|
|
|
994
|
-
|
|
989
|
+
const applied = new Map<string, TextChangeResult>();
|
|
995
990
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}
|
|
991
|
+
for (const [source, changes] of mutation.changes) {
|
|
992
|
+
const item = requiredValue(prepared.get(source));
|
|
993
|
+
applied.set(source, applyTextChanges(item.before.content, changes));
|
|
994
|
+
}
|
|
1001
995
|
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
const result = applied.get(source);
|
|
1007
|
-
|
|
1008
|
-
return result === undefined || result.content === item.before.content
|
|
1009
|
-
? []
|
|
1010
|
-
: [{
|
|
1011
|
-
source: item.resource.source,
|
|
1012
|
-
existed: item.existed,
|
|
1013
|
-
before: item.before,
|
|
1014
|
-
after: createTextDocument(item.resource.source, result.content),
|
|
1015
|
-
changes: result.changes,
|
|
1016
|
-
}];
|
|
1017
|
-
}),
|
|
1018
|
-
};
|
|
996
|
+
const plan: TextMutationPlan = {
|
|
997
|
+
resources: sources.flatMap((source) => {
|
|
998
|
+
const item = requiredValue(prepared.get(source));
|
|
999
|
+
const result = applied.get(source);
|
|
1019
1000
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1001
|
+
return result === undefined || result.content === item.before.content
|
|
1002
|
+
? []
|
|
1003
|
+
: [
|
|
1004
|
+
{
|
|
1005
|
+
source: item.resource.source,
|
|
1006
|
+
existed: item.existed,
|
|
1007
|
+
before: item.before,
|
|
1008
|
+
after: createTextDocument(item.resource.source, result.content),
|
|
1009
|
+
changes: result.changes,
|
|
1010
|
+
},
|
|
1011
|
+
];
|
|
1012
|
+
}),
|
|
1013
|
+
};
|
|
1023
1014
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
outcome = await registration.guard(plan, context);
|
|
1027
|
-
}
|
|
1028
|
-
catch (error)
|
|
1029
|
-
{
|
|
1030
|
-
return {
|
|
1031
|
-
kind: "failed",
|
|
1032
|
-
failure: {
|
|
1033
|
-
code: "PLUGIN_FAILED",
|
|
1034
|
-
source: sources[0] ?? "",
|
|
1035
|
-
message: `Mutation guard ${registration.id} failed`,
|
|
1036
|
-
cause: error,
|
|
1037
|
-
},
|
|
1038
|
-
completed: [],
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1015
|
+
for (const registration of mutationGuards) {
|
|
1016
|
+
let outcome;
|
|
1041
1017
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1018
|
+
try {
|
|
1019
|
+
outcome = await registration.guard(plan, context);
|
|
1020
|
+
} catch (error) {
|
|
1021
|
+
return {
|
|
1022
|
+
kind: "failed",
|
|
1023
|
+
failure: {
|
|
1024
|
+
code: "PLUGIN_FAILED",
|
|
1025
|
+
source: sources[0] ?? "",
|
|
1026
|
+
message: `Mutation guard ${registration.id} failed`,
|
|
1027
|
+
cause: error,
|
|
1028
|
+
},
|
|
1029
|
+
completed: [],
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (outcome.kind === "rejected") {
|
|
1034
|
+
return {
|
|
1035
|
+
kind: "failed",
|
|
1036
|
+
failure: {
|
|
1037
|
+
code: "MUTATION_REJECTED",
|
|
1038
|
+
source: plan.resources[0]?.source ?? sources[0] ?? "",
|
|
1039
|
+
message: outcome.rejection.message,
|
|
1040
|
+
},
|
|
1041
|
+
completed: [],
|
|
1042
|
+
};
|
|
1054
1043
|
}
|
|
1044
|
+
}
|
|
1055
1045
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1046
|
+
const completed: string[] = [];
|
|
1047
|
+
const written: string[] = [];
|
|
1048
|
+
const outcomes: Exclude<TextResourceEditOutcome<unknown>, { readonly kind: "failed" }>[] = [];
|
|
1058
1049
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
const item = prepared.get(source)!;
|
|
1050
|
+
for (const source of sources) {
|
|
1051
|
+
const text = applied.get(source)?.content;
|
|
1052
|
+
const item = requiredValue(prepared.get(source));
|
|
1063
1053
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
}
|
|
1054
|
+
if (text === undefined || text === item.before.content) {
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1068
1057
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
if (!isAgentContent(finalContent))
|
|
1072
|
-
{
|
|
1073
|
-
return {
|
|
1074
|
-
kind: "failed",
|
|
1075
|
-
failure: {
|
|
1076
|
-
code: "INVALID_WRITE_CONTENT",
|
|
1077
|
-
source,
|
|
1078
|
-
message: `Text edit for ${source} produced invalid content`,
|
|
1079
|
-
},
|
|
1080
|
-
completed,
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1058
|
+
const finalContent: unknown = [{ type: "text", text }];
|
|
1083
1059
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
resolverId: item.resolverId,
|
|
1096
|
-
message: `Unable to write ${source}`,
|
|
1097
|
-
cause: error,
|
|
1098
|
-
},
|
|
1099
|
-
completed,
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1060
|
+
if (!isAgentContent(finalContent)) {
|
|
1061
|
+
return {
|
|
1062
|
+
kind: "failed",
|
|
1063
|
+
failure: {
|
|
1064
|
+
code: "INVALID_WRITE_CONTENT",
|
|
1065
|
+
source,
|
|
1066
|
+
message: `Text edit for ${source} produced invalid content`,
|
|
1067
|
+
},
|
|
1068
|
+
completed,
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1102
1071
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1072
|
+
try {
|
|
1073
|
+
await item.resource.write(
|
|
1074
|
+
finalContent,
|
|
1075
|
+
context.signal === undefined ? {} : { signal: context.signal },
|
|
1076
|
+
);
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
const rollbackFailures: string[] = [];
|
|
1079
|
+
for (const writtenSource of [source, ...written].reverse()) {
|
|
1080
|
+
const writtenItem = requiredValue(prepared.get(writtenSource));
|
|
1081
|
+
try {
|
|
1082
|
+
await writtenItem.resource.write(
|
|
1083
|
+
[{ type: "text", text: writtenItem.before.content }],
|
|
1084
|
+
{},
|
|
1085
|
+
);
|
|
1086
|
+
} catch {
|
|
1087
|
+
rollbackFailures.push(writtenSource);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
kind: "failed",
|
|
1092
|
+
failure: {
|
|
1093
|
+
code: "WRITE_FAILED",
|
|
1094
|
+
source,
|
|
1095
|
+
resolverId: item.resolverId,
|
|
1096
|
+
message:
|
|
1097
|
+
rollbackFailures.length === 0
|
|
1098
|
+
? `Unable to write ${source}; completed writes were rolled back`
|
|
1099
|
+
: `Unable to write ${source}; rollback failed for ${rollbackFailures.join(", ")}`,
|
|
1100
|
+
cause: error,
|
|
1101
|
+
},
|
|
1102
|
+
completed: rollbackFailures,
|
|
1103
|
+
};
|
|
1120
1104
|
}
|
|
1121
1105
|
|
|
1122
|
-
|
|
1106
|
+
written.push(source);
|
|
1107
|
+
completed.push(source);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
for (const source of written) {
|
|
1111
|
+
const text = requiredValue(applied.get(source)).content;
|
|
1112
|
+
const item = requiredValue(prepared.get(source));
|
|
1113
|
+
outcomes.push(
|
|
1114
|
+
await finalizeTextResource({
|
|
1115
|
+
requestedSource: item.requestedSource,
|
|
1116
|
+
outcomeSource: item.requestedSource,
|
|
1117
|
+
resource: item.resource,
|
|
1118
|
+
resolvedBy: item.resolverId,
|
|
1119
|
+
existed: item.existed,
|
|
1120
|
+
before: item.before,
|
|
1121
|
+
requestedText: text,
|
|
1122
|
+
context,
|
|
1123
|
+
presenters,
|
|
1124
|
+
postEditHandlers,
|
|
1125
|
+
editCompletionListeners,
|
|
1126
|
+
result: mutation.result,
|
|
1127
|
+
}),
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
return { kind: "completed", resources: outcomes, result: mutation.result };
|
|
1123
1132
|
}
|
|
1124
1133
|
|
|
1125
1134
|
async function prepareTextResource(
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
): Promise<PreparedTextResource | { readonly failure: TextResourceEditFailure
|
|
1132
|
-
{
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
message: `Resolver ${resolver.id} failed`,
|
|
1149
|
-
cause: error,
|
|
1150
|
-
},
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1135
|
+
source: string,
|
|
1136
|
+
read: boolean,
|
|
1137
|
+
allowReadFailure: boolean,
|
|
1138
|
+
context: ResourceResolverContext,
|
|
1139
|
+
resolvers: readonly RegisteredResolver[],
|
|
1140
|
+
): Promise<PreparedTextResource | { readonly failure: TextResourceEditFailure }> {
|
|
1141
|
+
for (const { resolver } of resolvers) {
|
|
1142
|
+
let attempt: unknown;
|
|
1143
|
+
|
|
1144
|
+
try {
|
|
1145
|
+
attempt = await resolver.tryResolve(source, context);
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
return {
|
|
1148
|
+
failure: {
|
|
1149
|
+
code: "RESOLVE_FAILED",
|
|
1150
|
+
source,
|
|
1151
|
+
resolverId: resolver.id,
|
|
1152
|
+
message: `Resolver ${resolver.id} failed`,
|
|
1153
|
+
cause: error,
|
|
1154
|
+
},
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1153
1157
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1158
|
+
if (!isResourceResolutionAttempt(attempt)) {
|
|
1159
|
+
return {
|
|
1160
|
+
failure: {
|
|
1161
|
+
code: "INVALID_RESOLVER_RESULT",
|
|
1162
|
+
source,
|
|
1163
|
+
resolverId: resolver.id,
|
|
1164
|
+
message: `Resolver ${resolver.id} returned an invalid result`,
|
|
1165
|
+
cause: attempt,
|
|
1166
|
+
},
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1166
1169
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
}
|
|
1170
|
+
if (attempt.kind === "not-handled") {
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1171
1173
|
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
}
|
|
1174
|
+
if (attempt.kind === "failed") {
|
|
1175
|
+
return {
|
|
1176
|
+
failure: {
|
|
1177
|
+
code: "RESOLVE_FAILED",
|
|
1178
|
+
source,
|
|
1179
|
+
resolverId: resolver.id,
|
|
1180
|
+
message: `Resolver ${resolver.id} failed`,
|
|
1181
|
+
cause: attempt.error,
|
|
1182
|
+
},
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1184
1185
|
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1186
|
+
if (attempt.resource.write === undefined || (read && attempt.resource.read === undefined)) {
|
|
1187
|
+
return {
|
|
1188
|
+
failure: {
|
|
1189
|
+
code: "UNSUPPORTED_CAPABILITY",
|
|
1190
|
+
source: attempt.resource.source,
|
|
1191
|
+
resolverId: resolver.id,
|
|
1192
|
+
message: `Resource ${attempt.resource.source} does not support text editing`,
|
|
1193
|
+
},
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
1196
|
|
|
1197
|
-
|
|
1198
|
-
|
|
1197
|
+
let text = "";
|
|
1198
|
+
let isExisted = read;
|
|
1199
1199
|
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
let content: unknown;
|
|
1200
|
+
if (read) {
|
|
1201
|
+
let content: unknown;
|
|
1203
1202
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
},
|
|
1220
|
-
};
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
existed = false;
|
|
1224
|
-
content = [{ type: "text", text: "" }];
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
if (!isAgentContent(content) || content.length !== 1 || content[0].type !== "text")
|
|
1228
|
-
{
|
|
1229
|
-
return {
|
|
1230
|
-
failure: {
|
|
1231
|
-
code: "UNSUPPORTED_CONTENT",
|
|
1232
|
-
source: attempt.resource.source,
|
|
1233
|
-
resolverId: resolver.id,
|
|
1234
|
-
message: `Resource ${attempt.resource.source} is not editable text`,
|
|
1235
|
-
cause: content,
|
|
1236
|
-
},
|
|
1237
|
-
};
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
text = content[0].text;
|
|
1203
|
+
try {
|
|
1204
|
+
content = await requiredValue(attempt.resource.read)(
|
|
1205
|
+
context.signal === undefined ? {} : { signal: context.signal },
|
|
1206
|
+
);
|
|
1207
|
+
} catch (error) {
|
|
1208
|
+
if (!allowReadFailure) {
|
|
1209
|
+
return {
|
|
1210
|
+
failure: {
|
|
1211
|
+
code: "READ_FAILED",
|
|
1212
|
+
source: attempt.resource.source,
|
|
1213
|
+
resolverId: resolver.id,
|
|
1214
|
+
message: `Unable to read ${attempt.resource.source}`,
|
|
1215
|
+
cause: error,
|
|
1216
|
+
},
|
|
1217
|
+
};
|
|
1241
1218
|
}
|
|
1242
1219
|
|
|
1243
|
-
|
|
1220
|
+
isExisted = false;
|
|
1221
|
+
content = [{ type: "text", text: "" }];
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
if (!isAgentContent(content) || content.length !== 1 || content[0].type !== "text") {
|
|
1244
1225
|
return {
|
|
1245
|
-
|
|
1246
|
-
|
|
1226
|
+
failure: {
|
|
1227
|
+
code: "UNSUPPORTED_CONTENT",
|
|
1228
|
+
source: attempt.resource.source,
|
|
1247
1229
|
resolverId: resolver.id,
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
source: attempt.resource.source,
|
|
1252
|
-
content: before.content,
|
|
1253
|
-
lines: before.lines.map((line) => line.content),
|
|
1254
|
-
cwd: context.cwd,
|
|
1255
|
-
...(context.signal === undefined ? {} : { signal: context.signal }),
|
|
1256
|
-
},
|
|
1230
|
+
message: `Resource ${attempt.resource.source} is not editable text`,
|
|
1231
|
+
cause: content,
|
|
1232
|
+
},
|
|
1257
1233
|
};
|
|
1258
|
-
|
|
1234
|
+
}
|
|
1259
1235
|
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1236
|
+
text = content[0].text;
|
|
1237
|
+
}
|
|
1262
1238
|
|
|
1263
|
-
|
|
1264
|
-
{
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
async function finalizeTextResource<Result>(
|
|
1280
|
-
request: FinalizeTextResourceRequest<Result>,
|
|
1281
|
-
): Promise<Exclude<TextResourceEditOutcome<Result>, { readonly kind: "failed"; }>>
|
|
1282
|
-
{
|
|
1283
|
-
const requestedAfter = createTextDocument(request.resource.source, request.requestedText);
|
|
1284
|
-
const transaction: TextPostEditTransaction = {
|
|
1285
|
-
source: request.requestedSource,
|
|
1286
|
-
resourceSource: request.resource.source,
|
|
1287
|
-
resolvedBy: request.resolvedBy,
|
|
1288
|
-
cwd: request.context.cwd,
|
|
1289
|
-
before: request.before,
|
|
1290
|
-
requestedAfter,
|
|
1291
|
-
...(request.context.signal === undefined ? {} : { signal: request.context.signal }),
|
|
1239
|
+
const before = createTextDocument(attempt.resource.source, text);
|
|
1240
|
+
return {
|
|
1241
|
+
requestedSource: source,
|
|
1242
|
+
resource: attempt.resource,
|
|
1243
|
+
resolverId: resolver.id,
|
|
1244
|
+
existed: isExisted,
|
|
1245
|
+
before,
|
|
1246
|
+
anchorContext: {
|
|
1247
|
+
source: attempt.resource.source,
|
|
1248
|
+
content: before.content,
|
|
1249
|
+
lines: before.lines.map((line) => line.content),
|
|
1250
|
+
cwd: context.cwd,
|
|
1251
|
+
...(context.signal !== undefined && { signal: context.signal }),
|
|
1252
|
+
},
|
|
1292
1253
|
};
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
for (const registration of request.postEditHandlers)
|
|
1296
|
-
{
|
|
1297
|
-
try
|
|
1298
|
-
{
|
|
1299
|
-
const data = await registration.handler(transaction);
|
|
1254
|
+
}
|
|
1300
1255
|
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
postEditContributions.push({ id: registration.id, data });
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
catch
|
|
1307
|
-
{
|
|
1308
|
-
// Post-edit integrations do not change a successful write into a failure.
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
let finalText = request.requestedText;
|
|
1256
|
+
return { failure: { code: "NO_RESOLVER", source, message: `No resolver handled ${source}` } };
|
|
1257
|
+
}
|
|
1313
1258
|
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1259
|
+
interface FinalizeTextResourceRequest<Result> {
|
|
1260
|
+
readonly requestedSource: string;
|
|
1261
|
+
readonly outcomeSource: string;
|
|
1262
|
+
readonly resource: Resource;
|
|
1263
|
+
readonly resolvedBy: string;
|
|
1264
|
+
readonly existed: boolean;
|
|
1265
|
+
readonly before: TextDocument;
|
|
1266
|
+
readonly requestedText: string;
|
|
1267
|
+
readonly context: ResourceResolverContext & { readonly intent?: TextEditIntent };
|
|
1268
|
+
readonly presenters: readonly RegisteredPresenter[];
|
|
1269
|
+
readonly postEditHandlers: readonly TextPostEditHandlerRegistration[];
|
|
1270
|
+
readonly editCompletionListeners: readonly TextEditCompletionListener[];
|
|
1271
|
+
readonly result: Result;
|
|
1272
|
+
}
|
|
1321
1273
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1274
|
+
async function finalizeTextResource<Result>(
|
|
1275
|
+
request: FinalizeTextResourceRequest<Result>,
|
|
1276
|
+
): Promise<Exclude<TextResourceEditOutcome<Result>, { readonly kind: "failed" }>> {
|
|
1277
|
+
const requestedAfter = createTextDocument(request.resource.source, request.requestedText);
|
|
1278
|
+
const transaction: TextPostEditTransaction = {
|
|
1279
|
+
source: request.requestedSource,
|
|
1280
|
+
resourceSource: request.resource.source,
|
|
1281
|
+
resolvedBy: request.resolvedBy,
|
|
1282
|
+
cwd: request.context.cwd,
|
|
1283
|
+
before: request.before,
|
|
1284
|
+
requestedAfter,
|
|
1285
|
+
...(request.context.signal !== undefined && { signal: request.context.signal }),
|
|
1286
|
+
};
|
|
1287
|
+
const postEditContributions: TextPostEditContribution[] = [];
|
|
1288
|
+
|
|
1289
|
+
for (const registration of request.postEditHandlers) {
|
|
1290
|
+
try {
|
|
1291
|
+
const data = await registration.handler(transaction);
|
|
1292
|
+
|
|
1293
|
+
if (data !== undefined) {
|
|
1294
|
+
postEditContributions.push({ id: registration.id, data });
|
|
1295
|
+
}
|
|
1296
|
+
} catch {
|
|
1297
|
+
// Post-edit integrations do not change a successful write into a failure.
|
|
1331
1298
|
}
|
|
1299
|
+
}
|
|
1332
1300
|
|
|
1333
|
-
|
|
1334
|
-
const completion: TextEditCompletion = {
|
|
1335
|
-
source: request.requestedSource,
|
|
1336
|
-
resourceSource: request.resource.source,
|
|
1337
|
-
resolvedBy: request.resolvedBy,
|
|
1338
|
-
cwd: request.context.cwd,
|
|
1339
|
-
existed: request.existed,
|
|
1340
|
-
before: request.before,
|
|
1341
|
-
after: finalAfter,
|
|
1342
|
-
intent: request.context.intent ?? "edit",
|
|
1343
|
-
};
|
|
1301
|
+
let finalText = request.requestedText;
|
|
1344
1302
|
|
|
1345
|
-
|
|
1346
|
-
{
|
|
1347
|
-
|
|
1348
|
-
{
|
|
1349
|
-
|
|
1350
|
-
}
|
|
1351
|
-
catch
|
|
1352
|
-
{
|
|
1353
|
-
// Completion observers cannot turn a successful write into a failure.
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
let after = finalAfter;
|
|
1358
|
-
const presentationContext: TextPresentationContext = {
|
|
1359
|
-
purpose: "edit-diff",
|
|
1360
|
-
source: request.resource.source,
|
|
1361
|
-
cwd: request.context.cwd,
|
|
1362
|
-
resolvedBy: request.resolvedBy,
|
|
1363
|
-
...(request.context.signal === undefined ? {} : { signal: request.context.signal }),
|
|
1364
|
-
};
|
|
1303
|
+
if (request.resource.read !== undefined) {
|
|
1304
|
+
try {
|
|
1305
|
+
const reread = await request.resource.read(
|
|
1306
|
+
request.context.signal === undefined ? {} : { signal: request.context.signal },
|
|
1307
|
+
);
|
|
1365
1308
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1309
|
+
if (isAgentContent(reread) && reread.length === 1 && reread[0].type === "text") {
|
|
1310
|
+
finalText = reread[0].text;
|
|
1311
|
+
}
|
|
1312
|
+
} catch {
|
|
1313
|
+
// The requested mutation remains the successful fallback when a final reread fails.
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
const finalAfter = createTextDocument(request.resource.source, finalText);
|
|
1318
|
+
const completion: TextEditCompletion = {
|
|
1319
|
+
source: request.requestedSource,
|
|
1320
|
+
resourceSource: request.resource.source,
|
|
1321
|
+
resolvedBy: request.resolvedBy,
|
|
1322
|
+
cwd: request.context.cwd,
|
|
1323
|
+
existed: request.existed,
|
|
1324
|
+
before: request.before,
|
|
1325
|
+
after: finalAfter,
|
|
1326
|
+
intent: request.context.intent ?? "edit",
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
for (const listener of request.editCompletionListeners) {
|
|
1330
|
+
try {
|
|
1331
|
+
await listener(completion);
|
|
1332
|
+
} catch {
|
|
1333
|
+
// Completion observers cannot turn a successful write into a failure.
|
|
1369
1334
|
}
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
let after = finalAfter;
|
|
1338
|
+
const presentationContext: TextPresentationContext = {
|
|
1339
|
+
purpose: "edit-diff",
|
|
1340
|
+
source: request.resource.source,
|
|
1341
|
+
cwd: request.context.cwd,
|
|
1342
|
+
resolvedBy: request.resolvedBy,
|
|
1343
|
+
...(request.context.signal !== undefined && { signal: request.context.signal }),
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
for (const { registration } of request.presenters) {
|
|
1347
|
+
after = await registration.presenter.present(after, presentationContext);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
return {
|
|
1351
|
+
kind: "completed",
|
|
1352
|
+
source: request.outcomeSource,
|
|
1353
|
+
resolvedBy: request.resolvedBy,
|
|
1354
|
+
before: request.before,
|
|
1355
|
+
after,
|
|
1356
|
+
result: request.result,
|
|
1357
|
+
postEditContributions,
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1370
1360
|
|
|
1361
|
+
async function editTextResource<Result>(
|
|
1362
|
+
source: string,
|
|
1363
|
+
context: ResourceResolverContext,
|
|
1364
|
+
resolvers: readonly RegisteredResolver[],
|
|
1365
|
+
anchorResolvers: TextAnchorRegistrySnapshot,
|
|
1366
|
+
presenters: readonly RegisteredPresenter[],
|
|
1367
|
+
postEditHandlers: readonly TextPostEditHandlerRegistration[],
|
|
1368
|
+
editCompletionListeners: readonly TextEditCompletionListener[],
|
|
1369
|
+
operation: (
|
|
1370
|
+
text: string,
|
|
1371
|
+
resolveAnchor: ResolveTextAnchor,
|
|
1372
|
+
) => TextMutationResult<Result> | Promise<TextMutationResult<Result>>,
|
|
1373
|
+
): Promise<TextResourceEditOutcome<Result>> {
|
|
1374
|
+
if (source.length === 0) {
|
|
1371
1375
|
return {
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
postEditContributions,
|
|
1376
|
+
kind: "failed",
|
|
1377
|
+
failure: {
|
|
1378
|
+
code: "INVALID_REQUEST",
|
|
1379
|
+
source,
|
|
1380
|
+
message: "No source was provided",
|
|
1381
|
+
},
|
|
1379
1382
|
};
|
|
1380
|
-
}
|
|
1383
|
+
}
|
|
1381
1384
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
context: ResourceResolverContext,
|
|
1385
|
-
resolvers: readonly RegisteredResolver[],
|
|
1386
|
-
anchorResolvers: TextAnchorRegistrySnapshot,
|
|
1387
|
-
presenters: readonly RegisteredPresenter[],
|
|
1388
|
-
postEditHandlers: readonly TextPostEditHandlerRegistration[],
|
|
1389
|
-
editCompletionListeners: readonly TextEditCompletionListener[],
|
|
1390
|
-
operation: (
|
|
1391
|
-
text: string,
|
|
1392
|
-
resolveAnchor: ResolveTextAnchor,
|
|
1393
|
-
) => TextMutationResult<Result> | Promise<TextMutationResult<Result>>,
|
|
1394
|
-
): Promise<TextResourceEditOutcome<Result>>
|
|
1395
|
-
{
|
|
1396
|
-
if (source.length === 0)
|
|
1397
|
-
{
|
|
1398
|
-
return {
|
|
1399
|
-
kind: "failed",
|
|
1400
|
-
failure: {
|
|
1401
|
-
code: "INVALID_REQUEST",
|
|
1402
|
-
source,
|
|
1403
|
-
message: "No source was provided",
|
|
1404
|
-
},
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1385
|
+
for (const { resolver } of resolvers) {
|
|
1386
|
+
let attempt: unknown;
|
|
1407
1387
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1388
|
+
try {
|
|
1389
|
+
attempt = await resolver.tryResolve(source, context);
|
|
1390
|
+
} catch (error) {
|
|
1391
|
+
return {
|
|
1392
|
+
kind: "failed",
|
|
1393
|
+
failure: {
|
|
1394
|
+
code: "RESOLVE_FAILED",
|
|
1395
|
+
source,
|
|
1396
|
+
resolverId: resolver.id,
|
|
1397
|
+
message: `Resolver ${resolver.id} failed`,
|
|
1398
|
+
cause: error,
|
|
1399
|
+
},
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1411
1402
|
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
message: `Resolver ${resolver.id} failed`,
|
|
1425
|
-
cause: error,
|
|
1426
|
-
},
|
|
1427
|
-
};
|
|
1428
|
-
}
|
|
1403
|
+
if (!isResourceResolutionAttempt(attempt)) {
|
|
1404
|
+
return {
|
|
1405
|
+
kind: "failed",
|
|
1406
|
+
failure: {
|
|
1407
|
+
code: "INVALID_RESOLVER_RESULT",
|
|
1408
|
+
source,
|
|
1409
|
+
resolverId: resolver.id,
|
|
1410
|
+
message: `Resolver ${resolver.id} returned an invalid result`,
|
|
1411
|
+
cause: attempt,
|
|
1412
|
+
},
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1429
1415
|
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
kind: "failed",
|
|
1434
|
-
failure: {
|
|
1435
|
-
code: "INVALID_RESOLVER_RESULT",
|
|
1436
|
-
source,
|
|
1437
|
-
resolverId: resolver.id,
|
|
1438
|
-
message: `Resolver ${resolver.id} returned an invalid result`,
|
|
1439
|
-
cause: attempt,
|
|
1440
|
-
},
|
|
1441
|
-
};
|
|
1442
|
-
}
|
|
1416
|
+
if (attempt.kind === "not-handled") {
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1443
1419
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1420
|
+
if (attempt.kind === "failed") {
|
|
1421
|
+
return {
|
|
1422
|
+
kind: "failed",
|
|
1423
|
+
failure: {
|
|
1424
|
+
code: "RESOLVE_FAILED",
|
|
1425
|
+
source,
|
|
1426
|
+
resolverId: resolver.id,
|
|
1427
|
+
message: `Resolver ${resolver.id} failed`,
|
|
1428
|
+
cause: attempt.error,
|
|
1429
|
+
},
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1448
1432
|
|
|
1449
|
-
|
|
1450
|
-
{
|
|
1451
|
-
return {
|
|
1452
|
-
kind: "failed",
|
|
1453
|
-
failure: {
|
|
1454
|
-
code: "RESOLVE_FAILED",
|
|
1455
|
-
source,
|
|
1456
|
-
resolverId: resolver.id,
|
|
1457
|
-
message: `Resolver ${resolver.id} failed`,
|
|
1458
|
-
cause: attempt.error,
|
|
1459
|
-
},
|
|
1460
|
-
};
|
|
1461
|
-
}
|
|
1433
|
+
const resource = attempt.resource;
|
|
1462
1434
|
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
{
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
},
|
|
1475
|
-
};
|
|
1476
|
-
}
|
|
1435
|
+
if (resource.read === undefined || resource.write === undefined) {
|
|
1436
|
+
return {
|
|
1437
|
+
kind: "failed",
|
|
1438
|
+
failure: {
|
|
1439
|
+
code: "UNSUPPORTED_CAPABILITY",
|
|
1440
|
+
source: resource.source,
|
|
1441
|
+
resolverId: resolver.id,
|
|
1442
|
+
message: `Resource ${resource.source} does not support text editing`,
|
|
1443
|
+
},
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1477
1446
|
|
|
1478
|
-
|
|
1447
|
+
let content: unknown;
|
|
1479
1448
|
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
{
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
},
|
|
1497
|
-
};
|
|
1498
|
-
}
|
|
1449
|
+
try {
|
|
1450
|
+
content = await resource.read({
|
|
1451
|
+
...(context.signal !== undefined && { signal: context.signal }),
|
|
1452
|
+
});
|
|
1453
|
+
} catch (error) {
|
|
1454
|
+
return {
|
|
1455
|
+
kind: "failed",
|
|
1456
|
+
failure: {
|
|
1457
|
+
code: "READ_FAILED",
|
|
1458
|
+
source: resource.source,
|
|
1459
|
+
resolverId: resolver.id,
|
|
1460
|
+
message: `Unable to read ${resource.source}`,
|
|
1461
|
+
cause: error,
|
|
1462
|
+
},
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1499
1465
|
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1466
|
+
if (!isAgentContent(content)) {
|
|
1467
|
+
return {
|
|
1468
|
+
kind: "failed",
|
|
1469
|
+
failure: {
|
|
1470
|
+
code: "INVALID_RESOURCE_CONTENT",
|
|
1471
|
+
source: resource.source,
|
|
1472
|
+
resolverId: resolver.id,
|
|
1473
|
+
message: `Resource ${resource.source} returned invalid content`,
|
|
1474
|
+
cause: content,
|
|
1475
|
+
},
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1513
1478
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
if (content.length !== 1 || block.type !== "text")
|
|
1517
|
-
{
|
|
1518
|
-
return {
|
|
1519
|
-
kind: "failed",
|
|
1520
|
-
failure: {
|
|
1521
|
-
code: "UNSUPPORTED_CONTENT",
|
|
1522
|
-
source: resource.source,
|
|
1523
|
-
resolverId: resolver.id,
|
|
1524
|
-
message: `Resource ${resource.source} is not editable text`,
|
|
1525
|
-
},
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1479
|
+
const block = content[0];
|
|
1528
1480
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
anchorResolvers.resolve(
|
|
1541
|
-
value,
|
|
1542
|
-
anchorContext,
|
|
1543
|
-
kinds === undefined ? undefined : new Set(kinds),
|
|
1544
|
-
),
|
|
1545
|
-
);
|
|
1546
|
-
const finalContent: unknown = [{ type: "text", text: mutation.text }];
|
|
1547
|
-
|
|
1548
|
-
if (!isAgentContent(finalContent))
|
|
1549
|
-
{
|
|
1550
|
-
return {
|
|
1551
|
-
kind: "failed",
|
|
1552
|
-
failure: {
|
|
1553
|
-
code: "INVALID_WRITE_CONTENT",
|
|
1554
|
-
source: resource.source,
|
|
1555
|
-
resolverId: resolver.id,
|
|
1556
|
-
message: `Text edit for ${resource.source} produced invalid content`,
|
|
1557
|
-
cause: mutation,
|
|
1558
|
-
},
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1481
|
+
if (content.length !== 1 || block.type !== "text") {
|
|
1482
|
+
return {
|
|
1483
|
+
kind: "failed",
|
|
1484
|
+
failure: {
|
|
1485
|
+
code: "UNSUPPORTED_CONTENT",
|
|
1486
|
+
source: resource.source,
|
|
1487
|
+
resolverId: resolver.id,
|
|
1488
|
+
message: `Resource ${resource.source} is not editable text`,
|
|
1489
|
+
},
|
|
1490
|
+
};
|
|
1491
|
+
}
|
|
1561
1492
|
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
},
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1493
|
+
const before = createTextDocument(resource.source, block.text);
|
|
1494
|
+
const anchorContext: TextAnchorResolverContext = {
|
|
1495
|
+
source: resource.source,
|
|
1496
|
+
content: before.content,
|
|
1497
|
+
lines: before.lines.map((line) => line.content),
|
|
1498
|
+
cwd: context.cwd,
|
|
1499
|
+
...(context.signal !== undefined && { signal: context.signal }),
|
|
1500
|
+
};
|
|
1501
|
+
const mutation = await operation(block.text, (value, kinds) =>
|
|
1502
|
+
anchorResolvers.resolve(
|
|
1503
|
+
value,
|
|
1504
|
+
anchorContext,
|
|
1505
|
+
kinds === undefined ? undefined : new Set(kinds),
|
|
1506
|
+
),
|
|
1507
|
+
);
|
|
1508
|
+
const finalContent: unknown = [{ type: "text", text: mutation.text }];
|
|
1581
1509
|
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
editCompletionListeners,
|
|
1594
|
-
result: mutation.result,
|
|
1595
|
-
});
|
|
1510
|
+
if (!isAgentContent(finalContent)) {
|
|
1511
|
+
return {
|
|
1512
|
+
kind: "failed",
|
|
1513
|
+
failure: {
|
|
1514
|
+
code: "INVALID_WRITE_CONTENT",
|
|
1515
|
+
source: resource.source,
|
|
1516
|
+
resolverId: resolver.id,
|
|
1517
|
+
message: `Text edit for ${resource.source} produced invalid content`,
|
|
1518
|
+
cause: mutation,
|
|
1519
|
+
},
|
|
1520
|
+
};
|
|
1596
1521
|
}
|
|
1597
1522
|
|
|
1598
|
-
|
|
1523
|
+
try {
|
|
1524
|
+
await resource.write(finalContent, {
|
|
1525
|
+
...(context.signal !== undefined && { signal: context.signal }),
|
|
1526
|
+
});
|
|
1527
|
+
} catch (error) {
|
|
1528
|
+
return {
|
|
1599
1529
|
kind: "failed",
|
|
1600
1530
|
failure: {
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1531
|
+
code: "WRITE_FAILED",
|
|
1532
|
+
source: resource.source,
|
|
1533
|
+
resolverId: resolver.id,
|
|
1534
|
+
message: `Unable to write ${resource.source}`,
|
|
1535
|
+
cause: error,
|
|
1604
1536
|
},
|
|
1605
|
-
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
return finalizeTextResource({
|
|
1541
|
+
requestedSource: source,
|
|
1542
|
+
outcomeSource: resource.source,
|
|
1543
|
+
resource,
|
|
1544
|
+
resolvedBy: resolver.id,
|
|
1545
|
+
existed: true,
|
|
1546
|
+
before,
|
|
1547
|
+
requestedText: mutation.text,
|
|
1548
|
+
context,
|
|
1549
|
+
presenters,
|
|
1550
|
+
postEditHandlers,
|
|
1551
|
+
editCompletionListeners,
|
|
1552
|
+
result: mutation.result,
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
return {
|
|
1557
|
+
kind: "failed",
|
|
1558
|
+
failure: {
|
|
1559
|
+
code: "NO_RESOLVER",
|
|
1560
|
+
source,
|
|
1561
|
+
message: `No resolver handled ${source}`,
|
|
1562
|
+
},
|
|
1563
|
+
};
|
|
1606
1564
|
}
|
|
1607
1565
|
|
|
1608
1566
|
async function runPreEditHandlers<Input>(
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
): Promise<StageRunOutcome<TextPreEditState<Input>>>
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
{
|
|
1620
|
-
continue;
|
|
1621
|
-
}
|
|
1567
|
+
initialState: TextPreEditState<Input>,
|
|
1568
|
+
handlers: readonly RegisteredHandler[],
|
|
1569
|
+
tool: TextEditorToolId,
|
|
1570
|
+
): Promise<StageRunOutcome<TextPreEditState<Input>>> {
|
|
1571
|
+
let state = initialState;
|
|
1572
|
+
|
|
1573
|
+
for (const registered of handlers) {
|
|
1574
|
+
if (registered.registration.stage !== "text-pre-edit") {
|
|
1575
|
+
continue;
|
|
1576
|
+
}
|
|
1622
1577
|
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
kind: "failed",
|
|
1631
|
-
failure: pluginFailure(registered.pluginId, tool, "text-pre-edit", error),
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1578
|
+
try {
|
|
1579
|
+
state = (await registered.registration.handler(state)) as TextPreEditState<Input>;
|
|
1580
|
+
} catch (error) {
|
|
1581
|
+
return {
|
|
1582
|
+
kind: "failed",
|
|
1583
|
+
failure: pluginFailure(registered.pluginId, tool, "text-pre-edit", error),
|
|
1584
|
+
};
|
|
1634
1585
|
}
|
|
1586
|
+
}
|
|
1635
1587
|
|
|
1636
|
-
|
|
1588
|
+
return { kind: "completed", state };
|
|
1637
1589
|
}
|
|
1638
1590
|
|
|
1639
1591
|
async function runResultHandlers<Input, Result>(
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
): Promise<StageRunOutcome<TextEditState<Input, Result>>>
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
{
|
|
1652
|
-
continue;
|
|
1653
|
-
}
|
|
1592
|
+
stage: "text-edit" | "text-post-edit",
|
|
1593
|
+
initialState: TextEditState<Input, Result>,
|
|
1594
|
+
handlers: readonly RegisteredHandler[],
|
|
1595
|
+
tool: TextEditorToolId,
|
|
1596
|
+
): Promise<StageRunOutcome<TextEditState<Input, Result>>> {
|
|
1597
|
+
let state = initialState;
|
|
1598
|
+
|
|
1599
|
+
for (const registered of handlers) {
|
|
1600
|
+
if (registered.registration.stage !== stage) {
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1654
1603
|
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
kind: "failed",
|
|
1663
|
-
failure: pluginFailure(registered.pluginId, tool, stage, error),
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1604
|
+
try {
|
|
1605
|
+
state = (await registered.registration.handler(state)) as TextEditState<Input, Result>;
|
|
1606
|
+
} catch (error) {
|
|
1607
|
+
return {
|
|
1608
|
+
kind: "failed",
|
|
1609
|
+
failure: pluginFailure(registered.pluginId, tool, stage, error),
|
|
1610
|
+
};
|
|
1666
1611
|
}
|
|
1612
|
+
}
|
|
1667
1613
|
|
|
1668
|
-
|
|
1614
|
+
return { kind: "completed", state };
|
|
1669
1615
|
}
|
|
1670
1616
|
|
|
1671
1617
|
function pluginFailure(
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
): TextEditPipelineFailure
|
|
1677
|
-
{
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
};
|
|
1618
|
+
pluginId: string,
|
|
1619
|
+
tool: TextEditorToolId,
|
|
1620
|
+
stage: TextEditPipelineStage,
|
|
1621
|
+
cause: unknown,
|
|
1622
|
+
): TextEditPipelineFailure {
|
|
1623
|
+
return {
|
|
1624
|
+
code: "PLUGIN_FAILED",
|
|
1625
|
+
pluginId,
|
|
1626
|
+
tool,
|
|
1627
|
+
stage,
|
|
1628
|
+
message: `Plugin ${pluginId} failed during ${stage}`,
|
|
1629
|
+
cause,
|
|
1630
|
+
};
|
|
1686
1631
|
}
|
|
1687
1632
|
|
|
1688
1633
|
function getPluginValidationError(plugin: {
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
}): Error | undefined
|
|
1693
|
-
{
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1634
|
+
readonly apiVersion: number;
|
|
1635
|
+
readonly id: string;
|
|
1636
|
+
readonly protocol: string;
|
|
1637
|
+
}): Error | undefined {
|
|
1638
|
+
if (plugin.protocol !== TEXT_EDITOR_PROTOCOL) {
|
|
1639
|
+
return new Error(`Plugin ${plugin.id} uses an unsupported protocol`);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
if (plugin.apiVersion !== TEXT_EDITOR_API_VERSION) {
|
|
1643
|
+
return new Error(`Plugin ${plugin.id} uses an unsupported API version`);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
if (plugin.id.trim().length === 0) {
|
|
1647
|
+
return new Error("Plugin ID must not be empty");
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
return undefined;
|
|
1651
|
+
}
|
|
1698
1652
|
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1653
|
+
function createPluginContributionController(
|
|
1654
|
+
pluginId: string,
|
|
1655
|
+
registerContributions: (draft: PluginContributionDraft) => void,
|
|
1656
|
+
inspectTextAnchors: (
|
|
1657
|
+
request: TextAnchorInspectionRequest,
|
|
1658
|
+
) => Promise<TextAnchorInspectionOutcome>,
|
|
1659
|
+
onMutationTool: (listener: TextMutationToolListener) => () => void,
|
|
1660
|
+
onDidEdit: (listener: TextEditCompletionListener) => () => void,
|
|
1661
|
+
previewMutation: (request: TextMutationPreviewRequest) => Promise<TextMutationPreviewOutcome>,
|
|
1662
|
+
recoveryConfig: (section: string) => TextEditorRecoveryConfigSection,
|
|
1663
|
+
): PluginContributionController {
|
|
1664
|
+
const setupDraft: PluginContributionDraft = {
|
|
1665
|
+
resolvers: [],
|
|
1666
|
+
anchorResolvers: [],
|
|
1667
|
+
presenters: [],
|
|
1668
|
+
handlers: [],
|
|
1669
|
+
promptContributions: [],
|
|
1670
|
+
writablePromptContributions: [],
|
|
1671
|
+
tools: [],
|
|
1672
|
+
mutationTools: [],
|
|
1673
|
+
mutationToolListeners: [],
|
|
1674
|
+
editCompletionListeners: [],
|
|
1675
|
+
mutationGuards: [],
|
|
1676
|
+
toolRenderers: [],
|
|
1677
|
+
};
|
|
1678
|
+
let state: "active" | "closed" | "setup" = "setup";
|
|
1679
|
+
const assertAvailable = (): void => {
|
|
1680
|
+
if (state === "closed") {
|
|
1681
|
+
throw new Error(`Plugin ${pluginId} API is closed`);
|
|
1702
1682
|
}
|
|
1683
|
+
};
|
|
1684
|
+
const createToolApi = (tool: TextEditorToolId): TextEditorToolPluginApi => ({
|
|
1685
|
+
addHandler(registration): void {
|
|
1686
|
+
assertAvailable();
|
|
1703
1687
|
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
}
|
|
1688
|
+
if (!isTextEditHandlerRegistration(registration)) {
|
|
1689
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid handler for ${tool}`);
|
|
1690
|
+
}
|
|
1708
1691
|
|
|
1709
|
-
|
|
1710
|
-
}
|
|
1692
|
+
const contribution: RegisteredHandler = { pluginId, registration, tool };
|
|
1711
1693
|
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
): PluginContributionController
|
|
1720
|
-
{
|
|
1721
|
-
const setupDraft: PluginContributionDraft = {
|
|
1694
|
+
if (state === "setup") {
|
|
1695
|
+
assertNoDraftHandler(setupDraft.handlers, contribution);
|
|
1696
|
+
setupDraft.handlers.push(contribution);
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
registerContributions({
|
|
1722
1701
|
resolvers: [],
|
|
1723
1702
|
anchorResolvers: [],
|
|
1724
|
-
|
|
1725
|
-
handlers: [],
|
|
1703
|
+
handlers: [contribution],
|
|
1726
1704
|
promptContributions: [],
|
|
1727
1705
|
writablePromptContributions: [],
|
|
1728
1706
|
tools: [],
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
if (state === "closed")
|
|
1739
|
-
{
|
|
1740
|
-
throw new Error(`Plugin ${pluginId} API is closed`);
|
|
1741
|
-
}
|
|
1742
|
-
};
|
|
1743
|
-
const createToolApi = (tool: TextEditorToolId): TextEditorToolPluginApi => ({
|
|
1744
|
-
addHandler(registration): void
|
|
1745
|
-
{
|
|
1746
|
-
assertAvailable();
|
|
1747
|
-
|
|
1748
|
-
if (!isTextEditHandlerRegistration(registration))
|
|
1749
|
-
{
|
|
1750
|
-
throw new TypeError(`Plugin ${pluginId} provided an invalid handler for ${tool}`);
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
const contribution: RegisteredHandler = { pluginId, registration, tool };
|
|
1754
|
-
|
|
1755
|
-
if (state === "setup")
|
|
1756
|
-
{
|
|
1757
|
-
assertNoDraftHandler(setupDraft.handlers, contribution);
|
|
1758
|
-
setupDraft.handlers.push(contribution);
|
|
1759
|
-
return;
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
registerContributions({
|
|
1763
|
-
resolvers: [],
|
|
1764
|
-
anchorResolvers: [],
|
|
1765
|
-
handlers: [contribution],
|
|
1766
|
-
promptContributions: [],
|
|
1767
|
-
writablePromptContributions: [],
|
|
1768
|
-
tools: [],
|
|
1769
|
-
});
|
|
1770
|
-
},
|
|
1771
|
-
describe(description): void
|
|
1772
|
-
{
|
|
1773
|
-
assertAvailable();
|
|
1774
|
-
const contribution: PromptContribution = {
|
|
1775
|
-
description: normalizeDescription(`Plugin prompt description for ${tool}`, description),
|
|
1776
|
-
pluginId,
|
|
1777
|
-
tool,
|
|
1778
|
-
};
|
|
1779
|
-
|
|
1780
|
-
if (state === "setup")
|
|
1781
|
-
{
|
|
1782
|
-
assertNoDraftDescription(setupDraft.promptContributions, contribution);
|
|
1783
|
-
setupDraft.promptContributions.push(contribution);
|
|
1784
|
-
return;
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
registerContributions({
|
|
1788
|
-
resolvers: [],
|
|
1789
|
-
anchorResolvers: [],
|
|
1790
|
-
handlers: [],
|
|
1791
|
-
promptContributions: [contribution],
|
|
1792
|
-
writablePromptContributions: [],
|
|
1793
|
-
tools: [],
|
|
1794
|
-
});
|
|
1795
|
-
},
|
|
1796
|
-
});
|
|
1797
|
-
const api: TextEditorPluginApi = {
|
|
1798
|
-
addMutationTool(registration): void
|
|
1799
|
-
{
|
|
1800
|
-
assertAvailable();
|
|
1801
|
-
assertTextMutationToolRegistration(registration);
|
|
1802
|
-
|
|
1803
|
-
if (state === "setup")
|
|
1804
|
-
{
|
|
1805
|
-
setupDraft.mutationTools!.push(registration);
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
registerContributions({
|
|
1810
|
-
resolvers: [],
|
|
1811
|
-
anchorResolvers: [],
|
|
1812
|
-
handlers: [],
|
|
1813
|
-
promptContributions: [],
|
|
1814
|
-
writablePromptContributions: [],
|
|
1815
|
-
tools: [],
|
|
1816
|
-
mutationTools: [registration],
|
|
1817
|
-
});
|
|
1818
|
-
},
|
|
1819
|
-
addToolRenderer(registration): void
|
|
1820
|
-
{
|
|
1821
|
-
assertAvailable();
|
|
1822
|
-
|
|
1823
|
-
if (!isTextEditorToolRendererRegistration(registration))
|
|
1824
|
-
{
|
|
1825
|
-
throw new TypeError(`Plugin ${pluginId} provided an invalid text editor tool renderer`);
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
if (state === "setup")
|
|
1829
|
-
{
|
|
1830
|
-
setupDraft.toolRenderers!.push(registration);
|
|
1831
|
-
return;
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
registerContributions({
|
|
1835
|
-
resolvers: [],
|
|
1836
|
-
anchorResolvers: [],
|
|
1837
|
-
handlers: [],
|
|
1838
|
-
promptContributions: [],
|
|
1839
|
-
writablePromptContributions: [],
|
|
1840
|
-
tools: [],
|
|
1841
|
-
toolRenderers: [registration],
|
|
1842
|
-
});
|
|
1843
|
-
},
|
|
1844
|
-
addMutationGuard(registration): void
|
|
1845
|
-
{
|
|
1846
|
-
assertAvailable();
|
|
1847
|
-
|
|
1848
|
-
if (registration.id.trim().length === 0 || typeof registration.guard !== "function")
|
|
1849
|
-
{
|
|
1850
|
-
throw new TypeError(`Plugin ${pluginId} provided an invalid mutation guard`);
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
if (state === "setup")
|
|
1854
|
-
{
|
|
1855
|
-
setupDraft.mutationGuards!.push(registration);
|
|
1856
|
-
return;
|
|
1857
|
-
}
|
|
1858
|
-
|
|
1859
|
-
registerContributions({
|
|
1860
|
-
resolvers: [],
|
|
1861
|
-
anchorResolvers: [],
|
|
1862
|
-
handlers: [],
|
|
1863
|
-
promptContributions: [],
|
|
1864
|
-
writablePromptContributions: [],
|
|
1865
|
-
tools: [],
|
|
1866
|
-
mutationGuards: [registration],
|
|
1867
|
-
});
|
|
1868
|
-
},
|
|
1869
|
-
onMutationTool(listener): () => void
|
|
1870
|
-
{
|
|
1871
|
-
assertAvailable();
|
|
1872
|
-
|
|
1873
|
-
if (state === "setup")
|
|
1874
|
-
{
|
|
1875
|
-
setupDraft.mutationToolListeners!.push(listener);
|
|
1876
|
-
return () =>
|
|
1877
|
-
{
|
|
1878
|
-
const index = setupDraft.mutationToolListeners!.indexOf(listener);
|
|
1879
|
-
|
|
1880
|
-
if (index !== -1)
|
|
1881
|
-
{
|
|
1882
|
-
setupDraft.mutationToolListeners!.splice(index, 1);
|
|
1883
|
-
}
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
return onMutationTool(listener);
|
|
1888
|
-
},
|
|
1889
|
-
onDidEdit(listener): () => void
|
|
1890
|
-
{
|
|
1891
|
-
assertAvailable();
|
|
1707
|
+
});
|
|
1708
|
+
},
|
|
1709
|
+
describe(description): void {
|
|
1710
|
+
assertAvailable();
|
|
1711
|
+
const contribution: PromptContribution = {
|
|
1712
|
+
description: normalizeDescription(`Plugin prompt description for ${tool}`, description),
|
|
1713
|
+
pluginId,
|
|
1714
|
+
tool,
|
|
1715
|
+
};
|
|
1892
1716
|
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1717
|
+
if (state === "setup") {
|
|
1718
|
+
assertNoDraftDescription(setupDraft.promptContributions, contribution);
|
|
1719
|
+
setupDraft.promptContributions.push(contribution);
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1897
1722
|
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1723
|
+
registerContributions({
|
|
1724
|
+
resolvers: [],
|
|
1725
|
+
anchorResolvers: [],
|
|
1726
|
+
handlers: [],
|
|
1727
|
+
promptContributions: [contribution],
|
|
1728
|
+
writablePromptContributions: [],
|
|
1729
|
+
tools: [],
|
|
1730
|
+
});
|
|
1731
|
+
},
|
|
1732
|
+
});
|
|
1733
|
+
const api: TextEditorPluginApi = {
|
|
1734
|
+
addMutationTool(registration): void {
|
|
1735
|
+
assertAvailable();
|
|
1736
|
+
assertTextMutationToolRegistration(registration);
|
|
1737
|
+
|
|
1738
|
+
if (state === "setup") {
|
|
1739
|
+
requiredValue(setupDraft.mutationTools).push(registration);
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
registerContributions({
|
|
1744
|
+
resolvers: [],
|
|
1745
|
+
anchorResolvers: [],
|
|
1746
|
+
handlers: [],
|
|
1747
|
+
promptContributions: [],
|
|
1748
|
+
writablePromptContributions: [],
|
|
1749
|
+
tools: [],
|
|
1750
|
+
mutationTools: [registration],
|
|
1751
|
+
});
|
|
1752
|
+
},
|
|
1753
|
+
addToolRenderer(registration): void {
|
|
1754
|
+
assertAvailable();
|
|
1755
|
+
|
|
1756
|
+
if (!isTextEditorToolRendererRegistration(registration)) {
|
|
1757
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid text editor tool renderer`);
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
if (state === "setup") {
|
|
1761
|
+
requiredValue(setupDraft.toolRenderers).push(registration);
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
registerContributions({
|
|
1766
|
+
resolvers: [],
|
|
1767
|
+
anchorResolvers: [],
|
|
1768
|
+
handlers: [],
|
|
1769
|
+
promptContributions: [],
|
|
1770
|
+
writablePromptContributions: [],
|
|
1771
|
+
tools: [],
|
|
1772
|
+
toolRenderers: [registration],
|
|
1773
|
+
});
|
|
1774
|
+
},
|
|
1775
|
+
addMutationGuard(registration): void {
|
|
1776
|
+
assertAvailable();
|
|
1777
|
+
|
|
1778
|
+
if (registration.id.trim().length === 0 || typeof registration.guard !== "function") {
|
|
1779
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid mutation guard`);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
if (state === "setup") {
|
|
1783
|
+
requiredValue(setupDraft.mutationGuards).push(registration);
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
registerContributions({
|
|
1788
|
+
resolvers: [],
|
|
1789
|
+
anchorResolvers: [],
|
|
1790
|
+
handlers: [],
|
|
1791
|
+
promptContributions: [],
|
|
1792
|
+
writablePromptContributions: [],
|
|
1793
|
+
tools: [],
|
|
1794
|
+
mutationGuards: [registration],
|
|
1795
|
+
});
|
|
1796
|
+
},
|
|
1797
|
+
onMutationTool(listener): () => void {
|
|
1798
|
+
assertAvailable();
|
|
1799
|
+
|
|
1800
|
+
if (state === "setup") {
|
|
1801
|
+
requiredValue(setupDraft.mutationToolListeners).push(listener);
|
|
1802
|
+
return () => {
|
|
1803
|
+
const index = requiredValue(setupDraft.mutationToolListeners).indexOf(listener);
|
|
1804
|
+
|
|
1805
|
+
if (index !== -1) {
|
|
1806
|
+
requiredValue(setupDraft.mutationToolListeners).splice(index, 1);
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
}
|
|
1927
1810
|
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1811
|
+
return onMutationTool(listener);
|
|
1812
|
+
},
|
|
1813
|
+
onDidEdit(listener): () => void {
|
|
1814
|
+
assertAvailable();
|
|
1932
1815
|
|
|
1933
|
-
|
|
1816
|
+
if (typeof listener !== "function") {
|
|
1817
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid edit completion listener`);
|
|
1818
|
+
}
|
|
1934
1819
|
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
return;
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
registerContributions({
|
|
1943
|
-
resolvers: [contribution],
|
|
1944
|
-
anchorResolvers: [],
|
|
1945
|
-
handlers: [],
|
|
1946
|
-
promptContributions: [],
|
|
1947
|
-
writablePromptContributions: [],
|
|
1948
|
-
tools: [],
|
|
1949
|
-
});
|
|
1950
|
-
},
|
|
1951
|
-
addAnchorResolver(registration): void
|
|
1952
|
-
{
|
|
1953
|
-
assertAvailable();
|
|
1820
|
+
if (state === "setup") {
|
|
1821
|
+
requiredValue(setupDraft.editCompletionListeners).push(listener);
|
|
1822
|
+
return () => {
|
|
1823
|
+
const index = requiredValue(setupDraft.editCompletionListeners).indexOf(listener);
|
|
1954
1824
|
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1825
|
+
if (index !== -1) {
|
|
1826
|
+
requiredValue(setupDraft.editCompletionListeners).splice(index, 1);
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
return onDidEdit(listener);
|
|
1832
|
+
},
|
|
1833
|
+
inspectTextAnchors(request): Promise<TextAnchorInspectionOutcome> {
|
|
1834
|
+
assertAvailable();
|
|
1835
|
+
return inspectTextAnchors(request);
|
|
1836
|
+
},
|
|
1837
|
+
recoveryConfig(section): TextEditorRecoveryConfigSection {
|
|
1838
|
+
assertAvailable();
|
|
1839
|
+
return recoveryConfig(section);
|
|
1840
|
+
},
|
|
1841
|
+
previewMutation(request): Promise<TextMutationPreviewOutcome> {
|
|
1842
|
+
assertAvailable();
|
|
1843
|
+
return previewMutation(request);
|
|
1844
|
+
},
|
|
1845
|
+
addResolver(registration): void {
|
|
1846
|
+
assertAvailable();
|
|
1847
|
+
|
|
1848
|
+
if (!isResourceResolverRegistration(registration)) {
|
|
1849
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid resource resolver`);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
const contribution: ResolverContribution = { pluginId, registration };
|
|
1853
|
+
|
|
1854
|
+
if (state === "setup") {
|
|
1855
|
+
assertNoDraftResolver(setupDraft.resolvers, contribution);
|
|
1856
|
+
setupDraft.resolvers.push(contribution);
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
registerContributions({
|
|
1861
|
+
resolvers: [contribution],
|
|
1862
|
+
anchorResolvers: [],
|
|
1863
|
+
handlers: [],
|
|
1864
|
+
promptContributions: [],
|
|
1865
|
+
writablePromptContributions: [],
|
|
1866
|
+
tools: [],
|
|
1867
|
+
});
|
|
1868
|
+
},
|
|
1869
|
+
addAnchorResolver(registration): void {
|
|
1870
|
+
assertAvailable();
|
|
1959
1871
|
|
|
1960
|
-
|
|
1872
|
+
if (!isTextAnchorResolverRegistration(registration)) {
|
|
1873
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid text anchor resolver`);
|
|
1874
|
+
}
|
|
1961
1875
|
|
|
1962
|
-
|
|
1963
|
-
{
|
|
1964
|
-
setupDraft.anchorResolvers.push(contribution);
|
|
1965
|
-
return;
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
registerContributions({
|
|
1969
|
-
resolvers: [],
|
|
1970
|
-
anchorResolvers: [contribution],
|
|
1971
|
-
handlers: [],
|
|
1972
|
-
promptContributions: [],
|
|
1973
|
-
writablePromptContributions: [],
|
|
1974
|
-
tools: [],
|
|
1975
|
-
});
|
|
1976
|
-
},
|
|
1977
|
-
addTextPresenter(registration): void
|
|
1978
|
-
{
|
|
1979
|
-
assertAvailable();
|
|
1876
|
+
const contribution: TextAnchorResolverContribution = { pluginId, registration };
|
|
1980
1877
|
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1878
|
+
if (state === "setup") {
|
|
1879
|
+
setupDraft.anchorResolvers.push(contribution);
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1985
1882
|
|
|
1986
|
-
|
|
1883
|
+
registerContributions({
|
|
1884
|
+
resolvers: [],
|
|
1885
|
+
anchorResolvers: [contribution],
|
|
1886
|
+
handlers: [],
|
|
1887
|
+
promptContributions: [],
|
|
1888
|
+
writablePromptContributions: [],
|
|
1889
|
+
tools: [],
|
|
1890
|
+
});
|
|
1891
|
+
},
|
|
1892
|
+
addTextPresenter(registration): void {
|
|
1893
|
+
assertAvailable();
|
|
1987
1894
|
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
return;
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
registerContributions({
|
|
1995
|
-
resolvers: [],
|
|
1996
|
-
anchorResolvers: [],
|
|
1997
|
-
presenters: [contribution],
|
|
1998
|
-
handlers: [],
|
|
1999
|
-
promptContributions: [],
|
|
2000
|
-
writablePromptContributions: [],
|
|
2001
|
-
tools: [],
|
|
2002
|
-
});
|
|
2003
|
-
},
|
|
2004
|
-
describe(description): void
|
|
2005
|
-
{
|
|
2006
|
-
assertAvailable();
|
|
1895
|
+
if (!isTextPresenterRegistration(registration)) {
|
|
1896
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid text presenter`);
|
|
1897
|
+
}
|
|
2007
1898
|
|
|
2008
|
-
|
|
2009
|
-
{
|
|
2010
|
-
throw new Error(`Plugin ${pluginId} provides more than one writable resource description`);
|
|
2011
|
-
}
|
|
1899
|
+
const contribution: TextPresenterContribution = { pluginId, registration };
|
|
2012
1900
|
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
1901
|
+
if (state === "setup") {
|
|
1902
|
+
requiredValue(setupDraft.presenters).push(contribution);
|
|
1903
|
+
return;
|
|
1904
|
+
}
|
|
2017
1905
|
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
tools: [],
|
|
2031
|
-
});
|
|
2032
|
-
},
|
|
2033
|
-
tool(tool): TextEditorToolPluginApi
|
|
2034
|
-
{
|
|
2035
|
-
assertAvailable();
|
|
1906
|
+
registerContributions({
|
|
1907
|
+
resolvers: [],
|
|
1908
|
+
anchorResolvers: [],
|
|
1909
|
+
presenters: [contribution],
|
|
1910
|
+
handlers: [],
|
|
1911
|
+
promptContributions: [],
|
|
1912
|
+
writablePromptContributions: [],
|
|
1913
|
+
tools: [],
|
|
1914
|
+
});
|
|
1915
|
+
},
|
|
1916
|
+
describe(description): void {
|
|
1917
|
+
assertAvailable();
|
|
2036
1918
|
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
}
|
|
1919
|
+
if (setupDraft.writablePromptContributions.length > 0) {
|
|
1920
|
+
throw new Error(`Plugin ${pluginId} provides more than one writable resource description`);
|
|
1921
|
+
}
|
|
2041
1922
|
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
setupDraft.tools.push(tool);
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
else
|
|
2050
|
-
{
|
|
2051
|
-
registerContributions({
|
|
2052
|
-
resolvers: [],
|
|
2053
|
-
anchorResolvers: [],
|
|
2054
|
-
handlers: [],
|
|
2055
|
-
promptContributions: [],
|
|
2056
|
-
writablePromptContributions: [],
|
|
2057
|
-
tools: [tool],
|
|
2058
|
-
});
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
return createToolApi(tool);
|
|
2062
|
-
},
|
|
2063
|
-
};
|
|
1923
|
+
const contribution: WritablePromptContribution = {
|
|
1924
|
+
description: normalizeDescriptionSource(description),
|
|
1925
|
+
pluginId,
|
|
1926
|
+
};
|
|
2064
1927
|
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
state = "closed";
|
|
2070
|
-
},
|
|
2071
|
-
commit(): void
|
|
2072
|
-
{
|
|
2073
|
-
if (state !== "setup")
|
|
2074
|
-
{
|
|
2075
|
-
throw new Error(`Plugin ${pluginId} setup contributions cannot be committed`);
|
|
2076
|
-
}
|
|
1928
|
+
if (state === "setup") {
|
|
1929
|
+
setupDraft.writablePromptContributions.push(contribution);
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
2077
1932
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
1933
|
+
registerContributions({
|
|
1934
|
+
resolvers: [],
|
|
1935
|
+
anchorResolvers: [],
|
|
1936
|
+
handlers: [],
|
|
1937
|
+
promptContributions: [],
|
|
1938
|
+
writablePromptContributions: [contribution],
|
|
1939
|
+
tools: [],
|
|
1940
|
+
});
|
|
1941
|
+
},
|
|
1942
|
+
tool(tool): TextEditorToolPluginApi {
|
|
1943
|
+
assertAvailable();
|
|
1944
|
+
|
|
1945
|
+
if (!isTextEditorToolId(tool)) {
|
|
1946
|
+
throw new Error(`Plugin ${pluginId} provided an invalid tool ID`);
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
if (state === "setup") {
|
|
1950
|
+
if (!setupDraft.tools.includes(tool)) {
|
|
1951
|
+
setupDraft.tools.push(tool);
|
|
1952
|
+
}
|
|
1953
|
+
} else {
|
|
1954
|
+
registerContributions({
|
|
1955
|
+
resolvers: [],
|
|
1956
|
+
anchorResolvers: [],
|
|
1957
|
+
handlers: [],
|
|
1958
|
+
promptContributions: [],
|
|
1959
|
+
writablePromptContributions: [],
|
|
1960
|
+
tools: [tool],
|
|
1961
|
+
});
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
return createToolApi(tool);
|
|
1965
|
+
},
|
|
1966
|
+
};
|
|
1967
|
+
|
|
1968
|
+
return {
|
|
1969
|
+
api,
|
|
1970
|
+
close(): void {
|
|
1971
|
+
state = "closed";
|
|
1972
|
+
},
|
|
1973
|
+
commit(): void {
|
|
1974
|
+
if (state !== "setup") {
|
|
1975
|
+
throw new Error(`Plugin ${pluginId} setup contributions cannot be committed`);
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
registerContributions(setupDraft);
|
|
1979
|
+
state = "active";
|
|
1980
|
+
},
|
|
1981
|
+
};
|
|
2082
1982
|
}
|
|
2083
1983
|
|
|
2084
1984
|
function validateContributionDraft(
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
): void
|
|
2091
|
-
{
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
{
|
|
2098
|
-
throw new TypeError(`Plugin ${contribution.pluginId} provided an invalid resource resolver`);
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
|
-
const resolverId = contribution.registration.resolver.id;
|
|
1985
|
+
draft: PluginContributionDraft,
|
|
1986
|
+
registeredResolvers: readonly RegisteredResolver[],
|
|
1987
|
+
registeredHandlers: readonly RegisteredHandler[],
|
|
1988
|
+
registeredPromptContributions: readonly PromptContribution[],
|
|
1989
|
+
registeredWritablePromptContributions: readonly WritablePromptContribution[],
|
|
1990
|
+
): void {
|
|
1991
|
+
const resolverIds = new Set(registeredResolvers.map(({ resolver }) => resolver.id));
|
|
1992
|
+
|
|
1993
|
+
for (const contribution of draft.resolvers) {
|
|
1994
|
+
if (!isResourceResolverRegistration(contribution.registration)) {
|
|
1995
|
+
throw new TypeError(`Plugin ${contribution.pluginId} provided an invalid resource resolver`);
|
|
1996
|
+
}
|
|
2102
1997
|
|
|
2103
|
-
|
|
2104
|
-
{
|
|
2105
|
-
throw new Error(`Resource resolver ${resolverId} is already registered`);
|
|
2106
|
-
}
|
|
1998
|
+
const resolverId = contribution.registration.resolver.id;
|
|
2107
1999
|
|
|
2108
|
-
|
|
2000
|
+
if (resolverIds.has(resolverId)) {
|
|
2001
|
+
throw new Error(`Resource resolver ${resolverId} is already registered`);
|
|
2109
2002
|
}
|
|
2110
2003
|
|
|
2111
|
-
|
|
2004
|
+
resolverIds.add(resolverId);
|
|
2005
|
+
}
|
|
2112
2006
|
|
|
2113
|
-
|
|
2114
|
-
{
|
|
2115
|
-
if (!isTextEditHandlerRegistration(handler.registration))
|
|
2116
|
-
{
|
|
2117
|
-
throw new TypeError(`Plugin ${handler.pluginId} provided an invalid handler for ${handler.tool}`);
|
|
2118
|
-
}
|
|
2007
|
+
const handlerKeys = new Set(registeredHandlers.map(handlerKey));
|
|
2119
2008
|
|
|
2120
|
-
|
|
2009
|
+
for (const handler of draft.handlers) {
|
|
2010
|
+
if (!isTextEditHandlerRegistration(handler.registration)) {
|
|
2011
|
+
throw new TypeError(
|
|
2012
|
+
`Plugin ${handler.pluginId} provided an invalid handler for ${handler.tool}`,
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2121
2015
|
|
|
2122
|
-
|
|
2123
|
-
{
|
|
2124
|
-
throw new Error(
|
|
2125
|
-
`Plugin ${handler.pluginId} already handles ${handler.registration.stage} for ${handler.tool}`,
|
|
2126
|
-
);
|
|
2127
|
-
}
|
|
2016
|
+
const key = handlerKey(handler);
|
|
2128
2017
|
|
|
2129
|
-
|
|
2018
|
+
if (handlerKeys.has(key)) {
|
|
2019
|
+
throw new Error(
|
|
2020
|
+
`Plugin ${handler.pluginId} already handles ${handler.registration.stage} for ${handler.tool}`,
|
|
2021
|
+
);
|
|
2130
2022
|
}
|
|
2131
2023
|
|
|
2132
|
-
|
|
2024
|
+
handlerKeys.add(key);
|
|
2025
|
+
}
|
|
2133
2026
|
|
|
2134
|
-
|
|
2135
|
-
{
|
|
2136
|
-
const key = descriptionKey(contribution);
|
|
2027
|
+
const descriptionKeys = new Set(registeredPromptContributions.map(descriptionKey));
|
|
2137
2028
|
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
throw new Error(`Plugin ${contribution.pluginId} describes ${contribution.tool} more than once`);
|
|
2141
|
-
}
|
|
2029
|
+
for (const contribution of draft.promptContributions) {
|
|
2030
|
+
const key = descriptionKey(contribution);
|
|
2142
2031
|
|
|
2143
|
-
|
|
2032
|
+
if (descriptionKeys.has(key)) {
|
|
2033
|
+
throw new Error(
|
|
2034
|
+
`Plugin ${contribution.pluginId} describes ${contribution.tool} more than once`,
|
|
2035
|
+
);
|
|
2144
2036
|
}
|
|
2145
2037
|
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
);
|
|
2038
|
+
descriptionKeys.add(key);
|
|
2039
|
+
}
|
|
2149
2040
|
|
|
2150
|
-
|
|
2151
|
-
{
|
|
2152
|
-
|
|
2153
|
-
{
|
|
2154
|
-
throw new Error(
|
|
2155
|
-
`Plugin ${contribution.pluginId} provides more than one writable resource description`,
|
|
2156
|
-
);
|
|
2157
|
-
}
|
|
2041
|
+
const writablePluginIds = new Set(
|
|
2042
|
+
registeredWritablePromptContributions.map(({ pluginId }) => pluginId),
|
|
2043
|
+
);
|
|
2158
2044
|
|
|
2159
|
-
|
|
2045
|
+
for (const contribution of draft.writablePromptContributions) {
|
|
2046
|
+
if (writablePluginIds.has(contribution.pluginId)) {
|
|
2047
|
+
throw new Error(
|
|
2048
|
+
`Plugin ${contribution.pluginId} provides more than one writable resource description`,
|
|
2049
|
+
);
|
|
2160
2050
|
}
|
|
2161
2051
|
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2052
|
+
writablePluginIds.add(contribution.pluginId);
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
for (const tool of draft.tools) {
|
|
2056
|
+
if (!isTextEditorToolId(tool)) {
|
|
2057
|
+
throw new TypeError("Plugin provided an invalid tool ID");
|
|
2168
2058
|
}
|
|
2059
|
+
}
|
|
2169
2060
|
}
|
|
2170
2061
|
|
|
2171
2062
|
function assertNoDraftResolver(
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
): void
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
throw new Error(`Resource resolver ${resolverId} is already registered`);
|
|
2181
|
-
}
|
|
2063
|
+
resolvers: readonly ResolverContribution[],
|
|
2064
|
+
incoming: ResolverContribution,
|
|
2065
|
+
): void {
|
|
2066
|
+
const resolverId = incoming.registration.resolver.id;
|
|
2067
|
+
|
|
2068
|
+
if (resolvers.some((resolver) => resolver.registration.resolver.id === resolverId)) {
|
|
2069
|
+
throw new Error(`Resource resolver ${resolverId} is already registered`);
|
|
2070
|
+
}
|
|
2182
2071
|
}
|
|
2183
2072
|
|
|
2184
2073
|
function assertNoDraftHandler(
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
): void
|
|
2188
|
-
{
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
);
|
|
2194
|
-
}
|
|
2074
|
+
handlers: readonly RegisteredHandler[],
|
|
2075
|
+
incoming: RegisteredHandler,
|
|
2076
|
+
): void {
|
|
2077
|
+
if (handlers.some((handler) => handlerKey(handler) === handlerKey(incoming))) {
|
|
2078
|
+
throw new Error(
|
|
2079
|
+
`Plugin ${incoming.pluginId} already handles ${incoming.registration.stage} for ${incoming.tool}`,
|
|
2080
|
+
);
|
|
2081
|
+
}
|
|
2195
2082
|
}
|
|
2196
2083
|
|
|
2197
2084
|
function assertNoDraftDescription(
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
): void
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2085
|
+
contributions: readonly PromptContribution[],
|
|
2086
|
+
incoming: PromptContribution,
|
|
2087
|
+
): void {
|
|
2088
|
+
if (
|
|
2089
|
+
contributions.some((contribution) => descriptionKey(contribution) === descriptionKey(incoming))
|
|
2090
|
+
) {
|
|
2091
|
+
throw new Error(`Plugin ${incoming.pluginId} describes ${incoming.tool} more than once`);
|
|
2092
|
+
}
|
|
2206
2093
|
}
|
|
2207
2094
|
|
|
2208
|
-
function handlerKey(handler: RegisteredHandler): string
|
|
2209
|
-
{
|
|
2210
|
-
return `${handler.pluginId}\0${handler.tool}\0${handler.registration.stage}`;
|
|
2095
|
+
function handlerKey(handler: RegisteredHandler): string {
|
|
2096
|
+
return `${handler.pluginId}\0${handler.tool}\0${handler.registration.stage}`;
|
|
2211
2097
|
}
|
|
2212
2098
|
|
|
2213
|
-
function descriptionKey(contribution: PromptContribution): string
|
|
2214
|
-
{
|
|
2215
|
-
return `${contribution.pluginId}\0${contribution.tool}`;
|
|
2099
|
+
function descriptionKey(contribution: PromptContribution): string {
|
|
2100
|
+
return `${contribution.pluginId}\0${contribution.tool}`;
|
|
2216
2101
|
}
|
|
2217
2102
|
|
|
2218
|
-
function normalizeDescriptionSource(value: unknown): PromptDescriptionSource
|
|
2219
|
-
{
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
return normalizeDescription("Writable resource prompt description", value);
|
|
2223
|
-
}
|
|
2103
|
+
function normalizeDescriptionSource(value: unknown): PromptDescriptionSource {
|
|
2104
|
+
if (typeof value === "string") {
|
|
2105
|
+
return normalizeDescription("Writable resource prompt description", value);
|
|
2106
|
+
}
|
|
2224
2107
|
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
}
|
|
2108
|
+
if (typeof value === "function") {
|
|
2109
|
+
return value as () => string | undefined;
|
|
2110
|
+
}
|
|
2229
2111
|
|
|
2230
|
-
|
|
2112
|
+
throw new TypeError("Writable resource prompt description must be a string or callback");
|
|
2231
2113
|
}
|
|
2232
2114
|
|
|
2233
|
-
function renderDescriptionSource(source: PromptDescriptionSource): string | undefined
|
|
2234
|
-
{
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
return source;
|
|
2238
|
-
}
|
|
2115
|
+
function renderDescriptionSource(source: PromptDescriptionSource): string | undefined {
|
|
2116
|
+
if (typeof source === "string") {
|
|
2117
|
+
return source;
|
|
2118
|
+
}
|
|
2239
2119
|
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2120
|
+
const value: unknown = source();
|
|
2121
|
+
return value === undefined
|
|
2122
|
+
? undefined
|
|
2123
|
+
: normalizeDescription("Writable resource prompt description", value);
|
|
2244
2124
|
}
|
|
2245
2125
|
|
|
2246
|
-
function normalizeDescription(label: string, value: unknown): string
|
|
2247
|
-
{
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
throw new TypeError(`${label} must be a string`);
|
|
2251
|
-
}
|
|
2126
|
+
function normalizeDescription(label: string, value: unknown): string {
|
|
2127
|
+
if (typeof value !== "string") {
|
|
2128
|
+
throw new TypeError(`${label} must be a string`);
|
|
2129
|
+
}
|
|
2252
2130
|
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2131
|
+
const lines = value
|
|
2132
|
+
.replaceAll("\r\n", "\n")
|
|
2133
|
+
.replaceAll("\r", "\n")
|
|
2134
|
+
.split("\n")
|
|
2135
|
+
.map((line) => line.trimEnd());
|
|
2258
2136
|
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
}
|
|
2137
|
+
while (lines[0]?.trim().length === 0) {
|
|
2138
|
+
lines.shift();
|
|
2139
|
+
}
|
|
2263
2140
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
}
|
|
2141
|
+
while (lines.at(-1)?.trim().length === 0) {
|
|
2142
|
+
lines.pop();
|
|
2143
|
+
}
|
|
2268
2144
|
|
|
2269
|
-
|
|
2145
|
+
const description = lines.join("\n");
|
|
2270
2146
|
|
|
2271
|
-
|
|
2272
|
-
{
|
|
2273
|
-
|
|
2274
|
-
}
|
|
2147
|
+
if (description.trim().length === 0) {
|
|
2148
|
+
throw new Error(`${label} is empty`);
|
|
2149
|
+
}
|
|
2275
2150
|
|
|
2276
|
-
|
|
2151
|
+
return description;
|
|
2277
2152
|
}
|
|
2278
2153
|
|
|
2279
|
-
function renderPromptEntry(pluginId: string, description: string): string
|
|
2280
|
-
|
|
2281
|
-
const [firstLine, ...continuationLines] = description.split("\n");
|
|
2154
|
+
function renderPromptEntry(pluginId: string, description: string): string {
|
|
2155
|
+
const [firstLine, ...continuationLines] = description.split("\n");
|
|
2282
2156
|
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2157
|
+
return [
|
|
2158
|
+
`- \`${escapeInlineCode(pluginId)}\` — ${firstLine ?? ""}`,
|
|
2159
|
+
...continuationLines.map((line) => ` ${line}`),
|
|
2160
|
+
].join("\n");
|
|
2287
2161
|
}
|
|
2288
2162
|
|
|
2289
|
-
function indentGuidelineContinuation(guideline: string): string
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2163
|
+
function indentGuidelineContinuation(guideline: string): string {
|
|
2164
|
+
const [firstLine, ...continuationLines] = guideline.split("\n");
|
|
2165
|
+
return [
|
|
2166
|
+
firstLine ?? "",
|
|
2167
|
+
...continuationLines.map((line) => (line.length === 0 ? line : ` ${line}`)),
|
|
2168
|
+
].join("\n");
|
|
2293
2169
|
}
|
|
2294
2170
|
|
|
2295
|
-
function escapeInlineCode(value: string): string
|
|
2296
|
-
|
|
2297
|
-
return value.replaceAll("`", "\\`");
|
|
2171
|
+
function escapeInlineCode(value: string): string {
|
|
2172
|
+
return value.replaceAll("`", "\\`");
|
|
2298
2173
|
}
|
|
2299
2174
|
|
|
2300
2175
|
function mergeToolRenderer(
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
): TextEditorToolRendererRegistration
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2176
|
+
current: TextEditorToolRendererRegistration | undefined,
|
|
2177
|
+
registration: TextEditorToolRendererRegistration,
|
|
2178
|
+
): TextEditorToolRendererRegistration {
|
|
2179
|
+
const merged =
|
|
2180
|
+
registration.fallback === true
|
|
2181
|
+
? { ...registration, ...current, tool: registration.tool }
|
|
2182
|
+
: { ...current, ...registration, tool: registration.tool };
|
|
2183
|
+
const { fallback: _fallback, ...renderer } = merged;
|
|
2184
|
+
return renderer;
|
|
2310
2185
|
}
|
|
2311
2186
|
|
|
2312
2187
|
function replayMutationTools(
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
): void
|
|
2316
|
-
{
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
listener(registration);
|
|
2320
|
-
}
|
|
2188
|
+
listener: TextMutationToolListener,
|
|
2189
|
+
mutationTools: ReadonlyMap<string, AnyTextMutationToolRegistration>,
|
|
2190
|
+
): void {
|
|
2191
|
+
for (const registration of mutationTools.values()) {
|
|
2192
|
+
listener(registration);
|
|
2193
|
+
}
|
|
2321
2194
|
}
|
|
2322
2195
|
|
|
2323
2196
|
function addMutationRegistration(
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
core: TextEditorCore
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
registerMutationTool?.(registration, core);
|
|
2197
|
+
registration: AnyTextMutationToolRegistration,
|
|
2198
|
+
mutationTools: Map<string, AnyTextMutationToolRegistration>,
|
|
2199
|
+
registeredTools: Set<TextEditorToolId>,
|
|
2200
|
+
listeners: Set<TextMutationToolListener>,
|
|
2201
|
+
registerMutationTool:
|
|
2202
|
+
| ((registration: AnyTextMutationToolRegistration, core: TextEditorCore) => void)
|
|
2203
|
+
| undefined,
|
|
2204
|
+
core: TextEditorCore,
|
|
2205
|
+
): void {
|
|
2206
|
+
assertTextMutationToolRegistration(registration);
|
|
2207
|
+
|
|
2208
|
+
if (mutationTools.has(registration.name)) {
|
|
2209
|
+
throw new Error(`Mutation tool ${registration.name} is already registered`);
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
mutationTools.set(registration.name, registration);
|
|
2213
|
+
registeredTools.add(registration.name);
|
|
2214
|
+
|
|
2215
|
+
for (const listener of listeners) {
|
|
2216
|
+
listener(registration);
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
registerMutationTool?.(registration, core);
|
|
2348
2220
|
}
|