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
docs([wardroberow-migrate-to-userowdraft]): archive to DONE.md
[._.]/ Adam Eivyb6cc6688b046
diff --git a/DONE.md b/DONE.mdindex 4dacca3598..a179714245 100644--- a/DONE.md+++ b/DONE.md@@ -10,6 +10,7 @@ For active roadmap see [PLAN.md](./PLAN.md). For project goals see [GOALS.md](./### 2026-05-19+- **[wardroberow-migrate-to-userowdraft] Migrate `WardrobeRow` to consume `useRowDraft`.** `client/src/components/pipeline/CanonCard.jsx` no longer runs two `useFieldDraft` calls per outfit row — a single `useRowDraft(wardrobe, onCommit)` call covers both columns, so wardrobe entries pick up the same sibling-draft ride-along race protection that landed for `ListRow` in `[characterdetaileditor-listrow-row-draft-hook]`. `WardrobeSection.commit` reshapes from `(idx, field, value)` to `(idx, nextRow)`; the pending-row promotion trigger moves from "per-field `name` commit with non-empty value" to "any commit where `nextRow.name.trim()` is non-empty" — same end state, and the rewrite fires earlier for the ride-along case (description blur with a pending name draft now promotes the row instead of stranding it in `pendingNew`). The deferred concern from PLAN ("promotion semantics need their own design pass") resolved by following the existing `CharacterDetailEditor.updateRow` pattern, which already runs the same required-column check against `nextRow`. Removed the now-unused `useFieldDraft` import from `CanonCard.jsx`. +1 ride-along regression test in `CanonCard.test.jsx` (description blurs first with a pending name draft → row promotes with both fields intact). All 121 client tests pass.- **[code-quality-dedup-batch] Code quality / dedup batch — 8 items shipped together.** (1) `[extract-optionalbooleanmap-zod-helper]` — new `optionalBooleanMap(keys)` helper in `server/lib/validation.js` collapsing the `Object.fromEntries(KEYS.map((k) => [k, z.boolean().optional()]))` pattern at 3 sites (`server/routes/universeBuilder.js`, `server/routes/pipeline.js` ×2). (2) `[extract-a-tryreadfile-helper]` — new `tryReadFile(path, encoding='utf8')` in `server/lib/fileUtils.js` replacing the `readFile(...).catch(() => null)` pattern at ~60 sites across `server/`; `readFile` import removed from 22 files where all uses migrated. Auto-injected `tryReadFile` mock into ~80 test files' `vi.mock('../lib/fileUtils.js')` bodies to keep partial mocks working. (3) `[aitoolkit-loadproviders-corrupt-fallback]` — `loadProviders` in `server/lib/aiToolkit/providers.js` now wraps `JSON.parse` in a `parseOrRescue(content, source)` helper that renames the corrupt user file to `<path>.corrupt.<timestamp>` + logs + returns `{ activeProvider: null, providers: {} }` so a garbled providers.json can't crash server boot. The shipped-sample path parses BEFORE persisting so a malformed sample can't seed user-side providers.json with garbage (per codex review). (4) `[more-resolveproviderandmodel-migration-candidates]` — migrated 3 sites onto the existing `resolveProviderAndModel` helper (`server/services/agentContentGenerator.js#runAIGeneration`, `server/services/agentPersonalityGenerator.js`, `server/services/loops.js#runIteration`); loops.js wraps with `.catch(() => ({ provider: null }))` to preserve the original "swallow all" semantics across both `getProviderById` and `getActiveProvider` failures. (5) `[extract-assertprovider-helper]` — new `assertProvider(provider, { message, code, status = 503 })` helper in `server/lib/promptRunner.js`; throws `ServerError` with code+status when `code` is provided, plain `Error` otherwise (preserves each caller's original error shape). Migrated 7 `if (!provider) throw …` sites (`universeBuilderAutoSort.js`, `universeBuilderRefine.js`, `universeBuilderExpand.js` ×2, `universeBuilderPromote.js`, `agentContentGenerator.js`, `agentPersonalityGenerator.js`). Auto-injected `assertProvider` mock into 6 test files mocking `promptRunner.js`. (6) `[extract-uselocktoggle-hook]` — new `useLockToggle({ patchFn, onSuccess, lockedMessage, unlockedMessage, errorMessage })` returning `{ busy, toggle }` in `client/src/hooks/useLockToggle.js` collapsing the optimistic-PATCH lock toggle pattern at 4 sites: `toggleArcLock`/`FieldLockToggle#toggle`/`toggleSeasonLock` in `client/src/components/pipeline/ArcCanvas.jsx`, `handleStageLockToggle` in `client/src/pages/PipelineIssue.jsx` (removes the now-dead `stageLockSaving` useState). (7) `[skip-the-text-accumulator-in-promptrunner]` — `runPromptThroughProvider`'s `onData` now skips the `APPEND_CHUNK` text concat for TUI providers (which discard the accumulated `text` anyway in favor of `result.text` from `executeTuiRun`); TUI screen-redraw streams can hit hundreds of KB per run. (8) `[aitoolkit-createprovider-field-parity-test]` — new exhaustive test in `server/lib/aiToolkit/providers.test.js` that round-trips all 20 fields defined in `createProvider`'s explicit field list through `create → save → reload`, guarding against the regression where a Zod-schema field is added without being mirrored into the explicit `createProvider` field list. All 5690 server tests + 103 client tests pass; client build clean.- **[characterdetaileditor-listrow-row-draft-hook] Extract `ListRow`'s multi-column row-draft state into a shared `useRowDraft` hook.** `client/src/components/universe/CharacterDetailEditor.jsx`'s `ListRow` carried 19 lines of inline `useState({})` draft buffer + `draftFor`/`setDraft`/`commit` triple, with the load-bearing sibling-draft "ride-along" merge (`{...row, ...drafts, [col]: v}`) that keeps a fast A-blur → B-blur sequence from losing column A when the parent hasn't re-rendered yet. Lifted into new `client/src/hooks/useRowDraft.js` — the row-level analogue of `useFieldDraft` (single-field draft+blur). Hook signature is `useRowDraft(row, onChange)` returning `{ draftFor, setDraft, commit }`; preserves the ride-along merge verbatim and coerces `null`/`undefined` persisted columns to `''` so inputs stay controlled. `ListRow` collapses to a single hook call. 9 new vitest cases cover persisted/empty fallback, draft buffering without firing onChange, commit no-op when value equals persisted, commit no-op when no draft set, null-as-empty equivalence, the ride-along race-protection invariant (committing column B with a pending column-A draft ships both in one onChange), and that commit clears only the committed column from the drafts map. All 112 client tests pass.- **Better-audit residue refactor bundle.** Shipped four PLAN.md items from the Better-audit residue section as one PR — three landed as scoped fixes, one was rescoped after the underlying premise eroded. (1) `[medium-client-4-components-still-redefine]` — added `formatTimecode` (M:SS.ss for video timecodes), `formatDurationSec` (M:SS for seconds, `'—'` fallback), and `formatDateShort` (short-month date, `'—'` fallback) to `client/src/utils/formatters.js`; migrated `VideoTimelineEditor.jsx`, `VideoTimeline.jsx`, and `ImportTab.jsx` off their local re-definitions. `MortalLoomTab.jsx` (also named in PLAN) already imported `formatBytes` from the shared module, so no change there. (2) `[medium-perf-feeds-js-getitems-303-319-full-sort]` — `server/services/feeds.js` now maintains the newest-first sort invariant on writes (`addFeed`, `refreshFeed`, `applyParsedFeed` end-of-batch in `refreshAllFeeds`); `getItems` drops the per-call sort. New `ensureItemsSorted()` runs once on first read after server boot to normalize legacy disk data, with an `isSortedNewestFirst()` guard so an already-sorted file isn't re-saved on every restart. (3) `[medium-code-magic-numbers-in-cos-js-166-357]` — replaced the brittle `err.message.startsWith('unknown piper voice:')` check in `routes/voice.js` and the `err.message.includes('not initialized')` check in `services/visionTest.js` with typed error codes. `services/voice/tts.js` now throws `new ServerError(\`unknown piper voice: …\`, { status: 400, code: 'UNKNOWN_VOICE' })`; `services/providers.js` consolidated its nine `if (!aiToolkitInstance) throw new Error(…)` duplicates into a single `requireToolkit()` helper that throws `new ServerError('AI Toolkit not initialized', { status: 503, code: 'AI_TOOLKIT_NOT_INITIALIZED' })`. Both new ServerErrors bubble through `asyncHandler` automatically — the voice.js try/catch around `synthesize` dropped entirely (~10 LOC + 1 narrative comment). visionTest.js's error path now surfaces a more accurate "AI provider service is still initializing" message when the toolkit isn't warmed (previously it masqueraded as "provider not found", sending the user looking for the wrong root cause). Named time constants extracted in `cos.js` (`CD_RECOVERY_BOOT_TIMEOUT_MS = 60_000`, `POST_STARTUP_QUEUE_DELAY_MS = 30_000`, `RECENT_COMPLETION_GRACE_MS = 60_000`) and `lmStudioManager.js` (`DEFAULT_REQUEST_TIMEOUT_MS = 30_000`, `AVAILABILITY_PROBE_TIMEOUT_MS = 5_000`). (4) `[low-client-extract-shared-usepopoverposition-hook]` — **skipped, premise eroded.** The original PLAN flagged 4 components (`AddToCollectionMenu`, `BulkTargetPicker`, `ThemeSwitcher`, `VisualStylePicker`) but `VisualStylePicker` no longer exists in the codebase and `AddToCollectionMenu`/`BulkTargetPicker` no longer use the portal-positioning pattern. Today only `ThemeSwitcher` and `CollectionPickerShell` match the shape; the abstraction isn't worth the indirection at 2 callers. PLAN.md entry rewritten to reflect current state — extract when a 3rd caller lands. Updated `voice.test.js` to mock `ServerError` directly (drops the legacy back-compat test, asserts `code: 'UNKNOWN_VOICE'` on the body); loosened `visionTest.integration.test.js`'s "non-existent provider" assertion to accept either the "not found" branch (toolkit warmed) or "still initializing" branch (toolkit not yet wired in the test context). One `/simplify` follow-up deferred to PLAN.md as `[extract-requiretoolkit-pattern-to-runner-js]` — `runner.js` has 13 more sites of the same inlined `if (!aiToolkitInstance)` check that should adopt the new `requireToolkit()` helper. All 5703 server tests + 103 client tests pass.diff --git a/PLAN.md b/PLAN.mdindex f57c939190..01adc17428 100644--- a/PLAN.md+++ b/PLAN.md@@ -12,8 +12,6 @@ _Nothing currently parked — pick the next item from the Backlog._### Universe-as-Canon — Phase 2 + extensions-- [ ] [wardroberow-migrate-to-userowdraft] **Migrate `WardrobeRow` to consume `useRowDraft`.** `client/src/components/pipeline/CanonCard.jsx:104-149` currently runs two separate `useFieldDraft` calls (one per column: `name`, `description`). Switching to a single `useRowDraft` call would shrink the row and pick up the same sibling-draft ride-along race protection that landed for `ListRow` in `[characterdetaileditor-listrow-row-draft-hook]`. Non-trivial because `WardrobeSection.commit` (lines 171-193) does pending-row promotion on per-field `name` commits, not on whole-row commits — switching to row-shaped `onCommit(nextRow)` changes the promotion trigger. Surfaced by /simplify during the `useRowDraft` extraction PR; deferred because the promotion semantics need their own design pass.-- [x] ~~**Drop the default `characters` category.**~~ Shipped via the Universe Builder redesign Phase A migration; default `characters` bucket retired, variations backfilled into `universe.characters[]`.- [x] ~~**Universe expand LLM contract enrichment.**~~ Shipped via the Universe Builder redesign Phase B — expand contract now returns rich canon arrays alongside categories.- [x] ~~**arcPlanner prompt context — include canon characters/places/objects.**~~ Shipped via the Universe Builder redesign Phase B (`renderCanonForPrompt(world)` + `worldCanonText` + migration 019 for `pipeline-arc-overview`, `pipeline-arc-verify`, `pipeline-arc-resolve`, `pipeline-volume-verify`). Follow-up still open: sweep `grep -rn "world\.categories" server/services/pipeline server/services/universeBuilder*.js` for other prompt builders that read categories but not canon.