Rank by the cut: fetch gate overrides in scoring, the cut per agent, stages read the cut, fetch text renamed from enrich, the feed kept to the fetch gate, and migration 32

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-10-04 15:11:43 +02:00
1 parent 060ccf66e6
commit 617356e60c
35 files changed
+1054 -751

No files matched your search

+75 -23
View File
@@ -18,7 +18,7 @@ from app import jobs, places
from app.config import Config
from app.models import (
AFFINITY, RUNGS, TRACKS, Agent, Application, Company, CvLanguage, CvLanguages, FetchTerms,
Gate, Limits, Prompts, Role, RoleRow,
Gate, Limits, Prompts, Role, RoleRow, SavedFilter,
HandReason, ScoredRole, Status, Subscription, Weights, company_key, levels_between,
)
from app.storage import Store
@@ -95,7 +95,8 @@ def _feed_filters(
empty feed. The three seniority parameters become the levels between
them (`levels_between`), which is what the store filters on. `order=cv`
is the score order with the agent's judged roles first by `cv_score`
(`by_cv`)."""
(`by_cv`). A request that names an agent keeps to its fetch gate in
every order, newest included (`fetch_gate`), unless `gated`."""
for token in tokens:
if not places.known(token):
raise HTTPException(422, f"No place is known as {token!r}.")
@@ -118,6 +119,7 @@ def _feed_filters(
"tag_mode": tag_mode, "agent": _agent_id(store, agent),
"by_score": agent is not None and order in ("score", "cv"),
"by_cv": agent is not None and order == "cv", "gated": gated,
"fetch_gate": agent is not None,
"judged": judged or None, "pay": pay or None, "company_keys": company_keys,
"places": tokens, "seniority": list(levels), "seniority_unknown": seniority_unknown,
"pay_unknown": pay_unknown, "closing": closing}
@@ -235,14 +237,15 @@ def list_roles(
`agent` says whose votes, hidden companies and scores are meant. Each
role carries that agent's `vote`; a company it hid is left out unless
`show_muted` is set; `judged` keeps the liked, the unjudged or the
passed. With `order=score` (the default) the roles are the ones that
agent scored, best first, carrying `score` and `gated_reason`, a gated
one only with `gated=1`; with `order=newest` every open role, newest
first, with no score; with `order=cv` (CV match) the scored roles
the agent's `judge` read come first by `cv_score`, the rest after them
by score. Without `agent` the default agent's votes and
hidden companies apply, the order is newest and there is no score; with
no agent at all, every vote is None and nothing is hidden.
passed. Every order keeps to the roles that agent's fetch gate passes,
a gated one only with `gated=1`: with `order=score` (the default) best
first by final score, carrying `score` and `gated_reason`; with
`order=newest` newest first, carrying `gated_reason` and no score; with
`order=cv` (CV match) the roles the agent's `judge` read come first by
`cv_score`, the rest after them by CV closeness, then score. Without
`agent` the default agent's votes and hidden companies apply, the order
is newest over every open role and there is no score; with no agent at
all, every vote is None and nothing is hidden.
`include_read` set false hides a role already marked read. `tags` is
`?tags=a&tags=b`, kept to a role with any of them or, with
@@ -467,7 +470,7 @@ class StageBody(BaseModel):
@router.get("/stages")
def list_stages(store: StoreDep, config: ConfigDep) -> list[jobs.stages.Stage]:
"""The stages of a pull with a switch, extract, summarise, judge and
enrich: whether each is on, whether the stored switch or config.yaml says
fetch_text: whether each is on, whether the stored switch or config.yaml says
so, its model, and who would answer."""
return jobs.stages.describe(config, store)
@@ -778,7 +781,7 @@ def set_affinity(key: str, body: AffinityBody, store: StoreDep,
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
job = _score_after_change(queue)
jobs.cascade.enrich_after(queue, job)
jobs.cascade.fetch_text_after(queue, job)
return AffinityOut(**company.model_dump(), score_job=job.id if job else None)
@@ -804,14 +807,17 @@ class OverrideBody(BaseModel):
def _override(store: Store, queue: Any, key: str, on: bool, setter: str) -> Company:
"""Switch one of a company's two fetch overrides. On queues a pull right
after, as the other reopening switches do; off queues nothing and asks
nothing first, since no role closes until the next pull reads the board
with its filters again. 404 for an unknown key."""
"""Switch one of a company's two overrides of the fetch gate. Either
way the agents' fetch gates change for the roles already stored, so a
rescore is queued (`_score_after_change`) with the fetch text cascade
behind it. On also queues a pull, as the other reopening switches do;
off queues no pull, since no role closes until the next pull reads the
board with its filters again. 404 for an unknown key."""
try:
company = getattr(store, setter)(key, on)
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
jobs.cascade.fetch_text_after(queue, _score_after_change(queue))
if on:
queue.enqueue("pull")
return company
@@ -821,16 +827,19 @@ def _override(store: Store, queue: Any, key: str, on: bool, setter: str) -> Comp
def set_all_countries(key: str, body: OverrideBody, store: StoreDep,
queue: QueueDep) -> Company:
"""All countries on or off: global, apart from affinity. On, the
company's big boards are read with the agents' wide reach, Europe today,
rather than their places (`app/jobs/reach.py`). See `_override`."""
company's roles skip the place part of every agent's fetch gate (the
`any` gates, `jobs.score.failed_gates`), and its big boards are read
with the agents' wide reach, Europe today, rather than their places
(`app/jobs/reach.py`). See `_override`."""
return _override(store, queue, key, body.on, "set_all_countries")
@router.post("/companies/{key}/all-roles")
def set_all_roles(key: str, body: OverrideBody, store: StoreDep, queue: QueueDep) -> Company:
"""All roles on or off: global, apart from affinity. On, the company's
boards are read with no role-type narrowing, no fetch terms today
(`app/jobs/reach.py`). See `_override`."""
roles skip the role part of every agent's fetch gate, the titles to
leave out (`jobs.score.failed_gates`), and its boards are read with no
fetch terms (`app/jobs/reach.py`). See `_override`."""
return _override(store, queue, key, body.on, "set_all_roles")
@@ -1282,7 +1291,7 @@ def cv_languages(body: CvText, config: ConfigDep) -> CvLanguagesOut:
@router.post("/agents")
def save_agent(body: AgentBody, store: StoreDep, queue: QueueDep) -> Agent:
"""Queues the rescore, which the page's `POST /api/score` after a save
joins, and the enrich run behind it (`cascade.enrich_after`)."""
joins, and the fetch text cascade behind it (`cascade.fetch_text_after`)."""
try:
saved = store.save_agent(body.name, body.intent, body.gates, body.weights,
body.enabled, agent_id=body.id, limits=body.limits,
@@ -1294,13 +1303,56 @@ def save_agent(body: AgentBody, store: StoreDep, queue: QueueDep) -> Agent:
raise HTTPException(409, str(exc)) from exc
except KeyError:
raise HTTPException(404, f"no such agent: {body.id}") from None
jobs.cascade.enrich_after(queue, _score_after_change(queue))
jobs.cascade.fetch_text_after(queue, _score_after_change(queue))
return saved
@router.delete("/agents/{agent_id}", status_code=204)
def delete_agent(agent_id: int, store: StoreDep) -> Response:
"""Its prompts, scores, votes and affinities go with it."""
"""Its prompts, scores, votes, affinities and saved filters go with it."""
if not store.delete_agent(agent_id):
raise HTTPException(404, f"no such agent: {agent_id}")
return Response(status_code=204)
# ---------------------------------------------------------- saved filters
class FilterBody(BaseModel):
#: Checked by `Store.save_filter`, so a blank name is a 422 sentence.
name: str
#: The feed's query string as `roles.js` `addressFor` writes it, without
#: the agent.
query: str = ""
@router.get("/agents/{agent_id}/filters")
def list_saved_filters(agent_id: int, store: StoreDep) -> list[SavedFilter]:
"""The agent's saved filters, by name. 404 for an unknown agent."""
if store.agent(agent_id) is None:
raise HTTPException(404, f"no such agent: {agent_id}")
return store.saved_filters(agent_id)
@router.post("/agents/{agent_id}/filters", status_code=201)
def save_filter(agent_id: int, body: FilterBody, store: StoreDep) -> SavedFilter:
"""Save the feed's filters under a name for the agent. 404 for an
unknown agent, 422 for an empty name, 409 for a name the agent already
has regardless of case. There is no editing: a change is a new one."""
if store.agent(agent_id) is None:
raise HTTPException(404, f"no such agent: {agent_id}")
if not body.name.strip():
raise HTTPException(422, "Give the filter a name.")
try:
return store.save_filter(agent_id, body.name, body.query)
except KeyError:
raise HTTPException(404, f"no such agent: {agent_id}") from None
except ValueError as exc:
raise HTTPException(409, f"A filter named {body.name.strip()!r} is already saved.") \
from exc
@router.delete("/filters/{filter_id}", status_code=204)
def delete_saved_filter(filter_id: int, store: StoreDep) -> Response:
if not store.delete_filter(filter_id):
raise HTTPException(404, f"no such saved filter: {filter_id}")
return Response(status_code=204)