Skip to content

Week 5: Agent-ready codebases

Learning objectives

By the end of this week, you can:

  • locate a change point from a repository map and name the callers, rules and checks that constrain it (LO4);
  • ask an agent for a bounded proposal, then verify the proposal with independent tests, a diff and a local check (LO4, LO5);
  • score Structure, Documentation, Tests and Checks from observable anchors, name a disproving observation, and explain what evidence would change the score (LO4, LO5);
  • keep repository text and generated commands inside the approved safety boundary (LO7).

A repository is agent-ready when a fresh session can find the relevant code, learn the local contract, run a short check and report what it did not check. Readiness is a property of evidence at a named revision, not a feeling about how tidy the tree looks. A named revision is a specific commit.

Minimal example

One task, three states of one function

The task is deliberately small: replace a chain of status conditionals with a lookup while keeping the whitespace and case normalization, both aliases for passed (ok and pass) and the unknown fallback. The public fixture contains the same function in three states:

  • before.py is the disordered starting point: the caller and contract are not written beside the function;
  • rejected.py is a tempting proposal that removes strip();
  • refactored.py is a structure change that keeps the contract.

In this example, generation means two pieces of text: your request and the agent's proposal. A request for this task could read: “Replace the conditionals in status_label with a dictionary lookup. Return the same label for every input. Reply with the function only and run nothing.” The course wrote rejected.py and refactored.py as typical replies to such a request. Neither is a recorded model run. Read a proposal before anything runs it. Then verify it from the root of your course checkout. The verifier reads the variant files in its own folder, so it gives the same result from any directory:

python lectures/week-05/fixture/verify.py rejected
python lectures/week-05/fixture/verify.py refactored

Each command prints one line of JSON. The first exits with status 1 and reports the three padded inputs that fail:

{"cases": 10, "failures": [{"actual": "unknown", "expected": "passed", "input": " ok "}, {"actual": "unknown", "expected": "failed", "input": "\tfail\n"}, {"actual": "unknown", "expected": "passed", "input": " PASS "}], "if_statement_count": 0, "passed": 7, "scope": "course synthetic fixture; public feedback, not a grade", "variant": "rejected"}

The second exits with status 0:

{"cases": 10, "failures": [], "if_statement_count": 0, "passed": 10, "scope": "course synthetic fixture; public feedback, not a grade", "variant": "refactored"}

The result establishes those ten cases only. It does not prove behavior for every string or prove that a caller accepts the change.

You can also check a proposal from your own agent. Read it first, because the verifier imports the file and so runs every line in it. The file should hold only the function status_label and its lookup table, with no imports. Save it as candidate.py beside verify.py and run python lectures/week-05/fixture/verify.py candidate. The verifier tests it against the same ten cases. If the file is missing, the command prints a traceback ending ModuleNotFoundError: No module named 'candidate' and exits with status 1. That means the check did not run; it is not a failed case. Delete candidate.py when you have finished.

Now run the same fixed cases against the starting point:

python lectures/week-05/fixture/verify.py before
{"cases": 10, "failures": [], "if_statement_count": 3, "passed": 10, "scope": "course synthetic fixture; public feedback, not a grade", "variant": "before"}

before and refactored both pass all ten cases; only if_statement_count differs (3 and 0). The cases cannot tell the two states apart, which is the point: behaviour is preserved, and what changed is how much a fresh session has to guess. A fresh session is a new agent session with no memory of earlier work. In before.py a session must infer the contract from a chain of conditionals. In refactored.py the lookup table and the fallback are visible beside the change point. In a real project, a prepared repository would also name its entry point, contract and offline check in its instruction file. The agent still needs permission to read and edit. But the repository has removed the guesses that could be avoided.

What the comparison can and cannot show

The fixture is one function, so it cannot show every kind of blocker. The rows below are illustrative: they are the kinds of observation you will record in the studio on a whole repository, not results of the commands above.

Observation Supported claim Missing evidence
The session found status_label in two file opens The map points to this change point for this revision Other behaviours may have different maps
The documented check exits zero on the refactored copy These cases pass at this revision Callers, permissions and unlisted inputs
A repository lists three test commands, two of which fail Documentation is a blocker for a fresh session Whether the implementation itself is correct
A hook rejects an unused import with exit 2 The hook can stop that class of change Other checks and bypass paths

An agent may propose the score, but you choose it. For each dimension, record five things: the path or command, the revision, the observed result, the highest level whose anchors are all present, and one observation that would disprove the score.

Four observable readiness dimensions

Score each dimension on levels 1–4. An anchor is an observable condition that a level requires. Give each dimension the highest level at which you can show every anchor at the named revision. Level 1 means the map, file, test or gate is absent. Level 2 means it exists but at least one level-3 anchor cannot be shown yet; name which one. Level 4 needs every level-3 anchor as well as its own.

A5, due in Week 6, asks for this four-row score on your finished A4 repository, not on the repository you use in the studio. A5 prints its own, shorter anchor table. In A5, score from that table and use its wording. The lists below are the fuller version used in class.

Structure

  • 1: no map from a behaviour to its change point;
  • 2: a map exists, but a checked entry is wrong or mixes unrelated responsibilities;
  • 3: checked entries are accurate, the change point has one responsibility, and the probe reaches it in three file opens or fewer;
  • 4: a deliberate boundary violation fails a test or check.

Evidence is a behaviour, the files opened in order, a path:line change point and, at level 4, the failing result.

Documentation

  • 1: no instruction file (A5's table calls it a context file) or no runnable command;
  • 2: commands exist but one fails as written, or no invariant names the check that protects it;
  • 3: every listed command runs at the scored revision and at least three invariants name their checks;
  • 4: an automated check runs the documented commands and fails when one goes stale.

Evidence is the instruction-file path, each command and exit code, and the invariant-to-check list.

Tests

  • 1: no runnable test exercises the change point;
  • 2: one run passes but a hidden input, nondeterminism or a deliberate break goes undetected;
  • 3: two repeatable runs agree, stay within the chosen budget, use no hidden input, and a deliberate break fails;
  • 4: failure messages identify the broken behaviour and mutation evidence (small faults planted in the code on purpose, with a record of which ones the tests miss; Week 7 teaches it) accounts for surviving gaps.

The evidence is the two run summaries, the hidden-input search, and the deliberate-break result.

Checks

  • 1: no automatic gate (an executable check attached to an event the repository controls);
  • 2: a gate can be run by hand but is not required, or it ignores an unused import;
  • 3: one offline command runs the required gates and exits non-zero for an unused import;
  • 4: the gate runs before a commit is offered, and the project scanner stops a secret canary (a fake key such as sk-EXAMPLE, planted to see whether it is caught).

The evidence is the gate command, its failing and passing output, and the point where the gate is required.

Hands-on exercise

Use the studio activity on your own project or contribution target repository. First freeze a baseline at a named commit. Give the agent only the files it needs to answer one bounded question. Treat its proposal as untrusted text and inspect it. Then run the repository's documented check and inspect the diff. If a command needs a credential, network access or an unknown install, do not run it. Stop and revise the boundary instead.

Your first score is a four-row table with one evidence link and one disproving observation per row. Then remove one blocker that is within your scope—for example, reconcile two test commands, add a map from a behaviour to its module, or make a check command deterministic. Run the same probe at the new commit and score again. A tidy directory without a changed observation does not raise a score.

The studio page gives the timetable for the 90 minutes. Ask for help at the first failed command.

Supported execution

Run the fixture commands on this page directly, from the root of your course checkout with the Python environment from the setup page active. Before running a project's own check, follow Tools and model access.

Verification

Run the public fixture before and after reading the candidate. Expected: rejected exits with status 1 and reports 7 of 10 passed; refactored exits with status 0 and reports 10 of 10.

python lectures/week-05/fixture/verify.py rejected
python lectures/week-05/fixture/verify.py refactored

For your repository, run the exact command it documents, record its exit code and inspect the changed-file list:

git status --short
git diff --check
git diff --name-only

A passing check is evidence for the inputs it covered. A score changes only when the observed anchor changes at a named revision. Sometimes the same command passes only because its tests were deleted, its scope was weakened, or the agent reported a result without running a command. In that case, keep the old score and record the finding.

Common mistakes

Mistake How to detect it Correction
Scoring from a polished README A listed command fails or names a missing file Run each command at the scored revision and lower the row until it passes
Treating an agent's score as evidence No path, revision or output is attached Before you record a number, ask for one observable anchor and one observation that would disprove it
Refactoring only for shorter code The candidate passes happy paths but loses normalization or a caller contract Add the distinguishing case, restore the invariant, and rerun the unchanged check
Calling contradictory docs a test failure The same command is written three ways Choose one bounded source of truth and verify the chosen command. Record the conflict
Running a generated command blindly It asks for a key, network or an unpinned install Stop, inspect the trust boundary, and run it only in a dedicated directory or container that holds no credentials; otherwise record the missing prerequisite
Raising a score after deleting tests The test count or covered paths shrink Compare the old and new test lists and keep the score unchanged

End the work record with one decision: accept, narrow, recheck or stop. Name the evidence that supports it and the observation that would change it.