Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

feat(code): "Did you know?" tips — surface-categorized, rare, system-voice

Salman Qureshi4e7054bd5a40
diff --git a/src/channels/cli.ts b/src/channels/cli.ts
index 78fcd8bf..bd014b49 100644
--- a/src/channels/cli.ts
+++ b/src/channels/cli.ts
@@ -12,6 +12,7 @@ import { formatToolStep, formatToolResult } from '../utils/tool-label.js';
import type { ChatMessage, CompletionMeta, FileChangeSummary, ToolStep, PermissionPromptState, CurrentSessionInfo, SidebarSection, SkillInfo, SubAgentInfo, ProviderInfo, TokenInfo, SaverInfo, AppMode, WorkspaceState, WorkspaceTreeNode, WorkspaceGitFile, BackgroundTaskInfo, MercuryCodeGitState, MercuryCodeState, LiveActivityState, PlanStep } from '../ui/types.js';
import { TASK_SUMMARY_FILE_LIMIT } from '../ui/types.js';
import { TuiApp } from '../ui/App.js';
+import { nextTip } from '../ui/tips.js';
import { ResilientTuiOutput } from '../ui/resilient-output.js';
/**
@@ -1150,6 +1151,14 @@ export class CLIChannel extends BaseChannel {
lastStepLog: this.state.toolSteps.length > 0 ? [...this.state.toolSteps] : (this.state.lastStepLog ?? null),
lastStepLogElapsed: elapsedMs,
});
+ // "Did you know?" perk: a natural pause (task just finished, nothing
+ // pending). The picker's internal min-gap keeps it to a rare treat, never
+ // repeated, always in the system's own voice. Mercury Code has its own
+ // rotating tip row — the chat notice only fires in chat surfaces.
+ if (this.state.mode !== 'mercury-code') {
+ const tip = nextTip('chat');
+ if (tip) this.sendSystemNotice(`💡 Did you know? ${tip.tip}`);
+ }
}
/**
diff --git a/src/ui/App.tsx b/src/ui/App.tsx
index 8eb4a974..4331eda5 100644
--- a/src/ui/App.tsx
+++ b/src/ui/App.tsx
@@ -10,6 +10,7 @@ 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 { nextTip, rotateTip } from './tips.js';
import { PLAYER_CONTROLS, formatNowPlaying } from '../spotify/ui.js';
import type { SpotifyClient } from '../spotify/client.js';
import type { SubAgentStatus } from '../types/agent.js';
@@ -2370,6 +2371,34 @@ function MercuryLiveFeedback({ state }: { state: TuiState }): React.ReactNode {
}, 100);
return () => clearInterval(t);
}, [active, state.mode, state.tuiFrozen]);
+
+ // "Did you know?" tip row: after a minute of a running task, ONE dim tip
+ // appears and its content rotates a couple of times — the row's height is
+ // fixed for the whole stream (truncated), so no scrollback churn.
+ const [tipText, setTipText] = React.useState<string | null>(null);
+ const tipShownAtRef = React.useRef<number>(0);
+ const tipRotationsRef = React.useRef<number>(0);
+ React.useEffect(() => {
+ if (!active || state.mode !== 'mercury-code' || state.tuiFrozen) return;
+ if (!activity?.startedAt || tipText != null) return;
+ if (Date.now() - activity.startedAt < 60_000) return;
+ const tip = rotateTip('code');
+ if (tip) {
+ tipShownAtRef.current = Date.now();
+ setTipText(tip.tip);
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- activity identity churns; startedAt is the meaningful dep
+ }, [active, state.mode, state.tuiFrozen, activity?.startedAt, forceTick]);
+ React.useEffect(() => {
+ if (!tipText || tipRotationsRef.current >= 2) return;
+ const t = setInterval(() => {
+ tipRotationsRef.current += 1;
+ const next = rotateTip('code');
+ if (next) setTipText(next.tip);
+ if (tipRotationsRef.current >= 3) clearInterval(t);
+ }, 15_000);
+ return () => clearInterval(t);
+ }, [tipText]);
if (state.mode !== 'mercury-code') return null;
if (!active) return null;
@@ -2427,6 +2456,11 @@ function MercuryLiveFeedback({ state }: { state: TuiState }): React.ReactNode {
<Text dimColor> “{state.thinkingPreview.slice(-120)}”</Text>
</Box>
)}
+ {tipText && (
+ <Box paddingLeft={2}>
+ <Text dimColor wrap="truncate-end">💡 Did you know? {tipText}</Text>
+ </Box>
+ )}
{activeAgents.length > 0 && (
<React.Fragment>
<Text color="magenta"> ⧖ swarm · {activeAgents.length} in parallel</Text>
diff --git a/src/ui/tips.json b/src/ui/tips.json
new file mode 100644
index 00000000..d7d92d8c
--- /dev/null
+++ b/src/ui/tips.json
@@ -0,0 +1,132 @@
+[
+ {
+ "id": "code-freeze",
+ "surfaces": ["code"],
+ "tip": "Press Ctrl+S while a response streams to freeze the TUI — scroll, read, and copy freely; the chat keeps running underneath."
+ },
+ {
+ "id": "code-esc-esc",
+ "surfaces": ["code"],
+ "tip": "Esc twice starts the exit — Esc once arms it, Esc again opens the confirm box, and Ctrl+D force-quits without asking."
+ },
+ {
+ "id": "code-ctrl-b",
+ "surfaces": ["code"],
+ "tip": "Ctrl+B moves the current task to the background — it keeps working and reports back when it finishes."
+ },
+ {
+ "id": "code-stop",
+ "surfaces": ["code"],
+ "tip": "Type /stop to cancel a long task outright. Its work entry is closed, so a restart will not resume it — send the request again for a fresh start."
+ },
+ {
+ "id": "code-plan-execute",
+ "surfaces": ["code"],
+ "tip": "Ctrl+P and Ctrl+X flip Mercury Code between PLAN and EXECUTE — plan first, execute only what you approved."
+ },
+ {
+ "id": "code-diff",
+ "surfaces": ["code"],
+ "tip": "Press Ctrl+G (or /code diff) to see exactly what changed on disk before you commit."
+ },
+ {
+ "id": "code-multiline",
+ "surfaces": ["code"],
+ "tip": "Ctrl+N inserts a newline in the input box — describe multi-part changes in one go."
+ },
+ {
+ "id": "code-wheel",
+ "surfaces": ["code"],
+ "tip": "The full transcript lives in your terminal's own scrollback — wheel-scroll it and drag to select text like any other output."
+ },
+ {
+ "id": "code-step-log",
+ "surfaces": ["code"],
+ "tip": "Ctrl+D after a task shows its step log — every command that ran and what it returned."
+ },
+ {
+ "id": "code-summary",
+ "surfaces": ["code"],
+ "tip": "The completion banner recaps the task: what was done, how many files changed, and the next steps it suggests."
+ },
+ {
+ "id": "code-history",
+ "surfaces": ["code"],
+ "tip": "Press ↑ in the input box to walk back through your previous prompts."
+ },
+ {
+ "id": "both-whatsnew",
+ "surfaces": ["code", "chat"],
+ "tip": "/whatsnew shows what changed in this Mercury version, with the release-notes link."
+ },
+ {
+ "id": "both-sessions",
+ "surfaces": ["code", "chat"],
+ "tip": "/sessions lists your sessions; /session new starts a clean one without losing the old."
+ },
+ {
+ "id": "both-budget",
+ "surfaces": ["code", "chat"],
+ "tip": "/budget shows and manages your daily token budget — override, reset, or set a new cap."
+ },
+ {
+ "id": "both-permissions",
+ "surfaces": ["code", "chat"],
+ "tip": "/permissions switches the session permission mode — allow-all for the session, or ask-me for every change."
+ },
+ {
+ "id": "both-models",
+ "surfaces": ["code", "chat"],
+ "tip": "/models use <provider> switches the default model — saved across restarts."
+ },
+ {
+ "id": "both-log",
+ "surfaces": ["code", "chat"],
+ "tip": "Ctrl+D (or /log) prints the last task's step log after it finished."
+ },
+ {
+ "id": "both-view",
+ "surfaces": ["code", "chat"],
+ "tip": "Ctrl+T toggles balanced and detailed views of tool steps."
+ },
+ {
+ "id": "chat-code",
+ "surfaces": ["chat"],
+ "tip": "Type /code in normal chat to jump into Mercury Code — the full-screen coding TUI in the current directory."
+ },
+ {
+ "id": "chat-menu",
+ "surfaces": ["chat"],
+ "tip": "Type / to open the command picker with arrow-key navigation — every command is in there."
+ },
+ {
+ "id": "chat-bg",
+ "surfaces": ["chat"],
+ "tip": "Long task? /bg current sends it to the background and /bg list shows what's running."
+ },
+ {
+ "id": "chat-stop",
+ "surfaces": ["chat"],
+ "tip": "A task you don't want anymore? /stop ends it immediately — no waiting."
+ },
+ {
+ "id": "chat-whatsnew",
+ "surfaces": ["chat"],
+ "tip": "After an update, type /whatsnew — one friendly list of what changed."
+ },
+ {
+ "id": "chat-telegram",
+ "surfaces": ["chat"],
+ "tip": "Mercury also lives in Telegram — /pair links your account and you can chat from your phone."
+ },
+ {
+ "id": "both-skills",
+ "surfaces": ["code", "chat"],
+ "tip": "/skills lists installed skills; /skills search <query> finds more to install."
+ },
+ {
+ "id": "both-status",
+ "surfaces": ["code", "chat"],
+ "tip": "/status shows your setup at a glance — provider, budget, channels, skills."
+ }
+]
\ No newline at end of file
diff --git a/src/ui/tips.test.ts b/src/ui/tips.test.ts
new file mode 100644
index 00000000..70a302f2
--- /dev/null
+++ b/src/ui/tips.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from 'vitest';
+import { TIP_MIN_GAP_MS, TIPS, nextTip, rotateTip, type Tip } from './tips.js';
+
+/**
+ * "Did you know?" tips: curated, surface-categorized, shown as a rare perk.
+ * The dataset itself is contract-tested (content quality) and the picker is
+ * tested for its anti-nag properties.
+ */
+describe('tips dataset', () => {
+ it('every tip has an id, at least one surface, and concise text', () => {
+ const seen = new Set<string>();
+ for (const tip of TIPS as Tip[]) {
+ expect(tip.id).toBeTruthy();
+ expect(seen.has(tip.id)).toBe(false); // no duplicate ids
+ seen.add(tip.id);
+ expect(tip.surfaces.length).toBeGreaterThan(0);
+ expect(['code', 'chat'].some((s) => (tip.surfaces as string[]).includes(s))).toBe(true);
+ expect(tip.tip.length).toBeGreaterThan(20);
+ expect(tip.tip.length).toBeLessThan(220); // must fit one truncated line comfortably
+ }
+ });
+
+ it('covers both surfaces: code-specific, chat-specific, and shared tips', () => {
+ const ids = (surface: 'code' | 'chat') => (TIPS as Tip[]).filter((t) => t.surfaces.includes(surface));
+ expect(ids('code').length).toBeGreaterThan(8);
+ expect(ids('chat').length).toBeGreaterThan(6);
+ });
+});
+
+describe('tip picker (anti-nag)', () => {
+ it('the chat tip is gated by the minimum gap', () => {
+ const now = Date.now();
+ // First call consumes the gap; a second call immediately after must be silent.
+ const first = nextTip('chat', now);
+ if (first) {
+ expect(nextTip('chat', now + 1000)).toBeNull();
+ // After the gap, the next tip arrives.
+ const later = nextTip('chat', now + TIP_MIN_GAP_MS + 1000);
+ expect(later).not.toBeNull();
+ }
+ });
+
+ it('rotates round-robin: a tip never repeats until the pool has cycled', () => {
+ const pool = (TIPS as Tip[]).filter((t) => t.surfaces.includes('code'));
+ const seen = new Set<string>();
+ for (let i = 0; i < pool.length; i++) {
+ const tip = rotateTip('code');
+ expect(seen.has(tip!.id)).toBe(false);
+ seen.add(tip.id);
+ }
+ // One more rotation re-offers the earliest tip — the cycle restarts.
+ expect(seen.size).toBe(pool.length);
+ });
+});
\ No newline at end of file
diff --git a/src/ui/tips.ts b/src/ui/tips.ts
new file mode 100644
index 00000000..31ebd761
--- /dev/null
+++ b/src/ui/tips.ts
@@ -0,0 +1,66 @@
+import rawTips from './tips.json';
+
+/**
+ * "Did you know?" tips — a curated, surface-categorized perk shown SPARINGLY
+ * in the system's own voice (never as an LLM message).
+ *
+ * Anti-nag rules: round-robin rotation with a random start (no tip repeats
+ * until the pool has cycled), a hard minimum gap between tips per surface,
+ * and at most a couple of tips per running task in Mercury Code.
+ */
+
+export interface Tip {
+ id: string;
+ surfaces: Array<'code' | 'chat'>;
+ tip: string;
+}
+
+export const TIPS = rawTips as Tip[];
+
+/** Minimum wall-clock gap between tips on the same surface. */
+export const TIP_MIN_GAP_MS = 5 * 60 * 1000;
+
+const tipsFor = (surface: 'code' | 'chat'): Tip[] => TIPS.filter((tip) => tip.surfaces.includes(surface));
+
+// Round-robin cursors: one per surface, random start per runtime so different
+// sessions start on different tips; every tip shows before any repeats.
+const cursors: Record<string, number> = { code: Math.floor(Math.random() * 6), chat: Math.floor(Math.random() * 7) };
+const lastShownAt: Record<string, number> = { code: 0, chat: 0 };
+const lastShownId: Record<string, string | null> = { code: null, chat: null };
+
+/**
+ * Next tip for a surface: round-robin through the pool (never repeating until
+ * every tip has shown), with a hard minimum gap — null when the gap has not
+ * elapsed (callers stay silent).
+ */
+export function nextTip(surface: 'code' | 'chat', now = Date.now()): Tip | null {
+ const pool = tipsFor(surface);
+ if (pool.length === 0) return null;
+ if (now - (lastShownAt[surface] ?? 0) < TIP_MIN_GAP_MS) return null;
+ const index = cursors[surface]! % pool.length;
+ const tip = pool[index]!;
+ cursors[surface] = (index + 1) % pool.length;
+ lastShownAt[surface] = now;
+ lastShownId[surface] = tip.id;
+ return tip;
+}
+
+/** The id of the tip most recently shown on a surface (for the rotating row). */
+export function lastTipId(surface: 'code' | 'chat'): string | null {
+ return lastShownId[surface];
+}
+
+/**
+ * Rotate the CONTENT of an already-visible tip row (the row's height must
+ * not churn): moves to the next tip in the pool, skipping the one currently
+ * shown. Unlike nextTip, no time gate — the row is already on screen.
+ */
+export function rotateTip(surface: 'code' | 'chat'): Tip | null {
+ const pool = tipsFor(surface);
+ if (pool.length === 0) return null;
+ const index = cursors[surface]! % pool.length;
+ const tip = pool[index]!;
+ cursors[surface] = (index + 1) % pool.length;
+ lastShownId[surface] = tip.id;
+ return tip;
+}
\ No newline at end of file