@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/index.js CHANGED
@@ -19804,6 +19804,9 @@ var AGENT_INSTALL_PROGRESS_KIND = "agent.integration.install.progress";
19804
19804
  var AGENT_INSTALL_COMPLETED_KIND = "agent.integration.install.completed";
19805
19805
  var AGENT_INSTALL_FAILED_KIND = "agent.integration.install.failed";
19806
19806
  var AGENT_INSTALL_CANCELLED_KIND = "agent.integration.install.cancelled";
19807
+ var AGENT_SETTINGS_DISCOVER_KIND = "agent.settings.discover";
19808
+ var AGENT_SETTINGS_DISCOVERED_KIND = "agent.settings.discovered";
19809
+ var AGENT_SETTINGS_DISCOVERY_FAILED_KIND = "agent.settings.discovery.failed";
19807
19810
  var IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
19808
19811
  var DIRECTORY_IDENTIFIER_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
19809
19812
  var IDENTIFIER = external_exports.string().min(1).max(128).regex(IDENTIFIER_PATTERN);
@@ -19832,6 +19835,28 @@ var sessionConfigOptionSchema = external_exports.strictObject({
19832
19835
  values: external_exports.array(configValueSchema).max(500).readonly()
19833
19836
  }).readonly();
19834
19837
  var sessionConfigOptionsSchema = external_exports.array(sessionConfigOptionSchema).max(100).readonly();
19838
+ var agentSettingsDiscoverCommandSchema = external_exports.strictObject({
19839
+ additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly(),
19840
+ agentId: IDENTIFIER,
19841
+ directoryId: DIRECTORY_IDENTIFIER,
19842
+ kind: external_exports.literal(AGENT_SETTINGS_DISCOVER_KIND),
19843
+ requestId: IDENTIFIER
19844
+ }).readonly();
19845
+ var agentSettingsDiscoveredEventSchema = external_exports.strictObject({
19846
+ agentId: IDENTIFIER,
19847
+ agentName: external_exports.string().max(255),
19848
+ agentVersion: external_exports.string().max(128),
19849
+ configOptions: sessionConfigOptionsSchema,
19850
+ directoryId: DIRECTORY_IDENTIFIER,
19851
+ kind: external_exports.literal(AGENT_SETTINGS_DISCOVERED_KIND),
19852
+ requestId: IDENTIFIER
19853
+ }).readonly();
19854
+ var agentSettingsDiscoveryFailedEventSchema = external_exports.strictObject({
19855
+ code: IDENTIFIER,
19856
+ kind: external_exports.literal(AGENT_SETTINGS_DISCOVERY_FAILED_KIND),
19857
+ message: external_exports.string().min(1).max(500),
19858
+ requestId: IDENTIFIER
19859
+ }).readonly();
19835
19860
  var sessionConfigurationSelectionSchema = external_exports.strictObject({
19836
19861
  booleanValue: external_exports.boolean(),
19837
19862
  configId: IDENTIFIER,
@@ -19968,6 +19993,7 @@ var sessionPrepareCommandSchema = external_exports.strictObject({
19968
19993
  }).readonly().optional(),
19969
19994
  kind: external_exports.literal(SESSION_PREPARE_KIND),
19970
19995
  requestId: IDENTIFIER,
19996
+ /** @deprecated Reserved for the legacy Bot Agent-configuration endpoint. */
19971
19997
  transient: external_exports.boolean().optional()
19972
19998
  }).readonly();
19973
19999
  var runtimeTimingsSchema = external_exports.array(
@@ -20181,6 +20207,9 @@ var decodePromptImagesValue = (value) => decodeValue(value, external_exports.arr
20181
20207
  var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
20182
20208
  var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
20183
20209
  var encode3 = (message, schema) => JSON.stringify(decodeValue(message, schema));
20210
+ var decodeAgentSettingsDiscoverCommand = (encoded) => decode3(encoded, agentSettingsDiscoverCommandSchema);
20211
+ var encodeAgentSettingsDiscoveredEvent = (message) => encode3(message, agentSettingsDiscoveredEventSchema);
20212
+ var encodeAgentSettingsDiscoveryFailedEvent = (message) => encode3(message, agentSettingsDiscoveryFailedEventSchema);
20184
20213
  var decodeWorkspaceListCommand = (encoded) => decode3(encoded, workspaceListCommandSchema);
20185
20214
  var encodeWorkspaceEntriesEvent = (message) => encode3(message, workspaceEntriesEventSchema);
20186
20215
  var decodeSessionPrepareCommand = (encoded) => decode3(encoded, sessionPrepareCommandSchema);
@@ -30902,6 +30931,16 @@ var AcpPreparedSession = class {
30902
30931
  this.restored = restored;
30903
30932
  }
30904
30933
  };
30934
+ var AcpAgentSettingsSnapshot = class {
30935
+ agentName;
30936
+ agentVersion;
30937
+ configOptions;
30938
+ constructor(agentName, agentVersion, configOptions) {
30939
+ this.agentName = agentName;
30940
+ this.agentVersion = agentVersion;
30941
+ this.configOptions = configOptions;
30942
+ }
30943
+ };
30905
30944
  var AcpExecutionError = class extends Error {
30906
30945
  code;
30907
30946
  constructor(message, options = {}, code = "acp_execution_failed") {
@@ -32525,6 +32564,7 @@ var AcpProcessSession = class _AcpProcessSession {
32525
32564
  };
32526
32565
  var AcpSessionManager = class {
32527
32566
  #activeCommandIds = /* @__PURE__ */ new Map();
32567
+ #agentSettingsObserver = new NullAcpSessionObserver();
32528
32568
  #nativeOperations = /* @__PURE__ */ new Set();
32529
32569
  #nativeBrowserObserver = new NullAcpSessionObserver();
32530
32570
  #nativeBrowserPreparing = /* @__PURE__ */ new Map();
@@ -32719,9 +32759,29 @@ var AcpSessionManager = class {
32719
32759
  return runtime.prepared();
32720
32760
  };
32721
32761
  /**
32722
- * Opens a short-lived ACP session only to read the Agent's authoritative
32723
- * configuration options. The runtime and any persisted native-session
32724
- * record are released before this method resolves.
32762
+ * Opens a short-lived native ACP session only to read the local Agent's
32763
+ * authoritative settings. Its identity and store are private to this
32764
+ * operation and never become a Mobius Session.
32765
+ */
32766
+ inspectAgentSettings = async (options) => {
32767
+ const runtime = await AcpProcessSession.start(
32768
+ {
32769
+ ...options,
32770
+ sessionId: `agent-settings-${crypto.randomUUID()}`
32771
+ },
32772
+ () => this.#agentSettingsObserver,
32773
+ new MemoryAcpSessionStore()
32774
+ );
32775
+ try {
32776
+ const prepared = runtime.prepared();
32777
+ return new AcpAgentSettingsSnapshot(prepared.agentName, prepared.agentVersion, prepared.configOptions);
32778
+ } finally {
32779
+ await runtime.close();
32780
+ }
32781
+ };
32782
+ /**
32783
+ * @deprecated Retained for the Bot-scoped legacy Agent-configuration API.
32784
+ * Use inspectAgentSettings for Agent-scoped settings discovery.
32725
32785
  */
32726
32786
  inspectSession = async (options, metrics = unmeasuredOperationMetrics) => {
32727
32787
  if (this.#preparing.has(options.sessionId) || this.#sessions.has(options.sessionId)) {
@@ -34780,6 +34840,7 @@ var ClaudeCodeAgentSpecification = class extends BridgedAcpAgentDefinition {
34780
34840
 
34781
34841
  // src/agent-catalog/agents/codex-agent.ts
34782
34842
  var CodexAgentSpecification = class extends BridgedAcpAgentDefinition {
34843
+ versionProbeTimeoutMilliseconds = 1e4;
34783
34844
  adapterEnvironmentVariable = "CODEX_PATH";
34784
34845
  adapterOverrideVariable = "MOBIUS_CODEX_ACP_PATH";
34785
34846
  adapterPackageDefinition = new ManagedNpmPackageDefinition(
@@ -36401,6 +36462,7 @@ async function claimPairing(options, defaultWorkspace, localAgents, installableA
36401
36462
  const agents = localAgents.map((agent) => ({
36402
36463
  agentPath: agent.agentIdentity.requestedPath,
36403
36464
  agentVersion: agent.agentVersion,
36465
+ agentSettingsDiscovery: true,
36404
36466
  botSessionConfiguration: true,
36405
36467
  capabilities: agent.capabilities,
36406
36468
  id: agent.id,
@@ -36642,6 +36704,7 @@ async function publishAgentCatalog(config2, signal) {
36642
36704
  agents: catalog.agents.map((agent) => ({
36643
36705
  agentPath: agent.agentIdentity.requestedPath,
36644
36706
  agentVersion: agent.agentVersion,
36707
+ agentSettingsDiscovery: true,
36645
36708
  botSessionConfiguration: true,
36646
36709
  capabilities: agent.capabilities,
36647
36710
  id: agent.id,
@@ -37031,23 +37094,19 @@ var FixedInstallationExecutor = class {
37031
37094
  this.#catalog.transition(previous2.agents, previous2.installableAgents);
37032
37095
  throw error62;
37033
37096
  }
37034
- const alreadyReady = initialInventory.available.find((candidate2) => candidate2.specification.id === agentId);
37097
+ const alreadyReady = initialInventory.available.find((candidate) => candidate.specification.id === agentId);
37035
37098
  if (alreadyReady instanceof AvailableAgent) {
37036
37099
  return;
37037
37100
  }
37038
- const candidate = initialInventory.installable.find((agent2) => agent2.id === agentId);
37039
- if (candidate instanceof MissingAgentDefinition) {
37101
+ const initialDiscovery = initialInventory.unavailable.find(
37102
+ (candidate) => candidate.specification.id === agentId
37103
+ );
37104
+ if (initialDiscovery instanceof MissingAgent) {
37040
37105
  throw new InstallationManagerError(
37041
37106
  "agent_not_installed",
37042
37107
  `Install ${specification.label} on this machine, then try installing the integration again.`
37043
37108
  );
37044
37109
  }
37045
- if (!(candidate instanceof AgentIntegrationDefinition)) {
37046
- throw new InstallationManagerError(
37047
- "agent_verification_failed",
37048
- "The local Agent discovery result is unavailable"
37049
- );
37050
- }
37051
37110
  const verifiedAgent = await findVerifiedAgentExecutable(specification, discoveryOptions);
37052
37111
  if (verifiedAgent === null) {
37053
37112
  throw new InstallationManagerError(
@@ -37089,7 +37148,7 @@ var FixedInstallationExecutor = class {
37089
37148
  signal,
37090
37149
  specifications: this.#specifications
37091
37150
  });
37092
- const verified = inventory.available.find((candidate2) => candidate2.specification.id === agentId);
37151
+ const verified = inventory.available.find((candidate) => candidate.specification.id === agentId);
37093
37152
  if (verified instanceof AvailableAgent) {
37094
37153
  this.#audit.record("agent_installation_acp_verified", requestId, agentId, {
37095
37154
  adapterVersion: verified.agent.adapterVersion,
@@ -37105,7 +37164,7 @@ var FixedInstallationExecutor = class {
37105
37164
  }
37106
37165
  return;
37107
37166
  }
37108
- const unavailable = inventory.unavailable.find((candidate2) => candidate2.specification.id === agentId);
37167
+ const unavailable = inventory.unavailable.find((candidate) => candidate.specification.id === agentId);
37109
37168
  if (unavailable === void 0) {
37110
37169
  throw new InstallationManagerError(
37111
37170
  "agent_verification_failed",
@@ -40126,6 +40185,31 @@ async function resolveSessionDirectories(directories, bindingId, directoryId2, a
40126
40185
  }
40127
40186
  return new ResolvedSessionDirectories(cwd, additionalDirectories, additionalDirectoryEntries);
40128
40187
  }
40188
+ async function discoverAgentSettings(command, config2, directories, sessions, signal) {
40189
+ const resolved = await resolveSessionDirectories(
40190
+ directories,
40191
+ config2.bindingId,
40192
+ command.directoryId,
40193
+ command.additionalDirectoryIds,
40194
+ signal
40195
+ );
40196
+ const agent = config2.catalog.find(command.agentId);
40197
+ const snapshot = await sessions.inspectAgentSettings({
40198
+ additionalDirectories: resolved.additionalDirectories,
40199
+ agent,
40200
+ cwd: resolved.cwd,
40201
+ signal
40202
+ });
40203
+ return {
40204
+ agentId: command.agentId,
40205
+ agentName: snapshot.agentName,
40206
+ agentVersion: snapshot.agentVersion,
40207
+ configOptions: snapshot.configOptions,
40208
+ directoryId: command.directoryId,
40209
+ kind: AGENT_SETTINGS_DISCOVERED_KIND,
40210
+ requestId: command.requestId
40211
+ };
40212
+ }
40129
40213
  async function executeWorkspaceList(socket, command, directories, audit, signal) {
40130
40214
  try {
40131
40215
  const listing = await directories.list(command.bindingId, command.directoryId, signal);
@@ -40643,6 +40727,22 @@ async function publishAgentCatalogUntilAvailable(config2, diagnostics, signal, t
40643
40727
  }
40644
40728
  }
40645
40729
  }
40730
+ async function installDetectedAgentIntegrations(config2, installations, signal) {
40731
+ for (const agent of config2.catalog.read().installableAgents) {
40732
+ if (!(agent instanceof AgentIntegrationDefinition)) {
40733
+ continue;
40734
+ }
40735
+ signal.throwIfAborted();
40736
+ await installations.request(
40737
+ {
40738
+ agentId: agent.id,
40739
+ kind: AGENT_INSTALL_REQUEST_KIND,
40740
+ requestId: `automatic-integration-${randomUUID6()}`
40741
+ },
40742
+ signal
40743
+ );
40744
+ }
40745
+ }
40646
40746
  async function runRelayConnection(config2, directories, audit, sessions, installations, installationObserver, nativeSessions, outbox, publisher, grants, contexts, applicator, ipc, activeTurns, activeAttemptIds, connectionEpoch, diagnostics, onConnected, signal, timer) {
40647
40747
  const relayUrl = new URL(config2.relayUrl);
40648
40748
  relayUrl.searchParams.set("deliveryReceipts", "1");
@@ -40650,10 +40750,11 @@ async function runRelayConnection(config2, directories, audit, sessions, install
40650
40750
  const socket = await connectRelay(relayUrl, signal);
40651
40751
  const reconnectingTurns = [...activeTurns.values()];
40652
40752
  diagnostics.connectionOpened(connectionEpoch);
40653
- onConnected();
40654
40753
  const connectionController = new AbortController();
40655
40754
  const nativeRequests = /* @__PURE__ */ new Map();
40755
+ const agentSettingsDiscoveries = /* @__PURE__ */ new Map();
40656
40756
  installationObserver.connect(socket);
40757
+ onConnected();
40657
40758
  try {
40658
40759
  await new Promise((resolve6, reject) => {
40659
40760
  let finished = false;
@@ -41080,6 +41181,104 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41080
41181
  }
41081
41182
  return;
41082
41183
  }
41184
+ if (kind === AGENT_SETTINGS_DISCOVER_KIND) {
41185
+ const command2 = decodeAgentSettingsDiscoverCommand(encoded);
41186
+ const existing = [...agentSettingsDiscoveries.values()].find(
41187
+ (request) => request.agentId === command2.agentId && !request.controller.signal.aborted
41188
+ );
41189
+ if (agentSettingsDiscoveries.has(command2.requestId) || existing !== void 0) {
41190
+ if (socket.readyState === WebSocket2.OPEN) {
41191
+ send(
41192
+ socket,
41193
+ encodeAgentSettingsDiscoveryFailedEvent({
41194
+ code: "agent_settings_discovery_busy",
41195
+ kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
41196
+ message: "Another settings discovery is already running for this Agent",
41197
+ requestId: command2.requestId
41198
+ })
41199
+ );
41200
+ }
41201
+ return;
41202
+ }
41203
+ if (agentSettingsDiscoveries.size >= 4) {
41204
+ if (socket.readyState === WebSocket2.OPEN) {
41205
+ send(
41206
+ socket,
41207
+ encodeAgentSettingsDiscoveryFailedEvent({
41208
+ code: "agent_settings_discovery_busy",
41209
+ kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
41210
+ message: "Too many Agent settings discoveries are running",
41211
+ requestId: command2.requestId
41212
+ })
41213
+ );
41214
+ }
41215
+ return;
41216
+ }
41217
+ const controller = new AbortController();
41218
+ const operationSignal = AbortSignal.any([connectionController.signal, controller.signal]);
41219
+ const timeout = timer.schedule(
41220
+ () => controller.abort(
41221
+ new AcpExecutionError(
41222
+ "Agent settings discovery timed out",
41223
+ {},
41224
+ "agent_settings_discovery_timeout"
41225
+ )
41226
+ ),
41227
+ 9e4
41228
+ );
41229
+ const completion = (async () => {
41230
+ try {
41231
+ const result = await discoverAgentSettings(
41232
+ command2,
41233
+ config2,
41234
+ directories,
41235
+ sessions,
41236
+ operationSignal
41237
+ );
41238
+ audit.record({
41239
+ commandId: command2.requestId,
41240
+ details: { agentId: command2.agentId, directoryId: command2.directoryId },
41241
+ event: "agent_settings_discovered",
41242
+ sessionId: `agent-settings:${command2.agentId}`
41243
+ });
41244
+ if (socket.readyState === WebSocket2.OPEN) {
41245
+ send(socket, encodeAgentSettingsDiscoveredEvent(result));
41246
+ }
41247
+ } catch (error62) {
41248
+ const failure2 = operationSignal.aborted ? controller.signal.reason ?? new AcpExecutionError(
41249
+ "Agent settings discovery cancelled",
41250
+ {},
41251
+ "agent_settings_discovery_cancelled"
41252
+ ) : error62;
41253
+ audit.record({
41254
+ commandId: command2.requestId,
41255
+ details: { agentId: command2.agentId, code: operationErrorCode(failure2) },
41256
+ event: "agent_settings_discovery_failed",
41257
+ sessionId: `agent-settings:${command2.agentId}`
41258
+ });
41259
+ if (socket.readyState === WebSocket2.OPEN) {
41260
+ send(
41261
+ socket,
41262
+ encodeAgentSettingsDiscoveryFailedEvent({
41263
+ code: operationErrorCode(failure2),
41264
+ kind: AGENT_SETTINGS_DISCOVERY_FAILED_KIND,
41265
+ message: operationErrorMessage(failure2),
41266
+ requestId: command2.requestId
41267
+ })
41268
+ );
41269
+ }
41270
+ } finally {
41271
+ timeout.cancel();
41272
+ agentSettingsDiscoveries.delete(command2.requestId);
41273
+ }
41274
+ })();
41275
+ agentSettingsDiscoveries.set(command2.requestId, {
41276
+ agentId: command2.agentId,
41277
+ completion,
41278
+ controller
41279
+ });
41280
+ return;
41281
+ }
41083
41282
  if (kind === NATIVE_SESSION_REQUEST_KIND) {
41084
41283
  const command2 = decodeNativeSessionCommand(encoded);
41085
41284
  const previous2 = [...nativeRequests.values()].filter(
@@ -41464,7 +41663,10 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41464
41663
  });
41465
41664
  } finally {
41466
41665
  connectionController.abort();
41467
- await Promise.all([...nativeRequests.values()].map((request) => request.completion));
41666
+ await Promise.all([
41667
+ ...[...nativeRequests.values()].map((request) => request.completion),
41668
+ ...[...agentSettingsDiscoveries.values()].map((request) => request.completion)
41669
+ ]);
41468
41670
  }
41469
41671
  }
41470
41672
  async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
@@ -41508,7 +41710,31 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41508
41710
  installationAudit
41509
41711
  );
41510
41712
  let connectionEpoch = 0;
41713
+ let automaticIntegrationProvisioningStarted = false;
41714
+ let automaticIntegrationProvisioning = Promise.resolve();
41511
41715
  let connectionAnnounced = false;
41716
+ let catalogPublished = false;
41717
+ let readinessAnnounced = false;
41718
+ const startAutomaticIntegrationProvisioning = () => {
41719
+ if (!connectionAnnounced || !catalogPublished || automaticIntegrationProvisioningStarted) {
41720
+ return;
41721
+ }
41722
+ automaticIntegrationProvisioningStarted = true;
41723
+ automaticIntegrationProvisioning = installDetectedAgentIntegrations(config2, installations, signal).catch(
41724
+ (error62) => {
41725
+ if (!signal.aborted) {
41726
+ console.error("Mobius daemon could not automatically install detected Agent integrations", error62);
41727
+ }
41728
+ }
41729
+ );
41730
+ };
41731
+ const announceReadiness = () => {
41732
+ if (!connectionAnnounced || !catalogPublished || readinessAnnounced) {
41733
+ return;
41734
+ }
41735
+ readinessAnnounced = true;
41736
+ process.stdout.write("Mobius daemon is ready for Agent requests.\n");
41737
+ };
41512
41738
  const announceConnection = () => {
41513
41739
  if (connectionAnnounced) {
41514
41740
  return;
@@ -41522,8 +41748,18 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41522
41748
 
41523
41749
  `
41524
41750
  );
41751
+ announceReadiness();
41752
+ startAutomaticIntegrationProvisioning();
41525
41753
  };
41526
41754
  const catalogPublication = publishAgentCatalogUntilAvailable(config2, diagnostics, signal, timer);
41755
+ void catalogPublication.then(() => {
41756
+ if (signal.aborted) {
41757
+ return;
41758
+ }
41759
+ catalogPublished = true;
41760
+ announceReadiness();
41761
+ startAutomaticIntegrationProvisioning();
41762
+ });
41527
41763
  try {
41528
41764
  await ipc.listen(signal);
41529
41765
  while (!signal.aborted) {
@@ -41569,24 +41805,28 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer) {
41569
41805
  await catalogPublication;
41570
41806
  } finally {
41571
41807
  try {
41572
- await installations.close();
41808
+ await automaticIntegrationProvisioning;
41573
41809
  } finally {
41574
41810
  try {
41575
- await ipc.close();
41811
+ await installations.close();
41576
41812
  } finally {
41577
41813
  try {
41578
- await sessions.close();
41814
+ await ipc.close();
41579
41815
  } finally {
41580
41816
  try {
41581
- sessionStore.close();
41817
+ await sessions.close();
41582
41818
  } finally {
41583
41819
  try {
41584
- grants.close();
41820
+ sessionStore.close();
41585
41821
  } finally {
41586
41822
  try {
41587
- publisher.close();
41823
+ grants.close();
41588
41824
  } finally {
41589
- outbox.close();
41825
+ try {
41826
+ publisher.close();
41827
+ } finally {
41828
+ outbox.close();
41829
+ }
41590
41830
  }
41591
41831
  }
41592
41832
  }