Adopt Ashlar in an existing repository
At the end of this guide, ashlar check runs in CI and fails only when a file gets worse than it is today.
The examples come from a small repository: a Tauri desktop app in apps/desktop, an API in apps/api, and a
package in packages/money. The outputs are what Ashlar printed there.
-
Install Ashlar as a dev dependency. Ashlar is not on npm: each release attaches its packed tarball,
kurvball-ashlar-<version>.tgz, and you install it by its address:Terminal window pnpm add -D https://github.com/kurvball/ashlar/releases/download/v1.2.0/kurvball-ashlar-1.2.0.tgzWith npm,
npm install -Dand the same address. Your lockfile records the address and the tarball's checksum, so CI installs the same file with no token and nothing kept in your repository. To upgrade, install the newer release's address.To run a change that isn't released yet, build the tarball from Ashlar's repository instead (
git clone https://github.com/kurvball/ashlar.git, thenpnpm installandpnpm packthere), copy it into your repository, for example asvendor/kurvball-ashlar-<version>.tgz, commit it, and install it from there:pnpm add -D ./vendor/kurvball-ashlar-<version>.tgz. Installing from../ashlar/instead would leave a path in your lockfile that CI doesn't have.Ashlar needs Node 22.18 or later, and Git. Run it with
pnpm exec ashlar,yarn ashlarornpx --no-install ashlar. Never run a barenpx ashlar: a package namedashlaron npm is someone else's, andnpxwould download and run it. Check which version you have:Terminal window $ pnpm exec ashlar --version1.2.0 -
Write
ashlar.config.tsat the root.no-comment,no-disableandmax-lineshold in every file underinclude; every other rule needs to know where an app's parts are, so it applies only inside an app named inapps. Name one app for each app in the repository:import { defineConfig } from '@kurvball/ashlar';export default defineConfig({include: ['apps', 'packages'],apps: [{ root: 'apps/desktop', stack: 'tauri' },{ root: 'apps/api', stack: 'web', main: ['src'], renderer: [], shared: [], areas: ['src/*'] },],});includenames the folders Ashlar checks. Each app names its stack,electron,tauriorweb, and the stack says where its sides live: for Tauri, the screens insrc/, the host insrc-tauri/, features insrc/features/*. The API has no screens, so it has no renderer, and each folder in itssrc/is an area. Config lists every key and its default.A library or a CLI has no screens either: give it one
webapp whose main side is its source folder, with no renderer, and make each folder of it an area:export default defineConfig({include: ['src'],apps: [{ root: 'src', stack: 'web', main: ['.'], renderer: [], areas: ['*'] }],});areasmatters here. A stack's default areas sit in its usual main folder (server/*forweb), which a repository whose main side is its root doesn't have, and an app with no area has nothing forpublic-api-onlyto count. Ashlar says so rather than count zero:Terminal window $ pnpm exec ashlar checkAshlar checked 3 files in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.Warning: apps[0] (src): none of its 3 main-side files is in a service area, so public-api-only counts nothing there. Its areas, `src/server/*`, match none of them. Name them in `areas`, such as `areas: ['*']` for each folder of the app's root, or give `areas: []` to say it has none.With
areas: ['*'], the same files show what the warning hid:Terminal window $ pnpm exec ashlar checkAshlar checked 3 files in 0.1 s: 2 counts rose.public-api-only in src/cli.ts: 1, up from 0src/cli.ts:1:21Import another feature or area through its `index.ts`. If you need something inside it, it belongs in its index or in `shared/`.public-api-only in src/run/run.ts: 1, up from 0src/run/run.ts:1:22Import another feature or area through its `index.ts`. If you need something inside it, it belongs in its index or in `shared/`.A web client that calls its server with
fetch: namefetchas the app's bridge, andclient-onlycounts everyfetchoutsideclient/, as it counts Electron's or Tauri's packages. Without it, Ashlar doesn't knowfetchreaches the other side:{ root: 'apps/web', stack: 'web', bridge: { global: 'fetch' } } -
Run the check once, to see what is there:
Terminal window $ pnpm exec ashlar checkAshlar checked 9 files in 0.2 s: 6 counts rose.no-comment in apps/api/src/orders/index.ts: 1, up from 0apps/api/src/orders/index.ts:3: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.no-effect in apps/desktop/src/features/cart/Cart.tsx: 1, up from 0apps/desktop/src/features/cart/Cart.tsx:6:3`useEffect` belongs to `client/` and `primitives/`. A feature that needs one needs a hook in `primitives/`, named for what it does, instead.no-timer in apps/desktop/src/features/cart/Cart.tsx: 1, up from 0apps/desktop/src/features/cart/Cart.tsx:8:19A timer patches over a render you don't control. Use a hook from `primitives/`, named for what it waits on.feature-reach in apps/desktop/src/features/cart/reach.ts: 1, up from 0apps/desktop/src/features/cart/reach.ts:1:1Every feature folder holds a reach script, `reach.ts`: the developer's way to the feature as drive steps, ending on a snapshot of what it reaches. It is plain data that imports only types. Write one, then run it with `ashlar drive <feature>`.feature-reach in apps/desktop/src/features/search/reach.ts: 1, up from 0apps/desktop/src/features/search/reach.ts:1:1Every feature folder holds a reach script, `reach.ts`: the developer's way to the feature as drive steps, ending on a snapshot of what it reaches. It is plain data that imports only types. Write one, then run it with `ashlar drive <feature>`.no-comment in packages/money/src/total.ts: 1, up from 0packages/money/src/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.It exits with 1. With no baseline, every count must stay at zero, and an existing repository has breaks. If a break is in the wrong place, the layout is wrong: fix the app's folders in the config and run it again.
Two words: a count is one rule's number in one file, and breaks are what it counts. "6 counts rose" means six pairs of a file and a rule went up; the baseline below holds 6 breaks in all. Most rules count each place they fire, so a file with three comments holds 3
no-commentbreaks;max-linescounts the lines a file has over the limit, so a file of 724 lines holds 124. -
Take the baseline:
Terminal window $ pnpm exec ashlar check --shrinkAshlar checked 9 files in 0.2 s and took the baseline: 6 breaks in ashlar.baseline.json.The baseline holds each file's count for each rule:
{"feature-reach": {"apps/desktop/src/features/cart/reach.ts": 1,"apps/desktop/src/features/search/reach.ts": 1},"no-comment": {"apps/api/src/orders/index.ts": 1,"packages/money/src/total.ts": 1},"no-effect": {"apps/desktop/src/features/cart/Cart.tsx": 1},"no-timer": {"apps/desktop/src/features/cart/Cart.tsx": 1}}Commit
ashlar.baseline.json. From now on,checkpasses while no file's count rises above it:Terminal window $ pnpm exec ashlar checkAshlar checked 9 files in 0.1 s: no count rose. -
Run the check in CI. Give it a script in
package.json:{"scripts": {"check": "ashlar check"}}Then run
pnpm checkin your CI job. On GitHub Actions:steps:- uses: actions/checkout@v4with:fetch-depth: 0- uses: pnpm/action-setup@v4- uses: actions/setup-node@v4with:node-version: 22cache: pnpm- run: pnpm install --frozen-lockfile- run: pnpm checkAshlar compares with your main branch to tell which lines a change wrote: of
main,origin/main,masterandorigin/master, it takes the one whose merge base withHEADis closest. A pull request's checkout has no localmain, so it usesorigin/main, whichfetch-depth: 0fetches. A comment on a written line fails even when another comment in the file went, so the count stayed the same. Editing a line that holds a comment writes it too: fixing a path inside an old comment counts as a new comment. A comment can't be kept current, only replaced by a name or a test.Terminal window $ pnpm checkAshlar checked 12 files in 0.2 s: 1 count rose.no-comment in apps/api/src/sales/index.ts: 1 new one on lines changed since main. None may be added, even where others went.apps/api/src/sales/index.ts:4:3Comments 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.A change that adds a break fails the same way, with the message the agent reads:
Terminal window $ pnpm checkAshlar checked 9 files in 0.2 s: 1 count rose.no-comment in apps/api/src/db/index.ts: 1, up from 0apps/api/src/db/index.ts:2:3Comments 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. -
Lower the baseline as breaks go. When a fix takes a count down, as a reach script for the cart feature does here,
checksays so:Terminal window $ pnpm checkAshlar checked 10 files in 0.2 s: no count rose.1 break in the baseline is gone: `ashlar check --shrink` lowers it.Terminal window $ pnpm check --shrinkAshlar checked 10 files in 0.2 s: no count rose.The baseline now holds 5 breaks.--shrinkonly ever lowers a count. Commit the baseline with the fix.When the layout grows later, a wider
include, a new app or new areas, new counts appear that--shrinkwon't take in. Take them in on purpose withashlar check --accept-rise, which says what it took, or deleteashlar.baseline.jsonand take it again with--shrink. -
Turn a rule off, if it is wrong for the whole project. No comment in code can turn a rule off, so it goes in the config:
import { defineConfig } from '@kurvball/ashlar';export default defineConfig({include: ['apps', 'packages'],apps: [{ root: 'apps/desktop', stack: 'tauri' },{ root: 'apps/api', stack: 'web', main: ['src'], renderer: [], shared: [], areas: ['src/*'] },],rules: { 'no-timer': 'off' },});Terminal window $ pnpm checkAshlar checked 9 files in 0.2 s: no count rose.1 break in the baseline is gone: `ashlar check --shrink` lowers it.The rule's counts in the baseline are now gone, and
pnpm check --shrinktakes them out. -
Replace a rule's message with your own words, such as the name of your own hook:
import { defineConfig } from '@kurvball/ashlar';export default defineConfig({include: ['apps', 'packages'],apps: [{ root: 'apps/desktop', stack: 'tauri' },{ root: 'apps/api', stack: 'web', main: ['src'], renderer: [], shared: [], areas: ['src/*'] },],messages: {'no-timer':'A timer patches over a render you don’t control. Wait with `useDebounced` from `primitives/`.',},});Terminal window $ pnpm checkAshlar checked 9 files in 0.2 s: 1 count rose.no-timer in apps/desktop/src/features/search/Search.tsx: 1, up from 0apps/desktop/src/features/search/Search.tsx:4:36A timer patches over a render you don’t control. Wait with `useDebounced` from `primitives/`.The same words reach
ashlar ledger,ashlar briefand the onboarding guide. -
Write the onboarding guide, and keep it current.
ashlar onboardwrites it intodocs/onboarding/(or whereonboard.outsays): what the system is, each area, its decisions and rules, and the questions only a person can answer.ashlar onboard --checkfails when it is out of date, so run it with the check:{"scripts": {"check": "ashlar check && ashlar onboard --check"}}The guide is generated, so leave it as Ashlar writes it:
-
Keep formatters off it. Prettier would rewrite its Markdown, and
--checkwould call it stale. Add the folder to.prettierignore:docs/onboarding/ -
Run
ashlar onboardagain after a change it describes, and commit the result. The guide lists yourpackage.jsonscripts, your areas,DECISIONS.mdand.claude/rules/, so changing a script makes--checkfail until it is written again.
Onboarding says what the guide holds.
-
Related
Section titled “Related”- The ratchet
- Rules
- Onboarding
- Config
- Write a reach script, for the
feature-reachbreaks the baseline now holds - Move files without losing the ratchet
- Kurvball, a real repository that took its baseline this way