@moxt-ai/mobius 0.0.57 → 0.0.59

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/cli.js CHANGED
@@ -11,7 +11,7 @@ import { mkdir as mkdir5 } from "node:fs/promises";
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "@moxt-ai/mobius",
14
- version: "0.0.57",
14
+ version: "0.0.59",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -38994,6 +38994,25 @@ var RelayConnectionDiagnostics = class {
38994
38994
  addFailureDetails(details, failure2);
38995
38995
  this.#record("relay_connection_failed", connectionEpoch.toString(), details, true);
38996
38996
  };
38997
+ /**
38998
+ * Records that the Runtime gave up on Agent turns the Relay already settled. This is not a connection
38999
+ * failure, so it is recorded independently of the per-epoch failure deduplication.
39000
+ */
39001
+ reconciliationAbandoned = (connectionEpoch, relayErrorCode2, turnCount) => {
39002
+ this.#record(
39003
+ "relay_reconciliation_abandoned",
39004
+ connectionEpoch.toString(),
39005
+ {
39006
+ connectionEpoch: connectionEpoch.toString(),
39007
+ relayErrorCode: relayErrorCode2 ?? "unknown",
39008
+ relayOrigin: this.#relayOrigin,
39009
+ source: "reconciliation_abandoned",
39010
+ turnCount: turnCount.toString(),
39011
+ ...this.#route
39012
+ },
39013
+ true
39014
+ );
39015
+ };
38997
39016
  connectionOpened = (connectionEpoch) => {
38998
39017
  this.#record(
38999
39018
  "relay_connection_opened",
@@ -39940,11 +39959,34 @@ var ActiveDaemonTurn = class {
39940
39959
  };
39941
39960
  var ActiveTurnReconciliationError = class extends Error {
39942
39961
  code = "active_turn_reconciliation_failed";
39962
+ diagnosticDetails;
39963
+ relayErrorCode;
39964
+ terminal;
39943
39965
  constructor(message, options = {}) {
39944
39966
  super(message, options);
39945
39967
  this.name = "ActiveTurnReconciliationError";
39968
+ this.relayErrorCode = options.relayErrorCode ?? null;
39969
+ this.terminal = options.terminal ?? false;
39970
+ this.diagnosticDetails = this.relayErrorCode === null ? {} : { relayErrorCode: this.relayErrorCode };
39946
39971
  }
39947
39972
  };
39973
+ var TERMINAL_RECONCILIATION_RELAY_CODES = /* @__PURE__ */ new Set(["session_conflict"]);
39974
+ async function relayErrorCode(response) {
39975
+ try {
39976
+ const body = JSON.parse(await response.text());
39977
+ if (typeof body !== "object" || body === null) {
39978
+ return null;
39979
+ }
39980
+ const error62 = Reflect.get(body, "error");
39981
+ if (typeof error62 !== "object" || error62 === null) {
39982
+ return null;
39983
+ }
39984
+ const code = Reflect.get(error62, "code");
39985
+ return typeof code === "string" && code.length > 0 ? code : null;
39986
+ } catch {
39987
+ return null;
39988
+ }
39989
+ }
39948
39990
  function activeTurnReconciliationEndpoint(config2, turn) {
39949
39991
  const endpoint = relayHttpEndpoint(config2.relayUrl);
39950
39992
  let channelPath = "";
@@ -39982,12 +40024,15 @@ async function reconcileActiveTurn(config2, turn, signal) {
39982
40024
  { cause: error62 }
39983
40025
  );
39984
40026
  }
39985
- await response.body?.cancel();
39986
40027
  if (!response.ok) {
40028
+ const errorCode = await relayErrorCode(response);
40029
+ const terminal = errorCode !== null && TERMINAL_RECONCILIATION_RELAY_CODES.has(errorCode);
39987
40030
  throw new ActiveTurnReconciliationError(
39988
- `The Relay rejected the active Agent turn reconciliation with status ${response.status.toString()}`
40031
+ terminal ? `The Relay reported that the active Agent turn can no longer be reconciled (${errorCode})` : `The Relay rejected the active Agent turn reconciliation with status ${response.status.toString()}`,
40032
+ { relayErrorCode: errorCode, terminal }
39989
40033
  );
39990
40034
  }
40035
+ await response.body?.cancel();
39991
40036
  }
39992
40037
  async function reconcileActiveTurns(config2, turns, signal) {
39993
40038
  await Promise.all(turns.map(async (turn) => await reconcileActiveTurn(config2, turn, signal)));
@@ -41070,9 +41115,24 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
41070
41115
  );
41071
41116
  }
41072
41117
  }
41118
+ async function retainStillInstalledAgents(previous2, refreshed, signal) {
41119
+ const refreshedIdentifiers = new Set(refreshed.map((agent) => agent.id));
41120
+ const retained = [];
41121
+ for (const agent of previous2) {
41122
+ if (refreshedIdentifiers.has(agent.id)) {
41123
+ continue;
41124
+ }
41125
+ signal.throwIfAborted();
41126
+ if (await revalidateExecutable(agent.agentIdentity)) {
41127
+ retained.push(agent);
41128
+ }
41129
+ }
41130
+ return Object.freeze([...refreshed, ...retained]);
41131
+ }
41073
41132
  async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
41074
41133
  signal.throwIfAborted();
41075
- const environment = await resolveEnvironment(signal);
41134
+ const shellEnvironment = await resolveEnvironment(signal);
41135
+ const environment = new DaemonLocalContext(config2.localContext.stateDirectory, shellEnvironment).environment;
41076
41136
  signal.throwIfAborted();
41077
41137
  const inventory = await discoverLocalAgentInventory({
41078
41138
  defaultWorkspace: config2.defaultWorkspace,
@@ -41080,9 +41140,12 @@ async function refreshAgentCatalog(config2, resolveEnvironment, signal) {
41080
41140
  signal
41081
41141
  });
41082
41142
  const previousCatalog = config2.catalog.read();
41143
+ const refreshedAgents = inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment));
41144
+ const agents = await retainStillInstalledAgents(previousCatalog.agents, refreshedAgents, signal);
41145
+ const verifiedIdentifiers = new Set(agents.map((agent) => agent.id));
41083
41146
  config2.catalog.transition(
41084
- inventory.readyAgents().map((agent) => withDaemonEnvironment(agent, environment)),
41085
- inventory.installable
41147
+ agents,
41148
+ inventory.installable.filter((agent) => !verifiedIdentifiers.has(agent.id))
41086
41149
  );
41087
41150
  try {
41088
41151
  await publishAgentCatalog(config2, signal);
@@ -41984,6 +42047,24 @@ async function runRelayConnection(config2, directories, audit, sessions, install
41984
42047
  return;
41985
42048
  }
41986
42049
  console.error("Mobius daemon could not reconcile active Agent turns", error62);
42050
+ if (error62 instanceof ActiveTurnReconciliationError && error62.terminal) {
42051
+ diagnostics.reconciliationAbandoned(
42052
+ connectionEpoch,
42053
+ error62.relayErrorCode,
42054
+ reconnectingTurns.length
42055
+ );
42056
+ console.error(
42057
+ "Mobius daemon abandoned Agent turns the Relay already settled",
42058
+ error62.relayErrorCode
42059
+ );
42060
+ for (const turn of reconnectingTurns) {
42061
+ activeTurns.delete(turn.command.commandId);
42062
+ turn.abortDaemon();
42063
+ }
42064
+ publisher.connect(socket);
42065
+ resumeRuntimeDeliveries();
42066
+ return;
42067
+ }
41987
42068
  failAndClose(
41988
42069
  new Error("Active Agent turn reconciliation failed", { cause: error62 }),
41989
42070
  ACTIVE_TURN_RECONCILIATION_CLOSE_CODE,