feat(cli): add stats command - #40
Conversation
|
super nice! thanks! |
Blankeos
left a comment
There was a problem hiding this comment.
Merge confidence: 3/5 (feat/stats-command -> main)
Stats CLI looks good. Blocking issues are on the live Anthropic stream path, plus this branch now needs a rebase.
Rebase first
GitHub reports CONFLICTING vs current main (at least src/aisdk/README.md, compatible.rs, openai.rs, response.rs after #39/#41/#42). Please rebase onto main before anything else.
Blockers
-
Anthropic
message_deltadropsstop_reason. Real Anthropic events always includeusage. The new branch returnsChunkType::Usageand never callsanthropic_message_delta, somax_tokens/refusal/ finish-reasonEndare lost. Existing tests omitusage, so they still pass.Probe with usage +
stop_reason=max_tokensgotUsage(...)instead ofIncomplete. Inaisdk/response.rs,Incompletebecomes Failed and aborts the step — so truncated/refusal turns now look like a cleanmessage_stopsuccess. -
Anthropic usage double-count.
message_startemits partial usage;message_deltaemits final.Chat::record_usagesaturating-adds, so input/cache/cost can be ~2x the bill.
Non-blocking
- No DB migration (usage lives in existing
messages.partsJSON). - Compatible SSE can emit
Usage+Endtogether (good). - Unconditional
stream_options.include_usage: trueis fine for Ollama/Groq today, but some strict proxies still 400 — consider gating. - ACP persists usage with cost hardcoded
0.0and pushes extra parts instead of merging. cargo fmt --check, aisdk boundary,cargo check --tests, and focused stats tests passed.
Checklist
- Rebase onto
main - Emit Anthropic usage without swallowing
stop_reason(or attach usage only to the final event) - Tests that include the
usageobject:max_tokens/end_turn, and nomessage_startdouble-count - Optional: gate
include_usage; ACP cost parity
Fix the Anthropic stop_reason + double-count with those tests → 4/5. Rebase + that → merge-ready from my side.
Thanks for the OpenCode-style layout — the CLI aggregation itself is in good shape.
2158611 to
b1bce54
Compare
|
Resolved the requested blockers in
Validation: |
PR Review — #40
|
| Item | Last review | Now |
|---|---|---|
| Rebase | CONFLICTING vs main |
Rebased; then main moved again (#37) — small conflict in root_help_lists_completion |
Anthropic stop_reason swallowed by Usage |
blocker | Fixed — anthropic_stream_chunks can emit both |
message_start double-count |
blocker | Fixed — start is log-only |
Tests with usage payload |
missing | Added |
include_usage always on |
nit | unchanged |
ACP cost 0.0 / extra parts |
nit | unchanged |
| DB migration | none | none |
Checks run
| Check | Result |
|---|---|
cargo fmt --all -- --check |
pass |
scripts/check-aisdk-boundary.sh |
aisdk boundary ok |
| Anthropic usage tests + stats/CLI/record_usage | 10 passed |
Confidence bumps
| If you do | New score |
|---|---|
Rebase onto main and fix root_help_lists_completion |
4.5/5 |
Above + ACP merge/pricing parity, or gate include_usage |
5/5 |
Keep the stats CLI from this PR and the real provider usage/cost persistence from main. Anthropic now merges message_start + message_delta so input/cache tokens are not dropped, and sessions.total_cost is rolled up from usage parts.
Format sessions, messages, days, and per-model message counts with thousands separators. Keep token totals compact (K/M/B) and leave tool-usage counts ungrouped.
ACP was storing billed tokens with cost 0.0, so stats/history from ACP sessions looked token-rich and cost-poor. Reuse the same host catalog estimate as the TUI instead of leaving cost blank.
|
LGTM thanks @yan-ad ! |
Summary
crabcode statswith an OpenCode-compatible terminal layout--days,--tools,--models [N], and--project [PROJECT]Validation
cargo fmtcargo checkcrabcode statsoutput comparison againstopencode statsNotes
Crabcode currently does not persist input/cache token breakdowns or per-message model cost, so those fields remain zero until that data is recorded. Existing output token, session cost, model, and tool-call data are reported from SQLite.