@rt-tools/agent-kit 0.29.4 → 0.30.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 (52) hide show
  1. package/assets/checks/board-epics.github.mjs +17 -2
  2. package/assets/checks/board-folders.mjs +40 -1
  3. package/assets/checks/check-board.github.mjs +2 -1
  4. package/assets/checks/check-prose-style.mjs +6 -2
  5. package/assets/checks/spec-anchors.mjs +5 -1
  6. package/assets/defaults/gate-map.sh +4 -1
  7. package/assets/defaults/shell.sh +6 -2
  8. package/assets/hooks/claim-guard.sh +42 -13
  9. package/assets/hooks/epic-stop-guard.sh +26 -1
  10. package/assets/hooks/git-guard-delivery-epic.sh +11 -1
  11. package/assets/hooks/git-guard-delivery-tree.sh +29 -0
  12. package/assets/hooks/git-guard-delivery.sh +6 -6
  13. package/assets/hooks/git-guard-push-tests.sh +10 -1
  14. package/assets/hooks/grill-gate-bypass.sh +61 -0
  15. package/assets/hooks/grill-gate.sh +143 -3
  16. package/assets/hooks/proposal-guard.sh +3 -0
  17. package/assets/hooks/turn-exit-guard.sh +3 -3
  18. package/assets/hooks/turn-exit-verdict.sh +18 -1
  19. package/assets/patterns/git-workflow-commit.azure.md +4 -0
  20. package/assets/patterns/git-workflow-commit.github.md +15 -0
  21. package/assets/patterns/git-workflow-commit.gitlab.md +4 -0
  22. package/assets/patterns/git-workflow-pr-body.github.md +4 -0
  23. package/assets/patterns/queue-audit-read.github.md +47 -0
  24. package/assets/patterns/spec-driven-rule.md +8 -2
  25. package/assets/patterns/task-flow-close.md +11 -9
  26. package/assets/patterns/task-flow-start.md +21 -22
  27. package/assets/pitfalls/doc-style.md +8 -0
  28. package/assets/pitfalls/turn-conduct.md +14 -0
  29. package/assets/rules/component-structure.md +4 -0
  30. package/assets/rules/doc-style.md +20 -3
  31. package/assets/rules/git-workflow.azure.md +4 -0
  32. package/assets/rules/git-workflow.github.md +7 -24
  33. package/assets/rules/git-workflow.gitlab.md +4 -0
  34. package/assets/rules/queue-audit.github.md +77 -0
  35. package/assets/rules/status-report.md +6 -0
  36. package/assets/rules/task-flow.md +18 -21
  37. package/assets/rules/testing.md +4 -0
  38. package/assets/rules/turn-conduct.md +22 -20
  39. package/lib/commands.d.ts.map +1 -1
  40. package/lib/commands.js +12 -2
  41. package/lib/commands.js.map +1 -1
  42. package/lib/hooks-map.d.ts +14 -0
  43. package/lib/hooks-map.d.ts.map +1 -1
  44. package/lib/hooks-map.js +55 -8
  45. package/lib/hooks-map.js.map +1 -1
  46. package/lib/sync.d.ts +9 -0
  47. package/lib/sync.d.ts.map +1 -1
  48. package/lib/sync.js +6 -1
  49. package/lib/sync.js.map +1 -1
  50. package/package.json +1 -1
  51. package/rt-tools-agent-kit-0.30.0.tgz +0 -0
  52. package/rt-tools-agent-kit-0.29.4.tgz +0 -0
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { declaredEpicOf } from './board-epic-link.mjs';
6
6
  import { planPathOf, planRows, planTaskCells } from './board-epic-plan.mjs';
7
- import { ghJson, numberFromTitle, OfflineError, OWNER, REPO, TASK_KEY } from './board.mjs';
7
+ import { ghJson, numberFromBranch, numberFromTitle, OfflineError, OWNER, REPO, TASK_KEY } from './board.mjs';
8
8
  import { CONFIG } from './rt-kit-checks.config.mjs';
9
9
 
10
10
  /**
@@ -66,7 +66,16 @@ export function checkEpicLinks(open, report) {
66
66
 
67
67
  const planPath = found.path;
68
68
  const mentions = planTaskCells(found.text).join('\n').matchAll(new RegExp(`(?:#|${TASK_KEY}-)(\\d+)`, 'g'));
69
- const numbers = new Set([...mentions].map((match) => Number(match[1])));
69
+ const listed = [...mentions].map((match) => Number(match[1]));
70
+ const numbers = new Set(listed);
71
+ // A merge that took both sides of a conflict doubles rows of the makeup, and the set above
72
+ // does not see it.
73
+ for (const number of numbers) {
74
+ const times = listed.filter((one) => one === number).length;
75
+ if (times > 1) {
76
+ report(`#${epic.number}: the plan names the task #${number} in ${times} rows of the makeup — a merge took both sides; one row stays`);
77
+ }
78
+ }
70
79
  for (const number of numbers) {
71
80
  if (number === epic.number || !byNumber.has(number)) {
72
81
  continue;
@@ -236,6 +245,12 @@ export function checkEpicPullBase(open, pulls, report) {
236
245
  if (base.startsWith(`${TASK_KEY}-${epic}-`)) {
237
246
  continue;
238
247
  }
248
+ // A chain base: the branch of a task below in the same epic. The rule puts a chain PR on
249
+ // the previous branch, and that branch carries the epic branch.
250
+ const baseTask = numberFromBranch(base);
251
+ if (baseTask !== null && epicOf.get(baseTask) === epic) {
252
+ continue;
253
+ }
239
254
  report(
240
255
  `PR #${pull.number}: the task #${number} belongs to the epic #${epic}, and the base of the request is «${base}». A request past the epic takes the task out of it: the epic is handed in without it`
241
256
  );
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { execFileSync } from 'node:child_process';
11
11
 
12
- import { TASK_KEY } from './board.mjs';
12
+ import { TASK_KEY, numberFromTaskDir, taskDirs } from './board.mjs';
13
13
  import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
14
14
 
15
15
  /**
@@ -109,3 +109,42 @@ export function checkBranchFolders(report, mainBranch) {
109
109
  );
110
110
  }
111
111
  }
112
+
113
+ /**
114
+ * Task folders with a number that hold not one file from the index.
115
+ *
116
+ * Only a draft without a number may live outside history. The task creating command lays a numbered
117
+ * folder at once, and a task created "for later" leaves it on disk for good: the folder passes edits
118
+ * without a refusal and follows its owner across every switch of branches. Ten such folders were
119
+ * found by the owner in `git status`, not by a check.
120
+ *
121
+ * The index is asked, not the history: a folder added and not committed yet travels with the next
122
+ * commit, and a line about it would ask for what is already done.
123
+ */
124
+ export function checkUntrackedFolders(report) {
125
+ let tracked;
126
+ try {
127
+ tracked = execFileSync('git', ['ls-files', '-z', '--', CONFIG.tasksDir], {
128
+ cwd: ROOT,
129
+ encoding: 'utf8',
130
+ stdio: ['ignore', 'pipe', 'ignore'],
131
+ }).split('\0');
132
+ } catch {
133
+ // Not a repository: there is no index to compare with.
134
+ return;
135
+ }
136
+
137
+ for (const name of taskDirs()) {
138
+ if (numberFromTaskDir(name.split('/').pop()) === null) {
139
+ continue;
140
+ }
141
+ const prefix = `${CONFIG.tasksDir}/${name}/`;
142
+ if (tracked.some((file) => file.startsWith(prefix))) {
143
+ continue;
144
+ }
145
+ report(
146
+ `${prefix}: the task folder lies outside the index — take the branch of the task and commit the folder, ` +
147
+ `or delete it, if the task is not taken now`
148
+ );
149
+ }
150
+ }
@@ -48,7 +48,7 @@ import {
48
48
  numberFromTitle,
49
49
  taskDirs,
50
50
  } from './board.mjs';
51
- import { checkBranchFolders } from './board-folders.mjs';
51
+ import { checkBranchFolders, checkUntrackedFolders } from './board-folders.mjs';
52
52
  import { checkConflicting, checkHeadRun } from './board-pull-state.mjs';
53
53
  import { checkLongWork } from './board-long-work.mjs';
54
54
  import { HAS_PIPELINE, deployLag, lastDeploy, lastMainRun, pipelineText, pipelineWakesOnPush } from './board-runs.mjs';
@@ -167,6 +167,7 @@ let checked = { issues: 0, pulls: 0, cargo: 0, offBase: 0 };
167
167
  // Drafts are judged by the disk and so are checked always: no connection is needed for that.
168
168
  checkDrafts();
169
169
  checkBranchFolders(report, MAIN_BRANCH);
170
+ checkUntrackedFolders(report);
170
171
 
171
172
  let offline = false;
172
173
  try {
@@ -204,10 +204,14 @@ function findingsIn(line) {
204
204
  return found;
205
205
  }
206
206
 
207
- /** A sentence that is too long: the reader loses the beginning before the author reaches the end. */
207
+ /**
208
+ * A sentence that is too long: the reader loses the beginning before the author reaches the end.
209
+ * A full stop closed by emphasis — `.**` at the end of an article title — ends a sentence too:
210
+ * otherwise the title and the first sentence after it are counted as one.
211
+ */
208
212
  function longSentences(line) {
209
213
  return line
210
- .split(/(?<=[.!?])\s+/)
214
+ .split(/(?<=[.!?][*_]*)\s+/)
211
215
  .filter((sentence) => sentence.trim().split(/\s+/).length > WORDS_LIMIT)
212
216
  .map((sentence) => [`${sentence.trim().split(/\s+/).length} words in a sentence`, `split it: the limit is ${WORDS_LIMIT}`]);
213
217
  }
@@ -272,8 +272,12 @@ function publishedFiles() {
272
272
  const file = queue.pop();
273
273
  const dir = file.slice(0, file.lastIndexOf('/'));
274
274
  for (const [, relative] of read(file).matchAll(/(?:export|import)[^'"]*from\s+['"](\.[^'"]*)['"]/g)) {
275
+ // An ES module package writes the import with the `.js` ending of the built file; the
276
+ // source behind it is the `.ts` of the same name. Read literally, the published file
277
+ // stayed unseen, and every function the package hands out read as called by tests alone.
278
+ const source = relative.replace(/^\.\//, '').replace(/\.js$/, '');
275
279
  for (const suffix of ['.ts', '/index.ts', '']) {
276
- const path = `${dir}/${relative.replace(/^\.\//, '')}${suffix}`.replace(/\/\.\//g, '/');
280
+ const path = `${dir}/${source}${suffix}`.replace(/\/\.\//g, '/');
277
281
  if (exists(path) && !published.has(path)) {
278
282
  published.add(path);
279
283
  if (path.endsWith('/index.ts')) {
@@ -101,8 +101,11 @@ skill_for_default() {
101
101
  printf '%s\n' 'styling-bem' ;;
102
102
  */check-lib-layers.mjs | */lib-layers-allowlist.json) printf '%s\n' 'lib-layers' ;;
103
103
  */check-reuse.mjs | */reuse-allowlist.json) printf '%s\n' 'reuse-first' ;;
104
- */check-board.mjs | */board.mjs | */task-new.mjs | */check-schema-drift.mjs)
104
+ # The queue audit has a rule of its own, laid out on GitHub only; the folders
105
+ # module is laid out on every host and stays with the rule about tasks.
106
+ */board-folders.mjs | */task-new.mjs | */check-schema-drift.mjs)
105
107
  printf '%s\n' 'git-workflow' ;;
108
+ */check-board.mjs | */board.mjs | */board-*.mjs) printf '%s\n' 'queue-audit' ;;
106
109
  # A tree's own code linter rule is written by the same conventions as the code under
107
110
  # it.
108
111
  */eslint-rules/*) printf '%s\n' 'typescript-conventions' ;;
@@ -42,6 +42,10 @@
42
42
  # and only the target tells them apart. Behind a real sign stands a path, not a word in words. The
43
43
  # price is named directly: a path typed not in Latin letters no longer counts as a write — there is
44
44
  # not one such in the tree, and should they appear, the sign will have to be widened.
45
+ #
46
+ # The in-place flag of a stream editor is matched as a flag word, not as a substring. A path such
47
+ # as `order-item-list.html` carries `-i` inside it, and a read-only `sed -n …p` over such a path
48
+ # was refused as an in-place edit, together with any command that merely quoted the path.
45
49
  rt_shell_writes_default() {
46
50
  cleaned="$(printf '%s' "$1" \
47
51
  | sed -E 's#(&|[0-9]*)>>?[[:space:]]*/dev/(null|stderr)##g; s#[0-9]*>&[0-9-]##g; s#[-=]+>##g')"
@@ -62,7 +66,7 @@ rt_shell_writes_default() {
62
66
 
63
67
  printf '%s' "$cleaned" \
64
68
  | grep -Eq \
65
- '>>?[[:space:]]*[A-Za-z0-9_./~$"'"'"'-]|\btee\b|\bsed\b[^|]*-i|\bperl\b[^|]*-i|\bdd\b[^|]*of=|\bcp\b|\bmv\b|\brm\b|\btouch\b|\btruncate\b|\binstall\b|\bpatch\b|\bgit[[:space:]]+(checkout|restore|apply|stash)\b'
69
+ '>>?[[:space:]]*[A-Za-z0-9_./~$"'"'"'-]|\btee\b|\bsed\b[^|]*[[:space:]]-[a-zA-Z]*i\b|\bsed\b[^|]*--in-place|\bperl\b[^|]*[[:space:]]-[a-zA-Z]*i\b|\bdd\b[^|]*of=|\bcp\b|\bmv\b|\brm\b|\btouch\b|\btruncate\b|\binstall\b|\bpatch\b|\bgit[[:space:]]+(checkout|restore|apply|stash)\b'
66
70
  }
67
71
 
68
72
  # The paths named by a shell command. Prints one per line; the caller judges them.
@@ -149,7 +153,7 @@ rt_shell_paths_default() {
149
153
  #
150
154
  # The other kinds of writing are parsed as before: for an in-place edit, a copy, a move
151
155
  # and an interpreter the path stands in the command itself and not in one place.
152
- if ! printf '%s' "$piece" | grep -Eq '\bsed\b[^|]*-i|\bperl\b[^|]*-i|\bpython3?\b|\bnode\b|\bruby\b|\bdd\b[^|]*of=|\bcp\b|\bmv\b|\brm\b|\btouch\b|\btruncate\b|\binstall\b|\bpatch\b|\bgit[[:space:]]+(checkout|restore|apply|stash)\b'; then
156
+ if ! printf '%s' "$piece" | grep -Eq '\bsed\b[^|]*[[:space:]]-[a-zA-Z]*i\b|\bsed\b[^|]*--in-place|\bperl\b[^|]*[[:space:]]-[a-zA-Z]*i\b|\bpython3?\b|\bnode\b|\bruby\b|\bdd\b[^|]*of=|\bcp\b|\bmv\b|\brm\b|\btouch\b|\btruncate\b|\binstall\b|\bpatch\b|\bgit[[:space:]]+(checkout|restore|apply|stash)\b'; then
153
157
  printf '%s' "$piece" \
154
158
  | grep -oE '(>>?[[:space:]]*|\btee\b([[:space:]]+-a)?[[:space:]]+)[A-Za-z0-9_@.~/-]+' \
155
159
  | sed -E 's/^(>>?|tee([[:space:]]+-a)?)[[:space:]]*//' \
@@ -118,40 +118,69 @@ judged="$(printf '%s\n' "$said" \
118
118
  !code && !/^[[:space:]]*>/' \
119
119
  | sed -E 's/`[^`]*`/ /g; s/«[^»]*»/ /g; s/"[^"]*"/ /g' \
120
120
  | sed -E 's/([.!?])[[:space:]]+/\1\'$'\n''/g' \
121
- | grep -viE '(^|[[:space:]])(бы|если|разве|неужели|ли)([[:space:]]|[,.]|$)' 2>/dev/null)"
121
+ | grep -viE '(^|[[:space:]])(бы|если|разве|неужели|ли)([[:space:]]|[,.]|$)' 2>/dev/null \
122
+ | sed -E 's/^/ /; s/([[:space:]])не[[:space:]]+/\1не~/g')"
122
123
  [ -z "$judged" ] && exit 0
123
124
  said="$judged"
125
+ # Every sentence starts with a space, and a negation is glued to the word after it by `~`. The
126
+ # space is the word boundary: an anchor inside a group and a class with a negation do not hold one
127
+ # — `^` in a group under `grep -o` is true at any position where PATH leads to ugrep, and a class
128
+ # like `[^а-яё]` matches half of a two-byte letter. Without the boundary «слит» was found inside
129
+ # «числит», and a sentence about counting was read as merged work.
124
130
 
125
131
  # The claims map: what is said about the tree | what shows it | what to name in the refusal.
126
132
  #
127
133
  # The word is taken in the form it is said to the owner in. The future tense does not go here:
128
134
  # "I will check" and "I will start" are not claims — they are a promise, and there is nothing in
129
135
  # them to lie with.
136
+ #
137
+ # `@` stands before a claim word: it reads as the word boundary for the claim and as «не» before
138
+ # the word for its negation. A done action is named by a past form: «удаляет» and «удалить» describe
139
+ # what a command does, not what was done.
130
140
  claims=(
131
- 'проверено|прогнал[а]?|тесты (зелёные|прошли)|линт(ер)? (зелёный|прошёл|чистый)|сборка (зелёная|прошла)|набор зелёный|проверки зелёные|спеки зелёные|всё зелен(о|ое)§nx (test|lint|build|run|affected|run-many)|npm (run|test)|pnpm (run|exec|test)|jest|vitest|playwright|check:|run\.sh§команду набора — прогон тестов, линта или сборки'
132
- 'запушен[аоы]?|запушил[а]?|пуш прошёл|ветка уехала§git push§`git push`'
133
- '(PR|правка|ветка|работа)[^.]{0,20}(влит|слит|смержен)|влит[оа] в|слит[оа] в§git merge|gh pr merge§`git merge` или `gh pr merge`'
134
- '(ветки|ветка|файлы|файл|папка|каталог)[^.]{0,40}(снят|удал|почищ|вычищ)|снят[оыа] с§git branch|git push .*--delete|git rm|gh api|rm §команду удаления — `git branch -d`, `git push --delete` или `git rm`'
135
- 'прогон (зелёный|прошёл|кончился)|конвейер зелёный|проверки на PR зелёные§gh run§`gh run list` или `gh run view`'
136
- '(работа|правка|задача) готова|можно вливать|PR открыт|черновик снят§gh pr §`gh pr create`, `gh pr view` или `gh pr ready`'
141
+ '@проверено|@прогнал[а]?|@тесты (зелёные|прошли)|@линт(ер)? (зелёный|прошёл|чистый)|@сборка (зелёная|прошла)|@набор зелёный|@проверки зелёные|@спеки зелёные|@всё зелен(о|ое)§nx (test|lint|build|run|affected|run-many)|npm (run|test)|pnpm (run|exec|test)|jest|vitest|playwright|check:|run\.sh§команду набора — прогон тестов, линта или сборки'
142
+ # A gate called fixed is a claim about a run: the fix is shown by the gate passing, and the
143
+ # phrase was once said with not one run behind it.
144
+ '@проверк[аи] перед (push|пушем|отправкой)[^.]{0,30}(починен|исправлен)§git push|check:all|pnpm (run|exec)§прогон набора перед push — `git push` или `pnpm run check:all`'
145
+ '@запушен[аоы]?|@запушил[а]?|@пуш прошёл|@ветка уехала§git push§`git push`'
146
+ '(PR|правка|ветка|работа)[^.]{0,20}@(влит|слит|смержен)|@влит[оа] в|@слит[оа] в§git merge|gh pr merge§`git merge` или `gh pr merge`'
147
+ '(ветки|ветка|файлы|файл|папка|каталог)[^.]{0,40}@(снят|удал[её]н|удалил|почищен|почистил|вычищен|вычистил)|@снят[оыа] с§git branch|git push .*--delete|git rm|gh api|rm §команду удаления — `git branch -d`, `git push --delete` или `git rm`'
148
+ '@прогон (зелёный|прошёл|кончился)|@конвейер зелёный|@проверки на PR зелёные§gh run§`gh run list` или `gh run view`'
149
+ '@(работа|правка|задача) готова|@можно вливать|@PR открыт|@черновик снят§gh pr §`gh pr create`, `gh pr view` или `gh pr ready`'
137
150
  # Waiting for someone else's step is a claim about the state too, and there is something in it
138
151
  # to lie with: a run is green for an hour, and sometimes never starts at all. Said without a
139
152
  # command, it leaves finished work a draft, and the owner learns of it last — that is exactly
140
153
  # how it went twice in one day.
141
- 'жд[уёя][^.]{0,20}прогон|дожида[ею][^.]{0,20}прогон|прогон[^.]{0,20}(ещё идёт|не встал|не кончился|не дошёл)|черновик[^.]{0,30}(не снимаю|сниму|снимется)§gh run|gh pr checks|check-runs|check:board|board\.mjs§команду о прогоне — `gh run list`, `gh pr checks` или сверку очереди работ'
142
- 'задача заведена|задача (в|переведена в) колонк|колонка переведена§gh issue|gh api|task:new|task:move|board\.mjs§команду очереди работ — заведение задачи или перевод колонки'
143
- '(в дереве|в репозитории|здесь|такого файла|такой команды)[^.]{0,30}(нет|не бывает)|не заводили|нигде не встречается§grep|rg |ls |find |git ls-files|git grep|git log|cat §команду поиска — `grep`, `git ls-files` или обход каталога'
154
+ '@жд[уёя][^.]{0,20}прогон|@дожида[ею][^.]{0,20}прогон|@прогон[^.]{0,20}(ещё идёт|не встал|не кончился|не дошёл)|@черновик[^.]{0,30}(не снимаю|сниму|снимется)§gh run|gh pr checks|check-runs|check:board|board\.mjs§команду о прогоне — `gh run list`, `gh pr checks` или сверку очереди работ'
155
+ '@задача заведена|@задача (в|переведена в) колонк|@колонка переведена§gh issue|gh api|task:new|task:move|board\.mjs§команду очереди работ — заведение задачи или перевод колонки'
156
+ '(в дереве|в репозитории|здесь|такого файла|такой команды)[^.]{0,30}(нет|не бывает)|@не заводили|@нигде не встречается§grep|rg |ls |find |git ls-files|git grep|git log|cat §команду поиска — `grep`, `git ls-files` или обход каталога'
144
157
  )
145
158
 
159
+ # A negated claim is a statement about the tree too, but the action command cannot show it: «not
160
+ # pushed» is shown by a read of the branch state, not by a push.
161
+ read_proof='git (status|log|ls-remote|branch|show|rev-parse|fetch|diff)|gh (pr|run|api|issue)|ls |grep|board\.mjs'
162
+
146
163
  for row in "${claims[@]}"; do
147
164
  words="${row%%§*}"
148
165
  rest="${row#*§}"
149
166
  proof="${rest%%§*}"
150
167
  name="${rest#*§}"
151
168
 
152
- found="$(printf '%s' "$said" | grep -oiE "$words" 2>/dev/null | head -1)"
153
- [ -z "$found" ] && continue
154
- printf '%s' "$ran" | grep -qiE "$proof" 2>/dev/null && continue
169
+ # The text glues «не» to the next word, so the row does the same with its own «не».
170
+ words="${words//не /не~}"
171
+ claim_re="${words//@/ }"
172
+ negated_re="${words//@/ не~}"
173
+
174
+ found="$(printf '%s' "$said" | grep -oiE "$claim_re" 2>/dev/null | head -1)"
175
+ if [ -n "$found" ]; then
176
+ printf '%s' "$ran" | grep -qiE "$proof" 2>/dev/null && continue
177
+ else
178
+ found="$(printf '%s' "$said" | grep -oiE "$negated_re" 2>/dev/null | head -1)"
179
+ [ -z "$found" ] && continue
180
+ printf '%s' "$ran" | grep -qiE "$proof|$read_proof" 2>/dev/null && continue
181
+ name="команду чтения — \`git status\`, \`git log\` или \`git ls-remote\`"
182
+ fi
183
+ found="$(printf '%s' "$found" | sed -E 's/~/ /g; s/^[[:space:]]+//')"
155
184
 
156
185
  reason="BLOCKED by claim-guard: the owner was told «${found}» — that is a statement about the state of the tree, and there was no command showing it in this turn.
157
186
 
@@ -85,13 +85,38 @@ fi
85
85
  command -v rt_epic_over >/dev/null 2>&1 || exit 0
86
86
  rt_epic_over || exit 0
87
87
 
88
+ # The word of the owner about this very work releases the call: their message or their answer to a
89
+ # menu that names the number the call takes. The line in the call was the only form before, and an
90
+ # owner who forbade writing it left the executor one way out — stopping the work they had just set.
91
+ # The number is read from the call; the words of the executor do not count.
92
+ taken="$(printf '%s' "$cmd" | sed -nE 's/.*(checkout|switch)[[:space:]]+(-[A-Za-z]+[[:space:]]+)*-(b|c)[[:space:]]+[A-Za-z]+-([0-9]+)-.*/\4/p; s/.*(task:move|board\.mjs[[:space:]]+move)[^0-9|;&]*([0-9]+).*/\2/p; s/.*--epic-of[[:space:]=]+([0-9]+).*/\1/p' | head -1)"
93
+ transcript="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null)"
94
+ if [ -n "$taken" ] && [ -n "$transcript" ] && [ -f "$transcript" ]; then
95
+ named="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r --arg n "$taken" '
96
+ [.[] | select(.type == "user")
97
+ | select(((.isMeta // false) or (.isCompactSummary // false)) | not)
98
+ | (.message.content // "")
99
+ | if type == "string" then .
100
+ elif type == "array" then (map(
101
+ if .type == "text" then (.text // "")
102
+ elif .type == "tool_result" then ((.content
103
+ | if type == "string" then . elif type == "array"
104
+ then (map(if type == "object" then (.text // "") else "" end) | join(" ")) else "" end)
105
+ | if test("^The user answered:") then . else "" end)
106
+ else "" end) | join("\n"))
107
+ else "" end]
108
+ | map(test("(^|[^0-9])" + $n + "([^0-9]|$)")) | any
109
+ ' 2>/dev/null)"
110
+ [ "$named" = "true" ] && exit 0
111
+ fi
112
+
88
113
  root="$(git rev-parse --show-toplevel 2>/dev/null)"
89
114
  checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
90
115
  if [ -z "$checks" ] || [ "$checks" = null ]; then
91
116
  checks=tools
92
117
  fi
93
118
 
94
- reason="Refused: the epic is over — every task of it is merged or handed over by a request, and this call takes new work. The end of an epic is a stop: print the table by «npm run epic:table» (or «node $checks/epic-table.mjs»), tell the owner what was done on each task and what confirms it, and say outright that the session waits for their orders. New work is taken by their word, not by the count of what is left."
119
+ reason="Refused: the epic is over — every task of it is merged or handed over by a request, and this call takes new work. The end of an epic is a stop: print the table by «npm run epic:table» (or «node $checks/epic-table.mjs»), tell the owner what was done on each task and what confirms it, and say outright that the session waits for their orders. New work is taken by their word, not by the count of what is left: their message or their answer to a menu that names the number of this work releases the call."
95
120
 
96
121
  # shellcheck disable=SC1090
97
122
  [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
@@ -125,7 +125,17 @@ rt_epic_pull_base() {
125
125
  ' 2>/dev/null)"
126
126
  fi
127
127
 
128
- if [ "$_base" != "$_epic_branch" ]; then
128
+ # A chain base: the branch of the task below, standing on the epic branch. It is lawful
129
+ # while its history carries the epic branch — the rule puts a chain PR on the previous branch.
130
+ _chain=''
131
+ if [ -n "$_base" ] && [ "$_base" != "$_epic_branch" ] && [ "$_base" != "${main_branch:-main}" ] \
132
+ && git rev-parse --verify --quiet "origin/${_epic_branch}" >/dev/null 2>&1 \
133
+ && git rev-parse --verify --quiet "origin/${_base}" >/dev/null 2>&1 \
134
+ && git merge-base --is-ancestor "origin/${_epic_branch}" "origin/${_base}" 2>/dev/null; then
135
+ _chain=1
136
+ fi
137
+
138
+ if [ "$_base" != "$_epic_branch" ] && [ -z "$_chain" ]; then
129
139
  fault "the request of a task of the epic #${_epic} goes into the branch of the epic «${_epic_branch}», and the base here is ${_base:-the default branch of the repository}. A request into the main branch takes the task past its epic: the epic is handed in without it. Name the base: --base ${_epic_branch}."
130
140
  return 0
131
141
  fi
@@ -30,6 +30,16 @@ rt_delivery_exec_dir() {
30
30
  named="$(printf '%s' "$cmd" | sed -nE 's/.*(^|[;&|[:space:]])cd[[:space:]]+([^[:space:];&|]+).*/\2/p' | head -1)"
31
31
  named="${named%\'}"; named="${named#\'}"
32
32
  named="${named%\"}"; named="${named#\"}"
33
+ # The shell expands the home directory before `cd` runs, and the guard reads the command text
34
+ # unexpanded: a path with a tilde named no directory, and the command counted as running in the
35
+ # tree of the session.
36
+ case "$named" in
37
+ '~') named="$HOME" ;;
38
+ '~/'*) named="$HOME/${named#\~/}" ;;
39
+ '$HOME'|'${HOME}') named="$HOME" ;;
40
+ '$HOME/'*) named="$HOME/${named#\$HOME/}" ;;
41
+ '${HOME}/'*) named="$HOME/${named#\$\{HOME\}/}" ;;
42
+ esac
33
43
  [ -z "$named" ] && return 0
34
44
  [ -d "$named" ] || return 0
35
45
  git -C "$named" rev-parse --show-toplevel 2>/dev/null
@@ -95,3 +105,22 @@ rt_delivery_current_branch() {
95
105
  other="$(rt_delivery_foreign_root)"
96
106
  git -C "${other:-.}" branch --show-current 2>/dev/null
97
107
  }
108
+
109
+ # The form of the task number in a request title, by the profile of the tree of execution. The key of
110
+ # a neighbouring tree is its own: judged by the session's form, a lawful title of that tree was
111
+ # refused as having no number at all.
112
+ rt_delivery_title_re() {
113
+ other="$(rt_delivery_foreign_root)"
114
+ if [ -z "$other" ] || [ ! -f "$other/.claude/rt-kit/project.sh" ]; then
115
+ printf '%s' "$1"
116
+ return 0
117
+ fi
118
+ (
119
+ cd "$other" 2>/dev/null || { printf '%s' "$1"; exit 0; }
120
+ unset RT_TASK_TITLE_RE
121
+ for profile in "$other/.claude/rt-kit/defaults/project.sh" "$other/.claude/rt-kit/project.sh"; do
122
+ [ -f "$profile" ] && . "$profile" >/dev/null 2>&1
123
+ done
124
+ printf '%s' "${RT_TASK_TITLE_RE:-^\[[A-Za-z]+-[0-9]+\][[:space:]]+[^[:space:]]}"
125
+ )
126
+ }
@@ -33,15 +33,12 @@
33
33
  # RT_TASK_BOT — the account put as the assignee; the PR is opened by it as well;
34
34
  # RT_PULL_TOKEN_VAR — the variable through which its token is substituted into the call;
35
35
  # RT_PULL_TOKEN_HINT — the ready-made substitution of that token, whole;
36
- # RT_COMMIT_EMAIL — the address a machine commit is signed with; by its left part the commit
37
- # is recognised as well.
38
- # The refusal names both what is wrong and what fixes it: a refusal without an action is bypassed,
39
- # not carried out.
36
+ # RT_COMMIT_EMAIL — the address of a machine commit; its left part recognises the commit too.
37
+ # A refusal names what is wrong and what fixes it: one without an action is bypassed, not obeyed.
40
38
  #
41
39
  # FAIL-OPEN: not a repository, no parser, broken input, no profile — let through.
42
40
 
43
- # Its own name in the observations: the refusal is written by the shared deny tail, not by the
44
- # guard itself.
41
+ # Its own name in the observations: the refusal is written by the shared deny tail, not here.
45
42
  RT_GUARD_NAME=git-guard-delivery
46
43
 
47
44
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
@@ -365,6 +362,9 @@ epic_pull="$(printf '%s' "$state" | jq -r '.epic // empty' 2>/dev/null)"
365
362
  # folders of all its tasks are taken apart.
366
363
  command -v rt_epic_own_pull >/dev/null 2>&1 && rt_epic_own_pull "$state"
367
364
 
365
+ # A request in another repository is judged by the title form of that repository.
366
+ command -v rt_delivery_title_re >/dev/null 2>&1 && title_re="$(rt_delivery_title_re "$title_re")"
367
+
368
368
  title=''
369
369
  if command -v perl >/dev/null 2>&1; then
370
370
  title="$(printf '%s' "$cmd" | perl -0ne '
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
3
+ # rt-hook-timeout: 1800
3
4
  # Requires: hooks/profile-check.sh, hooks/deny-tail.sh
4
5
  # The guard of the checks before a push. PreToolUse on the push call.
5
6
  #
@@ -51,7 +52,8 @@ cmd="$(rt_hook_cmd)"
51
52
  # request header are put between them by `-c` keys, and that is exactly the form pushed with here.
52
53
  # While the sign was a substring, the whole gate set was not run at all on such a push, and the
53
54
  # silence of the guard read as "green".
54
- printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git([[:space:]]|\$)" || exit 0
55
+ # A loop body starts after `do`, `then` or `else`: a push there is a push too.
56
+ printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git([[:space:]]|\$)|(^|[;&|[:space:]])(do|then|else)[[:space:]]+git[[:space:]]" || exit 0
55
57
 
56
58
  # A stashed edit is never a push: `git stash push` puts the edit into the stash of this same
57
59
  # machine and sends nothing outside. The word `push` in it stands separate, and without this line
@@ -100,6 +102,13 @@ if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git[[:space:]]+(checkout|switch
100
102
  push_deny "BLOCKED: switching the branch and pushing by one command. The gate set runs on the tree that lies there at the minute the command is parsed — that is, on the FORMER branch, not the one that leaves for the hosting. A green set then reads as a check of what left, though it checked something else. Split the calls: switch first, then push by a separate command."
101
103
  fi
102
104
 
105
+ # Several pushes in one command, or a push inside a loop, are refused whole. The set runs once
106
+ # per call on the tree that lies there, and every other branch leaves unchecked.
107
+ pushes="$(printf '%s' "$probe" | grep -oE "${RT_CMD_BOUND}git([[:space:]]+-c[[:space:]]+[^[:space:]]+)*[[:space:]]+push([[:space:]]|\$)" | wc -l | tr -d ' ')"
108
+ if [ "${pushes:-0}" -gt 1 ] || printf '%s' "$probe" | grep -qE '(^|[;&|[:space:]])(do|then|else)[[:space:]]+git[[:space:]].*push'; then
109
+ push_deny "BLOCKED: several pushes by one command. The gate set runs once per call, on the tree that lies there — every other branch leaves for the hosting unchecked. Push each branch by a separate call, after switching to it."
110
+ fi
111
+
103
112
  workdir="$(rt_hook_cwd)"
104
113
  [ -z "$workdir" ] && workdir="${CLAUDE_PROJECT_DIR:-.}"
105
114
  cd "$workdir" 2>/dev/null || exit 0
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bash
2
+ # The fifth sign of the conversation guard: a question that offers to walk around a check does not
3
+ # leave. NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The
4
+ # conversation guard sources it — it was moved out when the guard crossed the file length limit.
5
+ #
6
+ # A red set was explained by a "foreign" cause, and the owner was asked whether to send it past the
7
+ # check. Such a question is a miss by itself, even when the owner answers "yes": a check is fixed at
8
+ # its cause or fixed itself, and a third option is not named. The sign reads the text the owner
9
+ # reads — the menu with its options, or the last reply when it ends with a question — and looks for
10
+ # the forms of a bypass: past the check, a bypass line, a disabled rule, a hook switched off.
11
+ #
12
+ # It expects `$tool`, `$asked_text`, `$transcript` and `$rt_hooks_dir` to be set; it prints the
13
+ # refusal and returns zero when the question offers a bypass, and stays silent otherwise.
14
+ #
15
+ # FAIL-OPEN: no text of a question — the sign stays silent.
16
+
17
+ rt_grill_bypass() {
18
+ local bypass_re offered_text reason deny_tail_text
19
+ bypass_re='мимо (проверк|гейт|хук)|в обход (проверк|гейт|хук)|обойти (проверк|гейт|хук)|bypass|--no-verify|Epic-stop-skip|Docs-skip|Task-folder-skip|# discard:|eslint-disable|stylelint-disable|отключ[а-я]* (проверк|правил|линтер|хук)|в список известных|allowlist'
20
+ if [ -n "$tool" ]; then
21
+ offered_text="$asked_text"
22
+ else
23
+ offered_text="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
24
+ def is_input:
25
+ .type == "user"
26
+ and ((.isCompactSummary // false) | not)
27
+ and ((.isMeta // false) | not)
28
+ and (((.message.content // []) | if type == "array"
29
+ then ([.[] | select(.type == "tool_result")] | length)
30
+ else 0 end) == 0);
31
+ (map(is_input) | rindex(true)) as $i
32
+ | (if $i == null then . else .[$i + 1:] end)
33
+ | [.[] | select(.type == "assistant") | (.message.content // [])[] | select(.type == "text") | .text]
34
+ | last // ""
35
+ | if test("\\?[[:space:]]*$") then . else "" end
36
+ ' 2>/dev/null)"
37
+ fi
38
+ [ -n "$offered_text" ] || return 1
39
+ printf '%s' "$offered_text" | grep -qiE "$bypass_re" 2>/dev/null || return 1
40
+
41
+ reason="BLOCKED by grill-gate: the question offers the owner to walk around a check.
42
+
43
+ A question about a bypass is a miss by itself, even when the owner answers «yes». A red check is fixed at its cause — on the machine and in the tree — or the check itself is fixed when it is wrong. A third option is not named, and handing the owner a command to run by hand instead is the same bypass. Ask only the decision the fix needs."
44
+
45
+ # shellcheck disable=SC1090
46
+ [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
47
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
48
+ deny_tail_text="$(rt_deny_tail "")"
49
+ [ -n "$deny_tail_text" ] && reason="${reason}
50
+
51
+ ${deny_tail_text}"
52
+
53
+ if [ -n "$tool" ]; then
54
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
55
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"grill-gate: a question does not offer a bypass of a check."}}\n'
56
+ else
57
+ jq -n --arg r "$reason" '{decision:"block",reason:$r}' 2>/dev/null \
58
+ || printf '{"decision":"block","reason":"grill-gate: a question does not offer a bypass of a check."}\n'
59
+ fi
60
+ return 0
61
+ }