@rt-tools/agent-kit 0.26.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/agents/cargo-writer.md +54 -0
- package/assets/checks/board-epic-link.github.mjs +29 -0
- package/assets/checks/board-epic-plan.github.mjs +86 -0
- package/assets/checks/board-epics.github.mjs +217 -69
- package/assets/checks/board-long-work.github.mjs +5 -1
- package/assets/checks/board-pull-state.github.mjs +163 -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-glossary.mjs +10 -2
- package/assets/checks/check-lib-layers.mjs +24 -1
- package/assets/checks/check-prose-style.mjs +19 -3
- package/assets/checks/check-reuse.mjs +26 -2
- package/assets/checks/check-schema-drift.mjs +19 -3
- package/assets/checks/check-specs.mjs +8 -1
- package/assets/checks/epic-table.github.mjs +268 -0
- package/assets/checks/lib-boundaries.mjs +2 -2
- package/assets/checks/lib-common.mjs +46 -0
- package/assets/checks/lib-manifests.mjs +18 -13
- package/assets/checks/rt-kit-checks.config.mjs +19 -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/specs-for.mjs +214 -0
- package/assets/checks/task-new.github.mjs +237 -6
- package/assets/commands/night.md +115 -0
- package/assets/defaults/gate-map.sh +20 -5
- package/assets/defaults/project.sh +13 -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 +64 -31
- package/assets/hooks/epic-over.sh +49 -0
- package/assets/hooks/epic-stop-guard.sh +108 -0
- package/assets/hooks/exam-guard.sh +10 -10
- package/assets/hooks/git-guard-delivery-conflict.sh +56 -1
- package/assets/hooks/git-guard-delivery-draft.sh +10 -6
- 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-tree.sh +50 -0
- package/assets/hooks/git-guard-delivery.sh +71 -27
- package/assets/hooks/git-guard-discard.sh +144 -0
- package/assets/hooks/git-guard-push-tests.sh +36 -16
- 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/reuse-first-guard.sh +29 -4
- package/assets/hooks/rule-article.sh +3 -0
- package/assets/hooks/rule-source-guard.sh +17 -2
- package/assets/hooks/skill-gate-layers.sh +4 -0
- package/assets/hooks/skill-gate.sh +7 -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 +21 -2
- package/assets/hooks/stand-login-guard.sh +3 -0
- package/assets/hooks/turn-exit-guard.sh +55 -67
- package/assets/hooks/turn-exit-patterns.sh +28 -1
- package/assets/hooks/turn-exit-verdict.sh +84 -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 +37 -7
- package/assets/laws/verifiability.md +22 -4
- 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 +44 -18
- package/assets/patterns/git-workflow-pr.gitlab.md +1 -1
- package/assets/patterns/git-workflow-stack.md +32 -9
- package/assets/patterns/status-report-table.github.md +11 -0
- package/assets/patterns/task-flow-close.md +96 -90
- package/assets/patterns/task-flow-start.md +40 -26
- package/assets/patterns/ts-procedure.md +6 -0
- package/assets/pitfalls/agent-kit.md +19 -0
- package/assets/pitfalls/git-workflow.github.md +44 -0
- package/assets/pitfalls/task-flow.md +25 -23
- package/assets/rules/autonomous-work.md +15 -3
- package/assets/rules/browser-verification.md +8 -0
- package/assets/rules/deploy-flow.github.md +6 -0
- package/assets/rules/doc-style.md +13 -4
- package/assets/rules/git-workflow.azure.md +10 -0
- package/assets/rules/git-workflow.github.md +144 -126
- package/assets/rules/git-workflow.gitlab.md +10 -0
- package/assets/rules/lib-layers.md +11 -0
- package/assets/rules/spec-driven.md +17 -1
- package/assets/rules/status-report.md +7 -0
- package/assets/rules/task-flow.md +78 -54
- package/assets/rules/testing.md +7 -0
- package/assets/rules/turn-conduct.md +30 -3
- package/assets/samples/tasks/_template/plan.md +4 -1
- package/assets/skills/agent-kit.md +40 -25
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +9 -2
- 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/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/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/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/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/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/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 +40 -14
- package/lib/shipment.js.map +1 -1
- package/package.json +1 -1
- package/rt-tools-agent-kit-0.28.0.tgz +0 -0
- package/rt-tools-agent-kit-0.26.0.tgz +0 -0
|
@@ -3,17 +3,31 @@
|
|
|
3
3
|
# Requires: hooks/deny-tail.sh
|
|
4
4
|
# Guard against a second dev server. PreToolUse.
|
|
5
5
|
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
6
|
+
# Who raises the stands is decided by the tree, not by the guard. The profile key
|
|
7
|
+
# RT_STANDS_RAISED_BY next to the stand list holds two values, and an unset key reads as `owner`:
|
|
8
|
+
# a tree that sets nothing keeps the behaviour it has today.
|
|
9
|
+
#
|
|
10
|
+
# owner — the applications are already raised by the owner, and every check through the browser
|
|
11
|
+
# goes there. Any raise is refused: a second instance takes an extra port, serves a
|
|
12
|
+
# different build and leads the investigation astray — a difference between two servers
|
|
13
|
+
# reads as a defect of the edit. On top of that, a build started in passing silently
|
|
14
|
+
# kills the server already raised.
|
|
15
|
+
# session — nobody raises the stands here but the session itself. There is left of the guard the
|
|
16
|
+
# one refusal that is right in such a tree: a raise over a port already taken. Under
|
|
17
|
+
# `owner` a tree where nobody raises anything gets the whole check through the browser
|
|
18
|
+
# refused, and the guard is dropped whole — together with the refusal that was right.
|
|
10
19
|
#
|
|
11
20
|
# Everything that RAISES a server is refused. Builds, tests, linters, requests to raised ports and
|
|
12
21
|
# looking at listeners pass.
|
|
13
22
|
#
|
|
14
23
|
# Where exactly the applications are raised is known to the project profile:
|
|
15
24
|
# .claude/rt-kit/project.sh, variable RT_STANDS. No profile — the refusal text stays general, the
|
|
16
|
-
# guard itself works.
|
|
25
|
+
# guard itself works; under `session` there are no ports to judge by, and the call passes.
|
|
26
|
+
#
|
|
27
|
+
# FAIL-OPEN: an unrecognised command, no way to ask the ports, a raise the tree knows nothing of —
|
|
28
|
+
# the call goes through. The price of a miss here is a second server on a busy port; the price of a
|
|
29
|
+
# wrong refusal is a guard nobody keeps. Under `session` the absence of the port
|
|
30
|
+
# listing tool reads the same way: there is nothing to learn a taken port by, and the call passes.
|
|
17
31
|
|
|
18
32
|
# Its own name in the observations: the refusal is written by the shared deny tail, not by the
|
|
19
33
|
# guard itself.
|
|
@@ -26,6 +40,49 @@ rt_hook_read
|
|
|
26
40
|
input="$RT_HOOK_INPUT"
|
|
27
41
|
|
|
28
42
|
tool="$(rt_hook_tool)"
|
|
43
|
+
|
|
44
|
+
# The tree profile: first the package default, and over it the project override, if there is one.
|
|
45
|
+
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
46
|
+
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
|
|
47
|
+
# shellcheck disable=SC1090
|
|
48
|
+
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
49
|
+
done
|
|
50
|
+
stands="${RT_STANDS:-}"
|
|
51
|
+
raiser="${RT_STANDS_RAISED_BY:-owner}"
|
|
52
|
+
|
|
53
|
+
# shellcheck disable=SC1090
|
|
54
|
+
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
55
|
+
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
56
|
+
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
57
|
+
|
|
58
|
+
# A port of the stand list somebody is listening on. Only these are judged under `session`: a port
|
|
59
|
+
# the tree never named belongs to no stand of it, and a refusal over it would refuse the session's
|
|
60
|
+
# own work.
|
|
61
|
+
taken_stand_port() {
|
|
62
|
+
local port
|
|
63
|
+
command -v lsof >/dev/null 2>&1 || return 1
|
|
64
|
+
for port in $(printf '%s' "$stands" | grep -oE ':[0-9]{2,5}' | tr -d ':' | sort -u); do
|
|
65
|
+
lsof -nP -iTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1 && { printf '%s' "$port"; return 0; }
|
|
66
|
+
done
|
|
67
|
+
return 1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
deny() {
|
|
71
|
+
local port
|
|
72
|
+
if [ "$raiser" = "session" ]; then
|
|
73
|
+
# Nobody raises the stands here but the session: a free port is its own business, and only
|
|
74
|
+
# a taken one is worth a refusal.
|
|
75
|
+
port="$(taken_stand_port)" || exit 0
|
|
76
|
+
echo "$1 On port ${port} somebody is already listening — a second instance answers with a build of its own and leads the investigation astray. Ask what it is: lsof -nP -iTCP:${port} -sTCP:LISTEN. $(rt_deny_tail)" >&2
|
|
77
|
+
exit 2
|
|
78
|
+
fi
|
|
79
|
+
if [ -n "$stands" ]; then
|
|
80
|
+
echo "$1 The applications are already raised by the owner: ${stands} — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
|
|
81
|
+
else
|
|
82
|
+
echo "$1 The applications are already raised by the owner — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
|
|
83
|
+
fi
|
|
84
|
+
exit 2
|
|
85
|
+
}
|
|
29
86
|
case "$tool" in
|
|
30
87
|
Bash | mcp__webstorm__execute_terminal_command | mcp__webstorm__execute_tool) ;;
|
|
31
88
|
# A ready run configuration does not show the command line — only its name is visible. Hence
|
|
@@ -40,16 +97,14 @@ case "$tool" in
|
|
|
40
97
|
file="$(printf '%s' "$input" | jq -r '.tool_input.filePath // empty' 2>/dev/null)"
|
|
41
98
|
case "$file" in
|
|
42
99
|
*/package.json|package.json)
|
|
43
|
-
|
|
44
|
-
exit 2 ;;
|
|
100
|
+
deny "A launch of a script straight from the manifest: the guard sees only the file and the line, not the script itself, so it cannot tell raising a server from a build. If a build or a test is needed, run them by a command in the terminal." ;;
|
|
45
101
|
esac
|
|
46
102
|
exit 0
|
|
47
103
|
fi
|
|
48
104
|
# The word "start" without a boundary also caught "restart", which raises no server.
|
|
49
105
|
case "$(printf '%s' "$name" | tr '[:upper:]' '[:lower:]')" in
|
|
50
106
|
*serve*|*dev*|start*|*\ start*|*:start*)
|
|
51
|
-
|
|
52
|
-
exit 2 ;;
|
|
107
|
+
deny "The configuration «${name}» looks like raising a development server. If the configuration does something else, run it by a command: by the name alone the guard does not see the content." ;;
|
|
53
108
|
esac
|
|
54
109
|
exit 0 ;;
|
|
55
110
|
*) exit 0 ;;
|
|
@@ -77,28 +132,6 @@ case "$cmd" in
|
|
|
77
132
|
printf '%s' "$cmd" | grep -qE '(^|[[:space:]])git[[:space:]]+daemon([[:space:]]|$)' || exit 0 ;;
|
|
78
133
|
esac
|
|
79
134
|
|
|
80
|
-
# The tree profile: first the package default, and over it the project override, if there is one.
|
|
81
|
-
rt_hooks_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
82
|
-
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
|
|
83
|
-
# shellcheck disable=SC1090
|
|
84
|
-
[ -f "$profile" ] && . "$profile" 2>/dev/null
|
|
85
|
-
done
|
|
86
|
-
stands="${RT_STANDS:-}"
|
|
87
|
-
|
|
88
|
-
# shellcheck disable=SC1090
|
|
89
|
-
[ -f "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" ] \
|
|
90
|
-
&& . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/deny-tail.sh" 2>/dev/null
|
|
91
|
-
command -v rt_deny_tail >/dev/null 2>&1 || rt_deny_tail() { :; }
|
|
92
|
-
|
|
93
|
-
deny() {
|
|
94
|
-
if [ -n "$stands" ]; then
|
|
95
|
-
echo "$1 The applications are already raised by the owner: ${stands} — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
|
|
96
|
-
else
|
|
97
|
-
echo "$1 The applications are already raised by the owner — check those. Do not raise an instance of your own; if a port does not answer, tell the owner instead of launching a second one. $(rt_deny_tail)" >&2
|
|
98
|
-
fi
|
|
99
|
-
exit 2
|
|
100
|
-
}
|
|
101
|
-
|
|
102
135
|
# The runners are listed outright. A group meaning "any word before the name" refused even a note
|
|
103
136
|
# saying that the server is raised by the owner.
|
|
104
137
|
RUNNER='((npx|pnpm|yarn|bun|npm)([[:space:]]+(exec|run|dlx))?[[:space:]]+)?'
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# The reading "the epic is over". NOT a guard: it has no `rt-hook:` declaration and hooks into no
|
|
3
|
+
# agent event. The guards that judge the end of an epic source it themselves.
|
|
4
|
+
#
|
|
5
|
+
# Why it lives apart. Three guards ask one and the same question, and each from its own side: one
|
|
6
|
+
# refuses taking new work after the end of an epic, and two others refuse the very stop that the end
|
|
7
|
+
# of an epic requires — a turn without the next task taken and a turn that says the session waits for
|
|
8
|
+
# a word. Written three times, the reading would diverge three ways, and the guards would refuse each
|
|
9
|
+
# other's lawful moves.
|
|
10
|
+
#
|
|
11
|
+
# The state is asked by the command that prints the table for the owner: a reader of its own would
|
|
12
|
+
# diverge from the printed table in silence. The call is not cheap — it goes to the hosting — so the
|
|
13
|
+
# Stop guards ask it right before a refusal, not on every turn.
|
|
14
|
+
#
|
|
15
|
+
# ZERO means the epic is over: not one of its tasks is left unfinished. Any other answer — a task in
|
|
16
|
+
# work, no epic behind the branch, no way to ask the hosting — is not zero, and the caller works as
|
|
17
|
+
# it did before this reading existed.
|
|
18
|
+
|
|
19
|
+
rt_epic_over() {
|
|
20
|
+
command -v jq >/dev/null 2>&1 || return 1
|
|
21
|
+
command -v node >/dev/null 2>&1 || return 1
|
|
22
|
+
|
|
23
|
+
local here root checks table left
|
|
24
|
+
# The turn names the directory it goes from, and a Stop guard is called from wherever the host
|
|
25
|
+
# stands: taken from the process, the tree would be a foreign one — or none at all.
|
|
26
|
+
here="."
|
|
27
|
+
if command -v rt_hook_cwd >/dev/null 2>&1; then
|
|
28
|
+
here="$(rt_hook_cwd 2>/dev/null)"
|
|
29
|
+
[ -z "$here" ] && here="."
|
|
30
|
+
fi
|
|
31
|
+
|
|
32
|
+
root="$(cd "$here" 2>/dev/null && git rev-parse --show-toplevel 2>/dev/null)"
|
|
33
|
+
[ -z "$root" ] && return 1
|
|
34
|
+
|
|
35
|
+
# Where the checks of the package lie is named by the tree: the directory differs from tree to
|
|
36
|
+
# tree, and a name written here would be right in the first one and wrong in the second.
|
|
37
|
+
checks="$(jq -r '.layout.checks // "tools"' "$root/.claude/rt-kit.json" 2>/dev/null)"
|
|
38
|
+
if [ -z "$checks" ] || [ "$checks" = null ]; then
|
|
39
|
+
checks=tools
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
table="$root/$checks/epic-table.mjs"
|
|
43
|
+
[ -f "$table" ] || return 1
|
|
44
|
+
|
|
45
|
+
left="$(cd "$root" && node "$table" --unfinished 2>/dev/null)" || return 1
|
|
46
|
+
[ -n "$left" ] && return 1
|
|
47
|
+
|
|
48
|
+
return 0
|
|
49
|
+
}
|
|
@@ -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
|
|
@@ -159,8 +159,9 @@ verdict="$(jq -s -r '
|
|
|
159
159
|
# echoing the same line or reading a file with it passes the guard, and the real verdict
|
|
160
160
|
# does not.
|
|
161
161
|
["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
|
|
162
|
-
| [.[] | select(.type == "assistant") | (.message.content // [])[]
|
|
163
|
-
| select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
|
|
162
|
+
| ([.[] | select(.type == "assistant") | (.message.content // [])[]
|
|
163
|
+
| select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
|
|
164
|
+
| {key: (.id // ""), value: true}] | from_entries) as $muted
|
|
164
165
|
|
|
165
166
|
| [ .[]
|
|
166
167
|
# The assistant text is never a verdict: writing the needed line in a reply costs one
|
|
@@ -169,8 +170,7 @@ verdict="$(jq -s -r '
|
|
|
169
170
|
elif .type == "user" then
|
|
170
171
|
([ ((.message.content // []) | if type == "array" then .[] else empty end
|
|
171
172
|
| select(.type == "tool_result")
|
|
172
|
-
| select((
|
|
173
|
-
| $id == null or ($muted | index($id)) == null)
|
|
173
|
+
| select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
|
|
174
174
|
| .content | textof),
|
|
175
175
|
((.message.content // "") | if type == "string" then . else "" end),
|
|
176
176
|
# The call result field: the same record, another form. Discarded only when
|
|
@@ -179,7 +179,7 @@ verdict="$(jq -s -r '
|
|
|
179
179
|
| if ($rec.toolUseResult // null) == null then ""
|
|
180
180
|
elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
|
|
181
181
|
| select(.type == "tool_result") | (.tool_use_id // "")]
|
|
182
|
-
| map(
|
|
182
|
+
| map($muted[.] // false) | any) then ""
|
|
183
183
|
else ($rec.toolUseResult | textof) end)
|
|
184
184
|
] | join("\n"))
|
|
185
185
|
# Host records — the role completion notice and the attachment: the host chooses their
|
|
@@ -208,8 +208,9 @@ if [ "$ready" = "1" ]; then
|
|
|
208
208
|
# commands and the tool results, and the second exam in such a tree did not count: five
|
|
209
209
|
# rounds with a full verdict let no edit through.
|
|
210
210
|
["Bash", "Read", "Grep", "Glob", "Edit", "Write", "MultiEdit", "NotebookEdit"] as $mute
|
|
211
|
-
| [.[] | select(.type == "assistant") | (.message.content // [])[]
|
|
212
|
-
| select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
|
|
211
|
+
| ([.[] | select(.type == "assistant") | (.message.content // [])[]
|
|
212
|
+
| select(.type == "tool_use") | select(.name as $n | $mute | index($n) != null)
|
|
213
|
+
| {key: (.id // ""), value: true}] | from_entries) as $muted
|
|
213
214
|
|
|
214
215
|
# A record gives two strings: the command — by it the moment of opening the PR is found —
|
|
215
216
|
# and the verdict, checked by the same rules as in the wide selection. The order is the
|
|
@@ -222,15 +223,14 @@ if [ "$ready" = "1" ]; then
|
|
|
222
223
|
elif .type == "user" then
|
|
223
224
|
([ ((.message.content // []) | if type == "array" then .[] else empty end
|
|
224
225
|
| select(.type == "tool_result")
|
|
225
|
-
| select((
|
|
226
|
-
| $id == null or ($muted | index($id)) == null)
|
|
226
|
+
| select((.tool_use_id // "") | if . == "" then true else ($muted[.] | not) end)
|
|
227
227
|
| .content | textof),
|
|
228
228
|
((.message.content // "") | if type == "string" then . else "" end),
|
|
229
229
|
(. as $rec
|
|
230
230
|
| if ($rec.toolUseResult // null) == null then ""
|
|
231
231
|
elif ([($rec.message.content // []) | if type == "array" then .[] else empty end
|
|
232
232
|
| select(.type == "tool_result") | (.tool_use_id // "")]
|
|
233
|
-
| map(
|
|
233
|
+
| map($muted[.] // false) | any) then ""
|
|
234
234
|
else ($rec.toolUseResult | textof) end)
|
|
235
235
|
] | join("\n"))
|
|
236
236
|
else tostring end)
|
|
@@ -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
|
|
@@ -27,6 +30,14 @@
|
|
|
27
30
|
# uncertainty — and it computes it again after every edit of the main branch — and reading
|
|
28
31
|
# uncertainty as a conflict would mean refusing work at every fresh tip.
|
|
29
32
|
#
|
|
33
|
+
# The list is split into one's own and a neighbour's. The machine account is one per tree, and
|
|
34
|
+
# several sessions work over the tree at once: by the account alone one's own work is
|
|
35
|
+
# indistinguishable from a neighbour's. A session credited with a neighbour's conflict cannot fix
|
|
36
|
+
# it — the branch is led by somebody else, they hold their own commits on it, and a merge from the
|
|
37
|
+
# side returns a red audit — so such a refusal has no lawful move at all. One's own branch is the
|
|
38
|
+
# one this working copy led: the copy's own record of switches answers that, while the branch refs
|
|
39
|
+
# are shared by every copy of the tree.
|
|
40
|
+
#
|
|
30
41
|
# FAIL-OPEN: no profile function, no network, no machine account — the tier is skipped.
|
|
31
42
|
|
|
32
43
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/utf8.sh" 2>/dev/null || true
|
|
@@ -35,6 +46,31 @@
|
|
|
35
46
|
# word search over the whole line.
|
|
36
47
|
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hook-input.sh" 2>/dev/null || true
|
|
37
48
|
|
|
49
|
+
# Did this working copy lead the branch. The record of switches belongs to the copy, while the
|
|
50
|
+
# branch refs are shared by every copy of the tree: by a ref one's own branch is indistinguishable
|
|
51
|
+
# from a neighbour's. An unnamed branch counts as one's own — a list without a branch says nothing
|
|
52
|
+
# to split by, and the former behaviour is the safer of the two.
|
|
53
|
+
rt_delivery_led_branch() {
|
|
54
|
+
named="$1"
|
|
55
|
+
[ -z "$named" ] && return 0
|
|
56
|
+
[ "$named" = "$(git -C "$root" rev-parse --abbrev-ref HEAD 2>/dev/null)" ] && return 0
|
|
57
|
+
git -C "$root" reflog HEAD -n 400 2>/dev/null \
|
|
58
|
+
| awk -v branch="$named" '
|
|
59
|
+
/checkout: moving from / { if ($NF == branch) { found = 1 } }
|
|
60
|
+
END { exit found ? 0 : 1 }
|
|
61
|
+
'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# The note about a neighbour's conflict, printed from the exit of the guard by whichever path it
|
|
65
|
+
# leaves — but only where nothing was refused: two JSON documents in a row are read as plain text,
|
|
66
|
+
# that is, as no refusal at all. A refusal carries the note inside itself.
|
|
67
|
+
rt_delivery_note_out() {
|
|
68
|
+
[ -n "${rt_delivery_said:-}" ] && return 0
|
|
69
|
+
[ -z "${rt_delivery_neighbour_note:-}" ] && return 0
|
|
70
|
+
jq -n --arg c "$rt_delivery_neighbour_note" \
|
|
71
|
+
'{hookSpecificOutput:{hookEventName:"PreToolUse",additionalContext:$c}}' 2>/dev/null
|
|
72
|
+
}
|
|
73
|
+
|
|
38
74
|
rt_delivery_conflict() {
|
|
39
75
|
# The sign of taking work is read from the text of the command and stands first: the query goes
|
|
40
76
|
# to the network, and paying for it on every shell command is not allowed.
|
|
@@ -68,13 +104,32 @@ rt_delivery_conflict() {
|
|
|
68
104
|
[ -z "$stuck" ] && return 0
|
|
69
105
|
|
|
70
106
|
listed=''
|
|
107
|
+
neighbour=''
|
|
71
108
|
while IFS= read -r line; do
|
|
72
109
|
[ -z "$line" ] && continue
|
|
73
|
-
|
|
110
|
+
# The line is «#<number> <branch>»: the branch stands last, and by it the copy is asked.
|
|
111
|
+
if rt_delivery_led_branch "${line##* }"; then
|
|
112
|
+
listed="${listed}${listed:+
|
|
74
113
|
}— ${line}"
|
|
114
|
+
else
|
|
115
|
+
neighbour="${neighbour}${neighbour:+
|
|
116
|
+
}— ${line} — the branch is led by another session"
|
|
117
|
+
fi
|
|
75
118
|
done <<EOF
|
|
76
119
|
${stuck}
|
|
77
120
|
EOF
|
|
121
|
+
|
|
122
|
+
# A neighbour's conflict is said aloud and refuses nothing: this session has nothing to fix it
|
|
123
|
+
# with, and the one who leads the branch learns of it from nowhere else. The note is left for
|
|
124
|
+
# the guard to print — it has one output point, and a second JSON document next to the first
|
|
125
|
+
# would be read as plain text, that is, as no refusal at all.
|
|
126
|
+
if [ -n "$neighbour" ]; then
|
|
127
|
+
rt_delivery_neighbour_note="A conflicting request of a neighbouring session stands, and there is nothing here to fix it with:
|
|
128
|
+
|
|
129
|
+
${neighbour}
|
|
130
|
+
|
|
131
|
+
The branch is led by another session and holds its own commits: a merge of the main branch from the side takes that work away. Tell the owner about the request and take work as usual."
|
|
132
|
+
fi
|
|
78
133
|
[ -z "$listed" ] && return 0
|
|
79
134
|
|
|
80
135
|
deny "BLOCKED: ${taking} while a conflicting request of your own stands. What was handed over conflicts with the main branch, and a person cannot merge it:
|
|
@@ -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
|
|
@@ -62,15 +65,16 @@ rt_delivery_draft_ready() {
|
|
|
62
65
|
printf '%s' "$pull" | jq -e '.conflicting' >/dev/null 2>&1 \
|
|
63
66
|
&& fault "the request${pull_name} conflicts with the main branch. Merge it into your branch, resolve the conflict and repeat: a lifted draft reads as «ready to merge», and this request cannot be merged."
|
|
64
67
|
|
|
65
|
-
# The author of the PR.
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
#
|
|
69
|
-
#
|
|
68
|
+
# The author of the PR. The clash that breaks the review — the author named as the
|
|
69
|
+
# reviewer — is already caught by the condition above: the hosting silently does not
|
|
70
|
+
# create such a review request, so the PR comes here with no review at all. What is
|
|
71
|
+
# left here is to name a foreign account aloud: a PR opened by other than the machine
|
|
72
|
+
# one is lawful, and silence about it is indistinguishable from a check that did not
|
|
73
|
+
# fire. A tree that named no machine account says nothing.
|
|
70
74
|
if [ -n "$task_bot" ]; then
|
|
71
75
|
pull_author="$(printf '%s' "$pull" | jq -r '.author // empty' 2>/dev/null)"
|
|
72
76
|
[ -n "$pull_author" ] && [ "$pull_author" != "$task_bot" ] \
|
|
73
|
-
&&
|
|
77
|
+
&& printf 'the delivery guard: the request%s was opened by the account «%s», not the machine one «%s». It has a review, so the draft is lifted.\n' "$pull_name" "$pull_author" "$task_bot" >&2
|
|
74
78
|
fi
|
|
75
79
|
fi
|
|
76
80
|
fi
|