Skip to main content

objectiveai_sdk/cli/command/daemon/kill/
mod.rs

1//! `daemon kill` — stop the per-state plugin daemon and clean up its
2//! sockets.
3//!
4//! Resolves the per-state daemon lock's live owner PID(s) and kills
5//! them; the leashed `daemon: true` plugins die with the daemon. Socket
6//! files are left on disk — the next daemon reclaims a stale one at bind
7//! time. Idempotent: a count of zero is not an error.
8
9use crate::cli::command::CommandRequest;
10
11#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
12#[schemars(rename = "cli.command.daemon.kill.Request")]
13pub struct Request {
14    pub path_type: Path,
15    #[serde(flatten)]
16    pub base: crate::cli::command::RequestBase,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
20#[schemars(rename = "cli.command.daemon.kill.Path")]
21pub enum Path {
22    #[serde(rename = "daemon/kill")]
23    DaemonKill,
24}
25
26impl CommandRequest for Request {
27    fn request_base(&self) -> &crate::cli::command::RequestBase {
28        &self.base
29    }
30
31    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
32        Some(&mut self.base)
33    }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
37#[schemars(rename = "cli.command.daemon.kill.Response")]
38pub struct Response {
39    pub killed: usize,
40}
41
42#[derive(clap::Args)]
43pub struct Args {
44    #[command(flatten)]
45    pub base: crate::cli::command::RequestBaseArgs,
46}
47
48#[derive(clap::Args)]
49#[command(args_conflicts_with_subcommands = true)]
50pub struct Command {
51    #[command(flatten)]
52    pub args: Args,
53    #[command(subcommand)]
54    pub schema: Option<Schema>,
55}
56
57#[derive(clap::Subcommand)]
58pub enum Schema {
59    /// Emit the JSON Schema for this leaf's `Request` type and exit.
60    RequestSchema(request_schema::Args),
61    /// Emit the JSON Schema for this leaf's `Response` type and exit.
62    ResponseSchema(response_schema::Args),
63}
64
65impl TryFrom<Args> for Request {
66    type Error = crate::cli::command::FromArgsError;
67    fn try_from(args: Args) -> Result<Self, Self::Error> {
68        Ok(Self { path_type: Path::DaemonKill, base: args.base.into() })
69    }
70}
71
72#[cfg(feature = "cli-executor")]
73pub async fn execute<E: crate::cli::command::CommandExecutor>(
74    executor: &E,
75    mut request: Request,
76    agent_arguments: Option<&crate::cli::command::AgentArguments>,
77) -> Result<Response, E::Error> {
78    request.base.clear_transform();
79    executor.execute_one(request, agent_arguments).await
80}
81
82#[cfg(feature = "cli-executor")]
83pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
84    executor: &E,
85    mut request: Request,
86    transform: crate::cli::command::Transform,
87    agent_arguments: Option<&crate::cli::command::AgentArguments>,
88) -> Result<serde_json::Value, E::Error> {
89    request.base.set_transform(transform);
90    executor.execute_one(request, agent_arguments).await
91}
92
93#[cfg(feature = "mcp")]
94impl crate::cli::command::CommandResponse for Response {
95    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
96        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
97    }
98}
99
100pub mod request_schema;
101
102pub mod response_schema;