maka-agent 0.2.0-dev.32.20260914 → 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 (33) 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/eval/dist/metering-checkpoint.js +4 -4
  3. package/node_modules/@maka/eval/harbor/relay_agent.py +1 -2
  4. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +2 -18
  5. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -2
  6. package/node_modules/@maka/runtime/dist/provider-error-classification.js +29 -38
  7. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +4 -1
  8. package/node_modules/@maka/runtime-host/dist/client/wait-for-ready.js +1 -1
  9. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +7 -6
  10. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +2 -2
  11. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +1 -0
  12. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +942 -0
  13. package/node_modules/@maka/storage/dist/agent-run-store.js +3 -923
  14. package/node_modules/@maka/storage/dist/artifact-store.js +63 -7
  15. package/node_modules/@maka/storage/dist/execution-persistence-provider.js +54 -0
  16. package/node_modules/@maka/storage/dist/execution-stores.js +181 -58
  17. package/node_modules/@maka/storage/dist/goal-authority.js +39 -8
  18. package/node_modules/@maka/storage/dist/graph-control-values.js +126 -0
  19. package/node_modules/@maka/storage/dist/interaction-store-contract.js +231 -0
  20. package/node_modules/@maka/storage/dist/interaction-store.js +62 -217
  21. package/node_modules/@maka/storage/dist/local-execution-persistence.js +80 -0
  22. package/node_modules/@maka/storage/dist/root-authority.js +4 -0
  23. package/node_modules/@maka/storage/dist/runtime-event-store-contract.js +19 -0
  24. package/node_modules/@maka/storage/dist/runtime-partial-values.js +114 -0
  25. package/node_modules/@maka/storage/dist/session-store-contract.js +61 -0
  26. package/node_modules/@maka/storage/dist/session-store-values.js +342 -0
  27. package/node_modules/@maka/storage/dist/session-store.js +7 -351
  28. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +4 -185
  29. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +9 -129
  30. package/node_modules/@maka/storage/dist/storage-writer-composition.js +2 -3
  31. package/node_modules/@maka/storage/dist/tool-commit-validation.js +111 -0
  32. package/node_modules/@maka/storage/package.json +1 -0
  33. package/package.json +1 -1
@@ -0,0 +1,342 @@
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 { randomUUID } from 'node:crypto';
20
+ import { DEFAULT_SESSION_NAME, normalizeUserSessionName } from '@maka/core/session-name';
21
+ import { isExecutorId } from '@maka/core/executor-id';
22
+ import { isSessionBlockedReason, isSessionConversationCopy, isSubagentSessionParent, isSubagentSessionRuntime, isSubagentSessionSpawn, isSessionStatus, isWorkHubCoordinationSessionId, subagentSessionRuntimeSummary, WORKHUB_COORDINATION_SESSION_ROLE, isSessionToolProfile, } from '@maka/core/session';
23
+ import { isCollaborationMode } from '@maka/core/collaboration';
24
+ import { DEFAULT_TOOL_MODE, isToolMode } from '@maka/core/tool-mode';
25
+ import { isOrchestrationMode } from '@maka/core/orchestration';
26
+ import { decodePersistedPermissionMode, isPermissionMode } from '@maka/core/permission';
27
+ import { isSubagentWorkspaceBinding } from '@maka/core/subagent-workspace';
28
+ import { assertSafeSessionId, isSafeSessionId } from './session-store-contract.js';
29
+ export function assertCoordinationIdentityPairing(sessionId, role) {
30
+ if (isWorkHubCoordinationSessionId(sessionId) !== (role === WORKHUB_COORDINATION_SESSION_ROLE)) {
31
+ throw new Error('WorkHub Coordination Session identity and role must be claimed together');
32
+ }
33
+ }
34
+ export function buildSessionHeader(workspaceRoot, input, sessionId = randomUUID(), conversationCopy) {
35
+ if (input.projectId !== undefined &&
36
+ input.projectId !== null &&
37
+ (typeof input.projectId !== 'string' || input.projectId.length === 0)) {
38
+ throw new Error('Invalid project id');
39
+ }
40
+ const now = Date.now();
41
+ assertSafeSessionId(sessionId);
42
+ assertCoordinationIdentityPairing(sessionId, input.role);
43
+ const name = input.name === undefined ? DEFAULT_SESSION_NAME : normalizeRequiredSessionName(input.name);
44
+ const header = {
45
+ id: sessionId,
46
+ ...(input.role === undefined ? {} : { role: input.role }),
47
+ workspaceRoot,
48
+ cwd: input.cwd,
49
+ ...(input.projectId !== undefined ? { projectId: input.projectId } : {}),
50
+ createdAt: now,
51
+ name,
52
+ titleIsManual: false,
53
+ isFlagged: false,
54
+ labels: input.labels ?? [],
55
+ isArchived: false,
56
+ status: input.status ?? 'active',
57
+ ...(input.blockedReason ? { blockedReason: input.blockedReason } : {}),
58
+ statusUpdatedAt: now,
59
+ ...(input.parentSessionId ? { parentSessionId: input.parentSessionId } : {}),
60
+ ...(input.branchOfTurnId ? { branchOfTurnId: input.branchOfTurnId } : {}),
61
+ ...(input.subagentParent ? { subagentParent: input.subagentParent } : {}),
62
+ ...(input.subagentRuntime ? { subagentRuntime: input.subagentRuntime } : {}),
63
+ ...(input.subagentSpawn ? { subagentSpawn: input.subagentSpawn } : {}),
64
+ ...(input.subagentWorkspace ? { subagentWorkspace: input.subagentWorkspace } : {}),
65
+ ...(conversationCopy ? { conversationCopy } : {}),
66
+ ...(input.revisionRootSessionId ? { revisionRootSessionId: input.revisionRootSessionId } : {}),
67
+ ...(input.revisionParentSessionId
68
+ ? { revisionParentSessionId: input.revisionParentSessionId }
69
+ : {}),
70
+ ...(input.revisionOfTurnId ? { revisionOfTurnId: input.revisionOfTurnId } : {}),
71
+ ...(input.revisionIndex !== undefined ? { revisionIndex: input.revisionIndex } : {}),
72
+ ...(input.revisionState ? { revisionState: input.revisionState } : {}),
73
+ hasUnread: false,
74
+ backend: input.executorId ? 'plugin-executor' : 'ai-sdk',
75
+ ...(input.executorId ? { executorId: input.executorId } : {}),
76
+ ...(input.llmConnectionId === undefined ? {} : { llmConnectionId: input.llmConnectionId }),
77
+ llmConnectionSlug: input.llmConnectionSlug,
78
+ // A subagent Session's route is chosen by the spawn that created it and is
79
+ // never re-targeted, so it is born frozen. Every other Session freezes on
80
+ // its first user Message.
81
+ connectionLocked: input.subagentParent !== undefined,
82
+ model: input.model ?? 'default',
83
+ ...(input.toolProfile !== undefined ? { toolProfile: input.toolProfile } : {}),
84
+ toolMode: input.toolMode ?? DEFAULT_TOOL_MODE,
85
+ permissionMode: input.permissionMode,
86
+ collaborationMode: input.collaborationMode ?? 'agent',
87
+ orchestrationMode: input.orchestrationMode ?? 'default',
88
+ ...(input.thinkingLevel !== undefined ? { thinkingLevel: input.thinkingLevel } : {}),
89
+ // Born on the ledger: a Session created here records its execution facts as
90
+ // RuntimeEvents from its first turn, so there is no transcript to convert.
91
+ // Only an imported transcript (staged at 0) and a Session written before
92
+ // this field existed have anything for the converter to do.
93
+ transcriptLedgerVersion: 1,
94
+ schemaVersion: 1,
95
+ };
96
+ assertValidSessionLineage(header);
97
+ return header;
98
+ }
99
+ function normalizeRequiredSessionName(name) {
100
+ const normalized = normalizeUserSessionName(name);
101
+ if (!normalized.ok)
102
+ throw new Error(normalized.error);
103
+ return normalized.value;
104
+ }
105
+ /** Validate and normalize a current SessionHeader before canonical persistence. */
106
+ export function normalizeSessionHeader(header, sessionId = header.id) {
107
+ const valid = header.id === sessionId &&
108
+ (header.role === undefined || header.role === WORKHUB_COORDINATION_SESSION_ROLE) &&
109
+ typeof header.workspaceRoot === 'string' &&
110
+ typeof header.cwd === 'string' &&
111
+ (header.projectId === undefined ||
112
+ header.projectId === null ||
113
+ (typeof header.projectId === 'string' && header.projectId.length > 0)) &&
114
+ isFiniteNumber(header.createdAt) &&
115
+ (header.lastMessageAt === undefined || isFiniteNumber(header.lastMessageAt)) &&
116
+ typeof header.name === 'string' &&
117
+ typeof header.titleIsManual === 'boolean' &&
118
+ typeof header.isFlagged === 'boolean' &&
119
+ Array.isArray(header.labels) &&
120
+ header.labels.every((label) => typeof label === 'string') &&
121
+ typeof header.isArchived === 'boolean' &&
122
+ !Object.prototype.hasOwnProperty.call(header, 'archivedAt') &&
123
+ isSessionStatus(header.status) &&
124
+ (header.blockedReason === undefined || isSessionBlockedReason(header.blockedReason)) &&
125
+ (header.statusUpdatedAt === undefined || isFiniteNumber(header.statusUpdatedAt)) &&
126
+ (header.parentSessionId === undefined || typeof header.parentSessionId === 'string') &&
127
+ (header.branchOfTurnId === undefined || typeof header.branchOfTurnId === 'string') &&
128
+ isValidConversationCopyLineage(header) &&
129
+ isValidRevisionLineage(header) &&
130
+ isValidSubagentSessionLineage(header) &&
131
+ isValidSessionExternalOrigin(header.externalOrigin) &&
132
+ (header.lastReadMessageId === undefined || typeof header.lastReadMessageId === 'string') &&
133
+ typeof header.hasUnread === 'boolean' &&
134
+ isPersistedBackendKind(header.backend) &&
135
+ isValidExecutorSelection(header) &&
136
+ (header.llmConnectionId === undefined ||
137
+ (typeof header.llmConnectionId === 'string' && header.llmConnectionId.length > 0)) &&
138
+ typeof header.llmConnectionSlug === 'string' &&
139
+ typeof header.connectionLocked === 'boolean' &&
140
+ typeof header.model === 'string' &&
141
+ (header.toolProfile === undefined || isSessionToolProfile(header.toolProfile)) &&
142
+ (header.toolMode === undefined || isToolMode(header.toolMode)) &&
143
+ isPermissionMode(header.permissionMode) &&
144
+ isCollaborationMode(header.collaborationMode) &&
145
+ isOrchestrationMode(header.orchestrationMode) &&
146
+ (header.transcriptLedgerVersion === undefined ||
147
+ header.transcriptLedgerVersion === 0 ||
148
+ header.transcriptLedgerVersion === 1) &&
149
+ header.schemaVersion === 1;
150
+ if (!valid) {
151
+ throw new Error(`Invalid session header for session ${sessionId}: malformed fields`);
152
+ }
153
+ const normalizedName = normalizeSessionName(header.name);
154
+ if (header.blockedReason === undefined) {
155
+ const { blockedReason: _blockedReason, ...withoutBlockedReason } = header;
156
+ return { ...withoutBlockedReason, name: normalizedName };
157
+ }
158
+ return { ...header, name: normalizedName };
159
+ }
160
+ export function decodePersistedSessionHeader(persisted, sessionId) {
161
+ const header = persisted;
162
+ const permissionMode = decodePersistedPermissionMode(header.permissionMode);
163
+ if (permissionMode === undefined) {
164
+ return normalizeSessionHeader(header, sessionId ?? header.id);
165
+ }
166
+ return normalizeSessionHeader(permissionMode === header.permissionMode ? header : { ...header, permissionMode }, sessionId ?? header.id);
167
+ }
168
+ function isValidSessionExternalOrigin(origin) {
169
+ if (origin === undefined)
170
+ return true;
171
+ return (typeof origin === 'object' &&
172
+ origin !== null &&
173
+ typeof origin.adapterId === 'string' &&
174
+ origin.adapterId.length > 0 &&
175
+ typeof origin.sourceSessionId === 'string' &&
176
+ origin.sourceSessionId.length > 0);
177
+ }
178
+ function isValidRevisionLineage(header) {
179
+ const values = [
180
+ header.revisionRootSessionId,
181
+ header.revisionParentSessionId,
182
+ header.revisionOfTurnId,
183
+ header.revisionIndex,
184
+ header.revisionState,
185
+ ];
186
+ if (values.every((value) => value === undefined))
187
+ return true;
188
+ return (typeof header.revisionRootSessionId === 'string' &&
189
+ isSafeSessionId(header.revisionRootSessionId) &&
190
+ typeof header.revisionParentSessionId === 'string' &&
191
+ isSafeSessionId(header.revisionParentSessionId) &&
192
+ typeof header.revisionOfTurnId === 'string' &&
193
+ header.revisionOfTurnId.length > 0 &&
194
+ header.revisionOfTurnId.length <= 128 &&
195
+ Number.isSafeInteger(header.revisionIndex) &&
196
+ header.revisionIndex >= 2 &&
197
+ (header.revisionState === 'preparing' || header.revisionState === 'committed'));
198
+ }
199
+ function assertValidSessionLineage(header) {
200
+ if (!isValidConversationCopyLineage(header)) {
201
+ throw new Error('Invalid Session conversation-copy lineage');
202
+ }
203
+ if (!isValidRevisionLineage(header)) {
204
+ throw new Error('Invalid session revision lineage');
205
+ }
206
+ if (!isValidSubagentSessionLineage(header)) {
207
+ throw new Error('Invalid subagent session lineage');
208
+ }
209
+ }
210
+ function isValidConversationCopyLineage(header) {
211
+ const copy = header.conversationCopy;
212
+ if (copy === undefined)
213
+ return true;
214
+ if (!isSessionConversationCopy(copy) ||
215
+ !isSafeSessionId(copy.sourceSessionId) ||
216
+ copy.sourceSessionId === header.id ||
217
+ header.subagentParent !== undefined) {
218
+ return false;
219
+ }
220
+ if (copy.kind === 'branch') {
221
+ const revisionClear = header.revisionRootSessionId === undefined &&
222
+ header.revisionParentSessionId === undefined &&
223
+ header.revisionOfTurnId === undefined &&
224
+ header.revisionIndex === undefined &&
225
+ header.revisionState === undefined;
226
+ if (!revisionClear || header.parentSessionId !== copy.sourceSessionId) {
227
+ return false;
228
+ }
229
+ // An empty copy (absent `sourceTurnId`) records provenance
230
+ // (`parentSessionId`) but must not fabricate a `branchOfTurnId`, and is only
231
+ // valid for a side conversation; a through-turn copy must anchor to it.
232
+ return copy.sourceTurnId === undefined
233
+ ? header.branchOfTurnId === undefined && copy.intent === 'side_conversation'
234
+ : header.branchOfTurnId === copy.sourceTurnId;
235
+ }
236
+ // Revision copies always carry a turn boundary (enforced at decode).
237
+ return (copy.sourceTurnId !== undefined &&
238
+ header.revisionParentSessionId === copy.sourceSessionId &&
239
+ header.revisionOfTurnId === copy.sourceTurnId);
240
+ }
241
+ function isValidSubagentSessionLineage(header) {
242
+ if (header.subagentParent === undefined) {
243
+ return (header.subagentRuntime === undefined &&
244
+ header.subagentSpawn === undefined &&
245
+ header.subagentWorkspace === undefined);
246
+ }
247
+ if (!isSubagentSessionParent(header.subagentParent) ||
248
+ !isSafeSessionId(header.subagentParent.parentSessionId) ||
249
+ header.parentSessionId !== undefined ||
250
+ header.branchOfTurnId !== undefined ||
251
+ header.revisionRootSessionId !== undefined ||
252
+ header.revisionParentSessionId !== undefined ||
253
+ header.revisionOfTurnId !== undefined ||
254
+ header.revisionIndex !== undefined ||
255
+ header.revisionState !== undefined) {
256
+ return false;
257
+ }
258
+ return ((header.subagentRuntime === undefined &&
259
+ header.subagentSpawn === undefined &&
260
+ header.subagentWorkspace === undefined) ||
261
+ (isSubagentSessionRuntime(header.subagentRuntime) &&
262
+ isSubagentSessionSpawn(header.subagentSpawn) &&
263
+ (header.subagentWorkspace === undefined ||
264
+ isSubagentWorkspaceBinding(header.subagentWorkspace))));
265
+ }
266
+ /**
267
+ * Decode guard for a durable session header. `'fake'` stays accepted:
268
+ * narrowing it here would make every session written by a build that shipped
269
+ * FakeBackend fail `normalizeSessionHeader` and read back as malformed (#3211).
270
+ */
271
+ function isPersistedBackendKind(value) {
272
+ return value === 'ai-sdk' || value === 'plugin-executor' || value === 'fake';
273
+ }
274
+ function isValidExecutorSelection(header) {
275
+ if (header.backend === 'plugin-executor') {
276
+ return isExecutorId(header.executorId);
277
+ }
278
+ return header.executorId === undefined;
279
+ }
280
+ function isFiniteNumber(value) {
281
+ return typeof value === 'number' && Number.isFinite(value);
282
+ }
283
+ export function toSummary(header) {
284
+ const lastMessageAt = header.lastMessageAt;
285
+ return {
286
+ id: header.id,
287
+ cwd: header.cwd,
288
+ ...(header.projectId !== undefined ? { projectId: header.projectId } : {}),
289
+ name: normalizeSessionName(header.name),
290
+ isFlagged: header.isFlagged,
291
+ isArchived: header.isArchived,
292
+ labels: header.labels,
293
+ hasUnread: header.hasUnread,
294
+ lastMessageAt,
295
+ status: header.status,
296
+ ...(header.blockedReason ? { blockedReason: header.blockedReason } : {}),
297
+ ...(header.statusUpdatedAt !== undefined ? { statusUpdatedAt: header.statusUpdatedAt } : {}),
298
+ ...(header.parentSessionId ? { parentSessionId: header.parentSessionId } : {}),
299
+ ...(header.branchOfTurnId ? { branchOfTurnId: header.branchOfTurnId } : {}),
300
+ ...(header.subagentParent ? { subagentParent: header.subagentParent } : {}),
301
+ ...(header.subagentRuntime
302
+ ? {
303
+ subagentRuntime: subagentSessionRuntimeSummary(header.subagentRuntime),
304
+ }
305
+ : {}),
306
+ ...(header.subagentWorkspace ? { subagentWorkspace: header.subagentWorkspace } : {}),
307
+ ...(header.revisionRootSessionId
308
+ ? { revisionRootSessionId: header.revisionRootSessionId }
309
+ : {}),
310
+ ...(header.revisionParentSessionId
311
+ ? { revisionParentSessionId: header.revisionParentSessionId }
312
+ : {}),
313
+ ...(header.revisionOfTurnId ? { revisionOfTurnId: header.revisionOfTurnId } : {}),
314
+ ...(header.revisionIndex !== undefined ? { revisionIndex: header.revisionIndex } : {}),
315
+ ...(header.revisionState ? { revisionState: header.revisionState } : {}),
316
+ backend: header.backend,
317
+ ...(header.executorId ? { executorId: header.executorId } : {}),
318
+ ...(header.llmConnectionId === undefined ? {} : { llmConnectionId: header.llmConnectionId }),
319
+ llmConnectionSlug: header.llmConnectionSlug,
320
+ connectionLocked: header.connectionLocked,
321
+ model: header.model,
322
+ permissionMode: header.permissionMode,
323
+ collaborationMode: header.collaborationMode ?? 'agent',
324
+ orchestrationMode: header.orchestrationMode ?? 'default',
325
+ ...(header.thinkingLevel !== undefined ? { thinkingLevel: header.thinkingLevel } : {}),
326
+ };
327
+ }
328
+ export function normalizeSessionName(name) {
329
+ return name === 'New Session' ? DEFAULT_SESSION_NAME : name;
330
+ }
331
+ export function createUserMessage(input) {
332
+ return {
333
+ type: 'user',
334
+ id: randomUUID(),
335
+ turnId: input.turnId,
336
+ ts: Date.now(),
337
+ text: input.text,
338
+ ...(input.displayText !== undefined ? { displayText: input.displayText } : {}),
339
+ attachments: input.attachments,
340
+ ...(input.inlineReferences !== undefined ? { inlineReferences: input.inlineReferences } : {}),
341
+ };
342
+ }