@rt-tools/agent-kit 0.27.0 → 0.29.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-link.github.mjs +13 -1
- 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/board-runs.github.mjs +102 -2
- package/assets/checks/check-board.github.mjs +63 -3
- 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/main-run.github.mjs +69 -0
- package/assets/checks/rt-kit-checks.config.mjs +21 -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/checks/tree-assignment.mjs +169 -0
- 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/end-conversation-guard.sh +59 -0
- package/assets/hooks/epic-over.sh +11 -2
- 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-epic.sh +7 -0
- package/assets/hooks/git-guard-delivery-tree.sh +50 -0
- package/assets/hooks/git-guard-delivery.sh +45 -24
- package/assets/hooks/git-guard-discard.sh +144 -0
- package/assets/hooks/git-guard-push-tests.sh +36 -16
- package/assets/hooks/git-guard-tree-assignment.sh +77 -0
- package/assets/hooks/hook-input.sh +8 -1
- package/assets/hooks/main-run-context.sh +45 -0
- 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/tree-assignment-guard.sh +101 -0
- package/assets/hooks/turn-exit-epic.sh +110 -0
- package/assets/hooks/turn-exit-guard.sh +80 -82
- package/assets/hooks/turn-exit-patterns.sh +18 -10
- package/assets/hooks/turn-exit-verdict.sh +96 -0
- package/assets/laws/delivery.md +20 -6
- package/assets/laws/verifiability.md +22 -4
- package/assets/laws/work-conduct.md +4 -0
- package/assets/patterns/git-workflow-merge.md +13 -0
- package/assets/patterns/git-workflow-pr-body.github.md +156 -0
- package/assets/patterns/git-workflow-pr.github.md +42 -119
- package/assets/patterns/git-workflow-stack.md +38 -2
- package/assets/patterns/task-flow-close.md +66 -79
- package/assets/patterns/task-flow-resume.md +8 -0
- package/assets/patterns/ts-procedure.md +6 -0
- package/assets/pitfalls/git-workflow.github.md +44 -0
- package/assets/pitfalls/task-flow.md +25 -23
- package/assets/pitfalls/turn-conduct.md +18 -0
- package/assets/rules/browser-verification.md +8 -0
- package/assets/rules/deploy-flow.github.md +6 -0
- package/assets/rules/doc-style.md +9 -2
- package/assets/rules/git-workflow.azure.md +10 -0
- package/assets/rules/git-workflow.github.md +128 -130
- 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 +82 -79
- package/assets/rules/testing.md +7 -0
- package/assets/rules/turn-conduct.md +47 -28
- package/assets/samples/tasks/_template/plan.md +4 -1
- package/assets/samples/tasks/_template/progress.md +1 -1
- package/assets/skills/agent-kit.md +17 -4
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +3 -2
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo.d.ts +49 -1
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +9 -2
- package/lib/cargo.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/observations-cargo.d.ts +20 -0
- package/lib/observations-cargo.d.ts.map +1 -0
- package/lib/observations-cargo.js +88 -0
- package/lib/observations-cargo.js.map +1 -0
- 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 +8 -20
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.js +30 -50
- package/lib/shipment.js.map +1 -1
- package/lib/tree-mark.d.ts +17 -0
- package/lib/tree-mark.d.ts.map +1 -0
- package/lib/tree-mark.js +41 -0
- package/lib/tree-mark.js.map +1 -0
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.29.0.tgz +0 -0
- package/rt-tools-agent-kit-0.27.0.tgz +0 -0
|
@@ -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
|
+
}
|
|
@@ -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-folder.sh, hooks/git-guard-delivery-epic.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-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
|
|
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
|
|
@@ -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}»"
|
|
@@ -260,6 +274,7 @@ if [ -n "$branch_arg" ]; then
|
|
|
260
274
|
# base fresh — `git checkout -b <branch> origin/<main>` — would be forbidden.
|
|
261
275
|
base_arg="$(printf '%s' "$cmd" | sed -nE 's/.*git[[:space:]]+(checkout([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-b|switch([[:space:]]+-[A-Za-z-]+)*[[:space:]]+-c)[[:space:]]+[^[:space:];&|]+[[:space:]]+([^[:space:];&|-][^[:space:];&|]*).*/\4/p' | head -1)"
|
|
262
276
|
base_ref="${base_arg:-HEAD}"
|
|
277
|
+
command -v rt_assignment_fault >/dev/null 2>&1 && rt_assignment_fault "$epic_arg" "the branch «${branch_arg}»"
|
|
263
278
|
if [ -n "$epic_arg" ] && command -v rt_epic_base >/dev/null 2>&1; then
|
|
264
279
|
rt_epic_base "$epic_arg" "$base_ref" "$branch_arg"
|
|
265
280
|
elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
|
|
@@ -409,30 +424,36 @@ fi
|
|
|
409
424
|
|
|
410
425
|
# The identity of the call. The hosting client holds two accounts — the logged-in one and the one
|
|
411
426
|
# 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.
|
|
427
|
+
# only through an explicit substitution.
|
|
425
428
|
#
|
|
426
|
-
#
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
429
|
+
# What is judged is not the name of the account but the clash with the reviewer: the author of a PR
|
|
430
|
+
# is never its reviewer, the hosting silently drops such a review request, and the author cannot be
|
|
431
|
+
# changed afterwards. A PR opened by any other account is lawful while its reviewer is somebody
|
|
432
|
+
# else — judging the name instead leaves a machine that holds no token with no way to deliver at all.
|
|
433
|
+
# The value is taken as one word up to the next space: a login has no spaces in it, and an alphabet
|
|
434
|
+
# listed by ranges would silently not recognise a neighbouring one — the value then reads as absent,
|
|
435
|
+
# and the clash with the reviewer goes unnoticed.
|
|
436
|
+
pull_reviewer="$(printf '%s' "$cmd" | sed -n "s/.*--reviewer[= ]\{1,\}['\"]\{0,1\}\([^[:space:]'\"]\{1,\}\).*/\1/p" | head -1)"
|
|
437
|
+
|
|
438
|
+
# Who will open the PR is asked of the hosting by the tree: the hosting, the client and the path to
|
|
439
|
+
# the token are each their own. The answer covers both accounts at once — the substitution reads a
|
|
440
|
+
# file that may not be on the machine, and then the client answers from the logged-in one.
|
|
441
|
+
token_login=''
|
|
442
|
+
command -v rt_pull_token_login >/dev/null 2>&1 && token_login="$(rt_pull_token_login 2>/dev/null)"
|
|
443
|
+
|
|
444
|
+
if [ -n "$token_login" ]; then
|
|
445
|
+
if [ -n "$pull_reviewer" ] && [ "$token_login" = "$pull_reviewer" ]; then
|
|
446
|
+
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."
|
|
447
|
+
elif [ -n "$task_bot" ] && [ "$token_login" != "$task_bot" ]; then
|
|
448
|
+
# Not a refusal: the reviewer is somebody else, and the review will be created. But silence
|
|
449
|
+
# about a foreign account is indistinguishable from a check that did not fire at all.
|
|
450
|
+
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
451
|
fi
|
|
452
|
+
elif [ -n "$pull_token_var" ] \
|
|
453
|
+
&& ! printf '%s' "$cmd" | grep -qE "(^|[;&|(]|&&|\|\||[[:space:]])${pull_token_var}="; then
|
|
454
|
+
# There is nothing to learn the author by — no helper, or an empty answer from it. Then the only
|
|
455
|
+
# lawful call is the one that names the account in its own text.
|
|
456
|
+
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
457
|
fi
|
|
437
458
|
|
|
438
459
|
# 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
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The assignment of an epic to this working copy. NOT a guard: it has no `rt-hook:` declaration and
|
|
3
|
+
# hooks into no agent event. The delivery guard sources it, the same way it sources the conditions
|
|
4
|
+
# about the epic of a task.
|
|
5
|
+
#
|
|
6
|
+
# Why at all. A machine holds several working copies of one tree, and the work queue answers only
|
|
7
|
+
# what is open: it holds no owner of a card, and by topic one epic cannot be told from another. A
|
|
8
|
+
# session that took the freshest epic of the list did work nobody had ordered — the whole day of it,
|
|
9
|
+
# up to a written agreement, and it was the owner who stopped that, not a check.
|
|
10
|
+
#
|
|
11
|
+
# WHAT IS HERE. Two calls, made from the delivery guard, where `fault` is already declared. The
|
|
12
|
+
# answer is computed by the tree's command: the table of assignments and the name of this copy are
|
|
13
|
+
# read in one place, by the audit and by the guard alike.
|
|
14
|
+
|
|
15
|
+
# Where the reading command lies. The layout directory of a tree is its own, and the path is taken
|
|
16
|
+
# from the tree settings the same way the neighbouring guards take it.
|
|
17
|
+
rt_assignment_cmd() {
|
|
18
|
+
_checks="$(jq -r '.layout.checks // "tools"' ".claude/rt-kit.json" 2>/dev/null)"
|
|
19
|
+
[ -n "$_checks" ] && [ "$_checks" != null ] || _checks=tools
|
|
20
|
+
printf '%s/tree-assignment.mjs' "$_checks"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# The refusal about the assignment, or silence. Arguments: the number of the epic of the work being
|
|
24
|
+
# taken (empty where the work has no epic) and what exactly is being taken, for the refusal text.
|
|
25
|
+
#
|
|
26
|
+
# The tree that declares no assignments answers with silence: it has nothing to divide, and a
|
|
27
|
+
# requirement invented for it would refuse every branch of a tree with one working copy.
|
|
28
|
+
rt_assignment_fault() {
|
|
29
|
+
_epic="$1"
|
|
30
|
+
_what="$2"
|
|
31
|
+
_said=''
|
|
32
|
+
_reader="$(rt_assignment_cmd)"
|
|
33
|
+
|
|
34
|
+
[ -f "$_reader" ] || return 0
|
|
35
|
+
command -v node >/dev/null 2>&1 || return 0
|
|
36
|
+
|
|
37
|
+
_said="$(node "$_reader" --fault "$_epic" 2>/dev/null)"
|
|
38
|
+
if [ -n "$_said" ]; then
|
|
39
|
+
fault "${_what} is not taken: ${_said}."
|
|
40
|
+
return 0
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
rt_assignment_stale "$_what"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# The assignment that outlived its epic.
|
|
47
|
+
#
|
|
48
|
+
# An assignment goes stale by itself: the epic ends, and the row stays as it was. That is exactly
|
|
49
|
+
# how a session got no order at all — the table named an epic all seven tasks of which had been
|
|
50
|
+
# closed for days, and the session, finding nothing alive there, chose the work by itself.
|
|
51
|
+
#
|
|
52
|
+
# The staleness is not readable from the table: the table says what was given, and only the queue
|
|
53
|
+
# says whether it is still alive. No answer from the queue — no refusal: the call goes to the
|
|
54
|
+
# network, and a tree without one keeps working.
|
|
55
|
+
rt_assignment_stale() {
|
|
56
|
+
_what="$1"
|
|
57
|
+
_assigned=''
|
|
58
|
+
_state=''
|
|
59
|
+
_reader="$(rt_assignment_cmd)"
|
|
60
|
+
|
|
61
|
+
command -v rt_task_state >/dev/null 2>&1 || return 0
|
|
62
|
+
[ -f "$_reader" ] || return 0
|
|
63
|
+
|
|
64
|
+
_assigned="$(node "$_reader" --assigned 2>/dev/null)"
|
|
65
|
+
[ -n "$_assigned" ] || return 0
|
|
66
|
+
|
|
67
|
+
_state="$(rt_task_state "$_assigned" 2>/dev/null)" || return 0
|
|
68
|
+
[ -n "$_state" ] || return 0
|
|
69
|
+
|
|
70
|
+
# The field is read by an explicit comparison: `.open // empty` gives the right side both for
|
|
71
|
+
# a missing field and for `false`, that is, exactly for the state this refusal is written for.
|
|
72
|
+
case "$(printf '%s' "$_state" | jq -r 'if .open == false then "false" else "" end' 2>/dev/null)" in
|
|
73
|
+
false)
|
|
74
|
+
fault "${_what} is not taken: the epic assigned to this copy is closed — the assignment outlived it. Ask the owner for a new one and write it into the table; an epic chosen instead of the closed one is not an order."
|
|
75
|
+
;;
|
|
76
|
+
esac
|
|
77
|
+
}
|
|
@@ -85,9 +85,16 @@ rt_hook_field() {
|
|
|
85
85
|
# is how PRs went out opened not by the machine record. A path part does not cross a space, so it
|
|
86
86
|
# stays inside one word and glues nothing extra to the call.
|
|
87
87
|
#
|
|
88
|
+
# A runner standing before the call is the same call. `timeout`, `nohup`, `env`, `sudo` and their
|
|
89
|
+
# kin take a command and run it as their own argument: the call is there, and the sign, looking only
|
|
90
|
+
# at the start of the line, did not see it. One push with `timeout` before it went past the whole
|
|
91
|
+
# gate set — the branch left with two red checks, and the pipeline caught them a minute later. The
|
|
92
|
+
# list is closed: any word before the call would count `echo git push` as a push.
|
|
93
|
+
#
|
|
88
94
|
# This is declared in a SINGLE place, not as a literal in every guard: having diverged, the copies
|
|
89
95
|
# are fixed one at a time and say nothing about the rest staying blind.
|
|
90
|
-
|
|
96
|
+
RT_CMD_RUNNER='((timeout|nohup|time|command|nice|stdbuf|sudo|env|caffeinate|setsid|ionice)([[:space:]]+(-[^[:space:]]+|[0-9]+(\.[0-9]+)?[smhd]?|[A-Za-z_][A-Za-z0-9_]*=[^[:space:]]*))*[[:space:]]+)*'
|
|
97
|
+
RT_CMD_BOUND='(^|[;&|(]|&&|\|\|)[[:space:]]*([A-Za-z_][A-Za-z0-9_]*=([^[:space:]]*|\$\([^)]*\)|"[^"]*"|'"'"'[^'"'"']*'"'"')[[:space:]]+)*'"$RT_CMD_RUNNER"'([^[:space:]]*/)?'
|
|
91
98
|
|
|
92
99
|
# The fields that all guards ask for.
|
|
93
100
|
rt_hook_tool() { rt_hook_field RT_HOOK_TOOL '.tool_name'; }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# rt-hook: SessionStart startup|resume|compact|clear
|
|
3
|
+
# SessionStart: the last run of the main branch goes into the context in one line, at every start.
|
|
4
|
+
#
|
|
5
|
+
# A merge reads as the end of the work, and a red main branch after it lives until the owner
|
|
6
|
+
# notices: a run of the main branch is opened by nobody, so nobody reads its outcome. The line is
|
|
7
|
+
# printed here so that the session starts from it, not from memory of a green PR; after a merge made
|
|
8
|
+
# mid-session the same command is called by hand — the rule `task-flow` names it.
|
|
9
|
+
#
|
|
10
|
+
# The reading itself lies among the checks laid out in the tree — the same reading the work queue
|
|
11
|
+
# audit uses. It goes to the hosting, and that costs a second at every start; the alternative is a
|
|
12
|
+
# day and a half of a red main branch nobody saw.
|
|
13
|
+
#
|
|
14
|
+
# FAIL-OPEN: no `jq`, no `node`, not a git repository, no laid-out reading — we exit silently. The
|
|
15
|
+
# session matters more than the line. What the reading itself could not do it says by its own line:
|
|
16
|
+
# no pipeline file, a pipeline asleep on a push, no network.
|
|
17
|
+
|
|
18
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
19
|
+
|
|
20
|
+
command -v jq >/dev/null 2>&1 || exit 0
|
|
21
|
+
command -v node >/dev/null 2>&1 || exit 0
|
|
22
|
+
|
|
23
|
+
root="$(cd "${CLAUDE_PROJECT_DIR:-.}" 2>/dev/null && git rev-parse --show-toplevel 2>/dev/null)"
|
|
24
|
+
[ -z "$root" ] && exit 0
|
|
25
|
+
|
|
26
|
+
# Where the checks of the package lie is named by the tree: the directory differs from tree to tree,
|
|
27
|
+
# and a name written here would be right in the first one and wrong in the second.
|
|
28
|
+
checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
|
|
29
|
+
if [ -z "$checks" ] || [ "$checks" = null ]; then
|
|
30
|
+
checks=tools
|
|
31
|
+
fi
|
|
32
|
+
reading="$root/$checks/main-run.mjs"
|
|
33
|
+
[ -f "$reading" ] || exit 0
|
|
34
|
+
|
|
35
|
+
# A non-zero code is the reading's own verdict — red or pushed out — not a breakage: the line is
|
|
36
|
+
# printed all the same. A reading that printed nothing has broken, and silence is all it gets.
|
|
37
|
+
line="$(cd "$root" && node "$reading" 2>/dev/null)"
|
|
38
|
+
[ -z "$line" ] && exit 0
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
printf 'MAIN BRANCH RUN — read before the first action, and again after every known merge.\n\n'
|
|
42
|
+
printf '%s\n\n' "$line"
|
|
43
|
+
printf 'A red or a pushed-out run is fixed before new work is taken: merges on top go out unchecked.\n'
|
|
44
|
+
printf 'The same line by hand: `node %s/main-run.mjs`. The rule — skill `task-flow`.\n' "$checks"
|
|
45
|
+
} | jq -Rs '{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:.}}' 2>/dev/null || exit 0
|
|
@@ -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
|