@rt-tools/agent-kit 0.28.0 → 0.29.1

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 (81) hide show
  1. package/assets/checks/board-epic-link.github.mjs +13 -1
  2. package/assets/checks/board-epic-plan.github.mjs +128 -9
  3. package/assets/checks/board-epics.github.mjs +6 -10
  4. package/assets/checks/board-folders.mjs +50 -0
  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-lib-layers.mjs +4 -2
  8. package/assets/checks/check-spec-coverage.mjs +65 -0
  9. package/assets/checks/check-work-steps.mjs +238 -0
  10. package/assets/checks/epic-table.github.mjs +15 -6
  11. package/assets/checks/lib-common.mjs +9 -4
  12. package/assets/checks/lib-domains.mjs +7 -4
  13. package/assets/checks/main-run.github.mjs +69 -0
  14. package/assets/checks/rt-kit-checks.config.mjs +16 -1
  15. package/assets/checks/task-new.github.mjs +6 -6
  16. package/assets/checks/tree-assignment.mjs +169 -0
  17. package/assets/defaults/project.sh +15 -1
  18. package/assets/hooks/end-conversation-guard.sh +59 -0
  19. package/assets/hooks/epic-over.sh +11 -2
  20. package/assets/hooks/git-guard-delivery-epic.sh +15 -1
  21. package/assets/hooks/git-guard-delivery.sh +4 -2
  22. package/assets/hooks/git-guard-push-tests.sh +31 -8
  23. package/assets/hooks/git-guard-tree-assignment.sh +77 -0
  24. package/assets/hooks/grill-gate.sh +63 -2
  25. package/assets/hooks/hook-input.sh +8 -1
  26. package/assets/hooks/main-run-context.sh +45 -0
  27. package/assets/hooks/prose-style-guard.sh +49 -3
  28. package/assets/hooks/tree-assignment-guard.sh +101 -0
  29. package/assets/hooks/turn-exit-epic.sh +149 -0
  30. package/assets/hooks/turn-exit-guard.sh +40 -24
  31. package/assets/hooks/turn-exit-patterns.sh +50 -8
  32. package/assets/hooks/turn-exit-verdict.sh +39 -8
  33. package/assets/hooks/waiting-turn-guard.sh +56 -1
  34. package/assets/hooks/write-targets.sh +23 -1
  35. package/assets/laws/delivery.md +6 -0
  36. package/assets/laws/work-conduct.md +26 -0
  37. package/assets/patterns/doc-style-human.md +6 -0
  38. package/assets/patterns/git-workflow-merge.md +14 -0
  39. package/assets/patterns/git-workflow-pr-body.github.md +161 -0
  40. package/assets/patterns/git-workflow-pr.github.md +6 -104
  41. package/assets/patterns/git-workflow-stack.md +19 -2
  42. package/assets/patterns/spec-driven-domain.md +4 -0
  43. package/assets/patterns/status-report-table.github.md +6 -0
  44. package/assets/patterns/task-flow-close.md +1 -1
  45. package/assets/patterns/task-flow-resume.md +8 -0
  46. package/assets/patterns/task-flow-start.md +26 -22
  47. package/assets/patterns/testing-e2e.md +14 -0
  48. package/assets/pitfalls/git-workflow.github.md +6 -0
  49. package/assets/pitfalls/turn-conduct.md +46 -0
  50. package/assets/rules/doc-style.md +3 -2
  51. package/assets/rules/git-workflow.github.md +37 -38
  52. package/assets/rules/observability.needs-app.md +5 -0
  53. package/assets/rules/reuse-first.md +33 -11
  54. package/assets/rules/task-flow.md +57 -56
  55. package/assets/rules/testing.md +15 -0
  56. package/assets/rules/turn-conduct.md +70 -73
  57. package/assets/rules/typescript-conventions.md +8 -0
  58. package/assets/samples/tasks/_template/plan.md +7 -1
  59. package/assets/samples/tasks/_template/progress.md +14 -1
  60. package/bin/agent-kit.d.ts.map +1 -1
  61. package/bin/agent-kit.js +2 -1
  62. package/bin/agent-kit.js.map +1 -1
  63. package/lib/cargo.d.ts +49 -1
  64. package/lib/cargo.d.ts.map +1 -1
  65. package/lib/cargo.js +9 -2
  66. package/lib/cargo.js.map +1 -1
  67. package/lib/observations-cargo.d.ts +32 -0
  68. package/lib/observations-cargo.d.ts.map +1 -0
  69. package/lib/observations-cargo.js +105 -0
  70. package/lib/observations-cargo.js.map +1 -0
  71. package/lib/shipment.d.ts +8 -20
  72. package/lib/shipment.d.ts.map +1 -1
  73. package/lib/shipment.js +22 -39
  74. package/lib/shipment.js.map +1 -1
  75. package/lib/tree-mark.d.ts +17 -0
  76. package/lib/tree-mark.d.ts.map +1 -0
  77. package/lib/tree-mark.js +41 -0
  78. package/lib/tree-mark.js.map +1 -0
  79. package/package.json +1 -1
  80. package/rt-tools-agent-kit-0.29.1.tgz +0 -0
  81. package/rt-tools-agent-kit-0.28.0.tgz +0 -0
@@ -24,6 +24,18 @@ const TASK_KEY = CONFIG.board?.taskKey ?? '';
24
24
  * kinship of cards.
25
25
  */
26
26
  export function declaredEpicOf(body, number = null) {
27
- const named = String(body ?? '').match(new RegExp(`задач[аи]\\s+эпика?\\s+(?:#|${TASK_KEY}-)(\\d+)`, 'i'))?.[1];
27
+ const named = String(body ?? '').match(DECLARATION)?.[1];
28
28
  return number === null ? named : named !== undefined && Number(named) === number;
29
29
  }
30
+
31
+ /**
32
+ * The declaration opens its line: the creating command writes it as a line of its own, and a
33
+ * hand-written one carries at most an ordinal before it — «Первая задачи эпика #7». A list marker
34
+ * is allowed for the same reason: in a plan the declaration lies among items.
35
+ *
36
+ * Read anywhere in the line, it caught the same words inside a sentence: a task whose description
37
+ * said «семь задач эпика #1870» was read as belonging to that epic, and the delivery check refused
38
+ * its branch from the main one. The words alone cannot tell a declaration from prose about an
39
+ * epic — the place in the line can.
40
+ */
41
+ const DECLARATION = new RegExp(`^\\s*(?:[-*]\\s+)?(?:\\S+\\s+)?задач[аи]\\s+эпика?\\s+(?:#|${TASK_KEY}-)(\\d+)`, 'im');
@@ -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.
@@ -10,8 +10,8 @@
10
10
  * No network or no token — the calls throw `OfflineError`, like the rest of the work with the
11
11
  * hosting: an inability to ask does not count as a discrepancy.
12
12
  */
13
- import { existsSync } from 'node:fs';
14
- import { join } from 'node:path';
13
+ import { existsSync, readFileSync } from 'node:fs';
14
+ import { basename, join } from 'node:path';
15
15
 
16
16
  import { OWNER, REPO, gh } from './board.mjs';
17
17
  import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
@@ -169,6 +169,106 @@ export function evictedOnHead(sha, options) {
169
169
  .map((run) => run.id);
170
170
  }
171
171
 
172
+ /**
173
+ * Whether the pipeline wakes on a push to the main branch.
174
+ *
175
+ * A pipeline that listens to requests alone never runs on the main branch, and the absence of a
176
+ * run there says nothing: a tree like that gets no finding about the main run, and the audit says
177
+ * so out loud. The trigger is read from the pipeline file by its `on` block: a `push` key without
178
+ * a list of branches wakes on every branch, one with a list — on the branches named.
179
+ */
180
+ export function pipelineWakesOnPush(pipelineText, mainBranch) {
181
+ const lines = pipelineText.split('\n');
182
+ const indentOf = (line) => line.length - line.trimStart().length;
183
+ // The lines of a block: those below its key and indented deeper than it, blank ones included.
184
+ const blockAfter = (index) => {
185
+ const depth = indentOf(lines[index]);
186
+ const body = [];
187
+ for (let i = index + 1; i < lines.length; i += 1) {
188
+ if (lines[i].trim() !== '' && indentOf(lines[i]) <= depth) {
189
+ break;
190
+ }
191
+ body.push(lines[i]);
192
+ }
193
+ return body;
194
+ };
195
+
196
+ const onIndex = lines.findIndex((line) => /^on:\s*(#.*)?$/.test(line));
197
+ if (onIndex === -1) {
198
+ // The short form: `on: push` or `on: [push, pull_request]` — a push without a list of
199
+ // branches wakes on every branch.
200
+ return lines.some((line) => /^on:\s*(\[.*\bpush\b.*\]|push)\s*(#.*)?$/.test(line));
201
+ }
202
+
203
+ const on = blockAfter(onIndex);
204
+ const pushIndex = on.findIndex((line) => /^\s+push:\s*(#.*)?$/.test(line));
205
+ if (pushIndex === -1) {
206
+ return on.some((line) => /^\s+push:\s*\S/.test(line));
207
+ }
208
+
209
+ const pushLines = on.slice(pushIndex);
210
+ const pushDepth = indentOf(pushLines[0]);
211
+ const push = pushLines.slice(1).filter((line) => line.trim() === '' || indentOf(line) > pushDepth);
212
+ const branchesIndex = push.findIndex((line) => /^\s+branches:/.test(line));
213
+ if (branchesIndex === -1) {
214
+ return true;
215
+ }
216
+
217
+ const inline = /^\s+branches:\s*\[(.*)\]/.exec(push[branchesIndex]);
218
+ const names = inline
219
+ ? inline[1].split(',')
220
+ : push
221
+ .slice(branchesIndex + 1)
222
+ .filter((line) => /^\s+-\s/.test(line))
223
+ .map((line) => line.replace(/^\s+-\s*/, ''));
224
+ return names.map((name) => name.trim().replace(/^['"]|['"]$/g, '')).includes(mainBranch);
225
+ }
226
+
227
+ /**
228
+ * How the last run of the pipeline on the main branch ended: `success`, `failure`, `running`,
229
+ * `evicted` if it was pushed out of the queue and never started, or `none` if there was no run.
230
+ *
231
+ * The main branch is asked about apart from the rollout and apart from the tips of open requests.
232
+ * A merge is read as the end of the work, and the run it starts is read by nobody: a red run of the
233
+ * main branch stood for a day and a half, the rollout behind it did not go, and the owner said so.
234
+ * A cancelled run is told from a fallen one by its step count, the same way as on a request tip:
235
+ * zero steps means the queue pushed it out for the next merge, and the merge was checked by nothing.
236
+ */
237
+ export function lastMainRun(mainBranch, options) {
238
+ const runs = gh(
239
+ [
240
+ 'api',
241
+ `repos/${OWNER}/${REPO}/actions/workflows/${encodeURIComponent(basename(PIPELINE))}/runs` +
242
+ `?branch=${encodeURIComponent(mainBranch)}&per_page=1`,
243
+ '--jq',
244
+ '[.workflow_runs[] | {id, status, conclusion, sha: .head_sha, at: .created_at, url: .html_url}] | first // empty',
245
+ ],
246
+ options
247
+ );
248
+ const last = String(runs).trim();
249
+ if (!last) {
250
+ return { verdict: 'none' };
251
+ }
252
+
253
+ const run = JSON.parse(last);
254
+ if (run.status !== 'completed') {
255
+ return { verdict: 'running', ...run };
256
+ }
257
+ if (run.conclusion === 'success') {
258
+ return { verdict: 'success', ...run };
259
+ }
260
+ if (run.conclusion === 'cancelled' && jobCount(run.id, options) === 0) {
261
+ return { verdict: 'evicted', ...run };
262
+ }
263
+
264
+ return { verdict: 'failure', ...run };
265
+ }
266
+
267
+ /** The text of the pipeline file; an empty string where the tree has none. */
268
+ export function pipelineText() {
269
+ return HAS_PIPELINE ? readFileSync(join(ROOT, PIPELINE), 'utf8') : '';
270
+ }
271
+
172
272
  /** How many steps a run has started. Zero means it never started at all. */
173
273
  function jobCount(id, options) {
174
274
  const answer = gh(['api', `repos/${OWNER}/${REPO}/actions/runs/${id}/jobs?per_page=1`, '--jq', '.total_count'], options);
@@ -51,12 +51,17 @@ import {
51
51
  import { checkBranchFolders } from './board-folders.mjs';
52
52
  import { checkConflicting, checkHeadRun } from './board-pull-state.mjs';
53
53
  import { checkLongWork } from './board-long-work.mjs';
54
- import { HAS_PIPELINE, deployLag, lastDeploy } from './board-runs.mjs';
54
+ import { HAS_PIPELINE, deployLag, lastDeploy, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
55
55
  import { checkEpicLinks, checkEpicPullBase, checkEpicState, checkEpicSubIssues } from './board-epics.mjs';
56
56
  import { similarTitles } from './board-titles.mjs';
57
57
  import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
58
58
 
59
59
  const IN_REVIEW = STATUS_OPTIONS[IN_REVIEW_STATUS].name;
60
+ /**
61
+ * The columns a card reaches only after its task is closed: the merge closes the task, and the
62
+ * board's own rule moves the card. A tree that names neither gets no such audit.
63
+ */
64
+ const CLOSING_STATUSES = [STATUS_OPTIONS.done?.name, STATUS_OPTIONS.deployed?.name].filter((name) => typeof name === 'string' && name !== '');
60
65
  const TASKS_DIR = join(ROOT, CONFIG.tasksDir);
61
66
  /** Age of an abandoned draft after which it stops looking like one started today. */
62
67
  const DRAFT_DAYS = 7;
@@ -157,7 +162,7 @@ function folderInBranch(branch, options) {
157
162
  }
158
163
  }
159
164
 
160
- let checked = { issues: 0, pulls: 0, cargo: 0 };
165
+ let checked = { issues: 0, pulls: 0, cargo: 0, offBase: 0 };
161
166
 
162
167
  // Drafts are judged by the disk and so are checked always: no connection is needed for that.
163
168
  checkDrafts();
@@ -175,7 +180,7 @@ try {
175
180
  // such a record, whatever labels it wears.
176
181
  const open = CARGO_LABELS.size === 0 ? allOpen : allOpen.filter((issue) => !isCargo(issue));
177
182
  const pulls = fetchOpenPulls(options);
178
- checked = { issues: issues.length, pulls: pulls.length, cargo: allOpen.length - open.length };
183
+ checked = { issues: issues.length, pulls: pulls.length, cargo: allOpen.length - open.length, offBase: 0 };
179
184
 
180
185
  for (const item of board.foreign) {
181
186
  report(`the board: ${item} — the board holds tasks, not PRs about them`);
@@ -230,6 +235,9 @@ try {
230
235
  if (HAS_PIPELINE && pull.headRefOid) {
231
236
  checkHeadRun(pull, report, MAIN_BRANCH, options);
232
237
  }
238
+ if (pull.baseRefName && pull.baseRefName !== MAIN_BRANCH) {
239
+ checked.offBase += 1;
240
+ }
233
241
 
234
242
  checkConflicting(pull, report);
235
243
 
@@ -268,6 +276,16 @@ try {
268
276
  if (pull === undefined && status === IN_REVIEW) {
269
277
  report(`#${issue.number}: the task awaits review, and there is no open PR behind it — the column lags the work`);
270
278
  }
279
+ // A closing column is reached by a card whose task the merge has closed: the board moves
280
+ // it by its own rule on a closed item. An open task standing there says the opposite of
281
+ // what the owner reads from the column — and nobody notices: the mover to the last column
282
+ // skips such a card in silence, and the closing of a task merged into an epic branch is
283
+ // done by a pipeline that any tree may lack, may add later, or may see fail.
284
+ if (status !== null && CLOSING_STATUSES.includes(status)) {
285
+ report(
286
+ `#${issue.number}: the task is open, and its card stands at «${status}» — a closing column means the work is merged. Close the task, or move the card back by npm run task:move -- ${issue.number} <column>`
287
+ );
288
+ }
271
289
  }
272
290
 
273
291
  // The task folder dies with the task: what explains a settled decision moves to
@@ -328,11 +346,53 @@ if (!offline && DEPLOY_WORKFLOW) {
328
346
  }
329
347
  }
330
348
 
349
+ // The main branch is audited by the last run of the pipeline on it. A PR is checked before the
350
+ // merge, but the merge itself nobody watches: a red main run stood for a day and a half without a
351
+ // line about it, and a run pushed out of the queue by the next merge looked like a passed one.
352
+ if (!offline && HAS_PIPELINE) {
353
+ if (pipelineWakesOnPush(pipelineText(), MAIN_BRANCH)) {
354
+ try {
355
+ const run = lastMainRun(MAIN_BRANCH, { token: botToken() ?? undefined });
356
+ if (run.verdict === 'failure') {
357
+ report(
358
+ `the last run of «${MAIN_BRANCH}» is red on ${String(run.sha).slice(0, 8)} of ${String(run.at).slice(0, 10)}: ` +
359
+ `merges on top go out unchecked — ${run.url}`
360
+ );
361
+ } else if (run.verdict === 'evicted') {
362
+ report(
363
+ `the run of «${MAIN_BRANCH}» on ${String(run.sha).slice(0, 8)} was pushed out of the queue and never checked the merge — ${run.url}`
364
+ );
365
+ }
366
+ } catch (error) {
367
+ if (error instanceof OfflineError) {
368
+ console.log(`check-board: the main branch run was not checked — ${error.message}`);
369
+ } else {
370
+ throw error;
371
+ }
372
+ }
373
+ } else {
374
+ // Silence here would read as «main is green»: the tree whose pipeline sleeps on a push is told so.
375
+ console.log(`check-board: the main branch run was not checked — the pipeline does not wake on a push to «${MAIN_BRANCH}»`);
376
+ }
377
+ }
378
+
331
379
  // What was not checked is named out loud: silence about runs would read as "the runs are there".
332
380
  if (!offline && !DEPLOY_WORKFLOW) {
333
381
  console.log('check-board: production was not checked against the main branch — the rollout workflow is not named in the tree config');
334
382
  }
335
383
 
384
+ // A base other than the main branch has two consequences, and they are read from one line: the
385
+ // pipeline wakes for no such PR, and the host closes no task on its merge. Named apart, the
386
+ // second was read by nobody — the executor took the line about the run as the whole of it, and
387
+ // the tasks of a chain stayed open after their merges. Per PR the audit is silent: that is the
388
+ // order of handing in of every task of an epic, and a line on each would teach to skip the audit.
389
+ if (!offline && checked.offBase > 0) {
390
+ console.log(
391
+ `check-board: open PRs with a base other than «${MAIN_BRANCH}» — ${checked.offBase}: the pipeline gives them no run, ` +
392
+ `and the host closes no task on their merge — the tree closes those by a pipeline of its own or by the hand after the merge`
393
+ );
394
+ }
395
+
336
396
  // What was filtered out is named by number: silent filtering is indistinguishable from a broken
337
397
  // audit — a label named with a typo would switch the check off entirely and say nothing about it.
338
398
  if (!offline && checked.cargo > 0) {
@@ -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');