@moxt-ai/mobius 0.0.43 → 0.0.45

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 (35) hide show
  1. package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
  2. package/dist/agent-catalog/publish-agent-catalog.js +1 -0
  3. package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
  4. package/dist/artifacts/runtime-artifact-uploader.d.ts.map +1 -1
  5. package/dist/artifacts/runtime-artifact-uploader.js +10 -17
  6. package/dist/artifacts/runtime-artifact-uploader.js.map +1 -1
  7. package/dist/bots/bot-context-applicator.d.ts +3 -3
  8. package/dist/bots/bot-context-applicator.d.ts.map +1 -1
  9. package/dist/bots/bot-context-applicator.js +7 -7
  10. package/dist/bots/bot-context-applicator.js.map +1 -1
  11. package/dist/bots/bot-execution-context.js +1 -1
  12. package/dist/bots/bot-execution-context.js.map +1 -1
  13. package/dist/bots/bot-outbound-ipc.js +1 -1
  14. package/dist/bots/bot-outbound-ipc.js.map +1 -1
  15. package/dist/bots/local-bot-execution-authorizer.d.ts +23 -0
  16. package/dist/bots/local-bot-execution-authorizer.d.ts.map +1 -0
  17. package/dist/bots/local-bot-execution-authorizer.js +62 -0
  18. package/dist/bots/local-bot-execution-authorizer.js.map +1 -0
  19. package/dist/cli.js +229 -851
  20. package/dist/cli.js.map +4 -4
  21. package/dist/index.js +233 -855
  22. package/dist/index.js.map +4 -4
  23. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  24. package/dist/pairing/pair-local-machine.js +1 -0
  25. package/dist/pairing/pair-local-machine.js.map +1 -1
  26. package/dist/run-daemon.d.ts.map +1 -1
  27. package/dist/run-daemon.js +139 -87
  28. package/dist/run-daemon.js.map +1 -1
  29. package/dist/runtime.js +230 -852
  30. package/dist/runtime.js.map +4 -4
  31. package/package.json +1 -1
  32. package/dist/bots/local-bot-grant-store.d.ts +0 -36
  33. package/dist/bots/local-bot-grant-store.d.ts.map +0 -1
  34. package/dist/bots/local-bot-grant-store.js +0 -398
  35. package/dist/bots/local-bot-grant-store.js.map +0 -1
package/dist/cli.js CHANGED
@@ -11,7 +11,7 @@ import { mkdir as mkdir5 } from "node:fs/promises";
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "@moxt-ai/mobius",
14
- version: "0.0.43",
14
+ version: "0.0.45",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -21138,6 +21138,7 @@ function decodeMessageKind(encoded) {
21138
21138
  }
21139
21139
  function decodeSessionPromptCommand(encoded) {
21140
21140
  const value = parseJson2(encoded);
21141
+ const hasSessionConfigurations = Object.hasOwn(value, "sessionConfigurations");
21141
21142
  assertExactKeys(value, [
21142
21143
  "additionalDirectoryIds",
21143
21144
  "agentId",
@@ -21149,6 +21150,7 @@ function decodeSessionPromptCommand(encoded) {
21149
21150
  "kind",
21150
21151
  "prompt",
21151
21152
  "resources",
21153
+ ...hasSessionConfigurations ? ["sessionConfigurations"] : [],
21152
21154
  "sessionId",
21153
21155
  "targetCommandId"
21154
21156
  ]);
@@ -21169,6 +21171,10 @@ function decodeSessionPromptCommand(encoded) {
21169
21171
  if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN2.test(targetCommandId)) {
21170
21172
  throw new ProtocolMessageError("Prompt disposition has an invalid target command");
21171
21173
  }
21174
+ const sessionConfigurations = hasSessionConfigurations ? decodeSessionConfigurationSelections(value["sessionConfigurations"]) : [];
21175
+ if (new Set(sessionConfigurations.map((selection) => selection.configId)).size !== sessionConfigurations.length) {
21176
+ throw new ProtocolMessageError("Session configuration identifiers must be unique");
21177
+ }
21172
21178
  return {
21173
21179
  additionalDirectoryIds: readDirectoryIdentifiers(value, "additionalDirectoryIds", 16),
21174
21180
  agentId: readIdentifier(value, "agentId"),
@@ -21180,6 +21186,7 @@ function decodeSessionPromptCommand(encoded) {
21180
21186
  kind: SESSION_PROMPT_KIND,
21181
21187
  prompt,
21182
21188
  resources,
21189
+ ...hasSessionConfigurations ? { sessionConfigurations } : {},
21183
21190
  sessionId: readIdentifier(value, "sessionId"),
21184
21191
  targetCommandId
21185
21192
  };
@@ -21356,9 +21363,6 @@ function encodeSessionFailedEvent(message) {
21356
21363
  }
21357
21364
 
21358
21365
  // ../protocol/src/bot.ts
21359
- var BOT_BINDING_APPROVAL_REQUEST_KIND = "bot.binding.approval.request";
21360
- var BOT_BINDING_APPROVED_KIND = "bot.binding.approved";
21361
- var BOT_BINDING_UNAVAILABLE_KIND = "bot.binding.unavailable";
21362
21366
  var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
21363
21367
  var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
21364
21368
  var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
@@ -21373,21 +21377,6 @@ var BotDeliveryTargetReference = class {
21373
21377
  this.deliveryTargetId = deliveryTargetId;
21374
21378
  }
21375
21379
  };
21376
- var BotCompletionDeliveryPolicy = class {
21377
- };
21378
- var NoBotCompletionDeliveryPolicy = class extends BotCompletionDeliveryPolicy {
21379
- kind = "none";
21380
- };
21381
- var RequiredBotCompletionDeliveryPolicy = class extends BotCompletionDeliveryPolicy {
21382
- deliveryTargetId;
21383
- kind = "required";
21384
- messageTemplate;
21385
- constructor(deliveryTargetId, messageTemplate) {
21386
- super();
21387
- this.deliveryTargetId = deliveryTargetId;
21388
- this.messageTemplate = messageTemplate;
21389
- }
21390
- };
21391
21380
  var BotReplyRoute = class {
21392
21381
  };
21393
21382
  var OwnerBotReplyRoute = class extends BotReplyRoute {
@@ -21403,94 +21392,6 @@ var BotConnectionReplyRoute = class extends BotReplyRoute {
21403
21392
  this.deliveryTargetId = deliveryTargetId;
21404
21393
  }
21405
21394
  };
21406
- var BotExecutionBindingApprovalRequest = class {
21407
- agentConfigRevision;
21408
- agentRef;
21409
- allowedDeliveryTargets;
21410
- behaviorDigest;
21411
- behaviorInstructions;
21412
- behaviorRevisionId;
21413
- bindingId;
21414
- bindingRevision;
21415
- botId;
21416
- completionPolicy;
21417
- executionConfiguration;
21418
- kind = BOT_BINDING_APPROVAL_REQUEST_KIND;
21419
- requestId;
21420
- requiredCapabilities;
21421
- runtimeId;
21422
- sessionConfigurations;
21423
- workspaceRef;
21424
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, runtimeId, agentRef, workspaceRef, agentConfigRevision, behaviorInstructions, behaviorDigest, requiredCapabilities, allowedDeliveryTargets, completionPolicy, executionConfiguration, sessionConfigurations = []) {
21425
- this.requestId = requestId;
21426
- this.botId = botId;
21427
- this.behaviorRevisionId = behaviorRevisionId;
21428
- this.bindingId = bindingId;
21429
- this.bindingRevision = bindingRevision;
21430
- this.runtimeId = runtimeId;
21431
- this.agentRef = agentRef;
21432
- this.workspaceRef = workspaceRef;
21433
- this.agentConfigRevision = agentConfigRevision;
21434
- this.behaviorInstructions = behaviorInstructions;
21435
- this.behaviorDigest = behaviorDigest;
21436
- this.requiredCapabilities = Object.freeze([...requiredCapabilities]);
21437
- this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
21438
- this.allowedDeliveryTargets = Object.freeze(
21439
- allowedDeliveryTargets.map(
21440
- (target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
21441
- )
21442
- );
21443
- this.completionPolicy = completionPolicy;
21444
- this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
21445
- }
21446
- toJSON() {
21447
- const { sessionConfigurations, ...request } = this;
21448
- return {
21449
- ...request,
21450
- ...sessionConfigurations.length === 0 ? {} : { sessionConfigurations }
21451
- };
21452
- }
21453
- };
21454
- var BotExecutionBindingApprovedEvent = class {
21455
- agentIdentityDigest;
21456
- behaviorRevisionId;
21457
- bindingId;
21458
- bindingRevision;
21459
- botId;
21460
- kind = BOT_BINDING_APPROVED_KIND;
21461
- localGrantId;
21462
- requestId;
21463
- workspaceIdentityDigest;
21464
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, localGrantId, agentIdentityDigest, workspaceIdentityDigest) {
21465
- this.requestId = requestId;
21466
- this.botId = botId;
21467
- this.behaviorRevisionId = behaviorRevisionId;
21468
- this.bindingId = bindingId;
21469
- this.bindingRevision = bindingRevision;
21470
- this.localGrantId = localGrantId;
21471
- this.agentIdentityDigest = agentIdentityDigest;
21472
- this.workspaceIdentityDigest = workspaceIdentityDigest;
21473
- }
21474
- };
21475
- var BotExecutionBindingUnavailableEvent = class {
21476
- behaviorRevisionId;
21477
- bindingId;
21478
- bindingRevision;
21479
- botId;
21480
- code;
21481
- kind = BOT_BINDING_UNAVAILABLE_KIND;
21482
- message;
21483
- requestId;
21484
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, code, message) {
21485
- this.requestId = requestId;
21486
- this.botId = botId;
21487
- this.behaviorRevisionId = behaviorRevisionId;
21488
- this.bindingId = bindingId;
21489
- this.bindingRevision = bindingRevision;
21490
- this.code = code;
21491
- this.message = message;
21492
- }
21493
- };
21494
21395
  var BotSessionPromptCommand = class {
21495
21396
  additionalDirectoryIds;
21496
21397
  agentId;
@@ -21512,7 +21413,6 @@ var BotSessionPromptCommand = class {
21512
21413
  executionConfiguration;
21513
21414
  images;
21514
21415
  kind = BOT_SESSION_PROMPT_KIND;
21515
- localGrantId;
21516
21416
  prompt;
21517
21417
  replyRoute;
21518
21418
  resources;
@@ -21520,7 +21420,7 @@ var BotSessionPromptCommand = class {
21520
21420
  sessionId;
21521
21421
  targetCommandId;
21522
21422
  turnId;
21523
- constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, localGrantId, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute, executionConfiguration, sessionConfigurations = [], disposition = SessionPromptDisposition.Reject, targetCommandId = "") {
21423
+ constructor(sessionId, commandId, agentId, bindingId, directoryId2, additionalDirectoryIds, images, resources, prompt, executionId, executionCapabilityId, executionCapabilitySecret, executionDeadlineAt, botId, conversationId, turnId, behaviorRevisionId, bindingRevision, behaviorInstructions, behaviorDigest, allowedDeliveryTargets, replyRoute, executionConfiguration, sessionConfigurations = [], disposition = SessionPromptDisposition.Reject, targetCommandId = "") {
21524
21424
  this.sessionId = sessionId;
21525
21425
  this.commandId = commandId;
21526
21426
  this.agentId = agentId;
@@ -21540,7 +21440,6 @@ var BotSessionPromptCommand = class {
21540
21440
  this.turnId = turnId;
21541
21441
  this.behaviorRevisionId = behaviorRevisionId;
21542
21442
  this.bindingRevision = bindingRevision;
21543
- this.localGrantId = localGrantId;
21544
21443
  this.behaviorInstructions = behaviorInstructions;
21545
21444
  this.behaviorDigest = behaviorDigest;
21546
21445
  this.allowedDeliveryTargets = Object.freeze(
@@ -21684,24 +21583,6 @@ function readSessionConfigurations(value) {
21684
21583
  }
21685
21584
  return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
21686
21585
  }
21687
- function readCompletionPolicy(value) {
21688
- if (!isRecord3(value)) {
21689
- throw new ProtocolMessageError("Invalid Bot completion policy");
21690
- }
21691
- const kind = readText2(value, "kind", 32, false);
21692
- if (kind === "none") {
21693
- assertExactKeys2(value, ["kind"]);
21694
- return new NoBotCompletionDeliveryPolicy();
21695
- }
21696
- if (kind === "required") {
21697
- assertExactKeys2(value, ["deliveryTargetId", "kind", "messageTemplate"]);
21698
- return new RequiredBotCompletionDeliveryPolicy(
21699
- readIdentifier2(value, "deliveryTargetId"),
21700
- readText2(value, "messageTemplate", 1e4, false)
21701
- );
21702
- }
21703
- throw new ProtocolMessageError("Invalid Bot completion policy");
21704
- }
21705
21586
  function readReplyRoute(value) {
21706
21587
  if (!isRecord3(value)) {
21707
21588
  throw new ProtocolMessageError("Invalid Bot reply route");
@@ -21720,110 +21601,6 @@ function readReplyRoute(value) {
21720
21601
  }
21721
21602
  throw new ProtocolMessageError("Invalid Bot reply route");
21722
21603
  }
21723
- function decodeBotExecutionBindingApprovalRequest(encoded) {
21724
- const value = parseJson3(encoded);
21725
- assertKeysWithOptional(
21726
- value,
21727
- [
21728
- "agentConfigRevision",
21729
- "agentRef",
21730
- "allowedDeliveryTargets",
21731
- "behaviorDigest",
21732
- "behaviorInstructions",
21733
- "behaviorRevisionId",
21734
- "bindingId",
21735
- "bindingRevision",
21736
- "botId",
21737
- "completionPolicy",
21738
- "executionConfiguration",
21739
- "kind",
21740
- "requestId",
21741
- "requiredCapabilities",
21742
- "runtimeId",
21743
- "workspaceRef"
21744
- ],
21745
- ["sessionConfigurations"]
21746
- );
21747
- if (value["kind"] !== BOT_BINDING_APPROVAL_REQUEST_KIND) {
21748
- throw new ProtocolMessageError("Invalid Bot binding approval request kind");
21749
- }
21750
- return new BotExecutionBindingApprovalRequest(
21751
- readIdentifier2(value, "requestId"),
21752
- readIdentifier2(value, "botId"),
21753
- readIdentifier2(value, "behaviorRevisionId"),
21754
- readIdentifier2(value, "bindingId"),
21755
- readInteger(value, "bindingRevision"),
21756
- readIdentifier2(value, "runtimeId"),
21757
- readIdentifier2(value, "agentRef"),
21758
- readDirectoryIdentifier2(value, "workspaceRef"),
21759
- readInteger(value, "agentConfigRevision"),
21760
- readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21761
- readDigest(value, "behaviorDigest"),
21762
- readIdentifiers(value, "requiredCapabilities", 32),
21763
- readTargets(value, "allowedDeliveryTargets"),
21764
- readCompletionPolicy(value["completionPolicy"]),
21765
- decodeAgentExecutionConfiguration(value["executionConfiguration"]),
21766
- readSessionConfigurations(value)
21767
- );
21768
- }
21769
- function decodeBotExecutionBindingApprovedEvent(encoded) {
21770
- const value = parseJson3(encoded);
21771
- assertExactKeys2(value, [
21772
- "agentIdentityDigest",
21773
- "behaviorRevisionId",
21774
- "bindingId",
21775
- "bindingRevision",
21776
- "botId",
21777
- "kind",
21778
- "localGrantId",
21779
- "requestId",
21780
- "workspaceIdentityDigest"
21781
- ]);
21782
- if (value["kind"] !== BOT_BINDING_APPROVED_KIND) {
21783
- throw new ProtocolMessageError("Invalid Bot binding approval event kind");
21784
- }
21785
- return new BotExecutionBindingApprovedEvent(
21786
- readIdentifier2(value, "requestId"),
21787
- readIdentifier2(value, "botId"),
21788
- readIdentifier2(value, "behaviorRevisionId"),
21789
- readIdentifier2(value, "bindingId"),
21790
- readInteger(value, "bindingRevision"),
21791
- readIdentifier2(value, "localGrantId"),
21792
- readDigest(value, "agentIdentityDigest"),
21793
- readDigest(value, "workspaceIdentityDigest")
21794
- );
21795
- }
21796
- function encodeBotExecutionBindingApprovedEvent(event) {
21797
- return JSON.stringify(decodeBotExecutionBindingApprovedEvent(JSON.stringify(event)));
21798
- }
21799
- function decodeBotExecutionBindingUnavailableEvent(encoded) {
21800
- const value = parseJson3(encoded);
21801
- assertExactKeys2(value, [
21802
- "behaviorRevisionId",
21803
- "bindingId",
21804
- "bindingRevision",
21805
- "botId",
21806
- "code",
21807
- "kind",
21808
- "message",
21809
- "requestId"
21810
- ]);
21811
- if (value["kind"] !== BOT_BINDING_UNAVAILABLE_KIND) {
21812
- throw new ProtocolMessageError("Invalid Bot binding unavailable event kind");
21813
- }
21814
- return new BotExecutionBindingUnavailableEvent(
21815
- readIdentifier2(value, "requestId"),
21816
- readIdentifier2(value, "botId"),
21817
- readIdentifier2(value, "behaviorRevisionId"),
21818
- readIdentifier2(value, "bindingId"),
21819
- readInteger(value, "bindingRevision"),
21820
- readIdentifier2(value, "code"),
21821
- readText2(value, "message", 500, false)
21822
- );
21823
- }
21824
- function encodeBotExecutionBindingUnavailableEvent(event) {
21825
- return JSON.stringify(decodeBotExecutionBindingUnavailableEvent(JSON.stringify(event)));
21826
- }
21827
21604
  function decodeBotSessionPromptCommand(encoded) {
21828
21605
  const value = parseJson3(encoded);
21829
21606
  assertKeysWithOptional(
@@ -21848,7 +21625,6 @@ function decodeBotSessionPromptCommand(encoded) {
21848
21625
  "executionConfiguration",
21849
21626
  "images",
21850
21627
  "kind",
21851
- "localGrantId",
21852
21628
  "prompt",
21853
21629
  "replyRoute",
21854
21630
  "resources",
@@ -21894,7 +21670,6 @@ function decodeBotSessionPromptCommand(encoded) {
21894
21670
  readIdentifier2(value, "turnId"),
21895
21671
  readIdentifier2(value, "behaviorRevisionId"),
21896
21672
  readInteger(value, "bindingRevision"),
21897
- readIdentifier2(value, "localGrantId"),
21898
21673
  readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21899
21674
  readDigest(value, "behaviorDigest"),
21900
21675
  readTargets(value, "allowedDeliveryTargets"),
@@ -23677,7 +23452,7 @@ function isContainedPath3(root, candidate) {
23677
23452
  }
23678
23453
  async function hashFile(path2, signal) {
23679
23454
  signal.throwIfAborted();
23680
- const digest2 = createHash("sha256");
23455
+ const digest = createHash("sha256");
23681
23456
  const stream = createReadStream(path2, { signal });
23682
23457
  try {
23683
23458
  for await (const chunk of stream) {
@@ -23688,9 +23463,9 @@ async function hashFile(path2, signal) {
23688
23463
  "The managed Agent archive produced invalid bytes"
23689
23464
  );
23690
23465
  }
23691
- digest2.update(chunk);
23466
+ digest.update(chunk);
23692
23467
  }
23693
- return digest2.digest("hex");
23468
+ return digest.digest("hex");
23694
23469
  } catch (error62) {
23695
23470
  if (signal.aborted) {
23696
23471
  signal.throwIfAborted();
@@ -24990,7 +24765,8 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
24990
24765
  botSessionConfiguration: true,
24991
24766
  capabilities: agent.capabilities,
24992
24767
  id: agent.id,
24993
- label: agent.label
24768
+ label: agent.label,
24769
+ sessionTurnConfiguration: true
24994
24770
  }));
24995
24771
  const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
24996
24772
  let response;
@@ -25207,7 +24983,7 @@ var AuditStore = class {
25207
24983
  };
25208
24984
 
25209
24985
  // src/run-daemon.ts
25210
- import { randomUUID as randomUUID6 } from "node:crypto";
24986
+ import { randomUUID as randomUUID5 } from "node:crypto";
25211
24987
  import { basename as basename6, join as join17 } from "node:path";
25212
24988
  import { styleText } from "node:util";
25213
24989
  import { fetch as fetch7, WebSocket as WebSocket2 } from "undici";
@@ -36894,7 +36670,8 @@ async function publishAgentCatalog(config2, signal) {
36894
36670
  botSessionConfiguration: true,
36895
36671
  capabilities: agent.capabilities,
36896
36672
  id: agent.id,
36897
- label: agent.label
36673
+ label: agent.label,
36674
+ sessionTurnConfiguration: true
36898
36675
  })),
36899
36676
  installableAgents: catalog.installableAgents
36900
36677
  }),
@@ -37620,13 +37397,6 @@ var UploadedRuntimeArtifact = class {
37620
37397
  this.sha256 = sha256;
37621
37398
  }
37622
37399
  };
37623
- function daemonToken(config2) {
37624
- const token = config2.relayUrl.searchParams.get("token");
37625
- if (token === null || token.length < 32) {
37626
- throw new RuntimeArtifactUploadError("artifact_endpoint_invalid", "The Relay daemon token is missing");
37627
- }
37628
- return token;
37629
- }
37630
37400
  function channelOrigin(config2) {
37631
37401
  const url2 = new URL(config2.relayUrl);
37632
37402
  url2.protocol = url2.protocol === "wss:" ? "https:" : "http:";
@@ -37671,24 +37441,23 @@ async function readAuthorization(response) {
37671
37441
  translateSdkError(cause);
37672
37442
  }
37673
37443
  }
37674
- function sessionArtifactUrl(origin, sessionId, resourcePath, token) {
37675
- const url2 = new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
37676
- url2.searchParams.set("token", token);
37677
- return url2;
37444
+ function sessionArtifactUrl(origin, sessionId, resourcePath) {
37445
+ return new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
37678
37446
  }
37679
- async function postLease(url2, request, signal) {
37447
+ async function postLease(url2, headers, request, signal) {
37680
37448
  return await fetch4(url2, {
37681
37449
  dispatcher: environmentProxyDispatcher,
37682
- headers: { "content-type": "application/json" },
37450
+ headers: { ...headers, "content-type": "application/json" },
37683
37451
  method: "POST",
37684
37452
  body: JSON.stringify(request),
37685
37453
  signal
37686
37454
  });
37687
37455
  }
37688
- async function putContent(url2, authorization, bytes, signal) {
37456
+ async function putContent(url2, headers, authorization, bytes, signal) {
37689
37457
  return await fetch4(url2, {
37690
37458
  dispatcher: environmentProxyDispatcher,
37691
37459
  headers: {
37460
+ ...headers,
37692
37461
  "content-type": authorization.mediaType,
37693
37462
  "x-mobius-upload-token": authorization.uploadToken
37694
37463
  },
@@ -37713,11 +37482,12 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
37713
37482
  const timeoutSignal = AbortSignal.timeout(UPLOAD_TIMEOUT_MILLISECONDS);
37714
37483
  const requestSignal = AbortSignal.any([signal, timeoutSignal]);
37715
37484
  const origin = channelOrigin(config2);
37716
- const token = daemonToken(config2);
37485
+ const headers = runtimeAuthorization(config2.relayUrl);
37717
37486
  let created;
37718
37487
  try {
37719
37488
  created = await postLease(
37720
- sessionArtifactUrl(origin, sessionId, "artifacts/uploads", token),
37489
+ sessionArtifactUrl(origin, sessionId, "artifacts/uploads"),
37490
+ headers,
37721
37491
  request,
37722
37492
  requestSignal
37723
37493
  );
@@ -37737,12 +37507,8 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
37737
37507
  let uploaded;
37738
37508
  try {
37739
37509
  uploaded = await putContent(
37740
- sessionArtifactUrl(
37741
- origin,
37742
- sessionId,
37743
- `artifacts/${encodeURIComponent(authorization.artifactId)}/content`,
37744
- token
37745
- ),
37510
+ sessionArtifactUrl(origin, sessionId, `artifacts/${encodeURIComponent(authorization.artifactId)}/content`),
37511
+ headers,
37746
37512
  authorization,
37747
37513
  artifact.bytes,
37748
37514
  requestSignal
@@ -37933,10 +37699,7 @@ var WorkspaceDirectoryService = class {
37933
37699
  };
37934
37700
  };
37935
37701
 
37936
- // src/bots/local-bot-grant-store.ts
37937
- import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
37938
- import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
37939
- var LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS = 90 * 24 * 60 * 60 * 1e3;
37702
+ // src/bots/local-bot-execution-authorizer.ts
37940
37703
  var LocalBotAuthorizationError = class extends Error {
37941
37704
  code;
37942
37705
  constructor(code, message, options = {}) {
@@ -37945,325 +37708,40 @@ var LocalBotAuthorizationError = class extends Error {
37945
37708
  this.name = "LocalBotAuthorizationError";
37946
37709
  }
37947
37710
  };
37948
- var LocalBotGrant = class {
37711
+ var AuthorizedLocalBotExecution = class {
37949
37712
  agent;
37950
- agentIdentityDigest;
37951
- allowedDeliveryTargetIds;
37952
37713
  behaviorDigest;
37953
37714
  behaviorRevisionId;
37954
37715
  bindingId;
37955
37716
  bindingRevision;
37956
37717
  botId;
37957
- expiresAt;
37958
37718
  executionConfiguration;
37959
- localGrantId;
37960
- revocationEpoch;
37961
- workspaceIdentityDigest;
37962
37719
  workspacePath;
37963
37720
  workspaceRef;
37964
- constructor(localGrantId, botId, behaviorRevisionId, behaviorDigest, bindingId, bindingRevision, agent, agentIdentityDigest, workspaceRef, workspacePath, workspaceIdentityDigest, allowedDeliveryTargetIds, executionConfiguration, expiresAt, revocationEpoch) {
37965
- this.localGrantId = localGrantId;
37966
- this.botId = botId;
37967
- this.behaviorRevisionId = behaviorRevisionId;
37968
- this.behaviorDigest = behaviorDigest;
37969
- this.bindingId = bindingId;
37970
- this.bindingRevision = bindingRevision;
37721
+ constructor(command, agent, workspacePath) {
37971
37722
  this.agent = agent;
37972
- this.agentIdentityDigest = agentIdentityDigest;
37973
- this.workspaceRef = workspaceRef;
37723
+ this.behaviorDigest = command.behaviorDigest;
37724
+ this.behaviorRevisionId = command.behaviorRevisionId;
37725
+ this.bindingId = command.bindingId;
37726
+ this.bindingRevision = command.bindingRevision;
37727
+ this.botId = command.botId;
37728
+ this.executionConfiguration = command.executionConfiguration;
37974
37729
  this.workspacePath = workspacePath;
37975
- this.workspaceIdentityDigest = workspaceIdentityDigest;
37976
- this.allowedDeliveryTargetIds = Object.freeze([...allowedDeliveryTargetIds]);
37977
- this.executionConfiguration = executionConfiguration;
37978
- this.expiresAt = expiresAt;
37979
- this.revocationEpoch = revocationEpoch;
37730
+ this.workspaceRef = command.directoryId;
37980
37731
  }
37981
37732
  };
37982
- function digest(value) {
37983
- return createHash3("sha256").update(value, "utf8").digest("hex");
37984
- }
37985
- function agentDigest(agent) {
37986
- return digest(
37987
- JSON.stringify({
37988
- adapter: agent.adapterIdentity,
37989
- agent: agent.agentIdentity,
37990
- agentVersion: agent.agentVersion,
37991
- arguments: agent.arguments,
37992
- id: agent.id
37993
- })
37994
- );
37995
- }
37996
- function configurePermission(agent, permissionMode) {
37997
- try {
37998
- return agent.withPermissionMode(permissionMode);
37999
- } catch (cause) {
38000
- if (cause instanceof AgentPermissionConfigurationError) {
38001
- throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
38002
- }
38003
- throw cause;
38004
- }
38005
- }
38006
- function workspaceDigest(path2) {
38007
- return digest(path2);
38008
- }
38009
- function exactTargets(left, right) {
38010
- if (left.length !== right.length) {
38011
- return false;
38012
- }
38013
- const expected = [...left].sort();
38014
- const actual = [...right].sort();
38015
- return expected.every((target, index2) => target === actual[index2]);
38016
- }
38017
- function exactSessionConfigurations(left, right) {
38018
- if (left.length !== right.length) {
38019
- return false;
38020
- }
38021
- const expected = new Map(left.map((selection) => [selection.configId, selection]));
38022
- return right.every((selection) => {
38023
- const approved = expected.get(selection.configId);
38024
- return approved !== void 0 && approved.booleanValue === selection.booleanValue && approved.value === selection.value && approved.valueType === selection.valueType;
38025
- });
38026
- }
38027
- function exactExecutionConfiguration(left, right) {
38028
- return left.permissionMode === right.permissionMode && exactSessionConfigurations([left.model, left.reasoningEffort], [right.model, right.reasoningEffort]);
38029
- }
38030
- function rowString(row, key) {
38031
- const value = Reflect.get(row, key);
38032
- if (typeof value !== "string") {
38033
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
38034
- }
38035
- return value;
38036
- }
38037
- function rowInteger(row, key) {
38038
- const value = Reflect.get(row, key);
38039
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
38040
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
38041
- }
38042
- return value;
38043
- }
38044
- function rowHasInteger(row, key) {
38045
- const value = Reflect.get(row, key);
38046
- if (value === null) {
38047
- return false;
38048
- }
38049
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
38050
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
38051
- }
38052
- return true;
38053
- }
38054
- function parseTargets(encoded) {
38055
- let value;
38056
- try {
38057
- value = JSON.parse(encoded);
38058
- } catch (cause) {
38059
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
38060
- }
38061
- if (!Array.isArray(value) || value.some((target) => typeof target !== "string")) {
38062
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
38063
- }
38064
- return value.filter((target) => typeof target === "string");
38065
- }
38066
- function parseSessionConfigurations(encoded) {
38067
- let value;
38068
- try {
38069
- value = JSON.parse(encoded);
38070
- return decodeSessionConfigurationSelections(value);
38071
- } catch (cause) {
38072
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
38073
- }
38074
- }
38075
- function parseExecutionConfiguration(encoded) {
38076
- let value;
38077
- try {
38078
- value = JSON.parse(encoded);
38079
- return decodeAgentExecutionConfiguration(value);
38080
- } catch (cause) {
38081
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
38082
- }
38083
- }
38084
- var LocalBotGrantStore = class {
38085
- #database;
38086
- constructor(path2) {
38087
- this.#database = new DatabaseSync3(path2);
38088
- this.#database.exec(`
38089
- CREATE TABLE IF NOT EXISTS local_bot_grants (
38090
- local_grant_id TEXT PRIMARY KEY,
38091
- bot_id TEXT NOT NULL,
38092
- behavior_revision_id TEXT NOT NULL,
38093
- behavior_digest TEXT NOT NULL,
38094
- binding_id TEXT NOT NULL UNIQUE,
38095
- binding_revision INTEGER NOT NULL,
38096
- agent_ref TEXT NOT NULL,
38097
- agent_identity_digest TEXT NOT NULL,
38098
- workspace_ref TEXT NOT NULL,
38099
- workspace_path TEXT NOT NULL,
38100
- workspace_identity_digest TEXT NOT NULL,
38101
- allowed_delivery_target_ids_json TEXT NOT NULL,
38102
- unattended_policy_json TEXT NOT NULL,
38103
- created_at INTEGER NOT NULL,
38104
- expires_at INTEGER NOT NULL,
38105
- revocation_epoch INTEGER NOT NULL DEFAULT 0,
38106
- revoked_at INTEGER
38107
- ) STRICT;
38108
- CREATE TABLE IF NOT EXISTS local_bot_binding_resolutions (
38109
- request_id TEXT PRIMARY KEY,
38110
- binding_id TEXT NOT NULL,
38111
- local_grant_id TEXT NOT NULL,
38112
- resolved_at INTEGER NOT NULL,
38113
- result TEXT NOT NULL CHECK (result IN ('approved', 'unavailable')),
38114
- error_code TEXT,
38115
- error_message TEXT
38116
- ) STRICT;
38117
- CREATE TABLE IF NOT EXISTS local_bot_grant_configurations (
38118
- local_grant_id TEXT PRIMARY KEY,
38119
- session_configurations_json TEXT NOT NULL
38120
- ) STRICT;
38121
- CREATE TABLE IF NOT EXISTS local_bot_grant_execution_configurations (
38122
- local_grant_id TEXT PRIMARY KEY,
38123
- execution_configuration_json TEXT NOT NULL
38124
- ) STRICT;
38125
- `);
38126
- }
38127
- approve = async (request, catalog, directories, bindingAuthorityId, now, signal) => {
37733
+ var LocalBotExecutionAuthorizer = class {
37734
+ authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
38128
37735
  signal.throwIfAborted();
38129
- const existing = this.#database.prepare(
38130
- `SELECT grants.* FROM local_bot_binding_resolutions AS resolutions
38131
- INNER JOIN local_bot_grants AS grants
38132
- ON grants.local_grant_id = resolutions.local_grant_id
38133
- WHERE resolutions.request_id = ? AND resolutions.binding_id = ?
38134
- AND resolutions.result = 'approved'`
38135
- ).get(request.requestId, request.bindingId);
38136
- if (existing !== void 0) {
38137
- return new BotExecutionBindingApprovedEvent(
38138
- request.requestId,
38139
- request.botId,
38140
- request.behaviorRevisionId,
38141
- request.bindingId,
38142
- request.bindingRevision,
38143
- rowString(existing, "local_grant_id"),
38144
- rowString(existing, "agent_identity_digest"),
38145
- rowString(existing, "workspace_identity_digest")
38146
- );
38147
- }
38148
- const resolved = await this.resolveProposal(request, catalog, directories, bindingAuthorityId, signal);
38149
- const localGrantId = `lbg_${randomUUID3()}`;
38150
- const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
38151
- this.#database.exec("BEGIN IMMEDIATE");
37736
+ let agent;
38152
37737
  try {
38153
- this.#database.prepare(
38154
- `INSERT INTO local_bot_grants (
38155
- local_grant_id, bot_id, behavior_revision_id, behavior_digest,
38156
- binding_id, binding_revision, agent_ref,
38157
- agent_identity_digest, workspace_ref, workspace_path,
38158
- workspace_identity_digest, allowed_delivery_target_ids_json,
38159
- unattended_policy_json, created_at, expires_at
38160
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
38161
- ).run(
38162
- localGrantId,
38163
- request.botId,
38164
- request.behaviorRevisionId,
38165
- request.behaviorDigest,
38166
- request.bindingId,
38167
- request.bindingRevision,
38168
- request.agentRef,
38169
- resolved.agentIdentityDigest,
38170
- request.workspaceRef,
38171
- resolved.workspacePath,
38172
- resolved.workspaceIdentityDigest,
38173
- JSON.stringify(request.allowedDeliveryTargets.map((target) => target.deliveryTargetId)),
38174
- JSON.stringify({ localSideEffects: "owner-approval-required" }),
38175
- now,
38176
- expiresAt
38177
- );
38178
- this.#database.prepare(
38179
- `INSERT INTO local_bot_grant_configurations (
38180
- local_grant_id, session_configurations_json
38181
- ) VALUES (?, ?)`
38182
- ).run(localGrantId, JSON.stringify(request.sessionConfigurations));
38183
- this.#database.prepare(
38184
- `INSERT INTO local_bot_grant_execution_configurations (
38185
- local_grant_id, execution_configuration_json
38186
- ) VALUES (?, ?)`
38187
- ).run(localGrantId, JSON.stringify(request.executionConfiguration));
38188
- this.#database.prepare(
38189
- `INSERT INTO local_bot_binding_resolutions (
38190
- request_id, binding_id, local_grant_id, resolved_at, result
38191
- ) VALUES (?, ?, ?, ?, 'approved')`
38192
- ).run(request.requestId, request.bindingId, localGrantId, now);
38193
- this.#database.exec("COMMIT");
37738
+ agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
38194
37739
  } catch (cause) {
38195
- this.#database.exec("ROLLBACK");
37740
+ if (cause instanceof AgentPermissionConfigurationError) {
37741
+ throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
37742
+ }
38196
37743
  throw cause;
38197
37744
  }
38198
- signal.throwIfAborted();
38199
- return new BotExecutionBindingApprovedEvent(
38200
- request.requestId,
38201
- request.botId,
38202
- request.behaviorRevisionId,
38203
- request.bindingId,
38204
- request.bindingRevision,
38205
- localGrantId,
38206
- resolved.agentIdentityDigest,
38207
- resolved.workspaceIdentityDigest
38208
- );
38209
- };
38210
- resolveExecution = async (command, catalog, directories, bindingAuthorityId, now, signal) => {
38211
- signal.throwIfAborted();
38212
- const row = this.#database.prepare(
38213
- `SELECT grants.*, COALESCE(configurations.session_configurations_json, '[]')
38214
- AS session_configurations_json,
38215
- COALESCE(execution.execution_configuration_json, ?)
38216
- AS execution_configuration_json
38217
- FROM local_bot_grants AS grants
38218
- LEFT JOIN local_bot_grant_configurations AS configurations
38219
- ON configurations.local_grant_id = grants.local_grant_id
38220
- LEFT JOIN local_bot_grant_execution_configurations AS execution
38221
- ON execution.local_grant_id = grants.local_grant_id
38222
- WHERE grants.local_grant_id = ? AND grants.bot_id = ?
38223
- AND behavior_revision_id = ? AND behavior_digest = ?
38224
- AND binding_id = ? AND binding_revision = ?
38225
- AND agent_ref = ?`
38226
- ).get(
38227
- JSON.stringify(DEFAULT_AGENT_EXECUTION_CONFIGURATION),
38228
- command.localGrantId,
38229
- command.botId,
38230
- command.behaviorRevisionId,
38231
- command.behaviorDigest,
38232
- command.bindingId,
38233
- command.bindingRevision,
38234
- command.agentId
38235
- );
38236
- if (row === void 0) {
38237
- throw new LocalBotAuthorizationError(
38238
- "binding_not_approved",
38239
- "The Bot execution binding is not locally approved"
38240
- );
38241
- }
38242
- const approvedTargets = parseTargets(rowString(row, "allowed_delivery_target_ids_json"));
38243
- const requestedTargets = command.allowedDeliveryTargets.map((target) => target.deliveryTargetId);
38244
- if (!exactTargets(approvedTargets, requestedTargets)) {
38245
- throw new LocalBotAuthorizationError(
38246
- "binding_not_approved",
38247
- "The Bot execution target policy differs from its binding"
38248
- );
38249
- }
38250
- const approvedConfigurations = parseSessionConfigurations(rowString(row, "session_configurations_json"));
38251
- if (!exactSessionConfigurations(approvedConfigurations, command.sessionConfigurations)) {
38252
- throw new LocalBotAuthorizationError(
38253
- "binding_not_approved",
38254
- "The Bot Agent configuration differs from its binding"
38255
- );
38256
- }
38257
- const approvedExecutionConfiguration = parseExecutionConfiguration(
38258
- rowString(row, "execution_configuration_json")
38259
- );
38260
- if (!exactExecutionConfiguration(approvedExecutionConfiguration, command.executionConfiguration)) {
38261
- throw new LocalBotAuthorizationError(
38262
- "binding_not_approved",
38263
- "The Bot execution configuration differs from its binding"
38264
- );
38265
- }
38266
- const agent = configurePermission(catalog.find(command.agentId), command.executionConfiguration.permissionMode);
38267
37745
  const [adapterUnchanged, agentUnchanged] = await Promise.all([
38268
37746
  revalidateExecutable(agent.adapterIdentity),
38269
37747
  revalidateExecutable(agent.agentIdentity)
@@ -38275,150 +37753,15 @@ var LocalBotGrantStore = class {
38275
37753
  "The local Agent executable changed while the Runtime is active; restart the Runtime"
38276
37754
  );
38277
37755
  }
38278
- const workspaceRef = rowString(row, "workspace_ref");
38279
- const workspacePath = await directories.resolve(bindingAuthorityId, workspaceRef, signal);
38280
- const currentAgentDigest = agentDigest(agent);
38281
- const currentWorkspaceDigest = workspaceDigest(workspacePath);
38282
- signal.throwIfAborted();
38283
- let expiresAt = rowInteger(row, "expires_at");
38284
- let revocationEpoch = rowInteger(row, "revocation_epoch");
38285
- if (currentAgentDigest !== rowString(row, "agent_identity_digest") || currentWorkspaceDigest !== rowString(row, "workspace_identity_digest") || workspacePath !== rowString(row, "workspace_path") || expiresAt <= now || rowHasInteger(row, "revoked_at")) {
38286
- const refreshed = this.refreshTarget(
38287
- rowString(row, "local_grant_id"),
38288
- currentAgentDigest,
38289
- currentWorkspaceDigest,
38290
- workspacePath,
38291
- now
38292
- );
38293
- expiresAt = refreshed.expiresAt;
38294
- revocationEpoch = refreshed.revocationEpoch;
38295
- }
38296
37756
  if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
38297
37757
  throw new LocalBotAuthorizationError(
38298
37758
  "binding_incompatible",
38299
- "The local Agent cannot apply the approved Bot behavior"
38300
- );
38301
- }
38302
- return new LocalBotGrant(
38303
- rowString(row, "local_grant_id"),
38304
- command.botId,
38305
- command.behaviorRevisionId,
38306
- command.behaviorDigest,
38307
- command.bindingId,
38308
- command.bindingRevision,
38309
- agent,
38310
- currentAgentDigest,
38311
- workspaceRef,
38312
- workspacePath,
38313
- currentWorkspaceDigest,
38314
- approvedTargets,
38315
- approvedExecutionConfiguration,
38316
- expiresAt,
38317
- revocationEpoch
38318
- );
38319
- };
38320
- recordUnavailable = (request, code, message, now) => {
38321
- this.#database.prepare(
38322
- `INSERT OR IGNORE INTO local_bot_binding_resolutions (
38323
- request_id, binding_id, local_grant_id, resolved_at,
38324
- result, error_code, error_message
38325
- ) VALUES (?, ?, '', ?, 'unavailable', ?, ?)`
38326
- ).run(request.requestId, request.bindingId, now, code, message);
38327
- };
38328
- close = () => {
38329
- this.#database.close();
38330
- };
38331
- resolveProposal = async (request, catalog, directories, bindingAuthorityId, signal) => {
38332
- const agent = configurePermission(
38333
- catalog.find(request.agentRef),
38334
- request.executionConfiguration.permissionMode
38335
- );
38336
- if (request.requiredCapabilities.includes("embedded-context") && !agent.capabilities.embeddedContextPrompt) {
38337
- throw new LocalBotAuthorizationError(
38338
- "binding_incompatible",
38339
- "The local Agent cannot apply embedded Bot context"
38340
- );
38341
- }
38342
- if (request.requiredCapabilities.some((capability) => capability !== "embedded-context")) {
38343
- throw new LocalBotAuthorizationError(
38344
- "binding_incompatible",
38345
- "The Bot requires an unsupported local Agent capability"
37759
+ "The local Agent cannot apply the Bot behavior"
38346
37760
  );
38347
37761
  }
38348
- const [adapterUnchanged, agentUnchanged] = await Promise.all([
38349
- revalidateExecutable(agent.adapterIdentity),
38350
- revalidateExecutable(agent.agentIdentity)
38351
- ]);
37762
+ const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
38352
37763
  signal.throwIfAborted();
38353
- if (!adapterUnchanged || !agentUnchanged) {
38354
- throw new LocalBotAuthorizationError(
38355
- "binding_incompatible",
38356
- "The local Agent executable changed before approval"
38357
- );
38358
- }
38359
- const workspacePath = await directories.resolve(bindingAuthorityId, request.workspaceRef, signal);
38360
- return {
38361
- agent,
38362
- agentIdentityDigest: agentDigest(agent),
38363
- workspaceIdentityDigest: workspaceDigest(workspacePath),
38364
- workspacePath
38365
- };
38366
- };
38367
- refreshTarget = (localGrantId, agentIdentityDigest, workspaceIdentityDigest, workspacePath, now) => {
38368
- const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
38369
- this.#database.exec("BEGIN IMMEDIATE");
38370
- try {
38371
- const current = this.#database.prepare("SELECT * FROM local_bot_grants WHERE local_grant_id = ?").get(localGrantId);
38372
- if (current === void 0) {
38373
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is missing");
38374
- }
38375
- const currentExpiresAt = rowInteger(current, "expires_at");
38376
- const currentRevocationEpoch = rowInteger(current, "revocation_epoch");
38377
- if (agentIdentityDigest === rowString(current, "agent_identity_digest") && workspaceIdentityDigest === rowString(current, "workspace_identity_digest") && workspacePath === rowString(current, "workspace_path") && currentExpiresAt > now && !rowHasInteger(current, "revoked_at")) {
38378
- this.#database.exec("COMMIT");
38379
- return { expiresAt: currentExpiresAt, revocationEpoch: currentRevocationEpoch };
38380
- }
38381
- const result = this.#database.prepare(
38382
- `UPDATE local_bot_grants
38383
- SET agent_identity_digest = ?, workspace_identity_digest = ?, workspace_path = ?,
38384
- expires_at = ?, revoked_at = NULL, revocation_epoch = revocation_epoch + 1
38385
- WHERE local_grant_id = ? AND revocation_epoch = ?`
38386
- ).run(
38387
- agentIdentityDigest,
38388
- workspaceIdentityDigest,
38389
- workspacePath,
38390
- expiresAt,
38391
- localGrantId,
38392
- currentRevocationEpoch
38393
- );
38394
- if (result.changes !== 1) {
38395
- throw new LocalBotAuthorizationError(
38396
- "local_grant_invalid",
38397
- "The local Bot grant target could not be refreshed"
38398
- );
38399
- }
38400
- this.#database.prepare(
38401
- `INSERT INTO audit_events (recorded_at, event, command_id, session_id, details_json)
38402
- VALUES (?, 'bot_binding_target_refreshed', ?, '', ?)`
38403
- ).run(
38404
- new Date(now).toISOString(),
38405
- rowString(current, "binding_id"),
38406
- JSON.stringify({
38407
- agentIdentityChanged: agentIdentityDigest !== rowString(current, "agent_identity_digest"),
38408
- bindingId: rowString(current, "binding_id"),
38409
- botId: rowString(current, "bot_id"),
38410
- expired: currentExpiresAt <= now,
38411
- revived: rowHasInteger(current, "revoked_at"),
38412
- workspaceIdentityChanged: workspaceIdentityDigest !== rowString(current, "workspace_identity_digest"),
38413
- workspacePathChanged: workspacePath !== rowString(current, "workspace_path")
38414
- })
38415
- );
38416
- this.#database.exec("COMMIT");
38417
- return { expiresAt, revocationEpoch: currentRevocationEpoch + 1 };
38418
- } catch (cause) {
38419
- this.#database.exec("ROLLBACK");
38420
- throw cause;
38421
- }
37764
+ return new AuthorizedLocalBotExecution(command, agent, workspacePath);
38422
37765
  };
38423
37766
  };
38424
37767
 
@@ -38430,18 +37773,18 @@ var AppliedBotContext = class {
38430
37773
  }
38431
37774
  };
38432
37775
  var EmbeddedBotContextApplicator = class {
38433
- apply = async (command, grant, resources, signal) => {
37776
+ apply = async (command, execution, resources, signal) => {
38434
37777
  signal.throwIfAborted();
38435
- if (grant.botId !== command.botId || grant.behaviorRevisionId !== command.behaviorRevisionId || grant.behaviorDigest !== command.behaviorDigest) {
37778
+ if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
38436
37779
  throw new LocalBotAuthorizationError(
38437
- "binding_not_approved",
38438
- "The Bot behavior does not match its local authorization"
37780
+ "binding_incompatible",
37781
+ "The Bot behavior does not match the execution target"
38439
37782
  );
38440
37783
  }
38441
37784
  if (command.behaviorInstructions.length === 0) {
38442
37785
  return new AppliedBotContext(resources);
38443
37786
  }
38444
- if (!grant.agent.capabilities.embeddedContextPrompt) {
37787
+ if (!execution.agent.capabilities.embeddedContextPrompt) {
38445
37788
  throw new LocalBotAuthorizationError(
38446
37789
  "binding_incompatible",
38447
37790
  "The local Agent cannot enforce the Bot behavior context"
@@ -38619,7 +37962,7 @@ function relayEndpoint(relayUrl, context, target) {
38619
37962
  endpoint.pathname = `${MOBIUS_API_PREFIX}/v1/bot-executions/${execution}/delivery-targets/${encodeURIComponent(deliveryTargetId)}/messages`;
38620
37963
  return endpoint;
38621
37964
  }
38622
- function daemonToken2(relayUrl) {
37965
+ function daemonToken(relayUrl) {
38623
37966
  const token = relayUrl.searchParams.get("token") ?? "";
38624
37967
  if (!/^[a-zA-Z0-9_-]{32,256}$/.test(token)) {
38625
37968
  throw new LocalBotAuthorizationError("bot_service_unavailable", "The Runtime credential is unavailable");
@@ -38774,7 +38117,7 @@ var BotOutboundIpcServer = class {
38774
38117
  response = await fetch5(relayEndpoint(this.#relayUrl, context, request.target), {
38775
38118
  body: JSON.stringify({ idempotencyKey: request.idempotencyKey, text: request.text }),
38776
38119
  headers: {
38777
- authorization: `Bearer ${daemonToken2(this.#relayUrl)}`,
38120
+ authorization: `Bearer ${daemonToken(this.#relayUrl)}`,
38778
38121
  "content-type": "application/json",
38779
38122
  "x-mobius-bot-execution-capability": context.command.executionCapabilitySecret
38780
38123
  },
@@ -38794,7 +38137,7 @@ var BotOutboundIpcServer = class {
38794
38137
  };
38795
38138
 
38796
38139
  // src/native-sessions/service.ts
38797
- import { randomUUID as randomUUID4 } from "node:crypto";
38140
+ import { randomUUID as randomUUID3 } from "node:crypto";
38798
38141
  import { basename as basename5 } from "node:path";
38799
38142
 
38800
38143
  // src/native-sessions/codex-history.ts
@@ -39089,7 +38432,7 @@ var NativeSessionService = class {
39089
38432
  if (authorized === null) {
39090
38433
  return null;
39091
38434
  }
39092
- const entryId = randomUUID4();
38435
+ const entryId = randomUUID3();
39093
38436
  if (this.#entries.size >= 5e3) {
39094
38437
  this.#entries.clear();
39095
38438
  }
@@ -39143,7 +38486,7 @@ var NativeSessionService = class {
39143
38486
  "invalid_native_session_response"
39144
38487
  );
39145
38488
  }
39146
- nextCursor = randomUUID4();
38489
+ nextCursor = randomUUID3();
39147
38490
  if (this.#cursors.size >= 500) {
39148
38491
  this.#cursors.clear();
39149
38492
  }
@@ -39461,7 +38804,7 @@ var NativeSessionService = class {
39461
38804
  };
39462
38805
 
39463
38806
  // src/prompt-artifact-resolver.ts
39464
- import { createHash as createHash4 } from "node:crypto";
38807
+ import { createHash as createHash3 } from "node:crypto";
39465
38808
  import { fetch as fetch6 } from "undici";
39466
38809
  var ARTIFACT_SCHEME = "mobius-artifact:";
39467
38810
  var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
@@ -39600,7 +38943,7 @@ async function download(config2, command, reference, signal) {
39600
38943
  );
39601
38944
  }
39602
38945
  const bytes = await responseBytes(response, reference.byteLength, requestSignal);
39603
- if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
38946
+ if (createHash3("sha256").update(bytes).digest("hex") !== reference.sha256) {
39604
38947
  throw new PromptArtifactError(
39605
38948
  "artifact_integrity_failed",
39606
38949
  "The prompt artifact failed integrity validation"
@@ -39909,7 +39252,7 @@ var RelayConnectionDiagnostics = class {
39909
39252
  };
39910
39253
 
39911
39254
  // src/relay-connection/liveness.ts
39912
- import { randomUUID as randomUUID5 } from "node:crypto";
39255
+ import { randomUUID as randomUUID4 } from "node:crypto";
39913
39256
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
39914
39257
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
39915
39258
  var RelayLivenessState = class {
@@ -39998,7 +39341,7 @@ var RelayConnectionLiveness = class {
39998
39341
  }
39999
39342
  throw new Error("Heartbeat was scheduled in an invalid state");
40000
39343
  }
40001
- const heartbeatId = randomUUID5();
39344
+ const heartbeatId = randomUUID4();
40002
39345
  this.#state = new AwaitingHeartbeatAckState(
40003
39346
  heartbeatId,
40004
39347
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -40015,7 +39358,7 @@ var RelayConnectionLiveness = class {
40015
39358
  // src/relay-connection/session-event-outbox.ts
40016
39359
  import { mkdirSync as mkdirSync3 } from "node:fs";
40017
39360
  import { dirname as dirname7 } from "node:path";
40018
- import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
39361
+ import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
40019
39362
  var DEFAULT_OUTBOX_LIMITS = {
40020
39363
  criticalEventBytes: 136 * 1024 * 1024,
40021
39364
  runtimeDeliveryBytes: 64 * 1024 * 1024,
@@ -40067,7 +39410,7 @@ function rowNumber(row, field) {
40067
39410
  }
40068
39411
  return value;
40069
39412
  }
40070
- function rowString2(row, field) {
39413
+ function rowString(row, field) {
40071
39414
  const value = typeof row === "object" && row !== null ? Reflect.get(row, field) : void 0;
40072
39415
  if (typeof value !== "string" || value.length === 0) {
40073
39416
  throw new Error(`SQLite returned an invalid ${field} value`);
@@ -40081,7 +39424,7 @@ var SessionEventOutbox = class {
40081
39424
  validateLimits(limits);
40082
39425
  this.#limits = limits;
40083
39426
  mkdirSync3(dirname7(path2), { recursive: true });
40084
- this.#database = new DatabaseSync4(path2);
39427
+ this.#database = new DatabaseSync3(path2);
40085
39428
  this.#database.exec(`
40086
39429
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
40087
39430
  ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -40316,8 +39659,8 @@ var SessionEventOutbox = class {
40316
39659
  WHERE delivery_id = ?`
40317
39660
  ).get(delivery.deliveryId);
40318
39661
  if (existing !== void 0) {
40319
- const sessionId = rowString2(existing, "session_id");
40320
- const payload = rowString2(existing, "payload_json");
39662
+ const sessionId = rowString(existing, "session_id");
39663
+ const payload = rowString(existing, "payload_json");
40321
39664
  const state = runtimeDeliveryState(existing);
40322
39665
  if (sessionId !== delivery.sessionId || payload !== delivery.payload) {
40323
39666
  throw new Error("The Runtime delivery identity conflicts with its durable receipt");
@@ -40405,9 +39748,9 @@ var SessionEventOutbox = class {
40405
39748
  ORDER BY received_at, delivery_id`
40406
39749
  ).all().map(
40407
39750
  (row) => new StoredRuntimeDelivery(
40408
- rowString2(row, "delivery_id"),
40409
- rowString2(row, "session_id"),
40410
- rowString2(row, "payload_json"),
39751
+ rowString(row, "delivery_id"),
39752
+ rowString(row, "session_id"),
39753
+ rowString(row, "payload_json"),
40411
39754
  runtimeDeliveryState(row),
40412
39755
  true
40413
39756
  )
@@ -40589,7 +39932,7 @@ function validateLimits(limits) {
40589
39932
  }
40590
39933
  }
40591
39934
  function runtimeDeliveryState(row) {
40592
- const state = rowString2(row, "state");
39935
+ const state = rowString(row, "state");
40593
39936
  if (state !== "received" && state !== "relay_committed" && state !== "processed") {
40594
39937
  throw new Error("SQLite returned an invalid Runtime delivery state");
40595
39938
  }
@@ -40615,9 +39958,9 @@ var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
40615
39958
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
40616
39959
  function botIpcSocketPath() {
40617
39960
  if (process.platform === "win32") {
40618
- return `\\\\.\\pipe\\mobius-bot-${randomUUID6()}`;
39961
+ return `\\\\.\\pipe\\mobius-bot-${randomUUID5()}`;
40619
39962
  }
40620
- return join17("/tmp", `mobius-bot-${randomUUID6()}.sock`);
39963
+ return join17("/tmp", `mobius-bot-${randomUUID5()}.sock`);
40621
39964
  }
40622
39965
  var DaemonAcpObserver = class {
40623
39966
  #config;
@@ -41409,6 +40752,36 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
41409
40752
  signal
41410
40753
  );
41411
40754
  const agent = config2.catalog.find(command.agentId);
40755
+ if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
40756
+ throw new AcpExecutionError(
40757
+ "The queued prompt target is unavailable",
40758
+ {},
40759
+ "prompt_queue_target_unavailable"
40760
+ );
40761
+ }
40762
+ if (command.sessionConfigurations !== void 0) {
40763
+ const prepared = await sessions.prepareExecutionSession({
40764
+ additionalDirectories: resolved.additionalDirectories,
40765
+ agent,
40766
+ cwd: resolved.cwd,
40767
+ sessionId: command.sessionId,
40768
+ signal
40769
+ });
40770
+ if (command.disposition === SessionPromptDisposition.Steer) {
40771
+ assertCompleteSessionConfiguration(prepared.configOptions, command.sessionConfigurations);
40772
+ } else {
40773
+ await applyCompleteSessionConfiguration(
40774
+ sessions,
40775
+ prepared.configOptions,
40776
+ command.sessionConfigurations,
40777
+ agent,
40778
+ resolved.cwd,
40779
+ resolved.additionalDirectories,
40780
+ command.sessionId,
40781
+ signal
40782
+ );
40783
+ }
40784
+ }
41412
40785
  audit.record({
41413
40786
  commandId: command.commandId,
41414
40787
  event: "session_authorized",
@@ -41443,13 +40816,6 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
41443
40816
  });
41444
40817
  stopReason = "steered";
41445
40818
  } else {
41446
- if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
41447
- throw new AcpExecutionError(
41448
- "The queued prompt target is unavailable",
41449
- {},
41450
- "prompt_queue_target_unavailable"
41451
- );
41452
- }
41453
40819
  const result = await sessions.runPrompt({
41454
40820
  additionalDirectories: resolved.additionalDirectories,
41455
40821
  agent,
@@ -41516,6 +40882,113 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
41516
40882
  console.error("Mobius daemon command failed", error62);
41517
40883
  }
41518
40884
  }
40885
+ function invalidSessionConfiguration(message) {
40886
+ return new AcpExecutionError(message, {}, "invalid_session_configuration");
40887
+ }
40888
+ function validateSessionConfigurationSelection(option2, selection) {
40889
+ if (option2.type !== selection.valueType) {
40890
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
40891
+ }
40892
+ if (option2.type === "boolean") {
40893
+ if (selection.value.length > 0) {
40894
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
40895
+ }
40896
+ return;
40897
+ }
40898
+ if (selection.booleanValue) {
40899
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
40900
+ }
40901
+ if (!option2.values.some((value) => value.value === selection.value)) {
40902
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
40903
+ }
40904
+ }
40905
+ function assertSessionConfigurationSchema(options, selections) {
40906
+ if (options.length !== selections.length) {
40907
+ throw invalidSessionConfiguration("The Turn configuration does not match the Agent settings schema");
40908
+ }
40909
+ const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40910
+ if (selectionsById.size !== selections.length) {
40911
+ throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
40912
+ }
40913
+ for (const option2 of options) {
40914
+ const selection = selectionsById.get(option2.id);
40915
+ if (selection === void 0 || selection.valueType !== option2.type || option2.type === "boolean" && selection.value.length > 0 || option2.type === "select" && selection.booleanValue) {
40916
+ throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option2.id}`);
40917
+ }
40918
+ }
40919
+ }
40920
+ function sessionConfigurationMatches(option2, selection) {
40921
+ validateSessionConfigurationSelection(option2, selection);
40922
+ return option2.type === "boolean" ? option2.booleanValue === selection.booleanValue : option2.currentValue === selection.value;
40923
+ }
40924
+ function sessionConfigurationPriority(selection, options) {
40925
+ if (selection.configId === "permission_mode") {
40926
+ return 0;
40927
+ }
40928
+ const option2 = options.find((candidate) => candidate.id === selection.configId);
40929
+ if (selection.configId === "model" || option2?.category === "model") {
40930
+ return 1;
40931
+ }
40932
+ if (selection.configId === "reasoning_effort" || option2?.category === "thought_level") {
40933
+ return 2;
40934
+ }
40935
+ if (option2?.category === "model_config") {
40936
+ return 3;
40937
+ }
40938
+ return 4;
40939
+ }
40940
+ function assertCompleteSessionConfiguration(options, selections) {
40941
+ assertSessionConfigurationSchema(options, selections);
40942
+ const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40943
+ for (const option2 of options) {
40944
+ const selection = selectionsById.get(option2.id);
40945
+ if (selection === void 0 || !sessionConfigurationMatches(option2, selection)) {
40946
+ throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option2.id}`);
40947
+ }
40948
+ }
40949
+ }
40950
+ async function applySessionConfigurationSelection(sessions, options, selection, agent, cwd, additionalDirectories, sessionId, signal) {
40951
+ const option2 = options.find((candidate) => candidate.id === selection.configId);
40952
+ if (option2 === void 0) {
40953
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
40954
+ }
40955
+ if (sessionConfigurationMatches(option2, selection)) {
40956
+ return options;
40957
+ }
40958
+ return await sessions.configureSession({
40959
+ additionalDirectories,
40960
+ agent,
40961
+ booleanValue: selection.booleanValue,
40962
+ configId: selection.configId,
40963
+ cwd,
40964
+ requestId: `cfg_${randomUUID5()}`,
40965
+ sessionId,
40966
+ signal,
40967
+ value: selection.value,
40968
+ valueType: selection.valueType
40969
+ });
40970
+ }
40971
+ async function applyCompleteSessionConfiguration(sessions, initialOptions, selections, agent, cwd, additionalDirectories, sessionId, signal) {
40972
+ assertSessionConfigurationSchema(initialOptions, selections);
40973
+ let options = initialOptions;
40974
+ const orderedSelections = selections.toSorted((left, right) => {
40975
+ const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
40976
+ return priority === 0 ? left.configId.localeCompare(right.configId) : priority;
40977
+ });
40978
+ for (const selection of orderedSelections) {
40979
+ options = await applySessionConfigurationSelection(
40980
+ sessions,
40981
+ options,
40982
+ selection,
40983
+ agent,
40984
+ cwd,
40985
+ additionalDirectories,
40986
+ sessionId,
40987
+ signal
40988
+ );
40989
+ }
40990
+ assertCompleteSessionConfiguration(options, selections);
40991
+ }
41519
40992
  function botExecutionAgent(agent, contextHandle, socketPath) {
41520
40993
  return new LocalAgentDefinition(
41521
40994
  agent.id,
@@ -41576,14 +41049,14 @@ async function applyRequiredExecutionSelection(sessions, configOptions, selectio
41576
41049
  booleanValue: false,
41577
41050
  configId: selection.configId,
41578
41051
  cwd,
41579
- requestId: `cfg_${randomUUID6()}`,
41052
+ requestId: `cfg_${randomUUID5()}`,
41580
41053
  sessionId,
41581
41054
  signal,
41582
41055
  value: selection.value,
41583
41056
  valueType: "select"
41584
41057
  });
41585
41058
  }
41586
- async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, grants, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
41059
+ async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
41587
41060
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
41588
41061
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
41589
41062
  });
@@ -41593,21 +41066,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41593
41066
  if (!Number.isSafeInteger(deadline) || remaining <= 0) {
41594
41067
  throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
41595
41068
  }
41596
- const grant = await grants.resolveExecution(
41597
- command,
41598
- config2.catalog,
41599
- directories,
41600
- config2.bindingId,
41601
- Date.now(),
41602
- signal
41603
- );
41604
- const requestedExecutionTargetOverridden = command.directoryId !== grant.workspaceRef || command.additionalDirectoryIds.length > 0;
41605
- if (requestedExecutionTargetOverridden && !(command.replyRoute instanceof OwnerBotReplyRoute)) {
41606
- throw new LocalBotAuthorizationError(
41607
- "binding_not_approved",
41608
- "Only a paired owner conversation can override the approved Bot workspace"
41609
- );
41610
- }
41069
+ const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
41611
41070
  const resolved = await resolveSessionDirectories(
41612
41071
  directories,
41613
41072
  config2.bindingId,
@@ -41615,20 +41074,8 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41615
41074
  command.additionalDirectoryIds,
41616
41075
  signal
41617
41076
  );
41618
- const executionTargetOverridden = resolved.cwd !== grant.workspacePath || resolved.additionalDirectories.length > 0;
41619
- if (executionTargetOverridden && !sessions.hasPreparedSession(
41620
- command.sessionId,
41621
- grant.agent.id,
41622
- resolved.cwd,
41623
- resolved.additionalDirectories
41624
- )) {
41625
- throw new LocalBotAuthorizationError(
41626
- "local_approval_required",
41627
- "Open this Bot conversation in the paired local Web app before using the selected workspace"
41628
- );
41629
- }
41630
41077
  const attachments = await resolvePromptArtifacts(config2, command, signal);
41631
- const applied = await applicator.apply(command, grant, attachments.resources, signal);
41078
+ const applied = await applicator.apply(command, execution, attachments.resources, signal);
41632
41079
  const deadlineSignal = AbortSignal.timeout(remaining);
41633
41080
  const executionSignal = AbortSignal.any([signal, deadlineSignal]);
41634
41081
  const startExecution = () => {
@@ -41638,8 +41085,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41638
41085
  behaviorRevisionId: command.behaviorRevisionId,
41639
41086
  bindingId: command.bindingId,
41640
41087
  botId: command.botId,
41641
- executionId: command.executionId,
41642
- localGrantId: command.localGrantId
41088
+ executionId: command.executionId
41643
41089
  },
41644
41090
  event: "bot_session_authorized",
41645
41091
  sessionId: command.sessionId
@@ -41662,7 +41108,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41662
41108
  startExecution();
41663
41109
  await sessions.steerPrompt({
41664
41110
  additionalDirectories: resolved.additionalDirectories,
41665
- agent: grant.agent,
41111
+ agent: execution.agent,
41666
41112
  commandId: command.commandId,
41667
41113
  cwd: resolved.cwd,
41668
41114
  images: attachments.images,
@@ -41682,7 +41128,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41682
41128
  }
41683
41129
  const lease = contexts.activate(command);
41684
41130
  try {
41685
- const agent = botExecutionAgent(grant.agent, lease.context.contextHandle, ipc.socketPath);
41131
+ const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
41686
41132
  const prepared = await sessions.prepareExecutionSession({
41687
41133
  additionalDirectories: resolved.additionalDirectories,
41688
41134
  agent,
@@ -41690,11 +41136,11 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41690
41136
  sessionId: command.sessionId,
41691
41137
  signal: executionSignal
41692
41138
  });
41693
- assertPreparedPermission(prepared.configOptions, grant.executionConfiguration.permissionMode);
41139
+ assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41694
41140
  let configOptions = await applyRequiredExecutionSelection(
41695
41141
  sessions,
41696
41142
  prepared.configOptions,
41697
- grant.executionConfiguration.model,
41143
+ execution.executionConfiguration.model,
41698
41144
  "model",
41699
41145
  agent,
41700
41146
  resolved.cwd,
@@ -41705,7 +41151,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41705
41151
  configOptions = await applyRequiredExecutionSelection(
41706
41152
  sessions,
41707
41153
  configOptions,
41708
- grant.executionConfiguration.reasoningEffort,
41154
+ execution.executionConfiguration.reasoningEffort,
41709
41155
  "thought_level",
41710
41156
  agent,
41711
41157
  resolved.cwd,
@@ -41720,7 +41166,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41720
41166
  booleanValue: selection.booleanValue,
41721
41167
  configId: selection.configId,
41722
41168
  cwd: resolved.cwd,
41723
- requestId: `cfg_${randomUUID6()}`,
41169
+ requestId: `cfg_${randomUUID5()}`,
41724
41170
  sessionId: command.sessionId,
41725
41171
  signal: executionSignal,
41726
41172
  value: selection.value,
@@ -41852,13 +41298,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
41852
41298
  {
41853
41299
  agentId: agent.id,
41854
41300
  kind: AGENT_INSTALL_REQUEST_KIND,
41855
- requestId: `automatic-integration-${randomUUID6()}`
41301
+ requestId: `automatic-integration-${randomUUID5()}`
41856
41302
  },
41857
41303
  signal
41858
41304
  );
41859
41305
  }
41860
41306
  }
41861
- async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, grants, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41307
+ async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, authorizer, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41862
41308
  const relayUrl = new URL(config2.relayUrl);
41863
41309
  relayUrl.searchParams.set("deliveryReceipts", "1");
41864
41310
  relayUrl.searchParams.set("liveness", "1");
@@ -42038,7 +41484,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42038
41484
  directories,
42039
41485
  audit,
42040
41486
  sessions,
42041
- grants,
41487
+ authorizer,
42042
41488
  contexts,
42043
41489
  applicator,
42044
41490
  ipc,
@@ -42218,70 +41664,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42218
41664
  }
42219
41665
  return;
42220
41666
  }
42221
- if (kind === BOT_BINDING_APPROVED_KIND) {
42222
- decodeBotExecutionBindingApprovedEvent(encoded);
42223
- return;
42224
- }
42225
- if (kind === BOT_BINDING_UNAVAILABLE_KIND) {
42226
- decodeBotExecutionBindingUnavailableEvent(encoded);
42227
- return;
42228
- }
42229
- if (kind === BOT_BINDING_APPROVAL_REQUEST_KIND) {
42230
- const request = decodeBotExecutionBindingApprovalRequest(encoded);
42231
- void grants.approve(
42232
- request,
42233
- config2.catalog,
42234
- directories,
42235
- config2.bindingId,
42236
- Date.now(),
42237
- connectionController.signal
42238
- ).then((approved) => {
42239
- audit.record({
42240
- commandId: request.requestId,
42241
- details: {
42242
- behaviorRevisionId: request.behaviorRevisionId,
42243
- bindingId: request.bindingId,
42244
- botId: request.botId,
42245
- localGrantId: approved.localGrantId
42246
- },
42247
- event: "bot_binding_approved",
42248
- sessionId: `bot-binding:${request.bindingId}`
42249
- });
42250
- if (socket.readyState === WebSocket2.OPEN) {
42251
- send(socket, encodeBotExecutionBindingApprovedEvent(approved));
42252
- }
42253
- }).catch((error62) => {
42254
- if (connectionController.signal.aborted) {
42255
- return;
42256
- }
42257
- const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "binding_incompatible";
42258
- const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local execution target is incompatible";
42259
- grants.recordUnavailable(request, code, message, Date.now());
42260
- audit.record({
42261
- commandId: request.requestId,
42262
- details: { bindingId: request.bindingId, botId: request.botId, code },
42263
- event: "bot_binding_unavailable",
42264
- sessionId: `bot-binding:${request.bindingId}`
42265
- });
42266
- if (socket.readyState === WebSocket2.OPEN) {
42267
- send(
42268
- socket,
42269
- encodeBotExecutionBindingUnavailableEvent(
42270
- new BotExecutionBindingUnavailableEvent(
42271
- request.requestId,
42272
- request.botId,
42273
- request.behaviorRevisionId,
42274
- request.bindingId,
42275
- request.bindingRevision,
42276
- code,
42277
- message
42278
- )
42279
- )
42280
- );
42281
- }
42282
- });
42283
- return;
42284
- }
42285
41667
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
42286
41668
  const command2 = decodeNativeSessionCancel(encoded);
42287
41669
  const pending = nativeRequests.get(command2.requestId);
@@ -42677,7 +42059,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42677
42059
  directories,
42678
42060
  audit,
42679
42061
  sessions,
42680
- grants,
42062
+ authorizer,
42681
42063
  contexts,
42682
42064
  applicator,
42683
42065
  ipc,
@@ -42803,7 +42185,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42803
42185
  const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
42804
42186
  const outbox = new SessionEventOutbox(config2.auditDatabasePath);
42805
42187
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
42806
- const grants = new LocalBotGrantStore(config2.auditDatabasePath);
42188
+ const authorizer = new LocalBotExecutionAuthorizer();
42807
42189
  const contexts = new BotExecutionContextRegistry();
42808
42190
  const applicator = new EmbeddedBotContextApplicator();
42809
42191
  const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
@@ -42894,7 +42276,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42894
42276
  nativeSessions,
42895
42277
  outbox,
42896
42278
  publisher,
42897
- grants,
42279
+ authorizer,
42898
42280
  contexts,
42899
42281
  applicator,
42900
42282
  ipc,
@@ -42939,13 +42321,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42939
42321
  sessionStore.close();
42940
42322
  } finally {
42941
42323
  try {
42942
- grants.close();
42324
+ publisher.close();
42943
42325
  } finally {
42944
- try {
42945
- publisher.close();
42946
- } finally {
42947
- outbox.close();
42948
- }
42326
+ outbox.close();
42949
42327
  }
42950
42328
  }
42951
42329
  }