maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.25.20260908
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/README.md +38 -19
- package/README.zh-CN.md +34 -19
- package/dist/acp/maka-acp-agent.js +2 -1
- package/dist/acp/session-configuration.js +143 -0
- package/dist/acp/session-registry.js +90 -4
- package/dist/cli-core.js +2 -0
- package/dist/pi-transcript-tools.js +6 -0
- package/dist/pi-transcript.js +5 -12
- package/dist/pi-tui-layout.js +56 -10
- package/dist/pi-tui-pickers.js +102 -1
- package/dist/pi-tui-runner.js +230 -46
- package/dist/pi-tui-todo.js +221 -0
- package/dist/pi-tui-transcript-viewer.js +134 -7
- package/dist/runtime-host-cli-context.js +224 -78
- package/dist/runtime-host-cli-installation.js +8 -2
- package/dist/runtime-host-cli.js +31 -1
- package/dist/runtime-host-handoff-surface.js +106 -0
- package/dist/runtime-host-installed-update-bootstrap.js +13 -0
- package/dist/runtime-host-installed-update-coordinator.js +33 -0
- package/dist/runtime-host-lifecycle-transaction.js +9 -1
- package/dist/runtime-host-local-handoff.js +48 -5
- package/dist/runtime-host-local-managed-activation.js +84 -0
- package/dist/runtime-host-local-source-retirement.js +18 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-operator-retirement.js +50 -0
- package/dist/runtime-host-service-manager.js +3 -3
- package/dist/runtime-host-session-channel.js +13 -0
- package/dist/runtime-host-session-driver.js +46 -26
- package/dist/runtime-host-session-update.js +62 -0
- package/dist/runtime-host-tui-command.js +38 -73
- package/dist/runtime-host-tui-context.js +1 -0
- package/dist/runtime-host-tui-owner.js +226 -0
- package/dist/tui-copy-catalog.js +219 -6
- package/dist/tui-host-owner-copy.js +24 -0
- 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-run.js +1 -0
- package/node_modules/@maka/core/dist/attachments.js +3 -0
- package/node_modules/@maka/core/dist/canonical-json.js +27 -0
- package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
- package/node_modules/@maka/core/dist/capabilities.js +35 -0
- package/node_modules/@maka/core/dist/computer-use.js +0 -1
- package/node_modules/@maka/core/dist/display-redaction.js +18 -0
- package/node_modules/@maka/core/dist/llm-connections.js +13 -0
- package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
- package/node_modules/@maka/core/dist/model-failure.js +40 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
- package/node_modules/@maka/core/dist/model-metadata.js +7 -3
- package/node_modules/@maka/core/dist/model-web-search.js +5 -4
- package/node_modules/@maka/core/dist/provider-registry.js +45 -4
- package/node_modules/@maka/core/dist/record-schema.js +9 -2
- package/node_modules/@maka/core/dist/redaction.js +35 -0
- package/node_modules/@maka/core/dist/run-composition.js +77 -2
- package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
- package/node_modules/@maka/core/dist/runtime-event.js +37 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
- package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
- package/node_modules/@maka/core/dist/session.js +84 -56
- package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
- package/node_modules/@maka/core/package.json +5 -0
- package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
- package/node_modules/@maka/mcp/dist/index.js +131 -1
- package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
- package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
- package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
- package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
- package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
- package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
- package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
- package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
- package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
- package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
- package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
- package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
- package/node_modules/@maka/runtime/dist/model-history.js +0 -112
- package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
- package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
- package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
- package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
- package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
- package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
- package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
- package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
- package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
- package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
- package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
- package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
- package/node_modules/@maka/runtime/package.json +2 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
- package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
- package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
- package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
- package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
- package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
- package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
- package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
- package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
- 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 +325 -73
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
- package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
- package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
- package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
- package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
- package/node_modules/@maka/storage/dist/git-exec.js +61 -0
- package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
- package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
- package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
- package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
- package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
- package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
- package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
- package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
- package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
- package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
- package/node_modules/@maka/storage/dist/session-repository.js +767 -0
- package/node_modules/@maka/storage/dist/session-store.js +25 -99
- package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
- package/node_modules/@maka/storage/dist/storage-id.js +28 -0
- package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
- package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
- package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* One physical Run owns one gate. Before commit, cancellation resumes that same
|
|
21
|
+
* Run without a terminal fact. Durable pause/continuation authority lives in the
|
|
22
|
+
* ledger, never in this in-memory gate.
|
|
23
|
+
*/
|
|
24
|
+
export class RunHandoffGate {
|
|
25
|
+
#pending;
|
|
26
|
+
#closed = false;
|
|
27
|
+
request(signal) {
|
|
28
|
+
if (this.#pending)
|
|
29
|
+
throw new Error('This Run already has a handoff reservation');
|
|
30
|
+
if (this.#closed || signal.aborted) {
|
|
31
|
+
return { ready: Promise.resolve(false), commit: () => false, cancel() { } };
|
|
32
|
+
}
|
|
33
|
+
let markReached;
|
|
34
|
+
let releaseBoundary;
|
|
35
|
+
const cancel = () => {
|
|
36
|
+
this.#settle(pending, 'continue');
|
|
37
|
+
};
|
|
38
|
+
const pending = {
|
|
39
|
+
reached: new Promise((resolve) => {
|
|
40
|
+
markReached = resolve;
|
|
41
|
+
}),
|
|
42
|
+
release: new Promise((resolve) => {
|
|
43
|
+
releaseBoundary = resolve;
|
|
44
|
+
}),
|
|
45
|
+
markReached: (ready) => markReached(ready),
|
|
46
|
+
releaseBoundary: (decision) => releaseBoundary(decision),
|
|
47
|
+
cleanup: () => signal.removeEventListener('abort', cancel),
|
|
48
|
+
atBoundary: false,
|
|
49
|
+
};
|
|
50
|
+
this.#pending = pending;
|
|
51
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
52
|
+
return {
|
|
53
|
+
ready: pending.reached,
|
|
54
|
+
commit: () => pending.atBoundary && this.#settle(pending, 'pause'),
|
|
55
|
+
cancel,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Called only after the preceding step's events and tool outcomes are durable. */
|
|
59
|
+
async reachBoundary(executionSignal) {
|
|
60
|
+
const pending = this.#pending;
|
|
61
|
+
if (!pending)
|
|
62
|
+
return 'continue';
|
|
63
|
+
const abort = () => {
|
|
64
|
+
this.#settle(pending, 'continue');
|
|
65
|
+
};
|
|
66
|
+
if (executionSignal.aborted) {
|
|
67
|
+
abort();
|
|
68
|
+
return 'continue';
|
|
69
|
+
}
|
|
70
|
+
executionSignal.addEventListener('abort', abort, { once: true });
|
|
71
|
+
pending.atBoundary = true;
|
|
72
|
+
pending.markReached(true);
|
|
73
|
+
try {
|
|
74
|
+
return await pending.release;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
executionSignal.removeEventListener('abort', abort);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Natural completion, user Stop, or failure must never leave a waiter behind. */
|
|
81
|
+
close() {
|
|
82
|
+
this.#closed = true;
|
|
83
|
+
if (this.#pending)
|
|
84
|
+
this.#settle(this.#pending, 'continue');
|
|
85
|
+
}
|
|
86
|
+
#settle(pending, decision) {
|
|
87
|
+
if (this.#pending !== pending)
|
|
88
|
+
return false;
|
|
89
|
+
this.#pending = undefined;
|
|
90
|
+
if (decision === 'pause')
|
|
91
|
+
this.#closed = true;
|
|
92
|
+
pending.cleanup();
|
|
93
|
+
pending.markReached(false);
|
|
94
|
+
pending.releaseBoundary(decision);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { isRuntimeSystemNoteKind } from '@maka/core/session';
|
|
19
20
|
import { createRuntimeEventId } from '@maka/core/runtime-event';
|
|
20
|
-
|
|
21
|
+
const RUNTIME_EVENT_BACKFILL_STATE_KEY = 'makaRuntimeRecovery';
|
|
21
22
|
export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
22
23
|
const newId = input.newId ?? (() => createRuntimeEventId('rt-backfill'));
|
|
23
24
|
const now = input.now ?? (() => Date.now());
|
|
@@ -115,13 +116,16 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
115
116
|
case 'tool_call': {
|
|
116
117
|
if (conversationTextOnly)
|
|
117
118
|
break;
|
|
118
|
-
|
|
119
|
+
// A provider-native call whose opaque output was not retained can never
|
|
120
|
+
// be replayed to a provider again, so it is converted hidden: the
|
|
121
|
+
// transcript keeps the card, and no model request is built from it.
|
|
122
|
+
const unreplayable = message.providerExecuted === true && !replayableProviderToolUseIds.has(message.id);
|
|
123
|
+
if (unreplayable) {
|
|
119
124
|
diagnostics.push({
|
|
120
125
|
code: 'skipped_provider_native_replay_gap',
|
|
121
126
|
message: 'provider-native tool history requires the opaque provider output for lossless recovery',
|
|
122
127
|
detail: { messageId: message.id, toolUseId: message.id },
|
|
123
128
|
});
|
|
124
|
-
break;
|
|
125
129
|
}
|
|
126
130
|
const stateDelta = toolCallStateDelta(message);
|
|
127
131
|
events.push({
|
|
@@ -130,6 +134,7 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
130
134
|
role: 'model',
|
|
131
135
|
author: 'agent',
|
|
132
136
|
...storedToolActivityIdentity(message),
|
|
137
|
+
...(unreplayable ? { modelVisibility: 'hidden' } : {}),
|
|
133
138
|
content: {
|
|
134
139
|
kind: 'function_call',
|
|
135
140
|
id: message.id,
|
|
@@ -163,14 +168,16 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
163
168
|
case 'tool_result': {
|
|
164
169
|
if (conversationTextOnly)
|
|
165
170
|
break;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
171
|
+
// Same rule as the call it answers: a result the provider cannot be
|
|
172
|
+
// shown again is kept as a transcript row and hidden from replay. A
|
|
173
|
+
// result whose call is not in this turn is hidden for the same reason —
|
|
174
|
+
// a lone result is not a request a provider would accept.
|
|
169
175
|
const call = safePriorToolCall(toolCalls, message);
|
|
176
|
+
const unreplayable = !call || (message.providerExecuted === true && message.providerOutput === undefined);
|
|
170
177
|
if (!call) {
|
|
171
178
|
diagnostics.push({
|
|
172
179
|
code: 'skipped_unmatched_tool_result',
|
|
173
|
-
message: 'tool_result
|
|
180
|
+
message: 'tool_result has no earlier same-turn tool_call, so its RuntimeEvent stays out of model replay',
|
|
174
181
|
detail: {
|
|
175
182
|
messageId: message.id,
|
|
176
183
|
toolUseId: message.toolUseId,
|
|
@@ -178,18 +185,18 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
178
185
|
turnId: input.run.turnId,
|
|
179
186
|
},
|
|
180
187
|
});
|
|
181
|
-
break;
|
|
182
188
|
}
|
|
183
189
|
events.push({
|
|
184
190
|
...base,
|
|
185
191
|
id: newId(),
|
|
186
192
|
role: 'tool',
|
|
187
193
|
author: 'tool',
|
|
188
|
-
...storedToolActivityIdentity(call),
|
|
194
|
+
...storedToolActivityIdentity(call ?? message),
|
|
195
|
+
...(unreplayable ? { modelVisibility: 'hidden' } : {}),
|
|
189
196
|
content: {
|
|
190
197
|
kind: 'function_response',
|
|
191
198
|
id: message.toolUseId,
|
|
192
|
-
name: call
|
|
199
|
+
name: call?.toolName ?? '',
|
|
193
200
|
result: message.content,
|
|
194
201
|
isError: message.isError,
|
|
195
202
|
...(message.providerExecuted !== undefined
|
|
@@ -205,33 +212,22 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
205
212
|
refs: {
|
|
206
213
|
storedMessageId: message.id,
|
|
207
214
|
toolCallId: message.toolUseId,
|
|
208
|
-
...(call
|
|
215
|
+
...(call?.parentToolCallId !== undefined
|
|
209
216
|
? { parentToolCallId: call.parentToolCallId }
|
|
210
217
|
: {}),
|
|
211
|
-
...(call
|
|
218
|
+
...(call?.parentOperationId !== undefined
|
|
212
219
|
? { parentOperationId: call.parentOperationId }
|
|
213
220
|
: {}),
|
|
214
221
|
},
|
|
215
222
|
});
|
|
216
223
|
break;
|
|
217
224
|
}
|
|
218
|
-
|
|
225
|
+
// The decision names the tool it answered for, so it converts on its own
|
|
226
|
+
// evidence; a matching call in the same turn is confirmation, not a
|
|
227
|
+
// requirement.
|
|
228
|
+
case 'permission_decision':
|
|
219
229
|
if (conversationTextOnly)
|
|
220
230
|
break;
|
|
221
|
-
const call = safePriorToolCall(toolCalls, message);
|
|
222
|
-
if (!call) {
|
|
223
|
-
diagnostics.push({
|
|
224
|
-
code: 'skipped_unmatched_permission_decision',
|
|
225
|
-
message: 'permission_decision requires an earlier same-turn tool_call to recover RuntimeEvent permissionDecision',
|
|
226
|
-
detail: {
|
|
227
|
-
messageId: message.id,
|
|
228
|
-
toolUseId: message.toolUseId,
|
|
229
|
-
runId: input.run.runId,
|
|
230
|
-
turnId: input.run.turnId,
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
231
|
events.push({
|
|
236
232
|
...base,
|
|
237
233
|
id: newId(),
|
|
@@ -242,15 +238,19 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
242
238
|
permissionDecision: {
|
|
243
239
|
requestId: message.id,
|
|
244
240
|
decision: message.decision,
|
|
241
|
+
toolName: message.toolName,
|
|
245
242
|
...(message.rememberForTurn !== undefined
|
|
246
243
|
? { rememberForTurn: message.rememberForTurn }
|
|
247
244
|
: {}),
|
|
245
|
+
...(message.reviewer !== undefined ? { reviewer: message.reviewer } : {}),
|
|
246
|
+
...(message.rationale !== undefined ? { rationale: message.rationale } : {}),
|
|
247
|
+
...(message.riskLevel !== undefined ? { riskLevel: message.riskLevel } : {}),
|
|
248
|
+
...(message.hint !== undefined ? { hint: message.hint } : {}),
|
|
248
249
|
},
|
|
249
250
|
},
|
|
250
|
-
refs: { storedMessageId: message.id, toolCallId:
|
|
251
|
+
refs: { storedMessageId: message.id, toolCallId: message.toolUseId },
|
|
251
252
|
});
|
|
252
253
|
break;
|
|
253
|
-
}
|
|
254
254
|
case 'token_usage':
|
|
255
255
|
if (conversationTextOnly)
|
|
256
256
|
break;
|
|
@@ -271,20 +271,44 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
271
271
|
},
|
|
272
272
|
});
|
|
273
273
|
break;
|
|
274
|
+
// Both are already accounted for elsewhere: the turn's ending becomes the
|
|
275
|
+
// terminal RuntimeEvent below, and a coordination record is the WorkHub's
|
|
276
|
+
// own durable proof, which no run ledger owns a copy of.
|
|
274
277
|
case 'turn_state':
|
|
278
|
+
case 'workhub_coordination':
|
|
275
279
|
break;
|
|
280
|
+
// A note that names a turn is that invocation's own fact, so it converts.
|
|
281
|
+
// A session-level kind that somehow carries a turnId is not: it says
|
|
282
|
+
// something about the Session, and the Session transcript keeps it.
|
|
276
283
|
case 'system_note':
|
|
277
284
|
if (conversationTextOnly)
|
|
278
285
|
break;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
if (!isRuntimeSystemNoteKind(message.kind)) {
|
|
287
|
+
diagnostics.push({
|
|
288
|
+
code: 'skipped_high_risk_message',
|
|
289
|
+
message: 'session-level system_note is not recovered into a run ledger because it does not belong to this run',
|
|
290
|
+
detail: {
|
|
291
|
+
messageId: message.id,
|
|
292
|
+
kind: message.kind,
|
|
293
|
+
runId: input.run.runId,
|
|
294
|
+
turnId: input.run.turnId,
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
events.push({
|
|
300
|
+
...base,
|
|
301
|
+
id: newId(),
|
|
302
|
+
role: 'system',
|
|
303
|
+
author: 'system',
|
|
304
|
+
modelVisibility: 'hidden',
|
|
305
|
+
content: {
|
|
306
|
+
kind: 'system_note',
|
|
307
|
+
note: message.kind,
|
|
308
|
+
...(message.data !== undefined ? { data: structuredClone(message.data) } : {}),
|
|
287
309
|
},
|
|
310
|
+
actions: { stateDelta: recoveryState(now, message) },
|
|
311
|
+
refs: { storedMessageId: message.id },
|
|
288
312
|
});
|
|
289
313
|
break;
|
|
290
314
|
}
|
|
@@ -297,12 +321,10 @@ export function backfillRuntimeEventsFromStoredMessages(input) {
|
|
|
297
321
|
newId,
|
|
298
322
|
now,
|
|
299
323
|
});
|
|
300
|
-
if (terminal.event)
|
|
324
|
+
if (terminal.event)
|
|
301
325
|
events.push(terminal.event);
|
|
302
|
-
|
|
303
|
-
else if (terminal.diagnostic) {
|
|
326
|
+
if (terminal.diagnostic)
|
|
304
327
|
diagnostics.push(terminal.diagnostic);
|
|
305
|
-
}
|
|
306
328
|
return { events, diagnostics };
|
|
307
329
|
}
|
|
308
330
|
function storedToolActivityIdentity(message) {
|
|
@@ -346,23 +368,28 @@ function terminalRecoveryState(now, message) {
|
|
|
346
368
|
}
|
|
347
369
|
function terminalRuntimeEvent(input) {
|
|
348
370
|
const turnState = latestTurnState(input.turnMessages);
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
371
|
+
const readStatus = terminalStatus(input.outcome, turnState);
|
|
372
|
+
// An invocation with no ending is not a legal ledger state, and leaving one
|
|
373
|
+
// open would strand the turn in recovery forever. Incomplete legacy evidence
|
|
374
|
+
// does not get to claim the turn completed, so it ends as the failure it
|
|
375
|
+
// actually was, marked so a reader can tell it apart from a recorded one.
|
|
376
|
+
const status = readStatus ?? 'failed';
|
|
377
|
+
const diagnostic = readStatus
|
|
378
|
+
? undefined
|
|
379
|
+
: {
|
|
380
|
+
code: 'synthesized_terminal_event',
|
|
381
|
+
message: 'terminal RuntimeEvent was synthesized because legacy terminal evidence is incomplete',
|
|
382
|
+
detail: {
|
|
383
|
+
runId: input.run.runId,
|
|
384
|
+
turnId: input.run.turnId,
|
|
385
|
+
declaredStatus: input.outcome?.status,
|
|
386
|
+
turnStatus: turnState?.status,
|
|
361
387
|
},
|
|
362
388
|
};
|
|
363
|
-
}
|
|
364
389
|
const ts = turnState?.ts ?? input.outcome?.ts ?? input.now();
|
|
365
|
-
const failureClass = status === 'failed'
|
|
390
|
+
const failureClass = status === 'failed'
|
|
391
|
+
? (turnState?.errorClass ?? input.outcome?.failureClass ?? 'missing_terminal_event')
|
|
392
|
+
: undefined;
|
|
366
393
|
const abortSource = status === 'aborted'
|
|
367
394
|
? (turnState?.abortSource ??
|
|
368
395
|
input.outcome?.abortSource ??
|
|
@@ -390,6 +417,7 @@ function terminalRuntimeEvent(input) {
|
|
|
390
417
|
},
|
|
391
418
|
...(turnState ? { refs: { storedMessageId: turnState.id } } : {}),
|
|
392
419
|
},
|
|
420
|
+
...(diagnostic ? { diagnostic } : {}),
|
|
393
421
|
};
|
|
394
422
|
}
|
|
395
423
|
function terminalStatus(outcome, turnState) {
|