Relevant Diff Snippets
These snippets are formatted as unified patch strings so they can be consumed by Diffs’
parsePatchFiles or PatchDiff flow from the official docs:
https://diffs.com/docs.
Electron main process: preload, desktop AI service, and guarded IPC
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
@@
-import { app, BrowserWindow, shell } from "electron";
+import { app, BrowserWindow, ipcMain, shell } from "electron";
+import type { Event as ElectronEvent, IpcMainInvokeEvent } from "electron";
+import { fileURLToPath } from "node:url";
+import { IslandflowDesktopAiService } from "./desktop-ai.js";
+import {
+ DESKTOP_AI_CANCEL_LOGIN,
+ DESKTOP_AI_GET_STATE,
+ DESKTOP_AI_LOGIN_BROWSER,
+ DESKTOP_AI_LOGIN_DEVICE,
+ DESKTOP_AI_LOGOUT,
+ DESKTOP_AI_RUN_TASK,
+ DESKTOP_AI_STATE_CHANNEL,
+ DESKTOP_AI_UPDATE_PREFERENCES
+} from "./desktop-ai-ipc.js";
@@
+const PRELOAD_PATH = fileURLToPath(new URL("./preload.js", import.meta.url));
@@
+const registerDesktopAiIpc = (service: IslandflowDesktopAiService): void => {
+ const guard = (event: IpcMainInvokeEvent): void => {
+ const senderUrl = event.senderFrame?.url || event.sender.getURL();
+ if (!isTrustedAppUrl(senderUrl)) {
+ throw new Error(`Rejected desktop AI IPC from untrusted origin: ${senderUrl || "unknown"}`);
+ }
+ };
+
+ ipcMain.handle(DESKTOP_AI_GET_STATE, async (event) => {
+ guard(event);
+ await service.start();
+ return service.getState();
+ });
+ // login, logout, preference, and task handlers follow the same guard
+};
Renderer shell: settings route, topbar entrypoint, and in-context copilot surfaces
diff --git a/apps/web/app/terminal.tsx b/apps/web/app/terminal.tsx
@@
+import { useDesktopAi } from "./desktop-ai";
+import {
+ DesktopAiSettingsRoute,
+ ReplayCopilotPanel,
+ ScreenCompilerPanel,
+ SmartMoneyCopilotPanel
+} from "./desktop-ai-panels";
@@
+export const NAV_ITEMS = [
+ { href: "/", label: "Home" },
+ { href: "/tape", label: "Tape" },
+ { href: "/signals", label: "Signals" },
+ { href: "/charts", label: "Charts" },
+ { href: "/replay", label: "Replay" },
+ { href: "/settings", label: "Settings" }
+];
@@
+
@@
+
@@
+
Shared desktop AI contract: auth state, rate limits, usage, and structured tasks
diff --git a/packages/types/src/desktop-ai.ts b/packages/types/src/desktop-ai.ts
+export const IslandflowAiTaskRequestSchema = z.discriminatedUnion("kind", [
+ z.object({ kind: z.literal("smart-money-explain"), context: IslandflowAiSmartMoneyContextSchema }),
+ z.object({ kind: z.literal("smart-money-skeptic"), context: IslandflowAiSmartMoneyContextSchema }),
+ z.object({ kind: z.literal("smart-money-burst-summary"), context: IslandflowAiSmartMoneyContextSchema }),
+ z.object({ kind: z.literal("watchlist-synthesis"), context: IslandflowAiSmartMoneyContextSchema }),
+ z.object({ kind: z.literal("replay-postmortem"), context: IslandflowAiReplayContextSchema }),
+ z.object({ kind: z.literal("screen-compile"), context: IslandflowAiScreenCompileContextSchema })
+]);
+
+export type IslandflowAiState = {
+ desktopAvailable: boolean;
+ transportStatus: IslandflowAiTransportStatus;
+ transportError: string | null;
+ profiles: IslandflowAiProfileSlot[];
+ account: IslandflowAiAccountState;
+ preferences: IslandflowAiPreferences;
+ models: IslandflowAiModelSummary[];
+ rateLimitsByLimitId: Record<string, IslandflowAiRateLimitSnapshot>;
+ usage: IslandflowAiUsageDashboard;
+ tasks: IslandflowAiTaskSnapshot[];
+ updatedAt: number;
+};
The document does not embed the Diffs runtime directly, but the snippets above are already prepared in the
patch-string format that Diffs documents for PatchDiff.