@rt-tools/agent-kit 0.33.1 → 0.35.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 (159) hide show
  1. package/README.md +14 -13
  2. package/assets/agents/goal-critic.md +76 -0
  3. package/assets/agents/product-strategist.md +95 -0
  4. package/assets/agents/qa-engineer.md +3 -0
  5. package/assets/checks/check-specs.mjs +11 -2
  6. package/assets/checks/rt-kit-checks.config.mjs +6 -0
  7. package/assets/checks/spec-common.mjs +6 -3
  8. package/assets/checks/spec-scenarios.mjs +9 -1
  9. package/assets/checks/task-new.github.mjs +6 -0
  10. package/assets/defaults/project.sh +49 -81
  11. package/assets/defaults/push.sh +100 -0
  12. package/assets/docs/GLOSSARY.md +4 -0
  13. package/assets/hooks/browser-guard-device-id.sh +1 -0
  14. package/assets/hooks/browser-guard-no-asking.sh +1 -0
  15. package/assets/hooks/browser-guard-no-listing.sh +1 -0
  16. package/assets/hooks/browser-guard-no-other-drivers.sh +7 -3
  17. package/assets/hooks/browser-guard-require-select.sh +1 -0
  18. package/assets/hooks/claim-guard.sh +7 -6
  19. package/assets/hooks/dev-server-guard.sh +1 -0
  20. package/assets/hooks/dispatch.sh +56 -3
  21. package/assets/hooks/docs-guard.sh +1 -0
  22. package/assets/hooks/end-conversation-guard.sh +1 -0
  23. package/assets/hooks/epic-stop-guard.sh +1 -0
  24. package/assets/hooks/exam-guard.sh +6 -1
  25. package/assets/hooks/git-guard-delivery-body.sh +25 -3
  26. package/assets/hooks/git-guard-delivery-draft.sh +23 -0
  27. package/assets/hooks/git-guard-delivery-folder.sh +38 -1
  28. package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
  29. package/assets/hooks/git-guard-delivery-signature.sh +19 -0
  30. package/assets/hooks/git-guard-delivery.sh +15 -19
  31. package/assets/hooks/git-guard-discard.sh +1 -0
  32. package/assets/hooks/git-guard-main.sh +18 -4
  33. package/assets/hooks/git-guard-no-verify.sh +1 -0
  34. package/assets/hooks/git-guard-push-ahead.sh +98 -0
  35. package/assets/hooks/git-guard-push-marks.sh +99 -0
  36. package/assets/hooks/git-guard-push-tests.sh +102 -83
  37. package/assets/hooks/grill-gate.sh +1 -0
  38. package/assets/hooks/guard-note.sh +11 -3
  39. package/assets/hooks/handover-mark.sh +37 -0
  40. package/assets/hooks/metric-marks.sh +233 -0
  41. package/assets/hooks/metric-send-start.sh +38 -0
  42. package/assets/hooks/observe.sh +103 -0
  43. package/assets/hooks/owner-corrections.sh +36 -0
  44. package/assets/hooks/pre-push.sh +113 -0
  45. package/assets/hooks/prose-style-guard.sh +1 -0
  46. package/assets/hooks/pull-outcomes.sh +59 -0
  47. package/assets/hooks/push-set.sh +160 -0
  48. package/assets/hooks/push-sign.sh +433 -0
  49. package/assets/hooks/qa-dataid-guard.sh +1 -0
  50. package/assets/hooks/rerun-guard.sh +15 -6
  51. package/assets/hooks/reuse-first-guard.sh +1 -0
  52. package/assets/hooks/role-calls.sh +120 -0
  53. package/assets/hooks/rule-source-guard.sh +16 -0
  54. package/assets/hooks/skill-gate.sh +11 -0
  55. package/assets/hooks/task-flow-draft-guard.sh +1 -0
  56. package/assets/hooks/task-flow-guard.sh +1 -0
  57. package/assets/hooks/tree-assignment-guard.sh +1 -0
  58. package/assets/hooks/turn-exit-epic.sh +24 -0
  59. package/assets/hooks/turn-exit-guard.sh +3 -23
  60. package/assets/hooks/turn-exit-patterns.sh +4 -3
  61. package/assets/hooks/turn-exit-verdict.sh +18 -1
  62. package/assets/hooks/waiting-turn-guard.sh +3 -1
  63. package/assets/hooks/window-fill-guard.sh +1 -0
  64. package/assets/hooks/work-start-guard.sh +1 -0
  65. package/assets/hooks/write-targets.sh +21 -0
  66. package/assets/patterns/git-workflow-commit.azure.md +5 -3
  67. package/assets/patterns/git-workflow-commit.github.md +16 -3
  68. package/assets/patterns/git-workflow-commit.gitlab.md +5 -3
  69. package/assets/patterns/git-workflow-pr-body.github.md +20 -3
  70. package/assets/patterns/git-workflow-pr.azure.md +30 -0
  71. package/assets/patterns/git-workflow-pr.github.md +57 -1
  72. package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
  73. package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
  74. package/assets/patterns/task-flow-close.md +32 -22
  75. package/assets/patterns/task-flow-cycle.md +72 -0
  76. package/assets/patterns/task-flow-start.md +3 -3
  77. package/assets/rules/browser-verification.md +4 -0
  78. package/assets/rules/deploy-flow.azure.md +5 -0
  79. package/assets/rules/deploy-flow.github.md +5 -0
  80. package/assets/rules/deploy-flow.gitlab.md +5 -0
  81. package/assets/rules/git-workflow.azure.md +15 -0
  82. package/assets/rules/git-workflow.github.md +15 -0
  83. package/assets/rules/git-workflow.gitlab.md +15 -0
  84. package/assets/rules/mockups.needs-mockups.md +13 -5
  85. package/assets/rules/task-flow.md +31 -25
  86. package/assets/samples/tasks/_template/plan.md +8 -0
  87. package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
  88. package/assets/skills/interface-review-icons.needs-app.md +136 -0
  89. package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
  90. package/assets/skills/interface-review-motion.needs-app.md +209 -0
  91. package/assets/skills/interface-review-performance.needs-app.md +110 -0
  92. package/assets/skills/interface-review-principles.needs-app.md +263 -0
  93. package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
  94. package/assets/skills/interface-review.needs-app.md +199 -0
  95. package/assets/skills/write-a-skill.md +16 -3
  96. package/assets/templates/postmortem.md +2 -0
  97. package/assets/workflows/feature.js +33 -5
  98. package/assets/workflows/plan.js +71 -4
  99. package/bin/agent-kit.d.ts.map +1 -1
  100. package/bin/agent-kit.js +28 -0
  101. package/bin/agent-kit.js.map +1 -1
  102. package/lib/cargo.d.ts +35 -0
  103. package/lib/cargo.d.ts.map +1 -1
  104. package/lib/cargo.js +76 -0
  105. package/lib/cargo.js.map +1 -1
  106. package/lib/commands.d.ts +9 -0
  107. package/lib/commands.d.ts.map +1 -1
  108. package/lib/commands.js +32 -19
  109. package/lib/commands.js.map +1 -1
  110. package/lib/config.d.ts +5 -0
  111. package/lib/config.d.ts.map +1 -1
  112. package/lib/config.js +1 -0
  113. package/lib/config.js.map +1 -1
  114. package/lib/file-lock.d.ts +4 -0
  115. package/lib/file-lock.d.ts.map +1 -0
  116. package/lib/file-lock.js +23 -0
  117. package/lib/file-lock.js.map +1 -0
  118. package/lib/metric-lines.d.ts +20 -0
  119. package/lib/metric-lines.d.ts.map +1 -0
  120. package/lib/metric-lines.js +117 -0
  121. package/lib/metric-lines.js.map +1 -0
  122. package/lib/metric-send-mark.d.ts +52 -0
  123. package/lib/metric-send-mark.d.ts.map +1 -0
  124. package/lib/metric-send-mark.js +69 -0
  125. package/lib/metric-send-mark.js.map +1 -0
  126. package/lib/metric-send.d.ts +18 -0
  127. package/lib/metric-send.d.ts.map +1 -0
  128. package/lib/metric-send.js +226 -0
  129. package/lib/metric-send.js.map +1 -0
  130. package/lib/metric-usage.d.ts +34 -0
  131. package/lib/metric-usage.d.ts.map +1 -0
  132. package/lib/metric-usage.js +111 -0
  133. package/lib/metric-usage.js.map +1 -0
  134. package/lib/metrics.d.ts +92 -0
  135. package/lib/metrics.d.ts.map +1 -0
  136. package/lib/metrics.js +263 -0
  137. package/lib/metrics.js.map +1 -0
  138. package/lib/observations-cargo.d.ts +2 -0
  139. package/lib/observations-cargo.d.ts.map +1 -1
  140. package/lib/observations-cargo.js +1 -1
  141. package/lib/observations-cargo.js.map +1 -1
  142. package/lib/observations.d.ts +22 -2
  143. package/lib/observations.d.ts.map +1 -1
  144. package/lib/observations.js +40 -13
  145. package/lib/observations.js.map +1 -1
  146. package/lib/outcomes.d.ts +89 -0
  147. package/lib/outcomes.d.ts.map +1 -0
  148. package/lib/outcomes.js +274 -0
  149. package/lib/outcomes.js.map +1 -0
  150. package/lib/ship.js +1 -1
  151. package/lib/ship.js.map +1 -1
  152. package/lib/shipment.d.ts.map +1 -1
  153. package/lib/shipment.js +7 -1
  154. package/lib/shipment.js.map +1 -1
  155. package/lib/snapshot.d.ts +2 -0
  156. package/lib/snapshot.d.ts.map +1 -1
  157. package/lib/snapshot.js +6 -0
  158. package/lib/snapshot.js.map +1 -1
  159. package/package.json +1 -1
@@ -7,9 +7,9 @@
7
7
  # on them entirely — rule `git-workflow`. A direct commit there is almost always a miss: "stayed on
8
8
  # main after merging the previous PR".
9
9
  #
10
- # The name of the main branch is not hard-wired as a string: first the pointer of the remote
11
- # repository is asked, then the existing `origin/main` and `origin/master` are tried, and only at
12
- # the end `main` is taken.
10
+ # The name of the main branch is not hard-wired as a string: first `RT_MAIN_BRANCH` of the tree
11
+ # profile is read, then the pointer of the remote repository is asked, then the existing
12
+ # `origin/main` and `origin/master` are tried, and only at the end `main` is taken.
13
13
  #
14
14
  # FAIL-OPEN: not a repository, no git, a detached HEAD, broken input — pass. A broken guard must not
15
15
  # get in the way of work.
@@ -17,6 +17,7 @@
17
17
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the
18
18
  # guard itself.
19
19
  RT_GUARD_NAME=git-guard-main
20
+ RT_GUARD_RULE=git-workflow
20
21
 
21
22
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
22
23
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -99,7 +100,20 @@ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
99
100
  branch="$(git branch --show-current 2>/dev/null)"
100
101
  [ -z "$branch" ] && exit 0 # a detached HEAD is not about this case
101
102
 
102
- default="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##')"
103
+ # The name is read from the tree's own profile — the one the commit runs in — as the other delivery
104
+ # guards read it. Not through the package default: that one always says `main`, and a tree on
105
+ # `master` that named nothing would lose the guessing below. The profile is loaded in a subshell, so
106
+ # nothing it declares leaks into the guard.
107
+ top="$(git rev-parse --show-toplevel 2>/dev/null)"
108
+ declared="$(
109
+ # shellcheck disable=SC1090,SC1091
110
+ [ -n "$top" ] && [ -f "$top/.claude/rt-kit/project.sh" ] \
111
+ && . "$top/.claude/rt-kit/project.sh" >/dev/null 2>&1 </dev/null
112
+ printf '%s' "${RT_MAIN_BRANCH:-}"
113
+ )"
114
+
115
+ default="$declared"
116
+ [ -z "$default" ] && default="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##')"
103
117
  if [ -z "$default" ]; then
104
118
  for candidate in main master; do
105
119
  if git show-ref --verify --quiet "refs/remotes/origin/$candidate" 2>/dev/null; then
@@ -26,6 +26,7 @@
26
26
  # in the way of work.
27
27
 
28
28
  RT_GUARD_NAME=git-guard-no-verify
29
+ RT_GUARD_RULE=git-workflow
29
30
 
30
31
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
31
32
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env bash
2
+ # The push set run ahead of the push: every check of `rt_push_checks <base>`, a green mark for each
3
+ # that passed. The push guard then reads the marks instead of running the steps again.
4
+ #
5
+ # NOT a guard: it has no `rt-hook:` declaration and is called by hand or by the agent —
6
+ # `bash .claude/hooks/git-guard-push-ahead.sh`, in the background. The guard cannot run a step
7
+ # longer than its hook limit, and a guard cut by the limit lets the call through with no verdict;
8
+ # here no limit cuts the run.
9
+ #
10
+ # The base, the profile and the marks are the guard's own — the helper `git-guard-push-marks.sh`
11
+ # and the same profile files — so a mark written here answers exactly the line the guard asks
12
+ # about. A check already green on this tree and base is not run again.
13
+ #
14
+ # Exit codes: 0 — the set is green; 1 — a check is red; 3 — the run did not start (no profile, no
15
+ # repository, edits outside the index). Not 2: to a hook that code means "refuse", and this command
16
+ # refuses nothing.
17
+ not_started=3
18
+
19
+ rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20
+
21
+ root="$(git rev-parse --show-toplevel 2>/dev/null)" || {
22
+ printf 'push ahead: not a repository\n' >&2
23
+ exit "$not_started"
24
+ }
25
+ cd "$root" || exit "$not_started"
26
+
27
+ for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "$root/.claude/rt-kit/defaults/project.sh" "$root/.claude/rt-kit/project.sh"; do
28
+ # shellcheck disable=SC1090
29
+ [ -f "$profile" ] && . "$profile" 2>/dev/null
30
+ done
31
+ # shellcheck disable=SC1090
32
+ . "$rt_hooks_dir/git-guard-push-marks.sh" 2>/dev/null || {
33
+ printf 'push ahead: the helper git-guard-push-marks.sh is not laid out\n' >&2
34
+ exit "$not_started"
35
+ }
36
+ command -v rt_push_checks >/dev/null 2>&1 || {
37
+ printf 'push ahead: the tree profile declares no rt_push_checks\n' >&2
38
+ exit "$not_started"
39
+ }
40
+ command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
41
+ # The line of a run for the metrics. No file — the checks run and record nothing.
42
+ # shellcheck disable=SC1091
43
+ [ -f "$rt_hooks_dir/metric-marks.sh" ] && . "$rt_hooks_dir/metric-marks.sh" 2>/dev/null
44
+ command -v rt_run_note >/dev/null 2>&1 || rt_run_note() { return 0; }
45
+ command -v rt_tree_sign >/dev/null 2>&1 || rt_tree_sign() { return 0; }
46
+
47
+ # A mark vouches for the tree of the head, and the checks run over the working copy: with edits
48
+ # outside the index the run would write marks for content that does not leave.
49
+ rt_push_mark_clean || {
50
+ printf 'push ahead: the working copy holds edits outside the index — commit first, the marks are written only for a clean copy\n' >&2
51
+ exit "$not_started"
52
+ }
53
+
54
+ base="$(rt_push_base "${RT_MAIN_BRANCH:-main}")"
55
+ skip_code="${RT_SKIP_CODE:-7}"
56
+ printf 'push ahead: base %s, tree %s\n' "${base:-none}" "$(git rev-parse --short 'HEAD^{tree}')"
57
+ sign="$(rt_tree_sign .)"
58
+
59
+ red=""
60
+ while IFS= read -r check; do
61
+ [ -z "$check" ] && continue
62
+ if rt_push_mark_has "$check" "$base"; then
63
+ printf '= green already: %s\n' "$check"
64
+ continue
65
+ fi
66
+ # After a red check a heavy one is not started: the push is refused anyway.
67
+ if [ -n "$red" ] && rt_push_check_heavy "$check"; then
68
+ printf '· held after red: %s\n' "$check"
69
+ continue
70
+ fi
71
+ key_before="$(rt_push_mark_key "$check" "$base")"
72
+ started="$(date +%s)"
73
+ out="$(eval "$check" 2>&1)"
74
+ status=$?
75
+ took=$(($(date +%s) - started))
76
+ if [ "$status" -eq 0 ]; then
77
+ rt_run_note "$sign" "$started" green "$check"
78
+ rt_push_mark_put "$check" "$base" "$key_before"
79
+ printf '+ green in %ss: %s\n' "$took" "$check"
80
+ elif [ "$status" -eq "$skip_code" ]; then
81
+ rt_run_note "$sign" "$started" skipped "$check"
82
+ printf '~ nothing to look at: %s\n' "$check"
83
+ else
84
+ rt_run_note "$sign" "$started" red "$check"
85
+ red="${red}${red:+
86
+ }${check}"
87
+ printf '✗ red in %ss: %s\n%s\n' "$took" "$check" "$(printf '%s' "$out" | tail -n 25)"
88
+ fi
89
+ done <<EOF
90
+ $(rt_push_checks "$base")
91
+ EOF
92
+
93
+ if [ -n "$red" ]; then
94
+ printf '\npush ahead: red —\n%s\n' "$red"
95
+ exit 1
96
+ fi
97
+ printf '\npush ahead: the set is green, the push passes from the marks\n'
98
+ exit 0
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env bash
2
+ # The base of the push set and the marks of a green run, shared by the push guard and by the
3
+ # command that runs the set ahead (`git-guard-push-ahead.sh`).
4
+ #
5
+ # NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. Both callers source
6
+ # it, and it decides nothing alone — it answers "against what" and "was this already green".
7
+ #
8
+ # FAIL-OPEN: no network, no remote, no git — the base falls back to the main branch or to nothing,
9
+ # and a mark that cannot be read counts as absent. Either way the set runs, never less of it.
10
+
11
+ # The base the contribution is counted against. Prints `origin/<branch>` or nothing.
12
+ #
13
+ # A stacked branch is counted against the branch it was created from, not against the main one:
14
+ # against the main one it paid for the whole stack under it, and a branch of the second kit three
15
+ # levels up did not fit the hook limit at all. The parent is read from the branch reflog — git
16
+ # writes `branch: Created from <ref>` itself at `checkout -b` — and is taken only when its remote
17
+ # copy exists and is an ancestor of the head. A parent merged and removed, rewritten or moved past
18
+ # the head gives the main branch back: the gate may turn out stricter than needed, never weaker.
19
+ rt_push_base() {
20
+ local main="$1" branch from
21
+ git fetch --quiet origin "$main" 2>/dev/null
22
+ git rev-parse --verify --quiet "origin/$main" >/dev/null 2>&1 || return 0
23
+
24
+ branch="$(git symbolic-ref --quiet --short HEAD 2>/dev/null)"
25
+ if [ -n "$branch" ]; then
26
+ from="$(git reflog show --format=%gs "refs/heads/$branch" 2>/dev/null \
27
+ | sed -n 's/^branch: Created from //p' | tail -n 1)"
28
+ from="${from#refs/remotes/}"
29
+ from="${from#refs/heads/}"
30
+ from="${from#origin/}"
31
+ case "$from" in
32
+ '' | HEAD | "$main" | "$branch") ;;
33
+ *)
34
+ if git fetch --quiet origin "$from" 2>/dev/null &&
35
+ git rev-parse --verify --quiet "origin/$from" >/dev/null 2>&1 &&
36
+ git merge-base --is-ancestor "origin/$from" HEAD 2>/dev/null; then
37
+ printf 'origin/%s' "$from"
38
+ return 0
39
+ fi
40
+ ;;
41
+ esac
42
+ fi
43
+
44
+ printf 'origin/%s' "$main"
45
+ }
46
+
47
+ # A mark is trusted only on a clean working copy. The checks run over the working copy, while the
48
+ # push sends commits: with an edit outside the index the two differ, and a mark would vouch for
49
+ # what does not leave. The observations record is not counted: the guard writes it itself, on every
50
+ # call, and a tree that does not ignore it would never get a single mark.
51
+ rt_push_mark_clean() {
52
+ [ -z "$(git status --porcelain -- . ':(exclude).claude/rt-kit/observations' 2>/dev/null)" ]
53
+ }
54
+
55
+ # The key of a mark: the check line, the tree of the head and the commit of the base. The tree and
56
+ # not the commit — an amended commit with the same content does not pay again; the base too — a
57
+ # step chosen by what the branch touched answers for that base alone.
58
+ rt_push_mark_key() {
59
+ local tree base_sha=''
60
+ tree="$(git rev-parse --verify --quiet 'HEAD^{tree}' 2>/dev/null)" || return 1
61
+ [ -n "$2" ] && base_sha="$(git rev-parse --verify --quiet "$2" 2>/dev/null)"
62
+ printf '%s\n%s\n%s\n' "$1" "$tree" "$base_sha" | git hash-object --stdin 2>/dev/null
63
+ }
64
+
65
+ # The marks live in the shared `.git` directory: every working copy of the repository sees them,
66
+ # and none of them lands in history.
67
+ rt_push_mark_dir() {
68
+ local common
69
+ common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" || return 1
70
+ printf '%s/rt-kit/push-green' "$common"
71
+ }
72
+
73
+ rt_push_mark_has() {
74
+ local key dir
75
+ rt_push_mark_clean || return 1
76
+ key="$(rt_push_mark_key "$1" "$2")" || return 1
77
+ dir="$(rt_push_mark_dir)" || return 1
78
+ [ -n "$key" ] && [ -f "$dir/$key" ]
79
+ }
80
+
81
+ # The third argument is the key taken BEFORE the check ran. A commit made while it ran — by
82
+ # another session or by hand — changes the tree, and a mark written by the new key would vouch for
83
+ # content the check never saw: such a run writes nothing.
84
+ rt_push_mark_put() {
85
+ local key dir
86
+ rt_push_mark_clean || return 0
87
+ key="$(rt_push_mark_key "$1" "$2")" || return 0
88
+ [ -n "$key" ] && [ "$key" = "$3" ] || return 0
89
+ dir="$(rt_push_mark_dir)" || return 0
90
+ mkdir -p "$dir" 2>/dev/null && printf '%s\n' "$1" > "$dir/$key" 2>/dev/null
91
+ return 0
92
+ }
93
+
94
+ # The tree runs its heavy steps ahead and the guard only reads their marks. Declared by the
95
+ # profile: in a tree whose heavy steps fit the hook limit a refusal for a missing mark is a new step
96
+ # for nothing, and the package does not know how long another tree's steps take.
97
+ rt_push_heavy_ahead() {
98
+ [ "${RT_PUSH_HEAVY_AHEAD:-}" = 1 ]
99
+ }
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
- # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
2
+ # rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool|mcp__terminal__run_in_terminal
3
3
  # rt-hook-timeout: 1800
4
- # Requires: hooks/profile-check.sh, hooks/deny-tail.sh
4
+ # Requires: hooks/profile-check.sh, hooks/deny-tail.sh, hooks/push-sign.sh, hooks/push-set.sh, hooks/git-guard-push-marks.sh
5
5
  # The guard of the checks before a push. PreToolUse on the push call.
6
6
  #
7
7
  # A push is the entry into the pipeline: a merge into the main branch starts the rollout, and
@@ -21,14 +21,21 @@
21
21
  #
22
22
  # The base is taken from the remote, not from the local main branch: the local one falls behind or
23
23
  # diverges silently. That has happened already — the local one stood at a merge wiped from the
24
- # history by a force push, and the set counted against it would have been the wrong one. There is
25
- # no network or no remote — the base is empty, and the profile falls back to a full run: the gate
26
- # may turn out stricter than needed, but NEVER weaker.
24
+ # history by a force push, and the set counted against it would have been the wrong one. A stacked
25
+ # branch is counted against the remote copy of the branch it was created from — the helper
26
+ # `git-guard-push-marks.sh` says when. There is no network or no remote — the base is empty, and
27
+ # the profile falls back to a full run: the gate may turn out stricter than needed, but NEVER weaker.
27
28
  #
28
- # FAIL-OPEN: not a repository, broken input, no profile — pass.
29
+ # A check green on the same tree against the same base is not run again, and a tree that declares
30
+ # `RT_PUSH_HEAVY_AHEAD=1` runs its heavy steps ahead by `git-guard-push-ahead.sh`: the guard only
31
+ # reads their marks. The hook limit is 30 minutes, and the heavy steps of one tree outgrew it.
32
+ #
33
+ # FAIL-OPEN: not a repository, broken input, no profile, no parse file `push-sign.sh`, no set file
34
+ # `push-set.sh`, no perl — pass.
29
35
 
30
36
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
31
37
  RT_GUARD_NAME=git-guard-push-tests
38
+ RT_GUARD_RULE=git-workflow
32
39
 
33
40
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
34
41
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -39,35 +46,36 @@ input="$RT_HOOK_INPUT"
39
46
 
40
47
  tool="$(rt_hook_tool)"
41
48
  case "$tool" in
42
- # The environment terminal and the universal runner put the command into the same field.
43
- Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
49
+ # The environment terminal, the universal runner and the session terminal tab put the command
50
+ # into the same field. Left out of this list, the tab carried a push past the gate after two
51
+ # refusals: the tree had no git hook, and nothing else would have run the set. The git hook
52
+ # `pre-push` now runs it for a push this guard does not see.
53
+ Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool | mcp__terminal__run_in_terminal) ;;
44
54
  *) exit 0 ;;
45
55
  esac
46
56
 
47
57
  cmd="$(rt_hook_cmd)"
48
58
 
49
- # A push call is recognised by two signs at once — the `git` command at the start of the line or
50
- # after a separator, and the word `push` as a separate word. By the same technique as the delivery
51
- # guard: the substring "git push" alone does not catch a push — the credentials helper and the
52
- # request header are put between them by `-c` keys, and that is exactly the form pushed with here.
53
- # While the sign was a substring, the whole gate set was not run at all on such a push, and the
54
- # silence of the guard read as "green".
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
57
-
58
- # A stashed edit is never a push: `git stash push` puts the edit into the stash of this same
59
- # machine and sends nothing outside. The word `push` in it stands separate, and without this line
60
- # the guard ran the whole set on it and then refused the call on the first red check — that is, it
61
- # refused a command that sends nothing anywhere. The stash is cut out of the line, and the sign is
62
- # counted on the remainder: in a compound command a real push may stand next to it.
63
- probe="$(printf '%s' "$cmd" | sed -E 's/git[[:space:]]+stash[[:space:]]+push/git stash/g')"
64
- printf '%s' "$probe" | grep -qE '(^|[[:space:]])push([[:space:]]|$)' || exit 0
65
-
66
- # A dry-run push sends nothing: there is no point running the whole set for it.
59
+ # Without the word there is no push at all, and the parse below is not paid for.
67
60
  case "$cmd" in
68
- *--dry-run*) exit 0 ;;
61
+ *push*) ;;
62
+ *) exit 0 ;;
69
63
  esac
70
64
 
65
+ # The push calls and the branch switches are found by the parse in `push-sign.sh`: one line per
66
+ # call, read below. No parse file or no perl — no lines, and the guard passes.
67
+ # shellcheck disable=SC1090
68
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/push-sign.sh" 2>/dev/null || true
69
+ command -v rt_push_calls >/dev/null 2>&1 || exit 0
70
+ push_calls="$(printf '%s' "$cmd" | rt_push_calls)"
71
+
72
+ # A dry-run push sends nothing: there is no point running the whole set for it. A dry run of one
73
+ # call does not cover a real push next to it in the same command.
74
+ pushes="$(printf '%s\n' "$push_calls" | grep -c ' real$')"
75
+ opaque=false
76
+ printf '%s\n' "$push_calls" | grep -qx 'opaque' && printf '%s' "$cmd" | grep -q 'git' && opaque=true
77
+ [ "${pushes:-0}" -gt 0 ] || [ "$opaque" = true ] || exit 0
78
+
71
79
  # The refusal of this gate. The shared deny tail — the two lawful moves and the lawful form of a
72
80
  # bypass — may not be laid out; then there is no tail, and the reason stays as it was.
73
81
  push_deny() {
@@ -86,6 +94,13 @@ ${deny_tail_text}"
86
94
  exit 0
87
95
  }
88
96
 
97
+ # Commands the parse cannot read are refused when the text names a push: a shell reading its
98
+ # commands from the input, `source` of a substitution, function calls that grow without bound. What
99
+ # such a command runs is seen only when it runs, and a silent pass would let a push leave unchecked.
100
+ if [ "$opaque" = true ]; then
101
+ push_deny "BLOCKED: the command names a push, and the guard cannot read what it runs — a shell reading commands from its input, \`source\` of a substitution, or function calls that grow without bound. Run the push as a separate plain command: \`git push <remote> <branch>\`."
102
+ fi
103
+
89
104
  # A branch switch in the same command is refused whole.
90
105
  #
91
106
  # The guard is a parse of the command BEFORE it runs: it runs the set in the tree that lies there
@@ -95,17 +110,26 @@ ${deny_tail_text}"
95
110
  # file that is not in the pushed branch at all — it was looking at the branch the same command was
96
111
  # leaving.
97
112
  #
98
- # What is judged is a switch to an existing branch. Creating a new one (`checkout -b`, `switch -c`)
99
- # does not fall here: a fresh branch has the same tree as it had.
100
- if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git[[:space:]]+(checkout|switch)[[:space:]]+" &&
101
- ! printf '%s' "$cmd" | grep -qE 'git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)([[:space:]]|$)'; then
113
+ # What is judged is a switch to another tree before the push. Creating a new branch from the current
114
+ # tip (`checkout -b`, `switch -c`) and restoring files do not fall here: the tree stays. A new
115
+ # branch from another start point does. A switch after the push changes nothing the set judged.
116
+ # The switch is found by the same parse as the push: a pattern over the line did not see
117
+ # `git checkout` inside `bash -c` or `eval`.
118
+ switched=false
119
+ printf '%s\n' "$push_calls" | awk '$0 == "switch" { s = 1 } / real$/ && s { f = 1 } END { exit !f }' && switched=true
120
+ if [ "$switched" = true ]; then
102
121
  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."
103
122
  fi
104
123
 
105
124
  # Several pushes in one command, or a push inside a loop, are refused whole. The set runs once
106
125
  # 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
126
+ # A push after `done` or inside `if` is one push; a push in the body or the condition of a loop is
127
+ # not. Several recipients in one call are several pushes too, and the parse above names them.
128
+ looped=false
129
+ printf '%s\n' "$push_calls" | grep -q '^loop .* real$' && looped=true
130
+ several_refs=false
131
+ printf '%s\n' "$push_calls" | grep -q ' several real$' && several_refs=true
132
+ if [ "${pushes:-0}" -gt 1 ] || [ "$looped" = true ] || [ "$several_refs" = true ]; then
109
133
  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
134
  fi
111
135
 
@@ -145,10 +169,10 @@ fi
145
169
  # `_default` suffix. There is neither — the hook passes: an empty guard is better than a guard
146
170
  # that refuses at random.
147
171
  rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
148
- for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
149
- # shellcheck disable=SC1090
150
- [ -f "$profile" ] && . "$profile" 2>/dev/null
151
- done
172
+ # The set itself is run by the code it shares with the git hook `pre-push`.
173
+ # shellcheck disable=SC1091
174
+ . "$rt_hooks_dir/push-set.sh" 2>/dev/null || exit 0
175
+ rt_push_set_profile "$rt_hooks_dir" "${CLAUDE_PROJECT_DIR:-.}"
152
176
 
153
177
  # A word about a missing profile function: a hook that exited silently is indistinguishable from a
154
178
  # working one. The file may not be laid out — then the former, silent behaviour stays.
@@ -180,55 +204,45 @@ if ! rt_needs rt_push_checks git-guard-push-tests; then
180
204
  exit 0
181
205
  fi
182
206
 
183
- main_branch="${RT_MAIN_BRANCH:-main}"
184
- base=''
185
- if git fetch --quiet origin "$main_branch" 2>/dev/null && git rev-parse --verify --quiet "origin/$main_branch" >/dev/null 2>&1; then
186
- base="origin/$main_branch"
187
- fi
188
-
189
- # The code by which a check declares that there was nothing to look at: neither "it matched" nor
190
- # "a divergence". Before, such a check said so by a line of output and exited with zero — in the
191
- # set that zero stood next to the passed ones and differed from them in nothing, while the summary
192
- # read as checked whole. It does not refuse the push: a check with nothing to look at is not a
193
- # breakage.
194
- rt_skip_code="${RT_SKIP_CODE:-7}"
207
+ base="$(rt_push_set_base)"
195
208
 
196
209
  # Every red among the light checks is named by one refusal. The gate used to leave on the first red
197
210
  # one, and each fix opened the next reason by a push of its own: three pushes in a row went so on one
198
- # branch — a repeated function, a name shared by two kits, a paint probe. After the first red a
199
- # heavy check is not started: the push is refused anyway, and its minutes buy nothing.
200
- command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
201
-
202
- failed=""
203
- output=""
204
- skipped=""
205
- held=""
206
- ran=0
207
- while IFS= read -r check; do
208
- [ -z "$check" ] && continue
209
- if [ -n "$failed" ] && rt_push_check_heavy "$check"; then
210
- held="${held}${held:+
211
- }${check}"
212
- continue
213
- fi
214
- ran=$((ran + 1))
215
- out="$(eval "$check" 2>&1)"
216
- status=$?
217
- [ "$status" -eq 0 ] && continue
218
- if [ "$status" -eq "$rt_skip_code" ]; then
219
- skipped="${skipped}${skipped:+
220
- }${check}"
221
- continue
222
- fi
223
- failed="${failed}${failed:+
224
- }${check}"
225
- output="${output}${output:+
226
-
227
- }── ${check}
228
- $(printf '%s' "$out" | tail -n 25)"
229
- done <<EOF
230
- $(rt_push_checks "$base")
231
- EOF
211
+ # branch — a repeated function, a name shared by two kits, a paint probe. A check with nothing to look
212
+ # at exits with the skip code: before, it said so by a line of output and exited with zero, and in the
213
+ # set that zero stood next to the passed ones and differed from them in nothing.
214
+ rt_push_set_ask_ahead=1
215
+ rt_push_set_run "$base"
216
+ failed="$rt_push_set_failed"
217
+ output="$rt_push_set_output"
218
+ skipped="$rt_push_set_skipped"
219
+ held="$rt_push_set_held"
220
+ ahead="$rt_push_set_ahead"
221
+ ran="$rt_push_set_ran"
222
+
223
+ # Heavy steps with no mark are named in one refusal together with the red light ones: the command
224
+ # that runs them ahead goes to the background, where no hook limit cuts it, and the push after it
225
+ # passes from the marks.
226
+ if [ -n "$ahead" ]; then
227
+ rt_push_gate_note ahead
228
+ ahead_cmd="bash ${rt_hooks_dir#"$PWD"/}/git-guard-push-ahead.sh"
229
+ dirty_line=""
230
+ rt_push_mark_clean || dirty_line="
231
+
232
+ The working copy holds edits outside the index: a mark is trusted only on a clean copy. Commit first."
233
+ red_line=""
234
+ [ -n "$failed" ] && red_line="
235
+
236
+ Red among the light checks:
237
+ ${failed}
238
+
239
+ $(printf '%s' "$output" | tr -d '\000')"
240
+ push_deny "BLOCKED: the heavy steps of this tree run ahead, not inside the guard — inside it they hit the hook limit, and a guard cut by the limit lets the call through with no verdict. No green mark for this tree and base:
241
+
242
+ ${ahead}
243
+
244
+ Run them in the background by \`${ahead_cmd}\` (the Bash call with run_in_background), wait for its end and push again: the push then passes from the marks.${dirty_line}${red_line}"
245
+ fi
232
246
 
233
247
  # What was skipped is named aloud even when the set passed: silence about it is exactly the
234
248
  # indistinguishability this code was created for. The push goes through at that — there is no
@@ -270,8 +284,13 @@ if [ ! -f "$gap_mark" ]; then
270
284
  : >"$gap_mark" 2>/dev/null || true
271
285
  fi
272
286
 
287
+ # A green set leaves the commit it judged in the mark of the shared git directory. The git hook
288
+ # `pre-push` runs the same set before every push, whatever sent it, and lets through a push of
289
+ # exactly this commit at once: the call this guard just let through would otherwise wait for the set
290
+ # twice. The mark is not written when every check was skipped or the copy has uncommitted edits.
273
291
  if [ -z "$failed" ]; then
274
292
  rt_push_gate_note green
293
+ rt_push_mark_write
275
294
  exit 0
276
295
  fi
277
296
 
@@ -36,6 +36,7 @@
36
36
 
37
37
  # Its own name in the observations: the refusal is written by the shared deny tail, not by the guard.
38
38
  RT_GUARD_NAME=grill-gate
39
+ RT_GUARD_RULE=task-flow
39
40
 
40
41
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
41
42
  . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
@@ -13,7 +13,10 @@
13
13
  # voluntary and exact: a hook that counts its own refusals by itself — like the rules gate — does
14
14
  # not set it, and the same event is not counted a second time.
15
15
  #
16
- # WHAT IS RECORDED. The guard name and the session id. Cleaning the values and deciding whether to
16
+ # THE RULE. A line `RT_GUARD_RULE=<rule>` next to the name says which rule the guard enforces. A
17
+ # refusal after that rule was loaded in the session counts against the rule: its text taught nothing.
18
+ #
19
+ # WHAT IS RECORDED. The guard name, its rule and the session id. Cleaning the values and deciding whether to
17
20
  # write at all is done by the observation record itself; here only the call is assembled.
18
21
  #
19
22
  # FAIL-OPEN. There may be no record at all — no file, the tree switched observations off, the
@@ -23,7 +26,7 @@
23
26
  # A guard refusal into the observations. The name is taken from `RT_GUARD_NAME`, the session id
24
27
  # from the hook input; without a name nothing is written.
25
28
  rt_guard_note() {
26
- local rt_gn_dir rt_gn_sid rt_gn_name
29
+ local rt_gn_dir rt_gn_sid rt_gn_name rt_gn_empty=''
27
30
  # A default, not a bare read: a guard may be written to abort on an undeclared variable, and a
28
31
  # record that reads it bare brings such a guard down whole — on every call, not on a refusal.
29
32
  rt_gn_name="${RT_GUARD_NAME:-}"
@@ -37,7 +40,12 @@ rt_guard_note() {
37
40
  rt_gn_sid="$(printf '%s' "${RT_HOOK_INPUT:-}" | jq -r '.session_id // empty' 2>/dev/null)"
38
41
 
39
42
  if [ -n "$rt_gn_sid" ]; then
40
- rt_note guard-deny "res=$rt_gn_name" "sid=$rt_gn_sid"
43
+ # shellcheck disable=SC1090
44
+ [ -f "$rt_gn_dir/metric-marks.sh" ] && . "$rt_gn_dir/metric-marks.sh" 2>/dev/null
45
+ command -v rt_refusal_empty >/dev/null 2>&1 \
46
+ && rt_gn_empty="$(rt_refusal_empty "$rt_gn_name" "$rt_gn_sid" \
47
+ "$(printf '%s' "${RT_HOOK_INPUT:-}" | jq -c '.tool_input // empty' 2>/dev/null)")"
48
+ rt_note guard-deny "res=$rt_gn_name" "sid=$rt_gn_sid" "empty=$rt_gn_empty" "rule=${RT_GUARD_RULE:-}"
41
49
  else
42
50
  rt_note guard-deny "res=$rt_gn_name"
43
51
  fi
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env bash
2
+ # rt-hook: PostToolUse Bash
3
+ # Requires: hooks/hook-input.sh, hooks/metric-marks.sh, hooks/git-guard-delivery.sh
4
+ #
5
+ # Keeps the sign of a handover after the call really ran. The delivery guard stands before the call,
6
+ # and a guard after it in the row may still refuse the request, so the guard only announces the
7
+ # branch. This hook turns the announcement into the sign. A call that failed leaves no sign.
8
+ #
9
+ # FAIL-OPEN: no input, no parser, no announcement — exit with zero and no output. This hook never
10
+ # refuses.
11
+
12
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
13
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || exit 0
14
+
15
+ rt_hook_read
16
+ [ -n "$RT_HOOK_INPUT" ] || exit 0
17
+ command -v jq >/dev/null 2>&1 || exit 0
18
+
19
+ cmd="$(rt_hook_cmd)"
20
+ case "$cmd" in
21
+ *pr*create* | *pr*ready* | *mr*create* | *mr*update*) ;;
22
+ *) exit 0 ;;
23
+ esac
24
+
25
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/metric-marks.sh" 2>/dev/null || exit 0
26
+
27
+ session="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '.session_id // empty' 2>/dev/null)"
28
+ pending="$(rt_handover_pending_file "$session" "$cmd")"
29
+ [ -n "$pending" ] && [ -f "$pending" ] || exit 0
30
+
31
+ failed="$(printf '%s' "$RT_HOOK_INPUT" | jq -r '
32
+ (.tool_response | type) == "object"
33
+ and ((.tool_response.is_error // false) or (.tool_response.interrupted // false)
34
+ or ((.tool_response.exit_code // 0) != 0))' 2>/dev/null)"
35
+ [ "$failed" = true ] || rt_handover_mark "$(cat "$pending" 2>/dev/null)"
36
+ rm -f "$pending" 2>/dev/null
37
+ exit 0