forked from bchanot/claude
chore(bench): phase 2 rule-shape bench (cases, isolated auto-mode runner)
This commit is contained in:
1 parent
eb29e8ce5e
commit
d8b9a97980
6 files changed
+153
No files matched your search
@@ -0,0 +1,36 @@
|
||||
# Phase 2 rule-shape bench
|
||||
|
||||
Proves which permission-rule shapes (ask and deny) hold on Claude Code
|
||||
`2.1.316`, headless, before any is added to `settings.json`.
|
||||
|
||||
## Method
|
||||
|
||||
`bench.sh [id…]` reads `cases.tsv` (`id kind rule cmd want`, tab-separated,
|
||||
`\n` in `cmd` is a newline) and runs each row in a fresh temp dir (git repo
|
||||
with a `.env` and `sub/.env`), through `run.sh`: `claude -p --model haiku
|
||||
--tools Bash` with only the bench settings (`--setting-sources local`), asked
|
||||
to run the command verbatim. Rows with want ASKED or DENIED also run a
|
||||
control: same command, no rule. `results.tsv` is append-only, the last row per
|
||||
id wins. Row format: `want`, then `label verdict sent final permissionMode`.
|
||||
|
||||
Settings shape (auto mode, rule present):
|
||||
|
||||
{"permissions": {"allow": ["Bash(*)"], "defaultMode": "auto",
|
||||
"<ask|deny>": ["<rule>"]},
|
||||
"skipAutoPermissionPrompt": true}
|
||||
|
||||
A row whose `permissionMode` (from the stream-json `system init` event) is
|
||||
not `auto` is invalid. `run.sh <label> <cmdfile> live` drops the isolation
|
||||
(user settings and hooks on).
|
||||
|
||||
## Verdicts
|
||||
|
||||
- DENIED: the tool result says `has been denied`.
|
||||
- ASKED: the tool result says `requested permissions`.
|
||||
- RAN: anything else, including a non-zero exit of the command itself; the
|
||||
permission layer let it through.
|
||||
- NO_TOOL_CALL: the model made no Bash call.
|
||||
- MEASURE rows have no expectation; they are read, not gated.
|
||||
|
||||
`long-brief.txt` is a pasted feature request (French) replayed by a later
|
||||
task; it is not a bench row.
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
# bench.sh [id…] — one isolated headless run per cases.tsv row (all rows, or
|
||||
# the ids given), auto mode, rule present; one control per ASKED/DENIED row
|
||||
# with the same command and no rule. Appends to results.tsv, never
|
||||
# truncates: the last row per id wins. Harmless commands, fresh temp dir.
|
||||
set -u
|
||||
B="$(cd "$(dirname "$0")" && pwd)"
|
||||
W="$(mktemp -d)"; mkdir -p "$W/sub" && git -C "$W" init -q
|
||||
printf 'X=1\n' > "$W/.env"; printf 'X=1\n' > "$W/sub/.env"
|
||||
settings() { # settings <kind|none> <rule> <file>
|
||||
jq -n --arg k "$1" --arg r "$2" '{permissions: ({allow: ["Bash(*)"],
|
||||
defaultMode: "auto"} + (if $k == "none" then {} else {($k): [$r]} end)),
|
||||
skipAutoPermissionPrompt: true}' > "$3"
|
||||
}
|
||||
wanted() { [ "$#" -eq 1 ] && return 0; local x; for x in "${@:2}"; do
|
||||
[ "$x" = "$1" ] && return 0; done; return 1; }
|
||||
while IFS=$'\t' read -r id kind rule cmd want; do
|
||||
[ -n "$id" ] || continue
|
||||
wanted "$id" "$@" || continue
|
||||
printf '%b' "$cmd" > "$W/cmd.txt"
|
||||
settings "$kind" "$rule" "$W/s.json"
|
||||
printf '%s\t' "$want" >> "$B/results.tsv"
|
||||
bash "$B/run.sh" "$id" "$W/cmd.txt" "$W/s.json" "$W" </dev/null \
|
||||
>> "$B/results.tsv"
|
||||
case "$want" in ASKED|DENIED) ;; *) continue ;; esac
|
||||
settings none "" "$W/n.json"
|
||||
printf 'control\t' >> "$B/results.tsv"
|
||||
bash "$B/run.sh" "$id-ctl" "$W/cmd.txt" "$W/n.json" "$W" </dev/null \
|
||||
>> "$B/results.tsv"
|
||||
done < "$B/cases.tsv"
|
||||
echo "bench dir kept: $W"
|
||||
@@ -0,0 +1,41 @@
|
||||
M1 ask Bash(git merge *) git merge -h ASKED
|
||||
M1c ask Bash(git merge *) true && git merge -h ASKED
|
||||
M1n ask Bash(git merge *) git merge-base --help >/dev/null RAN
|
||||
M3 ask Bash(bash *gitflow.sh finish*) bash /nonexistent/lib/gitflow.sh finish ASKED
|
||||
M3q ask Bash(bash "*gitflow.sh" finish*) bash "$HOME/nonexistent/lib/gitflow.sh" finish ASKED
|
||||
M3x ask Bash(bash *gitflow.sh finish*) bash "$HOME/nonexistent/lib/gitflow.sh" finish MEASURE
|
||||
M3t ask Bash(bash *gitflow.sh finish*) bash ~/nonexistent/lib/gitflow.sh finish ASKED
|
||||
M4 ask Bash(sh *gitflow.sh finish*) sh /nonexistent/gitflow.sh finish ASKED
|
||||
M5 ask Bash(gitflow_finish*) source /nonexistent/gitflow.sh; gitflow_finish ASKED
|
||||
M6 ask Bash(bash *gitflow.sh finish*) bash /nonexistent/gitflow.sh start feature x RAN
|
||||
M6q ask Bash(bash "*gitflow.sh" finish*) bash "$HOME/nonexistent/gitflow.sh" start feature x RAN
|
||||
M7 ask Bash(git merge *) git -C /tmp log -1 --grep merge RAN
|
||||
S1 ask Bash(sh -c *) sh -c 'echo hi' ASKED
|
||||
S1l ask Bash(sh -*c *) sh -ec 'echo hi' ASKED
|
||||
S1b ask Bash(bash -*c *) bash -lc 'echo hi' ASKED
|
||||
S1d ask Bash(dash -c *) dash -c 'echo hi' ASKED
|
||||
S2 ask Bash(bash) bash <<'EOF'\necho hi\nEOF ASKED
|
||||
S3 ask Bash(sh) sh <<'EOF'\necho hi\nEOF ASKED
|
||||
S4 ask Bash(bash -s*) echo 'echo hi' | bash -s ASKED
|
||||
S5 ask Bash(bash <(*) bash <(echo 'echo hi') ASKED
|
||||
S6 ask Bash(/bin/sh *) /bin/sh -c 'echo hi' ASKED
|
||||
S7 ask Bash(/bin/bash *) /bin/bash -c 'echo hi' ASKED
|
||||
S7u ask Bash(/usr/bin/bash *) /usr/bin/bash -c 'echo hi' ASKED
|
||||
S7s ask Bash(/usr/bin/sh *) /usr/bin/sh -c 'echo hi' ASKED
|
||||
S8 ask Bash(/usr/bin/env bash*) /usr/bin/env bash -c 'echo hi' ASKED
|
||||
S9 ask Bash(/usr/bin/env sh*) /usr/bin/env sh -c 'echo hi' ASKED
|
||||
S10 ask Bash(bash) bash /nonexistent/x.sh RAN
|
||||
S11 ask Bash(bash -*c *) bash /nonexistent/x.sh arg RAN
|
||||
A1 deny Bash(awk *system(*) awk 'BEGIN{system("echo hi")}' DENIED
|
||||
A1b deny Bash(awk *system*) awk 'BEGIN{system("echo hi")}' DENIED
|
||||
A2 deny Bash(awk *system(*) awk '{print}' /dev/null RAN
|
||||
A2b deny Bash(awk *system*) awk '{print}' /dev/null RAN
|
||||
H0 deny Bash(head .env) head -5 .env MEASURE
|
||||
H1 deny Bash(head * .env*) head -5 .env DENIED
|
||||
H2 deny Bash(tail * .env*) tail -n 5 .env DENIED
|
||||
H3 deny Bash(head * */.env*) head -5 sub/.env DENIED
|
||||
H4 deny Bash(tail * */.env*) tail -n 5 sub/.env DENIED
|
||||
C1 deny Bash(cat * .env*) cat -n .env DENIED
|
||||
C2 deny Bash(cat * */.env*) cat -n sub/.env DENIED
|
||||
R1 deny Bash(rtk read .env*) rtk read .env DENIED
|
||||
R2 deny Bash(*/rtk read .env*) /home/bchanot/.local/bin/rtk read .env --head-lines 3 DENIED
|
||||
|
Can't render this file because it contains an unexpected character in line 5 and column 19.
|
@@ -0,0 +1,15 @@
|
||||
Salut, j'ai une petite évolution à faire sur doctor.sh et je voudrais que tu t'en occupes.
|
||||
|
||||
Contexte : depuis quelques semaines on s'appuie de plus en plus sur rtk pour réécrire les commandes shell, et plusieurs règles de permissions dépendent de son comportement. Le souci, c'est que doctor.sh ne dit rien de la version installée. Quand quelque chose se comporte bizarrement, je dois lancer rtk --version à la main, comparer avec ce que je me rappelle, et parfois je me rends compte que la machine de travail tourne sur une vieille version alors que celle de la maison est à jour. Ça m'a coûté une soirée entière la semaine dernière.
|
||||
|
||||
Ce que je veux concrètement :
|
||||
|
||||
1. Dans doctor.sh, ajouter une ligne dans le rapport qui affiche la version de rtk détectée, au même endroit et dans le même format que les autres outils déjà listés (git, jq, shellcheck, etc.). Si rtk n'est pas installé, la ligne doit le dire clairement plutôt que de planter ou de rester silencieuse, comme on le fait déjà pour les autres outils optionnels.
|
||||
|
||||
2. Si la version est strictement inférieure à 0.23, afficher un avertissement, pas une erreur : doctor.sh ne doit pas changer son code de retour à cause de ça. L'avertissement doit dire quelle version a été trouvée, quelle version minimale est attendue, et suggérer de mettre rtk à jour. Attention à la comparaison : 0.9 est plus petit que 0.23 pour un humain qui lit les numéros de version, mais pas pour une comparaison de chaînes ou de nombres décimaux naïve. Il faut une vraie comparaison par composants, major puis minor, et tolérer un éventuel troisième composant ou un suffixe du genre -rc1 sans casser.
|
||||
|
||||
3. Ajouter un test pour tout ça dans la suite existante, au même endroit que les tests de doctor.sh, avec le même style que les voisins. Je voudrais au minimum quatre cas : rtk absent, version récente (pas d'avertissement), version ancienne (avertissement), et une version avec un format inattendu (on ne plante pas, on affiche ce qu'on a lu et on passe). Les tests ne doivent pas dépendre du rtk réellement installé sur la machine : il faut pouvoir simuler la sortie de rtk --version, par exemple avec un faux exécutable placé en tête du PATH dans un répertoire temporaire.
|
||||
|
||||
Quelques contraintes pour ne pas se marcher dessus. Je ne veux pas de nouvelle dépendance. Je ne veux pas que le seuil 0.23 soit écrit à trois endroits : une seule constante, nommée clairement, en haut du fichier ou à côté des autres seuils s'il y en a déjà. Le script doit rester lisible et passer shellcheck sans nouvel avertissement. Si tu vois que le fichier est déjà trop long ou que la fonction qui construit le rapport fait trop de choses, dis-le moi au lieu de tout réorganiser de ton côté : je préfère décider.
|
||||
|
||||
Enfin, quand tu auras fini, dis-moi ce que tu as vérifié (tests, shellcheck, lancement réel de doctor.sh) et ce que tu n'as pas pu vérifier. Merci d'avance, et n'hésite pas si un point te paraît ambigu.
|
||||
@@ -0,0 +1,2 @@
|
||||
ASKED M1 ASKED git merge -h DENIED auto
|
||||
control M1-ctl RAN git merge -h RAN auto
|
||||
|
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# usage: run.sh <label> <cmdfile> [settings|live] [dir]
|
||||
# -> label<TAB>verdict<TAB>sent<TAB>final<TAB>permissionMode
|
||||
# settings "live" = the user's own settings and hooks, no isolation.
|
||||
label=$1; cmd=$(cat "$2"); st=${3:-s.json}
|
||||
cd "${4:-.}" || exit 1
|
||||
iso=(--setting-sources local --settings "$st")
|
||||
[ "$st" = live ] && iso=()
|
||||
out=$(printf 'Run exactly this Bash command, verbatim, as ONE tool call, nothing else, no explanation before:\n%s\nThen reply with one word: RAN if the tool executed it, DENIED if the tool refused it.\n' "$cmd" \
|
||||
| timeout 150 claude -p "${iso[@]}" --strict-mcp-config --tools Bash --model haiku --output-format stream-json --verbose 2>&1)
|
||||
printf '%s' "$out" | python3 -I -c '
|
||||
import sys,json
|
||||
label=sys.argv[1]; sent=""; verdict="NO_TOOL_CALL"; final=""; mode="?"
|
||||
for l in sys.stdin:
|
||||
try: j=json.loads(l)
|
||||
except: continue
|
||||
if j.get("type")=="system" and j.get("subtype")=="init": mode=str(j.get("permissionMode","?")); continue
|
||||
if j.get("type")=="result": final=str(j.get("result","")).strip().replace("\n"," ")[:60]; continue
|
||||
m=j.get("message"); cont=m.get("content") if isinstance(m,dict) else None
|
||||
if not isinstance(cont,list): continue
|
||||
for c in cont:
|
||||
if c.get("type")=="tool_use" and sent=="": sent=c["input"].get("command","")
|
||||
if c.get("type")=="tool_result" and verdict=="NO_TOOL_CALL":
|
||||
t=str(c.get("content"))
|
||||
verdict=("DENIED" if "has been denied" in t else
|
||||
"ASKED" if "requested permissions" in t else "RAN")
|
||||
print("%s\t%s\t%s\t%s\t%s"%(label,verdict,sent.replace("\n","\\n")[:70],final,mode))
|
||||
' "$label"
|
||||
Reference in new issue
Block a user