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,20 @@
|
|
|
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
|
+
export const TOOL_RESULT_ARCHIVE_EVIDENCE_MAX_TRANSITIONS = 64;
|
|
20
|
+
export const TOOL_RESULT_ARCHIVE_EVIDENCE_MAX_BYTES = 2 * 1024 * 1024;
|
|
@@ -37,7 +37,7 @@ const ARCHIVED_SHAPE = defineObjectShape()([
|
|
|
37
37
|
'originalBytes',
|
|
38
38
|
'rewriteVersion',
|
|
39
39
|
'reason',
|
|
40
|
-
], ['artifactId', 'bodySha256']);
|
|
40
|
+
], ['artifactId', 'resourceRef', 'bodySha256']);
|
|
41
41
|
const IMAGE_SHAPE = defineObjectShape()(['kind', 'mimeType', 'ref'], []);
|
|
42
42
|
const SUMMARY_SHAPE = defineObjectShape()(['kind', 'original', 'summarized', 'reason'], []);
|
|
43
43
|
const WEB_SEARCH_SHAPE = defineObjectShape()(['kind', 'provider', 'query', 'rows'], []);
|
|
@@ -157,6 +157,7 @@ function isNonShellToolResultContent(value) {
|
|
|
157
157
|
typeof value.toolCallId === 'string' &&
|
|
158
158
|
typeof value.toolName === 'string' &&
|
|
159
159
|
isOptionalString(value.artifactId) &&
|
|
160
|
+
isOptionalString(value.resourceRef) &&
|
|
160
161
|
isOptionalString(value.bodySha256) &&
|
|
161
162
|
isFiniteNumber(value.originalEstimatedTokens) &&
|
|
162
163
|
isFiniteNumber(value.originalBytes) &&
|
|
@@ -44,30 +44,6 @@ const COMPACTION_DECISION_SHAPE = defineObjectShape()(['stage', 'sourceKind', 'd
|
|
|
44
44
|
'skippedReasonCounts',
|
|
45
45
|
'validationReasonCounts',
|
|
46
46
|
]);
|
|
47
|
-
const CURRENT_CONTEXT_BUDGET_SHAPE = defineObjectShape()([
|
|
48
|
-
'enabled',
|
|
49
|
-
'estimatedTokensBefore',
|
|
50
|
-
'estimatedTokensAfter',
|
|
51
|
-
'keptTurns',
|
|
52
|
-
'droppedTurns',
|
|
53
|
-
'keptEvents',
|
|
54
|
-
'droppedEvents',
|
|
55
|
-
], [
|
|
56
|
-
'policyName',
|
|
57
|
-
'prunedToolResults',
|
|
58
|
-
'prunedToolResultEstimatedTokensBefore',
|
|
59
|
-
'prunedToolResultEstimatedTokensAfter',
|
|
60
|
-
'archivePlaceholders',
|
|
61
|
-
'archiveWriteFailures',
|
|
62
|
-
'unarchivedToolResults',
|
|
63
|
-
'archivePlaceholderReasonCounts',
|
|
64
|
-
'activePrunedToolResults',
|
|
65
|
-
'activeSupersededToolResults',
|
|
66
|
-
'activeDuplicateToolResults',
|
|
67
|
-
'activeArchiveFailures',
|
|
68
|
-
'activeEstimatedTokensSaved',
|
|
69
|
-
'compactionDecisions',
|
|
70
|
-
]);
|
|
71
47
|
/**
|
|
72
48
|
* Keys written by retired context-budget implementations. They remain
|
|
73
49
|
* accepted only so persisted usage records stay readable; current code cannot
|
|
@@ -145,10 +121,30 @@ const RETIRED_CONTEXT_BUDGET_KEYS = [
|
|
|
145
121
|
'historyRewriteResetReason',
|
|
146
122
|
'historyRewriteGate',
|
|
147
123
|
];
|
|
148
|
-
const CONTEXT_BUDGET_SHAPE =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
124
|
+
const CONTEXT_BUDGET_SHAPE = defineObjectShape()([
|
|
125
|
+
'enabled',
|
|
126
|
+
'estimatedTokensBefore',
|
|
127
|
+
'estimatedTokensAfter',
|
|
128
|
+
'keptTurns',
|
|
129
|
+
'droppedTurns',
|
|
130
|
+
'keptEvents',
|
|
131
|
+
'droppedEvents',
|
|
132
|
+
], [
|
|
133
|
+
'policyName',
|
|
134
|
+
'prunedToolResults',
|
|
135
|
+
'prunedToolResultEstimatedTokensBefore',
|
|
136
|
+
'prunedToolResultEstimatedTokensAfter',
|
|
137
|
+
'archivePlaceholders',
|
|
138
|
+
'archiveWriteFailures',
|
|
139
|
+
'unarchivedToolResults',
|
|
140
|
+
'archivePlaceholderReasonCounts',
|
|
141
|
+
'activePrunedToolResults',
|
|
142
|
+
'activeSupersededToolResults',
|
|
143
|
+
'activeDuplicateToolResults',
|
|
144
|
+
'activeArchiveFailures',
|
|
145
|
+
'activeEstimatedTokensSaved',
|
|
146
|
+
'compactionDecisions',
|
|
147
|
+
], RETIRED_CONTEXT_BUDGET_KEYS);
|
|
152
148
|
const PROMPT_SEGMENT_KINDS = new Set([
|
|
153
149
|
'system_prompt',
|
|
154
150
|
'tool_schema',
|
|
@@ -213,15 +209,10 @@ const CONTEXT_NUMBERS = [
|
|
|
213
209
|
'activeEstimatedTokensSaved',
|
|
214
210
|
];
|
|
215
211
|
const CONTEXT_REASON_COUNTS = ['archivePlaceholderReasonCounts'];
|
|
216
|
-
const LAST_REQUEST_ANCHOR_SHAPE = defineObjectShape()(['inputTokens'], ['outputTokens', 'modelId', 'connectionId']);
|
|
217
|
-
const RETIRED_LAST_REQUEST_ANCHOR_KEYS = ['payloadChars'];
|
|
218
|
-
const LAST_REQUEST_ANCHOR_DECODE_SHAPE = {
|
|
219
|
-
required: LAST_REQUEST_ANCHOR_SHAPE.required,
|
|
220
|
-
allowed: new Set([...LAST_REQUEST_ANCHOR_SHAPE.allowed, ...RETIRED_LAST_REQUEST_ANCHOR_KEYS]),
|
|
221
|
-
};
|
|
212
|
+
const LAST_REQUEST_ANCHOR_SHAPE = defineObjectShape()(['inputTokens'], ['outputTokens', 'modelId', 'connectionId'], ['payloadChars']);
|
|
222
213
|
export function isLastRequestAnchor(value) {
|
|
223
214
|
return (isRecord(value) &&
|
|
224
|
-
hasExactShape(value,
|
|
215
|
+
hasExactShape(value, LAST_REQUEST_ANCHOR_SHAPE) &&
|
|
225
216
|
isFiniteNumber(value.inputTokens) &&
|
|
226
217
|
value.inputTokens > 0 &&
|
|
227
218
|
(value.outputTokens === undefined ||
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
"./durable-tool-result-projection": "./dist/durable-tool-result-projection.js",
|
|
10
10
|
"./model-projection-transition": "./dist/model-projection-transition.js",
|
|
11
11
|
"./canonical-runtime-event": "./dist/canonical-runtime-event.js",
|
|
12
|
+
"./canonical-json": "./dist/canonical-json.js",
|
|
12
13
|
"./runtime-boundary": "./dist/runtime-boundary.js",
|
|
14
|
+
"./runtime-handoff": "./dist/runtime-handoff.js",
|
|
15
|
+
"./runtime-logical-execution": "./dist/runtime-logical-execution.js",
|
|
13
16
|
"./runtime-event": "./dist/runtime-event.js",
|
|
14
17
|
"./tool-args-identity": "./dist/tool-args-identity.js",
|
|
15
18
|
"./tool-ledger-scanner": "./dist/tool-ledger-scanner.js",
|
|
@@ -34,6 +37,7 @@
|
|
|
34
37
|
"./plan": "./dist/plan.js",
|
|
35
38
|
"./agent-run": "./dist/agent-run.js",
|
|
36
39
|
"./subagent-workspace": "./dist/subagent-workspace.js",
|
|
40
|
+
"./model-failure": "./dist/model-failure.js",
|
|
37
41
|
"./model-call-attempt": "./dist/model-call-attempt.js",
|
|
38
42
|
"./model-call-usage-projection": "./dist/model-call-usage-projection.js",
|
|
39
43
|
"./usage-ledger-merge": "./dist/usage-ledger-merge.js",
|
|
@@ -51,6 +55,7 @@
|
|
|
51
55
|
"./user-question": "./dist/user-question.js",
|
|
52
56
|
"./connections": "./dist/connections.js",
|
|
53
57
|
"./context-offload": "./dist/context-offload.js",
|
|
58
|
+
"./tool-result-archive-evidence": "./dist/tool-result-archive-evidence.js",
|
|
54
59
|
"./attachments": "./dist/attachments.js",
|
|
55
60
|
"./artifacts": "./dist/artifacts.js",
|
|
56
61
|
"./pet": "./dist/pet.js",
|
|
@@ -19,13 +19,14 @@
|
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
20
|
import { link, mkdir, open, readFile, unlink } from 'node:fs/promises';
|
|
21
21
|
import { join } from 'node:path';
|
|
22
|
+
import { stableJsonStringify } from '@maka/core/canonical-json';
|
|
22
23
|
import { FileAttemptStore } from './attempt-store.js';
|
|
23
24
|
import { parseExperimentSpec } from './spec.js';
|
|
24
25
|
export async function openExperimentDirectory(root, spec) {
|
|
25
26
|
await mkdir(root, { recursive: true });
|
|
26
27
|
const specPath = join(root, 'experiment.json');
|
|
27
28
|
const temporaryPath = join(root, `.experiment-${randomUUID()}.tmp`);
|
|
28
|
-
const canonical = `${
|
|
29
|
+
const canonical = `${stableJsonStringify(spec)}\n`;
|
|
29
30
|
const temporary = await open(temporaryPath, 'wx', 0o600);
|
|
30
31
|
try {
|
|
31
32
|
await temporary.writeFile(canonical);
|
|
@@ -37,8 +38,9 @@ export async function openExperimentDirectory(root, spec) {
|
|
|
37
38
|
if (error.code !== 'EEXIST')
|
|
38
39
|
throw error;
|
|
39
40
|
const existing = parseExperimentSpec(JSON.parse(await readFile(specPath, 'utf8')));
|
|
40
|
-
if (
|
|
41
|
+
if (stableJsonStringify(existing) !== stableJsonStringify(spec)) {
|
|
41
42
|
throw new Error('experiment spec differs');
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
finally {
|
|
44
46
|
await temporary.close().catch(() => undefined);
|
|
@@ -46,14 +48,3 @@ export async function openExperimentDirectory(root, spec) {
|
|
|
46
48
|
}
|
|
47
49
|
return { root, specPath, attempts: new FileAttemptStore(join(root, 'attempts')) };
|
|
48
50
|
}
|
|
49
|
-
function canonicalJson(value) {
|
|
50
|
-
if (Array.isArray(value))
|
|
51
|
-
return `[${value.map(canonicalJson).join(',')}]`;
|
|
52
|
-
if (value && typeof value === 'object') {
|
|
53
|
-
return `{${Object.entries(value)
|
|
54
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
55
|
-
.map(([key, child]) => `${JSON.stringify(key)}:${canonicalJson(child)}`)
|
|
56
|
-
.join(',')}}`;
|
|
57
|
-
}
|
|
58
|
-
return JSON.stringify(value);
|
|
59
|
-
}
|
|
@@ -20,6 +20,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
20
20
|
import { auth, Client, extractWWWAuthenticateParams, LATEST_PROTOCOL_VERSION, SdkErrorCode, SdkHttpError, SSEClientTransport, StreamableHTTPClientTransport, } from '@modelcontextprotocol/client';
|
|
21
21
|
import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
|
|
22
22
|
import { redactSecrets } from '@maka/core/redaction';
|
|
23
|
+
import { serializedByteLength } from '@maka/core/serialized-byte-length';
|
|
23
24
|
import { deepScrubMcpSecrets, EMPTY_MCP_SECRET_INVENTORY, MCP_SECRET_MIN_SUBSTITUTION_LENGTH, mcpSecretInventory, scrubKnownMcpSecrets, } from '@maka/core/mcp-secrets';
|
|
24
25
|
import { isMcpStdioConfig, mcpConfigChangeRetiresCredentials, resolveMcpProtocolPreference, } from '@maka/core/mcp';
|
|
25
26
|
import { formatMcpDiagnosticText, MCP_DIAGNOSTIC_INPUT_CODE_UNITS, MCP_ERROR_DIAGNOSTIC_CODE_POINTS, } from './diagnostic-text.js';
|
|
@@ -47,6 +48,10 @@ const STDERR_OVERSIZED_LINE = '[stderr line omitted: exceeds diagnostic limit]';
|
|
|
47
48
|
const STDERR_CONTINUATION = '[stderr continuation omitted]';
|
|
48
49
|
const MAX_SUMMARIZED_ERROR_BLOCKS = 100;
|
|
49
50
|
const OVERSIZED_TOOL_ERROR_CONTENT = 'server returned oversized error content';
|
|
51
|
+
const MAX_SUCCESS_TOOL_RESULT_CONTENT_BLOCKS = 256;
|
|
52
|
+
const MAX_SUCCESS_TOOL_RESULT_BYTES = 24 * 1024 * 1024;
|
|
53
|
+
const MAX_SUCCESS_TOOL_RESULT_JSON_DEPTH = 32;
|
|
54
|
+
const MAX_SUCCESS_TOOL_RESULT_JSON_NODES = 8_192;
|
|
50
55
|
const MAX_TOOL_REFRESH_PASSES = 3;
|
|
51
56
|
const TOOL_REFRESH_BURST_IDLE_MS = 1_000;
|
|
52
57
|
// Recency-bounded per-server scrub material: enough to cover every value a
|
|
@@ -573,6 +578,7 @@ export class McpClientManager {
|
|
|
573
578
|
// The server writes this text; it can echo a secret it was sent.
|
|
574
579
|
throw new McpToolCallError(serverId, toolName, scrubKnownSecrets(redactSecrets(summarizeErrorContent(result.content)), inventory));
|
|
575
580
|
}
|
|
581
|
+
assertSuccessfulToolResultBudget(serverId, toolName, result, { raw: true });
|
|
576
582
|
const validateOutput = preparation.value.validateOutput;
|
|
577
583
|
if (validateOutput) {
|
|
578
584
|
if (result.structuredContent === undefined) {
|
|
@@ -595,10 +601,12 @@ export class McpClientManager {
|
|
|
595
601
|
}
|
|
596
602
|
// Success payloads cross toward the renderer and the transcript too; a
|
|
597
603
|
// server can embed the credential it was just sent into a result.
|
|
598
|
-
|
|
604
|
+
const published = {
|
|
599
605
|
content: deepScrub(result.content.map(normalizeContent), inventory),
|
|
600
606
|
structuredContent: deepScrub(result.structuredContent, inventory),
|
|
601
607
|
};
|
|
608
|
+
assertSuccessfulToolResultBudget(serverId, toolName, published);
|
|
609
|
+
return published;
|
|
602
610
|
}
|
|
603
611
|
async test(serverId) {
|
|
604
612
|
const started = this.now();
|
|
@@ -1852,6 +1860,128 @@ function normalizeContent(value) {
|
|
|
1852
1860
|
}
|
|
1853
1861
|
return { type: 'unknown', value };
|
|
1854
1862
|
}
|
|
1863
|
+
function assertSuccessfulToolResultBudget(serverId, toolName, result, options = {}) {
|
|
1864
|
+
if (result.content.length > MAX_SUCCESS_TOOL_RESULT_CONTENT_BLOCKS) {
|
|
1865
|
+
throw successfulToolResultBudgetError(serverId, toolName, 'content block');
|
|
1866
|
+
}
|
|
1867
|
+
const budget = {
|
|
1868
|
+
bytes: 0,
|
|
1869
|
+
nodes: 0,
|
|
1870
|
+
active: new WeakSet(),
|
|
1871
|
+
};
|
|
1872
|
+
try {
|
|
1873
|
+
// Bound the untrusted content before normalization and then the exact
|
|
1874
|
+
// result that crosses the public boundary. Known-block metadata may be
|
|
1875
|
+
// discarded later, but it must not provide a path around the first pass.
|
|
1876
|
+
countSuccessfulToolResultValue(result.structuredContent === undefined
|
|
1877
|
+
? { content: result.content }
|
|
1878
|
+
: { content: result.content, structuredContent: result.structuredContent }, budget, 0, options.raw === true);
|
|
1879
|
+
}
|
|
1880
|
+
catch (error) {
|
|
1881
|
+
if (error instanceof SuccessfulToolResultBudgetViolation) {
|
|
1882
|
+
throw successfulToolResultBudgetError(serverId, toolName, error.limit);
|
|
1883
|
+
}
|
|
1884
|
+
throw new McpToolCallError(serverId, toolName, 'server returned an invalid tool result');
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
class SuccessfulToolResultBudgetViolation extends Error {
|
|
1888
|
+
limit;
|
|
1889
|
+
constructor(limit) {
|
|
1890
|
+
super(limit);
|
|
1891
|
+
this.limit = limit;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
function countSuccessfulToolResultValue(value, budget, depth, rejectUndefined = false) {
|
|
1895
|
+
budget.nodes += 1;
|
|
1896
|
+
if (budget.nodes > MAX_SUCCESS_TOOL_RESULT_JSON_NODES) {
|
|
1897
|
+
throw new SuccessfulToolResultBudgetViolation('JSON node');
|
|
1898
|
+
}
|
|
1899
|
+
if (depth > MAX_SUCCESS_TOOL_RESULT_JSON_DEPTH) {
|
|
1900
|
+
throw new SuccessfulToolResultBudgetViolation('JSON depth');
|
|
1901
|
+
}
|
|
1902
|
+
if (value === null) {
|
|
1903
|
+
countSuccessfulToolResultBytes(budget, 4);
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
if (typeof value === 'string') {
|
|
1907
|
+
countSuccessfulToolResultJsonStringBytes(budget, value);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
if (typeof value === 'boolean') {
|
|
1911
|
+
countSuccessfulToolResultBytes(budget, value ? 4 : 5);
|
|
1912
|
+
return;
|
|
1913
|
+
}
|
|
1914
|
+
if (typeof value === 'number') {
|
|
1915
|
+
if (!Number.isFinite(value))
|
|
1916
|
+
throw new Error('non-finite number');
|
|
1917
|
+
countSuccessfulToolResultBytes(budget, JSON.stringify(value).length);
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
if (typeof value !== 'object')
|
|
1921
|
+
throw new Error('unsupported JSON value');
|
|
1922
|
+
if (budget.active.has(value))
|
|
1923
|
+
throw new Error('cyclic JSON value');
|
|
1924
|
+
if (typeof value.toJSON === 'function') {
|
|
1925
|
+
throw new Error('custom JSON serializer');
|
|
1926
|
+
}
|
|
1927
|
+
if (!Array.isArray(value)) {
|
|
1928
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1929
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
1930
|
+
throw new Error('non-plain JSON object');
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
budget.active.add(value);
|
|
1934
|
+
try {
|
|
1935
|
+
if (Array.isArray(value)) {
|
|
1936
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1937
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1938
|
+
if (index > 0)
|
|
1939
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1940
|
+
countSuccessfulToolResultValue(value[index], budget, depth + 1, rejectUndefined);
|
|
1941
|
+
}
|
|
1942
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1946
|
+
let emitted = 0;
|
|
1947
|
+
for (const key in value) {
|
|
1948
|
+
if (!Object.hasOwn(value, key))
|
|
1949
|
+
continue;
|
|
1950
|
+
const item = value[key];
|
|
1951
|
+
if (item === undefined) {
|
|
1952
|
+
if (rejectUndefined)
|
|
1953
|
+
throw new Error('unsupported JSON value');
|
|
1954
|
+
continue;
|
|
1955
|
+
}
|
|
1956
|
+
if (emitted > 0)
|
|
1957
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1958
|
+
countSuccessfulToolResultJsonStringBytes(budget, key);
|
|
1959
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1960
|
+
countSuccessfulToolResultValue(item, budget, depth + 1, rejectUndefined);
|
|
1961
|
+
emitted += 1;
|
|
1962
|
+
}
|
|
1963
|
+
countSuccessfulToolResultBytes(budget, 1);
|
|
1964
|
+
}
|
|
1965
|
+
finally {
|
|
1966
|
+
budget.active.delete(value);
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
function countSuccessfulToolResultJsonStringBytes(budget, value) {
|
|
1970
|
+
const remainingBytes = MAX_SUCCESS_TOOL_RESULT_BYTES - budget.bytes;
|
|
1971
|
+
const bytes = serializedByteLength(value, remainingBytes);
|
|
1972
|
+
if (bytes > remainingBytes)
|
|
1973
|
+
throw new SuccessfulToolResultBudgetViolation('byte');
|
|
1974
|
+
budget.bytes += bytes;
|
|
1975
|
+
}
|
|
1976
|
+
function countSuccessfulToolResultBytes(budget, bytes) {
|
|
1977
|
+
if (budget.bytes > MAX_SUCCESS_TOOL_RESULT_BYTES - bytes) {
|
|
1978
|
+
throw new SuccessfulToolResultBudgetViolation('byte');
|
|
1979
|
+
}
|
|
1980
|
+
budget.bytes += bytes;
|
|
1981
|
+
}
|
|
1982
|
+
function successfulToolResultBudgetError(serverId, toolName, limit) {
|
|
1983
|
+
return new McpToolCallError(serverId, toolName, `server returned a tool result that exceeds the ${limit} limit`);
|
|
1984
|
+
}
|
|
1855
1985
|
function summarizeErrorContent(content) {
|
|
1856
1986
|
if (content.length > MAX_SUMMARIZED_ERROR_BLOCKS)
|
|
1857
1987
|
return OVERSIZED_TOOL_ERROR_CONTENT;
|
|
@@ -61,19 +61,6 @@ export async function inspectAgentRunReadModel(runStore, runtimeEventStore, opti
|
|
|
61
61
|
diagnostics,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
export async function inspectSessionRunReadModels(runStore, runtimeEventStore, sessionId, options = {}) {
|
|
65
|
-
const invocations = await runtimeEventStore.listSessionInvocations(sessionId);
|
|
66
|
-
const models = [];
|
|
67
|
-
for (const invocation of invocations) {
|
|
68
|
-
models.push(await inspectAgentRunReadModel(runStore, runtimeEventStore, {
|
|
69
|
-
sessionId,
|
|
70
|
-
runId: invocation.runId,
|
|
71
|
-
invocation,
|
|
72
|
-
...(options.isFatalReadError ? { isFatalReadError: options.isFatalReadError } : {}),
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
return models;
|
|
76
|
-
}
|
|
77
64
|
// A run is not its invocation: a continuation is a new run on the invocation it
|
|
78
65
|
// resumes. This reader is addressed by run, so it looks the invocation up by the
|
|
79
66
|
// id it was actually given.
|