maka-agent 0.2.0-dev.22.20260905 → 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 (194) 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-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  28. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  29. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  30. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  31. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  32. package/node_modules/@maka/core/dist/bot-events.js +18 -63
  33. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  34. package/node_modules/@maka/core/dist/model-call-attempt.js +0 -82
  35. package/node_modules/@maka/core/dist/model-call-usage-projection.js +0 -186
  36. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  37. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  38. package/node_modules/@maka/core/dist/model-metadata.js +3 -3
  39. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  40. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  41. package/node_modules/@maka/core/dist/record-schema.js +22 -2
  42. package/node_modules/@maka/core/dist/redaction.js +41 -58
  43. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  44. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  45. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  46. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  47. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  48. package/node_modules/@maka/core/dist/session-trace.js +5 -1
  49. package/node_modules/@maka/core/dist/session.js +54 -52
  50. package/node_modules/@maka/core/dist/slash-command-catalog.js +2 -0
  51. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  52. package/node_modules/@maka/core/dist/usage-ledger-merge.js +7 -9
  53. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  54. package/node_modules/@maka/core/dist/workhub-creation-intent.js +34 -20
  55. package/node_modules/@maka/core/package.json +4 -0
  56. package/node_modules/@maka/eval/harbor/egress-proxy/entrypoint.sh +2 -1
  57. package/node_modules/@maka/mcp/dist/index.js +131 -1
  58. package/node_modules/@maka/runtime/dist/agent-run.js +272 -105
  59. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +13 -5
  60. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  61. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +155 -134
  62. package/node_modules/@maka/runtime/dist/bots/base-adapter.js +17 -0
  63. package/node_modules/@maka/runtime/dist/bots/bot-test.js +38 -22
  64. package/node_modules/@maka/runtime/dist/bots/dingtalk-bridge.js +7 -5
  65. package/node_modules/@maka/runtime/dist/bots/discord-bridge.js +4 -4
  66. package/node_modules/@maka/runtime/dist/bots/feishu-bridge.js +4 -5
  67. package/node_modules/@maka/runtime/dist/bots/qq-bridge.js +6 -4
  68. package/node_modules/@maka/runtime/dist/bots/slack-bridge.js +3 -4
  69. package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +4 -5
  70. package/node_modules/@maka/runtime/dist/bots/wechat-bridge.js +17 -19
  71. package/node_modules/@maka/runtime/dist/bots/wecom-bridge.js +5 -6
  72. package/node_modules/@maka/runtime/dist/bots/ws-bridge-base.js +2 -3
  73. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  74. package/node_modules/@maka/runtime/dist/conversation-copy.js +5 -4
  75. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  76. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  77. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  78. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  79. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +106 -0
  80. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  81. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  82. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  83. package/node_modules/@maka/runtime/dist/model-fetcher.js +7 -0
  84. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  85. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  86. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  87. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  88. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  89. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +68 -108
  90. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  91. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +82 -54
  92. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +117 -159
  93. package/node_modules/@maka/runtime/dist/runtime-kernel.js +150 -112
  94. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  95. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  96. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  97. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  98. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  99. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  100. package/node_modules/@maka/runtime/dist/session-trace-projection.js +3 -30
  101. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  102. package/node_modules/@maka/runtime/dist/test-connection.js +16 -16
  103. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  104. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  105. package/node_modules/@maka/runtime/package.json +1 -0
  106. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  107. package/node_modules/@maka/runtime-host/dist/candidate-entry.js +4 -1
  108. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  109. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  110. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +156 -0
  111. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +273 -0
  112. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  113. package/node_modules/@maka/runtime-host/dist/client/index.js +3 -1
  114. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  115. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +13 -0
  116. package/node_modules/@maka/runtime-host/dist/client/registered-host-termination.js +0 -59
  117. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  118. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +27 -5
  119. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  120. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  121. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +28 -16
  122. package/node_modules/@maka/runtime-host/dist/protocol/external-session.js +4 -0
  123. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +29 -12
  124. package/node_modules/@maka/runtime-host/dist/protocol/index.js +37 -1
  125. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +2 -0
  126. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +28 -1
  127. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  128. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  129. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  130. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  131. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +33 -0
  132. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +26 -1
  133. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +6 -1
  134. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  135. package/node_modules/@maka/runtime-host/dist/server/canonical-usage-reader.js +24 -11
  136. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  137. package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +7 -4
  138. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +168 -28
  139. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  140. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +3 -2
  141. package/node_modules/@maka/runtime-host/dist/server/external-session-coordinator.js +6 -3
  142. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  143. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +108 -23
  144. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  145. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  146. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  147. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +85 -8
  148. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +7 -0
  149. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +344 -71
  150. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  151. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  152. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +201 -12
  153. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  154. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +8 -55
  155. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  156. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  157. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  158. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  159. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  160. package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +4 -11
  161. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +44 -15
  162. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +6 -2
  163. package/node_modules/@maka/storage/dist/agent-run-store.js +44 -0
  164. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  165. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  166. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -4
  167. package/node_modules/@maka/storage/dist/codex-session-adapter.js +0 -2
  168. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  169. package/node_modules/@maka/storage/dist/conversation-operational-state.js +4 -0
  170. package/node_modules/@maka/storage/dist/execution-stores.js +11 -7
  171. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  172. package/node_modules/@maka/storage/dist/model-call-ledger.js +199 -32
  173. package/node_modules/@maka/storage/dist/model-call-usage-sql.js +136 -0
  174. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  175. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  176. package/node_modules/@maka/storage/dist/operational-state-store-public.js +1 -1
  177. package/node_modules/@maka/storage/dist/operational-state-store.js +5 -3
  178. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  179. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  180. package/node_modules/@maka/storage/dist/session-bundle-policy.js +24 -4
  181. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  182. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  183. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  184. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  185. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  186. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +17 -1
  187. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  188. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +129 -25
  189. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  190. package/node_modules/@maka/storage/dist/sqlite-usage-schema.js +200 -20
  191. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +111 -0
  192. package/node_modules/@maka/storage/dist/usage-stores.js +6 -2
  193. package/node_modules/@maka/storage/package.json +2 -0
  194. package/package.json +1 -1
@@ -274,6 +274,27 @@ export function decodeWorkHubCoordinationActResult(value) {
274
274
  }),
275
275
  };
276
276
  }
277
+ if (result.disposition === 'resume_work') {
278
+ const exact = requireShapedRecord(result, 'WorkHub Coordination resume result', ['disposition', 'outcome', 'targetSessionId'], ['targetTurnId']);
279
+ if (exact.outcome !== 'resume_started' && exact.outcome !== 'already_running') {
280
+ throw invalidProtocolFrame('Invalid WorkHub resume outcome');
281
+ }
282
+ // Only a started continuation names a Turn: the Host has one to name, and
283
+ // the other two outcomes changed nothing that could carry an identity.
284
+ if ((exact.outcome === 'resume_started') !== (exact.targetTurnId !== undefined)) {
285
+ throw invalidProtocolFrame('Invalid WorkHub resume target Turn');
286
+ }
287
+ return {
288
+ disposition: 'resume_work',
289
+ outcome: exact.outcome,
290
+ targetSessionId: requireEntityId(exact.targetSessionId, 'WorkHub target Session id'),
291
+ ...(exact.targetTurnId === undefined
292
+ ? {}
293
+ : {
294
+ targetTurnId: requireEntityId(exact.targetTurnId, 'WorkHub target Turn id'),
295
+ }),
296
+ };
297
+ }
277
298
  throw invalidProtocolFrame('Invalid WorkHub Coordination action disposition');
278
299
  }
279
300
  function decodeWorkHubCoordinationCandidate(value) {
@@ -372,6 +393,18 @@ function decodeWorkHubCoordinationProposal(value) {
372
393
  expects: decodeWorkHubCoordinationStopPreconditions(exact.expects),
373
394
  };
374
395
  }
396
+ if (proposal.disposition === 'resume_work') {
397
+ const exact = requireExactRecord(proposal, 'WorkHub resume proposal', [
398
+ 'disposition',
399
+ 'expects',
400
+ 'resumesActionId',
401
+ ]);
402
+ return {
403
+ disposition: 'resume_work',
404
+ resumesActionId: requireEntityId(exact.resumesActionId, 'WorkHub resume assignment'),
405
+ expects: decodeWorkHubCoordinationStopPreconditions(exact.expects),
406
+ };
407
+ }
375
408
  throw invalidProtocolFrame('Invalid WorkHub Coordination proposal disposition');
376
409
  }
377
410
  function decodeWorkHubCoordinationStopPreconditions(value) {
@@ -20,7 +20,7 @@ import { randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
20
20
  import { join } from 'node:path';
21
21
  import { isDeepStrictEqual } from 'node:util';
22
22
  import { runtimeHostAccessCredentialHash } from '../access-credential-identity.js';
23
- import { encodeCollaborationInvitationCode, } from '../protocol/index.js';
23
+ import { decodeCollaborationDisplayName, encodeCollaborationInvitationCode, } from '../protocol/index.js';
24
24
  import { createRuntimeHostConnectionAuthority, } from './connection-authority.js';
25
25
  import { createAccessCredentialDelivery, discardAccessCredentialDelivery, purgeAccessCredentialDeliveries, } from '../control/access-credential-delivery.js';
26
26
  import { ACCESS_FILE_NAME, assertAccessCredentialFileCapacity, CAPABILITY_PROVIDER_OPERATION_GRANTS, createAccessCredentialFile, effectiveOperationGrants, issuedAccessGrants, readAccessCredentialFile, RuntimeHostAccessCommitOutcomeUnknownError, RuntimeHostAccessInputError, SESSION_GUEST_OPERATION_GRANTS, writeAccessCredentialFile, } from './access-credential-store.js';
@@ -152,6 +152,9 @@ class FileRuntimeHostAccessAuthority {
152
152
  principalId,
153
153
  status: credential.status,
154
154
  createdAt: credential.createdAt,
155
+ ...(credential.displayName === undefined
156
+ ? {}
157
+ : { displayName: credential.displayName }),
155
158
  ...(credential.expiresAt ? { expiresAt: credential.expiresAt } : {}),
156
159
  },
157
160
  ]
@@ -176,6 +179,18 @@ class FileRuntimeHostAccessAuthority {
176
179
  principalId,
177
180
  });
178
181
  }
182
+ renameCollaborationPrincipal(input) {
183
+ const displayName = decodeCollaborationDisplayName(input.displayName);
184
+ return this.#mutate(async () => {
185
+ const matches = (credential) => credential.principalKind === 'session_guest' &&
186
+ credential.principalId === input.principalId &&
187
+ credential.status !== 'revoked';
188
+ if (!this.#file.credentials.some(matches))
189
+ return { renamed: false };
190
+ await this.#commit(createNextAccessCredentialFile(this.#file, this.#file.credentials.map((credential) => matches(credential) ? { ...credential, displayName } : credential), this.#file.sessionGrants), []);
191
+ return { renamed: true };
192
+ });
193
+ }
179
194
  createTurnAccessRequest(principalId, input) {
180
195
  return this.#mutate(async () => {
181
196
  const grant = this.activeSessionGrant(principalId, input.intent.sessionId, 'session_turn_request');
@@ -960,6 +975,16 @@ export async function revokeCollaborationPrincipal(authority, principalId) {
960
975
  return accessPersistenceFailure(error, 'Collaboration Guest revocation outcome is unknown', 'Collaboration Guest could not be revoked');
961
976
  }
962
977
  }
978
+ export async function renameCollaborationPrincipal(authority, input) {
979
+ if (!authority)
980
+ return collaborationUnavailable('collaboration.principal.rename');
981
+ try {
982
+ return { ok: true, result: await authority.renameCollaborationPrincipal(input) };
983
+ }
984
+ catch (error) {
985
+ return accessPersistenceFailure(error, 'Guest alias commit outcome is unknown', 'Guest alias could not be saved');
986
+ }
987
+ }
963
988
  function collaborationUnavailable(operation) {
964
989
  return {
965
990
  ok: false,
@@ -19,7 +19,7 @@
19
19
  import { randomUUID } from 'node:crypto';
20
20
  import { chmod, open, rename, rm } from 'node:fs/promises';
21
21
  import { dirname } from 'node:path';
22
- import { HOST_OPERATION_SPECS, operationAllowsRemoteOwner, decodeSessionTurnAccessRequest, } from '../protocol/index.js';
22
+ import { HOST_OPERATION_SPECS, operationAllowsRemoteOwner, decodeSessionTurnAccessRequest, decodeCollaborationDisplayName, } from '../protocol/index.js';
23
23
  // Schema 4 makes provider ownership downgrade-safe once an association exists.
24
24
  // Ordinary access files remain schema 3 so this feature does not fence a
25
25
  // downgrade before there is an owner association to preserve.
@@ -66,6 +66,7 @@ export const SESSION_GUEST_OPERATION_GRANTS = Object.freeze([
66
66
  'session.shared.query',
67
67
  'subscription.open',
68
68
  'subscription.close',
69
+ 'subscription.pty_interest.set',
69
70
  'session.transcript.page',
70
71
  'session.transcript.overlay.release',
71
72
  ]);
@@ -225,6 +226,7 @@ function encodeAccessCredentialFile(file) {
225
226
  schemaVersion: file.schemaVersion,
226
227
  credentials: file.credentials.map((credential) => ({
227
228
  credentialId: credential.credentialId,
229
+ ...(credential.displayName === undefined ? {} : { displayName: credential.displayName }),
228
230
  credentialHash: credential.credentialHash,
229
231
  principalId: credential.principalId,
230
232
  principalKind: credential.principalKind,
@@ -391,6 +393,9 @@ function decodeStoredCredential(value) {
391
393
  ...(typeof clientInstanceId === 'string' ? { clientInstanceId } : {}),
392
394
  ...(typeof expiresAt === 'string' ? { expiresAt } : {}),
393
395
  ...(revokedAt === undefined ? {} : { revokedAt }),
396
+ ...(value.displayName === undefined
397
+ ? {}
398
+ : { displayName: decodeCollaborationDisplayName(value.displayName) }),
394
399
  };
395
400
  }
396
401
  function decodeStoredSessionGrant(value) {
@@ -19,6 +19,7 @@
19
19
  import { truncateUtf8 } from '@maka/core/diagnostic-log';
20
20
  import { redactSecrets } from '@maka/core/redaction';
21
21
  import { readRunInvocation } from '@maka/core/runtime-event-store';
22
+ import { readLogicalRuntimeExecution } from '@maka/core/runtime-logical-execution';
22
23
  import { classifyTerminalRuntimeLedger } from '@maka/runtime/terminal-run-commit';
23
24
  import { TURN_FAILURE_MESSAGE_MAX_BYTES } from '../protocol/index.js';
24
25
  export async function readCanonicalTurnSnapshot(stores, identity, knownRun) {
@@ -29,8 +30,16 @@ export async function readCanonicalTurnSnapshot(stores, identity, knownRun) {
29
30
  if (run.turnId !== turnId) {
30
31
  throw new Error('Admitted Turn identity does not match its invocation');
31
32
  }
32
- const runtimeEvents = await stores.runtimeEventStore.readImmutableRuntimeEvents(sessionId, runId);
33
- const terminal = classifyTerminalRuntimeLedger(run, runtimeEvents);
33
+ const logical = await readLogicalRuntimeExecution(stores.runtimeEventStore, identity, run);
34
+ if (!logical)
35
+ throw new Error('Admitted logical execution disappeared');
36
+ const rootExecutionKind = logical.root.opening.root.kind === 'context_compact'
37
+ ? { rootExecutionKind: 'context_compact' }
38
+ : {};
39
+ if (logical.pendingHandoff) {
40
+ return { sessionId, turnId, runId, status: 'running', ...rootExecutionKind };
41
+ }
42
+ const terminal = classifyTerminalRuntimeLedger(logical.tip, logical.events);
34
43
  if (terminal.kind === 'fact') {
35
44
  const fact = terminal.fact;
36
45
  if (fact.runStatus === 'completed') {
@@ -76,8 +85,14 @@ export async function readCanonicalTurnSnapshot(stores, identity, knownRun) {
76
85
  }
77
86
  // No terminal event means the run is still open. Whether it is parked is the
78
87
  // pending-interaction store's answer, not something the run restates.
79
- const parked = await hasPendingInteraction(stores, sessionId, runId);
80
- return { sessionId, turnId, runId, status: parked ? 'waiting_for_user' : 'running' };
88
+ const parked = await hasPendingInteraction(stores, sessionId, logical.tip.runId);
89
+ return {
90
+ sessionId,
91
+ turnId,
92
+ runId,
93
+ status: parked ? 'waiting_for_user' : 'running',
94
+ ...rootExecutionKind,
95
+ };
81
96
  }
82
97
  /** Is this run waiting on a request the user has not answered? */
83
98
  async function hasPendingInteraction(stores, sessionId, runId) {
@@ -16,33 +16,46 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { resolveUsageRange } from '@maka/core/model-call-usage-projection';
20
19
  export class CanonicalUsageProjectionIncompleteError extends Error {
21
20
  constructor() {
22
21
  super('Canonical Usage projection is incomplete');
23
22
  this.name = 'CanonicalUsageProjectionIncompleteError';
24
23
  }
25
24
  }
26
- /** Reads and repairs the canonical usage source shared by Host-owned projections. */
27
- export async function readCanonicalUsage(stores, query, now, repair = true) {
28
- // `catchUpModelCallProjection` is a write. Paged log reads call this once per
29
- // page, so a caller that already repaired on its first page can pass
30
- // `repair: false` on later pages to avoid a redundant repair write per page.
25
+ /**
26
+ * Repairs the projection, then asks the ledger for one answer.
27
+ *
28
+ * `catchUpModelCallProjection` is a write. Paged log reads call this once per
29
+ * page, so a caller that already repaired on its first page passes
30
+ * `repair: false` on later pages to avoid a redundant repair write per page.
31
+ */
32
+ async function readCanonical(stores, query, repair, ask) {
31
33
  const repairOutcome = repair
32
34
  ? await stores.modelCalls
33
35
  .catchUpModelCallProjection(query.sessionId === undefined ? undefined : { sessionId: query.sessionId })
34
36
  .catch(() => ({ pendingRuns: 1, unreadableEvents: 0 }))
35
37
  : { pendingRuns: 0, unreadableEvents: 0 };
36
- const page = await stores.modelCalls.modelCallAttempts(resolveUsageRange(query.range, now), query.sessionId);
38
+ const answer = await ask();
37
39
  return {
38
- attempts: page.attempts,
39
- unreadableRecords: page.unreadableRecords + repairOutcome.unreadableEvents,
40
+ projection: answer.projection,
41
+ unreadableRecords: answer.unreadableRecords + repairOutcome.unreadableEvents,
40
42
  pendingRepairs: repairOutcome.pendingRuns,
41
43
  };
42
44
  }
45
+ export function readCanonicalUsageSummary(stores, query, now, repair = true) {
46
+ return readCanonical(stores, query, repair, () => stores.modelCalls.modelCallSummary(query, now));
47
+ }
48
+ export function readCanonicalUsageBuckets(stores, query, groupBy, now, repair = true) {
49
+ return readCanonical(stores, query, repair, () => stores.modelCalls.modelCallBuckets(query, groupBy, now));
50
+ }
51
+ export function readCanonicalUsageLogs(stores, query, now, limit, repair = true) {
52
+ // Both sources are newest-first, so a merged page can only be drawn from each
53
+ // source's own first `offset + limit` rows.
54
+ return readCanonical(stores, query, repair, () => stores.modelCalls.modelCallLogs(query, now, 0, limit));
55
+ }
43
56
  /** Runs one bounded repair pass and rejects data still unsafe for durable derivatives. */
44
- export async function readCompleteCanonicalUsage(stores, query, now) {
45
- const source = await readCanonicalUsage(stores, query, now);
57
+ export async function readCompleteCanonicalUsageSummary(stores, query, now) {
58
+ const source = await readCanonicalUsageSummary(stores, query, now);
46
59
  if (source.unreadableRecords > 0 || source.pendingRepairs > 0) {
47
60
  throw new CanonicalUsageProjectionIncompleteError();
48
61
  }
@@ -33,7 +33,7 @@ export class RuntimeHostConnectionSession {
33
33
  #clientCapabilities;
34
34
  #clientCapabilityCloseTask;
35
35
  #hostChanges;
36
- #inputClosed = false;
36
+ #inputClosedAbort = new AbortController();
37
37
  #closed = false;
38
38
  constructor(options) {
39
39
  this.#options = options;
@@ -65,7 +65,7 @@ export class RuntimeHostConnectionSession {
65
65
  }
66
66
  }
67
67
  async #closeAfterDispatchedReplies() {
68
- this.#inputClosed = true;
68
+ this.#inputClosedAbort.abort();
69
69
  this.#detachContinuity();
70
70
  this.#detachClientCapabilities();
71
71
  this.#detachHostChanges();
@@ -159,6 +159,7 @@ export class RuntimeHostConnectionSession {
159
159
  : undefined;
160
160
  const response = await dispatchOperation(frame, this.#options.resolveHandlers(), {
161
161
  ...this.#options.connection,
162
+ inputClosedSignal: this.#inputClosedAbort.signal,
162
163
  principal: this.#options.connection.authority.principalId,
163
164
  principalKind: this.#options.connection.authority.principalKind,
164
165
  ...(this.#options.connection.authority.credentialId
@@ -193,7 +194,7 @@ export class RuntimeHostConnectionSession {
193
194
  }
194
195
  }
195
196
  #ensureContinuity() {
196
- if (this.#closed || this.#inputClosed)
197
+ if (this.#closed || this.#inputClosedAbort.signal.aborted)
197
198
  return;
198
199
  const service = this.#options.resolveContinuity();
199
200
  if (!service)
@@ -222,7 +223,7 @@ export class RuntimeHostConnectionSession {
222
223
  this.#continuityService = undefined;
223
224
  }
224
225
  #ensureClientCapabilities() {
225
- if (this.#closed || this.#inputClosed)
226
+ if (this.#closed || this.#inputClosedAbort.signal.aborted)
226
227
  return;
227
228
  // Guests observe and submit approval requests; they cannot provide Client
228
229
  // Capabilities or directly admit a Turn. In particular, their pending and
@@ -274,7 +275,7 @@ export class RuntimeHostConnectionSession {
274
275
  void this.#clientCapabilityCloseTask.catch(() => undefined);
275
276
  }
276
277
  attachGlobalChanges() {
277
- if (this.#closed || this.#inputClosed)
278
+ if (this.#closed || this.#inputClosedAbort.signal.aborted)
278
279
  return;
279
280
  const service = this.#options.resolveHostChanges?.();
280
281
  if (!service || this.#hostChanges)
@@ -316,7 +317,7 @@ export class RuntimeHostConnectionSession {
316
317
  if (this.#closed)
317
318
  return;
318
319
  this.#closed = true;
319
- this.#inputClosed = true;
320
+ this.#inputClosedAbort.abort();
320
321
  this.#detachContinuity();
321
322
  this.#detachClientCapabilities();
322
323
  this.#detachHostChanges();
@@ -22,7 +22,7 @@ import { mergeUsageBuckets, mergeUsageSummary } from '@maka/core/usage-ledger-me
22
22
  import { authenticateInteractiveDailyReviewAuthorityWriter, } from '@maka/storage/daily-review-authority';
23
23
  import { authenticateInteractiveUsageStoresWriter, } from '@maka/storage/usage-stores';
24
24
  import { DAILY_REVIEW_RESULT_MAX_BYTES, } from '../protocol/index.js';
25
- import { CanonicalUsageProjectionIncompleteError, readCompleteCanonicalUsage, } from './canonical-usage-reader.js';
25
+ import { CanonicalUsageProjectionIncompleteError, readCanonicalUsageBuckets, readCompleteCanonicalUsageSummary, } from './canonical-usage-reader.js';
26
26
  const ARCHIVE_LIMIT = 180;
27
27
  const SCHEDULER_INTERVAL_MS = 60_000;
28
28
  /** Host-owned Daily Review data, generation, archive, and scheduling boundary. */
@@ -196,7 +196,10 @@ export class HostDailyReviewCoordinator {
196
196
  }
197
197
  async #buildSummary(range, now) {
198
198
  const query = dailyUsageQuery(range);
199
- const canonical = await readCompleteCanonicalUsage(this.#usage, query, now);
199
+ // The summary read repairs the projection and refuses an incomplete one; the
200
+ // bucket read that follows reuses that pass rather than repairing again.
201
+ const canonical = await readCompleteCanonicalUsageSummary(this.#usage, query, now);
202
+ const canonicalModels = await readCanonicalUsageBuckets(this.#usage, query, 'model', now, false);
200
203
  const [usageSummary, toolBuckets, modelBuckets, sessions] = await Promise.all([
201
204
  this.#usage.telemetry.summary(query),
202
205
  this.#usage.telemetry.buckets(query, 'tool'),
@@ -205,10 +208,10 @@ export class HostDailyReviewCoordinator {
205
208
  ]);
206
209
  return buildDailyReviewSummary({
207
210
  day: range,
208
- usageSummary: mergeUsageSummary(usageSummary, canonical, query, now),
211
+ usageSummary: mergeUsageSummary(usageSummary, canonical),
209
212
  sessions: pickDailyReviewSessions(collapseSessionRevisions(sessions), range, DAILY_REVIEW_LIST_LIMIT),
210
213
  topTools: pickDailyReviewTopEntries(toolBuckets, DAILY_REVIEW_LIST_LIMIT),
211
- topModels: pickDailyReviewTopEntries(mergeUsageBuckets(modelBuckets, canonical, query, 'model', now).buckets, DAILY_REVIEW_LIST_LIMIT),
214
+ topModels: pickDailyReviewTopEntries(mergeUsageBuckets(modelBuckets, canonicalModels).buckets, DAILY_REVIEW_LIST_LIMIT),
212
215
  });
213
216
  }
214
217
  async #run(input) {