maka-agent 0.2.0-dev.6.20260830 → 0.2.0-dev.9.20260831

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 (86) hide show
  1. package/dist/cli-core.js +11 -0
  2. package/dist/runtime-host-cli.js +44 -0
  3. package/dist/runtime-host-installed-update-activator.js +70 -33
  4. package/dist/runtime-host-installed-update-coordinator.js +11 -96
  5. package/dist/runtime-host-lifecycle-transaction.js +2 -0
  6. package/dist/runtime-host-local-handoff.js +169 -38
  7. package/dist/runtime-host-local-source-retirement.js +103 -0
  8. package/dist/runtime-host-local-target-activation.js +141 -0
  9. package/dist/runtime-host-peer-management-command.js +10 -4
  10. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  11. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  12. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  13. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  14. package/node_modules/@maka/core/dist/agent-run.js +0 -2
  15. package/node_modules/@maka/core/dist/artifacts.js +23 -15
  16. package/node_modules/@maka/core/dist/durable-tool-result-projection.js +124 -0
  17. package/node_modules/@maka/core/dist/foreign-session.js +1 -1
  18. package/node_modules/@maka/core/dist/llm-connections.js +20 -0
  19. package/node_modules/@maka/core/dist/runtime-event.js +28 -3
  20. package/node_modules/@maka/core/dist/session-name.js +0 -1
  21. package/node_modules/@maka/core/dist/task-ledger.js +6 -134
  22. package/node_modules/@maka/core/dist/usage-record-schema.js +1 -0
  23. package/node_modules/@maka/core/package.json +1 -0
  24. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +97 -133
  25. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +4 -18
  26. package/node_modules/@maka/runtime/dist/context-budget.js +0 -1
  27. package/node_modules/@maka/runtime/dist/conversation-copy.js +67 -0
  28. package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +390 -0
  29. package/node_modules/@maka/runtime/dist/model-history.js +12 -39
  30. package/node_modules/@maka/runtime/dist/plan-mode.js +0 -65
  31. package/node_modules/@maka/runtime/dist/recovery-resolver.js +18 -14
  32. package/node_modules/@maka/runtime/dist/run-trace.js +0 -10
  33. package/node_modules/@maka/runtime/dist/runtime-kernel.js +0 -1
  34. package/node_modules/@maka/runtime/dist/sandbox/index.js +0 -1
  35. package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +0 -12
  36. package/node_modules/@maka/runtime/dist/sandbox/macos-seatbelt.js +0 -12
  37. package/node_modules/@maka/runtime/dist/sandbox/sandbox-manager.js +0 -35
  38. package/node_modules/@maka/runtime/dist/sandbox/windows-sandbox.js +0 -12
  39. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +20 -11
  40. package/node_modules/@maka/runtime/dist/session-manager.js +0 -170
  41. package/node_modules/@maka/runtime/dist/shell-detect.js +3 -7
  42. package/node_modules/@maka/runtime/dist/shell-run-contract.js +0 -1
  43. package/node_modules/@maka/runtime/dist/shell-run-manager.js +1 -39
  44. package/node_modules/@maka/runtime/dist/shell-tools.js +1 -1
  45. package/node_modules/@maka/runtime/dist/task-ledger-tools.js +2 -2
  46. package/node_modules/@maka/runtime/dist/tool-runtime.js +118 -71
  47. package/node_modules/@maka/runtime/package.json +1 -1
  48. package/node_modules/@maka/runtime-host/dist/candidate-entry.js +6 -1
  49. package/node_modules/@maka/runtime-host/dist/candidate-launch-owner-guard.js +13 -0
  50. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +4 -1
  51. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +27 -1
  52. package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
  53. package/node_modules/@maka/runtime-host/dist/client/launcher.js +8 -2
  54. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +11 -1
  55. package/node_modules/@maka/runtime-host/dist/peer-mesh/index.js +1 -1
  56. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +394 -113
  57. package/node_modules/@maka/runtime-host/dist/peer-mesh/store.js +90 -21
  58. package/node_modules/@maka/runtime-host/dist/protocol/index.js +8 -1
  59. package/node_modules/@maka/runtime-host/dist/protocol/oauth.js +60 -7
  60. package/node_modules/@maka/runtime-host/dist/protocol/usage-pricing.js +4 -0
  61. package/node_modules/@maka/runtime-host/dist/server/artifact-coordinator.js +2 -4
  62. package/node_modules/@maka/runtime-host/dist/server/candidate.js +3 -0
  63. package/node_modules/@maka/runtime-host/dist/server/client-capability-recovery.js +10 -7
  64. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +6 -9
  65. package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +9 -7
  66. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +10 -0
  67. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +2 -58
  68. package/node_modules/@maka/runtime-host/dist/server/oauth-coordinator.js +91 -42
  69. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +10 -1
  70. package/node_modules/@maka/runtime-host/dist/server/usage-pricing-coordinator.js +45 -5
  71. package/node_modules/@maka/storage/dist/artifact-attachments.js +62 -11
  72. package/node_modules/@maka/storage/dist/artifact-store.js +11 -0
  73. package/node_modules/@maka/storage/dist/artifact-stores.js +4 -1
  74. package/node_modules/@maka/storage/dist/quiescent-session-snapshot.js +1154 -0
  75. package/node_modules/@maka/storage/dist/runtime-policy/connection-catalog-document.js +36 -0
  76. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +213 -46
  77. package/node_modules/@maka/storage/dist/runtime-policy/document-io.js +1 -1
  78. package/node_modules/@maka/storage/dist/runtime-policy/oauth-login-receipt-document.js +186 -0
  79. package/node_modules/@maka/storage/dist/runtime-policy/onboarding-transaction.js +120 -1
  80. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +2 -1
  81. package/node_modules/@maka/storage/dist/session-bundle-ustar.js +12 -0
  82. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +5 -0
  83. package/package.json +1 -1
  84. package/node_modules/@maka/runtime/dist/sandbox/diagnostics.js +0 -285
  85. package/node_modules/@maka/runtime/dist/system-prompt/sandbox-context-prompt.js +0 -77
  86. package/node_modules/@maka/runtime/dist/system-prompt/session-environment-prompt.js +0 -47
@@ -19,7 +19,7 @@
19
19
  import { chmod, lstat, mkdir, open, readFile, rename, unlink } from 'node:fs/promises';
20
20
  import { dirname, join } from 'node:path';
21
21
  import { acquireFileLifetimeOwner, } from '@maka/storage/file-lifetime-owner';
22
- import { decodeAuthorityTarget, decodeSignedPeerMeshRoster, decodeSignedPeerMeshRouteRecord, PEER_MESH_MAX_INVITATION_RECORDS, PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES, PEER_MESH_MAX_PENDING_INVITATIONS, validatePeerMeshAuthorityKeyPair, } from './model.js';
22
+ import { decodeAuthorityTarget, decodeSignedPeerMeshRoster, decodeSignedPeerMeshRouteRecord, PEER_MESH_MAX_INVITATION_RECORDS, PEER_MESH_MAX_MEMBERS, PEER_MESH_MAX_MESHES, PEER_MESH_MAX_PENDING_INVITATIONS, validatePeerMeshInvitation, validatePeerMeshAuthorityKeyPair, } from './model.js';
23
23
  import { canonicalPeerMeshDisplayName } from './display-name.js';
24
24
  const STATE_FILE = 'peer-mesh.json';
25
25
  const LOCK_FILE = 'peer-mesh.owner';
@@ -38,9 +38,10 @@ export async function openPeerMeshStateStore(dataRoot, localPeerId) {
38
38
  throw error;
39
39
  }
40
40
  }
41
- export async function hasActivePeerMeshMembership(dataRoot, localPeerId) {
41
+ export async function hasPeerMeshIdentityObligations(dataRoot, localPeerId) {
42
42
  const state = await readState(join(dataRoot, STATE_FILE), localPeerId);
43
- return state.meshes.some((mesh) => !isRetired(mesh, localPeerId));
43
+ return (state.pendingJoins.length > 0 ||
44
+ state.meshes.some((mesh) => !isRetiredPeerMeshState(mesh, localPeerId)));
44
45
  }
45
46
  export async function migrateLegacyPeerMeshState(dataRoot, localPeerId) {
46
47
  const legacyPath = join(dataRoot, STATE_FILE);
@@ -135,14 +136,16 @@ class PeerMeshStateStoreImpl {
135
136
  throw this.#failure;
136
137
  }
137
138
  }
138
- export function decodePeerMeshState(value, localPeerId) {
139
+ export function decodePeerMeshState(value, localPeerId, legacyReplica = false) {
139
140
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
140
141
  throw new Error('Invalid Peer Mesh state');
141
142
  }
142
143
  const record = value;
143
144
  const expectedKeys = record.role === 'authority'
144
145
  ? ['role', 'roster', 'authorityPrivateKey', 'invitations']
145
- : ['role', 'roster', 'authority'];
146
+ : legacyReplica
147
+ ? ['role', 'roster', 'authority']
148
+ : ['role', 'roster', 'authority', 'desiredMembership'];
146
149
  if (Object.keys(record).length !== expectedKeys.length ||
147
150
  expectedKeys.some((key) => !Object.hasOwn(record, key))) {
148
151
  throw new Error('Invalid Peer Mesh state');
@@ -175,13 +178,14 @@ export function decodePeerMeshState(value, localPeerId) {
175
178
  role: 'replica',
176
179
  authority,
177
180
  roster,
181
+ desiredMembership: legacyReplica ? 'active' : decodeDesiredMembership(record.desiredMembership),
178
182
  });
179
183
  }
180
- function decodePeerMeshStates(value, localPeerId) {
184
+ function decodePeerMeshStates(value, localPeerId, legacyReplica = false) {
181
185
  if (!Array.isArray(value) || value.length > PEER_MESH_MAX_MESHES) {
182
186
  throw new Error('Invalid Peer Mesh state collection');
183
187
  }
184
- const states = value.map((state) => decodePeerMeshState(state, localPeerId));
188
+ const states = value.map((state) => decodePeerMeshState(state, localPeerId, legacyReplica));
185
189
  const meshIds = states.map(({ roster }) => roster.roster.meshId);
186
190
  if (new Set(meshIds).size !== meshIds.length) {
187
191
  throw new Error('Duplicate Peer Mesh state');
@@ -192,7 +196,7 @@ function assertStateAdvance(current, next, localPeerId) {
192
196
  for (const previous of current) {
193
197
  const updated = next.find(({ roster }) => roster.roster.meshId === previous.roster.roster.meshId);
194
198
  if (!updated) {
195
- if (isRetired(previous, localPeerId))
199
+ if (isRetiredPeerMeshState(previous, localPeerId))
196
200
  continue;
197
201
  throw new Error('Active Peer Mesh state cannot be removed implicitly');
198
202
  }
@@ -211,12 +215,14 @@ function assertStateAdvance(current, next, localPeerId) {
211
215
  }
212
216
  }
213
217
  }
214
- function isRetired(state, localPeerId) {
218
+ export function isRetiredPeerMeshState(state, localPeerId) {
215
219
  return (state.roster.roster.closed ||
216
220
  (state.role === 'replica' && !state.roster.roster.members.includes(localPeerId)));
217
221
  }
218
- function isActiveMembership(state, localPeerId) {
219
- return !isRetired(state, localPeerId) && state.roster.roster.members.includes(localPeerId);
222
+ export function isActivePeerMeshMembership(state, localPeerId) {
223
+ return (!isRetiredPeerMeshState(state, localPeerId) &&
224
+ state.roster.roster.members.includes(localPeerId) &&
225
+ (state.role === 'authority' || state.desiredMembership === 'active'));
220
226
  }
221
227
  export function authorityKeys(state) {
222
228
  if (state.role !== 'authority') {
@@ -259,24 +265,34 @@ async function readState(path, expectedLocalPeerId) {
259
265
  Object.hasOwn(record, 'meshes') &&
260
266
  Object.hasOwn(record, 'routes') &&
261
267
  Object.hasOwn(record, 'transitMeshId');
262
- if (!versionOne && !versionTwo && !versionThree && !versionFour) {
268
+ const versionSix = record.version === 6 &&
269
+ Object.keys(record).length === 7 &&
270
+ Object.hasOwn(record, 'localPeerId') &&
271
+ Object.hasOwn(record, 'displayName') &&
272
+ Object.hasOwn(record, 'meshes') &&
273
+ Object.hasOwn(record, 'pendingJoins') &&
274
+ Object.hasOwn(record, 'routes') &&
275
+ Object.hasOwn(record, 'transitMeshId');
276
+ if (!versionOne && !versionTwo && !versionThree && !versionFour && !versionSix) {
263
277
  throw new Error('Unsupported Peer Mesh state document');
264
278
  }
265
279
  if (boundedString(record.localPeerId, 'localPeerId', 256) !== expectedLocalPeerId) {
266
280
  throw new Error('Peer Mesh state belongs to a different peer identity');
267
281
  }
268
282
  return decodePeerMeshStoredState({
269
- displayName: versionFour ? record.displayName : null,
283
+ displayName: versionFour || versionSix ? record.displayName : null,
270
284
  meshes: record.meshes,
285
+ pendingJoins: versionSix ? record.pendingJoins : [],
271
286
  routes: versionOne ? [] : record.routes,
272
- transitMeshId: versionThree || versionFour ? record.transitMeshId : null,
273
- }, expectedLocalPeerId);
287
+ transitMeshId: versionThree || versionFour || versionSix ? record.transitMeshId : null,
288
+ }, expectedLocalPeerId, !versionSix);
274
289
  }
275
290
  catch (error) {
276
291
  if (isNodeError(error, 'ENOENT')) {
277
292
  return Object.freeze({
278
293
  displayName: null,
279
294
  meshes: Object.freeze([]),
295
+ pendingJoins: Object.freeze([]),
280
296
  routes: Object.freeze([]),
281
297
  transitMeshId: null,
282
298
  });
@@ -296,7 +312,7 @@ async function pathExists(path) {
296
312
  }
297
313
  }
298
314
  async function writeState(path, localPeerId, state) {
299
- const document = `${JSON.stringify({ version: 4, localPeerId, ...state }, null, 2)}\n`;
315
+ const document = `${JSON.stringify({ version: 6, localPeerId, ...state }, null, 2)}\n`;
300
316
  if (Buffer.byteLength(document) > MAX_STATE_BYTES)
301
317
  throw new Error('Peer Mesh state is too large');
302
318
  const temporary = `${path}.tmp`;
@@ -400,40 +416,93 @@ function decodeRoutes(value, meshes) {
400
416
  }
401
417
  return Object.freeze(routes);
402
418
  }
403
- function decodePeerMeshStoredState(value, localPeerId) {
419
+ function decodePeerMeshStoredState(value, localPeerId, legacyReplica = false) {
404
420
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
405
421
  throw new Error('Invalid Peer Mesh state document');
406
422
  }
407
423
  const record = value;
408
- if (Object.keys(record).length !== 4 ||
424
+ if (Object.keys(record).length !== 5 ||
409
425
  !Object.hasOwn(record, 'displayName') ||
410
426
  !Object.hasOwn(record, 'meshes') ||
427
+ !Object.hasOwn(record, 'pendingJoins') ||
411
428
  !Object.hasOwn(record, 'routes') ||
412
429
  !Object.hasOwn(record, 'transitMeshId')) {
413
430
  throw new Error('Invalid Peer Mesh state document');
414
431
  }
415
- const meshes = decodePeerMeshStates(record.meshes, localPeerId);
432
+ const meshes = decodePeerMeshStates(record.meshes, localPeerId, legacyReplica);
433
+ const pendingJoins = decodePendingJoins(record.pendingJoins, meshes, localPeerId);
416
434
  const displayName = record.displayName === null ? null : canonicalPeerMeshDisplayName(record.displayName);
417
435
  const transitMeshId = record.transitMeshId === null
418
436
  ? null
419
437
  : boundedString(record.transitMeshId, 'transitMeshId', 128);
420
438
  if (transitMeshId !== null &&
421
- !meshes.some((mesh) => mesh.roster.roster.meshId === transitMeshId && isActiveMembership(mesh, localPeerId))) {
439
+ !meshes.some((mesh) => mesh.roster.roster.meshId === transitMeshId &&
440
+ isActivePeerMeshMembership(mesh, localPeerId))) {
422
441
  throw new Error('Peer Mesh transit selection is not an active membership');
423
442
  }
424
443
  return Object.freeze({
425
444
  displayName,
426
445
  meshes,
446
+ pendingJoins,
427
447
  routes: decodeRoutes(record.routes, meshes),
428
448
  transitMeshId,
429
449
  });
430
450
  }
451
+ function decodePendingJoins(value, meshes, localPeerId) {
452
+ if (!Array.isArray(value) || value.length > PEER_MESH_MAX_MESHES) {
453
+ throw new Error('Invalid pending Peer Mesh joins');
454
+ }
455
+ const joins = value.map((entry) => {
456
+ if (!entry ||
457
+ typeof entry !== 'object' ||
458
+ Array.isArray(entry) ||
459
+ Object.keys(entry).length !== 2 ||
460
+ !Object.hasOwn(entry, 'invitation') ||
461
+ !Object.hasOwn(entry, 'phase')) {
462
+ throw new Error('Invalid pending Peer Mesh join');
463
+ }
464
+ const record = entry;
465
+ return Object.freeze({
466
+ invitation: validatePeerMeshInvitation(record.invitation),
467
+ phase: decodePendingJoinPhase(record.phase),
468
+ });
469
+ });
470
+ const meshIds = joins.map(({ invitation }) => invitation.meshId);
471
+ const activeMeshIds = meshes
472
+ .filter((mesh) => isActivePeerMeshMembership(mesh, localPeerId))
473
+ .map(({ roster }) => roster.roster.meshId);
474
+ if (new Set(meshIds).size !== meshIds.length ||
475
+ joins.some(({ invitation }) => {
476
+ const existing = meshes.find(({ roster }) => roster.roster.meshId === invitation.meshId);
477
+ return (existing !== undefined &&
478
+ (existing.role !== 'replica' ||
479
+ existing.roster.roster.closed ||
480
+ existing.roster.authorityPublicKey !== invitation.authorityPublicKey));
481
+ }) ||
482
+ new Set([...activeMeshIds, ...meshIds]).size > PEER_MESH_MAX_MESHES) {
483
+ throw new Error('Invalid pending Peer Mesh joins');
484
+ }
485
+ return Object.freeze(joins);
486
+ }
487
+ function decodeDesiredMembership(value) {
488
+ if (value !== 'active' && value !== 'left') {
489
+ throw new Error('Invalid Peer Mesh desired membership');
490
+ }
491
+ return value;
492
+ }
493
+ function decodePendingJoinPhase(value) {
494
+ if (value !== 'prepared' && value !== 'outcome_unknown' && value !== 'leave_pending') {
495
+ throw new Error('Invalid Peer Mesh join phase');
496
+ }
497
+ return value;
498
+ }
431
499
  function pruneUnreferencedRoutes(state, localPeerId) {
432
500
  const knownPeers = new Set(state.meshes
433
501
  .filter(({ roster }) => !roster.roster.closed)
434
502
  .flatMap(({ roster }) => roster.roster.members));
435
503
  const routes = state.routes.filter(({ route }) => knownPeers.has(route.peerId));
436
- const transitMeshId = state.meshes.some((mesh) => mesh.roster.roster.meshId === state.transitMeshId && isActiveMembership(mesh, localPeerId))
504
+ const transitMeshId = state.meshes.some((mesh) => mesh.roster.roster.meshId === state.transitMeshId &&
505
+ isActivePeerMeshMembership(mesh, localPeerId))
437
506
  ? state.transitMeshId
438
507
  : null;
439
508
  return routes.length === state.routes.length && transitMeshId === state.transitMeshId
@@ -59,7 +59,12 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
59
59
  export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
60
60
  // Increment when the same protocol version no longer guarantees safe Client-Host
61
61
  // interoperability. Mismatches are rejected before domain commands are admitted.
62
- export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 76;
62
+ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 78;
63
+ // 78: OAuth login targets explicit create/existing Connection entities and
64
+ // returns their canonical identity. Older peers reject both closed wire shapes.
65
+ // 77: LLM and tool usage-log projections carry an optional `sessionTitle` (the
66
+ // Host-resolved session name for the usage Task column). Older Clients reject
67
+ // the unknown field, so a newer Host's usage logs are unreadable to them.
63
68
  // 76: Peer Mesh endpoint and Mesh display names are signed, persisted facts
64
69
  // managed through Host operations rather than local-only Client labels.
65
70
  // 75: Peer Mesh routes identify whether a peer is a Client or Runtime Host so
@@ -69,6 +74,8 @@ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 76;
69
74
  // unrelated provider for an interactive Session.
70
75
  // 73: Transcript pages carry a Host-owned Turn range boundary. Older peers
71
76
  // cannot preserve both the complete edge Turn and the bounded projection.
77
+ // 72: Collaboration Turn request query results require `canRequestTurns`.
78
+ // Older peers reject the new closed result shape.
72
79
  // 71: Session Guests can submit durable exact Turn access requests and Owners
73
80
  // can decide them. Older peers do not understand this execution-authority flow.
74
81
  // 70: Session Guest connections receive resource-scoped shared catalog and
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { decodeConnectionSlug, RuntimePolicyDomainDecodeError } from '@maka/core/runtime-policy';
19
20
  import { requireEntityId, requireExactRecord, requireRecord, requireShapedRecord, requireString, } from './codec.js';
20
21
  import { invalidProtocolFrame } from './errors.js';
21
22
  import { defineOperation } from './operation-spec.js';
@@ -37,6 +38,7 @@ export const OAUTH_LOGIN_FAILURE_CODES = [
37
38
  'authorization_failed',
38
39
  'provider_rejected',
39
40
  'credential_changed',
41
+ 'connection_changed',
40
42
  'persistence_failed',
41
43
  'internal_failure',
42
44
  ];
@@ -54,7 +56,7 @@ const START_ERRORS = [
54
56
  'not_found',
55
57
  'persistence_failed',
56
58
  ];
57
- const ATTEMPT_ERRORS = [...COMMON_ERRORS, 'not_found'];
59
+ const ATTEMPT_ERRORS = [...COMMON_ERRORS, 'not_found', 'persistence_failed'];
58
60
  export const OAUTH_OPERATION_SPECS = {
59
61
  'oauth.login.start': defineOperation({
60
62
  mode: 'command',
@@ -62,6 +64,7 @@ export const OAUTH_OPERATION_SPECS = {
62
64
  errors: START_ERRORS,
63
65
  decodeInput: decodeOAuthLoginStartInput,
64
66
  decodeOutput: decodeOAuthLoginProjection,
67
+ assertOutputForInput: assertOAuthStartOutput,
65
68
  }),
66
69
  'oauth.login.query': defineOperation({
67
70
  mode: 'query',
@@ -69,6 +72,7 @@ export const OAUTH_OPERATION_SPECS = {
69
72
  errors: ATTEMPT_ERRORS,
70
73
  decodeInput: decodeOAuthLoginAttemptInput,
71
74
  decodeOutput: decodeOAuthLoginProjection,
75
+ assertOutputForInput: assertOAuthAttemptOutput,
72
76
  }),
73
77
  'oauth.login.cancel': defineOperation({
74
78
  mode: 'control',
@@ -76,13 +80,14 @@ export const OAUTH_OPERATION_SPECS = {
76
80
  errors: ATTEMPT_ERRORS,
77
81
  decodeInput: decodeOAuthLoginAttemptInput,
78
82
  decodeOutput: decodeOAuthLoginProjection,
83
+ assertOutputForInput: assertOAuthAttemptOutput,
79
84
  }),
80
85
  };
81
86
  export function decodeOAuthLoginStartInput(value) {
82
- const input = requireExactRecord(value, 'OAuth login start input', ['attemptId', 'connectionId']);
87
+ const input = requireExactRecord(value, 'OAuth login start input', ['attemptId', 'target']);
83
88
  return {
84
89
  attemptId: requireEntityId(input.attemptId, 'attemptId'),
85
- connectionId: requireEntityId(input.connectionId, 'connectionId'),
90
+ target: decodeOAuthLoginTarget(input.target),
86
91
  };
87
92
  }
88
93
  export function decodeOAuthLoginAttemptInput(value) {
@@ -93,16 +98,64 @@ export function decodeOAuthLoginProjection(value) {
93
98
  const projection = requireRecord(value, 'OAuth login projection');
94
99
  const phase = oauthLoginPhase(projection.phase);
95
100
  const exact = requireExactRecord(projection, 'OAuth login projection', phase === 'failed'
96
- ? ['attemptId', 'connectionId', 'provider', 'phase', 'failure']
97
- : ['attemptId', 'connectionId', 'provider', 'phase']);
101
+ ? ['attemptId', 'connection', 'phase', 'failure']
102
+ : ['attemptId', 'connection', 'phase']);
98
103
  return {
99
104
  attemptId: requireEntityId(exact.attemptId, 'attemptId'),
100
- connectionId: requireEntityId(exact.connectionId, 'connectionId'),
101
- provider: oauthLoginProvider(exact.provider),
105
+ connection: decodeOAuthConnectionIdentity(exact.connection),
102
106
  phase,
103
107
  ...(phase === 'failed' ? { failure: oauthLoginFailure(exact.failure) } : {}),
104
108
  };
105
109
  }
110
+ function decodeOAuthLoginTarget(value) {
111
+ const target = requireRecord(value, 'OAuth login target');
112
+ if (target.kind === 'create') {
113
+ const exact = requireExactRecord(target, 'OAuth create target', ['kind', 'providerType']);
114
+ return { kind: 'create', providerType: oauthLoginProvider(exact.providerType) };
115
+ }
116
+ if (target.kind === 'existing') {
117
+ const exact = requireExactRecord(target, 'OAuth existing target', ['kind', 'connectionId']);
118
+ return { kind: 'existing', connectionId: requireEntityId(exact.connectionId, 'connectionId') };
119
+ }
120
+ throw invalidProtocolFrame('Invalid OAuth login target');
121
+ }
122
+ function decodeOAuthConnectionIdentity(value) {
123
+ const connection = requireExactRecord(value, 'OAuth connection identity', [
124
+ 'connectionId',
125
+ 'slug',
126
+ 'providerType',
127
+ ]);
128
+ return {
129
+ connectionId: requireEntityId(connection.connectionId, 'connectionId'),
130
+ slug: decodeDomain(() => decodeConnectionSlug(connection.slug)),
131
+ providerType: oauthLoginProvider(connection.providerType),
132
+ };
133
+ }
134
+ function assertOAuthStartOutput(input, output) {
135
+ assertOAuthAttemptOutput(input, output);
136
+ if ((input.target.kind === 'create' &&
137
+ output.connection.providerType !== input.target.providerType) ||
138
+ (input.target.kind === 'existing' &&
139
+ output.connection.connectionId !== input.target.connectionId)) {
140
+ throw invalidProtocolFrame('OAuth login start changed Connection identity');
141
+ }
142
+ }
143
+ function assertOAuthAttemptOutput(input, output) {
144
+ if (input.attemptId !== output.attemptId) {
145
+ throw invalidProtocolFrame('OAuth login changed attempt identity');
146
+ }
147
+ }
148
+ function decodeDomain(operation) {
149
+ try {
150
+ return operation();
151
+ }
152
+ catch (error) {
153
+ if (error instanceof RuntimePolicyDomainDecodeError) {
154
+ throw invalidProtocolFrame(error.message);
155
+ }
156
+ throw error;
157
+ }
158
+ }
106
159
  export function decodeOAuthPresentationRequest(method, value) {
107
160
  if (method === 'open_external') {
108
161
  const input = requireShapedRecord(value, 'OAuth presentation input', ['url'], ['stateHint']);
@@ -84,6 +84,7 @@ const LLM_USAGE_LOG_FIELDS = new Set([
84
84
  'status',
85
85
  'errorClass',
86
86
  'sessionId',
87
+ 'sessionTitle',
87
88
  'turnId',
88
89
  ]);
89
90
  const TOOL_USAGE_LOG_FIELDS = new Set([
@@ -103,6 +104,7 @@ const TOOL_USAGE_LOG_FIELDS = new Set([
103
104
  'bytesOut',
104
105
  'startedAt',
105
106
  'sessionId',
107
+ 'sessionTitle',
106
108
  'turnId',
107
109
  ]);
108
110
  const TOOL_RESULT_SUMMARY_FIELDS = new Set([
@@ -710,6 +712,7 @@ function decodeLlmUsageLog(value) {
710
712
  status: decodeUsageLogStatus(row.status),
711
713
  ...optionalProjectionText(row, 'errorClass'),
712
714
  ...optionalProjectionText(row, 'sessionId'),
715
+ ...optionalProjectionText(row, 'sessionTitle'),
713
716
  ...optionalProjectionText(row, 'turnId'),
714
717
  };
715
718
  }
@@ -748,6 +751,7 @@ function decodeToolUsageLog(value) {
748
751
  bytesOut: requireCount(row.bytesOut, 'tool usage log bytes out'),
749
752
  startedAt: nonnegativeFinite(row.startedAt, 'tool usage log start time'),
750
753
  ...optionalProjectionText(row, 'sessionId'),
754
+ ...optionalProjectionText(row, 'sessionTitle'),
751
755
  ...optionalProjectionText(row, 'turnId'),
752
756
  };
753
757
  }
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { createHash } from 'node:crypto';
20
20
  import { attachmentKindFromMimeType } from '@maka/core/attachments';
21
+ import { isArtifactSharedSessionReadable } from '@maka/core/artifacts';
21
22
  import { authenticateInteractiveArtifactStoreWriter, sanitizeArtifactName, } from '@maka/storage/artifact-stores';
22
23
  import { ARTIFACT_PAGE_MAX_ITEMS, ARTIFACT_PREVIEW_MAX_BYTES, ARTIFACT_READ_CHUNK_MAX_BYTES, ARTIFACT_RESULT_MAX_BYTES, encodeArtifactDeleteResult, encodeArtifactQueryResult, } from '../protocol/index.js';
23
24
  import { encodeArtifactProjection } from '../protocol/artifact.js';
@@ -25,7 +26,6 @@ import { ConnectionBoundChunkUploads } from './connection-bound-chunk-uploads.js
25
26
  const MAX_ACTIVE_ARTIFACT_UPLOADS = 16;
26
27
  const MAX_STAGED_ARTIFACT_UPLOAD_BYTES = 128 * 1024 * 1024;
27
28
  const ARTIFACT_UPLOAD_TTL_MS = 5 * 60 * 1000;
28
- const SHARED_ARTIFACT_SOURCES = new Set(['user_upload', 'tool_result']);
29
29
  /** Session-scoped Host projection and deletion authority for Artifacts. */
30
30
  export class HostArtifactCoordinator {
31
31
  handlers = {
@@ -312,9 +312,7 @@ export class HostArtifactCoordinator {
312
312
  if (!grant)
313
313
  return;
314
314
  const entry = await this.#store.getInSession(input.sessionId, input.artifactId);
315
- return entry.record?.status === 'live' &&
316
- entry.record.source !== undefined &&
317
- SHARED_ARTIFACT_SOURCES.has(entry.record.source)
315
+ return entry.record?.status === 'live' && isArtifactSharedSessionReadable(entry.record)
318
316
  ? grant.grantId
319
317
  : undefined;
320
318
  }
@@ -49,6 +49,9 @@ export async function startInteractiveRuntimeHostCandidate(options, createCompos
49
49
  handshakeTimeoutMs: options.handshakeTimeoutMs,
50
50
  generation: options.generation,
51
51
  composition,
52
+ ...(options.initialClientAdmission
53
+ ? { initialClientAdmission: options.initialClientAdmission }
54
+ : {}),
52
55
  ...(accessAuthority ? { accessAuthority } : {}),
53
56
  ...(websocket && accessAuthority
54
57
  ? {
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { compatibilityToolResultProjection } from '@maka/runtime/durable-tool-result-projection';
19
20
  const OUTCOME_UNKNOWN_TEXT = 'outcome_unknown: the Host restarted after dispatching this Client Capability call. The client-side effect may have happened; do not retry it automatically.';
20
21
  export async function recoverClientCapabilityOutcomes(store, sessionIds, now = Date.now) {
21
22
  let recovered = 0;
@@ -33,6 +34,14 @@ export async function recoverClientCapabilityOutcomes(store, sessionIds, now = D
33
34
  retrySafe: false,
34
35
  },
35
36
  };
37
+ const responseContent = {
38
+ kind: 'function_response',
39
+ id: operation.providerToolCallId,
40
+ name: operation.toolName,
41
+ result,
42
+ isError: true,
43
+ };
44
+ const modelProjection = compatibilityToolResultProjection(responseContent, sessionId);
36
45
  const runtimeEvent = {
37
46
  id: `${operation.operationId}_response`,
38
47
  invocationId: operation.invocationId,
@@ -43,13 +52,7 @@ export async function recoverClientCapabilityOutcomes(store, sessionIds, now = D
43
52
  partial: false,
44
53
  role: 'tool',
45
54
  author: 'tool',
46
- content: {
47
- kind: 'function_response',
48
- id: operation.providerToolCallId,
49
- name: operation.toolName,
50
- result,
51
- isError: true,
52
- },
55
+ content: { ...responseContent, ...(modelProjection ? { modelProjection } : {}) },
53
56
  refs: {
54
57
  operationId: operation.operationId,
55
58
  toolCallId: operation.providerToolCallId,
@@ -32,7 +32,7 @@ import { buildHistoryTools } from '@maka/runtime/history-tools';
32
32
  import { createLocalContinuationSafetyInspector } from '@maka/runtime/continuation-safety';
33
33
  import { createConfiguredSubagentCatalog } from '@maka/runtime/configured-subagent-catalog';
34
34
  import { buildHostCapabilitiesFromBinding } from '@maka/runtime/skills';
35
- import { createBuiltinSandboxManager, createSandboxDiagnosticsProvider, isBuiltinFilesystemWorkerSandboxAvailable, } from '@maka/runtime/sandbox';
35
+ import { createBuiltinSandboxManager, isBuiltinFilesystemWorkerSandboxAvailable, } from '@maka/runtime/sandbox';
36
36
  import { createFilesystemWorkerLaunchSpecProvider, FilesystemWorkerClient, } from '@maka/runtime/filesystem-worker';
37
37
  import { isOAuthEnrollmentProviderEnabled } from '@maka/runtime/oauth-provider-contracts';
38
38
  import { loadHistoryCompactCheckpointsFromRunLedger, loadLatestHistoryCompactCheckpointFromRunLedger, } from '@maka/runtime/history-compact-ledger';
@@ -224,12 +224,6 @@ export async function createExecutionRuntimeHostComposition(context, options = {
224
224
  resourceLocation: { kind: 'runtime' },
225
225
  })
226
226
  : undefined;
227
- const sandboxDiagnostics = createSandboxDiagnosticsProvider({
228
- ...(sandboxManager ? { sandboxManager } : {}),
229
- ...(filesystemWorkerLaunchSpecProvider
230
- ? { getFilesystemWorkerLaunchSpec: filesystemWorkerLaunchSpecProvider }
231
- : {}),
232
- });
233
227
  const filesystemWorker = sandboxManager && filesystemWorkerLaunchSpecProvider
234
228
  ? new FilesystemWorkerClient({
235
229
  sandboxManager,
@@ -478,7 +472,6 @@ export async function createExecutionRuntimeHostComposition(context, options = {
478
472
  context: backendContext,
479
473
  runtimePolicy: runtimePolicyStores,
480
474
  oauthCredentials,
481
- sandboxDiagnostics,
482
475
  createRunComposer: createInteractiveRunComposerFactory({
483
476
  skills,
484
477
  memory: requireMemory(memory),
@@ -847,7 +840,11 @@ export async function createExecutionRuntimeHostComposition(context, options = {
847
840
  },
848
841
  ...dependencies.oauthAuthorization,
849
842
  });
850
- const usagePricing = new HostUsagePricingCoordinator(openedUsageStores, context.requestDrain, runtimePolicyActivation, registerBackendInvalidation);
843
+ const usagePricing = new HostUsagePricingCoordinator(openedUsageStores, context.requestDrain, runtimePolicyActivation, registerBackendInvalidation,
844
+ // Name the Task column from the durable session header. Reads by id
845
+ // straight from the session store, so it also names reserved-role,
846
+ // coordination, and legacy sessions the filtered catalog omits.
847
+ async (sessionId) => (await stores.sessionStore.readHeaderSnapshot(sessionId)).name);
851
848
  const webSearch = new HostWebSearchCoordinator(webSearchService);
852
849
  const networkProxy = new HostNetworkProxyCoordinator(runtimePolicyStores.operations);
853
850
  const configuration = new HostConfigurationCoordinator(runtimePolicyStores.operations);
@@ -30,7 +30,7 @@ import { createProviderRequestCaptureRecorder } from '@maka/runtime/provider-req
30
30
  import { createProxiedFetchTransport, } from '@maka/runtime/network/scoped-fetch-transport';
31
31
  import { stableHash, toolCatalogHash } from '@maka/runtime/request-shape';
32
32
  import { toolAvailabilityHash } from '@maka/runtime/tool-availability';
33
- import { createAttachmentByteReader, persistProviderRequestCaptureArtifact, } from '@maka/storage/artifact-stores';
33
+ import { createAttachmentByteReader, createReadImageSnapshotPlanner, persistProviderRequestCaptureArtifact, } from '@maka/storage/artifact-stores';
34
34
  import { createReadImageSnapshotReader } from '@maka/storage/read-image-snapshot-store';
35
35
  import { createHostOAuthModelFetch, } from './oauth-execution-authority.js';
36
36
  import { readDuringBackendCreation, resolveExecutionTarget } from './execution-model-authority.js';
@@ -195,9 +195,7 @@ export async function createHostAiSdkBackend(input) {
195
195
  const resolved = await modelComposition.resolveSystemPrompt({
196
196
  sessionId: input.context.sessionId,
197
197
  turnId: context.turnId,
198
- ...(context.runId ? { runId: context.runId } : {}),
199
198
  cwd: input.context.header.cwd,
200
- workspaceRoot: input.context.workspaceRoot,
201
199
  ...(context.emitSkillCatalogTrace
202
200
  ? { emitSkillCatalogTrace: context.emitSkillCatalogTrace }
203
201
  : {}),
@@ -225,6 +223,7 @@ export async function createHostAiSdkBackend(input) {
225
223
  }));
226
224
  }
227
225
  : undefined;
226
+ const planProjectionImage = createReadImageSnapshotPlanner(input.artifacts);
228
227
  try {
229
228
  return new HostAiSdkBackend({
230
229
  sessionId: input.context.sessionId,
@@ -239,7 +238,6 @@ export async function createHostAiSdkBackend(input) {
239
238
  appendMessage: input.context.appendMessage ??
240
239
  ((message) => input.context.store.appendMessage(input.context.sessionId, message)),
241
240
  readExecutionBoundary: () => input.context.store.readExecutionBoundary(input.context.sessionId),
242
- sandboxDiagnostics: input.sandboxDiagnostics,
243
241
  ...(input.context.store.createSandboxBoundaryRequest
244
242
  ? {
245
243
  createSandboxBoundaryRequest: (request) => input.context.store.createSandboxBoundaryRequest(request),
@@ -278,6 +276,13 @@ export async function createHostAiSdkBackend(input) {
278
276
  ? { readImageSnapshotsUnavailable: true }
279
277
  : {}),
280
278
  }),
279
+ prepareDurableProjectionArtifact: ({ turnId, bytes, mediaType }) => planProjectionImage({
280
+ sessionId: input.context.sessionId,
281
+ turnId,
282
+ name: 'Tool Result image',
283
+ bytes,
284
+ mimeType: mediaType,
285
+ }),
281
286
  recordToolArtifacts: input.executionArtifacts.recordToolArtifacts,
282
287
  toolResultArchive: input.executionArtifacts.toolResultArchive,
283
288
  ...(!input.context.tools &&
@@ -307,15 +312,12 @@ export async function createHostAiSdkBackend(input) {
307
312
  systemPrompt: async (context) => {
308
313
  const resolved = await resolveRunPrompt({
309
314
  turnId: context.turnId,
310
- ...(context.runId ? { runId: context.runId } : {}),
311
315
  ...(context.emitSkillCatalogTrace
312
316
  ? { emitSkillCatalogTrace: context.emitSkillCatalogTrace }
313
317
  : {}),
314
318
  });
315
319
  return resolved.text;
316
320
  },
317
- turnTailPrompt: modelComposition.turnTailPrompt,
318
- shellRunContextSummary: input.context.shellRunContextSummary,
319
321
  lookupPricing: pricing,
320
322
  recordModelCallAttempt,
321
323
  assertModelCallAccountingReady,
@@ -308,6 +308,16 @@ export class RuntimeHostKernel {
308
308
  compositionRevision: this.compositionDescriptor.revision,
309
309
  };
310
310
  }
311
+ const initialClientAdmission = this.#options.initialClientAdmission;
312
+ if (initialClientAdmission &&
313
+ !initialClientAdmission.isClientAdmitted(hello.clientInstanceId)) {
314
+ return {
315
+ kind: 'draining',
316
+ hostEpoch: this.hostEpoch,
317
+ compositionId: this.compositionDescriptor.id,
318
+ compositionRevision: this.compositionDescriptor.revision,
319
+ };
320
+ }
311
321
  if (authority.clientInstanceId && authority.clientInstanceId !== hello.clientInstanceId) {
312
322
  throw new Error('Runtime Host access credential belongs to another Client');
313
323
  }