Skip to Content
harness-kit

stop-command

The built-in Policy stop-command, against a turn that ends with failing lint, unsaved work or an incomplete hand-off: its defaults, its options and a configuration that writes it.

To learn what it guards against and see it at work, read the guide: Stop checks and hand-off.

Defaults

DefaultValue
On by defaultno: an entry turns it on
Fail modeclosed
Timeout300000 ms
Eventsset by its options
Toolsevery tool, or as its options set
Agent typesevery agent, or as its options set

Options

OptionTypeDefaultDescription
diffBase("session-start" | object | object)[]—The ways to find the diff base, the first found winning: session-start (the commit HEAD was on when the session began), { mergeBase } or { ref }; ['session-start'] when absent.
envSetupstring—Shell text run before the command in the same shell, such as source "$NVM_DIR/nvm.sh" && nvm use.
fallbackRunstring—The command to run on the whole tree when no diff base is found; without it the changes since HEAD are judged.
outputobject—How the output is shortened for the agent: maxLines (120), maxLineChars (300) and dedupe (none, or tsc to show each TypeScript error once).
requireobject—A file the command needs, relative to the folder; while it is missing the stop blocks with hint.
retryOnExitinteger[]—Exit codes after which the command runs once more, such as 130 and 143 for an interruption.
runstringrequiredThe command, run by bash in the folder the Policy works in; {diff_base} stands for the diff base commit.
whenChangedstring[]—Globs, relative to that folder, of the changed files (committed since the diff base, uncommitted or untracked) that make it run; any change when absent.

Example

A configuration that writes every option, a comment above each:

import { defineConfig } from '@microeinhundert/harness-kit';

export default defineConfig({
  // The Policy entries, in the order their Decisions merge in.
  policies: [
    {
      // The Policy's name, unique in the configuration; messages and logs name the Policy by it.
      id: 'stop-command',
      // The constructor's options, which it decodes.
      options: {
        // The ways to find the diff base, the first found winning: `session-start` (the commit
        // `HEAD` was on when the session began), `{ mergeBase }` or `{ ref }`; `['session-start']`
        // when absent.
        diffBase: ['session-start'],
        // Shell text run before the command in the same shell, such as
        // `source "$NVM_DIR/nvm.sh" && nvm use`.
        envSetup: 'source "$NVM_DIR/nvm.sh" && nvm use',
        // The command to run on the whole tree when no diff base is found; without it the changes
        // since `HEAD` are judged.
        fallbackRun: 'npm run typecheck',
        // How the output is shortened for the agent: `maxLines` (120), `maxLineChars` (300) and
        // `dedupe` (`none`, or `tsc` to show each TypeScript error once).
        output: {
          // How repeated lines are folded: `none` keeps them, `tsc` shows each TypeScript error
          // once; `none` when absent.
          dedupe: 'none',
          // The most characters of a line shown before it is cut; 300 when absent.
          maxLineChars: 1,
          // The most lines of output shown; 120 when absent.
          maxLines: 1,
        },
        // A `file` the command needs, relative to the folder; while it is missing the stop blocks
        // with `hint`.
        require: {
          // A file the command needs, relative to the folder the Policy works in.
          file: 'node_modules/.bin/tsc',
          // What the stop tells the agent to do while the file is missing.
          hint: 'Run `npm ci` first.',
        },
        // Exit codes after which the command runs once more, such as 130 and 143 for an
        // interruption.
        retryOnExit: [1],
        // The command, run by `bash` in the folder the Policy works in; `{diff_base}` stands for
        // the diff base commit.
        run: 'npx tsc --noEmit',
        // Globs, relative to that folder, of the changed files (committed since the diff base,
        // uncommitted or untracked) that make it run; any change when absent.
        whenChanged: ['src/**/*.ts'],
      },
      // The name of the kit's Policy constructor that builds the Policy.
      use: 'stop-command',
    },
  ],
});

On this page