maka-agent 0.2.0-dev.15.20260902 → 0.2.0-dev.16.20260903

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 (160) hide show
  1. package/dist/cli-core.js +0 -1
  2. package/dist/pi-transcript.js +48 -0
  3. package/dist/pi-tui-form-interaction.js +497 -0
  4. package/dist/pi-tui-pickers.js +256 -55
  5. package/dist/pi-tui-runner.js +215 -12
  6. package/dist/runtime-host-cli.js +17 -42
  7. package/dist/runtime-host-lifecycle-transaction.js +31 -13
  8. package/dist/runtime-host-managed-lifecycle-manager.js +1 -1
  9. package/dist/runtime-host-onboarding.js +3 -1
  10. package/dist/runtime-host-openrc-service.js +469 -0
  11. package/dist/runtime-host-run-command.js +6 -2
  12. package/dist/runtime-host-service-command.js +3 -3
  13. package/dist/runtime-host-service-management-command.js +43 -15
  14. package/dist/runtime-host-session-channel.js +3 -0
  15. package/dist/runtime-host-session-driver.js +21 -6
  16. package/dist/runtime-host-setup-command.js +30 -31
  17. package/dist/tui-context-refresh.js +103 -0
  18. package/dist/tui-copy-catalog.js +73 -0
  19. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  20. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  21. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  22. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  23. package/node_modules/@maka/core/dist/chat-model-choice.js +4 -0
  24. package/node_modules/@maka/core/dist/computer-use.js +27 -92
  25. package/node_modules/@maka/core/dist/interaction.js +577 -3
  26. package/node_modules/@maka/core/dist/llm-connections.js +4 -0
  27. package/node_modules/@maka/core/dist/local-memory.js +2 -2
  28. package/node_modules/@maka/core/dist/model-call-usage-projection.js +3 -0
  29. package/node_modules/@maka/core/dist/model-metadata.js +26 -7
  30. package/node_modules/@maka/core/dist/model-thinking.js +17 -0
  31. package/node_modules/@maka/core/dist/provider-registry.js +1 -0
  32. package/node_modules/@maka/core/dist/runtime-event.js +23 -1
  33. package/node_modules/@maka/core/dist/scheduled-task.js +4 -0
  34. package/node_modules/@maka/core/dist/session.js +95 -2
  35. package/node_modules/@maka/core/dist/text-sanitize.js +19 -0
  36. package/node_modules/@maka/core/dist/usage-ledger-merge.js +3 -0
  37. package/node_modules/@maka/core/dist/usage-record-schema.js +11 -5
  38. package/node_modules/@maka/core/dist/workhub-creation-intent.js +75 -9
  39. package/node_modules/@maka/core/dist/workhub-session-resolver.js +50 -0
  40. package/node_modules/@maka/core/package.json +2 -0
  41. package/node_modules/@maka/eval/dist/harbor-external-subject.js +2 -1
  42. package/node_modules/@maka/eval/dist/harness-executor.js +3 -2
  43. package/node_modules/@maka/eval/dist/install-preflight.js +39 -10
  44. package/node_modules/@maka/eval/dist/process-termination.js +83 -0
  45. package/node_modules/@maka/mcp/dist/sep-2243.js +3 -3
  46. package/node_modules/@maka/runtime/dist/agent-run.js +6 -3
  47. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +332 -118
  48. package/node_modules/@maka/runtime/dist/ai-sdk-compaction-contract.js +6 -1
  49. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +171 -341
  50. package/node_modules/@maka/runtime/dist/bots/telegram-bridge.js +3 -26
  51. package/node_modules/@maka/runtime/dist/bundled-skill-catalog.generated.js +1 -1
  52. package/node_modules/@maka/runtime/dist/computer-use-codec.js +1 -141
  53. package/node_modules/@maka/runtime/dist/computer-use-tools.js +23 -105
  54. package/node_modules/@maka/runtime/dist/context-budget-policy.js +20 -26
  55. package/node_modules/@maka/runtime/dist/context-budget.js +18 -20
  56. package/node_modules/@maka/runtime/dist/conversation-copy.js +23 -19
  57. package/node_modules/@maka/runtime/dist/cua-frame-state.js +1 -69
  58. package/node_modules/@maka/runtime/dist/github-copilot-oauth-enrollment.js +267 -0
  59. package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +6 -9
  60. package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +67 -23
  61. package/node_modules/@maka/runtime/dist/history-compact-summary-validation.js +11 -18
  62. package/node_modules/@maka/runtime/dist/history-compaction.js +66 -73
  63. package/node_modules/@maka/runtime/dist/interaction-authority.js +69 -0
  64. package/node_modules/@maka/runtime/dist/mcp-tools.js +13 -1
  65. package/node_modules/@maka/runtime/dist/memory-extraction.js +11 -11
  66. package/node_modules/@maka/runtime/dist/model-adapter.js +24 -6
  67. package/node_modules/@maka/runtime/dist/model-factory.js +14 -5
  68. package/node_modules/@maka/runtime/dist/oauth-provider-contracts.js +28 -1
  69. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +7 -6
  70. package/node_modules/@maka/runtime/dist/opencode-session-header.js +29 -0
  71. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +11 -1
  72. package/node_modules/@maka/runtime/dist/runtime-kernel.js +12 -11
  73. package/node_modules/@maka/runtime/dist/runtime-read-model.js +51 -13
  74. package/node_modules/@maka/runtime/dist/scheduled-task-tools.js +3 -0
  75. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +26 -0
  76. package/node_modules/@maka/runtime/dist/session-manager.js +1 -0
  77. package/node_modules/@maka/runtime/dist/session-projection-helpers.js +16 -1
  78. package/node_modules/@maka/runtime/dist/stream-graph-projection.js +6 -0
  79. package/node_modules/@maka/runtime/dist/stream-graph-read-model.js +5 -0
  80. package/node_modules/@maka/runtime/dist/stream-usage-fallback-fetch.js +74 -0
  81. package/node_modules/@maka/runtime/dist/subscription-credentials.js +51 -4
  82. package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +47 -3
  83. package/node_modules/@maka/runtime/dist/system-prompt/main-session-prompt.js +20 -1
  84. package/node_modules/@maka/runtime/dist/test-connection.js +18 -11
  85. package/node_modules/@maka/runtime/dist/tool-runtime.js +183 -0
  86. package/node_modules/@maka/runtime/package.json +1 -0
  87. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +14 -0
  88. package/node_modules/@maka/runtime-host/dist/client/client-capability-channel.js +84 -1
  89. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +68 -51
  90. package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
  91. package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +8 -5
  92. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +342 -36
  93. package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +60 -4
  94. package/node_modules/@maka/runtime-host/dist/peer-mesh/index.js +3 -3
  95. package/node_modules/@maka/runtime-host/dist/peer-mesh/limits.js +1 -1
  96. package/node_modules/@maka/runtime-host/dist/peer-mesh/model.js +48 -60
  97. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +847 -431
  98. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +33 -74
  99. package/node_modules/@maka/runtime-host/dist/peer-mesh/store.js +82 -69
  100. package/node_modules/@maka/runtime-host/dist/peer-reachability/index.js +21 -0
  101. package/node_modules/@maka/runtime-host/dist/peer-reachability/model.js +202 -0
  102. package/node_modules/@maka/runtime-host/dist/peer-reachability/owner.js +119 -0
  103. package/node_modules/@maka/runtime-host/dist/peer-reachability/publisher.js +245 -0
  104. package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +4 -1
  105. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +68 -0
  106. package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +15 -8
  107. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +7 -23
  108. package/node_modules/@maka/runtime-host/dist/protocol/index.js +47 -1
  109. package/node_modules/@maka/runtime-host/dist/protocol/oauth.js +25 -1
  110. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  111. package/node_modules/@maka/runtime-host/dist/protocol/peer-mesh.js +14 -31
  112. package/node_modules/@maka/runtime-host/dist/protocol/scheduled-task.js +19 -6
  113. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +36 -1
  114. package/node_modules/@maka/runtime-host/dist/protocol/session-revision.js +11 -2
  115. package/node_modules/@maka/runtime-host/dist/protocol/usage-pricing.js +16 -2
  116. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +51 -2
  117. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +35 -2
  118. package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
  119. package/node_modules/@maka/runtime-host/dist/server/client-capability-coordinator.js +12 -10
  120. package/node_modules/@maka/runtime-host/dist/server/client-capability-invocation-broker.js +163 -30
  121. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +38 -14
  122. package/node_modules/@maka/runtime-host/dist/server/daily-review-coordinator.js +45 -22
  123. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +78 -20
  124. package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +4 -2
  125. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +2 -1
  126. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +49 -28
  127. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +3 -6
  128. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +130 -27
  129. package/node_modules/@maka/runtime-host/dist/server/interaction-projection.js +30 -1
  130. package/node_modules/@maka/runtime-host/dist/server/listener-set.js +2 -4
  131. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +16 -3
  132. package/node_modules/@maka/runtime-host/dist/server/oauth-coordinator.js +66 -3
  133. package/node_modules/@maka/runtime-host/dist/server/oauth-execution-authority.js +20 -3
  134. package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +8 -21
  135. package/node_modules/@maka/runtime-host/dist/server/peer-mesh-authority.js +1 -1
  136. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +6 -3
  137. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +72 -12
  138. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +48 -18
  139. package/node_modules/@maka/runtime-host/dist/server/session-turn-access-request-coordinator.js +43 -26
  140. package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +15 -1
  141. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +229 -4
  142. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +146 -8
  143. package/node_modules/@maka/runtime-host/dist/transport/peer-native.js +32 -6
  144. package/node_modules/@maka/runtime-host/package.json +1 -0
  145. package/node_modules/@maka/storage/dist/agent-run-store.js +18 -5
  146. package/node_modules/@maka/storage/dist/codex-session-adapter.js +14 -0
  147. package/node_modules/@maka/storage/dist/execution-stores.js +5 -0
  148. package/node_modules/@maka/storage/dist/interaction-store.js +13 -1
  149. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +9 -3
  150. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +49 -19
  151. package/node_modules/@maka/storage/dist/runtime-policy/oauth-login-receipt-document.js +3 -1
  152. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +13 -5
  153. package/node_modules/@maka/storage/dist/session-copy-cleanup.js +4 -2
  154. package/node_modules/@maka/storage/dist/session-store.js +39 -6
  155. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +16 -9
  156. package/node_modules/@maka/storage/dist/sqlite-session-metadata-schema.js +30 -3
  157. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +117 -0
  158. package/node_modules/@maka/storage/dist/sqlite-usage-store.js +29 -6
  159. package/node_modules/@maka/storage/dist/usage-stores.js +3 -1
  160. package/package.json +1 -1
@@ -24,7 +24,7 @@ export const OAUTH_PRESENTATION_SERVICE_ID = 'oauth_presentation';
24
24
  export const OAUTH_PRESENTATION_SERVICE_VERSION = '1';
25
25
  export const OAUTH_PRESENTATION_URL_MAX_LENGTH = 8_192;
26
26
  export const OAUTH_PRESENTATION_STATE_HINT_MAX_LENGTH = 1_024;
27
- export const OAUTH_LOGIN_PROVIDERS = ['openai-codex', 'xai-oauth'];
27
+ export const OAUTH_LOGIN_PROVIDERS = ['openai-codex', 'xai-oauth', 'github-copilot'];
28
28
  export const OAUTH_LOGIN_PHASES = [
29
29
  'awaiting_authorization',
30
30
  'exchanging',
@@ -82,6 +82,13 @@ export const OAUTH_OPERATION_SPECS = {
82
82
  decodeOutput: decodeOAuthLoginProjection,
83
83
  assertOutputForInput: assertOAuthAttemptOutput,
84
84
  }),
85
+ 'oauth.enrollment.query': defineOperation({
86
+ mode: 'query',
87
+ availability: 'ready',
88
+ errors: COMMON_ERRORS,
89
+ decodeInput: decodeOAuthEnrollmentQueryInput,
90
+ decodeOutput: decodeOAuthEnrollmentProjection,
91
+ }),
85
92
  };
86
93
  export function decodeOAuthLoginStartInput(value) {
87
94
  const input = requireExactRecord(value, 'OAuth login start input', ['attemptId', 'target']);
@@ -94,6 +101,23 @@ export function decodeOAuthLoginAttemptInput(value) {
94
101
  const input = requireExactRecord(value, 'OAuth login attempt input', ['attemptId']);
95
102
  return { attemptId: requireEntityId(input.attemptId, 'attemptId') };
96
103
  }
104
+ export function decodeOAuthEnrollmentQueryInput(value) {
105
+ const input = requireExactRecord(value, 'OAuth enrollment query input', ['provider']);
106
+ return { provider: oauthLoginProvider(input.provider) };
107
+ }
108
+ export function decodeOAuthEnrollmentProjection(value) {
109
+ const projection = requireExactRecord(value, 'OAuth enrollment projection', [
110
+ 'provider',
111
+ 'enabled',
112
+ ]);
113
+ if (typeof projection.enabled !== 'boolean') {
114
+ throw invalidProtocolFrame('Invalid OAuth enrollment projection');
115
+ }
116
+ return {
117
+ provider: oauthLoginProvider(projection.provider),
118
+ enabled: projection.enabled,
119
+ };
120
+ }
97
121
  export function decodeOAuthLoginProjection(value) {
98
122
  const projection = requireRecord(value, 'OAuth login projection');
99
123
  const phase = oauthLoginPhase(projection.phase);
@@ -147,6 +147,7 @@ export const REMOTE_OWNER_OPERATION_GRANTS = Object.freeze([
147
147
  'memory.mutate',
148
148
  'memory.query',
149
149
  'network-proxy.test',
150
+ 'oauth.enrollment.query',
150
151
  'oauth.login.cancel',
151
152
  'oauth.login.query',
152
153
  'oauth.login.start',
@@ -19,10 +19,10 @@
19
19
  import { assertExactKeys, requireCount, requireExactRecord, requireRecord, requireString, } from './codec.js';
20
20
  import { defineOperation } from './operation-spec.js';
21
21
  import { canonicalPeerMeshDisplayName } from '../peer-mesh/display-name.js';
22
- import { PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES, PEER_MESH_MAX_ROUTE_HINTS, } from '../peer-mesh/limits.js';
22
+ import { PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES } from '../peer-mesh/limits.js';
23
+ import { decodeSignedPeerReachabilityLease, } from '../peer-reachability/model.js';
23
24
  const PEER_ID_MAX_BYTES = 256;
24
25
  const MESH_ID_MAX_BYTES = 128;
25
- const MESH_ADDRESS_MAX_LENGTH = 1024;
26
26
  const MUTATION_ERRORS = [
27
27
  'invalid_request',
28
28
  'operation_unavailable',
@@ -146,9 +146,7 @@ export function decodePeerMeshInvitation(value) {
146
146
  'authorityPublicKey',
147
147
  'secret',
148
148
  'expiresAt',
149
- 'peerId',
150
- 'routeHints',
151
- 'coordinationRelays',
149
+ 'reachability',
152
150
  ]);
153
151
  if (record.version !== 1)
154
152
  throw new Error('Unsupported Peer Mesh invitation version');
@@ -158,28 +156,9 @@ export function decodePeerMeshInvitation(value) {
158
156
  authorityPublicKey: requireString(record.authorityPublicKey, 'Peer Mesh authority public key', PEER_ID_MAX_BYTES),
159
157
  secret: requireString(record.secret, 'Peer Mesh invitation secret', 64),
160
158
  expiresAt: requireCount(record.expiresAt, 'Peer Mesh invitation expiry'),
161
- peerId: requireMeshToken(record.peerId, 'Peer Mesh authority peerId'),
162
- routeHints: requireMeshAddresses(record.routeHints, 'Peer Mesh route hints'),
163
- coordinationRelays: requireMeshAddresses(record.coordinationRelays, 'Peer Mesh coordination relays'),
159
+ reachability: decodeSignedPeerReachabilityLease(record.reachability),
164
160
  };
165
161
  }
166
- function requireMeshToken(value, label) {
167
- const result = requireString(value, label, PEER_ID_MAX_BYTES);
168
- if (/\s|[\u0000-\u001f\u007f]/u.test(result))
169
- throw new Error(`Invalid ${label}`);
170
- return result;
171
- }
172
- function requireMeshAddresses(value, label) {
173
- if (!Array.isArray(value) || value.length > PEER_MESH_MAX_ROUTE_HINTS) {
174
- throw new Error(`Invalid ${label}`);
175
- }
176
- const addresses = value.map((address) => requireString(address, label, MESH_ADDRESS_MAX_LENGTH));
177
- if (addresses.some((address) => !address.startsWith('/') || /\s|[\u0000-\u001f\u007f]/u.test(address)) ||
178
- new Set(addresses).size !== addresses.length) {
179
- throw new Error(`Invalid ${label}`);
180
- }
181
- return Object.freeze(addresses);
182
- }
183
162
  function decodePeerMeshRemoveInput(value) {
184
163
  const record = requireExactRecord(value, 'Peer Mesh remove input', ['meshId', 'peerId']);
185
164
  return {
@@ -223,7 +202,9 @@ export function decodePeerMeshQueryResult(value) {
223
202
  localPeerId: requireString(localPeerId, 'Peer Mesh localPeerId', PEER_ID_MAX_BYTES),
224
203
  ...(record.localDisplayName === undefined
225
204
  ? {}
226
- : { localDisplayName: canonicalPeerMeshDisplayName(record.localDisplayName) }),
205
+ : {
206
+ localDisplayName: canonicalPeerMeshDisplayName(record.localDisplayName),
207
+ }),
227
208
  transit: decodePeerMeshTransitProjection(record.transit),
228
209
  }),
229
210
  meshes: Object.freeze(record.meshes.map(decodePeerMeshProjection)),
@@ -300,10 +281,10 @@ function decodePeerMeshMemberProjection(value) {
300
281
  ...(record.expiresAt === undefined ? [] : ['expiresAt']),
301
282
  ]);
302
283
  if (record.state !== 'local' &&
303
- record.state !== 'route_available' &&
304
- record.state !== 'coordination_only' &&
305
- record.state !== 'stale' &&
306
- record.state !== 'unknown') {
284
+ record.state !== 'connecting' &&
285
+ record.state !== 'reachable' &&
286
+ record.state !== 'reconnecting' &&
287
+ record.state !== 'needs_repair') {
307
288
  throw new Error('Invalid Peer Mesh member route state');
308
289
  }
309
290
  if (record.endpointKind !== undefined &&
@@ -320,7 +301,9 @@ function decodePeerMeshMemberProjection(value) {
320
301
  state: record.state,
321
302
  ...(record.expiresAt === undefined
322
303
  ? {}
323
- : { expiresAt: requireCount(record.expiresAt, 'Peer Mesh member route expiry') }),
304
+ : {
305
+ expiresAt: requireCount(record.expiresAt, 'Peer Mesh member route expiry'),
306
+ }),
324
307
  };
325
308
  }
326
309
  export function decodePeerMeshInvitationResult(value) {
@@ -244,7 +244,7 @@ function decodeCreateInput(value) {
244
244
  title: boundedText(input.title, 'ScheduledTask title', SCHEDULED_TASK_TITLE_MAX_CHARS, true),
245
245
  intentBody: boundedText(input.intentBody, 'ScheduledTask intent body', SCHEDULED_TASK_INTENT_MAX_CHARS),
246
246
  schedule: decodeSchedule(input.schedule),
247
- effect: decodeEffect(input.effect),
247
+ effect: decodeEffect(input.effect, { requireConnectionId: true }),
248
248
  ...(Object.hasOwn(input, 'maxFires')
249
249
  ? { maxFires: nullablePositiveCount(input.maxFires, 'ScheduledTask maxFires') }
250
250
  : {}),
@@ -269,7 +269,9 @@ function decodeUpdateInput(value) {
269
269
  }
270
270
  : {}),
271
271
  ...(Object.hasOwn(patch, 'schedule') ? { schedule: decodeSchedule(patch.schedule) } : {}),
272
- ...(Object.hasOwn(patch, 'effect') ? { effect: decodeEffect(patch.effect) } : {}),
272
+ ...(Object.hasOwn(patch, 'effect')
273
+ ? { effect: decodeEffect(patch.effect, { requireConnectionId: true }) }
274
+ : {}),
273
275
  ...(Object.hasOwn(patch, 'maxFires')
274
276
  ? { maxFires: nullablePositiveCount(patch.maxFires, 'ScheduledTask maxFires') }
275
277
  : {}),
@@ -332,7 +334,7 @@ function decodeSchedule(value) {
332
334
  }
333
335
  throw invalidProtocolFrame('Invalid ScheduledTask schedule');
334
336
  }
335
- function decodeEffect(value) {
337
+ function decodeEffect(value, options = {}) {
336
338
  const effect = requireRecord(value, 'ScheduledTask effect');
337
339
  if (effect.kind === 'notify') {
338
340
  if (effect.channel === 'local') {
@@ -363,7 +365,10 @@ function decodeEffect(value) {
363
365
  'kind',
364
366
  'execution',
365
367
  ]);
366
- return { kind: 'agent_run', execution: decodeExecution(exact.execution) };
368
+ return {
369
+ kind: 'agent_run',
370
+ execution: decodeExecution(exact.execution, options.requireConnectionId === true),
371
+ };
367
372
  }
368
373
  if (effect.kind === 'session_resume') {
369
374
  const exact = requireExactRecord(effect, 'ScheduledTask Session resume effect', [
@@ -377,7 +382,7 @@ function decodeEffect(value) {
377
382
  }
378
383
  throw invalidProtocolFrame('Invalid ScheduledTask effect');
379
384
  }
380
- function decodeExecution(value) {
385
+ function decodeExecution(value, requireConnectionId = false) {
381
386
  // `backend` left the template (#3306), but templates frozen by older builds
382
387
  // still carry it and this is a closed shape: the key must stay tolerated on
383
388
  // the way in, and it never lands on the decoded value.
@@ -388,7 +393,10 @@ function decodeExecution(value) {
388
393
  'permissionMode',
389
394
  'collaborationMode',
390
395
  'orchestrationMode',
391
- ], ['projectId', 'thinkingLevel', 'backend']);
396
+ ], ['projectId', 'thinkingLevel', 'backend', 'llmConnectionId']);
397
+ if (requireConnectionId && !Object.hasOwn(execution, 'llmConnectionId')) {
398
+ throw invalidProtocolFrame('ScheduledTask execution requires Connection id');
399
+ }
392
400
  if (!isPermissionMode(execution.permissionMode)) {
393
401
  throw invalidProtocolFrame('Invalid ScheduledTask permission mode');
394
402
  }
@@ -411,6 +419,11 @@ function decodeExecution(value) {
411
419
  ...(Object.hasOwn(execution, 'projectId')
412
420
  ? { projectId: execution.projectId }
413
421
  : {}),
422
+ ...(Object.hasOwn(execution, 'llmConnectionId')
423
+ ? {
424
+ llmConnectionId: requireEntityId(execution.llmConnectionId, 'ScheduledTask Connection id'),
425
+ }
426
+ : {}),
414
427
  llmConnectionSlug: boundedText(execution.llmConnectionSlug, 'ScheduledTask connection slug', 256, true),
415
428
  model: boundedText(execution.model, 'ScheduledTask model', 512, true),
416
429
  ...(Object.hasOwn(execution, 'thinkingLevel')
@@ -82,6 +82,13 @@ export const SESSION_COLLABORATION_OPERATION_SPECS = {
82
82
  decodeInput: decodeCollaborationTurnRequestAcknowledgeInput,
83
83
  decodeOutput: decodeCollaborationTurnRequestAcknowledgeResult,
84
84
  }),
85
+ 'collaboration.turn-request.withdraw': defineOperation({
86
+ mode: 'command',
87
+ availability: 'ready',
88
+ errors: COLLABORATION_ERRORS,
89
+ decodeInput: decodeCollaborationTurnRequestWithdrawInput,
90
+ decodeOutput: decodeCollaborationTurnRequestWithdrawResult,
91
+ }),
85
92
  'collaboration.turn-request.decide': defineOperation({
86
93
  mode: 'command',
87
94
  availability: 'ready',
@@ -248,6 +255,21 @@ function decodeCollaborationTurnRequestAcknowledgeResult(value) {
248
255
  }
249
256
  return { acknowledged: record.acknowledged };
250
257
  }
258
+ function decodeCollaborationTurnRequestWithdrawInput(value) {
259
+ const record = requireExactRecord(value, 'collaboration Turn request withdrawal input', [
260
+ 'requestId',
261
+ ]);
262
+ return { requestId: requireId(record.requestId, 'requestId') };
263
+ }
264
+ function decodeCollaborationTurnRequestWithdrawResult(value) {
265
+ const record = requireExactRecord(value, 'collaboration Turn request withdrawal result', [
266
+ 'withdrawn',
267
+ ]);
268
+ if (typeof record.withdrawn !== 'boolean') {
269
+ throw invalidProtocolFrame('Invalid collaboration Turn request withdrawal result');
270
+ }
271
+ return { withdrawn: record.withdrawn };
272
+ }
251
273
  function decodeCollaborationTurnRequestDecideInput(value) {
252
274
  const record = requireExactRecord(value, 'collaboration Turn request decision', [
253
275
  'requestId',
@@ -292,7 +314,20 @@ export function decodeSessionTurnAccessRequest(value) {
292
314
  };
293
315
  }
294
316
  function decodeSessionTurnRequestIntent(value) {
295
- const record = requireExactRecord(value, 'Session Turn request intent', [
317
+ const candidate = requireRecord(value, 'Session Turn request intent');
318
+ if (!Object.hasOwn(candidate, 'content')) {
319
+ const record = requireExactRecord(value, 'Session Turn regenerate request intent', [
320
+ 'sessionId',
321
+ 'turnId',
322
+ 'sourceTurnId',
323
+ ]);
324
+ return {
325
+ sessionId: requireEntityId(record.sessionId, 'sessionId'),
326
+ turnId: requireEntityId(record.turnId, 'turnId'),
327
+ sourceTurnId: requireEntityId(record.sourceTurnId, 'sourceTurnId'),
328
+ };
329
+ }
330
+ const record = requireExactRecord(value, 'Session Turn start request intent', [
296
331
  'sessionId',
297
332
  'turnId',
298
333
  'content',
@@ -67,6 +67,9 @@ function decodeSessionRevisionCopyInput(value) {
67
67
  if (input.intent !== undefined) {
68
68
  throw invalidProtocolFrame('Session revision copy does not support an intent');
69
69
  }
70
+ // A revision never carries an intent, so the shared decoder above already
71
+ // rejected a missing `sourceTurnId` (an empty copy requires the
72
+ // side_conversation intent); reaching here guarantees a turn boundary.
70
73
  return input;
71
74
  }
72
75
  function decodeSessionRevisionAbandonInput(value) {
@@ -87,7 +90,7 @@ function decodeSessionRevisionAbandonResult(value) {
87
90
  };
88
91
  }
89
92
  export function decodeSessionConversationCopyInput(value) {
90
- const input = requireShapedRecord(value, 'Session conversation-copy input', ['sourceSessionId', 'targetSessionId', 'sourceTurnId', 'expectedSourceRevision'], ['intent']);
93
+ const input = requireShapedRecord(value, 'Session conversation-copy input', ['sourceSessionId', 'targetSessionId', 'expectedSourceRevision'], ['sourceTurnId', 'intent']);
91
94
  const sourceSessionId = requireEntityId(input.sourceSessionId, 'sourceSessionId');
92
95
  const targetSessionId = requireEntityId(input.targetSessionId, 'targetSessionId');
93
96
  if (sourceSessionId === targetSessionId) {
@@ -96,10 +99,16 @@ export function decodeSessionConversationCopyInput(value) {
96
99
  if (input.intent !== undefined && input.intent !== 'side_conversation') {
97
100
  throw invalidProtocolFrame('Invalid Session conversation-copy intent');
98
101
  }
102
+ const sourceTurnId = input.sourceTurnId === undefined
103
+ ? undefined
104
+ : requireEntityId(input.sourceTurnId, 'sourceTurnId');
105
+ if (sourceTurnId === undefined && input.intent !== 'side_conversation') {
106
+ throw invalidProtocolFrame('An empty conversation copy requires the side_conversation intent');
107
+ }
99
108
  return {
100
109
  sourceSessionId,
101
110
  targetSessionId,
102
- sourceTurnId: requireEntityId(input.sourceTurnId, 'sourceTurnId'),
111
+ ...(sourceTurnId === undefined ? {} : { sourceTurnId }),
103
112
  expectedSourceRevision: positiveRevision(input.expectedSourceRevision, 'expected source Session revision'),
104
113
  ...(input.intent === 'side_conversation' ? { intent: input.intent } : {}),
105
114
  };
@@ -543,7 +543,8 @@ function decodeUsagePagePosition(result, itemCount) {
543
543
  return { offset, total, nextOffset };
544
544
  }
545
545
  function decodeUsageSummary(value) {
546
- const summary = requireExactRecord(value, 'usage summary', [
546
+ const summary = requireRecord(value, 'usage summary');
547
+ assertOptionalExactKeys(summary, 'usage summary', [
547
548
  'range',
548
549
  'totalRequests',
549
550
  'totalCostUsd',
@@ -551,7 +552,8 @@ function decodeUsageSummary(value) {
551
552
  'cacheHitRequests',
552
553
  'cacheCreateRequests',
553
554
  'errorRequests',
554
- ]);
555
+ 'totalDurationMs',
556
+ ], ['toolUsage']);
555
557
  const range = requireExactRecord(summary.range, 'usage summary range', ['from', 'to']);
556
558
  const tokens = requireExactRecord(summary.totalTokens, 'usage summary tokens', [
557
559
  'input',
@@ -581,6 +583,18 @@ function decodeUsageSummary(value) {
581
583
  cacheHitRequests: requireCount(summary.cacheHitRequests, 'usage cache hit requests'),
582
584
  cacheCreateRequests: requireCount(summary.cacheCreateRequests, 'usage cache create requests'),
583
585
  errorRequests: requireCount(summary.errorRequests, 'usage error requests'),
586
+ totalDurationMs: requireCount(summary.totalDurationMs, 'usage total duration'),
587
+ // Optional for a data reason, not a version one: tool rows that predate
588
+ // connection attribution cannot answer a `connectionSlug` filter, so the
589
+ // Host omits the split for that query rather than send an unscoped total.
590
+ ...(summary.toolUsage !== undefined ? { toolUsage: decodeToolUsage(summary.toolUsage) } : {}),
591
+ };
592
+ }
593
+ function decodeToolUsage(value) {
594
+ const toolUsage = requireExactRecord(value, 'usage tool usage', ['requests', 'durationMs']);
595
+ return {
596
+ requests: requireCount(toolUsage.requests, 'usage tool requests'),
597
+ durationMs: requireCount(toolUsage.durationMs, 'usage tool duration'),
584
598
  };
585
599
  }
586
600
  /**
@@ -171,6 +171,9 @@ export function decodeWorkHubCoordinationActInput(value) {
171
171
  }
172
172
  if (proposal.disposition === 'replace') {
173
173
  const confirmation = decodeWorkHubCoordinationDestructiveConfirmation(input.confirmation);
174
+ if (confirmation.kind !== 'user_correction') {
175
+ throw invalidProtocolFrame('Invalid WorkHub replacement confirmation');
176
+ }
174
177
  if (proposal.target.disposition === 'delegate_existing') {
175
178
  if (input.candidateSetId === undefined || input.create !== undefined) {
176
179
  throw invalidProtocolFrame('Invalid WorkHub replacement context');
@@ -190,6 +193,15 @@ export function decodeWorkHubCoordinationActInput(value) {
190
193
  confirmation,
191
194
  };
192
195
  }
196
+ if (proposal.disposition === 'stop_work') {
197
+ const confirmation = decodeWorkHubCoordinationDestructiveConfirmation(input.confirmation);
198
+ if (confirmation.kind !== 'user_stop' ||
199
+ input.candidateSetId !== undefined ||
200
+ input.create !== undefined) {
201
+ throw invalidProtocolFrame('Invalid WorkHub stop context');
202
+ }
203
+ return { ...base, confirmation };
204
+ }
193
205
  if (input.candidateSetId !== undefined ||
194
206
  input.create !== undefined ||
195
207
  input.confirmation !== undefined) {
@@ -238,6 +250,30 @@ export function decodeWorkHubCoordinationActResult(value) {
238
250
  ...(exact.steered === true ? { steered: true } : {}),
239
251
  };
240
252
  }
253
+ if (result.disposition === 'stop_work') {
254
+ const exact = requireShapedRecord(result, 'WorkHub Coordination stop result', ['disposition', 'outcome', 'targetSessionId'], ['targetTurnId']);
255
+ if (exact.outcome !== 'cancelled_pending' &&
256
+ exact.outcome !== 'stop_delivered' &&
257
+ exact.outcome !== 'already_terminal' &&
258
+ exact.outcome !== 'not_owned') {
259
+ throw invalidProtocolFrame('Invalid WorkHub stop outcome');
260
+ }
261
+ if (((exact.outcome === 'stop_delivered' || exact.outcome === 'not_owned') &&
262
+ exact.targetTurnId === undefined) ||
263
+ (exact.outcome === 'cancelled_pending' && exact.targetTurnId !== undefined)) {
264
+ throw invalidProtocolFrame('Invalid WorkHub stop target Turn');
265
+ }
266
+ return {
267
+ disposition: 'stop_work',
268
+ outcome: exact.outcome,
269
+ targetSessionId: requireEntityId(exact.targetSessionId, 'WorkHub target Session id'),
270
+ ...(exact.targetTurnId === undefined
271
+ ? {}
272
+ : {
273
+ targetTurnId: requireEntityId(exact.targetTurnId, 'WorkHub target Turn id'),
274
+ }),
275
+ };
276
+ }
241
277
  throw invalidProtocolFrame('Invalid WorkHub Coordination action disposition');
242
278
  }
243
279
  function decodeWorkHubCoordinationCandidate(value) {
@@ -331,8 +367,21 @@ function decodeWorkHubCoordinationProposal(value) {
331
367
  }
332
368
  throw invalidProtocolFrame('Invalid WorkHub replacement target');
333
369
  }
370
+ if (proposal.disposition === 'stop_work') {
371
+ const exact = requireExactRecord(proposal, 'WorkHub stop proposal', ['disposition', 'expects']);
372
+ return {
373
+ disposition: 'stop_work',
374
+ expects: decodeWorkHubCoordinationStopPreconditions(exact.expects),
375
+ };
376
+ }
334
377
  throw invalidProtocolFrame('Invalid WorkHub Coordination proposal disposition');
335
378
  }
379
+ function decodeWorkHubCoordinationStopPreconditions(value) {
380
+ const expects = requireExactRecord(value, 'WorkHub stop preconditions', ['targetSessionId']);
381
+ return {
382
+ targetSessionId: requireEntityId(expects.targetSessionId, 'WorkHub target Session id'),
383
+ };
384
+ }
336
385
  function decodeWorkHubCoordinationCreateContext(value) {
337
386
  const context = requireExactRecord(value, 'WorkHub creation context', ['workspace']);
338
387
  return {
@@ -341,10 +390,10 @@ function decodeWorkHubCoordinationCreateContext(value) {
341
390
  }
342
391
  function decodeWorkHubCoordinationDestructiveConfirmation(value) {
343
392
  const confirmation = requireExactRecord(value, 'WorkHub destructive confirmation', ['kind']);
344
- if (confirmation.kind !== 'user_correction') {
393
+ if (confirmation.kind !== 'user_correction' && confirmation.kind !== 'user_stop') {
345
394
  throw invalidProtocolFrame('Invalid WorkHub destructive confirmation');
346
395
  }
347
- return { kind: 'user_correction' };
396
+ return { kind: confirmation.kind };
348
397
  }
349
398
  function candidateSetId(value) {
350
399
  const id = requireUtf8String(value, 'WorkHub candidate set id', CANDIDATE_SET_ID_MAX_BYTES);
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
20
20
  import { join } from 'node:path';
21
+ import { isDeepStrictEqual } from 'node:util';
21
22
  import { runtimeHostAccessCredentialHash } from '../access-credential-identity.js';
22
23
  import { encodeCollaborationInvitationCode, } from '../protocol/index.js';
23
24
  import { createRuntimeHostConnectionAuthority, } from './connection-authority.js';
@@ -186,11 +187,21 @@ class FileRuntimeHostAccessAuthority {
186
187
  request.intent.sessionId === input.intent.sessionId &&
187
188
  request.intent.turnId === input.intent.turnId);
188
189
  if (existing) {
189
- if (existing.intent.content.text !== input.intent.content.text) {
190
- throw new RuntimeHostAccessInputError('A Turn access request already uses this Turn identity with different content');
190
+ if (!isDeepStrictEqual(existing.intent, input.intent)) {
191
+ throw new RuntimeHostAccessInputError('A Turn access request already uses this Turn identity with a different intent');
191
192
  }
192
193
  return existing;
193
194
  }
195
+ if (!('content' in input.intent)) {
196
+ const { sessionId, sourceTurnId } = input.intent;
197
+ const equivalentActive = retainedRequests.find((request) => request.principalId === principalId &&
198
+ isActiveTurnAccessRequest(request) &&
199
+ !('content' in request.intent) &&
200
+ request.intent.sessionId === sessionId &&
201
+ request.intent.sourceTurnId === sourceTurnId);
202
+ if (equivalentActive)
203
+ return equivalentActive;
204
+ }
194
205
  if (retainedRequests.filter(isActiveTurnAccessRequest).length >= TURN_ACCESS_REQUEST_ACTIVE_MAX) {
195
206
  throw new RuntimeHostAccessInputError('Too many Turn access requests are awaiting an Owner decision or admission');
196
207
  }
@@ -234,6 +245,15 @@ class FileRuntimeHostAccessAuthority {
234
245
  return { acknowledged: true };
235
246
  });
236
247
  }
248
+ withdrawTurnAccessRequest(principalId, input) {
249
+ return this.#mutate(async () => {
250
+ const current = this.#file.turnAccessRequests.find((request) => request.requestId === input.requestId && request.principalId === principalId);
251
+ if (!current || current.state.kind !== 'pending')
252
+ return { withdrawn: false };
253
+ await this.#commit(createAccessCredentialFile(this.#file.credentials, this.#file.sessionGrants, this.#file.turnAccessRequests.filter((request) => request !== current)));
254
+ return { withdrawn: true };
255
+ });
256
+ }
237
257
  decideTurnAccessRequest(principalId, input) {
238
258
  return this.#mutate(async () => {
239
259
  const current = this.#file.turnAccessRequests.find((request) => request.requestId === input.requestId);
@@ -882,6 +902,19 @@ export async function acknowledgeCollaborationTurnRequest(authority, principalId
882
902
  return accessPersistenceFailure(error, 'Turn access acknowledgement outcome is unknown', 'Turn access request could not be acknowledged');
883
903
  }
884
904
  }
905
+ export async function withdrawCollaborationTurnRequest(authority, principalId, input) {
906
+ if (!authority)
907
+ return collaborationUnavailable('collaboration.turn-request.withdraw');
908
+ try {
909
+ return {
910
+ ok: true,
911
+ result: await authority.withdrawTurnAccessRequest(principalId, input),
912
+ };
913
+ }
914
+ catch (error) {
915
+ return accessPersistenceFailure(error, 'Turn access withdrawal outcome is unknown', 'Turn access request could not be withdrawn');
916
+ }
917
+ }
885
918
  export async function decideCollaborationTurnRequest(authority, principalId, input) {
886
919
  if (!authority)
887
920
  return collaborationUnavailable('collaboration.turn-request.decide');
@@ -56,6 +56,7 @@ export const SESSION_GUEST_OPERATION_GRANTS = Object.freeze([
56
56
  'collaboration.turn-request.create',
57
57
  'collaboration.turn-request.acknowledge',
58
58
  'collaboration.turn-request.query',
59
+ 'collaboration.turn-request.withdraw',
59
60
  'runtime.resource.query',
60
61
  'session.shared.query',
61
62
  'subscription.open',
@@ -514,13 +514,16 @@ export class HostClientCapabilityCoordinator {
514
514
  this.#deleteProviderIfUnused(provider);
515
515
  }
516
516
  releaseConnection(connectionId) {
517
- this.#invocations.releaseConnection(connectionId);
517
+ const invocationCleanup = this.#invocations.releaseConnection(connectionId);
518
518
  const connection = this.#connections.get(connectionId);
519
519
  if (!connection)
520
- return Promise.resolve();
520
+ return invocationCleanup;
521
521
  let task;
522
- task = this.#activation
523
- .runMutation(() => this.#releaseConnectionState(connection))
522
+ task = Promise.all([
523
+ invocationCleanup,
524
+ this.#activation.runMutation(() => this.#releaseConnectionState(connection)),
525
+ ])
526
+ .then(() => undefined)
524
527
  .finally(() => this.#pendingConnectionReleases.delete(task));
525
528
  this.#pendingConnectionReleases.add(task);
526
529
  void task.catch(() => undefined);
@@ -556,9 +559,8 @@ export class HostClientCapabilityCoordinator {
556
559
  }
557
560
  async close() {
558
561
  this.beginDrain();
559
- for (const connectionId of [...this.#connections.keys()]) {
560
- this.releaseConnection(connectionId);
561
- }
562
+ const releases = [...this.#connections.keys()].map((connectionId) => this.releaseConnection(connectionId));
563
+ await Promise.allSettled(releases);
562
564
  await Promise.allSettled([...this.#pendingConnectionReleases]);
563
565
  this.#invocations.close();
564
566
  this.#sessions.clear();
@@ -738,7 +740,7 @@ export class HostClientCapabilityCoordinator {
738
740
  const target = managedClientCapabilityGrantTarget(selectedBinding.contractId, dynamicBinding.registration, dynamicBinding.tool, evidence);
739
741
  if (!target) {
740
742
  return {
741
- execute: ({ emitProgress } = {}) => prepared.admit(emitProgress),
743
+ execute: ({ emitProgress, requestInteraction } = {}) => prepared.admit(emitProgress, requestInteraction),
742
744
  cancel: () => prepared.cancel(),
743
745
  };
744
746
  }
@@ -760,7 +762,7 @@ export class HostClientCapabilityCoordinator {
760
762
  }
761
763
  }
762
764
  return {
763
- execute: ({ emitProgress } = {}) => prepared.admit(emitProgress),
765
+ execute: ({ emitProgress, requestInteraction } = {}) => prepared.admit(emitProgress, requestInteraction),
764
766
  cancel: () => prepared.cancel(),
765
767
  };
766
768
  }
@@ -771,7 +773,7 @@ export class HostClientCapabilityCoordinator {
771
773
  },
772
774
  callTool: (binding, args, options) => {
773
775
  const { dynamicBinding } = resolveBinding(binding);
774
- return this.#invocations.invoke(dynamicBinding.registration, dynamicBinding.tool, args, options.context, options.signal, options.timeoutMs ?? DEFAULT_CALL_TIMEOUT_MS, options.emitProgress);
776
+ return this.#invocations.invoke(dynamicBinding.registration, dynamicBinding.tool, args, options.context, options.signal, options.timeoutMs ?? DEFAULT_CALL_TIMEOUT_MS, options.emitProgress, options.requestInteraction);
775
777
  },
776
778
  };
777
779
  }