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

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 (215) hide show
  1. package/README.md +38 -19
  2. package/README.zh-CN.md +34 -19
  3. package/dist/acp/maka-acp-agent.js +2 -1
  4. package/dist/acp/session-configuration.js +143 -0
  5. package/dist/acp/session-registry.js +90 -4
  6. package/dist/cli-core.js +2 -0
  7. package/dist/pi-transcript-tools.js +6 -0
  8. package/dist/pi-transcript.js +5 -12
  9. package/dist/pi-tui-layout.js +56 -10
  10. package/dist/pi-tui-pickers.js +102 -1
  11. package/dist/pi-tui-runner.js +230 -46
  12. package/dist/pi-tui-todo.js +221 -0
  13. package/dist/pi-tui-transcript-viewer.js +134 -7
  14. package/dist/runtime-host-cli-context.js +224 -78
  15. package/dist/runtime-host-cli-installation.js +8 -2
  16. package/dist/runtime-host-cli.js +31 -1
  17. package/dist/runtime-host-handoff-surface.js +106 -0
  18. package/dist/runtime-host-installed-update-bootstrap.js +13 -0
  19. package/dist/runtime-host-installed-update-coordinator.js +33 -0
  20. package/dist/runtime-host-lifecycle-transaction.js +9 -1
  21. package/dist/runtime-host-local-handoff.js +48 -5
  22. package/dist/runtime-host-local-managed-activation.js +84 -0
  23. package/dist/runtime-host-local-source-retirement.js +18 -2
  24. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  25. package/dist/runtime-host-operator-retirement.js +50 -0
  26. package/dist/runtime-host-service-manager.js +3 -3
  27. package/dist/runtime-host-session-channel.js +13 -0
  28. package/dist/runtime-host-session-driver.js +46 -26
  29. package/dist/runtime-host-session-update.js +62 -0
  30. package/dist/runtime-host-tui-command.js +38 -73
  31. package/dist/runtime-host-tui-context.js +1 -0
  32. package/dist/runtime-host-tui-owner.js +226 -0
  33. package/dist/tui-copy-catalog.js +219 -6
  34. package/dist/tui-host-owner-copy.js +24 -0
  35. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  36. package/node_modules/@maka/core/dist/agent-run.js +1 -0
  37. package/node_modules/@maka/core/dist/attachments.js +3 -0
  38. package/node_modules/@maka/core/dist/canonical-json.js +27 -0
  39. package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
  40. package/node_modules/@maka/core/dist/capabilities.js +35 -0
  41. package/node_modules/@maka/core/dist/computer-use.js +0 -1
  42. package/node_modules/@maka/core/dist/display-redaction.js +18 -0
  43. package/node_modules/@maka/core/dist/llm-connections.js +13 -0
  44. package/node_modules/@maka/core/dist/model-call-attempt.js +2 -0
  45. package/node_modules/@maka/core/dist/model-failure.js +40 -0
  46. package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
  47. package/node_modules/@maka/core/dist/model-metadata.js +7 -3
  48. package/node_modules/@maka/core/dist/model-web-search.js +5 -4
  49. package/node_modules/@maka/core/dist/provider-registry.js +45 -4
  50. package/node_modules/@maka/core/dist/record-schema.js +9 -2
  51. package/node_modules/@maka/core/dist/redaction.js +35 -0
  52. package/node_modules/@maka/core/dist/run-composition.js +77 -2
  53. package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
  54. package/node_modules/@maka/core/dist/runtime-event.js +37 -6
  55. package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
  56. package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
  57. package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
  58. package/node_modules/@maka/core/dist/session.js +84 -56
  59. package/node_modules/@maka/core/dist/slash-command-catalog.js +3 -0
  60. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
  61. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  62. package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
  63. package/node_modules/@maka/core/package.json +5 -0
  64. package/node_modules/@maka/eval/dist/experiment-directory.js +4 -13
  65. package/node_modules/@maka/mcp/dist/index.js +131 -1
  66. package/node_modules/@maka/runtime/dist/agent-run-inspect.js +0 -13
  67. package/node_modules/@maka/runtime/dist/agent-run.js +351 -105
  68. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +29 -13
  69. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
  70. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +184 -183
  71. package/node_modules/@maka/runtime/dist/archive-read-tool.js +2 -2
  72. package/node_modules/@maka/runtime/dist/context-budget-helpers.js +0 -16
  73. package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
  74. package/node_modules/@maka/runtime/dist/conversation-copy.js +158 -15
  75. package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +3 -3
  76. package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
  77. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
  78. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
  79. package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
  80. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +174 -0
  81. package/node_modules/@maka/runtime/dist/mcp-tools.js +7 -2
  82. package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
  83. package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
  84. package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
  85. package/node_modules/@maka/runtime/dist/model-fetcher.js +49 -2
  86. package/node_modules/@maka/runtime/dist/model-history.js +0 -112
  87. package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
  88. package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
  89. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
  90. package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
  91. package/node_modules/@maka/runtime/dist/plugin-runtime.js +20 -10
  92. package/node_modules/@maka/runtime/dist/plugin-tool-service.js +205 -0
  93. package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
  94. package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +76 -109
  95. package/node_modules/@maka/runtime/dist/request-shape.js +23 -0
  96. package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
  97. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +83 -55
  98. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +121 -159
  99. package/node_modules/@maka/runtime/dist/runtime-kernel.js +157 -112
  100. package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
  101. package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
  102. package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
  103. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
  104. package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
  105. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
  106. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +21 -0
  107. package/node_modules/@maka/runtime/dist/stream-graph-supervisor-tools.js +0 -5
  108. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
  109. package/node_modules/@maka/runtime/dist/test-connection.js +16 -17
  110. package/node_modules/@maka/runtime/dist/tool-activation-identity.js +41 -0
  111. package/node_modules/@maka/runtime/dist/tool-availability.js +11 -1
  112. package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
  113. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +63 -1
  114. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +42 -12
  115. package/node_modules/@maka/runtime/dist/tool-result-archive.js +27 -4
  116. package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
  117. package/node_modules/@maka/runtime/package.json +2 -0
  118. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
  119. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
  120. package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
  121. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +179 -0
  122. package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +275 -0
  123. package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
  124. package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
  126. package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
  127. package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +46 -5
  128. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +1 -3
  129. package/node_modules/@maka/runtime-host/dist/node-error.js +22 -0
  130. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  131. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +1 -3
  132. package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
  133. package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +0 -1
  134. package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +1 -1
  135. package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +1 -3
  136. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
  137. package/node_modules/@maka/runtime-host/dist/protocol/index.js +29 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  139. package/node_modules/@maka/runtime-host/dist/protocol/plan.js +1 -0
  140. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +27 -5
  141. package/node_modules/@maka/runtime-host/dist/protocol/project-catalog.js +2 -2
  142. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
  143. package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
  144. package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
  145. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
  146. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +31 -2
  147. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
  148. package/node_modules/@maka/runtime-host/dist/server/agent-graph-coordinator.js +0 -3
  149. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
  150. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
  151. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +32 -32
  152. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +144 -33
  153. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +45 -16
  155. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
  156. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
  157. package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
  158. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
  159. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
  160. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +47 -22
  161. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
  162. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +6 -0
  164. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
  165. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
  166. package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
  167. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
  168. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
  169. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +5 -2
  170. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +12 -55
  171. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
  172. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
  173. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
  174. package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
  175. package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
  176. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +20 -2
  177. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +13 -4
  178. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +46 -0
  179. package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
  180. package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
  181. package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -5
  182. package/node_modules/@maka/storage/dist/codex-session-adapter.js +284 -198
  183. package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
  184. package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
  185. package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
  186. package/node_modules/@maka/storage/dist/git-exec.js +61 -0
  187. package/node_modules/@maka/storage/dist/git-worktree-child-executor.js +8 -35
  188. package/node_modules/@maka/storage/dist/goal-authority.js +2 -2
  189. package/node_modules/@maka/storage/dist/interaction-store.js +2 -2
  190. package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
  191. package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
  192. package/node_modules/@maka/storage/dist/project-catalog.js +2 -23
  193. package/node_modules/@maka/storage/dist/runtime-event-invariants.js +2 -2
  194. package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
  195. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +8 -3
  196. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
  197. package/node_modules/@maka/storage/dist/scheduled-task-store.js +249 -283
  198. package/node_modules/@maka/storage/dist/session-bundle-manifest.js +5 -17
  199. package/node_modules/@maka/storage/dist/session-bundle-policy.js +26 -5
  200. package/node_modules/@maka/storage/dist/session-copy-cleanup.js +2 -1
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
  202. package/node_modules/@maka/storage/dist/session-repository.js +767 -0
  203. package/node_modules/@maka/storage/dist/session-store.js +25 -99
  204. package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
  205. package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
  206. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
  207. package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
  208. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +130 -27
  209. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
  210. package/node_modules/@maka/storage/dist/storage-id.js +28 -0
  211. package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +138 -0
  212. package/node_modules/@maka/storage/dist/workspace-identity.js +2 -15
  213. package/node_modules/@maka/storage/dist/workspace-version-authority-internal.js +1 -8
  214. package/node_modules/@maka/storage/package.json +2 -0
  215. package/package.json +1 -1
@@ -62,7 +62,30 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
62
62
  export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
63
63
  // Increment when the same protocol version no longer guarantees safe Client-Host
64
64
  // interoperability. Mismatches are rejected before domain commands are admitted.
65
- export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 121;
65
+ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 133;
66
+ // 133: WorkHub actions carry attachments and new-Work model/permission defaults.
67
+ // Epoch-132 peers reject these additional fields on strict action shapes.
68
+ // 132: new Tool Result archives use versioned ledger references, not Artifact payloads.
69
+ // 131: Logical model steps bind durable Request Composition identities.
70
+ // 130: Turn contributions carry the optional bounded `failureMessage` diagnostic.
71
+ // Epoch-129 peers reject this added field on the strict contribution shape.
72
+ // 129: Turn states and Turn records drop `partialOutputRetained`. The fact was
73
+ // derived twice — once from the Turn's output rows, once off the state message
74
+ // — and read by nothing; older peers require the field on both.
75
+ // 128: Session transcript bootstraps drop `durableCoverage`. A durable sequence
76
+ // is an event ordinal times its stride, so no projection has contiguous
77
+ // sequences any more and the claim the field made is unavailable to make.
78
+ // 127: Session Turn contributions carry only the Turn's recorded state. Older
79
+ // peers require the derived shape booleans this projection no longer sends.
80
+ // 126: Durable transcript cursors seek Session event ordinals instead of run indexes.
81
+ // 125: Live Turn snapshots carry an optional `rootExecutionKind:'context_compact'`
82
+ // so a running context-compaction Turn can render a transcript row. Epoch-124
83
+ // peers reject the added optional field on the strict live snapshot shape.
84
+ // 124: PTY delivery is independent of the ordered Session state stream. A
85
+ // bounded PTY overflow requests terminal-only snapshot recovery.
86
+ // 123: Failed turns carry canonical retry decisions through bounded projections.
87
+ // 122: Authenticated physical handoff continuations retain logical Turn identity.
88
+ // Older peers cannot decode the handoff source and sealed invocation facts.
66
89
  // 121: Host diagnostics report `upgradeBlockingActivity`, the Host's
67
90
  // authoritative activity answer for maintenance probes, computed by the same
68
91
  // authority that gates `host.upgrade.prepare`. Older Clients reject the
@@ -353,6 +376,7 @@ export function decodeClientFrame(value) {
353
376
  }
354
377
  return {
355
378
  kind: 'hello',
379
+ ...(frame.activitySnapshotVersion === 2 ? { activitySnapshotVersion: 2 } : {}),
356
380
  clientInstanceId: requireClientInstanceId(frame.clientInstanceId),
357
381
  protocolMin,
358
382
  protocolMax,
@@ -370,8 +394,12 @@ export function decodeClientFrame(value) {
370
394
  export function decodeHostFrame(value) {
371
395
  const frame = requireRecord(value, 'host frame');
372
396
  if (frame.kind === 'accepted') {
397
+ if (frame.cooperativeHandoff !== undefined && frame.cooperativeHandoff !== true) {
398
+ throw invalidProtocolFrame('Invalid Runtime Host cooperative handoff capability');
399
+ }
373
400
  return {
374
401
  kind: 'accepted',
402
+ ...(frame.cooperativeHandoff === true ? { cooperativeHandoff: true } : {}),
375
403
  rootId: requireHostRootId(frame.rootId),
376
404
  hostEpoch: requireId(frame.hostEpoch, 'hostEpoch'),
377
405
  connectionId: requireId(frame.connectionId, 'connectionId'),
@@ -203,6 +203,7 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
203
203
  'skill.catalog.query',
204
204
  'subscription.close',
205
205
  'subscription.open',
206
+ 'subscription.pty_interest.set',
206
207
  'session.todo.query',
207
208
  'turn.interrupt',
208
209
  'turn.message.execution.query',
@@ -34,6 +34,7 @@ const QUERY_ERRORS = [
34
34
  ];
35
35
  const CONTROL_ERRORS = [
36
36
  ...QUERY_ERRORS,
37
+ 'unauthorized',
37
38
  'session_busy',
38
39
  'operation_conflict',
39
40
  'persistence_failed',
@@ -108,7 +108,7 @@ export const PLUGIN_PLATFORM_OPERATION_SPECS = {
108
108
  };
109
109
  function decodePluginPlatformQueryInput(value) {
110
110
  const input = requireShapedRecord(value, 'Plugin Platform query input', ['view'], ['rootId', 'cursor', 'limit']);
111
- if (!['status', 'packages', 'entries', 'failures'].includes(input.view)) {
111
+ if (!['status', 'packages', 'entries', 'tools', 'failures'].includes(input.view)) {
112
112
  throw invalidProtocolFrame('Invalid Plugin Platform query view');
113
113
  }
114
114
  const view = input.view;
@@ -125,8 +125,8 @@ function decodePluginPlatformQueryInput(value) {
125
125
  (input.rootId !== undefined || cursor !== undefined || limit !== undefined)) {
126
126
  throw invalidProtocolFrame('Plugin Platform status query does not accept paging');
127
127
  }
128
- if (input.rootId !== undefined && view !== 'entries') {
129
- throw invalidProtocolFrame('Plugin root identity is only valid for Entry queries');
128
+ if (input.rootId !== undefined && view !== 'entries' && view !== 'tools') {
129
+ throw invalidProtocolFrame('Plugin root identity is only valid for Entry and Tool queries');
130
130
  }
131
131
  let rootId;
132
132
  if (input.rootId !== undefined) {
@@ -190,7 +190,7 @@ function decodePluginPlatformQueryResult(value) {
190
190
  ]);
191
191
  if (!Array.isArray(output.items) ||
192
192
  output.items.length > 64 ||
193
- !['packages', 'entries', 'failures'].includes(view)) {
193
+ !['packages', 'entries', 'tools', 'failures'].includes(view)) {
194
194
  throw invalidProtocolFrame('Invalid Plugin Platform page');
195
195
  }
196
196
  const nextCursor = output.nextCursor === null
@@ -201,7 +201,9 @@ function decodePluginPlatformQueryResult(value) {
201
201
  ? { view, items: output.items.map(decodePackageProjection), nextCursor }
202
202
  : view === 'entries'
203
203
  ? { view, items: decodeInspections(output.items), nextCursor }
204
- : { view: 'failures', items: output.items.map(decodePlatformFailure), nextCursor };
204
+ : view === 'tools'
205
+ ? { view, items: output.items.map(decodeToolInspection), nextCursor }
206
+ : { view: 'failures', items: output.items.map(decodePlatformFailure), nextCursor };
205
207
  }
206
208
  requireEncodedByteLimit(decoded, 'Plugin Platform query result', PLUGIN_PLATFORM_QUERY_RESULT_MAX_BYTES);
207
209
  return decoded;
@@ -443,6 +445,26 @@ function decodeInspections(value) {
443
445
  };
444
446
  });
445
447
  }
448
+ function decodeToolInspection(value) {
449
+ const inspection = requireExactRecord(value, 'Plugin Tool inspection', [
450
+ 'entryId',
451
+ 'scopeId',
452
+ 'extensionId',
453
+ 'generation',
454
+ 'toolName',
455
+ 'activeCalls',
456
+ 'retired',
457
+ ]);
458
+ return {
459
+ entryId: requireId(inspection.entryId, 'Plugin Tool Entry identity'),
460
+ scopeId: decodeRootId(inspection.scopeId),
461
+ extensionId: requireId(inspection.extensionId, 'Plugin Tool package identity'),
462
+ generation: requireCount(inspection.generation, 'Plugin Tool generation'),
463
+ toolName: requireString(inspection.toolName, 'Plugin Tool name', 128),
464
+ activeCalls: requireCount(inspection.activeCalls, 'Plugin Tool active call count'),
465
+ retired: requireBoolean(inspection.retired),
466
+ };
467
+ }
446
468
  function decodeEntries(value) {
447
469
  if (!Array.isArray(value))
448
470
  throw invalidProtocolFrame('Invalid Plugin Entry list');
@@ -24,14 +24,14 @@ export const PROJECT_CATALOG_PAGE_MAX_ITEMS = 64;
24
24
  export const PROJECT_CATALOG_PAGE_MAX_BYTES = 48 * 1024;
25
25
  export const PROJECT_CATALOG_CURSOR_MAX_BYTES = 128;
26
26
  export const PROJECT_CATALOG_NAME_MAX_BYTES = 16 * 1024;
27
- export const PROJECT_CATALOG_PATH_MAX_BYTES = 4 * 1024;
27
+ const PROJECT_CATALOG_PATH_MAX_BYTES = 4 * 1024;
28
28
  export const PROJECT_DIRECTORY_PAGE_MAX_ITEMS = 128;
29
29
  export const PROJECT_DIRECTORY_PAGE_MAX_BYTES = 32 * 1024;
30
30
  export const PROJECT_DIRECTORY_MAX_ENTRIES = 4_096;
31
31
  export const PROJECT_DIRECTORY_MAX_ROOTS = 8;
32
32
  export const PROJECT_DIRECTORY_MAX_SEGMENTS = 64;
33
33
  export const PROJECT_DIRECTORY_ROOT_LABEL_MAX_BYTES = 128;
34
- export const PROJECT_DIRECTORY_ROOT_PATH_MAX_BYTES = PROJECT_CATALOG_PATH_MAX_BYTES;
34
+ const PROJECT_DIRECTORY_ROOT_PATH_MAX_BYTES = PROJECT_CATALOG_PATH_MAX_BYTES;
35
35
  export const PROJECT_DIRECTORY_SEGMENT_MAX_BYTES = 255;
36
36
  const PROJECT_DIRECTORY_ROOT_TEXT_ENCODER = new TextEncoder();
37
37
  export function canonicalProjectDirectoryRootSpec(root) {
@@ -72,6 +72,21 @@ const SUBSCRIPTION_CLOSE_ERRORS = [
72
72
  'internal_failure',
73
73
  ];
74
74
  export const SESSION_CONTINUITY_OPERATION_SPECS = {
75
+ 'subscription.pty_interest.set': defineOperation({
76
+ mode: 'control',
77
+ availability: 'ready',
78
+ errors: SUBSCRIPTION_CLOSE_ERRORS,
79
+ decodeInput: (value) => {
80
+ const record = requireExactRecord(value, 'PTY interest input', ['subscriptionId', 'refs']);
81
+ if (!Array.isArray(record.refs) || record.refs.length > 16)
82
+ throw invalidProtocolFrame('PTY interest must contain at most 16 refs');
83
+ const refs = record.refs.map(decodeRuntimeResourceRef);
84
+ if (new Set(refs).size !== refs.length)
85
+ throw invalidProtocolFrame('Duplicate PTY interest');
86
+ return { subscriptionId: requireId(record.subscriptionId, 'subscriptionId'), refs };
87
+ },
88
+ decodeOutput: decodeSubscriptionCloseResult,
89
+ }),
75
90
  'subscription.open': defineOperation({
76
91
  mode: 'control',
77
92
  availability: 'ready',
@@ -104,6 +119,31 @@ export const SESSION_CONTINUITY_OPERATION_SPECS = {
104
119
  export function decodeSubscriptionFrame(value) {
105
120
  requireEncodedByteLimit(value, 'subscription frame', SESSION_SUBSCRIPTION_FRAME_MAX_BYTES);
106
121
  const record = requireRecord(value, 'subscription frame');
122
+ if (record.kind === 'subscription.runtime_resource_pty_data') {
123
+ assertExactKeys(record, 'Runtime Resource PTY data frame', [
124
+ 'kind',
125
+ 'hostEpoch',
126
+ 'subscriptionId',
127
+ 'sessionId',
128
+ 'ref',
129
+ 'ptySequence',
130
+ 'data',
131
+ ...(Object.hasOwn(record, 'reset') ? ['reset'] : []),
132
+ ]);
133
+ if (record.reset !== undefined && record.reset !== true) {
134
+ throw invalidProtocolFrame('PTY reset must be true when present');
135
+ }
136
+ return {
137
+ kind: record.kind,
138
+ hostEpoch: requireId(record.hostEpoch, 'hostEpoch'),
139
+ subscriptionId: requireId(record.subscriptionId, 'subscriptionId'),
140
+ sessionId: requireEntityId(record.sessionId, 'sessionId'),
141
+ ref: decodeRuntimeResourceRef(record.ref),
142
+ ptySequence: requirePositiveCount(record.ptySequence, 'PTY sequence'),
143
+ data: requireUtf8BoundedString(record.data, 'Runtime Resource PTY data', SESSION_RUNTIME_RESOURCE_PTY_DATA_MAX_BYTES),
144
+ ...(record.reset === true ? { reset: true } : {}),
145
+ };
146
+ }
107
147
  const envelope = decodeEnvelope(record);
108
148
  let frame;
109
149
  if (record.kind === 'subscription.session_projection') {
@@ -209,26 +249,6 @@ export function decodeSubscriptionFrame(value) {
209
249
  }
210
250
  : { kind: record.kind, ...envelope, sessionId, domain };
211
251
  }
212
- else if (record.kind === 'subscription.runtime_resource_pty_data') {
213
- assertExactKeys(record, 'Runtime Resource PTY data frame', [
214
- 'kind',
215
- 'hostEpoch',
216
- 'subscriptionId',
217
- 'sequence',
218
- 'sessionId',
219
- 'ref',
220
- 'ptySequence',
221
- 'data',
222
- ]);
223
- frame = {
224
- kind: record.kind,
225
- ...envelope,
226
- sessionId: requireEntityId(record.sessionId, 'sessionId'),
227
- ref: decodeRuntimeResourceRef(record.ref),
228
- ptySequence: requirePositiveCount(record.ptySequence, 'PTY sequence'),
229
- data: requireUtf8BoundedString(record.data, 'Runtime Resource PTY data', SESSION_RUNTIME_RESOURCE_PTY_DATA_MAX_BYTES),
230
- };
231
- }
232
252
  else if (record.kind === 'subscription.closed') {
233
253
  assertExactKeys(record, 'subscription closed frame', [
234
254
  'kind',
@@ -105,7 +105,6 @@ export function decodeSessionTranscriptPageInput(value) {
105
105
  export function decodeSessionTranscriptBootstrap(value) {
106
106
  const bootstrap = requireExactRecord(value, 'Session transcript bootstrap', [
107
107
  'throughSequence',
108
- 'durableCoverage',
109
108
  'overlayMessageCount',
110
109
  'durable',
111
110
  'overlay',
@@ -113,9 +112,6 @@ export function decodeSessionTranscriptBootstrap(value) {
113
112
  const throughSequence = bootstrap.throughSequence === null
114
113
  ? null
115
114
  : requireCount(bootstrap.throughSequence, 'Session transcript watermark');
116
- if (bootstrap.durableCoverage !== 'complete' && bootstrap.durableCoverage !== 'projected') {
117
- throw invalidProtocolFrame('Invalid Session transcript durable coverage');
118
- }
119
115
  const overlayMessageCount = requireCount(bootstrap.overlayMessageCount, 'Session transcript overlay message count');
120
116
  if (overlayMessageCount > SESSION_TRANSCRIPT_OVERLAY_MAX_MESSAGES) {
121
117
  throw invalidProtocolFrame('Session transcript overlay exceeds its message limit');
@@ -135,7 +131,6 @@ export function decodeSessionTranscriptBootstrap(value) {
135
131
  }
136
132
  return {
137
133
  throughSequence,
138
- durableCoverage: bootstrap.durableCoverage,
139
134
  overlayMessageCount,
140
135
  durable,
141
136
  overlay,
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { MODEL_FAILURE_MESSAGE_MAX_BYTES } from '@maka/core/model-failure';
19
20
  import { decodeCanonicalMessage } from '@maka/core/session';
20
21
  import { truncateUtf8 } from '@maka/core/diagnostic-log';
21
22
  import { requireCount, requireEncodedByteLimit, requireEntityId, requireExactRecord, requireUtf8String, } from './codec.js';
@@ -47,11 +48,6 @@ export function mergeSessionTurnContributions(current, next) {
47
48
  ? next.latestState
48
49
  : current.latestState,
49
50
  userPromptPreview: current.userPromptPreview ?? next.userPromptPreview,
50
- hasAssistantMessage: current.hasAssistantMessage || next.hasAssistantMessage,
51
- hasAssistantOutput: current.hasAssistantOutput || next.hasAssistantOutput,
52
- hasToolResult: current.hasToolResult || next.hasToolResult,
53
- hasFailedToolResult: current.hasFailedToolResult || next.hasFailedToolResult,
54
- hasAbortNote: current.hasAbortNote || next.hasAbortNote,
55
51
  };
56
52
  }
57
53
  export function projectSessionTurnContributionForWire(contribution) {
@@ -69,11 +65,6 @@ export function projectSessionTurnContributionForWire(contribution) {
69
65
  userPromptPreview: contribution.userPromptPreview === null
70
66
  ? null
71
67
  : truncateUtf8(contribution.userPromptPreview, SESSION_TURN_PROMPT_PREVIEW_MAX_BYTES),
72
- hasAssistantMessage: contribution.hasAssistantMessage,
73
- hasAssistantOutput: contribution.hasAssistantOutput,
74
- hasToolResult: contribution.hasToolResult,
75
- hasFailedToolResult: contribution.hasFailedToolResult,
76
- hasAbortNote: contribution.hasAbortNote,
77
68
  };
78
69
  }
79
70
  function projectTurnStateMessageForWire(message) {
@@ -109,49 +100,44 @@ function projectTurnStateMessageForWire(message) {
109
100
  ...(message.errorClass
110
101
  ? { errorClass: truncateUtf8(message.errorClass, SESSION_TURN_DIAGNOSTIC_MAX_BYTES) }
111
102
  : {}),
112
- partialOutputRetained: message.partialOutputRetained,
103
+ ...(message.failureMessage
104
+ ? {
105
+ failureMessage: truncateUtf8(message.failureMessage, MODEL_FAILURE_MESSAGE_MAX_BYTES, '…'),
106
+ }
107
+ : {}),
108
+ ...(message.retry ? { retry: message.retry } : {}),
113
109
  };
114
110
  }
111
+ /**
112
+ * The Turn a contribution describes, or nothing when its ending is not on the
113
+ * page yet.
114
+ *
115
+ * A Turn's status is read off the `turn_state` its terminal projects; a
116
+ * contribution without one has not been folded up to its ending, and a status
117
+ * guessed from the rows that did arrive is one no reader trusts anyway.
118
+ */
115
119
  export function projectSessionTurnContribution(contribution) {
116
120
  const state = contribution.latestState?.message;
117
- const partialOutputRetained = contribution.hasAssistantOutput || contribution.hasToolResult;
118
- if (state) {
119
- return {
120
- turnId: contribution.turnId,
121
- firstSequence: contribution.firstSequence,
122
- ...(contribution.userPromptPreview
123
- ? { userPromptPreview: contribution.userPromptPreview }
124
- : {}),
125
- status: state.status,
126
- statusSource: 'recorded',
127
- ...(state.parentTurnId ? { parentTurnId: state.parentTurnId } : {}),
128
- ...(state.retriedFromTurnId ? { retriedFromTurnId: state.retriedFromTurnId } : {}),
129
- ...(state.regeneratedFromTurnId
130
- ? { regeneratedFromTurnId: state.regeneratedFromTurnId }
131
- : {}),
132
- ...(state.branchOfTurnId ? { branchOfTurnId: state.branchOfTurnId } : {}),
133
- ...(state.parentSessionId ? { parentSessionId: state.parentSessionId } : {}),
134
- ...(state.abortedAt !== undefined ? { abortedAt: state.abortedAt } : {}),
135
- ...(state.abortSource ? { abortSource: state.abortSource } : {}),
136
- ...(state.errorClass ? { errorClass: state.errorClass } : {}),
137
- partialOutputRetained: state.partialOutputRetained || partialOutputRetained,
138
- };
139
- }
121
+ if (!state)
122
+ return undefined;
140
123
  return {
141
124
  turnId: contribution.turnId,
142
125
  firstSequence: contribution.firstSequence,
143
126
  ...(contribution.userPromptPreview
144
127
  ? { userPromptPreview: contribution.userPromptPreview }
145
128
  : {}),
146
- status: contribution.hasAbortNote
147
- ? 'aborted'
148
- : contribution.hasAssistantMessage
149
- ? 'completed'
150
- : contribution.hasFailedToolResult
151
- ? 'failed'
152
- : 'completed',
153
- statusSource: 'inferred',
154
- partialOutputRetained,
129
+ status: state.status,
130
+ statusSource: 'recorded',
131
+ ...(state.parentTurnId ? { parentTurnId: state.parentTurnId } : {}),
132
+ ...(state.retriedFromTurnId ? { retriedFromTurnId: state.retriedFromTurnId } : {}),
133
+ ...(state.regeneratedFromTurnId ? { regeneratedFromTurnId: state.regeneratedFromTurnId } : {}),
134
+ ...(state.branchOfTurnId ? { branchOfTurnId: state.branchOfTurnId } : {}),
135
+ ...(state.parentSessionId ? { parentSessionId: state.parentSessionId } : {}),
136
+ ...(state.abortedAt !== undefined ? { abortedAt: state.abortedAt } : {}),
137
+ ...(state.abortSource ? { abortSource: state.abortSource } : {}),
138
+ ...(state.errorClass ? { errorClass: state.errorClass } : {}),
139
+ ...(state.failureMessage ? { failureMessage: state.failureMessage } : {}),
140
+ ...(state.retry ? { retry: state.retry } : {}),
155
141
  };
156
142
  }
157
143
  const QUERY_ERRORS = [
@@ -283,11 +269,6 @@ function decodeSessionTurnContribution(value) {
283
269
  'firstSequence',
284
270
  'latestState',
285
271
  'userPromptPreview',
286
- 'hasAssistantMessage',
287
- 'hasAssistantOutput',
288
- 'hasToolResult',
289
- 'hasFailedToolResult',
290
- 'hasAbortNote',
291
272
  ]);
292
273
  let latestState = null;
293
274
  if (contribution.latestState !== null) {
@@ -317,15 +298,5 @@ function decodeSessionTurnContribution(value) {
317
298
  userPromptPreview: contribution.userPromptPreview === null
318
299
  ? null
319
300
  : requireUtf8String(contribution.userPromptPreview, 'Session turn prompt preview', SESSION_TURN_PROMPT_PREVIEW_MAX_BYTES),
320
- hasAssistantMessage: requireBoolean(contribution.hasAssistantMessage),
321
- hasAssistantOutput: requireBoolean(contribution.hasAssistantOutput),
322
- hasToolResult: requireBoolean(contribution.hasToolResult),
323
- hasFailedToolResult: requireBoolean(contribution.hasFailedToolResult),
324
- hasAbortNote: requireBoolean(contribution.hasAbortNote),
325
301
  };
326
302
  }
327
- function requireBoolean(value) {
328
- if (typeof value !== 'boolean')
329
- throw invalidProtocolFrame('Invalid Session turn contribution');
330
- return value;
331
- }
@@ -427,6 +427,12 @@ function requirePositiveCount(value, label) {
427
427
  throw invalidProtocolFrame(`Invalid ${label}`);
428
428
  return count;
429
429
  }
430
+ function requireContextCompactRootExecutionKind(value) {
431
+ if (value !== 'context_compact') {
432
+ throw invalidProtocolFrame('Invalid Turn rootExecutionKind');
433
+ }
434
+ return value;
435
+ }
430
436
  export function decodeTurnSnapshot(value) {
431
437
  const record = requireRecord(value, 'Turn snapshot');
432
438
  const base = {
@@ -478,13 +484,16 @@ export function decodeTurnSnapshot(value) {
478
484
  abortSource: requireString(record.abortSource, 'abortSource', 128),
479
485
  };
480
486
  }
481
- requireShapedRecord(record, 'non-terminal Turn snapshot', ['sessionId', 'turnId', 'runId', 'status'], ['providerRetry']);
487
+ requireShapedRecord(record, 'non-terminal Turn snapshot', ['sessionId', 'turnId', 'runId', 'status'], ['providerRetry', 'rootExecutionKind']);
482
488
  return {
483
489
  ...base,
484
490
  status,
485
491
  ...(record.providerRetry !== undefined
486
492
  ? { providerRetry: decodeTurnProviderRetry(record.providerRetry) }
487
493
  : {}),
494
+ ...(record.rootExecutionKind !== undefined
495
+ ? { rootExecutionKind: requireContextCompactRootExecutionKind(record.rootExecutionKind) }
496
+ : {}),
488
497
  };
489
498
  }
490
499
  export function decodeContextCompactionOutcome(value) {
@@ -535,6 +544,7 @@ function requireProviderRetryReason(value) {
535
544
  if (value === 'network' ||
536
545
  value === 'provider_capacity' ||
537
546
  value === 'provider_unavailable' ||
547
+ value === 'stream_truncated' ||
538
548
  value === 'rate_limit' ||
539
549
  value === 'timeout' ||
540
550
  value === 'unknown') {
@@ -16,6 +16,8 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { decodeMessageContent } from './turn.js';
20
+ import { isWorkHubCreateDefaults } from '@maka/core/session';
19
21
  import { requireCount, requireEntityId, requireExactRecord, requireRecord, requireShapedRecord, requireUtf8String, } from './codec.js';
20
22
  import { invalidProtocolFrame } from './errors.js';
21
23
  import { defineOperation } from './operation-spec.js';
@@ -101,8 +103,14 @@ export function decodeWorkHubCoordinationResolveResult(value) {
101
103
  };
102
104
  }
103
105
  export function decodeWorkHubCoordinationAnswerInput(value) {
104
- const input = requireExactRecord(value, 'WorkHub Coordination answer input', ['turnId', 'text']);
106
+ const input = requireShapedRecord(value, 'WorkHub Coordination answer input', ['turnId', 'text'], ['attachments']);
105
107
  return {
108
+ ...(input.attachments !== undefined
109
+ ? {
110
+ attachments: decodeMessageContent({ text: input.text, attachments: input.attachments })
111
+ .attachments,
112
+ }
113
+ : {}),
106
114
  turnId: requireEntityId(input.turnId, 'WorkHub Coordination Turn id'),
107
115
  text: requireUtf8String(input.text, 'WorkHub Coordination answer text', WORKHUB_COORDINATION_TEXT_MAX_BYTES),
108
116
  };
@@ -146,12 +154,33 @@ export function decodeWorkHubCoordinationCandidatesResult(value) {
146
154
  };
147
155
  }
148
156
  export function decodeWorkHubCoordinationActInput(value) {
149
- const input = requireShapedRecord(value, 'WorkHub Coordination action input', ['actionId', 'userText', 'proposal'], ['candidateSetId', 'create', 'confirmation']);
157
+ const input = requireShapedRecord(value, 'WorkHub Coordination action input', ['actionId', 'userText', 'proposal'], ['candidateSetId', 'create', 'confirmation', 'newWorkDefaults', 'attachments']);
150
158
  const proposal = decodeWorkHubCoordinationProposal(input.proposal);
159
+ if (input.newWorkDefaults !== undefined &&
160
+ (!isWorkHubCreateDefaults(input.newWorkDefaults) ||
161
+ !(proposal.disposition === 'create_new' ||
162
+ (proposal.disposition === 'replace' && proposal.target.disposition === 'create_new')))) {
163
+ throw invalidProtocolFrame('Invalid WorkHub creation defaults');
164
+ }
165
+ if (input.attachments !== undefined &&
166
+ !['answer_here', 'delegate_existing', 'create_new', 'replace'].includes(proposal.disposition)) {
167
+ throw invalidProtocolFrame('This WorkHub action does not accept attachments');
168
+ }
151
169
  const base = {
152
170
  actionId: requireEntityId(input.actionId, 'WorkHub Coordination action id'),
153
171
  userText: requireUtf8String(input.userText, 'WorkHub Coordination action text', WORKHUB_COORDINATION_TEXT_MAX_BYTES),
154
172
  proposal,
173
+ ...(input.attachments !== undefined
174
+ ? {
175
+ attachments: decodeMessageContent({
176
+ text: input.userText,
177
+ attachments: input.attachments,
178
+ }).attachments,
179
+ }
180
+ : {}),
181
+ ...(input.newWorkDefaults !== undefined
182
+ ? { newWorkDefaults: input.newWorkDefaults }
183
+ : {}),
155
184
  };
156
185
  if (proposal.disposition === 'delegate_existing') {
157
186
  if (input.create !== undefined ||
@@ -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
  ]);
@@ -117,9 +117,6 @@ export class HostAgentGraphCoordinator {
117
117
  export function projectAgentGraphClientSnapshot(snapshot) {
118
118
  return projectSnapshot(snapshot);
119
119
  }
120
- export function projectAgentGraphOperatorInspection(inspection) {
121
- return projectInspection(inspection);
122
- }
123
120
  function projectSnapshot(snapshot) {
124
121
  const operators = snapshot.operators.slice(0, AGENT_GRAPH_MAX_OPERATORS).map(projectOperator);
125
122
  const visibleOperatorIds = new Set(operators.map((operator) => operator.operatorId));
@@ -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) {
@@ -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();