Summarise every saved or liked role whatever its rank, queue it at once on save or like, and shorten the order labels to Agent match, CV match and Newest so they fit one line

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet 5.5 committed 2026-10-03 23:14:12 +02:00
1 parent 1d0a4c37f2
commit ee8e450640
20 files changed
+208 -60

No files matched your search

+35 -8
View File
@@ -15,6 +15,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Response
from pydantic import BaseModel, Field
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,
@@ -163,15 +164,21 @@ def get_role(uid: str, store: StoreDep, agent: int | None = None) -> ScoredRole:
@router.post("/roles/{uid}/vote")
def vote_role(uid: str, body: VoteBody, store: StoreDep) -> ScoredRole:
def vote_role(uid: str, body: VoteBody, store: StoreDep, config: ConfigDep,
queue: QueueDep) -> ScoredRole:
"""1 like, 0 neither way, -1 pass, for `body.agent` or the default agent.
The role stays listed either way; the vote moves it in that agent's
ranking, see `Store.roles`, and shapes its taste at the next `score`."""
ranking, see `Store.roles`, and shapes its taste at the next `score`. A
like from an enabled agent also queues the role's summary, see
`_queue_summary`."""
owner = _agent_or_default(store, body.agent)
try:
return store.set_vote(owner.id, uid, body.value)
voted = store.set_vote(owner.id, uid, body.value)
except KeyError:
raise HTTPException(404, f"no such role: {uid}") from None
if body.value == 1 and owner.enabled:
_queue_summary(voted, store, config, queue)
return voted
@router.delete("/roles/{uid}/vote")
@@ -231,7 +238,7 @@ def list_roles(
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` (Best CV match) the scored roles
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
@@ -414,6 +421,22 @@ def fetch_text(uid: str, store: StoreDep, agent: int | None = None) -> ScoredRol
return role
def _queue_summary(role: Role, store: Store, config: Config, queue: Any) -> None:
"""Queue the summary of a role the owner just saved or liked, without
waiting for the next pull: one batch of this uid, under the key the read
page's button uses, so a double tap and the button share one job. Only
while the summarise stage is on (`jobs.stages`), for a role with no summary
yet and some text, and with a model reachable; otherwise nothing, and the
save or vote is not the place to say why."""
if (role.summary or not (role.article_text.strip() or role.description.strip())
or not jobs.stages.stage_on(config, store, "summarise")
or not agent.backend(config.agent)):
return
queue.enqueue(f"{jobs.summarise.TASK.kind}_batch", {"uids": [role.uid]},
label=f"Summarising {role.title or role.uid}",
dedup_key=f"summarise:{role.uid}")
@router.post("/roles/{uid}/summarise", status_code=202)
def summarise_role(uid: str, store: StoreDep, config: ConfigDep, queue: QueueDep) -> Job:
"""Queue a summary of one role, whatever its rank and whether or not the
@@ -745,7 +768,7 @@ def set_affinity(key: str, body: AffinityBody, store: StoreDep,
"""-1 hidden, 0 neutral, 1 liked, 2 favourite, for `body.agent` or the
default agent. A key with roles and no company row gets one first (see
`Store.set_affinity`); 404 for a key with neither. A change here is not
seen in Best match until `score` has run, so it queues one
seen in Agent match until `score` has run, so it queues one
(`_score_after_change`) and answers with its id."""
if body.affinity not in AFFINITY:
raise HTTPException(422, "affinity is -1, 0, 1 or 2")
@@ -1140,10 +1163,12 @@ class SaveBody(BaseModel):
@router.post("/applications", status_code=201)
def save_role(body: SaveBody, store: StoreDep) -> Application:
def save_role(body: SaveBody, store: StoreDep, config: ConfigDep,
queue: QueueDep) -> Application:
"""Track one role: the ★ on a role. Pressing it twice does not
double-track it: the existing row comes back rather than a second one
starting at `saved` over whatever status it has since moved to."""
starting at `saved` over whatever status it has since moved to. A saved
role is also queued for its summary, see `_queue_summary`."""
existing = next((a for a in store.applications() if a.role_uid == body.role_uid), None)
if existing is not None:
return existing
@@ -1153,7 +1178,9 @@ def save_role(body: SaveBody, store: StoreDep) -> Application:
application = Application(
role_uid=role.uid, company_key=role.company_key, role_title=role.title,
url=role.original_url, status=body.status, source=role.source)
return store.save_application(application)
saved = store.save_application(application)
_queue_summary(role, store, config, queue)
return saved
@router.delete("/applications/{app_id}", status_code=204)