fix(rtk-hook): rtk ask (rc 3) passes the original command to the native rules; re-pin

This commit is contained in:
bchanot committed 2026-11-02 18:33:55 +01:00
1 parent d8b9a97980
commit 60ee4a996e
3 files changed
+33 -13

No files matched your search

+1 -1
View File
@@ -1 +1 @@
82369e32905a8de6dc6b2566c5992f686794a826b2310b15a96e4bd9d25ac7b6 rtk-rewrite.sh
d4bd3a68b0bf203a0b79806d03217bf39264a41ffa37c5ff37441c74c29a8f3b rtk-rewrite.sh
+6 -12
View File
@@ -21,7 +21,7 @@
# 1 No RTK equivalent → command continues unchanged into the
# redaction check below (still may be rewritten there)
# 2 Deny rule matched → pass through (Claude Code native deny handles it)
# 3 + stdout Ask rule matched → rewrite but let Claude Code prompt the user
# 3 + stdout Ask rule matched → pass the original through (native ask sees it)
#
# Independent of the above: any command whose FINAL form is a single-pipeline
# `printenv`/`env` dump gets a redaction pipe appended (job7 — see below).
@@ -86,18 +86,12 @@ case $EXIT_CODE in
# check below still runs on it.
REWRITTEN="$CMD"
;;
2)
# Deny rule matched (rtk's own registry — not necessarily backed by a
# matching settings.json deny rule, so the original command can still
# reach native evaluation and run: e.g. bare `env`/`printenv` hits this
# exit code with no settings.json rule behind it). Keep the original
# command so the redaction check below still runs on it.
2|3)
# 2 = rtk deny, 3 = rtk ask: keep the ORIGINAL command so Claude Code's
# native deny/ask judges it as typed (a `rtk <cmd>` rewrite matched no
# native rule: bench 2026-10-25), and the redaction check still runs.
REWRITTEN="$CMD"
;;
3)
# Ask rule matched — rewrite the command but do NOT auto-allow so that
# Claude Code prompts the user for confirmation.
;;
*)
exit 0
;;
@@ -140,7 +134,7 @@ fi
ORIGINAL_INPUT=$(echo "$INPUT" | jq -c '.tool_input')
UPDATED_INPUT=$(echo "$ORIGINAL_INPUT" | jq --arg cmd "$REWRITTEN" '.command = $cmd')
# Rewrite WITHOUT a permissionDecision (exit 0 and exit 3 alike): the
# Rewrite WITHOUT a permissionDecision (rtk exit 0 only): the
# rewritten command goes through Claude Code's native allow/deny/ask
# evaluation. Permission control lives in settings.json, not in rtk.
jq -n \
+26
View File
@@ -42,4 +42,30 @@ check T9-unrelated-still-rewrites \
check T10-unrelated-not-redacted \
"$(raw 'cat /etc/hostname' | grep -c 'sed -E')" "0"
# --- T11-T13: rtk exit-code protocol, hermetic (a PATH shim plays rtk) ---
SHIM="$(mktemp -d)"; trap 'rm -rf "$SHIM"' EXIT
cat > "$SHIM/rtk" <<'SH'
#!/usr/bin/env bash
case "$1" in
--version) echo "rtk 0.50.0" ;;
rewrite) case "$2" in
probe-ask) echo "rtk probe-ask"; exit 3 ;;
probe-read) echo "rtk read probe-read"; exit 0 ;;
*) exit 1 ;;
esac ;;
esac
SH
chmod +x "$SHIM/rtk"
shim_raw() { # shim_raw <cmd> -> hook stdout with the shim first on PATH
jq -n --arg cmd "$1" '{tool_input:{command:$cmd}}' \
| PATH="$SHIM:$PATH" bash "$H"
}
check T11-rc3-passthrough "$(shim_raw probe-ask)" ""
check T12-rc0-still-rewrites \
"$(shim_raw probe-read | jq -r '.hookSpecificOutput.updatedInput.command')" \
"rtk read probe-read"
check T13-pin-matches \
"$(cd "$(dirname "$H")" && sha256sum -c .rtk-hook.sha256 >/dev/null 2>&1 \
&& echo ok || echo mismatch)" ok
printf 'PASS=%s FAIL=%s\n' "$pass" "$fail"; [ "$fail" -eq 0 ]