Persona live organ: one-turn, drain, wake-humans-pace, turn memory (squash of hands/persona-live-drain) #83

Merged
eureka merged 287 commits from hands/persona-live-drain into main 2026-11-28 07:05:45 +00:00
4 changed files with 24 additions and 16 deletions
Showing only changes of commit d9e80efbe3 - Show all commits

persona: the put lives beside the drain, not in project; test fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Meta Vens 2026-11-27 21:17:29 +01:00

View file

@ -29,13 +29,14 @@ use anyhow::{Result, anyhow, bail};
use chrono::{DateTime, Utc};
use cultcache_rs::{CultCache, DatabaseEntry, SingleFileMessagePackBackingStore};
use eureka_pipeline::{MemoryOrigin, Slug};
use huginn_mind::{Faculty, HuginnMindResponse, MindRefusal, PersonaPutOutcome, PipelineProvenance};
use serde_json::{Value, json};
use crate::address::{Addressee, addresses, is_for, localpart};
use crate::chat_client::{Basis, Chat, ChatDelivery, TailLine};
use crate::control::{ControlSource, Effective, HeldReason, derive};
use crate::heartbeat::{HeartbeatView, Speaker, own_rooms, pending_facts, wakes};
use crate::projection::{DomainSource, Model, Mouth, Organs, PersonaStore, Put, ReadSource, Request, Taken, Through, TurnKind, apply_commit, history, own_addressee as heard_as, take};
use crate::projection::{DomainSource, HuginnPersonaSource, Model, Mouth, Organs, PersonaStore, Put, ReadSource, Request, Taken, Through, TurnKind, apply_commit, history, own_addressee as heard_as, take};
/// The admitting agent's name on what her Persona admitted; `self_run::inbox` still reads her briefs by it.
pub const AGENT: &str = "mind-persona";
@ -366,6 +367,20 @@ fn drain<C: Chat>(instance: &Slug, start: &Start<C>) -> Outcome {
Outcome::Drained { turns: taken.len(), acked_through: acked, put_refused: taken.iter().filter(|turn| turn.put_refused).count() }
}
/// Her put through the persona door, the one writer of her state a start has.
impl PersonaStore for HuginnPersonaSource {
fn put(&self, state: &Value, expected_updated_at: Option<&str>, session: &str) -> Result<Put> {
let short = |text: &str| eureka_pipeline::Short(text.to_owned());
let provenance = PipelineProvenance { faculty: Faculty::Member, agent: short(AGENT), session: short(session), tool: short(AGENT), imported_from: None };
match self.client().persona_put(provenance, state.clone(), expected_updated_at.map(str::to_owned)).map_err(|_| anyhow!("the mind could not be asked to put the persona"))? {
HuginnMindResponse::PersonaPut(PersonaPutOutcome::Committed { .. }) => Ok(Put::Committed),
HuginnMindResponse::PersonaPut(PersonaPutOutcome::Refused(MindRefusal::PersonaStale { .. })) | HuginnMindResponse::Refused(MindRefusal::PersonaStale { .. }) => Ok(Put::Stale),
HuginnMindResponse::PersonaPut(PersonaPutOutcome::Refused(refusal)) | HuginnMindResponse::Refused(refusal) => Ok(Put::Refused(format!("{refusal:?}"))),
_ => bail!("the mind answered the persona put with something else"),
}
}
}
/// Who sent a delivery, as the wake rule sees them.
fn speaker(config: &Config, delivery: &ChatDelivery) -> Speaker {
if delivery.sender == config.own_sender {

View file

@ -278,7 +278,7 @@ fn t_l2_stale_put_reapplies_once() {
let stored = rig.store.stored.borrow();
assert_eq!(stored["outside"], "kept", "the outside value survives");
let notes = stored["thoughtMemory"]["shortTerm"].as_array().unwrap();
assert!(notes.iter().any(|note| note["text"].as_str().is_some_and(|text| text.contains("glad to hear from Meta"))), "the same record is applied again to the fresh state: {notes:?}");
assert!(notes.iter().any(|note| note["summary"].as_str().is_some_and(|text| text.contains("glad to hear from Meta"))), "the same record is applied again to the fresh state: {notes:?}");
assert_eq!(rig.log().iter().filter(|event| *event == "put").count(), 2, "one stale put, one retry");
assert!(rig.trace.rows.borrow()[0].1.get("put_refused").is_none());
}

View file

@ -38,7 +38,7 @@ use std::path::PathBuf;
use anyhow::{Result, anyhow, bail};
use chrono::{DateTime, Utc};
use eureka_state::HuginnClient;
use huginn_mind::{Faculty, HuginnMindResponse, MindRefusal, PersonaPutOutcome, PipelineProvenance};
use huginn_mind::HuginnMindResponse;
use serde_json::{Value, json};
use crate::address::{Addressee, is_for, localpart};
@ -76,6 +76,11 @@ impl HuginnPersonaSource {
pub fn new(client: HuginnClient) -> Self {
Self { client }
}
/// The persona door's client, for the drain's put (`persona::carry`).
pub(crate) fn client(&self) -> &HuginnClient {
&self.client
}
}
impl PersonaSource for HuginnPersonaSource {
@ -104,19 +109,6 @@ pub trait PersonaStore: PersonaSource {
fn put(&self, state: &Value, expected_updated_at: Option<&str>, session: &str) -> Result<Put>;
}
impl PersonaStore for HuginnPersonaSource {
fn put(&self, state: &Value, expected_updated_at: Option<&str>, session: &str) -> Result<Put> {
let short = |text: &str| eureka_pipeline::Short(text.to_owned());
let provenance = PipelineProvenance { faculty: Faculty::Member, agent: short(AGENT), session: short(session), tool: short(AGENT), imported_from: None };
match self.client.persona_put(provenance, state.clone(), expected_updated_at.map(str::to_owned)).map_err(|_| anyhow!("the mind could not be asked to put the persona"))? {
HuginnMindResponse::PersonaPut(PersonaPutOutcome::Committed { .. }) => Ok(Put::Committed),
HuginnMindResponse::PersonaPut(PersonaPutOutcome::Refused(MindRefusal::PersonaStale { .. })) | HuginnMindResponse::Refused(MindRefusal::PersonaStale { .. }) => Ok(Put::Stale),
HuginnMindResponse::PersonaPut(PersonaPutOutcome::Refused(refusal)) | HuginnMindResponse::Refused(refusal) => Ok(Put::Refused(format!("{refusal:?}"))),
_ => bail!("the mind answered the persona put with something else"),
}
}
}
/// The mouth, read: pending deliveries and the room tail, which acks nothing. The only chat port `project` holds.
pub trait MouthReader {
fn pending(&self) -> Result<ChatPending>;

View file

@ -91,6 +91,7 @@ fn t_l2_each_send_of_a_turn_has_its_own_id_and_its_own_rooms_basis() {
let basis = |request: &ChatSendRequest| request.basis.clone().unwrap();
assert_eq!(basis(&sent[0]), SendBasis { seen_event_id: Some("$newest".into()), since_unix_ms: 7 }, "the basis is the room's own newest event");
let elsewhere = Mouth { seen: BTreeMap::from([("#other:gamecult.org".to_owned(), "$elsewhere".to_owned())]), ..mouth(&chat) };
drop(sent);
chat.sent.borrow_mut().clear();
let _ = elsewhere.send("k:s0", "!dm-meta:gamecult.org", "hi", None, &[]);
assert_eq!(basis(&chat.sent.borrow()[0]), SendBasis { seen_event_id: None, since_unix_ms: 7 }, "another room's newest event is not this room's basis");