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(desktop): / commands and # skills in the composer, as in the terminal

Salman Qureshia425251463f1
diff --git a/apps/desktop/src/api/mercury.ts b/apps/desktop/src/api/mercury.ts
index 231953ed..fa534073 100644
--- a/apps/desktop/src/api/mercury.ts
+++ b/apps/desktop/src/api/mercury.ts
@@ -4,6 +4,7 @@
═══════════════════════════════════════════════════════════════ */
import { http, ApiError } from "./client";
+import type { CommandEntry } from "~/views/chat/picker";
import type { SkillDraft,
BotApproval, BotInboxEntry, BotManifest, BotPlan, CrewSpec, BotRunRecord, BotStatus, BotTier, BotTierId, ChatMessage, ChatSettings, ChatThread, CodeStatus, HealthInfo,
McpServer, ModelsResponse, CodeMode, CostReport, Deliverable, RunTranscript, PairResponse, PluginItem, ReasoningChoice, Skill, DeviceSummary,
@@ -57,6 +58,8 @@ export const chat = {
save: (threadId: string, saved: boolean) => http.post<{ id: string; saved: boolean; savedAt: string | null }>(`/api/chat/threads/${encodeURIComponent(threadId)}/save`, { saved }),
undo: (threadId: string, content: string) => http.post<{ ok: boolean; content: string; removed: number }>(`/api/chat/threads/${encodeURIComponent(threadId)}/undo`, { content }),
answer: (promptId: string, action: string, targetId?: string) => http.post<{ resolved: boolean }>(`/api/chat/permission/${encodeURIComponent(promptId)}`, { action, targetId }),
+ /** Every slash command with what it does (the "/" picker). */
+ commands: () => http.get<{ commands: CommandEntry[] }>("/api/chat/commands").then((r) => r.commands),
settings: () => http.get<ChatSettings>("/api/chat/settings"),
updateSettings: (patch: Partial<ChatSettings>) => http.put<ChatSettings>("/api/chat/settings", patch),
models: () => http.get<ModelsResponse>("/api/chat/models"),
diff --git a/apps/desktop/src/views/chat/CommandPicker.tsx b/apps/desktop/src/views/chat/CommandPicker.tsx
new file mode 100644
index 00000000..e0c472bf
--- /dev/null
+++ b/apps/desktop/src/views/chat/CommandPicker.tsx
@@ -0,0 +1,50 @@
+import { Hash, Puzzle, Slash } from "lucide-react";
+import { useEffect, useRef } from "react";
+import { cx } from "~/lib/cx";
+import type { PickerItem } from "./picker";
+
+/**
+ * The list above the composer while you type "/…" or "#…": the command (or
+ * skill), what it takes, and what it does. Arrow keys move, Tab fills, Enter
+ * runs a command that needs nothing more (or fills one that does), Esc closes.
+ */
+export function CommandPicker({ items, active, mode, onPick, onHover }: {
+ items: PickerItem[];
+ active: number;
+ mode: "command" | "skill";
+ onPick: (item: PickerItem) => void;
+ onHover: (index: number) => void;
+}) {
+ const list = useRef<HTMLDivElement>(null);
+ useEffect(() => {
+ list.current?.querySelector<HTMLElement>(`[data-index="${active}"]`)?.scrollIntoView({ block: "nearest" });
+ }, [active]);
+ return (
+ <div className="absolute bottom-full left-0 right-0 z-30 mb-2 overflow-hidden rounded-2xl border border-line bg-surface shadow-[0_8px_32px_-12px_rgb(0_0_0/0.28)]" role="listbox" aria-label={mode === "command" ? "Commands" : "Skills"}>
+ <div className="flex items-center gap-2 border-b border-line px-4 py-2 text-2xs font-medium uppercase tracking-wider text-ink4">
+ {mode === "command" ? <Slash size={11} /> : <Hash size={11} />}
+ {mode === "command" ? "Commands" : "Skills"}
+ <span className="flex-1" />
+ <span className="normal-case tracking-normal">↑↓ choose · Tab fill · Enter {mode === "command" ? "run" : "use"} · Esc close</span>
+ </div>
+ <div ref={list} className="max-h-[300px] overflow-y-auto py-1">
+ {items.map((item, i) => (
+ <button
+ key={item.key}
+ data-index={i}
+ role="option"
+ aria-selected={i === active}
+ onMouseEnter={() => onHover(i)}
+ onMouseDown={(e) => { e.preventDefault(); onPick(item); }}
+ className={cx("flex w-full items-baseline gap-3 px-4 py-1.5 text-left", i === active ? "bg-ink/[0.06]" : "")}
+ >
+ <span className="shrink-0 font-mono text-[13px] text-ink">{item.label}</span>
+ {item.hint && <span className="shrink-0 font-mono text-xs text-ink4">{item.hint}</span>}
+ <span className="min-w-0 flex-1 truncate text-xs text-ink3">{item.description}</span>
+ {item.kind === "command" && item.plugin && <span className="flex shrink-0 items-center gap-1 text-2xs text-ink4"><Puzzle size={10} />{item.plugin}</span>}
+ </button>
+ ))}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/views/chat/Composer.tsx b/apps/desktop/src/views/chat/Composer.tsx
index 255d4752..5ae3c61e 100644
--- a/apps/desktop/src/views/chat/Composer.tsx
+++ b/apps/desktop/src/views/chat/Composer.tsx
@@ -1,10 +1,12 @@
import { ArrowUp, AudioLines, ChevronDown, Paperclip, Shield, ShieldCheck, Square, X } from "lucide-react";
-import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { cx } from "~/lib/cx";
import * as api from "~/api/mercury";
import type { ModelsResponse } from "~/api/types";
import { usePermissionMode } from "~/app/permission";
-import { useRuntimeState } from "~/app/store";
+import { useBots, useRuntimeState } from "~/app/store";
+import { CommandPicker } from "./CommandPicker";
+import { matchCommands, matchSkills, pickerMode, type CommandEntry, type PickerItem, type SkillEntry } from "./picker";
import { startCall, useVoice } from "~/app/voice";
import { sendMessage, stopTurn, type CodeTurn } from "~/app/events";
import { useConversation, useConversationStore, type Surface } from "~/app/conversation";
@@ -51,6 +53,10 @@ export interface ComposerProps {
modeLabel?: string;
}
+/** Loaded once per app run: the "/" commands and the "#" skills. */
+let commandCache: CommandEntry[] | null = null;
+let skillCache: SkillEntry[] | null = null;
+
export function Composer({ surface, placeholder, code, extra, blockedReason, mono, draft, onDraftConsumed, onCycleMode, modeLabel }: ComposerProps) {
const [text, setText] = useState("");
const [files, setFiles] = useState<Pending[]>([]);
@@ -65,6 +71,29 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
const connected = useRuntimeState((s) => s.connected);
const textRef = useRef(text);
textRef.current = text;
+
+ // "/" commands and "#" skills, as in the terminal: a list above the box while you type.
+ const mode = pickerMode(text);
+ const [commands, setCommands] = useState<CommandEntry[]>(commandCache ?? []);
+ const [skills, setSkills] = useState<SkillEntry[]>(skillCache ?? []);
+ const bots = useBots((s) => s.bots);
+ useEffect(() => {
+ if (mode === "command" && !commandCache) void api.chat.commands().then((c) => { commandCache = c; setCommands(c); }).catch(() => {});
+ if (mode === "skill" && !skillCache) void api.skills.list().then((r) => { skillCache = r.skills; setSkills(r.skills); }).catch(() => {});
+ }, [mode]);
+ const items = useMemo<PickerItem[]>(
+ () => (mode === "command" ? matchCommands(text, commands, bots) : mode === "skill" ? matchSkills(text, skills) : []),
+ [mode, text, commands, skills, bots],
+ );
+ const [active, setActive] = useState(0);
+ const [dismissed, setDismissed] = useState<string | null>(null);
+ useEffect(() => { setActive(0); }, [text]);
+ /** Fill the box with a pick; a command that needs nothing more runs straight away when `run`. */
+ function choose(item: PickerItem, run: boolean) {
+ if (run && item.runs) { void submit(item.fill); return; }
+ setText(item.fill);
+ requestAnimationFrame(() => { const el = ref.current; if (el) { el.focus(); el.setSelectionRange(item.fill.length, item.fill.length); } });
+ }
const dictation = useDictation((spoken, mode) => {
const next = joinText(textRef.current, spoken);
if (mode === "send") { void submit(next); return; }
@@ -183,6 +212,7 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
const canSend = connected && !blockedReason && (text.trim().length > 0 || files.length > 0);
const canSendRef = useRef(false);
canSendRef.current = connected && !blockedReason;
+ const pickerOpen = items.length > 0 && dismissed !== text && !recording && connected && !blockedReason;
return (
<div className="shrink-0 px-8 pb-6 pt-2">
@@ -194,13 +224,14 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
onDragLeave={() => setDragging(false)}
onDrop={(e) => { e.preventDefault(); setDragging(false); if (e.dataTransfer.files.length) void addFiles(e.dataTransfer.files); }}
className={cx(
- "rounded-[28px] border bg-surface transition-[border-color,box-shadow] duration-150",
+ "relative rounded-[28px] border bg-surface transition-[border-color,box-shadow] duration-150",
"shadow-[0_1px_2px_rgb(0_0_0/0.04),0_4px_16px_-8px_rgb(0_0_0/0.12)]",
"focus-within:border-line-strong focus-within:shadow-[0_0_0_4px_rgb(var(--ink)/0.05),0_4px_16px_-8px_rgb(0_0_0/0.16)]",
dragging ? "border-accent border-dashed" : "border-line",
!connected && "opacity-70",
)}
>
+ {pickerOpen && mode && <CommandPicker items={items} active={Math.min(active, items.length - 1)} mode={mode} onHover={setActive} onPick={(item) => choose(item, true)} />}
{files.length > 0 && (
<div className="flex flex-wrap gap-2 px-4 pt-4">
{files.map((f) => (
@@ -226,6 +257,13 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
onChange={(e) => setText(e.target.value)}
onPaste={(e) => { if (e.clipboardData.files.length) { e.preventDefault(); void addFiles(e.clipboardData.files); } }}
onKeyDown={(e) => {
+ if (pickerOpen) {
+ if (e.key === "ArrowDown") { e.preventDefault(); setActive((a) => (a + 1) % items.length); return; }
+ if (e.key === "ArrowUp") { e.preventDefault(); setActive((a) => (a - 1 + items.length) % items.length); return; }
+ if (e.key === "Tab" && !e.shiftKey) { e.preventDefault(); choose(items[active], false); return; }
+ if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) { e.preventDefault(); choose(items[active], true); return; }
+ if (e.key === "Escape") { e.preventDefault(); setDismissed(text); return; }
+ }
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) { e.preventDefault(); void submit(); }
if (e.key === "Escape" && text) { e.preventDefault(); setText(""); }
else if (e.key === "Escape" && busy) { e.preventDefault(); stop(); }
diff --git a/apps/desktop/src/views/chat/picker.test.ts b/apps/desktop/src/views/chat/picker.test.ts
new file mode 100644
index 00000000..4d39a9cc
--- /dev/null
+++ b/apps/desktop/src/views/chat/picker.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it } from "vitest";
+import { matchCommands, matchSkills, pickerMode, type CommandEntry } from "./picker";
+
+const catalog: CommandEntry[] = [
+ { command: "/help", usage: "/help", description: "Show this manual", takesArgument: false, source: "mercury" },
+ { command: "/bots", usage: "/bots", description: "List your bots and fleets", takesArgument: false, source: "mercury" },
+ { command: "/bots open ", usage: "/bots open <id>", description: "Open a bot's own chat", takesArgument: true, source: "mercury" },
+ { command: "/models use ", usage: "/models use <provider>", description: "Switch the chat model", takesArgument: true, source: "mercury" },
+ { command: "/weather ", usage: "/weather …", description: "Forecast for a city", takesArgument: true, source: "plugin", plugin: "Weather" },
+];
+
+describe("composer pickers", () => {
+ it("opens the command picker on a leading slash and the skill picker on a #word still being typed", () => {
+ expect(pickerMode("/")).toBe("command");
+ expect(pickerMode("/bots open sc")).toBe("command");
+ expect(pickerMode("#rese")).toBe("skill");
+ expect(pickerMode("#research do this")).toBeNull();
+ expect(pickerMode("hello /help")).toBeNull();
+ expect(pickerMode("/help\nmore")).toBeNull();
+ });
+
+ it("lists commands that start with the text first, then ones whose words or description match", () => {
+ expect(matchCommands("/", catalog).map((i) => i.label)).toEqual(["/help", "/bots", "/bots open", "/models use", "/weather"]);
+ expect(matchCommands("/bo", catalog).map((i) => i.label)).toEqual(["/bots", "/bots open"]);
+ expect(matchCommands("/forecast", catalog).map((i) => i.label)).toEqual(["/weather"]);
+ const use = matchCommands("/models", catalog)[0];
+ expect(use).toMatchObject({ label: "/models use", hint: "<provider>", fill: "/models use ", runs: false });
+ expect(matchCommands("/help", catalog)[0]).toMatchObject({ runs: true, fill: "/help" });
+ expect(matchCommands("/w", catalog)[0]).toMatchObject({ plugin: "Weather" });
+ });
+
+ it("completes a bot id where the command takes one", () => {
+ const bots = [{ id: "scout", name: "Scout" }, { id: "writer", name: "Writer" }];
+ const items = matchCommands("/bots open sc", catalog, bots);
+ expect(items[0]).toMatchObject({ label: "/bots open scout", fill: "/bots open scout ", description: "Scout" });
+ });
+
+ it("finds skills by name, then by description, and skips turned-off ones", () => {
+ const skills = [
+ { name: "web-search", description: "Search the web", active: true },
+ { name: "pptx", description: "Make slides from research", active: true },
+ { name: "old", description: "research", active: false },
+ ];
+ expect(matchSkills("#", skills).map((i) => i.label)).toEqual(["#web-search", "#pptx"]);
+ expect(matchSkills("#research", skills).map((i) => i.label)).toEqual(["#pptx"]);
+ expect(matchSkills("#web", skills)[0]).toMatchObject({ fill: "#web-search " });
+ });
+});
diff --git a/apps/desktop/src/views/chat/picker.ts b/apps/desktop/src/views/chat/picker.ts
new file mode 100644
index 00000000..b22cdaf9
--- /dev/null
+++ b/apps/desktop/src/views/chat/picker.ts
@@ -0,0 +1,84 @@
+/* ═══════════════════════════════════════════════════════════════
+ The composer's pickers: "/" for commands, "#" for skills — the same
+ ones the terminal has. Pure functions; Composer draws and wires them.
+ ═══════════════════════════════════════════════════════════════ */
+
+export interface CommandEntry {
+ command: string;
+ usage: string;
+ description: string;
+ takesArgument: boolean;
+ source: "mercury" | "plugin";
+ plugin?: string;
+}
+
+export interface SkillEntry {
+ name: string;
+ description?: string;
+ active?: boolean;
+}
+
+export type PickerItem =
+ | { kind: "command"; key: string; label: string; hint: string; description: string; fill: string; runs: boolean; plugin?: string }
+ | { kind: "skill"; key: string; label: string; hint: string; description: string; fill: string; runs: false };
+
+/** "/bots <action> " subcommands whose argument is a bot id. */
+const BOT_ARG = /^(\/bots\s+(?:open|send|journal|inbox|budget|edit|delete|enable|disable|stop|start|run|persona|show|folder|fetch|tasks|crew|promote|demote|permissions|export|add-crew|remove-crew)\s+)(\S*)$/i;
+
+/** Which picker the text asks for, if any: a single line starting with "/", or a "#skill" still being typed. */
+export function pickerMode(text: string): "command" | "skill" | null {
+ if (text.includes("\n")) return null;
+ if (text.startsWith("/")) return "command";
+ if (/^#[^\s]*$/.test(text)) return "skill";
+ return null;
+}
+
+/**
+ * Commands for what's typed: bot ids when the command takes one, then the
+ * commands that start with it, then the ones whose words or description
+ * contain it. Exact matches first; at most `limit`.
+ */
+export function matchCommands(text: string, catalog: readonly CommandEntry[], bots: ReadonlyArray<{ id: string; name: string }> = [], limit = 40): PickerItem[] {
+ const out: PickerItem[] = [];
+ const arg = BOT_ARG.exec(text);
+ if (arg && bots.length) {
+ const [, prefix, typed] = arg;
+ const p = typed.toLowerCase();
+ for (const b of bots.filter((x) => x.id.toLowerCase().startsWith(p) || x.name.toLowerCase().startsWith(p)).slice(0, 8)) {
+ out.push({ kind: "command", key: `bot:${b.id}`, label: `${prefix}${b.id}`, hint: "", description: b.name, fill: `${prefix}${b.id} `, runs: false });
+ }
+ }
+ const q = text.toLowerCase();
+ const words = q.slice(1).trim();
+ const starts = catalog.filter((c) => c.command.toLowerCase().startsWith(q) || c.command.trim().toLowerCase() === q.trim());
+ const contains = words
+ ? catalog.filter((c) => !starts.includes(c) && (c.command.toLowerCase().includes(words) || c.description.toLowerCase().includes(words)))
+ : [];
+ for (const c of [...starts, ...contains]) {
+ if (out.length >= limit) break;
+ const label = c.command.trim();
+ out.push({
+ kind: "command",
+ key: c.command,
+ label,
+ hint: c.usage.startsWith(label) ? c.usage.slice(label.length).trim() : "",
+ description: c.description,
+ fill: c.command,
+ runs: !c.takesArgument,
+ plugin: c.source === "plugin" ? c.plugin : undefined,
+ });
+ }
+ return out;
+}
+
+/** Skills for "#…": name prefix, then name contains, then description contains. Active skills only. */
+export function matchSkills(text: string, skills: readonly SkillEntry[], limit = 40): PickerItem[] {
+ const q = text.slice(1).toLowerCase();
+ const usable = skills.filter((s) => s.active !== false);
+ const prefix = usable.filter((s) => s.name.toLowerCase().startsWith(q));
+ const name = usable.filter((s) => !prefix.includes(s) && s.name.toLowerCase().includes(q));
+ const desc = q ? usable.filter((s) => !prefix.includes(s) && !name.includes(s) && (s.description ?? "").toLowerCase().includes(q)) : [];
+ return [...prefix, ...name, ...desc].slice(0, limit).map((s) => ({
+ kind: "skill" as const, key: s.name, label: `#${s.name}`, hint: "", description: s.description ?? "", fill: `#${s.name} `, runs: false as const,
+ }));
+}