an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
feat(window): multi-window "floors" — isolated offices, per-PTY routing (flagged)
Chaitanya Giri66a46ceb3a7c
diff --git a/src/main/config.ts b/src/main/config.tsindex 8b11c83e..0265fc5c 100644--- a/src/main/config.ts+++ b/src/main/config.ts@@ -138,6 +138,14 @@ export interface HarnessConfig {circuitBreaker?: CircuitBreakerConfig;/** Fire native desktop notifications on agent lifecycle events (idle finish / waiting for input). */notifications?: boolean;+ /** Multi-window "floors": expose a New Floor action that opens additional+ * windows, each an independent office with isolated renderer state (its own+ * session partition) and per-window PTY routing. OFF by default (opt-in) —+ * the window/PTY-ownership plumbing is always active and single-window-safe,+ * but the New Floor entry points (app menu item + IPC) only appear when on.+ * The on-disk hive (god orchestration under harnessHome) stays process-global;+ * floors share it. */+ multiWindow?: boolean;/** Terminal theme — mirrored into each agent's per-session Claude settings* ("theme" key) at spawn so the TUI's truecolor palette matches. Scoped to* harness agents only; the user's global Claude theme is never touched. */@@ -189,6 +197,7 @@ const DEFAULTS: HarnessConfig = {embeddingModel: 'minilm',missions: [OPS_STANDUP_MISSION],notifications: false,+ multiWindow: false,slackEnabled: false,slackSigningSecret: undefined,slackBotToken: undefined,diff --git a/src/main/index.ts b/src/main/index.tsindex 23de3bdd..cd8d414f 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1,4 +1,4 @@-import { app, BrowserWindow, clipboard, dialog, ipcMain, powerSaveBlocker, screen, shell, Notification } from 'electron';+import { app, BrowserWindow, clipboard, dialog, ipcMain, Menu, powerSaveBlocker, screen, shell, Notification } from 'electron';import { spawn } from 'node:child_process';import { rmSync, existsSync, readFileSync, readdirSync, statSync, cpSync, writeFileSync, unlinkSync, mkdirSync, createWriteStream } from 'node:fs';import { randomBytes, createHash, timingSafeEqual } from 'node:crypto';@@ -125,7 +125,18 @@ const reflector = new MemoryReflector(// Durable harness state (SQLite, main process). Phase A: window bounds (kv) +// net-new command history. Opened in whenReady, closed in the teardown blocks.const persist = new PersistStore();+/** The PRIMARY window — the one running the hive/god orchestration and the sink+ * for process-global timer events (missions, breaker, Slack ingestion). It is+ * the most-recently-focused live window, so global events follow the user.+ * Additional "floor" windows are tracked in `allWindows` below. */let mainWindow: BrowserWindow | null = null;+/** Every open window (primary + floors). A registry, not a single handle, so+ * multi-window lifecycle (focus tracking, quit fan-out) is correct. */+const allWindows = new Set<BrowserWindow>();+/** Monotonic floor counter → a stable, unique session partition per floor so+ * each floor's renderer state (localStorage: agents, queues, selection) is+ * isolated from every other window's. */+let floorSeq = 0;/** When true, skip the quit interceptor (user already confirmed). */let allowQuit = false;@@ -589,7 +600,13 @@ function armHeartbeat(m: ScheduledMission): void {* throws "Object has been destroyed" (the main-process crash dialog). */function liveWebContents(): Electron.WebContents | null {const wc = mainWindow?.webContents;- return wc && !wc.isDestroyed() ? wc : null;+ if (wc && !wc.isDestroyed()) return wc;+ // Primary gone (closed/destroyed): fall back to any other live window so a+ // global event still reaches a renderer instead of being silently dropped.+ for (const w of allWindows) {+ if (!w.isDestroyed() && !w.webContents.isDestroyed()) return w.webContents;+ }+ return null;}// ─── Slack webhook server (Slack message → Michael's queue) ──────────────────@@ -1121,18 +1138,42 @@ function debounce(fn: () => void, ms: number): () => void {return () => { if (t) clearTimeout(t); t = setTimeout(() => { t = null; fn(); }, ms); };}-function createWindow(): void {- // Restore the last window geometry (kv), falling back to the default size.+/** Cascade a new floor off the focused window so it doesn't stack exactly on+ * top, clamped on-screen (clampBounds drops an off-display position). */+function floorCascade(): WindowBounds | null {+ const base = (mainWindow && !mainWindow.isDestroyed())+ ? mainWindow+ : [...allWindows].find((w) => !w.isDestroyed());+ if (!base) return null;+ const b = base.getBounds();+ const OFFSET = 36;+ return clampBounds({ x: b.x + OFFSET, y: b.y + OFFSET, width: b.width, height: b.height });+}++/**+ * Create a window. The PRIMARY window (no opts) restores saved geometry, uses+ * the default session, runs the hive, and keeps the existing app-quit warning.+ * A FLOOR window (`{ floor: true }`) gets its own persistent session partition+ * — isolating its renderer state (agents/queues/selection) from every other+ * window — cascades its position, and on close stops only its OWN terminals+ * while the app keeps running.+ */+function createWindow(opts: { floor?: boolean } = {}): BrowserWindow {+ const isFloor = opts.floor === true;++ // Primary restores saved geometry; floors cascade off the focused window.let saved: WindowBounds | null = null;- try { saved = clampBounds(persist.getKv('window.bounds')); } catch { saved = null; }+ if (!isFloor) { try { saved = clampBounds(persist.getKv('window.bounds')); } catch { saved = null; } }+ const cascade = isFloor ? floorCascade() : null;+ const geom = cascade ?? saved;const win = new BrowserWindow({- width: saved?.width ?? DEFAULT_WIN.width,- height: saved?.height ?? DEFAULT_WIN.height,- ...(saved && saved.x !== undefined && saved.y !== undefined ? { x: saved.x, y: saved.y } : {}),+ width: geom?.width ?? DEFAULT_WIN.width,+ height: geom?.height ?? DEFAULT_WIN.height,+ ...(geom && geom.x !== undefined && geom.y !== undefined ? { x: geom.x, y: geom.y } : {}),minWidth: MIN_WIN.width,minHeight: MIN_WIN.height,- title: 'Munder Difflin',+ title: isFloor ? 'Munder Difflin — Floor' : 'Munder Difflin',backgroundColor: '#FFF8E7',titleBarStyle: 'hiddenInset',show: false,@@ -1145,24 +1186,39 @@ function createWindow(): void {// flush, telemetry polls). Chromium throttles timers in occluded windows// — incl. behind the LOCK SCREEN — which silently stalls the hive while// the user is away. Don't.- backgroundThrottling: false+ backgroundThrottling: false,+ // Each floor gets its OWN persistent session partition → isolated+ // localStorage so floors never share or stomp each other's office state.+ // The primary keeps the DEFAULT session so existing persisted state loads.+ ...(isFloor ? { partition: `persist:floor-${++floorSeq}` } : {})}});- mainWindow = win;-- // Persist geometry as the user drags/resizes (debounced) and on close. Skip- // while maximized/minimized so a restore doesn't save the fullscreen rect.- const saveBounds = debounce(() => {- if (win.isDestroyed() || win.isMinimized() || win.isMaximized()) return;- try { persist.setKv('window.bounds', win.getBounds()); } catch { /* DB best-effort */ }- }, 400);- win.on('resized', saveBounds);- win.on('moved', saveBounds);- win.on('close', () => {- if (win.isDestroyed() || win.isMinimized() || win.isMaximized()) return;- try { persist.setKv('window.bounds', win.getBounds()); } catch { /* DB best-effort */ }- });+ // Capture the webContents once: after 'closed' the window is gone, but this+ // reference stays valid as the per-PTY ownership key.+ const wc = win.webContents;++ allWindows.add(win);+ // Global timer events follow the user — the most-recently-focused window is+ // primary. The primary is also seeded synchronously so boot events route now.+ win.on('focus', () => { mainWindow = win; });+ if (!isFloor) mainWindow = win;++ // Only the primary persists geometry (kv `window.bounds`); floors cascade+ // fresh each launch. Skip while maximized/minimized so a restore doesn't save+ // the fullscreen rect.+ if (!isFloor) {+ const saveBounds = debounce(() => {+ if (win.isDestroyed() || win.isMinimized() || win.isMaximized()) return;+ try { persist.setKv('window.bounds', win.getBounds()); } catch { /* DB best-effort */ }+ }, 400);+ win.on('resized', saveBounds);+ win.on('moved', saveBounds);+ win.on('close', () => {+ if (win.isDestroyed() || win.isMinimized() || win.isMaximized()) return;+ try { persist.setKv('window.bounds', win.getBounds()); } catch { /* DB best-effort */ }+ });+ }win.once('ready-to-show', () => win.show());@@ -1171,19 +1227,38 @@ function createWindow(): void {return { action: 'deny' };});- // On macOS, the red-X "close" event by default destroys the window — and on- // a single-window app, that effectively quits. Intercept it the same way we- // intercept before-quit so PTY users get the warning.+ // Close interception when live PTYs exist. The red-X destroys the window;+ // intercept it the same way before-quit does so PTY users aren't surprised.win.on('close', (e) => {if (allowQuit) return;+ if (isFloor) {+ // A floor's close is NOT an app quit — confirm only its OWN terminals,+ // via a self-contained native dialog (no renderer modal). Confirming lets+ // the window close; its PTYs are stopped in the 'closed' handler.+ const owned = ptyManager.countByOwner(wc);+ if (owned > 0) {+ const choice = dialog.showMessageBoxSync(win, {+ type: 'warning',+ buttons: ['Close floor', 'Cancel'],+ defaultId: 1,+ cancelId: 1,+ message: `Close this floor? ${owned} running terminal${owned === 1 ? '' : 's'} on it will be stopped.`,+ detail: 'Other floors keep running.'+ });+ if (choice === 1) e.preventDefault();+ }+ return;+ }+ // Primary window: existing app-wide quit warning (renderer modal).const count = ptyManager.list().length;if (count === 0) return;e.preventDefault();win.focus();- win.webContents.send('app:closeRequested', { ptyCount: count });+ wc.send('app:closeRequested', { ptyCount: count });});- ptyManager.attachWebContents(win.webContents);+ // The primary is the default PTY sink; floors route purely by per-PTY owner.+ if (!isFloor) ptyManager.attachWebContents(wc);if (isDev && process.env.ELECTRON_RENDERER_URL) {win.loadURL(process.env.ELECTRON_RENDERER_URL);@@ -1192,12 +1267,56 @@ function createWindow(): void {}win.on('closed', () => {- if (mainWindow === win) mainWindow = null;+ allWindows.delete(win);+ // A closed floor must not leave its terminals running headless. (Natural+ // onExit teardown — archive + worktree cleanup — still runs per PTY.)+ if (isFloor) { try { ptyManager.killByOwner(wc); } catch { /* best-effort */ } }+ if (mainWindow === win) {+ mainWindow = null;+ for (const w of allWindows) { if (!w.isDestroyed()) { mainWindow = w; break; } }+ }+ syncKeepAwake();});++ return win;+}++/** Open a new floor window — gated by the multiWindow flag. Returns the window,+ * or null when the feature is off (the entry points are hidden in that case,+ * but the IPC stays defensive). */+function openFloor(): BrowserWindow | null {+ if (!readConfig().multiWindow) return null;+ return createWindow({ floor: true });+}++/** Build + install the application menu. Only called when multiWindow is on, so+ * flag-off keeps Electron's default menu (zero behavior change). Uses standard+ * role-based items so copy/paste/quit/etc. work per-platform, and adds the+ * "New Floor" item (Cmd/Ctrl+Shift+N). */+function installAppMenu(): void {+ const isMac = process.platform === 'darwin';+ const newFloorItem = {+ label: 'New Floor',+ accelerator: 'CmdOrCtrl+Shift+N',+ click: () => { openFloor(); }+ };+ const template: Electron.MenuItemConstructorOptions[] = [+ ...(isMac ? [{ role: 'appMenu' as const }] : []),+ {+ label: 'File',+ submenu: isMac+ ? [newFloorItem, { type: 'separator' as const }, { role: 'close' as const }]+ : [newFloorItem, { type: 'separator' as const }, { role: 'quit' as const }]+ },+ { role: 'editMenu' },+ { role: 'viewMenu' },+ { role: 'windowMenu' }+ ];+ Menu.setApplicationMenu(Menu.buildFromTemplate(template));}// ─── IPC: pty lifecycle ─────────────────────────────────────────────────────-ipcMain.handle('pty:spawn', async (_evt, opts: SpawnOptions & { hive?: AgentMeta; isolate?: boolean; resume?: boolean; provider?: AgentProvider }) => {+ipcMain.handle('pty:spawn', async (evt, opts: SpawnOptions & { hive?: AgentMeta; isolate?: boolean; resume?: boolean; provider?: AgentProvider }) => {if (!opts || typeof opts.id !== 'string' || typeof opts.cwd !== 'string' || typeof opts.command !== 'string') {return { ok: false, error: 'invalid SpawnOptions' };}@@ -1307,7 +1426,10 @@ ipcMain.handle('pty:spawn', async (_evt, opts: SpawnOptions & { hive?: AgentMetaif (Object.keys(nonInteractiveEnv).length > 0) {opts.env = { ...(opts.env ?? {}), ...nonInteractiveEnv };}- const res = ptyManager.spawn(opts);+ // Record the spawning window as the PTY's owner so its output (pty:data/exit)+ // routes ONLY back to that floor — never leaking into another window's stream.+ const owner = BrowserWindow.fromWebContents(evt.sender)?.webContents ?? null;+ const res = ptyManager.spawn(opts, owner);syncKeepAwake(); // arm the power-save blocker while ≥1 agent PTY is alive (#18)return res;});@@ -1571,6 +1693,14 @@ ipcMain.handle('app:cancelClose', () => {// no-op — modal will close on the renderer side});+// Open a new floor (independent office window). Gated by the multiWindow flag+// inside openFloor(); returns whether a window opened so a renderer button can+// reflect availability. The app-menu "New Floor" item calls openFloor() directly.+ipcMain.handle('window:newFloor', () => {+ const win = openFloor();+ return { ok: win != null };+});+// ─── IPC: closing time (graceful, data-loss-free shutdown) ──────────────────// The third quit-dialog button. The god broadcasts closing time, every worker// saves its memory and ACKs, the god concludes with CLOSING-TIME-COMPLETE —@@ -1864,6 +1994,9 @@ app.whenReady().then(() => {try { persist.open(); } catch (e) { console.error('[db] open failed:', e); }// Bootstrap the hive (if harnessHome is configured) and start the message router.bootstrapHiveServices();+ // Multi-window floors (opt-in): install the menu carrying "New Floor". When+ // off, the app keeps Electron's default menu — zero behavior change.+ if (readConfig().multiWindow) installAppMenu();createWindow();// Auto-start the Slack webhook server when configured. Best-effort: a tunnel// failure (offline) is logged, not fatal. The tunnel URL is ephemeral anddiff --git a/src/main/pty.ts b/src/main/pty.tsindex 6506add7..75e26899 100644--- a/src/main/pty.ts+++ b/src/main/pty.ts@@ -8,6 +8,12 @@ interface PtySession {proc: pty.IPty;cwd: string;command: string;+ /** The window (webContents) that spawned this PTY and should receive its+ * output. Multi-window: each floor owns its own terminals, so `pty:data:<id>`+ * / `pty:exit:<id>` route ONLY here — never broadcast — so one floor's stream+ * never leaks into another. Null falls back to the default attached sink+ * (the primary window), preserving single-window behavior. */+ owner: WebContents | null;/** Epoch ms of the most recent byte this PTY emitted (bumped in onData). The* heartbeat (Lane A #1) reads this for two things: floor-quiet detection (an* agent printing/thinking counts as activity even before it writes a hive@@ -63,10 +69,29 @@ export class PtyManager {* runs. Best-effort — set once by the main process. */private exitHandler: ((id: string) => void) | null = null;+ /** The default/fallback output sink — set to the PRIMARY window. Used only for+ * sessions with no recorded owner; owned sessions route to their owner. */attachWebContents(wc: WebContents) {this.webContents = wc;}+ /** Count live PTYs owned by a given window — used to scope a floor's+ * close-confirmation to its OWN terminals, not the whole app's. */+ countByOwner(wc: WebContents): number {+ let n = 0;+ for (const s of this.sessions.values()) if (s.owner === wc) n++;+ return n;+ }++ /** Kill every PTY owned by a window (its onExit runs the normal teardown:+ * archive + worktree cleanup). Called when a floor window closes so its+ * terminals don't linger as orphaned processes writing to a dead webContents. */+ killByOwner(wc: WebContents): void {+ for (const [id, s] of [...this.sessions.entries()]) {+ if (s.owner === wc) { try { s.proc.kill(); } catch { /* already gone */ } void id; }+ }+ }+/** Register the natural-exit teardown callback. Invoked from inside node-pty's* onExit after the session is cleaned up. */setExitHandler(handler: (id: string) => void): void {@@ -77,8 +102,10 @@ export class PtyManager {* PTY fires onExit asynchronously — by then app.quit() may have destroyed the* window, and `.send()` on a destroyed webContents throws "Object has been* destroyed", which surfaces as the main-process crash dialog. Guard it. */- private safeSend(channel: string, payload: unknown): void {- const wc = this.webContents;+ private safeSend(channel: string, payload: unknown, target?: WebContents | null): void {+ // Route to the session's owner window when known (multi-window: keeps each+ // floor's stream private); fall back to the default attached sink otherwise.+ const wc = target ?? this.webContents;if (!wc || wc.isDestroyed()) return;try { wc.send(channel, payload); } catch { /* window tore down mid-send */ }}@@ -147,7 +174,7 @@ export class PtyManager {return command;}- spawn(opts: SpawnOptions): { ok: boolean; error?: string } {+ spawn(opts: SpawnOptions, owner: WebContents | null = null): { ok: boolean; error?: string } {if (this.sessions.has(opts.id)) {return { ok: false, error: `pty already exists for id ${opts.id}` };}@@ -209,15 +236,16 @@ export class PtyManager {} as Record<string, string>});- this.sessions.set(opts.id, { id: opts.id, proc, cwd: opts.cwd, command: resolved, lastOutputAt: Date.now() });+ this.sessions.set(opts.id, { id: opts.id, proc, cwd: opts.cwd, command: resolved, lastOutputAt: Date.now(), owner });proc.onData((data) => {const s = this.sessions.get(opts.id);if (s) s.lastOutputAt = Date.now();- this.safeSend(`pty:data:${opts.id}`, data);+ this.safeSend(`pty:data:${opts.id}`, data, s?.owner);});proc.onExit(({ exitCode, signal }) => {- this.safeSend(`pty:exit:${opts.id}`, { exitCode, signal });+ const s = this.sessions.get(opts.id);+ this.safeSend(`pty:exit:${opts.id}`, { exitCode, signal }, s?.owner);this.sessions.delete(opts.id);// Natural exit must run the same lifecycle teardown as an explicit kill.// Guarded so a teardown error can never crash node-pty's exit callback.diff --git a/src/preload/index.ts b/src/preload/index.tsindex df3c33c2..00b38628 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -463,6 +463,11 @@ const api = {confirmClose: (): Promise<void> => ipcRenderer.invoke('app:confirmClose'),cancelClose: (): Promise<void> => ipcRenderer.invoke('app:cancelClose'),+ // ─── Multi-window floors ───────────────────────────────────────────────────+ /** Open a new floor (independent office window). No-op when the multiWindow+ * flag is off. Resolves { ok } indicating whether a window opened. */+ newFloor: (): Promise<{ ok: boolean }> => ipcRenderer.invoke('window:newFloor'),+// ─── Closing time (graceful shutdown via the hive) ─────────────────────────/** Start the closing-time protocol: the god broadcasts shutdown, every worker* saves its memory and ACKs, the god concludes — then the app quits itself.