pi-agent-ide 0.9.8 → 1.0.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 +62 -0
- package/README.md +5 -3
- package/dist/chunk-2EY3LEZ7.js +1 -0
- package/dist/chunk-2QCE7GOV.js +1 -0
- package/dist/chunk-3V3OQO5S.js +118 -0
- package/dist/chunk-45EJ4762.js +33 -0
- package/dist/chunk-4AEYLVSR.js +5 -0
- package/dist/chunk-4DLSZYUO.js +1 -0
- package/dist/chunk-54EFJYUB.js +1 -0
- package/dist/{chunk-5DN2XBVI.js → chunk-5TPYHUJV.js} +1 -1
- package/dist/{chunk-KQV2ZXLP.js → chunk-6DC2Q5BI.js} +1 -1
- package/dist/chunk-72WO7H5T.js +1 -0
- package/dist/chunk-72X24ARV.js +2 -0
- package/dist/chunk-AB6RSWMB.js +23 -0
- package/dist/chunk-AKUBFJAR.js +1 -0
- package/dist/chunk-ASVMQMPX.js +10 -0
- package/dist/chunk-BW3XONMZ.js +1 -0
- package/dist/{chunk-R2U5WXYR.js → chunk-D23NS4VV.js} +1 -1
- package/dist/chunk-DSB6A5P5.js +53 -0
- package/dist/chunk-E4V4VNRM.js +3 -0
- package/dist/chunk-E6G3UVS7.js +1 -0
- package/dist/chunk-E7JBYW43.js +1 -0
- package/dist/chunk-FVWMI4GP.js +1 -0
- package/dist/chunk-GDIF3WT6.js +12 -0
- package/dist/chunk-GNYFA6FS.js +2 -0
- package/dist/{chunk-DHOIQZUF.js → chunk-GQXZEOND.js} +1 -1
- package/dist/chunk-GT2JPOBM.js +1 -0
- package/dist/chunk-GTZOIJCH.js +1 -0
- package/dist/chunk-HRZAIZGR.js +1 -0
- package/dist/{chunk-H6FEBUAP.js → chunk-HSAGZWPO.js} +1 -1
- package/dist/chunk-HUICUICD.js +3 -0
- package/dist/{chunk-2DSY4U73.js → chunk-I3G6K7QU.js} +1 -1
- package/dist/chunk-IRLWXPL4.js +7 -0
- package/dist/chunk-IZTOXSTR.js +6 -0
- package/dist/chunk-J5CKSIH7.js +1 -0
- package/dist/chunk-JKM4E5VB.js +5 -0
- package/dist/chunk-JMCI2ZE2.js +3 -0
- package/dist/{chunk-YZTVC7ME.js → chunk-JY63UUC2.js} +1 -1
- package/dist/chunk-KJ6HZC6L.js +7 -0
- package/dist/chunk-LG22ELG4.js +2 -0
- package/dist/chunk-LRAMFOUP.js +37 -0
- package/dist/chunk-MJMRV76H.js +1 -0
- package/dist/chunk-MMQIHUU5.js +1 -0
- package/dist/chunk-MNAIMZRO.js +9 -0
- package/dist/chunk-NGWQRV25.js +13 -0
- package/dist/chunk-NKI4TZSS.js +2 -0
- package/dist/chunk-NWCTAVGR.js +4 -0
- package/dist/chunk-O2C3F3MA.js +1 -0
- package/dist/chunk-OA26FH5G.js +1 -0
- package/dist/chunk-OEEE5BLN.js +16 -0
- package/dist/chunk-OLMACWQX.js +11 -0
- package/dist/{chunk-72FL5FHZ.js → chunk-PBMHSK6J.js} +1 -1
- package/dist/chunk-QC6VFZSB.js +2 -0
- package/dist/chunk-QCAGAJHJ.js +1 -0
- package/dist/{chunk-P7FUD4WY.js → chunk-QR7JR3P2.js} +1 -1
- package/dist/chunk-QSU5AEKW.js +1 -0
- package/dist/chunk-R7576HPO.js +25 -0
- package/dist/{chunk-B5UJCNQU.js → chunk-RNDSWVJF.js} +1 -1
- package/dist/chunk-S4GTWS2J.js +6 -0
- package/dist/chunk-SF44YQCB.js +2 -0
- package/dist/chunk-SJQGFUXR.js +6 -0
- package/dist/chunk-SKHD2QIT.js +1 -0
- package/dist/chunk-SKZTIAE4.js +4 -0
- package/dist/chunk-SZRC24OB.js +1 -0
- package/dist/chunk-T5PXAYWC.js +1 -0
- package/dist/chunk-TIZ4QDF3.js +1 -0
- package/dist/chunk-UHGHVYAW.js +4 -0
- package/dist/chunk-V2LLMBTA.js +1 -0
- package/dist/chunk-VB5P3TXJ.js +111 -0
- package/dist/chunk-VNG4QPPT.js +12 -0
- package/dist/chunk-VNNAVC4S.js +15 -0
- package/dist/chunk-VPBGKSFI.js +3 -0
- package/dist/chunk-WZ7MNISG.js +5 -0
- package/dist/chunk-X4CU7CMR.js +19 -0
- package/dist/chunk-X7CHS7JB.js +1 -0
- package/dist/chunk-XEPCURYZ.js +1 -0
- package/dist/chunk-XKVU6AAS.js +7 -0
- package/dist/chunk-XLTAP5YC.js +24 -0
- package/dist/chunk-XQMNVPNS.js +1 -0
- package/dist/chunk-YI32H7Z2.js +4 -0
- package/dist/chunk-YSGPCH52.js +18 -0
- package/dist/chunk-ZYG5E3DI.js +9 -0
- package/dist/entry-0.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-18.js +1 -1
- package/dist/entry-19.js +1 -1
- package/dist/entry-20.js +1 -1
- package/dist/entry-21.js +1 -1
- package/dist/entry-22.js +1 -1
- package/dist/entry-27.js +1 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-31.js +2 -2
- package/dist/entry-32.js +1 -1
- package/dist/entry-33.js +1 -1
- package/dist/entry-34.js +1 -1
- package/dist/entry-35.js +1 -1
- package/dist/entry-36.js +1 -1
- package/dist/entry-37.js +1 -1
- package/dist/entry-38.js +19 -13
- package/dist/entry-4.js +1 -1
- package/dist/entry-40.js +1 -1
- package/dist/entry-41.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +1 -1
- package/dist/entry-48.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-55.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-57.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-63.js +1 -1
- package/dist/entry-64.js +1 -1
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-68.js +1 -0
- package/dist/entry-69.js +1 -1
- package/dist/entry-71.js +1 -1
- package/dist/entry-72.js +0 -1
- package/dist/entry-73.js +1 -1
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -1
- package/dist/entry-77.js +1 -1
- package/dist/entry-78.js +1 -0
- package/dist/entry-79.js +1 -1
- package/dist/entry-8.js +1 -1
- package/dist/entry-80.js +1 -0
- package/dist/entry-81.js +0 -1
- package/dist/entry-82.js +1 -1
- package/dist/entry-83.js +1 -1
- package/dist/entry-84.js +0 -1
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -2
- package/dist/entry-87.js +1 -1
- package/dist/entry-88.js +1 -1
- package/dist/entry-89.js +1 -1
- package/dist/entry-90.js +1 -1
- package/dist/entry-91.js +1 -3
- package/dist/entry-92.js +1 -1
- package/dist/entry-93.js +1 -1
- package/dist/entry-94.js +1 -1
- package/dist/entry-95.js +3 -0
- package/dist/entry-96.js +1 -0
- package/dist/entry-97.js +1 -0
- package/dist/entry-98.js +1 -0
- package/dist/pi-agent-ide.js +26 -13
- package/docs/agent-guides/ast-search.md +15 -4
- package/docs/agent-guides/debugger.md +1 -1
- package/docs/agent-guides/git-changes.md +1 -0
- package/docs/agent-guides/ssh.md +27 -7
- package/docs/agent-guides/terminal.md +4 -0
- package/docs/configuration.md +65 -11
- package/docs/development.md +4 -0
- package/docs/extensions.md +6 -4
- package/docs/structured-results.md +29 -15
- package/docs/tools.md +95 -29
- package/docs/user-hooks.md +1 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-doctor/src/catalog.ts +2 -0
- package/node_modules/pi-agent-doctor/src/executable.ts +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem/src/file-write-lock.ts +6 -4
- package/node_modules/pi-agent-filesystem/src/replace-file.ts +5 -2
- package/node_modules/pi-agent-filesystem/src/resolver.ts +26 -10
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +13 -13
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +56 -65
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +197 -130
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +2 -1
- package/node_modules/pi-agent-ide-ast/src/ast-grep-binary.ts +46 -0
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +119 -97
- package/node_modules/pi-agent-ide-ast/src/extension.ts +9 -24
- package/node_modules/pi-agent-ide-ast/src/outline-page.ts +96 -0
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +42 -78
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +5 -1
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +2 -1
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +24 -5
- package/node_modules/pi-agent-ide-ast/src/search-presentation.ts +2 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +406 -200
- package/node_modules/pi-agent-ide-ast/src/tool-ast-search.ts +27 -9
- package/node_modules/pi-agent-ide-ast/src/tool-outline.ts +191 -0
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +63 -20
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +1 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +25 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-paths.ts +13 -6
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +12 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +88 -78
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +29 -3
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +39 -3
- package/node_modules/pi-agent-ide-formatter/src/rustfmt.ts +101 -0
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lint/src/catalog.ts +20 -14
- package/node_modules/pi-agent-ide-lint/src/registry.ts +2 -2
- package/node_modules/pi-agent-ide-lsp/index.ts +15 -88
- package/node_modules/pi-agent-ide-lsp/package.json +12 -12
- package/node_modules/pi-agent-ide-lsp/src/catalog.ts +21 -9
- package/node_modules/pi-agent-ide-lsp/src/lsp/clang-coverage.ts +265 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/clangd-launch.ts +48 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +66 -11
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +514 -207
- package/node_modules/pi-agent-ide-lsp/src/lsp/corrected-names.ts +211 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +20 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/files-containing.ts +70 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/line-breaks.ts +16 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +60 -16
- package/node_modules/pi-agent-ide-lsp/src/lsp/missing-sources.ts +21 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +44 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/position-map.ts +17 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/range-match.ts +49 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +16 -5
- package/node_modules/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +7 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +133 -37
- package/node_modules/pi-agent-ide-lsp/src/lsp/shared-servers.ts +164 -13
- package/node_modules/pi-agent-ide-lsp/src/lsp/source-changes.ts +18 -6
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +346 -164
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +376 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +6 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +10 -0
- package/node_modules/pi-agent-ide-lsp/src/name-captures.ts +66 -0
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +383 -92
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +305 -77
- package/node_modules/pi-agent-ide-lsp/src/tool-lsp-search.ts +33 -11
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-image/src/image-converter.ts +13 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +51 -12
- package/node_modules/pi-agent-read/src/api/tools/read.ts +39 -3
- package/node_modules/pi-agent-read/src/core/extension.ts +80 -3
- package/node_modules/pi-agent-read/src/core/read-core.ts +6 -0
- package/node_modules/pi-agent-read/src/core/tools/read/list-result.ts +79 -0
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +45 -4
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +18 -9
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +16 -3
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +37 -9
- package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +15 -4
- package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +49 -18
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +158 -51
- package/node_modules/pi-agent-resource/package.json +5 -1
- package/node_modules/pi-agent-resource/src/file-text-read.ts +86 -0
- package/node_modules/pi-agent-resource/src/index.ts +54 -0
- package/node_modules/pi-agent-resource/src/json-structured-arguments.ts +131 -0
- package/node_modules/pi-agent-resource/src/line-map.ts +750 -0
- package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
- package/node_modules/pi-agent-resource/src/resource-scheduler.ts +63 -23
- package/node_modules/pi-agent-resource/src/resource.ts +5 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +693 -66
- package/node_modules/pi-agent-resource/src/script-calls.ts +21 -0
- package/node_modules/pi-agent-resource/src/tool-deadline.ts +199 -0
- package/node_modules/pi-agent-resource/src/tool-result.ts +14 -5
- package/node_modules/pi-agent-resource/src/unchanged-read.ts +62 -0
- package/node_modules/pi-agent-search/package.json +8 -9
- package/node_modules/pi-agent-search/runtime/entry-57.js +0 -1
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +2 -1
- package/node_modules/pi-agent-search/src/api/null-fields.ts +50 -0
- package/node_modules/pi-agent-search/src/api/path-list.ts +68 -0
- package/node_modules/pi-agent-search/src/api/presentation.ts +2 -1
- package/node_modules/pi-agent-search/src/api/search-call-policy.ts +16 -0
- package/node_modules/pi-agent-search/src/api/search-capture.ts +56 -0
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +26 -4
- package/node_modules/pi-agent-search/src/api/search-scope.ts +38 -2
- package/node_modules/pi-agent-search/src/api/search.ts +46 -3
- package/node_modules/pi-agent-search/src/api/structured-result.ts +96 -25
- package/node_modules/pi-agent-search/src/core/extension.ts +75 -42
- package/node_modules/pi-agent-search/src/core/search-config.ts +2 -2
- package/node_modules/pi-agent-search/src/core/search-core.ts +103 -39
- package/node_modules/pi-agent-search-text/index.ts +62 -20
- package/node_modules/pi-agent-search-text/package.json +15 -15
- package/node_modules/pi-agent-search-text/runtime/entry-59.js +1 -0
- package/node_modules/pi-agent-search-text/src/current-matches.ts +314 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +178 -99
- package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +40 -17
- package/node_modules/pi-agent-search-text/src/persisted-result.ts +3 -8
- package/node_modules/pi-agent-search-text/src/resolvers.ts +395 -103
- package/node_modules/pi-agent-search-text/src/ripgrep.ts +142 -0
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +24 -12
- package/node_modules/pi-agent-search-text/src/search-backend.ts +333 -108
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +6 -0
- package/node_modules/pi-agent-search-text/src/search-query.ts +69 -34
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +80 -8
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +2 -1
- package/node_modules/pi-agent-search-text/src/search-result.ts +10 -1
- package/node_modules/pi-agent-search-text/src/search-session.ts +449 -58
- package/node_modules/pi-agent-search-text/src/tool-file-search.ts +51 -6
- package/node_modules/pi-agent-text/package.json +3 -3
- package/node_modules/pi-agent-text/runtime/entry-63.js +1 -0
- package/node_modules/pi-agent-text/src/index.ts +18 -0
- package/node_modules/pi-agent-text/src/line-anchors.ts +211 -0
- package/node_modules/pi-agent-text/src/no-final-line-break.ts +12 -0
- package/node_modules/pi-agent-text/src/search-highlight.ts +8 -0
- package/node_modules/pi-agent-text/src/source-line.ts +7 -1
- package/node_modules/pi-agent-text/src/text-anchor.ts +34 -3
- package/node_modules/pi-agent-text/src/text-converter.ts +2 -1
- package/node_modules/pi-agent-text/src/text-document.ts +9 -23
- package/node_modules/pi-agent-text/src/text-target.ts +14 -6
- package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-64.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/index.ts +1 -65
- package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-65.js +0 -1
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-66.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +185 -184
- package/node_modules/pi-agent-text-anchor-exact/src/anchored-literal-view.ts +122 -0
- package/node_modules/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +2 -1
- package/node_modules/pi-agent-text-anchor-exact/src/literal-match.ts +359 -0
- package/node_modules/pi-agent-text-anchor-exact/src/recovery.ts +1 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +5 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-67.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-68.js +2 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +92 -67
- package/node_modules/pi-agent-text-anchor-line-hash/src/range-history.ts +105 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +22 -17
- package/node_modules/pi-agent-text-editor/index.ts +0 -10
- package/node_modules/pi-agent-text-editor/package.json +37 -26
- package/node_modules/pi-agent-text-editor/runtime/entry-84.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-85.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-86.js +1 -0
- package/node_modules/pi-agent-text-editor/runtime/entry-88.js +2 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-excerpt.ts +7 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +2 -1
- package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +40 -8
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +37 -2
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/native-files.ts +16 -2
- package/node_modules/pi-agent-text-editor/src/api/pi-edit-text.ts +82 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +9 -2
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +13 -2
- package/node_modules/pi-agent-text-editor/src/api/text-selector-fields.ts +210 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/core/already-done.ts +123 -0
- package/node_modules/pi-agent-text-editor/src/core/anchor-candidates.ts +116 -0
- package/node_modules/pi-agent-text-editor/src/core/anchor-preview.ts +32 -0
- package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +109 -23
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +19 -5
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +6 -5
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +54 -21
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +7 -3
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +14 -5
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +32 -11
- package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +67 -38
- package/node_modules/pi-agent-text-editor/src/core/file-write-observations.ts +287 -0
- package/node_modules/pi-agent-text-editor/src/core/image-write.ts +16 -4
- package/node_modules/pi-agent-text-editor/src/core/lookalike-bytes.ts +254 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +29 -12
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/compact-receipt.ts +48 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +2 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +24 -34
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +13 -20
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +32 -3
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +36 -2
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +26 -19
- package/node_modules/pi-agent-text-editor/src/core/native-snapshot-source.ts +13 -0
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +526 -148
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +28 -3
- package/node_modules/pi-agent-text-editor/src/core/read-fragment-resolver.ts +34 -14
- package/node_modules/pi-agent-text-editor/src/core/reference-list.ts +95 -0
- package/node_modules/pi-agent-text-editor/src/core/result-scope.ts +129 -0
- package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +20 -8
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +86 -69
- package/node_modules/pi-agent-text-editor/src/core/source-aliases.ts +92 -0
- package/node_modules/pi-agent-text-editor/src/core/source-change-retry.ts +92 -7
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +162 -47
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +321 -101
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +206 -134
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -2
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +133 -18
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +13 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +823 -226
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +51 -1
- package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +7 -4
- package/node_modules/pi-agent-text-editor/src/tools/display-marker.ts +15 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +268 -159
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +37 -32
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +24 -70
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +23 -36
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +31 -45
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +33 -65
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +80 -42
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +27 -16
- package/node_modules/pi-agent-text-editor-renderer/index.ts +0 -14
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/runtime/entry-89.js +2 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +204 -78
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +75 -8
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +4 -1
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -3
- package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +44 -30
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +170 -26
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +83 -83
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -6
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-91.js +1 -0
- package/node_modules/pi-agent-tool-ui/package.json +3 -3
- package/node_modules/pi-agent-tool-ui/runtime/entry-92.js +1 -0
- package/node_modules/pi-agent-tool-ui/runtime/entry-93.js +1 -0
- package/node_modules/pi-agent-web/index.ts +0 -3
- package/node_modules/pi-agent-web/package.json +8 -8
- package/node_modules/pi-agent-web/src/search.ts +1 -2
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-html/runtime/entry-95.js +2 -0
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-image/runtime/entry-96.js +2 -0
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/runtime/entry-97.js +2 -0
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/node_modules/pi-agent-web-text/runtime/entry-98.js +2 -0
- package/package.json +38 -38
- package/skills/capture-code-review-rule/SKILL.md +1 -1
- package/skills/configure-agent-ide/SKILL.md +1 -1
- package/src/api/code-view.ts +0 -2
- package/src/api/tool-config/linters.json +1 -0
- package/src/api/tool-config/lsp-servers.json +5 -0
- package/src/api/tool-config.ts +23 -2
- package/src/backend/config.ts +2 -0
- package/src/backend/configured-process.ts +1 -0
- package/src/backend/dap-java-transport.ts +4 -2
- package/src/backend/dap-java-worker.py +11 -4
- package/src/backend/dap-node-transport.ts +4 -2
- package/src/backend/dap-tcp-transport.ts +2 -3
- package/src/backend/debugger-workspace-owner.ts +6 -6
- package/src/backend/doctor-probe-worker.py +23 -15
- package/src/backend/doctor-workspace.ts +19 -18
- package/src/backend/file-transfer.ts +160 -56
- package/src/backend/formatter-registration.ts +54 -2
- package/src/backend/identity.ts +81 -12
- package/src/backend/lsp-file-watchers.ts +7 -9
- package/src/backend/lsp-workspace-owner.ts +25 -1
- package/src/backend/object-transfer.ts +28 -15
- package/src/backend/owned-command.ts +2 -1
- package/src/backend/owned-read-command.ts +2 -1
- package/src/backend/packaged-source.ts +12 -0
- package/src/backend/process-environment.ts +7 -9
- package/src/backend/process-metadata.ts +5 -5
- package/src/backend/recipe-evidence-worker.py +2 -0
- package/src/backend/recipe-evidence.ts +7 -8
- package/src/backend/registration.ts +2 -1
- package/src/backend/registry.ts +12 -2
- package/src/backend/resource-resolver.ts +11 -32
- package/src/backend/search-environment.ts +61 -4
- package/src/backend/ssh-channel-worker.py +6 -304
- package/src/backend/ssh-channel.ts +287 -36
- package/src/backend/ssh-connection-loss.ts +123 -0
- package/src/backend/ssh-file-stream.ts +216 -0
- package/src/backend/ssh-master.ts +443 -0
- package/src/backend/ssh-transfer-worker-windows.py +84 -0
- package/src/backend/ssh-transfer-worker.py +43 -10
- package/src/backend/ssh-transport.ts +238 -24
- package/src/backend/ssh-worker.py +7 -728
- package/src/backend/ssh.ts +83 -35
- package/src/backend/ssh_channel_common.py +68 -0
- package/src/backend/ssh_channel_posix.py +324 -0
- package/src/backend/ssh_channel_windows.py +527 -0
- package/src/backend/ssh_paths.py +23 -0
- package/src/backend/ssh_windows_files.py +254 -0
- package/src/backend/ssh_worker_common.py +96 -0
- package/src/backend/ssh_worker_posix.py +780 -0
- package/src/backend/ssh_worker_windows.py +687 -0
- package/src/backend/tool-config-access.ts +14 -11
- package/src/backend/tool-project.ts +4 -3
- package/src/backend/web-browser.ts +2 -3
- package/src/backend/web-http.ts +5 -5
- package/src/code-view/diagnostic-view.ts +12 -30
- package/src/code-view/reference.ts +9 -18
- package/src/code-view/source-view.ts +2 -1
- package/src/composite/codemode-tool-names.ts +79 -0
- package/src/composite/detached-results.ts +25 -6
- package/src/composite/ide-alias-rendering.ts +26 -4
- package/src/composite/module-labels.ts +2 -2
- package/src/composite/module-settings.ts +1 -0
- package/src/composite/nested-tool-rendering.ts +70 -24
- package/src/composite/output-limits.ts +12 -5
- package/src/composite/parallel-tool-guidance.ts +38 -0
- package/src/composite/script-values/ast-search.ts +56 -0
- package/src/composite/script-values/copy.ts +8 -0
- package/src/composite/script-values/delete.ts +5 -0
- package/src/composite/script-values/diff.ts +28 -0
- package/src/composite/script-values/edit-selection.ts +48 -0
- package/src/composite/script-values/failures.ts +170 -0
- package/src/composite/script-values/file-receipts.ts +63 -0
- package/src/composite/script-values/file-search.ts +10 -0
- package/src/composite/script-values/index.ts +55 -0
- package/src/composite/script-values/insert.ts +5 -0
- package/src/composite/script-values/lsp-search.ts +92 -0
- package/src/composite/script-values/match.ts +53 -0
- package/src/composite/script-values/move.ts +8 -0
- package/src/composite/script-values/path-list.ts +25 -0
- package/src/composite/script-values/provider-value.ts +21 -0
- package/src/composite/script-values/read.ts +206 -0
- package/src/composite/script-values/replace.ts +5 -0
- package/src/composite/script-values/result-reference.ts +9 -0
- package/src/composite/script-values/search-matches.ts +113 -0
- package/src/composite/script-values/search.ts +64 -0
- package/src/composite/script-values/semantic-search.ts +8 -0
- package/src/composite/script-values/terminal.ts +112 -0
- package/src/composite/script-values/text.ts +7 -0
- package/src/composite/script-values/types.ts +56 -0
- package/src/composite/script-values/undo.ts +5 -0
- package/src/composite/script-values/write.ts +8 -0
- package/src/composite/settings-panel.ts +18 -2
- package/src/composite/text-results.ts +488 -175
- package/src/composite/tool-availability.ts +29 -16
- package/src/composite/tool-discovery-guidance.ts +97 -0
- package/src/documentation/attachment.ts +31 -0
- package/src/documentation/extension.ts +6 -2
- package/src/documentation/search.ts +1 -7
- 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 +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/file-write-lock.ts +6 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/replace-file.ts +5 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +26 -10
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +0 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-95.js +2 -0
- 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-96.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-97.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-98.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-94.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +1 -2
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +51 -12
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +39 -3
- package/src/extensions/pi-agent-read/src/core/extension.ts +80 -3
- package/src/extensions/pi-agent-read/src/core/read-core.ts +6 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/list-result.ts +79 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +45 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +18 -9
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +16 -3
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +37 -9
- package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +15 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +49 -18
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +158 -51
- package/src/extensions/pi-agent-search/package.json +8 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +62 -20
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +15 -15
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-59.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-62.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/current-matches.ts +314 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +178 -99
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +40 -17
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/persisted-result.ts +3 -8
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +395 -103
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/ripgrep.ts +142 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +24 -12
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +333 -108
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +6 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +69 -34
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +80 -8
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +2 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +10 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +449 -58
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/tool-file-search.ts +51 -6
- package/src/extensions/pi-agent-search/runtime/entry-57.js +0 -1
- package/src/extensions/pi-agent-search/runtime/entry-58.js +2 -0
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +2 -1
- package/src/extensions/pi-agent-search/src/api/null-fields.ts +50 -0
- package/src/extensions/pi-agent-search/src/api/path-list.ts +68 -0
- package/src/extensions/pi-agent-search/src/api/presentation.ts +2 -1
- package/src/extensions/pi-agent-search/src/api/search-call-policy.ts +16 -0
- package/src/extensions/pi-agent-search/src/api/search-capture.ts +56 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +26 -4
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +38 -2
- package/src/extensions/pi-agent-search/src/api/search.ts +46 -3
- package/src/extensions/pi-agent-search/src/api/structured-result.ts +96 -25
- package/src/extensions/pi-agent-search/src/core/extension.ts +75 -42
- package/src/extensions/pi-agent-search/src/core/search-config.ts +2 -2
- package/src/extensions/pi-agent-search/src/core/search-core.ts +103 -39
- package/src/extensions/pi-agent-text-editor/index.ts +0 -10
- package/src/extensions/pi-agent-text-editor/package.json +37 -26
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-64.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +1 -65
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-65.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-66.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +185 -184
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchored-literal-view.ts +122 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/fuzzy-worker.ts +2 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/literal-match.ts +359 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/recovery.ts +1 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +5 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-67.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-68.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +92 -67
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/range-history.ts +105 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +22 -17
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +0 -14
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-89.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +204 -78
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +75 -8
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +4 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +4 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +44 -30
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +170 -26
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +83 -83
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -6
- package/src/extensions/pi-agent-text-editor/runtime/entry-84.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-85.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-86.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-87.js +1 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-88.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-excerpt.ts +7 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +2 -1
- package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +40 -8
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +37 -2
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/native-files.ts +16 -2
- package/src/extensions/pi-agent-text-editor/src/api/pi-edit-text.ts +82 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +9 -2
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +13 -2
- package/src/extensions/pi-agent-text-editor/src/api/text-selector-fields.ts +210 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/core/already-done.ts +123 -0
- package/src/extensions/pi-agent-text-editor/src/core/anchor-candidates.ts +116 -0
- package/src/extensions/pi-agent-text-editor/src/core/anchor-preview.ts +32 -0
- package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +109 -23
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +19 -5
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +6 -5
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +54 -21
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +7 -3
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +14 -5
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +32 -11
- package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +67 -38
- package/src/extensions/pi-agent-text-editor/src/core/file-write-observations.ts +287 -0
- package/src/extensions/pi-agent-text-editor/src/core/image-write.ts +16 -4
- package/src/extensions/pi-agent-text-editor/src/core/lookalike-bytes.ts +254 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +29 -12
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/compact-receipt.ts +48 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +2 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +24 -34
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +13 -20
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +32 -3
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +36 -2
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +26 -19
- package/src/extensions/pi-agent-text-editor/src/core/native-snapshot-source.ts +13 -0
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +526 -148
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +28 -3
- package/src/extensions/pi-agent-text-editor/src/core/read-fragment-resolver.ts +34 -14
- package/src/extensions/pi-agent-text-editor/src/core/reference-list.ts +95 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-scope.ts +129 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +20 -8
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +86 -69
- package/src/extensions/pi-agent-text-editor/src/core/source-aliases.ts +92 -0
- package/src/extensions/pi-agent-text-editor/src/core/source-change-retry.ts +92 -7
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +162 -47
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +321 -101
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +206 -134
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -2
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +133 -18
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +13 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +823 -226
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +51 -1
- package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +7 -4
- package/src/extensions/pi-agent-text-editor/src/tools/display-marker.ts +15 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +268 -159
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +37 -32
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +24 -70
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +23 -36
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +31 -45
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +33 -65
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +80 -42
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +27 -16
- package/src/pi-agent-ide.ts +41 -32
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +56 -65
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +197 -130
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +2 -1
- package/src/plugins/pi-agent-ide-ast/src/ast-grep-binary.ts +46 -0
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +119 -97
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +9 -24
- package/src/plugins/pi-agent-ide-ast/src/outline-page.ts +96 -0
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +42 -78
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +5 -1
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +2 -1
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +24 -5
- package/src/plugins/pi-agent-ide-ast/src/search-presentation.ts +2 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +406 -200
- package/src/plugins/pi-agent-ide-ast/src/tool-ast-search.ts +27 -9
- package/src/plugins/pi-agent-ide-ast/src/tool-outline.ts +191 -0
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +63 -20
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +1 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +25 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-paths.ts +13 -6
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +12 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +88 -78
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +29 -3
- package/src/plugins/pi-agent-ide-debugger/index.ts +42 -32
- package/src/plugins/pi-agent-ide-debugger/src/string-enum.ts +14 -0
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +124 -79
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +39 -3
- package/src/plugins/pi-agent-ide-formatter/src/rustfmt.ts +101 -0
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lint/src/catalog.ts +20 -14
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +2 -2
- package/src/plugins/pi-agent-ide-lsp/index.ts +15 -88
- package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
- package/src/plugins/pi-agent-ide-lsp/src/catalog.ts +21 -9
- package/src/plugins/pi-agent-ide-lsp/src/lsp/clang-coverage.ts +265 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/clangd-launch.ts +48 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +66 -11
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +514 -207
- package/src/plugins/pi-agent-ide-lsp/src/lsp/corrected-names.ts +211 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +20 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/files-containing.ts +70 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/line-breaks.ts +16 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +60 -16
- package/src/plugins/pi-agent-ide-lsp/src/lsp/missing-sources.ts +21 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +44 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/position-map.ts +17 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/range-match.ts +49 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +16 -5
- package/src/plugins/pi-agent-ide-lsp/src/lsp/server-request-handlers.mjs +7 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-server-host.mjs +133 -37
- package/src/plugins/pi-agent-ide-lsp/src/lsp/shared-servers.ts +164 -13
- package/src/plugins/pi-agent-ide-lsp/src/lsp/source-changes.ts +18 -6
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +346 -164
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-selectors.ts +376 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +6 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/workspace-owner.ts +10 -0
- package/src/plugins/pi-agent-ide-lsp/src/name-captures.ts +66 -0
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +383 -92
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +305 -77
- package/src/plugins/pi-agent-ide-lsp/src/tool-lsp-search.ts +33 -11
- package/src/plugins/pi-agent-ide-processes/src/registry.ts +64 -3
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +57 -1
- package/src/plugins/pi-agent-ide-semantic/src/backend.ts +18 -6
- package/src/plugins/pi-agent-ide-semantic/src/vera-backend.ts +16 -9
- package/src/plugins/pi-agent-ide-terminal/index.ts +23 -7
- package/src/plugins/pi-agent-ide-terminal/src/list.ts +79 -0
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +22 -0
- package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +3 -0
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +18 -6
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +132 -18
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +117 -50
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +94 -10
- package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +24 -1
- package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +5 -2
- package/src/plugins/pi-agent-ide-terminal/src/terminal-text.ts +173 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +266 -112
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +6 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +11 -6
- package/src/plugins/pi-agent-ide-terminal/src/unix-pty-output.ts +47 -0
- package/src/post-edit/gate.ts +16 -1
- package/src/semantic/extension.ts +8 -2
- package/src/standalone/scoped-api.ts +85 -18
- package/src/toolchain/types.ts +4 -0
- package/dist/chunk-2AANEKFS.js +0 -1
- package/dist/chunk-33U3RUM3.js +0 -12
- package/dist/chunk-34IYWKY5.js +0 -1
- package/dist/chunk-4CSNQX54.js +0 -23
- package/dist/chunk-53IV6EKV.js +0 -1
- package/dist/chunk-5AROEOJB.js +0 -1
- package/dist/chunk-5D4C225L.js +0 -1
- package/dist/chunk-5W6QQZFI.js +0 -2
- package/dist/chunk-6W4OJLCJ.js +0 -1
- package/dist/chunk-6ZYCTWQE.js +0 -1
- package/dist/chunk-756K3LJY.js +0 -1
- package/dist/chunk-AMSNDWBT.js +0 -2
- package/dist/chunk-APWMLLSE.js +0 -17
- package/dist/chunk-BMSAVDRD.js +0 -13
- package/dist/chunk-BRJIXNFU.js +0 -5
- package/dist/chunk-C2GZLLSP.js +0 -5
- package/dist/chunk-ECSMTGVM.js +0 -6
- package/dist/chunk-EWTVVPUA.js +0 -11
- package/dist/chunk-FBR7ZLLN.js +0 -1
- package/dist/chunk-FGN2ZMEN.js +0 -1
- package/dist/chunk-FJSYWOE6.js +0 -1
- package/dist/chunk-FTECKRK6.js +0 -1
- package/dist/chunk-GRZTKMXQ.js +0 -1
- package/dist/chunk-HFCHOFLV.js +0 -2
- package/dist/chunk-HFF4GY7R.js +0 -3
- package/dist/chunk-HJXSEPO7.js +0 -111
- package/dist/chunk-HSEDKYH4.js +0 -1
- package/dist/chunk-II7AOJNH.js +0 -9
- package/dist/chunk-J34VKQGJ.js +0 -1
- package/dist/chunk-J6CDIH3S.js +0 -84
- package/dist/chunk-JHWLRL4U.js +0 -1
- package/dist/chunk-JMQ67UNK.js +0 -3
- package/dist/chunk-JRIP33PC.js +0 -13
- package/dist/chunk-K5M65CAF.js +0 -1
- package/dist/chunk-KJAR2WDO.js +0 -1
- package/dist/chunk-KX7MG72M.js +0 -1
- package/dist/chunk-L2B4DTVS.js +0 -1
- package/dist/chunk-LEKC4GQK.js +0 -5
- package/dist/chunk-LIGOOMJS.js +0 -10
- package/dist/chunk-LY2UANKU.js +0 -6
- package/dist/chunk-M7P7V4WI.js +0 -25
- package/dist/chunk-MXLSGMRZ.js +0 -3
- package/dist/chunk-N2NEFXHB.js +0 -13
- package/dist/chunk-NF74ITWT.js +0 -2
- package/dist/chunk-NQYUIQRH.js +0 -1
- package/dist/chunk-OCU6NW5Y.js +0 -1
- package/dist/chunk-OIEA4QWF.js +0 -4
- package/dist/chunk-ON5HDFNL.js +0 -10
- package/dist/chunk-P43GGKUC.js +0 -28
- package/dist/chunk-PPCWY4BB.js +0 -1
- package/dist/chunk-QGXZ4RWX.js +0 -1
- package/dist/chunk-S3T5NOSL.js +0 -1
- package/dist/chunk-S7E2D5K7.js +0 -5
- package/dist/chunk-SIYPD5MM.js +0 -3
- package/dist/chunk-STUZZM5B.js +0 -1
- package/dist/chunk-T4FTT3U4.js +0 -1
- package/dist/chunk-T5ACAOKJ.js +0 -4
- package/dist/chunk-TILMPAF2.js +0 -1
- package/dist/chunk-TSNY2FSU.js +0 -1
- package/dist/chunk-TWJINFQB.js +0 -9
- package/dist/chunk-TWQ6ACOI.js +0 -1
- package/dist/chunk-UDVVKVG4.js +0 -1
- package/dist/chunk-V2D5MLGE.js +0 -1
- package/dist/chunk-VDSSAP6Y.js +0 -1
- package/dist/chunk-VHYJTAXX.js +0 -1
- package/dist/chunk-WCSWQDJ2.js +0 -22
- package/dist/chunk-WQTF6Q2X.js +0 -3
- package/dist/chunk-XE4W5YTE.js +0 -2
- package/dist/chunk-YFPU2LRR.js +0 -23
- package/dist/chunk-YLEERRX3.js +0 -33
- package/dist/chunk-YOJHCARZ.js +0 -1
- package/dist/chunk-YPTDPMK5.js +0 -1
- package/docs/agent-guides/editing.md +0 -43
- package/docs/agent-guides/search.md +0 -38
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +0 -73
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-63.js +0 -2
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-64.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-66.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-68.js +0 -1
- package/node_modules/pi-agent-text-editor-renderer/runtime/entry-85.js +0 -2
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +0 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-88.js +0 -1
- package/node_modules/pi-agent-tool-ui/runtime/entry-89.js +0 -1
- package/node_modules/pi-agent-web-html/runtime/entry-91.js +0 -2
- package/node_modules/pi-agent-web-image/runtime/entry-92.js +0 -2
- package/node_modules/pi-agent-web-pdf/runtime/entry-93.js +0 -2
- package/src/composite/search-facts.ts +0 -45
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-91.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/runtime/entry-92.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/runtime/entry-93.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-94.js +0 -2
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-58.js +0 -2
- package/src/extensions/pi-agent-search/runtime/entry-54.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-63.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-64.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-66.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-85.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-68.js +0 -1
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +0 -73
- /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-54.js +0 -0
- /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-58.js +0 -0
- /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-62.js +0 -0
- /package/node_modules/{pi-agent-tool-call-interception → pi-agent-text-editor}/runtime/entry-87.js +0 -0
- /package/node_modules/{pi-agent-web → pi-agent-text-editor-stale-anchor}/runtime/entry-90.js +0 -0
- /package/node_modules/{pi-agent-web-text → pi-agent-web}/runtime/entry-94.js +0 -0
- /package/src/extensions/{pi-agent-read/extensions/pi-agent-web → pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor}/runtime/entry-90.js +0 -0
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
import { diffArrays } from "diff";
|
|
2
|
+
import type { ResultRange } from "./result-targets.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Beyond this many added and removed lines a file counts as rewritten and nothing is carried over.
|
|
6
|
+
* The comparison runs on the caller's thread and grows quadratically with this length: about
|
|
7
|
+
* 0.15 s at 1000 lines and 0.5 s at 2000 on a 26,000-line file.
|
|
8
|
+
*/
|
|
9
|
+
const maxEditedLines = 1500;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Where each line of one text sits in another text. Line numbers are one-based, as in ranges.
|
|
13
|
+
* A line counts as unchanged only when its text and line ending are identical; a moved or edited
|
|
14
|
+
* line has no counterpart.
|
|
15
|
+
*/
|
|
16
|
+
export interface LineMap {
|
|
17
|
+
/** Line number in the new text for an old line, or `undefined` when that line changed or vanished. */
|
|
18
|
+
readonly newLine: (oldLine: number) => number | undefined;
|
|
19
|
+
/** The map as a table indexed by old line number; 0 marks a changed line. */
|
|
20
|
+
readonly table: Int32Array;
|
|
21
|
+
/** Lines of both texts with their line endings, zero-based; used to look inside changed lines. */
|
|
22
|
+
readonly oldLines: readonly string[];
|
|
23
|
+
readonly newLines: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Split like every tool does (only `\n` ends a line; CR is ordinary text), keeping each line ending
|
|
28
|
+
* so endings compare too.
|
|
29
|
+
*/
|
|
30
|
+
function lineTokens(content: string): string[] | undefined {
|
|
31
|
+
const lines = content.split("\n");
|
|
32
|
+
return lines.map((line, index) => (index < lines.length - 1 ? `${line}\n` : line));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Compare two texts line by line. Returns `undefined` when they cannot be related safely. */
|
|
36
|
+
export function createLineMap(before: string, after: string): LineMap | undefined {
|
|
37
|
+
const old = lineTokens(before);
|
|
38
|
+
const next = lineTokens(after);
|
|
39
|
+
return old === undefined || next === undefined ? undefined : orderedMap(old, next);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function orderedMap(old: readonly string[], next: readonly string[]): LineMap | undefined {
|
|
43
|
+
const table = new Int32Array(old.length + 1);
|
|
44
|
+
let prefix = 0;
|
|
45
|
+
const shortest = Math.min(old.length, next.length);
|
|
46
|
+
while (prefix < shortest && old[prefix] === next[prefix]) prefix += 1;
|
|
47
|
+
let suffix = 0;
|
|
48
|
+
while (
|
|
49
|
+
suffix < shortest - prefix &&
|
|
50
|
+
old[old.length - 1 - suffix] === next[next.length - 1 - suffix]
|
|
51
|
+
)
|
|
52
|
+
suffix += 1;
|
|
53
|
+
for (let index = 0; index < prefix; index += 1) table[index + 1] = index + 1;
|
|
54
|
+
for (let index = 0; index < suffix; index += 1)
|
|
55
|
+
table[old.length - suffix + index + 1] = next.length - suffix + index + 1;
|
|
56
|
+
const oldMiddle = old.slice(prefix, old.length - suffix);
|
|
57
|
+
const newMiddle = next.slice(prefix, next.length - suffix);
|
|
58
|
+
if (oldMiddle.length > 0 && newMiddle.length > 0) {
|
|
59
|
+
const parts = diffArrays(oldMiddle, newMiddle, { maxEditLength: maxEditedLines });
|
|
60
|
+
if (parts === undefined) return undefined;
|
|
61
|
+
let oldIndex = 0;
|
|
62
|
+
let newIndex = 0;
|
|
63
|
+
for (const part of parts) {
|
|
64
|
+
if (part.added) newIndex += part.count;
|
|
65
|
+
else if (part.removed) oldIndex += part.count;
|
|
66
|
+
else {
|
|
67
|
+
const count = part.count;
|
|
68
|
+
for (let offset = 0; offset < count; offset += 1)
|
|
69
|
+
table[prefix + oldIndex + offset + 1] = prefix + newIndex + offset + 1;
|
|
70
|
+
oldIndex += count;
|
|
71
|
+
newIndex += count;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
table,
|
|
77
|
+
oldLines: old,
|
|
78
|
+
newLines: next,
|
|
79
|
+
newLine: (oldLine) => {
|
|
80
|
+
const line = table[oldLine];
|
|
81
|
+
return line === undefined || line === 0 ? undefined : line;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The final included line, excluding the next line's column-zero endpoint. */
|
|
87
|
+
export function lastSelectedLine({ start, end }: ResultRange): number {
|
|
88
|
+
return end.column === 0 && end.lineNumber > start.lineNumber
|
|
89
|
+
? end.lineNumber - 1
|
|
90
|
+
: end.lineNumber;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Move a range to the new text. Every line it touches must be unchanged and still adjacent;
|
|
95
|
+
* otherwise the selected text changed, and the range has no safe position.
|
|
96
|
+
*/
|
|
97
|
+
export function rebaseRange(
|
|
98
|
+
range: ResultRange,
|
|
99
|
+
map: Pick<LineMap, "newLine">,
|
|
100
|
+
): ResultRange | undefined {
|
|
101
|
+
const { start, end } = range;
|
|
102
|
+
const lastLine = lastSelectedLine(range);
|
|
103
|
+
const endsAfterLine = lastLine !== end.lineNumber;
|
|
104
|
+
let first: number | undefined;
|
|
105
|
+
let previous: number | undefined;
|
|
106
|
+
for (let line = start.lineNumber; line <= lastLine; line += 1) {
|
|
107
|
+
const moved = map.newLine(line);
|
|
108
|
+
if (moved === undefined || (previous !== undefined && moved !== previous + 1)) return undefined;
|
|
109
|
+
first ??= moved;
|
|
110
|
+
previous = moved;
|
|
111
|
+
}
|
|
112
|
+
if (first === undefined || previous === undefined) return undefined;
|
|
113
|
+
return {
|
|
114
|
+
...range,
|
|
115
|
+
start: { lineNumber: first, column: start.column },
|
|
116
|
+
end: { lineNumber: endsAfterLine ? previous + 1 : previous, column: end.column },
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Find the same region of the new text when some of the range's own lines changed. An edge line
|
|
122
|
+
* that is unchanged keeps its exact position; a changed edge reaches out to the nearest unchanged
|
|
123
|
+
* line beyond it, so the region covers whatever replaced the old text. At least one line inside
|
|
124
|
+
* the range must be unchanged: without one, nothing tells the region from other text. The result
|
|
125
|
+
* is marked `adjusted`: its text is not the text that was selected.
|
|
126
|
+
*
|
|
127
|
+
* `newLines` is the new text split at `\n`; the range may then end on a line that is not the last.
|
|
128
|
+
*/
|
|
129
|
+
export function relocateRange(
|
|
130
|
+
range: ResultRange,
|
|
131
|
+
map: LineMap,
|
|
132
|
+
newLines: readonly string[],
|
|
133
|
+
): ResultRange | undefined {
|
|
134
|
+
const { start, end } = range;
|
|
135
|
+
const lastLine = lastSelectedLine(range);
|
|
136
|
+
const endsAfterLine = lastLine !== end.lineNumber;
|
|
137
|
+
let survives = false;
|
|
138
|
+
for (let line = start.lineNumber; line <= lastLine && !survives; line += 1)
|
|
139
|
+
survives = map.newLine(line) !== undefined;
|
|
140
|
+
if (!survives) return undefined;
|
|
141
|
+
|
|
142
|
+
const first = map.newLine(start.lineNumber);
|
|
143
|
+
let from: ResultRange["start"];
|
|
144
|
+
if (first !== undefined) from = { lineNumber: first, column: start.column };
|
|
145
|
+
else {
|
|
146
|
+
let previous = 0;
|
|
147
|
+
for (let line = start.lineNumber - 1; line >= 1; line -= 1) {
|
|
148
|
+
const moved = map.newLine(line);
|
|
149
|
+
if (moved === undefined) continue;
|
|
150
|
+
previous = moved;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
from = { lineNumber: previous + 1, column: 0 };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const last = map.newLine(lastLine);
|
|
157
|
+
let to: ResultRange["end"];
|
|
158
|
+
if (last !== undefined) to = { lineNumber: endsAfterLine ? last + 1 : last, column: end.column };
|
|
159
|
+
else {
|
|
160
|
+
let next: number | undefined;
|
|
161
|
+
for (let line = lastLine + 1; line < map.table.length && next === undefined; line += 1)
|
|
162
|
+
next = map.newLine(line);
|
|
163
|
+
to =
|
|
164
|
+
next === undefined
|
|
165
|
+
? { lineNumber: newLines.length, column: newLines.at(-1)?.length ?? 0 }
|
|
166
|
+
: { lineNumber: next, column: 0 };
|
|
167
|
+
}
|
|
168
|
+
return { ...range, start: from, end: to, adjusted: true };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Move a range to the new text. Its text is kept exactly when it is unchanged, also when only
|
|
173
|
+
* other parts of its line changed; otherwise the region that replaced it is found and marked
|
|
174
|
+
* `adjusted`.
|
|
175
|
+
*/
|
|
176
|
+
export function moveRange(
|
|
177
|
+
range: ResultRange,
|
|
178
|
+
map: LineMap,
|
|
179
|
+
newLines: () => readonly string[],
|
|
180
|
+
): ResultRange | undefined {
|
|
181
|
+
return rebaseOrRelocateRange(range, map) ?? relocateRange(range, map, newLines());
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A changed stretch larger than this is not searched for a moved match; it counts as ambiguous. */
|
|
185
|
+
const maxHunkLines = 200;
|
|
186
|
+
|
|
187
|
+
interface LineHunk {
|
|
188
|
+
readonly oldFrom: number;
|
|
189
|
+
readonly oldTo: number;
|
|
190
|
+
readonly newFrom: number;
|
|
191
|
+
readonly newTo: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The changed stretch around an old line: its lines in both texts, one-based and inclusive. */
|
|
195
|
+
function hunkAround(map: LineMap, line: number): LineHunk | undefined {
|
|
196
|
+
const count = map.oldLines.length;
|
|
197
|
+
let before = line - 1;
|
|
198
|
+
while (before >= 1 && map.newLine(before) === undefined) before -= 1;
|
|
199
|
+
let after = line + 1;
|
|
200
|
+
while (after <= count && map.newLine(after) === undefined) after += 1;
|
|
201
|
+
if (after - before > maxHunkLines) return undefined;
|
|
202
|
+
const newBefore = before < 1 ? 0 : (map.newLine(before) ?? 0);
|
|
203
|
+
const newAfter = after > count ? map.newLines.length + 1 : (map.newLine(after) ?? 0);
|
|
204
|
+
return { oldFrom: before + 1, oldTo: after - 1, newFrom: newBefore + 1, newTo: newAfter - 1 };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function withoutEnding(token: string): string {
|
|
208
|
+
return token.endsWith("\n") ? token.slice(0, -1) : token;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function lineText(lines: readonly string[], line: number): string {
|
|
212
|
+
return withoutEnding(lines[line - 1] ?? "");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
interface MatchPosition {
|
|
216
|
+
readonly line: number;
|
|
217
|
+
readonly column: number;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Every start of `text` in the given lines, overlapping starts included, in reading order. */
|
|
221
|
+
function occurrences(
|
|
222
|
+
lines: readonly string[],
|
|
223
|
+
from: number,
|
|
224
|
+
to: number,
|
|
225
|
+
text: string,
|
|
226
|
+
): MatchPosition[] {
|
|
227
|
+
const found: MatchPosition[] = [];
|
|
228
|
+
for (let line = from; line <= to; line += 1) {
|
|
229
|
+
const content = lineText(lines, line);
|
|
230
|
+
for (let at = content.indexOf(text); at !== -1; at = content.indexOf(text, at + 1))
|
|
231
|
+
found.push({ line, column: at });
|
|
232
|
+
}
|
|
233
|
+
return found;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Move a one-line match whose line changed around it. Copies on one line can pair by order
|
|
238
|
+
* when their count stays the same and the hunk did not move. Other repeated matches need
|
|
239
|
+
* local context. The characters immediately on both sides of the match must still agree.
|
|
240
|
+
*/
|
|
241
|
+
export function relocateInChangedLine(range: ResultRange, map: LineMap): ResultRange | undefined {
|
|
242
|
+
return relocateInHunk(range, map.oldLines, map.newLines, () =>
|
|
243
|
+
hunkAround(map, range.start.lineNumber),
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function relocateInHunk(
|
|
248
|
+
range: ResultRange,
|
|
249
|
+
oldLines: readonly string[],
|
|
250
|
+
newLines: readonly string[],
|
|
251
|
+
locate: () => LineHunk | undefined,
|
|
252
|
+
movedHunk = false,
|
|
253
|
+
): ResultRange | undefined {
|
|
254
|
+
const { start, end } = range;
|
|
255
|
+
if (range.linewise === true || start.lineNumber !== end.lineNumber || start.column >= end.column)
|
|
256
|
+
return undefined;
|
|
257
|
+
const hunk = locate();
|
|
258
|
+
if (hunk === undefined || hunk.newTo < hunk.newFrom) return undefined;
|
|
259
|
+
const content = lineText(oldLines, start.lineNumber);
|
|
260
|
+
const matched = content.slice(start.column, end.column);
|
|
261
|
+
if (matched.length !== end.column - start.column) return undefined;
|
|
262
|
+
const old = occurrences(oldLines, hunk.oldFrom, hunk.oldTo, matched);
|
|
263
|
+
const next = occurrences(newLines, hunk.newFrom, hunk.newTo, matched);
|
|
264
|
+
const index = old.findIndex(
|
|
265
|
+
(item) => item.line === start.lineNumber && item.column === start.column,
|
|
266
|
+
);
|
|
267
|
+
if (index === -1 || next.length === 0) return undefined;
|
|
268
|
+
const spansLines = (matches: readonly MatchPosition[]) =>
|
|
269
|
+
matches[0]?.line !== matches.at(-1)?.line;
|
|
270
|
+
const needsContext =
|
|
271
|
+
old.length !== next.length ||
|
|
272
|
+
(old.length > 1 && (movedHunk || spansLines(old) || spansLines(next)));
|
|
273
|
+
const moved = needsContext
|
|
274
|
+
? findRepeatedMatch(range, oldLines, newLines, old, next)
|
|
275
|
+
: next[index];
|
|
276
|
+
if (moved === undefined) return undefined;
|
|
277
|
+
const target = lineText(newLines, moved.line);
|
|
278
|
+
if (
|
|
279
|
+
content.slice(start.column - 1, start.column) !==
|
|
280
|
+
target.slice(moved.column - 1, moved.column) ||
|
|
281
|
+
content.slice(end.column, end.column + 1) !==
|
|
282
|
+
target.slice(moved.column + matched.length, moved.column + matched.length + 1)
|
|
283
|
+
)
|
|
284
|
+
return undefined;
|
|
285
|
+
return {
|
|
286
|
+
...range,
|
|
287
|
+
start: { lineNumber: moved.line, column: moved.column },
|
|
288
|
+
end: { lineNumber: moved.line, column: moved.column + matched.length },
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Bound how much of a long line each candidate contributes as context.
|
|
293
|
+
const maxFlankLength = 256;
|
|
294
|
+
|
|
295
|
+
type Flank = string | readonly string[];
|
|
296
|
+
|
|
297
|
+
interface MatchContext {
|
|
298
|
+
readonly position: MatchPosition;
|
|
299
|
+
readonly left: Flank;
|
|
300
|
+
readonly right: Flank;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function matchContext(
|
|
304
|
+
position: MatchPosition,
|
|
305
|
+
lines: readonly string[],
|
|
306
|
+
length: number,
|
|
307
|
+
requireWholeFlank: boolean,
|
|
308
|
+
): MatchContext {
|
|
309
|
+
const text = lineText(lines, position.line);
|
|
310
|
+
const { column } = position;
|
|
311
|
+
const end = column + length;
|
|
312
|
+
if (requireWholeFlank) return { position, left: text.slice(0, column), right: text.slice(end) };
|
|
313
|
+
const runs = (flank: string) => flank.match(/[\p{ID_Continue}$]+|[^\p{ID_Continue}$]+/gu) ?? [];
|
|
314
|
+
const left = runs(text.slice(Math.max(0, column - maxFlankLength), column)).reverse();
|
|
315
|
+
const right = runs(text.slice(end, end + maxFlankLength));
|
|
316
|
+
// Do not use a run cut off by the context limit.
|
|
317
|
+
if (column > maxFlankLength) left.pop();
|
|
318
|
+
if (text.length - end > maxFlankLength) right.pop();
|
|
319
|
+
return { position, left, right };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function sharedContext(a: Flank, b: Flank): number {
|
|
323
|
+
if (typeof a === "string" || typeof b === "string")
|
|
324
|
+
return typeof a === "string" && a === b && /[\p{L}\p{N}]/u.test(a) ? 1 : 0;
|
|
325
|
+
let count = 0;
|
|
326
|
+
let hasWord = false;
|
|
327
|
+
for (const run of a) {
|
|
328
|
+
if (run !== b[count]) break;
|
|
329
|
+
// An identifier run immediately touching the match could be part of the selected word.
|
|
330
|
+
if (count > 0 && /[\p{L}\p{N}]/u.test(run)) hasWord = true;
|
|
331
|
+
count += 1;
|
|
332
|
+
}
|
|
333
|
+
return hasWord ? count : 0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Use a shared flank only when it identifies a single occurrence in both snapshots.
|
|
338
|
+
* Left and right are independent witnesses: if they disagree, neither can settle identity.
|
|
339
|
+
*/
|
|
340
|
+
function contextMatch(
|
|
341
|
+
at: MatchContext,
|
|
342
|
+
candidates: readonly MatchContext[],
|
|
343
|
+
others: readonly MatchContext[],
|
|
344
|
+
): MatchContext | undefined {
|
|
345
|
+
const onSide = (side: "left" | "right") => {
|
|
346
|
+
const flank = at[side];
|
|
347
|
+
let score = 0;
|
|
348
|
+
for (const candidate of candidates) {
|
|
349
|
+
if (candidate !== at) score = Math.max(score, sharedContext(flank, candidate[side]));
|
|
350
|
+
}
|
|
351
|
+
let best: MatchContext | undefined;
|
|
352
|
+
for (const candidate of others) {
|
|
353
|
+
const shared = sharedContext(flank, candidate[side]);
|
|
354
|
+
if (shared > score) {
|
|
355
|
+
score = shared;
|
|
356
|
+
best = candidate;
|
|
357
|
+
} else if (shared === score) best = undefined;
|
|
358
|
+
}
|
|
359
|
+
return best;
|
|
360
|
+
};
|
|
361
|
+
const left = onSide("left");
|
|
362
|
+
const right = onSide("right");
|
|
363
|
+
return left !== undefined && right !== undefined && left !== right ? undefined : (left ?? right);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Compare local context when the number or order of occurrences may have changed. */
|
|
367
|
+
function findRepeatedMatch(
|
|
368
|
+
{ start, end }: ResultRange,
|
|
369
|
+
oldLines: readonly string[],
|
|
370
|
+
newLines: readonly string[],
|
|
371
|
+
old: readonly MatchPosition[],
|
|
372
|
+
next: readonly MatchPosition[],
|
|
373
|
+
): MatchPosition | undefined {
|
|
374
|
+
const length = end.column - start.column;
|
|
375
|
+
// Two matches on the same line can share partial flanks even when they swapped.
|
|
376
|
+
const requireWholeFlank = old.filter(({ line }) => line === start.lineNumber).length > 1;
|
|
377
|
+
if (requireWholeFlank && old.length !== next.length) return undefined;
|
|
378
|
+
const before = old.map((position) => matchContext(position, oldLines, length, requireWholeFlank));
|
|
379
|
+
const after = next.map((position) => matchContext(position, newLines, length, requireWholeFlank));
|
|
380
|
+
const onOldLine = before.filter(({ position }) => position.line === start.lineNumber);
|
|
381
|
+
const ordinal = onOldLine.findIndex(({ position }) => position.column === start.column);
|
|
382
|
+
const selected = onOldLine[ordinal];
|
|
383
|
+
if (selected === undefined) return undefined;
|
|
384
|
+
const moved = contextMatch(selected, before, after);
|
|
385
|
+
if (moved === undefined || contextMatch(moved, after, before) !== selected) return undefined;
|
|
386
|
+
const onNewLine = after.filter(({ position }) => position.line === moved.position.line);
|
|
387
|
+
return onNewLine.length === onOldLine.length && onNewLine[ordinal] === moved
|
|
388
|
+
? moved.position
|
|
389
|
+
: undefined;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Rebase a range through unchanged lines, or through a changed line that leaves its text intact. */
|
|
393
|
+
export function rebaseOrRelocateRange(range: ResultRange, map: LineMap): ResultRange | undefined {
|
|
394
|
+
return rebaseRange(range, map) ?? relocateInChangedLine(range, map);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** One-based positions; a zero entry means the token occurs more than once. */
|
|
398
|
+
function uniqueLines(lines: readonly string[]): Map<string, number> {
|
|
399
|
+
const positions = new Map<string, number>();
|
|
400
|
+
for (const [index, line] of lines.entries())
|
|
401
|
+
positions.set(line, positions.has(line) ? 0 : index + 1);
|
|
402
|
+
return positions;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
interface ContextMap extends Pick<LineMap, "newLine" | "table"> {
|
|
406
|
+
readonly reordered: boolean;
|
|
407
|
+
readonly conflicts: Int32Array;
|
|
408
|
+
readonly newClaims: Int32Array;
|
|
409
|
+
readonly duplicated: ReadonlySet<string>;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function contextualMap(oldLines: readonly string[], newLines: readonly string[]): ContextMap {
|
|
413
|
+
const oldText = oldLines.map(withoutEnding);
|
|
414
|
+
const newText = newLines.map(withoutEnding);
|
|
415
|
+
const oldPositions = uniqueLines(oldText);
|
|
416
|
+
const newPositions = uniqueLines(newText);
|
|
417
|
+
const duplicated = new Set<string>();
|
|
418
|
+
for (const [token, old] of oldPositions) {
|
|
419
|
+
const next = newPositions.get(token);
|
|
420
|
+
if (next !== undefined && (old === 0) !== (next === 0)) duplicated.add(token);
|
|
421
|
+
}
|
|
422
|
+
const table = new Int32Array(oldLines.length + 1);
|
|
423
|
+
const conflicts = new Int32Array(table.length);
|
|
424
|
+
const reverse = new Int32Array(newLines.length + 1);
|
|
425
|
+
let last = 0;
|
|
426
|
+
let reordered = false;
|
|
427
|
+
for (const [token, old] of oldPositions) {
|
|
428
|
+
const next = newPositions.get(token) ?? 0;
|
|
429
|
+
if (old === 0 || next === 0 || token === "") continue;
|
|
430
|
+
table[old] = next;
|
|
431
|
+
reordered ||= next < last;
|
|
432
|
+
last = next;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Extend each unique anchor through neighboring identical lines. Both directions are needed:
|
|
436
|
+
// a repeated line may have context on only one side. Never choose between competing contexts.
|
|
437
|
+
const claim = (old: number, next: number) => {
|
|
438
|
+
const previous = table[old];
|
|
439
|
+
if (previous !== 0 && previous !== next) conflicts[old] = 1;
|
|
440
|
+
else table[old] = next;
|
|
441
|
+
const owner = reverse[next] ?? 0;
|
|
442
|
+
if (owner !== 0 && owner !== old) {
|
|
443
|
+
conflicts[old] = 1;
|
|
444
|
+
conflicts[owner] = 1;
|
|
445
|
+
} else reverse[next] = old;
|
|
446
|
+
};
|
|
447
|
+
const extend = (from: number, to: number, step: number) => {
|
|
448
|
+
let position = 0;
|
|
449
|
+
for (let old = from; old !== to; old += step) {
|
|
450
|
+
const token = oldText[old - 1];
|
|
451
|
+
if (token === undefined) break;
|
|
452
|
+
const unique = oldPositions.get(token) === old ? (newPositions.get(token) ?? 0) : 0;
|
|
453
|
+
if (unique !== 0 && token !== "") position = unique;
|
|
454
|
+
else if (position !== 0 && newText[position + step - 1] === token) position += step;
|
|
455
|
+
else position = 0;
|
|
456
|
+
if (position !== 0) claim(old, position);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
extend(1, table.length, 1);
|
|
460
|
+
extend(table.length - 1, 0, -1);
|
|
461
|
+
const newClaims = new Int32Array(reverse.length);
|
|
462
|
+
let claims = 0;
|
|
463
|
+
for (let line = 1; line < reverse.length; line += 1) {
|
|
464
|
+
if (reverse[line] !== 0) claims += 1;
|
|
465
|
+
newClaims[line] = claims;
|
|
466
|
+
}
|
|
467
|
+
return {
|
|
468
|
+
table,
|
|
469
|
+
reordered,
|
|
470
|
+
conflicts,
|
|
471
|
+
newClaims,
|
|
472
|
+
duplicated,
|
|
473
|
+
newLine: (old) => (conflicts[old] === 0 ? table[old] || undefined : undefined),
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** Map a small changed stretch inside a moved block, not across a cut or paste boundary. */
|
|
478
|
+
function movedHunk(map: ContextMap, line: number): LineHunk | undefined {
|
|
479
|
+
if (map.table[line] !== 0) return undefined;
|
|
480
|
+
let before = line - 1;
|
|
481
|
+
while (before > 0 && map.table[before] === 0 && line - before < maxHunkLines) before -= 1;
|
|
482
|
+
let after = line + 1;
|
|
483
|
+
while (after < map.table.length && map.table[after] === 0 && after - before < maxHunkLines)
|
|
484
|
+
after += 1;
|
|
485
|
+
const left = map.newLine(before);
|
|
486
|
+
const right = map.newLine(after);
|
|
487
|
+
if (
|
|
488
|
+
left === undefined ||
|
|
489
|
+
right === undefined ||
|
|
490
|
+
right <= left + 1 ||
|
|
491
|
+
right - left > maxHunkLines ||
|
|
492
|
+
after - before > maxHunkLines ||
|
|
493
|
+
map.newClaims[right - 1] !== map.newClaims[left]
|
|
494
|
+
)
|
|
495
|
+
return undefined;
|
|
496
|
+
return { oldFrom: before + 1, oldTo: after - 1, newFrom: left + 1, newTo: right - 1 };
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** Moves selections and explains losses between the same two text snapshots. */
|
|
500
|
+
export interface RangeTracker {
|
|
501
|
+
/** Move a selection. Set `allowAdjusted` to also accept changed regions for display. */
|
|
502
|
+
readonly move: (range: ResultRange, allowAdjusted?: boolean) => ResultRange | undefined;
|
|
503
|
+
/** Explain why a selection could not be moved and report current candidates. */
|
|
504
|
+
readonly describe: (range: ResultRange) => string;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Keep an adjusted line scope bounded by verified survivors, never by an ordered duplicate. */
|
|
508
|
+
function survivingRegion(
|
|
509
|
+
range: ResultRange,
|
|
510
|
+
context: ContextMap,
|
|
511
|
+
old: readonly string[],
|
|
512
|
+
next: readonly string[],
|
|
513
|
+
): ResultRange | undefined {
|
|
514
|
+
if (range.linewise !== true) return undefined;
|
|
515
|
+
let first: number | undefined;
|
|
516
|
+
let last: number | undefined;
|
|
517
|
+
let previous = 0;
|
|
518
|
+
let count = 0;
|
|
519
|
+
const end = lastSelectedLine(range);
|
|
520
|
+
for (let line = range.start.lineNumber; line <= end; line += 1) {
|
|
521
|
+
const moved = context.newLine(line);
|
|
522
|
+
if (moved === undefined) continue;
|
|
523
|
+
if (moved <= previous) return undefined;
|
|
524
|
+
first ??= line;
|
|
525
|
+
last = line;
|
|
526
|
+
previous = moved;
|
|
527
|
+
count += 1;
|
|
528
|
+
}
|
|
529
|
+
if (first === undefined || last === undefined) return undefined;
|
|
530
|
+
const from = context.newLine(first);
|
|
531
|
+
const token = old[last - 1];
|
|
532
|
+
if (from === undefined || token === undefined) return undefined;
|
|
533
|
+
// A bounding range must not capture an identifiable line from outside the old scope.
|
|
534
|
+
if ((context.newClaims[previous] ?? 0) - (context.newClaims[from - 1] ?? 0) !== count)
|
|
535
|
+
return undefined;
|
|
536
|
+
const cropped = {
|
|
537
|
+
...range,
|
|
538
|
+
start: first === range.start.lineNumber ? range.start : { lineNumber: first, column: 0 },
|
|
539
|
+
end:
|
|
540
|
+
last === end
|
|
541
|
+
? range.end
|
|
542
|
+
: token.endsWith("\n")
|
|
543
|
+
? { lineNumber: last + 1, column: 0 }
|
|
544
|
+
: { lineNumber: last, column: token.length },
|
|
545
|
+
};
|
|
546
|
+
return relocateRange(
|
|
547
|
+
cropped,
|
|
548
|
+
{ ...context, oldLines: old, newLines: next },
|
|
549
|
+
next.map(withoutEnding),
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
/** Track a snapshot pair once, even when many independent selections use it. */
|
|
553
|
+
export function createRangeTracker(before: string, after: string): RangeTracker {
|
|
554
|
+
if (before === after) return { move: (range) => range, describe: describeUnmappedRange };
|
|
555
|
+
const prefixLines = unchangedLinesBeforeAppend(before, after);
|
|
556
|
+
if (prefixLines === undefined) return createContextualRangeTracker(before, after);
|
|
557
|
+
|
|
558
|
+
let fallback: RangeTracker | undefined;
|
|
559
|
+
const contextual = () => (fallback ??= createContextualRangeTracker(before, after));
|
|
560
|
+
return {
|
|
561
|
+
move(range, allowAdjusted) {
|
|
562
|
+
const first = range.start.lineNumber;
|
|
563
|
+
const last = lastSelectedLine(range);
|
|
564
|
+
return Number.isInteger(first) &&
|
|
565
|
+
Number.isInteger(last) &&
|
|
566
|
+
first >= 1 &&
|
|
567
|
+
first <= last &&
|
|
568
|
+
last <= prefixLines
|
|
569
|
+
? range
|
|
570
|
+
: contextual().move(range, allowAdjusted);
|
|
571
|
+
},
|
|
572
|
+
describe: (range) => contextual().describe(range),
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** A single new, distinct line cannot change the identity of any complete line in the prefix. */
|
|
577
|
+
function unchangedLinesBeforeAppend(before: string, after: string): number | undefined {
|
|
578
|
+
if (
|
|
579
|
+
after.length <= before.length + 1 ||
|
|
580
|
+
!before.endsWith("\n") ||
|
|
581
|
+
!after.startsWith(before) ||
|
|
582
|
+
after.indexOf("\n", before.length) !== after.length - 1
|
|
583
|
+
)
|
|
584
|
+
return undefined;
|
|
585
|
+
|
|
586
|
+
const added = after.slice(before.length);
|
|
587
|
+
// Check at line boundaries. A copy could remove a unique contextual witness.
|
|
588
|
+
if (before.startsWith(added) || before.includes(`\n${added}`)) return undefined;
|
|
589
|
+
|
|
590
|
+
let count = 0;
|
|
591
|
+
for (let end = before.indexOf("\n"); end !== -1; end = before.indexOf("\n", end + 1)) count += 1;
|
|
592
|
+
return count;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function createContextualRangeTracker(before: string, after: string): RangeTracker {
|
|
596
|
+
const old = lineTokens(before);
|
|
597
|
+
const next = lineTokens(after);
|
|
598
|
+
if (old === undefined || next === undefined)
|
|
599
|
+
return { move: () => undefined, describe: describeUnmappedRange };
|
|
600
|
+
const context = contextualMap(old, next);
|
|
601
|
+
let ordered: LineMap | null | undefined;
|
|
602
|
+
const getOrdered = () => {
|
|
603
|
+
if (ordered === undefined) ordered = orderedMap(old, next) ?? null;
|
|
604
|
+
return ordered ?? undefined;
|
|
605
|
+
};
|
|
606
|
+
let lines: string[] | undefined;
|
|
607
|
+
let positions: Map<string, number[]> | undefined;
|
|
608
|
+
const move: RangeTracker["move"] = (range, allowAdjusted = false) => {
|
|
609
|
+
const exact = rebaseRange(range, {
|
|
610
|
+
newLine(line) {
|
|
611
|
+
const moved = context.newLine(line);
|
|
612
|
+
// The last selected line can cross EOF only if the selection excludes its ending.
|
|
613
|
+
if (
|
|
614
|
+
moved !== undefined &&
|
|
615
|
+
(line === range.end.lineNumber || old[line - 1] === next[moved - 1])
|
|
616
|
+
)
|
|
617
|
+
return moved;
|
|
618
|
+
return undefined;
|
|
619
|
+
},
|
|
620
|
+
});
|
|
621
|
+
if (exact !== undefined) return exact;
|
|
622
|
+
if (context.reordered) {
|
|
623
|
+
const moved = relocateInHunk(
|
|
624
|
+
range,
|
|
625
|
+
old,
|
|
626
|
+
next,
|
|
627
|
+
() => movedHunk(context, range.start.lineNumber),
|
|
628
|
+
true,
|
|
629
|
+
);
|
|
630
|
+
if (moved !== undefined || !allowAdjusted) return moved;
|
|
631
|
+
}
|
|
632
|
+
const map = getOrdered();
|
|
633
|
+
if (map === undefined) return undefined;
|
|
634
|
+
// The ordered diff cannot overrule conflicting context or a known different destination.
|
|
635
|
+
const last = lastSelectedLine(range);
|
|
636
|
+
for (let line = range.start.lineNumber; line <= last; line += 1) {
|
|
637
|
+
const known = context.newLine(line);
|
|
638
|
+
const orderedLine = map.newLine(line);
|
|
639
|
+
if (
|
|
640
|
+
context.conflicts[line] ||
|
|
641
|
+
(known !== undefined && known !== orderedLine) ||
|
|
642
|
+
(known === undefined &&
|
|
643
|
+
orderedLine !== undefined &&
|
|
644
|
+
(context.reordered || context.duplicated.has(lineText(old, line))))
|
|
645
|
+
)
|
|
646
|
+
return allowAdjusted ? survivingRegion(range, context, old, next) : undefined;
|
|
647
|
+
}
|
|
648
|
+
if (context.reordered) return relocateRange(range, map, (lines ??= after.split("\n")));
|
|
649
|
+
return allowAdjusted
|
|
650
|
+
? moveRange(range, map, () => (lines ??= after.split("\n")))
|
|
651
|
+
: rebaseOrRelocateRange(range, map);
|
|
652
|
+
};
|
|
653
|
+
const describe: RangeTracker["describe"] = (range) => {
|
|
654
|
+
const line = range.start.lineNumber;
|
|
655
|
+
const token = lineText(old, line);
|
|
656
|
+
const hunk = context.reordered ? movedHunk(context, line) : undefined;
|
|
657
|
+
let candidates = hunk === undefined ? [] : partialCandidateLines(range, token, next, hunk);
|
|
658
|
+
if (candidates.length === 0 && token.trim() !== "") {
|
|
659
|
+
positions ??= candidateLines(next);
|
|
660
|
+
candidates = positions.get(token) ?? [];
|
|
661
|
+
}
|
|
662
|
+
if (candidates.length === 0 && !context.reordered) {
|
|
663
|
+
const map = getOrdered();
|
|
664
|
+
if (map !== undefined) return describeLostRange(range, map);
|
|
665
|
+
}
|
|
666
|
+
const head = `line ${String(line)} \`${preview(token.trim())}\``;
|
|
667
|
+
if (candidates.length > 0)
|
|
668
|
+
return `${head}: cannot verify the same selection; candidate lines: ${candidates.join(", ")}`;
|
|
669
|
+
if (hunk !== undefined) return describeHunk(head, next, hunk);
|
|
670
|
+
return `${head}: selected text changed, was deleted, or has no unique surrounding context`;
|
|
671
|
+
};
|
|
672
|
+
return { move, describe };
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** Possible locations in a bounded moved stretch, not proof that a copy is the original. */
|
|
676
|
+
function partialCandidateLines(
|
|
677
|
+
range: ResultRange,
|
|
678
|
+
token: string,
|
|
679
|
+
lines: readonly string[],
|
|
680
|
+
hunk: LineHunk,
|
|
681
|
+
): number[] {
|
|
682
|
+
const { start, end } = range;
|
|
683
|
+
if (range.linewise === true || start.lineNumber !== end.lineNumber) return [];
|
|
684
|
+
const selected = token.slice(start.column, end.column);
|
|
685
|
+
if (selected.trim() === "" || selected.length !== end.column - start.column) return [];
|
|
686
|
+
const candidates: number[] = [];
|
|
687
|
+
for (let line = hunk.newFrom; line <= hunk.newTo && candidates.length < 3; line += 1) {
|
|
688
|
+
if (lineText(lines, line).includes(selected)) candidates.push(line);
|
|
689
|
+
}
|
|
690
|
+
return candidates;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/** Keep only a few locations per line; diagnostics never need the whole file. */
|
|
694
|
+
function candidateLines(lines: readonly string[]): Map<string, number[]> {
|
|
695
|
+
const positions = new Map<string, number[]>();
|
|
696
|
+
for (const [index, line] of lines.entries()) {
|
|
697
|
+
const token = withoutEnding(line);
|
|
698
|
+
const matches = positions.get(token);
|
|
699
|
+
if (matches === undefined) positions.set(token, [index + 1]);
|
|
700
|
+
else if (matches.length < 3) matches.push(index + 1);
|
|
701
|
+
}
|
|
702
|
+
return positions;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function describeUnmappedRange(range: ResultRange): string {
|
|
706
|
+
return `line ${String(range.start.lineNumber)}: the snapshots cannot be compared safely`;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Ranges selected in one text, placed in another text of the same source with their own text
|
|
711
|
+
* unchanged. Every reference and anchor that holds ranges of an earlier or later text uses this to
|
|
712
|
+
* resolve in the text its caller edits. Undefined when any range's own text changed.
|
|
713
|
+
*/
|
|
714
|
+
export function rangesInText(
|
|
715
|
+
ranges: readonly ResultRange[],
|
|
716
|
+
from: string,
|
|
717
|
+
to: string,
|
|
718
|
+
): ResultRange[] | undefined {
|
|
719
|
+
const tracker = createRangeTracker(from, to);
|
|
720
|
+
const moved: ResultRange[] = [];
|
|
721
|
+
for (const range of ranges) {
|
|
722
|
+
const next = tracker.move(range);
|
|
723
|
+
if (next === undefined) return undefined;
|
|
724
|
+
moved.push(next);
|
|
725
|
+
}
|
|
726
|
+
return moved;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/** Say where a range that could not be moved stands now, so the caller can pick a new target. */
|
|
730
|
+
export function describeLostRange(range: ResultRange, map: LineMap | undefined): string {
|
|
731
|
+
const line = range.start.lineNumber;
|
|
732
|
+
if (map === undefined) return `line ${String(line)}: the file changed too much to follow it`;
|
|
733
|
+
const original = lineText(map.oldLines, line).trim();
|
|
734
|
+
const hunk = hunkAround(map, line);
|
|
735
|
+
const head = `line ${String(line)} \`${preview(original)}\``;
|
|
736
|
+
if (hunk === undefined) return `${head}: changed or moved`;
|
|
737
|
+
return describeHunk(head, map.newLines, hunk);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function preview(text: string): string {
|
|
741
|
+
return text.length > 120 ? `${text.slice(0, 120)}…` : text;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function describeHunk(head: string, lines: readonly string[], hunk: LineHunk): string {
|
|
745
|
+
if (hunk.newTo < hunk.newFrom) return `${head}: deleted`;
|
|
746
|
+
const now = [];
|
|
747
|
+
for (let at = hunk.newFrom; at <= Math.min(hunk.newTo, hunk.newFrom + 2); at += 1)
|
|
748
|
+
now.push(`${String(at)}| ${preview(lineText(lines, at).trim())}`);
|
|
749
|
+
return `${head}: now ${now.join(" / ")}${hunk.newTo - hunk.newFrom > 2 ? " …" : ""}`;
|
|
750
|
+
}
|