Skip to content

Commit 2ab5361

Browse files
committed
Fix relative path bypass in write validator and add Codex flag probes in bitlesson selector
Write validator had the same relative-path fallback issue as the read validator: when realpath is unavailable, relative FILE_PATH bypassed the absolute prefix guard during methodology analysis. Bitlesson selector unconditionally passed --disable codex_hooks, --skip-git-repo-check, and --ephemeral to codex exec without checking if the CLI supports them. Added capability probes matching the pattern already used in loop-codex-stop-hook.sh.
1 parent 17fabf7 commit 2ab5361

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

hooks/loop-write-validator.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,21 @@ if [[ -n "$_MA_LOOP_DIR" ]] && [[ -f "$_MA_LOOP_DIR/methodology-analysis-state.m
121121
fi
122122
_ma_real_loop=$(realpath "$_MA_LOOP_DIR" 2>/dev/null || echo "")
123123
# Fallback to raw paths when realpath is unavailable (older macOS/BSD)
124-
[[ -z "$_ma_real_path" ]] && _ma_real_path="$FILE_PATH"
125-
[[ -z "$_ma_real_loop" ]] && _ma_real_loop="$_MA_LOOP_DIR"
124+
# Ensure paths are absolute so prefix guards cannot be bypassed
125+
if [[ -z "$_ma_real_path" ]]; then
126+
if [[ "$FILE_PATH" == /* ]]; then
127+
_ma_real_path="$FILE_PATH"
128+
else
129+
_ma_real_path="$PROJECT_ROOT/$FILE_PATH"
130+
fi
131+
fi
132+
if [[ -z "$_ma_real_loop" ]]; then
133+
if [[ "$_MA_LOOP_DIR" == /* ]]; then
134+
_ma_real_loop="$_MA_LOOP_DIR"
135+
else
136+
_ma_real_loop="$PROJECT_ROOT/$_MA_LOOP_DIR"
137+
fi
138+
fi
126139
if [[ "$_ma_real_path" == "$_ma_real_loop/"* ]]; then
127140
_ma_basename=$(basename "$_ma_real_path")
128141
case "$_ma_basename" in

scripts/bitlesson-select.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,19 @@ run_selector() {
185185
local model="$2"
186186

187187
if [[ "$provider" == "codex" ]]; then
188-
local codex_exec_args=(
189-
"--disable" "codex_hooks"
190-
"--skip-git-repo-check"
191-
"--ephemeral"
188+
local codex_exec_args=()
189+
# Probe whether the installed Codex CLI supports --disable flag
190+
if codex --help 2>&1 | grep -q -- '--disable'; then
191+
codex_exec_args+=("--disable" "codex_hooks")
192+
fi
193+
# Probe for --skip-git-repo-check and --ephemeral support
194+
if codex exec --help 2>&1 | grep -q -- '--skip-git-repo-check'; then
195+
codex_exec_args+=("--skip-git-repo-check")
196+
fi
197+
if codex exec --help 2>&1 | grep -q -- '--ephemeral'; then
198+
codex_exec_args+=("--ephemeral")
199+
fi
200+
codex_exec_args+=(
192201
"-s" "read-only"
193202
"-m" "$model"
194203
"-c" "model_reasoning_effort=low"

tests/test-bitlesson-select-routing.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ CAPTURE_BIN="$TEST_DIR/capture-bin"
448448
mkdir -p "$CAPTURE_BIN"
449449
cat > "$CAPTURE_BIN/codex" <<'EOF'
450450
#!/usr/bin/env bash
451+
# Respond to help probes with supported flags
452+
for arg in "$@"; do
453+
if [[ "$arg" == "--help" ]]; then
454+
echo " --disable <feature> Disable a feature"
455+
echo " --skip-git-repo-check Skip git repo check"
456+
echo " --ephemeral Ephemeral mode"
457+
exit 0
458+
fi
459+
done
451460
printf '%s\n' "$@" > "${TEST_CAPTURE_ARGS:?}"
452461
cat > /dev/null
453462
cat <<'OUT'

0 commit comments

Comments
 (0)