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([story-builder-embed-arccanvas]): embed the Arc Canvas + a reader-map beat timeline in the builder
[._.]/ Adam Eivye546477e1415
diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsxindex 9a3023eead..df4ba4bcae 100644--- a/client/src/pages/StoryBuilder.jsx+++ b/client/src/pages/StoryBuilder.jsx@@ -19,10 +19,11 @@ import {getStoryBuilderSteps, listStorySessions, getStorySession, createStorySession,updateStorySession, setStoryCurrentStep, lockStoryStep, unlockStoryStep,generateStoryStep, refineStoryStep, setStoryIssueLock, generateStoryIssues,- getUniverse, getPipelineSeries, listPipelineIssues,+ getUniverse, getPipelineSeries, listPipelineIssues, updatePipelineSeries,analyzeImport, commitImport, retryImporterIssues, IMPORTER_CONTENT_TYPES,getProviders, getSettings, generateImage, updateUniverse,} from '../services/api';+import ArcCanvas from '../components/pipeline/ArcCanvas';// Mirror Importer.jsx's commit picker — only these arc fields are sent on commit.const ARC_FIELDS_TO_COMMIT = ['logline', 'summary', 'protagonistArc', 'themes', 'shape'];@@ -359,6 +360,77 @@ function FieldBlock({ label, value }) {);}+// Color per reader-map beat kind (mirrors READER_MAP_BEAT_KINDS server-side).+const BEAT_KIND_COLOR = {+ hook: '#3b82f6', // port-accent — a question planted+ reveal: '#a855f7', // purple — new information+ payoff: '#22c55e', // port-success — a question answered+ emotional: '#f59e0b', // port-warning — a felt beat+ cliffhanger: '#ef4444', // port-error — an issue-boundary hook+};++// A compact timeline of the reader map's emotional beats: each beat is a bar+// positioned along the arc (normalized from `atArcPosition`) with its height+// set by `intensity` and its color by `kind`. Gives the reader-map step the+// at-a-glance escalation/pacing view the plain list can't. Beats without a+// position fall back to even spacing so they still render.+function ReaderMapBeatTimeline({ readerMap }) {+ const beats = Array.isArray(readerMap?.beats) ? readerMap.beats : [];+ if (beats.length === 0) return null;++ const W = 320;+ const H = 64;+ const PAD = 4;+ // Normalize positions: beats use an arbitrary `atArcPosition` scale (0..9999),+ // so map the observed [min,max] span onto the plot width. When every beat+ // shares a position (or none have one), fall back to even spacing by index.+ const positioned = beats.filter((b) => Number.isFinite(b.atArcPosition));+ const minPos = positioned.length ? Math.min(...positioned.map((b) => b.atArcPosition)) : 0;+ const maxPos = positioned.length ? Math.max(...positioned.map((b) => b.atArcPosition)) : 0;+ const span = maxPos - minPos;+ const xFor = (b, i) => {+ const usable = W - PAD * 2;+ if (span > 0 && Number.isFinite(b.atArcPosition)) {+ return PAD + ((b.atArcPosition - minPos) / span) * usable;+ }+ return beats.length === 1 ? W / 2 : PAD + (i / (beats.length - 1)) * usable;+ };++ return (+ <div>+ <div className="text-xs uppercase tracking-wide text-gray-500 mb-1">Beat timeline</div>+ <svg+ viewBox={`0 0 ${W} ${H}`}+ className="w-full h-16 bg-port-bg border border-port-border rounded"+ preserveAspectRatio="none"+ role="img"+ aria-label={`Reader-map beat timeline — ${beats.length} beats`}+ >+ <line x1={PAD} y1={H - PAD} x2={W - PAD} y2={H - PAD} stroke="#2a2a2a" strokeWidth="1" />+ {beats.map((b, i) => {+ const x = xFor(b, i);+ const intensity = Number.isFinite(b.intensity) ? Math.max(0, Math.min(1, b.intensity)) : 0.5;+ const barH = (H - PAD * 2) * intensity;+ const color = BEAT_KIND_COLOR[b.kind] || '#9ca3af';+ return (+ <g key={b.id || i}>+ <rect x={x - 1.5} y={H - PAD - barH} width="3" height={barH} fill={color} rx="1" />+ <title>{`${b.kind}${b.intensity != null ? ` ${Math.round(intensity * 100)}%` : ''}${b.note ? ` — ${b.note}` : ''}`}</title>+ </g>+ );+ })}+ </svg>+ <div className="flex flex-wrap gap-x-3 gap-y-0.5 mt-1">+ {Object.entries(BEAT_KIND_COLOR).map(([kind, color]) => (+ <span key={kind} className="inline-flex items-center gap-1 text-[10px] text-gray-500">+ <span className="inline-block w-2 h-2 rounded-sm" style={{ backgroundColor: color }} /> {kind}+ </span>+ ))}+ </div>+ </div>+ );+}+function ReaderMapView({ readerMap }) {if (!readerMap) return <p className="text-gray-600 italic text-sm">No reader map yet. Generate one to plan the audience experience.</p>;const Section = ({ title, items, render }) => (@@ -471,7 +543,7 @@ function RefineBox({ onRefine, disabled, busy, running, phase }) {);}-function StepPanel({ session, universe, series, issues, stepId, locked, onChanged }) {+function StepPanel({ session, universe, series, issues, stepId, locked, onChanged, onSeriesUpdate, onIssuesUpdate, onFlushPending }) {const { start, busy, phase, op } = useStepStream(session.id, stepId);const arc = series?.arc || {};const isRunning = (which) => busy && op === which;@@ -567,26 +639,45 @@ function StepPanel({ session, universe, series, issues, stepId, locked, onChange);}if (stepId === 'plotArc') {+ const hasArc = Boolean((arc.logline || arc.summary || '').trim());return (<div className="space-y-3">- <FieldBlock label="Arc logline" value={arc.logline} />- <FieldBlock label="Arc summary" value={arc.summary} />- <FieldBlock label="Protagonist arc" value={arc.protagonistArc} />- <FieldBlock label="Themes" value={(arc.themes || []).join(', ')} />- <FieldBlock label="Emotional shape (Vonnegut)" value={arc.shape} /><div className="flex items-center gap-2 flex-wrap">- {!locked && genButton('Generate plot arc', Boolean((arc.logline || arc.summary || '').trim()))}+ {!locked && genButton('Generate plot arc', hasArc)}{!locked && issuesHaveContent && backfillButton()}{series?.id && (<Link to={`/pipeline/series/${series.id}`} className="inline-flex items-center gap-1 text-sm text-gray-400 hover:text-port-accent">- <ExternalLink className="w-4 h-4" /> Deep-edit on the Arc Canvas+ <ExternalLink className="w-4 h-4" /> Open the full Arc Canvas page</Link>)}</div>- {issuesHaveContent && (+ {issuesHaveContent && !hasArc && (<p className="text-xs text-gray-500">Started from drafted issues? Backfill extracts the arc from their scripts / prose.</p>)}- {!locked && (arc.logline || arc.summary) && (+ {/* Embed the Arc Canvas inline once an arc exists, so the logline /+ summary / protagonist arc / themes / Vonnegut shape AND the season+ roadmap are editable in-builder instead of read-only field blocks ++ a deep-link. Falls back to the field summary before the first+ generate (ArcCanvas has nothing to show without an arc). The arc step+ is the right home for the whole-roadmap editor: it owns series.arc. */}+ {hasArc ? (+ <ArcCanvas+ series={series}+ issues={issues}+ onSeriesUpdate={onSeriesUpdate}+ onIssuesUpdate={onIssuesUpdate}+ onFlushPending={onFlushPending}+ />+ ) : (+ <>+ <FieldBlock label="Arc logline" value={arc.logline} />+ <FieldBlock label="Arc summary" value={arc.summary} />+ <FieldBlock label="Protagonist arc" value={arc.protagonistArc} />+ <FieldBlock label="Themes" value={(arc.themes || []).join(', ')} />+ <FieldBlock label="Emotional shape (Vonnegut)" value={arc.shape} />+ </>+ )}+ {!locked && hasArc && (<RefineBox onRefine={(fb) => runRefine(fb)} busy={busy} running={isRunning('refine')} phase={phase} />)}</div>@@ -595,6 +686,7 @@ function StepPanel({ session, universe, series, issues, stepId, locked, onChangeif (stepId === 'readerMap') {return (<div className="space-y-3">+ <ReaderMapBeatTimeline readerMap={arc.readerMap} /><ReaderMapView readerMap={arc.readerMap} />{!locked && genButton('Generate reader map', Boolean(arc.readerMap))}{!locked && arc.readerMap && <RefineBox onRefine={(fb) => runRefine(fb)} busy={busy} running={isRunning('refine')} phase={phase} />}@@ -878,6 +970,52 @@ function StoryBuilderDetail({ storyId, stepParam }) {setLoading(false);}, [storyId]);+ // ── Embedded ArcCanvas wiring (plotArc step) ──────────────────────────────+ // The Arc Canvas edits series.arc + the issue roadmap in place, so it needs+ // server-confirmed setters. Mirrors PipelineSeries.jsx: a `lastSavedRef`+ // dirty-check, an `updateSeriesFromServer` that keeps it aligned, and an+ // issues setter that accepts ArcCanvas's `setState(fn)`-shaped updates.+ const lastSavedRef = useRef(null);+ useEffect(() => { if (series) lastSavedRef.current = series; }, [series]);++ const updateSeriesFromServer = useCallback((next) => {+ setSeries(next);+ lastSavedRef.current = next;+ }, []);++ // ArcCanvas mutates issues via a setter-style update (`setState(fn)`-shaped);+ // plain arrays also work — flatten through Array.isArray to support both.+ const handleIssuesUpdate = useCallback((update) => {+ setIssues((prev) => {+ if (typeof update === 'function') return update(prev);+ if (Array.isArray(update)) return update;+ return prev;+ });+ }, []);++ // ArcCanvas calls this before a generate/verify so the server works against+ // the on-screen bible fields. The Story Builder edits those fields on their+ // own steps (not inside the arc step), so the only divergence to flush here+ // is whatever ArcCanvas itself set via updateSeriesFromServer — which already+ // persisted. So flush is a no-op unless a future inline bible edit lands;+ // kept for API-shape parity with ArcCanvas's contract.+ const flushPending = useCallback(async () => {+ if (!series) return false;+ const saved = lastSavedRef.current || series;+ const fields = ['name', 'logline', 'premise', 'styleNotes', 'issueCountTarget', 'universeId'];+ const dirty = fields.some((k) => (series[k] ?? '') !== (saved[k] ?? ''))+ || JSON.stringify(series.llm || {}) !== JSON.stringify(saved.llm || {});+ if (!dirty) return false;+ const updated = await updatePipelineSeries(series.id, {+ name: series.name, logline: series.logline, premise: series.premise,+ universeId: series.universeId, styleNotes: series.styleNotes,+ issueCountTarget: series.issueCountTarget, llm: series.llm || { provider: null, model: null },+ }, { silent: true }).catch(() => null);+ if (!updated) return false;+ updateSeriesFromServer(updated);+ return true;+ }, [series, updateSeriesFromServer]);+// Load the step manifest first; gate the loading spinner on BOTH it and the// session so the detail view never renders with an empty step rail.useEffect(() => {@@ -1026,6 +1164,9 @@ function StoryBuilderDetail({ storyId, stepParam }) {key={activeStepId}session={session} universe={universe} series={series} issues={issues}stepId={activeStepId} locked={stepState.locked} onChanged={reload}+ onSeriesUpdate={updateSeriesFromServer}+ onIssuesUpdate={handleIssuesUpdate}+ onFlushPending={flushPending}/>{/* Footer: lock + navigation */}diff --git a/client/src/pages/StoryBuilder.test.jsx b/client/src/pages/StoryBuilder.test.jsxindex f924e9fe12..efb9d78d52 100644--- a/client/src/pages/StoryBuilder.test.jsx+++ b/client/src/pages/StoryBuilder.test.jsx@@ -40,9 +40,17 @@ const api = vi.hoisted(() => ({getSettings: vi.fn(),generateImage: vi.fn(),updateUniverse: vi.fn(),+ updatePipelineSeries: vi.fn(),}));vi.mock('../services/api', () => api);+// The plotArc step embeds the full ArcCanvas roadmap editor; mock it to an+// inert sentinel so these tests assert the EMBEDDING (and its props) without+// pulling ArcCanvas's heavy import graph or its own API calls into scope.+vi.mock('../components/pipeline/ArcCanvas', () => ({+ default: ({ series }) => <div data-testid="arc-canvas">ArcCanvas[{series?.id}]</div>,+}));+import StoryBuilder from './StoryBuilder';const renderAt = (path) => render(@@ -208,6 +216,41 @@ describe('StoryBuilder — detail stepper', () => {expect(screen.queryByText('Generate reader map')).toBeNull();});+ it('plotArc step embeds the ArcCanvas once an arc exists, and shows the field summary before that', async () => {+ // No arc yet → read-only field summary, no embedded canvas.+ api.getPipelineSeries.mockResolvedValueOnce({ id: 's1', arc: { logline: '', summary: '' } });+ api.getStorySession.mockResolvedValue({+ id: 'stb-1', title: 'X', currentStep: 'plotArc', universeId: 'u1', seriesId: 's1',+ steps: mkSteps({ idea: { locked: true }, universeAesthetic: { locked: true } }),+ staleSteps: [], llm: { provider: '', model: '' },+ });+ const { unmount } = renderAt('/story-builder/stb-1/plotArc');+ await waitFor(() => expect(screen.getByText('Generate plot arc')).toBeTruthy());+ expect(screen.queryByTestId('arc-canvas')).toBeNull();+ unmount();++ // Arc present → the ArcCanvas is embedded inline (wired with the series).+ api.getPipelineSeries.mockResolvedValue({ id: 's1', arc: { logline: 'AL', summary: 'AS' } });+ renderAt('/story-builder/stb-1/plotArc');+ await waitFor(() => expect(screen.getByTestId('arc-canvas')).toBeTruthy());+ expect(screen.getByTestId('arc-canvas').textContent).toContain('s1');+ });++ it('readerMap step renders the beat timeline when the map has beats', async () => {+ api.getPipelineSeries.mockResolvedValue({+ id: 's1',+ arc: { logline: 'AL', summary: 'AS', readerMap: { beats: [{ id: 'rm-b1', kind: 'hook', atArcPosition: 0, intensity: 0.4 }, { id: 'rm-b2', kind: 'payoff', atArcPosition: 100, intensity: 0.9 }] } },+ });+ api.getStorySession.mockResolvedValue({+ id: 'stb-1', title: 'X', currentStep: 'readerMap', universeId: 'u1', seriesId: 's1',+ steps: mkSteps({ idea: { locked: true }, universeAesthetic: { locked: true }, plotArc: { locked: true } }),+ staleSteps: [], llm: { provider: '', model: '' },+ });+ renderAt('/story-builder/stb-1/readerMap');+ await waitFor(() => expect(screen.getByText('Beat timeline')).toBeTruthy());+ expect(screen.getByLabelText(/beat timeline — 2 beats/i)).toBeTruthy();+ });+it('"Lock & continue" locks the step AND auto-advances to the next', async () => {const { fireEvent } = await import('@testing-library/react');api.getStorySession.mockResolvedValue({