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,756 +1,1165 @@
|
|
|
1
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
1
2
|
import path from "node:path";
|
|
3
|
+
import type {
|
|
4
|
+
TextAnchorRecoveryCandidateRange,
|
|
5
|
+
TextAnchorRecoveryRange,
|
|
6
|
+
TextAnchorRejection,
|
|
7
|
+
TextSelectionRange,
|
|
8
|
+
TextTarget,
|
|
9
|
+
} from "pi-agent-text";
|
|
2
10
|
|
|
3
11
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
type AgentToolResult,
|
|
13
|
+
defineTool,
|
|
14
|
+
type ExtensionContext,
|
|
15
|
+
type ToolDefinition,
|
|
8
16
|
} from "@earendil-works/pi-coding-agent";
|
|
9
17
|
|
|
10
|
-
import { type FileMutationBatchResult, FileMutationResult } from "#src/api/mutation-result.js";
|
|
11
18
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
type FileMutationBatchResult,
|
|
20
|
+
FileMutationResult,
|
|
21
|
+
type MutationResultPresentation,
|
|
22
|
+
} from "#src/api/mutation-result.js";
|
|
23
|
+
import {
|
|
24
|
+
isMutationAnchorValue,
|
|
25
|
+
mutationSource,
|
|
26
|
+
type TextMutation,
|
|
27
|
+
type TextMutationContext,
|
|
28
|
+
type TextMutationEdit,
|
|
29
|
+
type TextMutationToolRegistration,
|
|
17
30
|
} from "#src/api/mutation-tool.js";
|
|
18
31
|
import { isTextMutationResultContributionData } from "#src/api/post-edit.js";
|
|
19
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
formatStaleAnchorMessage,
|
|
34
|
+
type StaleAnchorMessageDetails,
|
|
35
|
+
} from "#src/api/stale-anchor-message.js";
|
|
20
36
|
import { createUnifiedDiff } from "#src/core/mutation-result/diff.js";
|
|
21
37
|
import { FileMutationAgentResult } from "#src/core/mutation-result/file-mutation-agent-result.js";
|
|
22
38
|
import { readTextAnchorRecovery } from "#src/core/text-anchor-recovery.js";
|
|
23
39
|
import { applyTextChanges, TextChangeDocument } from "#src/core/text-change-engine.js";
|
|
40
|
+
import { resolvedTextAnchorType } from "#src/core/text-anchor-registry.js";
|
|
24
41
|
import { executeTextToolWithBatch } from "#src/core/text-edit-batch-registrar.js";
|
|
25
42
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
contextualizeTextMutationAnchorError,
|
|
44
|
+
TextMutationAnchorAggregateError,
|
|
45
|
+
TextMutationAnchorResolutionError,
|
|
28
46
|
} from "#src/core/text-mutation-anchor-error.js";
|
|
29
47
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH,
|
|
49
|
+
type ToolCallInterceptionRenderStore,
|
|
50
|
+
withToolCallInterceptionRendering,
|
|
32
51
|
} from "#src/core/tool-call-interceptor/rendering.js";
|
|
33
52
|
import { appendSchemaFieldOrder } from "#src/core/tool-description.js";
|
|
34
53
|
|
|
35
54
|
import type { TextEditExecutionOutcome } from "#src/api/edit-pipeline.js";
|
|
36
|
-
import type { TextMutationPreviewOutcome, TextMutationPreviewRequest } from "#src/api/mutation-preview.js";
|
|
37
55
|
import type {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
TextMutationPreviewOutcome,
|
|
57
|
+
TextMutationPreviewRequest,
|
|
58
|
+
} from "#src/api/mutation-preview.js";
|
|
59
|
+
import type {
|
|
60
|
+
ResolveResourceTextAnchor,
|
|
61
|
+
TextEditorCore,
|
|
62
|
+
TextResourceEditFailure,
|
|
63
|
+
TextResourceEditOutcome,
|
|
64
|
+
TextResourcesEditOutcome,
|
|
43
65
|
} from "#src/core/text-editor-core.js";
|
|
44
|
-
import type
|
|
66
|
+
import { renderTextAnchor, type TextAnchor } from "pi-agent-text";
|
|
67
|
+
import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
|
|
68
|
+
import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception";
|
|
45
69
|
import type { Static, TSchema } from "typebox";
|
|
46
70
|
|
|
47
|
-
export function createTextTool<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
): ToolDefinition<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
export function createTextTool<TParameters extends TSchema>(
|
|
72
|
+
core: TextEditorCore,
|
|
73
|
+
definition: TextMutationToolRegistration<TParameters>,
|
|
74
|
+
annotations: ToolCallInterceptionRenderStore,
|
|
75
|
+
pluginPromptGuideline: () => string | undefined,
|
|
76
|
+
getLastResolvedSource: () => string | undefined,
|
|
77
|
+
): ToolDefinition<TParameters, FileMutationBatchResult> {
|
|
78
|
+
const renderer = core.getToolRenderer(definition.name);
|
|
79
|
+
|
|
80
|
+
const tool = withToolCallInterceptionRendering<TParameters, FileMutationBatchResult, unknown>(
|
|
81
|
+
defineTool<TParameters, FileMutationBatchResult, unknown>({
|
|
82
|
+
name: definition.name,
|
|
83
|
+
label: definition.name,
|
|
84
|
+
|
|
85
|
+
promptSnippet: definition.promptSnippet,
|
|
86
|
+
description: appendSchemaFieldOrder(definition.description, definition.parameters),
|
|
87
|
+
parameters: definition.parameters,
|
|
88
|
+
prepareArguments: (arguments_) =>
|
|
89
|
+
// oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
|
|
90
|
+
prepareGuardedArguments(
|
|
91
|
+
definition.parameters,
|
|
92
|
+
arguments_,
|
|
93
|
+
definition.source.inherited ? definition.source.field : undefined,
|
|
94
|
+
getLastResolvedSource(),
|
|
95
|
+
definition.anchors ?? [],
|
|
96
|
+
),
|
|
97
|
+
...(renderer?.renderShell !== undefined && { renderShell: renderer.renderShell }),
|
|
98
|
+
...(renderer?.renderCall !== undefined && { renderCall: renderer.renderCall }),
|
|
99
|
+
...(renderer?.renderResult !== undefined && { renderResult: renderer.renderResult }),
|
|
100
|
+
async execute(toolCallId, parameters, signal, onUpdate, context) {
|
|
101
|
+
const directExecute = () =>
|
|
102
|
+
executeTextMutation(
|
|
103
|
+
core,
|
|
104
|
+
definition,
|
|
105
|
+
asMutationParameters<TParameters>(parameters),
|
|
106
|
+
signal,
|
|
107
|
+
context,
|
|
108
|
+
(field, state) =>
|
|
109
|
+
annotations.resolveArguments(toolCallId, {
|
|
110
|
+
[TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
|
|
111
|
+
}),
|
|
112
|
+
getLastResolvedSource(),
|
|
113
|
+
);
|
|
114
|
+
return executeTextToolWithBatch(toolCallId, directExecute, signal, onUpdate, context);
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
annotations,
|
|
118
|
+
);
|
|
119
|
+
Object.defineProperty(tool, "promptGuidelines", {
|
|
120
|
+
enumerable: true,
|
|
121
|
+
get(): string[] | undefined {
|
|
122
|
+
const pluginGuideline = pluginPromptGuideline();
|
|
123
|
+
const guidelines = [
|
|
124
|
+
...(pluginGuideline === undefined ? [] : [pluginGuideline]),
|
|
125
|
+
...(definition.promptGuidelines ?? []),
|
|
126
|
+
];
|
|
127
|
+
return guidelines.length === 0 ? undefined : guidelines;
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
return tool;
|
|
91
131
|
}
|
|
92
132
|
|
|
93
|
-
function prepareGuardedArguments<
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
133
|
+
function prepareGuardedArguments<TParameters extends TSchema>(
|
|
134
|
+
schema: TParameters,
|
|
135
|
+
arguments_: unknown,
|
|
136
|
+
sourceField: string | undefined,
|
|
137
|
+
lastResolvedSource: string | undefined,
|
|
138
|
+
anchorFields: NonNullable<TextMutationToolRegistration["anchors"]>,
|
|
139
|
+
): ReturnType<
|
|
140
|
+
NonNullable<ToolDefinition<TParameters, FileMutationBatchResult>["prepareArguments"]>
|
|
141
|
+
> {
|
|
142
|
+
const prepared =
|
|
143
|
+
arguments_ !== null && typeof arguments_ === "object" && !Array.isArray(arguments_)
|
|
144
|
+
? { ...(arguments_ as Record<string, unknown>) }
|
|
145
|
+
: {};
|
|
146
|
+
const required = (schema as { required?: unknown }).required;
|
|
147
|
+
const properties = (schema as { properties?: Record<string, { type?: unknown }> }).properties;
|
|
148
|
+
|
|
149
|
+
// Anchor ownership is asynchronous; defer its source fallback until resources resolve.
|
|
150
|
+
const hasExplicitAnchor = anchorFields.some((descriptor) =>
|
|
151
|
+
isMutationAnchorValue(descriptor, prepared[descriptor.field]),
|
|
152
|
+
);
|
|
153
|
+
if (
|
|
154
|
+
sourceField !== undefined &&
|
|
155
|
+
!(sourceField in prepared) &&
|
|
156
|
+
lastResolvedSource !== undefined &&
|
|
157
|
+
!hasExplicitAnchor
|
|
158
|
+
) {
|
|
159
|
+
prepared[sourceField] = lastResolvedSource;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (Array.isArray(required)) {
|
|
163
|
+
for (const field of required) {
|
|
164
|
+
if (
|
|
165
|
+
typeof field === "string" &&
|
|
166
|
+
!(field in prepared) &&
|
|
167
|
+
properties?.[field]?.type === "string"
|
|
168
|
+
) {
|
|
169
|
+
prepared[field] = "";
|
|
170
|
+
}
|
|
120
171
|
}
|
|
172
|
+
}
|
|
121
173
|
|
|
122
|
-
|
|
174
|
+
// oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
|
|
175
|
+
return prepared as ReturnType<
|
|
176
|
+
NonNullable<ToolDefinition<TParameters, FileMutationBatchResult>["prepareArguments"]>
|
|
177
|
+
>;
|
|
123
178
|
}
|
|
124
179
|
|
|
125
|
-
interface ResolvedMutationSources
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
180
|
+
interface ResolvedMutationSources {
|
|
181
|
+
readonly fields: ReadonlyMap<string, string>;
|
|
182
|
+
readonly anchors: ReadonlyMap<string, readonly string[]>;
|
|
183
|
+
readonly implicitTargets: ReadonlyMap<string, readonly TextTarget[]>;
|
|
184
|
+
readonly targets: readonly TextTarget[];
|
|
185
|
+
readonly resources: readonly string[];
|
|
130
186
|
}
|
|
131
187
|
|
|
132
188
|
async function resolveMutationSources(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
189
|
+
core: TextEditorCore,
|
|
190
|
+
definition: TextMutationToolRegistration,
|
|
191
|
+
input: Readonly<Record<string, unknown>>,
|
|
192
|
+
context: { readonly cwd: string; readonly signal?: AbortSignal },
|
|
193
|
+
lastResolvedSource?: string,
|
|
194
|
+
): Promise<ResolvedMutationSources> {
|
|
195
|
+
const expandedByAnchor = new Map<string, readonly TextTarget[]>();
|
|
196
|
+
const expandedBySourceField = new Map<string, readonly TextTarget[]>();
|
|
197
|
+
const expandedFromExplicitSource = new Set<string>();
|
|
198
|
+
const explicitlyScopedSourceFields = new Set<string>();
|
|
199
|
+
const allKinds = [
|
|
200
|
+
...new Set((definition.anchors ?? []).flatMap((descriptor) => descriptor.kinds)),
|
|
201
|
+
];
|
|
202
|
+
const resolveTargets = async (
|
|
203
|
+
value: string,
|
|
204
|
+
field: string,
|
|
205
|
+
source: string,
|
|
206
|
+
): Promise<readonly TextTarget[] | undefined> => {
|
|
207
|
+
try {
|
|
208
|
+
return await core.resolveTextAnchorResources(value, allKinds, context);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw contextualizeTextMutationAnchorError(error, definition.name, field, source, value);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
for (const descriptor of definition.anchors ?? []) {
|
|
215
|
+
const value = input[descriptor.field];
|
|
216
|
+
if (!isMutationAnchorValue(descriptor, value)) continue;
|
|
217
|
+
const expanded = await resolveTargets(
|
|
218
|
+
value,
|
|
219
|
+
descriptor.field,
|
|
220
|
+
typeof input[descriptor.sourceField] === "string"
|
|
221
|
+
? String(input[descriptor.sourceField])
|
|
222
|
+
: "",
|
|
223
|
+
);
|
|
224
|
+
if (expanded === undefined) continue;
|
|
225
|
+
expandedByAnchor.set(descriptor.field, expanded);
|
|
226
|
+
const existingTargets = expandedBySourceField.get(descriptor.sourceField);
|
|
227
|
+
if (existingTargets !== undefined && !sameTargetSources(existingTargets, expanded)) {
|
|
228
|
+
throw new Error(`Incompatible targets for ${descriptor.sourceField}.`);
|
|
229
|
+
}
|
|
230
|
+
expandedBySourceField.set(
|
|
231
|
+
descriptor.sourceField,
|
|
232
|
+
mergeTargets(expandedBySourceField.get(descriptor.sourceField) ?? [], expanded),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
for (const descriptor of [definition.source, ...(definition.source.targets ?? [])]) {
|
|
237
|
+
const explicit = input[descriptor.field];
|
|
238
|
+
if (typeof explicit !== "string" || explicit.length === 0) continue;
|
|
239
|
+
const expanded = await resolveTargets(explicit, descriptor.field, explicit);
|
|
240
|
+
if (expanded !== undefined) {
|
|
241
|
+
expandedFromExplicitSource.add(descriptor.field);
|
|
242
|
+
expandedBySourceField.set(
|
|
243
|
+
descriptor.field,
|
|
244
|
+
mergeTargets(expandedBySourceField.get(descriptor.field) ?? [], expanded),
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const fields = new Map<string, string>();
|
|
250
|
+
const sourceDescriptors = [definition.source, ...(definition.source.targets ?? [])];
|
|
251
|
+
for (const descriptor of sourceDescriptors) {
|
|
252
|
+
const explicit = input[descriptor.field];
|
|
253
|
+
const explicitSource =
|
|
254
|
+
typeof explicit === "string" && explicit.length > 0 ? explicit : undefined;
|
|
255
|
+
const fallback = "fallbackTo" in descriptor ? fields.get(descriptor.fallbackTo) : undefined;
|
|
256
|
+
let expanded = expandedBySourceField.get(descriptor.field);
|
|
257
|
+
if (expanded !== undefined) {
|
|
258
|
+
if (explicitSource !== undefined && !expandedFromExplicitSource.has(descriptor.field)) {
|
|
259
|
+
const scoped = expanded.filter((target) =>
|
|
260
|
+
sameResource(explicitSource, target.source, context.cwd),
|
|
261
|
+
);
|
|
168
262
|
|
|
169
|
-
if (
|
|
170
|
-
|
|
171
|
-
continue;
|
|
263
|
+
if (scoped.length === 0) {
|
|
264
|
+
throw new Error(`Anchor does not belong to ${explicitSource}.`);
|
|
172
265
|
}
|
|
173
266
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
throw new Error(`Mutation anchors for ${descriptor.sourceField} refer to different resources.`);
|
|
267
|
+
if (scoped.length !== expanded.length) {
|
|
268
|
+
expanded = scoped;
|
|
269
|
+
expandedBySourceField.set(descriptor.field, scoped);
|
|
270
|
+
explicitlyScopedSourceFields.add(descriptor.field);
|
|
179
271
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
272
|
+
}
|
|
273
|
+
fields.set(descriptor.field, requiredValue(expanded[0]).source);
|
|
274
|
+
continue;
|
|
183
275
|
}
|
|
276
|
+
// Resource-owning anchors win. Only an omitted primary source may use read history.
|
|
277
|
+
const inherited =
|
|
278
|
+
descriptor.field === definition.source.field &&
|
|
279
|
+
definition.source.inherited === true &&
|
|
280
|
+
!(descriptor.field in input)
|
|
281
|
+
? lastResolvedSource
|
|
282
|
+
: undefined;
|
|
283
|
+
const source = explicitSource ?? fallback ?? inherited;
|
|
284
|
+
if (source === undefined) throw new Error(`${descriptor.field} is required`);
|
|
285
|
+
fields.set(descriptor.field, source);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const anchors = new Map<string, readonly string[]>();
|
|
289
|
+
const implicitTargets = new Map<string, readonly TextTarget[]>();
|
|
290
|
+
for (const descriptor of definition.anchors ?? []) {
|
|
291
|
+
const targets = expandedBySourceField.get(descriptor.sourceField);
|
|
292
|
+
|
|
293
|
+
const hasExplicitAnchor = isMutationAnchorValue(descriptor, input[descriptor.field]);
|
|
294
|
+
const hasImplicitSourceSelection = expandedFromExplicitSource.has(descriptor.sourceField);
|
|
295
|
+
if (!hasExplicitAnchor && !hasImplicitSourceSelection) continue;
|
|
296
|
+
if (
|
|
297
|
+
targets !== undefined &&
|
|
298
|
+
(hasImplicitSourceSelection || !expandedByAnchor.has(descriptor.field))
|
|
299
|
+
) {
|
|
300
|
+
implicitTargets.set(descriptor.field, targets);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
for (const descriptor of definition.anchors ?? []) {
|
|
305
|
+
const expanded = expandedByAnchor.get(descriptor.field);
|
|
306
|
+
const value = input[descriptor.field];
|
|
307
|
+
|
|
308
|
+
if (typeof value === "string" && !isMutationAnchorValue(descriptor, value)) continue;
|
|
309
|
+
const source = fields.get(descriptor.sourceField);
|
|
310
|
+
if (expanded !== undefined) {
|
|
311
|
+
anchors.set(
|
|
312
|
+
descriptor.field,
|
|
313
|
+
source !== undefined &&
|
|
314
|
+
(expanded.length === 1 || explicitlyScopedSourceFields.has(descriptor.sourceField))
|
|
315
|
+
? [source]
|
|
316
|
+
: [...new Set(expanded.map((target) => target.source))],
|
|
317
|
+
);
|
|
318
|
+
} else if (source !== undefined) {
|
|
319
|
+
const selected = expandedBySourceField.get(descriptor.sourceField);
|
|
320
|
+
const explicitAnchor = input[descriptor.field];
|
|
321
|
+
anchors.set(
|
|
322
|
+
descriptor.field,
|
|
323
|
+
selected !== undefined && typeof explicitAnchor === "string" && explicitAnchor.length > 0
|
|
324
|
+
? [...new Set(selected.map((target) => target.source))]
|
|
325
|
+
: [source],
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const targets = [...expandedBySourceField.values()]
|
|
330
|
+
.flat()
|
|
331
|
+
.reduce<TextTarget[]>((all, target) => mergeTargets(all, [target]), []);
|
|
332
|
+
return {
|
|
333
|
+
fields,
|
|
334
|
+
anchors,
|
|
335
|
+
implicitTargets,
|
|
336
|
+
targets,
|
|
337
|
+
resources: [...new Set([...fields.values(), ...targets.map((target) => target.source)])],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
184
340
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const expanded = expandedBySourceField.get(descriptor.field);
|
|
194
|
-
|
|
195
|
-
if (expanded !== undefined)
|
|
196
|
-
{
|
|
197
|
-
if (explicitSource === undefined)
|
|
198
|
-
{
|
|
199
|
-
fields.set(descriptor.field, expanded[0]!);
|
|
200
|
-
}
|
|
201
|
-
else
|
|
202
|
-
{
|
|
203
|
-
if (expanded.length !== 1)
|
|
204
|
-
{
|
|
205
|
-
throw new Error(
|
|
206
|
-
`${descriptor.field} must be omitted when a search anchor selects multiple resources.`,
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (!sameResource(explicitSource, expanded[0]!, context.cwd))
|
|
211
|
-
{
|
|
212
|
-
throw new Error(`Anchor does not belong to ${explicitSource}.`);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
fields.set(descriptor.field, explicitSource);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const source = explicitSource ?? fallback;
|
|
222
|
-
|
|
223
|
-
if (source === undefined)
|
|
224
|
-
{
|
|
225
|
-
throw new Error(`${descriptor.field} is required`);
|
|
226
|
-
}
|
|
341
|
+
function sameTargetSources(left: readonly TextTarget[], right: readonly TextTarget[]): boolean {
|
|
342
|
+
const leftSources = new Set(left.map((target) => target.source));
|
|
343
|
+
const rightSources = new Set(right.map((target) => target.source));
|
|
344
|
+
return (
|
|
345
|
+
leftSources.size === rightSources.size &&
|
|
346
|
+
[...leftSources].every((source) => rightSources.has(source))
|
|
347
|
+
);
|
|
348
|
+
}
|
|
227
349
|
|
|
228
|
-
|
|
350
|
+
function mergeTargets(left: readonly TextTarget[], right: readonly TextTarget[]): TextTarget[] {
|
|
351
|
+
const merged = new Map<string, TextTarget>();
|
|
352
|
+
for (const target of [...left, ...right]) {
|
|
353
|
+
const previous = merged.get(target.source);
|
|
354
|
+
if (previous === undefined) {
|
|
355
|
+
merged.set(target.source, target);
|
|
356
|
+
continue;
|
|
229
357
|
}
|
|
358
|
+
const ranges = [...(previous.ranges ?? []), ...(target.ranges ?? [])];
|
|
359
|
+
merged.set(target.source, {
|
|
360
|
+
source: target.source,
|
|
361
|
+
...(ranges.length > 0 && { ranges: deduplicateRanges(ranges) }),
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
return [...merged.values()];
|
|
365
|
+
}
|
|
230
366
|
|
|
231
|
-
|
|
367
|
+
function deduplicateRanges(ranges: readonly TextSelectionRange[]): readonly TextSelectionRange[] {
|
|
368
|
+
const merged = new Map<string, TextSelectionRange>();
|
|
369
|
+
for (const range of ranges) {
|
|
370
|
+
const key = JSON.stringify({ start: range.start, end: range.end });
|
|
371
|
+
const previous = merged.get(key);
|
|
372
|
+
merged.set(key, {
|
|
373
|
+
...range,
|
|
374
|
+
...(previous?.linewise === true || range.linewise === true ? { linewise: true } : {}),
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return [...merged.values()];
|
|
378
|
+
}
|
|
232
379
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
380
|
+
function naturalLineSelection(content: string, lineNumber: number): TextSelectionRange {
|
|
381
|
+
const lines = content.split(/\r\n|\r|\n/u);
|
|
382
|
+
const line = lines[lineNumber - 1];
|
|
383
|
+
if (line === undefined) {
|
|
384
|
+
throw new Error(`Position anchor line ${lineNumber} is outside the source.`);
|
|
385
|
+
}
|
|
386
|
+
const hasFollowingLine = lineNumber < lines.length;
|
|
387
|
+
return {
|
|
388
|
+
start: { lineNumber, column: 0 },
|
|
389
|
+
end: hasFollowingLine
|
|
390
|
+
? { lineNumber: lineNumber + 1, column: 0 }
|
|
391
|
+
: { lineNumber, column: line.length },
|
|
392
|
+
linewise: true,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
237
395
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
396
|
+
function mergeResolvedAnchors(
|
|
397
|
+
documentFor: (source: string) => TextChangeDocument,
|
|
398
|
+
field: string,
|
|
399
|
+
explicit: ReadonlyMap<string, TextAnchor>,
|
|
400
|
+
implicit: ReadonlyMap<string, TextSelectionAnchor>,
|
|
401
|
+
): ReadonlyMap<string, TextAnchor> {
|
|
402
|
+
const sources = new Set([...explicit.keys(), ...implicit.keys()]);
|
|
403
|
+
return new Map(
|
|
404
|
+
[...sources].map((source) => {
|
|
405
|
+
const explicitAnchor = explicit.get(source);
|
|
406
|
+
const implicitAnchor = implicit.get(source);
|
|
407
|
+
if (explicitAnchor === undefined) return [source, requiredValue(implicitAnchor)] as const;
|
|
408
|
+
if (implicitAnchor === undefined) return [source, explicitAnchor] as const;
|
|
409
|
+
|
|
410
|
+
const explicitSelection = TextSelectionAnchor.is(explicitAnchor)
|
|
411
|
+
? explicitAnchor
|
|
412
|
+
: new TextSelectionAnchor(field, source, [
|
|
413
|
+
naturalLineSelection(documentFor(source).content, explicitAnchor.lineNumber),
|
|
414
|
+
]);
|
|
415
|
+
const ranges = [...explicitSelection.ranges, ...implicitAnchor.ranges].sort(
|
|
416
|
+
(left, right) =>
|
|
417
|
+
left.start.lineNumber - right.start.lineNumber || left.start.column - right.start.column,
|
|
418
|
+
);
|
|
419
|
+
const unique = deduplicateRanges(ranges);
|
|
420
|
+
for (let index = 1; index < unique.length; index++) {
|
|
421
|
+
const previous = requiredValue(unique[index - 1]);
|
|
422
|
+
const current = requiredValue(unique[index]);
|
|
423
|
+
if (
|
|
424
|
+
current.start.lineNumber < previous.end.lineNumber ||
|
|
425
|
+
(current.start.lineNumber === previous.end.lineNumber &&
|
|
426
|
+
current.start.column < previous.end.column)
|
|
427
|
+
) {
|
|
428
|
+
throw new Error(`Anchor ${field} selections overlap or are ambiguous.`);
|
|
248
429
|
}
|
|
249
|
-
|
|
430
|
+
}
|
|
431
|
+
return [source, new TextSelectionAnchor(field, source, unique)] as const;
|
|
432
|
+
}),
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
interface MutationExecutionContext extends TextMutationContext {
|
|
436
|
+
resultPresentationFor(source: string): MutationResultPresentation;
|
|
437
|
+
}
|
|
250
438
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
anchors,
|
|
254
|
-
resources: [...new Set([...fields.values(), ...[...anchors.values()].flat()])],
|
|
255
|
-
};
|
|
439
|
+
interface ExecutedTextMutation extends TextMutation {
|
|
440
|
+
readonly resultPresentations: ReadonlyMap<string, MutationResultPresentation>;
|
|
256
441
|
}
|
|
257
442
|
|
|
258
443
|
function createMutationContext(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
444
|
+
definition: TextMutationToolRegistration,
|
|
445
|
+
input: Readonly<Record<string, unknown>>,
|
|
446
|
+
invocation: { readonly cwd: string; readonly signal?: AbortSignal },
|
|
447
|
+
sources: ResolvedMutationSources,
|
|
448
|
+
texts: ReadonlyMap<string, string>,
|
|
449
|
+
resolveResourceAnchor: ResolveResourceTextAnchor,
|
|
450
|
+
publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
|
|
451
|
+
): MutationExecutionContext {
|
|
452
|
+
const documents = new Map(
|
|
453
|
+
[...texts].map(([source, text]) => [source, new TextChangeDocument(text)]),
|
|
454
|
+
);
|
|
455
|
+
const anchorCache = new Map<string, Promise<ReadonlyMap<string, TextAnchor>>>();
|
|
456
|
+
|
|
457
|
+
const majorAnchorSources = new Set<string>();
|
|
458
|
+
const sourceFor = (field: string): string => {
|
|
459
|
+
const source = sources.fields.get(field);
|
|
460
|
+
|
|
461
|
+
if (source === undefined) {
|
|
462
|
+
throw new Error(`Unknown mutation source field ${field}`);
|
|
463
|
+
}
|
|
272
464
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
465
|
+
return source;
|
|
466
|
+
};
|
|
467
|
+
const documentFor = (source: string): TextChangeDocument => {
|
|
468
|
+
const document = documents.get(source);
|
|
277
469
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
{
|
|
282
|
-
const document = documents.get(source);
|
|
470
|
+
if (document === undefined) {
|
|
471
|
+
throw new Error(`Unknown mutation resource ${source}`);
|
|
472
|
+
}
|
|
283
473
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
474
|
+
return document;
|
|
475
|
+
};
|
|
476
|
+
const resolveAnchors = (field: string): Promise<ReadonlyMap<string, TextAnchor>> => {
|
|
477
|
+
const cached = anchorCache.get(field);
|
|
288
478
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
{
|
|
293
|
-
const cached = anchorCache.get(field);
|
|
479
|
+
if (cached !== undefined) {
|
|
480
|
+
return cached;
|
|
481
|
+
}
|
|
294
482
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
483
|
+
const pending = (async () => {
|
|
484
|
+
const descriptor = (definition.anchors ?? []).find((anchor) => anchor.field === field);
|
|
485
|
+
const value = input[field];
|
|
486
|
+
const anchorSources = sources.anchors.get(field);
|
|
487
|
+
const implicitTargets = sources.implicitTargets.get(field);
|
|
299
488
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return [source, await resolveResourceAnchor(source, value, descriptor.kinds)] as const;
|
|
317
|
-
}
|
|
318
|
-
catch (error)
|
|
319
|
-
{
|
|
320
|
-
throw contextualizeTextMutationAnchorError(error, definition.name, field, source, value);
|
|
489
|
+
if (descriptor === undefined) {
|
|
490
|
+
throw new Error(
|
|
491
|
+
`Mutation tool ${definition.name} tried to resolve undeclared anchor ${field}`,
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const explicitAnchors =
|
|
496
|
+
typeof value === "string" && anchorSources !== undefined
|
|
497
|
+
? new Map(
|
|
498
|
+
await Promise.all(
|
|
499
|
+
anchorSources.map(async (source) => {
|
|
500
|
+
try {
|
|
501
|
+
const anchor = await resolveResourceAnchor(source, value, descriptor.kinds);
|
|
502
|
+
|
|
503
|
+
if (resolvedTextAnchorType(anchor) === "major") {
|
|
504
|
+
majorAnchorSources.add(source);
|
|
321
505
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
506
|
+
const rendered = renderTextAnchor(anchor, value, { source, anchor });
|
|
507
|
+
publishAnchorRenderState?.(field, {
|
|
508
|
+
kind: "resolved",
|
|
509
|
+
full: rendered.full,
|
|
510
|
+
compact: rendered.compact,
|
|
511
|
+
resolverId: rendered.resolverId,
|
|
512
|
+
});
|
|
513
|
+
return [source, anchor] as const;
|
|
514
|
+
} catch (error) {
|
|
515
|
+
publishAnchorRenderState?.(field, { kind: "failed" });
|
|
516
|
+
throw contextualizeTextMutationAnchorError(
|
|
517
|
+
error,
|
|
518
|
+
definition.name,
|
|
519
|
+
field,
|
|
520
|
+
source,
|
|
521
|
+
value,
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
}),
|
|
525
|
+
),
|
|
526
|
+
)
|
|
527
|
+
: undefined;
|
|
528
|
+
|
|
529
|
+
if (implicitTargets !== undefined) {
|
|
530
|
+
const implicit = new Map(
|
|
531
|
+
implicitTargets.map(
|
|
532
|
+
(target) =>
|
|
533
|
+
[
|
|
534
|
+
target.source,
|
|
535
|
+
new TextSelectionAnchor(field, target.source, target.ranges ?? []),
|
|
536
|
+
] as const,
|
|
537
|
+
),
|
|
538
|
+
);
|
|
539
|
+
if (explicitAnchors === undefined) return implicit;
|
|
540
|
+
return mergeResolvedAnchors(documentFor, field, explicitAnchors, implicit);
|
|
541
|
+
}
|
|
328
542
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
543
|
+
if (explicitAnchors === undefined) {
|
|
544
|
+
throw new Error(
|
|
545
|
+
`Mutation tool ${definition.name} tried to resolve undeclared anchor ${field}`,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
return explicitAnchors;
|
|
549
|
+
})();
|
|
550
|
+
anchorCache.set(field, pending);
|
|
551
|
+
return pending;
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
return {
|
|
555
|
+
cwd: invocation.cwd,
|
|
556
|
+
...(invocation.signal !== undefined && { signal: invocation.signal }),
|
|
557
|
+
sourceDocument: documentFor(sourceFor(definition.source.field)),
|
|
558
|
+
sourceFor,
|
|
559
|
+
documentFor,
|
|
560
|
+
targetDocument(field): TextChangeDocument {
|
|
561
|
+
if ((definition.source.targets ?? []).every((target) => target.field !== field)) {
|
|
562
|
+
throw new Error(
|
|
563
|
+
`Mutation tool ${definition.name} tried to access undeclared target ${field}`,
|
|
564
|
+
);
|
|
565
|
+
}
|
|
341
566
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const resolved = await resolveAnchors(field);
|
|
567
|
+
return documentFor(sourceFor(field));
|
|
568
|
+
},
|
|
569
|
+
resolveAnchors,
|
|
570
|
+
async resolveAnchor(field): Promise<TextAnchor> {
|
|
571
|
+
const resolved = await resolveAnchors(field);
|
|
348
572
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
573
|
+
if (resolved.size !== 1) {
|
|
574
|
+
throw new Error(
|
|
575
|
+
`Anchor ${field} selects multiple resources; use an operation that supports a search set.`,
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return requiredValue(resolved.values().next().value);
|
|
580
|
+
},
|
|
581
|
+
|
|
582
|
+
resultPresentationFor(source): MutationResultPresentation {
|
|
583
|
+
return [...majorAnchorSources].some((candidate) =>
|
|
584
|
+
sameResource(candidate, source, invocation.cwd),
|
|
585
|
+
)
|
|
586
|
+
? "major-anchor"
|
|
587
|
+
: "plain";
|
|
588
|
+
},
|
|
589
|
+
};
|
|
590
|
+
}
|
|
355
591
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
592
|
+
function withResultPresentations(
|
|
593
|
+
mutation: TextMutation,
|
|
594
|
+
context: MutationExecutionContext,
|
|
595
|
+
): ExecutedTextMutation {
|
|
596
|
+
return {
|
|
597
|
+
...mutation,
|
|
598
|
+
resultPresentations: new Map(
|
|
599
|
+
[...mutation.edits.keys()].map((source) => [source, context.resultPresentationFor(source)]),
|
|
600
|
+
),
|
|
601
|
+
};
|
|
359
602
|
}
|
|
360
603
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
604
|
+
const preflightMutationTools = new Set(["replace", "delete", "insert", "copy", "move"]);
|
|
605
|
+
/** Resolves every supplied anchor field for built-in span mutation tools. */
|
|
606
|
+
export async function preflightMutationAnchors(
|
|
607
|
+
definition: TextMutationToolRegistration,
|
|
608
|
+
input: Readonly<Record<string, unknown>>,
|
|
609
|
+
context: TextMutationContext,
|
|
610
|
+
): Promise<void> {
|
|
611
|
+
if (!preflightMutationTools.has(definition.name)) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const failures: TextMutationAnchorResolutionError[] = [];
|
|
615
|
+
await Promise.all(
|
|
616
|
+
(definition.anchors ?? []).map(async (descriptor) => {
|
|
617
|
+
if (!isMutationAnchorValue(descriptor, input[descriptor.field])) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
try {
|
|
621
|
+
await context.resolveAnchors(descriptor.field);
|
|
622
|
+
} catch (error) {
|
|
623
|
+
if (error instanceof TextMutationAnchorResolutionError) {
|
|
624
|
+
failures.push(error);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
throw error;
|
|
628
|
+
}
|
|
629
|
+
}),
|
|
630
|
+
);
|
|
631
|
+
if (failures.length > 0) {
|
|
632
|
+
throw new TextMutationAnchorAggregateError(failures);
|
|
633
|
+
}
|
|
366
634
|
}
|
|
367
635
|
|
|
368
|
-
function sameResource(left: string, right: string, cwd: string): boolean
|
|
369
|
-
|
|
370
|
-
return resourceIdentity(left, cwd) === resourceIdentity(right, cwd);
|
|
636
|
+
function sameResource(left: string, right: string, cwd: string): boolean {
|
|
637
|
+
return resourceIdentity(left, cwd) === resourceIdentity(right, cwd);
|
|
371
638
|
}
|
|
372
639
|
|
|
373
|
-
function resourceIdentity(source: string, cwd: string): string
|
|
374
|
-
{
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
return source;
|
|
378
|
-
}
|
|
640
|
+
function resourceIdentity(source: string, cwd: string): string {
|
|
641
|
+
if (/^[a-z][a-z\d+.-]*:\/\//iu.test(source)) {
|
|
642
|
+
return source;
|
|
643
|
+
}
|
|
379
644
|
|
|
380
|
-
|
|
381
|
-
|
|
645
|
+
const fileSource = source.startsWith("@") ? source.slice(1) : source;
|
|
646
|
+
return path.resolve(cwd, fileSource);
|
|
382
647
|
}
|
|
383
648
|
|
|
384
649
|
export async function previewTextMutation(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
): Promise<TextMutationPreviewOutcome>
|
|
388
|
-
|
|
389
|
-
|
|
650
|
+
core: TextEditorCore,
|
|
651
|
+
request: TextMutationPreviewRequest,
|
|
652
|
+
): Promise<TextMutationPreviewOutcome> {
|
|
653
|
+
const definition = core.getMutationTools().find((candidate) => candidate.name === request.tool);
|
|
654
|
+
|
|
655
|
+
if (definition === undefined) {
|
|
656
|
+
return { kind: "failed", reason: `Unknown mutation tool ${request.tool}` };
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
try {
|
|
660
|
+
const sources = await resolveMutationSources(core, definition, request.input, request);
|
|
661
|
+
return await core.previewTexts(
|
|
662
|
+
sources.resources.map((source) => ({
|
|
663
|
+
source,
|
|
664
|
+
read: true,
|
|
665
|
+
...(definition.name === "write" && { allowReadFailure: true }),
|
|
666
|
+
})),
|
|
667
|
+
{ cwd: request.cwd, ...(request.signal !== undefined && { signal: request.signal }) },
|
|
668
|
+
async (texts, resolveAnchor) => {
|
|
669
|
+
const mutationContext = createMutationContext(
|
|
670
|
+
definition,
|
|
671
|
+
request.input,
|
|
672
|
+
request,
|
|
673
|
+
sources,
|
|
674
|
+
texts,
|
|
675
|
+
resolveAnchor,
|
|
676
|
+
);
|
|
677
|
+
await preflightMutationAnchors(definition, request.input, mutationContext);
|
|
678
|
+
const mutation = await definition.mutate(mutationContext, request.input);
|
|
390
679
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
680
|
+
return {
|
|
681
|
+
changes: new Map([...mutation.edits].map(([source, edit]) => [source, edit.changes])),
|
|
682
|
+
result: mutation,
|
|
683
|
+
};
|
|
684
|
+
},
|
|
685
|
+
);
|
|
686
|
+
} catch (error) {
|
|
687
|
+
return { kind: "failed", reason: error instanceof Error ? error.message : String(error) };
|
|
688
|
+
}
|
|
689
|
+
}
|
|
395
690
|
|
|
396
|
-
|
|
691
|
+
/** Executes a mutation, using read history only when neither a source nor an anchor owns it. */
|
|
692
|
+
export async function executeTextMutation<TParameters extends TSchema>(
|
|
693
|
+
core: TextEditorCore,
|
|
694
|
+
definition: TextMutationToolRegistration<TParameters>,
|
|
695
|
+
parameters: Static<TParameters>,
|
|
696
|
+
signal: AbortSignal | undefined,
|
|
697
|
+
context: ExtensionContext,
|
|
698
|
+
publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
|
|
699
|
+
lastResolvedSource?: string,
|
|
700
|
+
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
701
|
+
const source = mutationSource(definition, parameters);
|
|
702
|
+
const pipeline = await core.executeEdit(
|
|
703
|
+
definition.name,
|
|
397
704
|
{
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
request.input,
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
return {
|
|
414
|
-
changes: new Map([...mutation.edits].map(([source, edit]) => [source, edit.changes])),
|
|
415
|
-
result: mutation,
|
|
416
|
-
};
|
|
417
|
-
},
|
|
705
|
+
cwd: context.cwd,
|
|
706
|
+
input: parameters,
|
|
707
|
+
...(signal !== undefined && { signal }),
|
|
708
|
+
},
|
|
709
|
+
async (state) => {
|
|
710
|
+
try {
|
|
711
|
+
const sources = await resolveMutationSources(
|
|
712
|
+
core,
|
|
713
|
+
definition,
|
|
714
|
+
state.input,
|
|
715
|
+
state,
|
|
716
|
+
lastResolvedSource,
|
|
418
717
|
);
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
state.input,
|
|
463
|
-
);
|
|
464
|
-
return {
|
|
465
|
-
changes: new Map(
|
|
466
|
-
[...mutation.edits].map(([editSource, edit]) => [editSource, edit.changes]),
|
|
467
|
-
),
|
|
468
|
-
result: mutation,
|
|
469
|
-
};
|
|
470
|
-
},
|
|
471
|
-
);
|
|
472
|
-
return await completeTextMutation(outcome, mutationSource(definition, state.input));
|
|
473
|
-
}
|
|
474
|
-
catch (error)
|
|
475
|
-
{
|
|
476
|
-
return failedResourceEdit(
|
|
477
|
-
mutationSource(definition, state.input),
|
|
478
|
-
"INVALID_REQUEST",
|
|
479
|
-
errorMessage(error),
|
|
480
|
-
error,
|
|
481
|
-
);
|
|
482
|
-
}
|
|
483
|
-
},
|
|
484
|
-
);
|
|
718
|
+
const outcome = await core.editTexts(
|
|
719
|
+
sources.resources.map((resourceSource) => ({
|
|
720
|
+
source: resourceSource,
|
|
721
|
+
read: true,
|
|
722
|
+
...(definition.name === "write" && { allowReadFailure: true }),
|
|
723
|
+
})),
|
|
724
|
+
{
|
|
725
|
+
cwd: state.cwd,
|
|
726
|
+
intent: definition.intent ?? "edit",
|
|
727
|
+
...(state.signal !== undefined && { signal: state.signal }),
|
|
728
|
+
},
|
|
729
|
+
async (texts, resolveAnchor) => {
|
|
730
|
+
const mutationContext = createMutationContext(
|
|
731
|
+
definition,
|
|
732
|
+
state.input,
|
|
733
|
+
state,
|
|
734
|
+
sources,
|
|
735
|
+
texts,
|
|
736
|
+
resolveAnchor,
|
|
737
|
+
publishAnchorRenderState,
|
|
738
|
+
);
|
|
739
|
+
await preflightMutationAnchors(definition, state.input, mutationContext);
|
|
740
|
+
const mutation = await definition.mutate(mutationContext, state.input);
|
|
741
|
+
const executedMutation = withResultPresentations(mutation, mutationContext);
|
|
742
|
+
return {
|
|
743
|
+
changes: new Map(
|
|
744
|
+
[...mutation.edits].map(([editSource, edit]) => [editSource, edit.changes]),
|
|
745
|
+
),
|
|
746
|
+
result: executedMutation,
|
|
747
|
+
};
|
|
748
|
+
},
|
|
749
|
+
);
|
|
750
|
+
return await completeTextMutation(outcome, mutationSource(definition, state.input));
|
|
751
|
+
} catch (error) {
|
|
752
|
+
return failedResourceEdit(
|
|
753
|
+
mutationSource(definition, state.input),
|
|
754
|
+
"INVALID_REQUEST",
|
|
755
|
+
errorMessage(error),
|
|
756
|
+
error,
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
);
|
|
485
761
|
|
|
486
|
-
|
|
762
|
+
return buildToolResult(core, pipeline, source, context);
|
|
487
763
|
}
|
|
488
764
|
|
|
489
765
|
export function mutationSources(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
): ReadonlyMap<string, string>
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
const primary = params[definition.source.field];
|
|
496
|
-
|
|
497
|
-
if (typeof primary !== "string" || primary.length === 0)
|
|
498
|
-
{
|
|
499
|
-
throw new Error(`${definition.source.field} is required`);
|
|
500
|
-
}
|
|
766
|
+
definition: TextMutationToolRegistration,
|
|
767
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
768
|
+
): ReadonlyMap<string, string> {
|
|
769
|
+
const sources = new Map<string, string>();
|
|
770
|
+
const primary = parameters[definition.source.field];
|
|
501
771
|
|
|
502
|
-
|
|
772
|
+
if (typeof primary !== "string" || primary.length === 0) {
|
|
773
|
+
throw new Error(`${definition.source.field} is required`);
|
|
774
|
+
}
|
|
503
775
|
|
|
504
|
-
|
|
505
|
-
{
|
|
506
|
-
const explicit = params[target.field];
|
|
507
|
-
const fallback = sources.get(target.fallbackTo);
|
|
508
|
-
const source = typeof explicit === "string" && explicit.length > 0 ? explicit : fallback;
|
|
776
|
+
sources.set(definition.source.field, primary);
|
|
509
777
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
778
|
+
for (const target of definition.source.targets ?? []) {
|
|
779
|
+
const explicit = parameters[target.field];
|
|
780
|
+
const fallback = sources.get(target.fallbackTo);
|
|
781
|
+
const source = typeof explicit === "string" && explicit.length > 0 ? explicit : fallback;
|
|
514
782
|
|
|
515
|
-
|
|
783
|
+
if (source === undefined) {
|
|
784
|
+
throw new Error(`${target.field} is required`);
|
|
516
785
|
}
|
|
517
786
|
|
|
518
|
-
|
|
787
|
+
sources.set(target.field, source);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
return sources;
|
|
519
791
|
}
|
|
520
792
|
|
|
521
|
-
type CompletedTextResource = Extract<
|
|
793
|
+
type CompletedTextResource = Extract<
|
|
794
|
+
TextResourceEditOutcome<unknown>,
|
|
795
|
+
{ readonly kind: "completed" }
|
|
796
|
+
>;
|
|
522
797
|
|
|
523
798
|
export function buildSuccessfulTextMutationResult(
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
799
|
+
resource: CompletedTextResource,
|
|
800
|
+
resultSource: string,
|
|
801
|
+
edit: TextMutationEdit,
|
|
802
|
+
diffAfterContent = resource.after.content,
|
|
803
|
+
resultPresentation: MutationResultPresentation = "plain",
|
|
804
|
+
editCount = 1,
|
|
805
|
+
): FileMutationResult {
|
|
806
|
+
const before = resource.before.content;
|
|
807
|
+
const finalAfter = resource.after.content;
|
|
808
|
+
const applied = applyTextChanges(before, edit.changes);
|
|
809
|
+
const unified = createUnifiedDiff(resultSource, before, diffAfterContent);
|
|
810
|
+
const mutationResultData = resource.postEditContributions
|
|
811
|
+
.map((contribution) => contribution.data)
|
|
812
|
+
.find(isTextMutationResultContributionData);
|
|
813
|
+
const rawChanges = applied.changes.map((change, editIndex) => ({
|
|
814
|
+
editIndex,
|
|
815
|
+
fromA: change.fromBefore,
|
|
816
|
+
toA: change.toBefore,
|
|
817
|
+
fromB: change.fromAfter,
|
|
818
|
+
toB: change.toAfter,
|
|
819
|
+
removedText: change.removedText,
|
|
820
|
+
insertedText: change.insertedText,
|
|
821
|
+
}));
|
|
822
|
+
|
|
823
|
+
return new FileMutationResult({
|
|
824
|
+
...mutationResultData,
|
|
825
|
+
ok: true,
|
|
826
|
+
path: resultSource,
|
|
827
|
+
diffs: [unified.diff],
|
|
828
|
+
files: [{ path: resultSource, action: edit.action }],
|
|
829
|
+
editCount,
|
|
830
|
+
addedLines: unified.stats.added,
|
|
831
|
+
removedLines: unified.stats.removed,
|
|
832
|
+
beforeContentMap: { [resultSource]: before },
|
|
833
|
+
afterContent: finalAfter,
|
|
834
|
+
rawChanges,
|
|
835
|
+
afterDocument: resource.after,
|
|
836
|
+
|
|
837
|
+
resultPresentation,
|
|
838
|
+
});
|
|
561
839
|
}
|
|
562
840
|
|
|
563
841
|
async function completeTextMutation(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
): Promise<TextResourcesEditOutcome<TextMutation>>
|
|
567
|
-
{
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
cause: error,
|
|
587
|
-
},
|
|
588
|
-
completed: outcome.resources.map((resource) => resource.source),
|
|
589
|
-
};
|
|
590
|
-
}
|
|
842
|
+
outcome: TextResourcesEditOutcome<TextMutation>,
|
|
843
|
+
source: string,
|
|
844
|
+
): Promise<TextResourcesEditOutcome<TextMutation>> {
|
|
845
|
+
if (outcome.kind === "failed" || outcome.result.afterWrite === undefined) {
|
|
846
|
+
return outcome;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
try {
|
|
850
|
+
await outcome.result.afterWrite();
|
|
851
|
+
return outcome;
|
|
852
|
+
} catch (error) {
|
|
853
|
+
return {
|
|
854
|
+
kind: "failed",
|
|
855
|
+
failure: {
|
|
856
|
+
code: "POST_WRITE_FAILED",
|
|
857
|
+
source,
|
|
858
|
+
message: `Post-write action failed for ${source}`,
|
|
859
|
+
cause: error,
|
|
860
|
+
},
|
|
861
|
+
completed: outcome.resources.map((resource) => resource.source),
|
|
862
|
+
};
|
|
863
|
+
}
|
|
591
864
|
}
|
|
592
865
|
|
|
593
866
|
async function buildToolResult(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
): Promise<AgentToolResult<FileMutationBatchResult>>
|
|
599
|
-
{
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
867
|
+
core: TextEditorCore,
|
|
868
|
+
pipeline: TextEditExecutionOutcome,
|
|
869
|
+
source: string,
|
|
870
|
+
context: ExtensionContext,
|
|
871
|
+
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
872
|
+
if (pipeline.kind === "failed") {
|
|
873
|
+
return failureToolResult(
|
|
874
|
+
source,
|
|
875
|
+
pipeline.failure.code,
|
|
876
|
+
pipeline.failure.message,
|
|
877
|
+
"not-applied",
|
|
878
|
+
);
|
|
879
|
+
}
|
|
606
880
|
|
|
607
|
-
|
|
608
|
-
{
|
|
609
|
-
return failureToolResult(source, "INVALID_RESULT", "Text editor returned an invalid edit result.", "unknown");
|
|
610
|
-
}
|
|
881
|
+
const outcome = pipeline.state.result;
|
|
611
882
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
883
|
+
if (!isResourcesEditOutcome(outcome)) {
|
|
884
|
+
return failureToolResult(
|
|
885
|
+
source,
|
|
886
|
+
"INVALID_RESULT",
|
|
887
|
+
"Text editor returned an invalid edit result.",
|
|
888
|
+
"unknown",
|
|
889
|
+
);
|
|
890
|
+
}
|
|
615
891
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
return recovery;
|
|
619
|
-
}
|
|
892
|
+
if (outcome.kind === "failed") {
|
|
893
|
+
const recovery = await anchorFailureToolResult(core, outcome.failure, context);
|
|
620
894
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
const message = `${outcome.failure.message.replace(/[.!?]+$/u, "")}.${completed}`;
|
|
624
|
-
return failureToolResult(source, outcome.failure.code, message, effect);
|
|
895
|
+
if (recovery !== undefined) {
|
|
896
|
+
return recovery;
|
|
625
897
|
}
|
|
626
898
|
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
899
|
+
const completed =
|
|
900
|
+
outcome.completed.length === 0 ? "" : ` Completed writes: ${outcome.completed.join(", ")}.`;
|
|
901
|
+
const effect = outcome.completed.length === 0 ? "not-applied" : "applied";
|
|
902
|
+
const message = `${outcome.failure.message.replace(/[.!?]+$/u, "")}.${completed}`;
|
|
903
|
+
return failureToolResult(source, outcome.failure.code, message, effect);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
const mutation = outcome.result as ExecutedTextMutation;
|
|
907
|
+
const results = outcome.resources.flatMap((resource) => {
|
|
908
|
+
const resultSource = resource.source;
|
|
909
|
+
const edit = mutation.edits.get(resultSource);
|
|
910
|
+
return edit === undefined
|
|
911
|
+
? []
|
|
912
|
+
: [
|
|
913
|
+
buildSuccessfulTextMutationResult(
|
|
914
|
+
resource,
|
|
915
|
+
resultSource,
|
|
916
|
+
edit,
|
|
917
|
+
undefined,
|
|
918
|
+
mutation.resultPresentations.get(resultSource) ?? "plain",
|
|
919
|
+
),
|
|
920
|
+
];
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
return {
|
|
924
|
+
content: [new FileMutationAgentResult(results).toTextContent()],
|
|
925
|
+
details: { results },
|
|
926
|
+
};
|
|
639
927
|
}
|
|
640
928
|
|
|
641
929
|
async function anchorFailureToolResult(
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
): Promise<AgentToolResult<FileMutationBatchResult> | undefined>
|
|
646
|
-
{
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
930
|
+
core: TextEditorCore,
|
|
931
|
+
failure: TextResourceEditFailure,
|
|
932
|
+
context: ExtensionContext,
|
|
933
|
+
): Promise<AgentToolResult<FileMutationBatchResult> | undefined> {
|
|
934
|
+
if (failure.cause instanceof TextMutationAnchorAggregateError) {
|
|
935
|
+
const recovered = await Promise.all(
|
|
936
|
+
failure.cause.failures.map((cause) =>
|
|
937
|
+
anchorFailureToolResult(core, { ...failure, source: cause.source, cause }, context),
|
|
938
|
+
),
|
|
939
|
+
);
|
|
940
|
+
const results: FileMutationResult[] = [];
|
|
941
|
+
const anchorRecoveries: NonNullable<FileMutationBatchResult["anchorRecoveries"]>[number][] = [];
|
|
942
|
+
const messages: string[] = [];
|
|
943
|
+
for (const item of recovered) {
|
|
944
|
+
if (item === undefined) {
|
|
945
|
+
continue;
|
|
946
|
+
}
|
|
947
|
+
results.push(...(item.details.results ?? []));
|
|
948
|
+
anchorRecoveries.push(...(item.details.anchorRecoveries ?? []));
|
|
949
|
+
for (const block of item.content) {
|
|
950
|
+
if (block.type === "text") {
|
|
951
|
+
messages.push(block.text);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
650
954
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
const resolution = contextual.resolution;
|
|
654
|
-
const range = resolution.rejection?.contextRange;
|
|
655
|
-
|
|
656
|
-
if (range === undefined)
|
|
657
|
-
{
|
|
658
|
-
return undefined;
|
|
955
|
+
if (results.length === 0) {
|
|
956
|
+
return undefined;
|
|
659
957
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
958
|
+
return {
|
|
959
|
+
content: [{ type: "text", text: messages.join("\n\n") }],
|
|
960
|
+
details: { results, anchorRecoveries },
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
if (!(failure.cause instanceof TextMutationAnchorResolutionError)) {
|
|
964
|
+
return undefined;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const contextual = failure.cause;
|
|
968
|
+
const resolution = contextual.resolution;
|
|
969
|
+
if (resolution.recovery === undefined) {
|
|
970
|
+
await resolution.refreshRecovery();
|
|
971
|
+
}
|
|
972
|
+
const recovery = resolution.recovery;
|
|
973
|
+
if (recovery?.kind === "timed-out") {
|
|
974
|
+
return failureToolResult(
|
|
975
|
+
contextual.source,
|
|
976
|
+
failure.code,
|
|
977
|
+
`${failure.message}; recovery timed out`,
|
|
978
|
+
"not-applied",
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
const windows =
|
|
983
|
+
recovery?.kind === "candidates"
|
|
984
|
+
? recoveryWindows(
|
|
985
|
+
recovery.candidates.map(({ range }) => range),
|
|
986
|
+
core.recoveryContextLines(),
|
|
987
|
+
)
|
|
988
|
+
: resolution.rejection?.contextRange === undefined
|
|
989
|
+
? []
|
|
990
|
+
: [resolution.rejection.contextRange];
|
|
991
|
+
if (windows.length === 0) {
|
|
992
|
+
return undefined;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
const reads = await Promise.all(
|
|
996
|
+
windows.map((range) =>
|
|
997
|
+
readTextAnchorRecovery(
|
|
998
|
+
core,
|
|
999
|
+
{ path: contextual.source, ...range },
|
|
1000
|
+
{
|
|
1001
|
+
cwd: context.cwd,
|
|
1002
|
+
...(context.signal !== undefined && { signal: context.signal }),
|
|
1003
|
+
},
|
|
1004
|
+
),
|
|
1005
|
+
),
|
|
1006
|
+
);
|
|
1007
|
+
const recoveryTexts: string[] = [];
|
|
1008
|
+
for (const read of reads) {
|
|
1009
|
+
if (read === undefined || read.isError === true) {
|
|
1010
|
+
return undefined;
|
|
669
1011
|
}
|
|
1012
|
+
recoveryTexts.push(
|
|
1013
|
+
...read.content.filter((block) => block.type === "text").map((block) => block.text),
|
|
1014
|
+
);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
const result = new FileMutationResult({
|
|
1018
|
+
ok: false,
|
|
1019
|
+
path: contextual.source,
|
|
1020
|
+
errors: [{ path: contextual.source, code: failure.code, reason: failure.message }],
|
|
1021
|
+
});
|
|
1022
|
+
const recoveryContext = recoveryTexts.join("\n");
|
|
1023
|
+
const rejectionCode = resolution.rejection?.code;
|
|
1024
|
+
const content =
|
|
1025
|
+
rejectionCode === "stale"
|
|
1026
|
+
? formatStaleAnchorMessage(
|
|
1027
|
+
{
|
|
1028
|
+
guardId: "stale-anchor",
|
|
1029
|
+
effect: "not-applied",
|
|
1030
|
+
toolName: contextual.toolName,
|
|
1031
|
+
field: contextual.field,
|
|
1032
|
+
path: contextual.source,
|
|
1033
|
+
anchor: contextual.anchor,
|
|
1034
|
+
...(recoveryContext.length > 0 && { context: recoveryContext }),
|
|
1035
|
+
} satisfies StaleAnchorMessageDetails,
|
|
1036
|
+
resolution.message,
|
|
1037
|
+
)
|
|
1038
|
+
: formatRejectedAnchorMessage(contextual, rejectionCode, resolution.message, recoveryContext);
|
|
1039
|
+
|
|
1040
|
+
return {
|
|
1041
|
+
content: [{ type: "text", text: content }],
|
|
1042
|
+
details: {
|
|
1043
|
+
results: [result],
|
|
1044
|
+
effect: "not-applied",
|
|
1045
|
+
anchorRecovery: true,
|
|
1046
|
+
...(recovery?.kind === "candidates" && {
|
|
1047
|
+
anchorRecoveries: [
|
|
1048
|
+
{
|
|
1049
|
+
field: contextual.field,
|
|
1050
|
+
path: contextual.source,
|
|
1051
|
+
anchor: contextual.anchor,
|
|
1052
|
+
total: recovery.total,
|
|
1053
|
+
candidates: recovery.candidates,
|
|
1054
|
+
},
|
|
1055
|
+
],
|
|
1056
|
+
}),
|
|
1057
|
+
} as FileMutationBatchResult,
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
670
1060
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
1061
|
+
function formatRejectedAnchorMessage(
|
|
1062
|
+
failure: TextMutationAnchorResolutionError,
|
|
1063
|
+
code: TextAnchorRejection["code"] | undefined,
|
|
1064
|
+
reason: string,
|
|
1065
|
+
recoveryContext: string,
|
|
1066
|
+
): string {
|
|
1067
|
+
const state =
|
|
1068
|
+
code === "ambiguous"
|
|
1069
|
+
? "is ambiguous"
|
|
1070
|
+
: code === "missing"
|
|
1071
|
+
? "was not found"
|
|
1072
|
+
: code === "invalid"
|
|
1073
|
+
? "is invalid"
|
|
1074
|
+
: "could not be resolved";
|
|
1075
|
+
const guidance =
|
|
1076
|
+
code === "ambiguous"
|
|
1077
|
+
? "Use a unique text span or one of the candidate anchors below."
|
|
1078
|
+
: "If the intended text is represented below, use its candidate anchor. Otherwise, reread the relevant section and choose a current anchor.";
|
|
1079
|
+
const context = recoveryContext.length === 0 ? "" : `\n\n${recoveryContext}`;
|
|
1080
|
+
return `[SYSTEM] ${failure.toolName} blocked: ${failure.field} anchor "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
|
|
1081
|
+
}
|
|
689
1082
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
1083
|
+
function recoveryWindows(
|
|
1084
|
+
ranges: readonly TextAnchorRecoveryCandidateRange[],
|
|
1085
|
+
contextLines: number,
|
|
1086
|
+
): TextAnchorRecoveryRange[] {
|
|
1087
|
+
const windows = ranges
|
|
1088
|
+
.map((range) => ({
|
|
1089
|
+
offset: Math.max(1, range.start.lineNumber - contextLines),
|
|
1090
|
+
limit: range.end.lineNumber - range.start.lineNumber + 1 + contextLines * 2,
|
|
1091
|
+
}))
|
|
1092
|
+
.sort((left, right) => left.offset - right.offset);
|
|
1093
|
+
const merged: TextAnchorRecoveryRange[] = [];
|
|
1094
|
+
for (const window of windows) {
|
|
1095
|
+
const previous = merged[merged.length - 1];
|
|
1096
|
+
if (previous === undefined || window.offset > previous.offset + previous.limit) {
|
|
1097
|
+
merged.push(window);
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
const end = Math.max(previous.offset + previous.limit, window.offset + window.limit);
|
|
1101
|
+
merged[merged.length - 1] = { offset: previous.offset, limit: end - previous.offset };
|
|
1102
|
+
}
|
|
1103
|
+
return merged;
|
|
698
1104
|
}
|
|
699
1105
|
|
|
700
1106
|
export async function buildFailedTextMutationResult(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
): Promise<AgentToolResult<FileMutationBatchResult>>
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
: failureToolResult(failure.source, failure.code, failure.message, effect);
|
|
1107
|
+
core: TextEditorCore,
|
|
1108
|
+
failure: TextResourceEditFailure,
|
|
1109
|
+
context: ExtensionContext,
|
|
1110
|
+
effect: "applied" | "not-applied" | "unknown" = "not-applied",
|
|
1111
|
+
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
1112
|
+
return effect === "not-applied"
|
|
1113
|
+
? ((await anchorFailureToolResult(core, failure, context)) ??
|
|
1114
|
+
failureToolResult(failure.source, failure.code, failure.message, effect))
|
|
1115
|
+
: failureToolResult(failure.source, failure.code, failure.message, effect);
|
|
711
1116
|
}
|
|
712
1117
|
|
|
713
1118
|
function failureToolResult(
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
): { content: [{ type: "text"; text: string
|
|
719
|
-
{
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
};
|
|
1119
|
+
source: string,
|
|
1120
|
+
code: string,
|
|
1121
|
+
reason: string,
|
|
1122
|
+
effect: "not-applied" | "applied" | "unknown",
|
|
1123
|
+
): { content: [{ type: "text"; text: string }]; details: FileMutationBatchResult } {
|
|
1124
|
+
const result = new FileMutationResult({
|
|
1125
|
+
ok: false,
|
|
1126
|
+
path: source,
|
|
1127
|
+
errors: [{ path: source, code, reason }],
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1130
|
+
return {
|
|
1131
|
+
content: [new FileMutationAgentResult(result).toTextContent()],
|
|
1132
|
+
details: { results: [result], effect } as FileMutationBatchResult,
|
|
1133
|
+
};
|
|
730
1134
|
}
|
|
731
1135
|
|
|
732
1136
|
function failedResourceEdit(
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
): TextResourcesEditOutcome<never>
|
|
738
|
-
{
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1137
|
+
source: string,
|
|
1138
|
+
code: TextResourceEditFailure["code"],
|
|
1139
|
+
message: string,
|
|
1140
|
+
cause?: unknown,
|
|
1141
|
+
): TextResourcesEditOutcome<never> {
|
|
1142
|
+
return {
|
|
1143
|
+
kind: "failed",
|
|
1144
|
+
failure: { code, source, message, ...(cause !== undefined && { cause }) },
|
|
1145
|
+
completed: [],
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
function isResourcesEditOutcome(value: unknown): value is TextResourcesEditOutcome<unknown> {
|
|
1150
|
+
return (
|
|
1151
|
+
typeof value === "object" &&
|
|
1152
|
+
value !== null &&
|
|
1153
|
+
((value as { kind?: unknown }).kind === "completed" ||
|
|
1154
|
+
(value as { kind?: unknown }).kind === "failed")
|
|
1155
|
+
);
|
|
744
1156
|
}
|
|
745
1157
|
|
|
746
|
-
function
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
&& value !== null
|
|
750
|
-
&& ((value as { kind?: unknown; }).kind === "completed" || (value as { kind?: unknown; }).kind === "failed");
|
|
1158
|
+
function asMutationParameters<TParameters extends TSchema>(value: unknown): Static<TParameters> {
|
|
1159
|
+
// oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
|
|
1160
|
+
return value as Static<TParameters>;
|
|
751
1161
|
}
|
|
752
1162
|
|
|
753
|
-
function errorMessage(error: unknown): string
|
|
754
|
-
|
|
755
|
-
return error instanceof Error ? error.message : String(error);
|
|
1163
|
+
function errorMessage(error: unknown): string {
|
|
1164
|
+
return error instanceof Error ? error.message : String(error);
|
|
756
1165
|
}
|