astrid_types/kernel.rs
1//! Kernel management API request and response types.
2
3use serde::{Deserialize, Serialize};
4
5/// The well-known system session UUID string used by the background daemon.
6///
7/// All kernel-internal IPC messages are published with this `source_id`.
8/// WASM capsules that verify message provenance should compare against
9/// this constant. Mirrors `astrid_core::SessionId::SYSTEM`.
10pub const SYSTEM_SESSION_UUID: &str = "00000000-0000-0000-0000-000000000000";
11
12/// Management API requests directed at the core daemon.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14#[serde(tag = "method", content = "params")]
15pub enum KernelRequest {
16 /// Request to install a capsule from a local or remote path.
17 InstallCapsule {
18 /// The path or URL to the `.capsule` archive.
19 source: String,
20 /// True if this should be installed locally in the workspace.
21 workspace: bool,
22 },
23 /// Request to approve a capability grant (usually following an `ApprovalNeeded` response).
24 ApproveCapability {
25 /// The unique ID of the request being approved.
26 request_id: String,
27 /// Cryptographic signature proving Root Identity authorization.
28 signature: String,
29 },
30 /// Request the list of currently loaded capsules.
31 ListCapsules,
32 /// Reload all capsules from the file system.
33 ReloadCapsules,
34 /// Request the list of globally registered slash commands.
35 GetCommands,
36 /// Request metadata about loaded capsules (manifests, providers, interceptors).
37 /// The kernel's equivalent of `/proc` — exposing process table info.
38 GetCapsuleMetadata,
39 /// Request the daemon to shut down gracefully.
40 Shutdown {
41 /// Optional reason for shutdown.
42 reason: Option<String>,
43 },
44 /// Request daemon status information.
45 GetStatus,
46}
47
48/// Management API responses from the core daemon.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(tag = "status", content = "data")]
51pub enum KernelResponse {
52 /// The request succeeded.
53 Success(serde_json::Value),
54 /// A list of available slash commands across all capsules.
55 Commands(Vec<CommandInfo>),
56 /// Metadata about loaded capsules.
57 CapsuleMetadata(Vec<CapsuleMetadataEntry>),
58 /// The request failed.
59 Error(String),
60 /// Daemon status information.
61 Status(DaemonStatus),
62 /// The request requires user capability approval before it can proceed.
63 ApprovalRequired {
64 /// Unique ID for this specific action request.
65 request_id: String,
66 /// Description of what is being requested.
67 description: String,
68 /// The specific capabilities required (e.g. `["host_process", "fs_write"]`).
69 capabilities: Vec<String>,
70 },
71}
72
73/// Daemon runtime status information.
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct DaemonStatus {
76 /// Process ID of the daemon.
77 pub pid: u32,
78 /// Daemon uptime in seconds.
79 pub uptime_secs: u64,
80 /// Daemon version string.
81 pub version: String,
82 /// Whether the daemon is running in ephemeral mode.
83 pub ephemeral: bool,
84 /// Number of currently connected clients.
85 pub connected_clients: u32,
86 /// Names of loaded capsules.
87 pub loaded_capsules: Vec<String>,
88}
89
90/// Metadata entry for a loaded capsule.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct CapsuleMetadataEntry {
93 /// The capsule's unique name.
94 pub name: String,
95 /// Interceptor event patterns declared by this capsule.
96 pub interceptor_events: Vec<String>,
97}
98
99/// Information about a registered slash command.
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct CommandInfo {
102 /// The slash command trigger (e.g. `/git`).
103 pub name: String,
104 /// A brief description of what the command does.
105 pub description: String,
106 /// The capsule that provides this command.
107 pub provider_capsule: String,
108}