pi-agent-ide 0.6.4 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +2 -2
- package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
- package/dist/chunk-2TRHFMCZ.js +11 -0
- package/dist/{chunk-WJTHY6AG.js → chunk-4GCWGE2C.js} +1 -1
- package/dist/chunk-4XMY4H4V.js +1 -0
- package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
- package/dist/{chunk-QEJGED4V.js → chunk-76ZK5ODR.js} +2 -2
- package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
- package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
- package/dist/chunk-CWD4O5PM.js +3 -0
- package/dist/chunk-D3WTDA6V.js +2 -0
- package/dist/chunk-EAZGN5ND.js +7 -0
- package/dist/chunk-GXEGY7GV.js +1 -0
- package/dist/chunk-HZEY4GT4.js +2 -0
- package/dist/chunk-LEEQIQ7D.js +28 -0
- package/dist/chunk-NRZO5KJT.js +9 -0
- package/dist/chunk-OMVRLWMX.js +5 -0
- package/dist/{chunk-VBICI5YA.js → chunk-PGIVHICI.js} +1 -1
- package/dist/{chunk-FBOW7XOV.js → chunk-PKKDDIWW.js} +1 -1
- package/dist/chunk-PNU3E7IO.js +3 -0
- package/dist/chunk-PS2B6THP.js +3 -0
- package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
- package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
- package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
- package/dist/chunk-VMTR74FF.js +2 -0
- package/dist/{chunk-HPUAIWIH.js → chunk-WMO6RNE2.js} +1 -1
- package/dist/chunk-WU6ZK6YD.js +1 -0
- package/dist/{chunk-GIRAEVUJ.js → chunk-XH5WN5XA.js} +1 -1
- package/dist/chunk-XYS4FSCC.js +12 -0
- package/dist/chunk-YP46DVVP.js +2 -0
- package/dist/entry-11.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-25.js +2 -2
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +2 -2
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +12 -9
- package/dist/entry-33.js +1 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-41.js +1 -1
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +13 -14
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +3 -6
- package/dist/entry-51.js +11 -9
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-57.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +0 -1
- package/dist/entry-62.js +1 -0
- package/dist/entry-63.js +0 -1
- package/dist/entry-64.js +1 -0
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-71.js +0 -1
- package/dist/entry-72.js +1 -0
- package/dist/entry-73.js +0 -1
- package/dist/entry-74.js +1 -0
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -1
- package/dist/entry-77.js +66 -1
- package/dist/entry-78.js +14 -325
- package/dist/entry-79.js +2 -18
- package/dist/entry-80.js +1 -2
- package/dist/entry-81.js +1 -1
- package/dist/entry-82.js +5 -1
- package/dist/entry-83.js +3 -5
- package/dist/entry-84.js +1 -3
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +14 -9
- package/docs/agent-guides/editing.md +38 -33
- package/docs/agent-guides/git-changes.md +1 -1
- package/docs/agent-guides/read-resources.md +8 -4
- package/docs/agent-guides/search-code.md +34 -2
- package/docs/agent-guides/select-code.md +115 -0
- package/docs/configuration.md +12 -17
- package/docs/development.md +2 -1
- package/docs/releases.md +1 -1
- package/docs/research/apply-native-capability-matrix.md +174 -0
- package/docs/research/apply-read-latency.md +2 -0
- package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
- package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
- package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/research/native-codemode-batching.md +1 -1
- package/docs/structured-results.md +30 -38
- package/docs/tools.md +11 -11
- package/docs/user-hooks.md +1 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/index.ts +7 -6
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/index.ts +4 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +15 -10
- package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +10 -5
- package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +142 -27
- package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +268 -0
- package/node_modules/pi-agent-ide-changes/index.ts +6 -21
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lsp/index.ts +5 -5
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +40 -3
- package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -1
- package/node_modules/pi-agent-read/src/core/extension.ts +18 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +50 -35
- package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +17 -3
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +10 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +407 -0
- package/node_modules/pi-agent-resource/src/tool-result.ts +13 -1
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
- package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
- package/node_modules/pi-agent-search/src/api/search.ts +28 -0
- package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
- package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
- package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
- package/node_modules/pi-agent-search-text/index.ts +3 -1
- package/node_modules/pi-agent-search-text/package.json +7 -6
- package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
- package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/index.ts +65 -4
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-editor/index.ts +0 -5
- package/node_modules/pi-agent-text-editor/package.json +26 -31
- package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +22 -5
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -14
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +86 -154
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +3 -0
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
- package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
- package/node_modules/pi-agent-web/index.ts +7 -3
- package/node_modules/pi-agent-web/package.json +8 -8
- package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
- package/node_modules/pi-agent-web/src/search.ts +111 -2
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/package.json +35 -36
- package/src/composite/module-labels.ts +1 -1
- package/src/composite/preferences.ts +0 -5
- package/src/composite/text-results.ts +221 -0
- package/src/documentation/extension.ts +11 -9
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/index.ts +4 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +7 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +40 -3
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -1
- package/src/extensions/pi-agent-read/src/core/extension.ts +18 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +50 -35
- package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +5 -3
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +17 -3
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
- package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
- package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
- package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
- package/src/extensions/pi-agent-text-editor/index.ts +0 -5
- package/src/extensions/pi-agent-text-editor/package.json +26 -31
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +65 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +22 -5
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -14
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +217 -30
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +86 -154
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +238 -244
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -11
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/src/pi-agent-ide.ts +4 -7
- package/src/plugins/pi-agent-ide-ast/package.json +15 -10
- package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +10 -5
- package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +142 -27
- package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +268 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +6 -21
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/src/plugins/pi-agent-ide-debugger/index.ts +5 -3
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +5 -3
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lsp/index.ts +5 -5
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -45
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
- package/src/plugins/pi-agent-ide-vision/index.ts +31 -4
- package/dist/chunk-2P2OGO3G.js +0 -2
- package/dist/chunk-5J43L2RL.js +0 -11
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/chunk-7AVXUV4A.js +0 -7
- package/dist/chunk-7WCZOO5I.js +0 -1
- package/dist/chunk-BAYETTZZ.js +0 -16
- package/dist/chunk-BVK5A7ED.js +0 -28
- package/dist/chunk-F7NVAC4Q.js +0 -0
- package/dist/chunk-FZBCKIJJ.js +0 -1
- package/dist/chunk-I5JLCFUX.js +0 -1
- package/dist/chunk-KUPHNMUK.js +0 -2
- package/dist/chunk-MIZAFRDR.js +0 -1
- package/dist/chunk-PJPA5EEE.js +0 -2
- package/dist/chunk-PXWDDBBC.js +0 -0
- package/dist/chunk-SILJ3OL4.js +0 -9
- package/dist/chunk-TQZBVOTT.js +0 -5
- package/dist/chunk-VWW3RLUX.js +0 -12
- package/dist/chunk-YHUTTZC6.js +0 -2
- package/dist/chunk-ZODCBFBL.js +0 -2
- package/dist/entry-87.js +0 -1
- package/docs/agent-guides/apply.md +0 -333
- package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
- package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
- package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
- /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
- /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
- /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
|
@@ -1,72 +1,119 @@
|
|
|
1
1
|
import { searchSymbols } from "./lsp/symbol-search.js";
|
|
2
|
-
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { selectionData, renderSearchMatches } from "pi-agent-search/api/search";
|
|
3
4
|
import type { LspManager } from "./lsp/manager.js";
|
|
4
5
|
import type { SymbolHit } from "./lsp/symbol-search.js";
|
|
5
|
-
import type { SearchResolver } from "pi-agent-search/api/search";
|
|
6
|
+
import type { SearchPluginApi, SearchResolver } from "pi-agent-search/api/search";
|
|
6
7
|
|
|
8
|
+
/** Expose strict LSP discovery and explicit reference navigation as shared source targets. */
|
|
7
9
|
export function createLspSearchResolver(
|
|
8
10
|
managerFor: (cwd: string) => Promise<LspManager>,
|
|
11
|
+
registerSelection: SearchPluginApi["registerSelection"],
|
|
9
12
|
): SearchResolver {
|
|
10
13
|
return {
|
|
11
14
|
id: "symbols",
|
|
15
|
+
supportsResultScope: true,
|
|
12
16
|
// Workspace symbol backends may read beyond the requested path.
|
|
13
17
|
readResources: (request) => (request.query.startsWith("symbols:") ? undefined : []),
|
|
14
18
|
toScriptData(payload) {
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
kind: "custom",
|
|
18
|
-
resolverId: "symbols",
|
|
19
|
-
value: {
|
|
20
|
-
query,
|
|
21
|
-
hits: hits.map((hit) => ({
|
|
22
|
-
source: hit.filePath,
|
|
23
|
-
lineNumber: hit.lineNumber,
|
|
24
|
-
column: hit.column,
|
|
25
|
-
kind: hit.kind,
|
|
26
|
-
name: hit.name,
|
|
27
|
-
})),
|
|
28
|
-
},
|
|
29
|
-
};
|
|
19
|
+
return (payload as { readonly data: unknown }).data;
|
|
30
20
|
},
|
|
31
21
|
async tryResolve(request, context) {
|
|
32
|
-
if (!request.query.startsWith("symbols:")) {
|
|
33
|
-
return { kind: "not-handled" };
|
|
34
|
-
}
|
|
35
|
-
|
|
22
|
+
if (!request.query.startsWith("symbols:")) return { kind: "not-handled" };
|
|
36
23
|
const query = request.query.slice("symbols:".length).trim();
|
|
37
|
-
|
|
38
|
-
if (query.length === 0) {
|
|
24
|
+
if (query.length === 0)
|
|
39
25
|
return { kind: "failed", error: new Error("symbols: query must not be empty") };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
26
|
const manager = await managerFor(context.cwd);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
27
|
+
const collect = (signal?: AbortSignal) =>
|
|
28
|
+
searchSymbols(
|
|
29
|
+
query,
|
|
30
|
+
context.cwd,
|
|
31
|
+
request.limit ?? 100,
|
|
32
|
+
signal,
|
|
33
|
+
{ ...request, ...(context.scope === undefined ? {} : { resultScope: context.scope }) },
|
|
34
|
+
manager,
|
|
35
|
+
);
|
|
36
|
+
const found = await collect(context.signal);
|
|
37
|
+
const session = await registerSelection(
|
|
38
|
+
{
|
|
39
|
+
request,
|
|
40
|
+
matches: found.hits,
|
|
41
|
+
complete: found.complete,
|
|
42
|
+
refresh: async (signal) => {
|
|
43
|
+
const refreshed = await collect(signal);
|
|
44
|
+
return { matches: refreshed.hits, complete: refreshed.complete };
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
context,
|
|
50
48
|
);
|
|
51
|
-
|
|
49
|
+
const data = selectionData(found.hits, found.complete, session.id, session);
|
|
50
|
+
return {
|
|
51
|
+
kind: "resolved",
|
|
52
|
+
payload: {
|
|
53
|
+
query,
|
|
54
|
+
hits: found.hits,
|
|
55
|
+
sessionId: session.id,
|
|
56
|
+
complete: found.complete,
|
|
57
|
+
navigation: request.navigation,
|
|
58
|
+
data: {
|
|
59
|
+
...data,
|
|
60
|
+
matches: data.matches.map((match, index) => ({
|
|
61
|
+
...match,
|
|
62
|
+
role: found.hits[index]?.role,
|
|
63
|
+
symbol: found.hits[index]?.symbol,
|
|
64
|
+
})),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
52
68
|
},
|
|
53
|
-
|
|
54
|
-
const
|
|
69
|
+
renderResult(result, options, theme) {
|
|
70
|
+
const data = result.details as {
|
|
71
|
+
hits: readonly SymbolHit[];
|
|
72
|
+
complete: boolean;
|
|
73
|
+
navigation?: "references";
|
|
74
|
+
cwd: string;
|
|
75
|
+
};
|
|
76
|
+
return renderSearchMatches(
|
|
77
|
+
data.hits,
|
|
78
|
+
data.complete,
|
|
79
|
+
theme,
|
|
80
|
+
options.expanded,
|
|
81
|
+
data.cwd,
|
|
82
|
+
data.navigation === "references"
|
|
83
|
+
? ["LSP reference navigation · may leave input scope"]
|
|
84
|
+
: [],
|
|
85
|
+
data.hits.map((hit) => `${hit.role} ${hit.symbol.name}`),
|
|
86
|
+
);
|
|
87
|
+
},
|
|
88
|
+
format(payload, context) {
|
|
89
|
+
const result = payload as {
|
|
55
90
|
readonly query: string;
|
|
91
|
+
readonly sessionId: string;
|
|
56
92
|
readonly hits: readonly SymbolHit[];
|
|
93
|
+
readonly complete: boolean;
|
|
94
|
+
readonly navigation?: "references";
|
|
57
95
|
};
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
? "
|
|
61
|
-
:
|
|
96
|
+
const heading =
|
|
97
|
+
result.navigation === "references"
|
|
98
|
+
? "LSP reference navigation (may leave input scope)"
|
|
99
|
+
: "LSP symbols inside scope";
|
|
100
|
+
const lines =
|
|
101
|
+
result.hits.length === 0
|
|
102
|
+
? ["No symbols found."]
|
|
103
|
+
: result.hits
|
|
104
|
+
.slice(0, 100)
|
|
62
105
|
.map(
|
|
63
106
|
(hit, index) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
107
|
+
`SEARCH#${result.sessionId}:${index + 1}:match ${path.relative(context.cwd, hit.source)}:${hit.lineNumber}:${hit.startColumn + 1} ${hit.role} ${hit.symbol.name} · declared at ${path.relative(context.cwd, hit.symbol.source)}:${hit.symbol.range.startLine}:${hit.symbol.range.startColumn + 1}`,
|
|
108
|
+
);
|
|
109
|
+
if (result.complete && result.hits.length)
|
|
110
|
+
lines.unshift(`SEARCH#${result.sessionId}:all:match selects all exact symbol matches.`);
|
|
111
|
+
if (!result.complete) lines.push("Incomplete results; not a complete edit scope.");
|
|
112
|
+
if (result.hits.length > 100) lines.push("Preview shortened; full source targets retained.");
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: [heading, ...lines].join("\n") }],
|
|
115
|
+
details: { ...result, cwd: context.cwd },
|
|
116
|
+
};
|
|
70
117
|
},
|
|
71
118
|
};
|
|
72
119
|
}
|
|
@@ -185,9 +185,11 @@ export async function registerTerminalResources(
|
|
|
185
185
|
}
|
|
186
186
|
},
|
|
187
187
|
});
|
|
188
|
-
api.describe(
|
|
189
|
-
"shell:<session> — terminal status and a bounded output tail with a full-log path when truncated.
|
|
190
|
-
|
|
188
|
+
api.describe({
|
|
189
|
+
path: "shell:<session> — terminal status and a bounded output tail with a full-log path when truncated.",
|
|
190
|
+
views:
|
|
191
|
+
"On shell:<session>, image[:scale=S] returns the virtual terminal screen; sequence[:duration=D,interval=I,scale=S] returns ordered PNG frames. Defaults: D=2 seconds, I=0.5 seconds, S=1. Scale satisfies 0 < S <= 1; sequences require 0 < D <= 10, I > 0, and at most 20 frames (floor(D/I)+1). Terminal captures do not support region or image grid selection; offset/limit do not crop their frames.",
|
|
192
|
+
});
|
|
191
193
|
},
|
|
192
194
|
} satisfies ReadPlugin;
|
|
193
195
|
|
|
@@ -268,7 +270,7 @@ export async function registerTerminalResources(
|
|
|
268
270
|
content: [{ type: "text", text: message }],
|
|
269
271
|
details: event.details,
|
|
270
272
|
},
|
|
271
|
-
mutationDataSchema,
|
|
273
|
+
mutationDataSchema(event.toolName),
|
|
272
274
|
{
|
|
273
275
|
status: "error",
|
|
274
276
|
errors: [resultError(message, "UNSUPPORTED_OPERATION", requestedSource)],
|
|
@@ -302,7 +304,7 @@ export async function registerTerminalResources(
|
|
|
302
304
|
changedLines: [],
|
|
303
305
|
} satisfies TerminalActionDetails,
|
|
304
306
|
},
|
|
305
|
-
mutationDataSchema,
|
|
307
|
+
mutationDataSchema(event.toolName),
|
|
306
308
|
{
|
|
307
309
|
status: "success",
|
|
308
310
|
errors: [],
|
|
@@ -321,7 +323,7 @@ export async function registerTerminalResources(
|
|
|
321
323
|
],
|
|
322
324
|
details: { source: requestedSource, deleted: false },
|
|
323
325
|
},
|
|
324
|
-
mutationDataSchema,
|
|
326
|
+
mutationDataSchema(event.toolName),
|
|
325
327
|
{
|
|
326
328
|
status: "error",
|
|
327
329
|
errors: [resultError(error, "TERMINAL_DELETE_FAILED", requestedSource)],
|
|
@@ -5,12 +5,11 @@ import {
|
|
|
5
5
|
type SearchPlugin,
|
|
6
6
|
} from "pi-agent-search/api/plugin-protocol";
|
|
7
7
|
import type { SearchRequest, SearchSelectionMatch } from "pi-agent-search/api/search";
|
|
8
|
-
import { selectionData } from "pi-agent-search/api/search";
|
|
8
|
+
import { selectionData, renderSearchMatches } from "pi-agent-search/api/search";
|
|
9
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
9
10
|
|
|
10
11
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
11
|
-
import { truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
12
12
|
|
|
13
|
-
import { renderTerminalAction } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
|
|
14
13
|
import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
|
|
15
14
|
import type { TerminalSessionSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
|
|
16
15
|
|
|
@@ -91,48 +90,23 @@ function terminalSearchResolver(manager: TerminalSessionManager) {
|
|
|
91
90
|
renderResult(
|
|
92
91
|
result: { details: unknown },
|
|
93
92
|
options: { readonly expanded?: boolean },
|
|
94
|
-
theme:
|
|
93
|
+
theme: Theme,
|
|
95
94
|
) {
|
|
96
95
|
const details = result.details;
|
|
97
96
|
const payload = isRecord(details) ? parsePayload(details.payload) : parsePayload(undefined);
|
|
98
|
-
|
|
99
|
-
payload.
|
|
100
|
-
|
|
101
|
-
JSON.stringify(payload.query),
|
|
102
|
-
payload.matches.slice(-6).map((match) => `${match.lineNumber}: ${match.lineText}`),
|
|
97
|
+
return renderSearchMatches(
|
|
98
|
+
payload.matches,
|
|
99
|
+
false,
|
|
103
100
|
theme,
|
|
101
|
+
options.expanded === true,
|
|
102
|
+
undefined,
|
|
103
|
+
[`Retained terminal output · ${payload.snapshot.status} · read-only`],
|
|
104
104
|
);
|
|
105
|
-
return new TerminalSearchPanel(content, options.expanded === true, theme);
|
|
106
105
|
},
|
|
107
106
|
};
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/** Keep terminal search readable without changing the complete agent-facing result. */
|
|
113
|
-
export class TerminalSearchPanel implements Component {
|
|
114
|
-
public constructor(
|
|
115
|
-
private readonly content: Component,
|
|
116
|
-
private readonly expanded: boolean,
|
|
117
|
-
private readonly theme: Parameters<typeof renderTerminalAction>[4],
|
|
118
|
-
) {}
|
|
119
|
-
|
|
120
|
-
public render(width: number): string[] {
|
|
121
|
-
const rows = this.content.render(width);
|
|
122
|
-
if (this.expanded || rows.length <= COMPACT_TERMINAL_SEARCH_ROWS) return rows;
|
|
123
|
-
const shown = COMPACT_TERMINAL_SEARCH_ROWS - 1;
|
|
124
|
-
const omitted = String(rows.length - shown);
|
|
125
|
-
const fullHint = `… ${omitted} visual rows omitted · ctrl+o to expand`;
|
|
126
|
-
const hint =
|
|
127
|
-
visibleWidth(fullHint) <= width ? fullHint : `… ${omitted} visual rows omitted · ctrl+o`;
|
|
128
|
-
return [...rows.slice(0, shown), this.theme.fg("muted", truncateToWidth(hint, width))];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public invalidate(): void {
|
|
132
|
-
this.content.invalidate();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
109
|
+
/** Find literal matches in retained output without claiming a complete source scope. */
|
|
136
110
|
export function findTerminalMatches(
|
|
137
111
|
snapshot: TerminalSessionSnapshot,
|
|
138
112
|
request: SearchRequest,
|
|
@@ -89,7 +89,7 @@ export function registerTerminalTools(
|
|
|
89
89
|
label: profile.displayName,
|
|
90
90
|
promptSnippet: `Execute ${profile.displayName} commands in synchronous or background terminal sessions`,
|
|
91
91
|
promptGuidelines: [
|
|
92
|
-
`Do not use ${toolName} commands or scripts to edit files. Use
|
|
92
|
+
`Do not use ${toolName} commands or scripts to edit files. Use the standalone editing tools instead. Commands that inherently generate files, such as formatters and code generators, are allowed.`,
|
|
93
93
|
],
|
|
94
94
|
description: `Use ${toolName} to execute a command in the user's configured ${profile.displayName} shell (${profile.executable}). Every call creates an addressable terminal session. Set background to true to continue without waiting. A foreground wait automatically returns the live session as background on timeout, a stable interactive prompt, or turn abort. Background completion is delivered automatically and wakes the agent. Silent background sessions wake an idle agent once for inspection after two minutes, with no further stale reminders for that session. Sessions survive extension reloads and keep the same shell: source. Output uses the shared Read limits, keeps the tail, and links a complete log file when truncated.`,
|
|
95
95
|
parameters: runParameters,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { ResultPanel } from "pi-agent-tool-ui";
|
|
2
3
|
import { connectAgentDocumentation, loadPackagedAgentGuide } from "pi-agent-documentation";
|
|
3
4
|
|
|
4
5
|
import type { BuiltinExtensionContext } from "#src/composite/selection.js";
|
|
@@ -126,10 +127,18 @@ export default async function registerVision(
|
|
|
126
127
|
return { kind: "continue", context };
|
|
127
128
|
},
|
|
128
129
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
api.describe({
|
|
131
|
+
path: () =>
|
|
132
|
+
`process:PID — process metadata. window:PID — capture a window of an IDE-owned or allowlisted process${pi.getFlag("pi-agent-ide-vision-arbitrary-windows") === true ? "; arbitrary windows are enabled" : "; other processes require --pi-agent-ide-vision-arbitrary-windows"}. display: or display:#N — display capture with a zero-based index; ${pi.getFlag("pi-agent-ide-vision-displays") === true ? "enabled" : "requires --pi-agent-ide-vision-displays"}. HTTP(S) URLs accept image or sequence screenshots.`,
|
|
133
|
+
views: () => {
|
|
134
|
+
const defaults = getVisionDefaults();
|
|
135
|
+
return `image or image:scale=S,region=X,Y,W,H — one screenshot. sequence or sequence:duration=D,interval=I,scale=S,region=X,Y,W,H — timed frames. Only one image/sequence view per request. duration and interval are seconds and only valid for sequence: 0 < D <= 10, I > 0, at most 20 frames (floor(D/I)+1). Scale satisfies 0 < S <= 1. Region uses normalized x,y,width,height: x,y >= 0, width,height > 0, and the rectangle must fit in 0..1; crop runs before scaling. Settings are optional; defaults: duration=${defaults.durationSeconds}, interval=${defaults.intervalSeconds}, scale=${defaults.scale}.`;
|
|
136
|
+
},
|
|
137
|
+
offset:
|
|
138
|
+
"For window:, display: and HTTP(S) image/sequence captures, a non-negative integer zero-based row-major grid cell index in the transformed image. Requires limit; omit to select cell 0 when limit is set.",
|
|
139
|
+
limit:
|
|
140
|
+
"For window:, display: and HTTP(S) image/sequence captures, a positive integer square grid cell size in output pixels. Omit both offset and limit for the bounded transformed image.",
|
|
141
|
+
});
|
|
133
142
|
},
|
|
134
143
|
}),
|
|
135
144
|
connectSearchPlugin(pi, {
|
|
@@ -166,6 +175,24 @@ export default async function registerVision(
|
|
|
166
175
|
.slice(0, Math.min(request.limit ?? 50, 100));
|
|
167
176
|
return { kind: "resolved" as const, payload: matches };
|
|
168
177
|
},
|
|
178
|
+
renderResult(result, options, theme) {
|
|
179
|
+
const data = result.details as {
|
|
180
|
+
processes: Awaited<ReturnType<typeof listProcesses>>;
|
|
181
|
+
};
|
|
182
|
+
return new ResultPanel(
|
|
183
|
+
{
|
|
184
|
+
summary: `${data.processes.length} processes shown`,
|
|
185
|
+
rows: data.processes.length
|
|
186
|
+
? data.processes.map((item) => ({
|
|
187
|
+
kind: "note",
|
|
188
|
+
text: `${item.pid} ${item.command}`,
|
|
189
|
+
}))
|
|
190
|
+
: [{ kind: "note", text: "No matching processes" }],
|
|
191
|
+
},
|
|
192
|
+
theme,
|
|
193
|
+
options.expanded,
|
|
194
|
+
);
|
|
195
|
+
},
|
|
169
196
|
format(payload) {
|
|
170
197
|
const processes = payload as Awaited<ReturnType<typeof listProcesses>>;
|
|
171
198
|
return {
|
package/dist/chunk-2P2OGO3G.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{a as o}from"./chunk-EI7MMDWY.js";import{AsyncLocalStorage as ae}from"node:async_hooks";function X(){return{pending:new Set,active:new ae}}o(X,"createSchedulerState");function ue(e,t){return e===void 0||t===void 0?!0:e.some(n=>t.some(r=>(n.mode==="write"||r.mode==="write")&&(n.resource==="*"||r.resource==="*"||n.resource===r.resource||n.recursive===!0&&r.resource.startsWith(n.resource.endsWith("/")?n.resource:`${n.resource}/`)||r.recursive===!0&&n.resource.startsWith(r.resource.endsWith("/")?r.resource:`${r.resource}/`))))}o(ue,"conflicts");function de(e,t,n){if(t===void 0||!n&&t.some(s=>s.mode!=="read"))return!1;if(e===void 0)return!0;let r=new Map;for(let s of t){let i=s.group??s.resource;r.set(i,[...r.get(i)??[],s])}return[...r.values()].every(s=>s.some(i=>e.some(a=>(i.mode==="read"||a.mode==="write")&&(a.resource==="*"||i.resource===a.resource&&(i.recursive!==!0||a.recursive===!0)||a.recursive===!0&&i.resource.startsWith(a.resource.endsWith("/")?a.resource:`${a.resource}/`)))))}o(de,"coveredAccess");async function le(e,t){if(t===void 0)return await e;t.throwIfAborted();let n,r=new Promise((s,i)=>{n=o(()=>i(t.reason),"abort"),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{t.removeEventListener("abort",n)}}o(le,"waitForDependencies");var I=class e{constructor(t=X()){this.state=t}static{o(this,"ResourceScheduler")}run(t,n,r,s={}){let i=Promise.resolve(t),a=this.state.active.getStore();if(a?.open){let S=i.then(R=>{if(r?.throwIfAborted(),!de(a.accesses,R,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 R});a.nested??=new e;let f=a.nested.run(S,n,r,{allowNestedWrites:a.allowNestedWrites});return a.children.add(f),f.then(()=>a.children.delete(f),()=>a.children.delete(f)),f}let m=[...this.state.pending],p=i.catch(()=>{}),w,d=new Promise(S=>{w=S}),E={accesses:p,done:d};return this.state.pending.add(E),(async()=>{try{r?.throwIfAborted();let S=await le(i.then(async R=>(await Promise.all(m.map($=>Promise.race([$.done,$.accesses.then(ce=>ue(R,ce)?$.done:void 0)]))),R)),r);r?.throwIfAborted();let f={accesses:S,children:new Set,open:!0,allowNestedWrites:s.allowNestedWrites===!0};try{return await this.state.active.run(f,n)}finally{for(;f.children.size>0;)await Promise.allSettled([...f.children]);f.open=!1}}finally{this.state.pending.delete(E),w()}})()}},pe=Symbol.for("pi-agent-resource.resource-scheduler-state"),fe=globalThis,Ce=fe[pe]??=X(),me=new I(Ce);import{realpath as ye,stat as ve}from"node:fs/promises";import N from"node:path";import{fileURLToPath as ge}from"node:url";async function Q(e,t,n){if(/^[a-z][a-z\d+.-]*:/iu.test(e)&&!/^[a-z]:[\\/]/iu.test(e)&&!e.startsWith("file:"))return[{resource:e,mode:n}];let r=N.resolve(t,e.startsWith("file:")?ge(e):e),[s,i]=await Promise.allSettled([ye(r),ve(r,{bigint:!0})]),a;if(s.status==="fulfilled")a=s.value;else{let d=s.reason;if(!(d instanceof Error)||!("code"in d)||d.code!=="ENOENT")throw d;let E=N.dirname(r);if(E===r)a=r;else{let f=(await Q(E,t,n)).find(R=>R.resource.startsWith("file:"));a=N.join(f?.resource.slice(5)??E,N.basename(r))}}let m=a.split(N.sep).join("/"),p=`file:${process.platform==="win32"?m.toLowerCase():m}`,w=[{resource:p,group:p,mode:n}];if(i.status==="fulfilled"){let d=i.value;d.isDirectory()&&(w[0]={resource:p,group:p,mode:n,recursive:!0}),d.ino!==0n&&w.push({resource:`inode:${d.dev}:${d.ino}`,group:p,mode:n,recursive:d.isDirectory()})}else{let d=i.reason;if(!(d instanceof Error)||!("code"in d)||d.code!=="ENOENT")throw d}return w}o(Q,"resourceAccesses");import{Type as l}from"typebox";import{Value as Re}from"typebox/value";var W=l.Object({code:l.String(),message:l.String(),source:l.Optional(l.String())},{additionalProperties:!1});function Z(e){return l.Union([l.Object({status:l.Literal("success"),data:e,errors:l.Array(W,{maxItems:0})},{additionalProperties:!1}),l.Object({status:l.Union([l.Literal("error"),l.Literal("partial")]),data:l.Optional(e),errors:l.Array(W,{minItems:1})},{additionalProperties:!1})])}o(Z,"structuredResultSchema");var ee=1024*1024;function H(e){let t=new Set,n=o(r=>{if(!(r===null||typeof r=="string"||typeof r=="boolean")&&!(typeof r=="number"&&Number.isFinite(r))){if(typeof r!="object"||t.has(r))throw new TypeError("Structured data must be finite, acyclic JSON");if(!Array.isArray(r)&&Object.getPrototypeOf(r)!==Object.prototype&&Object.getPrototypeOf(r)!==null)throw new TypeError("Structured data must not contain classes or raw byte buffers");t.add(r);for(let s of Array.isArray(r)?r:Object.values(r))n(s);t.delete(r)}},"visit");if(n(e),Buffer.byteLength(JSON.stringify(e))>ee)throw new RangeError("Structured data exceeds 1 MiB; return a smaller window or a full-result reference")}o(H,"assertJsonData");function te(e,t="EXECUTION_FAILED",n){return{code:typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="string"?e.code:t,message:e instanceof Error?e.message:String(e),...n===void 0?{}:{source:n}}}o(te,"resultError");function he(e,t,n){try{if(H(n),!Re.Check(Z(t),n))throw new TypeError("Result adapter returned data outside its public schema");return{...e,structuredContent:n,isError:n.status!=="success"}}catch(r){let s=te(r,"INVALID_STRUCTURED_RESULT"),i={status:"error",errors:[s]};return H(i),{...e,content:[...e.content,{type:"text",text:s.message}],structuredContent:i,isError:!0}}}o(he,"withStructuredResult");function Te(e,t){if(t.length===0)return;let n=e.trim();if(n.length===0||/[\r\n]/u.test(n))throw new TypeError("Content provider summary must be one non-empty line");return[n,...t.map(({description:r})=>r)].join(`
|
|
2
|
-
`)}o(Te,"renderContentDescription");import{Type as u}from"typebox";import{Value as Pe}from"typebox/value";import{Type as c}from"typebox";import{Value as we}from"typebox/value";var C={additionalProperties:!0},k=c.Function([],c.Unknown()),y=c.String({minLength:1}),Ee=c.Object({type:c.Literal("text"),text:c.String(),textSignature:c.Optional(c.String())},C),Se=c.Object({type:c.Literal("image"),data:c.String(),mimeType:c.String()},C),be=c.Object({type:c.Literal("custom"),kind:y,data:c.Unknown()},C),Oe=c.Array(c.Union([Ee,Se,be]),{minItems:1}),ne=c.Union([c.Object({source:y,link:c.Optional(y),read:k,write:c.Optional(c.Never())},C),c.Object({source:y,link:c.Optional(y),read:c.Optional(c.Never()),write:k},C),c.Object({source:y,link:c.Optional(y),read:k,write:k},C)]),Ae=c.Object({id:y,tryResolve:k},C),xe=c.Union([c.Object({kind:c.Literal("not-handled")},C),c.Object({kind:c.Literal("resolved"),resource:ne},C),c.Object({kind:c.Literal("failed"),error:c.Unknown()},C)]);function q(e){return _(Oe,e)?D(()=>e.every(t=>t.type!=="text"||!("textSignature"in t)||typeof t.textSignature=="string")):!1}o(q,"isAgentContent");function re(e){return _(ne,e)?D(()=>{let t=e,n=!("read"in t)||typeof t.read=="function",r=!("write"in t)||typeof t.write=="function";return n&&r}):!1}o(re,"isResource");function Ne(e){return _(Ae,e)}o(Ne,"isResourceResolver");function ke(e){return _(xe,e)?D(()=>{let t=e;return t.kind!=="resolved"||re(t.resource)}):!1}o(ke,"isResourceResolutionAttempt");function _(e,t){return D(()=>we.Check(e,t))}o(_,"safeCheck");function D(e){try{return e()}catch{return!1}}o(D,"safeEvaluate");var v={additionalProperties:!0},je=u.Function([],u.Unknown()),L=u.String({minLength:1}),Ie=u.Object({provider:L,capability:u.Union([u.Literal("read"),u.Literal("write")])},v),_e=u.Object({source:L,bytes:u.Unknown(),mediaType:u.Optional(u.String())},v),De=u.Object({signal:u.Optional(u.Unknown())},v),Le=u.Object({id:L,description:L,tryConvert:je},v),Ue=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)]),Ve=u.Object({target:u.Unknown(),converter:u.Unknown(),priority:u.Optional(u.Number())},v);function b(e){return O(Ie,e)&&T(()=>e.provider.trim().length>0)}o(b,"isContentTarget");function K(e){return O(_e,e)?T(()=>{let t=e;return t.bytes instanceof Uint8Array&&(!("mediaType"in t)||typeof t.mediaType=="string")}):!1}o(K,"isContentInput");function z(e){return O(De,e)?T(()=>{let t=e;return!("signal"in t)||t.signal instanceof AbortSignal}):!1}o(z,"isContentConversionContext");function oe(e){return O(Le,e)?T(()=>{let t=e;return t.id.trim().length>0&&t.description.trim().length>0&&!/[\r\n]/u.test(t.description)}):!1}o(oe,"isContentConverter");function F(e){return O(Ue,e)?T(()=>{let t=e;return t.kind!=="converted"||q(t.content)}):!1}o(F,"isContentConversionAttempt");function h(e){return O(Ve,e)?T(()=>{let t=e;return b(t.target)&&oe(t.converter)&&(!("priority"in t)||typeof t.priority=="number"&&Number.isFinite(t.priority))}):!1}o(h,"isContentConverterRegistration");function O(e,t){return T(()=>Pe.Check(e,t))}o(O,"safeCheck");function T(e){try{return e()}catch{return!1}}o(T,"safeEvaluate");var U=class extends Error{static{o(this,"UnsupportedContentError")}source;target;constructor(t,n){super(`No content converter for ${t} in ${n.provider}/${n.capability}`),this.name="UnsupportedContentError",this.source=t,this.target=n}};function Y(e){if(!b(e))throw new TypeError("Invalid content target");let t={...e},n=[],r=o(()=>[...n].sort((s,i)=>s.priority-i.priority||s.order-i.order),"snapshotConverters");return{target:t,register(s){if(!h(s))throw new TypeError("Invalid content converter registration");if(!A(t,s.target))throw new Error(`Content converter ${s.converter.id} targets ${s.target.provider}/${s.target.capability}, not ${t.provider}/${t.capability}`);if(n.some(({converter:i})=>i.id===s.converter.id))throw new Error(`Content converter ${s.converter.id} is already registered for ${t.provider}/${t.capability}`);n.push({converter:s.converter,priority:s.priority??0,order:n.length})},listDescriptions(){return r().map(({converter:s})=>({id:s.id,description:s.description}))},async convert(s,i){if(!K(s))throw new TypeError("Invalid content input");if(!z(i))throw new TypeError("Invalid content conversion context");B(i.signal);let a=r();for(let{converter:m}of a){B(i.signal);let p=await m.tryConvert(s,i);if(B(i.signal),!F(p))throw new TypeError(`Content converter ${m.id} returned an invalid outcome`);if(p.kind!=="not-handled"){if(p.kind==="failed")throw p.error;return p.content}}throw new U(s.source,t)}}}o(Y,"createContentRunner");function A(e,t){return e.provider===t.provider&&e.capability===t.capability}o(A,"targetsEqual");function B(e){e?.throwIfAborted()}o(B,"throwIfAborted");import{Type as g}from"typebox";import{Value as $e}from"typebox/value";var x="pi-agent-resource/content-conversion",V=2,P=`${x}/host/ready`,j=`${x}/converter/register`,se={additionalProperties:!0},We=g.Function([],g.Unknown()),He=g.Object({protocol:g.Literal(x),apiVersion:g.Literal(V),target:g.Unknown()},se),qe=g.Object({registration:g.Unknown(),accept:We},se);function G(e){return ie(He,e)&&M(()=>b(e.target))}o(G,"isContentHostReady");function J(e){return ie(qe,e)&&M(()=>h(e.registration))}o(J,"isContentConverterRegistrationRequest");function ie(e,t){return M(()=>$e.Check(e,t))}o(ie,"safeCheck");function M(e){try{return e()}catch{return!1}}o(M,"safeEvaluate");function Ke(e,t){let n=Y(t),r=e.events.on(j,s=>{if(!J(s))throw new Error("Invalid content converter registration request");if(!A(n.target,s.registration.target))return;let i;try{n.register(s.registration),i=Promise.resolve()}catch(a){i=Promise.reject(a instanceof Error?a:new Error("Content converter registration failed",{cause:a}))}s.accept(i)});return e.on("session_shutdown",r),e.events.emit(P,{protocol:x,apiVersion:V,target:n.target}),{target:n.target,listDescriptions(){return n.listDescriptions()},convert(s,i){return n.convert(s,i)}}}o(Ke,"createContentHost");function ze(e,t){if(!h(t))throw new TypeError("Invalid content converter registration");let n=o(()=>{let i,a={registration:t,accept(m){if(i!==void 0)throw new Error(`Content converter ${t.converter.id} registration was accepted more than once`);i=m}};return e.events.emit(j,a),i},"announce"),r=o(()=>{},"unsubscribe");r=e.events.on(P,i=>{if(!G(i))throw new Error("Invalid content conversion host readiness event");if(!A(t.target,i.target))return;let a=n();if(a===void 0)throw new Error(`${i.target.provider}/${i.target.capability} announced readiness without accepting content converter ${t.converter.id}`);r(),a.catch(()=>{})}),e.on("session_shutdown",r);let s=n();if(s!==void 0)return r(),s}o(ze,"connectContentConverter");export{I as a,me as b,Q as c,W as d,Z as e,ee as f,H as g,te as h,he as i,Te as j,q as k,re as l,Ne as m,ke as n,b as o,K as p,z as q,oe as r,F as s,h as t,U as u,Y as v,A as w,x,V as y,P as z,j as A,G as B,J as C,Ke as D,ze as E};
|
package/dist/chunk-5J43L2RL.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{d as B,h as M}from"./chunk-GIRAEVUJ.js";import{a as N}from"./chunk-I5JLCFUX.js";import{h as w,i as P}from"./chunk-2P2OGO3G.js";import{a as y}from"./chunk-EI7MMDWY.js";import{Allow as $}from"partial-json";import{Guard as f}from"typebox-guard/guard";import{Allow as F,parse as H}from"partial-json";function _(o,e=F.ALL){if(!(!o||o.trim().length===0))try{let t=H(o,e);return t==null||typeof t!="object"||Array.isArray(t)?void 0:t}catch{return}}y(_,"resolvePartial");var R=class{static{y(this,"PartialToolRecoveryRegistry")}registrations=new Map;states=new Map;register(e){this.registrations.set(e.recoveryKey??e.toolName,e)}unregister(e){for(let[t,n]of this.registrations)(n.toolName===e||t===e)&&this.registrations.delete(t)}recoveryKeyFor(e){for(let[t,n]of this.registrations)if(n.toolName===e||n.toolNames?.includes(e)||t===e)return t}async recover(e){let t=this.states.get(e.contentIndex);if(t?.status==="done")return t.result;if(t?.status==="running")return t.promise;let n=this.registrations.get(e.recoveryKey??e.toolName);if(!n)return;let r=this.run(n,e);this.states.set(e.contentIndex,{status:"running",promise:r});let a=await r;return this.states.set(e.contentIndex,{status:"done",result:a}),a}cancel(e){this.states.delete(e)}cleanup(e){this.states.delete(e)}cleanupAll(){this.states.clear()}async run(e,t){let n=[],r=new Set(t.completedEntryIndexes),a=new Set(t.blockedEntryIndexes),i=e.extractEntries(t).filter(c=>{if(r.has(c.index))return n.push({index:c.index,reason:"entry already completed before recovery"}),!1;if(a.has(c.index))return n.push({index:c.index,reason:"entry was blocked by a guard"}),!1;let g=e.isCompleteEntry?.(c,t)??c.complete;return g||n.push({index:c.index,reason:t.recoverCompleteBatch?"entry was incomplete in the recovered batch":"entry was incomplete before the stale entry"}),!t.recoverCompleteBatch&&t.staleEntryIndex!==void 0&&c.index>=t.staleEntryIndex?!1:g}),s=e.filterEntries?.(i,t)??i,d=new Set(s.map(c=>c.index));for(let c of i)d.has(c.index)||n.push({index:c.index,reason:"entry was excluded by recovery filtering"});let u=[];for(let c of s)try{e.validateEntry?.(c,t),u.push(c)}catch(g){n.push({index:c.index,reason:g instanceof Error?g.message:String(g)})}let m={toolName:t.toolName,contentIndex:t.contentIndex,...t.staleEntryIndex!==void 0&&{staleEntryIndex:t.staleEntryIndex},staleDetails:t.staleDetails};if(u.length===0)return{...m,status:"skipped",appliedEntries:[],skippedEntries:n};try{let c=e.buildParams(u,t),g=await e.execute(c,{contentIndex:t.contentIndex,toolCallId:t.toolCallId,toolName:t.toolName,cwd:t.cwd,ctx:t.ctx,signal:new AbortController().signal});return{...m,status:"recovered",appliedEntries:e.getAppliedEntries?.(g,u,t)??u.map(b=>b.index),skippedEntries:n,normalResult:g}}catch(c){return{...m,status:"failed",appliedEntries:[],skippedEntries:n,error:c instanceof Error?c.message:String(c)}}}};import{createAssistantMessageEventStream as W}from"@earendil-works/pi-ai";var O=Symbol.for("pi-agent-text-editor.tool-call-interceptor.streaming-provider.state");function K(o,e,t,n){let r=new Map,a={context:void 0,processStreamEvent:e,markStreamEventProcessed:t,finalizeStreamInterception:n},l=y((i,s)=>{if(!i)return;let d=s.modelRegistry.getProvider(i.provider);if(!d)return;let u=r.get(i.provider);if(u){if(u.subscribers.add(a),u.api===i.api&&d.streamSimple===u.wrapper)return;u.api=i.api;let p=s.modelRegistry.getRegisteredProviderConfig(i.provider);o.registerProvider(i.provider,{...p,api:i.api,streamSimple:u.wrapper});return}let m=d.streamSimple[O];if(m){if(m.subscribers.add(a),r.set(i.provider,m),m.api===i.api)return;m.api=i.api;let p=s.modelRegistry.getRegisteredProviderConfig(i.provider);o.registerProvider(i.provider,{...p,api:i.api,streamSimple:m.wrapper});return}let c=d.streamSimple.bind(d),g=new Set([a]),b=y((p,v,C)=>U(c,p,v,C,g),"wrapper"),E={api:i.api,delegate:c,wrapper:b,subscribers:g};b[O]=E;let h=s.modelRegistry.getRegisteredProviderConfig(i.provider);o.registerProvider(i.provider,{...h,api:i.api,streamSimple:b}),r.set(i.provider,E)},"install");o.on("before_provider_request",(i,s)=>{a.context=s,l(s.model,s)}),o.on("turn_start",(i,s)=>{a.context=s,l(s.model,s)}),o.on("agent_start",(i,s)=>{a.context=s,l(s.model,s)}),o.on("session_start",(i,s)=>{a.context=s,l(s.model,s)}),o.on("model_select",(i,s)=>{a.context=s,l(i.model,s)}),o.on("session_shutdown",()=>{for(let[i,s]of r)s.subscribers.delete(a),s.subscribers.size===0&&o.unregisterProvider(i);r.clear(),a.context=void 0})}y(K,"registerStreamingInterceptorProvider");function U(o,e,t,n,r){let a=W(),l=new AbortController,i=n?.signal,s=!1,d=Y(e),u=new Set,m=new Set,c=new Set,g=new Set,b=y(h=>{for(let p of r)p.markStreamEventProcessed(h)},"markStreamEventProcessed"),E=y(()=>{l.abort()},"abortFromParent");return i&&(i.aborted?l.abort():i.addEventListener("abort",E,{once:!0})),(async()=>{try{let h=o(e,t,{...n,signal:l.signal});for await(let p of h){if(s)continue;p.type==="done"?d=structuredClone(p.message):p.type==="error"?d=structuredClone(p.error):d=structuredClone(p.partial),Q(p,u);let v;for(let C of r){let I=C.context;if(I){let T=await C.processStreamEvent(p,I);v??=T}}if(b(p),q(p,m,c,g),a.push(structuredClone(p)),v){if(p.type==="toolcall_delta"||p.type==="toolcall_end")for(let x of r)x.finalizeStreamInterception(p.contentIndex);s=!0,l.abort();let C=p.type==="toolcall_delta"||p.type==="toolcall_end"?p.contentIndex:void 0,I={...d,content:d.content.filter((x,A)=>u.has(A)&&(C===void 0||A<=C||g.has(A))).map(x=>x.type==="toolCall"&&x.id===v.toolCallId?{...x,arguments:structuredClone(v.arguments)}:x)};V(a,b,I,u,m,c,g);let{errorMessage:T,...L}=I;a.push({type:"done",reason:"toolUse",message:{...L,stopReason:"toolUse"}}),a.end();continue}if(p.type==="done"||p.type==="error"){a.end();return}}}catch(h){if(s)return;let p=d,v=i?.aborted===!0?"aborted":"error",C={...p,stopReason:v,errorMessage:h instanceof Error?h.message:String(h)};a.push({type:"error",reason:v,error:C}),a.end()}finally{i?.removeEventListener("abort",E)}})(),a}y(U,"wrapStream");function Q(o,e){(o.type==="text_start"||o.type==="thinking_start"||o.type==="toolcall_start")&&e.add(o.contentIndex)}y(Q,"rememberStartEvent");function q(o,e,t,n){switch(o.type){case"text_end":{e.add(o.contentIndex);break}case"thinking_end":{t.add(o.contentIndex);break}case"toolcall_end":{n.add(o.contentIndex);break}}}y(q,"rememberEndEvent");function V(o,e,t,n,r,a,l){for(let[i,s]of t.content.entries())if(n.has(i)){if(s.type==="text"&&!r.has(i)){let d={type:"text_end",contentIndex:i,content:s.text,partial:t};e(d),o.push(d)}else if(s.type==="thinking"&&!a.has(i)){let d={type:"thinking_end",contentIndex:i,content:s.thinking,partial:t};e(d),o.push(d)}else if(s.type==="toolCall"&&!l.has(i)){let d={type:"toolcall_end",contentIndex:i,toolCall:s,partial:t};e(d),o.push(d)}}}y(V,"emitMissingEndEvents");function Y(o){return{role:"assistant",content:[],api:o.api,provider:o.provider,model:o.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"toolUse",timestamp:Date.now()}}y(Y,"emptyAssistantMessage");var Z="agentic-ide-partial-tool-recovery",G="pi-agent-text-editor/tool-call-annotation",S=new WeakMap,k=class{constructor(e){this.pi=e;e.on("tool_call",t=>{let n=this.toolCallRecords.get(t.toolCallId),r=n?.blockExecution?n.guardResult:void 0;return r?{block:!0,reason:r.content.filter(l=>l.type==="text").map(l=>l.text).join(`
|
|
2
|
-
`)||`Tool call ${t.toolName} was blocked by a streaming interceptor.`}:void 0}),e.on("tool_result",t=>{let n=this.toolCallBatchEntryIndexes.get(t.toolCallId);n!==void 0&&this.completedBatchEntryIndexes.add(n);let r=this.toolCallRecords.get(t.toolCallId)?.guardResult;if(this.toolCallRecords.delete(t.toolCallId),r){let a=r.details,l=typeof a=="object"&&a!==null&&"effect"in a&&(a.effect==="not-applied"||a.effect==="applied")?a.effect:"unknown",i=r.content.flatMap(s=>s.type==="text"?[s.text]:[]).join(`
|
|
3
|
-
`);return P({content:r.content,details:a},N,{status:"error",errors:[w(i,"INTERCEPTED")],data:{operation:t.toolName,operationId:t.toolCallId,effect:l,files:[]}})}}),e.on("message_update",async(t,n)=>{let r=t.assistantMessageEvent;this.consumeProcessedStreamEvent(r)||await this.processStreamEvent(r,n)}),e.on("message_end",async t=>{if(await this.finalizeRecovery(),this.annotateIncompleteCalls(),t.message.role!=="assistant")return;let n=this.pendingAbortReason;if(this.pendingAbortReason=void 0,!(n===void 0||t.message.stopReason!=="aborted"))return{message:{...t.message,errorMessage:n}}}),e.on("agent_end",async()=>{await this.finalizeRecovery(),this.annotateIncompleteCalls(),this.cleanupAll()})}static{y(this,"InterceptorImpl")}handlers=new Map;recoveryRegistry=new R;pendingRecoveryBlocks=[];pendingAbortReason;recoveryAppliedBatchIndexes=new Set;partialBuffers=new Map;completeArgumentContentIndices=new Set;streamedBatchEntries=new Map;batchEntryIndexes=new Map;toolCallBatchEntryIndexes=new Map;completedBatchEntryIndexes=new Set;nextBatchEntryIndex=0;contentNames=new Map;contentToolCallIds=new Map;pendingToolCallAnnotations=new Map;emittedToolCallAnnotationKinds=new Map;abortedContentIndices=new Set;dispatchQueues=new Map;abortCleanups=new Map;processedStreamEvents=new WeakSet;processedStreamEventKeys=new Map;toolCallRecords=new Map;blockedCallSink;processStreamEvent(e,t){if(e.type==="toolcall_start"){let n=e.partial.content[e.contentIndex];if(n?.type==="toolCall"){let r=this.getOrCreateBatchEntryIndex(e.contentIndex);this.contentNames.set(e.contentIndex,n.name),typeof n.id=="string"&&this.bindToolCallId(e.contentIndex,n.id),this.partialBuffers.set(e.contentIndex,""),this.streamedBatchEntries.set(e.contentIndex,{index:r,toolName:n.name,args:{},complete:!1}),this.installAbortCleanup(e.contentIndex,t.signal)}return Promise.resolve(void 0)}return e.type==="toolcall_delta"?this.enqueue(e.contentIndex,async()=>{let n=this.contentNames.get(e.contentIndex),r=this.contentToolCallIds.get(e.contentIndex);if(!n)return;let a=(this.partialBuffers.get(e.contentIndex)??"")+e.delta;this.partialBuffers.set(e.contentIndex,a),this.installAbortCleanup(e.contentIndex,t.signal);let l=_(a,$.OBJ|$.ARR)??{},i=ee(a),s=this.getOrCreateBatchEntryIndex(e.contentIndex);this.streamedBatchEntries.set(e.contentIndex,{index:s,toolName:n,args:l,complete:i!==void 0});let d=this.handlers.get(n);if(!r||!d||d.length===0||!i&&Object.keys(l).length===0)return;let u=i!==void 0;if(u&&this.completeArgumentContentIndices.has(e.contentIndex))return;u&&this.completeArgumentContentIndices.add(e.contentIndex);let m=i??l,c=await this.dispatchHandlers(d,{toolCall:{id:r,name:n,arguments:m},args:m,...!u&&{partialArgs:l},batchEntryIndex:s,batchEntries:this.getBatchEntries(s),contentIndex:e.contentIndex,cwd:t.cwd,signal:t.signal,ctx:t});return c&&this.rememberOriginalArguments(c.toolCallId,c.arguments),c}):e.type==="toolcall_end"?this.enqueue(e.contentIndex,async()=>{let n=e.toolCall.name,r=this.handlers.get(n),a=this.getOrCreateBatchEntryIndex(e.contentIndex);this.bindToolCallId(e.contentIndex,e.toolCall.id);let l=this.toolCallRecords.get(e.toolCall.id);this.toolCallRecords.set(e.toolCall.id,{originalArguments:structuredClone(e.toolCall.arguments),...l?.guardResult&&{guardResult:l.guardResult},...l?.blockExecution&&{blockExecution:!0}}),this.streamedBatchEntries.set(e.contentIndex,{index:a,toolName:n,args:e.toolCall.arguments,complete:!1});let i=!this.completeArgumentContentIndices.has(e.contentIndex),s;i&&(this.completeArgumentContentIndices.add(e.contentIndex),s=r&&r.length>0?await this.dispatchHandlers(r,{toolCall:e.toolCall,args:e.toolCall.arguments,batchEntryIndex:a,batchEntries:this.getBatchEntries(a),contentIndex:e.contentIndex,cwd:t.cwd,signal:t.signal,ctx:t}):void 0);let d=this.streamedBatchEntries.get(e.contentIndex);return d&&this.streamedBatchEntries.set(e.contentIndex,{...d,complete:!0}),this.cleanupContent(e.contentIndex,n),s}):Promise.resolve(void 0)}markStreamEventProcessed(e){this.processedStreamEvents.add(e);let t=j(e);t!==void 0&&this.processedStreamEventKeys.set(t,(this.processedStreamEventKeys.get(t)??0)+1)}consumeProcessedStreamEvent(e){let t=this.processedStreamEvents.delete(e),n=j(e);if(n===void 0)return t;let r=this.processedStreamEventKeys.get(n)??0;return r===0?t:(r===1?this.processedStreamEventKeys.delete(n):this.processedStreamEventKeys.set(n,r-1),!0)}finalizeStreamInterception(e){this.cleanupTransientContent(e,void 0,!0)}getToolCallRecord(e){return this.toolCallRecords.get(e)}rememberOriginalArguments(e,t){let n=this.toolCallRecords.get(e);n&&this.toolCallRecords.set(e,{originalArguments:structuredClone(t),...n.guardResult&&{guardResult:n.guardResult},...n.blockExecution&&{blockExecution:!0}})}async dispatchHandlers(e,t){for(let n of e){let r=await n.intercept(t);if(r!==void 0){this.pendingRecoveryBlocks.push({blocked:r,ctx:t});let a={content:[{type:"text",text:r.message.content}],details:r.message.details??null};return this.blockedCallSink?.({callId:t.toolCall.id,toolName:t.toolCall.name,arguments:structuredClone(t.args),...t.contentIndex!==void 0&&{contentIndex:t.contentIndex},...t.batchEntryIndex!==void 0&&{batchEntryIndex:t.batchEntryIndex},...r.message.details!==void 0&&{details:r.message.details},result:a,nativeExecutionBlocked:n.blockExecution===!0}),{toolCallId:t.toolCall.id,arguments:structuredClone(t.args),result:this.abortToolCall(r,t,n.name,n.blockExecution===!0)}}}}annotateIncompleteCalls(){for(let[e,t]of this.streamedBatchEntries)!t.complete&&this.contentNames.has(e)&&!this.recoveryAppliedBatchIndexes.has(t.index)&&!this.emittedToolCallAnnotationKinds.get(e)?.has("stale-anchor")&&this.annotateContent(e,{kind:"aborted"})}bindToolCallId(e,t){this.contentToolCallIds.set(e,t);let n=this.batchEntryIndexes.get(e);n!==void 0&&this.toolCallBatchEntryIndexes.set(t,n);let r=this.pendingToolCallAnnotations.get(e);if(r){for(let a of r)this.emitToolCallAnnotation(t,a);this.pendingToolCallAnnotations.delete(e)}}annotateContent(e,t){let n=this.emittedToolCallAnnotationKinds.get(e)??new Set;if(n.has(t.kind))return;n.add(t.kind),this.emittedToolCallAnnotationKinds.set(e,n);let r=this.contentToolCallIds.get(e);if(r){this.emitToolCallAnnotation(r,t);return}let a=this.pendingToolCallAnnotations.get(e)??[];a.push(t),this.pendingToolCallAnnotations.set(e,a)}emitToolCallAnnotation(e,t){let n={toolCallId:e,annotation:t};this.pi.events.emit(G,n)}getOrCreateBatchEntryIndex(e){let t=this.batchEntryIndexes.get(e);if(t!==void 0)return t;let n=this.nextBatchEntryIndex;return this.nextBatchEntryIndex+=1,this.batchEntryIndexes.set(e,n),n}getBatchEntries(e){return[...this.streamedBatchEntries.values()].filter(t=>t.index<=e).sort((t,n)=>t.index-n.index)}getAllBatchEntries(){return[...this.streamedBatchEntries.values()].sort((e,t)=>e.index-t.index)}abortToolCall(e,t,n,r){let a=X(e,n),l=e.annotation?e.annotation.kind==="aborted"&&e.annotation.label===void 0?{...e.annotation,label:a}:e.annotation:e.message.customType==="text-editor-stale-anchor-block"?{kind:"stale-anchor",label:a}:{kind:"aborted",label:a,color:"error"};t.contentIndex!==void 0&&(this.abortedContentIndices.add(t.contentIndex),this.annotateContent(t.contentIndex,l));let i={content:[{type:"text",text:e.message.content}],details:B(e.message.details,l,a)};return this.toolCallRecords.set(t.toolCall.id,{originalArguments:structuredClone(t.args),guardResult:i,...r&&{blockExecution:!0}}),i}async finalizeRecovery(){let e=this.pendingRecoveryBlocks.splice(0);if(e.length===0)return;let t=new Map;for(let n of e){let r=this.recoveryRegistry.recoveryKeyFor(n.ctx.toolCall.name);if(r===void 0)continue;let a=t.get(r)??[];a.push(n),t.set(r,a)}for(let n of t.values()){let r=n[0];if(!r)continue;let a=await this.recoverIfNeeded(r.blocked,r.ctx,this.getAllBatchEntries(),n);if(a===r.blocked)continue;let l=a.message.details,s=(f.IsObjectNotArray(l)&&f.IsObjectNotArray(l.recovery)?l.recovery:void 0)?.appliedEntries;if(Array.isArray(s))for(let d of s)typeof d=="number"&&this.recoveryAppliedBatchIndexes.add(d)}}async recoverIfNeeded(e,t,n,r){if(t.contentIndex===void 0)return e;let a=e.message.details,l=f.IsObjectNotArray(a)&&typeof a.entryIndex=="number"?a.entryIndex:void 0,i=[...new Set(r.map(g=>g.ctx.batchEntryIndex).filter(g=>g!==void 0))],s=[...new Set(r.map(g=>g.ctx.toolCall.id))],d=r.map(g=>g.blocked.message.details),u=r[0],m=u?this.recoveryRegistry.recoveryKeyFor(u.ctx.toolCall.name):void 0;if(!m)return e;let c=await this.recoveryRegistry.recover({contentIndex:t.contentIndex,toolCallId:t.toolCall.id,toolName:t.toolCall.name,...l!==void 0&&{staleEntryIndex:l},staleDetails:a,...t.partialArgs&&{partialArgs:t.partialArgs},args:t.args,batchEntries:n,...t.batchEntryIndex!==void 0&&{batchEntryIndex:t.batchEntryIndex},recoverCompleteBatch:!0,completedEntryIndexes:[...this.completedBatchEntryIndexes],blockedEntryIndexes:i,blockedToolCallIds:s,blockedDetails:d,recoveryKey:m,cwd:t.cwd,ctx:t.ctx});return c&&(c.appliedEntries.length>0||c.skippedEntries.length>0)?re(e,c):e}async enqueue(e,t){let r=(this.dispatchQueues.get(e)??Promise.resolve()).catch(()=>{}).then(t);this.dispatchQueues.set(e,r);try{return await r}finally{this.dispatchQueues.get(e)===r&&this.dispatchQueues.delete(e)}}installAbortCleanup(e,t){if(!t||this.abortCleanups.has(e))return;let n=y(()=>{let r=this.contentNames.get(e),a=r?this.handlers.get(r):void 0;for(let l of a??[])l.onAbort?.(e)},"listener");t.addEventListener("abort",n,{once:!0}),this.abortCleanups.set(e,()=>{t.removeEventListener("abort",n)})}cleanupContent(e,t){this.cleanupTransientContent(e,t),this.recoveryRegistry.cleanup(e)}cleanupTransientContent(e,t,n=!1){let r=t??this.contentNames.get(e),a=r?this.handlers.get(r):void 0;for(let l of a??[])n&&l.onAbort?.(e),l.onContentEnd?.(e);this.abortCleanups.get(e)?.(),this.abortCleanups.delete(e),this.contentNames.delete(e),this.contentToolCallIds.delete(e),this.pendingToolCallAnnotations.delete(e),this.emittedToolCallAnnotationKinds.delete(e),this.completeArgumentContentIndices.delete(e),this.partialBuffers.delete(e),this.abortedContentIndices.delete(e)}cleanupAll(){for(let e of this.handlers.values())for(let t of e)t.onAgentEnd?.();for(let e of this.abortCleanups.values())e();this.abortCleanups.clear(),this.contentNames.clear(),this.contentToolCallIds.clear(),this.pendingToolCallAnnotations.clear(),this.completeArgumentContentIndices.clear(),this.emittedToolCallAnnotationKinds.clear(),this.partialBuffers.clear(),this.streamedBatchEntries.clear(),this.batchEntryIndexes.clear(),this.toolCallBatchEntryIndexes.clear(),this.toolCallRecords.clear(),this.completedBatchEntryIndexes.clear(),this.nextBatchEntryIndex=0,this.abortedContentIndices.clear(),this.pendingAbortReason=void 0,this.dispatchQueues.clear(),this.processedStreamEventKeys.clear(),this.recoveryRegistry.cleanupAll(),this.pendingRecoveryBlocks.length=0,this.recoveryAppliedBatchIndexes.clear()}registerRecovery(e){this.recoveryRegistry.register(e)}unregisterRecovery(e){this.recoveryRegistry.unregister(e)}registerBlockedCallSink(e){this.blockedCallSink=e}register(e){let t=new Set(e.toolNames);for(let[n,r]of this.handlers){let a=r.findIndex(l=>l.name===e.name);a!==-1&&(t.has(n)?(r[a]=e,t.delete(n)):r.splice(a,1))}for(let n of t){let r=this.handlers.get(n)??[];r.push(e),this.handlers.set(n,r)}}unregister(e){for(let[t,n]of this.handlers)this.handlers.set(t,n.filter(r=>r.name!==e))}};function j(o){if(o.type==="toolcall_end")return`${o.type}\0${o.contentIndex}\0${o.toolCall.id}`;if(o.type!=="toolcall_start"&&o.type!=="toolcall_delta")return;let e=o.partial.content[o.contentIndex],t=e?.type==="toolCall"?e.id:"",n=o.type==="toolcall_delta"?o.delta:"";return`${o.type}\0${o.contentIndex}\0${t}\0${n}`}y(j,"toolStreamEventKey");function X(o,e){return o.annotation?.reason?o.annotation.reason:o.annotation?.label?o.annotation.label:o.message.customType==="text-editor-stale-anchor-block"?"Stale Anchor":e.replace(/[-_]+/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\s+/g," ").trim().replace(/\b\w/g,t=>t.toUpperCase())||"Blocked"}y(X,"abortReason");function ee(o){try{let e=JSON.parse(o);return f.IsObjectNotArray(e)?e:void 0}catch{return}}y(ee,"parseCompleteArguments");function te(o){let e=o.normalResult;if(!f.IsObjectNotArray(e)||!f.IsObjectNotArray(e.details))return[];let t=e.details.results;if(!Array.isArray(t))return[];let n=f.IsObjectNotArray(o.staleDetails)&&typeof o.staleDetails.path=="string"?o.staleDetails.path:void 0,r=t.filter(f.IsObjectNotArray).map(s=>f.IsObjectNotArray(s.data)?s.data:s),a=n===void 0?r:r.filter(s=>s.path===n),i=(a.length>0?a:r).flatMap(s=>{let d=s.freshAnchors;return Array.isArray(d)?d.filter(u=>typeof u=="string"):[]});return[...new Set(i)]}y(te,"freshAnchorsAfterRecovery");function ne(o,e){let n=o.indexOf(`
|
|
4
|
-
|
|
5
|
-
Current nearby anchors:`);return`${n===-1?o:o.slice(0,n)}
|
|
6
|
-
|
|
7
|
-
Current nearby anchors:
|
|
8
|
-
${e.map(a=>` ${a}`).join(`
|
|
9
|
-
`)}`}y(ne,"replaceCurrentAnchors");function re(o,e){let t=e.appliedEntries.length,n=t>0?`${t} (indices: ${e.appliedEntries.join(", ")})`:"0",r=e.skippedEntries.length>0?e.skippedEntries.map(u=>`${u.index} (${u.reason})`).join(", "):"none",a=e.error?`Recovery execution failed: ${e.error}.`:"Recovery execution completed.",l=te(e),i=l.length>0&&f.IsObjectNotArray(o.message.details)?{...o.message.details,freshAnchors:l}:o.message.details,s=l.length>0?ne(o.message.content,l):o.message.content,d=l.length>0&&f.IsObjectNotArray(e.staleDetails)?{...e,staleDetails:{...e.staleDetails,freshAnchors:l}}:e;return{message:{customType:Z,content:`${s}
|
|
10
|
-
|
|
11
|
-
[RECOVERY] Status: ${e.status}. Applied entries: ${n}. Skipped entries: ${r}. ${a}`,display:!1,details:{blocked:i,recovery:d}}}}y(re,"makeRecoveryResult");var D=new WeakMap;function z(o){let e=D.get(o);if(e)return e;let t=new k(o);return D.set(o,t),K(o,(n,r)=>t.processStreamEvent(n,r),n=>{t.markStreamEventProcessed(n)},n=>{t.finalizeStreamInterception(n)}),t}y(z,"coordinatorFor");function oe(o,e){z(o).register(e)}y(oe,"registerToolCallInterceptor");function ae(o,e){if(S.get(o)?.(),S.delete(o),e===void 0)return;let t=o.events.on(G,n=>{!f.IsObjectNotArray(n)||typeof n.toolCallId!="string"||!M(n.annotation)||e(n.toolCallId,n.annotation)});S.set(o,t)}y(ae,"registerToolCallAnnotationSink");function Ee(o,e){z(o).registerBlockedCallSink(e)}y(Ee,"registerBlockedToolCallSink");export{oe as a,ae as b,Ee as c};
|
package/dist/chunk-6EYWFBNG.js
DELETED
|
File without changes
|
package/dist/chunk-7AVXUV4A.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{a as d}from"./chunk-ZC65Z3CK.js";import{a as s}from"./chunk-EI7MMDWY.js";import{createTwoFilesPatch as m,diffLines as l}from"diff";function y(i,e,n,r=i){return{diff:m(i,r,e,n,"","",{context:3}).replace(/^(?:Index: .*\n)?={3,}\n?/m,"").trimEnd(),stats:p(e,n)}}s(y,"createUnifiedDiff");function p(i,e){let n=0,r=0;for(let t of l(i,e)){let a=g(t.value);t.removed&&(n+=a),t.added&&(r+=a)}return{removed:n,added:r}}s(p,"computeStats");function g(i){if(i.length===0)return 0;let e=i.replaceAll(`\r
|
|
2
|
-
`,`
|
|
3
|
-
`);return e.endsWith(`
|
|
4
|
-
`)?e.slice(0,-1).split(`
|
|
5
|
-
`).length:e.split(`
|
|
6
|
-
`).length}s(g,"countDiffLines");function x(i,e){let n=l(i,e),r=[],t=0;for(let a of n){let o=g(a.value);o!==0&&(a.removed||(a.added&&r.push({start:t+1,end:t+o}),t+=o))}return E(r)}s(x,"computeChangedRanges");function E(i){if(i.length===0)return[];let e=[...i].sort((r,t)=>r.start-t.start),n=[d(e[0])];for(let r=1;r<e.length;r++){let t=d(n.at(-1)),a=d(e[r]);a.start<=t.end+1?t.end=Math.max(t.end,a.end):n.push(a)}return n}s(E,"mergeAdjacentRanges");var f=class i{static{s(this,"FileRange")}start;end;constructor(e,n=e){n.lineNumber<e.lineNumber&&([e,n]=[n,e]),this.start=e,this.end=n}static fromLines(e,n){let r=n??e;return new i({lineNumber:e},{lineNumber:r})}},c=class i{static{s(this,"FileMutationResult")}data;constructor(e){this.data=e??{}}get ok(){return this.data.ok??!1}get isPartial(){return this.data.isPartial??!1}get diffs(){return this.data.diffs??[]}get files(){return this.data.files??[]}get warnings(){return this.data.warnings??[]}get errors(){return this.data.errors??[]}get lintViolations(){return this.data.lintViolations??[]}get hints(){return this.data.hints??[]}get syntaxErrorSummary(){return this.data.syntaxErrorSummary}get path(){return this.data.path}get editRange(){let e=this.data.activeEdits,n=e?.[0];if(n?.range){let r=n.range.start,a=d(e).at(-1)?.range?.end??r;return new f(r,a)}return this.data.editRange}get resolvedStartLine(){return this.editRange?.start.lineNumber}get resolvedEndLine(){return this.editRange?.end.lineNumber}get freshAnchors(){return this.data.freshAnchors}get failurePoint(){return this.data.failurePoint}get recovery(){return this.data.recovery}get expectedAnchor(){return this.data.expectedAnchor}get currentAnchor(){return this.data.currentAnchor}get internalErrorType(){return this.data.internalErrorType}get internalErrorMessage(){return this.data.internalErrorMessage}get editCount(){return this.data.editCount}get editRanges(){return this.data.editRanges}get addedLines(){return this.data.addedLines}get removedLines(){return this.data.removedLines}get appliedPaths(){return this.data.appliedPaths}get beforeContentMap(){return this.data.beforeContentMap}get afterContent(){return this.data.afterContent}get skipCount(){return this.data.skipCount??0}get staleEdits(){return this.data.staleEdits??[]}get proposedDiff(){return this.data.proposedDiff}get editIndex(){return this.data.editIndex}get editIndices(){return this.data.editIndices}get staleDiagnostic(){return this.data.staleDiagnostic}get fileChangedStatement(){return this.data.fileChangedStatement}get affectedPaths(){let e=new Set;for(let n of this.files)e.add(n.path);for(let n of this.errors)n.path&&e.add(n.path);for(let n of this.warnings)n.file&&e.add(n.file);return[...e]}get didChange(){return this.ok&&(this.files.length>0||this.diffs.length>0)}get createdFiles(){return this.files.filter(e=>e.action==="created")}get overwrittenFiles(){return this.files.filter(e=>e.action==="overwritten"||e.action==="edited")}get staleCount(){return this.staleEdits.length}get summary(){if(!this.ok){let t=this.errors[0];return t?`Failed: ${t.code??"ERROR"}${t.reason?` \u2014 ${t.reason}`:""}`:"Mutation failed"}if(this.files.length===0&&this.diffs.length===0){let t=this.appliedPaths;return t&&t.length>0?`${t.length} path${t.length===1?"":"s"} affected`:"No changes"}let e=this.createdFiles.length,n=this.overwrittenFiles.length,r=[];if(e>0&&r.push(`Created ${e} ${e===1?"file":"files"}`),n>0&&r.push(`Edited ${n} ${n===1?"file":"files"}`),this.diffs.length>0){let t=0,a=0;for(let o of this.diffs)for(let u of o.split(`
|
|
7
|
-
`))u.startsWith("+")&&!u.startsWith("+++")?t++:u.startsWith("-")&&!u.startsWith("---")&&a++;(t>0||a>0)&&r.push(`+${t}/-${a} lines`)}return r.join(", ")}getFileChange(e){return this.files.find(n=>n.path===e)}getDiffFor(e){let n=h(e);for(let r of this.diffs){let t=r.match(/^---\s+(.+)$/m);if(t&&(h(d(t[1]))===n||t[1]===e))return r}}getErrorsFor(e){return this.errors.filter(n=>n.path===e)}getWarningsFor(e){return this.warnings.filter(n=>n.file===e)}static fromFailureOptions(e){return new i({ok:!1,path:e.path,errors:[{path:e.path,code:e.code,reason:e.reason}],failurePoint:e.failurePoint,recovery:e.recovery,expectedAnchor:e.expectedAnchor,currentAnchor:e.currentAnchor,freshAnchors:e.freshLines?[...e.freshLines]:void 0,internalErrorType:e.internalError instanceof Error?e.internalError.name:void 0,internalErrorMessage:e.internalError instanceof Error?e.internalError.message:void 0})}static ensure(e){if(e instanceof i)return e;if(e&&typeof e=="object"){let n=e;return n.data&&typeof n.data=="object"?(Object.setPrototypeOf(n,i.prototype),n):new i(n)}return new i}};function h(i){return i.replace(/\\/g,"/").replace(/^a\//,"").replace(/^b\//,"")}s(h,"normalisePath");export{y as a,x as b,f as c,c as d};
|
package/dist/chunk-7WCZOO5I.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as c}from"./chunk-EI7MMDWY.js";import f from"node:path";import{pathToFileURL as p}from"node:url";function g(e,t){let o=new Map;for(let r of e){let n=o.get(r.source)??[];n.push(r),o.set(r.source,n)}let i=new Set,a=e.length,s=[...o].sort(([r,n],[h,u])=>u.length-n.length||r.localeCompare(h));for(let[r,n]of s){if(a<=t)break;i.add(r),a-=n.length}return{files:[...o].sort(([r],[n])=>r.localeCompare(n)).map(([r,n])=>{if(!i.has(r))return{kind:"detailed",source:r,matches:n};let h=new Map;for(let u of n)h.set(u.lineText,(h.get(u.lineText)??0)+1);return{kind:"compacted",source:r,matchCount:n.length,uniqueLineCount:h.size,groups:o.size===1?[...h].sort(([u,y],[b,C])=>C-y||u.localeCompare(b)).slice(0,t).map(([u,y])=>({text:u,matchCount:y})):[]}})}}c(g,"planSearchPresentation");function F(e,t,o,i,a,s=50){let r=g(t,s).files.map(n=>n.kind==="detailed"?x(n.source,n.matches,i):{path:S(n.source,i),link:p(n.source).href,matchCount:n.matchCount,uniqueLineCount:n.uniqueLineCount,groups:n.groups,lines:[]});return{...a!==void 0&&{sessionId:a},query:e,matchCount:t.length,fileCount:r.length,complete:o,files:r}}c(F,"createSearchToolDetails");function I(e){if(!d(e)||typeof e.query!="string"||!m(e.matchCount)||!m(e.fileCount)||typeof e.complete!="boolean"||e.sessionId!==void 0&&typeof e.sessionId!="string"||!Array.isArray(e.files)||!e.files.every(R))return!1;let t=e.files;return e.fileCount===t.length&&e.matchCount===t.reduce((o,i)=>o+i.matchCount,0)}c(I,"isSearchToolDetails");function x(e,t,o){let i=new Map;for(let s of t){let l=i.get(s.lineNumber);if(l!==void 0&&l.text!==s.lineText)throw new Error(`Search results disagree about line ${String(s.lineNumber)} in ${e}.`);let r=l??{lineNumber:s.lineNumber,text:s.lineText,ranges:[]};r.ranges.push({from:s.startColumn,to:s.endColumn}),i.set(s.lineNumber,r)}let a=[...i.values()].sort((s,l)=>s.lineNumber-l.lineNumber).map(s=>{let l=[...s.ranges].sort((r,n)=>r.from-n.from||r.to-n.to);return{lineNumber:s.lineNumber,text:s.text,matchCount:l.length,ranges:l}});return{path:S(e,o),link:p(e).href,matchCount:t.length,lines:a}}c(x,"createSearchResultFile");function R(e){if(!d(e)||typeof e.path!="string"||typeof e.link!="string"||!m(e.matchCount)||!Array.isArray(e.lines)||!e.lines.every(M))return!1;let t=e.lines,o=e.groups,i=new Set(t.flatMap(a=>a.logicalMatchIds??[]));return(o===void 0||Array.isArray(o)&&o.every(a=>d(a)&&typeof a.text=="string"&&m(a.matchCount)))&&(e.uniqueLineCount===void 0||m(e.uniqueLineCount))&&(t.length===0||(i.size>0?i.size===e.matchCount:e.matchCount===t.reduce((a,s)=>a+s.matchCount,0)))}c(R,"isSearchResultFile");function M(e){return d(e)&&Number.isSafeInteger(e.lineNumber)&&e.lineNumber>=1&&typeof e.text=="string"&&m(e.matchCount)&&Array.isArray(e.ranges)&&e.ranges.length===e.matchCount&&(e.logicalMatchIds===void 0||Array.isArray(e.logicalMatchIds)&&e.logicalMatchIds.every(t=>typeof t=="string"))&&e.ranges.every(t=>k(t,e.text))}c(M,"isSearchResultLine");function k(e,t){return d(e)&&Number.isSafeInteger(e.from)&&Number.isSafeInteger(e.to)&&e.from>=0&&e.to>e.from&&e.to<=t.length}c(k,"isSearchResultRange");function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}c(d,"isRecord");function m(e){return Number.isSafeInteger(e)&&e>=0}c(m,"isCount");function S(e,t){let o=f.relative(t,e);return o.length>0&&!o.startsWith("..")&&!f.isAbsolute(o)?o:e}c(S,"displaySource");export{g as a,F as b,I as c};
|
package/dist/chunk-BAYETTZZ.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{a as A,d as R}from"./chunk-7AVXUV4A.js";import{a as v}from"./chunk-FZBCKIJJ.js";import{b as N,d as L}from"./chunk-BSICWXMH.js";import{f as $}from"./chunk-YHUTTZC6.js";import{e as I,h as _,i as O}from"./chunk-2P2OGO3G.js";import{a as u}from"./chunk-EI7MMDWY.js";import B from"node:path";import{truncateHead as q,DEFAULT_MAX_BYTES as se,DEFAULT_MAX_LINES as ae}from"@earendil-works/pi-coding-agent";import{Text as k}from"@earendil-works/pi-tui";import{Type as h}from"typebox";import{Value as le}from"typebox/value";var U=h.Object({source:h.String(),sources:h.Array(h.String())},{additionalProperties:!1}),j=h.Object({kind:h.Literal("diff"),equal:h.Boolean(),before:U,after:U,stats:h.Object({added:h.Integer(),removed:h.Integer()}),diff:h.String(),truncated:h.Boolean(),fullResult:h.Optional(h.String())},{additionalProperties:!1}),ce=I(j),V=h.Union([h.String({minLength:1}),v]),H=h.Object({before:V,after:V},{additionalProperties:!1});async function fe(e,i,c){if(!le.Check(H,i))throw Object.assign(new Error("Use before and after source strings or read request objects"),{code:"INVALID_ARGUMENTS"});let n=i,r=u(async s=>{let t=typeof s=="string"?{path:s}:s,f=await e.read(t,c,"script");if(f.isError||f.details.failure)throw Object.assign(new Error(f.details.failure?.message??"Comparison read failed"),{code:f.details.failure?.code??"READ_FAILED",details:f.details.failure});if(f.script===void 0)throw Object.assign(new Error("Source has no comparable text data"),{code:"UNSUPPORTED_CONTENT"});return J(f.script,t.path??"source")},"resolve"),o=await r(n.before),a=await r(n.after),l=A(o.source,o.content,a.content,a.source);return{kind:"diff",ok:!0,equal:o.content===a.content,before:o,after:a,...l}}u(fe,"executeDiff");function J(e,i){if(e.kind==="text")return{source:e.source,sources:[e.source],content:e.content};if(e.kind==="resources"){let c=e.resources.map(n=>J(n,i));return{source:e.source??i,sources:c.flatMap(n=>n.sources),content:c.map(n=>n.content).join(`
|
|
2
|
-
`)}}if(e.kind==="bytes")throw Object.assign(new Error(`Byte sources are not text: ${e.source}`),{code:"UNSUPPORTED_CONTENT"});if(e.blocks.length===0||e.blocks.some(c=>c.type!=="text"))throw Object.assign(new Error(`Source is not text: ${e.source}`),{code:"UNSUPPORTED_CONTENT"});return{source:e.source,sources:[e.source],content:e.blocks.flatMap(c=>c.type==="text"?[c.text]:[]).join(`
|
|
3
|
-
`)}}u(J,"comparisonText");function S(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="diff"&&"ok"in e&&e.ok===!0}u(S,"isDiffOutcome");function P(e,i=process.cwd()){let c=u(r=>B.isAbsolute(r)?B.relative(i,r)||".":r,"displaySource"),n=`Diff: ${c(e.before.source)} \u2192 ${c(e.after.source)}`;return{results:[new R({ok:!0,path:n,beforeContentMap:{[n]:e.before.content},afterContent:e.after.content,diffs:[e.diff]})]}}u(P,"diffPresentation");function T(e){return e.equal?`No differences: ${e.before.source} \u2192 ${e.after.source}`:e.diff}u(T,"diffText");function Ne(e){return{content:[{type:"text",text:T(e)}],details:{}}}u(Ne,"diffReadResult");function Le(e,i,c){e.registerTool({name:"diff",exposure:"direct",namespace:{name:"ide_read",description:"Read resources and compare sources."},annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},label:"Diff",parameters:H,outputSchema:ce,promptSnippet:"Compare two text-readable sources",description:"Use diff to compare two sources. before and after accept a source string or a read request {path, offset?, limit?, views?}. Use any source that read can resolve as text. Omit limit to compare complete resolved text; read presentation limits do not clip comparison inputs. Multiple resolved resources are joined with one newline separator in resolver order. Diff line numbers are relative to each selected text, not the original file when a window is selected. Native non-text content is rejected. Output uses the existing text diff and a shared output budget; oversized output has a full temporary reference. The same diff function is available inside Apply.",renderCall(n,r){return new k(r.fg("toolTitle",r.bold("Diff")),0,0)},renderResult(n,r,o,a){let l=n.details;if(l?.comparison?.equal)return new k(T(l.comparison),0,0);let s=i.getToolRenderer("diff")?.renderResult;return s?s(n,r,o,a):new k(n.content.filter(t=>t.type==="text").map(t=>t.text).join(`
|
|
4
|
-
`),0,0)},async execute(n,r,o,a,l){let s=c();if(s===void 0)throw new Error("Diff requires the read extension");try{let t=await fe(s,r,{cwd:l.cwd,signal:o}),f=T(t),m=q(f),y=m.truncated?await s.saveTemporary(f):void 0,p=y===void 0?"":`
|
|
5
|
-
Full diff: ${y}`;return O({content:[{type:"text",text:y===void 0?f:q(f,{maxLines:ae-2,maxBytes:se-Buffer.byteLength(p)}).content+p}],details:{...P(t,l.cwd),comparison:t,temporarySource:y}},j,{status:"success",data:{kind:"diff",equal:t.equal,before:{source:t.before.source,sources:t.before.sources},after:{source:t.after.source,sources:t.after.sources},stats:t.stats,diff:m.content,truncated:m.truncated,...y===void 0?{}:{fullResult:y}},errors:[]})}catch(t){if(o?.aborted)throw t;let f=_(t,"DIFF_FAILED");return O({content:[{type:"text",text:f.message}],details:{}},j,{status:"error",errors:[f]})}}})}u(Le,"registerDiff");import{parser as Y}from"@lezer/javascript";import{TreeFragment as W}from"@lezer/common";var pe=new Set(["read","search","diff","open","createFile","deleteFile","copyFile","moveFile","flush","result"]);function z(e,i=Y.parse(e)){let c=[];i.iterate({enter(r){if(r.name==="AssignmentExpression"){let t=r.node.firstChild;t?.name==="VariableName"&&c.push({name:e.slice(t.from,t.to),from:0,to:e.length})}if(r.name!=="VariableDefinition")return;let o=r.node.parent;for(;o?.parent&&!["VariableDeclaration","ParamList","Block","Script"].includes(o.name);)o=o.parent;let a=o?.name==="VariableDeclaration"&&o.firstChild?.name==="var",l=new Set(["Script","FunctionDeclaration","FunctionExpression","ArrowFunction",...a?[]:["Block"]]),s=r.node.parent;for(s?.name==="FunctionDeclaration"&&(s=s.parent);s?.parent&&!l.has(s.name);)s=s.parent;c.push({name:e.slice(r.from,r.to),from:s?.from??0,to:s?.to??e.length})}});let n=[];return i.iterate({enter(r){if(r.name!=="CallExpression")return;let o=r.node.firstChild;if(o?.name!=="VariableName")return;let a=e.slice(o.from,o.to);if(!pe.has(a)||c.some(t=>t.name===a&&t.from<=r.from&&t.to>=r.to))return;let l=r.node.getChild("ArgList")?.getChild("ObjectExpression"),s=Object.create(null);if(!l){let t=r.node.getChild("ArgList"),f=t?e.slice(t.from+1,t.to).replace(/\)$/,""):"";f&&(s.arguments={text:f.length>160?f.slice(0,120)+"\u2026":f,literal:!1})}for(let t of l?.getChildren("Property")??[]){let f=t.firstChild,y=(f?e.slice(f.from,f.to):"").replace(/^["']|["']$/g,"");if(!/^[a-zA-Z_$][\w$]*$/.test(y)){for(let ie of["path","query","target","before","after"])delete s[ie];let x=e.slice(t.from,t.to);s[`argument@${t.from}`]={text:x.length>160?x.slice(0,160)+"\u2026":x,literal:!1};continue}let p=t.lastChild;if(!p||p.type.isError||p.name===":")continue;let g=e.slice(p.from,p.to),d=g.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t"),w=/^(?:["'])(?:\d+#[0-9A-F]+|CHANGE#[0-9A-F]+|begin|end|scope-(?:begin|end)-[^"']+)["']$/.test(g);s[y]={text:d.length>160&&!w?`${d.slice(0,100)}\u2026${d.slice(-40)} (${g.length} source chars)`:d,literal:["String","Number","BooleanLiteral","Null"].includes(p.name)&&p.lastChild?.type.isError!==!0}}return n.push({name:a,from:r.from,to:r.to,path:s.path,query:s.query,target:s.target,before:s.before,after:s.after,arguments:s}),!1}}),n}u(z,"parseApplyCalls");function ue(e,i=z(e),c,n=r=>r){let r=0,o=[],a=u(l=>n(l.split(`
|
|
6
|
-
`).map(s=>s.length>200?s.slice(0,200)+"\u2026":s).join(`
|
|
7
|
-
`)),"codePreview");for(let l of i)o.push(a(e.slice(r,l.from))),o.push(c?.(l)??`${l.name}(${l.path?l.path.literal?l.path.text:`\u2039${l.path.text}\u203A`:"\u2026"})`),r=l.to;return o.push(a(e.slice(r))),o.join("")}u(ue,"compactApplySource");function G(e,i){let c="",n="",r=[];return o=>{if(o===c)return n;let a=0;for(;a<c.length&&a<o.length&&c[a]===o[a];)a++;r=W.applyChanges(r,[{fromA:a,toA:c.length,fromB:a,toB:o.length}]);let l=Y.parse(o,r);return r=W.addTree(l),n=ue(o,z(o,l),e,i),c=o,n}}u(G,"createApplySourceProjection");import{lstat as Z,unlink as de}from"node:fs/promises";import K from"node:path";import X from"fs-extra";import{Type as b}from"typebox";import{Value as me}from"typebox/value";var D=b.String({minLength:1,description:"Local regular file path, relative to cwd or absolute."}),ge=b.Object({path:D},{additionalProperties:!1}),ye=b.Object({path:D,target:D,overwrite:b.Optional(b.Boolean({description:"Allow replacing an existing regular target file. Defaults to false."}))},{additionalProperties:!1});function E(e){return e!==null&&typeof e=="object"&&"kind"in e&&e.kind==="file-operation"}u(E,"isFileOperationResult");function C(e){return[`${e.operation}: ${e.effect}`,e.path,e.target===void 0?void 0:`Target: ${e.target}`,e.error===void 0?void 0:`${e.error.code}: ${e.error.message}`].filter(i=>i!==void 0).join(`
|
|
8
|
-
`)}u(C,"formatFileOperation");async function ze(e,i,c,n){let r=!1,o,a;try{let l=e==="delete"?ge:ye;if(!me.Check(l,i))throw Object.assign(new Error("Invalid file operation arguments"),{code:"INVALID_ARGUMENTS"});let s=i;o=K.resolve(c,s.path),a=s.target===void 0?void 0:K.resolve(c,s.target),n?.throwIfAborted();let t=await he(o);if(a!==void 0){let f=await we(a);if(f!==void 0){if(!f.isFile()||f.isSymbolicLink())throw Object.assign(new Error("Target must be a regular file"),{code:"INVALID_FILE_TYPE"});if(o===a||t.ino===f.ino&&t.dev===f.dev)throw Object.assign(new Error("Source and target are the same file"),{code:"SAME_FILE"});if(s.overwrite!==!0)throw Object.assign(new Error("Target exists; use overwrite: true to replace it"),{code:"EEXIST"})}}return n?.throwIfAborted(),r=!0,e==="delete"?await de(o):a!==void 0&&(e==="copy"?await X.copy(o,a,{overwrite:s.overwrite===!0,errorOnExist:!0}):await X.move(o,a,{overwrite:s.overwrite===!0})),{kind:"file-operation",operation:e,ok:!0,effect:"applied",path:o,...a===void 0?{}:{target:a}}}catch(l){return{kind:"file-operation",operation:e,ok:!1,effect:r?"unknown":"not-applied",...o===void 0?{}:{path:o},...a===void 0?{}:{target:a},error:{code:l!==null&&typeof l=="object"&&"code"in l?String(l.code):"FILE_OPERATION_FAILED",message:l instanceof Error?l.message:String(l)}}}}u(ze,"executeFileOperation");async function he(e){let i=await Z(e);if(!i.isFile()||i.isSymbolicLink())throw Object.assign(new Error("Source must be a regular file"),{code:"INVALID_FILE_TYPE"});return i}u(he,"regularFile");async function we(e){try{return await Z(e)}catch(i){if(i!==null&&typeof i=="object"&&"code"in i&&i.code==="ENOENT")return;throw i}}u(we,"optionalStat");import{Text as ne}from"@earendil-works/pi-tui";function Q(e){let i=e.select(),c=e.mutationValues().filter(xe);return i.files.map(n=>{let r=c.flatMap(l=>l.files.filter(s=>s.source===n.source).map(s=>({outcome:l,changed:s}))),o=e.mutationPresentation(n.source)?.data,a=o?.afterContent===n.after?o:void 0;return new R({ok:!0,path:n.source,files:[{path:n.source,action:n.before===null?"created":"edited"}],snapshot:{content:n.before??""},beforeContentMap:{[n.source]:n.before},afterContent:n.after??"",afterDocument:a?.afterDocument,resultPresentation:a?.resultPresentation,scopeMarkers:a?.scopeMarkers,hints:a?.hints,warnings:a?.warnings,diffStatuses:a?.diffStatuses,diffs:[A(n.source,n.before??"",n.after??"").diff],operations:r.map(({outcome:l,changed:s})=>({operation:l.operation==="remove"?"delete":l.operation,changes:s.changes.length})),formatting:a?.formatting??r.at(-1)?.changed.formatting})})}u(Q,"finalApplyMutations");function xe(e){return e!==null&&typeof e=="object"&&"operation"in e&&"files"in e&&Array.isArray(e.files)&&"effect"in e}u(xe,"isMutation");import{highlightCode as oe}from"@earendil-works/pi-coding-agent";import{wrapTextWithAnsi as ee,visibleWidth as te,truncateToWidth as be}from"@earendil-works/pi-tui";function ft(e,i,c,n=process.cwd()){let r=e.select(),o=[...r.automatic,...r.explicit.filter(t=>t.kind==="operation")].filter(t=>S(t.value)&&!t.value.equal),a=o.flatMap(t=>S(t.value)?[P(t.value,n)]:[]),l=new Set(o.flatMap(t=>t.presentation?.content??[]));if(r.files.length===0){let t=[...r.automatic.map(f=>f.presentation),...r.explicit.map(f=>f.kind==="operation"?f.presentation:void 0)].filter(f=>f!==void 0);return{comparisons:a,cwd:n,blocks:[...i.content.filter(f=>!l.has(f)).flatMap(f=>f.type==="text"?[{text:re(f.text),read:t.find(m=>m.content.includes(f))}]:[])]}}let s=i.mutations??Q(e);return{...s.length>0?{mutations:{results:s}}:{},comparisons:a,cwd:n,blocks:[...r.explicit.flatMap(t=>t.kind==="operation"&&S(t.value)&&!t.value.equal?[]:E(t.value)?[{text:C(t.value)}]:t.kind==="operation"?t.presentation?.content.flatMap(f=>f.type==="text"?[{text:f.text,read:t.presentation}]:[])??[]:[{text:re(typeof t.value=="string"?t.value:t.value===void 0?"undefined":JSON.stringify(t.value,null,2))}]),...r.automatic.flatMap(({value:t,presentation:f})=>{if(E(t))return[{text:C(t)}];if(t!==null&&typeof t=="object"&&"kind"in t&&t.kind==="index-operation")return f?.content.flatMap(m=>m.type==="text"?[{text:m.text}]:[])??[];if(t===null||typeof t!="object"||!("errors"in t)||!Array.isArray(t.errors))return[];if("operations"in t&&Array.isArray(t.operations)){let m=t.operations.filter(p=>p!==null&&typeof p=="object"&&"status"in p&&p.status==="applied").length;if(m===t.operations.length)return[];let y=t.operations.filter(p=>p!==null&&typeof p=="object"&&"status"in p&&p.status!=="applied").map(p=>({text:Oe(p)}));return[{text:`Apply partially applied: ${m} of ${t.operations.length} operations completed.`},...y]}return t.errors.flatMap(m=>m!==null&&typeof m=="object"&&"message"in m&&typeof m.message=="string"?[{text:m.message}]:[])}),...c===void 0?[]:[{text:c instanceof Error?c.message:JSON.stringify(c)}]]}}u(ft,"createApplyDisplay");function F(e,i,c,n,r,o,a=!1){let l=Math.max(1,c);if(l<5)return e.split(`
|
|
9
|
-
`).flatMap(d=>ee(d,l));let s=l-4,t=u(d=>i.fg("borderMuted",d),"border"),m=be(` ${n==="call"?"Apply \xB7 JavaScript":"Result"} `,l-4,""),y=[t(`${n==="call"?"\u256D":"\u251C"}\u2500`)+i.fg(a?"error":"accent",m)+t(`${"\u2500".repeat(Math.max(0,l-te(m)-3))}${n==="call"?"\u256E":"\u2524"}`)],p=`${t("\u2502")}${" ".repeat(l-2)}${t("\u2502")}`;for(let d of e.split(`
|
|
10
|
-
`)){let w=o==="diff"?i.fg(d.startsWith("+")?"toolDiffAdded":d.startsWith("-")?"toolDiffRemoved":"toolDiffContext",d):o?oe(d,o).join(`
|
|
11
|
-
`):i.fg("toolOutput",d);for(let x of ee(w,s))y.push(`${t("\u2502")} ${x}${" ".repeat(Math.max(0,s-te(x)))} ${t("\u2502")}`)}n==="call"&&y.push(p),r&&y.push(t(`\u2570${"\u2500".repeat(l-2)}\u256F`));let g=i.getBgAnsi("toolPendingBg");return y.map(d=>g+$(d,g)+"\x1B[0m")}u(F,"applyFrameRows");function Ae(e,i="compact"){return(c,n,r)=>{if(!r.expanded&&i==="disabled")return new ne(n.fg("toolTitle","apply"),0,0);let o=r.state,a=o.projectSource??=G(e?s=>e(s,n):void 0,e?s=>oe(s,"javascript").join(`
|
|
12
|
-
`):void 0),l=c!==null&&typeof c=="object"&&"source"in c&&typeof c.source=="string"?c.source:"";return{invalidate(){},render(s){return F(r.expanded||i==="full"?o.displaySource??l:i==="disabled"?"":Re(a(o.displaySource??l)),n,s,"call",!o.applyResultReady,r.expanded||i==="full"||!e?"javascript":void 0)}}}}u(Ae,"createApplyCallRenderer");function Re(e,i=N){let c=e.split(`
|
|
13
|
-
`);if(c.length<=i)return e;let n=Math.max(2,i-1),r=Math.ceil(n/2),o=Math.floor(n/2),a=c.length-r-o;return[...c.slice(0,r),`\u2026 ${a} lines omitted \u2026`,...c.slice(-o)].join(`
|
|
14
|
-
`)}u(Re,"compactApplyPreview");var pt=Ae();function Se(e){return(i,c,n,r)=>{r.state.applyResultReady=!0;let o=i.details;r.state.displaySource=o?.displaySource;let a=o?.display,l=a?.blocks??[{text:r.isError?"Apply failed":"Apply finished"}],s=L({kind:"source"}),t=l.map(p=>s(p.read??{content:[{type:"text",text:p.text}],details:ke(p.text)},c,n,{...r,isError:!1,lastComponent:void 0})),f=a?.mutations,m=(a?.comparisons??[]).flatMap(p=>[e?.(p,n,c.expanded,a?.cwd??process.cwd())??new ne((p.results??[]).flatMap(d=>d.data.diffs??[]).join(`
|
|
15
|
-
`),0,0)]),y=f===void 0?void 0:e?.(f,n,c.expanded,a?.cwd??process.cwd());return{invalidate(){y?.invalidate();for(let p of m)p.invalidate()},render(p){let g=[];for(let d of t){let w=d.render(Math.max(1,p-4));w.length!==0&&(g.length>0&&g.push(""),g.push(...w))}for(let d of m)g.length>0&&g.push(""),g.push(...d.render(Math.max(1,p-4)));if(y!==void 0){let d=y.render(Math.max(1,p-4));g.length>0&&d.length>0&&g.push(""),g.push(...d),d.length===0&&g.push(...(f?.results??[]).map(w=>w.path??"Changed file"))}else f!==void 0&&g.push(...(f.results??[]).map(d=>d.path??"Changed file"));return g.length===0&&l.length>0&&l.every(d=>d.read?.details.diagnosticCheck?.complete&&d.read.details.diagnosticCheck.count===0)?F("",n,p,"result",!0).slice(-1):F(g.length===0?"No output":g.join(`
|
|
16
|
-
`),n,p,"result",!0,void 0,r.isError)}}}}u(Se,"createApplyResultRenderer");function Oe(e){if(e===null||typeof e!="object")return String(e);let i="index"in e?Number(e.index)+1:"?",c="kind"in e?String(e.kind):"operation",n="status"in e?String(e.status):"unknown",r="error"in e&&e.error!==null&&typeof e.error=="object"?`: ${"code"in e.error?String(e.error.code):"ERROR"}: ${"message"in e.error?String(e.error.message):"Operation failed"}`:"";return`Operation ${i} (${c}): ${n}${r}`}u(Oe,"formatDisplayOutcome");function re(e){if(/^(?:Undo transaction:|Undo available)/u.test(e.trim()))return"";try{let i=JSON.parse(e);return JSON.stringify(M(i),null,2)}catch{return e.replace(/APPLY#[0-9A-F]{12}/gu,"Apply transaction")}}u(re,"redactApplyReceipts");function M(e){return Array.isArray(e)?e.map(M):e===null||typeof e!="object"?e:Object.fromEntries(Object.entries(e).filter(([i])=>i!=="transaction").map(([i,c])=>[i,M(c)]))}u(M,"redactTransactionKeys");function ke(e){try{let i=JSON.parse(e);return i!==null&&typeof i=="object"?{source:"result.json"}:{}}catch{return{}}}u(ke,"jsonDetails");var ut=Se();export{j as a,fe as b,S as c,Ne as d,Le as e,ze as f,Q as g,ft as h,Ae as i,pt as j,Se as k,ut as l};
|