utils/leetcode_coach/leetcode_coach/leetcode
Krzysztof kuhy Rudnicki 9b82aba9c8
Some checks are pending
file length / file-length (push) Waiting to run
focus-project pre-commit / pre-commit (push) Waiting to run
focus-project tests / test (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
leetcode-coach pre-commit / pre-commit (push) Waiting to run
leetcode-coach tests / test (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
Coach on OmniRoute free-best after a Claude limit
The REPL, relay and graders fall back to OmniRoute free-best, then
Ollama, through the same no-solution gate. leetcode --free starts
claude-free with the skill from /tmp/leetcode-free. v0.1.7.

Todo: 9005c9b4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:47:58 +01:00

43 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# leetcode — coaching session in print mode, on the cheapest model.
# Print mode matters: the no-solution Stop gate can only withhold a reply
# from a client that waits for hooks, and the interactive TUI streams first.
# leetcode <url-or-slug> [what you are stuck on...]
# leetcode --free <url-or-slug> [...] interactive claude-free (OmniRoute
# free-best, no Claude quota) with the /leetcode skill, started in
# /tmp/leetcode-free: claude-free runs only from a public directory, and
# the free providers log prompts, so nothing private is in reach. One
# fixed dir, so Claude Code asks to trust it once, not every session.
#
# Symlinked from ~/.local/bin/leetcode. The package is found through
# install.sh's editable install, like the Stop-hook shim; no PYTHONPATH here,
# because the REPL passes its environment on to `claude -p` and every hook and
# Bash call of the coached session would inherit it. -P keeps cwd off sys.path.
# ============================================================================
set -euo pipefail
readonly CLAUDE_FREE="${LEETCODE_CLAUDE_FREE_BIN:-claude-free}"
readonly FREE_DIR="${LEETCODE_FREE_DIR:-/tmp/leetcode-free}"
run_free() {
[[ -e "${FREE_DIR}" || -L "${FREE_DIR}" ]] || mkdir -m 700 "${FREE_DIR}"
# /tmp is shared: never start in a dir someone else planted there.
[[ -O "${FREE_DIR}" && ! -L "${FREE_DIR}" ]] || {
echo "leetcode: ${FREE_DIR} is not a directory you own" >&2
exit 77
}
cd "${FREE_DIR}"
exec "${CLAUDE_FREE}" "/leetcode $*"
}
if [[ "${1:-}" == --free ]]; then
shift
[[ $# -gt 0 ]] || { echo "Usage: leetcode --free <url-or-slug> [stuck on...]" >&2; exit 64; }
run_free "$@"
fi
exec /usr/bin/python3 -P -m leetcode_coach.leetcode_repl "$@"