@moxt-ai/mobius 0.0.126 → 0.0.127

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.
@@ -58,19 +58,6 @@ export declare class DaemonTurnRegistry {
58
58
  truncated: boolean;
59
59
  epoch: string;
60
60
  interaction: Readonly<{
61
- commandId: string;
62
- interactionId: string;
63
- kind: "session.permission.requested";
64
- options: readonly Readonly<{
65
- kind: "allow_always" | "allow_once" | "reject_always" | "reject_once";
66
- name: string;
67
- optionId: string;
68
- }>[];
69
- sessionId: string;
70
- title: string;
71
- toolCallId: string;
72
- toolKind: string;
73
- }> | Readonly<{
74
61
  accepted: boolean;
75
62
  commandId: string;
76
63
  elicitationId: string;
@@ -102,6 +89,19 @@ export declare class DaemonTurnRegistry {
102
89
  mode: "form" | "url";
103
90
  sessionId: string;
104
91
  url: string;
92
+ }> | Readonly<{
93
+ commandId: string;
94
+ interactionId: string;
95
+ kind: "session.permission.requested";
96
+ options: readonly Readonly<{
97
+ kind: "allow_always" | "allow_once" | "reject_always" | "reject_once";
98
+ name: string;
99
+ optionId: string;
100
+ }>[];
101
+ sessionId: string;
102
+ title: string;
103
+ toolCallId: string;
104
+ toolKind: string;
105
105
  }> | null;
106
106
  sequence: number;
107
107
  state: "running";
package/dist/index.js CHANGED
@@ -22373,6 +22373,30 @@ function loadDaemonConfig() {
22373
22373
  );
22374
22374
  }
22375
22375
 
22376
+ // src/acp/acp-error.ts
22377
+ var AcpExecutionError = class extends Error {
22378
+ code;
22379
+ constructor(message, options = {}, code = "acp_execution_failed") {
22380
+ super(message, options);
22381
+ this.code = code;
22382
+ this.name = "AcpExecutionError";
22383
+ }
22384
+ };
22385
+ var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
22386
+ configId;
22387
+ offeredValueCount;
22388
+ offeredValues;
22389
+ requestedValue;
22390
+ constructor(configId, requestedValue, offeredValues) {
22391
+ super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
22392
+ this.name = "AcpConfigurationValueUnavailableError";
22393
+ this.configId = configId.slice(0, 128);
22394
+ this.requestedValue = requestedValue.slice(0, 128);
22395
+ this.offeredValueCount = offeredValues.length;
22396
+ this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
22397
+ }
22398
+ };
22399
+
22376
22400
  // src/acp/process-session.ts
22377
22401
  import {
22378
22402
  methods as methods3,
@@ -22676,30 +22700,6 @@ async function replaceImageMarkers(text2, replace) {
22676
22700
  return `${rewritten}${text2.slice(cursor)}`;
22677
22701
  }
22678
22702
 
22679
- // src/acp/acp-error.ts
22680
- var AcpExecutionError = class extends Error {
22681
- code;
22682
- constructor(message, options = {}, code = "acp_execution_failed") {
22683
- super(message, options);
22684
- this.code = code;
22685
- this.name = "AcpExecutionError";
22686
- }
22687
- };
22688
- var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
22689
- configId;
22690
- offeredValueCount;
22691
- offeredValues;
22692
- requestedValue;
22693
- constructor(configId, requestedValue, offeredValues) {
22694
- super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
22695
- this.name = "AcpConfigurationValueUnavailableError";
22696
- this.configId = configId.slice(0, 128);
22697
- this.requestedValue = requestedValue.slice(0, 128);
22698
- this.offeredValueCount = offeredValues.length;
22699
- this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
22700
- }
22701
- };
22702
-
22703
22703
  // src/acp/activity.ts
22704
22704
  var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
22705
22705
  var AcpActivityNarration = class {
@@ -31262,6 +31262,116 @@ var RetainedSessions = class {
31262
31262
  };
31263
31263
  };
31264
31264
 
31265
+ // src/acp/native-session-browsers.ts
31266
+ var NativeSessionBrowsers = class {
31267
+ #sessions;
31268
+ #processes;
31269
+ #observer = new NullAcpSessionObserver();
31270
+ #store = new MemoryAcpSessionStore();
31271
+ constructor(processes) {
31272
+ this.#processes = processes;
31273
+ this.#sessions = new RetainedSessions({ touch: processes.touch, changed: processes.notifyChanged });
31274
+ }
31275
+ retire = async (sessionId, runtime) => {
31276
+ const retained = this.#sessions.detach(sessionId, runtime);
31277
+ if (retained) {
31278
+ this.#store.remove(sessionId);
31279
+ }
31280
+ await this.#processes.retire(runtime, () => runtime.close());
31281
+ };
31282
+ async #startRetained(options) {
31283
+ const runtime = await this.#processes.startRetained(
31284
+ options.signal,
31285
+ () => AcpProcessSession.startNativeSessionBrowser(options, () => this.#observer, this.#store),
31286
+ {
31287
+ isBusy: () => this.#sessions.isBusy(options.sessionId),
31288
+ retire: (runtime2) => this.retire(options.sessionId, runtime2)
31289
+ }
31290
+ );
31291
+ this.#sessions.retain(options.sessionId, runtime);
31292
+ return runtime;
31293
+ }
31294
+ async #startPreparation(options) {
31295
+ return await this.#sessions.prepare(options.sessionId, async () => {
31296
+ return await this.#startRetained(options);
31297
+ });
31298
+ }
31299
+ async #replacePreparation(existing, options) {
31300
+ return await this.#sessions.prepare(options.sessionId, async () => {
31301
+ await this.retire(options.sessionId, existing);
31302
+ return await this.#startRetained(options);
31303
+ });
31304
+ }
31305
+ prepare = async (options) => {
31306
+ const pending = this.#sessions.pending(options.sessionId);
31307
+ if (pending !== void 0) {
31308
+ const runtime2 = await pending;
31309
+ if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31310
+ this.#sessions.touch(options.sessionId, runtime2);
31311
+ return runtime2.prepared();
31312
+ }
31313
+ return await this.prepare(options);
31314
+ }
31315
+ const existing = this.#sessions.get(options.sessionId);
31316
+ if (existing !== void 0) {
31317
+ if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31318
+ this.#sessions.touch(options.sessionId, existing);
31319
+ return existing.prepared();
31320
+ }
31321
+ if (!existing.canRebind()) {
31322
+ throw new AcpExecutionError(
31323
+ "The agent or workspace cannot change after a conversation has started",
31324
+ {},
31325
+ "session_identity_mismatch"
31326
+ );
31327
+ }
31328
+ const runtime2 = await this.#replacePreparation(existing, options);
31329
+ return runtime2.prepared();
31330
+ }
31331
+ const runtime = await this.#startPreparation(options);
31332
+ return runtime.prepared();
31333
+ };
31334
+ async #ensure(options) {
31335
+ const existing = this.#sessions.get(options.sessionId);
31336
+ if (existing !== void 0) {
31337
+ if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31338
+ throw new AcpExecutionError(
31339
+ "The agent or workspace cannot change after a conversation has started",
31340
+ {},
31341
+ "session_identity_mismatch"
31342
+ );
31343
+ }
31344
+ this.#sessions.touch(options.sessionId, existing);
31345
+ return existing;
31346
+ }
31347
+ await this.prepare(options);
31348
+ const started = this.#sessions.get(options.sessionId);
31349
+ if (started === void 0) {
31350
+ throw new AcpExecutionError("ACP native session browser did not start");
31351
+ }
31352
+ return started;
31353
+ }
31354
+ use = async (options, operation) => await this.#sessions.use(options.sessionId, async () => await operation(await this.#ensure(options)));
31355
+ preview = async (options, nativeSessionId) => {
31356
+ return await this.#processes.runTransient(
31357
+ options.signal,
31358
+ async () => await AcpProcessSession.startNativeSessionBrowser(
31359
+ options,
31360
+ () => this.#observer,
31361
+ new MemoryAcpSessionStore()
31362
+ ),
31363
+ async (runtime) => {
31364
+ runtime.selectNativeSession(nativeSessionId);
31365
+ return await runtime.loadHistory(options.signal);
31366
+ },
31367
+ async (runtime) => await runtime.closeProcess()
31368
+ );
31369
+ };
31370
+ close = async () => {
31371
+ await Promise.all(this.#sessions.entries().map(async ([id, runtime]) => await this.retire(id, runtime)));
31372
+ };
31373
+ };
31374
+
31265
31375
  // src/acp/session-executions.ts
31266
31376
  var unreachable = (state) => {
31267
31377
  throw new AcpExecutionError("Unexpected execution state", { cause: state });
@@ -31555,15 +31665,10 @@ var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
31555
31665
  var AcpSessionManager = class {
31556
31666
  #processes = new AcpProcessPool();
31557
31667
  #sessions = new RetainedSessions({ touch: this.#processes.touch, changed: this.#processes.notifyChanged });
31558
- #nativeBrowserSessions = new RetainedSessions({
31559
- touch: this.#processes.touch,
31560
- changed: this.#processes.notifyChanged
31561
- });
31668
+ #browsers = new NativeSessionBrowsers(this.#processes);
31562
31669
  #executions = new SessionExecutions();
31563
31670
  #agentSettingsObserver = new NullAcpSessionObserver();
31564
31671
  #nativeOperations = /* @__PURE__ */ new Set();
31565
- #nativeBrowserObserver = new NullAcpSessionObserver();
31566
- #nativeBrowserStore = new MemoryAcpSessionStore();
31567
31672
  #store;
31568
31673
  #nativeHistoryReader;
31569
31674
  #sessionIdentity;
@@ -31581,16 +31686,10 @@ var AcpSessionManager = class {
31581
31686
  const stored = this.#store.read(sessionId);
31582
31687
  return stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`);
31583
31688
  }
31584
- #retention(sessionId, kind) {
31585
- if (kind === "execution") {
31586
- return {
31587
- isBusy: () => this.#executions.isBusy(sessionId) || this.#sessions.isBusy(sessionId) || this.#isNativeSessionOperationActive(sessionId),
31588
- retire: (runtime) => this.#retireSessionProcess(sessionId, runtime, () => runtime.close())
31589
- };
31590
- }
31689
+ #retention(sessionId) {
31591
31690
  return {
31592
- isBusy: () => this.#nativeBrowserSessions.isBusy(sessionId),
31593
- retire: (runtime) => this.#retireNativeBrowserProcess(sessionId, runtime, () => runtime.close())
31691
+ isBusy: () => this.#executions.isBusy(sessionId) || this.#sessions.isBusy(sessionId) || this.#isNativeSessionOperationActive(sessionId),
31692
+ retire: (runtime) => this.#retireSessionProcess(sessionId, runtime, () => runtime.close())
31594
31693
  };
31595
31694
  }
31596
31695
  async #retireSessionProcess(sessionId, runtime, close) {
@@ -31606,56 +31705,11 @@ var AcpSessionManager = class {
31606
31705
  }
31607
31706
  }
31608
31707
  }
31609
- async #retireNativeBrowserProcess(sessionId, runtime, close) {
31610
- const retained = this.#nativeBrowserSessions.detach(sessionId, runtime);
31611
- if (retained) {
31612
- this.#nativeBrowserStore.remove(sessionId);
31613
- }
31614
- await this.#processes.retire(runtime, close);
31615
- }
31616
31708
  async #startRetainedSessionProcess(options, start) {
31617
- const runtime = await this.#processes.startRetained(
31618
- options.signal,
31619
- start,
31620
- this.#retention(options.sessionId, "execution")
31621
- );
31709
+ const runtime = await this.#processes.startRetained(options.signal, start, this.#retention(options.sessionId));
31622
31710
  this.#sessions.retain(options.sessionId, runtime);
31623
31711
  return runtime;
31624
31712
  }
31625
- async #startRetainedNativeBrowserProcess(options, start) {
31626
- const runtime = await this.#processes.startRetained(
31627
- options.signal,
31628
- start,
31629
- this.#retention(options.sessionId, "browser")
31630
- );
31631
- this.#nativeBrowserSessions.retain(options.sessionId, runtime);
31632
- return runtime;
31633
- }
31634
- async #startNativeBrowserPreparation(options) {
31635
- return await this.#nativeBrowserSessions.prepare(options.sessionId, async () => {
31636
- return await this.#startRetainedNativeBrowserProcess(
31637
- options,
31638
- async () => await AcpProcessSession.startNativeSessionBrowser(
31639
- options,
31640
- () => this.#nativeBrowserObserver,
31641
- this.#nativeBrowserStore
31642
- )
31643
- );
31644
- });
31645
- }
31646
- async #replaceNativeBrowserPreparation(existing, options) {
31647
- return await this.#nativeBrowserSessions.prepare(options.sessionId, async () => {
31648
- await this.#retireNativeBrowserProcess(options.sessionId, existing, async () => await existing.close());
31649
- return await this.#startRetainedNativeBrowserProcess(
31650
- options,
31651
- async () => await AcpProcessSession.startNativeSessionBrowser(
31652
- options,
31653
- () => this.#nativeBrowserObserver,
31654
- this.#nativeBrowserStore
31655
- )
31656
- );
31657
- });
31658
- }
31659
31713
  async #startPreparation(options, metrics = unmeasuredOperationMetrics) {
31660
31714
  return await this.#sessions.prepare(options.sessionId, async () => {
31661
31715
  return await this.#startRetainedSessionProcess(
@@ -31852,35 +31906,7 @@ var AcpSessionManager = class {
31852
31906
  }
31853
31907
  return (await this.#replaceExecutionPreparation(existing, options)).prepared();
31854
31908
  };
31855
- prepareNativeSessionBrowser = async (options) => {
31856
- const pending = this.#nativeBrowserSessions.pending(options.sessionId);
31857
- if (pending !== void 0) {
31858
- const runtime2 = await pending;
31859
- if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31860
- this.#nativeBrowserSessions.touch(options.sessionId, runtime2);
31861
- return runtime2.prepared();
31862
- }
31863
- return await this.prepareNativeSessionBrowser(options);
31864
- }
31865
- const existing = this.#nativeBrowserSessions.get(options.sessionId);
31866
- if (existing !== void 0) {
31867
- if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
31868
- this.#nativeBrowserSessions.touch(options.sessionId, existing);
31869
- return existing.prepared();
31870
- }
31871
- if (!existing.canRebind()) {
31872
- throw new AcpExecutionError(
31873
- "The agent or workspace cannot change after a conversation has started",
31874
- {},
31875
- "session_identity_mismatch"
31876
- );
31877
- }
31878
- const runtime2 = await this.#replaceNativeBrowserPreparation(existing, options);
31879
- return runtime2.prepared();
31880
- }
31881
- const runtime = await this.#startNativeBrowserPreparation(options);
31882
- return runtime.prepared();
31883
- };
31909
+ prepareNativeSessionBrowser = (options) => this.#browsers.prepare(options);
31884
31910
  configureSession = async (options) => {
31885
31911
  return await this.#sessions.use(options.sessionId, async () => {
31886
31912
  const runtime = await this.ensureSession(options);
@@ -32013,14 +32039,11 @@ var AcpSessionManager = class {
32013
32039
  };
32014
32040
  close = async () => {
32015
32041
  const sessions = [...this.#sessions.entries()];
32016
- const nativeBrowserSessions = [...this.#nativeBrowserSessions.entries()];
32017
32042
  await Promise.all([
32018
32043
  ...sessions.map(
32019
32044
  async ([sessionId, runtime]) => await this.#retireSessionProcess(sessionId, runtime, async () => await runtime.close())
32020
32045
  ),
32021
- ...nativeBrowserSessions.map(
32022
- async ([sessionId, runtime]) => await this.#retireNativeBrowserProcess(sessionId, runtime, async () => await runtime.close())
32023
- )
32046
+ this.#browsers.close()
32024
32047
  ]);
32025
32048
  };
32026
32049
  findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
@@ -32048,7 +32071,7 @@ var AcpSessionManager = class {
32048
32071
  runtime.adoptNativeSessionId(nativeSessionId);
32049
32072
  this.#sessions.detach(temporarySessionId, runtime);
32050
32073
  this.#sessions.retain(nativeSessionId, runtime);
32051
- this.#processes.retain(runtime, this.#retention(nativeSessionId, "execution"));
32074
+ this.#processes.retain(runtime, this.#retention(nativeSessionId));
32052
32075
  adopted = true;
32053
32076
  return nativeSessionId;
32054
32077
  } finally {
@@ -32085,30 +32108,11 @@ var AcpSessionManager = class {
32085
32108
  }
32086
32109
  return started;
32087
32110
  };
32088
- async #ensureNativeSessionBrowser(options) {
32089
- const existing = this.#nativeBrowserSessions.get(options.sessionId);
32090
- if (existing !== void 0) {
32091
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
32092
- throw new AcpExecutionError(
32093
- "The agent or workspace cannot change after a conversation has started",
32094
- {},
32095
- "session_identity_mismatch"
32096
- );
32097
- }
32098
- this.#nativeBrowserSessions.touch(options.sessionId, existing);
32099
- return existing;
32100
- }
32101
- await this.prepareNativeSessionBrowser(options);
32102
- const started = this.#nativeBrowserSessions.get(options.sessionId);
32103
- if (started === void 0) {
32104
- throw new AcpExecutionError("ACP native session browser did not start");
32105
- }
32106
- return started;
32107
- }
32108
32111
  listNativeSessions = async (options, cursor) => {
32109
- return await this.#nativeBrowserSessions.use(options.sessionId, async () => {
32110
- return await (await this.#ensureNativeSessionBrowser(options)).listNativeSessions(cursor, options.signal);
32111
- });
32112
+ return await this.#browsers.use(
32113
+ options,
32114
+ async (runtime) => await runtime.listNativeSessions(cursor, options.signal)
32115
+ );
32112
32116
  };
32113
32117
  previewNativeSession = async (options, nativeSessionId) => {
32114
32118
  const key = `${options.agent.id}:${nativeSessionId}`;
@@ -32124,19 +32128,7 @@ var AcpSessionManager = class {
32124
32128
  }
32125
32129
  this.#nativeOperations.add(key);
32126
32130
  try {
32127
- return await this.#processes.runTransient(
32128
- options.signal,
32129
- async () => await AcpProcessSession.startNativeSessionBrowser(
32130
- options,
32131
- () => this.#nativeBrowserObserver,
32132
- new MemoryAcpSessionStore()
32133
- ),
32134
- async (runtime) => {
32135
- runtime.selectNativeSession(nativeSessionId);
32136
- return await runtime.loadHistory(options.signal);
32137
- },
32138
- async (runtime) => await runtime.closeProcess()
32139
- );
32131
+ return await this.#browsers.preview(options, nativeSessionId);
32140
32132
  } finally {
32141
32133
  this.#nativeOperations.delete(key);
32142
32134
  }
@@ -32234,8 +32226,7 @@ var AcpSessionManager = class {
32234
32226
  });
32235
32227
  };
32236
32228
  deleteNativeSession = async (options, nativeSessionId) => {
32237
- return await this.#nativeBrowserSessions.use(options.sessionId, async () => {
32238
- const runtime = await this.#ensureNativeSessionBrowser(options);
32229
+ return await this.#browsers.use(options, async (runtime) => {
32239
32230
  const key = `${options.agent.id}:${nativeSessionId}`;
32240
32231
  const linked = this.#store.findNative(options.agent.id, nativeSessionId);
32241
32232
  if (this.#nativeOperations.has(key) || linked.some(
@@ -32259,11 +32250,7 @@ var AcpSessionManager = class {
32259
32250
  await runtime.deleteNativeSession(nativeSessionId, options.signal);
32260
32251
  const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
32261
32252
  if (runtime.nativeSessionId() === nativeSessionId) {
32262
- await this.#retireNativeBrowserProcess(
32263
- options.sessionId,
32264
- runtime,
32265
- async () => await runtime.close()
32266
- );
32253
+ await this.#browsers.retire(options.sessionId, runtime);
32267
32254
  }
32268
32255
  return deleted;
32269
32256
  } finally {