hive-bash-mcp: count bash commands over OTEL in the daemon, drop the sqlite hand-off
This commit is contained in:
parent
9ec67d7a18
commit
076df804e4
1 changed files with 100 additions and 184 deletions
|
|
@ -6,7 +6,7 @@
|
|||
//! only the harness-only concepts: wall-clock turn duration as *this harness*
|
||||
//! measures it, what woke the turn, its outcome classification, the loose-ends
|
||||
//! backlog, sessions and their first turn's cost, context-window fill, the
|
||||
//! tools a turn called (claude exports no tool-call counter), bash commands,
|
||||
//! tools a turn called (claude exports no tool-call counter),
|
||||
//! reminders, and the cost an ACP agent reports — claude's runtime reports none.
|
||||
//!
|
||||
//! Synchronous instruments, not observable ones: unlike hive-c0re's
|
||||
|
|
@ -31,7 +31,6 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::OnceLock;
|
||||
use std::sync::atomic::{AtomicI64, Ordering};
|
||||
use std::time::Duration;
|
||||
|
||||
use opentelemetry::KeyValue;
|
||||
|
|
@ -96,9 +95,6 @@ struct Instruments {
|
|||
reported_cost: Counter<f64>,
|
||||
/// Tool calls made, keyed by `tool` (`Skill:<skill>` for a skill).
|
||||
tool_calls: Counter<u64>,
|
||||
/// Shell commands run by bash tasks, keyed by `command`: the normalised
|
||||
/// head the bash daemon records, not the full command line.
|
||||
bash_commands: Counter<u64>,
|
||||
/// Reminders scheduled and delivered, keyed by `event`.
|
||||
reminders: Counter<u64>,
|
||||
/// Input tokens of the first turn of a fresh claude session: what the
|
||||
|
|
@ -153,7 +149,6 @@ pub fn record(row: &TurnStatRow, fresh_session: bool) {
|
|||
for (tool, calls) in tool_call_counts(row.tool_call_breakdown_json.as_deref()) {
|
||||
inst.tool_calls.add(calls, &[KeyValue::new("tool", tool)]);
|
||||
}
|
||||
record_new_bash_commands(inst, row.started_at);
|
||||
}
|
||||
|
||||
/// The per-tool call counts a turn stored in `tool_call_breakdown_json`; a
|
||||
|
|
@ -164,25 +159,6 @@ fn tool_call_counts(json: Option<&str>) -> Vec<(String, u64)> {
|
|||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Unix seconds up to which bash commands are already counted; `0` before the
|
||||
/// first turn of this run.
|
||||
static BASH_COUNTED_UNTIL: AtomicI64 = AtomicI64::new(0);
|
||||
|
||||
/// Count the bash commands recorded since the last call. The first call after
|
||||
/// the harness starts counts only commands newer than `turn_started_at`, so a
|
||||
/// restart does not count the whole history again.
|
||||
fn record_new_bash_commands(inst: &Instruments, turn_started_at: i64) {
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let mut since = BASH_COUNTED_UNTIL.swap(now, Ordering::Relaxed);
|
||||
if since == 0 {
|
||||
since = turn_started_at.saturating_sub(1);
|
||||
}
|
||||
for (command, n) in crate::stats::bash_heads_since(since) {
|
||||
inst.bash_commands
|
||||
.add(n, &[KeyValue::new("command", command)]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Count one reminder event, `scheduled` or `delivered`. No-op when OTEL isn't
|
||||
/// configured, same as [`record`].
|
||||
pub fn record_reminder(event: &'static str) {
|
||||
|
|
@ -348,7 +324,6 @@ fn build() -> Option<Instruments> {
|
|||
.build(),
|
||||
reported_cost: meter.f64_counter("hyperhive.agent.cost.usage").build(),
|
||||
tool_calls: meter.u64_counter("hyperhive.agent.tool.calls").build(),
|
||||
bash_commands: meter.u64_counter("hyperhive.agent.bash.commands").build(),
|
||||
reminders: meter.u64_counter("hyperhive.agent.reminders").build(),
|
||||
first_turn_context: meter
|
||||
.u64_gauge("hyperhive.agent.first_turn.context")
|
||||
|
|
|
|||
Loading…
Reference in a new issue