@moxt-ai/mobius 0.0.93 → 0.0.94

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 (54) hide show
  1. package/dist/acp/activity.js +1 -1
  2. package/dist/acp/activity.js.map +1 -1
  3. package/dist/acp/codex/agent.d.ts.map +1 -1
  4. package/dist/acp/codex/agent.js +4 -8
  5. package/dist/acp/codex/agent.js.map +1 -1
  6. package/dist/acp/session-manager.d.ts +5 -3
  7. package/dist/acp/session-manager.d.ts.map +1 -1
  8. package/dist/acp/session-manager.js +77 -5
  9. package/dist/acp/session-manager.js.map +1 -1
  10. package/dist/acp/session-store.d.ts +3 -10
  11. package/dist/acp/session-store.d.ts.map +1 -1
  12. package/dist/acp/session-store.js +1 -131
  13. package/dist/acp/session-store.js.map +1 -1
  14. package/dist/audit/audit-store.d.ts +3 -4
  15. package/dist/audit/audit-store.d.ts.map +1 -1
  16. package/dist/audit/audit-store.js +10 -37
  17. package/dist/audit/audit-store.js.map +1 -1
  18. package/dist/cli.js +333 -326
  19. package/dist/cli.js.map +3 -3
  20. package/dist/config.d.ts +0 -2
  21. package/dist/config.d.ts.map +1 -1
  22. package/dist/config.js +0 -4
  23. package/dist/config.js.map +1 -1
  24. package/dist/daemon-manager.d.ts.map +1 -1
  25. package/dist/daemon-manager.js +13 -19
  26. package/dist/daemon-manager.js.map +1 -1
  27. package/dist/index.js +270 -264
  28. package/dist/index.js.map +3 -3
  29. package/dist/native-sessions/service.d.ts.map +1 -1
  30. package/dist/native-sessions/service.js +75 -4
  31. package/dist/native-sessions/service.js.map +1 -1
  32. package/dist/pairing/pair-local-machine.d.ts.map +1 -1
  33. package/dist/pairing/pair-local-machine.js +0 -1
  34. package/dist/pairing/pair-local-machine.js.map +1 -1
  35. package/dist/relay-connection/coalescing-narration-publisher.d.ts +1 -1
  36. package/dist/relay-connection/coalescing-narration-publisher.js +1 -1
  37. package/dist/relay-connection/coalescing-text-publisher.d.ts +1 -1
  38. package/dist/relay-connection/coalescing-text-publisher.js +1 -1
  39. package/dist/relay-connection/session-event-outbox.d.ts +4 -5
  40. package/dist/relay-connection/session-event-outbox.d.ts.map +1 -1
  41. package/dist/relay-connection/session-event-outbox.js +31 -21
  42. package/dist/relay-connection/session-event-outbox.js.map +1 -1
  43. package/dist/run-daemon.d.ts.map +1 -1
  44. package/dist/run-daemon.js +13 -19
  45. package/dist/run-daemon.js.map +1 -1
  46. package/dist/runtime.d.ts +0 -1
  47. package/dist/runtime.d.ts.map +1 -1
  48. package/dist/runtime.js +264 -256
  49. package/dist/runtime.js.map +3 -3
  50. package/dist/storage/runtime-installation-store.d.ts +0 -1
  51. package/dist/storage/runtime-installation-store.d.ts.map +1 -1
  52. package/dist/storage/runtime-installation-store.js +0 -1
  53. package/dist/storage/runtime-installation-store.js.map +1 -1
  54. package/package.json +1 -1
package/dist/runtime.js CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all2) => {
6
6
 
7
7
  // src/runtime.ts
8
8
  import { mkdir as mkdir6, realpath as realpath10, stat as stat9 } from "node:fs/promises";
9
- import { dirname as dirname8, join as join18, resolve as resolve7 } from "node:path";
9
+ import { resolve as resolve7 } from "node:path";
10
10
 
11
11
  // src/agent-catalog/local-agent.ts
12
12
  import { realpathSync, statSync } from "node:fs";
@@ -21687,18 +21687,17 @@ function effortValues(model) {
21687
21687
  }
21688
21688
  function modelSetting(models, currentValue) {
21689
21689
  const values = modelValues(models);
21690
- const current = currentValue.length > 0 ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
21690
+ const current = values.some((value) => value.value === currentValue) ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
21691
21691
  if (current.length === 0) {
21692
21692
  return null;
21693
21693
  }
21694
- const options = values.some((value) => value.value === current) ? values : [{ description: "", name: current, value: current }, ...values];
21695
21694
  return {
21696
21695
  category: "model",
21697
21696
  currentValue: current,
21698
21697
  description: "Model Codex uses for the session",
21699
21698
  id: MODEL_SETTING_ID,
21700
21699
  name: "Model",
21701
- options,
21700
+ options: values,
21702
21701
  type: "select"
21703
21702
  };
21704
21703
  }
@@ -24324,51 +24323,20 @@ async function discoverLocalAgentInventory(options) {
24324
24323
  }
24325
24324
 
24326
24325
  // src/audit/audit-store.ts
24327
- import { mkdirSync } from "node:fs";
24328
- import { dirname as dirname3 } from "node:path";
24329
- import { DatabaseSync } from "node:sqlite";
24326
+ var MAX_AUDIT_RECORDS = 1024;
24330
24327
  var AuditStore = class {
24331
- database;
24332
- constructor(path2) {
24333
- mkdirSync(dirname3(path2), { recursive: true });
24334
- this.database = new DatabaseSync(path2);
24335
- this.database.exec(`
24336
- CREATE TABLE IF NOT EXISTS audit_events (
24337
- id INTEGER PRIMARY KEY AUTOINCREMENT,
24338
- recorded_at TEXT NOT NULL,
24339
- event TEXT NOT NULL,
24340
- command_id TEXT NOT NULL,
24341
- session_id TEXT NOT NULL,
24342
- details_json TEXT NOT NULL DEFAULT '{}'
24343
- ) STRICT
24344
- `);
24345
- const columns = this.database.prepare("PRAGMA table_info(audit_events)").all();
24346
- if (!columns.some((column) => Reflect.get(column, "name") === "details_json")) {
24347
- this.database.exec("ALTER TABLE audit_events ADD COLUMN details_json TEXT NOT NULL DEFAULT '{}'");
24348
- }
24349
- }
24350
- record(record2) {
24351
- this.database.prepare(
24352
- `
24353
- INSERT INTO audit_events (
24354
- recorded_at,
24355
- event,
24356
- command_id,
24357
- session_id,
24358
- details_json
24359
- ) VALUES (?, ?, ?, ?, ?)
24360
- `
24361
- ).run(
24362
- (/* @__PURE__ */ new Date()).toISOString(),
24363
- record2.event,
24364
- record2.commandId,
24365
- record2.sessionId,
24366
- JSON.stringify(record2.details ?? {})
24328
+ #records = [];
24329
+ record = (record2) => {
24330
+ if (this.#records.length === MAX_AUDIT_RECORDS) {
24331
+ this.#records.shift();
24332
+ }
24333
+ this.#records.push(
24334
+ record2.details === void 0 ? { ...record2 } : { ...record2, details: { ...record2.details } }
24367
24335
  );
24368
- }
24369
- close() {
24370
- this.database.close();
24371
- }
24336
+ };
24337
+ close = () => {
24338
+ this.#records.length = 0;
24339
+ };
24372
24340
  };
24373
24341
 
24374
24342
  // src/config.ts
@@ -25676,6 +25644,8 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
25676
25644
  title: external_exports.string().max(500)
25677
25645
  }).readonly();
25678
25646
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
25647
+ external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
25648
+ external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
25679
25649
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
25680
25650
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
25681
25651
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -25697,6 +25667,8 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
25697
25667
  }).readonly()
25698
25668
  ]);
25699
25669
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
25670
+ external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
25671
+ external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
25700
25672
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
25701
25673
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
25702
25674
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -25725,7 +25697,7 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
25725
25697
  ]);
25726
25698
  var nativeSessionEntrySchema = external_exports.strictObject({
25727
25699
  entryId: identifier,
25728
- mobiusSessionIds: external_exports.array(identifier).max(500).readonly(),
25700
+ nativeSessionId: identifier,
25729
25701
  title: external_exports.string().max(500),
25730
25702
  directoryId,
25731
25703
  directoryLabel: external_exports.string().min(1).max(2048),
@@ -25737,6 +25709,18 @@ var resultEnvelope = {
25737
25709
  kind: external_exports.literal(NATIVE_SESSION_RESULT_KIND)
25738
25710
  };
25739
25711
  var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
25712
+ external_exports.strictObject({ ...resultEnvelope, action: external_exports.literal("create"), nativeSessionId: identifier }).readonly(),
25713
+ external_exports.strictObject({
25714
+ ...resultEnvelope,
25715
+ action: external_exports.literal("linked-history"),
25716
+ targetSessionId: identifier,
25717
+ history: sessionHistorySchema
25718
+ }).readonly(),
25719
+ external_exports.strictObject({
25720
+ ...resultEnvelope,
25721
+ action: external_exports.literal("unlinked-history"),
25722
+ targetSessionId: identifier
25723
+ }).readonly(),
25740
25724
  external_exports.strictObject({
25741
25725
  ...resultEnvelope,
25742
25726
  action: external_exports.literal("find"),
@@ -26284,7 +26268,6 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
26284
26268
  return {
26285
26269
  agents: daemonAgents,
26286
26270
  defaultWorkspace: connection.defaultWorkspace,
26287
- auditDatabasePath: connection.auditDatabasePath,
26288
26271
  bindingId: "workspace",
26289
26272
  catalog: new LocalAgentCatalog(daemonAgents, installableAgents),
26290
26273
  channelId: connection.channelId,
@@ -26296,7 +26279,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
26296
26279
  }
26297
26280
 
26298
26281
  // src/run-daemon.ts
26299
- import { createHash as createHash3, randomUUID as randomUUID3 } from "node:crypto";
26282
+ import { createHash as createHash4, randomUUID as randomUUID3 } from "node:crypto";
26300
26283
  import { basename as basename6 } from "node:path";
26301
26284
  import { styleText } from "node:util";
26302
26285
  import { fetch as fetch4, WebSocket as WebSocket2 } from "undici";
@@ -34804,9 +34787,6 @@ var AcpHistoryReplay = class {
34804
34787
  };
34805
34788
 
34806
34789
  // src/acp/session-store.ts
34807
- import { mkdirSync as mkdirSync2 } from "node:fs";
34808
- import { dirname as dirname4 } from "node:path";
34809
- import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
34810
34790
  var AcpStoredSession = class {
34811
34791
  additionalDirectories;
34812
34792
  agentId;
@@ -34839,44 +34819,6 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
34839
34819
  var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
34840
34820
  found = false;
34841
34821
  };
34842
- function readString3(value, field) {
34843
- if (typeof value !== "string" || value.length === 0) {
34844
- throw new Error(`Stored ACP session has an invalid ${field}`);
34845
- }
34846
- return value;
34847
- }
34848
- function readAdditionalDirectories(value) {
34849
- if (typeof value !== "string") {
34850
- throw new Error("Stored ACP session has invalid additional directories");
34851
- }
34852
- const decoded = JSON.parse(value);
34853
- if (!Array.isArray(decoded) || decoded.some((directory) => typeof directory !== "string")) {
34854
- throw new Error("Stored ACP session has invalid additional directories");
34855
- }
34856
- return decoded;
34857
- }
34858
- function readPrompted(value) {
34859
- if (value === 0) {
34860
- return false;
34861
- }
34862
- if (value === 1) {
34863
- return true;
34864
- }
34865
- throw new Error("Stored ACP session has an invalid prompted state");
34866
- }
34867
- function decodeSessionRow(row) {
34868
- if (typeof row !== "object" || row === null || Array.isArray(row)) {
34869
- throw new Error("Stored ACP session is not an object");
34870
- }
34871
- return new AcpStoredSession(
34872
- readString3(Reflect.get(row, "session_id"), "session ID"),
34873
- readString3(Reflect.get(row, "agent_id"), "agent ID"),
34874
- readString3(Reflect.get(row, "native_session_id"), "native session ID"),
34875
- readString3(Reflect.get(row, "cwd"), "working directory"),
34876
- readAdditionalDirectories(Reflect.get(row, "additional_directories_json")),
34877
- readPrompted(Reflect.get(row, "prompted"))
34878
- );
34879
- }
34880
34822
  var MemoryAcpSessionStore = class {
34881
34823
  #sessions = /* @__PURE__ */ new Map();
34882
34824
  #deleted = /* @__PURE__ */ new Set();
@@ -34905,106 +34847,6 @@ var MemoryAcpSessionStore = class {
34905
34847
  this.#sessions.set(session.sessionId, session);
34906
34848
  };
34907
34849
  };
34908
- var SqliteAcpSessionStore = class {
34909
- #database;
34910
- constructor(path2) {
34911
- mkdirSync2(dirname4(path2), { recursive: true });
34912
- this.#database = new DatabaseSync2(path2);
34913
- this.#database.exec(`
34914
- CREATE TABLE IF NOT EXISTS acp_deleted_sessions (session_id TEXT PRIMARY KEY) STRICT;
34915
- CREATE TABLE IF NOT EXISTS acp_sessions (
34916
- session_id TEXT PRIMARY KEY,
34917
- agent_id TEXT NOT NULL,
34918
- native_session_id TEXT NOT NULL,
34919
- cwd TEXT NOT NULL,
34920
- additional_directories_json TEXT NOT NULL,
34921
- prompted INTEGER NOT NULL DEFAULT 0 CHECK (prompted IN (0, 1)),
34922
- updated_at TEXT NOT NULL
34923
- ) STRICT
34924
- `);
34925
- const columns = this.#database.prepare("PRAGMA table_info(acp_sessions)").all();
34926
- const hasPromptedColumn = columns.some(
34927
- (column) => typeof column === "object" && column !== null && Reflect.get(column, "name") === "prompted"
34928
- );
34929
- if (!hasPromptedColumn) {
34930
- this.#database.exec(`
34931
- ALTER TABLE acp_sessions
34932
- ADD COLUMN prompted INTEGER NOT NULL DEFAULT 1 CHECK (prompted IN (0, 1))
34933
- `);
34934
- }
34935
- }
34936
- read = (sessionId) => {
34937
- if (this.#database.prepare("SELECT session_id FROM acp_deleted_sessions WHERE session_id = ?").get(sessionId) !== void 0) {
34938
- return new DeletedAcpStoredSession();
34939
- }
34940
- const row = this.#database.prepare(
34941
- `
34942
- SELECT
34943
- session_id,
34944
- agent_id,
34945
- native_session_id,
34946
- cwd,
34947
- additional_directories_json,
34948
- prompted
34949
- FROM acp_sessions
34950
- WHERE session_id = ?
34951
- `
34952
- ).get(sessionId);
34953
- return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeSessionRow(row));
34954
- };
34955
- remove = (sessionId) => {
34956
- this.#database.prepare("DELETE FROM acp_sessions WHERE session_id = ?").run(sessionId);
34957
- };
34958
- findNative = (agentId, nativeSessionId) => this.#database.prepare("SELECT * FROM acp_sessions WHERE agent_id = ? AND native_session_id = ?").all(agentId, nativeSessionId).map(decodeSessionRow);
34959
- markDeleted = (agentId, nativeSessionId) => {
34960
- const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
34961
- this.#database.exec("BEGIN");
34962
- try {
34963
- for (const id of ids) {
34964
- this.#database.prepare("INSERT OR IGNORE INTO acp_deleted_sessions (session_id) VALUES (?)").run(id);
34965
- this.remove(id);
34966
- }
34967
- this.#database.exec("COMMIT");
34968
- return ids;
34969
- } catch (error62) {
34970
- this.#database.exec("ROLLBACK");
34971
- throw error62;
34972
- }
34973
- };
34974
- write = (session) => {
34975
- this.#database.prepare(
34976
- `
34977
- INSERT INTO acp_sessions (
34978
- session_id,
34979
- agent_id,
34980
- native_session_id,
34981
- cwd,
34982
- additional_directories_json,
34983
- prompted,
34984
- updated_at
34985
- ) VALUES (?, ?, ?, ?, ?, ?, ?)
34986
- ON CONFLICT(session_id) DO UPDATE SET
34987
- agent_id = excluded.agent_id,
34988
- native_session_id = excluded.native_session_id,
34989
- cwd = excluded.cwd,
34990
- additional_directories_json = excluded.additional_directories_json,
34991
- prompted = excluded.prompted,
34992
- updated_at = excluded.updated_at
34993
- `
34994
- ).run(
34995
- session.sessionId,
34996
- session.agentId,
34997
- session.nativeSessionId,
34998
- session.cwd,
34999
- JSON.stringify(session.additionalDirectories),
35000
- session.prompted ? 1 : 0,
35001
- (/* @__PURE__ */ new Date()).toISOString()
35002
- );
35003
- };
35004
- close = () => {
35005
- this.#database.close();
35006
- };
35007
- };
35008
34850
 
35009
34851
  // src/acp/session-manager.ts
35010
34852
  var PROCESS_STOP_TIMEOUT_MILLISECONDS = 1e3;
@@ -35231,7 +35073,7 @@ function truncate4(value, maximumLength) {
35231
35073
  function isRecord7(value) {
35232
35074
  return typeof value === "object" && value !== null && !Array.isArray(value);
35233
35075
  }
35234
- function readString4(value, fallback = "") {
35076
+ function readString3(value, fallback = "") {
35235
35077
  return typeof value === "string" ? value : fallback;
35236
35078
  }
35237
35079
  function arraysEqual(left, right) {
@@ -35264,8 +35106,8 @@ function normalizeElicitationOptions(schema) {
35264
35106
  for (const option of oneOf) {
35265
35107
  if (isRecord7(option) && typeof option["const"] === "string") {
35266
35108
  normalized.push({
35267
- description: truncate4(readString4(option["description"]), 500),
35268
- label: truncate4(readString4(option["title"], option["const"]), 255),
35109
+ description: truncate4(readString3(option["description"]), 500),
35110
+ label: truncate4(readString3(option["title"], option["const"]), 255),
35269
35111
  value: truncate4(option["const"], 500)
35270
35112
  });
35271
35113
  }
@@ -35316,8 +35158,8 @@ function normalizeElicitationFields(requestedSchema) {
35316
35158
  defaultBooleanValue: typeof defaultValue === "boolean" ? defaultValue : false,
35317
35159
  defaultNumberValue: typeof defaultValue === "number" && Number.isFinite(defaultValue) ? defaultValue : 0,
35318
35160
  defaultStringValue: typeof defaultValue === "string" ? truncate4(defaultValue, 1e4) : Array.isArray(defaultValue) ? truncate4(JSON.stringify(defaultValue), 1e4) : "",
35319
- description: truncate4(readString4(property["description"]), 500),
35320
- format: truncate4(readString4(property["format"]), 64),
35161
+ description: truncate4(readString3(property["description"]), 500),
35162
+ format: truncate4(readString3(property["format"]), 64),
35321
35163
  hasDefaultValue: defaultValue !== void 0 && defaultValue !== null,
35322
35164
  maximum: numericString(property["maximum"]),
35323
35165
  maximumLength: numericString(property["maxLength"] ?? property["maxItems"]),
@@ -35325,9 +35167,9 @@ function normalizeElicitationFields(requestedSchema) {
35325
35167
  minimumLength: numericString(property["minLength"] ?? property["minItems"]),
35326
35168
  name: truncate4(name, 128),
35327
35169
  options,
35328
- pattern: truncate4(readString4(property["pattern"]), 500),
35170
+ pattern: truncate4(readString3(property["pattern"]), 500),
35329
35171
  required: required2.has(name),
35330
- title: truncate4(readString4(property["title"], name), 255),
35172
+ title: truncate4(readString3(property["title"], name), 255),
35331
35173
  type: normalizedType
35332
35174
  });
35333
35175
  }
@@ -36166,6 +36008,17 @@ var AcpProcessSession = class _AcpProcessSession {
36166
36008
  );
36167
36009
  };
36168
36010
  nativeSessionId = () => this.#nativeSessionId;
36011
+ adoptNativeSessionId = (sessionId) => {
36012
+ if (this.#prompted || this.#nativeSessionId !== sessionId) {
36013
+ throw new AcpExecutionError("The new Codex Session cannot be adopted", {}, "session_identity_mismatch");
36014
+ }
36015
+ const previousSessionId = this.#mobiusSessionId;
36016
+ this.#store.write(
36017
+ new AcpStoredSession(sessionId, this.#agentId, sessionId, this.#cwd, this.#additionalDirectories, false)
36018
+ );
36019
+ this.#store.remove(previousSessionId);
36020
+ this.#mobiusSessionId = sessionId;
36021
+ };
36169
36022
  configure = async (options) => {
36170
36023
  const existing = this.#configOptions.find((option) => option.id === options.configId);
36171
36024
  if (existing === void 0 || existing.type !== options.valueType) {
@@ -36559,7 +36412,7 @@ var AcpProcessSession = class _AcpProcessSession {
36559
36412
  message: truncate4(request.message, 2e3),
36560
36413
  mode: request.mode,
36561
36414
  sessionId: this.#mobiusSessionId,
36562
- url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate4(readString4(Reflect.get(request, "url")), 4096) : ""
36415
+ url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate4(readString3(Reflect.get(request, "url")), 4096) : ""
36563
36416
  });
36564
36417
  return await pending.completion.promise;
36565
36418
  } finally {
@@ -36919,16 +36772,17 @@ var AcpSessionManager = class {
36919
36772
  #transientProcessCount = 0;
36920
36773
  #store;
36921
36774
  #nativeHistoryReader;
36775
+ #sessionIdentity;
36922
36776
  #observer;
36923
- constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null) {
36777
+ constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null, sessionIdentity = "assigned") {
36924
36778
  this.#observer = observer;
36925
36779
  this.#store = store;
36926
36780
  this.#nativeHistoryReader = nativeHistoryReader;
36781
+ this.#sessionIdentity = sessionIdentity;
36927
36782
  }
36928
36783
  setObserver = (observer) => {
36929
36784
  this.#observer = observer;
36930
36785
  };
36931
- findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
36932
36786
  #notifyProcessCapacityChanged() {
36933
36787
  const changed = this.#processCapacityChanged;
36934
36788
  this.#processCapacityChanged = Promise.withResolvers();
@@ -37036,7 +36890,13 @@ var AcpSessionManager = class {
37036
36890
  if (retained) {
37037
36891
  this.#sessions.delete(sessionId);
37038
36892
  }
37039
- await this.#retireProcess(runtime, retained, close);
36893
+ try {
36894
+ await this.#retireProcess(runtime, retained, close);
36895
+ } finally {
36896
+ if (retained && this.#sessionIdentity === "native") {
36897
+ this.#store.remove(sessionId);
36898
+ }
36899
+ }
37040
36900
  }
37041
36901
  async #retireNativeBrowserProcess(sessionId, runtime, close) {
37042
36902
  const retained = this.#nativeBrowserSessions.get(sessionId) === runtime;
@@ -37183,7 +37043,14 @@ var AcpSessionManager = class {
37183
37043
  try {
37184
37044
  return await this.#startRetainedSessionProcess(
37185
37045
  options,
37186
- async () => await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics)
37046
+ async () => await AcpProcessSession.start(
37047
+ this.#sessionIdentity === "native" && options.agent.id === "codex" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(
37048
+ options.sessionId
37049
+ ) && this.#store.read(options.sessionId) instanceof MissingAcpStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId } } : options,
37050
+ () => this.#observer,
37051
+ this.#store,
37052
+ metrics
37053
+ )
37187
37054
  );
37188
37055
  } finally {
37189
37056
  this.#preparing.delete(options.sessionId);
@@ -37606,6 +37473,45 @@ var AcpSessionManager = class {
37606
37473
  ]);
37607
37474
  };
37608
37475
  hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#sessions.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
37476
+ createNativeSession = async (options) => {
37477
+ const temporarySessionId = `new-${crypto.randomUUID()}`;
37478
+ const temporaryOptions = { ...options, sessionId: temporarySessionId };
37479
+ this.#beginSessionUse(temporarySessionId);
37480
+ try {
37481
+ const runtime = await this.#startPreparation(temporaryOptions);
37482
+ let adopted = false;
37483
+ try {
37484
+ const nativeSessionId = runtime.nativeSessionId();
37485
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(nativeSessionId) || this.#sessions.has(nativeSessionId) || !(this.#store.read(nativeSessionId) instanceof MissingAcpStoredSession)) {
37486
+ throw new AcpExecutionError(
37487
+ "Codex returned an invalid new Session ID",
37488
+ {},
37489
+ "invalid_native_session_response"
37490
+ );
37491
+ }
37492
+ runtime.adoptNativeSessionId(nativeSessionId);
37493
+ this.#sessions.delete(temporarySessionId);
37494
+ this.#sessions.set(nativeSessionId, runtime);
37495
+ this.#retainedProcesses.set(
37496
+ runtime,
37497
+ new FoundAcpSessionProcessEvictionCandidate(nativeSessionId, runtime)
37498
+ );
37499
+ adopted = true;
37500
+ return nativeSessionId;
37501
+ } finally {
37502
+ if (!adopted) {
37503
+ await this.#retireSessionProcess(
37504
+ temporarySessionId,
37505
+ runtime,
37506
+ async () => await runtime.closeProcess()
37507
+ );
37508
+ }
37509
+ }
37510
+ } finally {
37511
+ this.#store.remove(temporarySessionId);
37512
+ this.#endSessionUse(temporarySessionId);
37513
+ }
37514
+ };
37609
37515
  ensureSession = async (options) => {
37610
37516
  const existing = this.#sessions.get(options.sessionId);
37611
37517
  if (existing !== void 0) {
@@ -37699,6 +37605,25 @@ var AcpSessionManager = class {
37699
37605
  this.#endSessionUse(options.sessionId);
37700
37606
  }
37701
37607
  };
37608
+ loadLinkedSessionHistory = async (options) => {
37609
+ options.signal.throwIfAborted();
37610
+ const stored = this.#store.read(options.sessionId);
37611
+ if (!(stored instanceof FoundAcpStoredSession) || !stored.session.prompted) {
37612
+ return null;
37613
+ }
37614
+ const linked = stored.session;
37615
+ if (linked.agentId !== options.agent.id || linked.cwd !== options.cwd || linked.additionalDirectories.length !== options.additionalDirectories.length || linked.additionalDirectories.some((directory, index2) => directory !== options.additionalDirectories[index2])) {
37616
+ throw new AcpExecutionError(
37617
+ "The session belongs to another Agent or workspace",
37618
+ {},
37619
+ "session_identity_mismatch"
37620
+ );
37621
+ }
37622
+ if (this.#nativeHistoryReader === null) {
37623
+ return await this.loadSessionHistory(options);
37624
+ }
37625
+ return await this.#nativeHistoryReader.read(options, linked.nativeSessionId);
37626
+ };
37702
37627
  openNativeSession = async (options, origin, loadHistory) => {
37703
37628
  const key = `${options.agent.id}:${origin.nativeSessionId}`;
37704
37629
  if (this.#nativeOperations.has(key)) {
@@ -38762,7 +38687,7 @@ var LocalAuthorizationError = class extends Error {
38762
38687
  // src/authorization/workspace-directory.ts
38763
38688
  import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
38764
38689
  import { homedir as homedir2 } from "node:os";
38765
- import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute10, join as join15, normalize as normalize4, relative as relative4 } from "node:path";
38690
+ import { basename as basename4, dirname as dirname3, isAbsolute as isAbsolute10, join as join15, normalize as normalize4, relative as relative4 } from "node:path";
38766
38691
  var WorkspaceDirectoryListing = class {
38767
38692
  directoryId;
38768
38693
  directoryLabel;
@@ -38886,7 +38811,7 @@ var WorkspaceDirectoryService = class {
38886
38811
  }
38887
38812
  }
38888
38813
  entries.sort((a, b) => a.name.localeCompare(b.name));
38889
- const parent = dirname5(target);
38814
+ const parent = dirname3(target);
38890
38815
  return new WorkspaceDirectoryListing(
38891
38816
  id,
38892
38817
  this.label(target),
@@ -38911,7 +38836,7 @@ var WorkspaceDirectoryService = class {
38911
38836
  };
38912
38837
 
38913
38838
  // src/daemon-diagnostic-log.ts
38914
- import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
38839
+ import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
38915
38840
  import { join as join16 } from "node:path";
38916
38841
  var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
38917
38842
  var DaemonDiagnosticLog = class {
@@ -38927,7 +38852,7 @@ var DaemonDiagnosticLog = class {
38927
38852
  const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
38928
38853
  `;
38929
38854
  const encodedBytes = Buffer.byteLength(encoded);
38930
- mkdirSync3(this.#directory, { mode: 448, recursive: true });
38855
+ mkdirSync(this.#directory, { mode: 448, recursive: true });
38931
38856
  let existingBytes = 0;
38932
38857
  try {
38933
38858
  existingBytes = statSync3(this.#path).size;
@@ -39416,6 +39341,84 @@ var NativeSessionService = class {
39416
39341
  sessionId: command.sessionId,
39417
39342
  signal
39418
39343
  };
39344
+ if (command.action === "linked-history") {
39345
+ if (options.agent.id !== "codex") {
39346
+ const history = await this.#sessions.loadLinkedSessionHistory({
39347
+ ...options,
39348
+ sessionId: command.targetSessionId
39349
+ });
39350
+ this.record(command, "native_session_history_read");
39351
+ return history === null ? {
39352
+ action: "unlinked-history",
39353
+ kind: "native.session.result",
39354
+ requestId: command.requestId,
39355
+ sessionId: command.sessionId,
39356
+ targetSessionId: command.targetSessionId
39357
+ } : {
39358
+ action: "linked-history",
39359
+ history,
39360
+ kind: "native.session.result",
39361
+ requestId: command.requestId,
39362
+ sessionId: command.sessionId,
39363
+ targetSessionId: command.targetSessionId
39364
+ };
39365
+ }
39366
+ const nativeSessionId = nativeSessionIdSchema.parse(command.targetSessionId);
39367
+ if (this.#sessions.hasPreparedSession(nativeSessionId, options.agent.id, cwd, additionalDirectories) && await this.#sessions.loadLinkedSessionHistory({ ...options, sessionId: nativeSessionId }) === null) {
39368
+ this.record(command, "native_session_history_read");
39369
+ return {
39370
+ action: "linked-history",
39371
+ history: {
39372
+ status: "available",
39373
+ messages: [],
39374
+ truncated: false,
39375
+ coveredCommandIds: [],
39376
+ coveredMessageIds: []
39377
+ },
39378
+ kind: "native.session.result",
39379
+ requestId: command.requestId,
39380
+ sessionId: command.sessionId,
39381
+ targetSessionId: command.targetSessionId
39382
+ };
39383
+ }
39384
+ const snapshot = await readCodexFullHistory(options.agent, cwd, nativeSessionId, signal);
39385
+ const resolved = await this.#directories.identify(command.bindingId, snapshot.cwd, signal);
39386
+ if (snapshot.nativeSessionId !== nativeSessionId || resolved.path !== cwd) {
39387
+ throw new AcpExecutionError(
39388
+ "Codex returned history for a different session or workspace.",
39389
+ {},
39390
+ "invalid_native_session_response"
39391
+ );
39392
+ }
39393
+ this.record(command, "native_session_history_read");
39394
+ return {
39395
+ action: "linked-history",
39396
+ history: snapshot.history,
39397
+ kind: "native.session.result",
39398
+ requestId: command.requestId,
39399
+ sessionId: command.sessionId,
39400
+ targetSessionId: command.targetSessionId
39401
+ };
39402
+ }
39403
+ if (command.action === "create") {
39404
+ if (options.agent.id !== "codex") {
39405
+ throw new AcpExecutionError(
39406
+ "Native session creation is unavailable for this Agent",
39407
+ {},
39408
+ "native_session_unsupported"
39409
+ );
39410
+ }
39411
+ const nativeSessionId = await this.#sessions.createNativeSession(options);
39412
+ signal.throwIfAborted();
39413
+ this.record(command, "native_session_created");
39414
+ return {
39415
+ action: "create",
39416
+ kind: "native.session.result",
39417
+ nativeSessionId,
39418
+ requestId: command.requestId,
39419
+ sessionId: command.sessionId
39420
+ };
39421
+ }
39419
39422
  const prepared = await this.#sessions.prepareNativeSessionBrowser(options);
39420
39423
  if (!prepared.capabilities.listSessions) {
39421
39424
  throw new AcpExecutionError(
@@ -39443,7 +39446,7 @@ var NativeSessionService = class {
39443
39446
  });
39444
39447
  return {
39445
39448
  entryId,
39446
- mobiusSessionIds: this.#sessions.findLinkedSessions(command.agentId, info.sessionId).filter((session) => session.prompted && session.cwd === authorized.cwd).map((session) => session.sessionId),
39449
+ nativeSessionId: info.sessionId,
39447
39450
  title: info.title ?? "Untitled session",
39448
39451
  directoryId: authorized.directoryId,
39449
39452
  directoryLabel: authorized.directoryLabel,
@@ -40548,26 +40551,26 @@ var RelayConnectionLiveness = class {
40548
40551
  };
40549
40552
 
40550
40553
  // src/relay-connection/session-event-outbox.ts
40551
- import { mkdirSync as mkdirSync4 } from "node:fs";
40552
- import { dirname as dirname6 } from "node:path";
40553
- import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
40554
+ import { createHash as createHash3 } from "node:crypto";
40555
+ import { DatabaseSync } from "node:sqlite";
40554
40556
  var DEFAULT_OUTBOX_LIMITS = {
40555
40557
  criticalEventBytes: 136 * 1024 * 1024,
40556
40558
  runtimeDeliveryBytes: 64 * 1024 * 1024,
40557
40559
  runtimeDeliveryCount: 64,
40558
40560
  standardEventBytes: 128 * 1024 * 1024
40559
40561
  };
40562
+ var MAX_TERMINAL_RECEIPTS = 1024;
40560
40563
  var SessionEventOutboxCapacityError = class extends Error {
40561
40564
  code = "session_event_outbox_full";
40562
40565
  constructor() {
40563
- super("The durable Session event outbox is full");
40566
+ super("The in-memory Session event outbox is full");
40564
40567
  this.name = "SessionEventOutboxCapacityError";
40565
40568
  }
40566
40569
  };
40567
40570
  var RuntimeDeliveryInboxCapacityError = class extends Error {
40568
40571
  code = "runtime_delivery_inbox_full";
40569
40572
  constructor() {
40570
- super("The durable Runtime delivery inbox is full");
40573
+ super("The in-memory Runtime delivery inbox is full");
40571
40574
  this.name = "RuntimeDeliveryInboxCapacityError";
40572
40575
  }
40573
40576
  };
@@ -40612,11 +40615,10 @@ function rowString(row, field) {
40612
40615
  var SessionEventOutbox = class {
40613
40616
  #database;
40614
40617
  #limits;
40615
- constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
40618
+ constructor(limits = DEFAULT_OUTBOX_LIMITS) {
40616
40619
  validateLimits(limits);
40617
40620
  this.#limits = limits;
40618
- mkdirSync4(dirname6(path2), { recursive: true });
40619
- this.#database = new DatabaseSync3(path2);
40621
+ this.#database = new DatabaseSync(":memory:");
40620
40622
  this.#database.exec(`
40621
40623
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
40622
40624
  ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -40644,7 +40646,7 @@ var SessionEventOutbox = class {
40644
40646
  CREATE TABLE IF NOT EXISTS relay_turn_receipts (
40645
40647
  command_id TEXT PRIMARY KEY,
40646
40648
  session_id TEXT NOT NULL,
40647
- command_json TEXT NOT NULL,
40649
+ command_hash TEXT NOT NULL,
40648
40650
  attempt_id TEXT NOT NULL,
40649
40651
  state TEXT NOT NULL CHECK (
40650
40652
  state IN ('dispatching', 'running', 'succeeded', 'failed', 'cancelled')
@@ -40675,19 +40677,20 @@ var SessionEventOutbox = class {
40675
40677
  `);
40676
40678
  }
40677
40679
  claimExecution = (commandId, sessionId, commandJson) => {
40680
+ const commandHash = createHash3("sha256").update(commandJson).digest("hex");
40678
40681
  this.#database.exec("BEGIN IMMEDIATE");
40679
40682
  try {
40680
40683
  const existing = this.#database.prepare(
40681
- `SELECT session_id, command_json, attempt_id, state
40684
+ `SELECT session_id, command_hash, attempt_id, state
40682
40685
  FROM relay_turn_receipts WHERE command_id = ?`
40683
40686
  ).get(commandId);
40684
40687
  if (typeof existing === "object" && existing !== null) {
40685
40688
  const storedSessionId = Reflect.get(existing, "session_id");
40686
- const storedCommand = Reflect.get(existing, "command_json");
40689
+ const storedCommandHash = Reflect.get(existing, "command_hash");
40687
40690
  const attemptId2 = Reflect.get(existing, "attempt_id");
40688
40691
  const state = Reflect.get(existing, "state");
40689
- if (storedSessionId !== sessionId || storedCommand !== commandJson || typeof attemptId2 !== "string" || !isDaemonExecutionState(state)) {
40690
- throw new Error("The daemon command identity conflicts with its durable receipt");
40692
+ if (storedSessionId !== sessionId || storedCommandHash !== commandHash || typeof attemptId2 !== "string" || !isDaemonExecutionState(state)) {
40693
+ throw new Error("The daemon command identity conflicts with its in-memory receipt");
40691
40694
  }
40692
40695
  this.#database.exec("COMMIT");
40693
40696
  return { attemptId: attemptId2, commandId, kind: "duplicate", state };
@@ -40695,9 +40698,9 @@ var SessionEventOutbox = class {
40695
40698
  const attemptId = crypto.randomUUID();
40696
40699
  this.#database.prepare(
40697
40700
  `INSERT INTO relay_turn_receipts (
40698
- command_id, session_id, command_json, attempt_id, state
40701
+ command_id, session_id, command_hash, attempt_id, state
40699
40702
  ) VALUES (?, ?, ?, ?, 'dispatching')`
40700
- ).run(commandId, sessionId, commandJson, attemptId);
40703
+ ).run(commandId, sessionId, commandHash, attemptId);
40701
40704
  this.#database.exec("COMMIT");
40702
40705
  return {
40703
40706
  attemptId,
@@ -40724,11 +40727,21 @@ var SessionEventOutbox = class {
40724
40727
  throw new Error("The daemon execution transition is invalid");
40725
40728
  }
40726
40729
  this.#database.prepare(`UPDATE relay_turn_receipts SET state = ? WHERE command_id = ?`).run(state, commandId);
40730
+ if (state === "succeeded" || state === "failed" || state === "cancelled") {
40731
+ this.#database.prepare(
40732
+ `DELETE FROM relay_turn_receipts
40733
+ WHERE state IN ('succeeded', 'failed', 'cancelled')
40734
+ AND rowid NOT IN (
40735
+ SELECT rowid FROM relay_turn_receipts
40736
+ WHERE state IN ('succeeded', 'failed', 'cancelled')
40737
+ ORDER BY rowid DESC LIMIT ?
40738
+ )`
40739
+ ).run(MAX_TERMINAL_RECEIPTS);
40740
+ }
40727
40741
  };
40728
40742
  /**
40729
- * The Attempt this Runtime durably claimed for a command, when that Attempt never reached a
40730
- * terminal state. A restarted Runtime has no in-memory Turn for a command it was executing before
40731
- * the restart, so this is the only record of the Attempt identity the Relay is still waiting on.
40743
+ * The Attempt this live Runtime claimed for a command that has not reached a terminal state.
40744
+ * Receipts disappear when the daemon process exits.
40732
40745
  */
40733
40746
  findUnsettledAttemptId = (commandId, sessionId) => {
40734
40747
  const row = this.#database.prepare(`SELECT attempt_id, state FROM relay_turn_receipts WHERE command_id = ? AND session_id = ?`).get(commandId, sessionId);
@@ -40777,7 +40790,7 @@ var SessionEventOutbox = class {
40777
40790
  WHERE event_id = ? AND session_id = ?`
40778
40791
  ).run(rejection.eventId, rejection.sessionId);
40779
40792
  if (deletion.changes !== 1) {
40780
- throw new Error("The rejected session event could not be removed from the durable outbox");
40793
+ throw new Error("The rejected session event could not be removed from the in-memory outbox");
40781
40794
  }
40782
40795
  this.#decrementEventState(byteLength);
40783
40796
  this.#database.exec("COMMIT");
@@ -40796,7 +40809,7 @@ var SessionEventOutbox = class {
40796
40809
  enqueueCritical = (sessionId, payload, attemptId = "") => this.#enqueueBounded(sessionId, payload, attemptId, this.#limits.criticalEventBytes);
40797
40810
  /**
40798
40811
  * Bytes still available to standard Session events. The daemon uses this to shed
40799
- * superseded streaming events instead of filling the durable outbox, so a long Turn
40812
+ * superseded streaming events instead of filling the in-memory outbox, so a long Turn
40800
40813
  * behind a slow Relay cannot make the next enqueue throw.
40801
40814
  */
40802
40815
  standardCapacityRemaining = () => {
@@ -40821,7 +40834,7 @@ var SessionEventOutbox = class {
40821
40834
  const payload = rowString(existing, "payload_json");
40822
40835
  const state = runtimeDeliveryState(existing);
40823
40836
  if (sessionId !== delivery.sessionId || payload !== delivery.payload) {
40824
- throw new Error("The Runtime delivery identity conflicts with its durable receipt");
40837
+ throw new Error("The Runtime delivery identity conflicts with its in-memory receipt");
40825
40838
  }
40826
40839
  this.#database.exec("COMMIT");
40827
40840
  return new StoredRuntimeDelivery(delivery.deliveryId, sessionId, payload, state, true);
@@ -40989,7 +41002,7 @@ var SessionEventOutbox = class {
40989
41002
  WHERE event_id = ? AND session_id = ?`
40990
41003
  ).run(eventId, sessionId);
40991
41004
  if (deletion.changes !== 1) {
40992
- throw new Error("The acknowledged session event could not be removed from the durable outbox");
41005
+ throw new Error("The acknowledged session event could not be removed from the in-memory outbox");
40993
41006
  }
40994
41007
  this.#decrementEventState(byteLength);
40995
41008
  this.#database.exec("COMMIT");
@@ -41471,7 +41484,7 @@ var DaemonSessionEventPublisher = class {
41471
41484
  };
41472
41485
  /**
41473
41486
  * Enqueue a standard event, shedding it instead of ending the daemon when the
41474
- * durable outbox is full.
41487
+ * in-memory outbox is full.
41475
41488
  *
41476
41489
  * A capacity error used to escape the coalescing timer that publishes activities,
41477
41490
  * so the process exited and every restart died on the same retained backlog. A full
@@ -41514,7 +41527,7 @@ var DaemonSessionEventPublisher = class {
41514
41527
  return;
41515
41528
  }
41516
41529
  this.#shedEventKinds.add(kind);
41517
- console.warn(`Mobius daemon is dropping durable "${kind}" events because the Session event outbox is full`);
41530
+ console.warn(`Mobius daemon is dropping queued "${kind}" events because the Session event outbox is full`);
41518
41531
  };
41519
41532
  acknowledge = (acknowledgement) => {
41520
41533
  if (!this.#outbox.acknowledge(acknowledgement)) {
@@ -42028,7 +42041,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
42028
42041
  unsupportedModelIds: modelEffort.unsupportedModelIds,
42029
42042
  valuesByModel: {}
42030
42043
  };
42031
- return createHash3("sha256").update(
42044
+ return createHash4("sha256").update(
42032
42045
  JSON.stringify({
42033
42046
  adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
42034
42047
  agentId: agent.id,
@@ -43023,7 +43036,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
43023
43036
  if (connectionController.signal.aborted) {
43024
43037
  return;
43025
43038
  }
43026
- console.error("Mobius daemon could not process a durable Runtime delivery", error62);
43039
+ console.error("Mobius daemon could not process a in-memory Runtime delivery", error62);
43027
43040
  failAndClose(
43028
43041
  new Error("Runtime delivery processing failed", { cause: error62 }),
43029
43042
  4008,
@@ -43826,8 +43839,8 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
43826
43839
  publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
43827
43840
  stateDirectory
43828
43841
  });
43829
- const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
43830
- const outbox = new SessionEventOutbox(config2.auditDatabasePath);
43842
+ const sessionStore = new MemoryAcpSessionStore();
43843
+ const outbox = new SessionEventOutbox();
43831
43844
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
43832
43845
  const activeTurns = /* @__PURE__ */ new Map();
43833
43846
  const activeAttemptIds = /* @__PURE__ */ new Map();
@@ -43839,9 +43852,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
43839
43852
  }
43840
43853
  publisher.recordAttempt(sessionId, event, attemptId);
43841
43854
  };
43842
- const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
43843
- read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
43844
- });
43855
+ const sessions = new AcpSessionManager(
43856
+ new DaemonAcpObserver(recordSessionEvent),
43857
+ sessionStore,
43858
+ {
43859
+ read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
43860
+ },
43861
+ "native"
43862
+ );
43845
43863
  const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
43846
43864
  const installationObserver = new DaemonInstallationObserver();
43847
43865
  const diagnostics = new RelayConnectionDiagnostics(
@@ -43977,13 +43995,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
43977
43995
  await sessions.close();
43978
43996
  } finally {
43979
43997
  try {
43980
- sessionStore.close();
43998
+ publisher.close();
43981
43999
  } finally {
43982
- try {
43983
- publisher.close();
43984
- } finally {
43985
- outbox.close();
43986
- }
44000
+ outbox.close();
43987
44001
  }
43988
44002
  }
43989
44003
  }
@@ -43999,9 +44013,9 @@ import { basename as basename7, resolve as resolve6 } from "node:path";
43999
44013
  import { fetch as fetch5 } from "undici";
44000
44014
 
44001
44015
  // src/storage/runtime-installation-store.ts
44002
- import { createHash as createHash4, randomUUID as randomUUID4 } from "node:crypto";
44016
+ import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
44003
44017
  import { mkdir as mkdir4, open as open5, readdir as readdir3, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
44004
- import { dirname as dirname7, join as join17, resolve as resolve5 } from "node:path";
44018
+ import { dirname as dirname4, join as join17, resolve as resolve5 } from "node:path";
44005
44019
  var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
44006
44020
  var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
44007
44021
  var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
@@ -44194,7 +44208,7 @@ function installationId() {
44194
44208
  return `min_${randomUUID4().replaceAll("-", "")}`;
44195
44209
  }
44196
44210
  function channelIndexFileName(channelId) {
44197
- return `mci_${createHash4("sha256").update(channelId).digest("hex")}.json`;
44211
+ return `mci_${createHash5("sha256").update(channelId).digest("hex")}.json`;
44198
44212
  }
44199
44213
  function decodeInstallationPointer(value) {
44200
44214
  if (!isRecord9(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
@@ -44342,7 +44356,7 @@ async function readJsonFile(path2, signal, missingCode) {
44342
44356
  }
44343
44357
  async function writeJsonAtomically(path2, value, signal) {
44344
44358
  signal.throwIfAborted();
44345
- const directory = dirname7(path2);
44359
+ const directory = dirname4(path2);
44346
44360
  const temporaryPath = join17(directory, `.${randomUUID4()}.tmp`);
44347
44361
  try {
44348
44362
  await mkdir4(directory, { mode: 448, recursive: true });
@@ -44405,7 +44419,6 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
44405
44419
  return new _RuntimeInstallationStore(applicationId, storedInstallationId, stateDirectory);
44406
44420
  };
44407
44421
  connectionPath = (connectionId2) => join17(this.#connectionDirectory, `${validateConnectionId(connectionId2)}.json`);
44408
- auditDatabasePath = (connectionId2) => join17(this.stateDirectory, "audit", `${validateConnectionId(connectionId2)}.sqlite`);
44409
44422
  channelIndexPath = (channelId) => join17(this.#channelDirectory, channelIndexFileName(validateIdentifier(channelId, "invalid_channel_id")));
44410
44423
  readConnection = async (connectionId2, signal) => {
44411
44424
  const stored = decodeConnection(
@@ -44798,7 +44811,6 @@ function buildPairedDaemon(installation, connection, defaultWorkspace, inventory
44798
44811
  config: createDaemonConfig(
44799
44812
  {
44800
44813
  defaultWorkspace,
44801
- auditDatabasePath: installation.auditDatabasePath(connection.connectionId),
44802
44814
  channelId: connection.channelId,
44803
44815
  relayUrl
44804
44816
  },
@@ -44920,7 +44932,6 @@ function loadMobiusRuntimeConnection(environment = process.env) {
44920
44932
  throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
44921
44933
  }
44922
44934
  return Object.freeze({
44923
- auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join18(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
44924
44935
  channelId,
44925
44936
  defaultWorkspace: loadDefaultWorkspace(environment),
44926
44937
  relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
@@ -44949,8 +44960,6 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
44949
44960
  const localContext = new DaemonLocalContext(readStateDirectory(environment), environment);
44950
44961
  const relayUrl = relayUrlFromConnection(connection);
44951
44962
  const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
44952
- const auditDatabasePath = resolve7(connection.auditDatabasePath);
44953
- await mkdir6(dirname8(auditDatabasePath), { recursive: true, mode: 448 });
44954
44963
  const inventory = await discoverLocalAgentInventory({
44955
44964
  defaultWorkspace,
44956
44965
  environment: localContext.environment,
@@ -44962,7 +44971,6 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
44962
44971
  return new MobiusRuntimeEngine(
44963
44972
  createDaemonConfig(
44964
44973
  {
44965
- auditDatabasePath,
44966
44974
  channelId: connection.channelId,
44967
44975
  defaultWorkspace,
44968
44976
  relayUrl
@@ -44988,7 +44996,7 @@ var MobiusRuntimeEngine = class {
44988
44996
  }
44989
44997
  signal.throwIfAborted();
44990
44998
  this.#state = new RunningMobiusRuntimeState();
44991
- const audit = new AuditStore(this.#config.auditDatabasePath);
44999
+ const audit = new AuditStore();
44992
45000
  try {
44993
45001
  await runDaemon(this.#config, audit, signal, void 0, {
44994
45002
  ...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus },