Skip to content

A4: Make a messy repository agent-ready

At a glance

  • Task: improve the small, messy practice repository that the course supplies. You add instructions, a blocking hook, better structure and checks.
  • Week: 5; hooks are taught in week 4
  • Weight: 2.5 points
  • Due: Sunday 23:59 in the listed week
  • Hand in: your revised repository, probe outputs, and report.json.
  • Done when: your hook blocks the assigned bad change at the event you attached it to. A good change and the regression run both pass. Your map tells a new agent where to work.
  • Time: published after a timed pilot; record your prediction and actual time.

Objectives

Create repository guidance and gates that support safe agent changes (LO2, LO4).

Prerequisites

Follow the course safety practices:

  • Run the agent in a dedicated directory or container.
  • Keep residency, employer and cloud credentials out of that environment.
  • Keep keys out of repositories, prompts, screenshots and logs.
  • Run injection demonstrations offline against the local machine only.

Use the mature coding-agent seat supplied for the course. Do not run an unknown generated command on a credential-bearing host.

The probes need Git and pytest in the environment you prepared on the setup page. Check before you start: python -m pytest --version must print a version.

Tasks

1. Inspect. Copy starter/ to a directory of your own outside the course checkout. That copy is your repository and your submission directory. Run every command in tasks 1 to 5 inside it. Make the baseline commit that its README describes. Then, before you ask for any change, map one behaviour to its files, tests and check command. The assigned bad change adds print("debug: leaked value") to app.py; your hook must block it.

2. Generate. Ask the agent to propose an instruction file, a small hook that blocks the assigned bad change, and a structural cleanup. Review every command before running it. Attach the hook to one of the two kinds of event taught in week 4, and record your choice as gate in report.json.

A Git hook (gate: {kind: git, event: pre-commit}) runs at each commit, whoever makes the commit. Put the hook where both Git and your reader can find it. Create the directory with mkdir -p .githooks, write your hook to .githooks/pre-commit, then run:

chmod +x .githooks/pre-commit
git config core.hooksPath .githooks
git add .githooks/pre-commit
git commit -m "Add pre-commit hook"

core.hooksPath is a local setting. It is not saved in a commit, so name that command in your instruction file. You must commit the hook file itself. A hook left in .git/hooks/ is not handed in.

A hook on the agent's own events (gate: {kind: agent, event: <the name your agent gives the event>}) runs at one of two moments. Before a tool call, it can stop the bad line from ever being written. At the end of a turn, it can stop the agent from reporting that it is done while the line is still there. Your agent's documentation explains how to attach a hook, how the hook receives the event and how it refuses. Commit the hook script, for example under .agent-hooks/. If the setting that attaches it lives outside the repository, commit a copy of that setting next to the script and name its real location in your instruction file. Make the hook save each event it receives under hook-events/ before it decides. You can then run it again on the same input. Either event sees only this agent's work. A hook at the end of a turn also lets the line stay in app.py until the agent tries to finish. In your explanation, say what your choice does not stop.

Also commit your structural cleanup before you go on to task 3. The bad probe in task 3 ends by resetting app.py to the last commit. That reset discards any uncommitted change to the file.

3. Verify the gate. Run the three probes as commands and keep each command, exit code and output.

With a Git hook, the probes are bad_commit, good_commit and regression. The bad commit must exit non-zero. The last line resets app.py to the last commit:

echo 'print("debug: leaked value")' >> app.py
git add app.py
git commit -m "bad probe"; echo "exit=$?"
git restore --staged app.py && git restore app.py

The good commit is a documentation or behaviour-preserving change and must exit zero:

printf '\nReviewed.\n' >> NOTES.md
git add NOTES.md
git commit -m "good probe"; echo "exit=$?"

With a hook on the agent's own events, the probes are blocked_run, allowed_run and regression. For the blocked run, ask the agent in a new turn to add print("debug: leaked value") to app.py. The hook must refuse the call that writes the line, or refuse the end of the turn while the line is there. Keep the part of the session that shows the refusal and the output of git diff --stat. Before you reset app.py with git restore app.py, run your hook again on the event it saved for that run. For a hook that reads its event on standard input, the probe's command looks like this:

python .agent-hooks/hook.py < hook-events/blocked.json; echo "exit=$?"

For the allowed run, ask the agent in another turn to add a Reviewed. line at the end of NOTES.md. The hook must allow it. Run the hook again on that saved event in the same way, then commit the change. The blocked run must exit non-zero and the allowed run zero. Some agents read a refusal from the hook's output, not from its exit code. In that case, write the probe command so that it exits non-zero when the output refuses. Keep that output in the evidence.

For either kind, the regression run must pass:

python -m pytest -q; echo "exit=$?"

4. Check structure. Confirm the instruction file names the same commands and invariants that the repository actually contains.

5. Revise. Fix one stale instruction or weak check. Commit that fix together with the instruction file, the map and your cleanup. Then repeat all three probes. The revision you record as after_revision must contain all of these changes (print it with git rev-parse HEAD). A5 later scores this repository at a named commit. Write the decision line.

Generation is the repository change that the agent proposes. Verification is the three probes plus your own inspection of the files.

Deliverables

Include the revised repository, the behaviour-to-code map, probe outputs and report.json. Name before and after revisions. Run from the course checkout:

python practice/a4/check.py path/to/submission

Grading

The criteria are:

  • usable instructions;
  • a hook that blocks the assigned bad change at the event you name;
  • passing good and regression checks;
  • clear structure;
  • evidence for one revision.

The public check only tests whether your record is consistent. It cannot replace a code review.

AI use rules

Green: the agent may propose documentation, a hook and refactoring ideas. Yellow: you may use generated code after you inspect it and run the probes. Red: accepting a gate, interpreting a failure and making the decision must be your own work. Keep credentials and private data out of the agent environment and logs. Attach one AI-use note ID.

Estimated time

Published after a timed pilot. Record your predicted and actual time. Ask for support when a hook or check behaves differently from its description.

Work record outline

assignment: A4
evidence: [{id: TODO, path: TODO, observation: TODO}]
before_revision: TODO
after_revision: TODO
instruction_path: TODO
structure_evidence: [TODO]
gate: {kind: git | agent, event: TODO}
probes: [{case: TODO, command: TODO, exit_code: TODO, evidence: [TODO]}]
explanation: TODO
ai_use_note: TODO
predicted_time: TODO
actual_time: TODO
decision: {action: accept | narrow | recheck | stop, because: [evidence ID(s)], next: TODO}

For kind: git, the probe cases are bad_commit, good_commit and regression. For kind: agent, they are blocked_run, allowed_run and regression. Record each case once. The outline lists the fields of report.json in plain text. starter/report.json holds them as JSON, except predicted_time and actual_time, which you add yourself. Evidence paths are relative to your submission directory. The check reads a field that still contains the word TODO, or text in angle brackets such as <name>, as unfilled.