Files
physicalCombinatorics/IMPLEMENTATION_PLAN.md
asimonson1125 af401d6bc2 dev server uses admin login too: localhost shows the public view
Drop open_access; run() prints a one-off PHYSCOM_ADMIN_TOKEN when none is set.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-25 17:27:55 -05:00

8.6 KiB
Raw Blame History

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.

Progress (2026-09-25)

Item Status
1.1 gunicorn, debug off Done. Dev server debug only with FLASK_DEBUG=1.
1.2 read-only public mode Done. Deviation: an unset token means nobody can write under gunicorn, instead of "localhost can write", because behind a reverse proxy every request looks like localhost. The dev server uses the same login; without a token it prints a one-off one.
1.3 cookie hardening Done. Secure is opt-in via PHYSCOM_SECURE_COOKIES=1 so plain-HTTP local Docker can still log in.
1.4 explore Done. Verified it never writes; it costs about 45 ms per call (measured over 168 combos). Non-finite inputs are now rejected. No app-level rate limit: add one at the proxy if needed.
1.5 secret key Done differently: instead of refusing to start, an unset key is generated once and saved next to the DB.
1.6 container Done: non-root, healthcheck. Base image not digest-pinned (no Docker available here to resolve one). Container build is untested, since Docker isn't installed on this machine.
1.7 untrack local config Done. Checked the history: no secrets. The repo was already public.
1.8 tests Done: tests/test_web_access.py.
2.1 LICENSE Open. Your decision (and your employer's).
2.2 README Done, apart from screenshots, which need a browser.
2.3 CI Done: .github/workflows/test.yml (Gitea Actions reads it). Unverified until a runner picks it up.
2.4 metadata Done. license is left unset until 2.1.
2.5 compose parity Done: Ollama vars, admin token, Postgres placeholder removed.
2.6 route smoke tests Done (in 1.8's file).
3.1 demo data Done differently: physcom demo --if-empty builds it on first start (about 20 s) instead of committing a snapshot that goes stale whenever the physics changes.
3.2 host Open. Your call: the README "Deploying publicly" section covers any host.
3.3 pass-4 reviews Open. Ollama wasn't running here. Run pass 4 locally, then snapshot export → import.
3.4 landing page Done: "Top Concepts" table, and the Run Pipeline button is hidden from visitors.