Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(wizard): first-run setup no longer exits at the mode menu (1.3.7)
Salman Qureshiceabacea14c1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 24b01f1b..672c7e38 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,9 @@# Changelog+## 1.3.7 — hotfix: first-run setup exited at the mode menu++- **The setup wizard quit silently at "Choose your mode"** (1.3.1 – 1.3.6, every platform, binaries and npm). The shared readline used for the name questions released itself a tick later and paused stdin *after* the arrow-key menu had taken it over; nothing was reading the terminal, so the process ran out of work and exited 0. The menu now releases the readline synchronously before it owns stdin. Reproduced and verified under a pseudo-terminal.+## 1.3.6 — hotfix: `mercury upgrade` is a no-op when already current- **`mercury upgrade` / `mercury-dev upgrade` re-installed (and restarted the daemon) even on the latest build.** They now resolve the channel's newest version first — stable from `/releases/latest`, dev from the rolling `mercury-dev-latest` release — and stop with "Already on the latest version" without touching the daemon or the binary. `--force` reinstalls anyway.diff --git a/README.md b/README.mdindex d08efcee..7d42b3e5 100644--- a/README.md+++ b/README.md@@ -21,7 +21,7 @@</p><p align="center">- <strong>🔖 Current Stable: v1.3.6 — Steady Mercury</strong>+ <strong>🔖 Current Stable: v1.3.7 — Steady Mercury</strong></p><p align="center">diff --git a/package-lock.json b/package-lock.jsonindex f092bf20..7318d78f 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.3.6",+ "version": "1.3.7","lockfileVersion": 2,"requires": true,"packages": {"": {"name": "@cosmicstack/mercury-agent",- "version": "1.3.6",+ "version": "1.3.7","hasInstallScript": true,"license": "MIT","dependencies": {diff --git a/package.json b/package.jsonindex 7fdfd44a..ec10fdfd 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.3.6",+ "version": "1.3.7","description": "Soul-driven AI agent with Second Brain memory, permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI or Telegram.","type": "module","main": "dist/index.js",diff --git a/src/cli/ask-release.test.ts b/src/cli/ask-release.test.tsnew file mode 100644index 00000000..d8d7c956--- /dev/null+++ b/src/cli/ask-release.test.ts@@ -0,0 +1,42 @@+import { describe, expect, it } from 'vitest';+import { EventEmitter } from 'node:events';+import { PassThrough } from 'node:stream';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { dirname, join } from 'node:path';+import { createPrompter } from './ask.js';++/**+ * Regression: the setup wizard exited 0 at the first arrow-key menu (1.3.1+ * – 1.3.6). ask() releases its shared readline on a deferred setImmediate;+ * readline.close() pauses the input. The menu had already resumed stdin,+ * the deferred pause landed after it, nothing was reading the terminal and+ * the process ran out of work.+ */+describe('shared readline release vs the next stdin consumer', () => {+ it('close() after an answered question is synchronous and cancels the deferred release', async () => {+ const input = new PassThrough();+ const output = new PassThrough();+ const p = createPrompter({ input, output });+ const answer = p.ask('name? ');+ input.write('Tester\n');+ expect(await answer).toBe('Tester');+ // A consumer takes over right away (the arrow menu): release now…+ p.close();+ let pausedLater = false;+ const orig = input.pause.bind(input);+ (input as unknown as { pause: () => unknown }).pause = () => { pausedLater = true; return orig(); };+ // …and the deferred release must not pause the input afterwards.+ await new Promise((r) => setImmediate(() => setImmediate(r)));+ expect(pausedLater).toBe(false);+ });++ it('the arrow menu releases the shared readline before it owns stdin', () => {+ const src = readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'utils', 'arrow-select.ts'), 'utf8').replace(/\r\n/g, '\n');+ const close = src.indexOf('closeAsk();');+ const keypress = src.indexOf('readline.emitKeypressEvents(process.stdin);');+ expect(close).toBeGreaterThan(0);+ expect(keypress).toBeGreaterThan(close);+ });+});+void EventEmitter;diff --git a/src/utils/arrow-select.ts b/src/utils/arrow-select.tsindex 5498cbda..dd4dab42 100644--- a/src/utils/arrow-select.ts+++ b/src/utils/arrow-select.ts@@ -1,4 +1,5 @@import readline from 'node:readline';+import { closeAsk } from '../cli/ask.js';import chalk from 'chalk';export interface ArrowSelectOption {@@ -28,6 +29,12 @@ export async function selectWithArrowKeys(return options[0]?.value ?? '';}+ // The shared question readline (ask.ts) releases itself on a deferred+ // setImmediate, and readline.close() pauses stdin. Taking over stdin here+ // and letting that release land afterwards left nothing reading the+ // terminal: the event loop drained and the wizard exited 0 at the menu.+ // Release it now, synchronously, before we own stdin.+ closeAsk();readline.emitKeypressEvents(process.stdin);const stdin = process.stdin;