@rt-tools/agent-kit 0.27.0 → 0.29.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 (112) hide show
  1. package/assets/checks/board-epic-link.github.mjs +13 -1
  2. package/assets/checks/board-epic-plan.github.mjs +86 -0
  3. package/assets/checks/board-epics.github.mjs +12 -67
  4. package/assets/checks/board-pull-state.github.mjs +6 -11
  5. package/assets/checks/board-runs.github.mjs +102 -2
  6. package/assets/checks/check-board.github.mjs +63 -3
  7. package/assets/checks/check-glossary.mjs +10 -2
  8. package/assets/checks/check-lib-layers.mjs +24 -1
  9. package/assets/checks/check-reuse.mjs +26 -2
  10. package/assets/checks/check-specs.mjs +8 -1
  11. package/assets/checks/lib-boundaries.mjs +2 -2
  12. package/assets/checks/lib-common.mjs +46 -0
  13. package/assets/checks/lib-manifests.mjs +18 -13
  14. package/assets/checks/main-run.github.mjs +69 -0
  15. package/assets/checks/rt-kit-checks.config.mjs +21 -0
  16. package/assets/checks/signals.mjs +39 -5
  17. package/assets/checks/spec-anchors.mjs +48 -4
  18. package/assets/checks/spec-common.mjs +40 -6
  19. package/assets/checks/spec-contract.mjs +33 -7
  20. package/assets/checks/spec-scenarios.mjs +24 -1
  21. package/assets/checks/task-new.github.mjs +9 -3
  22. package/assets/checks/tree-assignment.mjs +169 -0
  23. package/assets/defaults/gate-map.sh +20 -5
  24. package/assets/defaults/project.sh +6 -0
  25. package/assets/hooks/dev-server-guard.sh +61 -32
  26. package/assets/hooks/end-conversation-guard.sh +59 -0
  27. package/assets/hooks/epic-over.sh +11 -2
  28. package/assets/hooks/exam-guard.sh +10 -10
  29. package/assets/hooks/git-guard-delivery-conflict.sh +53 -1
  30. package/assets/hooks/git-guard-delivery-draft.sh +7 -6
  31. package/assets/hooks/git-guard-delivery-epic.sh +7 -0
  32. package/assets/hooks/git-guard-delivery-tree.sh +50 -0
  33. package/assets/hooks/git-guard-delivery.sh +45 -24
  34. package/assets/hooks/git-guard-discard.sh +144 -0
  35. package/assets/hooks/git-guard-push-tests.sh +36 -16
  36. package/assets/hooks/git-guard-tree-assignment.sh +77 -0
  37. package/assets/hooks/hook-input.sh +8 -1
  38. package/assets/hooks/main-run-context.sh +45 -0
  39. package/assets/hooks/reuse-first-guard.sh +29 -4
  40. package/assets/hooks/rule-source-guard.sh +17 -2
  41. package/assets/hooks/skill-gate.sh +7 -0
  42. package/assets/hooks/sql-guard-write.sh +18 -2
  43. package/assets/hooks/tree-assignment-guard.sh +101 -0
  44. package/assets/hooks/turn-exit-epic.sh +110 -0
  45. package/assets/hooks/turn-exit-guard.sh +80 -82
  46. package/assets/hooks/turn-exit-patterns.sh +18 -10
  47. package/assets/hooks/turn-exit-verdict.sh +96 -0
  48. package/assets/laws/delivery.md +20 -6
  49. package/assets/laws/verifiability.md +22 -4
  50. package/assets/laws/work-conduct.md +4 -0
  51. package/assets/patterns/git-workflow-merge.md +13 -0
  52. package/assets/patterns/git-workflow-pr-body.github.md +156 -0
  53. package/assets/patterns/git-workflow-pr.github.md +42 -119
  54. package/assets/patterns/git-workflow-stack.md +38 -2
  55. package/assets/patterns/task-flow-close.md +66 -79
  56. package/assets/patterns/task-flow-resume.md +8 -0
  57. package/assets/patterns/ts-procedure.md +6 -0
  58. package/assets/pitfalls/git-workflow.github.md +44 -0
  59. package/assets/pitfalls/task-flow.md +25 -23
  60. package/assets/pitfalls/turn-conduct.md +18 -0
  61. package/assets/rules/browser-verification.md +8 -0
  62. package/assets/rules/deploy-flow.github.md +6 -0
  63. package/assets/rules/doc-style.md +9 -2
  64. package/assets/rules/git-workflow.azure.md +10 -0
  65. package/assets/rules/git-workflow.github.md +128 -130
  66. package/assets/rules/git-workflow.gitlab.md +10 -0
  67. package/assets/rules/lib-layers.md +11 -0
  68. package/assets/rules/spec-driven.md +10 -1
  69. package/assets/rules/task-flow.md +82 -79
  70. package/assets/rules/testing.md +7 -0
  71. package/assets/rules/turn-conduct.md +47 -28
  72. package/assets/samples/tasks/_template/plan.md +4 -1
  73. package/assets/samples/tasks/_template/progress.md +1 -1
  74. package/assets/skills/agent-kit.md +17 -4
  75. package/bin/agent-kit.d.ts.map +1 -1
  76. package/bin/agent-kit.js +3 -2
  77. package/bin/agent-kit.js.map +1 -1
  78. package/lib/cargo.d.ts +49 -1
  79. package/lib/cargo.d.ts.map +1 -1
  80. package/lib/cargo.js +9 -2
  81. package/lib/cargo.js.map +1 -1
  82. package/lib/commands.d.ts +1 -1
  83. package/lib/commands.d.ts.map +1 -1
  84. package/lib/commands.js +59 -2
  85. package/lib/commands.js.map +1 -1
  86. package/lib/hooks-map.d.ts +5 -0
  87. package/lib/hooks-map.d.ts.map +1 -1
  88. package/lib/hooks-map.js +9 -3
  89. package/lib/hooks-map.js.map +1 -1
  90. package/lib/observations-cargo.d.ts +20 -0
  91. package/lib/observations-cargo.d.ts.map +1 -0
  92. package/lib/observations-cargo.js +88 -0
  93. package/lib/observations-cargo.js.map +1 -0
  94. package/lib/plan.d.ts +2 -0
  95. package/lib/plan.d.ts.map +1 -1
  96. package/lib/plan.js +8 -0
  97. package/lib/plan.js.map +1 -1
  98. package/lib/proposals.d.ts +25 -0
  99. package/lib/proposals.d.ts.map +1 -1
  100. package/lib/proposals.js +43 -1
  101. package/lib/proposals.js.map +1 -1
  102. package/lib/shipment.d.ts +8 -20
  103. package/lib/shipment.d.ts.map +1 -1
  104. package/lib/shipment.js +30 -50
  105. package/lib/shipment.js.map +1 -1
  106. package/lib/tree-mark.d.ts +17 -0
  107. package/lib/tree-mark.d.ts.map +1 -0
  108. package/lib/tree-mark.js +41 -0
  109. package/lib/tree-mark.js.map +1 -0
  110. package/package.json +1 -1
  111. package/rt-tools-agent-kit-0.29.0.tgz +0 -0
  112. package/rt-tools-agent-kit-0.27.0.tgz +0 -0
@@ -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
  }
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The last run of the main branch in one line.
4
+ *
5
+ * node tools/main-run.mjs
6
+ *
7
+ * Two readers call it: the session start prints the line into the context, and the executor
8
+ * calls it after every known merge. The queue audit reads the same run and names the same two
9
+ * findings; this command exists because the audit waits to be called, while a merge made
10
+ * mid-session moves the main branch without anybody asking the audit.
11
+ *
12
+ * Silence here is never «green»: where the run could not be read — no pipeline file, a pipeline
13
+ * asleep on a push to the main branch, no network — the line says so. The exit code is 1 on a red
14
+ * or a pushed-out run and 0 in every other case, so that a chain after a merge stops on it.
15
+ */
16
+ import { OfflineError, botToken } from './board.mjs';
17
+ import { HAS_PIPELINE, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
18
+ import { CONFIG } from './rt-kit-checks.config.mjs';
19
+
20
+ const MAIN_BRANCH = CONFIG.deploy?.mainBranch ?? 'main';
21
+
22
+ /** The line for one reading of the run; exported so the suite can read it without the hosting. */
23
+ export function mainRunLine(run, mainBranch = MAIN_BRANCH) {
24
+ const sha = String(run.sha ?? '').slice(0, 8);
25
+ const day = String(run.at ?? '').slice(0, 10);
26
+ switch (run.verdict) {
27
+ case 'none':
28
+ return `main-run: «${mainBranch}» has no run yet`;
29
+ case 'running':
30
+ return `main-run: «${mainBranch}» is being checked on ${sha} — ${run.url}`;
31
+ case 'success':
32
+ return `main-run: «${mainBranch}» is green on ${sha} of ${day}`;
33
+ case 'evicted':
34
+ return `main-run: the run of «${mainBranch}» on ${sha} was pushed out of the queue and never checked the merge — ${run.url}`;
35
+ default:
36
+ return `main-run: «${mainBranch}» is RED on ${sha} of ${day}: merges on top go out unchecked — ${run.url}`;
37
+ }
38
+ }
39
+
40
+ function main() {
41
+ if (!HAS_PIPELINE) {
42
+ console.log('main-run: the main branch run was not read — the tree has no pipeline file');
43
+ return 0;
44
+ }
45
+ if (!pipelineWakesOnPush(pipelineText(), MAIN_BRANCH)) {
46
+ console.log(`main-run: the main branch run was not read — the pipeline does not wake on a push to «${MAIN_BRANCH}»`);
47
+ return 0;
48
+ }
49
+
50
+ let run;
51
+ try {
52
+ run = lastMainRun(MAIN_BRANCH, { token: botToken() ?? undefined });
53
+ } catch (error) {
54
+ if (error instanceof OfflineError) {
55
+ console.log(`main-run: the main branch run was not read — ${error.message}`);
56
+ return 0;
57
+ }
58
+ throw error;
59
+ }
60
+
61
+ console.log(mainRunLine(run, MAIN_BRANCH));
62
+ return run.verdict === 'failure' || run.verdict === 'evicted' ? 1 : 0;
63
+ }
64
+
65
+ // The suite imports the line without running the reading; the hosting is asked only when called.
66
+ const isEntryPoint = process.argv[1] && import.meta.url === `file://${process.argv[1]}`;
67
+ if (isEntryPoint) {
68
+ process.exit(main());
69
+ }
@@ -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. */
@@ -91,6 +97,21 @@ const DEFAULTS = {
91
97
  * Empty — the tree has no such directory, and an epic is not created by the command.
92
98
  */
93
99
  plansDir: '',
100
+ /**
101
+ * Where the assignment of an epic to a working copy is declared, and where a copy holds its own
102
+ * name.
103
+ *
104
+ * Two files, and they lie apart on purpose. The assignment belongs to the working copy and is
105
+ * declared in the main branch: written into the branch of a task, it is in force only there,
106
+ * and at the first branch switch the executor works by one order while the check reads another.
107
+ * The name of the copy is the state of the machine — the path to it belongs in nobody's
108
+ * history, so the copy names itself by a short word in a file outside the index.
109
+ *
110
+ * Empty — the tree declares no assignments, and nothing about them is judged: a tree with one
111
+ * working copy has nothing to divide.
112
+ */
113
+ assignmentsFile: '',
114
+ treeNameFile: '.claude/rt-kit/tree-name',
94
115
  /** Where the lists of accepted debts are put. */
95
116
  allowlistDir: 'tools',
96
117
  /**
@@ -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;
@@ -13,7 +13,9 @@ import {
13
13
  VERDICT,
14
14
  VERDICT_MIN,
15
15
  bulletsOf,
16
+ codeOf,
16
17
  exists,
18
+ isTestFile,
17
19
  read,
18
20
  report,
19
21
  sectionOf,
@@ -203,7 +205,6 @@ function checkRuleImplementation(specFile, text, mapFile, heading = ['## Rules',
203
205
  * Code without comments. A symbol named in an explanation is called by nobody, and dead code
204
206
  * usually has more explanations than live code does.
205
207
  */
206
- const codeOf = (text) => text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:`'"])\/\/.*$/gm, '$1');
207
208
 
208
209
  const DECLARATION_MODIFIERS = '(?:export|declare|abstract|public|private|protected|static|readonly|override|async|accessor)';
209
210
 
@@ -257,6 +258,36 @@ function symbolOwners() {
257
258
  return owners;
258
259
  }
259
260
 
261
+ /**
262
+ * The files a package publishes outward: everything a `public-api.ts` or an `index.ts` re-exports,
263
+ * and everything those files re-export in turn. A symbol of a published file is called by whoever
264
+ * installed the package, and that caller is not in this tree at all: judged by the calls visible
265
+ * here, the whole public API of a kit reads as dead code.
266
+ */
267
+ function publishedFiles() {
268
+ const published = new Set();
269
+ const entries = SOURCE_ROOTS.flatMap((root) => walk(root, (name) => name === 'public-api.ts' || name === 'index.ts'));
270
+ const queue = [...entries];
271
+ while (queue.length) {
272
+ const file = queue.pop();
273
+ const dir = file.slice(0, file.lastIndexOf('/'));
274
+ for (const [, relative] of read(file).matchAll(/(?:export|import)[^'"]*from\s+['"](\.[^'"]*)['"]/g)) {
275
+ for (const suffix of ['.ts', '/index.ts', '']) {
276
+ const path = `${dir}/${relative.replace(/^\.\//, '')}${suffix}`.replace(/\/\.\//g, '/');
277
+ if (exists(path) && !published.has(path)) {
278
+ published.add(path);
279
+ if (path.endsWith('/index.ts')) {
280
+ queue.push(path);
281
+ }
282
+ break;
283
+ }
284
+ }
285
+ }
286
+ }
287
+
288
+ return published;
289
+ }
290
+
260
291
  /**
261
292
  * A symbol declared in its own file and met nowhere else carries nothing out: a rule bound
262
293
  * to it describes an intention.
@@ -277,6 +308,7 @@ function checkTracedAnchors() {
277
308
  }
278
309
 
279
310
  const owners = symbolOwners();
311
+ const published = publishedFiles();
280
312
  for (const { mapFile, path, symbol } of declared) {
281
313
  // A word boundary is placed only where one exists: there is none before a hash, and a
282
314
  // pattern with it would give zero occurrences for every private name.
@@ -284,12 +316,24 @@ function checkTracedAnchors() {
284
316
  ? `${escapeForRegExp(symbol)}\\b`
285
317
  : `\\b${escapeForRegExp(symbol)}\\b`;
286
318
  const here = (codeAt(path).match(new RegExp(bound, 'g')) || []).length;
287
- const elsewhere = [...(owners.get(symbol) || [])].filter((file) => file !== path).length;
319
+ // A test is not a call. A function written test-first and never called from the
320
+ // application is an intention: the test calls it itself, and by that call a live symbol
321
+ // cannot be told from a forgotten one. Counted together, the declaration and the test file
322
+ // next to it made two — the threshold — and the audit went green exactly when the binding
323
+ // lied hardest.
324
+ // The exclusion works only for a symbol declared in the code of the application. A helper
325
+ // declared in the suite harness itself is called by tests by its very purpose: judged by
326
+ // the same measure, the articles of the testing rule would all turn red at once.
327
+ const others = [...(owners.get(symbol) || [])].filter((file) => file !== path);
328
+ const elsewhere = isTestFile(path) || published.has(path) ? others.length : others.filter((file) => !isTestFile(file)).length;
288
329
  if (here + elsewhere < 2) {
289
330
  report(
290
331
  mapFile,
291
- `the binding leads into dead code: \`${symbol}\` is declared in \`${path}\` and met nowhere else — ` +
292
- 'either the statement is carried out elsewhere, or its place is in «Open questions» of the law as Q-<letter>-<number>'
332
+ others.length > elsewhere
333
+ ? `the binding leads into code called by a test alone: \`${symbol}\` is declared in \`${path}\` and outside tests is met nowhere — ` +
334
+ 'a test is not a call from the application; either the statement is carried out elsewhere, or its place is in «Open questions» of the law as Q-<letter>-<number>'
335
+ : `the binding leads into dead code: \`${symbol}\` is declared in \`${path}\` and met nowhere else — ` +
336
+ 'either the statement is carried out elsewhere, or its place is in «Open questions» of the law as Q-<letter>-<number>'
293
337
  );
294
338
  }
295
339
  }
@@ -41,23 +41,48 @@ const SKIPPED_DIRS = CONFIG.skippedDirs;
41
41
  /**
42
42
  * `### SC-BK-03 — a request for dates already taken`
43
43
  *
44
- * The number is accepted from one digit to three. A heading that did not match the template starts
45
- * no scenario and gives no refusal: a tree that numbered its scenarios from one would lose the
46
- * first nine of them silently — neither in coverage nor in debts, with a green audit.
44
+ * The number is accepted from one digit to four, the prefix from two letters to six. A heading the
45
+ * template did not take used to start no scenario and give no refusal: this tree crossed a
46
+ * thousand scenarios and lost the whole thousandth series at once — neither in coverage nor in
47
+ * debts, with a green audit. Now such a heading is named as a discrepancy of its own.
47
48
  */
48
- const SCENARIO_HEADING = /^###\s+(SC-([A-Z]{2,4})-(\d{1,3}))\s+—\s+(.+?)\s*$/;
49
+ const SCENARIO_HEADING = /^###\s+(SC-([A-Z]{2,6})-(\d{1,4}))\s+—\s+(.+?)\s*$/;
49
50
  /**
50
51
  * The keys of a spec are read under two names, English and the owner's. A tree translates its
51
52
  * specs one domain at a time, and a key that moved instead of learning the second name takes the
52
53
  * untranslated domains out of the audit silently: the heading is not found, the statements and the
53
54
  * scenarios are not read, and the audit stays green about a domain it no longer sees.
54
55
  */
56
+ /**
57
+ * The code of a file without its explanations. A declaration read as text — a right at a
58
+ * procedure, a boundary tag in a linter setting — is looked for here and not in the raw text: a
59
+ * sample call written in an explanation next to the real mark substitutes itself for it, and the
60
+ * right of a comment travels into the audit. Caught on a live one.
61
+ */
62
+ const codeOf = (text) => text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:`'"])\/\/.*$/gm, '$1');
63
+
64
+ /**
65
+ * A file that only serves the tests. A test is not a call from the application: a symbol declared
66
+ * and met nowhere but in the test next to it is an intention, and by such a meeting a live symbol
67
+ * cannot be told from a forgotten one.
68
+ *
69
+ * Besides the tests themselves this counts the harness the tree named by the key `harnessDirs` —
70
+ * a directory or a single file: a snapshot harness, a fixture builder. Their symbols are called
71
+ * by tests by their very purpose. The list is named narrowly: a showcase directory taken whole
72
+ * carries the stories with it, and a story calling a component is a real call.
73
+ */
74
+ const HARNESS_DIRS = CONFIG.harnessDirs ?? [];
75
+
76
+ function isTestFile(path) {
77
+ return /\.(?:spec|test|e2e)\.[jt]s$|(?:^|\/)tests?\/|-e2e\//.test(path) || HARNESS_DIRS.some((named) => path === named || path.startsWith(`${named}/`));
78
+ }
79
+
55
80
  /** The mark of a knowingly uncovered scenario; the reason is mandatory */
56
81
  const UNCOVERED = /^(?:Not covered|Не покрыто):\s*\S/;
57
82
  /** The test exists, but checks not everything promised or goes another way */
58
83
  const PARTIAL = /^(?:Coverage:\s*partial|Покрытие:\s*частичное)\s*—\s*\S/;
59
84
  /** A mention of the scenario in the title of a test; the number is as long as in the heading */
60
- const SCENARIO_REFERENCE = /\bSC-[A-Z]{2,4}-\d{1,3}\b/g;
85
+ const SCENARIO_REFERENCE = /\bSC-[A-Z]{2,6}-\d{1,4}\b/g;
61
86
  /** The promise line of a scenario; its continuations go with an indent */
62
87
  const PROMISE = /^(?:Then|Тогда)\s+\S/;
63
88
  /**
@@ -93,7 +118,14 @@ const E2E_ROOTS = CONFIG.e2eRoots;
93
118
  // there is nothing else to bind to — an element has neither a method nor a field. Before, such a
94
119
  // binding did not match the template, and the audit said there was no binding at all; a session
95
120
  // went on rewriting a table of bindings that was right.
96
- const ANCHOR = /`([\w./-]+\.[A-Za-z]{2,10}):(#?\p{L}[\p{L}\p{N}_-]*|#?_[\w-]*|\d+|\.[\p{L}\p{N}_-]+)`/gu;
121
+ // The name of a file is written in two shapes: with an extension, and whole without a dot —
122
+ // that is how an image description, a proxy config and a build file are named. A statement
123
+ // carried out exactly there had nothing to address it by, and stood under the verdict «not
124
+ // checked» while the article was carried out: the form called such an address the absence of
125
+ // one. The second shape takes a word with a capital letter — that is what tells the name of
126
+ // such a file from an ordinary word of prose standing in backticks next to a colon.
127
+ const ANCHOR =
128
+ /`((?:[\w./-]+\.[A-Za-z]{2,10}|(?:[\w./-]*\/)?[A-Z][\w-]*)):(#?\p{L}[\p{L}\p{N}_-]*|#?_[\w-]*|\d+|\.[\p{L}\p{N}_-]+)`/gu;
97
129
  /**
98
130
  * An explicit verdict instead of an anchor: an article that has nowhere to be carried out in the
99
131
  * tree. That happens lawfully — the rule speaks of a service the tree does not keep, or of a human
@@ -240,6 +272,8 @@ function bulletsOf(lines) {
240
272
 
241
273
  export {
242
274
  SPECS_DIR,
275
+ codeOf,
276
+ isTestFile,
243
277
  CONSTITUTION_DIR,
244
278
  NOT_DOMAINS,
245
279
  TEST_ROOTS,
@@ -2,22 +2,41 @@
2
2
  * The spec contract against what the code declares: the procedure table against the decorators,
3
3
  * the refusal codes against the throw points.
4
4
  */
5
- import { BACKTICKED, PROCEDURE_ROOTS, bulletsOf, read, report, sectionOf, walk } from './spec-common.mjs';
5
+ import { BACKTICKED, PROCEDURE_ROOTS, bulletsOf, codeOf, read, report, sectionOf, walk } from './spec-common.mjs';
6
6
 
7
7
  // ── 2. The contract against the decorators ────────────────────────────────────
8
8
 
9
- /** The lib roots whose procedures the domain serves; declared in the spec header. */
9
+ /**
10
+ * The lib roots whose procedures the domain serves; declared in the spec header.
11
+ *
12
+ * An empty input has three states, not two, and merged into one they give a green where nothing
13
+ * was checked at all: there is no line — the domain says nothing about procedures; the line says
14
+ * «none» — a lawful answer; the line stands and names no root in backticks — the declaration was
15
+ * not parsed, and the whole contract went unchecked in silence. A header naming its procedures in
16
+ * words left three procedures with their rights and refusal codes unverified, and the run was
17
+ * green.
18
+ *
19
+ * The third state is answered by `UNPARSED`: the caller tells it from an empty list and names it
20
+ * as a discrepancy of the spec, not as the absence of a subject.
21
+ */
22
+ const UNPARSED = Symbol('procedure roots are declared and not parsed');
23
+
10
24
  function procedureRootsOf(text) {
11
25
  const line = text.split('\n').find((candidate) => PROCEDURE_ROOTS.test(candidate));
12
26
  if (!line) {
13
27
  return null;
14
28
  }
15
29
  const value = line.match(PROCEDURE_ROOTS)[1];
16
- if (/^\s*(?:none|нет)\s*$/i.test(value.replace(/[`.]/g, ''))) {
30
+ // The word is taken at the beginning of the line, and what follows it is an explanation: a
31
+ // domain that has no procedures says why, and the reason is worth more than the bare word.
32
+ // Demanding the word alone made fifteen lawful headers unparsed at once.
33
+ if (/^\s*(?:none|нет)(?![\p{L}\p{N}_])/iu.test(value.replace(/[`]/g, ''))) {
17
34
  return [];
18
35
  }
19
36
 
20
- return [...value.matchAll(BACKTICKED)].map(([, path]) => path);
37
+ const roots = [...value.matchAll(BACKTICKED)].map(([, path]) => path);
38
+
39
+ return roots.length === 0 ? UNPARSED : roots;
21
40
  }
22
41
 
23
42
  /** What the procedures themselves declare: the contract method and the right to it. */
@@ -25,7 +44,9 @@ function declaredProcedures(roots) {
25
44
  const found = new Map();
26
45
  for (const root of roots) {
27
46
  for (const file of walk(root, (name) => name.endsWith('.procedure.ts'))) {
28
- const text = read(file);
47
+ // Without the explanations: a sample call written next to the real mark used to substitute
48
+ // itself for it, and the right of a comment travelled into the audit.
49
+ const text = codeOf(read(file));
29
50
  const method = text.match(/\.method\.([A-Za-z_]\w*)/);
30
51
  if (!method) {
31
52
  continue;
@@ -85,6 +106,11 @@ function checkContract(file, text, roots) {
85
106
 
86
107
  return;
87
108
  }
109
+ if (roots === UNPARSED) {
110
+ report(file, 'the line `**Процедуры:**` names no root in backticks: the roots are written as paths, and the absence of procedures is said by the word «нет». As it stands, the table of «Контракт» is checked against nothing');
111
+
112
+ return;
113
+ }
88
114
  const declared = declaredProcedures(roots);
89
115
  const rows = contractRows(text);
90
116
  const described = new Set();
@@ -135,7 +161,7 @@ function checkRefusalCodes(file, text, roots) {
135
161
 
136
162
  return;
137
163
  }
138
- if (!roots || !roots.length) {
164
+ if (!roots || roots === UNPARSED || !roots.length) {
139
165
  return;
140
166
  }
141
167
  const sources = roots.flatMap((root) => walk(root, (name) => name.endsWith('.ts') && !name.endsWith('.spec.ts')));
@@ -158,4 +184,4 @@ function checkRefusalCodes(file, text, roots) {
158
184
  }
159
185
  }
160
186
 
161
- export { checkContract, checkRefusalCodes, procedureRootsOf };
187
+ export { UNPARSED, checkContract, checkRefusalCodes, procedureRootsOf };
@@ -18,6 +18,29 @@ import {
18
18
 
19
19
  // ── 4. Scenarios and the level of binding ──────────────────────────────────────
20
20
 
21
+
22
+ /**
23
+ * A line begun as a scenario heading. By it a heading the template did not take is told from
24
+ * ordinary prose: silence about such a line makes the audit's answer a statement about what it
25
+ * managed to parse, not about what lies in the tree. A subdomain named with a five-letter prefix
26
+ * passed green with thirteen of its scenarios not counted at all.
27
+ */
28
+ const SCENARIO_HEADING_START = /^###\s+SC-/;
29
+
30
+ /** The headings of a file that begin as a scenario and are not taken by the template. */
31
+ function unparsedHeadings(file) {
32
+ const found = [];
33
+ read(file)
34
+ .split('\n')
35
+ .forEach((line, index) => {
36
+ if (SCENARIO_HEADING_START.test(line) && !SCENARIO_HEADING.test(line)) {
37
+ found.push({ file, line: index + 1, text: line.trim() });
38
+ }
39
+ });
40
+
41
+ return found;
42
+ }
43
+
21
44
  function parseScenarios(file) {
22
45
  const lines = read(file).split('\n');
23
46
  const scenarios = [];
@@ -221,4 +244,4 @@ function collectReferences() {
221
244
  return references;
222
245
  }
223
246
 
224
- export { collectReferences, parseScenarios, promisesScreen };
247
+ export { collectReferences, parseScenarios, promisesScreen, unparsedHeadings };
@@ -38,6 +38,7 @@ import { cpSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync
38
38
  import { dirname, join, resolve } from 'node:path';
39
39
  import { fileURLToPath } from 'node:url';
40
40
 
41
+ import { planPathOf } from './board-epic-plan.mjs';
41
42
  import {
42
43
  BACKLOG_OPTION_ID,
43
44
  BOT,
@@ -221,10 +222,15 @@ function epicOfCard(epicNumber) {
221
222
  if (!labelled) {
222
223
  fail(`#${epicNumber} is not an epic: the card carries no label «${EPIC_LABEL}». A task hangs on an epic, and an epic is what the audit reads by that label`);
223
224
  }
224
- const named = String(card.body ?? '').match(/(?:^|[\s(`])([\w.-]+(?:\/[\w.-]+)+\.md)/);
225
- const plan = named ? named[1] : null;
225
+ // Which of the paths in the body is the plan is decided by the shared reading, the same one the
226
+ // queue audit calls. Read here by its own way — the first path in the body — the command wrote a
227
+ // law into every task of the epic as its plan, and the branch of the epic was then read from
228
+ // that law and came back empty. Both sides answered as usual, and the miss showed only by
229
+ // reading a created task.
230
+ const found = planPathOf(card.body, { makeupRequired: false });
231
+ const plan = found.path;
226
232
  if (plan === null) {
227
- fail(`the card of the epic #${epicNumber} names no path to its plan — there is nowhere to read what the epic holds, and the branch of the epic is named there too`);
233
+ fail(`the card of the epic #${epicNumber}: ${found.why}. The branch of the epic is named in the plan too`);
228
234
  }
229
235
  return { plan, branch: epicBranchOf(plan, epicNumber) };
230
236
  }