@kurvball/ashlar 1.6.0 → 1.7.1

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.7.1
10
+
11
+ _Released 2026-12-04._
12
+
13
+ ### Patch Changes
14
+
15
+ - What Ashlar says when it refuses carries no home folder, on stderr and in the error object's `says` and `file` alike: a path in the folder it runs in shows from there (the folder itself as "this folder"), a path in the home folder shows from `~`, and any other path stays whole.
16
+
17
+ ## 1.7.0
18
+
19
+ _Released 2026-12-04._
20
+
21
+ ### Minor Changes
22
+
23
+ - With `--json`, a command that can't do what it was asked prints the error object on stdout, `{ v: 1, ok: false, error: { code, says, file?, line? } }`, in `schema/error.v1.json`: the same shape as Rehearse's and Marquee's refusals. Its exit code is unchanged, 2. An MCP tool's refusal carries the same object. Without `--json`, the sentence still goes to stderr.
24
+
9
25
  ## 1.6.0
10
26
 
11
27
  _Released 2026-12-04._
package/dist/baseline.js CHANGED
@@ -31,10 +31,10 @@ export function readBaseline(file) {
31
31
  counts = JSON.parse(readFileSync(file, 'utf8'));
32
32
  }
33
33
  catch (error) {
34
- throw new AshlarError(BASELINE_WORDS.unreadable(file, error.message));
34
+ throw new AshlarError(BASELINE_WORDS.unreadable(file, error.message), 'baseline', { file });
35
35
  }
36
36
  if (isPerFolder(counts))
37
- throw new AshlarError(BASELINE_WORDS.perFolder(file));
37
+ throw new AshlarError(BASELINE_WORDS.perFolder(file), 'baseline', { file });
38
38
  return counts;
39
39
  }
40
40
  export function tidyCounts(counts) {
package/dist/cli.js CHANGED
@@ -4,6 +4,7 @@ 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
6
  import { init, initText } from './init.js';
7
+ import { errorJson, scrubbed } from './errors.js';
7
8
  import { serve } from './mcp.js';
8
9
  import { featuresOf, unreadText } from './features.js';
9
10
  import { ledgerOf, ledgerText } from './ledger.js';
@@ -216,8 +217,19 @@ try {
216
217
  process.exitCode = await main(process.argv.slice(2));
217
218
  }
218
219
  catch (error) {
219
- if (!(error instanceof AshlarError))
220
- throw error;
221
- process.stderr.write(`${error.message}\n`);
222
- process.exitCode = 2;
220
+ const json = process.argv.slice(2).includes('--json');
221
+ if (!(error instanceof AshlarError)) {
222
+ if (!json)
223
+ throw error;
224
+ process.stderr.write(`${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`);
225
+ process.stdout.write(`${JSON.stringify(errorJson(error), null, 2)}\n`);
226
+ process.exitCode = 1;
227
+ }
228
+ else {
229
+ if (json)
230
+ process.stdout.write(`${JSON.stringify(errorJson(error), null, 2)}\n`);
231
+ else
232
+ process.stderr.write(`${scrubbed(error.message)}\n`);
233
+ process.exitCode = 2;
234
+ }
223
235
  }
package/dist/config.d.ts CHANGED
@@ -76,7 +76,16 @@ export declare const CONFIG_FILE = "ashlar.config.ts";
76
76
  export declare const CONFIG_FILES: string[];
77
77
  export declare const DEFAULT_IGNORE: string[];
78
78
  export declare const DEFAULT_TESTS: string[];
79
+ export declare const ERROR_CODES: readonly ['usage', 'config', 'baseline', 'git', 'lint', 'rules', 'decisions', 'secret', 'drive', 'refused'];
80
+ export type ErrorCode = (typeof ERROR_CODES)[number];
79
81
  export declare class AshlarError extends Error {
82
+ readonly code: ErrorCode;
83
+ readonly file: string | undefined;
84
+ readonly line: number | undefined;
85
+ constructor(says: string, code?: ErrorCode, at?: {
86
+ file?: string;
87
+ line?: number;
88
+ });
80
89
  }
81
90
  export declare function defineConfig(config: AshlarConfig): AshlarConfig;
82
91
  export declare function findConfig(from: string): string | null;
package/dist/config.js CHANGED
@@ -21,7 +21,28 @@ export const CONFIG_FILE = 'ashlar.config.ts';
21
21
  export const CONFIG_FILES = [CONFIG_FILE, 'ashlar.config.mts', 'ashlar.config.js', 'ashlar.config.mjs'];
22
22
  export const DEFAULT_IGNORE = ['node_modules', 'out', 'dist', 'release'];
23
23
  export const DEFAULT_TESTS = ['.test.ts', '.test.tsx'];
24
+ export const ERROR_CODES = [
25
+ 'usage',
26
+ 'config',
27
+ 'baseline',
28
+ 'git',
29
+ 'lint',
30
+ 'rules',
31
+ 'decisions',
32
+ 'secret',
33
+ 'drive',
34
+ 'refused',
35
+ ];
24
36
  export class AshlarError extends Error {
37
+ code;
38
+ file;
39
+ line;
40
+ constructor(says, code = 'usage', at = {}) {
41
+ super(says);
42
+ this.code = code;
43
+ this.file = at.file;
44
+ this.line = at.line;
45
+ }
25
46
  }
26
47
  export function defineConfig(config) {
27
48
  return config;
@@ -41,7 +62,7 @@ export function findConfig(from) {
41
62
  export function settle(config, root, file = CONFIG_FILE) {
42
63
  const problems = checkConfig(config);
43
64
  if (problems.length > 0) {
44
- throw new AshlarError(`${file} doesn't read:\n${problems.map((line) => ` ${line}`).join('\n')}`);
65
+ throw new AshlarError(`${file} doesn't read:\n${problems.map((line) => ` ${line}`).join('\n')}`, 'config', { file });
45
66
  }
46
67
  return {
47
68
  root,
@@ -78,7 +99,7 @@ function onboardOf(onboard) {
78
99
  function confinedOf(entry) {
79
100
  const words = (entry.words ?? []).map((word) => word.trim()).filter(Boolean);
80
101
  if (words.length === 0 || !entry.message?.trim()) {
81
- throw new AshlarError(`Each of ${CONFIG_FILE}'s confined names needs its words and the message agents read.`);
102
+ throw new AshlarError(`Each of ${CONFIG_FILE}'s confined names needs its words and the message agents read.`, 'config');
82
103
  }
83
104
  return {
84
105
  words,
@@ -90,10 +111,10 @@ function confinedOf(entry) {
90
111
  export async function loadConfig(from = process.cwd()) {
91
112
  const file = findConfig(from);
92
113
  if (!file)
93
- throw new AshlarError(`There is no ${CONFIG_FILE} in ${resolve(from)} or above it.`);
114
+ throw new AshlarError(`There is no ${CONFIG_FILE} in ${resolve(from)} or above it.`, 'config');
94
115
  const fresh = `${pathToFileURL(file).href}?v=${statSync(file).mtimeMs}`;
95
116
  const loaded = (await import(__rewriteRelativeImportExtension(fresh)));
96
117
  if (!loaded.default)
97
- throw new AshlarError(`${file} has no default export: export its config.`);
118
+ throw new AshlarError(`${file} has no default export: export its config.`, 'config', { file });
98
119
  return settle(loaded.default, realpathSync(dirname(file)), basename(file));
99
120
  }
@@ -0,0 +1,17 @@
1
+ import { type ErrorCode } from './config.ts';
2
+ export interface ErrorJson {
3
+ v: 1;
4
+ ok: false;
5
+ error: {
6
+ code: ErrorCode | 'crashed';
7
+ says: string;
8
+ file?: string;
9
+ line?: number;
10
+ };
11
+ }
12
+ export interface Places {
13
+ cwd: string;
14
+ home: string;
15
+ }
16
+ export declare function scrubbed(text: string, places?: Places): string;
17
+ export declare function errorJson(error: unknown, places?: Places): ErrorJson;
package/dist/errors.js ADDED
@@ -0,0 +1,55 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { isAbsolute, relative } from 'node:path';
4
+ import { AshlarError } from './config.js';
5
+ const here = () => ({ cwd: process.cwd(), home: homedir() });
6
+ function spellings(folder) {
7
+ let real = folder;
8
+ try {
9
+ real = realpathSync(folder);
10
+ }
11
+ catch {
12
+ real = folder;
13
+ }
14
+ return [...new Set([folder, real])]
15
+ .filter((path) => path !== '' && path !== '/')
16
+ .sort((a, b) => b.length - a.length);
17
+ }
18
+ const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
19
+ function replaced(text, folder, inside, whole) {
20
+ const name = escaped(folder);
21
+ return text
22
+ .replace(new RegExp(`${name}/`, 'g'), inside)
23
+ .replace(new RegExp(`${name}(?![\\w./-])`, 'g'), whole);
24
+ }
25
+ export function scrubbed(text, places = here()) {
26
+ let out = text;
27
+ for (const folder of spellings(places.cwd))
28
+ out = replaced(out, folder, '', 'this folder');
29
+ for (const folder of spellings(places.home))
30
+ out = replaced(out, folder, '~/', '~');
31
+ return out;
32
+ }
33
+ function shownFile(file, places) {
34
+ if (!isAbsolute(file))
35
+ return file;
36
+ const inside = relative(places.cwd, file);
37
+ return inside && !inside.startsWith('..') && !isAbsolute(inside) ? inside : scrubbed(file, places);
38
+ }
39
+ export function errorJson(error, places = here()) {
40
+ if (!(error instanceof AshlarError)) {
41
+ const said = error instanceof Error ? error.message.split('\n')[0] || error.name : String(error);
42
+ return { v: 1, ok: false, error: { code: 'crashed', says: scrubbed(`Ashlar stopped: ${said}`, places) } };
43
+ }
44
+ const file = error.file === undefined ? undefined : shownFile(error.file, places);
45
+ return {
46
+ v: 1,
47
+ ok: false,
48
+ error: {
49
+ code: error.code,
50
+ says: scrubbed(error.message, places),
51
+ ...(file !== undefined && { file }),
52
+ ...(error.line !== undefined && { line: error.line }),
53
+ },
54
+ };
55
+ }
package/dist/git.js CHANGED
@@ -101,7 +101,7 @@ export function hasHead(root) {
101
101
  }
102
102
  export function knownRef(root, ref) {
103
103
  if (git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]) === null) {
104
- throw new AshlarError(`git knows no ${ref} here.`);
104
+ throw new AshlarError(`git knows no ${ref} here.`, 'git');
105
105
  }
106
106
  }
107
107
  function said(output) {
@@ -116,7 +116,7 @@ export function atRef(config, ref, read) {
116
116
  maxBuffer: 64 * 1024 * 1024,
117
117
  });
118
118
  if (listing.status !== 0) {
119
- throw new AshlarError(`git couldn't list the files at ${ref}: ${said(listing.stderr)}`);
119
+ throw new AshlarError(`git couldn't list the files at ${ref}: ${said(listing.stderr)}`, 'git');
120
120
  }
121
121
  const listed = lines(listing.stdout);
122
122
  if (listed.length === 0)
@@ -126,13 +126,13 @@ export function atRef(config, ref, read) {
126
126
  maxBuffer: 1024 * 1024 * 1024,
127
127
  });
128
128
  if (archive.status !== 0) {
129
- throw new AshlarError(`git couldn't read the files at ${ref}: ${said(archive.stderr)}`);
129
+ throw new AshlarError(`git couldn't read the files at ${ref}: ${said(archive.stderr)}`, 'git');
130
130
  }
131
131
  const root = realpathSync(mkdtempSync(join(tmpdir(), 'ashlar-at-')));
132
132
  try {
133
133
  const unpacked = spawnSync('tar', ['-x', '-f', '-', '-C', root], { input: archive.stdout });
134
134
  if (unpacked.status !== 0) {
135
- throw new AshlarError(`Ashlar couldn't unpack the files at ${ref}: ${said(unpacked.stderr)}`);
135
+ throw new AshlarError(`Ashlar couldn't unpack the files at ${ref}: ${said(unpacked.stderr)}`, 'git');
136
136
  }
137
137
  const holds = (path) => existsSync(join(root, path));
138
138
  return read({ config: { ...config, root }, holds });
package/dist/init.js CHANGED
@@ -199,7 +199,7 @@ export function detect(root) {
199
199
  const files = filesOf(root);
200
200
  const sources = files.filter(isSource);
201
201
  if (sources.length === 0)
202
- throw new AshlarError(`Ashlar found no TypeScript in ${root}: run it in a TypeScript repository.`);
202
+ throw new AshlarError(`Ashlar found no TypeScript in ${root}: run it in a TypeScript repository.`, 'refused');
203
203
  const folders = foldersOf(files);
204
204
  const apps = candidatesOf(files, sources)
205
205
  .map((folder) => classify(root, folder, folders, sources))
@@ -251,7 +251,7 @@ export function init(root, options = {}) {
251
251
  const started = performance.now();
252
252
  const existing = findConfig(root);
253
253
  if (existing) {
254
- throw new AshlarError(`Ashlar already reads ${relative(root, existing) || existing}: init writes a config only where there is none.`);
254
+ throw new AshlarError(`Ashlar already reads ${relative(root, existing) || existing}: init writes a config only where there is none.`, 'refused');
255
255
  }
256
256
  const found = detect(root);
257
257
  const config = configOf(found);
@@ -44,7 +44,7 @@ export function parseDecisions(text, file) {
44
44
  });
45
45
  });
46
46
  if (problems.length > 0)
47
- throw new AshlarError(problems.join('\n'));
47
+ throw new AshlarError(problems.join('\n'), 'decisions');
48
48
  return decisions;
49
49
  }
50
50
  export function readDecisions(root, file) {
@@ -44,7 +44,7 @@ function frontOf(text, file) {
44
44
  return { values: new Map(), paths: null, body: text };
45
45
  const end = lines.findIndex((line, i) => i > 0 && line.trim() === FENCE);
46
46
  if (end === -1)
47
- throw new AshlarError(`${file}: its frontmatter opens with --- and never closes.`);
47
+ throw new AshlarError(`${file}: its frontmatter opens with --- and never closes.`, 'rules', { file });
48
48
  const values = new Map();
49
49
  let paths = null;
50
50
  let inPaths = false;
@@ -59,7 +59,7 @@ function frontOf(text, file) {
59
59
  }
60
60
  const pair = /^([A-Za-z]+):\s*(.*)$/.exec(line);
61
61
  if (!pair || !KEYS.has(pair[1])) {
62
- throw new AshlarError(`${file}:${i + 1}: Ashlar reads only these frontmatter keys: ${[...KEYS].join(', ')}.`);
62
+ throw new AshlarError(`${file}:${i + 1}: Ashlar reads only these frontmatter keys: ${[...KEYS].join(', ')}.`, 'rules', { file, line: i + 1 });
63
63
  }
64
64
  inPaths = pair[1] === 'paths';
65
65
  if (inPaths)
package/dist/lint.js CHANGED
@@ -28,7 +28,7 @@ function unreadable(stdout) {
28
28
  });
29
29
  if (errors.length > 10)
30
30
  lines.push(` and ${errors.length - 10} more`);
31
- throw new AshlarError(`oxlint couldn't read these files, so Ashlar can't count them:\n${lines.join('\n')}`);
31
+ throw new AshlarError(`oxlint couldn't read these files, so Ashlar can't count them:\n${lines.join('\n')}`, 'lint');
32
32
  }
33
33
  export function workspaceOf(config) {
34
34
  return readWorkspace(config.root, config.include, new Set(config.ignore));
@@ -72,7 +72,7 @@ export function lint(config, rules, workspace = workspaceOf(config)) {
72
72
  ], { cwd: config.root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
73
73
  if (!existsSync(record)) {
74
74
  const said = `${run.stderr ?? ''}${run.stdout ?? ''}`.trim();
75
- throw new AshlarError(`oxlint stopped before it finished${said ? `: ${said}` : '.'}`);
75
+ throw new AshlarError(`oxlint stopped before it finished${said ? `: ${said}` : '.'}`, 'lint');
76
76
  }
77
77
  unreadable(run.stdout);
78
78
  const findings = JSON.parse(readFileSync(record, 'utf8'));
package/dist/mcp.js CHANGED
@@ -2,6 +2,7 @@ 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 { errorJson } from './errors.js';
5
6
  import { init } from './init.js';
6
7
  export const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26'];
7
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.';
@@ -143,7 +144,10 @@ function argumentsOf(tool, given) {
143
144
  }
144
145
  return args;
145
146
  }
146
- const said = (message) => ({ content: [{ type: 'text', text: message }], isError: true });
147
+ const refused = (error) => ({
148
+ content: [{ type: 'text', text: JSON.stringify(errorJson(error)) }],
149
+ isError: true,
150
+ });
147
151
  export async function callTool(name, given, cwd = process.cwd(), log = process.stderr) {
148
152
  const tool = TOOLS.find((entry) => entry.name === name);
149
153
  if (!tool)
@@ -162,10 +166,10 @@ export async function callTool(name, given, cwd = process.cwd(), log = process.s
162
166
  };
163
167
  }
164
168
  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
+ if (!(error instanceof AshlarError)) {
170
+ log.write(`${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`);
171
+ }
172
+ return refused(error);
169
173
  }
170
174
  }
171
175
  const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
package/dist/move.js CHANGED
@@ -63,7 +63,7 @@ function planOf(config, counts, from, to) {
63
63
  return { kind: 'folder', from, to, side };
64
64
  }
65
65
  if (!side) {
66
- throw new AshlarError(`Ashlar can't tell where ${from}'s counts go: exactly one of ${from} and ${to} must exist.`);
66
+ throw new AshlarError(`Ashlar can't tell where ${from}'s counts go: exactly one of ${from} and ${to} must exist.`, 'refused');
67
67
  }
68
68
  return { kind: 'file', from, to, side };
69
69
  }
@@ -73,7 +73,7 @@ function riseLines(moves) {
73
73
  export function move(config, pairs, cwd = process.cwd(), options = {}) {
74
74
  const baseline = readBaseline(config.baseline);
75
75
  if (!baseline) {
76
- throw new AshlarError('There is no baseline to move counts in yet: take it first with `ashlar check --shrink`.');
76
+ throw new AshlarError('There is no baseline to move counts in yet: take it first with `ashlar check --shrink`.', 'refused');
77
77
  }
78
78
  const accept = options.acceptRise === true;
79
79
  const counts = structuredClone(baseline);
@@ -87,7 +87,7 @@ export function move(config, pairs, cwd = process.cwd(), options = {}) {
87
87
  'Ashlar moved no counts: the move would take in new breaks.',
88
88
  ...riseLines(moves).map((line) => ` ${line}`),
89
89
  'Fix the moved code, or give `--accept-rise` to take the rise into the baseline.',
90
- ].join('\n'));
90
+ ].join('\n'), 'refused');
91
91
  }
92
92
  writeBaseline(config.baseline, counts);
93
93
  return moves;
@@ -25,7 +25,7 @@ export function refuseSecrets(config) {
25
25
  'Secrets never enter knowledge files, and these lines look like one:',
26
26
  ...found,
27
27
  'Take the value out. Say who grants access instead, as an `access` line, never the credential.',
28
- ].join('\n'));
28
+ ].join('\n'), 'secret');
29
29
  }
30
30
  }
31
31
  const UNNAMED = 'this project';
@@ -30,7 +30,7 @@ export function documentsOf(config) {
30
30
  export function defaultOwner(config) {
31
31
  if (config.onboard.owner)
32
32
  return config.onboard.owner;
33
- throw new AshlarError('Name the project’s default owner, who gets every question nobody else owns: `onboard: { owner: "@handle" }` in ashlar.config.ts.');
33
+ throw new AshlarError('Name the project’s default owner, who gets every question nobody else owns: `onboard: { owner: "@handle" }` in ashlar.config.ts.', 'config');
34
34
  }
35
35
  export function questionsOf(config, knowledge) {
36
36
  const fallback = defaultOwner(config);
@@ -14,7 +14,7 @@ export function driveOf(config) {
14
14
  const drive = driveCommandOf(config);
15
15
  if (drive)
16
16
  return drive;
17
- throw new AshlarError(`Nothing drives this project's app: add Rehearse (a rehearse.yaml), and Ashlar walks each reach through \`rehearse drive\`, or name a drive command in ${CONFIG_FILE}, such as \`drive: 'pnpm drive'\`.`);
17
+ throw new AshlarError(`Nothing drives this project's app: add Rehearse (a rehearse.yaml), and Ashlar walks each reach through \`rehearse drive\`, or name a drive command in ${CONFIG_FILE}, such as \`drive: 'pnpm drive'\`.`, 'drive');
18
18
  }
19
19
  const record = (v) => v && typeof v === 'object' && !Array.isArray(v) ? v : null;
20
20
  function printedResult(stdout) {
@@ -129,9 +129,9 @@ function startThroughRehearse(config, options) {
129
129
  if (!start.error && !start.signal && printedResult(start.stdout ?? '')?.ok === true)
130
130
  return;
131
131
  driveCommand(config, { command: 'stop' }, options);
132
- throw new AshlarError(`\`rehearse drive start\` couldn't start this project's app: ${saidBy(start, 'start')}`);
132
+ throw new AshlarError(`\`rehearse drive start\` couldn't start this project's app: ${saidBy(start, 'start')}`, 'drive');
133
133
  }
134
- const rehearseCantDrive = (said) => new AshlarError(`This project has a rehearse.yaml, so Ashlar walks each reach through \`rehearse drive\`, and it didn't answer: ${said} Rehearse drives from its 0.3.0; until then, name a drive command in ${CONFIG_FILE}, such as \`drive: 'pnpm drive'\`.`);
134
+ const rehearseCantDrive = (said) => new AshlarError(`This project has a rehearse.yaml, so Ashlar walks each reach through \`rehearse drive\`, and it didn't answer: ${said} Rehearse drives from its 0.3.0; until then, name a drive command in ${CONFIG_FILE}, such as \`drive: 'pnpm drive'\`.`, 'drive');
135
135
  export function driveFeature(config, feature, options) {
136
136
  const head = { feature: feature.name, folder: feature.folder, stoppedAt: null, step: null, ms: 0 };
137
137
  if (!feature.reach)
package/dist/skill.js CHANGED
@@ -134,7 +134,7 @@ function attachOf(config) {
134
134
  return null;
135
135
  const path = join(config.root, file);
136
136
  if (!existsSync(path)) {
137
- throw new AshlarError(`skills.verify.attach names ${file}, and there is no such file.`);
137
+ throw new AshlarError(`skills.verify.attach names ${file}, and there is no such file.`, 'config');
138
138
  }
139
139
  return readFileSync(path, 'utf8');
140
140
  }
@@ -216,14 +216,14 @@ export function writeSkill(config, name, options = {}) {
216
216
  const text = skillText(name, config);
217
217
  const root = realpathSync(config.root);
218
218
  if (!inside(root, realpathSync(nearest(dirname(file)))) || linkedOut(root, file)) {
219
- throw new AshlarError(`${shown} leads out of the project: Ashlar writes skills only into it.`);
219
+ throw new AshlarError(`${shown} leads out of the project: Ashlar writes skills only into it.`, 'refused');
220
220
  }
221
221
  mkdirSync(dirname(file), { recursive: true });
222
222
  const was = existsSync(file) ? readFileSync(file, 'utf8') : null;
223
223
  if (was === text)
224
224
  return 'same';
225
225
  if (was !== null && !options.force) {
226
- throw new AshlarError(`${shown} differs from Ashlar's ${name} skill: give \`--force\` to replace it with Ashlar's.`);
226
+ throw new AshlarError(`${shown} differs from Ashlar's ${name} skill: give \`--force\` to replace it with Ashlar's.`, 'refused');
227
227
  }
228
228
  writeFileSync(file, text);
229
229
  return was === null ? 'written' : 'replaced';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kurvball/ashlar",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
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",
@@ -0,0 +1,45 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/kurvball/ashlar/blob/main/schema/error.v1.json",
4
+ "title": "A refusal, from any command with --json",
5
+ "description": "What any command prints with --json when it can't do what it was asked, in the shape Rehearse's and Marquee's refusals share. It exits with 2, or with 1 when Ashlar crashed.",
6
+ "type": "object",
7
+ "required": ["v", "ok", "error"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "v": { "const": 1, "description": "The contract version." },
11
+ "ok": { "const": false },
12
+ "error": {
13
+ "type": "object",
14
+ "required": ["code", "says"],
15
+ "additionalProperties": false,
16
+ "properties": {
17
+ "code": {
18
+ "enum": [
19
+ "usage",
20
+ "config",
21
+ "baseline",
22
+ "git",
23
+ "lint",
24
+ "rules",
25
+ "decisions",
26
+ "secret",
27
+ "drive",
28
+ "refused",
29
+ "crashed"
30
+ ],
31
+ "description": "A stable word for the kind of refusal: usage (the command line), config (ashlar.config.ts), baseline (ashlar.baseline.json), git, lint (oxlint), rules (a file in .claude/rules/), decisions (DECISIONS.md), secret (a knowledge file holds what looks like one), drive (the drive command), refused (what was asked would lose or overwrite something), or crashed."
32
+ },
33
+ "says": {
34
+ "type": "string",
35
+ "description": "What went wrong and what to do, in plain words: the sentence the command prints on stderr without --json."
36
+ },
37
+ "file": {
38
+ "type": "string",
39
+ "description": "The file at fault, from the folder Ashlar runs in, when there is one."
40
+ },
41
+ "line": { "type": "integer", "minimum": 1, "description": "Its line, when Ashlar knows it." }
42
+ }
43
+ }
44
+ }
45
+ }
@@ -65,5 +65,6 @@ writes nothing. Show a person the config before you commit it.
65
65
  `ashlar.config.ts`, by a person.
66
66
  - When `onboard` with `{ "check": true }` answers `ok: false`, the guide is stale: run `onboard` and commit
67
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.
68
+ - A refusal comes back with `isError: true` and the error object, `{ "v": 1, "ok": false, "error": { "code",
69
+ "says" } }`, also what a command prints with `--json` when it can't run. `says` tells you what was wrong, such
70
+ as a ref git doesn't know. Fix the call; don't retry it unchanged.