diff --git a/Dockerfile b/Dockerfile index 5500335..5ffe11c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,15 +6,42 @@ ENV PYTHONDONTWRITEBYTECODE=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 # Runtime deps: stockfish for eval, tmux for the agent panes, curl for the -# in-container vendor fetch step. +# in-container vendor fetch step, jq for pane-agent.sh JSON parse, +# node+npm for the claude-code CLI. RUN apt-get update && apt-get install -y --no-install-recommends \ stockfish \ tmux \ curl \ ca-certificates \ procps \ + jq \ + xz-utils \ + gnupg \ + && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ + && apt-get install -y --no-install-recommends nodejs \ && rm -rf /var/lib/apt/lists/* +# claude-code CLI — install globally via npm. The version pin keeps the +# image deterministic; bump as needed. +RUN npm install -g --omit=dev @anthropic-ai/claude-code@2.1.141 \ + && claude --version + +# codex CLI — official linux release tarball. The musl static binary +# works on Debian. +ARG CODEX_VERSION=0.130.0 +RUN curl -fsSL "https://github.com/openai/codex/releases/download/rust-v${CODEX_VERSION}/codex-x86_64-unknown-linux-musl.tar.gz" \ + -o /tmp/codex.tar.gz \ + && mkdir -p /tmp/codex && tar -xzf /tmp/codex.tar.gz -C /tmp/codex --strip-components=0 \ + && find /tmp/codex -type f -name 'codex-*' -exec mv {} /usr/local/bin/codex \; \ + && chmod +x /usr/local/bin/codex \ + && rm -rf /tmp/codex /tmp/codex.tar.gz \ + && codex --version + +# Debian's stockfish package installs to /usr/games/stockfish which is not +# on the default PATH for non-login shells. Symlink it so `which stockfish` +# works for both the Python wrapper and any spawn from tmux panes. +RUN ln -s /usr/games/stockfish /usr/local/bin/stockfish && stockfish --help >/dev/null 2>&1 || true + WORKDIR /app # Copy everything first — pip install -e needs src/ai_chess to exist at @@ -35,5 +62,50 @@ RUN chmod +x scripts/*.sh && ./scripts/fetch-vendor.sh # Runtime artefacts (games/, logs/, config/) — keep as named mountable dirs. RUN mkdir -p games logs config +# claude-code refuses to run with --dangerously-skip-permissions as root, +# so the container's main process drops to a non-root user. Codex is also +# fine here. The user's HOME (=/home/chess) is where ~/.codex lives, so +# the docker-compose volume mounts target /home/chess/.codex. +RUN useradd -m -u 1000 -s /bin/bash chess && chown -R chess:chess /app + +# Pre-seed claude-code state so its first-run onboarding (theme picker, +# changelog popup, etc.) is skipped — the flag lives in ~/.claude.json +# (a file in HOME, *not* the ~/.claude/ directory). Without this every +# fresh pane-agent.sh hangs at the theme prompt. +RUN mkdir -p /home/chess/.claude && \ + cat > /home/chess/.claude/settings.json <<'EOF' +{ + "theme": "light", + "permissions": { "allow": ["*"], "defaultMode": "bypassPermissions" }, + "skipDangerousModePermissionPrompt": true +} +EOF +RUN cat > /home/chess/.claude.json <<'EOF' +{ + "hasCompletedOnboarding": true, + "lastOnboardingVersion": "2.1.141", + "numStartups": 1, + "autoUpdates": false, + "officialMarketplaceAutoInstallAttempted": true, + "officialMarketplaceAutoInstalled": false, + "migrationVersion": 13, + "opusProMigrationComplete": true, + "sonnet1m45MigrationComplete": true, + "projects": { + "/app": { + "hasTrustDialogAccepted": true, + "hasClaudeMdExternalIncludesApproved": true, + "hasClaudeMdExternalIncludesWarningShown": true, + "projectOnboardingSeenCount": 1, + "allowedTools": ["*"] + } + } +} +EOF +RUN chown -R chess:chess /home/chess +USER chess +WORKDIR /app +ENV HOME=/home/chess + EXPOSE 7833 CMD ["python", "-m", "ai_chess"] diff --git a/deploy/codex/config.toml b/deploy/codex/config.toml new file mode 100644 index 0000000..fff1cd6 --- /dev/null +++ b/deploy/codex/config.toml @@ -0,0 +1,22 @@ +# Minimal codex config for the ai-chess container. +# Uses the user's cliproxyapi gateway; the chess MCP server lives next door +# (uvicorn on 127.0.0.1:7833 inside the same container) and is overridden +# per-side via -c at launch time by scripts/pane-agent.sh. + +model = "gpt-5.5" +model_provider = "cliproxyapi" +model_reasoning_effort = "xhigh" +approval_policy = "never" +sandbox_mode = "danger-full-access" +service_tier = "fast" + +[model_providers.cliproxyapi] +name = "cliproxyapi" +base_url = "https://cli.machka.dev/v1" +wire_api = "responses" + +[mcp_servers.chess] +url = "http://127.0.0.1:7833/mcp/black" + +[notice] +hide_full_access_warning = true diff --git a/docker-compose.yml b/docker-compose.yml index 77aef6b..24a121c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,16 +7,23 @@ services: environment: AI_CHESS_HOST: "0.0.0.0" # listen on all interfaces inside the container AI_CHESS_PORT: "7833" + # claude-code auth — talks to user's machka gateway, no Anthropic + # subscription needed at runtime. + ANTHROPIC_BASE_URL: "${ANTHROPIC_BASE_URL:-https://claude.machka.dev}" + ANTHROPIC_AUTH_TOKEN: "${ANTHROPIC_AUTH_TOKEN}" networks: default: caddy-network: aliases: - chessai - # Persistent runtime data — survives container rebuilds. volumes: + # Persistent runtime data — survives container rebuilds. - ./games:/app/games - ./logs:/app/logs - ./config:/app/config + # codex config + auth lives in /opt/chessai/secrets/codex on the host + # and is mapped into the container's $CODEX_HOME (= ~/.codex by default). + - ./secrets/codex:/home/chess/.codex:ro networks: caddy-network: diff --git a/scripts/pane-agent.sh b/scripts/pane-agent.sh index 25c5274..0712352 100755 --- a/scripts/pane-agent.sh +++ b/scripts/pane-agent.sh @@ -50,6 +50,9 @@ fi cd "$ROOT" +: "${CLAUDE_BIN:=$(command -v claude || echo /usr/local/bin/claude)}" +: "${CODEX_BIN:=$(command -v codex || echo /usr/local/bin/codex)}" + case "$agent" in claude) cat > "$CFG/claude-settings.${side}.json" </dev/null 2>&1 || true - /opt/homebrew/bin/codex mcp add chess --url "http://127.0.0.1:7833/mcp/${side}" - trap '/opt/homebrew/bin/codex mcp remove chess >/dev/null 2>&1 || true' EXIT - - exec /opt/homebrew/bin/codex \ + # Override the global config's chess MCP url (each side talks to its own + # path). The user's persistent ~/.codex/config.toml does NOT get + # rewritten — we just pass an inline override. + exec "$CODEX_BIN" \ -c 'model="gpt-5.5"' \ -c 'model_reasoning_effort="xhigh"' \ -c 'service_tier="fast"' \ -c "tui.theme=\"${codex_theme}\"" \ + -c "mcp_servers.chess.url=\"http://127.0.0.1:7833/mcp/${side}\"" \ --dangerously-bypass-approvals-and-sandbox ;;