Cheat sheets

Repo Memory, Init Scripts and Handoffs

Frame the task, keep state in schema-checked files, probe before start, and end each session with a handoff packet.

  • Concepts and terms
  • Tasks and commands
  • Annotated code
  • Diagrams
  • Comparisons
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

One workbench session#

1Framewrite goal, facts, paths, acceptance andunknowns before any edit.2Init scriptprobe the workbench. On a fail, halt and surfaceto the human.3Readload the scope contract and agent_state.json.4Editchange allowed files only.5Proverun the acceptance command through the feedbackrunner.6Judgerun the verification gate, then the reviewer.7Clean upclean_state.json must hold an empty list.8Hand offgenerate handoff.md and handoff.json.

Commands#

CommandWhat it does
python3 code/main.pyRuns the lesson demo. Each one writes its files next to the script
python3 code/main.py in lesson 34Writes workdir/agent_state.json and workdir/task_board.json
python3 code/main.py --no-cacheLesson 35: ignore prereqs.lock and run every probe
python3 code/main.py --write-lkgLesson 35: pin current HEAD as last-known-good
git diff --name-only <baseline> HEADThe command behind the lkg_diff probe
python3 code/main.py in lesson 40Writes handoff.md and handoff.json
python3 -m unittest discover code/tests -vLesson 43: tests the task frame validator
python3 -m unittest tests.test_accountsAcceptance command of the example frame

Schema-first state#

"required": ["schema_version", "active_task_id", "touched_files", "next_action"]
"active_task_id": {"type": ["string", "null"], "pattern": r"^(T-\d{3,}|)$"}
"status": {"enum": ["todo", "in_progress", "done", "blocked"]}
mgr = StateManager(state_path, STATE_SCHEMA)
state = mgr.load()read, then validate
mgr.commit(state)validate, then atomic_write
fd, tmp_name = tempfile.mkstemp(prefix=path.name + ".", dir=path.parent)
os.fsync(fh.fileno())flush to disk first
os.replace(tmp_name, path)atomic rename

Init probes#

probe_runtime
fails below REQUIRED_PYTHON.
probe_dependencies
importlib.util.find_spec for each dep.
probe_test_command
shutil.which on the test command.
probe_env
fails on a missing env var.
probe_state_freshness
warn when the state is old or absent.
probe_lkg_diff
fail above the file diff budget.
Probe
returns (name, status, detail).
Report
init_report.json. Exit 1 on any fail.

Seven handoff fields#

summary
one paragraph of what was done.
changed_files
the diff at a glance.
commands_run
what was actually executed.
failed_attempts
what was tried and why it failed.
open_risks
what can bite next session, with severity.
next_action
the first concrete step. The load-bearing field.
verdict_pointer
outputs/verification/<task_id>.json and the review.
feedback_tail
last TAIL_K records plus every nonzero exit.

Prompt-only versus workbench#

OutcomePrompt-onlyWorkbench-guided
tests_actually_runFalseTrue
acceptance_metFalseTrue
files_outside_scope20
handoff_qualitymissingfull packet
reviewer_total39
StepsRead, edit, claim done8 steps, init to handoff

Defaults and numbers#

SettingDefaultNote
REQUIRED_PYTHON(3, 10)Runtime probe floor
STATE_FRESHNESS_SECONDS24 60 60Older state gives a warn
LOCK_TTL_SECONDS24 60 60Fresh lock skips the probes
PROBE_BUDGET_SECONDS3.0Slower pass becomes warn
LKG_FILE_DIFF_BUDGET50More changed files is a fail
schema_version1Only allowed enum value
TAIL_K5Feedback records kept in the handoff
Review total risk7Below it the handoff adds a warn

Task frame#

frame = TaskFrame(
goal="Prevent duplicate email addresses during signup",
allowed_paths=["app/accounts.py", "tests/test_accounts.py"],
forbidden_paths=["migrations/**", "deploy/**"],
acceptance=["python3 -m unittest tests.test_accounts"],
facts=[RepositoryFact("Duplicate errors use status 409",
"tests/test_accounts.py:44")],receipt
unknowns=["Whether email comparison is case-insensitive"])
issues = validate(frame)empty list means READY
render(frame)Markdown, Status: READY or BLOCKED

Classify each unknown#

Discoverable
the repository or running system can answer it. Continue.
Decidable
the task contract gives the agent authority. Continue.
Human
changes product behavior, cost, risk or public compatibility. Pause.
Deferred
outside this slice. Put it in non-goals.

Troubleshooting#

SymptomCauseFix
Next session redoes finished workState lived in chat, not the repoKeep state in schema-checked JSON in the repo
Session resumes on corrupt statewrite_text() with silenced exceptionsUse atomic_write: mkstemp, fsync, os.replace
does not match on T-bogusTask id breaks the patternUse ids like T-001
init failed; refuse to launch agentA probe has status failFix the probe. Do not start the agent
lkg_diff fail, files changed above budgetMore than 50 files since the last-known-goodA human ratifies the baseline with --write-lkg
Probe pass turns to warn with slow:Probe above the 3 second budgetMove it out of init or cache its result
no next_action recorded; needs humanState has no next_actionSet next_action before the handoff
Frame Status: BLOCKEDvalidate found issuesFix each line under Blocking issues

Questions#

What goes in repo memory?
Data useful three months from now in a CI rerun.
Two init runs in a row?
The second is a no-op except a fresh timestamp.
Handoff without next_action?
It is a status report, not a handoff.
handoff.md and handoff.json differ?
The JSON wins.
When to stop reading the repo?
When each decision has evidence, is delegated, or is an unknown.
When to wrap up?
At 50-75% of the context budget, not at 95%.

Tips#

  • Keep large artifacts out of agent_state.json. Store only the path.
  • Log each tool call ID to pending_calls.jsonl before execution.
  • Append each mutation to state.events.jsonl. Snapshot to state.json.
  • Keep one active handoff per branch and topic.
  • Give each fact a receipt: a file path and line.
  • Init has no network and no LLM calls.