maka-agent 0.2.0-dev.18.20260904 → 0.2.0-dev.19.20260904

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 (70) hide show
  1. package/dist/mcp-capability-provider.js +2 -1
  2. package/dist/runtime-host-lifecycle-transaction.js +15 -0
  3. package/dist/runtime-host-update-command.js +3 -1
  4. package/node_modules/@maka/core/dist/agent-run.js +23 -338
  5. package/node_modules/@maka/core/dist/execution-inspect.js +9 -20
  6. package/node_modules/@maka/core/dist/provider-registry.js +0 -9
  7. package/node_modules/@maka/core/dist/runtime-boundary.js +79 -27
  8. package/node_modules/@maka/core/dist/runtime-event-store.js +6 -0
  9. package/node_modules/@maka/core/dist/runtime-event.js +153 -0
  10. package/node_modules/@maka/core/dist/runtime-invocation.js +223 -0
  11. package/node_modules/@maka/core/dist/workhub-creation-intent.js +19 -5
  12. package/node_modules/@maka/core/package.json +2 -0
  13. package/node_modules/@maka/runtime/dist/agent-graph-timeline.js +12 -11
  14. package/node_modules/@maka/runtime/dist/agent-run-inspect.js +42 -77
  15. package/node_modules/@maka/runtime/dist/agent-run-recovery.js +36 -46
  16. package/node_modules/@maka/runtime/dist/agent-run.js +205 -329
  17. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +2 -2
  18. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +28 -21
  19. package/node_modules/@maka/runtime/dist/context-diagnostics.js +8 -7
  20. package/node_modules/@maka/runtime/dist/continuation-replay.js +1 -1
  21. package/node_modules/@maka/runtime/dist/conversation-copy.js +93 -109
  22. package/node_modules/@maka/runtime/dist/execution-inspect.js +44 -39
  23. package/node_modules/@maka/runtime/dist/history-compact-checkpoint-coordinator.js +16 -6
  24. package/node_modules/@maka/runtime/dist/history-compact-ledger.js +6 -8
  25. package/node_modules/@maka/runtime/dist/history-compaction.js +9 -7
  26. package/node_modules/@maka/runtime/dist/interaction-authority.js +16 -0
  27. package/node_modules/@maka/runtime/dist/model-history.js +13 -8
  28. package/node_modules/@maka/runtime/dist/model-projection-transition-ledger.js +3 -3
  29. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -1
  30. package/node_modules/@maka/runtime/dist/prior-run-context.js +24 -94
  31. package/node_modules/@maka/runtime/dist/process-tree-terminator.js +2 -2
  32. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +21 -13
  33. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +75 -64
  34. package/node_modules/@maka/runtime/dist/runtime-kernel.js +101 -69
  35. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +85 -393
  36. package/node_modules/@maka/runtime/dist/runtime-read-model.js +29 -112
  37. package/node_modules/@maka/runtime/dist/runtime-resume.js +69 -118
  38. package/node_modules/@maka/runtime/dist/session-manager.js +293 -334
  39. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +0 -3
  40. package/node_modules/@maka/runtime/dist/stream-graph-projection.js +12 -15
  41. package/node_modules/@maka/runtime/dist/terminal-run-commit.js +37 -172
  42. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +2 -2
  43. package/node_modules/@maka/runtime-host/dist/client/index.js +1 -0
  44. package/node_modules/@maka/runtime-host/dist/client/launcher.js +1 -1
  45. package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +4 -2
  46. package/node_modules/@maka/runtime-host/dist/client/registered-host-termination.js +105 -0
  47. package/node_modules/@maka/runtime-host/dist/client-capability-entity-id.js +27 -0
  48. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +0 -14
  49. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -15
  50. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +22 -13
  51. package/node_modules/@maka/runtime-host/dist/server/execution-inspect-coordinator.js +35 -29
  52. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-projection.js +12 -7
  53. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +4 -5
  54. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +8 -16
  55. package/node_modules/@maka/runtime-host/dist/server/session-admission-gate.js +12 -0
  56. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +1 -1
  57. package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +8 -7
  58. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +2 -2
  59. package/node_modules/@maka/runtime-host/package.json +1 -0
  60. package/node_modules/@maka/storage/dist/agent-run-store.js +128 -215
  61. package/node_modules/@maka/storage/dist/artifact-store.js +12 -12
  62. package/node_modules/@maka/storage/dist/execution-record-codec.js +1 -22
  63. package/node_modules/@maka/storage/dist/execution-stores.js +10 -11
  64. package/node_modules/@maka/storage/dist/legacy-run-header.js +327 -0
  65. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +5 -0
  66. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +20 -5
  67. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +10 -2
  68. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +283 -1
  69. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +239 -63
  70. package/package.json +1 -1
@@ -17,7 +17,8 @@
17
17
  * under the License.
18
18
  */
19
19
  import { createHash } from 'node:crypto';
20
- import { CLIENT_CAPABILITY_MAX_TOOLS, CLIENT_CAPABILITY_MAX_TOOLS_PER_OFFER, clientCapabilityEntityId, decodeClientCapabilityReplaceInput, } from '@maka/runtime-host/protocol';
20
+ import { clientCapabilityEntityId } from '@maka/runtime-host/client-capability-entity-id';
21
+ import { CLIENT_CAPABILITY_MAX_TOOLS, CLIENT_CAPABILITY_MAX_TOOLS_PER_OFFER, decodeClientCapabilityReplaceInput, } from '@maka/runtime-host/protocol';
21
22
  const CAPABILITY_VERSION = '0';
22
23
  export function createMcpCapabilityProvider(manager) {
23
24
  const toolSnapshot = manager.toolSnapshot();
@@ -512,6 +512,21 @@ export async function verifyRuntimeHostLifecycleReady(config, deps, timeoutMs =
512
512
  }
513
513
  throw new RuntimeHostLifecycleTransactionError('transition_failed', `Runtime Host did not become ready: ${lastFailure instanceof Error ? lastFailure.message : String(lastFailure)}`, { cause: lastFailure });
514
514
  }
515
+ /** Repairs update-control artifacts without interrupting the running Host supervisor. */
516
+ export async function convergeRuntimeHostLifecycleControlProjection(config, deps) {
517
+ const canonical = decodeRuntimeHostManagedDeploymentConfig(config);
518
+ await deps.convergeOperator(canonical, canonical);
519
+ if (canonical.lifecycle.mode !== 'supervised')
520
+ return;
521
+ const provider = deps.resolveProvider(canonical);
522
+ if (canonical.reconciliation.trigger === 'scheduled') {
523
+ await provider.reconciliationTrigger.converge(runtimeHostReconciliationTriggerDefinition(canonical));
524
+ await provider.reconciliationTrigger.activate();
525
+ }
526
+ else {
527
+ await provider.reconciliationTrigger.uninstall();
528
+ }
529
+ }
515
530
  /** Verifies the durable operator and supervisor projection without requiring a compatible Host. */
516
531
  export async function verifyRuntimeHostLifecycleProjection(config, deps) {
517
532
  const canonical = decodeRuntimeHostManagedDeploymentConfig(config);
@@ -26,7 +26,7 @@ import { manageRuntimeHostService, replaceRuntimeHostManagedService, resolveRunt
26
26
  import { createPlatformRuntimeHostServiceBackend, resolveRuntimeHostLifecycleProvider, runtimeHostServiceSummary, } from './runtime-host-service-management-command.js';
27
27
  import { resolveManagedRuntimeHostUpdateSelection, RuntimeHostUpdateDiscoveryError, } from './runtime-host-update-discovery.js';
28
28
  import { RuntimeHostUpdatePackageError, withRuntimeHostRegistryUpdatePackage, } from './runtime-host-update-package.js';
29
- import { canDiscardRuntimeHostLifecycleDesiredArtifacts, replaceRuntimeHostLifecycle, resolveRecoverableRuntimeHostManagedDeployment, RuntimeHostLifecycleTransactionError, verifyRuntimeHostLifecycleProjection, } from './runtime-host-lifecycle-transaction.js';
29
+ import { canDiscardRuntimeHostLifecycleDesiredArtifacts, convergeRuntimeHostLifecycleControlProjection, replaceRuntimeHostLifecycle, resolveRecoverableRuntimeHostManagedDeployment, RuntimeHostLifecycleTransactionError, verifyRuntimeHostLifecycleProjection, } from './runtime-host-lifecycle-transaction.js';
30
30
  import { manageRuntimeHostManagedLifecycle } from './runtime-host-managed-lifecycle-manager.js';
31
31
  const OPERATOR_TIMEOUT_MS = 2 * 60_000;
32
32
  const OPERATOR_OUTPUT_MAX_BYTES = 256 * 1024;
@@ -70,6 +70,7 @@ export async function runManagedRuntimeHostUpdateCli(options, overrides = {}, fr
70
70
  }),
71
71
  assertOperatorDeployment: assertRuntimeHostManagedOperatorDeployment,
72
72
  recoverDeployment: resolveRecoverableRuntimeHostManagedDeployment,
73
+ convergeControlProjection: convergeRuntimeHostLifecycleControlProjection,
73
74
  verifyProjection: verifyRuntimeHostLifecycleProjection,
74
75
  assertOperatorConfig: assertRuntimeHostManagedOperatorConfig,
75
76
  manageLifecycle: manageRuntimeHostManagedLifecycle,
@@ -394,6 +395,7 @@ async function runCanonicalRuntimeHostUpdate(options, deps, emit) {
394
395
  throw new RuntimeHostServiceManagerError('not_installed', 'The managed Runtime Host deployment is not installed');
395
396
  }
396
397
  const current = recovered.config;
398
+ await deps.canonical.convergeControlProjection(current, lifecycleDeps);
397
399
  await deps.canonical.verifyProjection(current, lifecycleDeps);
398
400
  deps.canonical.assertOperatorConfig(current, options.operatorDeploymentId, process.argv[1] ?? '');
399
401
  const currentStatus = await deps.canonical.manageLifecycle(options.managedRootId, {
@@ -16,150 +16,17 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { decodePersistedPermissionMode, isPermissionMode, } from './permission.js';
20
- import { isCollaborationMode } from './collaboration.js';
21
- import { isAgentSwarmAuthorizationSource, isEffectiveOrchestrationSource, isOrchestrationMode, } from './orchestration.js';
19
+ /**
20
+ * The operational ledger one invocation writes beside its canonical events.
21
+ *
22
+ * These records are metering, request attempts, permission decisions and
23
+ * diagnostics: facts with an operational demand of their own. What an
24
+ * invocation *is* — its route, configuration, lineage and outcome — belongs to
25
+ * the event spine in `runtime-invocation.ts`, not here.
26
+ */
22
27
  import { defineObjectShape, hasExactShape, isFiniteNumber, isOptionalString, isRecord, } from './record-schema.js';
23
- import { isToolMode } from './tool-mode.js';
24
28
  import { decodeRunCompositionSnapshot } from './run-composition.js';
25
- export const AGENT_RUN_STATUSES = [
26
- 'created',
27
- 'running',
28
- 'waiting_for_user',
29
- 'completed',
30
- 'failed',
31
- 'cancelled',
32
- ];
33
- const AGENT_RUN_CONTINUATION_SOURCE_V1_SHAPE = defineObjectShape()(['sourceInvocationId', 'sourceRunId', 'sourceTurnId', 'sourceRuntimeEventHighWater'], []);
34
- const AGENT_RUN_CONTINUATION_SOURCE_V2_SHAPE = defineObjectShape()([
35
- 'protocol',
36
- 'claimId',
37
- 'boundaryDigest',
38
- 'sourceInvocationId',
39
- 'sourceRunId',
40
- 'sourceTurnId',
41
- 'sourceRuntimeEventHighWater',
42
- 'sourcePrefixDigest',
43
- 'replayManifestDigest',
44
- ], []);
45
- export function agentRunMatchesHostedRootExecution(run, execution) {
46
- if (execution.kind !== 'context_compact' && run.rootExecutionKind !== undefined)
47
- return false;
48
- if (execution.kind === 'regenerate') {
49
- return (run.parentTurnId === execution.sourceTurnId &&
50
- run.regeneratedFromTurnId === execution.sourceTurnId &&
51
- run.parentRunId === undefined &&
52
- run.resumedFromRunId === undefined &&
53
- run.retriedFromRunId === undefined &&
54
- run.agentId === undefined &&
55
- run.agentName === undefined &&
56
- run.retriedFromTurnId === undefined &&
57
- run.branchOfTurnId === undefined &&
58
- run.parentSessionId === undefined &&
59
- run.continuationSource === undefined &&
60
- run.scheduledTaskId === undefined &&
61
- run.legacyAutomationId === undefined &&
62
- run.goalId === undefined &&
63
- run.agentGraphWakeId === undefined &&
64
- run.agentGraphWakeAttemptId === undefined);
65
- }
66
- if (execution.kind === 'context_compact') {
67
- return (run.rootExecutionKind === 'context_compact' &&
68
- run.parentTurnId === undefined &&
69
- run.regeneratedFromTurnId === undefined &&
70
- run.parentRunId === undefined &&
71
- run.resumedFromRunId === undefined &&
72
- run.retriedFromRunId === undefined &&
73
- run.agentId === undefined &&
74
- run.agentName === undefined &&
75
- run.retriedFromTurnId === undefined &&
76
- run.branchOfTurnId === undefined &&
77
- run.parentSessionId === undefined &&
78
- run.continuationSource === undefined &&
79
- run.scheduledTaskId === undefined &&
80
- run.legacyAutomationId === undefined &&
81
- run.goalId === undefined &&
82
- run.agentGraphWakeId === undefined &&
83
- run.agentGraphWakeAttemptId === undefined);
84
- }
85
- if (execution.kind === 'safe_boundary_continuation') {
86
- const source = run.continuationSource;
87
- return (run.invocationId === execution.targetInvocationId &&
88
- run.parentRunId === execution.sourceRunId &&
89
- run.parentTurnId === execution.sourceTurnId &&
90
- source !== undefined &&
91
- 'protocol' in source &&
92
- source.protocol === 'continuation_source_v2' &&
93
- source.sourceInvocationId === execution.sourceInvocationId &&
94
- source.sourceRunId === execution.sourceRunId &&
95
- source.sourceTurnId === execution.sourceTurnId &&
96
- source.sourceRuntimeEventHighWater === execution.sourceRuntimeEventHighWater &&
97
- source.claimId === execution.claimId &&
98
- source.boundaryDigest === execution.boundaryDigest &&
99
- source.replayManifestDigest === execution.boundaryDigest &&
100
- run.resumedFromRunId === undefined &&
101
- run.retriedFromRunId === undefined &&
102
- run.agentId === undefined &&
103
- run.agentName === undefined &&
104
- run.retriedFromTurnId === undefined &&
105
- run.regeneratedFromTurnId === undefined &&
106
- run.branchOfTurnId === undefined &&
107
- run.parentSessionId === undefined &&
108
- run.scheduledTaskId === undefined &&
109
- run.legacyAutomationId === undefined &&
110
- run.goalId === undefined &&
111
- run.agentGraphWakeId === undefined &&
112
- run.agentGraphWakeAttemptId === undefined);
113
- }
114
- const authorityMatches = hostedRootAuthorityMatches(run, execution);
115
- return (authorityMatches &&
116
- run.parentRunId === undefined &&
117
- run.resumedFromRunId === undefined &&
118
- run.retriedFromRunId === undefined &&
119
- run.agentId === undefined &&
120
- run.agentName === undefined &&
121
- run.parentTurnId === undefined &&
122
- run.retriedFromTurnId === undefined &&
123
- run.regeneratedFromTurnId === undefined &&
124
- run.branchOfTurnId === undefined &&
125
- run.parentSessionId === undefined &&
126
- run.continuationSource === undefined);
127
- }
128
- function hostedRootAuthorityMatches(run, execution) {
129
- switch (execution.kind) {
130
- case 'scheduled_task':
131
- return (run.scheduledTaskId === execution.scheduledTaskId &&
132
- run.legacyAutomationId === undefined &&
133
- run.goalId === undefined &&
134
- run.agentGraphWakeId === undefined &&
135
- run.agentGraphWakeAttemptId === undefined);
136
- case 'legacy_automation':
137
- return (run.legacyAutomationId === execution.automationId &&
138
- run.scheduledTaskId === undefined &&
139
- run.goalId === undefined &&
140
- run.agentGraphWakeId === undefined &&
141
- run.agentGraphWakeAttemptId === undefined);
142
- case 'goal':
143
- return (run.goalId === execution.goalId &&
144
- run.scheduledTaskId === undefined &&
145
- run.legacyAutomationId === undefined &&
146
- run.agentGraphWakeId === undefined &&
147
- run.agentGraphWakeAttemptId === undefined);
148
- case 'agent_graph_supervisor_wake':
149
- return (execution.wakeId.startsWith(`${execution.graphId}:`) &&
150
- run.agentGraphWakeId === execution.wakeId &&
151
- run.agentGraphWakeAttemptId === execution.attemptId &&
152
- run.orchestrationMode === 'graph' &&
153
- run.orchestrationSource === 'turn_override' &&
154
- run.agentSwarmAuthorization === 'none' &&
155
- run.scheduledTaskId === undefined &&
156
- run.legacyAutomationId === undefined &&
157
- run.goalId === undefined);
158
- }
159
- }
160
29
  export const AGENT_RUN_EVENT_TYPES = [
161
- 'run_created',
162
- 'run_started',
163
30
  'turn_started',
164
31
  'plan_context_resolved',
165
32
  'plan_submitted',
@@ -171,7 +38,6 @@ export const AGENT_RUN_EVENT_TYPES = [
171
38
  'plan_execution_resumed',
172
39
  'plan_transition_failed',
173
40
  'graph_supervisor_yielded',
174
- 'run_status_changed',
175
41
  'model_resolved',
176
42
  'model_resolve_failed',
177
43
  'model_stream_started',
@@ -199,16 +65,11 @@ export const AGENT_RUN_EVENT_TYPES = [
199
65
  'sandbox_escalation_applied',
200
66
  'sandbox_escalation_failed',
201
67
  'sandbox_denial_detected',
202
- 'provider_request_captured',
203
- 'provider_request_attempt_recorded',
204
68
  'model_call_attempt_recorded',
205
69
  'history_compact_checkpoint_recorded',
206
70
  'model_projection_transition_recorded',
207
- 'task_gate_decided',
71
+ 'run_composition_recorded',
208
72
  'abort_requested',
209
- 'run_completed',
210
- 'run_failed',
211
- 'run_cancelled',
212
73
  'trace_write_failed',
213
74
  'event_corrupt',
214
75
  ];
@@ -245,180 +106,22 @@ const EMITTED_AGENT_RUN_EVENT_TYPES = new Set(AGENT_RUN_EVENT_TYPES);
245
106
  export function isEmittedAgentRunEventType(type) {
246
107
  return EMITTED_AGENT_RUN_EVENT_TYPES.has(type);
247
108
  }
248
- const AGENT_RUN_HEADER_SHAPE = defineObjectShape()([
249
- 'runId',
250
- 'sessionId',
251
- 'turnId',
252
- 'status',
253
- 'backendKind',
254
- 'llmConnectionSlug',
255
- 'modelId',
256
- 'cwd',
257
- 'permissionMode',
258
- 'createdAt',
259
- 'updatedAt',
260
- ], [
261
- 'invocationId',
262
- 'llmConnectionId',
263
- 'providerStateIdentity',
264
- 'completedAt',
265
- 'parentRunId',
266
- 'resumedFromRunId',
267
- 'retriedFromRunId',
268
- 'agentId',
269
- 'agentName',
270
- 'parentTurnId',
271
- 'retriedFromTurnId',
272
- 'regeneratedFromTurnId',
273
- 'branchOfTurnId',
274
- 'parentSessionId',
275
- 'workspaceIdentity',
276
- 'continuationSource',
277
- 'scheduledTaskId',
278
- 'legacyAutomationId',
279
- 'goalId',
280
- 'agentGraphWakeId',
281
- 'agentGraphWakeAttemptId',
282
- 'rootExecutionKind',
283
- 'failureClass',
284
- 'failureMessage',
285
- 'abortSource',
286
- 'traceWriteError',
287
- 'collaborationMode',
288
- 'orchestrationMode',
289
- 'orchestrationSource',
290
- 'agentSwarmAuthorization',
291
- 'toolMode',
292
- 'runComposition',
293
- ]);
294
109
  const AGENT_RUN_EVENT_SHAPE = defineObjectShape()(['type', 'id', 'runId', 'sessionId', 'turnId', 'ts'], ['message', 'data']);
295
- const RETIRED_AGENT_RUN_STATUSES = {
296
- waiting_permission: 'waiting_for_user',
297
- };
298
- export function decodePersistedAgentRunHeader(persisted) {
299
- let value = persisted;
300
- if (isRecord(value) &&
301
- value.automationId !== undefined &&
302
- value.legacyAutomationId === undefined) {
303
- const { automationId, ...current } = value;
304
- value = { ...current, legacyAutomationId: automationId };
305
- }
306
- if (isRecord(value)) {
307
- const status = typeof value.status === 'string'
308
- ? (RETIRED_AGENT_RUN_STATUSES[value.status] ?? value.status)
309
- : value.status;
310
- const permissionMode = decodePersistedPermissionMode(value.permissionMode);
311
- if (status !== value.status || permissionMode !== value.permissionMode) {
312
- value = { ...value, status, permissionMode };
313
- }
314
- }
315
- return decodeAgentRunHeader(value);
316
- }
317
- export function decodeAgentRunHeader(value) {
318
- if (!isRecord(value) || !hasExactShape(value, AGENT_RUN_HEADER_SHAPE)) {
319
- throw new Error('Invalid AgentRun header schema');
320
- }
321
- const valid = typeof value.runId === 'string' &&
322
- typeof value.sessionId === 'string' &&
323
- typeof value.turnId === 'string' &&
324
- AGENT_RUN_STATUSES.includes(value.status) &&
325
- isPersistedBackendKind(value.backendKind) &&
326
- (value.llmConnectionId === undefined ||
327
- (typeof value.llmConnectionId === 'string' && value.llmConnectionId.length > 0)) &&
328
- (value.providerStateIdentity === undefined ||
329
- (typeof value.providerStateIdentity === 'string' &&
330
- /^sha256:[0-9a-f]{64}$/.test(value.providerStateIdentity))) &&
331
- typeof value.llmConnectionSlug === 'string' &&
332
- typeof value.modelId === 'string' &&
333
- typeof value.cwd === 'string' &&
334
- isPermissionMode(value.permissionMode) &&
335
- (value.collaborationMode === undefined || isCollaborationMode(value.collaborationMode)) &&
336
- (value.orchestrationMode === undefined || isOrchestrationMode(value.orchestrationMode)) &&
337
- (value.orchestrationSource === undefined ||
338
- isEffectiveOrchestrationSource(value.orchestrationSource)) &&
339
- (value.agentSwarmAuthorization === undefined ||
340
- isAgentSwarmAuthorizationSource(value.agentSwarmAuthorization)) &&
341
- (value.rootExecutionKind === undefined || value.rootExecutionKind === 'context_compact') &&
342
- Number(value.scheduledTaskId !== undefined) +
343
- Number(value.legacyAutomationId !== undefined) +
344
- Number(value.goalId !== undefined) +
345
- Number(value.agentGraphWakeId !== undefined) <=
346
- 1 &&
347
- (value.toolMode === undefined || isToolMode(value.toolMode)) &&
348
- (value.runComposition === undefined || isRunCompositionSnapshot(value.runComposition)) &&
349
- isFiniteNumber(value.createdAt) &&
350
- isFiniteNumber(value.updatedAt) &&
351
- isOptionalString(value.invocationId) &&
352
- (value.completedAt === undefined || isFiniteNumber(value.completedAt)) &&
353
- [
354
- value.parentRunId,
355
- value.resumedFromRunId,
356
- value.retriedFromRunId,
357
- value.agentId,
358
- value.agentName,
359
- value.parentTurnId,
360
- value.retriedFromTurnId,
361
- value.regeneratedFromTurnId,
362
- value.branchOfTurnId,
363
- value.parentSessionId,
364
- value.workspaceIdentity,
365
- value.scheduledTaskId,
366
- value.legacyAutomationId,
367
- value.goalId,
368
- value.agentGraphWakeId,
369
- value.agentGraphWakeAttemptId,
370
- value.failureClass,
371
- value.failureMessage,
372
- value.abortSource,
373
- value.traceWriteError,
374
- ].every(isOptionalString) &&
375
- (value.continuationSource === undefined ||
376
- isAgentRunContinuationSource(value.continuationSource));
377
- if (!valid)
378
- throw new Error('Invalid AgentRun header schema');
379
- return value;
380
- }
381
- function isRunCompositionSnapshot(value) {
382
- try {
383
- decodeRunCompositionSnapshot(value);
384
- return true;
385
- }
386
- catch {
387
- return false;
110
+ export const RUN_COMPOSITION_RECORDED_EVENT_TYPE = 'run_composition_recorded';
111
+ /**
112
+ * Read a run's composer snapshot back out of its ledger.
113
+ *
114
+ * The composition is written once, before provider dispatch, and the store
115
+ * refuses a second append that disagrees with the first. So the earliest
116
+ * matching row is the whole answer, and a reader never has to reduce a stream.
117
+ */
118
+ export function agentRunCompositionFromEvents(events) {
119
+ for (const event of events) {
120
+ if (event.type !== RUN_COMPOSITION_RECORDED_EVENT_TYPE)
121
+ continue;
122
+ return decodeRunCompositionSnapshot(event.data?.runComposition);
388
123
  }
389
- }
390
- function isAgentRunContinuationSource(value) {
391
- if (!isRecord(value))
392
- return false;
393
- const common = typeof value.sourceInvocationId === 'string' &&
394
- typeof value.sourceRunId === 'string' &&
395
- typeof value.sourceTurnId === 'string' &&
396
- typeof value.sourceRuntimeEventHighWater === 'number' &&
397
- Number.isSafeInteger(value.sourceRuntimeEventHighWater) &&
398
- value.sourceRuntimeEventHighWater >= 0;
399
- if (!common)
400
- return false;
401
- if (hasExactShape(value, AGENT_RUN_CONTINUATION_SOURCE_V1_SHAPE))
402
- return true;
403
- return (hasExactShape(value, AGENT_RUN_CONTINUATION_SOURCE_V2_SHAPE) &&
404
- value.protocol === 'continuation_source_v2' &&
405
- typeof value.claimId === 'string' &&
406
- value.claimId.length > 0 &&
407
- typeof value.sourceInvocationId === 'string' &&
408
- value.sourceInvocationId.length > 0 &&
409
- typeof value.sourceRunId === 'string' &&
410
- value.sourceRunId.length > 0 &&
411
- typeof value.sourceTurnId === 'string' &&
412
- value.sourceTurnId.length > 0 &&
413
- typeof value.sourceRuntimeEventHighWater === 'number' &&
414
- value.sourceRuntimeEventHighWater > 0 &&
415
- isSha256Digest(value.boundaryDigest) &&
416
- isSha256Digest(value.sourcePrefixDigest) &&
417
- isSha256Digest(value.replayManifestDigest) &&
418
- value.replayManifestDigest === value.boundaryDigest);
419
- }
420
- function isSha256Digest(value) {
421
- return typeof value === 'string' && /^sha256:[0-9a-f]{64}$/.test(value);
124
+ return undefined;
422
125
  }
423
126
  export function decodeAgentRunEvent(value) {
424
127
  if (!isRecord(value) ||
@@ -436,21 +139,3 @@ export function decodeAgentRunEvent(value) {
436
139
  }
437
140
  return value;
438
141
  }
439
- /**
440
- * Decode guard for a durable run header. `'fake'` stays accepted: runs written
441
- * by builds that shipped FakeBackend must keep decoding (#3211).
442
- */
443
- function isPersistedBackendKind(value) {
444
- return value === 'ai-sdk' || value === 'fake';
445
- }
446
- /**
447
- * Whether a run contributes directly to the owning session's transcript.
448
- * Top-level continuations carry parent lineage for recovery, but unlike
449
- * child-agent runs their output remains part of the parent session
450
- * conversation. A legacy child retry may also carry continuation authority;
451
- * its agent identity keeps it outside the owning session transcript.
452
- */
453
- export function isSessionInlineRun(run) {
454
- return (run.parentRunId === undefined ||
455
- (run.continuationSource !== undefined && run.agentId === undefined));
456
- }
@@ -16,11 +16,11 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { AGENT_RUN_STATUSES } from './agent-run.js';
20
19
  import { EXECUTION_LOG_LEDGERS } from './execution-log-coverage.js';
21
20
  import { SESSION_STATUSES } from './session.js';
22
21
  export const AGENT_RUN_INSPECT_DOCUMENT_VERSION = 'maka.agent_run_inspect.v1';
23
22
  export const SESSION_INSPECT_DOCUMENT_VERSION = 'maka.session_inspect.v1';
23
+ const AGENT_RUN_INSPECT_STATUSES = ['running', 'completed', 'failed', 'cancelled'];
24
24
  export function isAgentRunInspectDocument(value) {
25
25
  if (!hasShape(value, [
26
26
  'schemaVersion',
@@ -67,26 +67,24 @@ export function isSessionInspectDocument(value) {
67
67
  item.turnId === runTurns.get(item.agentRunId));
68
68
  }
69
69
  function isAgentRunIdentity(value) {
70
- return (hasShape(value, ['sessionId', 'agentRunId', 'turnId', 'status', 'createdAt', 'updatedAt'], [
71
- 'invocationId',
70
+ return (hasShape(value, ['sessionId', 'agentRunId', 'invocationId', 'turnId', 'status', 'openedAt'], [
72
71
  'parentRunId',
73
72
  'resumedFromRunId',
74
73
  'retriedFromRunId',
75
74
  'parentTurnId',
76
75
  'agentId',
77
- 'completedAt',
76
+ 'endedAt',
78
77
  'failureClass',
79
78
  'abortSource',
80
79
  ]) &&
81
80
  isString(value.sessionId) &&
82
81
  isString(value.agentRunId) &&
82
+ isString(value.invocationId) &&
83
83
  isString(value.turnId) &&
84
- AGENT_RUN_STATUSES.includes(value.status) &&
85
- isCount(value.createdAt) &&
86
- isCount(value.updatedAt) &&
87
- isOptionalCount(value.completedAt) &&
84
+ AGENT_RUN_INSPECT_STATUSES.includes(value.status) &&
85
+ isCount(value.openedAt) &&
86
+ isOptionalCount(value.endedAt) &&
88
87
  [
89
- value.invocationId,
90
88
  value.parentRunId,
91
89
  value.resumedFromRunId,
92
90
  value.retriedFromRunId,
@@ -101,20 +99,11 @@ function isAgentRunSources(value) {
101
99
  isCount(value.operationalEventCount) &&
102
100
  isCount(value.runtimeEventCount) &&
103
101
  (value.runtimeCoverage === undefined || isCoverage(value.runtimeCoverage)) &&
104
- hasShape(value.health, [
105
- 'runtimeLedger',
106
- 'runtimeTerminalPresent',
107
- 'operationalTerminalPresent',
108
- 'statusConsistency',
109
- ], []) &&
102
+ hasShape(value.health, ['runtimeLedger', 'runtimeTerminalPresent'], []) &&
110
103
  (value.health.runtimeLedger === 'present' ||
111
104
  value.health.runtimeLedger === 'missing' ||
112
105
  value.health.runtimeLedger === 'read_failed') &&
113
- typeof value.health.runtimeTerminalPresent === 'boolean' &&
114
- typeof value.health.operationalTerminalPresent === 'boolean' &&
115
- (value.health.statusConsistency === 'consistent' ||
116
- value.health.statusConsistency === 'inconsistent' ||
117
- value.health.statusConsistency === 'incomplete'));
106
+ typeof value.health.runtimeTerminalPresent === 'boolean');
118
107
  }
119
108
  function isToolSummary(value) {
120
109
  return (hasShape(value, [
@@ -493,7 +493,6 @@ const providerRegistry = {
493
493
  catalogGroup: 'api',
494
494
  signupUrl: 'https://console.anthropic.com/settings/keys',
495
495
  catalogOrder: 9,
496
- recommendedOrder: 3,
497
496
  },
498
497
  'kimi-coding-plan': {
499
498
  label: 'Kimi Coding Plan',
@@ -511,7 +510,6 @@ const providerRegistry = {
511
510
  catalogGroup: 'plans',
512
511
  signupUrl: 'https://www.kimi.com/code/console',
513
512
  catalogOrder: 1,
514
- recommendedOrder: 5,
515
513
  },
516
514
  'minimax-coding-plan': {
517
515
  label: 'MiniMax Coding Plan',
@@ -593,7 +591,6 @@ const providerRegistry = {
593
591
  catalogGroup: 'api',
594
592
  signupUrl: 'https://platform.openai.com/api-keys',
595
593
  catalogOrder: 10,
596
- recommendedOrder: 2,
597
594
  },
598
595
  google: {
599
596
  label: 'Google Gemini',
@@ -613,7 +610,6 @@ const providerRegistry = {
613
610
  catalogGroup: 'api',
614
611
  signupUrl: 'https://aistudio.google.com/app/apikey',
615
612
  catalogOrder: 11,
616
- recommendedOrder: 4,
617
613
  },
618
614
  deepseek: {
619
615
  label: 'DeepSeek',
@@ -638,7 +634,6 @@ const providerRegistry = {
638
634
  catalogGroup: 'api',
639
635
  signupUrl: 'https://platform.deepseek.com/api_keys',
640
636
  catalogOrder: 3,
641
- recommendedOrder: 6,
642
637
  },
643
638
  moonshot: {
644
639
  label: 'Moonshot',
@@ -1235,7 +1230,6 @@ const providerRegistry = {
1235
1230
  category: 'local',
1236
1231
  catalogGroup: 'local',
1237
1232
  catalogOrder: 16,
1238
- recommendedOrder: 7,
1239
1233
  },
1240
1234
  'lm-studio': {
1241
1235
  label: 'LM Studio',
@@ -1273,7 +1267,6 @@ const providerRegistry = {
1273
1267
  category: 'custom',
1274
1268
  catalogGroup: 'aggregators',
1275
1269
  catalogOrder: 18,
1276
- recommendedOrder: 7.5,
1277
1270
  },
1278
1271
  'openai-responses-compatible': {
1279
1272
  label: 'Custom relay (OpenAI Responses)',
@@ -1287,7 +1280,6 @@ const providerRegistry = {
1287
1280
  category: 'custom',
1288
1281
  catalogGroup: 'aggregators',
1289
1282
  catalogOrder: 18.1,
1290
- recommendedOrder: 7.6,
1291
1283
  },
1292
1284
  'anthropic-compatible': {
1293
1285
  label: 'Custom relay (Anthropic)',
@@ -1300,7 +1292,6 @@ const providerRegistry = {
1300
1292
  category: 'custom',
1301
1293
  catalogGroup: 'aggregators',
1302
1294
  catalogOrder: 18.2,
1303
- recommendedOrder: 7.7,
1304
1295
  },
1305
1296
  'github-copilot': {
1306
1297
  label: githubCopilot.name,