@moxt-ai/mobius 0.0.357 → 0.0.358

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 (63) hide show
  1. package/dist/cli.js +236 -185
  2. package/dist/cli.js.map +3 -3
  3. package/dist/engine/acp/adapter/adapter-registry.d.ts +1 -1
  4. package/dist/engine/acp/adapter/adapter-registry.d.ts.map +1 -1
  5. package/dist/engine/acp/adapter/adapter-registry.js +2 -1
  6. package/dist/engine/acp/adapter/adapter-registry.js.map +1 -1
  7. package/dist/engine/acp/adapter/claude/adapter.d.ts +8 -35
  8. package/dist/engine/acp/adapter/claude/adapter.d.ts.map +1 -1
  9. package/dist/engine/acp/adapter/claude/adapter.js +7 -6
  10. package/dist/engine/acp/adapter/claude/adapter.js.map +1 -1
  11. package/dist/engine/acp/adapter/codex/adapter.d.ts +8 -35
  12. package/dist/engine/acp/adapter/codex/adapter.d.ts.map +1 -1
  13. package/dist/engine/acp/adapter/codex/adapter.js +21 -9
  14. package/dist/engine/acp/adapter/codex/adapter.js.map +1 -1
  15. package/dist/engine/acp/adapter/live-sessions.d.ts +1 -1
  16. package/dist/engine/acp/adapter/live-sessions.d.ts.map +1 -1
  17. package/dist/engine/acp/adapter/live-sessions.js +1 -0
  18. package/dist/engine/acp/adapter/live-sessions.js.map +1 -1
  19. package/dist/engine/acp/adapter/native-session-lookup.d.ts +2 -2
  20. package/dist/engine/acp/adapter/native-session-lookup.d.ts.map +1 -1
  21. package/dist/engine/acp/adapter/native-session-lookup.js +4 -4
  22. package/dist/engine/acp/adapter/native-session-lookup.js.map +1 -1
  23. package/dist/engine/acp/adapter/pi/adapter.d.ts +8 -35
  24. package/dist/engine/acp/adapter/pi/adapter.d.ts.map +1 -1
  25. package/dist/engine/acp/adapter/pi/adapter.js +7 -6
  26. package/dist/engine/acp/adapter/pi/adapter.js.map +1 -1
  27. package/dist/engine/acp/adapter/query-processes.d.ts +10 -7
  28. package/dist/engine/acp/adapter/query-processes.d.ts.map +1 -1
  29. package/dist/engine/acp/adapter/query-processes.js +66 -79
  30. package/dist/engine/acp/adapter/query-processes.js.map +1 -1
  31. package/dist/engine/acp/adapter/query-session.d.ts +6 -4
  32. package/dist/engine/acp/adapter/query-session.d.ts.map +1 -1
  33. package/dist/engine/acp/adapter/query-session.js +37 -22
  34. package/dist/engine/acp/adapter/query-session.js.map +1 -1
  35. package/dist/engine/acp/adapter/registry.js +3 -3
  36. package/dist/engine/acp/adapter/registry.js.map +1 -1
  37. package/dist/engine/acp/adapter/session-events.d.ts +1 -0
  38. package/dist/engine/acp/adapter/session-events.d.ts.map +1 -1
  39. package/dist/engine/acp/adapter/session-events.js +3 -0
  40. package/dist/engine/acp/adapter/session-events.js.map +1 -1
  41. package/dist/engine/acp/harness/codex/agent.d.ts.map +1 -1
  42. package/dist/engine/acp/harness/codex/agent.js +14 -8
  43. package/dist/engine/acp/harness/codex/agent.js.map +1 -1
  44. package/dist/engine/acp/harness/codex/borrowed-agent.d.ts.map +1 -1
  45. package/dist/engine/acp/harness/codex/borrowed-agent.js +8 -2
  46. package/dist/engine/acp/harness/codex/borrowed-agent.js.map +1 -1
  47. package/dist/engine/acp/native-history/preview-contract.d.ts +6 -13
  48. package/dist/engine/acp/native-history/preview-contract.d.ts.map +1 -1
  49. package/dist/engine/runtime/run.js +1 -1
  50. package/dist/engine/runtime/run.js.map +1 -1
  51. package/dist/engine/session/live/agent-session.d.ts +1 -1
  52. package/dist/engine/session/live/agent-session.d.ts.map +1 -1
  53. package/dist/engine/session/live/agent-session.js +2 -1
  54. package/dist/engine/session/live/agent-session.js.map +1 -1
  55. package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
  56. package/dist/engine/session/manager/session-manager.js +14 -1
  57. package/dist/engine/session/manager/session-manager.js.map +1 -1
  58. package/dist/engine/session/native/native-session-browser.d.ts.map +1 -1
  59. package/dist/engine/session/native/native-session-browser.js +8 -8
  60. package/dist/engine/session/native/native-session-browser.js.map +1 -1
  61. package/dist/engine.js +233 -178
  62. package/dist/engine.js.map +4 -4
  63. package/package.json +1 -1
package/dist/engine.js CHANGED
@@ -69128,6 +69128,7 @@ var CodexBorrowedAcpAgent = class {
69128
69128
  content,
69129
69129
  clientId: randomUUID7(),
69130
69130
  completion: Promise.withResolvers(),
69131
+ settled: Promise.withResolvers(),
69131
69132
  input: { kind: "awaiting" }
69132
69133
  };
69133
69134
  this.#pending = pending;
@@ -69165,7 +69166,6 @@ var CodexBorrowedAcpAgent = class {
69165
69166
  throw cause;
69166
69167
  } finally {
69167
69168
  signal.removeEventListener("abort", abort);
69168
- this.#pending = null;
69169
69169
  if (outcome === "cancelled") {
69170
69170
  try {
69171
69171
  await this.#removeQueuedInput(pending.clientId);
@@ -69173,6 +69173,8 @@ var CodexBorrowedAcpAgent = class {
69173
69173
  console.error("The cancelled Codex queued input could not be removed", cause);
69174
69174
  }
69175
69175
  }
69176
+ this.#pending = null;
69177
+ pending.settled.resolve();
69176
69178
  }
69177
69179
  };
69178
69180
  #removeQueuedInput = async (clientId) => {
@@ -69232,7 +69234,11 @@ var CodexBorrowedAcpAgent = class {
69232
69234
  );
69233
69235
  };
69234
69236
  cancel = async () => {
69235
- this.#pending?.completion.resolve({ stopReason: "cancelled" });
69237
+ const pending = this.#pending;
69238
+ if (pending !== null) {
69239
+ pending.completion.resolve({ stopReason: "cancelled" });
69240
+ await pending.settled.promise;
69241
+ }
69236
69242
  };
69237
69243
  close = async () => {
69238
69244
  this.#lifecycle = { kind: "closed" };
@@ -70933,16 +70939,19 @@ var CodexAcpAgent = class {
70933
70939
  */
70934
70940
  close = () => {
70935
70941
  if (this.#closePromise === null) {
70936
- this.#appServer.detach();
70937
70942
  this.#closePromise = (async () => {
70938
- await this.#sessionAgent.close();
70939
- const child = this.#appServer.child();
70940
70943
  try {
70941
- const captured = await captureProcessTree(child);
70942
- await stopProcessTree(child, captured);
70944
+ await this.#sessionAgent.close();
70943
70945
  } finally {
70944
- this.#connection?.close();
70945
- this.#onBackgroundActivity?.("none");
70946
+ this.#appServer.detach();
70947
+ const child = this.#appServer.child();
70948
+ try {
70949
+ const captured = await captureProcessTree(child);
70950
+ await stopProcessTree(child, captured);
70951
+ } finally {
70952
+ this.#connection?.close();
70953
+ this.#onBackgroundActivity?.("none");
70954
+ }
70946
70955
  }
70947
70956
  })();
70948
70957
  }
@@ -75835,6 +75844,7 @@ var AdapterRegistry = class {
75835
75844
  resolve = (agent) => {
75836
75845
  const existing = this.#adapters.get(agent.id);
75837
75846
  if (existing !== void 0) {
75847
+ existing.refreshAgent(agent);
75838
75848
  return existing;
75839
75849
  }
75840
75850
  const adapter = this.#resolve(agent, this.#dependencies);
@@ -76370,6 +76380,9 @@ var AdapterSessionConnection = class {
76370
76380
  get connection() {
76371
76381
  return this.#connection.connection;
76372
76382
  }
76383
+ get termination() {
76384
+ return this.#connection.termination;
76385
+ }
76373
76386
  initialize = (signal) => this.#connection.initialize(signal);
76374
76387
  agentSettingsModelEffort = () => this.#connection.agentSettingsModelEffort();
76375
76388
  race = (operation, exitMessage, signal) => this.#connection.race(operation, exitMessage, signal);
@@ -76483,6 +76496,7 @@ var AcpLiveSessions = class {
76483
76496
  "ACP agent exited while cancelling a prompt",
76484
76497
  bounded
76485
76498
  );
76499
+ return "retained";
76486
76500
  };
76487
76501
  closeSession = async (target, signal) => {
76488
76502
  const session = this.#find(target);
@@ -76694,7 +76708,7 @@ var lookupSchema = external_exports.object({
76694
76708
  maximumEntries: external_exports.number().int().positive().nullable()
76695
76709
  })
76696
76710
  });
76697
- async function findNativeSession(list, query, nativeSessionId, budget) {
76711
+ async function findNativeSession(list, cwd, nativeSessionId, budget, signal) {
76698
76712
  const decoded = lookupSchema.safeParse({ nativeSessionId, budget });
76699
76713
  if (!decoded.success) {
76700
76714
  throw new AcpExecutionError(
@@ -76708,9 +76722,9 @@ async function findNativeSession(list, query, nativeSessionId, budget) {
76708
76722
  let inspected = 0;
76709
76723
  const visited = /* @__PURE__ */ new Set();
76710
76724
  for (let pageNumber = 0; pageNumber < limits.maximumPages; pageNumber += 1) {
76711
- query.signal.throwIfAborted();
76712
- const page = await list(query, cursor);
76713
- query.signal.throwIfAborted();
76725
+ signal.throwIfAborted();
76726
+ const page = await list(cwd, cursor, signal);
76727
+ signal.throwIfAborted();
76714
76728
  inspected += page.sessions.length;
76715
76729
  const found = page.sessions.find((session) => session.sessionId === decoded.data.nativeSessionId);
76716
76730
  if (found !== void 0) {
@@ -76732,6 +76746,9 @@ async function findNativeSession(list, query, nativeSessionId, budget) {
76732
76746
  throw new AcpExecutionError("The native session was not found", {}, "native_session_not_found");
76733
76747
  }
76734
76748
 
76749
+ // src/engine/acp/adapter/query-processes.ts
76750
+ import { randomUUID as randomUUID14 } from "node:crypto";
76751
+
76735
76752
  // src/engine/session/history/session-event-store.ts
76736
76753
  import { randomUUID as randomUUID13 } from "node:crypto";
76737
76754
 
@@ -77440,45 +77457,51 @@ async function initializeAgentConnection(connection, agentId, verifiedVersion, s
77440
77457
 
77441
77458
  // src/engine/acp/adapter/query-session.ts
77442
77459
  var AcpQuerySession = class _AcpQuerySession {
77443
- #options;
77460
+ #cwd;
77461
+ #sessionId;
77444
77462
  #events;
77445
77463
  #connection;
77464
+ #lifecycle = { kind: "open" };
77446
77465
  #capabilities = unsupportedSessionCapabilities();
77447
77466
  #configOptions = [];
77448
- constructor(options, events, connector) {
77449
- this.#options = options;
77467
+ constructor(agent, cwd, sessionId, events, connector) {
77468
+ this.#cwd = cwd;
77469
+ this.#sessionId = sessionId;
77450
77470
  this.#events = events;
77451
77471
  this.#connection = connector.connectQuerySession({
77452
- agent: options.agent,
77453
- cwd: options.cwd,
77454
- sessionId: () => options.sessionId,
77472
+ agent,
77473
+ cwd,
77474
+ sessionId: () => sessionId,
77455
77475
  configOptions: () => this.#configOptions,
77456
77476
  onEvent: async (event) => {
77457
- this.#events.append(options.sessionId, { type: "acp", payload: event.payload });
77477
+ this.#events.append(sessionId, { type: "acp", payload: event.payload });
77458
77478
  if (event.kind === "configuration") {
77459
77479
  this.#configOptions = event.configOptions;
77460
77480
  }
77461
77481
  }
77462
77482
  });
77483
+ void this.#connection.termination.then(() => {
77484
+ this.#lifecycle = { kind: "terminated" };
77485
+ });
77463
77486
  }
77464
- static start = async (options, events, connector) => {
77487
+ static start = async (agent, cwd, sessionId, events, connector, signal) => {
77465
77488
  for (let attempt = 1; attempt <= 2; attempt += 1) {
77466
- await validateAgentRuntime(options.agent, options.signal);
77467
- const runtime = new _AcpQuerySession(options, events, connector);
77489
+ await validateAgentRuntime(agent, signal);
77490
+ const runtime = new _AcpQuerySession(agent, cwd, sessionId, events, connector);
77468
77491
  try {
77469
77492
  const initialized = await initializeAgentConnection(
77470
77493
  runtime.#connection,
77471
- options.agent.id,
77472
- options.agent.agentVersion,
77473
- options.signal
77494
+ agent.id,
77495
+ agent.agentVersion,
77496
+ signal
77474
77497
  );
77475
77498
  runtime.#capabilities = initialized.capabilities;
77476
77499
  return runtime;
77477
77500
  } catch (error62) {
77478
77501
  await runtime.closeProcess();
77479
- options.signal.throwIfAborted();
77502
+ signal.throwIfAborted();
77480
77503
  if (error62 instanceof RetryableAcpInitializationError && attempt === 1) {
77481
- console.warn(`[${options.agent.id}-acp] ACP agent initialization failed; retrying once`);
77504
+ console.warn(`[${agent.id}-acp] ACP agent initialization failed; retrying once`);
77482
77505
  continue;
77483
77506
  }
77484
77507
  if (error62 instanceof AcpExecutionError) {
@@ -77490,7 +77513,18 @@ var AcpQuerySession = class _AcpQuerySession {
77490
77513
  throw new AcpExecutionError("ACP agent initialization failed");
77491
77514
  };
77492
77515
  capabilities = () => this.#capabilities;
77493
- belongsTo = (agentId, cwd, directories) => this.#options.agent.id === agentId && this.#options.cwd === cwd && arraysEqual(this.#options.additionalDirectories, directories);
77516
+ hasTerminated = () => {
77517
+ switch (this.#lifecycle.kind) {
77518
+ case "open":
77519
+ return false;
77520
+ case "terminated":
77521
+ return true;
77522
+ default: {
77523
+ const unreachable3 = this.#lifecycle;
77524
+ return unreachable3;
77525
+ }
77526
+ }
77527
+ };
77494
77528
  listNativeSessions = async (cursor, signal) => {
77495
77529
  if (!this.#capabilities.listSessions) {
77496
77530
  throw new AcpExecutionError(
@@ -77516,7 +77550,7 @@ var AcpQuerySession = class _AcpQuerySession {
77516
77550
  }
77517
77551
  return decoded.data;
77518
77552
  };
77519
- previewEvents = async (nativeSessionId, eventLimit, signal) => {
77553
+ previewEvents = async (nativeSessionId, eventLimit, additionalDirectories, signal) => {
77520
77554
  if (!this.#capabilities.loadSession) {
77521
77555
  throw new AcpExecutionError(
77522
77556
  "This Agent restores context but does not provide message history.",
@@ -77524,14 +77558,14 @@ var AcpQuerySession = class _AcpQuerySession {
77524
77558
  "native_history_unsupported"
77525
77559
  );
77526
77560
  }
77527
- this.#events.reset(this.#options.sessionId);
77561
+ this.#events.reset(this.#sessionId);
77528
77562
  this.#connection.events.select(nativeSessionId);
77529
77563
  await this.#connection.race(
77530
77564
  this.#connection.connection.agent.request(
77531
77565
  methods12.agent.session.load,
77532
77566
  {
77533
- additionalDirectories: [...this.#options.additionalDirectories],
77534
- cwd: this.#options.cwd,
77567
+ additionalDirectories: [...additionalDirectories],
77568
+ cwd: this.#cwd,
77535
77569
  mcpServers: [],
77536
77570
  sessionId: nativeSessionId
77537
77571
  },
@@ -77542,125 +77576,105 @@ var AcpQuerySession = class _AcpQuerySession {
77542
77576
  );
77543
77577
  await this.#connection.events.drained();
77544
77578
  signal.throwIfAborted();
77545
- return this.#events.page(this.#options.sessionId, eventLimit, null);
77579
+ return this.#events.page(this.#sessionId, eventLimit, null);
77546
77580
  };
77547
77581
  closeProcess = async () => await this.#connection.closeProcess();
77582
+ discardEvents = () => this.#events.remove(this.#sessionId);
77548
77583
  };
77549
77584
 
77550
77585
  // src/engine/acp/adapter/query-processes.ts
77551
77586
  var AgentQueryProcesses = class {
77552
77587
  #eventPreviewsBySession = /* @__PURE__ */ new Map();
77553
- #processesByQuery;
77588
+ #processesByAgent = /* @__PURE__ */ new Map();
77589
+ #agent;
77554
77590
  #processes;
77555
77591
  #store = new MemorySessionEventStore();
77556
77592
  #connector;
77557
- constructor(processes, connector) {
77593
+ constructor(agent, processes, connector) {
77594
+ this.#agent = agent;
77558
77595
  this.#processes = processes;
77559
77596
  this.#connector = connector;
77560
- this.#processesByQuery = new RetainedAgentProcesses({
77561
- touch: processes.touch,
77562
- changed: processes.notifyChanged
77563
- });
77564
77597
  }
77565
- retire = async (sessionId, runtime) => {
77566
- const retained = this.#processesByQuery.detach(sessionId, runtime);
77567
- if (retained) {
77568
- this.#store.remove(sessionId);
77598
+ refreshAgent = (agent) => {
77599
+ this.#agent = agent;
77600
+ };
77601
+ retire = async (readers, cwd, runtime) => {
77602
+ readers.detach(cwd, runtime);
77603
+ try {
77604
+ await this.#processes.retire(runtime, () => runtime.closeProcess());
77605
+ } finally {
77606
+ runtime.discardEvents();
77569
77607
  }
77570
- await this.#processes.retire(runtime, () => runtime.closeProcess());
77571
77608
  };
77572
- async #startRetained(options) {
77573
- const runtime = await this.#processes.startRetained(
77574
- options.signal,
77575
- () => AcpQuerySession.start(options, this.#store, this.#connector),
77576
- {
77577
- isBusy: () => this.#processesByQuery.isBusy(options.sessionId),
77578
- retire: (runtime2) => this.retire(options.sessionId, runtime2),
77579
- retireIdle: (runtime2) => this.retire(options.sessionId, runtime2)
77580
- }
77581
- );
77582
- this.#processesByQuery.retain(options.sessionId, runtime);
77583
- return runtime;
77584
- }
77585
- async #startPreparation(options) {
77586
- return await this.#processesByQuery.prepare(options.sessionId, async () => {
77587
- return await this.#startRetained(options);
77588
- });
77589
- }
77590
- async #replacePreparation(existing, options) {
77591
- return await this.#processesByQuery.prepare(options.sessionId, async () => {
77592
- await this.retire(options.sessionId, existing);
77593
- return await this.#startRetained(options);
77594
- });
77595
- }
77596
- #prepare = async (options) => {
77597
- const pending = this.#processesByQuery.pending(options.sessionId);
77609
+ async #ensure(agent, readers, cwd, signal) {
77610
+ signal.throwIfAborted();
77611
+ const pending = readers.pending(cwd);
77598
77612
  if (pending !== void 0) {
77599
- const runtime2 = await waitForSharedOperation(pending, options.signal);
77600
- if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
77601
- this.#processesByQuery.touch(options.sessionId, runtime2);
77602
- return runtime2.capabilities();
77603
- }
77604
- return await this.#prepare(options);
77605
- }
77606
- const existing = this.#processesByQuery.get(options.sessionId);
77607
- if (existing !== void 0) {
77608
- if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
77609
- this.#processesByQuery.touch(options.sessionId, existing);
77610
- return existing.capabilities();
77611
- }
77612
- const runtime2 = await this.#replacePreparation(existing, options);
77613
- return runtime2.capabilities();
77613
+ return await waitForSharedOperation(pending, signal);
77614
77614
  }
77615
- const runtime = await this.#startPreparation(options);
77616
- return runtime.capabilities();
77617
- };
77618
- async #ensure(options) {
77619
- const existing = this.#processesByQuery.get(options.sessionId);
77620
- if (existing !== void 0) {
77621
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
77622
- throw new AcpExecutionError(
77623
- "The agent or workspace cannot change after a conversation has started",
77624
- {},
77625
- "session_identity_mismatch"
77626
- );
77627
- }
77628
- this.#processesByQuery.touch(options.sessionId, existing);
77615
+ const existing = readers.get(cwd);
77616
+ if (existing !== void 0 && !existing.hasTerminated()) {
77617
+ readers.touch(cwd, existing);
77629
77618
  return existing;
77630
77619
  }
77631
- await this.#prepare(options);
77632
- const started = this.#processesByQuery.get(options.sessionId);
77633
- if (started === void 0) {
77634
- throw new AcpExecutionError("ACP native session browser did not start");
77635
- }
77636
- return started;
77620
+ return await readers.prepare(cwd, async () => {
77621
+ if (existing !== void 0) {
77622
+ await this.retire(readers, cwd, existing);
77623
+ }
77624
+ const readerId = randomUUID14();
77625
+ const runtime = await this.#processes.startRetained(
77626
+ signal,
77627
+ () => AcpQuerySession.start(agent, cwd, readerId, this.#store, this.#connector, signal),
77628
+ {
77629
+ isBusy: () => readers.isBusy(cwd),
77630
+ retire: (runtime2) => this.retire(readers, cwd, runtime2),
77631
+ retireIdle: (runtime2) => this.retire(readers, cwd, runtime2)
77632
+ }
77633
+ );
77634
+ readers.retain(cwd, runtime);
77635
+ return runtime;
77636
+ });
77637
77637
  }
77638
- #use = async (options, operation) => await this.#processesByQuery.use(options.sessionId, async () => await operation(await this.#ensure(options)));
77639
- capabilities = async (query) => await this.#prepare(query);
77640
- listNativeSessions = async (query, cursor) => await this.#use(query, async (runtime) => await runtime.listNativeSessions(cursor, query.signal));
77641
- previewSessionEvents = async (options, request) => {
77642
- const { nativeSessionId, eventLimit, cursor } = request;
77638
+ #use = async (cwd, signal, operation) => {
77639
+ const agent = this.#agent;
77640
+ let readers = this.#processesByAgent.get(agent);
77641
+ if (readers === void 0) {
77642
+ readers = new RetainedAgentProcesses({
77643
+ touch: this.#processes.touch,
77644
+ changed: this.#processes.notifyChanged
77645
+ });
77646
+ this.#processesByAgent.set(agent, readers);
77647
+ }
77648
+ const current = readers;
77649
+ return await current.use(cwd, async () => await operation(await this.#ensure(agent, current, cwd, signal)));
77650
+ };
77651
+ capabilities = async (cwd, signal) => await this.#use(cwd, signal, async (runtime) => runtime.capabilities());
77652
+ listNativeSessions = async (cwd, cursor, signal) => await this.#use(cwd, signal, async (runtime) => await runtime.listNativeSessions(cursor, signal));
77653
+ previewSessionEvents = async (cwd, additionalDirectories, request, signal) => {
77654
+ signal.throwIfAborted();
77655
+ const agent = this.#agent;
77656
+ const { nativeSessionId, eventLimit, cursor, sessionId } = request;
77643
77657
  if (cursor !== null) {
77644
- const preview = this.#eventPreviewsBySession.get(options.sessionId);
77658
+ const preview = this.#eventPreviewsBySession.get(sessionId);
77645
77659
  if (preview === void 0 || preview.nativeSessionId !== nativeSessionId) {
77646
77660
  throw new Error("The native event cursor is invalid");
77647
77661
  }
77648
- return preview.store.page(options.sessionId, eventLimit, cursor);
77662
+ return preview.store.page(sessionId, eventLimit, cursor);
77649
77663
  }
77650
77664
  const store = new MemorySessionEventStore();
77651
- const previous = this.#eventPreviewsBySession.get(options.sessionId);
77665
+ const previous = this.#eventPreviewsBySession.get(sessionId);
77652
77666
  previous?.store.close();
77653
- this.#eventPreviewsBySession.set(options.sessionId, { nativeSessionId, store });
77667
+ this.#eventPreviewsBySession.set(sessionId, { nativeSessionId, store });
77654
77668
  try {
77655
77669
  return await this.#processes.runTransient(
77656
- options.signal,
77657
- async () => await AcpQuerySession.start(options, store, this.#connector),
77658
- async (runtime) => await runtime.previewEvents(nativeSessionId, eventLimit, options.signal),
77670
+ signal,
77671
+ async () => await AcpQuerySession.start(agent, cwd, sessionId, store, this.#connector, signal),
77672
+ async (runtime) => await runtime.previewEvents(nativeSessionId, eventLimit, additionalDirectories, signal),
77659
77673
  async (runtime) => await runtime.closeProcess()
77660
77674
  );
77661
77675
  } catch (error62) {
77662
- if (this.#eventPreviewsBySession.get(options.sessionId)?.store === store) {
77663
- this.#eventPreviewsBySession.delete(options.sessionId);
77676
+ if (this.#eventPreviewsBySession.get(sessionId)?.store === store) {
77677
+ this.#eventPreviewsBySession.delete(sessionId);
77664
77678
  }
77665
77679
  store.close();
77666
77680
  throw error62;
@@ -77668,8 +77682,11 @@ var AgentQueryProcesses = class {
77668
77682
  };
77669
77683
  close = async () => {
77670
77684
  await Promise.all(
77671
- this.#processesByQuery.entries().map(async ([id, runtime]) => await this.retire(id, runtime))
77685
+ [...this.#processesByAgent.values()].flatMap(
77686
+ (readers) => readers.entries().map(async ([cwd, runtime]) => await this.retire(readers, cwd, runtime))
77687
+ )
77672
77688
  );
77689
+ this.#processesByAgent.clear();
77673
77690
  for (const preview of this.#eventPreviewsBySession.values()) {
77674
77691
  preview.store.close();
77675
77692
  }
@@ -77683,12 +77700,13 @@ var ClaudeAdapter = class {
77683
77700
  #queryProcesses;
77684
77701
  #connector;
77685
77702
  #liveSessions;
77686
- constructor(dependencies) {
77703
+ constructor(agent, dependencies) {
77687
77704
  this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
77688
77705
  this.#liveSessions = new AcpLiveSessions(dependencies.contentExternalizer);
77689
- this.#queryProcesses = new AgentQueryProcesses(dependencies.processes, this.#connector);
77706
+ this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
77690
77707
  }
77691
- getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
77708
+ refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
77709
+ getCapabilities = (cwd, signal) => this.#queryProcesses.capabilities(cwd, signal);
77692
77710
  connectSession = (options) => this.#liveSessions.connectSession(options);
77693
77711
  cancel = (...args) => this.#liveSessions.cancel(...args);
77694
77712
  closeSession = (...args) => this.#liveSessions.closeSession(...args);
@@ -77696,9 +77714,9 @@ var ClaudeAdapter = class {
77696
77714
  steer = (...args) => this.#liveSessions.steer(...args);
77697
77715
  renameSession = (...args) => this.#liveSessions.renameSession(...args);
77698
77716
  configureSession = (...args) => this.#liveSessions.configureSession(...args);
77699
- listSessions = async (query, cursor) => await this.#queryProcesses.listNativeSessions(query, cursor);
77700
- findSession = (query, nativeSessionId, budget) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
77701
- readSessionHistory = async (query, request) => await this.#queryProcesses.previewSessionEvents(query, request);
77717
+ listSessions = (cwd, cursor, signal) => this.#queryProcesses.listNativeSessions(cwd, cursor, signal);
77718
+ findSession = (cwd, nativeSessionId, budget, signal) => findNativeSession(this.listSessions, cwd, nativeSessionId, budget, signal);
77719
+ readSessionHistory = (cwd, additionalDirectories, request, signal) => this.#queryProcesses.previewSessionEvents(cwd, additionalDirectories, request, signal);
77702
77720
  close = async () => await runCleanup(
77703
77721
  () => this.#queryProcesses.close(),
77704
77722
  () => this.#liveSessions.close()
@@ -83003,13 +83021,15 @@ function fitCodexToolEvent(event) {
83003
83021
 
83004
83022
  // src/engine/acp/adapter/codex/adapter.ts
83005
83023
  var CodexAdapter = class {
83024
+ #agent;
83006
83025
  #queryProcesses;
83007
83026
  #connector;
83008
83027
  #liveSessions;
83009
83028
  #dependencies;
83010
83029
  #contentExternalizer;
83011
83030
  #previewCache = null;
83012
- constructor(dependencies) {
83031
+ constructor(agent, dependencies) {
83032
+ this.#agent = agent;
83013
83033
  this.#dependencies = dependencies;
83014
83034
  this.#contentExternalizer = {
83015
83035
  update: async (sessionId, update, signal) => {
@@ -83021,18 +83041,25 @@ var CodexAdapter = class {
83021
83041
  };
83022
83042
  this.#connector = new AcpSessionConnector(this.#contentExternalizer, fitCodexToolEvent);
83023
83043
  this.#liveSessions = new AcpLiveSessions(this.#contentExternalizer, fitCodexToolEvent);
83024
- this.#queryProcesses = new AgentQueryProcesses(dependencies.processes, this.#connector);
83044
+ this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
83025
83045
  }
83026
- getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
83046
+ refreshAgent = (agent) => {
83047
+ this.#agent = agent;
83048
+ this.#queryProcesses.refreshAgent(agent);
83049
+ };
83050
+ getCapabilities = (cwd, signal) => this.#queryProcesses.capabilities(cwd, signal);
83027
83051
  connectSession = (options) => this.#liveSessions.connectSession(options);
83028
- cancel = (...args) => this.#liveSessions.cancel(...args);
83052
+ cancel = async (target, signal) => {
83053
+ await this.#liveSessions.closeSession(target, signal);
83054
+ return "closed";
83055
+ };
83029
83056
  closeSession = (...args) => this.#liveSessions.closeSession(...args);
83030
83057
  prompt = (...args) => this.#liveSessions.prompt(...args);
83031
83058
  steer = (...args) => this.#liveSessions.steer(...args);
83032
83059
  renameSession = (...args) => this.#liveSessions.renameSession(...args);
83033
83060
  configureSession = (...args) => this.#liveSessions.configureSession(...args);
83034
- listSessions = async (query, cursor) => await this.#queryProcesses.listNativeSessions(query, cursor);
83035
- findSession = (query, nativeSessionId, budget) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
83061
+ listSessions = (cwd, cursor, signal) => this.#queryProcesses.listNativeSessions(cwd, cursor, signal);
83062
+ findSession = (cwd, nativeSessionId, budget, signal) => findNativeSession(this.listSessions, cwd, nativeSessionId, budget, signal);
83036
83063
  close = async () => {
83037
83064
  await runCleanup(
83038
83065
  () => this.#queryProcesses.close(),
@@ -83040,9 +83067,9 @@ var CodexAdapter = class {
83040
83067
  () => this.#previewCache?.close()
83041
83068
  );
83042
83069
  };
83043
- readSessionHistory = async (query, request) => {
83044
- const { agent, cwd } = query;
83045
- const signal = AbortSignal.any([query.signal, AbortSignal.timeout(6e4)]);
83070
+ readSessionHistory = async (cwd, _additionalDirectories, request, cancellation) => {
83071
+ const agent = this.#agent;
83072
+ const signal = AbortSignal.any([cancellation, AbortSignal.timeout(6e4)]);
83046
83073
  const { sessionId } = request;
83047
83074
  signal.throwIfAborted();
83048
83075
  nativeSessionIdSchema.parse(request.nativeSessionId);
@@ -83118,12 +83145,13 @@ var PiAdapter = class {
83118
83145
  #queryProcesses;
83119
83146
  #connector;
83120
83147
  #liveSessions;
83121
- constructor(dependencies) {
83148
+ constructor(agent, dependencies) {
83122
83149
  this.#connector = new AcpSessionConnector(dependencies.contentExternalizer);
83123
83150
  this.#liveSessions = new AcpLiveSessions(dependencies.contentExternalizer);
83124
- this.#queryProcesses = new AgentQueryProcesses(dependencies.processes, this.#connector);
83151
+ this.#queryProcesses = new AgentQueryProcesses(agent, dependencies.processes, this.#connector);
83125
83152
  }
83126
- getCapabilities = async (query) => await this.#queryProcesses.capabilities(query);
83153
+ refreshAgent = (agent) => this.#queryProcesses.refreshAgent(agent);
83154
+ getCapabilities = (cwd, signal) => this.#queryProcesses.capabilities(cwd, signal);
83127
83155
  connectSession = (options) => this.#liveSessions.connectSession(options);
83128
83156
  cancel = (...args) => this.#liveSessions.cancel(...args);
83129
83157
  closeSession = (...args) => this.#liveSessions.closeSession(...args);
@@ -83131,9 +83159,9 @@ var PiAdapter = class {
83131
83159
  steer = (...args) => this.#liveSessions.steer(...args);
83132
83160
  renameSession = (...args) => this.#liveSessions.renameSession(...args);
83133
83161
  configureSession = (...args) => this.#liveSessions.configureSession(...args);
83134
- listSessions = async (query, cursor) => await this.#queryProcesses.listNativeSessions(query, cursor);
83135
- findSession = (query, nativeSessionId, budget) => findNativeSession(this.listSessions, query, nativeSessionId, budget);
83136
- readSessionHistory = async (query, request) => await this.#queryProcesses.previewSessionEvents(query, request);
83162
+ listSessions = (cwd, cursor, signal) => this.#queryProcesses.listNativeSessions(cwd, cursor, signal);
83163
+ findSession = (cwd, nativeSessionId, budget, signal) => findNativeSession(this.listSessions, cwd, nativeSessionId, budget, signal);
83164
+ readSessionHistory = (cwd, additionalDirectories, request, signal) => this.#queryProcesses.previewSessionEvents(cwd, additionalDirectories, request, signal);
83137
83165
  close = async () => await runCleanup(
83138
83166
  () => this.#queryProcesses.close(),
83139
83167
  () => this.#liveSessions.close()
@@ -83144,11 +83172,11 @@ var PiAdapter = class {
83144
83172
  var harnessAdapters = (agent, dependencies) => {
83145
83173
  switch (agent.id) {
83146
83174
  case "codex":
83147
- return new CodexAdapter(dependencies);
83175
+ return new CodexAdapter(agent, dependencies);
83148
83176
  case "claude":
83149
- return new ClaudeAdapter(dependencies);
83177
+ return new ClaudeAdapter(agent, dependencies);
83150
83178
  case "pi":
83151
- return new PiAdapter(dependencies);
83179
+ return new PiAdapter(agent, dependencies);
83152
83180
  default:
83153
83181
  throw new AcpExecutionError(
83154
83182
  `Agent "${agent.id}" has no registered harness adapter.`,
@@ -86156,8 +86184,9 @@ var AgentSession = class _AgentSession {
86156
86184
  await this.#interactions.cancelPendingInteractions();
86157
86185
  signal.throwIfAborted();
86158
86186
  if (this.#turn.running) {
86159
- await this.#adapter.cancel(this.#target(), signal);
86187
+ return await this.#adapter.cancel(this.#target(), signal);
86160
86188
  }
86189
+ return "retained";
86161
86190
  };
86162
86191
  respondPermission = async (options) => {
86163
86192
  await this.#interactions.respondPermission(options);
@@ -86798,7 +86827,18 @@ var SessionManager2 = class {
86798
86827
  await this.#executions.cancel(sessionId, async () => {
86799
86828
  const runtime = this.#executionProcesses.get(sessionId);
86800
86829
  if (runtime !== void 0) {
86801
- await runtime.cancel(signal2);
86830
+ const outcome = await runtime.cancel(signal2);
86831
+ switch (outcome) {
86832
+ case "retained":
86833
+ break;
86834
+ case "closed":
86835
+ await this.#stopSessionProcess(sessionId, runtime);
86836
+ break;
86837
+ default: {
86838
+ const unreachable3 = outcome;
86839
+ throw new AcpExecutionError("Unexpected cancellation outcome", { cause: unreachable3 });
86840
+ }
86841
+ }
86802
86842
  }
86803
86843
  });
86804
86844
  });
@@ -87164,7 +87204,7 @@ var SessionManager2 = class {
87164
87204
  };
87165
87205
 
87166
87206
  // src/engine/session/native/native-session-browser.ts
87167
- import { randomUUID as randomUUID14 } from "node:crypto";
87207
+ import { randomUUID as randomUUID15 } from "node:crypto";
87168
87208
 
87169
87209
  // src/engine/session/workspace/local-authorization-error.ts
87170
87210
  var LocalAuthorizationError = class extends OperationError {
@@ -87223,12 +87263,17 @@ var NativeSessionService = class {
87223
87263
  (scoped) => this.#sessions.withNativeSessionOperation(
87224
87264
  scoped,
87225
87265
  nativeSessionId,
87226
- (target) => target.adapter.readSessionHistory(target, {
87227
- nativeSessionId,
87228
- eventLimit,
87229
- cursor,
87230
- sessionId: target.sessionId
87231
- })
87266
+ (target) => target.adapter.readSessionHistory(
87267
+ target.cwd,
87268
+ target.additionalDirectories,
87269
+ {
87270
+ nativeSessionId,
87271
+ eventLimit,
87272
+ cursor,
87273
+ sessionId: target.sessionId
87274
+ },
87275
+ target.signal
87276
+ )
87232
87277
  )
87233
87278
  );
87234
87279
  #execute = async (command, signal) => {
@@ -87259,7 +87304,7 @@ var NativeSessionService = class {
87259
87304
  queuedCancellation: "before-start"
87260
87305
  };
87261
87306
  }
87262
- const capabilities = await options.adapter.getCapabilities(options);
87307
+ const capabilities = await options.adapter.getCapabilities(cwd, signal);
87263
87308
  if (!capabilities.listSessions) {
87264
87309
  throw new AcpExecutionError(
87265
87310
  "This Agent does not support native session listing",
@@ -87274,7 +87319,7 @@ var NativeSessionService = class {
87274
87319
  if (authorized === null) {
87275
87320
  return null;
87276
87321
  }
87277
- const entryId = decodeIdentifier(randomUUID14());
87322
+ const entryId = decodeIdentifier(randomUUID15());
87278
87323
  if (this.#entries.size >= 5e3) {
87279
87324
  this.#entries.clear();
87280
87325
  }
@@ -87313,7 +87358,7 @@ var NativeSessionService = class {
87313
87358
  }
87314
87359
  cursor = known.cursor;
87315
87360
  }
87316
- const page = await options.adapter.listSessions(options, cursor);
87361
+ const page = await options.adapter.listSessions(cwd, cursor, signal);
87317
87362
  const entries = [];
87318
87363
  for (const info of page.sessions) {
87319
87364
  const entry = await register(info);
@@ -87330,7 +87375,7 @@ var NativeSessionService = class {
87330
87375
  "invalid_native_session_response"
87331
87376
  );
87332
87377
  }
87333
- nextCursor = decodeIdentifier(randomUUID14());
87378
+ nextCursor = decodeIdentifier(randomUUID15());
87334
87379
  if (this.#cursors.size >= 500) {
87335
87380
  this.#cursors.clear();
87336
87381
  }
@@ -87348,10 +87393,15 @@ var NativeSessionService = class {
87348
87393
  };
87349
87394
  }
87350
87395
  if (command.action === "find") {
87351
- const found = await options.adapter.findSession(options, command.nativeSessionId, {
87352
- maximumPages: 500,
87353
- maximumEntries: 500
87354
- });
87396
+ const found = await options.adapter.findSession(
87397
+ cwd,
87398
+ command.nativeSessionId,
87399
+ {
87400
+ maximumPages: 500,
87401
+ maximumEntries: 500
87402
+ },
87403
+ signal
87404
+ );
87355
87405
  const entry = await register(found);
87356
87406
  if (entry !== null) {
87357
87407
  return { ...envelope2, action: "find", entry };
@@ -87489,10 +87539,15 @@ var NativeSessionService = class {
87489
87539
  }
87490
87540
  };
87491
87541
  resolveTarget = async (command, options, selected) => {
87492
- const info = await options.adapter.findSession(options, selected.nativeSessionId, {
87493
- maximumPages: 100,
87494
- maximumEntries: null
87495
- }).catch((cause) => {
87542
+ const info = await options.adapter.findSession(
87543
+ options.cwd,
87544
+ selected.nativeSessionId,
87545
+ {
87546
+ maximumPages: 100,
87547
+ maximumEntries: null
87548
+ },
87549
+ options.signal
87550
+ ).catch((cause) => {
87496
87551
  options.signal.throwIfAborted();
87497
87552
  if (cause instanceof AcpExecutionError && cause.code === "native_session_not_found") {
87498
87553
  throw new AcpExecutionError(
@@ -87761,7 +87816,7 @@ async function settleAbandonedTurn(projection, operations, cancellation) {
87761
87816
  }
87762
87817
 
87763
87818
  // src/engine/session/turn/execution-receipts.ts
87764
- import { createHash as createHash7, randomUUID as randomUUID15 } from "node:crypto";
87819
+ import { createHash as createHash7, randomUUID as randomUUID16 } from "node:crypto";
87765
87820
  var MAX_TERMINAL_RECEIPTS = 1024;
87766
87821
  var ExecutionReceipts = class {
87767
87822
  #executions = /* @__PURE__ */ new Map();
@@ -87902,7 +87957,7 @@ var ExecutionReceipts = class {
87902
87957
  ).digest("hex");
87903
87958
  this.#save(commandId, {
87904
87959
  admissionOrder: this.#nextAdmissionOrder(),
87905
- attemptId: randomUUID15(),
87960
+ attemptId: randomUUID16(),
87906
87961
  commandHash,
87907
87962
  sessionId,
87908
87963
  started: false,
@@ -87984,7 +88039,7 @@ var ExecutionReceipts = class {
87984
88039
  if (identity2 !== void 0) {
87985
88040
  return identity2.sessionId === sessionId && identity2.commandHash === commandHash ? { kind: "expired" } : { kind: "conflict" };
87986
88041
  }
87987
- const attemptId = randomUUID15();
88042
+ const attemptId = randomUUID16();
87988
88043
  this.#save(commandId, {
87989
88044
  admissionOrder: this.#nextAdmissionOrder(),
87990
88045
  attemptId,
@@ -88111,7 +88166,7 @@ var RuntimeTurnActivity = class {
88111
88166
  };
88112
88167
 
88113
88168
  // src/engine/session/turn/active-turn.ts
88114
- import { randomUUID as randomUUID16 } from "node:crypto";
88169
+ import { randomUUID as randomUUID17 } from "node:crypto";
88115
88170
  var ActiveRuntimeTurn = class {
88116
88171
  attemptId;
88117
88172
  command;
@@ -88121,7 +88176,7 @@ var ActiveRuntimeTurn = class {
88121
88176
  #dispatch;
88122
88177
  #sequence = 0;
88123
88178
  #interaction = null;
88124
- #epoch = decodeIdentifier(randomUUID16());
88179
+ #epoch = decodeIdentifier(randomUUID17());
88125
88180
  constructor(command, attemptId) {
88126
88181
  this.attemptId = attemptId;
88127
88182
  this.command = command;
@@ -88687,11 +88742,11 @@ import { extname as extname2, join as join29 } from "node:path";
88687
88742
  import { pathToFileURL as pathToFileURL3 } from "node:url";
88688
88743
 
88689
88744
  // src/engine/storage/files/scratch-directory.ts
88690
- import { randomUUID as randomUUID17 } from "node:crypto";
88745
+ import { randomUUID as randomUUID18 } from "node:crypto";
88691
88746
  import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile6, realpath as realpath7, rename as rename4, rm as rm3, stat as stat6, utimes, writeFile as writeFile2 } from "node:fs/promises";
88692
88747
  import { dirname as dirname11, join as join28 } from "node:path";
88693
88748
  async function atomicWrite(path7, bytes, signal) {
88694
- const temporary = `${path7}.${randomUUID17()}.tmp`;
88749
+ const temporary = `${path7}.${randomUUID18()}.tmp`;
88695
88750
  try {
88696
88751
  await writeFile2(temporary, bytes, { mode: 384, signal });
88697
88752
  signal.throwIfAborted();
@@ -88703,7 +88758,7 @@ async function atomicWrite(path7, bytes, signal) {
88703
88758
  var ScratchDirectory = class {
88704
88759
  #root;
88705
88760
  constructor(parent) {
88706
- this.#root = join28(parent, randomUUID17());
88761
+ this.#root = join28(parent, randomUUID18());
88707
88762
  }
88708
88763
  /** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
88709
88764
  refreshLease = async (leaseMilliseconds) => {
@@ -90709,7 +90764,7 @@ function createNativeSessionCommands(context) {
90709
90764
  }
90710
90765
 
90711
90766
  // src/engine/session/prompt/apply-session-configuration.ts
90712
- import { randomUUID as randomUUID18 } from "node:crypto";
90767
+ import { randomUUID as randomUUID19 } from "node:crypto";
90713
90768
  function invalidSessionConfiguration(message) {
90714
90769
  return new AcpExecutionError(message, {}, "invalid_session_configuration");
90715
90770
  }
@@ -90847,7 +90902,7 @@ async function applySessionConfigurationSelection(sessions, options, selection,
90847
90902
  booleanValue: selection.booleanValue,
90848
90903
  configId: selection.configId,
90849
90904
  cwd,
90850
- requestId: `cfg_${randomUUID18()}`,
90905
+ requestId: `cfg_${randomUUID19()}`,
90851
90906
  sessionId,
90852
90907
  signal,
90853
90908
  value: selection.value,
@@ -91137,7 +91192,7 @@ var sessionPromptCommand = {
91137
91192
  // package.json
91138
91193
  var package_default = {
91139
91194
  name: "@moxt-ai/mobius",
91140
- version: "0.0.357",
91195
+ version: "0.0.358",
91141
91196
  description: "Mobius CLI for pairing and running local AI agent services.",
91142
91197
  type: "module",
91143
91198
  bin: {
@@ -92409,7 +92464,7 @@ async function runRuntime(config2, parentSignal, timer = systemTimer, options =
92409
92464
  const catalogAgent = await resolveCatalogAgent(config2, agentId, resolveSignal);
92410
92465
  const environment = sessionId === void 0 ? void 0 : config2.sessionEnvironment?.({ sessionId, agentId });
92411
92466
  const agent = environment === void 0 ? catalogAgent : catalogAgent.withEnvironment({ ...catalogAgent.environment, ...environment });
92412
- return { agent, adapter: adapters.resolve(agent) };
92467
+ return { agent, adapter: adapters.resolve(catalogAgent) };
92413
92468
  };
92414
92469
  const layer = buildSessionLayer({
92415
92470
  processes,