taskfast_cli/cmd/me.rs
1// SPDX-License-Identifier: MIT
2//! `taskfast me` — profile + readiness in one envelope.
3//!
4//! Combines `GET /agents/me` and `GET /agents/me/readiness` so orchestrators
5//! can tell in one call whether the agent is authenticated, active, and
6//! ready to work. Pure read; honors `--dry-run` by passing through (reads
7//! have no side effects to short-circuit).
8//!
9//! Envelope `data` shape:
10//! `profile` is the `GET /agents/me` body as the server sent it — fields
11//! added after this CLI's spec was vendored pass through (gh#172).
12//!
13//! ```json
14//! {
15//! "profile": { ...AgentProfile... },
16//! "readiness": { "ready_to_work": bool, "checks": { ... } },
17//! "ready_to_work": bool
18//! }
19//! ```
20//! The top-level `ready_to_work` is duplicated for grep-friendly orchestrator
21//! checks (`jq -e .data.ready_to_work`).
22
23use clap::Parser;
24use serde_json::json;
25
26use super::{CmdError, CmdResult, Ctx};
27use crate::envelope::Envelope;
28
29use taskfast_agent::bootstrap::get_readiness;
30use taskfast_client::api::types::AgentProfile;
31
32#[derive(Debug, Parser)]
33pub struct Args {
34 /// Reconstruct in-flight tasks/bids state. Reserved — not yet
35 /// implemented; the full resume flow lands with the task+bid list
36 /// subcommands (see am-e3u.11).
37 #[arg(long)]
38 pub resume: bool,
39}
40
41pub async fn run(ctx: &Ctx, args: Args) -> CmdResult {
42 if args.resume {
43 return Err(CmdError::Unimplemented("taskfast me --resume"));
44 }
45
46 let client = ctx.client()?;
47 let profile = client
48 .get_agent_profile_raw()
49 .await
50 .map_err(CmdError::from)?;
51 // Still hold the server to the vendored contract for the fields it covers.
52 serde_json::from_value::<AgentProfile>(profile.clone())
53 .map_err(|e| CmdError::from(taskfast_client::Error::from(e)))?;
54 let readiness = get_readiness(&client).await.map_err(CmdError::from)?;
55
56 let data = json!({
57 "profile": profile,
58 "readiness": readiness,
59 "ready_to_work": readiness.ready_to_work,
60 });
61 Ok(Envelope::success(ctx.environment, ctx.dry_run, data))
62}