@moxt-ai/mobius 0.0.349 → 0.0.351

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 (32) hide show
  1. package/dist/cli.js +54 -11
  2. package/dist/cli.js.map +2 -2
  3. package/dist/engine/generated/acp-session-store-migrations.d.ts +3 -0
  4. package/dist/engine/generated/acp-session-store-migrations.d.ts.map +1 -1
  5. package/dist/engine/generated/acp-session-store-migrations.js +5 -1
  6. package/dist/engine/generated/acp-session-store-migrations.js.map +1 -1
  7. package/dist/engine/runtime/runtime-loop.d.ts +2 -0
  8. package/dist/engine/runtime/runtime-loop.d.ts.map +1 -1
  9. package/dist/engine/runtime/runtime-loop.js +4 -1
  10. package/dist/engine/runtime/runtime-loop.js.map +1 -1
  11. package/dist/engine/schema/acp-session-store/execution-receipt.d.ts +16 -0
  12. package/dist/engine/schema/acp-session-store/execution-receipt.d.ts.map +1 -1
  13. package/dist/engine/schema/acp-session-store/execution-receipt.js +2 -0
  14. package/dist/engine/schema/acp-session-store/execution-receipt.js.map +1 -1
  15. package/dist/engine/session/turn/execution-receipts.d.ts +3 -4
  16. package/dist/engine/session/turn/execution-receipts.d.ts.map +1 -1
  17. package/dist/engine/session/turn/execution-receipts.js +15 -5
  18. package/dist/engine/session/turn/execution-receipts.js.map +1 -1
  19. package/dist/engine/storage/session/execution-receipt-table.d.ts +1 -0
  20. package/dist/engine/storage/session/execution-receipt-table.d.ts.map +1 -1
  21. package/dist/engine/storage/session/execution-receipt-table.js +25 -7
  22. package/dist/engine/storage/session/execution-receipt-table.js.map +1 -1
  23. package/dist/engine/storage/sqlite/local-databases.d.ts.map +1 -1
  24. package/dist/engine/storage/sqlite/local-databases.js +6 -1
  25. package/dist/engine/storage/sqlite/local-databases.js.map +1 -1
  26. package/dist/engine/storage/sqlite/local-sqlite-database.d.ts +5 -0
  27. package/dist/engine/storage/sqlite/local-sqlite-database.d.ts.map +1 -1
  28. package/dist/engine/storage/sqlite/local-sqlite-database.js +9 -0
  29. package/dist/engine/storage/sqlite/local-sqlite-database.js.map +1 -1
  30. package/dist/engine.js +54 -11
  31. package/dist/engine.js.map +2 -2
  32. package/package.json +2 -2
package/dist/engine.js CHANGED
@@ -77572,6 +77572,10 @@ var acpSessionStoreMigrations = [
77572
77572
  {
77573
77573
  "name": "0008_execution_identity.sql",
77574
77574
  "sql": "CREATE TABLE `execution_identity` (\n `command_id` text PRIMARY KEY NOT NULL,\n `session_id` text NOT NULL,\n `command_hash` text NOT NULL\n);\n"
77575
+ },
77576
+ {
77577
+ "name": "0009_receipt_admission_order.sql",
77578
+ "sql": "ALTER TABLE `execution_receipt` ADD `admission_order` integer;"
77575
77579
  }
77576
77580
  ];
77577
77581
 
@@ -82484,6 +82488,13 @@ var LocalSqliteDatabase = class {
82484
82488
  throw new Error(`The ${label} migration is unavailable`);
82485
82489
  }
82486
82490
  this.transaction(() => {
82491
+ if (migration.compatibleColumn !== void 0) {
82492
+ const { table, column } = migration.compatibleColumn;
82493
+ if (this.#sqlite.prepare("SELECT name FROM pragma_table_info(?) WHERE name = ?").get(table, column) === void 0) {
82494
+ this.#sqlite.exec(migration.sql);
82495
+ }
82496
+ return;
82497
+ }
82487
82498
  this.#sqlite.exec(migration.sql);
82488
82499
  this.#sqlite.exec(`PRAGMA user_version = ${index2 + 1}`);
82489
82500
  });
@@ -82518,7 +82529,16 @@ function channelSessionDatabasePaths(stateDirectory, channelId) {
82518
82529
  sessions: join22(stateDirectory, "sessions", `${channelHash}.sqlite`)
82519
82530
  };
82520
82531
  }
82521
- var openAcpSessionDatabase = (path7) => new LocalSqliteDatabase(path7, "ACP Session database", acpSessionStoreMigrations);
82532
+ var openAcpSessionDatabase = (path7) => new LocalSqliteDatabase(
82533
+ path7,
82534
+ "ACP Session database",
82535
+ acpSessionStoreMigrations.map(
82536
+ (migration) => migration.name === "0009_receipt_admission_order.sql" ? {
82537
+ ...migration,
82538
+ compatibleColumn: { table: "execution_receipt", column: "admission_order" }
82539
+ } : migration
82540
+ )
82541
+ );
82522
82542
  var openSessionEventCacheDatabase = (path7) => new LocalSqliteDatabase(path7, "V2 Session event cache", sessionEventCacheMigrations, [
82523
82543
  "PRAGMA journal_mode = WAL",
82524
82544
  "PRAGMA synchronous = OFF",
@@ -83824,6 +83844,8 @@ var executionReceipt = sqliteTable("execution_receipt", {
83824
83844
  sessionId: text("session_id").notNull(),
83825
83845
  commandHash: text("command_hash").notNull(),
83826
83846
  attemptId: text("attempt_id").notNull(),
83847
+ // Nullable only for receipts written by older Runtimes; assigned before recovery.
83848
+ admissionOrder: integer2("admission_order"),
83827
83849
  // Compatibility projection for older Runtimes; started and outcome own the facts.
83828
83850
  state: text("state").notNull(),
83829
83851
  started: integer2("started", { mode: "boolean" }).notNull(),
@@ -83878,6 +83900,7 @@ var receiptSchema = external_exports.object({
83878
83900
  sessionId: external_exports.string(),
83879
83901
  commandHash: external_exports.string(),
83880
83902
  attemptId: external_exports.string(),
83903
+ admissionOrder: external_exports.number().int().positive().safe(),
83881
83904
  updatedAt: external_exports.string(),
83882
83905
  started: external_exports.boolean(),
83883
83906
  outcome: external_exports.string().nullable()
@@ -83902,9 +83925,18 @@ var ExecutionReceiptTable = class {
83902
83925
  const row = this.#database.orm.select({ sessionId: executionIdentity.sessionId, commandHash: executionIdentity.commandHash }).from(executionIdentity).where(eq2(executionIdentity.commandId, commandId)).get();
83903
83926
  return row === void 0 ? void 0 : identitySchema.parse(row);
83904
83927
  };
83905
- list = () => receiptSchema.array().parse(
83906
- this.#database.orm.select().from(executionReceipt).orderBy(asc(executionReceipt.updatedAt), asc(executionReceipt.commandId)).all()
83907
- );
83928
+ list = () => this.#database.transaction(() => {
83929
+ const rows = this.#database.orm.select().from(executionReceipt).orderBy(asc(executionReceipt.updatedAt), asc(executionReceipt.commandId)).all();
83930
+ let latestOrder = rows.reduce((latest, row) => Math.max(latest, row.admissionOrder ?? 0), 0);
83931
+ return rows.map((row) => {
83932
+ if (row.admissionOrder !== null) {
83933
+ return receiptSchema.parse(row);
83934
+ }
83935
+ const admissionOrder = ++latestOrder;
83936
+ this.#database.orm.update(executionReceipt).set({ admissionOrder }).where(eq2(executionReceipt.commandId, row.commandId)).run();
83937
+ return receiptSchema.parse({ ...row, admissionOrder });
83938
+ }).sort((left, right) => left.admissionOrder - right.admissionOrder);
83939
+ });
83908
83940
  save = (receipt, terminalLimit) => this.#database.transaction(() => {
83909
83941
  const row = { ...receipt, state: legacyState(receipt) };
83910
83942
  this.#database.orm.insert(executionReceipt).values(row).onConflictDoUpdate({ target: executionReceipt.commandId, set: row }).run();
@@ -87266,6 +87298,13 @@ var ExecutionReceipts = class {
87266
87298
  this.#activeCount += Number(receipt.outcome === null) - Number(wasActive);
87267
87299
  this.#onCount(this.#activeCount);
87268
87300
  };
87301
+ #nextAdmissionOrder = () => {
87302
+ let latest = 0;
87303
+ for (const receipt of this.#executions.values()) {
87304
+ latest = Math.max(latest, receipt.admissionOrder);
87305
+ }
87306
+ return latest + 1;
87307
+ };
87269
87308
  beginShutdown = () => {
87270
87309
  this.#closing = true;
87271
87310
  };
@@ -87300,21 +87339,22 @@ var ExecutionReceipts = class {
87300
87339
  }
87301
87340
  };
87302
87341
  /**
87303
- * How the Session's most recent started command ended. Receipts keep admission order, or the
87304
- * order they last changed after a restart; commands that never started (queued, or reserved for
87305
- * cancellation) are not turns, unless a restart failed them before they could start. Undefined
87306
- * while that command still runs, or when no turn is retained.
87342
+ * How the Session's most recently admitted turn ended. Admission order survives updates and
87343
+ * restarts. Commands that never started (queued, or reserved for cancellation) are not turns,
87344
+ * unless they failed before starting. Undefined while the latest turn runs or none is retained.
87307
87345
  */
87308
87346
  lastTurn = (sessionId) => {
87309
87347
  let last;
87348
+ let latestOrder = 0;
87310
87349
  for (const [commandId, receipt] of this.#executions) {
87311
87350
  if (receipt.sessionId !== sessionId) {
87312
87351
  continue;
87313
87352
  }
87314
87353
  const outcome2 = receipt.outcome === null ? void 0 : this.outcome(commandId);
87315
87354
  const failedBeforeStart = outcome2?.type === "lifecycle-metadata" && outcome2.payload.kind === "prompt.failed-before-start";
87316
- if (receipt.started || failedBeforeStart) {
87355
+ if ((receipt.started || failedBeforeStart) && receipt.admissionOrder > latestOrder) {
87317
87356
  last = commandId;
87357
+ latestOrder = receipt.admissionOrder;
87318
87358
  }
87319
87359
  }
87320
87360
  const outcome = last === void 0 ? void 0 : this.outcome(last);
@@ -87354,6 +87394,7 @@ var ExecutionReceipts = class {
87354
87394
  })
87355
87395
  ).digest("hex");
87356
87396
  this.#save(commandId, {
87397
+ admissionOrder: this.#nextAdmissionOrder(),
87357
87398
  attemptId: randomUUID15(),
87358
87399
  commandHash,
87359
87400
  sessionId,
@@ -87438,6 +87479,7 @@ var ExecutionReceipts = class {
87438
87479
  }
87439
87480
  const attemptId = randomUUID15();
87440
87481
  this.#save(commandId, {
87482
+ admissionOrder: this.#nextAdmissionOrder(),
87441
87483
  attemptId,
87442
87484
  commandHash,
87443
87485
  sessionId,
@@ -90755,7 +90797,7 @@ var sessionPromptCommand = {
90755
90797
  // package.json
90756
90798
  var package_default = {
90757
90799
  name: "@moxt-ai/mobius",
90758
- version: "0.0.349",
90800
+ version: "0.0.351",
90759
90801
  description: "Mobius CLI for pairing and running local AI agent services.",
90760
90802
  type: "module",
90761
90803
  bin: {
@@ -92253,8 +92295,9 @@ var RuntimeLoop = class {
92253
92295
  signal.throwIfAborted();
92254
92296
  this.#state = { kind: "preparing" };
92255
92297
  try {
92256
- const config2 = await this.#prepare(signal);
92298
+ const prepared = await this.#prepare(signal);
92257
92299
  signal.throwIfAborted();
92300
+ const config2 = this.#options.sessionEnvironment === void 0 ? prepared : { ...prepared, sessionEnvironment: this.#options.sessionEnvironment };
92258
92301
  validateRuntimeConfiguration(config2);
92259
92302
  this.#state = { kind: "running", config: config2 };
92260
92303
  await runRuntime(config2, signal, void 0, {