Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Windows/Linux: shortcut logic and what the island does with them

Claude23635500c892
diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.ts
index 24aaf55f..d1eda669 100644
--- a/windows/src/core/bridge.ts
+++ b/windows/src/core/bridge.ts
@@ -99,8 +99,26 @@ export const Bridge = {
/** Tray → Pause. Stops the integration pollers, not just the island. */
setPaused: (paused: boolean) => call<void>("set_paused", { paused }),
+
+ // ── Global shortcuts ──────────────────────────────────────────────────────
+ /** How each global shortcut went when Rust last registered them. */
+ shortcutsStatus: () => call<ShortcutsReport>("shortcuts_status"),
+ /** Lets go of every global shortcut while Settings records a new one. */
+ shortcutsSuspend: (suspended: boolean) => call<void>("shortcuts_suspend", { suspended }),
};
+export type ShortcutStatus =
+ | "active" | "off" | "inUse" | "duplicate" | "invalid"
+ | "typesCharacter" | "unsupported" | "notPorted";
+
+export interface ShortcutsReport {
+ actions: { id: string; status: ShortcutStatus; typed?: string }[];
+ /** "wayland" or "no-display" when no global shortcut can be registered. */
+ blocked: string | null;
+ /** `<executable> --shortcut`: append an action id for a desktop shortcut. */
+ command: string;
+}
+
export interface IntegrationUpdate {
id: string;
data: Record<string, unknown>;
diff --git a/windows/src/core/shortcuts.ts b/windows/src/core/shortcuts.ts
new file mode 100644
index 00000000..25216f88
--- /dev/null
+++ b/windows/src/core/shortcuts.ts
@@ -0,0 +1,388 @@
+// Keyboard shortcuts — the pure part, port of ShortcutLogic.swift.
+//
+// Global shortcuts are registered by Rust (src-tauri/src/shortcuts.rs), which
+// owns the same table of defaults; tests/shortcuts.test.mjs keeps the two in
+// step. This file parses and formats accelerators, turns a key press into one
+// (the recorder in Settings), spots duplicates, and maps the keys pressed
+// inside the open island to what they do.
+//
+// Why Ctrl+Alt+Space / A / T / S / G / ← → rather than the Mac's letters: see
+// the top of src-tauri/src/shortcuts.rs. In short, Windows reads Ctrl+Alt as
+// AltGr, and AltGr+E, Q, M, W, C, the digits and most punctuation type a
+// character on at least one of the French, German, Spanish, Italian,
+// Portuguese or Brazilian layouts (ALTGR_CHARACTERS below).
+
+// ── Strings shown to the user ─────────────────────────────────────────────────
+
+export const SHORTCUT_TEXT = {
+ toggleIsland: "Open or close the island",
+ openChat: "Open the chat",
+ goToAlert: "Go to the waiting permission or question",
+ jumpToTerminal: "Open the terminal",
+ attachFrontWindow: "Attach the front window to the chat",
+ nextPill: "Next pill",
+ prevPill: "Previous pill",
+ muteToggle: "Mute or unmute Mochi",
+ desktopToggle: "Send Mochi to the desktop",
+ wardrobeToggle: "Open the wardrobe",
+ island: {
+ nextPrev: "Next or previous pill",
+ byNumber: "Go to pill 1 to 9",
+ send: "Send the message",
+ newChat: "Start a new chat",
+ settings: "Open Settings",
+ pin: "Keep the island open",
+ close: "Close the island",
+ },
+} as const;
+
+// ── Actions ───────────────────────────────────────────────────────────────────
+
+/** Mac `ShortcutAction` raw values. Stored in settings.json: never rename one. */
+export type ShortcutId =
+ | "toggleIsland"
+ | "openChat"
+ | "goToAlert"
+ | "jumpToTerminal"
+ | "attachFrontWindow"
+ | "nextPill"
+ | "prevPill"
+ | "muteToggle"
+ | "desktopToggle"
+ | "wardrobeToggle";
+
+export interface ShortcutDef {
+ id: ShortcutId;
+ defaultKeys: string;
+ enabledByDefault: boolean;
+ /** False for the Mac actions this version can't do yet: reserved, never registered. */
+ ported: boolean;
+}
+
+const def = (id: ShortcutId, defaultKeys: string, enabledByDefault: boolean, ported: boolean): ShortcutDef =>
+ ({ id, defaultKeys, enabledByDefault, ported });
+
+/** Same order and defaults as ACTIONS in src-tauri/src/shortcuts.rs. */
+export const SHORTCUTS: readonly ShortcutDef[] = [
+ def("toggleIsland", "Ctrl+Alt+N", false, true),
+ def("openChat", "Ctrl+Alt+Space", true, true),
+ def("goToAlert", "Ctrl+Alt+A", true, true),
+ def("jumpToTerminal", "Ctrl+Alt+T", true, true),
+ def("attachFrontWindow", "Ctrl+Alt+F", true, false),
+ def("nextPill", "Ctrl+Alt+Right", true, true),
+ def("prevPill", "Ctrl+Alt+Left", true, true),
+ def("muteToggle", "Ctrl+Alt+S", true, true),
+ def("desktopToggle", "Ctrl+Alt+D", true, false),
+ def("wardrobeToggle", "Ctrl+Alt+G", true, true),
+];
+
+export interface Binding {
+ /** Canonical accelerator, e.g. "Ctrl+Alt+Space"; empty for no key. */
+ keys: string;
+ enabled: boolean;
+}
+
+/** `settings.shortcuts`: only the actions the user changed. */
+export type Bindings = Record<string, Binding>;
+
+/** The binding in force: what the user stored, or the default. */
+export function effective(d: ShortcutDef, stored: Bindings | undefined): Binding {
+ const own = stored?.[d.id];
+ return own ? { keys: own.keys, enabled: own.enabled } : { keys: d.defaultKeys, enabled: d.enabledByDefault };
+}
+
+// ── Accelerators ──────────────────────────────────────────────────────────────
+
+export interface Combo {
+ ctrl: boolean;
+ alt: boolean;
+ shift: boolean;
+ /** The Windows key / Super. */
+ meta: boolean;
+ /** Canonical key name (see KEY_NAMES). */
+ key: string;
+}
+
+const PUNCTUATION: Record<string, string> = {
+ Comma: ",", Period: ".", Slash: "/", Semicolon: ";", Quote: "'", Backquote: "`",
+ BracketLeft: "[", BracketRight: "]", Backslash: "\\", Minus: "-", Equal: "=",
+};
+
+const NAMED = [
+ "Space", "Enter", "Tab", "Backspace", "Delete", "Insert", "Home", "End",
+ "PageUp", "PageDown", "Up", "Down", "Left", "Right",
+];
+
+/** Every main key an accelerator may name — all of them parse in Rust too. */
+export const KEY_NAMES: readonly string[] = [
+ ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ ...Array.from({ length: 24 }, (_, i) => `F${i + 1}`),
+ ...NAMED,
+ ...Object.keys(PUNCTUATION),
+];
+
+const KEY_ALIASES: Record<string, string> = {
+ ARROWUP: "Up", ARROWDOWN: "Down", ARROWLEFT: "Left", ARROWRIGHT: "Right",
+ RETURN: "Enter", ESC: "Escape", DEL: "Delete", " ": "Space",
+ ...Object.fromEntries(Object.entries(PUNCTUATION).map(([name, ch]) => [ch, name])),
+};
+
+function canonicalKey(token: string): string | null {
+ const up = token.toUpperCase();
+ if (KEY_ALIASES[token]) return KEY_ALIASES[token];
+ if (KEY_ALIASES[up]) return KEY_ALIASES[up];
+ if (/^KEY[A-Z]$/.test(up)) return up.slice(3);
+ if (/^DIGIT[0-9]$/.test(up)) return up.slice(5);
+ return KEY_NAMES.find((k) => k.toUpperCase() === up) ?? null;
+}
+
+/**
+ * "Ctrl+Alt+Space" → a Combo. Accepts the spellings Rust accepts (Control,
+ * Option, Super/Cmd, ArrowLeft…). `null` for anything else, and for a bare key:
+ * a global shortcut always needs Ctrl, Alt or the Windows key.
+ */
+export function parseKeys(text: string): Combo | null {
+ if (!text.trim()) return null;
+ // "Ctrl+Alt++" doesn't happen: the plus key is spelled Equal.
+ const tokens = text.split("+").map((t) => t.trim());
+ if (tokens.some((t) => !t)) return null;
+ const combo: Combo = { ctrl: false, alt: false, shift: false, meta: false, key: "" };
+ for (const [i, token] of tokens.entries()) {
+ const last = i === tokens.length - 1;
+ switch (token.toUpperCase()) {
+ case "CTRL": case "CONTROL": case "COMMANDORCONTROL": case "CMDORCTRL":
+ if (last) return null;
+ combo.ctrl = true;
+ continue;
+ case "ALT": case "OPTION":
+ if (last) return null;
+ combo.alt = true;
+ continue;
+ case "SHIFT":
+ if (last) return null;
+ combo.shift = true;
+ continue;
+ case "SUPER": case "META": case "WIN": case "CMD": case "COMMAND":
+ if (last) return null;
+ combo.meta = true;
+ continue;
+ }
+ if (!last) return null;
+ const key = canonicalKey(token);
+ if (!key || key === "Escape") return null;
+ combo.key = key;
+ }
+ if (!combo.key || !(combo.ctrl || combo.alt || combo.meta)) return null;
+ return combo;
+}
+
+/** Combo → "Ctrl+Alt+Shift+Super+Key", the form stored and handed to Rust. */
+export function formatKeys(c: Combo): string {
+ const parts: string[] = [];
+ if (c.ctrl) parts.push("Ctrl");
+ if (c.alt) parts.push("Alt");
+ if (c.shift) parts.push("Shift");
+ if (c.meta) parts.push("Super");
+ parts.push(c.key);
+ return parts.join("+");
+}
+
+/** Canonical form of an accelerator, or null when it isn't one. */
+export function normalizeKeys(text: string): string | null {
+ const c = parseKeys(text);
+ return c ? formatKeys(c) : null;
+}
+
+const KEY_GLYPHS: Record<string, string> = { Up: "↑", Down: "↓", Left: "←", Right: "→", ...PUNCTUATION };
+
+/** What a person reads: "Ctrl+Alt+→", "Ctrl+Shift+K", "Win+Space". */
+export function displayKeys(text: string): string {
+ const c = parseKeys(text);
+ if (!c) return text.trim() ? text : "—";
+ const parts: string[] = [];
+ if (c.ctrl) parts.push("Ctrl");
+ if (c.alt) parts.push("Alt");
+ if (c.shift) parts.push("Shift");
+ if (c.meta) parts.push("Win");
+ parts.push(KEY_GLYPHS[c.key] ?? c.key);
+ return parts.join("+");
+}
+
+// ── Recording a key press ─────────────────────────────────────────────────────
+
+/** The parts of a KeyboardEvent the recorder reads. */
+export interface KeyPress {
+ key: string;
+ code: string;
+ ctrlKey: boolean;
+ altKey: boolean;
+ shiftKey: boolean;
+ metaKey: boolean;
+}
+
+export type Recorded =
+ /** Only modifiers so far: keep listening. */
+ | { kind: "pending" }
+ | { kind: "cancel" }
+ | { kind: "clear" }
+ | { kind: "keys"; keys: string }
+ /** Needs Ctrl, Alt or the Windows key. */
+ | { kind: "needsModifier" }
+ /** On this keyboard, Ctrl+Alt+key is AltGr and types `typed`. */
+ | { kind: "typesCharacter"; typed: string; keys: string }
+ | { kind: "unsupported" };
+
+const MODIFIER_KEYS = new Set(["Control", "Alt", "Shift", "Meta", "AltGraph", "OS", "Super", "Hyper"]);
+
+/** The main key of a press, by name. Letters follow the layout, so Ctrl+Alt+A
+ * is the key labelled A on AZERTY too — which is what RegisterHotKey and X11
+ * grab. Everything else goes by its position. */
+function pressedKey(e: KeyPress): string | null {
+ if (/^[a-z]$/i.test(e.key)) return e.key.toUpperCase();
+ if (/^Key[A-Z]$/.test(e.code)) return e.code.slice(3);
+ if (/^Digit[0-9]$/.test(e.code)) return e.code.slice(5);
+ if (/^Arrow(Up|Down|Left|Right)$/.test(e.code)) return e.code.slice(5);
+ if (/^F([1-9]|1[0-9]|2[0-4])$/.test(e.code)) return e.code;
+ if (NAMED.includes(e.code) || e.code in PUNCTUATION) return e.code;
+ if (e.code === "NumpadEnter") return "Enter";
+ return null;
+}
+
+/** Turns a key press in the recorder into what to do with it. */
+export function recordPress(e: KeyPress): Recorded {
+ if (MODIFIER_KEYS.has(e.key)) return { kind: "pending" };
+ const bare = !e.ctrlKey && !e.altKey && !e.metaKey && !e.shiftKey;
+ if (e.key === "Escape" && bare) return { kind: "cancel" };
+ if ((e.key === "Backspace" || e.key === "Delete") && bare) return { kind: "clear" };
+ const key = pressedKey(e);
+ if (!key) return { kind: "unsupported" };
+ if (!(e.ctrlKey || e.altKey || e.metaKey)) return { kind: "needsModifier" };
+ const keys = formatKeys({ ctrl: e.ctrlKey, alt: e.altKey, shift: e.shiftKey, meta: e.metaKey, key });
+ // Ctrl+Alt is AltGr on Windows. When the press typed something other than a
+ // plain letter, digit or space, this combination is how the user types it.
+ if (e.ctrlKey && e.altKey && !e.metaKey) {
+ if (e.key === "Dead") return { kind: "typesCharacter", typed: "´", keys };
+ if ([...e.key].length === 1 && !/^[a-z0-9 ]$/i.test(e.key)) {
+ return { kind: "typesCharacter", typed: e.key, keys };
+ }
+ }
+ return { kind: "keys", keys };
+}
+
+// ── Conflicts ─────────────────────────────────────────────────────────────────
+
+/** Actions whose combination another enabled action also uses. */
+export function duplicates(entries: Iterable<[string, string]>): Set<string> {
+ const seen = new Map<string, string>();
+ const dups = new Set<string>();
+ for (const [id, keys] of entries) {
+ const norm = normalizeKeys(keys);
+ if (!norm) continue;
+ const other = seen.get(norm);
+ if (other != null) {
+ dups.add(id);
+ dups.add(other);
+ } else {
+ seen.set(norm, id);
+ }
+ }
+ return dups;
+}
+
+/** The (id, keys) pairs Coucou would register with `stored`. */
+export function activeKeys(stored: Bindings | undefined): [string, string][] {
+ return SHORTCUTS.filter((d) => d.ported)
+ .map((d) => [d.id, effective(d, stored)] as const)
+ .filter(([, b]) => b.enabled && b.keys)
+ .map(([id, b]) => [id, b.keys]);
+}
+
+/**
+ * What AltGr (= Ctrl+Alt on Windows) types on the keys of the layouts the
+ * defaults were checked against: letters and digits only, the keys a shortcut
+ * is likely to use. Standard Windows layouts.
+ */
+export const ALTGR_CHARACTERS: Record<string, Record<string, string>> = {
+ "French (AZERTY)": {
+ E: "€", "2": "~", "3": "#", "4": "{", "5": "[", "6": "|", "7": "`", "8": "\\", "9": "^", "0": "@",
+ },
+ "German (QWERTZ)": { Q: "@", E: "€", M: "µ", "2": "²", "3": "³", "7": "{", "8": "[", "9": "]", "0": "}" },
+ Spanish: { E: "€", "1": "|", "2": "@", "3": "#", "4": "~", "5": "€", "6": "¬" },
+ Italian: { E: "€", "5": "€" },
+ Portuguese: { E: "€", "2": "@", "3": "£", "4": "§", "5": "€", "7": "{", "8": "[", "9": "]", "0": "}" },
+ "Brazilian (ABNT2)": {
+ Q: "/", W: "?", E: "°", C: "₢", "1": "¹", "2": "²", "3": "³", "4": "£", "5": "¢", "6": "¬",
+ },
+};
+
+/** The layouts on which `keys` would type a character instead of running. */
+export function altGrClashes(keys: string): string[] {
+ const c = parseKeys(keys);
+ if (!c || !c.ctrl || !c.alt || c.meta) return [];
+ return Object.entries(ALTGR_CHARACTERS)
+ .filter(([, chars]) => chars[c.key] != null)
+ .map(([layout]) => layout);
+}
+
+// ── Inside the open island ────────────────────────────────────────────────────
+
+/** Same as ShortcutLogic.navigate: next card-list selection, clamped. */
+export function navigate(selection: number | null, delta: number, itemCount: number): number | null {
+ if (itemCount <= 0) return null;
+ if (selection != null) return Math.max(0, Math.min(itemCount - 1, selection + delta));
+ return delta > 0 ? 0 : itemCount - 1;
+}
+
+/** The pill `delta` steps from `current`, wrapping around (cyclePill). */
+export function cyclePill(ids: readonly string[], current: string | null, delta: number): string | null {
+ if (ids.length === 0) return null;
+ const at = Math.max(0, current == null ? 0 : ids.indexOf(current));
+ return ids[(((at + delta) % ids.length) + ids.length) % ids.length];
+}
+
+/** Pill number `n`, counting from 1 (switchToPill). */
+export function pillByNumber(ids: readonly string[], n: number): string | null {
+ return n >= 1 && n <= ids.length ? ids[n - 1] : null;
+}
+
+/** Shown read-only in Settings, like ShortcutLogic.islandShortcuts. The Mac's
+ * ⌘↑ ⌘↓ ⌘O (card lists) and ⌘E (diff) have no counterpart here yet. */
+export const ISLAND_SHORTCUTS: readonly { keys: string; description: string }[] = [
+ { keys: "Ctrl+→ / Ctrl+←", description: SHORTCUT_TEXT.island.nextPrev },
+ { keys: "Ctrl+1 – Ctrl+9", description: SHORTCUT_TEXT.island.byNumber },
+ { keys: "Ctrl+Enter", description: SHORTCUT_TEXT.island.send },
+ { keys: "Ctrl+K", description: SHORTCUT_TEXT.island.newChat },
+ { keys: "Ctrl+,", description: SHORTCUT_TEXT.island.settings },
+ { keys: "Ctrl+P", description: SHORTCUT_TEXT.island.pin },
+ { keys: "Esc", description: SHORTCUT_TEXT.island.close },
+];
+
+export type IslandKeyAction =
+ | { kind: "cycle"; delta: 1 | -1 }
+ | { kind: "pill"; number: number }
+ | { kind: "newChat" }
+ | { kind: "settings" }
+ | { kind: "pin" };
+
+/**
+ * A key pressed while the island has the keyboard → what it does, or null to
+ * leave it alone. Ctrl stands in for ⌘. In a text field Ctrl+← and Ctrl+→
+ * keep moving by word.
+ */
+export function islandKeyAction(
+ e: KeyPress,
+ ctx: { view: string; inTextField: boolean },
+): IslandKeyAction | null {
+ if (!e.ctrlKey || e.altKey || e.shiftKey || e.metaKey) return null;
+ if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
+ if (ctx.inTextField) return null;
+ return { kind: "cycle", delta: e.key === "ArrowRight" ? 1 : -1 };
+ }
+ const digit = /^Digit([1-9])$/.exec(e.code);
+ if (digit) return { kind: "pill", number: Number(digit[1]) };
+ const letter = /^[a-z]$/i.test(e.key) ? e.key.toLowerCase() : /^Key([A-Z])$/.exec(e.code)?.[1].toLowerCase();
+ if (letter === "k") return ctx.view === "prompt" ? { kind: "newChat" } : null;
+ if (letter === "p") return { kind: "pin" };
+ if (e.key === "," || e.code === "Comma") return { kind: "settings" };
+ return null;
+}
diff --git a/windows/src/core/state.ts b/windows/src/core/state.ts
index 01236b80..d0102ece 100644
--- a/windows/src/core/state.ts
+++ b/windows/src/core/state.ts
@@ -2,6 +2,7 @@
import type { BotEmoteName, BotStateName, IslandMode, IslandViewName } from "./layout";
import type { EyeShape } from "../mochi/engine";
+import type { Bindings } from "./shortcuts";
export type AgentSource = "claudeCode" | "n8n" | "agent";
export type PillBadge = "approval" | "finished" | "error";
@@ -92,6 +93,8 @@ export interface Settings {
hooksInstalled: boolean;
/** Claude model used by the chat. */
model: string;
+ /** Global shortcuts the user changed, by action id (see core/shortcuts.ts). */
+ shortcuts: Bindings;
}
export const DEFAULT_SETTINGS: Settings = {
@@ -106,6 +109,7 @@ export const DEFAULT_SETTINGS: Settings = {
autostart: false,
hooksInstalled: false,
model: "claude-opus-5",
+ shortcuts: {},
};
type Listener = () => void;
diff --git a/windows/src/island/island.ts b/windows/src/island/island.ts
index 7fdb6180..ceafc828 100644
--- a/windows/src/island/island.ts
+++ b/windows/src/island/island.ts
@@ -7,7 +7,7 @@ import {
EXPANDED_CORNER, EXPANDED_W, NOTCH_W, PANEL_H, PANEL_W,
ROUNDED_CORNER, VIEW_LAYOUTS, botGlowColor, botGlowOpacity, botPosition, chatPromptHeight,
islandSize,
- type IslandMode, type IslandViewName,
+ type BotEmoteName, type IslandMode, type IslandViewName,
} from "../core/layout";
import { Sound } from "../core/sound";
import { State } from "../core/state";
@@ -339,6 +339,33 @@ export class Island {
this.fsm.pinned = false;
}
+ // ── Keyboard shortcuts (island/shortcuts.ts) ────────────────────────────────
+
+ emote(name: BotEmoteName) {
+ this.engine.triggerEmote(name);
+ this.ensureRunning();
+ }
+
+ /** Ctrl+P: keep the open island from folding away, or let it fold again. */
+ setPinned(on: boolean) {
+ State.isPinned = on;
+ this.fsm.pinned = on;
+ if (on) {
+ this.fsm.cancelTimers();
+ this.homeCollapseAt = null;
+ } else if (!this.wasInIsland && this.fsm.state === "home") {
+ this.fsm.mouseLeft();
+ this.homeCollapseAt = performance.now() + State.settings.autoCloseInterval * 1000;
+ }
+ State.notify();
+ }
+
+ /** The island takes the keyboard, so its own shortcuts work (Mac: makeKey).
+ * It gives it back when it closes, or when the chat is left. */
+ takeKeyboard() {
+ void Bridge.focusWindow(true);
+ }
+
// ── File drop ───────────────────────────────────────────────────────────────
private onDragDrop(e: { type: string; paths?: string[] }) {
diff --git a/windows/src/island/shortcuts.ts b/windows/src/island/shortcuts.ts
new file mode 100644
index 00000000..e9411a04
--- /dev/null
+++ b/windows/src/island/shortcuts.ts
@@ -0,0 +1,162 @@
+// Keyboard shortcuts → island. Port of IslandWindowController.handleHotKey and
+// handleIslandKey from the macOS app.
+//
+// Global shortcuts are caught by Rust and arrive as a `shortcut` event with
+// the action id (the wardrobe goes out as `open-wardrobe` instead, for the
+// wardrobe view to pick up). The in-island keys are read here, while the
+// island has the keyboard: it takes it for the chat, and when a global
+// shortcut opens it.
+
+import { Bridge, onEvent } from "../core/bridge";
+import type { BotEmoteName, IslandViewName } from "../core/layout";
+import { cyclePill, islandKeyAction, pillByNumber, type IslandKeyAction } from "../core/shortcuts";
+import { Sound } from "../core/sound";
+import { State } from "../core/state";
+
+const CLAUDE_ID = "integration_claude";
+
+/** What the shortcuts need from the island. */
+export interface ShortcutHost {
+ alert(view: IslandViewName): void;
+ setView(view: IslandViewName): void;
+ collapse(): void;
+ emote(name: BotEmoteName): void;
+ setPinned(on: boolean): void;
+ /** Gives the island the keyboard, so the in-island keys work (Mac: makeKey). */
+ takeKeyboard(): void;
+}
+
+function focusPill(host: ShortcutHost, id: string | null, open: boolean) {
+ if (!id) return;
+ State.setFocus(id);
+ Sound.play("blip");
+ if (open) host.alert("overview");
+ else host.setView("overview");
+}
+
+/** A global shortcut was pressed. `resume` lifts Pause, as the tray's Open does. */
+export function runGlobalShortcut(host: ShortcutHost, action: string, resume: () => void) {
+ switch (action) {
+ case "toggleIsland":
+ if (State.mode === "expanded") {
+ host.collapse();
+ } else {
+ resume();
+ host.alert(State.pendingApproval ? "approval" : State.defaultView());
+ host.takeKeyboard();
+ }
+ break;
+
+ case "openChat":
+ resume();
+ host.alert("prompt");
+ break;
+
+ case "goToAlert": {
+ const asking = State.tasks.find((t) => t.state === "question");
+ if (State.pendingApproval) {
+ resume();
+ State.setFocus(CLAUDE_ID);
+ host.alert("approval");
+ host.takeKeyboard();
+ } else if (asking) {
+ resume();
+ State.setFocus(asking.id);
+ host.alert("question");
+ host.takeKeyboard();
+ } else {
+ // Nothing is waiting: Mochi says so.
+ host.emote("annoyed");
+ Sound.play("error");
+ }
+ break;
+ }
+
+ // The Mac brings the terminal app forward; here it is the existing "Open
+ // terminal": the session's folder in VS Code.
+ case "jumpToTerminal":
+ void Bridge.openInVSCode(State.focusTask?.sessionCwd ?? null);
+ if (State.mode === "expanded") host.collapse();
+ break;
+
+ case "nextPill":
+ case "prevPill":
+ resume();
+ focusPill(
+ host,
+ cyclePill(State.tasks.map((t) => t.id), State.focusTask?.id ?? null, action === "nextPill" ? 1 : -1),
+ true,
+ );
+ break;
+
+ case "muteToggle": {
+ const on = !State.settings.soundEnabled;
+ State.settings.soundEnabled = on;
+ Sound.setEnabled(on);
+ void Bridge.saveSettings(State.settings);
+ if (on) Sound.play("tick");
+ host.emote(on ? "happy" : "annoyed");
+ State.notify();
+ break;
+ }
+
+ // wardrobeToggle never comes this way (Rust sends `open-wardrobe`), and
+ // attachFrontWindow / desktopToggle aren't in this version.
+ default:
+ break;
+ }
+}
+
+/** A key the island acts on while it has the keyboard. */
+export function runIslandKey(host: ShortcutHost, action: IslandKeyAction) {
+ const ids = State.tasks.map((t) => t.id);
+ switch (action.kind) {
+ case "cycle":
+ focusPill(host, cyclePill(ids, State.focusTask?.id ?? null, action.delta), false);
+ break;
+ case "pill":
+ focusPill(host, pillByNumber(ids, action.number), false);
+ break;
+ case "newChat":
+ // Not while an answer is on its way: it would land in the new chat.
+ if (State.stateOverride === "thinking") return;
+ State.chatHistory = [];
+ State.droppedFile = null;
+ State.promptContext = null;
+ void Bridge.chatReset();
+ Sound.play("blip");
+ host.setView("prompt");
+ break;
+ case "settings":
+ void Bridge.openSettingsWindow();
+ break;
+ case "pin":
+ // A permission card keeps the island pinned until it is answered.
+ if (State.pendingApproval) return;
+ host.setPinned(!State.isPinned);
+ break;
+ }
+}
+
+function inTextField(target: EventTarget | null): boolean {
+ const el = target as { tagName?: string; isContentEditable?: boolean } | null;
+ return el?.tagName === "INPUT" || el?.tagName === "TEXTAREA" || el?.isContentEditable === true;
+}
+
+export function registerShortcutHandlers(host: ShortcutHost, resume: () => void) {
+ void onEvent<string>("shortcut", (action) => runGlobalShortcut(host, action, resume));
+
+ // Capture phase: the chat field stops its own key events from bubbling.
+ window.addEventListener(
+ "keydown",
+ (e: KeyboardEvent) => {
+ if (State.mode !== "expanded") return;
+ const action = islandKeyAction(e, { view: State.view, inTextField: inTextField(e.target) });
+ if (!action) return;
+ e.preventDefault();
+ e.stopPropagation();
+ runIslandKey(host, action);
+ },
+ true,
+ );
+}
diff --git a/windows/src/main.ts b/windows/src/main.ts
index f65d5e75..708c3da4 100644
--- a/windows/src/main.ts
+++ b/windows/src/main.ts
@@ -7,6 +7,7 @@ import { State, type Settings } from "./core/state";
import { Island } from "./island/island";
import { registerHookHandlers } from "./island/hooks";
import { registerIntegrationHandlers, refreshConfigured } from "./island/integrations";
+import { registerShortcutHandlers } from "./island/shortcuts";
async function main() {
const root = document.getElementById("root");
@@ -63,6 +64,7 @@ async function main() {
registerHookHandlers(island);
registerIntegrationHandlers(island);
+ registerShortcutHandlers(island, () => setPaused(false));
island.launch();
diff --git a/windows/tests/shortcuts.test.mjs b/windows/tests/shortcuts.test.mjs
new file mode 100644
index 00000000..896748a9
--- /dev/null
+++ b/windows/tests/shortcuts.test.mjs
@@ -0,0 +1,395 @@
+// Keyboard shortcuts: the pure logic (src/core/shortcuts.ts, mirroring the
+// Mac's tests/ShortcutTests.swift) and what the island does with them
+// (src/island/shortcuts.ts), driven through the real bridge.
+
+import { beforeEach, test } from "node:test";
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { calls, emit, sent } from "./tauri.mjs";
+import {
+ ALTGR_CHARACTERS, ISLAND_SHORTCUTS, KEY_NAMES, SHORTCUTS, SHORTCUT_TEXT, activeKeys, altGrClashes,
+ cyclePill, displayKeys, duplicates, effective, formatKeys, islandKeyAction, navigate, normalizeKeys,
+ parseKeys, pillByNumber, recordPress,
+} from "../src/core/shortcuts.ts";
+import { registerShortcutHandlers, runGlobalShortcut, runIslandKey } from "../src/island/shortcuts.ts";
+import { DEFAULT_SETTINGS, State } from "../src/core/state.ts";
+
+const MAC_IDS = [
+ "toggleIsland", "openChat", "goToAlert", "jumpToTerminal", "attachFrontWindow",
+ "nextPill", "prevPill", "muteToggle", "desktopToggle", "wardrobeToggle",
+];
+
+// ── Defaults (testDefaultsExhaustive, testAllDefaultsHaveModifier, testNoDefaultDuplicates) ──
+
+test("every Mac action has a default, in the Mac's order, with its Mac id", () => {
+ assert.deepEqual(SHORTCUTS.map((d) => d.id), MAC_IDS);
+ for (const d of SHORTCUTS) assert.ok(SHORTCUT_TEXT[d.id], `${d.id} has no label`);
+});
+
+test("every default parses, is canonical and holds Ctrl+Alt", () => {
+ for (const d of SHORTCUTS) {
+ const c = parseKeys(d.defaultKeys);
+ assert.ok(c, `${d.id} default does not parse`);
+ assert.ok(c.ctrl && c.alt && !c.meta, `${d.id} default is not Ctrl+Alt`);
+ assert.equal(formatKeys(c), d.defaultKeys, `${d.id} default is not in canonical form`);
+ }
+});
+
+test("no two defaults share a combination", () => {
+ assert.deepEqual(duplicates(SHORTCUTS.map((d) => [d.id, d.defaultKeys])), new Set());
+});
+
+test("no default types a character with AltGr on the checked European layouts", () => {
+ for (const layout of ["French (AZERTY)", "German (QWERTZ)", "Spanish", "Italian", "Portuguese", "Brazilian (ABNT2)"]) {
+ assert.ok(ALTGR_CHARACTERS[layout], layout);
+ }
+ for (const d of SHORTCUTS) {
+ assert.deepEqual(altGrClashes(d.defaultKeys), [], `${d.id} = ${d.defaultKeys}`);
+ }
+ // The Mac's own letters would not have been safe.
+ assert.deepEqual(altGrClashes("Ctrl+Alt+M"), ["German (QWERTZ)"]);
+ assert.ok(altGrClashes("Ctrl+Alt+E").length >= 5);
+ assert.ok(altGrClashes("Ctrl+Alt+0").includes("French (AZERTY)"));
+ // Not Ctrl+Alt: not AltGr.
+ assert.deepEqual(altGrClashes("Ctrl+Shift+E"), []);
+});
+
+test("the defaults are the same on both sides of the bridge", () => {
+ const rust = readFileSync(new URL("../src-tauri/src/shortcuts.rs", import.meta.url), "utf8");
+ const rows = [...rust.matchAll(/^\s*action\("(\w+)", "([^"]+)", (true|false), (true|false)\),/gm)]
+ .map(([, id, keys, on, ported]) => ({ id, keys, on: on === "true", ported: ported === "true" }));
+ assert.deepEqual(
+ rows,
+ SHORTCUTS.map((d) => ({ id: d.id, keys: d.defaultKeys, on: d.enabledByDefault, ported: d.ported })),
+ );
+});
+
+// testEnabledByDefault
+test("only the island toggle is off by default; the two not ported yet are reserved", () => {
+ for (const d of SHORTCUTS) {
+ assert.equal(d.enabledByDefault, d.id !== "toggleIsland", d.id);
+ assert.equal(d.ported, !["attachFrontWindow", "desktopToggle"].includes(d.id), d.id);
+ }
+ assert.deepEqual(activeKeys({}).map(([id]) => id), [
+ "openChat", "goToAlert", "jumpToTerminal", "nextPill", "prevPill", "muteToggle", "wardrobeToggle",
+ ]);
+});
+
+// ── Parsing and formatting (testCarbonModifiers, testDisplayString, testKeyCodeToString) ──
+
+test("modifiers parse one by one and all together", () => {
+ assert.deepEqual(parseKeys("Ctrl+Shift+N"), { ctrl: true, alt: false, shift: true, meta: false, key: "N" });
+ assert.deepEqual(parseKeys("Ctrl+Alt+A"), { ctrl: true, alt: true, shift: false, meta: false, key: "A" });
+ assert.deepEqual(parseKeys("Super+Shift+Alt+Ctrl+k"), { ctrl: true, alt: true, shift: true, meta: true, key: "K" });
+ // The spellings Rust accepts.
+ assert.equal(normalizeKeys("control+option+arrowright"), "Ctrl+Alt+Right");
+ assert.equal(normalizeKeys("CmdOrCtrl+Alt+KeyQ"), "Ctrl+Alt+Q");
+ assert.equal(normalizeKeys("Ctrl+Alt+Digit7"), "Ctrl+Alt+7");
+ assert.equal(normalizeKeys("Ctrl+Alt+]"), "Ctrl+Alt+BracketRight");
+});
+
+test("a bare key, Shift alone, a modifier with no key, or nonsense is not a shortcut", () => {
+ for (const bad of ["", "A", "Shift+A", "Ctrl+Alt", "Ctrl+Alt+", "Ctrl+Alt+Nope", "A+Ctrl", "Ctrl+A+B", "Ctrl+Escape"]) {
+ assert.equal(parseKeys(bad), null, JSON.stringify(bad));
+ }
+});
+
+test("what a person reads", () => {
+ assert.equal(displayKeys("Ctrl+Shift+N"), "Ctrl+Shift+N");
+ assert.equal(displayKeys("Ctrl+Alt+Space"), "Ctrl+Alt+Space");
+ assert.equal(displayKeys("Ctrl+Alt+Right"), "Ctrl+Alt+→");
+ assert.equal(displayKeys("Ctrl+Alt+Left"), "Ctrl+Alt+←");
+ assert.equal(displayKeys("Super+Comma"), "Win+,");
+ assert.equal(displayKeys("Ctrl+Alt+BracketLeft"), "Ctrl+Alt+[");
+ assert.equal(displayKeys(""), "—");
+ // Each modifier once.
+ assert.equal(displayKeys("Ctrl+Ctrl+Alt+A").match(/Ctrl/g).length, 1);
+});
+
+test("every key name survives a round trip", () => {
+ for (const key of KEY_NAMES) {
+ assert.equal(normalizeKeys(`Ctrl+Alt+${key}`), `Ctrl+Alt+${key}`, key);
+ }
+});
+
+// ── Conflicts (testDuplicateDetection) ───────────────────────────────────────
+
+test("duplicates flag both actions, and only the same modifiers and key", () => {
+ assert.deepEqual(duplicates([]), new Set());
+ assert.deepEqual(duplicates([["goToAlert", "Ctrl+Alt+A"]]), new Set());
+ assert.deepEqual(duplicates([["goToAlert", "Ctrl+Alt+A"], ["jumpToTerminal", "Ctrl+Alt+T"]]), new Set());
+ assert.deepEqual(
+ duplicates([["goToAlert", "Ctrl+Alt+A"], ["jumpToTerminal", "ctrl+alt+a"]]),
+ new Set(["goToAlert", "jumpToTerminal"]),
+ );
+ assert.deepEqual(duplicates([["goToAlert", "Ctrl+Alt+A"], ["jumpToTerminal", "Ctrl+Shift+A"]]), new Set());
+});
+
+// ── Stored bindings (testLoadSaveRoundTrip) ───────────────────────────────────
+
+test("a stored binding wins, the rest keep their default, and off ones hold no keys", () => {
+ const stored = {
+ openChat: { keys: "Ctrl+Alt+K", enabled: true },
+ goToAlert: { keys: "Ctrl+Alt+A", enabled: false },
+ toggleIsland: { keys: "Ctrl+Alt+N", enabled: true },
+ };
+ const chat = SHORTCUTS.find((d) => d.id === "openChat");
+ assert.deepEqual(effective(chat, stored), { keys: "Ctrl+Alt+K", enabled: true });
+ assert.deepEqual(effective(chat, undefined), { keys: "Ctrl+Alt+Space", enabled: true });
+ const ids = activeKeys(stored).map(([id]) => id);
+ assert.ok(ids.includes("toggleIsland"));
+ assert.ok(!ids.includes("goToAlert"));
+ // Same JSON shape as Rust's Bindings.
+ assert.deepEqual(JSON.parse(JSON.stringify(stored)).openChat, { keys: "Ctrl+Alt+K", enabled: true });
+ assert.deepEqual(DEFAULT_SETTINGS.shortcuts, {});
+});
+
+// ── Recording a press ─────────────────────────────────────────────────────────
+
+const press = (over) => ({
+ key: "", code: "", ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, ...over,
+});
+
+test("the recorder turns a press into canonical keys", () => {
+ assert.deepEqual(recordPress(press({ key: " ", code: "Space", ctrlKey: true, altKey: true })),
+ { kind: "keys", keys: "Ctrl+Alt+Space" });
+ assert.deepEqual(recordPress(press({ key: "ArrowRight", code: "ArrowRight", ctrlKey: true, altKey: true })),
+ { kind: "keys", keys: "Ctrl+Alt+Right" });
+ // AZERTY: the key labelled A sits where QWERTY has Q. The label wins, as it
+ // does for RegisterHotKey.
+ assert.deepEqual(recordPress(press({ key: "a", code: "KeyQ", ctrlKey: true, altKey: true })),
+ { kind: "keys", keys: "Ctrl+Alt+A" });
+ assert.deepEqual(recordPress(press({ key: "K", code: "KeyK", ctrlKey: true, shiftKey: true })),
+ { kind: "keys", keys: "Ctrl+Shift+K" });
+ assert.deepEqual(recordPress(press({ key: "F9", code: "F9", metaKey: true })),
+ { kind: "keys", keys: "Super+F9" });
+});
+
+test("the recorder waits for a key, cancels, clears, and refuses what can't be a shortcut", () => {
+ assert.deepEqual(recordPress(press({ key: "Control", code: "ControlLeft", ctrlKey: true })), { kind: "pending" });
+ assert.deepEqual(recordPress(press({ key: "AltGraph", code: "AltRight", ctrlKey: true, altKey: true })), { kind: "pending" });
+ assert.deepEqual(recordPress(press({ key: "Escape", code: "Escape" })), { kind: "cancel" });
+ assert.deepEqual(recordPress(press({ key: "Backspace", code: "Backspace" })), { kind: "clear" });
+ assert.deepEqual(recordPress(press({ key: "a", code: "KeyA" })), { kind: "needsModifier" });
+ assert.deepEqual(recordPress(press({ key: "A", code: "KeyA", shiftKey: true })), { kind: "needsModifier" });
+ assert.deepEqual(recordPress(press({ key: "Unidentified", code: "Lang1", ctrlKey: true })), { kind: "unsupported" });
+});
+
+test("a Ctrl+Alt press that types a character on this keyboard is refused", () => {
+ // German: AltGr+E = €, AltGr+Q = @. French: AltGr+0 = @.
+ assert.deepEqual(recordPress(press({ key: "€", code: "KeyE", ctrlKey: true, altKey: true })),
+ { kind: "typesCharacter", typed: "€", keys: "Ctrl+Alt+E" });
+ assert.deepEqual(recordPress(press({ key: "@", code: "KeyQ", ctrlKey: true, altKey: true })),
+ { kind: "typesCharacter", typed: "@", keys: "Ctrl+Alt+Q" });
+ assert.deepEqual(recordPress(press({ key: "@", code: "Digit0", ctrlKey: true, altKey: true })),
+ { kind: "typesCharacter", typed: "@", keys: "Ctrl+Alt+0" });
+ assert.equal(recordPress(press({ key: "Dead", code: "BracketLeft", ctrlKey: true, altKey: true })).kind, "typesCharacter");
+ // Ctrl+Shift is never AltGr.
+ assert.deepEqual(recordPress(press({ key: "€", code: "KeyE", ctrlKey: true, shiftKey: true })),
+ { kind: "keys", keys: "Ctrl+Shift+E" });
+});
+
+// ── In the island (testCardNavigation and the island keys) ───────────────────
+
+test("card navigation clamps, and starts from either end", () => {
+ assert.equal(navigate(null, +1, 3), 0);
+ assert.equal(navigate(null, -1, 3), 2);
+ assert.equal(navigate(0, -1, 3), 0);
+ assert.equal(navigate(2, +1, 3), 2);
+ assert.equal(navigate(1, +1, 3), 2);
+ assert.equal(navigate(1, -1, 3), 0);
+ assert.equal(navigate(1, 0, 3), 1);
+ assert.equal(navigate(null, +1, 0), null);
+ assert.equal(navigate(0, +1, 0), null);
+});
+
+test("pills cycle around and are picked by number", () => {
+ const ids = ["a", "b", "c"];
+ assert.equal(cyclePill(ids, "a", 1), "b");
+ assert.equal(cyclePill(ids, "c", 1), "a");
+ assert.equal(cyclePill(ids, "a", -1), "c");
+ assert.equal(cyclePill(ids, "gone", 1), "b");
+ assert.equal(cyclePill([], "a", 1), null);
+ assert.equal(pillByNumber(ids, 1), "a");
+ assert.equal(pillByNumber(ids, 3), "c");
+ assert.equal(pillByNumber(ids, 4), null);
+ assert.equal(pillByNumber(ids, 0), null);
+});
+
+test("Ctrl stands in for ⌘ inside the island", () => {
+ const ctx = { view: "overview", inTextField: false };
+ const ctrl = (key, code = "") => press({ key, code, ctrlKey: true });
+ assert.deepEqual(islandKeyAction(ctrl("ArrowRight"), ctx), { kind: "cycle", delta: 1 });
+ assert.deepEqual(islandKeyAction(ctrl("ArrowLeft"), ctx), { kind: "cycle", delta: -1 });
+ assert.deepEqual(islandKeyAction(ctrl("&", "Digit1"), ctx), { kind: "pill", number: 1 });
+ assert.deepEqual(islandKeyAction(ctrl("9", "Digit9"), ctx), { kind: "pill", number: 9 });
+ assert.equal(islandKeyAction(ctrl("0", "Digit0"), ctx), null);
+ assert.deepEqual(islandKeyAction(ctrl("p", "KeyP"), ctx), { kind: "pin" });
+ assert.deepEqual(islandKeyAction(ctrl(",", "Comma"), ctx), { kind: "settings" });
+ // Ctrl+K only means something in the chat.
+ assert.equal(islandKeyAction(ctrl("k", "KeyK"), ctx), null);
+ assert.deepEqual(islandKeyAction(ctrl("k", "KeyK"), { view: "prompt", inTextField: true }), { kind: "newChat" });
+ // In a text field Ctrl+← → move by word.
+ assert.equal(islandKeyAction(ctrl("ArrowRight"), { view: "prompt", inTextField: true }), null);
+ // Anything with another modifier, or no Ctrl, is left alone.
+ assert.equal(islandKeyAction(press({ key: "ArrowRight", ctrlKey: true, altKey: true }), ctx), null);
+ assert.equal(islandKeyAction(press({ key: "p", code: "KeyP" }), ctx), null);
+ assert.ok(ISLAND_SHORTCUTS.length >= 6);
+});
+
+// ── What the island does ──────────────────────────────────────────────────────
+
+let did;
+const host = {
+ alert: (v) => did.push(`alert:${v}`),
+ setView: (v) => did.push(`setView:${v}`),
+ collapse: () => did.push("collapse"),
+ emote: (e) => did.push(`emote:${e}`),
+ setPinned: (on) => did.push(`pin:${on}`),
+ takeKeyboard: () => did.push("keyboard"),
+};
+const resume = () => did.push("resume");
+// The island listens on `window`, which here is the bare global object.
+const listeners = [];
+globalThis.addEventListener = (type, fn, capture) => listeners.push({ type, fn, capture });
+registerShortcutHandlers(host, resume);
+
+beforeEach(() => {
+ did = [];
+ calls.length = 0;
+ State.tasks = [];
+ State.focusId = null;
+ State.mode = "hidden";
+ State.view = "overview";
+ State.isPinned = false;
+ State.pendingApproval = null;
+ State.stateOverride = null;
+ State.chatHistory = [];
+ State.settings = { ...DEFAULT_SETTINGS };
+ State.loadIntegrationTasks();
+});
+
+test("a global shortcut arrives as an event and opens the chat", () => {
+ emit("shortcut", "openChat");
+ assert.deepEqual(did, ["resume", "alert:prompt"]);
+});
+
+test("island keys are read before the chat field sees them, and only while open", () => {
+ const keydown = listeners.find((l) => l.type === "keydown");
+ assert.equal(keydown.capture, true);
+ const ev = (over) => {
+ const e = { ...press(over), target: null, stopped: false, prevented: false };
+ e.preventDefault = () => { e.prevented = true; };
+ e.stopPropagation = () => { e.stopped = true; };
+ return e;
+ };
+ const hidden = ev({ key: "p", code: "KeyP", ctrlKey: true });
+ keydown.fn(hidden);
+ assert.equal(hidden.prevented, false);
+
+ State.mode = "expanded";
+ const pin = ev({ key: "p", code: "KeyP", ctrlKey: true });
+ keydown.fn(pin);
+ assert.ok(pin.prevented && pin.stopped);
+ assert.deepEqual(did, ["pin:true"]);
+
+ // Typing in the chat is left alone, word jumps included.
+ const word = ev({ key: "ArrowLeft", ctrlKey: true });
+ word.target = { tagName: "INPUT" };
+ keydown.fn(word);
+ assert.equal(word.prevented, false);
+ const plain = ev({ key: "k", code: "KeyK" });
+ keydown.fn(plain);
+ assert.equal(plain.prevented, false);
+});
+
+test("the island toggle opens with the keyboard, and closes an open island", () => {
+ runGlobalShortcut(host, "toggleIsland", resume);
+ assert.deepEqual(did, ["resume", "alert:overview", "keyboard"]);
+ did = [];
+ State.mode = "expanded";
+ runGlobalShortcut(host, "toggleIsland", resume);
+ assert.deepEqual(did, ["collapse"]);
+});
+
+test("go to alert: the permission first, then a question, else Mochi is annoyed", () => {
+ runGlobalShortcut(host, "goToAlert", resume);
+ assert.deepEqual(did, ["emote:annoyed"]);
+
+ did = [];
+ State.upsertExternalAgent("agent_gemini", "Gemini", "#fff");
+ State.updateTask("agent_gemini", "question");
+ runGlobalShortcut(host, "goToAlert", resume);
+ assert.deepEqual(did, ["resume", "alert:question", "keyboard"]);
+ assert.equal(State.focusId, "agent_gemini");
+
+ did = [];
+ State.pendingApproval = { requestId: "r1", sessionId: "s", tool: "Bash", command: "ls" };
+ runGlobalShortcut(host, "goToAlert", resume);
+ assert.deepEqual(did, ["resume", "alert:approval", "keyboard"]);
+ assert.equal(State.focusId, "integration_claude");
+ // Nothing is ever decided from a shortcut.
+ assert.deepEqual(sent("approval_decision"), []);
+});
+
+test("the terminal shortcut is the existing Open terminal, and folds the island", () => {
+ State.tasks[0].sessionCwd = "C:\\work\\proj";
+ State.mode = "expanded";
+ runGlobalShortcut(host, "jumpToTerminal", resume);
+ assert.deepEqual(sent("open_in_vscode"), [{ path: "C:\\work\\proj" }]);
+ assert.deepEqual(did, ["collapse"]);
+});
+
+test("next and previous pill wrap around and open the overview", () => {
+ const ids = State.tasks.map((t) => t.id);
+ State.focusId = ids[0];
+ runGlobalShortcut(host, "prevPill", resume);
+ assert.equal(State.focusId, ids[ids.length - 1]);
+ runGlobalShortcut(host, "nextPill", resume);
+ assert.equal(State.focusId, ids[0]);
+ assert.deepEqual(did, ["resume", "alert:overview", "resume", "alert:overview"]);
+});
+
+test("mute flips the sound, saves it, and Mochi reacts", () => {
+ runGlobalShortcut(host, "muteToggle", resume);
+ assert.equal(State.settings.soundEnabled, false);
+ assert.equal(sent("save_settings").at(-1).settings.soundEnabled, false);
+ runGlobalShortcut(host, "muteToggle", resume);
+ assert.equal(State.settings.soundEnabled, true);
+ assert.deepEqual(did, ["emote:annoyed", "emote:happy"]);
+});
+
+test("actions that aren't the island's do nothing here", () => {
+ for (const id of ["wardrobeToggle", "attachFrontWindow", "desktopToggle", "nonsense"]) {
+ runGlobalShortcut(host, id, resume);
+ }
+ assert.deepEqual(did, []);
+ assert.deepEqual(calls, []);
+});
+
+test("island keys: pills by number, new chat, settings, pin", () => {
+ const ids = State.tasks.map((t) => t.id);
+ runIslandKey(host, { kind: "pill", number: 2 });
+ assert.equal(State.focusId, ids[1]);
+ runIslandKey(host, { kind: "pill", number: 9 });
+ assert.equal(State.focusId, ids[1]);
+ runIslandKey(host, { kind: "cycle", delta: 1 });
+ assert.equal(State.focusId, ids[2 % ids.length]);
+
+ State.chatHistory = [{ id: 1, role: "user", content: "hi" }];
+ State.stateOverride = "thinking";
+ runIslandKey(host, { kind: "newChat" });
+ assert.equal(State.chatHistory.length, 1, "not while an answer is on its way");
+ State.stateOverride = null;
+ runIslandKey(host, { kind: "newChat" });
+ assert.deepEqual(State.chatHistory, []);
+ assert.equal(sent("chat_reset").length, 1);
+
+ runIslandKey(host, { kind: "settings" });
+ assert.equal(sent("open_settings_window").length, 1);
+
+ runIslandKey(host, { kind: "pin" });
+ State.pendingApproval = { requestId: "r1", sessionId: "s", tool: "Bash", command: "ls" };
+ runIslandKey(host, { kind: "pin" });
+ assert.deepEqual(did, ["setView:overview", "setView:overview", "setView:prompt", "pin:true"]);
+});