pi-agent-ide 0.6.4 → 0.7.1
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 +45 -0
- package/README.md +2 -2
- package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
- package/dist/chunk-2TRHFMCZ.js +11 -0
- package/dist/{chunk-WJTHY6AG.js → chunk-4GCWGE2C.js} +1 -1
- package/dist/chunk-4XMY4H4V.js +1 -0
- package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
- package/dist/{chunk-QEJGED4V.js → chunk-76ZK5ODR.js} +2 -2
- package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
- package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
- package/dist/chunk-CWD4O5PM.js +3 -0
- package/dist/chunk-D3WTDA6V.js +2 -0
- package/dist/chunk-EAZGN5ND.js +7 -0
- package/dist/chunk-GXEGY7GV.js +1 -0
- package/dist/chunk-HZEY4GT4.js +2 -0
- package/dist/chunk-LEEQIQ7D.js +28 -0
- package/dist/chunk-NRZO5KJT.js +9 -0
- package/dist/chunk-OMVRLWMX.js +5 -0
- package/dist/{chunk-VBICI5YA.js → chunk-PGIVHICI.js} +1 -1
- package/dist/{chunk-FBOW7XOV.js → chunk-PKKDDIWW.js} +1 -1
- package/dist/chunk-PNU3E7IO.js +3 -0
- package/dist/chunk-PS2B6THP.js +3 -0
- package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
- package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
- package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
- package/dist/chunk-VMTR74FF.js +2 -0
- package/dist/{chunk-HPUAIWIH.js → chunk-WMO6RNE2.js} +1 -1
- package/dist/chunk-WU6ZK6YD.js +1 -0
- package/dist/{chunk-GIRAEVUJ.js → chunk-XH5WN5XA.js} +1 -1
- package/dist/chunk-XYS4FSCC.js +12 -0
- package/dist/chunk-YP46DVVP.js +2 -0
- package/dist/entry-11.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-25.js +2 -2
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +2 -2
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +12 -9
- package/dist/entry-33.js +1 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-41.js +1 -1
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +13 -14
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +3 -6
- package/dist/entry-51.js +11 -9
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.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-60.js +1 -1
- package/dist/entry-61.js +0 -1
- package/dist/entry-62.js +1 -0
- package/dist/entry-63.js +0 -1
- package/dist/entry-64.js +1 -0
- 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 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-71.js +0 -1
- package/dist/entry-72.js +1 -0
- package/dist/entry-73.js +0 -1
- package/dist/entry-74.js +1 -0
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -1
- package/dist/entry-77.js +66 -1
- package/dist/entry-78.js +14 -325
- package/dist/entry-79.js +2 -18
- package/dist/entry-80.js +1 -2
- package/dist/entry-81.js +1 -1
- package/dist/entry-82.js +5 -1
- package/dist/entry-83.js +3 -5
- package/dist/entry-84.js +1 -3
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +14 -9
- package/docs/agent-guides/editing.md +38 -33
- package/docs/agent-guides/git-changes.md +1 -1
- package/docs/agent-guides/read-resources.md +8 -4
- package/docs/agent-guides/search-code.md +34 -2
- package/docs/agent-guides/select-code.md +115 -0
- package/docs/configuration.md +12 -17
- package/docs/development.md +2 -1
- package/docs/releases.md +1 -1
- package/docs/research/apply-native-capability-matrix.md +174 -0
- package/docs/research/apply-read-latency.md +2 -0
- package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
- package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
- package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/research/native-codemode-batching.md +1 -1
- package/docs/structured-results.md +30 -38
- package/docs/tools.md +11 -11
- package/docs/user-hooks.md +1 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/index.ts +7 -6
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/index.ts +4 -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 +15 -10
- package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -5
- package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +142 -27
- package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +268 -0
- package/node_modules/pi-agent-ide-changes/index.ts +6 -21
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- 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-lsp/index.ts +5 -5
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
- package/node_modules/pi-agent-image/package.json +2 -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 +40 -3
- package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -1
- package/node_modules/pi-agent-read/src/core/extension.ts +18 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
- package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +17 -3
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +10 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +407 -0
- package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
- package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
- package/node_modules/pi-agent-search/src/api/search.ts +28 -0
- package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
- package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
- package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
- package/node_modules/pi-agent-search-text/index.ts +3 -1
- package/node_modules/pi-agent-search-text/package.json +7 -6
- package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
- package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-editor/index.ts +0 -5
- package/node_modules/pi-agent-text-editor/package.json +26 -31
- package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +22 -5
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -14
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +86 -154
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
- package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
- package/node_modules/pi-agent-web/index.ts +7 -3
- package/node_modules/pi-agent-web/package.json +8 -8
- package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
- package/node_modules/pi-agent-web/src/search.ts +111 -2
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/package.json +35 -36
- package/src/composite/module-labels.ts +1 -1
- package/src/composite/preferences.ts +0 -5
- package/src/composite/text-results.ts +221 -0
- package/src/documentation/extension.ts +11 -9
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
- 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/index.ts +4 -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-web/index.ts +7 -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-83.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-pdf/package.json +4 -4
- 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/runtime/entry-82.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -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 +40 -3
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -1
- package/src/extensions/pi-agent-read/src/core/extension.ts +18 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
- package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +17 -3
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
- package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
- package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
- package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
- package/src/extensions/pi-agent-text-editor/index.ts +0 -5
- package/src/extensions/pi-agent-text-editor/package.json +26 -31
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
- 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-78.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +22 -5
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -14
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +86 -154
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/src/pi-agent-ide.ts +4 -7
- package/src/plugins/pi-agent-ide-ast/package.json +15 -10
- package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -5
- package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +142 -27
- package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +268 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +6 -21
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- 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-lsp/index.ts +5 -5
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
- package/src/plugins/pi-agent-ide-vision/index.ts +31 -4
- package/dist/chunk-2P2OGO3G.js +0 -2
- package/dist/chunk-5J43L2RL.js +0 -11
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/chunk-7AVXUV4A.js +0 -7
- package/dist/chunk-7WCZOO5I.js +0 -1
- package/dist/chunk-BAYETTZZ.js +0 -16
- package/dist/chunk-BVK5A7ED.js +0 -28
- package/dist/chunk-F7NVAC4Q.js +0 -0
- package/dist/chunk-FZBCKIJJ.js +0 -1
- package/dist/chunk-I5JLCFUX.js +0 -1
- package/dist/chunk-KUPHNMUK.js +0 -2
- package/dist/chunk-MIZAFRDR.js +0 -1
- package/dist/chunk-PJPA5EEE.js +0 -2
- package/dist/chunk-PXWDDBBC.js +0 -0
- package/dist/chunk-SILJ3OL4.js +0 -9
- package/dist/chunk-TQZBVOTT.js +0 -5
- package/dist/chunk-VWW3RLUX.js +0 -12
- package/dist/chunk-YHUTTZC6.js +0 -2
- package/dist/chunk-ZODCBFBL.js +0 -2
- package/dist/entry-87.js +0 -1
- package/docs/agent-guides/apply.md +0 -333
- package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
- package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
- package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
- /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
- /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
- /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
# Apply scripting reference
|
|
2
|
-
|
|
3
|
-
## Before using Apply
|
|
4
|
-
|
|
5
|
-
Read this guide before writing an Apply script. Use Apply only for computed or conditional edits, selection composition, explicit checkpoints, or one coherent cross-file transaction.
|
|
6
|
-
|
|
7
|
-
When each change is already known and independent, use standalone text tools instead. Submit those tools together in one assistant response; they share the original file snapshots and work for several edits in one file or across files. Do not write a JavaScript Apply program merely to group straightforward replacements, insertions, removals, copies, or moves. Read `docs:editing` for that workflow.
|
|
8
|
-
|
|
9
|
-
Open every source first, select from immutable snapshots, stage operations, and let normal completion commit once. A thrown script commits no pending operations. Check every operation outcome: independent valid edits may succeed when another edit is rejected. Keep each returned `APPLY#` receipt for atomic undo of that checkpoint.
|
|
10
|
-
|
|
11
|
-
## Choosing a selection
|
|
12
|
-
|
|
13
|
-
Choose boundaries from the request's source of truth. Prefer content-based selections when content identifies the target:
|
|
14
|
-
|
|
15
|
-
1. Use `find` for exact occurrences.
|
|
16
|
-
2. Use `between` for blocks identified by opening and closing content.
|
|
17
|
-
3. Use `select` for a structured search result.
|
|
18
|
-
4. Use `within`, `slice`, or `union` to narrow or combine those selections.
|
|
19
|
-
5. Use `linesOf` or `between(..., { lines: true })` when the operation must include complete lines.
|
|
20
|
-
6. Use `line(first, last)` only when the user supplied those line numbers or you independently verified both inclusive bounds.
|
|
21
|
-
|
|
22
|
-
Do not infer line ranges from the starting lines of nearby blocks. Do not include a following blank line unless the requested change includes that separator.
|
|
23
|
-
|
|
24
|
-
Selections are immutable and belong to one file snapshot. A flush refreshes open documents and makes earlier selections stale. Build new selections after each checkpoint.
|
|
25
|
-
|
|
26
|
-
## Read-only helpers
|
|
27
|
-
|
|
28
|
-
### `read({...})`
|
|
29
|
-
|
|
30
|
-
Use it to inspect a resource from inside an Apply script. It accepts the same arguments as the standalone Read tool and records its result automatically.
|
|
31
|
-
|
|
32
|
-
```js
|
|
33
|
-
read({ path: "config.json", offset: 1, limit: 40 });
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Effect: reads the requested window without staging a mutation.
|
|
37
|
-
|
|
38
|
-
### `search({...})`
|
|
39
|
-
|
|
40
|
-
Use it to discover files, text, symbols, or structures before opening a document. It accepts the standalone Search arguments and records its result automatically.
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
const matches = search({ query: '"oldName"', path: "src" });
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Effect: returns structured matches without changing files.
|
|
47
|
-
|
|
48
|
-
### `diff({before, after})`
|
|
49
|
-
|
|
50
|
-
Use it to compare two sources before deciding what to edit. It accepts the standalone Diff arguments and records its result automatically.
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
diff({ before: "old\n", after: "new\n" });
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Effect: returns a read-only textual comparison.
|
|
57
|
-
|
|
58
|
-
## Opening documents
|
|
59
|
-
|
|
60
|
-
### `open(path | { path, views? })`
|
|
61
|
-
|
|
62
|
-
Use it before selecting or editing an existing text resource.
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
const file = open("src/example.ts");
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Effect: creates an editor handle backed by an immutable snapshot. `file.source`, `file.content`, and `file.lines` expose its source, full canonical text, and line count. Supplying `views` changes how the source is opened when that resource supports views.
|
|
69
|
-
|
|
70
|
-
## Selection primitives
|
|
71
|
-
|
|
72
|
-
### `file.find(text)`
|
|
73
|
-
|
|
74
|
-
Use it when an exact string identifies one or more targets.
|
|
75
|
-
|
|
76
|
-
```js
|
|
77
|
-
const names = file.find("oldName");
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Effect: returns every exact occurrence in source order. It does not silently choose one occurrence. Use `slice` or `within` when only some occurrences are intended.
|
|
81
|
-
|
|
82
|
-
### `file.select(searchMatch)`
|
|
83
|
-
|
|
84
|
-
Use it to turn one structured Search match into a selection in its source document.
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
const target = file.select(matches[0]);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Effect: maps the match's line and column range to the open snapshot. It rejects matches from another file and matches whose recorded text is stale.
|
|
91
|
-
|
|
92
|
-
### `file.between(start, end, options?)`
|
|
93
|
-
|
|
94
|
-
Use it for blocks whose boundaries are identified by content or existing selections.
|
|
95
|
-
|
|
96
|
-
```js
|
|
97
|
-
const block = file.between("BEGIN", "END", { lines: true });
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Effect: pairs each start with the first end after that start, then continues with later non-overlapping pairs. By default both boundaries are included. `{ inside: true }` excludes both boundaries. `{ lines: true }` expands through the complete lines containing both boundaries, including the closing line's newline but not a following blank separator. `inside` and `lines` cannot be combined.
|
|
101
|
-
|
|
102
|
-
If repeated boundaries produce several blocks, narrow the result with `slice` rather than assuming only one pair exists.
|
|
103
|
-
|
|
104
|
-
### `file.line(first, last?)`
|
|
105
|
-
|
|
106
|
-
Use it only when the 1-based line bounds are authoritative or already verified.
|
|
107
|
-
|
|
108
|
-
```js
|
|
109
|
-
const header = file.line(1, 3);
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
Effect: selects complete lines from `first` through `last`, inclusive. Omitting `last` selects one line. Invalid, negative, reversed, or out-of-range bounds are rejected.
|
|
113
|
-
|
|
114
|
-
### `file.start()` and `file.end()`
|
|
115
|
-
|
|
116
|
-
Use them as zero-width destinations when `copy` or `move` should insert at the beginning or end of a document.
|
|
117
|
-
|
|
118
|
-
```js
|
|
119
|
-
copy(source.find("preamble"), target.start());
|
|
120
|
-
move(source.find("appendix"), target.end());
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Effect: returns a zero-width linewise selection at byte zero or end of file. These are positions, not existing text.
|
|
124
|
-
|
|
125
|
-
### `file.before(selection)` and `file.after(selection)`
|
|
126
|
-
|
|
127
|
-
Use them to convert selected content into insertion positions.
|
|
128
|
-
|
|
129
|
-
```js
|
|
130
|
-
const destination = file.before(file.find("export default"));
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
Effect: returns zero-width positions immediately before or after every selected range. Linewise selections retain linewise insertion behavior.
|
|
134
|
-
|
|
135
|
-
### `file.slice(selection, start?, end?)`
|
|
136
|
-
|
|
137
|
-
Use it to choose occurrences by position after a broader selector has found them.
|
|
138
|
-
|
|
139
|
-
```js
|
|
140
|
-
const first = file.slice(file.find("token"), 0, 1);
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
Effect: returns the same ranges that normal JavaScript array `slice(start, end)` would retain. It does not alter the document.
|
|
144
|
-
|
|
145
|
-
### `file.union(...selections)`
|
|
146
|
-
|
|
147
|
-
Use it to combine separate selections from the same snapshot into one mutation target.
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
const targets = file.union(file.find("alpha"), file.find("beta"));
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Effect: sorts ranges, removes exact duplicates, and rejects overlaps. It never turns sparse targets into one wide range containing the text between them.
|
|
154
|
-
|
|
155
|
-
### `file.within(candidates, scopes)`
|
|
156
|
-
|
|
157
|
-
Use it to keep only candidates fully contained by selected scopes.
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
const localNames = file.within(file.find("name"), file.between("class A", "}"));
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Effect: returns each candidate whose complete range lies inside at least one scope.
|
|
164
|
-
|
|
165
|
-
### `file.linesOf(selection)`
|
|
166
|
-
|
|
167
|
-
Use it when content matches identify targets but the operation must affect their complete containing lines.
|
|
168
|
-
|
|
169
|
-
```js
|
|
170
|
-
const declarations = file.linesOf(file.find("const obsolete ="));
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
Effect: expands every range to its containing line, preserves line endings, and removes duplicate line ranges.
|
|
174
|
-
|
|
175
|
-
## Text mutations
|
|
176
|
-
|
|
177
|
-
Every text mutation stages one operation for every selected range. Empty selections produce a warning rather than a guessed edit. Global forms infer the document from the SelectionSet; document methods provide the same behavior and may also accept a directly resolvable string target.
|
|
178
|
-
|
|
179
|
-
### `replace(selection, text)` and `file.replace(target, text)`
|
|
180
|
-
|
|
181
|
-
Use them to replace selected text.
|
|
182
|
-
|
|
183
|
-
```js
|
|
184
|
-
replace(file.find("oldName"), "newName");
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
Effect: replaces every selected range with `text` in one transaction.
|
|
188
|
-
|
|
189
|
-
### `remove(selection)` and `file.remove(target)`
|
|
190
|
-
|
|
191
|
-
Use them to remove selected text, not files.
|
|
192
|
-
|
|
193
|
-
```js
|
|
194
|
-
remove(file.linesOf(file.find("obsolete();")));
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
Effect: replaces every selected range with an empty string. Use precise sparse selections instead of a broad range spanning unrelated content.
|
|
198
|
-
|
|
199
|
-
### `insertBefore(selection, text)` and `file.insertBefore(target, text)`
|
|
200
|
-
|
|
201
|
-
Use them to insert text immediately before each selected range.
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
insertBefore(file.linesOf(file.find("function run")), "// Entry point\n");
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Effect: keeps the selected text and inserts before it. For linewise selections, Apply supplies the needed line boundary. Pass `{ separation: "blank-line" }` as a third argument to add only missing blank lines around a separate block; the default is `"line"`. An empty insert is rejected.
|
|
208
|
-
|
|
209
|
-
### `insertAfter(selection, text)` and `file.insertAfter(target, text)`
|
|
210
|
-
|
|
211
|
-
Use them to insert text immediately after each selected range.
|
|
212
|
-
|
|
213
|
-
```js
|
|
214
|
-
insertAfter(file.linesOf(file.find("import value")), 'import other from "./other.js";\n');
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
Effect: keeps the selected text and inserts after it. For linewise selections, Apply supplies the needed line boundary, including at an unterminated final line.
|
|
218
|
-
|
|
219
|
-
## Moving and copying text
|
|
220
|
-
|
|
221
|
-
### `copy(source, destination)`
|
|
222
|
-
|
|
223
|
-
Use it to duplicate selected text within one file or across open files.
|
|
224
|
-
|
|
225
|
-
```js
|
|
226
|
-
copy(source.find("sharedValue"), target.end());
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
Effect: concatenates source ranges in selection order. A zero-width destination inserts that text; a non-empty destination replaces it. Source text remains unchanged.
|
|
230
|
-
|
|
231
|
-
### `move(source, destination)`
|
|
232
|
-
|
|
233
|
-
Use it to relocate selected text within one file or across open files.
|
|
234
|
-
|
|
235
|
-
```js
|
|
236
|
-
move(source.between("BEGIN", "END", { lines: true }), target.end());
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
Effect: performs the same destination insertion or replacement as `copy`, then removes every source range in the same coherent transaction. Prefer linewise selections when moving complete blocks so separators remain stable.
|
|
240
|
-
|
|
241
|
-
## Whole-file operations
|
|
242
|
-
|
|
243
|
-
### `createFile(path, content)`
|
|
244
|
-
|
|
245
|
-
Use it to create a new file from complete content.
|
|
246
|
-
|
|
247
|
-
```js
|
|
248
|
-
createFile("src/new.ts", "export const value = 1;\n");
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
Effect: stages creation at `path`. It does not overwrite an existing file.
|
|
252
|
-
|
|
253
|
-
### `file.delete()` and `deleteFile(path)`
|
|
254
|
-
|
|
255
|
-
Use `file.delete()` when an opened file should be deleted after its earlier staged operations. Use `deleteFile(path)` when no document handle is needed.
|
|
256
|
-
|
|
257
|
-
```js
|
|
258
|
-
const obsolete = open("src/obsolete.ts");
|
|
259
|
-
obsolete.delete();
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
Effect: stages whole-file deletion. This is distinct from `remove(selection)`, which removes text.
|
|
263
|
-
|
|
264
|
-
### `copyFile(path, target, { overwrite? })`
|
|
265
|
-
|
|
266
|
-
Use it to copy one complete file.
|
|
267
|
-
|
|
268
|
-
```js
|
|
269
|
-
copyFile("config.example.json", "config.json");
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
Effect: stages a file copy. An existing regular target is rejected unless `overwrite: true` is explicit.
|
|
273
|
-
|
|
274
|
-
### `moveFile(path, target, { overwrite? })`
|
|
275
|
-
|
|
276
|
-
Use it to rename or relocate one complete file.
|
|
277
|
-
|
|
278
|
-
```js
|
|
279
|
-
moveFile("src/old.ts", "src/new.ts");
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
Effect: stages a file move. An existing regular target is rejected unless `overwrite: true` is explicit.
|
|
283
|
-
|
|
284
|
-
## Checkpoints and transaction guarantees
|
|
285
|
-
|
|
286
|
-
### `file.flush()`
|
|
287
|
-
|
|
288
|
-
Use it to checkpoint independent operations staged for one document when later work needs a refreshed snapshot.
|
|
289
|
-
|
|
290
|
-
```js
|
|
291
|
-
file.replace(file.find("old"), "new");
|
|
292
|
-
file.flush();
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
Effect: commits that file's independent pending operations, refreshes its open handle, and makes its earlier selections stale. If the file participates in a pending cross-file `copy` or `move`, nothing for that file is flushed so the transfer keeps one coherent snapshot.
|
|
296
|
-
|
|
297
|
-
### `flush()`
|
|
298
|
-
|
|
299
|
-
Use it only when the script deliberately needs a global checkpoint before continuing.
|
|
300
|
-
|
|
301
|
-
```js
|
|
302
|
-
flush();
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
Effect: commits every pending operation, refreshes affected open handles, and can return an `APPLY#` receipt. Normal successful completion already performs one global flush. A later thrown error does not undo an earlier explicit checkpoint.
|
|
306
|
-
|
|
307
|
-
## Failure, ordering, and undo
|
|
308
|
-
|
|
309
|
-
Operations are evaluated against their captured snapshots, not against text shifted by earlier staged edits. This makes several non-overlapping edits safe without compensating line numbers. Overlapping or stale selections are rejected rather than guessed.
|
|
310
|
-
|
|
311
|
-
A successful checkpoint may return an `APPLY#` receipt. Restore every path touched by that checkpoint atomically with:
|
|
312
|
-
|
|
313
|
-
```js
|
|
314
|
-
undo({ transaction: "APPLY#..." });
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
Separate explicit checkpoints can produce separate receipts. Do not assume one receipt covers changes committed by an earlier flush.
|
|
318
|
-
|
|
319
|
-
## Standalone anchors and specialized resources
|
|
320
|
-
|
|
321
|
-
Standalone text tools support line anchors, syntax-scope anchors, search selections, and unique exact strings. With an `end` selector, they operate on complete lines through the line containing the end boundary. Without `end`, an exact string selects only that fragment.
|
|
322
|
-
|
|
323
|
-
When a standalone text tool allows an omitted path, it can inherit the source identified by its anchor, the last read, or the preceding edit in the same batch. Supply the path explicitly when that inheritance would be ambiguous.
|
|
324
|
-
|
|
325
|
-
Some resources attach non-text actions to the same tools:
|
|
326
|
-
|
|
327
|
-
- `shell:<session>` — `write` sends exact input, `insert` sends named keys, and `delete` terminates the session.
|
|
328
|
-
- `debug:<session>` — `insert` controls the debugger and `delete` removes a breakpoint or terminates the session.
|
|
329
|
-
- `symbol:<file>#<selector>#name` — `replace` performs a native language-server rename when available.
|
|
330
|
-
|
|
331
|
-
Read `docs:terminal`, `docs:debugger`, or `docs:search-code` before using those specialized resources.
|
|
332
|
-
|
|
333
|
-
Never guess after a stale snapshot, empty selection, ambiguous target, or unknown rollback effect.
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
-
import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
export interface ApplyUndoBeforeState {
|
|
6
|
-
readonly path: string;
|
|
7
|
-
readonly existed: boolean;
|
|
8
|
-
readonly bytes?: Uint8Array;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface ApplyUndoPathState extends ApplyUndoBeforeState {
|
|
12
|
-
after: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface ApplyUndoReceipt {
|
|
16
|
-
readonly paths: readonly ApplyUndoPathState[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ApplyUndoResult {
|
|
20
|
-
readonly transaction: string;
|
|
21
|
-
readonly restored: readonly string[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Session-local, single-use receipts for atomic Apply rollback. */
|
|
25
|
-
export class ApplyUndoStore {
|
|
26
|
-
readonly #receipts = new Map<string, ApplyUndoReceipt>();
|
|
27
|
-
readonly #restoreState: (state: ApplyUndoBeforeState) => Promise<void>;
|
|
28
|
-
|
|
29
|
-
public constructor(restore = restoreState) {
|
|
30
|
-
this.#restoreState = restore;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async record(before: readonly ApplyUndoBeforeState[]): Promise<string> {
|
|
34
|
-
const touched = new Set(before.map((state) => path.normalize(state.path)));
|
|
35
|
-
this.invalidate(touched);
|
|
36
|
-
const paths = await Promise.all(
|
|
37
|
-
before.map(async (state) => ({ ...state, after: await fingerprint(state.path) })),
|
|
38
|
-
);
|
|
39
|
-
const transaction = `APPLY#${randomBytes(6).toString("hex").toUpperCase()}`;
|
|
40
|
-
this.#receipts.set(transaction, { paths });
|
|
41
|
-
return transaction;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public observeTextChange(
|
|
45
|
-
file: string,
|
|
46
|
-
before: string,
|
|
47
|
-
after: string,
|
|
48
|
-
postProcessing: "deferred" | "complete" | "final",
|
|
49
|
-
): void {
|
|
50
|
-
const normalized = path.normalize(file);
|
|
51
|
-
if (postProcessing === "final") {
|
|
52
|
-
const beforeFingerprint = textFingerprint(before);
|
|
53
|
-
for (const receipt of this.#receipts.values()) {
|
|
54
|
-
const state = receipt.paths.find(
|
|
55
|
-
(candidate) => path.normalize(candidate.path) === normalized,
|
|
56
|
-
);
|
|
57
|
-
if (state?.after === beforeFingerprint) state.after = textFingerprint(after);
|
|
58
|
-
}
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.invalidate(new Set([normalized]));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public invalidate(paths: ReadonlySet<string>): void {
|
|
65
|
-
for (const [transaction, receipt] of this.#receipts) {
|
|
66
|
-
if (receipt.paths.some((state) => paths.has(path.normalize(state.path))))
|
|
67
|
-
this.#receipts.delete(transaction);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public has(transaction: string): boolean {
|
|
72
|
-
return this.#receipts.has(transaction);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Paths reserved by a receipt; unavailable receipts cannot restore any paths. */
|
|
76
|
-
public sources(transaction: string): readonly string[] {
|
|
77
|
-
return this.#receipts.get(transaction)?.paths.map((state) => state.path) ?? [];
|
|
78
|
-
}
|
|
79
|
-
public async restore(transaction: string): Promise<ApplyUndoResult> {
|
|
80
|
-
const receipt = this.#receipts.get(transaction);
|
|
81
|
-
if (receipt === undefined)
|
|
82
|
-
throw coded("APPLY_UNDO_UNAVAILABLE", `No undo receipt is available for ${transaction}.`);
|
|
83
|
-
|
|
84
|
-
for (const state of receipt.paths) {
|
|
85
|
-
if ((await fingerprint(state.path)) !== state.after) {
|
|
86
|
-
this.#receipts.delete(transaction);
|
|
87
|
-
throw coded(
|
|
88
|
-
"APPLY_UNDO_STALE",
|
|
89
|
-
`${state.path} changed after ${transaction}; refusing to overwrite newer content.`,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const current = await Promise.all(receipt.paths.map((state) => save(state.path)));
|
|
95
|
-
try {
|
|
96
|
-
for (const state of receipt.paths) await this.#restoreState(state);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
const rollbackErrors: string[] = [];
|
|
99
|
-
for (const state of current) {
|
|
100
|
-
try {
|
|
101
|
-
await this.#restoreState(state);
|
|
102
|
-
} catch (rollbackError) {
|
|
103
|
-
rollbackErrors.push(
|
|
104
|
-
`${state.path}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
throw Object.assign(
|
|
109
|
-
coded("APPLY_UNDO_FAILED", error instanceof Error ? error.message : String(error)),
|
|
110
|
-
{ rollbackErrors },
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.#receipts.delete(transaction);
|
|
115
|
-
return { transaction, restored: receipt.paths.map((state) => state.path) };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function save(file: string): Promise<ApplyUndoBeforeState> {
|
|
120
|
-
try {
|
|
121
|
-
const stat = await lstat(file);
|
|
122
|
-
if (!stat.isFile() || stat.isSymbolicLink())
|
|
123
|
-
throw coded("INVALID_FILE_TYPE", `${file} is not a regular file.`);
|
|
124
|
-
return { path: file, existed: true, bytes: await readFile(file) };
|
|
125
|
-
} catch (error) {
|
|
126
|
-
if (hasCode(error, "ENOENT")) return { path: file, existed: false };
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function textFingerprint(content: string): string {
|
|
132
|
-
return `file:${createHash("sha256").update(content).digest("hex")}`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function fingerprint(file: string): Promise<string> {
|
|
136
|
-
const state = await save(file);
|
|
137
|
-
return state.existed
|
|
138
|
-
? `file:${createHash("sha256")
|
|
139
|
-
.update(state.bytes ?? new Uint8Array())
|
|
140
|
-
.digest("hex")}`
|
|
141
|
-
: "absent";
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function restoreState(state: ApplyUndoBeforeState): Promise<void> {
|
|
145
|
-
if (!state.existed) {
|
|
146
|
-
await rm(state.path, { force: true });
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
await mkdir(path.dirname(state.path), { recursive: true });
|
|
150
|
-
await writeFile(state.path, state.bytes ?? new Uint8Array());
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function coded(code: string, message: string): Error {
|
|
154
|
-
return Object.assign(new Error(message), { code });
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function hasCode(error: unknown, code: string): boolean {
|
|
158
|
-
return error !== null && typeof error === "object" && "code" in error && error.code === code;
|
|
159
|
-
}
|