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
Merge remote-tracking branch 'origin/main' into claim/issue-2529
Adam Eivyc3284643fec4
diff --cc .changelog/NEXT.mdindex fd3b6d4f45,9dcb130f56..8dcaac28e0--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@@ -19,7 -19,7 +19,8 @@@## Changed+- **[issue-2529] Split the `universeBuilder.js` god-module into focused sibling modules behind a thin barrel.** The ~2000-line `server/services/universeBuilder.js` (50+ exports mixing sanitizers, CRUD, peer-sync, and prompt compilation) was split along its natural seams into `universeBuilder/sanitize.js` (constants + record-shape sanitizers), `universeBuilder/storeFacade.js` (shared synchronous store getter), `universeBuilder/crud.js` (read/list/get, create/update/delete, runs, render-history mutations), `universeBuilder/sync.js` (peer-sync merge + tombstone GC), and `universeBuilder/compile.js` (prompt compilation). The original path is now a 20-line barrel that re-exports the full public surface, so all 94 existing importers keep working unchanged. Pure structural refactor — no behavior change; every existing suite (including the DB-backed tests) stays green. The `catalogDB.js` split is tracked as remaining work under the same issue.+ - **[issue-2524] Route per-key write tails through the shared `createKeyCachedQueue` helper (DRY).** Five modules each hand-rolled the same `Map` + `prev.then(fn, fn)` + `.catch`-silence + self-pruning tail to serialize read-modify-write cycles per key: `pipeline/issues.js` (per-series), `loraTraining/db.js` (per-run), `instances.js` (per-peer reciprocal sync), `worktreeManager.js` (per-repo worktree create), and `collectionStore.js` (per-record). Each now delegates to `server/lib/createKeyCachedQueue.js`, and `fileWriteQueue.js`'s id-keyed `createRecordWriteQueue` (already used by the pipeline series/issues and story-builder store facades) is now a thin validator wrapper over the same helper, so all per-key write serialization funnels through one implementation. `collectionStore.js`'s single-tail type-index queue likewise reuses `createFileWriteQueue`. Each site keeps its own key derivation (series-id normalization, macOS realpath resolution) and the fixed reciprocal-sync work body; silence/eviction semantics and observable write ordering are unchanged, and existing write-order tests still pass.- **[issue-2523] Extract a shared `createPgFileFacade` backbone for the six PG/file store dispatchers.** The pipeline series/issues, story-builder, universe-builder, catalog-user-types, and writers-room stores each re-implemented the same three pieces: the `isFileBackend()` escape-hatch predicate, the promise-memoized lazy backend selection (so concurrent first calls don't run the migration twice), and the PG bring-up sequence (health-check → `ensureSchema` → one-time file→DB migration → import the leaf-I/O `db.js`). Those now live once in `server/lib/pgFileFacade.js` as `isFileBackend()`, `resolvePgBackend({ requirement, migrate?, loadDb, makePg })`, and `createPgFileFacade({ makeFile, makePg })`; the two inline write-queue copies (`createFileWriteQueue`'s id-keyed sibling `createRecordWriteQueue`) were folded into `server/lib/fileWriteQueue.js`. Each store keeps its own genuinely-different `makeFile`/`makePg` factories and public surface; behavior is preserved on both the PostgreSQL and file/test backends. New unit tests cover the shared helpers.- **[issue-2526] Reuse shared helpers instead of local reimplementations (DRY).** Swapped duplicated one-off implementations for their existing `server/lib` counterparts: `sleep` (`youtubeSync.js`, `pipeline/seriesAutopilot.js`) and `pathExists` (`localLlm.js`) now import from `fileUtils.js`; `database.js`'s inline color-only `stripAnsi` uses the shared `ansiStrip.js` (full ANSI/control stripper); `systemHealth.js`'s byte formatter and `huggingFaceCatalog.js`'s (via a thin wrapper that preserves its `null`-on-unknown-size fallback contract) now delegate to `fileUtils.formatBytes`; and the two hand-rolled SSE header blocks now use the canonical `SSE_HEADERS` — `ask.js` keeps its extra `no-transform` directive on top of the shared set, and `mediaJobQueue`'s terminal-event path gains the previously-missing `X-Accel-Buffering: no` so it matches the live-stream path.- **[issue-2521] Validate the remaining ad-hoc route bodies with Zod `validateRequest`.** The ports (`/check`, `/allocate`), database (`switch`/`start`/`stop`/`destroy`/`export`), brain digest/review run, telegram (`method`/`config`/`test`/`forward-types`), and AI-toolkit provider (`POST`/`PUT`/`PUT active`) routes parsed `req.body` with hand-rolled `Array.isArray`/`includes` checks. Each now has a named Zod schema (PortOS schemas in `lib/validation.js`, brain schema in `brainValidation.js`, provider schemas in `aiToolkit/validation.js`) wired through `validateRequest`, so invalid bodies return a consistent `400 VALIDATION_ERROR` with per-field `context.details` instead of ad-hoc messages. Port numbers are range-checked (and `count` coercion no longer silently accepts booleans/arrays), backend/target values are enum-checked, and provider create/update reuse the canonical `providerSchema` (`.partial()` on update). As part of wiring `PUT /api/providers/active`, the toolkit providers map is now null-prototyped on load so a crafted id (`__proto__`, `constructor`, `toString`) can no longer resolve an inherited `Object.prototype` member as an existing provider and be persisted as the active one.