Add Flask web UI, Docker Compose, core engine + tests
- physcom core: CLI, 5-pass pipeline, SQLite repo, 37 tests - physcom_web: Flask app with HTMX for entity/domain/pipeline/results CRUD - Docker Compose: web + cli services sharing a named volume for the DB - Clean up local settings to use wildcard permissions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
0
src/physcom_web/routes/__init__.py
Normal file
0
src/physcom_web/routes/__init__.py
Normal file
16
src/physcom_web/routes/domains.py
Normal file
16
src/physcom_web/routes/domains.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""Domain listing routes."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
from physcom_web.app import get_repo
|
||||
|
||||
bp = Blueprint("domains", __name__, url_prefix="/domains")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def domain_list():
|
||||
repo = get_repo()
|
||||
domains = repo.list_domains()
|
||||
return render_template("domains/list.html", domains=domains)
|
||||
128
src/physcom_web/routes/entities.py
Normal file
128
src/physcom_web/routes/entities.py
Normal file
@@ -0,0 +1,128 @@
|
||||
"""Entity + dependency CRUD routes."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
|
||||
from physcom.models.entity import Dependency, Entity
|
||||
from physcom_web.app import get_repo
|
||||
|
||||
bp = Blueprint("entities", __name__, url_prefix="/entities")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def entity_list():
|
||||
repo = get_repo()
|
||||
entities = repo.list_entities()
|
||||
# Group by dimension
|
||||
grouped: dict[str, list[Entity]] = {}
|
||||
for e in entities:
|
||||
grouped.setdefault(e.dimension, []).append(e)
|
||||
return render_template("entities/list.html", grouped=grouped)
|
||||
|
||||
|
||||
@bp.route("/new", methods=["GET", "POST"])
|
||||
def entity_new():
|
||||
repo = get_repo()
|
||||
if request.method == "POST":
|
||||
dimension = request.form["dimension"].strip()
|
||||
name = request.form["name"].strip()
|
||||
description = request.form.get("description", "").strip()
|
||||
if not dimension or not name:
|
||||
flash("Dimension and name are required.", "error")
|
||||
return render_template("entities/form.html", entity=None,
|
||||
dimensions=repo.list_dimensions())
|
||||
entity = Entity(name=name, dimension=dimension, description=description)
|
||||
repo.add_entity(entity)
|
||||
flash(f"Entity '{name}' added to '{dimension}'.", "success")
|
||||
return redirect(url_for("entities.entity_detail", entity_id=entity.id))
|
||||
return render_template("entities/form.html", entity=None,
|
||||
dimensions=repo.list_dimensions())
|
||||
|
||||
|
||||
@bp.route("/<int:entity_id>")
|
||||
def entity_detail(entity_id: int):
|
||||
repo = get_repo()
|
||||
entity = repo.get_entity(entity_id)
|
||||
if not entity:
|
||||
flash("Entity not found.", "error")
|
||||
return redirect(url_for("entities.entity_list"))
|
||||
return render_template("entities/detail.html", entity=entity)
|
||||
|
||||
|
||||
@bp.route("/<int:entity_id>/edit", methods=["GET", "POST"])
|
||||
def entity_edit(entity_id: int):
|
||||
repo = get_repo()
|
||||
entity = repo.get_entity(entity_id)
|
||||
if not entity:
|
||||
flash("Entity not found.", "error")
|
||||
return redirect(url_for("entities.entity_list"))
|
||||
if request.method == "POST":
|
||||
name = request.form["name"].strip()
|
||||
description = request.form.get("description", "").strip()
|
||||
if not name:
|
||||
flash("Name is required.", "error")
|
||||
return render_template("entities/form.html", entity=entity,
|
||||
dimensions=repo.list_dimensions())
|
||||
repo.update_entity(entity_id, name, description)
|
||||
flash(f"Entity '{name}' updated.", "success")
|
||||
return redirect(url_for("entities.entity_detail", entity_id=entity_id))
|
||||
return render_template("entities/form.html", entity=entity,
|
||||
dimensions=repo.list_dimensions())
|
||||
|
||||
|
||||
@bp.route("/<int:entity_id>/delete", methods=["POST"])
|
||||
def entity_delete(entity_id: int):
|
||||
repo = get_repo()
|
||||
entity = repo.get_entity(entity_id)
|
||||
if entity:
|
||||
repo.delete_entity(entity_id)
|
||||
flash(f"Entity '{entity.name}' deleted.", "success")
|
||||
return redirect(url_for("entities.entity_list"))
|
||||
|
||||
|
||||
# ── Dependency CRUD (HTMX partials) ─────────────────────────
|
||||
|
||||
|
||||
@bp.route("/<int:entity_id>/deps/add", methods=["POST"])
|
||||
def dep_add(entity_id: int):
|
||||
repo = get_repo()
|
||||
dep = Dependency(
|
||||
category=request.form["category"].strip(),
|
||||
key=request.form["key"].strip(),
|
||||
value=request.form["value"].strip(),
|
||||
unit=request.form.get("unit", "").strip() or None,
|
||||
constraint_type=request.form.get("constraint_type", "requires").strip(),
|
||||
)
|
||||
if not dep.category or not dep.key or not dep.value:
|
||||
flash("Category, key, and value are required.", "error")
|
||||
else:
|
||||
repo.add_dependency(entity_id, dep)
|
||||
flash("Dependency added.", "success")
|
||||
entity = repo.get_entity(entity_id)
|
||||
return render_template("entities/_dep_table.html", entity=entity)
|
||||
|
||||
|
||||
@bp.route("/<int:entity_id>/deps/<int:dep_id>/edit", methods=["POST"])
|
||||
def dep_edit(entity_id: int, dep_id: int):
|
||||
repo = get_repo()
|
||||
dep = Dependency(
|
||||
category=request.form["category"].strip(),
|
||||
key=request.form["key"].strip(),
|
||||
value=request.form["value"].strip(),
|
||||
unit=request.form.get("unit", "").strip() or None,
|
||||
constraint_type=request.form.get("constraint_type", "requires").strip(),
|
||||
)
|
||||
repo.update_dependency(dep_id, dep)
|
||||
flash("Dependency updated.", "success")
|
||||
entity = repo.get_entity(entity_id)
|
||||
return render_template("entities/_dep_table.html", entity=entity)
|
||||
|
||||
|
||||
@bp.route("/<int:entity_id>/deps/<int:dep_id>/delete", methods=["POST"])
|
||||
def dep_delete(entity_id: int, dep_id: int):
|
||||
repo = get_repo()
|
||||
repo.delete_dependency(dep_id)
|
||||
flash("Dependency deleted.", "success")
|
||||
entity = repo.get_entity(entity_id)
|
||||
return render_template("entities/_dep_table.html", entity=entity)
|
||||
56
src/physcom_web/routes/pipeline.py
Normal file
56
src/physcom_web/routes/pipeline.py
Normal file
@@ -0,0 +1,56 @@
|
||||
"""Pipeline run routes."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
|
||||
from physcom_web.app import get_repo
|
||||
|
||||
bp = Blueprint("pipeline", __name__, url_prefix="/pipeline")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def pipeline_form():
|
||||
repo = get_repo()
|
||||
domains = repo.list_domains()
|
||||
dimensions = repo.list_dimensions()
|
||||
return render_template("pipeline/run.html", domains=domains, dimensions=dimensions)
|
||||
|
||||
|
||||
@bp.route("/run", methods=["POST"])
|
||||
def pipeline_run():
|
||||
repo = get_repo()
|
||||
|
||||
domain_name = request.form["domain"]
|
||||
domain = repo.get_domain(domain_name)
|
||||
if not domain:
|
||||
flash(f"Domain '{domain_name}' not found.", "error")
|
||||
return redirect(url_for("pipeline.pipeline_form"))
|
||||
|
||||
passes = [int(p) for p in request.form.getlist("passes")]
|
||||
if not passes:
|
||||
passes = [1, 2, 3]
|
||||
|
||||
threshold = float(request.form.get("threshold", 0.1))
|
||||
dim_list = request.form.getlist("dimensions")
|
||||
if not dim_list:
|
||||
flash("Select at least one dimension.", "error")
|
||||
return redirect(url_for("pipeline.pipeline_form"))
|
||||
|
||||
from physcom.engine.constraint_resolver import ConstraintResolver
|
||||
from physcom.engine.scorer import Scorer
|
||||
from physcom.engine.pipeline import Pipeline
|
||||
|
||||
resolver = ConstraintResolver()
|
||||
scorer = Scorer(domain)
|
||||
pipeline = Pipeline(repo, resolver, scorer, llm=None)
|
||||
|
||||
result = pipeline.run(domain, dim_list, score_threshold=threshold, passes=passes)
|
||||
|
||||
flash(
|
||||
f"Pipeline complete: {result.total_generated} combos generated, "
|
||||
f"{result.pass1_valid} valid, {result.pass1_blocked} blocked, "
|
||||
f"{result.pass3_above_threshold} above threshold.",
|
||||
"success",
|
||||
)
|
||||
return redirect(url_for("results.results_domain", domain_name=domain_name))
|
||||
95
src/physcom_web/routes/results.py
Normal file
95
src/physcom_web/routes/results.py
Normal file
@@ -0,0 +1,95 @@
|
||||
"""Results browse + review routes."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
||||
|
||||
from physcom_web.app import get_repo
|
||||
|
||||
bp = Blueprint("results", __name__, url_prefix="/results")
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def results_index():
|
||||
repo = get_repo()
|
||||
domains = repo.list_domains()
|
||||
return render_template("results/list.html", domains=domains, results=None, domain=None)
|
||||
|
||||
|
||||
@bp.route("/<domain_name>")
|
||||
def results_domain(domain_name: str):
|
||||
repo = get_repo()
|
||||
domain = repo.get_domain(domain_name)
|
||||
if not domain:
|
||||
flash(f"Domain '{domain_name}' not found.", "error")
|
||||
return redirect(url_for("results.results_index"))
|
||||
|
||||
status_filter = request.args.get("status")
|
||||
results = repo.get_all_results(domain_name, status=status_filter)
|
||||
statuses = repo.count_combinations_by_status()
|
||||
|
||||
return render_template(
|
||||
"results/list.html",
|
||||
domains=repo.list_domains(),
|
||||
domain=domain,
|
||||
results=results,
|
||||
status_filter=status_filter,
|
||||
statuses=statuses,
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/<domain_name>/<int:combo_id>")
|
||||
def result_detail(domain_name: str, combo_id: int):
|
||||
repo = get_repo()
|
||||
domain = repo.get_domain(domain_name)
|
||||
if not domain:
|
||||
flash(f"Domain '{domain_name}' not found.", "error")
|
||||
return redirect(url_for("results.results_index"))
|
||||
|
||||
combo = repo.get_combination(combo_id)
|
||||
if not combo:
|
||||
flash("Combination not found.", "error")
|
||||
return redirect(url_for("results.results_domain", domain_name=domain_name))
|
||||
|
||||
result = repo.get_result(combo_id, domain.id)
|
||||
scores = repo.get_combination_scores(combo_id, domain.id)
|
||||
|
||||
return render_template(
|
||||
"results/detail.html",
|
||||
domain=domain,
|
||||
combo=combo,
|
||||
result=result,
|
||||
scores=scores,
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/<domain_name>/<int:combo_id>/review", methods=["POST"])
|
||||
def submit_review(domain_name: str, combo_id: int):
|
||||
repo = get_repo()
|
||||
domain = repo.get_domain(domain_name)
|
||||
if not domain:
|
||||
flash(f"Domain '{domain_name}' not found.", "error")
|
||||
return redirect(url_for("results.results_index"))
|
||||
|
||||
novelty_flag = request.form.get("novelty_flag", "").strip() or None
|
||||
human_notes = request.form.get("human_notes", "").strip() or None
|
||||
|
||||
# Get existing result to preserve composite_score
|
||||
existing = repo.get_result(combo_id, domain.id)
|
||||
composite_score = existing["composite_score"] if existing else 0.0
|
||||
|
||||
repo.save_result(
|
||||
combo_id, domain.id, composite_score,
|
||||
pass_reached=5,
|
||||
novelty_flag=novelty_flag,
|
||||
human_notes=human_notes,
|
||||
)
|
||||
repo.update_combination_status(combo_id, "reviewed")
|
||||
|
||||
# Return HTMX partial or redirect
|
||||
if request.headers.get("HX-Request"):
|
||||
return render_template("results/_review_done.html",
|
||||
novelty_flag=novelty_flag, human_notes=human_notes)
|
||||
flash("Review saved.", "success")
|
||||
return redirect(url_for("results.result_detail",
|
||||
domain_name=domain_name, combo_id=combo_id))
|
||||
Reference in New Issue
Block a user