diff --git a/crates/ghostlight-dungeon/src/persona.rs b/crates/ghostlight-dungeon/src/persona.rs index af26eb9..e482cb3 100644 --- a/crates/ghostlight-dungeon/src/persona.rs +++ b/crates/ghostlight-dungeon/src/persona.rs @@ -228,22 +228,24 @@ struct CellAppraisalProposal { } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)] -enum CellInterpreterAgentAction { +#[serde(rename_all = "snake_case")] +enum CellInterpreterAgentTool { + Submit, + UpsertDecision, + RemoveDecision, + InspectDraft, +} + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(deny_unknown_fields)] +struct CellInterpreterAgentAction { + kind: CellInterpreterAgentTool, /// Efficient first attempt: publish one complete private draft for /// deterministic compilation and semantic verification. - Submit { - decisions: BTreeMap, - }, + decisions: Option>, /// Replace exactly one decision while preserving every other draft entry. - UpsertDecision { - subject_id: String, - decision: serde_json::Value, - }, - RemoveDecision { - subject_id: String, - }, - InspectDraft, + subject_id: Option, + decision: Option, } #[derive(Debug)] @@ -255,6 +257,12 @@ enum CellInterpreterAgentOutput { #[derive(Clone, Debug, Serialize)] #[serde(tag = "kind", rename_all = "snake_case")] enum CellInterpreterFinding { + InvalidActionShape { + requested_tool: CellInterpreterAgentTool, + decisions_present: bool, + subject_id_present: bool, + decision_present: bool, + }, DraftProgress { decision_subject_ids: Vec, missing_subject_ids: Vec, @@ -507,9 +515,9 @@ const CELL_PROJECTION_OUTPUT_CONTRACT: &str = r#"{ const CELL_INTERPRETER_AGENT_OUTPUT_CONTRACT: &str = r#"{ "kind":"submit | upsert_decision | remove_decision | inspect_draft", - "decisions":"required only for submit; the exact complete decision map", - "subject_id":"required for one-decision operations", - "decision":"required only for upsert_decision; one exact action, inaction, or undecided value" + "decisions":"the exact complete decision map for submit; null otherwise", + "subject_id":"one exact decision owner for upsert_decision or remove_decision; null otherwise", + "decision":"one exact action, inaction, or undecided value for upsert_decision; null otherwise" }"#; const CELL_EFFECT_VERIFIER_INSTRUCTIONS: &str = "You are the private semantic verifier between an Interpreter and the world kernel. Judge this one candidate action's typed effects as one composition against the exact attributed subject's choice in the Persona turn. Structural permissions were already checked. Use exact_subject_permission as the sole map of canonical subjects, locations, and destinations for this actor. canonical_locations is sibling identity context: compare it with exact_subject_permission.location_ids, and never treat a name as granting locality, co-presence, reach, publication, movement, target, effect, or mutation authority. A matching current-location name denotes that place or its unnamed local public, not an omitted canonical subject. activity_targets supplies each canonical target's exact name and current locations; reachable_destinations supplies exact actor-movement destination IDs and names; migration_destinations supplies exact population names and locations. Preserve every distinct affirmative means the subject actually chooses. Do not invent another means from a purpose, refusal, restraint, condition to preserve, desired social norm, or hoped-for state. Keeping someone's choice open, declining to coerce them, leaving state unchanged, respecting autonomy, or waiting for another subject's decision requires no additional typed effect unless the Persona separately chooses an observable act to do it. Communication can therefore be faithfully combined with restraint without implying coordinate, recruit, posture, or pressure effects. Reject effect omission only when the Persona explicitly undertakes another observable act. When one choice contains relocation, an activity at the subject's exact snapshot location occurs before relocation and an activity at the exact admitted destination occurs after arrival; activities within one location phase are an unordered atomic set. Array and object field order are not chronology. When the Persona chooses to go to a canonical target, actor_move must use that target's actual different reachable location. If actor and target are already co-located, reject movement to some other place; a local communicate, coordinate, or prepare may encode the stated attempt instead. A place named only in prose and absent from reachable_destinations and migration_destinations is local texture inside the supplied activity location; walking to it cannot justify rejecting a concrete local prepare or repair as omitted travel. Return exactly one verdict with action_index 0. A gestalt_migration means that exact population leaf chooses to travel together to the supplied destination within the strategic horizon; loading, waiting, giving away passage, sending only some other subject, or merely considering travel does not entail it. Conversely, when the population chooses to board, depart, or relocate together, reject gestalt_activity prepare that erases the chosen journey. Gestalt migration never entails that a named member moved. A member_migration means that named member personally chooses to travel to the destination. Boarding a transport whose supplied destination is unambiguous in the lived stream is a chosen journey; the Persona need not repeat the place name. Giving away a berth, sending somebody else, waiting, or merely considering travel does not entail migration. Conversely, when the member chooses to board, depart, travel, or join the supplied destination, reject member_activity that reduces that commitment to preparing, queuing, or approaching. A member_activity belongs only to that exact named person's stated attempt; it cannot be reassigned to their population. Communication targets must be the exact canonical subjects actually addressed in the Persona turn. An exact activity_targets entry is sufficient authority to attempt direct communication with that named subject; allowed_persistent_publication_channels governs only durable public publication and is never an additional requirement for direct contact. One communicate activity is also the complete supported composition when the same utterance addresses exact canonical targets and an unnamed public audience: target_subject_ids names the canonical addressees and candidate_action.public_channels names the simultaneous public reach. A call to unnamed people at a canonical location is such public or local audience, not a missing activity target. Do not demand a second targetless communicate for that same utterance. Use a targetless communicate only when the communication has no exact canonical addressee. Internal-population coordination is owner-specific: apply only coordination_target_contract.rule for this exact attributed subject, never a rule belonging to another subject kind. If the Persona addresses an unnamed clerk, dock master, passerby, or local environment, reject any effect that substitutes a containing population, related institution, or merely permitted ID. A targetless local investigate at the subject's exact current or paired movement destination is the faithful supported shape for seeking information from an unnamed role or the environment; its empty target list is intentional and must not itself be grounds for rejection. An institution posture must express its stated commitment or withholding. A gestalt pressure resolution must be causally supported by its stated attempt, and an added pressure must be a resulting unresolved condition rather than completed-action prose. An activity records only the exact attempt—never successful preparation, coordination, discovery, recruitment, obstruction, exchange, delivery, persuasion, acceptance, or target response. Reject omissions, reversals, subject swaps, wrong destinations, wishful outcomes, and effects that the Persona did not choose. Be concise. Return exactly one JSON object. A faithful verdict uses result \"match\", null mismatch_kind, and null repair_guidance. Otherwise use result \"mismatch\", exactly one mismatch_kind (\"subject_swap\", \"effect_omission\", \"effect_reversal\", \"target_substitution\", \"invented_outcome\", or \"wrong_effect_kind\"), and one concrete repair_guidance sentence of at most 240 characters. Name the exact omitted choice, substituted target, or wrong destination. When no supplied typed effect composition can faithfully encode the choice, explicitly say to remove the action rather than downgrade or redirect it. Shape: {\"verdicts\":[{\"action_index\":0,\"result\":\"match\",\"mismatch_kind\":null,\"repair_guidance\":null}]}"; @@ -1494,8 +1502,13 @@ impl ModelAgentTool for CellInterpreterWorkbench { action: Self::Action, context: &ModelAgentToolContext, ) -> ModelAgentToolOutcome { - match action { - CellInterpreterAgentAction::Submit { decisions } => { + match ( + action.kind, + action.decisions, + action.subject_id, + action.decision, + ) { + (CellInterpreterAgentTool::Submit, Some(decisions), None, None) => { if !self.draft.is_empty() { return ModelAgentToolOutcome::Rejected { finding: CellInterpreterFinding::SubmitRequiresEmptyDraft { @@ -1508,10 +1521,7 @@ impl ModelAgentTool for CellInterpreterWorkbench { self.draft = decisions; self.compile_draft(&context.source_receipt_ids).await } - CellInterpreterAgentAction::UpsertDecision { - subject_id, - decision, - } => { + (CellInterpreterAgentTool::UpsertDecision, None, Some(subject_id), Some(decision)) => { if !self.active_subject_ids.contains(&subject_id) { return ModelAgentToolOutcome::Rejected { finding: CellInterpreterFinding::UnknownDecisionOwner { @@ -1536,7 +1546,7 @@ impl ModelAgentTool for CellInterpreterWorkbench { self.draft.insert(subject_id, decision); self.compile_draft(&context.source_receipt_ids).await } - CellInterpreterAgentAction::RemoveDecision { subject_id } => { + (CellInterpreterAgentTool::RemoveDecision, None, Some(subject_id), None) => { if self.draft.is_empty() { return ModelAgentToolOutcome::Rejected { finding: CellInterpreterFinding::DraftRequired, @@ -1556,8 +1566,19 @@ impl ModelAgentTool for CellInterpreterWorkbench { self.draft.remove(&subject_id); self.compile_draft(&context.source_receipt_ids).await } - CellInterpreterAgentAction::InspectDraft => ModelAgentToolOutcome::Continue { - observation: self.progress(), + (CellInterpreterAgentTool::InspectDraft, None, None, None) => { + ModelAgentToolOutcome::Continue { + observation: self.progress(), + receipts: Vec::new(), + } + } + (kind, decisions, subject_id, decision) => ModelAgentToolOutcome::Rejected { + finding: CellInterpreterFinding::InvalidActionShape { + requested_tool: kind, + decisions_present: decisions.is_some(), + subject_id_present: subject_id.is_some(), + decision_present: decision.is_some(), + }, receipts: Vec::new(), }, } @@ -3029,49 +3050,25 @@ fn cell_interpreter_agent_schema( .and_then(serde_json::Value::as_object) .ok_or_else(|| anyhow!("cell appraisal schema has no exact decision owners"))?; let allowed_subject_ids = decision_properties.keys().cloned().collect::>(); - let mut commands = vec![serde_json::json!({ - "type":"object", - "additionalProperties":false, - "required":["kind","decisions"], - "properties":{ - "kind":{"const":"submit"}, - "decisions":decisions_schema - } - })]; - commands.extend( - decision_properties - .iter() - .map(|(subject_id, decision_schema)| { - serde_json::json!({ - "type":"object", - "additionalProperties":false, - "required":["kind","subject_id","decision"], - "properties":{ - "kind":{"const":"upsert_decision"}, - "subject_id":{"const":subject_id}, - "decision":decision_schema - } - }) - }), - ); - commands.push(serde_json::json!({ - "type":"object", - "additionalProperties":false, - "required":["kind","subject_id"], - "properties":{ - "kind":{"const":"remove_decision"}, - "subject_id":{"type":"string","enum":allowed_subject_ids} - } - })); - commands.push(serde_json::json!({ + let mut decision_alternatives = decision_properties.values().cloned().collect::>(); + decision_alternatives.push(serde_json::json!({"type":"null"})); + Ok(serde_json::json!({ + "$schema":"https://json-schema.org/draft/2020-12/schema", "type":"object", "additionalProperties":false, "required":["kind"], - "properties":{"kind":{"const":"inspect_draft"}} - })); - Ok(serde_json::json!({ - "$schema":"https://json-schema.org/draft/2020-12/schema", - "oneOf":commands + "properties":{ + "kind":{ + "type":"string", + "enum":["submit","upsert_decision","remove_decision","inspect_draft"] + }, + "decisions":{"anyOf":[decisions_schema,{"type":"null"}]}, + "subject_id":{"anyOf":[ + {"type":"string","enum":allowed_subject_ids}, + {"type":"null"} + ]}, + "decision":{"anyOf":decision_alternatives} + } })) } @@ -4127,8 +4124,9 @@ mod tests { }; let first = workbench .invoke( - CellInterpreterAgentAction::Submit { - decisions: BTreeMap::from([ + CellInterpreterAgentAction { + kind: CellInterpreterAgentTool::Submit, + decisions: Some(BTreeMap::from([ ( "faction-06".into(), institution_decision( @@ -4147,7 +4145,9 @@ mod tests { "institution:faction-07", ), ), - ]), + ])), + subject_id: None, + decision: None, }, &context, ) @@ -4164,8 +4164,11 @@ mod tests { let wholesale_resubmit = workbench .invoke( - CellInterpreterAgentAction::Submit { - decisions: BTreeMap::new(), + CellInterpreterAgentAction { + kind: CellInterpreterAgentTool::Submit, + decisions: Some(BTreeMap::new()), + subject_id: None, + decision: None, }, &context, ) @@ -4179,14 +4182,16 @@ mod tests { )); let unrelated_repair = workbench .invoke( - CellInterpreterAgentAction::UpsertDecision { - subject_id: "faction-07".into(), - decision: institution_decision( + CellInterpreterAgentAction { + kind: CellInterpreterAgentTool::UpsertDecision, + decisions: None, + subject_id: Some("faction-07".into()), + decision: Some(institution_decision( "faction-07", "rewrite-seven", "replace the already accepted course", "institution:faction-07", - ), + )), }, &context, ) @@ -4202,14 +4207,16 @@ mod tests { let second = workbench .invoke( - CellInterpreterAgentAction::UpsertDecision { - subject_id: "faction-06".into(), - decision: institution_decision( + CellInterpreterAgentAction { + kind: CellInterpreterAgentTool::UpsertDecision, + decisions: None, + subject_id: Some("faction-06".into()), + decision: Some(institution_decision( "faction-06", "withhold-six", "withhold pending the verified count", "institution:faction-06", - ), + )), }, &context, ) @@ -4227,6 +4234,25 @@ mod tests { 1, "the unchanged accepted action must not repay its semantic verifier" ); + + let invalid_shape = workbench + .invoke( + CellInterpreterAgentAction { + kind: CellInterpreterAgentTool::InspectDraft, + decisions: Some(BTreeMap::new()), + subject_id: None, + decision: None, + }, + &context, + ) + .await; + assert!(matches!( + invalid_shape, + ModelAgentToolOutcome::Rejected { + finding: CellInterpreterFinding::InvalidActionShape { .. }, + .. + } + )); } #[test] @@ -4338,6 +4364,8 @@ mod tests { assert!(schema.pointer("/properties/inactions").is_none()); let agent_schema = cell_interpreter_agent_schema(&schema).unwrap(); let agent_schema_text = serde_json::to_string(&agent_schema).unwrap(); + assert_eq!(agent_schema["type"], "object"); + assert!(agent_schema.get("oneOf").is_none()); assert!(agent_schema_text.contains("upsert_decision")); assert!(agent_schema_text.contains("inspect_draft")); assert!(agent_schema_text.contains("\"maxLength\":240")); @@ -4346,6 +4374,19 @@ mod tests { .unwrap() .is_valid(&serde_json::json!({"kind":"inspect_draft"})) ); + let mut provider_schema = agent_schema; + crate::model_connector::project_strict_responses_schema(&mut provider_schema).unwrap(); + assert_eq!(provider_schema["type"], "object"); + assert!( + jsonschema::validator_for(&provider_schema) + .unwrap() + .is_valid(&serde_json::json!({ + "kind":"inspect_draft", + "decisions":null, + "subject_id":null, + "decision":null + })) + ); assert_eq!( exact_constituent_effect_bundle_schema(&fixture_cell_slice().constituents[0]) .pointer("/properties/institution/anyOf/0/properties/posture/maxLength"), diff --git a/crates/ghostlight-dungeon/src/scheduler.rs b/crates/ghostlight-dungeon/src/scheduler.rs index 8afeb2d..11c6481 100644 --- a/crates/ghostlight-dungeon/src/scheduler.rs +++ b/crates/ghostlight-dungeon/src/scheduler.rs @@ -1551,7 +1551,7 @@ mod tests { .as_ref() .and_then(|schema| { schema - .pointer("/oneOf/0/properties/decisions/properties") + .pointer("/properties/decisions/anyOf/0/properties") .and_then(serde_json::Value::as_object) }) .map(|properties| properties.keys().cloned().collect::>()) diff --git a/notes/ghostlight-current-system-map.md b/notes/ghostlight-current-system-map.md index 8495dbb..e96915e 100644 --- a/notes/ghostlight-current-system-map.md +++ b/notes/ghostlight-current-system-map.md @@ -198,6 +198,9 @@ The Interpreter is a bounded model agent over a private workbench. Its efficient first action may submit the complete exact decision map only while the draft is empty. A rejected draft stays in the tool; later actions may upsert or remove only the exact decisions named as missing or rejected, or inspect the draft. +Its action wire is one strict root object with a typed `kind` discriminant and +nullable payload slots. The workbench owns the legal tool/payload combinations; +an invalid combination becomes a typed agent finding and cannot touch the draft. The tool structurally rejects whole-draft replacement and edits to unrelated accepted decisions. Local validation returns a typed `local_validation` finding and the semantic verifier returns exact subject-scoped mismatch @@ -291,11 +294,13 @@ the Interpreter still receives only exact effect permissions. A promise does not become a hard-coded behavior rule, but it cannot disappear merely because the actor entered offscreen simulation. -The Interpreter output schema is conditional on exact decision-owner ID. +The Interpreter decision schema is derived from every exact decision-owner ID. Institution, actor, Gestalt, and named-member effect variants cannot cross -subjects. Target IDs, canonical locations, pressure resolutions, movement -destinations, state references, and public channels are enumerated from that -subject's permitted slice. Movement and population-migration variants disappear +subjects: complete submits bind decisions by owner-key, while incremental edits +are rebound and validated under the selected owner by the workbench. Target IDs, +canonical locations, pressure resolutions, movement destinations, state +references, and public channels are enumerated from that subject's permitted +slice. Movement and population-migration variants disappear when the subject has no exact destination; target-requiring activities cannot emit an empty target list. Semantic correction therefore judges meaning rather than repairing type combinations local code already knows are impossible.