A complete setup: this repository's own
The configuration harness-kit's own repository runs on, part by part, from session-start checks to a read-only verifier subagent and a docs reminder at the stop.
You'll: see a real configuration in production, the one the repository that builds harness-kit runs every session on, and borrow the parts you need.
Before you start
You need the kit installed and your hooks synced; see Quick start. The configuration is specific to this repository (its checks, its verifier subagent): copy entries, not the whole file.
The configuration
import { defineConfig } from '@microeinhundert/harness-kit';
/**
* What the verifier reads when a command is refused: the commands it may run.
*/
const VERIFIER_COMMANDS = 'The verifier only runs: npm run check|lint|typecheck|test|fmt:check|boundaries, with no option but --filter and --; git status|diff|log|show, without --output; node -v.';
/**
* The files of harness-kit that make up its public surface, relative to the repository root: its published entries,
* its command line and flags, its configuration's Schema, the constructors of its built-in Policies and the Schemas of
* their options, its presets and its protocol, the modules the docs site's reference is generated from
* (`projects/harness-kit/packages/harness-kit/tooling/reference/`). A change to one updates the kit's docs in the same change (AGENTS.md);
* `projects/harness-kit/packages/harness-kit/tests/app/cli.repository-docs.test.ts` fails when the reference reads a file this list misses.
*/
const HARNESS_KIT_PUBLIC_SURFACE = [
'src/app/harness-kit.ts',
'src/app/testing.ts',
'src/app/github-adapter.ts',
'src/app/jira-adapter.ts',
'src/app/cli/*-command.ts',
'src/app/cli/*-flag.ts',
'src/features/config/model/built-in-constructors.ts',
'src/features/config/model/harness-config.ts',
'src/features/*/lib/*-policy-constructor.ts',
'src/features/*/lib/guard-constructors.ts',
'src/features/codegraph/lib/codegraph-constructor.ts',
'src/features/format/lib/format-on-edit-constructor.ts',
'src/features/paths/lib/*-constructor.ts',
'src/features/power/lib/keep-awake-constructor.ts',
'src/features/protection/lib/*-constructor.ts',
'src/features/pull-request/lib/pull-request-constructor.ts',
'src/features/references/lib/references-constructor.ts',
'src/features/rules/lib/rules-constructor.ts',
'src/features/status-sync/lib/status-sync-constructor.ts',
'src/features/stop-command/lib/stop-command-constructor.ts',
'src/features/toolchain/lib/toolchain-constructor.ts',
'src/features/tracker-fields/lib/tracker-fields-constructor.ts',
'src/features/work-saved/lib/work-saved-constructor.ts',
'src/features/workspace/lib/workspace-links-constructor.ts',
'src/features/worktree/lib/worktree-health-constructor.ts',
'src/features/*/model/*-options.ts',
'src/features/*/model/*-operations.ts',
'src/features/hook/model/decide-operation.ts',
'src/features/agents/model/branch-switch.ts',
'src/features/agents/model/readonly-agents.ts',
'src/features/codegraph/model/codegraph-context.ts',
'src/features/command/model/command-presets.ts',
'src/features/command/model/command-table.ts',
'src/features/forge/model/forge-guard.ts',
'src/features/format/model/formatter.ts',
'src/features/git/model/branch-name.ts',
'src/features/git/model/commit-subject.ts',
'src/features/git/model/git-conventions.ts',
'src/features/git/model/merge-method.ts',
'src/features/git/model/push-target.ts',
'src/features/git/model/stash-safety.ts',
'src/features/power/model/keep-awake.ts',
'src/features/work-saved/model/work-saved.ts',
'src/features/workspace/model/workspace-links.ts',
'src/features/worktree/model/worktree-health.ts',
'src/shared/lib/protocol-schema-print.ts',
'src/shared/model/protocol-message.ts',
'src/shared/model/protocol-schema.ts',
].map((file) => {
return `projects/harness-kit/packages/harness-kit/${file}`;
});
/**
* The public surface as git pathspecs, each a glob as `whenChanged` reads it.
*/
const SURFACE_PATHSPECS = HARNESS_KIT_PUBLIC_SURFACE.map((glob) => {
return `':(glob)${glob}'`;
}).join(' ');
/**
* Fails when the kit's docs did not change since the diff base (neither a tracked file of `projects/harness-kit/packages/harness-kit/docs/`
* differs from it nor a new one is there), naming each surface file that changed: the stop check blocks once for each
* state of its output, so a later change to another surface file blocks again.
*/
const HARNESS_KIT_DOCS_CHECK = [
'if git diff --quiet {diff_base} -- projects/harness-kit/packages/harness-kit/docs && [ -z "$(git ls-files --others --exclude-standard -- projects/harness-kit/packages/harness-kit/docs)" ]; then',
'echo "harness-kit\'s public surface changed, but projects/harness-kit/packages/harness-kit/docs did not: update the slice\'s file in projects/harness-kit/packages/harness-kit/docs (and the pages of projects/harness-kit/apps/docs/content/docs that cover it) in the same change, or say in the hand-off why no doc changes. Changed:";',
`{ git diff --name-only {diff_base} -- ${SURFACE_PATHSPECS}; git ls-files --others --exclude-standard -- ${SURFACE_PATHSPECS}; } | sort -u;`,
'exit 1;',
'fi',
].join(' ');
/**
* The repository's Claude Code hooks, which `harness-kit settings sync` writes into `.claude/settings.json`:
*
* - At a session start, the checkout the session works in syncs its CodeGraph index, and is checked for workspace
* packages it would load from another checkout (`@microeinhundert/*` and the kit's own `@microeinhundert/harness-kit`) and,
* in a worktree, for a stale base and a full disk. A subagent started in a worktree, which gets no session start,
* gets the same two checks once, at its first Bash or editing call there.
* - A worktree agent's call of the CodeGraph MCP tool, whose server serves the main checkout, must name the worktree
* as `projectPath`; the worktree gets its own index, built in the background or synced before the call.
* - The `verifier` subagent runs only the repository's checks, read-only git commands and `node -v`, writes no file and
* sets no variable. The project's `PreToolUse` hook screens its calls, as it screens those of every agent, by the
* payload's `agent_type`.
* - At a stop, a session that changed harness-kit's public surface but not its docs is reminded to update them, once
* for each state of the change.
*
* The kit's own `self-protection` and `hook-bypass` Policies run beside them.
*/
export default defineConfig({
policies: [
{
id: 'codegraph',
use: 'codegraph',
},
{
id: 'workspace-links',
use: 'workspace-links',
},
{
id: 'worktree-health',
use: 'worktree-health',
},
{
id: 'verifier-commands',
options: {
agentTypes: ['verifier'],
allow: ['npm run check', 'npm run lint', 'npm run typecheck', 'npm run test', 'npm run fmt:check', 'npm run boundaries', 'git status', 'git diff', 'git log', 'git show', 'node'],
default: 'deny',
denyArgs: ['--output(?:=.*)?'],
denyAssignments: true,
denyWrites: true,
message: VERIFIER_COMMANDS,
},
use: 'command-policy',
},
{
// The allow-list above admits `npm run <check>` by its words, which leave options out: this table refuses every
// option but `--` and turbo's `--filter`, so no argument passed on to a check writes files (`--fix`, `-u`,
// `--graph=…`, `--write`).
id: 'verifier-npm',
options: {
agentTypes: ['verifier'],
denyArgs: ['-(?!-$|-filter(?:=.*)?$).*'],
message: VERIFIER_COMMANDS,
tool: 'npm',
},
use: 'command-policy',
},
{
// The allow-list above admits `node` by its program alone, since `-v` is an option: this table admits no argument
// but the version flag.
id: 'verifier-node',
options: {
agentTypes: ['verifier'],
denyArgs: ['(?!-v$|--version$).*'],
message: VERIFIER_COMMANDS,
tool: 'node',
},
use: 'command-policy',
},
{
id: 'harness-kit-docs',
options: {
diffBase: [
'session-start',
{
mergeBase: 'origin/main',
},
],
run: HARNESS_KIT_DOCS_CHECK,
whenChanged: HARNESS_KIT_PUBLIC_SURFACE,
},
use: 'stop-command',
},
],
});What each part does
| Entries | Event | What it does |
|---|---|---|
codegraph, workspace-links, worktree-health | SessionStart | context syncs the code index, warns about packages linked from another checkout, a stale base or a full disk |
workspace-links, worktree-health | PreToolUse | context the same warnings for a subagent in a worktree, once, at its first Bash or editing call there |
codegraph | PreToolUse | deny keeps a codegraph_explore call from a worktree to that worktree's own index |
verifier-commands, verifier-npm, verifier-node | PreToolUse | deny keeps the verifier subagent to the repository's checks and read-only git |
harness-kit-docs | Stop | block-stop reminds an agent that changed the kit's public surface to update its docs |
self-protection, hook-bypass (no entry) | PreToolUse | deny keep every agent from switching the guardrails off |
Try it
The verifier subagent tries to fix lint instead of reporting it:
`npm run lint -- --fix` is refused: the npm command table denies one of its arguments.
Fix: The verifier only runs: npm run check|lint|typecheck|test|fmt:check|boundaries, with no option but --filter and --; git status|diff|log|show, without --output; node -v.npm run lint on its own passes: allow
If it does not work
- A call is refused that should pass. Run it through
harness-kit explainto see which Policy refused it; see A call is refused that should pass. - The docs reminder blocks the stop again and again. See A stop check blocks again and again.
- Your configuration does not load. See The harness configuration is invalid.
Related
- Commands: allow-lists for subagents.
- Session start:
codegraph,workspace-linksandworktree-health.