Write a reach script
At the end of this guide, a feature folder holds a reach.ts that ashlar map shows and ashlar drive
walks.
The examples come from a Tauri app in apps/desktop, whose features live in apps/desktop/src/features/*.
-
Find the feature folders that have no reach script yet:
Terminal window $ pnpm exec ashlar mapCart apps/desktop/src/features/cartOpen cart › Cart0 proofsSearch apps/desktop/src/features/searchno reach script yet1 proofEvery folder in an app's
featuresis a feature folder, and thefeature-reachrule counts one break in each that has no reach script that reads.ashlar checknames the file to write:Terminal window $ pnpm exec ashlar checkAshlar checked 11 files in 0.2 s: 1 count rose.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>`.It exits with 1 here because the folder is new. If you took the baseline before the features had reach scripts, the baseline holds these breaks and the check passes until you write them.
-
Write
reach.tsin the feature's folder:import type { ReachScript } from '@kurvball/ashlar/reach';export default {name: 'Search',steps: [{ key: 'ControlOrMeta+k' },{ type: 'red shoes' },{ key: 'Enter' },{ snapshot: 'Results', role: 'list' },],} satisfies ReachScript;The default export is the feature's
nameand itssteps, the way a person reaches it from the app's home. It is plain data. Node loads it as it is, so it imports only types: no component, no other module and nothing that runs.The
nameis what the developer and the agents call the feature. No two features may share one, and it is at most 60 characters.Each step is one of four:
Step Does Takes { click: 'Open cart' }Clicks the one element with that accessible name. role, when more than one element has the name{ type: 'red shoes' }Types the text into what has focus. nothing more { key: 'ControlOrMeta+k' }Presses a key. nothing more { snapshot: 'Results' }Reads the element with that name, and fails if nothing on screen has it. role, when more than one element has the nameThe last step is a snapshot of what the reach gets to, so a run proves it got there, and only the last step is one. A script holds at most 40 steps. A name in a
clickor asnapshotis the words on screen, as a snapshot shows them, and at most 120 characters.A
roleis one ofalertdialog,article,button,checkbox,combobox,complementary,dialog,grid,gridcell,group,heading,link,list,listitem,main,menu,menuitem,menuitemcheckbox,menuitemradio,navigation,option,radio,region,row,searchbox,status,switch,tab,tablist,tabpanel,textbox,toolbar,treeortreeitem.A
keyis named as Playwright names it:Enter,Escape,Tab,Backspace,Delete,Space,ArrowUp,ArrowDown,ArrowLeft,ArrowRight,Home,End,PageUp,PageDown,F1toF12, a lower-case letter or a digit, or one of, . / ; ' ` [ ] \ = -. Put modifiers in front, joined by+:ControlOrMeta,Meta,Control,AltandShift.ControlOrMeta+kis ⌘K on a Mac and Ctrl+K elsewhere. -
Read it on the map:
Terminal window $ pnpm exec ashlar mapCart apps/desktop/src/features/cartOpen cart › Cart0 proofsSearch apps/desktop/src/features/searchControlOrMeta+k › “red shoes” › Enter › Results1 proofA proof is a test in the feature's folder.
ashlar map --jsongives each step the drive command it runs:{"says": "Results","run": ["snapshot", "--name", "Results", "--role", "list"]}The
feature-reachbreak for the folder is gone, andashlar check --shrinklowers the baseline. -
Fix a script that doesn't read. Ashlar says which step is wrong and why:
Terminal window $ pnpm exec ashlar mapCart apps/desktop/src/features/cartOpen cart › Cart0 proofsSearch apps/desktop/src/features/searchits reach script doesn’t read: see below1 proofSearch’s reach script doesn’t read. Step 1 presses a key drive doesn't know: name it as Playwright does, such as Meta+k.That script pressed
Cmd+k. A script that doesn't read still counts as afeature-reachbreak. Each refusal says one of these:Refusal What Ashlar says not_a_scriptA reach script's default export is an object: its name and its steps. no_nameGive the reach script the name the developer and the agents say the feature by. long_nameA feature's name is at most 60 characters. no_stepsGive the reach script its steps, ending on a snapshot of what it reaches. too_many_stepsA reach is at most 40 steps. bad_stepStep n isn't a drive step: one of click (with a role, if it helps), type, key or snapshot. bad_keyStep n presses a key drive doesn't know: name it as Playwright does, such as Meta+k. bad_roleStep n names a role drive doesn't know. not_ending_on_snapshotA reach ends on a snapshot of what it reaches, so a run proves it got there. snapshot_midwayStep n is a snapshot: only the last step is. A script that Node can't load, or that takes another feature's name, doesn't read either, and Ashlar says why in the same place.
-
Name your drive command in the config. It is the command that drives your running app:
import { defineConfig } from '@kurvball/ashlar';export default defineConfig({include: ['apps', 'packages'],drive: 'pnpm drive',apps: [{ root: 'apps/desktop', stack: 'tauri' }],});Ashlar runs it from the root, once for each step, with the step's arguments and
--json:Terminal window pnpm drive click --name 'Open cart' --role button --jsonpnpm drive type 'red shoes' --jsonpnpm drive key ControlOrMeta+k --jsonpnpm drive snapshot --name Results --role list --jsonIt runs
stopbefore the first step and after the last, so each walk starts the app afresh. The command answers with one JSON object on its last line of output:{ "ok": true }when the step worked, orok: falsewith afailure(not_found,ambiguous,not_running,timed_outorcrashed) and what itsays. A command that prints no JSON is taken at its exit code. Each step has 60 seconds.A drive command written in TypeScript can read these arguments with
parseDrivefrom@kurvball/ashlar/drive. Without a drive command, a reach script is still data: the map, the brief and the onboarding guide show it, andashlar drivesays the config names none. -
Walk the reach:
Terminal window $ pnpm exec ashlar drive searchSearch: reached in 4 steps.Name the feature by its name or its folder.
--scheme darkasks for the dark colour scheme: Ashlar runs each step withDRIVE_SCHEME=dark.--allwalks every feature:Terminal window $ pnpm exec ashlar drive --allCart: reached in 2 steps.Search: its reach stopped at “Results”, step 4 of 4. Nothing on screen is named “Results”.1 of 2 features reached.It exits with 1 when a reach stops. If the work broke the way in, fix the work. Change the reach script only when the way in itself changed.
--jsonprints each walk as an object:{"version": 1,"feature": "Cart","folder": "apps/desktop/src/features/cart","stoppedAt": 1,"step": "Open cart","ms": 60,"outcome": "stopped","steps": 2,"says": "Nothing on screen is named “Open cart”."}
Related
Section titled “Related”- The feature map
- Agent skills: the verify skill walks the reach of each feature an agent's work changes
- CLI, for
ashlar mapandashlar drive - JSON outputs, for the map's and drive's JSON
- Kurvball, two reach scripts written from a real app's labels