Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(attach): live reply renders like the settled block (no cyan bar); spinners animate (1.3.8)
Salman Qureshiac76f2b62c6b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 672c7e38..95c4bec7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,10 @@# Changelog+## 1.3.8 — hotfix: live reply rendering and spinners in the attach TUI++- **No more cyan bar beside a streaming reply.** The attach TUI (what `mercury` opens) drew the live reply with a cyan `│` strip that disappeared once the reply settled. The live tail now renders exactly like the settled block — same `MERCURY:` header, indent and markdown.+- **Working/step indicators animate.** The attach TUI showed a frozen `⠋ working…` and static `→` steps; they now run on the shared 100 ms ticker like the main TUI.+## 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.diff --git a/README.md b/README.mdindex 7d42b3e5..9f69f23d 100644--- a/README.md+++ b/README.md@@ -21,7 +21,7 @@</p><p align="center">- <strong>🔖 Current Stable: v1.3.7 — Steady Mercury</strong>+ <strong>🔖 Current Stable: v1.3.8 — Steady Mercury</strong></p><p align="center">diff --git a/package-lock.json b/package-lock.jsonindex 7318d78f..56667419 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.3.7",+ "version": "1.3.8","lockfileVersion": 2,"requires": true,"packages": {"": {"name": "@cosmicstack/mercury-agent",- "version": "1.3.7",+ "version": "1.3.8","hasInstallScript": true,"license": "MIT","dependencies": {diff --git a/package.json b/package.jsonindex ec10fdfd..0423c0e8 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "@cosmicstack/mercury-agent",- "version": "1.3.7",+ "version": "1.3.8","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/ui/attach-live-render.test.tsx b/src/ui/attach-live-render.test.tsxnew file mode 100644index 00000000..a58a19d0--- /dev/null+++ b/src/ui/attach-live-render.test.tsx@@ -0,0 +1,56 @@+process.env.CI = '0';+import { describe, expect, it } from 'vitest';+import React from 'react';+import { EventEmitter } from 'node:events';+import { VtScreen } from './vt-screen.js';++class FakeStdout extends EventEmitter { isTTY = true; constructor(public screen: VtScreen) { super(); } get columns() { return this.screen.columns; } get rows() { return this.screen.rows; } write(c: string) { this.screen.write(c); return true; } }+class FakeStdin extends EventEmitter { isTTY = true; private q: string[] = []; setEncoding() {} setRawMode() {} resume() {} pause() {} ref() {} unref() {} read() { return this.q.shift() ?? null; } push(c: string) { this.q.push(c); this.emit('readable'); } }+const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));++/**+ * The attach TUI is the default launch (ADR-024). Its live reply used to be+ * drawn with a cyan "│" bar that vanished when the reply settled, and its+ * "working…" glyph never animated.+ */+describe('attach TUI live rendering', () => {+ it('streams a reply without a side bar, under a MERCURY header, with an animating spinner', async () => {+ const { render } = await import('ink');+ const { AttachTui } = await import('./attach-tui.js');+ let emit: ((e: { type: string; data: Record<string, unknown> }) => void) | null = null;+ const client = {+ getBaseUrl: () => 'http://127.0.0.1:6174',+ listThreads: async () => [],+ listSkills: async () => [],+ listBots: async () => [],+ currentModel: async () => ({ name: 'anthropic', model: 'x' }),+ budget: async () => null,+ createThread: async () => ({ id: 't1', shortId: 't1', alias: 'new', title: 'New' }),+ streamEvents: async (_id: string, onEvent: (e: { type: string; data: Record<string, unknown> }) => void) => { emit = onEvent; await new Promise(() => {}); },+ send: async () => ({ ok: true }),+ resolvePermission: async () => true,+ } as never;+ const screen = new VtScreen(100, 30); const stdin = new FakeStdin();+ const app = render(<AttachTui client={client} pid={1} version="1.3.8" onExit={() => {}} />, { stdout: new FakeStdout(screen) as never, stdin: stdin as never, exitOnCtrlC: false, patchConsole: false } as never);+ await sleep(300);+ stdin.push('\r'); // "new session" is the only pick row+ await sleep(300);+ expect(emit).not.toBeNull();+ emit!({ type: 'thinking', data: {} });+ await sleep(150);+ const a = screen.text().join('\n');+ expect(a).toContain('working…');+ const glyphA = a.match(/([⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]) working/)?.[1];+ await sleep(350);+ const glyphB = screen.text().join('\n').match(/([⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]) working/)?.[1];+ expect(glyphA).toBeDefined();+ expect(glyphB).not.toBe(glyphA);+ emit!({ type: 'text_delta', data: { text: 'Here is the reply, still streaming.' } });+ await sleep(200);+ const b = screen.text().join('\n');+ expect(b).toContain('MERCURY:');+ expect(b).toContain('Here is the reply, still streaming.');+ expect(b).not.toContain('│ Here');+ app.unmount();+ }, 20000);+});diff --git a/src/ui/attach-tui.tsx b/src/ui/attach-tui.tsxindex d8df3f6b..9887cfcd 100644--- a/src/ui/attach-tui.tsx+++ b/src/ui/attach-tui.tsx@@ -1,6 +1,7 @@import React from 'react';import { parseAttachHandoff } from './attach-handoff.js';import { LaunchPad } from './launch-pad.js';+import { useTick, spinnerFrame } from './tick-store.js';import { rotateTip } from './tips.js';import type { TuiState } from '../channels/cli.js';import { Box, Text, Spacer, Static, useApp, useInput } from 'ink';@@ -138,6 +139,11 @@ export function AttachTui({ client, pid, version, onExit, onHandoff }: { client:const [provider, setProvider] = React.useState<{ name: string; model: string } | null>(null);const [tokenInfo, setTokenInfo] = React.useState<{ used: number; budget: number } | null>(null);const launchTip = React.useMemo(() => rotateTip('chat')?.tip ?? null, []);+ // One shared 100 ms ticker drives every spinner while something is in flight.+ // (A hook: it must run on every render, before the pick-screen return.)+ const busy = streaming || steps.some((s) => !s.done);+ const tick = useTick(busy);+ const frame = spinnerFrame(tick);const [notice, setNotice] = React.useState<string | null>(null);const [input, setInput] = React.useState('');@@ -515,7 +521,12 @@ export function AttachTui({ client, pid, version, onExit, onHandoff }: { client:}const providerLabel = provider && provider.name ? `${provider.name}${provider.model ? ` ${provider.model}` : ''}` : 'connected';- const tailLines = streamTail.length > 0 ? streamTail.split('\n').slice(-ATTACH_STREAM_TAIL_MAX_LINES) : [];+ // The live tail looks exactly like the settled block it becomes: the same+ // MERCURY header and indent, the same markdown pass (an unclosed fence is+ // closed for rendering only). It used to be drawn with a cyan "│" bar that+ // vanished when the reply settled — the strip people saw in chat.+ const fenceSafeTail = (streamTail.match(/```/g) || []).length % 2 === 1 ? streamTail + '\n```' : streamTail;+ const tailLines = streamTail.length > 0 ? renderMarkdown(fenceSafeTail).split('\n').slice(-ATTACH_STREAM_TAIL_MAX_LINES) : [];return (<Box flexDirection="column" flexShrink={0}>@@ -524,18 +535,21 @@ export function AttachTui({ client, pid, version, onExit, onHandoff }: { client:</Static>{tailLines.length > 0 && (<Box flexDirection="column" flexShrink={0}>- {tailLines.map((line, idx) => (- <Box key={`t:${idx}`} paddingX={2}>- <Text color="cyan">│ </Text><Text>{line || ' '}</Text>- </Box>- ))}+ <Box flexShrink={0}><Text bold color="cyan">MERCURY:</Text></Box>+ <Box marginLeft={2} flexDirection="column" flexShrink={0}>+ {tailLines.map((line, idx) => (+ <Box key={`t:${idx}`} flexShrink={0}>+ <Text>{line.length > 0 ? line : ' '}</Text>+ </Box>+ ))}+ </Box></Box>)}{steps.length > 0 && (<Box flexDirection="column" paddingX={2} flexShrink={0}>{steps.map((step) => (<Box key={step.key}>- <Text color={step.done ? 'green' : 'cyan'}>{step.done ? '✓' : '→'}</Text>+ <Text color={step.done ? 'green' : 'cyan'}>{step.done ? '✓' : frame}</Text><Text dimColor> {step.label}</Text></Box>))}@@ -543,7 +557,7 @@ export function AttachTui({ client, pid, version, onExit, onHandoff }: { client:)}{streaming && tailLines.length === 0 && steps.length === 0 && (<Box paddingX={2} flexShrink={0}>- <Text color="cyan">⠋</Text><Text dimColor> working…</Text>+ <Text color="cyan">{frame}</Text><Text dimColor> working…</Text></Box>)}{prompt && <AttachPromptView prompt={prompt} activeIdx={promptIdx} />}