maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.32.20260914
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/THIRD_PARTY_NOTICES.txt +392 -0
- package/dist/acp/maka-acp-agent.js +8 -2
- package/dist/acp/prompt-content.js +225 -0
- package/dist/acp/session-event-mapper.js +103 -0
- package/dist/acp/session-registry.js +654 -17
- package/dist/acp/stdio-server.js +10 -1
- package/dist/cli-core.js +1 -1
- package/dist/pi-transcript-tools.js +3 -2
- package/dist/pi-transcript.js +15 -6
- package/dist/runtime-host-session-channel.js +63 -9
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/agent-graph-schedule.js +15 -4
- package/node_modules/@maka/core/dist/artifacts.js +6 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -2
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
- package/node_modules/@maka/core/dist/events.js +21 -0
- package/node_modules/@maka/core/dist/executor-id.js +22 -0
- package/node_modules/@maka/core/dist/external-session.js +18 -0
- package/node_modules/@maka/core/dist/goal.js +44 -2
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -13
- package/node_modules/@maka/core/dist/permission.js +0 -1
- package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
- package/node_modules/@maka/core/dist/runtime-event.js +25 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
- package/node_modules/@maka/core/dist/session-send-projection.js +6 -3
- package/node_modules/@maka/core/dist/session.js +8 -2
- package/node_modules/@maka/core/dist/shell-run-result.js +1 -0
- package/node_modules/@maka/core/dist/shell-run.js +4 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/unified-diff.js +33 -26
- package/node_modules/@maka/core/dist/work-board.js +94 -1
- package/node_modules/@maka/core/package.json +1 -0
- package/node_modules/@maka/eval/dist/fleet-simulation.js +270 -0
- package/node_modules/@maka/eval/dist/fleet-store.js +243 -0
- package/node_modules/@maka/eval/dist/fleet-worker.js +125 -0
- package/node_modules/@maka/eval/dist/fleet.js +329 -0
- package/node_modules/@maka/eval/dist/index.js +3 -0
- package/node_modules/@maka/runtime/dist/agent-run.js +2 -17
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +55 -180
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +43 -26
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +271 -382
- package/node_modules/@maka/runtime/dist/background-task-health-tool.js +104 -0
- package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
- package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
- package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
- package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
- package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
- package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
- package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
- package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
- package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
- package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
- package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
- package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
- package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
- package/node_modules/@maka/runtime/dist/history-compaction.js +3 -1
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
- package/node_modules/@maka/runtime/dist/local-web-fetch.js +1 -1
- package/node_modules/@maka/runtime/dist/model-adapter.js +62 -53
- package/node_modules/@maka/runtime/dist/model-history.js +26 -8
- package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
- package/node_modules/@maka/runtime/dist/plugin-executor-backend.js +311 -0
- package/node_modules/@maka/runtime/dist/plugin-executor-service.js +344 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +7 -1
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +35 -8
- package/node_modules/@maka/runtime/dist/read-page.js +231 -0
- package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
- package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
- package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +7 -1
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +188 -20
- package/node_modules/@maka/runtime/dist/runtime-invocation-route.js +49 -0
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +72 -150
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -3
- package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +106 -64
- package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
- package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +10 -4
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +2 -1
- package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +1 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +26 -4
- package/node_modules/@maka/runtime/dist/subagent-tools.js +7 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
- package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
- package/node_modules/@maka/runtime/dist/tool-runtime.js +52 -471
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
- package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
- package/node_modules/@maka/runtime/package.json +5 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +7 -2
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +24 -3
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +42 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +31 -3
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +8 -2
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
- package/node_modules/@maka/runtime-host/dist/server/child-agent-composition.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +3 -30
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +56 -8
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +14 -1
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
- package/node_modules/@maka/runtime-host/dist/server/host-session-availability.js +10 -2
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +56 -16
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +9 -5
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +4 -0
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
- package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +37 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
- package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +450 -234
- package/node_modules/@maka/storage/dist/claude-code-transcript-lineage.js +106 -77
- package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
- package/node_modules/@maka/storage/dist/legacy-run-header.js +2 -2
- package/node_modules/@maka/storage/dist/model-call-usage-sql.js +1 -1
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
- package/node_modules/@maka/storage/dist/session-store.js +12 -2
- package/node_modules/@maka/storage/dist/sqlite-long-term-memory-store.js +86 -12
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
- package/node_modules/@maka/storage/dist/work-board-store.js +40 -1
- package/node_modules/balanced-match/LICENSE.md +23 -0
- package/node_modules/balanced-match/README.md +57 -0
- package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
- package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
- package/node_modules/balanced-match/dist/esm/index.js +54 -0
- package/node_modules/balanced-match/dist/esm/package.json +3 -0
- package/node_modules/balanced-match/package.json +68 -0
- package/node_modules/brace-expansion/LICENSE +23 -0
- package/node_modules/brace-expansion/README.md +105 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
- package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
- package/node_modules/brace-expansion/dist/esm/index.js +285 -0
- package/node_modules/brace-expansion/dist/esm/package.json +3 -0
- package/node_modules/brace-expansion/package.json +64 -0
- package/node_modules/glob/LICENSE.md +63 -0
- package/node_modules/glob/README.md +1203 -0
- package/node_modules/glob/dist/commonjs/glob.js +248 -0
- package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
- package/node_modules/glob/dist/commonjs/ignore.js +119 -0
- package/node_modules/glob/dist/commonjs/index.js +68 -0
- package/node_modules/glob/dist/commonjs/index.min.js +4 -0
- package/node_modules/glob/dist/commonjs/package.json +3 -0
- package/node_modules/glob/dist/commonjs/pattern.js +223 -0
- package/node_modules/glob/dist/commonjs/processor.js +301 -0
- package/node_modules/glob/dist/commonjs/walker.js +387 -0
- package/node_modules/glob/dist/esm/glob.js +244 -0
- package/node_modules/glob/dist/esm/has-magic.js +23 -0
- package/node_modules/glob/dist/esm/ignore.js +115 -0
- package/node_modules/glob/dist/esm/index.js +55 -0
- package/node_modules/glob/dist/esm/index.min.js +4 -0
- package/node_modules/glob/dist/esm/package.json +3 -0
- package/node_modules/glob/dist/esm/pattern.js +219 -0
- package/node_modules/glob/dist/esm/processor.js +294 -0
- package/node_modules/glob/dist/esm/walker.js +381 -0
- package/node_modules/glob/package.json +98 -0
- package/node_modules/minimatch/LICENSE.md +55 -0
- package/node_modules/minimatch/README.md +528 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/ast.js +841 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
- package/node_modules/minimatch/dist/esm/escape.js +26 -0
- package/node_modules/minimatch/dist/esm/index.js +1114 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.js +34 -0
- package/node_modules/minimatch/package.json +73 -0
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/README.md +825 -0
- package/node_modules/minipass/dist/commonjs/index.js +1038 -0
- package/node_modules/minipass/dist/commonjs/package.json +3 -0
- package/node_modules/minipass/dist/esm/index.js +1020 -0
- package/node_modules/minipass/dist/esm/package.json +3 -0
- package/node_modules/minipass/package.json +77 -0
- package/node_modules/path-scurry/LICENSE.md +55 -0
- package/node_modules/path-scurry/README.md +636 -0
- package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
- package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/dist/esm/index.js +1983 -0
- package/node_modules/path-scurry/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
- package/node_modules/path-scurry/package.json +72 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
- package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
|
@@ -25,8 +25,7 @@ import { encodeToolStepProgress, ToolOutcomeUnknownError } from '@maka/core/even
|
|
|
25
25
|
import { isInteractionAnswerValidForRequest, projectInteractionFormRequest, } from '@maka/core/interaction';
|
|
26
26
|
import { computerUseModelCallArgs } from '@maka/core/computer-use';
|
|
27
27
|
import { redactSecrets } from '@maka/core/redaction';
|
|
28
|
-
import {
|
|
29
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
28
|
+
import { TOOL_BOUNDARY_PROTOCOL_V1 } from '@maka/core/runtime-event';
|
|
30
29
|
import { recordToolArtifactsSafely } from './tool-artifacts.js';
|
|
31
30
|
import { computerActionFields, describeComputerUseArgsViolation } from './computer-use-codec.js';
|
|
32
31
|
import { createToolOutputDeltaEmitter } from './tool-output-delta.js';
|
|
@@ -74,12 +73,6 @@ class RuntimeCommitBoundaryError extends Error {
|
|
|
74
73
|
this.name = 'RuntimeCommitBoundaryError';
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
class RuntimeManagedMutationUnsettledError extends Error {
|
|
78
|
-
constructor(cause) {
|
|
79
|
-
super(`Managed workspace mutation remains unsettled: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
80
|
-
this.name = 'RuntimeManagedMutationUnsettledError';
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
76
|
class ToolResultLimitError extends Error {
|
|
84
77
|
constructor() {
|
|
85
78
|
super('Tool result byte limit exceeded');
|
|
@@ -372,6 +365,8 @@ export class ToolRuntime {
|
|
|
372
365
|
return encodeDefaultDurableToolResultOutput(result, this.input.sessionId);
|
|
373
366
|
}
|
|
374
367
|
const output = tool.toModelOutput({ toolCallId, input, output: result });
|
|
368
|
+
if (output === undefined)
|
|
369
|
+
return encodeDefaultDurableToolResultOutput(result, this.input.sessionId);
|
|
375
370
|
// Projection is deliberately synchronous and total at the tool boundary.
|
|
376
371
|
// Fail closed for untyped/plugin implementations that violate the
|
|
377
372
|
// contract so a completed effect can never be stranded before T2.
|
|
@@ -512,18 +507,31 @@ export class ToolRuntime {
|
|
|
512
507
|
result: content,
|
|
513
508
|
isError: true,
|
|
514
509
|
}, this.input.sessionId) ?? DURABLE_TOOL_RESULT_PROJECTION_FAILURE;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
type: 'tool_result',
|
|
518
|
-
id: durableOutcome?.id ?? this.input.newId(),
|
|
510
|
+
await this.commitAndPublishToolResult({
|
|
511
|
+
queue,
|
|
519
512
|
turnId,
|
|
520
|
-
ts: durableOutcome?.ts ?? this.input.now(),
|
|
521
513
|
toolUseId,
|
|
522
|
-
...(durableOutcome ? { operationId: durableOutcome.operationId } : {}),
|
|
523
514
|
isError: true,
|
|
524
515
|
content,
|
|
525
516
|
modelProjection,
|
|
526
|
-
|
|
517
|
+
activityIdentity,
|
|
518
|
+
durableAttempt,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
async commitAndPublishToolResult(input) {
|
|
522
|
+
const durableOutcome = await input.durableAttempt?.commitOutcome(input.content, input.isError, input.modelProjection, input.durationMs);
|
|
523
|
+
input.queue.push({
|
|
524
|
+
type: 'tool_result',
|
|
525
|
+
id: durableOutcome?.id ?? this.input.newId(),
|
|
526
|
+
turnId: input.turnId,
|
|
527
|
+
ts: durableOutcome?.ts ?? this.input.now(),
|
|
528
|
+
toolUseId: input.toolUseId,
|
|
529
|
+
...(durableOutcome ? { operationId: durableOutcome.operationId } : {}),
|
|
530
|
+
isError: input.isError,
|
|
531
|
+
content: input.content,
|
|
532
|
+
modelProjection: input.modelProjection,
|
|
533
|
+
...(input.durationMs !== undefined ? { durationMs: input.durationMs } : {}),
|
|
534
|
+
...input.activityIdentity,
|
|
527
535
|
});
|
|
528
536
|
}
|
|
529
537
|
async executeTool(tool, turnId, queue, args, ctx, stepId) {
|
|
@@ -901,38 +909,9 @@ export class ToolRuntime {
|
|
|
901
909
|
pauseTarget?.resume();
|
|
902
910
|
}
|
|
903
911
|
}
|
|
904
|
-
let managedMutationAdmission;
|
|
905
|
-
if (tool.durableExecutionProfile === 'managed_mutation_v1') {
|
|
906
|
-
if ((tool.name !== 'Write' && tool.name !== 'Edit') ||
|
|
907
|
-
tool.recoveryMode !== 'reconcile' ||
|
|
908
|
-
!tool.managedMutationTransform ||
|
|
909
|
-
!dispatchOperationId ||
|
|
910
|
-
!this.input.runtimeCommitSink ||
|
|
911
|
-
!this.input.admitManagedMutation) {
|
|
912
|
-
const reason = 'Managed workspace mutation admission is unavailable before T1';
|
|
913
|
-
await refuseBeforeDispatch(reason);
|
|
914
|
-
this.recordLoopGateOutcome(callSignature, true);
|
|
915
|
-
return this.errorReturn(reason);
|
|
916
|
-
}
|
|
917
|
-
try {
|
|
918
|
-
managedMutationAdmission = await this.input.admitManagedMutation({
|
|
919
|
-
operationId: dispatchOperationId,
|
|
920
|
-
toolName: tool.name,
|
|
921
|
-
persistedArgs: structuredClone(persistedArgs),
|
|
922
|
-
abortSignal: ctx.abortSignal,
|
|
923
|
-
});
|
|
924
|
-
}
|
|
925
|
-
catch (error) {
|
|
926
|
-
const reason = `Managed workspace mutation admission failed: ${formatSyntheticToolErrorText(error)}`;
|
|
927
|
-
await refuseBeforeDispatch(reason);
|
|
928
|
-
this.recordLoopGateOutcome(callSignature, true);
|
|
929
|
-
return this.errorReturn(reason);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
912
|
const reservedSubagentSlot = this.reserveSubagentSlot(tool);
|
|
933
913
|
if (!reservedSubagentSlot) {
|
|
934
914
|
await preparedExecution?.cancel();
|
|
935
|
-
await disposeManagedMutationAdmission(managedMutationAdmission);
|
|
936
915
|
trace?.emit('tool', 'tool_failed', 'Tool execution rejected by runtime limit', {
|
|
937
916
|
toolUseId,
|
|
938
917
|
toolName: tool.name,
|
|
@@ -951,9 +930,6 @@ export class ToolRuntime {
|
|
|
951
930
|
persistedArgs,
|
|
952
931
|
modelFacingArgs,
|
|
953
932
|
abortSignal: ctx.abortSignal,
|
|
954
|
-
...(managedMutationAdmission
|
|
955
|
-
? { managedMutation: managedMutationAdmission.durableDispatch }
|
|
956
|
-
: {}),
|
|
957
933
|
...(invocationId ? { invocationId } : {}),
|
|
958
934
|
...(runId ? { runId } : {}),
|
|
959
935
|
});
|
|
@@ -962,7 +938,6 @@ export class ToolRuntime {
|
|
|
962
938
|
await preparedExecution?.cancel();
|
|
963
939
|
if (reservedSubagentSlot)
|
|
964
940
|
this.releaseSubagentSlot(tool);
|
|
965
|
-
await disposeManagedMutationAdmission(managedMutationAdmission);
|
|
966
941
|
throw error;
|
|
967
942
|
}
|
|
968
943
|
publishCallEvent(buildCallEvent('dispatch'));
|
|
@@ -1061,145 +1036,41 @@ export class ToolRuntime {
|
|
|
1061
1036
|
const invokeTool = () => preparedExecution
|
|
1062
1037
|
? preparedExecution.execute(toolContext)
|
|
1063
1038
|
: tool.impl(structuredClone(executionArgs), toolContext);
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
const result = immutableSnapshot
|
|
1068
|
-
? snapshotManagedToolResult(rawResult, ctx.maxResultBytes)
|
|
1069
|
-
: rawResult;
|
|
1070
|
-
if (!immutableSnapshot &&
|
|
1071
|
-
ctx.maxResultBytes !== undefined &&
|
|
1039
|
+
const prepareOperationValue = async () => {
|
|
1040
|
+
const result = await invokeTool();
|
|
1041
|
+
if (ctx.maxResultBytes !== undefined &&
|
|
1072
1042
|
serializedByteLength(result, ctx.maxResultBytes) > ctx.maxResultBytes) {
|
|
1073
1043
|
throw new ToolResultLimitError();
|
|
1074
1044
|
}
|
|
1075
|
-
const content =
|
|
1076
|
-
? Object.freeze(coerceResultContent(result))
|
|
1077
|
-
: coerceResultContent(result);
|
|
1045
|
+
const content = coerceResultContent(result);
|
|
1078
1046
|
const projected = this.projectToolResult(tool, turnId, toolUseId, executionArgs, result);
|
|
1079
1047
|
const modelProjection = isPromiseLike(projected) ? await projected : projected;
|
|
1080
|
-
|
|
1048
|
+
return {
|
|
1049
|
+
result,
|
|
1081
1050
|
content,
|
|
1082
1051
|
isError: deriveToolResultStatus(content, result) !== 'success',
|
|
1083
1052
|
durationMs: this.input.now() - startedAt,
|
|
1084
1053
|
modelProjection,
|
|
1085
1054
|
};
|
|
1086
|
-
const value = {
|
|
1087
|
-
result,
|
|
1088
|
-
outcome: immutableSnapshot ? Object.freeze(outcome) : outcome,
|
|
1089
|
-
};
|
|
1090
|
-
return immutableSnapshot ? Object.freeze(value) : value;
|
|
1091
1055
|
};
|
|
1092
|
-
|
|
1093
|
-
if (managedMutationAdmission) {
|
|
1094
|
-
const operationLifecycle = { state: 'open' };
|
|
1095
|
-
let operationPromise;
|
|
1096
|
-
let runtimeOwnedValue;
|
|
1097
|
-
const executeManagedOperation = () => {
|
|
1098
|
-
if (operationLifecycle.state !== 'open') {
|
|
1099
|
-
if (operationLifecycle.state === 'closed') {
|
|
1100
|
-
return Promise.reject(new Error('Managed mutation operation capability is closed'));
|
|
1101
|
-
}
|
|
1102
|
-
return Promise.reject(new Error('Managed mutation owner invoked the operation more than once'));
|
|
1103
|
-
}
|
|
1104
|
-
operationLifecycle.state = 'running';
|
|
1105
|
-
operationPromise = (async () => {
|
|
1106
|
-
try {
|
|
1107
|
-
const value = await prepareOperationValue(true);
|
|
1108
|
-
runtimeOwnedValue = value;
|
|
1109
|
-
return {
|
|
1110
|
-
// The canonical content is already recursively immutable, so
|
|
1111
|
-
// the owner can read it without receiving a mutable alias.
|
|
1112
|
-
content: value.outcome.content,
|
|
1113
|
-
isError: value.outcome.isError,
|
|
1114
|
-
durationMs: value.outcome.durationMs,
|
|
1115
|
-
modelProjection: value.outcome.modelProjection,
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
finally {
|
|
1119
|
-
if (operationLifecycle.state === 'running') {
|
|
1120
|
-
operationLifecycle.state = 'settled';
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
})();
|
|
1124
|
-
// Runtime also observes the promise so a careless owner cannot
|
|
1125
|
-
// turn an un-awaited operation rejection into an unhandled one.
|
|
1126
|
-
void operationPromise.catch(() => undefined);
|
|
1127
|
-
return operationPromise;
|
|
1128
|
-
};
|
|
1129
|
-
let settlement;
|
|
1130
|
-
let ownerFailed = false;
|
|
1131
|
-
let ownerError;
|
|
1132
|
-
try {
|
|
1133
|
-
settlement = await managedMutationAdmission.execute(executeManagedOperation);
|
|
1134
|
-
}
|
|
1135
|
-
catch (error) {
|
|
1136
|
-
ownerFailed = true;
|
|
1137
|
-
ownerError = error;
|
|
1138
|
-
}
|
|
1139
|
-
const ownerSettledWhileOperationRunning = operationLifecycle.state === 'running';
|
|
1140
|
-
if (ownerSettledWhileOperationRunning) {
|
|
1141
|
-
try {
|
|
1142
|
-
await operationPromise;
|
|
1143
|
-
}
|
|
1144
|
-
catch {
|
|
1145
|
-
// The terminal state is invalid regardless of how the detached
|
|
1146
|
-
// operation settles. Join it so no side effect can occur later.
|
|
1147
|
-
}
|
|
1148
|
-
finally {
|
|
1149
|
-
operationLifecycle.state = 'closed';
|
|
1150
|
-
}
|
|
1151
|
-
throw new RuntimeManagedMutationUnsettledError(new Error('Managed mutation owner settled before the operation completed', {
|
|
1152
|
-
...(ownerFailed ? { cause: ownerError } : {}),
|
|
1153
|
-
}));
|
|
1154
|
-
}
|
|
1155
|
-
operationLifecycle.state = 'closed';
|
|
1156
|
-
if (ownerFailed) {
|
|
1157
|
-
// Once managed T1 is durable, an admission/owner failure may never
|
|
1158
|
-
// fall through to the generic synthetic T2 path. Only the owner can
|
|
1159
|
-
// prove that a successor was accepted or the candidate was safely
|
|
1160
|
-
// discarded; every other failure remains unsettled for recovery.
|
|
1161
|
-
throw new RuntimeManagedMutationUnsettledError(ownerError);
|
|
1162
|
-
}
|
|
1163
|
-
const normalized = normalizeManagedMutationSettlement(settlement, ctx.maxResultBytes);
|
|
1164
|
-
if (normalized.kind === 'workspace_successor_committed') {
|
|
1165
|
-
if (!runtimeOwnedValue) {
|
|
1166
|
-
throw new RuntimeManagedMutationUnsettledError(new Error('Managed mutation owner committed success without executing the operation'));
|
|
1167
|
-
}
|
|
1168
|
-
settledExecution = {
|
|
1169
|
-
kind: 'managed',
|
|
1170
|
-
value: runtimeOwnedValue,
|
|
1171
|
-
durableOutcome: normalized.durableOutcome,
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
else {
|
|
1175
|
-
settledExecution = {
|
|
1176
|
-
kind: 'managed',
|
|
1177
|
-
value: normalized.value,
|
|
1178
|
-
durableOutcome: normalized.durableOutcome,
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
else {
|
|
1183
|
-
settledExecution = { kind: 'generic', value: await prepareOperationValue() };
|
|
1184
|
-
}
|
|
1185
|
-
const { result, outcome } = settledExecution.value;
|
|
1056
|
+
const { result, content, isError, durationMs, modelProjection } = await prepareOperationValue();
|
|
1186
1057
|
output.flush();
|
|
1187
|
-
const { content, durationMs, modelProjection } = outcome;
|
|
1188
1058
|
// Keep the full provider-facing terminal classification. `isError` is
|
|
1189
1059
|
// sufficient for the durable response envelope, but it intentionally
|
|
1190
1060
|
// collapses `aborted` into an error bit and therefore cannot drive live
|
|
1191
1061
|
// tool status, telemetry, or subagent lifecycle projection.
|
|
1192
1062
|
const toolResultStatus = deriveToolResultStatus(content, result);
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1063
|
+
await this.commitAndPublishToolResult({
|
|
1064
|
+
queue,
|
|
1065
|
+
turnId,
|
|
1066
|
+
toolUseId,
|
|
1067
|
+
isError,
|
|
1068
|
+
content,
|
|
1069
|
+
modelProjection,
|
|
1070
|
+
durationMs,
|
|
1071
|
+
activityIdentity,
|
|
1072
|
+
durableAttempt,
|
|
1073
|
+
});
|
|
1203
1074
|
if (hasSandboxDenial(content)) {
|
|
1204
1075
|
const denialKey = sandboxDenialKey(tool.name, this.input.header.cwd, executionArgs);
|
|
1205
1076
|
this.recentSandboxDenials.add(denialKey);
|
|
@@ -1214,19 +1085,6 @@ export class ToolRuntime {
|
|
|
1214
1085
|
commandHash: denialKey,
|
|
1215
1086
|
});
|
|
1216
1087
|
}
|
|
1217
|
-
queue.push({
|
|
1218
|
-
type: 'tool_result',
|
|
1219
|
-
id: durableOutcome?.id ?? this.input.newId(),
|
|
1220
|
-
turnId,
|
|
1221
|
-
ts: durableOutcome?.ts ?? this.input.now(),
|
|
1222
|
-
toolUseId,
|
|
1223
|
-
...(durableOutcome ? { operationId: durableOutcome.operationId } : {}),
|
|
1224
|
-
isError: toolResultStatus !== 'success',
|
|
1225
|
-
content,
|
|
1226
|
-
modelProjection,
|
|
1227
|
-
durationMs,
|
|
1228
|
-
...activityIdentity,
|
|
1229
|
-
});
|
|
1230
1088
|
this.input.recordToolInvocation?.({
|
|
1231
1089
|
sessionId: this.input.sessionId,
|
|
1232
1090
|
turnId,
|
|
@@ -1284,17 +1142,8 @@ export class ToolRuntime {
|
|
|
1284
1142
|
}
|
|
1285
1143
|
}
|
|
1286
1144
|
catch (err) {
|
|
1287
|
-
if (err instanceof RuntimeCommitBoundaryError
|
|
1288
|
-
err instanceof RuntimeManagedMutationUnsettledError) {
|
|
1145
|
+
if (err instanceof RuntimeCommitBoundaryError)
|
|
1289
1146
|
throw err;
|
|
1290
|
-
}
|
|
1291
|
-
// Admission exists only after the owner has selected managed mode and
|
|
1292
|
-
// Runtime has committed its T1 dispatch. From that point onward every
|
|
1293
|
-
// normalization, size check, adoption, publication, and telemetry error
|
|
1294
|
-
// is recovery-owned. It may never fall through to generic synthetic T2.
|
|
1295
|
-
if (managedMutationAdmission) {
|
|
1296
|
-
throw new RuntimeManagedMutationUnsettledError(err);
|
|
1297
|
-
}
|
|
1298
1147
|
if (isInteractionControlError(err))
|
|
1299
1148
|
throw err;
|
|
1300
1149
|
output.flush();
|
|
@@ -1319,21 +1168,18 @@ export class ToolRuntime {
|
|
|
1319
1168
|
}
|
|
1320
1169
|
const durationMs = Math.max(0, this.input.now() - startedAt);
|
|
1321
1170
|
const terminalResult = this.errorReturn(terminalFailure.message);
|
|
1322
|
-
const projected = this.projectToolResult(tool, turnId, toolUseId, executionArgs,
|
|
1171
|
+
const projected = this.projectToolResult(tool, turnId, toolUseId, executionArgs, terminalFailure.content);
|
|
1323
1172
|
const modelProjection = isPromiseLike(projected) ? await projected : projected;
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
type: 'tool_result',
|
|
1327
|
-
id: durableOutcome?.id ?? this.input.newId(),
|
|
1173
|
+
await this.commitAndPublishToolResult({
|
|
1174
|
+
queue,
|
|
1328
1175
|
turnId,
|
|
1329
|
-
ts: durableOutcome?.ts ?? this.input.now(),
|
|
1330
1176
|
toolUseId,
|
|
1331
|
-
...(durableOutcome ? { operationId: durableOutcome.operationId } : {}),
|
|
1332
1177
|
isError: true,
|
|
1333
1178
|
content: terminalFailure.content,
|
|
1334
1179
|
modelProjection,
|
|
1335
1180
|
durationMs,
|
|
1336
|
-
|
|
1181
|
+
activityIdentity,
|
|
1182
|
+
durableAttempt,
|
|
1337
1183
|
});
|
|
1338
1184
|
this.input.recordToolInvocation?.({
|
|
1339
1185
|
sessionId: this.input.sessionId,
|
|
@@ -1402,7 +1248,6 @@ export class ToolRuntime {
|
|
|
1402
1248
|
this.recordLoopGateOutcome(callSignature, attemptFailed, attemptBoundaryKind, attemptBoundaryDetails);
|
|
1403
1249
|
if (reservedSubagentSlot)
|
|
1404
1250
|
this.releaseSubagentSlot(tool);
|
|
1405
|
-
await disposeManagedMutationAdmission(managedMutationAdmission);
|
|
1406
1251
|
}
|
|
1407
1252
|
}
|
|
1408
1253
|
async prepareDurableToolAttempt(input) {
|
|
@@ -1484,7 +1329,6 @@ export class ToolRuntime {
|
|
|
1484
1329
|
toolName: input.tool.name,
|
|
1485
1330
|
canonicalArgsHash,
|
|
1486
1331
|
recoveryMode,
|
|
1487
|
-
...(input.managedMutation ? { managedMutation: input.managedMutation } : {}),
|
|
1488
1332
|
},
|
|
1489
1333
|
},
|
|
1490
1334
|
refs: {
|
|
@@ -1499,22 +1343,6 @@ export class ToolRuntime {
|
|
|
1499
1343
|
},
|
|
1500
1344
|
};
|
|
1501
1345
|
try {
|
|
1502
|
-
if (input.managedMutation) {
|
|
1503
|
-
decodeRuntimeEvent(dispatchEvent);
|
|
1504
|
-
const persistedPath = input.persistedArgs &&
|
|
1505
|
-
typeof input.persistedArgs === 'object' &&
|
|
1506
|
-
!Array.isArray(input.persistedArgs)
|
|
1507
|
-
? input.persistedArgs.path
|
|
1508
|
-
: undefined;
|
|
1509
|
-
if ((input.tool.name !== 'Write' && input.tool.name !== 'Edit') ||
|
|
1510
|
-
typeof persistedPath !== 'string' ||
|
|
1511
|
-
input.managedMutation.expectedPath !== persistedPath ||
|
|
1512
|
-
input.managedMutation.pathPolicyVersion !== 3 ||
|
|
1513
|
-
input.managedMutation.executionProfileDigest !==
|
|
1514
|
-
MANAGED_MUTATION_EXECUTION_PROFILE_V1_DIGEST) {
|
|
1515
|
-
throw new Error('Managed mutation admission does not match the durable tool call');
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
1346
|
this.assertDurableDispatchNotAborted(input.tool.name, input.abortSignal);
|
|
1519
1347
|
const prepared = await sink.commitToolPrepared({
|
|
1520
1348
|
operationId,
|
|
@@ -1569,7 +1397,6 @@ export class ToolRuntime {
|
|
|
1569
1397
|
let committedOutcome;
|
|
1570
1398
|
return {
|
|
1571
1399
|
operationId,
|
|
1572
|
-
responseEventId: `${operationId}_response`,
|
|
1573
1400
|
commitOutcome: async (result, isError, modelProjection, durationMs) => {
|
|
1574
1401
|
if (committedOutcome)
|
|
1575
1402
|
return committedOutcome;
|
|
@@ -1605,17 +1432,6 @@ export class ToolRuntime {
|
|
|
1605
1432
|
this.durableToolAttempts.delete(durableAttemptKey(input.startEvent.turnId, input.startEvent.toolUseId));
|
|
1606
1433
|
return committedOutcome;
|
|
1607
1434
|
},
|
|
1608
|
-
adoptCommittedOutcome: (event, result, isError, modelProjection, durationMs) => {
|
|
1609
|
-
if (committedOutcome)
|
|
1610
|
-
return committedOutcome;
|
|
1611
|
-
const expected = buildResponseEvent(result, isError, modelProjection, durationMs, event.ts);
|
|
1612
|
-
if (!Number.isFinite(event.ts) || !isDeepStrictEqual(event, expected)) {
|
|
1613
|
-
throw new RuntimeCommitBoundaryError('T2', new Error('Managed mutation settlement returned a mismatched durable outcome'));
|
|
1614
|
-
}
|
|
1615
|
-
committedOutcome = { id: event.id, operationId, ts: event.ts };
|
|
1616
|
-
this.durableToolAttempts.delete(durableAttemptKey(input.startEvent.turnId, input.startEvent.toolUseId));
|
|
1617
|
-
return committedOutcome;
|
|
1618
|
-
},
|
|
1619
1435
|
};
|
|
1620
1436
|
}
|
|
1621
1437
|
admitToolForStep(tool, stepId) {
|
|
@@ -1753,6 +1569,7 @@ export class ToolRuntime {
|
|
|
1753
1569
|
toolCallId: input.toolUseId,
|
|
1754
1570
|
agentProfile: spawnInput.agentProfile,
|
|
1755
1571
|
...(spawnInput.subagentId ? { subagentId: spawnInput.subagentId } : {}),
|
|
1572
|
+
...(spawnInput.executorId ? { executorId: spawnInput.executorId } : {}),
|
|
1756
1573
|
prompt: spawnInput.prompt,
|
|
1757
1574
|
...(spawnInput.swarm ? { swarm: spawnInput.swarm } : {}),
|
|
1758
1575
|
abortSignal,
|
|
@@ -2575,64 +2392,6 @@ function uncertainOutcomeSignalFromError(error) {
|
|
|
2575
2392
|
retrySafe: false,
|
|
2576
2393
|
};
|
|
2577
2394
|
}
|
|
2578
|
-
function normalizeManagedMutationSettlement(settlement, maxResultBytes) {
|
|
2579
|
-
if (!settlement || typeof settlement !== 'object' || Array.isArray(settlement)) {
|
|
2580
|
-
throw new Error('Managed mutation owner returned an invalid settlement');
|
|
2581
|
-
}
|
|
2582
|
-
const record = settlement;
|
|
2583
|
-
const kind = record.kind;
|
|
2584
|
-
if (kind === 'unsettled') {
|
|
2585
|
-
throw new RuntimeManagedMutationUnsettledError(record.error);
|
|
2586
|
-
}
|
|
2587
|
-
if (kind !== 'workspace_successor_committed' &&
|
|
2588
|
-
kind !== 'no_workspace_change_committed' &&
|
|
2589
|
-
kind !== 'operation_failed_no_effect_committed') {
|
|
2590
|
-
throw new Error('Managed mutation owner returned an unknown settlement kind');
|
|
2591
|
-
}
|
|
2592
|
-
const durableOutcomeValue = Object.hasOwn(record, 'durableOutcome')
|
|
2593
|
-
? record.durableOutcome
|
|
2594
|
-
: undefined;
|
|
2595
|
-
if (!durableOutcomeValue ||
|
|
2596
|
-
typeof durableOutcomeValue !== 'object' ||
|
|
2597
|
-
Array.isArray(durableOutcomeValue)) {
|
|
2598
|
-
throw new Error('Managed mutation settlement has no durable outcome');
|
|
2599
|
-
}
|
|
2600
|
-
const durableOutcome = durableOutcomeValue;
|
|
2601
|
-
if (kind === 'workspace_successor_committed') {
|
|
2602
|
-
return {
|
|
2603
|
-
kind,
|
|
2604
|
-
durableOutcome,
|
|
2605
|
-
};
|
|
2606
|
-
}
|
|
2607
|
-
if (!Object.hasOwn(record, 'providerResult')) {
|
|
2608
|
-
throw new Error('Managed no-effect settlement has no provider result');
|
|
2609
|
-
}
|
|
2610
|
-
const providerResult = snapshotManagedToolResult(record.providerResult, maxResultBytes);
|
|
2611
|
-
const response = durableOutcome.content;
|
|
2612
|
-
const expectedError = kind === 'operation_failed_no_effect_committed';
|
|
2613
|
-
if (response?.kind !== 'function_response' ||
|
|
2614
|
-
response.modelProjection === undefined ||
|
|
2615
|
-
(expectedError ? response.isError !== true : response.isError === true)) {
|
|
2616
|
-
throw new Error('Managed no-effect settlement has the wrong durable outcome state');
|
|
2617
|
-
}
|
|
2618
|
-
const content = Object.freeze(coerceResultContent(providerResult));
|
|
2619
|
-
const outcome = Object.freeze({
|
|
2620
|
-
content,
|
|
2621
|
-
isError: expectedError,
|
|
2622
|
-
modelProjection: response.modelProjection,
|
|
2623
|
-
durationMs: typeof durableOutcome.actions?.stateDelta?.durationMs === 'number'
|
|
2624
|
-
? durableOutcome.actions.stateDelta.durationMs
|
|
2625
|
-
: 0,
|
|
2626
|
-
});
|
|
2627
|
-
return {
|
|
2628
|
-
kind,
|
|
2629
|
-
value: Object.freeze({
|
|
2630
|
-
result: providerResult,
|
|
2631
|
-
outcome,
|
|
2632
|
-
}),
|
|
2633
|
-
durableOutcome,
|
|
2634
|
-
};
|
|
2635
|
-
}
|
|
2636
2395
|
function coerceResultContent(raw) {
|
|
2637
2396
|
if (typeof raw === 'string')
|
|
2638
2397
|
return { kind: 'text', text: raw };
|
|
@@ -2652,175 +2411,6 @@ function coerceResultContent(raw) {
|
|
|
2652
2411
|
}
|
|
2653
2412
|
return { kind: 'text', text: String(raw ?? '') };
|
|
2654
2413
|
}
|
|
2655
|
-
/**
|
|
2656
|
-
* Builds the one durable JSON representation while enforcing its byte budget.
|
|
2657
|
-
* The walk stops at the first over-budget token and never retains a mutable
|
|
2658
|
-
* tool/owner-owned object alias.
|
|
2659
|
-
*/
|
|
2660
|
-
const MANAGED_RESULT_MAX_BYTES = MANAGED_MUTATION_EXECUTION_PROFILE_V1_SPEC.resultSnapshot.maxBytes;
|
|
2661
|
-
const MANAGED_RESULT_MAX_DEPTH = MANAGED_MUTATION_EXECUTION_PROFILE_V1_SPEC.resultSnapshot.maxDepth;
|
|
2662
|
-
const MANAGED_RESULT_MAX_NODES = MANAGED_MUTATION_EXECUTION_PROFILE_V1_SPEC.resultSnapshot.maxNodes;
|
|
2663
|
-
const MANAGED_RESULT_MAX_PROPERTIES = MANAGED_MUTATION_EXECUTION_PROFILE_V1_SPEC.resultSnapshot.maxProperties;
|
|
2664
|
-
const MANAGED_RESULT_MAX_ARRAY_LENGTH = MANAGED_MUTATION_EXECUTION_PROFILE_V1_SPEC.resultSnapshot.maxArrayLength;
|
|
2665
|
-
function snapshotManagedToolResult(value, maxBytes) {
|
|
2666
|
-
const budget = {
|
|
2667
|
-
bytes: 0,
|
|
2668
|
-
limit: maxBytes === undefined
|
|
2669
|
-
? MANAGED_RESULT_MAX_BYTES
|
|
2670
|
-
: Number.isFinite(maxBytes) && maxBytes >= 0
|
|
2671
|
-
? Math.min(Math.floor(maxBytes), MANAGED_RESULT_MAX_BYTES)
|
|
2672
|
-
: 0,
|
|
2673
|
-
nodes: 0,
|
|
2674
|
-
properties: 0,
|
|
2675
|
-
active: new WeakSet(),
|
|
2676
|
-
};
|
|
2677
|
-
return snapshotStrictJsonValue(value, budget, '$', 0);
|
|
2678
|
-
}
|
|
2679
|
-
function snapshotStrictJsonValue(value, budget, path, depth) {
|
|
2680
|
-
budget.nodes += 1;
|
|
2681
|
-
if (budget.nodes > MANAGED_RESULT_MAX_NODES || depth > MANAGED_RESULT_MAX_DEPTH) {
|
|
2682
|
-
throw new ToolResultLimitError();
|
|
2683
|
-
}
|
|
2684
|
-
if (value === null) {
|
|
2685
|
-
consumeManagedResultBytes(budget, 4);
|
|
2686
|
-
return null;
|
|
2687
|
-
}
|
|
2688
|
-
if (typeof value === 'string') {
|
|
2689
|
-
consumeManagedJsonStringBytes(budget, value);
|
|
2690
|
-
return value;
|
|
2691
|
-
}
|
|
2692
|
-
if (typeof value === 'boolean') {
|
|
2693
|
-
consumeManagedResultBytes(budget, value ? 4 : 5);
|
|
2694
|
-
return value;
|
|
2695
|
-
}
|
|
2696
|
-
if (typeof value === 'number') {
|
|
2697
|
-
if (!Number.isFinite(value)) {
|
|
2698
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} is not finite`);
|
|
2699
|
-
}
|
|
2700
|
-
const canonical = Object.is(value, -0) ? 0 : value;
|
|
2701
|
-
consumeManagedResultBytes(budget, JSON.stringify(canonical).length);
|
|
2702
|
-
return canonical;
|
|
2703
|
-
}
|
|
2704
|
-
if (value === undefined) {
|
|
2705
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} is undefined`);
|
|
2706
|
-
}
|
|
2707
|
-
if (typeof value !== 'object') {
|
|
2708
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} has an unsupported type`);
|
|
2709
|
-
}
|
|
2710
|
-
if (budget.active.has(value)) {
|
|
2711
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} is cyclic`);
|
|
2712
|
-
}
|
|
2713
|
-
if (!Array.isArray(value)) {
|
|
2714
|
-
const prototype = Object.getPrototypeOf(value);
|
|
2715
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
2716
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} is not a plain object`);
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
if ('toJSON' in value) {
|
|
2720
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} defines toJSON`);
|
|
2721
|
-
}
|
|
2722
|
-
budget.active.add(value);
|
|
2723
|
-
try {
|
|
2724
|
-
if (Array.isArray(value)) {
|
|
2725
|
-
if (value.length > MANAGED_RESULT_MAX_ARRAY_LENGTH)
|
|
2726
|
-
throw new ToolResultLimitError();
|
|
2727
|
-
consumeManagedResultBytes(budget, 1);
|
|
2728
|
-
const output = [];
|
|
2729
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
2730
|
-
if (index > 0)
|
|
2731
|
-
consumeManagedResultBytes(budget, 1);
|
|
2732
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
2733
|
-
if (!descriptor) {
|
|
2734
|
-
throw new Error(`Managed tool result must be strict JSON: ${path} is a sparse array`);
|
|
2735
|
-
}
|
|
2736
|
-
if (!('value' in descriptor)) {
|
|
2737
|
-
throw new Error(`Managed tool result must be strict JSON: ${path}[${index}] is an accessor`);
|
|
2738
|
-
}
|
|
2739
|
-
output.push(snapshotStrictJsonValue(descriptor.value, budget, `${path}[${index}]`, depth + 1));
|
|
2740
|
-
}
|
|
2741
|
-
consumeManagedResultBytes(budget, 1);
|
|
2742
|
-
return Object.freeze(output);
|
|
2743
|
-
}
|
|
2744
|
-
consumeManagedResultBytes(budget, 1);
|
|
2745
|
-
const output = {};
|
|
2746
|
-
let emitted = 0;
|
|
2747
|
-
for (const key in value) {
|
|
2748
|
-
if (!Object.hasOwn(value, key))
|
|
2749
|
-
continue;
|
|
2750
|
-
budget.properties += 1;
|
|
2751
|
-
if (budget.properties > MANAGED_RESULT_MAX_PROPERTIES)
|
|
2752
|
-
throw new ToolResultLimitError();
|
|
2753
|
-
if (emitted > 0)
|
|
2754
|
-
consumeManagedResultBytes(budget, 1);
|
|
2755
|
-
consumeManagedJsonStringBytes(budget, key);
|
|
2756
|
-
consumeManagedResultBytes(budget, 1);
|
|
2757
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
2758
|
-
if (!descriptor || !('value' in descriptor)) {
|
|
2759
|
-
throw new Error(`Managed tool result must be strict JSON: ${path}.${key} is an accessor`);
|
|
2760
|
-
}
|
|
2761
|
-
Object.defineProperty(output, key, {
|
|
2762
|
-
configurable: true,
|
|
2763
|
-
enumerable: true,
|
|
2764
|
-
value: snapshotStrictJsonValue(descriptor.value, budget, `${path}.${key}`, depth + 1),
|
|
2765
|
-
writable: true,
|
|
2766
|
-
});
|
|
2767
|
-
emitted += 1;
|
|
2768
|
-
}
|
|
2769
|
-
consumeManagedResultBytes(budget, 1);
|
|
2770
|
-
return Object.freeze(output);
|
|
2771
|
-
}
|
|
2772
|
-
finally {
|
|
2773
|
-
budget.active.delete(value);
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
function consumeManagedJsonStringBytes(budget, value) {
|
|
2777
|
-
consumeManagedResultBytes(budget, 1);
|
|
2778
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
2779
|
-
const code = value.charCodeAt(index);
|
|
2780
|
-
let bytes;
|
|
2781
|
-
if (code === 0x22 ||
|
|
2782
|
-
code === 0x5c ||
|
|
2783
|
-
code === 0x08 ||
|
|
2784
|
-
code === 0x09 ||
|
|
2785
|
-
code === 0x0a ||
|
|
2786
|
-
code === 0x0c ||
|
|
2787
|
-
code === 0x0d) {
|
|
2788
|
-
bytes = 2;
|
|
2789
|
-
}
|
|
2790
|
-
else if (code <= 0x1f) {
|
|
2791
|
-
bytes = 6;
|
|
2792
|
-
}
|
|
2793
|
-
else if (code >= 0xd800 && code <= 0xdbff) {
|
|
2794
|
-
const next = value.charCodeAt(index + 1);
|
|
2795
|
-
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
2796
|
-
bytes = 4;
|
|
2797
|
-
index += 1;
|
|
2798
|
-
}
|
|
2799
|
-
else {
|
|
2800
|
-
bytes = 6;
|
|
2801
|
-
}
|
|
2802
|
-
}
|
|
2803
|
-
else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
2804
|
-
bytes = 6;
|
|
2805
|
-
}
|
|
2806
|
-
else if (code <= 0x7f) {
|
|
2807
|
-
bytes = 1;
|
|
2808
|
-
}
|
|
2809
|
-
else if (code <= 0x7ff) {
|
|
2810
|
-
bytes = 2;
|
|
2811
|
-
}
|
|
2812
|
-
else {
|
|
2813
|
-
bytes = 3;
|
|
2814
|
-
}
|
|
2815
|
-
consumeManagedResultBytes(budget, bytes);
|
|
2816
|
-
}
|
|
2817
|
-
consumeManagedResultBytes(budget, 1);
|
|
2818
|
-
}
|
|
2819
|
-
function consumeManagedResultBytes(budget, bytes) {
|
|
2820
|
-
if (budget.bytes > budget.limit - bytes)
|
|
2821
|
-
throw new ToolResultLimitError();
|
|
2822
|
-
budget.bytes += bytes;
|
|
2823
|
-
}
|
|
2824
2414
|
function coerceTerminalFailure(tool, cwd, args, err) {
|
|
2825
2415
|
if (tool.name !== 'Bash' || !err || typeof err !== 'object')
|
|
2826
2416
|
return null;
|
|
@@ -2830,14 +2420,14 @@ function coerceTerminalFailure(tool, cwd, args, err) {
|
|
|
2830
2420
|
const command = args && typeof args === 'object' && typeof args.command === 'string'
|
|
2831
2421
|
? args.command
|
|
2832
2422
|
: '';
|
|
2833
|
-
const stdout =
|
|
2834
|
-
const stderr =
|
|
2423
|
+
const stdout = String(error.stdout ?? '');
|
|
2424
|
+
const stderr = String(error.stderr ?? '');
|
|
2835
2425
|
const sandboxDenied = error.reason === 'sandbox_denial' && error.sandboxed === true;
|
|
2836
2426
|
return {
|
|
2837
2427
|
content: {
|
|
2838
2428
|
kind: 'terminal',
|
|
2839
2429
|
cwd,
|
|
2840
|
-
cmd:
|
|
2430
|
+
cmd: command,
|
|
2841
2431
|
status: error.code === 124 ? 'timed_out' : error.code === 130 ? 'cancelled' : 'failed',
|
|
2842
2432
|
exitCode: error.code,
|
|
2843
2433
|
output: {
|
|
@@ -2846,7 +2436,7 @@ function coerceTerminalFailure(tool, cwd, args, err) {
|
|
|
2846
2436
|
stderr,
|
|
2847
2437
|
stdoutTruncated: error.stdoutTruncated === true,
|
|
2848
2438
|
stderrTruncated: error.stderrTruncated === true,
|
|
2849
|
-
redacted:
|
|
2439
|
+
redacted: false,
|
|
2850
2440
|
},
|
|
2851
2441
|
...(sandboxDenied
|
|
2852
2442
|
? {
|
|
@@ -2993,15 +2583,6 @@ function isAmbiguousComputerFailure(raw) {
|
|
|
2993
2583
|
function durableAttemptKey(turnId, toolUseId) {
|
|
2994
2584
|
return JSON.stringify([turnId, toolUseId]);
|
|
2995
2585
|
}
|
|
2996
|
-
async function disposeManagedMutationAdmission(admission) {
|
|
2997
|
-
try {
|
|
2998
|
-
await admission?.dispose();
|
|
2999
|
-
}
|
|
3000
|
-
catch {
|
|
3001
|
-
// Cleanup is best-effort. It must never rewrite a durable terminal outcome,
|
|
3002
|
-
// nor obscure the primary pre-T1 or execution failure.
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
2586
|
function providerToolErrorMessage(output) {
|
|
3006
2587
|
if (!output || typeof output !== 'object' || Array.isArray(output))
|
|
3007
2588
|
return undefined;
|