@rt-tools/agent-kit 0.29.0 → 0.29.2

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 (53) hide show
  1. package/assets/checks/board-epic-plan.github.mjs +128 -9
  2. package/assets/checks/board-epics.github.mjs +6 -10
  3. package/assets/checks/board-folders.mjs +50 -0
  4. package/assets/checks/check-lib-layers.mjs +4 -2
  5. package/assets/checks/check-spec-coverage.mjs +65 -0
  6. package/assets/checks/check-work-steps.mjs +238 -0
  7. package/assets/checks/epic-table.github.mjs +15 -6
  8. package/assets/checks/lib-common.mjs +9 -4
  9. package/assets/checks/lib-domains.mjs +7 -4
  10. package/assets/checks/rt-kit-checks.config.mjs +1 -1
  11. package/assets/checks/task-new.github.mjs +6 -6
  12. package/assets/defaults/project.sh +15 -1
  13. package/assets/hooks/git-guard-delivery-epic.sh +8 -1
  14. package/assets/hooks/git-guard-delivery-tree.sh +63 -16
  15. package/assets/hooks/git-guard-delivery.sh +12 -11
  16. package/assets/hooks/git-guard-no-verify.sh +142 -0
  17. package/assets/hooks/git-guard-push-tests.sh +39 -8
  18. package/assets/hooks/grill-gate.sh +63 -2
  19. package/assets/hooks/prose-style-guard.sh +49 -3
  20. package/assets/hooks/turn-exit-epic.sh +39 -0
  21. package/assets/hooks/turn-exit-guard.sh +6 -4
  22. package/assets/hooks/turn-exit-patterns.sh +51 -0
  23. package/assets/hooks/turn-exit-verdict.sh +20 -1
  24. package/assets/hooks/waiting-turn-guard.sh +56 -1
  25. package/assets/hooks/write-targets.sh +23 -1
  26. package/assets/laws/work-conduct.md +22 -0
  27. package/assets/patterns/doc-style-human.md +6 -0
  28. package/assets/patterns/git-workflow-commit.github.md +4 -0
  29. package/assets/patterns/git-workflow-merge.md +1 -0
  30. package/assets/patterns/git-workflow-pr-body.github.md +10 -5
  31. package/assets/patterns/spec-driven-domain.md +4 -0
  32. package/assets/patterns/status-report-table.github.md +6 -0
  33. package/assets/patterns/task-flow-start.md +27 -23
  34. package/assets/patterns/testing-e2e.md +25 -0
  35. package/assets/pitfalls/turn-conduct.md +28 -0
  36. package/assets/rules/doc-style.md +1 -1
  37. package/assets/rules/git-workflow.github.md +2 -1
  38. package/assets/rules/observability.needs-app.md +5 -0
  39. package/assets/rules/reuse-first.md +33 -11
  40. package/assets/rules/spec-driven.md +3 -1
  41. package/assets/rules/task-flow.md +30 -29
  42. package/assets/rules/testing.md +15 -0
  43. package/assets/rules/turn-conduct.md +44 -46
  44. package/assets/rules/typescript-conventions.md +8 -0
  45. package/assets/samples/tasks/_template/plan.md +7 -1
  46. package/assets/samples/tasks/_template/progress.md +13 -0
  47. package/lib/observations-cargo.d.ts +12 -0
  48. package/lib/observations-cargo.d.ts.map +1 -1
  49. package/lib/observations-cargo.js +18 -1
  50. package/lib/observations-cargo.js.map +1 -1
  51. package/package.json +1 -1
  52. package/rt-tools-agent-kit-0.29.2.tgz +0 -0
  53. package/rt-tools-agent-kit-0.29.0.tgz +0 -0
@@ -8,9 +8,11 @@
8
8
  * plan. Both sides answered as usual, and the miss showed only from a third side — by reading a
9
9
  * created task.
10
10
  */
11
+ import { execFileSync } from 'node:child_process';
11
12
  import { existsSync, readFileSync } from 'node:fs';
12
13
  import { join } from 'node:path';
13
14
 
15
+ import { TASK_KEY } from './board.mjs';
14
16
  import { ROOT } from './rt-kit-checks.config.mjs';
15
17
 
16
18
  /** A path counts as a spelling with a directory: a bare file name occurs in the body in prose. */
@@ -47,6 +49,37 @@ export function planRows(plan) {
47
49
  return rows.join('\n');
48
50
  }
49
51
 
52
+ /**
53
+ * The task column of the makeup, cell by cell: the numbers of the tasks live there and nowhere else.
54
+ *
55
+ * The state column names the request the task was merged by, and a number read from the whole row
56
+ * turns that request into a task of the epic: the audit then says the plan names tasks that are no
57
+ * sub-issues of the card, and points at requests. The column is the one by which a row counts as a
58
+ * makeup row at all — the one whose header carries the word for a task.
59
+ */
60
+ export function planTaskCells(plan) {
61
+ const cells = [];
62
+ let column = -1;
63
+ for (const line of String(plan ?? '').split('\n')) {
64
+ const row = line.trimStart();
65
+ if (!row.startsWith('|')) {
66
+ column = -1;
67
+ continue;
68
+ }
69
+
70
+ const parts = row.split('|').slice(1, -1);
71
+ if (column === -1) {
72
+ column = parts.findIndex((part) => /(?:Task|Задача)/.test(part));
73
+ continue;
74
+ }
75
+ if (column >= 0 && parts.length > column) {
76
+ cells.push(parts[column]);
77
+ }
78
+ }
79
+
80
+ return cells;
81
+ }
82
+
50
83
  /**
51
84
  * The plan of an epic named by its own card, and the reason there is none.
52
85
  *
@@ -55,20 +88,20 @@ export function planRows(plan) {
55
88
  * the makeup empty and every open task of the epic read as not belonging to it — fourteen false
56
89
  * lines at once, and the true ones drowned among them.
57
90
  */
58
- export function planPathOf(body, { makeupRequired = true } = {}) {
91
+ export function planPathOf(body, { makeupRequired = true, epicNumber = null } = {}) {
59
92
  const named = [...String(body ?? '').matchAll(PATH_IN_BODY)].map((match) => match[1]);
60
93
  if (named.length === 0) {
61
- return { path: null, why: 'the epic card names no path to the plan — there is nowhere to read what the epic holds' };
94
+ return { path: null, text: null, why: 'the epic card names no path to the plan — there is nowhere to read what the epic holds' };
62
95
  }
63
96
 
64
- const onDisk = named.filter((path) => existsSync(join(ROOT, path)));
65
- if (onDisk.length === 0) {
66
- return { path: null, why: `the epic plan «${named[0]}» is not on disk — the card points into emptiness` };
97
+ const read = named.map((path) => ({ path, text: planTextOf(path, epicNumber) })).filter((one) => one.text !== null);
98
+ if (read.length === 0) {
99
+ return { path: null, text: null, why: `the epic plan «${named[0]}» is not on disk — the card points into emptiness` };
67
100
  }
68
101
 
69
- const carrying = onDisk.find((path) => planRows(readFileSync(join(ROOT, path), 'utf8')) !== '') ?? null;
102
+ const carrying = read.find((one) => planRows(one.text) !== '') ?? null;
70
103
  if (carrying !== null) {
71
- return { path: carrying, why: '' };
104
+ return { path: carrying.path, text: carrying.text, why: '' };
72
105
  }
73
106
 
74
107
  // The makeup is not demanded of the creating command: it creates the tasks of an epic, and the
@@ -76,11 +109,97 @@ export function planPathOf(body, { makeupRequired = true } = {}) {
76
109
  // would refuse the very first task of every epic, and there would be no way to create one at
77
110
  // all. The audit runs later and demands it: by its minute the numbers stand in the plan.
78
111
  if (!makeupRequired) {
79
- return { path: onDisk[0], why: '' };
112
+ return { path: read[0].path, text: read[0].text, why: '' };
80
113
  }
81
114
 
82
115
  return {
83
116
  path: null,
84
- why: `none of the documents the card names carries the makeup of the epic — «${onDisk.join('», «')}». The makeup is a table with a task column`,
117
+ text: null,
118
+ why: `none of the documents the card names carries the makeup of the epic — «${read.map((one) => one.path).join('», «')}». The makeup is a table with a task column`,
85
119
  };
86
120
  }
121
+
122
+ /**
123
+ * The branches of an epic by its number — its own and those of the remotes.
124
+ *
125
+ * The name of an epic branch is the same pair the tree writes everywhere else: the key, the number,
126
+ * a slug. A tree without a key names no branches this way, and the search then gives nothing rather
127
+ * than every branch at once.
128
+ */
129
+ function epicBranches(epicNumber) {
130
+ if (!TASK_KEY || epicNumber === null || epicNumber === undefined) {
131
+ return [];
132
+ }
133
+
134
+ try {
135
+ const refs = execFileSync(
136
+ 'git',
137
+ [
138
+ 'for-each-ref',
139
+ '--format=%(refname:short)',
140
+ `refs/heads/${TASK_KEY}-${epicNumber}-*`,
141
+ `refs/remotes/*/${TASK_KEY}-${epicNumber}-*`,
142
+ ],
143
+ { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
144
+ );
145
+
146
+ return refs.split('\n').map((one) => one.trim()).filter((one) => one !== '');
147
+ } catch {
148
+ return [];
149
+ }
150
+ }
151
+
152
+ /**
153
+ * The text of a plan: off the disk, and where the disk does not carry it — out of the branch of the
154
+ * epic. Empty when neither has it.
155
+ *
156
+ * A plan lives in the branch of its epic until the epic is merged whole, and the working tree stands
157
+ * on whichever branch the session happens to be on. Read off the disk alone, every live epic came
158
+ * back as a card pointing into emptiness, and the true divergences drowned among those lines. The
159
+ * reading stays without the network — the branch folders check makes the same move.
160
+ */
161
+ export function planTextOf(path, epicNumber = null) {
162
+ for (const branch of epicBranches(epicNumber)) {
163
+ // The disk is no older exactly when the current branch has absorbed the tip of the epic
164
+ // branch. Taken the other way round, the audit reads the copy of the main branch — older by
165
+ // a whole epic — and says the plan does not carry tasks that stand in it.
166
+ if (absorbed(branch)) {
167
+ continue;
168
+ }
169
+
170
+ try {
171
+ return execFileSync('git', ['show', `${branch}:${path}`], {
172
+ cwd: ROOT,
173
+ encoding: 'utf8',
174
+ stdio: ['ignore', 'pipe', 'ignore'],
175
+ });
176
+ } catch {
177
+ // A branch that does not carry the plan says nothing about it: the rest are still read.
178
+ }
179
+ }
180
+
181
+ const onDisk = join(ROOT, path);
182
+
183
+ return existsSync(onDisk) ? readFileSync(onDisk, 'utf8') : null;
184
+ }
185
+
186
+ /**
187
+ * Has the current branch absorbed the tip of that one. Asked of version control, not guessed: on the
188
+ * branch of the epic itself and on the branches of its tasks the disk carries the same plan or a
189
+ * newer one, and there is nothing to read out of the branch.
190
+ *
191
+ * FAIL-OPEN towards the branch: a repository that cannot answer reads as not absorbed, and the plan
192
+ * is then taken out of the branch — the answer the audit needs more often.
193
+ */
194
+ function absorbed(branch) {
195
+ try {
196
+ execFileSync('git', ['merge-base', '--is-ancestor', branch, 'HEAD'], {
197
+ cwd: ROOT,
198
+ stdio: ['ignore', 'ignore', 'ignore'],
199
+ });
200
+
201
+ return true;
202
+ } catch {
203
+ return false;
204
+ }
205
+ }
@@ -2,13 +2,10 @@
2
2
  * The link between a task and an epic. Lives in a file of its own: the work queue audit stands at
3
3
  * the length limit even without it, and these two checks are read separately.
4
4
  */
5
- import { readFileSync } from 'node:fs';
6
- import { join } from 'node:path';
7
-
8
5
  import { declaredEpicOf } from './board-epic-link.mjs';
9
- import { planPathOf, planRows } from './board-epic-plan.mjs';
6
+ import { planPathOf, planRows, planTaskCells } from './board-epic-plan.mjs';
10
7
  import { ghJson, numberFromTitle, OfflineError, OWNER, REPO, TASK_KEY } from './board.mjs';
11
- import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
8
+ import { CONFIG } from './rt-kit-checks.config.mjs';
12
9
 
13
10
  /**
14
11
  * The label of an epic card. Not named — the link is not judged: there would be nothing left to
@@ -60,7 +57,7 @@ export function checkEpicLinks(open, report) {
60
57
  const unreadable = new Set();
61
58
 
62
59
  for (const epic of epics) {
63
- const found = planPathOf(epic.body);
60
+ const found = planPathOf(epic.body, { epicNumber: epic.number });
64
61
  if (found.path === null) {
65
62
  report(`#${epic.number}: ${found.why}`);
66
63
  unreadable.add(epic.number);
@@ -68,8 +65,7 @@ export function checkEpicLinks(open, report) {
68
65
  }
69
66
 
70
67
  const planPath = found.path;
71
- const plan = readFileSync(join(ROOT, planPath), 'utf8');
72
- const mentions = planRows(plan).matchAll(new RegExp(`(?:#|${TASK_KEY}-)(\\d+)`, 'g'));
68
+ const mentions = planTaskCells(found.text).join('\n').matchAll(new RegExp(`(?:#|${TASK_KEY}-)(\\d+)`, 'g'));
73
69
  const numbers = new Set([...mentions].map((match) => Number(match[1])));
74
70
  for (const number of numbers) {
75
71
  if (number === epic.number || !byNumber.has(number)) {
@@ -165,13 +161,13 @@ export function checkEpicSubIssues(open, report, options) {
165
161
 
166
162
  const epics = open.filter((issue) => (issue.labels ?? []).some((label) => label.name === EPIC_LABEL));
167
163
  for (const epic of epics) {
168
- const found = planPathOf(epic.body);
164
+ const found = planPathOf(epic.body, { epicNumber: epic.number });
169
165
  if (found.path === null) {
170
166
  // The unread plan has already been reported by a line of its own in the link check.
171
167
  continue;
172
168
  }
173
169
 
174
- const rows = planRows(readFileSync(join(ROOT, found.path), 'utf8'));
170
+ const rows = planTaskCells(found.text).join('\n');
175
171
  const named = new Set([...rows.matchAll(new RegExp(`(?:#|${TASK_KEY}-)(\\d+)`, 'g'))].map((match) => Number(match[1])));
176
172
  named.delete(epic.number);
177
173
  if (named.size === 0) {
@@ -12,6 +12,51 @@ import { execFileSync } from 'node:child_process';
12
12
  import { TASK_KEY } from './board.mjs';
13
13
  import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
14
14
 
15
+ /**
16
+ * Does the branch name itself the branch of an epic.
17
+ *
18
+ * An epic branch is named exactly like a task branch — the key, a number, a slug — and carries no
19
+ * task folder at all: it holds the plan of its epic and the merges of its tasks. Judged by the name
20
+ * alone it gave a divergence line for every epic of the tree, forever, and such a line is
21
+ * indistinguishable from a real one.
22
+ *
23
+ * The plan is read out of the branch, not off the disk: a plan of a young epic lives only in its
24
+ * own branch, and the working tree stands on whichever branch the session happens to be on. The
25
+ * pattern is the one the creating command writes the header with — a second pattern of our own
26
+ * would drift from the first in silence.
27
+ *
28
+ * The check stays without the network: it is the only part of the audit that reads the local
29
+ * repository, and the epic label lives at the hosting.
30
+ */
31
+ function namesItselfEpic(git, branch) {
32
+ if (!CONFIG.plansDir) {
33
+ return false;
34
+ }
35
+ const named = new RegExp(`\\*\\*(?:Ветка эпика|Ветка|Branch):\\*\\*\\s*\`?${branch}\`?`);
36
+
37
+ // The paths come NUL-separated: by default git quotes anything outside ASCII, and a plan named
38
+ // in the tree's own language would come back as escapes — neither found on disk nor matching the
39
+ // suffix. Here the plans are named in the owner's language more often than not.
40
+ let files;
41
+ try {
42
+ files = git(['ls-tree', '-r', '-z', '--name-only', branch, '--', CONFIG.plansDir]).split('\0');
43
+ } catch {
44
+ return false;
45
+ }
46
+
47
+ for (const file of files.map((one) => one.trim()).filter((one) => one.endsWith('.md'))) {
48
+ try {
49
+ if (named.test(git(['show', `${branch}:${file}`]))) {
50
+ return true;
51
+ }
52
+ } catch {
53
+ // A plan that cannot be read names no branch: the rest are still read.
54
+ }
55
+ }
56
+
57
+ return false;
58
+ }
59
+
15
60
  /**
16
61
  * The plan guard asks the folder from the disk, so an uncommitted one lets edits through for the
17
62
  * whole of the work, and the refusal comes at the very end: the turn exit guard takes the sign of
@@ -41,6 +86,11 @@ export function checkBranchFolders(report, mainBranch) {
41
86
  const numbered = new RegExp(`^${TASK_KEY}-\\d+-`);
42
87
 
43
88
  for (const branch of branches.map((one) => one.trim()).filter((one) => numbered.test(one))) {
89
+ // An epic branch has no task folder by design, and demanding one is a demand of the
90
+ // impossible: it carries the plan of its epic and the merges of its tasks, nothing of its own.
91
+ if (namesItselfEpic(git, branch)) {
92
+ continue;
93
+ }
44
94
  try {
45
95
  // The branch contribution is empty — nothing to judge: a folder is put in by the very
46
96
  // first commit, not by creating it.
@@ -23,7 +23,7 @@ import { existsSync } from 'node:fs';
23
23
  import { join } from 'node:path';
24
24
 
25
25
  import { checkBoundaries, checkCoreLibs, checkNoDependencyLibs } from './lib-boundaries.mjs';
26
- import { FAMILIES, LIBS_ROOT, LIB_ROOTS, isDir, problems, report } from './lib-common.mjs';
26
+ import { API_FAMILIES, FAMILIES, LIBS_ROOT, LIB_ROOTS, isDir, problems, report } from './lib-common.mjs';
27
27
  import { collectAllDomainLibs, collectApiDomainLibs, collectFlatLibs, collectStrayLibs } from './lib-domains.mjs';
28
28
  import { checkAliases, checkLib } from './lib-manifests.mjs';
29
29
  import { checkReexports } from './lib-reexports.mjs';
@@ -81,6 +81,8 @@ if (problems.length > 0) {
81
81
  process.exit(1);
82
82
  }
83
83
 
84
+ // The families of the backend are named one by one: a family the walk skipped is indistinguishable
85
+ // from one walked without divergences, and the number alone does not say which were read.
84
86
  console.log(
85
- `check-lib-layers: ${domainLibs.length} libs of the front domain grid, ${apiLibs.length} of the backend and ${flatLibs.length} flat ones, no divergences`
87
+ `check-lib-layers: ${domainLibs.length} libs of the front domain grid, ${apiLibs.length} of the backend (${API_FAMILIES.join(', ') || 'no family'}) and ${flatLibs.length} flat ones, no divergences`
86
88
  );
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The check that no resource of the package leaves without a spec.
4
+ *
5
+ * The measure existed before this check and answered zero whatever it found: the entry into the
6
+ * specs, called without a name, prints the gaps and leaves with a success. A number nobody refuses
7
+ * on is read once, by whoever asked, and never again — a resource added without a spec reached the
8
+ * package in silence, and the complaint about it had nothing to be checked against.
9
+ *
10
+ * The reading is not written a second time here. The list is asked from the very command that
11
+ * prints it: a reader of its own would diverge from the printed list without a word, and the two
12
+ * answers about one and the same tree would then disagree.
13
+ *
14
+ * FAIL-OPEN: a tree that declared no directories of package sources is not judged — it holds laid-
15
+ * out copies, and demanding a spec of someone else's package from it is demanding the impossible.
16
+ * The check says so aloud rather than staying silent: silence reads as "nothing found".
17
+ *
18
+ * A non-zero exit code and the list of the uncovered.
19
+ */
20
+ import { existsSync } from 'node:fs';
21
+ import { join } from 'node:path';
22
+ import { spawnSync } from 'node:child_process';
23
+
24
+ import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
25
+
26
+ /** Where the checks of the tree lie: the entry into the specs is called from there. */
27
+ const CHECKS = CONFIG.layout?.checks ?? 'tools';
28
+
29
+ /** The name of the entry as it lies in the tree. */
30
+ const ENTRY = join(ROOT, CHECKS, 'specs-for.mjs');
31
+
32
+ if (!Array.isArray(CONFIG.portableDirs) || CONFIG.portableDirs.length === 0) {
33
+ console.log('check-spec-coverage: the tree declares no directories of package sources — there is nothing to judge');
34
+ process.exit(0);
35
+ }
36
+
37
+ if (!existsSync(ENTRY)) {
38
+ console.log(`check-spec-coverage: the entry into the specs is not laid out (${CHECKS}/specs-for.mjs) — there is nothing to ask with`);
39
+ process.exit(0);
40
+ }
41
+
42
+ const asked = spawnSync(process.execPath, [ENTRY], { cwd: ROOT, encoding: 'utf8' });
43
+
44
+ if (asked.status !== 0) {
45
+ console.error('check-spec-coverage: the entry into the specs answered with a failure — the list of the uncovered could not be read');
46
+ process.exit(1);
47
+ }
48
+
49
+ const uncovered = asked.stdout
50
+ .split('\n')
51
+ .map((line) => line.trim())
52
+ .filter(Boolean);
53
+
54
+ if (uncovered.length > 0) {
55
+ console.error(`check-spec-coverage: resources no spec speaks of ${uncovered.length}`);
56
+
57
+ for (const path of uncovered) {
58
+ console.error(` ${path}`);
59
+ }
60
+
61
+ console.error('\nA resource is described by a spec of its kind before it leaves with the package: a complaint about it is checked against that spec and against nothing else.');
62
+ process.exit(1);
63
+ }
64
+
65
+ console.log('check-spec-coverage: every resource the package carries is spoken of by a spec');
@@ -0,0 +1,238 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The check that the steps of the progress match the steps of the plan.
4
+ *
5
+ * The plan holds the steps and is not edited after it is written; the progress holds the same list
6
+ * with a mark on every step and is rewritten by every turn that moves the work. Two lists in two
7
+ * files diverge silently: the progress names three steps where the plan named seven, and the guard
8
+ * counting what is not done counts three. Nothing else reads both files, so nothing else sees it.
9
+ *
10
+ * Three things are judged, and each of them is a divergence on its own:
11
+ * the set — the same step numbers, in the same order;
12
+ * the names — copied from the plan word for word, not reworded;
13
+ * the marks — exactly one step going on right now, while any step is not done yet.
14
+ *
15
+ * The numbering is «<stage>.<step>»: a bare ordinal says nothing about which stage the step belongs
16
+ * to, and the stages are renumbered by nobody — the plan is not edited after it is written.
17
+ *
18
+ * FAIL-OPEN: no task folder, no plan in it, or a plan that names no steps — a zero code. A tree
19
+ * that has not started writing steps is not refused: the requirement arrives with the sample of the
20
+ * plan, and the folders written before it stay lawful. A plan whose step names still stand as the
21
+ * sample wrote them — in angle brackets — is not judged either: that is the sample itself and a
22
+ * folder just copied from it. A progress that carries the section of steps while the plan carries
23
+ * none is a divergence: the list was written from the head.
24
+ *
25
+ * A non-zero exit code and the list of divergences.
26
+ */
27
+ import { existsSync, readFileSync, readdirSync } from 'node:fs';
28
+ import { join } from 'node:path';
29
+
30
+ import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
31
+
32
+ const TASKS = CONFIG.tasksDir ? join(ROOT, CONFIG.tasksDir) : '';
33
+
34
+ /** The heading the steps of the progress lie under. */
35
+ const STEPS_HEADING = /^##\s+(?:Steps|Шаги)\s*$/;
36
+ /** The heading the stages of the plan lie under. */
37
+ const STAGES_HEADING = /^##\s+(?:Stages|Этапы)\s*$/;
38
+ /** A stage heading: the number stands before the dot, the name after it. */
39
+ const STAGE_HEADING = /^###\s+(\d+)\.\s+(.+?)\s*$/;
40
+ /** The opening of the step list inside a stage. */
41
+ const STEPS_OPENING = /^-\s+\*\*(?:Steps|Шаги):\*\*\s*$/;
42
+ /** A step of the plan: an indented ordinal and the name. */
43
+ const PLAN_STEP = /^\s+(\d+)\.\s+(.+?)\s*$/;
44
+ /** Another key of the stage: it closes the step list. */
45
+ const STAGE_KEY = /^-\s+\*\*/;
46
+ /** A step of the progress: the mark, the number of the stage, the number of the step, the name. */
47
+ const PROGRESS_STEP = /^-\s+\[([x>\s])\]\s+(\d+)\.(\d+)\s+(.+?)\s*$/;
48
+ /**
49
+ * A name left as the sample wrote it. The sample of a task folder carries step names in angle
50
+ * brackets, and a folder just copied from it holds them on both sides — with different words, so
51
+ * every fresh folder would be red before a line of work is done in it. The sample directory itself
52
+ * is judged by the same sign and needs no name of its own here.
53
+ */
54
+ const BLANK_NAME = /^<.+>$/;
55
+
56
+ /** The mark of a step that is done. */
57
+ const DONE = 'x';
58
+ /** The mark of the step going on right now. */
59
+ const CURRENT = '>';
60
+
61
+ /** The steps of the plan: the number «<stage>.<step>» and the name, in the order they are written. */
62
+ function stepsOfPlan(text) {
63
+ const steps = [];
64
+ let stage = null;
65
+ let inside = false;
66
+ let listing = false;
67
+
68
+ for (const line of text.split('\n')) {
69
+ if (STAGES_HEADING.test(line)) {
70
+ inside = true;
71
+ continue;
72
+ }
73
+
74
+ if (inside && /^##\s+/.test(line)) {
75
+ break;
76
+ }
77
+
78
+ if (!inside) {
79
+ continue;
80
+ }
81
+
82
+ const heading = line.match(STAGE_HEADING);
83
+
84
+ if (heading) {
85
+ stage = heading[1];
86
+ listing = false;
87
+ continue;
88
+ }
89
+
90
+ if (STEPS_OPENING.test(line)) {
91
+ listing = true;
92
+ continue;
93
+ }
94
+
95
+ if (!listing) {
96
+ continue;
97
+ }
98
+
99
+ const step = line.match(PLAN_STEP);
100
+
101
+ if (step) {
102
+ steps.push({ number: `${stage}.${step[1]}`, name: step[2] });
103
+ continue;
104
+ }
105
+
106
+ if (STAGE_KEY.test(line) || line.trim() === '') {
107
+ listing = line.trim() === '' ? listing : false;
108
+ }
109
+ }
110
+
111
+ return steps;
112
+ }
113
+
114
+ /** The steps of the progress: the number, the name and the mark, in the order they are written. */
115
+ function stepsOfProgress(text) {
116
+ const steps = [];
117
+ let inside = false;
118
+
119
+ for (const line of text.split('\n')) {
120
+ if (STEPS_HEADING.test(line)) {
121
+ inside = true;
122
+ continue;
123
+ }
124
+
125
+ if (inside && /^##\s+/.test(line)) {
126
+ break;
127
+ }
128
+
129
+ if (!inside) {
130
+ continue;
131
+ }
132
+
133
+ const step = line.match(PROGRESS_STEP);
134
+
135
+ if (step) {
136
+ steps.push({ mark: step[1].trim() || ' ', number: `${step[2]}.${step[3]}`, name: step[4] });
137
+ }
138
+ }
139
+
140
+ return { steps, declared: inside };
141
+ }
142
+
143
+ /** What is wrong with one task folder. An empty list means it matches. */
144
+ function judge(folder) {
145
+ const plan = join(folder, 'plan.md');
146
+ const progress = join(folder, 'progress.md');
147
+
148
+ if (!existsSync(plan) || !existsSync(progress)) {
149
+ return [];
150
+ }
151
+
152
+ const planned = stepsOfPlan(readFileSync(plan, 'utf8'));
153
+ const { steps: marked, declared } = stepsOfProgress(readFileSync(progress, 'utf8'));
154
+
155
+ if (planned.some((step) => BLANK_NAME.test(step.name))) {
156
+ return [];
157
+ }
158
+
159
+ if (planned.length === 0) {
160
+ return declared && marked.length > 0
161
+ ? ['the progress carries a list of steps, and the plan names none: the list was written from the head']
162
+ : [];
163
+ }
164
+
165
+ if (!declared) {
166
+ return [`the plan names ${planned.length} steps, and the progress carries no section of steps`];
167
+ }
168
+
169
+ const problems = [];
170
+
171
+ if (marked.length !== planned.length) {
172
+ problems.push(`the plan names ${planned.length} steps, the progress ${marked.length}`);
173
+ }
174
+
175
+ for (let index = 0; index < Math.min(planned.length, marked.length); index += 1) {
176
+ if (planned[index].number !== marked[index].number) {
177
+ problems.push(`step ${index + 1} in a row: the plan calls it «${planned[index].number}», the progress «${marked[index].number}»`);
178
+ continue;
179
+ }
180
+
181
+ if (planned[index].name !== marked[index].name) {
182
+ problems.push(`step ${planned[index].number}: the name in the progress is not the name in the plan — «${marked[index].name}»`);
183
+ }
184
+ }
185
+
186
+ const current = marked.filter((step) => step.mark === CURRENT);
187
+ const left = marked.filter((step) => step.mark !== DONE);
188
+
189
+ if (left.length > 0 && current.length !== 1) {
190
+ problems.push(
191
+ current.length === 0
192
+ ? `${left.length} steps are not done, and none is marked as going on right now`
193
+ : `${current.length} steps are marked as going on right now, and there is only ever one`,
194
+ );
195
+ }
196
+
197
+ if (left.length === 0 && current.length > 0) {
198
+ problems.push('every step is done, and one is still marked as going on right now');
199
+ }
200
+
201
+ return problems;
202
+ }
203
+
204
+ if (!TASKS || !existsSync(TASKS)) {
205
+ console.log('check-work-steps: the tree has no task folders — there is nothing to check');
206
+ process.exit(0);
207
+ }
208
+
209
+ const found = [];
210
+ let counted = 0;
211
+
212
+ for (const entry of readdirSync(TASKS, { withFileTypes: true })) {
213
+ if (!entry.isDirectory()) {
214
+ continue;
215
+ }
216
+
217
+ const folder = join(TASKS, entry.name);
218
+ const problems = judge(folder);
219
+
220
+ counted += 1;
221
+
222
+ for (const problem of problems) {
223
+ found.push(`${entry.name}: ${problem}`);
224
+ }
225
+ }
226
+
227
+ if (found.length > 0) {
228
+ console.error(`check-work-steps: divergences ${found.length}`);
229
+
230
+ for (const problem of found) {
231
+ console.error(` ${problem}`);
232
+ }
233
+
234
+ console.error('\nThe steps are written in the plan and mirrored in the progress with a mark each: the numbers and the names are copied, not reworded.');
235
+ process.exit(1);
236
+ }
237
+
238
+ console.log(`check-work-steps: task folders ${counted}, the steps of the plan and of the progress match`);
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- // rt-kit v0.26.0 · checks/epic-table.github.mjs · ca65adf7e1b9 · правится надстройкой, не здесь
3
2
  /**
4
3
  * The table of the epic's tasks: the order from the plan, the state from the hosting.
5
4
  *
@@ -17,13 +16,11 @@
17
16
  * empty epic.
18
17
  */
19
18
  import { execFileSync } from 'node:child_process';
20
- import { readFileSync } from 'node:fs';
21
- import { join } from 'node:path';
22
19
 
23
20
  import { OfflineError, TASK_KEY, botToken, fetchBoard, fetchOpenPulls, ghJson, numberFromBranch, numberFromTitle } from './board.mjs';
24
21
  import { declaredEpicOf, planPathOf, planRows } from './board-epics.mjs';
25
22
  import { verdictOnHead } from './board-runs.mjs';
26
- import { ROOT } from './rt-kit-checks.config.mjs';
23
+ import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
27
24
 
28
25
  /** The machine mode: the numbers of the unfinished tasks instead of the table for the owner. */
29
26
  const UNFINISHED = '--unfinished';
@@ -84,6 +81,15 @@ function epicAsked(argv) {
84
81
  return { number: null, why: `у хостинга нет задачи #${number} — назовите эпик доводом` };
85
82
  }
86
83
 
84
+ // The branch of the epic itself: its card declares no other epic, because it is the epic. It is
85
+ // taken by the label of an epic card — the same one the queue audit tells an epic from a task
86
+ // by. Without this the answer «the task declares no epic» read as a broken card rather than as
87
+ // a question asked the wrong way.
88
+ const epicLabel = CONFIG.board?.epicLabel ?? '';
89
+ if (epicLabel && (issue.labels ?? []).some((label) => label.name === epicLabel)) {
90
+ return { number, why: '' };
91
+ }
92
+
87
93
  const declared = declaredEpicOf(String(issue.body ?? ''));
88
94
  if (declared === undefined) {
89
95
  return {
@@ -208,12 +214,15 @@ function gathered(argv) {
208
214
  return { ok: false, why: `у хостинга нет карточки эпика #${asked.number}` };
209
215
  }
210
216
 
211
- const found = planPathOf(epic.body);
217
+ // Текст плана берёт общее чтение: план живого эпика лежит в ветке этого эпика, а рабочая копия
218
+ // стоит на той ветке, на которой стоит. Читая с диска, таблица отвечала «карточка указывает в
219
+ // пустоту» на любой ветке, кроме ветки самого эпика.
220
+ const found = planPathOf(epic.body, { epicNumber: epic.number });
212
221
  if (found.path === null) {
213
222
  return { ok: false, why: `карточка эпика #${asked.number}: ${found.why}` };
214
223
  }
215
224
 
216
- const plan = readFileSync(join(ROOT, found.path), 'utf8');
225
+ const plan = found.text;
217
226
  const rows = makeupOf(plan);
218
227
  if (rows.length === 0) {
219
228
  return { ok: false, why: `замысел «${found.path}» не несёт состава эпика: состав — таблица со столбцом задач` };