Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(agentic-ide): preview the composed prompt before a typed instruction is sent
Ruben Lütke6fed47e81a98
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsxindex 7895f4a3ce..c7e0ffaff3 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.test.tsx@@ -22,6 +22,7 @@ vi.mock("@/store/events", () => ({vi.mock("@/lib/agenticIdeApi", () => ({addTerminal: vi.fn(),closeTerminal: vi.fn(),+ composePrompt: vi.fn(),promptTerminal: vi.fn(),}));@@ -167,6 +168,18 @@ beforeEach(() => {]),);vi.mocked(api.closeTerminal).mockResolvedValue(sessionWith([["Nova", 0]]));+ vi.mocked(api.composePrompt).mockResolvedValue({+ composed: "## Task\nRun the tests.",+ composed_by: "llm",+ files: [],+ });+ vi.mocked(api.promptTerminal).mockResolvedValue({+ terminal: "Mika",+ sent: "## Task\nRun the tests.",+ composed_by: "raw",+ files: [],+ submitted: true,+ });});afterEach(() => {@@ -530,3 +543,68 @@ describe("restarting a dead pane", () => {expect(api.closeTerminal).not.toHaveBeenCalled();});});++describe("the prompt bar composes before it sends", () => {+ const type = (text: string) => {+ const box = screen.getByPlaceholderText(/instruction for Mika/i);+ fireEvent.change(box, { target: { value: text } });+ fireEvent.keyDown(box, { key: "Enter" });+ };++ it("shows the briefed prompt for approval instead of sending straight away", async () => {+ renderGrid();+ type("run the tests");++ await waitFor(() => expect(screen.getByTestId("prompt-preview")).toBeTruthy());+ expect(api.composePrompt).toHaveBeenCalledWith("Mika", "run the tests");+ expect(api.promptTerminal).not.toHaveBeenCalled();+ });++ it("sends the composed prompt when the user approves it", async () => {+ renderGrid();+ type("run the tests");+ await waitFor(() => expect(screen.getByTestId("prompt-preview")).toBeTruthy());++ fireEvent.click(screen.getByTestId("prompt-preview-send"));++ await waitFor(() =>+ expect(api.promptTerminal).toHaveBeenCalledWith("Mika", "## Task\nRun the tests."),+ );+ });++ it("sends the user's own wording when they prefer it", async () => {+ renderGrid();+ type("run the tests");+ await waitFor(() => expect(screen.getByTestId("prompt-preview")).toBeTruthy());++ fireEvent.click(screen.getByTestId("prompt-preview-verbatim"));++ await waitFor(() =>+ expect(api.promptTerminal).toHaveBeenCalledWith("Mika", "run the tests"),+ );+ });++ it("gives the typed text back when the preview is discarded", async () => {+ renderGrid();+ type("run the tests");+ await waitFor(() => expect(screen.getByTestId("prompt-preview")).toBeTruthy());++ fireEvent.click(screen.getByTestId("prompt-preview-cancel"));++ await waitFor(() => expect(screen.queryByTestId("prompt-preview")).toBeNull());+ expect(+ (screen.getByPlaceholderText(/instruction for Mika/i) as HTMLTextAreaElement).value,+ ).toBe("run the tests");+ expect(api.promptTerminal).not.toHaveBeenCalled();+ });++ it("still delivers the instruction when composing fails outright", async () => {+ vi.mocked(api.composePrompt).mockRejectedValue(new Error("no session"));+ renderGrid();+ type("run the tests");++ await waitFor(() =>+ expect(api.promptTerminal).toHaveBeenCalledWith("Mika", "run the tests"),+ );+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsxindex 8117bc4cb5..86387cd5fb 100644--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticGrid.tsx@@ -33,11 +33,14 @@ import {type SplitDirection,} from "./AgenticTerminal";import type { TerminalAppearance } from "./terminalThemes";-import { bandCapacityFor, paneGrid } from "./layout";+import { paneGrid, workspaceBandCapacityFor } from "./layout";+import { PromptPreview } from "./PromptPreview";import {addTerminal,closeTerminal,+ composePrompt,promptTerminal,+ type ComposedPreview,type SessionState,} from "@/lib/agenticIdeApi";@@ -144,6 +147,11 @@ export function AgenticGrid({const [statuses, setStatuses] = useState<Record<string, { status: PaneStatus; detail?: string }>>({});const [prompt, setPrompt] = useState("");const [sending, setSending] = useState(false);+ // The composed prompt waiting for the user's approval, and the wording they+ // originally typed. Both are kept so "Send verbatim" and Escape can hand the+ // original back — nothing typed here is ever lost behind the preview.+ const [preview, setPreview] = useState<ComposedPreview | null>(null);+ const [previewSource, setPreviewSource] = useState("");// Bumping a pane's token reconnects just that pane, which respawns its agent.// Keyed by call-sign so closing or splitting never disturbs the others.@@ -178,7 +186,7 @@ export function AgenticGrid({return () => observer.disconnect();}, []);- const perBand = useMemo(() => bandCapacityFor(gridWidth), [gridWidth]);+ const perBand = useMemo(() => workspaceBandCapacityFor(gridWidth), [gridWidth]);const grid = useMemo(() => paneGrid(session.terminals, perBand),[session.terminals, perBand],@@ -225,12 +233,13 @@ export function AgenticGrid({setStatuses((prev) => ({ ...prev, [name]: { status, detail } }));}, []);- const send = async () => {- const text = prompt.trim();- if (!text || !target) return;+ /** Type `text` into `target` and report honestly if it was not accepted. */+ const deliver = async (text: string) => {setSending(true);try {const result = await promptTerminal(target, text);+ setPreview(null);+ setPreviewSource("");setPrompt("");// The text is typed either way — but if the agent did not accept it, say// so instead of leaving the user to wonder why nothing happened.@@ -248,6 +257,36 @@ export function AgenticGrid({}};+ /**+ * Compose first, then ask.+ *+ * Jarvis turns a rough instruction into a briefed task with the relevant+ * files attached, which is a real improvement — but replacing someone's own+ * wording without showing them would be the wrong kind of helpful. So the+ * rewrite is offered, not imposed: send the brief, send what you typed, or+ * back out. If composition fails outright the original goes straight through+ * rather than blocking on a nicety.+ */+ const send = async () => {+ const text = prompt.trim();+ if (!text || !target) return;+ setSending(true);+ try {+ const composed = await composePrompt(target, text);+ if (composed.composed && composed.composed !== text) {+ setPreviewSource(text);+ setPreview(composed);+ return;+ }+ await deliver(text);+ } catch (e) {+ pushToast("warning", `Could not prepare the prompt: ${(e as Error).message}`);+ await deliver(text);+ } finally {+ setSending(false);+ }+ };+const project = session.project;const branchLabel = useMemo(() => (project.is_repo && project.branch ? `on ${project.branch}` : ""),@@ -490,6 +529,24 @@ export function AgenticGrid({);})}</div>+ {preview && (+ <div className="mb-2">+ <PromptPreview+ terminal={target}+ composed={preview.composed}+ files={preview.files}+ composedBy={preview.composed_by}+ onSend={() => void deliver(preview.composed)}+ onSendVerbatim={() => void deliver(previewSource)}+ onCancel={() => {+ // Give the user their own words back rather than dropping them.+ setPrompt(previewSource);+ setPreview(null);+ setPreviewSource("");+ }}+ />+ </div>+ )}<div className="flex items-end gap-2"><textareavalue={prompt}@@ -515,7 +572,7 @@ export function AgenticGrid({onClick={() => void send()}><ArrowUp className="h-4 w-4" />- Send+ {sending ? "Preparing…" : "Send"}</button></div><p className="mt-2 text-[11px] text-muted-foreground">diff --git a/jarvis/ui/web/frontend/src/components/agentic/PromptPreview.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/PromptPreview.test.tsxnew file mode 100644index 0000000000..95f3608ce8--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/PromptPreview.test.tsx@@ -0,0 +1,65 @@+import { render, screen, fireEvent } from "@testing-library/react";+import { describe, expect, it, vi } from "vitest";+import { PromptPreview } from "./PromptPreview";++const base = {+ terminal: "Mika",+ composed:+ "## Task\nReview the ranking pipeline.\n\n## Key files\n- `@jarvis/rank.py` - ranking",+ files: ["jarvis/rank.py"],+ composedBy: "llm" as const,+ onSend: () => {},+ onSendVerbatim: () => {},+ onCancel: () => {},+};++describe("PromptPreview", () => {+ it("shows the composed prompt with its line structure intact", () => {+ render(<PromptPreview {...base} />);+ const body = screen.getByTestId("prompt-preview-body");+ expect(body.textContent).toContain("## Task");+ expect(body.textContent).toContain("Review the ranking pipeline.");+ expect(body.textContent).toContain("## Key files");+ });++ it("names the terminal it would go to", () => {+ render(<PromptPreview {...base} />);+ expect(screen.getByText(/Mika/)).toBeTruthy();+ });++ it("sends the composed prompt", () => {+ const onSend = vi.fn();+ render(<PromptPreview {...base} onSend={onSend} />);+ fireEvent.click(screen.getByTestId("prompt-preview-send"));+ expect(onSend).toHaveBeenCalledTimes(1);+ });++ it("offers sending the original wording unchanged", () => {+ const onSendVerbatim = vi.fn();+ render(<PromptPreview {...base} onSendVerbatim={onSendVerbatim} />);+ fireEvent.click(screen.getByTestId("prompt-preview-verbatim"));+ expect(onSendVerbatim).toHaveBeenCalledTimes(1);+ });++ it("cancels on Escape so the typed text is never trapped", () => {+ const onCancel = vi.fn();+ render(<PromptPreview {...base} onCancel={onCancel} />);+ fireEvent.keyDown(window, { key: "Escape" });+ expect(onCancel).toHaveBeenCalledTimes(1);+ });++ it("says so when only the deterministic prompt could be built", () => {+ render(<PromptPreview {...base} composedBy="fallback" />);+ expect(screen.getByTestId("prompt-preview-note")).toBeTruthy();+ });++ it("stays quiet about provenance on the happy path", () => {+ render(<PromptPreview {...base} />);+ expect(screen.queryByTestId("prompt-preview-note")).toBeNull();+ });++ it("lists the files the prompt pulled in", () => {+ render(<PromptPreview {...base} />);+ expect(screen.getByText("jarvis/rank.py")).toBeTruthy();+ });+});diff --git a/jarvis/ui/web/frontend/src/components/agentic/PromptPreview.tsx b/jarvis/ui/web/frontend/src/components/agentic/PromptPreview.tsxnew file mode 100644index 0000000000..fbb6b87b6c--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/agentic/PromptPreview.tsx@@ -0,0 +1,125 @@+import { useEffect } from "react";+import { FileCode2, Send, Type, X } from "lucide-react";++/**+ * The composed prompt, shown for approval before it is typed into an agent.+ *+ * Jarvis rewrites a rough instruction into a briefed markdown task with the+ * relevant files attached. That is a genuine improvement for a spoken sentence,+ * where the alternative is a transcript — but someone who TYPED an instruction+ * already chose their words, and silently replacing them would be the wrong+ * kind of helpful. So the typed path composes, shows the result, and lets the+ * user pick: send the brief, send exactly what they wrote, or back out.+ *+ * Escape always cancels. The caller keeps the original text, so nothing the+ * user typed can be lost behind this.+ */+export interface PromptPreviewProps {+ /** Call-sign of the terminal this would go to. */+ terminal: string;+ /** The briefed markdown prompt. */+ composed: string;+ /** Repo-relative files the prompt references. */+ files: string[];+ /** Which layer produced it — `llm` is the full path. */+ composedBy: "llm" | "fallback" | "raw";+ onSend: () => void;+ onSendVerbatim: () => void;+ onCancel: () => void;+}++export function PromptPreview({+ terminal,+ composed,+ files,+ composedBy,+ onSend,+ onSendVerbatim,+ onCancel,+}: PromptPreviewProps) {+ useEffect(() => {+ const onKey = (event: KeyboardEvent) => {+ if (event.key === "Escape") onCancel();+ };+ window.addEventListener("keydown", onKey);+ return () => window.removeEventListener("keydown", onKey);+ }, [onCancel]);++ return (+ <div+ className="rounded-lg border border-primary/40 bg-card/80 p-3"+ data-testid="prompt-preview"+ >+ <div className="mb-2 flex items-center justify-between gap-2">+ <span className="text-xs font-medium text-muted-foreground">+ Prompt for <span className="text-foreground">{terminal}</span>+ </span>+ <button+ type="button"+ onClick={onCancel}+ className="btn-ghost h-7 w-7 p-0"+ aria-label="Discard this prompt"+ data-testid="prompt-preview-cancel"+ >+ <X className="h-3.5 w-3.5" />+ </button>+ </div>++ <pre+ className="max-h-64 overflow-y-auto whitespace-pre-wrap break-words rounded-md+ border border-border bg-background/60 px-3 py-2 font-mono text-xs+ leading-relaxed text-foreground"+ data-testid="prompt-preview-body"+ >+ {composed}+ </pre>++ {files.length > 0 && (+ <div className="mt-2 flex flex-wrap items-center gap-1.5">+ <FileCode2 className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />+ {files.map((file) => (+ <span key={file} className="chip font-mono text-[10px]">+ {file}+ </span>+ ))}+ </div>+ )}++ {/* Only ever shown when the full path did NOT run. The readback must not+ claim more than happened, and neither must this. */}+ {composedBy !== "llm" && (+ <p+ className="mt-2 text-[11px] text-muted-foreground"+ data-testid="prompt-preview-note"+ >+ Roughly prepared — no capable writing model was reachable, so this is+ the cleaned-up version of what you typed rather than a full brief.+ </p>+ )}++ <div className="mt-3 flex flex-wrap items-center gap-2">+ <button+ type="button"+ onClick={onSend}+ className="btn-primary"+ data-testid="prompt-preview-send"+ >+ <Send className="h-3.5 w-3.5" />+ Send+ </button>+ <button+ type="button"+ onClick={onSendVerbatim}+ className="btn-ghost"+ data-testid="prompt-preview-verbatim"+ >+ <Type className="h-3.5 w-3.5" />+ Send verbatim+ </button>+ <span className="ml-auto text-[11px] text-muted-foreground">+ Esc to discard+ </span>+ </div>+ </div>+ );+}diff --git a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.tsindex 89e0894291..a8746f14c6 100644--- a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts+++ b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts@@ -310,10 +310,11 @@ export interface PromptResult {* Send an instruction to one terminal.** `compose` asks the backend to rewrite a rough instruction into a briefed- * prompt with `@file` references attached. The typed prompt bar leaves it off —- * someone who typed a prompt already wrote what they meant, and silently- * rewriting it would be the wrong kind of helpful. Spoken instructions take the- * composed path.+ * prompt with `@file` references attached. The typed prompt bar sends with+ * `compose` OFF here — it composes in a separate step first (see+ * `composePrompt`) so the user approves the rewrite before it is typed into+ * their agent. Silently rewriting what someone typed would be the wrong kind+ * of helpful; showing it and asking is not.*/export async function promptTerminal(name: string,@@ -331,3 +332,44 @@ export async function promptTerminal(if (!res.ok) throw new Error(await detail(res));return (await res.json()) as PromptResult;}++export interface ComposedPreview {+ /** The briefed markdown prompt, ready to send. */+ composed: string;+ /** `llm` when a model wrote it, `fallback` when no capable model was up. */+ composed_by: "llm" | "fallback" | "raw";+ /** Repo-relative files the prompt references with `@`. */+ files: string[];+}++/**+ * Build the briefed prompt for `name` WITHOUT sending it.+ *+ * Same composition the spoken path uses, stopped one step short so the user can+ * read it. Takes as long as one model call plus reading a few files — the+ * caller should show that it is working.+ */+export async function composePrompt(+ name: string,+ prompt: string,+): Promise<ComposedPreview> {+ const res = await fetch(+ `/api/agentic-ide/terminals/${encodeURIComponent(name)}/prompt`,+ {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ prompt, compose: true, dry_run: true }),+ },+ );+ if (!res.ok) throw new Error(await detail(res));+ const data = (await res.json()) as {+ composed: string;+ composed_by: ComposedPreview["composed_by"];+ files: string[];+ };+ return {+ composed: data.composed,+ composed_by: data.composed_by,+ files: data.files ?? [],+ };+}