stats: log auto routing per prompt, hx stats routing report

This commit is contained in:
hermes committed 2026-11-10 22:08:55 +00:00
1 parent 478c007271
commit c6c4add124
5 files changed
+87 -1

No files matched your search

+23
View File
@@ -399,6 +399,29 @@ impl Router {
}
}
/// One line per routed prompt in `<session>.route` (JSON), read back by `hx stats`: the data to
/// tune the keyword lists and thresholds from. Best effort.
pub fn log(session: &std::path::Path, sig: &Signals, p: &Pick, effort: Effort, forced: bool) {
use std::io::Write;
let line = serde_json::json!({
"ts": hx_ai::auth::now_ms() / 1000,
"model": p.model,
"tier": p.tier.name(),
"wanted": sig.tier.name(),
"score": sig.score,
"effort": effort.name(),
"ctx": sig.ctx,
"hits": sig.hits,
"forced": forced,
});
// ponytail: a failed log write must not fail the prompt
let _ = std::fs::OpenOptions::new()
.create(true)
.append(true)
.open(session.with_extension("route"))
.and_then(|mut f| writeln!(f, "{line}"));
}
/// What `@word` at the start of a prompt asks for.
#[derive(Debug, Clone, PartialEq)]
pub enum Target {