omegon 0.6.15 → 0.6.16

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.
@@ -432,28 +432,66 @@ export default function (pi: ExtensionAPI) {
432
432
  /**
433
433
  * Replace the current Omegon process with a fresh instance.
434
434
  *
435
- * Spawns a new detached Omegon process with inherited stdio, then exits
436
- * the current process. The user sees the terminal briefly reset and the
437
- * new session starts automatically no manual re-launch needed.
435
+ * Resets terminal state (exits raw mode, alternate screen, mouse capture),
436
+ * then uses shell `exec` to replace the process in-place. This avoids the
437
+ * race between old-process TUI teardown and new-process TUI startup that
438
+ * causes ANSI garbage when using detach+exit.
438
439
  */
439
440
  function restartOmegon(): never {
440
441
  const { command, argvPrefix } = resolveOmegonSubprocess();
441
- // Pass through any user-facing args from the original invocation
442
- // (skip argv[0]=node, argv[1]=omegon.mjs which argvPrefix covers)
443
442
  const userArgs = process.argv.slice(2).filter(a =>
444
- // Strip injected resource flags — the new process injects its own
445
443
  !a.startsWith("--extensions-dir=") &&
446
444
  !a.startsWith("--themes-dir=") &&
447
445
  !a.startsWith("--skills-dir=") &&
448
- !a.startsWith("--prompts-dir=")
446
+ !a.startsWith("--prompts-dir=") &&
447
+ !a.startsWith("--extension=") && !a.startsWith("--extension ") &&
448
+ !a.startsWith("--skill=") && !a.startsWith("--skill ") &&
449
+ !a.startsWith("--prompt-template=") && !a.startsWith("--prompt-template ") &&
450
+ !a.startsWith("--theme=") && !a.startsWith("--theme ") &&
451
+ !a.startsWith("--no-skills") &&
452
+ !a.startsWith("--no-prompt-templates") &&
453
+ !a.startsWith("--no-themes") &&
454
+ !a.startsWith("--no-extensions")
449
455
  );
450
- const child = spawn(command, [...argvPrefix, ...userArgs], {
456
+
457
+ // Reset terminal to sane state before exec replaces us
458
+ const reset = [
459
+ "\x1b[?1049l", // exit alternate screen buffer
460
+ "\x1b[?1000l", // disable mouse click tracking
461
+ "\x1b[?1002l", // disable mouse drag tracking
462
+ "\x1b[?1006l", // disable SGR mouse mode
463
+ "\x1b[?25h", // show cursor
464
+ "\x1b[0m", // reset attributes
465
+ "\x1bc", // full terminal reset (RIS)
466
+ ].join("");
467
+ process.stdout.write(reset);
468
+
469
+ // Exit raw mode if active
470
+ if (process.stdin.isTTY && process.stdin.isRaw) {
471
+ process.stdin.setRawMode(false);
472
+ }
473
+
474
+ // Build the exec command — shell `exec` replaces the process entirely,
475
+ // no orphan child, no race between old and new TUI.
476
+ const parts = [command, ...argvPrefix, ...userArgs].map(shellEscape);
477
+ const child = spawn("sh", ["-c", `exec ${parts.join(" ")}`], {
451
478
  stdio: "inherit",
452
- detached: true,
453
479
  env: process.env,
454
480
  });
481
+ // If exec fails for some reason, exit when the child does
482
+ child.on("close", (code) => process.exit(code ?? 1));
483
+ // Prevent Node from keeping the event loop alive for other reasons
455
484
  child.unref();
456
- process.exit(0);
485
+
486
+ // The sh -c exec should have replaced us. If we're still here,
487
+ // just wait for the child.
488
+ return undefined as never;
489
+ }
490
+
491
+ /** Escape a string for POSIX shell */
492
+ function shellEscape(s: string): string {
493
+ if (/^[a-zA-Z0-9_./:=-]+$/.test(s)) return s;
494
+ return `'${s.replace(/'/g, "'\\''")}'`;
457
495
  }
458
496
 
459
497
  /** Run a command, collect stdout+stderr, resolve with exit code. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omegon",
3
- "version": "0.6.15",
3
+ "version": "0.6.16",
4
4
  "description": "Omegon — an opinionated distribution of pi (by Mario Zechner) with extensions for lifecycle management, memory, orchestration, and visualization",
5
5
  "bin": {
6
6
  "omegon": "bin/omegon.mjs",