Add a security review or a gate reviewer
Kraft ships two review skills besides the code review. The default chain runs
one of them at every gate; no shipped chain runs the other.
kraft:gate-reviewreads the document a gate is about and reports a verdict before you're asked. Checking first, it sends back work that isn't ready and hands the rest to you with a note. Deciding, it may also approve, so a gate that needs no person's decision no longer waits for one. It never clears the gate itself. Thedefaultchain's gates all check first.kraft:security-reviewreviews a change that touches authentication, sessions, tokens, secrets or permission checks. It reports findings the waykraft:code-reviewdoes, so they enter the same fix loop. It runs only in a chain you add it to.
Both cost money. A gate reviewer is a paid agent session on every item that reaches the gate with auto-gate on. A security pass costs an extra agent session per review round on every item.
Before you start
- A running Kraft server.
- A chain of your own to edit. Step 2 makes
chains/reviewed.yaml; if you already have a chain, edit that one. - Your config directory:
~/.kraft/config/, or$KRAFT_HOME/config/if you setKRAFT_HOME.
Add a security review to verification
- Add the task to
library.yaml, undertasks::config/library.yamlsecurity_review: kind: agent harness: claude prompt: Review this work item's change for security defects. skill: kraft:security-review inputs: [review_package, carried_findings, previous_review] - Make
chains/reviewed.yaml, a chain that extendsdefault, and overrideverificationso it runs the security review beside the code review. An override replaces a list it sets, asextendsdoes, so write both steps out:config/chains/reviewed.yamlid: reviewed extends: default overrides: verification: steps: - id: tests tasks: - id: test_changed_scopes extends: kraft-default:verify_changed_scopes - id: review read_only: true tasks: - id: code_review extends: kraft-default:code_review - id: security_review extends: security_review
The shipped taskskraft-default:verify_changed_scopesandkraft-default:code_reviewcome from the built-inkraft-default. Thesecurity_reviewtask is yours, from step 1, so it keeps its bare name.
In a chain that lists its ownnodes, put the samestepson its- id: verificationentry instead.
Tasks in one step run in parallel, so both reviews read the same tests-green change. Their findings share the node's fix loop.read_only: true, as on the shippedreviewstep, stops the item for you if either review changes the worktree.
Change or turn off the gate reviewer in the default chain
Added in 2.6
Each gate in the default chain (spec_approval, plan_approval,
chain_revision_approval, local_review and final_review) has an
auto_review that extends gate_reviewer, with
auto_review_mode: checks_first. A chain that extends default inherits all
five. Change one with an override, beside verification under the same
overrides: in chains/reviewed.yaml:
overrides:
# verification: as above
spec_approval:
auto_review_mode: decides
plan_approval:
auto_review:
prompt: Check that every task in the plan traces to the spec.
local_review:
auto_review: null
auto_review_mode: decideslets the reviewer approve as well. A deciding reviewer can clear the gate with no person, so keep it to a gate you trust an agent with. Atfinal_review, an approval starts the merge.- An override of the reviewer's
prompt,skillorharnesskeeps the rest ofgate_reviewer. It can't set the reviewer'sid,kindorextends: Kraft refuses the chain withan override cannot set auto_review.id, auto_review.extends. auto_review: nullleaves the gate to you, with no reviewer.- To skip every reviewer on one item, file it with
--no-auto-gate. - While a gate's reviewer runs,
kraft item skip,retryandresumeon the item are refused as a walk already running. Approving or rejecting the gate stops the reviewer first.
A chain written before this release that gives a default gate its own
auto_review, with an id, a kind or an extends, stops resolving with that
refusal. Delete those keys from the override's auto_review and keep the rest:
a reviewer that extended gate_reviewer needs nothing more, and one that set
its own prompt, skill or harness keeps them as overrides of the gate's
reviewer. Keep auto_review_mode, if the override sets one.
Add a gate reviewer to a gate
A gate in a chain that lists its own nodes, or one you add to a chain, has
no reviewer until you give it one.
- Pick the gate to review. This guide uses
spec_approval, in a chain of your own that lists itsnodes. - Find the
gate_reviewertask. The built-inkraft-defaultships it, and from your own chains you name itkraft-default:gate_reviewer: a baregate_revieweris looked up in your ownlibrary.yaml. A home with a full copy of the library, seeded before Kraft shippedkraft-default, may lack it. Add it undertasks:as below, or move onto kraft-default and use the prefixed name in step 3:config/library.yamlgate_reviewer: kind: agent harness: claude prompt: Check this gate before the person decides. skill: kraft:gate-review - Give the gate an
auto_reviewthat extends it, andauto_review_mode: checks_first, on its entry undernodes::config/chains/my-chain.yamlnodes: # spec: as before - id: spec_approval kind: gate message: Review and approve the specification. artifact: spec reject_to: spec auto_review_mode: checks_first auto_review: id: reviewer extends: kraft-default:gate_reviewer
In the Templates screen, a gate's "Add a reviewer" menu does the same: a reviewer added there checks first, and the gate's "reviewer may" row switches the mode. - To let the reviewer approve as well, set
auto_review_mode: decides, or leave the key out. A deciding reviewer can clear the gate with no person, so it is the stronger choice, for a gate you trust an agent with. Its task can also be written out in place ofextends:config/chains/my-chain.yamlnodes: - id: spec_approval # kind, message, artifact and reject_to: as above auto_review: id: reviewer kind: agent harness: claude prompt: Decide whether this gate needs a person. skill: kraft:gate-review - Leave out
fallback:. A gate review launches its reviewer once, so Kraft refuses the task at launch if it selects an agent profile (profile:) whose tier has afallback:list.
Auto-gate is on by default for an item you file, so adding auto_review starts a
paid reviewer agent on every such item that reaches the gate. An item filed by a
schedule, POST /api/triggers or auto-intake has it off, and --no-auto-gate
opts one more item out, in either mode. Filing a work item
has the rule.
What the reviewer can decide
The reviewer runs as a worker, so Kraft refuses it if it tries to approve or
reject. It reports a verdict, and Kraft applies it. The gate's
auto_review_mode says which verdicts count:
auto_review_mode | The reviewer reports | What Kraft does |
|---|---|---|
checks_first | reject or pass | A reject sends the work back, with concerns as the steer. A pass leaves the gate to you, shown as ready for you with the reviewer's note. An approve counts as a pass. Added in 2.5 |
decides, or unset | approve, reject, fixed or undecided | An approve clears the gate with no person asked. |
Result file says what each verdict does.
If the reviewer reports nothing or a value its mode doesn't take, or a reject
with no concerns, Kraft records undecided: the gate waits for a person,
shown as could not decide with the reviewer's note.
auto_review_attempts in policy.yaml
(default 1) bounds how many attempts one pending gate gets.
A reviewer that checks first
Added in 2.5
A checks_first reviewer's verdict never clears the gate, whatever it writes.
The item page, the phone and the review page show its outcome, ready for
you or could not decide, with its note, beside the gate you decide.
A pass ends automated review of that gate until it is asked for again,
whatever auto_review_attempts allows. The gate's next request, after a
reject and a re-run, starts afresh and so does kraft item retry on the item
waiting at the gate, which asks for the gate again. Pausing doesn't: an item
waiting at a gate can't be paused.
The reviewer must not change the work. Kraft reads the checkout before the
review and again after, and the gate's document too, which is kept outside the
checkout. If anything changed, Kraft ignores the verdict, a reject included,
and records undecided with a note naming the changed files: the first 20,
then how many more. In an item's own worktree the changes stay there: look
at them before you approve. The gate waits for you; the item doesn't stop.
If Kraft can't read the checkout before the review, the verdict doesn't count either: for an item in its own worktree, no reviewer starts at all.
On an in-place item the reviewer never works in your checkout. It still holds the checkout, so it waits while another item uses it, but it reads a throwaway copy of what is committed on the item's branch, and Kraft removes the copy after. Your checkout isn't switched and your uncommitted edits aren't touched, nor seen: they aren't in the copy.
A change the reviewer makes in the copy voids its verdict, and the note says the copy is gone. If the copy can't be made, for example because the item's branch was deleted, no reviewer starts and the gate is could not decide.
The check counts more than the reviewer's own edits:
- in an item's own worktree, files a test run of the reviewer's leaves behind, untracked and not gitignored, count as edits and void its verdict.
- on an in-place item, a commit anyone makes on the item's branch during the review counts too: the branch's tip is compared as well as the copy.
The check misses:
- an edit made across a server restart mid-review: the reading from before the review is held in memory, and is lost.
- on another machine, commits the
server refuses to publish (the branch moved, or its worktree has uncommitted
changes): they are kept under
refs/kraft/unsynced/with asandbox_branch_not_syncedevent, and not compared. A remote review whose commits are published is checked like a local one. - on another machine, a sandboxed review whose checkout holds git repositories Kraft didn't create: Kraft skips its commit sweep there, so its uncommitted edits are lost instead of flagged.
- for an item in its own worktree, an edit to the repository's own checkout: the reviewer is told where it is and may read it, but only the item's worktree and the gate's document are compared.
- on an in-place item, an uncommitted edit made in your checkout itself, not in the copy: only the copy, the branch's tip and the gate's document are compared.
Check it worked
- Lint the files, make the server read them, and print the chain with the
library expanded:
kraft admin templates lint kraft admin reload kraft admin templates show reviewed --resolved
A pass prints these lines (the counts are your own):3 chain(s), no errors reloaded 3 template(s) and policy.yaml and intake.yaml
The first line islint's, the secondreload's. In theshowoutput, look forsecurity_reviewunderverification, andauto_reviewon the gate. - File an item on the chain:
kraft item create "title" --chain reviewed - When the item has passed the tests in
verification, list the findings, and when it reaches the reviewed gate, list the reviewer's start:kraft view events ID --type findings_measured kraft view events ID --type gate_auto_review_started
A security finding shows infindings_measuredlike any review finding. A gate review that ran shows onegate_auto_review_startedrow. Agate_auto_review_skippedrow means the reviewer left the gate to a person.
Change how review-bot feedback is triaged
Added in 2.4
The shipped chain's merge_request_feedback node ends its review wait with a triage step, review_feedback.triage. A cheap agent reads what the review bots said and reports only the comments that need a change; the rest it declines, with a reason the person at final_review can read. Swap the skill it follows with one override in a chain that extends default. In chains/reviewed.yaml it goes under the same overrides: as the others:
overrides:
# verification and the gates: as above
merge_request_feedback.review_feedback.triage:
skill: superpowers:receiving-code-review
- The task stops if the worker can't load the skill, and waits for you.
superpowers:receiving-code-reviewneeds thesuperpowersplugin installed for the agent that runs the task, and was written for a session with a person in it. The shippedkraft:review-feedbackis written for a run with nobody to ask.- The triage never replies to, resolves or edits a thread on the merge request, whichever skill it follows.
Next steps
- Chain file keys: every key a gate takes,
auto_reviewincluded. - Filing a work item: which items have auto-gate on, and how to turn it off.
- Events: the events a gate review records.
- Write your own chain: add a node of your own to the same chain.