neosian 3.0.3

The state layer for LLM agents, as one static binary: the record, memory and the state process
//! Client readers (A1): a native session's hooks, and the client's own files
//! where its hooks do not carry a turn whole, as the recorder's events.

pub mod agy;
pub mod agy_window;
mod bounded;
mod stage;
pub mod vibe;
mod vibe_journal;

use crate::conversation::Error;
use crate::profile::model::Capture;
use crate::record::land::Landed;
use crate::record::payload::Payload;
use crate::record::settings::Settings;
use crate::record::spool::Spool;
use crate::store::grammar::Actor;
use std::io::Write;

/// Whether a client reader files this agent's hook call: every call that
/// reaches the verb, but the harness watcher's own event, which only
/// `neosian harness-file` hands over (X6a, X6c U1).
pub fn reads(agent: &str, watched: bool) -> bool {
    matches!(agent, "agy" | "vibe") && !watched
}

/// One hook call of a client with a reader, under the session lock, after
/// consent and pause (the span's id, the writer, the event and the payload).
pub fn land(
    settings: &Settings,
    spool: &Spool,
    call: (&str, &Actor, &str, &Payload),
    policy: Option<&Capture>,
    err: &mut dyn Write,
) -> Result<Landed, Error> {
    if settings.agent == "vibe" {
        vibe::land(settings, spool, call, policy, err)
    } else {
        agy::land(settings, spool, call, policy, err)
    }
}

#[cfg(test)]
mod tests {
    use serde_json::{Map, Value, json};

    #[test]
    fn a_payload_shaped_like_the_watchers_is_read_as_the_clients_own() {
        // X6c U1: no payload shape skips the client reader; only the
        // watcher's own entry does.
        assert!(!super::reads("agy", true) && !super::reads("vibe", true));
        assert!(super::reads("agy", false) && super::reads("vibe", false));
        let nonce = "0123456789abcdef0123456789abcdef";
        let shaped = json!({"hook_event_name": "Stop", "generation_id": nonce, "session_id": "s"});
        let text = shaped.to_string();
        for agent in ["agy", "vibe"] {
            let parsed: Map<String, Value> =
                crate::record::payload::parse_payload(&text, agent).unwrap_or_default();
            assert_ne!(
                parsed.get("hook_event_name"),
                Some(&json!("Stop")),
                "{agent}"
            );
        }
    }
}