kanade_shared/ipc/method.rs
1//! Method-name string constants for the KLP v1 namespace (SPEC §2.12.5).
2//!
3//! Centralised so the agent dispatcher and client call sites refer
4//! to the same string literal — a typo on either side becomes a
5//! compile error instead of a silent `MethodNotFound` at runtime.
6//!
7//! The constants intentionally mirror the SPEC table 1:1; future
8//! v2 method additions add a new entry here, never edit an existing
9//! one (the protocol-version handshake in §2.12.6 is the
10//! deprecation path).
11
12// ---- system.* ----
13
14/// Handshake — every connection's first request. SPEC §2.12.6.
15pub const SYSTEM_HANDSHAKE: &str = "system.handshake";
16/// Liveness check. No params, no return value beyond ack.
17pub const SYSTEM_PING: &str = "system.ping";
18/// Returns the agent's binary version + git rev.
19pub const SYSTEM_VERSION: &str = "system.version";
20/// Last N lines of `agent.log` for support handoff (SPEC §2.12.5).
21pub const SYSTEM_LOG_TAIL: &str = "system.log_tail";
22
23// ---- state.* ----
24
25/// One-shot bundle of health + inventory + compliance checks.
26pub const STATE_SNAPSHOT: &str = "state.snapshot";
27/// Start streaming `state.changed` pushes for this connection.
28pub const STATE_SUBSCRIBE: &str = "state.subscribe";
29/// Stop streaming `state.changed` pushes (the matching unsubscribe).
30pub const STATE_UNSUBSCRIBE: &str = "state.unsubscribe";
31/// Push (Agent → Client) when health / vpn / version etc. flips.
32pub const STATE_CHANGED: &str = "state.changed";
33
34// ---- notifications.* ----
35
36/// Paginated past-notifications listing (filter: unread/all).
37pub const NOTIFICATIONS_LIST: &str = "notifications.list";
38/// Start streaming `notifications.new` pushes for this connection.
39pub const NOTIFICATIONS_SUBSCRIBE: &str = "notifications.subscribe";
40/// Stop streaming `notifications.new` pushes.
41pub const NOTIFICATIONS_UNSUBSCRIBE: &str = "notifications.unsubscribe";
42/// Push (Agent → Client) carrying a new notification.
43pub const NOTIFICATIONS_NEW: &str = "notifications.new";
44/// Mark a notification read for this user — agent publishes
45/// `events.notifications.acked.>` on NATS with the OS-derived SID.
46pub const NOTIFICATIONS_ACK: &str = "notifications.ack";
47
48// ---- jobs.* ----
49
50/// List manifests with `user_invokable: true` (filter: category).
51pub const JOBS_LIST: &str = "jobs.list";
52/// Execute one of the listed jobs. Returns the synthesised `run_id`.
53pub const JOBS_EXECUTE: &str = "jobs.execute";
54/// Start streaming `jobs.progress` pushes for this connection.
55pub const JOBS_SUBSCRIBE: &str = "jobs.subscribe";
56/// Stop streaming `jobs.progress` pushes.
57pub const JOBS_UNSUBSCRIBE: &str = "jobs.unsubscribe";
58/// Push (Agent → Client) with stdout/stderr chunks + status changes.
59pub const JOBS_PROGRESS: &str = "jobs.progress";
60/// Kill a run started via `jobs.execute` on THIS connection (SPEC
61/// §2.12.4 — cross-connection kill is `Unauthorized`).
62pub const JOBS_KILL: &str = "jobs.kill";
63
64// ---- support.* ----
65
66/// Bundle recent inventory + log tail + agent state, upload to the
67/// JetStream Object Store, return the resulting ticket / object id.
68pub const SUPPORT_UPLOAD_DIAGNOSTICS: &str = "support.upload_diagnostics";
69
70// ---- maintenance.* ----
71
72/// List the next N days' scheduled jobs targeted at this PC.
73pub const MAINTENANCE_LIST: &str = "maintenance.list";
74/// User-initiated reboot-deferral (15m / 30m / 1h per SPEC §2.1).
75pub const MAINTENANCE_DEFER: &str = "maintenance.defer";
76
77#[cfg(test)]
78mod tests {
79 use super::*;
80
81 #[test]
82 fn method_names_are_stable_strings() {
83 // Pin the wire spellings so a careless rename can't drift
84 // them away from SPEC §2.12.5's table. New methods → new
85 // const + new assert here.
86 assert_eq!(SYSTEM_HANDSHAKE, "system.handshake");
87 assert_eq!(SYSTEM_PING, "system.ping");
88 assert_eq!(SYSTEM_VERSION, "system.version");
89 assert_eq!(SYSTEM_LOG_TAIL, "system.log_tail");
90
91 assert_eq!(STATE_SNAPSHOT, "state.snapshot");
92 assert_eq!(STATE_SUBSCRIBE, "state.subscribe");
93 assert_eq!(STATE_UNSUBSCRIBE, "state.unsubscribe");
94 assert_eq!(STATE_CHANGED, "state.changed");
95
96 assert_eq!(NOTIFICATIONS_LIST, "notifications.list");
97 assert_eq!(NOTIFICATIONS_SUBSCRIBE, "notifications.subscribe");
98 assert_eq!(NOTIFICATIONS_UNSUBSCRIBE, "notifications.unsubscribe");
99 assert_eq!(NOTIFICATIONS_NEW, "notifications.new");
100 assert_eq!(NOTIFICATIONS_ACK, "notifications.ack");
101
102 assert_eq!(JOBS_LIST, "jobs.list");
103 assert_eq!(JOBS_EXECUTE, "jobs.execute");
104 assert_eq!(JOBS_SUBSCRIBE, "jobs.subscribe");
105 assert_eq!(JOBS_UNSUBSCRIBE, "jobs.unsubscribe");
106 assert_eq!(JOBS_PROGRESS, "jobs.progress");
107 assert_eq!(JOBS_KILL, "jobs.kill");
108
109 assert_eq!(SUPPORT_UPLOAD_DIAGNOSTICS, "support.upload_diagnostics");
110
111 assert_eq!(MAINTENANCE_LIST, "maintenance.list");
112 assert_eq!(MAINTENANCE_DEFER, "maintenance.defer");
113 }
114}