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
+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:
|
||||
|
||||
Reference in new issue
Block a user