maka-agent 0.2.0-dev.34.20260915 → 0.2.0-dev.35.20260915

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.
Files changed (31) hide show
  1. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  2. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +2 -18
  3. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -2
  4. package/node_modules/@maka/runtime/dist/provider-error-classification.js +29 -38
  5. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +4 -1
  6. package/node_modules/@maka/runtime-host/dist/client/wait-for-ready.js +1 -1
  7. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +7 -6
  8. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +2 -2
  9. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +1 -0
  10. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +942 -0
  11. package/node_modules/@maka/storage/dist/agent-run-store.js +3 -923
  12. package/node_modules/@maka/storage/dist/artifact-store.js +63 -7
  13. package/node_modules/@maka/storage/dist/execution-persistence-provider.js +54 -0
  14. package/node_modules/@maka/storage/dist/execution-stores.js +181 -58
  15. package/node_modules/@maka/storage/dist/goal-authority.js +39 -8
  16. package/node_modules/@maka/storage/dist/graph-control-values.js +126 -0
  17. package/node_modules/@maka/storage/dist/interaction-store-contract.js +231 -0
  18. package/node_modules/@maka/storage/dist/interaction-store.js +62 -217
  19. package/node_modules/@maka/storage/dist/local-execution-persistence.js +80 -0
  20. package/node_modules/@maka/storage/dist/root-authority.js +4 -0
  21. package/node_modules/@maka/storage/dist/runtime-event-store-contract.js +19 -0
  22. package/node_modules/@maka/storage/dist/runtime-partial-values.js +114 -0
  23. package/node_modules/@maka/storage/dist/session-store-contract.js +61 -0
  24. package/node_modules/@maka/storage/dist/session-store-values.js +342 -0
  25. package/node_modules/@maka/storage/dist/session-store.js +7 -351
  26. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +4 -185
  27. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +9 -129
  28. package/node_modules/@maka/storage/dist/storage-writer-composition.js +2 -3
  29. package/node_modules/@maka/storage/dist/tool-commit-validation.js +111 -0
  30. package/node_modules/@maka/storage/package.json +1 -0
  31. package/package.json +1 -1
@@ -16,6 +16,8 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { SessionMetadataConflictError, SessionMetadataVersionConflictError, } from './session-store-contract.js';
20
+ export { SessionMetadataConflictError, SessionMetadataVersionConflictError, } from './session-store-contract.js';
19
21
  import { createRequire } from 'node:module';
20
22
  import { createHash } from 'node:crypto';
21
23
  import { dirname, resolve } from 'node:path';
@@ -35,7 +37,8 @@ import { normalizePendingMessageAdmission, normalizeProvenRootMessageHandoff, no
35
37
  import { normalizeSubmittedTurnIntent } from './submitted-turn-intent.js';
36
38
  import { messageContentDigest, messageContentsEqual, normalizeMessageContent, } from '@maka/core/events';
37
39
  import { AGENT_GRAPH_SUPERVISOR_WAKE_SCHEMA_VERSION, } from '@maka/core/agent-graph-supervisor-wake';
38
- import { assertSafeSessionId, decodePersistedSessionHeader, normalizeSessionHeader, SessionNotFoundError, } from './session-store.js';
40
+ import { assertSafeSessionId, SessionNotFoundError, } from './session-store-contract.js';
41
+ import { decodePersistedSessionHeader, normalizeSessionHeader } from './session-store.js';
39
42
  import { isDiscardableConversationCopy, isValidConversationCopyTransition, } from './session-conversation-copy.js';
40
43
  import { projectSessionCatalogMessages } from './session-message-projection.js';
41
44
  import { configureSqliteSessionMetadataDatabase, migrateSqliteSessionMetadataDatabase, readSqliteSessionMetadataSchemaVersion, SQLITE_AGENT_GRAPH_CONTROL_TABLES, SQLITE_SESSION_MESSAGE_CHUNK_BYTES, SQLITE_SESSION_MESSAGE_CHUNK_MARKER, } from './sqlite-session-metadata-schema.js';
@@ -118,9 +121,6 @@ function uniqueVersionedSessionIdentities(sessions) {
118
121
  }
119
122
  return [...unique.values()].sort((left, right) => left.sessionId.localeCompare(right.sessionId));
120
123
  }
121
- export class SessionMetadataConflictError extends Error {
122
- name = 'SessionMetadataConflictError';
123
- }
124
124
  export class StoredSessionMessageIncompatibleError extends Error {
125
125
  sessionId;
126
126
  sequence;
@@ -132,24 +132,9 @@ export class StoredSessionMessageIncompatibleError extends Error {
132
132
  this.sequence = sequence;
133
133
  }
134
134
  }
135
- export class SessionMetadataVersionConflictError extends SessionMetadataConflictError {
136
- sessionId;
137
- expectedVersion;
138
- actualVersion;
139
- name = 'SessionMetadataVersionConflictError';
140
- constructor(sessionId, expectedVersion, actualVersion) {
141
- super(`Session metadata version conflict for ${sessionId}: expected ${expectedVersion}, found ${actualVersion}`);
142
- this.sessionId = sessionId;
143
- this.expectedVersion = expectedVersion;
144
- this.actualVersion = actualVersion;
145
- }
146
- }
147
- export class AgentGraphIntentClaimConflictError extends SessionMetadataConflictError {
148
- name = 'AgentGraphIntentClaimConflictError';
149
- }
150
- export class AgentGraphScheduleUpdateConflictError extends SessionMetadataConflictError {
151
- name = 'AgentGraphScheduleUpdateConflictError';
152
- }
135
+ import { AgentGraphIntentClaimConflictError, AgentGraphScheduleUpdateConflictError, } from './session-store-contract.js';
136
+ export { AgentGraphIntentClaimConflictError, AgentGraphScheduleUpdateConflictError, } from './session-store-contract.js';
137
+ import { assertGraphLookupIdentity, assertAgentGraphSupervisorWakeClaim, assertAgentGraphSupervisorWakeAttempt, assertAgentGraphSupervisorWakeCompletion, assertAgentGraphClientProjectionRequest, encodeProjectionPayload, assertGraphEventTime, assertGraphIntentId, } from './graph-control-values.js';
153
138
  export function createSqliteSessionMetadataStore(path, options = {}) {
154
139
  return new SqliteSessionMetadataStore(path, options);
155
140
  }
@@ -4408,15 +4393,6 @@ function requireManagedProfile(boundary) {
4408
4393
  throw new Error('Expected a managed execution boundary');
4409
4394
  return boundary.profile;
4410
4395
  }
4411
- function assertGraphLookupIdentity(value, name) {
4412
- if (typeof value !== 'string' ||
4413
- value.length === 0 ||
4414
- value.length > 256 ||
4415
- value.trim() !== value ||
4416
- /[\u0000-\u001f\u007f]/.test(value)) {
4417
- throw new Error(`Invalid agent graph ${name}`);
4418
- }
4419
- }
4420
4396
  function assertSafeBoundaryRequestId(value) {
4421
4397
  if (!/^[A-Za-z0-9_-]{1,128}$/.test(value)) {
4422
4398
  throw new Error('Invalid sandbox boundary request id');
@@ -4431,92 +4407,6 @@ function assertSandboxBoundaryProvenanceId(value, name) {
4431
4407
  throw new Error(`Invalid sandbox boundary ${name}`);
4432
4408
  }
4433
4409
  }
4434
- function assertAgentGraphSupervisorWakeClaim(request) {
4435
- if (request.schemaVersion !== AGENT_GRAPH_SUPERVISOR_WAKE_SCHEMA_VERSION) {
4436
- throw new Error('Invalid agent graph supervisor wake schema');
4437
- }
4438
- assertGraphLookupIdentity(request.graphId, 'graph id');
4439
- assertGraphLookupIdentity(request.wakeId, 'supervisor wake id');
4440
- assertGraphLookupIdentity(request.snapshotVersion, 'snapshot version');
4441
- assertSafeSessionId(request.rootSessionId);
4442
- }
4443
- function assertAgentGraphSupervisorWakeAttempt(request) {
4444
- assertGraphLookupIdentity(request.graphId, 'graph id');
4445
- assertGraphLookupIdentity(request.wakeId, 'supervisor wake id');
4446
- assertGraphLookupIdentity(request.attemptId, 'supervisor wake attempt id');
4447
- assertGraphLookupIdentity(request.turnId, 'supervisor wake turn id');
4448
- }
4449
- function assertAgentGraphSupervisorWakeCompletion(request) {
4450
- assertGraphLookupIdentity(request.graphId, 'graph id');
4451
- assertGraphLookupIdentity(request.wakeId, 'supervisor wake id');
4452
- assertGraphLookupIdentity(request.attemptId, 'supervisor wake attempt id');
4453
- if (request.status !== 'waiting_permission' &&
4454
- request.status !== 'delivered' &&
4455
- request.status !== 'superseded' &&
4456
- request.status !== 'retryable_failed') {
4457
- throw new Error('Invalid agent graph supervisor wake completion status');
4458
- }
4459
- if ((request.status === 'retryable_failed' || request.status === 'superseded') &&
4460
- (!request.failureReason?.trim() || request.failureReason.length > 4_000)) {
4461
- throw new Error('Agent graph supervisor wake failure reason must be non-empty and bounded');
4462
- }
4463
- }
4464
- function assertAgentGraphClientProjectionRequest(request) {
4465
- if (request.schemaVersion !== AGENT_GRAPH_CLIENT_PROJECTION_SCHEMA_VERSION ||
4466
- (request.expectedSnapshotVersion !== null &&
4467
- typeof request.expectedSnapshotVersion !== 'string') ||
4468
- typeof request.replaceOperators !== 'boolean' ||
4469
- !Array.isArray(request.operators) ||
4470
- !Array.isArray(request.terminalActivities) ||
4471
- !Array.isArray(request.activityRecords)) {
4472
- throw new Error('Invalid agent graph client projection request');
4473
- }
4474
- assertGraphLookupIdentity(request.graphId, 'graph id');
4475
- assertSafeSessionId(request.rootSessionId);
4476
- if (request.expectedSnapshotVersion !== null) {
4477
- assertGraphLookupIdentity(request.expectedSnapshotVersion, 'expected snapshot version');
4478
- }
4479
- assertGraphLookupIdentity(request.snapshotVersion, 'snapshot version');
4480
- const operatorIds = new Set();
4481
- for (const operator of request.operators) {
4482
- assertGraphLookupIdentity(operator.operatorId, 'operator id');
4483
- if (operatorIds.has(operator.operatorId)) {
4484
- throw new Error(`Duplicate agent graph client operator ${operator.operatorId}`);
4485
- }
4486
- operatorIds.add(operator.operatorId);
4487
- }
4488
- const terminalIds = new Set();
4489
- for (const terminal of request.terminalActivities) {
4490
- assertGraphLookupIdentity(terminal.recordId, 'terminal record id');
4491
- assertGraphEventTime(terminal.eventTime);
4492
- if (terminalIds.has(terminal.recordId)) {
4493
- throw new Error(`Duplicate agent graph terminal activity ${terminal.recordId}`);
4494
- }
4495
- terminalIds.add(terminal.recordId);
4496
- }
4497
- const activityIds = new Set();
4498
- for (const record of request.activityRecords) {
4499
- assertGraphLookupIdentity(record.recordId, 'activity record id');
4500
- assertGraphEventTime(record.eventTime);
4501
- if (activityIds.has(record.recordId)) {
4502
- throw new Error(`Duplicate agent graph activity ${record.recordId}`);
4503
- }
4504
- activityIds.add(record.recordId);
4505
- }
4506
- if (request.incrementalRecordId !== undefined) {
4507
- assertGraphLookupIdentity(request.incrementalRecordId, 'incremental record id');
4508
- if (request.expectedSnapshotVersion === null || !activityIds.has(request.incrementalRecordId)) {
4509
- throw new Error('Invalid incremental agent graph projection record');
4510
- }
4511
- }
4512
- }
4513
- function encodeProjectionPayload(payload, name) {
4514
- const encoded = JSON.stringify(payload);
4515
- if (encoded === undefined) {
4516
- throw new Error(`Invalid agent graph ${name} payload`);
4517
- }
4518
- return encoded;
4519
- }
4520
4410
  function decodeAgentGraphClientProjectionRow(row) {
4521
4411
  if (row.schemaVersion !== AGENT_GRAPH_CLIENT_PROJECTION_SCHEMA_VERSION ||
4522
4412
  !Number.isSafeInteger(row.materializedAt) ||
@@ -4550,16 +4440,6 @@ function decodeAgentGraphClientOperatorProjectionRow(row) {
4550
4440
  materializedAt: row.materializedAt,
4551
4441
  };
4552
4442
  }
4553
- function assertGraphEventTime(value) {
4554
- if (!Number.isSafeInteger(value) || value < 0) {
4555
- throw new Error('Invalid agent graph terminal activity event time');
4556
- }
4557
- }
4558
- function assertGraphIntentId(value) {
4559
- if (!/^graph_intent_[a-f0-9]{32}$/.test(value)) {
4560
- throw new Error('Invalid agent graph intent id');
4561
- }
4562
- }
4563
4443
  function decodeStoredMessageRow(row, sessionId) {
4564
4444
  const sequence = requireStoredMessageSequence(row.sequence, sessionId);
4565
4445
  if (typeof row.record_json !== 'string') {
@@ -4638,7 +4518,7 @@ function sameWorkHubAssignmentRequest(existing, requested) {
4638
4518
  disposition: existing.disposition,
4639
4519
  userText: existing.userText,
4640
4520
  delegationText: existing.delegationText,
4641
- attachments: existing.attachments,
4521
+ attachments: existing.attachments ?? [],
4642
4522
  create: existing.create,
4643
4523
  replacesActionId: existing.replacesActionId,
4644
4524
  replacesDelegationId: existing.replacesDelegationId,
@@ -4650,7 +4530,7 @@ function sameWorkHubAssignmentRequest(existing, requested) {
4650
4530
  disposition: requested.disposition,
4651
4531
  userText: requested.userText,
4652
4532
  delegationText: requested.delegationText,
4653
- attachments: requested.attachments,
4533
+ attachments: requested.attachments ?? [],
4654
4534
  create: requested.create,
4655
4535
  replacesActionId: requested.replacesActionId,
4656
4536
  replacesDelegationId: requested.replacesDelegationId,
@@ -21,7 +21,6 @@ import { openInteractiveContextOffloadStoreForWrite } from './context-offload-st
21
21
  import { openInteractiveDailyReviewAuthorityForWrite } from './daily-review-authority.js';
22
22
  import { openInteractiveDeepResearchStoreForWrite } from './deep-research-authority.js';
23
23
  import { openInteractiveExecutionStoresForWrite } from './execution-stores.js';
24
- import { openInteractiveGoalAuthorityForWrite } from './goal-authority.js';
25
24
  import { openInteractiveLongTermMemoryStoreForWrite } from './long-term-memory-store.js';
26
25
  import { openInteractiveMemoryBundleStoreForWrite } from './memory-bundle-store.js';
27
26
  import { openInteractivePlanStoreForWrite } from './plan-authority.js';
@@ -71,7 +70,7 @@ async function createComposition(lease, options) {
71
70
  return failOpen(error);
72
71
  }
73
72
  };
74
- const execution = await openWriter(() => openInteractiveExecutionStoresForWrite(lease), (writer) => writer.sessionStore.close?.());
73
+ const execution = await openWriter(() => openInteractiveExecutionStoresForWrite(lease, options.executionProvider), (writer) => writer.sessionStore.close?.());
75
74
  try {
76
75
  await execution.sessionStore.ready();
77
76
  }
@@ -90,7 +89,7 @@ async function createComposition(lease, options) {
90
89
  const plan = await openWriter(() => openInteractivePlanStoreForWrite(lease), closeWriter);
91
90
  const deepResearch = await openWriter(() => openInteractiveDeepResearchStoreForWrite(lease), closeWriter);
92
91
  const dailyReview = await openWriter(() => openInteractiveDailyReviewAuthorityForWrite(lease), closeWriter);
93
- const goal = await openWriter(() => openInteractiveGoalAuthorityForWrite(lease), closeWriter);
92
+ const goal = execution.goalStore;
94
93
  const memoryBundle = await openWriter(() => openInteractiveMemoryBundleStoreForWrite(lease));
95
94
  const longTermMemory = await openWriter(() => openInteractiveLongTermMemoryStoreForWrite(lease), closeWriter);
96
95
  const sessionTodo = await openWriter(() => openInteractiveSessionTodoStoreForWrite(lease), closeWriter);
@@ -0,0 +1,111 @@
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
+ import { canonicalToolArgsHash } from '@maka/core/tool-args-identity';
20
+ import { validateToolLedgerEventLane } from '@maka/core/tool-ledger-scanner';
21
+ export function assertPreparedInput(input) {
22
+ if (input.journalEventId !== `${input.operationId}_prepared`) {
23
+ throw new Error('T1 journal identity must be derived from the tool operation');
24
+ }
25
+ assertNoReservedRecoveryFact(input.runtimeEvent);
26
+ assertNoReservedRecoveryFact(input.dispatchRuntimeEvent);
27
+ const content = input.runtimeEvent.content;
28
+ if (content?.kind !== 'function_call')
29
+ throw new Error('T1 requires a function_call RuntimeEvent');
30
+ if (content.id !== input.providerToolCallId || content.name !== input.toolName) {
31
+ throw new Error('T1 RuntimeEvent identity does not match the tool operation');
32
+ }
33
+ let derivedArgsHash;
34
+ try {
35
+ derivedArgsHash = canonicalToolArgsHash(content.name, content.args);
36
+ }
37
+ catch {
38
+ throw new Error('T1 argument hash does not match its canonical function call');
39
+ }
40
+ if (derivedArgsHash !== input.canonicalArgsHash ||
41
+ validateToolLedgerEventLane(input.runtimeEvent).ok !== true) {
42
+ throw new Error('T1 argument hash does not match its canonical function call');
43
+ }
44
+ const dispatch = input.dispatchRuntimeEvent.actions?.toolDispatch;
45
+ if (!dispatch ||
46
+ input.dispatchRuntimeEvent.content !== undefined ||
47
+ input.dispatchRuntimeEvent.partial ||
48
+ dispatch.operationId !== input.operationId ||
49
+ dispatch.providerToolCallId !== input.providerToolCallId ||
50
+ dispatch.toolName !== input.toolName ||
51
+ dispatch.canonicalArgsHash !== input.canonicalArgsHash ||
52
+ dispatch.recoveryMode !== input.recoveryMode ||
53
+ validateToolLedgerEventLane(input.dispatchRuntimeEvent).ok !== true) {
54
+ throw new Error('T1 requires a matching tool-dispatch RuntimeEvent');
55
+ }
56
+ assertSameRuntimeIdentity(input.runtimeEvent, input.dispatchRuntimeEvent, 'T1');
57
+ }
58
+ export function assertOutcomeInput(input) {
59
+ if (input.journalEventId !== `${input.operationId}_outcome`) {
60
+ throw new Error('T2 journal identity must be derived from the tool operation');
61
+ }
62
+ assertNoReservedRecoveryFact(input.runtimeEvent);
63
+ const content = input.runtimeEvent.content;
64
+ if (content?.kind !== 'function_response') {
65
+ throw new Error('T2 requires a function_response RuntimeEvent');
66
+ }
67
+ if (input.runtimeEvent.refs?.operationId !== input.operationId ||
68
+ input.runtimeEvent.refs?.toolCallId !== content.id) {
69
+ throw new Error('T2 requires operation and tool-call refs on the function_response RuntimeEvent');
70
+ }
71
+ if (validateToolLedgerEventLane(input.runtimeEvent).ok !== true) {
72
+ throw new Error('T2 requires one canonical function-response semantic lane');
73
+ }
74
+ }
75
+ export function assertPreparedIdentity(operation, input) {
76
+ const event = input.runtimeEvent;
77
+ const matches = operation.invocationId === event.invocationId &&
78
+ operation.runId === event.runId &&
79
+ operation.turnId === event.turnId &&
80
+ operation.providerToolCallId === input.providerToolCallId &&
81
+ operation.toolName === input.toolName &&
82
+ operation.canonicalArgsHash === input.canonicalArgsHash &&
83
+ operation.recoveryMode === input.recoveryMode &&
84
+ operation.callEventId === event.id &&
85
+ operation.dispatchEventId === input.dispatchRuntimeEvent.id;
86
+ if (!matches)
87
+ throw new Error(`Tool operation identity conflict for ${input.operationId}`);
88
+ }
89
+ export function assertSameRuntimeIdentity(first, second, boundary) {
90
+ if (first.sessionId !== second.sessionId ||
91
+ first.invocationId !== second.invocationId ||
92
+ first.runId !== second.runId ||
93
+ first.turnId !== second.turnId) {
94
+ throw new Error(`${boundary} RuntimeEvents do not share one execution identity`);
95
+ }
96
+ }
97
+ export function assertOutcomeIdentity(operation, event) {
98
+ const content = event.content;
99
+ const matches = content?.kind === 'function_response' &&
100
+ operation.invocationId === event.invocationId &&
101
+ operation.runId === event.runId &&
102
+ operation.turnId === event.turnId &&
103
+ operation.providerToolCallId === content.id &&
104
+ operation.toolName === content.name;
105
+ if (!matches)
106
+ throw new Error(`Tool operation outcome identity conflict for ${operation.operationId}`);
107
+ }
108
+ function assertNoReservedRecoveryFact(event) {
109
+ if (event.actions?.toolRecovery !== undefined)
110
+ throw new Error('Tool recovery facts require the atomic recovery bundle writer');
111
+ }
@@ -17,6 +17,7 @@
17
17
  "./deep-research-store": "./dist/deep-research-store.js",
18
18
  "./encrypted-file-managed-secret-store": "./dist/encrypted-file-managed-secret-store.js",
19
19
  "./execution-stores": "./dist/execution-stores.js",
20
+ "./execution-persistence-provider": "./dist/execution-persistence-provider.js",
20
21
  "./external-sessions": "./dist/external-sessions.js",
21
22
  "./file-lifetime-owner": "./dist/file-lifetime-owner.js",
22
23
  "./file-update-lock": "./dist/file-update-lock.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maka-agent",
3
- "version": "0.2.0-dev.34.20260915",
3
+ "version": "0.2.0-dev.35.20260915",
4
4
  "description": "Apache Maka (Incubating) developer snapshot; not an Apache release.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",