From bdb6f2fd69f697c725fe6e0a06430efa927e52a4 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 22 Nov 2026 01:06:18 +0100 Subject: [PATCH] Persona K34: Needs is read through its shape, so request on a words or lacking need is malformed; one NeedsKind Co-Authored-By: Claude Opus 5.5 --- crates/mind-body/src/projection/commit.rs | 37 ++++++++++++++++++-- crates/mind-body/src/projection/interpret.rs | 10 +----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/crates/mind-body/src/projection/commit.rs b/crates/mind-body/src/projection/commit.rs index 1525dfd..9979fae 100644 --- a/crates/mind-body/src/projection/commit.rs +++ b/crates/mind-body/src/projection/commit.rs @@ -60,15 +60,48 @@ pub(crate) enum How { /// What keeping a promise needs (map 16.25.2): her words alone, from what she already has; a read of `request`; or /// something this body has no way to do. Code owns what each kind requires of a kept close (`apply_one`), and derives -/// whether the promise opens or is blocked from it. A field no kind names makes it no `Needs`, as P1 holds it (map 16.27). +/// whether the promise opens or is blocked from it. It is read through its shape (`NeedsShape`): a field no kind names, +/// `request` on a kind other than `read`, makes it no `Needs`, as P1 holds it (map 16.27). #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)] +#[serde(tag = "kind", rename_all = "snake_case", try_from = "NeedsShape")] pub(crate) enum Needs { Words, Read { request: ReadRequest }, Lacking, } +/// What kind of thing keeping a promise needs: `Needs` without its read. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] +#[serde(rename_all = "snake_case")] +pub(crate) enum NeedsKind { + Words, + Read, + Lacking, +} + +/// `Needs` as it is written: its kind, and a request only for a read; nothing else. +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +struct NeedsShape { + kind: NeedsKind, + #[serde(default)] + request: Option, +} + +impl TryFrom for Needs { + type Error = &'static str; + + fn try_from(shape: NeedsShape) -> Result { + match (shape.kind, shape.request) { + (NeedsKind::Words, None) => Ok(Self::Words), + (NeedsKind::Lacking, None) => Ok(Self::Lacking), + (NeedsKind::Read, Some(request)) => Ok(Self::Read { request }), + (NeedsKind::Read, None) => Err("a read need names its request"), + (NeedsKind::Words | NeedsKind::Lacking, Some(_)) => Err("only a read need names a request"), + } + } +} + /// One state change the Interpreter proposes. `promise` names an open promise by its id in the Interpreter's list. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(tag = "kind", rename_all = "snake_case")] diff --git a/crates/mind-body/src/projection/interpret.rs b/crates/mind-body/src/projection/interpret.rs index cd6a903..4eafd92 100644 --- a/crates/mind-body/src/projection/interpret.rs +++ b/crates/mind-body/src/projection/interpret.rs @@ -43,7 +43,7 @@ use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; use super::Affordance; -use super::commit::{Evidence, How, Needs, Proposal}; +use super::commit::{Evidence, How, Needs, NeedsKind, Proposal}; use super::read::{self, Asked, Kind, QUOTE_MIN_WORDS, ReadRequest, SPAN_MIN_WORDS}; use super::narrate::{Model, heard_overlap, lived_stream, words}; use super::select::{Forms, Packet, capitalized, named_pronouns, spoken, turn_words, voiced}; @@ -427,14 +427,6 @@ struct ProposedNeeds { read: Option, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] -#[serde(rename_all = "snake_case")] -enum NeedsKind { - Words, - Read, - Lacking, -} - /// A read a promise needs, as the answer names it: a read's kind and target, with no quote. #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)]