Skip to content

Add a rule from a correction

At the end of this guide, Ashlar has a new rule: its case is a test, ledger.json says what it corrected, and its message tells the agent what to do instead.

A rule exists because a person corrected an agent's work and didn't want to correct it again. A rule with no correction behind it isn't taken. The example below is max-lines, as it went in.

  1. Write the correction down. Open a "Rule from a correction" issue on Ashlar's repository. It asks for:

    • what the agent did wrong, with counts when there are some, such as "19 files over 1,000 lines";
    • the case: the file, from the repository's root, and the smallest piece of code that shows it;
    • what the rule should say instead, as the agent will read it;
    • the prose it replaces: a line in AGENTS.md, CLAUDE.md, a skill or a review comment that people keep writing, or none;
    • where it applies: everywhere, or which kind of folder.

    Leave out anything private: the case becomes a test in Ashlar's source.

  2. Get the developer's yes. Ashlar's DECISIONS.md holds the rule for rules:

    - 2026-11-16 @daguenette [src/plugin, ledger.json] Every rule comes from a correction, names its replacement, ships with its case as a test, and needs the developer's yes.

    Every project that uses Ashlar runs every rule its config doesn't turn off, so no rule goes in on an agent's word alone.

  3. Write the case as a test, before the rule. Name the test after what went wrong, and put it in the rule's test file in src/plugin/:

    testRule('max-lines', maxLines, app, {
    valid: [{ name: 'a file of 600 lines', file: 'desktop/src/services/cards/short.ts', code: lines(600) }],
    invalid: [
    {
    name: 'WaitCard grew to 2,265 lines: one line over is already too long',
    file: 'desktop/src/renderer/shell/WaitCard.tsx',
    code: lines(601),
    },
    ],
    });

    invalid holds the case: the rule fires on it, with its message. valid holds what the rule must leave alone.

  4. Write the rule in src/plugin/. Add its name to LINT_RULES and its message to MESSAGES in src/plugin/messages.ts, and the rule to rules in src/plugin/index.ts. If it applies only in some places, say where in APPLIES in src/onboard/applies.ts, so a brief and the onboarding guide name it only there.

    A rule reports each break through found, which prints the message from the project's messages when the config gives one.

  5. Write the message. It tells the agent what to do instead, in one or two sentences:

    A file over 600 lines costs every agent that reads it. Split it along what it does.

    Say what to do, not only what not to do. A project can replace it with its own words through messages in its config, so name no project's own hooks or folders.

  6. Add its entry to ledger.json, in the same order as LINT_RULES:

    {
    "id": "max-lines",
    "rule": true,
    "says": "No file over its line limit",
    "applies": "all code",
    "corrected": "19 files over 1,000 lines, sessions/adapter.ts at 2,382 and WaitCard.tsx at 2,265",
    "by": "developer",
    "replaces": null,
    "case": {
    "file": "src/plugin/text.test.ts",
    "test": "WaitCard grew to 2,265 lines: one line over is already too long"
    },
    "message": "A file over 600 lines costs every agent that reads it. Split it along what it does."
    }
    Field Type What it holds
    id string The rule's name, as rules and messages in a config name it.
    rule boolean true for a rule ashlar check counts; false for a check the import graph makes, such as affected.
    says string What the rule says, in one sentence with no full stop.
    applies string Where it applies, read after "in": all code, features, shared/.
    corrected string What the correction was, with its counts, with no full stop.
    by developer, lead or gate Who made the correction.
    replaces string or null The prose the rule replaces, word for word, or null.
    case.file string The test file that holds the case, from Ashlar's root.
    case.test string The case's test name, exactly as the test says it.
    message string The message agents read under the default config.

    Tests check that the entries follow the rules' order, that each case is a test that is there to run, and that each message is the one the rule prints.

  7. Read the entry as an agent would:

    Terminal window
    $ node src/cli.ts ledger
    max-lines: No file over its line limit, in all code.
    It corrected: 19 files over 1,000 lines, sessions/adapter.ts at 2,382 and WaitCard.tsx at 2,265.
    Its case: src/plugin/text.test.ts, “WaitCard grew to 2,265 lines: one line over is already too long”.
    A file over 600 lines costs every agent that reads it. Split it along what it does.

    An entry that replaced prose says so on a line of its own:

    Terminal window
    $ node src/cli.ts ledger
    affected: A builder and the item gate run the tests the import graph says a change reaches, in every change.
    It corrected: Decisions 161 and 163: builders ran whole suites, eleven of them spending 394 of their 439 minutes of commands in test runs, and their prompts then told them in prose to pick the tests that cover their change.
    Its case: src/affected.test.ts, “lists every test that reaches a changed file through the graph”.
    It replaced: “Run only the test files you wrote or changed, each named by its path, never the whole test suite or a whole package's tests.”
    A builder and the item gate run the tests the import graph says a change reaches.

    In a project, pnpm exec ashlar ledger prints the same entries, with the messages the project's config gives.

Ashlar's rules hold for every project. A correction that belongs to one project goes in that project:

  • A name only some folders may say, such as a provider's: a confined entry in the config, with its message. See Config.
  • Better words for a rule, naming your own hooks: messages in the config.
  • A rule no check can hold: a line in DECISIONS.md or a folder rule in .claude/rules/, which every brief for that folder carries. See Answer questions and record decisions.

When a rule is wrong for a case, change the rule and record why in the ledger. No comment in code turns a rule off, and a project turns one off for all its code with rules in its config.