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.
To learn what it guards against and see it at work, read the guide: Paths and new files.
Defaults
| Default | Value |
|---|---|
| On by default | no: an entry turns it on |
| Fail mode | open |
| Timeout | 5000 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 |
|---|---|---|---|
exemptTrackedByGit | boolean | true | Whether a file whose name git already knows (tracked, untracked or in the history of any branch) is exempt as moved or restored rather than new. |
glob | string | required | The new files it checks, relative to the folder the Policy works in, such as db/migrate/*.rb. |
hint | string | — | The step that clears a refusal, in place of the kit's own. |
nameRegex | string | required | The pattern a checked file's name carries its timestamp by, in its first capture group, such as ^(\d{14})_; a name it does not match is not checked. |
timestampWithinMinutes | integer | 15 | How far from the current UTC time the timestamp may lie, either side, in minutes. |
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: 'new-file',
// The constructor's options, which it decodes.
options: {
// Whether a file whose name git already knows (tracked, untracked or in the history of any
// branch) is exempt as moved or restored rather than new.
exemptTrackedByGit: true,
// The new files it checks, relative to the folder the Policy works in, such as
// `db/migrate/*.rb`.
glob: 'db/migrate/*.rb',
// The step that clears a refusal, in place of the kit's own.
hint: 'Name the migration with the current UTC time, such as 20261130140500_add_orders.rb.',
// The pattern a checked file's name carries its timestamp by, in its first capture group,
// such as `^(\d{14})_`; a name it does not match is not checked.
nameRegex: '^(\\d{14})_',
// How far from the current UTC time the timestamp may lie, either side, in minutes.
timestampWithinMinutes: 15,
},
// The name of the kit's Policy constructor that builds the Policy.
use: 'new-file',
},
],
});allowed-paths
The built-in Policy allowed-paths, against writes to files that must not be edited, or outside where they belong: its defaults, its options and a configuration that writes it.
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.