Skip to content

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.

feat(modes): open a card to read everything a mode does, and switch with one plain click

Harald63fb645a57ad
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 7fcf19aa9a..463bc8ff3b 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -4459,5 +4459,69 @@
"ide_state_failed": "fehlgeschlagen",
"ide_state_exited": "beendet",
"ide_state_idle": "ruht"
+ },
+ "modes_view": {
+ "title": "Modi",
+ "subtitle": "Wie sich der Assistent verhält. Gilt für Sprache und Chat ab der nächsten Antwort.",
+ "override_banner": "{0} ist gerade in Kraft, weil im Agentic IDE der fokussierte Coding-Modus an ist. Deine eigene Wahl, {1}, übernimmt, sobald der Coding-Modus aus ist oder der Workspace geschlossen wird.",
+ "shelf_title": "Deine Modi",
+ "shelf_hint": "Klicke auf eine Karte, um alles zu lesen, was der Modus macht. „Verwenden“ schaltet um — für Sprache und Chat, ab der nächsten Antwort.",
+ "in_use": "In Benutzung",
+ "in_use_now": "Gerade in Benutzung",
+ "use": "Verwenden",
+ "use_named": "{0} verwenden",
+ "use_this_mode": "Diesen Modus verwenden",
+ "your_choice": "Deine Wahl",
+ "switched_waiting": "{0} ist als deine Wahl gespeichert. {1} bleibt in Kraft, bis der Coding-Modus endet.",
+ "detail_waiting": "Das ist deine Wahl. Sie übernimmt, sobald {0} loslässt — wenn der Coding-Modus aus ist oder der Workspace geschlossen wird.",
+ "badge_builtin": "Eingebaut",
+ "badge_builtin_edited": "Eingebaut · von dir bearbeitet",
+ "badge_yours": "Von dir",
+ "detail_behaviour": "So verhält er sich",
+ "detail_empty_character": "Fügt der Basis-Persona nichts hinzu — das ist der Assistent genau so, wie er ausgeliefert wird.",
+ "detail_voice": "Stimme",
+ "detail_voice_default": "Die eingestellte Stimme",
+ "detail_id": "Id",
+ "length_label": "Antwortlänge",
+ "volunteers_label": "Wie viel er von sich aus sagt",
+ "verbosity_brief": "Kurze Antworten",
+ "verbosity_normal": "Normale Länge",
+ "verbosity_rich": "Erklärt die Gründe",
+ "proactivity_reactive": "Beantwortet nur, was gefragt wurde",
+ "proactivity_normal": "Ausgewogen",
+ "proactivity_forward": "Denkt einen Schritt voraus",
+ "edit": "Bearbeiten",
+ "restore_original": "Original wiederherstellen",
+ "restore_named": "{0} wiederherstellen",
+ "delete": "Löschen",
+ "delete_named": "{0} löschen",
+ "restored": "{0} wiederhergestellt.",
+ "deleted": "{0} gelöscht.",
+ "saved": "{0} gespeichert.",
+ "needs_name": "Ein Modus braucht einen Namen und eine Beschreibung, wie er sich verhält.",
+ "build_title": "Modus bauen",
+ "build_subtitle": "Beschreibe den Assistenten, den du willst, und lass ihn den Modus schreiben — oder füll ihn selbst aus.",
+ "interview_toast": "Sag, was für einen Assistenten du willst. Den Rest frage ich.",
+ "interview_start": "Im Gespräch klären",
+ "interview_end": "Gespräch beenden",
+ "interview_idle": "Öffnet ein Sprachgespräch. Er interviewt dich und schreibt den Modus dann selbst.",
+ "interview_live": "Ich höre zu. Beschreibe den Assistenten, den du willst — er fragt den Rest und speichert den Modus, wenn du zustimmst.",
+ "rather_type": "Lieber tippen?",
+ "written_placeholder": "Eine Version von dir, die direkt ist und schlechte Nachrichten nie beschönigt…",
+ "ask_in_chat": "Im Chat fragen",
+ "chat_not_up": "Die Chat-Verbindung steht noch nicht.",
+ "editing_title": "{0} bearbeiten",
+ "editing_hint": "Speichern schreibt deine Änderungen in diesen Modus zurück.",
+ "editing_hint_builtin": "Speichern legt deine Version auf diese Karte. „Original wiederherstellen“ holt den eingebauten Modus jederzeit zurück.",
+ "cancel_edit": "Bearbeiten abbrechen",
+ "emoji_label": "Emoji",
+ "name_label": "Name des Modus",
+ "name_placeholder": "Nachteule",
+ "description_label": "Beschreibung in einer Zeile",
+ "description_placeholder": "Ruhig und kurz. Fängt spät nichts Neues mehr an.",
+ "character_label": "So verhält er sich",
+ "character_placeholder": "Sprich leise. Es ist spät und ich fahre runter…",
+ "save_mode": "Modus speichern",
+ "save_changes": "Änderungen speichern"
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 757f0f021b..206a52a596 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -4459,5 +4459,69 @@
"ide_state_failed": "failed",
"ide_state_exited": "exited",
"ide_state_idle": "idle"
+ },
+ "modes_view": {
+ "title": "Modes",
+ "subtitle": "How the assistant behaves. Applies to voice and chat from the next turn.",
+ "override_banner": "{0} is in force right now because focused coding mode is on in the Agentic IDE. Your own choice, {1}, takes over as soon as coding mode is turned off or the workspace closes.",
+ "shelf_title": "Your modes",
+ "shelf_hint": "Click a card to read everything a mode does. “Use” switches to it — in voice and chat, from the next turn.",
+ "in_use": "In use",
+ "in_use_now": "In use now",
+ "use": "Use",
+ "use_named": "Use {0}",
+ "use_this_mode": "Use this mode",
+ "your_choice": "Your choice",
+ "switched_waiting": "{0} is saved as your choice. {1} stays in force until coding mode ends.",
+ "detail_waiting": "This is your choice. It takes over as soon as {0} lets go — when coding mode is turned off or the workspace closes.",
+ "badge_builtin": "Built in",
+ "badge_builtin_edited": "Built in · edited by you",
+ "badge_yours": "Yours",
+ "detail_behaviour": "How it behaves",
+ "detail_empty_character": "Adds nothing on top of the base persona — this is the assistant exactly as it ships.",
+ "detail_voice": "Voice",
+ "detail_voice_default": "The configured voice",
+ "detail_id": "Id",
+ "length_label": "Answer length",
+ "volunteers_label": "How much it volunteers",
+ "verbosity_brief": "Short answers",
+ "verbosity_normal": "Normal length",
+ "verbosity_rich": "Explains the reasoning",
+ "proactivity_reactive": "Answers only what was asked",
+ "proactivity_normal": "Balanced",
+ "proactivity_forward": "Thinks a step ahead",
+ "edit": "Edit",
+ "restore_original": "Restore original",
+ "restore_named": "Restore {0}",
+ "delete": "Delete",
+ "delete_named": "Delete {0}",
+ "restored": "{0} restored.",
+ "deleted": "{0} deleted.",
+ "saved": "{0} saved.",
+ "needs_name": "A mode needs a name and a description of how it behaves.",
+ "build_title": "Build a mode",
+ "build_subtitle": "Describe the assistant you want and let it write the mode, or fill it in yourself.",
+ "interview_toast": "Say what kind of assistant you want. I'll ask the rest.",
+ "interview_start": "Talk it through",
+ "interview_end": "End the conversation",
+ "interview_idle": "Opens a voice conversation. It interviews you, then writes the mode itself.",
+ "interview_live": "Listening. Describe the assistant you want — it will ask the rest and save the mode when you agree.",
+ "rather_type": "Rather type it?",
+ "written_placeholder": "A version of you that is blunt and never softens bad news…",
+ "ask_in_chat": "Ask in chat",
+ "chat_not_up": "The chat connection is not up yet.",
+ "editing_title": "Editing {0}",
+ "editing_hint": "Saving writes your changes back to this mode.",
+ "editing_hint_builtin": "Saving keeps your version on this card. “Restore original” brings the built-in back at any time.",
+ "cancel_edit": "Stop editing",
+ "emoji_label": "Emoji",
+ "name_label": "Mode name",
+ "name_placeholder": "Night Owl",
+ "description_label": "One-line description",
+ "description_placeholder": "Quiet and short. Refuses to start new work late.",
+ "character_label": "How it behaves",
+ "character_placeholder": "Speak quietly. It is late and I am winding down…",
+ "save_mode": "Save mode",
+ "save_changes": "Save changes"
}
}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 5bd610a342..17af3fdfc1 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -4459,5 +4459,69 @@
"ide_state_failed": "falló",
"ide_state_exited": "terminado",
"ide_state_idle": "inactivo"
+ },
+ "modes_view": {
+ "title": "Modos",
+ "subtitle": "Cómo se comporta el asistente. Se aplica a voz y chat desde la próxima respuesta.",
+ "override_banner": "{0} está en vigor ahora porque el modo de programación enfocada está activo en el Agentic IDE. Tu propia elección, {1}, tomará el relevo en cuanto se apague el modo de programación o se cierre el espacio de trabajo.",
+ "shelf_title": "Tus modos",
+ "shelf_hint": "Haz clic en una tarjeta para leer todo lo que hace un modo. “Usar” cambia a él — en voz y chat, desde la próxima respuesta.",
+ "in_use": "En uso",
+ "in_use_now": "En uso ahora",
+ "use": "Usar",
+ "use_named": "Usar {0}",
+ "use_this_mode": "Usar este modo",
+ "your_choice": "Tu elección",
+ "switched_waiting": "{0} queda guardado como tu elección. {1} sigue en vigor hasta que termine el modo de programación.",
+ "detail_waiting": "Esta es tu elección. Tomará el relevo en cuanto {0} lo suelte — cuando se apague el modo de programación o se cierre el espacio de trabajo.",
+ "badge_builtin": "Integrado",
+ "badge_builtin_edited": "Integrado · editado por ti",
+ "badge_yours": "Tuyo",
+ "detail_behaviour": "Cómo se comporta",
+ "detail_empty_character": "No añade nada a la persona base — es el asistente exactamente como viene.",
+ "detail_voice": "Voz",
+ "detail_voice_default": "La voz configurada",
+ "detail_id": "Id",
+ "length_label": "Longitud de las respuestas",
+ "volunteers_label": "Cuánto aporta por iniciativa propia",
+ "verbosity_brief": "Respuestas cortas",
+ "verbosity_normal": "Longitud normal",
+ "verbosity_rich": "Explica el razonamiento",
+ "proactivity_reactive": "Responde solo lo que se preguntó",
+ "proactivity_normal": "Equilibrado",
+ "proactivity_forward": "Piensa un paso por delante",
+ "edit": "Editar",
+ "restore_original": "Restaurar el original",
+ "restore_named": "Restaurar {0}",
+ "delete": "Eliminar",
+ "delete_named": "Eliminar {0}",
+ "restored": "{0} restaurado.",
+ "deleted": "{0} eliminado.",
+ "saved": "{0} guardado.",
+ "needs_name": "Un modo necesita un nombre y una descripción de cómo se comporta.",
+ "build_title": "Crear un modo",
+ "build_subtitle": "Describe el asistente que quieres y deja que él escriba el modo, o rellénalo tú mismo.",
+ "interview_toast": "Di qué tipo de asistente quieres. Yo pregunto el resto.",
+ "interview_start": "Hablarlo",
+ "interview_end": "Terminar la conversación",
+ "interview_idle": "Abre una conversación de voz. Te entrevista y luego escribe el modo por sí mismo.",
+ "interview_live": "Escuchando. Describe el asistente que quieres — preguntará el resto y guardará el modo cuando estés de acuerdo.",
+ "rather_type": "¿Prefieres escribirlo?",
+ "written_placeholder": "Una versión tuya que es directa y nunca suaviza las malas noticias…",
+ "ask_in_chat": "Preguntar en el chat",
+ "chat_not_up": "La conexión del chat aún no está lista.",
+ "editing_title": "Editando {0}",
+ "editing_hint": "Guardar escribe tus cambios de vuelta en este modo.",
+ "editing_hint_builtin": "Guardar deja tu versión en esta tarjeta. “Restaurar el original” recupera el modo integrado en cualquier momento.",
+ "cancel_edit": "Dejar de editar",
+ "emoji_label": "Emoji",
+ "name_label": "Nombre del modo",
+ "name_placeholder": "Búho nocturno",
+ "description_label": "Descripción en una línea",
+ "description_placeholder": "Tranquilo y breve. Se niega a empezar trabajo nuevo tarde.",
+ "character_label": "Cómo se comporta",
+ "character_placeholder": "Habla bajo. Es tarde y estoy desconectando…",
+ "save_mode": "Guardar modo",
+ "save_changes": "Guardar cambios"
}
}
diff --git a/jarvis/ui/web/frontend/src/lib/modesApi.ts b/jarvis/ui/web/frontend/src/lib/modesApi.ts
index c1b153db13..06d51cd3c0 100644
--- a/jarvis/ui/web/frontend/src/lib/modesApi.ts
+++ b/jarvis/ui/web/frontend/src/lib/modesApi.ts
@@ -20,6 +20,8 @@ export interface AssistantMode {
/** How the assistant behaves — appended to the base persona, never replacing it. */
character: string;
built_in: boolean;
+ /** A built-in the user has overlaid with their own file — "restore" is real. */
+ edited: boolean;
voice: string;
verbosity: Verbosity;
proactivity: Proactivity;
@@ -27,7 +29,14 @@ export interface AssistantMode {
export interface ModesState {
modes: AssistantMode[];
+ /** The mode IN FORCE for the next turn — a section override wins here. */
active: string;
+ /**
+ * The user's own, stored choice. Equal to `active` unless a section override
+ * is in force; then it is the only proof the shelf has that a switch was
+ * saved rather than swallowed.
+ */
+ chosen: string;
/**
* A mode a SCREEN switched on (today: the Agentic IDE), which outranks the
* user's own choice while it lasts. Surfaced so the UI can say why the active
diff --git a/jarvis/ui/web/frontend/src/views/ModesView.test.tsx b/jarvis/ui/web/frontend/src/views/ModesView.test.tsx
new file mode 100644
index 0000000000..0ad160e2db
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/ModesView.test.tsx
@@ -0,0 +1,282 @@
+/**
+ * Component tests for ModesView — the shelf of characters.
+ *
+ * Pinned here is what a user noticed was missing: a card can be OPENED to read
+ * everything the mode does (the full character text, not the one-liner), a mode
+ * can be switched with one explicit click, and while the Agentic IDE holds the
+ * persona the screen tells the truth — the click was stored (chosen) even though
+ * something else is in force (active) — instead of looking broken.
+ *
+ * Driven through a stateful fetch fake, so a switch and the re-read that
+ * follows agree with each other. No jest-dom in this repo — assertions use
+ * toBeTruthy()/toBeNull().
+ */
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+
+// ViewHeader lives in ChatsView, which drags in the whole chat surface; the
+// view only needs its shape.
+vi.mock("@/views/ChatsView", () => ({
+ ViewHeader: ({ title }: { title: string }) => <header>{title}</header>,
+}));
+
+// The voice interview button needs a call controller; none of these tests
+// start a call, so a quiet stub keeps the realtime stack out of the render.
+vi.mock("@/components/agentic/useVoiceCall", () => ({
+ useVoiceCall: () => ({
+ active: false,
+ busy: false,
+ connecting: false,
+ toggleCall: vi.fn(async () => undefined),
+ voiceState: "idle",
+ }),
+}));
+
+import { ModesView } from "@/views/ModesView";
+import { setUiLanguage } from "@/i18n";
+import { useEventStore } from "@/store/events";
+import type { AssistantMode } from "@/lib/modesApi";
+
+const MODES: AssistantMode[] = [
+ {
+ slug: "assistant",
+ name: "Assistant",
+ emoji: "🎩",
+ description: "Precise and quiet.",
+ character: "",
+ built_in: true,
+ edited: false,
+ voice: "",
+ verbosity: "normal",
+ proactivity: "normal",
+ },
+ {
+ slug: "friend",
+ name: "Friend",
+ emoji: "🫂",
+ description: "Warm and casual.",
+ character: "You are talking to a friend, not serving a client.\n\nDrop the deference.",
+ built_in: true,
+ edited: false,
+ voice: "",
+ verbosity: "normal",
+ proactivity: "normal",
+ },
+ {
+ slug: "coding",
+ name: "Coding",
+ emoji: "💻",
+ description: "Terminal-aware.",
+ character: "The user is working in the Agentic IDE.",
+ built_in: true,
+ edited: false,
+ voice: "",
+ verbosity: "normal",
+ proactivity: "normal",
+ },
+ {
+ slug: "night-owl",
+ name: "Night Owl",
+ emoji: "🦉",
+ description: "Quiet and short.",
+ character: "Speak quietly. It is late.",
+ built_in: false,
+ edited: false,
+ voice: "nova",
+ verbosity: "brief",
+ proactivity: "reactive",
+ },
+];
+
+interface Call {
+ url: string;
+ method: string;
+ body: unknown;
+}
+
+/**
+ * A stand-in for /api/modes that keeps the one bit of state that matters: the
+ * user's stored choice, and — optionally — a section override that outranks it,
+ * exactly the way the backend's `active_slug()` composes the two.
+ */
+function stubServer(opts: { chosen?: string; override?: string } = {}) {
+ const state = { chosen: opts.chosen ?? "assistant", override: opts.override ?? "" };
+ const calls: Call[] = [];
+ const payload = () => ({
+ modes: MODES,
+ active: state.override || state.chosen,
+ chosen: state.chosen,
+ section_override: state.override,
+ verbosities: ["brief", "normal", "rich"],
+ proactivities: ["reactive", "normal", "forward"],
+ });
+ const json = (body: unknown, status = 200) => ({
+ ok: status >= 200 && status < 300,
+ status,
+ statusText: "OK",
+ json: async () => body,
+ });
+
+ vi.stubGlobal(
+ "fetch",
+ vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
+ const url = String(input);
+ const method = (init?.method ?? "GET").toUpperCase();
+ const body = init?.body ? JSON.parse(init.body as string) : null;
+ calls.push({ url, method, body });
+ if (url === "/api/modes" && method === "GET") return json(payload());
+ if (url === "/api/modes/active" && method === "PUT") {
+ state.chosen = (body as { slug: string }).slug;
+ return json({ ok: true, ...payload(), chosen: state.chosen, restart_required: false });
+ }
+ if (url === "/api/modes" && method === "POST") return json({ ok: true, ...payload() });
+ return json({ detail: `unexpected ${method} ${url}` }, 404);
+ }),
+ );
+ return { calls, state };
+}
+
+beforeEach(() => {
+ setUiLanguage("en");
+ useEventStore.setState({ toasts: [] });
+});
+
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+});
+
+async function renderView() {
+ render(<ModesView />);
+ await waitFor(() => expect(screen.getByTestId("mode-card-friend")).toBeTruthy());
+}
+
+describe("ModesView — reading a mode", () => {
+ it("opens with the mode in force and shows its full character text", async () => {
+ stubServer({ chosen: "friend" });
+ await renderView();
+
+ const detail = screen.getByTestId("mode-detail");
+ expect(within(detail).getByText("Friend")).toBeTruthy();
+ // The full text, verbatim — not the one-line description.
+ expect(screen.getByTestId("mode-detail-character").textContent).toContain(
+ "You are talking to a friend, not serving a client.",
+ );
+ expect(within(detail).getByText("In use now")).toBeTruthy();
+ });
+
+ it("clicking a card opens it without switching to it", async () => {
+ const server = stubServer({ chosen: "assistant" });
+ await renderView();
+
+ fireEvent.click(screen.getByTestId("mode-card-night-owl"));
+
+ const detail = screen.getByTestId("mode-detail");
+ expect(within(detail).getByText("Night Owl")).toBeTruthy();
+ expect(screen.getByTestId("mode-detail-character").textContent).toContain(
+ "Speak quietly. It is late.",
+ );
+ // The knobs and the voice are spelled out, not just the description.
+ expect(within(detail).getByText("Short answers")).toBeTruthy();
+ expect(within(detail).getByText("Answers only what was asked")).toBeTruthy();
+ expect(within(detail).getByText("nova")).toBeTruthy();
+ expect(within(detail).getByText("Yours")).toBeTruthy();
+ // Reading is not choosing: nothing was written.
+ expect(server.calls.filter((c) => c.method === "PUT")).toHaveLength(0);
+ expect(server.state.chosen).toBe("assistant");
+ });
+
+ it("states that the default mode adds nothing rather than showing a blank box", async () => {
+ stubServer({ chosen: "assistant" });
+ await renderView();
+ expect(screen.getByTestId("mode-detail-character").textContent).toContain(
+ "Adds nothing on top of the base persona",
+ );
+ });
+});
+
+describe("ModesView — switching", () => {
+ it("the card's Use switches with one click and the shelf follows", async () => {
+ const server = stubServer({ chosen: "assistant" });
+ await renderView();
+
+ fireEvent.click(screen.getByTestId("mode-use-friend"));
+
+ await waitFor(() => expect(server.state.chosen).toBe("friend"));
+ const put = server.calls.find((c) => c.method === "PUT");
+ expect(put?.url).toBe("/api/modes/active");
+ expect(put?.body).toEqual({ slug: "friend" });
+ await waitFor(() =>
+ expect(screen.getByTestId("mode-card-friend").getAttribute("data-active")).toBe("true"),
+ );
+ expect(screen.getByTestId("mode-card-assistant").getAttribute("data-active")).toBeNull();
+ // The card in use offers no second "Use".
+ expect(screen.queryByTestId("mode-use-friend")).toBeNull();
+ expect(screen.getByTestId("mode-use-assistant")).toBeTruthy();
+ });
+
+ it("the open panel's Use switches too", async () => {
+ const server = stubServer({ chosen: "assistant" });
+ await renderView();
+
+ fireEvent.click(screen.getByTestId("mode-card-night-owl"));
+ fireEvent.click(screen.getByTestId("mode-detail-use"));
+
+ await waitFor(() => expect(server.state.chosen).toBe("night-owl"));
+ await waitFor(() =>
+ expect(within(screen.getByTestId("mode-detail")).getByText("In use now")).toBeTruthy(),
+ );
+ });
+});
+
+describe("ModesView — while the Agentic IDE holds the persona", () => {
+ it("says which mode is in force, and that the click was stored", async () => {
+ const server = stubServer({ chosen: "assistant", override: "coding" });
+ await renderView();
+
+ const banner = screen.getByTestId("mode-override-banner");
+ expect(banner.textContent).toContain("Coding is in force");
+ expect(banner.textContent).toContain("Your own choice, Assistant");
+ expect(screen.getByTestId("mode-card-coding").getAttribute("data-active")).toBe("true");
+
+ fireEvent.click(screen.getByTestId("mode-use-friend"));
+ await waitFor(() => expect(server.state.chosen).toBe("friend"));
+
+ // Coding stays in force — but the shelf now shows Friend as the stored
+ // choice, and a toast says so, instead of the click vanishing.
+ await waitFor(() =>
+ expect(within(screen.getByTestId("mode-card-friend")).getByText("Your choice")).toBeTruthy(),
+ );
+ expect(screen.getByTestId("mode-card-coding").getAttribute("data-active")).toBe("true");
+ expect(screen.getByTestId("mode-override-banner").textContent).toContain(
+ "Your own choice, Friend",
+ );
+ const toasts = useEventStore.getState().toasts;
+ expect(toasts.some((t) => t.message.includes("Friend is saved as your choice"))).toBe(true);
+ });
+});
+
+describe("ModesView — editing", () => {
+ it("Edit loads the mode into the form and saves it back under the same id", async () => {
+ const server = stubServer({ chosen: "assistant" });
+ await renderView();
+
+ fireEvent.click(screen.getByTestId("mode-card-night-owl"));
+ fireEvent.click(screen.getByTestId("mode-detail-edit"));
+
+ const form = screen.getByTestId("mode-form");
+ expect(within(form).getByText("Editing Night Owl")).toBeTruthy();
+ const character = within(form).getByLabelText("How it behaves") as HTMLTextAreaElement;
+ expect(character.value).toBe("Speak quietly. It is late.");
+
+ fireEvent.change(character, { target: { value: "Speak quietly. It is very late." } });
+ fireEvent.click(screen.getByTestId("mode-save-button"));
+
+ await waitFor(() => expect(server.calls.some((c) => c.method === "POST")).toBe(true));
+ const post = server.calls.find((c) => c.method === "POST")?.body as Record<string, unknown>;
+ expect(post.slug).toBe("night-owl");
+ expect(post.name).toBe("Night Owl");
+ expect(post.character).toBe("Speak quietly. It is very late.");
+ expect(post.voice).toBe("nova");
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/views/ModesView.tsx b/jarvis/ui/web/frontend/src/views/ModesView.tsx
index 62b478d97c..a0a570f3a8 100644
--- a/jarvis/ui/web/frontend/src/views/ModesView.tsx
+++ b/jarvis/ui/web/frontend/src/views/ModesView.tsx
@@ -1,26 +1,52 @@
/**
* Modes — pick the character the assistant answers in, or build a new one.
*
- * Two halves, in the order the decision actually gets made: the shelf you
- * choose from, and the workshop where you make another one. Switching applies
- * from the next turn in voice AND in chat, with no restart, because both brains
- * read the persona through one function on the backend.
+ * Three parts, in the order the decision actually gets made: the shelf you
+ * choose from, the open card that shows EVERYTHING a mode does, and the
+ * workshop where you make (or change) one. Switching applies from the next turn
+ * in voice AND in chat, with no restart, because both brains read the persona
+ * through one function on the backend.
+ *
+ * Reading and choosing are two different clicks, on purpose. Clicking a card
+ * opens it below the shelf — the full character text, the knobs, the voice —
+ * without touching what the assistant is running, so you can read Coach without
+ * becoming Coach. Every card and the open panel carry an explicit "Use" so the
+ * switch is still one click and never a hidden gesture; the first version hid
+ * "restore" behind a hover and nobody found it.
+ *
+ * Two facts, shown apart: what is IN FORCE and what the user CHOSE. They differ
+ * while the Agentic IDE's coding mode overrides the persona, and a screen that
+ * only knows the first cannot even confirm that a click did anything.
*
* The workshop offers two ways in, because describing a personality out loud
* and typing one are genuinely different tasks. "Talk it through" opens a real
* voice conversation: the assistant interviews you and writes the mode itself
* with its `save_mode` tool. The written path hands the same job to the chat.
- * Either way the mode lands in the same place and shows up on this screen.
+ * The form is also the editor: "Edit" on any card loads it there, and saving
+ * writes it back under the same id (a built-in keeps its "restore original").
*
* Colours come from theme tokens only, so the view is correct in light and dark
* without a second palette to keep in step.
*/
-import { useCallback, useEffect, useMemo, useState } from "react";
-import { Loader2, Mic, MicOff, Plus, RotateCcw, Sparkles, Trash2, Check } from "lucide-react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import {
+ Check,
+ Loader2,
+ Mic,
+ MicOff,
+ Pencil,
+ Plus,
+ RotateCcw,
+ Sparkles,
+ Trash2,
+ X,
+} from "lucide-react";
import { ViewHeader } from "@/views/ChatsView";
import { useEventStore } from "@/store/events";
import { useVoiceCall } from "@/components/agentic/useVoiceCall";
+import { BrandedSelect } from "@/components/ui/select";
+import { useT } from "@/i18n";
import { sendChatMessage } from "@/lib/chat";
import { cn } from "@/lib/utils";
import {
@@ -30,6 +56,7 @@ import {
restoreBuiltin,
saveMode,
type AssistantMode,
+ type ModeDraft,
type ModesState,
type Proactivity,
type Verbosity,
@@ -52,28 +79,43 @@ const INTERVIEW_BRIEF =
"on the task? What should you never do? When you have enough, read the mode " +
"back to me in a sentence and save it with the save_mode tool.";
-const VERBOSITY_LABELS: Record<Verbosity, string> = {
- brief: "Short answers",
- normal: "Normal length",
- rich: "Explains the reasoning",
+/** i18n keys for the two knobs — layer 4 of the five-layer enum pattern. */
+const VERBOSITY_KEYS: Record<Verbosity, string> = {
+ brief: "modes_view.verbosity_brief",
+ normal: "modes_view.verbosity_normal",
+ rich: "modes_view.verbosity_rich",
};
-const PROACTIVITY_LABELS: Record<Proactivity, string> = {
- reactive: "Answers only what was asked",
- normal: "Balanced",
- forward: "Thinks a step ahead",
+const PROACTIVITY_KEYS: Record<Proactivity, string> = {
+ reactive: "modes_view.proactivity_reactive",
+ normal: "modes_view.proactivity_normal",
+ forward: "modes_view.proactivity_forward",
};
-const EMPTY_DRAFT = {
+interface Draft extends ModeDraft {
+ name: string;
+ emoji: string;
+ description: string;
+ character: string;
+ verbosity: Verbosity;
+ proactivity: Proactivity;
+}
+
+const EMPTY_DRAFT: Draft = {
name: "",
emoji: "",
description: "",
character: "",
- verbosity: "normal" as Verbosity,
- proactivity: "normal" as Proactivity,
+ verbosity: "normal",
+ proactivity: "normal",
};
+function fill(template: string, ...values: string[]): string {
+ return values.reduce((text, value, i) => text.replace(`{${i}}`, value), template);
+}
+
export function ModesView() {
+ const t = useT();
const pushToast = useEventStore((s) => s.pushToast);
const setActiveSection = useEventStore((s) => s.setActiveSection);
const { active: voiceLive, busy: voiceBusy, connecting, toggleCall } = useVoiceCall();
@@ -81,9 +123,11 @@ export function ModesView() {
const [state, setState] = useState<ModesState | null>(null);
const [loading, setLoading] = useState(true);
const [switching, setSwitching] = useState("");
- const [draft, setDraft] = useState(EMPTY_DRAFT);
+ const [viewing, setViewing] = useState<string | null>(null);
+ const [draft, setDraft] = useState<Draft>(EMPTY_DRAFT);
const [saving, setSaving] = useState(false);
const [written, setWritten] = useState("");
+ const formRef = useRef<HTMLElement>(null);
const refresh = useCallback(async () => {
try {
@@ -116,12 +160,28 @@ export function ModesView() {
}, [voiceLive, refresh]);
const modes = useMemo(() => state?.modes ?? [], [state]);
+ const active = state?.active ?? "";
+ const chosen = state?.chosen ?? active;
const override = state?.section_override ?? "";
+ const nameOf = (slug: string) => modes.find((m) => m.slug === slug)?.name ?? slug;
+
+ // The open card: what the user clicked, else the mode in force. Never a mode
+ // that has since been deleted — that panel would describe a ghost.
+ const shown = useMemo(() => {
+ const wanted = viewing && modes.some((m) => m.slug === viewing) ? viewing : active;
+ return modes.find((m) => m.slug === wanted) ?? null;
+ }, [modes, viewing, active]);
- const choose = async (slug: string) => {
- setSwitching(slug);
+ const choose = async (mode: AssistantMode) => {
+ setSwitching(mode.slug);
try {
- setState(await activateMode(slug));
+ const next = await activateMode(mode.slug);
+ setState(next);
+ if (next.section_override && next.active !== mode.slug) {
+ // The click DID something — it is stored — but nothing on the shelf
+ // moves. Say so, or the user learns that the screen is broken.
+ pushToast("info", fill(t("modes_view.switched_waiting"), mode.name, nameOf(next.active)));
+ }
} catch (e) {
pushToast("error", (e as Error).message);
} finally {
@@ -132,21 +192,44 @@ export function ModesView() {
const remove = async (mode: AssistantMode) => {
try {
setState(mode.built_in ? await restoreBuiltin(mode.slug) : await deleteMode(mode.slug));
- pushToast("success", mode.built_in ? `${mode.name} restored.` : `${mode.name} deleted.`);
+ pushToast(
+ "success",
+ fill(t(mode.built_in ? "modes_view.restored" : "modes_view.deleted"), mode.name),
+ );
+ if (draft.slug === mode.slug) setDraft(EMPTY_DRAFT);
} catch (e) {
pushToast("error", (e as Error).message);
}
};
+ const startEditing = (mode: AssistantMode) => {
+ setDraft({
+ slug: mode.slug,
+ name: mode.name,
+ emoji: mode.emoji,
+ description: mode.description,
+ character: mode.character,
+ voice: mode.voice,
+ verbosity: mode.verbosity,
+ proactivity: mode.proactivity,
+ });
+ // The form is below the fold on most screens; an "Edit" that visibly does
+ // nothing reads as broken.
+ formRef.current?.scrollIntoView?.({ behavior: "smooth", block: "start" });
+ };
+
+ const editing = draft.slug ? modes.find((m) => m.slug === draft.slug) ?? null : null;
+
const create = async () => {
if (!draft.name.trim() || !draft.character.trim()) {
- pushToast("warning", "A mode needs a name and a description of how it behaves.");
+ pushToast("warning", t("modes_view.needs_name"));
return;
}
setSaving(true);
try {
setState(await saveMode(draft));
- pushToast("success", `${draft.name} saved.`);
+ pushToast("success", fill(t("modes_view.saved"), draft.name));
+ if (draft.slug) setViewing(draft.slug);
setDraft(EMPTY_DRAFT);
} catch (e) {
pushToast("error", (e as Error).message);
@@ -157,7 +240,7 @@ export function ModesView() {
const startInterview = async () => {
// Ending a call needs no brief — only the opening of one does.
- if (!voiceLive) pushToast("info", "Say what kind of assistant you want. I'll ask the rest.");
+ if (!voiceLive) pushToast("info", t("modes_view.interview_toast"));
await toggleCall();
};
@@ -166,7 +249,7 @@ export function ModesView() {
if (!text) return;
const sent = await sendChatMessage(`${INTERVIEW_BRIEF}\n\nTo start: ${text}`);
if (!sent) {
- pushToast("error", "The chat connection is not up yet.");
+ pushToast("error", t("modes_view.chat_not_up"));
return;
}
setWritten("");
@@ -175,12 +258,15 @@ export function ModesView() {
setActiveSection("chats");
};
+ const fieldClass =
+ "rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary";
+
return (
<div className="flex h-full flex-col overflow-y-auto">
<ViewHeader
icon={<Sparkles className="h-4 w-4 text-muted-foreground" />}
- title="Modes"
- subtitle="How the assistant behaves. Applies to voice and chat from the next turn."
+ title={t("modes_view.title")}
+ subtitle={t("modes_view.subtitle")}
/>
{loading ? (
@@ -190,85 +276,147 @@ export function ModesView() {
) : (
<div className="flex flex-col gap-8 px-6 py-6">
{override && (
- <p className="rounded-lg border border-border bg-secondary/40 px-4 py-3 text-sm text-muted-foreground">
- The <span className="font-medium text-foreground">{override}</span> mode is in force
- while that section is open. Your own choice comes back when you leave it.
+ <p
+ data-testid="mode-override-banner"
+ className="rounded-lg border border-border bg-secondary/40 px-4 py-3 text-sm text-muted-foreground"
+ >
+ {fill(t("modes_view.override_banner"), nameOf(override), nameOf(chosen))}
</p>
)}
<section className="flex flex-col gap-3">
- <h3 className="font-display text-sm font-semibold tracking-tight">Your modes</h3>
+ <div>
+ <h3 className="font-display text-sm font-semibold tracking-tight">
+ {t("modes_view.shelf_title")}
+ </h3>
+ <p className="mt-1 text-sm text-muted-foreground">{t("modes_view.shelf_hint")}</p>
+ </div>
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{modes.map((mode) => {
- const isActive = mode.slug === state?.active;
+ const isActive = mode.slug === active;
+ const isChosen = mode.slug === chosen && !isActive;
+ const isShown = shown?.slug === mode.slug;
return (
<button
key={mode.slug}
type="button"
- onClick={() => void choose(mode.slug)}
- disabled={switching !== ""}
- aria-pressed={isActive}
+ onClick={() => setViewing(mode.slug)}
+ aria-pressed={isShown}
data-testid={`mode-card-${mode.slug}`}
+ data-active={isActive || undefined}
className={cn(
"group relative flex flex-col gap-2 rounded-xl border p-4 text-left transition-colors",
isActive
? "border-primary bg-primary/10"
- : "border-border bg-secondary/30 hover:bg-secondary/60",
+ : isChosen
+ ? "border-dashed border-primary/60 bg-secondary/30 hover:bg-secondary/60"
+ : "border-border bg-secondary/30 hover:bg-secondary/60",
+ isShown && "ring-2 ring-primary/50",
)}
>
- <div className="flex items-center gap-2">
+ <div className="flex items-center gap-2 pr-6">
<span className="text-lg leading-none">{mode.emoji || "•"}</span>
<span className="font-medium">{mode.name}</span>
- {isActive && <Check className="ml-auto h-4 w-4 text-primary" />}
- {switching === mode.slug && (
- <Loader2 className="ml-auto h-4 w-4 animate-spin text-muted-foreground" />
- )}
</div>
<p className="text-sm text-muted-foreground">{mode.description}</p>
<div className="mt-1 flex items-center gap-2 text-xs text-muted-foreground">
- <span>{VERBOSITY_LABELS[mode.verbosity]}</span>
+ <span>{t(VERBOSITY_KEYS[mode.verbosity])}</span>
<span aria-hidden>·</span>
- <span>{PROACTIVITY_LABELS[mode.proactivity]}</span>
+ <span>{t(PROACTIVITY_KEYS[mode.proactivity])}</span>
+ <span className="ml-auto">
+ {isActive ? (
+ <span className="flex items-center gap-1 font-medium text-primary">
+ <Check className="h-3.5 w-3.5" />
+ {t("modes_view.in_use")}
+ </span>
+ ) : switching === mode.slug ? (
+ <Loader2 className="h-3.5 w-3.5 animate-spin" />
+ ) : (
+ <span
+ role="button"
+ tabIndex={0}
+ data-testid={`mode-use-${mode.slug}`}
+ aria-label={fill(t("modes_view.use_named"), mode.name)}
+ onClick={(e) => {
+ e.stopPropagation();
+ if (!switching) void choose(mode);
+ }}
+ onKeyDown={(e) => {
+ if (e.key !== "Enter" && e.key !== " ") return;
+ e.stopPropagation();
+ e.preventDefault();
+ if (!switching) void choose(mode);
+ }}
+ className={cn(
+ "rounded-md border px-2 py-0.5 font-medium transition-colors",
+ isChosen
+ ? "border-primary/60 text-primary"
+ : "border-border text-foreground hover:border-primary hover:bg-primary hover:text-primary-foreground",
+ )}
+ >
+ {isChosen ? t("modes_view.your_choice") : t("modes_view.use")}
+ </span>
+ )}
+ </span>
</div>
{/*
Built-ins offer "restore", user modes offer "delete" — the
same button position, because to the user both mean "undo
- what I did to this card".
+ what I did to this card". Hidden until hover here; the open
+ panel below shows the same action in plain sight.
*/}
- <span
- role="button"
- tabIndex={0}
- aria-label={mode.built_in ? `Restore ${mode.name}` : `Delete ${mode.name}`}
- onClick={(e) => {
- e.stopPropagation();
- void remove(mode);
- }}
- onKeyDown={(e) => {
- if (e.key !== "Enter" && e.key !== " ") return;
- e.stopPropagation();
- e.preventDefault();
- void remove(mode);
- }}
- className="absolute right-3 top-3 hidden rounded p-1 text-muted-foreground hover:bg-destructive/20 hover:text-destructive group-hover:block"
- >
- {mode.built_in ? (
- <RotateCcw className="h-3.5 w-3.5" />
- ) : (
- <Trash2 className="h-3.5 w-3.5" />
- )}
- </span>
+ {(mode.built_in ? mode.edited : true) && (
+ <span
+ role="button"
+ tabIndex={0}
+ aria-label={fill(
+ t(mode.built_in ? "modes_view.restore_named" : "modes_view.delete_named"),
+ mode.name,
+ )}
+ onClick={(e) => {
+ e.stopPropagation();
+ void remove(mode);
+ }}
+ onKeyDown={(e) => {
+ if (e.key !== "Enter" && e.key !== " ") return;
+ e.stopPropagation();
+ e.preventDefault();
+ void remove(mode);
+ }}
+ className="absolute right-3 top-3 hidden rounded p-1 text-muted-foreground hover:bg-destructive/20 hover:text-destructive group-hover:block"
+ >
+ {mode.built_in ? (
+ <RotateCcw className="h-3.5 w-3.5" />
+ ) : (
+ <Trash2 className="h-3.5 w-3.5" />
+ )}
+ </span>
+ )}
</button>
);
})}
</div>
+
+ {shown && (
+ <ModeDetail
+ mode={shown}
+ isActive={shown.slug === active}
+ isChosen={shown.slug === chosen}
+ overrideName={override ? nameOf(override) : ""}
+ switching={switching === shown.slug}
+ onUse={() => void choose(shown)}
+ onEdit={() => startEditing(shown)}
+ onRemove={() => void remove(shown)}
+ />
+ )}
</section>
- <section className="flex flex-col gap-4">
+ <section className="flex flex-col gap-4" ref={formRef}>
<div>
- <h3 className="font-display text-sm font-semibold tracking-tight">Build a mode</h3>
- <p className="mt-1 text-sm text-muted-foreground">
- Describe the assistant you want and let it write the mode, or fill it in yourself.
- </p>
+ <h3 className="font-display text-sm font-semibold tracking-tight">
+ {t("modes_view.build_title")}
+ </h3>
+ <p className="mt-1 text-sm text-muted-foreground">{t("modes_view.build_subtitle")}</p>
</div>
<div className="grid gap-4 lg:grid-cols-2">
@@ -293,25 +441,23 @@ export function ModesView() {
) : (
<Mic className="h-4 w-4" />
)}
- {voiceLive ? "End the conversation" : "Talk it through"}
+ {voiceLive ? t("modes_view.interview_end") : t("modes_view.interview_start")}
</button>
<p className="text-sm text-muted-foreground">
- {voiceLive
- ? "Listening. Describe the assistant you want — it will ask the rest and save the mode when you agree."
- : "Opens a voice conversation. It interviews you, then writes the mode itself."}
+ {voiceLive ? t("modes_view.interview_live") : t("modes_view.interview_idle")}
</p>
<div className="mt-2 flex flex-col gap-2 border-t border-border pt-3">
<label className="text-xs font-medium text-muted-foreground" htmlFor="mode-written">
- Rather type it?
+ {t("modes_view.rather_type")}
</label>
<textarea
id="mode-written"
value={written}
onChange={(e) => setWritten(e.target.value)}
rows={3}
- placeholder="A version of you that is blunt and never softens bad news…"
- className="resize-none rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary"
+ placeholder={t("modes_view.written_placeholder")}
+ className={cn(fieldClass, "resize-none")}
/>
<button
type="button"
@@ -319,70 +465,95 @@ export function ModesView() {
disabled={!written.trim()}
className="self-start rounded-lg border border-border px-3 py-1.5 text-sm hover:bg-secondary/60 disabled:opacity-50"
>
- Ask in chat
+ {t("modes_view.ask_in_chat")}
</button>
</div>
</div>
- <div className="flex flex-col gap-3 rounded-xl border border-border bg-secondary/30 p-4">
+ <div
+ className={cn(
+ "flex flex-col gap-3 rounded-xl border bg-secondary/30 p-4",
+ editing ? "border-primary/60" : "border-border",
+ )}
+ data-testid="mode-form"
+ >
+ {editing && (
+ <div className="flex items-start justify-between gap-3 rounded-lg bg-primary/10 px-3 py-2 text-sm">
+ <div>
+ <div className="font-medium">
+ {fill(t("modes_view.editing_title"), editing.name)}
+ </div>
+ <div className="text-xs text-muted-foreground">
+ {t(
+ editing.built_in
+ ? "modes_view.editing_hint_builtin"
+ : "modes_view.editing_hint",
+ )}
+ </div>
+ </div>
+ <button
+ type="button"
+ onClick={() => setDraft(EMPTY_DRAFT)}
+ aria-label={t("modes_view.cancel_edit")}
+ title={t("modes_view.cancel_edit")}
+ className="rounded p-1 text-muted-foreground hover:bg-secondary hover:text-foreground"
+ >
+ <X className="h-4 w-4" />
+ </button>
+ </div>
+ )}
<div className="flex gap-2">
<input
- aria-label="Emoji"
+ aria-label={t("modes_view.emoji_label")}
value={draft.emoji}
onChange={(e) => setDraft({ ...draft, emoji: e.target.value })}
placeholder="🦉"
- className="w-16 rounded-lg border border-border bg-background px-3 py-2 text-center text-sm outline-none focus:border-primary"
+ className={cn(fieldClass, "w-16 text-center")}
/>
<input
- aria-label="Mode name"
+ aria-label={t("modes_view.name_label")}
value={draft.name}
onChange={(e) => setDraft({ ...draft, name: e.target.value })}
- placeholder="Night Owl"
- className="flex-1 rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary"
+ placeholder={t("modes_view.name_placeholder")}
+ className={cn(fieldClass, "flex-1")}
/>
</div>
<input
- aria-label="One-line description"
+ aria-label={t("modes_view.description_label")}
value={draft.description}
onChange={(e) => setDraft({ ...draft, description: e.target.value })}
- placeholder="Quiet and short. Refuses to start new work late."
- className="rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary"
+ placeholder={t("modes_view.description_placeholder")}
+ className={fieldClass}
/>
<textarea
- aria-label="How it behaves"
+ aria-label={t("modes_view.character_label")}
value={draft.character}
onChange={(e) => setDraft({ ...draft, character: e.target.value })}
- rows={5}
- placeholder="Speak quietly. It is late and I am winding down…"
- className="resize-none rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary"
+ rows={editing ? 12 : 5}
+ placeholder={t("modes_view.character_placeholder")}
+ className={cn(fieldClass, "resize-y")}
/>
<div className="flex flex-wrap gap-2">
- <select
- aria-label="Answer length"
+ <BrandedSelect
+ ariaLabel={t("modes_view.length_label")}
value={draft.verbosity}
- onChange={(e) => setDraft({ ...draft, verbosity: e.target.value as Verbosity })}
- className="rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary"
- >
- {(state?.verbosities ?? []).map((v) => (
- <option key={v} value={v}>
- {VERBOSITY_LABELS[v]}
- </option>
- ))}
- </select>
- <select
- aria-label="How much it volunteers"
+ onValueChange={(v) => setDraft({ ...draft, verbosity: v as Verbosity })}
+ className="min-w-[180px]"
+ options={(state?.verbosities ?? []).map((v) => ({
+ value: v,
+ label: t(VERBOSITY_KEYS[v]),
+ }))}
+ />
+ <BrandedSelect
+ ariaLabel={t("modes_view.volunteers_label")}
value={draft.proactivity}
- onChange={(e) =>
- setDraft({ ...draft, proactivity: e.target.value as Proactivity })
- }
- className="rounded-lg border border-border bg-background px-3 py-2 text-sm outline-none focus:border-primary"
- >
- {(state?.proactivities ?? []).map((p) => (
- <option key={p} value={p}>
- {PROACTIVITY_LABELS[p]}
- </option>
- ))}
- </select>
+ onValueChange={(p) => setDraft({ ...draft, proactivity: p as Proactivity })}
+ className="min-w-[220px]"
+ options={(state?.proactivities ?? []).map((p) => ({
+ value: p,
+ label: t(PROACTIVITY_KEYS[p]),
+ }))}
+ />
</div>
<button
type="button"
@@ -393,10 +564,12 @@ export function ModesView() {
>
{saving ? (
<Loader2 className="h-4 w-4 animate-spin" />
+ ) : editing ? (
+ <Pencil className="h-4 w-4" />
) : (
<Plus className="h-4 w-4" />
)}
- Save mode
+ {editing ? t("modes_view.save_changes") : t("modes_view.save_mode")}
</button>
</div>
</div>
@@ -406,3 +579,179 @@ export function ModesView() {
</div>
);
}
+
+interface ModeDetailProps {
+ mode: AssistantMode;
+ isActive: boolean;
+ isChosen: boolean;
+ /** Name of the mode a section is holding in force, or "" when none is. */
+ overrideName: string;
+ switching: boolean;
+ onUse: () => void;
+ onEdit: () => void;
+ onRemove: () => void;
+}
+
+/**
+ * The open card: everything a mode does, in plain sight.
+ *
+ * The full character text is the point — it is what the assistant actually
+ * reads — so it gets the room, verbatim and unabridged. The empty character of
+ * the default mode is stated as such rather than shown as a blank box, because
+ * "adds nothing" is a fact about that mode, not a missing value.
+ */
+function ModeDetail({
+ mode,
+ isActive,
+ isChosen,
+ overrideName,
+ switching,
+ onUse,
+ onEdit,
+ onRemove,
+}: ModeDetailProps) {
+ const t = useT();
+ const buttonClass =
+ "flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-sm transition-colors disabled:opacity-60";
+ return (
+ <div
+ data-testid="mode-detail"
+ className="mt-2 flex flex-col gap-4 rounded-xl border border-border bg-secondary/20 p-5"
+ >
+ <div className="flex flex-wrap items-start justify-between gap-3">
+ <div className="flex min-w-0 items-start gap-3">
+ <span className="text-2xl leading-none">{mode.emoji || "•"}</span>
+ <div className="min-w-0">
+ <div className="flex flex-wrap items-center gap-2">
+ <h4 className="font-display text-base font-semibold tracking-tight">{mode.name}</h4>
+ <span className="rounded-md border border-border px-1.5 py-0.5 text-[11px] text-muted-foreground">
+ {mode.built_in
+ ? mode.edited
+ ? t("modes_view.badge_builtin_edited")
+ : t("modes_view.badge_builtin")
+ : t("modes_view.badge_yours")}
+ </span>
+ {isActive && (
+ <span className="flex items-center gap-1 rounded-md bg-primary/15 px-1.5 py-0.5 text-[11px] font-medium text-primary">
+ <Check className="h-3 w-3" />
+ {t("modes_view.in_use")}
+ </span>
+ )}
+ {!isActive && isChosen && (
+ <span className="rounded-md border border-primary/60 px-1.5 py-0.5 text-[11px] font-medium text-primary">
+ {t("modes_view.your_choice")}
+ </span>
+ )}
+ </div>
+ {mode.description && (
+ <p className="mt-1 text-sm text-muted-foreground">{mode.description}</p>
+ )}
+ </div>
+ </div>
+ <div className="flex flex-wrap items-center gap-2">
+ <button
+ type="button"
+ onClick={onUse}
+ disabled={isActive || switching}
+ data-testid="mode-detail-use"
+ className={cn(
+ buttonClass,
+ isActive
+ ? "border-primary/40 text-primary"
+ : "border-primary bg-primary text-primary-foreground hover:opacity-90",
+ )}
+ >
+ {switching ? (
+ <Loader2 className="h-4 w-4 animate-spin" />
+ ) : (
+ <Check className="h-4 w-4" />
+ )}
+ {isActive ? t("modes_view.in_use_now") : t("modes_view.use_this_mode")}
+ </button>
+ <button
+ type="button"
+ onClick={onEdit}
+ data-testid="mode-detail-edit"
+ className={cn(buttonClass, "border-border hover:bg-secondary/60")}
+ >
+ <Pencil className="h-4 w-4" />
+ {t("modes_view.edit")}
+ </button>
+ {(mode.built_in ? mode.edited : true) && (
+ <button
+ type="button"
+ onClick={onRemove}
+ data-testid="mode-detail-remove"
+ className={cn(
+ buttonClass,
+ "border-border text-muted-foreground hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive",
+ )}
+ >
+ {mode.built_in ? (
+ <RotateCcw className="h-4 w-4" />
+ ) : (
+ <Trash2 className="h-4 w-4" />
+ )}
+ {mode.built_in ? t("modes_view.restore_original") : t("modes_view.delete")}
+ </button>
+ )}
+ </div>
+ </div>
+
+ {!isActive && isChosen && overrideName && (
+ <p className="text-sm text-muted-foreground">
+ {fill(t("modes_view.detail_waiting"), overrideName)}
+ </p>
+ )}
+
+ <div className="grid gap-4 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]">
+ <div className="flex flex-col gap-2">
+ <h5 className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
+ {t("modes_view.detail_behaviour")}
+ </h5>
+ {mode.character ? (
+ <pre
+ data-testid="mode-detail-character"
+ className="max-h-[28rem] overflow-y-auto whitespace-pre-wrap break-words rounded-lg border border-border bg-background/60 p-4 font-sans text-sm leading-relaxed text-foreground"
+ >
+ {mode.character}
+ </pre>
+ ) : (
+ <p
+ data-testid="mode-detail-character"
+ className="rounded-lg border border-dashed border-border p-4 text-sm text-muted-foreground"
+ >
+ {t("modes_view.detail_empty_character")}
+ </p>
+ )}
+ </div>
+ <dl className="flex flex-col gap-3 text-sm">
+ <div>
+ <dt className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
+ {t("modes_view.length_label")}
+ </dt>
+ <dd className="mt-0.5">{t(VERBOSITY_KEYS[mode.verbosity])}</dd>
+ </div>
+ <div>
+ <dt className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
+ {t("modes_view.volunteers_label")}
+ </dt>
+ <dd className="mt-0.5">{t(PROACTIVITY_KEYS[mode.proactivity])}</dd>
+ </div>
+ <div>
+ <dt className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
+ {t("modes_view.detail_voice")}
+ </dt>
+ <dd className="mt-0.5">{mode.voice || t("modes_view.detail_voice_default")}</dd>
+ </div>
+ <div>
+ <dt className="text-xs font-medium uppercase tracking-wider text-muted-foreground">
+ {t("modes_view.detail_id")}
+ </dt>
+ <dd className="mt-0.5 font-mono text-xs text-muted-foreground">{mode.slug}</dd>
+ </div>
+ </dl>
+ </div>
+ </div>
+ );
+}