feat(cli): neurosploit provider — register any endpoint without editing source

key add --base-url --name registers a plain OpenAI endpoint on a direct
connection. The profile added alongside it carries proxy, session header,
user agent, rate limits, context window and pricing, and none of that was
reachable from the CLI.

Add a provider subcommand: list, show, add, remove.

add merges rather than replaces, so changing one setting leaves the rest
alone — the same reason register merges. show prints what is set and what
falls back, including that pricing left unset means the cost ledger guesses
from the model name, which tells it nothing about a private gateway.

list marks each provider with whether its key is set, and whether it is
proxied, priced or rate-limited, so a misconfigured one is visible without
opening it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Joas A SantosandClaude Opus 5 committed 2026-12-04 14:35:48 -03:00
1 parent a00c856960
commit c89725c013
2 files changed
+180

No files matched your search

+173
View File
@@ -205,3 +205,176 @@ pub async fn handle(base: &Path, cmd: KeyCmd) -> anyhow::Result<()> {
}
Ok(())
}
// ─────────────────────────────────────────────────────────────────────────────
// Custom provider profiles
// ─────────────────────────────────────────────────────────────────────────────
/// Register any LLM endpoint with the settings it actually needs, so adding a
/// provider never means editing source.
///
/// `key add --base-url --name` covers a plain OpenAI endpoint on a direct
/// connection. This is for the rest: a gateway behind a proxy, one that wants
/// its own session header, a model the cost ledger has no price for.
#[derive(clap::Subcommand, Debug)]
pub enum ProviderCmd {
/// List registered providers.
List,
/// Show one provider's full profile.
Show { name: String },
/// Add or update a provider. Only the flags given are changed, so editing
/// one setting never clears the others.
Add {
/// Name this provider; used as `<name>:<model>`.
name: String,
/// Endpoint root, e.g. https://gateway.internal/v1 (required when new).
#[arg(long)]
base_url: Option<String>,
/// Wire format: openai (default) or anthropic.
#[arg(long)]
format: Option<String>,
/// Model ids to offer in pickers. Repeatable or comma-separated.
/// A model not listed here can still be used by typing its id.
#[arg(long, value_delimiter = ',')]
model: Vec<String>,
/// Route this provider's traffic through a proxy:
/// socks5://[user:pass@]host:port or http://host:port.
#[arg(long)]
proxy: Option<String>,
/// Send a stable per-run id in this header, for gateways that pin
/// prompt-cache routing on one.
#[arg(long)]
session_header: Option<String>,
/// Override User-Agent for this provider.
#[arg(long)]
user_agent: Option<String>,
/// Requests per second (0 = unlimited).
#[arg(long)]
rps: Option<f64>,
/// Requests per minute (0 = unlimited).
#[arg(long)]
rpm: Option<f64>,
/// Context window in thousands of tokens (0 = global default).
#[arg(long)]
context_k: Option<u32>,
/// USD per million tokens. Without these the cost ledger guesses from
/// the model name, which tells it nothing about a private gateway.
#[arg(long)]
price_input: Option<f64>,
#[arg(long)]
price_output: Option<f64>,
#[arg(long)]
price_cache_read: Option<f64>,
#[arg(long)]
price_cache_write: Option<f64>,
},
/// Remove a provider. Its API key is removed separately with `key remove`.
Remove { name: String },
}
pub fn handle_provider(base: &Path, cmd: ProviderCmd) -> anyhow::Result<()> {
use harness::custom_providers as cp;
match cmd {
ProviderCmd::List => {
let all = cp::list_profiles(base);
if all.is_empty() {
println!("No custom providers. Add one:");
println!(" neurosploit provider add mygw --base-url https://gateway.internal/v1");
return Ok(());
}
for (name, p) in all {
let key = if harness::keystore::load(base).contains_key(&name) { "key set" } else { "no key" };
let mut notes = vec![key.to_string()];
if !p.proxy.is_empty() { notes.push("proxied".into()); }
if p.has_pricing() { notes.push("priced".into()); }
if p.rpm > 0.0 || p.rps > 0.0 { notes.push("rate-limited".into()); }
println!(" {name:<20} {:<44} [{}]", p.base_url, notes.join(", "));
}
}
ProviderCmd::Show { name } => {
let p = cp::profile(base, &name)
.ok_or_else(|| anyhow::anyhow!("'{name}' is not registered"))?;
println!(" name : {name}");
println!(" base URL : {}", p.base_url);
println!(" format : {}", p.format);
println!(" API key : {}",
if harness::keystore::load(base).contains_key(&name) { "set".to_string() } else { format!("not set — neurosploit key add --provider {name}") });
println!(" models : {}",
if p.models.is_empty() { "(type any id)".into() } else { p.models.join(", ") });
println!(" proxy : {}", if p.proxy.is_empty() { "direct" } else { &p.proxy });
println!(" session header : {}", if p.session_header.is_empty() { "(none)" } else { &p.session_header });
println!(" user agent : {}", if p.user_agent.is_empty() { "(default)" } else { &p.user_agent });
println!(" rate limit : {}",
match (p.rps, p.rpm) {
(0.0, 0.0) => "unlimited".to_string(),
(s, 0.0) => format!("{s}/s"),
(0.0, m) => format!("{m}/min"),
(s, m) => format!("{s}/s, {m}/min"),
});
println!(" context : {}",
if p.context_k == 0 { "global default".into() } else { format!("{}K", p.context_k) });
if p.has_pricing() {
println!(" price (USD/Mtok): in {} · out {} · cache read {} · cache write {}",
p.price_input, p.price_output, p.price_cache_read, p.price_cache_write);
} else {
println!(" price : not set — the cost ledger will guess from the model name");
}
}
ProviderCmd::Add {
name, base_url, format, model, proxy, session_header, user_agent,
rps, rpm, context_k, price_input, price_output, price_cache_read, price_cache_write,
} => {
// Start from what is stored so a one-flag edit leaves the rest alone.
let mut p = cp::profile(base, &name).unwrap_or_default();
let is_new = p.base_url.is_empty();
if let Some(v) = base_url { p.base_url = v; }
if p.base_url.trim().is_empty() {
anyhow::bail!("--base-url is required when adding a new provider");
}
if let Some(v) = format { p.format = v; }
if !model.is_empty() { p.models = model; }
if let Some(v) = proxy { p.proxy = v; }
if let Some(v) = session_header { p.session_header = v; }
if let Some(v) = user_agent { p.user_agent = v; }
if let Some(v) = rps { p.rps = v; }
if let Some(v) = rpm { p.rpm = v; }
if let Some(v) = context_k { p.context_k = v; }
if let Some(v) = price_input { p.price_input = v; }
if let Some(v) = price_output { p.price_output = v; }
if let Some(v) = price_cache_read { p.price_cache_read = v; }
if let Some(v) = price_cache_write { p.price_cache_write = v; }
let saved = cp::save_profile(base, &name, p).map_err(|e| anyhow::anyhow!(e))?;
println!(" {} provider '{saved}'", if is_new { "added" } else { "updated" });
if !harness::keystore::load(base).contains_key(&saved) {
println!(" next: neurosploit key add --provider {saved} --base-url <url>");
}
println!(" use : --model {saved}:<model-id>");
}
ProviderCmd::Remove { name } => {
if cp::remove(base, &name)? {
println!(" removed provider '{name}' (its API key is separate: neurosploit key remove {name})");
} else {
println!(" '{name}' was not registered");
}
}
}
Ok(())
}
+7
View File
@@ -408,6 +408,12 @@ enum Cmd {
#[command(subcommand)]
cmd: keycli::KeyCmd,
},
/// Custom LLM providers: register any endpoint with the proxy, headers,
/// rate limits and pricing it needs, without editing source.
Provider {
#[command(subcommand)]
cmd: keycli::ProviderCmd,
},
/// Toolbox: list/check/run 200+ pentest tools and manage MCP tool servers.
Tools {
#[command(subcommand)]
@@ -1473,6 +1479,7 @@ async fn main() -> anyhow::Result<()> {
print_findings(&out);
}
Cmd::Key { cmd } => { keycli::handle(&base, cmd).await?; }
Cmd::Provider { cmd } => { keycli::handle_provider(&base, cmd)?; }
Cmd::Tools { cmd } => { toolscli::handle(cmd).await?; }
Cmd::Logs { cmd } => { handle_logs(&base, cmd).await?; }
Cmd::Tunnel { port, authtoken, region, domain, bind, no_serve } => {