@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
package/assets/hooks/dispatch.sh
CHANGED
|
@@ -141,11 +141,64 @@ EOF
|
|
|
141
141
|
exit 0
|
|
142
142
|
fi
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
# Each answer is kept apart, as a JSON string per line: glued together, two objects are no longer
|
|
145
|
+
# one answer, and the merge at the end needs to know where one ends.
|
|
146
|
+
if [ -n "$branch_out" ]; then
|
|
147
|
+
answers="${answers:-}$(printf '%s' "$branch_out" | jq -Rsc . 2>/dev/null)
|
|
145
148
|
"
|
|
149
|
+
collected="${collected}${branch_out}
|
|
150
|
+
"
|
|
151
|
+
count=$((${count:-0} + 1))
|
|
152
|
+
fi
|
|
146
153
|
done
|
|
147
154
|
|
|
148
|
-
#
|
|
149
|
-
|
|
155
|
+
# The answers of several branches are merged into one object. Objects printed one after another are
|
|
156
|
+
# no longer one answer: the agent read them as raw text, and the laws and the handover of a session
|
|
157
|
+
# start arrived cut. The texts of the context and of the system message are joined by an empty line,
|
|
158
|
+
# the plain text of a branch goes into the context, the other fields are taken in the order of the
|
|
159
|
+
# branches. An event without a context field keeps the text in the system message.
|
|
160
|
+
rt_dispatch_merge() {
|
|
161
|
+
case "$event" in
|
|
162
|
+
SessionStart | UserPromptSubmit | PreToolUse | PostToolUse) with_context=true ;;
|
|
163
|
+
*) with_context=false ;;
|
|
164
|
+
esac
|
|
165
|
+
printf '%s' "$answers" | jq -sc --arg ev "$event" --argjson ctx "$with_context" '
|
|
166
|
+
map(. as $s | (try ($s | fromjson) catch null) as $j
|
|
167
|
+
| if ($j | type) == "object" then {obj: $j} else {text: ($s | sub("\\s+$"; ""))} end)
|
|
168
|
+
| [.[] | .obj // empty] as $objs
|
|
169
|
+
| ([$objs[] | .hookSpecificOutput.additionalContext // empty]
|
|
170
|
+
+ [.[] | .text // empty | select(length > 0)]) as $texts
|
|
171
|
+
| [$objs[] | .systemMessage // empty] as $sys
|
|
172
|
+
| (reduce $objs[] as $o ({};
|
|
173
|
+
. * ($o | del(.systemMessage)
|
|
174
|
+
| if (.hookSpecificOutput | type) == "object"
|
|
175
|
+
then .hookSpecificOutput |= del(.additionalContext) else . end))) as $base
|
|
176
|
+
| if $ctx then
|
|
177
|
+
$base
|
|
178
|
+
| if ($texts | length) > 0 then
|
|
179
|
+
.hookSpecificOutput = ((.hookSpecificOutput // {})
|
|
180
|
+
+ {hookEventName: $ev, additionalContext: ($texts | join("\n\n"))})
|
|
181
|
+
else . end
|
|
182
|
+
| if ($sys | length) > 0 then .systemMessage = ($sys | join("\n\n")) else . end
|
|
183
|
+
else
|
|
184
|
+
($base | del(.hookSpecificOutput))
|
|
185
|
+
| if (($sys + $texts) | length) > 0 then .systemMessage = (($sys + $texts) | join("\n\n"))
|
|
186
|
+
else . end
|
|
187
|
+
end
|
|
188
|
+
' 2>/dev/null
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
# Not one branch refused: what they printed is given out — hints and digests. A single answer goes
|
|
192
|
+
# out as it is; where the merge has no parser, the former glued output is better than silence.
|
|
193
|
+
if [ "${count:-0}" -gt 1 ]; then
|
|
194
|
+
merged="$(rt_dispatch_merge)"
|
|
195
|
+
if [ -n "$merged" ]; then
|
|
196
|
+
printf '%s\n' "$merged"
|
|
197
|
+
else
|
|
198
|
+
printf '%s' "$collected"
|
|
199
|
+
fi
|
|
200
|
+
elif [ -n "${collected:-}" ]; then
|
|
201
|
+
printf '%s' "$collected"
|
|
202
|
+
fi
|
|
150
203
|
|
|
151
204
|
exit 0
|
|
@@ -258,6 +258,6 @@ case "$verdict" in
|
|
|
258
258
|
deny "BLOCKED by exam-guard: the exam on the loaded rules is failed. Read the rule whole again — not the piece that was asked about — and call the role strict-teacher anew. The answer shown gives knowledge of one line, not of the rule. The way out through the list of switched-off roles requires removing the protection, and the runtime may forbid such an edit; the second way out does not require it — the bypass is declared by the line «Exam-skip: причина» in the body of the last commit of the branch."
|
|
259
259
|
;;
|
|
260
260
|
*)
|
|
261
|
-
deny "BLOCKED by exam-guard: there was no exam on the loaded rules in this session. Call the role strict-teacher, hand it the list of loaded rules, answer its questions from memory and return the answers to it — the verdict it gives by the line «ЭКЗАМЕН: сдано N из 5». It counts from the answer of the role in whatever form the host delivered it, but not from the output of the shell and not from your own text: printing that line as an echo does not release the guard. The role was already called and the verdict received — then it arrived in a form the guard does not see: that is a defect of the guard, and an edit of
|
|
261
|
+
deny "BLOCKED by exam-guard: there was no exam on the loaded rules in this session. Call the role strict-teacher, hand it the list of loaded rules, answer its questions from memory and return the answers to it — the verdict it gives by the line «ЭКЗАМЕН: сдано N из 5». It counts from the answer of the role in whatever form the host delivered it, but not from the output of the shell and not from your own text: printing that line as an echo does not release the guard. The role was already called and the verdict received — then it arrived in a form the guard does not see: that is a defect of the guard, and an edit of «.claude/rt-kit.json» is taken out from under it. A loaded rule and a read rule are different things, and the price of that difference is paid by the owner."
|
|
262
262
|
;;
|
|
263
263
|
esac
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# The body of a PR being opened, for the delivery guard: the section about the remaining step
|
|
3
|
-
# line that closes the task.
|
|
2
|
+
# The body of a PR being opened, for the delivery guard: the section about the remaining step, the
|
|
3
|
+
# table of points and the line that closes the task.
|
|
4
4
|
#
|
|
5
5
|
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The delivery guard
|
|
6
6
|
# sources it — one tier of its verdict, moved out when the guard reached its length limit. It uses
|
|
@@ -15,7 +15,9 @@ rt_delivery_pull_body() {
|
|
|
15
15
|
# without a body is checked by the guard elsewhere. The flag is recognised only as a separate
|
|
16
16
|
# word: the tail `-b` of a branch name in the base argument read as the body flag, and the next
|
|
17
17
|
# word of the command became the body.
|
|
18
|
-
|
|
18
|
+
local pull_goal_section="${RT_PULL_GOAL_SECTION:-}"
|
|
19
|
+
[ -z "$pull_body_section" ] && [ -z "$pull_points_section" ] && [ -z "$pull_goal_section" ] \
|
|
20
|
+
&& [ -z "$pull_closes_line" ] && return 0
|
|
19
21
|
command -v perl >/dev/null 2>&1 || return 0
|
|
20
22
|
|
|
21
23
|
local body body_file closes
|
|
@@ -38,6 +40,26 @@ rt_delivery_pull_body() {
|
|
|
38
40
|
fault "the body of the request carries no section about the remaining step. The merge button is pressed by a person on the hosting, where there are no guards, and they merge as soon as they see green: all that holds the requirement there is what the owner read on the page. The section stands last and says exactly one thing — whether anything is left before the merge; it is rewritten by the same call that edits the body."
|
|
39
41
|
fi
|
|
40
42
|
|
|
43
|
+
# The table of points: without it the owner learns whether the work reached its point only after
|
|
44
|
+
# the merge. The guard sees the heading, not whether the signs were run.
|
|
45
|
+
if [ -n "$pull_points_section" ] && ! printf '%s' "$body" | grep -qE "$pull_points_section"; then
|
|
46
|
+
fault "the body of the request carries no section with the table of points. The owner decides on the request page whether the work reached its point. Run the role product-strategist and put its table of points into the body; a sign not run is written as not run."
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# The table of the critic: the session's own points prove nothing about what the owner asked for.
|
|
50
|
+
# A heading alone is not a table: a header, a divider and one row make three lines.
|
|
51
|
+
if [ -n "$pull_goal_section" ]; then
|
|
52
|
+
local goal_rows
|
|
53
|
+
goal_rows="$(printf '%s\n' "$body" | awk -v head="$pull_goal_section" '
|
|
54
|
+
$0 ~ head { inside = 1; next }
|
|
55
|
+
/^## / { inside = 0 }
|
|
56
|
+
inside && /^\|/ { rows++ }
|
|
57
|
+
END { print rows + 0 }
|
|
58
|
+
')"
|
|
59
|
+
[ "$goal_rows" -ge 3 ] \
|
|
60
|
+
|| fault "the body of the request carries no section with the table of the critic. Give the role goal-critic the owner's words verbatim and the result, and put its table into the body word for word."
|
|
61
|
+
fi
|
|
62
|
+
|
|
41
63
|
# The line that closes the task. Without it the merged task stays open on the board, and the
|
|
42
64
|
# work queue audit names that only after the merge — three PRs of one epic went out so, and the
|
|
43
65
|
# owner closed their tasks by hand. The number is the branch's, not the one the executor
|
|
@@ -68,9 +68,15 @@ rt_delivery_open_folder() {
|
|
|
68
68
|
return 0
|
|
69
69
|
fi
|
|
70
70
|
|
|
71
|
-
[ -n "$archive_dir" ] || return 0
|
|
72
71
|
_base="$(git merge-base "$main_branch" HEAD 2>/dev/null)"
|
|
73
72
|
[ -z "$_base" ] && return 0
|
|
73
|
+
|
|
74
|
+
# SC-AK-1249: the draft the plan named, still lying in the branch, would reach main unmerged.
|
|
75
|
+
_draft="$(rt_branch_plan_draft "$_folder" "$_base")"
|
|
76
|
+
[ -n "$_draft" ] && [ -n "$(git ls-tree -d --name-only HEAD -- "${_draft%/}" 2>/dev/null)" ] \
|
|
77
|
+
&& fault "the branch carries the unmerged agreement «${_draft}» its plan named — merge its rules and scenarios into the domain spec, remove the directory by a commit and repeat. If the work is merged in parts, put the comment «# Task-folder-skip: <reason>» into the command."
|
|
78
|
+
|
|
79
|
+
[ -n "$archive_dir" ] || return 0
|
|
74
80
|
rt_folder_was_in_branch "$_base" "$_folder" || return 0
|
|
75
81
|
|
|
76
82
|
_gained="$(git diff --name-only --diff-filter=A "$_base" HEAD -- "$archive_dir" 2>/dev/null | head -1)"
|
|
@@ -78,6 +84,16 @@ rt_delivery_open_folder() {
|
|
|
78
84
|
&& fault "the task folder was deleted, but the branch added nothing to «${archive_dir}». Deleting is cheaper than taking apart — and together with the folder the analysis of the request is gone, the only record of the words of the owner. Move what explains the decisions taken as one file with a telling name and repeat."
|
|
79
85
|
}
|
|
80
86
|
|
|
87
|
+
# The draft agreement the plan of the branch named by the line `**Draft:** \`path\``. The plan is
|
|
88
|
+
# read from the history: by the time the PR opens the folder is taken apart, and the last commit
|
|
89
|
+
# touching the plan is the one that removed it — then its parent still holds the plan.
|
|
90
|
+
rt_branch_plan_draft() {
|
|
91
|
+
_commit="$(git log -1 --format=%H "$2..HEAD" -- "$1/plan.md" 2>/dev/null)"
|
|
92
|
+
[ -n "$_commit" ] || return 0
|
|
93
|
+
{ git show "$_commit:$1/plan.md" 2>/dev/null || git show "$_commit^:$1/plan.md" 2>/dev/null; } \
|
|
94
|
+
| sed -nE 's/^\*\*Draft:\*\*[[:space:]]*`([^`]+)`.*/\1/p' | head -1
|
|
95
|
+
}
|
|
96
|
+
|
|
81
97
|
# Condition for leaving draft: the same subject between opening and merging. The owner reads a PR
|
|
82
98
|
# out of draft as an invitation to merge, and presses the button without waiting for the cleanup
|
|
83
99
|
# commit: the merge guard does not reach here at all — a person on the hosting presses it. Three
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# A draft on a base the pipeline does not wake for, for the delivery guard. NOT a guard: it has no
|
|
3
|
+
# `rt-hook:` declaration and hooks into no agent event. The delivery guard sources it and calls
|
|
4
|
+
# `rt_delivery_pull_draft` with the command text on a PR opening.
|
|
5
|
+
#
|
|
6
|
+
# A draft waits for a run. Where no run comes it waits for nothing, and the owner sees a locked
|
|
7
|
+
# merge button and a PR that reads as unfinished: one such draft stood half an hour waiting for a
|
|
8
|
+
# check that would never start. The rule said so in words; nothing held it.
|
|
9
|
+
#
|
|
10
|
+
# The bases are read from the pipeline file the tree already named for the push gate, not from a
|
|
11
|
+
# list of their own: a second list drifts from the file the first day the trigger changes.
|
|
12
|
+
#
|
|
13
|
+
# FAIL-OPEN: no settings, no pipeline file, a trigger without a branch filter, a pipeline of another
|
|
14
|
+
# host — not judged. A wrong refusal here would forbid a lawful draft, and silence costs half an hour.
|
|
15
|
+
|
|
16
|
+
# The pipeline file the tree named. Printed empty where there is none.
|
|
17
|
+
rt_pipeline_file() {
|
|
18
|
+
local settings="${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/checks.json" file
|
|
19
|
+
[ -f "$settings" ] || return 0
|
|
20
|
+
file="$(jq -r '.pushGate.pipelineFile // empty' "$settings" 2>/dev/null)"
|
|
21
|
+
[ -n "$file" ] && [ -f "${CLAUDE_PROJECT_DIR:-.}/$file" ] && printf '%s' "${CLAUDE_PROJECT_DIR:-.}/$file"
|
|
22
|
+
return 0
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# The branch patterns of the `pull_request` trigger, one per line. Prints nothing where the trigger
|
|
26
|
+
# has no such list: then the pipeline wakes for every base, or the file is of another host. Both the
|
|
27
|
+
# list form and the inline form are read; `branches-ignore` and `pull_request_target` are not.
|
|
28
|
+
rt_pipeline_pull_bases() {
|
|
29
|
+
awk '
|
|
30
|
+
function indent(line) { match(line, /^ */); return RLENGTH }
|
|
31
|
+
function clean(word) {
|
|
32
|
+
sub(/[[:space:]]*#.*$/, "", word)
|
|
33
|
+
gsub(/^[[:space:]"\047]+|[[:space:]"\047]+$/, "", word)
|
|
34
|
+
return word
|
|
35
|
+
}
|
|
36
|
+
!trigger {
|
|
37
|
+
if ($0 ~ /^[[:space:]]*pull_request:[[:space:]]*(#.*)?$/) { trigger = 1; trigger_at = indent($0) }
|
|
38
|
+
next
|
|
39
|
+
}
|
|
40
|
+
/^[[:space:]]*(#.*)?$/ { next }
|
|
41
|
+
indent($0) <= trigger_at { exit }
|
|
42
|
+
!list {
|
|
43
|
+
if ($0 ~ /^[[:space:]]*branches:/) {
|
|
44
|
+
line = $0
|
|
45
|
+
sub(/^[[:space:]]*branches:[[:space:]]*/, "", line)
|
|
46
|
+
if (line ~ /^\[/) {
|
|
47
|
+
gsub(/[][]/, "", line)
|
|
48
|
+
count = split(line, words, ",")
|
|
49
|
+
for (i = 1; i <= count; i++) if (clean(words[i]) != "") print clean(words[i])
|
|
50
|
+
exit
|
|
51
|
+
}
|
|
52
|
+
list = 1
|
|
53
|
+
list_at = indent($0)
|
|
54
|
+
}
|
|
55
|
+
next
|
|
56
|
+
}
|
|
57
|
+
indent($0) <= list_at && $0 !~ /^[[:space:]]*-/ { exit }
|
|
58
|
+
/^[[:space:]]*-/ { line = $0; sub(/^[[:space:]]*-[[:space:]]*/, "", line); print clean(line) }
|
|
59
|
+
' "$1" 2>/dev/null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Quoted text is cut first: a title may mention the flag.
|
|
63
|
+
rt_pull_asks_draft() {
|
|
64
|
+
printf '%s' "$1" | sed -E "s/\"[^\"]*\"//g; s/'[^']*'//g" \
|
|
65
|
+
| grep -qE '(^|[[:space:]])(--draft(=true)?|-d)([[:space:]]|$)'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
rt_delivery_pull_draft() {
|
|
69
|
+
local command_text="$1" file bases base pattern
|
|
70
|
+
rt_pull_asks_draft "$command_text" || return 0
|
|
71
|
+
|
|
72
|
+
file="$(rt_pipeline_file)"
|
|
73
|
+
[ -n "$file" ] || return 0
|
|
74
|
+
bases="$(rt_pipeline_pull_bases "$file")"
|
|
75
|
+
[ -n "$bases" ] || return 0
|
|
76
|
+
|
|
77
|
+
# The base named by the command. Absent — the host takes the default branch.
|
|
78
|
+
base=''
|
|
79
|
+
if command -v perl >/dev/null 2>&1; then
|
|
80
|
+
base="$(printf '%s' "$command_text" | perl -0ne '
|
|
81
|
+
if (/(?:^|\s)(?:--base|-B)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
82
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
83
|
+
}
|
|
84
|
+
' 2>/dev/null)"
|
|
85
|
+
fi
|
|
86
|
+
base="${base:-${main_branch:-main}}"
|
|
87
|
+
|
|
88
|
+
while IFS= read -r pattern; do
|
|
89
|
+
[ -z "$pattern" ] && continue
|
|
90
|
+
# shellcheck disable=SC2254
|
|
91
|
+
case "$base" in
|
|
92
|
+
$pattern) return 0 ;;
|
|
93
|
+
esac
|
|
94
|
+
done <<EOF
|
|
95
|
+
$bases
|
|
96
|
+
EOF
|
|
97
|
+
|
|
98
|
+
fault "a draft into «${base}»: the pipeline «${file##*/}» wakes for a request only into $(printf '%s' "$bases" | tr '\n' ' ' | sed 's/ $//'), so no run will come and the draft will wait for nothing. Open the request ready, without --draft, and set the reviewer in the same call."
|
|
99
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
|
|
3
|
-
# Requires: hooks/git-guard-delivery-merged.sh, hooks/git-guard-delivery-folder.sh,hooks/git-guard-delivery-epic.sh, hooks/git-guard-tree-assignment.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
|
|
3
|
+
# Requires: hooks/git-guard-delivery-merged.sh, hooks/git-guard-delivery-folder.sh,hooks/git-guard-delivery-epic.sh, hooks/git-guard-delivery-pipeline.sh, hooks/git-guard-tree-assignment.sh, hooks/git-guard-delivery-conflict.sh, hooks/profile-check.sh, hooks/deny-tail.sh, hooks/guard-note.sh
|
|
4
4
|
# Delivery guard. PreToolUse on creating a branch, on the push and on opening a PR.
|
|
5
5
|
#
|
|
6
6
|
# The delivery law demands three things nothing usually checks: an edit starts from a task visible
|
|
@@ -117,6 +117,7 @@ pull_token_hint="${RT_PULL_TOKEN_HINT:-}"
|
|
|
117
117
|
# the pattern is named by the tree, not by the package: the package does not know someone else's
|
|
118
118
|
# words, and an invented default would match nothing.
|
|
119
119
|
pull_body_section="${RT_PULL_BODY_SECTION:-}"
|
|
120
|
+
pull_points_section="${RT_PULL_POINTS_SECTION:-}"
|
|
120
121
|
# The line that closes the task on the merge, with `{number}` in place of the task number. Its keyword
|
|
121
122
|
# belongs to the hosting, so the sample is named by the tree, as the section above.
|
|
122
123
|
pull_closes_line="${RT_PULL_CLOSES_LINE:-}"
|
|
@@ -298,9 +299,16 @@ if [ -n "$branch_arg" ]; then
|
|
|
298
299
|
# The signature: the address of the machine account is declared by the tree, and the working
|
|
299
300
|
# copy does not know it — which means the very first commit will travel under someone else's
|
|
300
301
|
# signature, and after the push that is fixed only by a force push.
|
|
302
|
+
#
|
|
303
|
+
# A person the tree named in RT_HUMAN_EMAILS signs with their own mail lawfully: the push
|
|
304
|
+
# accepts it, and refusing it here left such a person no way to start a branch at all.
|
|
301
305
|
if [ -n "$commit_email" ]; then
|
|
302
306
|
tree_email="$(git config user.email 2>/dev/null)"
|
|
303
|
-
|
|
307
|
+
human_email=''
|
|
308
|
+
for one in ${RT_HUMAN_EMAILS:-}; do
|
|
309
|
+
[ "$tree_email" = "$one" ] && human_email=1 && break
|
|
310
|
+
done
|
|
311
|
+
[ -n "$tree_email" ] && [ "$tree_email" != "$commit_email" ] && [ -z "$human_email" ] \
|
|
304
312
|
&& fault "the working copy signs commits as «${tree_email}», while the tree declared the email of the machine account «${commit_email}». The very first commit leaves under a foreign signature: git config user.email \"${commit_email}\"."
|
|
305
313
|
fi
|
|
306
314
|
|
|
@@ -315,27 +323,23 @@ fi
|
|
|
315
323
|
# the length limit, and the signature is the most separate of its subjects. No helper — the
|
|
316
324
|
# signature is not judged, and the work goes on: the same fail-open as with the other conditions.
|
|
317
325
|
# shellcheck disable=SC1090
|
|
318
|
-
[ -f "$rt_hooks_dir/git-guard-delivery-signature.sh" ]
|
|
319
|
-
&& . "$rt_hooks_dir/git-guard-delivery-signature.sh" 2>/dev/null
|
|
326
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-signature.sh" ] && . "$rt_hooks_dir/git-guard-delivery-signature.sh" 2>/dev/null
|
|
320
327
|
command -v rt_delivery_signature >/dev/null 2>&1 && rt_delivery_signature
|
|
321
328
|
|
|
322
329
|
# --- the push into a merged branch -----------------------------------------------------------
|
|
323
330
|
# The helper next door — `git-guard-delivery-merged.sh`. No helper — the push is not judged by it.
|
|
324
331
|
# shellcheck disable=SC1090
|
|
325
|
-
[ -f "$rt_hooks_dir/git-guard-delivery-merged.sh" ]
|
|
326
|
-
&& . "$rt_hooks_dir/git-guard-delivery-merged.sh" 2>/dev/null
|
|
332
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-merged.sh" ] && . "$rt_hooks_dir/git-guard-delivery-merged.sh" 2>/dev/null
|
|
327
333
|
command -v rt_delivery_merged >/dev/null 2>&1 && rt_delivery_merged
|
|
328
334
|
|
|
329
335
|
# --- leaving draft ---------------------------------------------------------------------------
|
|
330
336
|
# The subject lives in a helper next door — `git-guard-delivery-draft.sh`, by the same technique as
|
|
331
337
|
# the signature. No helper — leaving draft is not judged, and the work goes on.
|
|
332
338
|
# shellcheck disable=SC1090
|
|
333
|
-
[ -f "$rt_hooks_dir/git-guard-delivery-draft.sh" ]
|
|
334
|
-
&& . "$rt_hooks_dir/git-guard-delivery-draft.sh" 2>/dev/null
|
|
339
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-draft.sh" ] && . "$rt_hooks_dir/git-guard-delivery-draft.sh" 2>/dev/null
|
|
335
340
|
command -v rt_delivery_draft_ready >/dev/null 2>&1 && rt_delivery_draft_ready
|
|
336
341
|
|
|
337
342
|
# --- merging a PR --------------------------------------------------------------------------
|
|
338
|
-
#
|
|
339
343
|
# The second line of the same condition that stands at the opening of a PR: it catches a merge going
|
|
340
344
|
# by command. We look for the command from the start of the line or after a separator, not anywhere
|
|
341
345
|
# in the text. Otherwise the guard refuses a message where `gh pr merge` is merely mentioned in
|
|
@@ -404,9 +408,12 @@ if [ -n "$title" ]; then
|
|
|
404
408
|
fi
|
|
405
409
|
fi
|
|
406
410
|
|
|
411
|
+
# A draft into a base the pipeline does not wake for waits for nothing. No helper — not judged.
|
|
412
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-pipeline.sh" ] && . "$rt_hooks_dir/git-guard-delivery-pipeline.sh" 2>/dev/null
|
|
413
|
+
command -v rt_delivery_pull_draft >/dev/null 2>&1 && rt_delivery_pull_draft "$cmd"
|
|
414
|
+
|
|
407
415
|
# The main branch is merged in before the PR opens: otherwise the reviewer sees someone else's edit
|
|
408
416
|
# mixed in with his own, and the checks run from an outdated base.
|
|
409
|
-
#
|
|
410
417
|
# There are two tiers. The first reads the local tip and works without the network. The second asks
|
|
411
418
|
# the remote reference: without it, silence means only "the local reference is not older than the
|
|
412
419
|
# branch", while it reads as "the main branch is merged in". No answer from the network — a silent
|
|
@@ -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
|
|
11
|
-
#
|
|
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.
|
|
@@ -99,7 +99,20 @@ git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
|
|
|
99
99
|
branch="$(git branch --show-current 2>/dev/null)"
|
|
100
100
|
[ -z "$branch" ] && exit 0 # a detached HEAD is not about this case
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
# The name is read from the tree's own profile — the one the commit runs in — as the other delivery
|
|
103
|
+
# guards read it. Not through the package default: that one always says `main`, and a tree on
|
|
104
|
+
# `master` that named nothing would lose the guessing below. The profile is loaded in a subshell, so
|
|
105
|
+
# nothing it declares leaks into the guard.
|
|
106
|
+
top="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
107
|
+
declared="$(
|
|
108
|
+
# shellcheck disable=SC1090,SC1091
|
|
109
|
+
[ -n "$top" ] && [ -f "$top/.claude/rt-kit/project.sh" ] \
|
|
110
|
+
&& . "$top/.claude/rt-kit/project.sh" >/dev/null 2>&1 </dev/null
|
|
111
|
+
printf '%s' "${RT_MAIN_BRANCH:-}"
|
|
112
|
+
)"
|
|
113
|
+
|
|
114
|
+
default="$declared"
|
|
115
|
+
[ -z "$default" ] && default="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's#^origin/##')"
|
|
103
116
|
if [ -z "$default" ]; then
|
|
104
117
|
for candidate in main master; do
|
|
105
118
|
if git show-ref --verify --quiet "refs/remotes/origin/$candidate" 2>/dev/null; then
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
|
|
42
|
+
# A mark vouches for the tree of the head, and the checks run over the working copy: with edits
|
|
43
|
+
# outside the index the run would write marks for content that does not leave.
|
|
44
|
+
rt_push_mark_clean || {
|
|
45
|
+
printf 'push ahead: the working copy holds edits outside the index — commit first, the marks are written only for a clean copy\n' >&2
|
|
46
|
+
exit "$not_started"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
base="$(rt_push_base "${RT_MAIN_BRANCH:-main}")"
|
|
50
|
+
skip_code="${RT_SKIP_CODE:-7}"
|
|
51
|
+
printf 'push ahead: base %s, tree %s\n' "${base:-none}" "$(git rev-parse --short 'HEAD^{tree}')"
|
|
52
|
+
|
|
53
|
+
red=""
|
|
54
|
+
while IFS= read -r check; do
|
|
55
|
+
[ -z "$check" ] && continue
|
|
56
|
+
if rt_push_mark_has "$check" "$base"; then
|
|
57
|
+
printf '= green already: %s\n' "$check"
|
|
58
|
+
continue
|
|
59
|
+
fi
|
|
60
|
+
# After a red check a heavy one is not started: the push is refused anyway.
|
|
61
|
+
if [ -n "$red" ] && rt_push_check_heavy "$check"; then
|
|
62
|
+
printf '· held after red: %s\n' "$check"
|
|
63
|
+
continue
|
|
64
|
+
fi
|
|
65
|
+
key_before="$(rt_push_mark_key "$check" "$base")"
|
|
66
|
+
started="$(date +%s)"
|
|
67
|
+
out="$(eval "$check" 2>&1)"
|
|
68
|
+
status=$?
|
|
69
|
+
took=$(($(date +%s) - started))
|
|
70
|
+
if [ "$status" -eq 0 ]; then
|
|
71
|
+
rt_push_mark_put "$check" "$base" "$key_before"
|
|
72
|
+
printf '+ green in %ss: %s\n' "$took" "$check"
|
|
73
|
+
elif [ "$status" -eq "$skip_code" ]; then
|
|
74
|
+
printf '~ nothing to look at: %s\n' "$check"
|
|
75
|
+
else
|
|
76
|
+
red="${red}${red:+
|
|
77
|
+
}${check}"
|
|
78
|
+
printf '✗ red in %ss: %s\n%s\n' "$took" "$check" "$(printf '%s' "$out" | tail -n 25)"
|
|
79
|
+
fi
|
|
80
|
+
done <<EOF
|
|
81
|
+
$(rt_push_checks "$base")
|
|
82
|
+
EOF
|
|
83
|
+
|
|
84
|
+
if [ -n "$red" ]; then
|
|
85
|
+
printf '\npush ahead: red —\n%s\n' "$red"
|
|
86
|
+
exit 1
|
|
87
|
+
fi
|
|
88
|
+
printf '\npush ahead: the set is green, the push passes from the marks\n'
|
|
89
|
+
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
|
+
}
|