@moxt-ai/mobius 0.0.43 → 0.0.44

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.
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.44",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -21356,9 +21356,6 @@ function encodeSessionFailedEvent(message) {
21356
21356
  }
21357
21357
 
21358
21358
  // ../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
21359
  var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
21363
21360
  var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
21364
21361
  var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
@@ -21373,21 +21370,6 @@ var BotDeliveryTargetReference = class {
21373
21370
  this.deliveryTargetId = deliveryTargetId;
21374
21371
  }
21375
21372
  };
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
21373
  var BotReplyRoute = class {
21392
21374
  };
21393
21375
  var OwnerBotReplyRoute = class extends BotReplyRoute {
@@ -21403,94 +21385,6 @@ var BotConnectionReplyRoute = class extends BotReplyRoute {
21403
21385
  this.deliveryTargetId = deliveryTargetId;
21404
21386
  }
21405
21387
  };
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
21388
  var BotSessionPromptCommand = class {
21495
21389
  additionalDirectoryIds;
21496
21390
  agentId;
@@ -21512,7 +21406,6 @@ var BotSessionPromptCommand = class {
21512
21406
  executionConfiguration;
21513
21407
  images;
21514
21408
  kind = BOT_SESSION_PROMPT_KIND;
21515
- localGrantId;
21516
21409
  prompt;
21517
21410
  replyRoute;
21518
21411
  resources;
@@ -21520,7 +21413,7 @@ var BotSessionPromptCommand = class {
21520
21413
  sessionId;
21521
21414
  targetCommandId;
21522
21415
  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 = "") {
21416
+ 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
21417
  this.sessionId = sessionId;
21525
21418
  this.commandId = commandId;
21526
21419
  this.agentId = agentId;
@@ -21540,7 +21433,6 @@ var BotSessionPromptCommand = class {
21540
21433
  this.turnId = turnId;
21541
21434
  this.behaviorRevisionId = behaviorRevisionId;
21542
21435
  this.bindingRevision = bindingRevision;
21543
- this.localGrantId = localGrantId;
21544
21436
  this.behaviorInstructions = behaviorInstructions;
21545
21437
  this.behaviorDigest = behaviorDigest;
21546
21438
  this.allowedDeliveryTargets = Object.freeze(
@@ -21684,24 +21576,6 @@ function readSessionConfigurations(value) {
21684
21576
  }
21685
21577
  return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
21686
21578
  }
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
21579
  function readReplyRoute(value) {
21706
21580
  if (!isRecord3(value)) {
21707
21581
  throw new ProtocolMessageError("Invalid Bot reply route");
@@ -21720,110 +21594,6 @@ function readReplyRoute(value) {
21720
21594
  }
21721
21595
  throw new ProtocolMessageError("Invalid Bot reply route");
21722
21596
  }
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
21597
  function decodeBotSessionPromptCommand(encoded) {
21828
21598
  const value = parseJson3(encoded);
21829
21599
  assertKeysWithOptional(
@@ -21848,7 +21618,6 @@ function decodeBotSessionPromptCommand(encoded) {
21848
21618
  "executionConfiguration",
21849
21619
  "images",
21850
21620
  "kind",
21851
- "localGrantId",
21852
21621
  "prompt",
21853
21622
  "replyRoute",
21854
21623
  "resources",
@@ -21894,7 +21663,6 @@ function decodeBotSessionPromptCommand(encoded) {
21894
21663
  readIdentifier2(value, "turnId"),
21895
21664
  readIdentifier2(value, "behaviorRevisionId"),
21896
21665
  readInteger(value, "bindingRevision"),
21897
- readIdentifier2(value, "localGrantId"),
21898
21666
  readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21899
21667
  readDigest(value, "behaviorDigest"),
21900
21668
  readTargets(value, "allowedDeliveryTargets"),
@@ -23677,7 +23445,7 @@ function isContainedPath3(root, candidate) {
23677
23445
  }
23678
23446
  async function hashFile(path2, signal) {
23679
23447
  signal.throwIfAborted();
23680
- const digest2 = createHash("sha256");
23448
+ const digest = createHash("sha256");
23681
23449
  const stream = createReadStream(path2, { signal });
23682
23450
  try {
23683
23451
  for await (const chunk of stream) {
@@ -23688,9 +23456,9 @@ async function hashFile(path2, signal) {
23688
23456
  "The managed Agent archive produced invalid bytes"
23689
23457
  );
23690
23458
  }
23691
- digest2.update(chunk);
23459
+ digest.update(chunk);
23692
23460
  }
23693
- return digest2.digest("hex");
23461
+ return digest.digest("hex");
23694
23462
  } catch (error62) {
23695
23463
  if (signal.aborted) {
23696
23464
  signal.throwIfAborted();
@@ -25207,7 +24975,7 @@ var AuditStore = class {
25207
24975
  };
25208
24976
 
25209
24977
  // src/run-daemon.ts
25210
- import { randomUUID as randomUUID6 } from "node:crypto";
24978
+ import { randomUUID as randomUUID5 } from "node:crypto";
25211
24979
  import { basename as basename6, join as join17 } from "node:path";
25212
24980
  import { styleText } from "node:util";
25213
24981
  import { fetch as fetch7, WebSocket as WebSocket2 } from "undici";
@@ -37933,10 +37701,7 @@ var WorkspaceDirectoryService = class {
37933
37701
  };
37934
37702
  };
37935
37703
 
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;
37704
+ // src/bots/local-bot-execution-authorizer.ts
37940
37705
  var LocalBotAuthorizationError = class extends Error {
37941
37706
  code;
37942
37707
  constructor(code, message, options = {}) {
@@ -37945,325 +37710,40 @@ var LocalBotAuthorizationError = class extends Error {
37945
37710
  this.name = "LocalBotAuthorizationError";
37946
37711
  }
37947
37712
  };
37948
- var LocalBotGrant = class {
37713
+ var AuthorizedLocalBotExecution = class {
37949
37714
  agent;
37950
- agentIdentityDigest;
37951
- allowedDeliveryTargetIds;
37952
37715
  behaviorDigest;
37953
37716
  behaviorRevisionId;
37954
37717
  bindingId;
37955
37718
  bindingRevision;
37956
37719
  botId;
37957
- expiresAt;
37958
37720
  executionConfiguration;
37959
- localGrantId;
37960
- revocationEpoch;
37961
- workspaceIdentityDigest;
37962
37721
  workspacePath;
37963
37722
  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;
37723
+ constructor(command, agent, workspacePath) {
37971
37724
  this.agent = agent;
37972
- this.agentIdentityDigest = agentIdentityDigest;
37973
- this.workspaceRef = workspaceRef;
37725
+ this.behaviorDigest = command.behaviorDigest;
37726
+ this.behaviorRevisionId = command.behaviorRevisionId;
37727
+ this.bindingId = command.bindingId;
37728
+ this.bindingRevision = command.bindingRevision;
37729
+ this.botId = command.botId;
37730
+ this.executionConfiguration = command.executionConfiguration;
37974
37731
  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;
37732
+ this.workspaceRef = command.directoryId;
37980
37733
  }
37981
37734
  };
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) => {
37735
+ var LocalBotExecutionAuthorizer = class {
37736
+ authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
38128
37737
  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");
37738
+ let agent;
38152
37739
  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");
37740
+ agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
38194
37741
  } catch (cause) {
38195
- this.#database.exec("ROLLBACK");
37742
+ if (cause instanceof AgentPermissionConfigurationError) {
37743
+ throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
37744
+ }
38196
37745
  throw cause;
38197
37746
  }
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
37747
  const [adapterUnchanged, agentUnchanged] = await Promise.all([
38268
37748
  revalidateExecutable(agent.adapterIdentity),
38269
37749
  revalidateExecutable(agent.agentIdentity)
@@ -38275,150 +37755,15 @@ var LocalBotGrantStore = class {
38275
37755
  "The local Agent executable changed while the Runtime is active; restart the Runtime"
38276
37756
  );
38277
37757
  }
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
37758
  if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
38297
37759
  throw new LocalBotAuthorizationError(
38298
37760
  "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"
37761
+ "The local Agent cannot apply the Bot behavior"
38346
37762
  );
38347
37763
  }
38348
- const [adapterUnchanged, agentUnchanged] = await Promise.all([
38349
- revalidateExecutable(agent.adapterIdentity),
38350
- revalidateExecutable(agent.agentIdentity)
38351
- ]);
37764
+ const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
38352
37765
  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
- }
37766
+ return new AuthorizedLocalBotExecution(command, agent, workspacePath);
38422
37767
  };
38423
37768
  };
38424
37769
 
@@ -38430,18 +37775,18 @@ var AppliedBotContext = class {
38430
37775
  }
38431
37776
  };
38432
37777
  var EmbeddedBotContextApplicator = class {
38433
- apply = async (command, grant, resources, signal) => {
37778
+ apply = async (command, execution, resources, signal) => {
38434
37779
  signal.throwIfAborted();
38435
- if (grant.botId !== command.botId || grant.behaviorRevisionId !== command.behaviorRevisionId || grant.behaviorDigest !== command.behaviorDigest) {
37780
+ if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
38436
37781
  throw new LocalBotAuthorizationError(
38437
- "binding_not_approved",
38438
- "The Bot behavior does not match its local authorization"
37782
+ "binding_incompatible",
37783
+ "The Bot behavior does not match the execution target"
38439
37784
  );
38440
37785
  }
38441
37786
  if (command.behaviorInstructions.length === 0) {
38442
37787
  return new AppliedBotContext(resources);
38443
37788
  }
38444
- if (!grant.agent.capabilities.embeddedContextPrompt) {
37789
+ if (!execution.agent.capabilities.embeddedContextPrompt) {
38445
37790
  throw new LocalBotAuthorizationError(
38446
37791
  "binding_incompatible",
38447
37792
  "The local Agent cannot enforce the Bot behavior context"
@@ -38794,7 +38139,7 @@ var BotOutboundIpcServer = class {
38794
38139
  };
38795
38140
 
38796
38141
  // src/native-sessions/service.ts
38797
- import { randomUUID as randomUUID4 } from "node:crypto";
38142
+ import { randomUUID as randomUUID3 } from "node:crypto";
38798
38143
  import { basename as basename5 } from "node:path";
38799
38144
 
38800
38145
  // src/native-sessions/codex-history.ts
@@ -39089,7 +38434,7 @@ var NativeSessionService = class {
39089
38434
  if (authorized === null) {
39090
38435
  return null;
39091
38436
  }
39092
- const entryId = randomUUID4();
38437
+ const entryId = randomUUID3();
39093
38438
  if (this.#entries.size >= 5e3) {
39094
38439
  this.#entries.clear();
39095
38440
  }
@@ -39143,7 +38488,7 @@ var NativeSessionService = class {
39143
38488
  "invalid_native_session_response"
39144
38489
  );
39145
38490
  }
39146
- nextCursor = randomUUID4();
38491
+ nextCursor = randomUUID3();
39147
38492
  if (this.#cursors.size >= 500) {
39148
38493
  this.#cursors.clear();
39149
38494
  }
@@ -39461,7 +38806,7 @@ var NativeSessionService = class {
39461
38806
  };
39462
38807
 
39463
38808
  // src/prompt-artifact-resolver.ts
39464
- import { createHash as createHash4 } from "node:crypto";
38809
+ import { createHash as createHash3 } from "node:crypto";
39465
38810
  import { fetch as fetch6 } from "undici";
39466
38811
  var ARTIFACT_SCHEME = "mobius-artifact:";
39467
38812
  var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
@@ -39600,7 +38945,7 @@ async function download(config2, command, reference, signal) {
39600
38945
  );
39601
38946
  }
39602
38947
  const bytes = await responseBytes(response, reference.byteLength, requestSignal);
39603
- if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
38948
+ if (createHash3("sha256").update(bytes).digest("hex") !== reference.sha256) {
39604
38949
  throw new PromptArtifactError(
39605
38950
  "artifact_integrity_failed",
39606
38951
  "The prompt artifact failed integrity validation"
@@ -39909,7 +39254,7 @@ var RelayConnectionDiagnostics = class {
39909
39254
  };
39910
39255
 
39911
39256
  // src/relay-connection/liveness.ts
39912
- import { randomUUID as randomUUID5 } from "node:crypto";
39257
+ import { randomUUID as randomUUID4 } from "node:crypto";
39913
39258
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
39914
39259
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
39915
39260
  var RelayLivenessState = class {
@@ -39998,7 +39343,7 @@ var RelayConnectionLiveness = class {
39998
39343
  }
39999
39344
  throw new Error("Heartbeat was scheduled in an invalid state");
40000
39345
  }
40001
- const heartbeatId = randomUUID5();
39346
+ const heartbeatId = randomUUID4();
40002
39347
  this.#state = new AwaitingHeartbeatAckState(
40003
39348
  heartbeatId,
40004
39349
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -40015,7 +39360,7 @@ var RelayConnectionLiveness = class {
40015
39360
  // src/relay-connection/session-event-outbox.ts
40016
39361
  import { mkdirSync as mkdirSync3 } from "node:fs";
40017
39362
  import { dirname as dirname7 } from "node:path";
40018
- import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
39363
+ import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
40019
39364
  var DEFAULT_OUTBOX_LIMITS = {
40020
39365
  criticalEventBytes: 136 * 1024 * 1024,
40021
39366
  runtimeDeliveryBytes: 64 * 1024 * 1024,
@@ -40067,7 +39412,7 @@ function rowNumber(row, field) {
40067
39412
  }
40068
39413
  return value;
40069
39414
  }
40070
- function rowString2(row, field) {
39415
+ function rowString(row, field) {
40071
39416
  const value = typeof row === "object" && row !== null ? Reflect.get(row, field) : void 0;
40072
39417
  if (typeof value !== "string" || value.length === 0) {
40073
39418
  throw new Error(`SQLite returned an invalid ${field} value`);
@@ -40081,7 +39426,7 @@ var SessionEventOutbox = class {
40081
39426
  validateLimits(limits);
40082
39427
  this.#limits = limits;
40083
39428
  mkdirSync3(dirname7(path2), { recursive: true });
40084
- this.#database = new DatabaseSync4(path2);
39429
+ this.#database = new DatabaseSync3(path2);
40085
39430
  this.#database.exec(`
40086
39431
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
40087
39432
  ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -40316,8 +39661,8 @@ var SessionEventOutbox = class {
40316
39661
  WHERE delivery_id = ?`
40317
39662
  ).get(delivery.deliveryId);
40318
39663
  if (existing !== void 0) {
40319
- const sessionId = rowString2(existing, "session_id");
40320
- const payload = rowString2(existing, "payload_json");
39664
+ const sessionId = rowString(existing, "session_id");
39665
+ const payload = rowString(existing, "payload_json");
40321
39666
  const state = runtimeDeliveryState(existing);
40322
39667
  if (sessionId !== delivery.sessionId || payload !== delivery.payload) {
40323
39668
  throw new Error("The Runtime delivery identity conflicts with its durable receipt");
@@ -40405,9 +39750,9 @@ var SessionEventOutbox = class {
40405
39750
  ORDER BY received_at, delivery_id`
40406
39751
  ).all().map(
40407
39752
  (row) => new StoredRuntimeDelivery(
40408
- rowString2(row, "delivery_id"),
40409
- rowString2(row, "session_id"),
40410
- rowString2(row, "payload_json"),
39753
+ rowString(row, "delivery_id"),
39754
+ rowString(row, "session_id"),
39755
+ rowString(row, "payload_json"),
40411
39756
  runtimeDeliveryState(row),
40412
39757
  true
40413
39758
  )
@@ -40589,7 +39934,7 @@ function validateLimits(limits) {
40589
39934
  }
40590
39935
  }
40591
39936
  function runtimeDeliveryState(row) {
40592
- const state = rowString2(row, "state");
39937
+ const state = rowString(row, "state");
40593
39938
  if (state !== "received" && state !== "relay_committed" && state !== "processed") {
40594
39939
  throw new Error("SQLite returned an invalid Runtime delivery state");
40595
39940
  }
@@ -40615,9 +39960,9 @@ var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
40615
39960
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
40616
39961
  function botIpcSocketPath() {
40617
39962
  if (process.platform === "win32") {
40618
- return `\\\\.\\pipe\\mobius-bot-${randomUUID6()}`;
39963
+ return `\\\\.\\pipe\\mobius-bot-${randomUUID5()}`;
40619
39964
  }
40620
- return join17("/tmp", `mobius-bot-${randomUUID6()}.sock`);
39965
+ return join17("/tmp", `mobius-bot-${randomUUID5()}.sock`);
40621
39966
  }
40622
39967
  var DaemonAcpObserver = class {
40623
39968
  #config;
@@ -41576,14 +40921,14 @@ async function applyRequiredExecutionSelection(sessions, configOptions, selectio
41576
40921
  booleanValue: false,
41577
40922
  configId: selection.configId,
41578
40923
  cwd,
41579
- requestId: `cfg_${randomUUID6()}`,
40924
+ requestId: `cfg_${randomUUID5()}`,
41580
40925
  sessionId,
41581
40926
  signal,
41582
40927
  value: selection.value,
41583
40928
  valueType: "select"
41584
40929
  });
41585
40930
  }
41586
- async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, grants, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
40931
+ async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
41587
40932
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
41588
40933
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
41589
40934
  });
@@ -41593,21 +40938,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41593
40938
  if (!Number.isSafeInteger(deadline) || remaining <= 0) {
41594
40939
  throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
41595
40940
  }
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
- }
40941
+ const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
41611
40942
  const resolved = await resolveSessionDirectories(
41612
40943
  directories,
41613
40944
  config2.bindingId,
@@ -41615,20 +40946,8 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41615
40946
  command.additionalDirectoryIds,
41616
40947
  signal
41617
40948
  );
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
40949
  const attachments = await resolvePromptArtifacts(config2, command, signal);
41631
- const applied = await applicator.apply(command, grant, attachments.resources, signal);
40950
+ const applied = await applicator.apply(command, execution, attachments.resources, signal);
41632
40951
  const deadlineSignal = AbortSignal.timeout(remaining);
41633
40952
  const executionSignal = AbortSignal.any([signal, deadlineSignal]);
41634
40953
  const startExecution = () => {
@@ -41638,8 +40957,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41638
40957
  behaviorRevisionId: command.behaviorRevisionId,
41639
40958
  bindingId: command.bindingId,
41640
40959
  botId: command.botId,
41641
- executionId: command.executionId,
41642
- localGrantId: command.localGrantId
40960
+ executionId: command.executionId
41643
40961
  },
41644
40962
  event: "bot_session_authorized",
41645
40963
  sessionId: command.sessionId
@@ -41662,7 +40980,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41662
40980
  startExecution();
41663
40981
  await sessions.steerPrompt({
41664
40982
  additionalDirectories: resolved.additionalDirectories,
41665
- agent: grant.agent,
40983
+ agent: execution.agent,
41666
40984
  commandId: command.commandId,
41667
40985
  cwd: resolved.cwd,
41668
40986
  images: attachments.images,
@@ -41682,7 +41000,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41682
41000
  }
41683
41001
  const lease = contexts.activate(command);
41684
41002
  try {
41685
- const agent = botExecutionAgent(grant.agent, lease.context.contextHandle, ipc.socketPath);
41003
+ const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
41686
41004
  const prepared = await sessions.prepareExecutionSession({
41687
41005
  additionalDirectories: resolved.additionalDirectories,
41688
41006
  agent,
@@ -41690,11 +41008,11 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41690
41008
  sessionId: command.sessionId,
41691
41009
  signal: executionSignal
41692
41010
  });
41693
- assertPreparedPermission(prepared.configOptions, grant.executionConfiguration.permissionMode);
41011
+ assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41694
41012
  let configOptions = await applyRequiredExecutionSelection(
41695
41013
  sessions,
41696
41014
  prepared.configOptions,
41697
- grant.executionConfiguration.model,
41015
+ execution.executionConfiguration.model,
41698
41016
  "model",
41699
41017
  agent,
41700
41018
  resolved.cwd,
@@ -41705,7 +41023,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41705
41023
  configOptions = await applyRequiredExecutionSelection(
41706
41024
  sessions,
41707
41025
  configOptions,
41708
- grant.executionConfiguration.reasoningEffort,
41026
+ execution.executionConfiguration.reasoningEffort,
41709
41027
  "thought_level",
41710
41028
  agent,
41711
41029
  resolved.cwd,
@@ -41720,7 +41038,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41720
41038
  booleanValue: selection.booleanValue,
41721
41039
  configId: selection.configId,
41722
41040
  cwd: resolved.cwd,
41723
- requestId: `cfg_${randomUUID6()}`,
41041
+ requestId: `cfg_${randomUUID5()}`,
41724
41042
  sessionId: command.sessionId,
41725
41043
  signal: executionSignal,
41726
41044
  value: selection.value,
@@ -41852,13 +41170,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
41852
41170
  {
41853
41171
  agentId: agent.id,
41854
41172
  kind: AGENT_INSTALL_REQUEST_KIND,
41855
- requestId: `automatic-integration-${randomUUID6()}`
41173
+ requestId: `automatic-integration-${randomUUID5()}`
41856
41174
  },
41857
41175
  signal
41858
41176
  );
41859
41177
  }
41860
41178
  }
41861
- async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, grants, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41179
+ async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, authorizer, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41862
41180
  const relayUrl = new URL(config2.relayUrl);
41863
41181
  relayUrl.searchParams.set("deliveryReceipts", "1");
41864
41182
  relayUrl.searchParams.set("liveness", "1");
@@ -42038,7 +41356,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42038
41356
  directories,
42039
41357
  audit,
42040
41358
  sessions,
42041
- grants,
41359
+ authorizer,
42042
41360
  contexts,
42043
41361
  applicator,
42044
41362
  ipc,
@@ -42218,70 +41536,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42218
41536
  }
42219
41537
  return;
42220
41538
  }
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
41539
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
42286
41540
  const command2 = decodeNativeSessionCancel(encoded);
42287
41541
  const pending = nativeRequests.get(command2.requestId);
@@ -42677,7 +41931,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42677
41931
  directories,
42678
41932
  audit,
42679
41933
  sessions,
42680
- grants,
41934
+ authorizer,
42681
41935
  contexts,
42682
41936
  applicator,
42683
41937
  ipc,
@@ -42803,7 +42057,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42803
42057
  const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
42804
42058
  const outbox = new SessionEventOutbox(config2.auditDatabasePath);
42805
42059
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
42806
- const grants = new LocalBotGrantStore(config2.auditDatabasePath);
42060
+ const authorizer = new LocalBotExecutionAuthorizer();
42807
42061
  const contexts = new BotExecutionContextRegistry();
42808
42062
  const applicator = new EmbeddedBotContextApplicator();
42809
42063
  const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
@@ -42894,7 +42148,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42894
42148
  nativeSessions,
42895
42149
  outbox,
42896
42150
  publisher,
42897
- grants,
42151
+ authorizer,
42898
42152
  contexts,
42899
42153
  applicator,
42900
42154
  ipc,
@@ -42939,13 +42193,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42939
42193
  sessionStore.close();
42940
42194
  } finally {
42941
42195
  try {
42942
- grants.close();
42196
+ publisher.close();
42943
42197
  } finally {
42944
- try {
42945
- publisher.close();
42946
- } finally {
42947
- outbox.close();
42948
- }
42198
+ outbox.close();
42949
42199
  }
42950
42200
  }
42951
42201
  }