Project every player route safely

This commit is contained in:
Meta Vens 2026-08-17 18:04:24 +02:00
commit e05b7edb16
7 changed files with 232 additions and 22 deletions

View file

@ -11,7 +11,7 @@ use ghostlight_dungeon::{
assessor::ActionAssessor,
compiler::{
CustomStart, GestaltFissionRequest, OpeningRequest, OpeningSuggestion, SelectedStart,
WorldCompiler,
SuggestedOpenings, SuggestedRoles, WorldCompiler,
},
domain::{
ActionIntent, Campaign, GestaltFissionPreview, NarrationProjection, RegionExpansionPreview,
@ -371,7 +371,7 @@ async fn compile_openings(
.into_response();
};
match compiler.suggest_openings(request).await {
Ok(value) => Json(value).into_response(),
Ok(value) => Json(opening_suggestions_projection(&value)).into_response(),
Err(error) => (StatusCode::BAD_GATEWAY, error.to_string()).into_response(),
}
}
@ -416,8 +416,11 @@ async fn compile_custom(
model_receipts: model_receipts.clone(),
},
);
Json(serde_json::json!({"preview_id":id,"preview":preview,"model_receipts":model_receipts}))
.into_response()
Json(serde_json::json!({
"preview_id":id,
"preview":world_compile_preview_projection(&preview),
}))
.into_response()
}
Err(error) => (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response(),
}
@ -440,7 +443,7 @@ async fn compile_roles(
.into_response();
};
match compiler.suggest_roles(&opening).await {
Ok(value) => Json(value).into_response(),
Ok(value) => Json(role_suggestions_projection(&value)).into_response(),
Err(error) => (StatusCode::BAD_GATEWAY, error.to_string()).into_response(),
}
}
@ -496,8 +499,11 @@ async fn store_preview(
model_receipts: model_receipts.clone(),
},
);
Json(serde_json::json!({"preview_id":id,"preview":preview,"model_receipts":model_receipts}))
.into_response()
Json(serde_json::json!({
"preview_id":id,
"preview":world_compile_preview_projection(&preview),
}))
.into_response()
}
Err(error) => (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response(),
}
@ -536,7 +542,11 @@ async fn approve_preview(
if let Err(error) = refresh_mesh(&state).await {
tracing::warn!(%error, "campaign approval CultMesh publication failed");
}
Json(CommandResult::Created { campaign }).into_response()
Json(player_command_projection(
&CommandResult::Created { campaign },
None,
))
.into_response()
}
Err(error) => {
(StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response()
@ -598,8 +608,11 @@ async fn compile_destination(
model_receipts: model_receipts.clone(),
},
);
Json(serde_json::json!({"preview_id":id,"preview":preview,"model_receipts":model_receipts}))
.into_response()
Json(serde_json::json!({
"preview_id":id,
"preview":region_expansion_preview_projection(&preview),
}))
.into_response()
}
Err(error) => (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response(),
}
@ -645,7 +658,7 @@ async fn approve_destination(
})
.await
{
Ok(value) => Json(value).into_response(),
Ok(value) => Json(player_command_projection(&value, None)).into_response(),
Err(error) => (StatusCode::CONFLICT, error.to_string()).into_response(),
}
}
@ -694,8 +707,7 @@ async fn compile_fission(
);
Json(serde_json::json!({
"preview_id":id,
"preview":preview,
"model_receipts":model_receipts
"preview":gestalt_fission_preview_projection(&preview),
}))
.into_response()
}
@ -745,7 +757,7 @@ async fn approve_fission(
if let Err(error) = refresh_mesh(&state).await {
tracing::warn!(%error, "gestalt fission CultMesh publication failed");
}
Json(value).into_response()
Json(player_command_projection(&value, None)).into_response()
}
Err(error) => (StatusCode::CONFLICT, error.to_string()).into_response(),
}
@ -1218,6 +1230,140 @@ async fn command(
}
}
fn opening_suggestions_projection(value: &SuggestedOpenings) -> serde_json::Value {
serde_json::json!({"openings":value.openings})
}
fn role_suggestions_projection(value: &SuggestedRoles) -> serde_json::Value {
serde_json::json!({"roles":value.roles})
}
fn world_compile_preview_projection(preview: &WorldCompilePreview) -> serde_json::Value {
let campaign = &preview.campaign;
let player = &campaign.actors[&campaign.player_actor_id];
let locations = campaign
.locations
.values()
.map(|location| {
serde_json::json!({
"id":location.id,
"name":location.name,
"container_id":location.container_id,
"routes":location.routes,
"persistent_features":location.persistent_features,
})
})
.collect::<Vec<_>>();
let cast = campaign
.actors
.values()
.filter(|actor| actor.id != campaign.player_actor_id)
.map(|actor| {
serde_json::json!({
"id":actor.id,
"name":actor.name,
"location_id":actor.location_id,
})
})
.collect::<Vec<_>>();
let institutions = campaign
.institutions
.values()
.map(|institution| {
serde_json::json!({
"id":institution.id,
"name":institution.name,
})
})
.collect::<Vec<_>>();
let populations = campaign
.gestalts
.values()
.map(|gestalt| {
serde_json::json!({
"id":gestalt.id,
"name":gestalt.name,
"home_location_id":gestalt.home_location_id,
})
})
.collect::<Vec<_>>();
let clocks = campaign
.clocks
.values()
.map(|clock| {
serde_json::json!({
"id":clock.id,
"name":clock.label,
"progress":clock.progress,
"threshold":clock.threshold,
"trigger":clock.consequence,
})
})
.collect::<Vec<_>>();
serde_json::json!({
"schema":preview.schema,
"title":preview.title,
"opening":campaign.transcript.first().map(|turn| turn.text.as_str()),
"locations":locations,
"cast":cast,
"institutions":institutions,
"populations":populations,
"clocks":clocks,
"player_role":{
"name":player.name,
"location_id":player.location_id,
"capabilities":player.capabilities,
"equipment":player.equipment,
"conditions":player.conditions,
"obligations":player.obligations,
},
"evidence_coverage":preview.evidence_coverage,
"gaps":preview.gaps,
"branch_assumptions":preview.branch_assumptions,
"requires_approval":preview.requires_approval,
})
}
fn region_expansion_preview_projection(preview: &RegionExpansionPreview) -> serde_json::Value {
serde_json::json!({
"origin_location_id":preview.expansion.origin_location_id,
"locations":preview.expansion.locations,
"gaps":preview.gaps,
"requires_approval":preview.requires_approval,
})
}
fn gestalt_fission_preview_projection(preview: &GestaltFissionPreview) -> serde_json::Value {
let children = preview
.children
.iter()
.map(|child| {
serde_json::json!({
"id":child.id,
"name":child.name,
"home_location_id":child.home_location_id,
"partition_value":preview.child_partition_values.get(&child.id),
})
})
.collect::<Vec<_>>();
serde_json::json!({
"parent_gestalt_id":preview.parent_gestalt_id,
"partition_axis":preview.partition_axis,
"children":children,
"gaps":preview.gaps,
"requires_approval":preview.requires_approval,
})
}
fn campaign_branch_projection(kind: &str, campaign: &Campaign) -> serde_json::Value {
serde_json::json!({
"kind":kind,
"campaign_id":campaign.id,
"name":campaign.name,
"revision":campaign.revision,
})
}
fn player_command_projection(
result: &CommandResult,
narration: Option<NarrationProjection>,
@ -1443,7 +1589,7 @@ async fn fork_campaign(
if let Err(error) = refresh_mesh(&state).await {
tracing::warn!(%error, "campaign fork CultMesh publication failed");
}
Json(campaign).into_response()
Json(campaign_branch_projection("forked", &campaign)).into_response()
}
Err(error) => {
(StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response()
@ -1488,7 +1634,7 @@ async fn reset_campaign(
if let Err(error) = refresh_mesh(&state).await {
tracing::warn!(%error, "campaign reset CultMesh publication failed");
}
Json(campaign).into_response()
Json(campaign_branch_projection("reset", &campaign)).into_response()
}
Err(error) => {
(StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response()
@ -2047,5 +2193,49 @@ mod tests {
assert!(!encoded.contains("Private state"));
assert!(!encoded.contains("actors"));
assert!(!encoded.contains("facts"));
let created = player_command_projection(
&CommandResult::Created {
campaign: seed("Hidden seed"),
},
None,
);
assert_eq!(created, serde_json::json!({"kind":"created"}));
}
#[test]
fn compiler_preview_projection_exposes_approval_shape_not_private_state() {
let mut campaign = seed("Approval preview");
let player = campaign.actors.get_mut("player").unwrap();
player.goals = vec!["private goal".into()];
player.memories = vec!["private memory".into()];
player
.relationships
.insert("hidden".into(), "distrust".into());
let preview = WorldCompilePreview {
schema: "ghostlight.world_compile_preview.v1".into(),
title: "Approval preview".into(),
campaign,
evidence_receipts: vec![],
evidence_coverage: vec![],
gaps: vec!["a visible gap".into()],
branch_assumptions: vec!["a visible assumption".into()],
requires_approval: true,
};
let projection = world_compile_preview_projection(&preview);
let encoded = serde_json::to_string(&projection).unwrap();
assert!(encoded.contains("player_role"));
assert!(encoded.contains("locations"));
for private_key in [
"\"campaign\":",
"\"evidence_receipts\":",
"\"goals\":",
"\"memories\":",
"\"relationships\":",
"\"model_receipts\":",
] {
assert!(!encoded.contains(private_key), "leaked {private_key}");
}
}
}

View file

@ -629,6 +629,14 @@ and model-stage state belongs to the authenticated operator projection only.
Player and model strings enter the DOM through text nodes rather than HTML
insertion, and all laboratory inputs have programmatic labels.
The same rule covers compiler and campaign-management routes. Opening and role
responses contain selectable suggestions, not retrieval/model receipts. An
approval preview contains the promised topology, public cast, institutions,
populations, clocks, player-role ledger, evidence-use coverage, gaps, and branch
assumptions without private goals, memories, relationships, raw evidence, or a
serialized campaign. Approval, expansion, fission, fork, and reset return small
public receipts; their internal command results remain inside the daemon.
The player surface includes compilation, transcript, composer, Assess/Attempt,
roll confirmation, Wait, character ledger, current place/time/pressure, news,
campaign management, fork/reset/export, and optional operator inspection.

View file

@ -390,6 +390,13 @@ finding (`fact_distress_relay_antenna_damaged`). The schema now describes
knowledge additions as player-readable declarative statements, and the local
boundary rejects unambiguous fact-ID/key syntax before it can become memory.
A route audit then found that approval, destination/fission approval, fork, and
reset still serialized internal campaign-bearing values even though the browser
ignored them. Every player route now returns a purpose-built public projection.
Compiler approval retains topology/cast/pressure/player-role/coverage/gap data,
while raw campaign state, evidence, model receipts, private goals, memories, and
relationships remain operator-only.
Next: commit and build this repaired candidate, replay the same authenticated
Huygens campaign in an isolated runtime, inspect both the visible surface and
the literal HTTP response, then prove away catch-up/concurrency/persistence/

View file

@ -92,6 +92,11 @@ before generation. Only direct-seed source text enters causal world compilation;
background and excluded sources remain coverage provenance and cannot donate
story incidents or cast.
Compiler, expansion, fission, fork, and reset routes follow the same projection
rule. Approval previews expose the public decision surface—topology, cast,
pressures, player role, source-use coverage, gaps, and assumptions—without raw
campaign, evidence, model receipts, private goals, memories, or relationships.
Relationship documents in the schema catalog are revision-bound projections
of actor-owned relationship maps; they are not a second relationship writer.
Vault manifests summarize the exact provider/source/authority/temporal lanes

File diff suppressed because one or more lines are too long

2
web/dist/index.html vendored
View file

@ -1,5 +1,5 @@
<!doctype html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>GhostlightDungeon</title> <script type="module" crossorigin src="/assets/index-AKBKut3T.js"></script>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>GhostlightDungeon</title> <script type="module" crossorigin src="/assets/index-D0cUnC_U.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DLoOYHpE.css">
</head>
<body><header><p class="eyebrow">STARFIRE / PRIVATE VERSE</p><h1>GhostlightDungeon</h1><p id="status" role="status" aria-live="polite">Reading the world…</p></header><main>

View file

@ -172,8 +172,8 @@ async function showPreview(result: any) {
const card = node("article", undefined, "card");
card.append(
node("h3", preview.title),
node("p", preview.campaign.transcript?.[0]?.text ?? ""),
node("p", `${Object.keys(preview.campaign.locations).length} locations · ${Object.keys(preview.campaign.actors).length} actors · ${Object.keys(preview.campaign.institutions).length} institutions`),
node("p", preview.opening ?? ""),
node("p", `${preview.locations?.length ?? 0} locations · ${(preview.cast?.length ?? 0) + 1} actors · ${preview.institutions?.length ?? 0} institutions`),
node("p", preview.gaps.length ? `Material gaps: ${preview.gaps.join("; ")}` : "No declared material gaps.", "warning"),
node("p", `Branch assumptions: ${preview.branch_assumptions.join("; ") || "none"}`),
node("p", coverage.length