From 81223e1a4e35223df2befb79809525fb21d70992 Mon Sep 17 00:00:00 2001
From: jonathan308 <5055076+jonathan308@users.noreply.github.com>
Date: Sun, 8 Nov 2026 22:00:46 -0800
Subject: [PATCH 01/79] feat(desktop): routes, contracts and preview seams for
clusters, sandboxes, waitlists, chat and local serving
The app's sidebar gains Chat, Clusters, Sandboxes and Early access. Each
feature gets its own shared types (shared/cluster.ts, sandbox.ts,
waitlists.ts, chat.ts, localServing.ts), its own preview module
(renderer/preview/*) and its own main-process relay (main/chat.ts,
main/clusterSession.ts), so the pages can be built side by side. The native
resources `cluster`, `sandbox`, `sandbox-logs` and `waitlists` are allowed
through the main process; `useResource` reads a resource while its page is
shown. Sandbox approval links open only on Darkbloom hosts over https.
Co-Authored-By: Claude Opus 5.5
---
desktop-app/src/main/backend.ts | 4 +
desktop-app/src/main/chat.ts | 29 +++++
desktop-app/src/main/clusterSession.ts | 33 +++++
desktop-app/src/main/ipc.ts | 45 ++++++-
desktop-app/src/main/security.ts | 19 +++
desktop-app/src/preload/index.ts | 16 +++
desktop-app/src/renderer/App.tsx | 26 +++-
.../renderer/components/operations/labels.ts | 11 ++
.../src/renderer/data/pageResources.ts | 6 +
desktop-app/src/renderer/data/useResource.ts | 50 ++++++++
.../src/renderer/features/chat/Chat.tsx | 16 +++
.../src/renderer/features/cluster/Cluster.tsx | 16 +++
.../renderer/features/sandboxes/Sandboxes.tsx | 16 +++
.../features/waitlists/WaitlistCard.tsx | 30 +++++
.../renderer/features/waitlists/Waitlists.tsx | 25 ++++
.../features/waitlists/useWaitlist.ts | 54 ++++++++
desktop-app/src/renderer/preview.ts | 21 +++-
desktop-app/src/renderer/preview/chat.ts | 18 +++
desktop-app/src/renderer/preview/cluster.ts | 4 +
.../src/renderer/preview/clusterSession.ts | 21 ++++
desktop-app/src/renderer/preview/features.ts | 35 ++++++
.../src/renderer/preview/localServing.ts | 4 +
desktop-app/src/renderer/preview/sandbox.ts | 4 +
desktop-app/src/renderer/preview/types.ts | 47 +++++++
desktop-app/src/renderer/preview/waitlists.ts | 69 +++++++++++
desktop-app/src/shared/chat.ts | 57 +++++++++
desktop-app/src/shared/cluster.ts | 115 ++++++++++++++++++
desktop-app/src/shared/contracts.ts | 56 ++++++++-
desktop-app/src/shared/localServing.ts | 35 ++++++
desktop-app/src/shared/sandbox.ts | 99 +++++++++++++++
desktop-app/src/shared/waitlists.ts | 34 ++++++
desktop-app/tests/app.test.tsx | 11 +-
desktop-app/tests/pageTitle.test.tsx | 13 ++
docs/developer/desktop-app.md | 23 +++-
34 files changed, 1047 insertions(+), 15 deletions(-)
create mode 100644 desktop-app/src/main/chat.ts
create mode 100644 desktop-app/src/main/clusterSession.ts
create mode 100644 desktop-app/src/renderer/data/useResource.ts
create mode 100644 desktop-app/src/renderer/features/chat/Chat.tsx
create mode 100644 desktop-app/src/renderer/features/cluster/Cluster.tsx
create mode 100644 desktop-app/src/renderer/features/sandboxes/Sandboxes.tsx
create mode 100644 desktop-app/src/renderer/features/waitlists/WaitlistCard.tsx
create mode 100644 desktop-app/src/renderer/features/waitlists/Waitlists.tsx
create mode 100644 desktop-app/src/renderer/features/waitlists/useWaitlist.ts
create mode 100644 desktop-app/src/renderer/preview/chat.ts
create mode 100644 desktop-app/src/renderer/preview/cluster.ts
create mode 100644 desktop-app/src/renderer/preview/clusterSession.ts
create mode 100644 desktop-app/src/renderer/preview/features.ts
create mode 100644 desktop-app/src/renderer/preview/localServing.ts
create mode 100644 desktop-app/src/renderer/preview/sandbox.ts
create mode 100644 desktop-app/src/renderer/preview/types.ts
create mode 100644 desktop-app/src/renderer/preview/waitlists.ts
create mode 100644 desktop-app/src/shared/chat.ts
create mode 100644 desktop-app/src/shared/cluster.ts
create mode 100644 desktop-app/src/shared/localServing.ts
create mode 100644 desktop-app/src/shared/sandbox.ts
create mode 100644 desktop-app/src/shared/waitlists.ts
diff --git a/desktop-app/src/main/backend.ts b/desktop-app/src/main/backend.ts
index 7b9a3af161..addbabd7ab 100644
--- a/desktop-app/src/main/backend.ts
+++ b/desktop-app/src/main/backend.ts
@@ -35,6 +35,10 @@ const resources = new Set([
'insights-month',
'request-history',
'hardware',
+ 'cluster',
+ 'sandbox',
+ 'sandbox-logs',
+ 'waitlists',
]);
export function validateDiscovery(value: unknown): {
port: number;
diff --git a/desktop-app/src/main/chat.ts b/desktop-app/src/main/chat.ts
new file mode 100644
index 0000000000..d228e1e50f
--- /dev/null
+++ b/desktop-app/src/main/chat.ts
@@ -0,0 +1,29 @@
+import type { ChatEvent, ChatModels, ChatRequest } from '../shared/chat';
+import type { Backend } from './backend';
+
+// Chat with this Mac's local API. The main process holds the local API key and makes every
+// request, so the renderer never sees it; only a loopback base URL from the native snapshot is
+// ever called. Each streamed answer is published as ChatEvents tagged with its stream ID.
+export class ChatRelay {
+ constructor(
+ private backend: Backend,
+ private publish: (event: ChatEvent) => void,
+ ) {}
+
+ async models(): Promise {
+ return { models: [], error: 'Chat is not available in this build.', code: 'unavailable' };
+ }
+
+ async send(_request: unknown): Promise<{ stream: string }> {
+ void this.backend;
+ void this.publish;
+ throw new Error('Chat is not available in this build.');
+ }
+
+ async cancel(_stream: unknown) {}
+
+ // Ends every stream, such as when the window navigates or closes.
+ reset() {}
+}
+
+export type { ChatRequest };
diff --git a/desktop-app/src/main/clusterSession.ts b/desktop-app/src/main/clusterSession.ts
new file mode 100644
index 0000000000..fd073561c1
--- /dev/null
+++ b/desktop-app/src/main/clusterSession.ts
@@ -0,0 +1,33 @@
+import type { ClusterSession } from '../shared/cluster';
+import type { Backend } from './backend';
+
+// The guided cluster setup session, run by the native API (`/control/v1/cluster/session`). This
+// relays the session's routes and holds one event stream while the renderer watches it,
+// publishing the whole session on every change.
+export class ClusterSessionRelay {
+ constructor(
+ private backend: Backend,
+ private publish: (session: ClusterSession) => void,
+ ) {}
+
+ async current(): Promise {
+ return null;
+ }
+
+ async start(_start: unknown): Promise {
+ void this.backend;
+ void this.publish;
+ throw new Error('Cluster setup from the app needs a newer Darkbloom CLI.');
+ }
+
+ async answer(_answer: unknown): Promise {
+ throw new Error('Cluster setup from the app needs a newer Darkbloom CLI.');
+ }
+
+ acquire() {}
+
+ release() {}
+
+ // Drops every subscription, such as when the renderer navigates or crashes.
+ reset() {}
+}
diff --git a/desktop-app/src/main/ipc.ts b/desktop-app/src/main/ipc.ts
index 02f41db44a..8e93a81466 100644
--- a/desktop-app/src/main/ipc.ts
+++ b/desktop-app/src/main/ipc.ts
@@ -2,10 +2,18 @@ import { app, clipboard, ipcMain, shell } from 'electron';
import path from 'node:path';
import type { Backend } from './backend';
import { HardwareWatch } from './hardware';
+import { ChatRelay } from './chat';
+import { ClusterSessionRelay } from './clusterSession';
import type { desktopUpdates } from './updates';
import type { MainWindow } from './window';
import type { SystemInfo } from '../shared/macos';
-import { clipboardText, externalURL, isTrustedSender, softwareUpdateURL } from './security';
+import {
+ approvalURL,
+ clipboardText,
+ externalURL,
+ isTrustedSender,
+ softwareUpdateURL,
+} from './security';
function installScript() {
return path.join(
@@ -61,14 +69,45 @@ export function registerIPC(options: {
(signal) => backend.openHardwareEvents(signal),
(sample) => window.send('hardware:sample', sample),
);
+ const chat = new ChatRelay(backend, (event) => window.send('chat:event', event));
+ const clusterSession = new ClusterSessionRelay(backend, (session) =>
+ window.send('cluster:session', session),
+ );
window.webContents?.on('did-start-navigation', (details) => {
- if (details.isMainFrame && !details.isSameDocument) hardware.reset();
+ if (details.isMainFrame && !details.isSameDocument) {
+ hardware.reset();
+ chat.reset();
+ clusterSession.reset();
+ }
+ });
+ window.webContents?.on('render-process-gone', () => {
+ hardware.reset();
+ chat.reset();
+ clusterSession.reset();
});
- window.webContents?.on('render-process-gone', () => hardware.reset());
handle('hardware:watch', () => {
if (!smokeTest) hardware.acquire();
});
handle('hardware:unwatch', () => hardware.release());
+ handle('chat:models', () => chat.models());
+ handle('chat:send', (request) => {
+ if (smokeTest) throw new Error('Chat is disabled in UI smoke tests');
+ return chat.send(request);
+ });
+ handle('chat:cancel', (stream) => chat.cancel(stream));
+ handle('cluster:session', () => clusterSession.current());
+ handle('cluster:session-start', (start) => {
+ if (smokeTest) throw new Error('Native actions are disabled in UI smoke tests');
+ return clusterSession.start(start);
+ });
+ handle('cluster:session-answer', (answer) => clusterSession.answer(answer));
+ handle('cluster:session-watch', () => {
+ if (!smokeTest) clusterSession.acquire();
+ });
+ handle('cluster:session-unwatch', () => clusterSession.release());
+ handle('app:approval', async (url) => {
+ await shell.openExternal(approvalURL(url));
+ });
handle('app:update-status', () => updates.status());
handle('app:update', () => updates.check());
handle('app:apply-update', () => updates.apply());
diff --git a/desktop-app/src/main/security.ts b/desktop-app/src/main/security.ts
index 9e701f5bc5..05ac3ef980 100644
--- a/desktop-app/src/main/security.ts
+++ b/desktop-app/src/main/security.ts
@@ -70,6 +70,25 @@ export function externalURL(target: unknown, deviceLinkURL: string | undefined)
return url;
}
+// A sandbox setup's browser approval page, from the installer's own event: https on a
+// Darkbloom host only (darkbloom.dev, darkbloom.ai and their subdomains), without credentials.
+export function approvalURL(value: unknown) {
+ if (typeof value !== 'string' || value.length > 2048) throw new Error('Unsupported link');
+ let url: URL;
+ try {
+ url = new URL(value);
+ } catch {
+ throw new Error('Unsupported link');
+ }
+ const host = url.hostname;
+ const darkbloom = ['darkbloom.dev', 'darkbloom.ai'].some(
+ (domain) => host === domain || host.endsWith('.' + domain),
+ );
+ if (url.protocol !== 'https:' || !darkbloom || url.username || url.password)
+ throw new Error('Unsupported link');
+ return url.toString();
+}
+
export function clipboardText(text: unknown) {
if (typeof text !== 'string' || text.length > 65536) throw new Error('Invalid clipboard value');
return text;
diff --git a/desktop-app/src/preload/index.ts b/desktop-app/src/preload/index.ts
index 18547870d4..d84b2eec32 100644
--- a/desktop-app/src/preload/index.ts
+++ b/desktop-app/src/preload/index.ts
@@ -29,5 +29,21 @@ const api: DesktopAPI = {
void ipcRenderer.invoke('hardware:unwatch');
};
},
+ chatModels: () => ipcRenderer.invoke('chat:models'),
+ chatSend: (request) => ipcRenderer.invoke('chat:send', request),
+ chatCancel: (stream) => ipcRenderer.invoke('chat:cancel', stream),
+ onChat: (callback) => subscribe('chat:event', callback),
+ clusterSession: () => ipcRenderer.invoke('cluster:session'),
+ startClusterSession: (start) => ipcRenderer.invoke('cluster:session-start', start),
+ answerClusterSession: (answer) => ipcRenderer.invoke('cluster:session-answer', answer),
+ onClusterSession: (callback) => {
+ const unsubscribe = subscribe('cluster:session', callback);
+ void ipcRenderer.invoke('cluster:session-watch');
+ return () => {
+ unsubscribe();
+ void ipcRenderer.invoke('cluster:session-unwatch');
+ };
+ },
+ openApproval: (url) => ipcRenderer.invoke('app:approval', url),
};
contextBridge.exposeInMainWorld('darkbloom', api);
diff --git a/desktop-app/src/renderer/App.tsx b/desktop-app/src/renderer/App.tsx
index a1c84f7edc..fc087f6678 100644
--- a/desktop-app/src/renderer/App.tsx
+++ b/desktop-app/src/renderer/App.tsx
@@ -1,5 +1,15 @@
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
-import { Box, Home as HomeIcon, Monitor, Trophy, Zap } from 'lucide-react';
+import {
+ Box,
+ Boxes,
+ Home as HomeIcon,
+ MessageCircle,
+ Monitor,
+ Network,
+ Ticket,
+ Trophy,
+ Zap,
+} from 'lucide-react';
import type { Route } from '../shared/contracts';
import { api, isPreview, useBackend } from './useBackend';
import { Home } from './features/Home';
@@ -17,11 +27,19 @@ import { GetHelp, HelpControl } from './components/Help';
import { AccountControl } from './components/AccountControl';
import { SocialLinks } from './components/SocialLinks';
import { useFocusRecovery } from './useFocusRecovery';
+import { Chat } from './features/chat/Chat';
+import { Cluster } from './features/cluster/Cluster';
+import { Sandboxes } from './features/sandboxes/Sandboxes';
+import { Waitlists } from './features/waitlists/Waitlists';
const navigation = [
{ id: 'home', label: 'Home', icon: HomeIcon },
+ { id: 'chat', label: 'Chat', icon: MessageCircle },
{ id: 'machines', label: 'My Macs', icon: Monitor },
+ { id: 'cluster', label: 'Clusters', icon: Network },
+ { id: 'sandboxes', label: 'Sandboxes', icon: Boxes },
{ id: 'leaderboard', label: 'Leaderboard', icon: Trophy },
{ id: 'updates', label: 'Updates', icon: Box },
+ { id: 'waitlists', label: 'Early access', icon: Ticket },
] as const;
export default function App() {
const [{ route, machine }, setView] = useState<{ route: Route; machine: MachineSelection }>({
@@ -109,7 +127,7 @@ export default function App() {
{backend.status.state !== 'ready' && (
@@ -135,6 +153,10 @@ export default function App() {
{route === 'earnings' && }
{route === 'updates' && }
{route === 'leaderboard' && }
+ {route === 'chat' && }
+ {route === 'cluster' && }
+ {route === 'sandboxes' && }
+ {route === 'waitlists' && }
- {curl}
-
- >
+ {local ? (
+ <>
+
+ {local.mode === 'both' && }
+ {localAPI && }
+ >
+ ) : (
+
+ )}
+ {localAPI && (
+ <>
+
+ {local && }
+
+ >
+ )}
+
);
}
diff --git a/desktop-app/src/renderer/features/studio/ChoiceCard.tsx b/desktop-app/src/renderer/features/studio/ChoiceCard.tsx
new file mode 100644
index 0000000000..3189e457f5
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/ChoiceCard.tsx
@@ -0,0 +1,75 @@
+import { useId, type ReactNode } from 'react';
+import { Check } from 'lucide-react';
+import styles from './studio.module.css';
+
+// One answer of a choice, as a card around a native radio. The radio is named by the title alone;
+// the badge, the marker (what is saved), the line and the hint describe it.
+export function ChoiceCard({
+ name,
+ checked,
+ disabled = false,
+ onSelect,
+ title,
+ detail,
+ badge,
+ marker,
+ hint,
+}: {
+ name: string;
+ checked: boolean;
+ disabled?: boolean;
+ onSelect: () => void;
+ title: string;
+ detail: ReactNode;
+ badge?: string;
+ marker?: string;
+ hint?: string;
+}) {
+ const id = useId();
+ const part = (what: string) => `${id}-${what}`;
+ const described = [
+ badge && part('badge'),
+ marker && part('marker'),
+ part('detail'),
+ hint && part('hint'),
+ ]
+ .filter(Boolean)
+ .join(' ');
+ return (
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/ConnectionDetails.tsx b/desktop-app/src/renderer/features/studio/ConnectionDetails.tsx
new file mode 100644
index 0000000000..8a10a42950
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/ConnectionDetails.tsx
@@ -0,0 +1,63 @@
+import { useId } from 'react';
+import { Check, Copy } from 'lucide-react';
+import type { Snapshot } from '../../../shared/contracts';
+import type { LocalServing } from '../../../shared/localServing';
+import { Button, Notice } from '../../components/UI';
+import type { Copier } from './useCopy';
+import type { EndpointKey } from './useEndpointKey';
+import { address, reach } from './words';
+
+// Base URL, the key (read only on Reveal) and, from a runtime that reports it, the port and
+// address this Mac's one local API listens on.
+export function ConnectionDetails({
+ endpoint,
+ local,
+ endpointKey,
+ copier,
+ problem,
+}: {
+ endpoint: Snapshot['endpoint'];
+ local?: LocalServing;
+ endpointKey: EndpointKey;
+ copier: Copier;
+ problem: string;
+}) {
+ const { copied, copy } = copier;
+ const heading = useId();
+ return (
+
+ Connection details
+
+ Base URL
+ {endpoint?.base_url || (local ? 'Not running' : 'Not enabled')}
+ {endpoint && (
+
+ )}
+
+
+ API key
+ {endpointKey.key || '••••••••••••••••'}
+
+
+ {local?.port != null && (
+
+ Listens on
+ {address(local.bind, local.port)}
+
+ )}
+
+ {endpoint?.authenticated === false ? 'No API key required.' : 'Requires an API key.'}{' '}
+ {reach(local?.bind)}
+
+ {problem && {problem}}
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/LegacyServingMode.tsx b/desktop-app/src/renderer/features/studio/LegacyServingMode.tsx
new file mode 100644
index 0000000000..053de3ffa9
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/LegacyServingMode.tsx
@@ -0,0 +1,82 @@
+import { useState } from 'react';
+import { Play } from 'lucide-react';
+import type { NativeModel } from '../../../shared/contracts';
+import type { BackendState } from '../../useBackend';
+import { Button } from '../../components/UI';
+import styles from './studio.module.css';
+
+// A runtime without local-first serving: its two ways to serve a local API, as before.
+export function LegacyServingMode({
+ backend,
+ models,
+ model,
+ onModel,
+}: {
+ backend: BackendState;
+ models: NativeModel[];
+ model: string;
+ onModel: (id: string) => void;
+}) {
+ const [mode, setMode] = useState('combined');
+ return (
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/MeFirst.tsx b/desktop-app/src/renderer/features/studio/MeFirst.tsx
new file mode 100644
index 0000000000..0e74086f98
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/MeFirst.tsx
@@ -0,0 +1,123 @@
+import { useEffect, useId, useState } from 'react';
+import { Pause } from 'lucide-react';
+import type { LocalServing } from '../../../shared/localServing';
+import type { BackendState } from '../../useBackend';
+import { Button } from '../../components/UI';
+import { backIn, idleMinutes, meFirstRange } from './words';
+import styles from './studio.module.css';
+
+// Both, me first: whether Darkbloom pauses while you use this Mac, and for how long it stays
+// paused after your last request. A serving process reads both when it starts, so a change made
+// while serving applies at the next restart.
+export function MeFirst({ backend, local }: { backend: BackendState; local: LocalServing }) {
+ const state = backend.state!;
+ const heading = useId();
+ const errorId = useId();
+ const [on, setOn] = useState(local.me_first);
+ const [idle, setIdle] = useState(String(local.me_first_idle_minutes));
+ useEffect(() => {
+ setOn(local.me_first);
+ setIdle(String(local.me_first_idle_minutes));
+ }, [local.me_first, local.me_first_idle_minutes]);
+ const [restart, setRestart] = useState(false);
+ const value = idleMinutes(idle);
+ const invalid = on && value === undefined;
+ const changed = on !== local.me_first || (on && value !== local.me_first_idle_minutes);
+ const paused =
+ local.paused_until != null ? backIn(local.paused_until - state.observed_at) : undefined;
+ const save = async () => {
+ const saved = await backend.act(
+ {
+ action: 'local_settings',
+ me_first: on,
+ me_first_idle_minutes: on && value !== undefined ? value : local.me_first_idle_minutes,
+ },
+ true,
+ );
+ if (saved && state.state !== 'stopped') setRestart(true);
+ };
+ return (
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/RequestExample.tsx b/desktop-app/src/renderer/features/studio/RequestExample.tsx
new file mode 100644
index 0000000000..65464cbb65
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/RequestExample.tsx
@@ -0,0 +1,29 @@
+import { Check, Copy } from 'lucide-react';
+import { Button } from '../../components/UI';
+import type { Copier } from './useCopy';
+
+// A curl request that works as copied: the key stays a placeholder, never a revealed key.
+export function RequestExample({
+ baseURL,
+ model,
+ copier,
+}: {
+ baseURL?: string;
+ model: string;
+ copier: Copier;
+}) {
+ const { copied, copy } = copier;
+ const curl = `curl ${baseURL || 'http://127.0.0.1:8000/v1'}/chat/completions \\\n -H 'Authorization: Bearer ' \\\n -H 'Content-Type: application/json' \\\n -d '${JSON.stringify({ model, messages: [{ role: 'user', content: 'Hello' }] })}'`;
+ return (
+
+
+
Make a request
+
+
+ {curl}
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/RequestRoute.tsx b/desktop-app/src/renderer/features/studio/RequestRoute.tsx
new file mode 100644
index 0000000000..ea6e0074eb
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/RequestRoute.tsx
@@ -0,0 +1,127 @@
+import { useEffect, useId, useState, type FormEvent } from 'react';
+import { KeyRound } from 'lucide-react';
+import type { LocalServing, RequestRoute as Route } from '../../../shared/localServing';
+import type { BackendState } from '../../useBackend';
+import { Button, Status } from '../../components/UI';
+import { ChoiceCard } from './ChoiceCard';
+import { effectiveRoute, keyRefusal, routeChoices } from './words';
+import styles from './studio.module.css';
+
+// Where your requests go when this Mac can't take them (`darkbloom route …`). A running local API
+// uses a saved route from its next request, so saving restarts nothing. Your other Macs and the
+// network need the account API key, which only `route_key` ever carries.
+export function RequestRoute({ backend, local }: { backend: BackendState; local: LocalServing }) {
+ const heading = useId();
+ const group = useId();
+ const current = effectiveRoute(local);
+ const [draft, setDraft] = useState(current);
+ useEffect(() => setDraft(current), [current]);
+ const needsKey = (route: Route) => route !== 'this-mac' && !local.route_key;
+ return (
+
+ When this Mac can’t take a request
+
+
+
+
+
+
+ );
+}
+
+// The account API key goes from the field straight into `route_key` and is cleared as it is sent:
+// it is never shown, kept or read back. The runtime says only whether one is saved.
+function AccountKey({ backend, saved }: { backend: BackendState; saved: boolean }) {
+ const inputId = useId();
+ const errorId = useId();
+ const [replacing, setReplacing] = useState(false);
+ const [value, setValue] = useState('');
+ useEffect(() => {
+ if (!saved) setReplacing(false);
+ }, [saved]);
+ if (saved && !replacing)
+ return (
+
+
+ Account API key
+ Saved in this Mac’s Keychain.
+
+ Key saved
+
+
+ );
+ const key = value.trim();
+ const refusal = key ? keyRefusal(key) : undefined;
+ const submit = async (event: FormEvent) => {
+ event.preventDefault();
+ if (!key || refusal || backend.busy) return;
+ setValue('');
+ if (await backend.act({ action: 'route_key', key }, true)) setReplacing(false);
+ };
+ return (
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/ServingChoice.tsx b/desktop-app/src/renderer/features/studio/ServingChoice.tsx
new file mode 100644
index 0000000000..ac4c95c9f2
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/ServingChoice.tsx
@@ -0,0 +1,112 @@
+import { useEffect, useId, useState } from 'react';
+import { ArrowUpRight, Play } from 'lucide-react';
+import type { Route } from '../../../shared/contracts';
+import type { LocalServing, ServingMode } from '../../../shared/localServing';
+import type { BackendState } from '../../useBackend';
+import { Button } from '../../components/UI';
+import { modelName } from '../../models/facts';
+import { ChoiceCard } from './ChoiceCard';
+import { names, servableModels, servingChoices, servingDetail, servingNow } from './words';
+import styles from './studio.module.css';
+
+// Each way to serve is one `start` flag; the start saves it as `[local] mode` once it goes ahead,
+// and the background service, restart and update serve it from then on.
+const startFlag: Record = {
+ local: { local: true },
+ network: { network: true },
+ both: { endpoint: true },
+};
+
+// The start question as three answers, the saved one marked. Nothing changes until Apply, which
+// restarts serving the chosen way with the models serving now.
+export function ServingChoice({
+ backend,
+ local,
+ navigate,
+}: {
+ backend: BackendState;
+ local: LocalServing;
+ navigate?: (route: Route) => void;
+}) {
+ const state = backend.state!;
+ const heading = useId();
+ const group = useId();
+ const saved = local.mode;
+ // The question's own default when nothing is saved yet.
+ const [draft, setDraft] = useState(saved ?? 'both');
+ useEffect(() => setDraft(saved ?? 'both'), [saved]);
+ const keep = servingNow(state, draft);
+ const choices = servableModels(state, draft);
+ const [chosen, setChosen] = useState('');
+ const pick = choices.some((model) => model.id === chosen) ? chosen : (choices[0]?.id ?? '');
+ const models = keep.length ? keep.map((model) => model.id) : pick ? [pick] : [];
+ const changed = draft !== saved;
+ // On a paired Mac a start starts the pair, which serves its own way.
+ const paired = !!state.pair;
+ const verb = state.state === 'stopped' ? 'starts' : 'restarts';
+ return (
+
+ How this Mac serves
+
+ {paired ? (
+
+ This Mac is in a pair, which serves its own way.{' '}
+ {navigate && (
+
+ )}
+
+ ) : (
+ <>
+ {changed &&
+ !keep.length &&
+ (choices.length ? (
+
+ ) : (
+ No model to serve yet. Get one in Models.
+ ))}
+
+
+
+ {changed && models.length
+ ? `Applying ${verb} serving with ${names(models.map((id) => modelName(state.models, id)))}.`
+ : `Applying ${verb} serving.`}
+
+
+ >
+ )}
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/ToolSetup.tsx b/desktop-app/src/renderer/features/studio/ToolSetup.tsx
new file mode 100644
index 0000000000..095a4c784d
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/ToolSetup.tsx
@@ -0,0 +1,64 @@
+import { useId } from 'react';
+import { Check, Copy, Wrench } from 'lucide-react';
+import type { LocalTool } from '../../../shared/localServing';
+import type { BackendState } from '../../useBackend';
+import { Button } from '../../components/UI';
+import type { Copier } from './useCopy';
+import { supports, toolCommand, toolName } from './words';
+import styles from './studio.module.css';
+
+const tools: LocalTool[] = ['opencode', 'hermes'];
+
+// `darkbloom --opencode` / `--hermes` point the tool at this Mac's local API, with a backup and a
+// one-line undo in the result. A runtime without `tool_setup` gets the command to run instead.
+export function ToolSetup({ backend, copier }: { backend: BackendState; copier: Copier }) {
+ const state = backend.state!;
+ const endpoint = state.endpoint;
+ const { copied, copy } = copier;
+ const heading = useId();
+ if (!supports(state, 'tool_setup'))
+ return (
+
+ Use it in your tools
+ {tools.map((tool) => (
+
+ {toolName[tool]}
+ {toolCommand[tool]}
+
+
+ ))}
+ Run it in Terminal.
+
+ );
+ // Tools need this Mac's local API running, with its key.
+ const blocked = !endpoint
+ ? 'Start serving first.'
+ : !endpoint.authenticated
+ ? 'Tools need the local API’s key. Start it without --no-auth.'
+ : undefined;
+ return (
+
+ Use it in your tools
+
+ {tools.map((tool) => (
+
+ ))}
+
+ {blocked && {blocked}}
+
+ );
+}
diff --git a/desktop-app/src/renderer/features/studio/studio.module.css b/desktop-app/src/renderer/features/studio/studio.module.css
new file mode 100644
index 0000000000..5a70ee5c0c
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/studio.module.css
@@ -0,0 +1,202 @@
+.studio {
+ container: studio / inline-size;
+}
+
+/* Answers of a choice: cards around native radios, three across, one column when narrow. */
+.choices {
+ display: grid;
+ grid-template-columns: repeat(3, minmax(0, 1fr));
+ gap: 14px;
+ min-width: 0;
+ margin: 0;
+ padding: 0;
+ border: 0;
+}
+.choice {
+ display: grid;
+ grid-template-columns: 16px minmax(0, 1fr);
+ align-items: start;
+ gap: 12px;
+ padding: 20px;
+ border: 1px solid var(--line);
+ border-radius: 5px;
+ cursor: pointer;
+ transition:
+ background var(--hover-duration),
+ border-color var(--hover-duration);
+}
+.choice:not([data-checked]):not(:has(input:disabled)):hover {
+ border-color: rgba(var(--contrast-rgb), 0.2);
+ background: rgba(var(--contrast-rgb), 0.02);
+}
+.choice[data-checked] {
+ border-color: color-mix(in srgb, var(--accent-brand) 45%, transparent);
+ background: color-mix(in srgb, var(--accent-brand) 4%, transparent);
+}
+.choice[data-checked]:not(:has(input:disabled)):hover {
+ border-color: color-mix(in srgb, var(--accent-brand) 70%, transparent);
+}
+.choice:has(input:disabled) {
+ cursor: not-allowed;
+}
+.choice:has(input:disabled) .choiceHead,
+.choice:has(input:disabled) .detail {
+ opacity: 0.55;
+}
+.choice input {
+ margin: 1px 0 0;
+ accent-color: var(--blue);
+}
+.choice input:disabled {
+ cursor: not-allowed;
+}
+.choiceBody {
+ display: grid;
+ gap: 8px;
+ min-width: 0;
+}
+.choiceHead {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 6px 8px;
+}
+.choiceHead strong {
+ font-size: 12px;
+ font-weight: 500;
+}
+.detail {
+ font-size: 11px;
+ line-height: 1.55;
+ color: var(--muted);
+}
+.badge {
+ font-size: 10px;
+ color: var(--accent-brand);
+ background: var(--blue-wash);
+ padding: 3px 7px;
+ border-radius: 4px;
+}
+.marker {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 10px;
+ color: var(--positive);
+}
+.hint {
+ font-size: 11px;
+ color: var(--warning);
+}
+
+/* A section's action, with what it does beside it. */
+.apply {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 12px 16px;
+ margin-top: 20px;
+}
+.apply small,
+.note {
+ font-size: 11px;
+ line-height: 1.6;
+ color: var(--muted);
+}
+.note {
+ display: block;
+ margin-top: 16px;
+}
+.note :global(.text-link) {
+ font-size: 11px;
+}
+
+.paused {
+ display: flex;
+ align-items: center;
+ gap: 9px;
+ margin-bottom: 4px;
+ font-size: 12px;
+ color: var(--text-secondary);
+}
+.paused > svg {
+ color: var(--accent-brand);
+}
+.paused strong {
+ font-weight: 500;
+ color: var(--text-primary);
+}
+
+/* A field with its error under it, right-aligned in a setting row. */
+.field {
+ display: grid;
+ justify-items: end;
+ gap: 8px;
+}
+.minutes,
+.keyControls {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-size: 12px;
+ color: var(--muted);
+}
+.minutes input,
+.keyInput {
+ background: var(--panel-bg);
+ border: 1px solid rgba(var(--contrast-rgb), 0.106);
+ border-radius: 4px;
+ padding: 10px 12px;
+ font-size: 12px;
+ color: var(--text-primary);
+ transition: border-color var(--hover-duration);
+}
+.minutes input {
+ width: 64px;
+ appearance: textfield;
+}
+.minutes input::-webkit-inner-spin-button,
+.minutes input::-webkit-outer-spin-button {
+ appearance: none;
+ margin: 0;
+}
+.keyInput {
+ width: 240px;
+ min-width: 0;
+}
+.minutes input:not(:disabled):hover,
+.keyInput:not(:disabled):hover {
+ border-color: rgba(var(--contrast-rgb), 0.24);
+}
+.minutes input[aria-invalid='true'],
+.keyInput[aria-invalid='true'] {
+ border-color: var(--negative);
+}
+/* Outranks the setting row's muted small text. */
+.field .error {
+ max-width: 340px;
+ margin-top: 0;
+ font-size: 11px;
+ color: var(--negative);
+}
+
+.tools {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 12px;
+}
+
+@container studio (max-width: 640px) {
+ .choices {
+ grid-template-columns: minmax(0, 1fr);
+ }
+ .field {
+ justify-items: start;
+ }
+ .keyControls {
+ flex-wrap: wrap;
+ }
+ .keyInput {
+ width: 100%;
+ }
+}
diff --git a/desktop-app/src/renderer/features/studio/useCopy.ts b/desktop-app/src/renderer/features/studio/useCopy.ts
new file mode 100644
index 0000000000..25b6edb8c9
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/useCopy.ts
@@ -0,0 +1,24 @@
+import { useState } from 'react';
+import type { LocalTool } from '../../../shared/localServing';
+import { api } from '../../useBackend';
+
+export type CopyTarget = 'url' | 'example' | LocalTool;
+
+// Which value was just copied, so only that button confirms it; a failed copy is reported
+// instead of claimed.
+export function useCopy(report: (problem: string) => void) {
+ const [copied, setCopied] = useState(null);
+ const copy = async (value: string, what: CopyTarget) => {
+ try {
+ report('');
+ await api?.copy(value);
+ setCopied(what);
+ setTimeout(() => setCopied((current) => (current === what ? null : current)), 1600);
+ } catch {
+ report('Couldn’t copy to the clipboard.');
+ }
+ };
+ return { copied, copy };
+}
+
+export type Copier = ReturnType;
diff --git a/desktop-app/src/renderer/features/studio/useEndpointKey.ts b/desktop-app/src/renderer/features/studio/useEndpointKey.ts
new file mode 100644
index 0000000000..15a0a28f9f
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/useEndpointKey.ts
@@ -0,0 +1,48 @@
+import { useEffect, useRef, useState } from 'react';
+import type { BackendState } from '../../useBackend';
+import { api } from '../../useBackend';
+
+// The local API key, read only on an explicit Reveal. Local credentials are independent of account
+// sign-in: ordinary snapshots and model changes keep a reveal, while a new endpoint, runtime or
+// provider session needs another explicit Reveal, and a read that resolves for an obsolete one is
+// ignored.
+export function useEndpointKey(backend: BackendState, report: (problem: string) => void) {
+ const state = backend.state!;
+ const endpoint = state.endpoint;
+ const [revealed, setKey] = useState<{ identity: string; key: string }>();
+ const session = useRef<{ identity: string; alive: boolean; request: number } | null>(null);
+ const identity =
+ endpoint?.authenticated && backend.status.state === 'ready'
+ ? JSON.stringify([state.installation_id, state.activity.started_at, endpoint.base_url])
+ : undefined;
+ useEffect(() => {
+ setKey(undefined);
+ if (!identity) return;
+ const current = { identity, alive: true, request: 0 };
+ session.current = current;
+ return () => {
+ current.alive = false;
+ if (session.current === current) session.current = null;
+ };
+ }, [identity]);
+ // Also mask during the render that precedes effect cleanup for a changed endpoint.
+ const key = revealed?.identity === identity ? revealed?.key : undefined;
+ const toggle = async () => {
+ const current = session.current;
+ if (!identity || !current?.alive || current.identity !== identity) return;
+ const request = ++current.request;
+ if (key) return setKey(undefined);
+ try {
+ report('');
+ const value = await api?.read<{ key: string }>('endpoint-key');
+ if (current.alive && current.request === request)
+ setKey(value?.key ? { identity: current.identity, key: value.key } : undefined);
+ } catch {
+ if (current.alive && current.request === request)
+ report('Couldn’t read the API key. Try again.');
+ }
+ };
+ return { key, available: !!identity, toggle };
+}
+
+export type EndpointKey = ReturnType;
diff --git a/desktop-app/src/renderer/features/studio/words.ts b/desktop-app/src/renderer/features/studio/words.ts
new file mode 100644
index 0000000000..f3da57afde
--- /dev/null
+++ b/desktop-app/src/renderer/features/studio/words.ts
@@ -0,0 +1,125 @@
+import type { NativeModel, Snapshot } from '../../../shared/contracts';
+import type { LocalServing, RequestRoute, ServingMode } from '../../../shared/localServing';
+import { servesNetwork } from '../../models/selection';
+
+// Studio's words are the CLI's own (`ServingQuestion`, `LocalFirstWords`, `MeFirstWords`,
+// `RouteChoiceFlow`, `LocalRouterAccountKeyFormat` in provider-swift/Sources), so the app and
+// `darkbloom start`, `status` and `route` say the same thing.
+
+export type StudioCapability = 'local_serving' | 'tool_setup' | 'update_rollback';
+
+export const supports = (state: Snapshot, capability: StudioCapability) =>
+ !!state.capabilities?.includes(capability);
+
+// `Snapshot.local`, only from a runtime that offers local-first serving.
+export const localServing = (state: Snapshot): LocalServing | undefined =>
+ supports(state, 'local_serving') ? state.local : undefined;
+
+// "1 minute", "2 minutes".
+export const minutes = (count: number) => (count === 1 ? '1 minute' : `${count} minutes`);
+
+// The start question's three answers, in its order.
+export const servingChoices: { mode: ServingMode; title: string }[] = [
+ { mode: 'local', title: 'Only me' },
+ { mode: 'network', title: 'Darkbloom network' },
+ { mode: 'both', title: 'Both, me first' },
+];
+
+// The question's line for each answer; Both says so when me first is off.
+export function servingDetail(
+ mode: ServingMode,
+ local: Pick,
+) {
+ if (mode === 'local')
+ return 'Darkbloom never contacts this Mac. Your tools use this Mac’s own API.';
+ if (mode === 'network') return 'This Mac serves Darkbloom and earns while it runs.';
+ return local.me_first
+ ? 'This Mac serves Darkbloom while you aren’t using it. When you use it, Darkbloom traffic ' +
+ `pauses until you’ve been idle for ${minutes(local.me_first_idle_minutes)}.`
+ : 'Darkbloom keeps serving while you use this Mac (me first is off).';
+}
+
+// Only me runs any model on this Mac; the network routes only catalog models.
+export const servableModels = (state: Snapshot, mode: ServingMode): NativeModel[] =>
+ state.models.filter(
+ (model) => model.downloaded && (mode === 'local' ? model.eligible : servesNetwork(model)),
+ );
+
+// The models serving now that the chosen way can serve; applying keeps them.
+export const servingNow = (state: Snapshot, mode: ServingMode) =>
+ servableModels(state, mode).filter((model) => model.serving);
+
+// "A", "A and B", "A, B and C".
+export function names(items: string[]) {
+ if (items.length < 2) return items.join('');
+ return `${items.slice(0, -1).join(', ')} and ${items.at(-1)}`;
+}
+
+export const meFirstRange = { min: 1, max: 120 };
+
+// Whole minutes from 1 to 120, else undefined.
+export function idleMinutes(value: string) {
+ const text = value.trim();
+ if (!/^\d+$/.test(text)) return undefined;
+ const count = Number(text);
+ return count >= meFirstRange.min && count <= meFirstRange.max ? count : undefined;
+}
+
+// When Darkbloom comes back if you stay idle, `seconds` from now.
+export function backIn(seconds: number) {
+ if (seconds <= 0) return 'back any moment now';
+ if (seconds < 60) return 'back in under a minute if you stay idle';
+ const total = Math.floor((seconds + 30) / 60);
+ const hours = Math.floor(total / 60);
+ const rest = minutes(total % 60);
+ const span =
+ hours === 0
+ ? rest
+ : `${hours === 1 ? '1 hour' : `${hours} hours`}${total % 60 ? ` ${rest}` : ''}`;
+ return `back in about ${span} if you stay idle`;
+}
+
+// The start question's follow-up, with the local-first guide's line for each answer.
+export const routeChoices: { route: RequestRoute; title: string; detail: string }[] = [
+ { route: 'this-mac', title: 'Only this Mac', detail: 'This Mac’s answer, always.' },
+ { route: 'my-macs', title: 'Only my Macs (free)', detail: 'Your other Macs, at no cost.' },
+ {
+ route: 'my-macs-first',
+ title: 'My Macs first',
+ detail: 'Your other Macs, then the Darkbloom network, billed to your balance.',
+ },
+];
+
+// The saved route, else this Mac only or, once an account key is saved, only my Macs.
+export const effectiveRoute = (local: LocalServing): RequestRoute =>
+ local.route ?? (local.route_key ? 'my-macs' : 'this-mac');
+
+// Why a pasted value can't be an account API key, in the CLI's words; undefined when it can be.
+// The CLI trims spaces and line breaks around the key first, and so does the app.
+export function keyRefusal(key: string) {
+ if (!key) return 'No key was given.';
+ if (key.length > 512) return 'That is longer than any Darkbloom API key.';
+ if ([...key].some((char) => char.charCodeAt(0) <= 0x20 || char.charCodeAt(0) >= 0x7f))
+ return 'An API key has no spaces, line breaks or non-ASCII characters.';
+ if (key.startsWith('dk-local-'))
+ return 'That is this Mac’s local API key; use an account API key from the Darkbloom console.';
+ return undefined;
+}
+
+const loopback = (host: string) =>
+ host === 'localhost' || host === '::1' || /^127(?:\.\d{1,3}){3}$/.test(host);
+
+// Where the local API answers: this Mac only on a loopback address (the default), else the
+// local network too.
+export const reach = (bind: string | null | undefined) =>
+ loopback(bind || '127.0.0.1')
+ ? 'Accessible only on this Mac.'
+ : 'Accessible on your local network.';
+
+export const address = (bind: string | null | undefined, port: number) => {
+ const host = bind || '127.0.0.1';
+ return `${host.includes(':') ? `[${host}]` : host}:${port}`;
+};
+
+export const toolCommand = { opencode: 'darkbloom --opencode', hermes: 'darkbloom --hermes' };
+export const toolName = { opencode: 'OpenCode', hermes: 'Hermes' };
diff --git a/desktop-app/src/renderer/preview/localServing.ts b/desktop-app/src/renderer/preview/localServing.ts
index c82aa56790..fd0c74de71 100644
--- a/desktop-app/src/renderer/preview/localServing.ts
+++ b/desktop-app/src/renderer/preview/localServing.ts
@@ -1,4 +1,160 @@
-import type { FeaturePreview } from './types';
+import type { Snapshot } from '../../shared/contracts';
+import type { LocalServing, ServingMode } from '../../shared/localServing';
+import { keyRefusal, routeChoices } from '../features/studio/words';
+import { previewOperation, previewParam, recordOperation, type FeaturePreview } from './types';
-// Development preview of localServing: fixtures and simulated actions. Never used for live data.
-export const localServingPreview: FeaturePreview = {};
+// Development preview of local-first serving: a `Snapshot.local` fixture, the capabilities that go
+// with it and simulated actions in the CLI's words. Never used for live data. `&local=only-me`,
+// `network` or `both` (the default) is the saved choice; `&local=paused` is Both, me first with
+// Darkbloom paused for you; `&local=unsupported` is a runtime without any of it. No account key is
+// saved until one is entered, and an entered key is checked for its shape only and never kept.
+const scenario = previewParam('local');
+const modes: Record = {
+ 'only-me': 'local',
+ network: 'network',
+ both: 'both',
+ paused: 'both',
+};
+const capabilities = ['local_serving', 'tool_setup', 'update_rollback'];
+// A snapshot with no capability list is a runtime from before the list, which the app reads as
+// offering Autopilot and the waitlist: they stay offered once the list exists.
+const listless = ['autopilot', 'waitlist'];
+const port = 8001;
+
+const endpointFor = (mode: ServingMode, models: string[]): Snapshot['endpoint'] =>
+ mode === 'network'
+ ? undefined
+ : { base_url: `http://127.0.0.1:${port}/v1`, authenticated: true, models };
+
+const settle = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
+
+export const localServingPreview: FeaturePreview = {
+ snapshot(snapshot) {
+ if (scenario === 'unsupported') return snapshot;
+ const mode = modes[scenario ?? ''] ?? 'both';
+ const local: LocalServing = {
+ mode,
+ me_first: true,
+ me_first_idle_minutes: 2,
+ route: null,
+ route_key: false,
+ port,
+ bind: '127.0.0.1',
+ paused_until: scenario === 'paused' ? snapshot.observed_at + 100 : null,
+ };
+ return {
+ ...snapshot,
+ capabilities: [
+ ...(snapshot.capabilities ?? listless),
+ ...capabilities.filter((name) => !snapshot.capabilities?.includes(name)),
+ ],
+ local,
+ endpoint: endpointFor(mode, snapshot.endpoint?.models ?? snapshot.machine.models),
+ };
+ },
+ async act(store, action) {
+ const state = store.get();
+ const local = state.local;
+ if (!local) return undefined;
+ const done = (message: string, next: Snapshot = store.get()) =>
+ recordOperation(store, previewOperation(action, 'succeeded', message), next);
+ const refused = (message: string) =>
+ recordOperation(store, previewOperation(action, 'failed', message));
+ // The snapshot as it is now, after a simulated wait, with `[local]` changed.
+ const latest = (change: Partial): Snapshot => {
+ const now = store.get();
+ return { ...now, local: { ...now.local!, ...change } };
+ };
+ switch (action.action) {
+ case 'start': {
+ // A start that names no way to serve is the shared preview's.
+ const mode = action.local
+ ? 'local'
+ : action.network
+ ? 'network'
+ : action.endpoint
+ ? 'both'
+ : undefined;
+ if (!mode) return undefined;
+ return done('Preview action complete', {
+ ...state,
+ state: 'running',
+ readiness: 'Connected and ready for requests',
+ local: { ...local, mode, paused_until: null },
+ endpoint: endpointFor(mode, action.models),
+ models: state.models.map((model) => ({
+ ...model,
+ serving: action.models.includes(model.id),
+ loaded: action.models.includes(model.id),
+ })),
+ });
+ }
+ case 'route': {
+ await settle(400);
+ if (action.route !== 'this-mac' && !store.get().local?.route_key)
+ return refused(
+ `✗ Not saved: \`darkbloom route ${action.route}\` passes your requests on with your account API key, and this Mac has none saved.`,
+ );
+ const meaning = routeChoices.find((choice) => choice.route === action.route)!.detail;
+ return done(
+ `✓ Saved. Your local API uses it now.\n${meaning}`,
+ latest({ route: action.route }),
+ );
+ }
+ case 'route_key': {
+ const refusal = keyRefusal(action.key.trim());
+ await settle(700);
+ if (refusal) return refused(`✗ Not saved: ${refusal}`);
+ return done(
+ '✓ Account key saved in this Mac’s Keychain. Darkbloom accepted it; your Macs serve 2 models now.\nYour local API uses it now.',
+ latest({ route_key: true }),
+ );
+ }
+ case 'local_settings': {
+ await settle(400);
+ const minutes = action.me_first_idle_minutes;
+ if (!Number.isInteger(minutes) || minutes < 1 || minutes > 120)
+ return refused(
+ `[local] me_first_idle_minutes must be a whole number of minutes from 1 to 120, not ${minutes}.`,
+ );
+ return done(
+ 'Saved. It applies when serving restarts.',
+ latest({
+ me_first: action.me_first,
+ me_first_idle_minutes: minutes,
+ ...(action.me_first ? {} : { paused_until: null }),
+ }),
+ );
+ }
+ case 'tool_setup': {
+ const tool = action.tool === 'opencode' ? 'OpenCode' : 'Hermes';
+ await settle(1200);
+ if (!store.get().endpoint)
+ return refused(
+ `✗ This Mac serves only the Darkbloom network, so ${tool} has no local address to use.`,
+ );
+ return done(
+ action.tool === 'opencode'
+ ? [
+ '✓ OpenCode can use Darkbloom: 2 models.',
+ ' Changed: ~/.config/opencode/opencode.jsonc (added the "darkbloom" provider; nothing else changed)',
+ ' Pick Darkbloom once with /models; OpenCode remembers it.',
+ ].join('\n')
+ : [
+ '✓ Hermes can use Darkbloom: 2 models.',
+ ' Changed: ~/.hermes/config.yaml (added the "darkbloom" provider)',
+ ' New Hermes chats now use Darkbloom’s GPT-OSS 20B. Switch back: hermes model',
+ ].join('\n'),
+ );
+ }
+ case 'update_rollback': {
+ await settle(1500);
+ return done(
+ `Rolled back: v${state.version} -> v0.9.15.\nv${state.version} is quarantined on this Mac: automatic updates skip it, and the next newer release installs normally.`,
+ );
+ }
+ default:
+ return undefined;
+ }
+ },
+};
diff --git a/desktop-app/src/shared/localServing.ts b/desktop-app/src/shared/localServing.ts
index da875826e2..f630834766 100644
--- a/desktop-app/src/shared/localServing.ts
+++ b/desktop-app/src/shared/localServing.ts
@@ -2,17 +2,25 @@
// your requests go when this Mac's local API can't take them; and tools set up to use it
// (docs/provider/cli-reference.md#how-this-mac-serves-one-question).
+// `[local] mode`: `local` (Only me), `network` (Darkbloom network, no local API) or `both` (Both,
+// me first: a local API beside Darkbloom).
+export type ServingMode = 'local' | 'network' | 'both';
+// `[local] route`: where your requests go when this Mac's local API can't take them.
+export type RequestRoute = 'this-mac' | 'my-macs' | 'my-macs-first';
+// `darkbloom --opencode` / `--hermes`.
+export type LocalTool = 'opencode' | 'hermes';
+
// `Snapshot.local`, from provider.toml's `[local]` section. Absent from older runtimes.
export interface LocalServing {
- // The saved choice: `local` (Only me), `network` (Darkbloom network, no local API) or `both`
- // (Both, me first: a local API beside Darkbloom). Null before the first choice.
- mode: 'local' | 'network' | 'both' | null;
+ // The saved choice. Null before the first choice.
+ mode: ServingMode | null;
// Both, me first: Darkbloom pauses while your local requests run, and for
// `me_first_idle_minutes` after (1–120). False: Darkbloom keeps serving beside you.
me_first: boolean;
me_first_idle_minutes: number;
- // Where your requests go when this Mac's local API can't take them.
- route: 'this-mac' | 'my-macs' | 'my-macs-first' | null;
+ // Where your requests go when this Mac's local API can't take them. Null before a route was
+ // saved: this Mac only, or only my Macs once an account key is saved (`resolvedRoute`).
+ route: RequestRoute | null;
// An account API key is saved (`darkbloom route key`); the key itself never crosses.
route_key: boolean;
// This Mac's one local API port and bind address.
@@ -24,12 +32,12 @@ export interface LocalServing {
export type LocalServingAction =
// `darkbloom route this-mac|my-macs|my-macs-first`: saves `[local] route`.
- | { action: 'route'; route: 'this-mac' | 'my-macs' | 'my-macs-first' }
+ | { action: 'route'; route: RequestRoute }
// `darkbloom route key`: saves the account API key, passed on standard input, never argv.
| { action: 'route_key'; key: string }
// Saves `[local] me_first` and `me_first_idle_minutes`.
| { action: 'local_settings'; me_first: boolean; me_first_idle_minutes: number }
// `darkbloom start --opencode` / `--hermes`: set the tool up to use this Mac's local API.
- | { action: 'tool_setup'; tool: 'opencode' | 'hermes' }
+ | { action: 'tool_setup'; tool: LocalTool }
// `darkbloom update --rollback`: return to the previous release.
| { action: 'update_rollback' };
diff --git a/desktop-app/tests/localServingPreview.test.tsx b/desktop-app/tests/localServingPreview.test.tsx
new file mode 100644
index 0000000000..732c501819
--- /dev/null
+++ b/desktop-app/tests/localServingPreview.test.tsx
@@ -0,0 +1,161 @@
+// @vitest-environment jsdom
+import { afterEach, expect, it, vi } from 'vitest';
+import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import '@testing-library/jest-dom/vitest';
+import type { Action, Snapshot } from '../src/shared/contracts';
+import type { PreviewStore } from '../src/renderer/preview/types';
+import { snapshot } from './onboardingFixtures';
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
+
+// The preview module reads its query once, when it loads.
+async function previewWith(query: string) {
+ window.history.replaceState({}, '', `/?preview${query}`);
+ vi.resetModules();
+ return (await import('../src/renderer/preview/localServing')).localServingPreview;
+}
+
+const base = () =>
+ snapshot({
+ state: 'running',
+ endpoint: {
+ base_url: 'http://127.0.0.1:8000/v1',
+ authenticated: true,
+ models: ['gpt-oss-20b'],
+ },
+ });
+
+function storeOf(state: Snapshot): PreviewStore & { current: () => Snapshot } {
+ let current = state;
+ return { get: () => current, set: (next) => (current = next), current: () => current };
+}
+
+async function act(
+ store: PreviewStore,
+ action: Action,
+ preview: Awaited>,
+) {
+ vi.useFakeTimers();
+ const pending = preview.act!(store, action);
+ await vi.advanceTimersByTimeAsync(2000);
+ return pending;
+}
+
+it('shows the whole feature by default and keeps what a listless runtime offered', async () => {
+ const preview = await previewWith('');
+ const next = preview.snapshot!(base());
+ expect(next.capabilities).toEqual([
+ 'autopilot',
+ 'waitlist',
+ 'local_serving',
+ 'tool_setup',
+ 'update_rollback',
+ ]);
+ expect(next.local).toMatchObject({
+ mode: 'both',
+ me_first: true,
+ me_first_idle_minutes: 2,
+ route: null,
+ route_key: false,
+ port: 8001,
+ bind: '127.0.0.1',
+ paused_until: null,
+ });
+ expect(next.endpoint).toEqual({
+ base_url: 'http://127.0.0.1:8001/v1',
+ authenticated: true,
+ models: ['gpt-oss-20b'],
+ });
+ // A runtime's own list is kept as it is.
+ expect(preview.snapshot!({ ...base(), capabilities: ['account-signin'] }).capabilities).toEqual([
+ 'account-signin',
+ 'local_serving',
+ 'tool_setup',
+ 'update_rollback',
+ ]);
+});
+
+it.each([
+ ['&local=only-me', 'local', true],
+ ['&local=network', 'network', false],
+ ['&local=both', 'both', true],
+])('saves the choice %s names', async (query, mode, endpoint) => {
+ const next = (await previewWith(query)).snapshot!(base());
+ expect(next.local?.mode).toBe(mode);
+ expect(!!next.endpoint).toBe(endpoint);
+});
+
+it('pauses Darkbloom for you with &local=paused, and offers nothing with &local=unsupported', async () => {
+ const state = base();
+ const paused = (await previewWith('&local=paused')).snapshot!(state);
+ expect(paused.local?.paused_until).toBe(state.observed_at + 100);
+ expect((await previewWith('&local=unsupported')).snapshot!(state)).toBe(state);
+});
+
+it('refuses a route that passes requests on until a key is saved, and never keeps the key', async () => {
+ const preview = await previewWith('');
+ const store = storeOf(preview.snapshot!(base()));
+ const refused = await act(store, { action: 'route', route: 'my-macs' }, preview);
+ expect(refused?.state).toBe('failed');
+ expect(refused?.message).toMatch(
+ /^✗ Not saved: `darkbloom route my-macs` passes your requests on/,
+ );
+ expect(store.current().local?.route).toBeNull();
+ const key = await act(store, { action: 'route_key', key: 'sk-preview-secret' }, preview);
+ expect(key?.state).toBe('succeeded');
+ expect(store.current().local?.route_key).toBe(true);
+ expect(JSON.stringify(store.current())).not.toContain('sk-preview-secret');
+ const saved = await act(store, { action: 'route', route: 'my-macs' }, preview);
+ expect(saved?.state).toBe('succeeded');
+ expect(store.current().local?.route).toBe('my-macs');
+ const local = await act(store, { action: 'route_key', key: 'dk-local-abc' }, preview);
+ expect(local?.state).toBe('failed');
+});
+
+it('applies a way to serve, saves me first and leaves a plain start to the shared preview', async () => {
+ const preview = await previewWith('');
+ const store = storeOf(preview.snapshot!(base()));
+ await act(store, { action: 'start', models: ['gpt-oss-20b'], network: true }, preview);
+ expect(store.current().local?.mode).toBe('network');
+ expect(store.current().endpoint).toBeUndefined();
+ await act(store, { action: 'start', models: ['gpt-oss-20b'], local: true }, preview);
+ expect(store.current().local?.mode).toBe('local');
+ expect(store.current().endpoint?.base_url).toBe('http://127.0.0.1:8001/v1');
+ expect(await preview.act!(store, { action: 'start', models: ['gpt-oss-20b'] })).toBeUndefined();
+ const refused = await act(
+ store,
+ { action: 'local_settings', me_first: true, me_first_idle_minutes: 0 },
+ preview,
+ );
+ expect(refused?.state).toBe('failed');
+ await act(
+ store,
+ { action: 'local_settings', me_first: false, me_first_idle_minutes: 9 },
+ preview,
+ );
+ expect(store.current().local).toMatchObject({ me_first: false, me_first_idle_minutes: 9 });
+ const tool = await act(store, { action: 'tool_setup', tool: 'opencode' }, preview);
+ expect(tool?.message).toMatch(/^✓ OpenCode can use Darkbloom/);
+});
+
+it('falls through for a runtime without local-first serving', async () => {
+ const preview = await previewWith('&local=unsupported');
+ const store = storeOf(preview.snapshot!(base()));
+ expect(await preview.act!(store, { action: 'route', route: 'this-mac' })).toBeUndefined();
+});
+
+it('opens Studio from This Mac in the preview with the three ways to serve', async () => {
+ window.history.replaceState({}, '', '/?preview');
+ vi.resetModules();
+ const App = (await import('../src/renderer/App')).default;
+ render();
+ await screen.findByRole('heading', { name: 'Your contribution' });
+ fireEvent.click(screen.getByRole('button', { name: 'My Macs' }));
+ fireEvent.click(await screen.findByRole('button', { name: /^Studio/ }));
+ expect(await screen.findByRole('heading', { name: 'How this Mac serves' })).toBeVisible();
+ expect(screen.getByRole('radio', { name: 'Both, me first' })).toBeChecked();
+ expect(screen.getByRole('button', { name: 'Set up OpenCode' })).toBeEnabled();
+});
diff --git a/desktop-app/tests/studioFixtures.ts b/desktop-app/tests/studioFixtures.ts
new file mode 100644
index 0000000000..91e28431f9
--- /dev/null
+++ b/desktop-app/tests/studioFixtures.ts
@@ -0,0 +1,37 @@
+import type { Snapshot } from '../src/shared/contracts';
+import type { LocalServing } from '../src/shared/localServing';
+import { poolSnapshot } from './modelsFixtures';
+
+export const localCapabilities = ['local_serving', 'tool_setup', 'update_rollback'];
+
+// A runtime with local-first serving: Both, me first saved, its local API on 8001 serving the two
+// loaded models, no route saved and no account key.
+export function localSnapshot(
+ local: Partial = {},
+ overrides: Partial = {},
+): Snapshot {
+ return poolSnapshot(
+ {},
+ {
+ capabilities: localCapabilities,
+ activity: { started_at: 1_790_000_000, samples: [] },
+ endpoint: {
+ base_url: 'http://127.0.0.1:8001/v1',
+ authenticated: true,
+ models: ['gpt-oss-20b', 'gemma-4-26b'],
+ },
+ local: {
+ mode: 'both',
+ me_first: true,
+ me_first_idle_minutes: 2,
+ route: null,
+ route_key: false,
+ port: 8001,
+ bind: '127.0.0.1',
+ paused_until: null,
+ ...local,
+ },
+ ...overrides,
+ },
+ );
+}
diff --git a/desktop-app/tests/studioRoute.test.tsx b/desktop-app/tests/studioRoute.test.tsx
new file mode 100644
index 0000000000..b800decce6
--- /dev/null
+++ b/desktop-app/tests/studioRoute.test.tsx
@@ -0,0 +1,134 @@
+// @vitest-environment jsdom
+import { afterEach, expect, it, vi } from 'vitest';
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
+import '@testing-library/jest-dom/vitest';
+import { Studio } from '../src/renderer/features/Studio';
+import { backendWith } from './onboardingFixtures';
+import { localSnapshot } from './studioFixtures';
+
+const api = vi.hoisted(() => ({ read: vi.fn(), copy: vi.fn(), onNavigate: () => () => {} }));
+vi.mock('../src/renderer/useBackend', () => ({ isPreview: false, api, useBackend: vi.fn() }));
+afterEach(() => {
+ cleanup();
+ vi.resetAllMocks();
+});
+
+const routing = () =>
+ within(screen.getByRole('region', { name: 'When this Mac can’t take a request' }));
+
+it('keeps requests on this Mac until an account key is saved, and says why', () => {
+ render();
+ const section = routing();
+ expect(section.getByRole('radio', { name: 'Only this Mac' })).toBeChecked();
+ for (const name of ['Only my Macs (free)', 'My Macs first']) {
+ const option = section.getByRole('radio', { name });
+ expect(option).toBeDisabled();
+ expect(option).toHaveAccessibleDescription(/Needs your account API key\.$/);
+ }
+ expect(section.getByRole('radio', { name: 'My Macs first' })).toHaveAccessibleDescription(
+ 'Your other Macs, then the Darkbloom network, billed to your balance. Needs your account API key.',
+ );
+ expect(section.getByRole('button', { name: 'Save' })).toBeDisabled();
+});
+
+it('takes only my Macs once a key is saved and no route is, then saves another route', async () => {
+ const backend = backendWith(localSnapshot({ route_key: true }));
+ render();
+ const section = routing();
+ expect(section.getByRole('radio', { name: 'Only my Macs (free)' })).toBeChecked();
+ fireEvent.click(section.getByRole('radio', { name: 'My Macs first' }));
+ await act(async () => fireEvent.click(section.getByRole('button', { name: 'Save' })));
+ expect(backend.act).toHaveBeenCalledExactlyOnceWith(
+ { action: 'route', route: 'my-macs-first' },
+ true,
+ );
+});
+
+it('follows the saved route', () => {
+ const view = render();
+ fireEvent.click(routing().getByRole('radio', { name: 'Only this Mac' }));
+ view.rerender(
+ ,
+ );
+ expect(routing().getByRole('radio', { name: 'My Macs first' })).toBeChecked();
+ expect(routing().getByRole('button', { name: 'Save' })).toBeDisabled();
+});
+
+it('sends the account key once, clears it as it is sent and never shows it', async () => {
+ let finish!: (saved: boolean) => void;
+ const backend = backendWith(localSnapshot());
+ vi.mocked(backend.act).mockReturnValueOnce(new Promise((done) => (finish = done)));
+ const { container } = render();
+ const field = routing().getByLabelText('Account API key');
+ expect(field).toHaveAttribute('type', 'password');
+ expect(field).toHaveAttribute('autocomplete', 'off');
+ const save = routing().getByRole('button', { name: 'Save key' });
+ expect(save).toBeDisabled();
+ fireEvent.change(field, { target: { value: ' sk-account-test\n' } });
+ fireEvent.click(save);
+ // Cleared before the runtime answers, and never in the page.
+ expect(field).toHaveValue('');
+ expect(container).not.toHaveTextContent('sk-account-test');
+ expect(backend.act).toHaveBeenCalledExactlyOnceWith(
+ { action: 'route_key', key: 'sk-account-test' },
+ true,
+ );
+ await act(async () => finish(true));
+ expect(field).toHaveValue('');
+});
+
+it.each([
+ [
+ 'dk-local-abc',
+ 'That is this Mac’s local API key; use an account API key from the Darkbloom console.',
+ ],
+ ['sk account', 'An API key has no spaces, line breaks or non-ASCII characters.'],
+ ['sk-ключ', 'An API key has no spaces, line breaks or non-ASCII characters.'],
+ ['k'.repeat(513), 'That is longer than any Darkbloom API key.'],
+])('refuses %j in the CLI’s words before sending it', (value, refusal) => {
+ const backend = backendWith(localSnapshot());
+ render();
+ const field = routing().getByLabelText('Account API key');
+ fireEvent.change(field, { target: { value } });
+ expect(field).toHaveAttribute('aria-invalid', 'true');
+ expect(field).toHaveAccessibleDescription(refusal);
+ const save = routing().getByRole('button', { name: 'Save key' });
+ expect(save).toBeDisabled();
+ fireEvent.submit(save.closest('form')!);
+ expect(backend.act).not.toHaveBeenCalled();
+});
+
+it('says a key is saved without showing it, and replaces it on request', async () => {
+ const backend = backendWith(localSnapshot({ route_key: true }));
+ render();
+ const section = routing();
+ expect(section.getByText('Key saved')).toBeVisible();
+ expect(section.queryByLabelText('Account API key')).not.toBeInTheDocument();
+ fireEvent.click(section.getByRole('button', { name: 'Replace' }));
+ fireEvent.change(section.getByLabelText('Account API key'), {
+ target: { value: 'sk-new-test' },
+ });
+ fireEvent.click(section.getByRole('button', { name: 'Cancel' }));
+ expect(section.getByText('Key saved')).toBeVisible();
+ // Cancelled input is gone: Replace starts empty.
+ fireEvent.click(section.getByRole('button', { name: 'Replace' }));
+ expect(section.getByLabelText('Account API key')).toHaveValue('');
+ fireEvent.change(section.getByLabelText('Account API key'), {
+ target: { value: 'sk-new-test' },
+ });
+ await act(async () => fireEvent.click(section.getByRole('button', { name: 'Save key' })));
+ expect(backend.act).toHaveBeenCalledWith({ action: 'route_key', key: 'sk-new-test' }, true);
+ expect(section.getByText('Key saved')).toBeVisible();
+});
+
+it('keeps the field after a refused key, empty, for another try', async () => {
+ const backend = backendWith(localSnapshot());
+ vi.mocked(backend.act).mockResolvedValueOnce(false);
+ render();
+ fireEvent.change(routing().getByLabelText('Account API key'), {
+ target: { value: 'sk-refused-test' },
+ });
+ await act(async () => fireEvent.click(routing().getByRole('button', { name: 'Save key' })));
+ expect(routing().getByLabelText('Account API key')).toHaveValue('');
+ expect(routing().queryByText('Key saved')).not.toBeInTheDocument();
+});
diff --git a/desktop-app/tests/studioServing.test.tsx b/desktop-app/tests/studioServing.test.tsx
new file mode 100644
index 0000000000..030b52116f
--- /dev/null
+++ b/desktop-app/tests/studioServing.test.tsx
@@ -0,0 +1,249 @@
+// @vitest-environment jsdom
+import { afterEach, expect, it, vi } from 'vitest';
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
+import '@testing-library/jest-dom/vitest';
+import { Studio } from '../src/renderer/features/Studio';
+import { backendWith } from './onboardingFixtures';
+import { localSnapshot } from './studioFixtures';
+
+const api = vi.hoisted(() => ({ read: vi.fn(), copy: vi.fn(), onNavigate: () => () => {} }));
+vi.mock('../src/renderer/useBackend', () => ({ isPreview: false, api, useBackend: vi.fn() }));
+afterEach(() => {
+ cleanup();
+ vi.resetAllMocks();
+});
+
+const apply = () => screen.getByRole('button', { name: 'Apply' });
+
+it('offers the CLI’s three ways to serve, marks the saved one and recommends Both, me first', () => {
+ render();
+ expect(screen.getByRole('group', { name: 'How this Mac serves' })).toBeVisible();
+ const onlyMe = screen.getByRole('radio', { name: 'Only me' });
+ const network = screen.getByRole('radio', { name: 'Darkbloom network' });
+ const both = screen.getByRole('radio', { name: 'Both, me first' });
+ expect(onlyMe).toHaveAccessibleDescription(
+ 'Darkbloom never contacts this Mac. Your tools use this Mac’s own API.',
+ );
+ expect(network).toHaveAccessibleDescription('This Mac serves Darkbloom and earns while it runs.');
+ expect(both).toBeChecked();
+ expect(both).toHaveAccessibleDescription(
+ 'Recommended Saved This Mac serves Darkbloom while you aren’t using it. When you use it, ' +
+ 'Darkbloom traffic pauses until you’ve been idle for 2 minutes.',
+ );
+ // Nothing to apply until another way is chosen; applying restarts serving.
+ expect(apply()).toBeDisabled();
+ expect(screen.getByText('Applying restarts serving.')).toBeVisible();
+ expect(screen.queryByText(/newer Darkbloom CLI/)).not.toBeInTheDocument();
+});
+
+it('applies Only me with the models serving now and says it restarts serving', () => {
+ const backend = backendWith(localSnapshot());
+ render();
+ fireEvent.click(screen.getByRole('radio', { name: 'Only me' }));
+ expect(
+ screen.getByText('Applying restarts serving with GPT-OSS 20B and Gemma 4 26B.'),
+ ).toBeVisible();
+ fireEvent.click(apply());
+ expect(backend.act).toHaveBeenCalledExactlyOnceWith({
+ action: 'start',
+ models: ['gpt-oss-20b', 'gemma-4-26b'],
+ local: true,
+ });
+});
+
+it('applies the network with `network` and Both with `endpoint`, keeping catalog models only', () => {
+ const state = localSnapshot({ mode: 'local' });
+ // A model found only on disk serves Only me, never the network.
+ state.models = [
+ ...state.models,
+ {
+ id: 'my-finetune',
+ display_name: 'My finetune',
+ size_gb: 4,
+ downloaded: true,
+ serving: true,
+ loaded: true,
+ eligible: true,
+ network: false,
+ },
+ ];
+ const backend = backendWith(state);
+ render();
+ fireEvent.click(screen.getByRole('radio', { name: 'Darkbloom network' }));
+ expect(
+ screen.getByText('Applying restarts serving with GPT-OSS 20B and Gemma 4 26B.'),
+ ).toBeVisible();
+ fireEvent.click(apply());
+ fireEvent.click(screen.getByRole('radio', { name: 'Both, me first' }));
+ fireEvent.click(apply());
+ expect(vi.mocked(backend.act).mock.calls).toEqual([
+ [{ action: 'start', models: ['gpt-oss-20b', 'gemma-4-26b'], network: true }],
+ [{ action: 'start', models: ['gpt-oss-20b', 'gemma-4-26b'], endpoint: true }],
+ ]);
+});
+
+it('asks for a model when none serves, and says a stopped Mac starts serving', () => {
+ const state = localSnapshot({ mode: 'network' }, { state: 'stopped', endpoint: undefined });
+ state.models = state.models.map((model) => ({ ...model, serving: false, loaded: false }));
+ const backend = backendWith(state);
+ render();
+ expect(screen.queryByRole('combobox')).not.toBeInTheDocument();
+ fireEvent.click(screen.getByRole('radio', { name: 'Only me' }));
+ const model = screen.getByRole('combobox', { name: /Model/ });
+ expect(model).toHaveValue('gpt-oss-20b');
+ fireEvent.change(model, { target: { value: 'qwen-3.5-9b' } });
+ expect(screen.getByText('Applying starts serving with Qwen 3.5 9B.')).toBeVisible();
+ fireEvent.click(apply());
+ expect(backend.act).toHaveBeenCalledWith({
+ action: 'start',
+ models: ['qwen-3.5-9b'],
+ local: true,
+ });
+});
+
+it('says when this Mac has no model to serve and offers no Apply', () => {
+ const state = localSnapshot({ mode: null }, { state: 'stopped', endpoint: undefined });
+ state.models = state.models.map((model) => ({ ...model, downloaded: false, serving: false }));
+ render();
+ expect(screen.getByText('No model to serve yet. Get one in Models.')).toBeVisible();
+ expect(apply()).toBeDisabled();
+});
+
+it('marks nothing saved before the first choice and preselects Both, me first', () => {
+ const backend = backendWith(localSnapshot({ mode: null }));
+ render();
+ expect(screen.getByRole('radio', { name: 'Both, me first' })).toBeChecked();
+ expect(screen.queryByText('Saved')).not.toBeInTheDocument();
+ expect(apply()).toBeEnabled();
+ fireEvent.click(apply());
+ expect(backend.act).toHaveBeenCalledWith({
+ action: 'start',
+ models: ['gpt-oss-20b', 'gemma-4-26b'],
+ endpoint: true,
+ });
+});
+
+it('follows a choice saved elsewhere, such as by `darkbloom start --local`', () => {
+ const view = render();
+ fireEvent.click(screen.getByRole('radio', { name: 'Darkbloom network' }));
+ view.rerender();
+ expect(screen.getByRole('radio', { name: 'Only me' })).toBeChecked();
+ expect(screen.getByRole('radio', { name: 'Only me' })).toHaveAccessibleDescription(/^Saved /);
+ expect(apply()).toBeDisabled();
+});
+
+it('offers no way to serve on a paired Mac, whose pair serves its own way', () => {
+ const navigate = vi.fn();
+ const backend = backendWith(
+ localSnapshot({}, { pair: { model: 'Qwen 3.8 27B', state: 'serving', leads: true } }),
+ );
+ render();
+ for (const radio of screen.getAllByRole('radio', { name: /Only me|Darkbloom network|Both/ }))
+ expect(radio).toBeDisabled();
+ expect(screen.queryByRole('button', { name: 'Apply' })).not.toBeInTheDocument();
+ expect(screen.getByText(/This Mac is in a pair, which serves its own way\./)).toBeVisible();
+ fireEvent.click(screen.getByRole('button', { name: /Clusters/ }));
+ expect(navigate).toHaveBeenCalledWith('cluster');
+});
+
+it('shows no local API parts while this Mac serves only the network', () => {
+ render(
+ ,
+ );
+ expect(screen.getByRole('radio', { name: 'Darkbloom network' })).toBeChecked();
+ for (const heading of [
+ 'Me first',
+ 'When this Mac can’t take a request',
+ 'Connection details',
+ 'Use it in your tools',
+ 'Make a request',
+ ])
+ expect(screen.queryByRole('heading', { name: heading })).not.toBeInTheDocument();
+ expect(screen.queryByText('Listening')).not.toBeInTheDocument();
+});
+
+it('shows me first only for Both, me first', () => {
+ const view = render();
+ expect(screen.queryByRole('heading', { name: 'Me first' })).not.toBeInTheDocument();
+ expect(screen.getByRole('heading', { name: 'Connection details' })).toBeVisible();
+ view.rerender();
+ expect(screen.getByRole('heading', { name: 'Me first' })).toBeVisible();
+});
+
+it('saves me first and its minutes, then offers Restart serving to apply them', async () => {
+ const backend = backendWith(localSnapshot());
+ render();
+ const meFirst = within(screen.getByRole('region', { name: 'Me first' }));
+ const save = meFirst.getByRole('button', { name: 'Save' });
+ const minutes = meFirst.getByRole('spinbutton', { name: 'Minutes before Darkbloom comes back' });
+ expect(
+ meFirst.getByRole('switch', { name: /Pause Darkbloom while you use this Mac/ }),
+ ).toBeChecked();
+ expect(minutes).toHaveValue(2);
+ expect(save).toBeDisabled();
+ fireEvent.change(minutes, { target: { value: '5' } });
+ await act(async () => fireEvent.click(save));
+ expect(backend.act).toHaveBeenCalledWith(
+ { action: 'local_settings', me_first: true, me_first_idle_minutes: 5 },
+ true,
+ );
+ expect(meFirst.getByText('Saved. Restart serving to apply.')).toBeVisible();
+ await act(async () => fireEvent.click(meFirst.getByRole('button', { name: 'Restart serving' })));
+ expect(backend.act).toHaveBeenLastCalledWith({ action: 'restart' }, true);
+ expect(meFirst.queryByText('Saved. Restart serving to apply.')).not.toBeInTheDocument();
+});
+
+it('turns me first off with the saved minutes, and needs no restart while stopped', async () => {
+ const backend = backendWith(localSnapshot({ me_first_idle_minutes: 7 }, { state: 'stopped' }));
+ render();
+ const meFirst = within(screen.getByRole('region', { name: 'Me first' }));
+ fireEvent.click(meFirst.getByRole('switch', { name: /Pause Darkbloom/ }));
+ expect(meFirst.queryByRole('spinbutton')).not.toBeInTheDocument();
+ expect(meFirst.getByText('Darkbloom keeps serving while you use the local API.')).toBeVisible();
+ await act(async () => fireEvent.click(meFirst.getByRole('button', { name: 'Save' })));
+ expect(backend.act).toHaveBeenCalledWith(
+ { action: 'local_settings', me_first: false, me_first_idle_minutes: 7 },
+ true,
+ );
+ expect(meFirst.queryByText('Saved. Restart serving to apply.')).not.toBeInTheDocument();
+});
+
+it.each(['0', '121', '2.5', ''])('refuses %j minutes before saving', (value) => {
+ const backend = backendWith(localSnapshot());
+ render();
+ const meFirst = within(screen.getByRole('region', { name: 'Me first' }));
+ const minutes = meFirst.getByRole('spinbutton', { name: 'Minutes before Darkbloom comes back' });
+ fireEvent.change(minutes, { target: { value } });
+ expect(minutes).toHaveAttribute('aria-invalid', 'true');
+ expect(minutes).toHaveAccessibleDescription('From 1 to 120 minutes.');
+ expect(meFirst.getByRole('button', { name: 'Save' })).toBeDisabled();
+ expect(backend.act).not.toHaveBeenCalled();
+});
+
+it('says Darkbloom is paused for you, and when it comes back', () => {
+ const state = localSnapshot();
+ render(
+ ,
+ );
+ expect(screen.getByRole('status')).toHaveTextContent(
+ 'Darkbloom is paused for you · back in about 2 minutes if you stay idle',
+ );
+});
+
+it('keeps today’s Studio for a runtime without local-first serving, with one line on what a newer CLI adds', () => {
+ const backend = backendWith(localSnapshot({}, { capabilities: ['autopilot'] }));
+ render();
+ expect(screen.getByRole('heading', { name: 'Serving mode' })).toBeVisible();
+ expect(screen.getByRole('radio', { name: /Local only/ })).toBeVisible();
+ expect(
+ screen.getByText('A newer Darkbloom CLI adds me first, request routing and tool setup.'),
+ ).toBeVisible();
+ for (const heading of ['How this Mac serves', 'Me first', 'Use it in your tools'])
+ expect(screen.queryByRole('heading', { name: heading })).not.toBeInTheDocument();
+ expect(screen.queryByText('Listens on')).not.toBeInTheDocument();
+});
diff --git a/desktop-app/tests/studioTools.test.tsx b/desktop-app/tests/studioTools.test.tsx
new file mode 100644
index 0000000000..bc2ffce14e
--- /dev/null
+++ b/desktop-app/tests/studioTools.test.tsx
@@ -0,0 +1,100 @@
+// @vitest-environment jsdom
+import { afterEach, expect, it, vi } from 'vitest';
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
+import '@testing-library/jest-dom/vitest';
+import { Studio } from '../src/renderer/features/Studio';
+import { backendWith } from './onboardingFixtures';
+import { localCapabilities, localSnapshot } from './studioFixtures';
+
+const api = vi.hoisted(() => ({ read: vi.fn(), copy: vi.fn(), onNavigate: () => () => {} }));
+vi.mock('../src/renderer/useBackend', () => ({ isPreview: false, api, useBackend: vi.fn() }));
+afterEach(() => {
+ cleanup();
+ vi.resetAllMocks();
+});
+
+const tools = () => within(screen.getByRole('region', { name: 'Use it in your tools' }));
+
+it('sets OpenCode and Hermes up with the runtime’s tool setup', () => {
+ const backend = backendWith(localSnapshot());
+ render();
+ fireEvent.click(tools().getByRole('button', { name: 'Set up OpenCode' }));
+ fireEvent.click(tools().getByRole('button', { name: 'Set up Hermes' }));
+ expect(vi.mocked(backend.act).mock.calls).toEqual([
+ [{ action: 'tool_setup', tool: 'opencode' }],
+ [{ action: 'tool_setup', tool: 'hermes' }],
+ ]);
+});
+
+it('sets tools up only while the local API runs with its key', () => {
+ const stopped = localSnapshot({}, { state: 'stopped', endpoint: undefined });
+ const view = render();
+ expect(tools().getByRole('button', { name: 'Set up OpenCode' })).toBeDisabled();
+ expect(tools().getByText('Start serving first.')).toBeVisible();
+ const keyless = localSnapshot();
+ keyless.endpoint = { ...keyless.endpoint!, authenticated: false };
+ view.rerender();
+ expect(tools().getByRole('button', { name: 'Set up Hermes' })).toBeDisabled();
+ expect(
+ tools().getByText('Tools need the local API’s key. Start it without --no-auth.'),
+ ).toBeVisible();
+});
+
+it('shows the command to run where the runtime can’t set tools up', async () => {
+ api.copy.mockResolvedValue(undefined);
+ const backend = backendWith(
+ localSnapshot({}, { capabilities: localCapabilities.filter((name) => name !== 'tool_setup') }),
+ );
+ render();
+ expect(tools().queryByRole('button', { name: /Set up/ })).not.toBeInTheDocument();
+ expect(tools().getByText('darkbloom --opencode')).toBeVisible();
+ expect(tools().getByText('darkbloom --hermes')).toBeVisible();
+ await act(async () =>
+ fireEvent.click(tools().getByRole('button', { name: 'Copy darkbloom --hermes' })),
+ );
+ expect(api.copy).toHaveBeenCalledExactlyOnceWith('darkbloom --hermes');
+ expect(tools().getByRole('button', { name: 'darkbloom --hermes copied' })).toBeVisible();
+ expect(tools().getByRole('button', { name: 'Copy darkbloom --opencode' })).toBeVisible();
+ expect(backend.act).not.toHaveBeenCalled();
+});
+
+it('names the port and address this Mac’s local API listens on', () => {
+ const view = render();
+ const details = () => within(screen.getByRole('region', { name: 'Connection details' }));
+ expect(details().getByText('127.0.0.1:8001')).toBeVisible();
+ expect(details().getByText('Requires an API key. Accessible only on this Mac.')).toBeVisible();
+ view.rerender();
+ expect(details().getByText('0.0.0.0:8001')).toBeVisible();
+ expect(
+ details().getByText('Requires an API key. Accessible on your local network.'),
+ ).toBeVisible();
+ view.rerender();
+ expect(details().getByText('[::1]:8007')).toBeVisible();
+ expect(details().getByText('Requires an API key. Accessible only on this Mac.')).toBeVisible();
+});
+
+it('says the local API isn’t running instead of an address it doesn’t have', () => {
+ render(
+ ,
+ );
+ const details = within(screen.getByRole('region', { name: 'Connection details' }));
+ expect(details.getByText('Not running')).toBeVisible();
+ expect(details.getByRole('button', { name: 'Reveal' })).toBeDisabled();
+ expect(details.getByText('127.0.0.1:8001')).toBeVisible();
+ expect(screen.getByRole('button', { name: /Copy example/ })).toBeDisabled();
+});
+
+it('keeps the key reveal and the example that works as copied', async () => {
+ api.read.mockResolvedValue({ key: 'dk-local-test' });
+ api.copy.mockResolvedValue(undefined);
+ render();
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Reveal' })));
+ expect(screen.getByText('dk-local-test')).toBeVisible();
+ expect(api.read).toHaveBeenCalledExactlyOnceWith('endpoint-key');
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: /Copy example/ })));
+ const copied = api.copy.mock.calls[0][0] as string;
+ expect(copied).toContain('curl http://127.0.0.1:8001/v1/chat/completions');
+ expect(copied).toContain('"model":"gpt-oss-20b"');
+ expect(copied).toContain('Authorization: Bearer ');
+ expect(copied).not.toContain('dk-local-test');
+});
diff --git a/desktop-app/tests/studioWords.test.ts b/desktop-app/tests/studioWords.test.ts
new file mode 100644
index 0000000000..fb465bda18
--- /dev/null
+++ b/desktop-app/tests/studioWords.test.ts
@@ -0,0 +1,85 @@
+import { expect, it } from 'vitest';
+import {
+ address,
+ backIn,
+ effectiveRoute,
+ idleMinutes,
+ keyRefusal,
+ localServing,
+ names,
+ reach,
+ servingDetail,
+} from '../src/renderer/features/studio/words';
+import { localSnapshot } from './studioFixtures';
+
+it('reads local-first serving only from a runtime that offers it', () => {
+ const state = localSnapshot();
+ expect(localServing(state)).toBe(state.local);
+ expect(localServing({ ...state, capabilities: undefined })).toBeUndefined();
+ expect(localServing({ ...state, capabilities: ['autopilot'] })).toBeUndefined();
+ expect(localServing({ ...state, local: undefined })).toBeUndefined();
+});
+
+it('words Both, me first by its minutes, and says when me first is off', () => {
+ expect(servingDetail('both', { me_first: true, me_first_idle_minutes: 1 })).toMatch(
+ /idle for 1 minute\.$/,
+ );
+ expect(servingDetail('both', { me_first: true, me_first_idle_minutes: 15 })).toMatch(
+ /idle for 15 minutes\.$/,
+ );
+ expect(servingDetail('both', { me_first: false, me_first_idle_minutes: 2 })).toBe(
+ 'Darkbloom keeps serving while you use this Mac (me first is off).',
+ );
+});
+
+it('says when Darkbloom comes back as the CLI does, from now', () => {
+ expect(backIn(-5)).toBe('back any moment now');
+ expect(backIn(0)).toBe('back any moment now');
+ expect(backIn(59)).toBe('back in under a minute if you stay idle');
+ expect(backIn(60)).toBe('back in about 1 minute if you stay idle');
+ expect(backIn(100)).toBe('back in about 2 minutes if you stay idle');
+ expect(backIn(3600)).toBe('back in about 1 hour if you stay idle');
+ expect(backIn(7300)).toBe('back in about 2 hours 2 minutes if you stay idle');
+});
+
+it('takes whole minutes from 1 to 120', () => {
+ expect(idleMinutes('1')).toBe(1);
+ expect(idleMinutes(' 120 ')).toBe(120);
+ for (const value of ['0', '121', '2.5', '-3', '', 'two', '1e2'])
+ expect(idleMinutes(value)).toBe(undefined);
+});
+
+it('resolves an unsaved route as the CLI does', () => {
+ const local = localSnapshot().local!;
+ expect(effectiveRoute(local)).toBe('this-mac');
+ expect(effectiveRoute({ ...local, route_key: true })).toBe('my-macs');
+ expect(effectiveRoute({ ...local, route: 'my-macs-first' })).toBe('my-macs-first');
+});
+
+it('refuses what can’t be an account key, as `darkbloom route key` does', () => {
+ expect(keyRefusal('')).toBe('No key was given.');
+ expect(keyRefusal('sk-live-ok_123')).toBeUndefined();
+ expect(keyRefusal('a\tb')).toMatch(/no spaces/);
+ expect(keyRefusal('a\u007fb')).toMatch(/non-ASCII/);
+ expect(keyRefusal('sk-😀')).toMatch(/non-ASCII/);
+ expect(keyRefusal('dk-local-xyz')).toMatch(/this Mac’s local API key/);
+ expect(keyRefusal('k'.repeat(512))).toBeUndefined();
+ expect(keyRefusal('k'.repeat(513))).toMatch(/longer than any/);
+});
+
+it('names where the local API answers', () => {
+ expect(reach(null)).toBe('Accessible only on this Mac.');
+ expect(reach('localhost')).toBe('Accessible only on this Mac.');
+ expect(reach('127.0.0.2')).toBe('Accessible only on this Mac.');
+ expect(reach('::')).toBe('Accessible on your local network.');
+ expect(reach('192.168.1.20')).toBe('Accessible on your local network.');
+ expect(address(null, 8001)).toBe('127.0.0.1:8001');
+ expect(address('fe80::1', 8001)).toBe('[fe80::1]:8001');
+});
+
+it('lists names in plain words', () => {
+ expect(names([])).toBe('');
+ expect(names(['A'])).toBe('A');
+ expect(names(['A', 'B'])).toBe('A and B');
+ expect(names(['A', 'B', 'C'])).toBe('A, B and C');
+});
From 4dd24f02357c9c7dc902d4989ec1308ad1a59790 Mon Sep 17 00:00:00 2001
From: jonathan308 <5055076+jonathan308@users.noreply.github.com>
Date: Sun, 8 Nov 2026 22:32:31 -0800
Subject: [PATCH 07/79] feat(desktop): Updates returns to the previous release
(`update_rollback`)
From a runtime with `update_rollback`, Updates offers **Return to the previous
release**, asked first as `darkbloom update --rollback` asks: this Mac returns
to the release kept for rollback once its requests finish, and automatic
updates then skip the installed one. The runtime's own refusal shows when no
release is kept. Older runtimes show nothing new.
Co-Authored-By: Claude Opus 5.5
---
desktop-app/src/renderer/features/Updates.tsx | 2 +
.../renderer/features/updates/Rollback.tsx | 50 +++++++++++++++++++
.../features/updates/updates.module.css | 4 ++
desktop-app/tests/updatesRollback.test.tsx | 44 ++++++++++++++++
4 files changed, 100 insertions(+)
create mode 100644 desktop-app/src/renderer/features/updates/Rollback.tsx
create mode 100644 desktop-app/tests/updatesRollback.test.tsx
diff --git a/desktop-app/src/renderer/features/Updates.tsx b/desktop-app/src/renderer/features/Updates.tsx
index 66c8d4423b..2cb762d713 100644
--- a/desktop-app/src/renderer/features/Updates.tsx
+++ b/desktop-app/src/renderer/features/Updates.tsx
@@ -6,6 +6,7 @@ import type { GUIUpdate } from '../../shared/contracts';
import { Button, Header } from '../components/UI';
import { AutoUpdateSwitch } from './updates/AutoUpdateSwitch';
import { ReleaseTimeline } from './updates/ReleaseTimeline';
+import { Rollback } from './updates/Rollback';
import { RuntimeVersion } from './updates/RuntimeVersion';
import styles from './updates/updates.module.css';
@@ -105,6 +106,7 @@ export function Updates({ backend }: { backend: BackendState }) {
)}
+
+
+
+ Previous release
+ Kept on this Mac for rollback.
+
+
+
+ {confirm && (
+ setConfirm(false)}>
+
+ This Mac returns to the release kept for rollback once its requests finish. Automatic
+ updates then skip {installed}; the next newer release installs normally.
+
+
+
+
+
+
+ )}
+ >
+ );
+}
diff --git a/desktop-app/src/renderer/features/updates/updates.module.css b/desktop-app/src/renderer/features/updates/updates.module.css
index 46d1e1bcd9..baa24fa92e 100644
--- a/desktop-app/src/renderer/features/updates/updates.module.css
+++ b/desktop-app/src/renderer/features/updates/updates.module.css
@@ -73,6 +73,10 @@
font-size: 12px;
color: var(--muted);
}
+.rollback {
+ margin-top: 18px;
+ border-top: 1px solid var(--line);
+}
.sectionHead {
display: flex;
align-items: baseline;
diff --git a/desktop-app/tests/updatesRollback.test.tsx b/desktop-app/tests/updatesRollback.test.tsx
new file mode 100644
index 0000000000..445a88f0f9
--- /dev/null
+++ b/desktop-app/tests/updatesRollback.test.tsx
@@ -0,0 +1,44 @@
+// @vitest-environment jsdom
+import { afterEach, expect, it, vi } from 'vitest';
+import { cleanup, fireEvent, render, screen } from '@testing-library/react';
+import '@testing-library/jest-dom/vitest';
+import { Rollback } from '../src/renderer/features/updates/Rollback';
+import { backendWith, snapshot } from './onboardingFixtures';
+
+vi.mock('../src/renderer/useBackend', () => ({ isPreview: false, api: undefined }));
+afterEach(cleanup);
+
+const offered = () => snapshot({ capabilities: ['update_rollback'], version: '0.12.1' });
+
+it('offers nothing to a runtime without rollback', () => {
+ const { container } = render();
+ expect(container).toBeEmptyDOMElement();
+});
+
+it('asks before returning to the previous release, and keeps this one on Keep', () => {
+ const backend = backendWith(offered());
+ render();
+ fireEvent.click(screen.getByRole('button', { name: 'Return to the previous release' }));
+ const dialog = screen.getByRole('dialog', { name: 'Return to the previous release?' });
+ expect(dialog).toHaveTextContent(
+ 'This Mac returns to the release kept for rollback once its requests finish. Automatic ' +
+ 'updates then skip 0.12.1; the next newer release installs normally.',
+ );
+ fireEvent.click(screen.getByRole('button', { name: 'Keep this release' }));
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+ expect(backend.act).not.toHaveBeenCalled();
+});
+
+it('rolls back once confirmed', () => {
+ const backend = backendWith(offered());
+ render();
+ fireEvent.click(screen.getByRole('button', { name: 'Return to the previous release' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Roll back' }));
+ expect(backend.act).toHaveBeenCalledExactlyOnceWith({ action: 'update_rollback' });
+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
+});
+
+it('waits while another action runs', () => {
+ render();
+ expect(screen.getByRole('button', { name: 'Return to the previous release' })).toBeDisabled();
+});
From 00edd0671f5eaa8ccfd906020491f73796061a1c Mon Sep 17 00:00:00 2001
From: jonathan308 <5055076+jonathan308@users.noreply.github.com>
Date: Sun, 8 Nov 2026 22:33:54 -0800
Subject: [PATCH 08/79] docs(desktop): Local API and serving modes, rollback in
Updates, changelog
The developer guide's `## Local API and serving modes` says what each Studio
section shows and sends (`start` with `local`/`network`/`endpoint`,
`local_settings`, `route`, `route_key`, `tool_setup`), how the account key is
handled, what a paired Mac and an older runtime see, the tests and the preview
links. Updates presentation adds **Return to the previous release**.
Co-Authored-By: Claude Opus 5.5
---
changelog.d/desktop-local-serving.md | 8 +++++
docs/developer/desktop-app.md | 47 +++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 1 deletion(-)
create mode 100644 changelog.d/desktop-local-serving.md
diff --git a/changelog.d/desktop-local-serving.md b/changelog.d/desktop-local-serving.md
new file mode 100644
index 0000000000..775aa5ba8e
--- /dev/null
+++ b/changelog.d/desktop-local-serving.md
@@ -0,0 +1,8 @@
+### The app's Studio serves the CLI's way, and Updates can roll back
+
+- This Mac > Studio asks the start question in its own words: **Only me**, **Darkbloom network** or **Both, me first** (recommended), with the saved choice marked. **Apply** saves the new choice and restarts serving with the models serving now (or one you choose when none serves), and says so first. Before, Studio offered only "Alongside the network" and "Local only", and the network alone couldn't be chosen in the app.
+- With **Both, me first**, Studio turns me first on or off and sets the minutes with none of your requests before Darkbloom comes back (1 to 120); a change applies when serving restarts, and **Restart serving** is offered. It says when Darkbloom is paused for you and when it comes back.
+- **When this Mac can't take a request**: Only this Mac, Only my Macs (free) or My Macs first (then the network, billed to your balance), saved as `darkbloom route` saves it. The last two need your account API key: paste it once and **Save key**. The app sends it to the Keychain and keeps no copy; it shows only "Key saved".
+- **Use it in your tools**: **Set up OpenCode** and **Set up Hermes** run `darkbloom --opencode` and `--hermes`; with an older CLI, Studio shows those commands to copy. Connection details add the port and address the local API listens on.
+- Updates offers **Return to the previous release** (`darkbloom update --rollback`), asked first.
+- With a CLI from before these, Studio stays as it was, with one line saying a newer Darkbloom CLI adds me first, request routing and tool setup.
diff --git a/docs/developer/desktop-app.md b/docs/developer/desktop-app.md
index d79ca25827..97cdcc03c3 100644
--- a/docs/developer/desktop-app.md
+++ b/docs/developer/desktop-app.md
@@ -575,7 +575,46 @@ Early access is documented with its implementation.
## Local API and serving modes
-The local API page is documented with its implementation.
+This Mac > Studio is the local API page (`desktop-app/src/renderer/features/Studio.tsx`,
+`Studio`; its parts in `desktop-app/src/renderer/features/studio/`). From a runtime whose
+`Snapshot.capabilities` lists `local_serving`, it reads `Snapshot.local`, the `[local]` section
+of `provider.toml` (`desktop-app/src/shared/localServing.ts`, `LocalServing`), and says
+everything in the CLI's words (`desktop-app/src/renderer/features/studio/words.ts`), as
+[Use your Mac yourself, first](../provider/local-first.md) describes them:
+
+| Section | Shows | Sends |
+|---|---|---|
+| How this Mac serves (`ServingChoice`) | The start question's answers, **Only me**, **Darkbloom network** and **Both, me first** (Recommended), `mode` marked Saved. With none saved, Both, me first is preselected, as in the question | **Apply**: `{ action: 'start', models, local: true }`, `network: true` or `endpoint: true` (the CLI's `--local`, through `desktop start-local`, `--network` and `--local-endpoint`), each saved as `[local] mode` once the start goes ahead. `models` are the models serving now that the choice can serve (the network only catalog models, `servesNetwork`); with none, a list asks for one. The line beside Apply says that applying restarts serving (starts it, when stopped) and with which models |
+| Me first (`MeFirst`), with `mode` `both` | `me_first` as a switch and `me_first_idle_minutes`, whole minutes from 1 to 120. While `paused_until` is set: "Darkbloom is paused for you" and when it comes back, timed from `observed_at` in `MeFirstWords`' words | `{ action: 'local_settings', me_first, me_first_idle_minutes }`, waited for. A serving process reads both when it starts (`ProviderLoop.enableMeFirst` in `provider-swift/Sources/ProviderCore/ProviderLoop+MeFirst.swift`), so a save while serving offers **Restart serving** |
+| When this Mac can't take a request (`RequestRoute`) | Only this Mac, Only my Macs (free), My Macs first. The route checked is `route`, else `my-macs` with `route_key`, else `this-mac` (`LocalSettings.resolvedRoute`). Without `route_key`, the two that pass requests on are disabled and say they need the account API key | **Save**: `{ action: 'route', route }`. **Save key**: `{ action: 'route_key', key }` from a password field, trimmed and checked first with the rules of `LocalRouterAccountKeyFormat` (`provider-swift/Sources/ProviderCore/Server/LocalRouterAccountKey.swift`), then cleared as it is sent. The key is never shown, stored or read back; "Key saved" comes from `route_key`, and **Replace** asks for another |
+| Use it in your tools (`ToolSetup`) | **Set up OpenCode** and **Set up Hermes** while the local API runs with a key. Without the `tool_setup` capability, `darkbloom --opencode` and `darkbloom --hermes` to copy | `{ action: 'tool_setup', tool: 'opencode' }` or `'hermes'` |
+| Connection details, Make a request | Base URL, the key on Reveal only (`useEndpointKey`), **Listens on** from `port` and `bind` with whether only this Mac can reach it, and the curl example with a key placeholder | Nothing |
+
+- **Where no local API serves** (`mode` `network`, or none saved, and no `Snapshot.endpoint`),
+ only How this Mac serves shows.
+- **A paired Mac** (`Snapshot.pair`): a start there starts the pair, so the choices are
+ disabled and a line says the pair serves its own way, with a link to Clusters.
+- **An older runtime** (no `local_serving`, or no `Snapshot.local`) keeps the earlier Studio:
+ "Alongside the network" (`start` with `endpoint: true`) and "Local only" (`local: true`),
+ one model, and one line, "A newer Darkbloom CLI adds me first, request routing and tool
+ setup." (`LegacyServingMode`).
+
+`studioServing.test.tsx`, `studioRoute.test.tsx`, `studioTools.test.tsx`,
+`studioWords.test.ts` and `studio.test.tsx` (the key reveal, copy and example) cover the page;
+`localServingPreview.test.tsx` covers the preview.
+
+Preview links (`?preview` plus; then My Macs > This Mac > Studio):
+
+| Query | Shows |
+|---|---|
+| none, or `&local=both` | Both, me first saved, its local API on port 8001, no route and no account key saved |
+| `&local=only-me`, `&local=network` | That choice saved; the network has no local API |
+| `&local=paused` | Both, me first, with Darkbloom paused for you |
+| `&local=unsupported` | A runtime without `local_serving`, `tool_setup` and `update_rollback` |
+
+The preview simulates every action in the CLI's words
+(`desktop-app/src/renderer/preview/localServing.ts`): `route` with a route that passes requests
+on fails until a key is saved, and an entered key is checked for its shape and never kept.
## Updates presentation
@@ -586,6 +625,12 @@ Updates and Settings. Updates saves through the revision-checked native settings
action, and offers **Restart serving** to apply the setting to a running provider.
It never restarts automatically from a toggle.
+From a runtime whose `Snapshot.capabilities` lists `update_rollback`, Updates offers
+**Return to the previous release** (`desktop-app/src/renderer/features/updates/Rollback.tsx`,
+`Rollback`). It asks first, as `darkbloom update --rollback` does, then sends
+`{ action: 'update_rollback' }`; the runtime's refusal, such as no release kept for rollback,
+shows in the operation feed. `updatesRollback.test.tsx` covers it.
+
A mandatory update is shown only when the installed version is below the
coordinator's published minimum. An available release alone is not mandatory.
Unknown policy remains unavailable; missing release notes are not invented.
From a3f554778240b9b566492c8e98e81df5fbefba06 Mon Sep 17 00:00:00 2001
From: jonathan308 <5055076+jonathan308@users.noreply.github.com>
Date: Sun, 8 Nov 2026 22:34:04 -0800
Subject: [PATCH 09/79] docs(desktop): document Early access, and name each
card's button target
The developer guide's Early access section covers how the page reads the
`waitlists` resource (capability, one shared read, what reads again), the
standing words, joining, the unavailable states, the hook and card that
Clusters and Sandboxes use, and the preview links. A changelog fragment
describes the page for users.
Join the waitlist and Open are described by their card's title, so a page of
cards doesn't read as a row of identical buttons.
Co-Authored-By: Claude Opus 5.5
---
changelog.d/desktop-early-access.md | 4 ++
.../features/waitlists/WaitlistCard.tsx | 20 +++++--
desktop-app/tests/waitlistsCard.test.tsx | 4 +-
desktop-app/tests/waitlistsPage.test.tsx | 4 +-
docs/developer/desktop-app.md | 53 ++++++++++++++++++-
5 files changed, 78 insertions(+), 7 deletions(-)
create mode 100644 changelog.d/desktop-early-access.md
diff --git a/changelog.d/desktop-early-access.md b/changelog.d/desktop-early-access.md
new file mode 100644
index 0000000000..8b15f9f77e
--- /dev/null
+++ b/changelog.d/desktop-early-access.md
@@ -0,0 +1,4 @@
+### The desktop app shows Early access: where your account stands on each waitlist
+
+- A new **Early access** page lists every waitlist the coordinator offers, such as Clusters and Darkbloom Sandbox, and where your account stands, as `darkbloom waitlist` says it: not joined, with **Join the waitlist**; your place in line and the day you joined; approved since a day, with **Open** for a feature that has a page in the app or else the command that starts it, to copy; or revoked, which joining again doesn't restore.
+- When the list can't be shown, the page says why: a Mac that isn't linked links from the page with the app's own code, a coordinator without waitlists has nothing to join, and anything else shows the reason with **Try again**. A Darkbloom CLI without waitlists gets a one-line note to update it.
diff --git a/desktop-app/src/renderer/features/waitlists/WaitlistCard.tsx b/desktop-app/src/renderer/features/waitlists/WaitlistCard.tsx
index 3fba358c00..2ad0de9d46 100644
--- a/desktop-app/src/renderer/features/waitlists/WaitlistCard.tsx
+++ b/desktop-app/src/renderer/features/waitlists/WaitlistCard.tsx
@@ -137,9 +137,11 @@ function FullCard({
#{entry.position} in line
)}
- {entry.status === 'none' && }
+ {entry.status === 'none' && (
+
+ )}
{entry.status === 'approved' && onOpen && (
-