Skip to main content

objectiveai_sdk/cli/command/agents/instances/list/
mod.rs

1//! `agents instances list` — enumerate agent instances under one or
2//! more targets, reporting per-agent aggregates (tags, queued count,
3//! spawn/active timestamps, total logged messages).
4
5use crate::cli::command::CommandRequest;
6
7/// Reuse the shared `--target` enum (`instance=L[,parent=P]`, `tag=T`,
8/// `me`) from `agents logs read all`. Each target resolves to an AIH
9/// whose direct children this command lists.
10pub use super::super::logs::list::Target;
11
12#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
13#[schemars(rename = "cli.command.agents.instances.list.Request")]
14pub struct Request {
15    pub path_type: Path,
16    pub targets: Vec<Target>,
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.agents.instances.list.Path")]
23pub enum Path {
24    #[serde(rename = "agents/instances/list")]
25    AgentsInstancesList,
26}
27
28impl CommandRequest for Request {
29    fn request_base(&self) -> &crate::cli::command::RequestBase {
30        &self.base
31    }
32
33    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
34        Some(&mut self.base)
35    }
36}
37
38/// One discovered agent instance under a target. Aggregated from the
39/// `logs.messages`, `message_queue`, and `tags` tiers.
40#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
41#[schemars(rename = "cli.command.agents.instances.list.ResponseItem")]
42pub struct ResponseItem {
43    /// Full hierarchy of this agent instance.
44    pub agent_instance_hierarchy: String,
45    /// Tag names currently bound to this AIH, newest-bound first.
46    pub tags: Vec<String>,
47    /// Active `message_queue` rows targeting this agent — counting
48    /// both direct-AIH rows and rows whose tag is bound to this AIH.
49    pub queued: u64,
50    /// RFC3339 timestamp of the first `logs.messages` row for this
51    /// agent. `None` when the agent has no logs yet (queue-only).
52    #[serde(default, skip_serializing_if = "Option::is_none")]
53    #[schemars(extend("omitempty" = true))]
54    pub created_at: Option<String>,
55    /// RFC3339 timestamp of the most recent `logs.messages` row for
56    /// this agent. `None` when the agent has no logs yet (queue-only).
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    #[schemars(extend("omitempty" = true))]
59    pub last_active_at: Option<String>,
60    /// Total `logs.messages` rows for this agent over all time.
61    pub logged: u64,
62}
63
64#[derive(clap::Args)]
65pub struct Args {
66    /// One or more `--target instance=L[,parent=P]` entries. Also
67    /// accepts `--target tag=T` and `--target me`. Lists the direct
68    /// children of each resolved target.
69    #[arg(long = "target", required = true)]
70    pub targets: Vec<String>,
71    #[command(flatten)]
72    pub base: crate::cli::command::RequestBaseArgs,
73}
74
75#[derive(clap::Args)]
76#[command(args_conflicts_with_subcommands = true)]
77pub struct Command {
78    #[command(flatten)]
79    pub args: Args,
80    #[command(subcommand)]
81    pub schema: Option<Schema>,
82}
83
84#[derive(clap::Subcommand)]
85pub enum Schema {
86    /// Emit the JSON Schema for this leaf's `Request` type and exit.
87    RequestSchema(request_schema::Args),
88    /// Emit the JSON Schema for this leaf's `Response` type and exit.
89    ResponseSchema(response_schema::Args),
90}
91
92impl TryFrom<Args> for Request {
93    type Error = crate::cli::command::FromArgsError;
94    fn try_from(args: Args) -> Result<Self, Self::Error> {
95        let targets = args
96            .targets
97            .iter()
98            .map(|s| {
99                s.parse::<Target>().map_err(|msg| {
100                    crate::cli::command::FromArgsError::path_parse("target", msg)
101                })
102            })
103            .collect::<Result<Vec<_>, _>>()?;
104        Ok(Self {
105            path_type: Path::AgentsInstancesList,
106            targets,
107            base: args.base.into(),
108        })
109    }
110}
111
112#[cfg(feature = "cli-executor")]
113pub async fn execute<E: crate::cli::command::CommandExecutor>(
114    executor: &E,
115    mut request: Request,
116
117        agent_arguments: Option<&crate::cli::command::AgentArguments>,
118    ) -> Result<E::Stream<ResponseItem>, E::Error> {
119    request.base.clear_transform();
120    executor.execute(request, agent_arguments).await
121}
122
123#[cfg(feature = "cli-executor")]
124pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
125    executor: &E,
126    mut request: Request,
127    transform: crate::cli::command::Transform,
128
129        agent_arguments: Option<&crate::cli::command::AgentArguments>,
130    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
131    request.base.set_transform(transform);
132    executor.execute(request, agent_arguments).await
133}
134
135#[cfg(feature = "mcp")]
136impl crate::cli::command::CommandResponse for ResponseItem {
137    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
138        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
139    }
140}
141
142pub mod request_schema;
143
144
145pub mod response_schema;