Anchor design (Layer 0)
Read PLAN.md §2 first. The Anchor is the frozen, hand-reviewed Go program that measures the harness, keeps the ledger, and applies or rejects candidate edits. Target 500 LOC, ceiling 1000 (non-blank, non-comment lines of non-test Go). It contains zero model calls and zero credentials.
Files
| file | responsibility |
|---|---|
main.go | CLI: init, snapshot, run, eval, apply, log, rollback, traces |
store.go | content-addressed harness snapshots (ledger/store/<sha256>.tar) |
manifest.go | reads the editable-path list from harness/manifest.toml |
sandbox.go | Podman driver: agent container, scoring container, result collection |
proxy.go | unix-socket model proxy with token accounting and hard budget |
ledger.go | SQLite schema and queries (ledger/anchor.db) |
evalrun.go | evaluate one snapshot on one split with the run cache |
apply.go | candidate validation and the acceptance rule (invariant I6) |
Key decisions
Snapshots are tarballs hashed over sorted paths, zero mtimes, fixed modes. The hash identifies a harness generation; harness/ on disk is just a working copy of the current head. anchor rollback <gen> re-extracts a snapshot.
The run cache is keyed by (harness hash, task hash, model name). A task hash covers every file in the task directory including hidden tests, so editing a task invalidates its cached runs. Nothing is re-run when nothing changed (PLAN §5).
The model proxy lives in the Anchor. PLAN §5 demands a hard token budget enforced in the Anchor, and invariants I2/I5 demand the sandbox has no network and no credentials. A dumb forwarder on a unix socket satisfies all three: it is the sandbox's only egress, it holds the credential outside the sandbox, and it is the one place every token is counted. It parses only the usage field; it knows nothing about prompts, models, or message formats.
SQLite via modernc.org/sqlite. PLAN §2 mandates SQLite; a pure-Go driver keeps the single static binary property that motivates Go for Layer 0. This is the Anchor's only third-party dependency and it needs the human owner's explicit approval (PLAN §7).
The manifest is parsed as the tiniest TOML subset: the quoted strings inside editable = [ ... ], comments stripped. Nothing else in the file is read.
Diffs are applied with git apply in a scratch copy of the snapshot. No diff library in the Anchor. git is an external tool, not a Go dependency.
Commands
anchor init --harness <dir>: snapshot the hand-written baseline, evaluate train and holdout, write generation 0 with decisionbaseline. Refuses to run twice.anchor snapshot <dir>: store a snapshot, print its hash.anchor run --harness <hash|dir> --task <task dir>: one task, one sandbox, prints the run record as JSON. Used by tests and for debugging.anchor eval --harness <hash|dir> --split <train|holdout|sealed> [--force]: mean score over the split using the run cache; prints per-task rows and the mean; records an eval row.anchor apply --candidate <json>: the acceptance rule below.anchor log [--json]: generations, train and holdout side by side.anchor rollback <gen>: head moves to that generation's snapshot, theharness/working copy is re-extracted, and a generation row with decisionrollbackrecords it. Re-evaluating the restored hash hits the cache, so the score is reproduced exactly;--forcere-runs it for real.anchor traces --split train [--harness <hash>] [--failed]: run rows and trace paths for the Evolver. Any split other thantrainis refused.
Acceptance rule (anchor apply)
Input: a candidate JSON {"diff": <path>, "component": <manifest path>, "hypothesis": <text>, "trace_ids": [<run ids>]}. Steps, each recorded with a reason on rejection:
componentmust be listed in the manifest; the diff must touch exactly that one file and no other (I3, one component per edit).- Not a whole-file rewrite: reject if the diff removes ≥ 80% of the file's lines and the file has ≥ 10 lines.
- Task-specific string detector (PLAN §4): reject if any added line contains a train task id, module name, or a quoted string of ≥ 8 characters taken from a train task's prompt or public tests, unless that string already occurs in the incumbent harness (then it is harness vocabulary, not a leak).
- Apply to a scratch copy, snapshot, hash. If the hash equals the incumbent, reject (no-op).
- Evaluate on
train. If train score ≤ incumbent train score, reject. - Evaluate on
holdout. Accept iff holdout score > incumbent holdout score (strict; ties reject, I6). - On accept: new generation row, head moves,
harness/working copy is refreshed from the new snapshot. On reject: generation row with the decision and both scores, head unchanged.
Every step writes to the ledger before the next begins, so an interrupted apply leaves a truthful record (I4).
Ledger schema
runs(id, harness_hash, task_hash, task_id, split, model, score, passed, total,
tokens_in, tokens_out, wall_ms, exit_code, trace_path, created_at)
evals(id, harness_hash, split, model, score, n_tasks, cached, created_at)
generations(gen, parent_gen, harness_hash, diff_hash, component, hypothesis,
trace_ids, decision, reason, train_pre, train_post,
holdout_pre, holdout_post, tokens, created_at)
head(id=1, gen)anchor traces --split train is the only trace access the Evolver uses; it never lists holdout or sealed runs. anchor log shows both train and holdout scores side by side for humans and the site, per PLAN §4.
Tests (written before the implementation)
sandbox_test.go: a container started with the real mount set cannot findanchor,holdout,test_hidden.py, orreferenceanywhere on its filesystem, has no network, and cannot write outside/work.store_test.go: snapshot hash is stable across runs and across mtime changes, and differs when content changes.proxy_test.go: usage is counted for both wire formats; the budget cuts off with 429; the credential header is injected and never echoed.apply_test.go: each rejection reason in the acceptance rule; ties reject; whole-file rewrite rejects; task-string detector fires.nollm_test.go: no Go source underanchor/mentions a model endpoint or provider SDK; total LOC under 1000.ledger_test.go: a generation can be reconstructed from the log alone; rollback restores the exact snapshot.
Built 2026-09-09 22:20 UTC · therealagi.ai · a harness that writes itself, under an immutable core.