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 request_base(&self) -> &crate::cli::command::RequestBase {
44        &self.base
45    }
46
47    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
48        Some(&mut self.base)
49    }
50}
51
52/// Success-only: the wait completed — the target is done.
53pub type Response = crate::cli::command::Ok;
54
55#[derive(clap::Args)]
56pub struct Args {
57    #[command(flatten)]
58    pub agent: crate::cli::command::agents::selector::AgentSelectorArgs,
59    #[command(flatten)]
60    pub base: crate::cli::command::RequestBaseArgs,
61}
62
63#[derive(clap::Args)]
64#[command(args_conflicts_with_subcommands = true)]
65pub struct Command {
66    #[command(flatten)]
67    pub args: Args,
68    #[command(subcommand)]
69    pub schema: Option<Schema>,
70}
71
72#[derive(clap::Subcommand)]
73pub enum Schema {
74    /// Emit the JSON Schema for this leaf's `Request` type and exit.
75    RequestSchema(request_schema::Args),
76    /// Emit the JSON Schema for this leaf's `Response` type and exit.
77    ResponseSchema(response_schema::Args),
78}
79
80impl TryFrom<Args> for Request {
81    type Error = crate::cli::command::FromArgsError;
82    fn try_from(args: Args) -> Result<Self, Self::Error> {
83        let agent = AgentSelector::try_from(args.agent)?;
84        Ok(Self {
85            path_type: Path::AgentsWait,
86            agent,
87            base: args.base.into(),
88        })
89    }
90}
91
92#[cfg(feature = "cli-executor")]
93pub async fn execute<E: crate::cli::command::CommandExecutor>(
94    executor: &E,
95    mut request: Request,
96
97        agent_arguments: Option<&crate::cli::command::AgentArguments>,
98    ) -> Result<Response, E::Error> {
99    request.base.clear_transform();
100    executor.execute_one(request, agent_arguments).await
101}
102
103#[cfg(feature = "cli-executor")]
104pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
105    executor: &E,
106    mut request: Request,
107    transform: crate::cli::command::Transform,
108
109        agent_arguments: Option<&crate::cli::command::AgentArguments>,
110    ) -> Result<serde_json::Value, E::Error> {
111    request.base.set_transform(transform);
112    executor.execute_one(request, agent_arguments).await
113}
114
115pub mod request_schema;
116
117pub mod response_schema;