From c6725351cd1ea5bc87a205dab225a51d1b5da517 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Fri, 20 Nov 2026 15:23:07 +0100 Subject: [PATCH] leetcode: make opus the default coaching model Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WzxdWWTVKrxg1PGVP4wc6W --- leetcode_coach/leetcode_coach/DOCS-clients.md | 4 ++-- leetcode_coach/leetcode_coach/leetcode_repl.py | 4 ++-- leetcode_coach/leetcode_coach/relay/chat.py | 6 +++--- leetcode_coach/leetcode_coach/req_check.py | 2 +- .../leetcode_coach/tests/test_cluster_cli.py | 2 +- .../leetcode_coach/tests/test_leetcode_repl.py | 11 +++++++++-- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/leetcode_coach/leetcode_coach/DOCS-clients.md b/leetcode_coach/leetcode_coach/DOCS-clients.md index d0bcfa0..00ae2aa 100644 --- a/leetcode_coach/leetcode_coach/DOCS-clients.md +++ b/leetcode_coach/leetcode_coach/DOCS-clients.md @@ -3,8 +3,8 @@ Moved out of `SKILL.md` (250-line cap); none of it is coaching instruction. The right client is `leetcode ` (this package's `leetcode` launcher, -symlinked from `~/.local/bin`): a print-mode loop on sonnet -(`LEETCODE_MODEL=opus` or `fable` to switch) that also runs +symlinked from `~/.local/bin`): a print-mode loop on opus +(`LEETCODE_MODEL=sonnet` or `fable` to switch) that also runs the req-before-code gate and the session log (`leetcode report`). The Stop hook (`stop_gate.py`) sends back a reply with a pasteable line or an early toolbox name, but the TUI has already streamed it (2026-09-21: the blocked diff --git a/leetcode_coach/leetcode_coach/leetcode_repl.py b/leetcode_coach/leetcode_coach/leetcode_repl.py index 4389117..e0dcfac 100755 --- a/leetcode_coach/leetcode_coach/leetcode_repl.py +++ b/leetcode_coach/leetcode_coach/leetcode_repl.py @@ -104,7 +104,7 @@ def start_session(problem: list[str], *, local: bool) -> int: opener = local_session.opening_message(problem[1:]) gate = phase.PhaseGate.open(problem[0]) return local_session.run(problem[0], [], opener, read_block, gate=gate) - return run_claude(os.environ.get("LEETCODE_MODEL", "sonnet"), problem) + return run_claude(os.environ.get("LEETCODE_MODEL", "opus"), problem) def main(argv: list[str]) -> int: @@ -115,7 +115,7 @@ def main(argv: list[str]) -> int: return report.main(args[1:]) if not args or args[0] in {"-h", "--help"}: print("Usage: leetcode [--local] [what you are stuck on...]") - print(" LEETCODE_MODEL=opus|fable leetcode ... (default: sonnet)") + print(" LEETCODE_MODEL=sonnet|fable leetcode ... (default: opus)") print(" --local coach on the local Ollama model (free, offline)") print(" leetcode due | --cluster | --retest (--dry-run)") print(" leetcode report req-before-code, max rung, reveal per problem") diff --git a/leetcode_coach/leetcode_coach/relay/chat.py b/leetcode_coach/leetcode_coach/relay/chat.py index e8f77b1..83ea21b 100644 --- a/leetcode_coach/leetcode_coach/relay/chat.py +++ b/leetcode_coach/leetcode_coach/relay/chat.py @@ -1,4 +1,4 @@ -"""The coaching chat: the CLI's sonnet session, one per problem. +"""The coaching chat: the CLI's opus session, one per problem. The same session `leetcode_repl.run_claude` runs: it opens with ``/leetcode `` (which loads SKILL.md and arms the no-solution Stop @@ -43,8 +43,8 @@ TurnError = CoachError def model() -> str: - """The coaching model (``LEETCODE_MODEL``, default sonnet, as the REPL).""" - return os.environ.get("LEETCODE_MODEL") or "sonnet" + """The coaching model (``LEETCODE_MODEL``, default opus, as the REPL).""" + return os.environ.get("LEETCODE_MODEL") or "opus" def _env(session: Session) -> dict[str, str]: diff --git a/leetcode_coach/leetcode_coach/req_check.py b/leetcode_coach/leetcode_coach/req_check.py index 3adcbd6..8feb827 100644 --- a/leetcode_coach/leetcode_coach/req_check.py +++ b/leetcode_coach/leetcode_coach/req_check.py @@ -1,7 +1,7 @@ """Judge kuhy's requirement list, and ambiguous code, on a cheap model. DOCS-coach-spec.md decision 5: a separate ``claude -p --model haiku`` call (the -coaching session stays on sonnet), Ollama through `local_backend` when haiku +coaching session stays on opus), Ollama through `local_backend` when haiku is out of quota, errors or answers something that is not the JSON asked for, and when neither answers the gate fails OPEN: ``unverified``, kuhy continues. diff --git a/leetcode_coach/leetcode_coach/tests/test_cluster_cli.py b/leetcode_coach/leetcode_coach/tests/test_cluster_cli.py index ccbe6af..368a16d 100644 --- a/leetcode_coach/leetcode_coach/tests/test_cluster_cli.py +++ b/leetcode_coach/leetcode_coach/tests/test_cluster_cli.py @@ -241,6 +241,6 @@ def test_repl_main_dispatches_cluster_commands( monkeypatch.setattr(local_session, "run", fake_local) monkeypatch.setattr(cluster_cli, "accepted_on_leetcode", never) assert leetcode_repl.main(["--cluster", "intervals"]) == 0 - assert started == [("sonnet", ["merge-intervals"])] + assert started == [("opus", ["merge-intervals"])] assert leetcode_repl.main(["--local", "--cluster", "intervals"]) == 0 assert handed == ["merge-intervals"] diff --git a/leetcode_coach/leetcode_coach/tests/test_leetcode_repl.py b/leetcode_coach/leetcode_coach/tests/test_leetcode_repl.py index 7688298..05c256d 100644 --- a/leetcode_coach/leetcode_coach/tests/test_leetcode_repl.py +++ b/leetcode_coach/leetcode_coach/tests/test_leetcode_repl.py @@ -129,12 +129,12 @@ def test_read_block_joins_lines_until_a_blank( assert leetcode_repl.read_block() == "x" -def test_repl_defaults_to_sonnet(monkeypatch: pytest.MonkeyPatch) -> None: +def test_repl_defaults_to_opus(monkeypatch: pytest.MonkeyPatch) -> None: seen: list[str] = [] monkeypatch.delenv("LEETCODE_MODEL", raising=False) monkeypatch.setattr(leetcode_repl, "run_claude", lambda m, _a: seen.append(m)) leetcode_repl.main(["two-sum"]) - assert seen == ["sonnet"] + assert seen == ["opus"] def test_local_flag_skips_claude(monkeypatch: pytest.MonkeyPatch) -> None: @@ -179,3 +179,10 @@ def test_launcher_does_not_leak_pythonpath_into_the_session() -> None: """The REPL hands its environment to `claude -p`; the launcher adds nothing.""" body = LAUNCHER.read_text(encoding="utf-8").split("set -euo pipefail", 1)[1] assert "PYTHONPATH" not in body + + +def test_relay_chat_defaults_to_opus(monkeypatch: pytest.MonkeyPatch) -> None: + from leetcode_coach.relay import chat + + monkeypatch.delenv("LEETCODE_MODEL", raising=False) + assert chat.model() == "opus"