@kurvball/ashlar 0.0.0-stage → 1.4.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 +250 -0
  2. package/LICENSE +21 -0
  3. package/README.md +150 -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 +40 -0
  13. package/dist/check.js +109 -0
  14. package/dist/cli.d.ts +2 -0
  15. package/dist/cli.js +215 -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 +143 -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 +55 -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
@@ -0,0 +1,86 @@
1
+ import { readdirSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { isGlob } from '../glob.js';
4
+ import { tidy, within } from '../layout.js';
5
+ import { nameOfFolder } from '../map.js';
6
+ import { byText } from '../order.js';
7
+ import { EVERYWHERE } from './decisions.js';
8
+ const isFolder = (path) => statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
9
+ function foldersOf(config, pattern) {
10
+ if (!pattern.endsWith('/*'))
11
+ return isFolder(join(config.root, pattern)) ? [pattern] : [];
12
+ const parent = pattern.slice(0, -2);
13
+ if (!isFolder(join(config.root, parent)))
14
+ return [];
15
+ return readdirSync(join(config.root, parent), { withFileTypes: true })
16
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.') && !config.ignore.includes(entry.name))
17
+ .map((entry) => tidy(`${parent}/${entry.name}`));
18
+ }
19
+ export function areasOf(config, names = new Map()) {
20
+ const areas = new Map();
21
+ const add = (path, kind, app) => {
22
+ if (!areas.has(path))
23
+ areas.set(path, { path, name: names.get(path) ?? nameOfFolder(path), kind, app });
24
+ };
25
+ for (const app of config.apps) {
26
+ for (const pattern of app.roles.features)
27
+ for (const path of foldersOf(config, pattern))
28
+ add(path, 'feature', app.root);
29
+ for (const pattern of app.areas)
30
+ for (const path of foldersOf(config, pattern))
31
+ add(path, 'area', app.root);
32
+ }
33
+ const named = config.onboard.areas ?? (config.apps.length === 0 ? config.include.map((folder) => `${folder}/*`) : []);
34
+ for (const pattern of named)
35
+ for (const path of foldersOf(config, pattern))
36
+ add(path, 'folder', null);
37
+ return [...areas.values()].sort((a, b) => byText(a.path, b.path));
38
+ }
39
+ export function overlaps(a, b) {
40
+ return a === EVERYWHERE || b === EVERYWHERE || within(a, b) || within(b, a);
41
+ }
42
+ export function staticPart(pattern) {
43
+ if (!isGlob(pattern))
44
+ return pattern;
45
+ const parts = pattern.split('/');
46
+ const fixed = parts.slice(0, parts.findIndex((part) => isGlob(part)));
47
+ return fixed.join('/');
48
+ }
49
+ export function ruleCoversArea(rule, area) {
50
+ return (rule.paths !== null &&
51
+ rule.paths.some((pattern) => {
52
+ const fixed = staticPart(pattern);
53
+ return fixed !== '' && overlaps(fixed, area);
54
+ }));
55
+ }
56
+ export function isCrossCutting(rule) {
57
+ return rule.paths === null || rule.paths.some((pattern) => staticPart(pattern) === '');
58
+ }
59
+ export function decisionCovers(decision, path) {
60
+ return decision.areas.some((area) => overlaps(area, path));
61
+ }
62
+ const HANDLE = /^@[A-Za-z0-9][\w.-]*$/;
63
+ export function ownerOf(config, decisions, path) {
64
+ for (const [folder, handle] of config.onboard.owners) {
65
+ if (within(path, folder))
66
+ return { handle, from: 'config' };
67
+ }
68
+ let best = null;
69
+ for (const decision of decisions) {
70
+ if (decision.kind !== 'owner')
71
+ continue;
72
+ for (const area of decision.areas) {
73
+ if (area !== EVERYWHERE && !within(path, area))
74
+ continue;
75
+ const depth = area === EVERYWHERE ? -1 : area.length;
76
+ const later = best !== null && depth === best.depth && decision.date >= best.decision.date;
77
+ if (best === null || depth > best.depth || later)
78
+ best = { decision, depth };
79
+ }
80
+ }
81
+ if (best) {
82
+ const named = best.decision.text.split(/\s+/)[0] ?? '';
83
+ return { handle: HANDLE.test(named) ? named : best.decision.owner, from: 'decision' };
84
+ }
85
+ return config.onboard.owner ? { handle: config.onboard.owner, from: 'default' } : null;
86
+ }
@@ -0,0 +1,14 @@
1
+ export declare const DECISION_KINDS: readonly ['decision', 'rule', 'trust', 'access', 'owner', 'setup'];
2
+ export type DecisionKind = (typeof DECISION_KINDS)[number];
3
+ export interface Decision {
4
+ line: number;
5
+ date: string;
6
+ owner: string;
7
+ areas: string[];
8
+ kind: DecisionKind;
9
+ text: string;
10
+ }
11
+ export declare const EVERYWHERE = "*";
12
+ export declare const DECISION_SHAPE = "- 2026-12-03 @owner [area, another/area] kind: what was decided";
13
+ export declare function parseDecisions(text: string, file: string): Decision[];
14
+ export declare function readDecisions(root: string, file: string): Decision[];
@@ -0,0 +1,53 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { AshlarError } from '../config.js';
4
+ import { tidy } from '../layout.js';
5
+ export const DECISION_KINDS = ['decision', 'rule', 'trust', 'access', 'owner', 'setup'];
6
+ export const EVERYWHERE = '*';
7
+ const LINE = /^- (\d{4}-\d{2}-\d{2}) (@[A-Za-z0-9][\w.-]*) \[([^\]]+)\] (?:(decision|rule|trust|access|owner|setup): )?(\S.*)$/;
8
+ export const DECISION_SHAPE = '- 2026-12-03 @owner [area, another/area] kind: what was decided';
9
+ const isDate = (date) => {
10
+ const at = new Date(`${date}T00:00:00Z`);
11
+ return !Number.isNaN(at.getTime()) && at.toISOString().slice(0, 10) === date;
12
+ };
13
+ export function parseDecisions(text, file) {
14
+ const decisions = [];
15
+ const problems = [];
16
+ let fenced = false;
17
+ text.split('\n').forEach((raw, i) => {
18
+ const line = raw.trimEnd();
19
+ if (/^\s*(```|~~~)/.test(line))
20
+ fenced = !fenced;
21
+ if (fenced || !line.startsWith('- '))
22
+ return;
23
+ const match = LINE.exec(line);
24
+ if (!match || !isDate(match[1])) {
25
+ problems.push(`${file}:${i + 1} isn't a decision line: ${DECISION_SHAPE}`);
26
+ return;
27
+ }
28
+ const areas = match[3]
29
+ .split(',')
30
+ .map((area) => area.trim())
31
+ .filter(Boolean)
32
+ .map((area) => (area === EVERYWHERE ? EVERYWHERE : tidy(area)));
33
+ if (areas.length === 0 || areas.includes('')) {
34
+ problems.push(`${file}:${i + 1} names no area: put a folder, a file or * in its brackets.`);
35
+ return;
36
+ }
37
+ decisions.push({
38
+ line: i + 1,
39
+ date: match[1],
40
+ owner: match[2],
41
+ areas,
42
+ kind: (match[4] ?? 'decision'),
43
+ text: match[5].trim(),
44
+ });
45
+ });
46
+ if (problems.length > 0)
47
+ throw new AshlarError(problems.join('\n'));
48
+ return decisions;
49
+ }
50
+ export function readDecisions(root, file) {
51
+ const path = join(root, file);
52
+ return existsSync(path) ? parseDecisions(readFileSync(path, 'utf8'), file) : [];
53
+ }
@@ -0,0 +1,4 @@
1
+ import type { Loaded } from '../config.ts';
2
+ import type { FolderRule } from './rules.ts';
3
+ export declare function topField(text: string, key: string): string | null;
4
+ export declare function readGuards(config: Loaded): FolderRule[];
@@ -0,0 +1,60 @@
1
+ import { readdirSync, readFileSync } from 'node:fs';
2
+ import { join, posix } from 'node:path';
3
+ import { anyOf } from '../glob.js';
4
+ import { byText } from '../order.js';
5
+ import { walkFolders } from '../workspace.js';
6
+ const unquoted = (value) => value.replace(/^(['"])(.*)\1$/, '$2');
7
+ export function topField(text, key) {
8
+ const lines = text.split('\n');
9
+ const at = lines.findIndex((line) => line.startsWith(`${key}:`));
10
+ if (at === -1)
11
+ return null;
12
+ const value = lines[at].slice(key.length + 1)
13
+ .replace(/\s+#.*$/, '')
14
+ .trim();
15
+ if (!/^[>|][-+]?$/.test(value))
16
+ return unquoted(value) || null;
17
+ const body = [];
18
+ for (const line of lines.slice(at + 1)) {
19
+ if (line.trim() && !/^\s/.test(line))
20
+ break;
21
+ body.push(line.trim());
22
+ }
23
+ const joined = value.startsWith('>') ? body.filter(Boolean).join(' ') : body.join('\n').trim();
24
+ return joined || null;
25
+ }
26
+ export function readGuards(config) {
27
+ const patterns = config.onboard.guards;
28
+ if (patterns.length === 0)
29
+ return [];
30
+ const matches = anyOf(patterns);
31
+ const skip = new Set(config.ignore);
32
+ const files = [];
33
+ const top = readdirSync(config.root, { withFileTypes: true });
34
+ for (const entry of top)
35
+ if (entry.isFile() && matches(entry.name))
36
+ files.push(entry.name);
37
+ const folders = top
38
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.') && !skip.has(entry.name))
39
+ .map((entry) => entry.name);
40
+ walkFolders(config.root, folders, skip, (file) => {
41
+ if (matches(file))
42
+ files.push(file);
43
+ });
44
+ return files.sort(byText).map((file) => {
45
+ const text = readFileSync(join(config.root, file), 'utf8');
46
+ const name = topField(text, 'name') ?? posix.basename(file);
47
+ const describe = topField(text, 'describe');
48
+ const folder = posix.dirname(file);
49
+ return {
50
+ file,
51
+ title: name,
52
+ paths: [folder === '.' ? '**' : `${folder}/**`],
53
+ gotcha: 'guard',
54
+ owner: null,
55
+ date: null,
56
+ guard: file,
57
+ text: `${describe ? `${describe} ` : ''}Rehearse guards it with the scenario \`${file}\`, on every change that reaches it.`,
58
+ };
59
+ });
60
+ }
@@ -0,0 +1,12 @@
1
+ export interface FolderRule {
2
+ file: string;
3
+ title: string;
4
+ paths: string[] | null;
5
+ gotcha: string | null;
6
+ owner: string | null;
7
+ date: string | null;
8
+ guard: string | null;
9
+ text: string;
10
+ }
11
+ export declare function parseRule(text: string, file: string): FolderRule;
12
+ export declare function readRules(root: string, folder: string): FolderRule[];
@@ -0,0 +1,100 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { AshlarError } from '../config.js';
4
+ import { tidy } from '../layout.js';
5
+ import { walkFolders } from '../workspace.js';
6
+ const FENCE = '---';
7
+ const KEYS = new Set(['paths', 'gotcha', 'guard', 'owner', 'date', 'description']);
8
+ const unquoted = (value) => value.trim().replace(/^(['"])(.*)\1$/, '$2');
9
+ function splitOutside(text) {
10
+ const parts = [];
11
+ let depth = 0;
12
+ let quote = null;
13
+ let part = '';
14
+ for (const char of text) {
15
+ if (quote) {
16
+ if (char === quote)
17
+ quote = null;
18
+ }
19
+ else if (char === '"' || char === "'")
20
+ quote = char;
21
+ else if (char === '{')
22
+ depth += 1;
23
+ else if (char === '}')
24
+ depth = Math.max(0, depth - 1);
25
+ else if (char === ',' && depth === 0) {
26
+ parts.push(part);
27
+ part = '';
28
+ continue;
29
+ }
30
+ part += char;
31
+ }
32
+ return [...parts, part];
33
+ }
34
+ function listOf(value) {
35
+ const inner = value.trim();
36
+ if (inner.startsWith('[') && inner.endsWith(']')) {
37
+ return splitOutside(inner.slice(1, -1)).map(unquoted).filter(Boolean);
38
+ }
39
+ return inner ? [unquoted(inner)] : [];
40
+ }
41
+ function frontOf(text, file) {
42
+ const lines = text.split('\n');
43
+ if (lines[0]?.trim() !== FENCE)
44
+ return { values: new Map(), paths: null, body: text };
45
+ const end = lines.findIndex((line, i) => i > 0 && line.trim() === FENCE);
46
+ if (end === -1)
47
+ throw new AshlarError(`${file}: its frontmatter opens with --- and never closes.`);
48
+ const values = new Map();
49
+ let paths = null;
50
+ let inPaths = false;
51
+ for (let i = 1; i < end; i += 1) {
52
+ const line = lines[i];
53
+ if (!line.trim() || line.trim().startsWith('#'))
54
+ continue;
55
+ const item = /^\s*-\s+(.*)$/.exec(line);
56
+ if (item && inPaths) {
57
+ paths.push(unquoted(item[1]));
58
+ continue;
59
+ }
60
+ const pair = /^([A-Za-z]+):\s*(.*)$/.exec(line);
61
+ if (!pair || !KEYS.has(pair[1])) {
62
+ throw new AshlarError(`${file}:${i + 1}: Ashlar reads only these frontmatter keys: ${[...KEYS].join(', ')}.`);
63
+ }
64
+ inPaths = pair[1] === 'paths';
65
+ if (inPaths)
66
+ paths = listOf(pair[2]);
67
+ else
68
+ values.set(pair[1], unquoted(pair[2]));
69
+ }
70
+ return { values, paths, body: lines.slice(end + 1).join('\n') };
71
+ }
72
+ function titleOf(body, file) {
73
+ const heading = /^#\s+(.+)$/m.exec(body);
74
+ return heading ? heading[1].trim() : (file.split('/').at(-1) ?? file).replace(/\.md$/, '');
75
+ }
76
+ const withoutTitle = (body) => body.replace(/^\s*#\s+.+\n?/, '');
77
+ export function parseRule(text, file) {
78
+ const front = frontOf(text, file);
79
+ const value = (key) => front.values.get(key) || null;
80
+ return {
81
+ file,
82
+ title: titleOf(front.body, file),
83
+ paths: front.paths && front.paths.length > 0 ? front.paths.map(tidy) : null,
84
+ gotcha: value('gotcha'),
85
+ owner: value('owner'),
86
+ date: value('date'),
87
+ guard: value('guard'),
88
+ text: withoutTitle(front.body).trim(),
89
+ };
90
+ }
91
+ export function readRules(root, folder) {
92
+ if (!existsSync(join(root, folder)))
93
+ return [];
94
+ const files = [];
95
+ walkFolders(root, [folder], new Set(), (file) => {
96
+ if (file.endsWith('.md'))
97
+ files.push(file);
98
+ });
99
+ return files.sort().map((file) => parseRule(readFileSync(join(root, file), 'utf8'), file));
100
+ }
@@ -0,0 +1,6 @@
1
+ export interface SecretAt {
2
+ line: number;
3
+ column: number;
4
+ kind: string;
5
+ }
6
+ export declare function secretsIn(text: string): SecretAt[];
@@ -0,0 +1,58 @@
1
+ const EDGE = '(?<![A-Za-z0-9])';
2
+ const SHAPES = [
3
+ ['a private key', /-----BEGIN [A-Z ]*PRIVATE KEY-----/g],
4
+ ['an AWS access key', new RegExp(`${EDGE}(?:AKIA|ASIA)[0-9A-Z]{16}(?![0-9A-Z])`, 'g')],
5
+ ['a GitHub token', new RegExp(`${EDGE}(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{22,})`, 'g')],
6
+ ['an npm token', new RegExp(`${EDGE}npm_[A-Za-z0-9]{30,}`, 'g')],
7
+ ['a Slack token', new RegExp(`${EDGE}xox[abprs]-[A-Za-z0-9-]{10,}`, 'g')],
8
+ ['an API key', new RegExp(`${EDGE}sk-[A-Za-z0-9_-]{20,}`, 'g')],
9
+ ['a Google API key', new RegExp(`${EDGE}AIza[0-9A-Za-z_-]{35}`, 'g')],
10
+ ['a Stripe key', new RegExp(`${EDGE}(?:sk|rk)_(?:live|test)_[0-9A-Za-z]{16,}`, 'g')],
11
+ ['a JSON web token', /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g],
12
+ ['a password in a URL', /[a-z][a-z0-9+.-]*:\/\/[^\s:/@]+:[^\s@/]{3,}@/gi],
13
+ ['a bearer token', /\bBearer\s+[A-Za-z0-9._~+/-]{16,}=*/g],
14
+ [
15
+ 'a password or token',
16
+ /(?:password|passwd|pwd|secret|token|api[_-]?key|access[_-]?key)['"]?(\s*[:=]\s*)['"]?([^\s'"`]{6,})/gi,
17
+ ],
18
+ ['a long encoded value', /[A-Za-z0-9+/_-]{40,}={0,2}/g],
19
+ ];
20
+ const HEX = /^[0-9a-f]+$/i;
21
+ const mixed = (value) => /[0-9]/.test(value) || (/[a-z]/.test(value) && /[A-Z]/.test(value));
22
+ function isEncoded(value) {
23
+ if (HEX.test(value))
24
+ return false;
25
+ const segments = value.split('/').filter(Boolean);
26
+ if (segments.length >= 3 && segments.every((segment) => segment.length <= 30))
27
+ return false;
28
+ return /[a-z]/.test(value) && /[A-Z]/.test(value) && /[0-9]/.test(value);
29
+ }
30
+ function counts(kind, match) {
31
+ if (kind === 'a long encoded value')
32
+ return isEncoded(match[0]);
33
+ if (kind === 'a password or token') {
34
+ const value = match[2] ?? '';
35
+ const assigned = !/\s/.test(match[1] ?? '');
36
+ return !value.startsWith('@') && (assigned || mixed(value));
37
+ }
38
+ return true;
39
+ }
40
+ function matchesIn(text) {
41
+ const found = [];
42
+ for (const [kind, shape] of SHAPES) {
43
+ for (const match of text.matchAll(shape)) {
44
+ if (!counts(kind, match))
45
+ continue;
46
+ const index = match.index;
47
+ const overlaps = found.some((at) => index < at.index + at.length && at.index < index + match[0].length);
48
+ if (!overlaps)
49
+ found.push({ index, length: match[0].length, kind });
50
+ }
51
+ }
52
+ return found.sort((a, b) => a.index - b.index);
53
+ }
54
+ export function secretsIn(text) {
55
+ return text
56
+ .split('\n')
57
+ .flatMap((line, i) => matchesIn(line).map((at) => ({ line: i + 1, column: at.index + 1, kind: at.kind })));
58
+ }
@@ -0,0 +1,61 @@
1
+ export type Stack = 'electron' | 'tauri' | 'web';
2
+ export type Process = 'main' | 'renderer' | 'shared';
3
+ export type Role = 'features' | 'client' | 'primitives';
4
+ export declare const STACKS: Readonly<Record<Stack, Readonly<Record<Process, string>>>>;
5
+ export declare const SERVICE_PACKAGES: Readonly<Record<Stack, readonly string[]>>;
6
+ export declare function isPackageIn(specifier: string, packages: readonly string[]): boolean;
7
+ export interface Build {
8
+ tests: string[];
9
+ reach: string[];
10
+ }
11
+ export interface Setup {
12
+ files: string[];
13
+ tests: string[];
14
+ exclude?: string[];
15
+ }
16
+ export interface AppConfig {
17
+ root: string;
18
+ stack: Stack;
19
+ main?: string[];
20
+ renderer?: string[];
21
+ shared?: string[];
22
+ features?: string[];
23
+ client?: string[];
24
+ primitives?: string[];
25
+ areas?: string[];
26
+ bridge?: {
27
+ global?: string;
28
+ modules?: string[];
29
+ packages?: string[];
30
+ };
31
+ builds?: Build[];
32
+ setups?: Setup[];
33
+ }
34
+ export interface AppLayout {
35
+ root: string;
36
+ stack: Stack;
37
+ processes: Record<Process, string[]>;
38
+ roles: Record<Role, string[]>;
39
+ areas: string[];
40
+ bridge: {
41
+ global: string | null;
42
+ modules: string[];
43
+ packages: string[];
44
+ };
45
+ builds: Build[];
46
+ setups: Setup[];
47
+ }
48
+ export interface Place {
49
+ app: AppLayout | null;
50
+ process: Process | null;
51
+ role: Role | null;
52
+ unit: string | null;
53
+ }
54
+ export declare function tidy(path: string): string;
55
+ export declare function setupsUnder(root: string, setups: Setup[]): Setup[];
56
+ export declare function appLayout(app: AppConfig): AppLayout;
57
+ export declare function within(path: string, folder: string): boolean;
58
+ export declare function unitOf(path: string, patterns: string[]): string | null;
59
+ export declare function placeOf(path: string, apps: AppLayout[]): Place;
60
+ export declare function isIndexOf(path: string, unit: string): boolean;
61
+ export declare function names(app: AppLayout): Readonly<Record<Process, string>>;
package/dist/layout.js ADDED
@@ -0,0 +1,120 @@
1
+ import { posix } from 'node:path';
2
+ export const STACKS = {
3
+ electron: { main: 'electron-main', renderer: 'electron-renderer', shared: 'shared' },
4
+ tauri: { main: 'src-tauri', renderer: 'src', shared: 'shared' },
5
+ web: { main: 'server', renderer: 'client', shared: 'shared' },
6
+ };
7
+ export const SERVICE_PACKAGES = {
8
+ electron: ['electron'],
9
+ tauri: ['@tauri-apps/api', '@tauri-apps/plugin-*'],
10
+ web: [],
11
+ };
12
+ export function isPackageIn(specifier, packages) {
13
+ return packages.some((name) => name.endsWith('*')
14
+ ? specifier.startsWith(name.slice(0, -1))
15
+ : specifier === name || specifier.startsWith(`${name}/`));
16
+ }
17
+ const NOWHERE = { app: null, process: null, role: null, unit: null };
18
+ const PROCESSES = ['main', 'renderer', 'shared'];
19
+ const ROLES = ['features', 'client', 'primitives'];
20
+ const INDEX = /^index\.(?:ts|tsx|mts|js|jsx|mjs)$/;
21
+ export function tidy(path) {
22
+ const normal = posix.normalize(path.replaceAll('\\', '/'));
23
+ return normal === '.' ? '' : normal.replace(/^\.\//, '').replace(/\/$/, '');
24
+ }
25
+ function under(root, paths) {
26
+ return paths.map((path) => tidy(posix.join(root, path)));
27
+ }
28
+ export function setupsUnder(root, setups) {
29
+ return setups.map((setup) => ({
30
+ files: under(root, setup.files),
31
+ tests: under(root, setup.tests),
32
+ exclude: under(root, setup.exclude ?? []),
33
+ }));
34
+ }
35
+ export function appLayout(app) {
36
+ const names = STACKS[app.stack];
37
+ const at = (paths) => under(app.root, paths);
38
+ const main = app.main ?? [names.main];
39
+ const renderer = app.renderer ?? [names.renderer];
40
+ const roleDefault = (role) => renderer.length === 0 ? [] : [`${names.renderer}/${role}`];
41
+ const builds = app.builds ?? [];
42
+ return {
43
+ root: tidy(app.root),
44
+ stack: app.stack,
45
+ processes: {
46
+ main: at(main),
47
+ renderer: at(renderer),
48
+ shared: at(app.shared ?? [names.shared]),
49
+ },
50
+ roles: {
51
+ features: at(app.features ?? roleDefault('features/*')),
52
+ client: at(app.client ?? roleDefault('client')),
53
+ primitives: at(app.primitives ?? roleDefault('primitives')),
54
+ },
55
+ areas: at(app.areas ?? [`${names.main}/*`]),
56
+ bridge: {
57
+ global: app.bridge?.global ?? null,
58
+ modules: at(app.bridge?.modules ?? []),
59
+ packages: app.bridge?.packages ?? [...SERVICE_PACKAGES[app.stack]],
60
+ },
61
+ builds: builds.map((build) => ({ tests: at(build.tests), reach: at(build.reach) })),
62
+ setups: setupsUnder(app.root, app.setups ?? []),
63
+ };
64
+ }
65
+ export function within(path, folder) {
66
+ return folder === '' || path === folder || path.startsWith(`${folder}/`);
67
+ }
68
+ function base(pattern) {
69
+ return pattern.endsWith('/*') ? pattern.slice(0, -2) : pattern;
70
+ }
71
+ function unitIn(path, pattern) {
72
+ if (!pattern.endsWith('/*'))
73
+ return within(path, pattern) ? pattern : null;
74
+ const parent = base(pattern);
75
+ if (!path.startsWith(`${parent}/`))
76
+ return null;
77
+ const rest = path.slice(parent.length + 1);
78
+ const slash = rest.indexOf('/');
79
+ return slash === -1 ? null : `${parent}/${rest.slice(0, slash)}`;
80
+ }
81
+ function longest(path, groups, keys) {
82
+ let best = null;
83
+ let length = -1;
84
+ for (const key of keys) {
85
+ for (const pattern of groups[key]) {
86
+ const folder = base(pattern);
87
+ if (within(path, folder) && folder.length > length) {
88
+ best = key;
89
+ length = folder.length;
90
+ }
91
+ }
92
+ }
93
+ return best;
94
+ }
95
+ export function unitOf(path, patterns) {
96
+ let best = null;
97
+ for (const pattern of patterns) {
98
+ const unit = unitIn(path, pattern);
99
+ if (unit !== null && (best === null || unit.length > best.length))
100
+ best = unit;
101
+ }
102
+ return best;
103
+ }
104
+ export function placeOf(path, apps) {
105
+ const app = apps.find((candidate) => within(path, candidate.root));
106
+ if (!app)
107
+ return NOWHERE;
108
+ return {
109
+ app,
110
+ process: longest(path, app.processes, PROCESSES),
111
+ role: longest(path, app.roles, ROLES),
112
+ unit: unitOf(path, [...app.roles.features, ...app.areas]),
113
+ };
114
+ }
115
+ export function isIndexOf(path, unit) {
116
+ return path.startsWith(`${unit}/`) && INDEX.test(path.slice(unit.length + 1));
117
+ }
118
+ export function names(app) {
119
+ return STACKS[app.stack];
120
+ }
@@ -0,0 +1,28 @@
1
+ import type { Loaded } from './config.ts';
2
+ export declare const LEDGER_FILE: string;
3
+ export declare const LEDGER_EXPORT = "./ledger.json";
4
+ export declare const CONFINED_MESSAGE = "A name the config confines appears only where it allows: read what you need from there instead.";
5
+ export interface LedgerCase {
6
+ file: string;
7
+ test: string;
8
+ }
9
+ export interface LedgerEntry {
10
+ id: string;
11
+ rule: boolean;
12
+ says: string;
13
+ applies: string;
14
+ corrected: string;
15
+ by: 'developer' | 'lead' | 'gate';
16
+ replaces: string | null;
17
+ case: LedgerCase;
18
+ message: string;
19
+ }
20
+ export interface Ledger {
21
+ version: 1;
22
+ entries: LedgerEntry[];
23
+ }
24
+ export declare function readLedger(file?: string): Ledger;
25
+ export type LedgerConfig = Pick<Loaded, 'apps' | 'maxLines' | 'confined'> & Partial<Pick<Loaded, 'messages'>>;
26
+ export declare function messageOf(entry: Pick<LedgerEntry, 'id' | 'rule' | 'says'>, config: LedgerConfig): string;
27
+ export declare function ledgerOf(config: LedgerConfig): LedgerEntry[];
28
+ export declare function ledgerText(entries: readonly LedgerEntry[]): string;
package/dist/ledger.js ADDED
@@ -0,0 +1,44 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { crossProcess, maxLines, MESSAGES } from './plugin/messages.js';
4
+ import { FEATURE_REACH } from './reach.js';
5
+ export const LEDGER_FILE = fileURLToPath(new URL('../ledger.json', import.meta.url));
6
+ export const LEDGER_EXPORT = './ledger.json';
7
+ export const CONFINED_MESSAGE = 'A name the config confines appears only where it allows: read what you need from there instead.';
8
+ export function readLedger(file = LEDGER_FILE) {
9
+ return JSON.parse(readFileSync(file, 'utf8'));
10
+ }
11
+ export function messageOf(entry, config) {
12
+ if (!entry.rule)
13
+ return `${entry.says}.`;
14
+ const said = config.messages?.[entry.id];
15
+ if (said)
16
+ return said;
17
+ switch (entry.id) {
18
+ case 'no-cross-process-import':
19
+ return crossProcess(config.apps[0] ?? null);
20
+ case 'max-lines':
21
+ return maxLines(config.maxLines);
22
+ case 'feature-reach':
23
+ return FEATURE_REACH.message;
24
+ case 'named-only-in':
25
+ return config.confined[0]?.message ?? CONFINED_MESSAGE;
26
+ default:
27
+ return MESSAGES[entry.id];
28
+ }
29
+ }
30
+ export function ledgerOf(config) {
31
+ return readLedger().entries.map((entry) => ({ ...entry, message: messageOf(entry, config) }));
32
+ }
33
+ export function ledgerText(entries) {
34
+ return entries
35
+ .map((entry) => [
36
+ `${entry.id}: ${entry.says}, in ${entry.applies}.`,
37
+ ` It corrected: ${entry.corrected}.`,
38
+ ` Its case: ${entry.case.file}, “${entry.case.test}”.`,
39
+ ...(entry.replaces ? [` It replaced: “${entry.replaces}.”`] : []),
40
+ ` ${entry.message}`,
41
+ ].join('\n'))
42
+ .map((block) => `${block}\n`)
43
+ .join('\n');
44
+ }
package/dist/lint.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { type Loaded } from './config.ts';
2
+ import type { LintRule } from './plugin/messages.ts';
3
+ import type { Edge, FileFindings } from './plugin/types.ts';
4
+ import { type Workspace } from './workspace.ts';
5
+ export interface Linted {
6
+ files: Record<string, FileFindings>;
7
+ seconds: number;
8
+ }
9
+ export declare function workspaceOf(config: Loaded): Workspace;
10
+ export declare function lint(config: Loaded, rules: readonly (LintRule | 'graph')[], workspace?: Workspace): Linted;
11
+ export declare function edgesOf(files: Record<string, FileFindings>): Map<string, Edge[]>;