Something went wrong. Try again.
Personal fork of prime agent. Mirror of: https://mnemosyne.sigilzero.dev/sigilzero/prime-agent
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608//! Daemon command-type breadth coverage (roadmap item 7, wave 1): the TS//! `DAEMON_COMMAND_TYPES` list (daemon-supervisor.ts) is the accept contract,//! pinned below in declaration order. Every TS type (plus the Rust-native//! frames) must parse, keep its wire `type`, and route by selector. The//! removed `wait_for_headless_completion` is the one deliberate omission.
use pa_daemon::protocol::command_active_session_id;use pa_daemon::protocol::command_type_name;use pa_daemon::protocol::parse_daemon_command_line;use pa_daemon::protocol::KNOWN_COMMAND_TYPES;
/// TS `DAEMON_COMMAND_TYPES` in declaration order, minus the removed/// `wait_for_headless_completion` (modes/daemon/daemon-supervisor.ts).const TS_DAEMON_COMMAND_TYPES: &[&str] = &[ "ack_result", "list", "list_agent_peers", "get_direct_worker_transport", "roster_subscribe", "roster_unsubscribe", "list_saved_sessions", "create", "attach", "reattach", "detach", "complete_owned_session", "promote_owned_session", "kill", "rename", "prompt", "cancel_prompt_admission", "prompt_and_wait", "steer", "follow_up", "restore_next_turn", "restore_actions", "append_custom_message", "resume_queue", "send_message", "agent_messages_status", "agent_messages_pause", "agent_messages_resume", "agent_messages_clear", "abort", "abort_and_send_queued", "start_side_question", "abort_side_question", "execute_bash", "execute_bash_and_wait", "abort_bash", "cancel_rlm_child", "delete_rlm_subagent", "wait_for_idle", "get_session_header", "get_state", "get_connection_state", "get_messages", "get_rlm_children", "get_session_stats", "get_context_tree", "get_commands", "get_resource_snapshot", "replace_acp_mcp_servers", "get_model_catalog", "get_available_models", "get_queue", "mutate_queued_message", "clear_queue", "abort_and_clear_queue", "acquire_session_input_pause", "release_session_input_pause", "cron_list", "heartbeats_list", "heartbeat_manage", "cron_add", "cron_cancel", "heartbeat_get", "heartbeat_set", "heartbeat_update", "set_model", "cycle_model", "set_scoped_models", "set_thinking_level", "cycle_thinking_level", "set_service_tier", "set_transport", "set_steering_mode", "set_follow_up_mode", "set_auto_compaction", "set_auto_retry", "compact", "abort_compaction", "abort_branch_summary", "abort_retry", "reload", "new_session", "switch_session", "fork", "navigate_tree", "import_jsonl", "export_html", "export_jsonl", "set_session_name", "get_rlm_max_depth_status", "set_rlm_max_depth", "rename_saved_session", "delete_saved_session", "get_session_context", "get_session_tree", "get_user_messages_for_forking", "get_last_assistant_text", "get_system_prompt", "get_tool_definition", "set_session_entry_label", "prepare_update_restart", "retry_worker", "restart", "shutdown",];
/// Minimal wire fixture per command type: the fields the `DaemonCommand` union/// requires on the wire (everything else is optional or in the lossless `rest`/// map); the session selector is "sess" everywhere a command carries one.const WIRE_FIXTURES: &[(&str, &str)] = &[ ("ack_result", r#"{"type": "ack_result", "commandId": "c1"}"#), ("list", r#"{"type": "list"}"#), ( "list_agent_peers", r#"{"type": "list_agent_peers", "workerToken": "token"}"#, ), ( "get_direct_worker_transport", r#"{"type": "get_direct_worker_transport", "activeSessionId": "sess"}"#, ), ("roster_subscribe", r#"{"type": "roster_subscribe"}"#), ("roster_unsubscribe", r#"{"type": "roster_unsubscribe"}"#), ("list_saved_sessions", r#"{"type": "list_saved_sessions"}"#), ("create", r#"{"type": "create"}"#), ("attach", r#"{"type": "attach", "activeSessionId": "sess"}"#), ( "reattach", r#"{"type": "reattach", "activeSessionId": "sess", "targetActiveSessionId": "target"}"#, ), ("detach", r#"{"type": "detach"}"#), ( "complete_owned_session", r#"{"type": "complete_owned_session", "activeSessionId": "sess"}"#, ), ( "promote_owned_session", r#"{"type": "promote_owned_session", "activeSessionId": "sess"}"#, ), ("kill", r#"{"type": "kill", "activeSessionId": "sess"}"#), ( "rename", r#"{"type": "rename", "activeSessionId": "sess", "name": "x"}"#, ), ( "prompt", r#"{"type": "prompt", "activeSessionId": "sess", "message": "x"}"#, ), ( "cancel_prompt_admission", r#"{"type": "cancel_prompt_admission", "activeSessionId": "sess", "admissionId": "a1"}"#, ), ( "prompt_and_wait", r#"{"type": "prompt_and_wait", "activeSessionId": "sess", "message": "x"}"#, ), ( "steer", r#"{"type": "steer", "activeSessionId": "sess", "message": "x"}"#, ), ( "follow_up", r#"{"type": "follow_up", "activeSessionId": "sess", "message": "x"}"#, ), ( "restore_next_turn", r#"{"type": "restore_next_turn", "activeSessionId": "sess", "messages": [ ]}"#, ), ( "restore_actions", r#"{"type": "restore_actions", "activeSessionId": "sess", "snapshot": { }}"#, ), ( "append_custom_message", r#"{"type": "append_custom_message", "activeSessionId": "sess", "message": "x"}"#, ), ( "resume_queue", r#"{"type": "resume_queue", "activeSessionId": "sess"}"#, ), ( "send_message", r#"{"type": "send_message", "targetActiveSessionId": "target", "message": "x"}"#, ), ( "agent_messages_status", r#"{"type": "agent_messages_status"}"#, ), ( "agent_messages_pause", r#"{"type": "agent_messages_pause"}"#, ), ( "agent_messages_resume", r#"{"type": "agent_messages_resume"}"#, ), ( "agent_messages_clear", r#"{"type": "agent_messages_clear", "activeSessionId": "sess"}"#, ), ("abort", r#"{"type": "abort", "activeSessionId": "sess"}"#), ( "start_side_question", r#"{"type": "start_side_question", "activeSessionId": "sess", "sideQuestionId": "sq1", "question": "q"}"#, ), ( "abort_side_question", r#"{"type": "abort_side_question", "activeSessionId": "sess", "sideQuestionId": "sq1"}"#, ), ( "execute_bash", r#"{"type": "execute_bash", "activeSessionId": "sess", "command": "true"}"#, ), ( "execute_bash_and_wait", r#"{"type": "execute_bash_and_wait", "activeSessionId": "sess", "command": "true"}"#, ), ( "abort_bash", r#"{"type": "abort_bash", "activeSessionId": "sess"}"#, ), ( "cancel_rlm_child", r#"{"type": "cancel_rlm_child", "activeSessionId": "sess", "childId": "c1"}"#, ), ( "delete_rlm_subagent", r#"{"type": "delete_rlm_subagent", "activeSessionId": "sess", "childId": "c1"}"#, ), ( "wait_for_idle", r#"{"type": "wait_for_idle", "activeSessionId": "sess"}"#, ), ( "get_session_header", r#"{"type": "get_session_header", "activeSessionId": "sess"}"#, ), ( "get_state", r#"{"type": "get_state", "activeSessionId": "sess"}"#, ), ( "get_connection_state", r#"{"type": "get_connection_state", "activeSessionId": "sess"}"#, ), ( "get_messages", r#"{"type": "get_messages", "activeSessionId": "sess"}"#, ), ( "get_rlm_children", r#"{"type": "get_rlm_children", "activeSessionId": "sess"}"#, ), ( "get_session_stats", r#"{"type": "get_session_stats", "activeSessionId": "sess"}"#, ), ( "get_context_tree", r#"{"type": "get_context_tree", "activeSessionId": "sess"}"#, ), ( "get_commands", r#"{"type": "get_commands", "activeSessionId": "sess"}"#, ), ( "get_resource_snapshot", r#"{"type": "get_resource_snapshot", "activeSessionId": "sess"}"#, ), ( "replace_acp_mcp_servers", r#"{"type": "replace_acp_mcp_servers", "activeSessionId": "sess", "ownerId": "o1", "servers": [ ]}"#, ), ( "get_model_catalog", r#"{"type": "get_model_catalog", "activeSessionId": "sess"}"#, ), ( "get_available_models", r#"{"type": "get_available_models", "activeSessionId": "sess"}"#, ), ( "get_queue", r#"{"type": "get_queue", "activeSessionId": "sess"}"#, ), ( "mutate_queued_message", r#"{"type": "mutate_queued_message", "activeSessionId": "sess", "lane": "steering", "index": 0, "expectedText": "x", "mutation": { "type": "delete" }}"#, ), ( "clear_queue", r#"{"type": "clear_queue", "activeSessionId": "sess"}"#, ), ( "abort_and_clear_queue", r#"{"type": "abort_and_clear_queue", "activeSessionId": "sess"}"#, ), ( "acquire_session_input_pause", r#"{"type": "acquire_session_input_pause", "activeSessionId": "sess", "leaseKey": "k"}"#, ), ( "release_session_input_pause", r#"{"type": "release_session_input_pause", "activeSessionId": "sess", "pauseId": "p"}"#, ), ("cron_list", r#"{"type": "cron_list"}"#), ("heartbeats_list", r#"{"type": "heartbeats_list"}"#), ( "heartbeat_manage", r#"{"type": "heartbeat_manage", "activeSessionId": "sess", "jobId": "j", "action": "pause"}"#, ), ( "cron_add", r#"{"type": "cron_add", "activeSessionId": "sess", "schedule": "0 0 * * *", "prompt": "p"}"#, ), ("cron_cancel", r#"{"type": "cron_cancel", "jobId": "j"}"#), ( "heartbeat_get", r#"{"type": "heartbeat_get", "activeSessionId": "sess"}"#, ), ( "heartbeat_set", r#"{"type": "heartbeat_set", "activeSessionId": "sess", "schedule": "0 0 * * *", "prompt": "p"}"#, ), ( "heartbeat_update", r#"{"type": "heartbeat_update", "activeSessionId": "sess", "action": "pause"}"#, ), ( "set_model", r#"{"type": "set_model", "activeSessionId": "sess", "provider": "prov", "modelId": "m"}"#, ), ( "cycle_model", r#"{"type": "cycle_model", "activeSessionId": "sess"}"#, ), ( "set_scoped_models", r#"{"type": "set_scoped_models", "activeSessionId": "sess", "scopedModels": [ ]}"#, ), ( "set_thinking_level", r#"{"type": "set_thinking_level", "activeSessionId": "sess", "level": "high"}"#, ), ( "cycle_thinking_level", r#"{"type": "cycle_thinking_level", "activeSessionId": "sess"}"#, ), ( "set_service_tier", r#"{"type": "set_service_tier", "activeSessionId": "sess"}"#, ), ( "set_transport", r#"{"type": "set_transport", "activeSessionId": "sess", "transport": "sse"}"#, ), ( "set_steering_mode", r#"{"type": "set_steering_mode", "activeSessionId": "sess", "mode": "all"}"#, ), ( "set_follow_up_mode", r#"{"type": "set_follow_up_mode", "activeSessionId": "sess", "mode": "all"}"#, ), ( "set_auto_compaction", r#"{"type": "set_auto_compaction", "activeSessionId": "sess", "enabled": true}"#, ), ( "set_auto_retry", r#"{"type": "set_auto_retry", "activeSessionId": "sess", "enabled": true}"#, ), ( "compact", r#"{"type": "compact", "activeSessionId": "sess"}"#, ), ( "abort_compaction", r#"{"type": "abort_compaction", "activeSessionId": "sess"}"#, ), ( "abort_branch_summary", r#"{"type": "abort_branch_summary", "activeSessionId": "sess"}"#, ), ( "abort_retry", r#"{"type": "abort_retry", "activeSessionId": "sess"}"#, ), ("reload", r#"{"type": "reload", "activeSessionId": "sess"}"#), ( "new_session", r#"{"type": "new_session", "activeSessionId": "sess"}"#, ), ( "switch_session", r#"{"type": "switch_session", "activeSessionId": "sess", "sessionPath": "/tmp/x.jsonl"}"#, ), ( "fork", r#"{"type": "fork", "activeSessionId": "sess", "entryId": "e"}"#, ), ( "navigate_tree", r#"{"type": "navigate_tree", "activeSessionId": "sess", "targetId": "t"}"#, ), ( "import_jsonl", r#"{"type": "import_jsonl", "activeSessionId": "sess", "inputPath": "/tmp/in"}"#, ), ( "export_html", r#"{"type": "export_html", "activeSessionId": "sess"}"#, ), ( "export_jsonl", r#"{"type": "export_jsonl", "activeSessionId": "sess"}"#, ), ( "set_session_name", r#"{"type": "set_session_name", "activeSessionId": "sess", "name": "x"}"#, ), ( "get_rlm_max_depth_status", r#"{"type": "get_rlm_max_depth_status", "activeSessionId": "sess"}"#, ), ( "set_rlm_max_depth", r#"{"type": "set_rlm_max_depth", "activeSessionId": "sess", "maxDepth": 2}"#, ), ( "rename_saved_session", r#"{"type": "rename_saved_session", "sessionPath": "/tmp/x.jsonl", "name": "x"}"#, ), ( "delete_saved_session", r#"{"type": "delete_saved_session", "sessionPath": "/tmp/x.jsonl"}"#, ), ( "get_session_context", r#"{"type": "get_session_context", "activeSessionId": "sess"}"#, ), ( "get_session_tree", r#"{"type": "get_session_tree", "activeSessionId": "sess"}"#, ), ( "get_user_messages_for_forking", r#"{"type": "get_user_messages_for_forking", "activeSessionId": "sess"}"#, ), ( "get_last_assistant_text", r#"{"type": "get_last_assistant_text", "activeSessionId": "sess"}"#, ), ( "get_system_prompt", r#"{"type": "get_system_prompt", "activeSessionId": "sess"}"#, ), ( "get_tool_definition", r#"{"type": "get_tool_definition", "activeSessionId": "sess", "name": "x"}"#, ), ( "set_session_entry_label", r#"{"type": "set_session_entry_label", "activeSessionId": "sess", "entryId": "e"}"#, ), ( "prepare_update_restart", r#"{"type": "prepare_update_restart"}"#, ), ( "retry_worker", r#"{"type": "retry_worker", "activeSessionId": "sess"}"#, ), ("restart", r#"{"type": "restart"}"#), ("shutdown", r#"{"type": "shutdown"}"#), ( "worker_register", r#"{"type": "worker_register", "activeSessionId": "sess", "socketPath": "/tmp/w.sock", "workerInstanceId": "wi", "token": "t", "pid": 1}"#, ), ( "worker_roster_delta", r#"{"type": "worker_roster_delta", "workerToken": "token", "summary": { }}"#, ), ( "get_worker_peer_transport", r#"{"type": "get_worker_peer_transport", "workerToken": "token", "targetActiveSessionId": "target"}"#, ), ( "commit_update_restart", r#"{"type": "commit_update_restart"}"#, ), ( "update_restore_status", r#"{"type": "update_restore_status"}"#, ), ( "get_mcp_connections", r#"{"type": "get_mcp_connections", "activeSessionId": "sess"}"#, ), ( "mark_anthropic_warning_shown", r#"{"type": "mark_anthropic_warning_shown", "activeSessionId": "sess"}"#, ),];
/// The accept list is the TS list, in TS order, then the Rust-native supervisor/worker frames.#[test]fn known_command_types_match_the_ts_list() { // Keep the ordered TS baseline intact. These declared public extensions // have fixed positions in the compatible command prefix. let mut expected = Vec::with_capacity(TS_DAEMON_COMMAND_TYPES.len() + 4); for command in TS_DAEMON_COMMAND_TYPES { match *command { "get_resource_snapshot" => expected.push("plugin_command"), "get_queue" => expected.extend([ "refresh_models", "apply_model_snapshots", "refresh_all_models", ]), _ => {} } expected.push(*command); } assert!(KNOWN_COMMAND_TYPES.len() > expected.len()); let (head, tail) = KNOWN_COMMAND_TYPES.split_at(expected.len()); assert_eq!( head, expected, "accept list must preserve the TS prefix with declared public extensions" ); for extra in tail { // Rust-native frames only; a new TS type must extend the TS constant. assert!( matches!( *extra, "worker_register" | "worker_roster_delta" | "get_worker_peer_transport" | "commit_update_restart" | "update_restore_status" | "get_mcp_connections" | "list_kernel_bash" | "tail_kernel_bash" | "kill_kernel_bash" | "mark_anthropic_warning_shown" ), "unexpected non-TS command type: {extra}" ); }}
#[test]fn every_command_type_parses_and_routes() { for (type_name, wire) in WIRE_FIXTURES { // String concat keeps the raw fixture braces intact (a format! call would treat them as // placeholders). let line = r#"{"type":"command","id":"c1","protocol":{"name":"prime-agent.daemon","version":7},"command":"# .to_string() + wire + "}"; let envelope = parse_daemon_command_line(&line) .unwrap_or_else(|e| panic!("{type_name} must parse: {e}")); assert_eq!( command_type_name(&envelope.command), *type_name, "router must preserve the wire type" ); let selector = command_active_session_id(&envelope.command); let wire_has_selector = wire.contains("activeSessionId"); assert_eq!( selector.is_some(), wire_has_selector, "{type_name}: session selector mismatch" ); assert_eq!(selector, wire_has_selector.then_some("sess")); }}
/// Unknown types keep the TS wire error, not a parse accident.#[test]fn unknown_type_keeps_the_ts_error_string() { let line = r#"{"type":"command","id":"c1","protocol":{"name":"prime-agent.daemon","version":7},"command":{"type":"not_a_command"}}"#; let error = parse_daemon_command_line(line).unwrap_err(); assert_eq!(error.to_string(), "Unknown daemon command: not_a_command");
// A known type with a malformed body is a malformed command, not unknown (the TS second-pass // error class). let line = r#"{"type":"command","id":"c2","protocol":{"name":"prime-agent.daemon","version":7},"command":{"type":"kill"}}"#; let error = parse_daemon_command_line(line).unwrap_err(); assert_eq!( error.to_string(), "Invalid daemon command: malformed kill command" ); assert!(!error.is_unknown_command());}