maka-agent 0.2.0-dev.27.20260910 → 0.2.0-dev.28.20260911
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/LICENSE +106 -0
- package/dist/cli-core.js +7 -0
- package/dist/runtime-host-run-command.js +15 -7
- package/dist/session-import-command.js +69 -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/@earendil-works/pi-tui/dist/components/editor.js +9 -4
- package/node_modules/@maka/core/dist/diagnostic-log.js +18 -7
- package/node_modules/@maka/core/dist/text-sanitize.js +8 -2
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +8 -8
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +3 -1
- package/node_modules/@maka/runtime/dist/bots/bot-test.js +2 -1
- package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +24 -20
- package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +5 -3
- package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +87 -29
- package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +40 -36
- package/node_modules/@maka/runtime/dist/computer-use-tools.js +4 -1
- package/node_modules/@maka/runtime/dist/deep-research-tools.js +11 -5
- package/node_modules/@maka/runtime/dist/edit-replace.js +2 -2
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +5 -6
- package/node_modules/@maka/runtime/dist/memory-extraction-evidence.js +7 -1
- package/node_modules/@maka/runtime/dist/memory-extraction.js +12 -7
- package/node_modules/@maka/runtime/dist/openai-responses-websocket.js +2 -5
- package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +11 -2
- package/node_modules/@maka/runtime/dist/request-customization-fetch.js +14 -7
- package/node_modules/@maka/runtime/dist/session-export.js +1 -0
- package/node_modules/@maka/runtime/dist/session-import.js +100 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +6 -1
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +9 -6
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +13 -6
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +43 -10
- package/node_modules/@maka/runtime/dist/stream-graph-handoff.js +6 -1
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +1 -4
- package/node_modules/@maka/runtime/dist/system-prompt/workspace-instructions.js +11 -6
- package/node_modules/@maka/runtime/dist/tavily-search.js +8 -2
- package/node_modules/@maka/runtime/dist/text-line-window.js +49 -0
- package/node_modules/@maka/runtime/dist/tool-output.js +35 -12
- package/node_modules/@maka/runtime/dist/unified-diff.js +40 -10
- package/node_modules/@maka/runtime/dist/web-fetch-tool.js +4 -2
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +82 -33
- package/node_modules/@maka/runtime/dist/workspace-executor.js +2 -6
- package/node_modules/@maka/runtime/package.json +2 -1
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +6 -6
- package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +7 -4
- package/node_modules/@maka/runtime-host/dist/protocol/artifact.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +3 -2
- package/node_modules/@maka/runtime-host/dist/protocol/skill-catalog.js +2 -1
- package/node_modules/@maka/runtime-host/dist/server/artifact-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +29 -4
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +6 -1
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +35 -4
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +24 -8
- package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +17 -8
- package/node_modules/@maka/runtime-host/dist/server/runtime-resource-projection.js +3 -9
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +20 -21
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +24 -2
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +18 -2
- package/node_modules/@maka/runtime-host/dist/transport/framed-byte-stream-transport.js +4 -1
- package/node_modules/@maka/runtime-host/dist/transport/local-ipc-framing.js +4 -2
- package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +9 -8
- package/node_modules/@maka/runtime-host/dist/transport/resumable-peer-stream.js +14 -9
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +19 -4
- package/node_modules/@maka/storage/dist/context-value-mutation-gate.js +59 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +579 -7
- package/node_modules/@maka/storage/dist/session-message-projection.js +8 -4
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +18 -4
- package/node_modules/@maka/storage/dist/stable-storage.js +2 -1
- package/node_modules/@modelcontextprotocol/client/dist/src-D_zzAWoS.mjs +22 -5
- package/node_modules/@modelcontextprotocol/client/dist/src-NAgB4Mp8.cjs +22 -5
- package/node_modules/zod/v4/core/memoizer.cjs +12 -16
- package/node_modules/zod/v4/core/memoizer.js +12 -16
- package/package.json +1 -1
|
@@ -26,6 +26,7 @@ import { compareAndDeleteEntry, hostVisibilityAfterWrite, openStableTarget, writ
|
|
|
26
26
|
import { promisify } from 'node:util';
|
|
27
27
|
import { runProcessWithBoundedTail, runShellWithBoundedTail } from './shell-exec.js';
|
|
28
28
|
import { isSupportedImagePath, readWorkspaceImage } from './image-file.js';
|
|
29
|
+
import { readTextLineWindow } from './text-line-window.js';
|
|
29
30
|
const execAsync = promisify(exec);
|
|
30
31
|
const execFileAsync = promisify(execFile);
|
|
31
32
|
export const LOCAL_WORKSPACE_EXECUTOR_FACTS = {
|
|
@@ -65,12 +66,7 @@ export class LocalWorkspaceExecutor {
|
|
|
65
66
|
return await readWorkspaceImage(input.path);
|
|
66
67
|
}
|
|
67
68
|
const content = await fs.readFile(input.path, 'utf8');
|
|
68
|
-
|
|
69
|
-
return { content };
|
|
70
|
-
const lines = content.split('\n');
|
|
71
|
-
const start = input.offset ?? 0;
|
|
72
|
-
const end = input.limit ? start + input.limit : lines.length;
|
|
73
|
-
return { content: lines.slice(start, end).join('\n') };
|
|
69
|
+
return { content: readTextLineWindow(content, input.offset, input.limit) };
|
|
74
70
|
}
|
|
75
71
|
async writeFile(input) {
|
|
76
72
|
await fs.writeFile(input.path, input.content, 'utf8');
|
|
@@ -131,7 +131,8 @@
|
|
|
131
131
|
"./tool-runtime": "./dist/tool-runtime.js",
|
|
132
132
|
"./web-fetch-tool": "./dist/web-fetch-tool.js",
|
|
133
133
|
"./web-search-tool": "./dist/web-search-tool.js",
|
|
134
|
-
"./xai-oauth-enrollment": "./dist/xai-oauth-enrollment.js"
|
|
134
|
+
"./xai-oauth-enrollment": "./dist/xai-oauth-enrollment.js",
|
|
135
|
+
"./session-import": "./dist/session-import.js"
|
|
135
136
|
},
|
|
136
137
|
"dependencies": {
|
|
137
138
|
"@ai-sdk/anthropic": "4.0.46",
|
|
@@ -52,7 +52,7 @@ export function formatHostHandoff(view, locale) {
|
|
|
52
52
|
busy: '其他連線或正在執行的工作阻止了自動交接。停止並繼續可能中斷這些工作。',
|
|
53
53
|
activity_unknown: '背景服務與目前用戶端不相容,且無法確認有哪些工作仍在執行。停止並繼續會重新啟動服務,可能中斷其他視窗或裝置上的工作。',
|
|
54
54
|
operator_required: `目前無法從這裡更新背景服務。請透過 ${view.target.name} 上管理此服務的應用程式或命令更新,再重試。`,
|
|
55
|
-
repair_required: '
|
|
55
|
+
repair_required: '上次啟動或交接失敗。請查看下方診斷資訊,修復原因後再重試;如果狀態沒有改變,重複重試通常不會解決問題。',
|
|
56
56
|
retry_required: '服務狀態發生了變化,或交接尚未完成。可以安全重試,不會預設中斷工作。',
|
|
57
57
|
}
|
|
58
58
|
: zh
|
|
@@ -61,7 +61,7 @@ export function formatHostHandoff(view, locale) {
|
|
|
61
61
|
busy: '其它连接或正在执行的工作阻止了自动交接。停止并继续可能中断这些工作。',
|
|
62
62
|
activity_unknown: '后台服务与当前客户端不兼容,且无法确认有哪些工作仍在运行。停止并继续会重新启动服务,可能中断其他窗口或设备上的工作。',
|
|
63
63
|
operator_required: `目前无法从这里更新后台服务。请通过 ${view.target.name} 上管理此服务的应用或命令更新,然后重试。`,
|
|
64
|
-
repair_required: '
|
|
64
|
+
repair_required: '上次启动或交接失败。请查看下方诊断信息,修复原因后再重试;如果状态没有变化,重复重试通常不会解决问题。',
|
|
65
65
|
retry_required: '服务状态发生了变化,或交接尚未完成。可以安全重试,不会默认中断工作。',
|
|
66
66
|
}
|
|
67
67
|
: {
|
|
@@ -69,26 +69,26 @@ export function formatHostHandoff(view, locale) {
|
|
|
69
69
|
busy: 'Other connections or work in progress prevent an automatic handoff. Stopping the service may interrupt that work.',
|
|
70
70
|
activity_unknown: 'The background service is incompatible with this client, and its active work is unknown. Stop and continue restarts it and may interrupt work in other windows or devices.',
|
|
71
71
|
operator_required: `This client cannot update the background service here. Use its managing app or operator command on ${view.target.name}, then retry.`,
|
|
72
|
-
repair_required: 'The last startup or handoff
|
|
72
|
+
repair_required: 'The last startup or handoff failed. Review the diagnostic below, correct the cause, then retry. Repeating the same action without a state change will usually fail again.',
|
|
73
73
|
retry_required: 'The service changed or the handoff has not finished. A safe retry will not interrupt work by default.',
|
|
74
74
|
};
|
|
75
75
|
if (view.recoveryBlocker && view.reason === 'operator_required') {
|
|
76
76
|
const guidance = zh
|
|
77
77
|
? tw
|
|
78
78
|
? {
|
|
79
|
-
managed: '
|
|
79
|
+
managed: '此背景服務由安裝它的 Maka 管理。如果由 Desktop 安裝,請在該 Desktop 中開啟此工作區,然後選擇「停止舊服務並繼續」;否則請使用安裝它的 Maka 更新服務,再回到這裡重試。',
|
|
80
80
|
owner: '此背景服務屬於另一個 Maka 安裝。請使用管理它的 Maka 安裝更新,再重試。',
|
|
81
81
|
installation: '這次啟動使用暫存安裝,無法接管現有背景服務。請使用已安裝的 Maka 更新服務,再重試。',
|
|
82
82
|
identity: '無法確認舊背景服務的處理程序身分,因此不能安全停止它。請關閉啟動它的 Maka 或透過其管理程式停止服務,再重試。',
|
|
83
83
|
}
|
|
84
84
|
: {
|
|
85
|
-
managed: '
|
|
85
|
+
managed: '此后台服务由安装它的 Maka 管理。如果由 Desktop 安装,请在该 Desktop 中打开此工作区,然后选择“停止旧服务并继续”;否则请使用安装它的 Maka 更新服务,再回到这里重试。',
|
|
86
86
|
owner: '此后台服务属于另一个 Maka 安装。请使用管理它的 Maka 安装更新,然后重试。',
|
|
87
87
|
installation: '本次启动使用临时安装,无法接管现有后台服务。请使用已安装的 Maka 更新服务,然后重试。',
|
|
88
88
|
identity: '无法确认旧后台服务的进程身份,因此不能安全停止它。请关闭启动它的 Maka 或通过其管理程序停止服务,然后重试。',
|
|
89
89
|
}
|
|
90
90
|
: {
|
|
91
|
-
managed: '
|
|
91
|
+
managed: 'This background service is managed by the Maka installation that created it. If Desktop installed it, open this workspace there and choose Stop old service and continue. Otherwise update the service with that Maka installation, then return here and retry.',
|
|
92
92
|
owner: 'Another Maka installation owns this background service. Update it using that installation, then retry.',
|
|
93
93
|
installation: 'This temporary installation cannot take over the existing background service. Update it using an installed Maka, then retry.',
|
|
94
94
|
identity: 'The old background process could not be identified safely. Close the Maka instance that started it or stop it through its operator, then retry.',
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { createHash } from 'node:crypto';
|
|
20
|
-
import { setTimeout as delay } from 'node:timers/promises';
|
|
21
20
|
import { performance } from 'node:perf_hooks';
|
|
22
21
|
import { canonicalPeerMeshMemberAdvertisement, canonicalPeerMeshRoster, createPeerMeshInvitationSecret, validatePeerMeshInvitation, decodeSignedPeerMeshMemberAdvertisement, decodeSignedPeerMeshRoster, generatePeerMeshAuthorityKeyPair, matchesPeerMeshInvitationSecret, PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES, PEER_MESH_MAX_INVITATION_RECORDS, PEER_MESH_MAX_PENDING_INVITATIONS, PEER_MESH_MAX_TRANSIT_ADDRESSES_PER_RELAY, PEER_MESH_MAX_TRANSIT_RELAY_ADDRESSES, peerMeshMemberAdvertisementSigningBytes, peerMeshId, peerMeshInvitationSecretDigest, signPeerMeshRoster, } from './model.js';
|
|
23
22
|
import { canonicalPeerMeshDisplayName } from './display-name.js';
|
|
@@ -793,19 +792,23 @@ class PeerMeshNodeImpl {
|
|
|
793
792
|
}
|
|
794
793
|
}
|
|
795
794
|
async #waitForReconciliationTrigger(observedGeneration, signal) {
|
|
796
|
-
if (this.#reconcileGeneration !== observedGeneration)
|
|
795
|
+
if (this.#reconcileGeneration !== observedGeneration || signal.aborted)
|
|
797
796
|
return;
|
|
798
797
|
let wake;
|
|
799
798
|
const triggered = new Promise((resolve) => {
|
|
800
799
|
wake = resolve;
|
|
801
800
|
this.#reconcileWaiters.add(wake);
|
|
802
801
|
});
|
|
803
|
-
|
|
802
|
+
const timeout = setTimeout(wake, RECONCILE_INTERVAL_MS);
|
|
803
|
+
signal.addEventListener('abort', wake, { once: true });
|
|
804
|
+
if (this.#reconcileGeneration !== observedGeneration || signal.aborted)
|
|
804
805
|
wake();
|
|
805
806
|
try {
|
|
806
|
-
await
|
|
807
|
+
await triggered;
|
|
807
808
|
}
|
|
808
809
|
finally {
|
|
810
|
+
clearTimeout(timeout);
|
|
811
|
+
signal.removeEventListener('abort', wake);
|
|
809
812
|
this.#reconcileWaiters.delete(wake);
|
|
810
813
|
}
|
|
811
814
|
}
|
|
@@ -345,7 +345,7 @@ export function decodeArtifactQueryResult(value) {
|
|
|
345
345
|
if (!isCanonicalBase64(chunkBase64)) {
|
|
346
346
|
throw invalidProtocolFrame('Invalid artifact chunk');
|
|
347
347
|
}
|
|
348
|
-
const chunkBytes = Buffer.
|
|
348
|
+
const chunkBytes = Buffer.byteLength(chunkBase64, 'base64');
|
|
349
349
|
if (chunkBytes > ARTIFACT_READ_CHUNK_MAX_BYTES || offset + chunkBytes > totalBytes) {
|
|
350
350
|
throw invalidProtocolFrame('Invalid artifact chunk bounds');
|
|
351
351
|
}
|
|
@@ -466,7 +466,7 @@ function decodeBinaryPreview(value) {
|
|
|
466
466
|
]);
|
|
467
467
|
const base64 = boundedText(exact.base64, 'artifact binary base64', base64MaxBytes(), true);
|
|
468
468
|
if (!isCanonicalBase64(base64) ||
|
|
469
|
-
Buffer.
|
|
469
|
+
Buffer.byteLength(base64, 'base64') > ARTIFACT_PREVIEW_MAX_BYTES) {
|
|
470
470
|
throw invalidProtocolFrame('Invalid artifact binary base64');
|
|
471
471
|
}
|
|
472
472
|
return {
|
|
@@ -62,7 +62,8 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
|
|
|
62
62
|
export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
|
|
63
63
|
// Increment when the same protocol version no longer guarantees safe Client-Host
|
|
64
64
|
// interoperability. Mismatches are rejected before domain commands are admitted.
|
|
65
|
-
export const RUNTIME_HOST_COMPATIBILITY_EPOCH =
|
|
65
|
+
export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 142;
|
|
66
|
+
// 142: Invocable Skill queries expose missing and archived Session refusals explicitly.
|
|
66
67
|
// 141: WorkHub root admissions bind model Intent/Recall decisions before actions.
|
|
67
68
|
// 140: Plugin Platform queries expose scoped Command contribution projections.
|
|
68
69
|
// Epoch-139 peers reject the added query view and result shape.
|
|
@@ -165,7 +165,8 @@ export function decodeSessionTranscriptPage(value) {
|
|
|
165
165
|
assertFragmentOrder(fragments, direction);
|
|
166
166
|
const rawBytes = requireCount(result.rawBytes, 'Session transcript page bytes');
|
|
167
167
|
if (rawBytes > SESSION_TRANSCRIPT_PAGE_MAX_BYTES ||
|
|
168
|
-
fragments.reduce((total, fragment) => total + Buffer.
|
|
168
|
+
fragments.reduce((total, fragment) => total + Buffer.byteLength(fragment.data, 'base64'), 0) !==
|
|
169
|
+
rawBytes) {
|
|
169
170
|
throw invalidProtocolFrame('Invalid Session transcript page byte count');
|
|
170
171
|
}
|
|
171
172
|
const nextCursor = result.nextCursor === null
|
|
@@ -231,7 +232,7 @@ function decodeSessionTranscriptFragment(value, source, throughSequence) {
|
|
|
231
232
|
const byteOffset = requireCount(exact.byteOffset, 'Session transcript fragment byte offset');
|
|
232
233
|
const totalBytes = requireCount(exact.totalBytes, 'Session transcript fragment total bytes');
|
|
233
234
|
const data = requireBase64Fragment(exact.data);
|
|
234
|
-
const dataBytes = Buffer.
|
|
235
|
+
const dataBytes = Buffer.byteLength(data, 'base64');
|
|
235
236
|
if (totalBytes === 0 ||
|
|
236
237
|
dataBytes === 0 ||
|
|
237
238
|
byteOffset >= totalBytes ||
|
|
@@ -42,6 +42,7 @@ const QUERY_ERRORS = [
|
|
|
42
42
|
'persistence_failed',
|
|
43
43
|
'internal_failure',
|
|
44
44
|
];
|
|
45
|
+
const INVOCABLE_QUERY_ERRORS = [...QUERY_ERRORS, 'not_found', 'session_archived'];
|
|
45
46
|
const MUTATION_ERRORS = [...QUERY_ERRORS, 'commit_outcome_unknown'];
|
|
46
47
|
export const SKILL_CATALOG_OPERATION_SPECS = {
|
|
47
48
|
'skill.catalog.query': defineHostPathOperation({
|
|
@@ -54,7 +55,7 @@ export const SKILL_CATALOG_OPERATION_SPECS = {
|
|
|
54
55
|
'skill.catalog.invocable.query': defineHostPathOperation({
|
|
55
56
|
mode: 'query',
|
|
56
57
|
availability: 'ready',
|
|
57
|
-
errors:
|
|
58
|
+
errors: INVOCABLE_QUERY_ERRORS,
|
|
58
59
|
decodeInput: decodeInvocableQueryInput,
|
|
59
60
|
decodeOutput: decodeInvocableQueryResult,
|
|
60
61
|
}, (input) => input.target.kind === 'new_session' && input.target.context.workspace.kind === 'host_path'),
|
|
@@ -85,6 +85,8 @@ export class HostArtifactCoordinator {
|
|
|
85
85
|
async #ingest(input, context) {
|
|
86
86
|
try {
|
|
87
87
|
if ((await this.#sessions.probeSessionRemoval(input.sessionId)).kind !== 'present') {
|
|
88
|
+
// Session removal can race an upload; release only this owner's staged bytes.
|
|
89
|
+
this.#uploads.abort(uploadKey(input.sessionId, input.uploadId), context);
|
|
88
90
|
return ingestFailure('not_found', 'Session was not found');
|
|
89
91
|
}
|
|
90
92
|
switch (input.kind) {
|
|
@@ -26,7 +26,7 @@ import { emptyPlanSessionState } from '@maka/core/plan';
|
|
|
26
26
|
import { readLogicalRuntimeExecutionForRun } from '@maka/core/runtime-logical-execution';
|
|
27
27
|
import { runtimeInvocationOutcome, } from '@maka/core/runtime-invocation';
|
|
28
28
|
import { isDeepResearchSession, WORKHUB_COORDINATION_SESSION_ID, WORKHUB_COORDINATION_REPLACEMENT_SCHEMA_VERSION, } from '@maka/core/session';
|
|
29
|
-
import { AgentGraphCoordinator } from '@maka/runtime/stream-graph-coordinator';
|
|
29
|
+
import { AgentGraphClientOperationError, AgentGraphCoordinator, } from '@maka/runtime/stream-graph-coordinator';
|
|
30
30
|
import { AgentGraphSupervisorWakeCoordinator } from '@maka/runtime/agent-graph-supervisor-wake';
|
|
31
31
|
import { BackendRegistry, SessionManager, workHubDirectStopAbortSource, } from '@maka/runtime/session-manager';
|
|
32
32
|
import { buildToolsForAgentDefinition } from '@maka/runtime/agent-catalog';
|
|
@@ -136,7 +136,7 @@ import { HostSessionRevisionCoordinator } from './session-revision-coordinator.j
|
|
|
136
136
|
import { HostSessionEffectCoordinator } from './session-effect-coordinator.js';
|
|
137
137
|
import { SessionContinuityCoordinator } from './session-continuity-coordinator.js';
|
|
138
138
|
import { createSessionTranscriptReader, } from './session-transcript-reader.js';
|
|
139
|
-
import { HostSkillCatalogCoordinator } from './skill-catalog-coordinator.js';
|
|
139
|
+
import { HostSkillCatalogCoordinator, SkillCatalogInvocableContextError, } from './skill-catalog-coordinator.js';
|
|
140
140
|
import { SkillCatalogRepository } from './skill-catalog-repository.js';
|
|
141
141
|
import { HostSessionTodoCoordinator } from './session-todo-coordinator.js';
|
|
142
142
|
import { HostTurnControlCoordinator } from './turn-control-coordinator.js';
|
|
@@ -500,8 +500,33 @@ export async function createExecutionRuntimeHostComposition(context, options = {
|
|
|
500
500
|
}), workspaceResolver, async (input, connection) => {
|
|
501
501
|
if (input.target.kind === 'session') {
|
|
502
502
|
const sessionId = input.target.sessionId;
|
|
503
|
-
|
|
504
|
-
|
|
503
|
+
let header;
|
|
504
|
+
try {
|
|
505
|
+
header = await stores.sessionStore.readHeaderSnapshot(sessionId);
|
|
506
|
+
}
|
|
507
|
+
catch (error) {
|
|
508
|
+
if (isSessionNotFoundError(error)) {
|
|
509
|
+
throw new SkillCatalogInvocableContextError('not_found', 'Session does not exist');
|
|
510
|
+
}
|
|
511
|
+
throw error;
|
|
512
|
+
}
|
|
513
|
+
if (header.isArchived) {
|
|
514
|
+
throw new SkillCatalogInvocableContextError('session_archived', 'Session is archived');
|
|
515
|
+
}
|
|
516
|
+
let preview;
|
|
517
|
+
try {
|
|
518
|
+
preview = await requireClientCapabilities(clientCapabilities).runWithSessionBindingPreview(sessionId, connection.connectionId, () => requireToolNameResolver(resolveAvailableToolNames)(sessionId));
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
if (isSessionNotFoundError(error)) {
|
|
522
|
+
throw new SkillCatalogInvocableContextError('not_found', 'Session does not exist');
|
|
523
|
+
}
|
|
524
|
+
if (error instanceof AgentGraphClientOperationError &&
|
|
525
|
+
error.code === 'session_archived') {
|
|
526
|
+
throw new SkillCatalogInvocableContextError('session_archived', 'Session is archived');
|
|
527
|
+
}
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
505
530
|
if (!preview.ok)
|
|
506
531
|
throw new Error(preview.message);
|
|
507
532
|
return {
|
|
@@ -86,8 +86,11 @@ export class HostGoalCoordinator {
|
|
|
86
86
|
acquireActivity: () => this.#acquireResidency(),
|
|
87
87
|
evaluator: options.evaluator,
|
|
88
88
|
getRecentContext: async (sessionId) => {
|
|
89
|
+
const controlLease = this.manager.getControlLease(sessionId);
|
|
89
90
|
const messages = await options.readSessionMessages(sessionId);
|
|
90
|
-
|
|
91
|
+
if (controlLease && this.manager.matchesControlLease(sessionId, controlLease)) {
|
|
92
|
+
tokenCache.set(sessionId, tokenCount(messages));
|
|
93
|
+
}
|
|
91
94
|
return recentContext(messages);
|
|
92
95
|
},
|
|
93
96
|
getTokenCount: (sessionId) => tokenCache.get(sessionId) ?? 0,
|
|
@@ -212,6 +215,7 @@ export class HostGoalCoordinator {
|
|
|
212
215
|
for (const sessionId of unique) {
|
|
213
216
|
operations.get(sessionId)?.commit();
|
|
214
217
|
this.#authorityBySession.delete(sessionId);
|
|
218
|
+
this.#tokenCache.delete(sessionId);
|
|
215
219
|
if (this.manager.remove(sessionId))
|
|
216
220
|
this.#onProjectionChanged(sessionId);
|
|
217
221
|
}
|
|
@@ -276,6 +280,7 @@ export class HostGoalCoordinator {
|
|
|
276
280
|
this.#recoveryAbort.abort();
|
|
277
281
|
this.continuation.dispose();
|
|
278
282
|
this.manager.dispose();
|
|
283
|
+
this.#tokenCache.clear();
|
|
279
284
|
for (const residency of this.#residencies.values())
|
|
280
285
|
residency.release();
|
|
281
286
|
this.#residencies.clear();
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
19
20
|
import { buildSideConversationSystemPromptFragment, isSideConversationSession, } from '@maka/core/side-conversation';
|
|
20
21
|
import { buildDeepResearchSystemPromptFragment, isDeepResearchSession, } from '@maka/core/deep-research';
|
|
21
22
|
import { activePlanExecution } from '@maka/core/plan';
|
|
@@ -100,6 +101,7 @@ export function createInteractiveRunComposer(input) {
|
|
|
100
101
|
const childInstruction = input.childInstruction?.trim();
|
|
101
102
|
const runProfile = hostedExecutionRunProfile(input.toolProfile);
|
|
102
103
|
const resolvedBaseSystemPrompts = new Map();
|
|
104
|
+
let latestCompletedPromptText;
|
|
103
105
|
const resolveBaseSystemPrompt = (context) => {
|
|
104
106
|
if (runProfile) {
|
|
105
107
|
return (input.resolveProfileSystemPrompt
|
|
@@ -146,8 +148,13 @@ export function createInteractiveRunComposer(input) {
|
|
|
146
148
|
input.deepResearch ? buildDeepResearchSystemPromptFragment() : undefined,
|
|
147
149
|
input.sideConversation ? buildSideConversationSystemPromptFragment() : undefined,
|
|
148
150
|
]);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
// Keep each turn's source revisions independent while sharing identical
|
|
152
|
+
// immutable text already retained by the turn cache.
|
|
153
|
+
const sharedText = latestCompletedPromptText !== undefined && latestCompletedPromptText.text === text
|
|
154
|
+
? latestCompletedPromptText.text
|
|
155
|
+
: text;
|
|
156
|
+
const resolvedPrompt = Object.freeze({
|
|
157
|
+
text: sharedText,
|
|
151
158
|
sourceRevisions: interactiveSourceRevisions({
|
|
152
159
|
runtimePolicyRevision: promptState.runtimePolicyRevision,
|
|
153
160
|
memoryBundleRevision: promptState.memoryBundleRevision,
|
|
@@ -155,6 +162,10 @@ export function createInteractiveRunComposer(input) {
|
|
|
155
162
|
skillCatalogRevision: inventory.revision,
|
|
156
163
|
}),
|
|
157
164
|
});
|
|
165
|
+
if (resolvedBaseSystemPrompts.get(key) === pending) {
|
|
166
|
+
latestCompletedPromptText = { key, text: sharedText };
|
|
167
|
+
}
|
|
168
|
+
return resolvedPrompt;
|
|
158
169
|
})
|
|
159
170
|
.catch((error) => {
|
|
160
171
|
if (resolvedBaseSystemPrompts.get(key) === pending)
|
|
@@ -164,8 +175,11 @@ export function createInteractiveRunComposer(input) {
|
|
|
164
175
|
resolvedBaseSystemPrompts.set(key, pending);
|
|
165
176
|
if (resolvedBaseSystemPrompts.size > 100) {
|
|
166
177
|
const oldest = resolvedBaseSystemPrompts.keys().next().value;
|
|
167
|
-
if (typeof oldest === 'string' && oldest !== key)
|
|
178
|
+
if (typeof oldest === 'string' && oldest !== key) {
|
|
168
179
|
resolvedBaseSystemPrompts.delete(oldest);
|
|
180
|
+
if (latestCompletedPromptText?.key === oldest)
|
|
181
|
+
latestCompletedPromptText = undefined;
|
|
182
|
+
}
|
|
169
183
|
}
|
|
170
184
|
return pending;
|
|
171
185
|
};
|
|
@@ -422,6 +436,7 @@ function buildPlanTraceContext(state, mode) {
|
|
|
422
436
|
}
|
|
423
437
|
function createTurnSkillInventorySnapshotResolver(skills, pluginSkills) {
|
|
424
438
|
const inventoryByTurn = new Map();
|
|
439
|
+
let latestCompleted;
|
|
425
440
|
return async (context) => {
|
|
426
441
|
const key = `${context.sessionId}\u0000${context.turnId}`;
|
|
427
442
|
const cached = inventoryByTurn.get(key);
|
|
@@ -464,12 +479,28 @@ function createTurnSkillInventorySnapshotResolver(skills, pluginSkills) {
|
|
|
464
479
|
.digest('hex'),
|
|
465
480
|
inventory: Object.freeze([...additions, ...base.inventory]),
|
|
466
481
|
});
|
|
482
|
+
})
|
|
483
|
+
.then((snapshot) => {
|
|
484
|
+
// An evicted late read still resolves its caller without acquiring another owner.
|
|
485
|
+
if (inventoryByTurn.get(key) !== pending)
|
|
486
|
+
return snapshot;
|
|
487
|
+
// Revisions omit some raw paths and ordering, so sharing requires full equality.
|
|
488
|
+
const shared = latestCompleted !== undefined &&
|
|
489
|
+
latestCompleted.snapshot.revision === snapshot.revision &&
|
|
490
|
+
isDeepStrictEqual(latestCompleted.snapshot, snapshot)
|
|
491
|
+
? latestCompleted.snapshot
|
|
492
|
+
: snapshot;
|
|
493
|
+
latestCompleted = { key, snapshot: shared };
|
|
494
|
+
return shared;
|
|
467
495
|
});
|
|
468
496
|
inventoryByTurn.set(key, pending);
|
|
469
497
|
if (inventoryByTurn.size > 100) {
|
|
470
498
|
const oldest = inventoryByTurn.keys().next().value;
|
|
471
|
-
if (typeof oldest === 'string' && oldest !== key)
|
|
499
|
+
if (typeof oldest === 'string' && oldest !== key) {
|
|
472
500
|
inventoryByTurn.delete(oldest);
|
|
501
|
+
if (latestCompleted?.key === oldest)
|
|
502
|
+
latestCompleted = undefined;
|
|
503
|
+
}
|
|
473
504
|
}
|
|
474
505
|
try {
|
|
475
506
|
return await pending;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { randomUUID } from 'node:crypto';
|
|
19
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
20
20
|
import { isDeepStrictEqual } from 'node:util';
|
|
21
21
|
import { aggregateMessageContents, messageContentDigest, messageContentsEqual, normalizeMessageContent, } from '@maka/core/events';
|
|
22
22
|
import { RuntimeMessageAuthorityInvariantError, } from '@maka/runtime/message-authority';
|
|
@@ -673,7 +673,7 @@ export class HostMessageCoordinator {
|
|
|
673
673
|
if (isCurrentEpoch) {
|
|
674
674
|
const receipt = await this.#readCompletedSubmit(input.sessionId, input.messageId);
|
|
675
675
|
if (receipt) {
|
|
676
|
-
return samePayload(receipt.
|
|
676
|
+
return samePayload(receipt.payloadIdentity, completedPayloadIdentity('submit', payload))
|
|
677
677
|
? success(receipt.result)
|
|
678
678
|
: failure('operation_conflict', 'Message identity has a different payload');
|
|
679
679
|
}
|
|
@@ -1064,7 +1064,7 @@ export class HostMessageCoordinator {
|
|
|
1064
1064
|
}
|
|
1065
1065
|
const receipt = await this.#readCompletedQueuedMutation(options);
|
|
1066
1066
|
if (receipt) {
|
|
1067
|
-
return samePayload(receipt.
|
|
1067
|
+
return samePayload(receipt.payloadIdentity, completedPayloadIdentity(options.operationKind, options.input))
|
|
1068
1068
|
? success(receipt.result)
|
|
1069
1069
|
: failure('operation_conflict', `${options.verb} identity has a different payload`);
|
|
1070
1070
|
}
|
|
@@ -1077,7 +1077,7 @@ export class HostMessageCoordinator {
|
|
|
1077
1077
|
return undefined;
|
|
1078
1078
|
try {
|
|
1079
1079
|
return {
|
|
1080
|
-
|
|
1080
|
+
payloadIdentity: receipt.payloadIdentity,
|
|
1081
1081
|
result: options.spec.decodeOutput(receipt.result),
|
|
1082
1082
|
};
|
|
1083
1083
|
}
|
|
@@ -1334,7 +1334,7 @@ export class HostMessageCoordinator {
|
|
|
1334
1334
|
}
|
|
1335
1335
|
const completed = await this.#readCompletedInterrupt(input.sessionId, input.interruptId);
|
|
1336
1336
|
if (completed) {
|
|
1337
|
-
return samePayload(completed.
|
|
1337
|
+
return samePayload(completed.payloadIdentity, input)
|
|
1338
1338
|
? completed.result
|
|
1339
1339
|
: failure('operation_conflict', 'Interrupt identity has a different payload');
|
|
1340
1340
|
}
|
|
@@ -1512,7 +1512,7 @@ export class HostMessageCoordinator {
|
|
|
1512
1512
|
return undefined;
|
|
1513
1513
|
try {
|
|
1514
1514
|
return {
|
|
1515
|
-
|
|
1515
|
+
payloadIdentity: receipt.payloadIdentity,
|
|
1516
1516
|
result: MESSAGE_OPERATION_SPECS['turn.message.submit'].decodeOutput(receipt.result),
|
|
1517
1517
|
};
|
|
1518
1518
|
}
|
|
@@ -1526,7 +1526,7 @@ export class HostMessageCoordinator {
|
|
|
1526
1526
|
return undefined;
|
|
1527
1527
|
try {
|
|
1528
1528
|
return {
|
|
1529
|
-
|
|
1529
|
+
payloadIdentity: receipt.payloadIdentity,
|
|
1530
1530
|
result: decodeCompletedInterruptOutcome(receipt.result),
|
|
1531
1531
|
};
|
|
1532
1532
|
}
|
|
@@ -1536,7 +1536,10 @@ export class HostMessageCoordinator {
|
|
|
1536
1536
|
}
|
|
1537
1537
|
#rememberCompletedOperation(operation, sessionId, operationId, payload, result) {
|
|
1538
1538
|
const key = queuedMutationKey(operation, sessionId, operationId);
|
|
1539
|
-
const receipt = {
|
|
1539
|
+
const receipt = {
|
|
1540
|
+
payloadIdentity: structuredClone(completedPayloadIdentity(operation, payload)),
|
|
1541
|
+
result: structuredClone(result),
|
|
1542
|
+
};
|
|
1540
1543
|
const committed = this.#completedOperations.get(key);
|
|
1541
1544
|
if (committed && !isDeepStrictEqual(committed, receipt)) {
|
|
1542
1545
|
throw new RuntimeMessageAuthorityInvariantError('Message operation replay identity has an ambiguous outcome');
|
|
@@ -1985,6 +1988,19 @@ function fitsEncodedByteLimit(value, maxBytes) {
|
|
|
1985
1988
|
function isEntityId(value) {
|
|
1986
1989
|
return /^[A-Za-z0-9_-]{1,128}$/.test(value);
|
|
1987
1990
|
}
|
|
1991
|
+
// Epoch-long replay needs the original result and request identity, not historical message bodies.
|
|
1992
|
+
function completedPayloadIdentity(operation, payload) {
|
|
1993
|
+
if (operation === 'submit') {
|
|
1994
|
+
const { content, ...identity } = payload;
|
|
1995
|
+
return { ...identity, contentDigest: messageContentDigest(content) };
|
|
1996
|
+
}
|
|
1997
|
+
if (operation === 'update_entry') {
|
|
1998
|
+
const { text, ...identity } = payload;
|
|
1999
|
+
// UTF-16 preserves distinct JS strings even when they contain unpaired surrogates.
|
|
2000
|
+
return { ...identity, textDigest: createHash('sha256').update(text, 'utf16le').digest('hex') };
|
|
2001
|
+
}
|
|
2002
|
+
return payload;
|
|
2003
|
+
}
|
|
1988
2004
|
function canonicalSubmitPayload(input) {
|
|
1989
2005
|
return {
|
|
1990
2006
|
originHostEpoch: input.originHostEpoch,
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { isDeepStrictEqual } from 'node:util';
|
|
20
|
-
import {
|
|
20
|
+
import { messageContentDigest, normalizeMessageContent, } from '@maka/core/events';
|
|
21
21
|
import { submittedTurnIntentsEqual } from '@maka/storage/execution-stores';
|
|
22
22
|
export class RootAdmissionOwner {
|
|
23
23
|
store;
|
|
@@ -44,7 +44,7 @@ export class RootAdmissionOwner {
|
|
|
44
44
|
const snapshots = Object.freeze(admissions.map(snapshotAdmission));
|
|
45
45
|
const byTurnId = new Map();
|
|
46
46
|
for (const admission of snapshots)
|
|
47
|
-
byTurnId.set(admission.turnId, admission);
|
|
47
|
+
byTurnId.set(admission.turnId, admissionIdentity(admission));
|
|
48
48
|
this.#admissionsBySession.set(sessionId, byTurnId);
|
|
49
49
|
const tip = snapshots.at(-1);
|
|
50
50
|
if (tip)
|
|
@@ -67,7 +67,7 @@ export class RootAdmissionOwner {
|
|
|
67
67
|
if (!known || !sameRootAdmission(known, admission)) {
|
|
68
68
|
throw new Error('Durable Root Turn conflict is outside the owned chain');
|
|
69
69
|
}
|
|
70
|
-
return Object.freeze({ kind: 'conflict', admission:
|
|
70
|
+
return Object.freeze({ kind: 'conflict', admission: snapshotAdmission(admission) });
|
|
71
71
|
}
|
|
72
72
|
if (admission.sessionId !== input.sessionId ||
|
|
73
73
|
admission.turnId !== input.turnId ||
|
|
@@ -80,7 +80,7 @@ export class RootAdmissionOwner {
|
|
|
80
80
|
throw new Error('Root Turn admission identity changed within one Host Epoch');
|
|
81
81
|
}
|
|
82
82
|
const snapshot = snapshotAdmission(admission);
|
|
83
|
-
byTurnId.set(admission.turnId, snapshot);
|
|
83
|
+
byTurnId.set(admission.turnId, admissionIdentity(snapshot));
|
|
84
84
|
this.#admissionsBySession.set(input.sessionId, byTurnId);
|
|
85
85
|
this.#tips.set(input.sessionId, snapshot);
|
|
86
86
|
return Object.freeze({ ...result, admission: snapshot });
|
|
@@ -91,6 +91,16 @@ export class RootAdmissionOwner {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
// Historical admissions must remain verifiable throughout the Host Epoch, but
|
|
95
|
+
// only the current tip needs to own the full message bodies.
|
|
96
|
+
function admissionIdentity(admission) {
|
|
97
|
+
const { normalizedInput, sourceMessages, ...metadata } = admission;
|
|
98
|
+
return Object.freeze({
|
|
99
|
+
...structuredClone(metadata),
|
|
100
|
+
normalizedInputDigest: normalizedInput === null ? null : messageContentDigest(normalizedInput),
|
|
101
|
+
sourceMessages: Object.freeze(sourceMessages.map(({ content, ...source }) => Object.freeze({ ...structuredClone(source), contentDigest: messageContentDigest(content) }))),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
94
104
|
function sameRootAdmission(left, right) {
|
|
95
105
|
return (left.schemaVersion === right.schemaVersion &&
|
|
96
106
|
left.sessionId === right.sessionId &&
|
|
@@ -102,9 +112,8 @@ function sameRootAdmission(left, right) {
|
|
|
102
112
|
isDeepStrictEqual(left.skillInvocation, right.skillInvocation) &&
|
|
103
113
|
isDeepStrictEqual(left.authorization, right.authorization) &&
|
|
104
114
|
left.previousRootTurnId === right.previousRootTurnId &&
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
: messageContentsEqual(left.normalizedInput, right.normalizedInput)) &&
|
|
115
|
+
left.normalizedInputDigest ===
|
|
116
|
+
(right.normalizedInput === null ? null : messageContentDigest(right.normalizedInput)) &&
|
|
108
117
|
left.sourceMessages.length === right.sourceMessages.length &&
|
|
109
118
|
left.sourceMessages.every((source, index) => {
|
|
110
119
|
const other = right.sourceMessages[index];
|
|
@@ -117,7 +126,7 @@ function sameRootAdmission(left, right) {
|
|
|
117
126
|
(other.submittedPlacement ?? other.placement) &&
|
|
118
127
|
submittedTurnIntentsEqual(source.submittedIntent, other.submittedIntent) &&
|
|
119
128
|
isDeepStrictEqual(source.skillInvocation, other.skillInvocation) &&
|
|
120
|
-
|
|
129
|
+
source.contentDigest === messageContentDigest(other.content));
|
|
121
130
|
}) &&
|
|
122
131
|
left.admittedAt === right.admittedAt);
|
|
123
132
|
}
|
|
@@ -27,10 +27,9 @@ export function canonicalRuntimeResources(resources) {
|
|
|
27
27
|
left.sourceToolCallId.localeCompare(right.sourceToolCallId));
|
|
28
28
|
}
|
|
29
29
|
function boundedRuntimeResourceUpdate(update) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
30
|
+
const bounded = structuredClone(update);
|
|
31
|
+
shrinkStateToFit(bounded.result);
|
|
32
|
+
return bounded;
|
|
34
33
|
}
|
|
35
34
|
export function runtimeResourceRevision(resources) {
|
|
36
35
|
return `sha256:${createHash('sha256').update(JSON.stringify(resources)).digest('hex')}`;
|
|
@@ -83,11 +82,6 @@ export function runtimeResourceSnapshotFromResult(result) {
|
|
|
83
82
|
const { operation: _operation, ...snapshot } = result;
|
|
84
83
|
return snapshot;
|
|
85
84
|
}
|
|
86
|
-
function boundedState(state) {
|
|
87
|
-
const bounded = structuredClone(state);
|
|
88
|
-
shrinkStateToFit(bounded);
|
|
89
|
-
return bounded;
|
|
90
|
-
}
|
|
91
85
|
function shrinkStateToFit(state) {
|
|
92
86
|
while (Buffer.byteLength(JSON.stringify(state), 'utf8') > RUNTIME_RESOURCE_SNAPSHOT_MAX_BYTES) {
|
|
93
87
|
const fields = mutableTextFields(state).sort((left, right) => Buffer.byteLength(right.value(), 'utf8') - Buffer.byteLength(left.value(), 'utf8'));
|