mirror of https://github.com/garrytan/gstack.git
fix(codex): resolve python for JSON parser
This commit is contained in:
parent
30fe6bb11c
commit
c1200b8247
|
|
@ -1055,10 +1055,15 @@ If the user passed `--xhigh`, use `"xhigh"` instead of `"high"`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
||||||
|
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
|
||||||
|
if [ -z "$PYTHON_CMD" ]; then
|
||||||
|
echo "ERROR: Python 3 is required to parse Codex JSON output. Install python3 or python and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Fix 1+2: wrap with timeout (gtimeout/timeout fallback chain via probe helper),
|
# Fix 1+2: wrap with timeout (gtimeout/timeout fallback chain via probe helper),
|
||||||
# capture stderr to $TMPERR for auth error detection (was: 2>/dev/null).
|
# capture stderr to $TMPERR for auth error detection (was: 2>/dev/null).
|
||||||
TMPERR=${TMPERR:-$(mktemp "$TMP_ROOT/codex-err-XXXXXX.txt")}
|
TMPERR=${TMPERR:-$(mktemp "$TMP_ROOT/codex-err-XXXXXX.txt")}
|
||||||
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="high"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 python3 -u -c "
|
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="high"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||||
import sys, json
|
import sys, json
|
||||||
turn_completed_count = 0
|
turn_completed_count = 0
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
|
|
@ -1201,8 +1206,13 @@ If the user passed `--xhigh`, use `"xhigh"` instead of `"medium"`.
|
||||||
For a **new session:**
|
For a **new session:**
|
||||||
```bash
|
```bash
|
||||||
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
||||||
|
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
|
||||||
|
if [ -z "$PYTHON_CMD" ]; then
|
||||||
|
echo "ERROR: Python 3 is required to parse Codex JSON output. Install python3 or python and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
||||||
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 python3 -u -c "
|
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||||
import sys, json
|
import sys, json
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
@ -1243,8 +1253,13 @@ fi
|
||||||
For a **resumed session** (user chose "Continue"):
|
For a **resumed session** (user chose "Continue"):
|
||||||
```bash
|
```bash
|
||||||
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
||||||
|
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
|
||||||
|
if [ -z "$PYTHON_CMD" ]; then
|
||||||
|
echo "ERROR: Python 3 is required to parse Codex JSON output. Install python3 or python and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
||||||
_gstack_codex_timeout_wrapper 600 codex exec resume <session-id> "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 python3 -u -c "
|
_gstack_codex_timeout_wrapper 600 codex exec resume <session-id> "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||||
<same python streaming parser as above, with flush=True on all print() calls>
|
<same python streaming parser as above, with flush=True on all print() calls>
|
||||||
"
|
"
|
||||||
# Fix 1: same hang detection pattern as new-session block
|
# Fix 1: same hang detection pattern as new-session block
|
||||||
|
|
|
||||||
|
|
@ -284,10 +284,15 @@ If the user passed `--xhigh`, use `"xhigh"` instead of `"high"`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
||||||
|
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
|
||||||
|
if [ -z "$PYTHON_CMD" ]; then
|
||||||
|
echo "ERROR: Python 3 is required to parse Codex JSON output. Install python3 or python and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Fix 1+2: wrap with timeout (gtimeout/timeout fallback chain via probe helper),
|
# Fix 1+2: wrap with timeout (gtimeout/timeout fallback chain via probe helper),
|
||||||
# capture stderr to $TMPERR for auth error detection (was: 2>/dev/null).
|
# capture stderr to $TMPERR for auth error detection (was: 2>/dev/null).
|
||||||
TMPERR=${TMPERR:-$(mktemp "$TMP_ROOT/codex-err-XXXXXX.txt")}
|
TMPERR=${TMPERR:-$(mktemp "$TMP_ROOT/codex-err-XXXXXX.txt")}
|
||||||
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="high"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 python3 -u -c "
|
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="high"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||||
import sys, json
|
import sys, json
|
||||||
turn_completed_count = 0
|
turn_completed_count = 0
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
|
|
@ -430,8 +435,13 @@ If the user passed `--xhigh`, use `"xhigh"` instead of `"medium"`.
|
||||||
For a **new session:**
|
For a **new session:**
|
||||||
```bash
|
```bash
|
||||||
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
||||||
|
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
|
||||||
|
if [ -z "$PYTHON_CMD" ]; then
|
||||||
|
echo "ERROR: Python 3 is required to parse Codex JSON output. Install python3 or python and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
||||||
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 python3 -u -c "
|
_gstack_codex_timeout_wrapper 600 codex exec "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||||
import sys, json
|
import sys, json
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
@ -472,8 +482,13 @@ fi
|
||||||
For a **resumed session** (user chose "Continue"):
|
For a **resumed session** (user chose "Continue"):
|
||||||
```bash
|
```bash
|
||||||
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
_REPO_ROOT=$(git rev-parse --show-toplevel) || { echo "ERROR: not in a git repo" >&2; exit 1; }
|
||||||
|
PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
|
||||||
|
if [ -z "$PYTHON_CMD" ]; then
|
||||||
|
echo "ERROR: Python 3 is required to parse Codex JSON output. Install python3 or python and retry." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
||||||
_gstack_codex_timeout_wrapper 600 codex exec resume <session-id> "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 python3 -u -c "
|
_gstack_codex_timeout_wrapper 600 codex exec resume <session-id> "<prompt>" -C "$_REPO_ROOT" -s read-only -c 'model_reasoning_effort="medium"' --enable web_search_cached --json < /dev/null 2>"$TMPERR" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||||
<same python streaming parser as above, with flush=True on all print() calls>
|
<same python streaming parser as above, with flush=True on all print() calls>
|
||||||
"
|
"
|
||||||
# Fix 1: same hang detection pattern as new-session block
|
# Fix 1: same hang detection pattern as new-session block
|
||||||
|
|
|
||||||
|
|
@ -1332,6 +1332,17 @@ describe('Codex skill', () => {
|
||||||
expect(content).toContain('mktemp');
|
expect(content).toContain('mktemp');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('codex JSON stream parser uses portable Python discovery', () => {
|
||||||
|
const files = ['codex/SKILL.md.tmpl', 'codex/SKILL.md'];
|
||||||
|
|
||||||
|
for (const rel of files) {
|
||||||
|
const content = fs.readFileSync(path.join(ROOT, rel), 'utf-8');
|
||||||
|
expect(content).toContain('PYTHON_CMD=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)');
|
||||||
|
expect(content).toContain('PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c');
|
||||||
|
expect(content).not.toContain('PYTHONUNBUFFERED=1 python3 -u -c');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('adversarial review in /review always runs both passes', () => {
|
test('adversarial review in /review always runs both passes', () => {
|
||||||
const content = fs.readFileSync(path.join(ROOT, 'review', 'SKILL.md'), 'utf-8');
|
const content = fs.readFileSync(path.join(ROOT, 'review', 'SKILL.md'), 'utf-8');
|
||||||
expect(content).toContain('Adversarial review (always-on)');
|
expect(content).toContain('Adversarial review (always-on)');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue