maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.24.20260907

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/acp/maka-acp-agent.js +2 -1
  2. package/dist/acp/session-configuration.js +143 -0
  3. package/dist/acp/session-registry.js +90 -4
  4. package/dist/cli-core.js +2 -0
  5. package/dist/pi-transcript.js +5 -12
  6. package/dist/pi-tui-runner.js +74 -4
  7. package/dist/runtime-host-cli-context.js +167 -78
  8. package/dist/runtime-host-cli-installation.js +8 -2
  9. package/dist/runtime-host-cli.js +31 -1
  10. package/dist/runtime-host-handoff-surface.js +81 -0
  11. package/dist/runtime-host-installed-update-bootstrap.js +13 -0
  12. package/dist/runtime-host-installed-update-coordinator.js +33 -0
  13. package/dist/runtime-host-lifecycle-transaction.js +9 -1
  14. package/dist/runtime-host-local-handoff.js +37 -4
  15. package/dist/runtime-host-local-managed-activation.js +84 -0
  16. package/dist/runtime-host-local-source-retirement.js +18 -2
  17. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  18. package/dist/runtime-host-operator-retirement.js +50 -0
  19. package/dist/runtime-host-service-manager.js +3 -0
  20. package/dist/runtime-host-session-driver.js +4 -25
  21. package/dist/runtime-host-session-update.js +62 -0
  22. package/dist/runtime-host-tui-command.js +38 -73
  23. package/dist/runtime-host-tui-context.js +1 -0
  24. package/dist/runtime-host-tui-owner.js +226 -0
  25. package/dist/tui-copy-catalog.js +140 -3
  26. package/dist/tui-host-owner-copy.js +24 -0
  27. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  28. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  29. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  30. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  31. package/node_modules/@maka/core/dist/model-metadata.js +3 -3
  32. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  33. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  34. package/node_modules/@maka/core/dist/record-schema.js +9 -2
  35. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  36. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  37. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  38. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  39. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  40. package/node_modules/@maka/core/dist/session.js +54 -52
  41. package/node_modules/@maka/core/dist/slash-command-catalog.js +2 -0
  42. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  43. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  44. package/node_modules/@maka/core/package.json +4 -0
  45. package/node_modules/@maka/mcp/dist/index.js +131 -1
  46. package/node_modules/@maka/runtime/dist/agent-run.js +272 -105
  47. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +13 -5
  48. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  49. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +127 -133
  50. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  51. package/node_modules/@maka/runtime/dist/conversation-copy.js +5 -4
  52. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  53. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  54. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  55. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  56. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +106 -0
  57. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  58. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  59. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  60. package/node_modules/@maka/runtime/dist/model-fetcher.js +7 -0
  61. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  62. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  63. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  64. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  65. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  66. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +68 -108
  67. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  68. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +82 -54
  69. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +117 -159
  70. package/node_modules/@maka/runtime/dist/runtime-kernel.js +150 -112
  71. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  72. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  73. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  74. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  75. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  76. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  77. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  78. package/node_modules/@maka/runtime/dist/test-connection.js +16 -16
  79. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  80. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  81. package/node_modules/@maka/runtime/package.json +1 -0
  82. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  83. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  84. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  85. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +156 -0
  86. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +273 -0
  87. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  88. package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
  89. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  90. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  91. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +27 -5
  92. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  93. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  94. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
  95. package/node_modules/@maka/runtime-host/dist/protocol/index.js +25 -1
  96. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  97. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  98. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  99. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  100. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  101. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
  102. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  103. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  104. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +100 -24
  105. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  106. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +3 -2
  107. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  108. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
  109. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  110. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  111. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  112. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
  113. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
  114. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  115. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  116. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
  117. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  118. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +8 -55
  119. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  120. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  121. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  122. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  123. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  124. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +0 -1
  125. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  126. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  127. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -4
  128. package/node_modules/@maka/storage/dist/codex-session-adapter.js +0 -2
  129. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  130. package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
  131. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  132. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  133. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  134. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  135. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  136. package/node_modules/@maka/storage/dist/session-bundle-policy.js +24 -4
  137. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  138. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  139. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  140. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  141. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  142. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
  143. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  144. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +129 -25
  145. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  146. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +111 -0
  147. package/node_modules/@maka/storage/package.json +2 -0
  148. package/package.json +1 -1
@@ -16,9 +16,10 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { MODEL_FAILURE_MESSAGE_MAX_BYTES, isModelRetryDecision, } from './model-failure.js';
19
20
  import { decodeMessageContent, TOOL_ACTIVITY_KINDS, } from './events.js';
20
21
  import { isToolCategory, } from './permission.js';
21
- import { defineObjectShape, hasExactShape, isFiniteNumber, isOptionalString, isRecord, } from './record-schema.js';
22
+ import { defineObjectShape, hasExactShape, isFiniteNumber, isOptionalString, isRecord, pickShape, } from './record-schema.js';
22
23
  import { isPermissionDecisionFields } from './interaction-record-schema.js';
23
24
  import { isTokenUsageFields } from './usage-record-schema.js';
24
25
  import { decodeCanonicalToolResultContent, decodePersistedToolResultContent, } from './tool-result-record-schema.js';
@@ -90,16 +91,7 @@ const SUBAGENT_SESSION_RUNTIME_SHAPE = defineObjectShape()([
90
91
  'systemPrompt',
91
92
  'toolNames',
92
93
  'categoryPolicy',
93
- ], ['presetId']);
94
- /**
95
- * Keys older child sessions wrote that this type no longer has.
96
- *
97
- * `hasExactShape` rejects unknown keys, so without this a record written before
98
- * the key was dropped would fail validation and make the whole child Session
99
- * unreadable. Nothing reads the values, and they stay in the stored JSON as
100
- * written — this only stops their presence from being treated as corruption.
101
- */
102
- const RETIRED_SUBAGENT_RUNTIME_KEYS = ['permissionCeiling'];
94
+ ], ['presetId'], ['permissionCeiling']);
103
95
  const SUBAGENT_SESSION_SPAWN_IDENTITY_SHAPE = defineObjectShape()(['schemaVersion', 'requestFingerprint', 'initialTurnId', 'initialRunId'], []);
104
96
  const SESSION_CONVERSATION_COPY_SHAPE = defineObjectShape()(['kind', 'sourceSessionId', 'requestFingerprint', 'state'], ['sourceTurnId', 'intent']);
105
97
  const SESSION_LINEAGE_ID_MAX_CHARS = 512;
@@ -135,15 +127,10 @@ export function isSubagentSessionParent(value) {
135
127
  isSessionLineageId(value.graph.operatorId));
136
128
  return swarmValid && graphValid && !(value.swarm && value.graph);
137
129
  }
138
- function withoutRetiredSubagentRuntimeKeys(value) {
139
- if (!RETIRED_SUBAGENT_RUNTIME_KEYS.some((key) => Object.hasOwn(value, key)))
140
- return value;
141
- return Object.fromEntries(Object.entries(value).filter(([key]) => !RETIRED_SUBAGENT_RUNTIME_KEYS.includes(key)));
142
- }
143
130
  /** Strict decoder guard for the persisted child execution snapshot. */
144
131
  export function isSubagentSessionRuntime(value) {
145
132
  if (!isRecord(value) ||
146
- !hasExactShape(withoutRetiredSubagentRuntimeKeys(value), SUBAGENT_SESSION_RUNTIME_SHAPE) ||
133
+ !hasExactShape(value, SUBAGENT_SESSION_RUNTIME_SHAPE) ||
147
134
  value.schemaVersion !== SUBAGENT_SESSION_RUNTIME_SCHEMA_VERSION ||
148
135
  !Number.isSafeInteger(value.definitionVersion) ||
149
136
  value.definitionVersion < 1 ||
@@ -286,19 +273,12 @@ function isSubagentCategoryPolicy(value) {
286
273
  export function userFacingText(message) {
287
274
  return message.displayText ?? message.text;
288
275
  }
289
- const USER_VISIBLE_SESSION_SYSTEM_NOTES = new Set([
290
- 'context_compacted',
291
- 'context_compaction_failed_open',
292
- 'context_provider_dropping',
293
- 'context_window_suggestion',
294
- 'context_window_overrun',
295
- 'context_reported_window_exceeded',
296
- 'context_overflow_after_compaction',
297
- 'step_limit',
298
- ]);
299
- /** Closed policy for system notes that are part of the user-visible transcript. */
276
+ /**
277
+ * Closed policy for system notes that are part of the user-visible transcript:
278
+ * exactly the notes the runtime writes.
279
+ */
300
280
  export function isUserVisibleSessionSystemNote(kind) {
301
- return USER_VISIBLE_SESSION_SYSTEM_NOTES.has(kind);
281
+ return isRuntimeSystemNoteKind(kind);
302
282
  }
303
283
  export const WORKHUB_COORDINATION_RECORD_SCHEMA_VERSION = 1;
304
284
  export const WORKHUB_COORDINATION_REPLACEMENT_SCHEMA_VERSION = 2;
@@ -311,6 +291,36 @@ function isWorkHubDelegationStopResolution(outcome, targetTurnId) {
311
291
  return targetTurnId === undefined;
312
292
  return outcome === 'already_terminal' && (targetTurnId === undefined || hasTargetTurnId);
313
293
  }
294
+ /**
295
+ * The notes the runtime writes: things that happened inside one invocation and
296
+ * are part of what that invocation did. Their record is its RuntimeEvent ledger.
297
+ */
298
+ export const RUNTIME_SYSTEM_NOTE_KINDS = [
299
+ 'context_compacted',
300
+ 'context_compaction_failed_open',
301
+ 'context_provider_dropping',
302
+ 'context_window_suggestion',
303
+ 'context_window_overrun',
304
+ 'context_reported_window_exceeded',
305
+ 'context_overflow_after_compaction',
306
+ 'step_limit',
307
+ ];
308
+ /**
309
+ * Notes only legacy transcripts carry, still decoded so those rows stay
310
+ * readable. Nothing writes them: the Session header and the invocation's
311
+ * opening and terminal facts already own what each of them said.
312
+ */
313
+ export const RETIRED_SYSTEM_NOTE_KINDS = [
314
+ 'session_start',
315
+ 'session_resume',
316
+ 'mode_change',
317
+ 'model_change',
318
+ 'error',
319
+ 'abort',
320
+ ];
321
+ export function isRuntimeSystemNoteKind(kind) {
322
+ return RUNTIME_SYSTEM_NOTE_KINDS.includes(kind);
323
+ }
314
324
  const USER_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 'ts', 'text'], [
315
325
  'displayText',
316
326
  'attachments',
@@ -366,7 +376,7 @@ const TOKEN_USAGE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', '
366
376
  'providerRequestTraceId',
367
377
  'lastRequestAnchor',
368
378
  ]);
369
- const TURN_STATE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 'ts', 'status', 'partialOutputRetained'], [
379
+ const TURN_STATE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 'ts', 'status'], [
370
380
  'parentTurnId',
371
381
  'retriedFromTurnId',
372
382
  'regeneratedFromTurnId',
@@ -375,7 +385,9 @@ const TURN_STATE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'turnId', 't
375
385
  'abortedAt',
376
386
  'abortSource',
377
387
  'errorClass',
378
- ]);
388
+ 'failureMessage',
389
+ 'retry',
390
+ ], ['partialOutputRetained']);
379
391
  const WORKHUB_DELEGATION_ASSIGNED_MESSAGE_SHAPE = defineObjectShape()([
380
392
  'type',
381
393
  'id',
@@ -481,20 +493,8 @@ const SYSTEM_NOTE_MESSAGE_SHAPE = defineObjectShape()(['type', 'id', 'ts', 'kind
481
493
  const ASSISTANT_THINKING_PART_SHAPE = defineObjectShape()(['text'], ['signature', 'providerOptions']);
482
494
  const ASSISTANT_THINKING_SHAPE = defineObjectShape()(['text'], ['signature', 'providerOptions', 'parts']);
483
495
  const SYSTEM_NOTE_KINDS = new Set([
484
- 'session_start',
485
- 'session_resume',
486
- 'mode_change',
487
- 'model_change',
488
- 'context_compacted',
489
- 'context_compaction_failed_open',
490
- 'context_provider_dropping',
491
- 'context_window_suggestion',
492
- 'context_window_overrun',
493
- 'context_reported_window_exceeded',
494
- 'context_overflow_after_compaction',
495
- 'step_limit',
496
- 'error',
497
- 'abort',
496
+ ...RUNTIME_SYSTEM_NOTE_KINDS,
497
+ ...RETIRED_SYSTEM_NOTE_KINDS,
498
498
  ]);
499
499
  export function decodeCanonicalMessage(value) {
500
500
  return decodeMessage(value, decodeCanonicalToolResultContent);
@@ -588,7 +588,6 @@ function decodeMessage(value, decodeToolResultContent) {
588
588
  if (hasExactShape(message, TURN_STATE_MESSAGE_SHAPE) &&
589
589
  hasMessageEnvelope(message, true) &&
590
590
  isTurnStatus(message.status) &&
591
- typeof message.partialOutputRetained === 'boolean' &&
592
591
  isOptionalString(message.parentTurnId) &&
593
592
  isOptionalString(message.retriedFromTurnId) &&
594
593
  isOptionalString(message.regeneratedFromTurnId) &&
@@ -596,8 +595,13 @@ function decodeMessage(value, decodeToolResultContent) {
596
595
  isOptionalString(message.parentSessionId) &&
597
596
  (message.abortedAt === undefined || isFiniteNumber(message.abortedAt)) &&
598
597
  isOptionalString(message.abortSource) &&
599
- isOptionalString(message.errorClass))
600
- return message;
598
+ isOptionalString(message.errorClass) &&
599
+ (message.failureMessage === undefined ||
600
+ (typeof message.failureMessage === 'string' &&
601
+ new TextEncoder().encode(message.failureMessage).byteLength <=
602
+ MODEL_FAILURE_MESSAGE_MAX_BYTES)) &&
603
+ (message.retry === undefined || isModelRetryDecision(message.retry)))
604
+ return pickShape(message, TURN_STATE_MESSAGE_SHAPE);
601
605
  break;
602
606
  case 'workhub_coordination':
603
607
  if (isWorkHubCoordinationMessage(message)) {
@@ -823,8 +827,6 @@ export function deriveTurnRecords(messages) {
823
827
  const latestState = bucket
824
828
  .filter((message) => message.type === 'turn_state')
825
829
  .at(-1);
826
- const partialOutputRetained = bucket.some((message) => (message.type === 'assistant' && message.text.trim().length > 0) ||
827
- message.type === 'tool_result');
828
830
  if (latestState) {
829
831
  return {
830
832
  turnId,
@@ -842,14 +844,14 @@ export function deriveTurnRecords(messages) {
842
844
  ...(latestState.abortedAt !== undefined ? { abortedAt: latestState.abortedAt } : {}),
843
845
  ...(latestState.abortSource ? { abortSource: latestState.abortSource } : {}),
844
846
  ...(latestState.errorClass ? { errorClass: latestState.errorClass } : {}),
845
- partialOutputRetained: latestState.partialOutputRetained || partialOutputRetained,
847
+ ...(latestState.failureMessage ? { failureMessage: latestState.failureMessage } : {}),
848
+ ...(latestState.retry ? { retry: latestState.retry } : {}),
846
849
  };
847
850
  }
848
851
  return {
849
852
  turnId,
850
853
  status: inferLegacyTurnStatus(bucket),
851
854
  statusSource: 'inferred',
852
- partialOutputRetained,
853
855
  };
854
856
  });
855
857
  }
@@ -24,6 +24,7 @@ export const SLASH_COMMAND_CATALOG = [
24
24
  { id: 'goal', session: 'required', surfaces: ['tui'] },
25
25
  { id: 'graph', session: 'none', surfaces: ['desktop', 'tui'] },
26
26
  { id: 'help', session: 'none', surfaces: ['tui'] },
27
+ { id: 'host', session: 'none', surfaces: ['tui'] },
27
28
  { id: 'mcp', session: 'none', surfaces: ['tui'] },
28
29
  { id: 'model', session: 'required', surfaces: ['tui'] },
29
30
  { id: 'move', session: 'required', surfaces: ['tui'] },
@@ -40,6 +41,7 @@ export const SLASH_COMMAND_CATALOG = [
40
41
  { id: 'swarm', session: 'none', surfaces: ['desktop', 'tui'] },
41
42
  { id: 'thinking', session: 'required', surfaces: ['tui'] },
42
43
  { id: 'transcript', session: 'required', surfaces: ['tui'] },
44
+ { id: 'update', session: 'none', surfaces: ['tui'] },
43
45
  ];
44
46
  export function slashCommandsForSurface(surface) {
45
47
  return SLASH_COMMAND_CATALOG.filter((command) => command.surfaces.includes(surface));
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ export const TOOL_RESULT_ARCHIVE_EVIDENCE_MAX_TRANSITIONS = 64;
20
+ export const TOOL_RESULT_ARCHIVE_EVIDENCE_MAX_BYTES = 2 * 1024 * 1024;
@@ -44,30 +44,6 @@ const COMPACTION_DECISION_SHAPE = defineObjectShape()(['stage', 'sourceKind', 'd
44
44
  'skippedReasonCounts',
45
45
  'validationReasonCounts',
46
46
  ]);
47
- const CURRENT_CONTEXT_BUDGET_SHAPE = defineObjectShape()([
48
- 'enabled',
49
- 'estimatedTokensBefore',
50
- 'estimatedTokensAfter',
51
- 'keptTurns',
52
- 'droppedTurns',
53
- 'keptEvents',
54
- 'droppedEvents',
55
- ], [
56
- 'policyName',
57
- 'prunedToolResults',
58
- 'prunedToolResultEstimatedTokensBefore',
59
- 'prunedToolResultEstimatedTokensAfter',
60
- 'archivePlaceholders',
61
- 'archiveWriteFailures',
62
- 'unarchivedToolResults',
63
- 'archivePlaceholderReasonCounts',
64
- 'activePrunedToolResults',
65
- 'activeSupersededToolResults',
66
- 'activeDuplicateToolResults',
67
- 'activeArchiveFailures',
68
- 'activeEstimatedTokensSaved',
69
- 'compactionDecisions',
70
- ]);
71
47
  /**
72
48
  * Keys written by retired context-budget implementations. They remain
73
49
  * accepted only so persisted usage records stay readable; current code cannot
@@ -145,10 +121,30 @@ const RETIRED_CONTEXT_BUDGET_KEYS = [
145
121
  'historyRewriteResetReason',
146
122
  'historyRewriteGate',
147
123
  ];
148
- const CONTEXT_BUDGET_SHAPE = {
149
- required: CURRENT_CONTEXT_BUDGET_SHAPE.required,
150
- allowed: new Set([...CURRENT_CONTEXT_BUDGET_SHAPE.allowed, ...RETIRED_CONTEXT_BUDGET_KEYS]),
151
- };
124
+ const CONTEXT_BUDGET_SHAPE = defineObjectShape()([
125
+ 'enabled',
126
+ 'estimatedTokensBefore',
127
+ 'estimatedTokensAfter',
128
+ 'keptTurns',
129
+ 'droppedTurns',
130
+ 'keptEvents',
131
+ 'droppedEvents',
132
+ ], [
133
+ 'policyName',
134
+ 'prunedToolResults',
135
+ 'prunedToolResultEstimatedTokensBefore',
136
+ 'prunedToolResultEstimatedTokensAfter',
137
+ 'archivePlaceholders',
138
+ 'archiveWriteFailures',
139
+ 'unarchivedToolResults',
140
+ 'archivePlaceholderReasonCounts',
141
+ 'activePrunedToolResults',
142
+ 'activeSupersededToolResults',
143
+ 'activeDuplicateToolResults',
144
+ 'activeArchiveFailures',
145
+ 'activeEstimatedTokensSaved',
146
+ 'compactionDecisions',
147
+ ], RETIRED_CONTEXT_BUDGET_KEYS);
152
148
  const PROMPT_SEGMENT_KINDS = new Set([
153
149
  'system_prompt',
154
150
  'tool_schema',
@@ -213,15 +209,10 @@ const CONTEXT_NUMBERS = [
213
209
  'activeEstimatedTokensSaved',
214
210
  ];
215
211
  const CONTEXT_REASON_COUNTS = ['archivePlaceholderReasonCounts'];
216
- const LAST_REQUEST_ANCHOR_SHAPE = defineObjectShape()(['inputTokens'], ['outputTokens', 'modelId', 'connectionId']);
217
- const RETIRED_LAST_REQUEST_ANCHOR_KEYS = ['payloadChars'];
218
- const LAST_REQUEST_ANCHOR_DECODE_SHAPE = {
219
- required: LAST_REQUEST_ANCHOR_SHAPE.required,
220
- allowed: new Set([...LAST_REQUEST_ANCHOR_SHAPE.allowed, ...RETIRED_LAST_REQUEST_ANCHOR_KEYS]),
221
- };
212
+ const LAST_REQUEST_ANCHOR_SHAPE = defineObjectShape()(['inputTokens'], ['outputTokens', 'modelId', 'connectionId'], ['payloadChars']);
222
213
  export function isLastRequestAnchor(value) {
223
214
  return (isRecord(value) &&
224
- hasExactShape(value, LAST_REQUEST_ANCHOR_DECODE_SHAPE) &&
215
+ hasExactShape(value, LAST_REQUEST_ANCHOR_SHAPE) &&
225
216
  isFiniteNumber(value.inputTokens) &&
226
217
  value.inputTokens > 0 &&
227
218
  (value.outputTokens === undefined ||
@@ -10,6 +10,8 @@
10
10
  "./model-projection-transition": "./dist/model-projection-transition.js",
11
11
  "./canonical-runtime-event": "./dist/canonical-runtime-event.js",
12
12
  "./runtime-boundary": "./dist/runtime-boundary.js",
13
+ "./runtime-handoff": "./dist/runtime-handoff.js",
14
+ "./runtime-logical-execution": "./dist/runtime-logical-execution.js",
13
15
  "./runtime-event": "./dist/runtime-event.js",
14
16
  "./tool-args-identity": "./dist/tool-args-identity.js",
15
17
  "./tool-ledger-scanner": "./dist/tool-ledger-scanner.js",
@@ -34,6 +36,7 @@
34
36
  "./plan": "./dist/plan.js",
35
37
  "./agent-run": "./dist/agent-run.js",
36
38
  "./subagent-workspace": "./dist/subagent-workspace.js",
39
+ "./model-failure": "./dist/model-failure.js",
37
40
  "./model-call-attempt": "./dist/model-call-attempt.js",
38
41
  "./model-call-usage-projection": "./dist/model-call-usage-projection.js",
39
42
  "./usage-ledger-merge": "./dist/usage-ledger-merge.js",
@@ -51,6 +54,7 @@
51
54
  "./user-question": "./dist/user-question.js",
52
55
  "./connections": "./dist/connections.js",
53
56
  "./context-offload": "./dist/context-offload.js",
57
+ "./tool-result-archive-evidence": "./dist/tool-result-archive-evidence.js",
54
58
  "./attachments": "./dist/attachments.js",
55
59
  "./artifacts": "./dist/artifacts.js",
56
60
  "./pet": "./dist/pet.js",
@@ -20,6 +20,7 @@ import { randomBytes } from 'node:crypto';
20
20
  import { auth, Client, extractWWWAuthenticateParams, LATEST_PROTOCOL_VERSION, SdkErrorCode, SdkHttpError, SSEClientTransport, StreamableHTTPClientTransport, } from '@modelcontextprotocol/client';
21
21
  import { StdioClientTransport } from '@modelcontextprotocol/client/stdio';
22
22
  import { redactSecrets } from '@maka/core/redaction';
23
+ import { serializedByteLength } from '@maka/core/serialized-byte-length';
23
24
  import { deepScrubMcpSecrets, EMPTY_MCP_SECRET_INVENTORY, MCP_SECRET_MIN_SUBSTITUTION_LENGTH, mcpSecretInventory, scrubKnownMcpSecrets, } from '@maka/core/mcp-secrets';
24
25
  import { isMcpStdioConfig, mcpConfigChangeRetiresCredentials, resolveMcpProtocolPreference, } from '@maka/core/mcp';
25
26
  import { formatMcpDiagnosticText, MCP_DIAGNOSTIC_INPUT_CODE_UNITS, MCP_ERROR_DIAGNOSTIC_CODE_POINTS, } from './diagnostic-text.js';
@@ -47,6 +48,10 @@ const STDERR_OVERSIZED_LINE = '[stderr line omitted: exceeds diagnostic limit]';
47
48
  const STDERR_CONTINUATION = '[stderr continuation omitted]';
48
49
  const MAX_SUMMARIZED_ERROR_BLOCKS = 100;
49
50
  const OVERSIZED_TOOL_ERROR_CONTENT = 'server returned oversized error content';
51
+ const MAX_SUCCESS_TOOL_RESULT_CONTENT_BLOCKS = 256;
52
+ const MAX_SUCCESS_TOOL_RESULT_BYTES = 24 * 1024 * 1024;
53
+ const MAX_SUCCESS_TOOL_RESULT_JSON_DEPTH = 32;
54
+ const MAX_SUCCESS_TOOL_RESULT_JSON_NODES = 8_192;
50
55
  const MAX_TOOL_REFRESH_PASSES = 3;
51
56
  const TOOL_REFRESH_BURST_IDLE_MS = 1_000;
52
57
  // Recency-bounded per-server scrub material: enough to cover every value a
@@ -573,6 +578,7 @@ export class McpClientManager {
573
578
  // The server writes this text; it can echo a secret it was sent.
574
579
  throw new McpToolCallError(serverId, toolName, scrubKnownSecrets(redactSecrets(summarizeErrorContent(result.content)), inventory));
575
580
  }
581
+ assertSuccessfulToolResultBudget(serverId, toolName, result, { raw: true });
576
582
  const validateOutput = preparation.value.validateOutput;
577
583
  if (validateOutput) {
578
584
  if (result.structuredContent === undefined) {
@@ -595,10 +601,12 @@ export class McpClientManager {
595
601
  }
596
602
  // Success payloads cross toward the renderer and the transcript too; a
597
603
  // server can embed the credential it was just sent into a result.
598
- return {
604
+ const published = {
599
605
  content: deepScrub(result.content.map(normalizeContent), inventory),
600
606
  structuredContent: deepScrub(result.structuredContent, inventory),
601
607
  };
608
+ assertSuccessfulToolResultBudget(serverId, toolName, published);
609
+ return published;
602
610
  }
603
611
  async test(serverId) {
604
612
  const started = this.now();
@@ -1852,6 +1860,128 @@ function normalizeContent(value) {
1852
1860
  }
1853
1861
  return { type: 'unknown', value };
1854
1862
  }
1863
+ function assertSuccessfulToolResultBudget(serverId, toolName, result, options = {}) {
1864
+ if (result.content.length > MAX_SUCCESS_TOOL_RESULT_CONTENT_BLOCKS) {
1865
+ throw successfulToolResultBudgetError(serverId, toolName, 'content block');
1866
+ }
1867
+ const budget = {
1868
+ bytes: 0,
1869
+ nodes: 0,
1870
+ active: new WeakSet(),
1871
+ };
1872
+ try {
1873
+ // Bound the untrusted content before normalization and then the exact
1874
+ // result that crosses the public boundary. Known-block metadata may be
1875
+ // discarded later, but it must not provide a path around the first pass.
1876
+ countSuccessfulToolResultValue(result.structuredContent === undefined
1877
+ ? { content: result.content }
1878
+ : { content: result.content, structuredContent: result.structuredContent }, budget, 0, options.raw === true);
1879
+ }
1880
+ catch (error) {
1881
+ if (error instanceof SuccessfulToolResultBudgetViolation) {
1882
+ throw successfulToolResultBudgetError(serverId, toolName, error.limit);
1883
+ }
1884
+ throw new McpToolCallError(serverId, toolName, 'server returned an invalid tool result');
1885
+ }
1886
+ }
1887
+ class SuccessfulToolResultBudgetViolation extends Error {
1888
+ limit;
1889
+ constructor(limit) {
1890
+ super(limit);
1891
+ this.limit = limit;
1892
+ }
1893
+ }
1894
+ function countSuccessfulToolResultValue(value, budget, depth, rejectUndefined = false) {
1895
+ budget.nodes += 1;
1896
+ if (budget.nodes > MAX_SUCCESS_TOOL_RESULT_JSON_NODES) {
1897
+ throw new SuccessfulToolResultBudgetViolation('JSON node');
1898
+ }
1899
+ if (depth > MAX_SUCCESS_TOOL_RESULT_JSON_DEPTH) {
1900
+ throw new SuccessfulToolResultBudgetViolation('JSON depth');
1901
+ }
1902
+ if (value === null) {
1903
+ countSuccessfulToolResultBytes(budget, 4);
1904
+ return;
1905
+ }
1906
+ if (typeof value === 'string') {
1907
+ countSuccessfulToolResultJsonStringBytes(budget, value);
1908
+ return;
1909
+ }
1910
+ if (typeof value === 'boolean') {
1911
+ countSuccessfulToolResultBytes(budget, value ? 4 : 5);
1912
+ return;
1913
+ }
1914
+ if (typeof value === 'number') {
1915
+ if (!Number.isFinite(value))
1916
+ throw new Error('non-finite number');
1917
+ countSuccessfulToolResultBytes(budget, JSON.stringify(value).length);
1918
+ return;
1919
+ }
1920
+ if (typeof value !== 'object')
1921
+ throw new Error('unsupported JSON value');
1922
+ if (budget.active.has(value))
1923
+ throw new Error('cyclic JSON value');
1924
+ if (typeof value.toJSON === 'function') {
1925
+ throw new Error('custom JSON serializer');
1926
+ }
1927
+ if (!Array.isArray(value)) {
1928
+ const prototype = Object.getPrototypeOf(value);
1929
+ if (prototype !== Object.prototype && prototype !== null) {
1930
+ throw new Error('non-plain JSON object');
1931
+ }
1932
+ }
1933
+ budget.active.add(value);
1934
+ try {
1935
+ if (Array.isArray(value)) {
1936
+ countSuccessfulToolResultBytes(budget, 1);
1937
+ for (let index = 0; index < value.length; index += 1) {
1938
+ if (index > 0)
1939
+ countSuccessfulToolResultBytes(budget, 1);
1940
+ countSuccessfulToolResultValue(value[index], budget, depth + 1, rejectUndefined);
1941
+ }
1942
+ countSuccessfulToolResultBytes(budget, 1);
1943
+ return;
1944
+ }
1945
+ countSuccessfulToolResultBytes(budget, 1);
1946
+ let emitted = 0;
1947
+ for (const key in value) {
1948
+ if (!Object.hasOwn(value, key))
1949
+ continue;
1950
+ const item = value[key];
1951
+ if (item === undefined) {
1952
+ if (rejectUndefined)
1953
+ throw new Error('unsupported JSON value');
1954
+ continue;
1955
+ }
1956
+ if (emitted > 0)
1957
+ countSuccessfulToolResultBytes(budget, 1);
1958
+ countSuccessfulToolResultJsonStringBytes(budget, key);
1959
+ countSuccessfulToolResultBytes(budget, 1);
1960
+ countSuccessfulToolResultValue(item, budget, depth + 1, rejectUndefined);
1961
+ emitted += 1;
1962
+ }
1963
+ countSuccessfulToolResultBytes(budget, 1);
1964
+ }
1965
+ finally {
1966
+ budget.active.delete(value);
1967
+ }
1968
+ }
1969
+ function countSuccessfulToolResultJsonStringBytes(budget, value) {
1970
+ const remainingBytes = MAX_SUCCESS_TOOL_RESULT_BYTES - budget.bytes;
1971
+ const bytes = serializedByteLength(value, remainingBytes);
1972
+ if (bytes > remainingBytes)
1973
+ throw new SuccessfulToolResultBudgetViolation('byte');
1974
+ budget.bytes += bytes;
1975
+ }
1976
+ function countSuccessfulToolResultBytes(budget, bytes) {
1977
+ if (budget.bytes > MAX_SUCCESS_TOOL_RESULT_BYTES - bytes) {
1978
+ throw new SuccessfulToolResultBudgetViolation('byte');
1979
+ }
1980
+ budget.bytes += bytes;
1981
+ }
1982
+ function successfulToolResultBudgetError(serverId, toolName, limit) {
1983
+ return new McpToolCallError(serverId, toolName, `server returned a tool result that exceeds the ${limit} limit`);
1984
+ }
1855
1985
  function summarizeErrorContent(content) {
1856
1986
  if (content.length > MAX_SUMMARIZED_ERROR_BLOCKS)
1857
1987
  return OVERSIZED_TOOL_ERROR_CONTENT;