Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat(writers-room): drag-to-resize AI sidebar + visible per-scene image gen preview
Adam Eivyba3a1dfab05f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 50d0731997..06bbae20be 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -28,6 +28,9 @@## Changed+- **Writers Room — AI sidebar is wider and drag-to-resize.** The right-hand AI/Outline/Versions panel default jumps from 240px → 480px so the Adapt scene cards, Evaluate critique, and Format diff render as real page content instead of being squeezed into a margin. A new vertical splitter between the editor and the sidebar lets the user drag to resize (range 280px → 70% of the work area); the chosen width persists per-user via `localStorage` (`wr.sidebarWidth`) so it sticks across reloads. Double-clicking the splitter resets to 480px. Mobile/tablet (< `lg`) still stacks editor + sidebar vertically and ignores the saved width.+- **Writers Room — per-scene image gen now shows a real preview area.** Clicking the per-scene "Image" button used to silently fire a render with no in-card UI feedback — for FLUX.2 jobs that take 30-90s, this looked like nothing happened until the final PNG appeared. Each `SceneCard` now subscribes to `image-gen:started` / `progress` / `completed` / `failed` socket events filtered by its own job id and renders an `aspect-square` preview slot (matching the Image Gen page) that shows: a spinner with "Step N/M" + ETA while queued, the live base64 diffusion frame as the model decodes intermediate latents, a thin progress bar overlaid at the bottom, and the final PNG once `image-gen:completed` fires. The button label flips between "Image" / "Rendering…" / "Re-render" so the state is unambiguous from the row header alone. Two scenes generating concurrently can't fight over progress because each card filters by its own jobId rather than sharing a single hook.+- **Writers Room — Library pane is collapsible.** A new chevron button in the header hides the 260px library to give the editor full width; a thin 32px rail stays visible with an expand button so the user can bring it back. State persists in `localStorage` under `wr.libraryCollapsed` and survives reloads. Right sidebar in the WorkEditor was also reorganized into three tabs — **AI** (default), **Outline**, **Versions** — replacing the previous always-visible Outline + Versions stack so the AI panel has room to render evaluation results, format diffs, and scene cards inline.- **Edge-to-edge layout for Media Gen, Writers Room, and Settings.** Pages that own a tab strip now follow the canonical full-width shell (header → edge-to-edge tab bar → padded content area) used by Calendar/Brain/etc., so the tab strip pins to the page edges instead of floating inside a centered `max-w-7xl` box. `Layout.jsx` also drops the `max-w-7xl mx-auto` cap on the remaining boxed pages, so on wide monitors content fills the available width (outer `p-4 md:p-6` is preserved, so non-tabbed pages still have breathing room). `MediaGen.jsx` and `Settings.jsx` were rewritten to the canonical shell; `WritersRoom.jsx` swapped its `h-[calc(100vh-3rem)]` viewport hack for `h-full` so the desktop layout no longer leaves a 3rem dead gap at the bottom.- **Sidebar reorg: AI group folded into Settings.** The top-level `AI` sidebar group is gone — its two children (`Prompts`, `Providers`) now live alphabetically under `Settings`. `server/lib/navManifest.js` re-keys `nav.prompts` → `nav.settings.prompts` and `nav.providers` → `nav.settings.providers` (with `section: 'Settings'`) so ⌘K and the voice agent's `ui_navigate` resolver group them with the rest of Settings. Routes (`/prompts`, `/ai`) are unchanged — only the navigational grouping moved, so existing bookmarks keep working.diff --git a/client/src/components/writers-room/AiPanel.jsx b/client/src/components/writers-room/AiPanel.jsxindex 90d3549955..7ab5e8e791 100644--- a/client/src/components/writers-room/AiPanel.jsx+++ b/client/src/components/writers-room/AiPanel.jsx@@ -8,6 +8,7 @@ import {} from '../../services/apiWritersRoom';import { generateImage } from '../../services/apiSystem';import { timeAgo } from '../../utils/formatters';+import socket from '../../services/socket';const KIND_META = {evaluate: { label: 'Evaluate', icon: Sparkles, hint: 'Editorial critique: logline, themes, issues, suggestions' },@@ -274,9 +275,70 @@ function ScriptResult({ result, workTitle }) {}function SceneCard({ scene, workTitle }) {+ // genStatus drives the button + preview overlay:+ // idle → no preview area shown+ // running → preview area shows spinner / live diffusion frame from socket+ // done → preview area shows the final rendered image+ // error → preview area shows the errorconst [genStatus, setGenStatus] = useState('idle');const [generated, setGenerated] = useState(null);const [error, setError] = useState(null);+ // Live diffusion progress for THIS scene's job, filtered by the jobId we+ // got back from generateImage. Each SceneCard tracks its own job, so two+ // cards rendering at once don't fight over a shared progress hook.+ const [progress, setProgress] = useState(null);+ const jobIdRef = useRef(null);++ useEffect(() => {+ const onStarted = (data) => {+ if (!jobIdRef.current || data.generationId !== jobIdRef.current) return;+ setProgress((prev) => ({+ ...(prev || {}),+ progress: 0,+ step: 0,+ totalSteps: data.totalSteps ?? prev?.totalSteps ?? null,+ currentImage: null,+ }));+ };+ const onProgress = (data) => {+ if (!jobIdRef.current || data.generationId !== jobIdRef.current) return;+ setProgress((prev) => ({+ ...(prev || {}),+ progress: data.progress ?? prev?.progress ?? 0,+ step: data.step ?? prev?.step ?? 0,+ totalSteps: data.totalSteps ?? prev?.totalSteps ?? null,+ eta: data.eta ?? prev?.eta ?? null,+ currentImage: data.currentImage ?? prev?.currentImage ?? null,+ }));+ };+ const onCompleted = (data) => {+ if (!jobIdRef.current || data.generationId !== jobIdRef.current) return;+ // The route response already gave us the canonical /data/images/<jobId>.png+ // path, so we keep using `generated` as the source of truth and just flip+ // status. data.path may be present on completion — adopt it if so.+ setGenerated((prev) => prev ? { ...prev, path: data.path || prev.path } : prev);+ setGenStatus('done');+ setProgress(null);+ jobIdRef.current = null;+ };+ const onFailed = (data) => {+ if (!jobIdRef.current || data.generationId !== jobIdRef.current) return;+ setError(data.error || data.message || 'Generation failed');+ setGenStatus('error');+ setProgress(null);+ jobIdRef.current = null;+ };+ socket.on('image-gen:started', onStarted);+ socket.on('image-gen:progress', onProgress);+ socket.on('image-gen:completed', onCompleted);+ socket.on('image-gen:failed', onFailed);+ return () => {+ socket.off('image-gen:started', onStarted);+ socket.off('image-gen:progress', onProgress);+ socket.off('image-gen:completed', onCompleted);+ socket.off('image-gen:failed', onFailed);+ };+ }, []);const generate = async () => {if (genStatus === 'running') return;@@ -286,6 +348,8 @@ function SceneCard({ scene, workTitle }) {}setGenStatus('running');setError(null);+ setProgress(null);+ setGenerated(null);// Truncate at 1900 chars to stay under the 2000-char API limit even when// the model returns a chatty visualPrompt.const prompt = `${workTitle ? `${workTitle}. ` : ''}${scene.visualPrompt}`.slice(0, 1900);@@ -295,10 +359,23 @@ function SceneCard({ scene, workTitle }) {return null;});if (!res) return;+ // For local mode the route returns immediately with a queued/running+ // status and the canonical path. The actual PNG lands at that path when+ // the queue's worker emits `image-gen:completed`. For external/codex+ // mode the response is synchronous and we already have the image —+ // jump straight to `done` with the path.+ jobIdRef.current = res.jobId || res.generationId || null;setGenerated({ path: res.path, jobId: res.jobId, prompt });- setGenStatus('done');+ if (res.status === 'queued' || res.status === 'running') {+ // stay in `running` — socket events drive completion+ } else {+ setGenStatus('done');+ }};+ const progressPct = progress?.progress != null ? Math.round(progress.progress * 100) : null;+ const showPreviewArea = genStatus === 'running' || genStatus === 'done' || genStatus === 'error';+return (<div className="border border-port-border rounded p-2 space-y-1.5 bg-port-card/40"><div className="flex items-start gap-2">@@ -313,9 +390,58 @@ function SceneCard({ scene, workTitle }) {title="Queue an image render using this scene's visual prompt">{genStatus === 'running' ? <Loader2 size={10} className="animate-spin" /> : <ImageIcon size={10} />}- {genStatus === 'running' ? 'Queuing…' : 'Image'}+ {genStatus === 'running' ? 'Rendering…' : genStatus === 'done' ? 'Re-render' : 'Image'}</button></div>++ {showPreviewArea && (+ <div className="aspect-square w-full bg-port-bg border border-port-border rounded-lg overflow-hidden flex items-center justify-center relative">+ {progress?.currentImage ? (+ <img+ src={`data:image/png;base64,${progress.currentImage}`}+ alt="Diffusing…"+ decoding="async"+ className="w-full h-full object-contain"+ />+ ) : genStatus === 'done' && generated?.path ? (+ <a href={generated.path} target="_blank" rel="noreferrer" className="block w-full h-full">+ <img+ src={generated.path}+ alt={scene.heading}+ loading="lazy"+ className="w-full h-full object-contain"+ onError={(e) => { e.currentTarget.style.display = 'none'; }}+ />+ </a>+ ) : genStatus === 'running' ? (+ <div className="text-gray-500 text-xs flex flex-col items-center gap-2 px-3 text-center">+ <Loader2 size={20} className="animate-spin text-port-accent" />+ <span className="font-medium text-gray-300">+ {progress?.step != null && progress?.totalSteps+ ? `Step ${progress.step}/${progress.totalSteps}`+ : 'Queued — waiting for first preview…'}+ </span>+ {progress?.eta != null && (+ <span className="text-[10px] text-gray-500">~{Math.max(0, Math.round(progress.eta))}s remaining</span>+ )}+ </div>+ ) : genStatus === 'error' ? (+ <div className="text-port-error text-xs px-3 text-center break-words">+ {error || 'Generation failed'}+ </div>+ ) : null}++ {genStatus === 'running' && progressPct != null && (+ <div className="absolute bottom-0 left-0 right-0 h-1 bg-black/50">+ <div className="h-full bg-port-accent transition-all" style={{ width: `${progressPct}%` }} />+ </div>+ )}+ </div>+ )}+ {genStatus === 'done' && generated?.jobId && (+ <div className="text-[9px] text-gray-500 truncate">job {generated.jobId}</div>+ )}+{scene.summary && <div className="text-gray-400">{scene.summary}</div>}{scene.characters?.length > 0 && (<div className="flex flex-wrap gap-1">@@ -339,21 +465,6 @@ function SceneCard({ scene, workTitle }) {<div className="mt-1 italic">{scene.visualPrompt}</div></details>)}- {generated && (- <div className="mt-1 space-y-1">- <a href={generated.path} target="_blank" rel="noreferrer" className="block">- <img- src={generated.path}- alt={scene.heading}- loading="lazy"- className="w-full rounded border border-port-border"- onError={(e) => { e.currentTarget.style.display = 'none'; }}- />- </a>- <div className="text-[9px] text-gray-500 truncate">job {generated.jobId}</div>- </div>- )}- {error && <div className="text-[10px] text-port-error">{error}</div>}</div>);}diff --git a/client/src/components/writers-room/WorkEditor.jsx b/client/src/components/writers-room/WorkEditor.jsxindex 5444018f5e..799c921cf2 100644--- a/client/src/components/writers-room/WorkEditor.jsx+++ b/client/src/components/writers-room/WorkEditor.jsx@@ -1,4 +1,4 @@-import { useEffect, useMemo, useRef, useState } from 'react';+import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { Save, GitCommit, Clock, FileText, Sparkles, ListTree } from 'lucide-react';import toast from '../ui/Toast';import {@@ -17,6 +17,18 @@ const SIDEBAR_TABS = [{ id: 'versions', label: 'Versions', Icon: Clock },];+const SIDEBAR_WIDTH_KEY = 'wr.sidebarWidth';+const SIDEBAR_DEFAULT = 480;+const SIDEBAR_MIN = 280;+const SIDEBAR_MAX_FRACTION = 0.7; // never let the sidebar eat more than 70% of the work area++function readSidebarWidth() {+ if (typeof window === 'undefined') return SIDEBAR_DEFAULT;+ const raw = window.localStorage.getItem(SIDEBAR_WIDTH_KEY);+ const n = raw ? parseInt(raw, 10) : NaN;+ return Number.isFinite(n) && n >= SIDEBAR_MIN ? n : SIDEBAR_DEFAULT;+}+export default function WorkEditor({ work, onChange }) {const [body, setBody] = useState(work.activeDraftBody || '');const [title, setTitle] = useState(work.title);@@ -161,6 +173,48 @@ export default function WorkEditor({ work, onChange }) {[work.drafts, work.activeDraftVersionId]);+ // Drag-to-resize sidebar — width is per-user via localStorage so the choice+ // sticks across reloads. The handle is desktop-only; the mobile stack ignores+ // sidebarWidth (the aside renders as a row beneath the editor).+ const splitRef = useRef(null);+ const [sidebarWidth, setSidebarWidth] = useState(readSidebarWidth);+ const dragStartRef = useRef(null);++ const onSplitMouseDown = useCallback((e) => {+ e.preventDefault();+ const startX = e.clientX;+ const startWidth = sidebarWidth;+ const containerWidth = splitRef.current?.getBoundingClientRect().width ?? 0;+ dragStartRef.current = { startX, startWidth, containerWidth };+ document.body.style.cursor = 'col-resize';+ document.body.style.userSelect = 'none';+ }, [sidebarWidth]);++ useEffect(() => {+ const onMove = (e) => {+ if (!dragStartRef.current) return;+ const { startX, startWidth, containerWidth } = dragStartRef.current;+ const max = Math.max(SIDEBAR_MIN + 1, containerWidth * SIDEBAR_MAX_FRACTION);+ // Dragging left grows the right-hand sidebar; dragging right shrinks it.+ const next = Math.min(max, Math.max(SIDEBAR_MIN, startWidth - (e.clientX - startX)));+ setSidebarWidth(next);+ };+ const onUp = () => {+ if (!dragStartRef.current) return;+ dragStartRef.current = null;+ document.body.style.cursor = '';+ document.body.style.userSelect = '';+ // Persist on release rather than every frame — avoids hammering localStorage.+ try { window.localStorage.setItem(SIDEBAR_WIDTH_KEY, String(Math.round(sidebarWidth))); } catch {}+ };+ window.addEventListener('mousemove', onMove);+ window.addEventListener('mouseup', onUp);+ return () => {+ window.removeEventListener('mousemove', onMove);+ window.removeEventListener('mouseup', onUp);+ };+ }, [sidebarWidth]);+return (<div className="flex flex-col h-full"><div className="flex flex-wrap items-center gap-2 px-4 py-3 border-b border-port-border bg-port-card">@@ -201,8 +255,8 @@ export default function WorkEditor({ work, onChange }) {</button></div>- <div className="flex-1 grid grid-cols-1 lg:grid-cols-[1fr_240px] min-h-0">- <div className="relative min-h-0">+ <div ref={splitRef} className="flex-1 flex flex-col lg:flex-row min-h-0">+ <div className="relative min-h-0 flex-1"><textarearef={textareaRef}value={body}@@ -217,7 +271,22 @@ export default function WorkEditor({ work, onChange }) {</div></div>- <aside className="border-t lg:border-t-0 lg:border-l border-port-border bg-port-card/60 flex flex-col text-xs min-h-0">+ <div+ onMouseDown={onSplitMouseDown}+ onDoubleClick={() => {+ setSidebarWidth(SIDEBAR_DEFAULT);+ try { window.localStorage.setItem(SIDEBAR_WIDTH_KEY, String(SIDEBAR_DEFAULT)); } catch {}+ }}+ role="separator"+ aria-label="Resize AI sidebar"+ aria-orientation="vertical"+ title="Drag to resize · double-click to reset"+ className="hidden lg:block w-1 shrink-0 cursor-col-resize bg-port-border hover:bg-port-accent/60 active:bg-port-accent transition-colors"+ />++ <aside+ style={{ '--sidebar-w': `${sidebarWidth}px` }}+ className="border-t lg:border-t-0 border-port-border bg-port-card/60 flex flex-col text-xs min-h-0 w-full lg:w-[var(--sidebar-w)] lg:shrink-0"><div className="flex border-b border-port-border bg-port-bg/40">{SIDEBAR_TABS.map(({ id, label, Icon }) => (<button