@rt-tools/agent-kit 0.26.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.
- package/assets/agents/cargo-writer.md +54 -0
- package/assets/checks/board-epic-link.github.mjs +29 -0
- package/assets/checks/board-epic-plan.github.mjs +86 -0
- package/assets/checks/board-epics.github.mjs +217 -69
- package/assets/checks/board-long-work.github.mjs +5 -1
- package/assets/checks/board-pull-state.github.mjs +163 -0
- package/assets/checks/board-task-dirs.github.mjs +98 -0
- package/assets/checks/board.github.mjs +8 -91
- package/assets/checks/check-board.github.mjs +25 -165
- package/assets/checks/check-glossary.mjs +10 -2
- package/assets/checks/check-lib-layers.mjs +24 -1
- package/assets/checks/check-prose-style.mjs +19 -3
- package/assets/checks/check-reuse.mjs +26 -2
- package/assets/checks/check-schema-drift.mjs +19 -3
- package/assets/checks/check-specs.mjs +8 -1
- package/assets/checks/epic-table.github.mjs +268 -0
- package/assets/checks/lib-boundaries.mjs +2 -2
- package/assets/checks/lib-common.mjs +46 -0
- package/assets/checks/lib-manifests.mjs +18 -13
- package/assets/checks/rt-kit-checks.config.mjs +19 -0
- package/assets/checks/signals.mjs +39 -5
- package/assets/checks/spec-anchors.mjs +48 -4
- package/assets/checks/spec-common.mjs +40 -6
- package/assets/checks/spec-contract.mjs +33 -7
- package/assets/checks/spec-scenarios.mjs +24 -1
- package/assets/checks/specs-for.mjs +214 -0
- package/assets/checks/task-new.github.mjs +237 -6
- package/assets/commands/night.md +115 -0
- package/assets/defaults/gate-map.sh +20 -5
- package/assets/defaults/project.sh +13 -0
- package/assets/defaults/turn-map.md +3 -1
- package/assets/docs/GLOSSARY.md +22 -22
- package/assets/hooks/browser-device-id.sh +4 -0
- package/assets/hooks/browser-guard-device-id.sh +4 -0
- package/assets/hooks/commit-msg.sh +3 -0
- package/assets/hooks/dev-server-guard.sh +64 -31
- package/assets/hooks/epic-over.sh +49 -0
- package/assets/hooks/epic-stop-guard.sh +108 -0
- package/assets/hooks/exam-guard.sh +10 -10
- package/assets/hooks/git-guard-delivery-conflict.sh +56 -1
- package/assets/hooks/git-guard-delivery-draft.sh +10 -6
- package/assets/hooks/git-guard-delivery-epic.sh +167 -0
- package/assets/hooks/git-guard-delivery-signature.sh +32 -2
- package/assets/hooks/git-guard-delivery-tree.sh +50 -0
- package/assets/hooks/git-guard-delivery.sh +71 -27
- package/assets/hooks/git-guard-discard.sh +144 -0
- package/assets/hooks/git-guard-push-tests.sh +36 -16
- package/assets/hooks/handoff-entry-guard.sh +20 -2
- package/assets/hooks/prose-style-guard.sh +31 -8
- package/assets/hooks/qa-dataid-guard.sh +33 -11
- package/assets/hooks/reuse-first-guard.sh +29 -4
- package/assets/hooks/rule-article.sh +3 -0
- package/assets/hooks/rule-source-guard.sh +17 -2
- package/assets/hooks/skill-gate-layers.sh +4 -0
- package/assets/hooks/skill-gate.sh +7 -0
- package/assets/hooks/skill-loaded.sh +4 -0
- package/assets/hooks/sql-guard-parse.sh +3 -0
- package/assets/hooks/sql-guard-request.sh +3 -0
- package/assets/hooks/sql-guard-target.sh +3 -0
- package/assets/hooks/sql-guard-write.sh +21 -2
- package/assets/hooks/stand-login-guard.sh +3 -0
- package/assets/hooks/turn-exit-guard.sh +55 -67
- package/assets/hooks/turn-exit-patterns.sh +28 -1
- package/assets/hooks/turn-exit-verdict.sh +84 -0
- package/assets/hooks/utf8.sh +3 -0
- package/assets/hooks/waiting-turn-guard.sh +11 -1
- package/assets/hooks/write-targets.sh +3 -0
- package/assets/laws/delivery.md +37 -7
- package/assets/laws/verifiability.md +22 -4
- package/assets/patterns/git-workflow-commit.azure.md +1 -1
- package/assets/patterns/git-workflow-commit.github.md +9 -2
- package/assets/patterns/git-workflow-commit.gitlab.md +1 -1
- package/assets/patterns/git-workflow-merge.md +8 -5
- package/assets/patterns/git-workflow-pr.azure.md +1 -1
- package/assets/patterns/git-workflow-pr.github.md +44 -18
- package/assets/patterns/git-workflow-pr.gitlab.md +1 -1
- package/assets/patterns/git-workflow-stack.md +32 -9
- package/assets/patterns/status-report-table.github.md +11 -0
- package/assets/patterns/task-flow-close.md +96 -90
- package/assets/patterns/task-flow-start.md +40 -26
- package/assets/patterns/ts-procedure.md +6 -0
- package/assets/pitfalls/agent-kit.md +19 -0
- package/assets/pitfalls/git-workflow.github.md +44 -0
- package/assets/pitfalls/task-flow.md +25 -23
- package/assets/rules/autonomous-work.md +15 -3
- package/assets/rules/browser-verification.md +8 -0
- package/assets/rules/deploy-flow.github.md +6 -0
- package/assets/rules/doc-style.md +13 -4
- package/assets/rules/git-workflow.azure.md +10 -0
- package/assets/rules/git-workflow.github.md +144 -126
- package/assets/rules/git-workflow.gitlab.md +10 -0
- package/assets/rules/lib-layers.md +11 -0
- package/assets/rules/spec-driven.md +17 -1
- package/assets/rules/status-report.md +7 -0
- package/assets/rules/task-flow.md +78 -54
- package/assets/rules/testing.md +7 -0
- package/assets/rules/turn-conduct.md +30 -3
- package/assets/samples/tasks/_template/plan.md +4 -1
- package/assets/skills/agent-kit.md +40 -25
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +9 -2
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo-prose.d.ts +41 -0
- package/lib/cargo-prose.d.ts.map +1 -0
- package/lib/cargo-prose.js +88 -0
- package/lib/cargo-prose.js.map +1 -0
- package/lib/cargo.d.ts +12 -1
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +8 -2
- package/lib/cargo.js.map +1 -1
- package/lib/commands.d.ts +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +59 -2
- package/lib/commands.js.map +1 -1
- package/lib/fate.d.ts +29 -0
- package/lib/fate.d.ts.map +1 -0
- package/lib/fate.js +147 -0
- package/lib/fate.js.map +1 -0
- package/lib/hooks-map.d.ts +5 -0
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +9 -3
- package/lib/hooks-map.js.map +1 -1
- package/lib/override-marks.d.ts +7 -0
- package/lib/override-marks.d.ts.map +1 -1
- package/lib/override-marks.js +14 -0
- package/lib/override-marks.js.map +1 -1
- package/lib/plan.d.ts +2 -0
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +8 -0
- package/lib/plan.js.map +1 -1
- package/lib/proposals.d.ts +25 -0
- package/lib/proposals.d.ts.map +1 -1
- package/lib/proposals.js +43 -1
- package/lib/proposals.js.map +1 -1
- package/lib/ship.d.ts +29 -2
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +34 -0
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.fixture.d.ts +8 -1
- package/lib/shipment.fixture.d.ts.map +1 -1
- package/lib/shipment.fixture.js +9 -0
- package/lib/shipment.fixture.js.map +1 -1
- package/lib/shipment.js +40 -14
- package/lib/shipment.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.28.0.tgz +0 -0
- package/rt-tools-agent-kit-0.26.0.tgz +0 -0
|
@@ -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
|
|
45
|
-
* no scenario and
|
|
46
|
-
*
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
/**
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The entry into the specs by the name of a resource: which spec speaks of this file and what
|
|
4
|
+
* exactly it says about it.
|
|
5
|
+
*
|
|
6
|
+
* A complaint from the intake names the place it is about — a hook, a rule, a skill — and the specs
|
|
7
|
+
* have no entry by that name. More than twenty subdomains stand in the domain, and the one needed is
|
|
8
|
+
* told from the rest only by reading: what is paid for by the whole window is not done before every
|
|
9
|
+
* taking apart of a complaint, and the complaint gets judged by memory.
|
|
10
|
+
*
|
|
11
|
+
* The entry is assembled from the bindings of the companions, not from a list of its own: a second
|
|
12
|
+
* list would name the same files from the other side and would diverge from the bindings in silence.
|
|
13
|
+
*
|
|
14
|
+
* node tools/specs-for.mjs hooks/turn-exit-guard.sh # which spec speaks of this file
|
|
15
|
+
* node tools/specs-for.mjs # the resources no spec speaks of
|
|
16
|
+
*
|
|
17
|
+
* Three answers, and the code tells them apart: zero — a spec speaks of the file; three — the
|
|
18
|
+
* package carries the file and no spec speaks of it; one — the package carries no such name at all.
|
|
19
|
+
* Answered by one code, a hole in the specs reads as a typo in the name, and the taking apart goes
|
|
20
|
+
* back to memory — the very thing the entry was made against.
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync, readdirSync } from 'node:fs';
|
|
23
|
+
import { join } from 'node:path';
|
|
24
|
+
|
|
25
|
+
import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
|
|
26
|
+
import { ANCHOR, SPECS_DIR, walk } from './spec-common.mjs';
|
|
27
|
+
|
|
28
|
+
/** A binding line of a companion: the statement text and the addresses it is carried out by. */
|
|
29
|
+
const BINDING = /^-\s+\*\*(.+?)\*\*\s+—\s+(.*)$/;
|
|
30
|
+
|
|
31
|
+
/** What counts as a resource of the package: the kinds of file the layout carries. */
|
|
32
|
+
const CARRIED = /\.(md|sh|mjs|ts|json)$/;
|
|
33
|
+
|
|
34
|
+
/** The package carries the file and no spec speaks of it: a gap in the specs, not a wrong name. */
|
|
35
|
+
const EXIT_UNCOVERED = 3;
|
|
36
|
+
|
|
37
|
+
/** The package carries no such file: a wrong name, and there is nothing to look for a spec about. */
|
|
38
|
+
const EXIT_UNKNOWN = 1;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The tail of a path is matched by whole segments. Matched by characters, a short name matches a
|
|
42
|
+
* longer one ending in it — a guard name would match a neighbouring guard whose name ends the same
|
|
43
|
+
* way — and the answer names a foreign spec, that is, leads the taking apart to a statement about
|
|
44
|
+
* another file.
|
|
45
|
+
*/
|
|
46
|
+
function tailMatches(pathSegments, askedSegments) {
|
|
47
|
+
if (askedSegments.length > pathSegments.length) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const from = pathSegments.length - askedSegments.length;
|
|
52
|
+
|
|
53
|
+
return askedSegments.every((segment, at) => segment === pathSegments[from + at]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const segmentsOf = (path) => path.replace(/^\.\//, '').split('/').filter(Boolean);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Every binding of every companion of the specs: the spec it stands in, the statement text, the
|
|
60
|
+
* address and the file of that address.
|
|
61
|
+
*/
|
|
62
|
+
function bindings() {
|
|
63
|
+
const found = [];
|
|
64
|
+
|
|
65
|
+
for (const companion of walk(SPECS_DIR, (name) => name === 'implementation.md')) {
|
|
66
|
+
let text = '';
|
|
67
|
+
try {
|
|
68
|
+
text = readFileSync(join(ROOT, companion), 'utf8');
|
|
69
|
+
} catch {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for (const line of text.split('\n')) {
|
|
74
|
+
const parsed = BINDING.exec(line);
|
|
75
|
+
|
|
76
|
+
if (!parsed) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const [, statement, rest] = parsed;
|
|
81
|
+
|
|
82
|
+
for (const anchor of rest.matchAll(ANCHOR)) {
|
|
83
|
+
found.push({
|
|
84
|
+
spec: `${companion.slice(0, -'implementation.md'.length)}spec.md`,
|
|
85
|
+
statement: statement.trim(),
|
|
86
|
+
file: anchor[1],
|
|
87
|
+
symbol: anchor[2],
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return found;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The files the package carries: the sources of portable texts named by the tree. */
|
|
97
|
+
function carried() {
|
|
98
|
+
const found = [];
|
|
99
|
+
|
|
100
|
+
const collect = (dir) => {
|
|
101
|
+
let entries;
|
|
102
|
+
try {
|
|
103
|
+
entries = readdirSync(join(ROOT, dir), { withFileTypes: true });
|
|
104
|
+
} catch {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
const path = `${dir}/${entry.name}`;
|
|
110
|
+
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
if (!CONFIG.skippedDirs.includes(entry.name)) {
|
|
113
|
+
collect(path);
|
|
114
|
+
}
|
|
115
|
+
} else if (CARRIED.test(entry.name)) {
|
|
116
|
+
found.push(path);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
CONFIG.portableDirs.forEach(collect);
|
|
122
|
+
|
|
123
|
+
return found;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The answer about one name: the subdomain, its statements about that very file and the addresses.
|
|
128
|
+
*
|
|
129
|
+
* Three outcomes, and they are told apart by the exit code, not by the wording alone: the taking
|
|
130
|
+
* apart of a complaint reads the code. Covered — zero; the package carries the file and no spec
|
|
131
|
+
* speaks of it — `EXIT_UNCOVERED`; the package carries no such file at all — `EXIT_UNKNOWN`.
|
|
132
|
+
*
|
|
133
|
+
* The middle outcome exists because it used to answer the same as a typo in the name. A hole in the
|
|
134
|
+
* specs then read as one's own mistake, and the complaint got judged by memory — the very thing the
|
|
135
|
+
* entry was made against.
|
|
136
|
+
*/
|
|
137
|
+
function entry(asked, all) {
|
|
138
|
+
const askedSegments = segmentsOf(asked);
|
|
139
|
+
const hit = all.filter((row) => tailMatches(segmentsOf(row.file), askedSegments));
|
|
140
|
+
|
|
141
|
+
if (hit.length === 0) {
|
|
142
|
+
return absent(asked, askedSegments, all);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// A file two subdomains speak of comes back with both, and the statements stand apart under
|
|
146
|
+
// each: read in one heap, they read as the statements of one spec.
|
|
147
|
+
const bySpec = new Map();
|
|
148
|
+
for (const row of hit) {
|
|
149
|
+
bySpec.set(row.spec, [...(bySpec.get(row.spec) ?? []), row]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const [spec, rows] of bySpec) {
|
|
153
|
+
console.log(spec);
|
|
154
|
+
for (const row of rows) {
|
|
155
|
+
console.log(` ${row.file}:${row.symbol}`);
|
|
156
|
+
console.log(` — ${row.statement}`);
|
|
157
|
+
}
|
|
158
|
+
console.log('');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The gaps: the files the package carries that not one binding names.
|
|
166
|
+
*
|
|
167
|
+
* Counted by what the package carries, not by the files the bindings name: counted the other way
|
|
168
|
+
* round, the list is empty by construction.
|
|
169
|
+
*/
|
|
170
|
+
function gapsOf(all) {
|
|
171
|
+
const named = all.map((row) => segmentsOf(row.file));
|
|
172
|
+
|
|
173
|
+
return carried()
|
|
174
|
+
.filter((path) => {
|
|
175
|
+
const segments = segmentsOf(path);
|
|
176
|
+
|
|
177
|
+
return !named.some((other) => tailMatches(other, segments) || tailMatches(segments, other));
|
|
178
|
+
})
|
|
179
|
+
.sort();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** The answer to a name no binding matched: a gap in the specs or a name the package does not carry. */
|
|
183
|
+
function absent(asked, askedSegments, all) {
|
|
184
|
+
const gaps = gapsOf(all);
|
|
185
|
+
const gap = gaps.find((path) => tailMatches(segmentsOf(path), askedSegments));
|
|
186
|
+
|
|
187
|
+
if (gap) {
|
|
188
|
+
console.log(`specs-for: the package carries «${gap}», and not one spec speaks of it`);
|
|
189
|
+
console.log(`Such resources: ${gaps.length}. The whole list is printed by the same command without a name.`);
|
|
190
|
+
|
|
191
|
+
return EXIT_UNCOVERED;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
console.log(`specs-for: the package carries no «${asked}» — the name is matched by nothing`);
|
|
195
|
+
console.log('The resources no spec speaks of are listed by the same command without a name.');
|
|
196
|
+
|
|
197
|
+
return EXIT_UNKNOWN;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The list of the gaps, a path per line: what is printed by the call without a name. */
|
|
201
|
+
function uncovered(all) {
|
|
202
|
+
gapsOf(all).forEach((path) => console.log(path));
|
|
203
|
+
|
|
204
|
+
return 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function main() {
|
|
208
|
+
const asked = process.argv[2];
|
|
209
|
+
const all = bindings();
|
|
210
|
+
|
|
211
|
+
return asked ? entry(asked, all) : uncovered(all);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
process.exit(main());
|