Skip to content

Commit 7492d0a

Browse files
committed
refactor(rust): move binary-only report helpers out of ccusage-core
Every adapter glob-imports ccusage-core, so any core edit recompiled all 19 adapters (lib and test). The helpers only the ccusage binary uses - last_window, the summary/session JSON builders, group_project_output, filter_and_sort_summaries and the date formatters - now live in a new ccusage-report crate, so editing them rebuilds only ccusage-report and ccusage (~3s instead of the whole adapter fan-out). BUILT_IN_AGENT_NAMES, DEFAULT_SESSION_DURATION_HOURS and the home module move down into ccusage-cli (core re-exports them), so ccusage-config and ccusage-cli-parser no longer depend on ccusage-core and stop rebuilding on core edits. Behaviour is unchanged; the moved insta snapshots are byte-identical.
1 parent 0c76c3e commit 7492d0a

32 files changed

Lines changed: 526 additions & 310 deletions

‎rust/Cargo.lock‎

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rust/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ccusage-cli-parser = { path = "crates/ccusage-cli-parser" }
4141
ccusage-config = { path = "crates/ccusage-config" }
4242
ccusage-core = { path = "crates/ccusage-core" }
4343
ccusage-pricing-snapshots = { path = "crates/ccusage-pricing-snapshots" }
44+
ccusage-report = { path = "crates/ccusage-report" }
4445
ccusage-terminal = { path = "crates/ccusage-terminal" }
4546
ccusage-test-support = { path = "crates/ccusage-test-support" }
4647
assert_fs = "1.1.4"

‎rust/crates/ccusage-cli-parser/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ serde_json.workspace = true
1515
# The config-merge tests parse a command line against a config file, so they
1616
# need the config layer and a filesystem fixture.
1717
ccusage-config.workspace = true
18-
ccusage-core.workspace = true
1918
ccusage-test-support.workspace = true
2019
insta.workspace = true
2120
serde_json.workspace = true

‎rust/crates/ccusage-cli-parser/src/tests.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn checks_the_date_window_after_config_and_flags_are_merged() {
445445
std::iter::once(OsString::from("ccusage"))
446446
.chain(args.iter().map(|arg| OsString::from(arg.as_str()))),
447447
&config,
448-
ccusage_core::DEFAULT_SESSION_DURATION_HOURS,
448+
ccusage_cli::DEFAULT_SESSION_DURATION_HOURS,
449449
env!("CARGO_PKG_VERSION"),
450450
)
451451
};
@@ -482,7 +482,7 @@ fn statusline_ignores_reversed_default_date_window() {
482482
let result = Cli::parse_from_with_config(
483483
std::iter::once(OsString::from("ccusage")).chain(args.iter().map(OsString::from)),
484484
&config,
485-
ccusage_core::DEFAULT_SESSION_DURATION_HOURS,
485+
ccusage_cli::DEFAULT_SESSION_DURATION_HOURS,
486486
env!("CARGO_PKG_VERSION"),
487487
);
488488

@@ -1591,7 +1591,7 @@ fn named_pi_store_validation_does_not_break_statusline() {
15911591
.map(|arg| std::ffi::OsString::from(arg.as_str())),
15921592
),
15931593
&config,
1594-
ccusage_core::DEFAULT_SESSION_DURATION_HOURS,
1594+
ccusage_cli::DEFAULT_SESSION_DURATION_HOURS,
15951595
env!("CARGO_PKG_VERSION"),
15961596
);
15971597

@@ -1617,7 +1617,7 @@ fn named_pi_store_validation_does_not_break_agent_commands() {
16171617
.map(|arg| std::ffi::OsString::from(arg.as_str())),
16181618
),
16191619
&config,
1620-
ccusage_core::DEFAULT_SESSION_DURATION_HOURS,
1620+
ccusage_cli::DEFAULT_SESSION_DURATION_HOURS,
16211621
env!("CARGO_PKG_VERSION"),
16221622
);
16231623

@@ -1642,7 +1642,7 @@ fn reports_named_pi_store_validation_through_cli_config_error_path() {
16421642
.map(|arg| std::ffi::OsString::from(arg.as_str())),
16431643
),
16441644
&config,
1645-
ccusage_core::DEFAULT_SESSION_DURATION_HOURS,
1645+
ccusage_cli::DEFAULT_SESSION_DURATION_HOURS,
16461646
env!("CARGO_PKG_VERSION"),
16471647
);
16481648
let Err(error) = result else {

‎rust/crates/ccusage-cli/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# ccusage-cli
22

33
The plain argument types the runtime shares: `SharedArgs`, the per-command
4-
argument structs, and the enums the reports switch on.
4+
argument structs, the enums the reports switch on, and the few constants and
5+
helpers (`BUILT_IN_AGENT_NAMES`, `DEFAULT_SESSION_DURATION_HOURS`,
6+
`home::home_dir`) that `ccusage-config` and `ccusage-cli-parser` need without
7+
depending on `ccusage-core`.
58

69
This crate deliberately has no dependencies, no build script, and no embedded
710
assets. `ccusage-core` and all 17 adapters depend on it, so anything heavier
@@ -10,6 +13,9 @@ renderer, and the help JSON live in `ccusage-cli-parser` instead.
1013

1114
## Public surface
1215

16+
- `BUILT_IN_AGENT_NAMES`
17+
- `DEFAULT_SESSION_DURATION_HOURS`
18+
- `home::home_dir`
1319
- `types::AgentCommandArgs`
1420
- `types::AgentReportKind`
1521
- `types::BlocksArgs`

‎rust/crates/ccusage-cli/src/lib.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod home;
12
mod types;
23

34
pub use types::{
@@ -6,3 +7,28 @@ pub use types::{
67
PricingOverride, STANDARD_AGENT_REPORTS, SessionArgs, SharedArgs, SortOrder, SourceArgs,
78
StatuslineArgs, VisualBurnRate, WeekDay, WeeklyArgs, normalize_date_bound,
89
};
10+
11+
/// Default length, in hours, of one billing block.
12+
pub const DEFAULT_SESSION_DURATION_HOURS: f64 = 5.0;
13+
14+
/// Agent subcommands that ship in the binary, in report load order.
15+
pub const BUILT_IN_AGENT_NAMES: &[&str] = &[
16+
"claude",
17+
"codex",
18+
"opencode",
19+
"amp",
20+
"droid",
21+
"codebuff",
22+
"hermes",
23+
"pi",
24+
"goose",
25+
"openclaw",
26+
"kilo",
27+
"copilot",
28+
"gemini",
29+
"antigravity",
30+
"kimi",
31+
"qwen",
32+
"grok",
33+
"zcode",
34+
];

‎rust/crates/ccusage-config/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ path = "src/bin/generate_config_schema.rs"
1212

1313
[dependencies]
1414
ccusage-cli.workspace = true
15-
ccusage-core.workspace = true
1615
schemars.workspace = true
1716
serde.workspace = true
1817
serde_json.workspace = true

‎rust/crates/ccusage-config/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ assert how a parsed command line and a config file combine.
2020
## Depends on
2121

2222
- `ccusage-cli`
23-
- `ccusage-core`
2423
- `schemars`
2524
- `serde`
2625
- `serde_json`

‎rust/crates/ccusage-config/src/config.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ fn validate_named_pi_store_name(name: &str) -> std::result::Result<(), NamedPiSt
253253

254254
fn reserved_named_pi_store_names() -> Vec<&'static str> {
255255
std::iter::once("all")
256-
.chain(ccusage_core::BUILT_IN_AGENT_NAMES.iter().copied())
256+
.chain(ccusage_cli::BUILT_IN_AGENT_NAMES.iter().copied())
257257
.collect()
258258
}
259259

@@ -313,7 +313,7 @@ fn claude_config_dirs() -> Vec<PathBuf> {
313313
.map(PathBuf::from)
314314
.collect();
315315
}
316-
ccusage_core::home::home_dir()
316+
ccusage_cli::home::home_dir()
317317
.map(|home| vec![home.join(".config").join("claude"), home.join(".claude")])
318318
.unwrap_or_default()
319319
}
@@ -429,7 +429,7 @@ fn option_takes_value(arg: &str) -> bool {
429429
}
430430

431431
fn is_agent_command(command: &str) -> bool {
432-
ccusage_core::BUILT_IN_AGENT_NAMES.contains(&command)
432+
ccusage_cli::BUILT_IN_AGENT_NAMES.contains(&command)
433433
}
434434

435435
fn is_report_command(command: &str) -> bool {
@@ -807,11 +807,11 @@ mod tests {
807807
use serde_json::{Value, json};
808808

809809
use super::*;
810+
use ccusage_cli::DEFAULT_SESSION_DURATION_HOURS;
810811
use ccusage_cli::{
811812
BlocksArgs, CliConfig, CodexSpeed, CostMode, SortOrder, StatuslineArgs, VisualBurnRate,
812813
WeekDay, WeeklyArgs,
813814
};
814-
use ccusage_core::DEFAULT_SESSION_DURATION_HOURS;
815815
use ccusage_test_support::fs_fixture;
816816

817817
#[test]
@@ -1398,7 +1398,7 @@ mod tests {
13981398
.into_iter()
13991399
.collect::<BTreeSet<_>>();
14001400
let expected = std::iter::once("all")
1401-
.chain(ccusage_core::BUILT_IN_AGENT_NAMES.iter().copied())
1401+
.chain(ccusage_cli::BUILT_IN_AGENT_NAMES.iter().copied())
14021402
.collect::<BTreeSet<_>>();
14031403

14041404
assert_eq!(reserved, expected);

0 commit comments

Comments
 (0)