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.

fix(desktop): prompt cards wrap long choices; keys that work

Salman Qureshi3957c68e144c
diff --git a/apps/desktop/src/components/indicators/Approval.test.ts b/apps/desktop/src/components/indicators/Approval.test.ts
new file mode 100644
index 00000000..a3f78331
--- /dev/null
+++ b/apps/desktop/src/components/indicators/Approval.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from "vitest";
+import { denyOption, splitLabel } from "./Approval";
+
+describe("approval card", () => {
+ it("splits a skill choice into a name and a description", () => {
+ expect(splitLabel("web-search — Search the web and the news")).toEqual({ name: "web-search", detail: "Search the web and the news" });
+ expect(splitLabel("None of these — answer normally")).toEqual({ name: "None of these", detail: "answer normally" });
+ expect(splitLabel("Allow once")).toEqual({ name: "Allow once", detail: null });
+ });
+
+ it("finds the deny answer for N", () => {
+ const p = (labels: string[]) => ({ id: "x", kind: "permission" as const, text: "", raisedAt: 0, options: labels.map((l) => ({ value: l, label: l })) });
+ expect(denyOption(p(["Allow", "Always allow", "Deny"]))?.label).toBe("Deny");
+ expect(denyOption(p(["Yes", "No"]))?.label).toBe("No");
+ expect(denyOption(p(["Continue"]))).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/components/indicators/Approval.tsx b/apps/desktop/src/components/indicators/Approval.tsx
index 6c8a5afc..83af38b1 100644
--- a/apps/desktop/src/components/indicators/Approval.tsx
+++ b/apps/desktop/src/components/indicators/Approval.tsx
@@ -1,17 +1,26 @@
-import { useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { cx } from "~/lib/cx";
import type { PendingPrompt } from "~/api/types";
import { Button } from "~/components/ui/Button";
-import { Kbd } from "~/components/ui/bits";
+import { Kbd, Spinner } from "~/components/ui/bits";
/**
* "Needs you": a prompt the runtime raised and is waiting on. One card for
* all three kinds (tool permission, continue?, pick one). The amber edge is
- * the only colour; the first option is the primary action.
+ * the only colour.
+ *
+ * Short answers ("Allow", "Deny") sit in a row of buttons. Picks, and any
+ * answer too long for a button, become a list of full-width rows that wrap,
+ * "name — description" split into a bold name and a quiet line under it,
+ * so nothing ever runs off the card. Keys work when you aren't typing:
+ * Y / N for allow / deny, 1-9 to pick.
*/
-export function Approval({ prompt, onAnswer, compact }: { prompt: PendingPrompt; onAnswer: (value: string | null) => Promise<void> | void; compact?: boolean }) {
+export function Approval({ prompt, onAnswer, compact, keys = false }: { prompt: PendingPrompt; onAnswer: (value: string | null) => Promise<void> | void; compact?: boolean; keys?: boolean }) {
const [busy, setBusy] = useState<string | null>(null);
+ const busyRef = useRef(busy);
+ busyRef.current = busy;
async function answer(value: string | null) {
+ if (busyRef.current !== null) return;
setBusy(value ?? "__cancel");
try {
await onAnswer(value);
@@ -19,27 +28,107 @@ export function Approval({ prompt, onAnswer, compact }: { prompt: PendingPrompt;
setBusy(null);
}
}
+ const answerRef = useRef(answer);
+ answerRef.current = answer;
+
const title = prompt.kind === "permission" ? "Allow this?" : prompt.kind === "continue" ? "Keep going?" : "Your pick";
+ const asList = prompt.kind === "choice" || prompt.options.some((o) => o.label.length > 32);
+ const deny = denyOption(prompt);
+ const yesNo = !asList && prompt.options.length >= 2 && !!deny;
+
+ useEffect(() => {
+ if (!keys) return;
+ const onKey = (e: KeyboardEvent) => {
+ const t = e.target as HTMLElement | null;
+ if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) return;
+ if (e.metaKey || e.ctrlKey || e.altKey) return;
+ const k = e.key.toLowerCase();
+ if (asList && /^[1-9]$/.test(k)) {
+ const o = prompt.options[Number(k) - 1];
+ if (o) { e.preventDefault(); void answerRef.current(o.value); }
+ } else if (yesNo && k === "y") {
+ e.preventDefault();
+ void answerRef.current(prompt.options[0].value);
+ } else if (yesNo && k === "n" && deny) {
+ e.preventDefault();
+ void answerRef.current(deny.value);
+ }
+ };
+ window.addEventListener("keydown", onKey);
+ return () => window.removeEventListener("keydown", onKey);
+ }, [keys, asList, yesNo, deny, prompt.options]);
+
return (
- <div className={cx("rounded-lg border border-amber/40 bg-amber/[0.06] p-3", compact && "p-2.5")} role="group" aria-label={title}>
+ <div className={cx("min-w-0 max-w-full rounded-lg border border-amber/40 bg-amber/[0.06] p-3", compact && "p-2.5")} role="group" aria-label={title}>
<div className="mb-1.5 flex items-center gap-2 text-xs font-medium text-amber">
<span className="block h-1.5 w-1.5 rounded-full bg-amber" aria-hidden="true" />
{title}
</div>
- <pre className="mb-3 whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed text-ink" data-selectable>{prompt.text}</pre>
- <div className="flex flex-wrap items-center gap-1.5">
- {prompt.options.map((o, i) => (
- <Button key={o.value} size="sm" variant={i === 0 ? "primary" : "outline"} loading={busy === o.value} disabled={busy !== null} onClick={() => void answer(o.value)}>
- {o.label}
- </Button>
- ))}
- {prompt.kind === "choice" && (
- <Button size="sm" variant="ghost" loading={busy === "__cancel"} disabled={busy !== null} onClick={() => void answer(null)}>
- Cancel
- </Button>
- )}
- {!compact && <span className="ml-auto hidden items-center gap-1 text-2xs text-ink4 sm:inline-flex"><Kbd>Y</Kbd> allow <Kbd>N</Kbd> deny</span>}
- </div>
+ {prompt.kind === "permission"
+ ? <pre className="mb-3 whitespace-pre-wrap break-words font-mono text-[12.5px] leading-relaxed text-ink [overflow-wrap:anywhere]" data-selectable>{prompt.text}</pre>
+ : <p className="mb-3 whitespace-pre-wrap break-words text-sm leading-relaxed text-ink [overflow-wrap:anywhere]" data-selectable>{prompt.text}</p>}
+
+ {asList ? (
+ <>
+ <div className="flex flex-col gap-1.5" role="listbox" aria-label={title}>
+ {prompt.options.map((o, i) => {
+ const { name, detail } = splitLabel(o.label);
+ return (
+ <button
+ key={o.value}
+ role="option"
+ aria-selected={false}
+ disabled={busy !== null}
+ onClick={() => void answer(o.value)}
+ className={cx(
+ "flex w-full min-w-0 items-start gap-3 rounded-lg border px-3 py-2 text-left transition-colors disabled:opacity-60",
+ i === 0 ? "border-accent/50 bg-accent/[0.07] hover:bg-accent/[0.12]" : "border-line bg-surface hover:border-ink/25 hover:bg-ink/[0.03]",
+ )}
+ >
+ <span className="mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded border border-line bg-soft font-mono text-2xs text-ink3">
+ {busy === o.value ? <Spinner size={10} /> : i < 9 ? i + 1 : "·"}
+ </span>
+ <span className="min-w-0 flex-1">
+ <span className="block break-words text-sm font-medium text-ink [overflow-wrap:anywhere]">{name}</span>
+ {detail && <span className="mt-0.5 line-clamp-2 block break-words text-xs leading-relaxed text-ink3 [overflow-wrap:anywhere]" title={detail}>{detail}</span>}
+ </span>
+ </button>
+ );
+ })}
+ </div>
+ <div className="mt-2 flex flex-wrap items-center gap-1.5">
+ {prompt.kind === "choice" && (
+ <Button size="sm" variant="ghost" loading={busy === "__cancel"} disabled={busy !== null} onClick={() => void answer(null)}>Cancel</Button>
+ )}
+ {keys && !compact && <span className="ml-auto hidden items-center gap-1 text-2xs text-ink4 sm:inline-flex"><Kbd>1</Kbd>–<Kbd>{Math.min(9, prompt.options.length)}</Kbd> to pick</span>}
+ </div>
+ </>
+ ) : (
+ <div className="flex flex-wrap items-center gap-1.5">
+ {prompt.options.map((o, i) => (
+ <Button key={o.value} size="sm" variant={i === 0 ? "primary" : "outline"} loading={busy === o.value} disabled={busy !== null} onClick={() => void answer(o.value)}>
+ {o.label}
+ </Button>
+ ))}
+ {keys && yesNo && deny && !compact && (
+ <span className="ml-auto hidden items-center gap-1 text-2xs text-ink4 sm:inline-flex">
+ <Kbd>Y</Kbd> {prompt.options[0].label.toLowerCase()} <Kbd>N</Kbd> {deny.label.toLowerCase()}
+ </span>
+ )}
+ </div>
+ )}
</div>
);
}
+
+/** "web-search — Search the web…" → name "web-search", detail "Search the web…". */
+export function splitLabel(label: string): { name: string; detail: string | null } {
+ const m = label.match(/^(.{1,60}?)\s+[—–-]{1,2}\s+([\s\S]+)$/);
+ return m ? { name: m[1].trim(), detail: m[2].trim() } : { name: label, detail: null };
+}
+
+/** The "no" answer of a yes/no prompt: a deny-like label, else the last option. */
+export function denyOption(prompt: PendingPrompt): PendingPrompt["options"][number] | null {
+ if (prompt.options.length < 2) return null;
+ return prompt.options.find((o) => /^(deny|no|don'?t|stop|reject|decline|never)\b/i.test(o.label)) ?? prompt.options[prompt.options.length - 1];
+}
diff --git a/apps/desktop/src/views/chat/Conversation.tsx b/apps/desktop/src/views/chat/Conversation.tsx
index 2061743b..55f7d8d4 100644
--- a/apps/desktop/src/views/chat/Conversation.tsx
+++ b/apps/desktop/src/views/chat/Conversation.tsx
@@ -70,13 +70,13 @@ export function Conversation({ header, empty, composer }: { header: ReactNode; e
stickToBottom.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
if (el.scrollTop < 160 && hiddenCount > 0 && !prepend.current) loadEarlier();
}}
- className={cx("min-h-0 flex-1 overflow-y-auto", isEmpty && "flex flex-col")}
+ className={cx("min-h-0 flex-1 overflow-y-auto overflow-x-hidden", isEmpty && "flex flex-col")}
>
{/* Centred with auto margins, not justify-center: when the start screen
is taller than the window, justify-center pushes its top under the
header where it can't be scrolled to. Auto margins collapse instead. */}
{isEmpty ? <div className="m-auto flex w-full justify-center py-8">{empty}</div> : (
- <div className="mx-auto flex w-full max-w-[780px] flex-col gap-7 px-8 py-8">
+ <div className="mx-auto flex w-full min-w-0 max-w-[780px] flex-col gap-7 px-8 py-8 [&>*]:min-w-0">
{loading && messages.length === 0 && <ThinkingDots label="Loading" />}
{hiddenCount > 0 && (
<button onClick={loadEarlier} className="self-center rounded-full border border-line px-3 py-1 text-xs text-ink3 hover:text-ink">
@@ -90,9 +90,9 @@ export function Conversation({ header, empty, composer }: { header: ReactNode; e
{!streaming && !live && (agent === "thinking" || agent === "working") && (
<ThinkingDots label={stopping ? "Stopping" : agent === "working" && step?.tool ? `Running ${step.tool}` : "Thinking"} className="pl-10" />
)}
- {prompts.map((p) => (
- <div key={p.id} className="pl-10">
- <Approval prompt={p} onAnswer={(v) => answerPrompt(store, p, v)} />
+ {prompts.map((p, i) => (
+ <div key={p.id} className="min-w-0 pl-10">
+ <Approval prompt={p} onAnswer={(v) => answerPrompt(store, p, v)} keys={i === prompts.length - 1} />
</div>
))}
</div>