@rt-tools/agent-kit 0.27.0 → 0.28.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/assets/checks/board-epic-plan.github.mjs +86 -0
- package/assets/checks/board-epics.github.mjs +12 -67
- package/assets/checks/board-pull-state.github.mjs +6 -11
- package/assets/checks/check-glossary.mjs +10 -2
- package/assets/checks/check-lib-layers.mjs +24 -1
- package/assets/checks/check-reuse.mjs +26 -2
- package/assets/checks/check-specs.mjs +8 -1
- package/assets/checks/lib-boundaries.mjs +2 -2
- package/assets/checks/lib-common.mjs +46 -0
- package/assets/checks/lib-manifests.mjs +18 -13
- package/assets/checks/rt-kit-checks.config.mjs +6 -0
- package/assets/checks/signals.mjs +39 -5
- package/assets/checks/spec-anchors.mjs +48 -4
- package/assets/checks/spec-common.mjs +40 -6
- package/assets/checks/spec-contract.mjs +33 -7
- package/assets/checks/spec-scenarios.mjs +24 -1
- package/assets/checks/task-new.github.mjs +9 -3
- package/assets/defaults/gate-map.sh +20 -5
- package/assets/defaults/project.sh +6 -0
- package/assets/hooks/dev-server-guard.sh +61 -32
- package/assets/hooks/exam-guard.sh +10 -10
- package/assets/hooks/git-guard-delivery-conflict.sh +53 -1
- package/assets/hooks/git-guard-delivery-draft.sh +7 -6
- package/assets/hooks/git-guard-delivery-tree.sh +50 -0
- package/assets/hooks/git-guard-delivery.sh +43 -23
- package/assets/hooks/git-guard-discard.sh +144 -0
- package/assets/hooks/git-guard-push-tests.sh +36 -16
- package/assets/hooks/reuse-first-guard.sh +29 -4
- package/assets/hooks/rule-source-guard.sh +17 -2
- package/assets/hooks/skill-gate.sh +7 -0
- package/assets/hooks/sql-guard-write.sh +18 -2
- package/assets/hooks/turn-exit-guard.sh +50 -66
- package/assets/hooks/turn-exit-patterns.sh +18 -1
- package/assets/hooks/turn-exit-verdict.sh +84 -0
- package/assets/laws/delivery.md +14 -6
- package/assets/laws/verifiability.md +22 -4
- package/assets/patterns/git-workflow-pr.github.md +39 -18
- package/assets/patterns/git-workflow-stack.md +21 -2
- package/assets/patterns/task-flow-close.md +65 -78
- package/assets/patterns/ts-procedure.md +6 -0
- package/assets/pitfalls/git-workflow.github.md +38 -0
- package/assets/pitfalls/task-flow.md +25 -23
- package/assets/rules/browser-verification.md +8 -0
- package/assets/rules/deploy-flow.github.md +6 -0
- package/assets/rules/doc-style.md +6 -0
- package/assets/rules/git-workflow.azure.md +10 -0
- package/assets/rules/git-workflow.github.md +119 -119
- package/assets/rules/git-workflow.gitlab.md +10 -0
- package/assets/rules/lib-layers.md +11 -0
- package/assets/rules/spec-driven.md +10 -1
- package/assets/rules/task-flow.md +59 -56
- package/assets/rules/testing.md +7 -0
- package/assets/rules/turn-conduct.md +23 -3
- package/assets/samples/tasks/_template/plan.md +4 -1
- package/assets/skills/agent-kit.md +17 -4
- package/bin/agent-kit.js +1 -1
- package/bin/agent-kit.js.map +1 -1
- package/lib/commands.d.ts +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +59 -2
- package/lib/commands.js.map +1 -1
- package/lib/hooks-map.d.ts +5 -0
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +9 -3
- package/lib/hooks-map.js.map +1 -1
- package/lib/plan.d.ts +2 -0
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +8 -0
- package/lib/plan.js.map +1 -1
- package/lib/proposals.d.ts +25 -0
- package/lib/proposals.d.ts.map +1 -1
- package/lib/proposals.js +43 -1
- package/lib/proposals.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +8 -11
- package/lib/shipment.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.28.0.tgz +0 -0
- package/rt-tools-agent-kit-0.27.0.tgz +0 -0
|
@@ -30,6 +30,14 @@
|
|
|
30
30
|
# uncertainty — and it computes it again after every edit of the main branch — and reading
|
|
31
31
|
# uncertainty as a conflict would mean refusing work at every fresh tip.
|
|
32
32
|
#
|
|
33
|
+
# The list is split into one's own and a neighbour's. The machine account is one per tree, and
|
|
34
|
+
# several sessions work over the tree at once: by the account alone one's own work is
|
|
35
|
+
# indistinguishable from a neighbour's. A session credited with a neighbour's conflict cannot fix
|
|
36
|
+
# it — the branch is led by somebody else, they hold their own commits on it, and a merge from the
|
|
37
|
+
# side returns a red audit — so such a refusal has no lawful move at all. One's own branch is the
|
|
38
|
+
# one this working copy led: the copy's own record of switches answers that, while the branch refs
|
|
39
|
+
# are shared by every copy of the tree.
|
|
40
|
+
#
|
|
33
41
|
# FAIL-OPEN: no profile function, no network, no machine account — the tier is skipped.
|
|
34
42
|
|
|
35
43
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
@@ -38,6 +46,31 @@
|
|
|
38
46
|
# word search over the whole line.
|
|
39
47
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
40
48
|
|
|
49
|
+
# Did this working copy lead the branch. The record of switches belongs to the copy, while the
|
|
50
|
+
# branch refs are shared by every copy of the tree: by a ref one's own branch is indistinguishable
|
|
51
|
+
# from a neighbour's. An unnamed branch counts as one's own — a list without a branch says nothing
|
|
52
|
+
# to split by, and the former behaviour is the safer of the two.
|
|
53
|
+
rt_delivery_led_branch() {
|
|
54
|
+
named="$1"
|
|
55
|
+
[ -z "$named" ] && return 0
|
|
56
|
+
[ "$named" = "$(git -C "$root" rev-parse --abbrev-ref HEAD 2>/dev/null)" ] && return 0
|
|
57
|
+
git -C "$root" reflog HEAD -n 400 2>/dev/null \
|
|
58
|
+
| awk -v branch="$named" '
|
|
59
|
+
/checkout: moving from / { if ($NF == branch) { found = 1 } }
|
|
60
|
+
END { exit found ? 0 : 1 }
|
|
61
|
+
'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# The note about a neighbour's conflict, printed from the exit of the guard by whichever path it
|
|
65
|
+
# leaves — but only where nothing was refused: two JSON documents in a row are read as plain text,
|
|
66
|
+
# that is, as no refusal at all. A refusal carries the note inside itself.
|
|
67
|
+
rt_delivery_note_out() {
|
|
68
|
+
[ -n "${rt_delivery_said:-}" ] && return 0
|
|
69
|
+
[ -z "${rt_delivery_neighbour_note:-}" ] && return 0
|
|
70
|
+
jq -n --arg c "$rt_delivery_neighbour_note" \
|
|
71
|
+
'{hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:$c}}' 2>/dev/null
|
|
72
|
+
}
|
|
73
|
+
|
|
41
74
|
rt_delivery_conflict() {
|
|
42
75
|
# The sign of taking work is read from the text of the command and stands first: the query goes
|
|
43
76
|
# to the network, and paying for it on every shell command is not allowed.
|
|
@@ -71,13 +104,32 @@ rt_delivery_conflict() {
|
|
|
71
104
|
[ -z "$stuck" ] && return 0
|
|
72
105
|
|
|
73
106
|
listed=''
|
|
107
|
+
neighbour=''
|
|
74
108
|
while IFS= read -r line; do
|
|
75
109
|
[ -z "$line" ] && continue
|
|
76
|
-
|
|
110
|
+
# The line is «#<number> <branch>»: the branch stands last, and by it the copy is asked.
|
|
111
|
+
if rt_delivery_led_branch "${line##* }"; then
|
|
112
|
+
listed="${listed}${listed:+
|
|
77
113
|
}— ${line}"
|
|
114
|
+
else
|
|
115
|
+
neighbour="${neighbour}${neighbour:+
|
|
116
|
+
}— ${line} — the branch is led by another session"
|
|
117
|
+
fi
|
|
78
118
|
done <<EOF
|
|
79
119
|
${stuck}
|
|
80
120
|
EOF
|
|
121
|
+
|
|
122
|
+
# A neighbour's conflict is said aloud and refuses nothing: this session has nothing to fix it
|
|
123
|
+
# with, and the one who leads the branch learns of it from nowhere else. The note is left for
|
|
124
|
+
# the guard to print — it has one output point, and a second JSON document next to the first
|
|
125
|
+
# would be read as plain text, that is, as no refusal at all.
|
|
126
|
+
if [ -n "$neighbour" ]; then
|
|
127
|
+
rt_delivery_neighbour_note="A conflicting request of a neighbouring session stands, and there is nothing here to fix it with:
|
|
128
|
+
|
|
129
|
+
${neighbour}
|
|
130
|
+
|
|
131
|
+
The branch is led by another session and holds its own commits: a merge of the main branch from the side takes that work away. Tell the owner about the request and take work as usual."
|
|
132
|
+
fi
|
|
81
133
|
[ -z "$listed" ] && return 0
|
|
82
134
|
|
|
83
135
|
deny "BLOCKED: ${taking} while a conflicting request of your own stands. What was handed over conflicts with the main branch, and a person cannot merge it:
|
|
@@ -65,15 +65,16 @@ rt_delivery_draft_ready() {
|
|
|
65
65
|
printf '%s' "$pull" | jq -e '.conflicting' >/dev/null 2>&1 \
|
|
66
66
|
&& fault "the request${pull_name} conflicts with the main branch. Merge it into your branch, resolve the conflict and repeat: a lifted draft reads as «ready to merge», and this request cannot be merged."
|
|
67
67
|
|
|
68
|
-
# The author of the PR.
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
72
|
-
#
|
|
68
|
+
# The author of the PR. The clash that breaks the review — the author named as the
|
|
69
|
+
# reviewer — is already caught by the condition above: the hosting silently does not
|
|
70
|
+
# create such a review request, so the PR comes here with no review at all. What is
|
|
71
|
+
# left here is to name a foreign account aloud: a PR opened by other than the machine
|
|
72
|
+
# one is lawful, and silence about it is indistinguishable from a check that did not
|
|
73
|
+
# fire. A tree that named no machine account says nothing.
|
|
73
74
|
if [ -n "$task_bot" ]; then
|
|
74
75
|
pull_author="$(printf '%s' "$pull" | jq -r '.author // empty' 2>/dev/null)"
|
|
75
76
|
[ -n "$pull_author" ] && [ "$pull_author" != "$task_bot" ] \
|
|
76
|
-
&&
|
|
77
|
+
&& printf 'the delivery guard: the request%s was opened by the account «%s», not the machine one «%s». It has a review, so the draft is lifted.\n' "$pull_name" "$pull_author" "$task_bot" >&2
|
|
77
78
|
fi
|
|
78
79
|
fi
|
|
79
80
|
fi
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The tree a command runs in, for the delivery guard: the form of a branch name is judged by the
|
|
3
|
+
# profile of that tree, not of the tree the session was started from.
|
|
4
|
+
#
|
|
5
|
+
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The delivery guard
|
|
6
|
+
# sources it — one tier of its verdict, moved out when the guard reached its length limit.
|
|
7
|
+
#
|
|
8
|
+
# Why exactly so. A session works in a neighbouring tree by the direct word of the owner: the task
|
|
9
|
+
# is created there, the number and the short name are right, and the branch name is lawful by that
|
|
10
|
+
# tree's key. The guard used to compare it with the key of the tree the session stands in and
|
|
11
|
+
# refused — a refusal with no lawful move at all, and the work stopped whole: neither a branch nor a
|
|
12
|
+
# commit. The same refusal caught an edit of an outside file: it was enough for a neighbouring
|
|
13
|
+
# tree's branch name to reach the command text as a line of a document.
|
|
14
|
+
#
|
|
15
|
+
# The directory of execution is taken from the command itself — from the move into it. The directory
|
|
16
|
+
# did not differ from the session's tree — everything goes as before. A tree with no profile of its own is not judged at all: a foreign tree is not accountable
|
|
17
|
+
# to this guard, and a refusal on a lawful name has no bypass.
|
|
18
|
+
#
|
|
19
|
+
# FAIL-OPEN: no move in the command, no profile in the tree it moves to — the form is not judged.
|
|
20
|
+
|
|
21
|
+
# Where the command runs, if it says so itself — the move at the start of the call. Prints the tree
|
|
22
|
+
# root or stays silent.
|
|
23
|
+
rt_delivery_exec_dir() {
|
|
24
|
+
named="$(printf '%s' "$cmd" | sed -nE 's/.*(^|[;&|[:space:]])cd[[:space:]]+([^[:space:];&|]+).*/\2/p' | head -1)"
|
|
25
|
+
named="${named%\'}"; named="${named#\'}"
|
|
26
|
+
named="${named%\"}"; named="${named#\"}"
|
|
27
|
+
[ -z "$named" ] && return 0
|
|
28
|
+
[ -d "$named" ] || return 0
|
|
29
|
+
git -C "$named" rev-parse --show-toplevel 2>/dev/null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Is the branch name lawful. The tree of execution answers; where it is the session's own tree, or
|
|
33
|
+
# says nothing of itself, the answer comes from the profile already loaded.
|
|
34
|
+
rt_delivery_branch_form_ok() {
|
|
35
|
+
named="$1"
|
|
36
|
+
other="$(rt_delivery_exec_dir)"
|
|
37
|
+
if [ -n "$other" ] && [ "$other" != "$root" ]; then
|
|
38
|
+
[ -f "$other/.claude/rt-kit/project.sh" ] || return 0
|
|
39
|
+
(
|
|
40
|
+
for profile in "$other/.claude/rt-kit/defaults/project.sh" "$other/.claude/rt-kit/project.sh"; do
|
|
41
|
+
# shellcheck disable=SC1090
|
|
42
|
+
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
43
|
+
done
|
|
44
|
+
command -v rt_task_branch_ok >/dev/null 2>&1 || exit 0
|
|
45
|
+
rt_task_branch_ok "$named"
|
|
46
|
+
)
|
|
47
|
+
return $?
|
|
48
|
+
fi
|
|
49
|
+
rt_task_branch_ok "$named"
|
|
50
|
+
}
|
|
@@ -145,6 +145,12 @@ deny() {
|
|
|
145
145
|
[ -f "$rt_hooks_dir/deny-tail.sh" ] && . "$rt_hooks_dir/deny-tail.sh" 2>/dev/null
|
|
146
146
|
reason="$1"
|
|
147
147
|
command -v rt_deny_tail >/dev/null 2>&1 && reason="$1 $(rt_deny_tail "$2")"
|
|
148
|
+
# A neighbour's conflict travels inside the refusal: the guard says one thing per call, and a
|
|
149
|
+
# second JSON document next to the first is read as plain text — that is, as no refusal at all.
|
|
150
|
+
[ -n "${rt_delivery_neighbour_note:-}" ] && reason="${reason}
|
|
151
|
+
|
|
152
|
+
${rt_delivery_neighbour_note}"
|
|
153
|
+
rt_delivery_said=1
|
|
148
154
|
|
|
149
155
|
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
150
156
|
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"The delivery guard."}}\n'
|
|
@@ -180,7 +186,15 @@ fault() {
|
|
|
180
186
|
# take the next one: while what was handed over conflicts, it is fixed by the first action of the
|
|
181
187
|
# turn. No helper — the tier is not judged, and the work goes on.
|
|
182
188
|
# shellcheck disable=SC1090
|
|
189
|
+
# The tree the command runs in: the form of a branch name is judged by its profile, not by the
|
|
190
|
+
# profile of the tree the session was started from. No helper — the form is judged as before.
|
|
191
|
+
# shellcheck disable=SC1090
|
|
192
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-tree.sh" ] && . "$rt_hooks_dir/git-guard-delivery-tree.sh" 2>/dev/null
|
|
193
|
+
command -v rt_delivery_branch_form_ok >/dev/null 2>&1 \
|
|
194
|
+
|| rt_delivery_branch_form_ok() { rt_task_branch_ok "$1"; }
|
|
195
|
+
|
|
183
196
|
[ -f "$rt_hooks_dir/git-guard-delivery-conflict.sh" ] && . "$rt_hooks_dir/git-guard-delivery-conflict.sh" 2>/dev/null
|
|
197
|
+
command -v rt_delivery_note_out >/dev/null 2>&1 && trap rt_delivery_note_out EXIT
|
|
184
198
|
command -v rt_delivery_conflict >/dev/null 2>&1 && rt_delivery_conflict
|
|
185
199
|
|
|
186
200
|
# The refusal on what has piled up. Empty — the calling side goes on.
|
|
@@ -243,7 +257,7 @@ if [ -n "$branch_arg" ]; then
|
|
|
243
257
|
# number at all.
|
|
244
258
|
number_arg="$(rt_task_branch_number "$branch_arg")"
|
|
245
259
|
if [ -n "$number_arg" ]; then
|
|
246
|
-
|
|
260
|
+
rt_delivery_branch_form_ok "$branch_arg" \
|
|
247
261
|
|| deny "BLOCKED: the branch name «${branch_arg}» is not of the form accepted here. The branch number is the same as the number of the task and of the title of the merge request."
|
|
248
262
|
state=''
|
|
249
263
|
check_task "$number_arg" "the branch «${branch_arg}»"
|
|
@@ -409,30 +423,36 @@ fi
|
|
|
409
423
|
|
|
410
424
|
# The identity of the call. The hosting client holds two accounts — the logged-in one and the one
|
|
411
425
|
# whose token stands in the call environment; which of them opens the PR is visible from the command
|
|
412
|
-
# only through an explicit substitution.
|
|
413
|
-
# a PR is never its reviewer, and the author cannot be changed.
|
|
414
|
-
#
|
|
415
|
-
# The command text is checked. A tree that named no token variable gets no requirement.
|
|
416
|
-
if [ -n "$pull_token_var" ] \
|
|
417
|
-
&& ! printf '%s' "$cmd" | grep -qE "(^|[;&|(]|&&|\|\||[[:space:]])${pull_token_var}="; then
|
|
418
|
-
fault "the request is opened without the token of the machine account: the command carries no substitution of «${pull_token_var}». Opened by the logged-in account, it comes out from the owner — they cannot be set as the reviewer then, and this is fixed only by reopening.${pull_token_hint:+ Substitute the token: ${pull_token_hint} …}"
|
|
419
|
-
fi
|
|
420
|
-
|
|
421
|
-
# The second tier of the same identity: who actually arrives under this token. A substitution speaks
|
|
422
|
-
# of the intent, not of the result: it read a file that is not on the machine, the client took an
|
|
423
|
-
# empty string for an unset token, and the PR came out from the owner under a command that looked
|
|
424
|
-
# right.
|
|
426
|
+
# only through an explicit substitution.
|
|
425
427
|
#
|
|
426
|
-
#
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
428
|
+
# What is judged is not the name of the account but the clash with the reviewer: the author of a PR
|
|
429
|
+
# is never its reviewer, the hosting silently drops such a review request, and the author cannot be
|
|
430
|
+
# changed afterwards. A PR opened by any other account is lawful while its reviewer is somebody
|
|
431
|
+
# else — judging the name instead leaves a machine that holds no token with no way to deliver at all.
|
|
432
|
+
# The value is taken as one word up to the next space: a login has no spaces in it, and an alphabet
|
|
433
|
+
# listed by ranges would silently not recognise a neighbouring one — the value then reads as absent,
|
|
434
|
+
# and the clash with the reviewer goes unnoticed.
|
|
435
|
+
pull_reviewer="$(printf '%s' "$cmd" | sed -n "s/.*--reviewer[= ]\{1,\}['\"]\{0,1\}\([^[:space:]'\"]\{1,\}\).*/\1/p" | head -1)"
|
|
436
|
+
|
|
437
|
+
# Who will open the PR is asked of the hosting by the tree: the hosting, the client and the path to
|
|
438
|
+
# the token are each their own. The answer covers both accounts at once — the substitution reads a
|
|
439
|
+
# file that may not be on the machine, and then the client answers from the logged-in one.
|
|
440
|
+
token_login=''
|
|
441
|
+
command -v rt_pull_token_login >/dev/null 2>&1 && token_login="$(rt_pull_token_login 2>/dev/null)"
|
|
442
|
+
|
|
443
|
+
if [ -n "$token_login" ]; then
|
|
444
|
+
if [ -n "$pull_reviewer" ] && [ "$token_login" = "$pull_reviewer" ]; then
|
|
445
|
+
fault "the request would be opened by the account «${token_login}», and the same one is named as its reviewer. The hosting accepts such a review request and silently does not create it, and the author of a request cannot be changed — it is fixed only by reopening. Open it by another account${pull_token_hint:+, substituting the token: ${pull_token_hint} …}, or name another reviewer."
|
|
446
|
+
elif [ -n "$task_bot" ] && [ "$token_login" != "$task_bot" ]; then
|
|
447
|
+
# Not a refusal: the reviewer is somebody else, and the review will be created. But silence
|
|
448
|
+
# about a foreign account is indistinguishable from a check that did not fire at all.
|
|
449
|
+
printf 'the delivery guard: the request will come out from the account «%s», not the machine one «%s». The reviewer is another one, so the review will be created.\n' "$token_login" "$task_bot" >&2
|
|
435
450
|
fi
|
|
451
|
+
elif [ -n "$pull_token_var" ] \
|
|
452
|
+
&& ! printf '%s' "$cmd" | grep -qE "(^|[;&|(]|&&|\|\||[[:space:]])${pull_token_var}="; then
|
|
453
|
+
# There is nothing to learn the author by — no helper, or an empty answer from it. Then the only
|
|
454
|
+
# lawful call is the one that names the account in its own text.
|
|
455
|
+
fault "who will open the request cannot be learned: the hosting was not asked, and the command carries no substitution of «${pull_token_var}». Opened by the logged-in account, the request may come out from the very person named as its reviewer, and that is fixed only by reopening.${pull_token_hint:+ Substitute the token: ${pull_token_hint} …}"
|
|
436
456
|
fi
|
|
437
457
|
|
|
438
458
|
# The PR body carries the section about the remaining step from the minute it opens: without it the
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# rt-hook: PreToolUse Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
|
|
3
|
+
# Requires: hooks/deny-tail.sh, hooks/guard-note.sh
|
|
4
|
+
# Guard of the working tree. PreToolUse on a git command that throws uncommitted edits away.
|
|
5
|
+
#
|
|
6
|
+
# `git reset --hard`, `git checkout -- <path>`, `git restore <path>` and `git clean -f` erase what
|
|
7
|
+
# lies in the working tree and is not committed, and git keeps no object of it: `git fsck
|
|
8
|
+
# --lost-found` finds nothing afterwards. In one working copy two sessions work at once, so the
|
|
9
|
+
# erased edits are as often a neighbour's as one's own — seven files of a neighbouring task went
|
|
10
|
+
# that way, and there was nothing to restore them from. The rule `git-workflow` says: a commit is
|
|
11
|
+
# dropped by `--soft`, and `--hard` is taken only to discard edits named before the call.
|
|
12
|
+
#
|
|
13
|
+
# The guard judges two things: the verb with its discarding form in the command, and a non-empty
|
|
14
|
+
# working tree in the directory the command runs in. A clean tree passes: there is nothing to lose.
|
|
15
|
+
# The lawful bypass is the comment `# discard: <reason>` in the same command — the edits are named
|
|
16
|
+
# by whoever throws them away.
|
|
17
|
+
#
|
|
18
|
+
# FAIL-OPEN: not a repository, no git, no parser, broken input — pass. A broken guard must not get
|
|
19
|
+
# in the way of work.
|
|
20
|
+
|
|
21
|
+
RT_GUARD_NAME=git-guard-discard
|
|
22
|
+
|
|
23
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
24
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
25
|
+
|
|
26
|
+
rt_hook_read
|
|
27
|
+
input="$RT_HOOK_INPUT"
|
|
28
|
+
[ -z "$input" ] && exit 0
|
|
29
|
+
|
|
30
|
+
tool="$(rt_hook_tool)"
|
|
31
|
+
case "$tool" in
|
|
32
|
+
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
|
|
33
|
+
*) exit 0 ;;
|
|
34
|
+
esac
|
|
35
|
+
|
|
36
|
+
cmd="$(rt_hook_cmd)"
|
|
37
|
+
|
|
38
|
+
# The universal executor of the environment passes the real command as a nested string.
|
|
39
|
+
if [ "$tool" = "mcp__webstorm__execute_tool" ] && command -v perl >/dev/null 2>&1; then
|
|
40
|
+
inner="$(printf '%s' "$cmd" | perl -0ne '
|
|
41
|
+
if (/--command(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(.+))/s) {
|
|
42
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
43
|
+
}
|
|
44
|
+
' 2>/dev/null)"
|
|
45
|
+
[ -n "$inner" ] && cmd="$inner"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# The bypass: the reason stands in the command itself, after the discard mark. An empty reason is
|
|
49
|
+
# no bypass — a mark without words names nothing.
|
|
50
|
+
if printf '%s' "$cmd" | grep -qE '#[[:space:]]*discard:[[:space:]]*[^[:space:]]'; then
|
|
51
|
+
exit 0
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
command -v awk >/dev/null 2>&1 || exit 0
|
|
55
|
+
|
|
56
|
+
# The verb is looked for in the command position, the same way the main-branch guard does it: the
|
|
57
|
+
# options between `git` and the verb are skipped, and the verb's own arguments are read on to the
|
|
58
|
+
# end of the shell word list of that call. Printed is one line per discarding call: the verb and
|
|
59
|
+
# the sign that makes it discarding.
|
|
60
|
+
#
|
|
61
|
+
# reset — `--hard` among the arguments
|
|
62
|
+
# checkout — `--` among the arguments, or a lone `.` (a path, not a branch)
|
|
63
|
+
# restore — any argument without a leading dash, unless `--staged` alone is asked
|
|
64
|
+
# clean — `-f`, `-fd`, `-df`, `--force` among the arguments
|
|
65
|
+
hits="$(printf '%s\n' "$cmd" | awk '
|
|
66
|
+
function flush() {
|
|
67
|
+
if (verb == "reset" && hard) print "reset --hard"
|
|
68
|
+
if (verb == "checkout" && (dashdash || dot)) print "checkout --"
|
|
69
|
+
if (verb == "restore" && path && !staged) print "restore"
|
|
70
|
+
if (verb == "clean" && force) print "clean -f"
|
|
71
|
+
verb = ""; hard = 0; dashdash = 0; dot = 0; path = 0; staged = 0; force = 0
|
|
72
|
+
}
|
|
73
|
+
{
|
|
74
|
+
for (i = 1; i <= NF; i++) {
|
|
75
|
+
word = $i
|
|
76
|
+
if (word == "&&" || word == "||" || word == ";" || word == "|") { flush(); continue }
|
|
77
|
+
sub(/^.*\//, "", word)
|
|
78
|
+
if (word == "git") {
|
|
79
|
+
flush()
|
|
80
|
+
for (j = i + 1; j <= NF; j++) {
|
|
81
|
+
arg = $j
|
|
82
|
+
if (arg == "-c" || arg == "-C" || arg == "--git-dir" || arg == "--work-tree" \
|
|
83
|
+
|| arg == "--namespace" || arg == "--exec-path") { j++; continue }
|
|
84
|
+
if (substr(arg, 1, 1) == "-") continue
|
|
85
|
+
verb = arg
|
|
86
|
+
break
|
|
87
|
+
}
|
|
88
|
+
i = j
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
if (verb == "") continue
|
|
92
|
+
if (word == "--hard") hard = 1
|
|
93
|
+
if (word == "--") dashdash = 1
|
|
94
|
+
if (word == ".") dot = 1
|
|
95
|
+
if (word == "--staged" || word == "-S") staged = 1
|
|
96
|
+
if (word == "-f" || word == "-fd" || word == "-df" || word == "-fdx" || word == "-fx" \
|
|
97
|
+
|| word == "-xf" || word == "-dfx" || word == "--force") force = 1
|
|
98
|
+
if (substr(word, 1, 1) != "-") path = 1
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
END { flush() }
|
|
102
|
+
' 2>/dev/null)"
|
|
103
|
+
[ -z "$hits" ] && exit 0
|
|
104
|
+
|
|
105
|
+
# The tree is read in the directory the command runs in: a separate working copy has a tree of its
|
|
106
|
+
# own, and the project root would answer for the wrong one.
|
|
107
|
+
workdir="$(rt_hook_cwd)"
|
|
108
|
+
[ -z "$workdir" ] && workdir="${CLAUDE_PROJECT_DIR:-.}"
|
|
109
|
+
cd "$workdir" 2>/dev/null || exit 0
|
|
110
|
+
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
|
|
111
|
+
|
|
112
|
+
# `clean` erases what is untracked; the other three erase what is tracked and changed. Each is
|
|
113
|
+
# judged by the part of the tree it can lose.
|
|
114
|
+
if printf '%s\n' "$hits" | grep -q '^clean'; then
|
|
115
|
+
changed="$(git status --porcelain --untracked-files=all 2>/dev/null)"
|
|
116
|
+
else
|
|
117
|
+
changed="$(git status --porcelain --untracked-files=no 2>/dev/null)"
|
|
118
|
+
fi
|
|
119
|
+
[ -z "$changed" ] && exit 0
|
|
120
|
+
|
|
121
|
+
count="$(printf '%s\n' "$changed" | grep -c .)"
|
|
122
|
+
files="$(printf '%s\n' "$changed" | sed 's/^...//' | head -20 | sed 's/^/ /')"
|
|
123
|
+
[ "$count" -gt 20 ] && files="${files}
|
|
124
|
+
… and $((count - 20)) more"
|
|
125
|
+
what="$(printf '%s\n' "$hits" | sort -u | paste -sd ',' - | sed 's/,/, /g')"
|
|
126
|
+
|
|
127
|
+
reason="BLOCKED by git-guard-discard: «git ${what}» throws away uncommitted edits, and the working tree holds ${count} of them:
|
|
128
|
+
${files}
|
|
129
|
+
|
|
130
|
+
Git keeps no object of an uncommitted edit: after this call there is nothing to restore it from. In one working copy two sessions work at once, so these files may be a neighbour's as well as your own. To drop a commit and keep the edits, take \`git reset --soft\`; to keep them aside, commit or stash them by name first. \`--hard\` is taken only when the goal is to throw the edits away, and then they are named before the call — the rule git-workflow."
|
|
131
|
+
|
|
132
|
+
# shellcheck disable=SC1090
|
|
133
|
+
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
134
|
+
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
135
|
+
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
136
|
+
deny_tail_text="$(rt_deny_tail 'the comment `# discard: <reason>` in the same command, the erased files named in the reason')"
|
|
137
|
+
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
138
|
+
|
|
139
|
+
${deny_tail_text}"
|
|
140
|
+
|
|
141
|
+
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
142
|
+
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"A discarding git command on a dirty working tree is refused. Commit or name the edits first."}}\n'
|
|
143
|
+
|
|
144
|
+
exit 0
|
|
@@ -66,6 +66,24 @@ case "$cmd" in
|
|
|
66
66
|
*--dry-run*) exit 0 ;;
|
|
67
67
|
esac
|
|
68
68
|
|
|
69
|
+
# The refusal of this gate. The shared deny tail — the two lawful moves and the lawful form of a
|
|
70
|
+
# bypass — may not be laid out; then there is no tail, and the reason stays as it was.
|
|
71
|
+
push_deny() {
|
|
72
|
+
reason="$1"
|
|
73
|
+
# shellcheck disable=SC1090
|
|
74
|
+
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
75
|
+
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
76
|
+
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
77
|
+
deny_tail_text="$(rt_deny_tail "")"
|
|
78
|
+
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
79
|
+
|
|
80
|
+
${deny_tail_text}"
|
|
81
|
+
|
|
82
|
+
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
83
|
+
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"The checks before the push did not pass."}}\n'
|
|
84
|
+
exit 0
|
|
85
|
+
}
|
|
86
|
+
|
|
69
87
|
# A branch switch in the same command is refused whole.
|
|
70
88
|
#
|
|
71
89
|
# The guard is a parse of the command BEFORE it runs: it runs the set in the tree that lies there
|
|
@@ -79,22 +97,7 @@ esac
|
|
|
79
97
|
# does not fall here: a fresh branch has the same tree as it had.
|
|
80
98
|
if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git[[:space:]]+(checkout|switch)[[:space:]]+" &&
|
|
81
99
|
! printf '%s' "$cmd" | grep -qE 'git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)([[:space:]]|$)'; then
|
|
82
|
-
|
|
83
|
-
# The shared deny tail: the two lawful moves and the lawful form of bypass, if the refusal has
|
|
84
|
-
# one. The file may not be laid out — then there is no tail, and the reason for the refusal
|
|
85
|
-
# stays as it was.
|
|
86
|
-
# shellcheck disable=SC1090
|
|
87
|
-
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
88
|
-
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
89
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
90
|
-
deny_tail_text="$(rt_deny_tail "")"
|
|
91
|
-
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
92
|
-
|
|
93
|
-
${deny_tail_text}"
|
|
94
|
-
|
|
95
|
-
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
96
|
-
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"Switching the branch and pushing by one command."}}\n'
|
|
97
|
-
exit 0
|
|
100
|
+
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."
|
|
98
101
|
fi
|
|
99
102
|
|
|
100
103
|
workdir="$(rt_hook_cwd)"
|
|
@@ -103,6 +106,23 @@ cd "$workdir" 2>/dev/null || exit 0
|
|
|
103
106
|
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
|
|
104
107
|
[ -f package.json ] || exit 0
|
|
105
108
|
|
|
109
|
+
# Sending from a second working copy is refused whole.
|
|
110
|
+
#
|
|
111
|
+
# The second copy is taken for reading: the merge of the main branch goes on it while the session's
|
|
112
|
+
# copy holds someone else's uncommitted work. A call made from there is judged by the copy the
|
|
113
|
+
# session stands in — that is, by a foreign tree: its stale archive and its half-written spec refuse
|
|
114
|
+
# the call, while the contribution actually leaving is never checked at all.
|
|
115
|
+
moved="$(printf '%s' "$cmd" | sed -nE 's/.*(^|[;&|[:space:]])cd[[:space:]]+([^[:space:];&|]+).*/\2/p' | head -1)"
|
|
116
|
+
moved="${moved%\'}"; moved="${moved#\'}"
|
|
117
|
+
moved="${moved%\"}"; moved="${moved#\"}"
|
|
118
|
+
if [ -n "$moved" ] && [ -d "$moved" ]; then
|
|
119
|
+
moved_root="$(git -C "$moved" rev-parse --show-toplevel 2>/dev/null)"
|
|
120
|
+
here_root="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
121
|
+
if [ -n "$moved_root" ] && [ -n "$here_root" ] && [ "$moved_root" != "$here_root" ]; then
|
|
122
|
+
push_deny "BLOCKED: the call goes from a second working copy — «${moved_root}», while the session stands in «${here_root}». The gate set runs where the session was started, not where the call was made: someone else's uncommitted work refuses it, and the contribution actually leaving passes unchecked. The second copy is for reading; bring the result of the merge back and send from the copy the session stands in."
|
|
123
|
+
fi
|
|
124
|
+
fi
|
|
125
|
+
|
|
106
126
|
# The tree profile: first the package default, over it the project override, if there is one. A
|
|
107
127
|
# function declared in the override replaces the default whole and may call it back by the
|
|
108
128
|
# `_default` suffix. There is neither — the hook passes: an empty guard is better than a guard
|
|
@@ -200,7 +200,10 @@ rt_bundles=''
|
|
|
200
200
|
rt_own_signals=''
|
|
201
201
|
rt_backend_roots=''
|
|
202
202
|
if [ -f "$rt_checks_json" ]; then
|
|
203
|
-
|
|
203
|
+
# A bundle is declared either by the name alone or by a pair of the name and the area of the
|
|
204
|
+
# tree. Both forms are read into one shape — the name, a tab, the area as a list: further on the
|
|
205
|
+
# area goes onto the sign itself, and there it is read the same way the full check reads it.
|
|
206
|
+
rt_bundles="$(jq -r '.reuse.bundles[]? | if type == "object" then "\(.name // "")\t\((.roots // []) | if type == "string" then [.] else . end | tojson)" else "\(.)\t[]" end' "$rt_checks_json" 2>/dev/null)"
|
|
204
207
|
own="$(jq -r '.reuse.signals // empty' "$rt_checks_json" 2>/dev/null)"
|
|
205
208
|
[ -n "$own" ] && rt_own_signals="${CLAUDE_PROJECT_DIR:-.}/$own"
|
|
206
209
|
# By the same key the full check reads them: a second declaration of the same roots would
|
|
@@ -219,10 +222,15 @@ signals_json() {
|
|
|
219
222
|
[ -n "$rt_signals_dir" ] || return 0
|
|
220
223
|
[ -d "$rt_signals_dir" ] || return 0
|
|
221
224
|
# The layout header is stripped before parsing: JSON has no comment, and the parse falls on it.
|
|
222
|
-
|
|
225
|
+
while IFS="$(printf '\t')" read -r name roots; do
|
|
226
|
+
[ -z "$name" ] && continue
|
|
223
227
|
file="$rt_signals_dir/$name.json"
|
|
224
|
-
[ -f "$file" ]
|
|
225
|
-
|
|
228
|
+
[ -f "$file" ] || continue
|
|
229
|
+
grep -v '^# rt-kit ' "$file" \
|
|
230
|
+
| jq -c --argjson roots "${roots:-[]}" '.signals[]? | if ($roots | length) > 0 then .roots = $roots else . end' 2>/dev/null
|
|
231
|
+
done <<BUNDLES
|
|
232
|
+
$rt_bundles
|
|
233
|
+
BUNDLES
|
|
226
234
|
[ -n "$rt_own_signals" ] && [ -f "$rt_own_signals" ] && grep -v '^# rt-kit ' "$rt_own_signals" | jq -c '.signals[]?' 2>/dev/null
|
|
227
235
|
}
|
|
228
236
|
|
|
@@ -254,6 +262,23 @@ while IFS= read -r signal; do
|
|
|
254
262
|
[ -n "$skip_backend" ] && continue
|
|
255
263
|
fi
|
|
256
264
|
|
|
265
|
+
# The area of the tree the bundle was declared with. A tree has more than one source of look
|
|
266
|
+
# oftener than one, and a sign of the first answers falsely over the second: an application
|
|
267
|
+
# assembled from another set of ready-made code drops out of the judging by the declaration.
|
|
268
|
+
# The full check reads the same field — they must not diverge. The boundary is judged by the
|
|
269
|
+
# directory: `apps/admin` must not take in `apps/administration`.
|
|
270
|
+
roots="$(printf '%s' "$signal" | jq -r '.roots[]? // empty' 2>/dev/null)"
|
|
271
|
+
if [ -n "$roots" ]; then
|
|
272
|
+
inside=''
|
|
273
|
+
while IFS= read -r area; do
|
|
274
|
+
[ -z "$area" ] && continue
|
|
275
|
+
case "$rel_path" in "$area" | "$area"/*) inside=1 ;; esac
|
|
276
|
+
done <<AREAS
|
|
277
|
+
$roots
|
|
278
|
+
AREAS
|
|
279
|
+
[ -z "$inside" ] && continue
|
|
280
|
+
fi
|
|
281
|
+
|
|
257
282
|
# The name pattern is checked against the path from the root of the tree, not against the file
|
|
258
283
|
# name: the layers the sign separates call their files alike, and by name they are
|
|
259
284
|
# indistinguishable. The full check checks against the path — they must not diverge.
|
|
@@ -123,12 +123,27 @@ while IFS= read -r candidate; do
|
|
|
123
123
|
continue
|
|
124
124
|
fi
|
|
125
125
|
|
|
126
|
+
# The override merges by the section «## », and that promise is true only of a text: a law, a
|
|
127
|
+
# rule, a pattern, a skill. A shell script and a check file have no sections at all, and the
|
|
128
|
+
# executor sent to write an override there finds nothing to merge — and learns it not from the
|
|
129
|
+
# guard but from the next layout, that is, latest of all. A promise true of a third of the
|
|
130
|
+
# cases is worse than none: people go and work by it.
|
|
131
|
+
case "$resource" in
|
|
132
|
+
*.md) override_way="an edit true only to this tree goes to the override .claude/rt-kit/overrides/${resource} — it merges by the section «## » and outlives the layout" ;;
|
|
133
|
+
*) override_way="there is no override by sections for a resource of this kind: it has no «## » sections at all, and the edit goes into the package itself" ;;
|
|
134
|
+
esac
|
|
135
|
+
|
|
126
136
|
if [ -n "$sources" ] && [ -f "$root/$sources/$resource" ]; then
|
|
127
137
|
deny "BLOCKED by rule-source-guard: «${candidate#"$root"/}» is laid out by the package, and an edit in its place is lost on the next layout — and until then the layout refuses this file whole, and the price is paid by whoever edits a neighbouring resource that day. The resource is «${resource}». Edit the source: ${sources}/${resource} — then build the package and lay it out." \
|
|
128
|
-
"
|
|
138
|
+
"$override_way"
|
|
129
139
|
fi
|
|
130
140
|
|
|
131
|
-
|
|
141
|
+
case "$resource" in
|
|
142
|
+
*.md) where="Edit the override: .claude/rt-kit/overrides/${resource} — it merges by the section «## » and outlives the layout." ;;
|
|
143
|
+
*) where="A resource of this kind has no override by sections — it has no «## » sections at all. The edit goes into the package itself and arrives here by a new edition." ;;
|
|
144
|
+
esac
|
|
145
|
+
|
|
146
|
+
deny "BLOCKED by rule-source-guard: «${candidate#"$root"/}» is laid out by the package @rt-tools/agent-kit, and an edit in its place is lost on the next layout. The resource is «${resource}». ${where}" \
|
|
132
147
|
"what is true of any tree is edited in the package itself and arrives here by a new edition"
|
|
133
148
|
done <<EOF
|
|
134
149
|
$candidates
|
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
# and after the rule is loaded the same area passes silently — there are no repeats, and it costs
|
|
9
9
|
# almost nothing.
|
|
10
10
|
#
|
|
11
|
+
# One thing does cancel the mark, and on purpose: compaction or clearing of the session window.
|
|
12
|
+
# `hooks/skill-gate-rearm.sh` removes the record then, and every area asks for its rule once more.
|
|
13
|
+
# The mark says "the rule is in the window", not "the rule was once read": after the compaction the
|
|
14
|
+
# text is gone from the window, and a gate that kept letting through would be letting the session
|
|
15
|
+
# work from a retelling. The re-arming is told to the session in words, so that it is not read as
|
|
16
|
+
# breakage.
|
|
17
|
+
#
|
|
11
18
|
# The "file — rule" map lives not here but in two files next door, and that is not duplication.
|
|
12
19
|
# The default — `.claude/rt-kit/defaults/gate-map.sh` — is carried by the package: the trees of
|
|
13
20
|
# this workshop are built alike, and rewriting one and the same map in each of them anew would
|
|
@@ -49,6 +49,16 @@ PIPE_EOF
|
|
|
49
49
|
# The exception acts PER SEGMENT. While it was checked over the whole command, one mention of
|
|
50
50
|
# `pg_dump` anywhere in the chain was enough for `-f` to stop counting as a write in all the
|
|
51
51
|
# other calls: `pg_dump … > /dev/null && psql -d app -f /tmp/x.sql` passed silently.
|
|
52
|
+
sql_delivers_file && is_write="yes"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# A file poured into the client names not a single SQL verb, and its content the guard does not see
|
|
56
|
+
# — so this is a write by definition. It stands in a function of its own because the answer is
|
|
57
|
+
# needed by two places: the common detection of a write above, and the early exit on a local
|
|
58
|
+
# migration below. While the loop stood in the first alone, the chain `prisma migrate deploy &&
|
|
59
|
+
# psql -d app -f fix.sql` passed silently: the exit counted a second write only by SQL verbs and by
|
|
60
|
+
# the commands that feed the pipe.
|
|
61
|
+
sql_delivers_file() {
|
|
52
62
|
while IFS= read -r seg; do
|
|
53
63
|
[ -z "$seg" ] && continue
|
|
54
64
|
# The word boundary is mandatory: `-f /tmp/pg_dump-restore.sql` is loading a dump, not
|
|
@@ -62,12 +72,13 @@ PIPE_EOF
|
|
|
62
72
|
seg_tail="$(printf '%s' "$seg" | perl -0pe 's{^.*?(?<![[:alnum:]_./-])(psql|pg_restore|prisma)(?=\s|$)}{$1}s' 2>/dev/null)"
|
|
63
73
|
[ -z "$seg_tail" ] && seg_tail="$seg"
|
|
64
74
|
if printf '%s' "$seg_tail" | grep -qE '(^|[[:space:]])(-f|--file)([[:space:]]|=)|<[[:space:]]*[^[:space:]|<]+\.(sql|dump)'; then
|
|
65
|
-
|
|
66
|
-
break
|
|
75
|
+
return 0
|
|
67
76
|
fi
|
|
68
77
|
done <<EOF
|
|
69
78
|
$segments
|
|
70
79
|
EOF
|
|
80
|
+
|
|
81
|
+
return 1
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
# --- destructive for certain ------------------------------------------------------------
|
|
@@ -178,6 +189,11 @@ sql_check_migrations() {
|
|
|
178
189
|
done <<MIGRATE_PIPE_EOF
|
|
179
190
|
$(client_segments)
|
|
180
191
|
MIGRATE_PIPE_EOF
|
|
192
|
+
# A file poured into the client is judged by the same sign as everywhere else. Its
|
|
193
|
+
# own set of signs here was narrower than the common one by exactly this, and the
|
|
194
|
+
# second link of `prisma migrate deploy && psql -d app -f fix.sql` fell out of the
|
|
195
|
+
# check whole: the guard sees neither the file nor its content.
|
|
196
|
+
sql_delivers_file && other_write="yes"
|
|
181
197
|
[ -z "$other_write" ] && exit 0
|
|
182
198
|
;;
|
|
183
199
|
'')
|