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
show the arc verifier the world category canon it judges groundedness against
[._.]/ Adam Eivy0fa14773f478
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex e4845ce021..c4f07cd8d7 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -38,6 +38,8 @@## Changed+- The series arc verifier can now see the world canon it was already judging against. A Universe Builder world keeps its factions, locations, vehicles, artifacts and interfaces as category variations; the named-canon trunks the verify prompt rendered stay empty until prose mints entities into them. So the verifier was handed a block labelled "world canon" that omitted the entire built world, and reported locked faction cards as invented and "absent from the World Canon" — findings no arc edit can ever close. That is a stall rather than a nuisance: the foundation gate's structure repair reverts its whole rewrite whenever verification leaves any blocker, so one permanent false positive discards every real fix beside it and the autopilot pauses. The sibling arc-resolve and volume-verify prompts already rendered this block, which is exactly why the verify/resolve pair could never converge. The arc-verify prompt now renders the category and composite canon, states that a listed entity is grounded, and a new contract test holds the pair to one world — plus the field-level half of the same class, asserting that every record field the checklist cites is one the context actually renders.+- The three collapsible result sections in the digital-twin list enrichment view — Item-by-Item Analysis, Patterns Detected and Personality Insights — now announce whether they are open. Their headers were plain `<button>`s whose only expanded/collapsed signal was the chevron glyph swapping between down and right, so a screen reader read the same label before and after activation with no state to report. Each header now carries `aria-expanded` bound to its own visibility flag and `aria-controls` pointing at the panel it toggles, and the panels carry the matching ids.- A federated catalog bundle whose live rows sit outside `ingredients` no longer bypasses the peer-sync schema-version gate. `applyIncomingPush` decided whether to gate the `catalog` category by looking at `catalogBundle.ingredients` alone, but the exporter already ships ingredient-free bundles (`refs` only), and catalog schema v4–v8 added `relations`, `tags`, `media` and `catalogTypes` blocks — so a peer on a newer catalog schema could push forward-shaped rows straight into an older receiver, which then tried to apply structures it can't interpret. The gate now counts a live row in ANY block of the bundle, including one added by a catalog version newer than the receiver knows about, and such a push is rejected with the usual 409 `PEER_SYNC_SCHEMA_VERSION_AHEAD`. Tombstone-only bundles stay exempt, so federated catalog deletes still converge across a version gap.diff --git a/PLAN.md b/PLAN.mdindex 7c2daf7fd3..31194d1c47 100644--- a/PLAN.md+++ b/PLAN.md@@ -348,7 +348,9 @@ is not reliably announced.### Stop the arc-verify prompt from checking fields its context never renders-- [ ] The arc-verify prompt's checklist and `buildVerifyContext`'s `renderLeaf` (`server/services/pipeline/arcPlanner/context.js`) are two independent lists that have to agree, with nothing enforcing it. They drifted once already: check #6 in `data/prompts/stages/pipeline-arc-verify.md` reports an arc-role imbalance from `arcRole`, which the leaf did not render, so every verified series got a permanent "zero pilot/finale" finding no resolver could ever close — and because the foundation gate's structure arm reverts whenever `verifyArc` leaves *any* blocker, that one phantom finding stalled the gate on plans with nothing wrong with them. `arcRole` is now rendered, but the class is still open: the same silent drift returns the next time a check names a field (`status`, `lengthProfile`, `themes`, a season field) the leaf drops. **The call to make:** add a test that parses the installed + shipped `pipeline-arc-verify.md` for backticked leaf field names and asserts each one appears in a leaf built by `buildVerifyContext`, failing loudly on a check that reads a field the context cannot supply. Prove it with a bypass probe (delete a field from the leaf and watch the test fail) — a rendered-but-unread field is harmless, an unrendered-but-checked field is a permanent false positive. `renderVolumeIssue` needs the same treatment against `pipeline-volume-verify.md` if that prompt ever grows a field-level check. Surfaced while unstalling a foundationGate pause whose structure repair had been reverting on this phantom blocker.+- [x] The arc-verify prompt's checklist and `buildVerifyContext`'s `renderLeaf` (`server/services/pipeline/arcPlanner/context.js`) are two independent lists that have to agree, with nothing enforcing it. They drifted once already: check #6 in `data/prompts/stages/pipeline-arc-verify.md` reports an arc-role imbalance from `arcRole`, which the leaf did not render, so every verified series got a permanent "zero pilot/finale" finding no resolver could ever close — and because the foundation gate's structure arm reverts whenever `verifyArc` leaves *any* blocker, that one phantom finding stalled the gate on plans with nothing wrong with them. `arcRole` is now rendered, but the class is still open: the same silent drift returns the next time a check names a field (`status`, `lengthProfile`, `themes`, a season field) the leaf drops. **The call to make:** add a test that parses the installed + shipped `pipeline-arc-verify.md` for backticked leaf field names and asserts each one appears in a leaf built by `buildVerifyContext`, failing loudly on a check that reads a field the context cannot supply. Prove it with a bypass probe (delete a field from the leaf and watch the test fail) — a rendered-but-unread field is harmless, an unrendered-but-checked field is a permanent false positive. Surfaced while unstalling a foundationGate pause whose structure repair had been reverting on this phantom blocker. **Shipped** as `server/services/pipeline/arcPlanner/verifyPromptContract.test.js`, which covers both halves of the class: every backticked record field the checklist cites must be renderable by the exported `renderVerifyIssueLeaf` / `renderVerifySeasonFields`, and the verify prompt must render every world block its paired resolve prompt does. The second half caught a live instance — the verifier judged groundedness against `worldCanonText` alone while the resolver could see `worldCategoriesText`, so locked faction cards read as un-canonized (migration 263).++- [ ] `renderVolumeIssue` needs the same field-level contract test against `pipeline-volume-verify.md` that `renderVerifyIssueLeaf` now has against `pipeline-arc-verify.md`. That prompt carries no field-level check today, so there is nothing broken yet — but it is the same two-lists-with-nothing-enforcing-agreement shape, and the volume verifier feeds the same revert-on-any-blocker gate.### Give the foundation gate's structure repair the same rollback ownership as the arc gatediff --git a/data.reference/prompts/stages/pipeline-arc-verify.md b/data.reference/prompts/stages/pipeline-arc-verify.mdindex 278184a0d0..38ac5de98f 100644--- a/data.reference/prompts/stages/pipeline-arc-verify.md+++ b/data.reference/prompts/stages/pipeline-arc-verify.md@@ -39,6 +39,25 @@ that an old draft's cast, villain, faction, or institution belongs in this arc.```{{worldCanonText}}```++### World entity categories — established factions, locations, technology++```+{{worldCategoriesText}}+```++### World composite reference sheets++```+{{worldCompositesText}}+```++The categories and composites above are **established world canon**, not exploratory scratch.+A faction, location, vehicle, artifact, or interface listed there is grounded+even when no named-canon record exists for it — the canon trunks above stay+empty until prose mints entities into them. Do NOT report such an entity as+invented, un-canonized, or absent from the world bible; check this block before+flagging any entity as ungrounded.{{/hasLinkedWorld}}## Full arcdiff --git a/scripts/migrations/005-shape-aware-arc-prompts.js b/scripts/migrations/005-shape-aware-arc-prompts.jsindex 003215a68e..9d138d9d06 100644--- a/scripts/migrations/005-shape-aware-arc-prompts.js+++ b/scripts/migrations/005-shape-aware-arc-prompts.js@@ -31,6 +31,7 @@ export const ACCEPTED_OLD_MD5 = {'52e31abc93e3105176236fcaa5d1575a', // pre-005 (original)'ff56d8387162017e08d5d0491060ddd6', // post-005 / pre-019 — the hash this migration originally produced'83347e7d923580a3062033ab39b3c14b', // post-250 / pre-261 — arc spine checkpoint before exhaustive verification+ '68f6956d7e09ebdb3870d8726b1b2a7a', // post-261 / pre-263 — before the world category canon block],'pipeline-volume-verify.md': ['c6ea28e972ad6e229bafb2d602b4dda3', // pre-005 (original)@@ -51,7 +52,7 @@ export const ACCEPTED_OLD_MD5 = {export const NEW_SHIPPED_MD5 = {'pipeline-arc-overview.md': '5ed760caaf3cf88916ec28b220e2f590', // post-250 arc spine checkpoint- 'pipeline-arc-verify.md': '68f6956d7e09ebdb3870d8726b1b2a7a', // post-261 exhaustive arc verification+ 'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3', // post-263 world category canon'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940', // post-019'pipeline-season-episodes.md': 'a88e8e78a949b7aaf500d03314e2ea0b', // post-172 (structure rules)'pipeline-arc-resolve.md': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)diff --git a/scripts/migrations/019-arc-volume-prompts-canon-context.js b/scripts/migrations/019-arc-volume-prompts-canon-context.jsindex 2a91ede881..932a701bb1 100644--- a/scripts/migrations/019-arc-volume-prompts-canon-context.js+++ b/scripts/migrations/019-arc-volume-prompts-canon-context.js@@ -46,6 +46,7 @@ export const ACCEPTED_OLD_MD5 = {'ff56d8387162017e08d5d0491060ddd6', // current (pre-Phase B) shipped'52e31abc93e3105176236fcaa5d1575a', // pre-005 (shape-aware), still in setup-data.js OLD list'83347e7d923580a3062033ab39b3c14b', // post-250 / pre-261 — arc spine checkpoint before exhaustive verification+ '68f6956d7e09ebdb3870d8726b1b2a7a', // post-261 / pre-263 — before the world category canon block],'pipeline-arc-resolve.md': ['cc27b4da1d1a13c35e35d1c2d6183815', // post-123 / pre-245 — the episodes[] channel, before edits had to name a finding@@ -62,7 +63,7 @@ export const ACCEPTED_OLD_MD5 = {export const NEW_SHIPPED_MD5 = {'pipeline-arc-overview.md': '5ed760caaf3cf88916ec28b220e2f590', // post-250 arc spine checkpoint- 'pipeline-arc-verify.md': '68f6956d7e09ebdb3870d8726b1b2a7a', // post-261 exhaustive arc verification+ 'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3', // post-263 world category canon'pipeline-arc-resolve.md': '2349bce80e9df8caafa391a6106327b6', // post-259 (measured text budgets)'pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940', // post-019};diff --git a/scripts/migrations/250-arc-spine-checkpoint-prompts.js b/scripts/migrations/250-arc-spine-checkpoint-prompts.jsindex 63102e7c3e..b210f6e99f 100644--- a/scripts/migrations/250-arc-spine-checkpoint-prompts.js+++ b/scripts/migrations/250-arc-spine-checkpoint-prompts.js@@ -12,12 +12,13 @@ export const ACCEPTED_OLD_MD5 = {'pipeline-arc-verify.md': ['36aa70cdfc25d7549573a4d556e7702c','83347e7d923580a3062033ab39b3c14b', // post-250 / pre-261+ '68f6956d7e09ebdb3870d8726b1b2a7a', // post-261 / pre-263 — before the world category canon block],};export const NEW_SHIPPED_MD5 = {'pipeline-arc-overview.md': '5ed760caaf3cf88916ec28b220e2f590',- 'pipeline-arc-verify.md': '68f6956d7e09ebdb3870d8726b1b2a7a',+ 'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3', // post-263 world category canon};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/261-exhaustive-arc-verification.js b/scripts/migrations/261-exhaustive-arc-verification.jsindex 0211cc0a2e..e4538c8ebc 100644--- a/scripts/migrations/261-exhaustive-arc-verification.js+++ b/scripts/migrations/261-exhaustive-arc-verification.js@@ -13,11 +13,14 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'pipeline-arc-verify.md': ['83347e7d923580a3062033ab39b3c14b'],+ 'pipeline-arc-verify.md': [+ '83347e7d923580a3062033ab39b3c14b',+ '68f6956d7e09ebdb3870d8726b1b2a7a', // post-261 / pre-263 — before the world category canon block+ ],};export const NEW_SHIPPED_MD5 = {- 'pipeline-arc-verify.md': '68f6956d7e09ebdb3870d8726b1b2a7a',+ 'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3', // post-263 world category canon};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/263-arc-verify-world-category-canon.js b/scripts/migrations/263-arc-verify-world-category-canon.jsnew file mode 100644index 0000000000..430223d870--- /dev/null+++ b/scripts/migrations/263-arc-verify-world-category-canon.js@@ -0,0 +1,43 @@+/**+ * Show the arc verifier the world canon it is already judging groundedness+ * against.+ *+ * A Universe Builder world defines its factions, locations, vehicles, artifacts,+ * and interfaces as `categories` variations. The named-canon trunks the verify+ * prompt rendered (`worldCanonText` — characters/places/objects) stay EMPTY until+ * prose mints entities into them, so the verifier was told "here is the world+ * canon" and handed a list that omitted the entire built world. It then flagged+ * locked faction cards as invented, un-canonized, and "absent from the World+ * Canon" — findings no arc edit can close, because the entity was grounded all+ * along.+ *+ * That is a stall, not a nuisance: the foundation gate's structure arm reverts+ * its whole repair whenever `verifyArc` leaves ANY blocker, so one permanent+ * false positive discards every real fix alongside it. The sibling+ * `pipeline-arc-resolve.md` and `pipeline-volume-verify.md` already render this+ * block — only the arc verifier was blind, which is exactly why the verify/+ * resolve pair could never converge.+ */++import { makePromptReplaceMigration } from './_lib.js';++export const ACCEPTED_OLD_MD5 = {+ 'pipeline-arc-verify.md': ['68f6956d7e09ebdb3870d8726b1b2a7a'],+};++export const NEW_SHIPPED_MD5 = {+ 'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3',+};++const { applyMigration, up } = makePromptReplaceMigration({+ accepted: ACCEPTED_OLD_MD5,+ current: NEW_SHIPPED_MD5,+ label: 'arc-verify world category canon',+ customizedHint: (filename) =>+ ` To upgrade it manually, diff data.reference/prompts/stages/${filename}\n` ++ ` against data/prompts/stages/${filename} and add the world entity category +\n` ++ ` composite blocks plus the rule that category canon is grounded canon.`,+});++export { applyMigration };+export default { up };diff --git a/scripts/migrations/263-arc-verify-world-category-canon.test.js b/scripts/migrations/263-arc-verify-world-category-canon.test.jsnew file mode 100644index 0000000000..ada4e8bd8d--- /dev/null+++ b/scripts/migrations/263-arc-verify-world-category-canon.test.js@@ -0,0 +1,32 @@+import { readFileSync } from 'fs';+import { describe, expect, it } from 'vitest';++import { repoRoot, runPromptMigrationTests } from './_testHelpers.js';+import migration, {+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ applyMigration,+} from './263-arc-verify-world-category-canon.js';++describe('migration 263 — arc-verify world category canon', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ prefix: 'migration-263-arc-verify-world-category-canon-',+ });++ it('renders the category + composite canon the groundedness checks judge against', () => {+ const prompt = readFileSync(+ `${repoRoot}/data.reference/prompts/stages/pipeline-arc-verify.md`,+ 'utf8',+ );+ expect(prompt).toContain('{{worldCategoriesText}}');+ expect(prompt).toContain('{{worldCompositesText}}');+ // The blocks alone are not enough — without this rule the verifier keeps+ // reading "World canon" as the exhaustive list and flags category entities.+ expect(prompt).toContain('established world canon');+ expect(prompt).toContain('check this block before');+ });+});diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.jsindex 695dafbefd..212a5bfc95 100644--- a/scripts/setup-data-drift.test.js+++ b/scripts/setup-data-drift.test.js@@ -31,7 +31,7 @@ const EXPECTED_STAGE_OLD = {'pipeline-teleplay.md': ['1280ef6b1ad68fa44070ca7478ec2a5f', '2568e14beaa574d43f8018a5def51d04', '376f779f4687b598f1c92ca4e770fd5a', '3f6fecc25573ed054b47db392250034a', 'afa4215330bf856429d70d7e2f856605'],'pipeline-season-episodes.md': ['6e349ad26bed8a0ccb042571f03f03eb', 'c4928e2a5f833358116b29d2d669888d', '50c68a29c3ebc275db3095d06bd87100'],'pipeline-arc-overview.md': ['6a3ecab43d1f46b7ef9aab6c69ea0326', 'd34d72b8e49ba303d38607845dd87f1c', '0a1f6ffa6908522e3690c5e9e53a6ee0', '612f8b04950e2ff26dd350dd76a062fe', '74d6c26548660d85fc345b2099c63b6c', '648e11352cd1565aee490de1f662bef0'],- 'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6', '36aa70cdfc25d7549573a4d556e7702c', '83347e7d923580a3062033ab39b3c14b'],+ 'pipeline-arc-verify.md': ['52e31abc93e3105176236fcaa5d1575a', 'ff56d8387162017e08d5d0491060ddd6', '36aa70cdfc25d7549573a4d556e7702c', '83347e7d923580a3062033ab39b3c14b', '68f6956d7e09ebdb3870d8726b1b2a7a'],'pipeline-volume-verify.md': ['03f3c874cb80e1c98abcf03168fa7a92', 'c6ea28e972ad6e229bafb2d602b4dda3'],'pipeline-arc-resolve.md': ['0611db539437083621e19bb88b005e8d', '0787128babf3c4c50e2f2cdb60214030', '5b340885c6e8f8afc63424d6b5bc7eb7', '87bc5c01f1a8a97b681727a38b05edc6', '8bb134554c122d1583c479ab3010e53d', '8e348f3d1894382889f9f0ee7d5c6792', '96f73a7e90526d65ef2bb100fb1cd4bf', 'a8677bbe1eb38f871fb152a5b0fec7c6', 'cc27b4da1d1a13c35e35d1c2d6183815', '31eca76b68f40de1b93734fe9bc9f4bb', '17fbb066d7957dc2e345df1795bb0d9d', 'ebd85d3a0b5949f16877c25ca498cce9'],'pipeline-script-verify.md': ['ed6c8101644cfe56a100eb6bfe3587f3'],@@ -61,7 +61,7 @@ const EXPECTED_STAGE_NEW = {'pipeline-teleplay.md': '2ea9974ac3803658b2314db1f5818b77','pipeline-season-episodes.md': 'a88e8e78a949b7aaf500d03314e2ea0b','pipeline-arc-overview.md': '5ed760caaf3cf88916ec28b220e2f590',- 'pipeline-arc-verify.md': '68f6956d7e09ebdb3870d8726b1b2a7a',+ 'pipeline-arc-verify.md': '9f32e91bd33b97d30e1cbb2e697f4fc3','pipeline-volume-verify.md': '49458d36700cb94e34806d536ffe2940','pipeline-arc-resolve.md': '2349bce80e9df8caafa391a6106327b6','pipeline-script-verify.md': '722c62462d05462603cf67ca0ed1dee8',diff --git a/server/services/pipeline/arcPlanner/context.js b/server/services/pipeline/arcPlanner/context.jsindex 250b4635a1..9d0587b0d2 100644--- a/server/services/pipeline/arcPlanner/context.js+++ b/server/services/pipeline/arcPlanner/context.js@@ -506,6 +506,41 @@ export function groupIssuesBySeasonTree(seasons, issues, { renderLeaf, seasonFiereturn tree;}+// The episode leaf the arc-verify prompt scores. EXPORTED because the prompt's+// checklist and this shape are two independent lists that have to agree, and+// nothing but a test enforces it — a check that names a field the leaf drops+// becomes a finding no resolver can ever close, and the foundation gate's+// structure arm reverts whenever `verifyArc` leaves ANY blocker, so one phantom+// finding stalls the gate forever on a plan with nothing wrong with it. That+// happened once with `arcRole` (check #6 reported "zero pilot/finale" on every+// pass while the data was correct). `verifyPromptContract.test.js` now asserts+// every record field the prompt cites is rendered here.+//+// `synopsis` (not `beats`) matches the prompt's existing language; it is sourced+// from idea.input, which carries the LLM's logline+synopsis.+export const renderVerifyIssueLeaf = (iss) => ({+ number: iss.number,+ title: iss.title,+ status: iss.status,+ arcPosition: iss.arcPosition,+ arcRole: iss.arcRole || null,+ synopsis: (iss.stages?.idea?.input || '').trim() || null,+});++// The volume node the arc-verify prompt scores. Exported for the same contract+// test as `renderVerifyIssueLeaf` — checks #3/#4/#7 read `endingHook`,+// `episodeCountTarget`, and `themes` straight off this shape.+export const renderVerifySeasonFields = (s) => ({+ number: s.number,+ title: s.title,+ logline: s.logline,+ synopsis: s.synopsis,+ endingHook: s.endingHook,+ episodeCountTarget: s.episodeCountTarget,+ themes: s.themes,+ status: s.status,+});+export async function buildVerifyContext(series, preloadedWorld, { spineOnly = false } = {}) {const seasons = sanitizeSeasonList(series.seasons || []);const [issues, base, canon] = await Promise.all([@@ -517,32 +552,8 @@ export async function buildVerifyContext(series, preloadedWorld, { spineOnly = fgetSeriesPlanningCanon(series),]);const tree = groupIssuesBySeasonTree(seasons, issues, {- // `synopsis` key (not `beats`) so it matches the prompt's existing- // language; sourced from idea.input which carries the LLM's logline+synopsis.- // `arcRole` is required, not decorative: the verify prompt's arc-role- // imbalance check (#6) reports "zero pilot/finale" purely from this leaf, so- // omitting it made that finding unsatisfiable — a volume with a correct- // pilot and finale still got flagged, every pass. The foundation gate's- // structure arm reverts whenever verifyArc leaves any blocker, so that one- // permanent false positive stalled the gate on plans with nothing wrong.- renderLeaf: (iss) => ({- number: iss.number,- title: iss.title,- status: iss.status,- arcPosition: iss.arcPosition,- arcRole: iss.arcRole || null,- synopsis: (iss.stages?.idea?.input || '').trim() || null,- }),- seasonFields: (s) => ({- number: s.number,- title: s.title,- logline: s.logline,- synopsis: s.synopsis,- endingHook: s.endingHook,- episodeCountTarget: s.episodeCountTarget,- themes: s.themes,- status: s.status,- }),+ renderLeaf: renderVerifyIssueLeaf,+ seasonFields: renderVerifySeasonFields,});return {...base,diff --git a/server/services/pipeline/arcPlanner/verifyPromptContract.test.js b/server/services/pipeline/arcPlanner/verifyPromptContract.test.jsnew file mode 100644index 0000000000..af2ce4b387--- /dev/null+++ b/server/services/pipeline/arcPlanner/verifyPromptContract.test.js@@ -0,0 +1,109 @@+/**+ * Contract between `pipeline-arc-verify.md` and the context `buildVerifyContext`+ * hands it. The prompt's checklist and the rendered context are two independent+ * lists that must agree, with nothing but this file enforcing it — and a+ * disagreement is not a cosmetic drift. The foundation gate's structure arm+ * reverts its whole repair whenever `verifyArc` leaves ANY blocker, so a check+ * that reads a field the context never renders produces a finding no resolver+ * can close, and the gate stalls forever on a plan with nothing wrong with it.+ *+ * Two instances of that class have shipped:+ * 1. check #6 read each episode's `arcRole`, which the leaf did not render, so+ * every series reported "zero pilot/finale" on every pass;+ * 2. the prompt judged whether an entity was grounded in the world bible while+ * rendering only `worldCanonText` — the named-canon trunks, which stay+ * empty until prose mints entities. A world's actual factions/locations/+ * technology live in `worldCategoriesText`, which the sibling+ * `pipeline-arc-resolve.md` rendered and this prompt did not, so the+ * verifier flagged locked faction cards as "absent from the World Canon"+ * while the resolver could plainly see them.+ *+ * Both directions are covered below: record fields the prompt cites must be+ * renderable, and the verify/resolve pair must see the same world.+ */++import { describe, it, expect } from 'vitest';+import { readFile } from 'fs/promises';+import { join, dirname } from 'path';+import { fileURLToPath } from 'url';++import { renderVerifyIssueLeaf, renderVerifySeasonFields } from './context.js';++const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..');+const shippedPrompt = (name) => join(REPO_ROOT, 'data.reference', 'prompts', 'stages', name);++// Backticked tokens that are deliberately NOT record fields. Anything backticked+// in the prompt that is not here must be renderable — that is the whole point of+// the guard, so extend this list only for genuinely non-field vocabulary.+const NON_FIELD_TOKENS = new Set([+ // Output-contract vocabulary.+ 'issues', 'severity', 'high', 'medium', 'low',+ // `arcRole` VALUES, not field names.+ 'pilot', 'finale', 'complication', 'midpoint', 'b-plot', 'all-is-lost',+]);++const backtickedTokens = (markdown) => {+ const out = new Set();+ for (const match of markdown.matchAll(/`([^`\n]+)`/g)) {+ // Strip the illustrative value a check may attach (`episodeCountTarget: 12`)+ // and the array marker (`issues[]`) so the bare identifier is what's tested.+ const token = match[1].split(':')[0].replace(/\[\]$/, '').trim();+ // Only single identifiers are candidate record fields. JSON blobs, dotted+ // arc paths (`arc.themes` — an arc field, not a leaf/season one), and prose+ // fragments are not.+ if (/^[a-z][A-Za-z0-9]*$/.test(token)) out.add(token);+ }+ return out;+};++const renderableFields = () => new Set([+ ...Object.keys(renderVerifyIssueLeaf({ stages: { idea: { input: 'x' } } })),+ ...Object.keys(renderVerifySeasonFields({})),+]);++describe('pipeline-arc-verify prompt ↔ buildVerifyContext leaf contract', () => {+ it('renders every record field the shipped checklist cites', async () => {+ const markdown = await readFile(shippedPrompt('pipeline-arc-verify.md'), 'utf-8');+ const renderable = renderableFields();+ const unrenderable = [...backtickedTokens(markdown)]+ .filter((token) => !NON_FIELD_TOKENS.has(token) && !renderable.has(token));+ expect(unrenderable).toEqual([]);+ });++ it('fails when a cited field is dropped from the leaf (bypass probe)', () => {+ // Proves the assertion above has teeth: a checklist naming `arcRole` against+ // a leaf that no longer renders it must be caught, not silently pass.+ const citedByPrompt = backtickedTokens('Check the episode `arcRole` balance.');+ const leafWithoutArcRole = new Set(+ Object.keys(renderVerifyIssueLeaf({ stages: {} })).filter((k) => k !== 'arcRole'),+ );+ const unrenderable = [...citedByPrompt]+ .filter((token) => !NON_FIELD_TOKENS.has(token) && !leafWithoutArcRole.has(token));+ expect(unrenderable).toEqual(['arcRole']);+ });+});++describe('pipeline-arc-verify ↔ pipeline-arc-resolve world parity', () => {+ // `buildResolveContext` wraps `buildVerifyContext`, so the pair is fed from one+ // world bag. A world variable the resolver renders but the verifier does not is+ // exactly the asymmetry that manufactures unsatisfiable groundedness findings:+ // the verifier calls a canon entity invented, the resolver can see it is not.+ const worldVars = (markdown) => new Set(+ [...markdown.matchAll(/\{\{\{?(world[A-Za-z0-9]*)\}?\}\}/g)].map((m) => m[1]),+ );++ it('shows the verifier every world block the resolver can see', async () => {+ const [verify, resolve] = await Promise.all([+ readFile(shippedPrompt('pipeline-arc-verify.md'), 'utf-8'),+ readFile(shippedPrompt('pipeline-arc-resolve.md'), 'utf-8'),+ ]);+ const verifyVars = worldVars(verify);+ const missing = [...worldVars(resolve)].filter((v) => !verifyVars.has(v));+ expect(missing).toEqual([]);+ });++ it('renders the category canon the world actually defines', async () => {+ const markdown = await readFile(shippedPrompt('pipeline-arc-verify.md'), 'utf-8');+ expect(markdown).toContain('{{worldCategoriesText}}');+ });+});