safe_chains/cli.rs
1use clap::Parser;
2use crate::verdict::SafetyLevel;
3
4#[derive(Parser)]
5#[command(name = "safe-chains")]
6#[command(about = "Auto-allow safe bash commands in agentic coding tools")]
7#[command(version)]
8#[allow(clippy::struct_excessive_bools)]
9pub struct Cli {
10 /// Command string to check (omit for Claude hook mode via stdin)
11 pub command: Option<String>,
12
13 /// Safety level threshold (inert, safe-read, safe-write). Only commands at or below this level pass.
14 #[arg(long, value_enum)]
15 pub level: Option<SafetyLevel>,
16
17 /// Print a per-segment breakdown of why a command would or would not auto-approve.
18 #[arg(long)]
19 pub explain: bool,
20
21 /// List all supported commands in Markdown format
22 #[arg(long)]
23 pub list_commands: bool,
24
25 /// Generate OpenCode permission config (merges with existing opencode.json)
26 #[arg(long)]
27 pub opencode_config: bool,
28
29 /// Generate mdBook command reference pages in docs/src/commands/
30 #[arg(long)]
31 pub generate_book: bool,
32
33 /// Configure the hook for the named tool (default: claude). Use --auto-detect for every installed tool.
34 #[arg(long)]
35 pub setup: bool,
36
37 /// Pair with --setup to select the target tool by name. See --list-tools.
38 #[arg(long, value_name = "NAME")]
39 pub tool: Option<String>,
40
41 /// Pair with --setup to install for every installed tool detected on this machine.
42 #[arg(long)]
43 pub auto_detect: bool,
44
45 /// Print the names of every supported integration target.
46 #[arg(long)]
47 pub list_tools: bool,
48
49 /// Hook subcommand: read this tool's stdin envelope, validate the command, write the response.
50 #[command(subcommand)]
51 pub subcommand: Option<Subcommand>,
52}
53
54#[derive(clap::Subcommand)]
55pub enum Subcommand {
56 /// Run as a runtime hook for the named tool.
57 Hook {
58 /// Tool to read/write the hook envelope for. See --list-tools.
59 #[arg(value_name = "TOOL")]
60 tool: String,
61 },
62}