From 94c1362b5edb7741b4b06adaf8848d28d4e6327c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 23:38:09 +0100 Subject: [PATCH] Era at genesis: WorldEra pinned write-once on CreateWorld, WorldSnapshot::guidance() read by every prompt lane, vault era tables with withheld lore The kernel owns a world's era as genesis-only state (no CommandBody carries one); every lane's domain guidance is guidance() (era line, then the brief). Each production vault declares its eras and default in vault.rs; VaultEvidenceSource::from_snapshot takes withheld paths. Seam with the elaboration library: render_brief now renders guidance(), and EvidenceQuery.referents is pub so the Dungeon's tests can query evidence. Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight/src/controllers.rs | 40 ++++- crates/ghostlight/src/elaboration.rs | 12 +- crates/ghostlight/src/journal.rs | 3 + crates/ghostlight/src/lens.rs | 2 +- crates/ghostlight/src/lib.rs | 97 +++++++++- crates/ghostlight/src/mailbox.rs | 3 + crates/ghostlight/src/table.rs | 2 +- crates/ghostlight/src/vault.rs | 166 +++++++++++++++++- crates/ghostlight/src/verse/genesis.rs | 1 + crates/ghostlight/src/verse/genesis/tests.rs | 1 + crates/ghostlight/tests/external_admission.rs | 1 + 11 files changed, 306 insertions(+), 22 deletions(-) diff --git a/crates/ghostlight/src/controllers.rs b/crates/ghostlight/src/controllers.rs index b855d3d..90f65f0 100644 --- a/crates/ghostlight/src/controllers.rs +++ b/crates/ghostlight/src/controllers.rs @@ -3407,7 +3407,7 @@ impl ControllerRunner { typed_view: &typed_view, available_tools: &catalog_signatures("", &selected.granted), decision_pressure: "Choose whether this decision owner should speak now.", - domain_guidance: &selected.snapshot.brief, + domain_guidance: &selected.snapshot.guidance(), step_budget: TOOL_STEP_BUDGET, }); let initial_conversation = @@ -3713,12 +3713,11 @@ impl ControllerRunner { tool_signatures: &view.tool_signatures, }) .collect(); + let guidance = selected.first().map(|first| first.snapshot.guidance()).unwrap_or_default(); let agent_prompt = build_grouped_agent_prompt(&GroupedAgentPrompt { views: &labeled, decision_pressure: "Choose whether each decision owner should act now.", - domain_guidance: selected - .first() - .map_or("", |first| first.snapshot.brief.as_str()), + domain_guidance: &guidance, step_budget: CELL_TOOL_STEP_BUDGET, }); let initial_conversation = match evaluate_grouped_loop(&agent_prompt, &constituents, &[])? { @@ -6716,7 +6715,7 @@ fn build_projector_invocation( let typed_view = selected.typed_view()?; let projector_context = selected.projector_context()?; let visible_stimulus = selected.visible_stimulus()?; - let guidance = selected.snapshot.brief.clone(); + let guidance = selected.snapshot.guidance(); let projector_prompt = build_projector_prompt(&ProjectorPrompt { identity: &identity, typed_context: &projector_context, @@ -8261,6 +8260,7 @@ mod tests { }; let snapshot = WorldSnapshot { grammar: None, + era: None, lens_weights: crate::tests::stock_weights(), world_id: opportunity.world_id, revision: opportunity.revision, @@ -8385,6 +8385,7 @@ mod tests { }; let snapshot = WorldSnapshot { grammar: None, + era: None, lens_weights: crate::tests::stock_weights(), world_id: opportunity.world_id, revision: opportunity.revision, @@ -8654,6 +8655,11 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: Some(crate::WorldEra { + id: "late-sol".into(), + label: "Late Sol".into(), + description: "The collapse of the old institutions.".into(), + }), }, &authenticated, ) @@ -8812,6 +8818,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) @@ -9209,6 +9216,13 @@ mod tests { let persona_request = &prepared[1]; assert_eq!(persona_request.provider.input.len(), 1); let persona_text = request_text(persona_request); + for lane in [&prepared[0], persona_request] { + let text = request_text(lane); + assert!( + text.contains("Era: Late Sol. The collapse of the old institutions.\nSpeak plainly."), + "a lane's domain guidance starts with the world's era, then its brief" + ); + } let selected = select_one(&snapshot, &opportunity).unwrap(); let subject_id = encoded_id(&mara).unwrap(); @@ -9239,7 +9253,7 @@ mod tests { let expected = build_persona_prompt(&PersonaPrompt { identity: &selected.persona_identity(), lived_stream: projector_prose, - domain_guidance: &selected.snapshot.brief, + domain_guidance: &selected.snapshot.guidance(), word_budget: PERSONA_WORD_BUDGET, }); assert_eq!(persona_text, expected); @@ -10055,6 +10069,7 @@ mod tests { }; let snapshot = WorldSnapshot { grammar: None, + era: None, lens_weights: crate::tests::stock_weights(), world_id: opportunity.world_id, revision: opportunity.revision, @@ -10220,6 +10235,7 @@ mod tests { }; let snapshot = WorldSnapshot { grammar: None, + era: None, lens_weights: crate::tests::stock_weights(), world_id: opportunity.world_id, revision: opportunity.revision, @@ -10724,6 +10740,7 @@ mod tests { }; let snapshot = WorldSnapshot { grammar: None, + era: None, lens_weights: crate::tests::stock_weights(), world_id: opportunity.world_id, revision: opportunity.revision, @@ -11766,6 +11783,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) @@ -12393,6 +12411,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &owner_caller, ) @@ -12917,6 +12936,7 @@ mod tests { }, }, grammar: None, + era: None, }, &authenticated, ) @@ -14623,6 +14643,7 @@ mod tests { }, scale_intent, grammar: None, + era: None, }, &authenticated, ) @@ -15611,6 +15632,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) @@ -16395,6 +16417,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) @@ -16867,6 +16890,7 @@ mod tests { jurisdictions: BTreeMap::from([(DraftHandle::new("sere"), 1000)]), }, grammar: None, + era: None, }, &authenticated, ) @@ -17584,6 +17608,7 @@ mod tests { .create( CreateWorldIntent { lens_weights: crate::tests::stock_weights(), + era: None, id: CommandId::new(), title: "The Whole Road".into(), brief: String::new(), @@ -17784,6 +17809,7 @@ mod tests { }, scale_intent: intent, grammar: None, + era: None, }; let (mailbox, task) = WorldMailbox::open(directory.path().join("two-roots.cc")).unwrap(); @@ -19303,6 +19329,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) @@ -19833,6 +19860,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) diff --git a/crates/ghostlight/src/elaboration.rs b/crates/ghostlight/src/elaboration.rs index e969f74..bab0ebb 100644 --- a/crates/ghostlight/src/elaboration.rs +++ b/crates/ghostlight/src/elaboration.rs @@ -301,7 +301,7 @@ pub struct EvidenceError { /// The referents the answer names, as world labels. #[derive(Clone, Debug, PartialEq, Eq)] pub struct EvidenceQuery { - pub(crate) referents: Vec, + pub referents: Vec, } #[derive(Clone, Debug, PartialEq, Eq)] @@ -1068,13 +1068,15 @@ fn render_refusal(mismatches: &[Mismatch]) -> String { text } -/// The world's own premise, when it has one. The seed session's optional -/// sentence rides beside it; the two are not the same thing. +/// The world's own guidance, when it has any: its era and its premise. The +/// seed session's optional sentence rides beside it; the two are not the same +/// thing. fn render_brief(snapshot: &WorldSnapshot) -> String { - if snapshot.brief.is_empty() { + let guidance = snapshot.guidance(); + if guidance.is_empty() { String::new() } else { - format!("Brief: {}\n", snapshot.brief) + format!("World guidance:\n{guidance}\n") } } diff --git a/crates/ghostlight/src/journal.rs b/crates/ghostlight/src/journal.rs index a2d36fb..79a7bf4 100644 --- a/crates/ghostlight/src/journal.rs +++ b/crates/ghostlight/src/journal.rs @@ -1127,6 +1127,7 @@ mod tests { }), scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }; let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap(); let snapshot = kernel.snapshot().unwrap(); @@ -1212,6 +1213,7 @@ mod tests { }), scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }; let (mut kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap(); let snapshot = kernel.snapshot().unwrap(); @@ -1780,6 +1782,7 @@ mod tests { }), scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }; let (kernel, _) = WorldKernel::create(&path, creation, &authenticated).unwrap(); let mut forged_head = kernel.state.clone(); diff --git a/crates/ghostlight/src/lens.rs b/crates/ghostlight/src/lens.rs index c14de9d..9f5bf91 100644 --- a/crates/ghostlight/src/lens.rs +++ b/crates/ghostlight/src/lens.rs @@ -52,7 +52,7 @@ impl Lens { } /// What kind of structure the lens reaches for. - pub(crate) fn reaches_for(self) -> &'static str { + pub fn reaches_for(self) -> &'static str { match self { Lens::Patina => "ordinary objects, customs, nicknames, local jokes", Lens::Charter => "government, law, offices, selection, succession, redress", diff --git a/crates/ghostlight/src/lib.rs b/crates/ghostlight/src/lib.rs index bc45a01..2af17b6 100644 --- a/crates/ghostlight/src/lib.rs +++ b/crates/ghostlight/src/lib.rs @@ -145,7 +145,7 @@ pub use table::{ }; pub use vault::{ ImportOutcome, SnapshotId, VAULT_PROFILE_SCHEMA, VAULT_SNAPSHOT_SCHEMA, VaultError, - VaultEvidenceSource, VaultProfile, VaultSnapshot, production_profile, production_vault_names, + VaultEra, VaultEvidenceSource, VaultProfile, VaultSnapshot, production_eras, production_profile, production_vault_names, }; pub use verse::{ CALL_RECORD_SCHEMA, CallRecordError, CallRecordStore, CreateVerseWorldIntent, ProviderCallRecord, @@ -453,6 +453,20 @@ struct CreateWorld { /// open-catalog world. Authored here and nowhere else: genesis installs it. #[serde(default, skip_serializing_if = "Option::is_none")] grammar: Option, + /// The era the world is pinned to, authored here and nowhere else: no + /// `CommandBody` carries a `WorldEra`, so it is write-once by command + /// shape, as `scale_intent` is. + #[serde(default, skip_serializing_if = "Option::is_none")] + era: Option, +} + +/// The period of its lore a world is set in. Authored at genesis by the +/// consumer that knows what periods its lore has, and never replaced. +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct WorldEra { + pub id: String, + pub label: String, + pub description: String, } /// Unattributed creation intent. World ingress derives ownership, controller @@ -477,6 +491,9 @@ pub struct CreateWorldIntent { /// Required. The library holds no default weights; a consumer states the /// world's flavor or is refused. pub lens_weights: LensWeights, + /// The era the world is set in, or none. Pinned at genesis and never + /// replaced. + pub era: Option, } /// One jurisdiction root as ingress states it. The handle is a string here and @@ -865,6 +882,10 @@ struct WorldState { /// grammars existed. #[serde(default, skip_serializing_if = "Option::is_none")] grammar: Option, + /// Pinned by genesis and never written again; absent from a world with no + /// era, whose state and digests are what they were before eras existed. + #[serde(default, skip_serializing_if = "Option::is_none")] + era: Option, draft_approvals: BTreeSet, subjects: BTreeMap, entities: BTreeMap, @@ -1239,6 +1260,8 @@ pub struct WorldSnapshot { pub owner: PrincipalId, pub title: String, pub brief: String, + /// The era the world was pinned to at genesis; none for a world with no era. + pub era: Option, /// The bound grammar's identity; none for a world with an open catalog. pub grammar: Option, pub draft_approvals: BTreeSet, @@ -1272,6 +1295,20 @@ pub struct WorldSnapshot { pub last_commit_digest: Option, } +impl WorldSnapshot { + /// What every lane reads as the world's guidance: the era line, then the + /// owner's brief verbatim, either omitted when empty. Derived on every + /// read; no prompt reads `brief` directly. + pub fn guidance(&self) -> String { + let era = self + .era + .as_ref() + .map(|era| format!("Era: {}. {}", era.label, era.description)); + let brief = (!self.brief.is_empty()).then(|| self.brief.clone()); + [era, brief].into_iter().flatten().collect::>().join("\n") + } +} + /// One committed act as the human operator's story feed reads it. It is the /// operator surface, not a perception surface: no subject-facing lane receives /// it, and `SelectedDecision` never sees an event log at all. @@ -1480,6 +1517,13 @@ fn prepare_creation( } let title = normalize_title(&input.title)?; let brief = input.brief.trim().to_owned(); + if input + .era + .as_ref() + .is_some_and(|era| [&era.id, &era.label, &era.description].iter().any(|text| text.trim().is_empty())) + { + return Err(KernelError::Invariant("a world era states an id, a label and a description".into())); + } // The world's own identity is not world structure, and it feeds every // derived ID, so it is minted before resolution rather than by it. let world_id = WorldId::issue(); @@ -2011,6 +2055,7 @@ impl WorldState { title, brief: String::new(), grammar, + era: None, draft_approvals: BTreeSet::new(), subjects: BTreeMap::new(), entities: BTreeMap::new(), @@ -2070,6 +2115,7 @@ impl WorldState { // equality replace a field-by-field binding zip. let mut state = Self::empty(world_id, owner.clone(), title.clone(), command.grammar.clone()); state.brief = brief.clone(); + state.era = command.era.clone(); let expected = patch::resolve_patch( &state, command.id, @@ -4247,6 +4293,7 @@ fn snapshot(state: &WorldState) -> Result { owner: state.owner.clone(), title: state.title.clone(), brief: state.brief.clone(), + era: state.era.clone(), grammar: state.grammar.as_ref().map(GrammarBinding::identity), draft_approvals: state.draft_approvals.clone(), required_approvers: required_approvers(state), @@ -5722,6 +5769,7 @@ mod tests { scale_intent: WorldScaleIntentRef::default(), lens_weights: stock_weights(), grammar: None, + era: None, } } @@ -15250,6 +15298,53 @@ mod clock_tests { assert_eq!(replayed.state.state_digest, created.state_digest); } + fn late_sol() -> WorldEra { + WorldEra { id: "late-sol".into(), label: "Late Sol".into(), description: "The old order fails.".into() } + } + + /// Genesis pins the era, replay restores it, and the only command that + /// can touch a world's flavor afterward leaves it alone: no `CommandBody` + /// carries a `WorldEra`. + #[test] + fn genesis_pins_the_era_and_nothing_replaces_it() { + let directory = tempfile::tempdir().unwrap(); + let path = directory.path().join("world.cc"); + let mut input = creation(CommandId::new(), "Pinned"); + input.era = Some(late_sol()); + let (kernel, _) = WorldKernel::create(&path, input, &auth_principal(owner())).unwrap(); + let created = kernel.snapshot().unwrap(); + assert_eq!(created.era, Some(late_sol())); + let world_id = created.world_id; + drop(kernel); + let replayed = WorldKernel::open(&path, world_id).unwrap(); + assert_eq!(replayed.snapshot().unwrap().era, Some(late_sol())); + assert_eq!(replayed.state.state_digest, created.state_digest); + + let mut blank = creation(CommandId::new(), "Blank Era"); + blank.era = Some(WorldEra { description: " ".into(), ..late_sol() }); + let refused = WorldKernel::create(&directory.path().join("blank.cc"), blank, &auth_principal(owner())); + assert!(matches!(refused, Err(KernelError::Invariant(_)))); + } + + /// Every lane reads this string: era first, then the brief verbatim, + /// either omitted when empty; nothing at all when both are. + #[test] + fn guidance_is_the_era_then_the_brief_and_empty_when_neither() { + let directory = tempfile::tempdir().unwrap(); + let mut snapshots = Vec::new(); + for (name, era, brief) in [("a", Some(late_sol()), "Speak plainly."), ("b", Some(late_sol()), ""), ("c", None, "Speak plainly."), ("d", None, "")] { + let mut input = creation(CommandId::new(), name); + input.era = era; + input.brief = brief.into(); + let (kernel, _) = WorldKernel::create(&directory.path().join(format!("{name}.cc")), input, &auth_principal(owner())).unwrap(); + snapshots.push(kernel.snapshot().unwrap().guidance()); + } + assert_eq!( + snapshots, + ["Era: Late Sol. The old order fails.\nSpeak plainly.", "Era: Late Sol. The old order fails.", "Speak plainly.", ""] + ); + } + #[test] fn a_genesis_lens_set_that_never_draws_is_refused() { let directory = tempfile::tempdir().unwrap(); diff --git a/crates/ghostlight/src/mailbox.rs b/crates/ghostlight/src/mailbox.rs index c9b232b..6fb7f89 100644 --- a/crates/ghostlight/src/mailbox.rs +++ b/crates/ghostlight/src/mailbox.rs @@ -212,6 +212,7 @@ impl WorldMailbox { scale_intent, lens_weights: input.lens_weights, grammar: None, + era: input.era, }, AuthenticatedCaller::verified_principal(principal_id), ) @@ -1083,6 +1084,7 @@ mod tests { CreateWorld { lens_weights: crate::tests::stock_weights(), grammar: None, + era: None, id, owner: PrincipalId::new("owner"), title: title.into(), @@ -1523,6 +1525,7 @@ mod tests { }, scale_intent: WorldScaleIntentRef::default(), grammar: None, + era: None, }, &authenticated, ) diff --git a/crates/ghostlight/src/table.rs b/crates/ghostlight/src/table.rs index 1eccbb5..0b34677 100644 --- a/crates/ghostlight/src/table.rs +++ b/crates/ghostlight/src/table.rs @@ -1591,7 +1591,7 @@ pub fn table_view(snapshot: &WorldSnapshot) -> String { "\n Clock: the world reads {} fictional minutes.", snapshot.now.0 )); - out.push_str(&format!("\n Brief: {}\n", snapshot.brief)); + out.push_str(&format!("\n Guidance: {}\n", snapshot.guidance().replace('\n', " "))); out } diff --git a/crates/ghostlight/src/vault.rs b/crates/ghostlight/src/vault.rs index 0ed5d20..9d662ec 100644 --- a/crates/ghostlight/src/vault.rs +++ b/crates/ghostlight/src/vault.rs @@ -108,6 +108,25 @@ struct ProductionVault { name: &'static str, root: &'static str, exclude: &'static [&'static str], + /// The periods of its lore a world may be set in, and which one a Begin + /// that names none gets. Not part of the profile, so a snapshot id does + /// not depend on it. + eras: &'static [VaultEra], + default_era: &'static str, +} + +/// One period of a vault's lore. `withhold` lists vault-relative paths whose +/// notes are not evidence for a world set in this era. +#[derive(Debug)] +pub struct VaultEra { + pub id: &'static str, + pub label: &'static str, + pub description: &'static str, + pub withhold: &'static [&'static str], +} + +const fn era(id: &'static str, label: &'static str, description: &'static str) -> VaultEra { + VaultEra { id, label, description, withhold: &[] } } const PRODUCTION_VAULTS: [ProductionVault; 4] = [ @@ -123,6 +142,23 @@ const PRODUCTION_VAULTS: [ProductionVault; 4] = [ "Stories/*/Coordinator Strategy.md", "Stories/*/Branch Map.md", ], + // The vault splits its own lore by folder. Pre-Elysium is the default + // (question aetheria-pre-elysium-pin: late Sol); the pin is this one + // string. + default_era: "pre-elysium", + eras: &[ + VaultEra { + id: "pre-elysium", + label: "Pre-Elysium", + description: "Late Sol, the Existential Collapse (2750-3025): aging infrastructure and institutions fail, wireheading is an industry, uploaded and uplifted minds hold unequal standing, powers fight over who survives; no FTL, no Elysium, no aether.", + withhold: &["Worldbuilding/Post-Elysium"], + }, + era( + "post-elysium", + "Post-Elysium", + "After the Rupture: Sol's civilization displaced into Elysium, a sealed hostile domain; aether, espers, pseudospace, necrotech and spirits exist; old political habits survive with sharper tools.", + ), + ], }, // Eusocial Interbeing is the Zyphos setting (ruling vault-profile-zyphos); // the Zyphos repository around it is machinery. @@ -130,19 +166,80 @@ const PRODUCTION_VAULTS: [ProductionVault; 4] = [ name: "zyphos", root: "Zyphos/Eusocial Interbeing", exclude: &["Game Design", "Inspirations"], + // The vault states no timeline: one present-day era. + default_era: "imperial-present", + eras: &[era( + "imperial-present", + "The Airawa Empire", + "The Airawa Empire rules a quarter of a continent through the Biological Memetic Engine; native nations resist; the Sa'ueia are nomads on another continent.", + )], }, ProductionVault { name: "delvehold", root: "Delvehold/Delvehold", exclude: &["Game Design", "Documentation"], + // The vault states no timeline: one present-day era. + default_era: "present", + eras: &[era( + "present", + "The Greathold now", + "The Greathold now: dwarven Holds in the Vaults of a mountain-range dungeon, at the start of a magical industrial revolution; delvers work dungeon contracts.", + )], }, ProductionVault { name: "avatar", root: "Avatar", exclude: &[], + // Humanity's waves are the spine. The vault does not partition notes + // by era, so no era withholds a path. + default_era: "rda-return", + eras: &[ + era( + "contact", + "Contact (2130s-2140s)", + "The first wave: RDA mining, the Avatar Program, TAP, and the contact disease.", + ), + era( + "first-war", + "The First War (2154)", + "Hometree falls, Toruk Makto unites the clans, and the RDA is expelled from Pandora.", + ), + era( + "aftermath", + "Aftermath (2154-2168)", + "No RDA on Pandora; defectors live at Hell's Gate and Jake prepares for the return.", + ), + era( + "rda-return", + "The RDA returns (2168-2169)", + "The second wave: the colonization mandate, the Bridgehead, and Ardmore.", + ), + era( + "western-frontier-war", + "Western Frontier War (2169)", + "The western frontier war of 2169, in the second wave's colonization.", + ), + era( + "reef-war", + "The Reef War (2169-2170)", + "The Metkayina reef clan, tulkun hunting, and the amrita the hunters want.", + ), + era( + "fire-and-ash", + "Fire and Ash (2170 on)", + "Mangkwan, Varang, and a Na'vi-on-Na'vi war.", + ), + ], }, ]; +/// The eras `name` offers and the default among them, or `None` for a name +/// production does not serve. +pub fn production_eras(name: &str) -> Option<(&'static [VaultEra], &'static str)> { + let vault = PRODUCTION_VAULTS.iter().find(|vault| vault.name == name)?; + Some((vault.eras, vault.default_era)) +} + /// The names of the vaults production serves. pub fn production_vault_names() -> impl Iterator { PRODUCTION_VAULTS.iter().map(|vault| vault.name) @@ -663,12 +760,17 @@ impl VaultEvidenceSource { /// tier is a directory in every vault that has one, so it is expressed as a /// scope and there is no tier field anywhere in this file. `..`, an /// absolute scope, and a scope that holds no note are refused. - pub fn from_snapshot(snapshot: &VaultSnapshot, scope: &str) -> Result { + /// + /// A note under any vault-relative path in `withhold` is not admitted, so + /// retrieval cannot return it; a world set in an era passes that era's + /// withheld lore here and every other caller passes none. + pub fn from_snapshot(snapshot: &VaultSnapshot, scope: &str, withhold: &[&str]) -> Result { let scope = relative_dir(scope).ok_or_else(|| VaultError::Scope(scope.to_owned()))?; let notes: Vec = snapshot .notes .iter() .filter(|note| scope.is_empty() || is_under(¬e.reference, &scope)) + .filter(|note| !withhold.iter().any(|path| is_under(¬e.reference, path))) .cloned() .collect(); if notes.is_empty() && !scope.is_empty() { @@ -968,7 +1070,7 @@ mod tests { } fn open(root: &Path, scope: &str) -> Result { - VaultEvidenceSource::from_snapshot(&VaultSnapshot::build(&profile(root))?, scope) + VaultEvidenceSource::from_snapshot(&VaultSnapshot::build(&profile(root))?, scope, &[]) } fn fixture() -> tempfile::TempDir { @@ -1407,7 +1509,7 @@ mod tests { async fn live_edits_do_not_reach_a_snapshot() { let vault = fixture(); let built = snapshot(vault.path()); - let source = VaultEvidenceSource::from_snapshot(&built, "").unwrap(); + let source = VaultEvidenceSource::from_snapshot(&built, "", &[]).unwrap(); let ask = || query(&["Rain Gate#Tolls", "Low Sere", "Provenance"]); let before = source.retrieve(&ask()).await.unwrap(); @@ -1420,7 +1522,7 @@ mod tests { for (b, a) in before.iter().zip(&after) { assert_eq!((&b.reference, &b.excerpt, &b.source), (&a.reference, &a.excerpt, &a.source)); } - let rebuilt = VaultEvidenceSource::from_snapshot(&built, "").unwrap(); + let rebuilt = VaultEvidenceSource::from_snapshot(&built, "", &[]).unwrap(); assert!(rebuilt.retrieve(&query(&["New"])).await.unwrap().is_empty()); assert_ne!(snapshot(vault.path()).id(), built.id()); } @@ -1657,12 +1759,12 @@ mod tests { )); } let built = snapshot(vault.path()); - assert!(matches!(VaultEvidenceSource::from_snapshot(&built, "Nowhere"), Err(VaultError::Scope(_)))); - assert!(VaultEvidenceSource::from_snapshot(&built, "Spoilers").is_ok()); + assert!(matches!(VaultEvidenceSource::from_snapshot(&built, "Nowhere", &[]), Err(VaultError::Scope(_)))); + assert!(VaultEvidenceSource::from_snapshot(&built, "Spoilers", &[]).is_ok()); let empty = tempfile::tempdir().unwrap(); - assert!(VaultEvidenceSource::from_snapshot(&snapshot(empty.path()), "").is_ok()); + assert!(VaultEvidenceSource::from_snapshot(&snapshot(empty.path()), "", &[]).is_ok()); assert!(matches!( - VaultEvidenceSource::from_snapshot(&snapshot(empty.path()), "Spoilers"), + VaultEvidenceSource::from_snapshot(&snapshot(empty.path()), "Spoilers", &[]), Err(VaultError::Scope(_)) )); } @@ -1893,4 +1995,52 @@ mod tests { println!("SMOKE {name} notes={} id={}", built.note_count(), built.id()); } } + + /// Spec test: a note under a withheld path is not admitted to the source, + /// so retrieval for it returns nothing; with nothing withheld it returns + /// the note. A link into withheld lore is not followed either. + #[tokio::test] + async fn withheld_lore_is_not_evidence() { + let directory = tempfile::tempdir().unwrap(); + let root = directory.path(); + write(root, "Worldbuilding/Post-Elysium/Aether.md", "The aether answers espers. +"); + write(root, "Worldbuilding/Pre-Elysium/Collapse.md", "The grid fails. See [[Aether]]. +"); + let built = snapshot(root); + + let withheld = VaultEvidenceSource::from_snapshot(&built, "", &["Worldbuilding/Post-Elysium"]).unwrap(); + assert!(withheld.retrieve(&query(&["Aether"])).await.unwrap().is_empty()); + let collapse = withheld.retrieve(&query(&["Collapse"])).await.unwrap(); + assert!(collapse.iter().all(|receipt| !receipt.reference.as_str().contains("Post-Elysium"))); + + let open = VaultEvidenceSource::from_snapshot(&built, "", &[]).unwrap(); + assert_eq!( + open.retrieve(&query(&["Aether"])).await.unwrap()[0].reference, + EvidenceRef::new("Worldbuilding/Post-Elysium/Aether.md") + ); + } + + /// Spec test: every production vault offers at least one era, with unique + /// kebab ids, a default that names one of them, and a description each. + #[test] + fn every_production_vault_has_a_coherent_era_table() { + for name in production_vault_names() { + let (eras, default) = production_eras(name).expect("a served vault has an era table"); + assert!(!eras.is_empty(), "{name}"); + assert!(eras.iter().any(|era| era.id == default), "{name} default {default}"); + let mut seen = std::collections::BTreeSet::new(); + for era in eras { + assert!(seen.insert(era.id), "{name}: duplicate era {}", era.id); + assert!( + !era.id.is_empty() && era.id.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-'), + "{name}: {} is not kebab", + era.id + ); + assert!(!era.label.is_empty() && !era.description.is_empty(), "{name}/{}", era.id); + } + } + assert!(production_eras("nowhere").is_none()); + } } + diff --git a/crates/ghostlight/src/verse/genesis.rs b/crates/ghostlight/src/verse/genesis.rs index 9641467..ca7b98e 100644 --- a/crates/ghostlight/src/verse/genesis.rs +++ b/crates/ghostlight/src/verse/genesis.rs @@ -135,6 +135,7 @@ impl CreateVerseWorldIntent { }, lens_weights: self.lens_weights, grammar: Some(self.catalog.grammar), + era: None, }) } } diff --git a/crates/ghostlight/src/verse/genesis/tests.rs b/crates/ghostlight/src/verse/genesis/tests.rs index 24f19d8..6853f7c 100644 --- a/crates/ghostlight/src/verse/genesis/tests.rs +++ b/crates/ghostlight/src/verse/genesis/tests.rs @@ -344,6 +344,7 @@ async fn the_dungeon_ingress_still_creates_an_unbound_world() { targets: BTreeMap::new(), jurisdictions: Vec::new(), lens_weights: stock_weights(), + era: None, }, &principal, ) diff --git a/crates/ghostlight/tests/external_admission.rs b/crates/ghostlight/tests/external_admission.rs index 0ce24bf..5654db3 100644 --- a/crates/ghostlight/tests/external_admission.rs +++ b/crates/ghostlight/tests/external_admission.rs @@ -57,6 +57,7 @@ impl World { // An external crate has no library fixture; it states its // own weights, as every consumer must. lens_weights: LensWeights::new(BTreeMap::from([(Lens::Patina, 1)])), + era: None, }, &principal, )