@moxt-ai/mobius 0.0.50 → 0.0.52

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 (33) hide show
  1. package/dist/acp/session-config/grok-build-session-config.d.ts.map +1 -1
  2. package/dist/acp/session-config/grok-build-session-config.js +2 -2
  3. package/dist/acp/session-config/grok-build-session-config.js.map +1 -1
  4. package/dist/acp/session-config/session-config-protocol.d.ts +0 -2
  5. package/dist/acp/session-config/session-config-protocol.d.ts.map +1 -1
  6. package/dist/acp/session-config/session-config-protocol.js +8 -107
  7. package/dist/acp/session-config/session-config-protocol.js.map +1 -1
  8. package/dist/acp/session-manager.d.ts +2 -0
  9. package/dist/acp/session-manager.d.ts.map +1 -1
  10. package/dist/acp/session-manager.js +28 -43
  11. package/dist/acp/session-manager.js.map +1 -1
  12. package/dist/agent-catalog/agent-settings-adapter.d.ts +22 -0
  13. package/dist/agent-catalog/agent-settings-adapter.d.ts.map +1 -0
  14. package/dist/agent-catalog/agent-settings-adapter.js +191 -0
  15. package/dist/agent-catalog/agent-settings-adapter.js.map +1 -0
  16. package/dist/agent-catalog/local-agent.d.ts +2 -4
  17. package/dist/agent-catalog/local-agent.d.ts.map +1 -1
  18. package/dist/agent-catalog/local-agent.js +3 -12
  19. package/dist/agent-catalog/local-agent.js.map +1 -1
  20. package/dist/cli.js +22730 -22714
  21. package/dist/cli.js.map +4 -4
  22. package/dist/index.js +496 -482
  23. package/dist/index.js.map +4 -4
  24. package/dist/run-daemon.d.ts.map +1 -1
  25. package/dist/run-daemon.js +162 -45
  26. package/dist/run-daemon.js.map +1 -1
  27. package/dist/runtime.js +22654 -22638
  28. package/dist/runtime.js.map +4 -4
  29. package/package.json +1 -1
  30. package/dist/agent-catalog/agent-permission-profile.d.ts +0 -16
  31. package/dist/agent-catalog/agent-permission-profile.d.ts.map +0 -1
  32. package/dist/agent-catalog/agent-permission-profile.js +0 -194
  33. package/dist/agent-catalog/agent-permission-profile.js.map +0 -1
package/dist/index.js CHANGED
@@ -16628,8 +16628,8 @@ function rewriteKeyNames(ctx) {
16628
16628
  bySchema.set(entry.schema, entry);
16629
16629
  }
16630
16630
  const rewrites = /* @__PURE__ */ new Map();
16631
- for (const record4 of pendingRecords.get(ctx) ?? []) {
16632
- const seen = ctx.seen.get(record4);
16631
+ for (const record3 of pendingRecords.get(ctx) ?? []) {
16632
+ const seen = ctx.seen.get(record3);
16633
16633
  const names = (seen?.def ?? seen?.schema)?.propertyNames;
16634
16634
  if (!names || names === true || rewrites.has(names))
16635
16635
  continue;
@@ -19875,21 +19875,46 @@ var sessionConfigOptionSchema = external_exports.strictObject({
19875
19875
  values: external_exports.array(configValueSchema).max(500).readonly()
19876
19876
  }).readonly();
19877
19877
  var sessionConfigOptionsSchema = external_exports.array(sessionConfigOptionSchema).max(100).readonly();
19878
+ var agentSettingSchema = external_exports.strictObject({
19879
+ booleanValue: external_exports.boolean(),
19880
+ category: external_exports.string().max(128),
19881
+ defaultValue: external_exports.string().max(500),
19882
+ description: SHORT_TEXT,
19883
+ id: external_exports.string().min(1).max(128),
19884
+ name: external_exports.string().min(1).max(255),
19885
+ type: external_exports.enum(["boolean", "select"]),
19886
+ values: external_exports.array(configValueSchema).max(500).readonly()
19887
+ }).readonly();
19888
+ var agentSettingsSchema = external_exports.array(agentSettingSchema).max(128).readonly();
19889
+ var AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE = "complete";
19890
+ var AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION = "on_model_selection";
19891
+ var AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE = "unavailable";
19892
+ var agentModelEffortResolutionSchema = external_exports.enum([
19893
+ AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE,
19894
+ AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION,
19895
+ AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE
19896
+ ]);
19897
+ var agentModelEffortSchema = external_exports.strictObject({
19898
+ effortSettingId: external_exports.string().max(128),
19899
+ modelSettingId: external_exports.string().max(128),
19900
+ resolution: agentModelEffortResolutionSchema,
19901
+ valuesByModel: external_exports.record(external_exports.string().min(1).max(500), external_exports.array(configValueSchema).max(500).readonly()).readonly()
19902
+ }).readonly();
19878
19903
  var agentSettingsDiscoverCommandSchema = external_exports.strictObject({
19879
- additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly(),
19880
19904
  agentId: IDENTIFIER,
19881
- directoryId: DIRECTORY_IDENTIFIER,
19882
19905
  kind: external_exports.literal(AGENT_SETTINGS_DISCOVER_KIND),
19906
+ model: external_exports.string().min(1).max(500).optional(),
19883
19907
  requestId: IDENTIFIER
19884
19908
  }).readonly();
19885
19909
  var agentSettingsDiscoveredEventSchema = external_exports.strictObject({
19886
19910
  agentId: IDENTIFIER,
19887
19911
  agentName: external_exports.string().max(255),
19888
19912
  agentVersion: external_exports.string().max(128),
19889
- configOptions: sessionConfigOptionsSchema,
19890
- directoryId: DIRECTORY_IDENTIFIER,
19891
19913
  kind: external_exports.literal(AGENT_SETTINGS_DISCOVERED_KIND),
19892
- requestId: IDENTIFIER
19914
+ modelEffort: agentModelEffortSchema,
19915
+ requestId: IDENTIFIER,
19916
+ settings: agentSettingsSchema,
19917
+ settingsRevision: external_exports.string().regex(/^[a-f0-9]{64}$/)
19893
19918
  }).readonly();
19894
19919
  var agentSettingsDiscoveryFailedEventSchema = external_exports.strictObject({
19895
19920
  code: IDENTIFIER,
@@ -21660,199 +21685,6 @@ async function runBoundedProcess(options) {
21660
21685
  }
21661
21686
  }
21662
21687
 
21663
- // src/agent-catalog/agent-permission-profile.ts
21664
- var AGENT_DEFAULT_PERMISSION_MODE = AGENT_DEFAULT_EXECUTION_SETTING;
21665
- var READ_ONLY_PERMISSION_MODE = "read-only";
21666
- var WORKSPACE_WRITE_PERMISSION_MODE = "workspace-write";
21667
- var DANGER_FULL_ACCESS_PERMISSION_MODE = "danger-full-access";
21668
- var PERMISSION_MODE_CONFIG_ID = AGENT_PERMISSION_MODE_CONFIG_ID;
21669
- var PERMISSION_MODE_MARKER = "MOBIUS_AGENT_PERMISSION_MODE";
21670
- var AgentPermissionConfigurationError = class extends Error {
21671
- code = "invalid_agent_permission_configuration";
21672
- constructor(message, options = {}) {
21673
- super(message, options);
21674
- this.name = "AgentPermissionConfigurationError";
21675
- }
21676
- };
21677
- var AgentPermissionProfile = class {
21678
- option = (environment) => ({
21679
- booleanValue: false,
21680
- category: "_mobius_permission",
21681
- currentValue: this.currentMode(environment),
21682
- description: this.description,
21683
- id: PERMISSION_MODE_CONFIG_ID,
21684
- name: "Permissions",
21685
- type: "select",
21686
- values: this.values
21687
- });
21688
- };
21689
- var AgentManagedPermissionProfile = class extends AgentPermissionProfile {
21690
- description = "This Agent manages its own local permissions.";
21691
- values = Object.freeze([
21692
- {
21693
- description: "Managed by the Agent",
21694
- groupId: "",
21695
- groupName: "",
21696
- name: "Agent default",
21697
- value: AGENT_DEFAULT_PERMISSION_MODE
21698
- }
21699
- ]);
21700
- currentMode = () => AGENT_DEFAULT_PERMISSION_MODE;
21701
- apply = (environment, permissionMode) => {
21702
- if (permissionMode !== AGENT_DEFAULT_PERMISSION_MODE) {
21703
- throw new AgentPermissionConfigurationError("The selected Agent does not support this permission mode");
21704
- }
21705
- return Object.freeze({ ...environment });
21706
- };
21707
- };
21708
- var PiPermissionProfile = class extends AgentPermissionProfile {
21709
- description = "Pi has no built-in sandbox and runs with the local Runtime user's authority.";
21710
- values = Object.freeze([
21711
- {
21712
- description: "Pi default; unrestricted local execution with the Runtime user's authority",
21713
- groupId: "",
21714
- groupName: "",
21715
- name: "Full access (Pi default)",
21716
- value: DANGER_FULL_ACCESS_PERMISSION_MODE
21717
- }
21718
- ]);
21719
- currentMode = () => DANGER_FULL_ACCESS_PERMISSION_MODE;
21720
- apply = (environment, permissionMode) => {
21721
- if (permissionMode !== DANGER_FULL_ACCESS_PERMISSION_MODE) {
21722
- throw new AgentPermissionConfigurationError("Pi only supports its default full-access permission mode");
21723
- }
21724
- return Object.freeze({ ...environment });
21725
- };
21726
- };
21727
- var adjustablePermissionValues = Object.freeze([
21728
- {
21729
- description: "Keep the Agent's existing permission policy",
21730
- groupId: "",
21731
- groupName: "",
21732
- name: "Agent default",
21733
- value: AGENT_DEFAULT_PERMISSION_MODE
21734
- },
21735
- {
21736
- description: "Allow inspection without local writes or commands that can change state",
21737
- groupId: "",
21738
- groupName: "",
21739
- name: "Read only",
21740
- value: READ_ONLY_PERMISSION_MODE
21741
- },
21742
- {
21743
- description: "Allow changes inside the selected workspace while protecting external paths",
21744
- groupId: "",
21745
- groupName: "",
21746
- name: "Workspace write",
21747
- value: WORKSPACE_WRITE_PERMISSION_MODE
21748
- },
21749
- {
21750
- description: "Allow unrestricted local execution with the Runtime user's authority",
21751
- groupId: "",
21752
- groupName: "",
21753
- name: "Full access",
21754
- value: DANGER_FULL_ACCESS_PERMISSION_MODE
21755
- }
21756
- ]);
21757
- function validateAdjustableMode(permissionMode) {
21758
- if (!adjustablePermissionValues.some((value) => value.value === permissionMode)) {
21759
- throw new AgentPermissionConfigurationError("The selected permission mode is unavailable");
21760
- }
21761
- return permissionMode;
21762
- }
21763
- var DeepSeekHarnessPermissionProfile = class extends AgentPermissionProfile {
21764
- description = "Controls the local side effects allowed for this Agent session.";
21765
- values = adjustablePermissionValues;
21766
- currentMode = (environment) => validateAdjustableMode(environment["DSH_PERMISSION_MODE"] ?? WORKSPACE_WRITE_PERMISSION_MODE);
21767
- apply = (environment, permissionMode) => {
21768
- if (permissionMode === AGENT_DEFAULT_PERMISSION_MODE) {
21769
- return Object.freeze({ ...environment });
21770
- }
21771
- return Object.freeze({
21772
- ...environment,
21773
- DSH_PERMISSION_MODE: validateAdjustableMode(permissionMode),
21774
- [PERMISSION_MODE_MARKER]: permissionMode
21775
- });
21776
- };
21777
- };
21778
- function record2(value) {
21779
- if (value === void 0) {
21780
- return {};
21781
- }
21782
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
21783
- throw new AgentPermissionConfigurationError("The OpenCode inline configuration is invalid");
21784
- }
21785
- return Object.fromEntries(Object.entries(value));
21786
- }
21787
- function openCodeConfiguration(environment) {
21788
- const encoded = environment["OPENCODE_CONFIG_CONTENT"];
21789
- if (encoded === void 0 || encoded.length === 0) {
21790
- return {};
21791
- }
21792
- try {
21793
- return record2(JSON.parse(encoded));
21794
- } catch (cause) {
21795
- if (cause instanceof AgentPermissionConfigurationError) {
21796
- throw cause;
21797
- }
21798
- throw new AgentPermissionConfigurationError("The OpenCode inline configuration is invalid", { cause });
21799
- }
21800
- }
21801
- function openCodePermission(permissionMode) {
21802
- if (permissionMode === READ_ONLY_PERMISSION_MODE) {
21803
- return {
21804
- "*": "deny",
21805
- glob: "allow",
21806
- grep: "allow",
21807
- lsp: "allow",
21808
- read: "allow",
21809
- skill: "allow"
21810
- };
21811
- }
21812
- if (permissionMode === WORKSPACE_WRITE_PERMISSION_MODE) {
21813
- return {
21814
- "*": "allow",
21815
- external_directory: "ask"
21816
- };
21817
- }
21818
- return "allow";
21819
- }
21820
- var OpenCodePermissionProfile = class extends AgentPermissionProfile {
21821
- description = "Controls the local side effects allowed for this Agent session.";
21822
- values = adjustablePermissionValues;
21823
- currentMode = (environment) => validateAdjustableMode(environment[PERMISSION_MODE_MARKER] ?? AGENT_DEFAULT_PERMISSION_MODE);
21824
- apply = (environment, permissionMode) => {
21825
- const validated = validateAdjustableMode(permissionMode);
21826
- if (validated === AGENT_DEFAULT_PERMISSION_MODE) {
21827
- return Object.freeze({ ...environment });
21828
- }
21829
- return Object.freeze({
21830
- ...environment,
21831
- OPENCODE_CONFIG_CONTENT: JSON.stringify({
21832
- ...openCodeConfiguration(environment),
21833
- permission: openCodePermission(validated)
21834
- }),
21835
- [PERMISSION_MODE_MARKER]: validated
21836
- });
21837
- };
21838
- };
21839
- var agentManagedPermissionProfile = new AgentManagedPermissionProfile();
21840
- var deepSeekHarnessPermissionProfile = new DeepSeekHarnessPermissionProfile();
21841
- var openCodePermissionProfile = new OpenCodePermissionProfile();
21842
- var piPermissionProfile = new PiPermissionProfile();
21843
- function permissionProfileForAgent(agentId) {
21844
- if (agentId === "deepseek-harness") {
21845
- return deepSeekHarnessPermissionProfile;
21846
- }
21847
- if (agentId === "opencode") {
21848
- return openCodePermissionProfile;
21849
- }
21850
- if (agentId === "pi") {
21851
- return piPermissionProfile;
21852
- }
21853
- return agentManagedPermissionProfile;
21854
- }
21855
-
21856
21688
  // src/agent-catalog/local-agent.ts
21857
21689
  function readTrustedIdentity(path2) {
21858
21690
  const resolvedPath = realpathSync(path2);
@@ -21878,8 +21710,7 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
21878
21710
  environment;
21879
21711
  id;
21880
21712
  label;
21881
- permissionProfile;
21882
- constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities(), permissionProfile = permissionProfileForAgent(id)) {
21713
+ constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities()) {
21883
21714
  this.adapterIdentity = adapterIdentity;
21884
21715
  this.adapterPath = adapterIdentity.realPath;
21885
21716
  this.adapterVersion = adapterVersion;
@@ -21888,29 +21719,22 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
21888
21719
  this.capabilities = Object.freeze({ ...capabilities });
21889
21720
  this.id = id;
21890
21721
  this.label = label;
21891
- this.permissionProfile = permissionProfile;
21892
21722
  this.command = adapterIdentity.realPath;
21893
21723
  this.arguments = Object.freeze([...arguments_]);
21894
- this.environment = permissionProfile.apply(environment, permissionProfile.currentMode(environment));
21724
+ this.environment = Object.freeze({ ...environment });
21895
21725
  }
21896
- withPermissionMode = (permissionMode) => {
21897
- if (permissionMode === AGENT_DEFAULT_PERMISSION_MODE && this.permissionProfile.currentMode(this.environment) === AGENT_DEFAULT_PERMISSION_MODE) {
21898
- return this;
21899
- }
21900
- return new _LocalAgentDefinition(
21901
- this.id,
21902
- this.label,
21903
- this.command,
21904
- this.arguments,
21905
- this.permissionProfile.apply(this.environment, permissionMode),
21906
- this.adapterVersion,
21907
- this.agentVersion,
21908
- this.adapterIdentity,
21909
- this.agentIdentity,
21910
- this.capabilities,
21911
- this.permissionProfile
21912
- );
21913
- };
21726
+ withEnvironment = (environment) => new _LocalAgentDefinition(
21727
+ this.id,
21728
+ this.label,
21729
+ this.command,
21730
+ this.arguments,
21731
+ environment,
21732
+ this.adapterVersion,
21733
+ this.agentVersion,
21734
+ this.adapterIdentity,
21735
+ this.agentIdentity,
21736
+ this.capabilities
21737
+ );
21914
21738
  };
21915
21739
  var InstallableAgentDefinition = class {
21916
21740
  id;
@@ -30177,13 +30001,14 @@ function normalizeConfigOptions(value, modes) {
30177
30001
  }
30178
30002
  const id = truncate2(readString2(option["id"]), 128);
30179
30003
  const name = truncate2(readString2(option["name"], id), 255);
30180
- if (id.length === 0 || name.length === 0) {
30004
+ const category = truncate2(readString2(option["category"]), 128);
30005
+ if (id.length === 0 || name.length === 0 || category === "_mobius_permission") {
30181
30006
  continue;
30182
30007
  }
30183
30008
  if (option["type"] === "boolean") {
30184
30009
  normalized.push({
30185
30010
  booleanValue: readBoolean(option["currentValue"]),
30186
- category: truncate2(readString2(option["category"]), 128),
30011
+ category,
30187
30012
  currentValue: "",
30188
30013
  description: truncate2(readString2(option["description"]), 500),
30189
30014
  id,
@@ -30199,7 +30024,7 @@ function normalizeConfigOptions(value, modes) {
30199
30024
  if (currentValue.length > 0 && values.some((entry) => entry.value === currentValue)) {
30200
30025
  normalized.push({
30201
30026
  booleanValue: false,
30202
- category: truncate2(readString2(option["category"]), 128),
30027
+ category,
30203
30028
  currentValue,
30204
30029
  description: truncate2(readString2(option["description"]), 500),
30205
30030
  id,
@@ -30246,122 +30071,16 @@ function normalizeConfigOptions(value, modes) {
30246
30071
  });
30247
30072
  }
30248
30073
  }
30249
- return normalized.slice(0, 100);
30250
- }
30251
- function insertRequiredOption(current, required2, afterCategory = "") {
30252
- if (current.some((option) => option.id === required2.id || option.category === required2.category)) {
30253
- return current;
30254
- }
30255
- if (current.length < MAXIMUM_CONFIG_OPTIONS) {
30256
- if (afterCategory.length === 0) {
30257
- return [required2, ...current];
30258
- }
30259
- const index3 = current.findIndex((option) => option.category === afterCategory);
30260
- if (index3 < 0) {
30261
- return [...current, required2];
30262
- }
30263
- return [...current.slice(0, index3 + 1), required2, ...current.slice(index3 + 1)];
30264
- }
30265
- if (afterCategory.length === 0) {
30266
- return [required2, ...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1)];
30267
- }
30268
- const index2 = current.findIndex((option) => option.category === afterCategory);
30269
- if (index2 < 0) {
30270
- return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 1), required2];
30271
- }
30272
- if (index2 < MAXIMUM_CONFIG_OPTIONS - 1) {
30273
- return [...current.slice(0, index2 + 1), required2, ...current.slice(index2 + 1, MAXIMUM_CONFIG_OPTIONS - 1)];
30274
- }
30275
- const anchor2 = current[index2];
30276
- if (anchor2 === void 0) {
30277
- throw new SessionConfigProtocolError("The required Agent execution setting is unavailable");
30278
- }
30279
- return [...current.slice(0, MAXIMUM_CONFIG_OPTIONS - 2), anchor2, required2];
30280
- }
30281
- function validRequiredSelect(option) {
30282
- return option.type === "select" && option.currentValue.length > 0 && option.values.some((value) => value.value === option.currentValue);
30283
- }
30284
- function ensureModelOption(current) {
30285
- const existing = current.find((option) => option.id === "model" || option.category === "model");
30286
- if (existing !== void 0 && validRequiredSelect(existing)) {
30287
- return current;
30288
- }
30289
- const unavailable = {
30290
- booleanValue: false,
30291
- category: "model",
30292
- currentValue: AGENT_DEFAULT_REASONING_EFFORT,
30293
- description: "This Agent does not expose an adjustable model.",
30294
- id: "model",
30295
- name: "Model",
30296
- type: "select",
30297
- values: [
30298
- {
30299
- description: "Selected by the Agent",
30300
- groupId: "",
30301
- groupName: "",
30302
- name: "Agent default",
30303
- value: AGENT_DEFAULT_REASONING_EFFORT
30304
- }
30305
- ]
30306
- };
30307
- return insertRequiredOption(
30308
- current.filter((option) => option.id !== "model" && option.category !== "model"),
30309
- unavailable
30310
- );
30311
- }
30312
- function ensureReasoningEffortOption(current) {
30313
- const existing = current.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
30314
- if (existing !== void 0 && validRequiredSelect(existing)) {
30315
- return current;
30316
- }
30317
- const unavailable = {
30318
- booleanValue: false,
30319
- category: "thought_level",
30320
- currentValue: AGENT_DEFAULT_REASONING_EFFORT,
30321
- description: "This Agent does not expose adjustable reasoning effort for the selected model.",
30322
- id: "reasoning_effort",
30323
- name: "Reasoning effort",
30324
- type: "select",
30325
- values: [
30326
- {
30327
- description: "Selected by the Agent",
30328
- groupId: "",
30329
- groupName: "",
30330
- name: "Agent default",
30331
- value: AGENT_DEFAULT_REASONING_EFFORT
30332
- }
30333
- ]
30334
- };
30335
- return insertRequiredOption(
30336
- current.filter((option) => option.id !== "reasoning_effort" && option.category !== "thought_level"),
30337
- unavailable,
30338
- "model"
30339
- );
30340
- }
30341
- function ensureRequiredExecutionOptions(current, permission) {
30342
- const normalized = ensureReasoningEffortOption(ensureModelOption(current));
30343
- const model = normalized.find(
30344
- (option) => (option.id === "model" || option.category === "model") && validRequiredSelect(option)
30345
- );
30346
- const reasoningEffort = normalized.find(
30347
- (option) => (option.id === "reasoning_effort" || option.category === "thought_level") && validRequiredSelect(option)
30348
- );
30349
- if (model === void 0 || reasoningEffort === void 0) {
30350
- throw new SessionConfigProtocolError("The required Agent execution settings are unavailable");
30351
- }
30352
- const optional2 = normalized.filter(
30353
- (option) => option.id !== permission.id && option.category !== permission.category && option.id !== "model" && option.category !== "model" && option.id !== "reasoning_effort" && option.category !== "thought_level"
30354
- );
30355
- return [permission, model, reasoningEffort, ...optional2].slice(0, MAXIMUM_CONFIG_OPTIONS);
30074
+ return normalized.slice(0, MAXIMUM_CONFIG_OPTIONS);
30356
30075
  }
30357
30076
  function normalizeStandardLifecycle(response) {
30358
30077
  const lifecycle = isRecord4(response) ? response : {};
30359
- return ensureReasoningEffortOption(normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]));
30078
+ return normalizeConfigOptions(lifecycle["configOptions"], lifecycle["modes"]);
30360
30079
  }
30361
30080
  function replaceStandardConfigOptions(current, value) {
30362
30081
  const next = normalizeConfigOptions(value, void 0);
30363
- const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, 100);
30364
- return ensureReasoningEffortOption(withMode);
30082
+ const withMode = next.some((option) => option.category === "mode") ? next : [...current.filter((option) => option.category === "mode"), ...next].slice(0, MAXIMUM_CONFIG_OPTIONS);
30083
+ return withMode;
30365
30084
  }
30366
30085
  function updateCurrentValue(current, configId, value) {
30367
30086
  return current.map((option) => option.id === configId ? { ...option, currentValue: value } : option);
@@ -30547,7 +30266,7 @@ function normalizeGrokLifecycle(response) {
30547
30266
  normalized.splice(modelIndex < 0 ? normalized.length : modelIndex + 1, 0, ...efforts);
30548
30267
  }
30549
30268
  }
30550
- return ensureReasoningEffortOption(normalized.slice(0, 100));
30269
+ return normalized.slice(0, 100);
30551
30270
  }
30552
30271
  function updateCurrentValue2(current, category, value) {
30553
30272
  return current.map((option) => option.category === category ? { ...option, currentValue: value } : option);
@@ -31428,7 +31147,6 @@ var AcpProcessSession = class _AcpProcessSession {
31428
31147
  #preSessionUpdates = [];
31429
31148
  #processExit;
31430
31149
  #metrics;
31431
- #permissionProfile;
31432
31150
  #sessionConfigProtocol;
31433
31151
  #store;
31434
31152
  #emittedToolImages = /* @__PURE__ */ new Set();
@@ -31472,7 +31190,6 @@ var AcpProcessSession = class _AcpProcessSession {
31472
31190
  this.#getObserver = getObserver;
31473
31191
  this.#mobiusSessionId = mobiusSessionId;
31474
31192
  this.#metrics = metrics;
31475
- this.#permissionProfile = agent.permissionProfile;
31476
31193
  this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
31477
31194
  this.#store = store;
31478
31195
  this.#verifiedAgentVersion = agent.agentVersion;
@@ -31579,6 +31296,7 @@ var AcpProcessSession = class _AcpProcessSession {
31579
31296
  belongsTo = (agentId, cwd, additionalDirectories) => this.#agentId === agentId && this.#cwd === cwd && arraysEqual(this.#additionalDirectories, additionalDirectories);
31580
31297
  usesEnvironment = (environment) => recordsEqual(this.#environment, environment);
31581
31298
  canRebind = () => !this.#prompted && !this.#turn.running;
31299
+ hasRunningTurn = () => this.#turn.running;
31582
31300
  prepared = () => new AcpPreparedSession(
31583
31301
  this.#agentName,
31584
31302
  this.#agentVersion,
@@ -31942,10 +31660,7 @@ var AcpProcessSession = class _AcpProcessSession {
31942
31660
  this.selectNativeSession(created.sessionId);
31943
31661
  lifecycleResponse = created;
31944
31662
  }
31945
- this.#configOptions = ensureRequiredExecutionOptions(
31946
- this.#sessionConfigProtocol.normalizeLifecycle(lifecycleResponse),
31947
- this.#permissionProfile.option(this.#environment)
31948
- );
31663
+ this.#configOptions = this.#sessionConfigProtocol.normalizeLifecycle(lifecycleResponse);
31949
31664
  await this.#updateTail;
31950
31665
  signal.throwIfAborted();
31951
31666
  if (this.#prompted) {
@@ -32046,12 +31761,17 @@ var AcpProcessSession = class _AcpProcessSession {
32046
31761
  )
32047
31762
  }
32048
31763
  );
31764
+ const applied = configured.find((option) => option.id === options.configId);
31765
+ if (applied === void 0 || applied.type !== options.valueType || applied.type === "boolean" && applied.booleanValue !== options.booleanValue || applied.type === "select" && applied.currentValue !== options.value) {
31766
+ throw new AcpExecutionError(
31767
+ "The Agent did not apply the requested session configuration",
31768
+ {},
31769
+ "invalid_session_configuration"
31770
+ );
31771
+ }
32049
31772
  await this.#updateTail;
32050
31773
  if (this.#configRevision === configRevision) {
32051
- this.#configOptions = ensureRequiredExecutionOptions(
32052
- configured,
32053
- this.#permissionProfile.option(this.#environment)
32054
- );
31774
+ this.#configOptions = configured;
32055
31775
  }
32056
31776
  } catch (error62) {
32057
31777
  if (error62 instanceof SessionConfigProtocolError) {
@@ -32529,9 +32249,9 @@ var AcpProcessSession = class _AcpProcessSession {
32529
32249
  return;
32530
32250
  }
32531
32251
  if (update.sessionUpdate === "config_option_update") {
32532
- this.#configOptions = ensureRequiredExecutionOptions(
32533
- this.#sessionConfigProtocol.normalizeUpdate(this.#configOptions, update.configOptions),
32534
- this.#permissionProfile.option(this.#environment)
32252
+ this.#configOptions = this.#sessionConfigProtocol.normalizeUpdate(
32253
+ this.#configOptions,
32254
+ update.configOptions
32535
32255
  );
32536
32256
  this.#configRevision += 1;
32537
32257
  await this.emitConfigUpdate();
@@ -33062,16 +32782,12 @@ var AcpSessionManager = class {
33062
32782
  const operation = (async () => {
33063
32783
  try {
33064
32784
  await this.#retireSessionProcess(options.sessionId, existing, async () => await existing.close());
33065
- this.#store.remove(options.sessionId);
33066
32785
  const runtime = await this.#startRetainedSessionProcess(
33067
32786
  options,
33068
32787
  async () => await AcpProcessSession.start(options, () => this.#observer, this.#store)
33069
32788
  );
33070
32789
  try {
33071
32790
  for (const desired of desiredConfigOptions) {
33072
- if (desired.id === PERMISSION_MODE_CONFIG_ID) {
33073
- continue;
33074
- }
33075
32791
  const current = runtime.prepared().configOptions.find((option) => option.id === desired.id);
33076
32792
  if (current === void 0 || current.type !== desired.type) {
33077
32793
  continue;
@@ -33102,7 +32818,6 @@ var AcpSessionManager = class {
33102
32818
  }
33103
32819
  } catch (error62) {
33104
32820
  await this.#retireSessionProcess(options.sessionId, runtime, async () => await runtime.close());
33105
- this.#store.remove(options.sessionId);
33106
32821
  throw error62;
33107
32822
  }
33108
32823
  return runtime;
@@ -33169,11 +32884,21 @@ var AcpSessionManager = class {
33169
32884
  () => this.#agentSettingsObserver,
33170
32885
  new MemoryAcpSessionStore()
33171
32886
  ),
33172
- (runtime) => {
32887
+ async (runtime) => {
33173
32888
  const prepared = runtime.prepared();
33174
- return Promise.resolve(
33175
- new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, prepared.configOptions)
33176
- );
32889
+ const model = options.model;
32890
+ const configOptions = model === void 0 ? prepared.configOptions : await runtime.configure({
32891
+ ...options,
32892
+ booleanValue: false,
32893
+ configId: prepared.configOptions.find(
32894
+ (option) => option.id === "model" || option.category === "model"
32895
+ )?.id ?? "model",
32896
+ requestId: "agent-settings-model",
32897
+ sessionId: `agent-settings-${crypto.randomUUID()}`,
32898
+ value: model,
32899
+ valueType: "select"
32900
+ });
32901
+ return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, configOptions);
33177
32902
  },
33178
32903
  async (runtime) => await runtime.close()
33179
32904
  );
@@ -33222,11 +32947,11 @@ var AcpSessionManager = class {
33222
32947
  this.#touchExpectedSession(options.sessionId, existing);
33223
32948
  return existing.prepared();
33224
32949
  }
33225
- if (!existing.canRebind()) {
32950
+ if (existing.hasRunningTurn()) {
33226
32951
  throw new AcpExecutionError(
33227
- "The execution environment cannot change after a conversation has started",
32952
+ "The execution environment cannot change while a conversation turn is running",
33228
32953
  {},
33229
- "session_identity_mismatch"
32954
+ "session_busy"
33230
32955
  );
33231
32956
  }
33232
32957
  return (await this.#replaceExecutionPreparation(existing, options)).prepared();
@@ -33264,30 +32989,6 @@ var AcpSessionManager = class {
33264
32989
  this.#beginSessionUse(options.sessionId);
33265
32990
  try {
33266
32991
  const runtime = await this.ensureSession(options);
33267
- if (options.configId === PERMISSION_MODE_CONFIG_ID) {
33268
- const permission = runtime.prepared().configOptions.find((candidate) => candidate.id === PERMISSION_MODE_CONFIG_ID);
33269
- if (permission === void 0 || permission.type !== "select" || options.valueType !== "select" || permission.values.length < 2 || !permission.values.some((value) => value.value === options.value)) {
33270
- throw new AcpExecutionError(
33271
- "The requested Agent permission mode is unavailable",
33272
- {},
33273
- "invalid_session_configuration"
33274
- );
33275
- }
33276
- if (permission.currentValue === options.value) {
33277
- return runtime.prepared().configOptions;
33278
- }
33279
- try {
33280
- return (await this.prepareExecutionSession({
33281
- ...options,
33282
- agent: options.agent.withPermissionMode(options.value)
33283
- })).configOptions;
33284
- } catch (error62) {
33285
- if (error62 instanceof AgentPermissionConfigurationError) {
33286
- throw new AcpExecutionError(error62.message, { cause: error62 }, error62.code);
33287
- }
33288
- throw error62;
33289
- }
33290
- }
33291
32992
  return await runtime.configure(options);
33292
32993
  } finally {
33293
32994
  this.#endSessionUse(options.sessionId);
@@ -33765,7 +33466,7 @@ var AuditStore = class {
33765
33466
  this.database.exec("ALTER TABLE audit_events ADD COLUMN details_json TEXT NOT NULL DEFAULT '{}'");
33766
33467
  }
33767
33468
  }
33768
- record(record4) {
33469
+ record(record3) {
33769
33470
  this.database.prepare(
33770
33471
  `
33771
33472
  INSERT INTO audit_events (
@@ -33778,10 +33479,10 @@ var AuditStore = class {
33778
33479
  `
33779
33480
  ).run(
33780
33481
  (/* @__PURE__ */ new Date()).toISOString(),
33781
- record4.event,
33782
- record4.commandId,
33783
- record4.sessionId,
33784
- JSON.stringify(record4.details ?? {})
33482
+ record3.event,
33483
+ record3.commandId,
33484
+ record3.sessionId,
33485
+ JSON.stringify(record3.details ?? {})
33785
33486
  );
33786
33487
  }
33787
33488
  close() {
@@ -36669,11 +36370,216 @@ async function resumeLocalMachine(arguments_, signal = new AbortController().sig
36669
36370
  }
36670
36371
 
36671
36372
  // src/run-daemon.ts
36672
- import { randomUUID as randomUUID4 } from "node:crypto";
36373
+ import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
36673
36374
  import { basename as basename7 } from "node:path";
36674
36375
  import { styleText } from "node:util";
36675
36376
  import { fetch as fetch6, WebSocket as WebSocket2 } from "undici";
36676
36377
 
36378
+ // src/agent-catalog/agent-settings-adapter.ts
36379
+ var AGENT_DEFAULT_VALUE = "agent_default";
36380
+ var READ_ONLY_VALUE = "read-only";
36381
+ var WORKSPACE_WRITE_VALUE = "workspace-write";
36382
+ var DANGER_FULL_ACCESS_VALUE = "danger-full-access";
36383
+ var DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID = "dsh_access_mode";
36384
+ var OPENCODE_PERMISSION_SETTING_ID = "opencode_permission";
36385
+ var AgentSettingsConfigurationError = class extends Error {
36386
+ code = "invalid_session_configuration";
36387
+ constructor(message, options = {}) {
36388
+ super(message, options);
36389
+ this.name = "AgentSettingsConfigurationError";
36390
+ }
36391
+ };
36392
+ var AgentSettingsLaunchSelectionResult = class {
36393
+ agent;
36394
+ handled;
36395
+ constructor(agent, handled) {
36396
+ this.agent = agent;
36397
+ this.handled = handled;
36398
+ }
36399
+ };
36400
+ var AppliedAgentLaunchSettings = class {
36401
+ agent;
36402
+ sessionConfigurations;
36403
+ constructor(agent, sessionConfigurations) {
36404
+ this.agent = agent;
36405
+ this.sessionConfigurations = Object.freeze([...sessionConfigurations]);
36406
+ }
36407
+ };
36408
+ var AgentSettingsAdapter = class {
36409
+ modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION;
36410
+ applyLaunchSelection = (agent, _selection) => new AgentSettingsLaunchSelectionResult(agent, false);
36411
+ settings = (_agent) => [];
36412
+ };
36413
+ function selectValue(name, value, description) {
36414
+ return {
36415
+ description,
36416
+ groupId: "",
36417
+ groupName: "",
36418
+ name,
36419
+ value
36420
+ };
36421
+ }
36422
+ function selectSetting(id, name, description, currentValue, values) {
36423
+ return {
36424
+ booleanValue: false,
36425
+ category: "execution",
36426
+ currentValue,
36427
+ description,
36428
+ id,
36429
+ name,
36430
+ type: "select",
36431
+ values
36432
+ };
36433
+ }
36434
+ function selectedValue(selection, configId) {
36435
+ if (selection.configId !== configId || selection.valueType !== "select" || selection.booleanValue || selection.value.length === 0) {
36436
+ throw new AgentSettingsConfigurationError("The requested Agent setting is invalid");
36437
+ }
36438
+ return selection.value;
36439
+ }
36440
+ function validValue(values, value) {
36441
+ if (!values.some((candidate) => candidate.value === value)) {
36442
+ throw new AgentSettingsConfigurationError("The requested Agent setting is unavailable");
36443
+ }
36444
+ return value;
36445
+ }
36446
+ var dshAccessModes = Object.freeze([
36447
+ selectValue("Read only", READ_ONLY_VALUE, "Allow inspection without local writes."),
36448
+ selectValue("Workspace write", WORKSPACE_WRITE_VALUE, "Allow changes in the selected workspace."),
36449
+ selectValue("Full access", DANGER_FULL_ACCESS_VALUE, "Allow unrestricted local execution.")
36450
+ ]);
36451
+ var DeepSeekHarnessSettingsAdapter = class extends AgentSettingsAdapter {
36452
+ settings = (agent) => {
36453
+ const configured = agent.environment["DSH_PERMISSION_MODE"] ?? WORKSPACE_WRITE_VALUE;
36454
+ return [
36455
+ selectSetting(
36456
+ DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID,
36457
+ "Access mode",
36458
+ "Controls the local side effects allowed for this DeepSeek Harness session.",
36459
+ validValue(dshAccessModes, configured),
36460
+ dshAccessModes
36461
+ )
36462
+ ];
36463
+ };
36464
+ applyLaunchSelection = (agent, selection) => {
36465
+ if (selection.configId !== DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID) {
36466
+ return new AgentSettingsLaunchSelectionResult(agent, false);
36467
+ }
36468
+ const value = validValue(dshAccessModes, selectedValue(selection, DEEPSEEK_HARNESS_ACCESS_MODE_SETTING_ID));
36469
+ return new AgentSettingsLaunchSelectionResult(
36470
+ agent.withEnvironment({ ...agent.environment, DSH_PERMISSION_MODE: value }),
36471
+ true
36472
+ );
36473
+ };
36474
+ };
36475
+ var openCodePermissionModes = Object.freeze([
36476
+ selectValue("Agent default", AGENT_DEFAULT_VALUE, "Keep OpenCode's existing permission policy."),
36477
+ selectValue("Read only", READ_ONLY_VALUE, "Allow inspection without local writes."),
36478
+ selectValue("Workspace write", WORKSPACE_WRITE_VALUE, "Allow changes in the selected workspace."),
36479
+ selectValue("Full access", DANGER_FULL_ACCESS_VALUE, "Allow unrestricted local execution.")
36480
+ ]);
36481
+ function openCodeConfiguration(environment) {
36482
+ const encoded = environment["OPENCODE_CONFIG_CONTENT"];
36483
+ if (encoded === void 0 || encoded.length === 0) {
36484
+ return {};
36485
+ }
36486
+ let parsed;
36487
+ try {
36488
+ parsed = JSON.parse(encoded);
36489
+ } catch (cause) {
36490
+ throw new AgentSettingsConfigurationError("The OpenCode configuration is invalid", { cause });
36491
+ }
36492
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
36493
+ throw new AgentSettingsConfigurationError("The OpenCode configuration is invalid");
36494
+ }
36495
+ return Object.freeze({ ...parsed });
36496
+ }
36497
+ function openCodePermission(value) {
36498
+ if (value === READ_ONLY_VALUE) {
36499
+ return {
36500
+ "*": "deny",
36501
+ glob: "allow",
36502
+ grep: "allow",
36503
+ lsp: "allow",
36504
+ read: "allow",
36505
+ skill: "allow"
36506
+ };
36507
+ }
36508
+ if (value === WORKSPACE_WRITE_VALUE) {
36509
+ return {
36510
+ "*": "allow",
36511
+ external_directory: "ask"
36512
+ };
36513
+ }
36514
+ return "allow";
36515
+ }
36516
+ var OpenCodeSettingsAdapter = class extends AgentSettingsAdapter {
36517
+ settings = (agent) => {
36518
+ const currentValue = agent.environment["MOBIUS_OPENCODE_PERMISSION"] ?? AGENT_DEFAULT_VALUE;
36519
+ return [
36520
+ selectSetting(
36521
+ OPENCODE_PERMISSION_SETTING_ID,
36522
+ "Permissions",
36523
+ "Controls OpenCode's local permission policy.",
36524
+ validValue(openCodePermissionModes, currentValue),
36525
+ openCodePermissionModes
36526
+ )
36527
+ ];
36528
+ };
36529
+ applyLaunchSelection = (agent, selection) => {
36530
+ if (selection.configId !== OPENCODE_PERMISSION_SETTING_ID) {
36531
+ return new AgentSettingsLaunchSelectionResult(agent, false);
36532
+ }
36533
+ const value = validValue(openCodePermissionModes, selectedValue(selection, OPENCODE_PERMISSION_SETTING_ID));
36534
+ if (value === AGENT_DEFAULT_VALUE) {
36535
+ return new AgentSettingsLaunchSelectionResult(agent, true);
36536
+ }
36537
+ return new AgentSettingsLaunchSelectionResult(
36538
+ agent.withEnvironment({
36539
+ ...agent.environment,
36540
+ MOBIUS_OPENCODE_PERMISSION: value,
36541
+ OPENCODE_CONFIG_CONTENT: JSON.stringify({
36542
+ ...openCodeConfiguration(agent.environment),
36543
+ permission: openCodePermission(value)
36544
+ })
36545
+ }),
36546
+ true
36547
+ );
36548
+ };
36549
+ };
36550
+ var CodexSettingsAdapter = class extends AgentSettingsAdapter {
36551
+ modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE;
36552
+ };
36553
+ var genericAdapter = new AgentSettingsAdapter();
36554
+ var codexAdapter = new CodexSettingsAdapter();
36555
+ var deepSeekHarnessAdapter = new DeepSeekHarnessSettingsAdapter();
36556
+ var openCodeAdapter = new OpenCodeSettingsAdapter();
36557
+ function agentSettingsAdapterForAgent(agentId) {
36558
+ if (agentId === "codex") {
36559
+ return codexAdapter;
36560
+ }
36561
+ if (agentId === "deepseek-harness") {
36562
+ return deepSeekHarnessAdapter;
36563
+ }
36564
+ if (agentId === "opencode") {
36565
+ return openCodeAdapter;
36566
+ }
36567
+ return genericAdapter;
36568
+ }
36569
+ function applyAgentLaunchSettings(agent, selections) {
36570
+ const adapter = agentSettingsAdapterForAgent(agent.id);
36571
+ let selectedAgent = agent;
36572
+ const sessionConfigurations = [];
36573
+ for (const selection of selections) {
36574
+ const applied = adapter.applyLaunchSelection(selectedAgent, selection);
36575
+ selectedAgent = applied.agent;
36576
+ if (!applied.handled) {
36577
+ sessionConfigurations.push(selection);
36578
+ }
36579
+ }
36580
+ return new AppliedAgentLaunchSettings(selectedAgent, sessionConfigurations);
36581
+ }
36582
+
36677
36583
  // src/agent-catalog/publish-agent-catalog.ts
36678
36584
  import { fetch as fetch3 } from "undici";
36679
36585
 
@@ -37331,7 +37237,7 @@ function invalidResponse(message) {
37331
37237
  function isRecord10(value) {
37332
37238
  return typeof value === "object" && value !== null && !Array.isArray(value);
37333
37239
  }
37334
- function record3(value, name) {
37240
+ function record2(value, name) {
37335
37241
  if (!isRecord10(value)) {
37336
37242
  throw invalidResponse(`The service returned an invalid ${name}`);
37337
37243
  }
@@ -37466,11 +37372,11 @@ function uploadingArtifact(value) {
37466
37372
  );
37467
37373
  }
37468
37374
  function decodeMobiusArtifactUpload(value) {
37469
- const artifact = record3(value, "artifact upload authorization");
37375
+ const artifact = record2(value, "artifact upload authorization");
37470
37376
  return new MobiusArtifactUpload(uploadingArtifact(artifact), stringField(artifact, "uploadToken", 256));
37471
37377
  }
37472
37378
  function decodeMobiusArtifact(value) {
37473
- const artifact = record3(value, "artifact");
37379
+ const artifact = record2(value, "artifact");
37474
37380
  const state = stringField(artifact, "state", 32);
37475
37381
  if (state === "uploading") {
37476
37382
  return uploadingArtifact(artifact);
@@ -39657,9 +39563,9 @@ var ACTIVE_TURN_RECONCILIATION_CLOSE_CODE = 4009;
39657
39563
  var DaemonAcpObserver = class {
39658
39564
  #config;
39659
39565
  #record;
39660
- constructor(config2, record4) {
39566
+ constructor(config2, record3) {
39661
39567
  this.#config = config2;
39662
- this.#record = record4;
39568
+ this.#record = record3;
39663
39569
  }
39664
39570
  importLocalArtifact = async (sessionId, artifact, signal) => (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39665
39571
  onCommands = (event) => {
@@ -40230,30 +40136,139 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
40230
40136
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
40231
40137
  }
40232
40138
  async function discoverAgentSettings(command, config2, directories, sessions, signal) {
40233
- const resolved = await resolveSessionDirectories(
40234
- directories,
40235
- config2.bindingId,
40236
- command.directoryId,
40237
- command.additionalDirectoryIds,
40238
- signal
40239
- );
40240
40139
  const agent = config2.catalog.find(command.agentId);
40140
+ const cwd = await directories.resolve(config2.bindingId, "default", signal);
40241
40141
  const snapshot = await sessions.inspectAgentSettings({
40242
- additionalDirectories: resolved.additionalDirectories,
40142
+ additionalDirectories: [],
40243
40143
  agent,
40244
- cwd: resolved.cwd,
40144
+ cwd,
40245
40145
  signal
40246
40146
  });
40147
+ const adapter = agentSettingsAdapterForAgent(agent.id);
40148
+ const settings = settingsFromSnapshot(agent, snapshot.configOptions);
40149
+ const modelEffort = await discoverModelEffort(
40150
+ command,
40151
+ agent,
40152
+ adapter.modelEffortResolution,
40153
+ snapshot.configOptions,
40154
+ cwd,
40155
+ sessions,
40156
+ signal
40157
+ );
40247
40158
  return {
40248
40159
  agentId: command.agentId,
40249
40160
  agentName: snapshot.agentName,
40250
40161
  agentVersion: snapshot.agentVersion,
40251
- configOptions: snapshot.configOptions,
40252
- directoryId: command.directoryId,
40253
40162
  kind: AGENT_SETTINGS_DISCOVERED_KIND,
40254
- requestId: command.requestId
40163
+ modelEffort,
40164
+ requestId: command.requestId,
40165
+ settings,
40166
+ settingsRevision: settingsRevision(agent, snapshot.agentVersion, settings, modelEffort)
40255
40167
  };
40256
40168
  }
40169
+ function settingFromOption(option) {
40170
+ return {
40171
+ booleanValue: option.booleanValue,
40172
+ category: option.category,
40173
+ defaultValue: option.type === "boolean" ? "" : option.currentValue,
40174
+ description: option.description,
40175
+ id: option.id,
40176
+ name: option.name,
40177
+ type: option.type,
40178
+ values: option.values
40179
+ };
40180
+ }
40181
+ function settingsFromSnapshot(agent, configOptions) {
40182
+ const settings = [
40183
+ ...agentSettingsAdapterForAgent(agent.id).settings(agent).map(settingFromOption),
40184
+ ...configOptions.map(settingFromOption)
40185
+ ];
40186
+ const identifiers = /* @__PURE__ */ new Set();
40187
+ for (const setting of settings) {
40188
+ if (identifiers.has(setting.id)) {
40189
+ throw new AcpExecutionError(
40190
+ "The Agent returned duplicate setting identifiers",
40191
+ {},
40192
+ "invalid_session_configuration"
40193
+ );
40194
+ }
40195
+ identifiers.add(setting.id);
40196
+ }
40197
+ if (settings.length > 128) {
40198
+ throw new AcpExecutionError("The Agent returned too many settings", {}, "invalid_session_configuration");
40199
+ }
40200
+ return settings;
40201
+ }
40202
+ function modelOption(options) {
40203
+ return options.find((option) => option.id === "model" || option.category === "model");
40204
+ }
40205
+ function effortOption(options) {
40206
+ return options.find((option) => option.id === "reasoning_effort" || option.category === "thought_level");
40207
+ }
40208
+ function unavailableModelEffort() {
40209
+ return {
40210
+ effortSettingId: "",
40211
+ modelSettingId: "",
40212
+ resolution: AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE,
40213
+ valuesByModel: {}
40214
+ };
40215
+ }
40216
+ async function discoverModelEffort(command, agent, resolution, initialOptions, cwd, sessions, signal) {
40217
+ const model = modelOption(initialOptions);
40218
+ const effort = effortOption(initialOptions);
40219
+ if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
40220
+ return unavailableModelEffort();
40221
+ }
40222
+ if (model === void 0 || model.type !== "select" || model.values.length === 0 || effort === void 0 || effort.type !== "select" || effort.values.length < 2) {
40223
+ return unavailableModelEffort();
40224
+ }
40225
+ const inspectModel = async (modelValue) => (await sessions.inspectAgentSettings({
40226
+ additionalDirectories: [],
40227
+ agent,
40228
+ cwd,
40229
+ model: modelValue,
40230
+ signal
40231
+ })).configOptions;
40232
+ const valuesByModel = {};
40233
+ if (resolution === "complete") {
40234
+ for (const value of model.values) {
40235
+ const selectedEffort = effortOption(await inspectModel(value.value));
40236
+ valuesByModel[value.value] = selectedEffort?.type === "select" ? selectedEffort.values : [];
40237
+ }
40238
+ return {
40239
+ effortSettingId: effort.id,
40240
+ modelSettingId: model.id,
40241
+ resolution: "complete",
40242
+ valuesByModel
40243
+ };
40244
+ }
40245
+ if (command.model !== void 0) {
40246
+ if (!model.values.some((value) => value.value === command.model)) {
40247
+ throw new AcpExecutionError("The selected Agent model is unavailable", {}, "invalid_session_configuration");
40248
+ }
40249
+ const selectedEffort = effortOption(await inspectModel(command.model));
40250
+ valuesByModel[command.model] = selectedEffort?.type === "select" ? selectedEffort.values : [];
40251
+ }
40252
+ return {
40253
+ effortSettingId: effort.id,
40254
+ modelSettingId: model.id,
40255
+ resolution: "on_model_selection",
40256
+ valuesByModel
40257
+ };
40258
+ }
40259
+ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
40260
+ const revisionModelEffort = modelEffort.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE ? modelEffort : { ...modelEffort, valuesByModel: {} };
40261
+ return createHash5("sha256").update(
40262
+ JSON.stringify({
40263
+ adapterVersion: agent.adapterVersion,
40264
+ agentId: agent.id,
40265
+ agentVersion: agent.agentVersion,
40266
+ modelEffort: revisionModelEffort,
40267
+ reportedAgentVersion,
40268
+ settings
40269
+ })
40270
+ ).digest("hex");
40271
+ }
40257
40272
  async function executeWorkspaceList(socket, command, directories, audit, signal) {
40258
40273
  try {
40259
40274
  const listing = await directories.list(command.bindingId, command.directoryId, signal);
@@ -40441,23 +40456,26 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40441
40456
  "prompt_queue_target_unavailable"
40442
40457
  );
40443
40458
  }
40459
+ const appliedSettings = command.sessionConfigurations === void 0 ? void 0 : agentForSessionConfiguration(agent, command.sessionConfigurations);
40460
+ const executionAgent = appliedSettings?.agent ?? agent;
40461
+ const sessionConfigurations = appliedSettings?.sessionConfigurations;
40444
40462
  if (command.sessionConfigurations !== void 0) {
40445
40463
  const prepared = await sessions.prepareExecutionSession({
40446
40464
  additionalDirectories: resolved.additionalDirectories,
40447
- agent,
40465
+ agent: executionAgent,
40448
40466
  cwd: resolved.cwd,
40449
40467
  sessionId: command.sessionId,
40450
40468
  signal
40451
40469
  });
40452
40470
  if (command.disposition === SessionPromptDisposition.Steer) {
40453
- assertCompleteSessionConfiguration(prepared.configOptions, command.sessionConfigurations);
40471
+ assertCompleteSessionConfiguration(prepared.configOptions, sessionConfigurations ?? []);
40454
40472
  } else {
40455
40473
  await applyCompleteSessionConfiguration(
40456
40474
  sessions,
40457
40475
  audit,
40458
40476
  prepared.configOptions,
40459
- command.sessionConfigurations,
40460
- agent,
40477
+ sessionConfigurations ?? [],
40478
+ executionAgent,
40461
40479
  resolved.cwd,
40462
40480
  resolved.additionalDirectories,
40463
40481
  command.commandId,
@@ -40488,7 +40506,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40488
40506
  if (command.disposition === SessionPromptDisposition.Steer) {
40489
40507
  await sessions.steerPrompt({
40490
40508
  additionalDirectories: resolved.additionalDirectories,
40491
- agent,
40509
+ agent: executionAgent,
40492
40510
  commandId: command.commandId,
40493
40511
  cwd: resolved.cwd,
40494
40512
  images: attachments.images,
@@ -40502,7 +40520,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40502
40520
  } else {
40503
40521
  const result = await sessions.runPrompt({
40504
40522
  additionalDirectories: resolved.additionalDirectories,
40505
- agent,
40523
+ agent: executionAgent,
40506
40524
  commandId: command.commandId,
40507
40525
  cwd: resolved.cwd,
40508
40526
  disposition: command.disposition,
@@ -40569,6 +40587,16 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
40569
40587
  function invalidSessionConfiguration(message) {
40570
40588
  return new AcpExecutionError(message, {}, "invalid_session_configuration");
40571
40589
  }
40590
+ function agentForSessionConfiguration(agent, selections) {
40591
+ try {
40592
+ return applyAgentLaunchSettings(agent, selections);
40593
+ } catch (error62) {
40594
+ if (error62 instanceof Error) {
40595
+ throw invalidSessionConfiguration(error62.message);
40596
+ }
40597
+ throw error62;
40598
+ }
40599
+ }
40572
40600
  function validateSessionConfigurationSelection(option, selection) {
40573
40601
  if (option.type !== selection.valueType) {
40574
40602
  throw invalidSessionConfiguration(`The Agent setting ${selection.configId} changed type`);
@@ -40626,20 +40654,17 @@ function sessionConfigurationMatches(option, selection) {
40626
40654
  return option.type === "boolean" ? option.booleanValue === selection.booleanValue : option.currentValue === selection.value;
40627
40655
  }
40628
40656
  function sessionConfigurationPriority(selection, options) {
40629
- if (selection.configId === "permission_mode") {
40630
- return 0;
40631
- }
40632
40657
  const option = options.find((candidate) => candidate.id === selection.configId);
40633
40658
  if (selection.configId === "model" || option?.category === "model") {
40634
- return 1;
40659
+ return 0;
40635
40660
  }
40636
40661
  if (selection.configId === "reasoning_effort" || option?.category === "thought_level") {
40637
- return 2;
40662
+ return 1;
40638
40663
  }
40639
40664
  if (option?.category === "model_config") {
40640
- return 3;
40665
+ return 2;
40641
40666
  }
40642
- return 4;
40667
+ return 3;
40643
40668
  }
40644
40669
  function assertCompleteSessionConfiguration(options, selections) {
40645
40670
  assertSessionConfigurationSchema(options, selections);
@@ -40655,12 +40680,6 @@ function assertAppliedSessionConfiguration(options, selections) {
40655
40680
  const selectionsById = new Map(selections.map((selection) => [selection.configId, selection]));
40656
40681
  for (const option of options) {
40657
40682
  const selection = selectionsById.get(option.id);
40658
- if (option.id === AGENT_PERMISSION_MODE_CONFIG_ID) {
40659
- if (selection === void 0 || !sessionConfigurationMatches(option, selection)) {
40660
- throw invalidSessionConfiguration(`The Turn configuration does not match Agent setting ${option.id}`);
40661
- }
40662
- continue;
40663
- }
40664
40683
  if (selection === void 0 || !sessionConfigurationSelectionIsAvailable(option, selection)) {
40665
40684
  continue;
40666
40685
  }
@@ -40681,61 +40700,56 @@ function unavailableSessionConfigurationCategory(selection) {
40681
40700
  async function applySessionConfigurationSelection(sessions, audit, options, selection, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40682
40701
  const option = options.find((candidate) => candidate.id === selection.configId);
40683
40702
  if (option === void 0) {
40684
- if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
40685
- warnIgnoredSetting(
40686
- audit,
40687
- "session_configuration_setting_ignored",
40688
- commandId,
40689
- sessionId,
40690
- agent.id,
40691
- selection,
40692
- unavailableSessionConfigurationCategory(selection),
40693
- "setting_unavailable"
40694
- );
40695
- return options;
40696
- }
40697
- throw invalidSessionConfiguration(`The Agent setting ${selection.configId} is unavailable`);
40703
+ warnIgnoredSetting(
40704
+ audit,
40705
+ "session_configuration_setting_ignored",
40706
+ commandId,
40707
+ sessionId,
40708
+ agent.id,
40709
+ selection,
40710
+ unavailableSessionConfigurationCategory(selection),
40711
+ "setting_unavailable"
40712
+ );
40713
+ return options;
40698
40714
  }
40699
- if (selection.configId !== AGENT_PERMISSION_MODE_CONFIG_ID) {
40700
- if (option.type !== selection.valueType) {
40701
- warnIgnoredSetting(
40702
- audit,
40703
- "session_configuration_setting_ignored",
40704
- commandId,
40705
- sessionId,
40706
- agent.id,
40707
- selection,
40708
- option.category,
40709
- "setting_schema_mismatch"
40710
- );
40711
- return options;
40712
- }
40713
- if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
40714
- warnIgnoredSetting(
40715
- audit,
40716
- "session_configuration_setting_ignored",
40717
- commandId,
40718
- sessionId,
40719
- agent.id,
40720
- selection,
40721
- option.category,
40722
- "selection_schema_mismatch"
40723
- );
40724
- return options;
40725
- }
40726
- if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
40727
- warnIgnoredSetting(
40728
- audit,
40729
- "session_configuration_setting_ignored",
40730
- commandId,
40731
- sessionId,
40732
- agent.id,
40733
- selection,
40734
- option.category,
40735
- "value_unavailable"
40736
- );
40737
- return options;
40738
- }
40715
+ if (option.type !== selection.valueType) {
40716
+ warnIgnoredSetting(
40717
+ audit,
40718
+ "session_configuration_setting_ignored",
40719
+ commandId,
40720
+ sessionId,
40721
+ agent.id,
40722
+ selection,
40723
+ option.category,
40724
+ "setting_schema_mismatch"
40725
+ );
40726
+ return options;
40727
+ }
40728
+ if (option.type === "boolean" && selection.value.length > 0 || option.type === "select" && selection.booleanValue) {
40729
+ warnIgnoredSetting(
40730
+ audit,
40731
+ "session_configuration_setting_ignored",
40732
+ commandId,
40733
+ sessionId,
40734
+ agent.id,
40735
+ selection,
40736
+ option.category,
40737
+ "selection_schema_mismatch"
40738
+ );
40739
+ return options;
40740
+ }
40741
+ if (option.type === "select" && !option.values.some((value) => value.value === selection.value)) {
40742
+ warnIgnoredSetting(
40743
+ audit,
40744
+ "session_configuration_setting_ignored",
40745
+ commandId,
40746
+ sessionId,
40747
+ agent.id,
40748
+ selection,
40749
+ option.category,
40750
+ "value_unavailable"
40751
+ );
40752
+ return options;
40739
40753
  }
40740
40754
  if (sessionConfigurationMatches(option, selection)) {
40741
40755
  return options;
@@ -41242,7 +41256,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41242
41256
  );
41243
41257
  audit.record({
41244
41258
  commandId: command2.requestId,
41245
- details: { agentId: command2.agentId, directoryId: command2.directoryId },
41259
+ details: { agentId: command2.agentId },
41246
41260
  event: "agent_settings_discovered",
41247
41261
  sessionId: `agent-settings:${command2.agentId}`
41248
41262
  });