K6d: affordances from what the turn holds, not what the request asks (map 16.19.5, 16.19.6)

Perceive only when the room read succeeded; Speak only with a mouth to
send through, a room, and the Interpreter running this turn. The turn
line says plainly what is missing ("no room reaches her", "she can say
nothing"). The derived "nothing she does here builds..." sentence is
shown to go when an affordance of kind write exists (a test-only
variant).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 15:24:00 +01:00
commit 617b331fbd
4 changed files with 68 additions and 29 deletions

View file

@ -113,16 +113,19 @@ pub struct Organs<'a> {
}
/// One thing she can do this turn, typed by what it does (map 16.6, 16.18). Derived by `affordances` from what the turn
/// runs with, never written in state or in guidance. C3b adds `Read` from the Interpreter's tool list and K12 adds
/// `Suggest`; neither is listed before the organ that backs it exists, so she is never told she can do what this turn
/// cannot.
/// actually holds, never written in state or in guidance, nor taken from what the request asks for (map 16.19.5). C3b
/// adds `Read` from the Interpreter's tool list and K12 adds `Suggest`; neither is listed before the organ that backs it
/// exists, so she is never told she can do what this turn cannot.
#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize)]
#[serde(rename_all = "snake_case")]
pub(crate) enum Affordance {
/// The room reaches her as typed lines: the mouth's `RoomLine` carries text only, and Select renders no images.
Perceive,
/// She says whole lines of her prose in the turn's room (`interpret`).
/// She sends a draft of hers in the turn's room (`interpret`).
Speak,
/// A test's stand-in for the first affordance that builds, changes or ships something (map 16.19.6): none exists yet.
#[cfg(test)]
TestWrite,
}
impl Affordance {
@ -131,15 +134,22 @@ impl Affordance {
pub(crate) fn writes(self) -> bool {
match self {
Self::Perceive | Self::Speak => false,
#[cfg(test)]
Self::TestWrite => true,
}
}
}
/// What this turn can do, from the organs it runs with and the turn's room (`select::turn_room`): the room's lines reach
/// her when there is a mouth to read them, and she can speak when the turn has a room, the only one the Interpreter lets
/// her speak in.
pub(crate) fn affordances(organs: &Organs, room: Option<&str>) -> Vec<Affordance> {
[(organs.chat.is_some(), Affordance::Perceive), (room.is_some(), Affordance::Speak)].into_iter().filter_map(|(can, affordance)| can.then_some(affordance)).collect()
/// What this turn can do, from what it holds (map 16.19.5):
/// - `Perceive` when the room was read: the mouth's read returned (a harness fixture's and the simulated room's always
/// do). A failed read, or no mouth, and no room reaches her.
/// - `Speak` when the turn has a port her words go out through and a step that sends them: a mouth (the live mouth the
/// commit sends through, a fixture's, or the simulated room), a room to speak in (`select::turn_room`, the only one the
/// Interpreter lets her speak in), and the Interpreter running this turn. A run that stops at the Projector or the
/// Persona says nothing, and its packet says she can say nothing.
pub(crate) fn affordances(organs: &Organs, read: bool, room: Option<&str>, through: Through) -> Vec<Affordance> {
let speaks = organs.chat.is_some() && room.is_some() && through == Through::Interpreter;
[(read, Affordance::Perceive), (speaks, Affordance::Speak)].into_iter().filter_map(|(can, affordance)| can.then_some(affordance)).collect()
}
/// How far a render runs: the Projector's narration, or on through the Persona stage to her prose.
@ -359,7 +369,7 @@ pub fn project(organs: &Organs, request: &Request, now: DateTime<Utc>) -> Result
let history = History { recent: request.recent.clone(), ..History::default() };
let people = People { operators: &request.operators, minds: &request.minds, own_sender: &request.own_sender };
let inputs = Inputs { kind: request.kind, state: &state, room: &room, history: &history, observation: None, people, now, seed: request.seed, affordances: &[] };
let can = affordances(organs, turn_room(&inputs));
let can = affordances(organs, room_report["read"] == true, turn_room(&inputs), request.through);
let inputs = Inputs { affordances: &can, ..inputs };
let mut report = json!({

View file

@ -370,7 +370,7 @@ fn the_interpreter_is_told_what_he_can_do_here_from_the_packets_affordances() {
assert!(prompt.contains("missing_affordance when his thought reaches for something his body cannot do this turn"), "{prompt}");
let mut listening = packet();
listening.affordances = vec![Affordance::Perceive];
assert!(speech_prompt(&listening, "x", "y", &Tuning::default()).contains("What he can do here:\nThis turn the room reaches him as typed lines; nothing"), "derived from the affordances, not a constant");
assert!(speech_prompt(&listening, "x", "y", &Tuning::default()).contains("What he can do here:\nThis turn the room reaches him as typed lines, and he can say nothing; nothing"), "derived from the affordances, not a constant");
}
#[test]

View file

@ -1261,14 +1261,14 @@ pub(crate) fn capitalized(word: &str) -> String {
/// Interpreter's "What she can do here" are this text. It ends with "nothing she does here builds, changes or ships
/// anything" exactly when no affordance writes (`Affordance::writes`): a derived sentence, never a constant.
pub(crate) fn turn_words(can: &[Affordance], her: Forms) -> String {
let clauses: Vec<String> = can
.iter()
.map(|affordance| match affordance {
Affordance::Perceive => format!("the room reaches {} as typed lines", her.obj),
Affordance::Speak => format!("{} can answer in the turn's room by typing lines of {} own", her.subj, her.poss),
})
.collect();
let mut words = if clauses.is_empty() { format!("this turn no room reaches {} and {} can say nothing", her.obj, her.subj) } else { format!("this turn {}", clauses.join(", and ")) };
let has = |affordance: Affordance| can.contains(&affordance);
let clauses = [
if has(Affordance::Perceive) { format!("the room reaches {} as typed lines", her.obj) } else { format!("no room reaches {}", her.obj) },
if has(Affordance::Speak) { format!("{} can answer in the turn's room by typing lines of {} own", her.subj, her.poss) } else { format!("{} can say nothing", her.subj) },
];
#[cfg(test)]
let clauses: Vec<String> = clauses.into_iter().chain(has(Affordance::TestWrite).then(|| format!("{} can write", her.subj))).collect();
let mut words = format!("this turn {}", clauses.join(", and "));
if !can.iter().any(|affordance| affordance.writes()) {
let does = if her.s.is_empty() { "do" } else { "does" };
let _ = write!(words, "; nothing {} {does} here builds, changes or ships anything", her.subj);

View file

@ -268,10 +268,14 @@ fn a_state_with_one_sense_renders_it_and_a_state_with_none_only_the_turn_line()
fn the_turn_line_is_derived_from_the_affordances_alone() {
let her = select::forms(&state());
assert_eq!(select::turn_words(&[Affordance::Perceive, Affordance::Speak], her), "this turn the room reaches her as typed lines, and she can answer in the turn's room by typing lines of her own; nothing she does here builds, changes or ships anything");
assert_eq!(select::turn_words(&[Affordance::Perceive], her), "this turn the room reaches her as typed lines; nothing she does here builds, changes or ships anything");
assert_eq!(select::turn_words(&[], her), "this turn no room reaches her and she can say nothing; nothing she does here builds, changes or ships anything");
assert_eq!(select::turn_words(&[Affordance::Perceive], her), "this turn the room reaches her as typed lines, and she can say nothing; nothing she does here builds, changes or ships anything");
assert_eq!(select::turn_words(&[Affordance::Speak], her), "this turn no room reaches her, and she can answer in the turn's room by typing lines of her own; nothing she does here builds, changes or ships anything");
assert_eq!(select::turn_words(&[], her), "this turn no room reaches her, and she can say nothing; nothing she does here builds, changes or ships anything");
let them = select::forms(&json!({ "presentation": { "pronouns": "any" } }));
assert!(select::turn_words(&[Affordance::Speak], them).ends_with("nothing they do here builds, changes or ships anything"));
// The sentence is derived (map 16.19.6): the first affordance of kind write removes it.
let writes = select::turn_words(&[Affordance::Perceive, Affordance::Speak, Affordance::TestWrite], her);
assert!(writes.ends_with(", and she can write") && !writes.contains("builds, changes or ships"), "{writes}");
// The longest turn line and the heading fit the least body guard the tuning allows.
for forms in [her, them, select::forms(&json!({ "presentation": { "pronouns": "he/him" } }))] {
let longest = format!("Their body:\n- {}.\n", select::turn_words(CAN, forms));
@ -279,20 +283,45 @@ fn the_turn_line_is_derived_from_the_affordances_alone() {
}
}
/// A mouth whose read fails.
struct Deaf;
impl MouthReader for Deaf {
fn pending(&self) -> Result<ChatPending> {
anyhow::bail!("the mouth did not answer")
}
}
#[test]
fn what_the_turn_can_do_comes_from_its_organs_and_its_room() {
fn what_the_turn_can_do_comes_from_what_it_holds() {
let chat = mouth();
let with = Organs { persona: None, chat: Some(&chat), addressing: None, model: None };
let without = Organs { chat: None, ..with };
assert_eq!(affordances(&with, Some("#swarm:gamecult.org")), [Affordance::Perceive, Affordance::Speak]);
assert_eq!(affordances(&with, None), [Affordance::Perceive], "no room, nowhere to speak");
assert_eq!(affordances(&without, Some("#swarm:gamecult.org")), [Affordance::Speak], "no mouth, no room reaches her");
// Through `project`: the packet carries what its organs can do; the request's room is the turn's.
let room = Some("#swarm:gamecult.org");
assert_eq!(affordances(&with, true, room, Through::Interpreter), [Affordance::Perceive, Affordance::Speak]);
assert_eq!(affordances(&with, true, None, Through::Interpreter), [Affordance::Perceive], "no room, nowhere to speak");
assert_eq!(affordances(&with, false, room, Through::Interpreter), [Affordance::Speak], "a failed read: no room reaches her");
assert_eq!(affordances(&without, false, room, Through::Interpreter), [], "a room and no send port: she can say nothing");
for through in [Through::Projector, Through::Persona] {
assert_eq!(affordances(&with, true, room, through), [Affordance::Perceive], "{through:?}: no Interpreter runs, so nothing she writes goes out");
}
// Through `project`: what the packet says she can do is what the turn held, not what the request asked for.
let dir = tempfile::tempdir().unwrap();
let stored = Stored(state());
let report = project(&Organs { persona: Some(&stored), ..without }, &request(dir.path(), None, None), now()).unwrap();
assert!(report["packet"]["context"].as_str().unwrap().contains("Her body:\n- this turn she can answer in the turn's room by typing lines of her own;"), "{}", report["packet"]["context"]);
assert_eq!(report["packet"]["affordances"], json!(["speak"]));
let context = |organs: &Organs, through: Through| {
let report = project(&Organs { persona: Some(&stored), ..*organs }, &Request { through, ..request(dir.path(), None, None) }, now()).unwrap();
(report["packet"]["context"].as_str().unwrap().to_owned(), report["packet"]["affordances"].clone())
};
let (body, can) = context(&without, Through::Interpreter);
assert!(body.contains("Her body:\n- this turn no room reaches her, and she can say nothing;"), "{body}");
assert_eq!(can, json!([]));
let deaf = Deaf;
let (body, can) = context(&Organs { chat: Some(&deaf), ..with }, Through::Interpreter);
assert!(body.contains("Her body:\n- this turn no room reaches her, and she can answer in the turn's room by typing lines of her own;"), "{body}");
assert_eq!(can, json!(["speak"]));
let (body, can) = context(&with, Through::Persona);
assert!(body.contains("Her body:\n- this turn the room reaches her as typed lines, and she can say nothing;"), "{body}");
assert_eq!(can, json!(["perceive"]));
}
#[test]