Wire the app like the boilerplate: door, queue, schedules, eight tabs

app/main.py assembles it in the boilerplate's order, auth.connect first,
then the queue with the scheduler and the pages. TABS is Roles,
Applications, Agents, Companies, Jobs, Schedules, Messages and Account:
the alpha page's three views become templates on the boilerplate's
base.html, driven by static/roles.js (the old app.js) through api() and
toasts.js, over the unchanged JSON routes. Companies lists every board with
its open roles and the affinity control. A 422 is one sentence, so a toast
never reads [object Object].

Config takes the boilerplate's shape: APP_CONFIG or config.yaml, a missing
file is the defaults, an unknown key is an error. roles.yaml is gone;
config.yaml is the committed default and carries the starter agents.

pull is now a job that asks for the pull cascade, because a schedule
enqueues a job kind; its default schedule, every 6h, is declared beside it
in app/jobs/cascade.py. pull_batch's targets are keyword-only so the Jobs
tab offers no batch button. `app worker` is the boilerplate's; `app job`
still drains a queue of its own and fires no schedules.

test_coupling holds pipeline, auth and desk apart (desk may import
pipeline) and plugins to desk; test_architecture keeps app's layers, now
with main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-23 12:48:12 +02:00
1 parent 24508dd6fc
commit 59a301c351
42 files changed
+2407 -998

No files matched your search

+99 -19
View File
@@ -1,17 +1,24 @@
"""The one page. Everything under `/api` and `/_jobs` is JSON; this route
hands the browser an empty shell — the filter bar, the section headers, the
`<select>` options a plugin's vocabulary decides — and `static/app.js` fills
it and drives every action from there.
"""The tabs: eight pages, declared once.
`FUNCTIONS` is `plugins.ats`'s, not `app`'s: the nine job functions are
the classifier's vocabulary, and this reaches `plugins/` the same way
`app.cli` already does, since a plugin is app-agnostic and never reaches
back into `app`.
`TABS` is the whole navigation. `base.html` renders it, every page marks
itself active by its own `path`, and adding a tab is one entry here plus one
template.
Every page is a shell. Roles, Applications, Agents and Companies are filled
and driven by `static/roles.js` from the JSON routes in `web/api.py`; Jobs,
Schedules and Account are shells around the modules' own elements. What the
server renders is only what a select needs to offer, so the options cannot
drift from what the store accepts.
`FUNCTIONS` is `plugins.ats`'s, not `app`'s: the nine job functions are the
classifier's vocabulary, and this reaches `plugins/` the same way `app.cli`
does, since a plugin is app-agnostic and never reaches back into `app`.
"""
from __future__ import annotations
import sys
from dataclasses import dataclass
from pathlib import Path
from fastapi import APIRouter, Request
@@ -26,22 +33,95 @@ if str(_ROOT) not in sys.path:
from plugins.ats import FUNCTIONS # noqa: E402
WEB = Path(__file__).resolve().parent
templates = Jinja2Templates(directory=WEB / "templates")
TEMPLATE_DIR = Path(__file__).resolve().parent.parent / "templates"
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
router = APIRouter(tags=["pages"])
#: `value, label` for each function select option. `FUNCTIONS` is already the
#: value a role's `function` column holds; only the label is dressed up.
@dataclass(frozen=True, slots=True)
class Tab:
path: str
label: str
template: str
#: The navigation, in order. One list; `base.html` is its only reader.
TABS: tuple[Tab, ...] = (
Tab("/", "Roles", "roles.html"),
Tab("/applications", "Applications", "applications.html"),
Tab("/agents", "Agents", "agents.html"),
Tab("/companies", "Companies", "companies.html"),
Tab("/jobs", "Jobs", "jobs.html"),
Tab("/schedules", "Schedules", "schedules.html"),
Tab("/messages", "Messages", "messages.html"),
Tab("/account", "Account", "account.html"),
)
#: `value, label` for each select option. `FUNCTIONS` is already the value a
#: role's `function` column holds; only the label is dressed up.
FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS]
REMOTE_OPTIONS = [(r, r.capitalize()) for r in REMOTE if r]
STATUS_OPTIONS = [(s, s.capitalize()) for s in STATUSES]
def asset(path: str) -> str:
"""A static URL stamped with the file's modification time, so a changed
file is a different URL and a cached stale copy is never the answer."""
name = path.lstrip("/")
try:
stamp = int((STATIC_DIR / name).stat().st_mtime)
except OSError:
return f"/static/{name}"
return f"/static/{name}?v={stamp}"
templates = Jinja2Templates(directory=str(TEMPLATE_DIR))
templates.env.globals["TABS"] = TABS
templates.env.globals["asset"] = asset
#: Out of the OpenAPI schema: these are pages.
router = APIRouter(include_in_schema=False)
def page(request: Request, name: str, **context: object) -> HTMLResponse:
return templates.TemplateResponse(request, name, context)
@router.get("/", response_class=HTMLResponse)
def index(request: Request) -> HTMLResponse:
return templates.TemplateResponse(request, "index.html", {
"functions": FUNCTION_OPTIONS,
"remote_options": REMOTE_OPTIONS,
"status_options": STATUS_OPTIONS,
})
def roles(request: Request) -> HTMLResponse:
return page(request, "roles.html", functions=FUNCTION_OPTIONS,
remote_options=REMOTE_OPTIONS)
@router.get("/applications", response_class=HTMLResponse)
def applications(request: Request) -> HTMLResponse:
return page(request, "applications.html", status_options=STATUS_OPTIONS)
@router.get("/agents", response_class=HTMLResponse)
def agents(request: Request) -> HTMLResponse:
return page(request, "agents.html")
@router.get("/companies", response_class=HTMLResponse)
def companies(request: Request) -> HTMLResponse:
return page(request, "companies.html")
@router.get("/jobs", response_class=HTMLResponse)
def jobs(request: Request) -> HTMLResponse:
return page(request, "jobs.html")
@router.get("/schedules", response_class=HTMLResponse)
def schedules(request: Request) -> HTMLResponse:
return page(request, "schedules.html")
@router.get("/messages", response_class=HTMLResponse)
def messages(request: Request) -> HTMLResponse:
return page(request, "messages.html")
@router.get("/account", response_class=HTMLResponse)
def account(request: Request) -> HTMLResponse:
return page(request, "account.html")