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:
1 parent
24508dd6fc
commit
59a301c351
42 files changed
+2407
-998
No files matched your search
+11
-6
@@ -1,14 +1,19 @@
|
||||
"""roledesk: a job-search engine on the `desk` plugin contract and the `pipeline` queue.
|
||||
|
||||
Layers, bottom to top, each importing only from those below it (see
|
||||
uv run app serve
|
||||
|
||||
The package is `app` because the boilerplate's deploy kit assumes it. Layers,
|
||||
bottom to top, each importing only from those below it (see
|
||||
`tests/test_architecture.py`):
|
||||
|
||||
models the shapes handed round, and the key functions for clustering
|
||||
config `roles.yaml`, validated
|
||||
config `config.yaml`, validated
|
||||
storage `Store`: every SQL statement against `roledesk.db`
|
||||
jobs the work this app queues
|
||||
web the FastAPI app
|
||||
cli the entry point
|
||||
jobs the work this app queues, and its default schedule
|
||||
web the tabs and the JSON routes behind them
|
||||
main `create_app()`: the door, the queue, the pages, in that order
|
||||
cli `app serve`, `app job`, `app worker`, `app companies`, `app db`
|
||||
|
||||
`desk` and `pipeline` come from the news repo and are imported, never edited.
|
||||
`pipeline/`, `auth/` and `desk/` are downstream copies (of the boilerplate and
|
||||
of news) and import nothing from here; `tests/test_coupling.py` holds that.
|
||||
"""
|
||||
@@ -0,0 +1,12 @@
|
||||
"""`python -m app` is `app`.
|
||||
|
||||
For a checkout whose console script is not on the PATH — a worktree the release
|
||||
scripts made, a container shell, a colleague who has not run `uv sync`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
+105
-26
@@ -1,13 +1,28 @@
|
||||
"""`app serve | job pull|extract|embed|score | companies seed|add|check | db init`."""
|
||||
"""The command line.
|
||||
|
||||
app serve [--host H] [--port P] [--reload]
|
||||
app job pull|extract|embed|score [--payload JSON]
|
||||
app worker [--workers http=8,cpu=1] [--until-idle]
|
||||
app companies seed|add|check
|
||||
app db init
|
||||
|
||||
`app job` queues the work on a queue of its own and drains it here, so a
|
||||
cascade such as `pull` runs every stage it starts before the command returns,
|
||||
and prints one line per stage. `app worker` is the boilerplate's: the same
|
||||
queue with no web app, and the schedules fired from it.
|
||||
|
||||
`python -m app` is the same thing, for a checkout with no console script.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from app import config as config_mod
|
||||
|
||||
@@ -26,18 +41,27 @@ if str(_ROOT) not in sys.path:
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(prog="app",
|
||||
description="A job-search engine on desk.")
|
||||
parser.add_argument("-c", "--config", default=None, help="path to roles.yaml")
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="app", description="roledesk: a job-search engine on desk and the pipeline queue.")
|
||||
parser.add_argument("-c", "--config", default=None,
|
||||
help="the YAML file to read (default: $APP_CONFIG, then config.yaml)")
|
||||
parser.add_argument("-v", "--verbose", action="store_true")
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
serve = sub.add_parser("serve", help="run the web app")
|
||||
serve.add_argument("--host", default="127.0.0.1")
|
||||
serve.add_argument("--port", type=int, default=8790)
|
||||
serve.add_argument("--host", default="", help="override config server.host")
|
||||
serve.add_argument("--port", type=int, default=0, help="override config server.port")
|
||||
serve.add_argument("--reload", action="store_true", help="restart on a source change")
|
||||
|
||||
job = sub.add_parser("job", help="queue a job or task and drain the queue once")
|
||||
job.add_argument("kind", choices=["pull", "extract", "embed", "score"])
|
||||
job = sub.add_parser("job", help="queue a job, task or cascade and drain the queue")
|
||||
job.add_argument("kind", help="pull, extract, embed, score, or any registered job")
|
||||
job.add_argument("--payload", default="{}",
|
||||
help="JSON spread over a job handler's keyword arguments")
|
||||
|
||||
worker = sub.add_parser("worker", help="drain the job table with no web app")
|
||||
worker.add_argument("--workers", default="", help="resource=count,... e.g. cpu=2")
|
||||
worker.add_argument("--until-idle", action="store_true",
|
||||
help="run what is queued, then exit")
|
||||
|
||||
companies = sub.add_parser("companies", help="the target company list")
|
||||
companies_sub = companies.add_subparsers(dest="action", required=True)
|
||||
@@ -60,52 +84,89 @@ def main(argv: list[str] | None = None) -> int:
|
||||
format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
try:
|
||||
if args.command == "serve":
|
||||
from app.web import serve
|
||||
config_mod.load(args.config) # a config error here, not in uvicorn
|
||||
return serve(args.host, args.port, args.config)
|
||||
return serve(args)
|
||||
if args.command == "job":
|
||||
return run_job(args)
|
||||
if args.command == "worker":
|
||||
return run_worker(args)
|
||||
if args.command == "companies":
|
||||
return run_companies(args)
|
||||
return init_db(args)
|
||||
except FileNotFoundError as exc:
|
||||
except (FileNotFoundError, config_mod.ConfigError) as exc:
|
||||
print(exc, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
def serve(args: argparse.Namespace) -> int:
|
||||
import uvicorn
|
||||
|
||||
config = config_mod.load(args.config) # a config error here, not in uvicorn
|
||||
host = args.host or config.server.host
|
||||
port = args.port or config.server.port
|
||||
level = str(config.log_level).lower()
|
||||
if args.reload:
|
||||
# The reloader builds the app in a fresh process from an import
|
||||
# string, and that process reads the config from $APP_CONFIG.
|
||||
if args.config:
|
||||
os.environ["APP_CONFIG"] = str(args.config)
|
||||
uvicorn.run("app.main:app", host=host, port=port, reload=True, log_level=level)
|
||||
return 0
|
||||
from app.main import create_app
|
||||
|
||||
uvicorn.run(create_app(config), host=host, port=port, log_level=level)
|
||||
return 0
|
||||
|
||||
|
||||
def run_job(args: argparse.Namespace) -> int:
|
||||
"""Queue `kind` — a job, or a task from `pipeline.TASKS` such as `pull` —
|
||||
then run everything queued until the queue is idle, and print how it
|
||||
ended: one line per task, from each task's final job. `pull` is a
|
||||
cascade, so it prints a line for every stage it went through."""
|
||||
from pipeline import FINAL, JobQueue, Jobs, TASKS
|
||||
"""Queue `kind` (a cascade such as `pull`, a task from `pipeline.TASKS`,
|
||||
or a job), run everything queued until the queue is idle, and print how
|
||||
it ended: one line per task, from each task's final job. `pull` is a
|
||||
cascade, so it prints a line for every stage it went through.
|
||||
|
||||
The queue fires no schedules: the command asked for one piece of work."""
|
||||
from app import jobs
|
||||
from app.storage import Store
|
||||
from pipeline import FINAL, JOBS, TASKS, JobQueue, Jobs
|
||||
|
||||
cascade = jobs.cascade
|
||||
|
||||
try:
|
||||
payload: dict[str, Any] = json.loads(args.payload or "{}")
|
||||
except json.JSONDecodeError as exc:
|
||||
print(f"--payload is not JSON: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
chained = args.kind in cascade.CASCADES
|
||||
if not chained and args.kind not in TASKS and args.kind not in JOBS:
|
||||
known = sorted(set(JOBS) | set(TASKS))
|
||||
print(f"no job kind {args.kind!r}. Have: {', '.join(known)}", file=sys.stderr)
|
||||
return 2
|
||||
config = config_mod.load(args.config)
|
||||
store = Store(config.database)
|
||||
queue = JobQueue(Jobs(config.database), config, store,
|
||||
queue = JobQueue(Jobs(str(config.database)), config, store,
|
||||
workers=config.workers.model_dump(),
|
||||
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=config.path)
|
||||
if args.kind in TASKS:
|
||||
task_id = queue.start_task(TASKS[args.kind]())
|
||||
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=str(config.path or ""),
|
||||
tz=config.timezone, schedules=False)
|
||||
if chained or args.kind not in JOBS:
|
||||
task_id = queue.start_task(cascade.chain(args.kind) if chained
|
||||
else TASKS[args.kind]())
|
||||
queue.drain()
|
||||
started = queue.jobs.of_task(task_id)
|
||||
if not started:
|
||||
print(json.dumps({"task": args.kind, "result": "nothing to do"}))
|
||||
return 0
|
||||
cascade = queue.jobs.of_cascade(started[0].cascade_id)
|
||||
finals = [j for j in cascade if j.kind == FINAL]
|
||||
whole = queue.jobs.of_cascade(started[0].cascade_id)
|
||||
finals = [j for j in whole if j.kind == FINAL]
|
||||
for final in finals:
|
||||
# A task's own jobs say what the work did; the final job only
|
||||
# tallies how they ended. Up to five, so a pull of twenty board
|
||||
# batches stays one readable line.
|
||||
work = [j.result for j in cascade if j.task_id == final.task_id
|
||||
work = [j.result for j in whole if j.task_id == final.task_id
|
||||
and j.kind != FINAL][:5]
|
||||
print(json.dumps({"id": final.id, "state": final.state,
|
||||
"result": final.result, "work": work,
|
||||
"error": final.error}))
|
||||
return 0 if all(f.state == "done" for f in finals) else 1
|
||||
queued = queue.enqueue(args.kind)
|
||||
queued = queue.enqueue(args.kind, payload)
|
||||
queue.drain()
|
||||
if queued is not None:
|
||||
done = queue.jobs.get(queued.id)
|
||||
@@ -116,6 +177,24 @@ def run_job(args: argparse.Namespace) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def run_worker(args: argparse.Namespace) -> int:
|
||||
"""`python -m pipeline.worker` with this app's settings filled in: the
|
||||
bootstrap, the pools from `workers:`, and the timezone, without which a
|
||||
`daily at 06:00` schedule would run at 06:00 on the machine's clock."""
|
||||
from app.jobs import BOOTSTRAP
|
||||
from pipeline.worker import main as worker_main
|
||||
|
||||
config = config_mod.load(args.config)
|
||||
argv = ["--db", str(config.database), "--bootstrap", BOOTSTRAP,
|
||||
"--bootstrap-arg", str(args.config or config.path or ""),
|
||||
"--timezone", str(config.timezone)]
|
||||
argv += ["--workers", args.workers or
|
||||
",".join(f"{name}={n}" for name, n in config.workers.model_dump().items())]
|
||||
if args.until_idle:
|
||||
argv.append("--until-idle")
|
||||
return worker_main(argv)
|
||||
|
||||
|
||||
def run_companies(args: argparse.Namespace) -> int:
|
||||
from app.storage import Store
|
||||
|
||||
|
||||
+75
-24
@@ -1,7 +1,16 @@
|
||||
"""Config loading: one YAML file, `roles.yaml`, validated into a model.
|
||||
"""Config loading: one YAML file, validated into a model.
|
||||
|
||||
A typo in a key is an error naming the key, because `Section` forbids extras.
|
||||
`sources` stays a dict: one block per plugin, whose keys only the plugin knows.
|
||||
The boilerplate's shape with roledesk's keys. A typo in a key is an error
|
||||
naming the key, because every section forbids extras: a setting you believe
|
||||
you have changed and have not is the expensive kind of typo. `sources` stays a
|
||||
dict: one block per plugin, whose keys only the plugin knows.
|
||||
|
||||
The path comes from `app --config`, else `APP_CONFIG`, else `config.yaml`
|
||||
beside the checkout. The Dockerfile sets `APP_CONFIG=/data/config.yaml`.
|
||||
|
||||
**A missing file is not an error.** Every field has a default that runs, so
|
||||
`uv run app serve` works on a fresh clone. The committed `config.yaml` adds
|
||||
the starter agents; `config.example.yaml` documents every key.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -11,12 +20,23 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
from pydantic import Field, ValidationError
|
||||
from pydantic import Field, ValidationError, model_validator
|
||||
|
||||
from desk.config import AgentConfig, ModelTaskConfig, Section, WorkersConfig
|
||||
from app.models import Gate, Weights
|
||||
from auth import AuthConfig
|
||||
from desk.config import AgentConfig, ModelTaskConfig, Section, WorkersConfig
|
||||
|
||||
DEFAULT_PATH = Path(os.environ.get("ROLEDESK_CONFIG", "roles.yaml"))
|
||||
#: Where `load()` looks when nobody says. Read at import so a test can set the
|
||||
#: variable first, and `app --config` overrides it after.
|
||||
DEFAULT_PATH = Path(os.environ.get("APP_CONFIG", "config.yaml"))
|
||||
|
||||
|
||||
class ServerConfig(Section):
|
||||
"""Where uvicorn binds. Anything but a loopback address makes
|
||||
`auth.enabled: auto` lock the app."""
|
||||
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 8790
|
||||
|
||||
|
||||
class ExtractConfig(ModelTaskConfig):
|
||||
@@ -42,7 +62,7 @@ class EmbedConfig(Section):
|
||||
|
||||
|
||||
class AgentSeed(Section):
|
||||
"""A search agent as `roles.yaml` lists it. Imported into an empty
|
||||
"""A search agent as `config.yaml` lists it. Imported into an empty
|
||||
`agents` table once; after that the table is the answer."""
|
||||
|
||||
name: str
|
||||
@@ -55,9 +75,27 @@ class AgentSeed(Section):
|
||||
class Config(Section):
|
||||
"""The whole file."""
|
||||
|
||||
database: str = "roledesk.db"
|
||||
server: ServerConfig = Field(default_factory=ServerConfig)
|
||||
|
||||
#: One SQLite file for the lot: roles and companies, the jobs table, the
|
||||
#: notice log, the schedules, and auth's `auth_*` tables. One file is one
|
||||
#: thing to back up.
|
||||
database: Path = Path("roledesk.db")
|
||||
|
||||
#: What a clock on screen means, and what a `daily at 06:00` schedule is
|
||||
#: 06:00 in. `every 6h` is six elapsed hours in any zone.
|
||||
timezone: str = "Europe/Berlin"
|
||||
|
||||
log_level: str = "INFO"
|
||||
|
||||
#: The door, auth's own model. See auth/README.md.
|
||||
auth: AuthConfig = Field(default_factory=AuthConfig)
|
||||
|
||||
#: Directories searched for `Source` plugins. A plugin imports `desk` only.
|
||||
plugin_paths: list[str] = Field(default_factory=lambda: ["plugins"])
|
||||
#: Workers per resource class. `http` is wide because a fetch is mostly waiting.
|
||||
workers: WorkersConfig = Field(default_factory=WorkersConfig)
|
||||
#: Who answers when a job needs a model. See desk/tools/agent.py.
|
||||
agent: AgentConfig = Field(default_factory=AgentConfig)
|
||||
extract: ExtractConfig = Field(default_factory=ExtractConfig)
|
||||
embed: EmbedConfig = Field(default_factory=EmbedConfig)
|
||||
@@ -65,28 +103,41 @@ class Config(Section):
|
||||
agents: list[AgentSeed] = Field(default_factory=list)
|
||||
#: One block per plugin: `enabled`, and whatever that plugin reads.
|
||||
sources: dict[str, Any] = Field(default_factory=dict)
|
||||
#: Where this was loaded from. Never written back into the file.
|
||||
path: str = Field("", exclude=True)
|
||||
|
||||
#: Where this came from, or None for the defaults. Never written back.
|
||||
path: Path | None = Field(default=None, exclude=True)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def _credentials_live_in_the_database(self) -> Config:
|
||||
"""`desk.tools.agent` reads a stored token from the app's database."""
|
||||
self.agent.credentials_database = str(self.database)
|
||||
return self
|
||||
|
||||
|
||||
class ConfigError(FileNotFoundError):
|
||||
"""A config that exists but does not validate. A FileNotFoundError so the
|
||||
CLI reports both kinds of unusable config the same way: as a message."""
|
||||
class ConfigError(ValueError):
|
||||
"""A config file that exists but does not validate. The message names
|
||||
every bad key, for the CLI to print as it is."""
|
||||
|
||||
|
||||
def load(path: str | Path | None = None) -> Config:
|
||||
p = Path(path or DEFAULT_PATH).expanduser()
|
||||
if not p.exists():
|
||||
raise FileNotFoundError(
|
||||
f"No config at {p}. Copy config.example.yaml to {p} and edit it.")
|
||||
with p.open(encoding="utf-8") as fh:
|
||||
raw = yaml.safe_load(fh) or {}
|
||||
def load(path: str | os.PathLike[str] | None = None) -> Config:
|
||||
"""Read the YAML file into a `Config`, or return the defaults.
|
||||
|
||||
An empty file is the same as no file. A file that is not a mapping, or
|
||||
that does not validate, is a `ConfigError`.
|
||||
"""
|
||||
where = Path(path).expanduser() if path else DEFAULT_PATH
|
||||
if not where.exists():
|
||||
return Config()
|
||||
raw: Any = yaml.safe_load(where.read_text(encoding="utf-8"))
|
||||
if raw is None:
|
||||
return Config(path=where)
|
||||
if not isinstance(raw, dict):
|
||||
raise ConfigError(f"{where}: expected a mapping of settings, "
|
||||
f"got {type(raw).__name__}")
|
||||
try:
|
||||
config = Config(**raw, path=str(p))
|
||||
return Config(**raw, path=where)
|
||||
except ValidationError as exc:
|
||||
raise ConfigError(f"{p}:\n{_explain(exc)}") from None
|
||||
config.agent.credentials_database = config.database
|
||||
return config
|
||||
raise ConfigError(f"{where}:\n{_explain(exc)}") from None
|
||||
|
||||
|
||||
def _explain(exc: ValidationError) -> str:
|
||||
|
||||
+10
-6
@@ -1,15 +1,18 @@
|
||||
"""The work roledesk queues. Importing this package registers every job and
|
||||
every task in `pipeline.TASKS`.
|
||||
"""The work roledesk queues. Importing this package registers every job, every
|
||||
task in `pipeline.TASKS` and the default schedule in `pipeline.SCHEDULES`.
|
||||
|
||||
pull.py read every configured plugin and store the roles it yields
|
||||
extract.py title and description into the gate columns, on Haiku
|
||||
embed.py one vector per open role, for fit
|
||||
score.py every open role scored for every enabled search agent
|
||||
cascade.py pull → extract → embed → score, and what `TASKS` offers
|
||||
cascade.py pull → extract → embed → score, what `TASKS` offers, the
|
||||
`pull` job a schedule fires, and that schedule
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.jobs import cascade, embed, extract, pull, score
|
||||
from app.jobs.score import seed_agents
|
||||
|
||||
@@ -17,9 +20,10 @@ from app.jobs.score import seed_agents
|
||||
BOOTSTRAP = "app.jobs:bootstrap"
|
||||
|
||||
|
||||
def bootstrap(config_path: str = "") -> tuple[object, object]:
|
||||
"""roledesk's `(config, store)` from the config file alone, for a job run
|
||||
in its own process or by `python -m pipeline.worker`."""
|
||||
def bootstrap(config_path: str = "") -> tuple[Any, Any]:
|
||||
"""`(config, store)` from the config file alone, for a job run in its own
|
||||
process or by `python -m pipeline.worker`. Importing this module is what
|
||||
fills `JOBS`, which is why the worker is handed a name rather than a queue."""
|
||||
from app import config as config_mod
|
||||
from app.storage import Store
|
||||
|
||||
|
||||
+36
-5
@@ -15,6 +15,10 @@ too, since embedding does not read its columns and the order costs nothing.
|
||||
A batch that failed, or a stage somebody killed, does not stop the chain: the
|
||||
work comes round on the next pull, and a rescore of what did arrive is worth
|
||||
having either way.
|
||||
|
||||
`pull` is a job as well as a cascade, because a schedule enqueues a job kind
|
||||
and a cascade is started by one: the `pull` job's only work is to ask for the
|
||||
chain. Its default schedule, `every 6h`, is declared here beside it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -24,9 +28,9 @@ from dataclasses import replace
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
|
||||
from desk.tools import agent
|
||||
from pipeline import TASKS, Tally, Task
|
||||
from app.jobs import embed, extract, pull, score # noqa: F401 -- registers the jobs
|
||||
from desk.tools import agent
|
||||
from pipeline import NULL, TASKS, RunContext, Tally, Task, declare, job
|
||||
|
||||
STEP = "app.jobs.cascade:step"
|
||||
|
||||
@@ -98,8 +102,35 @@ def step(config: Any, store: Any, tally: Tally, payload: dict[str, Any], *,
|
||||
return out
|
||||
|
||||
|
||||
#: What `app job <name>` and the Jobs view offer. `pull` is the whole
|
||||
#: chain; the others are one stage each, on their own.
|
||||
TASKS["pull"] = partial(task, "pull", cascade="pull")
|
||||
def chain(name: str) -> Task:
|
||||
"""The first stage of cascade `name`, carrying `step`, so the rest follow."""
|
||||
return task(CASCADES[name][0], cascade=name)
|
||||
|
||||
|
||||
@job("pull", "Pulling every board", resource="http")
|
||||
def run_pull(config: Any, store: Any, *, context: RunContext = NULL) -> dict[str, Any]:
|
||||
"""Ask for the pull cascade once this job is done. Its own work is nil.
|
||||
|
||||
Under `NULL` there is no queue to take the chain, so this raises rather
|
||||
than report a pull that never happened; `app job pull` starts the chain
|
||||
on a queue of its own instead of calling this.
|
||||
"""
|
||||
if not context.task(chain("pull")):
|
||||
raise RuntimeError("no queue to start the pull cascade on")
|
||||
return {"started": " > ".join(CASCADES["pull"])}
|
||||
|
||||
|
||||
#: What `app job <name>` and the Jobs tab offer besides `pull`: one stage
|
||||
#: each, on its own. `pull` is not a task here, since it is a job: a name that
|
||||
#: is both would be two buttons on the Jobs tab.
|
||||
for _name in ("extract", "embed", "score"):
|
||||
TASKS[_name] = partial(task, _name)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- schedules
|
||||
|
||||
# The default, next to the job it fires. A starting point rather than a
|
||||
# setting: a cadence edited or switched off on the Schedules tab survives
|
||||
# every restart (see pipeline/schedule.py).
|
||||
declare("pull", "pull", "every 6h",
|
||||
label="Pull every board, then extract, embed and score")
|
||||
+8
-4
@@ -28,7 +28,7 @@ from app.storage import Store
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
#: As many boards in the air per job as there are `http` workers by default
|
||||
#: (see `roles.yaml`), so one pull keeps the pool busy without one job
|
||||
#: (see `config.yaml`), so one pull keeps the pool busy without one job
|
||||
#: holding all 190-odd boards' worth of retries against a single attempt.
|
||||
BATCH_SIZE = 10
|
||||
|
||||
@@ -52,10 +52,14 @@ def _boards(config: Config, store: Store) -> list[dict[str, Any]]:
|
||||
|
||||
|
||||
@job("pull_batch", "Reading boards", resource="http")
|
||||
def run_batch(config: Config, store: Store, targets: list[str], *,
|
||||
context: RunContext = NULL) -> dict[str, Any]:
|
||||
def run_batch(config: Config, store: Store, *, targets: list[str],
|
||||
context: RunContext = NULL) -> dict[str, Any]:
|
||||
"""Fetch this batch's boards and `upsert_role` every item they list.
|
||||
|
||||
`targets` is keyword-only without a default, which is what makes it a
|
||||
required payload key to the queue: the Jobs tab offers no button for a
|
||||
batch that could only fail without one.
|
||||
|
||||
Builds the `ats` plugin scoped to just these targets — `Source.targets()`
|
||||
reads `options[subscription_field]`, so handing it only this batch's
|
||||
entries is what keeps one job from re-fetching every other job's boards.
|
||||
@@ -105,6 +109,6 @@ def close_boards(config: Config, store: Store, tally: Tally, *,
|
||||
|
||||
def pull_task() -> Task:
|
||||
"""The pull on its own. `app.jobs.cascade` makes it the first stage
|
||||
of the chain that `TASKS["pull"]` starts."""
|
||||
of the chain the `pull` job starts."""
|
||||
return Task(kind="pull_batch", finder=_boards, name="pull",
|
||||
label="Reading every board", settle=SETTLE)
|
||||
+2
-2
@@ -197,7 +197,7 @@ def run_score(config: Config, store: Store, *,
|
||||
# ------------------------------------------------------------------ seeding
|
||||
|
||||
def seed_agents(config: Config, store: Store) -> list[str]:
|
||||
"""Import `roles.yaml`'s `agents:` into an empty table, once. The state
|
||||
"""Import `config.yaml`'s `agents:` into an empty table, once. The state
|
||||
marker is what makes it once: deleting every agent afterwards is a
|
||||
choice, and a restart must not undo it."""
|
||||
if store.state.get(SEEDED) or store.agents():
|
||||
@@ -213,5 +213,5 @@ def seed_agents(config: Config, store: Store) -> list[str]:
|
||||
added.append(seed.name)
|
||||
if added:
|
||||
store.state[SEEDED] = store.now()
|
||||
log.info("imported %d agents from %s", len(added), config.path or "roles.yaml")
|
||||
log.info("imported %d agents from %s", len(added), config.path or "the defaults")
|
||||
return added
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
"""The app, assembled.
|
||||
|
||||
uv run app serve
|
||||
uv run uvicorn app.main:app --reload
|
||||
|
||||
`create_app()` is the whole of the wiring, and the order in it is the point:
|
||||
config and store, the door, the queue, the pages. Everything before the queue
|
||||
is something the queue needs; everything after it is something that enqueues.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.exceptions import RequestValidationError
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
||||
|
||||
import auth
|
||||
from app import jobs
|
||||
from app.config import Config, load
|
||||
from app.storage import Store
|
||||
from app.web import STATIC_DIR, api_router, pages_router, templates
|
||||
from pipeline import Jobs
|
||||
from pipeline.web import connect
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
#: Prefixes whose errors are JSON rather than a page. A caller that asked for
|
||||
#: data gets `{"detail": ...}`; a browser that asked for a page gets one.
|
||||
API_PREFIXES = ("/api", "/ws", "/_jobs", "/_auth", "/static", "/health")
|
||||
|
||||
|
||||
def create_app(config: Config | None = None) -> FastAPI:
|
||||
"""Build the application. A test passes its own config; nobody else does."""
|
||||
config = config or load()
|
||||
logging.basicConfig(
|
||||
level=getattr(logging, str(config.log_level).upper(), logging.INFO),
|
||||
format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
|
||||
# `Store` first, so the file is at the current schema before the queue and
|
||||
# auth add their own tables to it.
|
||||
store = Store(config.database)
|
||||
jobs.seed_agents(config, store)
|
||||
|
||||
app = FastAPI(title="roledesk", docs_url="/api/docs",
|
||||
summary="ATS boards in, roles scored per search agent, "
|
||||
"applications tracked.")
|
||||
app.state.config = config
|
||||
app.state.store = store
|
||||
|
||||
# The door, first, because it is the door. The middleware covers every
|
||||
# route whenever it was added, `/ws/jobs` included; written first, nobody
|
||||
# has to work that out. `auto` locks unless the bind address is loopback.
|
||||
# Auth's tables are the `auth_*` ones in the same file.
|
||||
auth.connect(app, auth.AuthStore(config.database), config.auth,
|
||||
host=config.server.host, open=("/static/",),
|
||||
stylesheet="/static/app.css")
|
||||
|
||||
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
||||
|
||||
# The queue: routes, socket, `<desk-jobs>`, `<desk-schedules>`, and a
|
||||
# worker in the lifespan that also fires the schedules. `tz` is what a
|
||||
# `daily at 06:00` cadence is read in.
|
||||
connect(app, Jobs(str(config.database)), config, store,
|
||||
workers=config.workers.model_dump(),
|
||||
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=str(config.path or ""),
|
||||
tz=config.timezone)
|
||||
|
||||
app.include_router(api_router)
|
||||
app.include_router(pages_router)
|
||||
|
||||
@app.get("/health", include_in_schema=False)
|
||||
def health() -> dict[str, Any]:
|
||||
"""Open, session-free, and it reads the store: `docker compose up
|
||||
--wait` waits on this, so it has to prove the database answers."""
|
||||
return {"ok": True, "open_roles": sum(store.open_role_counts().values())}
|
||||
|
||||
@app.exception_handler(StarletteHTTPException)
|
||||
async def errors(request: Request, exc: StarletteHTTPException) -> Any:
|
||||
"""JSON for a caller, a page for a browser. One shape for every API
|
||||
error, `{"detail": "<one sentence>"}`, so `api()` in `static/app.js`
|
||||
turns any failure into one toast carrying the server's own wording."""
|
||||
headers = getattr(exc, "headers", None)
|
||||
wants_page = (request.method == "GET"
|
||||
and not request.url.path.startswith(API_PREFIXES))
|
||||
if not wants_page:
|
||||
return JSONResponse({"detail": exc.detail}, status_code=exc.status_code,
|
||||
headers=headers)
|
||||
return templates.TemplateResponse(
|
||||
request, "error.html",
|
||||
{"status": exc.status_code, "detail": exc.detail},
|
||||
status_code=exc.status_code, headers=headers)
|
||||
|
||||
@app.exception_handler(RequestValidationError)
|
||||
async def invalid(request: Request, exc: RequestValidationError) -> JSONResponse:
|
||||
"""FastAPI's 422 body is a list of objects, which a toast shows as
|
||||
`[object Object]`. The same errors as one sentence instead."""
|
||||
said = "; ".join(
|
||||
f"{'.'.join(str(p) for p in err['loc'] if p != 'body')}: {err['msg']}"
|
||||
for err in exc.errors())
|
||||
return JSONResponse({"detail": said or "The request was not valid."},
|
||||
status_code=422)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
"""`app.main:app` for uvicorn, built on first use rather than on import, so
|
||||
importing this module opens no database."""
|
||||
if name == "app":
|
||||
built = create_app()
|
||||
globals()["app"] = built
|
||||
return built
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
@@ -0,0 +1,381 @@
|
||||
/* The whole stylesheet: the boilerplate's, with roledesk's palette in the
|
||||
* custom properties (a quiet UI face and newsdesk's teal signal colour) and
|
||||
* roledesk's own tabs in the section at the bottom. No build step.
|
||||
*
|
||||
* The `--desk-jobs-*` block at the bottom is how `<desk-jobs>` is themed. The
|
||||
* element keeps to a shadow root and reads those properties, so an app skins
|
||||
* it without forking it -- which is the deal that lets the queue ship its own
|
||||
* UI and still look like it belongs here.
|
||||
*/
|
||||
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
|
||||
--bg: #eceff1;
|
||||
--panel: #ffffff;
|
||||
--fg: #1a2027;
|
||||
--dim: #505c67;
|
||||
--line: #d6dbdf;
|
||||
--accent: #14655b;
|
||||
--accent-fg: #ffffff;
|
||||
--good: #15803d;
|
||||
--warn: #b45309;
|
||||
--error: #b91c1c;
|
||||
|
||||
--radius: 10px;
|
||||
--gap: 1rem;
|
||||
--font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto,
|
||||
"Helvetica Neue", Arial, sans-serif;
|
||||
--mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #14181c;
|
||||
--panel: #1b2126;
|
||||
--fg: #e3e7ea;
|
||||
--dim: #a8b2ba;
|
||||
--line: #2a3238;
|
||||
--accent: #4fb3a3;
|
||||
--accent-fg: #14181c;
|
||||
--good: #4ade80;
|
||||
--warn: #fbbf24;
|
||||
--error: #f87171;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--fg);
|
||||
font: 16px/1.55 var(--font);
|
||||
}
|
||||
|
||||
code, pre { font-family: var(--mono); font-size: 0.9em; }
|
||||
pre { overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
|
||||
a { color: var(--accent); }
|
||||
|
||||
/* -- the frame ------------------------------------------------------------ */
|
||||
|
||||
.top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--gap);
|
||||
flex-wrap: wrap;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--line);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 5;
|
||||
}
|
||||
|
||||
.brand span { color: var(--accent); }
|
||||
.brand {
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
text-decoration: none;
|
||||
color: var(--fg);
|
||||
}
|
||||
|
||||
.top nav { display: flex; gap: 0.25rem; flex-wrap: wrap; }
|
||||
|
||||
.top nav a {
|
||||
padding: 0.35rem 0.7rem;
|
||||
border-radius: var(--radius);
|
||||
text-decoration: none;
|
||||
color: var(--dim);
|
||||
}
|
||||
.top nav a:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
.top nav a.active { background: var(--accent); color: var(--accent-fg); }
|
||||
|
||||
main {
|
||||
max-width: 62rem;
|
||||
margin: 0 auto;
|
||||
padding: 1.5rem 1.25rem 4rem;
|
||||
}
|
||||
|
||||
h1 { font-size: 1.6rem; margin: 0 0 0.5rem; }
|
||||
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
|
||||
|
||||
.lede { color: var(--dim); max-width: 46rem; }
|
||||
.muted { color: var(--dim); }
|
||||
.small { font-size: 0.85rem; }
|
||||
|
||||
.note {
|
||||
background: color-mix(in srgb, var(--accent) 8%, var(--panel));
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
|
||||
border-radius: var(--radius);
|
||||
padding: 0.9rem 1rem;
|
||||
max-width: 46rem;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
padding: 1rem 1.15rem;
|
||||
margin: 1.25rem 0;
|
||||
}
|
||||
|
||||
.row-between {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: var(--gap);
|
||||
}
|
||||
|
||||
.summary { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; margin: 0; }
|
||||
.summary dt { color: var(--dim); }
|
||||
.summary dd { margin: 0; }
|
||||
|
||||
.buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
padding: 0.4rem 0.9rem;
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid transparent;
|
||||
background: var(--accent);
|
||||
color: var(--accent-fg);
|
||||
cursor: pointer;
|
||||
}
|
||||
button:disabled { opacity: 0.55; cursor: progress; }
|
||||
button.secondary {
|
||||
background: transparent;
|
||||
color: var(--fg);
|
||||
border-color: var(--line);
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 0 0.4rem;
|
||||
border-radius: 999px;
|
||||
background: var(--line);
|
||||
color: var(--dim);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* -- the notice log ------------------------------------------------------- */
|
||||
|
||||
.notice {
|
||||
border: 1px solid var(--line);
|
||||
border-left: 3px solid var(--dim);
|
||||
border-radius: var(--radius);
|
||||
padding: 0.6rem 0.8rem;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
.notice.error { border-left-color: var(--error); }
|
||||
.notice.warning { border-left-color: var(--warn); }
|
||||
.notice.good { border-left-color: var(--good); }
|
||||
.notice-head { display: flex; justify-content: space-between; gap: var(--gap); align-items: start; }
|
||||
.notice-text { font-weight: 600; }
|
||||
|
||||
/* -- toasts --------------------------------------------------------------- */
|
||||
|
||||
.toasts {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
width: min(26rem, calc(100vw - 2rem));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
/* A popover brings its own box; this is a container, not a card. */
|
||||
border: 0;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
inset: auto 1rem 1rem auto;
|
||||
}
|
||||
|
||||
.toast {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
align-items: start;
|
||||
background: var(--panel);
|
||||
color: var(--fg);
|
||||
border: 1px solid var(--line);
|
||||
border-left: 3px solid var(--dim);
|
||||
border-radius: var(--radius);
|
||||
padding: 0.6rem 0.75rem;
|
||||
box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
|
||||
animation: toast-in 160ms ease-out;
|
||||
}
|
||||
.toast.error { border-left-color: var(--error); }
|
||||
.toast.warning { border-left-color: var(--warn); }
|
||||
.toast.good { border-left-color: var(--good); }
|
||||
.toast.out { opacity: 0; transition: opacity 180ms ease-in; }
|
||||
.toast-body { flex: 1; min-width: 0; }
|
||||
.toast-count { color: var(--dim); }
|
||||
.toast-fix { color: var(--dim); }
|
||||
.toast-actions { display: flex; gap: 0.5rem; align-items: center; }
|
||||
.toast-actions:empty { display: none; }
|
||||
.toast-close {
|
||||
background: transparent;
|
||||
color: var(--dim);
|
||||
border: 0;
|
||||
padding: 0 0.25rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
@keyframes toast-in {
|
||||
from { transform: translateY(6px); opacity: 0; }
|
||||
to { transform: none; opacity: 1; }
|
||||
}
|
||||
|
||||
/* -- the modules' elements ------------------------------------------------ */
|
||||
/* `<desk-jobs>` and `<desk-schedules>` from the queue, `<auth-account>` from
|
||||
* auth: all three read these, so they look like one application and none of
|
||||
* them is forked to get it. An element the app has not got yet simply matches
|
||||
* nothing. */
|
||||
|
||||
desk-jobs, desk-schedules, auth-account {
|
||||
display: block;
|
||||
--desk-jobs-bg: var(--panel);
|
||||
--desk-jobs-fg: var(--fg);
|
||||
--desk-jobs-dim: var(--dim);
|
||||
--desk-jobs-accent: var(--accent);
|
||||
--desk-jobs-error: var(--error);
|
||||
--desk-jobs-font: var(--font);
|
||||
--desk-jobs-gap: var(--gap);
|
||||
--desk-jobs-radius: var(--radius);
|
||||
}
|
||||
|
||||
/* -- roledesk's tabs ------------------------------------------------------ */
|
||||
/* Roles, Applications, Agents and Companies, drawn by static/roles.js. */
|
||||
|
||||
input, select, textarea { font: inherit; color: inherit; }
|
||||
|
||||
.filters {
|
||||
display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
|
||||
padding: .75rem; margin-bottom: .5rem;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line); border-radius: var(--radius);
|
||||
}
|
||||
.filters input[type="search"], .filters input[type="text"], .filters select {
|
||||
padding: .4rem .55rem;
|
||||
border: 1px solid var(--line); border-radius: .3rem;
|
||||
background: var(--bg); min-width: 0;
|
||||
}
|
||||
.filters input[type="search"] { flex: 1 1 12rem; }
|
||||
.filters input[type="text"] { flex: 1 1 8rem; }
|
||||
.check {
|
||||
display: flex; align-items: center; gap: .35rem;
|
||||
color: var(--dim); font-size: .9rem; white-space: nowrap;
|
||||
}
|
||||
.check[hidden] { display: none; }
|
||||
|
||||
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
|
||||
textarea:focus-visible {
|
||||
outline: 2px solid var(--accent); outline-offset: 1px;
|
||||
}
|
||||
|
||||
.count { color: var(--dim); font-size: .85rem; margin: .75rem 0 .5rem; }
|
||||
|
||||
/* roles */
|
||||
|
||||
.roles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
|
||||
.role {
|
||||
background: var(--panel); border: 1px solid var(--line); border-radius: .5rem;
|
||||
padding: .6rem .8rem;
|
||||
display: flex; flex-direction: column; gap: .35rem;
|
||||
}
|
||||
.role-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; }
|
||||
.role-title { font-weight: 600; text-decoration: none; }
|
||||
.role-title:hover { text-decoration: underline; }
|
||||
.role-company { color: var(--dim); }
|
||||
.role-meta {
|
||||
display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
|
||||
color: var(--dim); font-size: .85rem;
|
||||
}
|
||||
.role-meta .badge {
|
||||
background: transparent; color: var(--dim);
|
||||
border: 1px solid var(--line); border-radius: 1rem;
|
||||
padding: .05rem .55rem; font-size: .78rem;
|
||||
}
|
||||
.role-meta .badge:empty { display: none; }
|
||||
.role-meta .role-score {
|
||||
color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.role-gated { color: var(--error); font-size: .85rem; }
|
||||
.role-age { margin-left: auto; }
|
||||
.role.muted, tr.muted { opacity: .55; }
|
||||
.role.gated { opacity: .7; }
|
||||
|
||||
.affinity { display: inline-flex; gap: .15rem; }
|
||||
.role-main .affinity { margin-left: auto; }
|
||||
.affinity button {
|
||||
background: none; border: 1px solid var(--line); border-radius: .3rem;
|
||||
padding: .1rem .4rem; color: var(--dim); font-size: .85rem; line-height: 1.4;
|
||||
}
|
||||
.affinity button[aria-pressed="true"] {
|
||||
color: var(--accent-fg); background: var(--accent); border-color: var(--accent);
|
||||
}
|
||||
.affinity button[data-value="-1"][aria-pressed="true"] {
|
||||
background: var(--error); border-color: var(--error);
|
||||
}
|
||||
|
||||
.save { align-self: flex-start; padding: .3rem .8rem; font-weight: 600; }
|
||||
.save[disabled] {
|
||||
background: var(--bg); color: var(--dim); border-color: var(--line); cursor: default;
|
||||
}
|
||||
|
||||
/* agents */
|
||||
|
||||
.agents { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
|
||||
.agent {
|
||||
display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
|
||||
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
|
||||
padding: .5rem .75rem;
|
||||
}
|
||||
.agent a { font-weight: 600; text-decoration: none; }
|
||||
.agent-meta { color: var(--dim); font-size: .85rem; flex: 1 1 12rem; }
|
||||
.agent-form {
|
||||
display: flex; flex-direction: column; gap: .6rem; max-width: 44rem;
|
||||
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
|
||||
padding: .75rem 1rem;
|
||||
}
|
||||
.agent-form h2 { font-size: 1rem; margin: 0; }
|
||||
.agent-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
|
||||
.agent-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
|
||||
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"] {
|
||||
background: var(--bg); border: 1px solid var(--line);
|
||||
border-radius: .3rem; padding: .35rem .5rem; width: 100%;
|
||||
}
|
||||
.agent-form textarea { font-family: var(--mono); font-size: .85rem; }
|
||||
.agent-form .hint { color: var(--dim); font-size: .8rem; overflow-wrap: anywhere; }
|
||||
.weights { display: flex; gap: .75rem; flex-wrap: wrap; border: 1px solid var(--line); border-radius: .3rem; }
|
||||
.weights label { flex: 1 1 6rem; }
|
||||
.agent-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
|
||||
|
||||
/* applications and companies */
|
||||
|
||||
table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
|
||||
table.list th, table.list td {
|
||||
text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line);
|
||||
font-size: .9rem;
|
||||
}
|
||||
table.list .num { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
table.list select { padding: .25rem .4rem; }
|
||||
|
||||
/* Below tablet width a table stops being a table: each row becomes a card,
|
||||
its cells stacked, so nothing scrolls sideways to be read. */
|
||||
@media (max-width: 640px) {
|
||||
table.list thead { display: none; }
|
||||
table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
|
||||
table.list tr { margin-bottom: .6rem; border: 1px solid var(--line); border-radius: .4rem; }
|
||||
table.list td { border-bottom: none; }
|
||||
table.list .num { text-align: left; }
|
||||
table.list td::before {
|
||||
content: attr(data-label);
|
||||
display: block; font-size: .72rem; color: var(--dim); margin-bottom: .1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.role-age, .role-main .affinity { margin-left: 0; }
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/* The one way this app talks to its own API.
|
||||
*
|
||||
* const kinds = await api("/api/jobs/kinds");
|
||||
* await api("/api/jobs", { method: "POST", body: { kind: "tick" } });
|
||||
*
|
||||
* Every button on every tab goes through `api`, so a failure is always one
|
||||
* toast carrying the server's own sentence. That is the other half of the
|
||||
* bargain the exception handler in `app/main.py` makes: it promises every
|
||||
* error body is `{"detail": "<one readable sentence>"}`, and this is what
|
||||
* cashes the promise. Wording a failure in the browser as well would be two
|
||||
* descriptions of one thing, and the client's would be the one that was wrong.
|
||||
*
|
||||
* `body` may be a plain object; it is JSON-encoded with the header set, since
|
||||
* forgetting the header is the failure that looks like a server bug.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
async function api(path, options) {
|
||||
const o = Object.assign({}, options);
|
||||
const headers = Object.assign({ Accept: "application/json" }, o.headers);
|
||||
if (o.body !== undefined && typeof o.body !== "string") {
|
||||
headers["Content-Type"] = "application/json";
|
||||
o.body = JSON.stringify(o.body);
|
||||
}
|
||||
o.headers = headers;
|
||||
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(path, o);
|
||||
} catch (e) {
|
||||
// The network, not the server: there is no `detail` to read.
|
||||
window.toast.error("Could not reach the server. Is it still running?");
|
||||
throw e;
|
||||
}
|
||||
const text = await response.text();
|
||||
let data = null;
|
||||
if (text) {
|
||||
try { data = JSON.parse(text); } catch (e) { data = null; }
|
||||
}
|
||||
if (!response.ok) {
|
||||
const detail = (data && data.detail)
|
||||
|| `The server answered ${response.status} and said nothing about why.`;
|
||||
window.toast.error(String(detail));
|
||||
const error = new Error(detail);
|
||||
error.status = response.status;
|
||||
error.detail = detail;
|
||||
throw error;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/* `window.esc` is toasts.js's — it loads first and had to have one anyway,
|
||||
and two copies of an escaper is one of them being fixed. See base.html
|
||||
for the load order that makes this safe. */
|
||||
|
||||
/* The queue's own elements do their own fetching, so their failures never
|
||||
pass through `api()`. They raise an event carrying the server's `detail`
|
||||
instead, and this is the same bargain kept one level out: one toast, the
|
||||
server's sentence, nothing reworded here.
|
||||
|
||||
`desk-jobs:notice` is a notice arriving on the element's socket, which
|
||||
live.js already delivers as `app:notice` — so it is deliberately not
|
||||
listened for. Two toasts for one failure is the bug that listening would
|
||||
buy. */
|
||||
document.addEventListener("desk-schedules:error", (e) => {
|
||||
const detail = (e.detail && e.detail.detail) || "That change was refused.";
|
||||
window.toast.error(String(detail));
|
||||
});
|
||||
|
||||
window.api = api;
|
||||
})();
|
||||
@@ -0,0 +1,66 @@
|
||||
/* The Jobs tab: a button per kind.
|
||||
*
|
||||
* The list comes from `/api/jobs/kinds`, which is the registry, so a new
|
||||
* `@job` in `app/jobs.py` is a new button and this file is not edited. What
|
||||
* the queue is doing is `<desk-jobs>`'s business, and it draws itself.
|
||||
*
|
||||
* Failures are the server's sentence through `api()`, which toasts it -- so
|
||||
* there is no error handling here beyond keeping the button usable.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const host = document.getElementById("kinds");
|
||||
if (!host) return;
|
||||
|
||||
async function start(kind, button) {
|
||||
button.disabled = true;
|
||||
try {
|
||||
const job = await window.api("/api/jobs", { method: "POST", body: { kind } });
|
||||
window.toast.good(`${job.label || kind}: queued.`);
|
||||
} catch (e) {
|
||||
/* already toasted */
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function draw() {
|
||||
let kinds;
|
||||
try {
|
||||
kinds = await window.api("/api/jobs/kinds");
|
||||
} catch (e) {
|
||||
host.innerHTML = '<span class="muted">could not read the job kinds</span>';
|
||||
return;
|
||||
}
|
||||
if (!kinds.length) {
|
||||
host.innerHTML = '<span class="muted">nothing is registered</span>';
|
||||
return;
|
||||
}
|
||||
host.innerHTML = "";
|
||||
kinds.forEach((k) => {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.textContent = k.label || k.kind;
|
||||
button.title = k.solo ? `${k.kind} -- one at a time` : k.kind;
|
||||
button.dataset.kind = k.kind;
|
||||
button.addEventListener("click", () => start(k.kind, button));
|
||||
host.appendChild(button);
|
||||
});
|
||||
}
|
||||
|
||||
/* `<desk-jobs>` takes up no space while the queue is idle, so the line that
|
||||
says so is the app's to show and hide. Off the same socket the element
|
||||
reads, through live.js, rather than by asking the element: it keeps to a
|
||||
shadow root and owes nobody an answer about its own height. */
|
||||
document.addEventListener("app:jobs", (e) => {
|
||||
const idle = document.getElementById("idle");
|
||||
if (!idle) return;
|
||||
const state = e.detail || {};
|
||||
const busy = (state.running || []).length + (state.queued || []).length;
|
||||
idle.hidden = busy > 0;
|
||||
});
|
||||
|
||||
document.addEventListener("DOMContentLoaded", draw);
|
||||
})();
|
||||
@@ -0,0 +1,84 @@
|
||||
/* The page's one connection to the server: the queue's socket.
|
||||
*
|
||||
* `/ws/jobs` sends two kinds of message, and this turns each into a document
|
||||
* event so that no other script opens a socket of its own — five tabs each
|
||||
* holding their own would be five reconnect loops to get subtly wrong:
|
||||
*
|
||||
* app:jobs the whole queue: {running, queued, recent, ...}. Sent on
|
||||
* connect and after every change. `window.live.jobs` holds the
|
||||
* latest, for a script that loads after a message.
|
||||
* app:notice one notice from the log (app/notices.py), its count
|
||||
* included. toasts.js shows it.
|
||||
* app:schedules the schedule list, whenever one fires, is skipped or is
|
||||
* edited. `<desk-schedules>` holds its own socket and does not
|
||||
* need this; it is here for a page that wants to say when the
|
||||
* next run is without drawing the whole table.
|
||||
*
|
||||
* Nothing here dispatches by hand: the name is taken from the message, so a
|
||||
* fourth type is a listener somewhere and no edit to this file.
|
||||
*
|
||||
* Reconnects with backoff, because the server restarting is the normal case
|
||||
* and a page that needs reloading after every deploy is a page people reload
|
||||
* by habit and then trust less.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const live = { jobs: null, connected: false };
|
||||
window.live = live;
|
||||
|
||||
let backoff = 1000;
|
||||
|
||||
function connect() {
|
||||
const proto = location.protocol === "https:" ? "wss:" : "ws:";
|
||||
const socket = new WebSocket(`${proto}//${location.host}/ws/jobs`);
|
||||
socket.onopen = () => {
|
||||
backoff = 1000;
|
||||
live.connected = true;
|
||||
};
|
||||
socket.onmessage = (ev) => {
|
||||
let msg;
|
||||
try { msg = JSON.parse(ev.data); } catch (e) { return; }
|
||||
const { type, ...body } = msg;
|
||||
if (!type) return;
|
||||
if (type === "jobs") live.jobs = body;
|
||||
document.dispatchEvent(new CustomEvent(`app:${type}`, { detail: body }));
|
||||
};
|
||||
socket.onclose = () => {
|
||||
live.connected = false;
|
||||
setTimeout(async () => {
|
||||
if (await signedOut()) return;
|
||||
connect();
|
||||
}, backoff);
|
||||
backoff = Math.min(backoff * 2, 30000);
|
||||
};
|
||||
}
|
||||
|
||||
/* A refused handshake and a dead server look identical from here: the
|
||||
middleware in `auth/` closes the socket before accepting it, which the
|
||||
server turns into an HTTP 403 on the upgrade, and the browser reports the
|
||||
same abnormal close it reports for "the server is gone". So one cheap
|
||||
request tells them apart, and an expired session sends the page to the
|
||||
door instead of leaving it reconnecting quietly against a login form for
|
||||
the rest of the afternoon. `<desk-jobs>` has the same trick as its
|
||||
`probe` attribute; it is done here so that it is done on every tab. */
|
||||
async function signedOut() {
|
||||
let answer;
|
||||
try {
|
||||
answer = await fetch("/api/jobs", { headers: { Accept: "application/json" } });
|
||||
} catch (e) {
|
||||
return false; // offline: keep the backoff going
|
||||
}
|
||||
if (answer.status !== 401 && answer.status !== 403) return false;
|
||||
const next = location.pathname + location.search;
|
||||
location.assign(`/login?next=${encodeURIComponent(next)}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// The login page has no session for the socket to use, and asking would
|
||||
// only be a 401 every second while somebody types a password.
|
||||
if (location.pathname !== "/login") connect();
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,85 @@
|
||||
/* The Messages tab: the notice log as a table.
|
||||
*
|
||||
* `/api/notices` is the queue's own route (`pipeline/web/jobs.py`) -- the log
|
||||
* belongs to the queue, the wording belongs to the app, and this page is only
|
||||
* the reading of it. It redraws on `app:notice` so a failure that happens
|
||||
* while you are looking at this tab appears without a reload.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const host = document.getElementById("notices");
|
||||
const clearAll = document.getElementById("clear-all");
|
||||
if (!host) return;
|
||||
|
||||
const esc = window.esc;
|
||||
|
||||
function when(iso) {
|
||||
if (!iso) return "";
|
||||
const d = new Date(iso);
|
||||
return isNaN(d) ? iso : d.toLocaleString();
|
||||
}
|
||||
|
||||
function row(n) {
|
||||
const count = n.count > 1 ? `<span class="badge">x${n.count}</span>` : "";
|
||||
return `
|
||||
<article class="notice ${esc(n.level)}" data-id="${n.id}">
|
||||
<div class="notice-head">
|
||||
<span class="notice-text">${esc(n.text)} ${count}</span>
|
||||
<button type="button" class="secondary" data-clear="${n.id}">Clear</button>
|
||||
</div>
|
||||
<div class="small muted">${esc(n.code)}${n.key ? " / " + esc(n.key) : ""}
|
||||
-- last said ${esc(when(n.last_at))}
|
||||
${n.kind === "bug" ? "-- looks like a bug rather than a bad day" : ""}</div>
|
||||
${n.fix ? `<div class="small">${esc(n.fix)}</div>` : ""}
|
||||
${n.detail ? `<details class="small"><summary>details</summary>
|
||||
<pre>${esc(n.detail)}</pre></details>` : ""}
|
||||
</article>`;
|
||||
}
|
||||
|
||||
async function draw() {
|
||||
let list;
|
||||
try {
|
||||
list = await window.api("/api/notices");
|
||||
} catch (e) {
|
||||
host.innerHTML = '<span class="muted">could not read the log</span>';
|
||||
return;
|
||||
}
|
||||
if (!list.length) {
|
||||
host.innerHTML = '<span class="muted">Nothing to report.</span>';
|
||||
return;
|
||||
}
|
||||
host.innerHTML = list.map(row).join("");
|
||||
}
|
||||
|
||||
host.addEventListener("click", async (e) => {
|
||||
const id = e.target.dataset && e.target.dataset.clear;
|
||||
if (!id) return;
|
||||
e.target.disabled = true;
|
||||
try {
|
||||
await window.api(`/api/notices/${id}`, { method: "DELETE" });
|
||||
await draw();
|
||||
} catch (err) {
|
||||
e.target.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (clearAll) {
|
||||
clearAll.addEventListener("click", async () => {
|
||||
clearAll.disabled = true;
|
||||
try {
|
||||
const out = await window.api("/api/notices", { method: "DELETE" });
|
||||
window.toast.good(`Cleared ${out.cleared}.`);
|
||||
await draw();
|
||||
} catch (e) {
|
||||
/* already toasted */
|
||||
} finally {
|
||||
clearAll.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("app:notice", draw);
|
||||
document.addEventListener("DOMContentLoaded", draw);
|
||||
})();
|
||||
@@ -0,0 +1,524 @@
|
||||
/* roledesk's four tabs: Roles, Applications, Agents and Companies.
|
||||
*
|
||||
* Each template renders an empty shell; everything on screen comes from the
|
||||
* JSON routes in app/web/api.py, and every action (Save, an affinity click, a
|
||||
* status change, an agent saved) is a fetch from here, not a form post. One
|
||||
* script for the four, because they share the company list and the affinity
|
||||
* control; `init` looks at which containers the page has.
|
||||
*
|
||||
* Every request goes through `api()` from app.js, so a failure is one toast
|
||||
* carrying the server's own sentence. The catch blocks here only put the
|
||||
* control back the way it was.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const api = window.api;
|
||||
|
||||
/** @type {Map<string, object>} company_key -> row from /api/companies */
|
||||
let companies = new Map();
|
||||
/** @type {Map<string, object>} role_uid -> application, for roles already tracked */
|
||||
let trackedByRole = new Map();
|
||||
/** @type {object[]} the last /api/roles response, already muted-filtered by the server */
|
||||
let roles = [];
|
||||
/** @type {object[]} every search agent, from /api/agents */
|
||||
let agents = [];
|
||||
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
|
||||
function debounce(fn, ms) {
|
||||
let timer;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => fn(...args), ms);
|
||||
};
|
||||
}
|
||||
|
||||
function count(n, one, many) {
|
||||
return `${n} ${n === 1 ? one : many || `${one}s`}`;
|
||||
}
|
||||
|
||||
async function loadCompanies() {
|
||||
const rows = await api("/api/companies");
|
||||
companies = new Map(rows.map((c) => [c.key, c]));
|
||||
}
|
||||
|
||||
async function loadApplications() {
|
||||
const applications = await api("/api/applications");
|
||||
trackedByRole = new Map(applications.filter((a) => a.role_uid).map((a) => [a.role_uid, a]));
|
||||
return applications;
|
||||
}
|
||||
|
||||
async function loadAgents() {
|
||||
agents = await api("/api/agents");
|
||||
}
|
||||
|
||||
function cell(tr, label, content) {
|
||||
const td = document.createElement("td");
|
||||
td.dataset.label = label;
|
||||
if (typeof content === "string") td.textContent = content;
|
||||
else td.appendChild(content);
|
||||
tr.appendChild(td);
|
||||
return td;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- affinity
|
||||
|
||||
const AFFINITY_LEVELS = [
|
||||
{ value: -1, label: "Mute" },
|
||||
{ value: 0, label: "Neutral" },
|
||||
{ value: 1, label: "Like" },
|
||||
{ value: 2, label: "Favourite" },
|
||||
];
|
||||
|
||||
/* The four buttons. `onChange` runs after the server accepted the change,
|
||||
so each tab decides what a change means for it: the role list refetches,
|
||||
since muting changes which roles come back, and the company table redraws. */
|
||||
function affinityControl(companyKey, current, onChange) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
span.setAttribute("aria-label", "Company affinity");
|
||||
for (const level of AFFINITY_LEVELS) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.dataset.value = String(level.value);
|
||||
button.textContent = level.label[0];
|
||||
button.title = level.label;
|
||||
button.setAttribute("aria-label", level.label);
|
||||
button.setAttribute("aria-pressed", String(level.value === current));
|
||||
button.addEventListener("click", () => setAffinity(companyKey, level.value, onChange));
|
||||
span.appendChild(button);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
async function setAffinity(companyKey, affinity, onChange) {
|
||||
if (!companyKey) return;
|
||||
let updated;
|
||||
try {
|
||||
updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
|
||||
method: "POST", body: { affinity },
|
||||
});
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
const company = companies.get(companyKey);
|
||||
if (company) company.affinity = updated.affinity;
|
||||
await onChange();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- roles
|
||||
|
||||
function filterParams() {
|
||||
const params = new URLSearchParams();
|
||||
for (const key of ["q", "company", "place"]) {
|
||||
const value = $(`#f-${key}`).value.trim();
|
||||
if (value) params.set(key, value);
|
||||
}
|
||||
for (const key of ["function", "remote", "days"]) {
|
||||
const value = $(`#f-${key}`).value;
|
||||
if (value) params.set(key, value);
|
||||
}
|
||||
if ($("#f-show-muted").checked) params.set("show_muted", "true");
|
||||
const agent = $("#f-agent").value;
|
||||
if (agent) {
|
||||
params.set("agent", agent);
|
||||
if ($("#f-gated").checked) params.set("gated", "1");
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
async function loadRoles() {
|
||||
try {
|
||||
roles = await api(`/api/roles?${filterParams().toString()}`);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
renderRoles();
|
||||
}
|
||||
|
||||
function relativeAge(iso) {
|
||||
const then = new Date(iso);
|
||||
const minutes = Math.max(0, Math.floor((Date.now() - then.getTime()) / 60000));
|
||||
if (minutes < 60) return `${minutes} min ago`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours} h ago`;
|
||||
return `${Math.floor(hours / 24)} d ago`;
|
||||
}
|
||||
|
||||
function renderRoles() {
|
||||
const list = $("#roles-list");
|
||||
const template = $("#role-row");
|
||||
list.replaceChildren();
|
||||
|
||||
for (const role of roles) {
|
||||
const node = template.content.cloneNode(true);
|
||||
const li = node.querySelector(".role");
|
||||
const company = companies.get(role.company_key);
|
||||
|
||||
if (company && company.affinity === -1) li.classList.add("muted");
|
||||
|
||||
const titleLink = node.querySelector(".role-title");
|
||||
titleLink.textContent = role.title || "(untitled)";
|
||||
titleLink.href = role.original_url || "#";
|
||||
|
||||
node.querySelector(".role-company").textContent = role.company || "";
|
||||
node.querySelector(".role-place").textContent = role.place || "";
|
||||
node.querySelector(".role-remote").textContent = role.remote || "";
|
||||
node.querySelector(".role-function").textContent = role.function || "";
|
||||
node.querySelector(".role-age").textContent = relativeAge(role.first_seen);
|
||||
if (role.score !== null && role.score !== undefined) {
|
||||
const badge = node.querySelector(".role-score");
|
||||
badge.textContent = role.gated_reason ? "gated" : role.score.toFixed(2);
|
||||
badge.title = "Score for the selected agent";
|
||||
node.querySelector(".role-gated").textContent = role.gated_reason || "";
|
||||
if (role.gated_reason) li.classList.add("gated");
|
||||
}
|
||||
|
||||
node.querySelector(".affinity").replaceWith(
|
||||
affinityControl(role.company_key, company ? company.affinity : 0, loadRoles));
|
||||
|
||||
const saveButton = node.querySelector(".save");
|
||||
setSaveButton(saveButton, role.uid);
|
||||
saveButton.addEventListener("click", () => saveRole(role.uid, saveButton));
|
||||
|
||||
list.appendChild(node);
|
||||
}
|
||||
|
||||
$("#roles-count").textContent = count(roles.length, "role");
|
||||
}
|
||||
|
||||
function setSaveButton(button, uid) {
|
||||
const saved = trackedByRole.has(uid);
|
||||
button.textContent = saved ? "Saved" : "Save";
|
||||
button.disabled = saved;
|
||||
}
|
||||
|
||||
async function saveRole(uid, button) {
|
||||
button.disabled = true;
|
||||
button.textContent = "Saving…";
|
||||
try {
|
||||
const application = await api("/api/applications", {
|
||||
method: "POST", body: { role_uid: uid, status: "saved" },
|
||||
});
|
||||
trackedByRole.set(uid, application);
|
||||
setSaveButton(button, uid);
|
||||
} catch (err) {
|
||||
button.disabled = false;
|
||||
button.textContent = "Save";
|
||||
}
|
||||
}
|
||||
|
||||
// The filter bar's order: "Newest", or one agent's score. Keeps the current
|
||||
// choice when the list is refreshed, unless that agent is gone.
|
||||
function renderAgentSelect() {
|
||||
const select = $("#f-agent");
|
||||
const current = select.value;
|
||||
select.replaceChildren(new Option("Newest", ""));
|
||||
for (const agent of agents) {
|
||||
const label = agent.enabled ? agent.name : `${agent.name} (off)`;
|
||||
select.appendChild(new Option(label, String(agent.id)));
|
||||
}
|
||||
select.value = agents.some((a) => String(a.id) === current) ? current : "";
|
||||
$("#show-gated").hidden = !select.value;
|
||||
}
|
||||
|
||||
/* `?q=`, `?company=`, `?place=` and `?agent=` prefill the filter bar, which
|
||||
is how the Companies and Agents tabs link into this one. */
|
||||
function prefill() {
|
||||
const query = new URLSearchParams(location.search);
|
||||
for (const key of ["q", "company", "place"]) {
|
||||
if (query.get(key)) $(`#f-${key}`).value = query.get(key);
|
||||
}
|
||||
const agent = query.get("agent");
|
||||
if (agent && agents.some((a) => String(a.id) === agent)) {
|
||||
$("#f-agent").value = agent;
|
||||
$("#show-gated").hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function initRoles() {
|
||||
try {
|
||||
await Promise.all([loadCompanies(), loadApplications(), loadAgents()]);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
renderAgentSelect();
|
||||
prefill();
|
||||
await loadRoles();
|
||||
|
||||
const refetch = debounce(loadRoles, 300);
|
||||
for (const key of ["q", "company", "place"]) {
|
||||
$(`#f-${key}`).addEventListener("input", refetch);
|
||||
}
|
||||
for (const sel of ["#f-function", "#f-remote", "#f-days", "#f-show-muted", "#f-gated"]) {
|
||||
$(sel).addEventListener("change", loadRoles);
|
||||
}
|
||||
$("#f-agent").addEventListener("change", () => {
|
||||
$("#show-gated").hidden = !$("#f-agent").value;
|
||||
loadRoles();
|
||||
});
|
||||
$("#filters").addEventListener("submit", (e) => e.preventDefault());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ applications
|
||||
|
||||
// `ROLEDESK_STATUSES` is set by applications.html from the same `STATUSES`
|
||||
// tuple the store validates against, so this list can never drift from
|
||||
// what a `POST .../status` will accept.
|
||||
function statusSelect(current) {
|
||||
const select = document.createElement("select");
|
||||
for (const status of window.ROLEDESK_STATUSES) {
|
||||
const option = document.createElement("option");
|
||||
option.value = status;
|
||||
option.textContent = status[0].toUpperCase() + status.slice(1);
|
||||
option.selected = status === current;
|
||||
select.appendChild(option);
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
function renderApplications(applications) {
|
||||
const body = $("#applications-list");
|
||||
body.replaceChildren();
|
||||
for (const application of applications) {
|
||||
const tr = document.createElement("tr");
|
||||
if (application.url) {
|
||||
const link = document.createElement("a");
|
||||
link.href = application.url;
|
||||
link.target = "_blank";
|
||||
link.rel = "noopener";
|
||||
link.textContent = application.role_title || "(untitled)";
|
||||
cell(tr, "Role", link);
|
||||
} else {
|
||||
cell(tr, "Role", application.role_title || "(untitled)");
|
||||
}
|
||||
const company = companies.get(application.company_key);
|
||||
cell(tr, "Company", company ? company.name : application.company_key);
|
||||
const select = statusSelect(application.status);
|
||||
select.addEventListener("change", () => setStatus(application.id, select));
|
||||
cell(tr, "Status", select);
|
||||
cell(tr, "Next", [application.next_action, application.next_date]
|
||||
.filter(Boolean).join(" · "));
|
||||
body.appendChild(tr);
|
||||
}
|
||||
$("#applications-count").textContent =
|
||||
count(applications.length, "tracked application");
|
||||
}
|
||||
|
||||
async function setStatus(id, select) {
|
||||
select.disabled = true;
|
||||
try {
|
||||
await api(`/api/applications/${encodeURIComponent(id)}/status`, {
|
||||
method: "POST", body: { status: select.value },
|
||||
});
|
||||
renderApplications(await loadApplications());
|
||||
} catch (err) {
|
||||
select.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function initApplications() {
|
||||
try {
|
||||
const [, applications] = await Promise.all([loadCompanies(), loadApplications()]);
|
||||
renderApplications(applications);
|
||||
} catch (err) {
|
||||
/* already toasted */
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ agents
|
||||
|
||||
function renderAgents() {
|
||||
const list = $("#agents-list");
|
||||
list.replaceChildren();
|
||||
for (const agent of agents) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "agent";
|
||||
const name = document.createElement("a");
|
||||
name.href = `/?agent=${agent.id}`;
|
||||
name.title = "Roles, ordered by this agent's score";
|
||||
name.textContent = agent.name;
|
||||
const meta = document.createElement("span");
|
||||
meta.className = "agent-meta";
|
||||
const gates = agent.gates.map((g) => `${g.mode} ${g.field}`).join(", ") || "no gates";
|
||||
meta.textContent = `${agent.enabled ? "" : "off · "}${gates}`;
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button";
|
||||
edit.className = "secondary";
|
||||
edit.textContent = "Edit";
|
||||
edit.addEventListener("click", () => fillAgentForm(agent));
|
||||
li.append(name, meta, edit);
|
||||
list.appendChild(li);
|
||||
}
|
||||
$("#agents-count").textContent = count(agents.length, "agent");
|
||||
}
|
||||
|
||||
function fillAgentForm(agent) {
|
||||
$("#agent-form-title").textContent = agent ? `Edit ${agent.name}` : "New agent";
|
||||
$("#a-id").value = agent ? String(agent.id) : "";
|
||||
$("#a-name").value = agent ? agent.name : "";
|
||||
$("#a-intent").value = agent ? agent.intent : "";
|
||||
$("#a-gates").value = JSON.stringify(agent ? agent.gates : [], null, 2);
|
||||
const weights = agent ? agent.weights : { fit: 0.6, recency: 0.2, affinity: 0.2 };
|
||||
$("#a-fit").value = weights.fit;
|
||||
$("#a-recency").value = weights.recency;
|
||||
$("#a-affinity").value = weights.affinity;
|
||||
$("#a-enabled").checked = agent ? agent.enabled : true;
|
||||
$("#a-delete").hidden = !agent;
|
||||
$("#agent-status").textContent = "";
|
||||
}
|
||||
|
||||
async function saveAgent(event) {
|
||||
event.preventDefault();
|
||||
const status = $("#agent-status");
|
||||
let gates;
|
||||
try {
|
||||
gates = JSON.parse($("#a-gates").value || "[]");
|
||||
} catch (err) {
|
||||
window.toast.error(`Gates are not valid JSON: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
const id = $("#a-id").value;
|
||||
const body = {
|
||||
name: $("#a-name").value.trim(),
|
||||
intent: $("#a-intent").value,
|
||||
gates,
|
||||
weights: {
|
||||
fit: Number($("#a-fit").value),
|
||||
recency: Number($("#a-recency").value),
|
||||
affinity: Number($("#a-affinity").value),
|
||||
},
|
||||
enabled: $("#a-enabled").checked,
|
||||
};
|
||||
if (id) body.id = Number(id);
|
||||
let saved;
|
||||
try {
|
||||
saved = await api("/api/agents", { method: "POST", body });
|
||||
} catch (err) {
|
||||
status.textContent = "";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await loadAgents();
|
||||
renderAgents();
|
||||
} catch (err) {
|
||||
/* already toasted; the save itself landed */
|
||||
}
|
||||
fillAgentForm(saved);
|
||||
await rescore(status, saved);
|
||||
}
|
||||
|
||||
async function deleteAgent() {
|
||||
const id = $("#a-id").value;
|
||||
if (!id || !confirm("Delete this agent and its scores?")) return;
|
||||
try {
|
||||
await api(`/api/agents/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
fillAgentForm(null);
|
||||
await loadAgents();
|
||||
renderAgents();
|
||||
} catch (err) {
|
||||
/* already toasted */
|
||||
}
|
||||
}
|
||||
|
||||
// Start the `score` job and wait for it, so "Saved and scored" means the
|
||||
// Roles tab already orders by what was saved.
|
||||
async function rescore(status, agent) {
|
||||
status.textContent = "Saved. Scoring…";
|
||||
let job;
|
||||
try {
|
||||
job = await api("/api/jobs", { method: "POST", body: { kind: "score", payload: {} } });
|
||||
} catch (err) {
|
||||
status.textContent = "Saved, but scoring did not start.";
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
let snapshot;
|
||||
try {
|
||||
snapshot = await api("/api/jobs");
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
|
||||
if (busy) continue;
|
||||
const done = snapshot.recent.find((j) => j.id === job.id);
|
||||
if (done && done.state !== "done") {
|
||||
status.textContent = `Saved. Scoring ${done.state}.`;
|
||||
if (done.error) window.toast.error(`Scoring ${done.state}: ${done.error}`);
|
||||
return;
|
||||
}
|
||||
status.replaceChildren("Saved and scored. ");
|
||||
const link = document.createElement("a");
|
||||
link.href = `/?agent=${agent.id}`;
|
||||
link.textContent = "See the roles";
|
||||
status.appendChild(link);
|
||||
return;
|
||||
}
|
||||
status.textContent = "Saved. Scoring is still running; see the Jobs tab.";
|
||||
}
|
||||
|
||||
async function initAgents() {
|
||||
try {
|
||||
await loadAgents();
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
renderAgents();
|
||||
$("#agent-form").addEventListener("submit", saveAgent);
|
||||
$("#a-new").addEventListener("click", () => fillAgentForm(null));
|
||||
$("#a-delete").addEventListener("click", deleteAgent);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- companies
|
||||
|
||||
function renderCompanies() {
|
||||
const q = $("#c-q").value.trim().toLowerCase();
|
||||
const affinity = $("#c-affinity").value;
|
||||
const rows = [...companies.values()]
|
||||
.filter((c) => !q || c.name.toLowerCase().includes(q) || c.board.includes(q))
|
||||
.filter((c) => affinity === "" || String(c.affinity) === affinity)
|
||||
.sort((a, b) => b.open_roles - a.open_roles || a.name.localeCompare(b.name));
|
||||
const body = $("#companies-list");
|
||||
body.replaceChildren();
|
||||
for (const company of rows) {
|
||||
const tr = document.createElement("tr");
|
||||
if (company.affinity === -1) tr.classList.add("muted");
|
||||
const link = document.createElement("a");
|
||||
link.href = `/?company=${encodeURIComponent(company.name)}`;
|
||||
link.title = "This company's open roles";
|
||||
link.textContent = company.name;
|
||||
cell(tr, "Company", link);
|
||||
cell(tr, "Board", company.board || "");
|
||||
cell(tr, "Open roles", String(company.open_roles)).className = "num";
|
||||
cell(tr, "Affinity",
|
||||
affinityControl(company.key, company.affinity, async () => renderCompanies()));
|
||||
body.appendChild(tr);
|
||||
}
|
||||
const open = rows.reduce((sum, c) => sum + c.open_roles, 0);
|
||||
$("#companies-count").textContent =
|
||||
`${count(rows.length, "company", "companies")}, ${count(open, "open role")}`;
|
||||
}
|
||||
|
||||
async function initCompanies() {
|
||||
try {
|
||||
await loadCompanies();
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
renderCompanies();
|
||||
$("#c-q").addEventListener("input", debounce(renderCompanies, 150));
|
||||
$("#c-affinity").addEventListener("change", renderCompanies);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
if ($("#roles-list")) initRoles();
|
||||
if ($("#applications-list")) initApplications();
|
||||
if ($("#agents-list")) initAgents();
|
||||
if ($("#companies-list")) initCompanies();
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,226 @@
|
||||
/* Toasts: the one place on screen for messages to the user.
|
||||
*
|
||||
* Adapted from health's `webapp/static/toasts.js`, which is where the
|
||||
* behaviour was worked out. Two sources, one look:
|
||||
*
|
||||
* server notices from the log (app/notices.py), delivered by live.js as
|
||||
* `app:notice`. A problem (warning, error) interrupts the first
|
||||
* time; a repeat within five minutes only bumps the count of a
|
||||
* toast already on screen, since it is already in the log. An
|
||||
* outcome (good, info) is news every time. On page load, notices
|
||||
* raised since the last visit are shown too, so one raised while
|
||||
* no tab was open is not lost.
|
||||
* pages `toast.error(text)`, `toast.good(text)`, ... for the outcome of
|
||||
* something the user just did. These are not logged: the user is
|
||||
* looking at the result.
|
||||
*
|
||||
* Errors stay until dismissed; everything else fades. Progress of work in
|
||||
* flight is not a toast -- that is what the job's progress bar is for.
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const FADE_MS = { info: 5000, good: 5000, warning: 10000, error: 0 };
|
||||
const SEEN_KEY = "app.notices.seen";
|
||||
const MAX_ON_LOAD = 3;
|
||||
|
||||
let stack = null;
|
||||
const byCode = new Map(); // "code|key" -> toast element, for server notices
|
||||
|
||||
/* Escaping, once for the page. This file needs one and loads first, so it
|
||||
is the one that exports it: every other script here builds a little HTML
|
||||
out of server strings, and a notice's detail is raw error text that has
|
||||
already been through somebody else's parser once. Two copies of an
|
||||
escaper is one of them being the one that gets fixed. */
|
||||
function esc(s) {
|
||||
return String(s === null || s === undefined ? "" : s).replace(/[&<>"']/g, (c) => ({
|
||||
"&": "&", "<": "<", ">": ">", '"': """, "'": "'",
|
||||
})[c]);
|
||||
}
|
||||
window.esc = esc;
|
||||
|
||||
/* The stack is a manual popover, so it lives in the browser's top layer and
|
||||
shows above a modal <dialog>. The top layer is ordered by opening, so it
|
||||
is reopened on every new toast to stay above whatever opened since. */
|
||||
const POPOVER = typeof HTMLElement.prototype.showPopover === "function";
|
||||
|
||||
function container() {
|
||||
if (!stack) {
|
||||
stack = document.createElement("div");
|
||||
stack.className = "toasts";
|
||||
stack.setAttribute("aria-live", "polite");
|
||||
if (POPOVER) stack.setAttribute("popover", "manual");
|
||||
document.body.appendChild(stack);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
/* A modal dialog makes the rest of the document inert, a popover opened
|
||||
after it included: the toast would be visible but its buttons dead. So
|
||||
while a modal is open the stack lives inside it, and goes back to the body
|
||||
when the modal closes. */
|
||||
function raise() {
|
||||
const modal = document.querySelector("dialog:modal");
|
||||
const home = modal || document.body;
|
||||
if (stack.parentElement !== home) {
|
||||
home.appendChild(stack);
|
||||
if (modal) {
|
||||
modal.addEventListener("close", () => {
|
||||
if (stack.parentElement !== modal) return;
|
||||
document.body.appendChild(stack);
|
||||
if (stack.children.length) reopen();
|
||||
}, { once: true });
|
||||
}
|
||||
}
|
||||
reopen();
|
||||
}
|
||||
|
||||
function reopen() {
|
||||
if (!POPOVER) return;
|
||||
if (stack.matches(":popover-open")) stack.hidePopover();
|
||||
stack.showPopover();
|
||||
}
|
||||
|
||||
/* opts: level (info|good|warning|error), text, detail, fix, count, sticky,
|
||||
action {label, run}, link {label, href}, id (dedupe key) */
|
||||
function show(opts) {
|
||||
const o = typeof opts === "string" ? { text: opts } : opts;
|
||||
const level = o.level || "info";
|
||||
if (o.id && byCode.has(o.id)) {
|
||||
const existing = byCode.get(o.id);
|
||||
if (existing.isConnected) {
|
||||
update(existing, o);
|
||||
return existing;
|
||||
}
|
||||
byCode.delete(o.id);
|
||||
}
|
||||
|
||||
const t = document.createElement("div");
|
||||
t.className = `toast ${level}`;
|
||||
t.setAttribute("role", level === "error" ? "alert" : "status");
|
||||
t.innerHTML = `
|
||||
<div class="toast-body">
|
||||
<div class="toast-text"></div>
|
||||
${o.fix ? `<div class="toast-fix small">${esc(o.fix)}</div>` : ""}
|
||||
${o.detail ? `<details class="toast-detail small"><summary>details</summary>
|
||||
<pre>${esc(o.detail)}</pre></details>` : ""}
|
||||
<div class="toast-actions">
|
||||
${o.action ? `<button type="button" data-act="action">${esc(o.action.label)}</button>` : ""}
|
||||
${o.link ? `<a href="${esc(o.link.href)}">${esc(o.link.label)}</a>` : ""}
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="toast-close" data-act="close" aria-label="dismiss">x</button>`;
|
||||
update(t, o);
|
||||
t.addEventListener("click", (e) => {
|
||||
const act = e.target.dataset && e.target.dataset.act;
|
||||
if (act === "close") dismiss(t);
|
||||
else if (act === "action" && o.action) {
|
||||
o.action.run();
|
||||
dismiss(t);
|
||||
}
|
||||
});
|
||||
container().appendChild(t);
|
||||
raise();
|
||||
if (o.id) byCode.set(o.id, t);
|
||||
|
||||
const fade = o.sticky ? 0 : FADE_MS[level];
|
||||
if (fade) {
|
||||
let timer = setTimeout(() => dismiss(t), fade);
|
||||
// Reading it keeps it: a toast does not fade from under the cursor.
|
||||
t.addEventListener("mouseenter", () => clearTimeout(timer));
|
||||
t.addEventListener("mouseleave", () => { timer = setTimeout(() => dismiss(t), fade); });
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
function update(t, o) {
|
||||
const count = o.count > 1 ? ` <span class="toast-count">x${o.count}</span>` : "";
|
||||
t.querySelector(".toast-text").innerHTML = esc(o.text) + count;
|
||||
}
|
||||
|
||||
function dismiss(t) {
|
||||
t.classList.add("out");
|
||||
setTimeout(() => {
|
||||
t.remove();
|
||||
if (POPOVER && stack && !stack.children.length && stack.matches(":popover-open")) {
|
||||
stack.hidePopover();
|
||||
}
|
||||
}, 180);
|
||||
}
|
||||
|
||||
const toast = {
|
||||
show,
|
||||
info: (text, o) => show({ ...o, level: "info", text }),
|
||||
good: (text, o) => show({ ...o, level: "good", text }),
|
||||
warning: (text, o) => show({ ...o, level: "warning", text }),
|
||||
error: (text, o) => show({ ...o, level: "error", text }),
|
||||
};
|
||||
window.toast = toast;
|
||||
|
||||
/* -- server notices ---------------------------------------------------- */
|
||||
|
||||
function seen() {
|
||||
try { return localStorage.getItem(SEEN_KEY) || ""; } catch (e) { return ""; }
|
||||
}
|
||||
function markSeen(at) {
|
||||
try { if (at > seen()) localStorage.setItem(SEEN_KEY, at); } catch (e) { /* convenience */ }
|
||||
}
|
||||
|
||||
const PROBLEM = new Set(["warning", "error"]);
|
||||
|
||||
function fromNotice(n) {
|
||||
const t = {
|
||||
id: `${n.code}|${n.key || ""}`,
|
||||
level: n.level,
|
||||
text: n.text,
|
||||
fix: n.fix,
|
||||
detail: n.detail,
|
||||
link: { label: "all messages", href: "/messages" },
|
||||
};
|
||||
if (PROBLEM.has(n.level)) t.count = n.count;
|
||||
if (n.level === "good") t.action = { label: "reload", run: () => location.reload() };
|
||||
return t;
|
||||
}
|
||||
|
||||
/* When this page last showed each problem. A repeat within QUIET_MS only
|
||||
bumps a count, so a burst -- a job retried in a loop -- is one toast; a
|
||||
repeat after that, such as a retry the user just pressed, is shown again. */
|
||||
const QUIET_MS = 5 * 60 * 1000;
|
||||
const shownAt = new Map();
|
||||
|
||||
function onNotice(n) {
|
||||
const id = `${n.code}|${n.key || ""}`;
|
||||
const onScreen = byCode.get(id);
|
||||
markSeen(n.last_at || "");
|
||||
if (PROBLEM.has(n.level) && n.count > 1 && !(onScreen && onScreen.isConnected)
|
||||
&& Date.now() - (shownAt.get(id) || 0) < QUIET_MS) return;
|
||||
shownAt.set(id, Date.now());
|
||||
show(fromNotice(n));
|
||||
}
|
||||
|
||||
async function missed() {
|
||||
// A browser that has never been here shows the last day's messages, not
|
||||
// the whole fortnight the log keeps.
|
||||
const since = seen() || new Date(Date.now() - 86400000).toISOString();
|
||||
let list;
|
||||
try {
|
||||
const r = await fetch("/api/notices", { headers: { Accept: "application/json" } });
|
||||
if (!r.ok) return;
|
||||
list = await r.json();
|
||||
} catch (e) { return; }
|
||||
const fresh = list.filter((n) => n.last_at > since);
|
||||
fresh.slice(0, MAX_ON_LOAD).forEach((n) => show(fromNotice(n)));
|
||||
if (fresh.length > MAX_ON_LOAD) {
|
||||
toast.info(`${fresh.length - MAX_ON_LOAD} more messages since your last visit.`,
|
||||
{ link: { label: "all messages", href: "/messages" } });
|
||||
}
|
||||
if (fresh.length) markSeen(fresh[0].last_at);
|
||||
}
|
||||
|
||||
document.addEventListener("app:notice", (e) => onNotice(e.detail));
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Not on Messages: the table is right there, in full, already.
|
||||
if (location.pathname !== "/login" && location.pathname !== "/messages") missed();
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,20 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Account — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Account</h1>
|
||||
|
||||
<p class="lede">One password, the sessions it has opened, and the passkeys registered beside it. There is no user to create and none to delete, because there is one. <code>docs/password-protection.md</code> is the reasoning behind every choice on this page; <code>auth/README.md</code> is how to take the folder into another project.</p>
|
||||
|
||||
<section class="card">
|
||||
{# As on the Jobs and Schedules tabs: the element and its script belong to
|
||||
the module, so this page is two lines and `auth/` owns what they draw.
|
||||
|
||||
It says its own failures in place, beside the button that caused them,
|
||||
and raises `auth-account:error` with the server's `detail` as well. No
|
||||
toast is wired to that here on purpose: one failure said twice is worse
|
||||
than one failure said once, and next to the form is where it belongs. #}
|
||||
<script type="module" src="/_auth/account.js"></script>
|
||||
<auth-account></auth-account>
|
||||
</section>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Agents — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Search agents</h1>
|
||||
<p class="lede">A search agent is a named search: an intent that <code>fit</code> is measured against, gates that require or prefer a column value, and the weights of each term. Saving one rescores it; the Roles tab orders by it when it is picked there.</p>
|
||||
|
||||
<p id="agents-count" class="count" role="status"></p>
|
||||
<ul id="agents-list" class="agents"></ul>
|
||||
|
||||
<form id="agent-form" class="agent-form" autocomplete="off">
|
||||
<h2 id="agent-form-title">New agent</h2>
|
||||
<input type="hidden" id="a-id">
|
||||
<label>Name <input type="text" id="a-name" required></label>
|
||||
<label>Intent <span class="hint">a CV paragraph, or what this search is for</span>
|
||||
<textarea id="a-intent" rows="5"></textarea></label>
|
||||
<label>Gates <span class="hint">JSON: [{"field": "place", "values": ["Berlin"], "mode": "require"}, {"field": "remote", "values": ["remote"], "mode": "prefer", "weight": 0.2}]</span>
|
||||
<textarea id="a-gates" rows="5" spellcheck="false">[]</textarea></label>
|
||||
<fieldset class="weights">
|
||||
<legend>Weights</legend>
|
||||
<label>Fit <input type="number" id="a-fit" min="0" step="0.05" value="0.6"></label>
|
||||
<label>Recency <input type="number" id="a-recency" min="0" step="0.05" value="0.2"></label>
|
||||
<label>Affinity <input type="number" id="a-affinity" min="0" step="0.05" value="0.2"></label>
|
||||
</fieldset>
|
||||
<label class="inline"><input type="checkbox" id="a-enabled" checked> Enabled</label>
|
||||
<div class="agent-actions">
|
||||
<button type="submit">Save and score</button>
|
||||
<button type="button" id="a-new" class="secondary">New</button>
|
||||
<button type="button" id="a-delete" class="secondary" hidden>Delete</button>
|
||||
</div>
|
||||
<p id="agent-status" class="count" role="status"></p>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('roles.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,24 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Applications — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Applications</h1>
|
||||
<p class="lede">Every role saved from the Roles tab, and where it stands. A status change is recorded as an event, which is what days to first screen and conversion are computed from.</p>
|
||||
|
||||
<p id="applications-count" class="count" role="status"></p>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr><th>Role</th><th>Company</th><th>Status</th><th>Next</th></tr>
|
||||
</thead>
|
||||
<tbody id="applications-list"></tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// The tracker's status vocabulary, from the same `STATUSES` tuple the
|
||||
// store validates a status change against; see app/web/pages.py.
|
||||
window.ROLEDESK_STATUSES = {{ status_options | map(attribute=0) | list | tojson }};
|
||||
</script>
|
||||
<script src="{{ asset('roles.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,35 @@
|
||||
{# The frame every page is in. The nav is `TABS` from app/web/pages.py and
|
||||
nothing else: adding a tab is one entry in that list, never a link here. #}
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<title>{% block title %}roledesk{% endblock %}</title>
|
||||
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='2' y='2' width='12' height='12' rx='3' fill='none' stroke='%2314655b' stroke-width='1.8'/%3E%3C/svg%3E">
|
||||
<link rel="stylesheet" href="{{ asset('app.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<header class="top">
|
||||
<a class="brand" href="/">role<span>desk</span></a>
|
||||
<nav>
|
||||
{% for tab in TABS %}
|
||||
<a href="{{ tab.path }}"
|
||||
{% if request.url.path == tab.path %}class="active" aria-current="page"{% endif %}>{{ tab.label }}</a>
|
||||
{% endfor %}
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
|
||||
{# toasts first, and the order is load-bearing: it owns `window.toast`, which
|
||||
app.js calls on a failed fetch and live.js feeds server notices into, and
|
||||
`window.esc`, which every page script below builds its HTML with. #}
|
||||
<script src="{{ asset('toasts.js') }}"></script>
|
||||
<script src="{{ asset('app.js') }}"></script>
|
||||
<script src="{{ asset('live.js') }}"></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,30 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Companies — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Companies</h1>
|
||||
<p class="lede">Every company whose board is read, with how many of its roles are open. Affinity: <strong>M</strong>ute hides its roles and leaves them unscored, <strong>N</strong>eutral is the default, <strong>L</strong>ike raises the affinity term, <strong>F</strong>avourite skips the gates and floors the score at 0.9.</p>
|
||||
|
||||
<form class="filters" autocomplete="off" onsubmit="return false">
|
||||
<input type="search" id="c-q" placeholder="Filter by name or board" aria-label="Filter companies">
|
||||
<select id="c-affinity" aria-label="Affinity">
|
||||
<option value="">Any affinity</option>
|
||||
<option value="2">Favourite</option>
|
||||
<option value="1">Like</option>
|
||||
<option value="0">Neutral</option>
|
||||
<option value="-1">Mute</option>
|
||||
</select>
|
||||
</form>
|
||||
|
||||
<p id="companies-count" class="count" role="status"></p>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr><th>Company</th><th>Board</th><th class="num">Open roles</th><th>Affinity</th></tr>
|
||||
</thead>
|
||||
<tbody id="companies-list"></tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('roles.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}{{ status }} — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ status }}</h1>
|
||||
|
||||
{# The server's own sentence, the same one `/api` callers get as `detail`.
|
||||
Two wordings for one failure is how a page ends up telling you something
|
||||
the API does not. #}
|
||||
<p class="lede">{{ detail }}</p>
|
||||
|
||||
<p><a href="/">Back to the roles</a>, or <a href="/messages">see what the server has been saying</a>.</p>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,33 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Jobs — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Jobs</h1>
|
||||
|
||||
<p class="lede"><strong>pull</strong> runs the whole chain: every board, then extract, embed and score. <strong>extract</strong>, <strong>embed</strong> and <strong>score</strong> run one stage on their own. The buttons come from <code>/api/jobs/kinds</code>, so a new <code>@job</code> under <code>app/jobs/</code> appears here without an edit.</p>
|
||||
|
||||
<section class="card">
|
||||
<h2>Start something</h2>
|
||||
<div id="kinds" class="buttons">
|
||||
<span class="muted">loading the job kinds…</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
{# The queue's own element, served by its own router. Two lines, and the
|
||||
module owns what they draw — see pipeline/web/static/jobs.js.
|
||||
|
||||
The heading is the app's, because the element takes up no space while
|
||||
nothing is running — that is its `idle="hide"` default, and a strip that
|
||||
is always there is furniture — and a card with nothing in it and nothing
|
||||
above it reads as something that failed to load. #}
|
||||
<h2>What is running</h2>
|
||||
<p class="muted small" id="idle">Nothing at the moment. Press one of the buttons above.</p>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('jobs.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,20 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Messages — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Messages</h1>
|
||||
|
||||
<p class="lede">Everything the server has said that nobody has cleared, newest first. A toast fades and is raised as often as not while no tab is open; this is where it is found again, with its fix, its raw error, and how many times it has been said. A row goes when you clear it, or a fortnight after it was last said.</p>
|
||||
|
||||
<section class="card">
|
||||
<div class="row-between">
|
||||
<h2>The log</h2>
|
||||
<button type="button" id="clear-all" class="secondary">Clear all</button>
|
||||
</div>
|
||||
<div id="notices"><span class="muted">loading…</span></div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('messages.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,67 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Roles — roledesk{% endblock %}
|
||||
|
||||
{# An empty shell: `static/roles.js` fills it and drives every action. The
|
||||
server renders only the select options, from `app.models` and
|
||||
`plugins.ats.FUNCTIONS`, so they cannot drift from what the store accepts. #}
|
||||
{% block content %}
|
||||
<form id="filters" class="filters" autocomplete="off">
|
||||
<select id="f-agent" aria-label="Order">
|
||||
<option value="">Newest</option>
|
||||
</select>
|
||||
<input type="search" id="f-q" placeholder="Search titles" aria-label="Search titles">
|
||||
<input type="text" id="f-company" placeholder="Company" aria-label="Company">
|
||||
<input type="text" id="f-place" placeholder="Place" aria-label="Place">
|
||||
<select id="f-function" aria-label="Function">
|
||||
<option value="">Any function</option>
|
||||
{% for value, label in functions %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-remote" aria-label="Remote">
|
||||
<option value="">Any remote</option>
|
||||
{% for value, label in remote_options %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-days" aria-label="New in">
|
||||
<option value="">Any time</option>
|
||||
<option value="1">New in 1 day</option>
|
||||
<option value="3">New in 3 days</option>
|
||||
<option value="7">New in 7 days</option>
|
||||
<option value="30">New in 30 days</option>
|
||||
</select>
|
||||
<label class="check">
|
||||
<input type="checkbox" id="f-show-muted"> Show muted
|
||||
</label>
|
||||
<label class="check" id="show-gated" hidden>
|
||||
<input type="checkbox" id="f-gated"> Show gated
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<p id="roles-count" class="count" role="status"></p>
|
||||
<ul id="roles-list" class="roles"></ul>
|
||||
|
||||
<template id="role-row">
|
||||
<li class="role">
|
||||
<div class="role-main">
|
||||
<a class="role-title" target="_blank" rel="noopener"></a>
|
||||
<span class="role-company"></span>
|
||||
<span class="affinity" role="group"></span>
|
||||
</div>
|
||||
<div class="role-meta">
|
||||
<span class="role-place"></span>
|
||||
<span class="role-remote badge"></span>
|
||||
<span class="role-function badge"></span>
|
||||
<span class="role-score badge"></span>
|
||||
<span class="role-gated"></span>
|
||||
<span class="role-age"></span>
|
||||
</div>
|
||||
<button type="button" class="save"></button>
|
||||
</li>
|
||||
</template>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="{{ asset('roles.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,15 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Schedules — roledesk{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Schedules</h1>
|
||||
|
||||
<p class="lede">A schedule enqueues a job kind on a cadence: <code>every 15m</code>, <code>every 6h</code>, <code>every 2d</code>, <code>daily at 06:00</code> or <code>weekly mon 07:00</code>, the clock ones read in <code>timezone</code> from <code>config.yaml</code>. The default, <code>pull</code> every 6h, is declared next to the <code>pull</code> job in <code>app/jobs/cascade.py</code>. It is a starting point: a cadence edited here, or a schedule switched off, survives restarts and deploys.</p>
|
||||
|
||||
<section class="card">
|
||||
{# The element and its script are the scheduler's own, served by its own
|
||||
router — see pipeline/web/static/schedules.js. Two lines, as with jobs. #}
|
||||
<script type="module" src="/_jobs/schedules.js"></script>
|
||||
<desk-schedules></desk-schedules>
|
||||
</section>
|
||||
{% endblock %}
|
||||
+7
-3
@@ -1,7 +1,11 @@
|
||||
"""The web face. One door: `create_app` and `serve`."""
|
||||
"""The web face: the tabs, the JSON routes behind them, and the Jinja
|
||||
environment. The queue brings its own routes and elements (`pipeline.web`),
|
||||
auth the login page and `<auth-account>` (`auth`); `app.main` puts them
|
||||
together. One door for all of it."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.web.app import create_app, serve
|
||||
from app.web.api import router as api_router
|
||||
from app.web.pages import STATIC_DIR, TABS, router as pages_router, templates
|
||||
|
||||
__all__ = ["create_app", "serve"]
|
||||
__all__ = ["STATIC_DIR", "TABS", "api_router", "pages_router", "templates"]
|
||||
+5
-3
@@ -1,7 +1,9 @@
|
||||
"""The JSON routes the page uses: roles, companies, applications, agents.
|
||||
"""The JSON routes the tabs use: roles, companies, applications, agents.
|
||||
|
||||
`/api/jobs*`, `/_jobs/jobs.js` and `/ws/jobs` are `pipeline.web`'s, mounted by
|
||||
`connect` in `app.py`. This is roledesk's own API, over the same store.
|
||||
`/api/jobs*`, `/api/schedules*`, `/api/notices` and `/ws/jobs` are
|
||||
`pipeline.web`'s and `/api/account*` is `auth`'s, both wired in `app/main.py`.
|
||||
This is roledesk's own API, over the same store. Every refusal is
|
||||
`{"detail": "<sentence>"}`, which `api()` in `static/app.js` turns into a toast.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
"""The application factory: the queue's routes and socket from
|
||||
`pipeline.web.connect`, roledesk's own JSON API, and the one page."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from pipeline import Jobs
|
||||
from pipeline.web import connect
|
||||
from app import config as config_mod
|
||||
from app import jobs
|
||||
from app.storage import Store
|
||||
from app.web.api import router as api_router
|
||||
from app.web.pages import router as pages_router
|
||||
|
||||
WEB = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def create_app(config_path: str | None = None) -> FastAPI:
|
||||
config = config_mod.load(config_path)
|
||||
# `Store` first, so the file is at the current schema before the queue
|
||||
# adds its own table to it.
|
||||
store = Store(config.database)
|
||||
jobs.seed_agents(config, store)
|
||||
app = FastAPI(title="roledesk", docs_url="/api/docs")
|
||||
connect(app, Jobs(config.database), config, store,
|
||||
workers=config.workers.model_dump(),
|
||||
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=config.path or "")
|
||||
app.state.config = config
|
||||
app.state.store = store
|
||||
app.include_router(api_router)
|
||||
app.include_router(pages_router)
|
||||
app.mount("/static", StaticFiles(directory=WEB / "static"), name="static")
|
||||
return app
|
||||
|
||||
|
||||
def serve(host: str, port: int, config_path: str | None) -> int:
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(create_app(config_path), host=host, port=port)
|
||||
return 0
|
||||
+99
-19
@@ -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")
|
||||
@@ -1,227 +0,0 @@
|
||||
/* roledesk — an alpha to look at real ads, not the final reader. The palette
|
||||
and type stack borrow newsdesk's visual language (news/newsdesk/web/static
|
||||
/app.css): a quiet UI face and a teal signal colour, nothing ported beyond
|
||||
that — no reader, no auth, no passkeys. */
|
||||
|
||||
:root {
|
||||
--bg: #eceff1;
|
||||
--panel: #ffffff;
|
||||
--ink: #1a2027;
|
||||
--muted: #505c67;
|
||||
--faint: #6d7883;
|
||||
--rule: #d6dbdf;
|
||||
--signal: #14655b;
|
||||
--signal-weak: #a9c4bf;
|
||||
--mute: #96382c;
|
||||
--focus: #1b4f8f;
|
||||
|
||||
--ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto,
|
||||
"Helvetica Neue", Arial, sans-serif;
|
||||
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #14181c;
|
||||
--panel: #1b2126;
|
||||
--ink: #e3e7ea;
|
||||
--muted: #a8b2ba;
|
||||
--faint: #8b959d;
|
||||
--rule: #2a3238;
|
||||
--signal: #4fb3a3;
|
||||
--signal-weak: #35544f;
|
||||
--mute: #cd6a5b;
|
||||
--focus: #6ea8e8;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body { max-width: 100%; overflow-x: hidden; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: var(--ui);
|
||||
line-height: 1.45;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
button, input, select { font: inherit; color: inherit; }
|
||||
|
||||
a { color: var(--signal); }
|
||||
|
||||
/* ---------------------------------------------------------------- chrome */
|
||||
|
||||
header {
|
||||
position: sticky; top: 0; z-index: 10;
|
||||
display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
|
||||
padding: .7rem 1rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.wordmark { font-weight: 640; letter-spacing: -.01em; font-size: 1.1rem; }
|
||||
.wordmark span { color: var(--signal); }
|
||||
|
||||
.tabs { display: flex; gap: .25rem; }
|
||||
|
||||
.tab {
|
||||
background: none; border: 1px solid transparent; border-radius: .3rem;
|
||||
padding: .35rem .75rem; cursor: pointer; color: var(--muted);
|
||||
}
|
||||
.tab[aria-pressed="true"] { color: var(--ink); background: var(--bg); border-color: var(--rule); }
|
||||
|
||||
/* --------------------------------------------------------------- filters */
|
||||
|
||||
.filters {
|
||||
display: flex; flex-wrap: wrap; gap: .5rem;
|
||||
padding: .75rem 1rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.filters input[type="search"], .filters input[type="text"], .filters select {
|
||||
padding: .4rem .55rem;
|
||||
border: 1px solid var(--rule); border-radius: .3rem;
|
||||
background: var(--bg); color: var(--ink);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filters input[type="search"] { flex: 1 1 12rem; }
|
||||
.filters input[type="text"] { flex: 1 1 8rem; }
|
||||
|
||||
.show-muted {
|
||||
display: flex; align-items: center; gap: .35rem;
|
||||
color: var(--muted); font-size: .9rem; white-space: nowrap;
|
||||
}
|
||||
|
||||
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
|
||||
outline: 2px solid var(--focus); outline-offset: 1px;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ views */
|
||||
|
||||
.view { padding: 0 1rem 1.5rem; }
|
||||
|
||||
.count { color: var(--faint); font-size: .85rem; margin: .75rem 0 .5rem; }
|
||||
|
||||
/* ------------------------------------------------------------------- roles */
|
||||
|
||||
.roles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
|
||||
|
||||
.role {
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: .5rem;
|
||||
padding: .6rem .8rem;
|
||||
display: flex; flex-direction: column; gap: .35rem;
|
||||
}
|
||||
|
||||
.role-main {
|
||||
display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem;
|
||||
}
|
||||
|
||||
.role-title { font-weight: 600; text-decoration: none; }
|
||||
.role-title:hover { text-decoration: underline; }
|
||||
|
||||
.role-company { color: var(--muted); }
|
||||
|
||||
.role-meta {
|
||||
display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
|
||||
color: var(--faint); font-size: .85rem;
|
||||
}
|
||||
|
||||
.badge {
|
||||
border: 1px solid var(--rule); border-radius: 1rem;
|
||||
padding: .05rem .55rem; font-size: .78rem;
|
||||
}
|
||||
.role-remote.badge:empty, .role-function.badge:empty { display: none; }
|
||||
|
||||
.role-age { margin-left: auto; }
|
||||
|
||||
.affinity { display: inline-flex; gap: .15rem; margin-left: auto; }
|
||||
.affinity button {
|
||||
background: none; border: 1px solid var(--rule); border-radius: .3rem;
|
||||
padding: .1rem .4rem; cursor: pointer; color: var(--muted); font-size: .85rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.affinity button[aria-pressed="true"] { color: #fff; background: var(--signal); border-color: var(--signal); }
|
||||
.affinity button[data-value="-1"][aria-pressed="true"] { background: var(--mute); border-color: var(--mute); }
|
||||
|
||||
.save {
|
||||
align-self: flex-start;
|
||||
background: var(--signal); color: #fff; border: 1px solid var(--signal);
|
||||
border-radius: .3rem; padding: .3rem .8rem; cursor: pointer; font-weight: 600;
|
||||
}
|
||||
.save[disabled] {
|
||||
background: var(--bg); color: var(--muted); border-color: var(--rule); cursor: default;
|
||||
}
|
||||
|
||||
.role.muted { opacity: .55; }
|
||||
.role.gated { opacity: .7; }
|
||||
.show-muted[hidden] { display: none; }
|
||||
.role-score.badge:empty { display: none; }
|
||||
.role-score.badge { color: var(--signal); border-color: var(--signal-weak); font-variant-numeric: tabular-nums; }
|
||||
.role-gated { color: var(--mute); font-size: .85rem; }
|
||||
|
||||
/* ---------------------------------------------------------------- agents */
|
||||
|
||||
.agents { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
|
||||
.agent {
|
||||
display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .5rem .75rem;
|
||||
}
|
||||
.agent-meta { color: var(--faint); font-size: .85rem; flex: 1 1 12rem; }
|
||||
.agent-form {
|
||||
display: flex; flex-direction: column; gap: .6rem; max-width: 44rem;
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .75rem 1rem;
|
||||
}
|
||||
.agent-form h2 { font-size: 1rem; margin: 0; }
|
||||
.agent-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
|
||||
.agent-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
|
||||
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"] {
|
||||
font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--rule);
|
||||
border-radius: 4px; padding: .35rem .5rem; width: 100%;
|
||||
}
|
||||
.agent-form textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85rem; }
|
||||
.agent-form .hint { color: var(--faint); font-size: .8rem; overflow-wrap: anywhere; }
|
||||
.weights { display: flex; gap: .75rem; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 4px; }
|
||||
.weights label { flex: 1 1 6rem; }
|
||||
.agent-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
|
||||
.agent-actions button, .agent button {
|
||||
background: var(--bg); border: 1px solid var(--rule); border-radius: 4px; padding: .3rem .8rem; cursor: pointer;
|
||||
}
|
||||
.agent-actions button.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
|
||||
|
||||
/* ------------------------------------------------------------ applications */
|
||||
|
||||
.applications { width: 100%; border-collapse: collapse; background: var(--panel); }
|
||||
.applications th, .applications td {
|
||||
text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--rule);
|
||||
font-size: .9rem;
|
||||
}
|
||||
.applications select { padding: .25rem .4rem; }
|
||||
|
||||
/* Below tablet width, a table stops being a table: each row becomes a card,
|
||||
its cells stacked, so nothing scrolls sideways to be read. */
|
||||
@media (max-width: 640px) {
|
||||
.applications thead { display: none; }
|
||||
.applications, .applications tbody, .applications tr, .applications td { display: block; width: 100%; }
|
||||
.applications tr { margin-bottom: .6rem; border: 1px solid var(--rule); border-radius: .4rem; }
|
||||
.applications td { border-bottom: none; }
|
||||
.applications td::before {
|
||||
content: attr(data-label);
|
||||
display: block; font-size: .72rem; color: var(--faint); margin-bottom: .1rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- jobs */
|
||||
|
||||
#jobs { padding: 1rem; border-top: 1px solid var(--rule); }
|
||||
#jobs h2 { font-size: .95rem; color: var(--muted); margin: 0 0 .6rem; }
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.role-age { margin-left: 0; }
|
||||
.affinity { margin-left: 0; }
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
// roledesk's page: the filter bar, the role list, the tracker, the search
|
||||
// agents, and the tab switch between them. The template renders an empty shell (see index.html);
|
||||
// everything on screen comes from the API, and every action — Save, an
|
||||
// affinity click, a status change — is a fetch from here, not a form post.
|
||||
"use strict";
|
||||
|
||||
const ROLES_URL = "/api/roles";
|
||||
|
||||
/** @type {Map<string, object>} company_key -> company row from /api/companies */
|
||||
let companies = new Map();
|
||||
/** @type {Map<string, object>} role_uid -> application row, for roles that are already tracked */
|
||||
let trackedByRole = new Map();
|
||||
/** @type {object[]} the last /api/roles response, already muted-filtered by the server */
|
||||
let roles = [];
|
||||
/** @type {object[]} every search agent, from /api/agents */
|
||||
let agents = [];
|
||||
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
|
||||
|
||||
function debounce(fn, ms) {
|
||||
let timer;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => fn(...args), ms);
|
||||
};
|
||||
}
|
||||
|
||||
async function api(path, options) {
|
||||
const res = await fetch(path, options);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.detail || `${path}: ${res.status}`);
|
||||
}
|
||||
return res.status === 204 ? null : res.json();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ tabs
|
||||
|
||||
function initTabs() {
|
||||
$$(".tab").forEach((tab) => {
|
||||
tab.addEventListener("click", () => {
|
||||
$$(".tab").forEach((t) => t.setAttribute("aria-pressed", String(t === tab)));
|
||||
const name = tab.dataset.tab;
|
||||
$("#roles-view").hidden = name !== "roles";
|
||||
$("#applications-view").hidden = name !== "applications";
|
||||
$("#agents-view").hidden = name !== "agents";
|
||||
if (name === "applications") loadApplications();
|
||||
if (name === "agents") loadAgents();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- roles
|
||||
|
||||
function filterParams() {
|
||||
const params = new URLSearchParams();
|
||||
const q = $("#f-q").value.trim();
|
||||
const company = $("#f-company").value.trim();
|
||||
const place = $("#f-place").value.trim();
|
||||
const fn = $("#f-function").value;
|
||||
const remote = $("#f-remote").value;
|
||||
const days = $("#f-days").value;
|
||||
if (q) params.set("q", q);
|
||||
if (company) params.set("company", company);
|
||||
if (place) params.set("place", place);
|
||||
if (fn) params.set("function", fn);
|
||||
if (remote) params.set("remote", remote);
|
||||
if (days) params.set("days", days);
|
||||
if ($("#f-show-muted").checked) params.set("show_muted", "true");
|
||||
const agent = $("#f-agent").value;
|
||||
if (agent) {
|
||||
params.set("agent", agent);
|
||||
if ($("#f-gated").checked) params.set("gated", "1");
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
async function loadRoles() {
|
||||
const params = filterParams();
|
||||
roles = await api(`${ROLES_URL}?${params.toString()}`);
|
||||
renderRoles();
|
||||
}
|
||||
|
||||
function relativeAge(iso) {
|
||||
const then = new Date(iso);
|
||||
const minutes = Math.max(0, Math.floor((Date.now() - then.getTime()) / 60000));
|
||||
if (minutes < 60) return `${minutes} min ago`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours} h ago`;
|
||||
const days = Math.floor(hours / 24);
|
||||
return `${days} d ago`;
|
||||
}
|
||||
|
||||
function renderRoles() {
|
||||
const list = $("#roles-list");
|
||||
const template = $("#role-row");
|
||||
list.replaceChildren();
|
||||
|
||||
for (const role of roles) {
|
||||
const node = template.content.cloneNode(true);
|
||||
const li = node.querySelector(".role");
|
||||
const company = companies.get(role.company_key);
|
||||
|
||||
if (company && company.affinity === -1) li.classList.add("muted");
|
||||
|
||||
const titleLink = node.querySelector(".role-title");
|
||||
titleLink.textContent = role.title || "(untitled)";
|
||||
titleLink.href = role.original_url || "#";
|
||||
|
||||
node.querySelector(".role-company").textContent = role.company || "";
|
||||
node.querySelector(".role-place").textContent = role.place || "";
|
||||
node.querySelector(".role-remote").textContent = role.remote || "";
|
||||
node.querySelector(".role-function").textContent = role.function || "";
|
||||
node.querySelector(".role-age").textContent = relativeAge(role.first_seen);
|
||||
if (role.score !== null && role.score !== undefined) {
|
||||
const badge = node.querySelector(".role-score");
|
||||
badge.textContent = role.gated_reason ? "gated" : role.score.toFixed(2);
|
||||
badge.title = "Score for the selected agent";
|
||||
node.querySelector(".role-gated").textContent = role.gated_reason || "";
|
||||
if (role.gated_reason) li.classList.add("gated");
|
||||
}
|
||||
|
||||
node.querySelector(".affinity").replaceWith(
|
||||
affinityControl(role.company_key, company ? company.affinity : 0));
|
||||
|
||||
const saveButton = node.querySelector(".save");
|
||||
setSaveButton(saveButton, role.uid);
|
||||
saveButton.addEventListener("click", () => saveRole(role.uid, saveButton));
|
||||
|
||||
list.appendChild(node);
|
||||
}
|
||||
|
||||
$("#roles-count").textContent = `${roles.length} role${roles.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
function setSaveButton(button, uid) {
|
||||
const saved = trackedByRole.has(uid);
|
||||
button.textContent = saved ? "Saved" : "Save";
|
||||
button.disabled = saved;
|
||||
}
|
||||
|
||||
async function saveRole(uid, button) {
|
||||
button.disabled = true;
|
||||
button.textContent = "Saving…";
|
||||
try {
|
||||
const application = await api("/api/applications", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ role_uid: uid, status: "saved" }),
|
||||
});
|
||||
trackedByRole.set(uid, application);
|
||||
setSaveButton(button, uid);
|
||||
} catch (err) {
|
||||
button.disabled = false;
|
||||
button.textContent = "Save";
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- affinity
|
||||
|
||||
const AFFINITY_LEVELS = [
|
||||
{ value: -1, label: "Mute" },
|
||||
{ value: 0, label: "Neutral" },
|
||||
{ value: 1, label: "Like" },
|
||||
{ value: 2, label: "Favourite" },
|
||||
];
|
||||
|
||||
function affinityControl(companyKey, current) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
span.setAttribute("aria-label", "Company affinity");
|
||||
for (const level of AFFINITY_LEVELS) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.dataset.value = String(level.value);
|
||||
button.textContent = level.label[0];
|
||||
button.title = level.label;
|
||||
button.setAttribute("aria-label", level.label);
|
||||
button.setAttribute("aria-pressed", String(level.value === current));
|
||||
button.addEventListener("click", () => setAffinity(companyKey, level.value));
|
||||
span.appendChild(button);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
async function setAffinity(companyKey, affinity) {
|
||||
if (!companyKey) return;
|
||||
try {
|
||||
const updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ affinity }),
|
||||
});
|
||||
const company = companies.get(companyKey);
|
||||
if (company) company.affinity = updated.affinity;
|
||||
// Muting or unmuting changes which roles the server hands back, so the
|
||||
// list is refetched rather than just re-rendered from what is on hand.
|
||||
await loadRoles();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ applications
|
||||
|
||||
// `ROLEDESK_STATUSES` is set by index.html from the same `STATUSES` tuple
|
||||
// the store validates against, so this list can never drift from what a
|
||||
// `POST .../status` will actually accept.
|
||||
function statusSelect(current) {
|
||||
const select = document.createElement("select");
|
||||
for (const status of window.ROLEDESK_STATUSES) {
|
||||
const option = document.createElement("option");
|
||||
option.value = status;
|
||||
option.textContent = status[0].toUpperCase() + status.slice(1);
|
||||
option.selected = status === current;
|
||||
select.appendChild(option);
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
async function loadApplications() {
|
||||
const applications = await api("/api/applications");
|
||||
trackedByRole = new Map(applications.filter((a) => a.role_uid).map((a) => [a.role_uid, a]));
|
||||
renderApplications(applications);
|
||||
}
|
||||
|
||||
function renderApplications(applications) {
|
||||
const body = $("#applications-list");
|
||||
body.replaceChildren();
|
||||
for (const application of applications) {
|
||||
const tr = document.createElement("tr");
|
||||
|
||||
const roleTd = document.createElement("td");
|
||||
roleTd.dataset.label = "Role";
|
||||
roleTd.textContent = application.role_title || "(untitled)";
|
||||
tr.appendChild(roleTd);
|
||||
|
||||
const companyTd = document.createElement("td");
|
||||
companyTd.dataset.label = "Company";
|
||||
const company = companies.get(application.company_key);
|
||||
companyTd.textContent = company ? company.name : application.company_key;
|
||||
tr.appendChild(companyTd);
|
||||
|
||||
const statusTd = document.createElement("td");
|
||||
statusTd.dataset.label = "Status";
|
||||
const select = statusSelect(application.status);
|
||||
select.addEventListener("change", () => setStatus(application.id, select.value));
|
||||
statusTd.appendChild(select);
|
||||
tr.appendChild(statusTd);
|
||||
|
||||
const nextTd = document.createElement("td");
|
||||
nextTd.dataset.label = "Next";
|
||||
nextTd.textContent = [application.next_action, application.next_date]
|
||||
.filter(Boolean).join(" · ");
|
||||
tr.appendChild(nextTd);
|
||||
|
||||
body.appendChild(tr);
|
||||
}
|
||||
$("#applications-count").textContent =
|
||||
`${applications.length} tracked application${applications.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
async function setStatus(id, status) {
|
||||
try {
|
||||
await api(`/api/applications/${encodeURIComponent(id)}/status`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
await loadApplications();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- agents
|
||||
|
||||
async function loadAgents() {
|
||||
agents = await api("/api/agents");
|
||||
renderAgentSelect();
|
||||
renderAgents();
|
||||
}
|
||||
|
||||
// The filter bar's order: "Newest", or one agent's score. Keeps the current
|
||||
// choice when the list is refreshed, unless that agent is gone.
|
||||
function renderAgentSelect() {
|
||||
const select = $("#f-agent");
|
||||
const current = select.value;
|
||||
select.replaceChildren(new Option("Newest", ""));
|
||||
for (const agent of agents) {
|
||||
const label = agent.enabled ? agent.name : `${agent.name} (off)`;
|
||||
select.appendChild(new Option(label, String(agent.id)));
|
||||
}
|
||||
select.value = agents.some((a) => String(a.id) === current) ? current : "";
|
||||
$("#show-gated").hidden = !select.value;
|
||||
}
|
||||
|
||||
function renderAgents() {
|
||||
const list = $("#agents-list");
|
||||
list.replaceChildren();
|
||||
for (const agent of agents) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "agent";
|
||||
const name = document.createElement("strong");
|
||||
name.textContent = agent.name;
|
||||
const meta = document.createElement("span");
|
||||
meta.className = "agent-meta";
|
||||
const gates = agent.gates.map((g) => `${g.mode} ${g.field}`).join(", ") || "no gates";
|
||||
meta.textContent = `${agent.enabled ? "" : "off · "}${gates}`;
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button";
|
||||
edit.textContent = "Edit";
|
||||
edit.addEventListener("click", () => fillAgentForm(agent));
|
||||
li.append(name, meta, edit);
|
||||
list.appendChild(li);
|
||||
}
|
||||
$("#agents-count").textContent = `${agents.length} agent${agents.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
function fillAgentForm(agent) {
|
||||
$("#agent-form-title").textContent = agent ? `Edit ${agent.name}` : "New agent";
|
||||
$("#a-id").value = agent ? String(agent.id) : "";
|
||||
$("#a-name").value = agent ? agent.name : "";
|
||||
$("#a-intent").value = agent ? agent.intent : "";
|
||||
$("#a-gates").value = JSON.stringify(agent ? agent.gates : [], null, 2);
|
||||
const weights = agent ? agent.weights : { fit: 0.6, recency: 0.2, affinity: 0.2 };
|
||||
$("#a-fit").value = weights.fit;
|
||||
$("#a-recency").value = weights.recency;
|
||||
$("#a-affinity").value = weights.affinity;
|
||||
$("#a-enabled").checked = agent ? agent.enabled : true;
|
||||
$("#a-delete").hidden = !agent;
|
||||
$("#agent-status").textContent = "";
|
||||
}
|
||||
|
||||
async function saveAgent(event) {
|
||||
event.preventDefault();
|
||||
const status = $("#agent-status");
|
||||
let gates;
|
||||
try {
|
||||
gates = JSON.parse($("#a-gates").value || "[]");
|
||||
} catch (err) {
|
||||
status.textContent = `Gates are not valid JSON: ${err.message}`;
|
||||
return;
|
||||
}
|
||||
const id = $("#a-id").value;
|
||||
const body = {
|
||||
name: $("#a-name").value.trim(),
|
||||
intent: $("#a-intent").value,
|
||||
gates,
|
||||
weights: {
|
||||
fit: Number($("#a-fit").value),
|
||||
recency: Number($("#a-recency").value),
|
||||
affinity: Number($("#a-affinity").value),
|
||||
},
|
||||
enabled: $("#a-enabled").checked,
|
||||
};
|
||||
if (id) body.id = Number(id);
|
||||
try {
|
||||
const saved = await api("/api/agents", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
await loadAgents();
|
||||
fillAgentForm(saved);
|
||||
await rescore(status);
|
||||
} catch (err) {
|
||||
status.textContent = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteAgent() {
|
||||
const id = $("#a-id").value;
|
||||
if (!id || !confirm("Delete this agent and its scores?")) return;
|
||||
try {
|
||||
await api(`/api/agents/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
fillAgentForm(null);
|
||||
await loadAgents();
|
||||
await loadRoles();
|
||||
} catch (err) {
|
||||
$("#agent-status").textContent = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the `score` job and refetch the roles once it has finished, so the
|
||||
// order on the Roles tab is the saved agent's.
|
||||
async function rescore(status) {
|
||||
status.textContent = "Saved. Scoring…";
|
||||
const job = await api("/api/jobs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ kind: "score", payload: {} }),
|
||||
});
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const snapshot = await api("/api/jobs");
|
||||
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
|
||||
if (!busy) {
|
||||
const done = snapshot.recent.find((j) => j.id === job.id);
|
||||
status.textContent = done && done.state !== "done"
|
||||
? `Scoring ${done.state}: ${done.error || ""}`
|
||||
: "Saved and scored.";
|
||||
await loadRoles();
|
||||
return;
|
||||
}
|
||||
}
|
||||
status.textContent = "Saved. Scoring is still running; see Jobs below.";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
async function loadCompanies() {
|
||||
const rows = await api("/api/companies");
|
||||
companies = new Map(rows.map((c) => [c.key, c]));
|
||||
}
|
||||
|
||||
async function init() {
|
||||
initTabs();
|
||||
await Promise.all([loadCompanies(), loadApplications(), loadAgents()]);
|
||||
await loadRoles();
|
||||
|
||||
const refetch = debounce(loadRoles, 300);
|
||||
$("#f-q").addEventListener("input", refetch);
|
||||
$("#f-company").addEventListener("input", refetch);
|
||||
$("#f-place").addEventListener("input", refetch);
|
||||
$("#f-function").addEventListener("change", loadRoles);
|
||||
$("#f-remote").addEventListener("change", loadRoles);
|
||||
$("#f-days").addEventListener("change", loadRoles);
|
||||
$("#f-show-muted").addEventListener("change", loadRoles);
|
||||
$("#f-agent").addEventListener("change", () => {
|
||||
$("#show-gated").hidden = !$("#f-agent").value;
|
||||
loadRoles();
|
||||
});
|
||||
$("#f-gated").addEventListener("change", loadRoles);
|
||||
$("#agent-form").addEventListener("submit", saveAgent);
|
||||
$("#a-new").addEventListener("click", () => fillAgentForm(null));
|
||||
$("#a-delete").addEventListener("click", deleteAgent);
|
||||
$("#filters").addEventListener("submit", (e) => e.preventDefault());
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
@@ -1,128 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>roledesk</title>
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<span class="wordmark">role<span>desk</span></span>
|
||||
<nav class="tabs" id="tabs">
|
||||
<button type="button" class="tab" data-tab="roles" aria-pressed="true">Roles</button>
|
||||
<button type="button" class="tab" data-tab="applications" aria-pressed="false">Applications</button>
|
||||
<button type="button" class="tab" data-tab="agents" aria-pressed="false">Agents</button>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<section id="roles-view" class="view">
|
||||
<form id="filters" class="filters" autocomplete="off">
|
||||
<select id="f-agent" aria-label="Order">
|
||||
<option value="">Newest</option>
|
||||
</select>
|
||||
<input type="search" id="f-q" placeholder="Search titles" aria-label="Search titles">
|
||||
<input type="text" id="f-company" placeholder="Company" aria-label="Company">
|
||||
<input type="text" id="f-place" placeholder="Place" aria-label="Place">
|
||||
<select id="f-function" aria-label="Function">
|
||||
<option value="">Any function</option>
|
||||
{% for value, label in functions %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-remote" aria-label="Remote">
|
||||
<option value="">Any remote</option>
|
||||
{% for value, label in remote_options %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-days" aria-label="New in">
|
||||
<option value="">Any time</option>
|
||||
<option value="1">New in 1 day</option>
|
||||
<option value="3">New in 3 days</option>
|
||||
<option value="7">New in 7 days</option>
|
||||
<option value="30">New in 30 days</option>
|
||||
</select>
|
||||
<label class="show-muted">
|
||||
<input type="checkbox" id="f-show-muted"> Show muted
|
||||
</label>
|
||||
<label class="show-muted" id="show-gated" hidden>
|
||||
<input type="checkbox" id="f-gated"> Show gated
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<p id="roles-count" class="count" role="status"></p>
|
||||
<ul id="roles-list" class="roles"></ul>
|
||||
</section>
|
||||
|
||||
<section id="applications-view" class="view" hidden>
|
||||
<p id="applications-count" class="count" role="status"></p>
|
||||
<table class="applications">
|
||||
<thead>
|
||||
<tr><th>Role</th><th>Company</th><th>Status</th><th>Next</th></tr>
|
||||
</thead>
|
||||
<tbody id="applications-list"></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section id="agents-view" class="view" hidden>
|
||||
<p id="agents-count" class="count" role="status"></p>
|
||||
<ul id="agents-list" class="agents"></ul>
|
||||
<form id="agent-form" class="agent-form" autocomplete="off">
|
||||
<h2 id="agent-form-title">New agent</h2>
|
||||
<input type="hidden" id="a-id">
|
||||
<label>Name <input type="text" id="a-name" required></label>
|
||||
<label>Intent <span class="hint">a CV paragraph, or what this search is for</span>
|
||||
<textarea id="a-intent" rows="5"></textarea></label>
|
||||
<label>Gates <span class="hint">JSON: [{"field": "place", "values": ["Berlin"], "mode": "require"}, {"field": "remote", "values": ["remote"], "mode": "prefer", "weight": 0.2}]</span>
|
||||
<textarea id="a-gates" rows="5" spellcheck="false">[]</textarea></label>
|
||||
<fieldset class="weights">
|
||||
<legend>Weights</legend>
|
||||
<label>Fit <input type="number" id="a-fit" min="0" step="0.05" value="0.6"></label>
|
||||
<label>Recency <input type="number" id="a-recency" min="0" step="0.05" value="0.2"></label>
|
||||
<label>Affinity <input type="number" id="a-affinity" min="0" step="0.05" value="0.2"></label>
|
||||
</fieldset>
|
||||
<label class="inline"><input type="checkbox" id="a-enabled" checked> Enabled</label>
|
||||
<div class="agent-actions">
|
||||
<button type="submit" class="primary">Save and score</button>
|
||||
<button type="button" id="a-new">New</button>
|
||||
<button type="button" id="a-delete" hidden>Delete</button>
|
||||
</div>
|
||||
<p id="agent-status" class="count" role="status"></p>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section id="jobs">
|
||||
<h2>Jobs</h2>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
</section>
|
||||
|
||||
<template id="role-row">
|
||||
<li class="role">
|
||||
<div class="role-main">
|
||||
<a class="role-title" target="_blank" rel="noopener"></a>
|
||||
<span class="role-company"></span>
|
||||
<span class="affinity" role="group"></span>
|
||||
</div>
|
||||
<div class="role-meta">
|
||||
<span class="role-place"></span>
|
||||
<span class="role-remote badge"></span>
|
||||
<span class="role-function badge"></span>
|
||||
<span class="role-score badge"></span>
|
||||
<span class="role-gated"></span>
|
||||
<span class="role-age"></span>
|
||||
</div>
|
||||
<button type="button" class="save"></button>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// The tracker's status vocabulary, from the same `STATUSES` tuple the
|
||||
// store validates a status change against — see app/web/pages.py.
|
||||
window.ROLEDESK_STATUSES = {{ status_options | map(attribute=0) | list | tojson }};
|
||||
</script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
+40
-17
@@ -1,10 +1,36 @@
|
||||
# roledesk configuration. `roles.yaml` is the one the app reads by default
|
||||
# (or $ROLEDESK_CONFIG, or `app -c path`). Every key here is optional.
|
||||
# roledesk configuration. The app reads --config, else $APP_CONFIG, else
|
||||
# config.yaml beside the checkout (committed: these defaults plus the starter
|
||||
# agents). Every value below is the default, so a copy with nothing changed
|
||||
# behaves exactly like no file at all. An unknown key is an error, not a
|
||||
# shrug; see app/config.py.
|
||||
|
||||
# The SQLite file: roles, companies, subscriptions, applications, and the
|
||||
# job queue's own table. Not shared with newsdesk.
|
||||
server:
|
||||
# 0.0.0.0 in a container -- the proxy is what is in front of it.
|
||||
host: 127.0.0.1
|
||||
port: 8790
|
||||
|
||||
# The SQLite file: roles, companies, subscriptions, applications, agents and
|
||||
# scores, the job queue and its schedules, the notice log, and auth's
|
||||
# sessions. Not shared with newsdesk.
|
||||
database: roledesk.db
|
||||
|
||||
# What a clock on screen means, and what `daily at 06:00` is 06:00 in.
|
||||
timezone: Europe/Berlin
|
||||
|
||||
log_level: INFO
|
||||
|
||||
# One password on a public hostname; see auth/README.md and
|
||||
# docs/password-protection.md. The password is never in this file.
|
||||
auth:
|
||||
enabled: auto # auto: open on loopback, locked on anything else
|
||||
session_days: 30
|
||||
secure_cookie: auto # always, behind a TLS-terminating proxy
|
||||
rp_id: "" # roledesk.example.com -- passkeys are bound to it
|
||||
rp_name: app # what the authenticator shows you
|
||||
origin: "" # https://roledesk.example.com
|
||||
password_env: APP_PASSWORD
|
||||
cookie: app_session # unique per app sharing a hostname
|
||||
|
||||
# Any .py file in these directories defining a desk `Source` subclass is a
|
||||
# plugin. A plugin imports `desk` only.
|
||||
plugin_paths:
|
||||
@@ -16,9 +42,10 @@ workers:
|
||||
http: 8
|
||||
cpu: 1
|
||||
|
||||
# Who answers when a job needs a model. See desk/tools/agent.py in ../news.
|
||||
# Who answers when a job needs a model. See desk/tools/agent.py; needs the
|
||||
# `agent` extra.
|
||||
agent:
|
||||
backend: auto # auto | api | claude_code | off
|
||||
backend: auto # auto | api | claude_code | off
|
||||
|
||||
# Title and description in, gate columns out (app/jobs/extract.py). Off by
|
||||
# default: on the API backend every batch of 20 roles is a paid call.
|
||||
@@ -27,22 +54,18 @@ extract:
|
||||
model: claude-haiku-4-5-20251001
|
||||
|
||||
# A role and each agent's intent as vectors, for the fit term of a score
|
||||
# (app/jobs/embed.py). Needs sentence-transformers; without it `embed`
|
||||
# posts a notice and scores leave fit out. Changing the model re-embeds.
|
||||
# (app/jobs/embed.py). Needs the `embeddings` extra; without it `embed` posts
|
||||
# a notice and scores leave fit out. Changing the model re-embeds.
|
||||
embed:
|
||||
model: sentence-transformers/all-MiniLM-L6-v2
|
||||
per_run: 50000
|
||||
|
||||
# One block per plugin, keyed by the plugin's name. The ats plugin reads its
|
||||
# boards from the subscriptions table, so it needs none.
|
||||
sources: {}
|
||||
|
||||
# Starter search agents, imported once into an empty `agents` table. Each gate
|
||||
# is {field, values, mode: require|prefer, weight}; fields are place, country,
|
||||
# remote, seniority, function, salary_min, currency, permit, languages and
|
||||
# company. weights default to {fit: 0.6, recency: 0.2, affinity: 0.2}.
|
||||
agents:
|
||||
- name: Berlin backend
|
||||
intent: Senior backend engineer, Python services and PostgreSQL.
|
||||
gates:
|
||||
- {field: place, values: [Berlin], mode: require}
|
||||
- {field: remote, values: [hybrid, remote], mode: prefer, weight: 0.2}
|
||||
|
||||
# One block per plugin. Empty until the ats plugin lands.
|
||||
sources: {}
|
||||
agents: []
|
||||
@@ -1,5 +1,13 @@
|
||||
# The default config. See config.example.yaml for what each key means.
|
||||
# roledesk's default config, committed. config.example.yaml documents every
|
||||
# key; anything left out here takes the default written there.
|
||||
server:
|
||||
host: 127.0.0.1
|
||||
port: 8790
|
||||
database: roledesk.db
|
||||
timezone: Europe/Berlin
|
||||
auth:
|
||||
rp_name: roledesk
|
||||
cookie: roledesk_session
|
||||
plugin_paths:
|
||||
- plugins
|
||||
workers:
|
||||
@@ -9,11 +17,11 @@ workers:
|
||||
extract:
|
||||
enabled: false
|
||||
model: claude-haiku-4-5-20251001
|
||||
sources: {}
|
||||
embed:
|
||||
model: sentence-transformers/all-MiniLM-L6-v2
|
||||
sources: {}
|
||||
# Starter search agents, imported once into an empty table. Edit them on the
|
||||
# page afterwards; this list is not read again.
|
||||
# Agents tab afterwards; this list is not read again.
|
||||
agents:
|
||||
- name: Berlin backend
|
||||
intent: >-
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
"""Drop-in plugins, discovered by `plugin_paths` in `roles.yaml`.
|
||||
"""Drop-in plugins, discovered by `plugin_paths` in `config.yaml`.
|
||||
|
||||
A plugin file imports `desk` only — see `tests/test_architecture.py`. This
|
||||
`__init__.py` makes the directory importable as `plugins.<name>` for the rest
|
||||
|
||||
@@ -95,6 +95,8 @@ ignore = [
|
||||
"app/models.py" = ["RUF012"]
|
||||
"desk/models.py" = ["RUF012"]
|
||||
"desk/sources/spec.py" = ["RUF012"]
|
||||
# The boilerplate's own test, adapted here but kept in its style.
|
||||
"tests/test_coupling.py" = ["SIM102"]
|
||||
|
||||
# ------------------------------------------------------------ type checking
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"""The package boundaries, held as a test rather than as a convention.
|
||||
|
||||
Adapted from news/tests/test_architecture.py. One tree of our own, `app`,
|
||||
and two external ones, `desk` and `pipeline`, imported from ../news.
|
||||
and three copied ones: `pipeline` and `auth` from the boilerplate, `desk` from
|
||||
news. Which of those may import which is `tests/test_coupling.py`'s rule; this
|
||||
file holds `app`'s own layers.
|
||||
|
||||
1. **Direction.** Within `app`, a package imports only from packages below
|
||||
it in `LAYERS`. `desk` and `pipeline` may be imported by any of them.
|
||||
it in `LAYERS`. `desk`, `pipeline` and `auth` may be imported by any of them.
|
||||
2. **Doors.** From outside a package, only `<tree>.<package>` is imported, and
|
||||
only names it lists in `__all__`. `desk.tools` has no door of its own, so
|
||||
there the door is the tool: `desk.tools.<tool>`, one level, no deeper.
|
||||
@@ -25,10 +27,11 @@ import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
#: Bottom to top. `cli` is the entry point and may reach anything.
|
||||
LAYERS = ["models", "config", "storage", "jobs", "web", "cli"]
|
||||
#: Bottom to top. `main` assembles the app from everything below it; `cli`
|
||||
#: and `__main__` are the entry points and may reach anything.
|
||||
LAYERS = ["models", "config", "storage", "jobs", "web", "main", "cli", "__main__"]
|
||||
APP = "app"
|
||||
EXTERNAL = {"desk", "pipeline"}
|
||||
EXTERNAL = {"desk", "pipeline", "auth"}
|
||||
TREES = {APP} | EXTERNAL
|
||||
|
||||
|
||||
@@ -142,7 +145,9 @@ def test_the_rules_catch_what_they_are_for() -> None:
|
||||
assert plugin_violations("from desk.sources.base import Source")
|
||||
assert not plugin_violations("from desk.sources import Source, Item")
|
||||
|
||||
assert direction_violations("storage", "from app.web import create_app")
|
||||
assert direction_violations("storage", "from app.web import TABS")
|
||||
assert direction_violations("web", "from app.main import create_app")
|
||||
assert not direction_violations("main", "from app.web import pages_router")
|
||||
assert direction_violations("storage", "from app import jobs")
|
||||
assert not direction_violations("jobs", "from app.storage import Store")
|
||||
assert not direction_violations("models", "from pipeline import job")
|
||||
|
||||
+13
-8
@@ -1,10 +1,13 @@
|
||||
"""The coupling rule, held by reading the imports.
|
||||
|
||||
`pipeline/` and `auth/` import nothing from `app/` and nothing from each
|
||||
other. `app/` imports both. That is what makes each of them copyable on its
|
||||
own into a project that has never heard of this one -- and it is exactly the
|
||||
rule that breaks quietly, one convenient import at a time, until the folder is
|
||||
a port rather than a copy.
|
||||
The boilerplate's test, with roledesk's two extra folders. `pipeline/`,
|
||||
`auth/` and `desk/` import nothing from `app/` and nothing from each other,
|
||||
except that `desk/` is built on `pipeline/`, as it is in news. `plugins/`
|
||||
imports `desk/` and nothing else, since a plugin is app-agnostic. `app/`
|
||||
imports all of them. That is what keeps each copied folder a copy that can be
|
||||
refreshed from its source, and it is the rule that breaks quietly, one
|
||||
convenient import at a time, until the folder is a port rather than a copy.
|
||||
`tests/test_architecture.py` holds `app/`'s own layers.
|
||||
|
||||
Read with `ast` rather than grepped: a string containing the word `app`, or a
|
||||
line in a docstring showing what an app would write, is not an import, and a
|
||||
@@ -21,10 +24,12 @@ import pytest
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
#: The module folders and what each may not reach for. Listed rather than
|
||||
#: derived so that adding a fourth folder is a decision, not an accident.
|
||||
#: derived so that adding a folder is a decision, not an accident.
|
||||
FORBIDDEN = {
|
||||
"pipeline": ("app", "auth"),
|
||||
"auth": ("app", "pipeline"),
|
||||
"pipeline": ("app", "auth", "desk", "plugins"),
|
||||
"auth": ("app", "pipeline", "desk", "plugins"),
|
||||
"desk": ("app", "auth", "plugins"),
|
||||
"plugins": ("app", "pipeline", "auth"),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ def test_there_are_scripts_to_check():
|
||||
def test_pyproject_packages_the_module_folders():
|
||||
data = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
|
||||
include = data["tool"]["setuptools"]["packages"]["find"]["include"]
|
||||
for pattern in ("app*", "pipeline*", "auth*"):
|
||||
for pattern in ("app*", "pipeline*", "auth*", "desk*"):
|
||||
assert pattern in include, f"{pattern} is missing: an install would leave it out"
|
||||
|
||||
|
||||
|
||||
+22
-7
@@ -17,7 +17,7 @@ if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from desk.models import Item # noqa: E402
|
||||
from pipeline import FINAL, TASKS, JobQueue, Jobs, RunContext # noqa: E402
|
||||
from pipeline import FINAL, SCHEDULES, TASKS, JobQueue, Jobs, RunContext # noqa: E402
|
||||
from plugins.ats import ATSSource # noqa: E402
|
||||
from app.config import AgentSeed, Config # noqa: E402
|
||||
from app.jobs import cascade, embed, score # noqa: E402
|
||||
@@ -266,13 +266,13 @@ def test_starter_agents_are_imported_once(store: Store, tmp_path: Path) -> None:
|
||||
def test_the_shipped_starter_agents_validate() -> None:
|
||||
from app import config as config_mod
|
||||
|
||||
names = [a.name for a in config_mod.load(ROOT / "roles.yaml").agents]
|
||||
names = [a.name for a in config_mod.load(ROOT / "config.yaml").agents]
|
||||
assert names == ["Berlin backend", "Remote EU stretch"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- cascade
|
||||
|
||||
def test_the_pull_cascade_runs_extract_embed_then_score(
|
||||
def test_the_pull_job_runs_pull_extract_embed_then_score(
|
||||
store: Store, config: Config, fake: FakeEmbedder, tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
store.add_subscription("ats", "greenhouse:acme", label="Acme", company="Acme",
|
||||
@@ -292,19 +292,34 @@ def test_the_pull_cascade_runs_extract_embed_then_score(
|
||||
queue = JobQueue(Jobs(tmp_path / "roledesk.db"), config, store,
|
||||
workers={"cpu": 1, "http": 1, "llm": 1})
|
||||
|
||||
task_id = queue.start_task(TASKS["pull"]())
|
||||
# The `pull` job, which is what the schedule fires: its own work is to ask
|
||||
# for the chain, which then runs to its end in the same drain.
|
||||
started = queue.enqueue("pull")
|
||||
queue.drain(timeout=60)
|
||||
|
||||
cascade_id = queue.jobs.of_task(task_id)[0].cascade_id
|
||||
jobs = sorted(queue.jobs.of_cascade(cascade_id), key=lambda j: j.id)
|
||||
assert started is not None and queue.jobs.get(started.id).state == "done" # type: ignore[union-attr]
|
||||
batch = queue.jobs.last("pull_batch")
|
||||
assert batch is not None
|
||||
jobs = sorted(queue.jobs.of_cascade(batch.cascade_id), key=lambda j: j.id)
|
||||
stages = [j.result.get("task") for j in jobs if j.kind == FINAL]
|
||||
assert stages == list(cascade.CASCADES["pull"])
|
||||
work = [j.kind for j in jobs if j.kind != FINAL]
|
||||
assert work == ["pull_batch", "embed", "score"], "extract is off, so it finds nothing"
|
||||
# The `pull` job and the chain it asked for are one cascade, so the Jobs
|
||||
# tab shows a scheduled pull as one run. Extract is off and finds nothing.
|
||||
assert work == ["pull", "pull_batch", "embed", "score"]
|
||||
assert all(j.state == "done" for j in jobs)
|
||||
assert len(store.scores(agent.id)) == 1
|
||||
|
||||
|
||||
def test_pull_is_a_job_on_a_six_hour_schedule_and_the_stages_are_tasks() -> None:
|
||||
"""A schedule enqueues a job kind, so `pull` is a job; were it a task too,
|
||||
the Jobs tab would draw two `pull` buttons."""
|
||||
assert "pull" not in TASKS
|
||||
assert {"extract", "embed", "score"} <= set(TASKS)
|
||||
assert SCHEDULES["pull"].kind == "pull"
|
||||
assert SCHEDULES["pull"].cadence == "every 6h"
|
||||
|
||||
|
||||
def test_follows_walks_the_cascade_and_stops_at_its_end() -> None:
|
||||
assert cascade.follows("pull", "pull") == "extract"
|
||||
assert cascade.follows("pull", "extract") == "embed"
|
||||
|
||||
+85
-14
@@ -1,4 +1,4 @@
|
||||
"""The JSON API the page calls, against a temp database and FastAPI's
|
||||
"""The tabs and the JSON API they call, against a temp database and FastAPI's
|
||||
TestClient. No network — nothing here touches an ATS host or the queue's own
|
||||
worker beyond starting and stopping it with the app."""
|
||||
|
||||
@@ -12,9 +12,12 @@ import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from desk.models import Item
|
||||
from app.config import Config, ServerConfig
|
||||
from app.main import create_app
|
||||
from app.storage import Store
|
||||
from app.web.app import create_app
|
||||
from app.web import TABS
|
||||
from auth import AuthConfig
|
||||
from desk.models import Item
|
||||
|
||||
|
||||
class Clock:
|
||||
@@ -41,10 +44,10 @@ def posting(source_id: str = "1", **raw: object) -> Item:
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path: Path) -> FastAPI:
|
||||
db = tmp_path / "roledesk.db"
|
||||
config_path = tmp_path / "roles.yaml"
|
||||
config_path.write_text(f"database: {db.as_posix()}\n", encoding="utf-8")
|
||||
return create_app(str(config_path))
|
||||
"""The database in `tmp_path` and the config passed in, so a test never
|
||||
touches `roledesk.db` and two tests never share a jobs table."""
|
||||
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "roledesk.db"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -195,14 +198,82 @@ def test_set_status_validates_and_writes_an_event(
|
||||
json={"status": "applied"}).status_code == 404
|
||||
|
||||
|
||||
# --------------------------------------------------------------------- page
|
||||
# -------------------------------------------------------------------- tabs
|
||||
|
||||
def test_index_renders_the_shell(client: TestClient) -> None:
|
||||
res = client.get("/")
|
||||
assert res.status_code == 200
|
||||
assert "roledesk" in res.text
|
||||
assert 'id="roles-list"' in res.text
|
||||
assert "<desk-jobs>" in res.text
|
||||
def test_every_tab_renders_with_the_whole_nav(client: TestClient) -> None:
|
||||
assert [t.label for t in TABS] == ["Roles", "Applications", "Agents", "Companies",
|
||||
"Jobs", "Schedules", "Messages", "Account"]
|
||||
for tab in TABS:
|
||||
res = client.get(tab.path)
|
||||
assert res.status_code == 200, f"{tab.path} answered {res.status_code}"
|
||||
assert "roledesk</title>" in res.text
|
||||
for other in TABS:
|
||||
assert f">{other.label}</a>" in res.text
|
||||
|
||||
|
||||
def test_each_roledesk_tab_is_a_shell_for_roles_js(client: TestClient) -> None:
|
||||
for path, container in [("/", 'id="roles-list"'),
|
||||
("/applications", 'id="applications-list"'),
|
||||
("/agents", 'id="agents-list"'),
|
||||
("/companies", 'id="companies-list"')]:
|
||||
page = client.get(path).text
|
||||
assert container in page and "/static/roles.js" in page
|
||||
# toasts.js before app.js before the page's own script: `api()` needs
|
||||
# `window.toast`, and roles.js needs `api()`.
|
||||
assert page.index("toasts.js") < page.index("app.js") < page.index("roles.js")
|
||||
assert "ROLEDESK_STATUSES" in client.get("/applications").text
|
||||
assert client.get("/static/roles.js").status_code == 200
|
||||
|
||||
|
||||
def test_the_modules_bring_their_own_elements(client: TestClient) -> None:
|
||||
assert "<desk-jobs>" in client.get("/jobs").text
|
||||
assert "<desk-schedules>" in client.get("/schedules").text
|
||||
assert "<auth-account>" in client.get("/account").text
|
||||
|
||||
|
||||
def test_pull_is_declared_every_six_hours(client: TestClient) -> None:
|
||||
rows = {r["name"]: r for r in client.get("/api/schedules").json()}
|
||||
assert rows["pull"]["kind"] == "pull"
|
||||
assert rows["pull"]["cadence"] == "every 6h"
|
||||
assert rows["pull"]["enabled"] is True and rows["pull"]["unknown"] is False
|
||||
|
||||
|
||||
def test_the_jobs_tab_offers_pull_once_and_no_batch(client: TestClient) -> None:
|
||||
"""A subset rather than the list: `pipeline/tests` registers kinds of its
|
||||
own into the same global `JOBS` when the whole suite runs."""
|
||||
kinds = [k["kind"] for k in client.get("/api/jobs/kinds").json()]
|
||||
assert {"embed", "extract", "pull", "score"} <= set(kinds)
|
||||
assert kinds.count("pull") == 1
|
||||
assert not {"pull_batch", "extract_batch", "advance"} & set(kinds)
|
||||
|
||||
|
||||
def test_an_error_is_one_sentence(client: TestClient) -> None:
|
||||
"""`api()` toasts `detail` as it is, so a 422 is a sentence, not a list."""
|
||||
res = client.post("/api/agents", json={"name": "Bad",
|
||||
"gates": [{"field": "salary", "values": [1]}]})
|
||||
assert res.status_code == 422
|
||||
assert "gates.0.field" in res.json()["detail"]
|
||||
missing = client.get("/nothing-here")
|
||||
assert missing.status_code == 404 and "text/html" in missing.headers["content-type"]
|
||||
|
||||
|
||||
def test_health_is_open_and_reads_the_store(client: TestClient) -> None:
|
||||
assert client.get("/health").json() == {"ok": True, "open_roles": 0}
|
||||
|
||||
|
||||
def test_a_locked_app_shuts_every_tab_and_the_api(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setenv("APP_PASSWORD", "open-sesame-please")
|
||||
config = Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "locked.db", auth=AuthConfig(enabled="always"))
|
||||
with TestClient(create_app(config), follow_redirects=False) as locked:
|
||||
for tab in TABS:
|
||||
assert locked.get(tab.path).status_code == 303
|
||||
assert locked.get("/api/roles").status_code == 401
|
||||
assert locked.get("/health").status_code == 200
|
||||
signed_in = locked.post("/login", json={"password": "open-sesame-please"})
|
||||
assert signed_in.status_code == 200
|
||||
assert locked.get("/api/roles").status_code == 200
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ agents
|
||||
|
||||
Reference in new issue
Block a user