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): answer a bot's question — Allow once, Always allow, Deny

Salman Qureshi33e4dfebfe6c
diff --git a/apps/desktop/src/api/mercury.ts b/apps/desktop/src/api/mercury.ts
index d9a259fa..1048d911 100644
--- a/apps/desktop/src/api/mercury.ts
+++ b/apps/desktop/src/api/mercury.ts
@@ -5,7 +5,7 @@
import { http, ApiError } from "./client";
import type { SkillDraft,
- BotInboxEntry, BotManifest, BotRunRecord, BotStatus, BotTier, BotTierId, ChatMessage, ChatSettings, ChatThread, CodeStatus, HealthInfo,
+ BotApproval, BotInboxEntry, BotManifest, BotRunRecord, BotStatus, BotTier, BotTierId, ChatMessage, ChatSettings, ChatThread, CodeStatus, HealthInfo,
McpServer, ModelsResponse, CodeMode, CostReport, Deliverable, RunTranscript, PairResponse, PluginItem, ReasoningChoice, Skill, DeviceSummary,
} from "./types";
@@ -110,6 +110,8 @@ export const bots = {
inbox: (opts: { unread?: boolean; bot?: string; limit?: number } = {}) =>
http.get<{ entries: BotInboxEntry[]; unread: number }>(`/api/bots/inbox?limit=${opts.limit ?? 100}${opts.unread ? "&unread=1" : ""}${opts.bot ? `&bot=${encodeURIComponent(opts.bot)}` : ""}`),
markRead: (ids?: string[]) => http.post<{ ok: boolean; unread: number }>("/api/bots/inbox/read", ids ? { ids } : {}),
+ approvals: () => http.get<{ approvals: BotApproval[] }>("/api/bots/approvals").then((r) => r.approvals),
+ answer: (approvalId: string, answer: "yes" | "always" | "no") => http.post<{ ok: boolean }>(`/api/bots/approvals/${encodeURIComponent(approvalId)}`, { answer }),
dlq: (id: string) => http.get<{ dlq: Array<{ id: string; prompt: string; reasonCode?: string; createdAt: number }> }>(`/api/bots/${encodeURIComponent(id)}/dlq`),
replay: (id: string, jobId: string) => http.post<{ accepted: boolean }>(`/api/bots/${encodeURIComponent(id)}/replay/${encodeURIComponent(jobId)}`, {}),
};
diff --git a/apps/desktop/src/api/types.ts b/apps/desktop/src/api/types.ts
index ae023941..87f7c034 100644
--- a/apps/desktop/src/api/types.ts
+++ b/apps/desktop/src/api/types.ts
@@ -187,6 +187,18 @@ export interface BotManifest {
memory?: { scope?: "own" | "shared-read" | "none"; learn?: boolean };
}
+/** A bot waiting for your answer mid-run (GET /api/bots/approvals). */
+export interface BotApproval {
+ id: string;
+ botId: string;
+ botName: string;
+ runId: string;
+ /** "Run command: …", "Write to file: …", "Read file: …" */
+ prompt: string;
+ at: number;
+ expiresAt: number;
+}
+
/** One thing a bot did for you (GET /api/bots/inbox). */
export interface BotInboxEntry {
id: string;
@@ -199,6 +211,8 @@ export interface BotInboxEntry {
files: string[];
complete?: boolean;
reasonCode?: string;
+ /** A question that may still be waiting for your answer. */
+ approvalId?: string;
at: number;
read: boolean;
}
diff --git a/apps/desktop/src/app/events.ts b/apps/desktop/src/app/events.ts
index cc63cd94..106546fb 100644
--- a/apps/desktop/src/app/events.ts
+++ b/apps/desktop/src/app/events.ts
@@ -32,6 +32,11 @@ export function useRuntimeEvents(enabled: boolean): void {
if (r?.bots) useBots.getState().setBots(r.bots, true);
return;
}
+ if (event === "bot_approval") {
+ // A bot asked, or its question was answered or timed out.
+ void refreshApprovals();
+ return;
+ }
if (event === "bot_inbox") {
// A result, a reported failure, or a run that needs you.
const entry = safeJson<BotInboxEntry>(raw);
@@ -255,7 +260,14 @@ export async function setThreadSaved(threadId: string, saved: boolean): Promise<
}
}
+export async function refreshApprovals(): Promise<void> {
+ try {
+ useBots.getState().setApprovals(await api.bots.approvals());
+ } catch { /* an older runtime has no approvals */ }
+}
+
export async function refreshBots(): Promise<void> {
+ void refreshApprovals();
try {
const { bots, available, unread } = await api.bots.list();
useBots.getState().setBots(bots, available, unread);
diff --git a/apps/desktop/src/app/store.ts b/apps/desktop/src/app/store.ts
index 2938e8cb..e42bc799 100644
--- a/apps/desktop/src/app/store.ts
+++ b/apps/desktop/src/app/store.ts
@@ -5,7 +5,7 @@
═══════════════════════════════════════════════════════════════ */
import { create } from "zustand";
-import type { BotStatus, ChatThread, PendingPrompt } from "~/api/types";
+import type { BotStatus, ChatThread, PendingPrompt, BotApproval } from "~/api/types";
export type View = "chat" | "artifacts" | "code" | "bots" | "brain" | "plugins" | "skills" | "settings";
@@ -109,6 +109,9 @@ interface BotsState {
unread: number;
/** Bumped when an inbox entry arrives, so open lists reload. */
inboxVersion: number;
+ /** Bots waiting for your answer right now. */
+ approvals: BotApproval[];
+ setApprovals(approvals: BotApproval[]): void;
setBots(bots: BotStatus[], available: boolean, unread?: number): void;
inboxChanged(unread?: number): void;
setActivity(botId: string, label: string | null): void;
@@ -120,6 +123,8 @@ export const useBots = create<BotsState>((set) => ({
activity: {},
unread: 0,
inboxVersion: 0,
+ approvals: [],
+ setApprovals: (approvals) => set({ approvals }),
setBots: (bots, available, unread) => set(unread === undefined ? { bots, available } : { bots, available, unread }),
inboxChanged: (unread) => set((s) => ({ inboxVersion: s.inboxVersion + 1, ...(unread === undefined ? {} : { unread }) })),
setActivity: (botId, label) => set((s) => {
diff --git a/apps/desktop/src/layout/Rail.tsx b/apps/desktop/src/layout/Rail.tsx
index adc43cb3..e8477580 100644
--- a/apps/desktop/src/layout/Rail.tsx
+++ b/apps/desktop/src/layout/Rail.tsx
@@ -34,7 +34,7 @@ export function Rail({ connectionName }: { connectionName: string }) {
const codeIds = useCodeSessions((s) => s.sessions);
const threads = useChat((s) => s.threads);
// Bots: amber when one needs you, blue when the inbox has something unread.
- const botsWaiting = useBots((s) => s.bots.filter((b) => b.needsYou).length);
+ const botsWaiting = useBots((s) => s.bots.filter((b) => b.needsYou).length + s.approvals.length);
const botsUnread = useBots((s) => s.unread);
// Count only conversations that are in that list, so every dot here has a dot to find there.
const dots = useMemo(() => {
diff --git a/apps/desktop/src/views/bots/Approvals.tsx b/apps/desktop/src/views/bots/Approvals.tsx
new file mode 100644
index 00000000..824c131d
--- /dev/null
+++ b/apps/desktop/src/views/bots/Approvals.tsx
@@ -0,0 +1,63 @@
+import { KeyRound } from "lucide-react";
+import { useEffect, useState } from "react";
+import * as api from "~/api/mercury";
+import type { BotApproval } from "~/api/types";
+import { refreshApprovals } from "~/app/events";
+import { useBots } from "~/app/store";
+import { Button } from "~/components/ui/Button";
+
+/**
+ * A bot asking you mid-run: what it wants to do, how long it will wait, and
+ * three answers. Allow once covers this run; Always allow is remembered in
+ * that bot's own permissions; no answer in time is a no.
+ */
+export function ApprovalCard({ a }: { a: BotApproval }) {
+ const [busy, setBusy] = useState<string | null>(null);
+ const [problem, setProblem] = useState<string | null>(null);
+ const [now, setNow] = useState(Date.now());
+ useEffect(() => { const t = setInterval(() => setNow(Date.now()), 15_000); return () => clearInterval(t); }, []);
+ const minutes = Math.max(0, Math.ceil((a.expiresAt - now) / 60_000));
+ const [what, ...rest] = a.prompt.split(": ");
+ const detail = rest.join(": ");
+
+ async function answer(v: "yes" | "always" | "no") {
+ setBusy(v);
+ setProblem(null);
+ try {
+ await api.bots.answer(a.id, v);
+ } catch (e) {
+ setProblem(e instanceof Error ? e.message : String(e));
+ } finally {
+ setBusy(null);
+ void refreshApprovals();
+ }
+ }
+
+ return (
+ <div className="flex flex-col gap-2.5 rounded-xl border border-amber/50 bg-amber/[0.05] p-4">
+ <div className="flex items-start gap-2.5">
+ <KeyRound size={16} className="mt-0.5 shrink-0 text-amber" aria-hidden="true" />
+ <div className="min-w-0 flex-1">
+ <div className="text-sm font-medium text-ink">{a.botName} asks to {what.toLowerCase()}</div>
+ {detail && <code className="mt-1 block break-all rounded-md bg-ink/[0.06] px-2 py-1 font-mono text-xs text-ink" data-selectable>{detail}</code>}
+ <p className="mt-1 text-xs text-ink3">It's waiting. {minutes > 0 ? `Without an answer in ${minutes} min, it's refused.` : "It's about to be refused."}</p>
+ </div>
+ </div>
+ <div className="flex flex-wrap items-center gap-2 pl-[26px]">
+ <Button size="sm" variant="primary" loading={busy === "yes"} disabled={!!busy} onClick={() => void answer("yes")}>Allow once</Button>
+ <Button size="sm" variant="outline" loading={busy === "always"} disabled={!!busy} onClick={() => void answer("always")}>Always allow for {a.botName}</Button>
+ <Button size="sm" variant="ghost" loading={busy === "no"} disabled={!!busy} onClick={() => void answer("no")}>Deny</Button>
+ {problem && <span className="text-xs text-red">{problem}</span>}
+ </div>
+ </div>
+ );
+}
+
+/** Every question waiting right now (for one bot, or all of them). */
+export function PendingApprovals({ botId }: { botId?: string }) {
+ const approvals = useBots((s) => s.approvals);
+ useEffect(() => { void refreshApprovals(); }, []);
+ const mine = approvals.filter((a) => !botId || a.botId === botId);
+ if (mine.length === 0) return null;
+ return <div className="flex flex-col gap-2">{mine.map((a) => <ApprovalCard key={a.id} a={a} />)}</div>;
+}
diff --git a/apps/desktop/src/views/bots/BotsView.tsx b/apps/desktop/src/views/bots/BotsView.tsx
index 74eef051..bf9c627f 100644
--- a/apps/desktop/src/views/bots/BotsView.tsx
+++ b/apps/desktop/src/views/bots/BotsView.tsx
@@ -18,6 +18,7 @@ import { Deliverables } from "./Deliverables";
import { Activity } from "./Activity";
import { Usage } from "./Usage";
import { BotInbox, InboxRow } from "./Inbox";
+import { PendingApprovals } from "./Approvals";
import { CreateBot } from "./CreateBot";
import { BotSettings } from "./BotSettings";
import { describeCron } from "./BotForms";
@@ -60,6 +61,7 @@ export function BotsView() {
const available = useBots((s) => s.available);
const activity = useBots((s) => s.activity);
const unread = useBots((s) => s.unread);
+ const waiting = useBots((s) => s.approvals.length);
const focus = useUi((s) => s.botFocus);
// "inbox", "new", or a bot id.
const [selected, setSelected] = useState<string | null>(null);
@@ -92,7 +94,7 @@ export function BotsView() {
</span>
</header>
<div className="min-h-0 flex-1 overflow-y-auto px-2 pb-4">
- <InboxRow active={selected === "inbox"} unread={unread} onClick={() => setSelected("inbox")} />
+ <InboxRow active={selected === "inbox"} unread={unread} waiting={waiting} onClick={() => setSelected("inbox")} />
{bots.length === 0 && <p className="px-2 pt-1 text-sm text-ink4">No bots yet. Press New bot to make one.</p>}
{fleets.map((f) => {
@@ -145,6 +147,7 @@ export function BotsView() {
<h1 className="text-xl font-semibold tracking-tight text-ink">Inbox</h1>
<p className="mt-0.5 text-sm text-ink3">What your bots did, newest first. Runs with nothing new stay quiet; every run is in a bot's Activity.</p>
</div>
+ <PendingApprovals />
<BotInbox bots={bots} onOpenBot={setSelected} />
</div>
) : selectedFleet ? (
@@ -230,6 +233,7 @@ function FleetDetail({ fleet, activity, onSelect }: { fleet: Fleet; activity: Re
return (
<div className="mx-auto flex max-w-[1000px] flex-col gap-6 px-8 py-7">
<BotHeader id={lead.id} status={lead} subtitle={`Fleet lead · ${crew.length} crew`} crewCount={crew.length} onDeleted={() => onSelect(null)} />
+ {members.map((m) => <PendingApprovals key={m.id} botId={m.id} />)}
<TabBar tab={tab} onChange={setTab} fleet />
{tab === "overview" && (
<>
@@ -270,6 +274,7 @@ function BotDetail({ id, status, onDeleted }: { id: string; status: BotStatus |
return (
<div className="mx-auto flex max-w-[1000px] flex-col gap-6 px-8 py-7">
<BotHeader id={id} status={status} onDeleted={onDeleted} />
+ <PendingApprovals botId={id} />
<TabBar tab={tab} onChange={setTab} fleet={false} />
{tab === "overview" && <BotBody id={id} status={status} />}
{tab === "results" && <BotInbox bots={status ? [status] : []} botId={id} />}
diff --git a/apps/desktop/src/views/bots/Inbox.tsx b/apps/desktop/src/views/bots/Inbox.tsx
index 90f5fc35..6ed685f6 100644
--- a/apps/desktop/src/views/bots/Inbox.tsx
+++ b/apps/desktop/src/views/bots/Inbox.tsx
@@ -120,11 +120,12 @@ function KindIcon({ kind }: { kind: BotInboxEntry["kind"] }) {
}
/** The inbox entry in the sidebar: an icon, "Inbox", and the unread count. */
-export function InboxRow({ active, unread, onClick }: { active: boolean; unread: number; onClick: () => void }) {
+export function InboxRow({ active, unread, waiting = 0, onClick }: { active: boolean; unread: number; waiting?: number; onClick: () => void }) {
return (
<button onClick={onClick} className={cx("mb-2 flex w-full items-center gap-2.5 rounded-lg px-2.5 py-2 text-left", active ? "bg-ink/[0.07]" : "hover:bg-ink/[0.05]")}>
<span className="flex h-8 w-8 items-center justify-center rounded-full bg-ink/[0.06]"><InboxIcon size={15} className="text-ink2" /></span>
<span className="flex-1 text-sm font-medium text-ink">Inbox</span>
+ {waiting > 0 && <span className="rounded-full bg-amber px-1.5 text-2xs font-semibold leading-5 text-black" aria-label={`${waiting} waiting for your answer`}>{waiting} asking</span>}
{unread > 0 && <span className="rounded-full bg-accent px-1.5 text-2xs font-semibold leading-5 text-on-accent">{unread}</span>}
</button>
);