pi-agent-ide 0.7.1 → 0.7.2
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 +37 -0
- package/dist/chunk-6U5OU77O.js +3 -0
- package/dist/chunk-EURHXLN3.js +2 -0
- package/dist/{chunk-WMO6RNE2.js → chunk-F6IWZKOG.js} +6 -6
- package/dist/{chunk-HZEY4GT4.js → chunk-H445SHSJ.js} +2 -2
- 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-PKKDDIWW.js → chunk-KOVPDKSJ.js} +1 -1
- package/dist/chunk-MXLSGMRZ.js +3 -0
- package/dist/chunk-OB46OPMZ.js +1 -0
- package/dist/chunk-PKSQT6TC.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-4GCWGE2C.js → chunk-SJ4UZ4GU.js} +1 -1
- package/dist/{chunk-2TRHFMCZ.js → chunk-SNF7PDDX.js} +1 -1
- package/dist/{chunk-YP46DVVP.js → chunk-STBJO3Z3.js} +1 -1
- package/dist/{chunk-76ZK5ODR.js → chunk-TQGE7RH6.js} +13 -13
- package/dist/{chunk-LEEQIQ7D.js → chunk-XDG7EQRN.js} +6 -6
- package/dist/chunk-YWQS33DF.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 +13 -12
- package/dist/entry-33.js +2 -1
- package/dist/entry-37.js +2 -2
- 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 +51 -42
- package/dist/entry-78.js +14 -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 +5 -5
- 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 +1 -1
- package/docs/releases.md +4 -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/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 +0 -2
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
- 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 +8 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +66 -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/package.json +9 -9
- 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/edit-completion.ts +2 -2
- 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/stale-anchor-message.ts +1 -1
- 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/mutation-result/file-mutation-agent-result.ts +35 -6
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -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 +232 -151
- 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 +7 -2
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +14 -13
- 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 +152 -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 +76 -32
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +381 -187
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +4 -2
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -2
- 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-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 +54 -5
- 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 +35 -35
- package/src/composite/nested-tool-rendering.ts +64 -6
- 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 +54 -5
- 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/edit-completion.ts +2 -2
- 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/stale-anchor-message.ts +1 -1
- 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/mutation-result/file-mutation-agent-result.ts +35 -6
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -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 +232 -151
- 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 +7 -2
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +14 -13
- 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 +152 -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 +76 -32
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +381 -187
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +4 -2
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -2
- 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-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 +0 -2
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
- 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 +8 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +66 -4
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/src/plugins/pi-agent-ide-debugger/index.ts +17 -7
- 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/package.json +9 -9
- 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
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
1
3
|
import type { ResultRange, ResultSourceTarget } from "pi-agent-resource";
|
|
2
4
|
import type { ResultTargetStore } from "pi-agent-resource";
|
|
3
5
|
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
4
6
|
import type { FileMutationBatchResult } from "#src/api/mutation-result.js";
|
|
5
7
|
import { createTextDocument } from "pi-agent-text";
|
|
6
8
|
import type { TextEditCompletion } from "#src/api/edit-completion.js";
|
|
7
|
-
import type { TextMutationEdit } from "#src/api/mutation-tool.js";
|
|
9
|
+
import type { TextMutation, TextMutationEdit } from "#src/api/mutation-tool.js";
|
|
8
10
|
import { applyTextChanges } from "./text-change-engine.js";
|
|
9
11
|
import { attachFileMutationTargets } from "./file-result-targets.js";
|
|
10
12
|
|
|
@@ -14,10 +16,36 @@ export interface OwnedMutationChanges {
|
|
|
14
16
|
readonly edits: ReadonlyMap<string, TextMutationEdit>;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
/**
|
|
19
|
+
/** Find Copy destinations with identical text and no secondary resource action. */
|
|
20
|
+
export function unchangedCopySources(
|
|
21
|
+
mutation: TextMutation,
|
|
22
|
+
snapshots: ReadonlyMap<string, string>,
|
|
23
|
+
): ReadonlySet<string> {
|
|
24
|
+
if (mutation.afterWrite !== undefined || mutation.semanticAction !== undefined) return new Set();
|
|
25
|
+
return new Set(
|
|
26
|
+
[...mutation.edits]
|
|
27
|
+
.filter(([source, edit]) => {
|
|
28
|
+
const before = snapshots.get(source);
|
|
29
|
+
return (
|
|
30
|
+
before !== undefined &&
|
|
31
|
+
edit.changes.length > 0 &&
|
|
32
|
+
edit.changes.every(
|
|
33
|
+
(change) =>
|
|
34
|
+
change.allowUnchanged && before.slice(change.from, change.to) === change.insert,
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
})
|
|
38
|
+
.map(([source]) => source),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
/** Map final resource snapshots and unchanged Copy ranges; verify before publishing. */
|
|
18
42
|
export function committedMutationTargets(
|
|
19
43
|
mutations: readonly OwnedMutationChanges[],
|
|
20
|
-
completions: readonly
|
|
44
|
+
completions: readonly Pick<
|
|
45
|
+
TextEditCompletion,
|
|
46
|
+
"source" | "resourceSource" | "resolvedBy" | "before" | "after" | "existed"
|
|
47
|
+
>[],
|
|
48
|
+
unchangedSnapshots: ReadonlyMap<string, string> = new Map(),
|
|
21
49
|
): ReadonlyMap<string, readonly ResultSourceTarget[]> {
|
|
22
50
|
const targets = new Map<string, ResultSourceTarget[]>();
|
|
23
51
|
const sources = new Set(mutations.flatMap((mutation) => [...mutation.edits.keys()]));
|
|
@@ -25,7 +53,7 @@ export function committedMutationTargets(
|
|
|
25
53
|
const completion = completions.findLast(
|
|
26
54
|
(item) => item.source === source || item.resourceSource === source,
|
|
27
55
|
);
|
|
28
|
-
if (
|
|
56
|
+
if (completion && completion.resolvedBy !== "filesystem") continue;
|
|
29
57
|
const changes = mutations
|
|
30
58
|
.flatMap((mutation) =>
|
|
31
59
|
(mutation.edits.get(source)?.changes ?? []).map((change, index) => ({
|
|
@@ -35,12 +63,22 @@ export function committedMutationTargets(
|
|
|
35
63
|
})),
|
|
36
64
|
)
|
|
37
65
|
.sort((left, right) => left.from - right.from);
|
|
38
|
-
const before = completion
|
|
39
|
-
|
|
40
|
-
if (
|
|
66
|
+
const before = completion?.before.content ?? unchangedSnapshots.get(source);
|
|
67
|
+
if (before === undefined) continue;
|
|
68
|
+
if (
|
|
69
|
+
!completion &&
|
|
70
|
+
changes.some(
|
|
71
|
+
(change) =>
|
|
72
|
+
!change.allowUnchanged || before.slice(change.from, change.to) !== change.insert,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
continue;
|
|
76
|
+
const after = completion?.after.content ?? before;
|
|
77
|
+
const resourceSource = completion?.resourceSource ?? source;
|
|
78
|
+
if (applyTextChanges(before, changes, completion?.existed === false).content !== after)
|
|
41
79
|
throw new Error("Mutation targets cannot be mapped to the actual written snapshot.");
|
|
42
80
|
const starts = [0];
|
|
43
|
-
for (const line of createTextDocument(
|
|
81
|
+
for (const line of createTextDocument(resourceSource, after).lines)
|
|
44
82
|
if (line.lineEnding.length > 0)
|
|
45
83
|
starts.push((starts.at(-1) ?? 0) + line.content.length + line.lineEnding.length);
|
|
46
84
|
const position = (offset: number): ResultRange["start"] => {
|
|
@@ -71,7 +109,7 @@ export function committedMutationTargets(
|
|
|
71
109
|
for (const [callId, selected] of ranges) {
|
|
72
110
|
const own = targets.get(callId) ?? [];
|
|
73
111
|
own.push({
|
|
74
|
-
source:
|
|
112
|
+
source: resourceSource,
|
|
75
113
|
expectedContent: after,
|
|
76
114
|
ranges: selected,
|
|
77
115
|
});
|
|
@@ -81,6 +119,81 @@ export function committedMutationTargets(
|
|
|
81
119
|
return targets;
|
|
82
120
|
}
|
|
83
121
|
|
|
122
|
+
/** Explain missing Copy authority without changing its write outcome. */
|
|
123
|
+
export function describeUnavailableCopyTarget(
|
|
124
|
+
result: AgentToolResult<FileMutationBatchResult>,
|
|
125
|
+
): AgentToolResult<FileMutationBatchResult> {
|
|
126
|
+
const notice = "No verified text selection. Read the destination before further edits.";
|
|
127
|
+
if (
|
|
128
|
+
result.isError ||
|
|
129
|
+
typeof result.details.metadata?.targetUnavailable !== "string" ||
|
|
130
|
+
result.content.some((block) => block.type === "text" && block.text === notice)
|
|
131
|
+
)
|
|
132
|
+
return result;
|
|
133
|
+
return {
|
|
134
|
+
...result,
|
|
135
|
+
content: [
|
|
136
|
+
...result.content,
|
|
137
|
+
{
|
|
138
|
+
type: "text",
|
|
139
|
+
text: notice,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Publish filesystem Write snapshots, never grant file authority to live resources. */
|
|
146
|
+
export async function attachWriteTarget(
|
|
147
|
+
result: AgentToolResult<FileMutationBatchResult>,
|
|
148
|
+
completions: readonly TextEditCompletion[],
|
|
149
|
+
store: ResultTargetStore,
|
|
150
|
+
cwd: string,
|
|
151
|
+
signal?: AbortSignal,
|
|
152
|
+
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
153
|
+
if (result.isError) return result;
|
|
154
|
+
const file = result.details.results?.[0]?.data;
|
|
155
|
+
if (file?.path === undefined || file.afterContent === undefined) return result;
|
|
156
|
+
if (completions.some((completion) => completion.resolvedBy !== "filesystem")) return result;
|
|
157
|
+
try {
|
|
158
|
+
const content = file.afterContent;
|
|
159
|
+
const lines = content.split(/\r\n|\r|\n/u);
|
|
160
|
+
const targets: ResultSourceTarget[] = [
|
|
161
|
+
{
|
|
162
|
+
source: path.resolve(
|
|
163
|
+
cwd,
|
|
164
|
+
file.path.startsWith("file://") ? fileURLToPath(file.path) : file.path,
|
|
165
|
+
),
|
|
166
|
+
expectedContent: content,
|
|
167
|
+
ranges: [
|
|
168
|
+
{
|
|
169
|
+
start: { lineNumber: 1, column: 0 },
|
|
170
|
+
end: { lineNumber: lines.length, column: lines.at(-1)?.length ?? 0 },
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
await store.verify({ targets, complete: true }, signal);
|
|
176
|
+
return {
|
|
177
|
+
...result,
|
|
178
|
+
details: {
|
|
179
|
+
...result.details,
|
|
180
|
+
metadata: { ...result.details.metadata, resultTarget: store.register(targets, cwd) },
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
} catch (error) {
|
|
184
|
+
signal?.throwIfAborted();
|
|
185
|
+
return {
|
|
186
|
+
...result,
|
|
187
|
+
details: {
|
|
188
|
+
...result.details,
|
|
189
|
+
metadata: {
|
|
190
|
+
...result.details.metadata,
|
|
191
|
+
targetUnavailable: error instanceof Error ? error.message : String(error),
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
84
197
|
/** Publish immediate results only when their committed range mapping is verified. */
|
|
85
198
|
export async function attachCommittedMutationTarget(
|
|
86
199
|
result: AgentToolResult<FileMutationBatchResult>,
|
|
@@ -92,8 +205,14 @@ export async function attachCommittedMutationTarget(
|
|
|
92
205
|
wholeFile = false,
|
|
93
206
|
plannedEdits?: ReadonlyMap<string, TextMutationEdit>,
|
|
94
207
|
destinationOnly = false,
|
|
208
|
+
unchangedSnapshots: ReadonlyMap<string, string> = new Map(),
|
|
95
209
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
96
|
-
if (
|
|
210
|
+
if (
|
|
211
|
+
result.isError ||
|
|
212
|
+
typeof result.details.metadata?.resultTarget === "string" ||
|
|
213
|
+
completions.some((completion) => completion.resolvedBy !== "filesystem")
|
|
214
|
+
)
|
|
215
|
+
return result;
|
|
97
216
|
result = await attachFileMutationTargets(result, store, cwd, signal);
|
|
98
217
|
if (
|
|
99
218
|
typeof result.details.metadata?.resultTarget === "string" ||
|
|
@@ -135,9 +254,11 @@ export async function attachCommittedMutationTarget(
|
|
|
135
254
|
},
|
|
136
255
|
);
|
|
137
256
|
}
|
|
257
|
+
for (const [source, edit] of plannedEdits ?? [])
|
|
258
|
+
if (!edits.has(source) && unchangedSnapshots.has(source)) edits.set(source, edit);
|
|
138
259
|
if (edits.size === 0 && result.details.metadata?.emptyTargets !== true) return result;
|
|
139
260
|
try {
|
|
140
|
-
const mapped = committedMutationTargets([{ callId, edits }], completions);
|
|
261
|
+
const mapped = committedMutationTargets([{ callId, edits }], completions, unchangedSnapshots);
|
|
141
262
|
const targets = mapped.get(callId) ?? [];
|
|
142
263
|
const outputCount = [...edits.values()].filter(
|
|
143
264
|
(edit) => edit.resultChanges?.length !== 0,
|