neosian 3.0.2

The state layer for LLM agents, as one static binary: the record, memory and the state process
//! The tool's prose (`assets/prompts/harness.yaml`): its description, its
//! parameters and every sentence it answers with, rendered here.

use crate::assets::{block, mapping, quoted, render};

pub const HARNESS: &str = include_str!(concat!(env!("NEOSIAN_ASSETS"), "/prompts/harness.yaml"));

pub fn description() -> String {
    block(HARNESS, "tool").expect("harness.yaml carries the tool")
}

pub fn params() -> Vec<(String, String)> {
    mapping(HARNESS, "params").expect("harness.yaml carries the params")
}

/// The sentence `key`, its `{{variables}}` filled.
pub fn say(key: &str, variables: &[(&str, &str)]) -> String {
    let template = quoted(HARNESS, key).unwrap_or_else(|| panic!("harness.yaml carries {key}"));
    render(&template, variables)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn every_sentence_the_tool_says_is_in_the_asset() {
        for key in [
            "running",
            "ended",
            "ended_unfiled",
            "stopped_note",
            "recorded",
            "not_recorded",
            "record_unknown",
            "record_failed",
            "record_pending",
            "record_off",
            "record_paused",
            "record_excluded",
            "record_gap",
            "record_bound",
            "record_session",
            "record_error",
            "record_elsewhere",
            "record_slow",
            "record_spool_unreadable",
            "linked",
            "link_written",
            "not_linked_session",
            "not_linked_absent",
            "not_linked_agent",
            "not_linked_mount",
            "not_linked_retry",
            "link_failed",
            "announced_existing",
            "output_cut",
            "answer_cut",
            "timed_out",
            "child_refused",
            "missing_harness",
            "none_available",
            "too_many",
            "busy",
            "stopped",
            "unknown_child",
            "no_session",
            "required",
            "bad_directory",
            "not_allowed",
            "need_directory",
            "bad_model",
            "bad_prompt",
            "bad_session",
            "bad_seconds",
            "bad_opencode_config",
            "spawn_failed",
            "codex_probe_failed",
            "codex_list_failed",
            "codex_unswitchable",
            "codex_unnamed",
            "codex_transport",
            "codex_transport_other",
            "signin_claude_code",
            "signin_codex",
            "signin_opencode",
            "signin_unknown",
            "signin_timeout",
            "signin_unstartable",
            "signin_unrecognized",
            "store_drifted",
            "child_store_changed",
            "pi_auth_lock",
            "cursor_worker_state",
            "cursor_worker_busy",
            "program_writable",
            "store_busy",
            "session_unchecked",
            "opencode_agent",
            "watcher_lost",
            "watch_off",
            "watch_bad_field",
            "watch_missing",
            "config_unreadable",
            "config_table",
            "config_enabled",
            "config_bounded",
            "config_directories",
            "config_unknown",
            "policy_presets",
            "sandbox_missing",
            "sandbox_refused",
            "sandbox_unenforced",
            "sandbox_no_store",
            "session_collided",
            "record_stopped",
            "stopped_recorded",
            "sandbox_store_unknown",
            "sandbox_path",
            "sandbox_home",
            "sandbox_state",
            "signin_pi",
            "signin_pi_no_model",
            "signin_invalid",
            "signin_no_model",
            "signin_no_agent_dir",
            "pi_no_mcp",
            "pi_incomplete",
            "pi_session_absent",
            "pi_session_ambiguous",
            "pi_session_replaced",
            "pi_session_dir",
            "pi_login_readable",
            "signin_cursor",
            "cursor_macos_only",
            "cursor_untrusted",
            "session_unclaimed",
            "cursor_chat_state",
            "cursor_chats_many",
            "signin_vibe",
            "vibe_home_refused",
            "no_mcp",
            "child_memory",
            "muse_no_mcp",
            "signin_muse",
            "muse_auth_file",
            "home_refused",
            "muse_session_dir",
        ] {
            let sentence = say(key, &[]);
            assert!(
                !sentence.is_empty() && !sentence.contains('\u{2014}'),
                "{key}"
            );
        }
        assert!(description().contains("read-only"));
        let names: Vec<String> = params().into_iter().map(|(name, _)| name).collect();
        assert_eq!(
            names,
            [
                "command",
                "agent",
                "prompt",
                "mode",
                "model",
                "directory",
                "child",
                "session",
                "seconds"
            ]
        );
        assert_eq!(
            say("busy", &[("child", "h1")]),
            "Child h1 is still running a turn; wait for it or stop it first."
        );
    }
}