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

docs+test: document PROMPT_VERSIONS bumps need no migration, guard against a seventh copy (#6482)

[._.]/91112df07347
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index 9d1447e7ba..74dfb32cdd 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -200,6 +200,7 @@ export const ALWAYS_RUN_TESTS = [
'scripts/client-server-import-purity.test.js',
'scripts/direct-invocation-drift.test.js',
'scripts/ensure-deps.test.js',
+ 'scripts/migrations/promptBumpMigrations.guard.test.js',
'scripts/node-version-drift.test.js',
'scripts/repo-scan-guards.test.js',
// Whole-tree scanner: any server file can add an import of client source.
diff --git a/scripts/migrations/promptBumpMigrations.guard.test.js b/scripts/migrations/promptBumpMigrations.guard.test.js
new file mode 100644
index 0000000000..a30405ccef
--- /dev/null
+++ b/scripts/migrations/promptBumpMigrations.guard.test.js
@@ -0,0 +1,77 @@
+/**
+ * Guard against re-introducing the copy-pasted prompt-bump migration (#6481).
+ *
+ * A `PROMPT_VERSIONS` bump needs no migration: `readSchedule()` in
+ * `server/services/taskScheduleStore.js` upgrades every uncustomized stored
+ * prompt to the shipped default on the next `loadSchedule()` and persists the
+ * result, so the first schedule read after an update converges the install
+ * anyway. Six migrations shipped between 2026-08-19 and 2026-09-03 before that
+ * was written down (281, 293, 297, 308, 332, 338) — each re-implementing that
+ * same loop against `data/task-schedule.json`, a path the store never reads.
+ * They stay (the distribution model forbids deleting applied migrations); this
+ * test only stops a seventh from joining them. See `server/AGENTS.md`
+ * "Prompt templates".
+ */
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { execFileSync } from 'node:child_process';
+import { join, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const HERE = resolve(fileURLToPath(import.meta.url), '..');
+const REPO_ROOT = resolve(HERE, '..', '..');
+
+// Frozen: the closed precedent this migration shape is not allowed to repeat.
+// Never add to this list — a new prompt bump needs no migration at all.
+const ALLOWED_PROMPT_BUMP_MIGRATIONS = new Set([
+ 'scripts/migrations/281-reconcile-missing-releases-prompt.js',
+ 'scripts/migrations/293-agents-md-prompt-rename.js',
+ 'scripts/migrations/297-release-check-slashdo-review-prompt.js',
+ 'scripts/migrations/308-release-check-advisory-review-prompt.js',
+ 'scripts/migrations/332-release-check-fix-blockers-prompt.js',
+ 'scripts/migrations/338-claim-issue-volunteer-claim-contract.js',
+]);
+
+const IMPORTS_PROMPT_DEFAULTS = /from\s+['"][^'"]*taskPromptDefaults\.js['"]/;
+const WRITES_TASK_SCHEDULE = /task-schedule\.json/;
+
+let tracked;
+const trackedMigrations = () => (tracked ??= execFileSync(
+ 'git',
+ ['ls-files', 'scripts/migrations/*.js'],
+ { cwd: REPO_ROOT, encoding: 'utf8' },
+).split('\n').filter((path) => path && !path.endsWith('.test.js')));
+
+describe('prompt-bump migrations stay closed', () => {
+ it('finds the migrations it is meant to guard', () => {
+ // A regression here means the pathspec stopped matching and every
+ // assertion below started passing vacuously.
+ expect(trackedMigrations()).toEqual(expect.arrayContaining([...ALLOWED_PROMPT_BUMP_MIGRATIONS]));
+ });
+
+ it('rejects a new migration that re-implements the schedule loader\'s prompt upgrade', () => {
+ const offenders = trackedMigrations()
+ .filter((path) => !ALLOWED_PROMPT_BUMP_MIGRATIONS.has(path))
+ .filter((path) => {
+ const source = readFileSync(join(REPO_ROOT, path), 'utf8');
+ return IMPORTS_PROMPT_DEFAULTS.test(source) && WRITES_TASK_SCHEDULE.test(source);
+ });
+
+ expect(offenders, [
+ 'A migration outside the frozen prompt-bump allowlist imports',
+ 'taskPromptDefaults.js and writes task-schedule.json — the exact shape',
+ 'this guard exists to stop. A PROMPT_VERSIONS bump needs no migration:',
+ 'taskScheduleStore.js#readSchedule() upgrades every uncustomized stored',
+ 'prompt on the next loadSchedule() and persists it. See server/AGENTS.md',
+ '"Prompt templates".',
+ ].join(' ')).toEqual([]);
+ });
+
+ // Bypass probe: prove the detector actually fires on the shape it targets,
+ // not merely that reading six known-good files finds nothing.
+ it('flags the copy-pasted shape wherever it appears', () => {
+ expect(IMPORTS_PROMPT_DEFAULTS.test("import { PROMPT_VERSIONS } from '../../server/services/taskPromptDefaults.js';")).toBe(true);
+ expect(WRITES_TASK_SCHEDULE.test("join('data', 'cos', 'task-schedule.json')")).toBe(true);
+ expect(IMPORTS_PROMPT_DEFAULTS.test("import { readFile } from 'fs/promises';")).toBe(false);
+ });
+});
diff --git a/server/AGENTS.md b/server/AGENTS.md
index 373b1fda6f..e9fce4a6fd 100644
--- a/server/AGENTS.md
+++ b/server/AGENTS.md
@@ -39,4 +39,5 @@ These apply to Express/service/model code. Universal constraints (no try/catch o
## Prompt templates
- **Stage-prompt template changes need a migration.** `scripts/setup-data.js` only copies *missing* prompt files to `data/prompts/stages/` — existing installs keep their old templates. When you add a `{{template.variable}}` reference to a `data.reference/prompts/stages/*.md` file, also add an entry to `scripts/migrations/NNN-…js` that updates the corresponding installed prompt when its hash still matches the pre-change shipped version. Normalize line endings (`\r\n` → `\n`, bare `\r` → `\n`) before hashing so the comparison is correct on Windows checkouts. The drift warning in `scripts/setup-data.js` distinguishes auto-updatable (matches old shipped hash) from customized (matches neither) — when adding to the migrated list, mirror both `OLD_SHIPPED_MD5` and `NEW_SHIPPED_MD5` there too so the warning stays actionable. Migration scripts live in `scripts/migrations/`; the per-install applied-list is `data/migrations.applied.json` (gitignored runtime state). See `scripts/migrations/003-update-pipeline-stage-prompts.js`.
+- **A `PROMPT_VERSIONS` bump for a scheduled-task prompt (`server/services/taskPromptDefaults.js`) needs NO migration.** `readSchedule()` in `server/services/taskScheduleStore.js` already upgrades every uncustomized stored prompt to the shipped default on the next `loadSchedule()` and persists the result — the first schedule read after the update converges the install regardless of whether a migration ran. Six migrations re-implemented that same loop against `data/task-schedule.json` (a path the store never reads — it reads `data/cos/task-schedule.json`) before this was written down: `281-reconcile-missing-releases-prompt.js`, `293-agents-md-prompt-rename.js`, `297-release-check-slashdo-review-prompt.js`, `308-release-check-advisory-review-prompt.js`, `332-release-check-fix-blockers-prompt.js`, `338-claim-issue-volunteer-claim-contract.js`. They stay — the distribution model forbids deleting applied migrations — but they are closed precedent, not a pattern to repeat. `scripts/migrations/promptBumpMigrations.guard.test.js` fails if a seventh copy imports `taskPromptDefaults.js` and writes `task-schedule.json`.
- **Creative prompts carry the IP-latitude clause automatically — never stamp it by hand.** PortOS is a professional artist's tool; a model that silently renames, genericizes, or disclaimers a deliberate reference to existing IP produces defective output, and rights/clearance is the operator's responsibility, not the model's. `server/lib/creativeLatitude.js` owns the clause and the single table that classifies what gets it, applied at each of the three LLM transports: `promptService.buildPrompt` (stage templates, keyed on the stage name — fails SAFE, so a stage the tables never saw is stamped), `promptRunner.runPromptThroughProvider` (every hand-rolled prompt, keyed on the run `source` tag it already requires — an allowlist, since ops calls dominate there), and `aiProvider.callProviderAISimple` (its own fetch, so creative callers pass `creative: true`). So **a new creative stage or LLM-calling service is covered only once its stage name / `source` is classified in that module** — add the prefix or exact name there rather than wrapping a call site. Two guard tests force the decision: `creativeLatitude.test.js` walks `data.reference/prompts/stage-config.json`, and `creativeLatitude.sources.test.js` scans every `source:` literal handed to the shared runners — both fail on an unclassified entry. A caller that budgets a context window before the stamp lands (the inline editorial check) must reserve `CREATIVE_LATITUDE_TOKENS`.