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([extract-mergeexpandintodraft-draft-result-from]): remove from PLAN.md and log to changelog
[._.]/ Adam Eivy128646d37f14
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 27836e07f0..03466bf689 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -4,6 +4,8 @@- **[apicore-request-arraybuffer-response-type] `apiCore.request()` grows an `arraybuffer` `responseType` escape hatch; two TTS audition helpers stop bypassing the shared client.** `client/src/services/apiCore.js#request` now accepts `{ responseType: 'arraybuffer' }` — when set, the helper returns `response.arrayBuffer()` instead of parsing JSON, while still funneling the error path (server-shaped 4xx/5xx, network-unreachable toast, `err.code` / `err.status` / `err.context` forwarding) through the same code. `apiVoice.js#testTts` and `apiPipeline.js#previewPipelineTtsVoice` dropped their raw `fetch` paths and now call `request()` with `responseType: 'arraybuffer'` + `silent: true` (all three callers — `VoiceTab.handleTest`, `VoiceTab.handlePreviewVoice`, `VoicePicker.handleAudition` — already own their own catch-block toasts, so silent avoids double-toasting per the CLAUDE.md convention). Drops ~25 LOC of duplicated `if (!res.ok) parse + throw` shaping. Also pruned a stale PLAN.md entry ([extract-useswipenav-hook-lib-clipboard-js]) — both halves of that item already shipped (clipboard helpers in `client/src/lib/clipboard.js`, swipe in `client/src/hooks/useSwipeNav.js`; `MediaLightbox.jsx:122` has been calling `useSwipeNav` since PR #261). 163/163 client tests pass; lint clean.+- **[extract-mergeexpandintodraft-draft-result-from] `mergeExpandIntoDraft` extracted from `UniverseBuilder.jsx#handleExpand`.** The merge block — lock-honoring scalar pick, locked-variation/sheet preservation, category `kind` precedence, canon dedupe by name/slugline/alias, addedCanonCount + pendingAdditions partitioning — moved to a pure `client/src/lib/universeBuilderExpand.js` so the I/O shell of `handleExpand` (validation, `expandUniverse()` call, `setDraft`, auto-save, toast) is no longer tangled with merge semantics. `handleExpand` shrinks from ~260 lines to ~120; the new module exports `mergeExpandIntoDraft`, `mergeVariations`, `mergeCanonByName`, and `extractPreservedFromDraft` (the locked-items extractor used by both the API-call site and the merge so they can't drift). 27 new unit tests pin the lock semantics (absent vs intentional `""` clear), category-kind precedence ("other" upgradable; user-curated kinds preserved), composite-sheet dedupe, place-slugline normalization, within-batch alias dedupe, and `pendingAdditions` partitioning by trunk. Existing 10-test `UniverseBuilder.test.jsx` still passes; full client suite at 190/190.+- **[datasync-bundle] `dataSync.js` write-pattern + checksum-cache cleanup (2 items).** (1) [datasync-migrate-categories-to-atomicwrite] Replace seven inlined `ensureDir + writeFile(JSON.stringify(...))` triples across the goals/character/digitalTwin/meatspace categories with single `atomicWrite(path, data)` calls — temp+rename atomicity protects readers from seeing a partial write, which matters for the larger pipeline/universe JSON files that other services write concurrently. Pre-loop `ensureDir` calls dropped because each `atomicWrite` ensures its own dirname. (2) [datasync-checksum-only-fast-path] Add a per-category mtime-keyed cache in front of `getChecksum()`. The orchestrator hits this every cycle and previously materialized the full snapshot just to discard `data`; now a `stat`-only path returns the cached checksum when no underlying file changed since the last computation, falling through to `getSnapshot()` on a cache miss. Same checksum value as before — pure optimization, no protocol break. Three new tests cover cache consistency across consecutive calls, invalidation after `applyRemote`, and invalidation on out-of-band file mutations (16/16 dataSync tests pass; 5973/5973 full server suite).- **[med-ai-dispatch-server-services-aidetect-js-242] `aiDetect.js` migrated to `runPromptThroughProvider` — TUI providers now work on Settings → Detect App.** `server/services/aiDetect.js` had a legacy `if (provider.type === 'cli') … else if ('api') … else 'Unknown provider type'` dispatch that rejected TUI providers outright and duplicated spawn/fetch logic the central handler already covers. The two inline functions (`executeCliDetection`, `executeApiDetection`) and the local `spawn`/`fetch` machinery are gone; detection now flows through `runPromptThroughProvider` from `server/lib/promptRunner.js` with `source: 'ai-app-detect'`, `cwd: dirPath` (so a spawned CLI/TUI runs against the analyzed repo, not PortOS's own cwd), and a 60s default timeout. `parseAiResponse` also moved to the shared `extractJson` helper from `server/lib/jsonExtract.js`, which strips CLI banner text and repairs trailing-comma JSON — relevant for TUI providers that emit banner output around the JSON payload. New `server/services/aiDetect.test.js` locks in the dispatch behavior (regression test ensures TUI no longer fails with "Unknown provider type") plus directory + provider-disabled error paths and the banner-stripping JSON case.diff --git a/PLAN.md b/PLAN.mdindex 80fed4ac74..2d692995ee 100644--- a/PLAN.md+++ b/PLAN.md@@ -12,7 +12,6 @@ _Nothing currently parked — pick the next item from the Backlog._### Code quality / dedup (from `/simplify` passes)-- [ ] [extract-mergeexpandintodraft-draft-result-from] **Extract `mergeExpandIntoDraft(draft, result)` from `UniverseBuilder.jsx#handleExpand`.** The function is ~150 lines mixing pure-merge logic (categories, sheets, canon, locks) with I/O shell (API call, setDraft, auto-save, toast). Pull the merge into a top-level pure helper so the I/O surface shrinks and the merge is unit-testable. Deferred from Phase B `/simplify` to keep that PR tightly scoped.- [ ] [route-medialightbox-settings-drawer-through] **Route `MediaLightbox` settings drawer through `components/Drawer.jsx`.** Reconcile `Drawer`'s flat Esc handler with the lightbox's layered Escape cascade.- [ ] [extract-usependinglistrows-hook] **Extract `usePendingListRows({ persisted, requiredColumn, idPrefix, onChange }) → { merged, isPending, addRow, updateRow, removeRow }`.** Surfaced by /simplify during `[wardroberow-migrate-to-userowdraft]`. `WardrobeSection` in `client/src/components/pipeline/CanonCard.jsx:155-211` and `CharacterDetailEditor` list-section block in `client/src/components/universe/CharacterDetailEditor.jsx:202-278` now share substantial structure: pending rows held client-side until a required column fills, then promoted to `onChange`/`patchList`, with an index space that concatenates `[...persisted, ...pending]` and an `isPending(idx)` partition. Estimated ~70 LOC savings across both call sites. Two load-bearing details to preserve in the extraction: (1) `WardrobeSection` mints `wd-<uuid>` ids that round-trip verbatim; `CharacterDetailEditor` mints `pending-<key>-<uuid>` that get stripped at promotion — pass an `idPrefix` and a `stripIdOnPromote` flag (or unify both onto server-shaped ids and drop the strip); (2) hook is per-list (one instance per `LIST_SECTION` in `CharacterDetailEditor`, one in `WardrobeSection`), NOT per-component. Deferred to keep this PR focused on the `useRowDraft` migration; revisit when a third caller appears or the parallel divergence drifts.- [ ] [client-tests-for-deep-routing-drag-smoke-tests-for] **Client tests for deep routing + drag.** Smoke tests for `goToWorld(id)` URL transitions and chip-reorder ordering (mock `useSortable`).