diff --git a/scripts/codex-run.sh b/scripts/codex-run.sh index ebbf294..10278b2 100755 --- a/scripts/codex-run.sh +++ b/scripts/codex-run.sh @@ -6,7 +6,8 @@ # codex-run.sh resume [codex-flags...] [prompt] # codex-run.sh review [--base X|--commit Y|--uncommitted] [codex-flags...] [prompt] # -# If /prompt.md exists and no positional prompt given, it is fed via stdin. +# If /prompt.md is non-empty it is always fed via stdin ('-'); codex-flags +# stay positional, so options and a file prompt combine freely. # Review runs against the git repo at the CURRENT WORKING DIRECTORY (no -C support). # # Files written to : events.jsonl last.md err.log thread_id status @@ -36,7 +37,7 @@ esac rm -f "$JOB_DIR/status" "$LAST"; : > "$EV"; : > "$ERR" -if [[ $# -eq 0 && -s $JOB_DIR/prompt.md ]]; then +if [[ -s $JOB_DIR/prompt.md ]]; then "${CMD[@]}" - < "$JOB_DIR/prompt.md" > "$EV" 2> "$ERR" & else "${CMD[@]}" "$@" < /dev/null > "$EV" 2> "$ERR" & diff --git a/tests/stub-ok/codex b/tests/stub-ok/codex index a4bfc59..f81e035 100755 --- a/tests/stub-ok/codex +++ b/tests/stub-ok/codex @@ -5,5 +5,6 @@ prev="" for a in "$@"; do [[ $prev == "-o" ]] && out=$a; prev=$a; done echo '{"type":"thread.started","thread_id":"test-thread-123"}' echo '{"type":"turn.completed"}' -echo "stub answer" > "$out" +stdin_content=$(cat) +echo "stub answer|$stdin_content" > "$out" exit 0 diff --git a/tests/test-run.sh b/tests/test-run.sh index c65e794..47fdc84 100755 --- a/tests/test-run.sh +++ b/tests/test-run.sh @@ -9,7 +9,7 @@ trap 'rm -rf "$TMP"' EXIT CODEX_BIN=$HERE/stub-ok/codex "$RUN" "$TMP/ok" exec "hello" [[ $(cat "$TMP/ok/status") == ok ]] [[ $(cat "$TMP/ok/thread_id") == test-thread-123 ]] -[[ $(cat "$TMP/ok/last.md") == "stub answer" ]] +[[ $(cat "$TMP/ok/last.md") == "stub answer|" ]] # 2. stall -> watchdog kills, status stalled, exit nonzero if CODEX_BIN=$HERE/stub-hang/codex CODEX_STALL_TIMEOUT=4 CODEX_WATCH_INTERVAL=2 \ @@ -23,5 +23,12 @@ fi mkdir -p "$TMP/stdin"; echo "prompt from file" > "$TMP/stdin/prompt.md" CODEX_BIN=$HERE/stub-ok/codex "$RUN" "$TMP/stdin" exec [[ $(cat "$TMP/stdin/status") == ok ]] +[[ $(cat "$TMP/stdin/last.md") == "stub answer|prompt from file" ]] + +# 4. prompt.md + codex flags -> stdin still delivered (regression: options ate the prompt) +mkdir -p "$TMP/flags"; echo "prompt with flags" > "$TMP/flags/prompt.md" +CODEX_BIN=$HERE/stub-ok/codex "$RUN" "$TMP/flags" exec -s read-only +[[ $(cat "$TMP/flags/status") == ok ]] +[[ $(cat "$TMP/flags/last.md") == "stub answer|prompt with flags" ]] echo "ALL PASS"