@rt-tools/agent-kit 0.32.0 → 0.34.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 (75) hide show
  1. package/README.md +8 -7
  2. package/assets/agents/goal-critic.md +67 -0
  3. package/assets/agents/product-strategist.md +90 -0
  4. package/assets/agents/qa-engineer.md +3 -0
  5. package/assets/checks/board.github.mjs +27 -0
  6. package/assets/checks/check-specs.mjs +11 -2
  7. package/assets/checks/rt-kit-checks.config.mjs +6 -0
  8. package/assets/checks/spec-common.mjs +6 -3
  9. package/assets/checks/spec-scenarios.mjs +9 -1
  10. package/assets/checks/task-new.github.mjs +6 -0
  11. package/assets/checks/tree-assignment.mjs +11 -3
  12. package/assets/defaults/project.sh +10 -81
  13. package/assets/defaults/push.sh +100 -0
  14. package/assets/docs/GLOSSARY.md +4 -0
  15. package/assets/hooks/browser-guard-no-other-drivers.sh +6 -3
  16. package/assets/hooks/claim-guard.sh +6 -6
  17. package/assets/hooks/dispatch.sh +56 -3
  18. package/assets/hooks/exam-guard.sh +1 -1
  19. package/assets/hooks/git-guard-delivery-body.sh +25 -3
  20. package/assets/hooks/git-guard-delivery-folder.sh +17 -1
  21. package/assets/hooks/git-guard-delivery-merged.sh +65 -0
  22. package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
  23. package/assets/hooks/git-guard-delivery.sh +22 -8
  24. package/assets/hooks/git-guard-main.sh +17 -4
  25. package/assets/hooks/git-guard-push-ahead.sh +89 -0
  26. package/assets/hooks/git-guard-push-marks.sh +99 -0
  27. package/assets/hooks/git-guard-push-tests.sh +101 -83
  28. package/assets/hooks/git-guard-tree-assignment.sh +1 -1
  29. package/assets/hooks/grill-gate-options.sh +50 -0
  30. package/assets/hooks/grill-gate.sh +9 -1
  31. package/assets/hooks/pre-push.sh +113 -0
  32. package/assets/hooks/push-set.sh +150 -0
  33. package/assets/hooks/push-sign.sh +433 -0
  34. package/assets/hooks/rerun-guard.sh +14 -6
  35. package/assets/hooks/turn-exit-guard.sh +2 -2
  36. package/assets/hooks/turn-exit-patterns.sh +4 -3
  37. package/assets/hooks/turn-exit-verdict.sh +18 -1
  38. package/assets/hooks/waiting-turn-guard.sh +2 -1
  39. package/assets/hooks/write-targets.sh +21 -0
  40. package/assets/patterns/dependencies-upgrade.md +5 -1
  41. package/assets/patterns/git-workflow-commit.github.md +14 -0
  42. package/assets/patterns/git-workflow-pr-body.github.md +20 -3
  43. package/assets/patterns/git-workflow-pr.azure.md +30 -0
  44. package/assets/patterns/git-workflow-pr.github.md +57 -1
  45. package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
  46. package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
  47. package/assets/patterns/reuse-first-extend.md +5 -0
  48. package/assets/patterns/task-flow-close.md +27 -16
  49. package/assets/patterns/task-flow-start.md +5 -4
  50. package/assets/pitfalls/task-flow.md +4 -0
  51. package/assets/rules/browser-verification.md +4 -0
  52. package/assets/rules/dependencies.md +3 -1
  53. package/assets/rules/deploy-flow.azure.md +5 -0
  54. package/assets/rules/deploy-flow.github.md +5 -0
  55. package/assets/rules/deploy-flow.gitlab.md +5 -0
  56. package/assets/rules/git-workflow.azure.md +15 -0
  57. package/assets/rules/git-workflow.github.md +15 -0
  58. package/assets/rules/git-workflow.gitlab.md +15 -0
  59. package/assets/rules/mockups.needs-mockups.md +13 -5
  60. package/assets/rules/reuse-first.md +3 -0
  61. package/assets/rules/task-flow.md +21 -16
  62. package/assets/rules/testing.md +5 -0
  63. package/assets/samples/tasks/_template/plan.md +7 -0
  64. package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
  65. package/assets/skills/interface-review-icons.needs-app.md +136 -0
  66. package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
  67. package/assets/skills/interface-review-motion.needs-app.md +209 -0
  68. package/assets/skills/interface-review-performance.needs-app.md +110 -0
  69. package/assets/skills/interface-review-principles.needs-app.md +263 -0
  70. package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
  71. package/assets/skills/interface-review.needs-app.md +199 -0
  72. package/assets/skills/write-a-skill.md +16 -3
  73. package/assets/workflows/feature.js +33 -5
  74. package/assets/workflows/plan.js +71 -4
  75. package/package.json +1 -1
@@ -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,11 +21,17 @@
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
@@ -39,35 +45,36 @@ input="$RT_HOOK_INPUT"
39
45
 
40
46
  tool="$(rt_hook_tool)"
41
47
  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) ;;
48
+ # The environment terminal, the universal runner and the session terminal tab put the command
49
+ # into the same field. Left out of this list, the tab carried a push past the gate after two
50
+ # refusals: the tree had no git hook, and nothing else would have run the set. The git hook
51
+ # `pre-push` now runs it for a push this guard does not see.
52
+ Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool | mcp__terminal__run_in_terminal) ;;
44
53
  *) exit 0 ;;
45
54
  esac
46
55
 
47
56
  cmd="$(rt_hook_cmd)"
48
57
 
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.
58
+ # Without the word there is no push at all, and the parse below is not paid for.
67
59
  case "$cmd" in
68
- *--dry-run*) exit 0 ;;
60
+ *push*) ;;
61
+ *) exit 0 ;;
69
62
  esac
70
63
 
64
+ # The push calls and the branch switches are found by the parse in `push-sign.sh`: one line per
65
+ # call, read below. No parse file or no perl — no lines, and the guard passes.
66
+ # shellcheck disable=SC1090
67
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/push-sign.sh" 2>/dev/null || true
68
+ command -v rt_push_calls >/dev/null 2>&1 || exit 0
69
+ push_calls="$(printf '%s' "$cmd" | rt_push_calls)"
70
+
71
+ # A dry-run push sends nothing: there is no point running the whole set for it. A dry run of one
72
+ # call does not cover a real push next to it in the same command.
73
+ pushes="$(printf '%s\n' "$push_calls" | grep -c ' real$')"
74
+ opaque=false
75
+ printf '%s\n' "$push_calls" | grep -qx 'opaque' && printf '%s' "$cmd" | grep -q 'git' && opaque=true
76
+ [ "${pushes:-0}" -gt 0 ] || [ "$opaque" = true ] || exit 0
77
+
71
78
  # The refusal of this gate. The shared deny tail — the two lawful moves and the lawful form of a
72
79
  # bypass — may not be laid out; then there is no tail, and the reason stays as it was.
73
80
  push_deny() {
@@ -86,6 +93,13 @@ ${deny_tail_text}"
86
93
  exit 0
87
94
  }
88
95
 
96
+ # Commands the parse cannot read are refused when the text names a push: a shell reading its
97
+ # commands from the input, `source` of a substitution, function calls that grow without bound. What
98
+ # such a command runs is seen only when it runs, and a silent pass would let a push leave unchecked.
99
+ if [ "$opaque" = true ]; then
100
+ 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>\`."
101
+ fi
102
+
89
103
  # A branch switch in the same command is refused whole.
90
104
  #
91
105
  # The guard is a parse of the command BEFORE it runs: it runs the set in the tree that lies there
@@ -95,17 +109,26 @@ ${deny_tail_text}"
95
109
  # file that is not in the pushed branch at all — it was looking at the branch the same command was
96
110
  # leaving.
97
111
  #
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
112
+ # What is judged is a switch to another tree before the push. Creating a new branch from the current
113
+ # tip (`checkout -b`, `switch -c`) and restoring files do not fall here: the tree stays. A new
114
+ # branch from another start point does. A switch after the push changes nothing the set judged.
115
+ # The switch is found by the same parse as the push: a pattern over the line did not see
116
+ # `git checkout` inside `bash -c` or `eval`.
117
+ switched=false
118
+ printf '%s\n' "$push_calls" | awk '$0 == "switch" { s = 1 } / real$/ && s { f = 1 } END { exit !f }' && switched=true
119
+ if [ "$switched" = true ]; then
102
120
  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
121
  fi
104
122
 
105
123
  # Several pushes in one command, or a push inside a loop, are refused whole. The set runs once
106
124
  # 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
125
+ # A push after `done` or inside `if` is one push; a push in the body or the condition of a loop is
126
+ # not. Several recipients in one call are several pushes too, and the parse above names them.
127
+ looped=false
128
+ printf '%s\n' "$push_calls" | grep -q '^loop .* real$' && looped=true
129
+ several_refs=false
130
+ printf '%s\n' "$push_calls" | grep -q ' several real$' && several_refs=true
131
+ if [ "${pushes:-0}" -gt 1 ] || [ "$looped" = true ] || [ "$several_refs" = true ]; then
109
132
  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
133
  fi
111
134
 
@@ -145,10 +168,10 @@ fi
145
168
  # `_default` suffix. There is neither — the hook passes: an empty guard is better than a guard
146
169
  # that refuses at random.
147
170
  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
171
+ # The set itself is run by the code it shares with the git hook `pre-push`.
172
+ # shellcheck disable=SC1091
173
+ . "$rt_hooks_dir/push-set.sh" 2>/dev/null || exit 0
174
+ rt_push_set_profile "$rt_hooks_dir" "${CLAUDE_PROJECT_DIR:-.}"
152
175
 
153
176
  # A word about a missing profile function: a hook that exited silently is indistinguishable from a
154
177
  # working one. The file may not be laid out — then the former, silent behaviour stays.
@@ -180,55 +203,45 @@ if ! rt_needs rt_push_checks git-guard-push-tests; then
180
203
  exit 0
181
204
  fi
182
205
 
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}"
206
+ base="$(rt_push_set_base)"
195
207
 
196
208
  # Every red among the light checks is named by one refusal. The gate used to leave on the first red
197
209
  # 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
210
+ # branch — a repeated function, a name shared by two kits, a paint probe. A check with nothing to look
211
+ # at exits with the skip code: before, it said so by a line of output and exited with zero, and in the
212
+ # set that zero stood next to the passed ones and differed from them in nothing.
213
+ rt_push_set_ask_ahead=1
214
+ rt_push_set_run "$base"
215
+ failed="$rt_push_set_failed"
216
+ output="$rt_push_set_output"
217
+ skipped="$rt_push_set_skipped"
218
+ held="$rt_push_set_held"
219
+ ahead="$rt_push_set_ahead"
220
+ ran="$rt_push_set_ran"
221
+
222
+ # Heavy steps with no mark are named in one refusal together with the red light ones: the command
223
+ # that runs them ahead goes to the background, where no hook limit cuts it, and the push after it
224
+ # passes from the marks.
225
+ if [ -n "$ahead" ]; then
226
+ rt_push_gate_note ahead
227
+ ahead_cmd="bash ${rt_hooks_dir#"$PWD"/}/git-guard-push-ahead.sh"
228
+ dirty_line=""
229
+ rt_push_mark_clean || dirty_line="
230
+
231
+ The working copy holds edits outside the index: a mark is trusted only on a clean copy. Commit first."
232
+ red_line=""
233
+ [ -n "$failed" ] && red_line="
234
+
235
+ Red among the light checks:
236
+ ${failed}
237
+
238
+ $(printf '%s' "$output" | tr -d '\000')"
239
+ 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:
240
+
241
+ ${ahead}
242
+
243
+ 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}"
244
+ fi
232
245
 
233
246
  # What was skipped is named aloud even when the set passed: silence about it is exactly the
234
247
  # indistinguishability this code was created for. The push goes through at that — there is no
@@ -270,8 +283,13 @@ if [ ! -f "$gap_mark" ]; then
270
283
  : >"$gap_mark" 2>/dev/null || true
271
284
  fi
272
285
 
286
+ # A green set leaves the commit it judged in the mark of the shared git directory. The git hook
287
+ # `pre-push` runs the same set before every push, whatever sent it, and lets through a push of
288
+ # exactly this commit at once: the call this guard just let through would otherwise wait for the set
289
+ # twice. The mark is not written when every check was skipped or the copy has uncommitted edits.
273
290
  if [ -z "$failed" ]; then
274
291
  rt_push_gate_note green
292
+ rt_push_mark_write
275
293
  exit 0
276
294
  fi
277
295
 
@@ -71,7 +71,7 @@ rt_assignment_stale() {
71
71
  # a missing field and for `false`, that is, exactly for the state this refusal is written for.
72
72
  case "$(printf '%s' "$_state" | jq -r 'if .open == false then "false" else "" end' 2>/dev/null)" in
73
73
  false)
74
- fault "${_what} is not taken: the epic assigned to this copy is closed — the assignment outlived it. Ask the owner for a new one and write it into the table; an epic chosen instead of the closed one is not an order."
74
+ fault "${_what} is not taken: the epic assigned to this copy is closed — the assignment outlived it. Ask the owner for a new one and write it into the table; an epic chosen instead of the closed one is not an order. A message of the owner in this conversation that names this work is that new assignment: write the row with their words and go on; ask only when no message of theirs names it."
75
75
  ;;
76
76
  esac
77
77
  }
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env bash
2
+ # A part of the fourth sign of the conversation guard: after a refused menu a list of options in
3
+ # prose is a question too. NOT a guard: it has no `rt-hook:` declaration and hooks into no agent
4
+ # event. The conversation guard sources it — it was moved out when the guard crossed the file
5
+ # length limit.
6
+ #
7
+ # After a refused menu the executor gave the same options as a numbered list with no question mark
8
+ # and ended the turn: the sign knew prose only by «?», and the list went out as an ordinary reply.
9
+ # In a turn where the menu was refused, a numbered list of two or more items under a line ending
10
+ # with a colon is a question too. Outside such a turn a list is not judged: many ordinary reports
11
+ # carry one, and a refusal on each would teach to strip lists from replies.
12
+ #
13
+ # It expects `$transcript` and `$question_text` to be set; it returns zero when the turn ends with
14
+ # such a list after a refused menu, and non-zero otherwise.
15
+ #
16
+ # FAIL-OPEN: no turn record, no parser — the list is not a question.
17
+
18
+ rt_grill_options_asked() {
19
+ local menu_refused options_re
20
+ menu_refused="$(tail -n 400 "$transcript" 2>/dev/null | jq -s -r '
21
+ def is_input:
22
+ .type == "user"
23
+ and ((.isCompactSummary // false) | not)
24
+ and ((.isMeta // false) | not)
25
+ and (((.message.content // []) | if type == "array"
26
+ then ([.[] | select(.type == "tool_result")] | length)
27
+ else 0 end) == 0);
28
+ def asks_menu:
29
+ .type == "assistant" and ((.message.content // []) | any(.[];
30
+ .type == "tool_use" and .name == "AskUserQuestion"));
31
+ def refused:
32
+ .type == "user" and ((.message.content // []) | if type == "array"
33
+ then any(.[]; .type == "tool_result" and (.is_error // false))
34
+ else false end);
35
+ (map(is_input) | rindex(true)) as $i
36
+ | (if $i == null then . else .[$i + 1:] end) as $turn
37
+ | [range(0; ($turn | length) - 1) as $k
38
+ | select(($turn[$k] | asks_menu) and ($turn[$k + 1] | refused))]
39
+ | if length > 0 then "yes" else "no" end
40
+ ' 2>/dev/null)"
41
+ [ "$menu_refused" = "yes" ] || return 1
42
+
43
+ options_re='^[[:space:]]*[0-9]+[.)][[:space:]]'
44
+ printf '%s\n' "$question_text" | awk -v re="$options_re" '
45
+ /:[[:space:]]*$/ { lead = 1; items = 0; next }
46
+ lead && $0 ~ re { items++; if (items >= 2) found = 1; next }
47
+ lead && /^[[:space:]]*$/ { next }
48
+ { lead = 0; items = 0 }
49
+ END { exit found ? 0 : 1 }'
50
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bash
2
- # Requires: hooks/deny-tail.sh, hooks/turn-exit-patterns.sh, hooks/grill-gate-bypass.sh
2
+ # Requires: hooks/deny-tail.sh, hooks/turn-exit-patterns.sh, hooks/grill-gate-bypass.sh, hooks/grill-gate-options.sh
3
3
  # rt-hook: Stop
4
4
  # The conversation guard: the owner is not asked a question until the laws and rules have been read
5
5
  # within the same turn. It judges two events, and that is not duplication; the second is declared
@@ -388,11 +388,16 @@ if [ -n "$done_marker" ]; then
388
388
  | join("\n")
389
389
  ' 2>/dev/null)"
390
390
  fi
391
+ # After a refused menu a list of options in prose is a question too: the helper next door.
392
+ # shellcheck disable=SC1090
393
+ [ -f "$rt_hooks_dir/grill-gate-options.sh" ] && . "$rt_hooks_dir/grill-gate-options.sh" 2>/dev/null
391
394
  asks="no"
392
395
  if [ -n "$tool" ]; then
393
396
  asks="yes"
394
397
  elif printf '%s\n' "$question_text" | grep -qE '\?[[:space:]]*$'; then
395
398
  asks="yes"
399
+ elif command -v rt_grill_options_asked >/dev/null 2>&1 && rt_grill_options_asked; then
400
+ asks="yes"
396
401
  fi
397
402
  marked="no"
398
403
  case "$question_text" in
@@ -402,6 +407,9 @@ if [ -n "$done_marker" ]; then
402
407
  reason="BLOCKED by grill-gate: a guard refused in this turn, and the question to the owner carries nothing done without the answer.
403
408
 
404
409
  A refusal removes the step, not the task. Do the mechanical part of the blocker first — what the linter's fix mode repairs, what the refusal names as fixable — then ask only the decision that is left. The question leaves with the line «$done_marker …» naming the working commands of this turn after the last refusal: an edit of a file or a command that changes the tree. A read or a status command does not count."
410
+ [ -n "$tool" ] && reason="${reason}
411
+
412
+ The same question in prose does not walk around this refusal: the menu and prose are judged alike, a list of options included. Fix the menu — add the line and a working command — and send it again."
405
413
 
406
414
  # shellcheck disable=SC1090
407
415
  [ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env bash
2
+ # The checks before a push, as a hook of git itself, not of the agent.
3
+ #
4
+ # Requires: hooks/push-set.sh, hooks/git-guard-push-marks.sh
5
+ #
6
+ # NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The version control
7
+ # calls it before every push, whatever sent it: the session guard of the push stands only on the
8
+ # agent's tools, and a push from a terminal outside the session, from another session through
9
+ # `git -C` or from an environment without the agent hooks used to leave with no check at all. That
10
+ # is how a kit branch left from a foreign session and broke the kit's main branch.
11
+ #
12
+ # A versioned template: the git hooks directory of the working copy is not versioned, so the tree
13
+ # wires the file to git itself — by its hooks manager, or by hand. The hook stays where the layout
14
+ # put it, next to `push-set.sh`, and git calls it through a line that names it:
15
+ # printf '#!/bin/sh\nexec bash .claude/hooks/pre-push.sh "$@"\n' > .git/hooks/pre-push
16
+ # chmod +x .git/hooks/pre-push
17
+ #
18
+ # What it runs is the same set the session guard runs, by the same code in `push-set.sh`:
19
+ # `rt_push_checks <base>` from the package default and the tree profile, every red one named, a
20
+ # skipped one named apart, no heavy one started after a red one.
21
+ #
22
+ # A push the session guard already judged runs no second set. The guard writes the commit it found
23
+ # green into the mark `rt-kit-push-green` of the shared git directory, and a push of exactly that
24
+ # commit passes here at once: a second fifteen-minute run inside a session push would cut the
25
+ # session off. The mark is written only on a working copy without uncommitted edits.
26
+ #
27
+ # A dry run is judged like a real push: git calls the hook for `--dry-run` too and does not say so.
28
+ #
29
+ # The set judges the tree the working copy stands on, so the hook lets through only a push of that
30
+ # commit. A push of another branch, of a tag or of an older commit is refused: a green set would
31
+ # then read as a check of what left, though it checked something else. A deletion sends no tree
32
+ # and is not judged.
33
+ #
34
+ # The pipeline is its own gate: under `CI` the hook passes. A hooks manager installs the hook on
35
+ # the runner too, and the pipeline's own pushes would wait for the whole set there.
36
+ #
37
+ # FAIL-OPEN: not a repository, no file `push-set.sh`, no profile or no `rt_push_checks`, an empty
38
+ # set, under `CI` — pass.
39
+
40
+ . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
41
+
42
+ [ -n "${CI:-}" ] && exit 0
43
+
44
+ repo_root="$(git rev-parse --show-toplevel 2>/dev/null)" || exit 0
45
+ cd "$repo_root" 2>/dev/null || exit 0
46
+
47
+ tip="$(git rev-parse --verify --quiet HEAD 2>/dev/null)"
48
+
49
+ # The refs being pushed come on the input, a line each: local ref, local sha, remote ref, remote
50
+ # sha. What is judged is the commit each one sends. A deletion comes with a sha of zeros only, of
51
+ # any length; a real commit that merely starts with zeros is judged like any other.
52
+ sends=0
53
+ foreign=""
54
+ while read -r local_ref local_sha _remote_ref _remote_sha; do
55
+ [ -z "$local_sha" ] && continue
56
+ [ -z "$(printf '%s' "$local_sha" | tr -d 0)" ] && continue
57
+ sends=$((sends + 1))
58
+ commit="$(git rev-parse --verify --quiet "${local_sha}^{commit}" 2>/dev/null)"
59
+ [ -n "$commit" ] && [ "$commit" = "$tip" ] && continue
60
+ foreign="${foreign}${foreign:+
61
+ } ${local_ref}"
62
+ done
63
+
64
+ [ "$sends" -eq 0 ] && exit 0
65
+
66
+ if [ -n "$foreign" ]; then
67
+ printf '%s\n' "pre-push: refused — the push sends a commit the working copy does not stand on:" >&2
68
+ printf '%s\n' "$foreign" >&2
69
+ printf '%s\n' "The checks run on the tree that lies here, so they would judge something else than what leaves. Switch to the branch and push it from there, one branch per push." >&2
70
+ exit 1
71
+ fi
72
+
73
+ hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
74
+ # shellcheck disable=SC1091
75
+ if ! . "$hooks_dir/push-set.sh" 2>/dev/null; then
76
+ printf '%s\n' "pre-push: no file push-set.sh next to the hook in ${hooks_dir} — no check ran. The hook is called where the layout put it, not copied away from it." >&2
77
+ exit 0
78
+ fi
79
+
80
+ rt_push_mark_covers "$tip" && exit 0
81
+
82
+ # The root is this repository's, whatever the caller exported: a push through `git -C` from a session
83
+ # of another copy carries that copy's root, and the profile would read its files instead.
84
+ rt_push_set_profile "$hooks_dir" "$repo_root"
85
+ command -v rt_push_checks >/dev/null 2>&1 || exit 0
86
+
87
+ base="$(rt_push_set_base)"
88
+ total="$(rt_push_checks "$base" | grep -c .)"
89
+ [ "${total:-0}" -eq 0 ] && exit 0
90
+
91
+ printf 'pre-push: running the checks before the push, %s of them\n' "$total" >&2
92
+
93
+ rt_push_set_run "$base"
94
+
95
+ [ -n "$rt_push_set_skipped" ] && printf 'pre-push: these checks had nothing to look at:\n%s\n' "$rt_push_set_skipped" >&2
96
+
97
+ if [ -z "$rt_push_set_failed" ]; then
98
+ if [ "$rt_push_set_passed" -eq 0 ]; then
99
+ printf '%s\n' "pre-push: no check of the set judged the tree — the push passes, and no mark of green is written." >&2
100
+ fi
101
+ rt_push_mark_write
102
+ exit 0
103
+ fi
104
+
105
+ held_line=""
106
+ [ -n "$rt_push_set_held" ] && held_line="
107
+
108
+ Not started after the red ones — heavy, and the push is refused anyway:
109
+ ${rt_push_set_held}"
110
+
111
+ printf '\npre-push: refused — red checks: %s\n%s%s\n\nThe tail of every red output:\n\n%s\n' \
112
+ "$(printf '%s\n' "$rt_push_set_failed" | grep -c .)" "$rt_push_set_failed" "$held_line" "$rt_push_set_output" >&2
113
+ exit 1