hx config init: write a commented sample config #142

Merged
hermes merged 1 commits from feat/config-init into main 2026-10-09 14:00:06 +00:00
3 changed files with 97 additions and 1 deletions

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@ Lens findings and affected-test results appear after each turn as a `┄ lens
`/help`, `/skills`, `/lsp`, `/mcp` open in a side panel (`esc` closes). `NO_COLOR` disables colour,
`HX_ASCII=1` uses ASCII symbols. Messages typed while the agent works are queued.
Config: `~/.hx/config.toml`, overridden per project by `.hx/config.toml`:
Config: `~/.hx/config.toml`, overridden per project by `.hx/config.toml`. `hx config init [--project] [--force]` writes a fully commented sample with every key. Example:
```toml
provider = "claude" # or "codex"
+43
View File
@@ -0,0 +1,43 @@
## hx config: ~/.hx/config.toml (global) or .hx/config.toml (project, overrides global).
## Every setting is commented out and shows its default or an example; uncomment to change it.
# provider = "claude" # claude | codex | custom; default: the first logged-in provider
# model = "claude-sonnet-5-5" # model for the chosen provider
# claude_model = "claude-sonnet-5-5" # default: the account's latest Sonnet
# codex_model = "gpt-5.6-sol" # default: Codex's top-listed model
# explore_model = "claude-haiku-4-5" # read-only `task` subagents; default: cheapest tier of the provider
# remember_model = true # reuse the last model picked with /model or /provider
# compact_at = 900000 # auto-compact at this many tokens; default: 90% of the context window
# max_tokens = 16384
# permissions = "ask" # ask | yolo (bash/write/edit run without a prompt)
# mouse = true # wheel scrolling; false keeps terminal text selection
# codemode = false # `codemode` tool: JS scripts that call other tools in a sandbox
# system_prompt = "..." # replaces the built-in prompt; AGENTS.md is still appended
## OpenAI-compatible endpoint (Ollama, vLLM, LM Studio, OpenRouter), used with provider = "custom".
# [openai_compat]
# base_url = "http://localhost:11434/v1"
# api_key_env = "OPENROUTER_API_KEY" # name of the env var holding the key; the key never goes here
# models = [] # fixed list; empty = ask GET {base_url}/models
# context_window = 128000 # for models that don't report one
# [lsp]
# mode = "turn_end" # turn_end | agent_end | off
# tests = "turn_end" # affected tests: turn_end | agent_end | off
# disable = [] # built-in server ids, e.g. ["clangd"]
# enable_runners = [] # opt-in (slow): ["clippy"]
# disable_runners = [] # ruff, biome, eslint, ast-grep, rustfmt, ruff-format, biome-format
## Add or override an LSP server (same id replaces a built-in).
# [[lsp.servers]]
# id = "zls"
# language = "zig"
# extensions = ["zig"]
# command = ["zls"]
# roots = ["build.zig"]
# install = ["brew", "install", "zls"] # offered by the lsp tool when `zls` is missing
## Subprocess extensions (JSON-RPC over stdio); global and project lists are concatenated.
# [[extensions]]
# command = ["node", "my-ext.js"]
# timeout_secs = 10
+53
View File
@@ -74,8 +74,28 @@ enum Cmd {
},
/// Serve lens diagnostics + LSP navigation as an MCP server over stdio.
McpServe,
/// Config file helpers.
Config {
#[command(subcommand)]
action: ConfigAction,
},
}
#[derive(Subcommand)]
enum ConfigAction {
/// Write a commented sample config to ~/.hx/config.toml (or .hx/config.toml with --project).
Init {
#[arg(long)]
project: bool,
/// Replace an existing file.
#[arg(long)]
force: bool,
},
}
/// Every key commented out; `sample_config_parses` keeps it in sync with `Config`.
const SAMPLE_CONFIG: &str = include_str!("config.sample.toml");
#[derive(Subcommand)]
enum McpAction {
/// OAuth login for an HTTP MCP server from mcp.json.
@@ -510,6 +530,24 @@ async fn main() -> Result<()> {
print!("{}", hub.system_prompt());
return Ok(());
}
Some(Cmd::Config {
action: ConfigAction::Init { project, force },
}) => {
let p = if project {
std::env::current_dir()?.join(".hx/config.toml")
} else {
context::hx_home().join("config.toml")
};
if p.exists() && !force {
anyhow::bail!("{} exists; use --force to replace it", p.display());
}
if let Some(d) = p.parent() {
std::fs::create_dir_all(d)?;
}
std::fs::write(&p, SAMPLE_CONFIG)?;
println!("wrote {}", p.display());
return Ok(());
}
Some(Cmd::McpServe) => {
let cwd = std::env::current_dir()?;
let mgr = Arc::new(hx_lens::manager::Manager::new(
@@ -930,3 +968,18 @@ mod tests {
assert_eq!(pricing("gpt-5.6-terra").unwrap().input, 2.5);
}
}
#[cfg(test)]
mod config_tests {
#[test]
fn sample_config_parses() {
let s = super::SAMPLE_CONFIG;
toml::from_str::<super::Config>(s).expect("commented sample");
let on: String = s
.lines()
.map(|l| l.strip_prefix("# ").unwrap_or(l))
.collect::<Vec<_>>()
.join("\n");
toml::from_str::<super::Config>(&on).expect("uncommented sample must match Config");
}
}