Skip to Content
harness-kit

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

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

Options

OptionTypeDefaultDescription
exemptTrackedByGitbooleantrueWhether 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.
globstringrequiredThe new files it checks, relative to the folder the Policy works in, such as db/migrate/*.rb.
hintstring—The step that clears a refusal, in place of the kit's own.
nameRegexstringrequiredThe 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.
timestampWithinMinutesinteger15How 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',
    },
  ],
});

On this page