@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.
package/dist/cli.js CHANGED
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.126",
3384
+ version: "0.0.127",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -39583,6 +39583,116 @@ var RetainedSessions = class {
39583
39583
  };
39584
39584
  };
39585
39585
 
39586
+ // src/acp/native-session-browsers.ts
39587
+ var NativeSessionBrowsers = class {
39588
+ #sessions;
39589
+ #processes;
39590
+ #observer = new NullAcpSessionObserver();
39591
+ #store = new MemoryAcpSessionStore();
39592
+ constructor(processes) {
39593
+ this.#processes = processes;
39594
+ this.#sessions = new RetainedSessions({ touch: processes.touch, changed: processes.notifyChanged });
39595
+ }
39596
+ retire = async (sessionId, runtime) => {
39597
+ const retained = this.#sessions.detach(sessionId, runtime);
39598
+ if (retained) {
39599
+ this.#store.remove(sessionId);
39600
+ }
39601
+ await this.#processes.retire(runtime, () => runtime.close());
39602
+ };
39603
+ async #startRetained(options) {
39604
+ const runtime = await this.#processes.startRetained(
39605
+ options.signal,
39606
+ () => AcpProcessSession.startNativeSessionBrowser(options, () => this.#observer, this.#store),
39607
+ {
39608
+ isBusy: () => this.#sessions.isBusy(options.sessionId),
39609
+ retire: (runtime2) => this.retire(options.sessionId, runtime2)
39610
+ }
39611
+ );
39612
+ this.#sessions.retain(options.sessionId, runtime);
39613
+ return runtime;
39614
+ }
39615
+ async #startPreparation(options) {
39616
+ return await this.#sessions.prepare(options.sessionId, async () => {
39617
+ return await this.#startRetained(options);
39618
+ });
39619
+ }
39620
+ async #replacePreparation(existing, options) {
39621
+ return await this.#sessions.prepare(options.sessionId, async () => {
39622
+ await this.retire(options.sessionId, existing);
39623
+ return await this.#startRetained(options);
39624
+ });
39625
+ }
39626
+ prepare = async (options) => {
39627
+ const pending = this.#sessions.pending(options.sessionId);
39628
+ if (pending !== void 0) {
39629
+ const runtime2 = await pending;
39630
+ if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
39631
+ this.#sessions.touch(options.sessionId, runtime2);
39632
+ return runtime2.prepared();
39633
+ }
39634
+ return await this.prepare(options);
39635
+ }
39636
+ const existing = this.#sessions.get(options.sessionId);
39637
+ if (existing !== void 0) {
39638
+ if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
39639
+ this.#sessions.touch(options.sessionId, existing);
39640
+ return existing.prepared();
39641
+ }
39642
+ if (!existing.canRebind()) {
39643
+ throw new AcpExecutionError(
39644
+ "The agent or workspace cannot change after a conversation has started",
39645
+ {},
39646
+ "session_identity_mismatch"
39647
+ );
39648
+ }
39649
+ const runtime2 = await this.#replacePreparation(existing, options);
39650
+ return runtime2.prepared();
39651
+ }
39652
+ const runtime = await this.#startPreparation(options);
39653
+ return runtime.prepared();
39654
+ };
39655
+ async #ensure(options) {
39656
+ const existing = this.#sessions.get(options.sessionId);
39657
+ if (existing !== void 0) {
39658
+ if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
39659
+ throw new AcpExecutionError(
39660
+ "The agent or workspace cannot change after a conversation has started",
39661
+ {},
39662
+ "session_identity_mismatch"
39663
+ );
39664
+ }
39665
+ this.#sessions.touch(options.sessionId, existing);
39666
+ return existing;
39667
+ }
39668
+ await this.prepare(options);
39669
+ const started = this.#sessions.get(options.sessionId);
39670
+ if (started === void 0) {
39671
+ throw new AcpExecutionError("ACP native session browser did not start");
39672
+ }
39673
+ return started;
39674
+ }
39675
+ use = async (options, operation) => await this.#sessions.use(options.sessionId, async () => await operation(await this.#ensure(options)));
39676
+ preview = async (options, nativeSessionId) => {
39677
+ return await this.#processes.runTransient(
39678
+ options.signal,
39679
+ async () => await AcpProcessSession.startNativeSessionBrowser(
39680
+ options,
39681
+ () => this.#observer,
39682
+ new MemoryAcpSessionStore()
39683
+ ),
39684
+ async (runtime) => {
39685
+ runtime.selectNativeSession(nativeSessionId);
39686
+ return await runtime.loadHistory(options.signal);
39687
+ },
39688
+ async (runtime) => await runtime.closeProcess()
39689
+ );
39690
+ };
39691
+ close = async () => {
39692
+ await Promise.all(this.#sessions.entries().map(async ([id, runtime]) => await this.retire(id, runtime)));
39693
+ };
39694
+ };
39695
+
39586
39696
  // src/acp/session-executions.ts
39587
39697
  var unreachable = (state) => {
39588
39698
  throw new AcpExecutionError("Unexpected execution state", { cause: state });
@@ -39876,15 +39986,10 @@ var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
39876
39986
  var AcpSessionManager = class {
39877
39987
  #processes = new AcpProcessPool();
39878
39988
  #sessions = new RetainedSessions({ touch: this.#processes.touch, changed: this.#processes.notifyChanged });
39879
- #nativeBrowserSessions = new RetainedSessions({
39880
- touch: this.#processes.touch,
39881
- changed: this.#processes.notifyChanged
39882
- });
39989
+ #browsers = new NativeSessionBrowsers(this.#processes);
39883
39990
  #executions = new SessionExecutions();
39884
39991
  #agentSettingsObserver = new NullAcpSessionObserver();
39885
39992
  #nativeOperations = /* @__PURE__ */ new Set();
39886
- #nativeBrowserObserver = new NullAcpSessionObserver();
39887
- #nativeBrowserStore = new MemoryAcpSessionStore();
39888
39993
  #store;
39889
39994
  #nativeHistoryReader;
39890
39995
  #sessionIdentity;
@@ -39902,16 +40007,10 @@ var AcpSessionManager = class {
39902
40007
  const stored = this.#store.read(sessionId);
39903
40008
  return stored instanceof FoundAcpStoredSession && this.#nativeOperations.has(`${stored.session.agentId}:${stored.session.nativeSessionId}`);
39904
40009
  }
39905
- #retention(sessionId, kind) {
39906
- if (kind === "execution") {
39907
- return {
39908
- isBusy: () => this.#executions.isBusy(sessionId) || this.#sessions.isBusy(sessionId) || this.#isNativeSessionOperationActive(sessionId),
39909
- retire: (runtime) => this.#retireSessionProcess(sessionId, runtime, () => runtime.close())
39910
- };
39911
- }
40010
+ #retention(sessionId) {
39912
40011
  return {
39913
- isBusy: () => this.#nativeBrowserSessions.isBusy(sessionId),
39914
- retire: (runtime) => this.#retireNativeBrowserProcess(sessionId, runtime, () => runtime.close())
40012
+ isBusy: () => this.#executions.isBusy(sessionId) || this.#sessions.isBusy(sessionId) || this.#isNativeSessionOperationActive(sessionId),
40013
+ retire: (runtime) => this.#retireSessionProcess(sessionId, runtime, () => runtime.close())
39915
40014
  };
39916
40015
  }
39917
40016
  async #retireSessionProcess(sessionId, runtime, close) {
@@ -39927,56 +40026,11 @@ var AcpSessionManager = class {
39927
40026
  }
39928
40027
  }
39929
40028
  }
39930
- async #retireNativeBrowserProcess(sessionId, runtime, close) {
39931
- const retained = this.#nativeBrowserSessions.detach(sessionId, runtime);
39932
- if (retained) {
39933
- this.#nativeBrowserStore.remove(sessionId);
39934
- }
39935
- await this.#processes.retire(runtime, close);
39936
- }
39937
40029
  async #startRetainedSessionProcess(options, start) {
39938
- const runtime = await this.#processes.startRetained(
39939
- options.signal,
39940
- start,
39941
- this.#retention(options.sessionId, "execution")
39942
- );
40030
+ const runtime = await this.#processes.startRetained(options.signal, start, this.#retention(options.sessionId));
39943
40031
  this.#sessions.retain(options.sessionId, runtime);
39944
40032
  return runtime;
39945
40033
  }
39946
- async #startRetainedNativeBrowserProcess(options, start) {
39947
- const runtime = await this.#processes.startRetained(
39948
- options.signal,
39949
- start,
39950
- this.#retention(options.sessionId, "browser")
39951
- );
39952
- this.#nativeBrowserSessions.retain(options.sessionId, runtime);
39953
- return runtime;
39954
- }
39955
- async #startNativeBrowserPreparation(options) {
39956
- return await this.#nativeBrowserSessions.prepare(options.sessionId, async () => {
39957
- return await this.#startRetainedNativeBrowserProcess(
39958
- options,
39959
- async () => await AcpProcessSession.startNativeSessionBrowser(
39960
- options,
39961
- () => this.#nativeBrowserObserver,
39962
- this.#nativeBrowserStore
39963
- )
39964
- );
39965
- });
39966
- }
39967
- async #replaceNativeBrowserPreparation(existing, options) {
39968
- return await this.#nativeBrowserSessions.prepare(options.sessionId, async () => {
39969
- await this.#retireNativeBrowserProcess(options.sessionId, existing, async () => await existing.close());
39970
- return await this.#startRetainedNativeBrowserProcess(
39971
- options,
39972
- async () => await AcpProcessSession.startNativeSessionBrowser(
39973
- options,
39974
- () => this.#nativeBrowserObserver,
39975
- this.#nativeBrowserStore
39976
- )
39977
- );
39978
- });
39979
- }
39980
40034
  async #startPreparation(options, metrics = unmeasuredOperationMetrics) {
39981
40035
  return await this.#sessions.prepare(options.sessionId, async () => {
39982
40036
  return await this.#startRetainedSessionProcess(
@@ -40173,35 +40227,7 @@ var AcpSessionManager = class {
40173
40227
  }
40174
40228
  return (await this.#replaceExecutionPreparation(existing, options)).prepared();
40175
40229
  };
40176
- prepareNativeSessionBrowser = async (options) => {
40177
- const pending = this.#nativeBrowserSessions.pending(options.sessionId);
40178
- if (pending !== void 0) {
40179
- const runtime2 = await pending;
40180
- if (runtime2.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40181
- this.#nativeBrowserSessions.touch(options.sessionId, runtime2);
40182
- return runtime2.prepared();
40183
- }
40184
- return await this.prepareNativeSessionBrowser(options);
40185
- }
40186
- const existing = this.#nativeBrowserSessions.get(options.sessionId);
40187
- if (existing !== void 0) {
40188
- if (existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40189
- this.#nativeBrowserSessions.touch(options.sessionId, existing);
40190
- return existing.prepared();
40191
- }
40192
- if (!existing.canRebind()) {
40193
- throw new AcpExecutionError(
40194
- "The agent or workspace cannot change after a conversation has started",
40195
- {},
40196
- "session_identity_mismatch"
40197
- );
40198
- }
40199
- const runtime2 = await this.#replaceNativeBrowserPreparation(existing, options);
40200
- return runtime2.prepared();
40201
- }
40202
- const runtime = await this.#startNativeBrowserPreparation(options);
40203
- return runtime.prepared();
40204
- };
40230
+ prepareNativeSessionBrowser = (options) => this.#browsers.prepare(options);
40205
40231
  configureSession = async (options) => {
40206
40232
  return await this.#sessions.use(options.sessionId, async () => {
40207
40233
  const runtime = await this.ensureSession(options);
@@ -40334,14 +40360,11 @@ var AcpSessionManager = class {
40334
40360
  };
40335
40361
  close = async () => {
40336
40362
  const sessions = [...this.#sessions.entries()];
40337
- const nativeBrowserSessions = [...this.#nativeBrowserSessions.entries()];
40338
40363
  await Promise.all([
40339
40364
  ...sessions.map(
40340
40365
  async ([sessionId, runtime]) => await this.#retireSessionProcess(sessionId, runtime, async () => await runtime.close())
40341
40366
  ),
40342
- ...nativeBrowserSessions.map(
40343
- async ([sessionId, runtime]) => await this.#retireNativeBrowserProcess(sessionId, runtime, async () => await runtime.close())
40344
- )
40367
+ this.#browsers.close()
40345
40368
  ]);
40346
40369
  };
40347
40370
  findSessions = (sessionIds) => sessionIds.flatMap((sessionId) => {
@@ -40369,7 +40392,7 @@ var AcpSessionManager = class {
40369
40392
  runtime.adoptNativeSessionId(nativeSessionId);
40370
40393
  this.#sessions.detach(temporarySessionId, runtime);
40371
40394
  this.#sessions.retain(nativeSessionId, runtime);
40372
- this.#processes.retain(runtime, this.#retention(nativeSessionId, "execution"));
40395
+ this.#processes.retain(runtime, this.#retention(nativeSessionId));
40373
40396
  adopted = true;
40374
40397
  return nativeSessionId;
40375
40398
  } finally {
@@ -40406,30 +40429,11 @@ var AcpSessionManager = class {
40406
40429
  }
40407
40430
  return started;
40408
40431
  };
40409
- async #ensureNativeSessionBrowser(options) {
40410
- const existing = this.#nativeBrowserSessions.get(options.sessionId);
40411
- if (existing !== void 0) {
40412
- if (!existing.belongsTo(options.agent.id, options.cwd, options.additionalDirectories)) {
40413
- throw new AcpExecutionError(
40414
- "The agent or workspace cannot change after a conversation has started",
40415
- {},
40416
- "session_identity_mismatch"
40417
- );
40418
- }
40419
- this.#nativeBrowserSessions.touch(options.sessionId, existing);
40420
- return existing;
40421
- }
40422
- await this.prepareNativeSessionBrowser(options);
40423
- const started = this.#nativeBrowserSessions.get(options.sessionId);
40424
- if (started === void 0) {
40425
- throw new AcpExecutionError("ACP native session browser did not start");
40426
- }
40427
- return started;
40428
- }
40429
40432
  listNativeSessions = async (options, cursor) => {
40430
- return await this.#nativeBrowserSessions.use(options.sessionId, async () => {
40431
- return await (await this.#ensureNativeSessionBrowser(options)).listNativeSessions(cursor, options.signal);
40432
- });
40433
+ return await this.#browsers.use(
40434
+ options,
40435
+ async (runtime) => await runtime.listNativeSessions(cursor, options.signal)
40436
+ );
40433
40437
  };
40434
40438
  previewNativeSession = async (options, nativeSessionId) => {
40435
40439
  const key = `${options.agent.id}:${nativeSessionId}`;
@@ -40445,19 +40449,7 @@ var AcpSessionManager = class {
40445
40449
  }
40446
40450
  this.#nativeOperations.add(key);
40447
40451
  try {
40448
- return await this.#processes.runTransient(
40449
- options.signal,
40450
- async () => await AcpProcessSession.startNativeSessionBrowser(
40451
- options,
40452
- () => this.#nativeBrowserObserver,
40453
- new MemoryAcpSessionStore()
40454
- ),
40455
- async (runtime) => {
40456
- runtime.selectNativeSession(nativeSessionId);
40457
- return await runtime.loadHistory(options.signal);
40458
- },
40459
- async (runtime) => await runtime.closeProcess()
40460
- );
40452
+ return await this.#browsers.preview(options, nativeSessionId);
40461
40453
  } finally {
40462
40454
  this.#nativeOperations.delete(key);
40463
40455
  }
@@ -40555,8 +40547,7 @@ var AcpSessionManager = class {
40555
40547
  });
40556
40548
  };
40557
40549
  deleteNativeSession = async (options, nativeSessionId) => {
40558
- return await this.#nativeBrowserSessions.use(options.sessionId, async () => {
40559
- const runtime = await this.#ensureNativeSessionBrowser(options);
40550
+ return await this.#browsers.use(options, async (runtime) => {
40560
40551
  const key = `${options.agent.id}:${nativeSessionId}`;
40561
40552
  const linked = this.#store.findNative(options.agent.id, nativeSessionId);
40562
40553
  if (this.#nativeOperations.has(key) || linked.some(
@@ -40580,11 +40571,7 @@ var AcpSessionManager = class {
40580
40571
  await runtime.deleteNativeSession(nativeSessionId, options.signal);
40581
40572
  const deleted = this.#store.markDeleted(options.agent.id, nativeSessionId);
40582
40573
  if (runtime.nativeSessionId() === nativeSessionId) {
40583
- await this.#retireNativeBrowserProcess(
40584
- options.sessionId,
40585
- runtime,
40586
- async () => await runtime.close()
40587
- );
40574
+ await this.#browsers.retire(options.sessionId, runtime);
40588
40575
  }
40589
40576
  return deleted;
40590
40577
  } finally {