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): only the commands that fit the app; a picked command is a chip

Salman Qureshia90d307ea0a0
diff --git a/apps/desktop/src/views/chat/CommandChip.tsx b/apps/desktop/src/views/chat/CommandChip.tsx
new file mode 100644
index 00000000..a2391485
--- /dev/null
+++ b/apps/desktop/src/views/chat/CommandChip.tsx
@@ -0,0 +1,26 @@
+import { Hash, Slash, X } from "lucide-react";
+import { cx } from "~/lib/cx";
+
+/**
+ * A command or skill as a chip, not as text: in the composer once picked,
+ * and at the start of a sent message. Commands wear the accent, skills cyan.
+ */
+export function CommandChip({ label, kind, onRemove, className }: { label: string; kind: "command" | "skill"; onRemove?: () => void; className?: string }) {
+ const skill = kind === "skill";
+ const text = label.replace(/^[/#]/, "");
+ return (
+ <span className={cx(
+ "inline-flex h-[26px] shrink-0 select-none items-center gap-1 rounded-lg px-2 align-middle font-mono text-[13px] ring-1",
+ skill ? "bg-cyan/10 text-cyan ring-cyan/30" : "bg-accent/10 text-accent ring-accent/30",
+ className,
+ )}>
+ {skill ? <Hash size={12} strokeWidth={2.25} aria-hidden="true" /> : <Slash size={12} strokeWidth={2.25} aria-hidden="true" />}
+ <span>{text}</span>
+ {onRemove && (
+ <button type="button" onClick={onRemove} className="-mr-1 ml-0.5 rounded p-0.5 opacity-60 hover:opacity-100" aria-label={`Remove ${label}`}>
+ <X size={11} />
+ </button>
+ )}
+ </span>
+ );
+}
diff --git a/apps/desktop/src/views/chat/Composer.tsx b/apps/desktop/src/views/chat/Composer.tsx
index 5ae3c61e..1674e394 100644
--- a/apps/desktop/src/views/chat/Composer.tsx
+++ b/apps/desktop/src/views/chat/Composer.tsx
@@ -6,7 +6,8 @@ import type { ModelsResponse } from "~/api/types";
import { usePermissionMode } from "~/app/permission";
import { useBots, useRuntimeState } from "~/app/store";
import { CommandPicker } from "./CommandPicker";
-import { matchCommands, matchSkills, pickerMode, type CommandEntry, type PickerItem, type SkillEntry } from "./picker";
+import { CommandChip } from "./CommandChip";
+import { matchCommands, matchSkills, pickerMode, relevantCommands, setKnownCommands, 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";
@@ -73,17 +74,23 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
textRef.current = text;
// "/" commands and "#" skills, as in the terminal: a list above the box while you type.
- const mode = pickerMode(text);
+ /** A picked command or skill: a chip before the text, which holds only what follows it. */
+ const [token, setToken] = useState<PickerItem | null>(null);
+ const mode = token ? null : pickerMode(text);
const [commands, setCommands] = useState<CommandEntry[]>(commandCache ?? []);
const [skills, setSkills] = useState<SkillEntry[]>(skillCache ?? []);
const bots = useBots((s) => s.bots);
+ // The list also lets the chat draw earlier commands as chips: load it once, up front.
useEffect(() => {
- if (mode === "command" && !commandCache) void api.chat.commands().then((c) => { commandCache = c; setCommands(c); }).catch(() => {});
+ if (!commandCache) void api.chat.commands().then((c) => { commandCache = c; setKnownCommands(c.map((x) => x.command)); setCommands(c); }).catch(() => {});
+ }, []);
+ useEffect(() => {
+ if (mode === "command" && !commandCache) void api.chat.commands().then((c) => { commandCache = c; setKnownCommands(c.map((x) => x.command)); 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],
+ () => (mode === "command" ? matchCommands(text, relevantCommands(commands, surface), bots) : mode === "skill" ? matchSkills(text, skills) : []),
+ [mode, text, commands, skills, bots, surface],
);
const [active, setActive] = useState(0);
const [dismissed, setDismissed] = useState<string | null>(null);
@@ -91,8 +98,9 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
/** 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); } });
+ setToken(item);
+ setText("");
+ requestAnimationFrame(() => ref.current?.focus());
}
const dictation = useDictation((spoken, mode) => {
const next = joinText(textRef.current, spoken);
@@ -185,13 +193,14 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
}
async function submit(override?: string) {
- const content = (override ?? text).trim();
+ const content = (override ?? (token ? `${token.fill}${text}` : text)).trim();
if ((!content && files.length === 0) || sending) return;
setSending(true);
setError(null);
try {
await sendMessage(surface, content, files.map((f) => ({ name: f.name, data: f.data, mime: f.mime })), code);
setText("");
+ setToken(null);
for (const f of files) if (f.preview) URL.revokeObjectURL(f.preview);
setFiles([]);
} catch (err) {
@@ -209,7 +218,7 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
setError(null);
void stopTurn(convStore).catch((err) => setError(err instanceof Error ? `Couldn't stop: ${err.message}` : "Couldn't stop"));
}
- const canSend = connected && !blockedReason && (text.trim().length > 0 || files.length > 0);
+ const canSend = connected && !blockedReason && (text.trim().length > 0 || files.length > 0 || token !== null);
const canSendRef = useRef(false);
canSendRef.current = connected && !blockedReason;
const pickerOpen = items.length > 0 && dismissed !== text && !recording && connected && !blockedReason;
@@ -251,6 +260,7 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
) : (
<div className="flex">
{mono && <span aria-hidden="true" className="pointer-events-none select-none pl-5 pt-4 font-mono text-md leading-[26px] text-accent">&gt;</span>}
+ {token && <CommandChip label={token.label} kind={token.kind} onRemove={() => { setToken(null); ref.current?.focus(); }} className={mono ? "ml-2 mt-[15px]" : "ml-4 mt-[15px]"} />}
<textarea
ref={ref}
value={text}
@@ -264,15 +274,18 @@ export function Composer({ surface, placeholder, code, extra, blockedReason, mon
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; }
}
+ // The chip goes back to text on Backspace (to edit it) and away on Esc, like a token field.
+ if (token && !text && e.key === "Backspace") { e.preventDefault(); setText(token.fill.trimEnd()); setToken(null); return; }
+ if (token && !text && e.key === "Escape") { e.preventDefault(); setToken(null); 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(); }
if (e.key === "Tab" && e.shiftKey && onCycleMode) { e.preventDefault(); onCycleMode(); }
}}
- placeholder={!connected ? "Waiting for Mercury…" : blockedReason ?? placeholder}
+ placeholder={!connected ? "Waiting for Mercury…" : blockedReason ?? (token ? (token.hint || (token.kind === "skill" ? "What should the skill do?" : "Add details, or press Enter")) : placeholder)}
rows={1}
disabled={!connected}
- className={cx("block max-h-[240px] w-full resize-none overflow-y-auto bg-transparent pb-1 pt-4 text-md leading-[26px] text-ink caret-accent placeholder:truncate placeholder:text-ink4", mono ? "pl-3 pr-5 font-mono text-[14.5px]" : "px-5")}
+ className={cx("block max-h-[240px] w-full resize-none overflow-y-auto bg-transparent pb-1 pt-4 text-md leading-[26px] text-ink caret-accent placeholder:truncate placeholder:text-ink4", mono ? "pl-3 pr-5 font-mono text-[14.5px]" : token ? "pl-2.5 pr-5" : "px-5")}
aria-label="Message"
/>
</div>
diff --git a/apps/desktop/src/views/chat/Message.tsx b/apps/desktop/src/views/chat/Message.tsx
index 17276e87..4d7bbbfc 100644
--- a/apps/desktop/src/views/chat/Message.tsx
+++ b/apps/desktop/src/views/chat/Message.tsx
@@ -1,4 +1,6 @@
import { Check, ChevronRight, Copy, Square, Wrench } from "lucide-react";
+import { CommandChip } from "./CommandChip";
+import { splitCommand } from "./picker";
import { memo, useState } from "react";
import type { ChatMessage, ThoughtTrace } from "~/api/types";
import { Mark } from "~/components/Logo";
@@ -35,7 +37,7 @@ export const Message = memo(function Message({ message, undoable = false }: { me
{files.length > 0 && <Attachments items={files} />}
{text && (
<p className="whitespace-pre-wrap break-words rounded-[22px] rounded-tr-md bg-ink/[0.065] px-4 py-2.5 text-base leading-[1.6] text-ink [overflow-wrap:anywhere]" data-selectable>
- {text}
+ <CommandText text={text} />
</p>
)}
<MessageMeta timestamp={message.timestamp} copy={text || undefined} align="end" undo={undoable ? message : undefined} />
@@ -195,3 +197,15 @@ export function StreamingMessage({ text, live, stopping = false }: { text: strin
</div>
);
}
+
+/** A sent command or skill pick: the command as a chip, then the rest as written. */
+function CommandText({ text }: { text: string }) {
+ const parts = splitCommand(text);
+ if (!parts) return <>{text}</>;
+ return (
+ <>
+ <CommandChip label={parts.token} kind={parts.token.startsWith("#") ? "skill" : "command"} className="mr-1.5 -translate-y-px" />
+ {parts.rest}
+ </>
+ );
+}
diff --git a/apps/desktop/src/views/chat/picker.test.ts b/apps/desktop/src/views/chat/picker.test.ts
index 4d39a9cc..58cbbcdf 100644
--- a/apps/desktop/src/views/chat/picker.test.ts
+++ b/apps/desktop/src/views/chat/picker.test.ts
@@ -46,3 +46,24 @@ describe("composer pickers", () => {
expect(matchSkills("#web", skills)[0]).toMatchObject({ fill: "#web-search " });
});
});
+
+describe("relevant commands and chips", () => {
+ it("keeps the commands that make sense in the app, plus Code's own in Code, plus every plugin command", async () => {
+ const { relevantCommands } = await import("./picker");
+ const all: CommandEntry[] = ["/help", "/menu", "/ws open ", "/sessions", "/code diff", "/bots send ", "/bots dlq clear"].map((c) => ({ command: c, usage: c, description: "", takesArgument: c.endsWith(" "), source: "mercury" as const }));
+ all.push({ command: "/weather ", usage: "/weather …", description: "", takesArgument: true, source: "plugin", plugin: "W" });
+ expect(relevantCommands(all, "chat").map((c) => c.command)).toEqual(["/help", "/bots send ", "/weather "]);
+ expect(relevantCommands(all, "code").map((c) => c.command)).toEqual(["/help", "/code diff", "/bots send ", "/weather "]);
+ });
+
+ it("splits a sent message into its command and the rest", async () => {
+ const { splitCommand } = await import("./picker");
+ const known = ["/bots", "/bots send ", "/models use "];
+ expect(splitCommand("/bots send scout write the brief", known)).toEqual({ token: "/bots send", rest: "scout write the brief" });
+ expect(splitCommand("/bots", known)).toEqual({ token: "/bots", rest: "" });
+ expect(splitCommand("/unknown thing", known)).toEqual({ token: "/unknown", rest: "thing" });
+ expect(splitCommand("#research the oxide raise")).toEqual({ token: "#research", rest: "the oxide raise" });
+ expect(splitCommand("hello")).toBeNull();
+ expect(splitCommand("/ slash alone")).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/views/chat/picker.ts b/apps/desktop/src/views/chat/picker.ts
index b22cdaf9..f35e50d0 100644
--- a/apps/desktop/src/views/chat/picker.ts
+++ b/apps/desktop/src/views/chat/picker.ts
@@ -22,6 +22,52 @@ 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 };
+/**
+ * The commands worth offering in the app. The terminal's list also has its
+ * own screens (/menu, /code exit, /ws …), display switches (/view, /stream)
+ * and things the app has buttons for (sessions, Ask Me / Allow All, the bot
+ * pages); those stay in the terminal. Plugins' commands are always offered.
+ */
+const DESKTOP_COMMANDS = new Set([
+ "/help", "/whatsnew", "/status", "/progress", "/log",
+ "/models", "/models use ", "/cloud models", "/cloud use ",
+ "/research", "/research on", "/research off", "/research ",
+ "/budget", "/saver", "/saver toggle", "/memory", "/tools", "/mcp",
+ "/skills", "/skills search ", "/skills install ",
+ "/plugins", "/plugins search ", "/plugins install ", "/plugins update",
+ "/agents", "/agents stop ", "/bg list", "/bg cancel ", "/stop",
+ "/bots", "/bots send ", "/bots run ", "/bots stop ", "/bots start ", "/bots cost",
+ "/call ", "/calls", "/spotify",
+]);
+
+/** Extra commands in the Code view. */
+const CODE_COMMANDS = new Set(["/code plan", "/code execute", "/code diff", "/code init", "/code agent "]);
+
+/** Commands the runtime knows, once loaded: the chat uses them to draw a sent command as a chip. */
+let known: string[] = [];
+export function setKnownCommands(commands: readonly string[]): void { known = [...commands]; }
+export function knownCommands(): readonly string[] { return known; }
+
+/** The catalog, narrowed to what this view offers. */
+export function relevantCommands(catalog: readonly CommandEntry[], surface: "chat" | "code"): CommandEntry[] {
+ return catalog.filter((c) => c.source === "plugin" || DESKTOP_COMMANDS.has(c.command) || (surface === "code" && CODE_COMMANDS.has(c.command)));
+}
+
+/**
+ * A sent message's command (or skill) and the rest, so the chat can show the
+ * command as a chip: the longest known command it starts with, else its first
+ * word; a "#skill" is its first word.
+ */
+export function splitCommand(text: string, commands: readonly string[] = known): { token: string; rest: string } | null {
+ if (!/^[/#][^\s]/.test(text)) return null;
+ if (text.startsWith("/")) {
+ const hit = commands.map((k) => k.trim()).filter((k) => text === k || text.startsWith(`${k} `)).sort((a, b) => b.length - a.length)[0];
+ if (hit) return { token: hit, rest: text.slice(hit.length).trim() };
+ }
+ const [token, ...rest] = text.split(/\s+/);
+ return { token, rest: rest.join(" ") };
+}
+
/** "/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;