@rt-tools/agent-kit 0.29.3 → 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 (60) hide show
  1. package/assets/agents/rules-reviewer.md +2 -1
  2. package/assets/agents/skill-curator.md +3 -0
  3. package/assets/checks/board-epics.github.mjs +17 -2
  4. package/assets/checks/board-folders.mjs +40 -1
  5. package/assets/checks/board.github.mjs +4 -1
  6. package/assets/checks/check-board.github.mjs +2 -1
  7. package/assets/checks/check-prose-style.mjs +6 -2
  8. package/assets/checks/spec-anchors.mjs +5 -1
  9. package/assets/defaults/gate-map.sh +4 -1
  10. package/assets/defaults/shell.sh +6 -2
  11. package/assets/hooks/claim-guard.sh +42 -13
  12. package/assets/hooks/epic-stop-guard.sh +26 -1
  13. package/assets/hooks/git-guard-delivery-draft.sh +4 -1
  14. package/assets/hooks/git-guard-delivery-epic.sh +11 -1
  15. package/assets/hooks/git-guard-delivery-folder.sh +33 -15
  16. package/assets/hooks/git-guard-delivery-tree.sh +29 -0
  17. package/assets/hooks/git-guard-delivery.sh +6 -6
  18. package/assets/hooks/git-guard-push-tests.sh +10 -1
  19. package/assets/hooks/grill-gate-bypass.sh +61 -0
  20. package/assets/hooks/grill-gate.sh +143 -3
  21. package/assets/hooks/proposal-guard.sh +3 -0
  22. package/assets/hooks/task-flow-context.sh +2 -0
  23. package/assets/hooks/task-flow-guard.sh +27 -0
  24. package/assets/hooks/turn-exit-guard.sh +3 -3
  25. package/assets/hooks/turn-exit-verdict.sh +18 -1
  26. package/assets/patterns/git-workflow-commit.azure.md +4 -0
  27. package/assets/patterns/git-workflow-commit.github.md +15 -0
  28. package/assets/patterns/git-workflow-commit.gitlab.md +4 -0
  29. package/assets/patterns/git-workflow-pr-body.github.md +4 -0
  30. package/assets/patterns/queue-audit-read.github.md +47 -0
  31. package/assets/patterns/spec-driven-rule.md +8 -2
  32. package/assets/patterns/task-flow-close.md +11 -9
  33. package/assets/patterns/task-flow-start.md +21 -22
  34. package/assets/pitfalls/doc-style.md +8 -0
  35. package/assets/pitfalls/turn-conduct.md +14 -0
  36. package/assets/rules/component-structure.md +4 -0
  37. package/assets/rules/doc-style.md +26 -7
  38. package/assets/rules/git-workflow.azure.md +4 -0
  39. package/assets/rules/git-workflow.github.md +7 -24
  40. package/assets/rules/git-workflow.gitlab.md +4 -0
  41. package/assets/rules/queue-audit.github.md +77 -0
  42. package/assets/rules/spec-driven.md +5 -6
  43. package/assets/rules/status-report.md +6 -0
  44. package/assets/rules/task-flow.md +18 -21
  45. package/assets/rules/testing.md +4 -0
  46. package/assets/rules/turn-conduct.md +22 -20
  47. package/lib/commands.d.ts.map +1 -1
  48. package/lib/commands.js +12 -2
  49. package/lib/commands.js.map +1 -1
  50. package/lib/hooks-map.d.ts +14 -0
  51. package/lib/hooks-map.d.ts.map +1 -1
  52. package/lib/hooks-map.js +55 -8
  53. package/lib/hooks-map.js.map +1 -1
  54. package/lib/sync.d.ts +9 -0
  55. package/lib/sync.d.ts.map +1 -1
  56. package/lib/sync.js +6 -1
  57. package/lib/sync.js.map +1 -1
  58. package/package.json +1 -1
  59. package/rt-tools-agent-kit-0.30.0.tgz +0 -0
  60. package/rt-tools-agent-kit-0.29.3.tgz +0 -0
@@ -82,7 +82,8 @@ what exactly they diverge and what the executor will do wrong by following one o
82
82
 
83
83
  For a **gap**: the name of the resource that lacks it, a quote of the place where it should have
84
84
  stood (or the section name, if there is no place at all), and what happens when the case comes.
85
- A gap has no second quote — do not invent one.
85
+ A gap has no second quote — do not invent one. A gap that asks for new text names the room left
86
+ in that resource: its lines and characters against the prose limits of the size check.
86
87
 
87
88
  No findings — say so. An empty reply is cheaper than an invented one: by an invented one real
88
89
  texts get edited.
@@ -108,6 +108,9 @@ Then for every proposal:
108
108
  - **package, companion or tree** — by the criterion above, and in one word why;
109
109
  - **ready-made text** — exactly what to insert, in the style of the neighbouring rules: in
110
110
  English, as a statement, without padding;
111
+ - **room in the target** — the target file's lines and characters now and after the insertion,
112
+ against the prose limits of the size check; a proposal that takes the file over a limit names
113
+ what in the same file is cut to make room;
111
114
  - **what caused it** — what exactly in this task went wrong without this rule;
112
115
  - whether the gate map needs an edit and which — in the package default or in the tree override.
113
116
 
@@ -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
+ }
@@ -169,7 +169,7 @@ export function pullState(ref, options) {
169
169
  const target = ref === undefined || ref === null || `${ref}`.trim() === '' ? [] : [`${ref}`.trim()];
170
170
  let pull;
171
171
  try {
172
- pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable'], options);
172
+ pull = ghJson(['pr', 'view', ...target, '--json', 'number,isDraft,reviewRequests,latestReviews,author,mergeable,headRefName'], options);
173
173
  } catch (error) {
174
174
  if (error instanceof OfflineError) {
175
175
  throw error;
@@ -194,6 +194,9 @@ export function pullState(ref, options) {
194
194
  // author. Only a direct "conflicting" is judged: `UNKNOWN` means the hosting is still
195
195
  // computing, and reading it as a conflict would mean refusing work on every fresh head.
196
196
  conflicting: pull.mergeable === 'CONFLICTING',
197
+ // The head branch: the folder guard judges the branch of the named PR, not the checked-out
198
+ // one — the lower PR of a stack is lifted from the upper branch.
199
+ branch: pull.headRefName ?? null,
197
200
  };
198
201
  }
199
202
 
@@ -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" ] \
@@ -37,6 +37,7 @@ rt_delivery_draft_ready() {
37
37
  # the whole demand with a single space. So the first argument is taken, whatever it is —
38
38
  # a number, an address or a branch name — and its absence means "ask about the current
39
39
  # branch".
40
+ pull_head=''
40
41
  pull_ref="$(printf '%s' "$cmd" | sed -nE 's/.*(gh[[:space:]]+pr[[:space:]]+ready|glab[[:space:]]+mr[[:space:]]+update)[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\2/p' | head -1)"
41
42
  if rt_needs rt_pull_state git-guard-delivery; then
42
43
  pull="$(cd "$root" && rt_pull_state "$pull_ref" 2>/dev/null)" || pull=''
@@ -53,6 +54,8 @@ rt_delivery_draft_ready() {
53
54
  *[!0-9]*) pull_name=" «${pull_name}»" ;;
54
55
  *) pull_name=" #${pull_name}" ;;
55
56
  esac
57
+ # The head branch of the PR goes to the folder condition below.
58
+ pull_head="$(printf '%s' "$pull" | jq -r '.branch // empty' 2>/dev/null)"
56
59
  printf '%s' "$pull" | jq -e '.reviewed' >/dev/null 2>&1 \
57
60
  || fault "the request${pull_name} has no review: no reviewer was requested and nobody left a review. A lifted draft reads as «ready to merge», and there is nobody to merge — set a reviewer and repeat."
58
61
 
@@ -82,7 +85,7 @@ rt_delivery_draft_ready() {
82
85
  # The task folder: the same subject as at opening and at the merge, as a third line. The
83
86
  # condition is local — it reads the branch, not the hosting — and therefore stands outside
84
87
  # the network tier above.
85
- command -v rt_delivery_ready_folder >/dev/null 2>&1 && rt_delivery_ready_folder
88
+ command -v rt_delivery_ready_folder >/dev/null 2>&1 && rt_delivery_ready_folder "$pull_head"
86
89
 
87
90
  deny_faults
88
91
  fi
@@ -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
@@ -20,7 +20,7 @@
20
20
  # into the main branch all the same. The branch name is substituted whole, slash included: for a
21
21
  # branch like `chore/312-slug` the folder lies in a nested directory.
22
22
  rt_folder_in_branch() {
23
- git ls-tree -d --name-only HEAD -- "$1" 2>/dev/null | head -1
23
+ git ls-tree -d --name-only "${2:-HEAD}" -- "$1" 2>/dev/null | head -1
24
24
  }
25
25
 
26
26
  # Was there a task folder in this branch at all. Asked of the branch that deleted it: otherwise the
@@ -29,10 +29,23 @@ rt_folder_was_in_branch() {
29
29
  _base="$1"
30
30
  _folder="$2"
31
31
  _had="$(git ls-tree -d --name-only "$_base" -- "$_folder" 2>/dev/null | head -1)"
32
- [ -z "$_had" ] && _had="$(git log "$_base..HEAD" --diff-filter=A --name-only --pretty=format: -- "$_folder" 2>/dev/null | head -1)"
32
+ [ -z "$_had" ] && _had="$(git log "$_base..${3:-HEAD}" --diff-filter=A --name-only --pretty=format: -- "$_folder" 2>/dev/null | head -1)"
33
33
  [ -n "$_had" ]
34
34
  }
35
35
 
36
+ # The branch and the tree the folder is judged by: sets `_branch` and `_tree`. A command that names
37
+ # a PR is judged by that PR's head: the lower PR of a stack is lifted from the upper branch, and the
38
+ # checked-out branch carries a folder the named PR does not have. The tree of the head is read from
39
+ # the remote ref. Without a head, or without its ref, the checked-out branch is judged, as before.
40
+ rt_delivery_folder_target() {
41
+ _branch="$(git branch --show-current 2>/dev/null)"
42
+ _tree=HEAD
43
+ [ -n "$1" ] && [ "$1" != "$_branch" ] || return 0
44
+ git rev-parse --verify --quiet "refs/remotes/origin/$1" >/dev/null 2>&1 || return 0
45
+ _branch="$1"
46
+ _tree="refs/remotes/origin/$1"
47
+ }
48
+
36
49
  # Condition for opening the PR: the folder is taken apart, and a record from the branch has arrived
37
50
  # in the archive. The refusal accumulates together with the other delivery conditions and is
38
51
  # printed all at once.
@@ -71,16 +84,17 @@ rt_delivery_open_folder() {
71
84
  # pieces of work in a row travelled into the main branch exactly that way, and the body of each PR
72
85
  # carried a promise to remove the folder after approval.
73
86
  #
74
- # The function asks for the branch itself: on this turn the guard has not worked it out yet.
87
+ # The function asks for the branch itself: on this turn the guard has not worked it out yet. The
88
+ # argument is the head branch of the named PR, empty when the PR state did not answer.
75
89
  rt_delivery_ready_folder() {
76
90
  [ -n "$tasks_dir" ] || return 0
77
91
  printf '%s' "$cmd" | grep -qiE "$folder_skip_re" && return 0
78
92
 
79
- _branch="$(git branch --show-current 2>/dev/null)"
93
+ rt_delivery_folder_target "$1"
80
94
  [ -z "$_branch" ] && return 0
81
95
  rt_task_branch_ok "$_branch" || return 0 # no folder stands behind a branch without a task
82
96
 
83
- _lying="$(rt_folder_in_branch "$tasks_dir/$_branch")"
97
+ _lying="$(rt_folder_in_branch "$tasks_dir/$_branch" "$_tree")"
84
98
  [ -n "$_lying" ] \
85
99
  && fault "the branch carries the task folder «${_lying}» — a lifted draft reads as «ready to merge», and merging it there is not allowed. The button is pressed by a person on the hosting, and the folder reaches main before their hand does. Move to «${archive_dir:-archive}» what explains the decisions taken, delete the rest, commit and repeat. If the work is merged in parts, put the comment «# Task-folder-skip: <reason>» into the command."
86
100
  }
@@ -91,33 +105,37 @@ rt_delivery_ready_folder() {
91
105
  rt_delivery_merge_folder() {
92
106
  [ -n "$tasks_dir" ] || exit 0 # the tree keeps no work by a folder
93
107
 
94
- _branch="$(git branch --show-current 2>/dev/null)"
95
- [ -z "$_branch" ] && exit 0
96
- rt_task_branch_ok "$_branch" || exit 0 # no folder stands behind a branch without a task
97
-
98
- _folder="$tasks_dir/$_branch"
99
-
100
108
  # First we look for the bypass in the command itself — that works without a network too. If
101
109
  # only the PR body were read, then without a network the guard would refuse a merge whose
102
110
  # reason is written in that very body.
103
111
  printf '%s' "$cmd" | grep -qiE "$folder_skip_re" && exit 0
104
112
 
105
113
  _number="$(printf '%s' "$cmd" | sed -nE 's/.*(pr|mr)[[:space:]]+(merge|update)[[:space:]]+([0-9]+).*/\3/p' | head -1)"
114
+ _head=''
115
+ if [ -n "$_number" ] && rt_needs rt_pull_state git-guard-delivery; then
116
+ _head="$(cd "$root" && rt_pull_state "$_number" 2>/dev/null | jq -r '.branch // empty' 2>/dev/null)"
117
+ fi
118
+ rt_delivery_folder_target "$_head"
119
+ [ -z "$_branch" ] && exit 0
120
+ rt_task_branch_ok "$_branch" || exit 0 # no folder stands behind a branch without a task
121
+
122
+ _folder="$tasks_dir/$_branch"
123
+
106
124
  if [ -n "$_number" ] && rt_needs rt_report_body git-guard-delivery; then
107
125
  _body="$(cd "$root" && rt_report_body "$_number" 2>/dev/null)"
108
126
  [ -n "$_body" ] && printf '%s' "$_body" | grep -qiE "$folder_skip_re" && exit 0
109
127
  fi
110
128
 
111
- _lying="$(rt_folder_in_branch "$_folder")"
129
+ _lying="$(rt_folder_in_branch "$_folder" "$_tree")"
112
130
  [ -n "$_lying" ] \
113
131
  && deny "BLOCKED: the task folder «${_lying}» is left in the branch — it will travel into main. There will be nobody to take it apart later: the work moves on to the next task, and this request closes. Move to «${archive_dir:-archive}» what explains the decisions taken, delete the rest and repeat. If the work is merged in parts, put the line «Task-folder-skip: <reason>» into the body of the request."
114
132
 
115
133
  [ -n "$archive_dir" ] || exit 0
116
- _base="$(git merge-base "$main_branch" HEAD 2>/dev/null)"
134
+ _base="$(git merge-base "$main_branch" "$_tree" 2>/dev/null)"
117
135
  [ -z "$_base" ] && exit 0
118
- rt_folder_was_in_branch "$_base" "$_folder" || exit 0
136
+ rt_folder_was_in_branch "$_base" "$_folder" "$_tree" || exit 0
119
137
 
120
- _gained="$(git diff --name-only --diff-filter=A "$_base" HEAD -- "$archive_dir" 2>/dev/null | head -1)"
138
+ _gained="$(git diff --name-only --diff-filter=A "$_base" "$_tree" -- "$archive_dir" 2>/dev/null | head -1)"
121
139
  [ -z "$_gained" ] \
122
140
  && deny "BLOCKED: the task folder was deleted, but the branch added nothing to «${archive_dir}». Deleting is cheaper than taking apart — and together with the folder the analysis of the request is gone, the only record of the words of the owner. Move what explains the decisions taken as one file with a telling name and repeat."
123
141
 
@@ -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