處理 AI review findings 並改寫 Node.js entrypoint #2

Merged
admin merged 59 commits from develop into master 2026-06-24 14:13:11 +00:00
Showing only changes of commit 80c9e51c9c - Show all commits
+31 -15
View File
@@ -9,6 +9,7 @@ die() {
cleanup() { cleanup() {
rm -f "${auth_file:-}" "${auth_path:-}" "${codex_output:-}" rm -f "${auth_file:-}" "${auth_path:-}" "${codex_output:-}"
rmdir "${auth_lock:-}" 2>/dev/null || true
} }
trap cleanup EXIT trap cleanup EXIT
@@ -24,13 +25,13 @@ fi
CODEX_HOME="${CODEX_HOME:-/root/.codex}" CODEX_HOME="${CODEX_HOME:-/root/.codex}"
PROMPT="${PROMPT:-請自我介紹}" PROMPT="${PROMPT:-請自我介紹}"
mkdir -p "$CODEX_HOME" || die "Unable to create CODEX_HOME." mkdir -p "$CODEX_HOME" || die "Unable to create CODEX_HOME."
umask 077
auth_file="$(mktemp "$CODEX_HOME/auth.XXXXXX")" auth_file="$(mktemp "$CODEX_HOME/auth.XXXXXX")"
auth_path="$CODEX_HOME/auth.json" auth_path="$CODEX_HOME/auth.json"
auth_lock="$CODEX_HOME/auth.lock"
if [[ -e "$auth_path" ]]; then mkdir "$auth_lock" || die "Unable to lock Codex auth.json."
die "Refusing to overwrite existing Codex auth.json."
fi
if ! printf '%s\n' "$OAUTH" | base64 -d > "$auth_file"; then if ! printf '%s\n' "$OAUTH" | base64 -d > "$auth_file"; then
die "OAUTH must be valid base64 encoded Codex auth.json." die "OAUTH must be valid base64 encoded Codex auth.json."
@@ -40,26 +41,41 @@ if ! jq -e 'type == "object"' "$auth_file" >/dev/null; then
die "Decoded OAUTH must be a JSON object." die "Decoded OAUTH must be a JSON object."
fi fi
if [[ -e "$auth_path" ]]; then
die "Refusing to overwrite existing Codex auth.json."
fi
install -m 600 "$auth_file" "$auth_path" install -m 600 "$auth_file" "$auth_path"
rm -f "$auth_file" rm -f "$auth_file"
codex_output="$(mktemp)" codex_output="$(mktemp)"
set +e run_codex() {
codex exec \ set +e
--dangerously-bypass-approvals-and-sandbox \ codex exec \
--skip-git-repo-check \ --dangerously-bypass-approvals-and-sandbox \
--model "$MODEL" \ --skip-git-repo-check \
"$PROMPT" 2>&1 | tee "$codex_output" --model "$MODEL" \
codex_status="${PIPESTATUS[0]}" "$PROMPT" 2>&1 | tee "$codex_output"
set -e local status="${PIPESTATUS[0]}"
set -e
return "$status"
}
if run_codex; then
codex_status=0
else
codex_status="$?"
fi
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
if [[ -r /proc/sys/kernel/random/uuid ]]; then while :; do
output_delimiter="CODEX_OUTPUT_$(cat /proc/sys/kernel/random/uuid)"
else
output_delimiter="CODEX_OUTPUT_$(mktemp -u XXXXXXXXXXXXXXXX)" output_delimiter="CODEX_OUTPUT_$(mktemp -u XXXXXXXXXXXXXXXX)"
fi
if ! grep -qxF "$output_delimiter" "$codex_output"; then
break
fi
done
if [[ "$codex_status" -eq 0 ]]; then if [[ "$codex_status" -eq 0 ]]; then
echo "status=completed" >> "$GITHUB_OUTPUT" echo "status=completed" >> "$GITHUB_OUTPUT"