omnius 1.0.867 → 1.0.868

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 (27) hide show
  1. package/dist/api/py-embed.js +13 -0
  2. package/dist/index.js +2 -2
  3. package/dist/library.js +220 -194
  4. package/dist/tui/native/worker.js +857 -143
  5. package/dist/update-worker.js +128 -77
  6. package/docs/DISCOVERY.json +1069 -139
  7. package/docs/DISCOVERY.md +26 -7
  8. package/docs/design/media-unification-TODO.md +26 -6
  9. package/docs/design/media-unification-design.md +89 -0
  10. package/docs/design/update-operation-cancellation.md +40 -0
  11. package/docs/design/update-session-restoration-TODO.md +30 -0
  12. package/docs/work-orders/evidence/instrument-media-live-20261016/media-audio-playing.png +0 -0
  13. package/docs/work-orders/evidence/instrument-media-live-20261016/media-image-100x30.png +0 -0
  14. package/docs/work-orders/evidence/instrument-media-live-20261016/media-image-120x36.png +0 -0
  15. package/docs/work-orders/evidence/instrument-media-live-20261016/media-image-160x48.png +0 -0
  16. package/docs/work-orders/evidence/instrument-media-live-20261016/media-image-60x20.png +0 -0
  17. package/docs/work-orders/evidence/instrument-media-live-20261016/media-image-80x24.png +0 -0
  18. package/docs/work-orders/evidence/instrument-media-live-20261016/media-progress-collapsed.png +0 -0
  19. package/docs/work-orders/evidence/instrument-media-live-20261016/media-video-frame-a.png +0 -0
  20. package/docs/work-orders/evidence/instrument-media-live-20261016/media-video-frame-b.png +0 -0
  21. package/docs/work-orders/evidence/instrument-media-live-20261016/media-voice-autocomplete-junction.png +0 -0
  22. package/docs/work-orders/evidence/instrument-media-live-20261016/report.json +813 -0
  23. package/docs/work-orders/evidence/instrument-media-verification-20261016.json +59 -0
  24. package/docs/work-orders/evidence/native-interface-state-verification-20261016.json +59 -0
  25. package/docs/work-orders/evidence/project-media-unification-20261016.json +108 -0
  26. package/npm-shrinkwrap.json +2 -2
  27. package/package.json +1 -1
@@ -2589,12 +2589,20 @@ var init_identity_kernel = __esm({
2589
2589
  }
2590
2590
  });
2591
2591
 
2592
+ // packages/execution/dist/tools/media-progress.js
2593
+ var init_media_progress = __esm({
2594
+ "packages/execution/dist/tools/media-progress.js"() {
2595
+ "use strict";
2596
+ }
2597
+ });
2598
+
2592
2599
  // packages/execution/dist/tools/audio-generate.js
2593
2600
  var DIFFUSERS_AUDIO_RUNNER, AUDIOCRAFT_RUNNER, TRANSFORMERS_AUDIO_RUNNER, TANGOFLUX_RUNNER;
2594
2601
  var init_audio_generate = __esm({
2595
2602
  "packages/execution/dist/tools/audio-generate.js"() {
2596
2603
  "use strict";
2597
2604
  init_process_async();
2605
+ init_media_progress();
2598
2606
  init_media_store_lease();
2599
2607
  init_model_broker();
2600
2608
  init_venv_paths();
@@ -296871,6 +296879,9 @@ init_process_lifecycle();
296871
296879
  init_identity_kernel();
296872
296880
 
296873
296881
  // packages/execution/dist/tools/image-generate.js
296882
+ init_process_async();
296883
+ import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
296884
+ init_media_progress();
296874
296885
  init_media_store_lease();
296875
296886
  init_model_broker();
296876
296887
  init_venv_paths();
@@ -297691,6 +297702,7 @@ def main():
297691
297702
  if __name__ == "__main__":
297692
297703
  main()
297693
297704
  `;
297705
+ var imageInvocationSignal = new AsyncLocalStorage4();
297694
297706
 
297695
297707
  // packages/execution/dist/index.js
297696
297708
  init_audio_generate();
@@ -297717,6 +297729,7 @@ var execFileAsync2 = promisify3(execFile3);
297717
297729
 
297718
297730
  // packages/execution/dist/tools/video-generate.js
297719
297731
  init_process_async();
297732
+ init_media_progress();
297720
297733
  init_media_store_lease();
297721
297734
  init_model_broker();
297722
297735
  init_venv_paths();
@@ -300151,6 +300164,7 @@ import {
300151
300164
  chmodSync,
300152
300165
  closeSync as closeSync3,
300153
300166
  existsSync as existsSync6,
300167
+ lstatSync,
300154
300168
  mkdirSync as mkdirSync5,
300155
300169
  openSync as openSync3,
300156
300170
  readFileSync as readFileSync6,
@@ -300217,6 +300231,41 @@ function compareOmniusVersions(left, right) {
300217
300231
  }
300218
300232
 
300219
300233
  // packages/cli/src/update-service.ts
300234
+ var UpdateCancelledError = class extends Error {
300235
+ constructor(message = "Update cancelled. Package changes already made are retained; no rollback is claimed.") {
300236
+ super(message);
300237
+ this.name = "UpdateCancelledError";
300238
+ }
300239
+ };
300240
+ function cancellationPath(operationId, paths) {
300241
+ if (!/^[a-zA-Z0-9_-]{1,128}$/.test(operationId)) throw new Error("Invalid update operation identity");
300242
+ return join15(paths.stateDir, `cancel-${operationId}.json`);
300243
+ }
300244
+ function watchUpdateCancellation(operationId, paths = resolveUpdatePaths()) {
300245
+ const controller = new AbortController();
300246
+ const path3 = cancellationPath(operationId, paths);
300247
+ const check = () => {
300248
+ if (controller.signal.aborted) return;
300249
+ try {
300250
+ const metadata = lstatSync(path3);
300251
+ if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > 1024) return;
300252
+ const request = JSON.parse(readFileSync6(path3, "utf8"));
300253
+ const state = readUpdateState(paths);
300254
+ if (state?.operation_id === operationId && state.status === "running" && state.cancel_token_hash && request.operation_id === operationId && request.token_hash === state.cancel_token_hash) controller.abort(new UpdateCancelledError());
300255
+ } catch {
300256
+ }
300257
+ };
300258
+ check();
300259
+ const timer = setInterval(check, 100);
300260
+ timer.unref?.();
300261
+ return { signal: controller.signal, close() {
300262
+ clearInterval(timer);
300263
+ try {
300264
+ unlinkSync3(path3);
300265
+ } catch {
300266
+ }
300267
+ } };
300268
+ }
300220
300269
  function resolveUpdatePaths(env = process.env, platform2 = process.platform, home = homedir15()) {
300221
300270
  const stateBase = platform2 === "win32" ? env["LOCALAPPDATA"] || join15(home, "AppData", "Local") : platform2 === "darwin" ? join15(home, "Library", "Application Support") : env["XDG_STATE_HOME"] || join15(home, ".local", "state");
300222
300271
  const cacheBase = platform2 === "win32" ? env["LOCALAPPDATA"] || join15(home, "AppData", "Local") : platform2 === "darwin" ? join15(home, "Library", "Caches") : env["XDG_CACHE_HOME"] || join15(home, ".cache");
@@ -300323,13 +300372,15 @@ function commandVersion(value) {
300323
300372
  const match2 = value.match(/(?:^|\s)v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)(?:\s|$)/);
300324
300373
  return match2?.[1] ?? null;
300325
300374
  }
300326
- async function runCommand(command, args, options = {}) {
300375
+ async function runUpdateCommand(command, args, options = {}) {
300327
300376
  if (options.signal?.aborted) {
300328
300377
  return { status: null, stdout: "", stderr: "command cancelled", signal: null, error: new Error("command cancelled") };
300329
300378
  }
300330
300379
  return await new Promise((resolve10) => {
300331
300380
  const child = spawn2(command, args, {
300332
300381
  env: options.env ?? process.env,
300382
+ cwd: options.cwd,
300383
+ shell: options.shell,
300333
300384
  stdio: options.inherit ? ["ignore", "inherit", "inherit"] : ["ignore", "pipe", "pipe"],
300334
300385
  windowsHide: true,
300335
300386
  detached: process.platform !== "win32"
@@ -300341,12 +300392,19 @@ async function runCommand(command, args, options = {}) {
300341
300392
  let stopping = false;
300342
300393
  let timer;
300343
300394
  let forceTimer;
300344
- let settlementTimer;
300345
300395
  const capture = (current, chunk) => `${current}${chunk.toString()}`.slice(-256 * 1024);
300346
300396
  const signalChild = (signal) => {
300347
300397
  try {
300348
300398
  if (child.pid && process.platform !== "win32") process.kill(-child.pid, signal);
300349
- else child.kill(signal);
300399
+ else if (child.pid && process.platform === "win32") {
300400
+ const killer = spawn2("taskkill", ["/pid", String(child.pid), "/t", "/f"], { stdio: "ignore", windowsHide: true });
300401
+ killer.once("error", () => {
300402
+ try {
300403
+ child.kill(signal);
300404
+ } catch {
300405
+ }
300406
+ });
300407
+ } else child.kill(signal);
300350
300408
  } catch {
300351
300409
  }
300352
300410
  };
@@ -300357,15 +300415,12 @@ async function runCommand(command, args, options = {}) {
300357
300415
  signalChild("SIGTERM");
300358
300416
  forceTimer = setTimeout(() => signalChild("SIGKILL"), 1e3);
300359
300417
  forceTimer.unref?.();
300360
- settlementTimer = setTimeout(() => finish({ status: null, stdout, stderr, signal: null, error }), 2e3);
300361
- settlementTimer.unref?.();
300362
300418
  };
300363
300419
  const finish = (result) => {
300364
300420
  if (settled) return;
300365
300421
  settled = true;
300366
300422
  clearTimeout(timer);
300367
300423
  if (forceTimer) clearTimeout(forceTimer);
300368
- if (settlementTimer) clearTimeout(settlementTimer);
300369
300424
  options.signal?.removeEventListener("abort", onAbort);
300370
300425
  resolve10(result);
300371
300426
  };
@@ -300373,20 +300428,27 @@ async function runCommand(command, args, options = {}) {
300373
300428
  terminate(new Error("command cancelled"));
300374
300429
  };
300375
300430
  options.signal?.addEventListener("abort", onAbort, { once: true });
300431
+ if (options.signal?.aborted) onAbort();
300376
300432
  child.stdout?.on("data", (chunk) => {
300377
300433
  stdout = capture(stdout, chunk);
300434
+ options.onStdout?.(chunk.toString());
300378
300435
  });
300379
300436
  child.stderr?.on("data", (chunk) => {
300380
300437
  stderr = capture(stderr, chunk);
300438
+ options.onStderr?.(chunk.toString());
300381
300439
  });
300382
300440
  child.once("error", (error) => finish({ status: null, stdout, stderr, signal: null, error }));
300383
- child.once("close", (status, signal) => finish({ status, stdout, stderr, signal, ...stopError ? { error: stopError } : {} }));
300441
+ child.once("close", (status, signal) => {
300442
+ if (stopping) signalChild("SIGKILL");
300443
+ finish({ status, stdout, stderr, signal, ...stopError ? { error: stopError } : {} });
300444
+ });
300384
300445
  timer = setTimeout(() => {
300385
300446
  terminate(new Error(`command timed out after ${options.timeout ?? 15e3}ms`));
300386
300447
  }, options.timeout ?? 15e3);
300387
300448
  timer.unref?.();
300388
300449
  });
300389
300450
  }
300451
+ var runCommand = runUpdateCommand;
300390
300452
  function globalPackageCandidates(prefix) {
300391
300453
  return process.platform === "win32" ? [join15(prefix, "node_modules", "omnius", "package.json"), join15(prefix, "omnius", "package.json")] : [join15(prefix, "lib", "node_modules", "omnius", "package.json"), join15(prefix, "node_modules", "omnius", "package.json")];
300392
300454
  }
@@ -300448,71 +300510,38 @@ async function quiesceDaemonWithRetry(quiesce, attempts = 3, pauseMs = 250) {
300448
300510
  }
300449
300511
  return false;
300450
300512
  }
300451
- function installGlobalPackageStreaming(input) {
300452
- return new Promise((resolve10) => {
300453
- const stderrTail = [];
300454
- let settled = false;
300455
- let timedOut = false;
300456
- const finish = (exitCode, error) => {
300457
- if (settled) return;
300458
- settled = true;
300459
- clearTimeout(timer);
300460
- resolve10({ exitCode, ...error ? { error } : {} });
300461
- };
300462
- const child = spawn2(
300463
- input.npmPath,
300464
- [
300465
- "install",
300466
- "-g",
300467
- `omnius@${input.targetVersion}`,
300468
- "--prefer-online",
300469
- "--no-audit",
300470
- "--no-fund",
300471
- "--no-progress"
300472
- ],
300473
- {
300474
- env: input.env,
300475
- stdio: ["ignore", "pipe", "pipe"],
300476
- windowsHide: true
300477
- }
300478
- );
300479
- child.stdout?.on("data", (chunk) => {
300480
- process.stdout.write(chunk);
300481
- });
300482
- child.stderr?.on("data", (chunk) => {
300483
- const text2 = String(chunk);
300484
- process.stderr.write(text2);
300485
- stderrTail.push(text2);
300486
- while (stderrTail.join("").length > 8e3 && stderrTail.length > 1) stderrTail.shift();
300487
- });
300488
- child.once("error", (error) => finish(-1, error.message));
300489
- child.once("close", (code, signal) => {
300490
- const exitCode = code ?? -1;
300491
- const evidence = stderrTail.join("").trim();
300492
- finish(
300493
- exitCode,
300494
- exitCode === 0 ? void 0 : timedOut ? "npm install timed out after 5 minutes" : evidence || `npm install exited with ${signal ? `signal ${signal}` : `code ${exitCode}`}`
300495
- );
300496
- });
300497
- const timer = setTimeout(() => {
300498
- timedOut = true;
300499
- try {
300500
- child.kill("SIGTERM");
300501
- } catch {
300502
- }
300503
- const forceTimer = setTimeout(() => {
300504
- try {
300505
- child.kill("SIGKILL");
300506
- } catch {
300507
- }
300508
- }, 2500);
300509
- forceTimer.unref?.();
300510
- }, 5 * 6e4);
300513
+ async function installGlobalPackageStreaming(input) {
300514
+ const result = await runUpdateCommand(input.npmPath, [
300515
+ "install",
300516
+ "-g",
300517
+ `omnius@${input.targetVersion}`,
300518
+ "--prefer-online",
300519
+ "--no-audit",
300520
+ "--no-fund",
300521
+ "--no-progress"
300522
+ ], {
300523
+ env: input.env,
300524
+ signal: input.signal,
300525
+ timeout: 5 * 6e4,
300526
+ onStdout: (text2) => process.stdout.write(text2),
300527
+ onStderr: (text2) => process.stderr.write(text2)
300511
300528
  });
300529
+ const exitCode = result.status ?? -1;
300530
+ return { exitCode, ...result.error || exitCode !== 0 ? {
300531
+ error: result.error?.message || result.stderr.slice(-8e3).trim() || `npm install exited with ${result.signal || exitCode}`
300532
+ } : {} };
300512
300533
  }
300513
300534
  async function runVerifiedUpdateTransaction(initial, dependencies, paths = resolveUpdatePaths()) {
300514
300535
  let state = initial;
300515
300536
  let daemonQuiesced = false;
300537
+ let installStarted = false;
300538
+ const throwIfCancelled = () => {
300539
+ if (dependencies.signal?.aborted) throw new UpdateCancelledError();
300540
+ };
300541
+ const onCancel = () => {
300542
+ if (state.status === "running") state = transition(state, { phase: "cancelling" }, paths);
300543
+ };
300544
+ dependencies.signal?.addEventListener("abort", onCancel, { once: true });
300516
300545
  const target = assertExactUpdateTarget(initial.target_version);
300517
300546
  const npmPath = resolveNpmPath();
300518
300547
  const env = {
@@ -300524,6 +300553,7 @@ async function runVerifiedUpdateTransaction(initial, dependencies, paths = resol
300524
300553
  OMNIUS_UPDATE_COORDINATED: "1"
300525
300554
  };
300526
300555
  try {
300556
+ throwIfCancelled();
300527
300557
  if (dependencies.quiesceDaemon) {
300528
300558
  state = transition(state, { phase: "daemon_quiescing" }, paths);
300529
300559
  if (!await quiesceDaemonWithRetry(dependencies.quiesceDaemon)) {
@@ -300532,20 +300562,25 @@ async function runVerifiedUpdateTransaction(initial, dependencies, paths = resol
300532
300562
  );
300533
300563
  }
300534
300564
  daemonQuiesced = true;
300565
+ throwIfCancelled();
300535
300566
  }
300536
- const prefixProbe = await runCommand(npmPath, ["prefix", "-g"], { env, timeout: 1e4 });
300567
+ const prefixProbe = await runCommand(npmPath, ["prefix", "-g"], { env, timeout: 1e4, signal: dependencies.signal });
300568
+ throwIfCancelled();
300537
300569
  state = transition(state, {
300538
300570
  phase: "installing",
300539
300571
  npm_path: npmPath,
300540
300572
  ...prefixProbe.status === 0 && prefixProbe.stdout.trim() ? { npm_prefix: prefixProbe.stdout.trim() } : {}
300541
300573
  }, paths);
300542
300574
  const installer = dependencies.install ?? installGlobalPackageStreaming;
300543
- const installResult = await installer({ npmPath, targetVersion: target, env });
300575
+ installStarted = true;
300576
+ const installResult = await installer({ npmPath, targetVersion: target, env, signal: dependencies.signal });
300544
300577
  state = transition(state, { installer_exit_code: installResult.exitCode }, paths);
300578
+ throwIfCancelled();
300545
300579
  if (installResult.exitCode !== 0) {
300546
300580
  throw new Error(installResult.error || `npm install exited with code ${installResult.exitCode}`);
300547
300581
  }
300548
300582
  const evidence = dependencies.inspectInstall ? await dependencies.inspectInstall(target, npmPath, env) : await inspectGlobalOmniusInstall(target, { npmPath, env });
300583
+ throwIfCancelled();
300549
300584
  state = transition(state, {
300550
300585
  phase: "package_verified",
300551
300586
  npm_prefix: evidence.npmPrefix,
@@ -300559,8 +300594,10 @@ async function runVerifiedUpdateTransaction(initial, dependencies, paths = resol
300559
300594
  let daemon = null;
300560
300595
  let restartAcknowledged = false;
300561
300596
  for (let attempt = 1; attempt <= 3; attempt++) {
300597
+ throwIfCancelled();
300562
300598
  restartAcknowledged = await dependencies.restartDaemon(target, evidence.executablePath) || restartAcknowledged;
300563
300599
  daemon = await dependencies.observeDaemon();
300600
+ throwIfCancelled();
300564
300601
  if (daemon?.bootVersion === target && daemon.bootPackageHash === evidence.packageHash) {
300565
300602
  break;
300566
300603
  }
@@ -300587,12 +300624,14 @@ async function runVerifiedUpdateTransaction(initial, dependencies, paths = resol
300587
300624
  daemon_boot_hash: daemon.bootPackageHash
300588
300625
  }, paths);
300589
300626
  if (state.tray_was_running && dependencies.restartTray) {
300627
+ throwIfCancelled();
300590
300628
  state = transition(state, { phase: "tray_restarting" }, paths);
300591
300629
  if (!await dependencies.restartTray(evidence.executablePath)) {
300592
300630
  throw new Error("The package and daemon updated, but the running tray could not be relaunched");
300593
300631
  }
300594
300632
  state = transition(state, { tray_restarted: true }, paths);
300595
300633
  }
300634
+ throwIfCancelled();
300596
300635
  const now = (/* @__PURE__ */ new Date()).toISOString();
300597
300636
  state = transition(state, {
300598
300637
  status: "completed",
@@ -300603,25 +300642,32 @@ async function runVerifiedUpdateTransaction(initial, dependencies, paths = resol
300603
300642
  }, paths);
300604
300643
  return state;
300605
300644
  } catch (error) {
300645
+ const cancelled = error instanceof UpdateCancelledError || dependencies.signal?.aborted === true;
300606
300646
  const message = error instanceof Error ? error.message : String(error);
300607
300647
  let recoveryNote;
300608
300648
  if (daemonQuiesced && dependencies.recoverDaemon) {
300649
+ state = transition(state, { phase: "recovering" }, paths);
300609
300650
  try {
300610
300651
  const recovered = await dependencies.recoverDaemon();
300611
- recoveryNote = recovered ? "The prior daemon was restarted after the failed update." : "The daemon could not be recovered automatically after the failed update.";
300652
+ recoveryNote = recovered ? "The daemon was restarted after the interrupted update." : "The daemon could not be recovered automatically after the failed update.";
300612
300653
  } catch (recoveryError) {
300613
300654
  recoveryNote = `Daemon recovery failed: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`;
300614
300655
  }
300615
300656
  }
300616
300657
  state = transition(state, {
300617
- status: "failed",
300618
- phase: "failed",
300658
+ status: cancelled ? "cancelled" : "failed",
300659
+ phase: cancelled ? "cancelled" : "failed",
300619
300660
  completed_at: (/* @__PURE__ */ new Date()).toISOString(),
300620
- error: message,
300621
- remediation: [permissionRemediation(message), recoveryNote].filter(Boolean).join(" ") || void 0
300661
+ error: cancelled ? "Update cancelled after the owned operation settled." : message,
300662
+ remediation: [
300663
+ cancelled && installStarted ? "Package files may have changed. No rollback was performed; verify the installed version before retrying." : void 0,
300664
+ permissionRemediation(message),
300665
+ recoveryNote
300666
+ ].filter(Boolean).join(" ") || void 0
300622
300667
  }, paths);
300623
300668
  return state;
300624
300669
  } finally {
300670
+ dependencies.signal?.removeEventListener("abort", onCancel);
300625
300671
  releaseUpdateLock(paths, initial.operation_id);
300626
300672
  }
300627
300673
  }
@@ -300967,20 +301013,25 @@ async function main() {
300967
301013
  const port = Number(new URL(endpoint).port || "11435");
300968
301014
  const trayWasRunning = state.tray_was_running || (await getTrayStatus(endpoint)).running;
300969
301015
  state.tray_was_running = trayWasRunning;
301016
+ const cancellation = watchUpdateCancellation(operationId, paths);
300970
301017
  const finalState = await runVerifiedUpdateTransaction(
300971
301018
  state,
300972
301019
  {
300973
301020
  quiesceDaemon: () => quiesceDaemonForUpdate(port),
300974
301021
  restartDaemon: (expected, executable) => restartDaemon(port, expected, executable),
300975
- recoverDaemon: () => restartDaemon(port, target),
301022
+ recoverDaemon: async () => {
301023
+ await restartDaemon(port);
301024
+ return Boolean(await getDaemonReportedIdentity(port));
301025
+ },
300976
301026
  observeDaemon: async () => {
300977
301027
  const identity = await getDaemonReportedIdentity(port);
300978
301028
  return identity ? { bootVersion: identity.bootVersion, bootPackageHash: identity.bootPackageHash } : null;
300979
301029
  },
300980
- restartTray: trayWasRunning ? (executable) => restartTrayWithInstalledExecutable(executable, endpoint) : void 0
301030
+ restartTray: trayWasRunning ? (executable) => restartTrayWithInstalledExecutable(executable, endpoint) : void 0,
301031
+ signal: cancellation.signal
300981
301032
  },
300982
301033
  paths
300983
- );
301034
+ ).finally(() => cancellation.close());
300984
301035
  process.exitCode = finalState.status === "completed" ? 0 : 1;
300985
301036
  }
300986
301037
  void main().catch((error) => {