mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-17 13:44:32 +01:00
fix(codex): --effort reaches the probe as an allowlisted request level, parsed before the mode and checked before the paid probe
The level now travels as run-with-timeout --request-effort '<effort-level>' (placeholder grammar ^[a-z]*$) instead of an agent-built env prefix, and the probe names /codex --effort when it rejects one. Effort flags count only right after /codex or its mode word and are removed before mode detection. Step 0.5 runs check-effort before probe-model, so a bad level makes no Codex call even on a cold cache. Tests cover all five dispatch fences and the zero-call cases. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
aa3201670e
commit
62eddd7d05
16 files changed
+161
-81
No files matched your search
+30
-14
@@ -6,7 +6,8 @@
|
||||
#
|
||||
# Subcommands (each wraps one function below):
|
||||
# select-model <exec|review> [--model <id>] CODEX_SEL:, CODEX_SEL_KIND:, CODEX_SANDBOX:
|
||||
# check-effort <default-effort> CODEX_EFFORT:; exit 0, or 1 on an invalid setting
|
||||
# check-effort <default-effort> [--request <level>]
|
||||
# CODEX_EFFORT:; exit 0, or 1 on an invalid setting
|
||||
# check-auth exit 0 authed, 1 not
|
||||
# show-sandbox CODEX_SANDBOX:
|
||||
# check-sandbox exit 0, or 3 with the reason on stderr
|
||||
@@ -17,11 +18,12 @@
|
||||
# CODEX_PROBE_STATE:; exit 0, 1, 2, 3 or 4
|
||||
# check-version warnings on stderr; exit 0
|
||||
# show-first-use-notice notice on stderr; exit 0
|
||||
# run-with-timeout [--user-invoked] [--effort <default>] <secs> <cmd...>
|
||||
# run-with-timeout [--user-invoked] [--effort <default> [--request-effort <level>]] <secs> <cmd...>
|
||||
# the command's exit code; 124 on timeout;
|
||||
# 3 when codex_reviews refuses the send;
|
||||
# --effort appends the resolved
|
||||
# model_reasoning_effort to a codex command
|
||||
# model_reasoning_effort to a codex command;
|
||||
# --request-effort is /codex --effort (empty: none)
|
||||
# log-event <event> [detail] silent; exit 0
|
||||
# log-hang <skill> <prompt-size> silent; exit 0
|
||||
# help usage; an unknown subcommand exits 64
|
||||
@@ -848,15 +850,18 @@ _gstack_codex_log_hang() {
|
||||
# --- Reasoning effort (#3098, #2934) ------------------------------------------
|
||||
|
||||
_gstack_codex_effort_check() {
|
||||
# One precedence, like the model: GSTACK_CODEX_EFFORT (per run), then
|
||||
# codex_effort in config.yaml, then the gate's own default in $1. Codex only
|
||||
# One precedence, like the model: the request's /codex --effort in $2, then
|
||||
# GSTACK_CODEX_EFFORT (per run), then codex_effort in config.yaml, then the
|
||||
# gate's own default in $1. Codex only
|
||||
# rejects an unknown model_reasoning_effort at request time, so an invalid
|
||||
# setting stops here, before any paid call, naming the source to fix. The
|
||||
# allowlist is the union of Codex's config levels and the API's minimal;
|
||||
# levels are model-dependent. A default outside it is a usage error (64).
|
||||
local _default="$1" _chosen _source _cfg
|
||||
local _default="$1" _request="${2:-}" _chosen _source _cfg
|
||||
case "$_default" in minimal|low|medium|high|xhigh|max|ultra) ;; *) return 64 ;; esac
|
||||
if [ -n "${GSTACK_CODEX_EFFORT:-}" ]; then
|
||||
if [ -n "$_request" ]; then
|
||||
_chosen="$_request"; _source="/codex --effort"
|
||||
elif [ -n "${GSTACK_CODEX_EFFORT:-}" ]; then
|
||||
_chosen="$GSTACK_CODEX_EFFORT"; _source="env GSTACK_CODEX_EFFORT"
|
||||
else
|
||||
_cfg=$("$_GSTACK_CODEX_BIN/gstack-config" get codex_effort 2>/dev/null || true)
|
||||
@@ -867,7 +872,11 @@ _gstack_codex_effort_check() {
|
||||
minimal|low|medium|high|xhigh|max|ultra) ;;
|
||||
*)
|
||||
echo "CODEX_EFFORT: invalid — '$_chosen' from $_source is not a Codex reasoning effort level. No Codex call was made." >&2
|
||||
echo "HINT: use one of minimal, low, medium, high, xhigh, max or ultra (export GSTACK_CODEX_EFFORT=<level> or gstack-config set codex_effort <level>), or unset it to keep each gate's own effort." >&2
|
||||
if [ -n "$_request" ]; then
|
||||
echo "HINT: use one of minimal, low, medium, high, xhigh, max or ultra (e.g. /codex review --effort medium), or drop --effort to keep the configured effort." >&2
|
||||
else
|
||||
echo "HINT: use one of minimal, low, medium, high, xhigh, max or ultra (export GSTACK_CODEX_EFFORT=<level> or gstack-config set codex_effort <level>), or unset it to keep each gate's own effort." >&2
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
@@ -881,8 +890,9 @@ _gstack_codex_usage() {
|
||||
printf '%s\n' \
|
||||
'Usage: gstack-codex-probe <subcommand> [args]' \
|
||||
' select-model <exec|review> [--model <id>] print CODEX_SEL:, CODEX_SEL_KIND: and CODEX_SANDBOX:; exit 0 or 1' \
|
||||
' check-effort <default-effort> GSTACK_CODEX_EFFORT, else codex_effort, else the default; print' \
|
||||
' CODEX_EFFORT:; exit 0, 1 on an invalid setting' \
|
||||
' check-effort <default-effort> [--request <level>]' \
|
||||
' the request level, else GSTACK_CODEX_EFFORT, else codex_effort,' \
|
||||
' else the default; print CODEX_EFFORT:; exit 0, 1 on an invalid setting' \
|
||||
' check-auth exit 0 when Codex credentials exist, 1 otherwise' \
|
||||
' show-sandbox print CODEX_SANDBOX: read-only (or danger-full-access)' \
|
||||
' check-sandbox free sandbox check; exit 0, or 3 with the reason on stderr' \
|
||||
@@ -892,12 +902,13 @@ _gstack_codex_usage() {
|
||||
' CODEX_SEL:, CODEX_SEL_KIND:, CODEX_SANDBOX:, CODEX_PROBE_STATE:' \
|
||||
' check-version warn on stderr about known-bad Codex CLI versions; exit 0' \
|
||||
' show-first-use-notice once per machine, say where reviews go; exit 0' \
|
||||
' run-with-timeout [--user-invoked] [--effort <default>] <secs> <cmd...>' \
|
||||
' run-with-timeout [--user-invoked] [--effort <default> [--request-effort <level>]] <secs> <cmd...>' \
|
||||
' run cmd under a deadline once codex_reviews allows the send;' \
|
||||
' its exit code, 124 on timeout, 3 refused (consent_missing).' \
|
||||
' --user-invoked: the user asked for this review by name' \
|
||||
' --effort: append -c model_reasoning_effort=<level> to a codex' \
|
||||
' command, as check-effort resolves it; 1 on an invalid setting' \
|
||||
' --request-effort: /codex --effort, outranking the rest (empty: none)' \
|
||||
' log-event <event> [detail] record a telemetry event when telemetry is on; exit 0' \
|
||||
' log-hang <skill> <prompt-size> record a timeout learning; exit 0' \
|
||||
' help this text'
|
||||
@@ -948,8 +959,8 @@ _gstack_codex_main() {
|
||||
_gstack_codex_select_model "$_GSTACK_CODEX_ARG_KIND" "$_GSTACK_CODEX_ARG_MODEL" || return 1
|
||||
printf 'CODEX_SEL: %s\nCODEX_SEL_KIND: %s\nCODEX_SANDBOX: %s\n' "$_GSTACK_CODEX_SEL" "$_GSTACK_CODEX_SEL_KIND" "$_GSTACK_CODEX_SANDBOX" ;;
|
||||
check-effort)
|
||||
[ "$#" -eq 1 ] || { _gstack_codex_usage >&2; return 64; }
|
||||
_gstack_codex_effort_check "$1"
|
||||
{ [ "$#" -eq 1 ] || { [ "$#" -eq 3 ] && [ "$2" = "--request" ]; }; } || { _gstack_codex_usage >&2; return 64; }
|
||||
_gstack_codex_effort_check "$1" "${3:-}"
|
||||
_rc=$?
|
||||
[ "$_rc" -eq 64 ] && { _gstack_codex_usage >&2; return 64; }
|
||||
return "$_rc" ;;
|
||||
@@ -988,10 +999,15 @@ _gstack_codex_main() {
|
||||
run-with-timeout)
|
||||
_GSTACK_CODEX_USER_INVOKED=0
|
||||
_GSTACK_CODEX_EFFORT_DEFAULT=""
|
||||
_GSTACK_CODEX_EFFORT_REQUEST=""
|
||||
if [ "${1:-}" = "--user-invoked" ]; then _GSTACK_CODEX_USER_INVOKED=1; shift; fi
|
||||
if [ "${1:-}" = "--effort" ]; then
|
||||
{ [ "$#" -ge 2 ] && [ -n "$2" ]; } || { _gstack_codex_usage >&2; return 64; }
|
||||
_GSTACK_CODEX_EFFORT_DEFAULT="$2"; shift 2
|
||||
if [ "${1:-}" = "--request-effort" ]; then
|
||||
[ "$#" -ge 2 ] || { _gstack_codex_usage >&2; return 64; }
|
||||
_GSTACK_CODEX_EFFORT_REQUEST="$2"; shift 2
|
||||
fi
|
||||
fi
|
||||
case "${1:-}" in ''|*[!0-9.]*) _gstack_codex_usage >&2; return 64 ;; esac
|
||||
[ "$#" -ge 2 ] || { _gstack_codex_usage >&2; return 64; }
|
||||
@@ -999,7 +1015,7 @@ _gstack_codex_main() {
|
||||
_gstack_codex_consent "$_GSTACK_CODEX_USER_INVOKED" || return 3
|
||||
if [ -n "$_GSTACK_CODEX_EFFORT_DEFAULT" ]; then
|
||||
_rc=0
|
||||
_GSTACK_CODEX_EFFORT_LINE=$(_gstack_codex_effort_check "$_GSTACK_CODEX_EFFORT_DEFAULT") || _rc=$?
|
||||
_GSTACK_CODEX_EFFORT_LINE=$(_gstack_codex_effort_check "$_GSTACK_CODEX_EFFORT_DEFAULT" "$_GSTACK_CODEX_EFFORT_REQUEST") || _rc=$?
|
||||
[ "$_rc" -eq 64 ] && { _gstack_codex_usage >&2; return 64; }
|
||||
[ "$_rc" -eq 0 ] || return "$_rc"
|
||||
set -- "$@" -c "model_reasoning_effort=\"${_GSTACK_CODEX_EFFORT_LINE#CODEX_EFFORT: }\""
|
||||
|
||||
+14
-14
@@ -483,10 +483,16 @@ Only for an explicit `--role plan-review` (e.g. `/codex challenge --role plan-re
|
||||
set `_CODEX_ROLE='plan-review'` below and in the mode block; the mode block then
|
||||
probes and dispatches the policy model within its own timeout. [Policy setup](https://github.com/garrytan/gstack/blob/main/docs/model-policy.md).
|
||||
|
||||
**Effort flags, read before the mode:** `--effort <level>`, `--effort=<level>` or `--xhigh`
|
||||
(= `--effort xhigh`) directly after `/codex` or its mode word, before any prompt text, set
|
||||
`<effort-level>` (else empty); remove them before Step 1. A later `--effort` is prompt text.
|
||||
Missing value, not one lowercase word, or conflicting flags: stop and say so.
|
||||
|
||||
```bash
|
||||
_CODEX_PROBE=~/.claude/skills/gstack/bin/gstack-codex-probe
|
||||
_CODEX_ROLE=''
|
||||
[ -x "$_CODEX_PROBE" ] || { echo "HELPER_UNAVAILABLE"; exit 1; }
|
||||
"$_CODEX_PROBE" check-effort high --request '<effort-level>' >/dev/null || exit 1 # free
|
||||
|
||||
# GSTACK_ACTIVE_HOST names the harness, never the model.
|
||||
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
|
||||
@@ -507,6 +513,8 @@ fi
|
||||
"$_CODEX_PROBE" check-version # warns if known-bad, non-blocking
|
||||
```
|
||||
|
||||
If `check-effort` failed, relay its lines and stop; no Codex call was made.
|
||||
|
||||
If the runtime guard reports a harness mismatch, stop. Outside coverage is unavailable. Repair with `./setup --host codex`; do not silently substitute another provider or force a same-harness invocation.
|
||||
|
||||
If the output contains `HELPER_UNAVAILABLE`, stop: `gstack-codex-probe` is missing or
|
||||
@@ -570,7 +578,7 @@ After this, every subsequent bash block in this skill uses `"$PLAN_ROOT"` and
|
||||
|
||||
## Step 1: Detect mode
|
||||
|
||||
Parse the user's input to determine which mode to run:
|
||||
Parse the input, effort flags removed, to determine which mode to run:
|
||||
|
||||
1. `/codex review` or `/codex review <instructions>` — **Review mode** (Step 2A)
|
||||
2. `/codex challenge` or `/codex challenge <focus>` — **Challenge mode** (Step 2B)
|
||||
@@ -596,12 +604,8 @@ The three modes are MUTUALLY EXCLUSIVE — at most one runs per invocation. Once
|
||||
the mode is determined, read ONLY that mode's section (see the Section index
|
||||
above); never read the other two mode sections.
|
||||
|
||||
**Reasoning effort override:** for `--effort <level>` or `--effort=<level>` anywhere in
|
||||
the input (`--xhigh` = `--effort xhigh`), remove it from the prompt text and prefix each
|
||||
`run-with-timeout` dispatch with `GSTACK_CODEX_EFFORT=<level>` (`GSTACK_CODEX_EFFORT=xhigh`).
|
||||
It outranks `codex_effort`; the probe rejects unknown levels before any Codex call. Missing
|
||||
value, not one lowercase word, or conflicting flags: stop and say so, never drop it silently.
|
||||
Otherwise `GSTACK_CODEX_EFFORT`, then `codex_effort`, then the per-mode defaults:
|
||||
**Reasoning effort:** each dispatch passes `--request-effort '<effort-level>'`, which
|
||||
outranks `GSTACK_CODEX_EFFORT`, then `codex_effort`, then the per-mode defaults:
|
||||
- Review (2A): `high` — bounded diff input, needs thoroughness
|
||||
- Challenge (2B): `high` — adversarial but bounded by diff
|
||||
- Consult (2C): `medium` — large context, interactive, needs speed
|
||||
@@ -789,13 +793,9 @@ Native `codex review` selects with `review` and sets both `model` and `review_mo
|
||||
flag also keeps installed skills out of Codex's context, so a review cannot become a
|
||||
nested skill run.
|
||||
|
||||
**Reasoning effort (per-mode defaults):**
|
||||
- **Review (2A):** `high` — bounded diff input, needs thoroughness but not max tokens
|
||||
- **Challenge (2B):** `high` — adversarial but bounded by diff size
|
||||
- **Consult (2C):** `medium` — large context (plans, codebase), interactive, needs speed
|
||||
|
||||
`run-with-timeout --effort <default>` resolves `GSTACK_CODEX_EFFORT`, then `gstack-config
|
||||
set codex_effort <level>`, then the default; an invalid value stops before any Codex call.
|
||||
**Reasoning effort** (defaults in Step 1): `run-with-timeout --effort <default>` resolves
|
||||
`--request-effort`, `GSTACK_CODEX_EFFORT`, `codex_effort`, then the default; an invalid
|
||||
value stops before any Codex call.
|
||||
`--user-invoked` runs even with `codex_reviews` disabled: the user asked by name.
|
||||
|
||||
Override one run with `--effort <level>` (`/codex review --effort medium`). `xhigh`
|
||||
|
||||
+14
-14
@@ -77,10 +77,16 @@ Only for an explicit `--role plan-review` (e.g. `/codex challenge --role plan-re
|
||||
set `_CODEX_ROLE='plan-review'` below and in the mode block; the mode block then
|
||||
probes and dispatches the policy model within its own timeout. [Policy setup](https://github.com/garrytan/gstack/blob/main/docs/model-policy.md).
|
||||
|
||||
**Effort flags, read before the mode:** `--effort <level>`, `--effort=<level>` or `--xhigh`
|
||||
(= `--effort xhigh`) directly after `/codex` or its mode word, before any prompt text, set
|
||||
`<effort-level>` (else empty); remove them before Step 1. A later `--effort` is prompt text.
|
||||
Missing value, not one lowercase word, or conflicting flags: stop and say so.
|
||||
|
||||
```bash
|
||||
_CODEX_PROBE=~/.claude/skills/gstack/bin/gstack-codex-probe
|
||||
_CODEX_ROLE=''
|
||||
[ -x "$_CODEX_PROBE" ] || { echo "HELPER_UNAVAILABLE"; exit 1; }
|
||||
"$_CODEX_PROBE" check-effort high --request '<effort-level>' >/dev/null || exit 1 # free
|
||||
|
||||
{{OUTSIDE_SELF_GUARD:codex}}
|
||||
if ! "$_CODEX_PROBE" check-auth >/dev/null; then
|
||||
@@ -92,6 +98,8 @@ fi
|
||||
"$_CODEX_PROBE" check-version # warns if known-bad, non-blocking
|
||||
```
|
||||
|
||||
If `check-effort` failed, relay its lines and stop; no Codex call was made.
|
||||
|
||||
If the runtime guard reports a harness mismatch, stop. Outside coverage is unavailable. Repair with `./setup --host codex`; do not silently substitute another provider or force a same-harness invocation.
|
||||
|
||||
If the output contains `HELPER_UNAVAILABLE`, stop: `gstack-codex-probe` is missing or
|
||||
@@ -155,7 +163,7 @@ After this, every subsequent bash block in this skill uses `"$PLAN_ROOT"` and
|
||||
|
||||
## Step 1: Detect mode
|
||||
|
||||
Parse the user's input to determine which mode to run:
|
||||
Parse the input, effort flags removed, to determine which mode to run:
|
||||
|
||||
1. `/codex review` or `/codex review <instructions>` — **Review mode** (Step 2A)
|
||||
2. `/codex challenge` or `/codex challenge <focus>` — **Challenge mode** (Step 2B)
|
||||
@@ -181,12 +189,8 @@ The three modes are MUTUALLY EXCLUSIVE — at most one runs per invocation. Once
|
||||
the mode is determined, read ONLY that mode's section (see the Section index
|
||||
above); never read the other two mode sections.
|
||||
|
||||
**Reasoning effort override:** for `--effort <level>` or `--effort=<level>` anywhere in
|
||||
the input (`--xhigh` = `--effort xhigh`), remove it from the prompt text and prefix each
|
||||
`run-with-timeout` dispatch with `GSTACK_CODEX_EFFORT=<level>` (`GSTACK_CODEX_EFFORT=xhigh`).
|
||||
It outranks `codex_effort`; the probe rejects unknown levels before any Codex call. Missing
|
||||
value, not one lowercase word, or conflicting flags: stop and say so, never drop it silently.
|
||||
Otherwise `GSTACK_CODEX_EFFORT`, then `codex_effort`, then the per-mode defaults:
|
||||
**Reasoning effort:** each dispatch passes `--request-effort '<effort-level>'`, which
|
||||
outranks `GSTACK_CODEX_EFFORT`, then `codex_effort`, then the per-mode defaults:
|
||||
- Review (2A): `high` — bounded diff input, needs thoroughness
|
||||
- Challenge (2B): `high` — adversarial but bounded by diff
|
||||
- Consult (2C): `medium` — large context, interactive, needs speed
|
||||
@@ -249,13 +253,9 @@ Native `codex review` selects with `review` and sets both `model` and `review_mo
|
||||
flag also keeps installed skills out of Codex's context, so a review cannot become a
|
||||
nested skill run.
|
||||
|
||||
**Reasoning effort (per-mode defaults):**
|
||||
- **Review (2A):** `high` — bounded diff input, needs thoroughness but not max tokens
|
||||
- **Challenge (2B):** `high` — adversarial but bounded by diff size
|
||||
- **Consult (2C):** `medium` — large context (plans, codebase), interactive, needs speed
|
||||
|
||||
`run-with-timeout --effort <default>` resolves `GSTACK_CODEX_EFFORT`, then `gstack-config
|
||||
set codex_effort <level>`, then the default; an invalid value stops before any Codex call.
|
||||
**Reasoning effort** (defaults in Step 1): `run-with-timeout --effort <default>` resolves
|
||||
`--request-effort`, `GSTACK_CODEX_EFFORT`, `codex_effort`, then the default; an invalid
|
||||
value stops before any Codex call.
|
||||
`--user-invoked` runs even with `codex_reviews` disabled: the user asked by name.
|
||||
|
||||
Override one run with `--effort <level>` (`/codex review --effort medium`). `xhigh`
|
||||
|
||||
@@ -55,7 +55,7 @@ if [ -n "$_CODEX_ROLE" ]; then export _CODEX_DEADLINE=$(($(date +%s)+540)); _COD
|
||||
else _CODEX_OUT=$("$_CODEX_PROBE" select-model exec) || exit 1; fi
|
||||
_CODEX_SEL=$(echo "$_CODEX_OUT" | sed -n 's/^CODEX_SEL: //p')
|
||||
_CODEX_SANDBOX_MODE=$(echo "$_CODEX_OUT" | sed -n 's/^CODEX_SANDBOX: //p')
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR" | tee "$TMPRESP.events" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high --request-effort '<effort-level>' 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR" | tee "$TMPRESP.events" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||
import sys, json
|
||||
turn_completed_count = 0
|
||||
turn_failed = False
|
||||
|
||||
@@ -41,7 +41,7 @@ fi
|
||||
[ -n "${TMPERR:-}" ] || TMPERR=$(mktemp "$TMP_ROOT/codex-err-XXXXXX") || { echo "ERROR: mktemp failed in TMP_ROOT=$TMP_ROOT; not running codex without its temp file" >&2; exit 1; }
|
||||
TMPRESP=$(mktemp "$TMP_ROOT/codex-resp-XXXXXX") || { echo "ERROR: mktemp failed in TMP_ROOT=$TMP_ROOT; not running codex without its temp file" >&2; exit 1; }
|
||||
{{CODEX_SELECT:exec:540}}
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR" | tee "$TMPRESP.events" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high --request-effort '<effort-level>' 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR" | tee "$TMPRESP.events" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||
import sys, json
|
||||
turn_completed_count = 0
|
||||
turn_failed = False
|
||||
|
||||
@@ -114,9 +114,9 @@ fi
|
||||
_LABEL=consult${_SID:+-resume}
|
||||
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
||||
if [ -n "$_SID" ]; then
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium 540 codex exec resume "$_SID" - -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium --request-effort '<effort-level>' 540 codex exec resume "$_SID" - -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
else
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium --request-effort '<effort-level>' 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
fi | tee "$TMPRESP.events" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||
import sys, json
|
||||
turn_completed_count = 0
|
||||
|
||||
@@ -100,9 +100,9 @@ fi
|
||||
_LABEL=consult${_SID:+-resume}
|
||||
# Fix 1: wrap with timeout (gtimeout/timeout fallback chain via probe helper)
|
||||
if [ -n "$_SID" ]; then
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium 540 codex exec resume "$_SID" - -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium --request-effort '<effort-level>' 540 codex exec resume "$_SID" - -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
else
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort medium --request-effort '<effort-level>' 540 codex exec - -C "$_REPO_ROOT" -s "${_CODEX_SANDBOX_MODE:?}" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPRESP" < "$PROMPT_FILE" 2>"$TMPERR"
|
||||
fi | tee "$TMPRESP.events" | PYTHONUNBUFFERED=1 "$PYTHON_CMD" -u -c "
|
||||
import sys, json
|
||||
turn_completed_count = 0
|
||||
|
||||
@@ -56,7 +56,7 @@ _CODEX_SANDBOX_MODE=$(echo "$_CODEX_OUT" | sed -n 's/^CODEX_SANDBOX: //p')
|
||||
# The 330s wrapper sits BELOW the 360s Bash gate so the wrapper fires FIRST
|
||||
# and a stall surfaces as a diagnosable exit 124 with an explicit message,
|
||||
# never as a silent harness kill that downstream reads as "no findings".
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high 330 codex review --base <base> -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" -c "review_model=\"${_CODEX_SEL:?}\"" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' < /dev/null >"$TMPOUT" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high --request-effort '<effort-level>' 330 codex review --base <base> -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" -c "review_model=\"${_CODEX_SEL:?}\"" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' < /dev/null >"$TMPOUT" 2>"$TMPERR"
|
||||
_CODEX_EXIT=$?
|
||||
cat "$TMPOUT"
|
||||
if [ "$_CODEX_EXIT" = "124" ]; then
|
||||
@@ -123,7 +123,7 @@ _PROMPT_FILE=$(mktemp "$TMP_ROOT/codex-prompt-XXXXXX") || { echo "ERROR: mktemp
|
||||
git diff "<base>...HEAD" 2>/dev/null
|
||||
printf '\nDIFF_END\n'
|
||||
} > "$_PROMPT_FILE"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high 330 codex exec - -s "${_CODEX_SANDBOX_MODE:?}" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPOUT" < "$_PROMPT_FILE" >"$TMPOUT.events" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high --request-effort '<effort-level>' 330 codex exec - -s "${_CODEX_SANDBOX_MODE:?}" -c "model=\"${_CODEX_SEL:?}\"" -c skills.include_instructions=false -c 'web_search="cached"' --json -o "$TMPOUT" < "$_PROMPT_FILE" >"$TMPOUT.events" 2>"$TMPERR"
|
||||
_CODEX_EXIT=$?
|
||||
rm -f "$_PROMPT_FILE" "$FOCUS_FILE"
|
||||
cat "$TMPOUT"
|
||||
|
||||
@@ -49,7 +49,7 @@ cd "$_REPO_ROOT"
|
||||
# The 330s wrapper sits BELOW the 360s Bash gate so the wrapper fires FIRST
|
||||
# and a stall surfaces as a diagnosable exit 124 with an explicit message,
|
||||
# never as a silent harness kill that downstream reads as "no findings".
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high 330 codex review --base <base> -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" {{CODEX_REVIEW_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} < /dev/null >"$TMPOUT" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high --request-effort '<effort-level>' 330 codex review --base <base> -c "sandbox_mode=\"${_CODEX_SANDBOX_MODE:?}\"" {{CODEX_REVIEW_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} < /dev/null >"$TMPOUT" 2>"$TMPERR"
|
||||
_CODEX_EXIT=$?
|
||||
cat "$TMPOUT"
|
||||
if [ "$_CODEX_EXIT" = "124" ]; then
|
||||
@@ -104,7 +104,7 @@ _PROMPT_FILE=$(mktemp "$TMP_ROOT/codex-prompt-XXXXXX") || { echo "ERROR: mktemp
|
||||
git diff "<base>...HEAD" 2>/dev/null
|
||||
printf '\nDIFF_END\n'
|
||||
} > "$_PROMPT_FILE"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high 330 codex exec - -s "${_CODEX_SANDBOX_MODE:?}" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPOUT" < "$_PROMPT_FILE" >"$TMPOUT.events" 2>"$TMPERR"
|
||||
"$_CODEX_PROBE" run-with-timeout --user-invoked --effort high --request-effort '<effort-level>' 330 codex exec - -s "${_CODEX_SANDBOX_MODE:?}" {{CODEX_MODEL_CONFIG_FLAG}} {{CODEX_WEB_SEARCH_FLAG}} --json -o "$TMPOUT" < "$_PROMPT_FILE" >"$TMPOUT.events" 2>"$TMPERR"
|
||||
_CODEX_EXIT=$?
|
||||
rm -f "$_PROMPT_FILE" "$FOCUS_FILE"
|
||||
cat "$TMPOUT"
|
||||
|
||||
+72
-18
@@ -27,10 +27,10 @@ describe('manual /codex modes (#3098)', () => {
|
||||
test('every mode dispatches through run-with-timeout --effort with its own default', () => {
|
||||
for (const [mode, def] of MODES) {
|
||||
const tmpl = read(`codex/sections/${mode}.md.tmpl`);
|
||||
const dispatches = tmpl.split('\n').filter(line => /run-with-timeout --user-invoked --effort \w+ \d+ codex (exec|review)\b/.test(line));
|
||||
const dispatches = tmpl.split('\n').filter(line => /run-with-timeout --user-invoked --effort \w+ (--request-effort '<effort-level>' )?\d+ codex (exec|review)\b/.test(line));
|
||||
expect(dispatches.length, mode).toBeGreaterThan(0);
|
||||
for (const line of dispatches) {
|
||||
expect(line, mode).toContain(`--effort ${def} `);
|
||||
expect(line, mode).toContain(`--effort ${def} --request-effort '<effort-level>' `);
|
||||
expect(line, mode).not.toContain('model_reasoning_effort');
|
||||
}
|
||||
expect(tmpl, mode).not.toContain('check-effort');
|
||||
@@ -39,10 +39,29 @@ describe('manual /codex modes (#3098)', () => {
|
||||
|
||||
test('the skill body documents the precedence and the --effort / --xhigh overrides', () => {
|
||||
const body = read('codex/SKILL.md.tmpl');
|
||||
for (const want of ['GSTACK_CODEX_EFFORT=xhigh', 'codex_effort', 'run-with-timeout --effort <default>']) expect(body).toContain(want);
|
||||
const step1 = between(body, '**Reasoning effort override:**', '- Review (2A)');
|
||||
expectTokens(step1, ['--effort <level>', '--effort=<level>', '--xhigh', 'GSTACK_CODEX_EFFORT=<level>'], 'codex Step 1');
|
||||
expectMentions(step1, [['remove', 'prompt text'], ['missing', 'lowercase word', 'conflicting', 'stop'], ['never', 'silently']], 'codex Step 1');
|
||||
for (const want of ['GSTACK_CODEX_EFFORT', 'codex_effort', 'run-with-timeout --effort <default>', '--request-effort']) expect(body).toContain(want);
|
||||
const flags = between(body, '**Effort flags, read before the mode:**', '```bash');
|
||||
expectTokens(flags, ['--effort <level>', '--effort=<level>', '--xhigh', '--effort xhigh', '<effort-level>'], 'codex effort flags');
|
||||
expectMentions(flags, [['directly after', 'mode word', 'before any prompt text'], ['later', 'prompt text'], ['remove', 'before Step 1'],
|
||||
['missing', 'lowercase word', 'conflicting', 'stop']], 'codex effort flags');
|
||||
const step1 = between(body, '## Step 1: Detect mode', '- Review (2A)');
|
||||
expectMentions(step1, [['effort flags removed'], ['--request-effort', 'outranks']], 'codex Step 1');
|
||||
});
|
||||
|
||||
test('effort flags are read and validated before mode detection and before the paid model probe', () => {
|
||||
const body = read('codex/SKILL.md.tmpl');
|
||||
const at = (s: string) => { const i = body.indexOf(s); expect(i, s).toBeGreaterThan(-1); return i; };
|
||||
const check = at(`"$_CODEX_PROBE" check-effort high --request '<effort-level>' >/dev/null || exit 1`);
|
||||
expect(at('**Effort flags, read before the mode:**')).toBeLessThan(check);
|
||||
expect(check).toBeLessThan(at('"$_CODEX_PROBE" probe-model exec'));
|
||||
expect(check).toBeLessThan(at('## Step 1: Detect mode'));
|
||||
expect(body).not.toMatch(/prefix each\s+`run-with-timeout` dispatch with `GSTACK_CODEX_EFFORT/);
|
||||
});
|
||||
|
||||
test('docs/model-policy.md documents the per-request --effort flag in its Reasoning effort section', () => {
|
||||
const doc = between(read('docs/model-policy.md'), '## Reasoning effort', '## Which workflows use the tiers?');
|
||||
expectTokens(doc, ['/codex review --effort medium', '--effort=<level>', '--xhigh', '--request-effort', 'GSTACK_CODEX_EFFORT'], 'model-policy effort');
|
||||
expectMentions(doc, [['outranks', 'exported'], ['directly after', 'mode word', 'prompt'], ['unknown level', 'before any Codex call']], 'model-policy effort');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,26 +120,61 @@ echo '{"type":"item.completed","item":{"type":"agent_message","text":"SCORE: 8"}
|
||||
expect(dispatchedArgs('review', 'banana', undefined)).toEqual([]);
|
||||
});
|
||||
|
||||
test('the rendered /codex review dispatch runs at a per-run GSTACK_CODEX_EFFORT prefix, over codex_effort', () => {
|
||||
const fence = read('codex/sections/review-mode.md').split('\n').find(line => /run-with-timeout --user-invoked --effort high 330 codex review /.test(line))!;
|
||||
const state = path.join(TMP, 'state-codex-review-prefix');
|
||||
const FENCES = (['review-mode', 'challenge-mode', 'consult-mode'] as const).flatMap(mode =>
|
||||
read(`codex/sections/${mode}.md`).split('\n').filter(line => /run-with-timeout --user-invoked --effort \w+ --request-effort '<effort-level>' \d+ codex /.test(line))
|
||||
.map(line => ({ mode, line: line.trim().split(' | tee ')[0] })));
|
||||
|
||||
test('all five rendered /codex dispatches carry the request level to the probe, over env and codex_effort', () => {
|
||||
expect(FENCES.length).toBe(5);
|
||||
const state = path.join(TMP, 'state-codex-request-effort');
|
||||
fs.mkdirSync(state, { recursive: true });
|
||||
fs.writeFileSync(path.join(state, 'config.yaml'), 'codex_effort: low\n');
|
||||
const env: Record<string, string> = {};
|
||||
for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !/^(CODEX_|GSTACK_CODEX_|OPENAI_)/.test(k)) env[k] = v;
|
||||
Object.assign(env, { PATH: `${fakeBin}:${process.env.PATH}`, GSTACK_HOME: state, GSTACK_STATE_ROOT: '', CODEX_HOME: TMP, GSTACK_ACTIVE_HOST: 'claude', CLAUDECODE: '1' });
|
||||
const run = (prefix: string) => {
|
||||
const err = path.join(TMP, 'dispatch-err');
|
||||
const run = (line: string, level: string, exported?: string) => {
|
||||
fs.rmSync(capture, { force: true });
|
||||
fs.rmSync(err, { force: true });
|
||||
const script = [`_CODEX_PROBE=${JSON.stringify(path.join(ROOT, 'bin', 'gstack-codex-probe'))}`, '_CODEX_SANDBOX_MODE=read-only', '_CODEX_SEL=gpt-test',
|
||||
`TMPOUT=${JSON.stringify(path.join(TMP, 'review-out'))}`, `TMPERR=${JSON.stringify(path.join(TMP, 'review-err'))}`,
|
||||
prefix + fence.replace('<base>', 'HEAD')].join('\n');
|
||||
spawnSync('bash', ['-c', script], { cwd: repo, env, encoding: 'utf8', timeout: 60_000 });
|
||||
return fs.existsSync(capture) ? fs.readFileSync(capture, 'utf8').split('\n') : [];
|
||||
`_REPO_ROOT=${JSON.stringify(repo)}`, `PROMPT_FILE=${JSON.stringify(prompt)}`, `_PROMPT_FILE=${JSON.stringify(prompt)}`, '_SID=sid-test',
|
||||
`TMPOUT=${JSON.stringify(path.join(TMP, 'dispatch-out'))}`, `TMPRESP=${JSON.stringify(path.join(TMP, 'dispatch-resp'))}`, `TMPERR=${JSON.stringify(err)}`,
|
||||
line.replace('<base>', 'HEAD').replace(`'<effort-level>'`, `'${level}'`)].join('\n');
|
||||
const r = spawnSync('bash', ['-c', script], { cwd: repo, env: exported ? { ...env, GSTACK_CODEX_EFFORT: exported } : env, encoding: 'utf8', timeout: 60_000 });
|
||||
return { status: r.status, args: fs.existsSync(capture) ? fs.readFileSync(capture, 'utf8').split('\n') : [], stderr: fs.existsSync(err) ? fs.readFileSync(err, 'utf8') : '' };
|
||||
};
|
||||
expect(run('')).toContain('model_reasoning_effort="low"');
|
||||
expect(run('GSTACK_CODEX_EFFORT=medium ')).toContain('model_reasoning_effort="medium"');
|
||||
expect(run('GSTACK_CODEX_EFFORT=xhigh ')).toContain('model_reasoning_effort="xhigh"');
|
||||
expect(run('GSTACK_CODEX_EFFORT=bogus ')).toEqual([]);
|
||||
for (const { mode, line } of FENCES) {
|
||||
expect(run(line, '').args, mode).toContain('model_reasoning_effort="low"');
|
||||
expect(run(line, 'medium').args, mode).toContain('model_reasoning_effort="medium"');
|
||||
expect(run(line, 'xhigh').args, mode).toContain('model_reasoning_effort="xhigh"');
|
||||
expect(run(line, 'medium', 'max').args, mode).toContain('model_reasoning_effort="medium"');
|
||||
const bogus = run(line, 'bogus');
|
||||
expect(bogus.args, mode).toEqual([]);
|
||||
expect(bogus.status, mode).toBe(1);
|
||||
expect(bogus.stderr, mode).toContain("CODEX_EFFORT: invalid — 'bogus' from /codex --effort");
|
||||
expect(bogus.stderr, mode).toContain('--effort medium');
|
||||
}
|
||||
});
|
||||
|
||||
test('check-effort --request outranks env and config, and names the flag when the level is invalid', () => {
|
||||
const probe = path.join(ROOT, 'bin', 'gstack-codex-probe');
|
||||
const state = path.join(TMP, 'state-check-effort-request');
|
||||
fs.mkdirSync(state, { recursive: true });
|
||||
fs.writeFileSync(path.join(state, 'config.yaml'), 'codex_effort: low\n');
|
||||
const env: Record<string, string> = {};
|
||||
for (const [k, v] of Object.entries(process.env)) if (v !== undefined && !/^(CODEX_|GSTACK_CODEX_|OPENAI_)/.test(k)) env[k] = v;
|
||||
Object.assign(env, { GSTACK_HOME: state, GSTACK_STATE_ROOT: '' });
|
||||
const check = (args: string[], exported?: string) => spawnSync(probe, ['check-effort', ...args], { env: exported ? { ...env, GSTACK_CODEX_EFFORT: exported } : env, encoding: 'utf8', timeout: 30_000 });
|
||||
expect(check(['high', '--request', 'medium'], 'max').stdout).toBe('CODEX_EFFORT: medium\n');
|
||||
expect(check(['high', '--request', '']).stdout).toBe('CODEX_EFFORT: low\n');
|
||||
expect(check(['high', '--request', ''], 'max').stdout).toBe('CODEX_EFFORT: max\n');
|
||||
const bad = check(['high', '--request', 'turbo']);
|
||||
expect(bad.status).toBe(1);
|
||||
expect(bad.stdout).toBe('');
|
||||
expect(bad.stderr).toContain("'turbo' from /codex --effort");
|
||||
expect(bad.stderr).not.toContain('export GSTACK_CODEX_EFFORT');
|
||||
expect(check(['high', '--request']).status).toBe(64);
|
||||
expect(check(['high', '--bogus', 'low']).status).toBe(64);
|
||||
});
|
||||
|
||||
test('/spec keeps medium effort and its 120 s budget whatever env or config say', () => {
|
||||
|
||||
@@ -645,7 +645,7 @@ describe('codex timeout wrapper: /review + /ship diff passes', () => {
|
||||
|
||||
test(`${relPath}: both diff-review Codex calls run under the wrapper`, () => {
|
||||
const wrapped =
|
||||
read().match(/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+)?\d+\s+codex\s+(exec|review)\b/g) ?? [];
|
||||
read().match(/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+(?:--request-effort\s+'[^']*'\s+)?)?\d+\s+codex\s+(exec|review)\b/g) ?? [];
|
||||
// Adversarial pass + structured review pass.
|
||||
expect(wrapped.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
@@ -658,7 +658,7 @@ describe('codex timeout wrapper: /review + /ship diff passes', () => {
|
||||
});
|
||||
|
||||
test(`${relPath}: wrapper budget stays under the outer Bash gate`, () => {
|
||||
const budgets = [...read().matchAll(/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+)?(\d+)\s+codex\b/g)].map(
|
||||
const budgets = [...read().matchAll(/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+(?:--request-effort\s+'[^']*'\s+)?)?(\d+)\s+codex\b/g)].map(
|
||||
(m) => Number(m[1]) * 1000,
|
||||
);
|
||||
expect(budgets.length).toBeGreaterThan(0);
|
||||
@@ -710,7 +710,7 @@ describe('codex skeleton+sections union: review sandbox + fail-closed gate + tim
|
||||
test(`${relPath}: (a) every scoped codex review invocation pins sandbox_mode from the selected sandbox`, () => {
|
||||
const invocations = read()
|
||||
.split('\n')
|
||||
.filter((l) => /run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+)?\d+\s+codex\s+review\b/.test(l));
|
||||
.filter((l) => /run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+(?:--request-effort\s+'[^']*'\s+)?)?\d+\s+codex\s+review\b/.test(l));
|
||||
expect(invocations.length).toBeGreaterThanOrEqual(1);
|
||||
for (const line of invocations) {
|
||||
// select-model reports read-only (full access only for
|
||||
@@ -772,7 +772,7 @@ describe('codex skeleton+sections union: review sandbox + fail-closed gate + tim
|
||||
const inspected: string[] = [];
|
||||
for (const section of sections) {
|
||||
const gates = [...section.matchAll(/timeout:\s*(\d{4,})/g)].map((m) => Number(m[1]));
|
||||
const wrappers = [...section.matchAll(/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+)?(\d+)\s+codex\b/g)].map(
|
||||
const wrappers = [...section.matchAll(/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+(?:--request-effort\s+'[^']*'\s+)?)?(\d+)\s+codex\b/g)].map(
|
||||
(m) => Number(m[1]) * 1000,
|
||||
);
|
||||
if (gates.length === 0 || wrappers.length === 0) continue;
|
||||
|
||||
@@ -17,7 +17,7 @@ const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'codex-sites-'));
|
||||
afterAll(() => fs.rmSync(TMP, { recursive: true, force: true }));
|
||||
|
||||
/** `codex exec|review` at the start of a shell command, optionally behind the probe's run-with-timeout. */
|
||||
const COMMAND = /(?:^|[;&|]\s*|\$\(\s*)(?:"\$_CODEX_PROBE"\s+run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+)?\d+\s+)?codex\s+(?:exec|review)\b/;
|
||||
const COMMAND = /(?:^|[;&|]\s*|\$\(\s*)(?:"\$_CODEX_PROBE"\s+run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+(?:--request-effort\s+'[^']*'\s+)?)?\d+\s+)?codex\s+(?:exec|review)\b/;
|
||||
const VALIDATOR = /outside-review-result\.ts\b/;
|
||||
|
||||
interface Site { file: string; line: string; fence: string; after: string }
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('Codex skill isolation (#2847)', () => {
|
||||
const calls: string[] = [];
|
||||
for (const file of renderedSkillFiles()) {
|
||||
for (const line of fs.readFileSync(file, 'utf8').split('\n')) {
|
||||
if (/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+)?\d+\s+codex\s+(exec|review)\b/.test(line)) calls.push(`${path.relative(ROOT, file)}: ${line}`);
|
||||
if (/run-with-timeout\s+(?:--user-invoked\s+)?(?:--effort\s+\w+\s+(?:--request-effort\s+'[^']*'\s+)?)?\d+\s+codex\s+(exec|review)\b/.test(line)) calls.push(`${path.relative(ROOT, file)}: ${line}`);
|
||||
}
|
||||
}
|
||||
expect(calls.length).toBeGreaterThan(10);
|
||||
|
||||
@@ -41,6 +41,7 @@ export const IDENTIFIER_PLACEHOLDERS: Record<string, IdentifierGrammar> = {
|
||||
'<clean|flagged>': { grammar: oneOf('clean', 'flagged'), what: 'semantic review outcome' },
|
||||
'<N|null>': { grammar: /^(?:[0-9]+(?:\.[0-9]+)?|null)$/, what: 'health score or null' },
|
||||
'<platform>': { grammar: oneOf('github', 'gitlab', 'unknown'), what: 'detected git platform' },
|
||||
'<effort-level>': { grammar: /^[a-z]*$/, what: "the request's /codex --effort level, or empty for none (the probe validates the level)", quoted: true },
|
||||
|
||||
// Ids, keys and numbers.
|
||||
'<id>': { grammar: ID, what: 'question or record id (kebab-case)' },
|
||||
|
||||
@@ -563,6 +563,7 @@ describe('manual /codex entry: explicit role only, paid probe only for the dispa
|
||||
const preflight = skill.match(/```bash\n(_CODEX_PROBE=[^\n]*\n_CODEX_ROLE=''[\s\S]*?)\n```/)![1]!
|
||||
.replace('{{OUTSIDE_SELF_GUARD:codex}}', RESOLVERS.OUTSIDE_SELF_GUARD(ctxFor('codex', 'claude', HOST_PATHS.claude), ['codex']));
|
||||
const withRole = (text: string, role: string) => text.replaceAll("_CODEX_ROLE=''", `_CODEX_ROLE='${role}'`);
|
||||
const withEffort = (text: string, level: string) => text.replaceAll(`'<effort-level>'`, `'${level}'`);
|
||||
const shell = (h: { dir: string; state: string }, script: string, sh = 'bash') => {
|
||||
fs.mkdirSync(path.join(h.dir, '.claude', 'skills'), { recursive: true });
|
||||
if (!fs.existsSync(path.join(h.dir, '.claude', 'skills', 'gstack'))) fs.symlinkSync(ROOT, path.join(h.dir, '.claude', 'skills', 'gstack'));
|
||||
@@ -574,17 +575,25 @@ describe('manual /codex entry: explicit role only, paid probe only for the dispa
|
||||
|
||||
test('Step 0.5 probes the native model without a role and makes no model call with it', () => {
|
||||
expect(skill).toContain('[Policy setup](https://github.com/garrytan/gstack/blob/main/docs/model-policy.md)');
|
||||
const plain = shell(home(), preflight);
|
||||
const plain = shell(home(), withEffort(preflight, ''));
|
||||
expect(plain.status).toBe(0);
|
||||
expect(plain.stdout).toContain('MODEL_OK');
|
||||
expect(plain.calls.map(codexModel)).toEqual(['model="gpt-5.6-terra"']);
|
||||
const role = shell(home(), withRole(preflight, 'plan-review'));
|
||||
const role = shell(home(), withEffort(withRole(preflight, 'plan-review'), ''));
|
||||
expect(role.status).toBe(0);
|
||||
expect(role.stdout).not.toMatch(/MODEL_OK|MODEL_UNUSABLE|AUTH_FAILED/);
|
||||
expect(role.calls).toEqual([]);
|
||||
expect(role.stderr).not.toContain('NOTICE: gstack plan reviews');
|
||||
});
|
||||
|
||||
test('an invalid /codex --effort level stops Step 0.5 before the paid model probe', () => {
|
||||
const r = shell(home(), withEffort(preflight, 'turbo'));
|
||||
expect(r.status).toBe(1);
|
||||
expect(r.stderr).toContain("'turbo' from /codex --effort");
|
||||
expect(r.stdout).not.toMatch(/MODEL_OK|MODEL_UNUSABLE|AUTH_FAILED/);
|
||||
expect(r.calls).toEqual([]);
|
||||
});
|
||||
|
||||
test('a missing manual challenge prompt stops before the paid readiness probe or notice', () => {
|
||||
const h = home();
|
||||
const template = fs.readFileSync(path.join(ROOT, 'codex/sections/challenge-mode.md.tmpl'), 'utf8');
|
||||
@@ -607,7 +616,7 @@ describe('manual /codex entry: explicit role only, paid probe only for the dispa
|
||||
expect(template.match(/\{\{CODEX_SELECT/g)!.length).toBe(selections.length);
|
||||
for (const block of template.split(/\{\{CODEX_SELECT:/).slice(1)) {
|
||||
const [kind, budget] = block.split('}}')[0]!.split(':');
|
||||
const wrappers = [...block.split('```')[0]!.matchAll(/run-with-timeout (?:--user-invoked )?(?:--effort \w+ )?(\d+) codex/g)].map(m => m[1]);
|
||||
const wrappers = [...block.split('```')[0]!.matchAll(/run-with-timeout (?:--user-invoked )?(?:--effort \w+ (?:--request-effort '[^']*' )?)?(\d+) codex/g)].map(m => m[1]);
|
||||
expect(wrappers.length).toBeGreaterThan(0);
|
||||
expect(new Set(wrappers)).toEqual(new Set([budget]));
|
||||
expect(kind).toMatch(/^(exec|review)$/);
|
||||
|
||||
@@ -17,7 +17,7 @@ const TMP = fs.mkdtempSync(path.join(os.tmpdir(), 'outside-send-boundary-'));
|
||||
afterAll(() => fs.rmSync(TMP, { recursive: true, force: true }));
|
||||
|
||||
const POSITION = String.raw`(?:^|[;&|]\s*|\$\(\s*|\b(?:then|do|else|if|!)\s+)`;
|
||||
const CODEX = new RegExp(`${POSITION}(?:g?timeout\\s+\\S+\\s+)?((?:"\\$_CODEX_PROBE"\\s+run-with-timeout\\s+(?:--user-invoked\\s+)?(?:--effort\\s+\\w+\\s+)?\\d+\\s+)?)codex\\s+(?:exec|review)\\b`);
|
||||
const CODEX = new RegExp(`${POSITION}(?:g?timeout\\s+\\S+\\s+)?((?:"\\$_CODEX_PROBE"\\s+run-with-timeout\\s+(?:--user-invoked\\s+)?(?:--effort\\s+\\w+\\s+(?:--request-effort\\s+'[^']*'\\s+)?)?\\d+\\s+)?)codex\\s+(?:exec|review)\\b`);
|
||||
/** A headless Claude prompt run (`claude -p`, `--print`, or a prompt on stdin), or the resolved CLAUDE_BIN; `claude mcp|auth|config` manage the CLI and send no repository content. */
|
||||
const CLAUDE = new RegExp(`${POSITION}(?:command\\s+)?(?:"\\$\\{?CLAUDE_BIN\\}?"|claude(?=\\s)(?![^|;&]*\\s(?:mcp|auth|config|update|doctor)\\b)[^|;&]*(?:\\s(?:-p|--print)\\b|\\s<\\s*\\S))`);
|
||||
|
||||
@@ -59,7 +59,7 @@ describe('generated skills start outside CLIs only through the consent-enforcing
|
||||
expect(files.length).toBeGreaterThan(20);
|
||||
const bad = files.flatMap(f => directLaunches(fs.readFileSync(f, 'utf8')).map(l => `${path.relative(TMP, f)}: ${l}`));
|
||||
expect(bad).toEqual([]);
|
||||
const wrapped = files.filter(f => /run-with-timeout (?:--user-invoked )?(?:--effort \w+ )?\d+ codex|gstack-claude-code/.test(fs.readFileSync(f, 'utf8')));
|
||||
const wrapped = files.filter(f => /run-with-timeout (?:--user-invoked )?(?:--effort \w+ (?:--request-effort '[^']*' )?)?\d+ codex|gstack-claude-code/.test(fs.readFileSync(f, 'utf8')));
|
||||
expect(wrapped.length).toBeGreaterThan(5);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user