@rt-tools/agent-kit 0.29.0 → 0.29.2

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 (53) hide show
  1. package/assets/checks/board-epic-plan.github.mjs +128 -9
  2. package/assets/checks/board-epics.github.mjs +6 -10
  3. package/assets/checks/board-folders.mjs +50 -0
  4. package/assets/checks/check-lib-layers.mjs +4 -2
  5. package/assets/checks/check-spec-coverage.mjs +65 -0
  6. package/assets/checks/check-work-steps.mjs +238 -0
  7. package/assets/checks/epic-table.github.mjs +15 -6
  8. package/assets/checks/lib-common.mjs +9 -4
  9. package/assets/checks/lib-domains.mjs +7 -4
  10. package/assets/checks/rt-kit-checks.config.mjs +1 -1
  11. package/assets/checks/task-new.github.mjs +6 -6
  12. package/assets/defaults/project.sh +15 -1
  13. package/assets/hooks/git-guard-delivery-epic.sh +8 -1
  14. package/assets/hooks/git-guard-delivery-tree.sh +63 -16
  15. package/assets/hooks/git-guard-delivery.sh +12 -11
  16. package/assets/hooks/git-guard-no-verify.sh +142 -0
  17. package/assets/hooks/git-guard-push-tests.sh +39 -8
  18. package/assets/hooks/grill-gate.sh +63 -2
  19. package/assets/hooks/prose-style-guard.sh +49 -3
  20. package/assets/hooks/turn-exit-epic.sh +39 -0
  21. package/assets/hooks/turn-exit-guard.sh +6 -4
  22. package/assets/hooks/turn-exit-patterns.sh +51 -0
  23. package/assets/hooks/turn-exit-verdict.sh +20 -1
  24. package/assets/hooks/waiting-turn-guard.sh +56 -1
  25. package/assets/hooks/write-targets.sh +23 -1
  26. package/assets/laws/work-conduct.md +22 -0
  27. package/assets/patterns/doc-style-human.md +6 -0
  28. package/assets/patterns/git-workflow-commit.github.md +4 -0
  29. package/assets/patterns/git-workflow-merge.md +1 -0
  30. package/assets/patterns/git-workflow-pr-body.github.md +10 -5
  31. package/assets/patterns/spec-driven-domain.md +4 -0
  32. package/assets/patterns/status-report-table.github.md +6 -0
  33. package/assets/patterns/task-flow-start.md +27 -23
  34. package/assets/patterns/testing-e2e.md +25 -0
  35. package/assets/pitfalls/turn-conduct.md +28 -0
  36. package/assets/rules/doc-style.md +1 -1
  37. package/assets/rules/git-workflow.github.md +2 -1
  38. package/assets/rules/observability.needs-app.md +5 -0
  39. package/assets/rules/reuse-first.md +33 -11
  40. package/assets/rules/spec-driven.md +3 -1
  41. package/assets/rules/task-flow.md +30 -29
  42. package/assets/rules/testing.md +15 -0
  43. package/assets/rules/turn-conduct.md +44 -46
  44. package/assets/rules/typescript-conventions.md +8 -0
  45. package/assets/samples/tasks/_template/plan.md +7 -1
  46. package/assets/samples/tasks/_template/progress.md +13 -0
  47. package/lib/observations-cargo.d.ts +12 -0
  48. package/lib/observations-cargo.d.ts.map +1 -1
  49. package/lib/observations-cargo.js +18 -1
  50. package/lib/observations-cargo.js.map +1 -1
  51. package/package.json +1 -1
  52. package/rt-tools-agent-kit-0.29.2.tgz +0 -0
  53. package/rt-tools-agent-kit-0.29.0.tgz +0 -0
@@ -13,12 +13,17 @@ import { CONFIG, ROOT, parseAllowlist } from './rt-kit-checks.config.mjs';
13
13
 
14
14
  const FAMILIES = CONFIG.families;
15
15
  /**
16
- * The lib root and the backend family come from the tree settings, not from the code: in a tree
16
+ * The lib root and the backend families come from the tree settings, not from the code: in a tree
17
17
  * that keeps its libs under another name the walk went past the code and the check went green on an
18
18
  * empty directory — that is, it answered "no violations" where it had not looked at all.
19
19
  */
20
20
  const LIBS_ROOT = CONFIG.libsRoot;
21
- const API_FAMILY = CONFIG.apiFamily;
21
+ /**
22
+ * The backend families are a list, and a single name is read as a list of one: a tree holds more
23
+ * than one server application under the same root, and a family the walk skipped is
24
+ * indistinguishable from one walked without divergences.
25
+ */
26
+ const API_FAMILIES = [CONFIG.apiFamily ?? []].flat().filter(Boolean);
22
27
  /**
23
28
  * The selector prefix mandatory for frontend libs. The word belongs to the tree entirely; empty
24
29
  * means the prefix means nothing here, and the check says nothing about it.
@@ -37,7 +42,7 @@ const COMMON_DOMAIN_LAYERS = [...FLAT_LAYERS, 'feature'].sort();
37
42
  /** The backend has no `ui` and no `shell`: it renders no markup and does no routing */
38
43
  const API_DOMAIN_LAYERS = ['api', 'data-access', 'feature', 'util'];
39
44
  /** Where libs that ended up outside the domain grid are looked for */
40
- const LIB_ROOTS = [...FAMILIES, API_FAMILY].map((family) => `${LIBS_ROOT}/${family}`);
45
+ const LIB_ROOTS = [...FAMILIES, ...API_FAMILIES].map((family) => `${LIBS_ROOT}/${family}`);
41
46
  const REQUIRED_FILES = ['project.json', 'tsconfig.json', 'vitest.config.mts', 'src/index.ts'];
42
47
  const BOUNDARIES_DIR = 'eslint/boundaries/domains';
43
48
 
@@ -173,7 +178,7 @@ function sourceCount(libPath) {
173
178
  export {
174
179
  FAMILIES,
175
180
  LIBS_ROOT,
176
- API_FAMILY,
181
+ API_FAMILIES,
177
182
  LIB_PREFIX,
178
183
  BARREL_FILES,
179
184
  FLAT_LAYERS,
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import {
10
10
  API_DOMAIN_LAYERS,
11
- API_FAMILY,
11
+ API_FAMILIES,
12
12
  COMMON_DOMAIN_LAYERS,
13
13
  FAMILIES,
14
14
  FEATURE_DOMAIN_LAYERS,
@@ -88,7 +88,8 @@ function collectDomainLibs(domainPath, isCommon) {
88
88
  }
89
89
 
90
90
  /**
91
- * The domains of the backend: `<libs root>/<backend family>/<domain>` with four layers. `feature`
91
+ * The domains of the backend: `<libs root>/<backend family>/<domain>` with four layers, walked for
92
+ * every family of the list. `feature`
92
93
  * is both a lib and a directory with a lib per proto service — by the same rule by which a
93
94
  * feature domain of the frontend has `feature/<screen>`.
94
95
  *
@@ -99,8 +100,10 @@ function collectDomainLibs(domainPath, isCommon) {
99
100
  function collectApiDomainLibs() {
100
101
  const libs = [];
101
102
 
102
- for (const entry of dirsIn(`${LIBS_ROOT}/${API_FAMILY}`)) {
103
- const domainPath = `${LIBS_ROOT}/${API_FAMILY}/${entry}`;
103
+ const domainPaths = API_FAMILIES.flatMap((family) =>
104
+ dirsIn(`${LIBS_ROOT}/${family}`).map((entry) => `${LIBS_ROOT}/${family}/${entry}`)
105
+ );
106
+ for (const domainPath of domainPaths) {
104
107
  if (isNotDomain(domainPath) || isLegacyDomain(domainPath)) {
105
108
  continue;
106
109
  }
@@ -186,7 +186,7 @@ const DEFAULTS = {
186
186
  libsRoot: 'libs',
187
187
  /** The families of front-end libs: `<libs root>/<family>/<domain>/<layer>`. */
188
188
  families: ['site', 'admin'],
189
- /** The backend family under the same root: its domains have a layer ladder of their own. */
189
+ /** The backend families under the same root — one name or a list of them; their domains have a layer ladder of their own. */
190
190
  apiFamily: 'api',
191
191
  /** The scope of import aliases: `@scope/<family>/<domain>/<layer>` in `tsconfig.base.json`. */
192
192
  importScope: '@app',
@@ -227,27 +227,27 @@ function epicOfCard(epicNumber) {
227
227
  // law into every task of the epic as its plan, and the branch of the epic was then read from
228
228
  // that law and came back empty. Both sides answered as usual, and the miss showed only by
229
229
  // reading a created task.
230
- const found = planPathOf(card.body, { makeupRequired: false });
230
+ const found = planPathOf(card.body, { makeupRequired: false, epicNumber });
231
231
  const plan = found.path;
232
232
  if (plan === null) {
233
233
  fail(`the card of the epic #${epicNumber}: ${found.why}. The branch of the epic is named in the plan too`);
234
234
  }
235
- return { plan, branch: epicBranchOf(plan, epicNumber) };
235
+ return { plan, branch: epicBranchOf(found.text, epicNumber) };
236
236
  }
237
237
 
238
238
  /**
239
- * The branch of the epic, read from the header of its plan.
239
+ * The branch of the epic, read from the header of its plan. The text comes from the shared reading:
240
+ * a plan of a live epic lies in the branch of that epic and not on the disk of this one.
240
241
  *
241
242
  * Three spellings are accepted: the one this command writes, the bare word about a branch and the
242
243
  * English one — the plans of a tree are translated one at a time, and a single spelling would take
243
244
  * every plan but the freshest out of the reading in silence.
244
245
  */
245
246
  function epicBranchOf(plan, epicNumber) {
246
- const path = join(ROOT, plan);
247
- if (!existsSync(path)) {
247
+ if (plan === null || plan === undefined) {
248
248
  return null;
249
249
  }
250
- const named = readFileSync(path, 'utf8').match(
250
+ const named = plan.match(
251
251
  new RegExp(`\\*\\*(?:Ветка эпика|Ветка|Branch):\\*\\*\\s*\`?(${TASK_KEY}-${epicNumber}-[a-z0-9][a-z0-9-]*)\`?`)
252
252
  );
253
253
  return named ? named[1] : null;
@@ -101,13 +101,26 @@ rt_push_checks_default() {
101
101
 
102
102
  for check in check-doc-paths check-specs check-file-size check-dupes check-styles \
103
103
  check-glossary check-lib-layers check-reuse check-schema-drift check-states check-state-next \
104
- check-turn-map check-archive-age check-profile-drift check-hook-scope check-push-gate; do
104
+ check-turn-map check-work-steps check-spec-coverage check-archive-age check-profile-drift \
105
+ check-hook-scope check-push-gate; do
105
106
  [ -f "$root/$RT_CHECKS_DIR/$check.mjs" ] && printf '%s\n' "node $RT_CHECKS_DIR/$check.mjs"
106
107
  done
107
108
 
108
109
  return 0
109
110
  }
110
111
 
112
+ # Is a check of the gate set heavy: success — it builds, raises or shoots, and costs minutes. After
113
+ # the first red check the gate still runs the light ones, so that one refusal names every red among
114
+ # them; a heavy one is not started then — its minutes buy nothing while the push is refused anyway.
115
+ # Before, the gate left on the first red, and every fix opened the next reason by a push of its own.
116
+ rt_push_check_heavy_default() {
117
+ case "$1" in
118
+ *' nx '* | *'nx affected'* | *'nx run'* | *'docker '* | *playwright* | *e2e*) return 0 ;;
119
+ esac
120
+
121
+ return 1
122
+ }
123
+
111
124
  # Which document must travel by the same commit as this file. Prints a path pattern or stays silent.
112
125
  rt_docs_pair_for_default() {
113
126
  case "$1" in
@@ -456,6 +469,7 @@ rt_qa_decorative_default() {
456
469
  # Defaults under the shared names. The project override will declare any of them anew — and call the
457
470
  # same name from here with the `_default` suffix for everything it did not name itself.
458
471
  rt_push_checks() { rt_push_checks_default "$@"; }
472
+ rt_push_check_heavy() { rt_push_check_heavy_default "$@"; }
459
473
  rt_push_docs_only() { rt_push_docs_only_default "$@"; }
460
474
 
461
475
  rt_docs_pair_for() { rt_docs_pair_for_default "$@"; }
@@ -76,8 +76,15 @@ rt_epic_base() {
76
76
 
77
77
  # The main branch is asked of the epic, not of the base: there it is fixed by one merge, and the
78
78
  # branches of all its tasks get it at once.
79
+ #
80
+ # The base answers for the epic when it already carries the tip. The merge of the main branch
81
+ # reaches the remote copy of the epic branch only through a push, and a push is sometimes
82
+ # refused by a check over code that a task of this epic is meant to fix — the task whose branch
83
+ # is being created right here. Judged by the remote copy alone, the guard closes the only road
84
+ # to that fix and names no other: the epic stands until a person lifts a check by hand.
79
85
  if git rev-parse --verify --quiet "origin/${main_branch}" >/dev/null 2>&1 \
80
- && ! git merge-base --is-ancestor "origin/${main_branch}" "origin/${_epic_branch}" 2>/dev/null; then
86
+ && ! git merge-base --is-ancestor "origin/${main_branch}" "origin/${_epic_branch}" 2>/dev/null \
87
+ && ! git merge-base --is-ancestor "origin/${main_branch}" "$_base_ref" 2>/dev/null; then
81
88
  _behind="$(git rev-list --count "origin/${_epic_branch}..origin/${main_branch}" 2>/dev/null)"
82
89
  fault "the branch of the epic «${_epic_branch}» does not carry the tip of «${main_branch}» — it has moved ahead by ${_behind:-several} commits. The main branch is merged into the branch of the epic, not bypassed by taking the base from the main one: git checkout ${_epic_branch}, git merge origin/${main_branch}, and send the branch."
83
90
  fi
@@ -16,7 +16,13 @@
16
16
  # did not differ from the session's tree — everything goes as before. A tree with no profile of its own is not judged at all: a foreign tree is not accountable
17
17
  # to this guard, and a refusal on a lawful name has no bypass.
18
18
  #
19
- # FAIL-OPEN: no move in the command, no profile in the tree it moves to — the form is not judged.
19
+ # The task itself is asked of the same tree. A branch created in another repository carries the
20
+ # number of a task of that repository; asked of the session's work queue, the number pointed to a
21
+ # task that does not exist or to a foreign one. A second copy of the same repository is not another
22
+ # tree: the shared `.git` directory is one, so the work queue and the profile are one too.
23
+ #
24
+ # FAIL-OPEN: no move in the command, no profile in the tree it moves to — neither the form nor the
25
+ # task is judged.
20
26
 
21
27
  # Where the command runs, if it says so itself — the move at the start of the call. Prints the tree
22
28
  # root or stays silent.
@@ -29,22 +35,63 @@ rt_delivery_exec_dir() {
29
35
  git -C "$named" rev-parse --show-toplevel 2>/dev/null
30
36
  }
31
37
 
32
- # Is the branch name lawful. The tree of execution answers; where it is the session's own tree, or
33
- # says nothing of itself, the answer comes from the profile already loaded.
34
- rt_delivery_branch_form_ok() {
35
- named="$1"
38
+ # The root of the tree of execution when it is another repository, or silence. Another repository
39
+ # is told by its shared `.git` directory, not by its root: a second copy of the same repository has
40
+ # a root of its own and the same work queue.
41
+ rt_delivery_foreign_root() {
36
42
  other="$(rt_delivery_exec_dir)"
37
- if [ -n "$other" ] && [ "$other" != "$root" ]; then
38
- [ -f "$other/.claude/rt-kit/project.sh" ] || return 0
39
- (
40
- for profile in "$other/.claude/rt-kit/defaults/project.sh" "$other/.claude/rt-kit/project.sh"; do
41
- # shellcheck disable=SC1090
42
- [ -f "$profile" ] && . "$profile" 2>/dev/null
43
- done
44
- command -v rt_task_branch_ok >/dev/null 2>&1 || exit 0
45
- rt_task_branch_ok "$named"
46
- )
43
+ [ -n "$other" ] || return 0
44
+ mine="$(git -C "$root" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
45
+ theirs="$(git -C "$other" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
46
+ [ -n "$theirs" ] && [ "$mine" != "$theirs" ] && printf '%s' "$other"
47
+ return 0
48
+ }
49
+
50
+ # Runs one profile function in the tree of execution, with that tree's profile loaded over the
51
+ # package default. A tree with no profile of its own, or a profile without the function, answers
52
+ # with success and no output: a foreign tree is not accountable to this guard.
53
+ rt_delivery_in_tree() {
54
+ tree="$1"; shift
55
+ [ -f "$tree/.claude/rt-kit/project.sh" ] || return 0
56
+ (
57
+ cd "$tree" 2>/dev/null || exit 0
58
+ # The session profile is loaded in this shell already: without the reset its function
59
+ # would answer for a foreign tree that never declared one.
60
+ unset -f "$1" 2>/dev/null
61
+ for profile in "$tree/.claude/rt-kit/defaults/project.sh" "$tree/.claude/rt-kit/project.sh"; do
62
+ # shellcheck disable=SC1090
63
+ [ -f "$profile" ] && . "$profile" 2>/dev/null
64
+ done
65
+ command -v "$1" >/dev/null 2>&1 || exit 0
66
+ "$@"
67
+ )
68
+ }
69
+
70
+ # Is the branch name lawful. The tree of execution answers; where it is the session's own
71
+ # repository, or says nothing of itself, the answer comes from the profile already loaded.
72
+ rt_delivery_branch_form_ok() {
73
+ other="$(rt_delivery_foreign_root)"
74
+ if [ -n "$other" ]; then
75
+ rt_delivery_in_tree "$other" rt_task_branch_ok "$1"
47
76
  return $?
48
77
  fi
49
- rt_task_branch_ok "$named"
78
+ rt_task_branch_ok "$1"
79
+ }
80
+
81
+ # The state of the task, from the work queue of the tree of execution. The session's own repository
82
+ # answers by the profile already loaded, from the session root — as before.
83
+ rt_delivery_task_state() {
84
+ other="$(rt_delivery_foreign_root)"
85
+ if [ -n "$other" ]; then
86
+ rt_delivery_in_tree "$other" rt_task_state "$1"
87
+ return $?
88
+ fi
89
+ command -v rt_task_state >/dev/null 2>&1 || return 0
90
+ (cd "$root" && rt_task_state "$1")
91
+ }
92
+
93
+ # The branch the command works on: of the tree of execution when it is another repository.
94
+ rt_delivery_current_branch() {
95
+ other="$(rt_delivery_foreign_root)"
96
+ git -C "${other:-.}" branch --show-current 2>/dev/null
50
97
  }
@@ -181,18 +181,18 @@ fault() {
181
181
  # shellcheck disable=SC1090
182
182
  [ -f "$rt_hooks_dir/git-guard-delivery-epic.sh" ] && . "$rt_hooks_dir/git-guard-delivery-epic.sh" 2>/dev/null
183
183
 
184
+ # Another repository the command runs in answers for the name form, the task and the branch.
185
+ # shellcheck disable=SC1090
186
+ [ -f "$rt_hooks_dir/git-guard-delivery-tree.sh" ] && . "$rt_hooks_dir/git-guard-delivery-tree.sh" 2>/dev/null
187
+ command -v rt_delivery_branch_form_ok >/dev/null 2>&1 || rt_delivery_branch_form_ok() { rt_task_branch_ok "$1"; }
188
+ command -v rt_delivery_task_state >/dev/null 2>&1 || rt_delivery_task_state() { (cd "$root" && rt_task_state "$1"); }
189
+ command -v rt_delivery_current_branch >/dev/null 2>&1 || rt_delivery_current_branch() { git branch --show-current 2>/dev/null; }
190
+
184
191
  # A conflicting PR of one's own: the same technique as with the folder and the signature. The helper
185
192
  # is called before all the tiers below and judges not the readiness of this work but the right to
186
193
  # take the next one: while what was handed over conflicts, it is fixed by the first action of the
187
194
  # turn. No helper — the tier is not judged, and the work goes on.
188
195
  # shellcheck disable=SC1090
189
- # The tree the command runs in: the form of a branch name is judged by its profile, not by the
190
- # profile of the tree the session was started from. No helper — the form is judged as before.
191
- # shellcheck disable=SC1090
192
- [ -f "$rt_hooks_dir/git-guard-delivery-tree.sh" ] && . "$rt_hooks_dir/git-guard-delivery-tree.sh" 2>/dev/null
193
- command -v rt_delivery_branch_form_ok >/dev/null 2>&1 \
194
- || rt_delivery_branch_form_ok() { rt_task_branch_ok "$1"; }
195
-
196
196
  [ -f "$rt_hooks_dir/git-guard-delivery-conflict.sh" ] && . "$rt_hooks_dir/git-guard-delivery-conflict.sh" 2>/dev/null
197
197
  command -v rt_delivery_note_out >/dev/null 2>&1 && trap rt_delivery_note_out EXIT
198
198
  command -v rt_delivery_conflict >/dev/null 2>&1 && rt_delivery_conflict
@@ -215,7 +215,7 @@ check_task() {
215
215
  # lifts it.
216
216
  judge_column="${3:-no}"
217
217
  rt_needs rt_task_state git-guard-delivery || return 0
218
- state="$(cd "$root" && rt_task_state "$number" 2>/dev/null)" || return 0
218
+ state="$(rt_delivery_task_state "$number" 2>/dev/null)" || return 0
219
219
  [ -z "$state" ] && return 0
220
220
 
221
221
  printf '%s' "$state" | jq -e '.exists' >/dev/null 2>&1 \
@@ -345,12 +345,12 @@ printf '%s' "$cmd" \
345
345
  | grep -qE "${RT_CMD_BOUND}(gh[[:space:]]+pr[[:space:]]+create|glab[[:space:]]+mr[[:space:]]+create|az[[:space:]]+repos[[:space:]]+pr[[:space:]]+create)([[:space:]]|\$)" \
346
346
  || exit 0
347
347
 
348
- branch="$(git branch --show-current 2>/dev/null)"
348
+ branch="$(rt_delivery_current_branch)"
349
349
  [ -z "$branch" ] && exit 0 # a detached HEAD is not about this case
350
350
 
351
351
  # A local branch without a number is lawful, and a PR from it is not: an edit that travels to the
352
352
  # main branch starts from a task. This is the only place where a task-less branch runs into a wall.
353
- rt_task_branch_ok "$branch" \
353
+ rt_delivery_branch_form_ok "$branch" \
354
354
  || deny "BLOCKED: a request from the branch «${branch}», with no task standing behind it. An edit begins with a task visible in the work queue: create it — ${task_new} — and move the work into a branch with its number."
355
355
 
356
356
  number="$(rt_task_branch_number "$branch")"
@@ -368,7 +368,8 @@ command -v rt_epic_own_pull >/dev/null 2>&1 && rt_epic_own_pull "$state"
368
368
  title=''
369
369
  if command -v perl >/dev/null 2>&1; then
370
370
  title="$(printf '%s' "$cmd" | perl -0ne '
371
- if (/(?:--title|-t)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
371
+ my $v = qr/(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/;
372
+ if (/--title(?:=|\s+)$v/s || /(?<![-\w])-t(?:=|\s+)$v/s) {
372
373
  print defined $1 ? $1 : (defined $2 ? $2 : $3);
373
374
  }
374
375
  ' 2>/dev/null)"
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
3
+ # Requires: hooks/deny-tail.sh, hooks/guard-note.sh
4
+ # Guard of the commit hooks. PreToolUse on a git commit or push that skips the tree's git hooks.
5
+ #
6
+ # The commit hooks check the message, the formatting and the document pair; the push gate does not
7
+ # read commit messages. A commit made past the hooks therefore reaches the host unchecked: an amend
8
+ # that fixed a one-letter typo in the subject went that way, and the message nobody checked was
9
+ # pushed. The rule `git-workflow` says: an amend goes through the same hooks as a commit, and a
10
+ # commit that skipped them is redone without the skip before the push.
11
+ #
12
+ # What counts as a skip, read in the command position of `git commit` and `git push`:
13
+ #
14
+ # --no-verify — on both verbs, the full name or its abbreviation down to `--no-veri`
15
+ # -n — on `git commit` only, alone or in a cluster of short keys before a key that
16
+ # takes a value (`-nm`, `-an`); on `git push` `-n` is a dry run and passes
17
+ # -c core.hooksPath=<path> — between `git` and the verb: the hooks are looked for elsewhere
18
+ # HUSKY=0 — an environment assignment in front of the call: the hook runner stays silent
19
+ #
20
+ # Text inside quotes and the value of a key that takes one (`-m`, `-F` and the rest) are not read:
21
+ # a commit message naming the flag is not a skip.
22
+ #
23
+ # There is no lawful bypass: the owner forbade skipping the checks for any edit.
24
+ #
25
+ # FAIL-OPEN: no awk, broken input, a tool that is not a command — pass. A broken guard must not get
26
+ # in the way of work.
27
+
28
+ RT_GUARD_NAME=git-guard-no-verify
29
+
30
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
31
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
32
+
33
+ rt_hook_read
34
+ input="$RT_HOOK_INPUT"
35
+ [ -z "$input" ] && exit 0
36
+
37
+ tool="$(rt_hook_tool)"
38
+ case "$tool" in
39
+ Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
40
+ *) exit 0 ;;
41
+ esac
42
+
43
+ cmd="$(rt_hook_cmd)"
44
+
45
+ # The universal executor of the environment passes the real command as a nested string.
46
+ if [ "$tool" = "mcp__webstorm__execute_tool" ] && command -v perl >/dev/null 2>&1; then
47
+ inner="$(printf '%s' "$cmd" | perl -0ne '
48
+ if (/--command(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(.+))/s) {
49
+ print defined $1 ? $1 : (defined $2 ? $2 : $3);
50
+ }
51
+ ' 2>/dev/null)"
52
+ [ -n "$inner" ] && cmd="$inner"
53
+ fi
54
+
55
+ command -v awk >/dev/null 2>&1 || exit 0
56
+
57
+ # One line per skipping call: the verb and the form of the skip. A line of the command ends a call
58
+ # the same way a separator does, so a verb never carries over into the next line.
59
+ hits="$(printf '%s\n' "$cmd" | awk -v sq="'" '
60
+ function reset_call() { verb = ""; husky = 0; hookspath = 0; skip_value = 0; quote = "" }
61
+ function report(form) { if (verb == "commit" || verb == "push") print verb " " form }
62
+ function takes_value(w) {
63
+ return w == "-m" || w == "-F" || w == "-c" || w == "-C" || w == "-t" || w == "-o" \
64
+ || w == "--message" || w == "--file" || w == "--template" || w == "--author" \
65
+ || w == "--date" || w == "--reuse-message" || w == "--reedit-message" \
66
+ || w == "--fixup" || w == "--squash" || w == "--push-option" || w == "--repo"
67
+ }
68
+ BEGIN { reset_call() }
69
+ {
70
+ reset_call()
71
+ for (i = 1; i <= NF; i++) {
72
+ word = $i
73
+ # Text inside quotes is a value, not a key: skipped up to the closing quote.
74
+ if (quote != "") {
75
+ if (substr(word, length(word), 1) == quote) quote = ""
76
+ continue
77
+ }
78
+ first = substr(word, 1, 1)
79
+ if ((first == sq || first == "\"") && !(length(word) > 1 && substr(word, length(word), 1) == first)) {
80
+ quote = first
81
+ skip_value = 0
82
+ continue
83
+ }
84
+ if (word == "&&" || word == "||" || word == ";" || word == "|") { reset_call(); continue }
85
+ if (skip_value) { skip_value = 0; continue }
86
+ if (verb == "" && word ~ /^HUSKY=0$/) { husky = 1; continue }
87
+ base = word
88
+ sub(/^.*\//, "", base)
89
+ if (verb == "" && base == "git") {
90
+ for (j = i + 1; j <= NF; j++) {
91
+ arg = $j
92
+ if (arg == "-c") {
93
+ if (tolower($(j + 1)) ~ /^core\.hookspath=/) hookspath = 1
94
+ j++
95
+ continue
96
+ }
97
+ if (arg == "-C" || arg == "--git-dir" || arg == "--work-tree" \
98
+ || arg == "--namespace" || arg == "--exec-path") { j++; continue }
99
+ if (substr(arg, 1, 1) == "-") continue
100
+ verb = arg
101
+ break
102
+ }
103
+ i = j
104
+ if (husky) report("HUSKY=0")
105
+ if (hookspath) report("-c core.hooksPath")
106
+ continue
107
+ }
108
+ if (verb == "") continue
109
+ if (word ~ /^--no-veri(f|fy)?$/) { report("--no-verify"); continue }
110
+ if (takes_value(word)) { skip_value = 1; continue }
111
+ if (verb == "commit" && word ~ /^-[a-zA-Z]+$/) {
112
+ # A cluster of short keys: the letters after a key that takes a value are that value.
113
+ for (k = 2; k <= length(word); k++) {
114
+ ch = substr(word, k, 1)
115
+ if (ch == "n") { report("-n"); break }
116
+ if (index("mFcCtS", ch) > 0) break
117
+ }
118
+ }
119
+ }
120
+ }
121
+ ' 2>/dev/null | sort -u)"
122
+ [ -z "$hits" ] && exit 0
123
+
124
+ what="$(printf '%s\n' "$hits" | sed 's/^/git /' | paste -sd ',' - | sed 's/,/, /g')"
125
+
126
+ reason="BLOCKED by git-guard-no-verify: «${what}» skips the git hooks of the tree.
127
+
128
+ The commit hooks check the message, the formatting and the document pair, and the push gate does not read commit messages: a commit made past the hooks reaches the host unchecked. An amend goes through the same hooks as a commit, a one-letter typo included. Run the same command without the skip; when a hook refuses, fix what it names. A commit already made past the hooks is redone without the skip before the push — the rule git-workflow."
129
+
130
+ # shellcheck disable=SC1090
131
+ [ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
132
+ && . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
133
+ command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
134
+ deny_tail_text="$(rt_deny_tail)"
135
+ [ -n "$deny_tail_text" ] && reason="${reason}
136
+
137
+ ${deny_tail_text}"
138
+
139
+ jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
140
+ || printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"A git commit or push that skips the git hooks is refused. Run it without the skip."}}\n'
141
+
142
+ exit 0
@@ -112,12 +112,20 @@ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
112
112
  # copy holds someone else's uncommitted work. A call made from there is judged by the copy the
113
113
  # session stands in — that is, by a foreign tree: its stale archive and its half-written spec refuse
114
114
  # the call, while the contribution actually leaving is never checked at all.
115
+ #
116
+ # A second copy is the same shared `.git` directory under another root. Another repository is no
117
+ # copy of this tree, and its root differs from the session root always: judged by the roots alone,
118
+ # a session of one tree could not push a branch into another repository at all. Such a call is not
119
+ # judged by this guard — the set of this tree says nothing about a foreign one.
115
120
  moved="$(printf '%s' "$cmd" | sed -nE 's/.*(^|[;&|[:space:]])cd[[:space:]]+([^[:space:];&|]+).*/\2/p' | head -1)"
116
121
  moved="${moved%\'}"; moved="${moved#\'}"
117
122
  moved="${moved%\"}"; moved="${moved#\"}"
118
123
  if [ -n "$moved" ] && [ -d "$moved" ]; then
119
124
  moved_root="$(git -C "$moved" rev-parse --show-toplevel 2>/dev/null)"
120
125
  here_root="$(git rev-parse --show-toplevel 2>/dev/null)"
126
+ moved_repo="$(git -C "$moved" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
127
+ here_repo="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)"
128
+ [ -n "$moved_repo" ] && [ -n "$here_repo" ] && [ "$moved_repo" != "$here_repo" ] && exit 0
121
129
  if [ -n "$moved_root" ] && [ -n "$here_root" ] && [ "$moved_root" != "$here_root" ]; then
122
130
  push_deny "BLOCKED: the call goes from a second working copy — «${moved_root}», while the session stands in «${here_root}». The gate set runs where the session was started, not where the call was made: someone else's uncommitted work refuses it, and the contribution actually leaving passes unchecked. The second copy is for reading; bring the result of the merge back and send from the copy the session stands in."
123
131
  fi
@@ -176,12 +184,24 @@ fi
176
184
  # breakage.
177
185
  rt_skip_code="${RT_SKIP_CODE:-7}"
178
186
 
187
+ # Every red among the light checks is named by one refusal. The gate used to leave on the first red
188
+ # one, and each fix opened the next reason by a push of its own: three pushes in a row went so on one
189
+ # branch — a repeated function, a name shared by two kits, a paint probe. After the first red a
190
+ # heavy check is not started: the push is refused anyway, and its minutes buy nothing.
191
+ command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
192
+
179
193
  failed=""
180
194
  output=""
181
195
  skipped=""
196
+ held=""
182
197
  ran=0
183
198
  while IFS= read -r check; do
184
199
  [ -z "$check" ] && continue
200
+ if [ -n "$failed" ] && rt_push_check_heavy "$check"; then
201
+ held="${held}${held:+
202
+ }${check}"
203
+ continue
204
+ fi
185
205
  ran=$((ran + 1))
186
206
  out="$(eval "$check" 2>&1)"
187
207
  status=$?
@@ -191,9 +211,12 @@ while IFS= read -r check; do
191
211
  }${check}"
192
212
  continue
193
213
  fi
194
- failed="$check"
195
- output="$out"
196
- break
214
+ failed="${failed}${failed:+
215
+ }${check}"
216
+ output="${output}${output:+
217
+
218
+ }── ${check}
219
+ $(printf '%s' "$out" | tail -n 25)"
197
220
  done <<EOF
198
221
  $(rt_push_checks "$base")
199
222
  EOF
@@ -245,19 +268,27 @@ fi
245
268
 
246
269
  rt_push_gate_note red
247
270
 
248
- # The tail of the output, not all of it: the runner prints a long one, and what is needed is the
249
- # reason for the refusal.
250
- tail_out="$(printf '%s' "$output" | tail -n 40 | tr -d '\000')"
271
+ # The tail of every red output, not all of it: the runner prints a long one, and what is needed is
272
+ # the reason for the refusal.
273
+ tail_out="$(printf '%s' "$output" | tr -d '\000')"
274
+ red_count="$(printf '%s\n' "$failed" | grep -c .)"
275
+ held_line=""
276
+ [ -n "$held" ] && held_line="
277
+
278
+ Not started after the red ones — heavy, and the push is refused anyway:
279
+ ${held}"
251
280
  # Red comes in two kinds, and the guard does not tell them apart: it checks only the return code.
252
281
  # When a check of the code fails, "fix it and push again" is right. When the check itself is wrong,
253
282
  # the same text orders fixing code nobody touched: a refusal once taken apart lay wholly in
254
283
  # documents untouched by any commit of the branch. The verifiability law says a broken check does
255
284
  # not stop the work, and until this line there was no such option in the refusal.
256
- reason="BLOCKED: a push without a green local run. «${failed}» failed — fix it and push again, the guard must not be bypassed. A push is the entry into the pipeline, and red from here is checked already in production.
285
+ reason="BLOCKED: a push without a green local run. Red checks: ${red_count} — fix them and push again, the guard must not be bypassed. A push is the entry into the pipeline, and red from here is checked already in production.
286
+
287
+ ${failed}${held_line}
257
288
 
258
289
  Three moves from here: fix what is named and repeat the call; fix the check itself, if it is the one that is wrong — take the refusals apart one by one, show the analysis to the owner and correct the check; or bring the owner the price of a bypass and wait for their word. What is in dispute is not added to the known list: it holds what was accepted, not the results of a broken check.
259
290
 
260
- The tail of the output:
291
+ The tail of every red output:
261
292
 
262
293
  ${tail_out}"
263
294