@rt-tools/agent-kit 0.26.0 → 0.27.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/agents/cargo-writer.md +54 -0
- package/assets/checks/board-epic-link.github.mjs +29 -0
- package/assets/checks/board-epics.github.mjs +239 -36
- package/assets/checks/board-long-work.github.mjs +5 -1
- package/assets/checks/board-pull-state.github.mjs +168 -0
- package/assets/checks/board-task-dirs.github.mjs +98 -0
- package/assets/checks/board.github.mjs +8 -91
- package/assets/checks/check-board.github.mjs +25 -165
- package/assets/checks/check-prose-style.mjs +19 -3
- package/assets/checks/check-schema-drift.mjs +19 -3
- package/assets/checks/epic-table.github.mjs +268 -0
- package/assets/checks/rt-kit-checks.config.mjs +13 -0
- package/assets/checks/specs-for.mjs +214 -0
- package/assets/checks/task-new.github.mjs +231 -6
- package/assets/commands/night.md +115 -0
- package/assets/defaults/project.sh +7 -0
- package/assets/defaults/turn-map.md +3 -1
- package/assets/docs/GLOSSARY.md +22 -22
- package/assets/hooks/browser-device-id.sh +4 -0
- package/assets/hooks/browser-guard-device-id.sh +4 -0
- package/assets/hooks/commit-msg.sh +3 -0
- package/assets/hooks/dev-server-guard.sh +4 -0
- package/assets/hooks/epic-over.sh +49 -0
- package/assets/hooks/epic-stop-guard.sh +108 -0
- package/assets/hooks/git-guard-delivery-conflict.sh +3 -0
- package/assets/hooks/git-guard-delivery-draft.sh +3 -0
- package/assets/hooks/git-guard-delivery-epic.sh +167 -0
- package/assets/hooks/git-guard-delivery-signature.sh +32 -2
- package/assets/hooks/git-guard-delivery.sh +28 -4
- package/assets/hooks/handoff-entry-guard.sh +20 -2
- package/assets/hooks/prose-style-guard.sh +31 -8
- package/assets/hooks/qa-dataid-guard.sh +33 -11
- package/assets/hooks/rule-article.sh +3 -0
- package/assets/hooks/skill-gate-layers.sh +4 -0
- package/assets/hooks/skill-loaded.sh +4 -0
- package/assets/hooks/sql-guard-parse.sh +3 -0
- package/assets/hooks/sql-guard-request.sh +3 -0
- package/assets/hooks/sql-guard-target.sh +3 -0
- package/assets/hooks/sql-guard-write.sh +3 -0
- package/assets/hooks/stand-login-guard.sh +3 -0
- package/assets/hooks/turn-exit-guard.sh +5 -1
- package/assets/hooks/turn-exit-patterns.sh +10 -0
- package/assets/hooks/utf8.sh +3 -0
- package/assets/hooks/waiting-turn-guard.sh +11 -1
- package/assets/hooks/write-targets.sh +3 -0
- package/assets/laws/delivery.md +23 -1
- package/assets/patterns/git-workflow-commit.azure.md +1 -1
- package/assets/patterns/git-workflow-commit.github.md +9 -2
- package/assets/patterns/git-workflow-commit.gitlab.md +1 -1
- package/assets/patterns/git-workflow-merge.md +8 -5
- package/assets/patterns/git-workflow-pr.azure.md +1 -1
- package/assets/patterns/git-workflow-pr.github.md +8 -3
- package/assets/patterns/git-workflow-pr.gitlab.md +1 -1
- package/assets/patterns/git-workflow-stack.md +13 -9
- package/assets/patterns/status-report-table.github.md +11 -0
- package/assets/patterns/task-flow-close.md +40 -21
- package/assets/patterns/task-flow-start.md +40 -26
- package/assets/pitfalls/agent-kit.md +19 -0
- package/assets/pitfalls/git-workflow.github.md +6 -0
- package/assets/rules/autonomous-work.md +15 -3
- package/assets/rules/doc-style.md +7 -4
- package/assets/rules/git-workflow.github.md +41 -23
- package/assets/rules/spec-driven.md +7 -0
- package/assets/rules/status-report.md +7 -0
- package/assets/rules/task-flow.md +31 -10
- package/assets/rules/turn-conduct.md +7 -0
- package/assets/skills/agent-kit.md +23 -21
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +8 -1
- package/bin/agent-kit.js.map +1 -1
- package/lib/cargo-prose.d.ts +41 -0
- package/lib/cargo-prose.d.ts.map +1 -0
- package/lib/cargo-prose.js +88 -0
- package/lib/cargo-prose.js.map +1 -0
- package/lib/cargo.d.ts +12 -1
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +8 -2
- package/lib/cargo.js.map +1 -1
- package/lib/fate.d.ts +29 -0
- package/lib/fate.d.ts.map +1 -0
- package/lib/fate.js +147 -0
- package/lib/fate.js.map +1 -0
- package/lib/override-marks.d.ts +7 -0
- package/lib/override-marks.d.ts.map +1 -1
- package/lib/override-marks.js +14 -0
- package/lib/override-marks.js.map +1 -1
- package/lib/ship.d.ts +29 -2
- package/lib/ship.d.ts.map +1 -1
- package/lib/ship.js +34 -0
- package/lib/ship.js.map +1 -1
- package/lib/shipment.d.ts.map +1 -1
- package/lib/shipment.fixture.d.ts +8 -1
- package/lib/shipment.fixture.d.ts.map +1 -1
- package/lib/shipment.fixture.js +9 -0
- package/lib/shipment.fixture.js.map +1 -1
- package/lib/shipment.js +32 -3
- package/lib/shipment.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.27.0.tgz +0 -0
- package/rt-tools-agent-kit-0.26.0.tgz +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
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/epic-over.sh, checks/epic-table.github.mjs
|
|
4
|
+
# Guard of the stop at the end of an epic. PreToolUse on a call that takes new work.
|
|
5
|
+
#
|
|
6
|
+
# An epic used to end with the session taking the next piece of work. The owner learned that the
|
|
7
|
+
# epic was over from an ordinary report, mixed in with everything else, and had nowhere to give an
|
|
8
|
+
# order about its outcome: by the time they read it, the branch for the next work was already
|
|
9
|
+
# created. The rule of the turn carried a line about this, and it was held the same way the line
|
|
10
|
+
# about the table of tasks was held before the command — by memory, that is, sometimes.
|
|
11
|
+
#
|
|
12
|
+
# The guard stands on the call, not on the end of the turn: a turn ends with text, and a guard that
|
|
13
|
+
# took to reading text would refuse by mood. Taking work is a call — a task, a branch by a number, a
|
|
14
|
+
# column.
|
|
15
|
+
#
|
|
16
|
+
# The state of the epic is asked by the same command that prints the table for the owner. A reader
|
|
17
|
+
# of its own would diverge from the printed table in silence: it would refuse work the table itself
|
|
18
|
+
# calls unfinished.
|
|
19
|
+
#
|
|
20
|
+
# FAIL-OPEN: no `jq`, no `node`, no command, an epic that cannot be asked, any error of its own —
|
|
21
|
+
# the call is ALLOWED. A guard that jams the work when the network is gone is switched off on the
|
|
22
|
+
# first day, and the price of a miss here is one turn of the owner's attention.
|
|
23
|
+
|
|
24
|
+
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
25
|
+
# guard itself.
|
|
26
|
+
RT_GUARD_NAME=epic-stop-guard
|
|
27
|
+
|
|
28
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
29
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
30
|
+
|
|
31
|
+
rt_hook_read
|
|
32
|
+
input="$RT_HOOK_INPUT"
|
|
33
|
+
[ -z "$input" ] && exit 0
|
|
34
|
+
|
|
35
|
+
command -v jq >/dev/null 2>&1 || exit 0
|
|
36
|
+
command -v node >/dev/null 2>&1 || exit 0
|
|
37
|
+
|
|
38
|
+
tool="$(rt_hook_tool)"
|
|
39
|
+
case "$tool" in
|
|
40
|
+
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
|
|
41
|
+
*) exit 0 ;;
|
|
42
|
+
esac
|
|
43
|
+
|
|
44
|
+
cmd="$(rt_hook_cmd)"
|
|
45
|
+
[ -z "$cmd" ] && exit 0
|
|
46
|
+
|
|
47
|
+
# The universal executor of the environment passes the real command as a nested string: it is the
|
|
48
|
+
# one to judge, not the wrapper.
|
|
49
|
+
if [ "$tool" = "mcp__webstorm__execute_tool" ] && command -v perl >/dev/null 2>&1; then
|
|
50
|
+
inner="$(printf '%s' "$cmd" | perl -0ne '
|
|
51
|
+
if (/--command(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(.+))/s) {
|
|
52
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
53
|
+
}
|
|
54
|
+
' 2>/dev/null)"
|
|
55
|
+
[ -n "$inner" ] && cmd="$inner"
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# The order of the owner travels in the call itself: the guard sees the call and does not see the
|
|
59
|
+
# conversation. An empty reason is not a bypass — the line then says nothing about who allowed it.
|
|
60
|
+
if printf '%s' "$cmd" | grep -qE 'Epic-stop-skip:[[:space:]]*[^[:space:]]' 2>/dev/null; then
|
|
61
|
+
exit 0
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
# What counts as taking new work: a branch by a task number, a created task, a column moved to the
|
|
65
|
+
# working one. Everything else — a commit, a push, reading the history — is not judged: the epic is
|
|
66
|
+
# closed by exactly these three, and a wider net would refuse the work of finishing it.
|
|
67
|
+
takes_work=no
|
|
68
|
+
if printf '%s' "$cmd" | grep -qE '(checkout|switch)[[:space:]]+(-[A-Za-z]+[[:space:]]+)*-(b|c)[[:space:]]+[A-Za-z]+-[0-9]+-' 2>/dev/null; then
|
|
69
|
+
takes_work=yes
|
|
70
|
+
fi
|
|
71
|
+
if printf '%s' "$cmd" | grep -qE 'task:new|task-new\.mjs' 2>/dev/null; then
|
|
72
|
+
takes_work=yes
|
|
73
|
+
fi
|
|
74
|
+
if printf '%s' "$cmd" | grep -qE '(task:move|board\.mjs[[:space:]]+move)([^|;&]*)in-progress' 2>/dev/null; then
|
|
75
|
+
takes_work=yes
|
|
76
|
+
fi
|
|
77
|
+
[ "$takes_work" = yes ] || exit 0
|
|
78
|
+
|
|
79
|
+
# The reading of the end of an epic is shared with the two guards that judge the stop itself: written
|
|
80
|
+
# apart, the three readings would diverge and refuse each other's lawful moves. A non-zero answer
|
|
81
|
+
# means a task in work, no epic behind the branch or no way to ask — there is nothing to judge by,
|
|
82
|
+
# and the work goes on.
|
|
83
|
+
# shellcheck disable=SC1090
|
|
84
|
+
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/epic-over.sh" 2>/dev/null || exit 0
|
|
85
|
+
command -v rt_epic_over >/dev/null 2>&1 || exit 0
|
|
86
|
+
rt_epic_over || exit 0
|
|
87
|
+
|
|
88
|
+
root="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
89
|
+
checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
|
|
90
|
+
if [ -z "$checks" ] || [ "$checks" = null ]; then
|
|
91
|
+
checks=tools
|
|
92
|
+
fi
|
|
93
|
+
|
|
94
|
+
reason="Refused: the epic is over — every task of it is merged or handed over by a request, and this call takes new work. The end of an epic is a stop: print the table by «npm run epic:table» (or «node $checks/epic-table.mjs»), tell the owner what was done on each task and what confirms it, and say outright that the session waits for their orders. New work is taken by their word, not by the count of what is left."
|
|
95
|
+
|
|
96
|
+
# shellcheck disable=SC1090
|
|
97
|
+
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
98
|
+
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
99
|
+
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
100
|
+
deny_tail_text="$(rt_deny_tail "the line «Epic-stop-skip: <the word of the owner>» in the call itself; an empty reason is not accepted")"
|
|
101
|
+
[ -n "$deny_tail_text" ] && reason="${reason}
|
|
102
|
+
|
|
103
|
+
${deny_tail_text}"
|
|
104
|
+
|
|
105
|
+
jq -n --arg r "$reason" '{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:$r}}' 2>/dev/null \
|
|
106
|
+
|| printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"The epic is over: the end of an epic is a stop, not the next task."}}\n'
|
|
107
|
+
|
|
108
|
+
exit 0
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
# A conflicting PR of one's own, for the delivery guard: while at least one handed-over piece of
|
|
3
3
|
# work is marked conflicting, a new one is not taken.
|
|
4
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
|
+
#
|
|
5
8
|
# There is deliberately no `# rt-hook:` line here: the event and the call pattern are declared by
|
|
6
9
|
# the guard itself, while a helper next to it registers as no hook and decides nothing on its own.
|
|
7
10
|
# It is called from the guard, uses the guard's variables and the guard's refusal — the same way as
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
# Leaving draft, for the delivery guard: does the PR have a review, does it conflict, and was it
|
|
3
3
|
# opened by the right account.
|
|
4
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
|
+
#
|
|
5
8
|
# There is deliberately no `# rt-hook:` line here: the event and the call pattern are declared by
|
|
6
9
|
# the guard itself, while a helper next to it registers as no hook and decides nothing on its own.
|
|
7
10
|
# It is called from the guard and uses the guard's own variables — the command, the tree root, the
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Delivery conditions about the epic of a task. NOT a guard: it has no `rt-hook:` declaration and
|
|
3
|
+
# it hooks into no agent event. The delivery guard sources it — the same way it sources the task
|
|
4
|
+
# folder conditions and the signature.
|
|
5
|
+
#
|
|
6
|
+
# Why a file of its own. The subject is one — the epic a task hangs on — and it shows at two call
|
|
7
|
+
# sites: the base of a new branch and the base of the request. Together with the command parsing,
|
|
8
|
+
# the signature, the folder and the work queue it would take the guard past the file length limit,
|
|
9
|
+
# and the guard cannot be split by event: it is one whole, and its command parsing is shared.
|
|
10
|
+
#
|
|
11
|
+
# WHAT IS HERE. Two calls, both called from the delivery guard, where `fault`, `main_branch` and
|
|
12
|
+
# the profile calls are already declared. The helper reads neither the input nor the settings.
|
|
13
|
+
|
|
14
|
+
# The branch of an epic by its number: the same form as a task branch — the profile pulls the
|
|
15
|
+
# number out of a name, and the epic branch is the one whose number is the epic's.
|
|
16
|
+
#
|
|
17
|
+
# The branch is looked for among the remote refs, not the local ones: a branch that exists only on
|
|
18
|
+
# somebody's machine is a base nobody else has, and the branches of the tasks are taken from it.
|
|
19
|
+
# Several matched — none is chosen: two branches of one epic is a discrepancy of its own, and a
|
|
20
|
+
# guess here would name a base at random.
|
|
21
|
+
rt_epic_branch() {
|
|
22
|
+
_epic="$1"
|
|
23
|
+
_found=''
|
|
24
|
+
for _ref in $(git for-each-ref --format='%(refname:short)' refs/remotes/origin 2>/dev/null); do
|
|
25
|
+
_name="${_ref#origin/}"
|
|
26
|
+
[ "$(rt_task_branch_number "$_name" 2>/dev/null)" = "$_epic" ] || continue
|
|
27
|
+
_found="${_found}${_found:+ }${_name}"
|
|
28
|
+
done
|
|
29
|
+
printf '%s' "$_found"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# The base of a new task branch against the branch of its epic.
|
|
33
|
+
#
|
|
34
|
+
# The task branch is taken from the branch of the epic, and a branch taken from the main one leaves
|
|
35
|
+
# the epic half merged before its last task is done: the merge of the epic then carries nothing of
|
|
36
|
+
# that task. The guard used to judge the base against the main branch alone and let this through in
|
|
37
|
+
# silence.
|
|
38
|
+
#
|
|
39
|
+
# The freshness of the main branch is not dropped, it is moved: it is asked of the branch of the
|
|
40
|
+
# epic, and there it is fixed by one merge — while asked of the base of the task branch it made the
|
|
41
|
+
# executor either wait for the epic branch to catch up or take the base from the main one, that is,
|
|
42
|
+
# do exactly what this condition forbids.
|
|
43
|
+
#
|
|
44
|
+
# Arguments: the number of the epic, the ref the branch grows from, the name of the new branch.
|
|
45
|
+
rt_epic_base() {
|
|
46
|
+
_epic="$1"
|
|
47
|
+
_base_ref="$2"
|
|
48
|
+
_branch="$3"
|
|
49
|
+
[ -n "$_epic" ] || return 0
|
|
50
|
+
|
|
51
|
+
_epic_branch="$(rt_epic_branch "$_epic")"
|
|
52
|
+
case "$_epic_branch" in
|
|
53
|
+
'')
|
|
54
|
+
fault "the task belongs to the epic #${_epic}, and no branch of that epic is in the remote. The branch of the epic is taken before the first of its tasks and sent at once — a branch that exists only on one machine is a base nobody else has."
|
|
55
|
+
return 0
|
|
56
|
+
;;
|
|
57
|
+
*' '*)
|
|
58
|
+
fault "the epic #${_epic} has more than one branch in the remote — ${_epic_branch}. There is no telling which of them the task branches from; leave one."
|
|
59
|
+
return 0
|
|
60
|
+
;;
|
|
61
|
+
esac
|
|
62
|
+
|
|
63
|
+
git rev-parse --verify --quiet "origin/${_epic_branch}" >/dev/null 2>&1 || return 0
|
|
64
|
+
|
|
65
|
+
if ! git merge-base --is-ancestor "origin/${_epic_branch}" "$_base_ref" 2>/dev/null; then
|
|
66
|
+
fault "the branch will grow from a base that does not carry the branch of the epic «${_epic_branch}». A task branched from the main one leaves its epic half merged before the epic itself is handed in. Take the base from the epic: git fetch origin && git checkout -b ${_branch} origin/${_epic_branch}."
|
|
67
|
+
return 0
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
# The main branch is asked of the epic, not of the base: there it is fixed by one merge, and the
|
|
71
|
+
# branches of all its tasks get it at once.
|
|
72
|
+
if git rev-parse --verify --quiet "origin/${main_branch}" >/dev/null 2>&1 \
|
|
73
|
+
&& ! git merge-base --is-ancestor "origin/${main_branch}" "origin/${_epic_branch}" 2>/dev/null; then
|
|
74
|
+
_behind="$(git rev-list --count "origin/${_epic_branch}..origin/${main_branch}" 2>/dev/null)"
|
|
75
|
+
fault "the branch of the epic «${_epic_branch}» does not carry the tip of «${main_branch}» — it has moved ahead by ${_behind:-several} commits. The main branch is merged into the branch of the epic, not bypassed by taking the base from the main one: git checkout ${_epic_branch}, git merge origin/${main_branch}, and send the branch."
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
return 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# The base of a request about a task of an epic.
|
|
82
|
+
#
|
|
83
|
+
# A request of a task goes into the branch of its epic, and one opened into the main branch takes
|
|
84
|
+
# the task past the epic: the epic is then handed in without it, and the reviewer sees the edit
|
|
85
|
+
# next to everything that lies in the main branch and not in the epic. The guard let any base
|
|
86
|
+
# through and asked only that the main branch be merged in.
|
|
87
|
+
#
|
|
88
|
+
# The freshness asked here is of the epic, not of the main branch: the request goes into the epic,
|
|
89
|
+
# and it is the divergence with the epic that shows in the diff. The main branch reaches the task
|
|
90
|
+
# through the epic — that is the same order as at the creation of the branch.
|
|
91
|
+
#
|
|
92
|
+
# Arguments: the number of the epic and the text of the command.
|
|
93
|
+
rt_epic_pull_base() {
|
|
94
|
+
_epic="$1"
|
|
95
|
+
_cmd="$2"
|
|
96
|
+
[ -n "$_epic" ] || return 0
|
|
97
|
+
|
|
98
|
+
_epic_branch="$(rt_epic_branch "$_epic")"
|
|
99
|
+
case "$_epic_branch" in
|
|
100
|
+
'' | *' '*) return 0 ;;
|
|
101
|
+
esac
|
|
102
|
+
|
|
103
|
+
# The base named by the command. Absent — the hosting takes the default branch of the
|
|
104
|
+
# repository, that is the main one: the very case this condition is about.
|
|
105
|
+
_base=''
|
|
106
|
+
if command -v perl >/dev/null 2>&1; then
|
|
107
|
+
_base="$(printf '%s' "$_cmd" | perl -0ne '
|
|
108
|
+
if (/(?:^|\s)(?:--base|-B)(?:=|\s+)(?:"((?:[^"\\]|\\.)*)"|\x27([^\x27]*)\x27|(\S+))/s) {
|
|
109
|
+
print defined $1 ? $1 : (defined $2 ? $2 : $3);
|
|
110
|
+
}
|
|
111
|
+
' 2>/dev/null)"
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
if [ "$_base" != "$_epic_branch" ]; then
|
|
115
|
+
fault "the request of a task of the epic #${_epic} goes into the branch of the epic «${_epic_branch}», and the base here is ${_base:-the default branch of the repository}. A request into the main branch takes the task past its epic: the epic is handed in without it. Name the base: --base ${_epic_branch}."
|
|
116
|
+
return 0
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
if git rev-parse --verify --quiet "origin/${_epic_branch}" >/dev/null 2>&1 \
|
|
120
|
+
&& ! git merge-base --is-ancestor "origin/${_epic_branch}" HEAD 2>/dev/null; then
|
|
121
|
+
_behind="$(git rev-list --count "HEAD..origin/${_epic_branch}" 2>/dev/null)"
|
|
122
|
+
fault "the branch of the epic «${_epic_branch}» has moved ahead by ${_behind:-several} commits and is not merged into this branch. The reviewer would see the edit mixed with someone else's: git fetch origin && git merge origin/${_epic_branch}."
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
return 0
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
# The request of an epic itself: it goes into the main branch, and it opens only when the folders
|
|
129
|
+
# of all its tasks are taken apart.
|
|
130
|
+
#
|
|
131
|
+
# The folder guard reads the folder of one task — by the name of the branch — and the branch of an
|
|
132
|
+
# epic has none of its own: every folder lying there belongs to a task of the epic whose work is
|
|
133
|
+
# not closed. Merged into the main branch, such an epic carries the folders of unfinished tasks
|
|
134
|
+
# there, and the reader of the main branch has no way to tell them from current work.
|
|
135
|
+
#
|
|
136
|
+
# The epic is recognised by the label of its card, not by the shape of the branch name: the branch
|
|
137
|
+
# of an epic and the branch of a task are named alike, and the label is the only thing that tells
|
|
138
|
+
# them apart. The tree has not named the label — the condition is not judged at all.
|
|
139
|
+
#
|
|
140
|
+
# Arguments: the state of the card of the current branch, as the work queue answered it.
|
|
141
|
+
rt_epic_own_pull() {
|
|
142
|
+
_state="$1"
|
|
143
|
+
[ -n "$epic_label" ] || return 0
|
|
144
|
+
[ -n "$_state" ] || return 0
|
|
145
|
+
[ -n "$tasks_dir" ] || return 0
|
|
146
|
+
|
|
147
|
+
printf '%s' "$_state" | jq -e --arg l "$epic_label" '(.labels // []) | index($l)' >/dev/null 2>&1 || return 0
|
|
148
|
+
|
|
149
|
+
_folders="$(git ls-tree -d --name-only HEAD -- "$tasks_dir" 2>/dev/null)"
|
|
150
|
+
[ -n "$_folders" ] || return 0
|
|
151
|
+
|
|
152
|
+
# What lies in the tasks directory of the branch, one level down: the sample and the index of
|
|
153
|
+
# the directory are not folders of tasks and do not hold the request.
|
|
154
|
+
_left=''
|
|
155
|
+
for _entry in $(git ls-tree -d --name-only "HEAD:${tasks_dir}" 2>/dev/null); do
|
|
156
|
+
case "$_entry" in
|
|
157
|
+
_template | _draft-*) continue ;;
|
|
158
|
+
esac
|
|
159
|
+
_left="${_left}${_left:+, }${_entry}"
|
|
160
|
+
done
|
|
161
|
+
[ -n "$_left" ] || return 0
|
|
162
|
+
|
|
163
|
+
fault "the branch of the epic still carries the folders of its tasks — ${_left}. The request of an epic opens when the last of its folders is taken apart: merged as it is, the epic takes the folders of unfinished work into the main branch, and the reader has no way to tell them from current work."
|
|
164
|
+
|
|
165
|
+
return 0
|
|
166
|
+
}
|
|
167
|
+
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
# The signature of a machine commit for the delivery guard: whose commit it is, whether it is signed
|
|
3
3
|
# with the right mail and what to do if it is not.
|
|
4
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
|
+
#
|
|
5
8
|
# There is deliberately no `# rt-hook:` line here: the event and the call pattern are declared by the
|
|
6
9
|
# guard itself, and a helper next to it is not registered as a hook and decides nothing alone. It is
|
|
7
10
|
# called from the guard and uses the guard variables — the command, the declared mail, the name of
|
|
@@ -75,6 +78,33 @@ if printf '%s' "$cmd" | grep -qE "${RT_CMD_BOUND}git([[:space:]]|\$)" \
|
|
|
75
78
|
bot_login="${commit_email%%@*}"
|
|
76
79
|
bot_login="${bot_login##*+}"
|
|
77
80
|
|
|
81
|
+
# The repair named in the refusal is itself a commit, and without this exception the guard
|
|
82
|
+
# refused it together with everything else: the divergence is removed only by a commit,
|
|
83
|
+
# and a commit is refused while the divergence is there. The circle closed, and there was
|
|
84
|
+
# no way out of it by the guard's own means — the second advice, rewriting the whole
|
|
85
|
+
# contribution, demands a clean working tree, and saving the work is a commit too.
|
|
86
|
+
#
|
|
87
|
+
# The repair is recognised not by trusting the line — the note above rightly refuses that —
|
|
88
|
+
# but by the declared mail: the guard looks in the call for exactly the address it declared
|
|
89
|
+
# itself, in both variables at once, next to a rewrite of the last commit. Faking that means
|
|
90
|
+
# putting the right signature, that is doing precisely what the guard demands.
|
|
91
|
+
#
|
|
92
|
+
# The quotes are stripped before matching: the same command is typed with double quotes,
|
|
93
|
+
# with single ones and without any, and a sign counting on one form stays silent on the
|
|
94
|
+
# other two — that is, refuses the repair again and says nothing about why.
|
|
95
|
+
# A push is never a repair, whatever stands in its variables: the divergence has to be
|
|
96
|
+
# removed BEFORE the contribution leaves, and after it only a force push helps. Without
|
|
97
|
+
# this line a compound call carrying both the rewrite and the push would take the whole
|
|
98
|
+
# exception onto the push as well.
|
|
99
|
+
repair=''
|
|
100
|
+
probe="$(printf '%s' "$cmd" | tr -d "\"'")"
|
|
101
|
+
if ! printf '%s' "$probe" | sed -E 's/git[[:space:]]+stash[[:space:]]+push/git stash/g' | grep -qE '(^|[[:space:]])push([[:space:]]|$)' \
|
|
102
|
+
&& printf '%s' "$probe" | grep -qF "GIT_AUTHOR_EMAIL=${commit_email}" \
|
|
103
|
+
&& printf '%s' "$probe" | grep -qF "GIT_COMMITTER_EMAIL=${commit_email}" \
|
|
104
|
+
&& printf '%s' "$probe" | grep -qE '(^|[[:space:]])--amend([[:space:]]|$)'; then
|
|
105
|
+
repair=1
|
|
106
|
+
fi
|
|
107
|
+
|
|
78
108
|
strangers=''
|
|
79
109
|
while IFS="$(printf '\t')" read -r short author email; do
|
|
80
110
|
[ -z "$short" ] && continue
|
|
@@ -112,12 +142,12 @@ $(git log --format='%h%x09%an%x09%ae' "origin/${main_branch}..HEAD" 2>/dev/null)
|
|
|
112
142
|
EOF
|
|
113
143
|
fi
|
|
114
144
|
|
|
115
|
-
[ -n "$unknown" ] \
|
|
145
|
+
[ -n "$unknown" ] && [ -z "$repair" ] \
|
|
116
146
|
&& deny "BLOCKED: a commit of the contribution is signed by an account the tree never declared. Known are the machine account ${commit_email} and the emails of people named by the profile; everything else the hosting attributes to whoever owns that address, and from inside the history the miss is invisible. Diverging: ${unknown}. Rewrite the signature before the push, after it only a force push fixes this:
|
|
117
147
|
the last commit — GIT_AUTHOR_EMAIL=\"${commit_email}\" GIT_COMMITTER_EMAIL=\"${commit_email}\" git commit --amend --no-edit --reset-author
|
|
118
148
|
the whole contribution of the branch — git filter-branch -f --env-filter 'GIT_AUTHOR_EMAIL=\"${commit_email}\"; GIT_COMMITTER_EMAIL=\"${commit_email}\"' origin/${main_branch}..HEAD"
|
|
119
149
|
|
|
120
|
-
[ -n "$strangers" ] \
|
|
150
|
+
[ -n "$strangers" ] && [ -z "$repair" ] \
|
|
121
151
|
&& deny "BLOCKED: a machine commit is signed by an email other than the one the tree declared. The hosting matches a service address by the number in it, and a commit with a foreign number it attributes to an outside person — from inside the miss is invisible, because the name of the account next to it is right. Diverging: ${strangers}. Declared: ${commit_email} — the email is taken from there, not typed from memory. Rewrite the signature before the push, after it only a force push fixes this:
|
|
122
152
|
the last commit — GIT_AUTHOR_NAME=\"${bot_login}\" GIT_AUTHOR_EMAIL=\"${commit_email}\" GIT_COMMITTER_NAME=\"${bot_login}\" GIT_COMMITTER_EMAIL=\"${commit_email}\" git commit --amend --no-edit --reset-author
|
|
123
153
|
the whole contribution of the branch — git filter-branch -f --env-filter 'GIT_AUTHOR_EMAIL=\"${commit_email}\"; GIT_COMMITTER_EMAIL=\"${commit_email}\"' origin/${main_branch}..HEAD"
|
|
@@ -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-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-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
|
|
@@ -107,6 +107,7 @@ task_move="${RT_TASK_MOVE_CMD:-npm run task:move}"
|
|
|
107
107
|
# a tree names its columns in its own words, and an invented name would match nothing and would
|
|
108
108
|
# silently switch the check off.
|
|
109
109
|
backlog_column="${RT_BOARD_BACKLOG:-}"
|
|
110
|
+
epic_label="${RT_BOARD_EPIC_LABEL:-}"
|
|
110
111
|
task_bot="${RT_TASK_BOT:-}"
|
|
111
112
|
# The identity of the call arrives through the environment, not as a word in the line: from the
|
|
112
113
|
# command text only one thing is visible — whether the token is substituted explicitly. A tree that
|
|
@@ -168,6 +169,12 @@ fault() {
|
|
|
168
169
|
# shellcheck disable=SC1090
|
|
169
170
|
[ -f "$rt_hooks_dir/git-guard-delivery-folder.sh" ] && . "$rt_hooks_dir/git-guard-delivery-folder.sh" 2>/dev/null
|
|
170
171
|
|
|
172
|
+
# The epic of a task: the same technique as with the folder. It is sourced before the branch block —
|
|
173
|
+
# there the base of a new branch is judged, and with an epic it is judged against the branch of the
|
|
174
|
+
# epic. No helper — the epic is not judged, and the base is asked against the main branch as before.
|
|
175
|
+
# shellcheck disable=SC1090
|
|
176
|
+
[ -f "$rt_hooks_dir/git-guard-delivery-epic.sh" ] && . "$rt_hooks_dir/git-guard-delivery-epic.sh" 2>/dev/null
|
|
177
|
+
|
|
171
178
|
# A conflicting PR of one's own: the same technique as with the folder and the signature. The helper
|
|
172
179
|
# is called before all the tiers below and judges not the readiness of this work but the right to
|
|
173
180
|
# take the next one: while what was handed over conflicts, it is fixed by the first action of the
|
|
@@ -238,7 +245,11 @@ if [ -n "$branch_arg" ]; then
|
|
|
238
245
|
if [ -n "$number_arg" ]; then
|
|
239
246
|
rt_task_branch_ok "$branch_arg" \
|
|
240
247
|
|| 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
|
+
state=''
|
|
241
249
|
check_task "$number_arg" "the branch «${branch_arg}»"
|
|
250
|
+
# The epic of the task: with one, the base is judged against the branch of the epic, and the
|
|
251
|
+
# freshness of the main branch moves there too — see `git-guard-delivery-epic.sh`.
|
|
252
|
+
epic_arg="$(printf '%s' "$state" | jq -r '.epic // empty' 2>/dev/null)"
|
|
242
253
|
|
|
243
254
|
# The delivery conditions already known here are checked here. After the work is done, the
|
|
244
255
|
# base is fixed by a merge with conflict resolution, and the commit signature by rewriting
|
|
@@ -249,7 +260,9 @@ if [ -n "$branch_arg" ]; then
|
|
|
249
260
|
# base fresh — `git checkout -b <branch> origin/<main>` — would be forbidden.
|
|
250
261
|
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)"
|
|
251
262
|
base_ref="${base_arg:-HEAD}"
|
|
252
|
-
if
|
|
263
|
+
if [ -n "$epic_arg" ] && command -v rt_epic_base >/dev/null 2>&1; then
|
|
264
|
+
rt_epic_base "$epic_arg" "$base_ref" "$branch_arg"
|
|
265
|
+
elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
|
|
253
266
|
&& git rev-parse --verify --quiet "$base_ref" >/dev/null 2>&1 \
|
|
254
267
|
&& ! git merge-base --is-ancestor "origin/${main_branch}" "$base_ref" 2>/dev/null; then
|
|
255
268
|
behind="$(git rev-list --count "${base_ref}..origin/${main_branch}" 2>/dev/null)"
|
|
@@ -327,6 +340,16 @@ rt_task_branch_ok "$branch" \
|
|
|
327
340
|
|
|
328
341
|
number="$(rt_task_branch_number "$branch")"
|
|
329
342
|
|
|
343
|
+
# The work queue is asked here and not at the end of the block: the epic of the task decides what
|
|
344
|
+
# the base of the request is judged against, and that judging stands above. The call is one — the
|
|
345
|
+
# state stays in `state` and the tail of the block reads the same answer.
|
|
346
|
+
state=''
|
|
347
|
+
check_task "$number" "the request from the branch «${branch}»" yes
|
|
348
|
+
epic_pull="$(printf '%s' "$state" | jq -r '.epic // empty' 2>/dev/null)"
|
|
349
|
+
# The branch of an epic itself: its request goes into the main branch, and it opens only when the
|
|
350
|
+
# folders of all its tasks are taken apart.
|
|
351
|
+
command -v rt_epic_own_pull >/dev/null 2>&1 && rt_epic_own_pull "$state"
|
|
352
|
+
|
|
330
353
|
title=''
|
|
331
354
|
if command -v perl >/dev/null 2>&1; then
|
|
332
355
|
title="$(printf '%s' "$cmd" | perl -0ne '
|
|
@@ -358,7 +381,9 @@ fi
|
|
|
358
381
|
# the remote reference: without it, silence means only "the local reference is not older than the
|
|
359
382
|
# branch", while it reads as "the main branch is merged in". No answer from the network — a silent
|
|
360
383
|
# skip; the waiting limit is set by git variables, an external `timeout` is not on every machine.
|
|
361
|
-
if
|
|
384
|
+
if [ -n "$epic_pull" ] && command -v rt_epic_pull_base >/dev/null 2>&1; then
|
|
385
|
+
rt_epic_pull_base "$epic_pull" "$cmd"
|
|
386
|
+
elif git rev-parse --verify --quiet "refs/remotes/origin/${main_branch}" >/dev/null 2>&1 \
|
|
362
387
|
&& ! git merge-base --is-ancestor "origin/${main_branch}" HEAD 2>/dev/null; then
|
|
363
388
|
behind="$(git rev-list --count "HEAD..origin/${main_branch}" 2>/dev/null)"
|
|
364
389
|
fault "«${main_branch}» has moved ahead by ${behind:-several} commits and is not merged into the branch. A PR from a diverged branch shows the reviewer the edit mixed with someone else, and the checks on it run from a stale base. Merge it in and repeat: git fetch origin && git merge origin/${main_branch} — the order and the resolving of the conflict are in the pattern git-workflow-merge."
|
|
@@ -437,7 +462,6 @@ if [ -n "$pull_body_section" ]; then
|
|
|
437
462
|
fi
|
|
438
463
|
fi
|
|
439
464
|
|
|
440
|
-
check_task "$number" "the request from the branch «${branch}»" yes
|
|
441
465
|
|
|
442
466
|
# The task folder is taken apart before the PR opens, not after the approval: the owner merges as
|
|
443
467
|
# soon as he sees green, and no room is left for a closing commit — three times in a row the folder
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# rt-hook: PreToolUse Edit|Write|MultiEdit
|
|
3
|
-
# Requires: rules/task-flow.md, hooks/deny-tail.sh
|
|
2
|
+
# rt-hook: PreToolUse Edit|Write|MultiEdit|Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
|
|
3
|
+
# Requires: rules/task-flow.md, hooks/deny-tail.sh, hooks/write-targets.sh
|
|
4
4
|
# Handover entry guard: a session started from a handover edits no file until the work-conduct rule
|
|
5
5
|
# is loaded.
|
|
6
6
|
#
|
|
@@ -26,9 +26,27 @@ input="$RT_HOOK_INPUT"
|
|
|
26
26
|
[ -z "$input" ] && exit 0
|
|
27
27
|
command -v jq >/dev/null 2>&1 || exit 0
|
|
28
28
|
|
|
29
|
+
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
30
|
+
|
|
31
|
+
# The write targets are taken by the shared parse: the same sign serves the guard of the place of an
|
|
32
|
+
# edit, and two copies of it would let through different shapes of a write. No file — a silent
|
|
33
|
+
# default remains, so that the guard does not break on an incomplete layout.
|
|
34
|
+
# shellcheck disable=SC1090
|
|
35
|
+
[ -f "$rt_hooks_dir/write-targets.sh" ] && . "$rt_hooks_dir/write-targets.sh" 2>/dev/null
|
|
36
|
+
command -v rt_write_targets >/dev/null 2>&1 || rt_write_targets() { cat >/dev/null; }
|
|
37
|
+
|
|
29
38
|
tool="$(rt_hook_tool)"
|
|
30
39
|
case "$tool" in
|
|
31
40
|
Edit | Write | MultiEdit) ;;
|
|
41
|
+
# A write by a shell command is the same edit of a file: the same session with the name of the
|
|
42
|
+
# shell instead of the name of the edit worked past the rule whole. A command that writes
|
|
43
|
+
# nothing the guard does not wake: it must not get in the way of reading the tree, which is
|
|
44
|
+
# exactly what the order of entry begins with.
|
|
45
|
+
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool)
|
|
46
|
+
cmd="$(rt_hook_cmd)"
|
|
47
|
+
[ -z "$cmd" ] && exit 0
|
|
48
|
+
[ -n "$(printf '%s' "$cmd" | rt_write_targets)" ] || exit 0
|
|
49
|
+
;;
|
|
32
50
|
*) exit 0 ;;
|
|
33
51
|
esac
|
|
34
52
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# rt-hook: PreToolUse Edit|Write|MultiEdit
|
|
3
|
-
# Requires: checks/check-prose-style.mjs, hooks/deny-tail.sh
|
|
2
|
+
# rt-hook: PreToolUse Edit|Write|MultiEdit|Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
|
|
3
|
+
# Requires: checks/check-prose-style.mjs, hooks/deny-tail.sh, hooks/write-targets.sh
|
|
4
4
|
# Prose guard: officialese and words that are not written in this tree do not reach the file.
|
|
5
5
|
#
|
|
6
6
|
# The rule about texts demands plain words, and this was held only by the memory of whoever writes:
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
# separate piece of work, and refusing an edit of a neighbouring line because of it would make the
|
|
12
12
|
# guard bypassed out of necessity.
|
|
13
13
|
#
|
|
14
|
+
# A write by a shell command is judged the same as one by the edit tool: the same text with the name
|
|
15
|
+
# of the shell instead of the name of the edit gave silence, and a document written by a heredoc
|
|
16
|
+
# went past the wording convention whole. The path is taken by the shared parse of write targets,
|
|
17
|
+
# and the new text is the body of the command — the written text stands inside it.
|
|
18
|
+
#
|
|
14
19
|
# FAIL-OPEN: no node, no check, a foreign tool, not `.md` → pass.
|
|
15
20
|
|
|
16
21
|
# Its own name in the observations: the refusal is recorded by the shared deny tail, not by the
|
|
@@ -26,13 +31,34 @@ input="$RT_HOOK_INPUT"
|
|
|
26
31
|
command -v jq >/dev/null 2>&1 || exit 0
|
|
27
32
|
command -v node >/dev/null 2>&1 || exit 0
|
|
28
33
|
|
|
34
|
+
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
35
|
+
|
|
36
|
+
# The write targets are taken by the shared parse: the same sign serves the guard of the place of an
|
|
37
|
+
# edit, and two copies of it would let through different shapes of a write. No file — a silent
|
|
38
|
+
# default remains, so that the guard does not break on an incomplete layout.
|
|
39
|
+
# shellcheck disable=SC1090
|
|
40
|
+
[ -f "$rt_hooks_dir/write-targets.sh" ] && . "$rt_hooks_dir/write-targets.sh" 2>/dev/null
|
|
41
|
+
command -v rt_write_targets >/dev/null 2>&1 || rt_write_targets() { cat >/dev/null; }
|
|
42
|
+
|
|
29
43
|
tool="$(rt_hook_tool)"
|
|
30
44
|
case "$tool" in
|
|
31
|
-
Edit | Write | MultiEdit)
|
|
45
|
+
Edit | Write | MultiEdit)
|
|
46
|
+
path="$(rt_hook_file)"
|
|
47
|
+
added="$(printf '%s' "$input" | jq -r '.tool_input.new_string // .tool_input.content // ([.tool_input.edits[]?.new_string] | join("\n")) // empty' 2>/dev/null)"
|
|
48
|
+
;;
|
|
49
|
+
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool)
|
|
50
|
+
cmd="$(rt_hook_cmd)"
|
|
51
|
+
[ -z "$cmd" ] && exit 0
|
|
52
|
+
# The first document among the write targets. A command writing several is judged by one of
|
|
53
|
+
# them: the text is one for the whole command, and a second refusal would repeat the first.
|
|
54
|
+
path="$(printf '%s' "$cmd" | rt_write_targets | grep -m1 '\.md$')"
|
|
55
|
+
# The new text is the body of the command: the written text stands inside it, and the
|
|
56
|
+
# findings of the check name the very lines that go into the file.
|
|
57
|
+
added="$cmd"
|
|
58
|
+
;;
|
|
32
59
|
*) exit 0 ;;
|
|
33
60
|
esac
|
|
34
61
|
|
|
35
|
-
path="$(rt_hook_file)"
|
|
36
62
|
case "$path" in
|
|
37
63
|
*.md) ;;
|
|
38
64
|
*) exit 0 ;;
|
|
@@ -41,13 +67,10 @@ esac
|
|
|
41
67
|
# The archive and the task folders are not judged: the archive is not edited at all, and the
|
|
42
68
|
# progress is written in haste and lives until the merge.
|
|
43
69
|
case "$path" in
|
|
44
|
-
*/docs/archive/* | */docs/tasks/*) exit 0 ;;
|
|
70
|
+
*/docs/archive/* | */docs/tasks/* | docs/archive/* | docs/tasks/*) exit 0 ;;
|
|
45
71
|
esac
|
|
46
72
|
|
|
47
|
-
added="$(printf '%s' "$input" | jq -r '.tool_input.new_string // .tool_input.content // ([.tool_input.edits[]?.new_string] | join("\n")) // empty' 2>/dev/null)"
|
|
48
73
|
[ -z "$added" ] && exit 0
|
|
49
|
-
|
|
50
|
-
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
51
74
|
check=""
|
|
52
75
|
for candidate in "$rt_hooks_dir/../checks/check-prose-style.mjs" "$rt_hooks_dir/../rt-kit/checks/check-prose-style.mjs" "${CLAUDE_PROJECT_DIR:-.}/tools/check-prose-style.mjs"; do
|
|
53
76
|
[ -f "$candidate" ] && check="$candidate" && break
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# rt-hook: PreToolUse Edit|Write|MultiEdit|mcp__webstorm__create_new_file
|
|
3
|
-
# Requires: hooks/profile-check.sh, hooks/deny-tail.sh
|
|
2
|
+
# rt-hook: PreToolUse Edit|Write|MultiEdit|mcp__webstorm__create_new_file|Bash|mcp__webstorm__execute_terminal_command|mcp__webstorm__execute_tool
|
|
3
|
+
# Requires: hooks/profile-check.sh, hooks/deny-tail.sh, hooks/write-targets.sh
|
|
4
4
|
# Anchor guard for end-to-end tests. PreToolUse on a markup edit.
|
|
5
5
|
#
|
|
6
6
|
# Specs address elements only through this attribute. Styling classes change together with the
|
|
@@ -38,15 +38,33 @@ input="$RT_HOOK_INPUT"
|
|
|
38
38
|
command -v jq >/dev/null 2>&1 || exit 0
|
|
39
39
|
command -v perl >/dev/null 2>&1 || exit 0
|
|
40
40
|
|
|
41
|
+
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
42
|
+
|
|
43
|
+
# The write targets are taken by the shared parse: the same sign serves the guard of the place of an
|
|
44
|
+
# edit, and two copies of it would let through different shapes of a write. No file — a silent
|
|
45
|
+
# default remains, so that the guard does not break on an incomplete layout.
|
|
46
|
+
# shellcheck disable=SC1090
|
|
47
|
+
[ -f "$rt_hooks_dir/write-targets.sh" ] && . "$rt_hooks_dir/write-targets.sh" 2>/dev/null
|
|
48
|
+
command -v rt_write_targets >/dev/null 2>&1 || rt_write_targets() { cat >/dev/null; }
|
|
49
|
+
|
|
41
50
|
tool="$(rt_hook_tool)"
|
|
51
|
+
cmd=""
|
|
42
52
|
case "$tool" in
|
|
43
53
|
# The IDE tool creates a file from the same two pieces of data, only names them differently —
|
|
44
54
|
# without this branch markup was created past all the checks.
|
|
45
|
-
Edit | Write | MultiEdit | mcp__webstorm__create_new_file)
|
|
55
|
+
Edit | Write | MultiEdit | mcp__webstorm__create_new_file)
|
|
56
|
+
path="$(printf '%s' "$input" | jq -r '.tool_input.file_path // .tool_input.pathInProject // empty' 2>/dev/null)"
|
|
57
|
+
;;
|
|
58
|
+
# Markup written by a shell command is judged the same: the same text with the name of the shell
|
|
59
|
+
# instead of the name of the edit gave silence, and a screen written by a heredoc got into the
|
|
60
|
+
# tree without a single anchor.
|
|
61
|
+
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool)
|
|
62
|
+
cmd="$(rt_hook_cmd)"
|
|
63
|
+
[ -z "$cmd" ] && exit 0
|
|
64
|
+
path="$(printf '%s' "$cmd" | rt_write_targets | grep -m1 '\.html$')"
|
|
65
|
+
;;
|
|
46
66
|
*) exit 0 ;;
|
|
47
67
|
esac
|
|
48
|
-
|
|
49
|
-
path="$(printf '%s' "$input" | jq -r '.tool_input.file_path // .tool_input.pathInProject // empty' 2>/dev/null)"
|
|
50
68
|
# The path from the IDE arrives relative to the tree root, while all the samples below are
|
|
51
69
|
# written from the application directory. Bring it to one form once, so the rules do not double.
|
|
52
70
|
case "$path" in
|
|
@@ -59,7 +77,6 @@ case "$path" in
|
|
|
59
77
|
esac
|
|
60
78
|
|
|
61
79
|
# The tree profile: first the package default, over it the project override, if there is one.
|
|
62
|
-
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
63
80
|
for profile in "$rt_hooks_dir/../rt-kit/defaults/project.sh" "$rt_hooks_dir/../defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/defaults/project.sh" "${CLAUDE_PROJECT_DIR:-.}/.claude/rt-kit/project.sh"; do
|
|
64
81
|
# shellcheck disable=SC1090
|
|
65
82
|
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
@@ -83,11 +100,16 @@ if [ -n "${RT_QA_SKIP_RE:-}" ] && printf '%s' "$path" | grep -qE "$RT_QA_SKIP_RE
|
|
|
83
100
|
fi
|
|
84
101
|
|
|
85
102
|
# Only the NEW text is checked: what already lay in the file was not created by this edit, and
|
|
86
|
-
# demanding an anchor from someone else's line means refusing the edit of a neighbouring one.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
103
|
+
# demanding an anchor from someone else's line means refusing the edit of a neighbouring one. For a
|
|
104
|
+
# shell command the new text is the body of the command: the written markup stands inside it.
|
|
105
|
+
if [ -n "$cmd" ]; then
|
|
106
|
+
added="$cmd"
|
|
107
|
+
else
|
|
108
|
+
added="$(printf '%s' "$input" | jq -r '
|
|
109
|
+
[ .tool_input.content?, .tool_input.text?, .tool_input.new_string?, (.tool_input.edits[]?.new_string) ]
|
|
110
|
+
| map(select(. != null)) | join("\n")
|
|
111
|
+
' 2>/dev/null)"
|
|
112
|
+
fi
|
|
91
113
|
[ -z "$added" ] && exit 0
|
|
92
114
|
|
|
93
115
|
decorative="$(rt_needs rt_qa_decorative qa-dataid-guard && rt_qa_decorative 2>/dev/null)"
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
# Parsing the applicability sign of a rule article. A helper: it declares no event of its own, and
|
|
3
3
|
# is sourced by whoever needs the text of an article — the rules gate in its refusal.
|
|
4
4
|
#
|
|
5
|
+
# NOT a guard: it has no `rt-hook:` declaration and hooks into no agent event. The rules gate
|
|
6
|
+
# sources it: an article says whether it applies itself, and the parsing of that lives here.
|
|
7
|
+
#
|
|
5
8
|
# A rule weighs from twenty to sixty kilobytes, while one of its articles covers a particular edit.
|
|
6
9
|
# A refusal that calls the whole rule pays the full price of the rule for the decision — and teaches
|
|
7
10
|
# the wrong thing: it is cheaper to read nothing extra, that is, to work less well explored.
|