Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
chore(lint): type the new TUI tests instead of `any`; keep the ratchet green
Salman Qureshif38eb9425ce4
diff --git a/.lint-baseline.json b/.lint-baseline.jsonindex 79e9ff09..76cc8c0a 100644--- a/.lint-baseline.json+++ b/.lint-baseline.json@@ -1,7 +1,7 @@{- "$comment": "ESLint ratchet baseline from the first real CI run (PR #149). Counts may only go down; refresh deliberately with `npm run lint:ratchet -- --update`.",+ "$comment": "ESLint ratchet baseline. Per-rule counts (errors + warnings) may only go down. Refresh with `npm run lint:ratchet -- --update` after a clean-up.","provisional": false,- "generatedAt": "2026-10-09T17:40:48.203Z",+ "generatedAt": "2026-10-10T06:55:02.126Z","target": "src","rules": {"(unknown)": 1,@@ -9,7 +9,7 @@"@typescript-eslint/no-require-imports": 6,"@typescript-eslint/no-this-alias": 5,"@typescript-eslint/no-unused-expressions": 100,- "@typescript-eslint/no-unused-vars": 281,+ "@typescript-eslint/no-unused-vars": 280,"no-console": 135,"no-control-regex": 27,"no-func-assign": 5,diff --git a/src/channels/cli.ts b/src/channels/cli.tsindex 794f8c79..7e792a18 100644--- a/src/channels/cli.ts+++ b/src/channels/cli.ts@@ -1296,6 +1296,7 @@ export class CLIChannel extends BaseChannel {* the logger instead (silent unless --verbose) until teardown.*/private captureConsole(): void {+ /* eslint-disable no-console -- this is the console redirect itself */if (this.restoreConsole) return;const methods = ['log', 'info', 'warn', 'error', 'debug'] as const;const original = methods.map((m) => [m, console[m]] as const);@@ -1308,6 +1309,7 @@ export class CLIChannel extends BaseChannel {this.restoreConsole = () => {for (const [m, fn] of original) console[m] = fn;};+ /* eslint-enable no-console */}private inkPatchWarned = false;diff --git a/src/core/system-message-warning.test.ts b/src/core/system-message-warning.test.tsindex 1cab3f7a..d7c88b80 100644--- a/src/core/system-message-warning.test.ts+++ b/src/core/system-message-warning.test.ts@@ -77,7 +77,7 @@ describe('AI SDK system-message warning', () => {describe('console while the TUI is mounted', () => {it('never reaches the terminal, and is restored on teardown', () => {- const channel = new CLIChannel() as any;+ const channel = new CLIChannel() as unknown as { captureConsole(): void; restoreConsole: (() => void) | null };const original = console.warn;const write = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);const errWrite = vi.spyOn(process.stderr, 'write').mockImplementation(() => true);@@ -88,7 +88,7 @@ describe('console while the TUI is mounted', () => {console.log('stray log');expect(write).not.toHaveBeenCalled();expect(errWrite).not.toHaveBeenCalled();- channel.restoreConsole();+ channel.restoreConsole?.();expect(console.warn).toBe(original);} finally {write.mockRestore();diff --git a/src/ui/App.tsx b/src/ui/App.tsxindex e22d81d0..2d460a1f 100644--- a/src/ui/App.tsx+++ b/src/ui/App.tsx@@ -7,12 +7,11 @@ import type { PermissionMode } from '../channels/base.js';import type { ProgrammingModeState } from '../core/programming-mode.js';import { renderMarkdown } from '../utils/markdown.js';import { IS_LIGHT_TERMINAL } from '../utils/terminal-theme.js';-import { isDevBuild } from '../utils/dev-build.js';import { highlightCodeBlock } from '../utils/highlight.js';import { normalizeTerminalText, getViewportWindow } from './terminal-viewport.js';import { useTerminalSize as useSharedTerminalSize } from './use-terminal-size.js';import { CursorCell } from './cursor-anchor.js';-import { isNarrow, ruleWidth, sidePanelWidth, fitText, fitTail, hintColumns } from './layout.js';+import { isNarrow, ruleWidth, sidePanelWidth, fitTail, hintColumns } from './layout.js';import { useTick, spinnerFrame, elapsedSeconds, SPINNER_FRAMES } from './tick-store.js';import { loadInputHistory, saveInputHistory } from './input-history-store.js';import { buildMercuryMessageLines, buildMercuryBrandLines, buildStreamTailLines, parseChunkIndex, splitFinalMessage, splitStreamingMessage, type MercuryTranscriptLine } from './mercury-transcript.js';@@ -309,7 +308,7 @@ export function TuiApp({ channel, onInput, onPermissionResolve, onExit, onInterr}// Typing anywhere starts chat with that text already in the input:// keystrokes on the launch pad are never dropped.- if (ch && !key.ctrl && !key.meta && !key.escape && /[^\x00-\x1f\x7f]/.test(ch)) {+ if (ch && !key.ctrl && !key.meta && !key.escape && [...ch].some((c) => { const code = c.codePointAt(0) ?? 0; return code >= 0x20 && code !== 0x7f; })) {onInput('/chat');const text = ch.replace(/[\r\n]+$/, '');setInputAndCursor(text);diff --git a/src/ui/launch-pad.test.tsx b/src/ui/launch-pad.test.tsxindex abc7845d..8a2bfd6d 100644--- a/src/ui/launch-pad.test.tsx+++ b/src/ui/launch-pad.test.tsx@@ -78,7 +78,7 @@ async function renderPad(s: TuiState, cols: number, onInput: (t: string) => voidconst channel = { getTuiStateSnapshot: () => s, subscribeToTuiState: () => () => {} };const { unmount } = render(<TuiApp channel={channel} onInput={onInput} onPermissionResolve={() => {}} onExit={() => {}} />,- { stdout: stdout as any, stdin: stdin as any, exitOnCtrlC: false, patchConsole: false, debug: true },+ { stdout: stdout as unknown as NodeJS.WriteStream, stdin: stdin as unknown as NodeJS.ReadStream, exitOnCtrlC: false, patchConsole: false, debug: true },);// Wait for the full mark draw-in (13 rows × 24 ms) and a settled frame.await waitFor(() => stripAnsi(stdout.output).includes('Workspace'));@@ -125,7 +125,7 @@ describe('launch pad rendering', () => {const rows = lastFrame(stdout, 'Workspace');for (const row of rows) expect(stringWidth(row)).toBeLessThanOrEqual(cols);const text = rows.join('\n');- expect(text).toMatch(/MERCURY|█ █/);+ expect(text).toMatch(/MERCURY|█ {3}█/);expect(text).toContain(cols >= 50 ? 'anthropic · claude-opus-5-5' : 'anthropic');expect(text).toContain('Type to start chatting');// Wordmark when it fits (with padding); a one-line header otherwise.diff --git a/src/ui/live-region-residue.test.tsx b/src/ui/live-region-residue.test.tsxindex 26fddce2..a30935da 100644--- a/src/ui/live-region-residue.test.tsx+++ b/src/ui/live-region-residue.test.tsx@@ -44,8 +44,23 @@ class FakeStdin extends EventEmitter {read(): null { return null; }}+/** Ink render options over the fake terminal. */+const io = (stdout: unknown) => ({+ stdout: stdout as NodeJS.WriteStream,+ stdin: new FakeStdin() as unknown as NodeJS.ReadStream,+ exitOnCtrlC: false,+ patchConsole: false,+});++/** Test-only access to CLIChannel's private state update. */+const updateChannel = (channel: CLIChannel, patch: Record<string, unknown>) =>+ (channel as unknown as { update(p: Record<string, unknown>): void }).update(patch);+const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));+/** Fixture messages are plain objects; the TUI only reads the fields they set. */+type StatePatch = Record<string, unknown>;+function mount(initial: TuiState, cols = 100, rows = 40) {let snapshot = initial;const listeners = new Set<() => void>();@@ -57,10 +72,10 @@ function mount(initial: TuiState, cols = 100, rows = 40) {const stdout = new FakeStdout(screen);const app = render(<TuiApp channel={channel} onInput={() => {}} onPermissionResolve={() => {}} onExit={() => {}} />,- { stdout: stdout as any, stdin: new FakeStdin() as any, exitOnCtrlC: false, patchConsole: false },+ io(stdout),);- const setState = (patch: Partial<TuiState>) => {- snapshot = { ...snapshot, ...patch } as TuiState;+ const setState = (patch: StatePatch) => {+ snapshot = { ...snapshot, ...patch } as unknown as TuiState;for (const l of listeners) l();};return { screen, stdout, setState, unmount: app.unmount };@@ -85,11 +100,11 @@ describe('live region residue', () => {it.each([[100, 40], [100, 12]])('Processing block disappears when the reply lands (%i×%i)', async (cols, rows) => {const { screen, setState, unmount } = mount(base(), cols, rows);await sleep(80);- setState({ chatMessages: [userMsg] as any, isThinking: true, liveActivity: { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() } as any });+ setState({ chatMessages: [userMsg], isThinking: true, liveActivity: { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() } });await sleep(250); // a few spinner ticksexpect(screen.text().join('\n')).toContain('Processing');// The reply lands and the turn ends in one state update, as in the agent.- setState({ chatMessages: [userMsg, agentMsg] as any, isThinking: false, liveActivity: null as any });+ setState({ chatMessages: [userMsg, agentMsg], isThinking: false, liveActivity: null });await sleep(250);const text = screen.text().join('\n');unmount();@@ -102,11 +117,11 @@ describe('live region residue', () => {it('Processing block disappears when the turn ends before the reply is added', async () => {const { screen, setState, unmount } = mount(base());await sleep(80);- setState({ chatMessages: [userMsg] as any, isThinking: true, liveActivity: { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() } as any });+ setState({ chatMessages: [userMsg], isThinking: true, liveActivity: { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() } });await sleep(250);- setState({ isThinking: false, liveActivity: null as any });+ setState({ isThinking: false, liveActivity: null });await sleep(60);- setState({ chatMessages: [userMsg, agentMsg] as any });+ setState({ chatMessages: [userMsg, agentMsg] });await sleep(250);const text = screen.text().join('\n');unmount();@@ -121,15 +136,15 @@ describe('live region residue — streamed reply', () => {const { screen, setState, unmount } = mount(base(), cols, rows);await sleep(80);const live = { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() };- setState({ chatMessages: [userMsg] as any, isThinking: true, liveActivity: live as any });+ setState({ chatMessages: [userMsg], isThinking: true, liveActivity: live });await sleep(200);// Stream the reply in chunks while the turn is still thinking.for (let n = 1; n <= 6; n++) {const partial = longReply.split('\n').slice(0, n * 2).join('\n');- setState({ chatMessages: [userMsg, { id: 'a1', role: 'agent', content: partial, timestamp: Date.now(), streaming: true }] as any, isThinking: true, liveActivity: { ...live, phase: 'Composing response' } as any });+ setState({ chatMessages: [userMsg, { id: 'a1', role: 'agent', content: partial, timestamp: Date.now(), streaming: true }], isThinking: true, liveActivity: { ...live, phase: 'Composing response' } });await sleep(90);}- setState({ chatMessages: [userMsg, { id: 'a1', role: 'agent', content: longReply, timestamp: Date.now() }] as any, isThinking: false, liveActivity: null as any });+ setState({ chatMessages: [userMsg, { id: 'a1', role: 'agent', content: longReply, timestamp: Date.now() }], isThinking: false, liveActivity: null });await sleep(300);const text = screen.text().join('\n');unmount();@@ -155,16 +170,16 @@ describe('live region residue — real CLIChannel turn', () => {] as const)('%s: Processing does not survive', async (_label, fromSplash, cols, rows) => {const channel = new CLIChannel();channel.initSplash('Mercury', '1.3.1');- (channel as any).update({ provider: { name: 'anthropic', model: 'claude-opus-5-5' } });- if (!fromSplash) (channel as any).update({ mode: 'chat' });+ updateChannel(channel, { provider: { name: 'anthropic', model: 'claude-opus-5-5' } });+ if (!fromSplash) updateChannel(channel, { mode: 'chat' });const screen = new VtScreen(cols, rows);const stdout = new FakeStdout(screen);const app = render(- <TuiApp channel={channel as any} onInput={() => {}} onPermissionResolve={() => {}} onExit={() => {}} />,- { stdout: stdout as any, stdin: new FakeStdin() as any, exitOnCtrlC: false, patchConsole: false },+ <TuiApp channel={channel} onInput={() => {}} onPermissionResolve={() => {}} onExit={() => {}} />,+ io(stdout),);await sleep(500); // launch pad draw-in- if (fromSplash) (channel as any).update({ mode: 'chat' });+ if (fromSplash) updateChannel(channel, { mode: 'chat' });await sleep(50);channel.sendUserMessage('so sup');channel.setLiveActivity('Starting task');@@ -199,22 +214,22 @@ describe('live region residue — terminal backpressure', () => {let snapshot = base();const listeners = new Set<() => void>();const channel = { getTuiStateSnapshot: () => snapshot, subscribeToTuiState: (l: () => void) => { listeners.add(l); return () => { listeners.delete(l); }; } };- const setState = (patch: Partial<TuiState>) => { snapshot = { ...snapshot, ...patch } as TuiState; for (const l of listeners) l(); };+ const setState = (patch: StatePatch) => { snapshot = { ...snapshot, ...patch } as unknown as TuiState; for (const l of listeners) l(); };const screen = new VtScreen(100, 40);const tty = new BackpressureStdout(screen);- const out = new ResilientTuiOutput(tty as any, new FakeStdout(new VtScreen(100, 40)) as any);+ const out = new ResilientTuiOutput(tty as unknown as NodeJS.WriteStream, new FakeStdout(new VtScreen(100, 40)) as unknown as NodeJS.WriteStream);const app = render(<TuiApp channel={channel} onInput={() => {}} onPermissionResolve={() => {}} onExit={() => {}} />,- { stdout: out as any, stdin: new FakeStdin() as any, exitOnCtrlC: false, patchConsole: false },+ io(out),);await sleep(80);- setState({ chatMessages: [userMsg] as any, isThinking: true, liveActivity: { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() } as any });+ setState({ chatMessages: [userMsg], isThinking: true, liveActivity: { phase: 'Starting task', stepsDone: 0, startedAt: Date.now() } });await sleep(120);// The buffer is momentarily full while the reply lands.tty.needDrainFor = 2;- setState({ chatMessages: [userMsg, agentMsg] as any, isThinking: false, liveActivity: null as any });+ setState({ chatMessages: [userMsg, agentMsg], isThinking: false, liveActivity: null });await sleep(250);- setState({ chatMessages: [userMsg, agentMsg, { id: 'u2', role: 'user', content: 'next', timestamp: Date.now() }] as any });+ setState({ chatMessages: [userMsg, agentMsg, { id: 'u2', role: 'user', content: 'next', timestamp: Date.now() }] });await sleep(250);app.unmount();out.dispose();diff --git a/src/ui/narrow-terminal.test.tsx b/src/ui/narrow-terminal.test.tsxindex c6d62ddd..55f1d704 100644--- a/src/ui/narrow-terminal.test.tsx+++ b/src/ui/narrow-terminal.test.tsx@@ -122,13 +122,11 @@ describe(`TUI at ${COLS} columns`, () => {'· Budget ' + (1200).toLocaleString() + ' / ' + (100000).toLocaleString() + ' today',trimmed[at + 6],]);- expect(trimmed[at + 6]).toMatch(/^· Workspace /);+ expect(trimmed[at + 6]).toMatch(/^· Workspace {2}/);expect(trimmed.slice(at + 7, at + 10)).toEqual(['', 'Type to start chatting', '/code Mercury Code here Tab skills']);unmount();});--it('chat: input chrome is exactly four rows and the sidebar collapses', async () => {const { rows, unmount } = await renderApp(state({mode: 'chat',