maka-agent 0.2.0-dev.11.20260831 → 0.2.0-dev.14.20260902

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 (226) hide show
  1. package/LICENSE +2 -2
  2. package/RUNTIME_HOST_PEER_DEPENDENCIES.rust.tsv +70 -0
  3. package/RUNTIME_HOST_PEER_THIRD_PARTY_NOTICES.txt +1839 -140
  4. package/THIRD_PARTY_NOTICES.txt +2 -2
  5. package/dist/acp/maka-acp-agent.js +6 -3
  6. package/dist/acp/session-registry.js +307 -0
  7. package/dist/acp/stdio-server.js +20 -1
  8. package/dist/cli-core.js +40 -3
  9. package/dist/mcp-capability-provider.js +1 -1
  10. package/dist/onboarding-catalog.js +3 -5
  11. package/dist/pi-transcript.js +21 -17
  12. package/dist/pi-tui-layout.js +4 -2
  13. package/dist/pi-tui-mcp-status.js +44 -130
  14. package/dist/pi-tui-pickers.js +11 -5
  15. package/dist/pi-tui-runner.js +133 -102
  16. package/dist/runtime-host-access-command.js +37 -4
  17. package/dist/runtime-host-capability-provider-command.js +16 -2
  18. package/dist/runtime-host-cli-context.js +73 -3
  19. package/dist/runtime-host-cli.js +187 -10
  20. package/dist/runtime-host-lifecycle-transaction.js +5 -2
  21. package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
  22. package/dist/runtime-host-onboarding.js +12 -16
  23. package/dist/runtime-host-peer-management-command.js +16 -4
  24. package/dist/runtime-host-plugin-command.js +101 -0
  25. package/dist/runtime-host-run-command.js +8 -2
  26. package/dist/runtime-host-service-management-command.js +2 -1
  27. package/dist/runtime-host-setup-command.js +1 -0
  28. package/dist/runtime-host-task-readiness.js +2 -3
  29. package/dist/runtime-host-tui-command.js +1 -1
  30. package/dist/runtime-host-tui-context.js +18 -5
  31. package/dist/runtime-host-update-command.js +71 -35
  32. package/dist/runtime-host-update-discovery.js +1 -0
  33. package/dist/tui-clipboard.js +86 -0
  34. package/dist/tui-copy-catalog.js +248 -0
  35. package/dist/tui-copy-command.js +103 -0
  36. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  37. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  38. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  39. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  40. package/node_modules/@maka/core/dist/attachments.js +92 -1
  41. package/node_modules/@maka/core/dist/bounded-response.js +71 -0
  42. package/node_modules/@maka/core/dist/chat-model-choice.js +8 -33
  43. package/node_modules/@maka/core/dist/client-capability-grant.js +149 -0
  44. package/node_modules/@maka/core/dist/connection-error-copy.js +17 -34
  45. package/node_modules/@maka/core/dist/connection-readiness.js +3 -31
  46. package/node_modules/@maka/core/dist/deep-research.js +1 -20
  47. package/node_modules/@maka/core/dist/events.js +22 -14
  48. package/node_modules/@maka/core/dist/foreign-session.js +2 -2
  49. package/node_modules/@maka/core/dist/interaction.js +49 -2
  50. package/node_modules/@maka/core/dist/llm-connections.js +74 -82
  51. package/node_modules/@maka/core/dist/maka-wordmark.js +23 -0
  52. package/node_modules/@maka/core/dist/model-catalog.js +242 -315
  53. package/node_modules/@maka/core/dist/model-facts.js +13 -19
  54. package/node_modules/@maka/core/dist/model-metadata.generated.js +1907 -1872
  55. package/node_modules/@maka/core/dist/model-metadata.js +184 -199
  56. package/node_modules/@maka/core/dist/model-thinking.js +1 -1
  57. package/node_modules/@maka/core/dist/models-dev-projection.js +302 -0
  58. package/node_modules/@maka/core/dist/models-dev-refresh.js +55 -0
  59. package/node_modules/@maka/core/dist/onboarding.js +2 -1
  60. package/node_modules/@maka/core/dist/provider-auth.js +47 -291
  61. package/node_modules/@maka/core/dist/provider-registry.js +68 -357
  62. package/node_modules/@maka/core/dist/runtime-event.js +5 -0
  63. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +83 -18
  64. package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +9 -1
  65. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +84 -0
  66. package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +75 -0
  67. package/node_modules/@maka/core/dist/runtime-policy.js +5 -2
  68. package/node_modules/@maka/core/dist/session-send-projection.js +2 -1
  69. package/node_modules/@maka/core/dist/session-start-mode.js +42 -0
  70. package/node_modules/@maka/core/dist/session.js +120 -5
  71. package/node_modules/@maka/core/dist/settings.js +10 -2
  72. package/node_modules/@maka/core/dist/slash-command-catalog.js +1 -0
  73. package/node_modules/@maka/core/dist/task-submission-readiness.js +2 -1
  74. package/node_modules/@maka/core/dist/usage-record-schema.js +11 -1
  75. package/node_modules/@maka/core/dist/workhub-creation-intent.js +896 -0
  76. package/node_modules/@maka/core/package.json +8 -2
  77. package/node_modules/@maka/mcp/dist/index.js +1 -0
  78. package/node_modules/@maka/runtime/dist/agent-run.js +7 -0
  79. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +55 -82
  80. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +178 -140
  81. package/node_modules/@maka/runtime/dist/archive-read-tool.js +26 -5
  82. package/node_modules/@maka/runtime/dist/builtin-tools.js +27 -2
  83. package/node_modules/@maka/runtime/dist/context-budget-policy.js +0 -12
  84. package/node_modules/@maka/runtime/dist/conversation-copy.js +66 -43
  85. package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +31 -0
  86. package/node_modules/@maka/runtime/dist/history-compact-error.js +10 -2
  87. package/node_modules/@maka/runtime/dist/history-compact-input-fit.js +7 -1
  88. package/node_modules/@maka/runtime/dist/history-compaction.js +13 -22
  89. package/node_modules/@maka/runtime/dist/image-file.js +5 -20
  90. package/node_modules/@maka/runtime/dist/local-web-fetch.js +2 -43
  91. package/node_modules/@maka/runtime/dist/mcp-tools.js +28 -0
  92. package/node_modules/@maka/runtime/dist/model-fetcher.js +15 -8
  93. package/node_modules/@maka/runtime/dist/model-history.js +59 -17
  94. package/node_modules/@maka/runtime/dist/model-runtime.js +2 -2
  95. package/node_modules/@maka/runtime/dist/plugin-composition-loader.js +173 -20
  96. package/node_modules/@maka/runtime/dist/plugin-runtime.js +219 -0
  97. package/node_modules/@maka/runtime/dist/provider-image-overflow-recovery.js +12 -31
  98. package/node_modules/@maka/runtime/dist/quiescent-session-snapshot.js +78 -0
  99. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +6 -0
  100. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +14 -2
  101. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +11 -10
  102. package/node_modules/@maka/runtime/dist/shell-tools.js +77 -1
  103. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +93 -83
  104. package/node_modules/@maka/runtime/dist/test-connection.js +6 -6
  105. package/node_modules/@maka/runtime/dist/tool-availability.js +74 -5
  106. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +333 -52
  107. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +34 -3
  108. package/node_modules/@maka/runtime/dist/tool-runtime.js +62 -6
  109. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +39 -16
  110. package/node_modules/@maka/runtime/package.json +1 -0
  111. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +10 -3
  112. package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +59 -18
  113. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +3 -2
  114. package/node_modules/@maka/runtime-host/dist/client/connection.js +72 -31
  115. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +49 -4
  116. package/node_modules/@maka/runtime-host/dist/client/index.js +3 -2
  117. package/node_modules/@maka/runtime-host/dist/client/oauth-presentation.js +1 -1
  118. package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +32 -1
  119. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +26 -4
  120. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +8 -0
  121. package/node_modules/@maka/runtime-host/dist/operator/access-management-frame.js +10 -1
  122. package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
  123. package/node_modules/@maka/runtime-host/dist/operator/managed-deployment.js +2 -0
  124. package/node_modules/@maka/runtime-host/dist/operator/peer-management-frame.js +2 -0
  125. package/node_modules/@maka/runtime-host/dist/operator/service-management-frame.js +2 -0
  126. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +56 -12
  127. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +4 -0
  128. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +22 -1
  129. package/node_modules/@maka/runtime-host/dist/protocol/configuration.js +55 -9
  130. package/node_modules/@maka/{storage/dist/task-ledger-store-internal.js → runtime-host/dist/protocol/connection-catalog-change.js} +7 -13
  131. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +37 -0
  132. package/node_modules/@maka/runtime-host/dist/protocol/index.js +49 -1
  133. package/node_modules/@maka/runtime-host/dist/protocol/network-proxy.js +1 -7
  134. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +5 -1
  135. package/node_modules/@maka/runtime-host/dist/protocol/plugin-platform.js +512 -0
  136. package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +72 -61
  137. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +1 -1
  138. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +4 -2
  139. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +5 -12
  140. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +92 -4
  141. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +17 -14
  142. package/node_modules/@maka/runtime-host/dist/server/access-credential-metadata.js +4 -2
  143. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +119 -47
  144. package/node_modules/@maka/runtime-host/dist/server/agent-graph-execution-coordinator.js +1 -2
  145. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +10 -4
  146. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +0 -9
  147. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +192 -18
  148. package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +122 -48
  149. package/node_modules/@maka/runtime-host/dist/server/client-capability-provider-id.js +31 -0
  150. package/node_modules/@maka/runtime-host/dist/server/configuration-coordinator.js +20 -1
  151. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +5 -5
  152. package/node_modules/@maka/runtime-host/dist/server/connection-session.js +1 -0
  153. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +163 -28
  154. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +2 -2
  155. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +4 -1
  156. package/node_modules/@maka/runtime-host/dist/server/extension-bundle.js +249 -0
  157. package/node_modules/@maka/runtime-host/dist/server/extension-package-manifest.js +262 -0
  158. package/node_modules/@maka/runtime-host/dist/server/host-change-feed.js +11 -0
  159. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +15 -0
  160. package/node_modules/@maka/runtime-host/dist/server/index.js +5 -0
  161. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +181 -13
  162. package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +6 -0
  163. package/node_modules/@maka/runtime-host/dist/server/listener-set.js +8 -4
  164. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +88 -22
  165. package/node_modules/@maka/runtime-host/dist/server/model-metadata-refresh.js +96 -0
  166. package/node_modules/@maka/runtime-host/dist/server/network-proxy-coordinator.js +0 -1
  167. package/node_modules/@maka/runtime-host/dist/server/operation-dispatcher.js +43 -118
  168. package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +3 -0
  169. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-patch.js +58 -0
  170. package/node_modules/@maka/runtime-host/dist/server/plugin-composition-store.js +141 -0
  171. package/node_modules/@maka/runtime-host/dist/server/plugin-package-loader.js +130 -0
  172. package/node_modules/@maka/runtime-host/dist/server/plugin-package-store.js +528 -0
  173. package/node_modules/@maka/runtime-host/dist/server/plugin-platform-coordinator.js +249 -0
  174. package/node_modules/@maka/runtime-host/dist/server/plugin-platform.js +1130 -0
  175. package/node_modules/@maka/runtime-host/dist/server/root-admission-owner.js +4 -0
  176. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +24 -5
  177. package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +57 -5
  178. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +2 -1
  179. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +3 -3
  180. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +35 -3
  181. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +16 -0
  182. package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +10 -2
  183. package/node_modules/@maka/runtime-host/dist/server/web-fetch-tool.js +1 -1
  184. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +276 -3
  185. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +101 -1
  186. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +1 -0
  187. package/node_modules/@maka/runtime-host/dist/webrtc-stun-policy.js +114 -0
  188. package/node_modules/@maka/runtime-host/package.json +2 -0
  189. package/node_modules/@maka/storage/dist/agent-run-store.js +4 -0
  190. package/node_modules/@maka/storage/dist/artifact-store.js +7 -23
  191. package/node_modules/@maka/storage/dist/conversation-operational-state.js +3 -0
  192. package/node_modules/@maka/storage/dist/execution-stores.js +3 -0
  193. package/node_modules/@maka/storage/dist/interaction-store-public.js +1 -1
  194. package/node_modules/@maka/storage/dist/interaction-store.js +173 -0
  195. package/node_modules/@maka/storage/dist/production-session-snapshot.js +761 -0
  196. package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1 -1
  197. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +19 -22
  198. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +205 -42
  199. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +2 -2
  200. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +5 -2
  201. package/node_modules/@maka/storage/dist/session-message-projection.js +1 -1
  202. package/node_modules/@maka/storage/dist/session-store.js +32 -6
  203. package/node_modules/@maka/storage/dist/session-todo-store.js +6 -68
  204. package/node_modules/@maka/storage/dist/settings-store.js +16 -25
  205. package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +19 -0
  206. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +10 -1
  207. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +73 -3
  208. package/node_modules/@maka/storage/dist/sqlite-workflow-schema.js +2 -10
  209. package/node_modules/@maka/storage/package.json +2 -0
  210. package/node_modules/fast-uri/index.js +215 -47
  211. package/node_modules/fast-uri/lib/schemes.js +9 -4
  212. package/node_modules/fast-uri/lib/utils.js +396 -92
  213. package/node_modules/fast-uri/package.json +1 -1
  214. package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  215. package/node_modules/qs/CHANGELOG.md +15 -0
  216. package/node_modules/qs/README.md +19 -1
  217. package/node_modules/qs/dist/qs.js +21 -21
  218. package/node_modules/qs/eslint.config.mjs +1 -1
  219. package/node_modules/qs/lib/parse.js +3 -4
  220. package/node_modules/qs/lib/stringify.js +23 -8
  221. package/node_modules/qs/lib/utils.js +10 -3
  222. package/node_modules/qs/package.json +4 -4
  223. package/package.json +1 -1
  224. package/node_modules/@maka/core/dist/task-ledger.js +0 -669
  225. package/node_modules/@maka/storage/dist/task-ledger-authority.js +0 -121
  226. package/node_modules/@maka/storage/dist/task-ledger-store.js +0 -663
@@ -140,6 +140,10 @@ function snapshotMessageContent(content) {
140
140
  }
141
141
  if (snapshot.attachments)
142
142
  Object.freeze(snapshot.attachments);
143
+ for (const reference of snapshot.directoryReferences ?? [])
144
+ Object.freeze(reference);
145
+ if (snapshot.directoryReferences)
146
+ Object.freeze(snapshot.directoryReferences);
143
147
  for (const quote of snapshot.quotes ?? [])
144
148
  Object.freeze(quote);
145
149
  if (snapshot.quotes)
@@ -51,6 +51,7 @@ export class RootTurnCoordinator {
51
51
  assertScheduledTaskRecoveryAdmission;
52
52
  agentGraphEpochs;
53
53
  nameSessionFromRootMessage;
54
+ directoryHostId;
54
55
  handlers = {
55
56
  'turn.resume.query': (input, context) => this.queryTurnResume(input, context),
56
57
  'turn.resume.start': (input, context) => this.startTurnResume(input, context),
@@ -62,7 +63,7 @@ export class RootTurnCoordinator {
62
63
  executionProjection;
63
64
  attachmentValidator;
64
65
  prepareSkillInvocation;
65
- constructor(manager, stores, sessionAdmission, rootAdmissionOwner, interactions, messages, continuity, acquireRecoveryResidency, requestHostDrain, clientCapabilities, resolveExecutionObserver, assertScheduledTaskRecoveryAdmission, attachmentValidator, prepareSkillInvocation, agentGraphEpochs, nameSessionFromRootMessage) {
66
+ constructor(manager, stores, sessionAdmission, rootAdmissionOwner, interactions, messages, continuity, acquireRecoveryResidency, requestHostDrain, clientCapabilities, resolveExecutionObserver, assertScheduledTaskRecoveryAdmission, attachmentValidator, prepareSkillInvocation, agentGraphEpochs, nameSessionFromRootMessage, directoryHostId) {
66
67
  this.manager = manager;
67
68
  this.sessionAdmission = sessionAdmission;
68
69
  this.rootAdmissionOwner = rootAdmissionOwner;
@@ -76,6 +77,7 @@ export class RootTurnCoordinator {
76
77
  this.assertScheduledTaskRecoveryAdmission = assertScheduledTaskRecoveryAdmission;
77
78
  this.agentGraphEpochs = agentGraphEpochs;
78
79
  this.nameSessionFromRootMessage = nameSessionFromRootMessage;
80
+ this.directoryHostId = directoryHostId;
79
81
  this.stores = authenticateExecutionStoresWriter(stores, 'interactive');
80
82
  this.executionProjection = new HostedExecutionProjectionReader(this.stores);
81
83
  this.#admissions = new HostedExecutionAdmissionRegistry((sessionId) => this.#executions.has(sessionId));
@@ -642,7 +644,7 @@ export class RootTurnCoordinator {
642
644
  failed: [],
643
645
  receipts: [],
644
646
  };
645
- const canonicalContent = preflightRootMessageContent(prepared.content);
647
+ const canonicalContent = preflightRootMessageContent(this.validateDirectoryReferences(input.sessionId, prepared.content));
646
648
  if (!canonicalContent.ok)
647
649
  return { error: 'Prepared message content exceeds durable limits' };
648
650
  const binding = prepared.commitCapabilityBinding
@@ -763,17 +765,34 @@ export class RootTurnCoordinator {
763
765
  if (parseSkillInvocationTokens(content.text).length === 0) {
764
766
  return {
765
767
  kind: 'ready',
766
- content,
768
+ content: this.validateDirectoryReferences(input.sessionId, content),
767
769
  skillInvocation: { loaded: [], failed: [], receipts: [] },
768
770
  };
769
771
  }
770
- const prepare = () => this.prepareSkillInvocationContent(input.sessionId, input.turnId, content, []);
772
+ const prepare = async () => {
773
+ const prepared = await this.prepareSkillInvocationContent(input.sessionId, input.turnId, content, []);
774
+ return prepared.kind === 'ready'
775
+ ? {
776
+ ...prepared,
777
+ content: this.validateDirectoryReferences(input.sessionId, prepared.content),
778
+ }
779
+ : prepared;
780
+ };
771
781
  if (input.placement === 'current_turn')
772
782
  return prepare();
773
783
  const preview = await this.previewCapabilityBinding(input.sessionId, '', prepare);
774
784
  return preview.ok ? preview.value : { kind: 'rejected', error: preview.message };
775
785
  });
776
786
  }
787
+ validateDirectoryReferences(sessionId, content) {
788
+ if (!content.directoryReferences?.length)
789
+ return content;
790
+ if (!this.directoryHostId ||
791
+ content.directoryReferences.some((reference) => reference.hostId !== this.directoryHostId)) {
792
+ throw new RuntimeHostedRootUnavailableError(sessionId, 'Directory references belong to a different Runtime Host');
793
+ }
794
+ return content;
795
+ }
777
796
  claimStop(input, commitQueueFence, admission) {
778
797
  return this.runCommand(async () => {
779
798
  const disposition = await this.prepareStopDisposition(input, commitQueueFence, admission);
@@ -957,7 +976,7 @@ export class RootTurnCoordinator {
957
976
  const prepared = await this.prepareRootMessageContent(request, lease);
958
977
  if (prepared.kind === 'rejected')
959
978
  return completedStart(prepared.outcome);
960
- const canonicalContent = preflightRootMessageContent(prepared.content);
979
+ const canonicalContent = preflightRootMessageContent(this.validateDirectoryReferences(request.sessionId, prepared.content));
961
980
  if (!canonicalContent.ok)
962
981
  return completedStart(canonicalContent.outcome);
963
982
  const attachments = canonicalContent.content.attachments ?? [];
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { resolveConnectionModelCatalog } from '@maka/core/model-catalog';
19
20
  import { authenticateRuntimePolicyStoresWriter, RuntimePolicyStoreError, } from '@maka/storage/runtime-policy-stores';
20
21
  import { CONNECTION_CATALOG_PAGE_MAX_BYTES, CONNECTION_CATALOG_PAGE_MAX_ITEMS, } from '../protocol/index.js';
21
22
  import { buildHostAgentSettingsTools } from './agent-settings-tools.js';
@@ -28,6 +29,7 @@ export class HostRuntimePolicyCoordinator {
28
29
  handlers = {
29
30
  'runtime.policy.query': () => this.#queryPolicy(),
30
31
  'runtime.policy.mutate': (input) => this.#mutatePolicy(input),
32
+ 'runtime.policy.network-proxy.update': (input) => this.#updateNetworkProxy(input),
31
33
  'connection.catalog.query': (input) => this.#queryCatalog(input),
32
34
  'connection.catalog.create': (input) => this.#createConnection(input),
33
35
  'connection.catalog.update': (input) => this.#updateConnection(input),
@@ -64,6 +66,27 @@ export class HostRuntimePolicyCoordinator {
64
66
  return projectPolicyMutation(await this.#stores.runtimePolicy.mutate(input));
65
67
  });
66
68
  }
69
+ async #updateNetworkProxy(input) {
70
+ return this.#storeMutation(async () => {
71
+ try {
72
+ await this.validateMutation({
73
+ expectedRevision: input.expectedPolicyRevision,
74
+ operation: { kind: 'set_network_proxy', value: input.networkProxy },
75
+ });
76
+ }
77
+ catch (error) {
78
+ throw new RuntimePolicyStoreError('invalid_policy_input', 'Network proxy update failed Host validation', { cause: error });
79
+ }
80
+ const result = await this.#stores.operations.updateNetworkProxy(input);
81
+ return result.kind === 'committed'
82
+ ? {
83
+ kind: 'committed',
84
+ revision: result.snapshot.revision,
85
+ credentialStatus: result.credentialStatus,
86
+ }
87
+ : result;
88
+ });
89
+ }
67
90
  async #queryCatalog(input) {
68
91
  const stored = await this.#storeQuery(() => this.#stores.connectionCatalog.getSnapshot());
69
92
  if (!stored.ok)
@@ -142,7 +165,9 @@ export class HostRuntimePolicyCoordinator {
142
165
  async #setCredential(input) {
143
166
  return this.#storeMutation(async () => {
144
167
  const result = await this.#stores.credentialVault.set(input);
145
- if (result.kind === 'connection_not_found' || result.kind === 'credential_stale') {
168
+ if (result.kind === 'connection_not_found' ||
169
+ result.kind === 'connection_stale' ||
170
+ result.kind === 'credential_stale') {
146
171
  return result;
147
172
  }
148
173
  const status = result.snapshot.entries.find((entry) => sameLocator(entry.locator, input.locator));
@@ -155,6 +180,9 @@ export class HostRuntimePolicyCoordinator {
155
180
  async #deleteCredential(input) {
156
181
  return this.#storeMutation(async () => {
157
182
  const result = await this.#stores.credentialVault.delete(input);
183
+ if (result.kind === 'connection_stale') {
184
+ throw invariantFailure('Credential deletion returned an impossible connection conflict');
185
+ }
158
186
  if (result.kind === 'connection_not_found' || result.kind === 'credential_stale') {
159
187
  return result;
160
188
  }
@@ -295,15 +323,32 @@ function projectCatalogItems(snapshot) {
295
323
  // table: a header item is atomic to the paginator, so a long declaration
296
324
  // list would make the whole connection unreadable.
297
325
  const { enabledModelIds, models, relayModelProfiles,
298
- // This marker is durable invalidation metadata, not part of the
299
- // client-visible catalog protocol.
300
- lastTestModelFactsFingerprint: _lastTestModelFactsFingerprint, ...header } = connection;
326
+ // When the Host last ran discovery, and the marker that invalidates a
327
+ // test when model facts change: both are the Host's own bookkeeping,
328
+ // not part of the client-visible catalog protocol.
329
+ modelsFetchedAt: _modelsFetchedAt, lastTestModelFactsFingerprint: _lastTestModelFactsFingerprint, ...header } = connection;
330
+ // The Host resolves the catalog because it owns the model metadata the
331
+ // resolution merges in. A client that merged its own bundled copy would
332
+ // describe a model by the version it happens to ship, so two clients on
333
+ // one Host could disagree about the same model.
334
+ const catalogEntries = resolveConnectionModelCatalog({
335
+ slug: connection.slug,
336
+ providerType: connection.providerType,
337
+ defaultModel: snapshot.defaultTarget?.connectionId === connection.connectionId
338
+ ? snapshot.defaultTarget.modelId
339
+ : '',
340
+ enabledModelIds: [...enabledModelIds],
341
+ models: [...models],
342
+ ...(connection.modelSource === undefined ? {} : { modelSource: connection.modelSource }),
343
+ ...(relayModelProfiles === undefined ? {} : { relayModelProfiles }),
344
+ });
301
345
  items.push({
302
346
  kind: 'connection',
303
347
  connectionIndex,
304
348
  ...header,
305
349
  enabledModelIdCount: enabledModelIds.length,
306
350
  modelCount: models.length,
351
+ catalogEntryCount: catalogEntries.length,
307
352
  });
308
353
  for (const [itemIndex, modelId] of enabledModelIds.entries()) {
309
354
  const relayProfile = relayModelProfiles?.[modelId];
@@ -316,7 +361,14 @@ function projectCatalogItems(snapshot) {
316
361
  });
317
362
  }
318
363
  for (const [itemIndex, model] of models.entries()) {
319
- items.push({ kind: 'model', connectionIndex, itemIndex, model });
364
+ // The override's effect travels; which fields it touched does not. That
365
+ // provenance answers one Host-side question — whether a context window
366
+ // was set by hand — and this page is not where it gets asked.
367
+ const { factOverriddenFields: _factOverriddenFields, ...projected } = model;
368
+ items.push({ kind: 'model', connectionIndex, itemIndex, model: projected });
369
+ }
370
+ for (const [itemIndex, entry] of catalogEntries.entries()) {
371
+ items.push({ kind: 'catalog_entry', connectionIndex, itemIndex, entry });
320
372
  }
321
373
  }
322
374
  return items;
@@ -23,7 +23,7 @@ import { isModelExplicitlyUnsupportedForChat } from '@maka/core/model-catalog';
23
23
  import { thinkingVariantsForConnection } from '@maka/core/model-thinking';
24
24
  import { executionBoundaryDisplayMode, } from '@maka/core/sandbox-boundary';
25
25
  import { DEFAULT_SESSION_NAME, normalizeUserSessionName } from '@maka/core/session-name';
26
- import { isSessionStartModeLabel as isExecutionSemanticLabel, sessionStartModeSpec, } from '@maka/core/deep-research';
26
+ import { isSessionStartModeLabel as isExecutionSemanticLabel, sessionStartModeSpec, } from '@maka/core/session-start-mode';
27
27
  import { isWorkHubCoordinationSessionId, isWorkHubCoordinationSessionTarget, } from '@maka/core/session';
28
28
  import { isSessionNotFoundError, SessionMetadataConflictError, SessionMetadataVersionConflictError, SessionReadMarkerMessageNotFoundError, } from '@maka/storage/execution-stores';
29
29
  import { SessionConfigurationRevisionConflictError, SessionConfigurationTransitionError, } from '@maka/runtime/session-manager';
@@ -108,6 +108,7 @@ export class HostSessionCatalogCoordinator {
108
108
  ...(workspace.projectId === null ? {} : { projectId: workspace.projectId }),
109
109
  name: prepared.name,
110
110
  labels: [...prepared.labels],
111
+ llmConnectionId: model.connectionId,
111
112
  llmConnectionSlug: model.connectionSlug,
112
113
  model: model.model,
113
114
  ...(input.thinkingLevel === undefined ? {} : { thinkingLevel: input.thinkingLevel }),
@@ -68,7 +68,7 @@ export class HostSessionRetirementCoordinator {
68
68
  #continuity;
69
69
  #artifacts;
70
70
  #sessionTodo;
71
- #assertNoContextOffloadReferences;
71
+ #contextOffload;
72
72
  #purgeOperationalState;
73
73
  #purgeAgentGraphState;
74
74
  #worktrees;
@@ -95,7 +95,7 @@ export class HostSessionRetirementCoordinator {
95
95
  this.#continuity = options.continuity;
96
96
  this.#artifacts = options.artifacts;
97
97
  this.#sessionTodo = options.sessionTodo;
98
- this.#assertNoContextOffloadReferences = options.assertNoContextOffloadReferences;
98
+ this.#contextOffload = options.contextOffload;
99
99
  this.#purgeOperationalState = options.purgeOperationalState;
100
100
  this.#purgeAgentGraphState = options.purgeAgentGraphState;
101
101
  this.#worktrees = options.worktrees;
@@ -201,7 +201,6 @@ export class HostSessionRetirementCoordinator {
201
201
  if (plan.archive.sessionIds.length > 0) {
202
202
  archiveHandles = await this.#prepareRetirement(plan.archive, 'archive');
203
203
  }
204
- await this.#assertNoContextOffloadReferences?.(plan.remove.sessionIds);
205
204
  const allSessionIds = [...plan.remove.sessionIds, ...plan.archive.sessionIds];
206
205
  await this.#finalizeWorkspacePatches(allSessionIds);
207
206
  await this.#disposeBackends(allSessionIds);
@@ -494,6 +493,7 @@ export class HostSessionRetirementCoordinator {
494
493
  purgeSessionSidecars({
495
494
  artifacts: this.#artifacts,
496
495
  sessionTodo: this.#sessionTodo,
496
+ ...(this.#contextOffload ? { contextOffload: this.#contextOffload } : {}),
497
497
  purgeOperationalState: this.#purgeOperationalState,
498
498
  }, sessionId),
499
499
  this.#purgeAgentGraphState(sessionId),
@@ -20,7 +20,7 @@ import { createHash, randomUUID } from 'node:crypto';
20
20
  import { isDeepResearchSession } from '@maka/core/deep-research';
21
21
  import { SIDE_CONVERSATION_SESSION_LABEL } from '@maka/core/side-conversation';
22
22
  import { isWorkHubCoordinationSessionId, isWorkHubCoordinationSessionTarget, sessionRevisionFamilyId, } from '@maka/core/session';
23
- import { archivedToolResultContainsLinkedChildReferences, archivedToolResultContainsConversationOwnedReferences, cloneConversationRuntimeLedger, collectConversationCopyLinkedChildReferences, collectConversationCopySessionFileRefs, createConversationCopySlice, prepareConversationRuntimeLedgerCopy, } from '@maka/runtime/conversation-copy';
23
+ import { archivedToolResultContainsLinkedChildReferences, archivedToolResultContainsConversationOwnedReferences, cloneConversationRuntimeLedger, collectConversationCopyLinkedChildReferences, collectConversationCopySessionContextRefIds, collectConversationCopySessionFileRefs, createConversationCopySlice, prepareConversationRuntimeLedgerCopy, } from '@maka/runtime/conversation-copy';
24
24
  import { isArchivedToolResultPlaceholder } from '@maka/runtime/context-budget';
25
25
  import { decodeModelProjectionTransition, MODEL_PROJECTION_TRANSITION_EVENT_TYPE, } from '@maka/core/model-projection-transition';
26
26
  import { authenticateInteractiveArtifactStoreWriter, } from '@maka/storage/artifact-stores';
@@ -52,7 +52,7 @@ export class HostSessionRevisionCoordinator {
52
52
  const copies = (await this.#stores.sessionStore.listHeaders()).filter((header) => header.conversationCopy !== undefined);
53
53
  for (const header of copies) {
54
54
  if (header.conversationCopy.state === 'preparing')
55
- await this.#discard(header);
55
+ await this.#discardDuringRecovery(header);
56
56
  }
57
57
  const committed = copies.filter((header) => header.conversationCopy.state === 'committed');
58
58
  const retained = new Set(committed
@@ -85,10 +85,18 @@ export class HostSessionRevisionCoordinator {
85
85
  await this.options.manager.commitRevisionVersion(header.id);
86
86
  }
87
87
  else {
88
- await this.#discard(header);
88
+ await this.#discardDuringRecovery(header);
89
89
  }
90
90
  }
91
91
  }
92
+ async #discardDuringRecovery(header) {
93
+ try {
94
+ await this.#discard(header);
95
+ }
96
+ catch (error) {
97
+ console.error(`[runtime-host] conversation copy cleanup deferred during recovery (${header.id}): ${conversationCopyCommitFailureDiagnostic(error)}`);
98
+ }
99
+ }
92
100
  async #copy(kind, input) {
93
101
  if (isWorkHubCoordinationSessionId(input.targetSessionId)) {
94
102
  return copyFailure('operation_conflict', 'Target Session identity is reserved for WorkHub coordination');
@@ -315,6 +323,28 @@ export class HostSessionRevisionCoordinator {
315
323
  .filter(({ serializedResult }) => archivedToolResultContainsLinkedChildReferences(serializedResult) ||
316
324
  archivedToolResultContainsConversationOwnedReferences(serializedResult, input.sourceSessionId, linkedReferences.references))
317
325
  .map(({ descriptor, serializedResult }) => [descriptor.artifactId, serializedResult]));
326
+ const sourceContextRefIds = collectConversationCopySessionContextRefIds({
327
+ sourceSessionId: input.sourceSessionId,
328
+ messages: slice.messages,
329
+ runtimeEvents: plan.runs.flatMap(({ runtimeEvents }) => runtimeEvents),
330
+ archivedResults: archivePreflight.serializedResults,
331
+ });
332
+ if (sourceContextRefIds.length > 0 && !this.options.contextOffload) {
333
+ throw new Error('Session context copy authority is unavailable');
334
+ }
335
+ const contextCopy = sourceContextRefIds.length === 0
336
+ ? { ok: true, copied: [] }
337
+ : await this.options.contextOffload.copyReferences({
338
+ sourceSessionId: input.sourceSessionId,
339
+ targetSessionId: input.targetSessionId,
340
+ references: sourceContextRefIds.map((sourceRefId) => ({
341
+ sourceRefId,
342
+ targetOwner: { kind: 'read_image_snapshot', ownerId: sourceRefId },
343
+ })),
344
+ });
345
+ if (!contextCopy.ok) {
346
+ throw new Error(`Session context references could not be copied: ${contextCopy.reason}`);
347
+ }
318
348
  const artifactCopy = await this.#artifacts.copyConversationArtifacts({
319
349
  sourceSessionId: input.sourceSessionId,
320
350
  targetSessionId: input.targetSessionId,
@@ -340,6 +370,7 @@ export class HostSessionRevisionCoordinator {
340
370
  targetSessionId: input.targetSessionId,
341
371
  artifactIds: artifactCopy.artifactIds,
342
372
  relativePaths: artifactCopy.relativePaths,
373
+ contextRefs: new Map(contextCopy.copied.map(({ sourceRefId, targetRefId }) => [sourceRefId, targetRefId])),
343
374
  linkedChildren: kind === 'side_conversation'
344
375
  ? {
345
376
  mode: 'snapshot',
@@ -544,6 +575,7 @@ export class HostSessionRevisionCoordinator {
544
575
  await purgeSessionSidecars({
545
576
  artifacts: this.#artifacts,
546
577
  sessionTodo: this.#sessionTodo,
578
+ ...(this.options.contextOffload ? { contextOffload: this.options.contextOffload } : {}),
547
579
  purgeOperationalState: (sessionId) => this.#stores.purgeConversationOperationalState(sessionId),
548
580
  }, header.id);
549
581
  await this.#stores.sessionStore.discardStableConversationCopy(header.id, copy.requestFingerprint);
@@ -16,10 +16,26 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ const CONTEXT_GARBAGE_BATCH_BLOBS = 64;
20
+ async function retireContextSession(contextOffload, sessionId) {
21
+ await contextOffload.retireSession(sessionId);
22
+ for (;;) {
23
+ const collected = await contextOffload.collectGarbage({
24
+ olderThan: Number.MAX_SAFE_INTEGER,
25
+ maxBlobs: CONTEXT_GARBAGE_BATCH_BLOBS,
26
+ maxBytes: Number.MAX_SAFE_INTEGER,
27
+ });
28
+ if (!collected.hasMore)
29
+ return;
30
+ }
31
+ }
19
32
  export async function purgeSessionSidecars(authority, sessionId) {
20
33
  const outcomes = await Promise.allSettled([
21
34
  authority.artifacts.purgeSessionArtifacts(sessionId),
22
35
  authority.sessionTodo.purgeSessionState(sessionId),
36
+ ...(authority.contextOffload
37
+ ? [retireContextSession(authority.contextOffload, sessionId)]
38
+ : []),
23
39
  authority.purgeOperationalState(sessionId),
24
40
  ]);
25
41
  const failures = outcomes.flatMap((outcome) => outcome.status === 'rejected' ? [outcome.reason] : []);
@@ -209,7 +209,11 @@ async function readRangeEdges(input) {
209
209
  if (targetRecords.length > SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES ||
210
210
  targetBytes > SESSION_TRANSCRIPT_RANGE_MAX_BYTES) {
211
211
  if (targetStart === 0) {
212
- throw new RangeError('Session transcript Turn range exceeds its capacity limit');
212
+ return {
213
+ selected: input.selected,
214
+ rangeBoundarySequence: null,
215
+ protectedTurnSequence: null,
216
+ };
213
217
  }
214
218
  reachedFarEdge = true;
215
219
  break;
@@ -246,7 +250,11 @@ async function readRangeEdges(input) {
246
250
  groupBytes > SESSION_TRANSCRIPT_RANGE_MAX_BYTES) {
247
251
  if (groupStart > 0)
248
252
  break;
249
- throw new RangeError('Session transcript Turn range exceeds its capacity limit');
253
+ return {
254
+ selected: input.selected,
255
+ rangeBoundarySequence: null,
256
+ protectedTurnSequence: null,
257
+ };
250
258
  }
251
259
  if (retainedMessages + group.length > SESSION_TRANSCRIPT_RANGE_MAX_MESSAGES ||
252
260
  retainedBytes + groupBytes > SESSION_TRANSCRIPT_RANGE_MAX_BYTES) {
@@ -24,7 +24,7 @@ export function createHostWebFetchService(input) {
24
24
  const createFetchTransport = input.createFetchTransport ?? createProxiedFetchTransport;
25
25
  return {
26
26
  fetch: async ({ url, sessionId, abortSignal }) => {
27
- const resolved = await input.policy.resolveWebFetchExecution();
27
+ const resolved = await input.policy.resolveHostOutboundExecution();
28
28
  if (resolved.kind === 'privacy_mode') {
29
29
  throw new Error('WebFetch is disabled while privacy mode is active.');
30
30
  }