A CLI for AI agent diffs
All tests pass.
Sure they do.
red-handed reads a code change and tells you if an AI coding agent got the tests green by cheating. A test that got skipped. An expected value bent to match the bug.
The checks are fixed regexes over the added and removed lines, there's no model in the loop and no API key.
npx red-handed demo
Exhibit A
agent/fix-discountagent: Fixed the discount bug. all tests pass
I ran it over 111 pull requests recently merged into React, Next.js, VS Code, Django, Kubernetes, Rails and six other big projects. It said CAUGHT three times and each one really did cut test coverage. A revert took its tests with it and a flaky check got deleted (the third wrapped an assertion in a try). All three had a reason and a maintainer's sign-off, which is fine, somebody looked. On 16 PRs opened by AI agents it said CLEAN every time, which was right.
It misses things. On 92 made-up diffs, written by AI agents that couldn't see the rules and measured before I tuned anything, it flagged 24 of 45 cheats and wrongly called 3 of 47 honest changes CAUGHT. If it gets yours wrong, send me the diff.
27 checks, 15 hard and 12 soft. No dependencies, just Node 20 and git.
27 checks. 3 CAUGHT in 111 merged PRs, all 3 real.
Playground
This runs src/ in your browser. A pretend agent was asked to fix a failing discount test. Pick one of the things it did, the other two tabs take a public pull request or your own diff.
Nothing scanned yet.
Pick a cheat. The last one is an honest fix.
Run it
Exit code is 0 for CLEAN or SUSPICIOUS, 1 for CAUGHT, 2 if it couldn't run. --strict fails on SUSPICIOUS too, and --json is there if you want to do something else with it.
npx red-handedInside a repo. Compares your branch with main and includes uncommitted and untracked files.
npx red-handed https://github.com/owner/repo/pull/12A public pull request, no clone. Set
GITHUB_TOKENfor private repos or the rate limit.npx red-handed demoBuilds a throwaway repo, cheats five ways and scans it. Same diff as "All five at once" above.
git diff main | npx red-handed -Any diff on stdin, or pass a
.patchfile.
GitHub Action
It posts one comment on the pull request and edits it on every push. Pull requests from forks get a read-only token, so there the report only goes to the job summary.
name: red-handed
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dizzymii/red-handed@v0
with:
fail-on: caught
27 rules
Read from src/rules.mjs, the same file the playground runs. One HARD finding makes the verdict CAUGHT. SOFT findings have honest uses, so they only make it SUSPICIOUS.
What it does not do
Treat it as a smoke alarm. When it goes off, go read the lines it printed.
It doesn't run your tests, so it can't tell you whether they pass. The rules are regexes over added and removed lines, and a determined author can get around them: build the string "te" + "st" and test-detection never sees it, or move the cheat somewhere it doesn't look.
So CLEAN only means the usual tricks aren't in the diff. Expect the odd false SOFT finding too. If you get a false HARD one, open an issue with the diff.
It doesn't send your code anywhere either, the only network call is to the GitHub API when you hand it a pull request.