@rt-tools/agent-kit 0.27.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/assets/checks/board-epic-plan.github.mjs +86 -0
  2. package/assets/checks/board-epics.github.mjs +12 -67
  3. package/assets/checks/board-pull-state.github.mjs +6 -11
  4. package/assets/checks/check-glossary.mjs +10 -2
  5. package/assets/checks/check-lib-layers.mjs +24 -1
  6. package/assets/checks/check-reuse.mjs +26 -2
  7. package/assets/checks/check-specs.mjs +8 -1
  8. package/assets/checks/lib-boundaries.mjs +2 -2
  9. package/assets/checks/lib-common.mjs +46 -0
  10. package/assets/checks/lib-manifests.mjs +18 -13
  11. package/assets/checks/rt-kit-checks.config.mjs +6 -0
  12. package/assets/checks/signals.mjs +39 -5
  13. package/assets/checks/spec-anchors.mjs +48 -4
  14. package/assets/checks/spec-common.mjs +40 -6
  15. package/assets/checks/spec-contract.mjs +33 -7
  16. package/assets/checks/spec-scenarios.mjs +24 -1
  17. package/assets/checks/task-new.github.mjs +9 -3
  18. package/assets/defaults/gate-map.sh +20 -5
  19. package/assets/defaults/project.sh +6 -0
  20. package/assets/hooks/dev-server-guard.sh +61 -32
  21. package/assets/hooks/exam-guard.sh +10 -10
  22. package/assets/hooks/git-guard-delivery-conflict.sh +53 -1
  23. package/assets/hooks/git-guard-delivery-draft.sh +7 -6
  24. package/assets/hooks/git-guard-delivery-tree.sh +50 -0
  25. package/assets/hooks/git-guard-delivery.sh +43 -23
  26. package/assets/hooks/git-guard-discard.sh +144 -0
  27. package/assets/hooks/git-guard-push-tests.sh +36 -16
  28. package/assets/hooks/reuse-first-guard.sh +29 -4
  29. package/assets/hooks/rule-source-guard.sh +17 -2
  30. package/assets/hooks/skill-gate.sh +7 -0
  31. package/assets/hooks/sql-guard-write.sh +18 -2
  32. package/assets/hooks/turn-exit-guard.sh +50 -66
  33. package/assets/hooks/turn-exit-patterns.sh +18 -1
  34. package/assets/hooks/turn-exit-verdict.sh +84 -0
  35. package/assets/laws/delivery.md +14 -6
  36. package/assets/laws/verifiability.md +22 -4
  37. package/assets/patterns/git-workflow-pr.github.md +39 -18
  38. package/assets/patterns/git-workflow-stack.md +21 -2
  39. package/assets/patterns/task-flow-close.md +65 -78
  40. package/assets/patterns/ts-procedure.md +6 -0
  41. package/assets/pitfalls/git-workflow.github.md +38 -0
  42. package/assets/pitfalls/task-flow.md +25 -23
  43. package/assets/rules/browser-verification.md +8 -0
  44. package/assets/rules/deploy-flow.github.md +6 -0
  45. package/assets/rules/doc-style.md +6 -0
  46. package/assets/rules/git-workflow.azure.md +10 -0
  47. package/assets/rules/git-workflow.github.md +119 -119
  48. package/assets/rules/git-workflow.gitlab.md +10 -0
  49. package/assets/rules/lib-layers.md +11 -0
  50. package/assets/rules/spec-driven.md +10 -1
  51. package/assets/rules/task-flow.md +59 -56
  52. package/assets/rules/testing.md +7 -0
  53. package/assets/rules/turn-conduct.md +23 -3
  54. package/assets/samples/tasks/_template/plan.md +4 -1
  55. package/assets/skills/agent-kit.md +17 -4
  56. package/bin/agent-kit.js +1 -1
  57. package/bin/agent-kit.js.map +1 -1
  58. package/lib/commands.d.ts +1 -1
  59. package/lib/commands.d.ts.map +1 -1
  60. package/lib/commands.js +59 -2
  61. package/lib/commands.js.map +1 -1
  62. package/lib/hooks-map.d.ts +5 -0
  63. package/lib/hooks-map.d.ts.map +1 -1
  64. package/lib/hooks-map.js +9 -3
  65. package/lib/hooks-map.js.map +1 -1
  66. package/lib/plan.d.ts +2 -0
  67. package/lib/plan.d.ts.map +1 -1
  68. package/lib/plan.js +8 -0
  69. package/lib/plan.js.map +1 -1
  70. package/lib/proposals.d.ts +25 -0
  71. package/lib/proposals.d.ts.map +1 -1
  72. package/lib/proposals.js +43 -1
  73. package/lib/proposals.js.map +1 -1
  74. package/lib/shipment.d.ts.map +1 -1
  75. package/lib/shipment.js +8 -11
  76. package/lib/shipment.js.map +1 -1
  77. package/package.json +1 -1
  78. package/rt-tools-agent-kit-0.28.0.tgz +0 -0
  79. package/rt-tools-agent-kit-0.27.0.tgz +0 -0
@@ -13,7 +13,9 @@ import {
13
13
  VERDICT,
14
14
  VERDICT_MIN,
15
15
  bulletsOf,
16
+ codeOf,
16
17
  exists,
18
+ isTestFile,
17
19
  read,
18
20
  report,
19
21
  sectionOf,
@@ -203,7 +205,6 @@ function checkRuleImplementation(specFile, text, mapFile, heading = ['## Rules',
203
205
  * Code without comments. A symbol named in an explanation is called by nobody, and dead code
204
206
  * usually has more explanations than live code does.
205
207
  */
206
- const codeOf = (text) => text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:`'"])\/\/.*$/gm, '$1');
207
208
 
208
209
  const DECLARATION_MODIFIERS = '(?:export|declare|abstract|public|private|protected|static|readonly|override|async|accessor)';
209
210
 
@@ -257,6 +258,36 @@ function symbolOwners() {
257
258
  return owners;
258
259
  }
259
260
 
261
+ /**
262
+ * The files a package publishes outward: everything a `public-api.ts` or an `index.ts` re-exports,
263
+ * and everything those files re-export in turn. A symbol of a published file is called by whoever
264
+ * installed the package, and that caller is not in this tree at all: judged by the calls visible
265
+ * here, the whole public API of a kit reads as dead code.
266
+ */
267
+ function publishedFiles() {
268
+ const published = new Set();
269
+ const entries = SOURCE_ROOTS.flatMap((root) => walk(root, (name) => name === 'public-api.ts' || name === 'index.ts'));
270
+ const queue = [...entries];
271
+ while (queue.length) {
272
+ const file = queue.pop();
273
+ const dir = file.slice(0, file.lastIndexOf('/'));
274
+ for (const [, relative] of read(file).matchAll(/(?:export|import)[^'"]*from\s+['"](\.[^'"]*)['"]/g)) {
275
+ for (const suffix of ['.ts', '/index.ts', '']) {
276
+ const path = `${dir}/${relative.replace(/^\.\//, '')}${suffix}`.replace(/\/\.\//g, '/');
277
+ if (exists(path) && !published.has(path)) {
278
+ published.add(path);
279
+ if (path.endsWith('/index.ts')) {
280
+ queue.push(path);
281
+ }
282
+ break;
283
+ }
284
+ }
285
+ }
286
+ }
287
+
288
+ return published;
289
+ }
290
+
260
291
  /**
261
292
  * A symbol declared in its own file and met nowhere else carries nothing out: a rule bound
262
293
  * to it describes an intention.
@@ -277,6 +308,7 @@ function checkTracedAnchors() {
277
308
  }
278
309
 
279
310
  const owners = symbolOwners();
311
+ const published = publishedFiles();
280
312
  for (const { mapFile, path, symbol } of declared) {
281
313
  // A word boundary is placed only where one exists: there is none before a hash, and a
282
314
  // pattern with it would give zero occurrences for every private name.
@@ -284,12 +316,24 @@ function checkTracedAnchors() {
284
316
  ? `${escapeForRegExp(symbol)}\\b`
285
317
  : `\\b${escapeForRegExp(symbol)}\\b`;
286
318
  const here = (codeAt(path).match(new RegExp(bound, 'g')) || []).length;
287
- const elsewhere = [...(owners.get(symbol) || [])].filter((file) => file !== path).length;
319
+ // A test is not a call. A function written test-first and never called from the
320
+ // application is an intention: the test calls it itself, and by that call a live symbol
321
+ // cannot be told from a forgotten one. Counted together, the declaration and the test file
322
+ // next to it made two — the threshold — and the audit went green exactly when the binding
323
+ // lied hardest.
324
+ // The exclusion works only for a symbol declared in the code of the application. A helper
325
+ // declared in the suite harness itself is called by tests by its very purpose: judged by
326
+ // the same measure, the articles of the testing rule would all turn red at once.
327
+ const others = [...(owners.get(symbol) || [])].filter((file) => file !== path);
328
+ const elsewhere = isTestFile(path) || published.has(path) ? others.length : others.filter((file) => !isTestFile(file)).length;
288
329
  if (here + elsewhere < 2) {
289
330
  report(
290
331
  mapFile,
291
- `the binding leads into dead code: \`${symbol}\` is declared in \`${path}\` and met nowhere else — ` +
292
- 'either the statement is carried out elsewhere, or its place is in «Open questions» of the law as Q-<letter>-<number>'
332
+ others.length > elsewhere
333
+ ? `the binding leads into code called by a test alone: \`${symbol}\` is declared in \`${path}\` and outside tests is met nowhere — ` +
334
+ 'a test is not a call from the application; either the statement is carried out elsewhere, or its place is in «Open questions» of the law as Q-<letter>-<number>'
335
+ : `the binding leads into dead code: \`${symbol}\` is declared in \`${path}\` and met nowhere else — ` +
336
+ 'either the statement is carried out elsewhere, or its place is in «Open questions» of the law as Q-<letter>-<number>'
293
337
  );
294
338
  }
295
339
  }
@@ -41,23 +41,48 @@ const SKIPPED_DIRS = CONFIG.skippedDirs;
41
41
  /**
42
42
  * `### SC-BK-03 — a request for dates already taken`
43
43
  *
44
- * The number is accepted from one digit to three. A heading that did not match the template starts
45
- * no scenario and gives no refusal: a tree that numbered its scenarios from one would lose the
46
- * first nine of them silently — neither in coverage nor in debts, with a green audit.
44
+ * The number is accepted from one digit to four, the prefix from two letters to six. A heading the
45
+ * template did not take used to start no scenario and give no refusal: this tree crossed a
46
+ * thousand scenarios and lost the whole thousandth series at once — neither in coverage nor in
47
+ * debts, with a green audit. Now such a heading is named as a discrepancy of its own.
47
48
  */
48
- const SCENARIO_HEADING = /^###\s+(SC-([A-Z]{2,4})-(\d{1,3}))\s+—\s+(.+?)\s*$/;
49
+ const SCENARIO_HEADING = /^###\s+(SC-([A-Z]{2,6})-(\d{1,4}))\s+—\s+(.+?)\s*$/;
49
50
  /**
50
51
  * The keys of a spec are read under two names, English and the owner's. A tree translates its
51
52
  * specs one domain at a time, and a key that moved instead of learning the second name takes the
52
53
  * untranslated domains out of the audit silently: the heading is not found, the statements and the
53
54
  * scenarios are not read, and the audit stays green about a domain it no longer sees.
54
55
  */
56
+ /**
57
+ * The code of a file without its explanations. A declaration read as text — a right at a
58
+ * procedure, a boundary tag in a linter setting — is looked for here and not in the raw text: a
59
+ * sample call written in an explanation next to the real mark substitutes itself for it, and the
60
+ * right of a comment travels into the audit. Caught on a live one.
61
+ */
62
+ const codeOf = (text) => text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/(^|[^:`'"])\/\/.*$/gm, '$1');
63
+
64
+ /**
65
+ * A file that only serves the tests. A test is not a call from the application: a symbol declared
66
+ * and met nowhere but in the test next to it is an intention, and by such a meeting a live symbol
67
+ * cannot be told from a forgotten one.
68
+ *
69
+ * Besides the tests themselves this counts the harness the tree named by the key `harnessDirs` —
70
+ * a directory or a single file: a snapshot harness, a fixture builder. Their symbols are called
71
+ * by tests by their very purpose. The list is named narrowly: a showcase directory taken whole
72
+ * carries the stories with it, and a story calling a component is a real call.
73
+ */
74
+ const HARNESS_DIRS = CONFIG.harnessDirs ?? [];
75
+
76
+ function isTestFile(path) {
77
+ return /\.(?:spec|test|e2e)\.[jt]s$|(?:^|\/)tests?\/|-e2e\//.test(path) || HARNESS_DIRS.some((named) => path === named || path.startsWith(`${named}/`));
78
+ }
79
+
55
80
  /** The mark of a knowingly uncovered scenario; the reason is mandatory */
56
81
  const UNCOVERED = /^(?:Not covered|Не покрыто):\s*\S/;
57
82
  /** The test exists, but checks not everything promised or goes another way */
58
83
  const PARTIAL = /^(?:Coverage:\s*partial|Покрытие:\s*частичное)\s*—\s*\S/;
59
84
  /** A mention of the scenario in the title of a test; the number is as long as in the heading */
60
- const SCENARIO_REFERENCE = /\bSC-[A-Z]{2,4}-\d{1,3}\b/g;
85
+ const SCENARIO_REFERENCE = /\bSC-[A-Z]{2,6}-\d{1,4}\b/g;
61
86
  /** The promise line of a scenario; its continuations go with an indent */
62
87
  const PROMISE = /^(?:Then|Тогда)\s+\S/;
63
88
  /**
@@ -93,7 +118,14 @@ const E2E_ROOTS = CONFIG.e2eRoots;
93
118
  // there is nothing else to bind to — an element has neither a method nor a field. Before, such a
94
119
  // binding did not match the template, and the audit said there was no binding at all; a session
95
120
  // went on rewriting a table of bindings that was right.
96
- const ANCHOR = /`([\w./-]+\.[A-Za-z]{2,10}):(#?\p{L}[\p{L}\p{N}_-]*|#?_[\w-]*|\d+|\.[\p{L}\p{N}_-]+)`/gu;
121
+ // The name of a file is written in two shapes: with an extension, and whole without a dot —
122
+ // that is how an image description, a proxy config and a build file are named. A statement
123
+ // carried out exactly there had nothing to address it by, and stood under the verdict «not
124
+ // checked» while the article was carried out: the form called such an address the absence of
125
+ // one. The second shape takes a word with a capital letter — that is what tells the name of
126
+ // such a file from an ordinary word of prose standing in backticks next to a colon.
127
+ const ANCHOR =
128
+ /`((?:[\w./-]+\.[A-Za-z]{2,10}|(?:[\w./-]*\/)?[A-Z][\w-]*)):(#?\p{L}[\p{L}\p{N}_-]*|#?_[\w-]*|\d+|\.[\p{L}\p{N}_-]+)`/gu;
97
129
  /**
98
130
  * An explicit verdict instead of an anchor: an article that has nowhere to be carried out in the
99
131
  * tree. That happens lawfully — the rule speaks of a service the tree does not keep, or of a human
@@ -240,6 +272,8 @@ function bulletsOf(lines) {
240
272
 
241
273
  export {
242
274
  SPECS_DIR,
275
+ codeOf,
276
+ isTestFile,
243
277
  CONSTITUTION_DIR,
244
278
  NOT_DOMAINS,
245
279
  TEST_ROOTS,
@@ -2,22 +2,41 @@
2
2
  * The spec contract against what the code declares: the procedure table against the decorators,
3
3
  * the refusal codes against the throw points.
4
4
  */
5
- import { BACKTICKED, PROCEDURE_ROOTS, bulletsOf, read, report, sectionOf, walk } from './spec-common.mjs';
5
+ import { BACKTICKED, PROCEDURE_ROOTS, bulletsOf, codeOf, read, report, sectionOf, walk } from './spec-common.mjs';
6
6
 
7
7
  // ── 2. The contract against the decorators ────────────────────────────────────
8
8
 
9
- /** The lib roots whose procedures the domain serves; declared in the spec header. */
9
+ /**
10
+ * The lib roots whose procedures the domain serves; declared in the spec header.
11
+ *
12
+ * An empty input has three states, not two, and merged into one they give a green where nothing
13
+ * was checked at all: there is no line — the domain says nothing about procedures; the line says
14
+ * «none» — a lawful answer; the line stands and names no root in backticks — the declaration was
15
+ * not parsed, and the whole contract went unchecked in silence. A header naming its procedures in
16
+ * words left three procedures with their rights and refusal codes unverified, and the run was
17
+ * green.
18
+ *
19
+ * The third state is answered by `UNPARSED`: the caller tells it from an empty list and names it
20
+ * as a discrepancy of the spec, not as the absence of a subject.
21
+ */
22
+ const UNPARSED = Symbol('procedure roots are declared and not parsed');
23
+
10
24
  function procedureRootsOf(text) {
11
25
  const line = text.split('\n').find((candidate) => PROCEDURE_ROOTS.test(candidate));
12
26
  if (!line) {
13
27
  return null;
14
28
  }
15
29
  const value = line.match(PROCEDURE_ROOTS)[1];
16
- if (/^\s*(?:none|нет)\s*$/i.test(value.replace(/[`.]/g, ''))) {
30
+ // The word is taken at the beginning of the line, and what follows it is an explanation: a
31
+ // domain that has no procedures says why, and the reason is worth more than the bare word.
32
+ // Demanding the word alone made fifteen lawful headers unparsed at once.
33
+ if (/^\s*(?:none|нет)(?![\p{L}\p{N}_])/iu.test(value.replace(/[`]/g, ''))) {
17
34
  return [];
18
35
  }
19
36
 
20
- return [...value.matchAll(BACKTICKED)].map(([, path]) => path);
37
+ const roots = [...value.matchAll(BACKTICKED)].map(([, path]) => path);
38
+
39
+ return roots.length === 0 ? UNPARSED : roots;
21
40
  }
22
41
 
23
42
  /** What the procedures themselves declare: the contract method and the right to it. */
@@ -25,7 +44,9 @@ function declaredProcedures(roots) {
25
44
  const found = new Map();
26
45
  for (const root of roots) {
27
46
  for (const file of walk(root, (name) => name.endsWith('.procedure.ts'))) {
28
- const text = read(file);
47
+ // Without the explanations: a sample call written next to the real mark used to substitute
48
+ // itself for it, and the right of a comment travelled into the audit.
49
+ const text = codeOf(read(file));
29
50
  const method = text.match(/\.method\.([A-Za-z_]\w*)/);
30
51
  if (!method) {
31
52
  continue;
@@ -85,6 +106,11 @@ function checkContract(file, text, roots) {
85
106
 
86
107
  return;
87
108
  }
109
+ if (roots === UNPARSED) {
110
+ report(file, 'the line `**Процедуры:**` names no root in backticks: the roots are written as paths, and the absence of procedures is said by the word «нет». As it stands, the table of «Контракт» is checked against nothing');
111
+
112
+ return;
113
+ }
88
114
  const declared = declaredProcedures(roots);
89
115
  const rows = contractRows(text);
90
116
  const described = new Set();
@@ -135,7 +161,7 @@ function checkRefusalCodes(file, text, roots) {
135
161
 
136
162
  return;
137
163
  }
138
- if (!roots || !roots.length) {
164
+ if (!roots || roots === UNPARSED || !roots.length) {
139
165
  return;
140
166
  }
141
167
  const sources = roots.flatMap((root) => walk(root, (name) => name.endsWith('.ts') && !name.endsWith('.spec.ts')));
@@ -158,4 +184,4 @@ function checkRefusalCodes(file, text, roots) {
158
184
  }
159
185
  }
160
186
 
161
- export { checkContract, checkRefusalCodes, procedureRootsOf };
187
+ export { UNPARSED, checkContract, checkRefusalCodes, procedureRootsOf };
@@ -18,6 +18,29 @@ import {
18
18
 
19
19
  // ── 4. Scenarios and the level of binding ──────────────────────────────────────
20
20
 
21
+
22
+ /**
23
+ * A line begun as a scenario heading. By it a heading the template did not take is told from
24
+ * ordinary prose: silence about such a line makes the audit's answer a statement about what it
25
+ * managed to parse, not about what lies in the tree. A subdomain named with a five-letter prefix
26
+ * passed green with thirteen of its scenarios not counted at all.
27
+ */
28
+ const SCENARIO_HEADING_START = /^###\s+SC-/;
29
+
30
+ /** The headings of a file that begin as a scenario and are not taken by the template. */
31
+ function unparsedHeadings(file) {
32
+ const found = [];
33
+ read(file)
34
+ .split('\n')
35
+ .forEach((line, index) => {
36
+ if (SCENARIO_HEADING_START.test(line) && !SCENARIO_HEADING.test(line)) {
37
+ found.push({ file, line: index + 1, text: line.trim() });
38
+ }
39
+ });
40
+
41
+ return found;
42
+ }
43
+
21
44
  function parseScenarios(file) {
22
45
  const lines = read(file).split('\n');
23
46
  const scenarios = [];
@@ -221,4 +244,4 @@ function collectReferences() {
221
244
  return references;
222
245
  }
223
246
 
224
- export { collectReferences, parseScenarios, promisesScreen };
247
+ export { collectReferences, parseScenarios, promisesScreen, unparsedHeadings };
@@ -38,6 +38,7 @@ import { cpSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync
38
38
  import { dirname, join, resolve } from 'node:path';
39
39
  import { fileURLToPath } from 'node:url';
40
40
 
41
+ import { planPathOf } from './board-epic-plan.mjs';
41
42
  import {
42
43
  BACKLOG_OPTION_ID,
43
44
  BOT,
@@ -221,10 +222,15 @@ function epicOfCard(epicNumber) {
221
222
  if (!labelled) {
222
223
  fail(`#${epicNumber} is not an epic: the card carries no label «${EPIC_LABEL}». A task hangs on an epic, and an epic is what the audit reads by that label`);
223
224
  }
224
- const named = String(card.body ?? '').match(/(?:^|[\s(`])([\w.-]+(?:\/[\w.-]+)+\.md)/);
225
- const plan = named ? named[1] : null;
225
+ // Which of the paths in the body is the plan is decided by the shared reading, the same one the
226
+ // queue audit calls. Read here by its own way — the first path in the body — the command wrote a
227
+ // law into every task of the epic as its plan, and the branch of the epic was then read from
228
+ // that law and came back empty. Both sides answered as usual, and the miss showed only by
229
+ // reading a created task.
230
+ const found = planPathOf(card.body, { makeupRequired: false });
231
+ const plan = found.path;
226
232
  if (plan === null) {
227
- fail(`the card of the epic #${epicNumber} names no path to its plan — there is nowhere to read what the epic holds, and the branch of the epic is named there too`);
233
+ fail(`the card of the epic #${epicNumber}: ${found.why}. The branch of the epic is named in the plan too`);
228
234
  }
229
235
  return { plan, branch: epicBranchOf(plan, epicNumber) };
230
236
  }
@@ -90,7 +90,11 @@ skill_for_default() {
90
90
  # the signs it judges by are declared in the rule's binding. Editing a sign in a
91
91
  # check, one opens the second place next to it — otherwise they drift apart
92
92
  # silently, and the check counts as a refusal what the rule allows.
93
- */check-specs.mjs) printf '%s\n' 'spec-driven' ;;
93
+ # The parsing of the spec audit lies not in the file with the `check-` prefix but
94
+ # in the helpers next to it: anchors, contract, scenarios, the shared part. They
95
+ # carry out the articles of the rule, and by name alone they matched no branch.
96
+ */check-specs.mjs | */spec-anchors.mjs | */spec-common.mjs | */spec-contract.mjs | */spec-scenarios.mjs | */specs-for.mjs)
97
+ printf '%s\n' 'spec-driven' ;;
94
98
  */check-doc-paths.mjs | */doc-paths-allowlist.json | */check-file-size.mjs)
95
99
  printf '%s\n' 'doc-style' ;;
96
100
  */check-styles.mjs | */styles-allowlist.json | */stylelint-rules/*)
@@ -110,13 +114,24 @@ skill_for_default() {
110
114
  # rule at hand. The rule lives with the delivery.
111
115
  */schema.prisma | */prisma/migrations/* | */prisma.config.ts)
112
116
  printf '%s\n' 'git-workflow' ;;
113
- # The pipeline and the image: the checks decide what runs before the merge at all,
114
- # and the image decides what arrives on production. Both were edited without a
115
- # single delivery rule.
117
+ # The pipeline carries two subjects at once: which checks run before the merge —
118
+ # that is the hand-over rule — and what reaches production after it, which is the
119
+ # rollout rule. Both names are printed, the rollout one first: the set before a push
120
+ # is written by the executor every day, while the rollout steps are read once and
121
+ # are the ones edited blindly.
116
122
  */.github/workflows/*.yml | */.gitlab-ci.yml | */azure-pipelines*.yml)
123
+ printf '%s\n' 'deploy-flow'
117
124
  printf '%s\n' 'git-workflow' ;;
125
+
126
+ # The image, the proxy config and the sample of the production environment are the
127
+ # rollout's own subject, and the branch used to hand them to the rule about tasks
128
+ # and branches: it says nothing about the server, the ports or the variables the
129
+ # image is raised with. What is written into these files is seen by nobody until the
130
+ # rollout, and by then it is production that answers.
118
131
  */Dockerfile | */*.Dockerfile | */docker-compose*.yml | */docker-compose*.yaml)
119
- printf '%s\n' 'git-workflow' ;;
132
+ printf '%s\n' 'deploy-flow' ;;
133
+ */Caddyfile | */nginx.conf | */*.nginx.conf | */nginx/*.conf | */.env.*.example)
134
+ printf '%s\n' 'deploy-flow' ;;
120
135
 
121
136
  # An end-to-end spec checks a running application, not a class: by file name it is
122
137
  # no different from an ordinary module, and without this branch it would go to the
@@ -28,6 +28,12 @@ rt_runner() {
28
28
  # than naming none.
29
29
  RT_STANDS="${RT_STANDS:-}"
30
30
 
31
+ # Who raises those stands. `owner` — the tree's own applications are up and any raise is refused;
32
+ # `session` — nobody raises them here but the session, and only a raise over a taken port is
33
+ # refused. The default is silent, and the guard reads silence as `owner`: a tree that sets nothing
34
+ # keeps the behaviour it has today.
35
+ RT_STANDS_RAISED_BY="${RT_STANDS_RAISED_BY:-}"
36
+
31
37
  # Where the tree's checks and the scenario set of its guards lie. A check the tree does not have is
32
38
  # not called by the push gate: the list is printed from what lies on disk.
33
39
  RT_CHECKS_DIR="${RT_CHECKS_DIR:-tools}"
@@ -3,21 +3,31 @@
3
3
  # Requires: hooks/deny-tail.sh
4
4
  # Guard against a second dev server. PreToolUse.
5
5
  #
6
- # The applications are already raised by the owner, and every check through the browser goes there.
7
- # A second instance takes an extra port, serves a different build and leads the investigation
8
- # astray: a difference between two servers reads as a defect of the edit. On top of that, a build
9
- # started in passing silently kills the server already raised.
6
+ # Who raises the stands is decided by the tree, not by the guard. The profile key
7
+ # RT_STANDS_RAISED_BY next to the stand list holds two values, and an unset key reads as `owner`:
8
+ # a tree that sets nothing keeps the behaviour it has today.
9
+ #
10
+ # owner — the applications are already raised by the owner, and every check through the browser
11
+ # goes there. Any raise is refused: a second instance takes an extra port, serves a
12
+ # different build and leads the investigation astray — a difference between two servers
13
+ # reads as a defect of the edit. On top of that, a build started in passing silently
14
+ # kills the server already raised.
15
+ # session — nobody raises the stands here but the session itself. There is left of the guard the
16
+ # one refusal that is right in such a tree: a raise over a port already taken. Under
17
+ # `owner` a tree where nobody raises anything gets the whole check through the browser
18
+ # refused, and the guard is dropped whole — together with the refusal that was right.
10
19
  #
11
20
  # Everything that RAISES a server is refused. Builds, tests, linters, requests to raised ports and
12
21
  # looking at listeners pass.
13
22
  #
14
23
  # Where exactly the applications are raised is known to the project profile:
15
24
  # .claude/rt-kit/project.sh, variable RT_STANDS. No profile — the refusal text stays general, the
16
- # guard itself works.
25
+ # guard itself works; under `session` there are no ports to judge by, and the call passes.
17
26
  #
18
27
  # FAIL-OPEN: an unrecognised command, no way to ask the ports, a raise the tree knows nothing of —
19
28
  # the call goes through. The price of a miss here is a second server on a busy port; the price of a
20
- # wrong refusal is a guard nobody keeps.
29
+ # wrong refusal is a guard nobody keeps. Under `session` the absence of the port
30
+ # listing tool reads the same way: there is nothing to learn a taken port by, and the call passes.
21
31
 
22
32
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
23
33
  # guard itself.
@@ -30,6 +40,49 @@ rt_hook_read
30
40
  input="$RT_HOOK_INPUT"
31
41
 
32
42
  tool="$(rt_hook_tool)"
43
+
44
+ # The tree profile: first the package default, and over it the project override, if there is one.
45
+ rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
46
+ for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
47
+ # shellcheck disable=SC1090
48
+ [ -f "$profile" ] && . "$profile" 2>/dev/null
49
+ done
50
+ stands="${RT_STANDS:-}"
51
+ raiser="${RT_STANDS_RAISED_BY:-owner}"
52
+
53
+ # shellcheck disable=SC1090
54
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
55
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
56
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
57
+
58
+ # A port of the stand list somebody is listening on. Only these are judged under `session`: a port
59
+ # the tree never named belongs to no stand of it, and a refusal over it would refuse the session's
60
+ # own work.
61
+ taken_stand_port() {
62
+ local port
63
+ command -v lsof >/dev/null 2>&1 || return 1
64
+ for port in $(printf '%s' "$stands" | grep -oE ':[0-9]{2,5}' | tr -d ':' | sort -u); do
65
+ lsof -nP -iTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1 && { printf '%s' "$port"; return 0; }
66
+ done
67
+ return 1
68
+ }
69
+
70
+ deny() {
71
+ local port
72
+ if [ "$raiser" = "session" ]; then
73
+ # Nobody raises the stands here but the session: a free port is its own business, and only
74
+ # a taken one is worth a refusal.
75
+ port="$(taken_stand_port)" || exit 0
76
+ echo "$1 On port ${port} somebody is already listening — a second instance answers with a build of its own and leads the investigation astray. Ask what it is: lsof -nP -iTCP:${port} -sTCP:LISTEN. $(rt_deny_tail)" >&2
77
+ exit 2
78
+ fi
79
+ if [ -n "$stands" ]; then
80
+ echo "$1 The applications are already raised by the owner: ${stands} — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
81
+ else
82
+ echo "$1 The applications are already raised by the owner — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
83
+ fi
84
+ exit 2
85
+ }
33
86
  case "$tool" in
34
87
  Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
35
88
  # A ready run configuration does not show the command line — only its name is visible. Hence
@@ -44,16 +97,14 @@ case "$tool" in
44
97
  file="$(printf '%s' "$input" | jq -r '.tool_input.filePath // empty' 2>/dev/null)"
45
98
  case "$file" in
46
99
  */package.json|package.json)
47
- echo "A launch of a script straight from the manifest: the guard sees only the file and the line, not the script itself, so it cannot tell raising a server from a build. The applications are already raised by the owner — if a build or a test is needed, run them by a command in the terminal." >&2
48
- exit 2 ;;
100
+ deny "A launch of a script straight from the manifest: the guard sees only the file and the line, not the script itself, so it cannot tell raising a server from a build. If a build or a test is needed, run them by a command in the terminal." ;;
49
101
  esac
50
102
  exit 0
51
103
  fi
52
104
  # The word "start" without a boundary also caught "restart", which raises no server.
53
105
  case "$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')" in
54
106
  *serve*|*dev*|start*|*\ start*|*:start*)
55
- echo "The configuration «${name}» looks like raising a development server, and the applications are already raised by the owner — check those. If the configuration does something else, run it by a command: by the name alone the guard does not see the content." >&2
56
- exit 2 ;;
107
+ deny "The configuration «${name}» looks like raising a development server. If the configuration does something else, run it by a command: by the name alone the guard does not see the content." ;;
57
108
  esac
58
109
  exit 0 ;;
59
110
  *) exit 0 ;;
@@ -81,28 +132,6 @@ case "$cmd" in
81
132
  printf '%s' "$cmd" | grep -qE '(^|[[:space:]])git[[:space:]]+daemon([[:space:]]|$)' || exit 0 ;;
82
133
  esac
83
134
 
84
- # The tree profile: first the package default, and over it the project override, if there is one.
85
- rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
86
- for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
87
- # shellcheck disable=SC1090
88
- [ -f "$profile" ] && . "$profile" 2>/dev/null
89
- done
90
- stands="${RT_STANDS:-}"
91
-
92
- # shellcheck disable=SC1090
93
- [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
94
- && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
95
- command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
96
-
97
- deny() {
98
- if [ -n "$stands" ]; then
99
- echo "$1 The applications are already raised by the owner: ${stands} — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
100
- else
101
- echo "$1 The applications are already raised by the owner — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
102
- fi
103
- exit 2
104
- }
105
-
106
135
  # The runners are listed outright. A group meaning "any word before the name" refused even a note
107
136
  # saying that the server is raised by the owner.
108
137
  RUNNER='((npx|pnpm|yarn|bun|npm)([[:space:]]+(exec|run|dlx))?[[:space:]]+)?'
@@ -159,8 +159,9 @@ verdict="$(jq -s -r '
159
159
  # echoing the same line or reading a file with it passes the guard, and the real verdict
160
160
  # does not.
161
161
  ["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
162
- | [.[] | select(.type == "assistant") | (.message.content // [])[]
163
- | select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null) | (.id // "")] as $muted
162
+ | ([.[] | select(.type == "assistant") | (.message.content // [])[]
163
+ | select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
164
+ | {key: (.id // ""), value: true}] | from_entries) as $muted
164
165
 
165
166
  | [ .[]
166
167
  # The assistant text is never a verdict: writing the needed line in a reply costs one
@@ -169,8 +170,7 @@ verdict="$(jq -s -r '
169
170
  elif .type == "user" then
170
171
  ([ ((.message.content // []) | if type == "array" then .[] else empty end
171
172
  | select(.type == "tool_result")
172
- | select(((.tool_use_id // "") | if . == "" then null else . end) as $id
173
- | $id == null or ($muted | index($id)) == null)
173
+ | select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
174
174
  | .content | textof),
175
175
  ((.message.content // "") | if type == "string" then . else "" end),
176
176
  # The call result field: the same record, another form. Discarded only when
@@ -179,7 +179,7 @@ verdict="$(jq -s -r '
179
179
  | if ($rec.toolUseResult // null) == null then ""
180
180
  elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
181
181
  | select(.type == "tool_result") | (.tool_use_id // "")]
182
- | map(. as $id | $muted | index($id)) | any(. != null)) then ""
182
+ | map($muted[.] // false) | any) then ""
183
183
  else ($rec.toolUseResult | textof) end)
184
184
  ] | join("\n"))
185
185
  # Host records — the role completion notice and the attachment: the host chooses their
@@ -208,8 +208,9 @@ if [ "$ready" = "1" ]; then
208
208
  # commands and the tool results, and the second exam in such a tree did not count: five
209
209
  # rounds with a full verdict let no edit through.
210
210
  ["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
211
- | [.[] | select(.type == "assistant") | (.message.content // [])[]
212
- | select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null) | (.id // "")] as $muted
211
+ | ([.[] | select(.type == "assistant") | (.message.content // [])[]
212
+ | select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
213
+ | {key: (.id // ""), value: true}] | from_entries) as $muted
213
214
 
214
215
  # A record gives two strings: the command — by it the moment of opening the PR is found —
215
216
  # and the verdict, checked by the same rules as in the wide selection. The order is the
@@ -222,15 +223,14 @@ if [ "$ready" = "1" ]; then
222
223
  elif .type == "user" then
223
224
  ([ ((.message.content // []) | if type == "array" then .[] else empty end
224
225
  | select(.type == "tool_result")
225
- | select(((.tool_use_id // "") | if . == "" then null else . end) as $id
226
- | $id == null or ($muted | index($id)) == null)
226
+ | select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
227
227
  | .content | textof),
228
228
  ((.message.content // "") | if type == "string" then . else "" end),
229
229
  (. as $rec
230
230
  | if ($rec.toolUseResult // null) == null then ""
231
231
  elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
232
232
  | select(.type == "tool_result") | (.tool_use_id // "")]
233
- | map(. as $id | $muted | index($id)) | any(. != null)) then ""
233
+ | map($muted[.] // false) | any) then ""
234
234
  else ($rec.toolUseResult | textof) end)
235
235
  ] | join("\n"))
236
236
  else tostring end)