pi-agent-ide 0.7.1 → 0.7.3
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 +66 -0
- package/README.md +3 -1
- package/dist/{chunk-PKKDDIWW.js → chunk-2ZMMRINH.js} +1 -1
- package/dist/chunk-6U5OU77O.js +3 -0
- package/dist/chunk-BYZSBXUK.js +2 -0
- package/dist/{chunk-LEEQIQ7D.js → chunk-CEX73RI5.js} +6 -6
- package/dist/chunk-DZWTKF2K.js +1 -0
- package/dist/{chunk-WMO6RNE2.js → chunk-EOKEQ3YH.js} +6 -6
- package/dist/{chunk-HZEY4GT4.js → chunk-H445SHSJ.js} +2 -2
- package/dist/{chunk-4GCWGE2C.js → chunk-HZ5BNF3A.js} +1 -1
- package/dist/chunk-IG56UGSO.js +2 -0
- package/dist/chunk-IICJXZBU.js +6 -0
- package/dist/{chunk-XYS4FSCC.js → chunk-IM24DB3K.js} +1 -1
- package/dist/chunk-MXLSGMRZ.js +3 -0
- package/dist/{chunk-76ZK5ODR.js → chunk-NHKPP2AI.js} +13 -13
- package/dist/chunk-OB46OPMZ.js +1 -0
- package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
- package/dist/chunk-QUYXINGZ.js +7 -0
- package/dist/{chunk-OMVRLWMX.js → chunk-SBP3ABH4.js} +1 -1
- package/dist/{chunk-YP46DVVP.js → chunk-STBJO3Z3.js} +1 -1
- package/dist/{chunk-2TRHFMCZ.js → chunk-TXOTNK6B.js} +1 -1
- package/dist/chunk-WLZIUMJL.js +1 -0
- package/dist/chunk-ZIWPKIBZ.js +1 -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 +1 -1
- 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-31.js +12 -11
- package/dist/entry-33.js +3 -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 +20 -12
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +7 -6
- 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-58.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-77.js +63 -49
- package/dist/entry-78.js +15 -14
- package/dist/entry-79.js +1 -1
- package/dist/entry-82.js +5 -5
- 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 +34 -11
- package/docs/agent-guides/editing.md +14 -7
- package/docs/agent-guides/git-changes.md +10 -0
- package/docs/agent-guides/read-resources.md +9 -46
- package/docs/agent-guides/search-code.md +7 -1
- package/docs/agent-guides/select-code.md +1 -0
- package/docs/agent-guides/terminal.md +9 -1
- package/docs/configuration.md +22 -1
- package/docs/development.md +4 -0
- package/docs/directory-operations.md +45 -0
- package/docs/releases.md +12 -0
- package/docs/research/codemode-write-context.md +56 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/structured-results.md +2 -2
- package/docs/tools.md +10 -2
- package/docs/user-hooks.md +26 -0
- 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/package.json +7 -7
- 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-jq/src/jq.ts +4 -1
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +13 -13
- package/node_modules/pi-agent-ide-ast/src/extension.ts +3 -3
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +0 -3
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +8 -6
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +13 -5
- package/node_modules/pi-agent-ide-changes/package.json +9 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- 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 +1 -1
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
- 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 +3 -3
- package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +1 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +5 -1
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +99 -44
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +1 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +6 -3
- package/node_modules/{pi-agent-read/src/core/tools/read → pi-agent-resource/src}/temp-resource-store.ts +17 -7
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +5 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +2 -2
- package/node_modules/pi-agent-search/src/core/extension.ts +2 -1
- package/node_modules/pi-agent-search/src/core/search-core.ts +13 -4
- package/node_modules/pi-agent-search-text/package.json +7 -7
- package/node_modules/pi-agent-search-text/src/resolvers.ts +11 -1
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +42 -32
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +6 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +17 -3
- 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/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-editor/package.json +9 -9
- package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +30 -40
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +24 -4
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +21 -14
- package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
- package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
- package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
- 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-web/package.json +7 -7
- package/node_modules/pi-agent-web/src/resolver.ts +11 -13
- 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 +36 -35
- package/src/api/hooks.ts +24 -0
- package/src/composite/nested-tool-rendering.ts +184 -77
- package/src/composite/output-limits.ts +125 -0
- package/src/composite/responses-tools.ts +25 -0
- package/src/composite/text-results.ts +158 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +4 -1
- 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/package.json +7 -7
- 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/resolver.ts +11 -13
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +3 -3
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +5 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +99 -44
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +11 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +42 -32
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +6 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +17 -3
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +5 -1
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +2 -2
- package/src/extensions/pi-agent-search/src/core/extension.ts +2 -1
- package/src/extensions/pi-agent-search/src/core/search-core.ts +13 -4
- package/src/extensions/pi-agent-text-editor/package.json +9 -9
- 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-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
- 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/delete-guard.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +30 -40
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +24 -4
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +21 -14
- package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
- package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/src/pi-agent-ide.ts +11 -0
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +3 -3
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +0 -3
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +8 -6
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +13 -5
- package/src/plugins/pi-agent-ide-changes/package.json +9 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/src/plugins/pi-agent-ide-debugger/index.ts +20 -8
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +93 -38
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +3 -2
- 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 +1 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
- package/src/plugins/pi-agent-ide-vision/index.ts +1 -0
- package/src/post-edit/gate.ts +13 -2
- package/dist/chunk-4XMY4H4V.js +0 -1
- package/dist/chunk-64M3SQPG.js +0 -3
- package/dist/chunk-CWD4O5PM.js +0 -3
- package/dist/chunk-D3WTDA6V.js +0 -2
- package/dist/chunk-EAZGN5ND.js +0 -7
- package/dist/chunk-GXEGY7GV.js +0 -1
- package/dist/chunk-MBUXFKIW.js +0 -3
- package/dist/chunk-PGIVHICI.js +0 -1
- package/dist/chunk-VMTR74FF.js +0 -2
- package/dist/chunk-WU6ZK6YD.js +0 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +0 -105
package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-agent-text-editor-stale-anchor",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"pi-agent-invariant": "0.7.
|
|
7
|
-
"pi-agent-read": "0.7.
|
|
8
|
-
"pi-agent-text-editor": "0.7.
|
|
6
|
+
"pi-agent-invariant": "0.7.3",
|
|
7
|
+
"pi-agent-read": "0.7.3",
|
|
8
|
+
"pi-agent-text-editor": "0.7.3"
|
|
9
9
|
},
|
|
10
10
|
"pi": {
|
|
11
11
|
"extensions": [
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A whole object removed from this path by Delete or directory/symlink Move, never a text selection. */
|
|
2
|
+
export interface BeforeDeleteEvent {
|
|
3
|
+
/** Absolute path supplied by the caller. */
|
|
4
|
+
readonly path: string;
|
|
5
|
+
/** Absolute identity with parent symlinks resolved, but not the final symlink. */
|
|
6
|
+
readonly resolvedPath: string;
|
|
7
|
+
readonly cwd: string;
|
|
8
|
+
readonly kind: "file" | "directory" | "symlink";
|
|
9
|
+
readonly recursive: boolean;
|
|
10
|
+
readonly signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A fail-closed policy. Throwing or denying prevents removal. */
|
|
14
|
+
export interface DeleteGuardRegistration {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly guard: (
|
|
17
|
+
event: BeforeDeleteEvent,
|
|
18
|
+
) =>
|
|
19
|
+
| { readonly decision: "allow" }
|
|
20
|
+
| { readonly decision: "deny"; readonly reason: string }
|
|
21
|
+
| Promise<
|
|
22
|
+
{ readonly decision: "allow" } | { readonly decision: "deny"; readonly reason: string }
|
|
23
|
+
>;
|
|
24
|
+
}
|
|
@@ -3,8 +3,8 @@ import type { TextDocument } from "pi-agent-text";
|
|
|
3
3
|
export type TextEditIntent = "edit" | "restore" | "mixed";
|
|
4
4
|
|
|
5
5
|
export interface TextEditCompletion {
|
|
6
|
-
/**
|
|
7
|
-
readonly postProcessing?: "deferred" | "final" | "complete";
|
|
6
|
+
/** Saved bytes remain observable even when post-edit work is deferred or interrupted. */
|
|
7
|
+
readonly postProcessing?: "deferred" | "final" | "complete" | "interrupted";
|
|
8
8
|
readonly source: string;
|
|
9
9
|
readonly resourceSource: string;
|
|
10
10
|
readonly resolvedBy: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { BeforeDeleteEvent, DeleteGuardRegistration } from "./delete-guard.js";
|
|
1
2
|
import type { TextEditIntent } from "#src/api/edit-completion.js";
|
|
2
3
|
import type { AppliedTextChange } from "#src/core/text-change-engine.js";
|
|
3
4
|
export type { AppliedTextChange } from "#src/core/text-change-engine.js";
|
|
@@ -28,8 +28,7 @@ export { type ChangedRange, computeChangedRanges } from "#src/core/mutation-resu
|
|
|
28
28
|
export {
|
|
29
29
|
mutationDataSchema,
|
|
30
30
|
mutationResultSchema,
|
|
31
|
-
|
|
32
|
-
type FlushData,
|
|
31
|
+
type BatchMutationData,
|
|
33
32
|
structuredMutation,
|
|
34
33
|
type MutationData,
|
|
35
34
|
} from "#src/core/structured-result.js";
|
|
@@ -5,6 +5,10 @@ import type { FileMutationBatchResult } from "./mutation-result.js";
|
|
|
5
5
|
export interface NativeEditBatchEvent {
|
|
6
6
|
readonly parentToolCallId: string;
|
|
7
7
|
readonly calls: readonly string[];
|
|
8
|
+
/** Successful Copy calls that retained identical destination text without a write. */
|
|
9
|
+
readonly unchangedCopyCalls?: readonly string[];
|
|
10
|
+
/** Per-call Copy receipts keep destination authority and rollback evidence. */
|
|
11
|
+
readonly copyResults?: ReadonlyMap<string, AgentToolResult<FileMutationBatchResult>>;
|
|
8
12
|
readonly result: AgentToolResult<FileMutationBatchResult>;
|
|
9
13
|
}
|
|
10
14
|
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
} from "#src/api/anchor-inspection.js";
|
|
16
16
|
import type { TextEditCompletionListener } from "#src/api/edit-completion.js";
|
|
17
17
|
import type { TextEditorToolPluginApi } from "#src/api/edit-pipeline.js";
|
|
18
|
+
import type { DeleteGuardRegistration } from "#src/api/delete-guard.js";
|
|
18
19
|
import type { TextMutationGuardRegistration } from "#src/api/mutation-guard.js";
|
|
19
20
|
import type {
|
|
20
21
|
TextMutationPreviewOutcome,
|
|
@@ -28,7 +29,7 @@ import type { TextEditorToolRendererRegistration } from "#src/api/tool-renderer.
|
|
|
28
29
|
|
|
29
30
|
export const TEXT_EDITOR_PROTOCOL = "pi-agent-text-editor";
|
|
30
31
|
|
|
31
|
-
export const TEXT_EDITOR_API_VERSION =
|
|
32
|
+
export const TEXT_EDITOR_API_VERSION = 24;
|
|
32
33
|
|
|
33
34
|
export const TEXT_POSITION_ANCHOR_KIND = "pi-agent-text-editor/position";
|
|
34
35
|
|
|
@@ -88,6 +89,8 @@ export interface TextEditorPluginApi {
|
|
|
88
89
|
addTextPresenter(registration: TextPresenterRegistration): void;
|
|
89
90
|
addMutationTool(registration: TextMutationToolRegistration): void;
|
|
90
91
|
addMutationGuard(registration: TextMutationGuardRegistration): void;
|
|
92
|
+
/** Add a fail-closed policy for whole-object filesystem deletion, not text removal. */
|
|
93
|
+
addDeleteGuard(registration: DeleteGuardRegistration): void;
|
|
91
94
|
addToolRenderer(registration: TextEditorToolRendererRegistration): void;
|
|
92
95
|
onMutationTool(listener: TextMutationToolListener): () => void;
|
|
93
96
|
onDidEdit(listener: TextEditCompletionListener): () => void;
|
|
@@ -14,7 +14,7 @@ export function formatStaleAnchorMessage(
|
|
|
14
14
|
): string {
|
|
15
15
|
const context = details.context === undefined ? "" : `\n\n${details.context}`;
|
|
16
16
|
return (
|
|
17
|
-
`[SYSTEM] ${details.toolName} blocked: ${details.field} anchor "${details.anchor}" is stale. ` +
|
|
17
|
+
`[SYSTEM] ${details.toolName} blocked: ${details.field === "anchor" ? "anchor" : `${details.field} anchor`} "${details.anchor}" is stale. ` +
|
|
18
18
|
`If the required line is represented by one of the context lines below, use that anchor. Otherwise, reread only the relevant section of "${details.path}" and regenerate the anchor. (${reason})${context}`
|
|
19
19
|
);
|
|
20
20
|
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { loadTemporaryDirectories } from "./temporary-directories.js";
|
|
6
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
7
|
+
import type { BeforeDeleteEvent } from "#src/api/delete-guard.js";
|
|
8
|
+
|
|
9
|
+
const exec = promisify(execFile);
|
|
10
|
+
|
|
11
|
+
/** Host-only deletion dependencies; these are not agent parameters. */
|
|
12
|
+
export interface DeletePolicyContext {
|
|
13
|
+
readonly beforeDelete?: (event: BeforeDeleteEvent) => Promise<void>;
|
|
14
|
+
readonly confirm?: (event: BeforeDeleteEvent, reason: string) => Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Project {
|
|
18
|
+
readonly root?: string;
|
|
19
|
+
readonly controls: readonly string[];
|
|
20
|
+
readonly gitAvailable: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A host approval that must be checked again immediately before removal. */
|
|
24
|
+
export interface DeletionGuard {
|
|
25
|
+
readonly event: BeforeDeleteEvent;
|
|
26
|
+
readonly verify: () => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Check policy and hooks, obtain any required approval, then verify the same object again. */
|
|
30
|
+
export async function prepareDeletion(
|
|
31
|
+
source: string,
|
|
32
|
+
cwd: string,
|
|
33
|
+
context: DeletePolicyContext,
|
|
34
|
+
signal?: AbortSignal,
|
|
35
|
+
): Promise<BeforeDeleteEvent> {
|
|
36
|
+
const guard = await prepareDeletionGuard(source, cwd, context, signal, true);
|
|
37
|
+
await guard.verify();
|
|
38
|
+
return guard.event;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Keep approval checks for multi-object removals; only Delete opts into temporary cleanup. */
|
|
42
|
+
export async function prepareDeletionGuard(
|
|
43
|
+
source: string,
|
|
44
|
+
cwd: string,
|
|
45
|
+
context: DeletePolicyContext,
|
|
46
|
+
signal?: AbortSignal,
|
|
47
|
+
allowTemporary = false,
|
|
48
|
+
): Promise<DeletionGuard> {
|
|
49
|
+
const before = await inspectDeletion(source, cwd, signal, allowTemporary);
|
|
50
|
+
await context.beforeDelete?.(before.event);
|
|
51
|
+
signal?.throwIfAborted();
|
|
52
|
+
if (before.reason !== undefined) {
|
|
53
|
+
if (context.confirm === undefined)
|
|
54
|
+
fail(
|
|
55
|
+
"DELETE_CONFIRMATION_REQUIRED",
|
|
56
|
+
`Deletion blocked: no user dialog is available. ${before.reason}`,
|
|
57
|
+
);
|
|
58
|
+
if (!(await context.confirm(before.event, before.reason)))
|
|
59
|
+
fail("DELETE_NOT_APPROVED", "Deletion was not approved by the user.");
|
|
60
|
+
}
|
|
61
|
+
signal?.throwIfAborted();
|
|
62
|
+
return {
|
|
63
|
+
event: before.event,
|
|
64
|
+
verify: async () => {
|
|
65
|
+
signal?.throwIfAborted();
|
|
66
|
+
let after;
|
|
67
|
+
try {
|
|
68
|
+
after = await inspectDeletion(source, cwd, signal, allowTemporary);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
signal?.throwIfAborted();
|
|
71
|
+
fail(
|
|
72
|
+
"DELETE_TARGET_CHANGED",
|
|
73
|
+
`Deletion target cannot be verified again: ${error instanceof Error ? error.message : String(error)}`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (before.snapshot !== after.snapshot)
|
|
77
|
+
fail(
|
|
78
|
+
"DELETE_TARGET_CHANGED",
|
|
79
|
+
"Deletion target or its safety classification changed. Nothing was removed; make a new request.",
|
|
80
|
+
);
|
|
81
|
+
signal?.throwIfAborted();
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function inspectDeletion(
|
|
87
|
+
source: string,
|
|
88
|
+
cwd: string,
|
|
89
|
+
signal: AbortSignal | undefined,
|
|
90
|
+
allowTemporary: boolean,
|
|
91
|
+
) {
|
|
92
|
+
signal?.throwIfAborted();
|
|
93
|
+
// Resolve ancestors without dereferencing the link that will be unlinked.
|
|
94
|
+
const resolvedPath = path.join(await realpath(path.dirname(source)), path.basename(source));
|
|
95
|
+
const stat = await lstat(resolvedPath);
|
|
96
|
+
const kind = stat.isSymbolicLink()
|
|
97
|
+
? "symlink"
|
|
98
|
+
: stat.isDirectory()
|
|
99
|
+
? "directory"
|
|
100
|
+
: stat.isFile()
|
|
101
|
+
? "file"
|
|
102
|
+
: undefined;
|
|
103
|
+
if (kind === undefined)
|
|
104
|
+
fail("INVALID_FILE_TYPE", "Delete supports regular files, directories, and symlinks.");
|
|
105
|
+
const project = await findProject(cwd, signal);
|
|
106
|
+
const boundary = project.root ?? (await realpath(cwd));
|
|
107
|
+
assertUnprotected(resolvedPath, boundary, project.controls);
|
|
108
|
+
|
|
109
|
+
const temporaryRoots =
|
|
110
|
+
allowTemporary && kind !== "file" ? await loadTemporaryDirectories(boundary) : [];
|
|
111
|
+
const temporary =
|
|
112
|
+
!temporaryRoots.some((root) => path.relative(root, resolvedPath) === "") &&
|
|
113
|
+
temporaryRoots.some((root) => contains(root, resolvedPath));
|
|
114
|
+
let reason: string | undefined;
|
|
115
|
+
let tracked: string[] = [];
|
|
116
|
+
if (kind !== "file") {
|
|
117
|
+
if (!project.gitAvailable || project.root === undefined) {
|
|
118
|
+
// Broken Git metadata must not bypass the tracking check inside the current project.
|
|
119
|
+
if (!temporary || (project.root !== undefined && contains(project.root, resolvedPath)))
|
|
120
|
+
reason = "No Git worktree or reliable Git check is available.";
|
|
121
|
+
} else if (!contains(project.root, resolvedPath)) {
|
|
122
|
+
if (!temporary) reason = "Target is outside the current Git worktree.";
|
|
123
|
+
} else {
|
|
124
|
+
try {
|
|
125
|
+
const entries = (
|
|
126
|
+
await git(project.root, ["ls-files", "--cached", "--full-name", "-z"], signal)
|
|
127
|
+
)
|
|
128
|
+
.split("\0")
|
|
129
|
+
.filter(Boolean);
|
|
130
|
+
tracked = entries
|
|
131
|
+
.filter((entry) =>
|
|
132
|
+
contains(resolvedPath, path.resolve(requiredValue(project.root), entry)),
|
|
133
|
+
)
|
|
134
|
+
.sort();
|
|
135
|
+
if (tracked.length > 0)
|
|
136
|
+
reason = "Target is tracked by Git or contains tracked or staged entries.";
|
|
137
|
+
} catch {
|
|
138
|
+
signal?.throwIfAborted();
|
|
139
|
+
reason = "Git tracking check failed.";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const event: BeforeDeleteEvent = {
|
|
144
|
+
path: source,
|
|
145
|
+
resolvedPath,
|
|
146
|
+
cwd,
|
|
147
|
+
kind,
|
|
148
|
+
recursive: kind === "directory",
|
|
149
|
+
...(signal === undefined ? {} : { signal }),
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
event,
|
|
153
|
+
reason,
|
|
154
|
+
snapshot: JSON.stringify({
|
|
155
|
+
resolvedPath,
|
|
156
|
+
kind,
|
|
157
|
+
dev: stat.dev,
|
|
158
|
+
ino: stat.ino,
|
|
159
|
+
birthtime: stat.birthtimeMs,
|
|
160
|
+
ctime: stat.ctimeMs,
|
|
161
|
+
mtime: stat.mtimeMs,
|
|
162
|
+
size: stat.size,
|
|
163
|
+
boundary,
|
|
164
|
+
controls: project.controls,
|
|
165
|
+
temporaryRoots,
|
|
166
|
+
reason,
|
|
167
|
+
tracked,
|
|
168
|
+
}),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Protect recursive transfer destinations, including paths that do not exist yet. */
|
|
173
|
+
export async function assertUnprotectedTransferPath(
|
|
174
|
+
resolvedPath: string,
|
|
175
|
+
cwd: string,
|
|
176
|
+
signal?: AbortSignal,
|
|
177
|
+
): Promise<void> {
|
|
178
|
+
const project = await findProject(cwd, signal);
|
|
179
|
+
assertUnprotected(resolvedPath, project.root ?? (await realpath(cwd)), project.controls);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function assertUnprotected(resolvedPath: string, boundary: string, controls: readonly string[]) {
|
|
183
|
+
if (
|
|
184
|
+
contains(resolvedPath, boundary) ||
|
|
185
|
+
resolvedPath === path.parse(resolvedPath).root ||
|
|
186
|
+
controls.some((control) => contains(control, resolvedPath) || contains(resolvedPath, control))
|
|
187
|
+
)
|
|
188
|
+
fail(
|
|
189
|
+
"DELETE_PROTECTED_TARGET",
|
|
190
|
+
`Cannot remove or overwrite protected project, ancestor, filesystem root, or Git control path: ${resolvedPath}`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
async function findProject(cwd: string, signal?: AbortSignal): Promise<Project> {
|
|
194
|
+
try {
|
|
195
|
+
const output = (
|
|
196
|
+
await git(
|
|
197
|
+
cwd,
|
|
198
|
+
[
|
|
199
|
+
"rev-parse",
|
|
200
|
+
"--path-format=absolute",
|
|
201
|
+
"--show-toplevel",
|
|
202
|
+
"--absolute-git-dir",
|
|
203
|
+
"--git-common-dir",
|
|
204
|
+
],
|
|
205
|
+
signal,
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
.trimEnd()
|
|
209
|
+
.split("\n");
|
|
210
|
+
if (output.length !== 3) throw new Error("Unexpected Git worktree paths");
|
|
211
|
+
const [root, gitDir, commonDir] = await Promise.all(output.map((entry) => realpath(entry)));
|
|
212
|
+
return {
|
|
213
|
+
root,
|
|
214
|
+
controls: [
|
|
215
|
+
path.join(requiredValue(root), ".git"),
|
|
216
|
+
requiredValue(gitDir),
|
|
217
|
+
requiredValue(commonDir),
|
|
218
|
+
].sort(),
|
|
219
|
+
gitAvailable: true,
|
|
220
|
+
};
|
|
221
|
+
} catch {
|
|
222
|
+
signal?.throwIfAborted();
|
|
223
|
+
// Preserve root/control protection even when Git is unavailable or its metadata is broken.
|
|
224
|
+
let directory = await realpath(cwd);
|
|
225
|
+
for (;;) {
|
|
226
|
+
const marker = path.join(directory, ".git");
|
|
227
|
+
const stat = await lstat(marker).catch((error: NodeJS.ErrnoException) => {
|
|
228
|
+
if (error.code === "ENOENT") return undefined;
|
|
229
|
+
throw error;
|
|
230
|
+
});
|
|
231
|
+
if (stat !== undefined) {
|
|
232
|
+
const controls = [marker];
|
|
233
|
+
if (stat.isDirectory() || stat.isSymbolicLink()) controls.push(await realpath(marker));
|
|
234
|
+
else if (stat.isFile()) {
|
|
235
|
+
const content = await readFile(marker, "utf8");
|
|
236
|
+
const reference = /^gitdir: (.+)\r?\n?$/u.exec(content)?.[1];
|
|
237
|
+
if (reference === undefined)
|
|
238
|
+
fail("DELETE_GIT_PROTECTION_FAILED", "Cannot identify current Git control data.");
|
|
239
|
+
const gitDir = await realpath(path.resolve(directory, reference));
|
|
240
|
+
controls.push(gitDir);
|
|
241
|
+
const common = await readFile(path.join(gitDir, "commondir"), "utf8").catch(
|
|
242
|
+
(error: NodeJS.ErrnoException) => {
|
|
243
|
+
if (error.code === "ENOENT") return undefined;
|
|
244
|
+
throw error;
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
if (common !== undefined)
|
|
248
|
+
controls.push(await realpath(path.resolve(gitDir, common.trimEnd())));
|
|
249
|
+
} else fail("DELETE_GIT_PROTECTION_FAILED", "Cannot identify current Git control data.");
|
|
250
|
+
return { root: directory, controls: controls.sort(), gitAvailable: false };
|
|
251
|
+
}
|
|
252
|
+
const parent = path.dirname(directory);
|
|
253
|
+
if (parent === directory) return { controls: [], gitAvailable: false };
|
|
254
|
+
directory = parent;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function git(cwd: string, args: string[], signal?: AbortSignal): Promise<string> {
|
|
260
|
+
const env = Object.fromEntries(
|
|
261
|
+
Object.entries(process.env).filter(([key]) => !key.startsWith("GIT_")),
|
|
262
|
+
);
|
|
263
|
+
const { stdout } = await exec("git", ["-C", cwd, ...args], {
|
|
264
|
+
env: { ...env, GIT_OPTIONAL_LOCKS: "0" },
|
|
265
|
+
signal,
|
|
266
|
+
timeout: 5000,
|
|
267
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
268
|
+
});
|
|
269
|
+
return stdout;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function contains(parent: string, child: string): boolean {
|
|
273
|
+
const relative = path.relative(parent, child);
|
|
274
|
+
return (
|
|
275
|
+
relative === "" ||
|
|
276
|
+
// This checks containment; it does not construct a parent-relative path.
|
|
277
|
+
// eslint-disable-next-line repo/no-parent-paths
|
|
278
|
+
(!path.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${path.sep}`))
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function fail(code: string, message: string): never {
|
|
283
|
+
throw Object.assign(new Error(message), { code });
|
|
284
|
+
}
|
|
@@ -33,10 +33,42 @@ export const diffDataSchema = Type.Object(
|
|
|
33
33
|
);
|
|
34
34
|
export const diffOutputSchema = structuredResultSchema(diffDataSchema);
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const comparisonReadParameters = {
|
|
37
|
+
...readParameters,
|
|
38
|
+
properties: {
|
|
39
|
+
...readParameters.properties,
|
|
40
|
+
path: {
|
|
41
|
+
...readParameters.properties.path,
|
|
42
|
+
description:
|
|
43
|
+
"Text-readable source accepted by Read, such as a file path, URL, temp: reference, SEARCH# or RESULT# reference, or registered resource. Supply a path.",
|
|
44
|
+
},
|
|
45
|
+
offset: {
|
|
46
|
+
...readParameters.properties.offset,
|
|
47
|
+
description:
|
|
48
|
+
"First text line to compare, numbered from 1. Omit or use 0 to start at line 1; negative offsets count from the end. For path#anchor, SEARCH# or RESULT# selections, count from the containing line: omitted, 0 or 1 starts there, 2 starts one line later, -1 one line earlier.",
|
|
49
|
+
},
|
|
50
|
+
limit: {
|
|
51
|
+
...readParameters.properties.limit,
|
|
52
|
+
description:
|
|
53
|
+
"Maximum text lines to compare from the selected starting position. Omit to compare all resolved text in the selected range. Read's display limits do not shorten the comparison inputs.",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const source = Type.Union([Type.String({ minLength: 1 }), comparisonReadParameters]);
|
|
37
58
|
/** Each side accepts a source string or the same request object as read. */
|
|
38
59
|
export const diffParameters = Type.Object(
|
|
39
|
-
{
|
|
60
|
+
{
|
|
61
|
+
before: {
|
|
62
|
+
...source,
|
|
63
|
+
description:
|
|
64
|
+
"Source for the removed (-) side. Supply a non-empty source reference string or a Read request object. Strings identify sources, not literal text.",
|
|
65
|
+
},
|
|
66
|
+
after: {
|
|
67
|
+
...source,
|
|
68
|
+
description:
|
|
69
|
+
"Source for the added (+) side. Supply a non-empty source reference string or a Read request object. Strings identify sources, not literal text.",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
40
72
|
{ additionalProperties: false },
|
|
41
73
|
);
|
|
42
74
|
export type DiffRequest = Static<typeof diffParameters>;
|
|
@@ -107,13 +139,21 @@ export function comparisonText(data: ReadScriptData, requested: string): Compari
|
|
|
107
139
|
};
|
|
108
140
|
}
|
|
109
141
|
if (data.kind === "bytes")
|
|
110
|
-
throw Object.assign(
|
|
111
|
-
|
|
112
|
-
|
|
142
|
+
throw Object.assign(
|
|
143
|
+
new Error(
|
|
144
|
+
`Byte sources are not text: ${data.source}\nIf this is a text file, use its path without raw:.`,
|
|
145
|
+
),
|
|
146
|
+
{
|
|
147
|
+
code: "UNSUPPORTED_CONTENT",
|
|
148
|
+
},
|
|
149
|
+
);
|
|
113
150
|
if (data.blocks.length === 0 || data.blocks.some((block) => block.type !== "text"))
|
|
114
|
-
throw Object.assign(
|
|
115
|
-
|
|
116
|
-
|
|
151
|
+
throw Object.assign(
|
|
152
|
+
new Error(`Source is not text: ${data.source}\nUse a source that Read resolves to text.`),
|
|
153
|
+
{
|
|
154
|
+
code: "UNSUPPORTED_CONTENT",
|
|
155
|
+
},
|
|
156
|
+
);
|
|
117
157
|
return {
|
|
118
158
|
source: data.source,
|
|
119
159
|
sources: [data.source],
|
|
@@ -166,8 +206,7 @@ export function registerDiff(
|
|
|
166
206
|
parameters: diffParameters,
|
|
167
207
|
outputSchema: diffOutputSchema,
|
|
168
208
|
promptSnippet: "Compare two text-readable sources",
|
|
169
|
-
description:
|
|
170
|
-
"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.",
|
|
209
|
+
description: "Use diff to compare two text-readable sources without changing them.",
|
|
171
210
|
renderCall(_args, theme) {
|
|
172
211
|
return new Text(theme.fg("toolTitle", theme.bold("Diff")), 0, 0);
|
|
173
212
|
},
|
|
@@ -195,7 +234,10 @@ export function registerDiff(
|
|
|
195
234
|
const full = diffText(comparison);
|
|
196
235
|
const bounded = truncateHead(full);
|
|
197
236
|
const temporarySource = bounded.truncated ? await read.saveTemporary(full) : undefined;
|
|
198
|
-
const footer =
|
|
237
|
+
const footer =
|
|
238
|
+
temporarySource === undefined
|
|
239
|
+
? ""
|
|
240
|
+
: `\nDiff output is truncated; the comparison used the complete resolved inputs.\nUse read with path "${temporarySource}" for the full diff.`;
|
|
199
241
|
return withStructuredResult(
|
|
200
242
|
{
|
|
201
243
|
content: [
|
|
@@ -205,7 +247,7 @@ export function registerDiff(
|
|
|
205
247
|
temporarySource === undefined
|
|
206
248
|
? full
|
|
207
249
|
: truncateHead(full, {
|
|
208
|
-
maxLines: DEFAULT_MAX_LINES -
|
|
250
|
+
maxLines: DEFAULT_MAX_LINES - footer.split("\n").length,
|
|
209
251
|
maxBytes: DEFAULT_MAX_BYTES - Buffer.byteLength(footer),
|
|
210
252
|
}).content + footer,
|
|
211
253
|
},
|
|
@@ -4,5 +4,5 @@ export const EDITING_GUIDELINES = [
|
|
|
4
4
|
"Use an available anchor when it selects exactly the intended text; otherwise use minimal unique exact text. Keep the edit limited to the intended content.",
|
|
5
5
|
"When search broadens to separate words, treat its results as location hints. Refine the query before using those matches for replacement.",
|
|
6
6
|
"Use standalone mutation tools in one assistant-response batch when each change is known in advance and does not depend on another change. This is the default for several independent edits in one file or across files. Every call is evaluated against the original file snapshots. Combine overlapping changes into one mutation. Use native Codemode for computed or dependent tool composition; it keeps the same tool contracts and does not add grouped rollback. Check each batch result and retry only unapplied changes.",
|
|
7
|
-
"Inside
|
|
7
|
+
"Inside Codemode, run independent edits on different resources concurrently; run edits on the same resource in order. Check the final Codemode result and retry only unapplied changes. Read docs:editing when you need a write report inside the script.",
|
|
8
8
|
] as const;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import type { TextEditorCore } from "#src/core/text-editor-core.js";
|
|
2
3
|
import type { FileOperation, FileOperationResult } from "#src/core/file-operations.js";
|
|
3
4
|
import { executeFileOperation } from "#src/core/file-operations.js";
|
|
@@ -16,6 +17,7 @@ export function isWholeFileInvocation(
|
|
|
16
17
|
input.path.length === 0 ||
|
|
17
18
|
input.path.startsWith("SEARCH#") ||
|
|
18
19
|
input.path.startsWith("RESULT#") ||
|
|
20
|
+
(operation === "delete" && input.path.startsWith("symbol:")) ||
|
|
19
21
|
(typeof input.target === "string" && input.target.startsWith("RESULT#"))
|
|
20
22
|
)
|
|
21
23
|
return false;
|
|
@@ -29,9 +31,13 @@ export async function executeWholeFileTool(
|
|
|
29
31
|
operation: FileOperation,
|
|
30
32
|
input: Readonly<Record<string, unknown>>,
|
|
31
33
|
signal: AbortSignal | undefined,
|
|
32
|
-
context: Pick<ExtensionContext, "cwd"
|
|
34
|
+
context: Pick<ExtensionContext, "cwd"> & {
|
|
35
|
+
readonly hasUI?: boolean;
|
|
36
|
+
readonly ui?: Pick<ExtensionContext["ui"], "confirm">;
|
|
37
|
+
},
|
|
33
38
|
verifySource?: () => Promise<void>,
|
|
34
39
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
40
|
+
const ui = context.hasUI ? context.ui : undefined;
|
|
35
41
|
const outcome = await core.enqueueFileOperation(
|
|
36
42
|
async (): Promise<FileOperationResult> => {
|
|
37
43
|
try {
|
|
@@ -51,7 +57,30 @@ export async function executeWholeFileTool(
|
|
|
51
57
|
},
|
|
52
58
|
};
|
|
53
59
|
}
|
|
54
|
-
return executeFileOperation(operation, input, context.cwd, signal
|
|
60
|
+
return executeFileOperation(operation, input, context.cwd, signal, {
|
|
61
|
+
beforeDelete: (event) => core.beforeDelete(event),
|
|
62
|
+
...(ui !== undefined && {
|
|
63
|
+
confirm: async (event, reason) =>
|
|
64
|
+
ui.confirm(
|
|
65
|
+
operation === "move" ? "Move filesystem object?" : "Delete permanently?",
|
|
66
|
+
[
|
|
67
|
+
event.path,
|
|
68
|
+
event.resolvedPath === event.path
|
|
69
|
+
? undefined
|
|
70
|
+
: `Resolved path: ${event.resolvedPath}`,
|
|
71
|
+
operation === "move" && event.path === path.resolve(context.cwd, String(input.path))
|
|
72
|
+
? `Move source to ${String(input.target)}; preserve link objects without following their targets.`
|
|
73
|
+
: event.recursive
|
|
74
|
+
? "Remove directory and all contents recursively."
|
|
75
|
+
: "Unlink symlink only; leave its target untouched.",
|
|
76
|
+
reason,
|
|
77
|
+
]
|
|
78
|
+
.filter((line) => line !== undefined)
|
|
79
|
+
.join("\n"),
|
|
80
|
+
{ signal },
|
|
81
|
+
),
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
55
84
|
},
|
|
56
85
|
signal,
|
|
57
86
|
{
|
|
@@ -64,7 +93,7 @@ export async function executeWholeFileTool(
|
|
|
64
93
|
if (outcome.ok && operation !== "copy" && outcome.path !== undefined)
|
|
65
94
|
forgetDeferredPostEdit(outcome.path);
|
|
66
95
|
let postProcessingError: string | undefined;
|
|
67
|
-
if (outcome.ok && outcome.target !== undefined) {
|
|
96
|
+
if (outcome.ok && outcome.target !== undefined && outcome.sourceKind === "file") {
|
|
68
97
|
try {
|
|
69
98
|
await core.postProcessFile(outcome.target, { cwd: context.cwd, signal });
|
|
70
99
|
} catch (error) {
|