pi-agent-ide 0.1.1 → 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 +11 -5
- 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 +21 -17
- package/docs/configuration.md +149 -52
- package/docs/development.md +105 -5
- package/docs/extensions.md +64 -4
- package/docs/generated/tool-catalog/css.md +7 -6
- package/docs/generated/tool-catalog/html.md +6 -5
- package/docs/generated/tool-catalog/javascript.md +8 -6
- package/docs/generated/tool-catalog/json.md +7 -6
- package/docs/generated/tool-catalog/markdown.md +6 -5
- package/docs/generated/tool-catalog/toml.md +6 -5
- package/docs/generated/tool-catalog/typescript.md +8 -6
- package/docs/generated/tool-catalog/yaml.md +6 -5
- package/docs/tools.md +88 -6
- package/node_modules/pi-agent-doctor/package.json +8 -5
- 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/executable.ts +33 -0
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +30 -4
- package/node_modules/pi-agent-filesystem/index.ts +4 -3
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem/runtime/entry-20.js +2 -0
- package/node_modules/pi-agent-filesystem-image/package.json +4 -4
- package/node_modules/pi-agent-filesystem-image/runtime/entry-21.js +2 -0
- package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
- package/node_modules/pi-agent-filesystem-pdf/runtime/entry-22.js +2 -0
- package/node_modules/pi-agent-filesystem-text/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/runtime/entry-23.js +2 -0
- package/node_modules/pi-agent-ide-ast/package.json +11 -10
- 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/outline.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +25 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +13 -5
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +6 -0
- package/node_modules/pi-agent-ide-changes/index.ts +6 -2
- package/node_modules/pi-agent-ide-changes/package.json +8 -7
- 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 +6 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +1 -1
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +1 -1
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +1 -0
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +1 -1
- package/node_modules/pi-agent-ide-changes/src/doctor-plugin.ts +31 -1
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +5 -0
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +7 -0
- package/node_modules/pi-agent-ide-formatter/package.json +4 -4
- package/node_modules/pi-agent-ide-formatter/runtime/entry-28.js +2 -0
- package/node_modules/pi-agent-ide-formatter/src/catalog.ts +34 -0
- package/node_modules/pi-agent-ide-formatter/src/doctor-plugin.ts +115 -63
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +71 -28
- package/node_modules/pi-agent-ide-languages/package.json +3 -3
- package/node_modules/pi-agent-ide-languages/runtime/entry-29.js +2 -0
- package/node_modules/pi-agent-ide-lint/index.ts +30 -155
- package/node_modules/pi-agent-ide-lint/package.json +8 -7
- package/node_modules/pi-agent-ide-lint/runtime/entry-30.js +2 -0
- package/node_modules/pi-agent-ide-lint/src/catalog.ts +14 -2
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +60 -4
- package/node_modules/pi-agent-ide-lint/src/diagnostics.ts +3 -1
- package/node_modules/pi-agent-ide-lint/src/doctor-plugin.ts +115 -64
- package/node_modules/pi-agent-ide-lint/src/registry.ts +72 -27
- package/node_modules/pi-agent-ide-lsp/index.ts +35 -134
- package/node_modules/pi-agent-ide-lsp/package.json +9 -8
- package/node_modules/pi-agent-ide-lsp/runtime/entry-31.js +2 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +113 -0
- package/node_modules/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -53
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +94 -27
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +2 -1
- 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 +137 -144
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +2 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +9 -32
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +86 -50
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +1 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +8 -6
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +5 -5
- 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-invariant/package.json +12 -0
- package/node_modules/pi-agent-invariant/runtime/entry-33.js +1 -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/pdf-converter.ts +3 -2
- package/node_modules/pi-agent-read/package.json +11 -9
- 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/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/tools/read.ts +113 -2
- package/node_modules/pi-agent-read/src/core/extension.ts +19 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +85 -13
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +26 -10
- 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 +102 -12
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +27 -3
- 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 +532 -46
- 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/content-converter.ts +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +1 -1
- package/node_modules/pi-agent-search/package.json +7 -6
- 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/search.ts +4 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +99 -27
- package/node_modules/pi-agent-search/src/core/search-config.ts +98 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +32 -28
- package/node_modules/pi-agent-search/src/core/search-timeout.ts +54 -0
- package/node_modules/pi-agent-search-text/index.ts +53 -3
- package/node_modules/pi-agent-search-text/package.json +9 -9
- 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 +20 -1
- package/node_modules/pi-agent-search-text/src/persisted-result.ts +56 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +36 -34
- package/node_modules/pi-agent-search-text/src/search-query.ts +254 -71
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +68 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +71 -117
- package/node_modules/pi-agent-search-text/src/search-result.ts +1 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +276 -110
- 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 +23 -0
- package/node_modules/pi-agent-text/src/stored-text.ts +14 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +160 -16
- package/node_modules/pi-agent-text/src/text-document.ts +26 -5
- package/node_modules/pi-agent-text/src/text-target.ts +105 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +7 -4
- 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 +6 -0
- 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 +8 -2
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +10 -6
- 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 +32 -1
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +20 -12
- package/node_modules/pi-agent-text-editor/package.json +22 -21
- 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 +2 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +38 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +30 -15
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +10 -13
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +12 -5
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +15 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +14 -10
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -2
- 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 +1 -1
- 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-registry.ts +96 -8
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +4 -1
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +194 -35
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +43 -13
- 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 +75 -5
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +7 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +541 -130
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +5 -9
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +228 -6
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +50 -70
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +25 -26
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +30 -21
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +57 -71
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +30 -27
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -0
- package/node_modules/pi-agent-text-editor-argument-order/package.json +3 -3
- package/node_modules/pi-agent-text-editor-argument-order/runtime/entry-69.js +2 -0
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +1 -1
- package/node_modules/pi-agent-text-editor-overwrite/package.json +4 -3
- package/node_modules/pi-agent-text-editor-overwrite/runtime/entry-70.js +2 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +21 -1
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -3
- 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 +1 -1
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +77 -22
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +140 -24
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +274 -43
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +33 -6
- 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 +7 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +265 -105
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +96 -15
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +22 -6
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -4
- 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 +175 -32
- 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 +16 -6
- package/node_modules/pi-agent-web/package.json +8 -6
- 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 +128 -24
- package/node_modules/pi-agent-web-html/package.json +6 -3
- 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 +19 -6
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-image/runtime/entry-77.js +2 -0
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/runtime/entry-78.js +2 -0
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/node_modules/pi-agent-web-text/runtime/entry-79.js +2 -0
- package/package.json +68 -54
- package/src/api/code-view.ts +4 -0
- package/src/api/connect-tip-provider.ts +49 -0
- package/src/api/plugin-protocol.ts +41 -2
- package/src/api/tips.ts +77 -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 +217 -13
- package/src/api/toolchain.ts +0 -5
- package/src/code-view/diagnostic-view.ts +117 -26
- package/src/code-view/source-view.ts +1 -1
- package/src/composite/builtin-extensions.ts +12 -6
- package/src/composite/extensions-config.ts +137 -0
- package/src/composite/selection.ts +58 -3
- package/src/core/diagnostic-store.ts +244 -0
- package/src/core/extension.ts +40 -0
- package/src/core/ide-core.ts +48 -3
- package/src/doctor/config-writer.ts +1 -1
- package/src/doctor/core.ts +47 -0
- package/src/doctor/discovery.ts +10 -2
- package/src/doctor/extension.ts +12 -1
- package/src/doctor/inventory.ts +24 -6
- package/src/doctor/run.ts +68 -87
- package/src/doctor/tip-provider.ts +92 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +4 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
- 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/package.json +4 -4
- 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/package.json +4 -4
- 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-web/index.ts +16 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +6 -3
- 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 +19 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
- 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/package.json +4 -4
- 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/package.json +4 -4
- 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 +128 -24
- package/src/extensions/pi-agent-read/package.json +11 -9
- 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/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +113 -2
- package/src/extensions/pi-agent-read/src/core/extension.ts +19 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +85 -13
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +26 -10
- 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 +102 -12
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +27 -3
- 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 +532 -46
- package/src/extensions/pi-agent-search/package.json +7 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +53 -3
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
- 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 +20 -1
- 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 +36 -34
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +254 -71
- 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 +71 -117
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +276 -110
- 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/search.ts +4 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +99 -27
- package/src/extensions/pi-agent-search/src/core/search-config.ts +98 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +32 -28
- package/src/extensions/pi-agent-search/src/core/search-timeout.ts +54 -0
- package/src/extensions/pi-agent-text-editor/package.json +22 -21
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +7 -4
- 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 +6 -0
- 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 +8 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +10 -6
- 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 +32 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +20 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +3 -3
- 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-overwrite/index.ts +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +4 -3
- 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 +21 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -3
- 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 +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +77 -22
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +140 -24
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +274 -43
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +33 -6
- 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 +7 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +265 -105
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +96 -15
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +22 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -4
- 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 +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +38 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +30 -15
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +10 -13
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +12 -5
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +15 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +14 -10
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -2
- 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 +1 -1
- 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-registry.ts +96 -8
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +4 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +194 -35
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +43 -13
- 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 +75 -5
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +7 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +541 -130
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +5 -9
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +228 -6
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +50 -70
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +25 -26
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +30 -21
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +57 -71
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +30 -27
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -0
- package/src/pi-agent-ide.ts +15 -3
- package/src/plugins/pi-agent-ide-ast/package.json +11 -10
- 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/outline.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +25 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +13 -5
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +6 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +6 -2
- package/src/plugins/pi-agent-ide-changes/package.json +8 -7
- 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 +6 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +1 -1
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +1 -1
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +1 -0
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +1 -1
- package/src/plugins/pi-agent-ide-changes/src/doctor-plugin.ts +31 -1
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +5 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +7 -0
- 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/package.json +4 -4
- package/src/plugins/pi-agent-ide-formatter/runtime/entry-28.js +2 -0
- package/src/plugins/pi-agent-ide-formatter/src/catalog.ts +34 -0
- package/src/plugins/pi-agent-ide-formatter/src/doctor-plugin.ts +115 -63
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +71 -28
- package/src/plugins/pi-agent-ide-languages/package.json +3 -3
- package/src/plugins/pi-agent-ide-languages/runtime/entry-29.js +2 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +30 -155
- package/src/plugins/pi-agent-ide-lint/package.json +8 -7
- package/src/plugins/pi-agent-ide-lint/runtime/entry-30.js +2 -0
- package/src/plugins/pi-agent-ide-lint/src/catalog.ts +14 -2
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +60 -4
- package/src/plugins/pi-agent-ide-lint/src/diagnostics.ts +3 -1
- package/src/plugins/pi-agent-ide-lint/src/doctor-plugin.ts +115 -64
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +72 -27
- package/src/plugins/pi-agent-ide-lsp/index.ts +35 -134
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-31.js +2 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +113 -0
- package/src/plugins/pi-agent-ide-lsp/src/doctor-plugin.ts +108 -53
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +94 -27
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +2 -1
- 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 +137 -144
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +2 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +9 -32
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +86 -50
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +1 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +8 -6
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +5 -5
- package/src/post-edit/gate.ts +17 -141
- 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/registry.ts +8 -23
- package/src/toolchain/types.ts +6 -74
- package/node_modules/pi-agent-search-semantic/index.ts +0 -97
- package/node_modules/pi-agent-search-semantic/package.json +0 -17
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +0 -20
- package/node_modules/pi-agent-search-web/index.ts +0 -82
- package/node_modules/pi-agent-search-web/package.json +0 -20
- package/node_modules/pi-agent-search-web/src/config.ts +0 -560
- package/node_modules/pi-agent-search-web/src/doctor-plugin.ts +0 -40
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +0 -74
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +0 -81
- package/node_modules/pi-agent-search-web/src/providers/request.ts +0 -427
- package/node_modules/pi-agent-search-web/src/providers/response.ts +0 -353
- package/node_modules/pi-agent-search-web/src/search-format.ts +0 -24
- package/node_modules/pi-agent-search-web/src/search.ts +0 -376
- package/node_modules/pi-agent-search-web/src/types.ts +0 -141
- package/src/composite/config.ts +0 -100
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +0 -97
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +0 -17
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +0 -20
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +0 -82
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +0 -20
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +0 -560
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/doctor-plugin.ts +0 -40
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +0 -74
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +0 -81
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +0 -427
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +0 -353
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +0 -24
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +0 -376
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +0 -141
- package/src/toolchain/gate.ts +0 -305
- /package/{src/utils/required-value.ts → node_modules/pi-agent-invariant/src/index.ts} +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import { requiredValue } from "
|
|
1
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import type {
|
|
4
|
+
TextAnchorRecoveryCandidateRange,
|
|
5
|
+
TextAnchorRecoveryRange,
|
|
6
|
+
TextAnchorRejection,
|
|
7
|
+
TextSelectionRange,
|
|
8
|
+
TextTarget,
|
|
9
|
+
} from "pi-agent-text";
|
|
3
10
|
|
|
4
11
|
import {
|
|
5
12
|
type AgentToolResult,
|
|
@@ -8,8 +15,13 @@ import {
|
|
|
8
15
|
type ToolDefinition,
|
|
9
16
|
} from "@earendil-works/pi-coding-agent";
|
|
10
17
|
|
|
11
|
-
import { type FileMutationBatchResult, FileMutationResult } from "#src/api/mutation-result.js";
|
|
12
18
|
import {
|
|
19
|
+
type FileMutationBatchResult,
|
|
20
|
+
FileMutationResult,
|
|
21
|
+
type MutationResultPresentation,
|
|
22
|
+
} from "#src/api/mutation-result.js";
|
|
23
|
+
import {
|
|
24
|
+
isMutationAnchorValue,
|
|
13
25
|
mutationSource,
|
|
14
26
|
type TextMutation,
|
|
15
27
|
type TextMutationContext,
|
|
@@ -25,12 +37,15 @@ import { createUnifiedDiff } from "#src/core/mutation-result/diff.js";
|
|
|
25
37
|
import { FileMutationAgentResult } from "#src/core/mutation-result/file-mutation-agent-result.js";
|
|
26
38
|
import { readTextAnchorRecovery } from "#src/core/text-anchor-recovery.js";
|
|
27
39
|
import { applyTextChanges, TextChangeDocument } from "#src/core/text-change-engine.js";
|
|
40
|
+
import { resolvedTextAnchorType } from "#src/core/text-anchor-registry.js";
|
|
28
41
|
import { executeTextToolWithBatch } from "#src/core/text-edit-batch-registrar.js";
|
|
29
42
|
import {
|
|
30
43
|
contextualizeTextMutationAnchorError,
|
|
44
|
+
TextMutationAnchorAggregateError,
|
|
31
45
|
TextMutationAnchorResolutionError,
|
|
32
46
|
} from "#src/core/text-mutation-anchor-error.js";
|
|
33
47
|
import {
|
|
48
|
+
TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH,
|
|
34
49
|
type ToolCallInterceptionRenderStore,
|
|
35
50
|
withToolCallInterceptionRendering,
|
|
36
51
|
} from "#src/core/tool-call-interceptor/rendering.js";
|
|
@@ -48,7 +63,9 @@ import type {
|
|
|
48
63
|
TextResourceEditOutcome,
|
|
49
64
|
TextResourcesEditOutcome,
|
|
50
65
|
} from "#src/core/text-editor-core.js";
|
|
51
|
-
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";
|
|
52
69
|
import type { Static, TSchema } from "typebox";
|
|
53
70
|
|
|
54
71
|
export function createTextTool<TParameters extends TSchema>(
|
|
@@ -64,6 +81,8 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
64
81
|
defineTool<TParameters, FileMutationBatchResult, unknown>({
|
|
65
82
|
name: definition.name,
|
|
66
83
|
label: definition.name,
|
|
84
|
+
|
|
85
|
+
promptSnippet: definition.promptSnippet,
|
|
67
86
|
description: appendSchemaFieldOrder(definition.description, definition.parameters),
|
|
68
87
|
parameters: definition.parameters,
|
|
69
88
|
prepareArguments: (arguments_) =>
|
|
@@ -73,7 +92,7 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
73
92
|
arguments_,
|
|
74
93
|
definition.source.inherited ? definition.source.field : undefined,
|
|
75
94
|
getLastResolvedSource(),
|
|
76
|
-
definition.anchors
|
|
95
|
+
definition.anchors ?? [],
|
|
77
96
|
),
|
|
78
97
|
...(renderer?.renderShell !== undefined && { renderShell: renderer.renderShell }),
|
|
79
98
|
...(renderer?.renderCall !== undefined && { renderCall: renderer.renderCall }),
|
|
@@ -86,6 +105,11 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
86
105
|
asMutationParameters<TParameters>(parameters),
|
|
87
106
|
signal,
|
|
88
107
|
context,
|
|
108
|
+
(field, state) =>
|
|
109
|
+
annotations.resolveArguments(toolCallId, {
|
|
110
|
+
[TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
|
|
111
|
+
}),
|
|
112
|
+
getLastResolvedSource(),
|
|
89
113
|
);
|
|
90
114
|
return executeTextToolWithBatch(toolCallId, directExecute, signal, onUpdate, context);
|
|
91
115
|
},
|
|
@@ -95,8 +119,12 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
95
119
|
Object.defineProperty(tool, "promptGuidelines", {
|
|
96
120
|
enumerable: true,
|
|
97
121
|
get(): string[] | undefined {
|
|
98
|
-
const
|
|
99
|
-
|
|
122
|
+
const pluginGuideline = pluginPromptGuideline();
|
|
123
|
+
const guidelines = [
|
|
124
|
+
...(pluginGuideline === undefined ? [] : [pluginGuideline]),
|
|
125
|
+
...(definition.promptGuidelines ?? []),
|
|
126
|
+
];
|
|
127
|
+
return guidelines.length === 0 ? undefined : guidelines;
|
|
100
128
|
},
|
|
101
129
|
});
|
|
102
130
|
return tool;
|
|
@@ -107,7 +135,7 @@ function prepareGuardedArguments<TParameters extends TSchema>(
|
|
|
107
135
|
arguments_: unknown,
|
|
108
136
|
sourceField: string | undefined,
|
|
109
137
|
lastResolvedSource: string | undefined,
|
|
110
|
-
anchorFields:
|
|
138
|
+
anchorFields: NonNullable<TextMutationToolRegistration["anchors"]>,
|
|
111
139
|
): ReturnType<
|
|
112
140
|
NonNullable<ToolDefinition<TParameters, FileMutationBatchResult>["prepareArguments"]>
|
|
113
141
|
> {
|
|
@@ -118,10 +146,10 @@ function prepareGuardedArguments<TParameters extends TSchema>(
|
|
|
118
146
|
const required = (schema as { required?: unknown }).required;
|
|
119
147
|
const properties = (schema as { properties?: Record<string, { type?: unknown }> }).properties;
|
|
120
148
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
);
|
|
125
153
|
if (
|
|
126
154
|
sourceField !== undefined &&
|
|
127
155
|
!(sourceField in prepared) &&
|
|
@@ -152,6 +180,8 @@ function prepareGuardedArguments<TParameters extends TSchema>(
|
|
|
152
180
|
interface ResolvedMutationSources {
|
|
153
181
|
readonly fields: ReadonlyMap<string, string>;
|
|
154
182
|
readonly anchors: ReadonlyMap<string, readonly string[]>;
|
|
183
|
+
readonly implicitTargets: ReadonlyMap<string, readonly TextTarget[]>;
|
|
184
|
+
readonly targets: readonly TextTarget[];
|
|
155
185
|
readonly resources: readonly string[];
|
|
156
186
|
}
|
|
157
187
|
|
|
@@ -160,110 +190,256 @@ async function resolveMutationSources(
|
|
|
160
190
|
definition: TextMutationToolRegistration,
|
|
161
191
|
input: Readonly<Record<string, unknown>>,
|
|
162
192
|
context: { readonly cwd: string; readonly signal?: AbortSignal },
|
|
193
|
+
lastResolvedSource?: string,
|
|
163
194
|
): Promise<ResolvedMutationSources> {
|
|
164
|
-
const expandedByAnchor = new Map<string, readonly
|
|
165
|
-
const expandedBySourceField = new Map<string, readonly
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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> => {
|
|
176
207
|
try {
|
|
177
|
-
|
|
208
|
+
return await core.resolveTextAnchorResources(value, allKinds, context);
|
|
178
209
|
} catch (error) {
|
|
179
|
-
|
|
180
|
-
throw contextualizeTextMutationAnchorError(
|
|
181
|
-
error,
|
|
182
|
-
definition.name,
|
|
183
|
-
descriptor.field,
|
|
184
|
-
typeof source === "string" ? source : "",
|
|
185
|
-
value,
|
|
186
|
-
);
|
|
210
|
+
throw contextualizeTextMutationAnchorError(error, definition.name, field, source, value);
|
|
187
211
|
}
|
|
212
|
+
};
|
|
188
213
|
|
|
189
|
-
|
|
190
|
-
|
|
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}.`);
|
|
191
229
|
}
|
|
230
|
+
expandedBySourceField.set(
|
|
231
|
+
descriptor.sourceField,
|
|
232
|
+
mergeTargets(expandedBySourceField.get(descriptor.sourceField) ?? [], expanded),
|
|
233
|
+
);
|
|
234
|
+
}
|
|
192
235
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
|
|
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),
|
|
198
245
|
);
|
|
199
246
|
}
|
|
200
|
-
|
|
201
|
-
expandedByAnchor.set(descriptor.field, expanded);
|
|
202
|
-
expandedBySourceField.set(descriptor.sourceField, expanded);
|
|
203
247
|
}
|
|
204
248
|
|
|
205
249
|
const fields = new Map<string, string>();
|
|
206
250
|
const sourceDescriptors = [definition.source, ...(definition.source.targets ?? [])];
|
|
207
|
-
|
|
208
251
|
for (const descriptor of sourceDescriptors) {
|
|
209
252
|
const explicit = input[descriptor.field];
|
|
210
253
|
const explicitSource =
|
|
211
254
|
typeof explicit === "string" && explicit.length > 0 ? explicit : undefined;
|
|
212
255
|
const fallback = "fallbackTo" in descriptor ? fields.get(descriptor.fallbackTo) : undefined;
|
|
213
|
-
|
|
214
|
-
|
|
256
|
+
let expanded = expandedBySourceField.get(descriptor.field);
|
|
215
257
|
if (expanded !== undefined) {
|
|
216
|
-
if (explicitSource
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
throw new Error(
|
|
221
|
-
`${descriptor.field} must be omitted when a search anchor selects multiple resources.`,
|
|
222
|
-
);
|
|
223
|
-
}
|
|
258
|
+
if (explicitSource !== undefined && !expandedFromExplicitSource.has(descriptor.field)) {
|
|
259
|
+
const scoped = expanded.filter((target) =>
|
|
260
|
+
sameResource(explicitSource, target.source, context.cwd),
|
|
261
|
+
);
|
|
224
262
|
|
|
225
|
-
if (
|
|
263
|
+
if (scoped.length === 0) {
|
|
226
264
|
throw new Error(`Anchor does not belong to ${explicitSource}.`);
|
|
227
265
|
}
|
|
228
266
|
|
|
229
|
-
|
|
267
|
+
if (scoped.length !== expanded.length) {
|
|
268
|
+
expanded = scoped;
|
|
269
|
+
expandedBySourceField.set(descriptor.field, scoped);
|
|
270
|
+
explicitlyScopedSourceFields.add(descriptor.field);
|
|
271
|
+
}
|
|
230
272
|
}
|
|
231
|
-
|
|
273
|
+
fields.set(descriptor.field, requiredValue(expanded[0]).source);
|
|
232
274
|
continue;
|
|
233
275
|
}
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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`);
|
|
241
285
|
fields.set(descriptor.field, source);
|
|
242
286
|
}
|
|
243
287
|
|
|
244
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
|
+
}
|
|
245
303
|
|
|
246
304
|
for (const descriptor of definition.anchors ?? []) {
|
|
247
305
|
const expanded = expandedByAnchor.get(descriptor.field);
|
|
248
|
-
const
|
|
306
|
+
const value = input[descriptor.field];
|
|
249
307
|
|
|
308
|
+
if (typeof value === "string" && !isMutationAnchorValue(descriptor, value)) continue;
|
|
309
|
+
const source = fields.get(descriptor.sourceField);
|
|
250
310
|
if (expanded !== undefined) {
|
|
251
311
|
anchors.set(
|
|
252
312
|
descriptor.field,
|
|
253
|
-
source !== undefined &&
|
|
313
|
+
source !== undefined &&
|
|
314
|
+
(expanded.length === 1 || explicitlyScopedSourceFields.has(descriptor.sourceField))
|
|
315
|
+
? [source]
|
|
316
|
+
: [...new Set(expanded.map((target) => target.source))],
|
|
254
317
|
);
|
|
255
318
|
} else if (source !== undefined) {
|
|
256
|
-
|
|
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
|
+
);
|
|
257
327
|
}
|
|
258
328
|
}
|
|
259
|
-
|
|
329
|
+
const targets = [...expandedBySourceField.values()]
|
|
330
|
+
.flat()
|
|
331
|
+
.reduce<TextTarget[]>((all, target) => mergeTargets(all, [target]), []);
|
|
260
332
|
return {
|
|
261
333
|
fields,
|
|
262
334
|
anchors,
|
|
263
|
-
|
|
335
|
+
implicitTargets,
|
|
336
|
+
targets,
|
|
337
|
+
resources: [...new Set([...fields.values(), ...targets.map((target) => target.source)])],
|
|
264
338
|
};
|
|
265
339
|
}
|
|
266
340
|
|
|
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
|
+
}
|
|
349
|
+
|
|
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;
|
|
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
|
+
}
|
|
366
|
+
|
|
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
|
+
}
|
|
379
|
+
|
|
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
|
+
}
|
|
395
|
+
|
|
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.`);
|
|
429
|
+
}
|
|
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
|
+
}
|
|
438
|
+
|
|
439
|
+
interface ExecutedTextMutation extends TextMutation {
|
|
440
|
+
readonly resultPresentations: ReadonlyMap<string, MutationResultPresentation>;
|
|
441
|
+
}
|
|
442
|
+
|
|
267
443
|
function createMutationContext(
|
|
268
444
|
definition: TextMutationToolRegistration,
|
|
269
445
|
input: Readonly<Record<string, unknown>>,
|
|
@@ -271,11 +447,14 @@ function createMutationContext(
|
|
|
271
447
|
sources: ResolvedMutationSources,
|
|
272
448
|
texts: ReadonlyMap<string, string>,
|
|
273
449
|
resolveResourceAnchor: ResolveResourceTextAnchor,
|
|
274
|
-
|
|
450
|
+
publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
|
|
451
|
+
): MutationExecutionContext {
|
|
275
452
|
const documents = new Map(
|
|
276
453
|
[...texts].map(([source, text]) => [source, new TextChangeDocument(text)]),
|
|
277
454
|
);
|
|
278
455
|
const anchorCache = new Map<string, Promise<ReadonlyMap<string, TextAnchor>>>();
|
|
456
|
+
|
|
457
|
+
const majorAnchorSources = new Set<string>();
|
|
279
458
|
const sourceFor = (field: string): string => {
|
|
280
459
|
const source = sources.fields.get(field);
|
|
281
460
|
|
|
@@ -305,33 +484,68 @@ function createMutationContext(
|
|
|
305
484
|
const descriptor = (definition.anchors ?? []).find((anchor) => anchor.field === field);
|
|
306
485
|
const value = input[field];
|
|
307
486
|
const anchorSources = sources.anchors.get(field);
|
|
487
|
+
const implicitTargets = sources.implicitTargets.get(field);
|
|
308
488
|
|
|
309
|
-
if (descriptor === undefined
|
|
489
|
+
if (descriptor === undefined) {
|
|
310
490
|
throw new Error(
|
|
311
491
|
`Mutation tool ${definition.name} tried to resolve undeclared anchor ${field}`,
|
|
312
492
|
);
|
|
313
493
|
}
|
|
314
494
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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);
|
|
505
|
+
}
|
|
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
|
+
}
|
|
542
|
+
|
|
543
|
+
if (explicitAnchors === undefined) {
|
|
544
|
+
throw new Error(
|
|
545
|
+
`Mutation tool ${definition.name} tried to resolve undeclared anchor ${field}`,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
return explicitAnchors;
|
|
335
549
|
})();
|
|
336
550
|
anchorCache.set(field, pending);
|
|
337
551
|
return pending;
|
|
@@ -364,15 +578,59 @@ function createMutationContext(
|
|
|
364
578
|
|
|
365
579
|
return requiredValue(resolved.values().next().value);
|
|
366
580
|
},
|
|
581
|
+
|
|
582
|
+
resultPresentationFor(source): MutationResultPresentation {
|
|
583
|
+
return [...majorAnchorSources].some((candidate) =>
|
|
584
|
+
sameResource(candidate, source, invocation.cwd),
|
|
585
|
+
)
|
|
586
|
+
? "major-anchor"
|
|
587
|
+
: "plain";
|
|
588
|
+
},
|
|
367
589
|
};
|
|
368
590
|
}
|
|
369
591
|
|
|
370
|
-
function
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
+
};
|
|
602
|
+
}
|
|
603
|
+
|
|
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
|
+
}),
|
|
375
630
|
);
|
|
631
|
+
if (failures.length > 0) {
|
|
632
|
+
throw new TextMutationAnchorAggregateError(failures);
|
|
633
|
+
}
|
|
376
634
|
}
|
|
377
635
|
|
|
378
636
|
function sameResource(left: string, right: string, cwd: string): boolean {
|
|
@@ -408,10 +666,16 @@ export async function previewTextMutation(
|
|
|
408
666
|
})),
|
|
409
667
|
{ cwd: request.cwd, ...(request.signal !== undefined && { signal: request.signal }) },
|
|
410
668
|
async (texts, resolveAnchor) => {
|
|
411
|
-
const
|
|
412
|
-
|
|
669
|
+
const mutationContext = createMutationContext(
|
|
670
|
+
definition,
|
|
413
671
|
request.input,
|
|
672
|
+
request,
|
|
673
|
+
sources,
|
|
674
|
+
texts,
|
|
675
|
+
resolveAnchor,
|
|
414
676
|
);
|
|
677
|
+
await preflightMutationAnchors(definition, request.input, mutationContext);
|
|
678
|
+
const mutation = await definition.mutate(mutationContext, request.input);
|
|
415
679
|
|
|
416
680
|
return {
|
|
417
681
|
changes: new Map([...mutation.edits].map(([source, edit]) => [source, edit.changes])),
|
|
@@ -424,12 +688,15 @@ export async function previewTextMutation(
|
|
|
424
688
|
}
|
|
425
689
|
}
|
|
426
690
|
|
|
691
|
+
/** Executes a mutation, using read history only when neither a source nor an anchor owns it. */
|
|
427
692
|
export async function executeTextMutation<TParameters extends TSchema>(
|
|
428
693
|
core: TextEditorCore,
|
|
429
694
|
definition: TextMutationToolRegistration<TParameters>,
|
|
430
695
|
parameters: Static<TParameters>,
|
|
431
696
|
signal: AbortSignal | undefined,
|
|
432
697
|
context: ExtensionContext,
|
|
698
|
+
publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
|
|
699
|
+
lastResolvedSource?: string,
|
|
433
700
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
434
701
|
const source = mutationSource(definition, parameters);
|
|
435
702
|
const pipeline = await core.executeEdit(
|
|
@@ -441,7 +708,13 @@ export async function executeTextMutation<TParameters extends TSchema>(
|
|
|
441
708
|
},
|
|
442
709
|
async (state) => {
|
|
443
710
|
try {
|
|
444
|
-
const sources = await resolveMutationSources(
|
|
711
|
+
const sources = await resolveMutationSources(
|
|
712
|
+
core,
|
|
713
|
+
definition,
|
|
714
|
+
state.input,
|
|
715
|
+
state,
|
|
716
|
+
lastResolvedSource,
|
|
717
|
+
);
|
|
445
718
|
const outcome = await core.editTexts(
|
|
446
719
|
sources.resources.map((resourceSource) => ({
|
|
447
720
|
source: resourceSource,
|
|
@@ -454,15 +727,23 @@ export async function executeTextMutation<TParameters extends TSchema>(
|
|
|
454
727
|
...(state.signal !== undefined && { signal: state.signal }),
|
|
455
728
|
},
|
|
456
729
|
async (texts, resolveAnchor) => {
|
|
457
|
-
const
|
|
458
|
-
|
|
730
|
+
const mutationContext = createMutationContext(
|
|
731
|
+
definition,
|
|
459
732
|
state.input,
|
|
733
|
+
state,
|
|
734
|
+
sources,
|
|
735
|
+
texts,
|
|
736
|
+
resolveAnchor,
|
|
737
|
+
publishAnchorRenderState,
|
|
460
738
|
);
|
|
739
|
+
await preflightMutationAnchors(definition, state.input, mutationContext);
|
|
740
|
+
const mutation = await definition.mutate(mutationContext, state.input);
|
|
741
|
+
const executedMutation = withResultPresentations(mutation, mutationContext);
|
|
461
742
|
return {
|
|
462
743
|
changes: new Map(
|
|
463
744
|
[...mutation.edits].map(([editSource, edit]) => [editSource, edit.changes]),
|
|
464
745
|
),
|
|
465
|
-
result:
|
|
746
|
+
result: executedMutation,
|
|
466
747
|
};
|
|
467
748
|
},
|
|
468
749
|
);
|
|
@@ -519,6 +800,8 @@ export function buildSuccessfulTextMutationResult(
|
|
|
519
800
|
resultSource: string,
|
|
520
801
|
edit: TextMutationEdit,
|
|
521
802
|
diffAfterContent = resource.after.content,
|
|
803
|
+
resultPresentation: MutationResultPresentation = "plain",
|
|
804
|
+
editCount = 1,
|
|
522
805
|
): FileMutationResult {
|
|
523
806
|
const before = resource.before.content;
|
|
524
807
|
const finalAfter = resource.after.content;
|
|
@@ -543,13 +826,15 @@ export function buildSuccessfulTextMutationResult(
|
|
|
543
826
|
path: resultSource,
|
|
544
827
|
diffs: [unified.diff],
|
|
545
828
|
files: [{ path: resultSource, action: edit.action }],
|
|
546
|
-
editCount
|
|
829
|
+
editCount,
|
|
547
830
|
addedLines: unified.stats.added,
|
|
548
831
|
removedLines: unified.stats.removed,
|
|
549
832
|
beforeContentMap: { [resultSource]: before },
|
|
550
833
|
afterContent: finalAfter,
|
|
551
834
|
rawChanges,
|
|
552
835
|
afterDocument: resource.after,
|
|
836
|
+
|
|
837
|
+
resultPresentation,
|
|
553
838
|
});
|
|
554
839
|
}
|
|
555
840
|
|
|
@@ -618,13 +903,21 @@ async function buildToolResult(
|
|
|
618
903
|
return failureToolResult(source, outcome.failure.code, message, effect);
|
|
619
904
|
}
|
|
620
905
|
|
|
621
|
-
const mutation = outcome.result as
|
|
906
|
+
const mutation = outcome.result as ExecutedTextMutation;
|
|
622
907
|
const results = outcome.resources.flatMap((resource) => {
|
|
623
908
|
const resultSource = resource.source;
|
|
624
909
|
const edit = mutation.edits.get(resultSource);
|
|
625
910
|
return edit === undefined
|
|
626
911
|
? []
|
|
627
|
-
: [
|
|
912
|
+
: [
|
|
913
|
+
buildSuccessfulTextMutationResult(
|
|
914
|
+
resource,
|
|
915
|
+
resultSource,
|
|
916
|
+
edit,
|
|
917
|
+
undefined,
|
|
918
|
+
mutation.resultPresentations.get(resultSource) ?? "plain",
|
|
919
|
+
),
|
|
920
|
+
];
|
|
628
921
|
});
|
|
629
922
|
|
|
630
923
|
return {
|
|
@@ -638,29 +931,87 @@ async function anchorFailureToolResult(
|
|
|
638
931
|
failure: TextResourceEditFailure,
|
|
639
932
|
context: ExtensionContext,
|
|
640
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
|
+
}
|
|
954
|
+
}
|
|
955
|
+
if (results.length === 0) {
|
|
956
|
+
return undefined;
|
|
957
|
+
}
|
|
958
|
+
return {
|
|
959
|
+
content: [{ type: "text", text: messages.join("\n\n") }],
|
|
960
|
+
details: { results, anchorRecoveries },
|
|
961
|
+
};
|
|
962
|
+
}
|
|
641
963
|
if (!(failure.cause instanceof TextMutationAnchorResolutionError)) {
|
|
642
964
|
return undefined;
|
|
643
965
|
}
|
|
644
966
|
|
|
645
967
|
const contextual = failure.cause;
|
|
646
968
|
const resolution = contextual.resolution;
|
|
647
|
-
|
|
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
|
+
}
|
|
648
981
|
|
|
649
|
-
|
|
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) {
|
|
650
992
|
return undefined;
|
|
651
993
|
}
|
|
652
994
|
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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
|
+
),
|
|
660
1006
|
);
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
1007
|
+
const recoveryTexts: string[] = [];
|
|
1008
|
+
for (const read of reads) {
|
|
1009
|
+
if (read === undefined || read.isError === true) {
|
|
1010
|
+
return undefined;
|
|
1011
|
+
}
|
|
1012
|
+
recoveryTexts.push(
|
|
1013
|
+
...read.content.filter((block) => block.type === "text").map((block) => block.text),
|
|
1014
|
+
);
|
|
664
1015
|
}
|
|
665
1016
|
|
|
666
1017
|
const result = new FileMutationResult({
|
|
@@ -668,30 +1019,90 @@ async function anchorFailureToolResult(
|
|
|
668
1019
|
path: contextual.source,
|
|
669
1020
|
errors: [{ path: contextual.source, code: failure.code, reason: failure.message }],
|
|
670
1021
|
});
|
|
671
|
-
const recoveryContext =
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
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);
|
|
684
1039
|
|
|
685
1040
|
return {
|
|
686
|
-
content: [{ type: "text", text:
|
|
1041
|
+
content: [{ type: "text", text: content }],
|
|
687
1042
|
details: {
|
|
688
1043
|
results: [result],
|
|
689
1044
|
effect: "not-applied",
|
|
690
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
|
+
}),
|
|
691
1057
|
} as FileMutationBatchResult,
|
|
692
1058
|
};
|
|
693
1059
|
}
|
|
694
1060
|
|
|
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
|
+
}
|
|
1082
|
+
|
|
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;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
695
1106
|
export async function buildFailedTextMutationResult(
|
|
696
1107
|
core: TextEditorCore,
|
|
697
1108
|
failure: TextResourceEditFailure,
|