Gates
Name the checks a repository must pass, run them under a lock so two agents never run the test suite at once, and wait for one inside a tool call.
Name the checks a repository must pass, and run them so that agents sharing a machine never run the full test suite at once. Two full runs at once slow both and can break both.
A gate is a named check: its tests, its lint, a type check. harness-kit runs a gate:
- under a time limit;
- when it must run alone, under a lock per repository;
- leaving a one-line record an agent can wait for.
Gates are not a Policy
gates key, the project catalog, and three commands. There is no entry to add or remove.List a repository's gates
harness-kit gates resolve lists the gates of the repository the session works in. A gate is a command line, or { name, run, exclusive?, timeout? }. A bare command line is named after itself (bin/rspec becomes bin-rspec).
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* Gates for every repository of the team: a project's kind brings `test` and `lint`, and a repository whose
* `package.json` has a `check:translations` script also gets that gate.
*/
export default defineConfig({
gates: {
derived: [
{
gate: {
name: 'translations',
run: 'npm run check:translations',
},
when: {
file: 'package.json',
path: ['scripts', 'check:translations'],
},
},
],
},
policies: [],
projects: {
source: {
catalog: {
groups: {
web: {},
},
kinds: {
app: {
gates: [
{
exclusive: true,
name: 'test',
run: 'npm test',
timeout: 1800,
},
'npm run lint',
],
stack: 'node',
},
},
projects: [
{
group: 'web',
kind: 'app',
name: 'storefront',
},
],
},
},
},
});$ npx harness-kit gates resolve
npm test
npm run lint
npm run check:translationsWith --json it prints { name, run, exclusive, timeout } for each, for a script or an agent to run them. A repository the catalog does not list, or a project without gates, exits with 1, naming why.
Run a gate
Start a gate with gate run. --exclusive takes the repository's lock first, and --timeout is in seconds:
npx harness-kit gate run test --exclusive --timeout 1800 -- npm testThe first line names the run's log and record, before it waits or starts:
harness-kit gate: test · log /tmp/harness-kit-501/gates/runs/test.20261201T100929364.27212.log · record /tmp/harness-kit-501/gates/runs/test.20261201T100929364.27212.exit
harness-kit gate: test started
harness-kit gate: test exited 3
The gate test did not pass: exited 3. Its output is in /tmp/harness-kit-501/gates/runs/test.20261201T100929364.27212.log.The exit code is the command's, 124 after a timeout and 128 plus the signal number when it was killed. When a gate fails, read the log the last line names.
Wait for a gate without blocking a tool call
A tool call should not block for half an hour. Start the gate in the background and wait in steps:
npx harness-kit gate await test.20261201T100929364.27212 --for 540gate await takes a record's path or a run id, as a queued behind line names it, and exits as the run did. Three codes are its own:
| Exit code | Meaning | What to do |
|---|---|---|
| 75 | the run is still going | call gate await again |
| 125 | the run's runner died without a record | read the log and start it again |
| 2 | the run never started | start the gate |
Turn it off
gate run and gate await need no configuration, so there is nothing to remove: do not start them. To drop a gate from the list, delete it from the gates key or the catalog.
Related
- Projects and stacks: the catalog gates come from.
- Command line reference.
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.
Session start
codegraph, workspace-links and worktree-health check the session's own checkout when it starts and tell the agent what to fix.