format-on-edit
The built-in Policy format-on-edit, against edited files left unformatted: its defaults, its options and a configuration that writes it.
To learn what it guards against and see it at work, read the guide: Formatting.
Defaults
| Default | Value |
|---|---|
| On by default | no: an entry turns it on |
| Fail mode | open |
| Timeout | 13000 ms |
| Events | set by its options |
| Tools | every tool, or as its options set |
| Agent types | every agent, or as its options set |
Options
| Option | Type | Default | Description |
|---|---|---|---|
deadlineMillis | integer | — | How long the formatter may run, in milliseconds, before it is stopped (10000 when absent). |
formatters | (object | object)[] | required | The formatters in the order they are tried, each a preset or a command; the first whose glob takes the edited file and whose whenFile the folder holds runs, and no other. |
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: 'format-on-edit',
// The constructor's options, which it decodes.
options: {
// How long the formatter may run, in milliseconds, before it is stopped (10000 when
// absent).
deadlineMillis: 1,
// The formatters in the order they are tried, each a `preset` or a command; the first whose
// glob takes the edited file and whose `whenFile` the folder holds runs, and no other.
formatters: [
{
// The edited files the formatter takes, one glob or several, relative to the folder the
// Policy works in.
glob: 'src/**/*.ts',
// What the note says to do when the formatter's program is not installed; `{install}`
// stands for the project's install command.
missingHint: 'run {install}; a fresh worktree has no node_modules',
// The formatter command, a program and its arguments, with `{file}` for the edited
// file's absolute path; a program with a `/` is a path relative to the folder, any
// other is found on `PATH`.
run: ['npx', 'prettier', '--write', '{file}'],
// A file of the folder the Policy works in, without which the formatter is skipped.
whenFile: '.prettierrc',
// A prefix put before the command where a file is in the folder, such as `bundle exec`
// with a `Gemfile.lock`.
wrapIf: {
// A file whose presence in the folder the Policy works in puts the prefix before the
// command.
file: 'Gemfile.lock',
// The words put before the formatter command, a program and its arguments.
prefix: ['bundle'],
},
},
],
},
// The name of the kit's Policy constructor that builds the Policy.
use: 'format-on-edit',
},
],
});new-file
The built-in Policy new-file, against writes to files that must not be edited, or outside where they belong: its defaults, its options and a configuration that writes it.
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.