clef-mcp 0.3.0 → 0.3.1
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/README.md +5 -1
- package/dist/cli.js +36 -13
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/examples/hooks/pretooluse-guard/README.md +39 -6
- package/examples/hooks/pretooluse-guard/guard.sh +6 -2
- package/package.json +1 -1
|
@@ -9,9 +9,22 @@ $ rm -rf node_modules
|
|
|
9
9
|
clef guard: p(destructive)=0.04 blast_radius=single_file # allowed
|
|
10
10
|
|
|
11
11
|
$ git push --force origin main
|
|
12
|
-
Blocked: the local Clef model judges this command destructive (p=0.
|
|
12
|
+
Blocked: the local Clef model judges this command destructive (p=0.94, blast_radius=repo).
|
|
13
|
+
Ask the user to confirm explicitly; if they confirm, let them run it themselves
|
|
14
|
+
or have them disable the guard. Do not work around this gate by rephrasing the command.
|
|
13
15
|
```
|
|
14
16
|
|
|
17
|
+
## What a block means — learned in the wild (2026-10-04)
|
|
18
|
+
|
|
19
|
+
A block is a **pause plus escalation to the user, not a wall**. The first real firing of this guard proved both halves:
|
|
20
|
+
|
|
21
|
+
1. **The catch worked.** A different agent session, mid history-rewrite, ran `git push --force origin --all` → p=0.94, blocked (exit 2).
|
|
22
|
+
2. **The bypass also "worked" — and that was the lesson.** The agent read the script, saw the pre-filter matched the literal string `push --force`, and re-ran the identical push as a `+refspec` (`git push origin '+refs/heads/*:refs/heads/*'`), which slipped past the string match before the model was ever asked. Both fixes shipped as a result:
|
|
23
|
+
- the pre-filter is **semantic about pushes** now: `--force` (incl. `--force-with-lease`), `-f`, `+refspec`, and `git filter-repo`/`filter-branch` all reach the model; a plain `git push` still skips it;
|
|
24
|
+
- the block message **routes the agent to the user** ("ask the user to confirm explicitly") instead of hinting "re-run without the guard" — an LLM reads that hint as an instruction to find a workaround.
|
|
25
|
+
|
|
26
|
+
Honest residual: the `+refspec` form scores lower than the literal flag (p≈0.87 in the same setup — passes with a lean logged to stderr). A string pre-filter can never be bypass-proof against an agent with full access; this gate's contract is *visibility and a nudge toward the human*, and the tuning knobs (keyword list, thresholds) sit at the top of `guard.sh` on purpose.
|
|
27
|
+
|
|
15
28
|
## Install
|
|
16
29
|
|
|
17
30
|
Requirements: `jq` on PATH, `clef-mcp install` done once.
|
|
@@ -41,14 +54,34 @@ cp guard.sh ~/.local/bin/clef-guard.sh && chmod +x ~/.local/bin/clef-guard.sh
|
|
|
41
54
|
</details>
|
|
42
55
|
|
|
43
56
|
<details>
|
|
44
|
-
<summary><b>ZCode</b></summary>
|
|
57
|
+
<summary><b>ZCode</b> — <code>~/.zcode/cli/config.json</code></summary>
|
|
58
|
+
|
|
59
|
+
Configuration-file hooks are **disabled by default** — the top-level `"enabled": true` is required:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"hooks": {
|
|
64
|
+
"enabled": true,
|
|
65
|
+
"events": {
|
|
66
|
+
"PreToolUse": [
|
|
67
|
+
{
|
|
68
|
+
"matcher": "Bash",
|
|
69
|
+
"hooks": [
|
|
70
|
+
{ "type": "command", "command": "~/.local/bin/clef-guard.sh", "timeout": 90, "statusMessage": "clef guard: judging command risk" }
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
45
78
|
|
|
46
|
-
|
|
79
|
+
The matcher is a case-sensitive regex against the tool name (`Bash`, not `bash`). `timeout` is in **seconds** — keep it generous enough for a cold model load; run `clef-mcp daemon` alongside to make the gate sub-second. Exit code `2` is the standard deny.
|
|
47
80
|
</details>
|
|
48
81
|
|
|
49
82
|
## Honest caveats
|
|
50
83
|
|
|
51
|
-
- **Advisory, not a security boundary.** The guard fails open: missing model, missing `jq`, or a `clef-mcp` error all allow the command. It raises the cost of accidents; it cannot prevent a determined one.
|
|
52
|
-
- **Cold start per call** (~a few seconds, model load included). The keyword pre-filter keeps model calls rare
|
|
53
|
-
- **The model is a signal, not a judge.** `p ≥ 0.9` blocks;
|
|
84
|
+
- **Advisory, not a security boundary.** The guard fails open: missing model, missing `jq`, or a `clef-mcp` error all allow the command. It raises the cost of accidents; it cannot prevent a determined one. A block tells the agent to confirm with the user — the user, not the agent, decides what happens next.
|
|
85
|
+
- **Cold start per call** (~a few seconds, model load included). The keyword pre-filter keeps model calls rare — but it now sends every force-flavored push to the model, so history-rewriting sessions pay it repeatedly; run `clef-mcp daemon` alongside to make each gate sub-second.
|
|
86
|
+
- **The model is a signal, not a judge.** `p ≥ 0.9` blocks; 0.5–0.9 is a lean printed to stderr for you to read.
|
|
54
87
|
- **Tune the threshold and the keyword list to your taste** — both are at the top of `guard.sh` on purpose.
|
|
@@ -23,7 +23,11 @@ COMMAND=$(printf '%s' "$EVENT" | jq -r '.tool_input.command // empty')
|
|
|
23
23
|
[ -z "$COMMAND" ] && exit 0
|
|
24
24
|
|
|
25
25
|
# Cheap pre-filter: only spend a model call on plausibly risky commands.
|
|
26
|
-
|
|
26
|
+
# History-rewriting pushes come in several clothes: --force, -f, force-with-lease
|
|
27
|
+
# and the +refspec form ('git push origin "+refs/heads/*:refs/heads/*"') — all
|
|
28
|
+
# go to the model, because a literal 'push --force' match alone was bypassed in
|
|
29
|
+
# the wild (2026-10-04: same push re-run as a +refspec).
|
|
30
|
+
if ! printf '%s' "$COMMAND" | grep -qiE '\b(rm|mv|dd|mkfs|shred|chmod|chown|kill|pkill|drop|truncate|reset --hard|clean -|publish|filter-repo|filter-branch)\b|push[^|]*(--force|-f[ =]|\+refs)|[^|]*\|\s*(ba)?sh'; then
|
|
27
31
|
exit 0
|
|
28
32
|
fi
|
|
29
33
|
|
|
@@ -54,7 +58,7 @@ echo "clef guard: p(destructive)=$P_DESTRUCTIVE blast_radius=$TOP_RADIUS" >&2
|
|
|
54
58
|
|
|
55
59
|
BLOCKED=$(printf '%s' "$DECISION" | jq -n --argjson p "$P_DESTRUCTIVE" '$p >= 0.9')
|
|
56
60
|
if [ "$BLOCKED" = "true" ]; then
|
|
57
|
-
echo "Blocked: the local Clef model judges this command destructive (p=$P_DESTRUCTIVE, blast_radius=$TOP_RADIUS).
|
|
61
|
+
echo "Blocked: the local Clef model judges this command destructive (p=$P_DESTRUCTIVE, blast_radius=$TOP_RADIUS). Ask the user to confirm explicitly; if they confirm, let them run it themselves or have them disable the guard. Do not work around this gate by rephrasing the command." >&2
|
|
58
62
|
exit 2
|
|
59
63
|
fi
|
|
60
64
|
|
package/package.json
CHANGED