Stop checks and hand-off
stop-command, work-saved and the hand-off checks keep the agent working until lint passes, the work is saved and the pull request and issue tell the truth.
Make "done" from an agent mean done: the checks pass, the work is committed and pushed, and the pull request and issue tell the truth. These Policies check that when the agent tries to end its turn, and keep it going with the reason and the fix: block-stop
Three rules every stop check follows
A session that touched nothing is never judged; a stop waits for background agents the session launched; and each check blocks only once for each state of what it objects to, so the agent is never stuck in a loop. Sessions and stop checks explains them.
API reference
The defaults and every option, with its type: stop-command, work-saved, pull-request,
references, status-sync, tracker-fields.
Configure the stop checks
The first two entries need only git; the hand-off checks need a forge, a tracker or both.
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* Two stop checks: lint of the packages the session changed, compared with where its branch left `main`, and the work
* committed and pushed before the agent hands off.
*/
export default defineConfig({
policies: [
{
id: 'lint',
options: {
diffBase: [
'session-start',
{
mergeBase: 'origin/main',
},
],
fallbackRun: 'npm run lint',
require: {
file: 'node_modules/.bin/turbo',
hint: 'npm ci',
},
run: 'npx turbo run lint --filter=...[{diff_base}]',
whenChanged: ['apps/**', 'packages/**'],
},
use: 'stop-command',
},
{
id: 'work-saved',
options: {
require: ['committed', 'pushed'],
},
use: 'work-saved',
},
],
});stop-command
Runs a command, typically lint or tests, scoped to what the session changed, and blocks the stop when it fails. Fails closed, with a 5-minute timeout.
Changed means committed since the base, plus uncommitted, plus untracked. The base is the commit the session started on, which fills in {diff_base}. The full output is kept in the session state and named in the message:
`npx turbo run lint --filter=...[37d0beebec6a60cf0cf78736eae0c50d88b3a2d6]` failed (exit 1). Fix these issues:
src/a.ts(1,1): error TS2322: Type 'string' is not assignable to type 'number'.
The full output is in /work/repository/.git/harness-kit/session-1/stop-output/lint.log.
Fix: Fix these issues, then end the turn again; `npx turbo run lint --filter=...[37d0beebec6a60cf0cf78736eae0c50d88b3a2d6]` in /work/repository checks them.API reference
stop-command, with its type and default.Turn it off by removing the entry. A command that cannot run blocks the stop, since the check fails closed.
work-saved
Blocks a stop while a branch the session touched has uncommitted changes or commits no remote has. Fails open. Deploy branches of the repository's project are left alone.
`feat/abc-1-docs` in /work/repository holds work that is only on this machine: 2 changed file(s) not committed.
Fix: Commit the 2 changed file(s) in /work/repository: the subject says what the commit does; leave out files that are not this session's work.
Push: git push -u origin HEAD
Commit and push without asking; if the work rightly stays local, say why in your hand-off.API reference
work-saved, with its type and default.Turn it off by removing the entry.
Hand-off checks
Four more checks look at what a turn hands off to people. They need a forge, a tracker or both, and each fails open within 30 seconds (references: 10). The GitHub and Jira pages show them with their trackers.
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* The hand-off checks on GitHub: every pushed work branch has a pull request whose body starts with its issue's URL,
* the final reply links what it names, the issue's status follows its pull request (a branch `feat/12-docs` names
* issue 12), and an issue in progress has an owner and a description once a command wrote to it.
*/
export default defineConfig({
adapters: {
forge: {
options: {
repository: 'acme/web',
},
use: 'github',
},
tracker: {
options: {
repository: 'acme/web',
statuses: [
{
category: 'in_progress',
labels: ['in progress'],
name: 'In Progress',
state: 'open',
},
],
},
use: 'github',
},
},
policies: [
{
id: 'pull-request',
options: {
currency: false,
},
use: 'pull-request',
},
{
id: 'references',
use: 'references',
},
{
id: 'status-sync',
options: {
branchKey: '^[^/]+/([0-9]+)',
roles: [
{
role: 'in_flight',
status: 'In Progress',
},
{
role: 'first_review',
status: 'In Review',
},
],
},
use: 'status-sync',
},
{
id: 'tracker-fields',
options: {
defaults: {
estimate: false,
sprint: false,
},
},
use: 'tracker-fields',
},
],
});Like every refusal, each ends with a Fix: line. The messages below are what the agent reads from this configuration on GitHub, where a branch like feat/12-docs names issue 12 and an issue is in progress when it carries the label in progress.
pull-request
Runs at a stop, and after gh pr create or gh pr edit. It wants three things, each its own section that you turn off with false:
exists: every pushed work branch has a pull request;currency: an open one carries the branch's commits, has a body edited after its last commit and no unanswered review thread, and is out of draft once marked finished;body: its body starts with the issue's URL.
A pushed branch without a pull request:
No pull request carries the commits of feat/12-docs.
Fix: Push it and open a draft pull request against main:
git push -u origin HEAD
gh pr create --draft --base main --title "<the issue’s title>" --body-file <file>
If the work rightly stays without a pull request, say why in your hand-off and end the turn again.Turn it off by removing the entry, or one section with false.
references, status-sync and tracker-fields
| Check | When it runs | What it wants |
|---|---|---|
references | at a stop | the final reply links every issue key, #123, owner/repo#123 and "PR 123" it names, instead of naming them bare |
status-sync | at a stop | each issue's status matches its pull request's stage, by roles you map to your workflow's statuses |
tracker-fields | after a call that wrote to the tracker | an issue in progress has an owner, a description, an estimate and a sprint, as each project requires |
references objects when the final reply names an issue or a pull request without its link:
Bare reference: #32, PR 12.
Fix: Restate each with its link, the reference alone as the link's text and not a title, such as [#32](https://github.com/<owner>/<repo>/pull/32), and end the turn again.status-sync objects when an issue lags behind the pull request its branch pushed, and names the transition that fixes it:
Pull request #7 is open and ready for review, and 12 still reads `Open`; it belongs in the first_review role, `In Review`.
Fix: harness-kit tracker transition 12 "In Review"
If an issue rightly stays where it is, say why in your hand-off and end the turn again.tracker-fields objects right after a command wrote to an issue that is in progress but incomplete, here with estimate and sprint switched off since GitHub has neither:
The write landed, but the tracker is not true yet: these issues are in progress and incomplete.
Fix: 12: no owner → assign 12 to the person who works on it
12: no description → write what 12 is about into its description
Fill them in, or move the issue back off the board.Turn one off by removing its entry.
Let one stop through
A check blocks a stop by its fail mode when it cannot run its command, or git cannot read the folder: stop-command closed, the others open. To let one stop through for a session, the person starts Claude Code with the entry's override variable.
Related
- Sessions and stop checks: Touches and the once-per-state rule.
- Troubleshooting: the common messages and how to clear them.