@kurvball/ashlar 1.8.2 → 1.9.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,19 @@ 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.9.0
10
+
11
+ _Released 2026-12-06._
12
+
13
+ ### Minor Changes
14
+
15
+ - `ashlar decide` records one decision: it adds a well-formed line to the decisions file the config names, so an agent proposes what a person decided in a pull request instead of editing the file by hand. It takes who decided (`--by`), the guide's areas, folders or files (`--areas`), a `--kind` and a `--date`, and refuses an area it can't find, a secret, malformed input and a decision the file already holds. It prints the line it wrote, or with `--json` the new `decide.v1.json`, and `--dry-run` writes nothing. `ashlar mcp` serves it as the `decide` tool, and the Ashlar and onboard skills now record decisions with it. On every command, `--` now ends the options, so what follows is read as it is.
16
+
17
+ ### Patch Changes
18
+
19
+ - The decisions file and the guide can live together in a folder with other files, through `onboard.decisions` and `onboard.out`, such as `memory/decisions.md` and `memory/guide`. Only the decisions file's lines are read as decisions, and `ashlar onboard` now refuses to write the guide into a folder that doesn't hold it yet over a file it didn't write, such as the folder's own `README.md`, instead of replacing it. Two new contract scenarios prove it on a fixture with such a folder.
20
+ - Ashlar runs on Windows, and CI checks it there. A drive command runs through the platform's shell, with each argument quoted for it, and `driveLine` takes the platform to quote for. A skill linked out of the repository is found on any drive.
21
+
9
22
  ## 1.8.2
10
23
 
11
24
  _Released 2026-12-04._
package/README.md CHANGED
@@ -74,8 +74,8 @@ repository and install the tarball from a folder of your project:
74
74
  Never run a bare `npx ashlar`. A package named `ashlar` on npm is someone else's, and `npx` would download and
75
75
  run it. Use `pnpm exec ashlar`, `yarn ashlar` or `npx --no-install ashlar`.
76
76
 
77
- Ashlar needs Node 22.18 or later, which reads `ashlar.config.ts` without a build step, and Git. It checks
78
- TypeScript. Its stacks are `electron`, `tauri` and `web`.
77
+ Ashlar needs Node 22.18 or later, which reads `ashlar.config.ts` without a build step, and Git, on Linux, macOS
78
+ or Windows. It checks TypeScript. Its stacks are `electron`, `tauri` and `web`.
79
79
 
80
80
  ## A config for an app
81
81
 
package/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs';
3
3
  import { relative } from 'node:path';
4
4
  import { affectedAnswer, briefAnswer, checkAnswer, mapAnswer, onboardAnswer } from './answers.js';
5
5
  import { AshlarError, loadConfig } from './config.js';
6
+ import { decide, decideText } from './decide.js';
6
7
  import { init, initText } from './init.js';
7
8
  import { errorJson, scrubbed } from './errors.js';
8
9
  import { gateAnswer } from './gate.js';
@@ -35,10 +36,15 @@ const FLAGS = {
35
36
  rehearse: ['json'],
36
37
  mcp: [],
37
38
  init: ['dry-run', 'json'],
39
+ decide: ['areas', 'by', 'kind', 'date', 'dry-run', 'json'],
38
40
  };
39
41
  const VALUED = new Map([
40
42
  ['since', 'a ref'],
41
43
  ['scheme', `a scheme: ${SCHEMES.join(' or ')}`],
44
+ ['areas', 'its areas, separated by commas'],
45
+ ['by', 'a handle, such as @robin'],
46
+ ['kind', 'a kind, such as rule'],
47
+ ['date', 'a date, such as 2026-12-03'],
42
48
  ]);
43
49
  function parse(args) {
44
50
  const positional = [];
@@ -46,6 +52,10 @@ function parse(args) {
46
52
  const values = new Map();
47
53
  for (let i = 0; i < args.length; i += 1) {
48
54
  const arg = args[i];
55
+ if (arg === '--') {
56
+ positional.push(...args.slice(i + 1));
57
+ break;
58
+ }
49
59
  if (!arg.startsWith('--')) {
50
60
  positional.push(arg);
51
61
  continue;
@@ -67,7 +77,8 @@ function parse(args) {
67
77
  if (value === '' || value.startsWith('--')) {
68
78
  throw new AshlarError(`Give \`--${name}\` ${takes}.`);
69
79
  }
70
- values.set(name, value);
80
+ const before = values.get(name);
81
+ values.set(name, name === 'areas' && before !== undefined ? `${before},${value}` : value);
71
82
  }
72
83
  return { command: positional.shift(), positional, flags, values };
73
84
  }
@@ -188,6 +199,27 @@ async function main(args) {
188
199
  print(json, fill, fillText(fill));
189
200
  return 0;
190
201
  }
202
+ if (command === 'decide') {
203
+ if (positional.length !== 1) {
204
+ throw new AshlarError('Give `ashlar decide` what was decided, in quotes: ashlar decide "Prices are whole cents." --areas src/cart --by @robin');
205
+ }
206
+ const areas = values.get('areas');
207
+ const by = values.get('by');
208
+ if (areas === undefined)
209
+ throw new AshlarError('Name the areas it covers with `--areas`, such as `--areas src/cart`.');
210
+ if (by === undefined)
211
+ throw new AshlarError('Say who decided with `--by`, such as `--by @robin`.');
212
+ const report = decide(config, {
213
+ text: positional[0],
214
+ areas: areas.split(','),
215
+ by,
216
+ kind: values.get('kind'),
217
+ date: values.get('date'),
218
+ dryRun: flags.has('dry-run'),
219
+ });
220
+ print(json, report, decideText(report));
221
+ return 0;
222
+ }
191
223
  if (command === 'drive')
192
224
  return drive(config, positional, flags, values);
193
225
  if (command === 'skill')
@@ -0,0 +1,21 @@
1
+ import { type Loaded } from './config.ts';
2
+ import { type Decision } from './knowledge/decisions.ts';
3
+ export declare const DECIDE_VERSION = 1;
4
+ export interface DecideInput {
5
+ text: string;
6
+ areas: readonly string[];
7
+ by: string;
8
+ kind?: string;
9
+ date?: string;
10
+ dryRun?: boolean;
11
+ }
12
+ export interface DecideReport {
13
+ version: typeof DECIDE_VERSION;
14
+ file: string;
15
+ wrote: boolean;
16
+ line: string;
17
+ decision: Decision;
18
+ }
19
+ export declare const today: (now?: Date) => string;
20
+ export declare function decide(config: Loaded, input: DecideInput): DecideReport;
21
+ export declare function decideText(report: DecideReport): string;
package/dist/decide.js ADDED
@@ -0,0 +1,131 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ import { AshlarError } from './config.js';
4
+ import { areasOf } from './knowledge/areas.js';
5
+ import { DECISION_KINDS, EVERYWHERE, HANDLE, isDate, parseDecisions, } from './knowledge/decisions.js';
6
+ import { secretsIn } from './knowledge/secrets.js';
7
+ import { tidy } from './layout.js';
8
+ export const DECIDE_VERSION = 1;
9
+ const pad = (n) => String(n).padStart(2, '0');
10
+ export const today = (now = new Date()) => `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
11
+ const isKind = (kind) => DECISION_KINDS.includes(kind);
12
+ function textOf(given) {
13
+ const text = given.trim();
14
+ if (text === '')
15
+ throw new AshlarError('Say what was decided, in one line.');
16
+ if (/[\r\n\u2028\u2029]/.test(text)) {
17
+ throw new AshlarError('A decision is one line: say it without line breaks, or record each part on its own.');
18
+ }
19
+ const secret = secretsIn(text)[0];
20
+ if (secret) {
21
+ throw new AshlarError(`What was decided holds what looks like ${secret.kind}. Secrets never enter the decisions file: say who grants access instead, as an \`access\` line, never the credential.`, 'secret');
22
+ }
23
+ return text;
24
+ }
25
+ function areaOf(given) {
26
+ const area = given.trim();
27
+ if (area === EVERYWHERE)
28
+ return EVERYWHERE;
29
+ if (/[[\],]/.test(area)) {
30
+ throw new AshlarError(`An area is a folder, a file or *, with no brackets or commas: ${area} isn't one.`);
31
+ }
32
+ const path = tidy(area);
33
+ if (path.startsWith('/') || /^[A-Za-z]:/.test(path) || path === '..' || path.startsWith('../')) {
34
+ throw new AshlarError(`${area} lies outside the repository: name it from the repository's root.`);
35
+ }
36
+ if (path === '')
37
+ throw new AshlarError('Name the area as a folder or a file, or * for everywhere.');
38
+ return path;
39
+ }
40
+ function namedAs(root, path) {
41
+ let folder = root;
42
+ for (const part of path.split('/')) {
43
+ if (!statSync(folder, { throwIfNoEntry: false })?.isDirectory())
44
+ return false;
45
+ if (!readdirSync(folder).includes(part))
46
+ return false;
47
+ folder = join(folder, part);
48
+ }
49
+ return true;
50
+ }
51
+ function areasFor(config, given) {
52
+ const areas = [...new Set(given.map(areaOf))];
53
+ if (areas.length === 0) {
54
+ throw new AshlarError('Name the areas it covers: folders, files, or * for everywhere.');
55
+ }
56
+ const guide = areasOf(config).map((area) => area.path);
57
+ const unknown = areas.filter((area) => area !== EVERYWHERE && !guide.includes(area) && !namedAs(config.root, area));
58
+ if (unknown.length > 0) {
59
+ const named = guide.length > 0 ? `one of the guide's areas (${guide.join(', ')}), ` : '';
60
+ throw new AshlarError(`${unknown.join(', ')} ${unknown.length === 1 ? 'is' : 'are'} no area of the guide, and no folder or file in this repository. Name ${named}a folder or a file, or * for everywhere.`);
61
+ }
62
+ return areas;
63
+ }
64
+ function byOf(given) {
65
+ const by = given.trim();
66
+ if (!HANDLE.test(by)) {
67
+ throw new AshlarError(`Say who decided as a handle, such as @robin: ${by || 'nothing'} isn't one.`);
68
+ }
69
+ return by;
70
+ }
71
+ function kindOf(given) {
72
+ const kind = given === undefined ? 'decision' : given.trim();
73
+ if (!isKind(kind))
74
+ throw new AshlarError(`A decision's kind is one of ${DECISION_KINDS.join(', ')}: not ${kind || 'nothing'}.`);
75
+ return kind;
76
+ }
77
+ function dateOf(given) {
78
+ const date = given === undefined ? today() : given.trim();
79
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || !isDate(date)) {
80
+ throw new AshlarError(`Give the date as 2026-12-03: ${date || 'nothing'} isn't one.`);
81
+ }
82
+ return date;
83
+ }
84
+ const sameAreas = (a, b) => a.length === b.length && [...a].sort().join('\n') === [...b].sort().join('\n');
85
+ function appended(existing, line) {
86
+ if (existing === null)
87
+ return `# Decisions\n\n${line}\n`;
88
+ if (existing === '')
89
+ return `${line}\n`;
90
+ const eol = existing.includes('\r\n') ? '\r\n' : '\n';
91
+ const ended = existing.endsWith('\n') ? existing : `${existing}${eol}`;
92
+ const last = ended.split(/\r?\n/).at(-2)?.trimEnd() ?? '';
93
+ const gap = last === '' || last.startsWith('- ') ? '' : eol;
94
+ return `${ended}${gap}${line}${eol}`;
95
+ }
96
+ export function decide(config, input) {
97
+ const text = textOf(input.text);
98
+ const by = byOf(input.by);
99
+ const kind = kindOf(input.kind);
100
+ const date = dateOf(input.date);
101
+ const areas = areasFor(config, input.areas);
102
+ const file = config.onboard.decisions;
103
+ const path = join(config.root, file);
104
+ const existing = existsSync(path) ? readFileSync(path, 'utf8') : null;
105
+ const before = existing === null ? [] : parseDecisions(existing, file);
106
+ const same = before.find((decision) => decision.kind === kind && decision.text === text && sameAreas(decision.areas, areas));
107
+ if (same)
108
+ throw new AshlarError(`${file}:${same.line} already records this ${kind}.`, 'decisions', {
109
+ file,
110
+ line: same.line,
111
+ });
112
+ const line = `- ${date} ${by} [${areas.join(', ')}] ${kind}: ${text}`;
113
+ const next = appended(existing, line);
114
+ const at = next.split('\n').length - 1;
115
+ const decision = parseDecisions(next, file).find((read) => read.line === at);
116
+ if (!decision || decision.text !== text || decision.kind !== kind || !sameAreas(decision.areas, areas)) {
117
+ throw new AshlarError(`${file} wouldn't read the new line back as a decision: does it end inside a code block?`, 'decisions', { file });
118
+ }
119
+ if (!input.dryRun) {
120
+ mkdirSync(dirname(path), { recursive: true });
121
+ writeFileSync(path, next);
122
+ }
123
+ return { version: DECIDE_VERSION, file, wrote: !input.dryRun, line, decision };
124
+ }
125
+ export function decideText(report) {
126
+ const where = `${report.file}, at line ${report.decision.line}`;
127
+ const said = report.wrote
128
+ ? `Wrote a decision to ${where}:`
129
+ : `Would write a decision to ${where}, and wrote nothing:`;
130
+ return `${said}\n${report.line}\n`;
131
+ }
package/dist/errors.js CHANGED
@@ -2,6 +2,7 @@ import { realpathSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { isAbsolute, relative } from 'node:path';
4
4
  import { AshlarError } from './config.js';
5
+ import { tidy } from './layout.js';
5
6
  const here = () => ({ cwd: process.cwd(), home: homedir() });
6
7
  function spellings(folder) {
7
8
  let real = folder;
@@ -12,15 +13,15 @@ function spellings(folder) {
12
13
  real = folder;
13
14
  }
14
15
  return [...new Set([folder, real])]
15
- .filter((path) => path !== '' && path !== '/')
16
+ .filter((path) => path !== '' && path !== '/' && !/^[A-Za-z]:\\?$/.test(path))
16
17
  .sort((a, b) => b.length - a.length);
17
18
  }
18
19
  const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
19
20
  function replaced(text, folder, inside, whole) {
20
21
  const name = escaped(folder);
21
22
  return text
22
- .replace(new RegExp(`${name}/`, 'g'), inside)
23
- .replace(new RegExp(`${name}(?![\\w./-])`, 'g'), whole);
23
+ .replace(new RegExp(`${name}[/\\\\]`, 'g'), inside)
24
+ .replace(new RegExp(`${name}(?![\\w./\\\\-])`, 'g'), whole);
24
25
  }
25
26
  export function scrubbed(text, places = here()) {
26
27
  let out = text;
@@ -34,7 +35,7 @@ function shownFile(file, places) {
34
35
  if (!isAbsolute(file))
35
36
  return file;
36
37
  const inside = relative(places.cwd, file);
37
- return inside && !inside.startsWith('..') && !isAbsolute(inside) ? inside : scrubbed(file, places);
38
+ return inside && !inside.startsWith('..') && !isAbsolute(inside) ? tidy(inside) : scrubbed(file, places);
38
39
  }
39
40
  export function errorJson(error, places = here()) {
40
41
  if (!(error instanceof AshlarError)) {
@@ -4,7 +4,7 @@ import { isGlob } from '../glob.js';
4
4
  import { tidy, within } from '../layout.js';
5
5
  import { nameOfFolder } from '../map.js';
6
6
  import { byText } from '../order.js';
7
- import { EVERYWHERE } from './decisions.js';
7
+ import { EVERYWHERE, HANDLE } from './decisions.js';
8
8
  const isFolder = (path) => statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
9
9
  function foldersOf(config, pattern) {
10
10
  if (!pattern.endsWith('/*'))
@@ -59,7 +59,6 @@ export function isCrossCutting(rule) {
59
59
  export function decisionCovers(decision, path) {
60
60
  return decision.areas.some((area) => overlaps(area, path));
61
61
  }
62
- const HANDLE = /^@[A-Za-z0-9][\w.-]*$/;
63
62
  export function ownerOf(config, decisions, path) {
64
63
  for (const [folder, handle] of config.onboard.owners) {
65
64
  if (within(path, folder))
@@ -10,5 +10,7 @@ export interface Decision {
10
10
  }
11
11
  export declare const EVERYWHERE = "*";
12
12
  export declare const DECISION_SHAPE = "- 2026-12-03 @owner [area, another/area] kind: what was decided";
13
+ export declare const HANDLE: RegExp;
14
+ export declare const isDate: (date: string) => boolean;
13
15
  export declare function parseDecisions(text: string, file: string): Decision[];
14
16
  export declare function readDecisions(root: string, file: string): Decision[];
@@ -6,7 +6,8 @@ export const DECISION_KINDS = ['decision', 'rule', 'trust', 'access', 'owner', '
6
6
  export const EVERYWHERE = '*';
7
7
  const LINE = /^- (\d{4}-\d{2}-\d{2}) (@[A-Za-z0-9][\w.-]*) \[([^\]]+)\] (?:(decision|rule|trust|access|owner|setup): )?(\S.*)$/;
8
8
  export const DECISION_SHAPE = '- 2026-12-03 @owner [area, another/area] kind: what was decided';
9
- const isDate = (date) => {
9
+ export const HANDLE = /^@[A-Za-z0-9][\w.-]*$/;
10
+ export const isDate = (date) => {
10
11
  const at = new Date(`${date}T00:00:00Z`);
11
12
  return !Number.isNaN(at.getTime()) && at.toISOString().slice(0, 10) === date;
12
13
  };
@@ -5,7 +5,7 @@ import { byText } from '../order.js';
5
5
  import { walkFolders } from '../workspace.js';
6
6
  const unquoted = (value) => value.replace(/^(['"])(.*)\1$/, '$2');
7
7
  export function topField(text, key) {
8
- const lines = text.split('\n');
8
+ const lines = text.split(/\r?\n/);
9
9
  const at = lines.findIndex((line) => line.startsWith(`${key}:`));
10
10
  if (at === -1)
11
11
  return null;
@@ -39,7 +39,7 @@ function listOf(value) {
39
39
  return inner ? [unquoted(inner)] : [];
40
40
  }
41
41
  function frontOf(text, file) {
42
- const lines = text.split('\n');
42
+ const lines = text.split(/\r?\n/);
43
43
  if (lines[0]?.trim() !== FENCE)
44
44
  return { values: new Map(), paths: null, body: text };
45
45
  const end = lines.findIndex((line, i) => i > 0 && line.trim() === FENCE);
package/dist/mcp.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { Readable, Writable } from 'node:stream';
2
2
  import { type Loaded } from './config.ts';
3
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.";
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, check before you push, and record what a person decides with decide: the skill at skill/ashlar/SKILL.md in the package teaches the loop.";
5
5
  type Kind = 'boolean' | 'string' | 'paths';
6
6
  interface Argument {
7
7
  kind: Kind;
8
8
  description: string;
9
+ values?: readonly string[];
9
10
  }
10
11
  interface Answer {
11
12
  json: object;
@@ -17,6 +18,7 @@ interface Tool {
17
18
  args: Record<string, Argument>;
18
19
  required?: string[];
19
20
  readOnly: boolean;
21
+ idempotent?: boolean;
20
22
  run?: (config: Loaded, args: Record<string, unknown>) => Answer;
21
23
  start?: (args: Record<string, unknown>, cwd: string) => Answer;
22
24
  }
package/dist/mcp.js CHANGED
@@ -2,10 +2,12 @@ import { readFileSync } from 'node:fs';
2
2
  import { createInterface } from 'node:readline';
3
3
  import { affectedAnswer, briefAnswer, checkAnswer, mapAnswer, onboardAnswer } from './answers.js';
4
4
  import { AshlarError, loadConfig } from './config.js';
5
+ import { decide } from './decide.js';
5
6
  import { errorJson } from './errors.js';
6
7
  import { init } from './init.js';
8
+ import { DECISION_KINDS } from './knowledge/decisions.js';
7
9
  export const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26'];
8
- 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.';
10
+ 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, check before you push, and record what a person decides with decide: the skill at skill/ashlar/SKILL.md in the package teaches the loop.';
9
11
  const paths = (args, name) => args[name] ?? [];
10
12
  const flag = (args, name) => args[name] === true;
11
13
  const text = (args, name) => args[name];
@@ -83,6 +85,38 @@ export const TOOLS = [
83
85
  readOnly: false,
84
86
  run: (config, args) => ({ json: onboardAnswer(config, flag(args, 'check')) }),
85
87
  },
88
+ {
89
+ name: 'decide',
90
+ description: 'Records one decision a person made: adds a well-formed line to the decisions file the config names, so it is proposed in a pull request rather than written by hand. It refuses an area that is neither one of the guide’s areas nor a folder or file in the repository, a secret, and a decision the file already holds. With dryRun, answers with the line it would write, and writes nothing. Answers with decide.v1.json.',
91
+ args: {
92
+ text: { kind: 'string', description: 'What was decided, in one line, in the person’s words.' },
93
+ areas: {
94
+ kind: 'paths',
95
+ description: 'The guide’s areas, folders or files it covers, or * for everywhere.',
96
+ },
97
+ by: { kind: 'string', description: 'Who decided, as a handle such as @robin.' },
98
+ kind: {
99
+ kind: 'string',
100
+ description: 'What kind of line it is: decision, unless given.',
101
+ values: DECISION_KINDS,
102
+ },
103
+ date: { kind: 'string', description: 'The day it was decided, as 2026-12-03: today, unless given.' },
104
+ dryRun: { kind: 'boolean', description: 'Answer with the line it would write, and write nothing.' },
105
+ },
106
+ required: ['text', 'areas', 'by'],
107
+ readOnly: false,
108
+ idempotent: false,
109
+ run: (config, args) => ({
110
+ json: decide(config, {
111
+ text: text(args, 'text'),
112
+ areas: paths(args, 'areas'),
113
+ by: text(args, 'by'),
114
+ kind: text(args, 'kind'),
115
+ date: text(args, 'date'),
116
+ dryRun: flag(args, 'dryRun'),
117
+ }),
118
+ }),
119
+ },
86
120
  ];
87
121
  const SCHEMA_DIR = new URL('../schema/', import.meta.url);
88
122
  export function outputSchemaOf(name) {
@@ -93,7 +127,7 @@ function inputSchemaOf(tool) {
93
127
  name,
94
128
  arg.kind === 'paths'
95
129
  ? { type: 'array', items: { type: 'string' }, description: arg.description }
96
- : { type: arg.kind, description: arg.description },
130
+ : { type: arg.kind, ...(arg.values ? { enum: arg.values } : {}), description: arg.description },
97
131
  ]));
98
132
  return {
99
133
  type: 'object',
@@ -111,7 +145,7 @@ export function toolList() {
111
145
  annotations: {
112
146
  readOnlyHint: tool.readOnly,
113
147
  ...(tool.readOnly ? {} : { destructiveHint: false }),
114
- idempotentHint: true,
148
+ idempotentHint: tool.idempotent ?? true,
115
149
  openWorldHint: false,
116
150
  },
117
151
  }));
@@ -1,4 +1,4 @@
1
- import type { Loaded } from '../config.ts';
1
+ import { type Loaded } from '../config.ts';
2
2
  import { type Area } from '../knowledge/areas.ts';
3
3
  import type { Decision } from '../knowledge/decisions.ts';
4
4
  import type { FolderRule } from '../knowledge/rules.ts';
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
+ import { AshlarError } from '../config.js';
3
4
  import { ownerOf } from '../knowledge/areas.js';
4
5
  import { areaPage, GENERATED, guideOf } from './guide.js';
5
6
  import { knowledgeOf } from './model.js';
@@ -26,6 +27,16 @@ export function onboard(config, options = {}) {
26
27
  const questions = questionsOf(config, knowledge);
27
28
  const files = guideOf(config, knowledge, questions);
28
29
  const out = config.onboard.out;
30
+ const ours = generatedIn(config.root, out);
31
+ const theirs = [...files.keys()].filter((path) => {
32
+ const file = join(config.root, out, path);
33
+ return existsSync(file) && !readFileSync(file, 'utf8').includes(GENERATED);
34
+ });
35
+ const present = [...files.keys()].some((path) => ours.includes(path));
36
+ if (!options.check && !present && theirs.length > 0) {
37
+ const named = theirs.map((path) => `${out}/${path}`);
38
+ throw new AshlarError(`${named.join(', ')} ${named.length === 1 ? "isn't" : "aren't"} part of the guide, and \`ashlar onboard\` would write over ${named.length === 1 ? 'it' : 'them'}. Move ${named.length === 1 ? 'it' : 'them'}, or point \`onboard.out\` at a folder of the guide's own.`, 'refused', { file: named[0] });
39
+ }
29
40
  const stale = [];
30
41
  const written = [];
31
42
  for (const [path, text] of files) {
@@ -39,7 +50,7 @@ export function onboard(config, options = {}) {
39
50
  writeFileSync(file, text);
40
51
  written.push(path);
41
52
  }
42
- const removed = generatedIn(config.root, out).filter((path) => !files.has(path));
53
+ const removed = ours.filter((path) => !files.has(path));
43
54
  if (!options.check)
44
55
  for (const path of removed)
45
56
  rmSync(join(config.root, out, path));
@@ -12,8 +12,8 @@ export interface DriveOptions {
12
12
  scheme: Scheme | null;
13
13
  stepMs?: number;
14
14
  }
15
- export declare const shellQuote: (arg: string) => string;
16
- export declare const driveLine: (drive: string, args: readonly string[]) => string;
15
+ export declare const shellQuote: (arg: string, platform?: NodeJS.Platform) => string;
16
+ export declare const driveLine: (drive: string, args: readonly string[], platform?: NodeJS.Platform) => string;
17
17
  export declare function driveOf(config: Loaded): string;
18
18
  export declare const OUTPUT_MB = 64;
19
19
  export declare const RAN_WORDS: {
@@ -8,8 +8,27 @@ export const isScheme = (v) => typeof v === 'string' && SCHEMES.includes(v);
8
8
  export { SCHEME_VARIABLE };
9
9
  export const STEP_MS = 60_000;
10
10
  const BARE = /^[A-Za-z0-9_./:=@%+,-]+$/;
11
- export const shellQuote = (arg) => BARE.test(arg) ? arg : `'${arg.replaceAll("'", `'\\''`)}'`;
12
- export const driveLine = (drive, args) => [drive.trim(), ...args.map(shellQuote)].join(' ');
11
+ const BARE_ON_WINDOWS = /^[A-Za-z0-9_./:@+\\-]+$/;
12
+ const CMD_META = /([()\][%!^"`<>&|;, *?])/g;
13
+ function cmdQuote(arg) {
14
+ let quoted = '"';
15
+ let slashes = 0;
16
+ for (const char of arg) {
17
+ if (char === '\\') {
18
+ slashes += 1;
19
+ continue;
20
+ }
21
+ quoted += char === '"' ? `${'\\'.repeat(slashes * 2 + 1)}"` : `${'\\'.repeat(slashes)}${char}`;
22
+ slashes = 0;
23
+ }
24
+ return `${quoted}${'\\'.repeat(slashes * 2)}"`.replace(CMD_META, '^$1');
25
+ }
26
+ export const shellQuote = (arg, platform = process.platform) => {
27
+ if (platform === 'win32')
28
+ return BARE_ON_WINDOWS.test(arg) ? arg : cmdQuote(arg);
29
+ return BARE.test(arg) ? arg : `'${arg.replaceAll("'", `'\\''`)}'`;
30
+ };
31
+ export const driveLine = (drive, args, platform = process.platform) => [drive.trim(), ...args.map((arg) => shellQuote(arg, platform))].join(' ');
13
32
  export function driveOf(config) {
14
33
  const drive = driveCommandOf(config);
15
34
  if (drive)
@@ -86,7 +105,8 @@ function spawnDrive(config, args, options) {
86
105
  const line = driveLine(driveOf(config), [...args, '--json']);
87
106
  const env = options.scheme ? { ...process.env, [SCHEME_VARIABLE]: options.scheme } : process.env;
88
107
  const started = performance.now();
89
- const run = spawnSync('/bin/sh', ['-c', line], {
108
+ const run = spawnSync(line, {
109
+ shell: true,
90
110
  cwd: config.root,
91
111
  encoding: 'utf8',
92
112
  env,
package/dist/resolve.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { statSync } from 'node:fs';
2
- import { join, posix } from 'node:path';
2
+ import { join, posix, relative } from 'node:path';
3
3
  import { tidy, within } from './layout.js';
4
4
  const EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.d.ts', '.js', '.jsx', '.mjs', '.cjs', '.json'];
5
5
  const SWAPS = {
@@ -105,7 +105,7 @@ export function makeResolver(root, workspace) {
105
105
  if (specifier.startsWith('.'))
106
106
  found = fileAt(tidy(posix.join(folder, specifier)));
107
107
  else if (specifier.startsWith('/'))
108
- found = fileAt(tidy(posix.relative(root, specifier)));
108
+ found = fileAt(tidy(relative(root, specifier)));
109
109
  else if (!specifier.startsWith('node:') && specifier !== '')
110
110
  found = bare(from, specifier);
111
111
  answers.set(key, found);
package/dist/skill.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
2
- import { dirname, join, relative } from 'node:path';
2
+ import { dirname, isAbsolute, join, relative } from 'node:path';
3
3
  import { AshlarError } from './config.js';
4
4
  import { PACKAGE } from './identity.js';
5
5
  import { ashlarRun, rehearseRun } from './runner.js';
@@ -154,13 +154,15 @@ export function onboardSkill(ashlar, decisions = 'DECISIONS.md', rules = '.claud
154
154
  '',
155
155
  '## When a person decides something',
156
156
  '',
157
- `When a person tells you how something should be done, and it should outlive your task, add one line to`,
158
- `\`${decisions}\` with today's date, their handle, the area and the kind:`,
157
+ `When a person tells you how something should be done, and it should outlive your task, record it with`,
158
+ `\`${ashlar} decide\`, in their words, with their handle, the area and the kind:`,
159
159
  '',
160
- '```markdown',
161
- '- 2026-12-03 @their-handle [src/area] rule: What they decided, in their words.',
160
+ '```sh',
161
+ `${ashlar} decide "What they decided, in their words." --areas src/area --by @their-handle --kind rule`,
162
162
  '```',
163
163
  '',
164
+ `It adds one line to \`${decisions}\` with today's date, and prints it. Commit it with your change.`,
165
+ '',
164
166
  'Add a line only on a person’s word, never on your own guess. The kinds are `decision`, `rule`, `trust`',
165
167
  '(a document is current), `access` (who grants access to what, never a credential), `owner` (the text is',
166
168
  'the owner’s handle) and `setup` (how to run something).',
@@ -192,7 +194,7 @@ export function skillText(name, config) {
192
194
  }
193
195
  function inside(root, path) {
194
196
  const from = relative(root, path);
195
- return from === '' || (!from.startsWith('..') && !from.startsWith('/'));
197
+ return from === '' || (!from.startsWith('..') && !isAbsolute(from));
196
198
  }
197
199
  function nearest(path) {
198
200
  let at = path;
package/dist/usage.d.ts CHANGED
@@ -1 +1 @@
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>] [--gate] [--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 --gate prints the gate answer a pull request report reads instead: ok, a one-line summary, the\n rules that moved, and each count that rose as an error on the lines the change wrote.\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";
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>] [--gate] [--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 --gate prints the gate answer a pull request report reads instead: ok, a one-line summary, the\n rules that moved, and each count that rose as an error on the lines the change wrote.\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 decide <what> --areas <areas> --by <@handle> [--kind <kind>] [--date <date>] [--dry-run] [--json]\n Adds one decision line to the decisions file the config names, DECISIONS.md unless onboard.decisions\n says otherwise, so an agent proposes what a person decided in a pull request. --areas takes the\n guide's areas, folders or files, separated by commas, or * for everywhere. --kind is decision,\n rule, trust, access, owner or setup, decision unless given, and --date is today unless given.\n It refuses an area it can't find, a secret, and a decision the file already holds. --dry-run\n prints the line it would write, and writes nothing.\n ashlar mcp\n Serves init, brief, check, affected, map, onboard and decide as MCP tools on stdio, for agents.\n Each tool 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
@@ -40,9 +40,16 @@ export const USAGE = `Usage:
40
40
  Prints what an agent needs before it changes those files: the data rules, the rules that apply
41
41
  there, the folder rules and gotchas, the decisions, the features and the open questions. Never
42
42
  access lines, and never a secret-shaped value.
43
+ ashlar decide <what> --areas <areas> --by <@handle> [--kind <kind>] [--date <date>] [--dry-run] [--json]
44
+ Adds one decision line to the decisions file the config names, DECISIONS.md unless onboard.decisions
45
+ says otherwise, so an agent proposes what a person decided in a pull request. --areas takes the
46
+ guide's areas, folders or files, separated by commas, or * for everywhere. --kind is decision,
47
+ rule, trust, access, owner or setup, decision unless given, and --date is today unless given.
48
+ It refuses an area it can't find, a secret, and a decision the file already holds. --dry-run
49
+ prints the line it would write, and writes nothing.
43
50
  ashlar mcp
44
- Serves init, brief, check, affected, map and onboard as MCP tools on stdio, for agents. Each tool
45
- takes its command's options and answers with the object its command prints with --json.
51
+ Serves init, brief, check, affected, map, onboard and decide as MCP tools on stdio, for agents.
52
+ Each tool takes its command's options and answers with the object its command prints with --json.
46
53
  ashlar snapshot [--json]
47
54
  Prints where things stand today: the ratchet, the map, the decisions and questions, and each
48
55
  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.8.2",
3
+ "version": "1.9.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",
@@ -63,7 +63,7 @@
63
63
  "vitest": "^3.2.7"
64
64
  },
65
65
  "scripts": {
66
- "build": "rm -rf dist && tsc -p tsconfig.build.json",
66
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
67
67
  "typecheck": "tsc --noEmit",
68
68
  "test": "vitest run",
69
69
  "lint": "node scripts/private-names.ts && node scripts/docs-check.ts && prettier --check . && oxlint src scripts docs/scripts && node src/cli.ts check && node src/cli.ts onboard --check",
@@ -0,0 +1,43 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/kurvball/ashlar/blob/main/schema/decide.v1.json",
4
+ "title": "ashlar decide --json",
5
+ "description": "The one decision line Ashlar added to the decisions file, and where.",
6
+ "type": "object",
7
+ "required": ["version", "file", "wrote", "line", "decision"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "version": { "const": 1 },
11
+ "file": {
12
+ "type": "string",
13
+ "description": "The decisions file, from the repository's root, as onboard.decisions names it."
14
+ },
15
+ "wrote": {
16
+ "type": "boolean",
17
+ "description": "Whether it added the line: false with --dry-run."
18
+ },
19
+ "line": {
20
+ "type": "string",
21
+ "description": "The line as it is written in the file."
22
+ },
23
+ "decision": {
24
+ "type": "object",
25
+ "description": "The line as Ashlar reads it back.",
26
+ "required": ["line", "date", "owner", "areas", "kind", "text"],
27
+ "additionalProperties": false,
28
+ "properties": {
29
+ "line": { "type": "integer", "minimum": 1, "description": "Its line number in the file." },
30
+ "date": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
31
+ "owner": { "type": "string", "description": "Who decided, as a handle such as @robin." },
32
+ "areas": {
33
+ "type": "array",
34
+ "minItems": 1,
35
+ "items": { "type": "string" },
36
+ "description": "The folders or files it covers, or * for everywhere."
37
+ },
38
+ "kind": { "enum": ["decision", "rule", "trust", "access", "owner", "setup"] },
39
+ "text": { "type": "string" }
40
+ }
41
+ }
42
+ }
43
+ }
@@ -55,12 +55,27 @@ writes nothing. Show a person the config before you commit it.
55
55
  5. **Lower the baseline when you fixed breaks.** When `slack` is above zero, run `check` with
56
56
  `{ "shrink": true }` (`ashlar check --shrink`) and commit `ashlar.baseline.json` with the fix.
57
57
 
58
+ ## When a person decides something
59
+
60
+ When a person tells you how something should be done, and it should outlive your task, record it as one
61
+ decision, in their words, with their handle:
62
+
63
+ - Tool: `decide` with `{ "text": "Prices are whole cents.", "areas": ["src/cart"], "by": "@robin", "kind": "rule" }`.
64
+ - Command: `ashlar decide "Prices are whole cents." --areas src/cart --by @robin --kind rule --json`.
65
+
66
+ It adds the line to the decisions file the config names, and answers with the `line` it wrote and where.
67
+ Commit it in your pull request, so people review the decision with the change. An area is one of the guide's
68
+ areas, a folder or a file, or `*` for everywhere. The `kind` is `decision` unless you give one: `rule` (what an
69
+ agent must do there), `trust` (a document is current), `access` (who grants access, never a credential),
70
+ `owner` (the text is the owner's handle) or `setup` (how to run something). Record only what a person decided,
71
+ never your own guess.
72
+
58
73
  ## Rules
59
74
 
60
75
  - Never raise the baseline yourself. `acceptRise` (`--accept-rise`) takes a rise in for good: ask a person
61
76
  first, and say which rule and file.
62
77
  - Never edit `ashlar.baseline.json` or the onboarding guide by hand. `check --shrink` writes the baseline, and
63
- `onboard` writes the guide.
78
+ `onboard` writes the guide. Add a decision with `decide`, not by editing the decisions file.
64
79
  - Never turn a rule off with a comment: there is no such comment. A rule is turned off only in
65
80
  `ashlar.config.ts`, by a person.
66
81
  - When `onboard` with `{ "check": true }` answers `ok: false`, the guide is stale: run `onboard` and commit