1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::path::PathBuf;
use clap::{Args, ValueEnum};
/// `harn usage` — aggregate LLM spend/usage analytics from the local
/// event log's `provider_call_response` records.
#[derive(Debug, Args)]
pub(crate) struct UsageArgs {
/// Project root whose `.harn/events.sqlite` to read. Defaults to the
/// current working directory. Ignored when `--all` is set.
#[arg(long)]
pub project: Option<PathBuf>,
/// Discover and aggregate across every `<project>/.harn/events.sqlite`
/// found under the search roots (current dir, then `~/projects`),
/// skipping vendored `.cargo/registry` copies.
#[arg(long)]
pub all: bool,
/// Only include calls at or after this date (inclusive). Accepts
/// `YYYY-MM-DD` or an RFC3339 timestamp.
#[arg(long)]
pub since: Option<String>,
/// Only include calls strictly before this date (exclusive). Accepts
/// `YYYY-MM-DD` or an RFC3339 timestamp.
#[arg(long)]
pub until: Option<String>,
/// Roll up by one dimension. Defaults to `provider`.
#[arg(long = "group-by", value_enum, default_value_t = UsageGroupBy::Provider)]
pub group_by: UsageGroupBy,
/// Only include rows for this provider.
#[arg(long)]
pub provider: Option<String>,
/// Only include rows for this model.
#[arg(long)]
pub model: Option<String>,
/// Emit the stable JSON envelope instead of the text table.
#[arg(long)]
pub json: bool,
/// Emit CSV rows instead of the text table.
#[arg(long, conflicts_with = "json")]
pub csv: bool,
/// Reconcile local event-log totals against provider billing APIs or
/// Langfuse. Not implemented in v1 — reserved for a follow-up.
#[arg(long, value_name = "SOURCE", hide = true)]
pub backfill: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub(crate) enum UsageGroupBy {
/// One row per provider.
Provider,
/// One row per `provider/model`.
Model,
/// One row per calendar day (UTC), as a cumulative time series.
Day,
/// One row per ISO week (UTC), as a cumulative time series.
Week,
/// One row per calendar month (UTC), as a cumulative time series.
Month,
}