maka-agent 0.2.0-dev.22.20260905 → 0.2.0-dev.24.20260907
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/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.js +5 -12
- package/dist/pi-tui-runner.js +74 -4
- package/dist/runtime-host-cli-context.js +167 -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 +81 -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 +37 -4
- 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 -0
- package/dist/runtime-host-session-driver.js +4 -25
- 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 +140 -3
- package/dist/tui-host-owner-copy.js +24 -0
- package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
- package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -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/bot-events.js +18 -63
- package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
- package/node_modules/@maka/core/dist/model-call-attempt.js +0 -82
- package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -186
- 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 +3 -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 +22 -2
- package/node_modules/@maka/core/dist/redaction.js +41 -58
- 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-trace.js +5 -1
- package/node_modules/@maka/core/dist/session.js +54 -52
- package/node_modules/@maka/core/dist/slash-command-catalog.js +2 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
- package/node_modules/@maka/core/dist/usage-ledger-merge.js +7 -9
- package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
- package/node_modules/@maka/core/dist/workhub-creation-intent.js +34 -20
- package/node_modules/@maka/core/package.json +4 -0
- package/node_modules/@maka/eval/harbor/egress-proxy/entrypoint.sh +2 -1
- package/node_modules/@maka/mcp/dist/index.js +131 -1
- package/node_modules/@maka/runtime/dist/agent-run.js +272 -105
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +13 -5
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +155 -134
- package/node_modules/@maka/runtime/dist/bots/base-adapter.js +17 -0
- package/node_modules/@maka/runtime/dist/bots/bot-test.js +38 -22
- package/node_modules/@maka/runtime/dist/bots/dingtalk-bridge.js +7 -5
- package/node_modules/@maka/runtime/dist/bots/discord-bridge.js +4 -4
- package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +4 -5
- package/node_modules/@maka/runtime/dist/bots/qq-bridge.js +6 -4
- package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +3 -4
- package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +4 -5
- package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +17 -19
- package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +5 -6
- package/node_modules/@maka/runtime/dist/bots/ws-bridge-base.js +2 -3
- package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
- package/node_modules/@maka/runtime/dist/conversation-copy.js +5 -4
- 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 +106 -0
- 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 +7 -0
- 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/provider-error-classification.js +84 -123
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +68 -108
- package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +82 -54
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +117 -159
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +150 -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/session-trace-projection.js +3 -30
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
- package/node_modules/@maka/runtime/dist/test-connection.js +16 -16
- package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
- package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
- package/node_modules/@maka/runtime/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
- package/node_modules/@maka/runtime-host/dist/candidate-entry.js +4 -1
- 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 +156 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +273 -0
- package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +3 -1
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/peer-client.js +13 -0
- package/node_modules/@maka/runtime-host/dist/client/registered-host-termination.js +0 -59
- 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 +27 -5
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +28 -16
- package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +4 -0
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +29 -12
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +37 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +2 -0
- package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +28 -1
- 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 +33 -0
- package/node_modules/@maka/runtime-host/dist/server/access-authority.js +26 -1
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +6 -1
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
- package/node_modules/@maka/runtime-host/dist/server/canonical-usage-reader.js +24 -11
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +7 -4
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +168 -28
- 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 +3 -2
- package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +6 -3
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +108 -23
- 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/message-coordinator.js +85 -8
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +7 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +344 -71
- 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 +201 -12
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +8 -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/usage-pricing-coordinator.js +4 -11
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -15
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +6 -2
- package/node_modules/@maka/storage/dist/agent-run-store.js +44 -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 -4
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +0 -2
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
- package/node_modules/@maka/storage/dist/conversation-operational-state.js +4 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +11 -7
- package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
- package/node_modules/@maka/storage/dist/model-call-ledger.js +199 -32
- package/node_modules/@maka/storage/dist/model-call-usage-sql.js +136 -0
- 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/operational-state-store-public.js +1 -1
- package/node_modules/@maka/storage/dist/operational-state-store.js +5 -3
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +24 -4
- 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 +17 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +129 -25
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
- package/node_modules/@maka/storage/dist/sqlite-usage-schema.js +200 -20
- package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +111 -0
- package/node_modules/@maka/storage/dist/usage-stores.js +6 -2
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -24,6 +24,7 @@ export const SLASH_COMMAND_CATALOG = [
|
|
|
24
24
|
{ id: 'goal', session: 'required', surfaces: ['tui'] },
|
|
25
25
|
{ id: 'graph', session: 'none', surfaces: ['desktop', 'tui'] },
|
|
26
26
|
{ id: 'help', session: 'none', surfaces: ['tui'] },
|
|
27
|
+
{ id: 'host', session: 'none', surfaces: ['tui'] },
|
|
27
28
|
{ id: 'mcp', session: 'none', surfaces: ['tui'] },
|
|
28
29
|
{ id: 'model', session: 'required', surfaces: ['tui'] },
|
|
29
30
|
{ id: 'move', session: 'required', surfaces: ['tui'] },
|
|
@@ -40,6 +41,7 @@ export const SLASH_COMMAND_CATALOG = [
|
|
|
40
41
|
{ id: 'swarm', session: 'none', surfaces: ['desktop', 'tui'] },
|
|
41
42
|
{ id: 'thinking', session: 'required', surfaces: ['tui'] },
|
|
42
43
|
{ id: 'transcript', session: 'required', surfaces: ['tui'] },
|
|
44
|
+
{ id: 'update', session: 'none', surfaces: ['tui'] },
|
|
43
45
|
];
|
|
44
46
|
export function slashCommandsForSurface(surface) {
|
|
45
47
|
return SLASH_COMMAND_CATALOG.filter((command) => command.surfaces.includes(surface));
|
|
@@ -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;
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { projectModelCallUsageBuckets, projectModelCallUsageLogs, projectModelCallUsageSummary, } from './model-call-usage-projection.js';
|
|
20
19
|
/**
|
|
21
20
|
* The cost to present for a usage total, or `undefined` when it cannot be shown
|
|
22
21
|
* honestly. Trust the total only when at least one canonical attempt was priced;
|
|
@@ -66,8 +65,8 @@ export function legacyUsageProvenance(legacyRecords) {
|
|
|
66
65
|
pendingRepairs: 0,
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
export function mergeUsageSummary(legacy, canonical
|
|
70
|
-
const projected =
|
|
68
|
+
export function mergeUsageSummary(legacy, canonical) {
|
|
69
|
+
const projected = canonical.projection;
|
|
71
70
|
return {
|
|
72
71
|
range: projected.range,
|
|
73
72
|
totalRequests: legacy.totalRequests + projected.totalRequests,
|
|
@@ -95,17 +94,16 @@ export function mergeUsageSummary(legacy, canonical, query, now) {
|
|
|
95
94
|
},
|
|
96
95
|
};
|
|
97
96
|
}
|
|
98
|
-
export function mergeUsageBuckets(legacy, canonical
|
|
99
|
-
const projected = projectModelCallUsageBuckets(canonical.attempts, query, groupBy, now);
|
|
97
|
+
export function mergeUsageBuckets(legacy, canonical) {
|
|
100
98
|
const merged = new Map();
|
|
101
|
-
for (const bucket of [...legacy, ...
|
|
99
|
+
for (const bucket of [...legacy, ...canonical.projection.buckets]) {
|
|
102
100
|
const existing = merged.get(bucket.key);
|
|
103
101
|
merged.set(bucket.key, existing ? combineBuckets(existing, bucket) : { ...bucket });
|
|
104
102
|
}
|
|
105
103
|
return {
|
|
106
104
|
buckets: [...merged.values()].sort((left, right) => right.requests - left.requests),
|
|
107
105
|
provenance: {
|
|
108
|
-
coverage:
|
|
106
|
+
coverage: canonical.projection.coverage,
|
|
109
107
|
legacyRecords: legacy.reduce((total, bucket) => total + bucket.requests, 0),
|
|
110
108
|
unreadableRecords: canonical.unreadableRecords,
|
|
111
109
|
pendingRepairs: canonical.pendingRepairs,
|
|
@@ -117,8 +115,8 @@ export function mergeUsageBuckets(legacy, canonical, query, groupBy, now) {
|
|
|
117
115
|
* the merged order can only come from the first `offset + limit` rows of each —
|
|
118
116
|
* callers may bound their reads to that prefix and still page exactly.
|
|
119
117
|
*/
|
|
120
|
-
export function mergeUsageLogs(legacy, canonical,
|
|
121
|
-
const projected =
|
|
118
|
+
export function mergeUsageLogs(legacy, canonical, offset, limit) {
|
|
119
|
+
const projected = canonical.projection;
|
|
122
120
|
const rows = [];
|
|
123
121
|
let left = 0;
|
|
124
122
|
let right = 0;
|
|
@@ -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 ||
|
|
@@ -74,7 +74,9 @@ const DIRECT_STOP_REQUEST = /^\s*(?:(?:please|kindly)\s+)?(?:stop|cancel|termina
|
|
|
74
74
|
// which is usually work to do inside a Session, and English admits no
|
|
75
75
|
// equivalent either.
|
|
76
76
|
const DIRECT_CHINESE_STOP_REQUEST = /^\s*(?:(?:请|请帮我|帮我|麻烦你?)\s*)?(?:停止|停掉|停下|取消|终止|中止)\s*(?:(?:这个|该)?(?:会话|工作|任务)\s*)?(.+?)\s*[。!]?\s*$/iu;
|
|
77
|
-
const
|
|
77
|
+
const DIRECT_RESUME_REQUEST = /^\s*(?:(?:please|kindly)\s+)?resume\s+(?:(?:the|this)\s+)?(?:(?:session|work|task|job)\s+)?(.+?)\s*[.!。!]?\s*$/iu;
|
|
78
|
+
const DIRECT_CHINESE_RESUME_REQUEST = /^\s*(?:(?:请|请帮我|帮我|麻烦你?)\s*)?(?:恢复|恢復|接着跑|接著跑)\s*(?:(?:这个|该)?(?:会话|工作|任务)\s*)?(.+?)\s*[。!]?\s*$/iu;
|
|
79
|
+
const UNSAFE_NAMED_ACTION_TARGET = /^(?:it|this|that|one|everything|all|current|session|work|task|job|(?:this|that|current)\s+(?:session|work|task|job)|它|这个|那个|全部|当前|会话|工作|任务|(?:这个|那个|当前)(?:会话|工作|任务))$/iu;
|
|
78
80
|
/**
|
|
79
81
|
* Whether trusted user text affirmatively asks WorkHub to create a new Session.
|
|
80
82
|
*
|
|
@@ -219,8 +221,14 @@ export function readWorkHubRequestIntent(value) {
|
|
|
219
221
|
: { kind: 'unusable' };
|
|
220
222
|
const correctionCue = hasWorkHubCorrectionCue(source);
|
|
221
223
|
const existingTarget = affirmativeWorkHubExistingCorrectionTarget(source);
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
+
const stop = directWorkHubNamedAction(source, literalMask.malformed, [
|
|
225
|
+
DIRECT_STOP_REQUEST,
|
|
226
|
+
DIRECT_CHINESE_STOP_REQUEST,
|
|
227
|
+
]);
|
|
228
|
+
const resume = directWorkHubNamedAction(source, literalMask.malformed, [
|
|
229
|
+
DIRECT_RESUME_REQUEST,
|
|
230
|
+
DIRECT_CHINESE_RESUME_REQUEST,
|
|
231
|
+
]);
|
|
224
232
|
const actions = allMatches(masked, EXECUTION_ACTION);
|
|
225
233
|
const execution = literalMask.malformed || naming.kind === 'unusable' || hasDominatingDeliberation(masked)
|
|
226
234
|
? 'non_executable'
|
|
@@ -237,9 +245,14 @@ export function readWorkHubRequestIntent(value) {
|
|
|
237
245
|
...(existingTarget ? { existingTarget } : {}),
|
|
238
246
|
},
|
|
239
247
|
stop: {
|
|
240
|
-
cue:
|
|
241
|
-
imperative: Boolean(
|
|
242
|
-
...(
|
|
248
|
+
cue: stop.cue,
|
|
249
|
+
imperative: Boolean(stop.target),
|
|
250
|
+
...(stop.target ? { target: stop.target } : {}),
|
|
251
|
+
},
|
|
252
|
+
resume: {
|
|
253
|
+
cue: resume.cue,
|
|
254
|
+
imperative: Boolean(resume.target),
|
|
255
|
+
...(resume.target ? { target: resume.target } : {}),
|
|
243
256
|
},
|
|
244
257
|
};
|
|
245
258
|
}
|
|
@@ -331,6 +344,14 @@ export function matchWorkHubSessionName(reference, sessionName) {
|
|
|
331
344
|
}
|
|
332
345
|
return { kind: 'named', remainder: normalizedTarget.slice(matchedName.length).trim() };
|
|
333
346
|
}
|
|
347
|
+
/** Whether a direct stop/resume reference names exactly this Session. */
|
|
348
|
+
export function workHubNamedDelegationActionTargetsSession(action, sessionName) {
|
|
349
|
+
if (!action.imperative || !action.target)
|
|
350
|
+
return false;
|
|
351
|
+
const match = matchWorkHubSessionName(action.target, sessionName);
|
|
352
|
+
return (match.kind === 'elided_name_punctuation' ||
|
|
353
|
+
(match.kind === 'named' && /^[.!?。!?]*$/u.test(match.remainder)));
|
|
354
|
+
}
|
|
334
355
|
/**
|
|
335
356
|
* The correction policy's tail rule. A correction may name its target and then
|
|
336
357
|
* say what to do with it, but a withdrawal anywhere in the reference retracts
|
|
@@ -355,24 +376,17 @@ export function workHubCorrectionAdmitsReference(reference, match) {
|
|
|
355
376
|
function correctionTargetMatchesSession(target, sessionName) {
|
|
356
377
|
return workHubCorrectionAdmitsReference(target, matchWorkHubSessionName(target, sessionName));
|
|
357
378
|
}
|
|
358
|
-
function
|
|
379
|
+
function directWorkHubNamedAction(value, malformedLiteral, patterns) {
|
|
359
380
|
if (malformedLiteral || /[??]\s*$/u.test(value))
|
|
360
|
-
return
|
|
361
|
-
const match =
|
|
381
|
+
return { cue: false };
|
|
382
|
+
const match = patterns[0].exec(value) ?? patterns[1].exec(value);
|
|
362
383
|
const rawTarget = match?.[1]?.trim();
|
|
363
384
|
if (!rawTarget)
|
|
364
|
-
return
|
|
365
|
-
const target =
|
|
366
|
-
|
|
367
|
-
return undefined;
|
|
368
|
-
return target;
|
|
369
|
-
}
|
|
370
|
-
function directWorkHubStopCue(value, malformedLiteral) {
|
|
371
|
-
if (malformedLiteral || /[??]\s*$/u.test(value))
|
|
372
|
-
return false;
|
|
373
|
-
return Boolean(DIRECT_STOP_REQUEST.test(value) || DIRECT_CHINESE_STOP_REQUEST.test(value));
|
|
385
|
+
return { cue: Boolean(match) };
|
|
386
|
+
const target = stripMatchingActionQuotes(rawTarget.replace(/[.!。!]+\s*$/u, '').trim());
|
|
387
|
+
return !target || UNSAFE_NAMED_ACTION_TARGET.test(target) ? { cue: true } : { cue: true, target };
|
|
374
388
|
}
|
|
375
|
-
function
|
|
389
|
+
function stripMatchingActionQuotes(value) {
|
|
376
390
|
const pairs = new Map([
|
|
377
391
|
['"', '"'],
|
|
378
392
|
["'", "'"],
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"./model-projection-transition": "./dist/model-projection-transition.js",
|
|
11
11
|
"./canonical-runtime-event": "./dist/canonical-runtime-event.js",
|
|
12
12
|
"./runtime-boundary": "./dist/runtime-boundary.js",
|
|
13
|
+
"./runtime-handoff": "./dist/runtime-handoff.js",
|
|
14
|
+
"./runtime-logical-execution": "./dist/runtime-logical-execution.js",
|
|
13
15
|
"./runtime-event": "./dist/runtime-event.js",
|
|
14
16
|
"./tool-args-identity": "./dist/tool-args-identity.js",
|
|
15
17
|
"./tool-ledger-scanner": "./dist/tool-ledger-scanner.js",
|
|
@@ -34,6 +36,7 @@
|
|
|
34
36
|
"./plan": "./dist/plan.js",
|
|
35
37
|
"./agent-run": "./dist/agent-run.js",
|
|
36
38
|
"./subagent-workspace": "./dist/subagent-workspace.js",
|
|
39
|
+
"./model-failure": "./dist/model-failure.js",
|
|
37
40
|
"./model-call-attempt": "./dist/model-call-attempt.js",
|
|
38
41
|
"./model-call-usage-projection": "./dist/model-call-usage-projection.js",
|
|
39
42
|
"./usage-ledger-merge": "./dist/usage-ledger-merge.js",
|
|
@@ -51,6 +54,7 @@
|
|
|
51
54
|
"./user-question": "./dist/user-question.js",
|
|
52
55
|
"./connections": "./dist/connections.js",
|
|
53
56
|
"./context-offload": "./dist/context-offload.js",
|
|
57
|
+
"./tool-result-archive-evidence": "./dist/tool-result-archive-evidence.js",
|
|
54
58
|
"./attachments": "./dist/attachments.js",
|
|
55
59
|
"./artifacts": "./dist/artifacts.js",
|
|
56
60
|
"./pet": "./dist/pet.js",
|
|
@@ -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;
|