heartgold
Point it at a repo and a goal. It researches how the best people solve that problem, tries several
implementations in isolated git worktrees, and keeps only the changes it can prove are better.
"In the streets of Philly where n—— don't even get to turn old
My heart pumping 'til it turn gold"
— Meek Mill, Classic Freestyle Pt. 2, as heard on Knxwledge's sameolemeek_
🎧 Listen: Bandcamp ·
Spotify ·
Lyrics
The name and the golden heart come from this track: a heart that keeps pumping until it turns gold.
heartgold does the same to a codebase: it keeps beating, round after round, until the code is gold.
What it does
python -m heartgold run path/to/repo --goal "Make lcs_length as fast as possible without changing its results"
A goal compiler (one cheap agent call, with a keyword fallback) reads the goal and the code and picks the mode, and
the function the goal is about. --mode speed|bug|spec skips it.
Speed mode (make code faster without changing what it returns). If the repo has no benchmark, heartgold writes
one first, built from how the code is really used (inputs like those in the tests, README and call sites), and keeps
it in .heartgold/ where no attempt can edit it.
- Identical-output oracle. It writes a few hundred probe inputs and records what the original code returns.
Every candidate must match those results exactly. Wrong-but-fast code is never kept.
- Independent benchmarks. It writes its own second benchmark with different inputs and parameter ranges, plus
adversarial worst-case benchmarks aimed at the current winner (RAISE-style minimax). A change must hold up on
all of them, not just the repo's own
bench.py.
- Research. It runs web research (via a
searchify CLI, when installed) and GitHub code search
(gh search code) for the fastest known algorithms, and turns the results into ranked ideas with sources.
- Rounds of attempts. Each round, coding agents try different ideas in parallel in separate git worktrees,
starting from the current best. The fastest verified attempt wins and is merged at once.
- Recovery. Attempts that are fast but wrong get a repair round that shows exactly which inputs differ. Good
ideas that were implemented badly get a retry with reference implementations. When a round brings no gain, a
fresh web + GitHub research round feeds the next one.
Close wins (under 1.5x) are re-timed against the current best, interleaved (old, new, old, new...), and kept only
if the bootstrap 95 % interval of the time ratio is entirely below 1. The final report gives the speedup with that
interval.
Bug mode (a wrong result, a crash, a bug report): it first writes reproduction tests and accepts them only if they
run and fail on the original code. The reproduction alone isn't trusted: it must fail first, then pass after the fix
(fail-to-pass). Then candidates, differential testing and a judge as in spec mode; a fix is kept only if the
reproduction passes and every original test still does.
Spec mode (build or fix behaviour to a written specification): it researches the requirements with verbatim-quote citation checks, fetches the full
specification text, writes tests from it, builds several candidates, finds inputs where they disagree, and has a
spec-reading judge settle each disagreement into an exact-value test (DiffSpec-style).
Metric mode (give --metric-cmd and --holdout-cmd): for scores rather than speed (accuracy, recall, nDCG). The
repo prints its score as JSON on data the agents may tune on, and on held-out data that only heartgold may read
(HEARTGOLD_HOLDOUT=1 is set for that one command and never for an agent). Attempts run in parallel worktrees and
are chosen on tune data; tests and the metric code itself are restored before every score; a change that makes the
held-out score worse is dropped as overfitting. The report quotes the held-out change with a paired-bootstrap 95 %
interval, the only number worth quoting.
The gate, in every mode. Before any candidate is scored, the repo's original tests and the harness around them
(benchmark files, conftest.py, pytest.ini, jest/vitest/phpunit/rspec config) are restored from the baseline, and
the candidate must pass at least as many original tests as the unchanged code did, so skipping or deselecting tests
cannot buy a pass. Any attempt that edited tests or harness files is logged as tamper in the ledger.