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

fileresponsibility
main.goCLI: init, snapshot, run, eval, apply, log, rollback, traces
store.gocontent-addressed harness snapshots (ledger/store/<sha256>.tar)
manifest.goreads the editable-path list from harness/manifest.toml
sandbox.goPodman driver: agent container, scoring container, result collection
proxy.gounix-socket model proxy with token accounting and hard budget
ledger.goSQLite schema and queries (ledger/anchor.db)
evalrun.goevaluate one snapshot on one split with the run cache
apply.gocandidate 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

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:

  1. component must be listed in the manifest; the diff must touch exactly that one file and no other (I3, one component per edit).
  2. Not a whole-file rewrite: reject if the diff removes ≥ 80% of the file's lines and the file has ≥ 10 lines.
  3. 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).
  4. Apply to a scratch copy, snapshot, hash. If the hash equals the incumbent, reject (no-op).
  5. Evaluate on train. If train score ≤ incumbent train score, reject.
  6. Evaluate on holdout. Accept iff holdout score > incumbent holdout score (strict; ties reject, I6).
  7. 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)

Built 2026-09-09 22:20 UTC · therealagi.ai · a harness that writes itself, under an immutable core.