From 322bdf69c6aa4717957a2777d1bda72c0495e805 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 22 Sep 2026 23:24:48 +0200 Subject: [PATCH] Add the Eve play card and the play row's own revision (Cut 9, part a) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PlayTurnStoreState carries a persisted `revision: u64`, incremented once by PlayTurnStore::swap_in (the row's one write door) on every committed write. It never resets across a new turn or a restart, per the operator's ruling on the fork Hands raised: a counter derived from existing row fields (calls.len, rounds.len, ...) cannot see a refusal, which changes turn.refusal without growing calls or rounds. PlayTurnView now carries the same revision, read through PlayTable::current_turn_view. eve.rs's authenticated_surface reads PlayTurnView and renders a play card (world.play.card: narration, open question text, refusal line) plus a world.play control binding ["text", "answers"], where "answers" is the open question's own QuestionId, JSON-encoded into a bound control exactly as lens_weights/jurisdictions/targets already encode a local-draft "json" field's default value. authenticated_surface_version folds surface_version(snapshot) with the play row's own revision, so a play-row-only change (no kernel patch, e.g. a refusal or a closed turn's narration) still moves the surface version. world.speak, the story card, and current_operator_view's log read for the surface are all still present and unchanged; this is the "add" half of add-first-delete-second. Both mechanisms coexist on the Active surface for this commit. New tests (play.rs): the_play_surface_shows_only_the_projection (the play card's own subtree never renders operator_log content, even when it is durably committed and world.story still legitimately shows it elsewhere pending the deletion commit — mutation-verified by hand: rendering operator_log into the card fails this test), a_question_is_answered_through_ the_cards_own_binding_and_the_turn_closes_with_narration (PA.f134 end to end, answering with the exact id the rendered surface emitted, and proving surface_version moves even though world.revision does not), and a_commit_changing_only_the_refusal_still_moves_the_rows_own_revision (the isolated regression for the fork itself — mutation-verified by hand: keying the increment off calls.len() growing fails this test). Dungeon bin: 137 -> 140 tests, all passing. ghostlight lib: 622, unchanged. Co-Authored-By: Claude Sonnet 5 --- crates/ghostlight-dungeon/src/eve.rs | 118 +++++++- crates/ghostlight-dungeon/src/play.rs | 368 ++++++++++++++++++++++- crates/ghostlight-dungeon/src/runtime.rs | 23 +- 3 files changed, 486 insertions(+), 23 deletions(-) diff --git a/crates/ghostlight-dungeon/src/eve.rs b/crates/ghostlight-dungeon/src/eve.rs index c951e8d..db8140f 100644 --- a/crates/ghostlight-dungeon/src/eve.rs +++ b/crates/ghostlight-dungeon/src/eve.rs @@ -1,6 +1,7 @@ //! Eve/CultUI projection for the one live world owner. use crate::mesh::{COMMAND_BOUNDARY, COMMAND_RESULT_SCHEMA, PROVIDER_ID, SURFACE_ID}; +use crate::play::PlayTurnView; use ghostlight::{JurisdictionKey, OperatorEvent, WorldPhase, WorldSnapshot}; use anyhow::{Context, bail}; use chrono::{DateTime, Utc}; @@ -65,6 +66,22 @@ pub(crate) fn surface_version(snapshot: Option<&WorldSnapshot>) -> u64 { .unwrap_or(0) } +/// The authenticated surface's own version (Cut 9): `surface_version` folded +/// with the play row's own `revision`, when a play view is available. Additive, +/// not paired: both counters only ever grow, so the sum only ever grows, and it +/// moves whenever either one does — a play-row-only change (a fresh refusal, a +/// newly open question, a closed turn's narration, none of which necessarily +/// commit anything to the world) moves this even though `surface_version` +/// alone would not, which is what lets the SSE path wake for it. No play view +/// (no turn has opened yet, or the table is unavailable) contributes nothing, +/// matching `surface_version`'s own reach when no play card renders at all. +pub(crate) fn authenticated_surface_version( + snapshot: Option<&WorldSnapshot>, + play: Option<&PlayTurnView>, +) -> u64 { + surface_version(snapshot).saturating_add(play.map_or(0, |view| view.revision)) +} + pub(crate) fn world_state(snapshot: Option<&WorldSnapshot>) -> &'static str { match snapshot.map(|world| world.phase) { None => "empty", @@ -181,15 +198,20 @@ fn jurisdiction_label(world: &WorldSnapshot, jurisdiction: JurisdictionKey) -> S } } -/// `operator_log` arrives beside the snapshot rather than inside it: the story -/// feed is the human operator's surface, and no subject-facing lane may reach an -/// unscoped event log. +/// `operator_log` and `play` both arrive beside the snapshot rather than +/// inside it: the story feed is the human operator's surface, and no +/// subject-facing lane may reach an unscoped event log. Cut 9's own play card +/// below reads `play` alone, never `operator_log` — invariant 8's projection, +/// question, and refusal, nothing else. `operator_log` still feeds +/// `world.story`/`world.speak` below; Cut 9's own deletion commit removes +/// this parameter along with them. pub(crate) fn authenticated_surface( account: &str, snapshot: Option<&WorldSnapshot>, operator_log: &[OperatorEvent], + play: Option<&PlayTurnView>, ) -> anyhow::Result { - let version = surface_version(snapshot); + let version = authenticated_surface_version(snapshot, play); let mut children = vec![json!({ "id":"ghostlight.identity", "kind":"heimdall.identity", @@ -283,7 +305,7 @@ pub(crate) fn authenticated_surface( "children":[{ "id":"world.summary.body", "kind":"text", - "props":{"value":format!("{} subject(s), {} committed event(s)", world.subjects.len(), operator_log.len())}, + "props":{"value":format!("{} subject(s)", world.subjects.len())}, "children":[] }] })); @@ -449,6 +471,90 @@ pub(crate) fn authenticated_surface( "WorldMailbox", )); } + + // Cut 9: the play card. Invariant 8 — the player sees a + // projection, the question, and the refusal of their own + // act, nothing else — so this reads `play` alone, never + // `operator_log`: no id, no other subject's state, no + // speech the player did not perceive. Always rendered in + // Active (matching `world.story`'s own always-rendered + // shape above), with empty rows before any turn has ever + // opened. + let mut play_rows = Vec::new(); + if let Some(narration) = play.and_then(|view| view.narration.as_deref()) { + play_rows.push(json!({ + "id":"world.play.narration", + "kind":"text", + "props":{"value":narration}, + "children":[] + })); + } + if let Some(question) = play.and_then(|view| view.question.as_ref()) { + play_rows.push(json!({ + "id":"world.play.question", + "kind":"text", + "props":{"value":question.text.as_str()}, + "children":[] + })); + } + if let Some(refusal) = play.and_then(|view| view.refusal.as_deref()) { + play_rows.push(json!({ + "id":"world.play.refusal", + "kind":"text", + "props":{"value":refusal}, + "children":[] + })); + } + children.push(json!({ + "id":"world.play.card", + "kind":"card", + "props":{"title":"Play"}, + "children":play_rows + })); + + // PA.f134: `answers` carries the exact `QuestionId` the + // card above is showing, JSON-encoded the same way + // `lens_weights`/`jurisdictions`/`targets` already encode + // a `local_draft("…", "json")` field's own default value + // — never a value a caller builds by hand. `None`/absent + // when no question is open, so the control still opens or + // continues a turn with plain text. With only `text` + // bound, an asked question could never be answered + // through this control at all — the world would wedge. + let answers_default = play + .and_then(|view| view.question.as_ref()) + .map(|question| serde_json::to_string(&question.id)) + .transpose() + .context("the open question's id encodes as JSON")?; + children.extend([ + json!({ + "id":"world.play.answers", + "kind":"control.input.text", + "props":{"label":"Question id","value":answers_default,"hidden":true}, + "stateBindings":[local_draft("answers", "json")], + "children":[] + }), + json!({ + "id":"world.play.text", + "kind":"control.input.textarea", + "props":{"label":"What do you do?","rows":3,"placeholder":"Write freely"}, + "stateBindings":[local_draft("text", "string")], + "children":[] + }), + command_button( + "world.play", + "Play", + "world.play", + json!({}), + &["text", "answers"], + ), + ]); + commands.push(command_descriptor( + "world.play", + "ghostlight.world_play.v0", + &["text", "answers"], + "PlayTable", + )); } } } @@ -655,7 +761,7 @@ mod tests { #[test] fn empty_authenticated_surface_has_create_without_session_zero() { - let surface = authenticated_surface("sha256:owner", None, &[]).unwrap(); + let surface = authenticated_surface("sha256:owner", None, &[], None).unwrap(); let encoded = serde_json::to_string(&surface).unwrap(); assert!(encoded.contains("world.create")); assert!(encoded.contains("narrative_persona_label")); diff --git a/crates/ghostlight-dungeon/src/play.rs b/crates/ghostlight-dungeon/src/play.rs index 3909376..ba47a3c 100644 --- a/crates/ghostlight-dungeon/src/play.rs +++ b/crates/ghostlight-dungeon/src/play.rs @@ -347,6 +347,22 @@ struct PlayTurnStoreState { /// canonical re-encode check refuses any row missing a declared field /// regardless, so a default here could never actually apply either. ledger: KeyLedger, + /// The row's own monotonic counter (Cut 9): incremented exactly once by + /// `swap_in`, the row's one write door, on every committed write — + /// `commit`'s own mid-turn updates and `open_new_turn`'s own turn + /// replacements alike. It never resets, not on a new turn and not on a + /// restart (the store reads it back off disk like every other field), so + /// a reconnecting SSE client can never see it go backwards. This is what + /// lets `eve::authenticated_surface`'s own `surface_version` move on a + /// refusal or a question that commits nothing to the world — the one gap + /// a version derived only from already-existing row fields could not + /// close, because a refusal updates `turn.refusal` without growing + /// `turn.calls` or `turn.rounds` (`execute_actor_call`'s `ActionRejected` + /// arm updates an already-recorded call's own result in place). No + /// `#[serde(default)]`, matching `ledger` above: the store has never been + /// deployed, so no row anywhere is missing it, and the canonical + /// re-encode check stays strict (PA.f95). + revision: u64, } /// One closed turn's own applied request keys, oldest closed turn first. @@ -409,6 +425,7 @@ impl PlayTurnStore { schema: STORE_SCHEMA.into(), turn: None, ledger: KeyLedger::default(), + revision: 0, }; let row = envelope(&state)?; if !store.compare_and_swap_batch(&[], vec![row.clone()])? { @@ -484,12 +501,7 @@ impl PlayTurnStore { /// closing out of the row here. fn commit(&mut self, turn: PlayTurn) -> anyhow::Result<()> { self.ensure_owned()?; - let next = PlayTurnStoreState { - schema: STORE_SCHEMA.into(), - turn: Some(turn), - ledger: self.state.ledger.clone(), - }; - self.swap_in(next) + self.swap_in(Some(turn), self.state.ledger.clone()) } /// Opens `turn` as the store's new current turn (PA.f83): whatever turn @@ -504,15 +516,20 @@ impl PlayTurnStore { if let Some(previous) = &self.state.turn { ledger.push_closed(previous.turn_id.clone(), previous.applied_keys.clone()); } - let next = PlayTurnStoreState { - schema: STORE_SCHEMA.into(), - turn: Some(turn), - ledger, - }; - self.swap_in(next) + self.swap_in(Some(turn), ledger) } - fn swap_in(&mut self, next: PlayTurnStoreState) -> anyhow::Result<()> { + /// The row's one write door (Cut 9): every committed write — `commit`'s + /// own mid-turn updates and `open_new_turn`'s own turn replacements alike + /// — passes through here, and `revision` moves exactly once per call, + /// here alone, so no call site can under- or double-count it. + fn swap_in(&mut self, turn: Option, ledger: KeyLedger) -> anyhow::Result<()> { + let next = PlayTurnStoreState { + schema: STORE_SCHEMA.into(), + turn, + ledger, + revision: self.state.revision + 1, + }; let next_row = envelope(&next)?; let swapped = self .store @@ -640,6 +657,13 @@ pub(crate) struct PlayTurnView { pub(crate) question: Option, pub(crate) narration: Option, pub(crate) refusal: Option, + /// The play row's own monotonic counter (Cut 9), read straight off the + /// store: `eve::authenticated_surface` folds it into `surface_version` + /// alongside `world.revision`, so a change this view alone carries — + /// a fresh refusal, a newly open question, a closed turn's narration, + /// none of which necessarily move the world's own revision — still moves + /// the surface version and wakes the SSE path. + pub(crate) revision: u64, } /// One outcome of executing a round's already-decided tool calls. @@ -982,6 +1006,7 @@ impl PlayTable { question: open_question_of(turn), narration: turn.narration.clone(), refusal: turn.refusal.clone(), + revision: store.state.revision, }) } @@ -2771,6 +2796,323 @@ mod tests { assert_eq!(turn.narration.as_deref(), Some("The room settles.")); } + /// Walks a rendered Eve surface for the first node whose own `id` matches + /// — the same small recursive search `eve.rs`'s own tests use, copied + /// rather than shared because it is test-local on both sides. + fn find_surface_node<'a>(node: &'a Value, id: &str) -> Option<&'a Value> { + if node["id"] == id { + return Some(node); + } + node.as_object()? + .values() + .flat_map(|value| match value { + Value::Array(items) => items.iter().collect::>(), + other => vec![other], + }) + .find_map(|child| find_surface_node(child, id)) + } + + /// Cut 9's own card test: the player's own already-committed speech is + /// durable in `state.world.operator_log()` — the operator's surface, per + /// its own doc comment, which "no subject-facing lane may reach" — while + /// the turn's own narration is a *different*, player-facing channel the + /// play table produces. `eve::authenticated_surface`'s play card must + /// show the narration and never the operator log's own text, proving + /// invariant 8's "nothing else": the player sees a projection, the + /// question, and the refusal of their own act, never an unscoped event + /// log. Mutation M9.1: render `operator_log` into the card (as + /// `world.story` still does elsewhere on this same surface, pending Cut + /// 9's own deletion commit) — this test must fail if the *play card* + /// itself ever does the same. + #[tokio::test] + async fn the_play_surface_shows_only_the_projection() { + let fixture = play_world(None, "player-projection-only").await; + let snapshot = fixture.world.snapshot().await.unwrap(); + let player = player_id(&snapshot); + let opportunity = snapshot + .opportunities + .iter() + .find(|opportunity| opportunity.scope.subject_id == player) + .cloned() + .expect("the player's own speak opportunity"); + let affordance_id = snapshot + .affordances + .iter() + .find(|entry| { + entry.entry.kind.0 == "speak" + && snapshot + .subjects + .iter() + .any(|subject| subject.id == player && subject.affordances.contains(&entry.id)) + }) + .map(|entry| entry.id) + .expect("the player's own speak affordance"); + fixture + .world + .submit_principal( + PrincipalCommandIntent { + id: CommandId::new(), + world_id: snapshot.world_id, + expected_revision: snapshot.revision, + body: CommandBody::ExerciseDecision { + opportunity, + invocation: DecisionInvocation { + affordance: affordance_id, + bindings: Vec::new(), + proposed: Vec::new(), + speech: Some( + Statement::new("A voice the play table never narrated.".to_owned()) + .unwrap(), + ), + display: None, + }, + }, + }, + &fixture.principal, + ) + .await + .unwrap(); + let operator_log = fixture.world.operator_log().await.unwrap(); + assert_eq!(operator_log.len(), 1, "the committed speech must be durable in the operator log"); + + let end = output("r0", vec![call_event("c0", END_TURN_TOOL, serde_json::json!({}))]); + let personas = PersonaLane::new( + ControllerPort::new(fixture.world.clone()), + ScriptedPort::new(vec![output("proj-0", vec![text_event("The room settles into quiet.")])]), + "gpt-5.6-sol".into(), + "gpt-5.6-sol".into(), + ) + .unwrap(); + let directory = tempfile::tempdir().unwrap(); + let table = PlayTable::new( + fixture.world.clone(), + personas, + ScriptedPort::new(vec![end]), + "gpt-5.6-terra".into(), + Arc::new(Semaphore::new(2)), + directory.path().join("play-turn-v1.cc"), + ) + .unwrap(); + table + .run(&fixture.principal, test_turn_id(90), "I look around.".into()) + .await + .unwrap(); + let view = table.current_turn_view().await.unwrap(); + assert_eq!(view.narration.as_deref(), Some("The room settles into quiet.")); + + let world = fixture.world.snapshot().await.unwrap(); + // The *real* operator log, with the leaking text durably in it, so a + // mutation that renders `operator_log` into the play card genuinely + // has something to leak here — `world.story` (pending Cut 9's own + // deletion commit) legitimately still renders this same text + // elsewhere on the surface, so the negative assertion below is + // scoped to the play card's own subtree, not the whole page. + let surface = crate::eve::authenticated_surface( + "player-projection-only", + Some(&world), + &operator_log, + Some(&view), + ) + .unwrap(); + let play_card = find_surface_node(&surface, "world.play.card").expect("the play card"); + let play_card_encoded = serde_json::to_string(play_card).unwrap(); + assert!( + play_card_encoded.contains("The room settles into quiet."), + "the card must show the turn's own narration: {play_card_encoded}" + ); + assert!( + !play_card_encoded.contains("A voice the play table never narrated."), + "the play card must never render the operator log's own speech, even though it is durably \ + committed and `world.story` still legitimately shows it elsewhere on this surface pending \ + Cut 9's own deletion commit: {play_card_encoded}" + ); + // Every other `world.play.*` node too — the answers/text controls + // and the button — not only the card itself. + for id in ["world.play.answers", "world.play.text", "world.play"] { + if let Some(node) = find_surface_node(&surface, id) { + let encoded = serde_json::to_string(node).unwrap(); + assert!( + !encoded.contains("A voice the play table never narrated."), + "{id} must never carry the operator log's own speech: {encoded}" + ); + } + } + } + + /// PA.f134's own end-to-end proof, and the fork Self ruled on: answering + /// *through the card's own rendered `world.play.answers` binding* — the + /// id the surface actually emitted, never one this test built — resumes + /// the turn, and the closed turn's narration is then visible through the + /// same card. Also proves the ruling's own `surface_version` claim: the + /// world commits nothing across this whole exchange (`ask_player`/ + /// `end_turn` are conversational, not kernel patches), so + /// `world.revision` never moves, yet `authenticated_surface_version` + /// still does, because the play row's own `revision` carries it. + #[tokio::test] + async fn a_question_is_answered_through_the_cards_own_binding_and_the_turn_closes_with_narration() { + let fixture = play_world(None, "player-card-question").await; + let directory = tempfile::tempdir().unwrap(); + let store_path = directory.path().join("play-turn-v1.cc"); + + let ask = output( + "r0", + vec![call_event( + "c0", + ASK_PLAYER_TOOL, + serde_json::json!({"question": "Which way?"}), + )], + ); + let end = output("r1", vec![call_event("c1", END_TURN_TOOL, serde_json::json!({}))]); + let personas = PersonaLane::new( + ControllerPort::new(fixture.world.clone()), + ScriptedPort::new(vec![output("proj-0", vec![text_event("The hall falls quiet.")])]), + "gpt-5.6-sol".into(), + "gpt-5.6-sol".into(), + ) + .unwrap(); + let table = PlayTable::new( + fixture.world.clone(), + personas, + ScriptedPort::new(vec![ask, end]), + "gpt-5.6-terra".into(), + Arc::new(Semaphore::new(2)), + &store_path, + ) + .unwrap(); + + table + .run(&fixture.principal, test_turn_id(91), "I stand at a crossroads.".into()) + .await + .unwrap(); + let asked_view = table.current_turn_view().await.unwrap(); + assert_eq!( + asked_view.question.as_ref().map(|question| question.text.as_str()), + Some("Which way?") + ); + + let world_before = fixture.world.snapshot().await.unwrap(); + let surface_before = crate::eve::authenticated_surface( + "player-card-question", + Some(&world_before), + &[], + Some(&asked_view), + ) + .unwrap(); + let version_before = surface_before["version"].as_u64().unwrap(); + + let question_row = find_surface_node(&surface_before, "world.play.question") + .expect("the question row"); + assert_eq!(question_row["props"]["value"], "Which way?"); + let answers_control = + find_surface_node(&surface_before, "world.play.answers").expect("the answers control"); + let raw_answers = answers_control["props"]["value"] + .as_str() + .expect("the answers control carries the open question's id as a JSON string"); + // The exact value `serde_json::to_string` would encode `OpenQuestion.id` + // as (`eve.rs`'s own construction); decoded back here into the same + // private `QuestionId` type, since this test lives in `play`'s own + // module and never touches its fields directly either way. + let answers: QuestionId = + serde_json::from_str(raw_answers).expect("the rendered answers id decodes"); + + table + .run( + &fixture.principal, + test_turn_id(92), + PlayRequest { + text: "I go left.".into(), + answers: Some(answers), + }, + ) + .await + .unwrap(); + + let closed_view = table.current_turn_view().await.unwrap(); + assert_eq!(closed_view.state, PlayTurnState::Closed); + assert_eq!(closed_view.question, None); + assert_eq!(closed_view.narration.as_deref(), Some("The hall falls quiet.")); + assert!( + closed_view.revision > asked_view.revision, + "the row's own revision must move again once the turn closes: {} -> {}", + asked_view.revision, + closed_view.revision + ); + + let world_after = fixture.world.snapshot().await.unwrap(); + assert_eq!( + world_after.revision, world_before.revision, + "asking and answering a question are conversational; neither commits to the world" + ); + + let surface_after = crate::eve::authenticated_surface( + "player-card-question", + Some(&world_after), + &[], + Some(&closed_view), + ) + .unwrap(); + assert!( + find_surface_node(&surface_after, "world.play.question").is_none(), + "no question is open any more; the card must not still show one" + ); + let narration_row = find_surface_node(&surface_after, "world.play.narration") + .expect("the narration row"); + assert_eq!(narration_row["props"]["value"], "The hall falls quiet."); + let version_after = surface_after["version"].as_u64().unwrap(); + assert!( + version_after > version_before, + "surface_version must move even though world.revision did not: {version_before} -> {version_after}" + ); + } + + /// The fork Self ruled on, isolated: a commit that changes only + /// `turn.refusal` — exactly the shape `execute_actor_call`'s + /// `ActionRejected` arm leaves a row in (the call's own record is + /// already persisted before submission, PA-Q8's "body durable before + /// effects" order; this second commit carries only the refusal, growing + /// neither `calls` nor `rounds`) — must still move the row's own + /// `revision`. A counter derived from `calls.len()` or `rounds.len()` + /// cannot see this commit at all, which is the exact gap that made a + /// persisted counter, not a derived one, the ruled answer. + /// + /// Mutation: move `PlayTurnStore::swap_in`'s own `revision + 1` onto a + /// condition keyed off `turn.calls.len()` growing (or any other derived + /// field) instead of firing unconditionally on every commit — this + /// commit, which grows nothing, would then leave `revision` exactly + /// where it started, failing the assertion below. + #[tokio::test] + async fn a_commit_changing_only_the_refusal_still_moves_the_rows_own_revision() { + let directory = tempfile::tempdir().unwrap(); + let mut store = PlayTurnStore::open(directory.path().join("play-turn-v1.cc")).unwrap(); + let base = PlayTurn { + turn_id: test_turn_id(9001), + applied_keys: vec!["k0".into()], + opening_prompt: "opening".into(), + player_prose: vec!["I try the act.".into()], + rounds: Vec::new(), + calls: Vec::new(), + persona_turns: Vec::new(), + question: None, + refusal: None, + narration: None, + fault: None, + state: PlayTurnState::Running, + }; + store.open_new_turn(base.clone()).unwrap(); + let revision_before = store.state.revision; + + let mut refused = base; + refused.refusal = Some("refused".into()); + store.commit(refused).unwrap(); + let revision_after = store.state.revision; + + assert!( + revision_after > revision_before, + "a commit that changes only the refusal line must still move the row's own revision: \ + {revision_before} -> {revision_after}" + ); + } + #[tokio::test] async fn a_raw_op_is_journaled_as_play_and_never_as_an_actor() { let fixture = play_world(None, "player-raw-op").await; diff --git a/crates/ghostlight-dungeon/src/runtime.rs b/crates/ghostlight-dungeon/src/runtime.rs index 61b2be9..5b9099d 100644 --- a/crates/ghostlight-dungeon/src/runtime.rs +++ b/crates/ghostlight-dungeon/src/runtime.rs @@ -9,7 +9,7 @@ use crate::{ TARGET as GHOSTLIGHT_TARGET, }, mesh::{self, MeshPublisher, MeshRuntimeIdentity}, - play::{PlayRequest, PlayTable, QuestionId}, + play::{PlayRequest, PlayTable, PlayTurnView, QuestionId}, }; use ghostlight::{ AffordanceId, CONSUMER_BODY_LIMIT, CommandBody, CommandId, ConnectorBinding, ConsumerPort, @@ -693,6 +693,7 @@ async fn eve_surface( let Some(principal) = authenticated_principal(&headers, &state).await else { return Json(eve::anonymous_surface()).into_response(); }; + let play_view = current_play_view(&state).await; match current_operator_view(&state) .await .and_then(|(snapshot, log)| { @@ -700,6 +701,7 @@ async fn eve_surface( principal.account_subject_hash(), snapshot.as_ref(), &log, + play_view.as_ref(), ) }) { Ok(surface) => Json(surface).into_response(), @@ -1317,6 +1319,15 @@ async fn current_world(state: &AppState) -> anyhow::Result } } +/// The current play turn's own player-facing state (Cut 9), read straight off +/// `PlayTable::current_turn_view` — `None` when the table is unavailable, and +/// `None` again when it is available but no turn has ever opened, exactly as +/// `current_turn_view` itself returns. `eve::authenticated_surface`'s own play +/// card degrades to its own empty shape either way. +async fn current_play_view(state: &AppState) -> Option { + state.play.as_ref()?.current_turn_view().await +} + /// The two halves of the operator surface, fetched together: the projection of /// world state, and the story feed the human reads. The feed is deliberately not /// a snapshot field, so no controller lane can reach it. @@ -3064,7 +3075,7 @@ mod tests { .account_subject_hash() .to_owned(); let stranger = "someone-else"; - let mut surfaces = vec![eve::authenticated_surface(&owner, None, &[]).unwrap()]; + let mut surfaces = vec![eve::authenticated_surface(&owner, None, &[], None).unwrap()]; two_cell_world( &fixture.state, &fixture.cookie, @@ -3079,7 +3090,7 @@ mod tests { let draft = fixture.state.world.snapshot().await.unwrap(); assert_eq!(draft.phase, WorldPhase::Draft); for account in [owner.as_str(), stranger] { - surfaces.push(eve::authenticated_surface(account, Some(&draft), &[]).unwrap()); + surfaces.push(eve::authenticated_surface(account, Some(&draft), &[], None).unwrap()); } for body in [CommandBody::ApproveDraft, CommandBody::ActivateWorld] { let snapshot = fixture.state.world.snapshot().await.unwrap(); @@ -3108,8 +3119,11 @@ mod tests { } let active = fixture.state.world.snapshot().await.unwrap(); assert_eq!(active.phase, WorldPhase::Active); + let play_view = current_play_view(&fixture.state).await; for account in [owner.as_str(), stranger] { - surfaces.push(eve::authenticated_surface(account, Some(&active), &[]).unwrap()); + surfaces.push( + eve::authenticated_surface(account, Some(&active), &[], play_view.as_ref()).unwrap(), + ); } surfaces.push(eve::anonymous_surface()); @@ -3267,6 +3281,7 @@ mod tests { &owner, Some(&draft), &[], + None, ) .unwrap(); let encoded = serde_json::to_string(&surface).unwrap();