Skip to main content

objectiveai_sdk/cli/command/agents/wait/
mod.rs

1//! `agents wait` — block until an agent is done.
2//!
3//! Takes an instance hierarchy or a tag (the `agents enqueue`
4//! selector shape — a plain ref has no live identity to wait on and
5//! errors). The wait is uncapped — it blocks until the target is
6//! done, however long that takes.
7//!
8//! - **Instance**: subscribe to the AIH lock's release; a free lock
9//!   returns immediately.
10//! - **Un-upgraded (GROUPED) tag**: the tag lock's holder is the
11//!   spawn materializing the tag. If nobody holds it, nothing is
12//!   materializing it — return immediately. Otherwise subscribe to
13//!   its release, re-resolve the tag (the spawn flow upgrades
14//!   GROUPED→BOUND strictly before releasing the tag lock, so a
15//!   still-GROUPED tag after release is a systemic invariant
16//!   violation and errors fatally), then fall through to the
17//!   instance wait on the freshly bound hierarchy.
18//!
19//! Success is the bare `"Ok"` sentinel either way.
20
21use crate::cli::command::CommandRequest;
22use crate::cli::command::agents::selector::AgentSelector;
23
24#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
25#[schemars(rename = "cli.command.agents.wait.Request")]
26pub struct Request {
27    pub path_type: Path,
28    /// Who to wait on — an instance hierarchy or a tag. A plain ref
29    /// has no live identity and errors.
30    pub agent: AgentSelector,
31    #[serde(flatten)]
32    pub base: crate::cli::command::RequestBase,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
36#[schemars(rename = "cli.command.agents.wait.Path")]
37pub enum Path {
38    #[serde(rename = "agents/wait")]
39    AgentsWait,
40}
41
42impl CommandRequest for Request {
43    fn into_command(&self) -> Vec<String> {
44        let mut argv = vec!["agents".to_string(), "wait".to_string()];
45        self.agent.push_flags(&mut argv);
46        self.base.push_flags(&mut argv);
47        argv
48    }
49
50    fn request_base(&self) -> &crate::cli::command::RequestBase {
51        &self.base
52    }
53
54    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
55        Some(&mut self.base)
56    }
57}
58
59/// Success-only: the wait completed — the target is done.
60pub type Response = crate::cli::command::Ok;
61
62#[derive(clap::Args)]
63pub struct Args {
64    #[command(flatten)]
65    pub agent: crate::cli::command::agents::selector::AgentSelectorArgs,
66    #[command(flatten)]
67    pub base: crate::cli::command::RequestBaseArgs,
68}
69
70#[derive(clap::Args)]
71#[command(args_conflicts_with_subcommands = true)]
72pub struct Command {
73    #[command(flatten)]
74    pub args: Args,
75    #[command(subcommand)]
76    pub schema: Option<Schema>,
77}
78
79#[derive(clap::Subcommand)]
80pub enum Schema {
81    /// Emit the JSON Schema for this leaf's `Request` type and exit.
82    RequestSchema(request_schema::Args),
83    /// Emit the JSON Schema for this leaf's `Response` type and exit.
84    ResponseSchema(response_schema::Args),
85}
86
87impl TryFrom<Args> for Request {
88    type Error = crate::cli::command::FromArgsError;
89    fn try_from(args: Args) -> Result<Self, Self::Error> {
90        let agent = AgentSelector::try_from(args.agent)?;
91        Ok(Self {
92            path_type: Path::AgentsWait,
93            agent,
94            base: args.base.into(),
95        })
96    }
97}
98
99#[cfg(feature = "cli-executor")]
100pub async fn execute<E: crate::cli::command::CommandExecutor>(
101    executor: &E,
102    mut request: Request,
103
104        agent_arguments: Option<&crate::cli::command::AgentArguments>,
105    ) -> Result<Response, E::Error> {
106    request.base.clear_transform();
107    executor.execute_one(request, agent_arguments).await
108}
109
110#[cfg(feature = "cli-executor")]
111pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
112    executor: &E,
113    mut request: Request,
114    transform: crate::cli::command::Transform,
115
116        agent_arguments: Option<&crate::cli::command::AgentArguments>,
117    ) -> Result<serde_json::Value, E::Error> {
118    request.base.set_transform(transform);
119    executor.execute_one(request, agent_arguments).await
120}
121
122pub mod request_schema;
123
124pub mod response_schema;