@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/runtime.js CHANGED
@@ -21289,9 +21289,6 @@ function encodeSessionFailedEvent(message) {
21289
21289
  }
21290
21290
 
21291
21291
  // ../protocol/src/bot.ts
21292
- var BOT_BINDING_APPROVAL_REQUEST_KIND = "bot.binding.approval.request";
21293
- var BOT_BINDING_APPROVED_KIND = "bot.binding.approved";
21294
- var BOT_BINDING_UNAVAILABLE_KIND = "bot.binding.unavailable";
21295
21292
  var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
21296
21293
  var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
21297
21294
  var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
@@ -21306,21 +21303,6 @@ var BotDeliveryTargetReference = class {
21306
21303
  this.deliveryTargetId = deliveryTargetId;
21307
21304
  }
21308
21305
  };
21309
- var BotCompletionDeliveryPolicy = class {
21310
- };
21311
- var NoBotCompletionDeliveryPolicy = class extends BotCompletionDeliveryPolicy {
21312
- kind = "none";
21313
- };
21314
- var RequiredBotCompletionDeliveryPolicy = class extends BotCompletionDeliveryPolicy {
21315
- deliveryTargetId;
21316
- kind = "required";
21317
- messageTemplate;
21318
- constructor(deliveryTargetId, messageTemplate) {
21319
- super();
21320
- this.deliveryTargetId = deliveryTargetId;
21321
- this.messageTemplate = messageTemplate;
21322
- }
21323
- };
21324
21306
  var BotReplyRoute = class {
21325
21307
  };
21326
21308
  var OwnerBotReplyRoute = class extends BotReplyRoute {
@@ -21336,94 +21318,6 @@ var BotConnectionReplyRoute = class extends BotReplyRoute {
21336
21318
  this.deliveryTargetId = deliveryTargetId;
21337
21319
  }
21338
21320
  };
21339
- var BotExecutionBindingApprovalRequest = class {
21340
- agentConfigRevision;
21341
- agentRef;
21342
- allowedDeliveryTargets;
21343
- behaviorDigest;
21344
- behaviorInstructions;
21345
- behaviorRevisionId;
21346
- bindingId;
21347
- bindingRevision;
21348
- botId;
21349
- completionPolicy;
21350
- executionConfiguration;
21351
- kind = BOT_BINDING_APPROVAL_REQUEST_KIND;
21352
- requestId;
21353
- requiredCapabilities;
21354
- runtimeId;
21355
- sessionConfigurations;
21356
- workspaceRef;
21357
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, runtimeId, agentRef, workspaceRef, agentConfigRevision, behaviorInstructions, behaviorDigest, requiredCapabilities, allowedDeliveryTargets, completionPolicy, executionConfiguration, sessionConfigurations = []) {
21358
- this.requestId = requestId;
21359
- this.botId = botId;
21360
- this.behaviorRevisionId = behaviorRevisionId;
21361
- this.bindingId = bindingId;
21362
- this.bindingRevision = bindingRevision;
21363
- this.runtimeId = runtimeId;
21364
- this.agentRef = agentRef;
21365
- this.workspaceRef = workspaceRef;
21366
- this.agentConfigRevision = agentConfigRevision;
21367
- this.behaviorInstructions = behaviorInstructions;
21368
- this.behaviorDigest = behaviorDigest;
21369
- this.requiredCapabilities = Object.freeze([...requiredCapabilities]);
21370
- this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
21371
- this.allowedDeliveryTargets = Object.freeze(
21372
- allowedDeliveryTargets.map(
21373
- (target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
21374
- )
21375
- );
21376
- this.completionPolicy = completionPolicy;
21377
- this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
21378
- }
21379
- toJSON() {
21380
- const { sessionConfigurations, ...request } = this;
21381
- return {
21382
- ...request,
21383
- ...sessionConfigurations.length === 0 ? {} : { sessionConfigurations }
21384
- };
21385
- }
21386
- };
21387
- var BotExecutionBindingApprovedEvent = class {
21388
- agentIdentityDigest;
21389
- behaviorRevisionId;
21390
- bindingId;
21391
- bindingRevision;
21392
- botId;
21393
- kind = BOT_BINDING_APPROVED_KIND;
21394
- localGrantId;
21395
- requestId;
21396
- workspaceIdentityDigest;
21397
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, localGrantId, agentIdentityDigest, workspaceIdentityDigest) {
21398
- this.requestId = requestId;
21399
- this.botId = botId;
21400
- this.behaviorRevisionId = behaviorRevisionId;
21401
- this.bindingId = bindingId;
21402
- this.bindingRevision = bindingRevision;
21403
- this.localGrantId = localGrantId;
21404
- this.agentIdentityDigest = agentIdentityDigest;
21405
- this.workspaceIdentityDigest = workspaceIdentityDigest;
21406
- }
21407
- };
21408
- var BotExecutionBindingUnavailableEvent = class {
21409
- behaviorRevisionId;
21410
- bindingId;
21411
- bindingRevision;
21412
- botId;
21413
- code;
21414
- kind = BOT_BINDING_UNAVAILABLE_KIND;
21415
- message;
21416
- requestId;
21417
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, code, message) {
21418
- this.requestId = requestId;
21419
- this.botId = botId;
21420
- this.behaviorRevisionId = behaviorRevisionId;
21421
- this.bindingId = bindingId;
21422
- this.bindingRevision = bindingRevision;
21423
- this.code = code;
21424
- this.message = message;
21425
- }
21426
- };
21427
21321
  var BotSessionPromptCommand = class {
21428
21322
  additionalDirectoryIds;
21429
21323
  agentId;
@@ -21445,7 +21339,6 @@ var BotSessionPromptCommand = class {
21445
21339
  executionConfiguration;
21446
21340
  images;
21447
21341
  kind = BOT_SESSION_PROMPT_KIND;
21448
- localGrantId;
21449
21342
  prompt;
21450
21343
  replyRoute;
21451
21344
  resources;
@@ -21453,7 +21346,7 @@ var BotSessionPromptCommand = class {
21453
21346
  sessionId;
21454
21347
  targetCommandId;
21455
21348
  turnId;
21456
- 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 = "") {
21349
+ 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 = "") {
21457
21350
  this.sessionId = sessionId;
21458
21351
  this.commandId = commandId;
21459
21352
  this.agentId = agentId;
@@ -21473,7 +21366,6 @@ var BotSessionPromptCommand = class {
21473
21366
  this.turnId = turnId;
21474
21367
  this.behaviorRevisionId = behaviorRevisionId;
21475
21368
  this.bindingRevision = bindingRevision;
21476
- this.localGrantId = localGrantId;
21477
21369
  this.behaviorInstructions = behaviorInstructions;
21478
21370
  this.behaviorDigest = behaviorDigest;
21479
21371
  this.allowedDeliveryTargets = Object.freeze(
@@ -21617,24 +21509,6 @@ function readSessionConfigurations(value) {
21617
21509
  }
21618
21510
  return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
21619
21511
  }
21620
- function readCompletionPolicy(value) {
21621
- if (!isRecord3(value)) {
21622
- throw new ProtocolMessageError("Invalid Bot completion policy");
21623
- }
21624
- const kind = readText2(value, "kind", 32, false);
21625
- if (kind === "none") {
21626
- assertExactKeys2(value, ["kind"]);
21627
- return new NoBotCompletionDeliveryPolicy();
21628
- }
21629
- if (kind === "required") {
21630
- assertExactKeys2(value, ["deliveryTargetId", "kind", "messageTemplate"]);
21631
- return new RequiredBotCompletionDeliveryPolicy(
21632
- readIdentifier2(value, "deliveryTargetId"),
21633
- readText2(value, "messageTemplate", 1e4, false)
21634
- );
21635
- }
21636
- throw new ProtocolMessageError("Invalid Bot completion policy");
21637
- }
21638
21512
  function readReplyRoute(value) {
21639
21513
  if (!isRecord3(value)) {
21640
21514
  throw new ProtocolMessageError("Invalid Bot reply route");
@@ -21653,110 +21527,6 @@ function readReplyRoute(value) {
21653
21527
  }
21654
21528
  throw new ProtocolMessageError("Invalid Bot reply route");
21655
21529
  }
21656
- function decodeBotExecutionBindingApprovalRequest(encoded) {
21657
- const value = parseJson3(encoded);
21658
- assertKeysWithOptional(
21659
- value,
21660
- [
21661
- "agentConfigRevision",
21662
- "agentRef",
21663
- "allowedDeliveryTargets",
21664
- "behaviorDigest",
21665
- "behaviorInstructions",
21666
- "behaviorRevisionId",
21667
- "bindingId",
21668
- "bindingRevision",
21669
- "botId",
21670
- "completionPolicy",
21671
- "executionConfiguration",
21672
- "kind",
21673
- "requestId",
21674
- "requiredCapabilities",
21675
- "runtimeId",
21676
- "workspaceRef"
21677
- ],
21678
- ["sessionConfigurations"]
21679
- );
21680
- if (value["kind"] !== BOT_BINDING_APPROVAL_REQUEST_KIND) {
21681
- throw new ProtocolMessageError("Invalid Bot binding approval request kind");
21682
- }
21683
- return new BotExecutionBindingApprovalRequest(
21684
- readIdentifier2(value, "requestId"),
21685
- readIdentifier2(value, "botId"),
21686
- readIdentifier2(value, "behaviorRevisionId"),
21687
- readIdentifier2(value, "bindingId"),
21688
- readInteger(value, "bindingRevision"),
21689
- readIdentifier2(value, "runtimeId"),
21690
- readIdentifier2(value, "agentRef"),
21691
- readDirectoryIdentifier2(value, "workspaceRef"),
21692
- readInteger(value, "agentConfigRevision"),
21693
- readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21694
- readDigest(value, "behaviorDigest"),
21695
- readIdentifiers(value, "requiredCapabilities", 32),
21696
- readTargets(value, "allowedDeliveryTargets"),
21697
- readCompletionPolicy(value["completionPolicy"]),
21698
- decodeAgentExecutionConfiguration(value["executionConfiguration"]),
21699
- readSessionConfigurations(value)
21700
- );
21701
- }
21702
- function decodeBotExecutionBindingApprovedEvent(encoded) {
21703
- const value = parseJson3(encoded);
21704
- assertExactKeys2(value, [
21705
- "agentIdentityDigest",
21706
- "behaviorRevisionId",
21707
- "bindingId",
21708
- "bindingRevision",
21709
- "botId",
21710
- "kind",
21711
- "localGrantId",
21712
- "requestId",
21713
- "workspaceIdentityDigest"
21714
- ]);
21715
- if (value["kind"] !== BOT_BINDING_APPROVED_KIND) {
21716
- throw new ProtocolMessageError("Invalid Bot binding approval event kind");
21717
- }
21718
- return new BotExecutionBindingApprovedEvent(
21719
- readIdentifier2(value, "requestId"),
21720
- readIdentifier2(value, "botId"),
21721
- readIdentifier2(value, "behaviorRevisionId"),
21722
- readIdentifier2(value, "bindingId"),
21723
- readInteger(value, "bindingRevision"),
21724
- readIdentifier2(value, "localGrantId"),
21725
- readDigest(value, "agentIdentityDigest"),
21726
- readDigest(value, "workspaceIdentityDigest")
21727
- );
21728
- }
21729
- function encodeBotExecutionBindingApprovedEvent(event) {
21730
- return JSON.stringify(decodeBotExecutionBindingApprovedEvent(JSON.stringify(event)));
21731
- }
21732
- function decodeBotExecutionBindingUnavailableEvent(encoded) {
21733
- const value = parseJson3(encoded);
21734
- assertExactKeys2(value, [
21735
- "behaviorRevisionId",
21736
- "bindingId",
21737
- "bindingRevision",
21738
- "botId",
21739
- "code",
21740
- "kind",
21741
- "message",
21742
- "requestId"
21743
- ]);
21744
- if (value["kind"] !== BOT_BINDING_UNAVAILABLE_KIND) {
21745
- throw new ProtocolMessageError("Invalid Bot binding unavailable event kind");
21746
- }
21747
- return new BotExecutionBindingUnavailableEvent(
21748
- readIdentifier2(value, "requestId"),
21749
- readIdentifier2(value, "botId"),
21750
- readIdentifier2(value, "behaviorRevisionId"),
21751
- readIdentifier2(value, "bindingId"),
21752
- readInteger(value, "bindingRevision"),
21753
- readIdentifier2(value, "code"),
21754
- readText2(value, "message", 500, false)
21755
- );
21756
- }
21757
- function encodeBotExecutionBindingUnavailableEvent(event) {
21758
- return JSON.stringify(decodeBotExecutionBindingUnavailableEvent(JSON.stringify(event)));
21759
- }
21760
21530
  function decodeBotSessionPromptCommand(encoded) {
21761
21531
  const value = parseJson3(encoded);
21762
21532
  assertKeysWithOptional(
@@ -21781,7 +21551,6 @@ function decodeBotSessionPromptCommand(encoded) {
21781
21551
  "executionConfiguration",
21782
21552
  "images",
21783
21553
  "kind",
21784
- "localGrantId",
21785
21554
  "prompt",
21786
21555
  "replyRoute",
21787
21556
  "resources",
@@ -21827,7 +21596,6 @@ function decodeBotSessionPromptCommand(encoded) {
21827
21596
  readIdentifier2(value, "turnId"),
21828
21597
  readIdentifier2(value, "behaviorRevisionId"),
21829
21598
  readInteger(value, "bindingRevision"),
21830
- readIdentifier2(value, "localGrantId"),
21831
21599
  readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21832
21600
  readDigest(value, "behaviorDigest"),
21833
21601
  readTargets(value, "allowedDeliveryTargets"),
@@ -23545,7 +23313,7 @@ function isContainedPath3(root, candidate) {
23545
23313
  }
23546
23314
  async function hashFile(path2, signal) {
23547
23315
  signal.throwIfAborted();
23548
- const digest2 = createHash("sha256");
23316
+ const digest = createHash("sha256");
23549
23317
  const stream = createReadStream(path2, { signal });
23550
23318
  try {
23551
23319
  for await (const chunk of stream) {
@@ -23556,9 +23324,9 @@ async function hashFile(path2, signal) {
23556
23324
  "The managed Agent archive produced invalid bytes"
23557
23325
  );
23558
23326
  }
23559
- digest2.update(chunk);
23327
+ digest.update(chunk);
23560
23328
  }
23561
- return digest2.digest("hex");
23329
+ return digest.digest("hex");
23562
23330
  } catch (error62) {
23563
23331
  if (signal.aborted) {
23564
23332
  signal.throwIfAborted();
@@ -24571,7 +24339,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = []) {
24571
24339
  }
24572
24340
 
24573
24341
  // src/run-daemon.ts
24574
- import { randomUUID as randomUUID4 } from "node:crypto";
24342
+ import { randomUUID as randomUUID3 } from "node:crypto";
24575
24343
  import { basename as basename5, join as join16 } from "node:path";
24576
24344
  import { styleText } from "node:util";
24577
24345
  import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
@@ -37297,10 +37065,7 @@ var WorkspaceDirectoryService = class {
37297
37065
  };
37298
37066
  };
37299
37067
 
37300
- // src/bots/local-bot-grant-store.ts
37301
- import { createHash as createHash3, randomUUID } from "node:crypto";
37302
- import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
37303
- var LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS = 90 * 24 * 60 * 60 * 1e3;
37068
+ // src/bots/local-bot-execution-authorizer.ts
37304
37069
  var LocalBotAuthorizationError = class extends Error {
37305
37070
  code;
37306
37071
  constructor(code, message, options = {}) {
@@ -37309,325 +37074,40 @@ var LocalBotAuthorizationError = class extends Error {
37309
37074
  this.name = "LocalBotAuthorizationError";
37310
37075
  }
37311
37076
  };
37312
- var LocalBotGrant = class {
37077
+ var AuthorizedLocalBotExecution = class {
37313
37078
  agent;
37314
- agentIdentityDigest;
37315
- allowedDeliveryTargetIds;
37316
37079
  behaviorDigest;
37317
37080
  behaviorRevisionId;
37318
37081
  bindingId;
37319
37082
  bindingRevision;
37320
37083
  botId;
37321
- expiresAt;
37322
37084
  executionConfiguration;
37323
- localGrantId;
37324
- revocationEpoch;
37325
- workspaceIdentityDigest;
37326
37085
  workspacePath;
37327
37086
  workspaceRef;
37328
- constructor(localGrantId, botId, behaviorRevisionId, behaviorDigest, bindingId, bindingRevision, agent, agentIdentityDigest, workspaceRef, workspacePath, workspaceIdentityDigest, allowedDeliveryTargetIds, executionConfiguration, expiresAt, revocationEpoch) {
37329
- this.localGrantId = localGrantId;
37330
- this.botId = botId;
37331
- this.behaviorRevisionId = behaviorRevisionId;
37332
- this.behaviorDigest = behaviorDigest;
37333
- this.bindingId = bindingId;
37334
- this.bindingRevision = bindingRevision;
37087
+ constructor(command, agent, workspacePath) {
37335
37088
  this.agent = agent;
37336
- this.agentIdentityDigest = agentIdentityDigest;
37337
- this.workspaceRef = workspaceRef;
37089
+ this.behaviorDigest = command.behaviorDigest;
37090
+ this.behaviorRevisionId = command.behaviorRevisionId;
37091
+ this.bindingId = command.bindingId;
37092
+ this.bindingRevision = command.bindingRevision;
37093
+ this.botId = command.botId;
37094
+ this.executionConfiguration = command.executionConfiguration;
37338
37095
  this.workspacePath = workspacePath;
37339
- this.workspaceIdentityDigest = workspaceIdentityDigest;
37340
- this.allowedDeliveryTargetIds = Object.freeze([...allowedDeliveryTargetIds]);
37341
- this.executionConfiguration = executionConfiguration;
37342
- this.expiresAt = expiresAt;
37343
- this.revocationEpoch = revocationEpoch;
37096
+ this.workspaceRef = command.directoryId;
37344
37097
  }
37345
37098
  };
37346
- function digest(value) {
37347
- return createHash3("sha256").update(value, "utf8").digest("hex");
37348
- }
37349
- function agentDigest(agent) {
37350
- return digest(
37351
- JSON.stringify({
37352
- adapter: agent.adapterIdentity,
37353
- agent: agent.agentIdentity,
37354
- agentVersion: agent.agentVersion,
37355
- arguments: agent.arguments,
37356
- id: agent.id
37357
- })
37358
- );
37359
- }
37360
- function configurePermission(agent, permissionMode) {
37361
- try {
37362
- return agent.withPermissionMode(permissionMode);
37363
- } catch (cause) {
37364
- if (cause instanceof AgentPermissionConfigurationError) {
37365
- throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
37366
- }
37367
- throw cause;
37368
- }
37369
- }
37370
- function workspaceDigest(path2) {
37371
- return digest(path2);
37372
- }
37373
- function exactTargets(left, right) {
37374
- if (left.length !== right.length) {
37375
- return false;
37376
- }
37377
- const expected = [...left].sort();
37378
- const actual = [...right].sort();
37379
- return expected.every((target, index2) => target === actual[index2]);
37380
- }
37381
- function exactSessionConfigurations(left, right) {
37382
- if (left.length !== right.length) {
37383
- return false;
37384
- }
37385
- const expected = new Map(left.map((selection) => [selection.configId, selection]));
37386
- return right.every((selection) => {
37387
- const approved = expected.get(selection.configId);
37388
- return approved !== void 0 && approved.booleanValue === selection.booleanValue && approved.value === selection.value && approved.valueType === selection.valueType;
37389
- });
37390
- }
37391
- function exactExecutionConfiguration(left, right) {
37392
- return left.permissionMode === right.permissionMode && exactSessionConfigurations([left.model, left.reasoningEffort], [right.model, right.reasoningEffort]);
37393
- }
37394
- function rowString(row, key) {
37395
- const value = Reflect.get(row, key);
37396
- if (typeof value !== "string") {
37397
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
37398
- }
37399
- return value;
37400
- }
37401
- function rowInteger(row, key) {
37402
- const value = Reflect.get(row, key);
37403
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
37404
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
37405
- }
37406
- return value;
37407
- }
37408
- function rowHasInteger(row, key) {
37409
- const value = Reflect.get(row, key);
37410
- if (value === null) {
37411
- return false;
37412
- }
37413
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
37414
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
37415
- }
37416
- return true;
37417
- }
37418
- function parseTargets(encoded) {
37419
- let value;
37420
- try {
37421
- value = JSON.parse(encoded);
37422
- } catch (cause) {
37423
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
37424
- }
37425
- if (!Array.isArray(value) || value.some((target) => typeof target !== "string")) {
37426
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
37427
- }
37428
- return value.filter((target) => typeof target === "string");
37429
- }
37430
- function parseSessionConfigurations(encoded) {
37431
- let value;
37432
- try {
37433
- value = JSON.parse(encoded);
37434
- return decodeSessionConfigurationSelections(value);
37435
- } catch (cause) {
37436
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
37437
- }
37438
- }
37439
- function parseExecutionConfiguration(encoded) {
37440
- let value;
37441
- try {
37442
- value = JSON.parse(encoded);
37443
- return decodeAgentExecutionConfiguration(value);
37444
- } catch (cause) {
37445
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
37446
- }
37447
- }
37448
- var LocalBotGrantStore = class {
37449
- #database;
37450
- constructor(path2) {
37451
- this.#database = new DatabaseSync3(path2);
37452
- this.#database.exec(`
37453
- CREATE TABLE IF NOT EXISTS local_bot_grants (
37454
- local_grant_id TEXT PRIMARY KEY,
37455
- bot_id TEXT NOT NULL,
37456
- behavior_revision_id TEXT NOT NULL,
37457
- behavior_digest TEXT NOT NULL,
37458
- binding_id TEXT NOT NULL UNIQUE,
37459
- binding_revision INTEGER NOT NULL,
37460
- agent_ref TEXT NOT NULL,
37461
- agent_identity_digest TEXT NOT NULL,
37462
- workspace_ref TEXT NOT NULL,
37463
- workspace_path TEXT NOT NULL,
37464
- workspace_identity_digest TEXT NOT NULL,
37465
- allowed_delivery_target_ids_json TEXT NOT NULL,
37466
- unattended_policy_json TEXT NOT NULL,
37467
- created_at INTEGER NOT NULL,
37468
- expires_at INTEGER NOT NULL,
37469
- revocation_epoch INTEGER NOT NULL DEFAULT 0,
37470
- revoked_at INTEGER
37471
- ) STRICT;
37472
- CREATE TABLE IF NOT EXISTS local_bot_binding_resolutions (
37473
- request_id TEXT PRIMARY KEY,
37474
- binding_id TEXT NOT NULL,
37475
- local_grant_id TEXT NOT NULL,
37476
- resolved_at INTEGER NOT NULL,
37477
- result TEXT NOT NULL CHECK (result IN ('approved', 'unavailable')),
37478
- error_code TEXT,
37479
- error_message TEXT
37480
- ) STRICT;
37481
- CREATE TABLE IF NOT EXISTS local_bot_grant_configurations (
37482
- local_grant_id TEXT PRIMARY KEY,
37483
- session_configurations_json TEXT NOT NULL
37484
- ) STRICT;
37485
- CREATE TABLE IF NOT EXISTS local_bot_grant_execution_configurations (
37486
- local_grant_id TEXT PRIMARY KEY,
37487
- execution_configuration_json TEXT NOT NULL
37488
- ) STRICT;
37489
- `);
37490
- }
37491
- approve = async (request, catalog, directories, bindingAuthorityId, now, signal) => {
37099
+ var LocalBotExecutionAuthorizer = class {
37100
+ authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
37492
37101
  signal.throwIfAborted();
37493
- const existing = this.#database.prepare(
37494
- `SELECT grants.* FROM local_bot_binding_resolutions AS resolutions
37495
- INNER JOIN local_bot_grants AS grants
37496
- ON grants.local_grant_id = resolutions.local_grant_id
37497
- WHERE resolutions.request_id = ? AND resolutions.binding_id = ?
37498
- AND resolutions.result = 'approved'`
37499
- ).get(request.requestId, request.bindingId);
37500
- if (existing !== void 0) {
37501
- return new BotExecutionBindingApprovedEvent(
37502
- request.requestId,
37503
- request.botId,
37504
- request.behaviorRevisionId,
37505
- request.bindingId,
37506
- request.bindingRevision,
37507
- rowString(existing, "local_grant_id"),
37508
- rowString(existing, "agent_identity_digest"),
37509
- rowString(existing, "workspace_identity_digest")
37510
- );
37511
- }
37512
- const resolved = await this.resolveProposal(request, catalog, directories, bindingAuthorityId, signal);
37513
- const localGrantId = `lbg_${randomUUID()}`;
37514
- const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
37515
- this.#database.exec("BEGIN IMMEDIATE");
37102
+ let agent;
37516
37103
  try {
37517
- this.#database.prepare(
37518
- `INSERT INTO local_bot_grants (
37519
- local_grant_id, bot_id, behavior_revision_id, behavior_digest,
37520
- binding_id, binding_revision, agent_ref,
37521
- agent_identity_digest, workspace_ref, workspace_path,
37522
- workspace_identity_digest, allowed_delivery_target_ids_json,
37523
- unattended_policy_json, created_at, expires_at
37524
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
37525
- ).run(
37526
- localGrantId,
37527
- request.botId,
37528
- request.behaviorRevisionId,
37529
- request.behaviorDigest,
37530
- request.bindingId,
37531
- request.bindingRevision,
37532
- request.agentRef,
37533
- resolved.agentIdentityDigest,
37534
- request.workspaceRef,
37535
- resolved.workspacePath,
37536
- resolved.workspaceIdentityDigest,
37537
- JSON.stringify(request.allowedDeliveryTargets.map((target) => target.deliveryTargetId)),
37538
- JSON.stringify({ localSideEffects: "owner-approval-required" }),
37539
- now,
37540
- expiresAt
37541
- );
37542
- this.#database.prepare(
37543
- `INSERT INTO local_bot_grant_configurations (
37544
- local_grant_id, session_configurations_json
37545
- ) VALUES (?, ?)`
37546
- ).run(localGrantId, JSON.stringify(request.sessionConfigurations));
37547
- this.#database.prepare(
37548
- `INSERT INTO local_bot_grant_execution_configurations (
37549
- local_grant_id, execution_configuration_json
37550
- ) VALUES (?, ?)`
37551
- ).run(localGrantId, JSON.stringify(request.executionConfiguration));
37552
- this.#database.prepare(
37553
- `INSERT INTO local_bot_binding_resolutions (
37554
- request_id, binding_id, local_grant_id, resolved_at, result
37555
- ) VALUES (?, ?, ?, ?, 'approved')`
37556
- ).run(request.requestId, request.bindingId, localGrantId, now);
37557
- this.#database.exec("COMMIT");
37104
+ agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
37558
37105
  } catch (cause) {
37559
- this.#database.exec("ROLLBACK");
37106
+ if (cause instanceof AgentPermissionConfigurationError) {
37107
+ throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
37108
+ }
37560
37109
  throw cause;
37561
37110
  }
37562
- signal.throwIfAborted();
37563
- return new BotExecutionBindingApprovedEvent(
37564
- request.requestId,
37565
- request.botId,
37566
- request.behaviorRevisionId,
37567
- request.bindingId,
37568
- request.bindingRevision,
37569
- localGrantId,
37570
- resolved.agentIdentityDigest,
37571
- resolved.workspaceIdentityDigest
37572
- );
37573
- };
37574
- resolveExecution = async (command, catalog, directories, bindingAuthorityId, now, signal) => {
37575
- signal.throwIfAborted();
37576
- const row = this.#database.prepare(
37577
- `SELECT grants.*, COALESCE(configurations.session_configurations_json, '[]')
37578
- AS session_configurations_json,
37579
- COALESCE(execution.execution_configuration_json, ?)
37580
- AS execution_configuration_json
37581
- FROM local_bot_grants AS grants
37582
- LEFT JOIN local_bot_grant_configurations AS configurations
37583
- ON configurations.local_grant_id = grants.local_grant_id
37584
- LEFT JOIN local_bot_grant_execution_configurations AS execution
37585
- ON execution.local_grant_id = grants.local_grant_id
37586
- WHERE grants.local_grant_id = ? AND grants.bot_id = ?
37587
- AND behavior_revision_id = ? AND behavior_digest = ?
37588
- AND binding_id = ? AND binding_revision = ?
37589
- AND agent_ref = ?`
37590
- ).get(
37591
- JSON.stringify(DEFAULT_AGENT_EXECUTION_CONFIGURATION),
37592
- command.localGrantId,
37593
- command.botId,
37594
- command.behaviorRevisionId,
37595
- command.behaviorDigest,
37596
- command.bindingId,
37597
- command.bindingRevision,
37598
- command.agentId
37599
- );
37600
- if (row === void 0) {
37601
- throw new LocalBotAuthorizationError(
37602
- "binding_not_approved",
37603
- "The Bot execution binding is not locally approved"
37604
- );
37605
- }
37606
- const approvedTargets = parseTargets(rowString(row, "allowed_delivery_target_ids_json"));
37607
- const requestedTargets = command.allowedDeliveryTargets.map((target) => target.deliveryTargetId);
37608
- if (!exactTargets(approvedTargets, requestedTargets)) {
37609
- throw new LocalBotAuthorizationError(
37610
- "binding_not_approved",
37611
- "The Bot execution target policy differs from its binding"
37612
- );
37613
- }
37614
- const approvedConfigurations = parseSessionConfigurations(rowString(row, "session_configurations_json"));
37615
- if (!exactSessionConfigurations(approvedConfigurations, command.sessionConfigurations)) {
37616
- throw new LocalBotAuthorizationError(
37617
- "binding_not_approved",
37618
- "The Bot Agent configuration differs from its binding"
37619
- );
37620
- }
37621
- const approvedExecutionConfiguration = parseExecutionConfiguration(
37622
- rowString(row, "execution_configuration_json")
37623
- );
37624
- if (!exactExecutionConfiguration(approvedExecutionConfiguration, command.executionConfiguration)) {
37625
- throw new LocalBotAuthorizationError(
37626
- "binding_not_approved",
37627
- "The Bot execution configuration differs from its binding"
37628
- );
37629
- }
37630
- const agent = configurePermission(catalog.find(command.agentId), command.executionConfiguration.permissionMode);
37631
37111
  const [adapterUnchanged, agentUnchanged] = await Promise.all([
37632
37112
  revalidateExecutable(agent.adapterIdentity),
37633
37113
  revalidateExecutable(agent.agentIdentity)
@@ -37639,150 +37119,15 @@ var LocalBotGrantStore = class {
37639
37119
  "The local Agent executable changed while the Runtime is active; restart the Runtime"
37640
37120
  );
37641
37121
  }
37642
- const workspaceRef = rowString(row, "workspace_ref");
37643
- const workspacePath = await directories.resolve(bindingAuthorityId, workspaceRef, signal);
37644
- const currentAgentDigest = agentDigest(agent);
37645
- const currentWorkspaceDigest = workspaceDigest(workspacePath);
37646
- signal.throwIfAborted();
37647
- let expiresAt = rowInteger(row, "expires_at");
37648
- let revocationEpoch = rowInteger(row, "revocation_epoch");
37649
- if (currentAgentDigest !== rowString(row, "agent_identity_digest") || currentWorkspaceDigest !== rowString(row, "workspace_identity_digest") || workspacePath !== rowString(row, "workspace_path") || expiresAt <= now || rowHasInteger(row, "revoked_at")) {
37650
- const refreshed = this.refreshTarget(
37651
- rowString(row, "local_grant_id"),
37652
- currentAgentDigest,
37653
- currentWorkspaceDigest,
37654
- workspacePath,
37655
- now
37656
- );
37657
- expiresAt = refreshed.expiresAt;
37658
- revocationEpoch = refreshed.revocationEpoch;
37659
- }
37660
37122
  if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
37661
37123
  throw new LocalBotAuthorizationError(
37662
37124
  "binding_incompatible",
37663
- "The local Agent cannot apply the approved Bot behavior"
37664
- );
37665
- }
37666
- return new LocalBotGrant(
37667
- rowString(row, "local_grant_id"),
37668
- command.botId,
37669
- command.behaviorRevisionId,
37670
- command.behaviorDigest,
37671
- command.bindingId,
37672
- command.bindingRevision,
37673
- agent,
37674
- currentAgentDigest,
37675
- workspaceRef,
37676
- workspacePath,
37677
- currentWorkspaceDigest,
37678
- approvedTargets,
37679
- approvedExecutionConfiguration,
37680
- expiresAt,
37681
- revocationEpoch
37682
- );
37683
- };
37684
- recordUnavailable = (request, code, message, now) => {
37685
- this.#database.prepare(
37686
- `INSERT OR IGNORE INTO local_bot_binding_resolutions (
37687
- request_id, binding_id, local_grant_id, resolved_at,
37688
- result, error_code, error_message
37689
- ) VALUES (?, ?, '', ?, 'unavailable', ?, ?)`
37690
- ).run(request.requestId, request.bindingId, now, code, message);
37691
- };
37692
- close = () => {
37693
- this.#database.close();
37694
- };
37695
- resolveProposal = async (request, catalog, directories, bindingAuthorityId, signal) => {
37696
- const agent = configurePermission(
37697
- catalog.find(request.agentRef),
37698
- request.executionConfiguration.permissionMode
37699
- );
37700
- if (request.requiredCapabilities.includes("embedded-context") && !agent.capabilities.embeddedContextPrompt) {
37701
- throw new LocalBotAuthorizationError(
37702
- "binding_incompatible",
37703
- "The local Agent cannot apply embedded Bot context"
37704
- );
37705
- }
37706
- if (request.requiredCapabilities.some((capability) => capability !== "embedded-context")) {
37707
- throw new LocalBotAuthorizationError(
37708
- "binding_incompatible",
37709
- "The Bot requires an unsupported local Agent capability"
37125
+ "The local Agent cannot apply the Bot behavior"
37710
37126
  );
37711
37127
  }
37712
- const [adapterUnchanged, agentUnchanged] = await Promise.all([
37713
- revalidateExecutable(agent.adapterIdentity),
37714
- revalidateExecutable(agent.agentIdentity)
37715
- ]);
37128
+ const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
37716
37129
  signal.throwIfAborted();
37717
- if (!adapterUnchanged || !agentUnchanged) {
37718
- throw new LocalBotAuthorizationError(
37719
- "binding_incompatible",
37720
- "The local Agent executable changed before approval"
37721
- );
37722
- }
37723
- const workspacePath = await directories.resolve(bindingAuthorityId, request.workspaceRef, signal);
37724
- return {
37725
- agent,
37726
- agentIdentityDigest: agentDigest(agent),
37727
- workspaceIdentityDigest: workspaceDigest(workspacePath),
37728
- workspacePath
37729
- };
37730
- };
37731
- refreshTarget = (localGrantId, agentIdentityDigest, workspaceIdentityDigest, workspacePath, now) => {
37732
- const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
37733
- this.#database.exec("BEGIN IMMEDIATE");
37734
- try {
37735
- const current = this.#database.prepare("SELECT * FROM local_bot_grants WHERE local_grant_id = ?").get(localGrantId);
37736
- if (current === void 0) {
37737
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is missing");
37738
- }
37739
- const currentExpiresAt = rowInteger(current, "expires_at");
37740
- const currentRevocationEpoch = rowInteger(current, "revocation_epoch");
37741
- if (agentIdentityDigest === rowString(current, "agent_identity_digest") && workspaceIdentityDigest === rowString(current, "workspace_identity_digest") && workspacePath === rowString(current, "workspace_path") && currentExpiresAt > now && !rowHasInteger(current, "revoked_at")) {
37742
- this.#database.exec("COMMIT");
37743
- return { expiresAt: currentExpiresAt, revocationEpoch: currentRevocationEpoch };
37744
- }
37745
- const result = this.#database.prepare(
37746
- `UPDATE local_bot_grants
37747
- SET agent_identity_digest = ?, workspace_identity_digest = ?, workspace_path = ?,
37748
- expires_at = ?, revoked_at = NULL, revocation_epoch = revocation_epoch + 1
37749
- WHERE local_grant_id = ? AND revocation_epoch = ?`
37750
- ).run(
37751
- agentIdentityDigest,
37752
- workspaceIdentityDigest,
37753
- workspacePath,
37754
- expiresAt,
37755
- localGrantId,
37756
- currentRevocationEpoch
37757
- );
37758
- if (result.changes !== 1) {
37759
- throw new LocalBotAuthorizationError(
37760
- "local_grant_invalid",
37761
- "The local Bot grant target could not be refreshed"
37762
- );
37763
- }
37764
- this.#database.prepare(
37765
- `INSERT INTO audit_events (recorded_at, event, command_id, session_id, details_json)
37766
- VALUES (?, 'bot_binding_target_refreshed', ?, '', ?)`
37767
- ).run(
37768
- new Date(now).toISOString(),
37769
- rowString(current, "binding_id"),
37770
- JSON.stringify({
37771
- agentIdentityChanged: agentIdentityDigest !== rowString(current, "agent_identity_digest"),
37772
- bindingId: rowString(current, "binding_id"),
37773
- botId: rowString(current, "bot_id"),
37774
- expired: currentExpiresAt <= now,
37775
- revived: rowHasInteger(current, "revoked_at"),
37776
- workspaceIdentityChanged: workspaceIdentityDigest !== rowString(current, "workspace_identity_digest"),
37777
- workspacePathChanged: workspacePath !== rowString(current, "workspace_path")
37778
- })
37779
- );
37780
- this.#database.exec("COMMIT");
37781
- return { expiresAt, revocationEpoch: currentRevocationEpoch + 1 };
37782
- } catch (cause) {
37783
- this.#database.exec("ROLLBACK");
37784
- throw cause;
37785
- }
37130
+ return new AuthorizedLocalBotExecution(command, agent, workspacePath);
37786
37131
  };
37787
37132
  };
37788
37133
 
@@ -37794,18 +37139,18 @@ var AppliedBotContext = class {
37794
37139
  }
37795
37140
  };
37796
37141
  var EmbeddedBotContextApplicator = class {
37797
- apply = async (command, grant, resources, signal) => {
37142
+ apply = async (command, execution, resources, signal) => {
37798
37143
  signal.throwIfAborted();
37799
- if (grant.botId !== command.botId || grant.behaviorRevisionId !== command.behaviorRevisionId || grant.behaviorDigest !== command.behaviorDigest) {
37144
+ if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
37800
37145
  throw new LocalBotAuthorizationError(
37801
- "binding_not_approved",
37802
- "The Bot behavior does not match its local authorization"
37146
+ "binding_incompatible",
37147
+ "The Bot behavior does not match the execution target"
37803
37148
  );
37804
37149
  }
37805
37150
  if (command.behaviorInstructions.length === 0) {
37806
37151
  return new AppliedBotContext(resources);
37807
37152
  }
37808
- if (!grant.agent.capabilities.embeddedContextPrompt) {
37153
+ if (!execution.agent.capabilities.embeddedContextPrompt) {
37809
37154
  throw new LocalBotAuthorizationError(
37810
37155
  "binding_incompatible",
37811
37156
  "The local Agent cannot enforce the Bot behavior context"
@@ -38158,7 +37503,7 @@ var BotOutboundIpcServer = class {
38158
37503
  };
38159
37504
 
38160
37505
  // src/native-sessions/service.ts
38161
- import { randomUUID as randomUUID2 } from "node:crypto";
37506
+ import { randomUUID } from "node:crypto";
38162
37507
  import { basename as basename4 } from "node:path";
38163
37508
 
38164
37509
  // src/native-sessions/codex-history.ts
@@ -38453,7 +37798,7 @@ var NativeSessionService = class {
38453
37798
  if (authorized === null) {
38454
37799
  return null;
38455
37800
  }
38456
- const entryId = randomUUID2();
37801
+ const entryId = randomUUID();
38457
37802
  if (this.#entries.size >= 5e3) {
38458
37803
  this.#entries.clear();
38459
37804
  }
@@ -38507,7 +37852,7 @@ var NativeSessionService = class {
38507
37852
  "invalid_native_session_response"
38508
37853
  );
38509
37854
  }
38510
- nextCursor = randomUUID2();
37855
+ nextCursor = randomUUID();
38511
37856
  if (this.#cursors.size >= 500) {
38512
37857
  this.#cursors.clear();
38513
37858
  }
@@ -38825,7 +38170,7 @@ var NativeSessionService = class {
38825
38170
  };
38826
38171
 
38827
38172
  // src/prompt-artifact-resolver.ts
38828
- import { createHash as createHash4 } from "node:crypto";
38173
+ import { createHash as createHash3 } from "node:crypto";
38829
38174
  import { fetch as fetch5 } from "undici";
38830
38175
  var ARTIFACT_SCHEME = "mobius-artifact:";
38831
38176
  var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
@@ -38964,7 +38309,7 @@ async function download(config2, command, reference, signal) {
38964
38309
  );
38965
38310
  }
38966
38311
  const bytes = await responseBytes(response, reference.byteLength, requestSignal);
38967
- if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
38312
+ if (createHash3("sha256").update(bytes).digest("hex") !== reference.sha256) {
38968
38313
  throw new PromptArtifactError(
38969
38314
  "artifact_integrity_failed",
38970
38315
  "The prompt artifact failed integrity validation"
@@ -39273,7 +38618,7 @@ var RelayConnectionDiagnostics = class {
39273
38618
  };
39274
38619
 
39275
38620
  // src/relay-connection/liveness.ts
39276
- import { randomUUID as randomUUID3 } from "node:crypto";
38621
+ import { randomUUID as randomUUID2 } from "node:crypto";
39277
38622
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
39278
38623
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
39279
38624
  var RelayLivenessState = class {
@@ -39362,7 +38707,7 @@ var RelayConnectionLiveness = class {
39362
38707
  }
39363
38708
  throw new Error("Heartbeat was scheduled in an invalid state");
39364
38709
  }
39365
- const heartbeatId = randomUUID3();
38710
+ const heartbeatId = randomUUID2();
39366
38711
  this.#state = new AwaitingHeartbeatAckState(
39367
38712
  heartbeatId,
39368
38713
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -39379,7 +38724,7 @@ var RelayConnectionLiveness = class {
39379
38724
  // src/relay-connection/session-event-outbox.ts
39380
38725
  import { mkdirSync as mkdirSync3 } from "node:fs";
39381
38726
  import { dirname as dirname7 } from "node:path";
39382
- import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
38727
+ import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
39383
38728
  var DEFAULT_OUTBOX_LIMITS = {
39384
38729
  criticalEventBytes: 136 * 1024 * 1024,
39385
38730
  runtimeDeliveryBytes: 64 * 1024 * 1024,
@@ -39431,7 +38776,7 @@ function rowNumber(row, field) {
39431
38776
  }
39432
38777
  return value;
39433
38778
  }
39434
- function rowString2(row, field) {
38779
+ function rowString(row, field) {
39435
38780
  const value = typeof row === "object" && row !== null ? Reflect.get(row, field) : void 0;
39436
38781
  if (typeof value !== "string" || value.length === 0) {
39437
38782
  throw new Error(`SQLite returned an invalid ${field} value`);
@@ -39445,7 +38790,7 @@ var SessionEventOutbox = class {
39445
38790
  validateLimits(limits);
39446
38791
  this.#limits = limits;
39447
38792
  mkdirSync3(dirname7(path2), { recursive: true });
39448
- this.#database = new DatabaseSync4(path2);
38793
+ this.#database = new DatabaseSync3(path2);
39449
38794
  this.#database.exec(`
39450
38795
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
39451
38796
  ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -39680,8 +39025,8 @@ var SessionEventOutbox = class {
39680
39025
  WHERE delivery_id = ?`
39681
39026
  ).get(delivery.deliveryId);
39682
39027
  if (existing !== void 0) {
39683
- const sessionId = rowString2(existing, "session_id");
39684
- const payload = rowString2(existing, "payload_json");
39028
+ const sessionId = rowString(existing, "session_id");
39029
+ const payload = rowString(existing, "payload_json");
39685
39030
  const state = runtimeDeliveryState(existing);
39686
39031
  if (sessionId !== delivery.sessionId || payload !== delivery.payload) {
39687
39032
  throw new Error("The Runtime delivery identity conflicts with its durable receipt");
@@ -39769,9 +39114,9 @@ var SessionEventOutbox = class {
39769
39114
  ORDER BY received_at, delivery_id`
39770
39115
  ).all().map(
39771
39116
  (row) => new StoredRuntimeDelivery(
39772
- rowString2(row, "delivery_id"),
39773
- rowString2(row, "session_id"),
39774
- rowString2(row, "payload_json"),
39117
+ rowString(row, "delivery_id"),
39118
+ rowString(row, "session_id"),
39119
+ rowString(row, "payload_json"),
39775
39120
  runtimeDeliveryState(row),
39776
39121
  true
39777
39122
  )
@@ -39953,7 +39298,7 @@ function validateLimits(limits) {
39953
39298
  }
39954
39299
  }
39955
39300
  function runtimeDeliveryState(row) {
39956
- const state = rowString2(row, "state");
39301
+ const state = rowString(row, "state");
39957
39302
  if (state !== "received" && state !== "relay_committed" && state !== "processed") {
39958
39303
  throw new Error("SQLite returned an invalid Runtime delivery state");
39959
39304
  }
@@ -39979,9 +39324,9 @@ var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
39979
39324
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
39980
39325
  function botIpcSocketPath() {
39981
39326
  if (process.platform === "win32") {
39982
- return `\\\\.\\pipe\\mobius-bot-${randomUUID4()}`;
39327
+ return `\\\\.\\pipe\\mobius-bot-${randomUUID3()}`;
39983
39328
  }
39984
- return join16("/tmp", `mobius-bot-${randomUUID4()}.sock`);
39329
+ return join16("/tmp", `mobius-bot-${randomUUID3()}.sock`);
39985
39330
  }
39986
39331
  var DaemonAcpObserver = class {
39987
39332
  #config;
@@ -40940,14 +40285,14 @@ async function applyRequiredExecutionSelection(sessions, configOptions, selectio
40940
40285
  booleanValue: false,
40941
40286
  configId: selection.configId,
40942
40287
  cwd,
40943
- requestId: `cfg_${randomUUID4()}`,
40288
+ requestId: `cfg_${randomUUID3()}`,
40944
40289
  sessionId,
40945
40290
  signal,
40946
40291
  value: selection.value,
40947
40292
  valueType: "select"
40948
40293
  });
40949
40294
  }
40950
- async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, grants, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
40295
+ async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
40951
40296
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
40952
40297
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
40953
40298
  });
@@ -40957,21 +40302,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
40957
40302
  if (!Number.isSafeInteger(deadline) || remaining <= 0) {
40958
40303
  throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
40959
40304
  }
40960
- const grant = await grants.resolveExecution(
40961
- command,
40962
- config2.catalog,
40963
- directories,
40964
- config2.bindingId,
40965
- Date.now(),
40966
- signal
40967
- );
40968
- const requestedExecutionTargetOverridden = command.directoryId !== grant.workspaceRef || command.additionalDirectoryIds.length > 0;
40969
- if (requestedExecutionTargetOverridden && !(command.replyRoute instanceof OwnerBotReplyRoute)) {
40970
- throw new LocalBotAuthorizationError(
40971
- "binding_not_approved",
40972
- "Only a paired owner conversation can override the approved Bot workspace"
40973
- );
40974
- }
40305
+ const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
40975
40306
  const resolved = await resolveSessionDirectories(
40976
40307
  directories,
40977
40308
  config2.bindingId,
@@ -40979,20 +40310,8 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
40979
40310
  command.additionalDirectoryIds,
40980
40311
  signal
40981
40312
  );
40982
- const executionTargetOverridden = resolved.cwd !== grant.workspacePath || resolved.additionalDirectories.length > 0;
40983
- if (executionTargetOverridden && !sessions.hasPreparedSession(
40984
- command.sessionId,
40985
- grant.agent.id,
40986
- resolved.cwd,
40987
- resolved.additionalDirectories
40988
- )) {
40989
- throw new LocalBotAuthorizationError(
40990
- "local_approval_required",
40991
- "Open this Bot conversation in the paired local Web app before using the selected workspace"
40992
- );
40993
- }
40994
40313
  const attachments = await resolvePromptArtifacts(config2, command, signal);
40995
- const applied = await applicator.apply(command, grant, attachments.resources, signal);
40314
+ const applied = await applicator.apply(command, execution, attachments.resources, signal);
40996
40315
  const deadlineSignal = AbortSignal.timeout(remaining);
40997
40316
  const executionSignal = AbortSignal.any([signal, deadlineSignal]);
40998
40317
  const startExecution = () => {
@@ -41002,8 +40321,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41002
40321
  behaviorRevisionId: command.behaviorRevisionId,
41003
40322
  bindingId: command.bindingId,
41004
40323
  botId: command.botId,
41005
- executionId: command.executionId,
41006
- localGrantId: command.localGrantId
40324
+ executionId: command.executionId
41007
40325
  },
41008
40326
  event: "bot_session_authorized",
41009
40327
  sessionId: command.sessionId
@@ -41026,7 +40344,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41026
40344
  startExecution();
41027
40345
  await sessions.steerPrompt({
41028
40346
  additionalDirectories: resolved.additionalDirectories,
41029
- agent: grant.agent,
40347
+ agent: execution.agent,
41030
40348
  commandId: command.commandId,
41031
40349
  cwd: resolved.cwd,
41032
40350
  images: attachments.images,
@@ -41046,7 +40364,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41046
40364
  }
41047
40365
  const lease = contexts.activate(command);
41048
40366
  try {
41049
- const agent = botExecutionAgent(grant.agent, lease.context.contextHandle, ipc.socketPath);
40367
+ const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
41050
40368
  const prepared = await sessions.prepareExecutionSession({
41051
40369
  additionalDirectories: resolved.additionalDirectories,
41052
40370
  agent,
@@ -41054,11 +40372,11 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41054
40372
  sessionId: command.sessionId,
41055
40373
  signal: executionSignal
41056
40374
  });
41057
- assertPreparedPermission(prepared.configOptions, grant.executionConfiguration.permissionMode);
40375
+ assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41058
40376
  let configOptions = await applyRequiredExecutionSelection(
41059
40377
  sessions,
41060
40378
  prepared.configOptions,
41061
- grant.executionConfiguration.model,
40379
+ execution.executionConfiguration.model,
41062
40380
  "model",
41063
40381
  agent,
41064
40382
  resolved.cwd,
@@ -41069,7 +40387,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41069
40387
  configOptions = await applyRequiredExecutionSelection(
41070
40388
  sessions,
41071
40389
  configOptions,
41072
- grant.executionConfiguration.reasoningEffort,
40390
+ execution.executionConfiguration.reasoningEffort,
41073
40391
  "thought_level",
41074
40392
  agent,
41075
40393
  resolved.cwd,
@@ -41084,7 +40402,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41084
40402
  booleanValue: selection.booleanValue,
41085
40403
  configId: selection.configId,
41086
40404
  cwd: resolved.cwd,
41087
- requestId: `cfg_${randomUUID4()}`,
40405
+ requestId: `cfg_${randomUUID3()}`,
41088
40406
  sessionId: command.sessionId,
41089
40407
  signal: executionSignal,
41090
40408
  value: selection.value,
@@ -41216,13 +40534,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
41216
40534
  {
41217
40535
  agentId: agent.id,
41218
40536
  kind: AGENT_INSTALL_REQUEST_KIND,
41219
- requestId: `automatic-integration-${randomUUID4()}`
40537
+ requestId: `automatic-integration-${randomUUID3()}`
41220
40538
  },
41221
40539
  signal
41222
40540
  );
41223
40541
  }
41224
40542
  }
41225
- async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, grants, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
40543
+ async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, authorizer, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41226
40544
  const relayUrl = new URL(config2.relayUrl);
41227
40545
  relayUrl.searchParams.set("deliveryReceipts", "1");
41228
40546
  relayUrl.searchParams.set("liveness", "1");
@@ -41402,7 +40720,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41402
40720
  directories,
41403
40721
  audit,
41404
40722
  sessions,
41405
- grants,
40723
+ authorizer,
41406
40724
  contexts,
41407
40725
  applicator,
41408
40726
  ipc,
@@ -41582,70 +40900,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41582
40900
  }
41583
40901
  return;
41584
40902
  }
41585
- if (kind === BOT_BINDING_APPROVED_KIND) {
41586
- decodeBotExecutionBindingApprovedEvent(encoded);
41587
- return;
41588
- }
41589
- if (kind === BOT_BINDING_UNAVAILABLE_KIND) {
41590
- decodeBotExecutionBindingUnavailableEvent(encoded);
41591
- return;
41592
- }
41593
- if (kind === BOT_BINDING_APPROVAL_REQUEST_KIND) {
41594
- const request = decodeBotExecutionBindingApprovalRequest(encoded);
41595
- void grants.approve(
41596
- request,
41597
- config2.catalog,
41598
- directories,
41599
- config2.bindingId,
41600
- Date.now(),
41601
- connectionController.signal
41602
- ).then((approved) => {
41603
- audit.record({
41604
- commandId: request.requestId,
41605
- details: {
41606
- behaviorRevisionId: request.behaviorRevisionId,
41607
- bindingId: request.bindingId,
41608
- botId: request.botId,
41609
- localGrantId: approved.localGrantId
41610
- },
41611
- event: "bot_binding_approved",
41612
- sessionId: `bot-binding:${request.bindingId}`
41613
- });
41614
- if (socket.readyState === WebSocket2.OPEN) {
41615
- send(socket, encodeBotExecutionBindingApprovedEvent(approved));
41616
- }
41617
- }).catch((error62) => {
41618
- if (connectionController.signal.aborted) {
41619
- return;
41620
- }
41621
- const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "binding_incompatible";
41622
- const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local execution target is incompatible";
41623
- grants.recordUnavailable(request, code, message, Date.now());
41624
- audit.record({
41625
- commandId: request.requestId,
41626
- details: { bindingId: request.bindingId, botId: request.botId, code },
41627
- event: "bot_binding_unavailable",
41628
- sessionId: `bot-binding:${request.bindingId}`
41629
- });
41630
- if (socket.readyState === WebSocket2.OPEN) {
41631
- send(
41632
- socket,
41633
- encodeBotExecutionBindingUnavailableEvent(
41634
- new BotExecutionBindingUnavailableEvent(
41635
- request.requestId,
41636
- request.botId,
41637
- request.behaviorRevisionId,
41638
- request.bindingId,
41639
- request.bindingRevision,
41640
- code,
41641
- message
41642
- )
41643
- )
41644
- );
41645
- }
41646
- });
41647
- return;
41648
- }
41649
40903
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
41650
40904
  const command2 = decodeNativeSessionCancel(encoded);
41651
40905
  const pending = nativeRequests.get(command2.requestId);
@@ -42041,7 +41295,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42041
41295
  directories,
42042
41296
  audit,
42043
41297
  sessions,
42044
- grants,
41298
+ authorizer,
42045
41299
  contexts,
42046
41300
  applicator,
42047
41301
  ipc,
@@ -42167,7 +41421,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42167
41421
  const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
42168
41422
  const outbox = new SessionEventOutbox(config2.auditDatabasePath);
42169
41423
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
42170
- const grants = new LocalBotGrantStore(config2.auditDatabasePath);
41424
+ const authorizer = new LocalBotExecutionAuthorizer();
42171
41425
  const contexts = new BotExecutionContextRegistry();
42172
41426
  const applicator = new EmbeddedBotContextApplicator();
42173
41427
  const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
@@ -42258,7 +41512,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42258
41512
  nativeSessions,
42259
41513
  outbox,
42260
41514
  publisher,
42261
- grants,
41515
+ authorizer,
42262
41516
  contexts,
42263
41517
  applicator,
42264
41518
  ipc,
@@ -42303,13 +41557,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42303
41557
  sessionStore.close();
42304
41558
  } finally {
42305
41559
  try {
42306
- grants.close();
41560
+ publisher.close();
42307
41561
  } finally {
42308
- try {
42309
- publisher.close();
42310
- } finally {
42311
- outbox.close();
42312
- }
41562
+ outbox.close();
42313
41563
  }
42314
41564
  }
42315
41565
  }
@@ -42321,7 +41571,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42321
41571
  }
42322
41572
 
42323
41573
  // src/pairing/pair-local-machine.ts
42324
- import { randomUUID as randomUUID5 } from "node:crypto";
41574
+ import { randomUUID as randomUUID4 } from "node:crypto";
42325
41575
  import { mkdir as mkdir4, open as open4, realpath as realpath8, rename as rename3, stat as stat7, writeFile as writeFile2 } from "node:fs/promises";
42326
41576
  import { hostname as hostname3 } from "node:os";
42327
41577
  import { basename as basename6, join as join17, resolve as resolve4 } from "node:path";
@@ -42484,7 +41734,7 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
42484
41734
  const connectionsDirectory = join17(readStateDirectory(environment), "connections");
42485
41735
  await mkdir4(connectionsDirectory, { mode: 448, recursive: true });
42486
41736
  const connectionPath = join17(connectionsDirectory, `${channelId}.json`);
42487
- const temporaryPath = join17(connectionsDirectory, `.${channelId}.${randomUUID5()}.tmp`);
41737
+ const temporaryPath = join17(connectionsDirectory, `.${channelId}.${randomUUID4()}.tmp`);
42488
41738
  await writeFile2(
42489
41739
  temporaryPath,
42490
41740
  `${JSON.stringify(