@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
@@ -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}» не несёт состава эпика: состав — таблица со столбцом задач` };
@@ -13,12 +13,17 @@ import { CONFIG, ROOT, parseAllowlist } from './rt-kit-checks.config.mjs';
13
13
 
14
14
  const FAMILIES = CONFIG.families;
15
15
  /**
16
- * The lib root and the backend family come from the tree settings, not from the code: in a tree
16
+ * The lib root and the backend families come from the tree settings, not from the code: in a tree
17
17
  * that keeps its libs under another name the walk went past the code and the check went green on an
18
18
  * empty directory — that is, it answered "no violations" where it had not looked at all.
19
19
  */
20
20
  const LIBS_ROOT = CONFIG.libsRoot;
21
- const API_FAMILY = CONFIG.apiFamily;
21
+ /**
22
+ * The backend families are a list, and a single name is read as a list of one: a tree holds more
23
+ * than one server application under the same root, and a family the walk skipped is
24
+ * indistinguishable from one walked without divergences.
25
+ */
26
+ const API_FAMILIES = [CONFIG.apiFamily ?? []].flat().filter(Boolean);
22
27
  /**
23
28
  * The selector prefix mandatory for frontend libs. The word belongs to the tree entirely; empty
24
29
  * means the prefix means nothing here, and the check says nothing about it.
@@ -37,7 +42,7 @@ const COMMON_DOMAIN_LAYERS = [...FLAT_LAYERS, 'feature'].sort();
37
42
  /** The backend has no `ui` and no `shell`: it renders no markup and does no routing */
38
43
  const API_DOMAIN_LAYERS = ['api', 'data-access', 'feature', 'util'];
39
44
  /** Where libs that ended up outside the domain grid are looked for */
40
- const LIB_ROOTS = [...FAMILIES, API_FAMILY].map((family) => `${LIBS_ROOT}/${family}`);
45
+ const LIB_ROOTS = [...FAMILIES, ...API_FAMILIES].map((family) => `${LIBS_ROOT}/${family}`);
41
46
  const REQUIRED_FILES = ['project.json', 'tsconfig.json', 'vitest.config.mts', 'src/index.ts'];
42
47
  const BOUNDARIES_DIR = 'eslint/boundaries/domains';
43
48
 
@@ -173,7 +178,7 @@ function sourceCount(libPath) {
173
178
  export {
174
179
  FAMILIES,
175
180
  LIBS_ROOT,
176
- API_FAMILY,
181
+ API_FAMILIES,
177
182
  LIB_PREFIX,
178
183
  BARREL_FILES,
179
184
  FLAT_LAYERS,
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import {
10
10
  API_DOMAIN_LAYERS,
11
- API_FAMILY,
11
+ API_FAMILIES,
12
12
  COMMON_DOMAIN_LAYERS,
13
13
  FAMILIES,
14
14
  FEATURE_DOMAIN_LAYERS,
@@ -88,7 +88,8 @@ function collectDomainLibs(domainPath, isCommon) {
88
88
  }
89
89
 
90
90
  /**
91
- * The domains of the backend: `<libs root>/<backend family>/<domain>` with four layers. `feature`
91
+ * The domains of the backend: `<libs root>/<backend family>/<domain>` with four layers, walked for
92
+ * every family of the list. `feature`
92
93
  * is both a lib and a directory with a lib per proto service — by the same rule by which a
93
94
  * feature domain of the frontend has `feature/<screen>`.
94
95
  *
@@ -99,8 +100,10 @@ function collectDomainLibs(domainPath, isCommon) {
99
100
  function collectApiDomainLibs() {
100
101
  const libs = [];
101
102
 
102
- for (const entry of dirsIn(`${LIBS_ROOT}/${API_FAMILY}`)) {
103
- const domainPath = `${LIBS_ROOT}/${API_FAMILY}/${entry}`;
103
+ const domainPaths = API_FAMILIES.flatMap((family) =>
104
+ dirsIn(`${LIBS_ROOT}/${family}`).map((entry) => `${LIBS_ROOT}/${family}/${entry}`)
105
+ );
106
+ for (const domainPath of domainPaths) {
104
107
  if (isNotDomain(domainPath) || isLegacyDomain(domainPath)) {
105
108
  continue;
106
109
  }
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The last run of the main branch in one line.
4
+ *
5
+ * node tools/main-run.mjs
6
+ *
7
+ * Two readers call it: the session start prints the line into the context, and the executor
8
+ * calls it after every known merge. The queue audit reads the same run and names the same two
9
+ * findings; this command exists because the audit waits to be called, while a merge made
10
+ * mid-session moves the main branch without anybody asking the audit.
11
+ *
12
+ * Silence here is never «green»: where the run could not be read — no pipeline file, a pipeline
13
+ * asleep on a push to the main branch, no network — the line says so. The exit code is 1 on a red
14
+ * or a pushed-out run and 0 in every other case, so that a chain after a merge stops on it.
15
+ */
16
+ import { OfflineError, botToken } from './board.mjs';
17
+ import { HAS_PIPELINE, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
18
+ import { CONFIG } from './rt-kit-checks.config.mjs';
19
+
20
+ const MAIN_BRANCH = CONFIG.deploy?.mainBranch ?? 'main';
21
+
22
+ /** The line for one reading of the run; exported so the suite can read it without the hosting. */
23
+ export function mainRunLine(run, mainBranch = MAIN_BRANCH) {
24
+ const sha = String(run.sha ?? '').slice(0, 8);
25
+ const day = String(run.at ?? '').slice(0, 10);
26
+ switch (run.verdict) {
27
+ case 'none':
28
+ return `main-run: «${mainBranch}» has no run yet`;
29
+ case 'running':
30
+ return `main-run: «${mainBranch}» is being checked on ${sha} — ${run.url}`;
31
+ case 'success':
32
+ return `main-run: «${mainBranch}» is green on ${sha} of ${day}`;
33
+ case 'evicted':
34
+ return `main-run: the run of «${mainBranch}» on ${sha} was pushed out of the queue and never checked the merge — ${run.url}`;
35
+ default:
36
+ return `main-run: «${mainBranch}» is RED on ${sha} of ${day}: merges on top go out unchecked — ${run.url}`;
37
+ }
38
+ }
39
+
40
+ function main() {
41
+ if (!HAS_PIPELINE) {
42
+ console.log('main-run: the main branch run was not read — the tree has no pipeline file');
43
+ return 0;
44
+ }
45
+ if (!pipelineWakesOnPush(pipelineText(), MAIN_BRANCH)) {
46
+ console.log(`main-run: the main branch run was not read — the pipeline does not wake on a push to «${MAIN_BRANCH}»`);
47
+ return 0;
48
+ }
49
+
50
+ let run;
51
+ try {
52
+ run = lastMainRun(MAIN_BRANCH, { token: botToken() ?? undefined });
53
+ } catch (error) {
54
+ if (error instanceof OfflineError) {
55
+ console.log(`main-run: the main branch run was not read — ${error.message}`);
56
+ return 0;
57
+ }
58
+ throw error;
59
+ }
60
+
61
+ console.log(mainRunLine(run, MAIN_BRANCH));
62
+ return run.verdict === 'failure' || run.verdict === 'evicted' ? 1 : 0;
63
+ }
64
+
65
+ // The suite imports the line without running the reading; the hosting is asked only when called.
66
+ const isEntryPoint = process.argv[1] && import.meta.url === `file://${process.argv[1]}`;
67
+ if (isEntryPoint) {
68
+ process.exit(main());
69
+ }
@@ -97,6 +97,21 @@ const DEFAULTS = {
97
97
  * Empty — the tree has no such directory, and an epic is not created by the command.
98
98
  */
99
99
  plansDir: '',
100
+ /**
101
+ * Where the assignment of an epic to a working copy is declared, and where a copy holds its own
102
+ * name.
103
+ *
104
+ * Two files, and they lie apart on purpose. The assignment belongs to the working copy and is
105
+ * declared in the main branch: written into the branch of a task, it is in force only there,
106
+ * and at the first branch switch the executor works by one order while the check reads another.
107
+ * The name of the copy is the state of the machine — the path to it belongs in nobody's
108
+ * history, so the copy names itself by a short word in a file outside the index.
109
+ *
110
+ * Empty — the tree declares no assignments, and nothing about them is judged: a tree with one
111
+ * working copy has nothing to divide.
112
+ */
113
+ assignmentsFile: '',
114
+ treeNameFile: '.claude/rt-kit/tree-name',
100
115
  /** Where the lists of accepted debts are put. */
101
116
  allowlistDir: 'tools',
102
117
  /**
@@ -171,7 +186,7 @@ const DEFAULTS = {
171
186
  libsRoot: 'libs',
172
187
  /** The families of front-end libs: `<libs root>/<family>/<domain>/<layer>`. */
173
188
  families: ['site', 'admin'],
174
- /** The backend family under the same root: its domains have a layer ladder of their own. */
189
+ /** The backend families under the same root — one name or a list of them; their domains have a layer ladder of their own. */
175
190
  apiFamily: 'api',
176
191
  /** The scope of import aliases: `@scope/<family>/<domain>/<layer>` in `tsconfig.base.json`. */
177
192
  importScope: '@app',
@@ -227,27 +227,27 @@ function epicOfCard(epicNumber) {
227
227
  // law into every task of the epic as its plan, and the branch of the epic was then read from
228
228
  // that law and came back empty. Both sides answered as usual, and the miss showed only by
229
229
  // reading a created task.
230
- const found = planPathOf(card.body, { makeupRequired: false });
230
+ const found = planPathOf(card.body, { makeupRequired: false, epicNumber });
231
231
  const plan = found.path;
232
232
  if (plan === null) {
233
233
  fail(`the card of the epic #${epicNumber}: ${found.why}. The branch of the epic is named in the plan too`);
234
234
  }
235
- return { plan, branch: epicBranchOf(plan, epicNumber) };
235
+ return { plan, branch: epicBranchOf(found.text, epicNumber) };
236
236
  }
237
237
 
238
238
  /**
239
- * The branch of the epic, read from the header of its plan.
239
+ * The branch of the epic, read from the header of its plan. The text comes from the shared reading:
240
+ * a plan of a live epic lies in the branch of that epic and not on the disk of this one.
240
241
  *
241
242
  * Three spellings are accepted: the one this command writes, the bare word about a branch and the
242
243
  * English one — the plans of a tree are translated one at a time, and a single spelling would take
243
244
  * every plan but the freshest out of the reading in silence.
244
245
  */
245
246
  function epicBranchOf(plan, epicNumber) {
246
- const path = join(ROOT, plan);
247
- if (!existsSync(path)) {
247
+ if (plan === null || plan === undefined) {
248
248
  return null;
249
249
  }
250
- const named = readFileSync(path, 'utf8').match(
250
+ const named = plan.match(
251
251
  new RegExp(`\\*\\*(?:Ветка эпика|Ветка|Branch):\\*\\*\\s*\`?(${TASK_KEY}-${epicNumber}-[a-z0-9][a-z0-9-]*)\`?`)
252
252
  );
253
253
  return named ? named[1] : null;
@@ -0,0 +1,169 @@
1
+ /**
2
+ * The epic assigned to this working copy.
3
+ *
4
+ * A machine holds several working copies of one tree, and a session in each of them asks the same
5
+ * question — which work is mine. The queue answers only what is open: it holds no owner of a card,
6
+ * and by topic one epic cannot be told from another. So the assignment is declared apart, and it
7
+ * is read from here by everyone who needs it — the startup hook, the delivery guard, the audit.
8
+ *
9
+ * Two files, and they lie apart. The assignment belongs to the working copy and is declared in the
10
+ * main branch — a record written into the branch of a task is in force only there. The name of the
11
+ * copy is the state of the machine: the path to it belongs in nobody's history, so the copy names
12
+ * itself by a short word in a file outside the index.
13
+ */
14
+ import { existsSync, readFileSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+
17
+ import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
18
+
19
+ /** The name this working copy calls itself by, or `null` where it names itself in no way. */
20
+ export function treeName(root = ROOT) {
21
+ const path = join(root, CONFIG.treeNameFile || '');
22
+
23
+ if (!CONFIG.treeNameFile || !existsSync(path)) {
24
+ return null;
25
+ }
26
+
27
+ const said = readFileSync(path, 'utf8').trim();
28
+
29
+ return said === '' ? null : said.split('\n')[0].trim();
30
+ }
31
+
32
+ /**
33
+ * The rows of the assignment table: the name of the copy, the epic, the plan of works and the day
34
+ * the assignment was given.
35
+ *
36
+ * The table is read by the shape of its row, not by the header: a header is translated, reordered
37
+ * and renamed, and every such edit would silently empty the answer. A row that does not hold a
38
+ * task key with a number is not an assignment — the heading row of the table and the line of dashes
39
+ * under it look exactly like a row to any reader that counts cells.
40
+ *
41
+ * A row whose epic cell holds a dash is a row all the same, and its epic is empty: «no work has
42
+ * been assigned to this copy» and «this copy is not in the table» are two different states, and
43
+ * whoever reads them needs to tell one from the other — the first is the owner's answer, the
44
+ * second is their silence.
45
+ */
46
+ export function assignments(root = ROOT) {
47
+ const path = join(root, CONFIG.assignmentsFile || '');
48
+
49
+ if (!CONFIG.assignmentsFile || !existsSync(path)) {
50
+ return [];
51
+ }
52
+
53
+ const key = CONFIG.board?.taskKey ?? '';
54
+ const epicRe = new RegExp(`^(?:#|${key}-)?(\\d+)$`);
55
+ const DASH = /^[-—–]$/;
56
+
57
+ return readFileSync(path, 'utf8')
58
+ .split('\n')
59
+ .filter((line) => line.trim().startsWith('|'))
60
+ .map((line) =>
61
+ line
62
+ .trim()
63
+ .replace(/^\||\|$/g, '')
64
+ .split('|')
65
+ .map((cell) => cell.trim().replace(/^`|`$/g, ''))
66
+ )
67
+ .filter((cells) => cells.length >= 2 && (epicRe.test(cells[1]) || DASH.test(cells[1])))
68
+ .map((cells) => ({
69
+ tree: cells[0],
70
+ epic: epicRe.test(cells[1]) ? Number(cells[1].match(epicRe)[1]) : null,
71
+ plan: cells[2] ?? '',
72
+ given: cells[3] ?? '',
73
+ }));
74
+ }
75
+
76
+ /** The assignment of this working copy, or `null` where the table names no such copy. */
77
+ export function assignmentOf(root = ROOT) {
78
+ const name = treeName(root);
79
+
80
+ return name === null ? null : (assignments(root).find((row) => row.tree === name) ?? null);
81
+ }
82
+
83
+ /**
84
+ * What is wrong with taking work under this epic — or an empty string where nothing is.
85
+ *
86
+ * Three answers, and they are different states, not degrees of one: the table names no such copy,
87
+ * the copy has no epic assigned, the epic is someone else's. The first two are cured by the owner's
88
+ * word and by nothing else; the third names both epics, so that the executor sees what they took
89
+ * and what they were given.
90
+ *
91
+ * A tree that declares no assignments is not judged: it has nothing to divide.
92
+ */
93
+ export function assignmentFault(epic, root = ROOT) {
94
+ if (!CONFIG.assignmentsFile) {
95
+ return '';
96
+ }
97
+
98
+ const key = CONFIG.board?.taskKey ?? '';
99
+ const name = treeName(root);
100
+
101
+ if (name === null) {
102
+ return `this working copy names itself in no way — write its short name into ${CONFIG.treeNameFile}, and the assignment table will find its row`;
103
+ }
104
+
105
+ const row = assignmentOf(root);
106
+
107
+ if (row === null) {
108
+ return `the table ${CONFIG.assignmentsFile} holds no row for the copy «${name}». Ask the owner what this copy leads; work is not taken by guesswork`;
109
+ }
110
+
111
+ if (row.epic === null) {
112
+ return `no epic is assigned to the copy «${name}» — the row in ${CONFIG.assignmentsFile} holds a dash. Ask the owner what to take; an epic chosen by oneself is not an order`;
113
+ }
114
+
115
+ if (epic !== null && epic !== undefined && String(epic) !== '' && Number(epic) !== row.epic) {
116
+ return `the copy «${name}» leads the epic ${key}-${row.epic}, and this work belongs to ${key}-${epic}. Someone else's epic is not taken by one's own decision: the owner moves the assignment`;
117
+ }
118
+
119
+ return '';
120
+ }
121
+
122
+ /**
123
+ * Called by hand and by the startup hook: it says what this copy answers for. The word about the
124
+ * absence is printed just as loudly as the assignment itself — a copy without a row is exactly the
125
+ * case in which work gets taken by guesswork.
126
+ */
127
+ if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) {
128
+ const assigned = process.argv.indexOf('--assigned');
129
+
130
+ if (assigned !== -1) {
131
+ // The number alone, for a caller that asks the queue about the state of that epic: the
132
+ // staleness of an assignment is not readable from the table — the table says what was
133
+ // given, the queue says whether it is still alive.
134
+ const row = assignmentOf();
135
+
136
+ console.log(row?.epic ?? '');
137
+ process.exit(0);
138
+ }
139
+
140
+ const asked = process.argv.indexOf('--fault');
141
+
142
+ if (asked !== -1) {
143
+ // The refusal text alone, and an empty answer where nothing is wrong: the caller is a guard,
144
+ // and it prints what it got. The exit code stays zero — the refusal is the guard's to make.
145
+ console.log(assignmentFault(process.argv[asked + 1] ?? ''));
146
+ process.exit(0);
147
+ }
148
+
149
+ const name = treeName();
150
+ const row = assignmentOf();
151
+
152
+ if (!CONFIG.assignmentsFile) {
153
+ console.log('tree-assignment: the tree declares no assignments — the key `assignmentsFile` is empty');
154
+ } else if (name === null) {
155
+ console.log(`tree-assignment: this working copy names itself in no way — write its short name into ${CONFIG.treeNameFile}`);
156
+ } else if (row === null) {
157
+ console.log(
158
+ `tree-assignment: «${name}» — the table ${CONFIG.assignmentsFile} holds no row for this copy. Ask the owner about it; work is not taken by guesswork`
159
+ );
160
+ } else if (row.epic === null) {
161
+ console.log(
162
+ `tree-assignment: «${name}» — no epic is assigned to this copy. Ask the owner about it; work is not taken by guesswork`
163
+ );
164
+ } else {
165
+ console.log(
166
+ `tree-assignment: «${name}» — epic ${CONFIG.board?.taskKey ?? ''}-${row.epic}, the plan of works ${row.plan}, given ${row.given}`
167
+ );
168
+ }
169
+ }