diff --git a/crates/ghostlight-dungeon/src/narrator.rs b/crates/ghostlight-dungeon/src/narrator.rs index c5d175b..b44d8b8 100644 --- a/crates/ghostlight-dungeon/src/narrator.rs +++ b/crates/ghostlight-dungeon/src/narrator.rs @@ -61,6 +61,10 @@ impl Narrator { }) .collect(); let public_slice = serde_json::json!({ + "viewer_actor": { + "id": player.id, + "name": player.name, + }, "world_time": campaign.world_time, "location": { "id": location.id, @@ -83,7 +87,7 @@ impl Narrator { campaign.id, campaign.revision ), lived_stream: format!( - "Narrate only latest_committed_turn and any latest_events it directly caused, in concrete, concise second-person interactive-fiction prose. The campaign contract governs tone, pacing, focus, consequences, and DM style. Obey every aggregate content boundary: line excludes the topic, veil keeps it off-screen, ask_first permits no new depiction without a current explicit player acceptance. Never expose boundary attribution. Location, time, and visible actors are grounding constraints, not a request to restate every field. Do not repeat older setup, list routes, or recap unrelated world state. Do not mention JSON, state, commits, revisions, or the source representation. Every environmental noun, sensory adjective, object state, action, and consequence must be traceable to the supplied JSON. Do not invent lighting, temperature, sound, motion, posture, dialogue, private thoughts, expertise, geography, findings, or outcomes. It is better to be spare than to fabricate texture. Emit prose only.\n\n{}", + "Narrate only latest_committed_turn and any latest_events it directly caused, in concrete, concise interactive-fiction prose. viewer_actor is the reader's character and the only actor that may be addressed in second person. If latest_committed_turn belongs to another visible actor, narrate that actor in third person and preserve their exact attribution; never transfer their speech, knowledge, uncertainty, choice, or action to the viewer. The campaign contract governs tone, pacing, focus, consequences, and DM style. Obey every aggregate content boundary: line excludes the topic, veil keeps it off-screen, ask_first permits no new depiction without a current explicit player acceptance. Never expose boundary attribution. Location, time, and visible actors are grounding constraints, not a request to restate every field. Do not repeat older setup, list routes, or recap unrelated world state. Do not mention JSON, state, commits, revisions, or the source representation. Every environmental noun, sensory adjective, object state, action, and consequence must be traceable to the supplied JSON. Do not invent lighting, temperature, sound, motion, posture, dialogue, private thoughts, expertise, geography, findings, or outcomes. It is better to be spare than to fabricate texture. Emit prose only.\n\n{}", serde_json::to_string(&public_slice)? ), output_schema: None, @@ -122,10 +126,30 @@ impl Narrator { mod tests { use super::*; use crate::{ - domain::{ActorState, BranchOrigin, Campaign, Location}, - model::FixtureModel, + domain::{ActorState, BranchOrigin, Campaign, Location, NarrativeTurn}, + model::{FixtureModel, ModelStageRequest}, }; - use std::collections::{BTreeMap, BTreeSet}; + use async_trait::async_trait; + use std::{ + collections::{BTreeMap, BTreeSet}, + sync::Mutex, + }; + + struct CaptureNarratorModel { + prompt: Mutex, + } + + #[async_trait] + impl ModelPort for CaptureNarratorModel { + async fn run(&self, request: &ModelStageRequest) -> Result { + *self.prompt.lock().unwrap() = request.lived_stream.clone(); + Ok("The clinic director answers without moving the ledger.".into()) + } + + fn provider(&self) -> &'static str { + "narrator-capture" + } + } fn campaign() -> Campaign { let actor = ActorState { @@ -207,4 +231,40 @@ mod tests { assert_eq!(persisted, seed); assert!(store.keys("narration_projection.v1").unwrap().is_empty()); } + + #[tokio::test] + async fn narrator_receives_exact_viewer_ownership_for_an_npc_turn() { + let dir = tempfile::tempdir().unwrap(); + let store = CampaignStore::open(dir.path().join("campaign.cc")).unwrap(); + let mut seed = campaign(); + let mut director = seed.actors["player"].clone(); + director.id = "clinic-director".into(); + director.name = "Clinic Director".into(); + seed.actors.insert(director.id.clone(), director); + seed.transcript.push(NarrativeTurn { + revision: 0, + at: Utc::now(), + speaker: "clinic-director".into(), + text: "I will keep the triage ledger.".into(), + }); + store.create_campaign(&seed, &[], &[]).unwrap(); + let model = Arc::new(CaptureNarratorModel { + prompt: Mutex::new(String::new()), + }); + let narrator = Narrator { + model: model.clone(), + model_name: "fixture".into(), + }; + + narrator.project(&store, &seed).await.unwrap(); + + let prompt = model.prompt.lock().unwrap(); + assert!(prompt.contains("\"viewer_actor\":{\"id\":\"player\",\"name\":\"Player\"}")); + assert!(prompt.contains("\"speaker\":\"clinic-director\"")); + assert!(prompt.contains("the only actor that may be addressed in second person")); + assert!( + prompt + .contains("never transfer their speech, knowledge, uncertainty, choice, or action") + ); + } } diff --git a/docs/architecture/ghostlight-dungeon-mvp.md b/docs/architecture/ghostlight-dungeon-mvp.md index 8296695..3a9d44d 100644 --- a/docs/architecture/ghostlight-dungeon-mvp.md +++ b/docs/architecture/ghostlight-dungeon-mvp.md @@ -193,8 +193,9 @@ Each assessment also carries four bounded typed outcome deltas. The accepted MVP delta vocabulary is deliberately narrow: conditions and relationships on actors within the acting actor's location, self-movement over an existing route, advancement of existing clocks, and posture changes to existing -institutions. It cannot create actors, places, capabilities, knowledge, -equipment, clocks, institutions, custody, or branch facts. The kernel validates +institutions. It cannot create actors, places, capabilities, equipment, clocks, +institutions, custody, or branch facts; a bounded knowledge +addition may only copy an existing accessible `WorldFact` statement. The kernel validates all four bands before storing an assessment and applies only the OS-random roll's selected band in the same atomic commit as the roll receipt. Narrative stakes describe that transition; they are no longer the transition. @@ -223,9 +224,12 @@ not enter catch-up because neither advances or enters the fiction. campaign row and cannot be read back as canonical input except as a display projection. -The narrator rechecks the campaign revision after inference. Stale or malformed -prose is discarded. Successful projections survive refresh without acquiring -write authority over the world they describe. +The narrator rechecks the campaign revision after inference. Its typed public +slice identifies the exact viewer actor separately from the latest turn's +speaker. Second-person narration belongs only to that viewer; another actor's +speech, knowledge, uncertainty, choice, or action cannot be transferred to the +player by prose. Stale or malformed prose is discarded. Successful projections +survive refresh without acquiring write authority over the world they describe. ### Cut line @@ -644,7 +648,10 @@ discoverable at that actor's current location. Every proposed knowledge addition must exactly match one of those statements. A fact known by the acting actor may be communicated to another present actor; a location-bound fact may be discovered only by the acting actor. Player attempts and NPC initiative use -the same validator. The kernel atomically updates actor knowledge but never +the same validator. The model schema enumerates each present recipient +separately and gives that recipient only the exact new facts legal for that +recipient; a generic actor-keyed string map is not an inference affordance. The +kernel repeats the semantic check, atomically updates actor knowledge, and never creates a fact from model prose. This ownership makes the negative invariant structural: an invented protocol