Separate ordinary speech from assessed attempts

This commit is contained in:
Meta Vens 2026-08-18 22:11:43 +02:00
commit 5db04a1fe7
5 changed files with 76 additions and 16 deletions

View file

@ -231,6 +231,13 @@ impl WorldCompiler {
}
pub async fn suggest_openings(&self, request: OpeningRequest) -> Result<SuggestedOpenings> {
validate_user_text("setting", &request.setting, 120)?;
if request.constraints.len() > 8 {
return Err(anyhow!("opening request accepts at most 8 constraints"));
}
for constraint in &request.constraints {
validate_user_text("opening constraint", constraint, 240)?;
}
let (queries, retrieval_receipt) = self.plan_opening_queries(&request).await?;
let receipts = self.retrieve_all(&queries, "all", 8).await?;
let evidence = opening_evidence_text(&queries, &receipts);
@ -362,6 +369,11 @@ impl WorldCompiler {
&self,
start: CustomStart,
) -> Result<(WorldCompilePreview, Vec<ModelStageReceipt>)> {
validate_user_text("campaign name", &start.campaign_name, 80)?;
validate_user_text("player identity", &start.who, 500)?;
validate_user_text("starting location", &start.where_, 500)?;
validate_user_text("starting time", &start.when, 500)?;
validate_user_text("player goal", &start.goal, 1_000)?;
let (queries, retrieval_receipt) = self
.plan_queries(
"custom_retrieval_plan",
@ -706,6 +718,7 @@ impl WorldCompiler {
crate::domain::RegionExpansionPreview,
Vec<ModelStageReceipt>,
)> {
validate_user_text("destination request", destination_request, 500)?;
let origin = campaign
.locations
.get(origin_location_id)
@ -1189,6 +1202,21 @@ impl WorldCompiler {
}
}
fn validate_user_text(label: &str, value: &str, max_chars: usize) -> Result<()> {
let value = value.trim();
if value.is_empty()
|| value.chars().count() > max_chars
|| value
.chars()
.any(|character| character.is_control() && !matches!(character, '\n' | '\r' | '\t'))
{
return Err(anyhow!(
"{label} must contain 1 to {max_chars} readable characters"
));
}
Ok(())
}
fn global_agency_queries(start: &CustomStart) -> Vec<String> {
let horizon = start.when.chars().take(120).collect::<String>();
vec![
@ -2258,6 +2286,15 @@ fn validate_opening_playability(campaign: &Campaign) -> Result<()> {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn user_text_admission_rejects_empty_oversized_and_binary_control_input() {
assert!(validate_user_text("field", "", 8).is_err());
assert!(validate_user_text("field", " ", 8).is_err());
assert!(validate_user_text("field", "123456789", 8).is_err());
assert!(validate_user_text("field", "hello\0world", 20).is_err());
assert!(validate_user_text("field", "hello\nworld", 20).is_ok());
}
use crate::{domain::SourceWitness, model::ModelPort, vault::FixtureVault};
use async_trait::async_trait;
use sha2::Digest;

File diff suppressed because one or more lines are too long

12
web/dist/index.html vendored
View file

@ -1,16 +1,16 @@
<!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-DWEg_yl8.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-BxLzO9Gw.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-B7Qh0xAi.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>
<section id="compiler" hidden><h2>Compile a world</h2><div class="compiler-grid">
<form id="suggest-form"><label for="setting">Generate three grounded openings</label><input id="setting" value="Aetheria" required><button type="submit">Retrieve and suggest</button></form>
<form id="custom-form"><p class="form-heading">Or describe your own beginning</p><label for="campaign-name">Campaign name</label><input id="campaign-name" name="campaign_name" required><label for="custom-who">Who are you?</label><input id="custom-who" name="who" required><label for="custom-where">Where are you?</label><input id="custom-where" name="where_" required><label for="custom-when">When?</label><input id="custom-when" name="when" required><label for="custom-goal">What do you want?</label><textarea id="custom-goal" name="goal" required></textarea><button type="submit">Compile custom start</button></form>
<form id="suggest-form"><label for="setting">Generate three grounded openings</label><input id="setting" value="Aetheria" maxlength="120" required><button type="submit">Retrieve and suggest</button></form>
<form id="custom-form"><p class="form-heading">Or describe your own beginning</p><label for="campaign-name">Campaign name</label><input id="campaign-name" name="campaign_name" maxlength="80" required><label for="custom-who">Who are you?</label><input id="custom-who" name="who" maxlength="500" required><label for="custom-where">Where are you?</label><input id="custom-where" name="where_" maxlength="500" required><label for="custom-when">When?</label><input id="custom-when" name="when" maxlength="500" required><label for="custom-goal">What do you want?</label><textarea id="custom-goal" name="goal" maxlength="1000" required></textarea><button type="submit">Compile custom start</button></form>
</div><div id="compiler-results"></div></section><section id="surface"></section>
<form id="composer"><label for="attempt">What does your character do or say?</label><textarea id="attempt" name="attempt" required></textarea><label for="intended-effect">What outcome are they trying to cause?</label><input id="intended-effect" name="intended_effect" required><p class="quiet">Speech can happen even when persuasion, deception, or intimidation fails.</p><div><button type="submit">Assess</button><button type="button" id="wait">Wait one hour</button></div></form><section id="receipt" class="card" hidden aria-live="polite"></section>
<form id="destination-form"><p class="form-heading">Compile a destination without moving there</p><label for="destination-origin">Current location id</label><input id="destination-origin" name="origin_location_id" readonly required><label for="destination-request">Where do you want the world to extend?</label><input id="destination-request" name="destination" required><button type="submit">Retrieve destination</button></form>
<form id="composer"><label for="attempt">What does your character do or say?</label><textarea id="attempt" name="attempt" required></textarea><label for="intended-effect">What outcome are they trying to cause? <span class="quiet">Required for an assessed attempt</span></label><input id="intended-effect" name="intended_effect"><p class="quiet">Use Speak when the words themselves are the action. Use Assess attempt when you want the words or action to persuade, deceive, intimidate, overcome resistance, or cause another uncertain effect.</p><div><button type="button" id="speak">Speak</button><button type="submit">Assess attempt</button><button type="button" id="wait">Wait one hour</button></div></form><section id="receipt" class="card" hidden aria-live="polite"></section>
<form id="destination-form"><p class="form-heading">Compile a destination without moving there</p><label for="destination-origin">Current location id</label><input id="destination-origin" name="origin_location_id" readonly required><label for="destination-request">Where do you want the world to extend?</label><input id="destination-request" name="destination" maxlength="500" required><button type="submit">Retrieve destination</button></form>
<section id="campaign-lab" hidden><h2>Campaign laboratory</h2><div id="campaign-list"></div>
<form id="resolution-form"><label for="active-cell-budget">Active Persona-cell budget: <output id="active-cell-budget-value">8</output></label><input id="active-cell-budget" name="active_cell_budget" type="range" min="1" max="32" value="8"><p id="resolution-status"></p><button type="submit">Apply at safe boundary</button></form>
<form id="fission-form"><p class="form-heading">Approval-gated population fission</p><label for="fission-parent">Population</label><select name="parent_gestalt_id" id="fission-parent" required></select><label for="fission-axis">Partition axis</label><select id="fission-axis" name="partition_axis"><option value="geography">Geography</option><option value="ideology">Ideology</option><option value="authority">Authority</option><option value="economy_role">Economic role</option><option value="species_body">Species/body</option><option value="information">Information</option></select><label for="fission-values">Named cuts, comma separated</label><input id="fission-values" name="requested_partition_values" required><label for="fission-reason">Why does this population need canonical leaves?</label><input id="fission-reason" name="reason" required><button type="submit">Compile fission preview</button></form>
<form id="fork-form"><label for="fork-name">Fork name</label><input id="fork-name" name="name" required><button type="submit">Fork selected campaign</button></form><form id="reset-form"><label for="reset-name">Reset branch name</label><input id="reset-name" name="name" required><button type="submit">Reset from selected branch seed</button></form><a href="/api/campaigns/export" download>Export selected CultCache .cc</a> <a href="/api/campaigns/canon-candidates.md" download>Export canon candidates Markdown</a><details id="operator-lab" hidden><summary>Operator inspector</summary><form id="provider-parallelism-form"><label for="provider-parallelism">Provider request parallelism: <output id="provider-parallelism-value">8</output></label><input id="provider-parallelism" type="range" min="1" max="32" value="8"><button type="submit">Apply operator limit</button></form><button type="button" id="load-operator">Load private state and receipts</button><div id="operator-output"></div></details></section>
<form id="fork-form"><label for="fork-name">Fork name</label><input id="fork-name" name="name" maxlength="80" required><button type="submit">Fork selected campaign</button></form><form id="reset-form"><label for="reset-name">Reset branch name</label><input id="reset-name" name="name" maxlength="80" required><button type="submit">Reset from selected branch seed</button></form><a href="/api/campaigns/export" download>Export selected CultCache .cc</a> <a href="/api/campaigns/canon-candidates.md" download>Export canon candidates Markdown</a><details id="operator-lab" hidden><summary>Operator inspector</summary><form id="provider-parallelism-form"><label for="provider-parallelism">Provider request parallelism: <output id="provider-parallelism-value">8</output></label><input id="provider-parallelism" type="range" min="1" max="32" value="8"><button type="submit">Apply operator limit</button></form><button type="button" id="load-operator">Load private state and receipts</button><div id="operator-output"></div></details></section>
</main></body></html>

View file

@ -2,13 +2,13 @@
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>GhostlightDungeon</title></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>
<section id="compiler" hidden><h2>Compile a world</h2><div class="compiler-grid">
<form id="suggest-form"><label for="setting">Generate three grounded openings</label><input id="setting" value="Aetheria" required><button type="submit">Retrieve and suggest</button></form>
<form id="custom-form"><p class="form-heading">Or describe your own beginning</p><label for="campaign-name">Campaign name</label><input id="campaign-name" name="campaign_name" required><label for="custom-who">Who are you?</label><input id="custom-who" name="who" required><label for="custom-where">Where are you?</label><input id="custom-where" name="where_" required><label for="custom-when">When?</label><input id="custom-when" name="when" required><label for="custom-goal">What do you want?</label><textarea id="custom-goal" name="goal" required></textarea><button type="submit">Compile custom start</button></form>
<form id="suggest-form"><label for="setting">Generate three grounded openings</label><input id="setting" value="Aetheria" maxlength="120" required><button type="submit">Retrieve and suggest</button></form>
<form id="custom-form"><p class="form-heading">Or describe your own beginning</p><label for="campaign-name">Campaign name</label><input id="campaign-name" name="campaign_name" maxlength="80" required><label for="custom-who">Who are you?</label><input id="custom-who" name="who" maxlength="500" required><label for="custom-where">Where are you?</label><input id="custom-where" name="where_" maxlength="500" required><label for="custom-when">When?</label><input id="custom-when" name="when" maxlength="500" required><label for="custom-goal">What do you want?</label><textarea id="custom-goal" name="goal" maxlength="1000" required></textarea><button type="submit">Compile custom start</button></form>
</div><div id="compiler-results"></div></section><section id="surface"></section>
<form id="composer"><label for="attempt">What does your character do or say?</label><textarea id="attempt" name="attempt" required></textarea><label for="intended-effect">What outcome are they trying to cause?</label><input id="intended-effect" name="intended_effect" required><p class="quiet">Speech can happen even when persuasion, deception, or intimidation fails.</p><div><button type="submit">Assess</button><button type="button" id="wait">Wait one hour</button></div></form><section id="receipt" class="card" hidden aria-live="polite"></section>
<form id="destination-form"><p class="form-heading">Compile a destination without moving there</p><label for="destination-origin">Current location id</label><input id="destination-origin" name="origin_location_id" readonly required><label for="destination-request">Where do you want the world to extend?</label><input id="destination-request" name="destination" required><button type="submit">Retrieve destination</button></form>
<form id="composer"><label for="attempt">What does your character do or say?</label><textarea id="attempt" name="attempt" required></textarea><label for="intended-effect">What outcome are they trying to cause? <span class="quiet">Required for an assessed attempt</span></label><input id="intended-effect" name="intended_effect"><p class="quiet">Use Speak when the words themselves are the action. Use Assess attempt when you want the words or action to persuade, deceive, intimidate, overcome resistance, or cause another uncertain effect.</p><div><button type="button" id="speak">Speak</button><button type="submit">Assess attempt</button><button type="button" id="wait">Wait one hour</button></div></form><section id="receipt" class="card" hidden aria-live="polite"></section>
<form id="destination-form"><p class="form-heading">Compile a destination without moving there</p><label for="destination-origin">Current location id</label><input id="destination-origin" name="origin_location_id" readonly required><label for="destination-request">Where do you want the world to extend?</label><input id="destination-request" name="destination" maxlength="500" required><button type="submit">Retrieve destination</button></form>
<section id="campaign-lab" hidden><h2>Campaign laboratory</h2><div id="campaign-list"></div>
<form id="resolution-form"><label for="active-cell-budget">Active Persona-cell budget: <output id="active-cell-budget-value">8</output></label><input id="active-cell-budget" name="active_cell_budget" type="range" min="1" max="32" value="8"><p id="resolution-status"></p><button type="submit">Apply at safe boundary</button></form>
<form id="fission-form"><p class="form-heading">Approval-gated population fission</p><label for="fission-parent">Population</label><select name="parent_gestalt_id" id="fission-parent" required></select><label for="fission-axis">Partition axis</label><select id="fission-axis" name="partition_axis"><option value="geography">Geography</option><option value="ideology">Ideology</option><option value="authority">Authority</option><option value="economy_role">Economic role</option><option value="species_body">Species/body</option><option value="information">Information</option></select><label for="fission-values">Named cuts, comma separated</label><input id="fission-values" name="requested_partition_values" required><label for="fission-reason">Why does this population need canonical leaves?</label><input id="fission-reason" name="reason" required><button type="submit">Compile fission preview</button></form>
<form id="fork-form"><label for="fork-name">Fork name</label><input id="fork-name" name="name" required><button type="submit">Fork selected campaign</button></form><form id="reset-form"><label for="reset-name">Reset branch name</label><input id="reset-name" name="name" required><button type="submit">Reset from selected branch seed</button></form><a href="/api/campaigns/export" download>Export selected CultCache .cc</a> <a href="/api/campaigns/canon-candidates.md" download>Export canon candidates Markdown</a><details id="operator-lab" hidden><summary>Operator inspector</summary><form id="provider-parallelism-form"><label for="provider-parallelism">Provider request parallelism: <output id="provider-parallelism-value">8</output></label><input id="provider-parallelism" type="range" min="1" max="32" value="8"><button type="submit">Apply operator limit</button></form><button type="button" id="load-operator">Load private state and receipts</button><div id="operator-output"></div></details></section>
<form id="fork-form"><label for="fork-name">Fork name</label><input id="fork-name" name="name" maxlength="80" required><button type="submit">Fork selected campaign</button></form><form id="reset-form"><label for="reset-name">Reset branch name</label><input id="reset-name" name="name" maxlength="80" required><button type="submit">Reset from selected branch seed</button></form><a href="/api/campaigns/export" download>Export selected CultCache .cc</a> <a href="/api/campaigns/canon-candidates.md" download>Export canon candidates Markdown</a><details id="operator-lab" hidden><summary>Operator inspector</summary><form id="provider-parallelism-form"><label for="provider-parallelism">Provider request parallelism: <output id="provider-parallelism-value">8</output></label><input id="provider-parallelism" type="range" min="1" max="32" value="8"><button type="submit">Apply operator limit</button></form><button type="button" id="load-operator">Load private state and receipts</button><div id="operator-output"></div></details></section>
</main><script type="module" src="/src/main.ts"></script></body></html>

View file

@ -311,14 +311,37 @@ function installAssessment(result: any) {
composer.addEventListener("submit", async event => {
event.preventDefault();
const description = document.querySelector<HTMLTextAreaElement>("#attempt")!.value.trim();
const intendedEffect = document.querySelector<HTMLInputElement>("#intended-effect")!.value.trim();
if (!description || !intendedEffect) return;
const effectInput = document.querySelector<HTMLInputElement>("#intended-effect")!;
const intendedEffect = effectInput.value.trim();
if (!description) return;
if (!intendedEffect) {
status.textContent = "Describe the uncertain outcome you want assessed, or use Speak for words that need no roll.";
effectInput.focus();
return;
}
installAssessment(await send({
type: "assess",
expected_revision: revision,
intent: { actor_id: playerActorId, description, intended_effect: intendedEffect },
}));
});
document.querySelector<HTMLButtonElement>("#speak")!.addEventListener("click", async () => {
const speechInput = document.querySelector<HTMLTextAreaElement>("#attempt")!;
const text = speechInput.value.trim();
if (!text) {
status.textContent = "Write what your character says first.";
speechInput.focus();
return;
}
const result = await send({
type: "speak",
expected_revision: revision,
actor_id: playerActorId,
text,
intended_effect: null,
});
if (result?.kind === "committed") speechInput.value = "";
});
document.querySelector<HTMLButtonElement>("#wait")!.addEventListener("click", () => void send({ type: "wait", expected_revision: revision, minutes: 60 }));
document.querySelector<HTMLInputElement>("#active-cell-budget")!.addEventListener("input", event => {
document.querySelector<HTMLOutputElement>("#active-cell-budget-value")!.value = (event.currentTarget as HTMLInputElement).value;