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
@@ -26,27 +26,28 @@ import { HOST_OPERATION_SPECS, operationAllowsRemoteOwner, decodeSessionTurnAcce
26
26
  const ACCESS_FILE_SCHEMA_VERSION = 4;
27
27
  const PRE_CAPABILITY_OWNER_ACCESS_FILE_SCHEMA_VERSION = 3;
28
28
  const ACCESS_FILE_MAX_BYTES = 512 * 1024;
29
- const LEGACY_TRANSCRIPT_QUERY_GRANT = 'session.transcript.query';
30
- const TRANSCRIPT_QUERY_REPLACEMENT_GRANTS = [
31
- 'session.transcript.page',
32
- 'session.transcript.overlay.release',
33
- ];
34
- const TURN_QUERY_GRANT = 'session.turns.query';
35
- const TURN_QUERY_REPLACEMENT_GRANTS = [
36
- TURN_QUERY_GRANT,
37
- 'session.turn_landmarks.query',
38
- ];
39
- // Operations that left the protocol entirely. A previously issued access file
40
- // may still grant them; the grant is released on decode — there is nothing to
41
- // migrate it to — because failing the whole file would keep the Host from
42
- // starting over a capability it could not serve anyway.
43
- const RETIRED_OPERATION_GRANTS = new Set([
29
+ const PERSISTED_GRANT_MIGRATIONS = new Map([
30
+ // The transcript query split into paging and its overlay release.
31
+ [
32
+ 'session.transcript.query',
33
+ {
34
+ kind: 'replace',
35
+ successors: ['session.transcript.page', 'session.transcript.overlay.release'],
36
+ },
37
+ ],
38
+ // The Turn query kept its name and gained a separate landmark query beside it.
39
+ [
40
+ 'session.turns.query',
41
+ { kind: 'replace', successors: ['session.turns.query', 'session.turn_landmarks.query'] },
42
+ ],
43
+ // TaskLedger became SessionTodo; the query carried its authority over.
44
+ ['task.ledger.query', { kind: 'replace', successors: ['session.todo.query'] }],
44
45
  // Retired with the Claude subscription provider, whose client identity the
45
46
  // usage report required.
46
- 'oauth.account.usage.fetch',
47
+ ['oauth.account.usage.fetch', { kind: 'release' }],
47
48
  // Retired with the second execution-inspection contract; no shipped surface
48
- // called execution.inspect.resolve, so a stored grant is released on decode.
49
- 'execution.inspect.resolve',
49
+ // called execution.inspect.resolve.
50
+ ['execution.inspect.resolve', { kind: 'release' }],
50
51
  ]);
51
52
  export const ACCESS_FILE_NAME = 'runtime-host-access.json';
52
53
  export const SESSION_GUEST_OPERATION_GRANTS = Object.freeze([
@@ -62,6 +63,15 @@ export const SESSION_GUEST_OPERATION_GRANTS = Object.freeze([
62
63
  'session.transcript.page',
63
64
  'session.transcript.overlay.release',
64
65
  ]);
66
+ // A Client Capability provider serves exactly this much and nothing else. It
67
+ // sits beside the Session Guest list because both are principal policy that
68
+ // `effectiveOperationGrants` re-applies on every decode: what a principal may
69
+ // hold is decided by the running build, never by what its record happens to say.
70
+ export const CAPABILITY_PROVIDER_OPERATION_GRANTS = Object.freeze([
71
+ 'host.status',
72
+ 'client.capability.replace',
73
+ 'client.capability.unregister',
74
+ ]);
65
75
  export class RuntimeHostAccessInputError extends Error {
66
76
  constructor(message) {
67
77
  super(message);
@@ -93,6 +103,38 @@ export function createAccessCredentialFile(credentials, sessionGrants = [], turn
93
103
  export function issuedAccessGrants(grants) {
94
104
  return validateIssuedGrants([...new Set(['host.status', ...grants])]);
95
105
  }
106
+ // What the running build lets this credential exercise. Derived from the record
107
+ // on every decode and never persisted: a grant the current protocol does not
108
+ // define, or that the current policy for this principal no longer allows, is
109
+ // absent here while staying in the record. Dropping it from the record instead
110
+ // would make an unrelated later write erase it for good (#4420).
111
+ export function effectiveOperationGrants(credential) {
112
+ // A Session Guest holds whatever the guest policy grants now. Its record was
113
+ // never authoritative — issuance writes the policy list wholesale.
114
+ if (credential.principalKind === 'session_guest')
115
+ return SESSION_GUEST_OPERATION_GRANTS;
116
+ const permitted = credential.principalKind === 'capability_provider'
117
+ ? new Set(CAPABILITY_PROVIDER_OPERATION_GRANTS)
118
+ : undefined;
119
+ return Object.freeze(credential.grants.filter((grant) => Object.hasOwn(HOST_OPERATION_SPECS, grant) &&
120
+ operationAllowsRemoteOwner(grant) &&
121
+ (permitted === undefined || permitted.has(grant))));
122
+ }
123
+ // Stored grants this build can neither serve nor account for: absent from the
124
+ // protocol and named by no migration entry. A rename that ships without its
125
+ // entry leaves its old key here, which is what the released forward roll
126
+ // asserts against — the record survives, so the omission is recoverable, but it
127
+ // is still an omission.
128
+ export function unresolvedPersistedGrants(file) {
129
+ const unresolved = new Set();
130
+ for (const credential of file.credentials) {
131
+ for (const grant of credential.grants) {
132
+ if (!Object.hasOwn(HOST_OPERATION_SPECS, grant))
133
+ unresolved.add(grant);
134
+ }
135
+ }
136
+ return Object.freeze([...unresolved].sort());
137
+ }
96
138
  export function assertAccessCredentialFileCapacity(file) {
97
139
  const fullyRevoked = createAccessCredentialFile(file.credentials.map((credential) => credential.status === 'revoked'
98
140
  ? credential
@@ -168,8 +210,39 @@ export async function writeAccessCredentialFile(path, file) {
168
210
  throw error;
169
211
  }
170
212
  }
213
+ // The on-disk shape, stated once. The record's field is `grants` in memory and
214
+ // `operationGrants` on disk, and only what this function names is written — so
215
+ // a field added to the runtime type cannot reach the file by accident, and the
216
+ // key an older build reads keeps its published name.
217
+ function encodeAccessCredentialFile(file) {
218
+ return {
219
+ schemaVersion: file.schemaVersion,
220
+ credentials: file.credentials.map((credential) => ({
221
+ credentialId: credential.credentialId,
222
+ credentialHash: credential.credentialHash,
223
+ principalId: credential.principalId,
224
+ principalKind: credential.principalKind,
225
+ status: credential.status,
226
+ operationGrants: credential.grants,
227
+ canPublishClientCapabilities: credential.canPublishClientCapabilities,
228
+ canUseHostPaths: credential.canUseHostPaths,
229
+ ...(credential.capabilityOwner ? { capabilityOwner: credential.capabilityOwner } : {}),
230
+ createdAt: credential.createdAt,
231
+ ...(credential.bindClientInstanceOnFinalize === true
232
+ ? { bindClientInstanceOnFinalize: true }
233
+ : {}),
234
+ ...(credential.clientInstanceId === undefined
235
+ ? {}
236
+ : { clientInstanceId: credential.clientInstanceId }),
237
+ ...(credential.expiresAt === undefined ? {} : { expiresAt: credential.expiresAt }),
238
+ ...(credential.revokedAt === undefined ? {} : { revokedAt: credential.revokedAt }),
239
+ })),
240
+ sessionGrants: file.sessionGrants,
241
+ turnAccessRequests: file.turnAccessRequests,
242
+ };
243
+ }
171
244
  function serializeAccessCredentialFile(file) {
172
- const contents = `${JSON.stringify(file, null, 2)}\n`;
245
+ const contents = `${JSON.stringify(encodeAccessCredentialFile(file), null, 2)}\n`;
173
246
  if (Buffer.byteLength(contents) > ACCESS_FILE_MAX_BYTES) {
174
247
  throw new RuntimeHostAccessCapacityError();
175
248
  }
@@ -251,19 +324,12 @@ function decodeStoredCredential(value) {
251
324
  }
252
325
  if (!Array.isArray(value.operationGrants))
253
326
  throw new Error('Invalid operationGrants');
254
- const storedOperationGrants = value.operationGrants.map((grant) => requireStoredString(grant, 'operationGrant'));
255
- if (new Set(storedOperationGrants).size !== storedOperationGrants.length) {
327
+ const storedGrants = value.operationGrants.map((grant) => requireStoredString(grant, 'operationGrant'));
328
+ if (new Set(storedGrants).size !== storedGrants.length) {
256
329
  throw new Error('Duplicate Runtime Host access operation grant');
257
330
  }
258
- const migratedOperationGrants = validateStoredGrants(migrateStoredOperationGrants(storedOperationGrants));
259
- if (principalKind === 'session_guest' &&
260
- migratedOperationGrants.some((grant) => !SESSION_GUEST_OPERATION_GRANTS.includes(grant))) {
261
- throw new Error('Session Guest credential has an invalid operation grant');
262
- }
263
- const operationGrants = Object.freeze(principalKind === 'session_guest'
264
- ? [...SESSION_GUEST_OPERATION_GRANTS]
265
- : migratedOperationGrants.filter(operationAllowsRemoteOwner));
266
- if (!operationGrants.includes('host.status')) {
331
+ const grants = migratePersistedGrants(storedGrants);
332
+ if (!grants.includes('host.status')) {
267
333
  throw new Error('Runtime Host access credential lacks its liveness grant');
268
334
  }
269
335
  if (typeof value.canPublishClientCapabilities !== 'boolean' ||
@@ -310,7 +376,7 @@ function decodeStoredCredential(value) {
310
376
  principalId,
311
377
  principalKind,
312
378
  status: value.status,
313
- operationGrants,
379
+ grants,
314
380
  canPublishClientCapabilities: value.canPublishClientCapabilities,
315
381
  canUseHostPaths: value.canUseHostPaths,
316
382
  ...(capabilityOwner ? { capabilityOwner } : {}),
@@ -360,36 +426,42 @@ function decodeCapabilityOwner(value) {
360
426
  }
361
427
  return Object.freeze({ principalId, clientInstanceId });
362
428
  }
363
- function migrateStoredOperationGrants(grants) {
429
+ // Rewrites the record, and only where a migration entry says to. A stored grant
430
+ // naming no entry is carried through unchanged, whether or not this build knows
431
+ // it: an older build must not erase a key a newer one wrote, and a newer build
432
+ // must not erase a key whose migration entry was forgotten. Both erasures are
433
+ // permanent, because the next unrelated mutation rewrites the whole file.
434
+ function migratePersistedGrants(grants) {
364
435
  const migrated = [];
365
436
  const seen = new Set();
366
437
  for (const stored of grants) {
367
- const replacements = RETIRED_OPERATION_GRANTS.has(stored)
368
- ? []
369
- : stored === LEGACY_TRANSCRIPT_QUERY_GRANT
370
- ? TRANSCRIPT_QUERY_REPLACEMENT_GRANTS
371
- : stored === TURN_QUERY_GRANT
372
- ? TURN_QUERY_REPLACEMENT_GRANTS
373
- : [stored];
374
- for (const replacement of replacements) {
375
- if (seen.has(replacement))
438
+ const migration = PERSISTED_GRANT_MIGRATIONS.get(stored);
439
+ const successors = migration
440
+ ? migration.kind === 'replace'
441
+ ? migration.successors
442
+ : []
443
+ : [stored];
444
+ for (const successor of successors) {
445
+ if (seen.has(successor))
376
446
  continue;
377
- seen.add(replacement);
378
- migrated.push(replacement);
447
+ seen.add(successor);
448
+ migrated.push(successor);
379
449
  }
380
450
  }
381
- return migrated;
451
+ return Object.freeze(migrated);
382
452
  }
383
- function validateStoredGrants(grants) {
453
+ // The issuance gate. Nothing the current protocol does not define may enter the
454
+ // record through this Host; what a predecessor already wrote is the decoder's
455
+ // problem, not this one's.
456
+ function assertCurrentOperations(grants) {
384
457
  for (const grant of grants) {
385
458
  if (!Object.hasOwn(HOST_OPERATION_SPECS, grant)) {
386
459
  throw new RuntimeHostAccessInputError(`Unknown Runtime Host operation grant: ${grant}`);
387
460
  }
388
461
  }
389
- return Object.freeze([...grants]);
390
462
  }
391
463
  function validateIssuedGrants(grants) {
392
- validateStoredGrants(grants);
464
+ assertCurrentOperations(grants);
393
465
  for (const grant of grants) {
394
466
  if (!operationAllowsRemoteOwner(grant)) {
395
467
  throw new RuntimeHostAccessInputError(`Runtime Host operation ${grant} is local-owner only`);
@@ -147,8 +147,7 @@ function classifyAgentGraphOutcome(snapshot) {
147
147
  if (snapshot.status === 'cancelled')
148
148
  return { kind: 'aborted', turnId: snapshot.turnId };
149
149
  if (snapshot.status === 'failed') {
150
- if (snapshot.failureClass === 'context_overflow' ||
151
- snapshot.failureClass === 'context_budget_exhausted') {
150
+ if (snapshot.failureClass === 'context_overflow') {
152
151
  return {
153
152
  kind: 'context_overflow',
154
153
  turnId: snapshot.turnId,
@@ -19,8 +19,14 @@
19
19
  import { randomUUID } from 'node:crypto';
20
20
  import { readFile, rename, rm, writeFile } from 'node:fs/promises';
21
21
  import { join } from 'node:path';
22
- import { OPENCODE_FREE_DEFAULT_ENABLED_MODELS, OPENCODE_FREE_DEFAULT_MODEL, } from '@maka/core/llm-connections';
22
+ import { OPENCODE_FREE_DEFAULT_MODEL, defaultEnabledModelIdsWhenOmitted, } from '@maka/core/llm-connections';
23
23
  const JOURNAL_FILE = '.runtime-host-bootstrap.json';
24
+ /**
25
+ * What the seeded OpenCode Free connection starts with — the provider's own
26
+ * declaration of the models a fresh connection to it enables, so the seed and
27
+ * a hand-added connection cannot drift apart.
28
+ */
29
+ const OPENCODE_FREE_SEED_MODEL_IDS = defaultEnabledModelIdsWhenOmitted('opencode-free') ?? [];
24
30
  /** Establishes a usable first target before Runtime Host accepts clients. */
25
31
  export async function ensureBootstrapRuntimePolicy(input) {
26
32
  const journalPath = join(input.workspaceRoot, JOURNAL_FILE);
@@ -35,7 +41,7 @@ export async function ensureBootstrapRuntimePolicy(input) {
35
41
  slug: 'opencode-free',
36
42
  providerType: 'opencode-free',
37
43
  legacyEnabledModelIds: LEGACY_OPENCODE_FREE_SEEDS,
38
- enabledModelIds: OPENCODE_FREE_DEFAULT_ENABLED_MODELS,
44
+ enabledModelIds: OPENCODE_FREE_SEED_MODEL_IDS,
39
45
  defaultModelId: OPENCODE_FREE_DEFAULT_MODEL,
40
46
  retiredModelIds: retiredOpencodeFreeModelIds(),
41
47
  });
@@ -82,7 +88,7 @@ function bootstrapSeeds(environment) {
82
88
  slug: 'opencode-free',
83
89
  name: 'OpenCode Free',
84
90
  providerType: 'opencode-free',
85
- enabledModelIds: OPENCODE_FREE_DEFAULT_ENABLED_MODELS,
91
+ enabledModelIds: OPENCODE_FREE_SEED_MODEL_IDS,
86
92
  },
87
93
  ];
88
94
  const deepseek = environment.DEEPSEEK_API_KEY?.trim();
@@ -163,7 +169,7 @@ const LEGACY_OPENCODE_FREE_SEEDS = [
163
169
  ['nemotron-3-ultra-free', 'mimo-v2.5-free', 'deepseek-v4-flash-free'],
164
170
  ];
165
171
  function retiredOpencodeFreeModelIds() {
166
- const current = new Set(OPENCODE_FREE_DEFAULT_ENABLED_MODELS);
172
+ const current = new Set(OPENCODE_FREE_SEED_MODEL_IDS);
167
173
  return [...new Set(LEGACY_OPENCODE_FREE_SEEDS.flat())].filter((id) => !current.has(id));
168
174
  }
169
175
  async function removeFailedBootstrapConnection(stores, connection) {
@@ -16,7 +16,6 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { isContextBudgetExhaustedDetail, } from '@maka/core/events';
20
19
  import { truncateUtf8 } from '@maka/core/diagnostic-log';
21
20
  import { redactSecrets } from '@maka/core/redaction';
22
21
  import { classifyTerminalRuntimeLedger } from '@maka/runtime/terminal-run-commit';
@@ -53,7 +52,6 @@ export async function readCanonicalTurnSnapshot(stores, identity, knownRun) {
53
52
  const failureMessage = fact.terminalEvent.content?.kind === 'error'
54
53
  ? truncateUtf8(redactSecrets(fact.terminalEvent.content.message), TURN_FAILURE_MESSAGE_MAX_BYTES, '…')
55
54
  : undefined;
56
- const contextBudgetExhaustedDetail = readContextBudgetExhaustedDetail(fact.terminalEvent.actions?.stateDelta?.contextBudgetExhaustedDetail);
57
55
  return {
58
56
  sessionId,
59
57
  turnId,
@@ -62,7 +60,6 @@ export async function readCanonicalTurnSnapshot(stores, identity, knownRun) {
62
60
  terminalEventId: fact.terminalEvent.id,
63
61
  failureClass: fact.failureClass,
64
62
  ...(failureMessage ? { failureMessage } : {}),
65
- ...(contextBudgetExhaustedDetail ? { contextBudgetExhaustedDetail } : {}),
66
63
  };
67
64
  }
68
65
  if (!fact.abortSource)
@@ -87,9 +84,6 @@ export async function readCanonicalTurnSnapshot(stores, identity, knownRun) {
87
84
  }
88
85
  return { sessionId, turnId, runId, status: run.status };
89
86
  }
90
- function readContextBudgetExhaustedDetail(value) {
91
- return isContextBudgetExhaustedDetail(value) ? value : undefined;
92
- }
93
87
  function readContextCompactionOutcome(value) {
94
88
  if (!value || typeof value !== 'object')
95
89
  return undefined;
@@ -111,9 +105,6 @@ export function worstCaseFailedTurnSnapshot(identity) {
111
105
  terminalEventId: 'x'.repeat(128),
112
106
  failureClass: '\0'.repeat(128),
113
107
  failureMessage: '\0'.repeat(TURN_FAILURE_MESSAGE_MAX_BYTES),
114
- // Keep capacity preflight conservative for every protocol-valid failure
115
- // detail, including the longest malformed-summary diagnostic.
116
- contextBudgetExhaustedDetail: 'malformed_summary_too_small_for_fold',
117
108
  };
118
109
  }
119
110
  async function readRunIfPresent(stores, sessionId, runId) {
@@ -18,11 +18,24 @@
18
18
  */
19
19
  import { createHash } from 'node:crypto';
20
20
  import { AsyncLocalStorage } from 'node:async_hooks';
21
- import { buildMcpTools, mcpProxyToolName } from '@maka/runtime/mcp-tools';
21
+ import { buildMcpTools, mcpProxyToolName, } from '@maka/runtime/mcp-tools';
22
+ import { clientCapabilityScopeIdentity, } from '@maka/core/client-capability-grant';
22
23
  import { ClientCapabilityInvocationBroker, ClientCapabilityInvocationError, } from './client-capability-invocation-broker.js';
24
+ import { clientCapabilityProviderId } from './client-capability-provider-id.js';
23
25
  // Leave the Host deadline outside the provider's bounded action deadline so an
24
26
  // accepted call can return its real terminal result instead of outcome_unknown.
25
27
  const DEFAULT_CALL_TIMEOUT_MS = 150_000;
28
+ const DESKTOP_BROWSER_SERVER_ID = 'desktop_browser';
29
+ const DESKTOP_SETTINGS_SERVER_ID = 'desktop_settings';
30
+ const DESKTOP_BROWSER_TOOLS = new Set([
31
+ 'browser_navigate',
32
+ 'browser_snapshot',
33
+ 'browser_click',
34
+ 'browser_type',
35
+ 'browser_wait',
36
+ 'browser_extract',
37
+ ]);
38
+ const DESKTOP_SETTINGS_TOOLS = new Set(['MakaClientSettingsGet', 'MakaClientSettingsUpdate']);
26
39
  export { ClientCapabilityInvocationError };
27
40
  /**
28
41
  * Host-owned registry, selection authority, and reverse-call lifecycle for
@@ -35,9 +48,12 @@ export class HostClientCapabilityCoordinator {
35
48
  };
36
49
  #activation;
37
50
  #onModelToolsChanged;
51
+ #interactions;
52
+ #grants;
38
53
  #providers = new Map();
39
54
  #connections = new Map();
40
55
  #sessions = new Map();
56
+ #pendingApprovals = new Map();
41
57
  #previewSessions = new AsyncLocalStorage();
42
58
  #pendingConnectionReleases = new Set();
43
59
  #invocations;
@@ -46,6 +62,8 @@ export class HostClientCapabilityCoordinator {
46
62
  constructor(options) {
47
63
  this.#activation = options.activation;
48
64
  this.#onModelToolsChanged = options.onModelToolsChanged;
65
+ this.#interactions = options.interactions;
66
+ this.#grants = options.grants;
49
67
  this.#invocations = new ClientCapabilityInvocationBroker({
50
68
  senderFor: (connectionId) => {
51
69
  const connection = this.#connections.get(connectionId);
@@ -359,11 +377,14 @@ export class HostClientCapabilityCoordinator {
359
377
  ...buildMcpTools(this.#snapshotProvider(state?.initiatingProviderId, interactive), {
360
378
  callTimeoutMs: DEFAULT_CALL_TIMEOUT_MS,
361
379
  categoryHint: 'client_capability',
380
+ hostAdmission: 'client_capability',
362
381
  recoveryMode: 'outcome_unknown',
382
+ executionLocation: 'remote',
363
383
  }),
364
384
  ...buildMcpTools(this.#snapshotProvider(state?.initiatingProviderId, trusted), {
365
385
  callTimeoutMs: DEFAULT_CALL_TIMEOUT_MS,
366
386
  categoryHint: 'custom_tool',
387
+ hostAdmission: 'client_capability',
367
388
  recoveryMode: 'outcome_unknown',
368
389
  executionLocation: 'remote',
369
390
  activityKindForDescriptor: (descriptor) => trustedClientToolActivityKind(descriptor),
@@ -584,7 +605,7 @@ export class HostClientCapabilityCoordinator {
584
605
  }
585
606
  let registration;
586
607
  try {
587
- if (provider.trustedProvider &&
608
+ if (provider.principalKind === 'capability_provider' &&
588
609
  (input.services?.length ||
589
610
  input.offers.some((offer) => offer.affinity !== 'session' || offer.hostPathAccess !== 'none'))) {
590
611
  throw new Error('A trusted capability provider may publish only path-independent session capabilities');
@@ -686,28 +707,114 @@ export class HostClientCapabilityCoordinator {
686
707
  revision: this.#revision,
687
708
  tools: Object.freeze(boundTools),
688
709
  });
710
+ const resolveBinding = (binding) => {
711
+ const selectedBinding = bindings.get(binding);
712
+ if (!selectedBinding) {
713
+ throw new ClientCapabilityInvocationError('capability_lost', 'Client Capability tool is not part of the frozen offer');
714
+ }
715
+ const { serverId, name: toolName } = selectedBinding.tool.descriptor;
716
+ const dynamicBinding = selectedBinding.registration
717
+ ? {
718
+ registration: selectedBinding.registration,
719
+ tool: selectedBinding.tool,
720
+ }
721
+ : this.#selectCallBinding(selectedBinding.contractId, initiatingProviderId, toolIdentity(serverId, toolName));
722
+ return { selectedBinding, dynamicBinding };
723
+ };
689
724
  return {
690
725
  toolSnapshot: () => snapshot,
691
- callTool: (binding, args, options) => {
692
- const selectedBinding = bindings.get(binding);
693
- if (!selectedBinding) {
694
- return Promise.reject(new ClientCapabilityInvocationError('capability_lost', 'Client Capability tool is not part of the frozen offer'));
695
- }
696
- const { serverId, name: toolName } = selectedBinding.tool.descriptor;
697
- const dynamicBinding = selectedBinding.registration
698
- ? {
699
- registration: selectedBinding.registration,
700
- tool: selectedBinding.tool,
726
+ prepareTool: async (binding, args, options) => {
727
+ const { selectedBinding, dynamicBinding } = resolveBinding(binding);
728
+ const prepared = this.#invocations.prepare(dynamicBinding.registration, dynamicBinding.tool, args, options.context, options.signal, options.timeoutMs ?? DEFAULT_CALL_TIMEOUT_MS);
729
+ try {
730
+ const evidence = await prepared.waitUntilAccepted();
731
+ const boundary = options.context.executionBoundary;
732
+ if (!boundary)
733
+ throw new Error('Client Capability execution boundary is unavailable');
734
+ if (boundary.kind !== 'bypass') {
735
+ if (options.context.permissionMode !== 'ask' || !options.context.runId) {
736
+ throw new Error('Client Capability is unavailable in the current permission mode');
737
+ }
738
+ const target = managedClientCapabilityGrantTarget(selectedBinding.contractId, dynamicBinding.registration, dynamicBinding.tool, evidence);
739
+ if (!target) {
740
+ return {
741
+ execute: ({ emitProgress } = {}) => prepared.admit(emitProgress),
742
+ cancel: () => prepared.cancel(),
743
+ };
744
+ }
745
+ const key = { sessionId: options.context.sessionId, ...target };
746
+ if (!(await this.#grants.readClientCapabilitySessionGrant(key))) {
747
+ const decision = await this.#requestApprovalOnce({
748
+ ...key,
749
+ turnId: options.context.turnId,
750
+ runId: options.context.runId,
751
+ toolCallId: options.context.toolCallId,
752
+ providerSignal: prepared.providerSignal,
753
+ callerSignal: options.signal,
754
+ });
755
+ if (decision !== 'allow')
756
+ throw new Error('Client Capability request was denied');
757
+ if (!(await this.#grants.readClientCapabilitySessionGrant(key))) {
758
+ throw new Error('Client Capability approval did not publish its Session Grant');
759
+ }
760
+ }
701
761
  }
702
- : this.#selectCallBinding(selectedBinding.contractId, initiatingProviderId, toolIdentity(serverId, toolName));
762
+ return {
763
+ execute: ({ emitProgress } = {}) => prepared.admit(emitProgress),
764
+ cancel: () => prepared.cancel(),
765
+ };
766
+ }
767
+ catch (error) {
768
+ prepared.cancel();
769
+ throw error;
770
+ }
771
+ },
772
+ callTool: (binding, args, options) => {
773
+ const { dynamicBinding } = resolveBinding(binding);
703
774
  return this.#invocations.invoke(dynamicBinding.registration, dynamicBinding.tool, args, options.context, options.signal, options.timeoutMs ?? DEFAULT_CALL_TIMEOUT_MS, options.emitProgress);
704
775
  },
705
776
  };
706
777
  }
778
+ #requestApprovalOnce(input) {
779
+ const target = {
780
+ providerId: input.providerId,
781
+ contractId: input.contractId,
782
+ serverId: input.serverId,
783
+ toolName: input.toolName,
784
+ capability: input.capability,
785
+ scope: input.scope,
786
+ };
787
+ const key = [
788
+ input.sessionId,
789
+ target.providerId,
790
+ target.contractId,
791
+ target.capability,
792
+ clientCapabilityScopeIdentity(target.scope),
793
+ ].join('\0');
794
+ const existing = this.#pendingApprovals.get(key);
795
+ if (existing)
796
+ return waitForClientCapabilityApproval(existing, input.callerSignal);
797
+ const pending = this.#interactions
798
+ .requestClientCapabilityApproval({
799
+ sessionId: input.sessionId,
800
+ turnId: input.turnId,
801
+ runId: input.runId,
802
+ toolCallId: input.toolCallId,
803
+ target,
804
+ providerSignal: input.providerSignal,
805
+ ...(input.callerSignal ? { callerSignal: input.callerSignal } : {}),
806
+ })
807
+ .finally(() => {
808
+ if (this.#pendingApprovals.get(key) === pending)
809
+ this.#pendingApprovals.delete(key);
810
+ });
811
+ this.#pendingApprovals.set(key, pending);
812
+ return pending;
813
+ }
707
814
  #provider(identity) {
708
- const providerId = clientProviderId(identity.principalId, identity.clientInstanceId);
709
- const trustedProvider = identity.principalKind === 'capability_provider';
710
- if (identity.capabilityOwner && !trustedProvider) {
815
+ const providerId = clientCapabilityProviderId(identity);
816
+ const trustedProvider = identity.principalKind === 'local_owner' || identity.principalKind === 'capability_provider';
817
+ if (identity.capabilityOwner && identity.principalKind !== 'capability_provider') {
711
818
  throw new Error('Only a capability provider may declare a Client Capability owner');
712
819
  }
713
820
  let provider = this.#providers.get(providerId);
@@ -957,8 +1064,45 @@ function freezeRegistration(providerId, connectionId, input, trustedProvider) {
957
1064
  snapshotRefs: 0,
958
1065
  };
959
1066
  }
960
- function clientProviderId(principalId, clientInstanceId) {
961
- return `${principalId}\0${clientInstanceId}`;
1067
+ function managedClientCapabilityGrantTarget(contractId, registration, tool, evidence) {
1068
+ const { serverId, name: toolName } = tool.descriptor;
1069
+ if (!registration.trustedProvider) {
1070
+ throw new Error('Managed Client Capability requires a trusted Desktop provider');
1071
+ }
1072
+ if (tool.offerId === DESKTOP_SETTINGS_SERVER_ID &&
1073
+ serverId === DESKTOP_SETTINGS_SERVER_ID &&
1074
+ DESKTOP_SETTINGS_TOOLS.has(toolName)) {
1075
+ if (evidence.kind !== 'none') {
1076
+ throw new Error('Desktop Settings admission does not accept scope evidence');
1077
+ }
1078
+ return undefined;
1079
+ }
1080
+ if (tool.offerId !== DESKTOP_BROWSER_SERVER_ID ||
1081
+ serverId !== DESKTOP_BROWSER_SERVER_ID ||
1082
+ !DESKTOP_BROWSER_TOOLS.has(toolName)) {
1083
+ throw new Error(`Client Capability has no managed admission policy: ${serverId}/${toolName}`);
1084
+ }
1085
+ if (evidence.kind !== 'browser_url') {
1086
+ throw new Error('Desktop Browser admission requires URL evidence');
1087
+ }
1088
+ let url;
1089
+ try {
1090
+ url = new URL(evidence.url);
1091
+ }
1092
+ catch {
1093
+ throw new Error('Desktop Browser admission URL is invalid');
1094
+ }
1095
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
1096
+ throw new Error('Desktop Browser admission requires an HTTP origin');
1097
+ }
1098
+ return Object.freeze({
1099
+ providerId: registration.providerId,
1100
+ contractId,
1101
+ serverId,
1102
+ toolName,
1103
+ capability: 'browser',
1104
+ scope: Object.freeze({ kind: 'browser_origin', origin: url.origin }),
1105
+ });
962
1106
  }
963
1107
  function serviceContract(serviceId, version) {
964
1108
  return `${serviceId}\0${version}`;
@@ -1040,6 +1184,36 @@ function clientCapabilityOwnerIdentitiesEqual(left, right) {
1040
1184
  left.principalId === right.principalId &&
1041
1185
  left.clientInstanceId === right.clientInstanceId));
1042
1186
  }
1187
+ function waitForClientCapabilityApproval(approval, callerSignal) {
1188
+ if (!callerSignal)
1189
+ return approval;
1190
+ if (callerSignal.aborted) {
1191
+ return Promise.reject(clientCapabilityCallerAbortError(callerSignal));
1192
+ }
1193
+ return new Promise((resolve, reject) => {
1194
+ const cleanup = () => callerSignal.removeEventListener('abort', onAbort);
1195
+ const onAbort = () => {
1196
+ cleanup();
1197
+ reject(clientCapabilityCallerAbortError(callerSignal));
1198
+ };
1199
+ callerSignal.addEventListener('abort', onAbort, { once: true });
1200
+ void approval.then((decision) => {
1201
+ cleanup();
1202
+ resolve(decision);
1203
+ }, (error) => {
1204
+ cleanup();
1205
+ reject(error);
1206
+ });
1207
+ });
1208
+ }
1209
+ function clientCapabilityCallerAbortError(signal) {
1210
+ const reason = signal.reason;
1211
+ if (reason instanceof Error)
1212
+ return reason;
1213
+ return new Error(typeof reason === 'string' ? reason : 'Client Capability caller cancelled', {
1214
+ ...(reason === undefined ? {} : { cause: reason }),
1215
+ });
1216
+ }
1043
1217
  function canonicalJson(value) {
1044
1218
  if (value === null || typeof value === 'boolean' || typeof value === 'number') {
1045
1219
  return JSON.stringify(value);