Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

feat: show queued messages, restyle like gentlemanprogramming.com, clear icons, and stop cleanly when switching conversations

Alan Buscagliab0ee7ac042c5
diff --git a/biome.json b/biome.json
index ac739b3..6dc5b67 100644
--- a/biome.json
+++ b/biome.json
@@ -8,7 +8,9 @@
"!apps/desktop/src-tauri/target",
"!apps/desktop/src-tauri/gen",
"!odd",
- "!docs"
+ "!docs",
+ "!test-results",
+ "!playwright-report"
]
},
"formatter": {
diff --git a/e2e/web.spec.ts b/e2e/web.spec.ts
index 96685ae..5925766 100644
--- a/e2e/web.spec.ts
+++ b/e2e/web.spec.ts
@@ -68,6 +68,68 @@ test("offers to continue after the assistant was interrupted", async ({ page })
await expect(page.getByText("I was interrupted. Continue?")).toBeHidden();
});
+test("shows a message sent while the assistant works as queued, then delivers it", async ({ page }) => {
+ await open(page);
+ await page.getByRole("button", { name: "New conversation" }).click();
+ await expect(page.getByText("Hi! What can I do for you?")).toBeVisible();
+ await say(page, "slow");
+ await expect(page.getByRole("button", { name: "Stop" })).toBeVisible();
+ await say(page, "queued one");
+ const queued = page.getByRole("article", { name: "Queued message" });
+ await expect(queued).toHaveCount(1);
+ await expect(queued).toContainText("Queued");
+ await expect(queued.locator(".message-body")).toHaveText("queued one");
+ await expect(page.locator(".message-assistant").last()).toHaveText("Echo: queued one", { timeout: 10_000 });
+ await expect(queued).toHaveCount(0);
+ await expect(page.locator(".message-user")).toHaveText(["slow", "queued one"]);
+ await expect(page.locator(".message-assistant")).toHaveText(["Echo: slow", "Echo: queued one"]);
+});
+
+test("asks before leaving a running answer, then opens the other conversation with no error", async ({
+ page,
+}) => {
+ await open(page);
+ await page.getByRole("button", { name: "New conversation" }).click();
+ await expect(page.getByText("Hi! What can I do for you?")).toBeVisible();
+ await say(page, "first chat");
+ await expect(page.locator(".message-assistant").last()).toHaveText("Echo: first chat");
+ await page.getByRole("button", { name: "New conversation" }).click();
+ await expect(page.getByText("Hi! What can I do for you?")).toBeVisible();
+ await say(page, "hang");
+ await expect(page.getByRole("button", { name: "Stop" })).toBeVisible();
+
+ await page.getByRole("button", { name: "Conversations" }).click();
+ await page
+ .getByRole("navigation", { name: "Earlier conversations" })
+ .getByRole("button", { name: /first chat/ })
+ .click();
+ const dialog = page.getByRole("alertdialog", { name: "Stop and switch?" });
+ await expect(dialog).toContainText(
+ "The assistant is still answering. Stop it and open the other conversation?",
+ );
+ await dialog.getByRole("button", { name: "Stop and switch" }).click();
+
+ await expect(page.getByRole("heading", { level: 1 })).toHaveText("first chat");
+ await expect(page.locator(".message-user")).toHaveText(["first chat"]);
+ await expect(page.locator(".message-assistant")).toHaveText(["Echo: first chat"]);
+ await expect(page.getByRole("button", { name: "Stop" })).toBeHidden();
+ await expect(dialog).toBeHidden();
+ await expect(page.locator(".notice")).toHaveCount(0);
+ await expect(page.locator(".message-note-error")).toHaveCount(0);
+});
+
+test("closes open options when the user starts typing, with titled header icons", async ({ page }) => {
+ await open(page);
+ for (const name of ["Conversations", "Accounts", "Profiles", "New conversation"]) {
+ await expect(page.getByRole("button", { name })).toHaveAttribute("title", name);
+ }
+ await page.getByRole("button", { name: "Profiles" }).click();
+ await expect(page.getByRole("region", { name: "Profiles" })).toBeVisible();
+ await page.getByRole("textbox", { name: "Message" }).pressSequentially("h");
+ await expect(page.getByRole("region", { name: "Profiles" })).toBeHidden();
+ await expect(page.getByRole("textbox", { name: "Message" })).toHaveValue("h");
+});
+
test("keeps the conversation after a page reload", async ({ page }) => {
await open(page);
await say(page, "remember this");
diff --git a/packages/daemon/src/bridge.ts b/packages/daemon/src/bridge.ts
index b47403f..d871d30 100644
--- a/packages/daemon/src/bridge.ts
+++ b/packages/daemon/src/bridge.ts
@@ -4,6 +4,8 @@ import {
type Ask,
type ClientMessage,
isThinkingLevel,
+ type MessageQueue,
+ parseQueue,
type RoleRoute,
type ServerPayload,
} from "@gentle-dot/protocol";
@@ -34,6 +36,8 @@ export interface BridgeOptions {
log?: (line: string) => void;
auth?: AuthManager;
profiles?: ProfileStore;
+ /** How long switching conversations waits for a running answer to stop. Default 10 s. */
+ stopTimeoutMs?: number;
}
type ProfileCommand = Extract<
@@ -55,6 +59,8 @@ const DIALOG_METHODS = new Set(["select", "confirm", "input", "editor"]);
/** An open dialog; `options` keeps the agent's original option strings for the answer. */
type PendingAsk = { ask: Ask; options?: string[]; timer?: NodeJS.Timeout };
const REMEMBERED_REQUEST_IDS = 500;
+const READY_TIMEOUT_MS = 60_000;
+const ANSWER_FAILED = "Something went wrong while answering. Please try again.";
/**
* Translates between protocol v1 clients and the supervised agent: it keeps
@@ -74,6 +80,12 @@ export class DotBridge {
private nextMessage = 0;
private assistantId: string | undefined;
private restartPending = false;
+ /** The running answer is being stopped on purpose, so its end is not an error. */
+ private stopRequested = false;
+ /** The conversation switch in progress; messages sent meanwhile wait for it. */
+ private switching: Promise<void> = Promise.resolve();
+ /** Messages waiting for the agent, as shown to the user. */
+ private queue: MessageQueue = { steering: [], followUp: [] };
private readonly liveSwitch: LiveModelSwitch;
constructor(supervisor: AgentSupervisor, options: BridgeOptions) {
@@ -98,6 +110,7 @@ export class DotBridge {
...this.conversationRef(),
...(this.supervisor.model ? { model: this.supervisor.model } : {}),
});
+ if (this.queued()) this.deliver(client, { type: "queue", ...this.queue });
for (const { ask } of this.asks.values()) this.deliver(client, { type: "ask", ask });
if (this.interrupted) this.deliver(client, { type: "interrupted" });
return () => {
@@ -161,6 +174,7 @@ export class DotBridge {
await this.sendProfiles(client, true);
return;
}
+ await this.switching;
this.interrupted = false;
const busy = this.supervisor.busy;
await this.supervisor.request(
@@ -174,6 +188,7 @@ export class DotBridge {
await this.supervisor.request({ type: "steer", message: message.text });
return;
case "abort":
+ if (this.supervisor.busy) this.stopRequested = true;
await this.supervisor.request({ type: "abort" });
return;
case "ui_response": {
@@ -200,8 +215,10 @@ export class DotBridge {
return;
}
case "new_conversation":
- await this.supervisor.request({ type: "new_session" });
- this.afterConversationChange([]);
+ await this.changeConversation(async () => {
+ await this.switchAfterStop(() => this.supervisor.request({ type: "new_session" }));
+ this.afterConversationChange([]);
+ });
return;
case "list_conversations":
this.deliver(client, this.conversationsPayload());
@@ -216,8 +233,12 @@ export class DotBridge {
});
return;
}
- await this.supervisor.request({ type: "switch_session", sessionPath: path });
- this.afterConversationChange(await this.loadHistory());
+ await this.changeConversation(async () => {
+ await this.switchAfterStop(() =>
+ this.supervisor.request({ type: "switch_session", sessionPath: path }),
+ );
+ this.afterConversationChange(await this.loadHistory());
+ });
return;
}
case "auth_list":
@@ -257,15 +278,81 @@ export class DotBridge {
await this.profileCommand(client, message);
return;
case "get_history":
+ // Windows ask for history as soon as they connect, often while the agent starts.
+ await this.whenReady();
this.deliver(client, {
type: "history",
...this.conversationRef(),
- messages: historyFromMessages(await this.loadHistory()),
+ messages: historyFromMessages(await this.currentHistory()),
});
return;
}
}
+ /** Runs a conversation switch; a message sent meanwhile goes to the new conversation, after its history. */
+ private changeConversation(change: () => Promise<void>): Promise<void> {
+ const run = change();
+ this.switching = run.catch(() => {});
+ return run;
+ }
+
+ /**
+ * The engine aborts a running answer when it switches sessions, and its end
+ * would land in the new conversation. Stop it first and wait (bounded) for
+ * the run to settle, then switch; that stop is intentional, not an error.
+ */
+ private async switchAfterStop(switchTo: () => Promise<unknown>): Promise<void> {
+ if (!this.supervisor.busy) {
+ await switchTo();
+ return;
+ }
+ this.stopRequested = true;
+ try {
+ const settled = this.nextSettle(this.options.stopTimeoutMs ?? 10_000);
+ await this.supervisor.request({ type: "abort" });
+ if (!(await settled)) this.log("the running answer did not stop in time; switching anyway");
+ await switchTo();
+ } finally {
+ this.stopRequested = false;
+ }
+ }
+
+ /** Resolves true when the run settles or the agent goes away, false after `timeoutMs`. */
+ private nextSettle(timeoutMs: number): Promise<boolean> {
+ return new Promise((resolve) => {
+ const finish = (settled: boolean) => {
+ clearTimeout(timer);
+ off();
+ resolve(settled);
+ };
+ const timer = setTimeout(() => finish(false), timeoutMs);
+ const off = this.supervisor.onEvent((event) => {
+ if (event.type === "agent_settled") finish(true);
+ else if (event.type === "supervisor_state" && event.state !== "ready") finish(true);
+ });
+ });
+ }
+
+ /** Waits until the agent can take commands; gives up after a minute or when it stopped. */
+ private whenReady(): Promise<void> {
+ if (this.supervisor.state === "ready") return Promise.resolve();
+ return new Promise((resolve, reject) => {
+ const finish = (error?: Error) => {
+ clearTimeout(timer);
+ off();
+ if (error) reject(error);
+ else resolve();
+ };
+ const timer = setTimeout(() => finish(new Error("the agent did not start in time")), READY_TIMEOUT_MS);
+ timer.unref();
+ const off = this.supervisor.onEvent((event) => {
+ if (event.type !== "supervisor_state") return;
+ if (event.state === "ready") finish();
+ else if (event.state === "stopped") finish(new Error("the agent stopped"));
+ });
+ });
+ }
+
private requireAuth(): AuthManager {
if (!this.options.auth) throw new Error("sign-in is not available");
return this.options.auth;
@@ -401,6 +488,18 @@ export class DotBridge {
this.broadcast(this.conversationsPayload());
}
+ /**
+ * History replaces what a window shows, so it must not be older than the
+ * messages already sent: read it again when one arrived while loading.
+ */
+ private async currentHistory(): Promise<unknown[]> {
+ for (let attempt = 0; ; attempt++) {
+ const seen = this.nextMessage;
+ const messages = await this.loadHistory();
+ if (this.nextMessage === seen || attempt >= 2) return messages;
+ }
+ }
+
private async loadHistory(): Promise<unknown[]> {
const response = await this.supervisor.request({ type: "get_messages" });
return (response.data as { messages?: unknown[] } | undefined)?.messages ?? [];
@@ -423,8 +522,11 @@ export class DotBridge {
private onAgentEvent(event: SupervisorEvent): void {
switch (event.type) {
case "supervisor_state":
- if (event.state !== "ready") this.clearRun();
- else this.settleModelSwitch();
+ if (event.state !== "ready") {
+ this.stopRequested = false;
+ this.clearRun();
+ this.clearQueue();
+ } else this.settleModelSwitch();
break;
case "interrupted":
this.interrupted = true;
@@ -443,9 +545,15 @@ export class DotBridge {
case "tool_execution_end":
this.onTool(event);
break;
+ case "queue_update":
+ this.onQueueUpdate(event);
+ break;
case "agent_settled":
this.runningTools.clear();
this.assistantId = undefined;
+ this.stopRequested = false;
+ // Anything still queued will not be taken by this run.
+ this.clearQueue();
// The title of a new conversation comes from its first message.
this.broadcast(this.conversationsPayload());
this.settleModelSwitch();
@@ -458,6 +566,24 @@ export class DotBridge {
this.refreshState();
}
+ /** The engine sends both complete queues on every change. */
+ private onQueueUpdate(event: AgentRecord): void {
+ const queue = parseQueue(event);
+ if (!queue) return;
+ this.queue = { steering: queue.steering.map(presentText), followUp: queue.followUp.map(presentText) };
+ this.broadcast({ type: "queue", ...this.queue });
+ }
+
+ private queued(): boolean {
+ return this.queue.steering.length > 0 || this.queue.followUp.length > 0;
+ }
+
+ private clearQueue(): void {
+ if (!this.queued()) return;
+ this.queue = { steering: [], followUp: [] };
+ this.broadcast({ type: "queue", ...this.queue });
+ }
+
private onMessageStart(event: AgentRecord): void {
const message = event.message as { role?: string } | undefined;
if (message?.role === "user") {
@@ -479,10 +605,15 @@ export class DotBridge {
| undefined;
if (message?.role !== "assistant") return;
const messageId = this.assistantId ?? `m${++this.nextMessage}`;
- this.broadcast({ type: "message_done", messageId, text: presentText(textOf(message)) });
- if (message.stopReason === "error") {
+ const text = presentText(textOf(message));
+ // The engine ends a stopped answer as "aborted", or as an error when a session switch tore it down.
+ if (message.stopReason === "aborted" || (message.stopReason === "error" && this.stopRequested)) {
+ this.broadcast({ type: "message_done", messageId, text, stopped: true });
+ } else if (message.stopReason === "error") {
this.log(`assistant error: ${message.errorMessage ?? "unknown"}`);
- this.broadcast({ type: "toast", level: "error", message: "Something went wrong while answering." });
+ this.broadcast({ type: "message_done", messageId, text, error: ANSWER_FAILED });
+ } else {
+ this.broadcast({ type: "message_done", messageId, text });
}
}
diff --git a/packages/daemon/test/bridge-stop.test.ts b/packages/daemon/test/bridge-stop.test.ts
new file mode 100644
index 0000000..aac47fa
--- /dev/null
+++ b/packages/daemon/test/bridge-stop.test.ts
@@ -0,0 +1,50 @@
+import type { ServerPayload } from "@gentle-dot/protocol";
+import { afterEach, describe, expect, it } from "vitest";
+import { DotBridge } from "../src/bridge.ts";
+import type { AgentSupervisor } from "../src/supervisor.ts";
+import { fakeSupervisor, waitFor } from "./helpers.ts";
+
+const supervisors: AgentSupervisor[] = [];
+afterEach(async () => {
+ await Promise.all(supervisors.splice(0).map((s) => s.stop()));
+});
+
+async function setup(env: NodeJS.ProcessEnv) {
+ const { supervisor, dataDir } = fakeSupervisor({ env: { ...process.env, ...env } });
+ supervisors.push(supervisor);
+ const logs: string[] = [];
+ const bridge = new DotBridge(supervisor, { dataDir, log: (line) => logs.push(line), stopTimeoutMs: 300 });
+ const received: ServerPayload[] = [];
+ const client = { send: (payload: ServerPayload) => received.push(payload) };
+ bridge.attach(client);
+ await supervisor.start();
+ return { bridge, client, received, logs };
+}
+
+describe("stopping before a switch", () => {
+ it("still switches after a bounded wait when the agent ignores the stop, and clears the stop mark", async () => {
+ const { bridge, client, received, logs } = await setup({ FAKE_AGENT_IGNORE_ABORT: "1" });
+ await bridge.handle(client, { type: "send", text: "hang" });
+ await waitFor(() => bridge.agentState === "thinking");
+ const started = Date.now();
+ await bridge.handle(client, { type: "new_conversation" });
+ expect(Date.now() - started).toBeLessThan(3000);
+ expect(logs.some((line) => line.includes("did not stop"))).toBe(true);
+ const history = received.findIndex((p) => p.type === "history");
+ const stopped = received.findIndex((p) => p.type === "message_done" && p.stopped === true);
+ expect(stopped).toBeGreaterThanOrEqual(0);
+ expect(stopped).toBeLessThan(history);
+ expect(received.filter((p) => p.type === "error" || p.type === "toast")).toEqual([]);
+ await waitFor(() => bridge.agentState === "idle");
+
+ // The mark is gone: a real failure afterwards is an error, not a stop.
+ await bridge.handle(client, { type: "send", text: "fail" });
+ const failed = await waitFor(() =>
+ received.find(
+ (p): p is Extract<ServerPayload, { type: "message_done" }> =>
+ p.type === "message_done" && p.error !== undefined,
+ ),
+ );
+ expect(failed.stopped).toBeUndefined();
+ });
+});
diff --git a/packages/daemon/test/fixtures/fake-agent.ts b/packages/daemon/test/fixtures/fake-agent.ts
index 561a994..ff60d98 100644
--- a/packages/daemon/test/fixtures/fake-agent.ts
+++ b/packages/daemon/test/fixtures/fake-agent.ts
@@ -5,16 +5,25 @@
// "tool:<name>" runs one fake tool call
// "ask:select" asks a select dialog and echoes the answer
// "ask:confirm" asks a confirm dialog and echoes the answer
-// "hang" starts a run that only ends on abort
+// "hang" starts a run that only ends on abort (an aborted answer), or on a
+// session switch (Pi then ends it with an error: "This operation was aborted")
+// "fail" the provider fails: an answer that ends with stopReason "error"
+// "slow" answers after 1.5 s, leaving time to queue messages
// "crash" starts a run and exits with code 1
// "burst" answers and finishes the run in a single stdout write
// The "noreply" command is never answered.
+// A prompt sent while busy (with streamingBehavior), steer, and follow_up are
+// queued like Pi does: a queue_update with both complete queues, then each one
+// is taken when the run would end (queue_update, user message_start, echo).
// Environment:
// FAKE_AGENT_ARGS_FILE write argv as JSON to this file
// FAKE_AGENT_BRANDING emit branded startup UI records
// FAKE_AGENT_ENV_FILE write selected environment variables as JSON to this file
// FAKE_AGENT_COMMANDS_FILE append every model command (set_model, set_thinking_level) as JSONL
// FAKE_AGENT_NO_MODEL refuse every prompt, like an engine with no signed-in account
+// FAKE_AGENT_DROP_QUEUE settle without taking or reporting queued messages
+// FAKE_AGENT_IGNORE_ABORT answer abort but keep running (a session switch still ends the run)
+// FAKE_AGENT_START_DELAY_MS answer the first get_state only after this delay
// get_available_models lists MODELS; set_model and set_thinking_level change what
// get_state reports, so tests can read the last values back.
import { randomUUID } from "node:crypto";
@@ -73,7 +82,11 @@ let sessionId = "";
let sessionFile = "";
let messages: Message[] = [];
let busy = false;
-let hanging: (() => void) | undefined;
+let hanging: ((stopReason: "aborted" | "error") => void) | undefined;
+/** Resolves when the current run has ended. */
+let runEnded: Promise<void> = Promise.resolve();
+let started = false;
+const queue = { steering: [] as string[], followUp: [] as string[] };
/** Records collected for one stdout write while a "burst" prompt runs. */
let batch: string[] | undefined;
const pendingUi = new Map<string, (rec: Rec) => void>();
@@ -147,27 +160,81 @@ function assistantText(text: string): void {
remember({ role: "assistant", content: text });
}
+function emitQueue(): void {
+ out({ type: "queue_update", steering: [...queue.steering], followUp: [...queue.followUp] });
+}
+
+function enqueue(text: string, behavior: unknown): void {
+ (behavior === "followUp" ? queue.followUp : queue.steering).push(text);
+ emitQueue();
+}
+
+function userMessage(text: string): void {
+ remember({ role: "user", content: text });
+ out({ type: "message_start", message: { role: "user", content: text } });
+ out({ type: "message_end", message: { role: "user", content: text } });
+}
+
function endRun(): void {
+ if (process.env.FAKE_AGENT_DROP_QUEUE) {
+ queue.steering = [];
+ queue.followUp = [];
+ }
+ const next = queue.steering.shift() ?? queue.followUp.shift();
+ if (next !== undefined) {
+ // Pi removes the message from the queue before it starts the user message.
+ emitQueue();
+ userMessage(next);
+ assistantText(`Echo: ${next}`);
+ endRun();
+ return;
+ }
out({ type: "agent_end", messages: [], willRetry: false });
busy = false;
out({ type: "agent_settled" });
}
+function endedAnswer(stopReason: "aborted" | "error", errorMessage: string): void {
+ const message = { role: "assistant", content: [], stopReason, errorMessage };
+ out({ type: "message_start", message });
+ out({ type: "message_end", message });
+}
+
async function run(text: string) {
busy = true;
- remember({ role: "user", content: text });
+ let ended: () => void = () => {};
+ runEnded = new Promise((resolve) => {
+ ended = resolve;
+ });
+ try {
+ await runPrompt(text);
+ } finally {
+ ended();
+ }
+}
+
+async function runPrompt(text: string) {
out({ type: "agent_start" });
- out({ type: "message_start", message: { role: "user", content: text } });
- out({ type: "message_end", message: { role: "user", content: text } });
+ userMessage(text);
if (text === "crash") {
// Give the pipe time to flush; macOS pipes are asynchronous.
setTimeout(() => process.exit(1), 50);
return;
}
if (text === "hang") {
- await new Promise<void>((resolve) => {
+ const stopReason = await new Promise<"aborted" | "error">((resolve) => {
hanging = resolve;
});
+ endedAnswer(stopReason, "This operation was aborted");
+ return endRun();
+ }
+ if (text === "fail") {
+ endedAnswer("error", "Gentle Shell provider exploded: 500 Internal Server Error");
+ return endRun();
+ }
+ if (text === "slow") {
+ await new Promise((resolve) => setTimeout(resolve, 1500));
+ assistantText("Echo: slow");
return endRun();
}
if (text.startsWith("tool:")) {
@@ -199,7 +266,14 @@ async function run(text: string) {
function handle(rec: Rec) {
const { id, type } = rec;
switch (type) {
- case "get_state":
+ case "get_state": {
+ const delay = Number(process.env.FAKE_AGENT_START_DELAY_MS ?? 0);
+ if (!started && delay > 0) {
+ started = true;
+ setTimeout(() => handle(rec), delay);
+ return;
+ }
+ started = true;
return respond(id, "get_state", {
model: { id: model.id, name: model.name, provider: model.provider },
thinkingLevel,
@@ -208,6 +282,7 @@ function handle(rec: Rec) {
sessionId,
messageCount: messages.length,
});
+ }
case "get_messages":
return respond(id, "get_messages", {
messages: messages.map((m) =>
@@ -220,7 +295,10 @@ function handle(rec: Rec) {
return respond(id, "get_commands", { commands: [{ name: "gentle:status" }, { name: "history" }] });
case "prompt": {
if (busy && !rec.streamingBehavior) return respond(id, "prompt", undefined, "Agent is streaming");
- if (busy) return respond(id, "prompt", { disposition: "queued" });
+ if (busy) {
+ enqueue(String(rec.message), rec.streamingBehavior);
+ return respond(id, "prompt", { disposition: "queued" });
+ }
if (process.env.FAKE_AGENT_NO_MODEL) return respond(id, "prompt", undefined, "No model selected");
if (rec.message === "burst") batch = [];
respond(id, "prompt", { disposition: "started" });
@@ -233,19 +311,18 @@ function handle(rec: Rec) {
}
case "steer":
case "follow_up":
+ if (busy) enqueue(String(rec.message), type === "follow_up" ? "followUp" : "steer");
return respond(id, type, { disposition: "queued" });
case "abort":
- hanging?.();
- hanging = undefined;
+ if (!process.env.FAKE_AGENT_IGNORE_ABORT) {
+ hanging?.("aborted");
+ hanging = undefined;
+ }
return respond(id, "abort");
case "new_session":
- newSession();
- return respond(id, "new_session", { cancelled: false });
case "switch_session":
- if (!loadSession(String(rec.sessionPath))) {
- return respond(id, "switch_session", undefined, "Session not found");
- }
- return respond(id, "switch_session", { cancelled: false });
+ void switchSession(rec);
+ return;
case "get_available_models":
return respond(id, type, { models: MODELS });
case "set_model": {
@@ -278,6 +355,22 @@ function handle(rec: Rec) {
}
}
+/** Like Pi, a session switch first tears down a running answer. */
+async function switchSession(rec: Rec): Promise<void> {
+ if (busy) {
+ hanging?.("error");
+ hanging = undefined;
+ await runEnded;
+ }
+ const type = String(rec.type);
+ if (type === "new_session") {
+ newSession();
+ return respond(rec.id, type, { cancelled: false });
+ }
+ if (!loadSession(String(rec.sessionPath))) return respond(rec.id, type, undefined, "Session not found");
+ return respond(rec.id, type, { cancelled: false });
+}
+
if (process.env.FAKE_AGENT_BRANDING) {
out({
type: "extension_ui_request",
diff --git a/packages/daemon/test/gateway.test.ts b/packages/daemon/test/gateway.test.ts
index c27add2..eebcbed 100644
--- a/packages/daemon/test/gateway.test.ts
+++ b/packages/daemon/test/gateway.test.ts
@@ -4,7 +4,7 @@ import type { ServerMessage } from "@gentle-dot/protocol";
import { afterEach, describe, expect, it } from "vitest";
import WebSocket from "ws";
import { type DotDaemon, ensureToken, startDaemon, startupMessage } from "../src/daemon.ts";
-import { HIDDEN_NAMES } from "../src/white-label.ts";
+import { HIDDEN_NAMES, presentText } from "../src/white-label.ts";
import { FAKE_AGENT, tempDir, waitFor } from "./helpers.ts";
const daemons: DotDaemon[] = [];
@@ -236,6 +236,195 @@ describe("gateway", () => {
await find(client, "history");
});
+ it("shows a message sent while busy as queued in every window, then delivers it when the run ends", async () => {
+ const d = await daemon();
+ const a = await authed(d);
+ const b = await authed(d);
+ send(a, { type: "send", text: "slow" });
+ await find(a, "agent_state", (m) => m.state === "thinking");
+ send(a, { type: "send", text: "ask Gentle Shell later" });
+ const shown = presentText("ask Gentle Shell later");
+ expect(shown).not.toContain("Gentle Shell");
+ for (const client of [a, b]) {
+ const queued = await find(client, "queue", (m) => m.steering.length > 0);
+ expect(queued).toMatchObject({ steering: [shown], followUp: [] });
+ }
+ // The final answer is white-labeled too; the user's own words are shown as typed.
+ const echo = presentText("Echo: ask Gentle Shell later");
+ const done = await find(b, "message_done", (m) => m.text === echo);
+ const types = b.messages.map((m) => m.type);
+ const emptied = b.messages.findIndex(
+ (m) => m.type === "queue" && m.steering.length === 0 && m.followUp.length === 0,
+ );
+ const delivered = b.messages.findIndex(
+ (m) => m.type === "user_message" && m.text === "ask Gentle Shell later",
+ );
+ expect(emptied).toBeGreaterThan(types.indexOf("queue"));
+ expect(delivered).toBeGreaterThan(emptied);
+ expect(b.messages.indexOf(done)).toBeGreaterThan(delivered);
+ expect(b.messages.filter((m) => m.type === "message_done").map((m) => m.text)).toEqual([
+ "Echo: slow",
+ echo,
+ ]);
+ await find(b, "agent_state", (m) => m.state === "idle");
+ });
+
+ it("gives a window that connects later the current queue, and nothing once it is empty", async () => {
+ const d = await daemon();
+ const a = await authed(d);
+ send(a, { type: "send", text: "slow" });
+ await find(a, "agent_state", (m) => m.state === "thinking");
+ send(a, { type: "send", text: "queued one" });
+ await find(a, "queue", (m) => m.steering.length > 0);
+ const late = await authed(d);
+ const queued = await find(late, "queue");
+ expect(queued).toMatchObject({ steering: ["queued one"], followUp: [] });
+ expect(late.messages.map((m) => m.type).slice(0, 2)).toEqual(["ready", "queue"]);
+ await find(a, "agent_state", (m) => m.state === "idle");
+ const after = await authed(d);
+ send(after, { type: "list_conversations" });
+ await find(after, "conversations");
+ expect(after.messages.some((m) => m.type === "queue")).toBe(false);
+ });
+
+ it("clears the queue when the run settles without the engine emptying it", async () => {
+ const d = await daemon({ ...process.env, FAKE_AGENT_DROP_QUEUE: "1" });
+ const a = await authed(d);
+ send(a, { type: "send", text: "slow" });
+ await find(a, "agent_state", (m) => m.state === "thinking");
+ send(a, { type: "send", text: "never delivered" });
+ await find(a, "queue", (m) => m.steering.length > 0);
+ await find(a, "agent_state", (m) => m.state === "idle");
+ const cleared = await find(a, "queue", (m) => m.steering.length === 0 && m.followUp.length === 0);
+ expect(cleared).toMatchObject({ steering: [], followUp: [] });
+ expect(a.messages.some((m) => m.type === "user_message" && m.text === "never delivered")).toBe(false);
+ const late = await authed(d);
+ send(late, { type: "list_conversations" });
+ await find(late, "conversations");
+ expect(late.messages.some((m) => m.type === "queue")).toBe(false);
+ });
+
+ it("clears the queue when the agent restarts", async () => {
+ const d = await daemon();
+ const a = await authed(d);
+ send(a, { type: "send", text: "hang" });
+ await find(a, "agent_state", (m) => m.state === "thinking");
+ send(a, { type: "send", text: "lost in the crash" });
+ await find(a, "queue", (m) => m.steering.length > 0);
+ const pid = d.supervisor.pid;
+ if (!pid) throw new Error("the agent is not running");
+ process.kill(pid, "SIGKILL");
+ await find(a, "agent_state", (m) => m.state === "restarting");
+ const cleared = await find(a, "queue", (m) => m.steering.length === 0);
+ expect(cleared).toMatchObject({ steering: [], followUp: [] });
+ await find(a, "agent_state", (m) => m.state === "idle");
+ });
+
+ it("stops a running answer before opening another conversation, with no error", async () => {
+ const d = await daemon();
+ const client = await authed(d);
+ send(client, { type: "send", text: "first chat" });
+ await find(client, "message_done", (m) => m.text === "Echo: first chat");
+ await find(client, "agent_state", (m) => m.state === "idle");
+ const firstId = (await find(client, "ready")).conversationId;
+ send(client, { type: "new_conversation" });
+ await find(client, "history", (m) => m.conversationId !== firstId);
+ const hangs = () => client.messages.filter((m) => m.type === "user_message" && m.text === "hang").length;
+ send(client, { type: "send", text: "hang" });
+ await waitFor(() => hangs() === 1);
+ const before = client.messages.length;
+
+ send(client, { type: "open_conversation", conversationId: firstId });
+ const history = await find(client, "history", (m) => m.conversationId === firstId);
+ expect(history.messages.map((m) => m.text)).toEqual(["first chat", "Echo: first chat"]);
+ const after = client.messages.slice(before);
+ const stopped = after.findIndex((m) => m.type === "message_done" && m.stopped === true);
+ expect(stopped).toBeGreaterThanOrEqual(0);
+ expect(stopped).toBeLessThan(after.indexOf(history));
+ expect(after.filter((m) => m.type === "toast" || m.type === "error")).toEqual([]);
+ expect(after.some((m) => m.type === "message_done" && m.error !== undefined)).toBe(false);
+ await find(client, "agent_state", (m) => m.state === "idle");
+
+ send(client, { type: "send", text: "hang" });
+ await waitFor(() => hangs() === 2);
+ const mark = client.messages.length;
+ send(client, { type: "new_conversation" });
+ const fresh = await waitFor(() =>
+ client.messages
+ .slice(mark)
+ .find((m): m is Extract<ServerMessage, { type: "history" }> => m.type === "history"),
+ );
+ expect(fresh.conversationId).not.toBe(firstId);
+ expect(fresh.messages).toEqual([]);
+ const later = client.messages.slice(mark);
+ expect(later.some((m) => m.type === "message_done" && m.stopped === true)).toBe(true);
+ expect(later.filter((m) => m.type === "toast" || m.type === "error")).toEqual([]);
+ });
+
+ it("sends a message typed during a switch to the new conversation, after its history", async () => {
+ const d = await daemon();
+ const client = await authed(d);
+ const oldId = (await find(client, "ready")).conversationId;
+ send(client, { type: "new_conversation" });
+ send(client, { type: "send", text: "right away" });
+ const done = await find(client, "message_done");
+ expect(done.text).toBe("Echo: right away");
+ await find(client, "agent_state", (m) => m.state === "idle");
+ const types = client.messages.map((m) => m.type);
+ const history = client.messages.findIndex((m) => m.type === "history");
+ const user = types.indexOf("user_message");
+ expect(history).toBeGreaterThanOrEqual(0);
+ expect(history).toBeLessThan(user);
+ expect(types.lastIndexOf("history")).toBe(history);
+ const listed = await find(client, "conversations", (m) =>
+ m.conversations.some((c) => c.title === "right away"),
+ );
+ expect(listed.activeId).not.toBe(oldId);
+ expect(listed.conversations.find((c) => c.title === "right away")?.id).toBe(listed.activeId);
+ });
+
+ it("marks an answer the user stopped as stopped, not as an error", async () => {
+ const d = await daemon();
+ const client = await authed(d);
+ send(client, { type: "send", text: "hang" });
+ await find(client, "agent_state", (m) => m.state === "thinking");
+ send(client, { type: "abort" });
+ const done = await find(client, "message_done");
+ expect(done).toMatchObject({ stopped: true });
+ expect(done.error).toBeUndefined();
+ await find(client, "agent_state", (m) => m.state === "idle");
+ expect(client.messages.filter((m) => m.type === "toast" || m.type === "error")).toEqual([]);
+ });
+
+ it("reports an error while answering inside the conversation, in plain words", async () => {
+ const d = await daemon();
+ const client = await authed(d);
+ send(client, { type: "send", text: "fail" });
+ const done = await find(client, "message_done");
+ expect(done.error).toBe("Something went wrong while answering. Please try again.");
+ expect(done.stopped).toBeUndefined();
+ const shown = JSON.stringify(client.messages);
+ expect(shown).not.toContain("exploded");
+ for (const name of HIDDEN_NAMES) expect(shown).not.toMatch(name);
+ await find(client, "agent_state", (m) => m.state === "idle");
+ expect(client.messages.filter((m) => m.type === "toast")).toEqual([]);
+ });
+
+ it("answers a history request made while the agent restarts once it is back", async () => {
+ const d = await daemon({ ...process.env, FAKE_AGENT_START_DELAY_MS: "400" });
+ const client = await authed(d);
+ send(client, { type: "send", text: "keep me" });
+ await find(client, "agent_state", (m) => m.state === "idle");
+ const pid = d.supervisor.pid;
+ if (!pid) throw new Error("the agent is not running");
+ process.kill(pid, "SIGKILL");
+ await find(client, "agent_state", (m) => m.state === "restarting");
+ send(client, { type: "get_history" });
+ const history = await find(client, "history");
+ expect(history.messages.map((m) => m.text)).toEqual(["keep me", "Echo: keep me"]);
+ expect(client.messages.filter((m) => m.type === "error")).toEqual([]);
+ });
+
it("tells clients about an interrupted run after the agent restarts", async () => {
const d = await daemon();
const client = await authed(d);
diff --git a/packages/protocol/src/index.ts b/packages/protocol/src/index.ts
index 54c58b4..2ca55bd 100644
--- a/packages/protocol/src/index.ts
+++ b/packages/protocol/src/index.ts
@@ -42,6 +42,14 @@ export interface ConversationSummary {
updatedAt: string;
}
+/** Messages the user sent while the assistant was busy, waiting to be taken. */
+export interface MessageQueue {
+ /** Delivered after the current step. */
+ steering: string[];
+ /** Delivered when the assistant finishes. */
+ followUp: string[];
+}
+
export type AuthMethod = "oauth" | "api_key";
export interface AuthProvider {
@@ -167,7 +175,15 @@ export type ServerPayload =
| { type: "agent_state"; state: AgentState }
| { type: "user_message"; messageId: string; text: string }
| { type: "message_delta"; messageId: string; delta: string }
- | { type: "message_done"; messageId: string; text: string }
+ | {
+ type: "message_done";
+ messageId: string;
+ text: string;
+ /** The answer was stopped on purpose (Stop, or switching conversations). */
+ stopped?: true;
+ /** The answer failed; a plain-language explanation for the chat. */
+ error?: string;
+ }
| { type: "activity"; messageId: string; activity: Activity }
| { type: "ask"; ask: Ask }
| { type: "ask_resolved"; requestId: string }
@@ -175,6 +191,7 @@ export type ServerPayload =
| { type: "history"; conversationId?: string; messages: HistoryMessage[] }
| { type: "conversations"; conversations: ConversationSummary[]; activeId?: string }
| { type: "interrupted" }
+ | ({ type: "queue" } & MessageQueue)
| { type: "error"; code: string; message: string }
| { type: "auth_providers"; providers: AuthProvider[]; open?: boolean }
| { type: "auth_prompt"; prompt: AuthPrompt }
@@ -200,6 +217,19 @@ const isString = (value: unknown): value is string => typeof value === "string";
const isOptional = (value: unknown, check: (v: unknown) => boolean) => value === undefined || check(value);
const MAX_TEXT = 100_000;
+/**
+ * Reads the complete queues from the engine's `queue_update` record. A missing
+ * queue is empty and entries that are not text are dropped; returns undefined
+ * when a queue is not a list.
+ */
+export function parseQueue(value: unknown): MessageQueue | undefined {
+ if (typeof value !== "object" || value === null) return undefined;
+ const { steering = [], followUp = [] } = value as Record<string, unknown>;
+ if (!Array.isArray(steering) || !Array.isArray(followUp)) return undefined;
+ const texts = (list: unknown[]) => list.filter((item): item is string => isString(item) && item !== "");
+ return { steering: texts(steering), followUp: texts(followUp) };
+}
+
/** Validates one raw client frame; returns undefined when it is not a known, well-formed message. */
export function parseClientMessage(raw: string): ClientMessage | undefined {
let value: unknown;
diff --git a/packages/protocol/test/protocol.test.ts b/packages/protocol/test/protocol.test.ts
index 5be0cf2..72f52a0 100644
--- a/packages/protocol/test/protocol.test.ts
+++ b/packages/protocol/test/protocol.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, it } from "vitest";
-import { isValidProfileName, PROTOCOL_VERSION, parseClientMessage, THINKING_LEVELS } from "../src/index.ts";
+import {
+ isValidProfileName,
+ PROTOCOL_VERSION,
+ parseClientMessage,
+ parseQueue,
+ THINKING_LEVELS,
+} from "../src/index.ts";
describe("protocol", () => {
it("exposes version 1", () => {
@@ -57,6 +63,29 @@ describe("protocol", () => {
});
});
+describe("queue", () => {
+ it("reads both complete queues from the engine's queue_update", () => {
+ expect(
+ parseQueue({
+ type: "queue_update",
+ steering: ["look at the tests"],
+ followUp: ["then deploy", "and tell me"],
+ }),
+ ).toEqual({ steering: ["look at the tests"], followUp: ["then deploy", "and tell me"] });
+ expect(parseQueue({ steering: [], followUp: [] })).toEqual({ steering: [], followUp: [] });
+ });
+
+ it("treats a missing queue as empty and drops entries that are not text", () => {
+ expect(parseQueue({ steering: ["one", 2, null, ""] })).toEqual({ steering: ["one"], followUp: [] });
+ });
+
+ it("rejects a record whose queues are not lists", () => {
+ for (const value of [null, "queue", { steering: "one" }, { steering: [], followUp: { a: 1 } }]) {
+ expect(parseQueue(value), JSON.stringify(value)).toBeUndefined();
+ }
+ });
+});
+
describe("profile messages", () => {
const parse = (value: object) => parseClientMessage(JSON.stringify(value));
diff --git a/packages/ui/src/accounts.css b/packages/ui/src/accounts.css
index 82f75b5..04a75d0 100644
--- a/packages/ui/src/accounts.css
+++ b/packages/ui/src/accounts.css
@@ -1,13 +1,13 @@
+/* Accounts screen (AccountsPanel). Uses the shared tokens and button styles from styles.css. */
+
.provider-section {
margin-top: 18px;
}
.provider-section h3 {
margin: 0;
- font-size: 12px;
- line-height: 16px;
- font-weight: 600;
- letter-spacing: 0.04em;
+ font: 600 11px / 16px var(--font-mono);
+ letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--muted);
}
@@ -24,21 +24,27 @@
flex-direction: column;
align-items: flex-start;
gap: 4px;
- padding: 14px;
- border-radius: 14px;
+ padding: 14px 16px;
+ border-radius: var(--radius-md);
text-align: left;
}
.method-choice b {
- font-size: 14px;
+ font-size: 15px;
+ font-weight: 700;
}
.method-choice span {
font-size: 12px;
- line-height: 16px;
+ font-weight: 400;
+ line-height: 17px;
color: var(--muted);
}
+.method-choice:hover:not(:disabled) b {
+ color: var(--accent);
+}
+
.connected-row {
display: flex;
align-items: center;
diff --git a/packages/ui/src/components/AskCard.tsx b/packages/ui/src/components/AskCard.tsx
index bec623a..f6bdb6c 100644
--- a/packages/ui/src/components/AskCard.tsx
+++ b/packages/ui/src/components/AskCard.tsx
@@ -1,14 +1,20 @@
import type { Ask } from "@gentle-dot/protocol";
-import { useState } from "react";
+import { useEffect, useRef, useState } from "react";
import type { Send } from "./types.ts";
export function AskCard({ ask, send }: { ask: Ask; send: Send }) {
const [value, setValue] = useState(ask.prefill ?? "");
+ const card = useRef<HTMLElement>(null);
+ // A question that arrives below a long conversation must be seen.
+ useEffect(() => {
+ card.current?.scrollIntoView?.({ block: "nearest" });
+ }, []);
const answer = (fields: { value?: string; confirmed?: boolean; cancelled?: boolean }) =>
send({ type: "ui_response", requestId: ask.requestId, ...fields });
return (
- <section className="ask-card" aria-label="The assistant needs your answer">
+ <section ref={card} className="ask-card" aria-label="The assistant needs your answer">
+ <p className="eyebrow">Needs your answer</p>
<p className="ask-title">{ask.title}</p>
{ask.message ? <p className="ask-message">{ask.message}</p> : null}
{ask.method === "select" ? (
diff --git a/packages/ui/src/components/ChatSurface.tsx b/packages/ui/src/components/ChatSurface.tsx
index 06ac038..dcf15be 100644
--- a/packages/ui/src/components/ChatSurface.tsx
+++ b/packages/ui/src/components/ChatSurface.tsx
@@ -1,9 +1,11 @@
+import type { ClientMessage } from "@gentle-dot/protocol";
import { useState } from "react";
import { openUrl as openExternal } from "../desktop.ts";
import { activeTitle, type DotAction, type DotState, isBusy, needsAccount } from "../store.ts";
import { AccountsPanel } from "./AccountsPanel.tsx";
import { AskCard } from "./AskCard.tsx";
import { Composer } from "./Composer.tsx";
+import { AccountsIcon, ConversationsIcon, MinusIcon, PlusIcon, ProfilesIcon } from "./icons.tsx";
import { MessageList } from "./MessageList.tsx";
import { ProfilesPanel } from "./ProfilesPanel.tsx";
import { newRequestId, type Send } from "./types.ts";
@@ -21,6 +23,8 @@ interface ChatSurfaceProps {
const CONTINUE_TEXT = "Continue where you left off.";
+type SwitchMessage = Extract<ClientMessage, { type: "new_conversation" | "open_conversation" }>;
+
function statusText(state: DotState): string | undefined {
if (state.connection === "unauthorized") {
return "This access key is not valid anymore. Open the page again from the Gentle Dot menu (Open in browser).";
@@ -51,6 +55,19 @@ export function ChatSurface({
dispatch({ type: "profiles", open: true });
};
const [showConversations, setShowConversations] = useState(false);
+ /** A switch that waits for the user to confirm stopping the running answer. */
+ const [pendingSwitch, setPendingSwitch] = useState<SwitchMessage | undefined>(undefined);
+ const switchTo = (message: SwitchMessage) => {
+ setShowConversations(false);
+ if (isBusy(state.agentState)) setPendingSwitch(message);
+ else send(message);
+ };
+ /** Typing means the user is back to the chat; a sign-in waiting for an answer stays. */
+ const closeOptions = () => {
+ setShowConversations(false);
+ if (state.auth.open && !state.auth.flow?.prompt) dispatch({ type: "accounts", open: false });
+ if (state.profiles.open) dispatch({ type: "profiles", open: false });
+ };
const covered = state.auth.open || state.profiles.open;
const status = statusText(state);
const ready =
@@ -60,46 +77,46 @@ export function ChatSurface({
<div className={`chat chat-${variant}`} data-state={state.agentState}>
<header className="chat-header" data-tauri-drag-region={variant === "panel" ? "" : undefined}>
<span className={`state-dot state-${state.agentState}`} aria-hidden="true" />
- <h1>{activeTitle(state)}</h1>
+ <h1 className="gradient-text">{activeTitle(state)}</h1>
<button
type="button"
className="icon"
aria-label="Conversations"
+ title="Conversations"
aria-expanded={showConversations}
onClick={() => {
if (!showConversations) send({ type: "list_conversations" });
setShowConversations(!showConversations);
}}
>
- ☰
+ <ConversationsIcon />
</button>
- <button type="button" className="icon" aria-label="Accounts" onClick={openAccounts}>
- ⚿
+ <button type="button" className="icon" aria-label="Accounts" title="Accounts" onClick={openAccounts}>
+ <AccountsIcon />
</button>
- <button type="button" className="icon" aria-label="Profiles" onClick={openProfiles}>
- ◐
+ <button type="button" className="icon" aria-label="Profiles" title="Profiles" onClick={openProfiles}>
+ <ProfilesIcon />
</button>
<button
type="button"
className="icon"
aria-label="New conversation"
+ title="New conversation"
disabled={!ready}
- onClick={() => {
- setShowConversations(false);
- send({ type: "new_conversation" });
- }}
+ onClick={() => switchTo({ type: "new_conversation" })}
>
- +
+ <PlusIcon />
</button>
{onHide ? (
- <button type="button" className="icon" aria-label="Hide" onClick={onHide}>
- –
+ <button type="button" className="icon" aria-label="Hide" title="Hide" onClick={onHide}>
+ <MinusIcon />
</button>
) : null}
</header>
{showConversations ? (
<nav className="conversations" aria-label="Earlier conversations">
+ <p className="eyebrow">Conversations</p>
{state.conversations.length === 0 ? <p className="muted">No conversations yet.</p> : null}
{state.conversations.map((conversation) => (
<button
@@ -107,10 +124,8 @@ export function ChatSurface({
type="button"
className={conversation.id === state.conversationId ? "active" : ""}
onClick={() => {
- setShowConversations(false);
- if (conversation.id !== state.conversationId) {
- send({ type: "open_conversation", conversationId: conversation.id });
- }
+ if (conversation.id === state.conversationId) setShowConversations(false);
+ else switchTo({ type: "open_conversation", conversationId: conversation.id });
}}
>
<span>{conversation.title}</span>
@@ -155,7 +170,7 @@ export function ChatSurface({
) : null}
<main className="chat-body" hidden={covered}>
- <MessageList messages={state.messages} />
+ <MessageList messages={state.messages} queued={[...state.queue.steering, ...state.queue.followUp]} />
{state.interrupted ? (
<div className="interrupted">
<p>I was interrupted. Continue?</p>
@@ -174,6 +189,27 @@ export function ChatSurface({
))}
</main>
+ {pendingSwitch ? (
+ <div className="switch-confirm" role="alertdialog" aria-label="Stop and switch?">
+ <p>The assistant is still answering. Stop it and open the other conversation?</p>
+ <div className="switch-actions">
+ <button
+ type="button"
+ className="primary"
+ onClick={() => {
+ send(pendingSwitch);
+ setPendingSwitch(undefined);
+ }}
+ >
+ Stop and switch
+ </button>
+ <button type="button" onClick={() => setPendingSwitch(undefined)}>
+ Cancel
+ </button>
+ </div>
+ </div>
+ ) : null}
+
{state.notices.length > 0 ? (
<div className="notices">
{state.notices.map((notice) => (
@@ -187,7 +223,13 @@ export function ChatSurface({
</div>
) : null}
- <Composer busy={isBusy(state.agentState)} disabled={!ready} send={send} focusKey={focusKey} />
+ <Composer
+ busy={isBusy(state.agentState)}
+ disabled={!ready}
+ send={send}
+ focusKey={focusKey}
+ onStartTyping={closeOptions}
+ />
</div>
);
}
diff --git a/packages/ui/src/components/Composer.tsx b/packages/ui/src/components/Composer.tsx
index beddab9..6bc6442 100644
--- a/packages/ui/src/components/Composer.tsx
+++ b/packages/ui/src/components/Composer.tsx
@@ -1,4 +1,5 @@
import { type KeyboardEvent, useEffect, useRef, useState } from "react";
+import { SendIcon } from "./icons.tsx";
import { newRequestId, type Send } from "./types.ts";
interface ComposerProps {
@@ -7,9 +8,11 @@ interface ComposerProps {
send: Send;
/** Changes to this value move focus to the text box. */
focusKey?: number;
+ /** Called when the text box goes from empty to having text. */
+ onStartTyping?: () => void;
}
-export function Composer({ busy, disabled, send, focusKey }: ComposerProps) {
+export function Composer({ busy, disabled, send, focusKey, onStartTyping }: ComposerProps) {
const [text, setText] = useState("");
const box = useRef<HTMLTextAreaElement>(null);
@@ -46,7 +49,10 @@ export function Composer({ busy, disabled, send, focusKey }: ComposerProps) {
rows={1}
value={text}
disabled={disabled}
- onChange={(event) => setText(event.target.value)}
+ onChange={(event) => {
+ if (text === "" && event.target.value !== "") onStartTyping?.();
+ setText(event.target.value);
+ }}
onKeyDown={onKeyDown}
/>
{busy ? (
@@ -59,8 +65,9 @@ export function Composer({ busy, disabled, send, focusKey }: ComposerProps) {
className="composer-send"
disabled={disabled || text.trim() === ""}
aria-label="Send"
+ title="Send"
>
- ↑
+ <SendIcon />
</button>
</form>
);
diff --git a/packages/ui/src/components/MessageList.tsx b/packages/ui/src/components/MessageList.tsx
index d9df985..f47c6c9 100644
--- a/packages/ui/src/components/MessageList.tsx
+++ b/packages/ui/src/components/MessageList.tsx
@@ -53,15 +53,21 @@ function Activities({ activities }: { activities: Activity[] }) {
);
}
-export function MessageList({ messages }: { messages: ChatMessage[] }) {
+interface MessageListProps {
+ messages: ChatMessage[];
+ /** Messages waiting for the assistant, shown after the running answer. */
+ queued?: string[];
+}
+
+export function MessageList({ messages, queued = [] }: MessageListProps) {
const end = useRef<HTMLDivElement>(null);
const last = messages.at(-1);
// biome-ignore lint/correctness/useExhaustiveDependencies: scroll whenever the visible content grows
useEffect(() => {
end.current?.scrollIntoView?.({ block: "end" });
- }, [messages.length, last?.text, last?.activities.length]);
+ }, [messages.length, last?.text, last?.activities.length, last?.note, queued.length]);
- if (messages.length === 0) {
+ if (messages.length === 0 && queued.length === 0) {
return (
<div className="empty">
<p>Hi! What can I do for you?</p>
@@ -82,6 +88,25 @@ export function MessageList({ messages }: { messages: ChatMessage[] }) {
</div>
) : null}
{message.streaming ? <span className="caret" aria-hidden="true" /> : null}
+ {message.note ? (
+ <p
+ className={`message-note message-note-${message.note.kind}`}
+ role={message.note.kind === "error" ? "alert" : undefined}
+ >
+ {message.note.text}
+ </p>
+ ) : null}
+ </article>
+ ))}
+ {queued.map((text, i) => (
+ <article
+ // biome-ignore lint/suspicious/noArrayIndexKey: the same text can be queued twice
+ key={`${i}-${text}`}
+ className="message message-user message-queued"
+ aria-label="Queued message"
+ >
+ <span className="queued-label">Queued</span>
+ <div className="message-body message-plain">{text}</div>
</article>
))}
<div ref={end} />
diff --git a/packages/ui/src/components/icons.tsx b/packages/ui/src/components/icons.tsx
new file mode 100644
index 0000000..ec64b85
--- /dev/null
+++ b/packages/ui/src/components/icons.tsx
@@ -0,0 +1,87 @@
+import type { ReactNode } from "react";
+
+/** One stroke icon set for the header: 18 px, drawn in the button's text color. */
+function Icon({ children }: { children: ReactNode }) {
+ return (
+ <svg
+ width="18"
+ height="18"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.8"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ aria-hidden="true"
+ focusable="false"
+ >
+ {children}
+ </svg>
+ );
+}
+
+/** Two chat bubbles: earlier conversations. */
+export function ConversationsIcon() {
+ return (
+ <Icon>
+ <path d="M14 9a2 2 0 0 1-2 2H6l-3 3V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2z" />
+ <path d="M18 9h1a2 2 0 0 1 2 2v9l-3-3h-6a2 2 0 0 1-2-2v-1" />
+ </Icon>
+ );
+}
+
+/** A key: sign-ins and API keys. */
+export function AccountsIcon() {
+ return (
+ <Icon>
+ <circle cx="7.5" cy="15.5" r="4.5" />
+ <path d="m10.7 12.3 9.8-9.8" />
+ <path d="m16 7 3 3" />
+ <path d="m19 4 2 2" />
+ </Icon>
+ );
+}
+
+/** Sliders: which model does what. */
+export function ProfilesIcon() {
+ return (
+ <Icon>
+ <path d="M4 21v-7" />
+ <path d="M4 10V3" />
+ <path d="M12 21v-9" />
+ <path d="M12 8V3" />
+ <path d="M20 21v-5" />
+ <path d="M20 12V3" />
+ <path d="M2 14h4" />
+ <path d="M10 8h4" />
+ <path d="M18 16h4" />
+ </Icon>
+ );
+}
+
+export function PlusIcon() {
+ return (
+ <Icon>
+ <path d="M12 5v14" />
+ <path d="M5 12h14" />
+ </Icon>
+ );
+}
+
+/** An arrow up, for the composer's send button. */
+export function SendIcon() {
+ return (
+ <Icon>
+ <path d="M12 19V5" />
+ <path d="m5 12 7-7 7 7" />
+ </Icon>
+ );
+}
+
+export function MinusIcon() {
+ return (
+ <Icon>
+ <path d="M5 12h14" />
+ </Icon>
+ );
+}
diff --git a/packages/ui/src/profiles.css b/packages/ui/src/profiles.css
index 2d82ac7..e554388 100644
--- a/packages/ui/src/profiles.css
+++ b/packages/ui/src/profiles.css
@@ -1,23 +1,16 @@
/* Profiles screen (ProfilesPanel). Uses the shared tokens and button styles from styles.css. */
-.profiles-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
-}
-
-.profiles h2 {
- margin: 0;
- font-size: 16px;
-}
+/* The header and the eyebrow title are shared with Accounts in styles.css. */
.profiles h3 {
margin: 4px 0 12px;
- font-size: 15px;
-}
-
-.profiles .muted {
- margin: 4px 0 12px;
+ font-size: 18px;
+ line-height: 24px;
+ font-weight: 800;
+ background: linear-gradient(100deg, var(--text) 20%, var(--accent));
+ -webkit-background-clip: text;
+ background-clip: text;
+ color: transparent;
}
.profile-list {
@@ -26,12 +19,25 @@
padding: 0;
}
+.profile-list {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+}
+
.profile-list li {
- padding: 10px 0;
- border-bottom: 1px solid var(--line);
+ padding: 12px 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--line);
+ background: var(--surface);
+}
+
+.profile-list li.in-use {
+ border-color: var(--accent-line);
}
.profile-name {
+ font-weight: 700;
display: flex;
align-items: center;
gap: 8px;
@@ -59,8 +65,10 @@
}
button.danger {
- background: var(--danger);
- border-color: var(--danger);
+ background: var(--red);
+ border-color: var(--red);
+ color: var(--accent-ink);
+ box-shadow: 0 10px 30px rgba(255, 113, 143, 0.25);
}
.profiles-footer {
@@ -68,10 +76,10 @@ button.danger {
}
.profiles-import {
- padding: 10px 12px;
- border-radius: 14px;
+ padding: 12px 14px;
+ border-radius: var(--radius-md);
border: 1px solid var(--line);
- background: var(--raised);
+ background: var(--surface);
}
.profiles-import p {
@@ -95,18 +103,20 @@ button.danger {
gap: 6px;
}
+.profile-field {
+ font-size: 12px;
+ color: var(--muted);
+}
+
.profile-field input,
.role-route select {
padding: 7px 10px;
- border-radius: 10px;
- border: 1px solid var(--line);
- background: var(--raised);
- color: inherit;
- font: inherit;
+ font-size: 14px;
+ color: var(--text);
}
.profile-problem {
- color: var(--danger);
+ color: var(--red);
}
.role-routes {
diff --git a/packages/ui/src/store.ts b/packages/ui/src/store.ts
index c98ee1a..01c2686 100644
--- a/packages/ui/src/store.ts
+++ b/packages/ui/src/store.ts
@@ -6,6 +6,7 @@ import type {
AuthPrompt,
AuthProvider,
ConversationSummary,
+ MessageQueue,
ModelOption,
Profile,
ProfileRole,
@@ -47,6 +48,8 @@ export interface ChatMessage {
text: string;
streaming: boolean;
activities: Activity[];
+ /** How an answer ended when it did not finish normally. */
+ note?: { kind: "stopped" | "error"; text: string };
}
export interface Notice {
@@ -61,6 +64,8 @@ export interface DotState {
conversationId?: string;
model?: string;
messages: ChatMessage[];
+ /** Messages sent while the assistant works, not taken yet. */
+ queue: MessageQueue;
asks: Ask[];
conversations: ConversationSummary[];
interrupted: boolean;
@@ -81,6 +86,7 @@ export const initialState: DotState = {
connection: "connecting",
agentState: "starting",
messages: [],
+ queue: { steering: [], followUp: [] },
asks: [],
conversations: [],
interrupted: false,
@@ -127,6 +133,8 @@ function reduceServer(state: DotState, message: ServerMessage): DotState {
return {
...state,
agentState: message.agentState,
+ // The daemon sends the queue right after ready when one exists.
+ queue: initialState.queue,
conversationId: message.conversationId ?? state.conversationId,
model: message.model ?? state.model,
};
@@ -148,11 +156,12 @@ function reduceServer(state: DotState, message: ServerMessage): DotState {
streaming: true,
}));
case "message_done":
- return updateAssistant(state, message.messageId, (m) => ({
- ...m,
- text: message.text,
- streaming: false,
- }));
+ return updateAssistant(state, message.messageId, (m) => {
+ const done: ChatMessage = { ...m, text: message.text, streaming: false };
+ if (message.error !== undefined) done.note = { kind: "error", text: message.error };
+ else if (message.stopped) done.note = { kind: "stopped", text: "Stopped." };
+ return done;
+ });
case "activity":
return updateAssistant(state, message.messageId, (m) => {
const index = m.activities.findIndex((a) => a.id === message.activity.id);
@@ -182,6 +191,8 @@ function reduceServer(state: DotState, message: ServerMessage): DotState {
};
case "interrupted":
return { ...state, interrupted: true };
+ case "queue":
+ return { ...state, queue: { steering: message.steering, followUp: message.followUp } };
case "auth_providers":
return {
...closeProfiles(state, message.open === true),
diff --git a/packages/ui/src/styles.css b/packages/ui/src/styles.css
index 2a90896..ed05daf 100644
--- a/packages/ui/src/styles.css
+++ b/packages/ui/src/styles.css
@@ -1,42 +1,37 @@
+/* Visual tokens measured from gentlemanprogramming.com (S15). Dark only. */
:root {
- --bg: #0e0f13;
- --surface: rgba(28, 30, 38, 0.72);
- --surface-solid: #1c1e26;
- --raised: rgba(255, 255, 255, 0.06);
- --line: rgba(255, 255, 255, 0.09);
- --text: #ecedef;
- --muted: #8a8f98;
- --accent: #7c5cff;
- --accent-soft: rgba(124, 92, 255, 0.18);
+ --bg: #1a1218;
+ --bg-glass: rgba(26, 18, 24, 0.82);
+ --surface: #20161e;
+ --surface-2: #241822;
+ --line: #342230;
+ --text: #f6eff3;
+ --muted: #a78e9b;
+ --accent: #f095c8;
+ /* Text on the pink accent: white is 2.13:1 there, this is 8.60:1 (the site's pills do the same). */
+ --accent-ink: #1a1218;
+ --accent-soft: rgba(240, 149, 200, 0.12);
+ --accent-line: rgba(240, 149, 200, 0.35);
+ --accent-shadow: 0 10px 30px rgba(240, 149, 200, 0.3);
+ --green: #b4e7c7;
+ --red: #ff718f;
+ --yellow: #e0c27a;
+ /* The rose Dot's badge (S9) keeps its own amber. */
--amber: #f5a524;
- --danger: #f0506e;
+ --radius-sm: 8px;
+ --radius-md: 12px;
+ --radius-lg: 16px;
+ --radius-pill: 999px;
--radius: 20px;
--ease: cubic-bezier(0.2, 0.8, 0.2, 1);
- color-scheme: dark light;
- font:
- 14px / 20px -apple-system,
- BlinkMacSystemFont,
- "SF Pro Text",
- "Segoe UI",
- system-ui,
- sans-serif;
+ --font-text: Inter, "SF Pro Text", system-ui, -apple-system, "Segoe UI", sans-serif;
+ --font-mono: "IosevkaTerm NF", "Iosevka Term", "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
+ color-scheme: dark;
+ font: 14px / 20px var(--font-text);
color: var(--text);
-webkit-font-smoothing: antialiased;
}
-@media (prefers-color-scheme: light) {
- :root {
- --bg: #f5f5f8;
- --surface: rgba(255, 255, 255, 0.78);
- --surface-solid: #ffffff;
- --raised: rgba(0, 0, 0, 0.04);
- --line: rgba(0, 0, 0, 0.08);
- --text: #17181c;
- --muted: #6b7079;
- --accent-soft: rgba(124, 92, 255, 0.12);
- }
-}
-
* {
box-sizing: border-box;
}
@@ -49,7 +44,7 @@ body,
}
body {
- background: var(--bg);
+ background: radial-gradient(900px 480px at 12% -12%, rgba(240, 149, 200, 0.1), transparent 70%), var(--bg);
}
html[data-surface="dot"] body,
@@ -60,6 +55,7 @@ html[data-surface="panel"] body {
button,
input,
+select,
textarea {
font: inherit;
color: inherit;
@@ -68,14 +64,19 @@ textarea {
button {
cursor: pointer;
border: 1px solid var(--line);
- background: var(--raised);
- border-radius: 10px;
- padding: 6px 12px;
- transition: background 120ms var(--ease);
+ background: var(--surface);
+ border-radius: var(--radius-sm);
+ padding: 7px 14px;
+ font-weight: 600;
+ transition:
+ background 120ms var(--ease),
+ border-color 120ms var(--ease),
+ box-shadow 120ms var(--ease);
}
button:hover:not(:disabled) {
- background: var(--accent-soft);
+ background: var(--surface-2);
+ border-color: var(--accent-line);
}
button:disabled {
@@ -86,24 +87,113 @@ button:disabled {
button.primary {
background: var(--accent);
border-color: var(--accent);
- color: #fff;
+ color: var(--accent-ink);
+ box-shadow: var(--accent-shadow);
+}
+
+button.primary:hover:not(:disabled) {
+ background: #f4aad4;
+ border-color: #f4aad4;
+}
+
+button.primary:disabled {
+ box-shadow: none;
}
button.icon {
- border: none;
+ display: inline-grid;
+ place-items: center;
+ border: 1px solid transparent;
background: none;
- width: 30px;
- height: 30px;
+ width: 32px;
+ height: 32px;
padding: 0;
- border-radius: 8px;
+ border-radius: var(--radius-sm);
color: var(--muted);
}
+button.icon:hover:not(:disabled) {
+ color: var(--text);
+ background: var(--surface-2);
+ border-color: var(--line);
+}
+
+button.icon[aria-expanded="true"] {
+ color: var(--accent);
+ background: var(--accent-soft);
+ border-color: var(--accent-line);
+}
+
+input,
+select,
+textarea {
+ border: 1px solid var(--line);
+ background: var(--bg);
+ border-radius: var(--radius-sm);
+}
+
+input:focus,
+select:focus,
+textarea:focus {
+ outline: none;
+ border-color: var(--accent-line);
+ box-shadow: 0 0 0 3px var(--accent-soft);
+}
+
:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
+/* Uppercase monospace label for sections, like the site's eyebrows. */
+.eyebrow {
+ margin: 0;
+ font: 600 12px / 16px var(--font-mono);
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ color: var(--accent);
+}
+
+/* Headings: heavy, light-to-pink gradient text. */
+.gradient-text {
+ font-weight: 800;
+ letter-spacing: -0.01em;
+ background: linear-gradient(100deg, var(--text) 20%, var(--accent));
+ -webkit-background-clip: text;
+ background-clip: text;
+ color: transparent;
+}
+
+.muted {
+ color: var(--muted);
+ font-size: 12px;
+ line-height: 16px;
+}
+
+.chip {
+ display: inline-flex;
+ align-items: center;
+ padding: 1px 9px;
+ border-radius: var(--radius-pill);
+ border: 1px solid var(--line);
+ font: 600 11px / 16px var(--font-mono);
+ letter-spacing: 0.04em;
+ color: var(--muted);
+}
+
+.chip.ok {
+ border-color: rgba(180, 231, 199, 0.3);
+ background: rgba(180, 231, 199, 0.1);
+ color: var(--green);
+}
+
+.card {
+ padding: 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--line);
+ background: var(--surface);
+}
+
/* ---------- Dot: the rose in a black circle (docs/brand/rose-design.html) ---------- */
/* The window is this square (DOT_SIZE in shell.rs); outside the disc it stays transparent. */
@@ -396,38 +486,46 @@ button.icon {
}
.chat-panel {
- background: var(--surface);
+ background: rgba(26, 18, 24, 0.94);
border: 1px solid var(--line);
border-radius: var(--radius);
overflow: hidden;
- backdrop-filter: blur(24px) saturate(1.4);
- -webkit-backdrop-filter: blur(24px) saturate(1.4);
+ backdrop-filter: blur(24px) saturate(1.3);
+ -webkit-backdrop-filter: blur(24px) saturate(1.3);
}
.chat-web {
- max-width: 760px;
+ max-width: 780px;
margin: 0 auto;
+ border-left: 1px solid var(--line);
+ border-right: 1px solid var(--line);
}
.chat-header {
+ position: relative;
+ z-index: 3;
display: flex;
align-items: center;
- gap: 6px;
- padding: 12px 12px 10px 16px;
+ gap: 4px;
+ padding: 10px 10px 10px 16px;
+ background: var(--bg-glass);
border-bottom: 1px solid var(--line);
+ backdrop-filter: blur(12px);
+ -webkit-backdrop-filter: blur(12px);
}
.chat-header h1 {
flex: 1;
- margin: 0;
- font-size: 14px;
- font-weight: 600;
+ margin: 0 0 0 4px;
+ font-size: 15px;
+ line-height: 20px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.state-dot {
+ flex: none;
width: 8px;
height: 8px;
border-radius: 50%;
@@ -435,64 +533,78 @@ button.icon {
}
.state-idle {
- background: #3ecf8e;
+ background: var(--green);
+ box-shadow: 0 0 8px rgba(180, 231, 199, 0.5);
}
.state-thinking,
.state-working {
background: var(--accent);
+ box-shadow: 0 0 8px rgba(240, 149, 200, 0.6);
animation: pulse 1s var(--ease) infinite;
}
.state-needs_you {
- background: var(--amber);
+ background: var(--yellow);
}
.state-error {
- background: var(--danger);
+ background: var(--red);
}
.conversations {
position: absolute;
- top: 52px;
- left: 8px;
- right: 8px;
- z-index: 2;
+ top: 56px;
+ left: 10px;
+ right: 10px;
+ z-index: 4;
max-height: 60%;
overflow: auto;
- padding: 6px;
- background: var(--surface-solid);
+ padding: 12px 8px 8px;
+ background: var(--surface);
border: 1px solid var(--line);
- border-radius: 14px;
- box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
+ border-radius: var(--radius-md);
+ box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
+}
+
+.conversations .eyebrow {
+ padding: 0 8px 8px;
+}
+
+.conversations > .muted {
+ margin: 0;
+ padding: 0 8px 4px;
}
.conversations button {
display: flex;
flex-direction: column;
align-items: flex-start;
+ gap: 2px;
width: 100%;
- border: none;
+ padding: 8px 10px;
+ border: 1px solid transparent;
background: none;
+ font-weight: 500;
text-align: left;
}
.conversations button.active {
background: var(--accent-soft);
+ border-color: var(--accent-line);
}
-.conversations time,
-.muted {
+.conversations time {
color: var(--muted);
- font-size: 12px;
- line-height: 16px;
+ font: 11px / 16px var(--font-mono);
}
.status {
margin: 10px 12px 0;
padding: 8px 12px;
- border-radius: 10px;
- background: var(--raised);
+ border-radius: var(--radius-md);
+ border: 1px solid var(--line);
+ background: var(--surface);
color: var(--muted);
font-size: 12px;
line-height: 16px;
@@ -501,7 +613,7 @@ button.icon {
.chat-body {
flex: 1;
overflow-y: auto;
- padding: 12px 16px;
+ padding: 14px 16px;
}
.empty {
@@ -511,21 +623,46 @@ button.icon {
color: var(--muted);
}
+.empty p {
+ margin: 0;
+ font-size: 15px;
+}
+
.message {
- margin: 0 0 12px;
+ margin: 0 0 14px;
}
.message-user {
display: flex;
- justify-content: flex-end;
+ flex-direction: column;
+ align-items: flex-end;
}
.message-user .message-body {
max-width: 85%;
- padding: 8px 12px;
- border-radius: 14px 14px 4px 14px;
- background: var(--accent);
- color: #fff;
+ padding: 9px 13px;
+ border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
+ border: 1px solid var(--accent-line);
+ background: rgba(240, 149, 200, 0.16);
+ color: var(--text);
+}
+
+/* Sent while the assistant works; waiting to be taken. */
+.message-queued {
+ opacity: 0.6;
+}
+
+.message-queued .message-body {
+ border-style: dashed;
+ background: transparent;
+}
+
+.queued-label {
+ margin: 0 4px 4px 0;
+ font: 600 10px / 14px var(--font-mono);
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ color: var(--muted);
}
.message-plain {
@@ -533,6 +670,10 @@ button.icon {
overflow-wrap: anywhere;
}
+.message-assistant .message-body {
+ line-height: 22px;
+}
+
.message-body > :first-child {
margin-top: 0;
}
@@ -544,20 +685,24 @@ button.icon {
.message-body pre {
overflow-x: auto;
padding: 10px 12px;
- border-radius: 10px;
- background: var(--raised);
- font:
- 12px / 18px "SF Mono",
- ui-monospace,
- Menlo,
- monospace;
+ border-radius: var(--radius-sm);
+ border: 1px solid var(--line);
+ background: var(--surface);
+ font: 12px / 18px var(--font-mono);
}
.message-body code {
- font-family: "SF Mono", ui-monospace, Menlo, monospace;
+ font-family: var(--font-mono);
font-size: 12px;
}
+.message-body :not(pre) > code {
+ padding: 1px 5px;
+ border-radius: 6px;
+ background: var(--surface-2);
+ color: var(--accent);
+}
+
.message-body a {
color: var(--accent);
}
@@ -586,10 +731,11 @@ button.icon {
display: inline-flex;
align-items: center;
gap: 8px;
- padding: 3px 10px;
- border-radius: 999px;
+ padding: 3px 11px;
+ border-radius: var(--radius-pill);
color: var(--muted);
font-size: 12px;
+ font-weight: 500;
line-height: 16px;
}
@@ -609,16 +755,26 @@ button.icon {
}
.activity-failed {
- color: var(--danger);
+ color: var(--red);
}
.ask-card,
.interrupted {
- margin: 4px 0 12px;
- padding: 12px;
- border-radius: 14px;
- border: 1px solid var(--amber);
- background: rgba(245, 165, 36, 0.08);
+ margin: 4px 0 14px;
+ padding: 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--line);
+ background: var(--surface);
+}
+
+.ask-card {
+ border-color: rgba(224, 194, 122, 0.45);
+ box-shadow: 0 10px 30px rgba(224, 194, 122, 0.08);
+}
+
+.ask-card .eyebrow {
+ margin-bottom: 6px;
+ color: var(--yellow);
}
.interrupted {
@@ -626,14 +782,12 @@ button.icon {
align-items: center;
justify-content: space-between;
gap: 12px;
- border-color: var(--line);
- background: var(--raised);
}
.interrupted p,
.ask-title {
margin: 0;
- font-weight: 600;
+ font-weight: 700;
}
.ask-message {
@@ -646,25 +800,67 @@ button.icon {
display: flex;
flex-wrap: wrap;
gap: 8px;
- margin-top: 10px;
+ margin-top: 12px;
+}
+
+.ask-card .ask-options button:not(.primary) {
+ border-radius: var(--radius-pill);
}
.ask-form input,
.ask-form textarea {
flex: 1 1 100%;
padding: 8px 10px;
- border-radius: 10px;
- border: 1px solid var(--line);
- background: var(--raised);
}
.ask-skip {
- margin-top: 8px;
+ margin-top: 10px;
border: none;
background: none;
padding: 0;
color: var(--muted);
font-size: 12px;
+ font-weight: 500;
+}
+
+.ask-skip:hover:not(:disabled) {
+ background: none;
+ color: var(--text);
+}
+
+.message-note {
+ margin: 6px 0 0;
+ font-size: 12px;
+ line-height: 16px;
+ color: var(--muted);
+}
+
+.message-note-error {
+ display: inline-block;
+ padding: 6px 10px;
+ border-radius: var(--radius-sm);
+ border: 1px solid rgba(255, 113, 143, 0.4);
+ background: rgba(255, 113, 143, 0.08);
+ color: var(--red);
+}
+
+.switch-confirm {
+ margin: 0 12px 10px;
+ padding: 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid rgba(224, 194, 122, 0.45);
+ background: var(--surface);
+ box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
+}
+
+.switch-confirm p {
+ margin: 0 0 12px;
+ font-weight: 600;
+}
+
+.switch-actions {
+ display: flex;
+ gap: 8px;
}
.notices {
@@ -680,23 +876,27 @@ button.icon {
justify-content: space-between;
gap: 8px;
padding: 8px 12px;
- border-radius: 10px;
- background: var(--raised);
+ border-radius: var(--radius-md);
+ border: 1px solid var(--line);
+ background: var(--surface);
font-size: 12px;
}
.notice-error {
- background: rgba(240, 80, 110, 0.14);
+ border-color: rgba(255, 113, 143, 0.4);
+ color: var(--red);
}
.notice-warning {
- background: rgba(245, 165, 36, 0.14);
+ border-color: rgba(224, 194, 122, 0.4);
+ color: var(--yellow);
}
.notice button {
border: none;
background: none;
padding: 0 4px;
+ color: inherit;
}
.composer {
@@ -704,10 +904,18 @@ button.icon {
align-items: flex-end;
gap: 8px;
margin: 0 12px 12px;
- padding: 8px 8px 8px 14px;
- border-radius: 16px;
+ padding: 7px 7px 7px 14px;
+ border-radius: var(--radius-lg);
border: 1px solid var(--line);
- background: var(--raised);
+ background: var(--surface);
+ transition:
+ border-color 120ms var(--ease),
+ box-shadow 120ms var(--ease);
+}
+
+.composer:focus-within {
+ border-color: var(--accent-line);
+ box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer textarea {
@@ -717,74 +925,109 @@ button.icon {
field-sizing: content;
padding: 6px 0;
border: none;
+ border-radius: 0;
background: none;
outline: none;
}
+.composer textarea:focus {
+ box-shadow: none;
+}
+
+.composer textarea::placeholder {
+ color: var(--muted);
+}
+
.composer-send {
+ display: grid;
+ place-items: center;
width: 32px;
height: 32px;
padding: 0;
border-radius: 50%;
background: var(--accent);
border-color: var(--accent);
- color: #fff;
- font-weight: 700;
+ color: var(--accent-ink);
+}
+
+.composer-send:hover:not(:disabled) {
+ background: #f4aad4;
+ border-color: #f4aad4;
+}
+
+.composer-send:not(:disabled) {
+ box-shadow: 0 6px 18px rgba(240, 149, 200, 0.3);
+}
+
+.composer-send:disabled {
+ opacity: 1;
+ background: var(--surface-2);
+ border-color: var(--line);
+ color: var(--muted);
}
.composer-stop {
height: 32px;
- border-radius: 999px;
+ border-radius: var(--radius-pill);
}
/* ---------- Accounts ---------- */
.onboarding {
margin: 10px 12px 0;
- padding: 12px;
- border-radius: 14px;
- border: 1px solid var(--accent);
- background: var(--accent-soft);
+ padding: 14px;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--accent-line);
+ background: var(--surface);
+ box-shadow: 0 10px 30px rgba(240, 149, 200, 0.08);
}
.onboarding p {
- margin: 0 0 10px;
+ margin: 0 0 12px;
}
-.accounts-header {
+.accounts-header,
+.profiles-header {
display: flex;
align-items: center;
justify-content: space-between;
}
-.accounts h2 {
+/* The screen title reads as the section eyebrow. */
+.accounts h2,
+.profiles h2 {
margin: 0;
- font-size: 16px;
+ font: 600 12px / 16px var(--font-mono);
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ color: var(--accent);
}
-.accounts .muted {
- margin: 4px 0 12px;
+.accounts > .muted,
+.profiles .muted {
+ margin: 6px 0 12px;
}
.accounts-search {
width: 100%;
padding: 8px 10px;
- border-radius: 10px;
- border: 1px solid var(--line);
- background: var(--raised);
}
.providers {
list-style: none;
- margin: 12px 0 0;
+ margin: 10px 0 0;
padding: 0;
}
.providers li {
- padding: 10px 0;
+ padding: 12px 0;
border-bottom: 1px solid var(--line);
}
+.providers li:last-child {
+ border-bottom: none;
+}
+
.provider-name {
display: flex;
align-items: center;
@@ -798,35 +1041,35 @@ button.icon {
gap: 8px;
}
-.chip.ok {
- padding: 1px 8px;
- border-radius: 999px;
- font-size: 11px;
- background: rgba(62, 207, 142, 0.16);
- color: #3ecf8e;
-}
-
button.link {
border: none;
background: none;
+ padding: 4px 2px;
color: var(--muted);
+ font-weight: 500;
text-decoration: underline;
+ text-underline-offset: 3px;
+}
+
+button.link:hover:not(:disabled) {
+ background: none;
+ color: var(--accent);
}
.auth-flow {
- padding: 12px;
- border-radius: 14px;
+ padding: 14px;
+ border-radius: var(--radius-md);
border: 1px solid var(--line);
- background: var(--raised);
+ background: var(--surface);
}
.auth-flow-title {
margin: 0 0 8px;
- font-weight: 600;
+ font-weight: 700;
}
.auth-step {
- margin: 10px 0;
+ margin: 12px 0;
}
.auth-step p {
@@ -843,20 +1086,17 @@ button.link {
.device-code {
display: block;
margin: 0 0 10px;
- font:
- 600 22px / 28px "SF Mono",
- ui-monospace,
- Menlo,
- monospace;
+ font: 600 22px / 28px var(--font-mono);
letter-spacing: 0.08em;
+ color: var(--accent);
}
.auth-result.ok {
- color: #3ecf8e;
+ color: var(--green);
}
.auth-result.failed {
- color: var(--danger);
+ color: var(--red);
}
.auth-actions {
diff --git a/packages/ui/test/header.test.tsx b/packages/ui/test/header.test.tsx
new file mode 100644
index 0000000..a4a53cc
--- /dev/null
+++ b/packages/ui/test/header.test.tsx
@@ -0,0 +1,133 @@
+import type { ClientMessage, ServerMessage, ServerPayload } from "@gentle-dot/protocol";
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { useReducer } from "react";
+import { describe, expect, it, vi } from "vitest";
+import { ChatSurface } from "../src/components/ChatSurface.tsx";
+import { type DotState, initialState, reduce } from "../src/store.ts";
+
+function apply(state: DotState, ...payloads: ServerPayload[]): DotState {
+ return payloads.reduce(
+ (s, p) => reduce(s, { type: "server", message: { ...p, seq: 1 } as ServerMessage }),
+ state,
+ );
+}
+
+const providers = [{ id: "openai", name: "OpenAI", methods: ["api_key" as const], configured: true }];
+
+const ready = apply(
+ { ...initialState, connection: "open", agentState: "idle" },
+ { type: "auth_providers", providers },
+ { type: "profiles", profiles: [{ name: "daily", roles: {} }], roles: [], models: [], importable: false },
+);
+
+/** ChatSurface wired to the real reducer, so opening and closing actually happen. */
+function Harness({ initial, send }: { initial: DotState; send: (m: ClientMessage) => void }) {
+ const [state, dispatch] = useReducer(reduce, initial);
+ return (
+ <ChatSurface
+ variant="panel"
+ state={state}
+ send={send}
+ dismiss={vi.fn()}
+ dispatch={dispatch}
+ onHide={vi.fn()}
+ />
+ );
+}
+
+const box = () => screen.getByRole("textbox", { name: "Message" });
+
+describe("header icons", () => {
+ it("uses one set of 18 px stroke SVG icons with names and tooltips instead of text glyphs", () => {
+ const { container } = render(<Harness initial={ready} send={vi.fn()} />);
+ const names = ["Conversations", "Accounts", "Profiles", "New conversation", "Hide"];
+ for (const name of names) {
+ const button = screen.getByRole("button", { name });
+ expect(button).toHaveAttribute("title", name);
+ const icons = button.querySelectorAll("svg");
+ expect(icons).toHaveLength(1);
+ const icon = icons[0];
+ expect(icon).toHaveAttribute("width", "18");
+ expect(icon).toHaveAttribute("height", "18");
+ expect(icon).toHaveAttribute("fill", "none");
+ expect(icon).toHaveAttribute("stroke", "currentColor");
+ expect(icon).toHaveAttribute("aria-hidden", "true");
+ expect(button.textContent).toBe("");
+ }
+ const header = container.querySelector(".chat-header");
+ for (const glyph of ["☰", "⚿", "◐", "+", "–"]) expect(header?.textContent).not.toContain(glyph);
+ // Each action has its own drawing.
+ const drawings = names.map((name) => screen.getByRole("button", { name }).innerHTML);
+ expect(new Set(drawings).size).toBe(names.length);
+ });
+
+ it("shows no Hide button in the browser", () => {
+ render(<ChatSurface variant="web" state={ready} send={vi.fn()} dismiss={vi.fn()} />);
+ expect(screen.queryByRole("button", { name: "Hide" })).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Profiles" })).toHaveAttribute("title", "Profiles");
+ });
+});
+
+describe("typing closes open options", () => {
+ it("closes the conversations list, accounts, and profiles when the first character is typed", async () => {
+ const send = vi.fn();
+ render(<Harness initial={ready} send={send} />);
+
+ await userEvent.click(screen.getByRole("button", { name: "Conversations" }));
+ expect(screen.getByRole("navigation", { name: "Earlier conversations" })).toBeInTheDocument();
+ await userEvent.type(box(), "h");
+ expect(screen.queryByRole("navigation", { name: "Earlier conversations" })).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Conversations" })).toHaveAttribute("aria-expanded", "false");
+ expect(box()).toHaveValue("h");
+
+ await userEvent.clear(box());
+ await userEvent.click(screen.getByRole("button", { name: "Accounts" }));
+ expect(screen.getByRole("region", { name: "Accounts" })).toBeInTheDocument();
+ await userEvent.type(box(), "hi");
+ expect(screen.queryByRole("region", { name: "Accounts" })).not.toBeInTheDocument();
+
+ await userEvent.clear(box());
+ await userEvent.click(screen.getByRole("button", { name: "Profiles" }));
+ expect(screen.getByRole("region", { name: "Profiles" })).toBeInTheDocument();
+ await userEvent.type(box(), "x");
+ expect(screen.queryByRole("region", { name: "Profiles" })).not.toBeInTheDocument();
+ expect(box()).toHaveValue("x");
+ expect(send).not.toHaveBeenCalledWith(expect.objectContaining({ type: "send" }));
+ });
+
+ it("leaves an option opened while text is already typed until the box is emptied and typing starts again", async () => {
+ render(<Harness initial={ready} send={vi.fn()} />);
+ await userEvent.type(box(), "draft");
+ await userEvent.click(screen.getByRole("button", { name: "Profiles" }));
+ await userEvent.type(box(), " more");
+ expect(screen.getByRole("region", { name: "Profiles" })).toBeInTheDocument();
+ await userEvent.clear(box());
+ await userEvent.type(box(), "n");
+ expect(screen.queryByRole("region", { name: "Profiles" })).not.toBeInTheDocument();
+ });
+
+ it("keeps accounts open while a sign-in waits for the user's answer, but still closes the list", async () => {
+ let s = reduce(ready, { type: "accounts", open: true });
+ s = reduce(s, { type: "auth_started", providerId: "openai" });
+ s = apply(s, {
+ type: "auth_prompt",
+ prompt: { flowId: "f1", kind: "secret", message: "Paste your API key" },
+ });
+ render(<Harness initial={s} send={vi.fn()} />);
+ await userEvent.click(screen.getByRole("button", { name: "Conversations" }));
+ await userEvent.type(box(), "o");
+ expect(screen.getByRole("region", { name: "Accounts" })).toBeInTheDocument();
+ expect(screen.getByText("Paste your API key")).toBeInTheDocument();
+ expect(screen.queryByRole("navigation", { name: "Earlier conversations" })).not.toBeInTheDocument();
+ });
+
+ it("closes accounts when a sign-in has no question showing", async () => {
+ let s = reduce(ready, { type: "accounts", open: true });
+ s = reduce(s, { type: "auth_started", providerId: "openai" });
+ render(<Harness initial={s} send={vi.fn()} />);
+ expect(screen.getByRole("region", { name: "Accounts" })).toBeInTheDocument();
+ await userEvent.type(box(), "o");
+ expect(screen.queryByRole("region", { name: "Accounts" })).not.toBeInTheDocument();
+ });
+});
diff --git a/packages/ui/test/queue.test.tsx b/packages/ui/test/queue.test.tsx
new file mode 100644
index 0000000..b1b82a7
--- /dev/null
+++ b/packages/ui/test/queue.test.tsx
@@ -0,0 +1,92 @@
+import type { ServerMessage, ServerPayload } from "@gentle-dot/protocol";
+import { render, screen, within } from "@testing-library/react";
+import { describe, expect, it, vi } from "vitest";
+import { ChatSurface } from "../src/components/ChatSurface.tsx";
+import { type DotState, initialState, reduce } from "../src/store.ts";
+
+let seq = 0;
+function apply(state: DotState, ...payloads: ServerPayload[]): DotState {
+ return payloads.reduce(
+ (s, p) => reduce(s, { type: "server", message: { ...p, seq: ++seq } as ServerMessage }),
+ state,
+ );
+}
+
+const open: DotState = { ...initialState, connection: "open", agentState: "idle" };
+
+describe("queue state", () => {
+ it("starts empty, takes each complete queue from the daemon, and replaces it", () => {
+ expect(initialState.queue).toEqual({ steering: [], followUp: [] });
+ let s = apply(open, { type: "queue", steering: ["first"], followUp: ["later"] });
+ expect(s.queue).toEqual({ steering: ["first"], followUp: ["later"] });
+ s = apply(s, { type: "queue", steering: [], followUp: ["later"] });
+ expect(s.queue).toEqual({ steering: [], followUp: ["later"] });
+ });
+
+ it("forgets the queue on ready, since the daemon re-sends it when one exists", () => {
+ const s = apply(
+ open,
+ { type: "queue", steering: ["stale"], followUp: [] },
+ { type: "ready", agentState: "idle" },
+ );
+ expect(s.queue).toEqual({ steering: [], followUp: [] });
+ });
+});
+
+function surface(state: DotState) {
+ return <ChatSurface variant="web" state={state} send={vi.fn()} dismiss={vi.fn()} />;
+}
+
+describe("queued messages in the chat", () => {
+ it("shows queued messages after the running answer as dimmed, labeled user bubbles", () => {
+ const s = apply(
+ { ...open, agentState: "thinking" },
+ { type: "user_message", messageId: "u1", text: "write the report" },
+ { type: "message_delta", messageId: "m1", delta: "Working on it" },
+ { type: "queue", steering: ["add a summary"], followUp: ["then email it"] },
+ );
+ const { container } = render(surface(s));
+ const articles = [...container.querySelectorAll("article")];
+ expect(articles.map((a) => a.className)).toEqual([
+ "message message-user",
+ "message message-assistant",
+ "message message-user message-queued",
+ "message message-user message-queued",
+ ]);
+ const queued = screen.getAllByRole("article", { name: "Queued message" });
+ expect(queued.map((q) => within(q).getByText("Queued").textContent)).toEqual(["Queued", "Queued"]);
+ expect(queued.map((q) => q.querySelector(".message-body")?.textContent)).toEqual([
+ "add a summary",
+ "then email it",
+ ]);
+ expect(queued[0]?.querySelector(".message-body")).toHaveClass("message-plain");
+ });
+
+ it("shows a queued message even before any answer exists, without the greeting", () => {
+ render(surface(apply(open, { type: "queue", steering: ["hello?"], followUp: [] })));
+ expect(screen.queryByText("Hi! What can I do for you?")).not.toBeInTheDocument();
+ expect(screen.getByRole("article", { name: "Queued message" })).toHaveTextContent("hello?");
+ });
+
+ it("turns a queued message into a normal one when the assistant takes it", () => {
+ let s = apply(
+ { ...open, agentState: "thinking" },
+ { type: "user_message", messageId: "u1", text: "slow" },
+ { type: "queue", steering: ["queued one"], followUp: [] },
+ );
+ const { container, rerender } = render(surface(s));
+ expect(screen.getByRole("article", { name: "Queued message" })).toHaveTextContent("queued one");
+ s = apply(
+ s,
+ { type: "message_done", messageId: "m1", text: "Echo: slow" },
+ { type: "queue", steering: [], followUp: [] },
+ { type: "user_message", messageId: "u2", text: "queued one" },
+ );
+ rerender(surface(s));
+ expect(screen.queryByRole("article", { name: "Queued message" })).not.toBeInTheDocument();
+ expect(screen.queryByText("Queued")).not.toBeInTheDocument();
+ const users = [...container.querySelectorAll(".message-user")];
+ expect(users.map((u) => u.textContent)).toEqual(["slow", "queued one"]);
+ expect(users.every((u) => !u.classList.contains("message-queued"))).toBe(true);
+ });
+});
diff --git a/packages/ui/test/switch.test.tsx b/packages/ui/test/switch.test.tsx
new file mode 100644
index 0000000..b82baa8
--- /dev/null
+++ b/packages/ui/test/switch.test.tsx
@@ -0,0 +1,103 @@
+import type { ServerMessage, ServerPayload } from "@gentle-dot/protocol";
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { describe, expect, it, vi } from "vitest";
+import { ChatSurface } from "../src/components/ChatSurface.tsx";
+import { type DotState, initialState, reduce } from "../src/store.ts";
+
+function apply(state: DotState, ...payloads: ServerPayload[]): DotState {
+ return payloads.reduce(
+ (s, p) => reduce(s, { type: "server", message: { ...p, seq: 1 } as ServerMessage }),
+ state,
+ );
+}
+
+const open: DotState = { ...initialState, connection: "open", agentState: "idle" };
+
+describe("answer outcome", () => {
+ it("keeps an error and a stop on the answer they belong to", () => {
+ const s = apply(
+ open,
+ { type: "message_delta", messageId: "m1", delta: "Half an ans" },
+ { type: "message_done", messageId: "m1", text: "Half an answer", stopped: true },
+ { type: "message_done", messageId: "m2", text: "", error: "Something went wrong while answering." },
+ );
+ expect(s.messages.map((m) => [m.id, m.text, m.streaming, m.note])).toEqual([
+ ["m1", "Half an answer", false, { kind: "stopped", text: "Stopped." }],
+ ["m2", "", false, { kind: "error", text: "Something went wrong while answering." }],
+ ]);
+ expect(s.notices).toEqual([]);
+ });
+
+ it("shows the error inline and a neutral note for a stop", () => {
+ const s = apply(
+ open,
+ { type: "message_done", messageId: "m1", text: "Partial", stopped: true },
+ { type: "message_done", messageId: "m2", text: "", error: "Something went wrong while answering." },
+ );
+ const { container } = render(<ChatSurface variant="web" state={s} send={vi.fn()} dismiss={vi.fn()} />);
+ const answers = [...container.querySelectorAll(".message-assistant")];
+ expect(answers).toHaveLength(2);
+ expect(answers[0]?.querySelector(".message-note")).toHaveTextContent("Stopped.");
+ expect(answers[0]?.querySelector(".message-note")).toHaveClass("message-note-stopped");
+ expect(answers[0]).toHaveTextContent("Partial");
+ const error = answers[1]?.querySelector(".message-note");
+ expect(error).toHaveTextContent("Something went wrong while answering.");
+ expect(error).toHaveClass("message-note-error");
+ expect(error).toHaveAttribute("role", "alert");
+ expect(container.querySelector(".notice")).toBeNull();
+ });
+});
+
+const conversations = [
+ { id: "b.jsonl", title: "Current", updatedAt: "2026-10-08T10:00:00.000Z" },
+ { id: "a.jsonl", title: "Trip plan", updatedAt: "2026-10-07T10:00:00.000Z" },
+];
+const QUESTION = "The assistant is still answering. Stop it and open the other conversation?";
+
+describe("switching while the assistant answers", () => {
+ it("asks first, and Cancel keeps the running answer", async () => {
+ const send = vi.fn();
+ const busy = { ...open, agentState: "thinking" as const, conversationId: "b.jsonl", conversations };
+ render(<ChatSurface variant="web" state={busy} send={send} dismiss={vi.fn()} />);
+ await userEvent.click(screen.getByRole("button", { name: "New conversation" }));
+ const dialog = screen.getByRole("alertdialog", { name: "Stop and switch?" });
+ expect(dialog).toHaveTextContent(QUESTION);
+ expect(send).not.toHaveBeenCalled();
+ await userEvent.click(screen.getByRole("button", { name: "Cancel" }));
+ expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument();
+ expect(send).not.toHaveBeenCalled();
+ });
+
+ it("starts a new conversation after Stop and switch", async () => {
+ const send = vi.fn();
+ const busy = { ...open, agentState: "working" as const, conversationId: "b.jsonl", conversations };
+ render(<ChatSurface variant="web" state={busy} send={send} dismiss={vi.fn()} />);
+ await userEvent.click(screen.getByRole("button", { name: "New conversation" }));
+ await userEvent.click(screen.getByRole("button", { name: "Stop and switch" }));
+ expect(send.mock.calls).toEqual([[{ type: "new_conversation" }]]);
+ expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument();
+ });
+
+ it("opens the chosen conversation after Stop and switch", async () => {
+ const send = vi.fn();
+ const busy = { ...open, agentState: "needs_you" as const, conversationId: "b.jsonl", conversations };
+ render(<ChatSurface variant="web" state={busy} send={send} dismiss={vi.fn()} />);
+ await userEvent.click(screen.getByRole("button", { name: "Conversations" }));
+ send.mockClear();
+ await userEvent.click(screen.getByRole("button", { name: /Trip plan/ }));
+ expect(screen.queryByRole("navigation", { name: "Earlier conversations" })).not.toBeInTheDocument();
+ expect(screen.getByRole("alertdialog", { name: "Stop and switch?" })).toHaveTextContent(QUESTION);
+ expect(send).not.toHaveBeenCalled();
+ await userEvent.click(screen.getByRole("button", { name: "Stop and switch" }));
+ expect(send.mock.calls).toEqual([[{ type: "open_conversation", conversationId: "a.jsonl" }]]);
+ });
+
+ it("switches right away when the assistant is idle", async () => {
+ const send = vi.fn();
+ render(<ChatSurface variant="web" state={{ ...open, conversations }} send={send} dismiss={vi.fn()} />);
+ await userEvent.click(screen.getByRole("button", { name: "New conversation" }));
+ expect(send).toHaveBeenCalledWith({ type: "new_conversation" });
+ expect(screen.queryByRole("alertdialog")).not.toBeInTheDocument();
+ });
+});