neosian 3.0.0

The state layer for LLM agents, as one static binary: the record, memory and the state process
//! Cursor's plan and display reading (X5b). The stream lines follow the
//! installed 2026.09.10-fd3934a print handler (source-derived: no turn has
//! run here); tool calls are in the protobuf JSON form it prints.

use std::path::Path;

use serde_json::{Value, json};

use super::super::adapter::{Agent, Mode, Request, plan as adapter_plan};
use super::super::events::Event;

const CHAT: &str = "0e6a1c2b-3f4d-4e5a-8b9c-0d1e2f3a4b5c";

fn request<'a>(mode: Mode, resume: Option<&'a str>, model: Option<&'a str>) -> Request<'a> {
    Request {
        agent: Agent::Cursor,
        mode,
        model,
        directory: Path::new("/Users/person/work/app"),
        resume,
        new_session: "5eab6b3f-d0af-49c3-9c0c-a9b47c2c8ebe",
        private: Path::new("/tmp/neosian-harness-x"),
        codex_keys: &[],
        opencode_config: None,
        parent: Some("parent-1"),
        server: None,
        codex_off: &[],
        confined: true,
        pi: None,
        child_home: None,
        memory: None,
    }
}

#[test]
fn both_modes_run_the_planned_argv_with_the_prompt_on_stdin_only() {
    let head = [
        "cursor-agent",
        "-p",
        "--output-format",
        "stream-json",
        "--trust",
        "--workspace",
        "/Users/person/work/app",
        "--sandbox",
        "disabled",
    ];
    let read_only = adapter_plan(&request(Mode::ReadOnly, None, None)).unwrap();
    assert_eq!(read_only.argv, [&head[..], &["--mode", "ask"]].concat());
    let write = adapter_plan(&request(Mode::Write, Some(CHAT), Some("gpt-5"))).unwrap();
    let tail = ["--force", "--model", "gpt-5", "--resume", CHAT];
    assert_eq!(write.argv, [&head[..], &tail[..]].concat());
    let set = |plan: &super::super::adapter::Plan, key: &str, value: &str| {
        plan.env.contains(&(key.to_string(), value.to_string()))
    };
    for plan in [&read_only, &write] {
        assert!(
            !plan
                .argv
                .iter()
                .any(|w| w == "--approve-mcps" || w == "enabled")
        );
        assert!(set(plan, "NODE_DISABLE_COMPILE_CACHE", "1"));
        assert!(set(plan, "NEOSIAN_HARNESS_CHILD", "1"));
    }
    // A first turn's chat is Cursor's, so no session variable is set.
    assert!(
        !read_only
            .env
            .iter()
            .any(|(k, _)| k == "NEOSIAN_HARNESS_SESSION")
    );
    assert!(set(&write, "NEOSIAN_HARNESS_SESSION", CHAT));
}

fn shown(line: Value) -> Vec<Event> {
    Agent::Cursor.read(&line.to_string())
}

#[test]
fn the_display_shows_the_chat_chunks_tools_and_the_result() {
    let init = json!({"type": "system", "subtype": "init", "apiKeySource": "login",
        "cwd": "/w", "session_id": CHAT, "model": "Auto", "permissionMode": "default"});
    assert_eq!(shown(init), [Event::Session(CHAT.into())]);
    let chunk = json!({"type": "assistant", "message": {"role": "assistant",
        "content": [{"type": "text", "text": "Reading it."}]}, "session_id": CHAT});
    assert_eq!(shown(chunk), [Event::Text("Reading it.".into())]);
    let mcp = json!({"type": "tool_call", "subtype": "completed", "call_id": "c1",
        "tool_call": {"mcpToolCall": {"args": {"name": "x", "providerIdentifier": "srv",
            "toolName": "find", "args": {}}, "result": {"success": {"content": []}}}},
        "session_id": CHAT});
    let Event::Observed(entry) = &shown(mcp)[0] else {
        panic!("an entry")
    };
    assert_eq!(entry["name"], "mcp__srv__find");
    assert_eq!(entry["status"], "completed");
    assert_eq!(entry["result"], "success");
    let done = json!({"type": "result", "subtype": "success", "is_error": false,
        "result": "banana", "session_id": CHAT});
    assert_eq!(shown(done), [Event::Answer("banana".into())]);
    let failed = json!({"type": "result", "subtype": "error", "is_error": true,
        "result": "no", "session_id": CHAT});
    assert_eq!(shown(failed), [Event::Failure("no".into())]);
}