estimate_physics was abstract on LLMProvider and implemented by every provider, but pass 2 has been estimator-only for a while -- nothing called it. Removed it along with PHYSICS_ESTIMATION_PROMPT, format_metrics_for_prompt and parse_metric_json. STATUS.md and the original IMPLEMENTATION_PLAN.md described a project that no longer exists; replaced with a phased plan for making the repo and a hosted demo safe and presentable. Co-Authored-By: Claude <noreply@anthropic.com>
61 lines
6.7 KiB
Markdown
61 lines
6.7 KiB
Markdown
# Implementation Plan — Public Release
|
||
|
||
Goal: make PhysCom presentable on the internet, both as a **public GitHub repo** and as a **hosted demo site**. The core engine is done: a 5-pass pipeline with 132 passing tests, a web UI with full CRUD, and Gemini and Ollama providers for pass 4. What's left is safety, packaging and presentation.
|
||
|
||
Phases are ordered by risk. **Phase 1 blocks any public deployment.** Phases 2–3 block a good first impression. Phase 4 is optional.
|
||
|
||
---
|
||
|
||
## Phase 1 — Make it safe to expose (blocker)
|
||
|
||
The Docker image today runs Flask's **dev server with `debug=True` bound to `0.0.0.0`**. The Werkzeug debugger allows remote code execution, so the current container must never be reachable from the internet.
|
||
|
||
| # | Task | Where | Notes |
|
||
|---|------|-------|-------|
|
||
| 1.1 | Serve with gunicorn, debug off | `Dockerfile`, `pyproject.toml` (`web` extra) | `gunicorn -w 1 --threads 8 "physcom_web.app:create_app()"`. Use one worker because pipeline runs are background threads inside the web process. Keep `python -m physcom_web` as the localhost-only dev entry point. Only turn on `debug=True` when `FLASK_DEBUG=1`. |
|
||
| 1.2 | Read-only public mode | `app.py`, a `before_request` hook | Add a `PHYSCOM_ADMIN_TOKEN` env var. If it's unset, only localhost can write. On a public host, every non-GET request and the `/admin`, `/pipeline`, entity/domain edit and review routes need a session flag set by a one-field `/login?token=` form. Browsing results, entities, domains and the result "explore" panel stays public. There's no user system: one admin is enough for a demo. |
|
||
| 1.3 | CSRF | `app.py` | With 1.2, only the admin can write. Set `SESSION_COOKIE_SAMESITE="Lax"`, `SESSION_COOKIE_SECURE=True` and `SESSION_COOKIE_HTTPONLY=True`; Lax already blocks cross-site POSTs. Only add Flask-WTF if public writes are ever allowed. |
|
||
| 1.4 | Check that "explore" is safe to leave public | `routes/results.py:91` | It's a POST that re-runs the estimator for one combo. Confirm it writes nothing, and cap its cost with a request timeout or small rate limit (a per-IP token bucket in memory is enough). If it does write, put it behind the admin check. |
|
||
| 1.5 | Persistent secret key | `app.py:36` | Today it falls back to a random key on each start, which logs the admin out on every restart and breaks sessions if there's ever more than one worker. In public mode, refuse to start without `FLASK_SECRET_KEY`. |
|
||
| 1.6 | Hardened container | `Dockerfile` | Run as a non-root user, add a `HEALTHCHECK` against `/`, and pin the base image digest. |
|
||
| 1.7 | Untrack local config | `.claude/settings.local.json` | It's committed today. `git rm --cached` it and add it to `.gitignore`. Check the git history for anything sensitive before making the repo public. |
|
||
| 1.8 | Tests | `tests/test_web_access.py` (new, one file) | Using the Flask test client: anonymous GET of results → 200; anonymous POST to `/admin/wipe` → 403; request with the token → allowed; debug off by default. |
|
||
|
||
**Done when:** the container runs gunicorn, anonymous visitors can browse but can't change anything, and 1.8 passes.
|
||
|
||
## Phase 2 — Public repo polish
|
||
|
||
| # | Task | Notes |
|
||
|---|------|-------|
|
||
| 2.1 | `LICENSE` | Choose one (MIT is the usual default) and set `license` in `pyproject.toml`. Check with the employer first, since the repo lives under a corporate OneDrive. |
|
||
| 2.2 | Rewrite `README.md` | Keep the transport pitch at the top. It still lists the old metrics (safety and availability were removed from scoring) and still says 9×9 = 81 combos; the seed is now 11 × 15 × 18 across 5 domains. Replace the "a few notes" brainstorm at the bottom with a short **How it works** section (the 5 passes, emergent guardrails, log-normalized geometric mean) that links to `LOGIC DOCS/`. Add 2–3 screenshots (results list, combo detail, explore panel) and a link to the live demo. |
|
||
| 2.3 | CI | `.github/workflows/test.yml`: `pip install -e ".[dev,web]"` then `pytest -q` on Python 3.11 and 3.13. Add a badge to the README. |
|
||
| 2.4 | `pyproject.toml` metadata | Change `requires-python` from `>=3.10` to `>=3.11` (CLAUDE.md says 3.11+). Add authors, `readme`, `license`, `urls`. |
|
||
| 2.5 | Compose parity | Add `OLLAMA_MODEL` and `OLLAMA_HOST` to `docker-compose.yml` (only the Gemini vars are there now). Delete the commented-out Postgres block (see Phase 4). |
|
||
| 2.6 | Web route smoke tests | Extend 1.8's file with a parametrized "every GET route returns 200 on the seeded DB" test. The only web tests today are the async-pipeline tests; entity, domain and result pages have no coverage. |
|
||
|
||
## Phase 3 — Hosted demo
|
||
|
||
| # | Task | Notes |
|
||
|---|------|-------|
|
||
| 3.1 | Ship precomputed results | A full run is CPU-heavy (about 11.7k optimizer calls per combo), and anonymous runs would invite DoS. Run all 5 domains offline, export with `physcom snapshot export`, and load that snapshot on first start when the DB is empty. That uses the existing snapshot import and needs no new code path. |
|
||
| 3.2 | Pick a host | Any single small container host with a persistent volume works (Fly.io, Railway, a small VPS with Caddy for TLS). Keep SQLite: the demo is read-mostly with one writer. |
|
||
| 3.3 | Pass-4 reviews | Pre-generate them into the snapshot with a local Ollama model (phi4 scored 8/8 on the labeled set). The public site then needs no LLM key and costs nothing per visitor. |
|
||
| 3.4 | Landing page | `home.html` currently shows counts. Add a 3-sentence pitch and a "top surprising combos" list (high composite score, unusual pairings) so first-time visitors see the interesting output without digging. |
|
||
|
||
## Phase 4 — Optional, only if needed
|
||
|
||
Skipped until something forces them:
|
||
- **Postgres**: not needed for a read-mostly demo. Revisit only if you need multiple writers or multiple web workers.
|
||
- **Numpy-vectorized optimizer**: see `LOGIC DOCS/003`. Only needed when a 4th dimension is added or runs get slow; GPU is ruled out below the stated threshold.
|
||
- **Anthropic provider**: one file in the pattern of `llm/providers/gemini.py`, plus a branch in `llm/registry.py`. Add it if you want Claude reviews.
|
||
- **Pass-4 rationale**: show the estimator's chosen mass allocation and free variables in the review prompt (see the `ponytail:` note in `llm/prompts.py`). Only needed if reviews misjudge combos because they can't see this.
|
||
- **Per-key overrun tolerance** (`constraint_resolver.py:58`): only if mass and footprint turn out to need different slack.
|
||
- **More seed domains or dimensions** beyond transport: this would show off the generic formula estimator, but it's new content rather than polish.
|
||
|
||
---
|
||
|
||
## Suggested order
|
||
|
||
1.1 → 1.5 → 1.2 → 1.3 → 1.4 → 1.6 → 1.7 → 1.8 → 2.3 → 2.1 → 2.4 → 2.5 → 2.6 → 3.1 → 3.3 → 2.2 (screenshots need the final UI) → 3.4 → 3.2.
|