@cratis/pi 7.132.0 → 7.133.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/package/corpus/harnesses/pi/extensions/cratis-hooks/index.ts +3 -3
- package/package/corpus/hooks/README.md +10 -5
- package/package/corpus/hooks/scripts/cratis-pattern-scan.sh +9 -4
- package/package/corpus/hooks/scripts/cratis-quality-gate.sh +15 -2
- package/package/corpus/hooks/scripts/hook-lib.sh +8 -2
- package/package.json +1 -1
|
@@ -179,9 +179,9 @@ async function runCommandGuards(
|
|
|
179
179
|
/**
|
|
180
180
|
* Whether a hook script is installed at all.
|
|
181
181
|
*
|
|
182
|
-
* A repository that ships no hook scripts is a supported configuration
|
|
183
|
-
*
|
|
184
|
-
*
|
|
182
|
+
* A repository that ships no hook scripts is a supported configuration, so an absent script is
|
|
183
|
+
* not an error and is not enforced. Installed scripts report missing `jq`: guards refuse calls,
|
|
184
|
+
* the quality gate blocks changed trees, and the advisory pattern scan warns once per session.
|
|
185
185
|
*
|
|
186
186
|
* The dangerous case is the other one: the script is present, so this repository clearly intends
|
|
187
187
|
* the guard to run, but it cannot be executed. That is a broken guard rather than an absent one,
|
|
@@ -96,8 +96,9 @@ This is a guardrail, **not absolute enforcement**. Node, Bash and Git are requir
|
|
|
96
96
|
launch the adapter; native callback failure, crash, timeout, or malformed-response behavior
|
|
97
97
|
can fail open before a supported denial is received. Other local hook configurations and
|
|
98
98
|
specialized tool paths are outside this adapter's control. The existing scripts retain
|
|
99
|
-
their own deliberate allowances and limits: missing `jq` makes the store, secret and write guards refuse every call;
|
|
100
|
-
|
|
99
|
+
their own deliberate allowances and limits: missing `jq` makes the store, secret and write guards refuse every call;
|
|
100
|
+
the quality gate blocks changed trees (dry runs warn only), and pattern scanning warns once per session without blocking.
|
|
101
|
+
PR checks can allow with an unchecked/offline warning; command-text parsing cannot see all indirect
|
|
101
102
|
execution. Inherited `CRATIS_HOOKS_ALLOW_STORE_MUTATIONS=1` and existing script configuration
|
|
102
103
|
are preserved. An adapter exit **0** is not proof that every underlying check ran.
|
|
103
104
|
|
|
@@ -800,9 +801,13 @@ Each is an explicit, auditable opt-out — none of them is a default.
|
|
|
800
801
|
- **Gate commands are an argv array**, executed directly. They never pass through a shell.
|
|
801
802
|
- **`jq` is the dependency for the write, store-mutation, secret, pattern and quality hooks.** The
|
|
802
803
|
write, store-mutation and secret guards refuse every call while it is missing (exit 2, with the
|
|
803
|
-
reason and the install hint on stderr)
|
|
804
|
-
|
|
805
|
-
|
|
804
|
+
reason and the install hint on stderr). Without `jq`, the quality gate blocks changed trees with
|
|
805
|
+
an install hint (exit 2); dry runs warn with exit 0. Unchanged trees, non-Git directories,
|
|
806
|
+
Stop-hook re-entry and `CRATIS_HOOKS_SKIP_GATE=1` still exit 0 silently. A person accepting
|
|
807
|
+
unverified turn ends can set that escape hatch in the environment the harness was started from.
|
|
808
|
+
The pattern scan exits 0 with a one-line stderr notice at most once per session (or on each call
|
|
809
|
+
if session state is unavailable). The PR-body hook uses Node instead, and the checker uses Git
|
|
810
|
+
and `gh` as described above.
|
|
806
811
|
- **Fail safe.** Malformed config, empty stdin, a missing file, a binary file, a file over 2 MB:
|
|
807
812
|
all exit 0 silently. The one deliberate exception is the store-mutation guard's command lists:
|
|
808
813
|
an unreadable shipped or local list is not an empty allowlist that happens to pass, so every `cratis chronicle`
|
|
@@ -18,12 +18,17 @@ set -euo pipefail
|
|
|
18
18
|
[ "${CRATIS_HOOKS_SKIP_SCAN:-0}" = "1" ] && exit 0
|
|
19
19
|
|
|
20
20
|
input="$(hook_read_stdin)"
|
|
21
|
+
if ! hook_have jq; then
|
|
22
|
+
# Only a session key is needed to de-duplicate this advisory when JSON parsing is unavailable.
|
|
23
|
+
session="$(sed -n 's/.*"session_id"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' <<<"$input")"
|
|
24
|
+
if state_dir="$(hook_state_dir "${session:-nosession}")"; then
|
|
25
|
+
hook_claim_once "$state_dir/pattern-scan-missing-jq.seen" missing-jq || exit 0
|
|
26
|
+
fi
|
|
27
|
+
printf 'cratis-pattern-scan: jq is not installed; pattern scanning is off until jq is installed.\n' >&2
|
|
28
|
+
exit 0
|
|
29
|
+
fi
|
|
21
30
|
[ -n "$input" ] || exit 0
|
|
22
31
|
|
|
23
|
-
# jq is the repository's established JSON dependency. If it is not
|
|
24
|
-
# installed the hook degrades to a silent no-op rather than breaking the session.
|
|
25
|
-
hook_have jq || exit 0
|
|
26
|
-
|
|
27
32
|
root="$(hook_repo_root)"
|
|
28
33
|
cwd="$(hook_json "$input" '.cwd')"
|
|
29
34
|
[ -n "$cwd" ] || cwd="$root"
|
|
@@ -22,7 +22,21 @@ set -euo pipefail
|
|
|
22
22
|
[ "${CRATIS_HOOKS_SKIP_GATE:-0}" = "1" ] && exit 0
|
|
23
23
|
|
|
24
24
|
input="$(hook_read_stdin)"
|
|
25
|
-
|
|
25
|
+
root="$(hook_repo_root)"
|
|
26
|
+
if ! hook_have jq; then
|
|
27
|
+
# Without JSON parsing, still honor Stop re-entry and never block an unchanged tree.
|
|
28
|
+
LC_ALL=C grep -Eq '"stop_hook_active"[[:space:]]*:[[:space:]]*true' <<<"$input" && exit 0
|
|
29
|
+
git -C "$root" rev-parse --git-dir >/dev/null 2>&1 || exit 0
|
|
30
|
+
[ -n "$(git -C "$root" status --porcelain --untracked-files=normal 2>/dev/null || true)" ] || exit 0
|
|
31
|
+
{
|
|
32
|
+
printf 'BLOCKED by cratis-quality-gate: jq is not installed, so no quality gates ran on this change.\n'
|
|
33
|
+
hook_jq_install_hint
|
|
34
|
+
printf '\nA person who accepts ending turns without the gate sets CRATIS_HOOKS_SKIP_GATE=1 in the environment the agent\n'
|
|
35
|
+
printf 'harness was started from; setting it inside the command has no effect.\n'
|
|
36
|
+
} >&2
|
|
37
|
+
[ "${CRATIS_HOOKS_GATE_DRYRUN:-0}" = "1" ] && exit 0
|
|
38
|
+
exit 2
|
|
39
|
+
fi
|
|
26
40
|
|
|
27
41
|
# Never re-enter: Claude Code sets stop_hook_active when the previous Stop hook already
|
|
28
42
|
# blocked and the model is continuing. Blocking again would loop forever.
|
|
@@ -30,7 +44,6 @@ if [ -n "$input" ] && [ "$(hook_json "$input" '.stop_hook_active')" = "true" ];
|
|
|
30
44
|
exit 0
|
|
31
45
|
fi
|
|
32
46
|
|
|
33
|
-
root="$(hook_repo_root)"
|
|
34
47
|
here="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
35
48
|
export CRATIS_HOOKS_SCRIPTS_DIR="$here"
|
|
36
49
|
config="${CRATIS_HOOKS_GATES:-$here/quality-gates.json}"
|
|
@@ -34,6 +34,12 @@ hook_read_stdin() {
|
|
|
34
34
|
cat 2>/dev/null || true
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
# Shared installation hint, without a trailing newline so guards can append their warning.
|
|
38
|
+
hook_jq_install_hint() {
|
|
39
|
+
printf 'Stop and ask the user to install jq (macOS: brew install jq; Debian/Ubuntu: sudo apt-get install jq;\n'
|
|
40
|
+
printf 'Windows: winget install jqlang.jq), then retry.'
|
|
41
|
+
}
|
|
42
|
+
|
|
37
43
|
# Refuse the tool call when jq is missing: $1 is the guard name, $2 the variable that lets a person run without it.
|
|
38
44
|
# A guard that cannot read the tool call cannot check it, so this ends the sourcing script with exit 2
|
|
39
45
|
# (the deny signal every wired harness honors). It uses only builtins, so it works without jq.
|
|
@@ -41,8 +47,8 @@ hook_require_jq() {
|
|
|
41
47
|
hook_have jq && return 0
|
|
42
48
|
{
|
|
43
49
|
printf 'BLOCKED by %s: jq is not installed, so this guard cannot read the tool call and refuses every call until it is.\n' "$1"
|
|
44
|
-
|
|
45
|
-
printf '
|
|
50
|
+
hook_jq_install_hint
|
|
51
|
+
printf ' Do not work around the guard.\n'
|
|
46
52
|
printf 'A person who accepts running without this guard sets %s=1 in the environment the agent\n' "$2"
|
|
47
53
|
printf 'harness was started from; setting it inside the command has no effect.\n'
|
|
48
54
|
} >&2
|