Skip to content

Commit 2a0faf6

Browse files
committed
Fix BSD sed portability, awk field splitting, and strict parser defaults
- Replace GNU-only sed /I flag with portable grep -oEi for verdict extraction in extract_mainline_progress_verdict - Fix upsert_state_fields awk to split on first = only using index/substr, preventing silent value truncation on values containing = - Add STATE_PRIVACY_MODE default to parse_state_file_strict for parity with the tolerant parser - Cache codex --disable feature probe per loop to avoid running codex --help on every stop-hook invocation
1 parent 611a437 commit 2a0faf6

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

hooks/lib/loop-common.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ parse_state_file_strict() {
532532
STATE_FULL_REVIEW_ROUND="${STATE_FULL_REVIEW_ROUND:-5}"
533533
STATE_ASK_CODEX_QUESTION="${STATE_ASK_CODEX_QUESTION:-true}"
534534
STATE_AGENT_TEAMS="${STATE_AGENT_TEAMS:-false}"
535+
STATE_PRIVACY_MODE="${STATE_PRIVACY_MODE:-true}"
535536
STATE_MAINLINE_STALL_COUNT="${STATE_MAINLINE_STALL_COUNT:-0}"
536537
STATE_LAST_MAINLINE_VERDICT="${STATE_LAST_MAINLINE_VERDICT:-$MAINLINE_VERDICT_UNKNOWN}"
537538
STATE_DRIFT_STATUS="${STATE_DRIFT_STATUS:-$DRIFT_STATUS_NORMAL}"
@@ -585,7 +586,9 @@ extract_mainline_progress_verdict() {
585586
return
586587
fi
587588

588-
verdict_value=$(printf '%s\n' "$verdict_line" | sed -E 's/.*Mainline Progress Verdict:[[:space:]]*(ADVANCED|STALLED|REGRESSED).*/\1/I')
589+
# Extract the verdict word using grep -oEi (portable) instead of sed /I (GNU-only).
590+
# The preceding grep -Ei already ensures the line contains one of the three verdicts.
591+
verdict_value=$(printf '%s\n' "$verdict_line" | grep -oEi 'ADVANCED|STALLED|REGRESSED' | tail -1)
589592
normalize_mainline_progress_verdict "$verdict_value"
590593
}
591594

@@ -602,9 +605,11 @@ upsert_state_fields() {
602605
BEGIN {
603606
count = split(assignments, pairs, " ");
604607
for (i = 1; i <= count; i++) {
605-
split(pairs[i], kv, "=");
606-
keys[kv[1]] = kv[2];
607-
order[i] = kv[1];
608+
eq = index(pairs[i], "=");
609+
key = substr(pairs[i], 1, eq - 1);
610+
val = substr(pairs[i], eq + 1);
611+
keys[key] = val;
612+
order[i] = key;
608613
}
609614
separator_count = 0;
610615
}

hooks/loop-codex-stop-hook.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,17 @@ mkdir -p "$CACHE_DIR"
10631063
# portable-timeout.sh already sourced above
10641064

10651065
# Disable native hooks for nested Codex reviewer calls to prevent Stop-hook recursion.
1066-
# Probe whether the installed Codex CLI supports --disable; fall back to empty args
1066+
# Probe whether the installed Codex CLI supports --disable; cache the result per loop
10671067
# so older builds do not fail with an unknown-argument error.
10681068
CODEX_DISABLE_HOOKS_ARGS=()
1069-
if codex --help 2>&1 | grep -q -- '--disable'; then
1069+
_CODEX_FEATURE_CACHE="$CACHE_DIR/.codex-disable-hooks-supported"
1070+
if [[ -f "$_CODEX_FEATURE_CACHE" ]]; then
1071+
[[ "$(cat "$_CODEX_FEATURE_CACHE")" == "yes" ]] && CODEX_DISABLE_HOOKS_ARGS=(--disable codex_hooks)
1072+
elif codex --help 2>&1 | grep -q -- '--disable'; then
10701073
CODEX_DISABLE_HOOKS_ARGS=(--disable codex_hooks)
1074+
echo "yes" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
1075+
else
1076+
echo "no" > "$_CODEX_FEATURE_CACHE" 2>/dev/null
10711077
fi
10721078

10731079
# Build command arguments for summary review (codex exec)

0 commit comments

Comments
 (0)