@kurvball/ashlar 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ changesets merged since the release before it, under its version and release dat
6
6
  and patch changes; see [RELEASING.md](RELEASING.md). Versions up to 1.0.1 follow
7
7
  [Keep a Changelog 1.1.0](https://keepachangelog.com/en/1.1.0/).
8
8
 
9
+ ## 1.6.0
10
+
11
+ _Released 2026-12-04._
12
+
13
+ ### Minor Changes
14
+
15
+ - `ashlar init` finds a repository's apps, their features and their areas, writes `ashlar.config.ts` (`.mts` in a package that isn't a module) and takes the baseline, where there is no config yet. `--dry-run` prints the config it would write. `--json` answers in `schema/init.v1.json`, and `ashlar mcp` serves it as the `init` tool.
16
+
17
+ ## 1.5.0
18
+
19
+ _Released 2026-12-04._
20
+
21
+ ### Minor Changes
22
+
23
+ - `ashlar mcp` serves `brief`, `check`, `affected`, `map` and `onboard` as MCP tools on stdio. Each takes its command's options and answers with the object its command prints with `--json`, with the command's v1 schema as its output schema. The Ashlar skill, `skill/ashlar/SKILL.md` in the package and `/SKILL.md` on the docs site, teaches agents to brief before writing and check before pushing, through the server or the commands.
24
+
9
25
  ## 1.4.0
10
26
 
11
27
  _Released 2026-12-04._
package/README.md CHANGED
@@ -58,9 +58,13 @@ Install Ashlar from npm, as a dev dependency:
58
58
 
59
59
  ```sh
60
60
  pnpm add -D @kurvball/ashlar
61
+ pnpm exec ashlar init
61
62
  pnpm exec ashlar check
62
63
  ```
63
64
 
65
+ `ashlar init` finds the repository's apps, their features and their areas, writes `ashlar.config.ts`, and takes
66
+ the baseline.
67
+
64
68
  With npm, `npm install -D @kurvball/ashlar`, then `npx --no-install ashlar check`. Each version is published by
65
69
  Ashlar's release workflow with [provenance](https://docs.npmjs.com/generating-provenance-statements): its npm
66
70
  page names the commit and the workflow run that built it. To try an unreleased change, `pnpm pack` this
@@ -95,6 +99,7 @@ wrong type, gets one line saying which key and what is wrong.
95
99
 
96
100
  | Command | What it does |
97
101
  | ---------------------------- | --------------------------------------------------------------------------------------- |
102
+ | `ashlar init` | Finds the apps, writes `ashlar.config.ts` and takes the baseline. |
98
103
  | `ashlar check` | Fails when a file's count rises above the baseline. `--shrink` lowers it. |
99
104
  | `ashlar affected <files...>` | Lists the tests that reach the files. `--since <ref>` takes a branch's changes. |
100
105
  | `ashlar move <from> <to>` | Moves a file's or a folder's counts in the baseline to its new name. |
@@ -108,6 +113,7 @@ wrong type, gets one line saying which key and what is wrong.
108
113
  | `ashlar skill onboard` | Prints the skill an agent follows to read its brief and keep decisions. |
109
114
  | `ashlar dependents <files>` | Lists what reaches each file, for Rehearse's `rehearse list --affected`. |
110
115
  | `ashlar rehearse` | Prints the blocks of `rehearse.yaml` Ashlar fills: each reach script a flow. |
116
+ | `ashlar mcp` | Serves `init`, `brief`, `check`, `affected`, `map` and `onboard` as MCP tools. |
111
117
 
112
118
  A feature's reach script, `reach.ts` in its folder, lists the steps a person takes to get to it in the running
113
119
  app. `affected` follows imports, stylesheets, setup files and builds. `skill verify --write` writes the skill
@@ -0,0 +1,40 @@
1
+ import { type AffectedReport } from './affected.ts';
2
+ import { type CheckOptions, type CheckReport } from './check.ts';
3
+ import { type Loaded } from './config.ts';
4
+ import { type Feature } from './features.ts';
5
+ import { type Brief } from './onboard/brief.ts';
6
+ import { type OnboardReport } from './onboard/onboard.ts';
7
+ export declare function checkAnswer(config: Loaded, options: CheckOptions): {
8
+ checked: CheckReport;
9
+ warnings: string[];
10
+ json: {
11
+ ok: boolean;
12
+ seconds: number;
13
+ files: number;
14
+ baseline: import("./check.ts").BaselineState;
15
+ rules: import("./check.ts").RuleTotal[];
16
+ rises: import("./check.ts").RiseReport[];
17
+ taken: import("./baseline.ts").Rise[];
18
+ slack: number;
19
+ moves: import("./git.ts").Renamed[];
20
+ version: 1;
21
+ };
22
+ };
23
+ export declare function affectedAnswer(config: Loaded, files: readonly string[], since: string | undefined): {
24
+ report: AffectedReport;
25
+ json: {
26
+ changed: string[];
27
+ deleted: string[];
28
+ tests: string[];
29
+ features: import("./affected.ts").AffectedFeature[];
30
+ unreached: string[];
31
+ seconds: number;
32
+ version: 1;
33
+ };
34
+ };
35
+ export declare function mapAnswer(config: Loaded): {
36
+ features: Feature[];
37
+ json: import("./map.ts").FeatureMap;
38
+ };
39
+ export declare function onboardAnswer(config: Loaded, checkOnly: boolean): OnboardReport;
40
+ export declare function briefAnswer(config: Loaded, files: readonly string[], cwd?: string): Brief;
@@ -0,0 +1,30 @@
1
+ import { affected } from './affected.js';
2
+ import { check } from './check.js';
3
+ import { AshlarError } from './config.js';
4
+ import { buildMap, featuresOf } from './features.js';
5
+ import { brief } from './onboard/brief.js';
6
+ import { onboard } from './onboard/onboard.js';
7
+ export function checkAnswer(config, options) {
8
+ const checked = check(config, options);
9
+ const { warnings, ...report } = checked;
10
+ return { checked, warnings, json: { version: 1, ...report } };
11
+ }
12
+ export function affectedAnswer(config, files, since) {
13
+ if (files.length === 0 && since === undefined) {
14
+ throw new AshlarError('Name the changed files, or give `--since <ref>`.');
15
+ }
16
+ const report = affected(config, { files: [...files], since });
17
+ return { report, json: { version: 1, ...report } };
18
+ }
19
+ export function mapAnswer(config) {
20
+ const features = featuresOf(config);
21
+ return { features, json: buildMap(config, features) };
22
+ }
23
+ export function onboardAnswer(config, checkOnly) {
24
+ return onboard(config, { check: checkOnly });
25
+ }
26
+ export function briefAnswer(config, files, cwd) {
27
+ if (files.length === 0)
28
+ throw new AshlarError('Name the files or folders the agent will change.');
29
+ return brief(config, files, cwd);
30
+ }
package/dist/cli.js CHANGED
@@ -1,18 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { relative } from 'node:path';
4
- import { affected } from './affected.js';
5
- import { check } from './check.js';
4
+ import { affectedAnswer, briefAnswer, checkAnswer, mapAnswer, onboardAnswer } from './answers.js';
6
5
  import { AshlarError, loadConfig } from './config.js';
7
- import { buildMap, featuresOf, unreadText } from './features.js';
6
+ import { init, initText } from './init.js';
7
+ import { serve } from './mcp.js';
8
+ import { featuresOf, unreadText } from './features.js';
8
9
  import { ledgerOf, ledgerText } from './ledger.js';
9
10
  import { mapText } from './map.js';
10
11
  import { move } from './move.js';
11
12
  import { driveFeature, driveOf, featureNamed, isScheme, runsText, SCHEMES } from './reachDrive.js';
12
13
  import { affectedText, checkText, movedText } from './report.js';
13
14
  import { USAGE } from './usage.js';
14
- import { brief, briefText } from './onboard/brief.js';
15
- import { onboard, onboardText } from './onboard/onboard.js';
15
+ import { briefText } from './onboard/brief.js';
16
+ import { onboardText } from './onboard/onboard.js';
16
17
  import { snapshot, snapshotText } from './onboard/snapshot.js';
17
18
  import { dependentsOf, dependentsText } from './rehearse/dependents.js';
18
19
  import { fillText, rehearseFill } from './rehearse/fill.js';
@@ -30,6 +31,8 @@ const FLAGS = {
30
31
  snapshot: ['json'],
31
32
  dependents: ['json'],
32
33
  rehearse: ['json'],
34
+ mcp: [],
35
+ init: ['dry-run', 'json'],
33
36
  };
34
37
  const VALUED = new Map([
35
38
  ['since', 'a ref'],
@@ -90,25 +93,33 @@ async function main(args) {
90
93
  throw new AshlarError(`\`ashlar ${command}\` takes no ${unknown.map((f) => `--${f}`).join(', ')}: it takes ${named}.`);
91
94
  }
92
95
  }
96
+ if (command === 'init') {
97
+ if (positional.length > 0)
98
+ throw new AshlarError('`ashlar init` takes no paths: run it at the root of the repository.');
99
+ const { report, warnings } = init(process.cwd(), { dryRun: flags.has('dry-run') });
100
+ print(json, report, initText(report));
101
+ for (const warning of warnings)
102
+ process.stderr.write(`Warning: ${warning}\n`);
103
+ return 0;
104
+ }
105
+ if (command === 'mcp') {
106
+ if (positional.length > 0)
107
+ throw new AshlarError('`ashlar mcp` takes no files.');
108
+ await serve();
109
+ return 0;
110
+ }
93
111
  const config = await loadConfig();
94
112
  if (command === 'check') {
95
- const checked = check(config, {
96
- shrink: flags.has('shrink'),
97
- acceptRise: flags.has('accept-rise'),
98
- since,
99
- });
100
- const { warnings, ...report } = checked;
101
- print(json, { version: 1, ...report }, checkText(checked, relative(process.cwd(), config.baseline), since));
113
+ const options = { shrink: flags.has('shrink'), acceptRise: flags.has('accept-rise'), since };
114
+ const { checked, warnings, json: answer } = checkAnswer(config, options);
115
+ print(json, answer, checkText(checked, relative(process.cwd(), config.baseline), since));
102
116
  for (const warning of warnings)
103
117
  process.stderr.write(`Warning: ${warning}\n`);
104
- return report.ok ? 0 : 1;
118
+ return answer.ok ? 0 : 1;
105
119
  }
106
120
  if (command === 'affected') {
107
- if (positional.length === 0 && since === undefined) {
108
- throw new AshlarError('Name the changed files, or give `--since <ref>`.');
109
- }
110
- const report = affected(config, { files: positional, since });
111
- print(json, { version: 1, ...report }, affectedText(report));
121
+ const { report, json: answer } = affectedAnswer(config, positional, since);
122
+ print(json, answer, affectedText(report));
112
123
  if (!json && report.unreached.length > 0) {
113
124
  process.stderr.write(`No test reaches ${report.unreached.join(', ')}.\n`);
114
125
  }
@@ -131,22 +142,19 @@ async function main(args) {
131
142
  return 0;
132
143
  }
133
144
  if (command === 'map') {
134
- const features = featuresOf(config);
135
- const map = buildMap(config, features);
145
+ const { features, json: map } = mapAnswer(config);
136
146
  const unreadable = new Set(features.filter((f) => f.reach && !f.reach.ok).map((f) => f.folder));
137
147
  print(json, map, `${mapText(map, unreadable)}${unreadText(features)}`);
138
148
  return 0;
139
149
  }
140
150
  if (command === 'onboard') {
141
151
  const check = flags.has('check');
142
- const report = onboard(config, { check });
152
+ const report = onboardAnswer(config, check);
143
153
  print(json, report, onboardText(report, check));
144
154
  return report.ok ? 0 : 1;
145
155
  }
146
156
  if (command === 'brief') {
147
- if (positional.length === 0)
148
- throw new AshlarError('Name the files or folders the agent will change.');
149
- const said = brief(config, positional);
157
+ const said = briefAnswer(config, positional);
150
158
  print(json, said, briefText(said));
151
159
  return 0;
152
160
  }
package/dist/config.js CHANGED
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import { existsSync, realpathSync } from 'node:fs';
9
+ import { existsSync, realpathSync, statSync } from 'node:fs';
10
10
  import { basename, dirname, join, resolve } from 'node:path';
11
11
  import { pathToFileURL } from 'node:url';
12
12
  import { checkConfig } from './configCheck.js';
@@ -91,7 +91,8 @@ export async function loadConfig(from = process.cwd()) {
91
91
  const file = findConfig(from);
92
92
  if (!file)
93
93
  throw new AshlarError(`There is no ${CONFIG_FILE} in ${resolve(from)} or above it.`);
94
- const loaded = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
94
+ const fresh = `${pathToFileURL(file).href}?v=${statSync(file).mtimeMs}`;
95
+ const loaded = (await import(__rewriteRelativeImportExtension(fresh)));
95
96
  if (!loaded.default)
96
97
  throw new AshlarError(`${file} has no default export: export its config.`);
97
98
  return settle(loaded.default, realpathSync(dirname(file)), basename(file));
package/dist/init.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { type AshlarConfig } from './config.ts';
2
+ import type { AppConfig, Stack } from './layout.ts';
3
+ export interface InitApp {
4
+ root: string;
5
+ stack: Stack;
6
+ features: number;
7
+ why: string;
8
+ }
9
+ export interface InitReport {
10
+ version: 1;
11
+ config: string;
12
+ wrote: boolean;
13
+ include: string[];
14
+ apps: InitApp[];
15
+ owner: string | null;
16
+ baseline: {
17
+ file: string | null;
18
+ breaks: number;
19
+ } | null;
20
+ source: string;
21
+ seconds: number;
22
+ }
23
+ export interface Found {
24
+ include: string[];
25
+ apps: {
26
+ config: AppConfig;
27
+ found: InitApp;
28
+ }[];
29
+ owner: string | null;
30
+ }
31
+ export declare function detect(root: string): Found;
32
+ export declare function configOf(found: Found): AshlarConfig;
33
+ export declare function configSource(config: AshlarConfig): string;
34
+ export declare function init(root: string, options?: {
35
+ dryRun?: boolean;
36
+ }): {
37
+ report: InitReport;
38
+ warnings: string[];
39
+ };
40
+ export declare function initText(report: InitReport): string;
package/dist/init.js ADDED
@@ -0,0 +1,308 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { join, posix, relative } from 'node:path';
4
+ import { check } from './check.js';
5
+ import { AshlarError, CONFIG_FILE, findConfig, settle } from './config.js';
6
+ const SKIPPED = new Set([
7
+ 'node_modules',
8
+ 'dist',
9
+ 'out',
10
+ 'release',
11
+ 'build',
12
+ 'coverage',
13
+ '.git',
14
+ 'target',
15
+ 'vendor',
16
+ ]);
17
+ const BESIDE = new Set(['docs', 'doc', 'examples', 'example', 'fixtures', '__fixtures__']);
18
+ const NOT_APPS = new Set([...BESIDE, 'test', 'tests', '__tests__', 'e2e', 'scripts']);
19
+ const UI_PACKAGES = ['react', 'react-dom', 'vue', 'svelte', 'solid-js', 'preact', '@angular/core', 'lit'];
20
+ const SOURCE = /\.(?:ts|tsx|mts|cts)$/;
21
+ const DECLARATION = /\.d\.[mc]?ts$/;
22
+ const DEEPEST_FEATURES = 4;
23
+ function filesOf(root) {
24
+ const listed = spawnSync('git', ['ls-files', '--cached', '--others', '--exclude-standard'], {
25
+ cwd: root,
26
+ encoding: 'utf8',
27
+ maxBuffer: 256 * 1024 * 1024,
28
+ });
29
+ const files = listed.status === 0 ? listed.stdout.split('\n').filter((line) => line !== '') : walk(root, '');
30
+ return files.filter((file) => !file.split('/').some((part) => SKIPPED.has(part)));
31
+ }
32
+ function walk(root, folder) {
33
+ return readdirSync(join(root, folder), { withFileTypes: true }).flatMap((entry) => {
34
+ const path = folder ? `${folder}/${entry.name}` : entry.name;
35
+ if (SKIPPED.has(entry.name) || entry.name.startsWith('.'))
36
+ return [];
37
+ return entry.isDirectory() ? walk(root, path) : [path];
38
+ });
39
+ }
40
+ const isSource = (file) => SOURCE.test(file) && !DECLARATION.test(file);
41
+ function foldersOf(files) {
42
+ const folders = new Set();
43
+ for (const file of files) {
44
+ const parts = file.split('/');
45
+ for (let depth = 1; depth < parts.length; depth += 1)
46
+ folders.add(parts.slice(0, depth).join('/'));
47
+ }
48
+ return folders;
49
+ }
50
+ const joined = (...parts) => posix.join(...parts.filter((part) => part !== '')) || '';
51
+ const inside = (path, folder) => folder === '' || path.startsWith(`${folder}/`);
52
+ const childrenOf = (folders, folder) => [...folders].filter((path) => inside(path, folder) && !path.slice(folder ? folder.length + 1 : 0).includes('/'));
53
+ function dependenciesOf(root, folder) {
54
+ const file = join(root, folder, 'package.json');
55
+ if (!existsSync(file))
56
+ return new Set();
57
+ const manifest = JSON.parse(readFileSync(file, 'utf8'));
58
+ return new Set([
59
+ ...Object.keys(manifest.dependencies ?? {}),
60
+ ...Object.keys(manifest.devDependencies ?? {}),
61
+ ...Object.keys(manifest.peerDependencies ?? {}),
62
+ ]);
63
+ }
64
+ function includeOf(sources) {
65
+ const counts = new Map();
66
+ for (const file of sources) {
67
+ const [top, ...rest] = file.split('/');
68
+ if (rest.length === 0 || !top || BESIDE.has(top))
69
+ continue;
70
+ counts.set(top, (counts.get(top) ?? 0) + 1);
71
+ }
72
+ return [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([top]) => top);
73
+ }
74
+ function candidatesOf(files, sources) {
75
+ const packages = files
76
+ .filter((file) => file.endsWith('/package.json'))
77
+ .map((file) => posix.dirname(file))
78
+ .filter((folder) => !folder.split('/').some((part) => NOT_APPS.has(part)))
79
+ .filter((folder) => sources.some((file) => inside(file, folder)))
80
+ .sort();
81
+ if (packages.length === 0)
82
+ return [''];
83
+ const loose = sources.some((file) => file.startsWith('src/') && !packages.some((folder) => inside(file, folder)));
84
+ return loose ? ['', ...packages] : packages;
85
+ }
86
+ function featuresFolder(folders, source) {
87
+ const found = [...folders]
88
+ .filter((path) => inside(path, source) && posix.basename(path) === 'features')
89
+ .filter((path) => {
90
+ const rest = path.slice(source ? source.length + 1 : 0).split('/');
91
+ return rest.length <= DEEPEST_FEATURES && !rest.some((part) => NOT_APPS.has(part));
92
+ })
93
+ .filter((path) => childrenOf(folders, path).length > 0)
94
+ .sort((a, b) => a.split('/').length - b.split('/').length || a.localeCompare(b));
95
+ return found[0] ?? null;
96
+ }
97
+ const local = (path, root) => (root === '' ? path : path.slice(root.length + 1)) || '.';
98
+ function roles(folders, root, renderer) {
99
+ const at = (name) => joined(root, renderer === '.' ? '' : renderer, name);
100
+ const role = (name) => (folders.has(at(name)) ? [local(at(name), root)] : undefined);
101
+ return { client: role('client'), primitives: role('primitives') };
102
+ }
103
+ function counted(folders, pattern) {
104
+ return pattern.endsWith('/*') ? childrenOf(folders, pattern.slice(0, -2)).length : 0;
105
+ }
106
+ function app(given, why, folders) {
107
+ const config = Object.fromEntries(Object.entries({ ...given, root: given.root || '.' }).filter(([, value]) => value !== undefined));
108
+ const features = (config.features ?? [])
109
+ .map((pattern) => counted(folders, joined(config.root, pattern)))
110
+ .reduce((sum, count) => sum + count, 0);
111
+ return { config, found: { root: config.root, stack: config.stack, features, why } };
112
+ }
113
+ function classify(root, folder, folders, sources) {
114
+ const has = (path) => folders.has(path);
115
+ const src = joined(folder, 'src');
116
+ if (has(joined(folder, 'src-tauri'))) {
117
+ const features = has(joined(src, 'features')) ? { features: ['src/features/*'] } : {};
118
+ return app({ root: folder, stack: 'tauri', ...features }, 'a Tauri app: its host in src-tauri/, its screens in src/', folders);
119
+ }
120
+ for (const at of [folder, src]) {
121
+ if (has(joined(at, 'electron-main')) || has(joined(at, 'electron-renderer'))) {
122
+ const features = has(joined(at, 'electron-renderer/features'))
123
+ ? { features: ['electron-renderer/features/*'] }
124
+ : {};
125
+ return app({ root: at, stack: 'electron', ...features }, 'an Electron app: electron-main/ and electron-renderer/', folders);
126
+ }
127
+ }
128
+ for (const at of [folder, src]) {
129
+ if (has(joined(at, 'server')) && has(joined(at, 'client'))) {
130
+ const features = has(joined(at, 'client/features')) ? { features: ['client/features/*'] } : {};
131
+ return app({ root: at, stack: 'web', ...features }, 'a web app: its server in server/, its screens in client/', folders);
132
+ }
133
+ }
134
+ const dependencies = dependenciesOf(root, folder);
135
+ if (dependencies.has('electron') && has(joined(src, 'main')) && has(joined(src, 'renderer'))) {
136
+ const feature = featuresFolder(folders, joined(src, 'renderer'));
137
+ return app({
138
+ root: folder,
139
+ stack: 'electron',
140
+ main: ['src/main', ...(has(joined(src, 'preload')) ? ['src/preload'] : [])],
141
+ renderer: ['src/renderer'],
142
+ shared: has(joined(src, 'shared')) ? ['src/shared'] : [],
143
+ ...(feature ? { features: [`${local(feature, folder)}/*`] } : {}),
144
+ ...roles(folders, folder, feature ? local(posix.dirname(feature), folder) : 'src/renderer'),
145
+ }, 'an Electron app: its main process in src/main, its screens in src/renderer', folders);
146
+ }
147
+ const base = has(src) ? src : folder;
148
+ const feature = featuresFolder(folders, base);
149
+ const ui = UI_PACKAGES.some((name) => dependencies.has(name));
150
+ const shown = (path) => path || '.';
151
+ if (feature && posix.dirname(feature) !== base) {
152
+ const renderer = local(posix.dirname(feature), base);
153
+ const { client, primitives } = roles(folders, base, renderer);
154
+ return app({
155
+ root: base,
156
+ stack: 'web',
157
+ main: ['.'],
158
+ renderer: [renderer],
159
+ features: [`${renderer}/features/*`],
160
+ ...(client ? { client } : {}),
161
+ ...(primitives ? { primitives } : {}),
162
+ areas: ['*', ...(client ?? []), ...(primitives ?? [])],
163
+ ...(client ? { bridge: { global: 'fetch' } } : {}),
164
+ }, `a web app: its code in ${shown(base)}, its screens in ${joined(base, renderer)}`, folders);
165
+ }
166
+ if (feature || ui) {
167
+ const { client, primitives } = roles(folders, base, '.');
168
+ return app({
169
+ root: base,
170
+ stack: 'web',
171
+ main: [],
172
+ renderer: ['.'],
173
+ shared: [],
174
+ ...(feature ? { features: ['features/*'] } : {}),
175
+ ...(client ? { client } : {}),
176
+ ...(primitives ? { primitives } : {}),
177
+ ...(client ? { bridge: { global: 'fetch' } } : {}),
178
+ }, `a web front end in ${shown(base)}`, folders);
179
+ }
180
+ const subfolders = childrenOf(folders, base).filter((path) => sources.some((file) => inside(file, path)));
181
+ if (subfolders.length === 0)
182
+ return null;
183
+ return app({ root: base, stack: 'web', main: ['.'], renderer: [], shared: [], areas: ['*'] }, `no screens: each folder of ${shown(base)} is an area`, folders);
184
+ }
185
+ function ownerOf(root) {
186
+ for (const file of ['.github/CODEOWNERS', 'CODEOWNERS', 'docs/CODEOWNERS']) {
187
+ const path = join(root, file);
188
+ if (!existsSync(path))
189
+ continue;
190
+ for (const line of readFileSync(path, 'utf8').split('\n')) {
191
+ const [pattern, owner] = line.trim().split(/\s+/);
192
+ if ((pattern === '*' || pattern === '/*') && owner?.startsWith('@'))
193
+ return owner;
194
+ }
195
+ }
196
+ return null;
197
+ }
198
+ export function detect(root) {
199
+ const files = filesOf(root);
200
+ const sources = files.filter(isSource);
201
+ if (sources.length === 0)
202
+ throw new AshlarError(`Ashlar found no TypeScript in ${root}: run it in a TypeScript repository.`);
203
+ const folders = foldersOf(files);
204
+ const apps = candidatesOf(files, sources)
205
+ .map((folder) => classify(root, folder, folders, sources))
206
+ .filter((found) => found !== null);
207
+ const include = includeOf(sources);
208
+ return { include: include.length > 0 ? include : ['.'], apps, owner: ownerOf(root) };
209
+ }
210
+ const quoted = (value) => `'${value.replaceAll('\\', '\\\\').replaceAll("'", "\\'")}'`;
211
+ function literal(value, indent) {
212
+ if (typeof value === 'string')
213
+ return quoted(value);
214
+ if (typeof value === 'boolean' || typeof value === 'number')
215
+ return String(value);
216
+ if (Array.isArray(value))
217
+ return `[${value.map((entry) => literal(entry, indent)).join(', ')}]`;
218
+ const entries = Object.entries(value).filter(([, entry]) => entry !== undefined);
219
+ const inner = `${indent} `;
220
+ const short = `{ ${entries.map(([key, entry]) => `${key}: ${literal(entry, inner)}`).join(', ')} }`;
221
+ if (short.length + indent.length <= 100)
222
+ return short;
223
+ return `{\n${entries.map(([key, entry]) => `${inner}${key}: ${literal(entry, inner)},`).join('\n')}\n${indent}}`;
224
+ }
225
+ export function configOf(found) {
226
+ return {
227
+ include: found.include,
228
+ ...(found.apps.length > 0 ? { apps: found.apps.map((entry) => entry.config) } : {}),
229
+ ...(found.owner ? { onboard: { owner: found.owner } } : {}),
230
+ };
231
+ }
232
+ export function configSource(config) {
233
+ const body = Object.entries(config)
234
+ .map(([key, value]) => {
235
+ if (key !== 'apps')
236
+ return ` ${key}: ${literal(value, ' ')},`;
237
+ const apps = value.map((entry) => ` ${literal(entry, ' ')},`).join('\n');
238
+ return ` apps: [\n${apps}\n ],`;
239
+ })
240
+ .join('\n');
241
+ return `import { defineConfig } from '@kurvball/ashlar';\n\nexport default defineConfig({\n${body}\n});\n`;
242
+ }
243
+ function configFileFor(root) {
244
+ const manifest = join(root, 'package.json');
245
+ if (!existsSync(manifest))
246
+ return 'ashlar.config.mts';
247
+ const type = JSON.parse(readFileSync(manifest, 'utf8')).type;
248
+ return type === 'module' ? CONFIG_FILE : 'ashlar.config.mts';
249
+ }
250
+ export function init(root, options = {}) {
251
+ const started = performance.now();
252
+ const existing = findConfig(root);
253
+ if (existing) {
254
+ throw new AshlarError(`Ashlar already reads ${relative(root, existing) || existing}: init writes a config only where there is none.`);
255
+ }
256
+ const found = detect(root);
257
+ const config = configOf(found);
258
+ const file = configFileFor(root);
259
+ const settled = settle(config, root, file);
260
+ const source = configSource(config);
261
+ let baseline = null;
262
+ let warnings = [];
263
+ if (!options.dryRun) {
264
+ writeFileSync(join(root, file), source);
265
+ const checked = check(settled, { shrink: true });
266
+ const breaks = checked.rules.reduce((total, rule) => total + rule.baseline, 0);
267
+ baseline = { file: breaks > 0 ? relative(root, settled.baseline) : null, breaks };
268
+ warnings = checked.warnings;
269
+ }
270
+ const report = {
271
+ version: 1,
272
+ config: file,
273
+ wrote: !options.dryRun,
274
+ include: found.include,
275
+ apps: found.apps.map((entry) => entry.found),
276
+ owner: found.owner,
277
+ baseline,
278
+ source,
279
+ seconds: (performance.now() - started) / 1000,
280
+ };
281
+ return { report, warnings };
282
+ }
283
+ const plural = (count, one, many) => `${count} ${count === 1 ? one : many}`;
284
+ function listed(names) {
285
+ return names.length < 2 ? (names[0] ?? '') : `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
286
+ }
287
+ export function initText(report) {
288
+ const lines = report.apps.length === 0
289
+ ? ['Ashlar found no app, so only the rules that hold in every file apply.']
290
+ : [
291
+ `Ashlar found ${plural(report.apps.length, 'app', 'apps')} in ${report.seconds.toFixed(1)} s:`,
292
+ ...report.apps.map((app) => ` ${app.root}: ${app.why}${app.features > 0 ? `, ${plural(app.features, 'feature', 'features')}` : ''}.`),
293
+ ];
294
+ lines.push(`It checks ${listed(report.include)}.`);
295
+ if (report.baseline?.file) {
296
+ lines.push(`Wrote ${report.config}, and took the baseline: ${plural(report.baseline.breaks, 'break', 'breaks')} in ${report.baseline.file}.`, 'Commit both. From now on `ashlar check` fails when a file gets worse: run it on every pull request,', 'as https://ashlar.kurvball.ca/recipes/run-in-github-actions/ shows.');
297
+ }
298
+ else if (report.baseline) {
299
+ lines.push(`Wrote ${report.config}. Nothing breaks a rule, so there is no baseline: every count must stay at zero.`, 'Commit it, and run `ashlar check` on every pull request,', 'as https://ashlar.kurvball.ca/recipes/run-in-github-actions/ shows.');
300
+ }
301
+ else {
302
+ lines.push(`It would write ${report.config}, and take the baseline:`, '', report.source.trimEnd());
303
+ }
304
+ if (!report.owner) {
305
+ lines.push(`Before \`ashlar onboard\`, name who answers its questions: \`onboard: { owner: '@handle' }\`.`);
306
+ }
307
+ return `${lines.join('\n')}\n`;
308
+ }
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ import { type Loaded } from './config.ts';
3
+ export declare const PROTOCOL_VERSIONS: readonly ['2025-11-25', '2025-06-18', '2025-03-26'];
4
+ export declare const INSTRUCTIONS = "Ashlar checks a TypeScript repository against rules that came from corrections, and holds each file to a baseline that only shrinks. In a repository with no ashlar.config.ts, init writes one. Brief before you write, and check before you push: the skill at skill/ashlar/SKILL.md in the package teaches the loop.";
5
+ type Kind = 'boolean' | 'string' | 'paths';
6
+ interface Argument {
7
+ kind: Kind;
8
+ description: string;
9
+ }
10
+ interface Answer {
11
+ json: object;
12
+ warnings?: readonly string[];
13
+ }
14
+ interface Tool {
15
+ name: string;
16
+ description: string;
17
+ args: Record<string, Argument>;
18
+ required?: string[];
19
+ readOnly: boolean;
20
+ run?: (config: Loaded, args: Record<string, unknown>) => Answer;
21
+ start?: (args: Record<string, unknown>, cwd: string) => Answer;
22
+ }
23
+ export declare const TOOLS: readonly Tool[];
24
+ export declare function outputSchemaOf(name: string): Record<string, unknown>;
25
+ export declare function toolList(): Record<string, unknown>[];
26
+ export declare function callTool(name: string, given: unknown, cwd?: string, log?: NodeJS.WriteStream & {
27
+ fd: 2;
28
+ }): Promise<{
29
+ content: {
30
+ type: string;
31
+ text: string;
32
+ }[];
33
+ isError: boolean;
34
+ } | {
35
+ content: {
36
+ type: string;
37
+ text: string;
38
+ }[];
39
+ structuredContent: object;
40
+ isError: boolean;
41
+ } | null>;
42
+ export declare function serve(input?: Readable, output?: Writable): Promise<void>;
43
+ export {};
package/dist/mcp.js ADDED
@@ -0,0 +1,236 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { createInterface } from 'node:readline';
3
+ import { affectedAnswer, briefAnswer, checkAnswer, mapAnswer, onboardAnswer } from './answers.js';
4
+ import { AshlarError, loadConfig } from './config.js';
5
+ import { init } from './init.js';
6
+ export const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26'];
7
+ export const INSTRUCTIONS = 'Ashlar checks a TypeScript repository against rules that came from corrections, and holds each file to a baseline that only shrinks. In a repository with no ashlar.config.ts, init writes one. Brief before you write, and check before you push: the skill at skill/ashlar/SKILL.md in the package teaches the loop.';
8
+ const paths = (args, name) => args[name] ?? [];
9
+ const flag = (args, name) => args[name] === true;
10
+ const text = (args, name) => args[name];
11
+ export const TOOLS = [
12
+ {
13
+ name: 'init',
14
+ description: 'Finds the repository’s apps, their features and areas, writes ashlar.config.ts and takes the baseline, where there is no config yet. With dryRun, answers with the config it would write, and writes nothing. Answers with init.v1.json.',
15
+ args: {
16
+ dryRun: { kind: 'boolean', description: 'Answer with the config it would write, and write nothing.' },
17
+ },
18
+ readOnly: false,
19
+ start: (args, cwd) => {
20
+ const { report, warnings } = init(cwd, { dryRun: flag(args, 'dryRun') });
21
+ return { json: report, warnings };
22
+ },
23
+ },
24
+ {
25
+ name: 'brief',
26
+ description: 'What an agent needs before it changes some files: the data rules, the rules that apply there, the folder rules and gotchas, the decisions, the features and the open questions. Answers with brief.v1.json.',
27
+ args: { paths: { kind: 'paths', description: 'The files or folders the agent will change.' } },
28
+ required: ['paths'],
29
+ readOnly: true,
30
+ run: (config, args) => ({ json: briefAnswer(config, paths(args, 'paths')) }),
31
+ },
32
+ {
33
+ name: 'check',
34
+ description: "Runs the rules and the import graph, and answers ok: false when a file's count rises above what the baseline holds for it. A rise is a finding, not an error. Answers with check.v1.json.",
35
+ args: {
36
+ shrink: {
37
+ kind: 'boolean',
38
+ description: 'Write the baseline: take it the first time, then only lower each file’s counts.',
39
+ },
40
+ acceptRise: {
41
+ kind: 'boolean',
42
+ description: 'Take each count that rose into the baseline. Ask a person first.',
43
+ },
44
+ since: {
45
+ kind: 'string',
46
+ description: 'Measure the lines a change wrote from where it left this ref rather than main, such as a release line.',
47
+ },
48
+ },
49
+ readOnly: false,
50
+ run: (config, args) => {
51
+ const { json, warnings } = checkAnswer(config, {
52
+ shrink: flag(args, 'shrink'),
53
+ acceptRise: flag(args, 'acceptRise'),
54
+ since: text(args, 'since'),
55
+ });
56
+ return { json, warnings };
57
+ },
58
+ },
59
+ {
60
+ name: 'affected',
61
+ description: 'Lists the tests that reach the files, or the files changed since a ref, through imports, stylesheets, setup files and builds. Answers with affected.v1.json.',
62
+ args: {
63
+ files: { kind: 'paths', description: 'The changed files.' },
64
+ since: { kind: 'string', description: 'Take the files changed since this ref instead, or as well.' },
65
+ },
66
+ readOnly: true,
67
+ run: (config, args) => ({ json: affectedAnswer(config, paths(args, 'files'), text(args, 'since')).json }),
68
+ },
69
+ {
70
+ name: 'map',
71
+ description: 'Lists each feature folder in the layout: its name, its reach script and its proofs, the tests in it. Answers with map.v1.json.',
72
+ args: {},
73
+ readOnly: true,
74
+ run: (config) => ({ json: mapAnswer(config).json }),
75
+ },
76
+ {
77
+ name: 'onboard',
78
+ description: 'Writes the onboarding guide from the map, DECISIONS.md and .claude/rules/, with every unknown as a question routed to its owner. With check, answers ok: false when the guide is stale, and writes nothing. Answers with onboard.v1.json.',
79
+ args: {
80
+ check: { kind: 'boolean', description: 'Only check that the guide is current, and write nothing.' },
81
+ },
82
+ readOnly: false,
83
+ run: (config, args) => ({ json: onboardAnswer(config, flag(args, 'check')) }),
84
+ },
85
+ ];
86
+ const SCHEMA_DIR = new URL('../schema/', import.meta.url);
87
+ export function outputSchemaOf(name) {
88
+ return JSON.parse(readFileSync(new URL(`${name}.v1.json`, SCHEMA_DIR), 'utf8'));
89
+ }
90
+ function inputSchemaOf(tool) {
91
+ const properties = Object.fromEntries(Object.entries(tool.args).map(([name, arg]) => [
92
+ name,
93
+ arg.kind === 'paths'
94
+ ? { type: 'array', items: { type: 'string' }, description: arg.description }
95
+ : { type: arg.kind, description: arg.description },
96
+ ]));
97
+ return {
98
+ type: 'object',
99
+ properties,
100
+ ...(tool.required ? { required: tool.required } : {}),
101
+ additionalProperties: false,
102
+ };
103
+ }
104
+ export function toolList() {
105
+ return TOOLS.map((tool) => ({
106
+ name: tool.name,
107
+ description: tool.description,
108
+ inputSchema: inputSchemaOf(tool),
109
+ outputSchema: outputSchemaOf(tool.name),
110
+ annotations: {
111
+ readOnlyHint: tool.readOnly,
112
+ ...(tool.readOnly ? {} : { destructiveHint: false }),
113
+ idempotentHint: true,
114
+ openWorldHint: false,
115
+ },
116
+ }));
117
+ }
118
+ function argumentsOf(tool, given) {
119
+ if (given === undefined || given === null)
120
+ given = {};
121
+ if (typeof given !== 'object' || Array.isArray(given)) {
122
+ throw new AshlarError(`Give \`${tool.name}\` its arguments as an object.`);
123
+ }
124
+ const args = given;
125
+ const takes = Object.keys(tool.args);
126
+ for (const [name, value] of Object.entries(args)) {
127
+ const arg = tool.args[name];
128
+ if (!arg) {
129
+ const named = takes.length ? takes.join(', ') : 'none';
130
+ throw new AshlarError(`\`${tool.name}\` takes no ${name}: it takes ${named}.`);
131
+ }
132
+ const fits = arg.kind === 'paths'
133
+ ? Array.isArray(value) && value.every((entry) => typeof entry === 'string')
134
+ : typeof value === arg.kind;
135
+ if (!fits) {
136
+ const wanted = arg.kind === 'paths' ? 'a list of paths' : arg.kind === 'string' ? 'a string' : 'true or false';
137
+ throw new AshlarError(`Give \`${name}\` ${wanted}.`);
138
+ }
139
+ }
140
+ for (const name of tool.required ?? []) {
141
+ if (args[name] === undefined)
142
+ throw new AshlarError(`\`${tool.name}\` needs ${name}.`);
143
+ }
144
+ return args;
145
+ }
146
+ const said = (message) => ({ content: [{ type: 'text', text: message }], isError: true });
147
+ export async function callTool(name, given, cwd = process.cwd(), log = process.stderr) {
148
+ const tool = TOOLS.find((entry) => entry.name === name);
149
+ if (!tool)
150
+ return null;
151
+ try {
152
+ const args = argumentsOf(tool, given);
153
+ const { json, warnings = [] } = tool.start
154
+ ? tool.start(args, cwd)
155
+ : tool.run(await loadConfig(cwd), args);
156
+ for (const warning of warnings)
157
+ log.write(`Warning: ${warning}\n`);
158
+ return {
159
+ content: [{ type: 'text', text: JSON.stringify(json) }],
160
+ structuredContent: json,
161
+ isError: false,
162
+ };
163
+ }
164
+ catch (error) {
165
+ if (error instanceof AshlarError)
166
+ return said(error.message);
167
+ log.write(`${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`);
168
+ return said(`Ashlar failed: ${error instanceof Error ? error.message : String(error)}`);
169
+ }
170
+ }
171
+ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
172
+ async function reply(message) {
173
+ const id = message.id;
174
+ const answer = (result) => ({ jsonrpc: '2.0', id, result });
175
+ const fail = (code, text) => ({
176
+ jsonrpc: '2.0',
177
+ id: id ?? null,
178
+ error: { code, message: text },
179
+ });
180
+ if (message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
181
+ return id === undefined || message.method === undefined ? null : fail(-32600, 'Invalid request');
182
+ }
183
+ if (id === undefined)
184
+ return null;
185
+ const params = message.params ?? {};
186
+ switch (message.method) {
187
+ case 'initialize': {
188
+ const asked = params.protocolVersion;
189
+ const protocolVersion = PROTOCOL_VERSIONS.find((version) => version === asked) ?? PROTOCOL_VERSIONS[0];
190
+ return answer({
191
+ protocolVersion,
192
+ capabilities: { tools: { listChanged: false } },
193
+ serverInfo: { name: 'ashlar', version: VERSION },
194
+ instructions: INSTRUCTIONS,
195
+ });
196
+ }
197
+ case 'ping':
198
+ return answer({});
199
+ case 'tools/list':
200
+ return answer({ tools: toolList() });
201
+ case 'tools/call': {
202
+ if (typeof params.name !== 'string')
203
+ return fail(-32602, 'Name the tool to call.');
204
+ const result = await callTool(params.name, params.arguments);
205
+ return result ? answer(result) : fail(-32602, `Ashlar has no ${params.name} tool.`);
206
+ }
207
+ default:
208
+ return fail(-32601, `Ashlar's server has no method ${message.method}.`);
209
+ }
210
+ }
211
+ export async function serve(input = process.stdin, output = process.stdout) {
212
+ const write = output.write.bind(output);
213
+ if (output === process.stdout) {
214
+ process.stdout.write = process.stderr.write.bind(process.stderr);
215
+ }
216
+ const send = (message) => write(`${JSON.stringify(message)}\n`);
217
+ for await (const line of createInterface({ input, crlfDelay: Infinity })) {
218
+ if (line.trim() === '')
219
+ continue;
220
+ let message;
221
+ try {
222
+ message = JSON.parse(line);
223
+ }
224
+ catch {
225
+ send({ jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } });
226
+ continue;
227
+ }
228
+ if (typeof message !== 'object' || message === null || Array.isArray(message)) {
229
+ send({ jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid request' } });
230
+ continue;
231
+ }
232
+ const response = await reply(message);
233
+ if (response)
234
+ send(response);
235
+ }
236
+ }
package/dist/usage.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const USAGE = "Usage:\n ashlar check [--shrink] [--accept-rise] [--since <ref>] [--json]\n Runs the rules and the import graph, and fails when a file's count rises above what the\n baseline holds for that file. A file the baseline doesn't name holds none.\n --shrink writes the baseline: it takes it the first time, then only lowers each file's counts.\n A file that is gone drops out, and a file git saw renamed takes its counts to its new name.\n --accept-rise takes each count that rose into the baseline, and says what it took in.\n --since <ref> measures the lines a change touched, and the files it renamed, from where it\n left <ref> rather than main: on a pull request into a release line, give that line.\n ashlar affected [files...] [--since <ref>] [--json]\n Lists the tests that reach the files, or the files changed since <ref>, through imports,\n stylesheets, setup files and builds. A deleted file lists the tests that imported it,\n and --json lists the deleted files apart.\n ashlar move <from> <to> [<from> <to> ...] [--accept-rise] [--json]\n Moves a file's counts in the baseline to its new name, or those of every file in a folder.\n Each file keeps what it holds now, up to what the baseline held for it.\n It refuses a move that takes in new breaks, unless --accept-rise is given.\n ashlar ledger [--json]\n Lists Ashlar's ledger: each rule and each check from the import graph, what it corrected, the\n case it came from as a test, the prose it replaced and the message agents read.\n ashlar map [--json]\n Lists each feature folder in the layout: its name, its reach and its proofs, the tests in it.\n --json prints it as JSON, in the feature map's schema.\n ashlar drive <feature> [--scheme light|dark] [--json]\n ashlar drive --all [--scheme light|dark] [--json]\n Walks a feature's reach script, step by step, through the config's drive command, or through\n rehearse drive when the project has a rehearse.yaml and names none. It stops at the first step\n that fails, saying which and why. --all walks every feature's.\n ashlar onboard [--check] [--json]\n Writes the onboarding guide from the map, DECISIONS.md and .claude/rules/: what the system is, a\n page per area, and every unknown as a question routed to its owner. --check fails when the\n guide is stale or was edited by hand, and writes nothing.\n ashlar brief <paths...> [--json]\n Prints what an agent needs before it changes those files: the data rules, the rules that apply\n there, the folder rules and gotchas, the decisions, the features and the open questions. Never\n access lines, and never a secret-shaped value.\n ashlar snapshot [--json]\n Prints where things stand today: the ratchet, the map, the decisions and questions, and each\n area's recent commits. It writes nothing.\n ashlar dependents <files...> [--json]\n Lists every file that reaches each file through imports, directly or not, and the reach script\n of each feature whose folder they touch: what Rehearse reads for rehearse list --affected.\n --json prints it in Rehearse's dependents contract.\n ashlar rehearse [--json]\n Prints the blocks of rehearse.yaml Ashlar fills: each feature's reach script as a flow that\n covers its folder. --json adds each flow as Rehearse reads it.\n ashlar skill verify|onboard [--write] [--force]\n Prints a skill for agents. verify: how an agent checks its own work with the map and drive,\n and shows what it made, through the attach section the config names, if any. onboard: how an\n agent reads its brief before it changes files, and keeps what people decide.\n --write writes it into .claude/skills/<name>/SKILL.md, and --force replaces one that differs.\n\n ashlar --version\n Prints the version of Ashlar that runs.\n";
1
+ export declare const USAGE = "Usage:\n ashlar init [--dry-run] [--json]\n Finds the repository's apps, their features and areas, writes the config and takes the\n baseline, where there is no config yet. --dry-run prints the config it would write, and writes\n nothing.\n ashlar check [--shrink] [--accept-rise] [--since <ref>] [--json]\n Runs the rules and the import graph, and fails when a file's count rises above what the\n baseline holds for that file. A file the baseline doesn't name holds none.\n --shrink writes the baseline: it takes it the first time, then only lowers each file's counts.\n A file that is gone drops out, and a file git saw renamed takes its counts to its new name.\n --accept-rise takes each count that rose into the baseline, and says what it took in.\n --since <ref> measures the lines a change touched, and the files it renamed, from where it\n left <ref> rather than main: on a pull request into a release line, give that line.\n ashlar affected [files...] [--since <ref>] [--json]\n Lists the tests that reach the files, or the files changed since <ref>, through imports,\n stylesheets, setup files and builds. A deleted file lists the tests that imported it,\n and --json lists the deleted files apart.\n ashlar move <from> <to> [<from> <to> ...] [--accept-rise] [--json]\n Moves a file's counts in the baseline to its new name, or those of every file in a folder.\n Each file keeps what it holds now, up to what the baseline held for it.\n It refuses a move that takes in new breaks, unless --accept-rise is given.\n ashlar ledger [--json]\n Lists Ashlar's ledger: each rule and each check from the import graph, what it corrected, the\n case it came from as a test, the prose it replaced and the message agents read.\n ashlar map [--json]\n Lists each feature folder in the layout: its name, its reach and its proofs, the tests in it.\n --json prints it as JSON, in the feature map's schema.\n ashlar drive <feature> [--scheme light|dark] [--json]\n ashlar drive --all [--scheme light|dark] [--json]\n Walks a feature's reach script, step by step, through the config's drive command, or through\n rehearse drive when the project has a rehearse.yaml and names none. It stops at the first step\n that fails, saying which and why. --all walks every feature's.\n ashlar onboard [--check] [--json]\n Writes the onboarding guide from the map, DECISIONS.md and .claude/rules/: what the system is, a\n page per area, and every unknown as a question routed to its owner. --check fails when the\n guide is stale or was edited by hand, and writes nothing.\n ashlar brief <paths...> [--json]\n Prints what an agent needs before it changes those files: the data rules, the rules that apply\n there, the folder rules and gotchas, the decisions, the features and the open questions. Never\n access lines, and never a secret-shaped value.\n ashlar mcp\n Serves init, brief, check, affected, map and onboard as MCP tools on stdio, for agents. Each tool\n takes its command's options and answers with the object its command prints with --json.\n ashlar snapshot [--json]\n Prints where things stand today: the ratchet, the map, the decisions and questions, and each\n area's recent commits. It writes nothing.\n ashlar dependents <files...> [--json]\n Lists every file that reaches each file through imports, directly or not, and the reach script\n of each feature whose folder they touch: what Rehearse reads for rehearse list --affected.\n --json prints it in Rehearse's dependents contract.\n ashlar rehearse [--json]\n Prints the blocks of rehearse.yaml Ashlar fills: each feature's reach script as a flow that\n covers its folder. --json adds each flow as Rehearse reads it.\n ashlar skill verify|onboard [--write] [--force]\n Prints a skill for agents. verify: how an agent checks its own work with the map and drive,\n and shows what it made, through the attach section the config names, if any. onboard: how an\n agent reads its brief before it changes files, and keeps what people decide.\n --write writes it into .claude/skills/<name>/SKILL.md, and --force replaces one that differs.\n\n ashlar --version\n Prints the version of Ashlar that runs.\n";
package/dist/usage.js CHANGED
@@ -1,4 +1,8 @@
1
1
  export const USAGE = `Usage:
2
+ ashlar init [--dry-run] [--json]
3
+ Finds the repository's apps, their features and areas, writes the config and takes the
4
+ baseline, where there is no config yet. --dry-run prints the config it would write, and writes
5
+ nothing.
2
6
  ashlar check [--shrink] [--accept-rise] [--since <ref>] [--json]
3
7
  Runs the rules and the import graph, and fails when a file's count rises above what the
4
8
  baseline holds for that file. A file the baseline doesn't name holds none.
@@ -34,6 +38,9 @@ export const USAGE = `Usage:
34
38
  Prints what an agent needs before it changes those files: the data rules, the rules that apply
35
39
  there, the folder rules and gotchas, the decisions, the features and the open questions. Never
36
40
  access lines, and never a secret-shaped value.
41
+ ashlar mcp
42
+ Serves init, brief, check, affected, map and onboard as MCP tools on stdio, for agents. Each tool
43
+ takes its command's options and answers with the object its command prints with --json.
37
44
  ashlar snapshot [--json]
38
45
  Prints where things stand today: the ratchet, the map, the decisions and questions, and each
39
46
  area's recent commits. It writes nothing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurvball/ashlar",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "The rules for building software with agents: lint rules, an import graph with a shrink-only ratchet, a feature map and onboarding for TypeScript projects.",
5
5
  "keywords": [
6
6
  "agents",
@@ -46,6 +46,7 @@
46
46
  "dist",
47
47
  "ledger.json",
48
48
  "schema",
49
+ "skill",
49
50
  "CHANGELOG.md"
50
51
  ],
51
52
  "dependencies": {
@@ -53,6 +54,7 @@
53
54
  },
54
55
  "devDependencies": {
55
56
  "@changesets/cli": "3.0.3",
57
+ "@modelcontextprotocol/sdk": "1.32.2",
56
58
  "@types/node": "^22.20.5",
57
59
  "ajv": "8.20.0",
58
60
  "prettier": "3.9.10",
@@ -0,0 +1,63 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/kurvball/ashlar/blob/main/schema/init.v1.json",
4
+ "title": "ashlar init --json",
5
+ "description": "The apps Ashlar found, the folders it checks, the config it wrote, and the baseline it took.",
6
+ "type": "object",
7
+ "required": ["version", "config", "wrote", "include", "apps", "owner", "baseline", "source", "seconds"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "version": { "const": 1 },
11
+ "config": {
12
+ "type": "string",
13
+ "description": "The config file, ashlar.config.ts, or ashlar.config.mts in a package that isn't a module."
14
+ },
15
+ "wrote": {
16
+ "type": "boolean",
17
+ "description": "Whether it wrote the config and took the baseline: false with --dry-run."
18
+ },
19
+ "include": {
20
+ "type": "array",
21
+ "items": { "type": "string" },
22
+ "description": "The folders Ashlar checks."
23
+ },
24
+ "apps": {
25
+ "type": "array",
26
+ "description": "Each app it found, as the config names it.",
27
+ "items": {
28
+ "type": "object",
29
+ "required": ["root", "stack", "features", "why"],
30
+ "additionalProperties": false,
31
+ "properties": {
32
+ "root": { "type": "string" },
33
+ "stack": { "enum": ["electron", "tauri", "web"] },
34
+ "features": {
35
+ "type": "integer",
36
+ "minimum": 0,
37
+ "description": "How many feature folders it holds."
38
+ },
39
+ "why": { "type": "string", "description": "What Ashlar saw that made it this app, in a sentence." }
40
+ }
41
+ }
42
+ },
43
+ "owner": { "type": ["string", "null"], "description": "The default owner, from CODEOWNERS, or null." },
44
+ "baseline": {
45
+ "type": ["object", "null"],
46
+ "description": "The baseline it took, or null with --dry-run.",
47
+ "required": ["file", "breaks"],
48
+ "additionalProperties": false,
49
+ "properties": {
50
+ "file": {
51
+ "type": ["string", "null"],
52
+ "description": "The baseline file, or null when nothing breaks a rule."
53
+ },
54
+ "breaks": { "type": "integer", "minimum": 0 }
55
+ }
56
+ },
57
+ "source": {
58
+ "type": "string",
59
+ "description": "The config's text, written or, with --dry-run, as it would be written."
60
+ },
61
+ "seconds": { "type": "number" }
62
+ }
63
+ }
@@ -0,0 +1,69 @@
1
+ ---
2
+ name: ashlar
3
+ description: Use in a TypeScript repository with an `ashlar.config.ts` at its root, often beside an `ashlar.baseline.json`. Brief before you change files, find the tests a change reaches, and check before you push. Answers "what rules apply to these files?", "which tests should I run?" and "did my change make a file worse?".
4
+ ---
5
+
6
+ # Ashlar
7
+
8
+ Ashlar checks a TypeScript repository against rules that came from corrections, and holds each file to a
9
+ baseline that only shrinks: old code stays as it is, and no file gets worse. Each rule's message says what to
10
+ do instead.
11
+
12
+ Every step below works two ways, and both answer with the same JSON object:
13
+
14
+ - **The MCP server,** when your client has it: call the tool named in the step. The repository's `.mcp.json`
15
+ starts it with `npx --no-install ashlar mcp`.
16
+ - **The command,** when it doesn't: run it with `--json` through the package manager, `pnpm exec ashlar`,
17
+ `yarn ashlar` or `npx --no-install ashlar`. Never a bare `npx ashlar`: that package is someone else's.
18
+
19
+ In a repository with no `ashlar.config.ts` yet, `init` writes one and takes the baseline: the tool `init`, or
20
+ `ashlar init --json`. With `{ "dryRun": true }` (`--dry-run`) it answers with the config it would write, and
21
+ writes nothing. Show a person the config before you commit it.
22
+
23
+ ## The loop
24
+
25
+ 1. **Brief before you write.** Name the files or folders you will change.
26
+ - Tool: `brief` with `{ "paths": ["src/cart"] }`.
27
+ - Command: `ashlar brief src/cart --json`.
28
+
29
+ Read every part of the answer before you write a line:
30
+ - `rules` and `dataRules`: the rules that hold there, each with the `message` that says what to do instead;
31
+ - `folderRules`: the folder's own rules and its gotchas, and a `guard` when a scenario tries one on every
32
+ change;
33
+ - `decisions`: what was decided, by whom, and when;
34
+ - `features`: the feature folders you touch, each with its reach script;
35
+ - `questions`: what nobody has answered yet. Don't guess an answer; ask its `owner`.
36
+
37
+ 2. **Write the change.** Follow the brief. A comment is a break: say it with a name or a test instead.
38
+
39
+ 3. **Run the tests the change reaches.**
40
+ - Tool: `affected` with `{ "since": "origin/main" }`, or `{ "files": [...] }`.
41
+ - Command: `ashlar affected --since origin/main --json`.
42
+
43
+ Run each test in `tests`. A file in `unreached` has no test that reaches it: write one, or say so in your
44
+ report. Each entry in `features` names the reach script that walks that feature in the app.
45
+
46
+ 4. **Check before you push.**
47
+ - Tool: `check`, with `{ "since": "origin/release/1.x" }` on a pull request into a release line.
48
+ - Command: `ashlar check --json`, or `ashlar check --since origin/release/1.x --json`.
49
+
50
+ `ok: true` means no file got worse. With `ok: false`, each entry in `rises` names the `rule`, the `file`, its
51
+ `count` against the `baseline`, the `breaks` (each `fresh` one is on a line you changed) and the `message`.
52
+ Do what the message says, then check again. A rise is a finding, not an error: the tool answers it with
53
+ `isError: false`.
54
+
55
+ 5. **Lower the baseline when you fixed breaks.** When `slack` is above zero, run `check` with
56
+ `{ "shrink": true }` (`ashlar check --shrink`) and commit `ashlar.baseline.json` with the fix.
57
+
58
+ ## Rules
59
+
60
+ - Never raise the baseline yourself. `acceptRise` (`--accept-rise`) takes a rise in for good: ask a person
61
+ first, and say which rule and file.
62
+ - Never edit `ashlar.baseline.json` or the onboarding guide by hand. `check --shrink` writes the baseline, and
63
+ `onboard` writes the guide.
64
+ - Never turn a rule off with a comment: there is no such comment. A rule is turned off only in
65
+ `ashlar.config.ts`, by a person.
66
+ - When `onboard` with `{ "check": true }` answers `ok: false`, the guide is stale: run `onboard` and commit
67
+ what it wrote.
68
+ - A refusal comes back with `isError: true` and a sentence saying what was wrong, such as a ref git doesn't
69
+ know. Fix the call; don't retry it unchanged.