@rt-tools/agent-kit 0.26.0 → 0.27.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-epics.github.mjs +239 -36
- package/assets/checks/board-long-work.github.mjs +5 -1
- package/assets/checks/board-pull-state.github.mjs +168 -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-prose-style.mjs +19 -3
- package/assets/checks/check-schema-drift.mjs +19 -3
- package/assets/checks/epic-table.github.mjs +268 -0
- package/assets/checks/rt-kit-checks.config.mjs +13 -0
- package/assets/checks/specs-for.mjs +214 -0
- package/assets/checks/task-new.github.mjs +231 -6
- package/assets/commands/night.md +115 -0
- package/assets/defaults/project.sh +7 -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 +4 -0
- package/assets/hooks/epic-over.sh +49 -0
- package/assets/hooks/epic-stop-guard.sh +108 -0
- package/assets/hooks/git-guard-delivery-conflict.sh +3 -0
- package/assets/hooks/git-guard-delivery-draft.sh +3 -0
- 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.sh +28 -4
- 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/rule-article.sh +3 -0
- package/assets/hooks/skill-gate-layers.sh +4 -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 +3 -0
- package/assets/hooks/stand-login-guard.sh +3 -0
- package/assets/hooks/turn-exit-guard.sh +5 -1
- package/assets/hooks/turn-exit-patterns.sh +10 -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 +23 -1
- 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 +8 -3
- package/assets/patterns/git-workflow-pr.gitlab.md +1 -1
- package/assets/patterns/git-workflow-stack.md +13 -9
- package/assets/patterns/status-report-table.github.md +11 -0
- package/assets/patterns/task-flow-close.md +40 -21
- package/assets/patterns/task-flow-start.md +40 -26
- package/assets/pitfalls/agent-kit.md +19 -0
- package/assets/pitfalls/git-workflow.github.md +6 -0
- package/assets/rules/autonomous-work.md +15 -3
- package/assets/rules/doc-style.md +7 -4
- package/assets/rules/git-workflow.github.md +41 -23
- package/assets/rules/spec-driven.md +7 -0
- package/assets/rules/status-report.md +7 -0
- package/assets/rules/task-flow.md +31 -10
- package/assets/rules/turn-conduct.md +7 -0
- package/assets/skills/agent-kit.md +23 -21
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +8 -1
- 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/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/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/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 +32 -3
- package/lib/shipment.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.27.0.tgz +0 -0
- package/rt-tools-agent-kit-0.26.0.tgz +0 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// rt-kit v0.26.0 · checks/epic-table.github.mjs · ca65adf7e1b9 · правится надстройкой, не здесь
|
|
3
|
+
/**
|
|
4
|
+
* The table of the epic's tasks: the order from the plan, the state from the hosting.
|
|
5
|
+
*
|
|
6
|
+
* The shape of the answer to the question "where is the work" is written down — the rule of the
|
|
7
|
+
* status report and the pattern next to it — and the table itself was assembled by the session: it
|
|
8
|
+
* remembered which calls to make and how to fold the answers into cells. A session that has just
|
|
9
|
+
* started remembers none of that, and two sessions fold the same answers differently: one names the
|
|
10
|
+
* run on the head, another the last run of the branch.
|
|
11
|
+
*
|
|
12
|
+
* node tools/epic-table.mjs # the epic of the current branch
|
|
13
|
+
* node tools/epic-table.mjs 1940 # the epic named by its number
|
|
14
|
+
*
|
|
15
|
+
* The answer goes to the standard output and is carried to the owner as it is. A non-zero code
|
|
16
|
+
* means the table was not assembled, and then no table is printed at all: an empty one reads as an
|
|
17
|
+
* empty epic.
|
|
18
|
+
*/
|
|
19
|
+
import { execFileSync } from 'node:child_process';
|
|
20
|
+
import { readFileSync } from 'node:fs';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
|
|
23
|
+
import { OfflineError, TASK_KEY, botToken, fetchBoard, fetchOpenPulls, ghJson, numberFromBranch, numberFromTitle } from './board.mjs';
|
|
24
|
+
import { declaredEpicOf, planPathOf, planRows } from './board-epics.mjs';
|
|
25
|
+
import { verdictOnHead } from './board-runs.mjs';
|
|
26
|
+
import { ROOT } from './rt-kit-checks.config.mjs';
|
|
27
|
+
|
|
28
|
+
/** The machine mode: the numbers of the unfinished tasks instead of the table for the owner. */
|
|
29
|
+
const UNFINISHED = '--unfinished';
|
|
30
|
+
|
|
31
|
+
/** The machine account's token is substituted per call, as everywhere in the work with the queue. */
|
|
32
|
+
const OPTIONS = { token: botToken() };
|
|
33
|
+
|
|
34
|
+
/** How the outcome of the run is named in the cell: the word of the hosting says nothing to the owner. */
|
|
35
|
+
const VERDICT = {
|
|
36
|
+
success: 'зелёный',
|
|
37
|
+
failure: 'красный',
|
|
38
|
+
running: 'идёт',
|
|
39
|
+
none: 'не начинался',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** The current branch: the task number is read from it when the epic is not named by an argument. */
|
|
43
|
+
function branchOf() {
|
|
44
|
+
try {
|
|
45
|
+
return execFileSync('git', ['branch', '--show-current'], { cwd: ROOT, encoding: 'utf8' }).trim();
|
|
46
|
+
} catch {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A card with its body: the belonging to an epic and the path to the plan are declared exactly
|
|
53
|
+
* there, and the reading of the queue takes the body of the task apart, not its title.
|
|
54
|
+
*/
|
|
55
|
+
function issueOf(number) {
|
|
56
|
+
try {
|
|
57
|
+
return ghJson(['issue', 'view', String(number), '--json', 'number,title,state,body,labels'], OPTIONS);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof OfflineError) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Which epic is asked about: the argument names it, and without an argument it is taken from the
|
|
68
|
+
* current branch — the branch gives the task, the body of the task declares the epic.
|
|
69
|
+
*/
|
|
70
|
+
function epicAsked(argv) {
|
|
71
|
+
const named = argv.map((one) => one.replace(/^#/, '')).find((one) => /^\d+$/.test(one));
|
|
72
|
+
if (named !== undefined) {
|
|
73
|
+
return { number: Number(named), why: '' };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const branch = branchOf();
|
|
77
|
+
const number = numberFromBranch(branch);
|
|
78
|
+
if (number === null) {
|
|
79
|
+
return { number: null, why: `ветка «${branch}» не несёт номера задачи — назовите эпик доводом: node tools/epic-table.mjs <номер>` };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const issue = issueOf(number);
|
|
83
|
+
if (!issue) {
|
|
84
|
+
return { number: null, why: `у хостинга нет задачи #${number} — назовите эпик доводом` };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const declared = declaredEpicOf(String(issue.body ?? ''));
|
|
88
|
+
if (declared === undefined) {
|
|
89
|
+
return {
|
|
90
|
+
number: null,
|
|
91
|
+
why: `задача #${number} не объявляет эпика — в теле задачи под эпиком стоит строка «Задача эпика #<номер>»`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { number: Number(declared), why: '' };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The makeup of the epic: the ordinal, the number of the task and what it is about, in the order of the plan. */
|
|
99
|
+
function makeupOf(plan) {
|
|
100
|
+
const key = new RegExp(`(?:#|${TASK_KEY}-)(\\d+)`);
|
|
101
|
+
const rows = [];
|
|
102
|
+
for (const line of planRows(plan).split('\n')) {
|
|
103
|
+
const cells = line
|
|
104
|
+
.split('|')
|
|
105
|
+
.slice(1, -1)
|
|
106
|
+
.map((cell) => cell.trim());
|
|
107
|
+
if (cells.length < 2 || cells.every((cell) => /^:?-+:?$/.test(cell))) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const found = cells.map((cell) => key.exec(cell)).find(Boolean);
|
|
112
|
+
if (found) {
|
|
113
|
+
rows.push({ order: cells[0], number: Number(found[1]), about: cells[cells.length - 1] });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return rows;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The name of a task without the key in front: the key stands in a column of its own. */
|
|
120
|
+
function nameOf(title) {
|
|
121
|
+
return String(title ?? '').replace(new RegExp(`^\\[${TASK_KEY}-\\d+\\]\\s*`), '');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* One row of the table filled from the hosting: the name of the task and the state cell.
|
|
126
|
+
*
|
|
127
|
+
* A task is counted finished by the same reading the cell is written by: merged, or handed over by
|
|
128
|
+
* a request. Waiting for a merge is not work — the executor has nothing left to do about it, and
|
|
129
|
+
* the work of the epic is over exactly at that minute.
|
|
130
|
+
*
|
|
131
|
+
* The run is asked by the head of the request, not by the branch: the list of the runs of a branch
|
|
132
|
+
* answers about the last commit that started one, and a green run of a commit gone by then reads as
|
|
133
|
+
* a green head.
|
|
134
|
+
*/
|
|
135
|
+
function rowOf(number, board, pulls) {
|
|
136
|
+
const issue = issueOf(number);
|
|
137
|
+
if (!issue) {
|
|
138
|
+
return { name: '—', state: 'не заведена', finished: false };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const name = nameOf(issue.title);
|
|
142
|
+
if (issue.state !== 'OPEN') {
|
|
143
|
+
return { name, state: 'влито', finished: true };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const pull = pulls.find((one) => numberFromTitle(String(one.title ?? '')) === number);
|
|
147
|
+
if (!pull) {
|
|
148
|
+
const column = board.items.get(number)?.status ?? null;
|
|
149
|
+
return { name, state: column ? `в очереди, столбец «${column}»` : 'заведена, столбца нет', finished: false };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const verdict = verdictOnHead(pull.headRefOid, OPTIONS);
|
|
153
|
+
const draft = pull.isDraft === true ? 'черновик' : 'готова к слиянию';
|
|
154
|
+
return { name, state: `заявка #${pull.number} ${draft}, прогон на вершине ${VERDICT[verdict] ?? verdict}`, finished: true };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Why the epic exists, in one sentence — the first phrase of the section the plan opens with.
|
|
159
|
+
*
|
|
160
|
+
* A plan whose first section is worded otherwise loses the phrase, and the paragraph then names
|
|
161
|
+
* only the count of the tasks: that is the open question `Q-WC-9` of the subdomain.
|
|
162
|
+
*/
|
|
163
|
+
function whyOf(plan) {
|
|
164
|
+
const section = /^##\s+Зачем\s*$/m.exec(plan);
|
|
165
|
+
if (!section) {
|
|
166
|
+
return '';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const rest =
|
|
170
|
+
plan
|
|
171
|
+
.slice(section.index + section[0].length)
|
|
172
|
+
.split(/\n\s*\n/)
|
|
173
|
+
.find((piece) => piece.trim() !== '') ?? '';
|
|
174
|
+
const sentence = rest.trim().replace(/\s+/g, ' ');
|
|
175
|
+
const end = sentence.indexOf('. ');
|
|
176
|
+
return end === -1 ? sentence : sentence.slice(0, end + 1);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The paragraph above the table: an epic squeezed into columns loses what it is named for. */
|
|
180
|
+
function paragraphOf(epic, plan, rows) {
|
|
181
|
+
const running = rows.findIndex((row) => row.state !== 'влито');
|
|
182
|
+
const where = running === -1 ? 'все закрыты' : `идёт ${running + 1}`;
|
|
183
|
+
const why = whyOf(plan);
|
|
184
|
+
const tail = why === '' ? '' : ` — ${why}`;
|
|
185
|
+
return `**Эпик «${nameOf(epic.title)}» (${TASK_KEY}-${epic.number})**${tail} Задач ${rows.length}, ${where}.`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The table itself: the ordinal, the name, the key, what it is about, the state. */
|
|
189
|
+
function tableOf(rows) {
|
|
190
|
+
const head = ['| № | Задача | Номер | О чём | Состояние |', '| --- | --- | --- | --- | --- |'];
|
|
191
|
+
const body = rows.map((row) => `| ${row.order} | ${row.name} | ${TASK_KEY}-${row.number} | ${row.about} | ${row.state} |`);
|
|
192
|
+
return [...head, ...body];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The epic, its plan and the rows filled from the hosting — or the reason there is nothing to
|
|
197
|
+
* assemble. Both answers of the command stand on this one reading: assembled twice, they would
|
|
198
|
+
* count a task finished differently.
|
|
199
|
+
*/
|
|
200
|
+
function gathered(argv) {
|
|
201
|
+
const asked = epicAsked(argv);
|
|
202
|
+
if (asked.number === null) {
|
|
203
|
+
return { ok: false, why: asked.why };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const epic = issueOf(asked.number);
|
|
207
|
+
if (!epic) {
|
|
208
|
+
return { ok: false, why: `у хостинга нет карточки эпика #${asked.number}` };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const found = planPathOf(epic.body);
|
|
212
|
+
if (found.path === null) {
|
|
213
|
+
return { ok: false, why: `карточка эпика #${asked.number}: ${found.why}` };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const plan = readFileSync(join(ROOT, found.path), 'utf8');
|
|
217
|
+
const rows = makeupOf(plan);
|
|
218
|
+
if (rows.length === 0) {
|
|
219
|
+
return { ok: false, why: `замысел «${found.path}» не несёт состава эпика: состав — таблица со столбцом задач` };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const board = fetchBoard(OPTIONS);
|
|
223
|
+
const pulls = fetchOpenPulls(OPTIONS);
|
|
224
|
+
return { ok: true, why: '', epic, plan, rows: rows.map((row) => ({ ...row, ...rowOf(row.number, board, pulls) })) };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** The lines of the answer, or the refusal with the reason: the caller prints and ends. */
|
|
228
|
+
export function epicTable(argv) {
|
|
229
|
+
const found = gathered(argv);
|
|
230
|
+
if (!found.ok) {
|
|
231
|
+
return { ok: false, lines: [found.why] };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return { ok: true, lines: [paragraphOf(found.epic, found.plan, found.rows), '', ...tableOf(found.rows)] };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* The numbers of the tasks of the epic that are not finished, one per line — the machine answer for
|
|
239
|
+
* the guard of the stop.
|
|
240
|
+
*
|
|
241
|
+
* It is a mode of this very command, not a reader of its own: a second reading of the same tasks
|
|
242
|
+
* would diverge from the printed table in silence, and the guard would refuse work the table calls
|
|
243
|
+
* unfinished. An empty answer with the zero code means the epic is over.
|
|
244
|
+
*/
|
|
245
|
+
export function unfinished(argv) {
|
|
246
|
+
const found = gathered(argv);
|
|
247
|
+
if (!found.ok) {
|
|
248
|
+
return { ok: false, lines: [found.why] };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return { ok: true, lines: found.rows.filter((row) => row.finished !== true).map((row) => String(row.number)) };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const isEntryPoint = process.argv[1] && import.meta.url === `file://${process.argv[1]}`;
|
|
255
|
+
|
|
256
|
+
if (isEntryPoint) {
|
|
257
|
+
const argv = process.argv.slice(2);
|
|
258
|
+
const asked = argv.filter((one) => one !== UNFINISHED);
|
|
259
|
+
let outcome;
|
|
260
|
+
try {
|
|
261
|
+
outcome = argv.includes(UNFINISHED) ? unfinished(asked) : epicTable(asked);
|
|
262
|
+
} catch (error) {
|
|
263
|
+
const why = error instanceof OfflineError ? error.message : String(error?.message ?? error);
|
|
264
|
+
outcome = { ok: false, lines: [`состояние спросить нечем: ${why}`, 'таблица не печатается: пустая читается как пустой эпик'] };
|
|
265
|
+
}
|
|
266
|
+
process.stdout.write(outcome.lines.length === 0 ? '' : `${outcome.lines.join('\n')}\n`);
|
|
267
|
+
process.exit(outcome.ok ? 0 : 1);
|
|
268
|
+
}
|
|
@@ -79,6 +79,18 @@ const DEFAULTS = {
|
|
|
79
79
|
/** Where the domain specs lie; empty — the tree has none, and the spec audit is not run. */
|
|
80
80
|
specsDir: 'docs/specs',
|
|
81
81
|
tasksDir: 'docs/tasks',
|
|
82
|
+
/**
|
|
83
|
+
* Where the plans of work wider than one task live: the plan of an epic and the plan of work
|
|
84
|
+
* that does not fit into one session lie side by side there.
|
|
85
|
+
*
|
|
86
|
+
* The creating command needs it, the audit does not: the audit takes the path to a plan from
|
|
87
|
+
* the body of the epic card, and that stays the only truth about an epic already created. This
|
|
88
|
+
* key says only where a new plan is put — a directory that has not been named refuses the
|
|
89
|
+
* creation of an epic instead of scattering plans across the tree.
|
|
90
|
+
*
|
|
91
|
+
* Empty — the tree has no such directory, and an epic is not created by the command.
|
|
92
|
+
*/
|
|
93
|
+
plansDir: '',
|
|
82
94
|
/** Where the lists of accepted debts are put. */
|
|
83
95
|
allowlistDir: 'tools',
|
|
84
96
|
/**
|
|
@@ -216,6 +228,7 @@ const DEFAULTS = {
|
|
|
216
228
|
*/
|
|
217
229
|
longWork: {
|
|
218
230
|
label: '',
|
|
231
|
+
/** Empty — the tree's `plansDir` is taken: one directory is not named twice. */
|
|
219
232
|
plansDir: '',
|
|
220
233
|
},
|
|
221
234
|
/** The work queue: the owner, the repository, the board and the machine account. */
|
|
@@ -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());
|