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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
use crate::types::Mode;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(
name = "search",
version,
about = "Agent-friendly multi-provider search CLI",
long_about = "Aggregates 13 search providers across 13 explicit search modes.\n\
You choose the mode (-m) and/or providers (-p); the CLI does not guess\n\
intent. Run `search agent-info` for the machine-readable capability map.\n\
Outputs colored tables for humans, JSON when piped to other tools.\n\n\
PROVIDERS:\n \
parallel Agent-native search (Parallel AI): LLM-ready excerpts\n \
brave Independent web index (not Google/Bing) + LLM grounding\n \
serper Cheapest raw Google SERP: web, news, scholar, patents, places\n \
exa Neural/semantic search, LinkedIn people, find-similar\n \
jina Fast web search + URL-to-markdown reader\n \
linkup High-accuracy agent search (SimpleQA leader)\n \
firecrawl JS-rendered page scraping + structured extraction\n \
tavily RAG-oriented search: general, news, academic, deep\n \
serpapi Many engines (Google, Bing, YouTube, Baidu, Scholar)\n \
perplexity LLM-synthesized answer with citations (Sonar)\n \
browserless Cloud browser for Cloudflare/JS-heavy pages\n \
stealth Local anti-bot scraper (no API key)\n \
xai Only real-time X/Twitter search (Grok agentic)\n\n\
EXAMPLES:\n \
search \"rust error handling\" # general web search\n \
search search -q \"CRISPR\" -m academic # academic papers\n \
search search -q \"CEO of Stripe\" -m people # LinkedIn profiles via Exa\n \
search search -q \"AI news\" -m news # breaking news\n \
search search -q \"trending on twitter\" -m social # X/Twitter search\n \
search search -q \"query\" -p exa # force Exa only\n \
search search -q \"query\" -p exa,brave # only Exa + Brave\n \
search --x \"AI agents\" # search X (Twitter) only\n \
search \"query\" --json | jq '.results[].url' # pipe JSON to jq"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
/// Search query (shorthand for `search -q`)
#[arg(trailing_var_arg = true, global = false)]
pub query_words: Vec<String>,
/// Output as JSON (auto-enabled when piped)
#[arg(long, global = true)]
pub json: bool,
/// Suppress non-essential output
#[arg(long, global = true)]
pub quiet: bool,
/// Replay the last search result from cache
#[arg(long, global = true)]
pub last: bool,
/// Search X (Twitter) only — shorthand for -m social -p xai
#[arg(long = "x", global = true)]
pub x_only: bool,
/// Verbose debug logging to stderr (sets log level to debug unless RUST_LOG is set)
#[arg(long, global = true, visible_alias = "verbose")]
pub debug: bool,
}
#[derive(Subcommand)]
pub enum Commands {
/// Search across providers (use -m for mode, -p to pick providers)
Search(SearchArgs),
/// Manage configuration (show, set, check)
Config {
#[command(subcommand)]
action: ConfigAction,
},
/// Show machine-readable capabilities (for agents)
AgentInfo,
/// List all providers with status and capabilities
Providers,
/// Verify if email addresses exist via SMTP (no API key needed). Probes
/// mail servers directly (RCPT TO) — bulk probing can hurt IP reputation
Verify(VerifyArgs),
/// Manage skill file installation for agent platforms
Skill {
#[command(subcommand)]
action: SkillAction,
},
/// Check for updates or self-update
Update {
/// Only check, don't install
#[arg(long)]
check: bool,
},
/// Show remaining credits/quota for providers that expose a usage API
Usage,
/// Test-fire every configured provider with a minimal query and report
/// health, latency, and failure causes (each check is one billed request)
Doctor,
/// Usage statistics from the local search logs (spend, modes, providers)
Stats(StatsArgs),
/// Manage the local query cache
Cache {
#[command(subcommand)]
action: CacheAction,
},
}
#[derive(Parser)]
pub struct StatsArgs {
/// Analysis window in days
#[arg(long, default_value = "30")]
pub days: u64,
/// Delete log files older than this many days, then exit
#[arg(long)]
pub prune: Option<u64>,
}
#[derive(Subcommand)]
pub enum CacheAction {
/// Delete all cached query results
Clear,
}
#[derive(Parser)]
pub struct VerifyArgs {
/// Email addresses to verify
pub emails: Vec<String>,
/// Read emails from file (one per line, use - for stdin)
#[arg(short, long)]
pub file: Option<String>,
}
#[derive(Parser)]
pub struct SearchArgs {
/// Search query
#[arg(short, long)]
pub query: String,
/// Search mode (default: general). Choose explicitly: general, news,
/// academic, deep, social, scholar, patents, people, places, images,
/// similar, scrape, extract. See `search agent-info` for the full map.
#[arg(short, long, value_enum, default_value = "general")]
pub mode: Mode,
/// Number of results to return
#[arg(short, long)]
pub count: Option<usize>,
/// Use only specific providers (comma-separated: parallel,brave,serper,exa,jina,linkup,firecrawl,tavily,serpapi,perplexity,browserless,stealth,xai)
#[arg(short, long, value_delimiter = ',')]
pub providers: Option<Vec<String>>,
/// Include only results from these domains (comma-separated)
#[arg(short, long, value_delimiter = ',')]
pub domain: Option<Vec<String>>,
/// Exclude results from these domains (comma-separated)
#[arg(long, value_delimiter = ',')]
pub exclude_domain: Option<Vec<String>>,
/// Freshness filter: day, week, month, year
#[arg(short, long)]
pub freshness: Option<String>,
/// Bypass the local 5-minute query cache and force a fresh search
#[arg(long)]
pub no_cache: bool,
/// Cap each result snippet (and answer) at this many characters
#[arg(long)]
pub max_chars: Option<usize>,
/// Country code for region-biased results (e.g. gb, de, jp) — applied by
/// providers that support it (serper, serpapi, brave, parallel)
#[arg(long)]
pub country: Option<String>,
/// Language code for results (e.g. en, de, fr) — applied by providers
/// that support it (serper, serpapi, brave)
#[arg(long)]
pub lang: Option<String>,
/// Allow extract/scrape of private, loopback, and link-local addresses
/// (blocked by default to keep prompt-injected agents away from
/// localhost and cloud metadata endpoints)
#[arg(long)]
pub allow_private: bool,
}
#[derive(Subcommand)]
pub enum ConfigAction {
/// Show current configuration (API keys masked)
Show,
/// Set a configuration value (e.g. keys.brave YOUR_KEY)
Set {
/// Config key (e.g. keys.brave, settings.timeout)
key: String,
/// Value to set. Pass "-" to read it from stdin, keeping secrets out
/// of shell history and process listings
value: String,
},
/// Health-check which providers are configured and ready
Check,
/// Show configuration file path
Path,
}
#[derive(Subcommand)]
pub enum SkillAction {
/// Write skill file to all detected agent platforms
Install,
/// Check which platforms have the skill installed
Status,
}
pub mod skill {
use crate::output::Ctx;
use std::path::PathBuf;
const SKILL_CONTENT: &str = include_str!("../SKILL.md");
struct Target {
name: &'static str,
path: PathBuf,
}
fn home() -> PathBuf {
std::env::var("HOME")
.or_else(|_| std::env::var("USERPROFILE"))
.map(PathBuf::from)
.unwrap_or_else(|_| PathBuf::from("."))
}
fn targets() -> Vec<Target> {
let h = home();
vec![
Target {
name: "Claude Code",
path: h.join(".claude/skills/search"),
},
Target {
name: "Codex CLI",
path: h.join(".codex/skills/search"),
},
Target {
name: "Gemini CLI",
path: h.join(".gemini/skills/search"),
},
]
}
pub fn install(ctx: &Ctx) {
let mut results = Vec::new();
for t in &targets() {
let skill_path = t.path.join("SKILL.md");
let status = if skill_path.exists()
&& std::fs::read_to_string(&skill_path).is_ok_and(|c| c == SKILL_CONTENT)
{
"already_current"
} else {
if let Err(e) = std::fs::create_dir_all(&t.path) {
eprintln!(" Failed {}: {e}", t.name);
continue;
}
if let Err(e) = std::fs::write(&skill_path, SKILL_CONTENT) {
eprintln!(" Failed {}: {e}", t.name);
continue;
}
"installed"
};
results.push((t.name, skill_path.display().to_string(), status));
}
if ctx.is_json() {
let items: Vec<serde_json::Value> = results
.iter()
.map(|(name, path, status)| {
serde_json::json!({"platform": name, "path": path, "status": status})
})
.collect();
crate::output::json::render_value(&serde_json::json!({
"version": "1",
"status": "success",
"data": items,
}));
} else if !ctx.suppress_human() {
use owo_colors::OwoColorize;
for (name, path, status) in &results {
let marker = if *status == "installed" { "+" } else { "=" };
println!(" {} {} -> {}", marker.green(), name.bold(), path.dimmed());
}
}
}
pub fn status(ctx: &Ctx) {
let mut results = Vec::new();
for t in &targets() {
let skill_path = t.path.join("SKILL.md");
let (installed, current) = if skill_path.exists() {
let current =
std::fs::read_to_string(&skill_path).is_ok_and(|c| c == SKILL_CONTENT);
(true, current)
} else {
(false, false)
};
results.push((t.name, installed, current));
}
if ctx.is_json() {
let items: Vec<serde_json::Value> = results
.iter()
.map(|(name, installed, current)| {
serde_json::json!({"platform": name, "installed": installed, "current": current})
})
.collect();
crate::output::json::render_value(&serde_json::json!({
"version": "1",
"status": "success",
"data": items,
}));
} else if !ctx.suppress_human() {
use owo_colors::OwoColorize;
for (name, installed, current) in &results {
let status = if *current {
"current".green().to_string()
} else if *installed {
"outdated".yellow().to_string()
} else {
"not installed".red().to_string()
};
println!(" {} {}", name.bold(), status);
}
}
}
}