Skip to main content

objectiveai_sdk/cli/command/kill_all/
mod.rs

1//! `kill-all` — terminate every process holding a lock anywhere under
2//! the configured `OBJECTIVEAI_DIR`.
3//!
4//! Where `{api,db,mcp,viewer} kill` target one server by its known
5//! lock key, this is the blunt sweep: it walks the whole dir tree for
6//! every `*.lock` file, resolves each one's live owner PIDs, and kills
7//! them all — the api server, per-state db supervisors (taking their
8//! postmasters with them), viewers, mcp servers, and any agent-holding
9//! cli processes. Idempotent: a count of zero is not an error.
10
11use crate::cli::command::CommandRequest;
12
13#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.kill_all.Request")]
15pub struct Request {
16    pub path_type: Path,
17    #[serde(flatten)]
18    pub base: crate::cli::command::RequestBase,
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
22#[schemars(rename = "cli.command.kill_all.Path")]
23pub enum Path {
24    #[serde(rename = "kill-all")]
25    KillAll,
26}
27
28impl CommandRequest for Request {
29    fn into_command(&self) -> Vec<String> {
30        let mut argv = vec!["kill-all".to_string()];
31        self.base.push_flags(&mut argv);
32        argv
33    }
34
35    fn request_base(&self) -> &crate::cli::command::RequestBase {
36        &self.base
37    }
38
39    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
40        Some(&mut self.base)
41    }
42}
43
44#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
45#[schemars(rename = "cli.command.kill_all.Response")]
46pub struct Response {
47    pub killed: usize,
48}
49
50#[derive(clap::Args)]
51pub struct Args {
52    #[command(flatten)]
53    pub base: crate::cli::command::RequestBaseArgs,
54}
55
56#[derive(clap::Args)]
57#[command(args_conflicts_with_subcommands = true)]
58pub struct Command {
59    #[command(flatten)]
60    pub args: Args,
61    #[command(subcommand)]
62    pub schema: Option<Schema>,
63}
64
65#[derive(clap::Subcommand)]
66pub enum Schema {
67    /// Emit the JSON Schema for this leaf's `Request` type and exit.
68    RequestSchema(request_schema::Args),
69    /// Emit the JSON Schema for this leaf's `Response` type and exit.
70    ResponseSchema(response_schema::Args),
71}
72
73impl TryFrom<Args> for Request {
74    type Error = crate::cli::command::FromArgsError;
75    fn try_from(args: Args) -> Result<Self, Self::Error> {
76        Ok(Self { path_type: Path::KillAll, base: args.base.into() })
77    }
78}
79
80#[cfg(feature = "cli-executor")]
81pub async fn execute<E: crate::cli::command::CommandExecutor>(
82    executor: &E,
83    mut request: Request,
84
85        agent_arguments: Option<&crate::cli::command::AgentArguments>,
86    ) -> Result<Response, E::Error> {
87    request.base.clear_transform();
88    executor.execute_one(request, agent_arguments).await
89}
90
91#[cfg(feature = "cli-executor")]
92pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
93    executor: &E,
94    mut request: Request,
95    transform: crate::cli::command::Transform,
96
97        agent_arguments: Option<&crate::cli::command::AgentArguments>,
98    ) -> Result<serde_json::Value, E::Error> {
99    request.base.set_transform(transform);
100    executor.execute_one(request, agent_arguments).await
101}
102
103#[cfg(feature = "mcp")]
104impl crate::cli::command::CommandResponse for Response {
105    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
106        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
107    }
108}
109
110pub mod request_schema;
111
112pub mod response_schema;