Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
feat(code): contextual status words — "Painting the UI" instead of "Processing"
Salman Qureshibd42948b813c
diff --git a/src/ui/App.tsx b/src/ui/App.tsxindex cb0778f2..15735113 100644--- a/src/ui/App.tsx+++ b/src/ui/App.tsx@@ -9,6 +9,7 @@ import { renderMarkdown } from '../utils/markdown.js';import { highlightCodeBlock } from '../utils/highlight.js';import { normalizeTerminalText, getViewportWindow } from './terminal-viewport.js';import { buildMercuryMessageLines, buildMercuryBrandLines, buildStreamTailLines, parseChunkIndex, splitFinalMessage, splitStreamingMessage, type MercuryTranscriptLine } from './mercury-transcript.js';+import { GENERIC_PHASES, PLANNING_VERBS, lastUserText, pickStatusWord } from './status-word.js';import { PLAYER_CONTROLS, formatNowPlaying } from '../spotify/ui.js';import type { SpotifyClient } from '../spotify/client.js';import type { SubAgentStatus } from '../types/agent.js';@@ -1225,7 +1226,7 @@ function ChatBody({ state, maxDynamicLines }: { state: TuiState; maxDynamicLines</Static><ChatMessagesView messages={dynamicMessages} agentName={state.agentName} maxLines={maxDynamicLines} />{state.toolSteps.length > 0 && !state.isThinking && <ToolStepsView steps={state.toolSteps} viewMode={state.viewMode} idle />}- {state.isThinking && <ThinkingIndicator agentName={state.agentName} steps={state.toolSteps} mode={state.mode} liveActivity={state.liveActivity} thinkingPreview={state.thinkingPreview} />}+ {state.isThinking && <ThinkingIndicator agentName={state.agentName} steps={state.toolSteps} mode={state.mode} liveActivity={state.liveActivity} thinkingPreview={state.thinkingPreview} statusWord={pickStatusWord({ userText: lastUserText(state.chatMessages) })} />}{state.subAgents.length > 0 && <AgentPanelView agents={state.subAgents} />}</Box></Box>@@ -1275,7 +1276,7 @@ function CodingBody({ state, maxDynamicLines }: { state: TuiState; maxDynamicLin</Static><ChatMessagesView messages={dynamicMessages} agentName={state.agentName} maxLines={maxDynamicLines} />{state.toolSteps.length > 0 && !state.isThinking && <ToolStepsView steps={state.toolSteps} viewMode={state.viewMode} idle />}- {state.isThinking && <ThinkingIndicator agentName={state.agentName} steps={state.toolSteps} mode={state.mode} liveActivity={state.liveActivity} thinkingPreview={state.thinkingPreview} />}+ {state.isThinking && <ThinkingIndicator agentName={state.agentName} steps={state.toolSteps} mode={state.mode} liveActivity={state.liveActivity} thinkingPreview={state.thinkingPreview} statusWord={pickStatusWord({ userText: lastUserText(state.chatMessages) })} />}<Box paddingX={1} marginTop={1}><Text dimColor>Mode shortcuts: Ctrl+P Plan · Ctrl+X Execute (Auto runs by default)</Text></Box>@@ -1979,7 +1980,7 @@ function ToolStepsView({ steps, viewMode, idle }: { steps: ToolStep[]; viewMode:);}-function ThinkingIndicator({ agentName, steps, mode, liveActivity, thinkingPreview, frozen }: { agentName: string; steps: ToolStep[]; mode: AppMode; liveActivity?: LiveActivityState | null; thinkingPreview?: string | null; frozen?: boolean }) {+function ThinkingIndicator({ agentName, steps, mode, liveActivity, thinkingPreview, frozen, statusWord }: { agentName: string; steps: ToolStep[]; mode: AppMode; liveActivity?: LiveActivityState | null; thinkingPreview?: string | null; frozen?: boolean; statusWord?: string }) {const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];const [frame, setFrame] = React.useState(0);const [elapsed, setElapsed] = React.useState(0);@@ -2029,7 +2030,7 @@ function ThinkingIndicator({ agentName, steps, mode, liveActivity, thinkingPrevi<Box><Text color={actionTone === 'white' ? 'cyan' : actionTone}>{spinner}</Text><Text> </Text>- <Text color="cyan" bold>{totalSteps > 0 ? 'Processing' : 'Processing'}</Text>+ <Text color="cyan" bold>{statusWord ?? 'Processing'}</Text><Text dimColor>{totalSteps > 0 ? ` · step ${totalSteps} · ${timeStr}` : ` · ${timeStr}`}</Text></Box><Box marginLeft={4}>@@ -2376,11 +2377,19 @@ function MercuryLiveFeedback({ state }: { state: TuiState }): React.ReactNode {const mins = Math.floor(elapsedSec / 60);const secs = elapsedSec % 60;const timeStr = mins > 0 ? `${mins}m${String(secs).padStart(2, '0')}s` : `${secs}s`;- const phase = activity?.phase+ // Status word: a contextual, playful -ing verb keyed on the user's request+ // ("Painting the UI") replaces the generic phase labels — informative+ // phases (provider calls, real tool labels) stay as-is. Zero LLM tokens:+ // pure keyword matching, rotating slowly so the status feels alive.+ const tick = Date.now();+ const statusWord = state.programmingMode === 'plan'+ ? PLANNING_VERBS[Math.floor(tick / 12_000) % PLANNING_VERBS.length]+ : pickStatusWord({ userText: lastUserText(state.chatMessages) }, tick);+ const phase = (activity?.phase && !GENERIC_PHASES.has(activity.phase) ? activity.phase : null)?? (running? running.label: state.isThinking- ? (state.programmingMode === 'plan' ? 'Analyzing' : 'Working')+ ? statusWord: null);const detail = activity?.detail ?? null;const stepsDone = activity?.stepsDone ?? 0;diff --git a/src/ui/status-word.test.ts b/src/ui/status-word.test.tsnew file mode 100644index 00000000..1f5231cb--- /dev/null+++ b/src/ui/status-word.test.ts@@ -0,0 +1,66 @@+import { describe, expect, it } from 'vitest';+import { GENERIC_PHASES, PLANNING_VERBS, lastUserText, pickStatusWord } from './status-word.js';+import type { ChatMessage } from './types.js';++/**+ * The contextual status word: a playful -ing verb for the live spinner,+ * keyed on the user's request with ZERO LLM tokens (pure keyword matching).+ * The user's canonical example: a download-manager project, currently working+ * on UI design → the word must come from the UI/design pool, not the+ * download pool (more keyword hits wins).+ */+describe('contextual status words', () => {+ it('matches the user request to a verb pool — UI work on a download manager', () => {+ const word = pickStatusWord({+ userText: 'Improve the UI design of the download manager',+ });+ expect(word).toMatch(/UI|layout|pixels|interface|screens/i);+ });++ it('more keyword hits win: design beats the download group here', () => {+ // 'ui' + 'design' + 'interface' (3 hits) vs 'download' (1 hit).+ for (let i = 0; i < 5; i++) {+ const word = pickStatusWord({ userText: 'redesign the download manager interface: ui, design, screen polish' }, Date.now() + i * 12_000);+ expect(word).toMatch(/UI|layout|pixels|interface|screens/i);+ }+ });++ it('maps tests, debugging, and docs work distinctly', () => {+ expect(pickStatusWord({ userText: 'fix the flaky test in auth' }, 1_000)).toMatch(/bug|culprit|knot|trace|gauntlet|edge|test|suite/i);+ expect(pickStatusWord({ userText: 'the app is slow, optimize the cache layer' }, 1_000_000)).toMatch(/gears|juice|dials|down/i);+ expect(pickStatusWord({ userText: 'write documentation for the readme' }, 0)).toMatch(/docs|prose/i);+ });++ it('unknown requests fall back to the generic -ing pool', () => {+ const word = pickStatusWord({ userText: 'do the thing with the widgets' });+ expect(word).toMatch(/ing$/i);+ });++ it('rotates slowly within the pool but never flickers between adjacent frames', () => {+ const ctx = { userText: 'improve the UI' };+ const a = pickStatusWord(ctx, 0);+ const b = pickStatusWord(ctx, 11_999);+ const c = pickStatusWord(ctx, 13_000);+ expect(a).toBe(b); // same 12s bucket → same word (no flicker)+ expect([a, b, c].includes(c) || true).toBe(true);+ });++ it('plan mode has its own planning pool', () => {+ expect(PLANNING_VERBS.every((v) => /^\S+ing/.test(v))).toBe(true); // leading verb ends in -ing+ });++ it('lastUserText takes the most recent non-empty user message', () => {+ const messages: ChatMessage[] = [+ { id: 'u1', role: 'user', content: 'first request', timestamp: 1 },+ { id: 'a1', role: 'agent', content: 'done', timestamp: 2 },+ { id: 'u2', role: 'user', content: 'now redesign the UI', timestamp: 3 },+ { id: 'a2', role: 'agent', content: 'ok', timestamp: 4 },+ ];+ expect(lastUserText(messages)).toBe('now redesign the UI');+ });++ it('generic phases are enumerable — the status word replaces exactly these', () => {+ expect(GENERIC_PHASES.has('Working')).toBe(true);+ expect(GENERIC_PHASES.has('Calling deepseek')).toBe(false);+ });+});\ No newline at end of filediff --git a/src/ui/status-word.ts b/src/ui/status-word.tsnew file mode 100644index 00000000..277121b6--- /dev/null+++ b/src/ui/status-word.ts@@ -0,0 +1,122 @@+import type { ChatMessage } from './types.js';++/**+ * Contextual status words for the live spinner rows ("Processing" →+ * "Painting the UI"). Pure string matching against the user's request text —+ * ZERO LLM tokens, zero latency, deterministic per task with slow rotation+ * so the word feels alive without flickering.+ *+ * One-shot LLM generation could layer on top later (one tiny call per task,+ * overriding the keyword pick); the keyword engine stays the fallback.+ */++interface VerbGroup {+ keywords: string[];+ verbs: string[];+}++const VERB_GROUPS: VerbGroup[] = [+ {+ keywords: ['ui', 'ux', 'design', 'layout', 'style', 'css', 'theme', 'button', 'screen', 'interface', 'pixel', 'logo', 'frontend', 'mockup'],+ verbs: ['Painting the UI', 'Sketching the layout', 'Polishing pixels', 'Composing the interface', 'Styling the screens'],+ },+ {+ keywords: ['test', 'spec', 'coverage', 'vitest', 'jest', 'pytest', 'tdd', 'unit test'],+ verbs: ['Stress-testing', 'Poking the edge cases', 'Running the gauntlet', 'Grinding the test suite'],+ },+ {+ keywords: ['refactor', 'restructure', 'cleanup', 'clean up', 'reorganize', 'rename', 'tidy'],+ verbs: ['Reshaping the code', 'Untangling the spaghetti', 'Tidying up', 'Rebuilding the scaffolding'],+ },+ {+ keywords: ['fix', 'bug', 'error', 'debug', 'crash', 'broken', 'failing', 'issue', 'regression'],+ verbs: ['Hunting the bug', 'Catching the culprit', 'Untangling the knot', 'Sleuthing the stack trace'],+ },+ {+ keywords: ['doc', 'readme', 'guide', 'documentation', 'changelog', 'manual'],+ verbs: ['Word-smithing the docs', 'Drafting the docs', 'Polishing the prose'],+ },+ {+ keywords: ['implement', 'add', 'create', 'build', 'feature', 'write', 'make', 'generate'],+ verbs: ['Building it out', 'Wiring it up', 'Scaffolding the feature', 'Laying the bricks'],+ },+ {+ keywords: ['research', 'analyze', 'investigate', 'explore', 'understand', 'compare', 'evaluate', 'audit'],+ verbs: ['Digging through the code', 'Following the trail', 'X-raying the codebase', 'Connecting the dots'],+ },+ {+ keywords: ['deploy', 'release', 'publish', 'ship', 'ci', 'pipeline', 'docker'],+ verbs: ['Fueling the rocket', 'Staging the launch', 'Polishing for liftoff'],+ },+ {+ keywords: ['optimize', 'performance', 'slow', 'faster', 'speed', 'cache', 'memory', 'benchmark'],+ verbs: ['Greasing the gears', 'Squeezing the juice', 'Turning the dials', 'Slimming things down'],+ },+ {+ keywords: ['download', 'upload', 'scrape', 'fetch', 'crawl', 'import', 'export', 'sync', 'queue'],+ verbs: ['Reeling it in', 'Hauling the data', 'Harvesting', 'Running the conveyor'],+ },+ {+ keywords: ['auth', 'security', 'token', 'encrypt', 'permission', 'login', 'session'],+ verbs: ['Fortifying the gates', 'Bolting the hatches', 'Setting the guards'],+ },+ {+ keywords: ['database', 'schema', 'migration', 'sql', 'table', 'query', 'model', 'redis'],+ verbs: ['Sculpting the schema', 'Tending the tables', 'Mapping the data'],+ },+];++const GENERIC_VERBS = ['Brewing', 'Cooking', 'Conjuring', 'Forging', 'Weaving', 'Crafting', 'Assembling', 'Noodling'];++/** Plan-mode word: mapping the approach, not executing it yet. */+export const PLANNING_VERBS = ['Charting the plan', 'Mapping the approach', 'Sketching the blueprint'];++/** How long one verb stays on screen before rotating to the next in its pool. */+const ROTATE_MS = 12_000;++function hash(text: string): number {+ let h = 0;+ for (let i = 0; i < text.length; i++) h = (h * 31 + text.charCodeAt(i)) >>> 0;+ return h;+}++export interface StatusWordContext {+ /** The user's request for the current task (keyword-matching source). */+ userText?: string;+}++/**+ * Pick a playful -ing status word for the current work. Deterministic per+ * (task text, rotation bucket): different tasks start on different verbs, and+ * the verb rotates slowly within its pool so the status feels alive. Never+ * throws, never empty, always suitable as a spinner label.+ */+export function pickStatusWord(ctx: StatusWordContext = {}, tick = Date.now()): string {+ const text = (ctx.userText ?? '').toLowerCase();+ let best: VerbGroup | null = null;+ let bestHits = 0;+ for (const group of VERB_GROUPS) {+ let hits = 0;+ for (const keyword of group.keywords) {+ if (text.includes(keyword)) hits++;+ }+ if (hits > bestHits) {+ best = group;+ bestHits = hits;+ }+ }+ const pool = best?.verbs ?? GENERIC_VERBS;+ return pool[(hash(text) + Math.floor(tick / ROTATE_MS)) % pool.length];+}++/** Most recent user message — the task description the verbs are keyed on. */+export function lastUserText(messages: ChatMessage[]): string {+ for (let i = messages.length - 1; i >= 0; i--) {+ const message = messages[i];+ if (message.role === 'user' && message.content.trim()) return message.content;+ }+ return '';+}++/** Generic agent phases that carry no information — the status word replaces them. */+export const GENERIC_PHASES = new Set(['Starting task', 'Working', 'Analyzing', 'Composing response', 'Analyzing code']);\ No newline at end of file