arcella_types/alme.rs
1// arcella/arcella-types/src/alme/proto/mod.rs
2//
3// Copyright (c) 2025 Arcella Team
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE>
6// or the MIT license <LICENSE-MIT>, at your option.
7// This file may not be copied, modified, or distributed
8// except according to those terms.
9
10//! ALME (Arcella Local Management Extensions) protocol definitions.
11//!
12//! This crate defines the shared request/response structures used by both
13//! the Arcella daemon (server) and clients (e.g., CLI, GUI, tests).
14
15use serde::{Deserialize, Serialize};
16
17/// A high-level, type-safe ALME command.
18#[derive(Serialize, Deserialize, Debug, Clone)]
19#[serde(tag = "cmd", content = "args")]
20pub enum AlmeCommand {
21 /// Ping the server: `cmd = "ping"`, args = {}
22 Ping,
23
24 /// Tail the log of one or all deployments
25 #[serde(rename = "log:tail")]
26 LogTail {
27 #[serde(default)]
28 n: usize,
29 },
30
31 /// Get status of one or all deployments
32 #[serde(rename = "module:status")]
33 Status {
34 #[serde(default)]
35 deployment_id: Option<String>,
36 },
37
38 /// List all deployments
39 #[serde(rename = "module:list")]
40 ModuleList,
41
42 /// Install a module: `cmd = "module:install"`, args = { "path": "..." }
43 #[serde(rename = "module:install")]
44 ModuleInstall {
45 path: String,
46 },
47
48 /// Deploy from file: `cmd = "deploy"`, args = { "file": "..." }
49 #[serde(rename = "module:deploy")]
50 ModuleDeploy {
51 file: String,
52 },
53
54 /// Start a deployment by ID
55 #[serde(rename = "module:start")]
56 ModuleStart {
57 deployment_id: String,
58 },
59
60 /// Stop a deployment by ID
61 #[serde(rename = "module:stop")]
62 ModuleStop {
63 deployment_id: String,
64 },
65
66}
67
68/// An ALME request sent by a client.
69#[derive(Serialize, Deserialize, Debug, Clone)]
70pub struct AlmeRequest {
71 #[serde(flatten)]
72 pub command: AlmeCommand,
73}
74
75/// An ALME response returned by the server.
76#[derive(Serialize, Deserialize, Debug)]
77pub struct AlmeResponse {
78 /// Whether the command succeeded.
79 pub success: bool,
80
81 /// Human-readable message (e.g., "pong", "Arcella runtime is active").
82 pub message: String,
83
84 /// Optional structured data (e.g., status details, log lines, module list).
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub data: Option<serde_json::Value>,
87}
88
89impl AlmeResponse {
90 /// Create a successful response.
91 pub fn success(message: &str, data: Option<serde_json::Value>) -> Self {
92 Self {
93 success: true,
94 message: message.into(),
95 data,
96 }
97 }
98
99 /// Create an error response.
100 pub fn error(message: &str) -> Self {
101 Self {
102 success: false,
103 message: message.into(),
104 data: None,
105 }
106 }
107}