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
refactor([story-builder-embed-arccanvas]): /simplify — fix lastSavedRef guard, extract beat colors
[._.]/ Adam Eivy06a5bfe64b18
diff --git a/PLAN.md b/PLAN.mdindex 41f714741b..223ae44110 100644--- a/PLAN.md+++ b/PLAN.md@@ -9,6 +9,7 @@ Claimable, well-specified, no decision needed — `/claim`-able. Unordered.- [ ] [story-builder-create-rollback] **`createStorySession` seed mode leaves an orphan universe if `createSeries` throws.** `server/services/storyBuilder.js` creates the universe shell, then the series shell, with no rollback — a `createSeries` failure leaves a stray universe (which also fired peer auto-subscribe) with no session pointing at it. Wrap the two creates so a series failure deletes the just-created universe, or create the series first.- [ ] [story-builder-goto-step-gate-divergence] **Two `setStoryCurrentStep` paths swallow a rejection and navigate anyway.** (a) `goToStep` in `client/src/pages/StoryBuilder.jsx` (~line 769) on a manual step click and (b) the `lock.toggle` `onSuccess` auto-advance (~line 754). If the server re-gate rejects the move while the client's `staleSteps` is stale, the UI lands on the target step but the persisted `currentStep` pointer stays behind. Either toast + revert nav on rejection, or refetch on failure. Both paths share the fix.- [ ] [story-builder-import-partial-commit] **Import flow doesn't handle a partial commit.** `ImportPanel.importAndBuild` calls `commitImport` once; if it fails after the universe/arc/canon persist but the issue-create rolls back, it just toasts a generic error. Re-clicking re-sends the full payload — a retry could duplicate issues. The standalone `Importer.jsx` guards this with the `arcAlreadyPersisted` retry (sends `arc:null, seasons:[]`). Either reuse that path or surface a "open in the Importer to recover" link.+- [ ] [arccanvas-sync-shared-hook] **Cleanup: extract the ArcCanvas host-wiring into a shared hook.** `client/src/pages/PipelineSeries.jsx` and `client/src/pages/StoryBuilder.jsx` (the `StoryBuilderDetail` wiring added by `story-builder-embed-arccanvas`) both hand-roll the same `lastSavedRef` + `updateSeriesFromServer` + `handleIssuesUpdate` + `flushPending` contract ArcCanvas expects. The two `flushPending` field-sets diverge (PipelineSeries flushes 10 bible fields + cover/style overrides; StoryBuilder only 6 and treats it as a near-no-op), and PipelineSeries also carries `patchSeries`/`handleSave`. Extract `useArcCanvasSync({ series, setSeries, setIssues, flushFields })` → `{ updateSeriesFromServer, handleIssuesUpdate, flushPending }` in `client/src/hooks/` and migrate both callers. Deferred from the embed PR because it's a 2-file refactor (touches PipelineSeries) with its own review surface.- [ ] [story-builder-extract-image-render-hook] **Cleanup: the image-render lifecycle is duplicated 5×.** `StepCharacters` (StoryBuilder.jsx) + `StyleProbeImage.jsx` each re-implement `getSettings → readPipelineImageSettings → imageCfg` + a single-render jobId lifecycle, and `StepCharacters` near-verbatim copies `UniverseCanonSection`'s styled-render-and-persist routine. Extract a `useImageRenderSettings()` + `useSingleImageRender({ buildPrompt, onComplete })` hook and a shared canon styled-render helper. Also: `ProviderModelPicker` (StoryBuilder.jsx) duplicates the Importer's `LlmPicker` + `SeriesLlmPicker`/`FeatureProviderPicker`/`StagePromptModelPicker` — promote one shared provider/model picker.- [ ] [story-builder-refine-returns-provider] **`refineStep('readerMap')` drops `providerId`/`model` from the conductor's return.** Every other refine branch surfaces them so the route/UI can show which model ran; the readerMap branch destructures `runId` only. Two-line fix (local-review SC-6, 2026-05-27).- [ ] [story-builder-refine-fallback-changes] **`refineReaderMap` returns `changes`/`rationale` describing a refine attempt that was discarded in favor of the existing map.** When the LLM payload is empty, the function falls back to `arc.readerMap` but still surfaces the change list the LLM described. Fix: when falling back, clear `changes` and `rationale`. (local-review SC-7, 2026-05-27).diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex e1ceca3796..1c6b1c8cef 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -30,6 +30,7 @@ grep -i "what you want to do" client/src/lib/README.md| `seasonStructure.js` | Mirror of `server/lib/seasonStructure.js`. || `sheetPointers.js` | Mirror of the character-sheet pointer helpers from `server/lib/storyBible.js`. `LEGACY_SHEET_VARIANT_ID` + `readSheetPointer` / `listSheetPointers` / `applySheetPointer` for traversing both the legacy `referenceSheetImageRef` field and the `referenceSheets` map. || `universeStylePreset.js` | Build the client-side style preset that `composeStyledPrompt` layers on top. |+| `beatColors.js` | `BEAT_KIND_COLORS` + `getBeatKindColor(kind)` — per-kind display colors for reader-map emotional beats (kinds defined server-side in `storyArc.js`). Keeps every beat visualization consistent. || `bibleLimits.js` | Mirror of `server/lib/storyBible.js` `BIBLE_LIMITS`. || `catalogTypes.js` | Client mirror of `server/lib/catalogTypes.js` — catalog ingredient type registry (label, badge color, primary-content key/label, snippet fallback chain, per-type editor field list) for the Catalog list/picker/editor. || `editorialRoadmap.js` | `projectAnalyzedPoints` (aggregate roadmap → analyzed chart points with arc-position `frac`) + `dominant` (most-frequent string). Shared by EditorialRoadmapPanel and the Reader Map page. |diff --git a/client/src/lib/beatColors.js b/client/src/lib/beatColors.jsnew file mode 100644index 0000000000..b641bf0a30--- /dev/null+++ b/client/src/lib/beatColors.js@@ -0,0 +1,18 @@+// Canonical per-kind colors for reader-map emotional beats. The beat kinds+// themselves are defined server-side (READER_MAP_BEAT_KINDS in+// server/lib/storyArc.js); this maps each to a display color so every+// beat-visualization (the Story Builder beat timeline today, any future+// reader-map widget) stays consistent. Values match the Tailwind design tokens+// where one applies. `getBeatKindColor` falls back to neutral gray for an+// unknown kind so a future server-side kind never renders invisibly.+export const BEAT_KIND_COLORS = Object.freeze({+ 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+});++export function getBeatKindColor(kind) {+ return BEAT_KIND_COLORS[kind] || '#9ca3af';+}diff --git a/client/src/lib/index.js b/client/src/lib/index.jsindex bbfbe82e28..281f020679 100644--- a/client/src/lib/index.js+++ b/client/src/lib/index.js@@ -12,6 +12,7 @@ export * from './sheetPointers.js';export * from './universeStylePreset.js';// === Pipeline / image-gen defaults ===+export * from './beatColors.js';export * from './bibleLimits.js';export * from './catalogTypes.js';export * from './editorialRoadmap.js';diff --git a/client/src/pages/StoryBuilder.jsx b/client/src/pages/StoryBuilder.jsxindex df4ba4bcae..47a4f11baf 100644--- a/client/src/pages/StoryBuilder.jsx+++ b/client/src/pages/StoryBuilder.jsx@@ -24,6 +24,7 @@ import {getProviders, getSettings, generateImage, updateUniverse,} from '../services/api';import ArcCanvas from '../components/pipeline/ArcCanvas';+import { BEAT_KIND_COLORS, getBeatKindColor } from '../lib/beatColors';// Mirror Importer.jsx's commit picker — only these arc fields are sent on commit.const ARC_FIELDS_TO_COMMIT = ['logline', 'summary', 'protagonistArc', 'themes', 'shape'];@@ -360,15 +361,6 @@ 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@@ -411,7 +403,7 @@ function ReaderMapBeatTimeline({ readerMap }) {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';+ const color = getBeatKindColor(b.kind);return (<g key={b.id || i}><rect x={x - 1.5} y={H - PAD - barH} width="3" height={barH} fill={color} rx="1" />@@ -421,7 +413,7 @@ function ReaderMapBeatTimeline({ readerMap }) {})}</svg><div className="flex flex-wrap gap-x-3 gap-y-0.5 mt-1">- {Object.entries(BEAT_KIND_COLOR).map(([kind, color]) => (+ {Object.entries(BEAT_KIND_COLORS).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>@@ -976,7 +968,12 @@ function StoryBuilderDetail({ storyId, stepParam }) {// 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]);+ // Capture the FIRST server snapshot only (guard on empty ref) — like+ // PipelineSeries.jsx. Updating on every `series` change would clobber the+ // last-saved baseline on an unrelated refetch and defeat flushPending's+ // dirty-check (it would always see series === lastSaved). After load, the ref+ // only advances via updateSeriesFromServer (a server-confirmed save).+ useEffect(() => { if (series && !lastSavedRef.current) lastSavedRef.current = series; }, [series]);const updateSeriesFromServer = useCallback((next) => {setSeries(next);