The agent loop
All work in cairn is tracked as a task. The graph lives as files under .cairn/. Every non-trivial change is a task, driven through its lifecycle. Drive tasks with cairn's MCP tools (as an agent) or the web UI (as a human); both go through the same rules.
States are defined in .cairn/config.yaml (default backlog → in_progress → in_review → done | canceled; closed: done, canceled). Transitions are free except two gates:
- deps gate: a task can't leave the initial state until every dependency is closed (its
readyflag reflects this). - checks gate: moving into a closed state auto-runs the task's
cmdchecks and refuses if any fail. Manual checks (nocmd) must be attested first.
Both gates are detailed in Checks & gates.
The eight steps
- Identity: call
identity; use its exact bound actor for session writes. - Find work: list ready tasks in the initial state ("what can I start now").
- Begin: call
beginwithexpected_actorand a uniqueidempotency_key. This claims the task, enters the working state, and returns the session id. - Build + heartbeat: make the change and periodically report concise progress with
heartbeat(status, never chain-of-thought). - Note: add a short provenance note at each meaningful decision (see below).
- Run checks: run the task's checks with
run_checksbefore handoff. This is enforced, not advisory.finishrefuses if any command check is still pending or failing (manual checks are exempt, since they're attested during review). - Finish: call
finishwith a review summary. This ends the session and moves the task to review; it does not claim the work is verified or close the task. Closing to a done state re-runs the command checks fresh, so a stalepasscan't slip through. - Close: transition to a closed state once reviewed; the checks gate runs and refuses on failure.
If work is abandoned, call cancel with a reason. This ends the session and releases the assignment while leaving the task open. Legacy clients may still use claim + transition, but their work is not session-observable.
TIP
The mechanics of begin/heartbeat/finish/cancel (supervision states, storage, the trust boundary) are covered in Sessions. Full tool parameters are in the MCP tools reference.
Note discipline
Provenance is the task's memory. Add a concise note (a sentence or two) whenever you:
- make or change a design decision (and why the alternative was rejected),
- deviate from the task's stated intent,
- discover a constraint (a frozen spec, an API limitation),
- hand off, block, or pause (what's left, what's blocking),
- finish: a closing note naming the files touched, the key decision, and how you verified.
Don't note the obvious ("started coding", restating the title) or anything the diff already says plainly. If a reader of only the provenance couldn't follow the story, you under-noted; if every entry restates the obvious, you over-noted.