Skip to main content

objectiveai_sdk/cli/command/plugins/logs/list/
mod.rs

1//! `plugins logs list` — read captured plugin stderr lines for one
2//! plugin coordinate (owner/name/version), ascending by the BIGSERIAL
3//! `"index"` cursor (paginate with `--after-id` / `--limit`).
4
5use crate::cli::command::CommandRequest;
6
7#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
8#[schemars(rename = "cli.command.plugins.logs.list.Request")]
9pub struct Request {
10    pub path_type: Path,
11    pub owner: String,
12    pub name: String,
13    pub version: String,
14    /// Skip rows with `"index" <= after_id`. Use the highest `index`
15    /// from a previous page to paginate forward.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    #[schemars(extend("omitempty" = true))]
18    pub after_id: Option<i64>,
19    /// Cap on rows returned. `None` = unlimited.
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    #[schemars(extend("omitempty" = true))]
22    pub limit: Option<i64>,
23    #[serde(flatten)]
24    pub base: crate::cli::command::RequestBase,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
28#[schemars(rename = "cli.command.plugins.logs.list.Path")]
29pub enum Path {
30    #[serde(rename = "plugins/logs/list")]
31    PluginsLogsList,
32}
33
34impl CommandRequest for Request {
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/// One captured stderr line from a `plugins run` invocation.
45#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
46#[schemars(rename = "cli.command.plugins.logs.list.ResponseItem")]
47pub struct ResponseItem {
48    /// `objectiveai.plugin_messages."index"` — the BIGSERIAL cursor;
49    /// pass as `--after-id` to page forward.
50    pub index: i64,
51    pub owner: String,
52    pub name: String,
53    pub version: String,
54    /// AIH of the agent run that invoked `plugins run`.
55    pub agent_instance_hierarchy: String,
56    /// Response id of the invoking agent run, if any.
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    #[schemars(extend("omitempty" = true))]
59    pub response_id: Option<String>,
60    /// Unix-seconds capture time.
61    pub created_at: i64,
62    pub line: String,
63}
64
65#[derive(clap::Args)]
66#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
67#[command(group(clap::ArgGroup::new("name_required").required(true).args(["name"])))]
68#[command(group(clap::ArgGroup::new("version_required").required(true).args(["version"])))]
69pub struct Args {
70    /// Plugin owner (GitHub `<owner>` segment). Required.
71    #[arg(long)]
72    pub owner: Option<String>,
73    /// Plugin name (repository segment). Required.
74    #[arg(long)]
75    pub name: Option<String>,
76    /// Plugin version. Required.
77    #[arg(long)]
78    pub version: Option<String>,
79    /// Skip rows with `"index" <= after_id`.
80    #[arg(long)]
81    pub after_id: Option<i64>,
82    /// Cap on rows returned.
83    #[arg(long)]
84    pub limit: Option<i64>,
85    #[command(flatten)]
86    pub base: crate::cli::command::RequestBaseArgs,
87}
88
89#[derive(clap::Args)]
90#[command(args_conflicts_with_subcommands = true)]
91pub struct Command {
92    #[command(flatten)]
93    pub args: Args,
94    #[command(subcommand)]
95    pub schema: Option<Schema>,
96}
97
98#[derive(clap::Subcommand)]
99pub enum Schema {
100    /// Emit the JSON Schema for this leaf's `Request` type and exit.
101    RequestSchema(request_schema::Args),
102    /// Emit the JSON Schema for this leaf's `Response` type and exit.
103    ResponseSchema(response_schema::Args),
104}
105
106impl TryFrom<Args> for Request {
107    type Error = crate::cli::command::FromArgsError;
108    fn try_from(args: Args) -> Result<Self, Self::Error> {
109        Ok(Self {
110            path_type: Path::PluginsLogsList,
111            owner: args.owner.ok_or_else(|| {
112                crate::cli::command::FromArgsError::path_parse(
113                    "owner",
114                    "--owner is required".to_string(),
115                )
116            })?,
117            name: args.name.ok_or_else(|| {
118                crate::cli::command::FromArgsError::path_parse(
119                    "name",
120                    "--name is required".to_string(),
121                )
122            })?,
123            version: args.version.ok_or_else(|| {
124                crate::cli::command::FromArgsError::path_parse(
125                    "version",
126                    "--version is required".to_string(),
127                )
128            })?,
129            after_id: args.after_id,
130            limit: args.limit,
131            base: args.base.into(),
132        })
133    }
134}
135
136#[cfg(feature = "cli-executor")]
137pub async fn execute<E: crate::cli::command::CommandExecutor>(
138    executor: &E,
139    mut request: Request,
140    agent_arguments: Option<&crate::cli::command::AgentArguments>,
141) -> Result<E::Stream<ResponseItem>, E::Error> {
142    request.base.clear_transform();
143    executor.execute(request, agent_arguments).await
144}
145
146#[cfg(feature = "cli-executor")]
147pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
148    executor: &E,
149    mut request: Request,
150    transform: crate::cli::command::Transform,
151    agent_arguments: Option<&crate::cli::command::AgentArguments>,
152) -> Result<E::Stream<serde_json::Value>, E::Error> {
153    request.base.set_transform(transform);
154    executor.execute(request, agent_arguments).await
155}
156
157#[cfg(feature = "mcp")]
158impl crate::cli::command::CommandResponse for ResponseItem {
159    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
160        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
161    }
162}
163
164pub mod request_schema;
165
166pub mod response_schema;
167
168/// One `/listen` broadcast run of `plugins logs list`: the actual
169/// [`Request`], the producer's
170/// [`AgentArguments`](crate::cli::command::AgentArguments), and the
171/// response-item stream. See [`crate::cli::websocket_listener`].
172#[cfg(feature = "cli-listener")]
173pub struct ListenerExecution {
174    pub request: Request,
175    pub agent_arguments: crate::cli::command::AgentArguments,
176    pub response: crate::cli::websocket_listener::ResponseItemStream<ResponseItem>,
177}