Get started
By the end you will have installed Ashlar in a small TypeScript project, run ashlar check, seen a rule fail
with the message an agent reads, and fixed what it found.
Before you begin
Section titled “Before you begin”- Node 22.18 or later. Ashlar loads
ashlar.config.tswith Node's own type stripping, so the config needs no build step. - Git.
- pnpm. npm works too: each step that differs shows both.
Check a project
Section titled “Check a project”-
Make a project.
Terminal window mkdir shopcd shopgit initGive it a
package.json:package.json {"name": "shop","private": true,"type": "module"}"type": "module"lets Node readashlar.config.tsas a module. If a project can't have it, name the configashlar.config.mtsinstead.Then one file of code:
src/total.ts export function total(prices: number[]): number {return prices.reduce((sum, price) => sum + price, 0);} -
Install Ashlar as a dev dependency, from its release.
Terminal window pnpm add -D https://github.com/kurvball/ashlar/releases/download/v1.2.0/kurvball-ashlar-1.2.0.tgzTerminal window npm install -D https://github.com/kurvball/ashlar/releases/download/v1.2.0/kurvball-ashlar-1.2.0.tgz -
Write
ashlar.config.tsat the root of the project.ashlar.config.ts import { defineConfig } from '@kurvball/ashlar';export default defineConfig({include: ['src'],});includenames the folders Ashlar checks. It is the only key a config needs. The config reference lists the others. -
Run the check.
Terminal window $ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.Terminal window $ npx --no-install ashlar checkAshlar checked 1 file in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.The check exits with 0. A project with no baseline holds every rule at zero breaks.
-
Break a rule. Add a comment to
src/total.ts, as an agent might:src/total.ts // Adds up the prices in the cart.export function total(prices: number[]): number {return prices.reduce((sum, price) => sum + price, 0);}Run the check again. With npm, run
npx --no-install ashlar checkwherever this page sayspnpm exec ashlar check.Terminal window $ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: 1 count rose.no-comment in src/total.ts: 1, up from 0src/total.ts:1:1Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.The check exits with 1. It names the rule, the file, its count against the baseline, and where each break is. The last line is the rule's message: what an agent reads, and what it should do instead.
-
Do what the message says. The comment said what the function adds up, so let the name say it:
src/total.ts export function cartTotal(prices: number[]): number {return prices.reduce((sum, price) => sum + price, 0);}Terminal window $ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.
On a repository that already has breaks
Section titled “On a repository that already has breaks”Most code isn't at zero. In a repository with breaks, take a baseline once:
$ pnpm exec ashlar check --shrinkAshlar checked 2 files in 0.1 s and took the baseline: 3 breaks in ashlar.baseline.json.Commit ashlar.baseline.json. From then on, ashlar check fails when a file's count rises above what the
baseline holds for it, and --shrink only ever lowers it. The ratchet explains how, and
Adopt Ashlar in an existing repository walks through it.
Ashlar exits with 0 when all is well, 1 when a check or a drive fails, and 2 when a command or the config is
wrong. Every command but skill takes --json.