diff --git a/core/skills/implement/SKILL.md b/core/skills/implement/SKILL.md index fd485570..419f753a 100644 --- a/core/skills/implement/SKILL.md +++ b/core/skills/implement/SKILL.md @@ -62,6 +62,8 @@ Before the check and draft push for primary review, rebase your own commits onto Leave base merges out of a branch awaiting its delta. For base or check-script changes after review, follow the [Review budget](../../CONTRACT.md#review-budget). +If a reviewed branch needs a conflict refresh, confirm the review path and +merge the base before starting the check for the resolved head. Preserve the primary for the delta and the delta for post-review fixes. Never bypass the sandbox, change the check list or enable `[checks].network` to pass checks. diff --git a/src/loopzero/runners.py b/src/loopzero/runners.py index 876b69d0..ec18c5cf 100644 --- a/src/loopzero/runners.py +++ b/src/loopzero/runners.py @@ -171,6 +171,16 @@ def _tail(text: str) -> str: return text[-TAIL_CHARS:] +def _auth_failure(family: str, diagnostic: str) -> RunnerAuthFailed: + names = CLAUDE_AUTH_ENV if family == "claude" else CODEX_AUTH_ENV + env = _proc.build_env(names) + values = {variant for value in env.values() if value for variant in (value, json.dumps(value)[1:-1])} + patterns = [*map(re.escape, sorted(values, key=len, reverse=True)), r"\bsk-[A-Za-z0-9_-]{8,}", + r"\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+"] + diagnostic = re.sub("|".join(patterns), "[REDACTED]", diagnostic) + return RunnerAuthFailed(f"{family}: CLI is not authenticated\n{_tail(diagnostic)}") + + def _looks_like_auth_failure(text: str) -> bool: return _AUTH_FAILURE.search(text) is not None @@ -270,7 +280,7 @@ def _run( with contextlib.suppress(json.JSONDecodeError, ValueError): envelope = _extract_json_object(done.stdout) if _claude_envelope_auth_failure(envelope) or _looks_like_auth_failure(combined): - raise RunnerAuthFailed(f"{family}: CLI is not authenticated\n{_tail(combined)}") + raise _auth_failure(family, combined) if _subscription_exhausted(combined, envelope): raise RunnerUsageLimit(f"{family}: usage limit reached", _tail(combined)) if _looks_too_long(combined): @@ -1038,13 +1048,13 @@ def _review_claude( if not isinstance(envelope, dict): raise RunnerMalformedOutput("claude: result envelope is not an object", _tail(raw)) if _claude_envelope_auth_failure(envelope): - raise RunnerAuthFailed(f"claude: CLI is not authenticated\n{_tail(raw)}") + raise _auth_failure("claude", raw) if envelope.get("is_error") and _subscription_exhausted(raw, envelope): raise RunnerUsageLimit("claude: usage limit reached", _tail(raw)) if envelope.get("is_error") or envelope.get("subtype", "success") != "success": text = str(envelope.get("result", "")) if _looks_like_auth_failure(text): - raise RunnerAuthFailed(f"claude: CLI is not authenticated\n{_tail(text)}") + raise _auth_failure("claude", text) if _looks_too_long(text) or _looks_too_long(raw): raise RunnerPromptTooLong("claude: prompt is too long", _tail(raw)) raise RunnerBadOutput(f"claude: {envelope.get('subtype', 'error')}", _tail(raw)) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7dbbd774..466e6377 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2247,6 +2247,21 @@ def test_review_observes_new_codex_version_in_saved_receipt( assert result.provenance["cli_version"] == version +def test_review_redacts_native_authentication_diagnostics(wt, gh, fake_tool, capsys, monkeypatch, head): + arm_empty_primary_review_history(gh, head) + for family, env in (("claude", "ANTHROPIC_API_KEY"), ("codex", "OPENAI_API_KEY")): + monkeypatch.setenv(env, f"opaque-fake-{family}-credential") + fake_tool(family, "if [ \"$1\" = --version ]; then echo 'codex-cli 0.161.0'; exit 0; fi\n" + f'printf "Not logged in with %s (server echoed sk-FakeToken0123)\\n" "${env}" >&2\nexit 1\n') + code, _, err = run(capsys, "review") + assert code == 4 + assert err.count("Not logged in with [REDACTED] (server echoed [REDACTED])") == 2 + assert "opaque-fake-" not in err and "sk-FakeToken0123" not in err + for family, remedy in (("claude", "claude auth login"), ("codex", "codex login")): + assert f"{family}: CLI is not authenticated" in err + assert f"Fix: run `{remedy}`." in err + + @pytest.mark.parametrize("save", [True, False]) def test_review_malformed_fragments_stay_out_of_terminal(wt, gh, fake_bin, monkeypatch, capsys, save): prepare_review(wt, gh, fake_bin) diff --git a/tests/test_runners.py b/tests/test_runners.py index 828cca8e..c7f610a2 100644 --- a/tests/test_runners.py +++ b/tests/test_runners.py @@ -625,7 +625,7 @@ def test_claude_bad_severity(fake_bin: Path, tmp_path: Path) -> None: CLAUDE_EXPIRED_OAUTH = { "is_error": True, "api_error_status": 401, "terminal_reason": "api_error", - "result": "Failed to authenticate. API Error: 401 OAuth access token has expired. Re-authenticate to continue.", + "result": "Failed to authenticate. API Error: 401 OAuth access token has expired. Re-authenticate to continue. Token sk-ant-FAKE0123.", } @@ -653,6 +653,8 @@ def test_claude_classifies_error_envelopes(fake_bin, tmp_path, exit_code, output _review("claude", tmp_path) if error is RunnerBadOutput: assert not isinstance(raised.value, RunnerUsageLimit) + if output is CLAUDE_EXPIRED_OAUTH: + assert "Token [REDACTED]." in str(raised.value) @pytest.mark.parametrize("family,message", [