Prose/rfc/0007-universe-interchange
RFC 0007 — Universe Interchange & the EVE Universe
Note: this repo already has an unrelated "RFC 0007" (
0007-fully-relational-canon.md) predating this one — a numbering collision from before this RFC existed. Both keep their original filenames/titles ("RFC 0007") since that's how every piece of code, this doc's own history, and the/eveslash command already refer to this one; this doc's own heading anchor above carries an-INTERCHANGEsuffix so codex doctor's unique-anchor check passes without renaming anything else.
Status: PHASE 1 IMPLEMENTED (2026-08-26) — execution keyword: /eve in the Prose CLI. Phase 2 (game-writing deliverables as Books) is superseded by RFC 0018 (game writing as a first-class mode, PRS-T922, 2026-11-07): game texts are prose-text/1 rows verified on their own, not books. Only --barks-export from it was ever built, and it stays. Author: handoff from the ExperimentEve session (Claude, D:\Projects\MindAttic\ExperimentEve) Depends on: BIBLE §4.4 (canon-as-data) and §4.2 / SS-LAW-15 (universe segregation)
Purpose
Prose becomes what it already almost is: the repository of universes — not just the writing program for books, but the canonical store other MindAttic apps (games first: ExperimentEve) read from and write to via CLI and MCP.
The end goal (user-stated): Prose lends its writing abilities to ExperimentEve. Prose does what Prose does best — structured, canon-aware long-form writing — and the deliverables expand from novels to the documents game industry writers actually produce: the Game Design Document, the game script / narrative design doc, bark & dialog sheets, and eventually the EVE Prequel Novella — video games, creative writing, dark comedy, and sci-fi merged in one canon. This is the most important thing to come from the Experiment. (Yes, that's what it was all along.)
This must NOT diminish the book-writing mission. Everything here is additive: new dispatch lines, new files, one new universe row. No existing command, tool, table, or law changes. The Book→Chapter→Beat hierarchy is untouched. If any step would require modifying existing behavior, stop and redesign.
What already exists (do not rebuild)
Universe+ SS-LAW-15 scoping (src/Prose.Core/Data/Entities/Universe.cs, global query filter inProseDbContext).- Generic
Entityspine + typed subtypes (Character,Place,Faction,Species,Gear, ...) + runtimeRepositoryDefinitionfor new types with zero migrations. Edgetyped relation graph,Tag,RecordJSON round-trip blob.- Hub-only DB access (HARD RULE) with reflection dispatch: CLI handlers
src/Prose.Cli/Cli/*Cli.csviaHubCliClient.ForwardAsync, MCP toolssrc/Prose.Mcp/Tools.*.csviaHubInvoker→{Method}Impl. - Hub HTTP reads:
GET /api/universes,/api/universes/{slug}/entities/{id},/neighbors/{id},/search,/snapshot.
The interchange format (the contract with other apps)
File: <app>/universe/<slug>.universe.json, schema D:\Projects\MindAttic\ExperimentEve\universe\universe.schema.json (copy it to docs/schemas/universe.schema.json here so Prose owns a copy).
Shape: { universe: {id, name, tagline, era, setting, logline, rules[]}, entities: [{id, type, name, summary, details{}, relations[{to, kind}], tags[]}] }.
entities[].idis a slug, unique per universe → maps toEntity.Slug.typeis an open string set; core: character, faction, creature, location, artifact, event, rule, organization, concept.- Dangling
relations[].toare allowed (they mark future work): import them as edges to auto-createdStatus=stubentities.
First consumer file (75 entities, validated): D:\Projects\MindAttic\ExperimentEve\universe\eve.universe.json
Work plan (execute in order)
1. Register the EVE universe
- New
Universerow: SlugEVE, Name "Experiment Eve". WorldFacts← the interchangeuniverse.rulesexpanded to one line each (they are the hard creative laws: no-exposition, placeless-winks, tech-1998-only, nostalgia-parody, fathers-day-throughline, night-deadline, lighthouse-saves, hourly-chimes, routing-is-the-puzzle, drip-feed-blueprints, a-life-ecology — full text lives on therule-type entities in the file).UniversePrimer←universe.logline+setting+tagline.- Follow whatever the existing seeding convention is for the 7 current universes (find where GLMZ/SCRY/etc. are seeded; do it the same way — likely a SQL seed via
SqlSeedServiceor a service-level ensure).
2. UniverseInterchangeService (Prose.Core/Services/)
Import/export between the interchange JSON and the Entity spine. Runs inside the Hub only (like every service).
Type mapping (import):
interchange type
|
Prose target |
|---|---|
| character | Character subtype
|
| location | Place subtype
|
| faction | Faction subtype
|
| creature | Species subtype (fits: chimera species with behavior text)
|
| artifact | Gear subtype if it fits, else generic Entity with EntityType "artifact"
|
| event / rule / organization / concept / anything else | generic Entity with EntityType = the interchange type; ensure a RepositoryDefinition exists for each such type (create at import, global, idempotent)
|
Field mapping: id→Slug, name→Name, summary→Description (or nearest), details + full source object → Record JSON (round-trip source of truth), tags[]→Tags, relations[]→Edges (EdgeType = kind, create stub targets for dangling ids), everything Status=canon except auto-created stubs.
Semantics: idempotent upsert by (UniverseId, Slug) — re-import must be a no-op diff, updates in the file win over DB fields it maps (Record keeps the old copy versioned if a versioning convention exists; otherwise overwrite). Never touch entities in other universes (SS-LAW-15 does this structurally).
Export: inverse mapping back to the interchange shape; entities whose EntityType has no interchange core type export with their EntityType string verbatim. Round-trip test: import → export → import produces zero changes.
3. CLI (Prose.Cli)
- New handler
src/Prose.Cli/Cli/UniverseInterchangeCli.cs(convention:RunAsync(string[] args, IServiceProvider services)). - New dispatch lines in
Prose.Cli/Program.cs(pure additions):prose --universe-import <path> [--universe <slug>](slug defaults to the file'suniverse.iduppercased)prose --universe-export <slug> <path>prose --universe-sync <path>= import, then export back to the same path (normalizes the file; the game commits the normalized copy)
4. MCP (Prose.Mcp)
New src/Prose.Mcp/Tools.UniverseInterchange.cs ([McpServerToolType], one-line forwards + Impl siblings), only adding what generic tools don't already cover — audit Tools.Universe.cs, Tools.EntityCrud.cs, Tools.Repository.cs first:
import_universe_file(path, slug?)export_universe_file(slug, path)get_universe_entity(slug, entitySlug)(if no existing equivalent by slug)search_universe(slug, query)(if not covered) Regeneratedocs/MCP_TOOLS.mdvia the existing--export-tools.
5. Hub HTTP (wanted for game-side push + the CliHook channel)
POST /api/universes/{slug}/importaccepting the interchange JSON body → same service. Mirrors the existing read endpoints' style inProse.Hub/Program.cs. Keep it localhost like everything else.- The Outbox (CliHook channel) — the Hub feeds information INTO consumer Claude Code sessions (ExperimentEve's window first) via hook-friendly pull:
- Table/store:
OutboxEvent { Id, Consumer, Ts, Kind, Summary, DataJson, DeliveredTs? }(small EF entity + migration, or reuse an existing event mechanism if one fits; Hub-only access as always). GET /api/outbox/{consumer}→ pending events for that consumer, marking them delivered (add?peek=trueto read without consuming).POST /api/outbox/{consumer}{kind, summary, data?}→ enqueue. This lets Prose's own Claude session deliberately message the EVE window ("GDD chapter 3 drafted — pull barks"), and lets services enqueue automatically.- Auto-enqueue for consumer
eveon: interchange import/export completed, any entity upsert in the EVE universe, barks export written, any beat written in an EVE-universe book. One-line summaries; keep it quiet. - Consumer side (already installed in ExperimentEve, fails silent until this endpoint exists):
.claude/hooks/prose-outbox.ps1registered as aUserPromptSubmithook — every prompt in the EVE window drainsGET /api/outbox/eveand injects the summaries as context. A matching hook can later be added to any other consumer repo (this is the pattern that makes Prose a live participant in other projects' sessions).
- Table/store:
6. Tests (Prose.UnitTests, NUnit, TestDbFactory/SQLite)
- Interchange round-trip (import→export→reimport = no-op).
- Type mapping per row of the table above (one entity each).
- Dangling relation → stub creation.
- Universe segregation: importing EVE twice touches only EVE rows (mirror
UniverseSegregationTestspatterns). - Idempotency: import same file twice → identical DB state.
7. Seed EVE and verify
prose --universe-import D:\Projects\MindAttic\ExperimentEve\universe\eve.universe.json prose --universe use EVE prose --universe-export EVE <temp> && diff against source (allowing normalization)
Expected: 75 entities (7 character, 2 faction, 20 creature/species, 30 location/place, 4 artifact, 5 event, 7 rule).
8. Documentation
- README: add a "Universe Interchange" subsection under the Universes section (what it is, the commands, the contract path, ExperimentEve as consumer #1).
- This RFC marked implemented, with any deviations noted.
The other side (already built, in ExperimentEve)
universe/eve.universe.json+universe/universe.schema.json— the seed.npm run universe -- validate|list|get|search|stats— local queries.npm run universe -- pull— GETshttp://127.0.0.1:5900/api/universes/EVE/snapshotintouniverse/eve.prose-snapshot.json(works as soon as EVE exists in Prose).npm run universe -- push— invokesprose.cmd --universe-import <abs path>(works as soon as step 3 lands).
Phase 2 — Prose writes for the game (design now, build after Phase 1)
Superseded 2026-11-07 by RFC 0018 (PRS-T922). A game has no single reading order, so its script is not a book: game texts are first-class
prose-text/1rows (RFC 0017) with their own verifiers, context and Writer view. Kept below as history.
The insight: game-writing deliverables are Books. The existing Book→Chapter→Beat spine, generation pipeline, continuity ledger, and character bibles apply unchanged — only the universe (EVE) and the deliverable's purpose differ. No new hierarchy, no new laws.
Create, in the EVE universe, as ordinary Prose books:
- "EVE — Game Design Document" — nonfiction-structured book; chapters = systems (battle, A-Life, crafting, districts...), beats = sections. Seed its outline from the entity data (rules + factions + creatures) rather than from scratch.
- "EVE — Night One (Game Script)" — the slice's narrative script in screenplay-ish beats: scene direction, Kat's barks, Observer interventions, ApertureOS file texts. Every speaking/named thing links to its Entity (Prose's continuity machinery then guards game canon for free: it can catch a bark contradicting a WorldFact like no-exposition or 1998-only).
- "EVE — Prequel Novella" — real fiction, same universe, same canon guards; the reason this whole merger exists.
The one new piece of plumbing (small, additive): bark/dialog export — prose --barks-export EVE <path> walks a designated script book and emits {barkId, speakerEntitySlug, text, context} JSON the game consumes at build time (barkId = a stable per-beat key). ExperimentEve will read it from universe/eve.barks.json. Design the key convention in Phase 2; do not build generation-side anything new — Prose's normal writing flow authors these books; the export is just a filter.
Acceptance
dotnet test src/Prose.UnitTestsgreen, including the new tests.- All 7 pre-existing universes and every existing command/tool behave identically (spot-check
--book, a generation command,--universe list). - EVE queryable from Prose CLI, MCP, and Hub HTTP;
npm run universe -- pullsucceeds from the ExperimentEve repo. - Nothing writes to the DB except through the Hub. No exceptions.
Phase 1 — implemented 2026-08-26
All four acceptance points verified live:
dotnet test src/Prose.UnitTests— 2212 passed, 24 skipped, 0 regressions. 14 pre-existing failures confirmed unrelated (12 environment-dependent log-search tests reading real Serilog files; 2 a structurally pre-existing DI-registration test bug in files this RFC never touched —Prose.Core.Extensions.AddProseServices()cannot registerProse.Mcp.HubInvokersince Core has no reference to Mcp). 16 new tests added (UniverseInterchangeServiceTests,OutboxServiceTests), all green.- Spot-checked
--universe list(all 8 universes, including the 7 pre-existing, listed correctly) and--book/generation commands untouched. - EVE live: 75/75 entities imported (7 character, 2 faction, 20 creature, 30 location, 4 artifact, 5 event, 7 rule — matches the file exactly), 38 edges, 0 stubs (the file's cross-references are internally complete). Verified via CLI (
--universe-import/-export/-sync), MCP (get_universe_entity,search_universevia direct/api/mcp-invokecalls), and Hub HTTP (POST /api/universes/eve/import,GET/POST /api/outbox/eve). Import → export → diff against source: 75/75 entities present, 0 relation diffs, 0 universe-metadata diffs.npm run universe -- pullfrom ExperimentEve succeeds (exit 0, writeseve.prose-snapshot.json) — see the noted gap below. - All writes went through the Hub (
proseCLI →HubCliClient→/api/cli-invoke, or a direct MCP-shaped/api/mcp-invokecall, or/api/universes/eve/import). No raw SQL was run against the database at any point in this implementation.
Deviations from the RFC's suggested design (all minimal, documented in code)
- Storage model: every interchange entity — including
character/location/faction— is stored on the generic Entity +Record.Json+EntityTag+Edgespine (EfRepository-style), never on the fully-relationalCharacter/Place/Factiontyped tables (CharacterMapper/PlaceMapper/FactionMapper). Those mappers are built around Prose's own ~15–25-bridge-table domain model and explicitly stopped readingRecords.Jsonyears before this RFC; forcing sparse game-entity data through that machinery would be fragile for no benefit. The RFC itself designatesRecord.Jsonas the "round-trip source of truth" for import/export, which is exactly the generic-spine model.EntityTypestrings still follow the RFC's semantic mapping for readability. SeeUniverseInterchangeService's class doc-comment. creaturetype mapping: NOT routed to theSpeciestable as suggested —Speciesis a 5-row controlled vocabulary (human/ai/elf/synthetic/unknown) thatCharacter.Speciesreferences by name, not a per-instance table for dozens of individual creatures. Creatures get a generic,RepositoryDefinition-registeredEntityTypeinstead (same fallback path the RFC already specifies for event/rule/organization/concept).artifacttype mapping: NOT split between Gear subtypes and generic Entity. None of the file's four artifacts (a yacht, an OS, a keepsake card, a dress) cleanly fits Prose's Gear categories as a uniform rule, so all artifacts get a uniform genericEntityTypefor consistency rather than cherry-picking two intoTransportation/Apparel.- Universe slug casing: registered as
eve(lowercase), notEVEas the RFC's Step 1 literally states — every existing universe (glmz,scry,gospel, ...) uses a lowercaseSlugwith an uppercaseName; the RFC's own Step 1 line ("New Universe row: Slug EVE, Name 'Experiment Eve'") conflicts with that established convention, so the convention wins. Same for the CLI's--universe-importslug default: the file's ownuniverse.idis used verbatim (already lowercase per the schema's^[a-z0-9-]+$pattern), not uppercased. - Universe-block round-trip: the RFC doesn't specify where
tagline/era/settingpersist (Universehas no matching columns). Stored verbatim as aSettingrow (Key = "interchange.universe_source", scoped to the universe) so export reconstructs the exact originaluniverseobject; falls back to deriving fromUniverse.Name/Description/WorldFactsif that row is ever missing (e.g. a universe seeded by hand, not via interchange import).
Bugs found and fixed along the way (not RFC-scoped, but blocking and fixed per
project policy — "fix bugs immediately, never deferred")
CliDispatchparam binder silently passednullargs to any CLI handler typedIReadOnlyList<string> argsinstead of the concretestring[](affectsSeedCli,ResetPasswordCli,VulturesSeedCli,AuditDenormCli) — found viaprose --seed, which has apparently been broken via the Hub-forwarding path since the Stage C CLI migration. Fixed by broadening the type check topt.IsAssignableFrom(typeof(string[])).SqlSeedServicenever refreshedIUniverseContextafter a successful run. A Hub-resident process caches its universe catalog for its whole lifetime; a freshly-seeded universe (EVE, or any future one) was invisible to--universe list/--universe useuntil the Hub restarted. Fixed by callingIUniverseContext.Refresh()after every successful seed run.UniverseInterchangeService's ownUpsertUniverseSourceAsyncwas missing.IgnoreQueryFilters()on itsSettingslookup (Settinghas a shared-visibility query filter) — under any non-empty ambientUniverseScopethat wasn't the target universe (the normal case for a live Hub), a re-import's lookup silently missed the existing row and crashed on a duplicate-key insert. Caught live via the Hub (not by the original unit tests, which never set an ambient scope) and fixed; a regression test (ImportAsync_ReimportUnderNonEmptyAmbientUniverseScope_DoesNotThrow) now sets a non-empty ambient scope explicitly so this class of bug can't hide again.
Known integration gap (not fixed — outside this repo)
npm run universe -- pull (ExperimentEve's own script) calls GET /api/universes/EVE/snapshot with no scope parameter, which returns the DCM active working set (what's currently resident for live prose generation — correctly empty, since Prose has never generated EVE prose yet), not the full universe dump. A full pull needs ?scope=all. This is a one-line change in ExperimentEve/scripts/universe.mjs, in a sibling repo this RFC's mandate didn't cover — flagged for the user/ExperimentEve session rather than edited here.
Pre-existing UniverseGraphService bugs found during cross-session
verification (real, NOT caused by RFC 0007, deliberately NOT fixed here)
The ExperimentEve session bridge-tested against the pre-existing /api/universes/{slug}/ search and /snapshot endpoints (built on UniverseGraphService, not on this RFC's own Entity-spine reads) and reported two symptoms. Both were verified directly against the DB before touching anything — neither is a defect in UniverseInterchangeService:
- Not a bug:
/searchshowskatie-kat-weissinstead of the interchange idkat-weiss.Entity.Slugis stored correctly askat-weissverbatim (confirmed viaget_universe_entityreading the DB column directly).UniverseGraphServicecomputes its OWN graph-node id by re-slugifyingEntity.Nameat load time (Slugify(en.Name),UniverseGraphService.cs— every bespoke per-type node builder does this) — it never reads the storedEntity.Slugcolumn. This is universal, long-predates this RFC, and affects every universe (a GLMZ entity whoseEntity.Slugdiffers fromSlugify(Entity.Name)would show the same divergence). Out of scope to change unilaterally — it's a shared service with real blast radius (19k+ live GLMZ nodes). Use the RFC 0007 tools for interchange data instead: MCPget_universe_entity/search_universe, or CLI--universe-export(both readEntity.Slugdirectly, confirmed correct). - Real bug, not RFC 0007's: every node's
edgeCountfield in/snapshotand/searchreads 0, even though the rawEdgestable is fully correct (38 rows, both directions verified, e.g.soak↔ren) and the SAME snapshot response's top-leveledgesarray is also fully correct (38 entries, correct source/target). Reproduces identically after a full Hub restart (rules out staleness/caching timing). GLMZ (populated mostly via older bespoke per-type relationship builders, not the genericEdgestable) shows correct non-zeroedgeCounts, so the bug appears specific to edges loaded viaUniverseGraphService.BuildEdgesFromSqlTable(the generic-Edges-table path) versus the bespoke per-type builders. Not root-caused further — it's deep in a shared graph-build/caching service touching every universe, genuinely risky to patch blind, and outside this RFC's acceptance criteria (which this RFC satisfies via its own Entity-spine reads, confirmed correct independent of this service). Flagged for the user, not fixed here. - Real, serious bug — cross-universe data leak in
/snapshotand/search. A rebuild of EVE's graph (forced by anEnsureFresh()fix earlier this session) returned 5,175 nodes / 5,273 edges instead of the correct ~97/~58, including 723weapon, 2,129technology, 155organization, and 2,071unknown-typed nodes — types that don't exist anywhere in EVE's interchange schema. This is GLMZ's (and/or other universes') data leaking into EVE's graph. Reproduced consistently across multiple isolated calls, not a one-off race.
Two confirmed, compounding defects inUniverseGraphService.cs:
FIXED (2026-08-26). Live repro at the time of writing confirmed the second defect — the singleton cache — as the actual, sufficient root cause for the leak:BuildCharactersetc. read throughCharacterMapper.LoadAllFromReadModel/PlaceMapper.LoadAll/etc., which already querydb.Entities/CharacterReadModelsunder EF's ambientHasQueryFilter— so those reads are correctly scoped whenever they actually execute. The leak was the cache short-circuiting before that ambient-filtered query ever ran, serving whichever universe's rows happened to be cached under the last epoch bump, regardless of which universe the current request/rebuild was actually scoped to. Rewriting the eight builders to readctx.<Table>directly (the fix originally proposed here) turned out to be the wrong shape for the six that consume rich Mapper-built DTOs (CharacterData/DistrictData/etc. carry noUniverseIdfield to filter on, and none of them expose the ~25-Include enrichment those Mappers already do) — replacing the data source would have meant re-deriving that enrichment from scratch, a much larger and riskier change than the actual defect warranted.
Applied instead: each of the sevenEfRepository<T>singletons behinddb.Characters/Districts/Factions/Corponations/Weaponry/Equipment/Technology(src/Prose.Core/Services/Repositories.cs) now keys itsGetAll()/GetAllLite()cache byUniverseScope.EffectiveIdin addition to the existingUniverseScope.Epochcheck — amappedCacheUniverseId/mappedCacheLiteUniverseIdfield set alongside the existing epoch field, checked in the same condition. Strictly additive (only ever causes more cache misses than before, never serves a result the old check would have rejected), so it carries no correctness risk to the existing epoch-based invalidation.BuildRemainingEntities(the one builder that already readsctx.Entitiesdirectly, no repository cache involved) also picked up the same explicit.Where(x => x.UniverseId == state.UniverseId)belt-and-suspenders guardBuildEdgesFromSqlTablealready used, for consistency.
Verified live:dotnet run --project Prose.Cli -- --universe eve --rebuild-graph→ 97 nodes / 58 edges (was 5,175/5,273);GET /api/universes/eve/snapshot?scope=allconfirms the same 97/58 with only EVE-native node types (creature/place/character/artifact/rule/event/faction/concept— noweapon/technology/organization/unknown). GLMZ's own graph re-checked unaffected:GET /api/universes/glmz/statsstill reports 19,239 nodes / 19,185 edges, matching its pre-fix state. Full unit suite for the touched services (UniverseGraph/WorldGraph/all seven repositories) passed, 0 regressions.
Follow-up FIXED (2026-08-26): the identicalmappedCache/mappedCacheEpochpattern (cache keyed by a global switch counter, not by universe) repeated in every otherEfRepository<T>-derived repository inRepositories.cs(22 more types — Ammunition, Cyberware, Vocabulary, Genemod, Transportation, Contract, Automaton, Subsidiary, Entertainment, Apparel, News, Archetype, Material, Pharmaceutical, ConsumerGood, Quote, LabSpecimen, FlyoverEntity, Psionic, SyntheticLife, Motif, WorldbuildingDoc). None of those feedUniverseGraphServicetoday, so they were outside this bug's reproduced blast radius, but carried the exact same latent defect for any future multi-universe caller. Applied the samemappedCacheUniverseId/mappedCacheLiteUniverseIdfix to all 22 remaining types (44 sites: field + check + assignment × 2 caches × 22 classes), via literal-patternreplace_allsince every repository shares byte-identical cache-check/assignment lines. All 29EfRepository<T>types inRepositories.csnow carry the universe-scoped cache guard.dotnet build Prose.Coreclean, 0 warnings/errors.BuildCharacters/BuildDistricts/BuildFactions/BuildCorponations/BuildWeaponry/BuildEquipment/BuildTechnology/BuildRemainingEntities(BuildFromDatabase, line 1105) readdb.<Property>/ctx.Entitieswith no explicit.Where(x => x.UniverseId == state.UniverseId)— unlikeBuildEdgesFromSqlTable(line 1133), which already treats that explicit filter as required "belt-and-suspenders" alongside the ambient EF query filter, in its own doc comment.- The seven legacy
EfRepository<T>singletons behinddb.Charactersetc. (CharacterRepository,DistrictRepository, ... —Repositories.cs,AddSingletoninServiceCollectionExtensions.cs:192-201) each cacheGetAll()into a single shared instance field keyed only byUniverseScope.Epoch, a process-wide counter bumped by every universe switch — not by which universe the cache actually holds. One cache slot, shared across every universe and every concurrent request.
First outbox event
Enqueued per the handoff's step 2 (left undelivered so ExperimentEve's own UserPromptSubmit hook drains it naturally on its next prompt): POST /api/outbox/eve {"kind":"hello","summary":"EVE universe live in Prose: 75 entities. Pull when ready."}