refactor(agent): cut MCP-guard, EN-only, persist flags for resume (NUL-safe, hoisted)

This commit is contained in:
admin committed 2026-09-01 00:19:55 +00:00
1 parent f062d03a4e
commit 66048fd74c
3 files changed
+83 -48

No files matched your search

+22 -12
View File
@@ -2,9 +2,9 @@
# codex-crew: deterministic wrapper around `codex exec` with stall watchdog.
#
# Usage:
# codex-run.sh <job_dir> exec [codex-flags...] [prompt]
# codex-run.sh <job_dir> resume <thread_id> [codex-flags...] [prompt]
# codex-run.sh <job_dir> review [--base X|--commit Y|--uncommitted] [codex-flags...] [prompt]
# codex-run.sh <job_dir> exec [codex-flags...]
# codex-run.sh <job_dir> resume <thread_id> [codex-flags...]
# codex-run.sh <job_dir> review [--base X|--commit Y|--uncommitted] [codex-flags...]
#
# If <job_dir>/prompt.md is non-empty it is always fed via stdin ('-'); codex-flags
# stay positional, so options and a file prompt combine freely.
@@ -31,14 +31,14 @@ PF=$JOB_DIR/prompt.md
STALL=${CODEX_STALL_TIMEOUT:-600}
TICK=${CODEX_WATCH_INTERVAL:-15}
BIN=${CODEX_BIN:-codex}
FLAGS_FILE="$JOB_DIR/codex-flags"
build_cmd() { local -a f=("$@"); CMD=("$BIN" "${f[@]}" exec --json --skip-git-repo-check -o "$LAST"); }
case $MODE in
exec) CMD=("$BIN" exec --json --skip-git-repo-check -o "$LAST") ;;
resume) TID=$1; shift; printf '%s\n' "$TID" > "$JOB_DIR/thread_id"
CMD=("$BIN" exec resume "$TID" --json --skip-git-repo-check -o "$LAST") ;;
exec) if (( $# )); then printf '%s\0' "$@" > "$FLAGS_FILE"; else : > "$FLAGS_FILE"; fi
build_cmd "$@" ;;
review)
if [[ -s $JOB_DIR/prompt.md ]]; then
# scope flags conflict with a prompt at the CLI level — move scope into text
SCOPE_DESC=""; REST=()
while [[ $# -gt 0 ]]; do
case $1 in
@@ -48,22 +48,32 @@ case $MODE in
*) REST+=("$1"); shift ;;
esac
done
if (( ${#REST[@]} )); then printf '%s\0' "${REST[@]}" > "$FLAGS_FILE"; else : > "$FLAGS_FILE"; fi
set -- "${REST[@]}"
if [[ -n $SCOPE_DESC ]]; then
PF=$JOB_DIR/prompt.final.md
{ printf 'This is a code review task. %s\n\n' "$SCOPE_DESC"; cat "$JOB_DIR/prompt.md"; } > "$PF"
fi
set -- ${REST[@]+"${REST[@]}"}
fi
CMD=("$BIN" exec review --json --skip-git-repo-check -o "$LAST") ;;
CMD=("$BIN" "$@" exec review --json --skip-git-repo-check -o "$LAST")
else
SCOPE_ARGS=(); REST=()
while [[ $# -gt 0 ]]; do case $1 in --base) SCOPE_ARGS=(--base "$2"); shift 2;; --commit) SCOPE_ARGS=(--commit "$2"); shift 2;; --uncommitted) SCOPE_ARGS=(--uncommitted); shift;; *) REST+=("$1"); shift;; esac; done
if (( ${#REST[@]} )); then printf '%s\0' "${REST[@]}" > "$FLAGS_FILE"; else : > "$FLAGS_FILE"; fi
CMD=("$BIN" "${REST[@]}" exec review "${SCOPE_ARGS[@]}" --json --skip-git-repo-check -o "$LAST")
fi ;;
resume) TID=$1; shift
printf '%s\n' "$TID" > "$JOB_DIR/thread_id"
if [[ -s $FLAGS_FILE ]]; then mapfile -d '' -t SAVED < "$FLAGS_FILE"; set -- "${SAVED[@]}" "$@"; fi
CMD=("$BIN" "$@" exec resume "$TID" --json --skip-git-repo-check -o "$LAST") ;;
*) echo "usage: codex-run.sh <job_dir> exec|resume|review ..." >&2; exit 2 ;;
esac
rm -f "$JOB_DIR/status" "$LAST"; : > "$EV"; : > "$ERR"
if [[ -s $PF ]]; then
"${CMD[@]}" "$@" - < "$PF" > "$EV" 2> "$ERR" &
"${CMD[@]}" - < "$PF" > "$EV" 2> "$ERR" &
else
"${CMD[@]}" "$@" < /dev/null > "$EV" 2> "$ERR" &
"${CMD[@]}" < /dev/null > "$EV" 2> "$ERR" &
fi
PID=$!