@bastani/atomic 0.9.20-alpha.8 → 0.9.20
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 +288 -0
- package/dist/builtin/intercom/CHANGELOG.md +25 -0
- package/dist/builtin/intercom/package.json +3 -5
- package/dist/builtin/mcp/CHANGELOG.md +13 -0
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/subagents/CHANGELOG.md +56 -0
- package/dist/builtin/subagents/package.json +3 -3
- package/dist/builtin/subagents/skills/tdd/SKILL.md +10 -2
- package/dist/builtin/subagents/skills/tdd/mocking.md +4 -0
- package/dist/builtin/subagents/skills/tdd/test-audit.md +105 -0
- package/dist/builtin/subagents/skills/tdd/tests.md +3 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +13 -3
- package/dist/builtin/web-access/CHANGELOG.md +13 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +169 -0
- package/dist/builtin/workflows/README.md +1 -1
- package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
- package/dist/builtin/workflows/builtin/{chunk-njmf5ze7.js → chunk-0nrgfbag.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-hmt5w62g.js → chunk-2hak3b7g.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-2hzrv5y8.js → chunk-73c5tayt.js} +1020 -200
- package/dist/builtin/workflows/builtin/{chunk-ffdrv23t.js → chunk-bzdvx2xr.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-5724b0cf.js → chunk-crw7q5g1.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-7n51c5gh.js → chunk-cw86srkf.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-dxjxtgmp.js → chunk-jaj27rqc.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-3tx8ry44.js → chunk-kspvwc24.js} +3 -2
- package/dist/builtin/workflows/builtin/{chunk-7bzcersz.js → chunk-maqv731g.js} +3 -3
- package/dist/builtin/workflows/builtin/{chunk-9z3ztr2a.js → chunk-vkmpdat4.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-vn0wb31x.js → chunk-w18kbz63.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-jngsbbpm.js → chunk-wh19f5ee.js} +3 -3
- package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
- package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
- package/dist/builtin/workflows/builtin/goal.js +4 -4
- package/dist/builtin/workflows/builtin/index.js +12 -12
- package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +4 -4
- package/dist/builtin/workflows/builtin/steering-context.js +1 -1
- package/dist/builtin/workflows/builtin/tournament.js +3 -3
- package/dist/builtin/workflows/package.json +4 -4
- package/dist/builtin/workflows/src/authoring.d.ts +6 -3
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +12164 -11365
- package/dist/builtin/workflows/src/index.js +41685 -12907
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +13 -0
- package/dist/core/agent-session-boundaries.d.ts.map +1 -1
- package/dist/core/agent-session-boundaries.js +9 -4
- package/dist/core/agent-session-boundaries.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +4 -0
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
- package/dist/core/agent-session-queue-pause.js +2 -1
- package/dist/core/agent-session-queue-pause.js.map +1 -1
- package/dist/core/agent-session-tasks.js +4 -4
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +4 -3
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session.d.ts +3 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +3 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/cache-stats.d.ts +7 -1
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +24 -5
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/context-tool-pairing.d.ts +10 -14
- package/dist/core/context-tool-pairing.d.ts.map +1 -1
- package/dist/core/context-tool-pairing.js +99 -28
- package/dist/core/context-tool-pairing.js.map +1 -1
- package/dist/core/execution-model-router.d.ts +1 -1
- package/dist/core/execution-model-router.d.ts.map +1 -1
- package/dist/core/execution-model-router.js +23 -14
- package/dist/core/execution-model-router.js.map +1 -1
- package/dist/core/extensions/agent-events.d.ts +9 -1
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +2 -1
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -2
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.js +1 -0
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/extensions/provider-types.d.ts +34 -16
- package/dist/core/extensions/provider-types.d.ts.map +1 -1
- package/dist/core/extensions/provider-types.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +4 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/tool-types.d.ts +9 -0
- package/dist/core/extensions/tool-types.d.ts.map +1 -1
- package/dist/core/extensions/tool-types.js.map +1 -1
- package/dist/core/fast-model-routing.d.ts.map +1 -1
- package/dist/core/fast-model-routing.js +1 -0
- package/dist/core/fast-model-routing.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +2 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-registry.d.ts +3 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +6 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-runtime-auth.d.ts +2 -2
- package/dist/core/model-runtime-auth.d.ts.map +1 -1
- package/dist/core/model-runtime-auth.js.map +1 -1
- package/dist/core/model-runtime-streaming.d.ts.map +1 -1
- package/dist/core/model-runtime-streaming.js +2 -1
- package/dist/core/model-runtime-streaming.js.map +1 -1
- package/dist/core/model-runtime.d.ts +11 -3
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +41 -6
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager-npm.d.ts.map +1 -1
- package/dist/core/package-manager-npm.js +32 -8
- package/dist/core/package-manager-npm.js.map +1 -1
- package/dist/core/package-manager-resolver.js +3 -1
- package/dist/core/package-manager-resolver.js.map +1 -1
- package/dist/core/package-manager-types.d.ts +1 -0
- package/dist/core/package-manager-types.d.ts.map +1 -1
- package/dist/core/package-manager-types.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +40 -21
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +22 -20
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/provider-composer.d.ts +3 -3
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +54 -10
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +8 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +46 -4
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader-core.d.ts.map +1 -1
- package/dist/core/resource-loader-core.js +7 -3
- package/dist/core/resource-loader-core.js.map +1 -1
- package/dist/core/resource-loader-extension-warnings.d.ts +9 -0
- package/dist/core/resource-loader-extension-warnings.d.ts.map +1 -0
- package/dist/core/resource-loader-extension-warnings.js +54 -0
- package/dist/core/resource-loader-extension-warnings.js.map +1 -0
- package/dist/core/resource-loader-extensions.d.ts.map +1 -1
- package/dist/core/resource-loader-extensions.js +1 -0
- package/dist/core/resource-loader-extensions.js.map +1 -1
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.js +6 -0
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +3 -1
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk.js +16 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +4 -4
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/structured-output/choice-schema.d.ts +8 -0
- package/dist/core/structured-output/choice-schema.d.ts.map +1 -0
- package/dist/core/structured-output/choice-schema.js +79 -0
- package/dist/core/structured-output/choice-schema.js.map +1 -0
- package/dist/core/structured-output/index.d.ts +3 -5
- package/dist/core/structured-output/index.d.ts.map +1 -1
- package/dist/core/structured-output/index.js +218 -41
- package/dist/core/structured-output/index.js.map +1 -1
- package/dist/core/structured-output/resolver.d.ts +0 -46
- package/dist/core/structured-output/resolver.d.ts.map +1 -1
- package/dist/core/structured-output/resolver.js +15 -93
- package/dist/core/structured-output/resolver.js.map +1 -1
- package/dist/core/structured-output/types.d.ts +27 -21
- package/dist/core/structured-output/types.d.ts.map +1 -1
- package/dist/core/structured-output/types.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +9 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/owner-store.d.ts +6 -0
- package/dist/core/tasks/owner-store.d.ts.map +1 -1
- package/dist/core/tasks/owner-store.js +16 -3
- package/dist/core/tasks/owner-store.js.map +1 -1
- package/dist/core/tasks/pause.js +1 -1
- package/dist/core/tasks/pause.js.map +1 -1
- package/dist/core/tasks/supervisor.d.ts +4 -2
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js +9 -3
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js +1 -0
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +1 -0
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +1 -0
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.d.ts +4 -3
- package/dist/core/tools/file-mutation-coordinator.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-coordinator.js +45 -38
- package/dist/core/tools/file-mutation-coordinator.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +16 -0
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/structured-output.d.ts +9 -6
- package/dist/core/tools/structured-output.d.ts.map +1 -1
- package/dist/core/tools/structured-output.js +36 -8
- package/dist/core/tools/structured-output.js.map +1 -1
- package/dist/core/tools/todos.d.ts.map +1 -1
- package/dist/core/tools/todos.js +1 -0
- package/dist/core/tools/todos.js.map +1 -1
- package/dist/core/tools/tool-concurrency.d.ts +23 -0
- package/dist/core/tools/tool-concurrency.d.ts.map +1 -0
- package/dist/core/tools/tool-concurrency.js +58 -0
- package/dist/core/tools/tool-concurrency.js.map +1 -0
- package/dist/core/tools/tool-definition-wrapper.d.ts +4 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +1 -0
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js +11 -9
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +2 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/task-inspector.d.ts +1 -0
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +11 -11
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/components/task-list.d.ts +9 -3
- package/dist/modes/interactive/components/task-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-list.js +26 -2
- package/dist/modes/interactive/components/task-list.js.map +1 -1
- package/dist/modes/interactive/interactive-agent-events.js +3 -9
- package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +1 -1
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +3 -9
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-resource-rendering.js +6 -9
- package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +1 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-slash-commands.js +2 -4
- package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts +1 -0
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +5 -0
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +14 -17
- package/dist/utils/clipboard-image.js.map +1 -1
- package/docs/background-tasks.md +1 -0
- package/docs/computer-use.md +33 -9
- package/docs/custom-provider/registration.md +1 -1
- package/docs/custom-provider.md +43 -1
- package/docs/extensions/authoring.md +22 -3
- package/docs/extensions/events.md +18 -0
- package/docs/extensions/examples.md +1 -0
- package/docs/getting-started/first-session.md +1 -1
- package/docs/models/evals.md +31 -79
- package/docs/models/model-selection.md +5 -1
- package/docs/packages/authoring.md +3 -1
- package/docs/providers.md +7 -11
- package/docs/sdk/reference.md +18 -42
- package/docs/sdk/structured-decisions.md +44 -89
- package/docs/sdk.md +1 -1
- package/docs/settings.md +6 -6
- package/docs/skills.md +2 -2
- package/docs/subagents/reference.md +7 -8
- package/docs/usage.md +13 -0
- package/docs/workflows/api-reference.md +38 -35
- package/docs/workflows/authoring.md +113 -1
- package/docs/workflows/builtins.md +1 -1
- package/docs/workflows/operations.md +53 -29
- package/docs/workflows/reliable-design.md +1 -1
- package/docs/workflows/verification.md +38 -7
- package/docs/workflows.md +1 -1
- package/examples/extensions/README.md +1 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/structured-output.ts +6 -0
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
- package/dist/builtin/workflows/src/durable/dependency-doctor-types.d.ts +0 -42
- package/dist/core/decision-provider.d.ts +0 -4
- package/dist/core/decision-provider.d.ts.map +0 -1
- package/dist/core/decision-provider.js +0 -12
- package/dist/core/decision-provider.js.map +0 -1
- package/dist/core/structured-output/jev-client.d.ts +0 -25
- package/dist/core/structured-output/jev-client.d.ts.map +0 -1
- package/dist/core/structured-output/jev-client.js +0 -174
- package/dist/core/structured-output/jev-client.js.map +0 -1
- package/dist/core/structured-output/jev.d.ts +0 -5
- package/dist/core/structured-output/jev.d.ts.map +0 -1
- package/dist/core/structured-output/jev.js +0 -249
- package/dist/core/structured-output/jev.js.map +0 -1
|
@@ -63,46 +63,45 @@ export function computeConflictEvidence(assumed, found) {
|
|
|
63
63
|
...(start < endFound ? { found: clampLine(foundLines[start] ?? "") } : {}),
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
+
const SHELL_OUTPUT_IS_NOT_A_READ = "Shell output (cat, sed, head) and tags quoted in error messages do not count as reads.";
|
|
66
67
|
/**
|
|
67
68
|
* Paired so the instruction cannot contradict the diagnosis it follows.
|
|
68
69
|
*
|
|
69
|
-
* A single shared instruction cannot be true of all
|
|
70
|
-
* false for the
|
|
70
|
+
* A single shared instruction cannot be true of all seven reasons. "Read the file again" is
|
|
71
|
+
* false for the ones that fail precisely because the file was never read, and impossible for
|
|
71
72
|
* `target_missing`, where there is nothing left to read.
|
|
72
73
|
*/
|
|
73
74
|
const REASON_COPY = {
|
|
74
75
|
changed_before_write: {
|
|
75
|
-
diagnosis: "
|
|
76
|
-
instruction:
|
|
76
|
+
diagnosis: "The file changed after this edit was prepared.",
|
|
77
|
+
instruction: (path) => `Read ${path} again and rebuild the edit from its current content and tag. Do not resend the same edit.`,
|
|
77
78
|
},
|
|
78
79
|
no_prior_observation: {
|
|
79
|
-
diagnosis:
|
|
80
|
-
instruction:
|
|
80
|
+
diagnosis: `This session has not read the file it is overwriting. ${SHELL_OUTPUT_IS_NOT_A_READ}`,
|
|
81
|
+
instruction: (path) => `Read ${path} with the read tool, then decide whether this overwrite is still the change you want.`,
|
|
81
82
|
},
|
|
82
83
|
changed_since_observation: {
|
|
83
|
-
diagnosis: "
|
|
84
|
-
instruction:
|
|
84
|
+
diagnosis: "The file changed since this session last read it.",
|
|
85
|
+
instruction: (path) => `Read ${path} again and reconcile this change with its current content.`,
|
|
85
86
|
},
|
|
86
87
|
target_exists: {
|
|
87
|
-
diagnosis: "
|
|
88
|
-
instruction:
|
|
88
|
+
diagnosis: "The file already exists.",
|
|
89
|
+
instruction: (path) => `Read ${path} and edit it in place, or write to a different path.`,
|
|
89
90
|
},
|
|
90
91
|
target_missing: {
|
|
91
|
-
diagnosis: "
|
|
92
|
-
instruction: "Do not read it
|
|
92
|
+
diagnosis: "The file no longer exists.",
|
|
93
|
+
instruction: () => "Do not read it. Confirm the removal was intended, then recreate the file or drop this change.",
|
|
93
94
|
},
|
|
94
95
|
target_unreadable: {
|
|
95
|
-
diagnosis: "
|
|
96
|
-
instruction:
|
|
96
|
+
diagnosis: "The file still exists but can no longer be read.",
|
|
97
|
+
instruction: (path) => `Something replaced or locked ${path} rather than editing it. Inspect what is there before retrying; an identical edit will fail the same way.`,
|
|
97
98
|
},
|
|
98
99
|
foreign_snapshot: {
|
|
99
|
-
diagnosis:
|
|
100
|
-
instruction:
|
|
100
|
+
diagnosis: `The presented tag was not issued to this session. Only read, search, write, and edit results issue tags. ${SHELL_OUTPUT_IS_NOT_A_READ}`,
|
|
101
|
+
instruction: (path) => `Read ${path} with the read tool (a line range such as ${path}:10-40 is enough), then retry with the tag and line numbers from that result. Nothing was written.`,
|
|
101
102
|
},
|
|
102
103
|
};
|
|
103
104
|
function describeRequester(requester) {
|
|
104
|
-
if (!requester)
|
|
105
|
-
return "";
|
|
106
105
|
const parts = [`session=${requester.sessionId}`];
|
|
107
106
|
if (requester.parentSessionId)
|
|
108
107
|
parts.push(`parent=${requester.parentSessionId}`);
|
|
@@ -124,10 +123,10 @@ function describeRequester(requester) {
|
|
|
124
123
|
parts.push(`attempt=${requester.attemptId}`);
|
|
125
124
|
if (requester.toolCallId)
|
|
126
125
|
parts.push(`call=${requester.toolCallId}`);
|
|
127
|
-
return
|
|
126
|
+
return parts.join(" ");
|
|
128
127
|
}
|
|
129
128
|
/**
|
|
130
|
-
* Quote an excerpt of file content
|
|
129
|
+
* Quote an excerpt of file content so it stays on its own line of the message.
|
|
131
130
|
*
|
|
132
131
|
* `JSON.stringify` rather than wrapping in backticks or quotes of our own: source lines
|
|
133
132
|
* routinely contain both, and a template literal in a TypeScript file would otherwise close
|
|
@@ -139,12 +138,10 @@ function quoteExcerpt(text) {
|
|
|
139
138
|
return JSON.stringify(text);
|
|
140
139
|
}
|
|
141
140
|
function describeEvidence(evidence) {
|
|
142
|
-
if (!evidence)
|
|
143
|
-
return "";
|
|
144
141
|
const span = evidence.assumedLines === 1 && evidence.foundLines === 1
|
|
145
142
|
? ""
|
|
146
143
|
: ` (${evidence.assumedLines} lines replaced by ${evidence.foundLines})`;
|
|
147
|
-
const at = `
|
|
144
|
+
const at = `line ${evidence.line}`;
|
|
148
145
|
if (evidence.assumed !== undefined && evidence.found !== undefined) {
|
|
149
146
|
return `${at}: assumed ${quoteExcerpt(evidence.assumed)}, found ${quoteExcerpt(evidence.found)}${span}.`;
|
|
150
147
|
}
|
|
@@ -153,13 +150,15 @@ function describeEvidence(evidence) {
|
|
|
153
150
|
}
|
|
154
151
|
return `${at}: assumed ${quoteExcerpt(evidence.assumed ?? "")}, which is no longer present${span}.`;
|
|
155
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The live tag is labeled as unusable because it is not minted by the refusal: an agent that
|
|
155
|
+
* copies it into a retry is rejected again with the same conflict.
|
|
156
|
+
*/
|
|
156
157
|
function describeLiveState(state) {
|
|
157
|
-
if (!state)
|
|
158
|
-
return "";
|
|
159
158
|
if (!state.tag)
|
|
160
|
-
return "
|
|
161
|
-
const first = state.firstLine ? `,
|
|
162
|
-
return
|
|
159
|
+
return "does not exist.";
|
|
160
|
+
const first = state.firstLine ? `, first line ${quoteExcerpt(state.firstLine)}` : "";
|
|
161
|
+
return `${state.lines} lines${first}. Current tag #${state.tag} is for comparison only; edits need a tag from your own read.`;
|
|
163
162
|
}
|
|
164
163
|
/**
|
|
165
164
|
* Raised instead of a bare `Error` so a conflict is countable rather than merely readable.
|
|
@@ -180,19 +179,27 @@ export class FileMutationConflict extends Error {
|
|
|
180
179
|
this.causeCode = details.causeCode;
|
|
181
180
|
}
|
|
182
181
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
182
|
+
* One labeled line per concern, ordered by what must survive truncation: the code, reason,
|
|
183
|
+
* and path first, then why and what to do, then the divergence and live state, and the
|
|
184
|
+
* requester identity last. Identity is correlation for logs, never guidance, so it is the
|
|
185
|
+
* most expendable part of the message for the model reading it.
|
|
186
186
|
*/
|
|
187
187
|
static formatMessage(details) {
|
|
188
|
-
const tag = details.presentedTag ? ` (presented #${details.presentedTag})` : "";
|
|
189
188
|
const copy = REASON_COPY[details.reason];
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
const presented = details.presentedTag ? ` (presented #${details.presentedTag})` : "";
|
|
190
|
+
const cause = details.causeCode ? ` Filesystem error: ${details.causeCode}.` : "";
|
|
191
|
+
const lines = [
|
|
192
|
+
`${FILE_MUTATION_CONFLICT_CODE}:${details.reason} ${details.path}${presented}`,
|
|
193
|
+
`Why: ${copy.diagnosis}${cause}`,
|
|
194
|
+
`Next: ${copy.instruction(details.path)}`,
|
|
195
|
+
];
|
|
196
|
+
if (details.evidence)
|
|
197
|
+
lines.push(`First divergence: ${describeEvidence(details.evidence)}`);
|
|
198
|
+
if (details.liveState)
|
|
199
|
+
lines.push(`Live file: ${describeLiveState(details.liveState)}`);
|
|
200
|
+
if (details.requester)
|
|
201
|
+
lines.push(`Requester: ${describeRequester(details.requester)}`);
|
|
202
|
+
return lines.join("\n");
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
/** Whether a thrown value is an exclusive-create collision reported by the filesystem. */
|
|
@@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AAC,EAAE,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,mFAAmF;QACnF,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7D,CAAC;AACH,CAAC","sourcesContent":["import { computeFileHash, type SnapshotStore } from \"./hashline-engine/index.ts\";\n\n/**\n * Stable token carried inside every conflict message.\n *\n * It lives in the message text, not only on the class, because nothing typed survives the\n * trip from a tool to a workflow: a subagent result reports `cause`/`error` as strings, a\n * workflow task result has no error field at all, and a workflow runner reduces a failure to\n * `err.message`. Matching this token is how a consumer downstream of that flattening tells a\n * mutation conflict apart from an ordinary tool error.\n *\n * It is placed at the start of the message so it survives truncation of the tail as the\n * message is relayed. Never change it without updating every consumer that matches on it.\n */\nexport const FILE_MUTATION_CONFLICT_CODE = \"FILE_MUTATION_CONFLICT\";\n\n/**\n * Reasons report a {@link FileMutationLiveState} wherever the live target can be described,\n * which is everywhere except `target_unreadable`: that one exists precisely because the target\n * could not be read, so claiming a size or a tag for it would be invention.\n *\n * Only the reasons that have something to compare against also report a\n * {@link FileMutationConflictEvidence} diff: `no_prior_observation` never read the file, and\n * `foreign_snapshot` presented a tag naming content this session has never seen, so in both\n * cases there is no prior side to diff.\n */\nexport type FileMutationConflictReason =\n\t/** Live content moved between the mutation being prepared and the write being attempted. */\n\t| \"changed_before_write\"\n\t/** Overwrite attempted with no prior read of this file in this session. */\n\t| \"no_prior_observation\"\n\t/** Overwrite attempted, but what this session observed is no longer the live content. */\n\t| \"changed_since_observation\"\n\t/** Exclusive create lost: the target already exists. */\n\t| \"target_exists\"\n\t/** The target no longer exists: removed between preparing the mutation and writing it. */\n\t| \"target_missing\"\n\t/**\n\t * The target still exists but can no longer be read: replaced by a directory, made\n\t * unreadable, locked, or rewritten as content this reader cannot parse. Distinct from a\n\t * content change because there is nothing to diff, and from a deletion because the path is\n\t * still occupied.\n\t */\n\t| \"target_unreadable\"\n\t/** The presented tag was never minted in this session's snapshot store. */\n\t| \"foreign_snapshot\";\n\n/**\n * Correlation only.\n *\n * Flora, 2026-08-13: identity \"must never grant permission or identify a current owner or\n * culprit\". So this describes the writer being *rejected*, never a winner, and nothing in\n * this module reads it to decide whether a mutation is admitted. A record of the last Atomic\n * writer could not prove ownership anyway, because shell commands, external programs, other\n * Atomic processes and symlink changes all bypass this coordinator.\n */\nexport interface MutationRequester {\n\treadonly sessionId: string;\n\t/** Session that spawned this one, from the child's `supervisor.supervisorSessionId`. */\n\treadonly parentSessionId?: string;\n\treadonly workflowRunId?: string;\n\treadonly workflowStageId?: string;\n\treadonly workflowStageName?: string;\n\treadonly subagentRunId?: string;\n\treadonly subagentAgent?: string;\n\t/**\n\t * Position within a fan-out. Needed to tell siblings apart: a child's intercom address is\n\t * `agent + runId + index` (`resolveSubagentIntercomTarget`), so a stage that spawns several\n\t * children of one agent onto one file yields identical identity without it.\n\t */\n\treadonly subagentIndex?: number;\n\t/** Opaque per-attempt UUID. Diagnostic only; never an authority. */\n\treadonly attemptId?: string;\n\t/** The specific tool call rejected. Narrower than the attempt, which makes many calls. */\n\treadonly toolCallId?: string;\n}\n\n/**\n * Resolved per execution rather than captured once.\n *\n * Mirrors `sessionTempDir` in the session tool registry, which is a thunk \"so bash spill\n * files follow the live transcript session across fork/branch/resume\". A requester captured\n * at tool-construction time would keep a stale session id through exactly those transitions,\n * which is the relaunch case this feature exists to make legible.\n *\n * Takes the tool call id rather than leaving callers to merge it in, because it has a\n * different lifetime from the rest: session identity belongs to the session, the call id is\n * an argument of the single `execute` being rejected.\n */\nexport type MutationRequesterResolver = (toolCallId: string) => MutationRequester | undefined;\n\n/**\n * What actually diverged, so a conflict can be acted on without a second round trip.\n *\n * A reason and a path are not evidence; they say a race happened, not what it did. Whatever acts\n * on the rejection, a workflow applying its own control behavior or a human reading the error,\n * needs the divergence itself before it can decide anything.\n *\n * The span is computed by trimming the common prefix and suffix rather than comparing line by\n * line positionally, so inserting one line at the top reports one changed region and not every\n * following line.\n */\nexport interface FileMutationConflictEvidence {\n\t/** 1-based line of the first divergence. */\n\treadonly line: number;\n\t/** Lines the rejected mutation assumed occupied the divergent span. */\n\treadonly assumedLines: number;\n\t/** Lines actually occupying it now. */\n\treadonly foundLines: number;\n\t/** First assumed line, clamped. Absent when the span is pure insertion. */\n\treadonly assumed?: string;\n\t/** First live line, clamped. Absent when the span is pure deletion. */\n\treadonly found?: string;\n}\n\n/**\n * Excerpts are clamped because a conflict travels as message text through channels that\n * truncate, and because file content copied into an error outlives the turn in ledger records.\n * One line per side is enough to tell the model whether its plan still holds.\n */\nconst EVIDENCE_LINE_CHARS = 120;\n\nfunction clampLine(line: string): string {\n\treturn line.length <= EVIDENCE_LINE_CHARS ? line : `${line.slice(0, EVIDENCE_LINE_CHARS)}...`;\n}\n\n/**\n * The target as it stood at the moment of refusal, independent of any comparison.\n *\n * Kept separate from {@link FileMutationConflictEvidence} because the two answer different\n * questions and only one of them can be unanswerable. A conflict may have nothing to diff\n * against, as when the session never read the file, but there is still always something worth\n * reporting about what the mutation was aimed at. Size in particular is the difference between\n * clobbering an empty placeholder and clobbering four hundred lines of production code.\n */\nexport interface FileMutationLiveState {\n\t/** Lines currently in the file. Zero when it is empty or does not exist. */\n\treadonly lines: number;\n\t/** Tag of the live content, so a rejected tag can be told apart from the real one. */\n\treadonly tag?: string;\n\t/** First line, clamped. Absent when the file is missing, empty, or starts with a blank line. */\n\treadonly firstLine?: string;\n}\n\n/** Describe live content, or a missing target when `live` is `undefined`. */\nexport function computeLiveState(live: string | undefined): FileMutationLiveState {\n\tif (live === undefined) return { lines: 0 };\n\t// Trailing newline terminates the last line rather than starting an empty one.\n\tconst lines = live === \"\" ? [] : live.replace(/\\n$/, \"\").split(\"\\n\");\n\tconst first = lines[0];\n\treturn {\n\t\tlines: lines.length,\n\t\ttag: computeFileHash(live),\n\t\t...(first ? { firstLine: clampLine(first) } : {}),\n\t};\n}\n\n/**\n * Compare what a mutation assumed against what is live, returning `undefined` when they agree.\n *\n * Both sides must already share a line-ending convention. `Snapshot.text` is normalized to LF,\n * so a caller passing raw live bytes on Windows would report every line as divergent.\n */\nexport function computeConflictEvidence(assumed: string, found: string): FileMutationConflictEvidence | undefined {\n\tif (assumed === found) return undefined;\n\tconst assumedLines = assumed.split(\"\\n\");\n\tconst foundLines = found.split(\"\\n\");\n\tlet start = 0;\n\twhile (start < assumedLines.length && start < foundLines.length && assumedLines[start] === foundLines[start]) {\n\t\tstart++;\n\t}\n\tlet endAssumed = assumedLines.length;\n\tlet endFound = foundLines.length;\n\twhile (endAssumed > start && endFound > start && assumedLines[endAssumed - 1] === foundLines[endFound - 1]) {\n\t\tendAssumed--;\n\t\tendFound--;\n\t}\n\treturn {\n\t\tline: start + 1,\n\t\tassumedLines: endAssumed - start,\n\t\tfoundLines: endFound - start,\n\t\t...(start < endAssumed ? { assumed: clampLine(assumedLines[start] ?? \"\") } : {}),\n\t\t...(start < endFound ? { found: clampLine(foundLines[start] ?? \"\") } : {}),\n\t};\n}\n\nexport interface FileMutationConflictDetails {\n\treadonly reason: FileMutationConflictReason;\n\t/** Display path, as the model referred to it. */\n\treadonly path: string;\n\t/** Symlink-resolved key, from `canonicalMutationKey`. */\n\treadonly canonicalKey: string;\n\treadonly requester?: MutationRequester;\n\t/** The tag the rejected mutation presented, when it had one. */\n\treadonly presentedTag?: string;\n\t/** Absent when the reason carries no comparison, as with `no_prior_observation`. */\n\treadonly evidence?: FileMutationConflictEvidence;\n\t/** What the mutation was aimed at. Absent only when it could not be read at all. */\n\treadonly liveState?: FileMutationLiveState;\n\t/**\n\t * Filesystem error code that classified the conflict, such as `EISDIR` or `EACCES`. For a\n\t * target that became unreadable this is the whole diagnosis, since nothing else about the\n\t * file can be reported once the read fails.\n\t */\n\treadonly causeCode?: string;\n}\n\ninterface ReasonCopy {\n\t/** Why the mutation was refused. */\n\treadonly diagnosis: string;\n\t/** What to do about it. */\n\treadonly instruction: string;\n}\n\n/**\n * Paired so the instruction cannot contradict the diagnosis it follows.\n *\n * A single shared instruction cannot be true of all six reasons. \"Read the file again\" is\n * false for the two that fail precisely because the file was never read, and impossible for\n * `target_missing`, where there is nothing left to read.\n */\nconst REASON_COPY: Record<FileMutationConflictReason, ReasonCopy> = {\n\tchanged_before_write: {\n\t\tdiagnosis: \"the file changed after this edit was prepared\",\n\t\tinstruction: \"Read the file again and rebuild this edit from what it says now; do not resend it unchanged.\",\n\t},\n\tno_prior_observation: {\n\t\tdiagnosis: \"this session has not read the file it is overwriting\",\n\t\tinstruction: \"Read the file first, then decide whether this overwrite is still the change you want.\",\n\t},\n\tchanged_since_observation: {\n\t\tdiagnosis: \"the file changed since this session last read it\",\n\t\tinstruction: \"Read the file again and reconcile this change with what is there now.\",\n\t},\n\ttarget_exists: {\n\t\tdiagnosis: \"the file already exists\",\n\t\tinstruction: \"Read the existing file and edit it in place, or write to a different path.\",\n\t},\n\ttarget_missing: {\n\t\tdiagnosis: \"the file no longer exists\",\n\t\tinstruction: \"Do not read it; confirm the removal was intended, then recreate the file or drop this change.\",\n\t},\n\ttarget_unreadable: {\n\t\tdiagnosis: \"the file still exists but could no longer be read\",\n\t\tinstruction:\n\t\t\t\"Something replaced or locked the path rather than editing it. Inspect what is there now before retrying; a second identical edit will fail the same way.\",\n\t},\n\tforeign_snapshot: {\n\t\tdiagnosis: \"the snapshot tag was not issued in this session\",\n\t\tinstruction: \"Read the file in this session to obtain a valid tag before editing it.\",\n\t},\n};\n\nfunction describeRequester(requester: MutationRequester | undefined): string {\n\tif (!requester) return \"\";\n\tconst parts = [`session=${requester.sessionId}`];\n\tif (requester.parentSessionId) parts.push(`parent=${requester.parentSessionId}`);\n\tif (requester.workflowRunId) parts.push(`run=${requester.workflowRunId}`);\n\tif (requester.workflowStageId) parts.push(`stage=${requester.workflowStageId}`);\n\t// Quoted: a stage name is free text and the field separator here is a space.\n\tif (requester.workflowStageName) parts.push(`stageName=\"${requester.workflowStageName}\"`);\n\tif (requester.subagentRunId) parts.push(`child=${requester.subagentRunId}`);\n\tif (requester.subagentAgent) parts.push(`agent=${requester.subagentAgent}`);\n\t// Presence, not truthiness: the first child of a fan-out is index 0.\n\tif (requester.subagentIndex !== undefined) parts.push(`index=${requester.subagentIndex}`);\n\tif (requester.attemptId) parts.push(`attempt=${requester.attemptId}`);\n\tif (requester.toolCallId) parts.push(`call=${requester.toolCallId}`);\n\treturn ` [${parts.join(\" \")}]`;\n}\n\n/**\n * Quote an excerpt of file content for inclusion in a single-line message.\n *\n * `JSON.stringify` rather than wrapping in backticks or quotes of our own: source lines\n * routinely contain both, and a template literal in a TypeScript file would otherwise close\n * the delimiter early and leave the excerpt unreadable. It also escapes control characters,\n * so a stray CR from a file this module was handed unnormalized shows up as `\\r` rather than\n * silently rearranging the message.\n */\nfunction quoteExcerpt(text: string): string {\n\treturn JSON.stringify(text);\n}\n\nfunction describeEvidence(evidence: FileMutationConflictEvidence | undefined): string {\n\tif (!evidence) return \"\";\n\tconst span =\n\t\tevidence.assumedLines === 1 && evidence.foundLines === 1\n\t\t\t? \"\"\n\t\t\t: ` (${evidence.assumedLines} lines replaced by ${evidence.foundLines})`;\n\tconst at = ` First divergence at line ${evidence.line}`;\n\tif (evidence.assumed !== undefined && evidence.found !== undefined) {\n\t\treturn `${at}: assumed ${quoteExcerpt(evidence.assumed)}, found ${quoteExcerpt(evidence.found)}${span}.`;\n\t}\n\tif (evidence.found !== undefined) {\n\t\treturn `${at}: found ${quoteExcerpt(evidence.found)} where this mutation expected nothing${span}.`;\n\t}\n\treturn `${at}: assumed ${quoteExcerpt(evidence.assumed ?? \"\")}, which is no longer present${span}.`;\n}\n\nfunction describeLiveState(state: FileMutationLiveState | undefined): string {\n\tif (!state) return \"\";\n\tif (!state.tag) return \" The target does not exist.\";\n\tconst first = state.firstLine ? `, starting ${quoteExcerpt(state.firstLine)}` : \"\";\n\treturn ` Target now holds ${state.lines} lines, #${state.tag}${first}.`;\n}\n\n/**\n * Raised instead of a bare `Error` so a conflict is countable rather than merely readable.\n * The message is the wire format; see {@link FILE_MUTATION_CONFLICT_CODE}.\n */\nexport class FileMutationConflict extends Error {\n\treadonly reason: FileMutationConflictReason;\n\treadonly path: string;\n\treadonly canonicalKey: string;\n\treadonly requester: MutationRequester | undefined;\n\treadonly presentedTag: string | undefined;\n\t/** Structured alongside the message so a ledger can record it without re-parsing text. */\n\treadonly evidence: FileMutationConflictEvidence | undefined;\n\treadonly liveState: FileMutationLiveState | undefined;\n\treadonly causeCode: string | undefined;\n\n\tconstructor(details: FileMutationConflictDetails) {\n\t\tsuper(FileMutationConflict.formatMessage(details));\n\t\t// Sub-classing Error does not set this, and consumers match on it.\n\t\tthis.name = \"FileMutationConflict\";\n\t\tthis.reason = details.reason;\n\t\tthis.path = details.path;\n\t\tthis.canonicalKey = details.canonicalKey;\n\t\tthis.requester = details.requester;\n\t\tthis.presentedTag = details.presentedTag;\n\t\tthis.evidence = details.evidence;\n\t\tthis.liveState = details.liveState;\n\t\tthis.causeCode = details.causeCode;\n\t}\n\n\t/**\n\t * Ordered by what must survive truncation: the code first, then the reason and guidance,\n\t * then the divergence, and the live-state summary last. The tail is the most expendable\n\t * because it is the part a reader can always recover by opening the file.\n\t */\n\tstatic formatMessage(details: FileMutationConflictDetails): string {\n\t\tconst tag = details.presentedTag ? ` (presented #${details.presentedTag})` : \"\";\n\t\tconst copy = REASON_COPY[details.reason];\n\t\tconst cause = details.causeCode ? ` (${details.causeCode})` : \"\";\n\t\treturn (\n\t\t\t`${FILE_MUTATION_CONFLICT_CODE}:${details.reason} ${details.path}${tag}: ` +\n\t\t\t`${copy.diagnosis}${cause}.${describeRequester(details.requester)} ` +\n\t\t\tcopy.instruction +\n\t\t\tdescribeEvidence(details.evidence) +\n\t\t\tdescribeLiveState(details.liveState)\n\t\t);\n\t}\n}\n\n/** Whether a thrown value is an exclusive-create collision reported by the filesystem. */\nexport function isExclusiveCreateCollision(error: unknown): boolean {\n\treturn typeof error === \"object\" && error !== null && \"code\" in error && error.code === \"EEXIST\";\n}\n\n/**\n * Whether a thrown value says the target is gone. `ENOTDIR` counts because a parent directory\n * replaced by a file makes the path unreachable for the same reason a deletion does.\n */\nexport function isMissingTargetError(error: unknown): boolean {\n\tconst code = filesystemErrorCode(error);\n\treturn code === \"ENOENT\" || code === \"ENOTDIR\";\n}\n\n/** The `code` a filesystem rejection carries, when it carries one. */\nexport function filesystemErrorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) return undefined;\n\tconst code = (error as { code?: unknown }).code;\n\treturn typeof code === \"string\" ? code : undefined;\n}\n\n/**\n * Guard for the window between preparing a mutation and committing it, called under the\n * mutation queue.\n *\n * `prepared` is the content the mutation was computed against, which for a hashline edit is\n * the file as `prepare` read it, NOT what the session originally observed, since `prepare`\n * re-reads and may have recovered onto drifted content. Naming that honestly matters: this\n * closes a time-of-check window, it does not prove the session read the file.\n *\n * Full text rather than tags: a hashline tag is 16 bits and the engine documents that it can\n * collide, so it is a label for the model to recognize, never proof of identity.\n */\nexport function assertLiveMatchesPrepared(args: {\n\treadonly canonicalKey: string;\n\treadonly path: string;\n\treadonly prepared: string;\n\treadonly live: string;\n\treadonly requester?: MutationRequester;\n\treadonly presentedTag?: string;\n}): void {\n\tif (args.live === args.prepared) return;\n\tconst evidence = computeConflictEvidence(args.prepared, args.live);\n\tthrow new FileMutationConflict({\n\t\treason: \"changed_before_write\",\n\t\tpath: args.path,\n\t\tcanonicalKey: args.canonicalKey,\n\t\trequester: args.requester,\n\t\tpresentedTag: args.presentedTag,\n\t\tliveState: computeLiveState(args.live),\n\t\t...(evidence ? { evidence } : {}),\n\t});\n}\n\n/**\n * Guard for `write` overwriting an existing file: this session must already have observed the\n * exact content it is about to replace.\n *\n * Asks the session's own store and never another session's, which is what keeps cross-session\n * rejection strict. `byHashAndText` answers both halves of the requirement at once, since a\n * hit means this session recorded exactly this content for this path.\n *\n * `storeKey` is the snapshot store's own key convention, the normalized absolute path, which\n * is NOT symlink-resolved unlike `canonicalKey`. Passing the wrong one makes a symlinked path\n * miss and report a false `no_prior_observation`.\n *\n * The tag is derived here rather than accepted. Unlike the engine's own use of\n * `byHashAndText`, where the hash is the independent claim a section presented, `write` has no\n * presented tag: it replaces the whole file. Any tag is therefore just `live` hashed, and\n * taking it as a parameter only creates a way for the two to disagree silently.\n */\nexport function assertPriorSessionObservation(args: {\n\treadonly canonicalKey: string;\n\treadonly storeKey: string;\n\treadonly path: string;\n\treadonly store: SnapshotStore;\n\treadonly live: string;\n\treadonly requester?: MutationRequester;\n}): void {\n\tif (args.store.byHashAndText(args.storeKey, computeFileHash(args.live), args.live)) return;\n\t// The last version this session recorded is what it believed it was overwriting, so the\n\t// divergence from live is the evidence. Without one there is nothing to diff, but the live\n\t// state still reports what was about to be clobbered sight unseen, which is the part\n\t// whoever reviews the rejection actually needs.\n\tconst head = args.store.head(args.storeKey);\n\tconst evidence = head ? computeConflictEvidence(head.text, args.live) : undefined;\n\tthrow new FileMutationConflict({\n\t\treason: head ? \"changed_since_observation\" : \"no_prior_observation\",\n\t\tpath: args.path,\n\t\tcanonicalKey: args.canonicalKey,\n\t\trequester: args.requester,\n\t\tliveState: computeLiveState(args.live),\n\t\t...(evidence ? { evidence } : {}),\n\t});\n}\n\n/**\n * Build a requester from parts already present on a session. Kept pure so it is testable\n * without constructing an `AgentSession`, and so this module never imports one.\n */\nexport function buildMutationRequester(parts: {\n\treadonly sessionId: string;\n\treadonly orchestration?: {\n\t\treadonly kind: string;\n\t\treadonly workflowRunId: string;\n\t\treadonly workflowStageId: string;\n\t\treadonly workflowStageName: string;\n\t};\n\treadonly intercom?: {\n\t\treadonly runId: string;\n\t\treadonly agent: string;\n\t\treadonly index?: number;\n\t\treadonly supervisor?: { readonly supervisorSessionId: string };\n\t};\n\treadonly attemptId?: string;\n\treadonly toolCallId?: string;\n}): MutationRequester {\n\tconst workflow = parts.orchestration?.kind === \"workflow-stage\" ? parts.orchestration : undefined;\n\tconst supervisorSessionId = parts.intercom?.supervisor?.supervisorSessionId;\n\tconst subagentIndex = parts.intercom?.index;\n\treturn {\n\t\tsessionId: parts.sessionId,\n\t\t...(supervisorSessionId ? { parentSessionId: supervisorSessionId } : {}),\n\t\t...(workflow ? { workflowRunId: workflow.workflowRunId } : {}),\n\t\t...(workflow ? { workflowStageId: workflow.workflowStageId } : {}),\n\t\t...(workflow ? { workflowStageName: workflow.workflowStageName } : {}),\n\t\t...(parts.intercom ? { subagentRunId: parts.intercom.runId } : {}),\n\t\t...(parts.intercom ? { subagentAgent: parts.intercom.agent } : {}),\n\t\t// Presence, not truthiness: index 0 is the first child, and `0 ? … : {}` drops it.\n\t\t...(subagentIndex !== undefined ? { subagentIndex } : {}),\n\t\t...(parts.attemptId ? { attemptId: parts.attemptId } : {}),\n\t\t...(parts.toolCallId ? { toolCallId: parts.toolCallId } : {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"file-mutation-coordinator.js","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAsB,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line-engine/index.ts\";\n\n/**\n * Stable token carried inside every conflict message.\n *\n * It lives in the message text, not only on the class, because nothing typed survives the\n * trip from a tool to a workflow: a subagent result reports `cause`/`error` as strings, a\n * workflow task result has no error field at all, and a workflow runner reduces a failure to\n * `err.message`. Matching this token is how a consumer downstream of that flattening tells a\n * mutation conflict apart from an ordinary tool error.\n *\n * It is placed at the start of the message so it survives truncation of the tail as the\n * message is relayed. Never change it without updating every consumer that matches on it.\n */\nexport const FILE_MUTATION_CONFLICT_CODE = \"FILE_MUTATION_CONFLICT\";\n\n/**\n * Reasons report a {@link FileMutationLiveState} wherever the live target can be described,\n * which is everywhere except `target_unreadable`: that one exists precisely because the target\n * could not be read, so claiming a size or a tag for it would be invention.\n *\n * Only the reasons that have something to compare against also report a\n * {@link FileMutationConflictEvidence} diff: `no_prior_observation` never read the file, and\n * `foreign_snapshot` presented a tag naming content this session has never seen, so in both\n * cases there is no prior side to diff.\n */\nexport type FileMutationConflictReason =\n\t/** Live content moved between the mutation being prepared and the write being attempted. */\n\t| \"changed_before_write\"\n\t/** Overwrite attempted with no prior read of this file in this session. */\n\t| \"no_prior_observation\"\n\t/** Overwrite attempted, but what this session observed is no longer the live content. */\n\t| \"changed_since_observation\"\n\t/** Exclusive create lost: the target already exists. */\n\t| \"target_exists\"\n\t/** The target no longer exists: removed between preparing the mutation and writing it. */\n\t| \"target_missing\"\n\t/**\n\t * The target still exists but can no longer be read: replaced by a directory, made\n\t * unreadable, locked, or rewritten as content this reader cannot parse. Distinct from a\n\t * content change because there is nothing to diff, and from a deletion because the path is\n\t * still occupied.\n\t */\n\t| \"target_unreadable\"\n\t/** The presented tag was never minted in this session's snapshot store. */\n\t| \"foreign_snapshot\";\n\n/**\n * Correlation only.\n *\n * Flora, 2026-08-13: identity \"must never grant permission or identify a current owner or\n * culprit\". So this describes the writer being *rejected*, never a winner, and nothing in\n * this module reads it to decide whether a mutation is admitted. A record of the last Atomic\n * writer could not prove ownership anyway, because shell commands, external programs, other\n * Atomic processes and symlink changes all bypass this coordinator.\n */\nexport interface MutationRequester {\n\treadonly sessionId: string;\n\t/** Session that spawned this one, from the child's `supervisor.supervisorSessionId`. */\n\treadonly parentSessionId?: string;\n\treadonly workflowRunId?: string;\n\treadonly workflowStageId?: string;\n\treadonly workflowStageName?: string;\n\treadonly subagentRunId?: string;\n\treadonly subagentAgent?: string;\n\t/**\n\t * Position within a fan-out. Needed to tell siblings apart: a child's intercom address is\n\t * `agent + runId + index` (`resolveSubagentIntercomTarget`), so a stage that spawns several\n\t * children of one agent onto one file yields identical identity without it.\n\t */\n\treadonly subagentIndex?: number;\n\t/** Opaque per-attempt UUID. Diagnostic only; never an authority. */\n\treadonly attemptId?: string;\n\t/** The specific tool call rejected. Narrower than the attempt, which makes many calls. */\n\treadonly toolCallId?: string;\n}\n\n/**\n * Resolved per execution rather than captured once.\n *\n * Mirrors `sessionTempDir` in the session tool registry, which is a thunk \"so bash spill\n * files follow the live transcript session across fork/branch/resume\". A requester captured\n * at tool-construction time would keep a stale session id through exactly those transitions,\n * which is the relaunch case this feature exists to make legible.\n *\n * Takes the tool call id rather than leaving callers to merge it in, because it has a\n * different lifetime from the rest: session identity belongs to the session, the call id is\n * an argument of the single `execute` being rejected.\n */\nexport type MutationRequesterResolver = (toolCallId: string) => MutationRequester | undefined;\n\n/**\n * What actually diverged, so a conflict can be acted on without a second round trip.\n *\n * A reason and a path are not evidence; they say a race happened, not what it did. Whatever acts\n * on the rejection, a workflow applying its own control behavior or a human reading the error,\n * needs the divergence itself before it can decide anything.\n *\n * The span is computed by trimming the common prefix and suffix rather than comparing line by\n * line positionally, so inserting one line at the top reports one changed region and not every\n * following line.\n */\nexport interface FileMutationConflictEvidence {\n\t/** 1-based line of the first divergence. */\n\treadonly line: number;\n\t/** Lines the rejected mutation assumed occupied the divergent span. */\n\treadonly assumedLines: number;\n\t/** Lines actually occupying it now. */\n\treadonly foundLines: number;\n\t/** First assumed line, clamped. Absent when the span is pure insertion. */\n\treadonly assumed?: string;\n\t/** First live line, clamped. Absent when the span is pure deletion. */\n\treadonly found?: string;\n}\n\n/**\n * Excerpts are clamped because a conflict travels as message text through channels that\n * truncate, and because file content copied into an error outlives the turn in ledger records.\n * One line per side is enough to tell the model whether its plan still holds.\n */\nconst EVIDENCE_LINE_CHARS = 120;\n\nfunction clampLine(line: string): string {\n\treturn line.length <= EVIDENCE_LINE_CHARS ? line : `${line.slice(0, EVIDENCE_LINE_CHARS)}...`;\n}\n\n/**\n * The target as it stood at the moment of refusal, independent of any comparison.\n *\n * Kept separate from {@link FileMutationConflictEvidence} because the two answer different\n * questions and only one of them can be unanswerable. A conflict may have nothing to diff\n * against, as when the session never read the file, but there is still always something worth\n * reporting about what the mutation was aimed at. Size in particular is the difference between\n * clobbering an empty placeholder and clobbering four hundred lines of production code.\n */\nexport interface FileMutationLiveState {\n\t/** Lines currently in the file. Zero when it is empty or does not exist. */\n\treadonly lines: number;\n\t/** Tag of the live content, so a rejected tag can be told apart from the real one. */\n\treadonly tag?: string;\n\t/** First line, clamped. Absent when the file is missing, empty, or starts with a blank line. */\n\treadonly firstLine?: string;\n}\n\n/** Describe live content, or a missing target when `live` is `undefined`. */\nexport function computeLiveState(live: string | undefined): FileMutationLiveState {\n\tif (live === undefined) return { lines: 0 };\n\t// Trailing newline terminates the last line rather than starting an empty one.\n\tconst lines = live === \"\" ? [] : live.replace(/\\n$/, \"\").split(\"\\n\");\n\tconst first = lines[0];\n\treturn {\n\t\tlines: lines.length,\n\t\ttag: computeFileHash(live),\n\t\t...(first ? { firstLine: clampLine(first) } : {}),\n\t};\n}\n\n/**\n * Compare what a mutation assumed against what is live, returning `undefined` when they agree.\n *\n * Both sides must already share a line-ending convention. `Snapshot.text` is normalized to LF,\n * so a caller passing raw live bytes on Windows would report every line as divergent.\n */\nexport function computeConflictEvidence(assumed: string, found: string): FileMutationConflictEvidence | undefined {\n\tif (assumed === found) return undefined;\n\tconst assumedLines = assumed.split(\"\\n\");\n\tconst foundLines = found.split(\"\\n\");\n\tlet start = 0;\n\twhile (start < assumedLines.length && start < foundLines.length && assumedLines[start] === foundLines[start]) {\n\t\tstart++;\n\t}\n\tlet endAssumed = assumedLines.length;\n\tlet endFound = foundLines.length;\n\twhile (endAssumed > start && endFound > start && assumedLines[endAssumed - 1] === foundLines[endFound - 1]) {\n\t\tendAssumed--;\n\t\tendFound--;\n\t}\n\treturn {\n\t\tline: start + 1,\n\t\tassumedLines: endAssumed - start,\n\t\tfoundLines: endFound - start,\n\t\t...(start < endAssumed ? { assumed: clampLine(assumedLines[start] ?? \"\") } : {}),\n\t\t...(start < endFound ? { found: clampLine(foundLines[start] ?? \"\") } : {}),\n\t};\n}\n\nexport interface FileMutationConflictDetails {\n\treadonly reason: FileMutationConflictReason;\n\t/** Display path, as the model referred to it. */\n\treadonly path: string;\n\t/** Symlink-resolved key, from `canonicalMutationKey`. */\n\treadonly canonicalKey: string;\n\treadonly requester?: MutationRequester;\n\t/** The tag the rejected mutation presented, when it had one. */\n\treadonly presentedTag?: string;\n\t/** Absent when the reason carries no comparison, as with `no_prior_observation`. */\n\treadonly evidence?: FileMutationConflictEvidence;\n\t/** What the mutation was aimed at. Absent only when it could not be read at all. */\n\treadonly liveState?: FileMutationLiveState;\n\t/**\n\t * Filesystem error code that classified the conflict, such as `EISDIR` or `EACCES`. For a\n\t * target that became unreadable this is the whole diagnosis, since nothing else about the\n\t * file can be reported once the read fails.\n\t */\n\treadonly causeCode?: string;\n}\n\ninterface ReasonCopy {\n\t/** Why the mutation was refused, as a full sentence. */\n\treadonly diagnosis: string;\n\t/** What to do about it, addressed to the model and naming the path it acts on. */\n\treadonly instruction: (path: string) => string;\n}\n\nconst SHELL_OUTPUT_IS_NOT_A_READ =\n\t\"Shell output (cat, sed, head) and tags quoted in error messages do not count as reads.\";\n\n/**\n * Paired so the instruction cannot contradict the diagnosis it follows.\n *\n * A single shared instruction cannot be true of all seven reasons. \"Read the file again\" is\n * false for the ones that fail precisely because the file was never read, and impossible for\n * `target_missing`, where there is nothing left to read.\n */\nconst REASON_COPY: Record<FileMutationConflictReason, ReasonCopy> = {\n\tchanged_before_write: {\n\t\tdiagnosis: \"The file changed after this edit was prepared.\",\n\t\tinstruction: (path) =>\n\t\t\t`Read ${path} again and rebuild the edit from its current content and tag. Do not resend the same edit.`,\n\t},\n\tno_prior_observation: {\n\t\tdiagnosis: `This session has not read the file it is overwriting. ${SHELL_OUTPUT_IS_NOT_A_READ}`,\n\t\tinstruction: (path) =>\n\t\t\t`Read ${path} with the read tool, then decide whether this overwrite is still the change you want.`,\n\t},\n\tchanged_since_observation: {\n\t\tdiagnosis: \"The file changed since this session last read it.\",\n\t\tinstruction: (path) => `Read ${path} again and reconcile this change with its current content.`,\n\t},\n\ttarget_exists: {\n\t\tdiagnosis: \"The file already exists.\",\n\t\tinstruction: (path) => `Read ${path} and edit it in place, or write to a different path.`,\n\t},\n\ttarget_missing: {\n\t\tdiagnosis: \"The file no longer exists.\",\n\t\tinstruction: () =>\n\t\t\t\"Do not read it. Confirm the removal was intended, then recreate the file or drop this change.\",\n\t},\n\ttarget_unreadable: {\n\t\tdiagnosis: \"The file still exists but can no longer be read.\",\n\t\tinstruction: (path) =>\n\t\t\t`Something replaced or locked ${path} rather than editing it. Inspect what is there before retrying; an identical edit will fail the same way.`,\n\t},\n\tforeign_snapshot: {\n\t\tdiagnosis: `The presented tag was not issued to this session. Only read, search, write, and edit results issue tags. ${SHELL_OUTPUT_IS_NOT_A_READ}`,\n\t\tinstruction: (path) =>\n\t\t\t`Read ${path} with the read tool (a line range such as ${path}:10-40 is enough), then retry with the tag and line numbers from that result. Nothing was written.`,\n\t},\n};\n\nfunction describeRequester(requester: MutationRequester): string {\n\tconst parts = [`session=${requester.sessionId}`];\n\tif (requester.parentSessionId) parts.push(`parent=${requester.parentSessionId}`);\n\tif (requester.workflowRunId) parts.push(`run=${requester.workflowRunId}`);\n\tif (requester.workflowStageId) parts.push(`stage=${requester.workflowStageId}`);\n\t// Quoted: a stage name is free text and the field separator here is a space.\n\tif (requester.workflowStageName) parts.push(`stageName=\"${requester.workflowStageName}\"`);\n\tif (requester.subagentRunId) parts.push(`child=${requester.subagentRunId}`);\n\tif (requester.subagentAgent) parts.push(`agent=${requester.subagentAgent}`);\n\t// Presence, not truthiness: the first child of a fan-out is index 0.\n\tif (requester.subagentIndex !== undefined) parts.push(`index=${requester.subagentIndex}`);\n\tif (requester.attemptId) parts.push(`attempt=${requester.attemptId}`);\n\tif (requester.toolCallId) parts.push(`call=${requester.toolCallId}`);\n\treturn parts.join(\" \");\n}\n\n/**\n * Quote an excerpt of file content so it stays on its own line of the message.\n *\n * `JSON.stringify` rather than wrapping in backticks or quotes of our own: source lines\n * routinely contain both, and a template literal in a TypeScript file would otherwise close\n * the delimiter early and leave the excerpt unreadable. It also escapes control characters,\n * so a stray CR from a file this module was handed unnormalized shows up as `\\r` rather than\n * silently rearranging the message.\n */\nfunction quoteExcerpt(text: string): string {\n\treturn JSON.stringify(text);\n}\n\nfunction describeEvidence(evidence: FileMutationConflictEvidence): string {\n\tconst span =\n\t\tevidence.assumedLines === 1 && evidence.foundLines === 1\n\t\t\t? \"\"\n\t\t\t: ` (${evidence.assumedLines} lines replaced by ${evidence.foundLines})`;\n\tconst at = `line ${evidence.line}`;\n\tif (evidence.assumed !== undefined && evidence.found !== undefined) {\n\t\treturn `${at}: assumed ${quoteExcerpt(evidence.assumed)}, found ${quoteExcerpt(evidence.found)}${span}.`;\n\t}\n\tif (evidence.found !== undefined) {\n\t\treturn `${at}: found ${quoteExcerpt(evidence.found)} where this mutation expected nothing${span}.`;\n\t}\n\treturn `${at}: assumed ${quoteExcerpt(evidence.assumed ?? \"\")}, which is no longer present${span}.`;\n}\n\n/**\n * The live tag is labeled as unusable because it is not minted by the refusal: an agent that\n * copies it into a retry is rejected again with the same conflict.\n */\nfunction describeLiveState(state: FileMutationLiveState): string {\n\tif (!state.tag) return \"does not exist.\";\n\tconst first = state.firstLine ? `, first line ${quoteExcerpt(state.firstLine)}` : \"\";\n\treturn `${state.lines} lines${first}. Current tag #${state.tag} is for comparison only; edits need a tag from your own read.`;\n}\n\n/**\n * Raised instead of a bare `Error` so a conflict is countable rather than merely readable.\n * The message is the wire format; see {@link FILE_MUTATION_CONFLICT_CODE}.\n */\nexport class FileMutationConflict extends Error {\n\treadonly reason: FileMutationConflictReason;\n\treadonly path: string;\n\treadonly canonicalKey: string;\n\treadonly requester: MutationRequester | undefined;\n\treadonly presentedTag: string | undefined;\n\t/** Structured alongside the message so a ledger can record it without re-parsing text. */\n\treadonly evidence: FileMutationConflictEvidence | undefined;\n\treadonly liveState: FileMutationLiveState | undefined;\n\treadonly causeCode: string | undefined;\n\n\tconstructor(details: FileMutationConflictDetails) {\n\t\tsuper(FileMutationConflict.formatMessage(details));\n\t\t// Sub-classing Error does not set this, and consumers match on it.\n\t\tthis.name = \"FileMutationConflict\";\n\t\tthis.reason = details.reason;\n\t\tthis.path = details.path;\n\t\tthis.canonicalKey = details.canonicalKey;\n\t\tthis.requester = details.requester;\n\t\tthis.presentedTag = details.presentedTag;\n\t\tthis.evidence = details.evidence;\n\t\tthis.liveState = details.liveState;\n\t\tthis.causeCode = details.causeCode;\n\t}\n\n\t/**\n\t * One labeled line per concern, ordered by what must survive truncation: the code, reason,\n\t * and path first, then why and what to do, then the divergence and live state, and the\n\t * requester identity last. Identity is correlation for logs, never guidance, so it is the\n\t * most expendable part of the message for the model reading it.\n\t */\n\tstatic formatMessage(details: FileMutationConflictDetails): string {\n\t\tconst copy = REASON_COPY[details.reason];\n\t\tconst presented = details.presentedTag ? ` (presented #${details.presentedTag})` : \"\";\n\t\tconst cause = details.causeCode ? ` Filesystem error: ${details.causeCode}.` : \"\";\n\t\tconst lines = [\n\t\t\t`${FILE_MUTATION_CONFLICT_CODE}:${details.reason} ${details.path}${presented}`,\n\t\t\t`Why: ${copy.diagnosis}${cause}`,\n\t\t\t`Next: ${copy.instruction(details.path)}`,\n\t\t];\n\t\tif (details.evidence) lines.push(`First divergence: ${describeEvidence(details.evidence)}`);\n\t\tif (details.liveState) lines.push(`Live file: ${describeLiveState(details.liveState)}`);\n\t\tif (details.requester) lines.push(`Requester: ${describeRequester(details.requester)}`);\n\t\treturn lines.join(\"\\n\");\n\t}\n}\n\n/** Whether a thrown value is an exclusive-create collision reported by the filesystem. */\nexport function isExclusiveCreateCollision(error: unknown): boolean {\n\treturn typeof error === \"object\" && error !== null && \"code\" in error && error.code === \"EEXIST\";\n}\n\n/**\n * Whether a thrown value says the target is gone. `ENOTDIR` counts because a parent directory\n * replaced by a file makes the path unreachable for the same reason a deletion does.\n */\nexport function isMissingTargetError(error: unknown): boolean {\n\tconst code = filesystemErrorCode(error);\n\treturn code === \"ENOENT\" || code === \"ENOTDIR\";\n}\n\n/** The `code` a filesystem rejection carries, when it carries one. */\nexport function filesystemErrorCode(error: unknown): string | undefined {\n\tif (typeof error !== \"object\" || error === null || !(\"code\" in error)) return undefined;\n\tconst code = (error as { code?: unknown }).code;\n\treturn typeof code === \"string\" ? code : undefined;\n}\n\n/**\n * Guard for the window between preparing a mutation and committing it, called under the\n * mutation queue.\n *\n * `prepared` is the content the mutation was computed against, which for a hashline edit is\n * the file as `prepare` read it, NOT what the session originally observed, since `prepare`\n * re-reads and may have recovered onto drifted content. Naming that honestly matters: this\n * closes a time-of-check window, it does not prove the session read the file.\n *\n * Full text rather than tags: a hashline tag is 16 bits and the engine documents that it can\n * collide, so it is a label for the model to recognize, never proof of identity.\n */\nexport function assertLiveMatchesPrepared(args: {\n\treadonly canonicalKey: string;\n\treadonly path: string;\n\treadonly prepared: string;\n\treadonly live: string;\n\treadonly requester?: MutationRequester;\n\treadonly presentedTag?: string;\n}): void {\n\tif (args.live === args.prepared) return;\n\tconst evidence = computeConflictEvidence(args.prepared, args.live);\n\tthrow new FileMutationConflict({\n\t\treason: \"changed_before_write\",\n\t\tpath: args.path,\n\t\tcanonicalKey: args.canonicalKey,\n\t\trequester: args.requester,\n\t\tpresentedTag: args.presentedTag,\n\t\tliveState: computeLiveState(args.live),\n\t\t...(evidence ? { evidence } : {}),\n\t});\n}\n\n/**\n * Guard for `write` overwriting an existing file: this session must already have observed the\n * exact content it is about to replace.\n *\n * Asks the session's own store and never another session's, which is what keeps cross-session\n * rejection strict. `byHashAndText` answers both halves of the requirement at once, since a\n * hit means this session recorded exactly this content for this path.\n *\n * `storeKey` is the snapshot store's own key convention, the normalized absolute path, which\n * is NOT symlink-resolved unlike `canonicalKey`. Passing the wrong one makes a symlinked path\n * miss and report a false `no_prior_observation`.\n *\n * The tag is derived here rather than accepted. Unlike the engine's own use of\n * `byHashAndText`, where the hash is the independent claim a section presented, `write` has no\n * presented tag: it replaces the whole file. Any tag is therefore just `live` hashed, and\n * taking it as a parameter only creates a way for the two to disagree silently.\n */\nexport function assertPriorSessionObservation(args: {\n\treadonly canonicalKey: string;\n\treadonly storeKey: string;\n\treadonly path: string;\n\treadonly store: SnapshotStore;\n\treadonly live: string;\n\treadonly requester?: MutationRequester;\n}): void {\n\tif (args.store.byHashAndText(args.storeKey, computeFileHash(args.live), args.live)) return;\n\t// The last version this session recorded is what it believed it was overwriting, so the\n\t// divergence from live is the evidence. Without one there is nothing to diff, but the live\n\t// state still reports what was about to be clobbered sight unseen, which is the part\n\t// whoever reviews the rejection actually needs.\n\tconst head = args.store.head(args.storeKey);\n\tconst evidence = head ? computeConflictEvidence(head.text, args.live) : undefined;\n\tthrow new FileMutationConflict({\n\t\treason: head ? \"changed_since_observation\" : \"no_prior_observation\",\n\t\tpath: args.path,\n\t\tcanonicalKey: args.canonicalKey,\n\t\trequester: args.requester,\n\t\tliveState: computeLiveState(args.live),\n\t\t...(evidence ? { evidence } : {}),\n\t});\n}\n\n/**\n * Build a requester from parts already present on a session. Kept pure so it is testable\n * without constructing an `AgentSession`, and so this module never imports one.\n */\nexport function buildMutationRequester(parts: {\n\treadonly sessionId: string;\n\treadonly orchestration?: {\n\t\treadonly kind: string;\n\t\treadonly workflowRunId: string;\n\t\treadonly workflowStageId: string;\n\t\treadonly workflowStageName: string;\n\t};\n\treadonly intercom?: {\n\t\treadonly runId: string;\n\t\treadonly agent: string;\n\t\treadonly index?: number;\n\t\treadonly supervisor?: { readonly supervisorSessionId: string };\n\t};\n\treadonly attemptId?: string;\n\treadonly toolCallId?: string;\n}): MutationRequester {\n\tconst workflow = parts.orchestration?.kind === \"workflow-stage\" ? parts.orchestration : undefined;\n\tconst supervisorSessionId = parts.intercom?.supervisor?.supervisorSessionId;\n\tconst subagentIndex = parts.intercom?.index;\n\treturn {\n\t\tsessionId: parts.sessionId,\n\t\t...(supervisorSessionId ? { parentSessionId: supervisorSessionId } : {}),\n\t\t...(workflow ? { workflowRunId: workflow.workflowRunId } : {}),\n\t\t...(workflow ? { workflowStageId: workflow.workflowStageId } : {}),\n\t\t...(workflow ? { workflowStageName: workflow.workflowStageName } : {}),\n\t\t...(parts.intercom ? { subagentRunId: parts.intercom.runId } : {}),\n\t\t...(parts.intercom ? { subagentAgent: parts.intercom.agent } : {}),\n\t\t// Presence, not truthiness: index 0 is the first child, and `0 ? … : {}` drops it.\n\t\t...(subagentIndex !== undefined ? { subagentIndex } : {}),\n\t\t...(parts.attemptId ? { attemptId: parts.attemptId } : {}),\n\t\t...(parts.toolCallId ? { toolCallId: parts.toolCallId } : {}),\n\t};\n}\n"]}
|
|
@@ -51,6 +51,22 @@ export declare function createPowerShellToolDefinition(cwd: string, options?: Po
|
|
|
51
51
|
budgetMs?: number;
|
|
52
52
|
} & Partial<Record<"command" | "cwd" | "env" | "pty" | "timeout" | "wait", never>>)) | undefined;
|
|
53
53
|
executionMode?: import("@earendil-works/pi-agent-core").ToolExecutionMode;
|
|
54
|
+
concurrency?: import("./tool-concurrency.ts").ToolConcurrency<({
|
|
55
|
+
command: string;
|
|
56
|
+
env?: Record<string, string> | undefined;
|
|
57
|
+
timeout?: number | undefined;
|
|
58
|
+
wait?: import("../tasks/contracts.ts").WaitPolicy | undefined;
|
|
59
|
+
cwd?: string | undefined;
|
|
60
|
+
pty?: boolean | undefined;
|
|
61
|
+
} & {
|
|
62
|
+
action?: never;
|
|
63
|
+
id?: never;
|
|
64
|
+
budgetMs?: never;
|
|
65
|
+
}) | ({
|
|
66
|
+
action: "wait";
|
|
67
|
+
id: string;
|
|
68
|
+
budgetMs?: number;
|
|
69
|
+
} & Partial<Record<"command" | "cwd" | "env" | "pty" | "timeout" | "wait", never>>)> | undefined;
|
|
54
70
|
renderCall?: ((args: ({
|
|
55
71
|
command: string;
|
|
56
72
|
env?: Record<string, string> | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"powershell.d.ts","sourceRoot":"","sources":["../../../src/core/tools/powershell.ts"],"names":[],"mappings":"AASA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EAKpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAGN,KAAK,sBAAsB,EAE3B,MAAM,sBAAsB,CAAC;AAS9B,eAAO,MAAM,sCAAsC;sBACzC,8BAA8B;;EAE7B,CAAC;AACZ,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAClD,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;AACpD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAChD,MAAM,WAAW,qBAChB,SAAQ,IAAI,CAAC,eAAe,EAAE,0BAA0B,GAAG,WAAW,GAAG,WAAW,CAAC;IACrF,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AACD,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE;IACzD,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACnC,GAAG,oBAAoB,CA0DvB;AACD,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B
|
|
1
|
+
{"version":3,"file":"powershell.d.ts","sourceRoot":"","sources":["../../../src/core/tools/powershell.ts"],"names":[],"mappings":"AASA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,eAAe,EAKpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAGN,KAAK,sBAAsB,EAE3B,MAAM,sBAAsB,CAAC;AAS9B,eAAO,MAAM,sCAAsC;sBACzC,8BAA8B;;EAE7B,CAAC;AACZ,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAClD,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;AACpD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAChD,MAAM,WAAW,qBAChB,SAAQ,IAAI,CAAC,eAAe,EAAE,0BAA0B,GAAG,WAAW,GAAG,WAAW,CAAC;IACrF,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AACD,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE;IACzD,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACnC,GAAG,oBAAoB,CA0DvB;AACD,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgC9F;AACD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;mHAEhF;AACD,MAAM,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;AACtD,MAAM,MAAM,mBAAmB,GAAG,aAAa,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Static, type TSchema, Type } from "typebox";
|
|
2
2
|
import { type ToolDefinition } from "../extensions/types.ts";
|
|
3
3
|
export declare const STRUCTURED_OUTPUT_TOOL_NAME = "structured_output";
|
|
4
4
|
export type JsonPrimitive = string | number | boolean | null;
|
|
@@ -14,15 +14,18 @@ export interface StructuredOutputFileCapture {
|
|
|
14
14
|
outputPath: string;
|
|
15
15
|
}
|
|
16
16
|
export interface StructuredOutputToolOptions<TSchemaDef extends TSchema> {
|
|
17
|
-
/** Tool parameter schema. */
|
|
18
17
|
schema: TSchemaDef;
|
|
19
|
-
/** In-process result sink for SDK and workflow callers. */
|
|
20
18
|
capture?: StructuredOutputCapture<Static<TSchemaDef>>;
|
|
21
|
-
/** Cross-process result sink for subagent child runtimes. */
|
|
22
19
|
output?: StructuredOutputFileCapture;
|
|
23
|
-
/** Tool name. Defaults to `structured_output`. */
|
|
24
20
|
name?: string;
|
|
25
21
|
}
|
|
22
|
+
export declare const StructuredOutputParameters: Type.TObject<{
|
|
23
|
+
instructions: Type.TString;
|
|
24
|
+
state: Type.TObject<{}>;
|
|
25
|
+
model: Type.TOptional<Type.TString>;
|
|
26
|
+
fallbackModels: Type.TOptional<Type.TArray<Type.TString>>;
|
|
27
|
+
}>;
|
|
28
|
+
export type StructuredOutputParams = Static<typeof StructuredOutputParameters>;
|
|
26
29
|
export declare function createStructuredOutputCapture<TValue = unknown>(): StructuredOutputCapture<TValue>;
|
|
27
|
-
export declare function createStructuredOutputTool<TSchemaDef extends TSchema>(options: StructuredOutputToolOptions<TSchemaDef>): ToolDefinition<
|
|
30
|
+
export declare function createStructuredOutputTool<TSchemaDef extends TSchema>(options: StructuredOutputToolOptions<TSchemaDef>): ToolDefinition<typeof StructuredOutputParameters, Static<TSchemaDef>>;
|
|
28
31
|
//# sourceMappingURL=structured-output.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../../../src/core/tools/structured-output.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"structured-output.d.ts","sourceRoot":"","sources":["../../../src/core/tools/structured-output.ts"],"names":[],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CA8CvE"}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
+
import { Type } from "typebox";
|
|
3
4
|
import { defineTool } from "../extensions/types.js";
|
|
4
5
|
export const STRUCTURED_OUTPUT_TOOL_NAME = "structured_output";
|
|
6
|
+
export const StructuredOutputParameters = Type.Object({
|
|
7
|
+
instructions: Type.String({ minLength: 1, description: "Complete judgment instructions for the result." }),
|
|
8
|
+
state: Type.Object({}, {
|
|
9
|
+
additionalProperties: true,
|
|
10
|
+
minProperties: 1,
|
|
11
|
+
description: "Named finite JSON values holding the task, relevant context, constraints and reference text. Never include secrets.",
|
|
12
|
+
}),
|
|
13
|
+
model: Type.Optional(Type.String({
|
|
14
|
+
description: "Exact provider/model ID of a chat or classifier model, such as typesafe/jev-latest. Omit to use the current chat model.",
|
|
15
|
+
})),
|
|
16
|
+
fallbackModels: Type.Optional(Type.Array(Type.String(), {
|
|
17
|
+
description: "Ordered exact fallback model IDs. The current chat model is always tried last.",
|
|
18
|
+
})),
|
|
19
|
+
}, { additionalProperties: false });
|
|
5
20
|
function stringifyParams(params) {
|
|
6
21
|
try {
|
|
7
22
|
return JSON.stringify(params, null, 2);
|
|
@@ -32,27 +47,40 @@ export function createStructuredOutputTool(options) {
|
|
|
32
47
|
return defineTool({
|
|
33
48
|
name,
|
|
34
49
|
label: "Structured Output",
|
|
35
|
-
description: "
|
|
50
|
+
description: "Infer the final machine-readable result from instructions and named state using the selected model, then any fallbacks, then the current chat model.",
|
|
36
51
|
promptSnippet: "Return final machine-readable output",
|
|
37
52
|
promptGuidelines: [
|
|
38
53
|
`${name} is the final machine-readable result channel; call ${name} exactly once when done.`,
|
|
54
|
+
"Pass complete instructions and named state; omit model to use the current chat model.",
|
|
39
55
|
`Do not write a prose final answer after calling ${name}.`,
|
|
40
56
|
],
|
|
41
|
-
parameters:
|
|
57
|
+
parameters: StructuredOutputParameters,
|
|
42
58
|
maxResultSizeChars: Infinity,
|
|
43
59
|
structuredOutput: true,
|
|
44
|
-
async execute(_toolCallId, params) {
|
|
45
|
-
const
|
|
60
|
+
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
61
|
+
const { generateStructuredOutput } = await import("../structured-output/index.js");
|
|
62
|
+
const result = await generateStructuredOutput({
|
|
63
|
+
schema: options.schema,
|
|
64
|
+
instructions: params.instructions,
|
|
65
|
+
state: params.state,
|
|
66
|
+
...(params.model !== undefined ? { model: params.model } : {}),
|
|
67
|
+
...(params.fallbackModels !== undefined ? { fallbackModels: params.fallbackModels } : {}),
|
|
68
|
+
currentModel: ctx.model,
|
|
69
|
+
modelRegistry: ctx.modelRegistry,
|
|
70
|
+
...(signal ? { signal } : {}),
|
|
71
|
+
});
|
|
72
|
+
const value = result.value;
|
|
73
|
+
const serializedValue = stringifyParams(value);
|
|
46
74
|
if (options.output) {
|
|
47
|
-
await writeCapturedOutput(options.output,
|
|
75
|
+
await writeCapturedOutput(options.output, serializedValue);
|
|
48
76
|
}
|
|
49
77
|
if (options.capture) {
|
|
50
|
-
options.capture.value =
|
|
78
|
+
options.capture.value = value;
|
|
51
79
|
options.capture.called = true;
|
|
52
80
|
}
|
|
53
81
|
return {
|
|
54
|
-
content: [{ type: "text", text:
|
|
55
|
-
details:
|
|
82
|
+
content: [{ type: "text", text: serializedValue }],
|
|
83
|
+
details: value,
|
|
56
84
|
terminate: true,
|
|
57
85
|
};
|
|
58
86
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../../../src/core/tools/structured-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"structured-output.js","sourceRoot":"","sources":["../../../src/core/tools/structured-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;A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D,OAAO,EAAE,KAAK;gBACd,SAAS,EAAE,IAAI;aACf,CAAC;QACH,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport { type Static, type TSchema, Type } from \"typebox\";\nimport { defineTool, type ToolDefinition } from \"../extensions/types.ts\";\n\nexport const STRUCTURED_OUTPUT_TOOL_NAME = \"structured_output\";\n\nexport type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonObject | JsonValue[];\nexport type JsonObject = { readonly [key: string]: JsonValue };\n\nexport interface StructuredOutputCapture<TValue = unknown> {\n\tvalue: TValue | undefined;\n\tcalled: boolean;\n}\n\nexport interface StructuredOutputFileCapture {\n\toutputPath: string;\n}\n\nexport interface StructuredOutputToolOptions<TSchemaDef extends TSchema> {\n\tschema: TSchemaDef;\n\tcapture?: StructuredOutputCapture<Static<TSchemaDef>>;\n\toutput?: StructuredOutputFileCapture;\n\tname?: string;\n}\n\nexport const StructuredOutputParameters = Type.Object(\n\t{\n\t\tinstructions: Type.String({ minLength: 1, description: \"Complete judgment instructions for the result.\" }),\n\t\tstate: Type.Object(\n\t\t\t{},\n\t\t\t{\n\t\t\t\tadditionalProperties: true,\n\t\t\t\tminProperties: 1,\n\t\t\t\tdescription:\n\t\t\t\t\t\"Named finite JSON values holding the task, relevant context, constraints and reference text. Never include secrets.\",\n\t\t\t},\n\t\t),\n\t\tmodel: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription:\n\t\t\t\t\t\"Exact provider/model ID of a chat or classifier model, such as typesafe/jev-latest. Omit to use the current chat model.\",\n\t\t\t}),\n\t\t),\n\t\tfallbackModels: Type.Optional(\n\t\t\tType.Array(Type.String(), {\n\t\t\t\tdescription: \"Ordered exact fallback model IDs. The current chat model is always tried last.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\nexport type StructuredOutputParams = Static<typeof StructuredOutputParameters>;\n\nfunction stringifyParams<TSchemaDef extends TSchema>(params: Static<TSchemaDef>): string {\n\ttry {\n\t\treturn JSON.stringify(params, null, 2);\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Structured output must be JSON-serializable: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n}\n\nasync function writePrivateJsonFile(filePath: string, serializedJson: string): Promise<void> {\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, serializedJson, { mode: 0o600 });\n\t// Re-apply the private mode after writing so pre-existing looser files are tightened too.\n\tawait fs.chmod(filePath, 0o600);\n}\n\nasync function writeCapturedOutput(output: StructuredOutputFileCapture, serializedParams: string): Promise<void> {\n\ttry {\n\t\tawait writePrivateJsonFile(output.outputPath, serializedParams);\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to write structured output capture: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n}\n\nexport function createStructuredOutputCapture<TValue = unknown>(): StructuredOutputCapture<TValue> {\n\treturn { value: undefined, called: false };\n}\n\nexport function createStructuredOutputTool<TSchemaDef extends TSchema>(\n\toptions: StructuredOutputToolOptions<TSchemaDef>,\n): ToolDefinition<typeof StructuredOutputParameters, Static<TSchemaDef>> {\n\tconst name = options.name ?? STRUCTURED_OUTPUT_TOOL_NAME;\n\n\treturn defineTool({\n\t\tname,\n\t\tlabel: \"Structured Output\",\n\t\tdescription:\n\t\t\t\"Infer the final machine-readable result from instructions and named state using the selected model, then any fallbacks, then the current chat model.\",\n\t\tpromptSnippet: \"Return final machine-readable output\",\n\t\tpromptGuidelines: [\n\t\t\t`${name} is the final machine-readable result channel; call ${name} exactly once when done.`,\n\t\t\t\"Pass complete instructions and named state; omit model to use the current chat model.\",\n\t\t\t`Do not write a prose final answer after calling ${name}.`,\n\t\t],\n\t\tparameters: StructuredOutputParameters,\n\t\tmaxResultSizeChars: Infinity,\n\t\tstructuredOutput: true,\n\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx): Promise<AgentToolResult<Static<TSchemaDef>>> {\n\t\t\tconst { generateStructuredOutput } = await import(\"../structured-output/index.js\");\n\t\t\tconst result = await generateStructuredOutput({\n\t\t\t\tschema: options.schema,\n\t\t\t\tinstructions: params.instructions,\n\t\t\t\tstate: params.state as JsonObject,\n\t\t\t\t...(params.model !== undefined ? { model: params.model } : {}),\n\t\t\t\t...(params.fallbackModels !== undefined ? { fallbackModels: params.fallbackModels } : {}),\n\t\t\t\tcurrentModel: ctx.model,\n\t\t\t\tmodelRegistry: ctx.modelRegistry,\n\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t});\n\t\t\tconst value = result.value;\n\t\t\tconst serializedValue = stringifyParams(value);\n\t\t\tif (options.output) {\n\t\t\t\tawait writeCapturedOutput(options.output, serializedValue);\n\t\t\t}\n\t\t\tif (options.capture) {\n\t\t\t\toptions.capture.value = value;\n\t\t\t\toptions.capture.called = true;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: serializedValue }],\n\t\t\t\tdetails: value,\n\t\t\t\tterminate: true,\n\t\t\t};\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todos.d.ts","sourceRoot":"","sources":["../../../src/core/tools/todos.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI7D,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,eAAO,MAAM,gCAAgC;;EAIlC,CAAC;AAEZ,wBAAgB,wBAAwB,CACvC,GAAG,GAAE,MAAsB,GACzB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"todos.d.ts","sourceRoot":"","sources":["../../../src/core/tools/todos.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAI7D,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,eAAO,MAAM,gCAAgC;;EAIlC,CAAC;AAEZ,wBAAgB,wBAAwB,CACvC,GAAG,GAAE,MAAsB,GACzB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,CAAC,CAmBpD"}
|
package/dist/core/tools/todos.js
CHANGED
|
@@ -23,6 +23,7 @@ export function createTodoToolDefinition(cwd = process.cwd()) {
|
|
|
23
23
|
const todosDirLabel = getTodosDirLabel(cwd);
|
|
24
24
|
return {
|
|
25
25
|
name: "todo",
|
|
26
|
+
concurrency: "exclusive",
|
|
26
27
|
label: "Todo",
|
|
27
28
|
description: `Manage file-based todos in ${todosDirLabel} (list, list-all, get, create, update, append, delete, claim, release). ` +
|
|
28
29
|
"Title is the short summary; body is long-form markdown notes (update replaces, append adds). " +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todos.js","sourceRoot":"","sources":["../../../src/core/tools/todos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAwB,MAAM,kBAAkB,CAAC;AAEpE,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7D,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC;QACzB,0TAA0T;KACjT,CAAC;CACF,CAAC,CAAC;AAEZ,MAAM,UAAU,wBAAwB,CACvC,GAAG,GAAW,OAAO,CAAC,GAAG,EAAE;IAE3B,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAE5C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,MAAM;QACb,WAAW,EACV,8BAA8B,aAAa,0EAA0E;YACrH,+FAA+F;YAC/F,6FAA6F;YAC7F,sFAAsF;QACvF,GAAG,gCAAgC,EAAE;QACrC,UAAU,EAAE,UAAU;QACtB,gBAAgB,EAAE,CAAC,GAAG,gCAAgC,CAAC,UAAU,CAAC;QAClE,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAM,EAAE,GAAG,CAAC;QAC7F,UAAU,EAAE,cAAc;QAC1B,YAAY,EAAE,gBAAgB;KAC9B,CAAC;AACH,CAAC","sourcesContent":["/**\n * This tool stores todo items as files under <todo-dir> (defaults to\n * <CONFIG_DIR_NAME>/todos, or the path in <APP_NAME>_TODO_PATH). Each todo is\n * a standalone markdown file named <id>.md and an optional <id>.lock file is\n * used while a session is editing it.\n *\n * File format in <CONFIG_DIR_NAME>/todos:\n * - The file starts with a JSON object (not YAML) containing the front matter:\n * { id, title, tags, status, created_at, assigned_to_session }\n * - After the JSON block comes optional markdown body text separated by a blank line.\n */\nimport { experimentalToolSamplingProperty } from \"../experimental.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { executeTodoToolAction } from \"./todos-execute.ts\";\nimport { getTodosDirLabel } from \"./todos-paths.ts\";\nimport { renderTodoCall, renderTodoResult } from \"./todos-render.ts\";\nimport { TodoParams, type TodoToolDetails } from \"./todos-types.ts\";\n\nexport const todoToolSystemPromptContribution = Object.freeze({\n\tguidelines: Object.freeze([\n\t\t\"**To-do management**: If the user has a complex task that can be broken down into actionable steps, use the `todo` tool to create a task list before proceeding. This ensures clarity and alignment with the user's goals and that you have a way to track your work and ensure you are meeting the user's expectations.\",\n\t] as const),\n} as const);\n\nexport function createTodoToolDefinition(\n\tcwd: string = process.cwd(),\n): ToolDefinition<typeof TodoParams, TodoToolDetails> {\n\tconst todosDirLabel = getTodosDirLabel(cwd);\n\n\treturn {\n\t\tname: \"todo\",\n\t\tlabel: \"Todo\",\n\t\tdescription:\n\t\t\t`Manage file-based todos in ${todosDirLabel} (list, list-all, get, create, update, append, delete, claim, release). ` +\n\t\t\t\"Title is the short summary; body is long-form markdown notes (update replaces, append adds). \" +\n\t\t\t\"Todo ids are shown as TODO-<hex>; id parameters accept TODO-<hex> or the raw hex filename. \" +\n\t\t\t\"Claim tasks before working on them to avoid conflicts, and close them when complete.\",\n\t\t...experimentalToolSamplingProperty(),\n\t\tparameters: TodoParams,\n\t\tpromptGuidelines: [...todoToolSystemPromptContribution.guidelines],\n\t\texecute: (_toolCallId, params, _signal, _onUpdate, ctx) => executeTodoToolAction(params, ctx),\n\t\trenderCall: renderTodoCall,\n\t\trenderResult: renderTodoResult,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"todos.js","sourceRoot":"","sources":["../../../src/core/tools/todos.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAwB,MAAM,kBAAkB,CAAC;AAEpE,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7D,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC;QACzB,0TAA0T;KACjT,CAAC;CACF,CAAC,CAAC;AAEZ,MAAM,UAAU,wBAAwB,CACvC,GAAG,GAAW,OAAO,CAAC,GAAG,EAAE;IAE3B,MAAM,aAAa,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAE5C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,WAAW;QACxB,KAAK,EAAE,MAAM;QACb,WAAW,EACV,8BAA8B,aAAa,0EAA0E;YACrH,+FAA+F;YAC/F,6FAA6F;YAC7F,sFAAsF;QACvF,GAAG,gCAAgC,EAAE;QACrC,UAAU,EAAE,UAAU;QACtB,gBAAgB,EAAE,CAAC,GAAG,gCAAgC,CAAC,UAAU,CAAC;QAClE,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAM,EAAE,GAAG,CAAC;QAC7F,UAAU,EAAE,cAAc;QAC1B,YAAY,EAAE,gBAAgB;KAC9B,CAAC;AACH,CAAC","sourcesContent":["/**\n * This tool stores todo items as files under <todo-dir> (defaults to\n * <CONFIG_DIR_NAME>/todos, or the path in <APP_NAME>_TODO_PATH). Each todo is\n * a standalone markdown file named <id>.md and an optional <id>.lock file is\n * used while a session is editing it.\n *\n * File format in <CONFIG_DIR_NAME>/todos:\n * - The file starts with a JSON object (not YAML) containing the front matter:\n * { id, title, tags, status, created_at, assigned_to_session }\n * - After the JSON block comes optional markdown body text separated by a blank line.\n */\nimport { experimentalToolSamplingProperty } from \"../experimental.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { executeTodoToolAction } from \"./todos-execute.ts\";\nimport { getTodosDirLabel } from \"./todos-paths.ts\";\nimport { renderTodoCall, renderTodoResult } from \"./todos-render.ts\";\nimport { TodoParams, type TodoToolDetails } from \"./todos-types.ts\";\n\nexport const todoToolSystemPromptContribution = Object.freeze({\n\tguidelines: Object.freeze([\n\t\t\"**To-do management**: If the user has a complex task that can be broken down into actionable steps, use the `todo` tool to create a task list before proceeding. This ensures clarity and alignment with the user's goals and that you have a way to track your work and ensure you are meeting the user's expectations.\",\n\t] as const),\n} as const);\n\nexport function createTodoToolDefinition(\n\tcwd: string = process.cwd(),\n): ToolDefinition<typeof TodoParams, TodoToolDetails> {\n\tconst todosDirLabel = getTodosDirLabel(cwd);\n\n\treturn {\n\t\tname: \"todo\",\n\t\tconcurrency: \"exclusive\",\n\t\tlabel: \"Todo\",\n\t\tdescription:\n\t\t\t`Manage file-based todos in ${todosDirLabel} (list, list-all, get, create, update, append, delete, claim, release). ` +\n\t\t\t\"Title is the short summary; body is long-form markdown notes (update replaces, append adds). \" +\n\t\t\t\"Todo ids are shown as TODO-<hex>; id parameters accept TODO-<hex> or the raw hex filename. \" +\n\t\t\t\"Claim tasks before working on them to avoid conflicts, and close them when complete.\",\n\t\t...experimentalToolSamplingProperty(),\n\t\tparameters: TodoParams,\n\t\tpromptGuidelines: [...todoToolSystemPromptContribution.guidelines],\n\t\texecute: (_toolCallId, params, _signal, _onUpdate, ctx) => executeTodoToolAction(params, ctx),\n\t\trenderCall: renderTodoCall,\n\t\trenderResult: renderTodoResult,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
/**
|
|
3
|
+
* How a tool call is ordered against the other calls of the same assistant message.
|
|
4
|
+
* - "shared": may overlap other shared calls; waits for the latest earlier exclusive call (default)
|
|
5
|
+
* - "exclusive": waits for every earlier call; later calls wait for it
|
|
6
|
+
* - function: resolved per call from its prepared arguments; a throwing resolver means "exclusive"
|
|
7
|
+
*/
|
|
8
|
+
export type ToolConcurrencyMode = "shared" | "exclusive";
|
|
9
|
+
export type ToolConcurrency<TArgs = Record<string, unknown>> = ToolConcurrencyMode | ((args: Partial<TArgs>) => ToolConcurrencyMode);
|
|
10
|
+
export declare function resolveToolConcurrency<TArgs>(concurrency: ToolConcurrency<TArgs> | undefined, args: Partial<TArgs>): ToolConcurrencyMode;
|
|
11
|
+
/**
|
|
12
|
+
* Orders tool executions in the order they start. The agent loop starts a batch's calls in
|
|
13
|
+
* assistant-message order, so an exclusive call observes every earlier call's effects and no
|
|
14
|
+
* later call observes the state from before it.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ToolExecutionScheduler {
|
|
17
|
+
#private;
|
|
18
|
+
/** Runs `run` synchronously when nothing earlier blocks it, so its abort listeners attach immediately. */
|
|
19
|
+
schedule<T>(mode: ToolConcurrencyMode, run: () => Promise<T>): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
/** Route a tool's executions through a session scheduler according to its declared concurrency. */
|
|
22
|
+
export declare function scheduleToolExecution(tool: AgentTool, scheduler: ToolExecutionScheduler): AgentTool;
|
|
23
|
+
//# sourceMappingURL=tool-concurrency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-concurrency.d.ts","sourceRoot":"","sources":["../../../src/core/tools/tool-concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,WAAW,CAAC;AACzD,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACxD,mBAAmB,GACnB,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,mBAAmB,CAAC,CAAC;AAEnD,wBAAgB,sBAAsB,CAAC,KAAK,EAC3C,WAAW,EAAE,eAAe,CAAC,KAAK,CAAC,GAAG,SAAS,EAC/C,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,GAClB,mBAAmB,CAOrB;AAED;;;;GAIG;AACH,qBAAa,sBAAsB;;IAIlC,0GAA0G;IAC1G,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAuBxE;CACD;AAUD,mGAAmG;AACnG,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,sBAAsB,GAAG,SAAS,CAQnG"}
|