cli: claude_cli auto-on when claude is in PATH; false disables

This commit is contained in:
hermes committed 2026-10-16 20:13:46 +00:00
1 parent 769effc8b0
commit b06c06ad80
1 file changed
+32 -3
+32 -3
View File
@@ -111,14 +111,22 @@ enum McpAction {
} }
/// `~/.hx/config.toml`, overridden by `.hx/config.toml` in the project. /// `~/.hx/config.toml`, overridden by `.hx/config.toml` in the project.
#[derive(Clone, serde::Deserialize)]
#[serde(untagged)]
enum CliCfg {
Switch(bool),
Args(Vec<String>),
}
#[derive(Default, serde::Deserialize)] #[derive(Default, serde::Deserialize)]
#[serde(default, deny_unknown_fields)] #[serde(default, deny_unknown_fields)]
struct Config { struct Config {
provider: Option<Kind>, provider: Option<Kind>,
model: Option<String>, model: Option<String>,
claude_model: Option<String>, claude_model: Option<String>,
/// Run Claude through the official `claude` CLI (subscription billing). Value = extra `claude` args, `[]` for none. /// Run Claude through the official `claude` CLI (subscription billing). Default: on when `claude` is in PATH.
claude_cli: Option<Vec<String>>, /// `false` = own OAuth calls (billed as extra usage); `true` / `[]` = on; a list = on with extra `claude` args.
claude_cli: Option<CliCfg>,
/// OpenAI-compatible endpoint (Ollama, vLLM, LM Studio, OpenRouter, ...), provider "custom". /// OpenAI-compatible endpoint (Ollama, vLLM, LM Studio, OpenRouter, ...), provider "custom".
openai_compat: Option<hx_ai::openai_compat::Config>, openai_compat: Option<hx_ai::openai_compat::Config>,
codex_model: Option<String>, codex_model: Option<String>,
@@ -629,7 +637,15 @@ async fn main() -> Result<()> {
if let Some(oc) = cfg.openai_compat.clone() { if let Some(oc) = cfg.openai_compat.clone() {
let _ = COMPAT.set(oc); let _ = COMPAT.set(oc);
} }
if let Some(a) = cfg.claude_cli.clone() { // auto-detect, except against a test server (HX_BASE_URL)
let cli_args = match cfg.claude_cli.clone() {
Some(CliCfg::Args(a)) => Some(a),
Some(CliCfg::Switch(on)) => on.then(Vec::new),
None => (std::env::var_os("HX_BASE_URL").is_none()
&& hx_ai::claude_cli::ClaudeCli::available())
.then(Vec::new),
};
if let Some(a) = cli_args {
let _ = CLAUDE_CLI.set(a); let _ = CLAUDE_CLI.set(a);
} }
// MCP servers connect while the model catalog loads // MCP servers connect while the model catalog loads
@@ -1020,6 +1036,19 @@ mod tests {
#[cfg(test)] #[cfg(test)]
mod config_tests { mod config_tests {
#[test]
fn claude_cli_switch_or_args() {
use super::{CliCfg, Config};
let p = |t: &str| toml::from_str::<Config>(t).unwrap().claude_cli;
assert!(matches!(
p("claude_cli = false"),
Some(CliCfg::Switch(false))
));
assert!(matches!(p("claude_cli = true"), Some(CliCfg::Switch(true))));
assert!(matches!(p("claude_cli = [\"-x\"]"), Some(CliCfg::Args(a)) if a == ["-x"]));
assert!(p("").is_none());
}
#[test] #[test]
fn sample_config_parses() { fn sample_config_parses() {
let s = super::SAMPLE_CONFIG; let s = super::SAMPLE_CONFIG;