namespace ClaudeDo.Worker.Usage.TokenTracker; /// One row of tokentracker sessions --format json. Field names mirror the /// export's snake_case keys: cached_input_tokens is the cache *read* count, /// cache_creation_input_tokens the write count. /// ⚠️ is not unique across rows — TokenTracker splits one /// Claude session into several rows (measured: 886 rows over 547 hashes), e.g. on a model switch. /// The segments are disjoint, so summing rows that share a hash is correct; counting them is not /// the same as counting sessions. public sealed record TokenTrackerSession( string SessionHash, string Source, string Model, DateTimeOffset StartedAt, long InputTokens, long OutputTokens, long CacheReadTokens, long CacheCreationTokens, double CostUsd, int Turns, int RetryTurns, bool Productive, bool OneShot); /// A parsed export plus when we fetched it. is the /// version field of the session rows — the only compatibility signal the export gives us. public sealed record TokenTrackerExport( int FormatVersion, IReadOnlyList Sessions, DateTime FetchedAtUtc); public sealed record TokenTrackerProbe( bool Installed, string? Version, bool NodeOk, string? NodeVersion, string? Error) { public static TokenTrackerProbe Unknown { get; } = new(false, null, false, null, null); } /// Outcome of one CLI invocation. false always carries an /// — callers turn that into state, never into an exception. public sealed record TokenTrackerRunResult(bool Ok, string StdOut, string? Error); /// Aggregated per date/model/scope. Scope is "claudedo" or "other", /// decided by whether the session hash belongs to one of our runs. Sessions replaces the /// old assistant-message count — it counts export rows (session segments), because the /// export has neither message granularity nor one row per session. public sealed record TokenTrackerModelRow( DateOnly Date, string Model, string Scope, long InputTokens, long OutputTokens, long CacheReadTokens, long CacheCreationTokens, int Sessions, double CostUsd); /// What the export adds on top of what task_runs already knows about a task. public sealed record TokenTrackerTaskExtras( double CostUsd, int Retries, bool Productive, bool OneShot);