bootcc AUTONOMY.md
7.8 kB 162 lines
Markdown
at main

bootcc Autonomous Operating Contract #

This file is the standing, machine-parseable agreement every bootcc work session follows. It exists so that a brand-new crush run session (with no memory of prior sessions) can pick up and continue the multi-week project without any human input.

Work is executed as a self-perpetuating crank: an agent does one small, verifiable increment, commits it, advances the state, and the driver launches the next session.

Golden rules (do not violate) #

  1. Work only inside /home/lrvick/Sources/bootcc. Everything commits there. Never touch anything else.
  2. One small increment per session. Each session completes exactly one item from TASKS/NEXT.md, no more, no less.
  3. Prove it builds + tests before committing. The universal check is the gate:
    cd /home/lrvick/Sources/bootcc && sh tools/gate.sh
    
    It runs, in one place: make (build + full test suite), the make clean+make+cmp determinism check, the trailing-newline sweep, and the real-tcc.c frontier ratchet. It prints GO / NO-GO; only on GO do you commit. The gate also rewrites tools/.frontier_state - commit that file with the increment.
  4. Commit after every verified increment. Prefix messages with the task id. Attribute footer is already configured; keep it.
  5. M2-Planet subset discipline: bootcc source must compile under the vendored M2-Planet (make does this). That means: integer-only, no for(;;) (use while(1)), no long long, no variadic stdlib, bounded strings, and no trailing-code after a non-empty function body's closing brace. Every source file must end with a trailing newline (M2 fails on a missing final newline; the gate sweeps this for every file).
  6. Never rely on GCC. bootcc must be fully buildable and fully validated with M2-Planet/M2libc alone. The product build (build/amd64/bootcc) is pure M2 and must stay that way. GCC (and the gcc-built build/amd64/frontier-probe) may exist ONLY as an optional drift-detection oracle: a byte comparison of the SAME engine sources compiled two ways (m2==gcc). It is never a build input, never a gate requirement, and never the path used to validate an increment. When an oracle binary is cached in a scratch dir it must be rebuilt whenever the engine sources change (existence-only caching yields stale-oracle false failures). Validate engine work on the M2-built build/amd64/bootcc and against TCC 0.9.27 runtime parity, not on the gcc probe.
  7. Never brute-force a large component in one shot. If a task needs

    ~200 lines of new logic, split it into smaller self-contained increments and do ONE per session. If a piece keeps failing, reduce scope or write a tiny failing probe first.

  8. Update state every session. At session end: append to LOG.md and rewrite TASKS/NEXT.md to the concrete next increment.

Guardrails (machine-enforced, no discretion) #

These exist so a fully unattended crank cannot burn hours on a hang, commit a regression, or silently walk backward on the long-term goal.

1. The gate (tools/gate.sh) is the single definition of a completed #

increment

Worktree changes + make green + rebuild determinism + trailing newlines (every file except the four crafted EOF tests whose goldens pin no-trailing-newline EOF line reporting) + frontier non-regression. NO-GO means the increment is not done: keep working or park (below). Never commit on NO-GO.

2. The frontier ratchet (tools/frontier.sh + tools/.frontier_state) #

The frontier measures how far bootcc gets on the REAL TinyCC 0.9.27 tcc.c (-P tokens -> -s symbols -> -x first-error line -> -x clean -> -e first-error line -> -e clean), encoded as a comparable STAGE:DETAIL scalar. The gate refuses to pass if the scalar regresses. The state file is committed with every increment, so the ratchet lives in git history. A regression is only ever overridden with tools/frontier.sh --force and a LOG.md entry explaining exactly why it was justified.

3. Watchdog timeouts in every harness #

Every bootcc/driver/toolchain/tcc -run invocation in tests/run-*.sh runs under coreutils timeout (default 60s, override with BOOTCC_TEST_TIMEOUT; build steps get 300-600s). A hung case fails that case (exit 124), never the session. This exists because one unbounded infinite loop once burned 8.5 hours of CPU.

4. Park rules (stop, write state, yield) #

An agent that is not making progress must PARK, not spin:

  • Three strikes: if the SAME task fails the same way three times (three distinct fix attempts, each proven with make/make test green but not solving the task), stop. Write TASKS/PARKED.md (see format below) and end the session.
  • Stall rule: if K=3 consecutive increments pass the gate without the frontier scalar advancing (i.e. work that does not move the long-term goal), park the current task line and pick the next QUEUE line that can advance the frontier; if none exists, write TASKS/PARKED.md and stop.
  • Park format (TASKS/PARKED.md, append a dated section per park):
    ## PARKED <date>: <task id + one line>
    state:   <what is true right now, with evidence: commands + output>
    tried:   <the 3 attempts, each 1-2 lines>
    why:     <best hypothesis for why it is stuck>
    unpark:  <the concrete experiment that would unblock this>
    
    A fresh session that reads a parked section must run its unpark experiment BEFORE anything else on that task.
  • STOP file: if a STOP file exists in the repo root, do NO work and exit immediately (human halt convention; the human removes it to resume).

5. What a session may NOT do #

  • commit on gate NO-GO
  • override the ratchet without a LOG.md entry
  • delete, shrink, or loosen a test/golden to make a failure go away
  • touch vendor/ (checksum-gated third party)
  • run unbounded: every external command that could loop gets a timeout

Where things live #

  • PLAN.md — the original architecture plan.
  • LOG.md — running log of every completed increment (append only).
  • STATE.md — one-paragraph "where we are right now" (fresh session's first read).
  • TASKS/NEXT.md -- the single next task spec this session must do.
  • src/ -- bootcc source.
  • tests/ -- golden tests driven by make test (all watchdoged).
  • makefile -- M2-Planet build + tests.
  • vendor/ -- pinned M2-Planet/M2libc (do not modify).
  • tools/gate.sh -- the definition of a completed increment (GO / NO-GO).
  • tools/frontier.sh + tools/.frontier_state -- the real-tcc.c progress measure and its ratchet.

Session startup ritual #

At the very start of a session, read in this order:

  1. AUTONOMY.md (this file)
  2. STATE.md
  3. TASKS/NEXT.md
  4. git log --oneline -5 (see the last few commits)

Then do the task, test, commit, update STATE.md + TASKS/NEXT.md + LOG.md.

Session end ritual #

  • sh tools/gate.sh prints GO (it runs make + determinism + trailing-newline sweep + frontier ratchet; on GO it rewrites tools/.frontier_state).
  • git add -A && git commit with a good message (includes the frontier state file).
  • Append a line to LOG.md (note the frontier scalar if it advanced).
  • Rewrite TASKS/NEXT.md with the next single increment.
  • Update STATE.md to one line summarising the new position.
  • Do NOT push.

If you get stuck #

  • Re-read the exact M2-subset rules in PLAN.md section 2.
  • Reduce the increment to the smallest provable piece.
  • Write a tiny probe (/tmp/x.c) and M2-compile it to confirm a construct is accepted before relying on it.
  • It is fine to leave a later sub-item marked "deferred (see TASKS/NEXT.md)".