Skip to content

Add autter badge: a README badge with the repo's AI-written share - #83

Closed
sagnik11 wants to merge 2 commits into
mainfrom
autter/pensive-liskov-0aebff
Closed

sagnik11 wants to merge 2 commits into
mainfrom
autter/pensive-liskov-0aebff

Conversation

@sagnik11

@sagnik11 sagnik11 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What

A new autter badge subcommand that gives any repository a README badge reading AI-written | 72%.

$ autter badge
AI-written: 72%  (912 AI-accepted of 1266 added lines)
Window: 58 non-merge commits since 2026-08-05, 54 with authorship notes

README snippet (copied to clipboard):

  [![AI-written](https://img.shields.io/badge/AI--written-72%25-5b5bd6)](https://autter.dev)

Metric definition

ai_percent = sum(ai_accepted) / sum(git_diff_added_lines) over the window, the same ratio each uploaded commit summary already carries as ai_percent (upload_commit_authorship_summary in post_commit.rs).

  • Window: the last 90 days of non-merge commits on the current branch by default; --since <date|duration> (anything git log --since accepts) or --all-time.
  • Commits without an authorship note add nothing to either sum but are counted, so the output reports coverage (commits_with_authorship / commits), like RangeAuthorshipStatsData.
  • Merge commits are skipped (they attest no lines and would only lower coverage).
  • .autter-ignore and --ignore <pat> apply through effective_ignore_patterns, as in autter stats.
  • The walk is capped at 2000 commits; the output says when the cap was hit (capped: true).

Computation lives in src/authorship/repo_share.rs; the command in src/commands/badge.rs.

Two snippet modes

  1. Live badge (cloud-linked repo, signed in). POST /cli/repo-badge-link with { "repo_url" } returns { "token", "badge_url"?, "page_url"? } (ApiClient::create_repo_badge_link, mirroring upload_commit_authorship_summary). The snippet points at <api_base_url>/api/public/repos/<token>/badge.svg and links to the repo's Autter page. The lookup runs on a thread with a 5s recv_timeout, so it never blocks longer than that.
  2. Static badge (everyone else). A shields.io static badge with the local number, plus one line saying why the live badge was not used. With --write on a GitHub remote the snippet becomes a shields.io endpoint?url= badge reading the committed .autter/badge.json from raw.githubusercontent.com, so it updates from the file.

--json prints the payload below, directly usable as a shields.io endpoint; --write [path] (default .autter/badge.json) stores it.

{"schemaVersion":1,"label":"AI-written","message":"72%","color":"5b5bd6","ai_percent":72.04,"ai_accepted":912,"added_lines":1266,"commits":58,"commits_with_authorship":54,"since":"2026-08-05","capped":false}

Colors (documented in autter badge --help): no data lightgrey; under 25% 74c0fc; 25-49% 007ec6; 50-74% 5b5bd6; 75% and up 2ee6c5 (Autter teal).

Backend half (separate monorepo change, not in this PR)

  • POST /cli/repo-badge-link (authenticated, org-scoped) returning the token.
  • GET /api/public/repos/:token/badge.svg: copy renderBadgeSvg from backend/src/services/scan-passport.ts and the token-gated route pattern /public/scans/:token/badge.svg from backend/src/routes/public-scans.ts. Data source: the commit_authorship_summaries table created in backend/src/routes/cli-data-plane.ts, aggregated per repo_url with the same ratio and color thresholds as above so both snippet modes match.

Tests

  • tests/integration/badge.rs (explicit mock_ai / mock_known_human checkpoints): all-AI repo, mixed repo, commits lacking notes (coverage), .autter-ignore, window flags and empty window, --write default and custom path, GitHub-remote endpoint snippet, help text; insta snapshot of the no-cloud Markdown output.
  • Unit tests for colors, message rounding, shields URL escaping, flag parsing, and percent.

cargo fmt --check, cargo clippy --all-targets -D warnings, and cargo test badge are clean locally.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

sagnik11 and others added 2 commits November 4, 2026 00:09
`autter badge` prints the share of added lines written by AI over the
last 90 days (or --since / --all-time) and a paste-ready Markdown
snippet. The number is sum(ai_accepted) / sum(git_diff_added_lines)
over commits with an authorship note, the same ratio each uploaded
commit summary carries as ai_percent; commits without a note are
counted so the output can report coverage.

--json prints a shields.io endpoint payload (schemaVersion, label,
message, color, plus the figures) and --write stores it, by default in
.autter/badge.json, so a committed file can back the badge without an
account. When the repository is linked to Autter and the user is signed
in, the snippet uses the live badge behind POST /cli/repo-badge-link;
otherwise it falls back to a static shields.io badge within 5s.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The backend mounts CLI routes under /api/cli, like every other CLI
endpoint, so the badge link request goes there too.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
sagnik11 added a commit that referenced this pull request Nov 3, 2026
Bumps the version to 3.0.0 in Cargo.toml, Cargo.lock and
npm/package.json, and adds the 3.0.0 changelog section for
`autter badge` (#83) and `autter wrapped` (#82), with the badge's
feature doc. Merging tags v3.0.0 and the Release workflow publishes.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@sagnik11

sagnik11 commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

Closing: this code already shipped in autter 3.0.0 through #82, which merged this branch in. Every file here is identical on main.

@sagnik11 sagnik11 closed this Nov 4, 2026
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.

1 participant