Skip to main content

objectiveai_sdk/cli/command/development/plugins/mcp/reset/
mod.rs

1//! `development plugins mcp reset` — drop the plugin's built image so
2//! the next run rebuilds it.
3//!
4//! This is the per-edit verb. A registered plugin still takes the
5//! image-exists fast path, so an edit does not take effect on its own;
6//! rebuilds are explicit, and this is what asks for one.
7//!
8//! Forwarded to the LOCAL laboratory host, which holds the image. It
9//! does not require a registration — it names an image tag, so it is
10//! equally a way to force a released plugin to be re-fetched.
11
12use crate::cli::command::CommandRequest;
13
14#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.development.plugins.mcp.reset.Request")]
16pub struct Request {
17    pub path_type: Path,
18    /// GitHub `<owner>` segment, lowercased on arrival.
19    pub owner: String,
20    /// Repository segment, likewise lowercased.
21    pub name: String,
22    /// Plugin version — with owner and name, it derives the image tag.
23    pub version: String,
24    /// Also delete the plugin's build CACHE directories.
25    ///
26    /// Off by default, and that default is the point: this command
27    /// runs after every edit, and the caches are the only reason the
28    /// rebuild it triggers is fast. Ask for this when a cache is
29    /// corrupt or a toolchain changed, not routinely.
30    #[serde(default)]
31    pub caches: bool,
32    #[serde(flatten)]
33    pub base: crate::cli::command::RequestBase,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
37#[schemars(rename = "cli.command.development.plugins.mcp.reset.Path")]
38pub enum Path {
39    #[serde(rename = "development/plugins/mcp/reset")]
40    DevelopmentPluginsMcpReset,
41}
42
43impl CommandRequest for Request {
44    fn request_base(&self) -> &crate::cli::command::RequestBase {
45        &self.base
46    }
47
48    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
49        Some(&mut self.base)
50    }
51}
52
53/// What the host actually dropped.
54#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
55#[schemars(rename = "cli.command.development.plugins.mcp.reset.Response")]
56pub struct Response {
57    pub owner: String,
58    pub name: String,
59    pub version: String,
60    /// Whether an image was removed. `false` for a plugin that was
61    /// never built is a SUCCESS — the point of the command is that the
62    /// next run rebuilds, and that is already true.
63    pub removed: bool,
64    /// Cache directories deleted; always 0 without `--caches`.
65    pub caches_removed: u64,
66}
67
68#[derive(clap::Args)]
69#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
70#[command(group(clap::ArgGroup::new("name_required").required(true).args(["name"])))]
71#[command(group(clap::ArgGroup::new("version_required").required(true).args(["version"])))]
72pub struct Args {
73    /// GitHub <owner> segment.
74    #[arg(long)]
75    pub owner: Option<String>,
76    /// Repository segment.
77    #[arg(long)]
78    pub name: Option<String>,
79    /// Plugin version.
80    #[arg(long)]
81    pub version: Option<String>,
82    /// Also delete the build caches. Slower next build; use only when
83    /// a cache is suspect.
84    #[arg(long)]
85    pub caches: bool,
86    #[command(flatten)]
87    pub base: crate::cli::command::RequestBaseArgs,
88}
89
90#[derive(clap::Args)]
91#[command(args_conflicts_with_subcommands = true)]
92pub struct Command {
93    #[command(flatten)]
94    pub args: Args,
95    #[command(subcommand)]
96    pub schema: Option<Schema>,
97}
98
99#[derive(clap::Subcommand)]
100pub enum Schema {
101    /// Emit the JSON Schema for this leaf's `Request` type and exit.
102    RequestSchema(request_schema::Args),
103    /// Emit the JSON Schema for this leaf's `Response` type and exit.
104    ResponseSchema(response_schema::Args),
105}
106
107impl TryFrom<Args> for Request {
108    type Error = crate::cli::command::FromArgsError;
109    fn try_from(args: Args) -> Result<Self, Self::Error> {
110        let owner = args.owner.ok_or_else(|| {
111            crate::cli::command::FromArgsError::path_parse(
112                "owner",
113                "--owner is required".to_string(),
114            )
115        })?;
116        let name = args.name.ok_or_else(|| {
117            crate::cli::command::FromArgsError::path_parse(
118                "name",
119                "--name is required".to_string(),
120            )
121        })?;
122        let version = args.version.ok_or_else(|| {
123            crate::cli::command::FromArgsError::path_parse(
124                "version",
125                "--version is required".to_string(),
126            )
127        })?;
128        Ok(Self {
129            path_type: Path::DevelopmentPluginsMcpReset,
130            owner,
131            name,
132            version,
133            caches: args.caches,
134            base: args.base.into(),
135        })
136    }
137}
138
139#[cfg(feature = "mcp")]
140impl crate::cli::command::CommandResponse for Response {
141    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
142        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
143    }
144}
145
146#[cfg(feature = "cli-executor")]
147pub async fn execute<E: crate::cli::command::CommandExecutor>(
148    executor: &E,
149    mut request: Request,
150    identity: Option<&crate::identity::Identity>,
151) -> Result<Response, E::Error> {
152    request.base.clear_transform();
153    executor.execute_one(request, identity).await
154}
155
156#[cfg(feature = "cli-executor")]
157pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
158    executor: &E,
159    mut request: Request,
160    transform: crate::cli::command::Transform,
161    identity: Option<&crate::identity::Identity>,
162) -> Result<serde_json::Value, E::Error> {
163    request.base.set_transform(transform);
164    executor.execute_one(request, identity).await
165}
166
167pub mod request_schema;
168
169pub mod response_schema;
170
171/// One `/listen` broadcast run of `development plugins mcp reset`. See
172/// [`crate::daemon::command_listener`].
173#[cfg(all(feature = "cli", feature = "daemon"))]
174pub struct ListenerExecution {
175    pub request: Request,
176    pub identity: crate::identity::Identity,
177    pub response: crate::daemon::command_listener::UnaryResponse<Response>,
178}