Skip to content

Commit 7f7e319

Browse files
authored
Merge pull request anomalyco#884 from affaan-m/feat/ecc2-token-meter
feat(ecc2): token/cost meter widget
2 parents e7d8275 + d7bcc92 commit 7f7e319

6 files changed

Lines changed: 577 additions & 42 deletions

File tree

‎ecc2/src/comms/mod.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ pub enum MessageType {
1313
/// Response to a query
1414
Response { answer: String },
1515
/// Notification of completion
16-
Completed { summary: String, files_changed: Vec<String> },
16+
Completed {
17+
summary: String,
18+
files_changed: Vec<String>,
19+
},
1720
/// Conflict detected (e.g., two agents editing the same file)
1821
Conflict { file: String, description: String },
1922
}

‎ecc2/src/config/mod.rs‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
33
use std::path::PathBuf;
44

55
#[derive(Debug, Clone, Serialize, Deserialize)]
6+
#[serde(default)]
67
pub struct Config {
78
pub db_path: PathBuf,
89
pub worktree_root: PathBuf,
@@ -11,6 +12,8 @@ pub struct Config {
1112
pub session_timeout_secs: u64,
1213
pub heartbeat_interval_secs: u64,
1314
pub default_agent: String,
15+
pub cost_budget_usd: f64,
16+
pub token_budget: u64,
1417
pub theme: Theme,
1518
}
1619

@@ -31,6 +34,8 @@ impl Default for Config {
3134
session_timeout_secs: 3600,
3235
heartbeat_interval_secs: 30,
3336
default_agent: "claude".to_string(),
37+
cost_budget_usd: 10.0,
38+
token_budget: 500_000,
3439
theme: Theme::Dark,
3540
}
3641
}
@@ -52,3 +57,36 @@ impl Config {
5257
}
5358
}
5459
}
60+
61+
#[cfg(test)]
62+
mod tests {
63+
use super::Config;
64+
65+
#[test]
66+
fn default_includes_positive_budget_thresholds() {
67+
let config = Config::default();
68+
69+
assert!(config.cost_budget_usd > 0.0);
70+
assert!(config.token_budget > 0);
71+
}
72+
73+
#[test]
74+
fn missing_budget_fields_fall_back_to_defaults() {
75+
let legacy_config = r#"
76+
db_path = "/tmp/ecc2.db"
77+
worktree_root = "/tmp/ecc-worktrees"
78+
max_parallel_sessions = 8
79+
max_parallel_worktrees = 6
80+
session_timeout_secs = 3600
81+
heartbeat_interval_secs = 30
82+
default_agent = "claude"
83+
theme = "Dark"
84+
"#;
85+
86+
let config: Config = toml::from_str(legacy_config).unwrap();
87+
let defaults = Config::default();
88+
89+
assert_eq!(config.cost_budget_usd, defaults.cost_budget_usd);
90+
assert_eq!(config.token_budget, defaults.token_budget);
91+
}
92+
}

‎ecc2/src/main.rs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
mod comms;
12
mod config;
3+
mod observability;
24
mod session;
35
mod tui;
46
mod worktree;
5-
mod observability;
6-
mod comms;
77

88
use anyhow::Result;
99
use clap::Parser;
@@ -63,10 +63,13 @@ async fn main() -> Result<()> {
6363
Some(Commands::Dashboard) | None => {
6464
tui::app::run(db, cfg).await?;
6565
}
66-
Some(Commands::Start { task, agent, worktree: use_worktree }) => {
67-
let session_id = session::manager::create_session(
68-
&db, &cfg, &task, &agent, use_worktree,
69-
).await?;
66+
Some(Commands::Start {
67+
task,
68+
agent,
69+
worktree: use_worktree,
70+
}) => {
71+
let session_id =
72+
session::manager::create_session(&db, &cfg, &task, &agent, use_worktree).await?;
7073
println!("Session started: {session_id}");
7174
}
7275
Some(Commands::Sessions) => {

‎ecc2/src/session/store.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ impl StateStore {
236236
.into_iter()
237237
.find(|s| s.id == id || s.id.starts_with(id)))
238238
}
239-
240239
pub fn send_message(&self, from: &str, to: &str, content: &str, msg_type: &str) -> Result<()> {
241240
self.conn.execute(
242241
"INSERT INTO messages (from_session, to_session, content, msg_type, timestamp)

0 commit comments

Comments
 (0)