1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//! The command line, and nothing else: no behavior lives here.
use crate::model::Agent;
use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "egrix",
version,
about = "Find leaked credentials and suspicious network destinations in your AI agents' history.",
long_about = "Find leaked credentials and suspicious network destinations in your AI agents' history.\n\nRuns locally, reads transcripts without sending them anywhere, and redacts every value it prints. The only network call is the daily update check.\nWith no command, opens the dashboard in a terminal and prints a summary otherwise.",
after_help = "Exit codes: 0 no new findings, 1 new findings, 2 error."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Subcommand)]
pub enum Command {
/// Scan for secrets and network destinations and print a summary
Scan {
#[command(flatten)]
filter: Filter,
#[command(flatten)]
output: Output,
},
/// List leaked credentials
Secrets {
#[command(flatten)]
filter: Filter,
#[command(flatten)]
output: Output,
/// How to group the list
#[arg(long, value_enum, default_value = "repo")]
group: Group,
/// Show the transcript around one secret, by id
#[arg(long, value_name = "ID")]
show: Option<String>,
},
/// List external hosts the agents touched
Egress {
#[command(flatten)]
filter: Filter,
#[command(flatten)]
output: Output,
/// Show the transcript around each sighting of one host
#[arg(long, value_name = "HOST")]
show: Option<String>,
/// Include allowed hosts in the list
#[arg(long)]
all: bool,
},
/// Mask found secrets inside the transcript files (keeps a backup)
Fix {
#[command(flatten)]
filter: Filter,
/// Only this secret, by id
#[arg(long, value_name = "ID")]
id: Option<String>,
/// Put masked secrets back instead
#[arg(long)]
undo: bool,
/// Do not ask for confirmation
#[arg(long, short)]
yes: bool,
},
/// Record what you did about a secret
Mark {
/// Secret id, or a unique prefix of it
id: String,
/// The credential was rotated at the provider
#[arg(long, group = "what")]
rotated: bool,
/// False positive: stop reporting it
#[arg(long, group = "what")]
ignored: bool,
/// Clear both marks
#[arg(long, group = "what")]
clear: bool,
},
/// Manage your allow and deny lists
Hosts {
#[command(subcommand)]
action: HostsAction,
},
/// Inspect the secret rules
Rules {
#[command(subcommand)]
action: RulesAction,
},
/// Accept the current findings, so only new ones fail a scan
Baseline {
#[command(flatten)]
filter: Filter,
},
/// Check for a newer egrix, or install it
Update {
/// Only report whether a newer release exists
#[arg(long)]
check: bool,
/// Install new releases on their own, in the background
#[arg(long, conflicts_with = "disable_auto")]
enable_auto: bool,
/// Stop installing new releases on their own
#[arg(long)]
disable_auto: bool,
/// Internal: the detached check started on launch
#[arg(long, hide = true)]
check_background: bool,
},
}
#[derive(Subcommand)]
pub enum HostsAction {
/// Trust a host and its subdomains
Allow { host: String },
/// Flag a host and its subdomains
Deny { host: String },
/// Take a host off both lists
Remove { host: String },
/// Print both lists
List,
}
#[derive(Subcommand)]
pub enum RulesAction {
/// Print every active rule
List,
/// Run the rules over a file and print what they find
Test { file: PathBuf },
}
#[derive(Args, Clone, Default)]
pub struct Filter {
/// Only this agent's history
#[arg(long, value_enum)]
pub agent: Option<Agent>,
/// Only the last period: 7d, 2w, 3m
#[arg(long, value_name = "SPAN")]
pub since: Option<String>,
/// Only repositories whose name or remote contains this
#[arg(long, value_name = "NAME")]
pub repo: Option<String>,
}
#[derive(Args, Clone, Default)]
pub struct Output {
/// Machine-readable JSON
#[arg(long, conflicts_with = "sarif")]
pub json: bool,
/// SARIF 2.1.0, for code-scanning tools
#[arg(long)]
pub sarif: bool,
/// Print raw secret values instead of redacted previews
#[arg(long)]
pub reveal: bool,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
pub enum Group {
#[default]
Repo,
Remote,
Rule,
Agent,
}
// `next` and `name` drive the dashboard's grouping key.
#[cfg_attr(not(feature = "tui"), allow(dead_code))]
impl Group {
pub fn next(self) -> Self {
match self {
Group::Repo => Group::Remote,
Group::Remote => Group::Rule,
Group::Rule => Group::Agent,
Group::Agent => Group::Repo,
}
}
pub fn name(self) -> &'static str {
match self {
Group::Repo => "repository",
Group::Remote => "remote",
Group::Rule => "rule",
Group::Agent => "agent",
}
}
/// The heading a secret falls under.
pub fn key(self, secret: &crate::model::Secret) -> String {
let loc = &secret.location;
match self {
Group::Repo => loc.repo_name().to_string(),
Group::Remote => crate::report::repo_label(loc.repo.as_ref(), true),
Group::Rule => secret.rule.clone(),
Group::Agent => loc.agent.name().to_string(),
}
}
}