@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/index.js CHANGED
@@ -33,7 +33,6 @@ var createAcpClient = (handler) => client({ name: "mobius" }).onRequest(
33
33
 
34
34
  // src/config.ts
35
35
  import { join as join3, resolve as resolve3 } from "node:path";
36
- import { fileURLToPath } from "node:url";
37
36
 
38
37
  // ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/classic/external.js
39
38
  var external_exports = {};
@@ -21005,6 +21004,8 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
21005
21004
  title: external_exports.string().max(500)
21006
21005
  }).readonly();
21007
21006
  var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
21007
+ external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
21008
+ external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
21008
21009
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
21009
21010
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
21010
21011
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -21026,6 +21027,8 @@ var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
21026
21027
  }).readonly()
21027
21028
  ]);
21028
21029
  var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
21030
+ external_exports.strictObject({ ...identity, action: external_exports.literal("create") }).readonly(),
21031
+ external_exports.strictObject({ ...identity, action: external_exports.literal("linked-history"), targetSessionId: identifier }).readonly(),
21029
21032
  external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
21030
21033
  external_exports.strictObject({ ...identity, action: external_exports.literal("history"), entryId: identifier }).readonly(),
21031
21034
  external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
@@ -21054,7 +21057,7 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
21054
21057
  ]);
21055
21058
  var nativeSessionEntrySchema = external_exports.strictObject({
21056
21059
  entryId: identifier,
21057
- mobiusSessionIds: external_exports.array(identifier).max(500).readonly(),
21060
+ nativeSessionId: identifier,
21058
21061
  title: external_exports.string().max(500),
21059
21062
  directoryId,
21060
21063
  directoryLabel: external_exports.string().min(1).max(2048),
@@ -21066,6 +21069,18 @@ var resultEnvelope = {
21066
21069
  kind: external_exports.literal(NATIVE_SESSION_RESULT_KIND)
21067
21070
  };
21068
21071
  var nativeSessionResultSchema = external_exports.discriminatedUnion("action", [
21072
+ external_exports.strictObject({ ...resultEnvelope, action: external_exports.literal("create"), nativeSessionId: identifier }).readonly(),
21073
+ external_exports.strictObject({
21074
+ ...resultEnvelope,
21075
+ action: external_exports.literal("linked-history"),
21076
+ targetSessionId: identifier,
21077
+ history: sessionHistorySchema
21078
+ }).readonly(),
21079
+ external_exports.strictObject({
21080
+ ...resultEnvelope,
21081
+ action: external_exports.literal("unlinked-history"),
21082
+ targetSessionId: identifier
21083
+ }).readonly(),
21069
21084
  external_exports.strictObject({
21070
21085
  ...resultEnvelope,
21071
21086
  action: external_exports.literal("find"),
@@ -22359,7 +22374,6 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
22359
22374
  return {
22360
22375
  agents: daemonAgents,
22361
22376
  defaultWorkspace: connection.defaultWorkspace,
22362
- auditDatabasePath: connection.auditDatabasePath,
22363
22377
  bindingId: "workspace",
22364
22378
  catalog: new LocalAgentCatalog(daemonAgents, installableAgents),
22365
22379
  channelId: connection.channelId,
@@ -22380,7 +22394,6 @@ function loadDaemonConfig() {
22380
22394
  return createDaemonConfig(
22381
22395
  {
22382
22396
  defaultWorkspace: loadDefaultWorkspace(),
22383
- auditDatabasePath: process.env["MOBIUS_AUDIT_DATABASE"] ?? fileURLToPath(new URL("../../../.mobius/daemon.sqlite", import.meta.url)),
22384
22397
  channelId: process.env["MOBIUS_CHANNEL_ID"] ?? "local",
22385
22398
  relayUrl
22386
22399
  },
@@ -22401,7 +22414,7 @@ import {
22401
22414
  // src/authorization/local-raster.ts
22402
22415
  import { open as open2, readFile as readFile2, realpath as realpath2, stat as stat2 } from "node:fs/promises";
22403
22416
  import { basename, isAbsolute, normalize } from "node:path";
22404
- import { fileURLToPath as fileURLToPath2 } from "node:url";
22417
+ import { fileURLToPath } from "node:url";
22405
22418
  var MAX_LOCAL_RASTER_BYTES = 128 * 1024 * 1024;
22406
22419
  var MAX_INLINE_RASTER_BYTES = 3e6;
22407
22420
  var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
@@ -22498,7 +22511,7 @@ function parseLocalImageUri(uri) {
22498
22511
  if (url2.protocol !== "file:" || url2.host.length > 0) {
22499
22512
  return null;
22500
22513
  }
22501
- return fileURLToPath2(url2);
22514
+ return fileURLToPath(url2);
22502
22515
  } catch {
22503
22516
  return null;
22504
22517
  }
@@ -30930,9 +30943,6 @@ var AcpHistoryReplay = class {
30930
30943
  };
30931
30944
 
30932
30945
  // src/acp/session-store.ts
30933
- import { mkdirSync } from "node:fs";
30934
- import { dirname } from "node:path";
30935
- import { DatabaseSync } from "node:sqlite";
30936
30946
  var AcpStoredSession = class {
30937
30947
  additionalDirectories;
30938
30948
  agentId;
@@ -30965,44 +30975,6 @@ var FoundAcpStoredSession = class extends AcpStoredSessionLookup {
30965
30975
  var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
30966
30976
  found = false;
30967
30977
  };
30968
- function readString3(value, field) {
30969
- if (typeof value !== "string" || value.length === 0) {
30970
- throw new Error(`Stored ACP session has an invalid ${field}`);
30971
- }
30972
- return value;
30973
- }
30974
- function readAdditionalDirectories(value) {
30975
- if (typeof value !== "string") {
30976
- throw new Error("Stored ACP session has invalid additional directories");
30977
- }
30978
- const decoded = JSON.parse(value);
30979
- if (!Array.isArray(decoded) || decoded.some((directory) => typeof directory !== "string")) {
30980
- throw new Error("Stored ACP session has invalid additional directories");
30981
- }
30982
- return decoded;
30983
- }
30984
- function readPrompted(value) {
30985
- if (value === 0) {
30986
- return false;
30987
- }
30988
- if (value === 1) {
30989
- return true;
30990
- }
30991
- throw new Error("Stored ACP session has an invalid prompted state");
30992
- }
30993
- function decodeSessionRow(row) {
30994
- if (typeof row !== "object" || row === null || Array.isArray(row)) {
30995
- throw new Error("Stored ACP session is not an object");
30996
- }
30997
- return new AcpStoredSession(
30998
- readString3(Reflect.get(row, "session_id"), "session ID"),
30999
- readString3(Reflect.get(row, "agent_id"), "agent ID"),
31000
- readString3(Reflect.get(row, "native_session_id"), "native session ID"),
31001
- readString3(Reflect.get(row, "cwd"), "working directory"),
31002
- readAdditionalDirectories(Reflect.get(row, "additional_directories_json")),
31003
- readPrompted(Reflect.get(row, "prompted"))
31004
- );
31005
- }
31006
30978
  var MemoryAcpSessionStore = class {
31007
30979
  #sessions = /* @__PURE__ */ new Map();
31008
30980
  #deleted = /* @__PURE__ */ new Set();
@@ -31031,106 +31003,6 @@ var MemoryAcpSessionStore = class {
31031
31003
  this.#sessions.set(session.sessionId, session);
31032
31004
  };
31033
31005
  };
31034
- var SqliteAcpSessionStore = class {
31035
- #database;
31036
- constructor(path2) {
31037
- mkdirSync(dirname(path2), { recursive: true });
31038
- this.#database = new DatabaseSync(path2);
31039
- this.#database.exec(`
31040
- CREATE TABLE IF NOT EXISTS acp_deleted_sessions (session_id TEXT PRIMARY KEY) STRICT;
31041
- CREATE TABLE IF NOT EXISTS acp_sessions (
31042
- session_id TEXT PRIMARY KEY,
31043
- agent_id TEXT NOT NULL,
31044
- native_session_id TEXT NOT NULL,
31045
- cwd TEXT NOT NULL,
31046
- additional_directories_json TEXT NOT NULL,
31047
- prompted INTEGER NOT NULL DEFAULT 0 CHECK (prompted IN (0, 1)),
31048
- updated_at TEXT NOT NULL
31049
- ) STRICT
31050
- `);
31051
- const columns = this.#database.prepare("PRAGMA table_info(acp_sessions)").all();
31052
- const hasPromptedColumn = columns.some(
31053
- (column) => typeof column === "object" && column !== null && Reflect.get(column, "name") === "prompted"
31054
- );
31055
- if (!hasPromptedColumn) {
31056
- this.#database.exec(`
31057
- ALTER TABLE acp_sessions
31058
- ADD COLUMN prompted INTEGER NOT NULL DEFAULT 1 CHECK (prompted IN (0, 1))
31059
- `);
31060
- }
31061
- }
31062
- read = (sessionId) => {
31063
- if (this.#database.prepare("SELECT session_id FROM acp_deleted_sessions WHERE session_id = ?").get(sessionId) !== void 0) {
31064
- return new DeletedAcpStoredSession();
31065
- }
31066
- const row = this.#database.prepare(
31067
- `
31068
- SELECT
31069
- session_id,
31070
- agent_id,
31071
- native_session_id,
31072
- cwd,
31073
- additional_directories_json,
31074
- prompted
31075
- FROM acp_sessions
31076
- WHERE session_id = ?
31077
- `
31078
- ).get(sessionId);
31079
- return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeSessionRow(row));
31080
- };
31081
- remove = (sessionId) => {
31082
- this.#database.prepare("DELETE FROM acp_sessions WHERE session_id = ?").run(sessionId);
31083
- };
31084
- findNative = (agentId, nativeSessionId) => this.#database.prepare("SELECT * FROM acp_sessions WHERE agent_id = ? AND native_session_id = ?").all(agentId, nativeSessionId).map(decodeSessionRow);
31085
- markDeleted = (agentId, nativeSessionId) => {
31086
- const ids = this.findNative(agentId, nativeSessionId).map((session) => session.sessionId);
31087
- this.#database.exec("BEGIN");
31088
- try {
31089
- for (const id of ids) {
31090
- this.#database.prepare("INSERT OR IGNORE INTO acp_deleted_sessions (session_id) VALUES (?)").run(id);
31091
- this.remove(id);
31092
- }
31093
- this.#database.exec("COMMIT");
31094
- return ids;
31095
- } catch (error62) {
31096
- this.#database.exec("ROLLBACK");
31097
- throw error62;
31098
- }
31099
- };
31100
- write = (session) => {
31101
- this.#database.prepare(
31102
- `
31103
- INSERT INTO acp_sessions (
31104
- session_id,
31105
- agent_id,
31106
- native_session_id,
31107
- cwd,
31108
- additional_directories_json,
31109
- prompted,
31110
- updated_at
31111
- ) VALUES (?, ?, ?, ?, ?, ?, ?)
31112
- ON CONFLICT(session_id) DO UPDATE SET
31113
- agent_id = excluded.agent_id,
31114
- native_session_id = excluded.native_session_id,
31115
- cwd = excluded.cwd,
31116
- additional_directories_json = excluded.additional_directories_json,
31117
- prompted = excluded.prompted,
31118
- updated_at = excluded.updated_at
31119
- `
31120
- ).run(
31121
- session.sessionId,
31122
- session.agentId,
31123
- session.nativeSessionId,
31124
- session.cwd,
31125
- JSON.stringify(session.additionalDirectories),
31126
- session.prompted ? 1 : 0,
31127
- (/* @__PURE__ */ new Date()).toISOString()
31128
- );
31129
- };
31130
- close = () => {
31131
- this.#database.close();
31132
- };
31133
- };
31134
31006
 
31135
31007
  // src/acp/session-manager.ts
31136
31008
  var PROCESS_STOP_TIMEOUT_MILLISECONDS = 1e3;
@@ -31357,7 +31229,7 @@ function truncate3(value, maximumLength) {
31357
31229
  function isRecord5(value) {
31358
31230
  return typeof value === "object" && value !== null && !Array.isArray(value);
31359
31231
  }
31360
- function readString4(value, fallback = "") {
31232
+ function readString3(value, fallback = "") {
31361
31233
  return typeof value === "string" ? value : fallback;
31362
31234
  }
31363
31235
  function arraysEqual(left, right) {
@@ -31390,8 +31262,8 @@ function normalizeElicitationOptions(schema) {
31390
31262
  for (const option of oneOf) {
31391
31263
  if (isRecord5(option) && typeof option["const"] === "string") {
31392
31264
  normalized.push({
31393
- description: truncate3(readString4(option["description"]), 500),
31394
- label: truncate3(readString4(option["title"], option["const"]), 255),
31265
+ description: truncate3(readString3(option["description"]), 500),
31266
+ label: truncate3(readString3(option["title"], option["const"]), 255),
31395
31267
  value: truncate3(option["const"], 500)
31396
31268
  });
31397
31269
  }
@@ -31442,8 +31314,8 @@ function normalizeElicitationFields(requestedSchema) {
31442
31314
  defaultBooleanValue: typeof defaultValue === "boolean" ? defaultValue : false,
31443
31315
  defaultNumberValue: typeof defaultValue === "number" && Number.isFinite(defaultValue) ? defaultValue : 0,
31444
31316
  defaultStringValue: typeof defaultValue === "string" ? truncate3(defaultValue, 1e4) : Array.isArray(defaultValue) ? truncate3(JSON.stringify(defaultValue), 1e4) : "",
31445
- description: truncate3(readString4(property["description"]), 500),
31446
- format: truncate3(readString4(property["format"]), 64),
31317
+ description: truncate3(readString3(property["description"]), 500),
31318
+ format: truncate3(readString3(property["format"]), 64),
31447
31319
  hasDefaultValue: defaultValue !== void 0 && defaultValue !== null,
31448
31320
  maximum: numericString(property["maximum"]),
31449
31321
  maximumLength: numericString(property["maxLength"] ?? property["maxItems"]),
@@ -31451,9 +31323,9 @@ function normalizeElicitationFields(requestedSchema) {
31451
31323
  minimumLength: numericString(property["minLength"] ?? property["minItems"]),
31452
31324
  name: truncate3(name, 128),
31453
31325
  options,
31454
- pattern: truncate3(readString4(property["pattern"]), 500),
31326
+ pattern: truncate3(readString3(property["pattern"]), 500),
31455
31327
  required: required2.has(name),
31456
- title: truncate3(readString4(property["title"], name), 255),
31328
+ title: truncate3(readString3(property["title"], name), 255),
31457
31329
  type: normalizedType
31458
31330
  });
31459
31331
  }
@@ -32292,6 +32164,17 @@ var AcpProcessSession = class _AcpProcessSession {
32292
32164
  );
32293
32165
  };
32294
32166
  nativeSessionId = () => this.#nativeSessionId;
32167
+ adoptNativeSessionId = (sessionId) => {
32168
+ if (this.#prompted || this.#nativeSessionId !== sessionId) {
32169
+ throw new AcpExecutionError("The new Codex Session cannot be adopted", {}, "session_identity_mismatch");
32170
+ }
32171
+ const previousSessionId = this.#mobiusSessionId;
32172
+ this.#store.write(
32173
+ new AcpStoredSession(sessionId, this.#agentId, sessionId, this.#cwd, this.#additionalDirectories, false)
32174
+ );
32175
+ this.#store.remove(previousSessionId);
32176
+ this.#mobiusSessionId = sessionId;
32177
+ };
32295
32178
  configure = async (options) => {
32296
32179
  const existing = this.#configOptions.find((option) => option.id === options.configId);
32297
32180
  if (existing === void 0 || existing.type !== options.valueType) {
@@ -32685,7 +32568,7 @@ var AcpProcessSession = class _AcpProcessSession {
32685
32568
  message: truncate3(request.message, 2e3),
32686
32569
  mode: request.mode,
32687
32570
  sessionId: this.#mobiusSessionId,
32688
- url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate3(readString4(Reflect.get(request, "url")), 4096) : ""
32571
+ url: request.mode === "url" && typeof Reflect.get(request, "url") === "string" ? truncate3(readString3(Reflect.get(request, "url")), 4096) : ""
32689
32572
  });
32690
32573
  return await pending.completion.promise;
32691
32574
  } finally {
@@ -33045,16 +32928,17 @@ var AcpSessionManager = class {
33045
32928
  #transientProcessCount = 0;
33046
32929
  #store;
33047
32930
  #nativeHistoryReader;
32931
+ #sessionIdentity;
33048
32932
  #observer;
33049
- constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null) {
32933
+ constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null, sessionIdentity = "assigned") {
33050
32934
  this.#observer = observer;
33051
32935
  this.#store = store;
33052
32936
  this.#nativeHistoryReader = nativeHistoryReader;
32937
+ this.#sessionIdentity = sessionIdentity;
33053
32938
  }
33054
32939
  setObserver = (observer) => {
33055
32940
  this.#observer = observer;
33056
32941
  };
33057
- findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
33058
32942
  #notifyProcessCapacityChanged() {
33059
32943
  const changed = this.#processCapacityChanged;
33060
32944
  this.#processCapacityChanged = Promise.withResolvers();
@@ -33162,7 +33046,13 @@ var AcpSessionManager = class {
33162
33046
  if (retained) {
33163
33047
  this.#sessions.delete(sessionId);
33164
33048
  }
33165
- await this.#retireProcess(runtime, retained, close);
33049
+ try {
33050
+ await this.#retireProcess(runtime, retained, close);
33051
+ } finally {
33052
+ if (retained && this.#sessionIdentity === "native") {
33053
+ this.#store.remove(sessionId);
33054
+ }
33055
+ }
33166
33056
  }
33167
33057
  async #retireNativeBrowserProcess(sessionId, runtime, close) {
33168
33058
  const retained = this.#nativeBrowserSessions.get(sessionId) === runtime;
@@ -33309,7 +33199,14 @@ var AcpSessionManager = class {
33309
33199
  try {
33310
33200
  return await this.#startRetainedSessionProcess(
33311
33201
  options,
33312
- async () => await AcpProcessSession.start(options, () => this.#observer, this.#store, metrics)
33202
+ async () => await AcpProcessSession.start(
33203
+ 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(
33204
+ options.sessionId
33205
+ ) && this.#store.read(options.sessionId) instanceof MissingAcpStoredSession ? { ...options, origin: { kind: "import", nativeSessionId: options.sessionId } } : options,
33206
+ () => this.#observer,
33207
+ this.#store,
33208
+ metrics
33209
+ )
33313
33210
  );
33314
33211
  } finally {
33315
33212
  this.#preparing.delete(options.sessionId);
@@ -33732,6 +33629,45 @@ var AcpSessionManager = class {
33732
33629
  ]);
33733
33630
  };
33734
33631
  hasPreparedSession = (sessionId, agentId, cwd, additionalDirectories) => this.#sessions.get(sessionId)?.belongsTo(agentId, cwd, additionalDirectories) === true;
33632
+ createNativeSession = async (options) => {
33633
+ const temporarySessionId = `new-${crypto.randomUUID()}`;
33634
+ const temporaryOptions = { ...options, sessionId: temporarySessionId };
33635
+ this.#beginSessionUse(temporarySessionId);
33636
+ try {
33637
+ const runtime = await this.#startPreparation(temporaryOptions);
33638
+ let adopted = false;
33639
+ try {
33640
+ const nativeSessionId = runtime.nativeSessionId();
33641
+ 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)) {
33642
+ throw new AcpExecutionError(
33643
+ "Codex returned an invalid new Session ID",
33644
+ {},
33645
+ "invalid_native_session_response"
33646
+ );
33647
+ }
33648
+ runtime.adoptNativeSessionId(nativeSessionId);
33649
+ this.#sessions.delete(temporarySessionId);
33650
+ this.#sessions.set(nativeSessionId, runtime);
33651
+ this.#retainedProcesses.set(
33652
+ runtime,
33653
+ new FoundAcpSessionProcessEvictionCandidate(nativeSessionId, runtime)
33654
+ );
33655
+ adopted = true;
33656
+ return nativeSessionId;
33657
+ } finally {
33658
+ if (!adopted) {
33659
+ await this.#retireSessionProcess(
33660
+ temporarySessionId,
33661
+ runtime,
33662
+ async () => await runtime.closeProcess()
33663
+ );
33664
+ }
33665
+ }
33666
+ } finally {
33667
+ this.#store.remove(temporarySessionId);
33668
+ this.#endSessionUse(temporarySessionId);
33669
+ }
33670
+ };
33735
33671
  ensureSession = async (options) => {
33736
33672
  const existing = this.#sessions.get(options.sessionId);
33737
33673
  if (existing !== void 0) {
@@ -33825,6 +33761,25 @@ var AcpSessionManager = class {
33825
33761
  this.#endSessionUse(options.sessionId);
33826
33762
  }
33827
33763
  };
33764
+ loadLinkedSessionHistory = async (options) => {
33765
+ options.signal.throwIfAborted();
33766
+ const stored = this.#store.read(options.sessionId);
33767
+ if (!(stored instanceof FoundAcpStoredSession) || !stored.session.prompted) {
33768
+ return null;
33769
+ }
33770
+ const linked = stored.session;
33771
+ 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])) {
33772
+ throw new AcpExecutionError(
33773
+ "The session belongs to another Agent or workspace",
33774
+ {},
33775
+ "session_identity_mismatch"
33776
+ );
33777
+ }
33778
+ if (this.#nativeHistoryReader === null) {
33779
+ return await this.loadSessionHistory(options);
33780
+ }
33781
+ return await this.#nativeHistoryReader.read(options, linked.nativeSessionId);
33782
+ };
33828
33783
  openNativeSession = async (options, origin, loadHistory) => {
33829
33784
  const key = `${options.agent.id}:${origin.nativeSessionId}`;
33830
33785
  if (this.#nativeOperations.has(key)) {
@@ -34044,51 +33999,20 @@ async function runAcpPrompt(options) {
34044
33999
  }
34045
34000
 
34046
34001
  // src/audit/audit-store.ts
34047
- import { mkdirSync as mkdirSync2 } from "node:fs";
34048
- import { dirname as dirname2 } from "node:path";
34049
- import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
34002
+ var MAX_AUDIT_RECORDS = 1024;
34050
34003
  var AuditStore = class {
34051
- database;
34052
- constructor(path2) {
34053
- mkdirSync2(dirname2(path2), { recursive: true });
34054
- this.database = new DatabaseSync2(path2);
34055
- this.database.exec(`
34056
- CREATE TABLE IF NOT EXISTS audit_events (
34057
- id INTEGER PRIMARY KEY AUTOINCREMENT,
34058
- recorded_at TEXT NOT NULL,
34059
- event TEXT NOT NULL,
34060
- command_id TEXT NOT NULL,
34061
- session_id TEXT NOT NULL,
34062
- details_json TEXT NOT NULL DEFAULT '{}'
34063
- ) STRICT
34064
- `);
34065
- const columns = this.database.prepare("PRAGMA table_info(audit_events)").all();
34066
- if (!columns.some((column) => Reflect.get(column, "name") === "details_json")) {
34067
- this.database.exec("ALTER TABLE audit_events ADD COLUMN details_json TEXT NOT NULL DEFAULT '{}'");
34068
- }
34069
- }
34070
- record(record2) {
34071
- this.database.prepare(
34072
- `
34073
- INSERT INTO audit_events (
34074
- recorded_at,
34075
- event,
34076
- command_id,
34077
- session_id,
34078
- details_json
34079
- ) VALUES (?, ?, ?, ?, ?)
34080
- `
34081
- ).run(
34082
- (/* @__PURE__ */ new Date()).toISOString(),
34083
- record2.event,
34084
- record2.commandId,
34085
- record2.sessionId,
34086
- JSON.stringify(record2.details ?? {})
34004
+ #records = [];
34005
+ record = (record2) => {
34006
+ if (this.#records.length === MAX_AUDIT_RECORDS) {
34007
+ this.#records.shift();
34008
+ }
34009
+ this.#records.push(
34010
+ record2.details === void 0 ? { ...record2 } : { ...record2, details: { ...record2.details } }
34087
34011
  );
34088
- }
34089
- close() {
34090
- this.database.close();
34091
- }
34012
+ };
34013
+ close = () => {
34014
+ this.#records.length = 0;
34015
+ };
34092
34016
  };
34093
34017
 
34094
34018
  // src/authorization/local-authorization-error.ts
@@ -34214,7 +34138,7 @@ var LocalAgentInventory = class {
34214
34138
 
34215
34139
  // src/agent-installation/managed-npm-package.ts
34216
34140
  import { mkdir, mkdtemp, open as open3, realpath as realpath3, rename, rm, stat as stat3 } from "node:fs/promises";
34217
- import { delimiter, dirname as dirname3, isAbsolute as isAbsolute2, join as join4, relative, sep } from "node:path";
34141
+ import { delimiter, dirname, isAbsolute as isAbsolute2, join as join4, relative, sep } from "node:path";
34218
34142
  var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
34219
34143
  var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
34220
34144
  var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
@@ -34444,7 +34368,7 @@ var ManagedNpmPackageInstaller = class {
34444
34368
  throw error62;
34445
34369
  }
34446
34370
  }
34447
- const parent = dirname3(root);
34371
+ const parent = dirname(root);
34448
34372
  await mkdir(parent, { mode: 448, recursive: true });
34449
34373
  const staging = await mkdtemp(join4(parent, `.${definition2.version}.staging-`));
34450
34374
  try {
@@ -34479,7 +34403,7 @@ var ManagedNpmPackageInstaller = class {
34479
34403
  NPM_CONFIG_IGNORE_SCRIPTS: "true",
34480
34404
  NPM_CONFIG_PACKAGE_LOCK: "true",
34481
34405
  NPM_CONFIG_REGISTRY: "https://registry.npmjs.org/",
34482
- PATH: `${dirname3(process.execPath)}${delimiter}/usr/bin${delimiter}/bin`
34406
+ PATH: `${dirname(process.execPath)}${delimiter}/usr/bin${delimiter}/bin`
34483
34407
  };
34484
34408
  if (definition2.includeOptionalDependencies) {
34485
34409
  installEnvironment["NPM_CONFIG_INCLUDE"] = "optional";
@@ -35344,18 +35268,17 @@ function effortValues(model) {
35344
35268
  }
35345
35269
  function modelSetting(models, currentValue) {
35346
35270
  const values = modelValues(models);
35347
- const current = currentValue.length > 0 ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
35271
+ const current = values.some((value) => value.value === currentValue) ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
35348
35272
  if (current.length === 0) {
35349
35273
  return null;
35350
35274
  }
35351
- const options = values.some((value) => value.value === current) ? values : [{ description: "", name: current, value: current }, ...values];
35352
35275
  return {
35353
35276
  category: "model",
35354
35277
  currentValue: current,
35355
35278
  description: "Model Codex uses for the session",
35356
35279
  id: MODEL_SETTING_ID,
35357
35280
  name: "Model",
35358
- options,
35281
+ options: values,
35359
35282
  type: "select"
35360
35283
  };
35361
35284
  }
@@ -36643,7 +36566,7 @@ import { join as join10 } from "node:path";
36643
36566
  import { createHash } from "node:crypto";
36644
36567
  import { createReadStream } from "node:fs";
36645
36568
  import { chmod, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open4, realpath as realpath6, rename as rename2, rm as rm2, stat as stat5, writeFile as writeFile2 } from "node:fs/promises";
36646
- import { delimiter as delimiter2, dirname as dirname4, isAbsolute as isAbsolute6, join as join9, relative as relative3, sep as sep3 } from "node:path";
36569
+ import { delimiter as delimiter2, dirname as dirname2, isAbsolute as isAbsolute6, join as join9, relative as relative3, sep as sep3 } from "node:path";
36647
36570
 
36648
36571
  // src/agent-installation/verified-download.ts
36649
36572
  import { fetch } from "undici";
@@ -37943,7 +37866,7 @@ async function discoverLocalAgentInventory(options) {
37943
37866
  // src/storage/runtime-installation-store.ts
37944
37867
  import { createHash as createHash2, randomUUID } from "node:crypto";
37945
37868
  import { mkdir as mkdir4, open as open5, readdir as readdir2, rename as rename3, unlink, writeFile as writeFile3 } from "node:fs/promises";
37946
- import { dirname as dirname5, join as join15, resolve as resolve4 } from "node:path";
37869
+ import { dirname as dirname3, join as join15, resolve as resolve4 } from "node:path";
37947
37870
  var APPLICATION_ID_PATTERN = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+){1,31}$/;
37948
37871
  var CONNECTION_ID_PATTERN = /^mcn_[a-f0-9]{32}$/;
37949
37872
  var INSTALLATION_ID_PATTERN = /^min_[a-f0-9]{32}$/;
@@ -38284,7 +38207,7 @@ async function readJsonFile(path2, signal, missingCode) {
38284
38207
  }
38285
38208
  async function writeJsonAtomically(path2, value, signal) {
38286
38209
  signal.throwIfAborted();
38287
- const directory = dirname5(path2);
38210
+ const directory = dirname3(path2);
38288
38211
  const temporaryPath = join15(directory, `.${randomUUID()}.tmp`);
38289
38212
  try {
38290
38213
  await mkdir4(directory, { mode: 448, recursive: true });
@@ -38347,7 +38270,6 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
38347
38270
  return new _RuntimeInstallationStore(applicationId, storedInstallationId, stateDirectory);
38348
38271
  };
38349
38272
  connectionPath = (connectionId2) => join15(this.#connectionDirectory, `${validateConnectionId(connectionId2)}.json`);
38350
- auditDatabasePath = (connectionId2) => join15(this.stateDirectory, "audit", `${validateConnectionId(connectionId2)}.sqlite`);
38351
38273
  channelIndexPath = (channelId) => join15(this.#channelDirectory, channelIndexFileName(validateIdentifier(channelId, "invalid_channel_id")));
38352
38274
  readConnection = async (connectionId2, signal) => {
38353
38275
  const stored = decodeConnection(
@@ -38786,7 +38708,6 @@ function buildPairedDaemon(installation, connection, defaultWorkspace, inventory
38786
38708
  config: createDaemonConfig(
38787
38709
  {
38788
38710
  defaultWorkspace,
38789
- auditDatabasePath: installation.auditDatabasePath(connection.connectionId),
38790
38711
  channelId: connection.channelId,
38791
38712
  relayUrl
38792
38713
  },
@@ -38906,7 +38827,7 @@ function isRuntimeRelayRevocation(closeCode, closeReason) {
38906
38827
  }
38907
38828
 
38908
38829
  // src/run-daemon.ts
38909
- import { createHash as createHash4, randomUUID as randomUUID4 } from "node:crypto";
38830
+ import { createHash as createHash5, randomUUID as randomUUID4 } from "node:crypto";
38910
38831
  import { basename as basename7 } from "node:path";
38911
38832
  import { styleText } from "node:util";
38912
38833
  import { fetch as fetch5, WebSocket as WebSocket2 } from "undici";
@@ -39692,7 +39613,7 @@ var FixedInstallationExecutor = class {
39692
39613
  import { createReadStream as createReadStream2 } from "node:fs";
39693
39614
  import { realpath as realpath8, stat as stat7 } from "node:fs/promises";
39694
39615
  import { basename as basename4, isAbsolute as isAbsolute9, normalize as normalize3 } from "node:path";
39695
- import { fileURLToPath as fileURLToPath3 } from "node:url";
39616
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
39696
39617
  var CHUNK_BYTES = 192 * 1024;
39697
39618
  function requestedPath(value) {
39698
39619
  if (value.includes("\0")) {
@@ -39701,7 +39622,7 @@ function requestedPath(value) {
39701
39622
  if (value.startsWith("file:")) {
39702
39623
  try {
39703
39624
  const url2 = new URL(value);
39704
- return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath3(url2) : null;
39625
+ return url2.protocol === "file:" && url2.host.length === 0 ? fileURLToPath2(url2) : null;
39705
39626
  } catch {
39706
39627
  return null;
39707
39628
  }
@@ -39770,7 +39691,7 @@ async function streamLocalFile(command, send2, signal) {
39770
39691
  // src/authorization/workspace-directory.ts
39771
39692
  import { readdir as readdir3, realpath as realpath9, stat as stat8 } from "node:fs/promises";
39772
39693
  import { homedir as homedir2 } from "node:os";
39773
- import { basename as basename5, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
39694
+ import { basename as basename5, dirname as dirname4, isAbsolute as isAbsolute10, join as join16, normalize as normalize4, relative as relative4 } from "node:path";
39774
39695
  var WorkspaceDirectoryListing = class {
39775
39696
  directoryId;
39776
39697
  directoryLabel;
@@ -39894,7 +39815,7 @@ var WorkspaceDirectoryService = class {
39894
39815
  }
39895
39816
  }
39896
39817
  entries.sort((a, b) => a.name.localeCompare(b.name));
39897
- const parent = dirname6(target);
39818
+ const parent = dirname4(target);
39898
39819
  return new WorkspaceDirectoryListing(
39899
39820
  id,
39900
39821
  this.label(target),
@@ -39919,7 +39840,7 @@ var WorkspaceDirectoryService = class {
39919
39840
  };
39920
39841
 
39921
39842
  // src/daemon-diagnostic-log.ts
39922
- import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
39843
+ import { appendFileSync, mkdirSync, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
39923
39844
  import { join as join17 } from "node:path";
39924
39845
  var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
39925
39846
  var DaemonDiagnosticLog = class {
@@ -39935,7 +39856,7 @@ var DaemonDiagnosticLog = class {
39935
39856
  const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
39936
39857
  `;
39937
39858
  const encodedBytes = Buffer.byteLength(encoded);
39938
- mkdirSync3(this.#directory, { mode: 448, recursive: true });
39859
+ mkdirSync(this.#directory, { mode: 448, recursive: true });
39939
39860
  let existingBytes = 0;
39940
39861
  try {
39941
39862
  existingBytes = statSync3(this.#path).size;
@@ -40424,6 +40345,84 @@ var NativeSessionService = class {
40424
40345
  sessionId: command.sessionId,
40425
40346
  signal
40426
40347
  };
40348
+ if (command.action === "linked-history") {
40349
+ if (options.agent.id !== "codex") {
40350
+ const history = await this.#sessions.loadLinkedSessionHistory({
40351
+ ...options,
40352
+ sessionId: command.targetSessionId
40353
+ });
40354
+ this.record(command, "native_session_history_read");
40355
+ return history === null ? {
40356
+ action: "unlinked-history",
40357
+ kind: "native.session.result",
40358
+ requestId: command.requestId,
40359
+ sessionId: command.sessionId,
40360
+ targetSessionId: command.targetSessionId
40361
+ } : {
40362
+ action: "linked-history",
40363
+ history,
40364
+ kind: "native.session.result",
40365
+ requestId: command.requestId,
40366
+ sessionId: command.sessionId,
40367
+ targetSessionId: command.targetSessionId
40368
+ };
40369
+ }
40370
+ const nativeSessionId = nativeSessionIdSchema.parse(command.targetSessionId);
40371
+ if (this.#sessions.hasPreparedSession(nativeSessionId, options.agent.id, cwd, additionalDirectories) && await this.#sessions.loadLinkedSessionHistory({ ...options, sessionId: nativeSessionId }) === null) {
40372
+ this.record(command, "native_session_history_read");
40373
+ return {
40374
+ action: "linked-history",
40375
+ history: {
40376
+ status: "available",
40377
+ messages: [],
40378
+ truncated: false,
40379
+ coveredCommandIds: [],
40380
+ coveredMessageIds: []
40381
+ },
40382
+ kind: "native.session.result",
40383
+ requestId: command.requestId,
40384
+ sessionId: command.sessionId,
40385
+ targetSessionId: command.targetSessionId
40386
+ };
40387
+ }
40388
+ const snapshot = await readCodexFullHistory(options.agent, cwd, nativeSessionId, signal);
40389
+ const resolved = await this.#directories.identify(command.bindingId, snapshot.cwd, signal);
40390
+ if (snapshot.nativeSessionId !== nativeSessionId || resolved.path !== cwd) {
40391
+ throw new AcpExecutionError(
40392
+ "Codex returned history for a different session or workspace.",
40393
+ {},
40394
+ "invalid_native_session_response"
40395
+ );
40396
+ }
40397
+ this.record(command, "native_session_history_read");
40398
+ return {
40399
+ action: "linked-history",
40400
+ history: snapshot.history,
40401
+ kind: "native.session.result",
40402
+ requestId: command.requestId,
40403
+ sessionId: command.sessionId,
40404
+ targetSessionId: command.targetSessionId
40405
+ };
40406
+ }
40407
+ if (command.action === "create") {
40408
+ if (options.agent.id !== "codex") {
40409
+ throw new AcpExecutionError(
40410
+ "Native session creation is unavailable for this Agent",
40411
+ {},
40412
+ "native_session_unsupported"
40413
+ );
40414
+ }
40415
+ const nativeSessionId = await this.#sessions.createNativeSession(options);
40416
+ signal.throwIfAborted();
40417
+ this.record(command, "native_session_created");
40418
+ return {
40419
+ action: "create",
40420
+ kind: "native.session.result",
40421
+ nativeSessionId,
40422
+ requestId: command.requestId,
40423
+ sessionId: command.sessionId
40424
+ };
40425
+ }
40427
40426
  const prepared = await this.#sessions.prepareNativeSessionBrowser(options);
40428
40427
  if (!prepared.capabilities.listSessions) {
40429
40428
  throw new AcpExecutionError(
@@ -40451,7 +40450,7 @@ var NativeSessionService = class {
40451
40450
  });
40452
40451
  return {
40453
40452
  entryId,
40454
- mobiusSessionIds: this.#sessions.findLinkedSessions(command.agentId, info.sessionId).filter((session) => session.prompted && session.cwd === authorized.cwd).map((session) => session.sessionId),
40453
+ nativeSessionId: info.sessionId,
40455
40454
  title: info.title ?? "Untitled session",
40456
40455
  directoryId: authorized.directoryId,
40457
40456
  directoryLabel: authorized.directoryLabel,
@@ -41536,26 +41535,26 @@ var RelayConnectionLiveness = class {
41536
41535
  };
41537
41536
 
41538
41537
  // src/relay-connection/session-event-outbox.ts
41539
- import { mkdirSync as mkdirSync4 } from "node:fs";
41540
- import { dirname as dirname7 } from "node:path";
41541
- import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
41538
+ import { createHash as createHash4 } from "node:crypto";
41539
+ import { DatabaseSync } from "node:sqlite";
41542
41540
  var DEFAULT_OUTBOX_LIMITS = {
41543
41541
  criticalEventBytes: 136 * 1024 * 1024,
41544
41542
  runtimeDeliveryBytes: 64 * 1024 * 1024,
41545
41543
  runtimeDeliveryCount: 64,
41546
41544
  standardEventBytes: 128 * 1024 * 1024
41547
41545
  };
41546
+ var MAX_TERMINAL_RECEIPTS = 1024;
41548
41547
  var SessionEventOutboxCapacityError = class extends Error {
41549
41548
  code = "session_event_outbox_full";
41550
41549
  constructor() {
41551
- super("The durable Session event outbox is full");
41550
+ super("The in-memory Session event outbox is full");
41552
41551
  this.name = "SessionEventOutboxCapacityError";
41553
41552
  }
41554
41553
  };
41555
41554
  var RuntimeDeliveryInboxCapacityError = class extends Error {
41556
41555
  code = "runtime_delivery_inbox_full";
41557
41556
  constructor() {
41558
- super("The durable Runtime delivery inbox is full");
41557
+ super("The in-memory Runtime delivery inbox is full");
41559
41558
  this.name = "RuntimeDeliveryInboxCapacityError";
41560
41559
  }
41561
41560
  };
@@ -41600,11 +41599,10 @@ function rowString(row, field) {
41600
41599
  var SessionEventOutbox = class {
41601
41600
  #database;
41602
41601
  #limits;
41603
- constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
41602
+ constructor(limits = DEFAULT_OUTBOX_LIMITS) {
41604
41603
  validateLimits(limits);
41605
41604
  this.#limits = limits;
41606
- mkdirSync4(dirname7(path2), { recursive: true });
41607
- this.#database = new DatabaseSync3(path2);
41605
+ this.#database = new DatabaseSync(":memory:");
41608
41606
  this.#database.exec(`
41609
41607
  CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
41610
41608
  ordinal INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -41632,7 +41630,7 @@ var SessionEventOutbox = class {
41632
41630
  CREATE TABLE IF NOT EXISTS relay_turn_receipts (
41633
41631
  command_id TEXT PRIMARY KEY,
41634
41632
  session_id TEXT NOT NULL,
41635
- command_json TEXT NOT NULL,
41633
+ command_hash TEXT NOT NULL,
41636
41634
  attempt_id TEXT NOT NULL,
41637
41635
  state TEXT NOT NULL CHECK (
41638
41636
  state IN ('dispatching', 'running', 'succeeded', 'failed', 'cancelled')
@@ -41663,19 +41661,20 @@ var SessionEventOutbox = class {
41663
41661
  `);
41664
41662
  }
41665
41663
  claimExecution = (commandId, sessionId, commandJson) => {
41664
+ const commandHash = createHash4("sha256").update(commandJson).digest("hex");
41666
41665
  this.#database.exec("BEGIN IMMEDIATE");
41667
41666
  try {
41668
41667
  const existing = this.#database.prepare(
41669
- `SELECT session_id, command_json, attempt_id, state
41668
+ `SELECT session_id, command_hash, attempt_id, state
41670
41669
  FROM relay_turn_receipts WHERE command_id = ?`
41671
41670
  ).get(commandId);
41672
41671
  if (typeof existing === "object" && existing !== null) {
41673
41672
  const storedSessionId = Reflect.get(existing, "session_id");
41674
- const storedCommand = Reflect.get(existing, "command_json");
41673
+ const storedCommandHash = Reflect.get(existing, "command_hash");
41675
41674
  const attemptId2 = Reflect.get(existing, "attempt_id");
41676
41675
  const state = Reflect.get(existing, "state");
41677
- if (storedSessionId !== sessionId || storedCommand !== commandJson || typeof attemptId2 !== "string" || !isDaemonExecutionState(state)) {
41678
- throw new Error("The daemon command identity conflicts with its durable receipt");
41676
+ if (storedSessionId !== sessionId || storedCommandHash !== commandHash || typeof attemptId2 !== "string" || !isDaemonExecutionState(state)) {
41677
+ throw new Error("The daemon command identity conflicts with its in-memory receipt");
41679
41678
  }
41680
41679
  this.#database.exec("COMMIT");
41681
41680
  return { attemptId: attemptId2, commandId, kind: "duplicate", state };
@@ -41683,9 +41682,9 @@ var SessionEventOutbox = class {
41683
41682
  const attemptId = crypto.randomUUID();
41684
41683
  this.#database.prepare(
41685
41684
  `INSERT INTO relay_turn_receipts (
41686
- command_id, session_id, command_json, attempt_id, state
41685
+ command_id, session_id, command_hash, attempt_id, state
41687
41686
  ) VALUES (?, ?, ?, ?, 'dispatching')`
41688
- ).run(commandId, sessionId, commandJson, attemptId);
41687
+ ).run(commandId, sessionId, commandHash, attemptId);
41689
41688
  this.#database.exec("COMMIT");
41690
41689
  return {
41691
41690
  attemptId,
@@ -41712,11 +41711,21 @@ var SessionEventOutbox = class {
41712
41711
  throw new Error("The daemon execution transition is invalid");
41713
41712
  }
41714
41713
  this.#database.prepare(`UPDATE relay_turn_receipts SET state = ? WHERE command_id = ?`).run(state, commandId);
41714
+ if (state === "succeeded" || state === "failed" || state === "cancelled") {
41715
+ this.#database.prepare(
41716
+ `DELETE FROM relay_turn_receipts
41717
+ WHERE state IN ('succeeded', 'failed', 'cancelled')
41718
+ AND rowid NOT IN (
41719
+ SELECT rowid FROM relay_turn_receipts
41720
+ WHERE state IN ('succeeded', 'failed', 'cancelled')
41721
+ ORDER BY rowid DESC LIMIT ?
41722
+ )`
41723
+ ).run(MAX_TERMINAL_RECEIPTS);
41724
+ }
41715
41725
  };
41716
41726
  /**
41717
- * The Attempt this Runtime durably claimed for a command, when that Attempt never reached a
41718
- * terminal state. A restarted Runtime has no in-memory Turn for a command it was executing before
41719
- * the restart, so this is the only record of the Attempt identity the Relay is still waiting on.
41727
+ * The Attempt this live Runtime claimed for a command that has not reached a terminal state.
41728
+ * Receipts disappear when the daemon process exits.
41720
41729
  */
41721
41730
  findUnsettledAttemptId = (commandId, sessionId) => {
41722
41731
  const row = this.#database.prepare(`SELECT attempt_id, state FROM relay_turn_receipts WHERE command_id = ? AND session_id = ?`).get(commandId, sessionId);
@@ -41765,7 +41774,7 @@ var SessionEventOutbox = class {
41765
41774
  WHERE event_id = ? AND session_id = ?`
41766
41775
  ).run(rejection.eventId, rejection.sessionId);
41767
41776
  if (deletion.changes !== 1) {
41768
- throw new Error("The rejected session event could not be removed from the durable outbox");
41777
+ throw new Error("The rejected session event could not be removed from the in-memory outbox");
41769
41778
  }
41770
41779
  this.#decrementEventState(byteLength);
41771
41780
  this.#database.exec("COMMIT");
@@ -41784,7 +41793,7 @@ var SessionEventOutbox = class {
41784
41793
  enqueueCritical = (sessionId, payload, attemptId = "") => this.#enqueueBounded(sessionId, payload, attemptId, this.#limits.criticalEventBytes);
41785
41794
  /**
41786
41795
  * Bytes still available to standard Session events. The daemon uses this to shed
41787
- * superseded streaming events instead of filling the durable outbox, so a long Turn
41796
+ * superseded streaming events instead of filling the in-memory outbox, so a long Turn
41788
41797
  * behind a slow Relay cannot make the next enqueue throw.
41789
41798
  */
41790
41799
  standardCapacityRemaining = () => {
@@ -41809,7 +41818,7 @@ var SessionEventOutbox = class {
41809
41818
  const payload = rowString(existing, "payload_json");
41810
41819
  const state = runtimeDeliveryState(existing);
41811
41820
  if (sessionId !== delivery.sessionId || payload !== delivery.payload) {
41812
- throw new Error("The Runtime delivery identity conflicts with its durable receipt");
41821
+ throw new Error("The Runtime delivery identity conflicts with its in-memory receipt");
41813
41822
  }
41814
41823
  this.#database.exec("COMMIT");
41815
41824
  return new StoredRuntimeDelivery(delivery.deliveryId, sessionId, payload, state, true);
@@ -41977,7 +41986,7 @@ var SessionEventOutbox = class {
41977
41986
  WHERE event_id = ? AND session_id = ?`
41978
41987
  ).run(eventId, sessionId);
41979
41988
  if (deletion.changes !== 1) {
41980
- throw new Error("The acknowledged session event could not be removed from the durable outbox");
41989
+ throw new Error("The acknowledged session event could not be removed from the in-memory outbox");
41981
41990
  }
41982
41991
  this.#decrementEventState(byteLength);
41983
41992
  this.#database.exec("COMMIT");
@@ -42459,7 +42468,7 @@ var DaemonSessionEventPublisher = class {
42459
42468
  };
42460
42469
  /**
42461
42470
  * Enqueue a standard event, shedding it instead of ending the daemon when the
42462
- * durable outbox is full.
42471
+ * in-memory outbox is full.
42463
42472
  *
42464
42473
  * A capacity error used to escape the coalescing timer that publishes activities,
42465
42474
  * so the process exited and every restart died on the same retained backlog. A full
@@ -42502,7 +42511,7 @@ var DaemonSessionEventPublisher = class {
42502
42511
  return;
42503
42512
  }
42504
42513
  this.#shedEventKinds.add(kind);
42505
- console.warn(`Mobius daemon is dropping durable "${kind}" events because the Session event outbox is full`);
42514
+ console.warn(`Mobius daemon is dropping queued "${kind}" events because the Session event outbox is full`);
42506
42515
  };
42507
42516
  acknowledge = (acknowledgement) => {
42508
42517
  if (!this.#outbox.acknowledge(acknowledgement)) {
@@ -43016,7 +43025,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
43016
43025
  unsupportedModelIds: modelEffort.unsupportedModelIds,
43017
43026
  valuesByModel: {}
43018
43027
  };
43019
- return createHash4("sha256").update(
43028
+ return createHash5("sha256").update(
43020
43029
  JSON.stringify({
43021
43030
  adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
43022
43031
  agentId: agent.id,
@@ -44011,7 +44020,7 @@ async function runRelayConnection(config2, directories, audit, sessions, install
44011
44020
  if (connectionController.signal.aborted) {
44012
44021
  return;
44013
44022
  }
44014
- console.error("Mobius daemon could not process a durable Runtime delivery", error62);
44023
+ console.error("Mobius daemon could not process a in-memory Runtime delivery", error62);
44015
44024
  failAndClose(
44016
44025
  new Error("Runtime delivery processing failed", { cause: error62 }),
44017
44026
  4008,
@@ -44814,8 +44823,8 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
44814
44823
  publishCatalog: async (installationSignal) => await publishAgentCatalog(config2, installationSignal),
44815
44824
  stateDirectory
44816
44825
  });
44817
- const sessionStore = new SqliteAcpSessionStore(config2.auditDatabasePath);
44818
- const outbox = new SessionEventOutbox(config2.auditDatabasePath);
44826
+ const sessionStore = new MemoryAcpSessionStore();
44827
+ const outbox = new SessionEventOutbox();
44819
44828
  const publisher = new DaemonSessionEventPublisher(outbox, timer);
44820
44829
  const activeTurns = /* @__PURE__ */ new Map();
44821
44830
  const activeAttemptIds = /* @__PURE__ */ new Map();
@@ -44827,9 +44836,14 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
44827
44836
  }
44828
44837
  publisher.recordAttempt(sessionId, event, attemptId);
44829
44838
  };
44830
- const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
44831
- read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
44832
- });
44839
+ const sessions = new AcpSessionManager(
44840
+ new DaemonAcpObserver(recordSessionEvent),
44841
+ sessionStore,
44842
+ {
44843
+ read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
44844
+ },
44845
+ "native"
44846
+ );
44833
44847
  const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
44834
44848
  const installationObserver = new DaemonInstallationObserver();
44835
44849
  const diagnostics = new RelayConnectionDiagnostics(
@@ -44965,13 +44979,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
44965
44979
  await sessions.close();
44966
44980
  } finally {
44967
44981
  try {
44968
- sessionStore.close();
44982
+ publisher.close();
44969
44983
  } finally {
44970
- try {
44971
- publisher.close();
44972
- } finally {
44973
- outbox.close();
44974
- }
44984
+ outbox.close();
44975
44985
  }
44976
44986
  }
44977
44987
  }
@@ -44982,7 +44992,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
44982
44992
 
44983
44993
  // src/runtime.ts
44984
44994
  import { mkdir as mkdir6, realpath as realpath10, stat as stat9 } from "node:fs/promises";
44985
- import { dirname as dirname8, join as join18, resolve as resolve7 } from "node:path";
44995
+ import { resolve as resolve7 } from "node:path";
44986
44996
  var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
44987
44997
  var RUNTIME_CREDENTIAL_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
44988
44998
  var MobiusRuntimeConfigurationError = class extends Error {
@@ -45039,7 +45049,6 @@ function loadMobiusRuntimeConnection(environment = process.env) {
45039
45049
  throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
45040
45050
  }
45041
45051
  return Object.freeze({
45042
- auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join18(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
45043
45052
  channelId,
45044
45053
  defaultWorkspace: loadDefaultWorkspace(environment),
45045
45054
  relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
@@ -45068,8 +45077,6 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
45068
45077
  const localContext = new DaemonLocalContext(readStateDirectory(environment), environment);
45069
45078
  const relayUrl = relayUrlFromConnection(connection);
45070
45079
  const defaultWorkspace = await resolveWorkspace(connection.defaultWorkspace);
45071
- const auditDatabasePath = resolve7(connection.auditDatabasePath);
45072
- await mkdir6(dirname8(auditDatabasePath), { recursive: true, mode: 448 });
45073
45080
  const inventory = await discoverLocalAgentInventory({
45074
45081
  defaultWorkspace,
45075
45082
  environment: localContext.environment,
@@ -45081,7 +45088,6 @@ async function createMobiusRuntimeEngine(connection, signal, environment = proce
45081
45088
  return new MobiusRuntimeEngine(
45082
45089
  createDaemonConfig(
45083
45090
  {
45084
- auditDatabasePath,
45085
45091
  channelId: connection.channelId,
45086
45092
  defaultWorkspace,
45087
45093
  relayUrl
@@ -45107,7 +45113,7 @@ var MobiusRuntimeEngine = class {
45107
45113
  }
45108
45114
  signal.throwIfAborted();
45109
45115
  this.#state = new RunningMobiusRuntimeState();
45110
- const audit = new AuditStore(this.#config.auditDatabasePath);
45116
+ const audit = new AuditStore();
45111
45117
  try {
45112
45118
  await runDaemon(this.#config, audit, signal, void 0, {
45113
45119
  ...this.#options.onConnectionStatus === void 0 ? {} : { onConnectionStatus: this.#options.onConnectionStatus },