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,3 +1,4 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { requiredValue } from "pi-agent-invariant";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -21,19 +22,18 @@ import {
|
|
|
21
22
|
} from "./text-edit-batch-registrar.js";
|
|
22
23
|
import { buildFailedTextMutationResult, mutationSources } from "./text-mutation.js";
|
|
23
24
|
import { isWholeFileInvocation } from "./file-operation-tools.js";
|
|
25
|
+
import { isResultInput } from "./result-transfer.js";
|
|
24
26
|
import { FileMutationAgentResult } from "./mutation-result/file-mutation-agent-result.js";
|
|
25
|
-
import { Type } from "typebox";
|
|
26
27
|
import {
|
|
27
28
|
ResourceScheduler,
|
|
28
29
|
resourceAccesses,
|
|
29
30
|
connectResultTargets,
|
|
30
31
|
resultError,
|
|
31
|
-
withStructuredResult,
|
|
32
32
|
type ResultTargetStore,
|
|
33
33
|
type StructuredResult,
|
|
34
34
|
} from "pi-agent-resource";
|
|
35
35
|
import { createPostEditScope } from "./post-edit-scope.js";
|
|
36
|
-
import { committedMutationTargets } from "./mutation-result-targets.js";
|
|
36
|
+
import { committedMutationTargets, unchangedCopySources } from "./mutation-result-targets.js";
|
|
37
37
|
import { FileMutationResult as MutationPresentation } from "./mutation-result/file-mutation-result.js";
|
|
38
38
|
import { isFormattingContribution, isDiffStatusContribution } from "#src/api/post-edit.js";
|
|
39
39
|
import { captureScriptMutation } from "./text-mutation.js";
|
|
@@ -41,13 +41,7 @@ import {
|
|
|
41
41
|
NATIVE_EDIT_BATCH_EVENT,
|
|
42
42
|
type NativeEditBatchEvent,
|
|
43
43
|
} from "#src/api/native-edit-batch-event.js";
|
|
44
|
-
import {
|
|
45
|
-
flushDataSchema,
|
|
46
|
-
flushOutputSchema,
|
|
47
|
-
mutationOutcome,
|
|
48
|
-
type MutationData,
|
|
49
|
-
type FlushData,
|
|
50
|
-
} from "./structured-result.js";
|
|
44
|
+
import { mutationOutcome, type MutationData, type BatchMutationData } from "./structured-result.js";
|
|
51
45
|
|
|
52
46
|
interface PendingBatch {
|
|
53
47
|
readonly entries: TextBatchEntry[];
|
|
@@ -63,8 +57,7 @@ interface BatchSummary {
|
|
|
63
57
|
}
|
|
64
58
|
|
|
65
59
|
interface ScriptBatch {
|
|
66
|
-
readonly reports: StructuredResult<
|
|
67
|
-
reportCursor: number;
|
|
60
|
+
readonly reports: StructuredResult<BatchMutationData>[];
|
|
68
61
|
readonly id: string;
|
|
69
62
|
readonly context: ExtensionContext;
|
|
70
63
|
readonly summaries: BatchSummary[];
|
|
@@ -77,10 +70,33 @@ interface ScriptBatch {
|
|
|
77
70
|
tail: Promise<void>;
|
|
78
71
|
readonly scheduler: ResourceScheduler;
|
|
79
72
|
readonly callOrder: Map<string, number>;
|
|
73
|
+
readonly unfinishedCalls: Map<string, string>;
|
|
80
74
|
pending: PendingBatch;
|
|
81
75
|
closed: boolean;
|
|
82
76
|
}
|
|
83
77
|
|
|
78
|
+
function replaceScriptResult(
|
|
79
|
+
script: ScriptBatch,
|
|
80
|
+
previous: FileMutationResult,
|
|
81
|
+
updated: FileMutationResult,
|
|
82
|
+
): void {
|
|
83
|
+
const index = script.results.indexOf(previous);
|
|
84
|
+
if (index >= 0) script.results[index] = updated;
|
|
85
|
+
for (const [slot, presentation] of script.presentations.entries()) {
|
|
86
|
+
const results = presentation.result.details.results;
|
|
87
|
+
if (!results?.includes(previous)) continue;
|
|
88
|
+
script.presentations[slot] = {
|
|
89
|
+
...presentation,
|
|
90
|
+
result: {
|
|
91
|
+
...presentation.result,
|
|
92
|
+
details: {
|
|
93
|
+
...presentation.result.details,
|
|
94
|
+
results: results.map((result) => (result === previous ? updated : result)),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
84
100
|
function mergedFiles(files: MutationData["files"]): MutationData["files"] {
|
|
85
101
|
const merged = new Map<string, MutationData["files"][number]>();
|
|
86
102
|
for (const file of files) {
|
|
@@ -104,7 +120,7 @@ function receiptEffect(files: MutationData["files"]): MutationData["effect"] {
|
|
|
104
120
|
: "not-applied";
|
|
105
121
|
}
|
|
106
122
|
|
|
107
|
-
function receiptStatus(errors: readonly unknown[], operations:
|
|
123
|
+
function receiptStatus(errors: readonly unknown[], operations: BatchMutationData["operations"]) {
|
|
108
124
|
return errors.length === 0
|
|
109
125
|
? ("success" as const)
|
|
110
126
|
: operations.some(
|
|
@@ -136,6 +152,7 @@ function isBatchable(
|
|
|
136
152
|
input: Readonly<Record<string, unknown>>,
|
|
137
153
|
): boolean {
|
|
138
154
|
if (
|
|
155
|
+
registration.name === "write" ||
|
|
139
156
|
registration.direct?.matches(input) ||
|
|
140
157
|
registration.intent === "restore" ||
|
|
141
158
|
isWholeFileInvocation(registration.wholeFileOperation, input) ||
|
|
@@ -172,73 +189,6 @@ class NativeTextEditBatchCoordinator {
|
|
|
172
189
|
private readonly pi: ExtensionAPI,
|
|
173
190
|
) {
|
|
174
191
|
this.resultTargets = connectResultTargets(pi);
|
|
175
|
-
pi.registerTool({
|
|
176
|
-
name: "flush",
|
|
177
|
-
exposure: "codemode",
|
|
178
|
-
namespace: {
|
|
179
|
-
name: "ide_edit",
|
|
180
|
-
description: "Edit files and live IDE resources with guarded operations.",
|
|
181
|
-
},
|
|
182
|
-
annotations: {
|
|
183
|
-
readOnlyHint: false,
|
|
184
|
-
destructiveHint: true,
|
|
185
|
-
idempotentHint: false,
|
|
186
|
-
openWorldHint: false,
|
|
187
|
-
},
|
|
188
|
-
label: "Flush",
|
|
189
|
-
description:
|
|
190
|
-
"Use flush to commit pending native Codemode text edits and return their observed effects. Await tools.flush({}) before depending on a completed write. A failed flush retains applied effects and does not replay edits. Call it only inside native Codemode.",
|
|
191
|
-
promptSnippet: "Commit pending native editor changes and inspect their effects",
|
|
192
|
-
parameters: Type.Object({}, { additionalProperties: false }),
|
|
193
|
-
outputSchema: flushOutputSchema,
|
|
194
|
-
execute: async (id) => {
|
|
195
|
-
const script = this.invocations.get(id);
|
|
196
|
-
if (!script) throw new Error("Flush requires an active native Codemode script");
|
|
197
|
-
const work = script.scheduler.run(undefined, async () => {
|
|
198
|
-
await this.commit(script);
|
|
199
|
-
const reports = script.reports.slice(script.reportCursor);
|
|
200
|
-
script.reportCursor = script.reports.length;
|
|
201
|
-
const files = mergedFiles(reports.flatMap((report) => report.data?.files ?? []));
|
|
202
|
-
const errors = reports.flatMap((report) => report.errors);
|
|
203
|
-
const operations = reports.flatMap((report) => report.data?.operations ?? []);
|
|
204
|
-
const effect = receiptEffect(files);
|
|
205
|
-
return withStructuredResult(
|
|
206
|
-
{
|
|
207
|
-
content: [
|
|
208
|
-
{
|
|
209
|
-
type: "text",
|
|
210
|
-
text: [
|
|
211
|
-
errors.length === 0
|
|
212
|
-
? `Flushed ${operations.length} editor operations; ${effect}.`
|
|
213
|
-
: `Editor flush failed; ${effect}.`,
|
|
214
|
-
...files.map(
|
|
215
|
-
(file) =>
|
|
216
|
-
`${file.source}: ${file.effect}${file.state ? ` (${file.state})` : ""}`,
|
|
217
|
-
),
|
|
218
|
-
...operations.map(
|
|
219
|
-
(operation) =>
|
|
220
|
-
`${operation.operation}: ${operation.effect}${operation.errors.length ? ` — ${operation.errors.map((error) => error.message).join("; ")}` : ""}`,
|
|
221
|
-
),
|
|
222
|
-
].join("\n"),
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
details: { results: [] },
|
|
226
|
-
},
|
|
227
|
-
flushDataSchema,
|
|
228
|
-
{
|
|
229
|
-
status: receiptStatus(errors, operations),
|
|
230
|
-
data: { operation: "flush", effect, files, operations },
|
|
231
|
-
errors,
|
|
232
|
-
},
|
|
233
|
-
);
|
|
234
|
-
});
|
|
235
|
-
script.tail = work.then(
|
|
236
|
-
() => undefined,
|
|
237
|
-
() => undefined,
|
|
238
|
-
);
|
|
239
|
-
return work;
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
192
|
pi.on("tool_call", async (event, context) => {
|
|
243
193
|
if (event.toolName === "codemode" && event.parentToolCallId === undefined) {
|
|
244
194
|
this.scripts.set(event.toolCallId, {
|
|
@@ -246,7 +196,6 @@ class NativeTextEditBatchCoordinator {
|
|
|
246
196
|
context,
|
|
247
197
|
summaries: [],
|
|
248
198
|
reports: [],
|
|
249
|
-
reportCursor: 0,
|
|
250
199
|
presentations: [],
|
|
251
200
|
results: [],
|
|
252
201
|
errors: [],
|
|
@@ -256,6 +205,7 @@ class NativeTextEditBatchCoordinator {
|
|
|
256
205
|
tail: Promise.resolve(),
|
|
257
206
|
scheduler: new ResourceScheduler(),
|
|
258
207
|
callOrder: new Map(),
|
|
208
|
+
unfinishedCalls: new Map(),
|
|
259
209
|
pending: pendingBatch(),
|
|
260
210
|
closed: false,
|
|
261
211
|
});
|
|
@@ -264,15 +214,18 @@ class NativeTextEditBatchCoordinator {
|
|
|
264
214
|
const script =
|
|
265
215
|
event.parentToolCallId === undefined ? undefined : this.scripts.get(event.parentToolCallId);
|
|
266
216
|
if (!script) return;
|
|
267
|
-
if (event.toolName === "flush") {
|
|
268
|
-
this.invocations.set(event.toolCallId, script);
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
217
|
const registration = this.core
|
|
272
218
|
.getMutationTools()
|
|
273
219
|
.find((tool) => tool.name === event.toolName);
|
|
274
|
-
if (registration) this.scopedInvocations.set(event.toolCallId, script);
|
|
275
220
|
const input: Record<string, unknown> = event.input;
|
|
221
|
+
if (registration) {
|
|
222
|
+
this.scopedInvocations.set(event.toolCallId, script);
|
|
223
|
+
const source = input[registration.source.field];
|
|
224
|
+
script.unfinishedCalls.set(
|
|
225
|
+
event.toolCallId,
|
|
226
|
+
typeof source === "string" && !isResultInput(source) ? source : "",
|
|
227
|
+
);
|
|
228
|
+
}
|
|
276
229
|
let ownsSource = false;
|
|
277
230
|
if (registration && !isWholeFileInvocation(registration.wholeFileOperation, input)) {
|
|
278
231
|
const resolverContext = {
|
|
@@ -283,7 +236,9 @@ class NativeTextEditBatchCoordinator {
|
|
|
283
236
|
const value = input[descriptor.field];
|
|
284
237
|
if (typeof value === "string" && value.length > 0) {
|
|
285
238
|
if (
|
|
286
|
-
["replace", "write", "copy", "move", "delete", "undo"].includes(
|
|
239
|
+
["replace", "write", "copy", "move", "delete", "undo", "insert"].includes(
|
|
240
|
+
registration.name,
|
|
241
|
+
) &&
|
|
287
242
|
value.startsWith("RESULT#")
|
|
288
243
|
) {
|
|
289
244
|
// The executor validates result handles and returns a structured rejection.
|
|
@@ -326,25 +281,51 @@ class NativeTextEditBatchCoordinator {
|
|
|
326
281
|
return;
|
|
327
282
|
});
|
|
328
283
|
pi.on("tool_result", async (event) => {
|
|
284
|
+
this.scopedInvocations.get(event.toolCallId)?.unfinishedCalls.delete(event.toolCallId);
|
|
329
285
|
this.invocations.delete(event.toolCallId);
|
|
330
286
|
this.scopedInvocations.delete(event.toolCallId);
|
|
331
287
|
const script = this.scripts.get(event.toolCallId);
|
|
332
288
|
if (!script) return;
|
|
333
289
|
script.closed = true;
|
|
290
|
+
const texts = event.content
|
|
291
|
+
.filter((block) => block.type === "text")
|
|
292
|
+
.map((block) => block.text);
|
|
293
|
+
let executionError = texts.findLast((text) => text.startsWith("Script error:\n")) ?? "";
|
|
294
|
+
const executionDetails = event.details;
|
|
295
|
+
if (
|
|
296
|
+
event.isError &&
|
|
297
|
+
executionDetails !== null &&
|
|
298
|
+
typeof executionDetails === "object" &&
|
|
299
|
+
"fullOutputPath" in executionDetails &&
|
|
300
|
+
typeof executionDetails.fullOutputPath === "string"
|
|
301
|
+
) {
|
|
302
|
+
try {
|
|
303
|
+
const output = await readFile(executionDetails.fullOutputPath, "utf8");
|
|
304
|
+
// A timeout has one engine error line followed by the call summary, not a JavaScript stack.
|
|
305
|
+
const matches = [
|
|
306
|
+
...output.matchAll(
|
|
307
|
+
/(?:^|\n)(Script error:\nScript (?:aborted|timed out):[^\n]*\n\n(?:Tool calls made before the failure[^\n]*|No tool calls were made\.))/gu,
|
|
308
|
+
),
|
|
309
|
+
];
|
|
310
|
+
const match = matches.at(-1);
|
|
311
|
+
executionError =
|
|
312
|
+
match !== undefined &&
|
|
313
|
+
!output.slice(match.index + match[0].length).includes("Script error:\n")
|
|
314
|
+
? (match[1] ?? "")
|
|
315
|
+
: "";
|
|
316
|
+
} catch {
|
|
317
|
+
// Use the returned output when its complete artifact is unavailable.
|
|
318
|
+
}
|
|
319
|
+
}
|
|
334
320
|
const interrupted =
|
|
335
321
|
script.context.signal?.aborted ||
|
|
336
|
-
(event.isError &&
|
|
337
|
-
event.content.some(
|
|
338
|
-
(block) =>
|
|
339
|
-
block.type === "text" &&
|
|
340
|
-
/^Script error:\nScript (?:aborted|timed out):/u.test(block.text),
|
|
341
|
-
));
|
|
322
|
+
(event.isError && /^Script error:\nScript (?:aborted|timed out):/u.test(executionError));
|
|
342
323
|
if (interrupted) script.cancellation.abort();
|
|
343
324
|
await script.tail;
|
|
344
325
|
if (interrupted) {
|
|
345
326
|
if (script.pending.entries.length > 0) {
|
|
346
327
|
const error = resultError(
|
|
347
|
-
"
|
|
328
|
+
"The operation was interrupted before writing. No file was changed.",
|
|
348
329
|
"CANCELLED",
|
|
349
330
|
);
|
|
350
331
|
const operations = script.pending.entries.map((entry) => ({
|
|
@@ -357,7 +338,7 @@ class NativeTextEditBatchCoordinator {
|
|
|
357
338
|
status: "error",
|
|
358
339
|
errors: [error],
|
|
359
340
|
data: {
|
|
360
|
-
operation: "
|
|
341
|
+
operation: "batch",
|
|
361
342
|
effect: "not-applied",
|
|
362
343
|
operations,
|
|
363
344
|
files: [...script.pending.snapshots.keys()].map((source) => ({
|
|
@@ -374,46 +355,85 @@ class NativeTextEditBatchCoordinator {
|
|
|
374
355
|
script.pending = pendingBatch();
|
|
375
356
|
}
|
|
376
357
|
} else await this.commit(script);
|
|
358
|
+
if (interrupted) {
|
|
359
|
+
for (const [id, source] of script.unfinishedCalls) {
|
|
360
|
+
if (
|
|
361
|
+
script.presentations.some((presentation) => presentation.calls.includes(id)) ||
|
|
362
|
+
script.reports.some((report) =>
|
|
363
|
+
report.data?.operations.some((operation) => operation.id === id),
|
|
364
|
+
)
|
|
365
|
+
)
|
|
366
|
+
continue;
|
|
367
|
+
// Cancellation is not a result. Do not guess whether a resolver already wrote.
|
|
368
|
+
const message =
|
|
369
|
+
"The operation was interrupted. Its file effects are unknown.\nRead the affected files before retrying.";
|
|
370
|
+
const presentation = new MutationPresentation({
|
|
371
|
+
ok: false,
|
|
372
|
+
path: source,
|
|
373
|
+
fileChangedStatement: message,
|
|
374
|
+
errors: [{ path: source, code: "CANCELLED" }],
|
|
375
|
+
});
|
|
376
|
+
const result: AgentToolResult<FileMutationBatchResult> = {
|
|
377
|
+
content: [new FileMutationAgentResult(presentation).toTextContent()],
|
|
378
|
+
details: { results: [presentation], effect: "unknown" },
|
|
379
|
+
isError: true,
|
|
380
|
+
};
|
|
381
|
+
script.results.push(presentation);
|
|
382
|
+
script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
377
385
|
try {
|
|
378
386
|
await this.core.enqueueFileOperation(
|
|
379
387
|
() =>
|
|
380
|
-
script.postEdits.finish(
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
result
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
388
|
+
script.postEdits.finish(
|
|
389
|
+
(outcome) => {
|
|
390
|
+
const index = script.results.findLastIndex(
|
|
391
|
+
(item) => item.data.path === outcome.after.source,
|
|
392
|
+
);
|
|
393
|
+
if (index < 0) return;
|
|
394
|
+
const previous = requiredValue(script.results[index]).data;
|
|
395
|
+
const updated = new MutationPresentation({
|
|
396
|
+
...previous,
|
|
397
|
+
afterContent: outcome.after.content,
|
|
398
|
+
afterDocument: outcome.after,
|
|
399
|
+
formatting: outcome.postEditContributions
|
|
400
|
+
.map((item) => item.data)
|
|
401
|
+
.findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
|
|
402
|
+
diffStatuses: outcome.postEditContributions
|
|
403
|
+
.map((item) => item.data)
|
|
404
|
+
.filter(isDiffStatusContribution)
|
|
405
|
+
.flatMap((item) => item.diffStatuses),
|
|
406
|
+
});
|
|
407
|
+
replaceScriptResult(script, requiredValue(script.results[index]), updated);
|
|
408
|
+
},
|
|
409
|
+
(source, error) => {
|
|
410
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
411
|
+
const failure = { code: "POST_EDIT_FAILED", message: reason, source };
|
|
412
|
+
for (const previous of script.results.filter(
|
|
413
|
+
(result) => result.data.path === source,
|
|
414
|
+
)) {
|
|
415
|
+
replaceScriptResult(
|
|
416
|
+
script,
|
|
417
|
+
previous,
|
|
418
|
+
new MutationPresentation({
|
|
419
|
+
ok: false,
|
|
420
|
+
path: source,
|
|
421
|
+
errors: [{ path: source, code: failure.code, reason }],
|
|
422
|
+
fileChangedStatement:
|
|
423
|
+
"The edit was saved, but final processing failed. Final text is not confirmed. Run Read/Search before editing this resource again.",
|
|
424
|
+
}),
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
for (const [index, report] of script.reports.entries()) {
|
|
428
|
+
if (!report.data?.files.some((file) => file.source === source)) continue;
|
|
429
|
+
script.reports[index] = {
|
|
430
|
+
...report,
|
|
431
|
+
status: report.status === "success" ? "partial" : report.status,
|
|
432
|
+
errors: [...report.errors, failure],
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
),
|
|
417
437
|
undefined,
|
|
418
438
|
{ cwd: script.context.cwd, sources: script.postEdits.sources() },
|
|
419
439
|
);
|
|
@@ -478,16 +498,23 @@ class NativeTextEditBatchCoordinator {
|
|
|
478
498
|
pi.on("session_shutdown", clear);
|
|
479
499
|
}
|
|
480
500
|
|
|
481
|
-
/**
|
|
482
|
-
runPostEdits<T>(id: string, work: () => T): T {
|
|
501
|
+
/** Share post-edit state while allowing Write to finish its own processing immediately. */
|
|
502
|
+
runPostEdits<T>(id: string, work: () => T, immediate: boolean): T {
|
|
483
503
|
const script = this.scopedInvocations.get(id);
|
|
484
|
-
return script ? script.postEdits.run(work) : work();
|
|
504
|
+
return script ? script.postEdits.run(work, immediate) : work();
|
|
485
505
|
}
|
|
486
506
|
|
|
487
|
-
/** Include non-batched mutations in the script's final post-edit presentation. */
|
|
507
|
+
/** Include applied, non-batched mutations in the script's final post-edit presentation. */
|
|
488
508
|
recordMutation(id: string, result: AgentToolResult<FileMutationBatchResult>): void {
|
|
489
509
|
const script = this.scopedInvocations.get(id);
|
|
490
|
-
if (
|
|
510
|
+
if (script && !script.closed) script.unfinishedCalls.delete(id);
|
|
511
|
+
if (
|
|
512
|
+
!script ||
|
|
513
|
+
script.closed ||
|
|
514
|
+
result.details.effect === "not-applied" ||
|
|
515
|
+
!result.details.results?.some((item) => item.data.ok === true)
|
|
516
|
+
)
|
|
517
|
+
return;
|
|
491
518
|
script.results.push(...result.details.results);
|
|
492
519
|
script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
|
|
493
520
|
}
|
|
@@ -615,6 +642,13 @@ class NativeTextEditBatchCoordinator {
|
|
|
615
642
|
? this.resultTargets.reserve(context.cwd)
|
|
616
643
|
: undefined;
|
|
617
644
|
if (target) script.targets.set(id, target);
|
|
645
|
+
const unchangedCopy =
|
|
646
|
+
registration.name === "copy" &&
|
|
647
|
+
planning.plan.mutations.every(
|
|
648
|
+
({ mutation }) =>
|
|
649
|
+
mutation.edits.size > 0 &&
|
|
650
|
+
unchangedCopySources(mutation, batch.snapshots).size === mutation.edits.size,
|
|
651
|
+
);
|
|
618
652
|
const details = {
|
|
619
653
|
results: [],
|
|
620
654
|
source: entry.path,
|
|
@@ -626,7 +660,12 @@ class NativeTextEditBatchCoordinator {
|
|
|
626
660
|
content: [
|
|
627
661
|
{
|
|
628
662
|
type: "text",
|
|
629
|
-
text:
|
|
663
|
+
text:
|
|
664
|
+
registration.name === "copy"
|
|
665
|
+
? unchangedCopy
|
|
666
|
+
? "No changes: destination already has this text."
|
|
667
|
+
: `Copy destination: ${typeof normalized.target === "string" ? normalized.target : entry.path}`
|
|
668
|
+
: `Accepted ${registration.name} for ${entry.path}. Check the final Codemode result for applied changes.`,
|
|
630
669
|
},
|
|
631
670
|
],
|
|
632
671
|
details,
|
|
@@ -645,6 +684,7 @@ class NativeTextEditBatchCoordinator {
|
|
|
645
684
|
mapped = committedMutationTargets(
|
|
646
685
|
batch.plan.mutations.map(({ callId, mutation }) => ({ callId, edits: mutation.edits })),
|
|
647
686
|
completions,
|
|
687
|
+
batch.snapshots,
|
|
648
688
|
);
|
|
649
689
|
} catch (error) {
|
|
650
690
|
for (const entry of batch.entries) {
|
|
@@ -688,6 +728,17 @@ class NativeTextEditBatchCoordinator {
|
|
|
688
728
|
script.context.signal === undefined
|
|
689
729
|
? script.cancellation.signal
|
|
690
730
|
: AbortSignal.any([script.context.signal, script.cancellation.signal]);
|
|
731
|
+
const unchangedCopies = new Map(
|
|
732
|
+
batch.plan.mutations
|
|
733
|
+
.filter(({ mutation }) => mutation.operation === "copy")
|
|
734
|
+
.map(({ callId, mutation }) => {
|
|
735
|
+
const sources = unchangedCopySources(mutation, batch.snapshots);
|
|
736
|
+
return [
|
|
737
|
+
callId,
|
|
738
|
+
{ sources, all: sources.size > 0 && sources.size === mutation.edits.size },
|
|
739
|
+
] as const;
|
|
740
|
+
}),
|
|
741
|
+
);
|
|
691
742
|
let observedSources: string[] = [];
|
|
692
743
|
const record = (outcome: StructuredResult<MutationData>): boolean => {
|
|
693
744
|
const calls = journal.snapshot();
|
|
@@ -695,11 +746,13 @@ class NativeTextEditBatchCoordinator {
|
|
|
695
746
|
id: call.callId,
|
|
696
747
|
operation: requiredValue(batch.entries.find((entry) => entry.callId === call.callId)).op,
|
|
697
748
|
effect:
|
|
698
|
-
call.state === "completed"
|
|
699
|
-
? ("applied" as const)
|
|
700
|
-
: call.state === "
|
|
701
|
-
? ("
|
|
702
|
-
:
|
|
749
|
+
call.state === "completed" && unchangedCopies.get(call.callId)?.all
|
|
750
|
+
? ("not-applied" as const)
|
|
751
|
+
: call.state === "completed" || call.state === "failed-applied"
|
|
752
|
+
? ("applied" as const)
|
|
753
|
+
: call.state === "failed-unknown" || call.state === "running"
|
|
754
|
+
? ("unknown" as const)
|
|
755
|
+
: ("not-applied" as const),
|
|
703
756
|
errors: call.failure === undefined ? [] : [resultError(call.failure.error)],
|
|
704
757
|
}));
|
|
705
758
|
const files = mergedFiles([
|
|
@@ -712,7 +765,10 @@ class NativeTextEditBatchCoordinator {
|
|
|
712
765
|
return [...mutationSources(registration, entry).values()].map((source) => ({
|
|
713
766
|
source,
|
|
714
767
|
effect:
|
|
715
|
-
mutation?.edits.has(source) === false
|
|
768
|
+
mutation?.edits.has(source) === false ||
|
|
769
|
+
unchangedCopies.get(operation.id)?.sources.has(source) === true
|
|
770
|
+
? ("not-applied" as const)
|
|
771
|
+
: operation.effect,
|
|
716
772
|
}));
|
|
717
773
|
}),
|
|
718
774
|
...observedSources.map((source) => ({ source, effect: "applied" as const })),
|
|
@@ -734,7 +790,7 @@ class NativeTextEditBatchCoordinator {
|
|
|
734
790
|
errors,
|
|
735
791
|
data: {
|
|
736
792
|
...outcome.data,
|
|
737
|
-
operation: "
|
|
793
|
+
operation: "batch",
|
|
738
794
|
effect: receiptEffect(files),
|
|
739
795
|
files,
|
|
740
796
|
operations,
|
|
@@ -775,16 +831,36 @@ class NativeTextEditBatchCoordinator {
|
|
|
775
831
|
);
|
|
776
832
|
observedSources = captured.completions.map((completion) => completion.resourceSource);
|
|
777
833
|
if (captured.kind === "failed") throw captured.error;
|
|
778
|
-
|
|
834
|
+
const value =
|
|
835
|
+
captured.completions.length === 0 &&
|
|
836
|
+
journal
|
|
837
|
+
.snapshot()
|
|
838
|
+
.every((call) => call.state === "completed" && unchangedCopies.get(call.callId)?.all)
|
|
839
|
+
? {
|
|
840
|
+
...captured.value,
|
|
841
|
+
content: [
|
|
842
|
+
{ type: "text" as const, text: "No changes: destination already has this text." },
|
|
843
|
+
],
|
|
844
|
+
details: { ...captured.value.details, effect: "not-applied" as const },
|
|
845
|
+
}
|
|
846
|
+
: captured.value;
|
|
847
|
+
script.results.push(...(value.details.results ?? []));
|
|
779
848
|
await this.settleTargets(script, batch, journal, captured.completions, signal);
|
|
780
849
|
const presentation = {
|
|
781
850
|
parentToolCallId: script.id,
|
|
782
851
|
calls: batch.entries.map((entry) => entry.callId),
|
|
783
|
-
|
|
852
|
+
unchangedCopyCalls: journal
|
|
853
|
+
.snapshot()
|
|
854
|
+
.filter((call) => call.state === "completed" && unchangedCopies.get(call.callId)?.all)
|
|
855
|
+
.map((call) => call.callId),
|
|
856
|
+
...(value.details.copyResults === undefined
|
|
857
|
+
? {}
|
|
858
|
+
: { copyResults: value.details.copyResults }),
|
|
859
|
+
result: value,
|
|
784
860
|
} satisfies NativeEditBatchEvent;
|
|
785
861
|
script.presentations.push(presentation);
|
|
786
862
|
this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, presentation);
|
|
787
|
-
return record(mutationOutcome(
|
|
863
|
+
return record(mutationOutcome(value, "batch", captured.completions));
|
|
788
864
|
} catch (error) {
|
|
789
865
|
journal.markRunningUnknown(error);
|
|
790
866
|
await this.settleTargets(script, batch, journal, [], signal);
|
|
@@ -795,10 +871,15 @@ class NativeTextEditBatchCoordinator {
|
|
|
795
871
|
|
|
796
872
|
const coordinators = new WeakMap<TextEditorCore, NativeTextEditBatchCoordinator>();
|
|
797
873
|
|
|
798
|
-
/**
|
|
799
|
-
export function runNativePostEditScope<T>(
|
|
874
|
+
/** Share deferred post-edit state, or finish this operation's processing before return. */
|
|
875
|
+
export function runNativePostEditScope<T>(
|
|
876
|
+
core: TextEditorCore,
|
|
877
|
+
id: string,
|
|
878
|
+
work: () => T,
|
|
879
|
+
immediate = false,
|
|
880
|
+
): T {
|
|
800
881
|
const coordinator = coordinators.get(core);
|
|
801
|
-
return coordinator ? coordinator.runPostEdits(id, work) : work();
|
|
882
|
+
return coordinator ? coordinator.runPostEdits(id, work, immediate) : work();
|
|
802
883
|
}
|
|
803
884
|
|
|
804
885
|
/** Retain immediate child results so final formatting is visible on the parent script. */
|