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

Merge remote-tracking branch 'origin/main' into claim/issue-1839

[._.]/ Adam Eivycbfd5516a6b6
diff --cc .changelog/NEXT.md
index d13dd33698,729b0093fe..a8d9f939df
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@@ -41,7 -41,7 +41,8 @@@
- **[issue-1836] Moved socket-handler orchestration into services** — the `standardize:start` and `app:deploy` Socket.IO handlers (`server/services/socket.js`) implemented their multi-step flows inline in the socket layer, where they couldn't be unit-tested or reused from an HTTP route. The PM2 standardization flow (analyze → git backup → apply) is now `pm2Standardizer.runStandardizeFlow()` and the deploy flow (resolve app → check deploy script → run) is now `appDeployer.runDeployFlow()`; each takes progress callbacks and returns a terminal outcome, so the socket handler is a thin adapter. Both are covered by new unit tests. Behavior-preserving. (#1836)
+ - **Extracted a shared helper for the copy-paste stage-seed migrations** — 44 first-shipment "seed a new pipeline stage" migrations under `scripts/migrations/` (e.g. `130-editorial-character-consistency-stage.js`) were near-identical: only the stage key differed while ~65 lines of read-reference → no-clobber-copy → merge-stage-config were verbatim copies, each with its own copy-paste test. They now collapse to a 3-line `export default makeSeedMigration(stageKey)` call from a new `scripts/migrations/_seedStageHelpers.js` (companion to the existing `_lib.js`/`_testHelpers.js`; the runner skips `_`-prefixed files). The helper reproduces the migrations' on-disk effects exactly — fresh-seed, idempotent no-clobber of a customized `.md`/config, and missing-reference no-throw; `filename` defaults to `${stageKey}.md` (the universal convention, overridable for a divergent template), and no `down()` is emitted because the runner (`run-migrations.js`) only ever calls `up()` and tracks applied migrations by filename. Boot-log copy is incidental and now uniformly keyed on `stageKey`. Net −2,500 lines; all 757 `scripts/` tests pass unchanged, and the new `_seedStageHelpers.test.js` covers the helper directly. (#1838)
+- **Extracted a shared `withAbortTimeout` helper for the duplicated peer-fetch timeout boilerplate** — the `new AbortController()` + `setTimeout(abort)` + `finally{clearTimeout}` triple was hand-rolled at 12 federation/probe call sites (4 in `instances.js`, plus `peerSocketRelay`, `peerSync`, `peerCosSync`×2, `peerSyncAssets`, `peerSyncPush`, `peerMediaLibrarySync`, `sidecarSync`). It can't reuse `fetchWithTimeout` because `peerFetch` needs the Tailnet-insecure HTTPS agent. The new `server/lib/abortTimeout.js` `withAbortTimeout(timeoutMs, fn)` runs `fn(signal)` under a timed `AbortController` and always clears the timer on settle — covering both the headers-only idiom (peer-sync pulls/pushes, body separately size-capped) and the whole-operation idiom (`probePeer` shares one signal across three parallel fetches and their body reads). The `peerFetch` call stays in each module (so existing test mocks/assertions are unchanged); behavior-preserving. (#1839)
- **Replaced aiToolkit runner monkey-patching with declared extension points** — `server/index.js` previously reached into the toolkit runner's private surface, overwriting `executeCliRun`/`executeTuiRun` and re-wrapping `stopRun`/`isRunActive`/`deleteRun` to consult an ad-hoc `_portosActiveRuns` map, plus inlining a 34-line update-marker IIFE in bootstrap. The toolkit runner (`server/lib/aiToolkit/runner.js`) now exposes `setCliRunner()`/`setTuiRunner()` and an external-run registry (`registerExternalRun`/`unregisterExternalRun`/`hasExternalRun`) that its own `stopRun`/`isRunActive`/`deleteRun` consult first — so the host registers its CLI/TUI runners through a documented contract instead of mutating private props, and adding a new lifecycle method no longer requires a matching monkey-patch. `server/services/runner.js` tracks its child processes via the registry, and the update-marker read/validate/record/cleanup lifecycle moved into a unit-tested `processUpdateMarker()` in `server/services/updateChecker.js`. Behavior-preserving; the aiToolkit override contract (`server/lib/aiToolkit/CLAUDE.md`) is updated to match. (#1834)
- **Decomposed two remaining large files: `server/routes/meatspace.js` + `server/services/videoGen/local.js`** — the 1,069-line `meatspace.js` router (14 health sub-domains, each backed by its own service import) is split one concern per file (`meatspaceCoreRoutes.js` overview/config/birth-date/death-clock/LEV, `meatspaceAlcoholRoutes.js`, `meatspaceNicotineRoutes.js`, `meatspaceHealthRoutes.js` blood/body/BP/workouts/epigenetic/eyes, `meatspacePostRoutes.js` POST drills + training + memory builder, `meatspaceCalendarRoutes.js` life calendar/activities/events, `meatspaceExportRoutes.js` MortalLoom export), assembled by a thin `meatspace.js` barrel that mounts each under `/api/meatspace` — the same pattern `routes/cos.js`/`routes/brain.js` use; the split is wiring-only (the 70-route surface is byte-identical, verified). The 1,805-line `videoGen/local.js` had its BYOV runtime management (venv/helper-script path constants, `BYOV_RUNTIME_INFO`, install/ready/fingerprint probes) extracted to `videoGen/runtimes.js` and its render-history I/O (`loadHistory`/`saveHistory`) to `videoGen/history.js`; `local.js` keeps generation + post-processing and re-exports the extracted surface so every existing deep import (`from '../videoGen/local.js'`) keeps resolving unchanged (all 30 prior exports preserved, verified). (#1833)
- **Decomposed `server/routes/brain.js` (1,149-line router covering 13 sub-domains)** — the monolithic Brain router that mixed capture/inbox, four entity CRUD collections + memories, digest/review, settings/summary, links + buckets, graph, federation sync, and the daily log is now split one concern per file (`brainCapture.js`, `brainCrud.js`, `brainDigest.js`, `brainSettings.js`, `brainLinks.js`, `brainGraph.js`, `brainSync.js`, `brainDailyLog.js`), assembled by a thin `brain.js` barrel that mounts each sub-router under `/api/brain` — the same pattern `routes/cos.js` already uses. The split is wiring-only: route paths, ordering (literal-before-`:id` routes stay within their owning sub-router), validation, and the barrel's default export are unchanged, so `server/index.js` and the existing `brain.test.js` (105 tests) pass without edits. (#1832)