fix: propagate codex exit code, safe arithmetic, preserve cwd

- Add script -e flag so codex exit code propagates through PTY wrapper
- Use subshell for git repo check to avoid changing caller's cwd
  (fixes broken relative --workdir paths)
- Replace ((ERRORS++)) with ERRORS=$((ERRORS + 1)) to avoid set -e
  terminating on first verification failure
- Add script binary to installer dependency check
This commit is contained in:
Robert Koller 2026-03-16 05:26:05 +00:00
parent 6fbffd98fa
commit 5b8332e88d
3 changed files with 21 additions and 12 deletions

View File

@ -114,11 +114,21 @@ if ! command -v timeout &> /dev/null; then
if [[ "$(uname)" == "Darwin" ]]; then
echo " Install with: brew install coreutils"
fi
((MISSING++))
MISSING=$((MISSING + 1))
else
info "timeout: available"
fi
if ! command -v script &> /dev/null; then
error "'script' (from util-linux) is required for Codex PTY support."
if [[ "$(uname)" == "Darwin" ]]; then
echo " Install with: brew install util-linux"
fi
MISSING=$((MISSING + 1))
else
info "script: available"
fi
if command -v tmux &> /dev/null; then
info "tmux: available"
else
@ -126,7 +136,7 @@ else
fi
if [[ $MISSING -gt 0 ]]; then
error "Missing $MISSING required system dependency. Install it and rerun."
error "Missing $MISSING required system dependencies. Install them and rerun."
exit 1
fi
@ -198,35 +208,35 @@ if command -v claude &> /dev/null || $DRY_RUN; then
info "claude CLI: OK"
else
error "claude CLI: not found"
((ERRORS++))
ERRORS=$((ERRORS + 1))
fi
if command -v codex &> /dev/null || $DRY_RUN; then
info "codex CLI: OK"
else
error "codex CLI: not found"
((ERRORS++))
ERRORS=$((ERRORS + 1))
fi
if [[ -f "$SKILL_DIR/SKILL.md" ]] || $DRY_RUN; then
info "SKILL.md: OK"
else
error "SKILL.md: not found at $SKILL_DIR"
((ERRORS++))
ERRORS=$((ERRORS + 1))
fi
if [[ -x "$SKILL_DIR/scripts/delegate.sh" ]] || $DRY_RUN; then
info "scripts/delegate.sh: OK"
else
error "scripts/delegate.sh: not found or not executable"
((ERRORS++))
ERRORS=$((ERRORS + 1))
fi
if [[ -x "$SKILL_DIR/scripts/tmux-session.sh" ]] || $DRY_RUN; then
info "scripts/tmux-session.sh: OK"
else
error "scripts/tmux-session.sh: not found or not executable"
((ERRORS++))
ERRORS=$((ERRORS + 1))
fi
# --- Auth check ---

View File

@ -118,8 +118,7 @@ fi
# Codex requires a git repository — fail fast instead of silently mutating
if [[ "$AGENT" == "codex" ]]; then
cd "$WORKDIR"
if [[ ! -d .git ]] && ! git rev-parse --git-dir > /dev/null 2>&1; then
if ! (cd "$WORKDIR" && { [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; }); then
echo "Error: Codex requires a git repository but $WORKDIR is not one." >&2
echo "Initialize one with: cd $WORKDIR && git init" >&2
exit 1
@ -167,9 +166,10 @@ run_delegation() {
;;
codex)
# Codex requires a PTY — use script(1) to provide one.
# -e: propagate child exit code (without it, script always returns 0)
# Run through bash -c so printf '%q' quoting is interpreted correctly
# (script passes commands to /bin/sh which may be dash, not bash).
script -q -c "bash -c $(printf '%q' "$(build_codex_cmd) $(printf '%q' "$PROMPT")")" "$LOG_FILE" || exit_code=$?
script -e -q -c "bash -c $(printf '%q' "$(build_codex_cmd) $(printf '%q' "$PROMPT")")" "$LOG_FILE" || exit_code=$?
;;
esac

View File

@ -128,8 +128,7 @@ case "$ACTION" in
# Codex requires a git repo
if [[ "$AGENT" == "codex" ]]; then
cd "$WORKDIR"
if [[ ! -d .git ]] && ! git rev-parse --git-dir > /dev/null 2>&1; then
if ! (cd "$WORKDIR" && { [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; }); then
echo "Error: Codex requires a git repository but $WORKDIR is not one." >&2
echo "Initialize one with: cd $WORKDIR && git init" >&2
exit 1