Skip to content

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

fix: keep the manual-add draft when the Add toggle collapses the form

[._.]/ Adam Eivy49be0df68b08
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 10e445eaad..1eeb0c1dfa 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -22,7 +22,7 @@
- **The Sprite Manager page no longer carries its three header panels inline.** `ImportPanel`, `NewSpritePanel`, and `SpriteSearch` were independent top-level components sharing `Sprites.jsx` with the detail/render orchestration; each is now its own file in `client/src/components/sprites/`, leaving the page at 606 lines of routing, render tracking, and workflow wiring. Pure move — same props, handlers, and markup. (#3390)
- **`/api/universe-builder` is a directory of sub-routers, not one 987-line file.** The 36 endpoints split along the service seams they already delegated to — `expand.js`, `vision.js`, `styleReferences.js`, `referenceSheets.js`, `merge.js`, `crud.js`, `render.js`, `canon.js` — behind a thin `routes/universeBuilder/index.js`, with the zod fragments and image resolvers more than one router composes moved to `shared.js`. Mount order is the load-bearing part and is documented at the mount: every sub-router owning a single-segment static path (`/expand`, `/duplicates`, `/merge*`, …) mounts ahead of `crud.js`, whose `GET /:id` would otherwise swallow it. Verified by resolving 520 method+URL combinations against the old and new routers and confirming every one lands on the same handler. (#3392)
- **Typing in the Writers Room no longer re-renders the storyboard sidebar.** `WorkEditor`'s body textarea shared a render with `<StoryboardPanel>` — a heavy tree of bibles, boards, scene cards, and image config with zero dependency on the prose — so every keystroke re-rendered the whole sidebar. The panel is now memoized and every prop it receives is referentially stable across keystrokes (the run/style handlers are `useCallback`s and `onJumpToScene` reads the body through a ref instead of a dep), leaving one re-render on the clean → dirty flip and none after. Three hooks came out with it — `useLiveSuggest`, `useSidebarResize`, `useTokenPopover` — plus `WorkEditorVersions` / `WorkEditorVoicePanel` as their own files. Behavior is unchanged. (#3387)
-- **A canon trunk's wiring travels by context, not a 36-prop bag.** `KindSection` inside `UniverseCanonSection.jsx` took every handler, spinner id, and job map as an individually threaded prop, so adding one capability meant editing the call site, the signature, and its defaults. The bag is now published once per kind through `KindSectionContext` and read where it's used, and the inline add-entry mini-form moved to `CanonAddEntryForm.jsx` (its name/description draft resets on unmount instead of by hand). `KindSection` takes zero props; behavior, markup, and classes are unchanged. (#3388)
+- **A canon trunk's wiring travels by context, not a 36-prop bag.** `KindSection` inside `UniverseCanonSection.jsx` took every handler, spinner id, and job map as an individually threaded prop, so adding one capability meant editing the call site, the signature, and its defaults. The bag is now published once per kind through `KindSectionContext` and read where it's used, and the inline add-entry mini-form moved to `CanonAddEntryForm.jsx` as a controlled leaf — the typed draft stays with the section, because the toolbar "Add" button is a toggle and collapsing the form has to bring the draft back on reopen. `KindSection` takes zero props; behavior, markup, and classes are unchanged. (#3388)
- `agentLifecycle.js` imported `getAgent` aliased as `getAgentRecord`, shadowing the real transcript-free reader that was split out in #3368 for exactly this purpose. Both call sites read only `.status`/`.metadata`, but the alias made them hydrate the record: reading and line-splitting a completed run's whole `output.txt` (megabytes on a long TUI run) and potentially rewriting `metadata.json` via `repairCodexTaskSummary`. Now imports the real `getAgentRecord`, read once and shared.
## Better audit 2026-08-03 (UX, City scene, game/music/writing focus) — PRs #3401–#3404
diff --git a/client/src/components/universe/CanonAddEntryForm.jsx b/client/src/components/universe/CanonAddEntryForm.jsx
index 97985311d4..c52b8bbfcf 100644
--- a/client/src/components/universe/CanonAddEntryForm.jsx
+++ b/client/src/components/universe/CanonAddEntryForm.jsx
@@ -5,17 +5,17 @@
* owns persistence (optimistic append → `updateUniverse` → revert on failure).
* Mirrors CategoryEditor's `adding`/`newLabel` bucket-add shape.
*
- * Draft state lives here and the component is unmounted by its owner whenever
- * the form is closed, so cancel/save both reset the fields for free — the same
- * net behavior as the previous inline version, which cleared them by hand.
+ * The `{ name, description }` draft is CONTROLLED by the owner rather than held
+ * here, because the owner's toolbar "Add" button is a toggle: collapsing the
+ * form and reopening it must bring the typed draft back. Only Cancel and a
+ * successful Save clear it (both route through `onClose`).
*/
-import { useState } from 'react';
import { Loader2 } from 'lucide-react';
import { BIBLE_LIMITS } from '../../lib/bibleLimits';
-export default function CanonAddEntryForm({ kind, creating = false, onAddEntry = null, onClose }) {
- const [newName, setNewName] = useState('');
- const [newDesc, setNewDesc] = useState('');
+export default function CanonAddEntryForm({ kind, creating = false, draft, onDraftChange, onAddEntry = null, onClose }) {
+ const newName = draft?.name || '';
+ const newDesc = draft?.description || '';
const submitAdd = async () => {
if (!newName.trim() || !onAddEntry || creating) return;
@@ -29,7 +29,7 @@ export default function CanonAddEntryForm({ kind, creating = false, onAddEntry =
<div className="bg-port-bg border border-port-border rounded p-2 mb-2 flex flex-col gap-2">
<input
value={newName}
- onChange={(e) => setNewName(e.target.value)}
+ onChange={(e) => onDraftChange({ name: e.target.value, description: newDesc })}
onKeyDown={(e) => { if (e.key === 'Enter') submitAdd(); }}
placeholder={`${kind.singular[0].toUpperCase()}${kind.singular.slice(1)} name`}
className="bg-port-card border border-port-border rounded px-2 py-1 text-white text-sm"
@@ -39,7 +39,7 @@ export default function CanonAddEntryForm({ kind, creating = false, onAddEntry =
/>
<textarea
value={newDesc}
- onChange={(e) => setNewDesc(e.target.value)}
+ onChange={(e) => onDraftChange({ name: newName, description: e.target.value })}
placeholder={`Describe this ${kind.singular} (optional — image-gen-ready prose)`}
className="bg-port-card border border-port-border rounded px-2 py-1 text-white text-sm"
rows={2}
diff --git a/client/src/components/universe/UniverseCanonSection.add.test.jsx b/client/src/components/universe/UniverseCanonSection.add.test.jsx
index 3abed5c4eb..f7780e00e5 100644
--- a/client/src/components/universe/UniverseCanonSection.add.test.jsx
+++ b/client/src/components/universe/UniverseCanonSection.add.test.jsx
@@ -10,7 +10,7 @@
* places/objects).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
import { MemoryRouter } from 'react-router';
vi.mock('../../services/apiCatalog', () => ({
@@ -141,6 +141,32 @@ describe('UniverseCanonSection — manual Add', () => {
expect(updateUniverse).not.toHaveBeenCalled();
});
+ it('keeps the typed draft when the Add toggle collapses the form, and clears it on Cancel', async () => {
+ // The toolbar "Add" button is a toggle, so collapsing mid-typing must not
+ // throw the draft away — this is why the draft is owned by the section and
+ // CanonAddEntryForm is a controlled leaf. Cancel, by contrast, discards.
+ renderSection({ onUniverseChange: vi.fn() });
+ // Settle the mount-time usage fetch before driving the form.
+ await act(async () => {});
+
+ const toggle = screen.getByRole('button', { name: /add character/i });
+ fireEvent.click(toggle);
+ fireEvent.change(screen.getByLabelText(/new character name/i), { target: { value: 'Half Typed' } });
+ fireEvent.change(screen.getByLabelText(/new character description/i), { target: { value: 'wip' } });
+
+ fireEvent.click(toggle); // collapse
+ expect(screen.queryByLabelText(/new character name/i)).toBeNull();
+
+ fireEvent.click(toggle); // reopen — draft survives
+ expect(screen.getByLabelText(/new character name/i).value).toBe('Half Typed');
+ expect(screen.getByLabelText(/new character description/i).value).toBe('wip');
+
+ fireEvent.click(screen.getByRole('button', { name: /^cancel$/i }));
+ fireEvent.click(toggle);
+ expect(screen.getByLabelText(/new character name/i).value).toBe('');
+ expect(screen.getByLabelText(/new character description/i).value).toBe('');
+ });
+
it('reverts the optimistic append when the save fails', async () => {
const onUniverseChange = vi.fn();
updateUniverse.mockRejectedValue(new Error('boom'));
diff --git a/client/src/components/universe/UniverseCanonSection.jsx b/client/src/components/universe/UniverseCanonSection.jsx
index b5855830bf..b438ac3b0b 100644
--- a/client/src/components/universe/UniverseCanonSection.jsx
+++ b/client/src/components/universe/UniverseCanonSection.jsx
@@ -949,11 +949,15 @@ function KindSection() {
);
const Icon = kind.icon;
- // Whether the manual-add mini-form is open. The form owns its own name/desc
- // draft (CanonAddEntryForm) and unmounts when closed, so cancel/save reset
- // the fields for free; only the disclosure bit lives here because the "Add"
- // button in the controls strip toggles it.
+ // Manual-add form state — the disclosure bit plus the typed draft (mirrors
+ // CategoryEditor's `adding`/`newLabel` bucket-add form). Persistence is the
+ // parent's job via `onAddEntry`; the form (CanonAddEntryForm) is a controlled
+ // leaf. The draft lives HERE, not in the form, because the "Add" button is a
+ // toggle: collapsing the form and reopening it must bring the draft back.
+ // Only Cancel and a successful Save clear it.
const [adding, setAdding] = useState(false);
+ const [addDraft, setAddDraft] = useState({ name: '', description: '' });
+ const closeAddForm = () => { setAdding(false); setAddDraft({ name: '', description: '' }); };
// Bulk lock-state summary computed off the FULL list (not the series-filtered
// view) so the buttons reflect the universe-wide state the bulk action will
@@ -1051,8 +1055,10 @@ function KindSection() {
<CanonAddEntryForm
kind={kind}
creating={creating}
+ draft={addDraft}
+ onDraftChange={setAddDraft}
onAddEntry={onAddEntry}
- onClose={() => setAdding(false)}
+ onClose={closeAddForm}
/>
) : null;