Skip to main content

zag_agent/
manpages.rs

1//! Built-in manpages and the `--help-agent` reference document.
2//!
3//! Markdown sources live in `zag-agent/man/` and are embedded at compile
4//! time via [`include_str!`]. The CLI's `zag man <command>` and
5//! `zag --help-agent` subcommands read from this module, and library
6//! callers can use the same content programmatically.
7//!
8//! # Example
9//!
10//! ```no_run
11//! use zag_agent::manpages;
12//!
13//! // Full AI-oriented reference
14//! let help = manpages::HELP_AGENT;
15//! println!("{help}");
16//!
17//! // Per-command manpage
18//! if let Some(md) = manpages::manpage(Some("review")) {
19//!     println!("{md}");
20//! }
21//!
22//! // Enumerate everything that has a manpage
23//! for name in manpages::manpage_names() {
24//!     println!("{name}");
25//! }
26//! ```
27
28/// Top-level CLI overview.
29pub const ZAG: &str = include_str!("../man/zag.md");
30/// AI-oriented CLI reference, printed by `zag --help-agent`.
31pub const HELP_AGENT: &str = include_str!("../man/help-agent.md");
32pub const MAN: &str = include_str!("../man/man.md");
33pub const RUN: &str = include_str!("../man/run.md");
34pub const EXEC: &str = include_str!("../man/exec.md");
35pub const REVIEW: &str = include_str!("../man/review.md");
36pub const PLAN: &str = include_str!("../man/plan.md");
37pub const CONFIG: &str = include_str!("../man/config.md");
38pub const SESSION: &str = include_str!("../man/session.md");
39pub const CAPABILITY: &str = include_str!("../man/capability.md");
40pub const DISCOVER: &str = include_str!("../man/discover.md");
41pub const LISTEN: &str = include_str!("../man/listen.md");
42pub const SKILLS: &str = include_str!("../man/skills.md");
43pub const MCP: &str = include_str!("../man/mcp.md");
44pub const PS: &str = include_str!("../man/ps.md");
45pub const SEARCH: &str = include_str!("../man/search.md");
46pub const INPUT: &str = include_str!("../man/input.md");
47pub const BROADCAST: &str = include_str!("../man/broadcast.md");
48pub const WHOAMI: &str = include_str!("../man/whoami.md");
49pub const WAIT: &str = include_str!("../man/wait.md");
50pub const SPAWN: &str = include_str!("../man/spawn.md");
51pub const STATUS: &str = include_str!("../man/status.md");
52pub const COLLECT: &str = include_str!("../man/collect.md");
53pub const ENV: &str = include_str!("../man/env.md");
54pub const PIPE: &str = include_str!("../man/pipe.md");
55pub const EVENTS: &str = include_str!("../man/events.md");
56pub const CANCEL: &str = include_str!("../man/cancel.md");
57pub const SUMMARY: &str = include_str!("../man/summary.md");
58pub const WATCH: &str = include_str!("../man/watch.md");
59pub const SUBSCRIBE: &str = include_str!("../man/subscribe.md");
60pub const LOG: &str = include_str!("../man/log.md");
61pub const OUTPUT: &str = include_str!("../man/output.md");
62pub const RETRY: &str = include_str!("../man/retry.md");
63pub const GC: &str = include_str!("../man/gc.md");
64pub const SERVE: &str = include_str!("../man/serve.md");
65pub const CONNECT: &str = include_str!("../man/connect.md");
66pub const USER: &str = include_str!("../man/user.md");
67pub const USAGE: &str = include_str!("../man/usage.md");
68pub const ORCHESTRATION: &str = include_str!("../man/orchestration.md");
69
70/// Names of every manpage accepted by [`manpage`], in a stable order suited
71/// for user-facing listings.
72pub const MANPAGE_NAMES: &[&str] = &[
73    "zag",
74    "run",
75    "exec",
76    "review",
77    "plan",
78    "config",
79    "session",
80    "capability",
81    "discover",
82    "listen",
83    "man",
84    "skills",
85    "mcp",
86    "ps",
87    "search",
88    "input",
89    "broadcast",
90    "whoami",
91    "wait",
92    "spawn",
93    "status",
94    "collect",
95    "env",
96    "pipe",
97    "events",
98    "cancel",
99    "summary",
100    "watch",
101    "subscribe",
102    "log",
103    "output",
104    "retry",
105    "gc",
106    "serve",
107    "connect",
108    "disconnect",
109    "user",
110    "usage",
111    "orchestration",
112];
113
114/// Return the manpage content for the given command name, or `None` if the
115/// name is not recognised. `None` / empty / `"zag"` all return the top-level
116/// [`ZAG`] manpage. `"disconnect"` aliases to [`CONNECT`].
117pub fn manpage(command: Option<&str>) -> Option<&'static str> {
118    Some(match command.unwrap_or("zag") {
119        "" | "zag" => ZAG,
120        "run" => RUN,
121        "exec" => EXEC,
122        "review" => REVIEW,
123        "plan" => PLAN,
124        "config" => CONFIG,
125        "session" => SESSION,
126        "capability" => CAPABILITY,
127        "discover" => DISCOVER,
128        "listen" => LISTEN,
129        "man" => MAN,
130        "skills" => SKILLS,
131        "mcp" => MCP,
132        "ps" => PS,
133        "search" => SEARCH,
134        "input" => INPUT,
135        "broadcast" => BROADCAST,
136        "whoami" => WHOAMI,
137        "wait" => WAIT,
138        "spawn" => SPAWN,
139        "status" => STATUS,
140        "collect" => COLLECT,
141        "env" => ENV,
142        "pipe" => PIPE,
143        "events" => EVENTS,
144        "cancel" => CANCEL,
145        "summary" => SUMMARY,
146        "watch" => WATCH,
147        "subscribe" => SUBSCRIBE,
148        "log" => LOG,
149        "output" => OUTPUT,
150        "retry" => RETRY,
151        "gc" => GC,
152        "serve" => SERVE,
153        "connect" | "disconnect" => CONNECT,
154        "user" => USER,
155        "usage" => USAGE,
156        "orchestration" => ORCHESTRATION,
157        _ => return None,
158    })
159}
160
161/// Names of every command for which [`manpage`] returns `Some`.
162pub fn manpage_names() -> &'static [&'static str] {
163    MANPAGE_NAMES
164}
165
166#[cfg(test)]
167#[path = "manpages_tests.rs"]
168mod tests;