pi-agent-ide 0.6.3 → 0.7.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 +97 -0
- package/README.md +10 -3
- package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
- package/dist/chunk-3HYXQ4YA.js +28 -0
- package/dist/chunk-3JO7QFIL.js +1 -0
- package/dist/chunk-4NIFBFFR.js +11 -0
- package/dist/{chunk-VCTK4JSN.js → chunk-64M3SQPG.js} +1 -1
- package/dist/{chunk-5QQABP47.js → chunk-7LD2OQH3.js} +1 -1
- package/dist/chunk-7LZKOHH2.js +1 -0
- package/dist/chunk-AJRIASPQ.js +2 -0
- package/dist/chunk-EAZGN5ND.js +7 -0
- package/dist/{chunk-ZM4L5AGN.js → chunk-EDURPQAV.js} +3 -2
- package/dist/{chunk-GIRAEVUJ.js → chunk-F5YZG77W.js} +1 -1
- package/dist/chunk-FK42RSF4.js +1 -0
- package/dist/{chunk-O6LE42GK.js → chunk-FXNKMNSJ.js} +1 -1
- package/dist/chunk-GBLKIB6O.js +2 -0
- package/dist/chunk-KBP3QUDT.js +2 -0
- package/dist/chunk-KR36BT5E.js +1 -0
- package/dist/{chunk-NTYXZ3EL.js → chunk-KVHDMIZS.js} +1 -1
- package/dist/{chunk-QDST6VIU.js → chunk-KZC7TI5M.js} +1 -1
- package/dist/chunk-OE7QVAI2.js +5 -0
- package/dist/{chunk-GUTQ3PWL.js → chunk-PLKYHUNT.js} +1 -1
- package/dist/chunk-PNU3E7IO.js +3 -0
- package/dist/chunk-PS2B6THP.js +3 -0
- package/dist/chunk-PYPPV2F5.js +25 -0
- package/dist/{chunk-25CZ5ZIU.js → chunk-QFTBY67N.js} +3 -3
- package/dist/chunk-S5LXX32D.js +28 -0
- package/dist/chunk-SILJ3OL4.js +9 -0
- package/dist/chunk-SQKAXYIR.js +2 -0
- package/dist/chunk-VCGNVTXQ.js +1 -0
- package/dist/chunk-XYS4FSCC.js +12 -0
- package/dist/chunk-YGGKGZO2.js +1 -0
- package/dist/{chunk-L7JMDDSD.js → chunk-YRF7OATP.js} +1 -1
- package/dist/chunk-ZPT5D4VP.js +2 -0
- package/dist/entry-0.js +1 -1
- 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-16.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 +1 -1
- 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 +11 -9
- package/dist/entry-33.js +1 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-42.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +12 -11
- 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-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 +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-72.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-77.js +50 -307
- package/dist/entry-78.js +14 -26
- package/dist/entry-79.js +2 -2
- package/dist/entry-80.js +1 -1
- package/dist/entry-81.js +1 -1
- package/dist/entry-82.js +5 -3
- package/dist/entry-83.js +1 -1
- package/dist/entry-84.js +1 -1
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +15 -3
- package/docs/agent-guides/editing.md +31 -3
- package/docs/agent-guides/git-changes.md +1 -1
- package/docs/agent-guides/json-reading.md +19 -3
- package/docs/agent-guides/read-resources.md +15 -1
- package/docs/agent-guides/search-code.md +43 -2
- package/docs/agent-guides/select-code.md +194 -0
- package/docs/agent-guides/terminal.md +1 -1
- package/docs/code-review.md +99 -0
- package/docs/configuration.md +36 -7
- package/docs/development.md +16 -19
- package/docs/nightly.md +7 -0
- package/docs/releases.md +42 -0
- 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 +29 -0
- package/docs/research/native-codemode-batching.md +65 -0
- package/docs/structured-results.md +86 -0
- package/docs/tools.md +24 -4
- 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-documentation/src/index.ts +1 -1
- package/node_modules/pi-agent-filesystem/index.ts +6 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -6
- package/node_modules/pi-agent-filesystem/src/path-recovery.ts +109 -0
- 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 +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 +4 -2
- package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +6 -2
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +110 -7
- 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 +251 -0
- package/node_modules/pi-agent-ide-changes/index.ts +2 -24
- package/node_modules/pi-agent-ide-changes/package.json +8 -7
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +126 -48
- 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 +2 -2
- 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 -30
- 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/read-parameters.ts +2 -2
- package/node_modules/pi-agent-read/src/api/tools/read.ts +35 -2
- package/node_modules/pi-agent-read/src/core/extension.ts +11 -0
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
- 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 +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +127 -73
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +22 -0
- package/node_modules/pi-agent-resource/src/resource-access.ts +55 -0
- package/node_modules/pi-agent-resource/src/resource-scheduler.ts +204 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +233 -0
- package/node_modules/pi-agent-resource/src/tool-result.ts +125 -0
- package/node_modules/pi-agent-search/package.json +5 -4
- 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 +13 -6
- package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
- package/node_modules/pi-agent-search/src/api/search.ts +39 -0
- package/node_modules/pi-agent-search/src/api/structured-result.ts +148 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +90 -24
- package/node_modules/pi-agent-search/src/core/search-core.ts +145 -78
- package/node_modules/pi-agent-search-text/index.ts +6 -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 +174 -26
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +201 -18
- package/node_modules/pi-agent-search-text/src/search-query.ts +42 -34
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +18 -4
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +90 -259
- package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +110 -17
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/text-document.ts +15 -10
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.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 +4 -7
- package/node_modules/pi-agent-text-editor/package.json +20 -21
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +78 -41
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +12 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +35 -4
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +1 -1
- 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 +2 -0
- 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 +820 -0
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
- 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 +412 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +149 -139
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +236 -185
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +253 -203
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
- 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 +9 -73
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -5
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +276 -129
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +16 -1
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- 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 +23 -0
- package/node_modules/pi-agent-web/package.json +7 -6
- package/node_modules/pi-agent-web/src/search.ts +221 -0
- package/node_modules/pi-agent-web-html/package.json +2 -2
- package/node_modules/pi-agent-web-image/package.json +3 -3
- package/node_modules/pi-agent-web-pdf/package.json +3 -3
- package/node_modules/pi-agent-web-text/package.json +3 -3
- package/package.json +42 -37
- package/skills/capture-code-review-rule/SKILL.md +60 -0
- package/src/code-review/config.ts +68 -0
- package/src/code-review/extension.ts +105 -0
- package/src/code-review/fragments.ts +26 -0
- package/src/code-review/reviewer.ts +198 -0
- package/src/composite/host-version.ts +13 -0
- package/src/composite/module-labels.ts +1 -1
- package/src/composite/nested-tool-rendering.ts +298 -0
- package/src/composite/preferences.ts +0 -5
- package/src/composite/tool-availability.ts +90 -0
- package/src/core/extension.ts +2 -0
- package/src/documentation/extension.ts +81 -145
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +6 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -6
- 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/path-recovery.ts +109 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +221 -0
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +35 -2
- package/src/extensions/pi-agent-read/src/core/extension.ts +11 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
- 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 +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +127 -73
- package/src/extensions/pi-agent-search/package.json +5 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +6 -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 +174 -26
- 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 +201 -18
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +42 -34
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +18 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +90 -259
- 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 +110 -17
- 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 +13 -6
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +39 -0
- package/src/extensions/pi-agent-search/src/api/structured-result.ts +148 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +90 -24
- package/src/extensions/pi-agent-search/src/core/search-core.ts +145 -78
- package/src/extensions/pi-agent-text-editor/index.ts +4 -7
- package/src/extensions/pi-agent-text-editor/package.json +20 -21
- 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/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.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 +9 -73
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +276 -129
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
- 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/index.ts +16 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +78 -41
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +12 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +35 -4
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +1 -1
- 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 +2 -0
- 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 +820 -0
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
- 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 +412 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +149 -139
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +236 -185
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +253 -203
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
- 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 +61 -8
- 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 +4 -2
- package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +6 -2
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +110 -7
- 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 +251 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +2 -24
- package/src/plugins/pi-agent-ide-changes/package.json +8 -7
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +126 -48
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/src/plugins/pi-agent-ide-debugger/index.ts +63 -17
- package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +18 -2
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +24 -4
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +68 -2
- package/src/plugins/pi-agent-ide-debugger/src/java-runtime.ts +357 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +55 -3
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +13 -13
- 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 +2 -2
- 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 -30
- package/src/plugins/pi-agent-ide-terminal/index.ts +12 -2
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +65 -30
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +16 -37
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +1 -0
- package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +100 -0
- package/src/plugins/pi-agent-ide-terminal/src/steering.ts +62 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +98 -46
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +3 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +15 -6
- package/src/plugins/pi-agent-ide-vision/index.ts +35 -1
- package/dist/chunk-3E2NTWCN.js +0 -2
- package/dist/chunk-4LUW26BX.js +0 -10
- package/dist/chunk-4U2GUKNJ.js +0 -0
- package/dist/chunk-5VSE5X5R.js +0 -2
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/chunk-7WCZOO5I.js +0 -1
- package/dist/chunk-CEX3VOJ7.js +0 -2
- package/dist/chunk-FA6BKC5Y.js +0 -1
- package/dist/chunk-FEDVTZJG.js +0 -1
- package/dist/chunk-HMLH43ZS.js +0 -4
- package/dist/chunk-ITSNK5YG.js +0 -7
- package/dist/chunk-KII2JQC5.js +0 -1
- package/dist/chunk-LVWMWWWF.js +0 -28
- package/dist/chunk-P7XO5CIP.js +0 -2
- package/dist/chunk-PZFOOHY2.js +0 -15
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/chunk-S3ZPXWX7.js +0 -2
- package/dist/chunk-T7CZIACQ.js +0 -27
- package/dist/chunk-VXD6FZP5.js +0 -5
- package/dist/chunk-YHUTTZC6.js +0 -2
- package/dist/chunk-YT42LKFV.js +0 -16
- 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 -155
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -344
- 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 -133
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -148
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -920
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
- 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 -155
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -344
- 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 -133
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -148
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -920
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import"./chunk-MPT3R4BL.js";import{a as y,b as A,c as D,d as k}from"./chunk-T7I2VX3J.js";import{a as I}from"./chunk-6CZO43OH.js";import{a as E,b as P}from"./chunk-OBNING2A.js";import{a}from"./chunk-EI7MMDWY.js";var N=/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/,h=class{static{a(this,"AgentDocumentationRegistry")}#e=new Map;register(n){let o=new Set(this.#e.keys());for(let r of n)_(r,o),o.add(r.id);for(let r of n)this.#e.set(r.id,b(r))}list(){return[...this.#e.values()].sort((n,o)=>n.id.localeCompare(o.id))}get(n){return this.#e.get(n)}matching(n,o){let r=v(o);return r?.startsWith("docs:")===!0?[]:this.list().filter(s=>s.triggers.some(d=>{if(d.tool!==n)return!1;let l=d.resourcePrefixes===void 0||r!==void 0&&d.resourcePrefixes.some(i=>r.startsWith(i)),t=d.viewPrefixes===void 0||T(o).some(i=>d.viewPrefixes?.some(u=>i.startsWith(u)));return l&&t}))}};function _(e,n){if(!N.test(e.id))throw new Error(`Invalid documentation ID: ${e.id}`);if(e.description.trim().length===0)throw new Error(`Documentation ${e.id} has no description`);if(e.markdown.trim().length===0)throw new Error(`Documentation ${e.id} has no Markdown content`);if(e.triggers.length===0||e.triggers.some(o=>o.tool.trim().length===0||o.resourcePrefixes?.some(r=>r.length===0)===!0||o.viewPrefixes?.some(r=>r.length===0)===!0))throw new Error(`Documentation ${e.id} has no valid triggers`);if(n.has(e.id))throw new Error(`Documentation ${e.id} is already registered`)}a(_,"validateDocument");function b(e){return Object.freeze({...e,triggers:Object.freeze(e.triggers.map(n=>Object.freeze({...n,...n.resourcePrefixes===void 0?{}:{resourcePrefixes:Object.freeze([...n.resourcePrefixes])},...n.viewPrefixes===void 0?{}:{viewPrefixes:Object.freeze([...n.viewPrefixes])}})))})}a(b,"freezeDocument");function T(e){if(typeof e!="object"||e===null)return[];let n=e.views;return Array.isArray(n)?n.filter(o=>typeof o=="string"):[]}a(T,"readViews");function v(e){if(typeof e!="object"||e===null)return;let n=e.path;return typeof n=="string"?n:void 0}a(v,"readPath");var R="agent-documentation-read";async function M(e){let n=new h,o=new Set,r=new Map,s=new Map,d=a(t=>{let i=t.filter(u=>!o.has(u));if(i.length!==0){e.appendEntry(R,{ids:i});for(let u of i)o.add(u)}},"remember"),l=e.events.on(k,t=>{if(!z(t))throw new Error("Invalid agent documentation registration");n.register(t.documents)});e.on("session_shutdown",l),await I(e,{protocol:E,apiVersion:P,id:"agent-documentation",setup(t){t.addResolver({resolver:{id:"agent-documentation",tryResolve(i){if(!i.startsWith("docs:"))return Promise.resolve({kind:"not-handled"});let u=i.slice(5),m=u.length===0?void 0:n.get(u),g=u.length===0?$(n.list()):m?.markdown;return g===void 0?Promise.resolve({kind:"failed",error:new Error(`Unknown documentation ID: ${u}`)}):Promise.resolve({kind:"resolved",resource:{source:i,read:a(()=>Promise.resolve([{type:"text",text:g}]),"read")}})}}}),t.describe(()=>n.list().length===0?void 0:"docs: and docs:<id> \u2014 list or read packaged agent guidance."),t.addPromptGuideline(()=>j(n.list()))}}),e.on("session_start",(t,i)=>{w(i.sessionManager.getBranch(),n,o)}),e.on("session_tree",(t,i)=>{w(i.sessionManager.getBranch(),n,o)}),e.on("session_compact",(t,i)=>{w(i.sessionManager.getBranch(),n,o)}),e.on("tool_call",t=>{t.toolCallId.includes("-preflight-")||t.parentToolCallId!==void 0&&r.set(t.toolCallId,t.parentToolCallId)}),e.on("tool_result",t=>{if(t.toolCallId.includes("-preflight-"))return;let i=r.get(t.toolCallId);r.delete(t.toolCallId);let u=s.get(t.toolCallId)??[];s.delete(t.toolCallId);let m=t.toolName==="read"?S(t.input):void 0;if(m!==void 0){let c=m.slice(5),C=c.length===0||n.get(c)!==void 0,p=n.get(c);return p!==void 0&&!t.isError&&O(t.content,p)&&d([c]),{content:t.content,structuredContent:t.structuredContent,details:{...f(t.details)?t.details:{},documentation:C?c.length===0?{kind:"list",ids:n.list().map(x=>x.id)}:{kind:"document",id:c}:{kind:"error",code:"UNKNOWN_DOCUMENTATION",id:c}},isError:t.isError}}let g=[...u,...n.matching(t.toolName,t.input).filter(c=>!o.has(c.id))];if(g.length!==0)return d(g.map(c=>c.id)),i!==void 0&&t.structuredContent!==void 0&&s.set(i,[...s.get(i)??[],...g]),{content:[...t.content,...g.map(c=>({type:"text",text:`
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Guide: ${c.id}
|
|
6
|
+
|
|
7
|
+
${c.markdown.trim()}`}))],structuredContent:t.structuredContent,details:{...f(t.details)?t.details:{},documentation:{kind:"attachment",ids:g.map(c=>c.id)}},isError:t.isError}}),e.events.emit(D,{protocol:y,apiVersion:A})}a(M,"registerProgressiveDocumentation");function $(e){return e.length===0?"No agent documentation is currently available.":["# Available agent documentation","",...e.map(n=>`- \`${n.id}\` \u2014 ${n.description}`)].join(`
|
|
8
|
+
`)}a($,"renderListing");function j(e){if(e.length!==0)return["Read the matching docs:<id> before using any tool or feature with packaged guidance, including tools discovered later or called through Codemode. Read each guide once per branch. Tool descriptions and docs: listings do not replace the full guide.","If a result includes a Guide, read it before your next use. The call has already run: do not repeat it just to obtain documentation. Native structured child calls keep their guides on the parent result. Output readable-only child results to retain their guides; filtering those results can hide them.","Available documents:",...e.map(n=>` - ${n.id} \u2014 ${n.description}`)].join(`
|
|
9
|
+
`)}a(j,"renderPromptGuideline");function w(e,n,o){o.clear();for(let s of e){if(!f(s))continue;if(s.type==="custom"&&s.customType===R&&f(s.data)){r(s.data.ids);continue}if(s.type!=="message"||!f(s.message))continue;let d=s.message;if(d.role!=="toolResult"||!f(d.details))continue;let l=d.details.documentation;if(f(l)&&(l.kind==="attachment"&&r(l.ids),l.kind==="document"&&!d.isError&&typeof l.id=="string")){let t=n.get(l.id);t!==void 0&&O(d.content,t)&&r([t.id])}}function r(s){if(Array.isArray(s))for(let d of s)typeof d=="string"&&n.get(d)!==void 0&&o.add(d)}a(r,"addIds")}a(w,"restoreClaims");function O(e,n){return Array.isArray(e)&&e.some(o=>f(o)&&o.type==="text"&&typeof o.text=="string"&&o.text.includes(n.markdown.trim()))}a(O,"containsFullGuide");function S(e){if(!(!f(e)||typeof e.path!="string"||!e.path.startsWith("docs:")))return e.path}a(S,"documentationSource");function z(e){return f(e)&&Array.isArray(e.documents)}a(z,"isRegistrationRequest");function f(e){return typeof e=="object"&&e!==null}a(f,"isRecord");export{M as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as i}from"./chunk-EI7MMDWY.js";import{AsyncLocalStorage as ye}from"node:async_hooks";function re(){return{pending:new Set,active:new ye}}i(re,"createSchedulerState");function Ce(t,e){return t===void 0||e===void 0?!0:t.some(r=>e.some(n=>(r.mode==="write"||n.mode==="write")&&(r.resource==="*"||n.resource==="*"||r.resource===n.resource||r.recursive===!0&&n.resource.startsWith(r.resource.endsWith("/")?r.resource:`${r.resource}/`)||n.recursive===!0&&r.resource.startsWith(n.resource.endsWith("/")?n.resource:`${n.resource}/`))))}i(Ce,"conflicts");function ve(t,e,r){if(e===void 0||!r&&e.some(o=>o.mode!=="read"))return!1;if(t===void 0)return!0;let n=new Map;for(let o of e){let s=o.group??o.resource;n.set(s,[...n.get(s)??[],o])}return[...n.values()].every(o=>o.some(s=>t.some(a=>(s.mode==="read"||a.mode==="write")&&(a.resource==="*"||s.resource===a.resource&&(s.recursive!==!0||a.recursive===!0)||a.recursive===!0&&s.resource.startsWith(a.resource.endsWith("/")?a.resource:`${a.resource}/`)))))}i(ve,"coveredAccess");async function Re(t,e){if(e===void 0)return await t;e.throwIfAborted();let r,n=new Promise((o,s)=>{r=i(()=>s(e.reason),"abort"),e.addEventListener("abort",r,{once:!0})});try{return await Promise.race([t,n])}finally{e.removeEventListener("abort",r)}}i(Re,"waitForDependencies");var _=class t{constructor(e=re()){this.state=e}static{i(this,"ResourceScheduler")}run(e,r,n,o={}){let s=Promise.resolve(e),a=this.state.active.getStore();if(a?.open){let E=s.then(h=>{if(n?.throwIfAborted(),!ve(a.accesses,h,a.allowNestedWrites))throw Object.assign(new Error("Nested resource access must be covered by its parent reservation and permitted by its owner."),{code:"UNDECLARED_RESOURCE_ACCESS"});return h});a.nested??=new t;let g=a.nested.run(E,r,n,{allowNestedWrites:a.allowNestedWrites});return a.children.add(g),g.then(()=>a.children.delete(g),()=>a.children.delete(g)),g}let d=[...this.state.pending],p=s.catch(()=>{}),y,l=new Promise(E=>{y=E}),S={accesses:p,done:l};return this.state.pending.add(S),(async()=>{try{n?.throwIfAborted();let E=await Re(s.then(async h=>(await Promise.all(d.map(F=>Promise.race([F.done,F.accesses.then(me=>Ce(h,me)?F.done:void 0)]))),h)),n);n?.throwIfAborted();let g={accesses:E,children:new Set,open:!0,allowNestedWrites:o.allowNestedWrites===!0};try{return await this.state.active.run(g,r)}finally{for(;g.children.size>0;)await Promise.allSettled([...g.children]);g.open=!1}}finally{this.state.pending.delete(S),y()}})()}},he=Symbol.for("pi-agent-resource.resource-scheduler-state"),we=globalThis,Te=we[he]??=re(),Se=new _(Te);import{realpath as Ee,stat as be}from"node:fs/promises";import N from"node:path";import{fileURLToPath as xe}from"node:url";async function ne(t,e,r){if(/^[a-z][a-z\d+.-]*:/iu.test(t)&&!/^[a-z]:[\\/]/iu.test(t)&&!t.startsWith("file:"))return[{resource:t,mode:r}];let n=N.resolve(e,t.startsWith("file:")?xe(t):t),[o,s]=await Promise.allSettled([Ee(n),be(n,{bigint:!0})]),a;if(o.status==="fulfilled")a=o.value;else{let l=o.reason;if(!(l instanceof Error)||!("code"in l)||l.code!=="ENOENT")throw l;let S=N.dirname(n);if(S===n)a=n;else{let g=(await ne(S,e,r)).find(h=>h.resource.startsWith("file:"));a=N.join(g?.resource.slice(5)??S,N.basename(n))}}let d=a.split(N.sep).join("/"),p=`file:${process.platform==="win32"?d.toLowerCase():d}`,y=[{resource:p,group:p,mode:r}];if(s.status==="fulfilled"){let l=s.value;l.isDirectory()&&(y[0]={resource:p,group:p,mode:r,recursive:!0}),l.ino!==0n&&y.push({resource:`inode:${l.dev}:${l.ino}`,group:p,mode:r,recursive:l.isDirectory()})}else{let l=s.reason;if(!(l instanceof Error)||!("code"in l)||l.code!=="ENOENT")throw l}return y}i(ne,"resourceAccesses");import{Type as f}from"typebox";import{Value as Ae}from"typebox/value";var M=f.Object({code:f.String(),message:f.String(),source:f.Optional(f.String())},{additionalProperties:!1});function oe(t){return f.Union([f.Object({status:f.Literal("success"),data:t,errors:f.Array(M,{maxItems:0})},{additionalProperties:!1}),f.Object({status:f.Union([f.Literal("error"),f.Literal("partial")]),data:f.Optional(t),errors:f.Array(M,{minItems:1})},{additionalProperties:!1})])}i(oe,"structuredResultSchema");var se=1024*1024;function q(t){let e=new Set,r=i(n=>{if(!(n===null||typeof n=="string"||typeof n=="boolean")&&!(typeof n=="number"&&Number.isFinite(n))){if(typeof n!="object"||e.has(n))throw new TypeError("Structured data must be finite, acyclic JSON");if(!Array.isArray(n)&&Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null)throw new TypeError("Structured data must not contain classes or raw byte buffers");e.add(n);for(let o of Array.isArray(n)?n:Object.values(n))r(o);e.delete(n)}},"visit");if(r(t),Buffer.byteLength(JSON.stringify(t))>se)throw new RangeError("Structured data exceeds 1 MiB; return a smaller window or a full-result reference")}i(q,"assertJsonData");function ie(t,e="EXECUTION_FAILED",r){return{code:typeof t=="object"&&t!==null&&"code"in t&&typeof t.code=="string"?t.code:e,message:t instanceof Error?t.message:String(t),...r===void 0?{}:{source:r}}}i(ie,"resultError");function Oe(t,e,r){try{if(q(r),!Ae.Check(oe(e),r))throw new TypeError("Result adapter returned data outside its public schema");return{...t,structuredContent:r,isError:r.status!=="success"}}catch(n){let o=ie(n,"INVALID_STRUCTURED_RESULT"),s={status:"error",errors:[o]};return q(s),{...t,content:[...t.content,{type:"text",text:o.message}],structuredContent:s,isError:!0}}}i(Oe,"withStructuredResult");function Ne(t,e){if(e.length===0)return;let r=t.trim();if(r.length===0||/[\r\n]/u.test(r))throw new TypeError("Content provider summary must be one non-empty line");return[r,...e.map(({description:n})=>n)].join(`
|
|
2
|
+
`)}i(Ne,"renderContentDescription");import{Type as u}from"typebox";import{Value as Ve}from"typebox/value";import{Type as c}from"typebox";import{Value as ke}from"typebox/value";var m={additionalProperties:!0},k=c.Function([],c.Unknown()),C=c.String({minLength:1}),Pe=c.Object({type:c.Literal("text"),text:c.String(),textSignature:c.Optional(c.String())},m),je=c.Object({type:c.Literal("image"),data:c.String(),mimeType:c.String()},m),Ie=c.Object({type:c.Literal("custom"),kind:C,data:c.Unknown()},m),_e=c.Array(c.Union([Pe,je,Ie]),{minItems:1}),ae=c.Union([c.Object({source:C,link:c.Optional(C),read:k,write:c.Optional(c.Never())},m),c.Object({source:C,link:c.Optional(C),read:c.Optional(c.Never()),write:k},m),c.Object({source:C,link:c.Optional(C),read:k,write:k},m)]),Ue=c.Object({id:C,tryResolve:k},m),De=c.Union([c.Object({kind:c.Literal("not-handled")},m),c.Object({kind:c.Literal("resolved"),resource:ae},m),c.Object({kind:c.Literal("failed"),error:c.Unknown()},m)]);function z(t){return U(_e,t)?D(()=>t.every(e=>e.type!=="text"||!("textSignature"in e)||typeof e.textSignature=="string")):!1}i(z,"isAgentContent");function ce(t){return U(ae,t)?D(()=>{let e=t,r=!("read"in e)||typeof e.read=="function",n=!("write"in e)||typeof e.write=="function";return r&&n}):!1}i(ce,"isResource");function Le(t){return U(Ue,t)}i(Le,"isResourceResolver");function $e(t){return U(De,t)?D(()=>{let e=t;return e.kind!=="resolved"||ce(e.resource)}):!1}i($e,"isResourceResolutionAttempt");function U(t,e){return D(()=>ke.Check(t,e))}i(U,"safeCheck");function D(t){try{return t()}catch{return!1}}i(D,"safeEvaluate");var v={additionalProperties:!0},We=u.Function([],u.Unknown()),L=u.String({minLength:1}),He=u.Object({provider:L,capability:u.Union([u.Literal("read"),u.Literal("write")])},v),Ke=u.Object({source:L,bytes:u.Unknown(),mediaType:u.Optional(u.String())},v),Fe=u.Object({signal:u.Optional(u.Unknown())},v),Me=u.Object({id:L,description:L,tryConvert:We},v),qe=u.Union([u.Object({kind:u.Literal("not-handled")},v),u.Object({kind:u.Literal("converted"),content:u.Unknown()},v),u.Object({kind:u.Literal("failed"),error:u.Unknown()},v)]),ze=u.Object({target:u.Unknown(),converter:u.Unknown(),priority:u.Optional(u.Number())},v);function b(t){return x(He,t)&&T(()=>t.provider.trim().length>0)}i(b,"isContentTarget");function B(t){return x(Ke,t)?T(()=>{let e=t;return e.bytes instanceof Uint8Array&&(!("mediaType"in e)||typeof e.mediaType=="string")}):!1}i(B,"isContentInput");function J(t){return x(Fe,t)?T(()=>{let e=t;return!("signal"in e)||e.signal instanceof AbortSignal}):!1}i(J,"isContentConversionContext");function ue(t){return x(Me,t)?T(()=>{let e=t;return e.id.trim().length>0&&e.description.trim().length>0&&!/[\r\n]/u.test(e.description)}):!1}i(ue,"isContentConverter");function Y(t){return x(qe,t)?T(()=>{let e=t;return e.kind!=="converted"||z(e.content)}):!1}i(Y,"isContentConversionAttempt");function w(t){return x(ze,t)?T(()=>{let e=t;return b(e.target)&&ue(e.converter)&&(!("priority"in e)||typeof e.priority=="number"&&Number.isFinite(e.priority))}):!1}i(w,"isContentConverterRegistration");function x(t,e){return T(()=>Ve.Check(t,e))}i(x,"safeCheck");function T(t){try{return t()}catch{return!1}}i(T,"safeEvaluate");var $=class extends Error{static{i(this,"UnsupportedContentError")}source;target;constructor(e,r){super(`No content converter for ${e} in ${r.provider}/${r.capability}`),this.name="UnsupportedContentError",this.source=e,this.target=r}};function X(t){if(!b(t))throw new TypeError("Invalid content target");let e={...t},r=[],n=i(()=>[...r].sort((o,s)=>o.priority-s.priority||o.order-s.order),"snapshotConverters");return{target:e,register(o){if(!w(o))throw new TypeError("Invalid content converter registration");if(!A(e,o.target))throw new Error(`Content converter ${o.converter.id} targets ${o.target.provider}/${o.target.capability}, not ${e.provider}/${e.capability}`);if(r.some(({converter:s})=>s.id===o.converter.id))throw new Error(`Content converter ${o.converter.id} is already registered for ${e.provider}/${e.capability}`);r.push({converter:o.converter,priority:o.priority??0,order:r.length})},listDescriptions(){return n().map(({converter:o})=>({id:o.id,description:o.description}))},async convert(o,s){if(!B(o))throw new TypeError("Invalid content input");if(!J(s))throw new TypeError("Invalid content conversion context");G(s.signal);let a=n();for(let{converter:d}of a){G(s.signal);let p=await d.tryConvert(o,s);if(G(s.signal),!Y(p))throw new TypeError(`Content converter ${d.id} returned an invalid outcome`);if(p.kind!=="not-handled"){if(p.kind==="failed")throw p.error;return p.content}}throw new $(o.source,e)}}}i(X,"createContentRunner");function A(t,e){return t.provider===e.provider&&t.capability===e.capability}i(A,"targetsEqual");function G(t){t?.throwIfAborted()}i(G,"throwIfAborted");import{Type as R}from"typebox";import{Value as Be}from"typebox/value";var O="pi-agent-resource/content-conversion",V=2,P=`${O}/host/ready`,j=`${O}/converter/register`,de={additionalProperties:!0},Je=R.Function([],R.Unknown()),Ye=R.Object({protocol:R.Literal(O),apiVersion:R.Literal(V),target:R.Unknown()},de),Ge=R.Object({registration:R.Unknown(),accept:Je},de);function Q(t){return le(Ye,t)&&ee(()=>b(t.target))}i(Q,"isContentHostReady");function Z(t){return le(Ge,t)&&ee(()=>w(t.registration))}i(Z,"isContentConverterRegistrationRequest");function le(t,e){return ee(()=>Be.Check(t,e))}i(le,"safeCheck");function ee(t){try{return t()}catch{return!1}}i(ee,"safeEvaluate");function Xe(t,e){let r=X(e),n=t.events.on(j,o=>{if(!Z(o))throw new Error("Invalid content converter registration request");if(!A(r.target,o.registration.target))return;let s;try{r.register(o.registration),s=Promise.resolve()}catch(a){s=Promise.reject(a instanceof Error?a:new Error("Content converter registration failed",{cause:a}))}o.accept(s)});return t.on("session_shutdown",n),t.events.emit(P,{protocol:O,apiVersion:V,target:r.target}),{target:r.target,listDescriptions(){return r.listDescriptions()},convert(o,s){return r.convert(o,s)}}}i(Xe,"createContentHost");function Qe(t,e){if(!w(e))throw new TypeError("Invalid content converter registration");let r=i(()=>{let s,a={registration:e,accept(d){if(s!==void 0)throw new Error(`Content converter ${e.converter.id} registration was accepted more than once`);s=d}};return t.events.emit(j,a),s},"announce"),n=i(()=>{},"unsubscribe");n=t.events.on(P,s=>{if(!Q(s))throw new Error("Invalid content conversion host readiness event");if(!A(e.target,s.target))return;let a=r();if(a===void 0)throw new Error(`${s.target.provider}/${s.target.capability} announced readiness without accepting content converter ${e.converter.id}`);n(),a.catch(()=>{})}),t.on("session_shutdown",n);let o=r();if(o!==void 0)return n(),o}i(Qe,"connectContentConverter");import{randomUUID as pe}from"node:crypto";import{readFile as Ze}from"node:fs/promises";import W from"node:path";import{Type as I}from"typebox";var et=I.Union([I.String(),I.Object({},{additionalProperties:!0}),I.Array(I.Unknown())]),H="RESULT#",fe="pi-agent-resource:result-targets",K=class{static{i(this,"ResultTargetStore")}#e=new Map;clear(){this.#e.clear()}register(e,r,n=!0){let o=`${H}${pe()}`;return this.#e.set(o,{state:"ready",targets:te(e),complete:n,cwd:W.resolve(r)}),o}reserve(e){let r=`${H}${pe()}`;return this.#e.set(r,{state:"pending",cwd:W.resolve(e)}),r}confirm(e,r,n){let o=this.#e.get(e);if(o?.state!=="pending"||o.cwd!==W.resolve(n))throw new Error("Only a pending result in this worktree can be confirmed.");this.#e.set(e,{state:"ready",cwd:o.cwd,targets:te(r),complete:!0})}reject(e,r){let n=this.#e.get(e);n?.state==="pending"&&this.#e.set(e,{state:"rejected",cwd:n.cwd,reason:r})}resolve(e,r){let n=this.#t(e),o=[],s=!0;for(let a of n){let d=this.#e.get(a);if(d===void 0)throw new Error("Result target expired or unknown; repeat Read/Search.");if(d.cwd!==W.resolve(r))throw new Error("Result target belongs to another worktree.");if(d.state==="pending")throw new Error("Result target is pending; its write has not been confirmed.");if(d.state==="rejected")throw new Error(d.reason);s&&=d.complete,o.push(...d.targets)}return{targets:te(o),complete:s}}resolveOrdered(e,r){let n=this.resolve(e,r),o=[],s=new Set;for(let a of new Set(this.#t(e)))for(let d of this.resolve(a,r).targets)for(let p of d.ranges){let y=JSON.stringify([d.source,p]);s.has(y)||(s.add(y),o.push({...d,ranges:[p]}))}return{targets:o,complete:n.complete}}async verify(e,r){await ge(e,r)}#t(e){if(typeof e=="string"&&e.startsWith(H))return[e];if(Array.isArray(e))return e.flatMap(n=>this.#t(n));if(e===null||typeof e!="object")throw new Error("Unsupported result input.");let r=e;if("status"in r){if(r.status!=="success")throw new Error("Only successful source results can be consumed.");return this.#t(r.data)}if(typeof r.target=="string"&&r.target.startsWith(H))return[r.target];if(r.kind==="resources"&&Array.isArray(r.resources))return this.#t(r.resources);throw new Error("This result has no supported source target; do not use preview text as a source.")}};async function ge(t,e){let r=new Map;for(let n of t.targets){e?.throwIfAborted();let o=r.get(n.source);if(o===void 0&&(o=await Ze(n.source,{encoding:"utf8",signal:e}),r.set(n.source,o)),o!==n.expectedContent)throw new Error("Result target is stale; repeat Read/Search.")}}i(ge,"verifyResultTargets");function te(t){let e=new Map;for(let r of t){let n=e.get(r.source);if(n!==void 0&&n.expectedContent!==r.expectedContent)throw new Error("Result targets refer to different snapshots of the same source.");let o=n??{source:r.source,expectedContent:r.expectedContent,ranges:[],seen:new Set};for(let s of r.ranges){let a=JSON.stringify(s);o.seen.has(a)||(o.seen.add(a),o.ranges.push(structuredClone(s)))}e.set(r.source,o)}return[...e.values()].filter(r=>r.ranges.length>0).map(({seen:r,...n})=>({...n,ranges:n.ranges.sort((o,s)=>o.start.lineNumber-s.start.lineNumber||o.start.column-s.start.column||o.end.lineNumber-s.end.lineNumber||o.end.column-s.end.column)}))}i(te,"combineTargets");function tt(t){let e;if(t.events.emit(fe,{accept:i(o=>{e=o},"accept")}),e!==void 0)return e;let r=new K,n=t.events.on(fe,o=>{o!==null&&typeof o=="object"&&"accept"in o&&typeof o.accept=="function"&&o.accept(r)});return t.on("session_start",()=>{r.clear()}),t.on("session_shutdown",()=>{r.clear(),n()}),r}i(tt,"connectResultTargets");export{_ as a,Se as b,ne as c,M as d,oe as e,se as f,q as g,ie as h,Oe as i,Ne as j,z as k,ce as l,Le as m,$e as n,b as o,B as p,J as q,ue as r,Y as s,w as t,$ as u,X as v,A as w,O as x,V as y,P as z,j as A,Q as B,Z as C,Xe as D,Qe as E,et as F,K as G,ge as H,tt as I};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as A,e as R,f as w,h as g,i as U}from"./chunk-SQKAXYIR.js";import{a as y}from"./chunk-EI7MMDWY.js";import{Type as e}from"typebox";import{Value as D}from"typebox/value";var k=e.Union([e.Literal("pending"),e.Literal("applied"),e.Literal("not-applied"),e.Literal("unknown")]),F=e.Object({source:e.String(),effect:k,action:e.Optional(e.String()),state:e.Optional(e.Union([e.Literal("present"),e.Literal("absent"),e.Literal("unknown")]))},{additionalProperties:!1}),j=e.Object({id:e.String(),operation:e.String(),effect:k,errors:e.Array(A),status:e.Optional(e.Union([e.Literal("success"),e.Literal("error"),e.Literal("warning"),e.Literal("unknown")])),sources:e.Optional(e.Array(e.String())),warnings:e.Optional(e.Array(A))},{additionalProperties:!1}),I=e.Object({operation:e.String(),effect:k,operationId:e.Optional(e.String()),target:e.Optional(e.String({description:"Backend-owned resulting-text scope: replace/insert text, write's whole file, copy/move destinations, or undo's whole restored files. Delete never supplies a live target. Pending handles require a confirmed commit."})),targetUnavailable:e.Optional(e.String({description:"Why a completed mutation could not provide a safe resulting-text target. The write effect is reported separately."})),files:e.Array(F),changes:e.Optional(e.Array(e.Object({source:e.String(),from:e.Integer({description:"Inclusive zero-based UTF-16 offset in the pre-edit snapshot; not a live selector."}),to:e.Integer({description:"Exclusive zero-based UTF-16 offset in the pre-edit snapshot; not a live selector."}),removedText:e.String(),insertedText:e.String()},{additionalProperties:!1}))),changesUnavailable:e.Optional(e.String({description:"Why the exact change record is omitted; applied effects remain reported."})),operations:e.Optional(e.Array(j)),parentToolCallId:e.Optional(e.String()),recovery:e.Optional(e.Array(e.Object({source:e.String(),field:e.String(),anchor:e.String(),total:e.Integer(),candidates:e.Array(e.Object({rank:e.Integer(),range:e.Object({start:e.Object({lineNumber:e.Integer(),column:e.Integer()}),end:e.Object({lineNumber:e.Integer(),column:e.Integer()})})}))}))),action:e.Optional(e.Object({source:e.String(),kind:e.Optional(e.String()),status:e.Optional(e.String()),command:e.Optional(e.String()),deleted:e.Optional(e.Boolean()),session:e.Optional(e.String()),file:e.Optional(e.String()),line:e.Optional(e.Integer()),verified:e.Optional(e.Boolean()),evaluation:e.Optional(e.Object({expression:e.String(),result:e.String(),type:e.Optional(e.String()),variablesReference:e.Integer()},{additionalProperties:!1})),breakpoints:e.Optional(e.Array(e.Object({source:e.String(),file:e.String(),line:e.Integer(),verified:e.Boolean()},{additionalProperties:!1})))},{additionalProperties:!1}))},{additionalProperties:!1}),P=R(I);function s(l){return typeof l=="object"&&l!==null}y(s,"record");function N(l,p,S=[]){let o=l.details,d=s(o)?o:{},O=s(o)&&s(o.nativeEditBatch)?o.nativeEditBatch:void 0;if(O?.state==="accepted")return{status:"success",errors:[],data:{operation:p,effect:"pending",...typeof o.metadata?.resultTarget=="string"?{target:o.metadata.resultTarget}:{},files:typeof d.source=="string"?[{source:d.source,effect:"pending"}]:[],...typeof O.parentToolCallId=="string"?{parentToolCallId:O.parentToolCallId}:{}}};let m=new Set(S.map(r=>r.resourceSource)),a=[],u=[],v=o.results;for(let r of v??[]){let n=r.data,c=[...new Set([...(n.files??[]).map(i=>i.path),...n.path?[n.path]:[]])];for(let i of c)u.push({source:i,...m.has(i)?{state:"present"}:{},effect:m.has(i)||n.ok===!0&&n.files?.some(M=>M.path===i)?"applied":o.effect??"unknown"});for(let i of n.errors??[])a.push({code:i.code??"MUTATION_FAILED",message:i.reason??"Mutation failed",source:i.path});n.ok===!1&&(n.errors?.length??0)===0&&a.push({code:"MUTATION_FAILED",message:"Mutation failed",...n.path?{source:n.path}:{}})}for(let r of m)u.some(n=>n.source===r)||u.push({source:r,effect:"applied",state:"present"});let t=s(o.metadata)&&s(o.metadata.semanticAction)?o.metadata.semanticAction:void 0;if(t){let r=t.effect==="not-applied"||t.effect==="unknown"?t.effect:t.ok===!1?"unknown":"applied",n=typeof t.source=="string"?t.source:void 0;n&&u.push({source:n,...t.kind==="file-operation"&&t.ok===!0?{state:p==="delete"||p==="move"?"absent":"present"}:{},effect:p==="copy"&&typeof t.target=="string"&&t.target!==n?"not-applied":r}),typeof t.target=="string"&&u.push({source:t.target,effect:r,...t.kind==="file-operation"&&t.ok===!0?{state:"present"}:{}}),s(t.error)&&a.push(g(t.error.message,typeof t.error.code=="string"?t.error.code:"MUTATION_FAILED",n)),typeof t.postProcessingError=="string"&&a.push(g(t.postProcessingError,"POST_EDIT_FAILED",n)),t.ok===!1&&a.length===0&&a.push(g("Resource operation failed","MUTATION_FAILED",n))}let f=[...new Map(u.map(r=>[r.source,r])).values()];if(Array.isArray(o.metadata?.resultFileStates))for(let r of o.metadata.resultFileStates){if(!s(r))continue;let n=f.find(c=>c.source===r.source);n&&(r.state==="present"||r.state==="absent")&&(n.state=r.state)}let T=(v??[]).filter(r=>r.data.ok).flatMap(r=>{let n=r.data.path;return n===void 0?[]:(r.data.rawChanges??[]).map(c=>({source:n,from:c.fromA,to:c.toA,removedText:c.removedText,insertedText:c.insertedText}))}),x=Buffer.byteLength(JSON.stringify(T))<=w/2,E=f.some(r=>r.effect==="applied");l.isError&&a.length===0&&a.push({code:"MUTATION_FAILED",message:"Mutation failed"}),(v?.length??0)===0&&!t&&m.size===0&&a.length===0&&o.effect!=="not-applied"&&a.push({code:"UNKNOWN_RESULT",message:"Mutation effects were not reported"});let L=f.some(r=>r.effect==="unknown")||a.some(r=>r.code==="UNKNOWN_RESULT")?"unknown":E?"applied":"not-applied",h=t&&typeof t.source=="string"?{source:t.source,...typeof t.kind=="string"?{kind:t.kind}:{},...typeof t.status=="string"?{status:t.status}:{},...typeof t.command=="string"?{command:t.command}:{},...typeof t.deleted=="boolean"?{deleted:t.deleted}:{},...typeof t.session=="string"?{session:t.session}:{},...typeof t.file=="string"?{file:t.file}:{},...typeof t.line=="number"?{line:t.line}:{},...typeof t.verified=="boolean"?{verified:t.verified}:{},...s(t.evaluation)?{evaluation:{expression:t.evaluation.expression,result:t.evaluation.result,variablesReference:t.evaluation.variablesReference,...typeof t.evaluation.type=="string"?{type:t.evaluation.type}:{}}}:{},...Array.isArray(t.breakpoints)?{breakpoints:t.breakpoints.filter(s).map(r=>({source:r.source,file:r.file,line:r.line,verified:r.verified}))}:{}}:void 0,b=h&&D.Check(I.properties.action,h)?h:void 0;return h&&!b&&a.push(g("Action adapter returned invalid fields","INVALID_STRUCTURED_RESULT")),{status:a.length===0?"success":!t&&E&&f.some(r=>r.effect!=="applied")?"partial":"error",data:{operation:p,effect:L,files:f,...T.length===0?{}:x?{changes:T}:{changesUnavailable:"Exact change record exceeds the 512 KiB receipt budget; it was not clipped."},...typeof o.metadata?.resultTarget=="string"?{target:o.metadata.resultTarget}:{},...typeof o.metadata?.targetUnavailable=="string"?{targetUnavailable:o.metadata.targetUnavailable}:{},...o.anchorRecoveries===void 0?{}:{recovery:o.anchorRecoveries.map(r=>({source:r.path,field:r.field,anchor:r.anchor,total:r.total,candidates:[...r.candidates]}))},...b?{action:b}:{}},errors:a}}y(N,"mutationOutcome");function W(l,p,S=[],o){let d=N(l,p,S);return d.data&&o!==void 0&&(d.data.operationId=o),U(l,I,d)}y(W,"structuredMutation");export{I as a,P as b,N as c,W as d};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{b as C}from"./chunk-EAZGN5ND.js";import{a as b}from"./chunk-ZC65Z3CK.js";import{a as m}from"./chunk-EI7MMDWY.js";import{diffChars as j}from"diff";import{DefaultLinesDiffComputer as J}from"vscode-diff";var N=2,P=.5,S=100,Q=16e3,H=1e6,Z=new J,ee=new Set(["async","boolean","const","export","false","function","interface","let","new","null","number","private","protected","public","readonly","return","static","string","true","type","undefined","var"]);function E(e,n,t=[],r={}){let o=ne(e,n,(r.beforeLineOffset??0)+1,(r.afterLineOffset??0)+1);if(o===void 0)return{rows:[],added:0,modified:0,removed:0,focusRow:0,omittedChanges:{outside:0,ambiguous:0,unavailable:!0}};let i=r.project===!1?o:oe(o),f=r.focusAfterLine??(t.length===0?void 0:fe(n,b(t.at(-1)).to)+(r.afterLineOffset??0));return{rows:i,added:o.filter(({kind:d})=>d==="added").length,modified:o.filter(({kind:d})=>d==="modified").length,removed:o.filter(({kind:d})=>d==="removed").length,focusRow:se(i,f)}}m(E,"createDiffModel");function ne(e,n,t=1,r=1){if(e.length+n.length>H)return;let o=performance.now()+S,i=W(e),f=W(n),d=[];if(i.length===0||f.length===0)return[...i.map((u,y)=>({kind:"removed",text:u,beforeLine:t+y,changed:!0})),...f.map((u,y)=>({kind:"added",text:u,afterLine:r+y,changed:!0}))];let a=new Set(i.map(u=>u.trim())),c=f.some(u=>a.has(u.trim()))?Z.computeDiff([...i],[...f],{ignoreTrimWhitespace:!0,computeMoves:!1,maxComputationTimeMs:S}):{hitTimeout:!1,changes:[{original:{startLineNumber:1,endLineNumberExclusive:i.length+1},modified:{startLineNumber:1,endLineNumberExclusive:f.length+1}}]};if(c.hitTimeout||performance.now()>=o)return;let g=0,s=0,h=m(u=>{for(;s<u;)d.push({kind:"context",text:b(f[s]),beforeLine:t+g++,afterLine:r+s++,changed:!1})},"appendContext");for(let u of c.changes){h(u.modified.startLineNumber-1);let y=i.slice(u.original.startLineNumber-1,u.original.endLineNumberExclusive-1).map((x,R)=>({text:x,line:t+g+R})),w=f.slice(u.modified.startLineNumber-1,u.modified.endLineNumberExclusive-1).map((x,R)=>({text:x,line:r+s+R})),D=te(y,w,o);d.push(...D??[...y.map(({text:x,line:R})=>({kind:"removed",text:x,beforeLine:R,changed:!0})),...w.map(({text:x,line:R})=>({kind:"added",text:x,afterLine:R,changed:!0}))]),g+=y.length,s+=w.length}if(h(f.length),e.endsWith(`
|
|
2
|
+
`)!==n.endsWith(`
|
|
3
|
+
`)){let u=d.at(-1);u?.kind==="context"&&(d[d.length-1]={...u,kind:"modified",changed:!0,addedRanges:[],deletedOffsets:e.endsWith(`
|
|
4
|
+
`)?[u.text.length]:[]})}return d}m(ne,"createSemanticRows");function T(e,n,t){let r=e[n]?.[t];if(r===void 0)throw new RangeError(`Score [${n}, ${t}] is outside the alignment matrix.`);return r}m(T,"scoreAt");function te(e,n,t){let r=new Map,o=m((c,g)=>{if(performance.now()>=t)return;let s=r.get(c)?.get(g);if(s!==void 0)return s;let h=ie(c,g,t);if(h!==void 0){let u=r.get(c);u===void 0&&(u=new Map,r.set(c,u)),u.set(g,h)}return h},"compareCharacters");if(e.length>1&&e.length===n.length){let c=[];for(let[g,s]of e.entries()){let h=b(n[g]),u=z(s.text,h.text,o);if(u===void 0)return;if(u<P)break;let y=_(s,h,t);if(y===void 0)return;c.push(y)}if(c.length===e.length)return c}if(e.length===1&&n.length===1){let c=_(b(e[0]),b(n[0]),t);return c===void 0?void 0:[c]}if(e.length*n.length>Q)return;let i=Array.from({length:e.length},()=>Array(n.length).fill(0)),f=Array.from({length:e.length+1},()=>Array.from({length:n.length+1}).fill(0));for(let c=1;c<=e.length;c++)for(let g=1;g<=n.length;g++){let s=z(b(e[c-1]).text,b(n[g-1]).text,o);if(s===void 0)return;b(i[c-1])[g-1]=s;let h=s>=P?T(f,c-1,g-1)+s:Number.NEGATIVE_INFINITY;b(f[c])[g]=Math.max(T(f,c-1,g),T(f,c,g-1),h)}let d=[],a=e.length,l=n.length;for(;a>0||l>0;){let c=a>0&&l>0?T(i,a-1,l-1):0;if((a>0&&l>0&&c>=P?T(f,a-1,l-1)+c:Number.NEGATIVE_INFINITY)===T(f,a,l)){let s=_(b(e[a-1]),b(n[l-1]),t);if(s===void 0)return;d.push(s),a--,l--}else if(l>0&&T(f,a,l-1)>=(a>0?T(f,a-1,l):Number.NEGATIVE_INFINITY)){let s=b(n[l-1]);d.push({kind:"added",text:s.text,afterLine:s.line,changed:!0}),l--}else{let s=b(e[a-1]);d.push({kind:"removed",text:s.text,beforeLine:s.line,changed:!0}),a--}}return d.reverse()}m(te,"alignChangedLines");function _(e,n,t){let r=re(e.text,n.text,t);if(r!==void 0)return{kind:"modified",text:n.text,beforeLine:e.line,afterLine:n.line,changed:!0,...r}}m(_,"modifiedRow");function re(e,n,t=performance.now()+S){let r=t-performance.now();if(r<=0||e.length+n.length>H)return;let o=j(e.trim(),n.trim(),{timeout:r,maxEditLength:5e3});if(o===void 0)return;let i=[],f=[],d=n.length-n.trimStart().length;for(let a=0;a<o.length;a++){let l=b(o[a]);l.removed?o[a+1]?.added||f.push(d):(l.added&&i.push({from:d,to:d+l.value.length}),d+=l.value.length)}return{addedRanges:i,deletedOffsets:f}}m(re,"compareInlineText");function z(e,n,t){let r=t(e,n);if(r===void 0)return;let o=V(e),i=V(n);if(o.length===0&&i.length===0)return r;let f=B(o,i,t),d=B(i,o,t);if(f===void 0||d===void 0)return;let a=(f+d)/2;return r*.35+a*.65}m(z,"lineSimilarity");function V(e){return(e.toLowerCase().match(/[\p{L}\p{N}_$]+/gu)??[]).filter(n=>!ee.has(n))}m(V,"semanticTokens");function B(e,n,t){if(e.length===0||n.length===0)return 0;let r=0;for(let o of e){let i=0;for(let f of n){let d=t(o,f);if(d===void 0)return;i=Math.max(i,d)}r+=i}return r/e.length}m(B,"directionalTokenSimilarity");function ie(e,n,t){if(t-performance.now()<=0)return;let o=Math.max(e.length,n.length);if(o===0||e===n)return 1;let i=Array.from(e),f=Array.from(n),d=0,a=0;for(;d<i.length&&d<f.length&&i[d]===f[d];)a+=b(i[d]).length,d++;let l=i.length,c=f.length;for(;l>d&&c>d&&i[l-1]===f[c-1];)a+=b(i[--l]).length,c--;let g=i.slice(d,l),s=f.slice(d,c);if(s.length>g.length&&([g,s]=[s,g]),s.length<=31&&g.every(y=>y.length===1)){let y=new Map;for(let[x,R]of s.entries())y.set(R,(y.get(R)??0)|1<<x);let w=0;for(let x of g){let R=(y.get(x)??0)|w;w=R&~(R-(w<<1|1))}let D=a;for(;w!==0;)w&=w-1,D++;return D/o}let h=j(e,n,{timeout:t-performance.now(),maxEditLength:2e3});return h===void 0?void 0:h.filter(y=>!y.added&&!y.removed).reduce((y,w)=>y+w.value.length,0)/o}m(ie,"characterSimilarity");function oe(e){let n=[];for(let t=0;t<e.length;t++){if(!b(e[t]).changed)continue;let r=t;for(;t+1<e.length&&b(e[t+1]).changed;)t++;let o={start:Math.max(0,r-N),end:Math.min(e.length-1,t+N)},i=n.at(-1);i!==void 0&&o.start<=i.end+1?n[n.length-1]={start:i.start,end:Math.max(i.end,o.end)}:n.push(o)}return n.flatMap((t,r)=>{let o=n[r-1];return[...o===void 0?[]:[de(t.start-o.end-1)],...e.slice(t.start,t.end+1)]})}m(oe,"projectHunks");function de(e){return{kind:"omitted",text:"",changed:!1,omitted:e}}m(de,"omittedRow");function W(e){if(e.length===0)return[];let n=e.replaceAll(`\r
|
|
5
|
+
`,`
|
|
6
|
+
`),t=n.split(`
|
|
7
|
+
`);return n.endsWith(`
|
|
8
|
+
`)&&t.pop(),t}m(W,"splitPart");function fe(e,n){let t=1;for(let r=0;r<Math.min(n,e.length);r++)e[r]===`
|
|
9
|
+
`&&t++;return t}m(fe,"lineAtOffset");function se(e,n){if(n!==void 0){let t=e.findLastIndex(r=>r.afterLine!==void 0&&r.afterLine<=n&&r.changed);if(t!==-1)return t}return Math.max(0,e.findLastIndex(t=>t.changed))}m(se,"findFocusRow");function G(e){return{resources:e.flatMap(n=>{let t=n.model??E(n.beforeContent,n.afterContent,n.ranges),r=ae(t,n),o=t.rows[t.focusRow]?.afterLine;return r.length===0?[]:[{path:n.path,windows:r,...o!==void 0&&{focusAfterLine:o}}]})}}m(G,"freezeMutationViewports");function $(e,n){return e.map(t=>{let r=n?.resources.find(o=>ce(o.path,t.path));return r===void 0?{...t,model:E(t.beforeContent,t.afterContent,t.ranges)}:{...t,model:ue(t.beforeContent,t.afterContent,r,t.diffPeerRanges,t.finalLineOwnership)}})}m($,"projectFinalResources");function ae(e,n){let t=[],r=[],o=m(()=>{if(r.length===0)return;let i=r.flatMap(u=>u.beforeLine===void 0?[]:[u.beforeLine]),f=F(n.beforeContent,n.beforeRanges?.at(-1)),d=i.length===0?f-1:Math.min(...i)-1,a=i.length===0?d:Math.max(...i),l=r.flatMap(u=>u.changed&&u.beforeLine!==void 0?[u.beforeLine]:[]),c=r.findIndex(u=>u.changed),g=r.slice(0,c).findLast(u=>u.beforeLine!==void 0)?.beforeLine,s=r.slice(c+1).find(u=>u.beforeLine!==void 0)?.beforeLine,h=g??(s===void 0?f-1:s-1);t.push({beforeStart:d,beforeEnd:a,seedStart:l.length===0?h:Math.min(...l)-1,seedEnd:l.length===0?h:Math.max(...l)}),r=[]},"flush");for(let i of e.rows)i.kind==="omitted"?o():r.push(i);return o(),t}m(ae,"freezeWindows");function ue(e,n,t,r=[],o){let i=E(e,n,[],{project:!1});if(i.rows.length===0&&e!==n)return{...i,omittedChanges:{outside:0,ambiguous:0,unavailable:!0}};let f=new Set,d=0,a=0,l=0;for(let s=0;s<i.rows.length;){let h=b(i.rows[s]);if(!h.changed){l=h.beforeLine??l,s++;continue}let u=s,y=l,w=[];for(;s<i.rows.length&&b(i.rows[s]).changed;){let p=b(i.rows[s]).beforeLine;p!==void 0&&(w.push(p),l=p),s++}let D=w.length===0?y:Math.min(...w)-1,x=w.length===0?y:Math.max(...w),R=t.windows.filter(p=>v(D,x,p.seedStart,p.seedEnd));if(r.some(p=>{let M=F(e,p)-1,A=F(e,{from:Math.max(p.from,p.to-1),to:p.to});return v(D,x,M,p.from===p.to?M:A)})){if(R.length>0)for(let p=u;p<s;p++){let M=b(i.rows[p]).beforeLine,A=b(i.rows[p]).afterLine;if(M===void 0&&A!==void 0&&o!==void 0){let L=o.own.includes(A),I=o.peers.includes(A);L&&!I?f.add(p):(L||!I)&&a++;continue}let k=M!==void 0&&R.some(L=>v(M-1,M,L.seedStart,L.seedEnd)),O=M!==void 0&&r.some(L=>{let I=F(e,L)-1,U=F(e,{from:Math.max(L.from,L.to-1),to:L.to});return v(M-1,M,I,U)});k&&!O?f.add(p):(!O||k)&&a++}continue}if(R.length===0){d+=s-u;continue}if(!R.some(p=>D>=p.beforeStart&&x<=p.beforeEnd)){a+=s-u;continue}for(let p=u;p<s;p++)f.add(p)}for(let s of[...f])for(let h=Math.max(0,s-N);h<Math.min(i.rows.length,s+N+1);h++)b(i.rows[h]).changed||f.add(h);let c=[],g=-1;for(let s of[...f].sort((h,u)=>h-u))g!==-1&&s>g+1&&c.push({kind:"omitted",text:"",changed:!1,omitted:s-g-1}),c.push(b(i.rows[s])),g=s;return{rows:c,added:c.filter(({kind:s})=>s==="added").length,modified:c.filter(({kind:s})=>s==="modified").length,removed:c.filter(({kind:s})=>s==="removed").length,focusRow:le(c,t.focusAfterLine),...d+a>0&&{omittedChanges:{outside:d,ambiguous:a}}}}m(ue,"createFrozenModel");function v(e,n,t,r){return e===n?e>=t&&e<=r:t===r?t>=e&&t<=n:e<r&&n>t}m(v,"overlaps");function F(e,n){let t=n?.from??0;return e.slice(0,t).split(`
|
|
10
|
+
`).length}m(F,"lineAtRange");function le(e,n){if(n!==void 0){let t=e.findLastIndex(r=>r.afterLine!==void 0&&r.afterLine<=n);if(t!==-1)return t}return Math.max(0,e.findLastIndex(({changed:t})=>t))}m(le,"focusRowAt");function ce(e,n){return e===n||e.endsWith(`/${n}`)||n.endsWith(`/${e}`)}m(ce,"samePath");function X(e,n,t=!0){let r=e?.mutationRender;if(r!==void 0)return r.map(({path:d,model:a,diffStatuses:l})=>({path:d,model:a,...l===void 0?{}:{diffStatuses:l},ranges:[],beforeContent:"",afterContent:""}));let o=(e?.results??[]).map(d=>C.ensure(d)),i=o.flatMap(me);if(!t)return i;let f=n??he(o);return $(i,f)}m(X,"resolveMutationResultResources");function me(e){let n=e.afterContent,t=Y(e.data.rawChanges);return!e.ok||typeof n!="string"?[]:K(e).flatMap(r=>{let o=e.beforeContentMap?.[r];if(typeof o!="string"&&o!==null)return[];let i=t===void 0?void 0:q(o??"",t),f=ge(o??"",n,t,e.data.diffPeerRanges),d=i===n?{beforeRanges:t?.map(({fromA:a,toA:l})=>({from:a,to:l}))??[],ranges:t?.map(({fromB:a,toB:l})=>({from:a,to:l}))??[]}:void 0;return[{path:r,ranges:[],beforeContent:o??"",...d===void 0?{}:{typingIdentity:d},...f===void 0?{}:{finalLineOwnership:f},...e.data.diffPeerRanges===void 0?{}:{diffPeerRanges:e.data.diffPeerRanges},...e.data.diffStatuses===void 0?{}:{diffStatuses:e.data.diffStatuses},afterContent:n}]})}m(me,"finalResource");function ge(e,n,t,r){if(t===void 0||r===void 0)return;let o=[...t.map(({fromA:a,toA:l,insertedText:c})=>({from:a,to:l,insert:c,own:!0})),...r.map(a=>({...a,own:!1}))].sort((a,l)=>a.from-l.from),i={own:new Set,peers:new Set},f="",d=0;for(let a of o){if(a.from<d||a.to<a.from||a.to>e.length)return;f+=e.slice(d,a.from);let l=f.split(`
|
|
11
|
+
`).length;if(f+=a.insert,a.insert.length>0){let c=f.slice(0,-1).split(`
|
|
12
|
+
`).length;for(let g=l;g<=c;g++)i[a.own?"own":"peers"].add(g)}d=a.to}if(f+e.slice(d)===n)return{own:[...i.own],peers:[...i.peers]}}m(ge,"unchangedBatchOwnership");function he(e){let n=e.flatMap(pe);return n.length===0?void 0:G(n)}m(he,"persistedViewports");function pe(e){if(!e.ok)return[];let n=Y(e.data.rawChanges);return n===void 0||n.length===0?[]:K(e).flatMap(t=>{let r=e.beforeContentMap?.[t];if(typeof r!="string"&&r!==null)return[];let o=r??"",i=q(o,n);return i===void 0?[]:[{path:t,beforeContent:o,afterContent:i,beforeRanges:n.map(({fromA:f,toA:d})=>({from:f,to:d})),ranges:n.map(({fromB:f,toB:d})=>({from:f,to:d}))}]})}m(pe,"generatedResource");function K(e){return e.files.length>0?e.files.map(({path:n})=>n):e.path===void 0?[]:[e.path]}m(K,"resultPaths");function Y(e){if(!(!Array.isArray(e)||!e.every(be)))return[...e].sort((n,t)=>n.fromA-t.fromA)}m(Y,"persistedChanges");function be(e){if(typeof e!="object"||e===null)return!1;let n=e;return Number.isInteger(n.fromA)&&Number.isInteger(n.toA)&&Number.isInteger(n.fromB)&&Number.isInteger(n.toB)&&typeof n.insertedText=="string"}m(be,"isPersistedTextChange");function q(e,n){let t="",r=0;for(let o of n){if(o.fromA<r||o.toA<o.fromA||o.toA>e.length)return;t+=e.slice(r,o.fromA)+o.insertedText,r=o.toA}return t+e.slice(r)}m(q,"replayChanges");function _e(e){let n=X(e,void 0),{displayResults:t,...r}=e;return{...r,results:e.results?.map(o=>{let i=C.ensure(o),{beforeContentMap:f,afterContent:d,afterDocument:a,snapshot:l,activeEdits:c,inputEdits:g,beforeReadText:s,rawChanges:h,diffPeerRanges:u,diffs:y,...w}=i.data;return new C(w)}),mutationRender:n.flatMap(({path:o,model:i,diffStatuses:f})=>i===void 0?[]:[{path:o,model:i,...f===void 0?{}:{diffStatuses:f}}])}}m(_e,"compactMutationDetails");export{N as a,E as b,re as c,G as d,X as e,_e as f};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t="pi-agent-text-editor:native-batch-finished";export{t as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as u,f as E,k as a}from"./chunk-
|
|
1
|
+
import{e as u,f as E,k as a}from"./chunk-FXNKMNSJ.js";import{a as n}from"./chunk-EI7MMDWY.js";function T(o,r){let s=n(()=>{let e,i={plugin:r,accept(c){if(e!==void 0)throw new Error(`Plugin ${r.id} registration was accepted more than once`);e=c}};return o.events.emit(E,i),e},"announce"),t=n(()=>{},"unsubscribe");t=o.events.on(u,e=>{if(!a(e))throw new Error("Invalid pi-agent-text-editor core readiness event");let i=s();if(i===void 0)throw new Error("pi-agent-text-editor core announced readiness without accepting the plugin");t(),i.catch(()=>{})}),o.on("session_shutdown",t);let d=s();if(d!==void 0)return t(),d}n(T,"connectTextEditorPlugin");export{T as a};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as o}from"./chunk-EI7MMDWY.js";import{Type as t}from"typebox";import{Value as C}from"typebox/value";var f=Symbol.for("pi-agent-text/TextAnchor"),u=class{constructor(n,r){this.value=n;this.lineNumber=r;if(n.length===0)throw new TypeError("Text anchor value must be non-empty");if(!Number.isSafeInteger(r)||r<1)throw new RangeError("Text anchor line number must be a positive safe integer")}static{o(this,"TextAnchor")}[f]=!0;static is(n){if(typeof n!="object"||n===null)return!1;try{let r=n;return r[f]===!0&&typeof r.value=="string"&&Number.isSafeInteger(r.lineNumber)&&r.lineNumber>=1}catch{return!1}}toString(){return this.value}},x=new WeakMap;function w(e,n,r){x.set(e,{renderer:n,resolverId:r})}o(w,"attachTextAnchorRenderer");function S(e){return x.get(e)?.renderer}o(S,"getTextAnchorRenderer");function P(e,n,r){let i=x.get(e);if(i===void 0)throw new Error(`No renderer is attached to text anchor "${n}"`);return{...i.renderer,resolverId:i.resolverId,full:i.renderer.renderFull(n,r),compact:i.renderer.renderCompact(n,r)}}o(P,"renderTextAnchor");var c={additionalProperties:!0},l=t.Function([],t.Unknown()),g=t.Object({lineNumber:t.Integer({minimum:1}),column:t.Integer({minimum:0})},c),j=t.Object({rank:t.Integer({minimum:1}),range:t.Object({start:g,end:g},c)},c),L=t.Object({id:t.String({minLength:1}),description:t.Union([t.String(),l]),normalize:t.Optional(l),renderFull:l,renderCompact:l,tryResolve:l,recover:t.Optional(l)},c),O=t.Object({code:t.Union([t.Literal("invalid"),t.Literal("stale"),t.Literal("missing"),t.Literal("ambiguous")]),reason:t.String(),contextRange:t.Optional(t.Object({offset:t.Number(),limit:t.Number()}))}),E=t.Union([t.Object({kind:t.Literal("not-handled")},c),t.Object({kind:t.Literal("resolved"),anchor:t.Unknown()},c),t.Object({kind:t.Literal("rejected"),rejection:O},c),t.Object({kind:t.Literal("failed"),error:t.Unknown()},c)]),N=t.Union([t.Object({kind:t.Literal("unavailable")},c),t.Object({kind:t.Literal("candidates"),candidates:t.Array(j),total:t.Integer({minimum:0})},c),t.Object({kind:t.Literal("timed-out")},c),t.Object({kind:t.Literal("failed"),error:t.Unknown()},c)]);function D(e){return p(L,e)&&y(()=>e.id.trim().length>0)}o(D,"isTextAnchorResolver");function I(e){return p(E,e)&&y(()=>{let n=e;return n.kind!=="resolved"||u.is(n.anchor)})}o(I,"isTextAnchorResolutionAttempt");function M(e){return p(N,e)}o(M,"isTextAnchorRecoveryOutcome");function p(e,n){return y(()=>C.Check(e,n))}o(p,"safeCheck");function y(e){try{return e()}catch{return!1}}o(y,"safeEvaluate");function T(e){if(!e.some(i=>i.marker!==void 0))return e.map(i=>`${i.prefix??""}${i.content}${i.suffix??""}`);let r=Math.max(0,...e.map(i=>i.prefix?.length??0));return e.map(i=>`${i.marker??" "}|${(i.prefix??"").padStart(r," ")}${i.content}${i.suffix??""}`)}o(T,"renderPresentedTextRows");var h="pi-agent-text/source-line";function $(e){let n=e.metadata?.[h];if(F(n))return n}o($,"getTextSourceLine");function U(e,n){return{...e,metadata:{...e.metadata,[h]:n}}}o(U,"withTextSourceLine");function F(e){if(typeof e!="object"||e===null)return!1;let n=e;return typeof n.source=="string"&&n.source.length>0&&typeof n.lineNumber=="number"&&Number.isInteger(n.lineNumber)&&n.lineNumber>0&&typeof n.content=="string"}o(F,"isTextSourceLine");import{Type as d}from"typebox";import{Value as W}from"typebox/value";var q=d.Function([],d.Unknown()),R=d.Object({id:d.String({minLength:1}),present:q}),B=d.Object({presenter:R,priority:d.Optional(d.Number())});function V(e){return A(R,e)}o(V,"isTextLinePresenter");function _(e){return A(B,e)}o(_,"isTextPresenterRegistration");function z(e,n){return{source:e,content:n,lines:H(n)}}o(z,"createTextDocument");function K(e){return e.lines.map(n=>`${n.content}${n.lineEnding}`).join("")}o(K,"renderTextDocument");function Y(e,n={}){let r=e.lines.flatMap(s=>[...s.presentation?.before??[],G(s,n.compact===!0),...s.presentation?.after??[]]),i=T(r),a=0;return e.lines.map(s=>{let m=1+(s.presentation?.before?.length??0)+(s.presentation?.after?.length??0),k=i.slice(a,a+m).join(`
|
|
2
|
+
`);return a+=m,`${k}${s.lineEnding}`}).join("")}o(Y,"renderPresentedTextDocument");function G(e,n){let r=n&&e.presentation?.compactPrefix!==void 0?e.presentation.compactPrefix:e.presentation?.prefix,i=n&&e.presentation?.compactSuffix!==void 0?e.presentation.compactSuffix:e.presentation?.suffix;return{content:e.content,...r!==void 0&&{prefix:r},...i!==void 0&&{suffix:i},...e.presentation?.marker!==void 0&&{marker:e.presentation.marker}}}o(G,"presentedRowFor");function H(e){if(e.length===0)return[];let n=[],r=/\r\n|\r|\n/gu,i=0,a;for(;(a=r.exec(e))!==null;)n.push({lineNumber:n.length+1,content:e.slice(i,a.index),lineEnding:a[0]}),i=a.index+a[0].length;return i<e.length&&n.push({lineNumber:n.length+1,content:e.slice(i),lineEnding:""}),n}o(H,"splitTextLines");function A(e,n){try{return W.Check(e,n)}catch{return!1}}o(A,"safeCheck");var J=new Set(["application/ecmascript","application/graphql","application/javascript","application/json","application/sql","application/toml","application/x-httpd-php","application/x-javascript","application/x-ndjson","application/x-www-form-urlencoded","application/x-yaml","application/xml","application/yaml"]);function Q(){return{id:"text",description:"Text file paths and URLs return their text.",tryConvert(e,n){return Promise.resolve(X(e,n))}}}o(Q,"createTextContentConverter");function X(e,n){let r=ee(n.signal);if(r!==void 0)return{kind:"failed",error:r};try{return{kind:"converted",content:[{type:"text",text:new TextDecoder("utf8",{fatal:!0}).decode(e.bytes)}]}}catch(i){return b(e.mediaType)?{kind:"failed",error:new TypeError(`${e.source} is not valid UTF-8 text`,{cause:i})}:{kind:"not-handled"}}}o(X,"convertText");function b(e){if(e===void 0)return!1;let n=e.split(";",1)[0]?.trim().toLowerCase()??"";return n.startsWith("text/")||J.has(n)||n.endsWith("+json")||n.endsWith("+xml")}o(b,"isTextualMediaType");function Z(e){let n=e[0];if(e.length!==1||n.type!=="text")throw new TypeError("Text resources require exactly one text block");return n.text}o(Z,"textFromAgentContent");function ee(e){if(e?.aborted===!0)return e.reason instanceof Error?e.reason:ne()}o(ee,"cancellationError");function ne(){let e=new Error("The operation was aborted");return e.name="AbortError",e}o(ne,"abortError");function te(e){if(e===null||typeof e!="object")return!1;let n=e;if(n.kind==="not-handled")return!0;if(n.kind==="failed")return"error"in n;if(n.kind==="rejected"){let r=n.rejection;return r!==null&&typeof r=="object"&&["invalid","stale","missing","ambiguous"].includes(r.code)&&typeof r.reason=="string"}return n.kind!=="resolved"||!Array.isArray(n.targets)||n.targets.length===0?!1:n.targets.every(r=>{if(r===null||typeof r!="object")return!1;let i=r.source,a=r.ranges;return typeof i=="string"&&i.length>0&&(r.expectedContent===void 0||typeof r.expectedContent=="string")&&(a===void 0||Array.isArray(a)&&a.every(re))})}o(te,"isTextTargetResolutionAttempt");function re(e){if(e===null||typeof e!="object")return!1;let n=e;return v(n.start)&&v(n.end)&&(n.linewise===void 0||typeof n.linewise=="boolean")}o(re,"isTextSelectionRange");function v(e){if(e===null||typeof e!="object")return!1;let n=e;return Number.isInteger(n.lineNumber)&&n.lineNumber>=1&&Number.isInteger(n.column)&&n.column>=0}o(v,"isTextSelectionPosition");function oe(e,n){if(e.length<16)return e;let r=n.indexOf(e);return r<0?e:[r,e.length]}o(oe,"storeText");function ie(e,n){return typeof e=="string"?e:n.slice(e[0],e[0]+e[1])}o(ie,"restoreText");export{u as a,w as b,S as c,P as d,D as e,I as f,M as g,T as h,$ as i,U as j,V as k,_ as l,z as m,K as n,Y as o,Q as p,b as q,Z as r,te as s,oe as t,ie as u};
|
package/dist/entry-0.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-KVHDMIZS.js";import"./chunk-ZPT5D4VP.js";import"./chunk-KINKBPPX.js";import"./chunk-ZC65Z3CK.js";import"./chunk-EI7MMDWY.js";export{h as addDiagnosticAnnotations,g as createDiagnosticViewContent,l as createSourceMappedTextReadHandler,i as diagnosticStatus,c as formatCodeViewReference,f as formatDiagnosticViewSource,k as formatSourceViewResults,d as formatSymbolSelector,a as parseCodeViewReference,j as renderSourceViewLine,b as resolveCodeViewPath,e as resolveDiagnosticViewPath};
|
package/dist/entry-11.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-IQD6PON5.js";import"./chunk-
|
|
1
|
+
import"./chunk-IQD6PON5.js";import"./chunk-KR36BT5E.js";import{a as l}from"./chunk-YRF7OATP.js";import{a as s,b as c}from"./chunk-FXNKMNSJ.js";import"./chunk-U2JKHKLK.js";import"./chunk-7LZKOHH2.js";import"./chunk-NNCZYO4Q.js";import"./chunk-64M3SQPG.js";import{a as g}from"./chunk-6CZO43OH.js";import{a as f,b as y}from"./chunk-OBNING2A.js";import"./chunk-PS2B6THP.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import"./chunk-ZC65Z3CK.js";import{a as d}from"./chunk-EI7MMDWY.js";function x(n,e){return u(e),g(n,{protocol:f,apiVersion:y,id:`hook/before-read/${e.id}`,setup(t){t.addResourceGuard({id:e.id,async guard(o){let r=await e.run(o);return r.decision==="allow"?{kind:"accepted"}:{kind:"rejected",reason:r.reason}}})}})}d(x,"connectBeforeReadHook");function A(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/before-edit/${e.id}`,setup(t){t.addMutationGuard({id:e.id,async guard(o,r){let a=await e.run({cwd:r.cwd,intent:r.intent??"edit",resources:o.resources.map(i=>({resourceSource:i.source,existed:i.existed,before:i.before,after:i.after,changes:i.changes})),...r.signal!==void 0&&{signal:r.signal}});return a.decision==="allow"?{kind:"accepted"}:{kind:"rejected",rejection:{code:"MUTATION_REJECTED",reason:a.reason,message:`Edit blocked by hook ${e.id}: ${a.reason}`,effect:"not-applied"}}}})}})}d(A,"connectBeforeEditHook");function m(n,e){return u(e),l(n,{protocol:s,apiVersion:c,id:`hook/after-edit/${e.id}`,setup(t){t.onDidEdit(async o=>{if(o.postProcessing!=="deferred")try{return await e.run(o)}catch(r){return{feedback:`After-edit hook ${e.id} failed after the edit was saved: ${r instanceof Error?r.message:String(r)}`,tone:"error"}}})}})}d(m,"connectAfterEditHook");function u(n){if(n.id.trim().length===0||typeof n.run!="function")throw new TypeError("A file hook needs a non-empty id and run function")}d(u,"assertHook");export{m as connectAfterEditHook,A as connectBeforeEditHook,x as connectBeforeReadHook};
|
package/dist/entry-13.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-U2JKHKLK.js";import{a as k,b as l,c as m,d as n,e as o,f as p,g as q}from"./chunk-
|
|
1
|
+
import"./chunk-U2JKHKLK.js";import{a as k,b as l,c as m,d as n,e as o,f as p,g as q,h as r,i as s,j as t}from"./chunk-7LZKOHH2.js";import"./chunk-NNCZYO4Q.js";import{b as i,d as j}from"./chunk-64M3SQPG.js";import{a as h}from"./chunk-6CZO43OH.js";import{a,b,c,d,e,f,g}from"./chunk-OBNING2A.js";import"./chunk-PS2B6THP.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import"./chunk-ZC65Z3CK.js";import"./chunk-EI7MMDWY.js";export{i as COMPACT_READ_ROWS,b as READ_API_VERSION,c as READ_CORE_READY_EVENT,d as READ_PLUGIN_REGISTER_EVENT,a as READ_PROTOCOL,h as connectReadPlugin,j as createReadResultRenderer,s as isFragmentResolverRegistration,e as isReadCoreReady,t as isReadFragmentResolution,q as isReadHandlerRegistration,f as isReadPlugin,g as isReadPluginRegistrationRequest,r as isReadViewRegistration,p as isResourceResolverRegistration,o as isTextTargetResolverRegistration,l as readDataSchema,m as readOutputSchema,k as readParameters,n as structuredRead};
|
package/dist/entry-14.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u}from"./chunk-
|
|
1
|
+
import{A,B,C,D,E,F,G,H,I,a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s,v as u,w as v,x as w,y,z}from"./chunk-SQKAXYIR.js";import"./chunk-EI7MMDWY.js";export{y as CONTENT_API_VERSION,A as CONTENT_CONVERTER_REGISTER_EVENT,z as CONTENT_HOST_READY_EVENT,w as CONTENT_PROTOCOL,p as MAX_STRUCTURED_BYTES,o as ResourceScheduler,G as ResultTargetStore,s as UnsupportedContentError,t as assertJsonData,E as connectContentConverter,I as connectResultTargets,D as createContentHost,u as createContentRunner,c as isAgentContent,n as isContentConversionAttempt,k as isContentConversionContext,l as isContentConverter,q as isContentConverterRegistration,C as isContentConverterRegistrationRequest,B as isContentHostReady,j as isContentInput,i as isContentTarget,d as isResource,h as isResourceResolutionAttempt,g as isResourceResolver,b as renderContentDescription,e as resourceAccesses,r as resourceScheduler,x as resultError,f as resultErrorSchema,F as resultInputSchema,m as structuredResultSchema,v as targetsEqual,H as verifyResultTargets,a as withStructuredResult};
|
package/dist/entry-15.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-
|
|
1
|
+
import{a as b,b as c,c as i,d as j,e as k,f as l,g as n,h as q,i as s}from"./chunk-AJRIASPQ.js";import{a,c as d,d as g,e as h}from"./chunk-FK42RSF4.js";import{a as x}from"./chunk-ZTYWHL2F.js";import{a as o,b as r,c as e,d as f,e as m,f as p,g as t}from"./chunk-7UGNGK7Y.js";import"./chunk-PS2B6THP.js";import"./chunk-SQKAXYIR.js";import"./chunk-EI7MMDWY.js";export{l as FuzzyVocabulary,r as SEARCH_API_VERSION,e as SEARCH_CORE_READY_EVENT,f as SEARCH_PLUGIN_REGISTER_EVENT,o as SEARCH_PROTOCOL,x as connectSearchPlugin,c as containsSearchMatch,s as formatFuzzyCandidate,q as fuzzyCandidateData,i as fuzzyLimits,k as isFuzzyQuery,j as isFuzzyResultData,m as isSearchCoreReady,p as isSearchPlugin,t as isSearchPluginRegistrationRequest,n as rankFuzzyIdentifiers,b as renderSearchMatches,d as searchDataSchema,g as searchOutputSchema,a as searchSchema,h as selectionData};
|
package/dist/entry-16.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s}from"./chunk-
|
|
1
|
+
import{a as o,b as r,c as e,d as f,e as m,f as p,g as t,h as x,i as a,j as b,k as c,l as d,m as g,n as h,o as i,p as j,q as k,r as l,s as n,t as q,u as s}from"./chunk-ZPT5D4VP.js";import"./chunk-EI7MMDWY.js";export{o as TextAnchor,r as attachTextAnchorRenderer,j as createTextContentConverter,g as createTextDocument,e as getTextAnchorRenderer,a as getTextSourceLine,t as isTextAnchorRecoveryOutcome,p as isTextAnchorResolutionAttempt,m as isTextAnchorResolver,c as isTextLinePresenter,d as isTextPresenterRegistration,n as isTextTargetResolutionAttempt,k as isTextualMediaType,i as renderPresentedTextDocument,x as renderPresentedTextRows,f as renderTextAnchor,h as renderTextDocument,s as restoreText,q as storeText,l as textFromAgentContent,b as withTextSourceLine};
|
package/dist/entry-17.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-IQD6PON5.js";import{m as o}from"./chunk-
|
|
1
|
+
import"./chunk-IQD6PON5.js";import{m as o}from"./chunk-KR36BT5E.js";import{a as n}from"./chunk-YRF7OATP.js";import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"./chunk-FXNKMNSJ.js";import"./chunk-SQKAXYIR.js";import"./chunk-ZPT5D4VP.js";import"./chunk-EI7MMDWY.js";export{b as TEXT_EDITOR_API_VERSION,e as TEXT_EDITOR_CORE_READY_EVENT,f as TEXT_EDITOR_PLUGIN_REGISTER_EVENT,a as TEXT_EDITOR_PROTOCOL,c as TEXT_POSITION_ANCHOR_KIND,d as TEXT_SEARCH_ANCHOR_KIND,n as connectTextEditorPlugin,o as connectTextEditorPostEditHandler,h as isResourceResolverRegistration,i as isTextAnchorResolverRegistration,j as isTextAnchorResourceResolutionAttempt,k as isTextEditorCoreReady,l as isTextEditorPlugin,m as isTextEditorPluginRegistrationRequest,g as isTextEditorToolId};
|
package/dist/entry-25.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
`)}]}
|
|
1
|
+
import{a as k}from"./chunk-YRF7OATP.js";import{a as A,b as D}from"./chunk-FXNKMNSJ.js";import"./chunk-NNCZYO4Q.js";import{d as T}from"./chunk-64M3SQPG.js";import{a as P}from"./chunk-6CZO43OH.js";import{a as F,b as C}from"./chunk-OBNING2A.js";import"./chunk-PS2B6THP.js";import{D as v,j as E}from"./chunk-SQKAXYIR.js";import{r as b}from"./chunk-ZPT5D4VP.js";import{a as p}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import{readdirSync as V,realpathSync as j,statSync as U}from"node:fs";import{mkdir as $,readFile as z,writeFile as Z}from"node:fs/promises";import I from"node:path";import{fileURLToPath as B,pathToFileURL as G}from"node:url";function O(e){return _("read",e)}s(O,"createFilesystemReadResolver");function S(e){return _("write",e)}s(S,"createFilesystemWriteResolver");function _(e,t){return{id:"filesystem",tryResolve(r,n){return Promise.resolve(X(r,n,e,t))}}}s(_,"createFilesystemResolver");function X(e,t,r,n){if(e.length===0)return{kind:"failed",error:new TypeError("Filesystem source must not be empty")};if(!K(e))return{kind:"not-handled"};if(t.signal?.aborted===!0)return{kind:"failed",error:x()};let o=e.startsWith("file://")?j(B(new URL(e))):I.resolve(t.cwd,e),i=G(o).href,d=(()=>{try{return U(o).isDirectory()}catch{return!1}})(),u=s(async({signal:f})=>d?q(o,f):J(o,n,f),"read");return r==="read"||d?{kind:"resolved",resource:{source:o,link:i,read:u}}:{kind:"resolved",resource:{source:o,link:i,read:u,async write(f,m){y(m.signal);let h=b(f);await $(I.dirname(o),{recursive:!0}),y(m.signal),await Z(o,h,{encoding:"utf8",...m.signal!==void 0&&{signal:m.signal}})}}}}s(X,"resolveFilesystemSource");function q(e,t){y(t);let r=V(e,{withFileTypes:!0}),n=[`\u{1F4C1} ${e}/`];r.length>0&&n.push("");for(let o of r){let i=o.isDirectory()?"\u{1F4C1}":o.isFile()?"\u{1F4C4}":"\u{1F517}";n.push(` ${i} ${o.name}`)}return[{type:"text",text:n.join(`
|
|
2
|
+
`)}]}s(q,"readDirectoryContent");async function J(e,t,r){y(r);let n=await z(e,{encoding:null,...r!==void 0&&{signal:r}});return y(r),t.convert({source:e,bytes:n},r===void 0?{}:{signal:r})}s(J,"readFilesystemContent");function K(e){return/^[A-Za-z]:[\\/]/u.test(e)||e.startsWith("file://")?!0:!/^[A-Za-z][A-Za-z\d+.-]*:/u.test(e)}s(K,"isFilesystemSource");function y(e){if(e?.aborted===!0)throw x()}s(y,"throwIfAborted");function x(){let e=new Error("The operation was aborted");return e.name="AbortError",e}s(x,"abortError");import{execFile as Q}from"node:child_process";import{existsSync as Y}from"node:fs";import{realpath as H}from"node:fs/promises";import ee from"node:os";import c from"node:path";import{fileURLToPath as te}from"node:url";async function L(e,t){let r=e.cause,n=Date.now()+500;if(t.signal?.aborted||e.source===void 0||typeof r!="object"||r===null||!("code"in r)||r.code!=="ENOENT")return;let o=e.source.startsWith("file://")?te(e.source):e.source,i=c.relative(t.cwd,c.resolve(t.cwd,o));if(!w(i)||i.includes("#"))return;let d=c.basename(i).toLowerCase();if(d.length<3||d.length>160)return;let u=c.join(process.env.PI_CODING_AGENT_DIR??c.join(ee.homedir(),".pi","agent"),"bin",process.platform==="win32"?"rg.exe":"rg"),f=await new Promise(a=>{Q(Y(u)?u:"rg",["--files","--hidden","--no-config","--no-ignore-parent","--null","--glob","!.git/**"],{cwd:t.cwd,timeout:250,maxBuffer:2*1024*1024,...t.signal===void 0?{}:{signal:t.signal}},(l,R)=>a(l?[]:R.split("\0").filter(Boolean).slice(0,2e4)))}),m=Math.min(3,Math.max(1,Math.floor(d.length*.2))),h=f.flatMap(a=>{if(t.signal?.aborted||Date.now()>n||!w(a))return[];let l=c.basename(a).toLowerCase();if(l.length>160||Math.abs(l.length-d.length)>m)return[];let R=re(d,l);if(R>m)return[];let M=c.dirname(i).toLowerCase(),W=c.dirname(a).toLowerCase();return[{path:a,distance:R,directoryDistance:M===W?0:1}]}).sort((a,l)=>a.distance-l.distance||a.directoryDistance-l.directoryDistance||a.path.localeCompare(l.path)),g=[],N=await H(t.cwd);for(let a of h.slice(0,20)){if(t.signal?.aborted||Date.now()>n)return;try{let l=await H(c.resolve(t.cwd,a.path));w(c.relative(N,l))&&g.push({path:a.path})}catch{}if(g.length===3)break}return g.length?g:void 0}s(L,"recoverFilesystemPath");function w(e){return e!==""&&!/^\.\.(?:[\\/]|$)/u.test(e)&&!c.isAbsolute(e)}s(w,"insideWorkspace");function re(e,t){let r=Array.from({length:t.length+1},(n,o)=>o);for(let n=1;n<=e.length;n++){let o=[n];for(let i=1;i<=t.length;i++)o[i]=Math.min(p(o[i-1])+1,p(r[i])+1,p(r[i-1])+(e[n-1]===t[i-1]?0:1));r=o}return p(r[t.length])}s(re,"editDistance");var oe={provider:"filesystem",capability:"read"},ne={provider:"filesystem",capability:"write"},ie=T({kind:"source",nativeResources:!0});async function se(e){let t=v(e,oe),r=v(e,ne),n=O(t),o=S(r),i={protocol:F,apiVersion:C,id:"filesystem",setup(u){u.addResolver({resolver:n,renderResult:ie,recoverFailure:L}),u.describe(()=>E("File path \u2014 file content; directory path \u2014 entry listing. Relative, absolute and file:// paths accepted.",t.listDescriptions()))}},d={protocol:A,apiVersion:D,id:"filesystem",setup(u){u.addResolver({resolver:o})}};await Promise.all([P(e,i),k(e,d)])}s(se,"registerFilesystemPlugin");export{se as default};
|
package/dist/entry-26.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as r}from"./chunk-QIJMV2P2.js";import{
|
|
1
|
+
import{a as r}from"./chunk-QIJMV2P2.js";import{E as e}from"./chunk-SQKAXYIR.js";import{a as t}from"./chunk-EI7MMDWY.js";var n={target:{provider:"filesystem",capability:"read"},converter:r(),priority:100};async function i(o){await e(o,n)}t(i,"registerFilesystemImage");export{i as default};
|
package/dist/entry-27.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{e as P,f as x}from"./chunk-T7I2VX3J.js";import{a as T}from"./chunk-MGCHOGQD.js";import{a as E,b as h}from"./chunk-T6LX2RX5.js";import{a as S}from"./chunk-6CZO43OH.js";import{a as R,b as O}from"./chunk-OBNING2A.js";import{m as q}from"./chunk-
|
|
1
|
+
import{e as P,f as x}from"./chunk-T7I2VX3J.js";import{a as T}from"./chunk-MGCHOGQD.js";import{a as E,b as h}from"./chunk-T6LX2RX5.js";import{a as S}from"./chunk-6CZO43OH.js";import{a as R,b as O}from"./chunk-OBNING2A.js";import{m as q}from"./chunk-ZPT5D4VP.js";import{c as j,d as v,e as y}from"./chunk-N34ATN52.js";import{a as o}from"./chunk-EI7MMDWY.js";import C from"cross-spawn";import{fileURLToPath as L}from"node:url";var b=5e3,J=10*1024*1024,k=L(new URL(".",new URL("../src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts",import.meta.url).href));function _(r){let e=r?.filter(i=>i==="jq"||i.startsWith("jq:"))??[];if(e.length===0)return;if(e.length>1)throw new Error("Read accepts only one jq view");if(r?.length!==1)throw new Error("The jq view cannot be combined with other views");let t=e[0];if(t===void 0||t==="jq"||t.slice(3).trim().length===0)throw new Error('The jq view requires a filter, for example views: ["jq:.scripts"]');return{filter:t.slice(3)}}o(_,"parseJqView");function A(r,e,t){return t.signal?.aborted===!0?Promise.reject(new Error("jq execution was cancelled")):new Promise((i,d)=>{let s=C(t.command??"jq",["-L",k,"--",r],{cwd:t.cwd,env:V(t.cwd),shell:!1,stdio:["pipe","pipe","pipe"],windowsHide:!0}),a="",l="",u=!1,m=0,c=o(n=>{u||(u=!0,clearTimeout(p),t.signal?.removeEventListener("abort",g),n===void 0?i(a):d(n))},"finish"),f=o(n=>{s.kill(),c(n)},"stop"),g=o(()=>f(new Error("jq execution was cancelled")),"abort"),p=setTimeout(()=>f(new Error(`jq did not finish within ${b/1e3} seconds`)),b);p.unref(),t.signal?.addEventListener("abort",g,{once:!0}),s.stdout?.setEncoding("utf8"),s.stderr?.setEncoding("utf8"),s.stdout?.on("data",n=>{if(m+=Buffer.byteLength(n),m>J){f(new Error(`jq output exceeded ${J/1024/1024}MB`));return}a+=n}),s.stderr?.on("data",n=>{Buffer.byteLength(l)<16384&&(l+=n)}),s.once("error",n=>c(new Error(`Cannot start jq: ${n.message}`))),s.once("close",(n,w)=>{if(!u)if(n===0)c();else{let I=l.trim().split(/\r?\n/u).slice(0,8).join(`
|
|
2
2
|
`);c(new Error(I||`jq exited ${w===null?`with code ${String(n)}`:`after signal ${w}`}`))}}),s.stdin?.once("error",n=>c(new Error(`Cannot send JSON to jq: ${n.message}`))),s.stdin?.end(e)})}o(A,"executeJq");function V(r){let e=j(r,process.env),t={};for(let i of["PATH","PATHEXT","SystemRoot","SYSTEMROOT","WINDIR"])e[i]!==void 0&&(t[i]=e[i]);return t}o(V,"safeEnvironment");async function N(r){x(r,[await P({id:"json-reading",description:"Query and transform JSON resources with jq read views",triggers:[{tool:"read",viewPrefixes:["jq:"]}]})]),await Promise.all([S(r,B),T(r,$)])}o(N,"registerFilesystemJq");var B={protocol:R,apiVersion:O,id:"filesystem-jq",setup(r){r.addView({view:"jq",presenter:{id:"filesystem-jq",present:o(e=>e,"present")}}),r.addHandler({stage:"read",when:{resolvedBy:"filesystem",contentKind:"text"},async handler(e){let t=e.state;if(t?.contentKind!=="text")return{kind:"continue",context:e};let i;try{i=_(e.request.views)}catch(a){return D(t,a instanceof Error?a.message:String(a))}if(i===void 0)return{kind:"continue",context:e};let d;try{d=await A(i.filter,t.content[0].text,{cwd:e.resolverContext.cwd,...e.resolverContext.signal===void 0?{}:{signal:e.resolverContext.signal}})}catch(a){return D(t,a instanceof Error?a.message:String(a))}let s={...t,content:[{type:"text",text:d}],text:q(t.source,d),preserveTruncatedOutput:!0};return{kind:"continue",context:{...e,state:s}}}}),r.describe('JSON files accept views such as ["jq:.scripts | keys"] to query them with the installed jq executable.')}};function D(r,e){return{kind:"return",result:{content:[{type:"text",text:`jq failed: ${e}`}],details:{source:r.source,resolvedBy:r.resolvedBy,failure:{code:"READ_FAILED",source:r.source,resolverId:r.resolvedBy,pluginId:"filesystem-jq",stage:"read",message:e}},isError:!0}}}o(D,"jqFailure");var $={protocol:E,apiVersion:1,id:"filesystem-jq",setup(r){r.addSetupCheck({id:"jq",async inspect(e){return await v("jq",e.cwd,e.env)?{}:{actions:[{id:"jq-unavailable",message:"JSON jq views are unavailable because jq was not found"}]}}}),r.addCheck({id:"jq",title:"JSON jq views",async run(e){let t=await y("jq",["--version"],e.cwd,e.env);return[t.ok?{status:"pass",message:"jq is available",detail:t.detail}:{status:"fail",message:"jq is not available",detail:t.detail}]}})}};export{N as default};
|
package/dist/entry-28.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as r}from"./chunk-BHSO2MDK.js";import{
|
|
1
|
+
import{a as r}from"./chunk-BHSO2MDK.js";import{E as e}from"./chunk-SQKAXYIR.js";import{a as t}from"./chunk-EI7MMDWY.js";var n={target:{provider:"filesystem",capability:"read"},converter:r(),priority:200};async function i(o){await e(o,n)}t(i,"registerFilesystemPdf");export{i as default};
|
package/dist/entry-29.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{E as t}from"./chunk-SQKAXYIR.js";import{p as i}from"./chunk-ZPT5D4VP.js";import{a as r}from"./chunk-EI7MMDWY.js";var o=i(),n={target:{provider:"filesystem",capability:"read"},converter:o,priority:300},s={target:{provider:"filesystem",capability:"write"},converter:o,priority:300};async function a(e){await Promise.all([t(e,n),t(e,s)])}r(a,"registerFilesystemText");export{a as default};
|
package/dist/entry-30.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as e,c as o}from"./chunk-
|
|
1
|
+
import{b as e,c as o}from"./chunk-QFTBY67N.js";import"./chunk-ZPT5D4VP.js";import"./chunk-EI7MMDWY.js";export{o as AstScopeManager,e as parseDocument};
|
package/dist/entry-31.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import{b as
|
|
1
|
+
import{b as Ie}from"./chunk-GBLKIB6O.js";import"./chunk-3JO7QFIL.js";import{f as ve,g as Ae}from"./chunk-F5YZG77W.js";import{b as E,c as Le}from"./chunk-QFTBY67N.js";import{e as ne,f as re}from"./chunk-T7I2VX3J.js";import{a as oe}from"./chunk-MGCHOGQD.js";import{a as ee,b as te}from"./chunk-T6LX2RX5.js";import{a as be}from"./chunk-YRF7OATP.js";import{a as ge,b as he,c as ye}from"./chunk-FXNKMNSJ.js";import"./chunk-NNCZYO4Q.js";import{d as ue}from"./chunk-64M3SQPG.js";import{a as ie}from"./chunk-6CZO43OH.js";import{a as se,b as ae}from"./chunk-OBNING2A.js";import{b as Re}from"./chunk-AJRIASPQ.js";import{e as M}from"./chunk-FK42RSF4.js";import{a as we}from"./chunk-ZTYWHL2F.js";import{a as Se,b as xe}from"./chunk-7UGNGK7Y.js";import{a as ce,b as le,e as de}from"./chunk-PS2B6THP.js";import{F as _,H as T,I as fe,e as pe,h as me,i as C}from"./chunk-SQKAXYIR.js";import{a as q,b as J,c as X,l as Y}from"./chunk-KVHDMIZS.js";import{m as W}from"./chunk-ZPT5D4VP.js";import"./chunk-KINKBPPX.js";import{j as Z}from"./chunk-M5MJP7Z2.js";import"./chunk-WZI4YC2O.js";import{e as Q}from"./chunk-N34ATN52.js";import{a as K}from"./chunk-ZC65Z3CK.js";import{a as p}from"./chunk-EI7MMDWY.js";import{readFile as it}from"node:fs/promises";var ct={cmake:"no compatible Tree-sitter parser is packaged",dockerfile:"no compatible Tree-sitter parser is packaged",julia:"no compatible Tree-sitter parser is packaged",powershell:"no compatible Tree-sitter parser is packaged",r:"no compatible Tree-sitter parser is packaged",svelte:"the container grammar is not available as an ast-grep language package",terraform:"the HCL grammar is not available as an ast-grep language package",vue:"the container grammar is not available as an ast-grep language package",xml:"no compatible Tree-sitter parser is packaged",zig:"no compatible Tree-sitter parser is packaged"},$=new Set(["c","cpp","csharp","css","dart","elixir","go","html","java","kotlin","lua","markdown","php","ruby","scala","shell","sql","swift","javascript","typescript","python","rust","json","yaml","toml"]),Oe={protocol:ee,apiVersion:1,id:"ast",setup(t){t.addSetupCheck({id:"structural-search",async inspect(e){return[...e.detectedLanguageIds].some(s=>$.has(s))?await Z({command:["ast-grep"]},e.cwd,e.env)?{}:{actions:[{id:"ast-grep-unavailable",message:"Structural search is unavailable because ast-grep was not found"}]}:{}}}),t.addCheck({id:"parsers",title:"AST",async run(e){let n=[];for(let s of e.detectedLanguageIds){let r=ct[s];if(r!==void 0){n.push({status:"skip",message:`${s} AST is unavailable: ${r}`});continue}if(!$.has(s))continue;let o=e.files.find(a=>lt(a,s));if(o!==void 0)try{let a=await it(o,"utf8"),c=await E(o,e.cwd,a.replaceAll(`\r
|
|
2
2
|
`,`
|
|
3
3
|
`).split(`
|
|
4
|
-
`));n.push(
|
|
5
|
-
`),"format");e.signal?.throwIfAborted();let
|
|
6
|
-
`,
|
|
7
|
-
`);
|
|
8
|
-
`)}],details:n.presentation}}}}
|
|
9
|
-
`).length;return{source:
|
|
4
|
+
`));n.push(c===void 0?{status:"fail",message:`${s} parser did not return a tree`}:{status:"pass",message:`${s} parser loaded`,detail:o})}catch(a){n.push({status:"fail",message:`${s}: ${a instanceof Error?a.message:String(a)}`})}}return n.length>0?n:[{status:"skip",message:"No supported AST files found"}]}}),t.addCheck({id:"ast-grep",title:"Structural search",async run(e){if(![...e.detectedLanguageIds].some(s=>$.has(s)))return[{status:"skip",message:"No supported structural-search files found"}];let n=await Q("ast-grep",["--version"],e.cwd,e.env);return[n.ok?{status:"pass",message:"ast-grep is available",detail:n.detail}:{status:"fail",message:"ast-grep is not available",detail:n.detail}]}})}};function lt(t,e){let n=t.slice(t.lastIndexOf(".")).toLowerCase();return{c:[".c",".h"],cpp:[".cc",".cpp",".cxx",".hh",".hpp",".hxx"],csharp:[".cs"],css:[".css",".scss",".less"],dart:[".dart"],elixir:[".ex",".exs"],go:[".go"],html:[".html",".htm"],java:[".java"],kotlin:[".kt",".kts"],lua:[".lua"],markdown:[".md",".mdx"],php:[".php"],ruby:[".rb",".rake"],scala:[".scala",".sc"],shell:[".sh",".bash"],sql:[".sql"],swift:[".swift"],javascript:[".js",".jsx",".mjs",".cjs"],typescript:[".ts",".tsx",".mts",".cts"],python:[".py",".pyi"],rust:[".rs"],json:[".json",".jsonc"],yaml:[".yaml",".yml"],toml:[".toml"]}[e]?.includes(n)??!1}p(lt,"matchesLanguage");var dt,ut;function Te(t){return{id:"ast",tryResolve(e,n){return Promise.resolve(pt(e,n,t))}}}p(Te,"createAstOutlineResolver");function pt(t,e,n){let s;try{s=q(t,"ast")}catch(a){return{kind:"failed",error:a}}if(s===void 0)return{kind:"not-handled"};let r;try{r=J(s.path,e.cwd)}catch(a){return{kind:"failed",error:a}}return{kind:"resolved",resource:{source:X("ast",r),async read({signal:a}){a?.throwIfAborted();let c=await(ut??=import("./chunk-7LD2OQH3.js")),d=await(n??(dt??=new c.AstOutlineManager)).readFileOutline(r,e.cwd);return a?.throwIfAborted(),[c.formatAstOutline(d)]}}}}p(pt,"resolveAstOutlineSource");import{DEFAULT_MAX_BYTES as mt,DEFAULT_MAX_LINES as ft,truncateHead as D}from"@earendil-works/pi-coding-agent";var U=p(async(t,e,n)=>{let{source:s,resolvedBy:r,lines:o,totalLines:a,startLine:c}=t.details;if(!(s===void 0||r!=="filesystem"||o===void 0||o.length!==a||c!==void 0&&c!==1))try{let{AstOutlineManager:l,isSupportedOutlinePath:d}=await import("./chunk-7LD2OQH3.js");if(!d(s))return;let u=p(g=>[`AST overview of ${g.path}, source lines 1-${g.totalLines}: the requested text exceeded the read buffer.`,"Source line numbers are on the left. Detail is reduced to fit the buffer; omitted bodies are not exact source text. Read a small source range when needed.",...g.renderedLines.map(f=>`${f.sourceLine?.lineNumber??"\u2026"} | ${f.text}`)].join(`
|
|
5
|
+
`),"format");e.signal?.throwIfAborted();let b=await new l(12).readDocumentOutline(s,e.cwd,o.map(g=>g.content),g=>(e.signal?.throwIfAborted(),!D(u(g),n).truncated)),y=u(b);return D(y,n).truncated?void 0:{script:t.script,content:[{type:"text",text:y}],details:{source:s,resolvedBy:"ast-overflow"}}}catch{e.signal?.throwIfAborted();return}},"reduceAstReadOutput");function Ee(){return async t=>{let{state:e,result:n}=t,s=n?.content.length===1?n.content[0]:void 0;if(t.audience==="script"||n===void 0||e?.contentKind!=="text"||e.resolvedBy!=="filesystem"||s?.type!=="text"||!D(s.text).truncated)return{kind:"continue",context:t};let r=await U({...n,details:{...n.details,source:e.source,resolvedBy:e.resolvedBy,lines:e.text.lines,startLine:1,totalLines:e.text.lines.length}},t.resolverContext,{maxBytes:mt,maxLines:ft});return r===void 0?{kind:"continue",context:t}:{kind:"return",result:r}}}p(Ee,"createAstOverflowHandler");var ke="pi-agent-ast";function Ne(t){return{id:"ast-scopes",async present(e,n){if(n.resolvedBy!=="filesystem")return e;try{let s=await t.getDocumentScopes(e.source,n.cwd,e.lines.map(o=>o.content)),r=gt(e.lines,s);return r===e.lines?e:{...e,lines:r}}catch{return e}}}}p(Ne,"createAstScopePresenter");function Pe(){return t=>{let e=t.state,n=t.result;if(e?.contentKind!=="text"||n===void 0)return{kind:"continue",context:t};let s=n.details.lines;if(s===void 0)return{kind:"continue",context:t};let r=new Map(e.text.lines.map(u=>[u.lineNumber,u])),o=new Set(s.map(u=>u.lineNumber)),a=new Map;for(let u of s){let b=r.get(u.lineNumber),y=je(b);for(let g of y?.boundaries??[]){if(o.has(g.endLine))continue;let f=r.get(g.endLine);f!==void 0&&a.set(g.endLine,f)}}if(a.size===0)return{kind:"continue",context:t};let c=[...a.values()].sort((u,b)=>u.lineNumber-b.lineNumber),l=[...s,...c],d=s.at(-1);return{kind:"continue",context:t,transform:p(u=>ht(u,l,d),"transform")}}}p(Pe,"createAstScopePostReadHandler");function gt(t,e){if(e.length===0)return t;let n=new Map,s=new Map;for(let r of e){let o=n.get(r.startLine)??[];o.push(r.beginAnchor.value),n.set(r.startLine,o);let a=s.get(r.startLine)??[];a.push({endLine:r.endLine,beginAnchor:r.beginAnchor.value,endAnchor:r.endScopeAnchor.value}),s.set(r.startLine,a);let c=n.get(r.endLine)??[];c.push(r.endScopeAnchor.value),n.set(r.endLine,c)}return t.map(r=>{let o=n.get(r.lineNumber),a=s.get(r.lineNumber);return o===void 0&&a===void 0?r:{...r,...o!==void 0&&{anchors:[...new Set([...r.anchors??[],...o])],presentation:{...r.presentation,suffix:`${r.presentation?.suffix??""}${o.map(c=>` <!-- ${c} -->`).join("")}`}},metadata:{...r.metadata,[ke]:{...je(r),...a!==void 0&&{boundaries:a}}}}})}p(gt,"addScopeMarkers");function je(t){let e=t?.metadata?.[ke];if(!(typeof e!="object"||e===null))return e}p(je,"getAstScopeMetadata");function ht(t,e,n){let s=t.content.length===1?t.content[0]:void 0;if(s?.type!=="text"||t.details.lines===void 0)return t;let r=e.slice(t.details.lines.length);if(r.length===0)return t;let o=n?.lineEnding!==void 0&&n.lineEnding.length>0?n.lineEnding:r[0]?.lineEnding!==void 0&&r[0].lineEnding.length>0?r[0].lineEnding:`
|
|
6
|
+
`,a=r.map((d,u)=>{let y=u===r.length-1?d.lineEnding:d.lineEnding||o,g=d.presentation?.prefix??"",f=d.presentation?.suffix??"";return`${g}${d.content}${f}${y}`}).join(""),c=/(?:\r\n|\r|\n)$/.test(s.text)?"":o,l=`${s.text}${c}${a}`;return{...t,content:[{...s,text:l}],details:{...t.details,lines:e}}}p(ht,"appendTextLines");var Ce=/^scope-(begin|end)-[A-Z0-9]{3,4}(?:-[1-9]\d*)?$/;function _e(t){return{id:"ast-scope",description:'`scope-begin-HASH` / `scope-end-HASH` from read views: ["ast"] \u2014 first/last lines of a scope. Any numeric suffix is part of the anchor.',renderFull(e){return e},renderCompact(e){return Ce.exec(e)?.[1]==="begin"?"scope start":"scope end"},async tryResolve(e,n){if(!Ce.test(e))return{kind:"not-handled"};try{let r=(await t.getDocumentScopes(n.source,n.cwd,n.lines)).find(o=>o.beginAnchor.value===e||o.endScopeAnchor.value===e);return r===void 0?{kind:"rejected",rejection:{code:"stale",reason:`AST scope anchor ${e} is stale`}}:{kind:"resolved",anchor:r.beginAnchor.value===e?r.beginAnchor:r.endScopeAnchor}}catch(s){return{kind:"failed",error:s}}}}}p(_e,"createAstScopeAnchorResolver");import wt from"cross-spawn";import{readFile as Rt,stat as De}from"node:fs/promises";import k from"node:path";import Me from"node:path";import{pathToFileURL as yt}from"node:url";function $e(t,e,n,s,r){let o=new Map;for(let c of e){let l=o.get(c.file)??[];l.push(c),o.set(c.file,l)}let a=[...o.entries()].map(([c,l])=>bt(c,l,s));return{sessionId:r,query:t,matchCount:e.length,fileCount:a.length,complete:n,files:a}}p($e,"createAstSearchPresentation");function bt(t,e,n){let s=new Map;e.forEach((a,c)=>{let l=a.lines.replace(/\r/gu,"").split(`
|
|
7
|
+
`);l.at(-1)===""&&l.pop();let d=`${t}:${String(c)}`;l.forEach((u,b)=>{let y=a.range.start.line+b+1,g=St(a,u,b,l.length);if(g===void 0)return;let f=s.get(y)??{text:u,ranges:[],logicalMatchIds:[]};f.ranges.push(g),f.logicalMatchIds.push(d),s.set(y,f)})});let r=[...s.entries()].sort(([a],[c])=>a-c).map(([a,c])=>{let l=xt(c.ranges);return{lineNumber:a,text:c.text,matchCount:l.length,ranges:l,logicalMatchIds:[...new Set(c.logicalMatchIds)]}}),o=Me.resolve(n,t);return{path:Me.relative(n,o),link:yt(o).href,matchCount:e.length,lines:r}}p(bt,"createFilePresentation");function St(t,e,n,s){let r=n===0,o=n===s-1,a=r?t.range.start.column:0,c=o?t.range.end.column:e.length;if(!(c<=a))return{from:Math.min(a,e.length),to:Math.min(c,e.length)}}p(St,"highlightedRange");function xt(t){let e=[...t].sort((s,r)=>s.from-r.from||s.to-r.to),n=[];for(let s of e){let r=n.at(-1);r===void 0||s.from>r.to?n.push(s):n[n.length-1]={from:r.from,to:Math.max(r.to,s.to)}}return n}p(xt,"mergeRanges");function Be(t){return{id:"ast",supportsResultScope:!0,readResources:p((e,n)=>e.query.startsWith("ast:")?n.scope?.targets.map(s=>s.source)??[e.path??n.cwd]:[],"readResources"),renderResult:Ie,async tryResolve(e,n){if(!e.query.startsWith("ast:"))return{kind:"not-handled"};let s=e.query.slice(4).trim();if(s.length===0)return{kind:"failed",error:new Error("ast: pattern must not be empty")};let r=p(async d=>{n.scope!==void 0&&await T(n.scope,d);let u=await vt(s,e,n.cwd,d,n.scope?.targets.map(f=>f.source));u.sort((f,h)=>k.resolve(n.cwd,f.file).localeCompare(k.resolve(n.cwd,h.file))||f.range.byteOffset.start-h.range.byteOffset.start||f.range.byteOffset.end-h.range.byteOffset.end);let b=await Ue(u,n.cwd,d),y=u.map((f,h)=>{let m=K(b[h]);return{selection:m,raw:{...f,range:{...f.range,start:{line:m.lineNumber-1,column:m.startColumn},end:{line:(m.endLineNumber??m.lineNumber)-1,column:m.endColumn}}}}}).filter(({selection:f})=>n.scope===void 0||Re(n.scope,f)),g=y.slice(0,e.limit??100);return n.scope!==void 0&&await T(n.scope,d),{raw:g.map(f=>f.raw),matches:g.map(f=>f.selection),complete:(n.scope?.complete??!0)&&y.length<=(e.limit??100)}},"collect"),o=await r(n.signal),a=await t({request:e,matches:o.matches,complete:o.complete,refresh:r},n),c=M(o.matches,o.complete,a.id,a),l=[];for(let d of o.raw.slice(0,c.matches.length)){let u=Object.entries({...Object.fromEntries(Object.entries(d.metaVariables?.single??{}).map(([y,g])=>[y,[g]])),...d.metaVariables?.multi}),b=[];for(let[y,g]of u){for(let m of g)if(m.range.byteOffset.start<d.range.byteOffset.start||m.range.byteOffset.end>d.range.byteOffset.end)throw new Error("AST capture lies outside its parent match.");let f=await Ue(g.map(m=>({...d,...m})),n.cwd,n.signal),h=[];for(let m=0;m<f.length;m+=100){let x=f.slice(m,m+100),w=await t({request:e,matches:x,complete:o.complete,refresh:p(async()=>{throw new Error("Capture snapshots cannot refresh; repeat the AST search.")},"refresh")},n);h.push(...M(x,o.complete,void 0,w).matches)}b.push([y,h])}l.push(Object.fromEntries(b))}return n.scope!==void 0&&await T(n.scope,n.signal),{kind:"resolved",payload:{data:{...c,matches:c.matches.map((d,u)=>({...d,captures:l[u]}))},pattern:s,matches:o.raw.map((d,u)=>({...d,selection:o.matches[u]})),complete:o.complete,sessionId:a.id,presentation:$e(e.query,o.raw,o.complete,n.cwd,a.id)}}},toScriptData(e){return e.data},format(e){let n=e;if(n.matches.length===0)return{content:[{type:"text",text:"No AST matches found."}],details:n.presentation};let s=n.matches.flatMap((r,o)=>[`SEARCH#${n.sessionId}:${String(o+1)}:match ${r.file}:${String(r.range.start.line+1)}:${String(r.range.start.column+1)} ${r.language}`,` ${r.lines.trim()}`]);return n.complete&&s.unshift(`SEARCH#${n.sessionId}:all:match selects all exact AST matches.`),n.complete||s.push("Result limit reached."),{content:[{type:"text",text:s.join(`
|
|
8
|
+
`)}],details:n.presentation}}}}p(Be,"createAstSearchResolver");async function Ue(t,e,n){let s=new Map;for(let r of t){let o=k.resolve(e,r.file);if(s.has(o))continue;let a=await De(o),c=await Rt(o,{signal:n}),l=await De(o);if(a.mtimeMs!==l.mtimeMs||a.size!==l.size)throw new Error("AST source changed during search. Run the structural query again.");s.set(o,c)}return t.map(r=>{let o=k.resolve(e,r.file),a=s.get(o);if(a===void 0)throw new Error("Missing AST source snapshot");let{start:c,end:l}=r.range.byteOffset;if(!Number.isInteger(c)||!Number.isInteger(l)||c<0||l<c||l>a.length||a.subarray(c,l).toString("utf8")!==r.text)throw new Error("AST range does not match its source snapshot. Search again.");let d=a.subarray(0,c).toString("utf8"),u=a.subarray(0,l).toString("utf8"),b=d.split(`
|
|
9
|
+
`).length;return{source:o,lineNumber:b,endLineNumber:u.split(`
|
|
10
10
|
`).length,startColumn:d.length-d.lastIndexOf(`
|
|
11
11
|
`)-1,endColumn:u.length-u.lastIndexOf(`
|
|
12
|
-
`)-1,matchedText:
|
|
13
|
-
`)[p-1]?.replace(/\r$/u,"")??""}})}l(Re,"selectionMatches");function be(a,e,n,r){let t=["run","--pattern",a,"--json=compact","--no-ignore","parent"];for(let s of te(e.include))t.push("--globs",s);for(let s of te(e.exclude))t.push("--globs",`!${s}`);return t.push(e.path??"."),new Promise((s,o)=>{let i=Ae("ast-grep",t,{cwd:n,stdio:["ignore","pipe","pipe"]}),c="",d="";i.stdout.setEncoding("utf8"),i.stderr.setEncoding("utf8"),i.stdout.on("data",p=>c+=p),i.stderr.on("data",p=>d+=p);let u=l(()=>{i.kill("SIGTERM")},"abort");r?.addEventListener("abort",u,{once:!0}),i.once("error",o),i.once("close",p=>{if(r?.removeEventListener("abort",u),r?.aborted===!0){o(r.reason instanceof Error?r.reason:new Error("AST search aborted"));return}if(p!==0&&p!==1){o(new Error(d.trim()||`ast-grep exited with code ${String(p)}`));return}try{let f=JSON.parse(c.length===0?"[]":c);if(!Array.isArray(f))throw new TypeError("ast-grep returned non-array JSON");s(f)}catch(f){o(f instanceof Error?f:new Error(String(f)))}})})}l(be,"runAstGrep");function te(a){return a?.split(",").map(e=>e.trim()).filter(Boolean)??[]}l(te,"splitGlobs");var we=I({kind:"code-view",label:"AST"});async function re(a){let e=new F,n=K(e),r={protocol:P,apiVersion:k,id:"ast",setup(s){s.addResolver({resolver:z(),renderResult:we}),s.addHandler({stage:"read",when:{resolvedBy:"ast",contentKind:"text"},handler:v()}),s.addView({view:"ast",presenter:n});let o=U();s.addOutputReducer(S);let i=q();s.addHandler({stage:"post-read",async handler(c){let d=await o(c);return d.kind==="return"?d:i(d.context)}}),s.describe('ast:<path> \u2014 compact declaration outline. views: ["ast"] \u2014 scope boundaries alongside source text. Oversized code reads may return an outline with source line numbers; offset/limit read a smaller source range.')}},t={protocol:$,apiVersion:C,id:"ast",setup(s){s.addAnchorResolver({resolver:Y(e),kind:N,type:"auxiliary"}),s.addTextPresenter({presenter:n})}};await Promise.all([M(a,r),E(a,G),_(a,t),j(a,{protocol:D,apiVersion:H,id:"ast-search",setup(s){s.addResolver({resolver:ne(s.registerSelection)}),s.describe("Search code structure with ast:<pattern>, using source-code syntax and placeholders such as $NAME for one node and $$$BODY for several nodes. path, include and exclude narrow the search. Use returned SEARCH# references to read, replace, copy, move or delete exact AST matches, including multiline nodes. A single :match reference becomes stale after its file changes; :all:match reruns the original structural query. Incomplete results do not provide all selections. Use captures in Apply to compute replacement text; these edits do not update imports or references.")}})])}l(re,"registerAst");export{re as default};
|
|
12
|
+
`)-1,matchedText:r.text,lineText:a.toString("utf8").split(`
|
|
13
|
+
`)[b-1]?.replace(/\r$/u,"")??""}})}p(Ue,"selectionMatches");function vt(t,e,n,s,r){if(s?.throwIfAborted(),r?.length===0)return Promise.resolve([]);let o=["run","--pattern",t,"--json=compact","--no-ignore","parent"];for(let a of Ge(e.include))o.push("--globs",a);for(let a of Ge(e.exclude))o.push("--globs",`!${a}`);return o.push(...r??[e.path??"."]),new Promise((a,c)=>{let l=wt("ast-grep",o,{cwd:n,stdio:["ignore","pipe","pipe"]}),d="",u="";l.stdout.setEncoding("utf8"),l.stderr.setEncoding("utf8"),l.stdout.on("data",y=>d+=y),l.stderr.on("data",y=>u+=y);let b=p(()=>{l.kill("SIGTERM")},"abort");s?.addEventListener("abort",b,{once:!0}),l.once("error",c),l.once("close",y=>{if(s?.removeEventListener("abort",b),s?.aborted===!0){c(s.reason instanceof Error?s.reason:new Error("AST search aborted"));return}if(y!==0&&y!==1){c(new Error(u.trim()||`ast-grep exited with code ${String(y)}`));return}try{let g=JSON.parse(d.length===0?"[]":d);if(!Array.isArray(g))throw new TypeError("ast-grep returned non-array JSON");a(g)}catch(g){c(g instanceof Error?g:new Error(String(g)))}})})}p(vt,"runAstGrep");function Ge(t){return t?.split(",").map(e=>e.trim()).filter(Boolean)??[]}p(Ge,"splitGlobs");import{Text as Ut}from"@earendil-works/pi-tui";import Ve from"node:path";import{pathToFileURL as At}from"node:url";function He(t,e,n,s){let r=new Map;for(let c of t){let l=r.get(c.target.source);l?l.push(c):r.set(c.target.source,[c])}let o=[];t.length||o.push({kind:"note",text:"No selections"}),e||o.push({kind:"note",text:"Incomplete input; not a complete edit scope"}),n&&o.push({kind:"note",text:`${n} input(s) without a selection`});let a=100;for(let[c,l]of r){if(!a)break;let d=l.slice(0,a);a-=d.length;let u=Ve.relative(s,c)||Ve.basename(c),b=[],y=!1,g=l[0]?.target.expectedContent.split(/\r\n|\n|\r/u)??[];for(let h of d){let{start:m,end:x}=h.range,R=m.lineNumber===x.lineNumber&&m.column===x.column?m.lineNumber:x.lineNumber-(x.column===0?1:0),F=Math.min(R,m.lineNumber+19);y||=F<R;for(let L=m.lineNumber;L<=F;L++){let z=g[L-1]??"";b.push({source:c,label:u,link:At(c).href,lineNumber:L,text:z,ranges:[{from:L===m.lineNumber?m.column:0,to:L===x.lineNumber?x.column:z.length}]})}}let f=le(b);o.push(...f.map(h=>h.kind==="source"?{...h,count:l.length}:h)),y&&o.push({kind:"note",text:"\u2026 selection preview shortened \xB7 full target retained"});for(let h of d){h.range.start.lineNumber===h.range.end.lineNumber&&h.range.start.column===h.range.end.column&&o.push({kind:"note",text:`zero-width \xB7 ${h.range.start.lineNumber}:${h.range.start.column}`});let{start:m,end:x}=h.range;o.push({kind:"note",expandedOnly:!0,text:`${h.syntax?`${h.syntax.object}${h.syntax.part?`/${h.syntax.part}`:""} \xB7 `:""}${m.lineNumber}:${m.column}\u2013${x.lineNumber}:${x.column} \xB7 ${h.origins.length} origin(s)${h.origins.some(w=>w.expanded)?" \xB7 expanded":""}`});for(let w of h.origins.slice(0,20)){let R=w.range;o.push({kind:"note",expandedOnly:!0,text:`from ${R.startLine}:${R.startColumn}\u2013${R.endLine}:${R.endColumn}`})}h.origins.length>20&&o.push({kind:"note",expandedOnly:!0,text:"\u2026 more origins retained in structured result"})}}return t.length>100&&o.push({kind:"note",text:"\u2026 more selections \xB7 consume the complete result target"}),{summary:`${t.length} ${t.length===1?"selection":"selections"} in ${r.size} ${r.size===1?"file":"files"}${e?"":" \xB7 incomplete"}`,rows:o}}p(He,"selectPresentation");import Tt from"node:path";var S=class extends Error{constructor(n,s){super(s);this.code=n}static{p(this,"SelectionError")}};function v(t){return{startLine:t.start.lineNumber,startColumn:t.start.column,endLine:t.end.lineNumber,endColumn:t.end.column}}p(v,"publicRange");function O(t,e){let n=JSON.stringify([e.target.source,e.range]),s=t.get(n);t.set(n,s?{...e,origins:[...s.origins,...e.origins]}:e)}p(O,"retainRegion");var A=class{constructor(e){this.content=e;let n=0,s=W("",e),r=s.lines.map(o=>{let a=n;return n+=o.content.length+o.lineEnding.length,{start:a,length:o.content.length,end:n}});(r.length===0||s.lines.at(-1)?.lineEnding)&&r.push({start:n,length:0,end:n}),this.lines=r}static{p(this,"SourceText")}lines;boundary(e){if(!Number.isSafeInteger(e)||e<0||e>this.content.length)throw new S("INVALID_RANGE","Text bounds are outside the retained snapshot.");let n=this.content.charCodeAt(e-1),s=this.content.charCodeAt(e);if(n>=55296&&n<=56319&&s>=56320&&s<=57343||n===13&&s===10)throw new S("INVALID_BOUNDARY","Text boundary splits a surrogate pair or CRLF separator.")}offset(e){let n=this.lines[e.lineNumber-1];if(!Number.isSafeInteger(e.lineNumber)||!n||!Number.isSafeInteger(e.column)||e.column<0||e.column>n.length)throw new S("INVALID_RANGE","Source bounds are outside the retained snapshot.");let s=n.start+e.column;return this.boundary(s),s}lineIndex(e){let n=0,s=this.lines.length-1;for(;n<s;){let r=Math.ceil((n+s)/2);(this.lines[r]?.start??0)<=e?n=r:s=r-1}return n}position(e){this.boundary(e);let n=this.lineIndex(e);return{lineNumber:n+1,column:e-(this.lines[n]?.start??0)}}range(e,n){if(n<e)throw new S("INVALID_RANGE","Text bounds are reversed.");return{start:this.position(e),end:this.position(n)}}fullLines(e,n){let s=this.lines[this.lineIndex(e)],r=this.lines[this.lineIndex(n>e?n-1:e)];if(!s||!r)throw new S("INVALID_RANGE","Source line bounds are unavailable.");return{from:s.start,to:r.end}}};function Fe(t,e,n){let s=t;for(;s.parent&&s.parent.node.startIndex===s.node.startIndex&&s.parent.node.endIndex===s.node.endIndex;)s=s.parent;let r=s.parent;if(!r||!(r.node.type==="arguments"&&r.parent?.object==="call"||r.node.type==="formal_parameters"&&r.parent?.object==="function")||s.node.type==="comment")throw new S("EXACT_LIST_ELEMENT_REQUIRED","elementExtent requires an exact direct call argument or parenthesized function parameter. Use a full AST capture; partial expressions and other lists are not supported.");let o=r.node.startIndex,a=r.node.endIndex-1;if(n[o]!=="("||n[a]!==")")throw new S("UNSUPPORTED_LIST","Only parenthesized argument and parameter lists are supported.");if(e==="inside")return{startIndex:s.node.startIndex,endIndex:s.node.endIndex};let c=r.children.filter(h=>h.node.type!=="comment"),l=c.indexOf(s),d=c[l-1],u=c[l+1],b=d?.node.endIndex??o+1,y=u?.node.startIndex??a,g=n.slice(b,s.node.startIndex),f=n.slice(s.node.endIndex,y);if(!(d?/^\s*,\s*$/u:/^\s*$/u).test(g)||!(u?/^\s*,\s*$/u:/^\s*,?\s*$/u).test(f))throw new S("AMBIGUOUS_LIST_TRIVIA","Comments or unsupported trivia in adjacent list gaps have no inferred owner. Use inside for the exact element, or choose explicit text boundaries.");return c.length===1?{startIndex:o+1,endIndex:a}:u||f.includes(",")?{startIndex:s.node.startIndex,endIndex:y}:{startIndex:b,endIndex:s.node.endIndex}}p(Fe,"listElementExtent");var It={function_declaration:"function",generator_function_declaration:"function",function_expression:"function",generator_function:"function",arrow_function:"function",method_definition:"function",function_signature:"function",method_signature:"function",abstract_method_signature:"function",call_expression:"call",new_expression:"call",class_declaration:"class",class:"class",abstract_class_declaration:"class",if_statement:"if",switch_statement:"switch",for_statement:"loop",for_in_statement:"loop",while_statement:"loop",do_statement:"loop",try_statement:"try",catch_clause:"catch",variable_declarator:"binding",assignment_expression:"assignment",augmented_assignment_expression:"assignment",object:"object",object_pattern:"object",pair:"property",pair_pattern:"property",shorthand_property_identifier:"property",shorthand_property_identifier_pattern:"property",array:"array",array_pattern:"array",return_statement:"return",throw_statement:"throw"};function ze(t,e){let n=[],s=[{node:t,parent:void 0}];for(;s.length;){e?.throwIfAborted();let r=s.pop();if(!r)continue;let o={node:r.node,object:It[r.node.type],parent:r.parent,children:[]};r.parent?.children.push(o),n.push(o);for(let a of r.node.namedChildren.toReversed())s.push({node:a,parent:o})}return n}p(ze,"constructIndex");function I(t){let e=t.parent;for(;e&&!e.object;)e=e.parent;return e}p(I,"constructParent");function G(t,e,n){let s=[],r=[...t.children].reverse();for(;r.length;){n?.throwIfAborted();let o=r.pop();o&&(o.object&&s.push(o),(e||!o.object)&&r.push(...o.children.toReversed()))}return s}p(G,"constructChildren");var Lt={function:[["name",["name"]],["body",["body"]],["parameters",["parameters","parameter"]],["returnType",["return_type"]]],call:[["callee",["function","constructor"]],["arguments",["arguments"]]],class:[["name",["name"]],["body",["body"]]],if:[["condition",["condition"]],["then",["consequence"]],["else",["alternative"]]],switch:[["condition",["value"]],["body",["body"]]],loop:[["condition",["condition"]],["body",["body"]]],try:[["body",["body"]],["handler",["handler"]],["finalizer",["finalizer"]]],catch:[["body",["body"]],["parameter",["parameter"]]],binding:[["name",["name"]],["type",["type"]],["value",["value"]]],assignment:[["left",["left"]],["right",["right"]]],property:[["key",["key"]],["value",["value"]]],return:[["value",[]]],throw:[["value",[]]],object:[],array:[]};function Ot(t){return t.node.type==="for_statement"?[["initializer",["initializer"]],["condition",["condition"]],["update",["increment"]],["body",["body"]]]:t.node.type==="for_in_statement"?[["left",["left"]],["iterable",["right"]],["body",["body"]]]:t.node.type==="finally_clause"?[["body",["body"]]]:t.object?Lt[t.object]:[]}p(Ot,"partFields");function qe(t,e){let n=Ot(t),s=n.find(([r])=>r===e)?.[1];if(!s)throw new S("UNSUPPORTED_PART",`Unsupported part ${e} for ${t.object??"this syntax container"}; supported parts: ${n.map(([r])=>r).join(", ")||"none"}. Use navigate children/descendants for nested constructs.`);if(t.object==="property"&&t.node.type.startsWith("shorthand_property_identifier"))return t.node;if(t.object==="return"||t.object==="throw")return t.node.namedChildren.find(r=>r.type!=="comment");for(let r of s){let o=t.node.childForFieldName(r);if(o)return o}}p(qe,"constructPart");var Et=new Set([".js",".mjs",".cjs",".ts",".mts",".cts"]);function kt(t,e,n){let s=t.filter(o=>o.node.startIndex===e&&o.node.endIndex===n),r=s.find(o=>o.object)??s.at(-1);if(!r)throw new S("EXACT_NODE_REQUIRED","Navigation and parts require an exact syntax node. Use object/enclosing first for a partial match; use a returned part target to navigate its contents.");return r}p(kt,"exactNode");function Nt(t,e,n,s){let r;for(let a of t)a.object!==s.object||a.node.startIndex>e||a.node.endIndex<n||e===n&&a.node.endIndex===n||(!r||a.node.endIndex-a.node.startIndex<r.node.endIndex-r.node.startIndex)&&(r=a);if(!r&&t.filter(a=>a.object===s.object&&a.node.startIndex<n&&a.node.endIndex>e).length>1)throw new S("AMBIGUOUS_SEED","The seed spans separate constructs; select narrower input ranges.");let o=1;for(;r&&o<(s.level??1);){for(r=I(r);r&&r.object!==s.object;)r=I(r);o++}return r}p(Nt,"enclosing");function Pt(t,e,n,s){let r;switch(e.relation){case"parent":{let o=I(t);r=o?[o]:[];break}case"ancestors":{r=[];let o=I(t);for(;o;)s?.throwIfAborted(),r.push(o),o=I(o);break}case"children":case"descendants":{r=G(t,e.relation==="descendants",s);break}case"siblings":{if(!t.object)throw new S("EXACT_CONSTRUCT_REQUIRED","siblings requires an exact supported construct, not a part container. Use enclosing first.");let o=G(I(t)??n,!1,s),a=o.indexOf(t),c=e.direction??"all",l=c==="previous"?o[a-1]:o[a+1];r=c==="all"?o.filter(d=>d!==t):l?[l]:[];break}}return r.filter(o=>!e.object||o.object===e.object).sort((o,a)=>o.node.startIndex-a.node.startIndex||a.node.endIndex-o.node.endIndex)}p(Pt,"navigate");async function Je(t,e,n,s){let r=new Map,o=0;for(let a of t.targets){if(s?.throwIfAborted(),!Et.has(Tt.extname(a.source).toLowerCase()))throw new S("UNSUPPORTED_LANGUAGE","Select AST supports JavaScript and TypeScript files, without JSX/TSX.");let c=await E(a.source,n,a.expectedContent.split(`
|
|
14
|
+
`));if(!c)throw new S("UNSUPPORTED_PROVIDER","No syntax provider is available for this source.");try{if(c.rootNode.hasError)throw new S("INVALID_SYNTAX","The syntax provider reports errors; no structural targets were created.");let l=ze(c.rootNode,s),d=l[0];if(!d)throw Error("Missing syntax root");let u=new A(a.expectedContent);for(let b of a.ranges){s?.throwIfAborted();let y=u.offset(b.start),g=u.offset(b.end),f=e.kind==="object"?Nt(l,y,g,e):kt(l,y,g),h=f&&e.kind==="elementExtent"?Fe(f,e.extent,a.expectedContent):void 0,m=f?e.kind==="part"?[qe(f,e.part)].filter(x=>x!==void 0).map(x=>({node:x,object:f.object})):e.kind==="navigate"?Pt(f,e,d,s):[f]:[];m.length||o++;for(let x of m){let w=h??x.node,R=x.object&&e.kind!=="elementExtent"?{object:x.object,...e.kind==="part"?{part:e.part}:{}}:void 0;O(r,{target:a,range:{start:u.position(w.startIndex),end:u.position(w.endIndex)},text:a.expectedContent.slice(w.startIndex,w.endIndex),origins:[{source:a.source,range:v({start:b.start,end:u.position(g)}),expanded:w.startIndex<y||w.endIndex>g}],...R?{syntax:R}:{}})}}}finally{c.delete?.()}}return{regions:[...r.values()],missingInputs:o}}p(Je,"selectStructuralRegions");function Ke(t,e,n){n?.throwIfAborted();let s=e.kind==="range"||e.kind==="lines";if(s&&new Set(t.targets.map(a=>a.source)).size>1)throw new S("MULTIPLE_SOURCES","Absolute text bounds require one source.");let r=new Map,o=0;for(let a of t.targets){n?.throwIfAborted();let c=new A(a.expectedContent),l=s?jt(c,e):void 0,d=!1;for(let u of a.ranges){n?.throwIfAborted();let b=c.offset(u.start),y=c.offset(u.end);c.range(b,y);let g=l?l.from>=b&&l.to<=y?[l]:[]:Ct(c,{from:b,to:y},e,n);g.length?d=!0:o++;for(let f of g){n?.throwIfAborted();let h=c.range(f.from,f.to),m=f.from<b||f.to>y;if(m&&e.kind!=="linesOf"&&!(e.kind==="between"&&e.extent==="lines"))throw new S("OUTSIDE_SCOPE","Text selection exceeds its input scope.");O(r,{target:a,range:h,text:c.content.slice(f.from,f.to),origins:[{source:a.source,range:v(u),expanded:m}]})}}if(l&&!d)throw new S("OUTSIDE_SCOPE","Requested text bounds are outside every input scope.")}return{regions:[...r.values()],missingInputs:o}}p(Ke,"selectTextRegions");function jt(t,e){if(e.kind==="range"){let r=t.offset({lineNumber:e.startLine,column:e.startColumn}),o=t.offset({lineNumber:e.endLine,column:e.endColumn});return t.range(r,o),{from:r,to:o}}let n=t.lines[e.first-1],s=t.lines[e.last-1];if(!Number.isSafeInteger(e.first)||!Number.isSafeInteger(e.last)||!n||!s||e.last<e.first)throw new S("INVALID_RANGE","Line bounds are outside the retained snapshot or reversed.");return{from:n.start,to:s.end}}p(jt,"absoluteInterval");function Ct(t,e,n,s){let r=t.content.slice(e.from,e.to);switch(n.kind){case"between":{B(n.start),B(n.end);let o=[],a=0;for(;a<=r.length;){s?.throwIfAborted();let c=r.indexOf(n.start,a);if(c<0)break;let l=r.indexOf(n.end,c+n.start.length);if(l<0)throw new S("UNMATCHED_MARKER","Opening marker has no following closing marker in its input scope.");let d=e.from+c,u=e.from+l+n.end.length;t.boundary(d),t.boundary(d+n.start.length),t.boundary(e.from+l),t.boundary(u),o.push(n.extent==="lines"?t.fullLines(d,u):{from:n.extent==="inside"?d+n.start.length:d,to:n.extent==="inside"?e.from+l:u}),a=l+n.end.length}return o}case"sliceText":{let o=n.to??r.length;return Xe(n.from,o,r.length),[{from:e.from+n.from,to:e.from+o}]}case"trim":{if(!r.trim().length)return[{from:e.to,to:e.to}];let o=n.side==="end"?0:r.length-r.trimStart().length,a=n.side==="start"?r.length:r.trimEnd().length;return[{from:e.from+o,to:e.from+a}]}case"split":{B(n.delimiter);let o=[],a=0;for(;a<=r.length;){s?.throwIfAborted();let c=r.indexOf(n.delimiter,a);if(o.push({from:e.from+a,to:c<0?e.to:e.from+c}),c<0)break;a=c+n.delimiter.length}return o}case"linesOf":return[t.fullLines(e.from,e.to)];case"position":{let o=n.edge==="before"?e.from:e.to;return[{from:o,to:o}]}case"columns":{let o=[],a=t.lineIndex(e.from),c=t.lineIndex(e.to>e.from?e.to-1:e.from);for(let l=a;l<=c;l++){s?.throwIfAborted();let d=t.lines[l];if(!d)throw new S("INVALID_RANGE","Source line bounds are unavailable.");Xe(n.from,n.to,d.length);let u={from:d.start+n.from,to:d.start+n.to};if(u.from<e.from||u.to>e.to)throw new S("OUTSIDE_SCOPE","Requested columns exceed their input scope.");o.push(u)}return o}case"range":case"lines":throw new S("INVALID_RANGE","Absolute bounds must resolve against one source.")}}p(Ct,"transform");function B(t){if(!t.length)throw new S("INVALID_MARKER","Use a non-empty literal marker or delimiter.")}p(B,"nonEmpty");function Xe(t,e,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(e)||t<0||e<t||e>n)throw new S("INVALID_RANGE","Text bounds are outside their region or reversed.")}p(Xe,"orderedBounds");function Qe(t,e,n,s){s?.throwIfAborted();let r=new Map;for(let d of[...t.targets,...n.targets]){s?.throwIfAborted();let u=r.get(d.source);if(u&&u.content!==d.expectedContent)throw new S("INCOMPATIBLE_SNAPSHOTS","Geometry inputs use different snapshots of the same source.");u||r.set(d.source,new A(d.expectedContent))}let o=We(t,r,s),a=We(n,r,s),c=new Map,l=0;for(let[d,u]of o){s?.throwIfAborted();let b=r.get(d);if(!b)throw new S("MISSING_SOURCE","Verified source text is unavailable.");let y=a.get(d)??[],g=Ye(y.map(P),!0,s),f=[];if(e.kind==="merge")f.push(...Ye(u.map(P),e.adjacent??!1,s));else for(let h of u){s?.throwIfAborted();let m=_t(h,y,g,e.kind,s);m.length||l++,f.push(...m)}for(let h of f){s?.throwIfAborted();let m=h.seeds[0];if(!m)throw new S("MISSING_ORIGIN","Geometry output has no candidate origin.");O(c,{target:m.target,range:b.range(h.from,h.to),text:b.content.slice(h.from,h.to),origins:h.seeds.map(x=>({source:d,range:v(x.range),expanded:h.from<x.from||h.to>x.to}))})}}return{regions:[...c.values()],missingInputs:l}}p(Qe,"selectGeometryRegions");function We(t,e,n){let s=new Map;for(let r of t.targets){let o=e.get(r.source);if(!o)throw new S("MISSING_SOURCE","Verified source text is unavailable.");let a=s.get(r.source)??[];for(let c of r.ranges){n?.throwIfAborted();let l=o.offset(c.start),d=o.offset(c.end);o.range(l,d),a.push({target:r,range:c,from:l,to:d})}s.set(r.source,a)}return s}p(We,"seedsBySource");function P(t){return{from:t.from,to:t.to,seeds:[t]}}p(P,"asSpan");function N(t,e){return e.from===e.to?t.from===t.to?e.from===t.from:t.from<=e.from&&e.from<t.to:t.from<=e.from&&e.to<=t.to}p(N,"contains");function _t(t,e,n,s,r){if(s==="within")return e.some(c=>N(c,t))?[P(t)]:[];if(t.from===t.to)return n.some(l=>N(l,t))===(s==="intersection")?[P(t)]:[];if(s==="intersection"){let c=[];for(let l of n)if(r?.throwIfAborted(),l.from===l.to)N(t,l)&&c.push({from:l.from,to:l.to,seeds:[t]});else{let d=Math.max(t.from,l.from),u=Math.min(t.to,l.to);d<u&&c.push({from:d,to:u,seeds:[t]})}return c}let o=[],a=t.from;for(let c of n)if(r?.throwIfAborted(),!(c.from===c.to||c.to<=a||c.from>=t.to)&&(c.from>a&&o.push({from:a,to:c.from,seeds:[t]}),a=Math.max(a,c.to),a>=t.to))break;return a<t.to&&o.push({from:a,to:t.to,seeds:[t]}),o}p(_t,"transform");function Ye(t,e,n){let s=[...t].sort((a,c)=>a.from-c.from||a.to-c.to),r=[];for(let a of s){if(n?.throwIfAborted(),a.from===a.to)continue;let c=r.at(-1);c&&(a.from<c.to||e&&a.from===c.to)?r[r.length-1]={from:c.from,to:Math.max(c.to,a.to),seeds:[...c.seeds,...a.seeds]}:r.push(a)}let o=new Map;for(let a of s){if(n?.throwIfAborted(),a.from!==a.to)continue;let c=r.findIndex(u=>N(u,a)),l=c>=0?r[c]:o.get(a.from),d=l?{...l,seeds:[...l.seeds,...a.seeds]}:a;c>=0?r[c]=d:o.set(a.from,d)}return[...r,...o.values()].sort((a,c)=>a.from-c.from||a.to-c.to)}p(Ye,"mergeSpans");import{Type as i}from"typebox";var Mt=i.Union([i.Object({kind:i.Literal("range"),startLine:i.Integer({minimum:1}),startColumn:i.Integer({minimum:0}),endLine:i.Integer({minimum:1}),endColumn:i.Integer({minimum:0})},{additionalProperties:!1,description:"Use absolute one-based lines and exclusive UTF-16 columns in one source. Require full containment in an input region."}),i.Object({kind:i.Literal("lines"),first:i.Integer({minimum:1}),last:i.Integer({minimum:1})},{additionalProperties:!1,description:"Use inclusive absolute line numbers in one source. Include existing line endings; require full containment in an input region."}),i.Object({kind:i.Literal("between"),start:i.String({minLength:1}),end:i.String({minLength:1}),extent:i.Union([i.Literal("inside"),i.Literal("around"),i.Literal("lines")])},{additionalProperties:!1,description:"Pair non-empty literal opening markers with the next closing marker per region, without nesting. Resume after each pair; unmatched openings are errors. inside excludes markers, around includes them, lines explicitly expands to complete containing lines."}),i.Object({kind:i.Literal("sliceText"),from:i.Integer({minimum:0}),to:i.Optional(i.Integer({minimum:0}))},{additionalProperties:!1,description:"Slice each region by non-negative relative UTF-16 offsets. The exclusive to defaults to its end. Equal offsets select a zero-width point."}),i.Object({kind:i.Literal("trim"),side:i.Union([i.Literal("start"),i.Literal("end"),i.Literal("both")])},{additionalProperties:!1,description:"Trim Unicode whitespace from the requested edges of each region. A whitespace-only region selects a zero-width point at its end."}),i.Object({kind:i.Literal("split"),delimiter:i.String({minLength:1})},{additionalProperties:!1,description:"Split each region by a non-empty literal delimiter, excluding delimiters and retaining empty segments as zero-width points."}),i.Object({kind:i.Literal("linesOf")},{additionalProperties:!1,description:"Expand each region to complete containing lines, preserving line endings and reporting expansion. An exclusive end at next-line column zero does not include that next line."}),i.Object({kind:i.Literal("position"),edge:i.Union([i.Literal("before"),i.Literal("after")])},{additionalProperties:!1,description:"Select the zero-width start or end of each region. Use a whole-file Read for file edges."}),i.Object({kind:i.Literal("columns"),from:i.Integer({minimum:0}),to:i.Integer({minimum:0})},{additionalProperties:!1,description:"Select an exclusive UTF-16 column interval on each touched line, excluding line endings. Every interval must fit its line and original input region; no clipping."})]);function V(t,e){return i.Object({kind:i.Literal(t),scopes:{..._,description:"Comparison scopes: verified results, data, targets, item arrays, or a readable source string. Match sets by source, not array position."}},{additionalProperties:!1,description:e})}p(V,"scopedOperation");var $t=i.Union([V("within","Retain each candidate whole only when one comparison scope contains it. Never clip or join scopes for containment."),V("intersection","Clip each candidate to the union of comparison scopes in its source. Touching text ranges do not create a point."),V("difference","Subtract comparison scopes from each candidate, retaining separate surviving fragments. Point scopes do not cut text."),i.Object({kind:i.Literal("merge"),adjacent:i.Optional(i.Boolean({description:"Also merge touching nonempty ranges. Default false; never fill a gap or extend text for a point."}))},{additionalProperties:!1,description:"Explicitly merge overlapping ranges by source, retaining every contributing origin. Covered points are absorbed; other points remain separate."})]),H=i.Union([i.Literal("function"),i.Literal("call"),i.Literal("class"),i.Literal("if"),i.Literal("switch"),i.Literal("loop"),i.Literal("try"),i.Literal("catch"),i.Literal("binding"),i.Literal("assignment"),i.Literal("object"),i.Literal("property"),i.Literal("array"),i.Literal("return"),i.Literal("throw")]),tt=i.Union([i.Literal("name"),i.Literal("body"),i.Literal("parameters"),i.Literal("returnType"),i.Literal("type"),i.Literal("callee"),i.Literal("arguments"),i.Literal("condition"),i.Literal("then"),i.Literal("else"),i.Literal("initializer"),i.Literal("update"),i.Literal("iterable"),i.Literal("left"),i.Literal("right"),i.Literal("value"),i.Literal("key"),i.Literal("handler"),i.Literal("finalizer"),i.Literal("parameter")]),Ze=i.Optional({...H,description:"Filter results by construct category after navigation. The filter does not change parent/child/sibling relationships."}),Dt=i.Union([i.Object({kind:i.Literal("elementExtent"),extent:i.Union([i.Literal("inside"),i.Literal("around")])},{additionalProperties:!1,description:"Select an exact direct JS/TS call argument or parenthesized function parameter. inside keeps the element; around includes owned comma/whitespace. Prefer the following separator; last without a trailing comma uses the preceding gap; only elements own the list interior. Adjacent boundary comments reject around. No destination syntax repair."}),i.Object({kind:i.Literal("object"),object:H,relation:i.Optional(i.Literal("enclosing")),level:i.Optional(i.Integer({minimum:1,description:"Default 1 (nearest). Count only constructs of the requested category."})),extent:i.Optional(i.Literal("around"))},{additionalProperties:!1,description:"Select the requested containing construct. level=1 is nearest and includes an exact seed; higher levels count only that category. Match the entire seed, not its first character."}),i.Object({kind:i.Literal("part"),part:tt},{additionalProperties:!1,description:"Select an exact supported construct's named part, including delimiters belonging to its syntax node. A supported optional part may be absent; unsupported parts are errors with available names. Use an enclosing object first for partial input."}),i.Object({kind:i.Literal("navigate"),relation:i.Union([i.Literal("parent"),i.Literal("ancestors"),i.Literal("children"),i.Literal("descendants")]),object:Ze},{additionalProperties:!1,description:"Navigate from an exact named syntax node, including constructs, part targets and the document root. Skip parser-only wrappers in results. Exclude the starting node; ancestors/descendants return results in source order. parent/children never skip recognized constructs to satisfy a filter. Use enclosing first for ranges that cut through a node."}),i.Object({kind:i.Literal("navigate"),relation:i.Literal("siblings"),object:Ze,direction:i.Optional(i.Union([i.Literal("previous"),i.Literal("next"),i.Literal("all")],{description:"Default all. previous/next select the immediate sibling before category filtering, not the next matching category."}))},{additionalProperties:!1,description:"Select siblings of an exact supported construct under the same normalized parent. Exclude the input; return source order. A missing neighbor is valid absence."})]),nt=i.Object({path:{..._,description:"Pass a compatible source result, its data or RESULT# target, a returned-item array, or a file path. Preview text and reconstructed coordinates are not source targets."},operation:i.Union([Dt,Mt,$t])},{additionalProperties:!1}),et=i.Object({startLine:i.Integer({minimum:1}),startColumn:i.Integer({minimum:0}),endLine:i.Integer({minimum:1}),endColumn:i.Integer({minimum:0})},{additionalProperties:!1}),j=i.Object({kind:i.Literal("selection"),target:i.String({description:"Stored target for every selected range, including items beyond the preview."}),complete:i.Boolean({description:"Execution completeness inherited from all inputs, independent of preview limits."}),totalItems:i.Integer({minimum:0}),missingInputs:i.Integer({minimum:0}),truncated:i.Boolean(),items:i.Array(i.Object({target:i.String(),source:i.String(),range:et,syntax:i.Optional(i.Object({object:H,part:i.Optional(tt)},{additionalProperties:!1,description:"Parser-derived normalized construct category and selected part. This describes the target; it is not edit authority."})),origins:i.Array(i.Object({source:i.String(),range:et,expanded:i.Boolean()},{additionalProperties:!1})),preview:i.String({maxLength:1e3}),textTruncated:i.Boolean()},{additionalProperties:!1}),{maxItems:100})},{additionalProperties:!1}),rt=pe(j);function Gt(t){switch(t.kind){case"object":return`enclosing ${t.object} \xB7 level ${t.level??1}`;case"part":return`part ${t.part}`;case"elementExtent":return`list element \xB7 ${t.extent}`;case"navigate":return`${t.relation}${t.relation==="siblings"?` ${t.direction??"all"}`:""}${t.object?` \xB7 ${t.object}`:""}`;case"between":return`between ${JSON.stringify(t.start)} \u2026 ${JSON.stringify(t.end)} \xB7 ${t.extent}`;case"range":return`range ${t.startLine}:${t.startColumn}\u2013${t.endLine}:${t.endColumn}`;case"lines":return`lines ${t.first}\u2013${t.last}`;case"sliceText":return`text slice ${t.from}\u2013${t.to??"end"}`;case"trim":return`trim ${t.side}`;case"split":return`split ${JSON.stringify(t.delimiter)}`;case"linesOf":return"containing lines";case"position":return`position ${t.edge}`;case"columns":return`columns ${t.from}\u2013${t.to}`;case"within":case"intersection":case"difference":return t.kind;case"merge":return t.adjacent?"merge overlaps and adjacent ranges":"merge overlaps"}}p(Gt,"operationLabel");function ot(t){return t.kind==="within"||t.kind==="intersection"||t.kind==="difference"||t.kind==="merge"}p(ot,"isGeometryOperation");async function st(t,e){let n=fe(t);re(t,[await ne({id:"select-code",description:"Derive text and AST boundaries, navigate constructs and combine source-range sets",triggers:[{tool:"select"}]})]),t.registerTool(Ae({name:"select",label:"select",exposure:"direct",namespace:{name:"ide_select",description:"Derive exact source boundaries from existing targets."},annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},description:"Use select to derive verified text boundaries and positions, combine source-local range sets, and navigate normalized JavaScript/TypeScript constructs and named parts, without JSX/TSX. AST enclosing matches the full seed and counts levels within the requested category. Navigation skips parser-only wrappers; filters do not change relationships. Navigation requires exact named syntax nodes; parts require a node with that supported part. Supported optional parts may be absent; unsupported parts are errors with available names. syntax describes the result category, not edit authority. Text operations apply per region; range/lines require one source. Geometry matches by source and snapshot, not array position; within retains whole candidates, intersection clips, difference subtracts, and merge explicitly joins overlaps or optional adjacency without filling gaps. Points use included starts and excluded ends. Bounds are strict UTF-16; surrogate-pair and CRLF splits are errors. Expansion and merge retain input associations. Results keep strict snapshots, completeness and individually consumable items; preview truncation does not clip the whole target. elementExtent derives exact JS/TS argument/parameter boundaries, optionally including owned commas/whitespace; adjacent comments refuse around extents. It does not repair destination syntax. ownBody and semantic identity are not implemented.",promptSnippet:"Derive text and AST boundaries, navigate constructs and combine source-range sets",promptGuidelines:["Use Search for predicate matches and existing captures; use Select when a target needs new text or structural boundaries.","Compare the enclosing owner of each inner match with the original function when checking a condition in that function's own body."],parameters:nt,outputSchema:rt,renderCall(s,r,o){return de(o.lastComponent,{tool:"select",primary:{text:Gt(s.operation),color:"accent"},qualifiers:[{text:typeof s.path=="string"&&!s.path.startsWith("RESULT#")?s.path:"in result scope"}],expanded:o.expanded},r)},renderResult(s,r,o){let a=s.details;return a?new ce(a,o,r.expanded):new Ut(s.content.flatMap(c=>c.type==="text"?[c.text]:[]).join(`
|
|
15
|
+
`),0,0)},async execute(s,r,o,a,c){try{o?.throwIfAborted();let l=p(async m=>{if(typeof m=="string"&&!m.startsWith("RESULT#")){let x=await e.read({path:m},{cwd:c.cwd,...o!==void 0&&{signal:o}},"script");if(x.isError)throw new Error("Select could not read this source.");m=x.script}return n.resolve(m,c.cwd)},"resolve"),d=await l(r.path),u=r.operation,b=ot(u)&&"scopes"in u?await l(u.scopes):{targets:[],complete:!0},y={targets:[...d.targets,...b.targets],complete:d.complete&&b.complete};await n.verify(y,o);let g=ot(u)?Qe(d,u,b,o):u.kind==="object"||u.kind==="part"||u.kind==="navigate"||u.kind==="elementExtent"?await Je(d,u,c.cwd,o):Ke(d,u,o);await n.verify(y,o),o?.throwIfAborted();let f=g.regions.map(m=>({...m.target,ranges:[m.range]})),h={kind:"selection",target:n.register(f,c.cwd,y.complete),complete:y.complete,totalItems:g.regions.length,missingInputs:g.missingInputs,truncated:g.regions.length>100,items:g.regions.slice(0,100).map(m=>{let x=m.text.slice(0,1e3).replace(/[\uD800-\uDBFF]$/u,"");return{target:n.register([{...m.target,ranges:[m.range]}],c.cwd,y.complete),source:m.target.source,range:v(m.range),origins:m.origins,...m.syntax?{syntax:m.syntax}:{},preview:x,textTruncated:x.length<m.text.length}})};return C({content:[{type:"text",text:JSON.stringify(h)}],details:He(g.regions,y.complete,g.missingInputs,c.cwd)},j,{status:"success",data:h,errors:[]})}catch(l){if(o?.aborted)throw l;return C({content:[{type:"text",text:l instanceof Error?l.message:String(l)}],details:void 0},j,{status:"error",errors:[me(l,"SELECT_FAILED")]})}}},new ve))}p(st,"registerSelect");var Bt=ue({kind:"code-view",label:"AST"});async function at(t){let e=new Le,n=Ne(e),s={protocol:se,apiVersion:ae,id:"ast",async setup(o){o.addResolver({resolver:Te(),renderResult:Bt}),o.addHandler({stage:"read",when:{resolvedBy:"ast",contentKind:"text"},handler:Y()}),o.addView({view:"ast",presenter:n});let a=Ee();o.addOutputReducer(U);let c=Pe();o.addHandler({stage:"post-read",async handler(l){let d=await a(l);return d.kind==="return"?d:c(d.context)}}),o.describe('ast:<path> \u2014 compact declaration outline. views: ["ast"] \u2014 scope boundaries alongside source text. Oversized code reads may return an outline with source line numbers; offset/limit read a smaller source range.'),await st(t,o)}},r={protocol:ge,apiVersion:he,id:"ast",setup(o){o.addAnchorResolver({resolver:_e(e),kind:ye,type:"auxiliary"}),o.addTextPresenter({presenter:n})}};await Promise.all([ie(t,s),oe(t,Oe),be(t,r),we(t,{protocol:Se,apiVersion:xe,id:"ast-search",setup(o){o.addResolver({resolver:Be(o.registerSelection)}),o.describe("Search code structure with ast:<pattern>, using source-code syntax and placeholders such as $NAME for one node and $$$BODY for several nodes. path, include and exclude narrow the search. Use returned SEARCH# references to read, replace, copy, move or delete exact AST matches, including multiline nodes. A single :match reference becomes stale after its file changes; :all:match reruns the original structural query. Incomplete results do not provide all selections. Use each match's captures.NAME array in native Codemode as Search/replace input. Single captures contain one node; multi captures retain provider nodes, including punctuation. Strict result scopes return only wholly contained matches. These edits do not update imports or references.")}})])}p(at,"registerAst");export{at as default};
|