From d99aed9a3c70a59a31de3db1ee703a1c51b39f97 Mon Sep 17 00:00:00 2001 From: Dasemu Date: Sun, 18 Oct 2026 15:02:48 +0200 Subject: [PATCH] chore: bootstrap Claude setup Co-Authored-By: Claude Sonnet 5 --- .claude/bootstrap-version | 1 + .claude/settings.json | 15 ++++++++ .env.example | 15 ++++++++ .github/workflows/ci.yml | 27 +++++++++++++ .github/workflows/version.yml | 59 +++++++++++++++++++++++++++++ CLAUDE.md | 50 ++++++++++++++++++++++++ README.md | 10 ++--- VERSION | 1 + API_SPEC.md => docs/API_SPEC.md | 0 DEPLOYMENT.md => docs/DEPLOYMENT.md | 4 +- OPERATIONS.md => docs/OPERATIONS.md | 0 TODO.md => docs/TODO.md | 0 12 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 .claude/bootstrap-version create mode 100644 .claude/settings.json create mode 100644 .env.example create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/version.yml create mode 100644 CLAUDE.md create mode 100644 VERSION rename API_SPEC.md => docs/API_SPEC.md (100%) rename DEPLOYMENT.md => docs/DEPLOYMENT.md (96%) rename OPERATIONS.md => docs/OPERATIONS.md (100%) rename TODO.md => docs/TODO.md (100%) diff --git a/.claude/bootstrap-version b/.claude/bootstrap-version new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/.claude/bootstrap-version @@ -0,0 +1 @@ +2 diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..4bcd329 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "Stop": [ + { + "matcher": "", + "hooks": [ + { + "type": "command", + "command": "cd \"$CLAUDE_PROJECT_DIR\" && if [ -x .venv/bin/python ]; then PY=.venv/bin/python; else PY=python3; fi; \"$PY\" -m pytest -q" + } + ] + } + ] + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..38fbdc9 --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +# SkiPredictor - environment variables +# Copy to .env and fill in real values. Never commit the real .env file. + +# Telegram bot token (required for the bot and the in-process scheduler). +# See also bot/.env.example for the bot-only subset of this file. +TELEGRAM_BOT_TOKEN= + +# Secret key used to sign JWTs issued by the FastAPI backend (app/api/auth.py). +JWT_SECRET_KEY= + +# Comma-separated Telegram user IDs that receive daily accuracy reports (optional). +ADMIN_TELEGRAM_IDS= + +# Override the default SQLite database path (optional). +SKIPREDICTOR_DB_PATH= diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1bee62c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI + +on: + pull_request: + branches: [development] + push: + branches: [development, main] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + cache: "pip" + + - name: Install dependencies + run: pip install -r requirements.txt + + # No linter is configured for the Python codebase yet (no ruff/black/flake8 in + # requirements.txt or config files), so only the test step runs here. + - name: Run tests + run: python -m pytest -q diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..fdf7170 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,59 @@ +name: Version bump + +on: + push: + branches: [development, main] + +permissions: + contents: write + +jobs: + bump: + if: github.actor != 'github-actions[bot]' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Bump version + run: | + set -euo pipefail + CURRENT=$(cat VERSION) + IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT" + + if [ "${{ github.ref_name }}" = "development" ]; then + PATCH=$((PATCH + 1)) + elif [ "${{ github.ref_name }}" = "main" ]; then + # Merge commit from an approved development -> main PR: bump MINOR. + # Any other push to main is treated as a hotfix: bump PATCH. + PARENTS=$(git log -1 --pretty=%P | wc -w) + if [ "$PARENTS" -ge 2 ] && git log -1 --pretty=%s | grep -qi "development"; then + MINOR=$((MINOR + 1)) + PATCH=0 + else + PATCH=$((PATCH + 1)) + fi + fi + + NEW_VERSION="$MAJOR.$MINOR.$PATCH" + echo "$NEW_VERSION" > VERSION + git add VERSION + git commit -m "chore(release): v$NEW_VERSION [skip ci]" + git tag "v$NEW_VERSION" + git push origin HEAD:${{ github.ref_name }} + git push origin "v$NEW_VERSION" + + - name: Merge main back into development + if: github.ref_name == 'main' + run: | + git fetch origin development + git checkout development + git merge --no-edit origin/main + git push origin development diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..df86a19 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,50 @@ +# CLAUDE.md + +## Overview +SkiPredictor forecasts next-day status (open probability, km open, crowd level) for three +Northern Spain ski stations, combining a rules engine with ML models (scikit-learn, +LightGBM) and YOLO-based webcam crowd detection. Delivered via a FastAPI backend and a +Telegram bot. See `AGENTS.md` for the full product/architecture spec. + +## Commands +- Setup: `./setup.sh` (creates `.venv`, installs `requirements.txt`, downloads historical + data, trains initial models). +- Run backend + bot + scheduler: `./start.sh --cron --collect-now --bot`. +- Run API only: `.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000`. +- Test: `.venv/bin/python -m pytest` (or `python3 -m pytest` if no venv). +- Lint/format: none configured for the Python codebase (no ruff/black/flake8 in + `requirements.txt`). The `mobile/` subproject has its own `npm run lint` (ESLint). +- Retrain models: `.venv/bin/python scripts/retrain_model.py`. + +## Architecture +`data_sources/` (weather + station scraping + webcams) -> `pipeline/` (dataset build + +feature engineering) -> `ml/` + `predictor/` (rules engine, ML models, hybrid combiner) -> +`app/` (FastAPI backend, scheduler) and `bot/` (Telegram bot). `storage/` wraps the +SQLite database. `mobile/` is an independent Capacitor/React app, not wired into the +Python pipeline. Full details: `docs/DEPLOYMENT.md`, `docs/OPERATIONS.md`, +`docs/API_SPEC.md`. + +## Conventions +- Station/feature parameters live in `config/stations.yaml` and `config/features.yaml`; + never hardcode station thresholds in code. +- Rules always take priority over ML output when physical conditions are deterministic + (e.g. extreme wind closes a station regardless of the ML prediction). +- SQLite (`storage/sqlite_store.py`) is the single source of truth; no CSV/JSON fallback + paths for data the DB already owns. + +## Workflow quirks +- Use git worktrees under `.tmp/` for parallel feature work (see `AGENTS.md`), not + directories outside the repo. +- Production is assumed to run on the server unless told otherwise, even when iterating + locally. + +## Deployment +Runs on a VPS/LXC under systemd (no Docker), serving the FastAPI app with an internal +APScheduler for forecast cycles and weekly retraining. See `docs/DEPLOYMENT.md` for the +systemd unit and `docs/OPERATIONS.md` for day-to-day tasks. + +## Gotchas +- `requirements.txt` pulls in `ultralytics`/`opencv-python-headless` (YOLO) and + `lightgbm`; installs are heavy (~2 GB) and the first run downloads the YOLO weights. +- Historical webcam downloads must resolve the real image URL (see `LESSONS.md`) or you + silently save HTML instead of JPEGs. diff --git a/README.md b/README.md index b86ceec..348b9c2 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,14 @@ cd skipredictor ./start.sh --cron --collect-now --bot ``` -*See [DEPLOYMENT.md](DEPLOYMENT.md) for detailed server setup, ML training, and systemd integration.* +*See [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md) for detailed server setup, ML training, and systemd integration.* ## 📖 Documentation -- [API Specification](API_SPEC.md): REST API endpoints, schemas, and authentication. -- [Deployment Guide](DEPLOYMENT.md): Server installation, cron jobs, and ML workflows. -- [Operations Guide](OPERATIONS.md): Common administrative tasks and troubleshooting. -- [TODO / Roadmap](TODO.md): Current status and planned features. +- [API Specification](docs/API_SPEC.md): REST API endpoints, schemas, and authentication. +- [Deployment Guide](docs/DEPLOYMENT.md): Server installation, cron jobs, and ML workflows. +- [Operations Guide](docs/OPERATIONS.md): Common administrative tasks and troubleshooting. +- [TODO / Roadmap](docs/TODO.md): Current status and planned features. ## ⚖️ License diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/API_SPEC.md b/docs/API_SPEC.md similarity index 100% rename from API_SPEC.md rename to docs/API_SPEC.md diff --git a/DEPLOYMENT.md b/docs/DEPLOYMENT.md similarity index 96% rename from DEPLOYMENT.md rename to docs/DEPLOYMENT.md index a67e0fc..3eef9da 100644 --- a/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -84,7 +84,7 @@ WantedBy=multi-user.target ## Legacy Cron Jobs (Optional) -If you prefer not to use the internal scheduler, you can still use standard cron jobs for daily collection and retraining. See [OPERATIONS.md](OPERATIONS.md) for details. +If you prefer not to use the internal scheduler, you can still use standard cron jobs for daily collection and retraining. See [OPERATIONS.md](./OPERATIONS.md) for details. ## Monitoring @@ -94,4 +94,4 @@ If you prefer not to use the internal scheduler, you can still use standard cron ## Project Structure -*See [README.md](README.md) for the full directory tree.* +*See [README.md](../README.md) for the full directory tree.* diff --git a/OPERATIONS.md b/docs/OPERATIONS.md similarity index 100% rename from OPERATIONS.md rename to docs/OPERATIONS.md diff --git a/TODO.md b/docs/TODO.md similarity index 100% rename from TODO.md rename to docs/TODO.md