@kurvball/ashlar 0.0.0-stage → 1.3.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.
Files changed (132) hide show
  1. package/CHANGELOG.md +238 -0
  2. package/LICENSE +21 -0
  3. package/README.md +145 -2
  4. package/dist/affected.d.ts +19 -0
  5. package/dist/affected.js +78 -0
  6. package/dist/areas.d.ts +2 -0
  7. package/dist/areas.js +20 -0
  8. package/dist/baseline.d.ts +27 -0
  9. package/dist/baseline.js +109 -0
  10. package/dist/beside.d.ts +1 -0
  11. package/dist/beside.js +4 -0
  12. package/dist/check.d.ts +39 -0
  13. package/dist/check.js +109 -0
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/cli.js +211 -0
  16. package/dist/config.d.ts +84 -0
  17. package/dist/config.js +98 -0
  18. package/dist/configCheck.d.ts +2 -0
  19. package/dist/configCheck.js +204 -0
  20. package/dist/css.d.ts +13 -0
  21. package/dist/css.js +66 -0
  22. package/dist/drive.d.ts +77 -0
  23. package/dist/drive.js +188 -0
  24. package/dist/features.d.ts +32 -0
  25. package/dist/features.js +156 -0
  26. package/dist/git.d.ts +18 -0
  27. package/dist/git.js +140 -0
  28. package/dist/glob.d.ts +5 -0
  29. package/dist/glob.js +49 -0
  30. package/dist/graph.d.ts +16 -0
  31. package/dist/graph.js +83 -0
  32. package/dist/identity.d.ts +1 -0
  33. package/dist/identity.js +1 -0
  34. package/dist/index.d.ts +21 -0
  35. package/dist/index.js +18 -0
  36. package/dist/jsonc.d.ts +1 -0
  37. package/dist/jsonc.js +66 -0
  38. package/dist/knowledge/areas.d.ts +25 -0
  39. package/dist/knowledge/areas.js +86 -0
  40. package/dist/knowledge/decisions.d.ts +14 -0
  41. package/dist/knowledge/decisions.js +53 -0
  42. package/dist/knowledge/guards.d.ts +4 -0
  43. package/dist/knowledge/guards.js +60 -0
  44. package/dist/knowledge/rules.d.ts +12 -0
  45. package/dist/knowledge/rules.js +100 -0
  46. package/dist/knowledge/secrets.d.ts +6 -0
  47. package/dist/knowledge/secrets.js +58 -0
  48. package/dist/layout.d.ts +61 -0
  49. package/dist/layout.js +120 -0
  50. package/dist/ledger.d.ts +28 -0
  51. package/dist/ledger.js +44 -0
  52. package/dist/lint.d.ts +11 -0
  53. package/dist/lint.js +109 -0
  54. package/dist/map.d.ts +25 -0
  55. package/dist/map.js +37 -0
  56. package/dist/move.d.ts +18 -0
  57. package/dist/move.js +94 -0
  58. package/dist/onboard/applies.d.ts +11 -0
  59. package/dist/onboard/applies.js +28 -0
  60. package/dist/onboard/brief.d.ts +40 -0
  61. package/dist/onboard/brief.js +126 -0
  62. package/dist/onboard/guide.d.ts +7 -0
  63. package/dist/onboard/guide.js +150 -0
  64. package/dist/onboard/model.d.ts +15 -0
  65. package/dist/onboard/model.js +57 -0
  66. package/dist/onboard/onboard.d.ts +28 -0
  67. package/dist/onboard/onboard.js +86 -0
  68. package/dist/onboard/questions.d.ts +15 -0
  69. package/dist/onboard/questions.js +90 -0
  70. package/dist/onboard/snapshot.d.ts +28 -0
  71. package/dist/onboard/snapshot.js +58 -0
  72. package/dist/order.d.ts +1 -0
  73. package/dist/order.js +1 -0
  74. package/dist/origins.d.ts +6 -0
  75. package/dist/origins.js +51 -0
  76. package/dist/plugin/boundaries.d.ts +5 -0
  77. package/dist/plugin/boundaries.js +174 -0
  78. package/dist/plugin/exports.d.ts +2 -0
  79. package/dist/plugin/exports.js +41 -0
  80. package/dist/plugin/features.d.ts +4 -0
  81. package/dist/plugin/features.js +34 -0
  82. package/dist/plugin/here.d.ts +13 -0
  83. package/dist/plugin/here.js +69 -0
  84. package/dist/plugin/imports.d.ts +12 -0
  85. package/dist/plugin/imports.js +103 -0
  86. package/dist/plugin/index.d.ts +14 -0
  87. package/dist/plugin/index.js +19 -0
  88. package/dist/plugin/messages.d.ts +20 -0
  89. package/dist/plugin/messages.js +36 -0
  90. package/dist/plugin/names.d.ts +3 -0
  91. package/dist/plugin/names.js +68 -0
  92. package/dist/plugin/references.d.ts +5 -0
  93. package/dist/plugin/references.js +52 -0
  94. package/dist/plugin/text.d.ts +7 -0
  95. package/dist/plugin/text.js +87 -0
  96. package/dist/plugin/types.d.ts +87 -0
  97. package/dist/plugin/types.js +1 -0
  98. package/dist/reach.d.ts +82 -0
  99. package/dist/reach.js +163 -0
  100. package/dist/reachDrive.d.ts +31 -0
  101. package/dist/reachDrive.js +200 -0
  102. package/dist/reachReader.d.ts +1 -0
  103. package/dist/reachReader.js +31 -0
  104. package/dist/rehearse/dependents.d.ts +9 -0
  105. package/dist/rehearse/dependents.js +38 -0
  106. package/dist/rehearse/fill.d.ts +28 -0
  107. package/dist/rehearse/fill.js +44 -0
  108. package/dist/report.d.ts +6 -0
  109. package/dist/report.js +91 -0
  110. package/dist/resolve.d.ts +3 -0
  111. package/dist/resolve.js +114 -0
  112. package/dist/runner.d.ts +6 -0
  113. package/dist/runner.js +29 -0
  114. package/dist/skill.d.ts +23 -0
  115. package/dist/skill.js +235 -0
  116. package/dist/usage.d.ts +1 -0
  117. package/dist/usage.js +53 -0
  118. package/dist/workspace.d.ts +16 -0
  119. package/dist/workspace.js +125 -0
  120. package/ledger.json +201 -0
  121. package/package.json +73 -3
  122. package/schema/affected.v1.json +58 -0
  123. package/schema/brief.v1.json +205 -0
  124. package/schema/check.v1.json +151 -0
  125. package/schema/dependents.v1.json +30 -0
  126. package/schema/drive.v1.json +55 -0
  127. package/schema/ledger.v1.json +61 -0
  128. package/schema/map.v1.json +62 -0
  129. package/schema/move.v1.json +61 -0
  130. package/schema/onboard.v1.json +186 -0
  131. package/schema/rehearse.v1.json +91 -0
  132. package/schema/snapshot.v1.json +101 -0
package/dist/beside.js ADDED
@@ -0,0 +1,4 @@
1
+ import { extname } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ const EXTENSION = extname(fileURLToPath(import.meta.url));
4
+ export const besideModule = (path, from) => fileURLToPath(new URL(`${path}${EXTENSION}`, from));
@@ -0,0 +1,39 @@
1
+ import { type Rise } from './baseline.ts';
2
+ import type { Loaded } from './config.ts';
3
+ import { type Renamed } from './git.ts';
4
+ export interface BreakAt {
5
+ file: string;
6
+ line: number;
7
+ column: number;
8
+ size: number;
9
+ fresh: boolean;
10
+ }
11
+ export interface RiseReport extends Rise {
12
+ message: string;
13
+ breaks: BreakAt[];
14
+ added: number;
15
+ }
16
+ export declare const NONE_NEW: readonly string[];
17
+ export interface RuleTotal {
18
+ rule: string;
19
+ count: number;
20
+ baseline: number;
21
+ }
22
+ export type BaselineState = 'held' | 'taken' | 'shrunk' | 'risen' | 'none';
23
+ export interface CheckReport {
24
+ ok: boolean;
25
+ seconds: number;
26
+ files: number;
27
+ baseline: BaselineState;
28
+ rules: RuleTotal[];
29
+ rises: RiseReport[];
30
+ taken: Rise[];
31
+ slack: number;
32
+ moves: Renamed[];
33
+ warnings: string[];
34
+ }
35
+ export interface CheckOptions {
36
+ shrink?: boolean;
37
+ acceptRise?: boolean;
38
+ }
39
+ export declare function check(config: Loaded, options?: CheckOptions): CheckReport;
package/dist/check.js ADDED
@@ -0,0 +1,109 @@
1
+ import { carried, countsOf, holdsAny, readBaseline, risesOf, shrunk, slackOf, totalOf, writeBaseline, } from './baseline.js';
2
+ import { areaWarnings } from './areas.js';
3
+ import { withReachBreaks } from './features.js';
4
+ import { changedLines, renamedSince } from './git.js';
5
+ import { lint } from './lint.js';
6
+ import { lintRulesOf } from './plugin/messages.js';
7
+ export const NONE_NEW = ['no-comment', 'no-disable'];
8
+ function raised(baseline, rises) {
9
+ const out = {};
10
+ for (const [rule, files] of Object.entries(baseline))
11
+ out[rule] = { ...files };
12
+ for (const rise of rises)
13
+ (out[rise.rule] ??= {})[rise.file] = rise.count;
14
+ return out;
15
+ }
16
+ function stateOf(before, options, taken) {
17
+ if (!before)
18
+ return options.shrink || taken.length > 0 ? 'taken' : 'none';
19
+ if (taken.length > 0)
20
+ return 'risen';
21
+ return options.shrink ? 'shrunk' : 'held';
22
+ }
23
+ function isFresh(changed, file, rule, line, size) {
24
+ const lines = changed.get(file);
25
+ if (!lines)
26
+ return false;
27
+ if (lines === 'all')
28
+ return true;
29
+ if (rule === 'max-lines')
30
+ return lines.size > 0;
31
+ for (let at = line; at < line + size; at += 1)
32
+ if (lines.has(at))
33
+ return true;
34
+ return false;
35
+ }
36
+ function describe(files, rises, changed) {
37
+ return rises.map((rise) => {
38
+ let message = '';
39
+ const breaks = [];
40
+ for (const found of files[rise.file]?.breaks ?? []) {
41
+ if (found.rule !== rise.rule)
42
+ continue;
43
+ message = found.message;
44
+ const fresh = isFresh(changed, rise.file, found.rule, found.line, found.size);
45
+ breaks.push({ file: rise.file, line: found.line, column: found.column, size: found.size, fresh });
46
+ }
47
+ breaks.sort((a, b) => a.line - b.line || a.column - b.column);
48
+ const added = breaks.filter((found) => found.fresh).reduce((sum, found) => sum + found.size, 0);
49
+ return { ...rise, message, breaks, added };
50
+ });
51
+ }
52
+ function newBreaks(files, changed, counts, baseline, rises) {
53
+ const risen = new Set(rises.map((rise) => `${rise.rule}\0${rise.file}`));
54
+ const found = new Map();
55
+ for (const [file, findings] of Object.entries(files)) {
56
+ if (!changed.has(file))
57
+ continue;
58
+ for (const at of findings.breaks) {
59
+ const key = `${at.rule}\0${file}`;
60
+ if (!NONE_NEW.includes(at.rule) || risen.has(key))
61
+ continue;
62
+ if (!isFresh(changed, file, at.rule, at.line, at.size))
63
+ continue;
64
+ const count = counts[at.rule]?.[file] ?? 0;
65
+ found.set(key, { rule: at.rule, file, count, baseline: baseline[at.rule]?.[file] ?? 0 });
66
+ }
67
+ }
68
+ return [...found.values()];
69
+ }
70
+ function movesInto(rises, renamed, baseline) {
71
+ const risen = new Set(rises.map((rise) => rise.file));
72
+ return renamed.filter((move) => risen.has(move.to) && holdsAny(baseline, move.from));
73
+ }
74
+ export function check(config, options = {}) {
75
+ const started = performance.now();
76
+ const linted = lint(config, [...lintRulesOf(config), 'graph']);
77
+ const files = withReachBreaks(config, linted.files);
78
+ const counts = countsOf(files);
79
+ const before = readBaseline(config.baseline);
80
+ let renamed = null;
81
+ const renames = () => (renamed ??= renamedSince(config.root, config.include));
82
+ let baseline = options.shrink
83
+ ? shrunk(counts, before && carried(before, renames()))
84
+ : (before ?? {});
85
+ const taken = options.acceptRise ? risesOf(counts, baseline) : [];
86
+ if (taken.length > 0)
87
+ baseline = raised(baseline, taken);
88
+ if (options.shrink || taken.length > 0)
89
+ writeBaseline(config.baseline, baseline);
90
+ const risen = risesOf(counts, baseline);
91
+ const changed = changedLines(config.root, config.include);
92
+ const rises = [...risen, ...newBreaks(files, changed, counts, baseline, risen)];
93
+ return {
94
+ ok: rises.length === 0,
95
+ seconds: (performance.now() - started) / 1000,
96
+ files: Object.keys(linted.files).length,
97
+ baseline: stateOf(before, options, taken),
98
+ rules: config.rules.map((rule) => ({
99
+ rule,
100
+ count: totalOf(counts, rule),
101
+ baseline: totalOf(baseline, rule),
102
+ })),
103
+ rises: rises.length > 0 ? describe(files, rises, changed) : [],
104
+ taken,
105
+ slack: slackOf(counts, baseline),
106
+ moves: risen.length > 0 ? movesInto(risen, renames(), baseline) : [],
107
+ warnings: areaWarnings(config.apps, Object.keys(linted.files)),
108
+ };
109
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { relative } from 'node:path';
4
+ import { affected } from './affected.js';
5
+ import { check } from './check.js';
6
+ import { AshlarError, loadConfig } from './config.js';
7
+ import { buildMap, featuresOf, unreadText } from './features.js';
8
+ import { ledgerOf, ledgerText } from './ledger.js';
9
+ import { mapText } from './map.js';
10
+ import { move } from './move.js';
11
+ import { driveFeature, driveOf, featureNamed, isScheme, runsText, SCHEMES } from './reachDrive.js';
12
+ import { affectedText, checkText, movedText } from './report.js';
13
+ import { USAGE } from './usage.js';
14
+ import { brief, briefText } from './onboard/brief.js';
15
+ import { onboard, onboardText } from './onboard/onboard.js';
16
+ import { snapshot, snapshotText } from './onboard/snapshot.js';
17
+ import { dependentsOf, dependentsText } from './rehearse/dependents.js';
18
+ import { fillText, rehearseFill } from './rehearse/fill.js';
19
+ import { isSkill, SKILL_FILE, SKILL_WRITE_WORDS, SKILLS, skillText, writeSkill } from './skill.js';
20
+ const FLAGS = {
21
+ check: ['shrink', 'accept-rise', 'json'],
22
+ affected: ['since', 'json'],
23
+ move: ['accept-rise', 'json'],
24
+ ledger: ['json'],
25
+ map: ['json'],
26
+ drive: ['all', 'scheme', 'json'],
27
+ skill: ['write', 'force'],
28
+ onboard: ['check', 'json'],
29
+ brief: ['json'],
30
+ snapshot: ['json'],
31
+ dependents: ['json'],
32
+ rehearse: ['json'],
33
+ };
34
+ const VALUED = new Map([
35
+ ['since', 'a ref'],
36
+ ['scheme', `a scheme: ${SCHEMES.join(' or ')}`],
37
+ ]);
38
+ function parse(args) {
39
+ const positional = [];
40
+ const flags = new Set();
41
+ const values = new Map();
42
+ for (let i = 0; i < args.length; i += 1) {
43
+ const arg = args[i];
44
+ if (!arg.startsWith('--')) {
45
+ positional.push(arg);
46
+ continue;
47
+ }
48
+ const equals = arg.indexOf('=');
49
+ const name = arg.slice(2, equals === -1 ? undefined : equals);
50
+ const takes = VALUED.get(name);
51
+ if (takes === undefined) {
52
+ if (equals !== -1)
53
+ throw new AshlarError(`\`--${name}\` takes no value.`);
54
+ flags.add(name);
55
+ continue;
56
+ }
57
+ let value = arg.slice(equals + 1);
58
+ if (equals === -1) {
59
+ i += 1;
60
+ value = args[i] ?? '';
61
+ }
62
+ if (value === '' || value.startsWith('--')) {
63
+ throw new AshlarError(`Give \`--${name}\` ${takes}.`);
64
+ }
65
+ values.set(name, value);
66
+ }
67
+ return { command: positional.shift(), positional, flags, values };
68
+ }
69
+ function print(json, value, text) {
70
+ process.stdout.write(json ? `${JSON.stringify(value, null, 2)}\n` : text);
71
+ }
72
+ async function main(args) {
73
+ const { command, positional, flags, values } = parse(args);
74
+ const since = values.get('since');
75
+ const json = flags.has('json');
76
+ if (command === undefined && flags.has('version')) {
77
+ const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
78
+ process.stdout.write(`${manifest.version}\n`);
79
+ return 0;
80
+ }
81
+ if (command === undefined || flags.has('help') || command === 'help') {
82
+ process.stdout.write(USAGE);
83
+ return command === undefined && !flags.has('help') ? 1 : 0;
84
+ }
85
+ const takes = FLAGS[command];
86
+ if (takes) {
87
+ const unknown = [...flags, ...values.keys()].filter((flag) => !takes.includes(flag));
88
+ if (unknown.length > 0) {
89
+ const named = takes.length ? takes.map((flag) => `--${flag}`).join(', ') : 'none';
90
+ throw new AshlarError(`\`ashlar ${command}\` takes no ${unknown.map((f) => `--${f}`).join(', ')}: it takes ${named}.`);
91
+ }
92
+ }
93
+ const config = await loadConfig();
94
+ if (command === 'check') {
95
+ const checked = check(config, { shrink: flags.has('shrink'), acceptRise: flags.has('accept-rise') });
96
+ const { warnings, ...report } = checked;
97
+ print(json, { version: 1, ...report }, checkText(checked, relative(process.cwd(), config.baseline)));
98
+ for (const warning of warnings)
99
+ process.stderr.write(`Warning: ${warning}\n`);
100
+ return report.ok ? 0 : 1;
101
+ }
102
+ if (command === 'affected') {
103
+ if (positional.length === 0 && since === undefined) {
104
+ throw new AshlarError('Name the changed files, or give `--since <ref>`.');
105
+ }
106
+ const report = affected(config, { files: positional, since });
107
+ print(json, { version: 1, ...report }, affectedText(report));
108
+ if (!json && report.unreached.length > 0) {
109
+ process.stderr.write(`No test reaches ${report.unreached.join(', ')}.\n`);
110
+ }
111
+ return 0;
112
+ }
113
+ if (command === 'move') {
114
+ if (positional.length === 0 || positional.length % 2 !== 0) {
115
+ throw new AshlarError('Give `ashlar move` pairs of paths: <from> <to>.');
116
+ }
117
+ const pairs = [];
118
+ for (let i = 0; i < positional.length; i += 2)
119
+ pairs.push([positional[i], positional[i + 1]]);
120
+ const moves = move(config, pairs, process.cwd(), { acceptRise: flags.has('accept-rise') });
121
+ print(json, { version: 1, moves }, movedText(moves));
122
+ return 0;
123
+ }
124
+ if (command === 'ledger') {
125
+ const entries = ledgerOf(config);
126
+ print(json, { version: 1, entries }, ledgerText(entries));
127
+ return 0;
128
+ }
129
+ if (command === 'map') {
130
+ const features = featuresOf(config);
131
+ const map = buildMap(config, features);
132
+ const unreadable = new Set(features.filter((f) => f.reach && !f.reach.ok).map((f) => f.folder));
133
+ print(json, map, `${mapText(map, unreadable)}${unreadText(features)}`);
134
+ return 0;
135
+ }
136
+ if (command === 'onboard') {
137
+ const check = flags.has('check');
138
+ const report = onboard(config, { check });
139
+ print(json, report, onboardText(report, check));
140
+ return report.ok ? 0 : 1;
141
+ }
142
+ if (command === 'brief') {
143
+ if (positional.length === 0)
144
+ throw new AshlarError('Name the files or folders the agent will change.');
145
+ const said = brief(config, positional);
146
+ print(json, said, briefText(said));
147
+ return 0;
148
+ }
149
+ if (command === 'snapshot') {
150
+ const said = snapshot(config);
151
+ print(json, said, snapshotText(said));
152
+ return 0;
153
+ }
154
+ if (command === 'dependents') {
155
+ if (positional.length === 0)
156
+ throw new AshlarError('Name the files whose dependents you want.');
157
+ const found = dependentsOf(config, positional);
158
+ print(json, found, dependentsText(found));
159
+ return 0;
160
+ }
161
+ if (command === 'rehearse') {
162
+ if (positional.length > 0)
163
+ throw new AshlarError('`ashlar rehearse` takes no files.');
164
+ const fill = rehearseFill(config);
165
+ print(json, fill, fillText(fill));
166
+ return 0;
167
+ }
168
+ if (command === 'drive')
169
+ return drive(config, positional, flags, values);
170
+ if (command === 'skill')
171
+ return skill(config, positional, flags);
172
+ throw new AshlarError(`Ashlar has no ${command} command.\n\n${USAGE}`);
173
+ }
174
+ function drive(config, positional, flags, values) {
175
+ const scheme = values.get('scheme') ?? null;
176
+ if (scheme !== null && !isScheme(scheme)) {
177
+ throw new AshlarError(`Drive has no ${scheme} scheme: ${SCHEMES.join(' or ')}.`);
178
+ }
179
+ const all = flags.has('all');
180
+ if (all ? positional.length > 0 : positional.length !== 1) {
181
+ throw new AshlarError('Name one feature, or give `--all`.');
182
+ }
183
+ driveOf(config);
184
+ const features = featuresOf(config);
185
+ const chosen = all ? features : [featureNamed(features, positional[0])];
186
+ const runs = chosen.map((feature) => ({ version: 1, ...driveFeature(config, feature, { scheme }) }));
187
+ print(flags.has('json'), all ? runs : runs[0], runsText(runs, all));
188
+ return runs.every((run) => run.outcome === 'reached') ? 0 : 1;
189
+ }
190
+ function skill(config, positional, flags) {
191
+ const [name, ...rest] = positional;
192
+ if (!isSkill(name) || rest.length > 0) {
193
+ throw new AshlarError(`Name the skill: ${SKILLS.join(', ')}.`);
194
+ }
195
+ if (!flags.has('write')) {
196
+ process.stdout.write(skillText(name, config));
197
+ return 0;
198
+ }
199
+ const wrote = writeSkill(config, name, { force: flags.has('force') });
200
+ process.stdout.write(`${SKILL_WRITE_WORDS[wrote](SKILL_FILE[name])}\n`);
201
+ return 0;
202
+ }
203
+ try {
204
+ process.exitCode = await main(process.argv.slice(2));
205
+ }
206
+ catch (error) {
207
+ if (!(error instanceof AshlarError))
208
+ throw error;
209
+ process.stderr.write(`${error.message}\n`);
210
+ process.exitCode = 2;
211
+ }
@@ -0,0 +1,84 @@
1
+ import { type AppConfig, type AppLayout, type Setup } from './layout.ts';
2
+ import { type RuleName } from './plugin/messages.ts';
3
+ import type { Confined } from './plugin/types.ts';
4
+ export interface AshlarConfig {
5
+ include: string[];
6
+ ignore?: string[];
7
+ apps?: AppConfig[];
8
+ setups?: Setup[];
9
+ tests?: string[];
10
+ maxLines?: number;
11
+ baseline?: string;
12
+ drive?: string;
13
+ confined?: ConfinedConfig[];
14
+ rules?: Partial<Record<RuleName, RuleSwitch>>;
15
+ messages?: Partial<Record<Exclude<RuleName, 'named-only-in'>, string>>;
16
+ skills?: SkillsConfig;
17
+ onboard?: OnboardConfig;
18
+ }
19
+ export interface OnboardConfig {
20
+ out?: string;
21
+ decisions?: string;
22
+ rules?: string;
23
+ owner?: string;
24
+ owners?: Record<string, string>;
25
+ areas?: string[];
26
+ documents?: string[];
27
+ dataRules?: string[];
28
+ guards?: string[];
29
+ }
30
+ export interface OnboardLoaded {
31
+ out: string;
32
+ decisions: string;
33
+ rules: string;
34
+ owner: string | null;
35
+ owners: [string, string][];
36
+ areas: string[] | null;
37
+ documents: string[] | null;
38
+ dataRules: string[];
39
+ guards: string[];
40
+ }
41
+ export declare const DATA_RULES: string[];
42
+ export declare const GUARDS: string[];
43
+ export type RuleSwitch = 'on' | 'off';
44
+ export interface SkillsConfig {
45
+ verify?: {
46
+ attach?: string;
47
+ };
48
+ }
49
+ export interface ConfinedConfig {
50
+ words: string[];
51
+ only: string[];
52
+ within?: string[];
53
+ message: string;
54
+ }
55
+ export interface Loaded {
56
+ root: string;
57
+ include: string[];
58
+ ignore: string[];
59
+ apps: AppLayout[];
60
+ setups: Setup[];
61
+ tests: string[];
62
+ maxLines: number;
63
+ baseline: string;
64
+ drive: string | null;
65
+ confined: Confined[];
66
+ rules: RuleName[];
67
+ messages: Partial<Record<RuleName, string>>;
68
+ skills: {
69
+ verify: {
70
+ attach: string | null;
71
+ };
72
+ };
73
+ onboard: OnboardLoaded;
74
+ }
75
+ export declare const CONFIG_FILE = "ashlar.config.ts";
76
+ export declare const CONFIG_FILES: string[];
77
+ export declare const DEFAULT_IGNORE: string[];
78
+ export declare const DEFAULT_TESTS: string[];
79
+ export declare class AshlarError extends Error {
80
+ }
81
+ export declare function defineConfig(config: AshlarConfig): AshlarConfig;
82
+ export declare function findConfig(from: string): string | null;
83
+ export declare function settle(config: AshlarConfig, root: string, file?: string): Loaded;
84
+ export declare function loadConfig(from?: string): Promise<Loaded>;
package/dist/config.js ADDED
@@ -0,0 +1,98 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { existsSync, realpathSync } from 'node:fs';
10
+ import { basename, dirname, join, resolve } from 'node:path';
11
+ import { pathToFileURL } from 'node:url';
12
+ import { checkConfig } from './configCheck.js';
13
+ import { appLayout, setupsUnder, tidy } from './layout.js';
14
+ import { RULES } from './plugin/messages.js';
15
+ export const DATA_RULES = [
16
+ 'Real data never enters the repository: not in code, tests, fixtures or documents.',
17
+ 'Secrets are never printed, logged or written into the repository.',
18
+ ];
19
+ export const GUARDS = ['**/*.guard.flow.yaml', '**/*.guard.rehearse.yaml'];
20
+ export const CONFIG_FILE = 'ashlar.config.ts';
21
+ export const CONFIG_FILES = [CONFIG_FILE, 'ashlar.config.mts', 'ashlar.config.js', 'ashlar.config.mjs'];
22
+ export const DEFAULT_IGNORE = ['node_modules', 'out', 'dist', 'release'];
23
+ export const DEFAULT_TESTS = ['.test.ts', '.test.tsx'];
24
+ export class AshlarError extends Error {
25
+ }
26
+ export function defineConfig(config) {
27
+ return config;
28
+ }
29
+ export function findConfig(from) {
30
+ let folder = resolve(from);
31
+ for (;;) {
32
+ const candidate = CONFIG_FILES.map((name) => join(folder, name)).find((file) => existsSync(file));
33
+ if (candidate)
34
+ return candidate;
35
+ const parent = dirname(folder);
36
+ if (parent === folder)
37
+ return null;
38
+ folder = parent;
39
+ }
40
+ }
41
+ export function settle(config, root, file = CONFIG_FILE) {
42
+ const problems = checkConfig(config);
43
+ if (problems.length > 0) {
44
+ throw new AshlarError(`${file} doesn't read:\n${problems.map((line) => ` ${line}`).join('\n')}`);
45
+ }
46
+ return {
47
+ root,
48
+ include: config.include.map(tidy),
49
+ ignore: config.ignore ?? DEFAULT_IGNORE,
50
+ apps: (config.apps ?? []).map(appLayout),
51
+ setups: setupsUnder('', config.setups ?? []),
52
+ tests: config.tests ?? DEFAULT_TESTS,
53
+ maxLines: config.maxLines ?? 600,
54
+ baseline: join(root, config.baseline ?? 'ashlar.baseline.json'),
55
+ drive: typeof config.drive === 'string' && config.drive.trim() ? config.drive.trim() : null,
56
+ confined: (config.confined ?? []).map(confinedOf),
57
+ rules: RULES.filter((rule) => config.rules?.[rule] !== 'off'),
58
+ messages: Object.fromEntries(Object.entries(config.messages ?? {}).map(([rule, message]) => [rule, message.trim()])),
59
+ skills: { verify: { attach: config.skills?.verify?.attach?.trim() || null } },
60
+ onboard: onboardOf(config.onboard ?? {}),
61
+ };
62
+ }
63
+ function onboardOf(onboard) {
64
+ return {
65
+ out: tidy(onboard.out ?? 'docs/onboarding'),
66
+ decisions: tidy(onboard.decisions ?? 'DECISIONS.md'),
67
+ rules: tidy(onboard.rules ?? '.claude/rules'),
68
+ owner: onboard.owner?.trim() || null,
69
+ owners: Object.entries(onboard.owners ?? {})
70
+ .map(([folder, owner]) => [tidy(folder), owner.trim()])
71
+ .sort((a, b) => b[0].length - a[0].length),
72
+ areas: onboard.areas ? onboard.areas.map(tidy) : null,
73
+ documents: onboard.documents ? onboard.documents.map(tidy) : null,
74
+ dataRules: onboard.dataRules ?? DATA_RULES,
75
+ guards: onboard.guards ?? GUARDS,
76
+ };
77
+ }
78
+ function confinedOf(entry) {
79
+ const words = (entry.words ?? []).map((word) => word.trim()).filter(Boolean);
80
+ 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.`);
82
+ }
83
+ return {
84
+ words,
85
+ only: (entry.only ?? []).map(tidy),
86
+ within: (entry.within ?? []).map(tidy),
87
+ message: entry.message.trim(),
88
+ };
89
+ }
90
+ export async function loadConfig(from = process.cwd()) {
91
+ const file = findConfig(from);
92
+ if (!file)
93
+ throw new AshlarError(`There is no ${CONFIG_FILE} in ${resolve(from)} or above it.`);
94
+ const loaded = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
95
+ if (!loaded.default)
96
+ throw new AshlarError(`${file} has no default export: export its config.`);
97
+ return settle(loaded.default, realpathSync(dirname(file)), basename(file));
98
+ }
@@ -0,0 +1,2 @@
1
+ export declare function checkConfig(config: unknown): string[];
2
+ export declare const CONFIG_KEYS: readonly string[];