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.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Desktop Mochi: drag him out of the island; alerts bring him back
Claude7a8d5e63d9fd
diff --git a/windows/src/core/state.ts b/windows/src/core/state.tsindex 16acf8c4..674b611d 100644--- a/windows/src/core/state.ts+++ b/windows/src/core/state.ts@@ -98,6 +98,11 @@ export interface Settings {* Same raw values as the Mac's "mochiOutfit"; read it through parseOutfit.*/mochiOutfit: string;+ /** Mochi on the desktop. Rust owns it: whatever the page sends back is ignored. */+ desktopMochi?: {+ onDesktop: boolean;+ spot: { x: number; y: number; space: string } | null;+ };}export const DEFAULT_SETTINGS: Settings = {@@ -147,6 +152,12 @@ class AppState {integrations: Record<string, IntegrationInfo> = {};+ /**+ * Mochi is out of the island — on the desktop, flying, or being dragged+ * there — so the island's own Mochi is hidden (AppState.mochiOnDesktop).+ */+ mochiOnDesktop = false;+/** Outfit shown on Mochi while the pointer rests on a wardrobe button. */wardrobePreview: Outfit | null = null;diff --git a/windows/src/island/desktop.ts b/windows/src/island/desktop.tsnew file mode 100644index 00000000..eac54d24--- /dev/null+++ b/windows/src/island/desktop.ts@@ -0,0 +1,170 @@+// Mochi on the desktop, island side: runs his life cycle (the controller in+// mochi/desktop-logic.ts) against the real app, tells the desktop window what+// to show, and handles the drag out of the island. The window itself lives in+// src-tauri/src/desktop.rs and draws him in src/desktop/main.ts.++import { Bridge, emitToWindow, onEvent, type DesktopMode } from "../core/bridge";+import type { BotEmoteName } from "../core/layout";+import { Sound } from "../core/sound";+import { State } from "../core/state";+import {+ DESKTOP_EVENTS, DesktopMochiController, alertActive, type DesktopSnapshot,+} from "../mochi/desktop-logic";+import { SeasonCache, parseOutfit } from "../mochi/wardrobe";++/** Label of the desktop Mochi's window (desktop.rs LABEL). */+const WINDOW = "mochi";++/** What the life cycle needs from the island. */+export interface DesktopHost {+ /** Shows the island (compact) if it is hidden. */+ reveal(): void;+ /** Right-click on the desktop Mochi: the wardrobe, or back. */+ wardrobeFromDesktop(): void;+ /** Three pokes on the desktop Mochi. */+ dizzyFromDesktop(): void;+}++export class DesktopLink {+ mode: DesktopMode = "off";+ readonly controller: DesktopMochiController;++ /** The pointer is dragging Mochi out of the island. */+ carrying = false;++ private seasons = new SeasonCache();+ private pushed = "";+ private pendingCarry: { x: number; y: number } | null = null;+ private carryFrame = false;+ private host: DesktopHost;++ constructor(host: DesktopHost) {+ this.host = host;+ this.controller = new DesktopMochiController({+ flyOut: async () => (await Bridge.desktopFlyOut()) ?? false,+ flyHome: async (forget) => (await Bridge.desktopFlyHome(forget)) ?? true,+ setAway: (away) => {+ State.mochiOnDesktop = away;+ State.notify();+ },+ emote: (emote: BotEmoteName, duration = 1.8) =>+ void emitToWindow(WINDOW, DESKTOP_EVENTS.emote, { emote, duration }),+ play: (sound) => Sound.play(sound),+ alertActive: () => alertActive(State),+ revealIsland: () => {+ if (State.mode === "hidden") this.host.reveal();+ },+ later: (fn, ms) => void window.setTimeout(fn, ms),+ });+ }++ /** False where windows can't be placed (GNOME on Wayland): he stays in the island. */+ get supported(): boolean {+ return this.mode !== "off";+ }++ async init() {+ const info = await Bridge.desktopInfo();+ if (!info || info.mode === "off") return;+ this.mode = info.mode;+ this.controller.enabled = info.onDesktop;++ await onEvent<{ from: "island" | "desktop"; home: boolean }>(DESKTOP_EVENTS.dropped, (e) =>+ this.onDropped(e.from, e.home),+ );+ await onEvent<null>(DESKTOP_EVENTS.home, () => void this.controller.flyHome());+ await onEvent<null>(DESKTOP_EVENTS.wardrobe, () => this.host.wardrobeFromDesktop());+ await onEvent<null>(DESKTOP_EVENTS.dizzy, () => this.host.dizzyFromDesktop());+ // The window's page (re)loaded: it knows nothing yet.+ await onEvent<null>(DESKTOP_EVENTS.ready, () => {+ this.pushed = "";+ this.push();+ });++ State.subscribe(() => this.sync());+ this.sync();+ }++ /** The launch greeting is over: back to his spot if that is where he lives. */+ launch() {+ if (this.supported) void this.controller.launchFlyIfNeeded();+ }++ // ── Drag out of the island ──────────────────────────────────────────────────++ /** Whether Mochi can be picked up from the island right now. */+ canPickUp(): boolean {+ return this.supported && !State.paused && !State.mochiOnDesktop && this.controller.phase === "home";+ }++ /** (x, y): the pointer, island-window coordinates. */+ pickUp(x: number, y: number) {+ this.carrying = true;+ State.mochiOnDesktop = true;+ State.notify();+ void Bridge.desktopPickUp(x, y).then((ok) => {+ if (ok) return;+ this.carrying = false;+ State.mochiOnDesktop = false;+ State.notify();+ });+ }++ /** The pointer moved during the drag. Windows carries him from Rust. */+ carry(x: number, y: number) {+ if (!this.carrying || this.mode === "poll") return;+ this.pendingCarry = { x, y };+ if (this.carryFrame) return;+ this.carryFrame = true;+ requestAnimationFrame(() => {+ this.carryFrame = false;+ const p = this.pendingCarry;+ this.pendingCarry = null;+ if (p && this.carrying) void Bridge.desktopCarry(p.x, p.y);+ });+ }++ /** The button went up. On Windows the cursor poll has seen it already. */+ carryEnd(x: number, y: number) {+ if (!this.carrying || this.mode === "poll") return;+ this.pendingCarry = null;+ void Bridge.desktopCarryEnd(x, y);+ }++ private onDropped(from: "island" | "desktop", home: boolean) {+ if (from === "island") {+ this.carrying = false;+ if (home) {+ // Dropped back on the island: he is simply there again.+ State.mochiOnDesktop = false;+ State.notify();+ } else {+ this.controller.installed();+ }+ } else if (home) {+ void this.controller.flyHome();+ }+ }++ // ── State → desktop window ──────────────────────────────────────────────────++ private sync() {+ this.controller.updateAlert(alertActive(State));+ this.controller.updateState(State.effectiveState);+ this.push();+ }++ private push() {+ const snapshot: DesktopSnapshot = {+ state: State.effectiveState,+ outfit: State.wardrobePreview ?? this.seasons.get(parseOutfit(State.settings.mochiOutfit)),+ soundEnabled: State.settings.soundEnabled,+ soundVolume: State.settings.soundVolume,+ paused: State.paused,+ };+ const key = JSON.stringify(snapshot);+ if (key === this.pushed) return;+ this.pushed = key;+ void emitToWindow(WINDOW, DESKTOP_EVENTS.state, snapshot);+ }+}diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 18aabfa6..bcd8b4f8 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -20,6 +20,8 @@ import { USC, UploadSeq } from "../upload/sequence";import { buildHeader, buildViews, type ViewActions, type ViewHost } from "../views/views";import { h } from "../views/dom";import { IslandStateMachine } from "./fsm";+import { DesktopLink } from "./desktop";+import { DRAG_THRESHOLD } from "../mochi/desktop-logic";const BOT_OVERHANG = 40;/** Extra canvas on each side of Mochi, for the witch hat's brim and the Santa hat's tip. */@@ -39,6 +41,8 @@ const modeOrder = (m: IslandMode) => (m === "hidden" ? 0 : m === "compact" ? 1 :export class Island {readonly fsm = new IslandStateMachine();+ /** Mochi on the desktop: his life cycle and the drag out of the island. */+ readonly desktop: DesktopLink;private root: HTMLElement;private islandEl!: HTMLElement;@@ -91,12 +95,20 @@ export class Island {private prevViewBeforeConfused: IslandViewName = "overview";private lastSyncedView: IslandViewName | null = null;+ /** Where a press on Mochi started: moving past DRAG_THRESHOLD drags him out. */+ private botPress: { x: number; y: number } | null = null;+/** Drop sequence bookkeeping: last tick played, and whether the ✓ has fired. */private uploadTens = 0;private uploadDone = false;constructor(root: HTMLElement) {this.root = root;+ this.desktop = new DesktopLink({+ reveal: () => this.reveal(),+ wardrobeFromDesktop: () => this.wardrobeFromDesktop(),+ dizzyFromDesktop: () => this.handleDizzy(),+ });this.build();this.wireFsm();this.wireInput();@@ -245,6 +257,8 @@ export class Island {private wireFsm() {this.fsm.homeToPetitDelay = State.settings.autoCloseInterval;this.fsm.onTransition = (from, to) => {+ // The greeting is over, however it ended: back to his desktop spot.+ if (from === "coucou" && to !== "coucou") this.desktop.launch();switch (to) {case "hidden":this.setMode("hidden");@@ -362,6 +376,19 @@ export class Island {else this.setView("wardrobe");}+ /**+ * Right-click on the desktop Mochi (macOS openWardrobeFromDesktop): opens the+ * wardrobe from any state, or goes back if it is already open.+ */+ wardrobeFromDesktop() {+ if (State.mode === "expanded" && State.view === "wardrobe") {+ this.setView(State.defaultView());+ return;+ }+ if (State.paused) return;+ this.alert("wardrobe");+ }+/** An alert stopped waiting for an answer: let the island auto-close again. */dropPin() {this.fsm.pinned = false;@@ -562,6 +589,10 @@ export class Island {this.islandEl.addEventListener("mousedown", (e) => {Sound.resume();State.lastActivity = performance.now();+ // A press on Mochi may become a drag out to the desktop.+ if (e.button === 0 && this.isBotHit(e.clientX, e.clientY)) {+ this.botPress = { x: e.clientX, y: e.clientY };+ }// Right-click on Mochi opens the wardrobe, and closes it again.if (e.button === 2 && this.isBotHit(e.clientX, e.clientY)) {this.cancelBotHover();@@ -584,6 +615,29 @@ export class Island {if (this.isBotHit(e.clientX, e.clientY)) e.preventDefault();});+ // Dragging Mochi out of the island puts him on the desktop.+ window.addEventListener("mousemove", (e) => {+ if (this.desktop.carrying) {+ this.desktop.carry(e.clientX, e.clientY);+ return;+ }+ const press = this.botPress;+ if (!press) return;+ if (!(e.buttons & 1)) {+ this.botPress = null;+ return;+ }+ if (Math.hypot(e.clientX - press.x, e.clientY - press.y) <= DRAG_THRESHOLD) return;+ this.botPress = null;+ if (!this.canDragOut()) return;+ this.cancelBotHover();+ this.desktop.pickUp(e.clientX, e.clientY);+ });+ window.addEventListener("mouseup", (e) => {+ this.botPress = null;+ if (this.desktop.carrying) this.desktop.carryEnd(e.clientX, e.clientY);+ });+window.addEventListener("keydown", (e) => {if (e.key === "Escape" && State.mode === "expanded" && !State.isPinned) this.collapse();State.lastActivity = performance.now();@@ -654,7 +708,15 @@ export class Island {this.ensureRunning();}+ /** The greeting and the drop sequence draw a Mochi of their own: not that one. */+ private canDragOut(): boolean {+ if (State.mode === "hidden" || !this.desktop.canPickUp()) return false;+ return !(State.mode === "expanded" && (State.view === "greeting" || this.uploadActive));+ }+private isBotHit(x: number, y: number): boolean {+ // Out on the desktop, the island's Mochi is invisible: nothing to hit.+ if (State.mochiOnDesktop) return false;const rect = this.islandRect();const cx = rect.x + this.botCx.value;const cy = rect.y + this.botCy.value;@@ -690,7 +752,7 @@ export class Island {}/** Three slaps → dizzy + confused view for 3.3 s, then back. */- private handleDizzy() {+ handleDizzy() {this.prevViewBeforeConfused = State.view;State.stateOverride = "dizzy";this.engine.setState("dizzy");@@ -790,11 +852,13 @@ export class Island {this.botSize.target = p.diameter / 0.6;const greetingActive = State.mode === "expanded" && State.view === "greeting";- // The drop canvas draws its own Mochi; two of them would overlap.- const visible = p.opacity > 0 && !greetingActive && !this.uploadActive;+ // The drop canvas draws its own Mochi; two of them would overlap. Out on the+ // desktop, he isn't here at all.+ const away = State.mochiOnDesktop;+ const visible = p.opacity > 0 && !greetingActive && !this.uploadActive && !away;this.botCanvas.style.opacity = visible ? "1" : "0";- if (State.mode === "expanded" && State.view !== "uploading" && !greetingActive && !this.uploadActive) {+ if (State.mode === "expanded" && State.view !== "uploading" && !greetingActive && !this.uploadActive && !away) {const d = p.diameter;const color = botGlowColor(State.effectiveState);this.botGlow.style.display = "block";diff --git a/windows/src/main.ts b/windows/src/main.tsindex 21b2195f..fc292721 100644--- a/windows/src/main.ts+++ b/windows/src/main.ts@@ -23,6 +23,7 @@ async function main() {island.applySettings();State.loadIntegrationTasks();if (boot && !boot.cursorPoll) island.followPageCursor();+ await island.desktop.init();await onEvent<{ x: number; y: number }>("cursor", ({ x, y }) => island.onCursor(x, y));