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
@@ -616,6 +616,16 @@ class PeerMeshNodeImpl {
616
616
  transitRelayPeerIds: Object.freeze(transitRelayPeerIds),
617
617
  });
618
618
  }
619
+ peerConnected(peerId) {
620
+ if (this.#lifetime.signal.aborted)
621
+ return;
622
+ const localPeerId = this.#peer.identity().peerId;
623
+ if (peerId !== localPeerId &&
624
+ this.#store
625
+ .read()
626
+ .meshes.some((state) => isActiveMembership(state, localPeerId) && state.roster.roster.members.includes(peerId)))
627
+ this.#triggerReconciliation();
628
+ }
619
629
  async prepareRoutes(peerId, signal) {
620
630
  this.#assertOpen();
621
631
  signal.throwIfAborted();
@@ -821,13 +831,22 @@ class PeerMeshNodeImpl {
821
831
  const gossipCursor = this.#gossipCursor;
822
832
  this.#gossipCursor = (this.#gossipCursor + 1) % PEER_MESH_MAX_MEMBERS;
823
833
  const now = this.#now();
834
+ const targetFor = (peerId) => {
835
+ const signed = latestReachability(stored.reachability, peerId, now, true);
836
+ if (signed)
837
+ return dialTarget(signed);
838
+ // A fresh Session Share can reconnect an existing member after all of
839
+ // its stored routes expired. Reuse that authenticated connection to
840
+ // exchange signed evidence; the connection itself grants no membership.
841
+ return this.#peer.isConnected(peerId)
842
+ ? { peerId, routeHints: [], coordinationRelays: [] }
843
+ : undefined;
844
+ };
824
845
  for (const [index, state] of memberships.entries()) {
825
846
  const meshId = state.roster.roster.meshId;
826
847
  const desiredMembership = state.role === 'replica' ? state.desiredMembership : 'active';
827
- const authority = state.role === 'replica'
828
- ? currentAuthorityTarget(state, stored.reachability, now)
829
- : undefined;
830
- if (authority && authority.lease.peerId !== excludedPeerId) {
848
+ const authority = state.role === 'replica' ? targetFor(state.roster.roster.authorityPeerId) : undefined;
849
+ if (authority && authority.peerId !== excludedPeerId) {
831
850
  pending.push({
832
851
  kind: 'membership',
833
852
  meshId,
@@ -843,7 +862,7 @@ class PeerMeshNodeImpl {
843
862
  peerId !== excludedPeerId &&
844
863
  (state.role === 'authority' || peerId !== state.roster.roster.authorityPeerId))
845
864
  .flatMap((peerId) => {
846
- const target = peerTarget(peerId, stored.reachability, now);
865
+ const target = targetFor(peerId);
847
866
  return target ? [target] : [];
848
867
  });
849
868
  if (rotatingTargets.length === 0)
@@ -902,7 +921,7 @@ class PeerMeshNodeImpl {
902
921
  }
903
922
  async #notifyLeave(meshId, target, roster, signal) {
904
923
  const stream = await this.#peer.connectMeshControl({
905
- ...dialTarget(target),
924
+ ...target,
906
925
  directDeadlineMs: CONNECT_DEADLINE_MS,
907
926
  }, signal);
908
927
  try {
@@ -918,16 +937,15 @@ class PeerMeshNodeImpl {
918
937
  }
919
938
  async #syncPeer(meshId, target, signal) {
920
939
  const localPeerId = this.#peer.identity().peerId;
921
- const targetPeerId = target.lease.peerId;
940
+ const targetPeerId = target.peerId;
922
941
  for (let page = 0; page <= PEER_MESH_MAX_MEMBERS; page += 1) {
923
942
  if (!isActiveMeshMember(this.#store.read().meshes, meshId, localPeerId, targetPeerId))
924
943
  return;
925
944
  const discovered = this.resolveRoutes(targetPeerId);
926
- const targetRoutes = dialTarget(target);
927
945
  const stream = await this.#peer.connectMeshControl({
928
946
  peerId: targetPeerId,
929
- routeHints: mergeAddresses(discovered?.routeHints ?? [], targetRoutes.routeHints),
930
- coordinationRelays: mergeAddresses(discovered?.coordinationRelays ?? [], targetRoutes.coordinationRelays),
947
+ routeHints: mergeAddresses(discovered?.routeHints ?? [], target.routeHints),
948
+ coordinationRelays: mergeAddresses(discovered?.coordinationRelays ?? [], target.coordinationRelays),
931
949
  transitRelayPeerIds: discovered?.transitRelayPeerIds,
932
950
  directDeadlineMs: CONNECT_DEADLINE_MS,
933
951
  }, signal);
@@ -1700,9 +1718,6 @@ function peerMeshStatus(state, identity, endpointKind, reachability, advertiseme
1700
1718
  })),
1701
1719
  });
1702
1720
  }
1703
- function currentAuthorityTarget(state, reachability, now) {
1704
- return latestReachability(reachability, state.roster.roster.authorityPeerId, now, true);
1705
- }
1706
1721
  function rosterAnnouncementTargets(memberPeerIds, reachability, localPeerId, now) {
1707
1722
  const members = new Set(memberPeerIds);
1708
1723
  return Object.freeze(reachability.filter((signed) => signed.lease.peerId !== localPeerId &&
@@ -1937,9 +1952,6 @@ function hasReachabilityRoutes(signed) {
1937
1952
  function usableHistoricalReachability(signed, now) {
1938
1953
  return signed.lease.expiresAt > now - PEER_REACHABILITY_RECOVERY_HORIZON_MS;
1939
1954
  }
1940
- function peerTarget(peerId, reachability, now) {
1941
- return latestReachability(reachability, peerId, now, true);
1942
- }
1943
1955
  function dialTarget(reachability) {
1944
1956
  return Object.freeze({
1945
1957
  peerId: reachability.lease.peerId,
@@ -46,6 +46,10 @@ const IMPORT_ERRORS = [
46
46
  'not_found',
47
47
  'operation_conflict',
48
48
  'commit_outcome_unknown',
49
+ // Distinct, stable reasons the import page renders as specific banners, so the
50
+ // shell classifies by code rather than by the redacted error message.
51
+ 'model_unavailable',
52
+ 'source_unreadable',
49
53
  ];
50
54
  export const EXTERNAL_SESSION_OPERATION_SPECS = {
51
55
  'external-session.source.query': defineOperation({
@@ -17,13 +17,15 @@
17
17
  * under the License.
18
18
  */
19
19
  import { invalidProtocolFrame } from './errors.js';
20
- import { requireCount, requireEncodedByteLimit, requireExactRecord, requireId, requireRecord, requireString, requireUtf8String, } from './codec.js';
20
+ import { requireCount, requireEncodedByteLimit, requireExactRecord, requireId, requireRecord, requireShapedRecord, requireString, requireUtf8String, } from './codec.js';
21
21
  import { defineOperation } from './operation-spec.js';
22
22
  import { decodeSignedPeerReachabilityLease, } from '../peer-reachability/model.js';
23
23
  export function isHostActivityIdle(activity) {
24
24
  return (activity.connections === 0 &&
25
25
  activity.activeOperations === 0 &&
26
- activity.residencies.length === 0);
26
+ (activity.drainResidencies === undefined
27
+ ? activity.residencies.length === 0
28
+ : activity.drainResidencies === 0));
27
29
  }
28
30
  export const HOST_DIAGNOSTICS_RESULT_MAX_BYTES = 72 * 1024;
29
31
  export const HOST_DIAGNOSTIC_LOG_MAX_ENTRIES = 256;
@@ -81,6 +83,7 @@ function decodeHostDiagnosticsResult(value) {
81
83
  'activeOperations',
82
84
  'activeResidencies',
83
85
  ...(valueRecord.peerEndpoint === undefined ? [] : ['peerEndpoint']),
86
+ 'upgradeBlockingActivity',
84
87
  'compositionModules',
85
88
  'residencies',
86
89
  'protocolVersion',
@@ -104,6 +107,7 @@ function decodeHostDiagnosticsResult(value) {
104
107
  }
105
108
  return {
106
109
  ...decodeHostStatusFields(record),
110
+ upgradeBlockingActivity: requireUpgradeBlockingActivity(record.upgradeBlockingActivity),
107
111
  compositionModules: record.compositionModules.map((moduleId) => requireString(moduleId, 'Runtime Host composition module id', 64)),
108
112
  residencies: record.residencies.map((value) => {
109
113
  const residency = requireExactRecord(value, 'Runtime Host residency', ['label', 'count']);
@@ -123,17 +127,28 @@ function decodeHostDiagnosticsResult(value) {
123
127
  logs: record.logs.map((entry) => requireUtf8String(entry, 'Runtime Host diagnostic log entry', HOST_DIAGNOSTIC_LOG_MAX_ENTRY_BYTES)),
124
128
  };
125
129
  }
130
+ function requireUpgradeBlockingActivity(value) {
131
+ if (typeof value !== 'boolean') {
132
+ throw invalidProtocolFrame('Invalid Runtime Host upgrade blocking activity');
133
+ }
134
+ return value;
135
+ }
126
136
  export function decodeHostActivitySnapshot(value) {
127
- const record = requireExactRecord(value, 'Runtime Host activity', [
128
- 'connections',
129
- 'activeOperations',
130
- 'processUptimeSeconds',
131
- 'residencies',
132
- ]);
137
+ const record = requireShapedRecord(value, 'Runtime Host activity', ['connections', 'activeOperations', 'processUptimeSeconds', 'residencies'], ['drainResidencies', 'cooperativeHandoff']);
133
138
  if (!Array.isArray(record.residencies) || record.residencies.length > 128) {
134
139
  throw invalidProtocolFrame('Invalid Runtime Host activity residencies');
135
140
  }
136
141
  return {
142
+ ...(record.cooperativeHandoff === undefined
143
+ ? {}
144
+ : {
145
+ cooperativeHandoff: requireBoolean(record.cooperativeHandoff, 'Runtime Host cooperative handoff capability'),
146
+ }),
147
+ ...(record.drainResidencies === undefined
148
+ ? {}
149
+ : {
150
+ drainResidencies: requireCount(record.drainResidencies, 'Runtime Host drain residencies'),
151
+ }),
137
152
  connections: requireCount(record.connections, 'Runtime Host activity connections'),
138
153
  activeOperations: requireCount(record.activeOperations, 'Runtime Host activity active operations'),
139
154
  processUptimeSeconds: requireCount(record.processUptimeSeconds, 'Runtime Host activity process uptime'),
@@ -150,13 +165,15 @@ export function decodeHostActivitySnapshot(value) {
150
165
  };
151
166
  }
152
167
  function decodeHostUpgradePrepareInput(value) {
153
- const record = requireExactRecord(value, 'Runtime Host upgrade prepare input', [
154
- 'expectedHostEpoch',
155
- 'allowInterruptActiveTasks',
156
- ]);
168
+ const record = requireShapedRecord(value, 'Runtime Host upgrade prepare input', ['expectedHostEpoch', 'allowInterruptActiveTasks'], ['allowCooperativeHandoff']);
157
169
  return {
158
170
  expectedHostEpoch: requireId(record.expectedHostEpoch, 'Runtime Host expected Host Epoch'),
159
171
  allowInterruptActiveTasks: requireBoolean(record.allowInterruptActiveTasks, 'Runtime Host upgrade interrupt authority'),
172
+ ...(record.allowCooperativeHandoff === undefined
173
+ ? {}
174
+ : {
175
+ allowCooperativeHandoff: requireBoolean(record.allowCooperativeHandoff, 'Runtime Host cooperative handoff authority'),
176
+ }),
160
177
  };
161
178
  }
162
179
  function requireBoolean(value, label) {
@@ -62,7 +62,38 @@ 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 = 117;
65
+ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 130;
66
+ // 130: Turn contributions carry the optional bounded `failureMessage` diagnostic.
67
+ // Epoch-129 peers reject this added field on the strict contribution shape.
68
+ // 129: Turn states and Turn records drop `partialOutputRetained`. The fact was
69
+ // derived twice — once from the Turn's output rows, once off the state message
70
+ // — and read by nothing; older peers require the field on both.
71
+ // 128: Session transcript bootstraps drop `durableCoverage`. A durable sequence
72
+ // is an event ordinal times its stride, so no projection has contiguous
73
+ // sequences any more and the claim the field made is unavailable to make.
74
+ // 127: Session Turn contributions carry only the Turn's recorded state. Older
75
+ // peers require the derived shape booleans this projection no longer sends.
76
+ // 126: Durable transcript cursors seek Session event ordinals instead of run indexes.
77
+ // 125: Live Turn snapshots carry an optional `rootExecutionKind:'context_compact'`
78
+ // so a running context-compaction Turn can render a transcript row. Epoch-124
79
+ // peers reject the added optional field on the strict live snapshot shape.
80
+ // 124: PTY delivery is independent of the ordered Session state stream. A
81
+ // bounded PTY overflow requests terminal-only snapshot recovery.
82
+ // 123: Failed turns carry canonical retry decisions through bounded projections.
83
+ // 122: Authenticated physical handoff continuations retain logical Turn identity.
84
+ // Older peers cannot decode the handoff source and sealed invocation facts.
85
+ // 121: Host diagnostics report `upgradeBlockingActivity`, the Host's
86
+ // authoritative activity answer for maintenance probes, computed by the same
87
+ // authority that gates `host.upgrade.prepare`. Older Clients reject the
88
+ // unknown key when decoding diagnostics, so the pair must refuse each other
89
+ // at the handshake.
90
+ // 120: WorkHub admits named resume proposals with an explicit resumesActionId
91
+ // and returns a transient resume outcome. Older peers cannot decode this action.
92
+ // 119: Session Guest principals expose optional display names and an owner-only
93
+ // rename command. Older peers reject named principal projections.
94
+ // 118: External-session import publishes distinct `model_unavailable` and
95
+ // `source_unreadable` error codes so the shell classifies failures by code
96
+ // instead of the redacted message. Older peers cannot decode the new codes.
66
97
  // 117: WorkHub exposes only one correction linkage per bounded candidate and
67
98
  // no longer returns the Host's complete active-link set.
68
99
  // 116: User deletion rejects workflow-owned Artifacts with operation_conflict.
@@ -341,6 +372,7 @@ export function decodeClientFrame(value) {
341
372
  }
342
373
  return {
343
374
  kind: 'hello',
375
+ ...(frame.activitySnapshotVersion === 2 ? { activitySnapshotVersion: 2 } : {}),
344
376
  clientInstanceId: requireClientInstanceId(frame.clientInstanceId),
345
377
  protocolMin,
346
378
  protocolMax,
@@ -358,8 +390,12 @@ export function decodeClientFrame(value) {
358
390
  export function decodeHostFrame(value) {
359
391
  const frame = requireRecord(value, 'host frame');
360
392
  if (frame.kind === 'accepted') {
393
+ if (frame.cooperativeHandoff !== undefined && frame.cooperativeHandoff !== true) {
394
+ throw invalidProtocolFrame('Invalid Runtime Host cooperative handoff capability');
395
+ }
361
396
  return {
362
397
  kind: 'accepted',
398
+ ...(frame.cooperativeHandoff === true ? { cooperativeHandoff: true } : {}),
363
399
  rootId: requireHostRootId(frame.rootId),
364
400
  hostEpoch: requireId(frame.hostEpoch, 'hostEpoch'),
365
401
  connectionId: requireId(frame.connectionId, 'connectionId'),
@@ -114,6 +114,7 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
114
114
  'collaboration.grant.revoke',
115
115
  'collaboration.invitation.prepare',
116
116
  'collaboration.principal.revoke',
117
+ 'collaboration.principal.rename',
117
118
  'collaboration.turn-request.decide',
118
119
  'collaboration.turn-request.query',
119
120
  'connection.catalog.create',
@@ -202,6 +203,7 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
202
203
  'skill.catalog.query',
203
204
  'subscription.close',
204
205
  'subscription.open',
206
+ 'subscription.pty_interest.set',
205
207
  'session.todo.query',
206
208
  'turn.interrupt',
207
209
  'turn.message.execution.query',
@@ -54,6 +54,24 @@ export const SESSION_COLLABORATION_OPERATION_SPECS = {
54
54
  decodeInput: decodeCollaborationGrantRevokeInput,
55
55
  decodeOutput: decodeCollaborationGrantRevokeResult,
56
56
  }),
57
+ 'collaboration.principal.rename': defineOperation({
58
+ mode: 'command',
59
+ availability: 'ready',
60
+ errors: COLLABORATION_ERRORS,
61
+ decodeInput(value) {
62
+ const record = requireExactRecord(value, 'Guest alias', ['principalId', 'displayName']);
63
+ return {
64
+ principalId: decodePrincipalId(record.principalId),
65
+ displayName: decodeCollaborationDisplayName(record.displayName),
66
+ };
67
+ },
68
+ decodeOutput(value) {
69
+ const record = requireExactRecord(value, 'Guest alias result', ['renamed']);
70
+ if (typeof record.renamed !== 'boolean')
71
+ throw invalidProtocolFrame('Invalid Guest alias result');
72
+ return { renamed: record.renamed };
73
+ },
74
+ }),
57
75
  'collaboration.principal.revoke': defineOperation({
58
76
  mode: 'command',
59
77
  availability: 'ready',
@@ -179,19 +197,28 @@ function decodeCollaborationAccessQueryResult(value) {
179
197
  };
180
198
  }
181
199
  function decodeSessionGuestPrincipal(value) {
182
- const record = requireShapedRecord(value, 'Session Guest principal', ['principalId', 'status', 'createdAt'], ['expiresAt']);
200
+ const record = requireShapedRecord(value, 'Session Guest principal', ['principalId', 'status', 'createdAt'], ['expiresAt', 'displayName']);
183
201
  if (record.status !== 'pending' && record.status !== 'active') {
184
202
  throw invalidProtocolFrame('Invalid Session Guest principal status');
185
203
  }
186
204
  return {
187
205
  principalId: decodePrincipalId(record.principalId),
188
206
  status: record.status,
207
+ ...(record.displayName === undefined
208
+ ? {}
209
+ : { displayName: decodeCollaborationDisplayName(record.displayName) }),
189
210
  createdAt: decodeIsoTimestamp(record.createdAt, 'createdAt'),
190
211
  ...(record.expiresAt === undefined
191
212
  ? {}
192
213
  : { expiresAt: decodeIsoTimestamp(record.expiresAt, 'expiresAt') }),
193
214
  };
194
215
  }
216
+ export function decodeCollaborationDisplayName(value) {
217
+ const name = requireUtf8String(value, 'Guest alias', 256).trim();
218
+ if (!name)
219
+ throw invalidProtocolFrame('Guest alias must not be blank');
220
+ return name;
221
+ }
195
222
  function decodeCollaborationGrantRevokeInput(value) {
196
223
  const record = requireExactRecord(value, 'collaboration grant revoke input', ['grantId']);
197
224
  return { grantId: requireId(record.grantId, 'grantId') };
@@ -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') {