pi-agent-ide 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/README.md +10 -3
- package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
- package/dist/chunk-3HYXQ4YA.js +28 -0
- package/dist/chunk-3JO7QFIL.js +1 -0
- package/dist/chunk-4NIFBFFR.js +11 -0
- package/dist/{chunk-VCTK4JSN.js → chunk-64M3SQPG.js} +1 -1
- package/dist/{chunk-5QQABP47.js → chunk-7LD2OQH3.js} +1 -1
- package/dist/chunk-7LZKOHH2.js +1 -0
- package/dist/chunk-AJRIASPQ.js +2 -0
- package/dist/chunk-EAZGN5ND.js +7 -0
- package/dist/{chunk-ZM4L5AGN.js → chunk-EDURPQAV.js} +3 -2
- package/dist/{chunk-GIRAEVUJ.js → chunk-F5YZG77W.js} +1 -1
- package/dist/chunk-FK42RSF4.js +1 -0
- package/dist/{chunk-O6LE42GK.js → chunk-FXNKMNSJ.js} +1 -1
- package/dist/chunk-GBLKIB6O.js +2 -0
- package/dist/chunk-KBP3QUDT.js +2 -0
- package/dist/chunk-KR36BT5E.js +1 -0
- package/dist/{chunk-NTYXZ3EL.js → chunk-KVHDMIZS.js} +1 -1
- package/dist/{chunk-QDST6VIU.js → chunk-KZC7TI5M.js} +1 -1
- package/dist/chunk-OE7QVAI2.js +5 -0
- package/dist/{chunk-GUTQ3PWL.js → chunk-PLKYHUNT.js} +1 -1
- package/dist/chunk-PNU3E7IO.js +3 -0
- package/dist/chunk-PS2B6THP.js +3 -0
- package/dist/chunk-PYPPV2F5.js +25 -0
- package/dist/{chunk-25CZ5ZIU.js → chunk-QFTBY67N.js} +3 -3
- package/dist/chunk-S5LXX32D.js +28 -0
- package/dist/chunk-SILJ3OL4.js +9 -0
- package/dist/chunk-SQKAXYIR.js +2 -0
- package/dist/chunk-VCGNVTXQ.js +1 -0
- package/dist/chunk-XYS4FSCC.js +12 -0
- package/dist/chunk-YGGKGZO2.js +1 -0
- package/dist/{chunk-L7JMDDSD.js → chunk-YRF7OATP.js} +1 -1
- package/dist/chunk-ZPT5D4VP.js +2 -0
- package/dist/entry-0.js +1 -1
- package/dist/entry-11.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-16.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-25.js +2 -2
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +1 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +11 -9
- package/dist/entry-33.js +1 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-42.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +12 -11
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +3 -6
- package/dist/entry-51.js +11 -9
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-55.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-57.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +0 -1
- package/dist/entry-62.js +1 -0
- package/dist/entry-63.js +0 -1
- package/dist/entry-64.js +1 -0
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-72.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-77.js +50 -307
- package/dist/entry-78.js +14 -26
- package/dist/entry-79.js +2 -2
- package/dist/entry-80.js +1 -1
- package/dist/entry-81.js +1 -1
- package/dist/entry-82.js +5 -3
- package/dist/entry-83.js +1 -1
- package/dist/entry-84.js +1 -1
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +15 -3
- package/docs/agent-guides/editing.md +31 -3
- package/docs/agent-guides/git-changes.md +1 -1
- package/docs/agent-guides/json-reading.md +19 -3
- package/docs/agent-guides/read-resources.md +15 -1
- package/docs/agent-guides/search-code.md +43 -2
- package/docs/agent-guides/select-code.md +194 -0
- package/docs/agent-guides/terminal.md +1 -1
- package/docs/code-review.md +99 -0
- package/docs/configuration.md +36 -7
- package/docs/development.md +16 -19
- package/docs/nightly.md +7 -0
- package/docs/releases.md +42 -0
- package/docs/research/apply-native-capability-matrix.md +174 -0
- package/docs/research/apply-read-latency.md +2 -0
- package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
- package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
- package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
- package/docs/research/native-codemode-batch-decision.md +29 -0
- package/docs/research/native-codemode-batching.md +65 -0
- package/docs/structured-results.md +86 -0
- package/docs/tools.md +24 -4
- package/docs/user-hooks.md +1 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-documentation/src/index.ts +1 -1
- package/node_modules/pi-agent-filesystem/index.ts +6 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -6
- package/node_modules/pi-agent-filesystem/src/path-recovery.ts +109 -0
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +15 -10
- package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -2
- package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +6 -2
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +110 -7
- package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +251 -0
- package/node_modules/pi-agent-ide-changes/index.ts +2 -24
- package/node_modules/pi-agent-ide-changes/package.json +8 -7
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +126 -48
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lsp/index.ts +2 -2
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +92 -30
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/node_modules/pi-agent-read/src/api/tools/read.ts +35 -2
- package/node_modules/pi-agent-read/src/core/extension.ts +11 -0
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
- package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +127 -73
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +22 -0
- package/node_modules/pi-agent-resource/src/resource-access.ts +55 -0
- package/node_modules/pi-agent-resource/src/resource-scheduler.ts +204 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +233 -0
- package/node_modules/pi-agent-resource/src/tool-result.ts +125 -0
- package/node_modules/pi-agent-search/package.json +5 -4
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +13 -6
- package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
- package/node_modules/pi-agent-search/src/api/search.ts +39 -0
- package/node_modules/pi-agent-search/src/api/structured-result.ts +148 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +90 -24
- package/node_modules/pi-agent-search/src/core/search-core.ts +145 -78
- package/node_modules/pi-agent-search-text/index.ts +6 -1
- package/node_modules/pi-agent-search-text/package.json +7 -6
- package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +174 -26
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +201 -18
- package/node_modules/pi-agent-search-text/src/search-query.ts +42 -34
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +18 -4
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +90 -259
- package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +110 -17
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/text-document.ts +15 -10
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +4 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-editor/index.ts +4 -7
- package/node_modules/pi-agent-text-editor/package.json +20 -21
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +78 -41
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +12 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +35 -4
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +820 -0
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +412 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +149 -139
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +236 -185
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +253 -203
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/node_modules/pi-agent-text-editor-renderer/index.ts +9 -73
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -5
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +276 -129
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +16 -1
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
- package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
- package/node_modules/pi-agent-web/index.ts +23 -0
- package/node_modules/pi-agent-web/package.json +7 -6
- package/node_modules/pi-agent-web/src/search.ts +221 -0
- package/node_modules/pi-agent-web-html/package.json +2 -2
- package/node_modules/pi-agent-web-image/package.json +3 -3
- package/node_modules/pi-agent-web-pdf/package.json +3 -3
- package/node_modules/pi-agent-web-text/package.json +3 -3
- package/package.json +42 -37
- package/skills/capture-code-review-rule/SKILL.md +60 -0
- package/src/code-review/config.ts +68 -0
- package/src/code-review/extension.ts +105 -0
- package/src/code-review/fragments.ts +26 -0
- package/src/code-review/reviewer.ts +198 -0
- package/src/composite/host-version.ts +13 -0
- package/src/composite/module-labels.ts +1 -1
- package/src/composite/nested-tool-rendering.ts +298 -0
- package/src/composite/preferences.ts +0 -5
- package/src/composite/tool-availability.ts +90 -0
- package/src/core/extension.ts +2 -0
- package/src/documentation/extension.ts +81 -145
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +6 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/path-recovery.ts +109 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +221 -0
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +35 -2
- package/src/extensions/pi-agent-read/src/core/extension.ts +11 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +9 -10
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +28 -15
- package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +127 -73
- package/src/extensions/pi-agent-search/package.json +5 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +6 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +174 -26
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +201 -18
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +42 -34
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +18 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +90 -259
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +110 -17
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +13 -6
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +39 -0
- package/src/extensions/pi-agent-search/src/api/structured-result.ts +148 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +90 -24
- package/src/extensions/pi-agent-search/src/core/search-core.ts +145 -78
- package/src/extensions/pi-agent-text-editor/index.ts +4 -7
- package/src/extensions/pi-agent-text-editor/package.json +20 -21
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/anchor.ts +4 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +9 -73
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +276 -129
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +36 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +28 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +40 -10
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +16 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +6 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +12 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +78 -41
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +8 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +12 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +35 -4
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +820 -0
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +20 -6
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +412 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +149 -139
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +236 -185
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +253 -203
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +25 -5
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +8 -4
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/src/pi-agent-ide.ts +61 -8
- package/src/plugins/pi-agent-ide-ast/package.json +15 -10
- package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -2
- package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +6 -1
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +6 -2
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +110 -7
- package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +251 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +2 -24
- package/src/plugins/pi-agent-ide-changes/package.json +8 -7
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +5 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +126 -48
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- package/src/plugins/pi-agent-ide-debugger/index.ts +63 -17
- package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +18 -2
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +24 -4
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +68 -2
- package/src/plugins/pi-agent-ide-debugger/src/java-runtime.ts +357 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +55 -3
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +13 -13
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lsp/index.ts +2 -2
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +92 -30
- package/src/plugins/pi-agent-ide-terminal/index.ts +12 -2
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +1 -1
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +65 -30
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +16 -37
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +1 -0
- package/src/plugins/pi-agent-ide-terminal/src/shell-result.ts +100 -0
- package/src/plugins/pi-agent-ide-terminal/src/steering.ts +62 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +98 -46
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +3 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +15 -6
- package/src/plugins/pi-agent-ide-vision/index.ts +35 -1
- package/dist/chunk-3E2NTWCN.js +0 -2
- package/dist/chunk-4LUW26BX.js +0 -10
- package/dist/chunk-4U2GUKNJ.js +0 -0
- package/dist/chunk-5VSE5X5R.js +0 -2
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/chunk-7WCZOO5I.js +0 -1
- package/dist/chunk-CEX3VOJ7.js +0 -2
- package/dist/chunk-FA6BKC5Y.js +0 -1
- package/dist/chunk-FEDVTZJG.js +0 -1
- package/dist/chunk-HMLH43ZS.js +0 -4
- package/dist/chunk-ITSNK5YG.js +0 -7
- package/dist/chunk-KII2JQC5.js +0 -1
- package/dist/chunk-LVWMWWWF.js +0 -28
- package/dist/chunk-P7XO5CIP.js +0 -2
- package/dist/chunk-PZFOOHY2.js +0 -15
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/chunk-S3ZPXWX7.js +0 -2
- package/dist/chunk-T7CZIACQ.js +0 -27
- package/dist/chunk-VXD6FZP5.js +0 -5
- package/dist/chunk-YHUTTZC6.js +0 -2
- package/dist/chunk-YT42LKFV.js +0 -16
- package/docs/agent-guides/apply.md +0 -333
- package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -155
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -344
- package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -133
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -148
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -920
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
- package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -155
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -344
- package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -133
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -148
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -920
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +0 -52
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type TextContent,
|
|
8
8
|
} from "pi-agent-resource";
|
|
9
9
|
import { Type } from "typebox";
|
|
10
|
+
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
10
11
|
import { Value } from "typebox/value";
|
|
11
12
|
|
|
12
13
|
import type { ToolDefinition, TruncationResult } from "@earendil-works/pi-coding-agent";
|
|
@@ -50,12 +51,19 @@ export interface ReadFailure {
|
|
|
50
51
|
readonly stage?: ReadPipelineStage;
|
|
51
52
|
readonly message: string;
|
|
52
53
|
readonly cause?: unknown;
|
|
54
|
+
/** Ranked exact paths offered as hints, never read automatically. */
|
|
55
|
+
readonly candidates?: readonly { readonly path: string }[];
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
export type ReadResultRenderer = NonNullable<ToolDefinition["renderResult"]>;
|
|
56
59
|
export type ReadCallRenderer = NonNullable<ToolDefinition["renderCall"]>;
|
|
57
60
|
|
|
58
61
|
export interface ResourceResolverRegistration {
|
|
62
|
+
/** Offers recovery hints after this resolver fails to resolve or read a source. */
|
|
63
|
+
readonly recoverFailure?: (
|
|
64
|
+
failure: ReadFailure,
|
|
65
|
+
context: ResourceResolverContext,
|
|
66
|
+
) => Promise<ReadFailure["candidates"]>;
|
|
59
67
|
readonly resolver: ResourceResolver;
|
|
60
68
|
/** Selects a resolver-specific call header before resource resolution. */
|
|
61
69
|
readonly matchesCall?: (source: string) => boolean;
|
|
@@ -136,6 +144,8 @@ export interface ReadPipelineContext {
|
|
|
136
144
|
/** Data execution keeps full requested content; presentation handlers must not compact it. */
|
|
137
145
|
readonly audience?: "agent" | "script";
|
|
138
146
|
readonly request: ReadRequest;
|
|
147
|
+
/** Original RESULT# scope bounds source authority even when Read shows surrounding lines. */
|
|
148
|
+
readonly sourceTarget?: string;
|
|
139
149
|
readonly resolverContext: ResourceResolverContext;
|
|
140
150
|
readonly state?: ReadState;
|
|
141
151
|
readonly result?: ReadToolResult;
|
|
@@ -187,14 +197,22 @@ export type ReadScriptData =
|
|
|
187
197
|
readonly byteLength: number;
|
|
188
198
|
readonly totalBytes: number;
|
|
189
199
|
readonly bytes: readonly number[];
|
|
200
|
+
readonly truncated?: boolean;
|
|
190
201
|
}
|
|
191
202
|
| {
|
|
192
203
|
readonly kind: "text";
|
|
204
|
+
/** Strict source-window handle, independent of preview truncation. */
|
|
205
|
+
readonly target?: string;
|
|
193
206
|
readonly source: string;
|
|
194
207
|
readonly content: string;
|
|
195
208
|
readonly lines: readonly ReadTextLine[];
|
|
196
209
|
readonly startLine: number;
|
|
197
210
|
readonly endLine: number;
|
|
211
|
+
readonly references?: readonly {
|
|
212
|
+
readonly value: string;
|
|
213
|
+
readonly kind: string;
|
|
214
|
+
readonly state?: string;
|
|
215
|
+
}[];
|
|
198
216
|
readonly totalLines: number;
|
|
199
217
|
}
|
|
200
218
|
| {
|
|
@@ -208,7 +226,8 @@ export type ReadScriptData =
|
|
|
208
226
|
readonly resources: readonly ReadScriptData[];
|
|
209
227
|
};
|
|
210
228
|
export interface ReadToolResult {
|
|
211
|
-
|
|
229
|
+
readonly structuredContent?: AgentToolResult<ReadResultDetails>["structuredContent"];
|
|
230
|
+
/** Canonical adapter data; never reconstructed from rendered text or stored in renderer details. */
|
|
212
231
|
readonly script?: ReadScriptData;
|
|
213
232
|
readonly content: (TextContent | ImageContent)[];
|
|
214
233
|
readonly details: ReadResultDetails;
|
|
@@ -216,7 +235,16 @@ export interface ReadToolResult {
|
|
|
216
235
|
}
|
|
217
236
|
|
|
218
237
|
export type ReadStageOutcome =
|
|
219
|
-
| {
|
|
238
|
+
| {
|
|
239
|
+
readonly kind: "continue";
|
|
240
|
+
readonly context: ReadPipelineContext;
|
|
241
|
+
/**
|
|
242
|
+
* Post-read handlers inspect the same base result concurrently. Return a pure
|
|
243
|
+
* decoration here; transforms apply in registration order, unless a handler
|
|
244
|
+
* returns a final result. Context changes are ignored during post-read.
|
|
245
|
+
*/
|
|
246
|
+
readonly transform?: (result: ReadToolResult) => ReadToolResult;
|
|
247
|
+
}
|
|
220
248
|
| { readonly kind: "return"; readonly result: ReadToolResult };
|
|
221
249
|
|
|
222
250
|
export type ReadPreReadHandler = ReadPipelineHandler;
|
|
@@ -413,3 +441,8 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
413
441
|
}
|
|
414
442
|
|
|
415
443
|
export { readParameters } from "#src/api/read-parameters.js";
|
|
444
|
+
export {
|
|
445
|
+
readDataSchema,
|
|
446
|
+
readOutputSchema,
|
|
447
|
+
structuredRead,
|
|
448
|
+
} from "#src/core/tools/read/structured-result.js";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { connectResultTargets } from "pi-agent-resource";
|
|
3
|
+
import { createReadResultTargetHandler } from "#src/core/tools/read/result-target.js";
|
|
2
4
|
import { connectAgentDocumentation, loadPackagedAgentGuide } from "pi-agent-documentation";
|
|
3
5
|
import {
|
|
4
6
|
ToolCallInterceptionRenderStore,
|
|
@@ -35,6 +37,15 @@ export default async function registerReadCore(
|
|
|
35
37
|
}),
|
|
36
38
|
]);
|
|
37
39
|
const core = createReadCore(parsePresentation(context?.preferences["ui.read"]));
|
|
40
|
+
const targets = connectResultTargets(pi);
|
|
41
|
+
await core.registerPlugin({
|
|
42
|
+
protocol: READ_PROTOCOL,
|
|
43
|
+
apiVersion: READ_API_VERSION,
|
|
44
|
+
id: "result-targets",
|
|
45
|
+
setup(api) {
|
|
46
|
+
api.addHandler({ stage: "post-read", handler: createReadResultTargetHandler(targets) });
|
|
47
|
+
},
|
|
48
|
+
});
|
|
38
49
|
|
|
39
50
|
const unsubscribeRegistration = pi.events.on(READ_PLUGIN_REGISTER_EVENT, (request) => {
|
|
40
51
|
if (!isReadPluginRegistrationRequest(request)) {
|
|
@@ -107,16 +107,15 @@ export async function readRaw(
|
|
|
107
107
|
byteLength: count,
|
|
108
108
|
totalBytes: stat.size,
|
|
109
109
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}),
|
|
110
|
+
script: {
|
|
111
|
+
kind: "bytes",
|
|
112
|
+
source,
|
|
113
|
+
byteOffset: start,
|
|
114
|
+
byteLength: count,
|
|
115
|
+
totalBytes: stat.size,
|
|
116
|
+
bytes: Array.from(bytes),
|
|
117
|
+
truncated: count < requestedLength,
|
|
118
|
+
},
|
|
120
119
|
};
|
|
121
120
|
} finally {
|
|
122
121
|
await handle.close();
|
|
@@ -65,9 +65,7 @@ export function projectReadState(
|
|
|
65
65
|
const projected = projectAgentContent(state.content);
|
|
66
66
|
|
|
67
67
|
return {
|
|
68
|
-
|
|
69
|
-
script: { kind: "native" as const, source: state.source, blocks: state.content },
|
|
70
|
-
}),
|
|
68
|
+
script: { kind: "native", source: state.source, blocks: state.content },
|
|
71
69
|
content: projected.content,
|
|
72
70
|
details: {
|
|
73
71
|
...readDetails(state),
|
|
@@ -104,17 +102,16 @@ export function projectReadState(
|
|
|
104
102
|
];
|
|
105
103
|
|
|
106
104
|
return {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}),
|
|
105
|
+
script: {
|
|
106
|
+
kind: "text",
|
|
107
|
+
...(state.text.references === undefined ? {} : { references: state.text.references }),
|
|
108
|
+
source: state.source,
|
|
109
|
+
content: lines.map((line) => line.content + line.lineEnding).join(""),
|
|
110
|
+
lines,
|
|
111
|
+
startLine: lines[0]?.lineNumber ?? 0,
|
|
112
|
+
endLine: lines.at(-1)?.lineNumber ?? 0,
|
|
113
|
+
totalLines,
|
|
114
|
+
},
|
|
118
115
|
content,
|
|
119
116
|
details: {
|
|
120
117
|
...readDetails(state),
|
|
@@ -140,7 +137,23 @@ function renderFinalTextLines(
|
|
|
140
137
|
|
|
141
138
|
export function failureResult(failure: ReadFailure): ReadToolResult {
|
|
142
139
|
return {
|
|
143
|
-
content: [
|
|
140
|
+
content: [
|
|
141
|
+
{
|
|
142
|
+
type: "text",
|
|
143
|
+
text: [
|
|
144
|
+
`${failure.code}: ${failure.message}`,
|
|
145
|
+
...(failure.candidates?.length
|
|
146
|
+
? [
|
|
147
|
+
"",
|
|
148
|
+
"Possible matches:",
|
|
149
|
+
...failure.candidates.map((candidate) => `- ${JSON.stringify(candidate.path)}`),
|
|
150
|
+
"",
|
|
151
|
+
"Retry read with an exact candidate path.",
|
|
152
|
+
]
|
|
153
|
+
: []),
|
|
154
|
+
].join("\n"),
|
|
155
|
+
},
|
|
156
|
+
],
|
|
144
157
|
details: { failure },
|
|
145
158
|
isError: true,
|
|
146
159
|
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import type { ResultRange, ResultTargetStore } from "pi-agent-resource";
|
|
3
|
+
import type { ReadPostReadHandler } from "#src/api/tools/read.js";
|
|
4
|
+
|
|
5
|
+
/** Attach source authority only when the read still maps to exact filesystem text. */
|
|
6
|
+
export function createReadResultTargetHandler(store: ResultTargetStore): ReadPostReadHandler {
|
|
7
|
+
return async (context) => {
|
|
8
|
+
const state = context.state;
|
|
9
|
+
if (state?.contentKind !== "text" || state.resolvedBy !== "filesystem")
|
|
10
|
+
return { kind: "continue", context };
|
|
11
|
+
let content: string;
|
|
12
|
+
try {
|
|
13
|
+
content = await readFile(state.source, {
|
|
14
|
+
encoding: "utf8",
|
|
15
|
+
signal: context.resolverContext.signal,
|
|
16
|
+
});
|
|
17
|
+
} catch {
|
|
18
|
+
context.resolverContext.signal?.throwIfAborted();
|
|
19
|
+
return { kind: "continue", context };
|
|
20
|
+
}
|
|
21
|
+
if (content !== state.text.content) return { kind: "continue", context };
|
|
22
|
+
const input =
|
|
23
|
+
context.sourceTarget === undefined
|
|
24
|
+
? undefined
|
|
25
|
+
: store.resolve(context.sourceTarget, context.resolverContext.cwd);
|
|
26
|
+
const sources = input?.targets.filter((target) => target.source === state.source);
|
|
27
|
+
if (sources?.some((target) => target.expectedContent !== content))
|
|
28
|
+
return { kind: "continue", context };
|
|
29
|
+
return {
|
|
30
|
+
kind: "continue",
|
|
31
|
+
context,
|
|
32
|
+
transform(result) {
|
|
33
|
+
const script = result.script;
|
|
34
|
+
if (result.isError || script?.kind !== "text" || script.source !== state.source)
|
|
35
|
+
return result;
|
|
36
|
+
if (
|
|
37
|
+
!script.lines.every((line) => {
|
|
38
|
+
const original = state.text.lines[line.lineNumber - 1];
|
|
39
|
+
return original?.content === line.content && original.lineEnding === line.lineEnding;
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
return result;
|
|
43
|
+
const first = script.lines[0];
|
|
44
|
+
const last = script.lines.at(-1);
|
|
45
|
+
const window: ResultRange | undefined =
|
|
46
|
+
first === undefined || last === undefined
|
|
47
|
+
? content.length === 0
|
|
48
|
+
? {
|
|
49
|
+
start: { lineNumber: 1, column: 0 },
|
|
50
|
+
end: { lineNumber: 1, column: 0 },
|
|
51
|
+
}
|
|
52
|
+
: undefined
|
|
53
|
+
: {
|
|
54
|
+
start: { lineNumber: first.lineNumber, column: 0 },
|
|
55
|
+
end:
|
|
56
|
+
last.lineEnding.length > 0
|
|
57
|
+
? { lineNumber: last.lineNumber + 1, column: 0 }
|
|
58
|
+
: { lineNumber: last.lineNumber, column: last.content.length },
|
|
59
|
+
linewise: true,
|
|
60
|
+
};
|
|
61
|
+
const ranges =
|
|
62
|
+
window === undefined
|
|
63
|
+
? []
|
|
64
|
+
: sources === undefined
|
|
65
|
+
? [window]
|
|
66
|
+
: sources.flatMap((source) =>
|
|
67
|
+
source.ranges.flatMap((range) => intersectRange(range, window)),
|
|
68
|
+
);
|
|
69
|
+
const target = store.register(
|
|
70
|
+
ranges.length === 0 ? [] : [{ source: state.source, expectedContent: content, ranges }],
|
|
71
|
+
context.resolverContext.cwd,
|
|
72
|
+
input?.complete ?? true,
|
|
73
|
+
);
|
|
74
|
+
return { ...result, script: { ...script, target } };
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function comparePosition(left: ResultRange["start"], right: ResultRange["start"]): number {
|
|
81
|
+
return left.lineNumber - right.lineNumber || left.column - right.column;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function intersectRange(range: ResultRange, window: ResultRange): ResultRange[] {
|
|
85
|
+
const start = comparePosition(range.start, window.start) >= 0 ? range.start : window.start;
|
|
86
|
+
const end = comparePosition(range.end, window.end) <= 0 ? range.end : window.end;
|
|
87
|
+
if (
|
|
88
|
+
comparePosition(start, end) > 0 ||
|
|
89
|
+
(comparePosition(start, end) === 0 && comparePosition(range.start, range.end) !== 0)
|
|
90
|
+
)
|
|
91
|
+
return [];
|
|
92
|
+
return [{ start, end }];
|
|
93
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { structuredResultSchema, withStructuredResult } from "pi-agent-resource";
|
|
3
|
+
import type { ReadScriptData, ReadToolResult } from "#src/api/tools/read.js";
|
|
4
|
+
import type { TextLine } from "pi-agent-text";
|
|
5
|
+
|
|
6
|
+
const reference = Type.Object(
|
|
7
|
+
{ value: Type.String(), kind: Type.String(), state: Type.Optional(Type.String()) },
|
|
8
|
+
{ additionalProperties: false },
|
|
9
|
+
);
|
|
10
|
+
const line = Type.Object(
|
|
11
|
+
{
|
|
12
|
+
lineNumber: Type.Integer(),
|
|
13
|
+
content: Type.String(),
|
|
14
|
+
lineEnding: Type.String(),
|
|
15
|
+
anchors: Type.Optional(Type.Array(Type.String())),
|
|
16
|
+
},
|
|
17
|
+
{ additionalProperties: false },
|
|
18
|
+
);
|
|
19
|
+
const continuation = Type.Object(
|
|
20
|
+
{ path: Type.String(), offset: Type.Integer() },
|
|
21
|
+
{ additionalProperties: false },
|
|
22
|
+
);
|
|
23
|
+
const common = {
|
|
24
|
+
source: Type.String(),
|
|
25
|
+
truncated: Type.Boolean(),
|
|
26
|
+
continuation: Type.Optional(continuation),
|
|
27
|
+
fullResult: Type.Optional(Type.String()),
|
|
28
|
+
};
|
|
29
|
+
const text = Type.Object(
|
|
30
|
+
{
|
|
31
|
+
...common,
|
|
32
|
+
kind: Type.Literal("text"),
|
|
33
|
+
target: Type.Optional(Type.String()),
|
|
34
|
+
lines: Type.Array(line),
|
|
35
|
+
startLine: Type.Integer(),
|
|
36
|
+
endLine: Type.Integer(),
|
|
37
|
+
totalLines: Type.Integer(),
|
|
38
|
+
references: Type.Optional(Type.Array(reference)),
|
|
39
|
+
},
|
|
40
|
+
{ additionalProperties: false },
|
|
41
|
+
);
|
|
42
|
+
const bytes = Type.Object(
|
|
43
|
+
{
|
|
44
|
+
...common,
|
|
45
|
+
kind: Type.Literal("bytes"),
|
|
46
|
+
bytes: Type.Array(Type.Integer({ minimum: 0, maximum: 255 })),
|
|
47
|
+
byteOffset: Type.Integer(),
|
|
48
|
+
byteLength: Type.Integer(),
|
|
49
|
+
totalBytes: Type.Integer(),
|
|
50
|
+
},
|
|
51
|
+
{ additionalProperties: false },
|
|
52
|
+
);
|
|
53
|
+
const block = Type.Union([
|
|
54
|
+
Type.Object({ type: Type.Literal("text"), text: Type.String() }, { additionalProperties: false }),
|
|
55
|
+
Type.Object(
|
|
56
|
+
{ type: Type.Literal("image"), data: Type.String(), mimeType: Type.String() },
|
|
57
|
+
{ additionalProperties: false },
|
|
58
|
+
),
|
|
59
|
+
]);
|
|
60
|
+
const native = Type.Object(
|
|
61
|
+
{ ...common, kind: Type.Literal("native"), blocks: Type.Array(block) },
|
|
62
|
+
{ additionalProperties: false },
|
|
63
|
+
);
|
|
64
|
+
export const readDataSchema = Type.Union([
|
|
65
|
+
Type.Object(
|
|
66
|
+
{
|
|
67
|
+
kind: Type.Literal("recovery"),
|
|
68
|
+
source: Type.String(),
|
|
69
|
+
candidates: Type.Array(Type.Object({ path: Type.String() }, { additionalProperties: false })),
|
|
70
|
+
},
|
|
71
|
+
{ additionalProperties: false },
|
|
72
|
+
),
|
|
73
|
+
text,
|
|
74
|
+
bytes,
|
|
75
|
+
native,
|
|
76
|
+
Type.Object(
|
|
77
|
+
{
|
|
78
|
+
kind: Type.Literal("resources"),
|
|
79
|
+
source: Type.Optional(Type.String()),
|
|
80
|
+
resources: Type.Array(Type.Union([text, bytes, native])),
|
|
81
|
+
truncated: Type.Boolean(),
|
|
82
|
+
fullResult: Type.Optional(Type.String()),
|
|
83
|
+
},
|
|
84
|
+
{ additionalProperties: false },
|
|
85
|
+
),
|
|
86
|
+
]);
|
|
87
|
+
export const readOutputSchema = structuredResultSchema(readDataSchema);
|
|
88
|
+
|
|
89
|
+
function publicLine(value: TextLine) {
|
|
90
|
+
return {
|
|
91
|
+
lineNumber: value.lineNumber,
|
|
92
|
+
content: value.content,
|
|
93
|
+
lineEnding: value.lineEnding,
|
|
94
|
+
...(value.anchors === undefined ? {} : { anchors: [...value.anchors] }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Bound selected data, not source snapshots or human-facing presentation. */
|
|
98
|
+
function publicData(value: ReadScriptData): unknown {
|
|
99
|
+
if (value.kind === "resources") {
|
|
100
|
+
const resources = value.resources.map((resource) => publicData(resource));
|
|
101
|
+
return {
|
|
102
|
+
kind: value.kind,
|
|
103
|
+
...(value.source === undefined ? {} : { source: value.source }),
|
|
104
|
+
resources,
|
|
105
|
+
truncated: resources.some(
|
|
106
|
+
(resource) =>
|
|
107
|
+
typeof resource === "object" &&
|
|
108
|
+
resource !== null &&
|
|
109
|
+
"truncated" in resource &&
|
|
110
|
+
resource.truncated === true,
|
|
111
|
+
),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (value.kind === "bytes") {
|
|
115
|
+
const bytes = value.bytes.slice(0, 32768);
|
|
116
|
+
const truncated = value.truncated === true || bytes.length < value.bytes.length;
|
|
117
|
+
return {
|
|
118
|
+
kind: value.kind,
|
|
119
|
+
source: value.source,
|
|
120
|
+
bytes,
|
|
121
|
+
byteOffset: value.byteOffset,
|
|
122
|
+
byteLength: bytes.length,
|
|
123
|
+
totalBytes: value.totalBytes,
|
|
124
|
+
truncated,
|
|
125
|
+
...(value.byteOffset + bytes.length < value.totalBytes
|
|
126
|
+
? { continuation: { path: value.source, offset: value.byteOffset + bytes.length } }
|
|
127
|
+
: {}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (value.kind === "native")
|
|
131
|
+
return {
|
|
132
|
+
kind: value.kind,
|
|
133
|
+
source: value.source,
|
|
134
|
+
truncated: false,
|
|
135
|
+
blocks: value.blocks.map((block) => {
|
|
136
|
+
if (block.type === "text") return { type: block.type, text: block.text };
|
|
137
|
+
if (block.type === "image")
|
|
138
|
+
return { type: block.type, data: block.data, mimeType: block.mimeType };
|
|
139
|
+
throw new TypeError("Custom content requires a structured adapter");
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
const lines = [];
|
|
143
|
+
let size = 0;
|
|
144
|
+
for (const line of value.lines) {
|
|
145
|
+
const projected = publicLine(line);
|
|
146
|
+
size += Buffer.byteLength(JSON.stringify(projected));
|
|
147
|
+
if (lines.length >= 2000 || size > 512 * 1024) break;
|
|
148
|
+
lines.push(projected);
|
|
149
|
+
}
|
|
150
|
+
if (lines.length === 0 && value.lines.length > 0)
|
|
151
|
+
throw new RangeError(
|
|
152
|
+
"Selected line exceeds the structured window; use a raw byte range or a source-specific view",
|
|
153
|
+
);
|
|
154
|
+
const truncated = lines.length < value.lines.length;
|
|
155
|
+
const endLine = lines.at(-1)?.lineNumber ?? value.startLine - 1;
|
|
156
|
+
// Continue against the resolved source with absolute line numbers, not a relative selector.
|
|
157
|
+
return {
|
|
158
|
+
kind: value.kind,
|
|
159
|
+
source: value.source,
|
|
160
|
+
lines,
|
|
161
|
+
startLine: lines[0]?.lineNumber ?? 0,
|
|
162
|
+
endLine: lines.at(-1)?.lineNumber ?? 0,
|
|
163
|
+
totalLines: value.totalLines,
|
|
164
|
+
truncated,
|
|
165
|
+
...(value.target === undefined ? {} : { target: value.target }),
|
|
166
|
+
...(value.references === undefined ? {} : { references: value.references }),
|
|
167
|
+
...(truncated || endLine < value.totalLines
|
|
168
|
+
? { continuation: { path: value.source, offset: endLine + 1 } }
|
|
169
|
+
: {}),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Require resolver-owned script data. Never reconstruct it from rendered content or renderer details. */
|
|
174
|
+
export function structuredRead(result: ReadToolResult): ReadToolResult {
|
|
175
|
+
const failure = result.details.failure;
|
|
176
|
+
if (result.isError || failure !== undefined)
|
|
177
|
+
return withStructuredResult(result, readDataSchema, {
|
|
178
|
+
status: "error",
|
|
179
|
+
...(failure?.candidates?.length && failure.source !== undefined
|
|
180
|
+
? {
|
|
181
|
+
data: { kind: "recovery", source: failure.source, candidates: failure.candidates },
|
|
182
|
+
}
|
|
183
|
+
: {}),
|
|
184
|
+
errors: [
|
|
185
|
+
{
|
|
186
|
+
code: failure?.code ?? "READ_FAILED",
|
|
187
|
+
message: failure?.message ?? "Read failed",
|
|
188
|
+
...(failure?.source === undefined ? {} : { source: failure.source }),
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
try {
|
|
193
|
+
if (result.script === undefined)
|
|
194
|
+
throw new TypeError("Read handler must return structured script data");
|
|
195
|
+
const data = publicData(result.script);
|
|
196
|
+
return withStructuredResult(result, readDataSchema, {
|
|
197
|
+
status: "success",
|
|
198
|
+
data:
|
|
199
|
+
result.details.temporarySource !== undefined && typeof data === "object" && data !== null
|
|
200
|
+
? { ...data, fullResult: result.details.temporarySource }
|
|
201
|
+
: data,
|
|
202
|
+
errors: [],
|
|
203
|
+
});
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return withStructuredResult(result, readDataSchema, {
|
|
206
|
+
status: "error",
|
|
207
|
+
errors: [
|
|
208
|
+
{
|
|
209
|
+
code:
|
|
210
|
+
error instanceof RangeError
|
|
211
|
+
? "STRUCTURED_RESULT_TOO_LARGE"
|
|
212
|
+
: "STRUCTURED_ADAPTER_REQUIRED",
|
|
213
|
+
message: error instanceof Error ? error.message : String(error),
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|