Skip to content

git ai usage#1434

Open
clarete wants to merge 100 commits into
git-ai-project:mainfrom
clarete:lincoln/git-ai-usage
Open

git ai usage#1434
clarete wants to merge 100 commits into
git-ai-project:mainfrom
clarete:lincoln/git-ai-usage

Conversation

@clarete
Copy link
Copy Markdown

@clarete clarete commented May 24, 2026

git-ai usage — local AI usage statistics

This PR adds a new git-ai usage subcommand that aggregates locally recorded metric events into a human-readable (or JSON) summary of AI coding activity, without requiring a network connection or account.

usage

git-ai usage [--period 1d|3d|7d|30d] [--repo <substring>] [--json]

How it works

The telemetry worker already flushes metric events to a local SQLite DB (metric_events). This PR adds a second table, local_events, that stores a filtered copy of the three event types relevant to usage stats (Committed, Checkpoint, SessionEvent) as they are flushed. A 30-day retention window is enforced with a once-per-day prune pass.

git-ai usage reads directly from local_events — no DB writes, no network calls.

Global View

Screenshot 2026-05-24 at 7 32 05 PM

Repository View

Screenshot 2026-05-24 at 7 33 04 PM
Open in Devin Review

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 24, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ svarlamov
❌ clarete
You have signed the CLA already but the status is still pending? Let us recheck it.

devin-ai-integration[bot]

This comment was marked as resolved.

@clarete clarete force-pushed the lincoln/git-ai-usage branch 3 times, most recently from 88ce909 to 5870c0d Compare May 27, 2026 13:56
@svarlamov svarlamov closed this May 29, 2026
@svarlamov svarlamov reopened this May 29, 2026
@svarlamov svarlamov force-pushed the lincoln/git-ai-usage branch from 5870c0d to 3a78249 Compare May 29, 2026 14:02
devin-ai-integration[bot]

This comment was marked as resolved.

@svarlamov svarlamov force-pushed the lincoln/git-ai-usage branch from 84d2289 to 4040fab Compare June 5, 2026 18:45
devin-ai-integration[bot]

This comment was marked as resolved.

@svarlamov svarlamov force-pushed the lincoln/git-ai-usage branch 2 times, most recently from 5aaa275 to d023b54 Compare June 5, 2026 23:11
clarete and others added 17 commits June 5, 2026 23:46
Adds a new `git-ai activity` CLI command that shows aggregated stats
from locally persisted metric events (Committed, Checkpoint, SessionEvent).

- Schema migration 2→3: adds local_events table (never cleared, unlike
  the upload queue) with indexes on event_id and ts
- store_local_events() in telemetry_worker fires before upload attempts,
  persisting interesting events regardless of network status
- local_stats module aggregates events in memory: AI/human line splits,
  per-tool breakdowns, unique session counts, files touched
- git-ai activity [--period 7d|30d|all] [--json] (default: 30d)
- Excluded from daemon-required commands; reads local DB standalone

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tted

Commits with no AI lines were dropping their human_additions because the
early-return guard fired before the accumulation. Moved the accumulation
above the guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Displays AI acceptance rate (committed AI lines / checkpoint AI lines)
below the per-tool breakdown. Only shown when checkpoint history is
sufficient to produce a meaningful ratio (<= 100%).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…t-ai activity

- Activity over time: bar chart bucketed by day (<=7d), week (30d), or month (all)
  with empty buckets filled in so the chart is always contiguous
- AI coding velocity: each bucket shows AI lines + commit count so output
  doubles as a velocity trend across the period
- Time of day: 24-slot sparkline (local time) showing when AI-assisted
  commits land, using Unicode block chars for density

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Weekly buckets now display "May 18 – May 24" instead of just "May 18"
so users can see their work falls within the bucket rather than thinking
it refers to a specific day.

Activity over time section moved below Sessions and above Time of day.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace Commits/Checkpoints/Sessions headers with a top-level AI vs Human
percentage bar followed by stacked AI and Human sections. Surfaces the
same data with clearer framing — no internal "checkpoint" terminology.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Preserve the model from tool_model_pairs instead of stripping it, so the
breakdown distinguishes sonnet/opus/etc. Trims the redundant tool prefix
from the model name (claude::claude-sonnet-4-6 -> "claude · sonnet-4-6").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Surface how much committed code was confidently attributed to AI or
known-human vs left "untracked". Computed as (ai + human) / total git
diff additions. Answers the "can I trust these numbers" question by
exposing the size of the unattributed holes in the data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
clarete and others added 25 commits June 5, 2026 23:46
Three sites in print_terminal independently computed filled/empty block
counts and formatted them. Now handled by ratio_bar(value, max, width);
bar(pct, width) becomes a thin wrapper over it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rings

bucket_key and fill_buckets both independently produced daily/weekly/
monthly label strings. A change to any format required two edits. Now
handled by bucket_label(date, granularity) called from both sites.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Repositories block: replace block-bar + dot-separated stats with
  aligned tabular columns; singular/plural for commit/session labels
- Model breakdown lines now include "lines" unit after the count
- Acceptance rate shows a range (e.g. 56–81%) when multiple tools
  have valid data, falling back to the overall rate for single-tool
- WoW block: drop "↑ new this week" label when last week had no spend
  (redundant); fix "$-0.00" display by formatting near-zero as "$0"
- Add format_cost() helper: rounds to whole dollars for amounts ≥ $10,
  keeps cents below that threshold; applied to all cost display sites

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pre-compute max widths for tool names, line counts, model names, token
counts, and costs so each column lines up across rows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously each repo triggered a separate SQL scan via compute_activity,
giving O(n × repos) fetches. Now one fetch covers all repos and grouping
is done in memory via compute_activity_from_records.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove get_distinct_repo_urls, is_backfilled, mark_backfilled, and
  get_existing_commit_shas -- all had no callers
- Fix days_ago() u32 truncation: clamp before casting so values above
  u32::MAX do not silently wrap
- Inline store_local_events into flush_metrics chunk loop so events are
  walked once; interesting events are serialized once per flush instead
  of in a separate pre-pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds opportunistic pruning to insert_local_events: at most once per day
a DELETE removes rows with ts older than 30 days, keeping the table
bounded to roughly the window used by git-ai usage (max 60d period).
Last-prune timestamp is persisted in schema_metadata.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Events predating the repo_url column (migration 2->3) have no repo
identity and were mapping to repo_url="", inflating repos.len() and
incorrectly triggering the multi-repo display path for single-repo users.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…1d/3d)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously a failed DELETE left the timestamp unwritten, causing
prune_local_events_if_due to retry on every subsequent flush. Wrapping
both writes in a transaction makes them atomic: either both succeed or
neither does, so a failure advances the timestamp and avoids a retry loop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
committed * 100 could overflow u32 (wraps in release, panics in debug)
for tools with >42.9M committed AI lines. Widening to u64 before
multiplication eliminates the risk.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SessionRecord, compute_session_list, extract_claude_user_text,
extract_codex_user_text, and normalize_title had no call sites.
Removing them eliminates ~300 lines and a diverging copy of the
token-accumulation and yield-classification logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…usage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use u64 arithmetic for all percentage multiplications in usage.rs to
  prevent u32 overflow on large line counts (same fix pattern as the
  prior acceptance-rate fix)
- Fix spark_char overflow: value*8 now computed in u64 before casting
- Emit u32::MAX instead of silently dropping tools with no checkpoint
  events in the query window, so the ">100% (incomplete data)" signal
  is surfaced as intended
- Consolidate the two separate DB fetches in handle_usage into a single
  compute_all() call so overall stats and per-repo breakdown always
  reflect the same event snapshot

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If two processes race on the schema migration, the second ALTER TABLE
attempt would fail with "duplicate column name". Catch that specific
error so both processes proceed normally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@svarlamov svarlamov force-pushed the lincoln/git-ai-usage branch from d023b54 to 7f3a8d5 Compare June 5, 2026 23:46
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants