@rt-tools/agent-kit 0.27.0 → 0.28.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 (79) hide show
  1. package/assets/checks/board-epic-plan.github.mjs +86 -0
  2. package/assets/checks/board-epics.github.mjs +12 -67
  3. package/assets/checks/board-pull-state.github.mjs +6 -11
  4. package/assets/checks/check-glossary.mjs +10 -2
  5. package/assets/checks/check-lib-layers.mjs +24 -1
  6. package/assets/checks/check-reuse.mjs +26 -2
  7. package/assets/checks/check-specs.mjs +8 -1
  8. package/assets/checks/lib-boundaries.mjs +2 -2
  9. package/assets/checks/lib-common.mjs +46 -0
  10. package/assets/checks/lib-manifests.mjs +18 -13
  11. package/assets/checks/rt-kit-checks.config.mjs +6 -0
  12. package/assets/checks/signals.mjs +39 -5
  13. package/assets/checks/spec-anchors.mjs +48 -4
  14. package/assets/checks/spec-common.mjs +40 -6
  15. package/assets/checks/spec-contract.mjs +33 -7
  16. package/assets/checks/spec-scenarios.mjs +24 -1
  17. package/assets/checks/task-new.github.mjs +9 -3
  18. package/assets/defaults/gate-map.sh +20 -5
  19. package/assets/defaults/project.sh +6 -0
  20. package/assets/hooks/dev-server-guard.sh +61 -32
  21. package/assets/hooks/exam-guard.sh +10 -10
  22. package/assets/hooks/git-guard-delivery-conflict.sh +53 -1
  23. package/assets/hooks/git-guard-delivery-draft.sh +7 -6
  24. package/assets/hooks/git-guard-delivery-tree.sh +50 -0
  25. package/assets/hooks/git-guard-delivery.sh +43 -23
  26. package/assets/hooks/git-guard-discard.sh +144 -0
  27. package/assets/hooks/git-guard-push-tests.sh +36 -16
  28. package/assets/hooks/reuse-first-guard.sh +29 -4
  29. package/assets/hooks/rule-source-guard.sh +17 -2
  30. package/assets/hooks/skill-gate.sh +7 -0
  31. package/assets/hooks/sql-guard-write.sh +18 -2
  32. package/assets/hooks/turn-exit-guard.sh +50 -66
  33. package/assets/hooks/turn-exit-patterns.sh +18 -1
  34. package/assets/hooks/turn-exit-verdict.sh +84 -0
  35. package/assets/laws/delivery.md +14 -6
  36. package/assets/laws/verifiability.md +22 -4
  37. package/assets/patterns/git-workflow-pr.github.md +39 -18
  38. package/assets/patterns/git-workflow-stack.md +21 -2
  39. package/assets/patterns/task-flow-close.md +65 -78
  40. package/assets/patterns/ts-procedure.md +6 -0
  41. package/assets/pitfalls/git-workflow.github.md +38 -0
  42. package/assets/pitfalls/task-flow.md +25 -23
  43. package/assets/rules/browser-verification.md +8 -0
  44. package/assets/rules/deploy-flow.github.md +6 -0
  45. package/assets/rules/doc-style.md +6 -0
  46. package/assets/rules/git-workflow.azure.md +10 -0
  47. package/assets/rules/git-workflow.github.md +119 -119
  48. package/assets/rules/git-workflow.gitlab.md +10 -0
  49. package/assets/rules/lib-layers.md +11 -0
  50. package/assets/rules/spec-driven.md +10 -1
  51. package/assets/rules/task-flow.md +59 -56
  52. package/assets/rules/testing.md +7 -0
  53. package/assets/rules/turn-conduct.md +23 -3
  54. package/assets/samples/tasks/_template/plan.md +4 -1
  55. package/assets/skills/agent-kit.md +17 -4
  56. package/bin/agent-kit.js +1 -1
  57. package/bin/agent-kit.js.map +1 -1
  58. package/lib/commands.d.ts +1 -1
  59. package/lib/commands.d.ts.map +1 -1
  60. package/lib/commands.js +59 -2
  61. package/lib/commands.js.map +1 -1
  62. package/lib/hooks-map.d.ts +5 -0
  63. package/lib/hooks-map.d.ts.map +1 -1
  64. package/lib/hooks-map.js +9 -3
  65. package/lib/hooks-map.js.map +1 -1
  66. package/lib/plan.d.ts +2 -0
  67. package/lib/plan.d.ts.map +1 -1
  68. package/lib/plan.js +8 -0
  69. package/lib/plan.js.map +1 -1
  70. package/lib/proposals.d.ts +25 -0
  71. package/lib/proposals.d.ts.map +1 -1
  72. package/lib/proposals.js +43 -1
  73. package/lib/proposals.js.map +1 -1
  74. package/lib/shipment.d.ts.map +1 -1
  75. package/lib/shipment.js +8 -11
  76. package/lib/shipment.js.map +1 -1
  77. package/package.json +1 -1
  78. package/rt-tools-agent-kit-0.28.0.tgz +0 -0
  79. package/rt-tools-agent-kit-0.27.0.tgz +0 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The plan of an epic named by its own card: which of the paths in the body is the plan.
3
+ *
4
+ * A file of its own because two readers need it at once — the queue audit and the creating command
5
+ * — and they lie in different layers. Read in two places, the choice diverges silently: the audit
6
+ * takes the document that carries the makeup, while the command took the first path in the body,
7
+ * and a card that names a law before its plan then wrote the law into every task of the epic as its
8
+ * plan. Both sides answered as usual, and the miss showed only from a third side — by reading a
9
+ * created task.
10
+ */
11
+ import { existsSync, readFileSync } from 'node:fs';
12
+ import { join } from 'node:path';
13
+
14
+ import { ROOT } from './rt-kit-checks.config.mjs';
15
+
16
+ /** A path counts as a spelling with a directory: a bare file name occurs in the body in prose. */
17
+ const PATH_IN_BODY = /(?:^|[\s(`])([\w.-]+(?:\/[\w.-]+)+\.md)/g;
18
+
19
+ /**
20
+ * The rows of the epic makeup — those standing in the table with the task column.
21
+ *
22
+ * The epic plan holds other tables too: the sources of findings, the makeup of families, the count
23
+ * of items. Numbers taken from the whole text, and even from all the tables, would make an epic
24
+ * task out of everything it mentioned — the previous epic its findings grew from, a review, a task
25
+ * of a neighbouring tree.
26
+ */
27
+ export function planRows(plan) {
28
+ const rows = [];
29
+ let inside = false;
30
+ for (const line of plan.split('\n')) {
31
+ const isRow = line.trimStart().startsWith('|');
32
+ if (!isRow) {
33
+ inside = false;
34
+ continue;
35
+ }
36
+ if (!inside) {
37
+ // The column has two names, English and the owner's: a tree translates its plans one at
38
+ // a time, and one name would take the untranslated epics out of the check silently. A
39
+ // word boundary is no good here either: `\b` knows only Latin letters and never matches
40
+ // Cyrillic — the check would stay silent on any plan.
41
+ inside = /\|[^|]*(?:Task|Задача)/.test(line);
42
+ continue;
43
+ }
44
+ rows.push(line);
45
+ }
46
+
47
+ return rows.join('\n');
48
+ }
49
+
50
+ /**
51
+ * The plan of an epic named by its own card, and the reason there is none.
52
+ *
53
+ * The plan is the document that carries the makeup, not the first path in the body. A card names
54
+ * its decision next to its plan, and the decision has no table of tasks: read as the plan, it made
55
+ * the makeup empty and every open task of the epic read as not belonging to it — fourteen false
56
+ * lines at once, and the true ones drowned among them.
57
+ */
58
+ export function planPathOf(body, { makeupRequired = true } = {}) {
59
+ const named = [...String(body ?? '').matchAll(PATH_IN_BODY)].map((match) => match[1]);
60
+ if (named.length === 0) {
61
+ return { path: null, why: 'the epic card names no path to the plan — there is nowhere to read what the epic holds' };
62
+ }
63
+
64
+ const onDisk = named.filter((path) => existsSync(join(ROOT, path)));
65
+ if (onDisk.length === 0) {
66
+ return { path: null, why: `the epic plan «${named[0]}» is not on disk — the card points into emptiness` };
67
+ }
68
+
69
+ const carrying = onDisk.find((path) => planRows(readFileSync(join(ROOT, path), 'utf8')) !== '') ?? null;
70
+ if (carrying !== null) {
71
+ return { path: carrying, why: '' };
72
+ }
73
+
74
+ // The makeup is not demanded of the creating command: it creates the tasks of an epic, and the
75
+ // numbers land in the plan by the same edit — that is, after. Demanded here, the requirement
76
+ // would refuse the very first task of every epic, and there would be no way to create one at
77
+ // all. The audit runs later and demands it: by its minute the numbers stand in the plan.
78
+ if (!makeupRequired) {
79
+ return { path: onDisk[0], why: '' };
80
+ }
81
+
82
+ return {
83
+ path: null,
84
+ why: `none of the documents the card names carries the makeup of the epic — «${onDisk.join('», «')}». The makeup is a table with a task column`,
85
+ };
86
+ }
@@ -2,10 +2,11 @@
2
2
  * The link between a task and an epic. Lives in a file of its own: the work queue audit stands at
3
3
  * the length limit even without it, and these two checks are read separately.
4
4
  */
5
- import { existsSync, readFileSync } from 'node:fs';
5
+ import { readFileSync } from 'node:fs';
6
6
  import { join } from 'node:path';
7
7
 
8
8
  import { declaredEpicOf } from './board-epic-link.mjs';
9
+ import { planPathOf, planRows } from './board-epic-plan.mjs';
9
10
  import { ghJson, numberFromTitle, OfflineError, OWNER, REPO, TASK_KEY } from './board.mjs';
10
11
  import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
11
12
 
@@ -14,77 +15,15 @@ import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
14
15
  * tell an epic card from an ordinary task by.
15
16
  */
16
17
  // Чтение объявления переехало в свой модуль, а звали его отсюда: имя оставлено на прежнем месте,
17
- // чтобы соседям не пришлось знать о переезде.
18
- export { declaredEpicOf };
18
+ // чтобы соседям не пришлось знать о переезде. Тем же ходом переехал выбор документа замысла — его
19
+ // читает и команда заведения задачи.
20
+ export { declaredEpicOf, planPathOf, planRows };
19
21
 
20
22
  const EPIC_LABEL = CONFIG.board?.epicLabel ?? '';
21
23
 
22
24
  /** The labels of the cargo of the trees: those records are not tasks and are not judged as such. */
23
25
  const CARGO_LABELS = CONFIG.board?.cargoLabels ?? [];
24
26
 
25
- /**
26
- * The rows of the epic makeup — those standing in the table with the task column.
27
- *
28
- * The epic plan holds other tables too: the sources of findings, the makeup of families, the count
29
- * of items. Numbers taken from the whole text, and even from all the tables, would make an epic
30
- * task out of everything it mentioned — the previous epic its findings grew from, a review, a task
31
- * of a neighbouring tree.
32
- */
33
- export function planRows(plan) {
34
- const rows = [];
35
- let inside = false;
36
- for (const line of plan.split('\n')) {
37
- const isRow = line.trimStart().startsWith('|');
38
- if (!isRow) {
39
- inside = false;
40
- continue;
41
- }
42
- if (!inside) {
43
- // The column has two names, English and the owner's: a tree translates its plans one at
44
- // a time, and one name would take the untranslated epics out of the check silently. A
45
- // word boundary is no good here either: `\b` knows only Latin letters and never matches
46
- // Cyrillic — the check would stay silent on any plan.
47
- inside = /\|[^|]*(?:Task|Задача)/.test(line);
48
- continue;
49
- }
50
- rows.push(line);
51
- }
52
- return rows.join('\n');
53
- }
54
-
55
- /**
56
- * The plan of an epic named by its own card, and the reason there is none.
57
- *
58
- * The plan is the document that carries the makeup, not the first path in the body. A card names
59
- * its decision next to its plan, and the decision has no table of tasks: read as the plan, it made
60
- * the makeup empty and every open task of the epic read as not belonging to it — fourteen false
61
- * lines at once, and the true ones drowned among them.
62
- *
63
- * A path counts as a spelling with a directory: a bare file name occurs in the body in prose and
64
- * would lead the reader to the very first mention.
65
- */
66
- export function planPathOf(body) {
67
- const named = [...String(body ?? '').matchAll(/(?:^|[\s(`])([\w.-]+(?:\/[\w.-]+)+\.md)/g)].map((match) => match[1]);
68
- if (named.length === 0) {
69
- return { path: null, why: 'the epic card names no path to the plan — there is nowhere to read what the epic holds' };
70
- }
71
-
72
- const onDisk = named.filter((path) => existsSync(join(ROOT, path)));
73
- if (onDisk.length === 0) {
74
- return { path: null, why: `the epic plan «${named[0]}» is not on disk — the card points into emptiness` };
75
- }
76
-
77
- const carrying = onDisk.find((path) => planRows(readFileSync(join(ROOT, path), 'utf8')) !== '') ?? null;
78
- if (carrying === null) {
79
- return {
80
- path: null,
81
- why: `none of the documents the card names carries the makeup of the epic — «${onDisk.join('», «')}». The makeup is a table with a task column`,
82
- };
83
- }
84
-
85
- return { path: carrying, why: '' };
86
- }
87
-
88
27
  /**
89
28
  * The link between a task and an epic, read in both directions.
90
29
  *
@@ -241,7 +180,13 @@ export function checkEpicSubIssues(open, report, options) {
241
180
 
242
181
  let linked;
243
182
  try {
244
- linked = new Set(ghJson(['api', `repos/${OWNER}/${REPO}/issues/${epic.number}/sub_issues`, '--jq', '[.[].number]'], options));
183
+ // The list comes in pages, and an epic outgrows one page long before it is closed.
184
+ // Read by the first page alone, the audit calls a linked task unlinked: the line
185
+ // then stands in every run, the eye stops reading it, and a real divergence rides
186
+ // past together with it.
187
+ linked = new Set(
188
+ ghJson(['api', '--paginate', `repos/${OWNER}/${REPO}/issues/${epic.number}/sub_issues`, '--jq', '[.[].number]'], options)
189
+ );
245
190
  } catch (error) {
246
191
  if (error instanceof OfflineError) {
247
192
  throw error;
@@ -64,18 +64,13 @@ export function checkHeadRun(pull, report, mainBranch, options) {
64
64
  return;
65
65
  }
66
66
 
67
- // A PR on top of a neighbouring one gets no run: the workflow listens for PRs into the main
68
- // branch and does not see events with another base. The line about a lost event is wrong
69
- // here twice: the event was not lost, and closing and reopening will not bring it back — the
70
- // advice is followed literally, no run starts, and on the second try the breakage is looked
71
- // for in the hosting.
67
+ // A PR whose base is not the main branch gets no run at all: the workflow listens for PRs
68
+ // into the main branch and does not see events with another base. That is the order of
69
+ // handing in, not a discrepancy — every task of an epic is handed in exactly so — and the
70
+ // audit says nothing about it. The former line was wrong three times over: the event was not
71
+ // lost, reopening will not bring it back, and the base of a task request stays the epic
72
+ // branch to the merge.
72
73
  if (pull.baseRefName && pull.baseRefName !== mainBranch) {
73
- report(
74
- `PR #${pull.number}: there is no run on the tip ${pull.headRefOid.slice(0, 8)} and there will be none — ` +
75
- `the request is opened into the branch «${pull.baseRefName}», and the workflow listens to requests into the main one; ` +
76
- `move the base to «${mainBranch}» once the lower request is merged`
77
- );
78
-
79
74
  return;
80
75
  }
81
76
 
@@ -45,6 +45,13 @@ const GLOSSARY = 'docs/GLOSSARY.md';
45
45
  const SECTIONS = ['## Not written here', '## Так не пишем'];
46
46
  /** A pair of the glossary: `- **left** — right`. On the left there may be several words by comma. */
47
47
  const PAIR = /^-\s+\*\*(.+?)\*\*\s+—/;
48
+ /**
49
+ * The same pair written as a table row: `| left | right |`. The form is the tree's to choose, and a
50
+ * section set as a table used to read as empty — the check then declared a skip and stood in the
51
+ * gate next to the passed ones without judging a single word. The header row and the delimiter row
52
+ * are sifted out by the same expression: neither holds a word in bold or in backticks.
53
+ */
54
+ const ROW = /^\|\s*(?:\*\*(.+?)\*\*|`(.+?)`)\s*\|/;
48
55
  /** A bracketed clarification at a word: one meaning of two is forbidden, and search cannot part them. */
49
56
  const HINT = /\([^)]*\)\s*$/;
50
57
 
@@ -73,11 +80,12 @@ function forbiddenWords(text) {
73
80
  if (line.startsWith('## ')) {
74
81
  break;
75
82
  }
76
- const found = PAIR.exec(line);
83
+ const found = PAIR.exec(line) ?? ROW.exec(line);
77
84
  if (!found) {
78
85
  continue;
79
86
  }
80
- for (const part of found[1].split(',')) {
87
+ const left = found[1] ?? found[2] ?? found[3];
88
+ for (const part of left.split(',')) {
81
89
  const word = part.trim();
82
90
  if (!word) {
83
91
  continue;
@@ -23,7 +23,7 @@ import { existsSync } from 'node:fs';
23
23
  import { join } from 'node:path';
24
24
 
25
25
  import { checkBoundaries, checkCoreLibs, checkNoDependencyLibs } from './lib-boundaries.mjs';
26
- import { LIB_ROOTS, isDir, problems, report } from './lib-common.mjs';
26
+ import { FAMILIES, LIBS_ROOT, LIB_ROOTS, isDir, problems, report } from './lib-common.mjs';
27
27
  import { collectAllDomainLibs, collectApiDomainLibs, collectFlatLibs, collectStrayLibs } from './lib-domains.mjs';
28
28
  import { checkAliases, checkLib } from './lib-manifests.mjs';
29
29
  import { checkReexports } from './lib-reexports.mjs';
@@ -37,11 +37,34 @@ skipUnless(
37
37
  `the layout of the libs ${LIB_ROOTS.join(', ')} or the file tsconfig.base.json`
38
38
  );
39
39
 
40
+ // A family named in the settings whose directory the tree does not hold. The walk goes past it in
41
+ // silence, and the answer comes out the same as an honest one: the check reads the names of the
42
+ // families from the settings, and a tree that renamed one keeps the package default. The whole
43
+ // absence of the layout is another matter — it is the skip above.
44
+ const lost = FAMILIES.filter((family) => !isDir(`${LIBS_ROOT}/${family}`));
45
+ if (lost.length > 0) {
46
+ console.error(`check-lib-layers: the family «${lost.join('», «')}» is declared by the key «families», and the tree holds no ${lost.map((family) => `${LIBS_ROOT}/${family}`).join(', ')}\n`);
47
+ console.error(' A family walked past in silence answers exactly like an honest zero. Either the directory is named otherwise — then the key is fixed — or the family is gone, and its name leaves the key.');
48
+ process.exit(1);
49
+ }
50
+
40
51
  const domainLibs = collectAllDomainLibs();
41
52
  const apiLibs = collectApiDomainLibs();
42
53
  const flatLibs = collectFlatLibs();
43
54
  const strays = collectStrayLibs([...domainLibs, ...apiLibs]);
44
55
 
56
+ // A walk that met not a single lib is a refusal, not a green answer. The skip above says the tree
57
+ // has no lib layout at all; here the roots are in place, and the walk came back empty — the domains
58
+ // lie a level deeper, the settings named an empty list of families, or a lib carries no
59
+ // `project.json` and is therefore not a lib to this check. The line «0 libs, no divergences» is
60
+ // indistinguishable from an honest zero, and the check stands in the push gate: its silence reads
61
+ // as its green answer.
62
+ if (domainLibs.length + apiLibs.length + flatLibs.length === 0) {
63
+ console.error(`check-lib-layers: not a single lib was met over the roots ${LIB_ROOTS.join(', ')}\n`);
64
+ console.error(' The check would answer «no divergences» without having read a lib. The roots are named by the keys «libsRoot», «families» and «apiFamily» of the checks config; a lib is recognised by its `project.json`.');
65
+ process.exit(1);
66
+ }
67
+
45
68
  strays.forEach((path) => report(path, `the lib is outside the domain grid and is not listed in ${allowlistOf('lib-layers')}`));
46
69
  domainLibs.forEach((libPath) => checkLib(libPath));
47
70
  apiLibs.forEach((libPath) => checkLib(libPath, { requirePrefix: false }));
@@ -11,7 +11,9 @@
11
11
  * The signs do not lie here: they are declared as bundles per package of rt-tools, and the tree
12
12
  * names in the setting of the checks the ones it takes. The same list is read by the guard — they
13
13
  * must not diverge, otherwise an edit passes the guard and falls on the gate. Its own signs the
14
- * tree appends by a file of its own.
14
+ * tree appends by a file of its own. A bundle is declared with the area of the tree it holds over:
15
+ * an application assembled from another set of ready-made code drops out of the walk by the
16
+ * declaration, not by the tree declining to declare the bundle at all.
15
17
  *
16
18
  * There are two differences from the guard. The first: the inventory of the kit is not read — the
17
19
  * guard asks the disk because it answers for one edit, while a sweeping check cares about what has
@@ -112,6 +114,21 @@ function withoutMarked(text) {
112
114
  return lines.filter((line, index) => !line.includes('native-ok') && !lines[index - 1]?.includes('native-ok')).join('\n');
113
115
  }
114
116
 
117
+ /**
118
+ * Whether the file lies in the area the sign was declared with.
119
+ *
120
+ * The boundary is judged by the directory, not by the beginning of the string: `apps/admin` must
121
+ * not take in `apps/administration`, otherwise a neighbouring application gets judged by a set of
122
+ * ready-made code it was never assembled from. A sign without an area holds over the whole tree.
123
+ */
124
+ function within(path, roots) {
125
+ if (!roots || roots.length === 0) {
126
+ return true;
127
+ }
128
+
129
+ return roots.some((area) => path === area || path.startsWith(area.endsWith('/') ? area : `${area}/`));
130
+ }
131
+
115
132
  const allowlist = parseAllowlist('reuse');
116
133
  const known = allowlist.keys;
117
134
  const debt = new Set(allowlist.debt.keys());
@@ -126,7 +143,14 @@ for (const root of SOURCE_ROOTS) {
126
143
  // itself takes the folders of the source of that ready-made out from under the sign,
127
144
  // not the bundle whole.
128
145
  const excluded = signal.exceptNamed && new RegExp(signal.exceptNamed).test(path);
129
- if (!path.endsWith(signal.ext) || skipped || excluded || (signal.onlyNamed && !new RegExp(signal.onlyNamed).test(path))) {
146
+ const outside = !within(path, signal.roots);
147
+ if (
148
+ !path.endsWith(signal.ext) ||
149
+ skipped ||
150
+ excluded ||
151
+ outside ||
152
+ (signal.onlyNamed && !new RegExp(signal.onlyNamed).test(path))
153
+ ) {
130
154
  continue;
131
155
  }
132
156
  const times = found(signal, text);
@@ -52,7 +52,7 @@ import { checkRuleImplementation, checkSpecLaws, checkTracedAnchors } from './sp
52
52
  import { CONSTITUTION_DIR, REQUIRED_HEADINGS, SPECS_DIR, collectDomains, exists, problems, read, report, walk } from './spec-common.mjs';
53
53
  import { checkContract, checkRefusalCodes, procedureRootsOf } from './spec-contract.mjs';
54
54
  import { proposedGroups, staleProposed } from './spec-proposed.mjs';
55
- import { collectReferences, parseScenarios, promisesScreen } from './spec-scenarios.mjs';
55
+ import { collectReferences, parseScenarios, promisesScreen, unparsedHeadings } from './spec-scenarios.mjs';
56
56
 
57
57
  // ── run ───────────────────────────────────────────────────────────────────────
58
58
 
@@ -158,6 +158,13 @@ for (const domain of domains) {
158
158
 
159
159
  const found = walk(base, (name) => name === 'scenarios.md').flatMap(parseScenarios);
160
160
 
161
+ // A heading the template did not take starts no scenario and, left unnamed, takes it out of
162
+ // the count silently: the coverage marks under it are not read either, and a test referring to
163
+ // its number does not turn red — references are looked for among the parsed ones.
164
+ for (const heading of walk(base, (name) => name === 'scenarios.md').flatMap(unparsedHeadings)) {
165
+ report(`${heading.file}:${heading.line}`, `the scenario heading is not taken by the template and counts as ordinary prose: ${heading.text}`);
166
+ }
167
+
161
168
  // The prefix belongs to the domain together with its subdomains, not to a separate directory.
162
169
  // A domain is split when its spec has outgrown the length limit, and the scenarios move into
163
170
  // the subdomains unchanged: the number is the only thing binding a scenario to a test title,
@@ -9,7 +9,7 @@
9
9
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
 
12
- import { BOUNDARIES_DIR, FAMILIES, isDir, projectTag, report } from './lib-common.mjs';
12
+ import { BOUNDARIES_DIR, FAMILIES, isDir, libTag, report } from './lib-common.mjs';
13
13
  import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
14
14
 
15
15
  /**
@@ -29,7 +29,7 @@ function checkBoundaries(libs) {
29
29
  const sources = files.map((name) => ({ name, text: readFileSync(join(ROOT, BOUNDARIES_DIR, name), 'utf8') }));
30
30
 
31
31
  for (const libPath of libs) {
32
- const tag = projectTag(libPath);
32
+ const tag = libTag(libPath);
33
33
  const declaration = `sourceTag: '${tag}'`;
34
34
  const owners = sources.flatMap(({ name, text }) => {
35
35
  const count = text.split(declaration).length - 1;
@@ -101,10 +101,52 @@ const isSingleLayerDomain = (path) => matches(pathsOf('singleLayerDomains'), pat
101
101
  /** Paths the lib walk must skip */
102
102
  const isIgnoredLib = (path) => isNotDomain(path) || isLegacyDomain(path) || isLegacyLib(path);
103
103
 
104
+ /**
105
+ * The formula: what the name, the tag and the alias of a lib must become where the tree declared
106
+ * nothing. It is not the name itself — the name is what the tree wrote down. A tree that names its
107
+ * libs otherwise used to redden on flat ground, and the only way to silence that was the exceptions
108
+ * list.
109
+ */
104
110
  const projectName = (libPath) => libPath.replace(/^libs\//, '').replaceAll('/', '-');
105
111
  const projectTag = (libPath) => `scope:${projectName(libPath)}`;
106
112
  const importAlias = (libPath) => `${CONFIG.importScope}/${libPath.slice(`${LIBS_ROOT}/`.length)}`;
107
113
 
114
+ /** The name the lib declared in its manifest; an empty string when it declared none. */
115
+ function declaredName(libPath) {
116
+ if (!existsSync(join(ROOT, libPath, 'project.json'))) {
117
+ return '';
118
+ }
119
+ try {
120
+ return String(readJson(`${libPath}/project.json`).name ?? '');
121
+ } catch {
122
+ // Unreadable JSON is the business of the manifest check, and it says so in its own words:
123
+ // here a refusal would take down the whole walk over the neighbouring libs as well.
124
+ return '';
125
+ }
126
+ }
127
+
128
+ /** The name of the lib: the declared one, and the formula only where nothing is declared. */
129
+ const libName = (libPath) => declaredName(libPath) || projectName(libPath);
130
+ /** The tag of the lib: derived from its own name, not from its path. */
131
+ const libTag = (libPath) => `scope:${libName(libPath)}`;
132
+
133
+ /**
134
+ * The alias `tsconfig.base.json` points at this lib by. It is looked for by what it points at, not
135
+ * by its spelling: a lib is reachable by an alias or it is not, and how the tree spells the alias is
136
+ * the tree's own business. An empty string means no alias points here.
137
+ */
138
+ function declaredAlias(libPath) {
139
+ const target = `./${libPath}/src/index.ts`;
140
+ let paths = {};
141
+ try {
142
+ paths = readJson('tsconfig.base.json').compilerOptions.paths ?? {};
143
+ } catch {
144
+ return '';
145
+ }
146
+
147
+ return Object.keys(paths).find((alias) => paths[alias]?.[0] === target) ?? '';
148
+ }
149
+
108
150
  /**
109
151
  * The files of a lib, except the barrel: an empty layer has a barrel just as a filled one does, and
110
152
  * an empty layer cannot be told from a filled one by it.
@@ -157,5 +199,9 @@ export {
157
199
  projectName,
158
200
  projectTag,
159
201
  importAlias,
202
+ declaredName,
203
+ declaredAlias,
204
+ libName,
205
+ libTag,
160
206
  sourceCount,
161
207
  };
@@ -9,7 +9,7 @@
9
9
  import { existsSync } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
 
12
- import { LIB_PREFIX, REQUIRED_FILES, importAlias, projectName, projectTag, readJson, report } from './lib-common.mjs';
12
+ import { LIB_PREFIX, REQUIRED_FILES, declaredAlias, importAlias, libTag, projectName, readJson, report } from './lib-common.mjs';
13
13
  import { ROOT } from './rt-kit-checks.config.mjs';
14
14
 
15
15
  function checkLib(libPath, { requirePrefix = true } = {}) {
@@ -24,8 +24,11 @@ function checkLib(libPath, { requirePrefix = true } = {}) {
24
24
  }
25
25
 
26
26
  const project = readJson(`${libPath}/project.json`);
27
- if (project.name !== projectName(libPath)) {
28
- report(libPath, `the project name «${project.name}» does not match the path, expected «${projectName(libPath)}»`);
27
+ // The name the tree wrote down is the name. The formula speaks only where nothing is written:
28
+ // it says what the name must become, and judging a declared name by it reddens a lib that
29
+ // breaks nothing.
30
+ if (!project.name) {
31
+ report(libPath, `the manifest declares no project name, and by the path it must be «${projectName(libPath)}»`);
29
32
  }
30
33
  if (project.sourceRoot !== `${libPath}/src`) {
31
34
  report(libPath, `sourceRoot «${project.sourceRoot}» does not match the path`);
@@ -38,23 +41,25 @@ function checkLib(libPath, { requirePrefix = true } = {}) {
38
41
  report(libPath, `prefix «${project.prefix}» instead of the mandatory «${LIB_PREFIX}»`);
39
42
  }
40
43
 
44
+ // One tag per lib stays mandatory — the linter boundaries are built on it — and the tag is
45
+ // judged against the lib's own name, not against its path.
41
46
  const tags = project.tags ?? [];
42
47
  if (tags.length !== 1) {
43
- report(libPath, `tags ${tags.length}, and there must be exactly one: ${projectTag(libPath)}`);
44
- } else if (tags[0] !== projectTag(libPath)) {
45
- report(libPath, `the tag «${tags[0]}» does not match the path, expected «${projectTag(libPath)}»`);
48
+ report(libPath, `tags ${tags.length}, and there must be exactly one: ${libTag(libPath)}`);
49
+ } else if (tags[0] !== libTag(libPath)) {
50
+ report(libPath, `the tag «${tags[0]}» does not match the name of the lib, expected «${libTag(libPath)}»`);
46
51
  }
47
52
  }
48
53
 
54
+ /**
55
+ * Every lib is reachable by an alias. Which alias is the tree's own business: it is looked for by
56
+ * what it points at, and its spelling is judged by nothing. A lib nothing points at is named
57
+ * together with the alias the formula would give it.
58
+ */
49
59
  function checkAliases(libs) {
50
- const paths = readJson('tsconfig.base.json').compilerOptions.paths;
51
60
  for (const libPath of libs) {
52
- const alias = importAlias(libPath);
53
- const target = `./${libPath}/src/index.ts`;
54
- if (!paths[alias]) {
55
- report(libPath, `tsconfig.base.json has no alias ${alias}`);
56
- } else if (paths[alias][0] !== target) {
57
- report(libPath, `the alias ${alias} points at ${paths[alias][0]}, not at ${target}`);
61
+ if (declaredAlias(libPath) === '') {
62
+ report(libPath, `tsconfig.base.json names no alias pointing at ./${libPath}/src/index.ts, and by the path it must be ${importAlias(libPath)}`);
58
63
  }
59
64
  }
60
65
  }
@@ -74,6 +74,12 @@ const DEFAULTS = {
74
74
  * those it installs: a sign about ready-made code from a package the tree does not have
75
75
  * answers falsely. Empty — there are no signs at all, and the guard and the check say so
76
76
  * rather than stay silent.
77
+ *
78
+ * A bundle is named either by the name alone or by a pair of the name and the area of the tree
79
+ * it holds over: `{ "name": "ui-kit-v2", "roots": ["apps/admin"] }`. A tree with two sources of
80
+ * look judges each application by its own bundle; without an area it would have a single move —
81
+ * not to declare the bundle at all, and then nothing catches a bypass of the ready-made where
82
+ * the bundle does hold.
77
83
  */
78
84
  reuse: { bundles: [], signals: '' },
79
85
  /** Where the domain specs lie; empty — the tree has none, and the spec audit is not run. */
@@ -38,14 +38,38 @@ function parseSignals(text) {
38
38
  return JSON.parse(text.replace(/^#[^\n]*\n/, '')).signals ?? [];
39
39
  }
40
40
 
41
- function readBundle(name) {
42
- const path = join(BUNDLES_DIR, `${name}.json`);
43
- if (!existsSync(path)) {
41
+ /**
42
+ * The name of a bundle and the area of the tree it applies to.
43
+ *
44
+ * A bundle is declared either by the name alone or by a pair of the name and the area — a directory
45
+ * or a list of them. There is more than one source of look in a tree oftener than one: the owner
46
+ * panel is assembled from one set of ready-made code, the public site from another, and a sign of
47
+ * the first answers falsely over the second. Without an area such a tree has a single move — not to
48
+ * declare the bundle at all, and then nothing catches a bypass of the ready-made in the area where
49
+ * the bundle does hold. An area is not written for a tree with one source of look: an empty list
50
+ * means the whole tree, exactly as before.
51
+ */
52
+ function bundleOf(declared) {
53
+ if (typeof declared === 'string') {
54
+ return { name: declared, roots: [] };
55
+ }
56
+
57
+ const roots = declared?.roots ?? [];
58
+
59
+ return { name: declared?.name, roots: typeof roots === 'string' ? [roots] : roots };
60
+ }
61
+
62
+ function readBundle(declared) {
63
+ const { name, roots } = bundleOf(declared);
64
+ const path = name ? join(BUNDLES_DIR, `${name}.json`) : '';
65
+ if (!path || !existsSync(path)) {
44
66
  const known = bundleNames().join(', ') || 'none';
45
- throw new Error(`the bundle of signs «${name}» is not found at the package; there are: ${known}`);
67
+ throw new Error(`the bundle of signs «${name ?? ''}» is not found at the package; there are: ${known}`);
46
68
  }
47
69
 
48
- return parseSignals(readFileSync(path, 'utf8'));
70
+ // The area goes onto the sign, not next to it: further on the signs of all the bundles lie in
71
+ // one list, and by the sign alone there would be no telling which bundle it came from.
72
+ return parseSignals(readFileSync(path, 'utf8')).map((signal) => (roots.length > 0 ? { ...signal, roots } : signal));
49
73
  }
50
74
 
51
75
  /** A sign that looks for a native tag: `<input\\b`, `<textarea\\b`, `<select\\b`. */
@@ -109,6 +133,16 @@ export function withKitDirectives(signals, directives) {
109
133
  */
110
134
  export function loadSignals(config, root) {
111
135
  const declared = config.bundles ?? [];
136
+ const names = declared.map((one) => bundleOf(one).name);
137
+ const twice = names.find((name, index) => names.indexOf(name) !== index);
138
+ if (twice) {
139
+ throw new Error(
140
+ `the bundle of signs «${twice}» is declared twice. A bundle carries one area of the tree: ` +
141
+ `declared a second time, it takes the first declaration away silently, and the area named ` +
142
+ `there is left judged by nothing. Two areas of one bundle are written as one list of directories.`
143
+ );
144
+ }
145
+
112
146
  const signals = declared.flatMap(readBundle);
113
147
 
114
148
  const ownPath = config.signals ? join(root, config.signals) : null;