@moxt-ai/mobius 0.0.43 → 0.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/agent-catalog/publish-agent-catalog.d.ts.map +1 -1
  2. package/dist/agent-catalog/publish-agent-catalog.js +1 -0
  3. package/dist/agent-catalog/publish-agent-catalog.js.map +1 -1
  4. package/dist/artifacts/runtime-artifact-uploader.d.ts.map +1 -1
  5. package/dist/artifacts/runtime-artifact-uploader.js +10 -17
  6. package/dist/artifacts/runtime-artifact-uploader.js.map +1 -1
  7. package/dist/bots/bot-context-applicator.d.ts +3 -3
  8. package/dist/bots/bot-context-applicator.d.ts.map +1 -1
  9. package/dist/bots/bot-context-applicator.js +7 -7
  10. package/dist/bots/bot-context-applicator.js.map +1 -1
  11. package/dist/bots/bot-execution-context.js +1 -1
  12. package/dist/bots/bot-execution-context.js.map +1 -1
  13. package/dist/bots/bot-outbound-ipc.js +1 -1
  14. package/dist/bots/bot-outbound-ipc.js.map +1 -1
  15. package/dist/bots/local-bot-execution-authorizer.d.ts +23 -0
  16. package/dist/bots/local-bot-execution-authorizer.d.ts.map +1 -0
  17. package/dist/bots/local-bot-execution-authorizer.js +62 -0
  18. package/dist/bots/local-bot-execution-authorizer.js.map +1 -0
  19. package/dist/cli.js +229 -851
  20. package/dist/cli.js.map +4 -4
  21. package/dist/index.js +233 -855
  22. package/dist/index.js.map +4 -4
  23. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  24. package/dist/pairing/pair-local-machine.js +1 -0
  25. package/dist/pairing/pair-local-machine.js.map +1 -1
  26. package/dist/run-daemon.d.ts.map +1 -1
  27. package/dist/run-daemon.js +139 -87
  28. package/dist/run-daemon.js.map +1 -1
  29. package/dist/runtime.js +230 -852
  30. package/dist/runtime.js.map +4 -4
  31. package/package.json +1 -1
  32. package/dist/bots/local-bot-grant-store.d.ts +0 -36
  33. package/dist/bots/local-bot-grant-store.d.ts.map +0 -1
  34. package/dist/bots/local-bot-grant-store.js +0 -398
  35. package/dist/bots/local-bot-grant-store.js.map +0 -1
package/dist/index.js CHANGED
@@ -20514,6 +20514,7 @@ function decodeMessageKind(encoded) {
20514
20514
  }
20515
20515
  function decodeSessionPromptCommand(encoded) {
20516
20516
  const value = parseJson2(encoded);
20517
+ const hasSessionConfigurations = Object.hasOwn(value, "sessionConfigurations");
20517
20518
  assertExactKeys(value, [
20518
20519
  "additionalDirectoryIds",
20519
20520
  "agentId",
@@ -20525,6 +20526,7 @@ function decodeSessionPromptCommand(encoded) {
20525
20526
  "kind",
20526
20527
  "prompt",
20527
20528
  "resources",
20529
+ ...hasSessionConfigurations ? ["sessionConfigurations"] : [],
20528
20530
  "sessionId",
20529
20531
  "targetCommandId"
20530
20532
  ]);
@@ -20545,6 +20547,10 @@ function decodeSessionPromptCommand(encoded) {
20545
20547
  if (disposition === SessionPromptDisposition.Reject && targetCommandId.length > 0 || disposition !== SessionPromptDisposition.Reject && !IDENTIFIER_PATTERN2.test(targetCommandId)) {
20546
20548
  throw new ProtocolMessageError("Prompt disposition has an invalid target command");
20547
20549
  }
20550
+ const sessionConfigurations = hasSessionConfigurations ? decodeSessionConfigurationSelections(value["sessionConfigurations"]) : [];
20551
+ if (new Set(sessionConfigurations.map((selection) => selection.configId)).size !== sessionConfigurations.length) {
20552
+ throw new ProtocolMessageError("Session configuration identifiers must be unique");
20553
+ }
20548
20554
  return {
20549
20555
  additionalDirectoryIds: readDirectoryIdentifiers(value, "additionalDirectoryIds", 16),
20550
20556
  agentId: readIdentifier(value, "agentId"),
@@ -20556,6 +20562,7 @@ function decodeSessionPromptCommand(encoded) {
20556
20562
  kind: SESSION_PROMPT_KIND,
20557
20563
  prompt,
20558
20564
  resources,
20565
+ ...hasSessionConfigurations ? { sessionConfigurations } : {},
20559
20566
  sessionId: readIdentifier(value, "sessionId"),
20560
20567
  targetCommandId
20561
20568
  };
@@ -20732,9 +20739,6 @@ function encodeSessionFailedEvent(message) {
20732
20739
  }
20733
20740
 
20734
20741
  // ../protocol/src/bot.ts
20735
- var BOT_BINDING_APPROVAL_REQUEST_KIND = "bot.binding.approval.request";
20736
- var BOT_BINDING_APPROVED_KIND = "bot.binding.approved";
20737
- var BOT_BINDING_UNAVAILABLE_KIND = "bot.binding.unavailable";
20738
20742
  var BOT_SESSION_PROMPT_KIND = "bot.session.prompt";
20739
20743
  var IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
20740
20744
  var DIRECTORY_IDENTIFIER_PATTERN3 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
@@ -20749,21 +20753,6 @@ var BotDeliveryTargetReference = class {
20749
20753
  this.deliveryTargetId = deliveryTargetId;
20750
20754
  }
20751
20755
  };
20752
- var BotCompletionDeliveryPolicy = class {
20753
- };
20754
- var NoBotCompletionDeliveryPolicy = class extends BotCompletionDeliveryPolicy {
20755
- kind = "none";
20756
- };
20757
- var RequiredBotCompletionDeliveryPolicy = class extends BotCompletionDeliveryPolicy {
20758
- deliveryTargetId;
20759
- kind = "required";
20760
- messageTemplate;
20761
- constructor(deliveryTargetId, messageTemplate) {
20762
- super();
20763
- this.deliveryTargetId = deliveryTargetId;
20764
- this.messageTemplate = messageTemplate;
20765
- }
20766
- };
20767
20756
  var BotReplyRoute = class {
20768
20757
  };
20769
20758
  var OwnerBotReplyRoute = class extends BotReplyRoute {
@@ -20779,94 +20768,6 @@ var BotConnectionReplyRoute = class extends BotReplyRoute {
20779
20768
  this.deliveryTargetId = deliveryTargetId;
20780
20769
  }
20781
20770
  };
20782
- var BotExecutionBindingApprovalRequest = class {
20783
- agentConfigRevision;
20784
- agentRef;
20785
- allowedDeliveryTargets;
20786
- behaviorDigest;
20787
- behaviorInstructions;
20788
- behaviorRevisionId;
20789
- bindingId;
20790
- bindingRevision;
20791
- botId;
20792
- completionPolicy;
20793
- executionConfiguration;
20794
- kind = BOT_BINDING_APPROVAL_REQUEST_KIND;
20795
- requestId;
20796
- requiredCapabilities;
20797
- runtimeId;
20798
- sessionConfigurations;
20799
- workspaceRef;
20800
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, runtimeId, agentRef, workspaceRef, agentConfigRevision, behaviorInstructions, behaviorDigest, requiredCapabilities, allowedDeliveryTargets, completionPolicy, executionConfiguration, sessionConfigurations = []) {
20801
- this.requestId = requestId;
20802
- this.botId = botId;
20803
- this.behaviorRevisionId = behaviorRevisionId;
20804
- this.bindingId = bindingId;
20805
- this.bindingRevision = bindingRevision;
20806
- this.runtimeId = runtimeId;
20807
- this.agentRef = agentRef;
20808
- this.workspaceRef = workspaceRef;
20809
- this.agentConfigRevision = agentConfigRevision;
20810
- this.behaviorInstructions = behaviorInstructions;
20811
- this.behaviorDigest = behaviorDigest;
20812
- this.requiredCapabilities = Object.freeze([...requiredCapabilities]);
20813
- this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
20814
- this.allowedDeliveryTargets = Object.freeze(
20815
- allowedDeliveryTargets.map(
20816
- (target) => new BotDeliveryTargetReference(target.alias, target.deliveryTargetId)
20817
- )
20818
- );
20819
- this.completionPolicy = completionPolicy;
20820
- this.executionConfiguration = decodeAgentExecutionConfiguration(executionConfiguration);
20821
- }
20822
- toJSON() {
20823
- const { sessionConfigurations, ...request } = this;
20824
- return {
20825
- ...request,
20826
- ...sessionConfigurations.length === 0 ? {} : { sessionConfigurations }
20827
- };
20828
- }
20829
- };
20830
- var BotExecutionBindingApprovedEvent = class {
20831
- agentIdentityDigest;
20832
- behaviorRevisionId;
20833
- bindingId;
20834
- bindingRevision;
20835
- botId;
20836
- kind = BOT_BINDING_APPROVED_KIND;
20837
- localGrantId;
20838
- requestId;
20839
- workspaceIdentityDigest;
20840
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, localGrantId, agentIdentityDigest, workspaceIdentityDigest) {
20841
- this.requestId = requestId;
20842
- this.botId = botId;
20843
- this.behaviorRevisionId = behaviorRevisionId;
20844
- this.bindingId = bindingId;
20845
- this.bindingRevision = bindingRevision;
20846
- this.localGrantId = localGrantId;
20847
- this.agentIdentityDigest = agentIdentityDigest;
20848
- this.workspaceIdentityDigest = workspaceIdentityDigest;
20849
- }
20850
- };
20851
- var BotExecutionBindingUnavailableEvent = class {
20852
- behaviorRevisionId;
20853
- bindingId;
20854
- bindingRevision;
20855
- botId;
20856
- code;
20857
- kind = BOT_BINDING_UNAVAILABLE_KIND;
20858
- message;
20859
- requestId;
20860
- constructor(requestId, botId, behaviorRevisionId, bindingId, bindingRevision, code, message) {
20861
- this.requestId = requestId;
20862
- this.botId = botId;
20863
- this.behaviorRevisionId = behaviorRevisionId;
20864
- this.bindingId = bindingId;
20865
- this.bindingRevision = bindingRevision;
20866
- this.code = code;
20867
- this.message = message;
20868
- }
20869
- };
20870
20771
  var BotSessionPromptCommand = class {
20871
20772
  additionalDirectoryIds;
20872
20773
  agentId;
@@ -20888,7 +20789,6 @@ var BotSessionPromptCommand = class {
20888
20789
  executionConfiguration;
20889
20790
  images;
20890
20791
  kind = BOT_SESSION_PROMPT_KIND;
20891
- localGrantId;
20892
20792
  prompt;
20893
20793
  replyRoute;
20894
20794
  resources;
@@ -20896,7 +20796,7 @@ var BotSessionPromptCommand = class {
20896
20796
  sessionId;
20897
20797
  targetCommandId;
20898
20798
  turnId;
20899
- 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 = "") {
20799
+ 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 = "") {
20900
20800
  this.sessionId = sessionId;
20901
20801
  this.commandId = commandId;
20902
20802
  this.agentId = agentId;
@@ -20916,7 +20816,6 @@ var BotSessionPromptCommand = class {
20916
20816
  this.turnId = turnId;
20917
20817
  this.behaviorRevisionId = behaviorRevisionId;
20918
20818
  this.bindingRevision = bindingRevision;
20919
- this.localGrantId = localGrantId;
20920
20819
  this.behaviorInstructions = behaviorInstructions;
20921
20820
  this.behaviorDigest = behaviorDigest;
20922
20821
  this.allowedDeliveryTargets = Object.freeze(
@@ -21060,24 +20959,6 @@ function readSessionConfigurations(value) {
21060
20959
  }
21061
20960
  return decodeSessionConfigurationSelections(value["sessionConfigurations"]);
21062
20961
  }
21063
- function readCompletionPolicy(value) {
21064
- if (!isRecord2(value)) {
21065
- throw new ProtocolMessageError("Invalid Bot completion policy");
21066
- }
21067
- const kind = readText2(value, "kind", 32, false);
21068
- if (kind === "none") {
21069
- assertExactKeys2(value, ["kind"]);
21070
- return new NoBotCompletionDeliveryPolicy();
21071
- }
21072
- if (kind === "required") {
21073
- assertExactKeys2(value, ["deliveryTargetId", "kind", "messageTemplate"]);
21074
- return new RequiredBotCompletionDeliveryPolicy(
21075
- readIdentifier2(value, "deliveryTargetId"),
21076
- readText2(value, "messageTemplate", 1e4, false)
21077
- );
21078
- }
21079
- throw new ProtocolMessageError("Invalid Bot completion policy");
21080
- }
21081
20962
  function readReplyRoute(value) {
21082
20963
  if (!isRecord2(value)) {
21083
20964
  throw new ProtocolMessageError("Invalid Bot reply route");
@@ -21096,110 +20977,6 @@ function readReplyRoute(value) {
21096
20977
  }
21097
20978
  throw new ProtocolMessageError("Invalid Bot reply route");
21098
20979
  }
21099
- function decodeBotExecutionBindingApprovalRequest(encoded) {
21100
- const value = parseJson3(encoded);
21101
- assertKeysWithOptional(
21102
- value,
21103
- [
21104
- "agentConfigRevision",
21105
- "agentRef",
21106
- "allowedDeliveryTargets",
21107
- "behaviorDigest",
21108
- "behaviorInstructions",
21109
- "behaviorRevisionId",
21110
- "bindingId",
21111
- "bindingRevision",
21112
- "botId",
21113
- "completionPolicy",
21114
- "executionConfiguration",
21115
- "kind",
21116
- "requestId",
21117
- "requiredCapabilities",
21118
- "runtimeId",
21119
- "workspaceRef"
21120
- ],
21121
- ["sessionConfigurations"]
21122
- );
21123
- if (value["kind"] !== BOT_BINDING_APPROVAL_REQUEST_KIND) {
21124
- throw new ProtocolMessageError("Invalid Bot binding approval request kind");
21125
- }
21126
- return new BotExecutionBindingApprovalRequest(
21127
- readIdentifier2(value, "requestId"),
21128
- readIdentifier2(value, "botId"),
21129
- readIdentifier2(value, "behaviorRevisionId"),
21130
- readIdentifier2(value, "bindingId"),
21131
- readInteger(value, "bindingRevision"),
21132
- readIdentifier2(value, "runtimeId"),
21133
- readIdentifier2(value, "agentRef"),
21134
- readDirectoryIdentifier2(value, "workspaceRef"),
21135
- readInteger(value, "agentConfigRevision"),
21136
- readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21137
- readDigest(value, "behaviorDigest"),
21138
- readIdentifiers(value, "requiredCapabilities", 32),
21139
- readTargets(value, "allowedDeliveryTargets"),
21140
- readCompletionPolicy(value["completionPolicy"]),
21141
- decodeAgentExecutionConfiguration(value["executionConfiguration"]),
21142
- readSessionConfigurations(value)
21143
- );
21144
- }
21145
- function decodeBotExecutionBindingApprovedEvent(encoded) {
21146
- const value = parseJson3(encoded);
21147
- assertExactKeys2(value, [
21148
- "agentIdentityDigest",
21149
- "behaviorRevisionId",
21150
- "bindingId",
21151
- "bindingRevision",
21152
- "botId",
21153
- "kind",
21154
- "localGrantId",
21155
- "requestId",
21156
- "workspaceIdentityDigest"
21157
- ]);
21158
- if (value["kind"] !== BOT_BINDING_APPROVED_KIND) {
21159
- throw new ProtocolMessageError("Invalid Bot binding approval event kind");
21160
- }
21161
- return new BotExecutionBindingApprovedEvent(
21162
- readIdentifier2(value, "requestId"),
21163
- readIdentifier2(value, "botId"),
21164
- readIdentifier2(value, "behaviorRevisionId"),
21165
- readIdentifier2(value, "bindingId"),
21166
- readInteger(value, "bindingRevision"),
21167
- readIdentifier2(value, "localGrantId"),
21168
- readDigest(value, "agentIdentityDigest"),
21169
- readDigest(value, "workspaceIdentityDigest")
21170
- );
21171
- }
21172
- function encodeBotExecutionBindingApprovedEvent(event) {
21173
- return JSON.stringify(decodeBotExecutionBindingApprovedEvent(JSON.stringify(event)));
21174
- }
21175
- function decodeBotExecutionBindingUnavailableEvent(encoded) {
21176
- const value = parseJson3(encoded);
21177
- assertExactKeys2(value, [
21178
- "behaviorRevisionId",
21179
- "bindingId",
21180
- "bindingRevision",
21181
- "botId",
21182
- "code",
21183
- "kind",
21184
- "message",
21185
- "requestId"
21186
- ]);
21187
- if (value["kind"] !== BOT_BINDING_UNAVAILABLE_KIND) {
21188
- throw new ProtocolMessageError("Invalid Bot binding unavailable event kind");
21189
- }
21190
- return new BotExecutionBindingUnavailableEvent(
21191
- readIdentifier2(value, "requestId"),
21192
- readIdentifier2(value, "botId"),
21193
- readIdentifier2(value, "behaviorRevisionId"),
21194
- readIdentifier2(value, "bindingId"),
21195
- readInteger(value, "bindingRevision"),
21196
- readIdentifier2(value, "code"),
21197
- readText2(value, "message", 500, false)
21198
- );
21199
- }
21200
- function encodeBotExecutionBindingUnavailableEvent(event) {
21201
- return JSON.stringify(decodeBotExecutionBindingUnavailableEvent(JSON.stringify(event)));
21202
- }
21203
20980
  function decodeBotSessionPromptCommand(encoded) {
21204
20981
  const value = parseJson3(encoded);
21205
20982
  assertKeysWithOptional(
@@ -21224,7 +21001,6 @@ function decodeBotSessionPromptCommand(encoded) {
21224
21001
  "executionConfiguration",
21225
21002
  "images",
21226
21003
  "kind",
21227
- "localGrantId",
21228
21004
  "prompt",
21229
21005
  "replyRoute",
21230
21006
  "resources",
@@ -21270,7 +21046,6 @@ function decodeBotSessionPromptCommand(encoded) {
21270
21046
  readIdentifier2(value, "turnId"),
21271
21047
  readIdentifier2(value, "behaviorRevisionId"),
21272
21048
  readInteger(value, "bindingRevision"),
21273
- readIdentifier2(value, "localGrantId"),
21274
21049
  readText2(value, "behaviorInstructions", MAX_INSTRUCTIONS_LENGTH, true),
21275
21050
  readDigest(value, "behaviorDigest"),
21276
21051
  readTargets(value, "allowedDeliveryTargets"),
@@ -34250,10 +34025,7 @@ var LocalAuthorizationError = class extends Error {
34250
34025
  // src/bots/bot-execution-context.ts
34251
34026
  import { randomBytes } from "node:crypto";
34252
34027
 
34253
- // src/bots/local-bot-grant-store.ts
34254
- import { createHash, randomUUID } from "node:crypto";
34255
- import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
34256
- var LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS = 90 * 24 * 60 * 60 * 1e3;
34028
+ // src/bots/local-bot-execution-authorizer.ts
34257
34029
  var LocalBotAuthorizationError = class extends Error {
34258
34030
  code;
34259
34031
  constructor(code, message, options = {}) {
@@ -34262,325 +34034,40 @@ var LocalBotAuthorizationError = class extends Error {
34262
34034
  this.name = "LocalBotAuthorizationError";
34263
34035
  }
34264
34036
  };
34265
- var LocalBotGrant = class {
34037
+ var AuthorizedLocalBotExecution = class {
34266
34038
  agent;
34267
- agentIdentityDigest;
34268
- allowedDeliveryTargetIds;
34269
34039
  behaviorDigest;
34270
34040
  behaviorRevisionId;
34271
34041
  bindingId;
34272
34042
  bindingRevision;
34273
34043
  botId;
34274
- expiresAt;
34275
34044
  executionConfiguration;
34276
- localGrantId;
34277
- revocationEpoch;
34278
- workspaceIdentityDigest;
34279
34045
  workspacePath;
34280
34046
  workspaceRef;
34281
- constructor(localGrantId, botId, behaviorRevisionId, behaviorDigest, bindingId, bindingRevision, agent, agentIdentityDigest, workspaceRef, workspacePath, workspaceIdentityDigest, allowedDeliveryTargetIds, executionConfiguration, expiresAt, revocationEpoch) {
34282
- this.localGrantId = localGrantId;
34283
- this.botId = botId;
34284
- this.behaviorRevisionId = behaviorRevisionId;
34285
- this.behaviorDigest = behaviorDigest;
34286
- this.bindingId = bindingId;
34287
- this.bindingRevision = bindingRevision;
34047
+ constructor(command, agent, workspacePath) {
34288
34048
  this.agent = agent;
34289
- this.agentIdentityDigest = agentIdentityDigest;
34290
- this.workspaceRef = workspaceRef;
34049
+ this.behaviorDigest = command.behaviorDigest;
34050
+ this.behaviorRevisionId = command.behaviorRevisionId;
34051
+ this.bindingId = command.bindingId;
34052
+ this.bindingRevision = command.bindingRevision;
34053
+ this.botId = command.botId;
34054
+ this.executionConfiguration = command.executionConfiguration;
34291
34055
  this.workspacePath = workspacePath;
34292
- this.workspaceIdentityDigest = workspaceIdentityDigest;
34293
- this.allowedDeliveryTargetIds = Object.freeze([...allowedDeliveryTargetIds]);
34294
- this.executionConfiguration = executionConfiguration;
34295
- this.expiresAt = expiresAt;
34296
- this.revocationEpoch = revocationEpoch;
34056
+ this.workspaceRef = command.directoryId;
34297
34057
  }
34298
34058
  };
34299
- function digest(value) {
34300
- return createHash("sha256").update(value, "utf8").digest("hex");
34301
- }
34302
- function agentDigest(agent) {
34303
- return digest(
34304
- JSON.stringify({
34305
- adapter: agent.adapterIdentity,
34306
- agent: agent.agentIdentity,
34307
- agentVersion: agent.agentVersion,
34308
- arguments: agent.arguments,
34309
- id: agent.id
34310
- })
34311
- );
34312
- }
34313
- function configurePermission(agent, permissionMode) {
34314
- try {
34315
- return agent.withPermissionMode(permissionMode);
34316
- } catch (cause) {
34317
- if (cause instanceof AgentPermissionConfigurationError) {
34318
- throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
34319
- }
34320
- throw cause;
34321
- }
34322
- }
34323
- function workspaceDigest(path2) {
34324
- return digest(path2);
34325
- }
34326
- function exactTargets(left, right) {
34327
- if (left.length !== right.length) {
34328
- return false;
34329
- }
34330
- const expected = [...left].sort();
34331
- const actual = [...right].sort();
34332
- return expected.every((target, index2) => target === actual[index2]);
34333
- }
34334
- function exactSessionConfigurations(left, right) {
34335
- if (left.length !== right.length) {
34336
- return false;
34337
- }
34338
- const expected = new Map(left.map((selection) => [selection.configId, selection]));
34339
- return right.every((selection) => {
34340
- const approved = expected.get(selection.configId);
34341
- return approved !== void 0 && approved.booleanValue === selection.booleanValue && approved.value === selection.value && approved.valueType === selection.valueType;
34342
- });
34343
- }
34344
- function exactExecutionConfiguration(left, right) {
34345
- return left.permissionMode === right.permissionMode && exactSessionConfigurations([left.model, left.reasoningEffort], [right.model, right.reasoningEffort]);
34346
- }
34347
- function rowString(row, key) {
34348
- const value = Reflect.get(row, key);
34349
- if (typeof value !== "string") {
34350
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
34351
- }
34352
- return value;
34353
- }
34354
- function rowInteger(row, key) {
34355
- const value = Reflect.get(row, key);
34356
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
34357
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
34358
- }
34359
- return value;
34360
- }
34361
- function rowHasInteger(row, key) {
34362
- const value = Reflect.get(row, key);
34363
- if (value === null) {
34364
- return false;
34365
- }
34366
- if (typeof value !== "number" || !Number.isSafeInteger(value)) {
34367
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
34368
- }
34369
- return true;
34370
- }
34371
- function parseTargets(encoded) {
34372
- let value;
34373
- try {
34374
- value = JSON.parse(encoded);
34375
- } catch (cause) {
34376
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
34377
- }
34378
- if (!Array.isArray(value) || value.some((target) => typeof target !== "string")) {
34379
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid");
34380
- }
34381
- return value.filter((target) => typeof target === "string");
34382
- }
34383
- function parseSessionConfigurations(encoded) {
34384
- let value;
34385
- try {
34386
- value = JSON.parse(encoded);
34387
- return decodeSessionConfigurationSelections(value);
34388
- } catch (cause) {
34389
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
34390
- }
34391
- }
34392
- function parseExecutionConfiguration(encoded) {
34393
- let value;
34394
- try {
34395
- value = JSON.parse(encoded);
34396
- return decodeAgentExecutionConfiguration(value);
34397
- } catch (cause) {
34398
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is invalid", { cause });
34399
- }
34400
- }
34401
- var LocalBotGrantStore = class {
34402
- #database;
34403
- constructor(path2) {
34404
- this.#database = new DatabaseSync3(path2);
34405
- this.#database.exec(`
34406
- CREATE TABLE IF NOT EXISTS local_bot_grants (
34407
- local_grant_id TEXT PRIMARY KEY,
34408
- bot_id TEXT NOT NULL,
34409
- behavior_revision_id TEXT NOT NULL,
34410
- behavior_digest TEXT NOT NULL,
34411
- binding_id TEXT NOT NULL UNIQUE,
34412
- binding_revision INTEGER NOT NULL,
34413
- agent_ref TEXT NOT NULL,
34414
- agent_identity_digest TEXT NOT NULL,
34415
- workspace_ref TEXT NOT NULL,
34416
- workspace_path TEXT NOT NULL,
34417
- workspace_identity_digest TEXT NOT NULL,
34418
- allowed_delivery_target_ids_json TEXT NOT NULL,
34419
- unattended_policy_json TEXT NOT NULL,
34420
- created_at INTEGER NOT NULL,
34421
- expires_at INTEGER NOT NULL,
34422
- revocation_epoch INTEGER NOT NULL DEFAULT 0,
34423
- revoked_at INTEGER
34424
- ) STRICT;
34425
- CREATE TABLE IF NOT EXISTS local_bot_binding_resolutions (
34426
- request_id TEXT PRIMARY KEY,
34427
- binding_id TEXT NOT NULL,
34428
- local_grant_id TEXT NOT NULL,
34429
- resolved_at INTEGER NOT NULL,
34430
- result TEXT NOT NULL CHECK (result IN ('approved', 'unavailable')),
34431
- error_code TEXT,
34432
- error_message TEXT
34433
- ) STRICT;
34434
- CREATE TABLE IF NOT EXISTS local_bot_grant_configurations (
34435
- local_grant_id TEXT PRIMARY KEY,
34436
- session_configurations_json TEXT NOT NULL
34437
- ) STRICT;
34438
- CREATE TABLE IF NOT EXISTS local_bot_grant_execution_configurations (
34439
- local_grant_id TEXT PRIMARY KEY,
34440
- execution_configuration_json TEXT NOT NULL
34441
- ) STRICT;
34442
- `);
34443
- }
34444
- approve = async (request, catalog, directories, bindingAuthorityId, now, signal) => {
34059
+ var LocalBotExecutionAuthorizer = class {
34060
+ authorize = async (command, catalog, directories, bindingAuthorityId, signal) => {
34445
34061
  signal.throwIfAborted();
34446
- const existing = this.#database.prepare(
34447
- `SELECT grants.* FROM local_bot_binding_resolutions AS resolutions
34448
- INNER JOIN local_bot_grants AS grants
34449
- ON grants.local_grant_id = resolutions.local_grant_id
34450
- WHERE resolutions.request_id = ? AND resolutions.binding_id = ?
34451
- AND resolutions.result = 'approved'`
34452
- ).get(request.requestId, request.bindingId);
34453
- if (existing !== void 0) {
34454
- return new BotExecutionBindingApprovedEvent(
34455
- request.requestId,
34456
- request.botId,
34457
- request.behaviorRevisionId,
34458
- request.bindingId,
34459
- request.bindingRevision,
34460
- rowString(existing, "local_grant_id"),
34461
- rowString(existing, "agent_identity_digest"),
34462
- rowString(existing, "workspace_identity_digest")
34463
- );
34464
- }
34465
- const resolved = await this.resolveProposal(request, catalog, directories, bindingAuthorityId, signal);
34466
- const localGrantId = `lbg_${randomUUID()}`;
34467
- const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
34468
- this.#database.exec("BEGIN IMMEDIATE");
34062
+ let agent;
34469
34063
  try {
34470
- this.#database.prepare(
34471
- `INSERT INTO local_bot_grants (
34472
- local_grant_id, bot_id, behavior_revision_id, behavior_digest,
34473
- binding_id, binding_revision, agent_ref,
34474
- agent_identity_digest, workspace_ref, workspace_path,
34475
- workspace_identity_digest, allowed_delivery_target_ids_json,
34476
- unattended_policy_json, created_at, expires_at
34477
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
34478
- ).run(
34479
- localGrantId,
34480
- request.botId,
34481
- request.behaviorRevisionId,
34482
- request.behaviorDigest,
34483
- request.bindingId,
34484
- request.bindingRevision,
34485
- request.agentRef,
34486
- resolved.agentIdentityDigest,
34487
- request.workspaceRef,
34488
- resolved.workspacePath,
34489
- resolved.workspaceIdentityDigest,
34490
- JSON.stringify(request.allowedDeliveryTargets.map((target) => target.deliveryTargetId)),
34491
- JSON.stringify({ localSideEffects: "owner-approval-required" }),
34492
- now,
34493
- expiresAt
34494
- );
34495
- this.#database.prepare(
34496
- `INSERT INTO local_bot_grant_configurations (
34497
- local_grant_id, session_configurations_json
34498
- ) VALUES (?, ?)`
34499
- ).run(localGrantId, JSON.stringify(request.sessionConfigurations));
34500
- this.#database.prepare(
34501
- `INSERT INTO local_bot_grant_execution_configurations (
34502
- local_grant_id, execution_configuration_json
34503
- ) VALUES (?, ?)`
34504
- ).run(localGrantId, JSON.stringify(request.executionConfiguration));
34505
- this.#database.prepare(
34506
- `INSERT INTO local_bot_binding_resolutions (
34507
- request_id, binding_id, local_grant_id, resolved_at, result
34508
- ) VALUES (?, ?, ?, ?, 'approved')`
34509
- ).run(request.requestId, request.bindingId, localGrantId, now);
34510
- this.#database.exec("COMMIT");
34064
+ agent = catalog.find(command.agentId).withPermissionMode(command.executionConfiguration.permissionMode);
34511
34065
  } catch (cause) {
34512
- this.#database.exec("ROLLBACK");
34066
+ if (cause instanceof AgentPermissionConfigurationError) {
34067
+ throw new LocalBotAuthorizationError("binding_incompatible", cause.message, { cause });
34068
+ }
34513
34069
  throw cause;
34514
34070
  }
34515
- signal.throwIfAborted();
34516
- return new BotExecutionBindingApprovedEvent(
34517
- request.requestId,
34518
- request.botId,
34519
- request.behaviorRevisionId,
34520
- request.bindingId,
34521
- request.bindingRevision,
34522
- localGrantId,
34523
- resolved.agentIdentityDigest,
34524
- resolved.workspaceIdentityDigest
34525
- );
34526
- };
34527
- resolveExecution = async (command, catalog, directories, bindingAuthorityId, now, signal) => {
34528
- signal.throwIfAborted();
34529
- const row = this.#database.prepare(
34530
- `SELECT grants.*, COALESCE(configurations.session_configurations_json, '[]')
34531
- AS session_configurations_json,
34532
- COALESCE(execution.execution_configuration_json, ?)
34533
- AS execution_configuration_json
34534
- FROM local_bot_grants AS grants
34535
- LEFT JOIN local_bot_grant_configurations AS configurations
34536
- ON configurations.local_grant_id = grants.local_grant_id
34537
- LEFT JOIN local_bot_grant_execution_configurations AS execution
34538
- ON execution.local_grant_id = grants.local_grant_id
34539
- WHERE grants.local_grant_id = ? AND grants.bot_id = ?
34540
- AND behavior_revision_id = ? AND behavior_digest = ?
34541
- AND binding_id = ? AND binding_revision = ?
34542
- AND agent_ref = ?`
34543
- ).get(
34544
- JSON.stringify(DEFAULT_AGENT_EXECUTION_CONFIGURATION),
34545
- command.localGrantId,
34546
- command.botId,
34547
- command.behaviorRevisionId,
34548
- command.behaviorDigest,
34549
- command.bindingId,
34550
- command.bindingRevision,
34551
- command.agentId
34552
- );
34553
- if (row === void 0) {
34554
- throw new LocalBotAuthorizationError(
34555
- "binding_not_approved",
34556
- "The Bot execution binding is not locally approved"
34557
- );
34558
- }
34559
- const approvedTargets = parseTargets(rowString(row, "allowed_delivery_target_ids_json"));
34560
- const requestedTargets = command.allowedDeliveryTargets.map((target) => target.deliveryTargetId);
34561
- if (!exactTargets(approvedTargets, requestedTargets)) {
34562
- throw new LocalBotAuthorizationError(
34563
- "binding_not_approved",
34564
- "The Bot execution target policy differs from its binding"
34565
- );
34566
- }
34567
- const approvedConfigurations = parseSessionConfigurations(rowString(row, "session_configurations_json"));
34568
- if (!exactSessionConfigurations(approvedConfigurations, command.sessionConfigurations)) {
34569
- throw new LocalBotAuthorizationError(
34570
- "binding_not_approved",
34571
- "The Bot Agent configuration differs from its binding"
34572
- );
34573
- }
34574
- const approvedExecutionConfiguration = parseExecutionConfiguration(
34575
- rowString(row, "execution_configuration_json")
34576
- );
34577
- if (!exactExecutionConfiguration(approvedExecutionConfiguration, command.executionConfiguration)) {
34578
- throw new LocalBotAuthorizationError(
34579
- "binding_not_approved",
34580
- "The Bot execution configuration differs from its binding"
34581
- );
34582
- }
34583
- const agent = configurePermission(catalog.find(command.agentId), command.executionConfiguration.permissionMode);
34584
34071
  const [adapterUnchanged, agentUnchanged] = await Promise.all([
34585
34072
  revalidateExecutable(agent.adapterIdentity),
34586
34073
  revalidateExecutable(agent.agentIdentity)
@@ -34592,150 +34079,15 @@ var LocalBotGrantStore = class {
34592
34079
  "The local Agent executable changed while the Runtime is active; restart the Runtime"
34593
34080
  );
34594
34081
  }
34595
- const workspaceRef = rowString(row, "workspace_ref");
34596
- const workspacePath = await directories.resolve(bindingAuthorityId, workspaceRef, signal);
34597
- const currentAgentDigest = agentDigest(agent);
34598
- const currentWorkspaceDigest = workspaceDigest(workspacePath);
34599
- signal.throwIfAborted();
34600
- let expiresAt = rowInteger(row, "expires_at");
34601
- let revocationEpoch = rowInteger(row, "revocation_epoch");
34602
- if (currentAgentDigest !== rowString(row, "agent_identity_digest") || currentWorkspaceDigest !== rowString(row, "workspace_identity_digest") || workspacePath !== rowString(row, "workspace_path") || expiresAt <= now || rowHasInteger(row, "revoked_at")) {
34603
- const refreshed = this.refreshTarget(
34604
- rowString(row, "local_grant_id"),
34605
- currentAgentDigest,
34606
- currentWorkspaceDigest,
34607
- workspacePath,
34608
- now
34609
- );
34610
- expiresAt = refreshed.expiresAt;
34611
- revocationEpoch = refreshed.revocationEpoch;
34612
- }
34613
34082
  if (command.behaviorInstructions.length > 0 && !agent.capabilities.embeddedContextPrompt) {
34614
34083
  throw new LocalBotAuthorizationError(
34615
34084
  "binding_incompatible",
34616
- "The local Agent cannot apply the approved Bot behavior"
34617
- );
34618
- }
34619
- return new LocalBotGrant(
34620
- rowString(row, "local_grant_id"),
34621
- command.botId,
34622
- command.behaviorRevisionId,
34623
- command.behaviorDigest,
34624
- command.bindingId,
34625
- command.bindingRevision,
34626
- agent,
34627
- currentAgentDigest,
34628
- workspaceRef,
34629
- workspacePath,
34630
- currentWorkspaceDigest,
34631
- approvedTargets,
34632
- approvedExecutionConfiguration,
34633
- expiresAt,
34634
- revocationEpoch
34635
- );
34636
- };
34637
- recordUnavailable = (request, code, message, now) => {
34638
- this.#database.prepare(
34639
- `INSERT OR IGNORE INTO local_bot_binding_resolutions (
34640
- request_id, binding_id, local_grant_id, resolved_at,
34641
- result, error_code, error_message
34642
- ) VALUES (?, ?, '', ?, 'unavailable', ?, ?)`
34643
- ).run(request.requestId, request.bindingId, now, code, message);
34644
- };
34645
- close = () => {
34646
- this.#database.close();
34647
- };
34648
- resolveProposal = async (request, catalog, directories, bindingAuthorityId, signal) => {
34649
- const agent = configurePermission(
34650
- catalog.find(request.agentRef),
34651
- request.executionConfiguration.permissionMode
34652
- );
34653
- if (request.requiredCapabilities.includes("embedded-context") && !agent.capabilities.embeddedContextPrompt) {
34654
- throw new LocalBotAuthorizationError(
34655
- "binding_incompatible",
34656
- "The local Agent cannot apply embedded Bot context"
34657
- );
34658
- }
34659
- if (request.requiredCapabilities.some((capability) => capability !== "embedded-context")) {
34660
- throw new LocalBotAuthorizationError(
34661
- "binding_incompatible",
34662
- "The Bot requires an unsupported local Agent capability"
34085
+ "The local Agent cannot apply the Bot behavior"
34663
34086
  );
34664
34087
  }
34665
- const [adapterUnchanged, agentUnchanged] = await Promise.all([
34666
- revalidateExecutable(agent.adapterIdentity),
34667
- revalidateExecutable(agent.agentIdentity)
34668
- ]);
34088
+ const workspacePath = await directories.resolve(bindingAuthorityId, command.directoryId, signal);
34669
34089
  signal.throwIfAborted();
34670
- if (!adapterUnchanged || !agentUnchanged) {
34671
- throw new LocalBotAuthorizationError(
34672
- "binding_incompatible",
34673
- "The local Agent executable changed before approval"
34674
- );
34675
- }
34676
- const workspacePath = await directories.resolve(bindingAuthorityId, request.workspaceRef, signal);
34677
- return {
34678
- agent,
34679
- agentIdentityDigest: agentDigest(agent),
34680
- workspaceIdentityDigest: workspaceDigest(workspacePath),
34681
- workspacePath
34682
- };
34683
- };
34684
- refreshTarget = (localGrantId, agentIdentityDigest, workspaceIdentityDigest, workspacePath, now) => {
34685
- const expiresAt = now + LOCAL_BOT_GRANT_LIFETIME_MILLISECONDS;
34686
- this.#database.exec("BEGIN IMMEDIATE");
34687
- try {
34688
- const current = this.#database.prepare("SELECT * FROM local_bot_grants WHERE local_grant_id = ?").get(localGrantId);
34689
- if (current === void 0) {
34690
- throw new LocalBotAuthorizationError("local_grant_invalid", "The local Bot grant is missing");
34691
- }
34692
- const currentExpiresAt = rowInteger(current, "expires_at");
34693
- const currentRevocationEpoch = rowInteger(current, "revocation_epoch");
34694
- if (agentIdentityDigest === rowString(current, "agent_identity_digest") && workspaceIdentityDigest === rowString(current, "workspace_identity_digest") && workspacePath === rowString(current, "workspace_path") && currentExpiresAt > now && !rowHasInteger(current, "revoked_at")) {
34695
- this.#database.exec("COMMIT");
34696
- return { expiresAt: currentExpiresAt, revocationEpoch: currentRevocationEpoch };
34697
- }
34698
- const result = this.#database.prepare(
34699
- `UPDATE local_bot_grants
34700
- SET agent_identity_digest = ?, workspace_identity_digest = ?, workspace_path = ?,
34701
- expires_at = ?, revoked_at = NULL, revocation_epoch = revocation_epoch + 1
34702
- WHERE local_grant_id = ? AND revocation_epoch = ?`
34703
- ).run(
34704
- agentIdentityDigest,
34705
- workspaceIdentityDigest,
34706
- workspacePath,
34707
- expiresAt,
34708
- localGrantId,
34709
- currentRevocationEpoch
34710
- );
34711
- if (result.changes !== 1) {
34712
- throw new LocalBotAuthorizationError(
34713
- "local_grant_invalid",
34714
- "The local Bot grant target could not be refreshed"
34715
- );
34716
- }
34717
- this.#database.prepare(
34718
- `INSERT INTO audit_events (recorded_at, event, command_id, session_id, details_json)
34719
- VALUES (?, 'bot_binding_target_refreshed', ?, '', ?)`
34720
- ).run(
34721
- new Date(now).toISOString(),
34722
- rowString(current, "binding_id"),
34723
- JSON.stringify({
34724
- agentIdentityChanged: agentIdentityDigest !== rowString(current, "agent_identity_digest"),
34725
- bindingId: rowString(current, "binding_id"),
34726
- botId: rowString(current, "bot_id"),
34727
- expired: currentExpiresAt <= now,
34728
- revived: rowHasInteger(current, "revoked_at"),
34729
- workspaceIdentityChanged: workspaceIdentityDigest !== rowString(current, "workspace_identity_digest"),
34730
- workspacePathChanged: workspacePath !== rowString(current, "workspace_path")
34731
- })
34732
- );
34733
- this.#database.exec("COMMIT");
34734
- return { expiresAt, revocationEpoch: currentRevocationEpoch + 1 };
34735
- } catch (cause) {
34736
- this.#database.exec("ROLLBACK");
34737
- throw cause;
34738
- }
34090
+ return new AuthorizedLocalBotExecution(command, agent, workspacePath);
34739
34091
  };
34740
34092
  };
34741
34093
 
@@ -34835,7 +34187,7 @@ var BotExecutionContextRegistry = class {
34835
34187
  };
34836
34188
 
34837
34189
  // src/bots/bot-message-command.ts
34838
- import { randomUUID as randomUUID2 } from "node:crypto";
34190
+ import { randomUUID } from "node:crypto";
34839
34191
  import { createConnection } from "node:net";
34840
34192
  var BOT_IPC_RESPONSE_LIMIT = 64 * 1024;
34841
34193
  var BOT_IPC_TIMEOUT_MILLISECONDS = 2e4;
@@ -34984,7 +34336,7 @@ async function executeBotMessageCommand(arguments_, environment, signal) {
34984
34336
  socketPath,
34985
34337
  JSON.stringify({
34986
34338
  contextHandle,
34987
- idempotencyKey: `cli_${randomUUID2()}`,
34339
+ idempotencyKey: `cli_${randomUUID()}`,
34988
34340
  target,
34989
34341
  text: text3
34990
34342
  }),
@@ -35232,7 +34584,7 @@ var BotOutboundIpcServer = class {
35232
34584
  };
35233
34585
 
35234
34586
  // src/pairing/pair-local-machine.ts
35235
- import { randomUUID as randomUUID3 } from "node:crypto";
34587
+ import { randomUUID as randomUUID2 } from "node:crypto";
35236
34588
  import { mkdir as mkdir4, open as open4, realpath as realpath7, rename as rename3, stat as stat6, writeFile as writeFile2 } from "node:fs/promises";
35237
34589
  import { hostname as hostname3 } from "node:os";
35238
34590
  import { basename as basename3, join as join15, resolve as resolve3 } from "node:path";
@@ -36192,7 +35544,7 @@ var HermesAgentSpecification = class extends DirectAcpAgentDefinition {
36192
35544
  import { join as join10 } from "node:path";
36193
35545
 
36194
35546
  // src/agent-installation/managed-agent-archive.ts
36195
- import { createHash as createHash2 } from "node:crypto";
35547
+ import { createHash } from "node:crypto";
36196
35548
  import { createReadStream } from "node:fs";
36197
35549
  import { chmod as chmod2, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open3, realpath as realpath6, rename as rename2, rm as rm2, stat as stat5, writeFile } from "node:fs/promises";
36198
35550
  import { delimiter as delimiter2, dirname as dirname5, isAbsolute as isAbsolute7, join as join9, relative as relative4, sep as sep4 } from "node:path";
@@ -36305,7 +35657,7 @@ function isContainedPath3(root, candidate) {
36305
35657
  }
36306
35658
  async function hashFile(path2, signal) {
36307
35659
  signal.throwIfAborted();
36308
- const digest2 = createHash2("sha256");
35660
+ const digest = createHash("sha256");
36309
35661
  const stream = createReadStream(path2, { signal });
36310
35662
  try {
36311
35663
  for await (const chunk of stream) {
@@ -36316,9 +35668,9 @@ async function hashFile(path2, signal) {
36316
35668
  "The managed Agent archive produced invalid bytes"
36317
35669
  );
36318
35670
  }
36319
- digest2.update(chunk);
35671
+ digest.update(chunk);
36320
35672
  }
36321
- return digest2.digest("hex");
35673
+ return digest.digest("hex");
36322
35674
  } catch (error62) {
36323
35675
  if (signal.aborted) {
36324
35676
  signal.throwIfAborted();
@@ -37407,7 +36759,8 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
37407
36759
  botSessionConfiguration: true,
37408
36760
  capabilities: agent.capabilities,
37409
36761
  id: agent.id,
37410
- label: agent.label
36762
+ label: agent.label,
36763
+ sessionTurnConfiguration: true
37411
36764
  }));
37412
36765
  const endpoint = options.pairingId.length > 0 ? mobiusApiUrl(options.relayOrigin, `/v1/runtime-pairings/${encodeURIComponent(options.pairingId)}/redeem`) : mobiusApiUrl(options.relayOrigin, "/pairings/claim");
37413
36766
  let response;
@@ -37438,7 +36791,7 @@ async function persistConnection(channelId, relayOrigin, runtimeCredential2, def
37438
36791
  const connectionsDirectory = join15(readStateDirectory(environment), "connections");
37439
36792
  await mkdir4(connectionsDirectory, { mode: 448, recursive: true });
37440
36793
  const connectionPath = join15(connectionsDirectory, `${channelId}.json`);
37441
- const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID3()}.tmp`);
36794
+ const temporaryPath = join15(connectionsDirectory, `.${channelId}.${randomUUID2()}.tmp`);
37442
36795
  await writeFile2(
37443
36796
  temporaryPath,
37444
36797
  `${JSON.stringify(
@@ -37588,7 +36941,7 @@ async function resumeLocalMachine(arguments_, signal = new AbortController().sig
37588
36941
  }
37589
36942
 
37590
36943
  // src/run-daemon.ts
37591
- import { randomUUID as randomUUID6 } from "node:crypto";
36944
+ import { randomUUID as randomUUID5 } from "node:crypto";
37592
36945
  import { basename as basename6, join as join17 } from "node:path";
37593
36946
  import { styleText } from "node:util";
37594
36947
  import { fetch as fetch7, WebSocket as WebSocket2 } from "undici";
@@ -37649,7 +37002,8 @@ async function publishAgentCatalog(config2, signal) {
37649
37002
  botSessionConfiguration: true,
37650
37003
  capabilities: agent.capabilities,
37651
37004
  id: agent.id,
37652
- label: agent.label
37005
+ label: agent.label,
37006
+ sessionTurnConfiguration: true
37653
37007
  })),
37654
37008
  installableAgents: catalog.installableAgents
37655
37009
  }),
@@ -38133,7 +37487,7 @@ var FixedInstallationExecutor = class {
38133
37487
  };
38134
37488
 
38135
37489
  // src/artifacts/runtime-artifact-uploader.ts
38136
- import { createHash as createHash3 } from "node:crypto";
37490
+ import { createHash as createHash2 } from "node:crypto";
38137
37491
 
38138
37492
  // ../mobius-sdk/src/errors.ts
38139
37493
  var MobiusError = class extends Error {
@@ -38375,13 +37729,6 @@ var UploadedRuntimeArtifact = class {
38375
37729
  this.sha256 = sha256;
38376
37730
  }
38377
37731
  };
38378
- function daemonToken2(config2) {
38379
- const token = config2.relayUrl.searchParams.get("token");
38380
- if (token === null || token.length < 32) {
38381
- throw new RuntimeArtifactUploadError("artifact_endpoint_invalid", "The Relay daemon token is missing");
38382
- }
38383
- return token;
38384
- }
38385
37732
  function channelOrigin(config2) {
38386
37733
  const url2 = new URL(config2.relayUrl);
38387
37734
  url2.protocol = url2.protocol === "wss:" ? "https:" : "http:";
@@ -38426,24 +37773,23 @@ async function readAuthorization(response) {
38426
37773
  translateSdkError(cause);
38427
37774
  }
38428
37775
  }
38429
- function sessionArtifactUrl(origin, sessionId, resourcePath, token) {
38430
- const url2 = new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
38431
- url2.searchParams.set("token", token);
38432
- return url2;
37776
+ function sessionArtifactUrl(origin, sessionId, resourcePath) {
37777
+ return new URL(`${origin.pathname}/sessions/${encodeURIComponent(sessionId)}/${resourcePath}`, origin);
38433
37778
  }
38434
- async function postLease(url2, request, signal) {
37779
+ async function postLease(url2, headers, request, signal) {
38435
37780
  return await fetch5(url2, {
38436
37781
  dispatcher: environmentProxyDispatcher,
38437
- headers: { "content-type": "application/json" },
37782
+ headers: { ...headers, "content-type": "application/json" },
38438
37783
  method: "POST",
38439
37784
  body: JSON.stringify(request),
38440
37785
  signal
38441
37786
  });
38442
37787
  }
38443
- async function putContent(url2, authorization, bytes, signal) {
37788
+ async function putContent(url2, headers, authorization, bytes, signal) {
38444
37789
  return await fetch5(url2, {
38445
37790
  dispatcher: environmentProxyDispatcher,
38446
37791
  headers: {
37792
+ ...headers,
38447
37793
  "content-type": authorization.mediaType,
38448
37794
  "x-mobius-upload-token": authorization.uploadToken
38449
37795
  },
@@ -38460,7 +37806,7 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
38460
37806
  artifact.name,
38461
37807
  artifact.mimeType,
38462
37808
  artifact.bytes.byteLength,
38463
- createHash3("sha256").update(artifact.bytes).digest("hex")
37809
+ createHash2("sha256").update(artifact.bytes).digest("hex")
38464
37810
  );
38465
37811
  } catch (cause) {
38466
37812
  translateSdkError(cause);
@@ -38468,11 +37814,12 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
38468
37814
  const timeoutSignal = AbortSignal.timeout(UPLOAD_TIMEOUT_MILLISECONDS);
38469
37815
  const requestSignal = AbortSignal.any([signal, timeoutSignal]);
38470
37816
  const origin = channelOrigin(config2);
38471
- const token = daemonToken2(config2);
37817
+ const headers = runtimeAuthorization(config2.relayUrl);
38472
37818
  let created;
38473
37819
  try {
38474
37820
  created = await postLease(
38475
- sessionArtifactUrl(origin, sessionId, "artifacts/uploads", token),
37821
+ sessionArtifactUrl(origin, sessionId, "artifacts/uploads"),
37822
+ headers,
38476
37823
  request,
38477
37824
  requestSignal
38478
37825
  );
@@ -38492,12 +37839,8 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
38492
37839
  let uploaded;
38493
37840
  try {
38494
37841
  uploaded = await putContent(
38495
- sessionArtifactUrl(
38496
- origin,
38497
- sessionId,
38498
- `artifacts/${encodeURIComponent(authorization.artifactId)}/content`,
38499
- token
38500
- ),
37842
+ sessionArtifactUrl(origin, sessionId, `artifacts/${encodeURIComponent(authorization.artifactId)}/content`),
37843
+ headers,
38501
37844
  authorization,
38502
37845
  artifact.bytes,
38503
37846
  requestSignal
@@ -38687,18 +38030,18 @@ var AppliedBotContext = class {
38687
38030
  }
38688
38031
  };
38689
38032
  var EmbeddedBotContextApplicator = class {
38690
- apply = async (command, grant, resources, signal) => {
38033
+ apply = async (command, execution, resources, signal) => {
38691
38034
  signal.throwIfAborted();
38692
- if (grant.botId !== command.botId || grant.behaviorRevisionId !== command.behaviorRevisionId || grant.behaviorDigest !== command.behaviorDigest) {
38035
+ if (execution.botId !== command.botId || execution.behaviorRevisionId !== command.behaviorRevisionId || execution.behaviorDigest !== command.behaviorDigest) {
38693
38036
  throw new LocalBotAuthorizationError(
38694
- "binding_not_approved",
38695
- "The Bot behavior does not match its local authorization"
38037
+ "binding_incompatible",
38038
+ "The Bot behavior does not match the execution target"
38696
38039
  );
38697
38040
  }
38698
38041
  if (command.behaviorInstructions.length === 0) {
38699
38042
  return new AppliedBotContext(resources);
38700
38043
  }
38701
- if (!grant.agent.capabilities.embeddedContextPrompt) {
38044
+ if (!execution.agent.capabilities.embeddedContextPrompt) {
38702
38045
  throw new LocalBotAuthorizationError(
38703
38046
  "binding_incompatible",
38704
38047
  "The local Agent cannot enforce the Bot behavior context"
@@ -38716,7 +38059,7 @@ var EmbeddedBotContextApplicator = class {
38716
38059
  };
38717
38060
 
38718
38061
  // src/native-sessions/service.ts
38719
- import { randomUUID as randomUUID4 } from "node:crypto";
38062
+ import { randomUUID as randomUUID3 } from "node:crypto";
38720
38063
  import { basename as basename5 } from "node:path";
38721
38064
 
38722
38065
  // src/native-sessions/codex-history.ts
@@ -39011,7 +38354,7 @@ var NativeSessionService = class {
39011
38354
  if (authorized === null) {
39012
38355
  return null;
39013
38356
  }
39014
- const entryId = randomUUID4();
38357
+ const entryId = randomUUID3();
39015
38358
  if (this.#entries.size >= 5e3) {
39016
38359
  this.#entries.clear();
39017
38360
  }
@@ -39065,7 +38408,7 @@ var NativeSessionService = class {
39065
38408
  "invalid_native_session_response"
39066
38409
  );
39067
38410
  }
39068
- nextCursor = randomUUID4();
38411
+ nextCursor = randomUUID3();
39069
38412
  if (this.#cursors.size >= 500) {
39070
38413
  this.#cursors.clear();
39071
38414
  }
@@ -39383,7 +38726,7 @@ var NativeSessionService = class {
39383
38726
  };
39384
38727
 
39385
38728
  // src/prompt-artifact-resolver.ts
39386
- import { createHash as createHash4 } from "node:crypto";
38729
+ import { createHash as createHash3 } from "node:crypto";
39387
38730
  import { fetch as fetch6 } from "undici";
39388
38731
  var ARTIFACT_SCHEME = "mobius-artifact:";
39389
38732
  var ARTIFACT_DOWNLOAD_TIMEOUT_MILLISECONDS = 2e4;
@@ -39522,7 +38865,7 @@ async function download(config2, command, reference, signal) {
39522
38865
  );
39523
38866
  }
39524
38867
  const bytes = await responseBytes(response, reference.byteLength, requestSignal);
39525
- if (createHash4("sha256").update(bytes).digest("hex") !== reference.sha256) {
38868
+ if (createHash3("sha256").update(bytes).digest("hex") !== reference.sha256) {
39526
38869
  throw new PromptArtifactError(
39527
38870
  "artifact_integrity_failed",
39528
38871
  "The prompt artifact failed integrity validation"
@@ -39831,7 +39174,7 @@ var RelayConnectionDiagnostics = class {
39831
39174
  };
39832
39175
 
39833
39176
  // src/relay-connection/liveness.ts
39834
- import { randomUUID as randomUUID5 } from "node:crypto";
39177
+ import { randomUUID as randomUUID4 } from "node:crypto";
39835
39178
  var HEARTBEAT_ACK_TIMEOUT_MILLISECONDS = 1e4;
39836
39179
  var HEARTBEAT_INTERVAL_MILLISECONDS = 2e4;
39837
39180
  var RelayLivenessState = class {
@@ -39920,7 +39263,7 @@ var RelayConnectionLiveness = class {
39920
39263
  }
39921
39264
  throw new Error("Heartbeat was scheduled in an invalid state");
39922
39265
  }
39923
- const heartbeatId = randomUUID5();
39266
+ const heartbeatId = randomUUID4();
39924
39267
  this.#state = new AwaitingHeartbeatAckState(
39925
39268
  heartbeatId,
39926
39269
  this.#timer.schedule(this.#handleTimeout, HEARTBEAT_ACK_TIMEOUT_MILLISECONDS)
@@ -39937,7 +39280,7 @@ var RelayConnectionLiveness = class {
39937
39280
  // src/relay-connection/session-event-outbox.ts
39938
39281
  import { mkdirSync as mkdirSync3 } from "node:fs";
39939
39282
  import { dirname as dirname7 } from "node:path";
39940
- import { DatabaseSync as DatabaseSync4 } from "node:sqlite";
39283
+ import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
39941
39284
  var DEFAULT_OUTBOX_LIMITS = {
39942
39285
  criticalEventBytes: 136 * 1024 * 1024,
39943
39286
  runtimeDeliveryBytes: 64 * 1024 * 1024,
@@ -39989,7 +39332,7 @@ function rowNumber(row, field) {
39989
39332
  }
39990
39333
  return value;
39991
39334
  }
39992
- function rowString2(row, field) {
39335
+ function rowString(row, field) {
39993
39336
  const value = typeof row === "object" && row !== null ? Reflect.get(row, field) : void 0;
39994
39337
  if (typeof value !== "string" || value.length === 0) {
39995
39338
  throw new Error(`SQLite returned an invalid ${field} value`);
@@ -40003,7 +39346,7 @@ var SessionEventOutbox = class {
40003
39346
  validateLimits(limits);
40004
39347
  this.#limits = limits;
40005
39348
  mkdirSync3(dirname7(path2), { recursive: true });
40006
- this.#database = new DatabaseSync4(path2);
39349
+ this.#database = new DatabaseSync3(path2);
40007
39350
  this.#database.exec(`
40008
39351
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
40009
39352
  ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -40238,8 +39581,8 @@ var SessionEventOutbox = class {
40238
39581
  WHERE delivery_id = ?`
40239
39582
  ).get(delivery.deliveryId);
40240
39583
  if (existing !== void 0) {
40241
- const sessionId = rowString2(existing, "session_id");
40242
- const payload = rowString2(existing, "payload_json");
39584
+ const sessionId = rowString(existing, "session_id");
39585
+ const payload = rowString(existing, "payload_json");
40243
39586
  const state = runtimeDeliveryState(existing);
40244
39587
  if (sessionId !== delivery.sessionId || payload !== delivery.payload) {
40245
39588
  throw new Error("The Runtime delivery identity conflicts with its durable receipt");
@@ -40327,9 +39670,9 @@ var SessionEventOutbox = class {
40327
39670
  ORDER BY received_at, delivery_id`
40328
39671
  ).all().map(
40329
39672
  (row) => new StoredRuntimeDelivery(
40330
- rowString2(row, "delivery_id"),
40331
- rowString2(row, "session_id"),
40332
- rowString2(row, "payload_json"),
39673
+ rowString(row, "delivery_id"),
39674
+ rowString(row, "session_id"),
39675
+ rowString(row, "payload_json"),
40333
39676
  runtimeDeliveryState(row),
40334
39677
  true
40335
39678
  )
@@ -40511,7 +39854,7 @@ function validateLimits(limits) {
40511
39854
  }
40512
39855
  }
40513
39856
  function runtimeDeliveryState(row) {
40514
- const state = rowString2(row, "state");
39857
+ const state = rowString(row, "state");
40515
39858
  if (state !== "received" && state !== "relay_committed" && state !== "processed") {
40516
39859
  throw new Error("SQLite returned an invalid Runtime delivery state");
40517
39860
  }
@@ -40537,9 +39880,9 @@ var ACTIVE_TURN_RECONCILIATION_TIMEOUT_MILLISECONDS = 2e4;
40537
39880
  var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
40538
39881
  function botIpcSocketPath() {
40539
39882
  if (process.platform === "win32") {
40540
- return `\\\\.\\pipe\\mobius-bot-${randomUUID6()}`;
39883
+ return `\\\\.\\pipe\\mobius-bot-${randomUUID5()}`;
40541
39884
  }
40542
- return join17("/tmp", `mobius-bot-${randomUUID6()}.sock`);
39885
+ return join17("/tmp", `mobius-bot-${randomUUID5()}.sock`);
40543
39886
  }
40544
39887
  var DaemonAcpObserver = class {
40545
39888
  #config;
@@ -41331,6 +40674,36 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
41331
40674
  signal
41332
40675
  );
41333
40676
  const agent = config2.catalog.find(command.agentId);
40677
+ if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
40678
+ throw new AcpExecutionError(
40679
+ "The queued prompt target is unavailable",
40680
+ {},
40681
+ "prompt_queue_target_unavailable"
40682
+ );
40683
+ }
40684
+ if (command.sessionConfigurations !== void 0) {
40685
+ const prepared = await sessions.prepareExecutionSession({
40686
+ additionalDirectories: resolved.additionalDirectories,
40687
+ agent,
40688
+ cwd: resolved.cwd,
40689
+ sessionId: command.sessionId,
40690
+ signal
40691
+ });
40692
+ if (command.disposition === SessionPromptDisposition.Steer) {
40693
+ assertCompleteSessionConfiguration(prepared.configOptions, command.sessionConfigurations);
40694
+ } else {
40695
+ await applyCompleteSessionConfiguration(
40696
+ sessions,
40697
+ prepared.configOptions,
40698
+ command.sessionConfigurations,
40699
+ agent,
40700
+ resolved.cwd,
40701
+ resolved.additionalDirectories,
40702
+ command.sessionId,
40703
+ signal
40704
+ );
40705
+ }
40706
+ }
41334
40707
  audit.record({
41335
40708
  commandId: command.commandId,
41336
40709
  event: "session_authorized",
@@ -41365,13 +40738,6 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
41365
40738
  });
41366
40739
  stopReason = "steered";
41367
40740
  } else {
41368
- if (command.disposition === SessionPromptDisposition.Queue && !outbox.isTerminalExecution(command.targetCommandId, command.sessionId)) {
41369
- throw new AcpExecutionError(
41370
- "The queued prompt target is unavailable",
41371
- {},
41372
- "prompt_queue_target_unavailable"
41373
- );
41374
- }
41375
40741
  const result = await sessions.runPrompt({
41376
40742
  additionalDirectories: resolved.additionalDirectories,
41377
40743
  agent,
@@ -41438,6 +40804,113 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
41438
40804
  console.error("Mobius daemon command failed", error62);
41439
40805
  }
41440
40806
  }
40807
+ function invalidSessionConfiguration(message) {
40808
+ return new AcpExecutionError(message, {}, "invalid_session_configuration");
40809
+ }
40810
+ function validateSessionConfigurationSelection(option2, selection) {
40811
+ if (option2.type !== selection.valueType) {
40812
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
40813
+ }
40814
+ if (option2.type === "boolean") {
40815
+ if (selection.value.length > 0) {
40816
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
40817
+ }
40818
+ return;
40819
+ }
40820
+ if (selection.booleanValue) {
40821
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an invalid value`);
40822
+ }
40823
+ if (!option2.values.some((value) => value.value === selection.value)) {
40824
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} has an unavailable value`);
40825
+ }
40826
+ }
40827
+ function assertSessionConfigurationSchema(options, selections) {
40828
+ if (options.length !== selections.length) {
40829
+ throw invalidSessionConfiguration("The Turn configuration does not match the Agent settings schema");
40830
+ }
40831
+ const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40832
+ if (selectionsById.size !== selections.length) {
40833
+ throw invalidSessionConfiguration("The Turn configuration contains duplicate Agent settings");
40834
+ }
40835
+ for (const option2 of options) {
40836
+ const selection = selectionsById.get(option2.id);
40837
+ if (selection === void 0 || selection.valueType !== option2.type || option2.type === "boolean" && selection.value.length > 0 || option2.type === "select" && selection.booleanValue) {
40838
+ throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option2.id}`);
40839
+ }
40840
+ }
40841
+ }
40842
+ function sessionConfigurationMatches(option2, selection) {
40843
+ validateSessionConfigurationSelection(option2, selection);
40844
+ return option2.type === "boolean" ? option2.booleanValue === selection.booleanValue : option2.currentValue === selection.value;
40845
+ }
40846
+ function sessionConfigurationPriority(selection, options) {
40847
+ if (selection.configId === "permission_mode") {
40848
+ return 0;
40849
+ }
40850
+ const option2 = options.find((candidate) => candidate.id === selection.configId);
40851
+ if (selection.configId === "model" || option2?.category === "model") {
40852
+ return 1;
40853
+ }
40854
+ if (selection.configId === "reasoning_effort" || option2?.category === "thought_level") {
40855
+ return 2;
40856
+ }
40857
+ if (option2?.category === "model_config") {
40858
+ return 3;
40859
+ }
40860
+ return 4;
40861
+ }
40862
+ function assertCompleteSessionConfiguration(options, selections) {
40863
+ assertSessionConfigurationSchema(options, selections);
40864
+ const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40865
+ for (const option2 of options) {
40866
+ const selection = selectionsById.get(option2.id);
40867
+ if (selection === void 0 || !sessionConfigurationMatches(option2, selection)) {
40868
+ throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option2.id}`);
40869
+ }
40870
+ }
40871
+ }
40872
+ async function applySessionConfigurationSelection(sessions, options, selection, agent, cwd, additionalDirectories, sessionId, signal) {
40873
+ const option2 = options.find((candidate) => candidate.id === selection.configId);
40874
+ if (option2 === void 0) {
40875
+ throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
40876
+ }
40877
+ if (sessionConfigurationMatches(option2, selection)) {
40878
+ return options;
40879
+ }
40880
+ return await sessions.configureSession({
40881
+ additionalDirectories,
40882
+ agent,
40883
+ booleanValue: selection.booleanValue,
40884
+ configId: selection.configId,
40885
+ cwd,
40886
+ requestId: `cfg_${randomUUID5()}`,
40887
+ sessionId,
40888
+ signal,
40889
+ value: selection.value,
40890
+ valueType: selection.valueType
40891
+ });
40892
+ }
40893
+ async function applyCompleteSessionConfiguration(sessions, initialOptions, selections, agent, cwd, additionalDirectories, sessionId, signal) {
40894
+ assertSessionConfigurationSchema(initialOptions, selections);
40895
+ let options = initialOptions;
40896
+ const orderedSelections = selections.toSorted((left, right) => {
40897
+ const priority = sessionConfigurationPriority(left, initialOptions) - sessionConfigurationPriority(right, initialOptions);
40898
+ return priority === 0 ? left.configId.localeCompare(right.configId) : priority;
40899
+ });
40900
+ for (const selection of orderedSelections) {
40901
+ options = await applySessionConfigurationSelection(
40902
+ sessions,
40903
+ options,
40904
+ selection,
40905
+ agent,
40906
+ cwd,
40907
+ additionalDirectories,
40908
+ sessionId,
40909
+ signal
40910
+ );
40911
+ }
40912
+ assertCompleteSessionConfiguration(options, selections);
40913
+ }
41441
40914
  function botExecutionAgent(agent, contextHandle, socketPath) {
41442
40915
  return new LocalAgentDefinition(
41443
40916
  agent.id,
@@ -41498,14 +40971,14 @@ async function applyRequiredExecutionSelection(sessions, configOptions, selectio
41498
40971
  booleanValue: false,
41499
40972
  configId: selection.configId,
41500
40973
  cwd,
41501
- requestId: `cfg_${randomUUID6()}`,
40974
+ requestId: `cfg_${randomUUID5()}`,
41502
40975
  sessionId,
41503
40976
  signal,
41504
40977
  value: selection.value,
41505
40978
  valueType: "select"
41506
40979
  });
41507
40980
  }
41508
- async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, grants, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
40981
+ async function executeBotPrompt(outbox, publisher, command, config2, directories, audit, sessions, authorizer, contexts, applicator, ipc, attemptId, activateAttempt, timer, signal) {
41509
40982
  const activities = new CoalescingDaemonActivityPublisher(timer, (activity) => {
41510
40983
  publisher.recordAttempt(command.sessionId, encodeDaemonActivity(command, activity), attemptId);
41511
40984
  });
@@ -41515,21 +40988,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41515
40988
  if (!Number.isSafeInteger(deadline) || remaining <= 0) {
41516
40989
  throw new LocalBotAuthorizationError("turn_expired", "The Bot execution deadline has expired");
41517
40990
  }
41518
- const grant = await grants.resolveExecution(
41519
- command,
41520
- config2.catalog,
41521
- directories,
41522
- config2.bindingId,
41523
- Date.now(),
41524
- signal
41525
- );
41526
- const requestedExecutionTargetOverridden = command.directoryId !== grant.workspaceRef || command.additionalDirectoryIds.length > 0;
41527
- if (requestedExecutionTargetOverridden && !(command.replyRoute instanceof OwnerBotReplyRoute)) {
41528
- throw new LocalBotAuthorizationError(
41529
- "binding_not_approved",
41530
- "Only a paired owner conversation can override the approved Bot workspace"
41531
- );
41532
- }
40991
+ const execution = await authorizer.authorize(command, config2.catalog, directories, config2.bindingId, signal);
41533
40992
  const resolved = await resolveSessionDirectories(
41534
40993
  directories,
41535
40994
  config2.bindingId,
@@ -41537,20 +40996,8 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41537
40996
  command.additionalDirectoryIds,
41538
40997
  signal
41539
40998
  );
41540
- const executionTargetOverridden = resolved.cwd !== grant.workspacePath || resolved.additionalDirectories.length > 0;
41541
- if (executionTargetOverridden && !sessions.hasPreparedSession(
41542
- command.sessionId,
41543
- grant.agent.id,
41544
- resolved.cwd,
41545
- resolved.additionalDirectories
41546
- )) {
41547
- throw new LocalBotAuthorizationError(
41548
- "local_approval_required",
41549
- "Open this Bot conversation in the paired local Web app before using the selected workspace"
41550
- );
41551
- }
41552
40999
  const attachments = await resolvePromptArtifacts(config2, command, signal);
41553
- const applied = await applicator.apply(command, grant, attachments.resources, signal);
41000
+ const applied = await applicator.apply(command, execution, attachments.resources, signal);
41554
41001
  const deadlineSignal = AbortSignal.timeout(remaining);
41555
41002
  const executionSignal = AbortSignal.any([signal, deadlineSignal]);
41556
41003
  const startExecution = () => {
@@ -41560,8 +41007,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41560
41007
  behaviorRevisionId: command.behaviorRevisionId,
41561
41008
  bindingId: command.bindingId,
41562
41009
  botId: command.botId,
41563
- executionId: command.executionId,
41564
- localGrantId: command.localGrantId
41010
+ executionId: command.executionId
41565
41011
  },
41566
41012
  event: "bot_session_authorized",
41567
41013
  sessionId: command.sessionId
@@ -41584,7 +41030,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41584
41030
  startExecution();
41585
41031
  await sessions.steerPrompt({
41586
41032
  additionalDirectories: resolved.additionalDirectories,
41587
- agent: grant.agent,
41033
+ agent: execution.agent,
41588
41034
  commandId: command.commandId,
41589
41035
  cwd: resolved.cwd,
41590
41036
  images: attachments.images,
@@ -41604,7 +41050,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41604
41050
  }
41605
41051
  const lease = contexts.activate(command);
41606
41052
  try {
41607
- const agent = botExecutionAgent(grant.agent, lease.context.contextHandle, ipc.socketPath);
41053
+ const agent = botExecutionAgent(execution.agent, lease.context.contextHandle, ipc.socketPath);
41608
41054
  const prepared = await sessions.prepareExecutionSession({
41609
41055
  additionalDirectories: resolved.additionalDirectories,
41610
41056
  agent,
@@ -41612,11 +41058,11 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41612
41058
  sessionId: command.sessionId,
41613
41059
  signal: executionSignal
41614
41060
  });
41615
- assertPreparedPermission(prepared.configOptions, grant.executionConfiguration.permissionMode);
41061
+ assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41616
41062
  let configOptions = await applyRequiredExecutionSelection(
41617
41063
  sessions,
41618
41064
  prepared.configOptions,
41619
- grant.executionConfiguration.model,
41065
+ execution.executionConfiguration.model,
41620
41066
  "model",
41621
41067
  agent,
41622
41068
  resolved.cwd,
@@ -41627,7 +41073,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41627
41073
  configOptions = await applyRequiredExecutionSelection(
41628
41074
  sessions,
41629
41075
  configOptions,
41630
- grant.executionConfiguration.reasoningEffort,
41076
+ execution.executionConfiguration.reasoningEffort,
41631
41077
  "thought_level",
41632
41078
  agent,
41633
41079
  resolved.cwd,
@@ -41642,7 +41088,7 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41642
41088
  booleanValue: selection.booleanValue,
41643
41089
  configId: selection.configId,
41644
41090
  cwd: resolved.cwd,
41645
- requestId: `cfg_${randomUUID6()}`,
41091
+ requestId: `cfg_${randomUUID5()}`,
41646
41092
  sessionId: command.sessionId,
41647
41093
  signal: executionSignal,
41648
41094
  value: selection.value,
@@ -41774,13 +41220,13 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
41774
41220
  {
41775
41221
  agentId: agent.id,
41776
41222
  kind: AGENT_INSTALL_REQUEST_KIND,
41777
- requestId: `automatic-integration-${randomUUID6()}`
41223
+ requestId: `automatic-integration-${randomUUID5()}`
41778
41224
  },
41779
41225
  signal
41780
41226
  );
41781
41227
  }
41782
41228
  }
41783
- async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, grants, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41229
+ async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, authorizer, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
41784
41230
  const relayUrl = new URL(config2.relayUrl);
41785
41231
  relayUrl.searchParams.set("deliveryReceipts", "1");
41786
41232
  relayUrl.searchParams.set("liveness", "1");
@@ -41960,7 +41406,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41960
41406
  directories,
41961
41407
  audit,
41962
41408
  sessions,
41963
- grants,
41409
+ authorizer,
41964
41410
  contexts,
41965
41411
  applicator,
41966
41412
  ipc,
@@ -42140,70 +41586,6 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42140
41586
  }
42141
41587
  return;
42142
41588
  }
42143
- if (kind === BOT_BINDING_APPROVED_KIND) {
42144
- decodeBotExecutionBindingApprovedEvent(encoded);
42145
- return;
42146
- }
42147
- if (kind === BOT_BINDING_UNAVAILABLE_KIND) {
42148
- decodeBotExecutionBindingUnavailableEvent(encoded);
42149
- return;
42150
- }
42151
- if (kind === BOT_BINDING_APPROVAL_REQUEST_KIND) {
42152
- const request = decodeBotExecutionBindingApprovalRequest(encoded);
42153
- void grants.approve(
42154
- request,
42155
- config2.catalog,
42156
- directories,
42157
- config2.bindingId,
42158
- Date.now(),
42159
- connectionController.signal
42160
- ).then((approved) => {
42161
- audit.record({
42162
- commandId: request.requestId,
42163
- details: {
42164
- behaviorRevisionId: request.behaviorRevisionId,
42165
- bindingId: request.bindingId,
42166
- botId: request.botId,
42167
- localGrantId: approved.localGrantId
42168
- },
42169
- event: "bot_binding_approved",
42170
- sessionId: `bot-binding:${request.bindingId}`
42171
- });
42172
- if (socket.readyState === WebSocket2.OPEN) {
42173
- send(socket, encodeBotExecutionBindingApprovedEvent(approved));
42174
- }
42175
- }).catch((error62) => {
42176
- if (connectionController.signal.aborted) {
42177
- return;
42178
- }
42179
- const code = error62 instanceof LocalBotAuthorizationError ? error62.code : "binding_incompatible";
42180
- const message = error62 instanceof LocalBotAuthorizationError ? error62.message : "The local execution target is incompatible";
42181
- grants.recordUnavailable(request, code, message, Date.now());
42182
- audit.record({
42183
- commandId: request.requestId,
42184
- details: { bindingId: request.bindingId, botId: request.botId, code },
42185
- event: "bot_binding_unavailable",
42186
- sessionId: `bot-binding:${request.bindingId}`
42187
- });
42188
- if (socket.readyState === WebSocket2.OPEN) {
42189
- send(
42190
- socket,
42191
- encodeBotExecutionBindingUnavailableEvent(
42192
- new BotExecutionBindingUnavailableEvent(
42193
- request.requestId,
42194
- request.botId,
42195
- request.behaviorRevisionId,
42196
- request.bindingId,
42197
- request.bindingRevision,
42198
- code,
42199
- message
42200
- )
42201
- )
42202
- );
42203
- }
42204
- });
42205
- return;
42206
- }
42207
41589
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
42208
41590
  const command2 = decodeNativeSessionCancel(encoded);
42209
41591
  const pending = nativeRequests.get(command2.requestId);
@@ -42599,7 +41981,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
42599
41981
  directories,
42600
41982
  audit,
42601
41983
  sessions,
42602
- grants,
41984
+ authorizer,
42603
41985
  contexts,
42604
41986
  applicator,
42605
41987
  ipc,
@@ -42725,7 +42107,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42725
42107
  const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
42726
42108
  const outbox = new SessionEventOutbox(config2.auditDatabasePath);
42727
42109
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
42728
- const grants = new LocalBotGrantStore(config2.auditDatabasePath);
42110
+ const authorizer = new LocalBotExecutionAuthorizer();
42729
42111
  const contexts = new BotExecutionContextRegistry();
42730
42112
  const applicator = new EmbeddedBotContextApplicator();
42731
42113
  const ipc = new BotOutboundIpcServer(botIpcSocketPath(), config2.relayUrl, contexts);
@@ -42816,7 +42198,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42816
42198
  nativeSessions,
42817
42199
  outbox,
42818
42200
  publisher,
42819
- grants,
42201
+ authorizer,
42820
42202
  contexts,
42821
42203
  applicator,
42822
42204
  ipc,
@@ -42861,13 +42243,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
42861
42243
  sessionStore.close();
42862
42244
  } finally {
42863
42245
  try {
42864
- grants.close();
42246
+ publisher.close();
42865
42247
  } finally {
42866
- try {
42867
- publisher.close();
42868
- } finally {
42869
- outbox.close();
42870
- }
42248
+ outbox.close();
42871
42249
  }
42872
42250
  }
42873
42251
  }