@muggleai/works 5.20.0-staging.142 → 5.20.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/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/hooks/README.md +17 -2
- package/dist/plugin/hooks/hooks.json +4 -88
- package/dist/plugin/scripts/guardrail-build-followthrough-gate.sh +13 -23
- package/dist/plugin/scripts/guardrail-build-router.sh +12 -7
- package/dist/plugin/scripts/guardrail-capability-claim.sh +27 -17
- package/dist/plugin/scripts/guardrail-classify-gate.sh +12 -7
- package/dist/plugin/scripts/guardrail-comment-reply-gate.sh +15 -26
- package/dist/plugin/scripts/guardrail-debug-path-gate.sh +14 -24
- package/dist/plugin/scripts/guardrail-dispatch.sh +34 -0
- package/dist/plugin/scripts/guardrail-e2e-gate.sh +13 -21
- package/dist/plugin/scripts/guardrail-lib.sh +91 -0
- package/dist/plugin/scripts/guardrail-offer-ran.sh +12 -20
- package/dist/plugin/scripts/guardrail-pr-opened.sh +12 -7
- package/dist/plugin/scripts/guardrail-pr-terminal.sh +12 -7
- package/dist/plugin/scripts/guardrail-record-comment-replies.sh +12 -7
- package/dist/plugin/scripts/guardrail-record-stage-read.sh +12 -7
- package/dist/plugin/scripts/guardrail-record-stage-signals.sh +12 -7
- package/dist/plugin/scripts/guardrail-record-tests.sh +12 -7
- package/dist/plugin/scripts/guardrail-report-format.sh +12 -7
- package/dist/plugin/scripts/guardrail-resolve-gate.sh +12 -7
- package/dist/plugin/scripts/guardrail-skill-stages.sh +27 -18
- package/dist/plugin/scripts/guardrail-stage-gate.sh +14 -24
- package/dist/plugin/scripts/guardrail-terminal-gate.sh +13 -20
- package/dist/plugin/scripts/guardrail-walkthrough-gate.sh +14 -22
- package/dist/plugin/scripts/guardrail-walkthrough-heading.sh +12 -7
- package/dist/plugin/scripts/guardrail-watch-gate.sh +14 -25
- package/dist/plugin/scripts/guardrails.mjs +29 -0
- package/dist/release-manifest.json +3 -3
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/hooks/README.md +17 -2
- package/plugin/hooks/hooks.json +4 -88
- package/plugin/scripts/guardrail-build-followthrough-gate.sh +13 -23
- package/plugin/scripts/guardrail-build-router.sh +12 -7
- package/plugin/scripts/guardrail-capability-claim.sh +27 -17
- package/plugin/scripts/guardrail-classify-gate.sh +12 -7
- package/plugin/scripts/guardrail-comment-reply-gate.sh +15 -26
- package/plugin/scripts/guardrail-debug-path-gate.sh +14 -24
- package/plugin/scripts/guardrail-dispatch.sh +34 -0
- package/plugin/scripts/guardrail-e2e-gate.sh +13 -21
- package/plugin/scripts/guardrail-lib.sh +91 -0
- package/plugin/scripts/guardrail-offer-ran.sh +12 -20
- package/plugin/scripts/guardrail-pr-opened.sh +12 -7
- package/plugin/scripts/guardrail-pr-terminal.sh +12 -7
- package/plugin/scripts/guardrail-record-comment-replies.sh +12 -7
- package/plugin/scripts/guardrail-record-stage-read.sh +12 -7
- package/plugin/scripts/guardrail-record-stage-signals.sh +12 -7
- package/plugin/scripts/guardrail-record-tests.sh +12 -7
- package/plugin/scripts/guardrail-report-format.sh +12 -7
- package/plugin/scripts/guardrail-resolve-gate.sh +12 -7
- package/plugin/scripts/guardrail-skill-stages.sh +27 -18
- package/plugin/scripts/guardrail-stage-gate.sh +14 -24
- package/plugin/scripts/guardrail-terminal-gate.sh +13 -20
- package/plugin/scripts/guardrail-walkthrough-gate.sh +14 -22
- package/plugin/scripts/guardrail-walkthrough-heading.sh +12 -7
- package/plugin/scripts/guardrail-watch-gate.sh +14 -25
- package/plugin/scripts/guardrails.mjs +29 -0
|
@@ -17,12 +17,17 @@ set -uo pipefail
|
|
|
17
17
|
# hand-listed set instructs the user to run an echo that can never register,
|
|
18
18
|
# then blocks the turn anyway. Over-matching here only costs a needless spawn.
|
|
19
19
|
# Degrades to {}.
|
|
20
|
-
payload="$(cat)"
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
22
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
23
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
24
|
+
|
|
25
|
+
GUARDRAIL_SUBCOMMAND="record-comment-replies"
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
guardrail_wants() {
|
|
28
|
+
guardrail_payload_matches 'reviewThreads|merge_requests/[0-9]+/discussions|comments/[0-9]+/replies|discussions/[A-Za-z0-9_-]+/notes|MUGGLE_[A-Z0-9_]+_SKIP'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
32
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
33
|
+
fi
|
|
@@ -10,12 +10,17 @@ set -uo pipefail
|
|
|
10
10
|
# never one outside it, so source reads and repo docs return {} in-shell. Both
|
|
11
11
|
# path separators are accepted: a Windows payload carries escaped backslashes.
|
|
12
12
|
# Degrades to {}.
|
|
13
|
-
payload="$(cat)"
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
15
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
16
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
17
|
+
|
|
18
|
+
GUARDRAIL_SUBCOMMAND="record-stage-read"
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
guardrail_wants() {
|
|
21
|
+
guardrail_payload_matches '"file_path"[[:space:]]*:[[:space:]]*"[^"]*[/\\]+skills[/\\]+[^"]*\.md"'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
25
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
26
|
+
fi
|
|
@@ -12,12 +12,17 @@ set -uo pipefail
|
|
|
12
12
|
# echo that can never register, then blocks the turn anyway. Anchoring the
|
|
13
13
|
# marker to a leading `echo` stays in guardrails.mjs; over-matching here only
|
|
14
14
|
# costs a needless spawn. Degrades to {}.
|
|
15
|
-
payload="$(cat)"
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
17
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
18
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
19
|
+
|
|
20
|
+
GUARDRAIL_SUBCOMMAND="record-stage-signals"
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
guardrail_wants() {
|
|
23
|
+
guardrail_payload_matches 'MUGGLE_[A-Z0-9_]+_SKIP|muggle.*(telemetry-event-emit|user-feedback-create)'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
27
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
28
|
+
fi
|
|
@@ -20,12 +20,17 @@ set -uo pipefail
|
|
|
20
20
|
# the user to run an echo that could never reach the recorder, then blocked the
|
|
21
21
|
# turn anyway. Anchoring the marker to a leading `echo` stays in guardrails.mjs;
|
|
22
22
|
# over-matching here only costs a needless spawn.
|
|
23
|
-
payload="$(cat)"
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
25
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
26
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
27
|
+
|
|
28
|
+
GUARDRAIL_SUBCOMMAND="record-tests"
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
guardrail_wants() {
|
|
31
|
+
guardrail_payload_matches '(pnpm|npm|yarn)[[:space:]]+(run[[:space:]]+)?test|jest|vitest|pytest|go[[:space:]]+test|cargo[[:space:]]+test|muggle.*(execute|test-generation|replay)|muggle-local-telemetry-skill-emit|MUGGLE_[A-Z0-9_]+_SKIP|gh[[:space:]]+pr[[:space:]]+(comment|create|edit)|issues/comments/[0-9]'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
35
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
36
|
+
fi
|
|
@@ -16,12 +16,17 @@ set -uo pipefail
|
|
|
16
16
|
# can't be overwritten with hand-written markdown afterwards, and a pre-filter
|
|
17
17
|
# on `gh pr` alone left that bypass wide open. Degrades to {} so it never blocks
|
|
18
18
|
# an unrelated command.
|
|
19
|
-
payload="$(cat)"
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
21
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
22
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
23
|
+
|
|
24
|
+
GUARDRAIL_SUBCOMMAND="report-gate"
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
guardrail_wants() {
|
|
27
|
+
guardrail_payload_matches 'gh[[:space:]]+pr[[:space:]]+(comment|create|edit)|issues/comments/[0-9]'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
31
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
32
|
+
fi
|
|
@@ -11,12 +11,17 @@ set -uo pipefail
|
|
|
11
11
|
# and `resolved=false` through to guardrails.mjs, which allows both. Cheaper to
|
|
12
12
|
# pay one cold start on the rare inverse call than to encode the boundary twice
|
|
13
13
|
# and have the two drift. Degrades to {} so it never blocks an unrelated command.
|
|
14
|
-
payload="$(cat)"
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
16
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
17
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
18
|
+
|
|
19
|
+
GUARDRAIL_SUBCOMMAND="resolve-gate"
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
guardrail_wants() {
|
|
22
|
+
guardrail_payload_matches 'resolveReviewThread|resolved=(true|false)'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
26
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
27
|
+
fi
|
|
@@ -12,24 +12,33 @@ set -uo pipefail
|
|
|
12
12
|
# input with no skill name, returns {} in-shell. Every key the resolver reads is
|
|
13
13
|
# accepted here — a key matched in one and missed in the other makes the gate
|
|
14
14
|
# dead code on exactly the harness that names it that way. Degrades to {}.
|
|
15
|
-
payload="$(cat)"
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
17
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
18
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
| grep -oE '"(skill|skillName|name|command)"[[:space:]]*:[[:space:]]*"[^"]*"' \
|
|
21
|
-
| sed -E 's/.*:[[:space:]]*"([^"]*)".*/\1/'); do
|
|
22
|
-
# A namespaced invocation (`muggle:muggle-test`) and a slash command
|
|
23
|
-
# (`/muggle-test`) both name the same skill directory.
|
|
24
|
-
skill="${candidate##*:}"
|
|
25
|
-
skill="${skill#/}"
|
|
26
|
-
case "$skill" in
|
|
27
|
-
"" | *[!A-Za-z0-9._-]*) continue ;;
|
|
28
|
-
esac
|
|
29
|
-
if [ -f "$root/skills/$skill/SKILL.md" ]; then
|
|
30
|
-
printf '%s' "$payload" | node "${root}/scripts/guardrails.mjs" skill-stages 2>/dev/null || printf '{}'
|
|
31
|
-
exit 0
|
|
32
|
-
fi
|
|
33
|
-
done
|
|
20
|
+
GUARDRAIL_SUBCOMMAND="skill-stages"
|
|
34
21
|
|
|
35
|
-
|
|
22
|
+
guardrail_wants() {
|
|
23
|
+
local root="${CLAUDE_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}"
|
|
24
|
+
local key_pattern='"(skill|skillName|name|command)"[[:space:]]*:[[:space:]]*"([^"]*)"'
|
|
25
|
+
local remaining="$GUARDRAIL_PAYLOAD"
|
|
26
|
+
local candidate_words candidate skill
|
|
27
|
+
while [[ $remaining =~ $key_pattern ]]; do
|
|
28
|
+
remaining="${remaining#*"${BASH_REMATCH[0]}"}"
|
|
29
|
+
read -r -a candidate_words <<<"${BASH_REMATCH[2]}"
|
|
30
|
+
for candidate in "${candidate_words[@]}"; do
|
|
31
|
+
skill="${candidate##*:}"
|
|
32
|
+
skill="${skill#/}"
|
|
33
|
+
case "$skill" in
|
|
34
|
+
"" | *[!A-Za-z0-9._-]*) continue ;;
|
|
35
|
+
esac
|
|
36
|
+
[[ -f $root/skills/$skill/SKILL.md ]] && return 0
|
|
37
|
+
done
|
|
38
|
+
done
|
|
39
|
+
return 1
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
43
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
44
|
+
fi
|
|
@@ -14,31 +14,21 @@ set -uo pipefail
|
|
|
14
14
|
# skill declared stages, so the state file is absent or mandatoryStages is empty
|
|
15
15
|
# and we return {} in-shell. The read-vs-declared comparison runs in
|
|
16
16
|
# guardrails.mjs. Degrades to {}.
|
|
17
|
-
payload="$(cat)"
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
[
|
|
21
|
-
|
|
18
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
19
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
20
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
# macOS/Linux and on most Git Bash setups; fall back to converting USERPROFILE
|
|
25
|
-
# when HOME doesn't hold the state dir (some Windows shells point HOME elsewhere).
|
|
26
|
-
home="${HOME:-}"
|
|
27
|
-
if [ ! -d "$home/.muggle-ai" ] && command -v cygpath >/dev/null 2>&1 && [ -n "${USERPROFILE:-}" ]; then
|
|
28
|
-
home="$(cygpath -u "$USERPROFILE" 2>/dev/null || printf '%s' "$home")"
|
|
29
|
-
fi
|
|
22
|
+
GUARDRAIL_SUBCOMMAND="stage-gate"
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|| grep -q '"stageSkipped": true' "$state_file"; then
|
|
39
|
-
printf '{}'
|
|
40
|
-
exit 0
|
|
41
|
-
fi
|
|
24
|
+
guardrail_wants() {
|
|
25
|
+
guardrail_load_state \
|
|
26
|
+
&& guardrail_state_has '"mandatoryStages"' \
|
|
27
|
+
&& ! guardrail_state_has '"mandatoryStages": []' \
|
|
28
|
+
&& ! guardrail_state_has '"stageReleased": true' \
|
|
29
|
+
&& ! guardrail_state_has '"stageSkipped": true'
|
|
30
|
+
}
|
|
42
31
|
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
33
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
34
|
+
fi
|
|
@@ -12,27 +12,20 @@ set -uo pipefail
|
|
|
12
12
|
# only spawns Node when a terminal PR is actually pending. On the overwhelming
|
|
13
13
|
# majority of turns no PR went terminal, so the state file is absent or
|
|
14
14
|
# terminalPending is empty and we return {} in-shell. Degrades to {}.
|
|
15
|
-
payload="$(cat)"
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
[
|
|
19
|
-
|
|
16
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
17
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
18
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
# macOS/Linux and on most Git Bash setups; fall back to converting USERPROFILE
|
|
23
|
-
# when HOME doesn't hold the state dir (some Windows shells point HOME elsewhere).
|
|
24
|
-
home="${HOME:-}"
|
|
25
|
-
if [ ! -d "$home/.muggle-ai" ] && command -v cygpath >/dev/null 2>&1 && [ -n "${USERPROFILE:-}" ]; then
|
|
26
|
-
home="$(cygpath -u "$USERPROFILE" 2>/dev/null || printf '%s' "$home")"
|
|
27
|
-
fi
|
|
20
|
+
GUARDRAIL_SUBCOMMAND="terminal-gate"
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fi
|
|
22
|
+
guardrail_wants() {
|
|
23
|
+
guardrail_load_state \
|
|
24
|
+
&& guardrail_state_has '"terminalPending"' \
|
|
25
|
+
&& ! guardrail_state_has '"terminalReleased": true' \
|
|
26
|
+
&& ! guardrail_state_has '"terminalPending": []'
|
|
27
|
+
}
|
|
36
28
|
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
30
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
31
|
+
fi
|
|
@@ -14,29 +14,21 @@ set -uo pipefail
|
|
|
14
14
|
# or e2eRun is unset, so we return {} in-shell and never pay Node cold-start —
|
|
15
15
|
# which also means the gate's `gh` lookups only ever run on turns that could
|
|
16
16
|
# genuinely owe a walkthrough. Degrades to {}.
|
|
17
|
-
payload="$(cat)"
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
[
|
|
21
|
-
|
|
18
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
19
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
20
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
# macOS/Linux and on most Git Bash setups; fall back to converting USERPROFILE
|
|
25
|
-
# when HOME doesn't hold the state dir (some Windows shells point HOME elsewhere).
|
|
26
|
-
home="${HOME:-}"
|
|
27
|
-
if [ ! -d "$home/.muggle-ai" ] && command -v cygpath >/dev/null 2>&1 && [ -n "${USERPROFILE:-}" ]; then
|
|
28
|
-
home="$(cygpath -u "$USERPROFILE" 2>/dev/null || printf '%s' "$home")"
|
|
29
|
-
fi
|
|
22
|
+
GUARDRAIL_SUBCOMMAND="walkthrough-gate"
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
exit 0
|
|
39
|
-
fi
|
|
24
|
+
guardrail_wants() {
|
|
25
|
+
guardrail_load_state \
|
|
26
|
+
&& guardrail_state_has '"e2eRun": true' \
|
|
27
|
+
&& ! guardrail_state_has '"walkthroughPosted": true' \
|
|
28
|
+
&& ! guardrail_state_has '"walkthroughReleased": true' \
|
|
29
|
+
&& ! guardrail_state_has '"walkthroughSkipped": true'
|
|
30
|
+
}
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
33
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
34
|
+
fi
|
|
@@ -13,12 +13,17 @@ set -uo pipefail
|
|
|
13
13
|
# Must stay synchronous (only a sync PreToolUse hook can deny). The same keyword
|
|
14
14
|
# pre-filter keeps Node off the hot path for ordinary commands, and any failure
|
|
15
15
|
# degrades to {} so an unrelated command is never blocked.
|
|
16
|
-
payload="$(cat)"
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
18
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
19
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
20
|
+
|
|
21
|
+
GUARDRAIL_SUBCOMMAND="walkthrough-heading-gate"
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
guardrail_wants() {
|
|
24
|
+
guardrail_payload_matches 'gh[[:space:]]+pr[[:space:]]+(comment|create|edit)|issues/comments/[0-9]'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
28
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
29
|
+
fi
|
|
@@ -10,32 +10,21 @@ set -uo pipefail
|
|
|
10
10
|
# runs in guardrails.mjs. On the overwhelming majority of turns no PR was opened,
|
|
11
11
|
# so the state file is absent or prsHandled is empty and we return {} in-shell,
|
|
12
12
|
# never paying Node cold-start. Degrades to {}.
|
|
13
|
-
payload="$(cat)"
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
[
|
|
17
|
-
|
|
14
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
15
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
16
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
# macOS/Linux and on most Git Bash setups; fall back to converting USERPROFILE
|
|
21
|
-
# when HOME doesn't hold the state dir (some Windows shells point HOME elsewhere).
|
|
22
|
-
home="${HOME:-}"
|
|
23
|
-
if [ ! -d "$home/.muggle-ai" ] && command -v cygpath >/dev/null 2>&1 && [ -n "${USERPROFILE:-}" ]; then
|
|
24
|
-
home="$(cygpath -u "$USERPROFILE" 2>/dev/null || printf '%s' "$home")"
|
|
25
|
-
fi
|
|
18
|
+
GUARDRAIL_SUBCOMMAND="watch-gate"
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|| grep -q '"watchReleased": true' "$state_file" \
|
|
35
|
-
|| grep -q '"watchSkipped": true' "$state_file"; then
|
|
36
|
-
printf '{}'
|
|
37
|
-
exit 0
|
|
38
|
-
fi
|
|
20
|
+
guardrail_wants() {
|
|
21
|
+
guardrail_load_state \
|
|
22
|
+
&& guardrail_state_has '"prsHandled"' \
|
|
23
|
+
&& ! guardrail_state_has '"prsHandled": []' \
|
|
24
|
+
&& ! guardrail_state_has '"watchReleased": true' \
|
|
25
|
+
&& ! guardrail_state_has '"watchSkipped": true'
|
|
26
|
+
}
|
|
39
27
|
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
29
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
30
|
+
fi
|
|
@@ -51,6 +51,7 @@ var CALL_FAILURE_SIGNALS = [
|
|
|
51
51
|
];
|
|
52
52
|
var FORGE_TERMINAL_CMD = /\b(?:gh\s+pr\s+(?:merge|close|reopen)|glab\s+mr\s+(?:merge|close|reopen))\b/;
|
|
53
53
|
var WATCH_TERMINAL_CMD = /pr-watch-(?:loop|arm)\.sh/;
|
|
54
|
+
var MERGED_GATE_OUTPUT_SEPARATOR = "\n\n";
|
|
54
55
|
|
|
55
56
|
// src/guardrails/store/fileLock.ts
|
|
56
57
|
function isProcessAlive(pid) {
|
|
@@ -1425,6 +1426,23 @@ function denyTool(reason, host2) {
|
|
|
1425
1426
|
}
|
|
1426
1427
|
});
|
|
1427
1428
|
}
|
|
1429
|
+
function mergeHookOutputs(gateOutputs, host2) {
|
|
1430
|
+
const parsedOutputs = gateOutputs.flatMap((gateOutput) => {
|
|
1431
|
+
try {
|
|
1432
|
+
return [JSON.parse(gateOutput)];
|
|
1433
|
+
} catch {
|
|
1434
|
+
return [];
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
const denyReasons = parsedOutputs.filter((parsed) => parsed.hookSpecificOutput?.permissionDecision === "deny").map((parsed) => parsed.hookSpecificOutput?.permissionDecisionReason ?? "").filter(Boolean);
|
|
1438
|
+
if (denyReasons.length > 0) return denyTool(denyReasons.join(MERGED_GATE_OUTPUT_SEPARATOR), host2);
|
|
1439
|
+
const blockReasons = parsedOutputs.filter((parsed) => parsed.decision === "block").map((parsed) => parsed.reason ?? "").filter(Boolean);
|
|
1440
|
+
if (blockReasons.length > 0) return blockStop(blockReasons.join(MERGED_GATE_OUTPUT_SEPARATOR), host2);
|
|
1441
|
+
const contexts = parsedOutputs.map((parsed) => parsed.hookSpecificOutput?.additionalContext ?? parsed.additional_context ?? "").filter(Boolean);
|
|
1442
|
+
if (contexts.length === 0) return "{}";
|
|
1443
|
+
const hookEventName = parsedOutputs.find((parsed) => parsed.hookSpecificOutput?.hookEventName)?.hookSpecificOutput?.hookEventName;
|
|
1444
|
+
return envelope(hookEventName ?? "", contexts.join(MERGED_GATE_OUTPUT_SEPARATOR), host2);
|
|
1445
|
+
}
|
|
1428
1446
|
|
|
1429
1447
|
// src/guardrails/cli.ts
|
|
1430
1448
|
function readStdin() {
|
|
@@ -1742,7 +1760,18 @@ function capabilityClaimGate() {
|
|
|
1742
1760
|
const reason = `Do not end the turn yet. This turn tells the user that an email- or login-gated flow cannot be tested, reached, or verified \u2014 the one class of blocker Muggle clears. Every managed login profile owns a live inbox, so magic-link and sign-in-link logins, emailed OTPs, email-based 2FA, verification mail, and password resets run end to end with no mail stub and no test-only backdoor; stored credentials and CAPTCHA solving are covered too. Re-read plugin/skills/_shared/identity-and-inbox.md, then correct the claim or run the flow. If the real blocker is SMS/phone OTP, authenticator-app TOTP, or OAuth-only social login, those limits are genuine \u2014 name the one that applies and move on.`;
|
|
1743
1761
|
return blockStop(reason, host);
|
|
1744
1762
|
}
|
|
1763
|
+
function runFiringGates() {
|
|
1764
|
+
const gateOutputs = process.argv.slice(3).map((firingSubcommand) => {
|
|
1765
|
+
try {
|
|
1766
|
+
return (handlers[firingSubcommand] ?? (() => "{}"))();
|
|
1767
|
+
} catch {
|
|
1768
|
+
return "{}";
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
return mergeHookOutputs(gateOutputs, host);
|
|
1772
|
+
}
|
|
1745
1773
|
var handlers = {
|
|
1774
|
+
run: runFiringGates,
|
|
1746
1775
|
"pr-opened": prOpened,
|
|
1747
1776
|
"capability-claim-gate": capabilityClaimGate,
|
|
1748
1777
|
"pr-terminal": prTerminal,
|