@moxt-ai/mobius 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/runtime.js CHANGED
@@ -1233,6 +1233,7 @@ var ClaudeCodeAgentSpecification = class extends BridgedAcpAgentDefinition {
1233
1233
 
1234
1234
  // src/agent-catalog/agents/codex-agent.ts
1235
1235
  var CodexAgentSpecification = class extends BridgedAcpAgentDefinition {
1236
+ versionProbeTimeoutMilliseconds = 1e4;
1236
1237
  adapterEnvironmentVariable = "CODEX_PATH";
1237
1238
  adapterOverrideVariable = "MOBIUS_CODEX_ACP_PATH";
1238
1239
  adapterPackageDefinition = new ManagedNpmPackageDefinition(
@@ -22545,6 +22546,9 @@ var AGENT_INSTALL_PROGRESS_KIND = "agent.integration.install.progress";
22545
22546
  var AGENT_INSTALL_COMPLETED_KIND = "agent.integration.install.completed";
22546
22547
  var AGENT_INSTALL_FAILED_KIND = "agent.integration.install.failed";
22547
22548
  var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
22549
+ var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
22550
+ var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
22551
+ var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
22548
22552
  var IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
22549
22553
  var DIRECTORY_IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
22550
22554
  var IDENTIFIER = external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN);
@@ -22573,6 +22577,28 @@ var sessionConfigOptionSchema = external_exports.strictObject({
22573
22577
  values: external_exports.array(configValueSchema).max(500).readonly()
22574
22578
  }).readonly();
22575
22579
  var sessionConfigOptionsSchema = external_exports.array(sessionConfigOptionSchema).max(100).readonly();
22580
+ var agentSettingsDiscoverCommandSchema = external_exports.strictObject({
22581
+ additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly(),
22582
+ agentId: IDENTIFIER,
22583
+ directoryId: DIRECTORY_IDENTIFIER,
22584
+ kind: external_exports.literal(AGENT_SETTINGS_DISCOVER_KIND),
22585
+ requestId: IDENTIFIER
22586
+ }).readonly();
22587
+ var agentSettingsDiscoveredEventSchema = external_exports.strictObject({
22588
+ agentId: IDENTIFIER,
22589
+ agentName: external_exports.string().max(255),
22590
+ agentVersion: external_exports.string().max(128),
22591
+ configOptions: sessionConfigOptionsSchema,
22592
+ directoryId: DIRECTORY_IDENTIFIER,
22593
+ kind: external_exports.literal(AGENT_SETTINGS_DISCOVERED_KIND),
22594
+ requestId: IDENTIFIER
22595
+ }).readonly();
22596
+ var agentSettingsDiscoveryFailedEventSchema = external_exports.strictObject({
22597
+ code: IDENTIFIER,
22598
+ kind: external_exports.literal(AGENT_SETTINGS_DISCOVERY_FAILED_KIND),
22599
+ message: external_exports.string().min(1).max(500),
22600
+ requestId: IDENTIFIER
22601
+ }).readonly();
22576
22602
  var sessionConfigurationSelectionSchema = external_exports.strictObject({
22577
22603
  booleanValue: external_exports.boolean(),
22578
22604
  configId: IDENTIFIER,
@@ -22709,6 +22735,7 @@ var sessionPrepareCommandSchema = external_exports.strictObject({
22709
22735
  }).readonly().optional(),
22710
22736
  kind: external_exports.literal(SESSION_PREPARE_KIND),
22711
22737
  requestId: IDENTIFIER,
22738
+ /** @deprecated Reserved for the legacy Bot Agent-configuration endpoint. */
22712
22739
  transient: external_exports.boolean().optional()
22713
22740
  }).readonly();
22714
22741
  var runtimeTimingsSchema = external_exports.array(
@@ -22922,6 +22949,9 @@ var decodePromptImagesValue = (value) => decodeValue(value, external_exports.arr
22922
22949
  var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
22923
22950
  var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
22924
22951
  var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
22952
+ var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
22953
+ var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
22954
+ var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
22925
22955
  var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
22926
22956
  var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
22927
22957
  var decodeSessionPrepareCommand = (encoded) => decode3(encoded, sessionPrepareCommandSchema);
@@ -32915,6 +32945,16 @@ var AcpPreparedSession = class {
32915
32945
  this.restored = restored;
32916
32946
  }
32917
32947
  };
32948
+ var AcpAgentSettingsSnapshot = class {
32949
+ agentName;
32950
+ agentVersion;
32951
+ configOptions;
32952
+ constructor(agentName, agentVersion, configOptions) {
32953
+ this.agentName = agentName;
32954
+ this.agentVersion = agentVersion;
32955
+ this.configOptions = configOptions;
32956
+ }
32957
+ };
32918
32958
  var AcpExecutionError = class extends Error {
32919
32959
  code;
32920
32960
  constructor(message, options = {}, code = "acp_execution_failed") {
@@ -34538,6 +34578,7 @@ var AcpProcessSession = class _AcpProcessSession {
34538
34578
  };
34539
34579
  var AcpSessionManager = class {
34540
34580
  #activeCommandIds = /* @__PURE__ */ new Map();
34581
+ #agentSettingsObserver = new NullAcpSessionObserver();
34541
34582
  #nativeOperations = /* @__PURE__ */ new Set();
34542
34583
  #nativeBrowserObserver = new NullAcpSessionObserver();
34543
34584
  #nativeBrowserPreparing = /* @__PURE__ */ new Map();
@@ -34732,9 +34773,29 @@ var AcpSessionManager = class {
34732
34773
  return runtime.prepared();
34733
34774
  };
34734
34775
  /**
34735
- * Opens a short-lived ACP session only to read the Agent's authoritative
34736
- * configuration options. The runtime and any persisted native-session
34737
- * record are released before this method resolves.
34776
+ * Opens a short-lived native ACP session only to read the local Agent's
34777
+ * authoritative settings. Its identity and store are private to this
34778
+ * operation and never become a Mobius Session.
34779
+ */
34780
+ inspectAgentSettings = async (options) => {
34781
+ const runtime = await AcpProcessSession.start(
34782
+ {
34783
+ ...options,
34784
+ sessionId: `agent-settings-${crypto.randomUUID()}`
34785
+ },
34786
+ () => this.#agentSettingsObserver,
34787
+ new MemoryAcpSessionStore()
34788
+ );
34789
+ try {
34790
+ const prepared = runtime.prepared();
34791
+ return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, prepared.configOptions);
34792
+ } finally {
34793
+ await runtime.close();
34794
+ }
34795
+ };
34796
+ /**
34797
+ * @deprecated Retained for the Bot-scoped legacy Agent-configuration API.
34798
+ * Use inspectAgentSettings for Agent-scoped settings discovery.
34738
34799
  */
34739
34800
  inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
34740
34801
  if (this.#preparing.has(options.sessionId) || this.#sessions.has(options.sessionId)) {
@@ -35267,6 +35328,7 @@ async function publishAgentCatalog(config2, signal) {
35267
35328
  agents: catalog.agents.map((agent) => ({
35268
35329
  agentPath: agent.agentIdentity.requestedPath,
35269
35330
  agentVersion: agent.agentVersion,
35331
+ agentSettingsDiscovery: true,
35270
35332
  botSessionConfiguration: true,
35271
35333
  capabilities: agent.capabilities,
35272
35334
  id: agent.id,
@@ -35656,23 +35718,19 @@ var FixedInstallationExecutor = class {
35656
35718
  this.#catalog.transition(previous2.agents, previous2.installableAgents);
35657
35719
  throw error62;
35658
35720
  }
35659
- const alreadyReady = initialInventory.available.find((candidate2) => candidate2.specification.id === agentId);
35721
+ const alreadyReady = initialInventory.available.find((candidate) => candidate.specification.id === agentId);
35660
35722
  if (alreadyReady instanceof AvailableAgent) {
35661
35723
  return;
35662
35724
  }
35663
- const candidate = initialInventory.installable.find((agent2) => agent2.id === agentId);
35664
- if (candidate instanceof MissingAgentDefinition) {
35725
+ const initialDiscovery = initialInventory.unavailable.find(
35726
+ (candidate) => candidate.specification.id === agentId
35727
+ );
35728
+ if (initialDiscovery instanceof MissingAgent) {
35665
35729
  throw new InstallationManagerError(
35666
35730
  "agent_not_installed",
35667
35731
  `Install ${specification.label} on this machine, then try installing the integration again.`
35668
35732
  );
35669
35733
  }
35670
- if (!(candidate instanceof AgentIntegrationDefinition)) {
35671
- throw new InstallationManagerError(
35672
- "agent_verification_failed",
35673
- "The local Agent discovery result is unavailable"
35674
- );
35675
- }
35676
35734
  const verifiedAgent = await findVerifiedAgentExecutable(specification, discoveryOptions);
35677
35735
  if (verifiedAgent === null) {
35678
35736
  throw new InstallationManagerError(
@@ -35714,7 +35772,7 @@ var FixedInstallationExecutor = class {
35714
35772
  signal,
35715
35773
  specifications: this.#specifications
35716
35774
  });
35717
- const verified = inventory.available.find((candidate2) => candidate2.specification.id === agentId);
35775
+ const verified = inventory.available.find((candidate) => candidate.specification.id === agentId);
35718
35776
  if (verified instanceof AvailableAgent) {
35719
35777
  this.#audit.record("agent_installation_acp_verified", requestId, agentId, {
35720
35778
  adapterVersion: verified.agent.adapterVersion,
@@ -35730,7 +35788,7 @@ var FixedInstallationExecutor = class {
35730
35788
  }
35731
35789
  return;
35732
35790
  }
35733
- const unavailable = inventory.unavailable.find((candidate2) => candidate2.specification.id === agentId);
35791
+ const unavailable = inventory.unavailable.find((candidate) => candidate.specification.id === agentId);
35734
35792
  if (unavailable === void 0) {
35735
35793
  throw new InstallationManagerError(
35736
35794
  "agent_verification_failed",
@@ -39571,6 +39629,31 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
39571
39629
  }
39572
39630
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
39573
39631
  }
39632
+ async function discoverAgentSettings(command, config2, directories, sessions, signal) {
39633
+ const resolved = await resolveSessionDirectories(
39634
+ directories,
39635
+ config2.bindingId,
39636
+ command.directoryId,
39637
+ command.additionalDirectoryIds,
39638
+ signal
39639
+ );
39640
+ const agent = config2.catalog.find(command.agentId);
39641
+ const snapshot = await sessions.inspectAgentSettings({
39642
+ additionalDirectories: resolved.additionalDirectories,
39643
+ agent,
39644
+ cwd: resolved.cwd,
39645
+ signal
39646
+ });
39647
+ return {
39648
+ agentId: command.agentId,
39649
+ agentName: snapshot.agentName,
39650
+ agentVersion: snapshot.agentVersion,
39651
+ configOptions: snapshot.configOptions,
39652
+ directoryId: command.directoryId,
39653
+ kind: AGENT_SETTINGS_DISCOVERED_KIND,
39654
+ requestId: command.requestId
39655
+ };
39656
+ }
39574
39657
  async function executeWorkspaceList(socket, command, directories, audit, signal) {
39575
39658
  try {
39576
39659
  const listing = await directories.list(command.bindingId, command.directoryId, signal);
@@ -40088,6 +40171,22 @@ async function publishAgentCatalogUntilAvailable(config2, diagnostics, signal, t
40088
40171
  }
40089
40172
  }
40090
40173
  }
40174
+ async function installDetectedAgentIntegrations(config2, installations, signal) {
40175
+ for (const agent of config2.catalog.read().installableAgents) {
40176
+ if (!(agent instanceof AgentIntegrationDefinition)) {
40177
+ continue;
40178
+ }
40179
+ signal.throwIfAborted();
40180
+ await installations.request(
40181
+ {
40182
+ agentId: agent.id,
40183
+ kind: AGENT_INSTALL_REQUEST_KIND,
40184
+ requestId: `automatic-integration-${randomUUID4()}`
40185
+ },
40186
+ signal
40187
+ );
40188
+ }
40189
+ }
40091
40190
  async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, grants, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
40092
40191
  const relayUrl = new URL(config2.relayUrl);
40093
40192
  relayUrl.searchParams.set("deliveryReceipts", "1");
@@ -40095,10 +40194,11 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40095
40194
  const socket = await connectRelay(relayUrl, signal);
40096
40195
  const reconnectingTurns = [...activeTurns.values()];
40097
40196
  diagnostics.connectionOpened(connectionEpoch);
40098
- onConnected();
40099
40197
  const connectionController = new AbortController();
40100
40198
  const nativeRequests = /* @__PURE__ */ new Map();
40199
+ const agentSettingsDiscoveries = /* @__PURE__ */ new Map();
40101
40200
  installationObserver.connect(socket);
40201
+ onConnected();
40102
40202
  try {
40103
40203
  await new Promise((resolve6, reject) => {
40104
40204
  let finished = false;
@@ -40525,6 +40625,104 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40525
40625
  }
40526
40626
  return;
40527
40627
  }
40628
+ if (kind === AGENT_SETTINGS_DISCOVER_KIND) {
40629
+ const command2 = decodeAgentSettingsDiscoverCommand(encoded);
40630
+ const existing = [...agentSettingsDiscoveries.values()].find(
40631
+ (request) => request.agentId === command2.agentId && !request.controller.signal.aborted
40632
+ );
40633
+ if (agentSettingsDiscoveries.has(command2.requestId) || existing !== void 0) {
40634
+ if (socket.readyState === WebSocket2.OPEN) {
40635
+ send(
40636
+ socket,
40637
+ encodeAgentSettingsDiscoveryFailedEvent({
40638
+ code: "agent_settings_discovery_busy",
40639
+ kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
40640
+ message: "Another settings discovery is already running for this Agent",
40641
+ requestId: command2.requestId
40642
+ })
40643
+ );
40644
+ }
40645
+ return;
40646
+ }
40647
+ if (agentSettingsDiscoveries.size >= 4) {
40648
+ if (socket.readyState === WebSocket2.OPEN) {
40649
+ send(
40650
+ socket,
40651
+ encodeAgentSettingsDiscoveryFailedEvent({
40652
+ code: "agent_settings_discovery_busy",
40653
+ kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
40654
+ message: "Too many Agent settings discoveries are running",
40655
+ requestId: command2.requestId
40656
+ })
40657
+ );
40658
+ }
40659
+ return;
40660
+ }
40661
+ const controller = new AbortController();
40662
+ const operationSignal = AbortSignal.any([connectionController.signal, controller.signal]);
40663
+ const timeout = timer.schedule(
40664
+ () => controller.abort(
40665
+ new AcpExecutionError(
40666
+ "Agent settings discovery timed out",
40667
+ {},
40668
+ "agent_settings_discovery_timeout"
40669
+ )
40670
+ ),
40671
+ 9e4
40672
+ );
40673
+ const completion = (async () => {
40674
+ try {
40675
+ const result = await discoverAgentSettings(
40676
+ command2,
40677
+ config2,
40678
+ directories,
40679
+ sessions,
40680
+ operationSignal
40681
+ );
40682
+ audit.record({
40683
+ commandId: command2.requestId,
40684
+ details: { agentId: command2.agentId, directoryId: command2.directoryId },
40685
+ event: "agent_settings_discovered",
40686
+ sessionId: `agent-settings:${command2.agentId}`
40687
+ });
40688
+ if (socket.readyState === WebSocket2.OPEN) {
40689
+ send(socket, encodeAgentSettingsDiscoveredEvent(result));
40690
+ }
40691
+ } catch (error62) {
40692
+ const failure2 = operationSignal.aborted ? controller.signal.reason ?? new AcpExecutionError(
40693
+ "Agent settings discovery cancelled",
40694
+ {},
40695
+ "agent_settings_discovery_cancelled"
40696
+ ) : error62;
40697
+ audit.record({
40698
+ commandId: command2.requestId,
40699
+ details: { agentId: command2.agentId, code: operationErrorCode(failure2) },
40700
+ event: "agent_settings_discovery_failed",
40701
+ sessionId: `agent-settings:${command2.agentId}`
40702
+ });
40703
+ if (socket.readyState === WebSocket2.OPEN) {
40704
+ send(
40705
+ socket,
40706
+ encodeAgentSettingsDiscoveryFailedEvent({
40707
+ code: operationErrorCode(failure2),
40708
+ kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
40709
+ message: operationErrorMessage(failure2),
40710
+ requestId: command2.requestId
40711
+ })
40712
+ );
40713
+ }
40714
+ } finally {
40715
+ timeout.cancel();
40716
+ agentSettingsDiscoveries.delete(command2.requestId);
40717
+ }
40718
+ })();
40719
+ agentSettingsDiscoveries.set(command2.requestId, {
40720
+ agentId: command2.agentId,
40721
+ completion,
40722
+ controller
40723
+ });
40724
+ return;
40725
+ }
40528
40726
  if (kind === NATIVE_SESSION_REQUEST_KIND) {
40529
40727
  const command2 = decodeNativeSessionCommand(encoded);
40530
40728
  const previous2 = [...nativeRequests.values()].filter(
@@ -40909,7 +41107,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40909
41107
  });
40910
41108
  } finally {
40911
41109
  connectionController.abort();
40912
- await Promise.all([...nativeRequests.values()].map((request) => request.completion));
41110
+ await Promise.all([
41111
+ ...[...nativeRequests.values()].map((request) => request.completion),
41112
+ ...[...agentSettingsDiscoveries.values()].map((request) => request.completion)
41113
+ ]);
40913
41114
  }
40914
41115
  }
40915
41116
  async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
@@ -40953,7 +41154,31 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
40953
41154
  installationAudit
40954
41155
  );
40955
41156
  let connectionEpoch = 0;
41157
+ let automaticIntegrationProvisioningStarted = false;
41158
+ let automaticIntegrationProvisioning = Promise.resolve();
40956
41159
  let connectionAnnounced = false;
41160
+ let catalogPublished = false;
41161
+ let readinessAnnounced = false;
41162
+ const startAutomaticIntegrationProvisioning = () => {
41163
+ if (!connectionAnnounced || !catalogPublished || automaticIntegrationProvisioningStarted) {
41164
+ return;
41165
+ }
41166
+ automaticIntegrationProvisioningStarted = true;
41167
+ automaticIntegrationProvisioning = installDetectedAgentIntegrations(config2, installations, signal).catch(
41168
+ (error62) => {
41169
+ if (!signal.aborted) {
41170
+ console.error("Mobius daemon could not automatically install detected Agent integrations", error62);
41171
+ }
41172
+ }
41173
+ );
41174
+ };
41175
+ const announceReadiness = () => {
41176
+ if (!connectionAnnounced || !catalogPublished || readinessAnnounced) {
41177
+ return;
41178
+ }
41179
+ readinessAnnounced = true;
41180
+ process.stdout.write("Mobius daemon is ready for Agent requests.\n");
41181
+ };
40957
41182
  const announceConnection = () => {
40958
41183
  if (connectionAnnounced) {
40959
41184
  return;
@@ -40967,8 +41192,18 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
40967
41192
 
40968
41193
  `
40969
41194
  );
41195
+ announceReadiness();
41196
+ startAutomaticIntegrationProvisioning();
40970
41197
  };
40971
41198
  const catalogPublication = publishAgentCatalogUntilAvailable(config2, diagnostics, signal, timer);
41199
+ void catalogPublication.then(() => {
41200
+ if (signal.aborted) {
41201
+ return;
41202
+ }
41203
+ catalogPublished = true;
41204
+ announceReadiness();
41205
+ startAutomaticIntegrationProvisioning();
41206
+ });
40972
41207
  try {
40973
41208
  await ipc.listen(signal);
40974
41209
  while (!signal.aborted) {
@@ -41014,24 +41249,28 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41014
41249
  await catalogPublication;
41015
41250
  } finally {
41016
41251
  try {
41017
- await installations.close();
41252
+ await automaticIntegrationProvisioning;
41018
41253
  } finally {
41019
41254
  try {
41020
- await ipc.close();
41255
+ await installations.close();
41021
41256
  } finally {
41022
41257
  try {
41023
- await sessions.close();
41258
+ await ipc.close();
41024
41259
  } finally {
41025
41260
  try {
41026
- sessionStore.close();
41261
+ await sessions.close();
41027
41262
  } finally {
41028
41263
  try {
41029
- grants.close();
41264
+ sessionStore.close();
41030
41265
  } finally {
41031
41266
  try {
41032
- publisher.close();
41267
+ grants.close();
41033
41268
  } finally {
41034
- outbox.close();
41269
+ try {
41270
+ publisher.close();
41271
+ } finally {
41272
+ outbox.close();
41273
+ }
41035
41274
  }
41036
41275
  }
41037
41276
  }
@@ -41171,6 +41410,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
41171
41410
  const agents = localAgents.map((agent) => ({
41172
41411
  agentPath: agent.agentIdentity.requestedPath,
41173
41412
  agentVersion: agent.agentVersion,
41413
+ agentSettingsDiscovery: true,
41174
41414
  botSessionConfiguration: true,
41175
41415
  capabilities: agent.capabilities,
41176
41416
  id: agent.id,