leetcode: make opus the default coaching model

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWTVKrxg1PGVP4wc6W
This commit is contained in:
Krzysztof Rudnicki 2026-11-20 15:23:07 +01:00
parent 8e5ddf87b7
commit c6725351cd
6 changed files with 18 additions and 11 deletions

View File

@ -3,8 +3,8 @@
Moved out of `SKILL.md` (250-line cap); none of it is coaching instruction. Moved out of `SKILL.md` (250-line cap); none of it is coaching instruction.
The right client is `leetcode <url>` (this package's `leetcode` launcher, The right client is `leetcode <url>` (this package's `leetcode` launcher,
symlinked from `~/.local/bin`): a print-mode loop on sonnet symlinked from `~/.local/bin`): a print-mode loop on opus
(`LEETCODE_MODEL=opus` or `fable` to switch) that also runs (`LEETCODE_MODEL=sonnet` or `fable` to switch) that also runs
the req-before-code gate and the session log (`leetcode report`). The Stop 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 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 toolbox name, but the TUI has already streamed it (2026-09-21: the blocked

View File

@ -104,7 +104,7 @@ def start_session(problem: list[str], *, local: bool) -> int:
opener = local_session.opening_message(problem[1:]) opener = local_session.opening_message(problem[1:])
gate = phase.PhaseGate.open(problem[0]) gate = phase.PhaseGate.open(problem[0])
return local_session.run(problem[0], [], opener, read_block, gate=gate) 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: def main(argv: list[str]) -> int:
@ -115,7 +115,7 @@ def main(argv: list[str]) -> int:
return report.main(args[1:]) return report.main(args[1:])
if not args or args[0] in {"-h", "--help"}: if not args or args[0] in {"-h", "--help"}:
print("Usage: leetcode [--local] <url-or-slug> [what you are stuck on...]") print("Usage: leetcode [--local] <url-or-slug> [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(" --local coach on the local Ollama model (free, offline)")
print(" leetcode due | --cluster <name> | --retest <slug> (--dry-run)") print(" leetcode due | --cluster <name> | --retest <slug> (--dry-run)")
print(" leetcode report req-before-code, max rung, reveal per problem") print(" leetcode report req-before-code, max rung, reveal per problem")

View File

@ -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 The same session `leetcode_repl.run_claude` runs: it opens with
``/leetcode <slug>`` (which loads SKILL.md and arms the no-solution Stop ``/leetcode <slug>`` (which loads SKILL.md and arms the no-solution Stop
@ -43,8 +43,8 @@ TurnError = CoachError
def model() -> str: def model() -> str:
"""The coaching model (``LEETCODE_MODEL``, default sonnet, as the REPL).""" """The coaching model (``LEETCODE_MODEL``, default opus, as the REPL)."""
return os.environ.get("LEETCODE_MODEL") or "sonnet" return os.environ.get("LEETCODE_MODEL") or "opus"
def _env(session: Session) -> dict[str, str]: def _env(session: Session) -> dict[str, str]:

View File

@ -1,7 +1,7 @@
"""Judge kuhy's requirement list, and ambiguous code, on a cheap model. """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 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, 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. and when neither answers the gate fails OPEN: ``unverified``, kuhy continues.

View File

@ -241,6 +241,6 @@ def test_repl_main_dispatches_cluster_commands(
monkeypatch.setattr(local_session, "run", fake_local) monkeypatch.setattr(local_session, "run", fake_local)
monkeypatch.setattr(cluster_cli, "accepted_on_leetcode", never) monkeypatch.setattr(cluster_cli, "accepted_on_leetcode", never)
assert leetcode_repl.main(["--cluster", "intervals"]) == 0 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 leetcode_repl.main(["--local", "--cluster", "intervals"]) == 0
assert handed == ["merge-intervals"] assert handed == ["merge-intervals"]

View File

@ -129,12 +129,12 @@ def test_read_block_joins_lines_until_a_blank(
assert leetcode_repl.read_block() == "x" 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] = [] seen: list[str] = []
monkeypatch.delenv("LEETCODE_MODEL", raising=False) monkeypatch.delenv("LEETCODE_MODEL", raising=False)
monkeypatch.setattr(leetcode_repl, "run_claude", lambda m, _a: seen.append(m)) monkeypatch.setattr(leetcode_repl, "run_claude", lambda m, _a: seen.append(m))
leetcode_repl.main(["two-sum"]) leetcode_repl.main(["two-sum"])
assert seen == ["sonnet"] assert seen == ["opus"]
def test_local_flag_skips_claude(monkeypatch: pytest.MonkeyPatch) -> None: 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.""" """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] body = LAUNCHER.read_text(encoding="utf-8").split("set -euo pipefail", 1)[1]
assert "PYTHONPATH" not in body 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"