@rt-tools/agent-kit 0.33.1 → 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.
- package/README.md +8 -7
- package/assets/agents/goal-critic.md +67 -0
- package/assets/agents/product-strategist.md +90 -0
- package/assets/agents/qa-engineer.md +3 -0
- package/assets/checks/check-specs.mjs +11 -2
- package/assets/checks/rt-kit-checks.config.mjs +6 -0
- package/assets/checks/spec-common.mjs +6 -3
- package/assets/checks/spec-scenarios.mjs +9 -1
- package/assets/checks/task-new.github.mjs +6 -0
- package/assets/defaults/project.sh +10 -81
- package/assets/defaults/push.sh +100 -0
- package/assets/docs/GLOSSARY.md +4 -0
- package/assets/hooks/browser-guard-no-other-drivers.sh +6 -3
- package/assets/hooks/claim-guard.sh +6 -6
- package/assets/hooks/dispatch.sh +56 -3
- package/assets/hooks/exam-guard.sh +1 -1
- package/assets/hooks/git-guard-delivery-body.sh +25 -3
- package/assets/hooks/git-guard-delivery-folder.sh +17 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
- package/assets/hooks/git-guard-delivery.sh +17 -10
- package/assets/hooks/git-guard-main.sh +17 -4
- package/assets/hooks/git-guard-push-ahead.sh +89 -0
- package/assets/hooks/git-guard-push-marks.sh +99 -0
- package/assets/hooks/git-guard-push-tests.sh +101 -83
- package/assets/hooks/pre-push.sh +113 -0
- package/assets/hooks/push-set.sh +150 -0
- package/assets/hooks/push-sign.sh +433 -0
- package/assets/hooks/rerun-guard.sh +14 -6
- package/assets/hooks/turn-exit-guard.sh +2 -2
- package/assets/hooks/turn-exit-patterns.sh +4 -3
- package/assets/hooks/turn-exit-verdict.sh +18 -1
- package/assets/hooks/waiting-turn-guard.sh +2 -1
- package/assets/hooks/write-targets.sh +21 -0
- package/assets/patterns/git-workflow-commit.github.md +11 -0
- package/assets/patterns/git-workflow-pr-body.github.md +20 -3
- package/assets/patterns/git-workflow-pr.azure.md +30 -0
- package/assets/patterns/git-workflow-pr.github.md +57 -1
- package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
- package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
- package/assets/patterns/task-flow-close.md +27 -16
- package/assets/patterns/task-flow-start.md +3 -3
- package/assets/rules/browser-verification.md +4 -0
- package/assets/rules/deploy-flow.azure.md +5 -0
- package/assets/rules/deploy-flow.github.md +5 -0
- package/assets/rules/deploy-flow.gitlab.md +5 -0
- package/assets/rules/git-workflow.azure.md +15 -0
- package/assets/rules/git-workflow.github.md +15 -0
- package/assets/rules/git-workflow.gitlab.md +15 -0
- package/assets/rules/mockups.needs-mockups.md +13 -5
- package/assets/rules/task-flow.md +21 -16
- package/assets/samples/tasks/_template/plan.md +7 -0
- package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
- package/assets/skills/interface-review-icons.needs-app.md +136 -0
- package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
- package/assets/skills/interface-review-motion.needs-app.md +209 -0
- package/assets/skills/interface-review-performance.needs-app.md +110 -0
- package/assets/skills/interface-review-principles.needs-app.md +263 -0
- package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
- package/assets/skills/interface-review.needs-app.md +199 -0
- package/assets/skills/write-a-skill.md +16 -3
- package/assets/workflows/feature.js +33 -5
- package/assets/workflows/plan.js +71 -4
- package/package.json +1 -1
|
@@ -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.
|
|
25
|
-
#
|
|
26
|
-
#
|
|
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
|
-
#
|
|
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
|
|
43
|
-
|
|
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
|
-
#
|
|
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
|
-
|
|
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
|
|
99
|
-
#
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
108
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
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.
|
|
199
|
-
#
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
|
|
@@ -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
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The gate set before a push, one way for both who run it. NOT a guard: it has no `rt-hook:`
|
|
3
|
+
# declaration and hooks into no agent event. The session guard of the push and the git hook
|
|
4
|
+
# `pre-push` source it and call its functions.
|
|
5
|
+
#
|
|
6
|
+
# Two copies of the same loop drifted apart in their first week: the hook started the heavy checks
|
|
7
|
+
# after a red one, said nothing about a skipped check and wrote the mark of green when nothing had
|
|
8
|
+
# been checked at all. Here lives the single one.
|
|
9
|
+
#
|
|
10
|
+
# rt_push_set_profile <hooks dir> <tree root> — the package default and the tree override
|
|
11
|
+
# rt_push_set_base — the main branch of the remote, or empty
|
|
12
|
+
# rt_push_set_run <base> — every line of `rt_push_checks <base>`
|
|
13
|
+
# rt_push_mark_path / rt_push_mark_covers <commit> / rt_push_mark_write — the mark of green
|
|
14
|
+
#
|
|
15
|
+
# What `rt_push_set_run` found is left in the variables `rt_push_set_failed`, `_output`, `_skipped`,
|
|
16
|
+
# `_held` and `_ahead` (one check per line) and in the counters `rt_push_set_ran` and
|
|
17
|
+
# `rt_push_set_passed`.
|
|
18
|
+
|
|
19
|
+
# The tree profile: first the package default, over it the project override. A function declared in
|
|
20
|
+
# the override replaces the default whole and may call it back by the `_default` suffix. The root is
|
|
21
|
+
# exported, because the profile functions find the tree files by it: a root inherited from another
|
|
22
|
+
# session reads that session's tree, and the set comes out narrower without a word.
|
|
23
|
+
rt_push_set_profile() {
|
|
24
|
+
local hooks_dir="$1" root="$2" profile
|
|
25
|
+
export CLAUDE_PROJECT_DIR="$root"
|
|
26
|
+
for profile in "$hooks_dir/../rt-kit/defaults/project.sh" "$hooks_dir/../defaults/project.sh" \
|
|
27
|
+
"$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
|
+
# The base of a stacked branch and the marks of a green run. No helper — the base is the main
|
|
32
|
+
# branch, no mark is read and none is written: the set runs whole.
|
|
33
|
+
# shellcheck disable=SC1091
|
|
34
|
+
[ -f "$hooks_dir/git-guard-push-marks.sh" ] && . "$hooks_dir/git-guard-push-marks.sh" 2>/dev/null
|
|
35
|
+
command -v rt_push_mark_has >/dev/null 2>&1 || rt_push_mark_has() { return 1; }
|
|
36
|
+
command -v rt_push_mark_put >/dev/null 2>&1 || rt_push_mark_put() { return 0; }
|
|
37
|
+
command -v rt_push_mark_clean >/dev/null 2>&1 || rt_push_mark_clean() { return 1; }
|
|
38
|
+
command -v rt_push_mark_key >/dev/null 2>&1 || rt_push_mark_key() { return 1; }
|
|
39
|
+
command -v rt_push_heavy_ahead >/dev/null 2>&1 || rt_push_heavy_ahead() { return 1; }
|
|
40
|
+
return 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
rt_push_set_base() {
|
|
44
|
+
local main_branch="${RT_MAIN_BRANCH:-main}"
|
|
45
|
+
if command -v rt_push_base >/dev/null 2>&1; then
|
|
46
|
+
rt_push_base "$main_branch"
|
|
47
|
+
return 0
|
|
48
|
+
fi
|
|
49
|
+
if git fetch --quiet origin "$main_branch" 2>/dev/null && git rev-parse --verify --quiet "origin/$main_branch" >/dev/null 2>&1; then
|
|
50
|
+
printf 'origin/%s' "$main_branch"
|
|
51
|
+
fi
|
|
52
|
+
return 0
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Every red among the light checks is named by one refusal. After the first red a heavy check is not
|
|
56
|
+
# started: the push is refused anyway, and its minutes buy nothing.
|
|
57
|
+
#
|
|
58
|
+
# The code by which a check declares that there was nothing to look at does not refuse the push, and
|
|
59
|
+
# it is counted apart from a passed one. A skip code of 0 or 1 is no skip code: 1 is the exit of any
|
|
60
|
+
# failure, and every red check would read as skipped.
|
|
61
|
+
#
|
|
62
|
+
# A check green on this very tree against this very base is not run again. A caller under the hook
|
|
63
|
+
# limit sets `rt_push_set_ask_ahead=1`: in a tree that runs its heavy steps ahead such a step is then
|
|
64
|
+
# named in `rt_push_set_ahead` instead of being started. The git hook has no such limit, leaves the
|
|
65
|
+
# variable empty and runs the step itself.
|
|
66
|
+
rt_push_set_run() {
|
|
67
|
+
local base="$1" check out status key_before skip_code="${RT_SKIP_CODE:-7}"
|
|
68
|
+
case "$skip_code" in '' | 0 | 1 | *[!0-9]*) skip_code=7 ;; esac
|
|
69
|
+
command -v rt_push_check_heavy >/dev/null 2>&1 || rt_push_check_heavy() { return 1; }
|
|
70
|
+
|
|
71
|
+
rt_push_set_failed=""
|
|
72
|
+
rt_push_set_output=""
|
|
73
|
+
rt_push_set_skipped=""
|
|
74
|
+
rt_push_set_held=""
|
|
75
|
+
rt_push_set_ahead=""
|
|
76
|
+
rt_push_set_ran=0
|
|
77
|
+
rt_push_set_passed=0
|
|
78
|
+
while IFS= read -r check; do
|
|
79
|
+
[ -z "$check" ] && continue
|
|
80
|
+
if rt_push_mark_has "$check" "$base"; then
|
|
81
|
+
rt_push_set_ran=$((rt_push_set_ran + 1))
|
|
82
|
+
rt_push_set_passed=$((rt_push_set_passed + 1))
|
|
83
|
+
continue
|
|
84
|
+
fi
|
|
85
|
+
if [ "${rt_push_set_ask_ahead:-}" = 1 ] && rt_push_heavy_ahead && rt_push_check_heavy "$check"; then
|
|
86
|
+
rt_push_set_ahead="${rt_push_set_ahead}${rt_push_set_ahead:+
|
|
87
|
+
}${check}"
|
|
88
|
+
continue
|
|
89
|
+
fi
|
|
90
|
+
if [ -n "$rt_push_set_failed" ] && rt_push_check_heavy "$check"; then
|
|
91
|
+
rt_push_set_held="${rt_push_set_held}${rt_push_set_held:+
|
|
92
|
+
}${check}"
|
|
93
|
+
continue
|
|
94
|
+
fi
|
|
95
|
+
rt_push_set_ran=$((rt_push_set_ran + 1))
|
|
96
|
+
key_before=""
|
|
97
|
+
rt_push_mark_clean && key_before="$(rt_push_mark_key "$check" "$base" 2>/dev/null)"
|
|
98
|
+
out="$(eval "$check" 2>&1 </dev/null)"
|
|
99
|
+
status=$?
|
|
100
|
+
if [ "$status" -eq 0 ]; then
|
|
101
|
+
rt_push_set_passed=$((rt_push_set_passed + 1))
|
|
102
|
+
rt_push_mark_put "$check" "$base" "$key_before"
|
|
103
|
+
continue
|
|
104
|
+
fi
|
|
105
|
+
if [ "$status" -eq "$skip_code" ]; then
|
|
106
|
+
rt_push_set_skipped="${rt_push_set_skipped}${rt_push_set_skipped:+
|
|
107
|
+
}${check}"
|
|
108
|
+
continue
|
|
109
|
+
fi
|
|
110
|
+
rt_push_set_failed="${rt_push_set_failed}${rt_push_set_failed:+
|
|
111
|
+
}${check}"
|
|
112
|
+
rt_push_set_output="${rt_push_set_output}${rt_push_set_output:+
|
|
113
|
+
|
|
114
|
+
}── ${check}
|
|
115
|
+
$(printf '%s' "$out" | tail -n 25)"
|
|
116
|
+
done <<EOF
|
|
117
|
+
$(rt_push_checks "$base")
|
|
118
|
+
EOF
|
|
119
|
+
return 0
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# The mark of green: the commit a green set judged, one line. It lies in the shared git directory, not
|
|
123
|
+
# in that of a working copy: a push from a session through `git -C` into a second copy would
|
|
124
|
+
# otherwise not see the mark the guard just wrote and run the set a second time.
|
|
125
|
+
rt_push_mark_path() {
|
|
126
|
+
local common
|
|
127
|
+
common="$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" || return 0
|
|
128
|
+
[ -n "$common" ] && printf '%s/rt-kit-push-green' "$common"
|
|
129
|
+
return 0
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
rt_push_mark_covers() {
|
|
133
|
+
local commit="$1" mark
|
|
134
|
+
mark="$(rt_push_mark_path)"
|
|
135
|
+
[ -n "$commit" ] && [ -n "$mark" ] && [ -f "$mark" ] && [ "$(head -n 1 "$mark" 2>/dev/null)" = "$commit" ]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# The mark is written only for a set that judged the commit itself. A set where every check was
|
|
139
|
+
# skipped judged nothing. A working copy with uncommitted edits to tracked files was judged
|
|
140
|
+
# together with them, so the commit alone was never judged. Files outside the history do not count:
|
|
141
|
+
# a working copy keeps folders of other tasks, and the mark would never be written.
|
|
142
|
+
rt_push_mark_write() {
|
|
143
|
+
local mark tip
|
|
144
|
+
[ "${rt_push_set_passed:-0}" -gt 0 ] || return 0
|
|
145
|
+
[ -z "$(git status --porcelain --untracked-files=no 2>/dev/null)" ] || return 0
|
|
146
|
+
mark="$(rt_push_mark_path)"
|
|
147
|
+
tip="$(git rev-parse --verify --quiet HEAD 2>/dev/null)"
|
|
148
|
+
[ -n "$mark" ] && [ -n "$tip" ] && printf '%s\n' "$tip" >"$mark" 2>/dev/null
|
|
149
|
+
return 0
|
|
150
|
+
}
|