Add WorldPatch::sets_persona_of_existing_subject (PA.f61 library seam)

Dungeon must refuse a play-agent authoring run that rewrites an existing
subject's persona material, but WorldPatch's declarations/operations fields
are pub(crate), so a consumer cannot inspect the decoded patch by hand. Add
one read-only query the library owns: true when any SetPersonaMaterial
operation targets Ref::Existing rather than a same-patch Ref::Draft handle.
Owner: ghostlight::patch::WorldPatch. Consumer: ghostlight-dungeon's play
agent (commit_authoring_run), landing in the next commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-22 17:08:37 +02:00
commit a5329a9ba3

View file

@ -1247,6 +1247,28 @@ pub struct WorldPatch {
pub(crate) evidence: Vec<EvidenceRef>,
}
impl WorldPatch {
/// Whether any `SetPersonaMaterial` operation in this patch targets a
/// subject the patch does not itself declare — an existing, canonical
/// subject (`Ref::Existing`) rather than a draft handle this same patch's
/// own declarations introduced (`Ref::Draft`). `WorldPatch`'s fields are
/// `pub(crate)`, so a consumer that must refuse this shape (PA.f61: the
/// play agent may author a brand-new Persona's material, but never
/// rewrite an existing one's) reads it through this query rather than
/// parsing the patch's own JSON to decide.
pub fn sets_persona_of_existing_subject(&self) -> bool {
self.operations.iter().any(|operation| {
matches!(
operation,
ComponentOp::SetPersonaMaterial {
subject: Ref::Existing(_),
..
}
)
})
}
}
/// The one byte bound on a `WorldPatch` frame from any external source, and
/// the three item bounds on a `WorldPatch` as a value. One owner, two
/// consumers: the consumer ingress decodes against them through
@ -7711,6 +7733,43 @@ mod tests {
CallerId, CommandBody, CommandId, KernelError, SubmitReceipt, WorldKernel, WorldPhase,
};
/// Owner: `WorldPatch::sets_persona_of_existing_subject`. Consumer:
/// `ghostlight-dungeon`'s play agent (PA.f61), which refuses a
/// `set_persona_material` run whose patch answers true here, since
/// `WorldPatch`'s own fields are `pub(crate)` and Dungeon may not parse
/// its JSON to decide the question itself.
#[test]
fn sets_persona_of_existing_subject_reads_the_subject_refs_own_shape() {
let empty = WorldPatch::default();
assert!(!empty.sets_persona_of_existing_subject());
let existing = WorldPatch {
declarations: Vec::new(),
operations: vec![ComponentOp::SetPersonaMaterial {
subject: Ref::Existing(SubjectId::issue()),
values: Vec::new(),
voice: Statement::new("flat and even").unwrap(),
memories: Vec::new(),
reads: Vec::new(),
}],
evidence: Vec::new(),
};
assert!(existing.sets_persona_of_existing_subject());
let draft = WorldPatch {
declarations: Vec::new(),
operations: vec![ComponentOp::SetPersonaMaterial {
subject: Ref::Draft(DraftHandle::new("npc")),
values: Vec::new(),
voice: Statement::new("flat and even").unwrap(),
memories: Vec::new(),
reads: Vec::new(),
}],
evidence: Vec::new(),
};
assert!(!draft.sets_persona_of_existing_subject());
}
fn entity(handle: &str, label: &str, kind: EntityKind) -> Declaration {
Declaration::Entity(EntityDeclaration {
handle: DraftHandle::new(handle),