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
fix([bump-stale-shipped-md5-on-settled-migrations]): track live-sample hashes in migrations 003/004/005/013 (#418)
[._.]/ Adam Eivy0ed63bfa6c69
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex fc38670beb..402694358e 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -12,6 +12,7 @@- **[cover-prose-input-idea-input-in-canonusage-corpus] Universe canon cross-reference test suite now pins every stage the per-issue search reads** — a regression that silently drops a stage from the search now fails the test suite immediately.- **[extract-shared-requiretoolkit-helper] Internal: consolidated three duplicated AI toolkit accessors into one shared module.** No behavior change; cuts ~30 lines and makes future toolkit-state changes one-touch.- **[backport-pre-023-migrations-to-_lib] Internal: collapsed seven settled prompt-update migrations onto the shared `_lib.js` helper.** Drops ~465 lines of duplicated migration scaffolding so future prompt-replace migrations are easier to read and review. The shared helper now also handles the rename/retire case migration 003 needed for the long-renamed `pipeline-tv-script.md` template — older installs that still carry that file get it removed cleanly on next startup.+- **[bump-stale-shipped-md5-on-settled-migrations] Internal: prompt-replace migrations 003 / 004 / 005 / 013 now track the live `data.sample` hash and ship per-migration test files.** Each migration's `NEW_SHIPPED_MD5` was advancing-and-then-stale (e.g. 005's `pipeline-arc-overview.md` had been re-evolved by 019, 013's `pipeline-comic-script.md` by 027), so a fresh install whose `data/migrations.applied.json` was reset would misclassify the live sample as "customized" and skip the upgrade. Bumped each NEW hash to the current live sample, appended every intermediate hash to `ACCEPTED_OLD_MD5` per the 019 convention, and added a `<num>.test.js` for each migration so the drift catch fails fast on future template edits. The shared `runPromptMigrationTests` helper grew a `createIfMissing` opt-in so migration 005's missing-file branch can be asserted directly.- **[codex5-bundle-lazy-routes] Dashboard widgets load on demand.** A dashboard layout now only downloads the widgets it actually uses — the first paint of a slimmed-down layout no longer drags in every widget in the registry, and slow widgets render their own placeholder while loading instead of blocking sibling cells. Also adds an `npm run build:analyze` script for inspecting bundle composition during development.- **[strip-stage-runhistory-from-list-payloads] Pipeline list views stay lean as version history grows.** The sidebar's recent-issues list and the per-series issue list no longer ship each stage's full draft history on every read — the History button on an issue's detail page still shows the full set, but list responses can no longer balloon to many megabytes once a series has many issues with deep histories.- **GOALS.md is now purely strategic; CoS runtime guidance lives in `docs/GOALS_OPERATIONAL.md`.** The per-domain operational goals, task-generation priorities, and core principles that the autonomous agent reads have been split out of GOALS.md so each file has a single concern. No behavior change — the Goal Progress dashboard still reads the same goals; only the file path moved.diff --git a/PLAN.md b/PLAN.mdindex dde0027920..52298c7927 100644--- a/PLAN.md+++ b/PLAN.md@@ -4,7 +4,6 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [.changel## Next Up-- [ ] [bump-stale-shipped-md5-on-settled-migrations] **Bump stale `NEW_SHIPPED_MD5` entries on settled migrations + add `runPromptMigrationTests` coverage.** Migrations 003 / 004 / 005 / 013 still record their original NEW hash, but downstream migrations have since evolved the same files (e.g. 003's `pipeline-idea-expansion.md` is at the post-025 hash today, 005's `pipeline-arc-overview.md` is at the post-019 hash, 013's `pipeline-comic-script.md` is past `133d200d069c2e8173b7c129eea58f53`). That's a latent bug: a fresh install with `data/migrations.applied.json` cleared misclassifies every shipped file as "customized" instead of "already current," and `runPromptMigrationTests`'s drift-catch can't be wired up. Per the 019 convention, bump each migration's `NEW_SHIPPED_MD5` entry to the current `data.sample` hash and append the intermediate hash(es) to `ACCEPTED_OLD_MD5`; then add a `<num>.test.js` that calls `runPromptMigrationTests`. Skipped from `[backport-pre-023-migrations-to-_lib]` because that PR was scoped to a pure refactor.- [ ] [useautorefetch-poll-result-dedup] **`useAutoRefetch` poll-result deduplication.** Surfaced by /simplify during `[codex5-polling-consolidation]`. After migrating 20 callers to `useAutoRefetch`, every poll still calls `setData(result)` unconditionally — re-rendering even when the API returned bytewise-identical state. `EpisodeVideoStage` is the only pre-existing dedup site (`(prev, p) => prev.updatedAt === p.updatedAt && prev.status === p.status`); the rest (ProcessesTab, AgentsPage, Brain summary, DigitalTwin status, meatspace OverviewTab fan-out, MediaJobsQueue, ChiefOfStaff, Browser status, etc.) re-render every interval. Options: (a) accept an optional `compareKey: (data) => string` option on the hook so callers can opt into signature-compare, (b) wrap the hook's internal `setData` to default to `Object.is` comparison and only the rare case (deep object reuse) needs explicit opt-in. Low priority — UI churn is invisible but burns CPU on the Dashboard's many widgets.- [ ] [useautorefetch-shared-visibility-listener] **Shared `visibilitychange` listener for `useAutoRefetch` consumers.** Each `useAutoRefetch` caller currently attaches its own `document.addEventListener('visibilitychange', ...)`. On a page with 20+ widgets (Dashboard), tab show fires 20+ near-simultaneous `loadData()` calls. Extract a singleton emitter (e.g. `client/src/hooks/useVisibilityEvent.js`) and have `useAutoRefetch` subscribe to that instead. Trivial overhead today; revisit if Dashboard widget count grows or profiling flags it.- [ ] [useautorefetch-pollonly-mode] **`useAutoRefetch` `{ pollOnly: true }` mode.** Several callers (Brain, DigitalTwin, ChiefOfStaff, meatspace OverviewTab, MediaJobsQueue, Loops, etc.) use the hook purely as a poll tick — they own their own state via the fetchFn's side-effects and ignore `data` / `loading`. The `return null;` ceremony is documented but signals "I'm not using the hook's data". Add a `{ pollOnly: true }` option that skips the `data` / `loading` useStates and returns `{ refetch }` only, so side-effect-only callers don't carry unused state. Defer until there are enough such callers that the noise is worth abstracting.diff --git a/scripts/migrations/003-update-pipeline-stage-prompts.js b/scripts/migrations/003-update-pipeline-stage-prompts.jsindex ec5294c9d6..f197111aec 100644--- a/scripts/migrations/003-update-pipeline-stage-prompts.js+++ b/scripts/migrations/003-update-pipeline-stage-prompts.js@@ -19,19 +19,33 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-idea-expansion.md': ['aee25112b2c596f643b17c559b772c22'],- 'pipeline-prose.md': ['bfea5aeeb471aae9749baee765b473a7'],- 'pipeline-comic-script.md': ['40e5fdc1a1e68a7419b7dad936366c1a'],+ 'pipeline-idea-expansion.md': [+ 'aee25112b2c596f643b17c559b772c22', // pre-003 (original)+ '41facefbc0c0549d456bef9111f95ab9', // post-003 / pre-004 — the hash this migration originally produced+ '1ee44cf95851ff8debf18729ebcd40b4', // post-004 / pre-025+ ],+ 'pipeline-prose.md': [+ 'bfea5aeeb471aae9749baee765b473a7', // pre-003 (original)+ '30ac30ec2b9d3e2a9eb869c181732cc6', // post-003 / pre-027 — the hash this migration originally produced+ ],+ 'pipeline-comic-script.md': [+ '40e5fdc1a1e68a7419b7dad936366c1a', // pre-003 (original)+ 'beab031951859ca13579cdb9c4dbe769', // post-003 / pre-013 — the hash this migration originally produced+ '1e0af305c27d0c80c4b482d2ebcb4a0d', // post-013 / pre-027+ ],'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],- 'pipeline-season-episodes.md': ['6e349ad26bed8a0ccb042571f03f03eb'],+ 'pipeline-season-episodes.md': [+ '6e349ad26bed8a0ccb042571f03f03eb', // pre-003 (original)+ 'c4928e2a5f833358116b29d2d669888d', // post-003 / pre-005 — the hash this migration originally produced+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-idea-expansion.md': '41facefbc0c0549d456bef9111f95ab9',- 'pipeline-prose.md': '30ac30ec2b9d3e2a9eb869c181732cc6',- 'pipeline-comic-script.md': 'beab031951859ca13579cdb9c4dbe769',- 'pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a',- 'pipeline-season-episodes.md': 'c4928e2a5f833358116b29d2d669888d',+ 'pipeline-idea-expansion.md': '1f3c5d077a5ef9a4b610335d5e3edd9c', // post-025+ 'pipeline-prose.md': 'd1f8e3f1d214725b5aa67f309a81cd7d', // post-027+ 'pipeline-comic-script.md': '133d200d069c2e8173b7c129eea58f53', // post-027+ 'pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a', // retired upstream (no data.sample)+ 'pipeline-season-episodes.md': '50c68a29c3ebc275db3095d06bd87100', // post-005};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/003-update-pipeline-stage-prompts.test.js b/scripts/migrations/003-update-pipeline-stage-prompts.test.jsnew file mode 100644index 0000000000..3cba9c657f--- /dev/null+++ b/scripts/migrations/003-update-pipeline-stage-prompts.test.js@@ -0,0 +1,32 @@+/**+ * Test for migration 003 — pipeline stage prompts gain {{lengthTargets.*}}+ * variables.+ *+ * `pipeline-tv-script.md` was retired (renamed to `pipeline-teleplay.md`) so+ * it has no `data.sample/` counterpart; the standard fixture loop in+ * `_testHelpers.js` reads the live sample to seed each fixture, which would+ * ENOENT on the retired entry. Filter it out of the test-facing maps — the+ * retire-on-missing branch is exercised end-to-end by `scripts/run-migrations.js`+ * on every fresh install, not by this drift-catch suite.+ *+ * Picked up via the vitest include glob in server/vitest.config.js+ * (`../scripts/migrations/**\/*.test.js`).+ */+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './003-update-pipeline-stage-prompts.js';++const RETIRED = 'pipeline-tv-script.md';+const { [RETIRED]: _retiredAccepted, ...ACTIVE_ACCEPTED } = ACCEPTED_OLD_MD5;+const { [RETIRED]: _retiredNew, ...ACTIVE_NEW } = NEW_SHIPPED_MD5;++describe('migration 003 — pipeline stage prompts (length profile)', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5: ACTIVE_ACCEPTED,+ NEW_SHIPPED_MD5: ACTIVE_NEW,+ prefix: 'migration-003-',+ });+});diff --git a/scripts/migrations/004-augment-idea-expansion-context.js b/scripts/migrations/004-augment-idea-expansion-context.jsindex 576b4d333e..06dbe9f408 100644--- a/scripts/migrations/004-augment-idea-expansion-context.js+++ b/scripts/migrations/004-augment-idea-expansion-context.js@@ -12,11 +12,14 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-idea-expansion.md': ['41facefbc0c0549d456bef9111f95ab9'], // post-003+ 'pipeline-idea-expansion.md': [+ '1ee44cf95851ff8debf18729ebcd40b4', // post-004 / pre-025 — the hash this migration originally produced+ '41facefbc0c0549d456bef9111f95ab9', // post-003 / pre-004+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-idea-expansion.md': '1ee44cf95851ff8debf18729ebcd40b4',+ 'pipeline-idea-expansion.md': '1f3c5d077a5ef9a4b610335d5e3edd9c', // post-025};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/004-augment-idea-expansion-context.test.js b/scripts/migrations/004-augment-idea-expansion-context.test.jsnew file mode 100644index 0000000000..3cb12ac308--- /dev/null+++ b/scripts/migrations/004-augment-idea-expansion-context.test.js@@ -0,0 +1,21 @@+/**+ * Test for migration 004 — pipeline-idea-expansion.md gains arc / volume /+ * neighbor-issue context blocks.+ *+ * Picked up via the vitest include glob in server/vitest.config.js+ * (`../scripts/migrations/**\/*.test.js`).+ */+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './004-augment-idea-expansion-context.js';++describe('migration 004 — idea-expansion context', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ prefix: 'migration-004-',+ });+});diff --git a/scripts/migrations/005-shape-aware-arc-prompts.js b/scripts/migrations/005-shape-aware-arc-prompts.jsindex 02b5529db8..db23b42ec9 100644--- a/scripts/migrations/005-shape-aware-arc-prompts.js+++ b/scripts/migrations/005-shape-aware-arc-prompts.js@@ -21,19 +21,32 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326'],- 'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a'],- 'pipeline-volume-verify.md': ['c6ea28e972ad6e229bafb2d602b4dda3'],- 'pipeline-season-episodes.md': ['c4928e2a5f833358116b29d2d669888d'],- 'pipeline-arc-resolve.md': ['87bc5c01f1a8a97b681727a38b05edc6'],+ 'pipeline-arc-overview.md': [+ '6a3ecab43d1f46b7ef9aab6c69ea0326', // pre-005 (original)+ 'd34d72b8e49ba303d38607845dd87f1c', // post-005 / pre-019 — the hash this migration originally produced+ ],+ 'pipeline-arc-verify.md': [+ '52e31abc93e3105176236fcaa5d1575a', // pre-005 (original)+ 'ff56d8387162017e08d5d0491060ddd6', // post-005 / pre-019 — the hash this migration originally produced+ ],+ 'pipeline-volume-verify.md': [+ 'c6ea28e972ad6e229bafb2d602b4dda3', // pre-005 (original)+ '03f3c874cb80e1c98abcf03168fa7a92', // post-005 / pre-019 — the hash this migration originally produced+ ],+ 'pipeline-season-episodes.md': ['c4928e2a5f833358116b29d2d669888d'], // pre-005 (original); post-005 hash IS the live sample+ 'pipeline-arc-resolve.md': [+ '87bc5c01f1a8a97b681727a38b05edc6', // pre-005 (original)+ 'a8677bbe1eb38f871fb152a5b0fec7c6', // post-005 / pre-019 — the hash this migration originally produced+ '8e348f3d1894382889f9f0ee7d5c6792', // post-019 / pre-023+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-overview.md': 'd34d72b8e49ba303d38607845dd87f1c',- 'pipeline-arc-verify.md': 'ff56d8387162017e08d5d0491060ddd6',- 'pipeline-volume-verify.md': '03f3c874cb80e1c98abcf03168fa7a92',- 'pipeline-season-episodes.md': '50c68a29c3ebc275db3095d06bd87100',- 'pipeline-arc-resolve.md': 'a8677bbe1eb38f871fb152a5b0fec7c6',+ 'pipeline-arc-overview.md': '0a1f6ffa6908522e3690c5e9e53a6ee0', // post-019+ 'pipeline-arc-verify.md': '36aa70cdfc25d7549573a4d556e7702c', // post-019+ 'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940', // post-019+ 'pipeline-season-episodes.md': '50c68a29c3ebc275db3095d06bd87100', // post-005 (live sample)+ 'pipeline-arc-resolve.md': '5b340885c6e8f8afc63424d6b5bc7eb7', // post-023};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/005-shape-aware-arc-prompts.test.js b/scripts/migrations/005-shape-aware-arc-prompts.test.jsnew file mode 100644index 0000000000..a0918f38b0--- /dev/null+++ b/scripts/migrations/005-shape-aware-arc-prompts.test.js@@ -0,0 +1,22 @@+/**+ * Test for migration 005 — pipeline arc / season / verify / resolve prompts+ * gain Vonnegut-shape variables.+ *+ * Picked up via the vitest include glob in server/vitest.config.js+ * (`../scripts/migrations/**\/*.test.js`).+ */+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './005-shape-aware-arc-prompts.js';++describe('migration 005 — shape-aware arc/volume prompts', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ prefix: 'migration-005-',+ createIfMissing: true,+ });+});diff --git a/scripts/migrations/013-comic-script-back-cover.js b/scripts/migrations/013-comic-script-back-cover.jsindex 0f36547e7b..befdddd77e 100644--- a/scripts/migrations/013-comic-script-back-cover.js+++ b/scripts/migrations/013-comic-script-back-cover.js@@ -17,11 +17,12 @@ export const ACCEPTED_OLD_MD5 = {'pipeline-comic-script.md': ['40e5fdc1a1e68a7419b7dad936366c1a', // pre-003 (original)'beab031951859ca13579cdb9c4dbe769', // post-003 (length-profile feature)+ '1e0af305c27d0c80c4b482d2ebcb4a0d', // post-013 / pre-027 — the hash this migration originally produced],};export const NEW_SHIPPED_MD5 = {- 'pipeline-comic-script.md': '1e0af305c27d0c80c4b482d2ebcb4a0d',+ 'pipeline-comic-script.md': '133d200d069c2e8173b7c129eea58f53', // post-027};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/013-comic-script-back-cover.test.js b/scripts/migrations/013-comic-script-back-cover.test.jsnew file mode 100644index 0000000000..b61eb53b73--- /dev/null+++ b/scripts/migrations/013-comic-script-back-cover.test.js@@ -0,0 +1,21 @@+/**+ * Test for migration 013 — pipeline-comic-script.md gains a `## Back cover+ * concept` section.+ *+ * Picked up via the vitest include glob in server/vitest.config.js+ * (`../scripts/migrations/**\/*.test.js`).+ */+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './013-comic-script-back-cover.js';++describe('migration 013 — comic-script back-cover', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ prefix: 'migration-013-',+ });+});diff --git a/scripts/migrations/_testHelpers.js b/scripts/migrations/_testHelpers.jsindex 61c6cb7a56..327bdd2792 100644--- a/scripts/migrations/_testHelpers.js+++ b/scripts/migrations/_testHelpers.js@@ -33,6 +33,10 @@ export const customizedBody = (filename) =>* (`'migration-025-'`) so a debugger leaves a recognizable sandbox in `/tmp`.* `subdir` defaults to `'stages'`; pass `'_partials'` for shared mustache* fragments that live under `data/prompts/_partials/` instead.+ *+ * `createIfMissing` mirrors the migration's own `createIfMissing` flag (e.g.+ * migration 005). When true, the "missing on disk" case writes sample → data+ * instead of being a no-op, so the test asserts the sample body landed.*/export function runPromptMigrationTests({migration,@@ -41,6 +45,7 @@ export function runPromptMigrationTests({NEW_SHIPPED_MD5,prefix,subdir = 'stages',+ createIfMissing = false,}) {let rootDir;let stagesDir;@@ -60,12 +65,23 @@ export function runPromptMigrationTests({rmSync(rootDir, { recursive: true, force: true });});- it('no-ops when the stage prompt is missing (setup-data.js will create it)', async () => {- await expect(migration.up({ rootDir })).resolves.not.toThrow();- for (const filename of Object.keys(NEW_SHIPPED_MD5)) {- expect(existsSync(join(stagesDir, filename))).toBe(false);- }- });+ it(+ createIfMissing+ ? 'creates from sample when the stage prompt is missing (createIfMissing)'+ : 'no-ops when the stage prompt is missing (setup-data.js will create it)',+ async () => {+ await expect(migration.up({ rootDir })).resolves.not.toThrow();+ for (const filename of Object.keys(NEW_SHIPPED_MD5)) {+ const dataPath = join(stagesDir, filename);+ if (createIfMissing) {+ expect(existsSync(dataPath)).toBe(true);+ expect(readFileSync(dataPath, 'utf-8')).toBe(sampleBody(filename, subdir));+ } else {+ expect(existsSync(dataPath)).toBe(false);+ }+ }+ },+ );it('skips files already at the new hash (idempotent re-run)', async () => {for (const filename of Object.keys(NEW_SHIPPED_MD5)) {