Skip to content

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.

  • Node 22.18 or later. Ashlar loads ashlar.config.ts with Node's own type stripping, so the config needs no build step.
  • Git.
  • pnpm. npm works too: each step that differs shows both.
  1. Make a project.

    Terminal window
    mkdir shop
    cd shop
    git init

    Give it a package.json:

    package.json
    {
    "name": "shop",
    "private": true,
    "type": "module"
    }

    "type": "module" lets Node read ashlar.config.ts as a module. If a project can't have it, name the config ashlar.config.mts instead.

    Then one file of code:

    src/total.ts
    export function total(prices: number[]): number {
    return prices.reduce((sum, price) => sum + price, 0);
    }
  2. 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.tgz
  3. Write ashlar.config.ts at the root of the project.

    ashlar.config.ts
    import { defineConfig } from '@kurvball/ashlar';
    export default defineConfig({
    include: ['src'],
    });

    include names the folders Ashlar checks. It is the only key a config needs. The config reference lists the others.

  4. Run the check.

    Terminal window
    $ pnpm exec ashlar check
    Ashlar 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.

  5. 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 check wherever this page says pnpm exec ashlar check.

    Terminal window
    $ pnpm exec ashlar check
    Ashlar checked 1 file in 0.1 s: 1 count rose.
    no-comment in src/total.ts: 1, up from 0
    src/total.ts:1:1
    Comments 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.

  6. 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 check
    Ashlar checked 1 file in 0.1 s: no count rose.
    There is no baseline, so every count must stay at zero.

Most code isn't at zero. In a repository with breaks, take a baseline once:

Terminal window
$ pnpm exec ashlar check --shrink
Ashlar 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.