Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Disable hooks for nested Codex helpers by BBuf · Pull Request #194 · PolyArch/humanize · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions hooks/loop-codex-stop-hook.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -1174,19 +1174,31 @@ mkdir -p "$CACHE_DIR"
# portable-timeout.sh already sourced above

# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
# so older builds do not fail with an unknown-argument error.
# Codex has used different hook feature names across releases. Probe each name
# before disabling it so older CLIs that validate feature names still work.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_FEATURE_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
: > "$_CODEX_FEATURE_CACHE" 2>/dev/null || true
fi
fi

Expand Down
27 changes: 19 additions & 8 deletions scripts/ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -241,20 +241,31 @@ EOF
# Build Codex Command
# ========================================

# Probe whether the installed Codex CLI supports --disable hooks to prevent
# nested hook recursion when ask-codex.sh is called from inside a running loop.
# Cache the probe result in the skill directory to avoid repeated probes.
# Probe supported hook feature names before disabling them. Codex has used
# different names across releases, and older CLIs reject unknown feature names.
CODEX_DISABLE_HOOKS_ARGS=()
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-supported"
_CODEX_DISABLE_HOOKS_CACHE="$SKILL_DIR/.codex-disable-hooks-features"
if [[ -f "$_CODEX_DISABLE_HOOKS_CACHE" ]]; then
[[ "$(cat "$_CODEX_DISABLE_HOOKS_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
while IFS= read -r feature_name; do
case "$feature_name" in
hooks|plugin_hooks|codex_hooks)
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
;;
esac
done < "$_CODEX_DISABLE_HOOKS_CACHE"
else
CODEX_HELP_OUTPUT="$(codex --help </dev/null 2>&1 || true)"
if grep -q -- '--disable' <<< "$CODEX_HELP_OUTPUT"; then
CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)
echo "yes" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
_CODEX_DISABLE_HOOK_FEATURES=()
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
CODEX_DISABLE_HOOKS_ARGS+=("--disable" "$feature_name")
_CODEX_DISABLE_HOOK_FEATURES+=("$feature_name")
fi
done
printf '%s\n' ${_CODEX_DISABLE_HOOK_FEATURES[@]+"${_CODEX_DISABLE_HOOK_FEATURES[@]}"} > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
else
echo "no" > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
: > "$_CODEX_DISABLE_HOOKS_CACHE" 2>/dev/null || true
fi
fi

Expand Down
14 changes: 10 additions & 4 deletions scripts/bitlesson-select.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,11 +193,17 @@ run_selector() {
# Capture help output first to avoid pipefail+SIGPIPE interaction when
# grep exits early (after finding a match) before codex finishes writing.
local codex_help_output codex_exec_help_output
codex_help_output=$(codex --help 2>&1) || true
codex_exec_help_output=$(codex exec --help 2>&1) || true
# Probe whether the installed Codex CLI supports --disable flag
codex_help_output=$(codex --help </dev/null 2>&1) || true
codex_exec_help_output=$(codex exec --help </dev/null 2>&1) || true
# Probe supported hook feature names before disabling them. Older Codex
# CLIs reject unknown feature names even when --disable exists.
if grep -q -- '--disable' <<< "$codex_help_output"; then
codex_exec_args+=("--disable" "hooks")
local feature_name
for feature_name in hooks plugin_hooks codex_hooks; do
if codex --disable "$feature_name" --help </dev/null >/dev/null 2>&1; then
codex_exec_args+=("--disable" "$feature_name")
fi
done
fi
# Probe for --skip-git-repo-check and --ephemeral support
if grep -q -- '--skip-git-repo-check' <<< "$codex_exec_help_output"; then
Expand Down
107 changes: 93 additions & 14 deletions tests/test-ask-codex.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@
# MOCK_CODEX_EXIT_CODE - exit code the mock returns (default: 0)
# MOCK_CODEX_STDOUT - text the mock writes to stdout
# MOCK_CODEX_STDERR - text the mock writes to stderr
# MOCK_CODEX_HELP_OUTPUT - text the mock writes for `codex --help`
# MOCK_CODEX_ARGS_FILE - optional file where non-help argv is captured
#

set -euo pipefail
Expand DownExpand Up@@ -40,6 +42,23 @@ cat > "$MOCK_BIN_DIR/codex" << 'MOCK_EOF'
#!/usr/bin/env bash
# Mock codex binary for testing ask-codex.sh
# Controlled via environment variables.
if printf '%s\n' "$@" | grep -qx -- '--help'; then
if [[ "${1:-}" == "--disable" ]]; then
feature="${2:-}"
supported_features=" ${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "$supported_features" != *" $feature "* ]]; then
echo "unknown feature: $feature" >&2
exit 2
fi
fi
if [[ -n "${MOCK_CODEX_HELP_OUTPUT:-}" ]]; then
echo "$MOCK_CODEX_HELP_OUTPUT"
fi
exit 0
fi
if [[ -n "${MOCK_CODEX_ARGS_FILE:-}" ]]; then
printf '%s\n' "$@" > "$MOCK_CODEX_ARGS_FILE"
fi
if [[ -n "${MOCK_CODEX_STDERR:-}" ]]; then
echo "$MOCK_CODEX_STDERR" >&2
fi
Expand All@@ -63,6 +82,9 @@ reset_mock() {
export MOCK_CODEX_EXIT_CODE="0"
export MOCK_CODEX_STDOUT=""
export MOCK_CODEX_STDERR=""
export MOCK_CODEX_HELP_OUTPUT=""
export MOCK_CODEX_ARGS_FILE=""
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
rm -rf "$MOCK_PROJECT/.humanize/skill" 2>/dev/null || true
}

Expand All@@ -86,6 +108,7 @@ run_ask_codex_capturing_dir() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$RUN_XDG_CACHE_HOME"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@" 2>&1 >/dev/null
) || RUN_EXIT_CODE=$?
output_path=$(printf '%s\n' "$run_stderr" | grep "^ask-codex: response saved to " | sed 's/^ask-codex: response saved to //')
Expand DownExpand Up@@ -114,6 +137,7 @@ run_ask_codex() {
cd "$MOCK_PROJECT"
export CLAUDE_PROJECT_DIR="$MOCK_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$MOCK_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand DownExpand Up@@ -253,6 +277,54 @@ else
fail "successful run exits 0" "exit 0" "exit=$EXIT_CODE"
fi

# Test: supported Codex --disable flag disables all known hook features
reset_mock
export MOCK_CODEX_STDOUT="hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="hooks plugin_hooks codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks'; then
pass "successful run disables all known hook features for nested codex exec"
else
fail "successful run disables all known hook features for nested codex exec" \
"exec args include hooks, plugin_hooks, codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# Test: older Codex builds only receive supported hook feature names
reset_mock
export MOCK_CODEX_STDOUT="legacy-hook-disable-test"
export MOCK_CODEX_HELP_OUTPUT=" --disable <feature> Disable a feature"
export MOCK_CODEX_SUPPORTED_FEATURES="codex_hooks"
ASK_CODEX_ARGS_FILE="$TEST_DIR/ask-codex-legacy-args.txt"
export MOCK_CODEX_ARGS_FILE="$ASK_CODEX_ARGS_FILE"
EXIT_CODE=0
run_ask_codex "legacy hook disable test" > /dev/null 2>&1 || EXIT_CODE=$?
CAPTURED_ARGS="$(cat "$ASK_CODEX_ARGS_FILE" 2>/dev/null || true)"
if [[ $EXIT_CODE -eq 0 ]] \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'exec' \
&& echo "$CAPTURED_ARGS" | grep -qx -- '--disable' \
&& echo "$CAPTURED_ARGS" | grep -qx -- 'codex_hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'hooks' \
&& ! echo "$CAPTURED_ARGS" | grep -qx -- 'plugin_hooks'; then
pass "successful run disables only supported hook features for older codex"
else
fail "successful run disables only supported hook features for older codex" \
"exec args include only codex_hooks" \
"exit=$EXIT_CODE, args=$CAPTURED_ARGS"
fi
reset_mock

# ========================================
# Error Handling Tests
# ========================================
Expand DownExpand Up@@ -519,6 +591,7 @@ run_ask_codex_probe() {
cd "$PROBE_PROJECT"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -545,14 +618,17 @@ reset_mock
export MOCK_CODEX_STDOUT="probe-test-supports"
run_ask_codex_probe "probe disable test" > /dev/null 2>&1 || true

# Check that the cached probe result is "yes" in the skill dir
# Check that the cached probe result lists the supported hook features.
PROBE_SKILL_DIR=$(find "$PROBE_PROJECT/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_RESULT" == "yes" ]]; then
pass "auto-probe: cached 'yes' when codex supports --disable"
if [[ -n "$PROBE_SKILL_DIR" ]] && [[ -f "$PROBE_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_RESULT=$(cat "$PROBE_SKILL_DIR/.codex-disable-hooks-features")
if echo "$PROBE_RESULT" | grep -qx -- 'hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'plugin_hooks' \
&& echo "$PROBE_RESULT" | grep -qx -- 'codex_hooks'; then
pass "auto-probe: cached supported hook features when codex supports --disable"
else
fail "auto-probe: cached 'yes' when codex supports --disable" "yes" "$PROBE_RESULT"
fail "auto-probe: cached supported hook features when codex supports --disable" \
"hooks, plugin_hooks, codex_hooks" "$PROBE_RESULT"
fi
else
fail "auto-probe: probe cache file created" "cache file exists" "not found"
Expand DownExpand Up@@ -583,6 +659,7 @@ run_ask_codex_probe_no() {
cd "$PROBE_PROJECT_NO"
export CLAUDE_PROJECT_DIR="$PROBE_PROJECT_NO"
export XDG_CACHE_HOME="$TEST_DIR/cache-probe-no"
export XDG_CONFIG_HOME="$TEST_DIR/no-user-config"
PATH="$PROBE_BIN_NO_DIR:$PATH" bash "$ASK_CODEX_SCRIPT" "$@"
)
}
Expand All@@ -592,23 +669,25 @@ export MOCK_CODEX_STDOUT="probe-test-no-support"
run_ask_codex_probe_no "probe no-support test" > /dev/null 2>&1 || true

PROBE_NO_SKILL_DIR=$(find "$PROBE_PROJECT_NO/.humanize/skill" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort | tail -1)
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-supported")
if [[ "$PROBE_NO_RESULT" == "no" ]]; then
pass "auto-probe: cached 'no' when codex does not support --disable"
if [[ -n "$PROBE_NO_SKILL_DIR" ]] && [[ -f "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features" ]]; then
PROBE_NO_RESULT=$(cat "$PROBE_NO_SKILL_DIR/.codex-disable-hooks-features")
if [[ -z "$PROBE_NO_RESULT" ]]; then
pass "auto-probe: cached empty feature list when codex does not support --disable"
else
fail "auto-probe: cached 'no' when codex does not support --disable" "no" "$PROBE_NO_RESULT"
fail "auto-probe: cached empty feature list when codex does not support --disable" \
"(empty)" "$PROBE_NO_RESULT"
fi
else
fail "auto-probe: probe cache file created for no-support case" "cache file exists" "not found"
fi

# Test C: ask-codex.sh script contains the probe implementation
if grep -q "CODEX_DISABLE_HOOKS_ARGS=(--disable hooks)" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-supported" "$ASK_CODEX_SCRIPT"; then
if grep -q "for feature_name in hooks plugin_hooks codex_hooks" "$ASK_CODEX_SCRIPT" \
&& grep -q "codex-disable-hooks-features" "$ASK_CODEX_SCRIPT"; then
pass "ask-codex.sh contains nested hook disable auto-probe implementation"
else
fail "ask-codex.sh contains nested hook disable auto-probe implementation" "hooks disable args + probe cache" "not found"
fail "ask-codex.sh contains nested hook disable auto-probe implementation" \
"feature loop + probe cache" "not found"
fi

# ========================================
Expand Down
6 changes: 4 additions & 2 deletions tests/test-bitlesson-select-routing.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -481,8 +481,10 @@ captured_args="$(cat "$CAPTURE_ARGS")"

if [[ $exit_code -eq 0 ]] \
&& echo "$stdout_out" | grep -q "BL-20260315-tracker-drift" \
&& echo "$captured_args" | grep -q -- '--disable' \
&& echo "$captured_args" | grep -q -- 'hooks' \
&& echo "$captured_args" | grep -qx -- '--disable' \
&& echo "$captured_args" | grep -qx -- 'hooks' \
&& echo "$captured_args" | grep -qx -- 'plugin_hooks' \
&& echo "$captured_args" | grep -qx -- 'codex_hooks' \
&& echo "$captured_args" | grep -q -- '--skip-git-repo-check' \
&& echo "$captured_args" | grep -q -- '--ephemeral' \
&& echo "$captured_args" | grep -q -- 'read-only' \
Expand Down
48 changes: 35 additions & 13 deletions tests/test-disable-nested-codex-hooks.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,14 +70,22 @@ setup_mock_codex() {
mkdir -p "$bin_dir"
cat > "$bin_dir/codex" <<EOF
#!/usr/bin/env bash
# The stop hook probes feature support with \`codex --help\`; advertise
# --disable so the nested invocation is expected to include it.
if [[ "\$1" == "--help" ]]; then
# The stop hook probes feature support with \`codex --help\` and validates each
# known feature with \`codex --disable <feature> --help\`.
if printf '%s\n' "\$@" | grep -qx -- '--help'; then
if [[ "\${1:-}" == "--disable" ]]; then
feature="\${2:-}"
supported_features=" \${MOCK_CODEX_SUPPORTED_FEATURES:-hooks plugin_hooks codex_hooks} "
if [[ "\$supported_features" != *" \$feature "* ]]; then
echo "unknown feature: \$feature" >&2
exit 2
fi
fi
cat <<HELP
Usage: codex [OPTIONS] <COMMAND>

Options:
--disable <HOOK> Disable a specific Codex hook (e.g. hooks)
--disable <HOOK> Disable a specific Codex hook
--skip-git-repo-check Skip git repo validation
HELP
exit 0
Expand DownExpand Up@@ -186,13 +194,14 @@ run_loop_hook() {
local repo_dir="$1"
local args_file="$2"
local review_started="$3"
local supported_features="${4:-hooks plugin_hooks codex_hooks}"
local bin_dir="$TEST_DIR/bin-${review_started}"

setup_mock_codex "$bin_dir" "$args_file"
setup_loop_dir "$repo_dir" "$review_started"

set +e
OUTPUT=$(echo '{}' | PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
OUTPUT=$(echo '{}' | MOCK_CODEX_SUPPORTED_FEATURES="$supported_features" PATH="$bin_dir:$PATH" CLAUDE_PROJECT_DIR="$repo_dir" bash "$STOP_HOOK" 2>&1)
EXIT_CODE=$?
set -e

Expand All@@ -206,22 +215,22 @@ REPO_IMPL="$TEST_DIR/repo-impl"
setup_repo "$REPO_IMPL"
run_loop_hook "$REPO_IMPL" "$TEST_DIR/impl.args" "false"

if grep -q -- 'exec --disable hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables hooks for codex exec"
if grep -q -- 'exec --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/impl.args"; then
pass "implementation-phase stop hook disables all known hook features for codex exec"
else
fail "implementation-phase stop hook disables hooks for codex exec" \
"exec --disable hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fail "implementation-phase stop hook disables all known hook features for codex exec" \
"exec --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/impl.args" 2>/dev/null || echo missing)"
fi

REPO_REVIEW="$TEST_DIR/repo-review"
setup_repo "$REPO_REVIEW"
run_loop_hook "$REPO_REVIEW" "$TEST_DIR/review.args" "true"

if grep -q -- 'review --disable hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables hooks for codex review"
if grep -q -- 'review --disable hooks --disable plugin_hooks --disable codex_hooks' "$TEST_DIR/review.args"; then
pass "review-phase stop hook disables all known hook features for codex review"
else
fail "review-phase stop hook disables hooks for codex review" \
"review --disable hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fail "review-phase stop hook disables all known hook features for codex review" \
"review --disable hooks --disable plugin_hooks --disable codex_hooks" "$(cat "$TEST_DIR/review.args" 2>/dev/null || echo missing)"
fi

if ! grep -q 'codex --help 2>&1 | grep -q' "$STOP_HOOK"; then
Expand DownExpand Up@@ -250,6 +259,19 @@ else
'must not pass prompt input when `--base` is used' "$(cat "$REVIEW_PROMPT" 2>/dev/null || echo missing)"
fi

REPO_LEGACY="$TEST_DIR/repo-legacy"
setup_repo "$REPO_LEGACY"
run_loop_hook "$REPO_LEGACY" "$TEST_DIR/legacy.args" "false" "codex_hooks"

if grep -q -- 'exec --disable codex_hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- '--disable hooks' "$TEST_DIR/legacy.args" \
&& ! grep -q -- 'plugin_hooks' "$TEST_DIR/legacy.args"; then
pass "implementation-phase stop hook disables only supported legacy hook feature"
else
fail "implementation-phase stop hook disables only supported legacy hook feature" \
"exec --disable codex_hooks only" "$(cat "$TEST_DIR/legacy.args" 2>/dev/null || echo missing)"
fi

echo ""
echo "========================================"
echo "Disable Nested Codex Hooks Tests"
Expand Down
Loading