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.
-
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.
-
Get the developer's yes. Ashlar's
DECISIONS.mdholds 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.
-
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),},],});invalidholds the case: the rule fires on it, with its message.validholds what the rule must leave alone. -
Write the rule in
src/plugin/. Add its name toLINT_RULESand its message toMESSAGESinsrc/plugin/messages.ts, and the rule torulesinsrc/plugin/index.ts. If it applies only in some places, say where inAPPLIESinsrc/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'smessageswhen the config gives one. -
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
messagesin its config, so name no project's own hooks or folders. -
Add its entry to
ledger.json, in the same order asLINT_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 idstring The rule's name, as rulesandmessagesin a config name it.ruleboolean truefor a ruleashlar checkcounts;falsefor a check the import graph makes, such asaffected.saysstring What the rule says, in one sentence with no full stop. appliesstring Where it applies, read after "in": all code,features,shared/.correctedstring What the correction was, with its counts, with no full stop. bydeveloper,leadorgateWho made the correction. replacesstring or nullThe prose the rule replaces, word for word, or null.case.filestring The test file that holds the case, from Ashlar's root. case.teststring The case's test name, exactly as the test says it. messagestring 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
messageis the one the rule prints. -
Read the entry as an agent would:
Terminal window $ node src/cli.ts ledgermax-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 ledgeraffected: 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 ledgerprints the same entries, with the messages the project's config gives.
In your own project
Section titled “In your own project”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
confinedentry in the config, with its message. See Config. - Better words for a rule, naming your own hooks:
messagesin the config. - A rule no check can hold: a line in
DECISIONS.mdor 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.
Related
Section titled “Related”- Corrections
- Rules
- CLI, for
ashlar ledger - JSON outputs, for
ashlar ledger --json