Bring the Python side to the ADR: the judge scores 0 to 10 with the cap at 4 and migration 33 clears every judgement, summarise reads the top 30 of the want and the match order, a hidden company's roles are never in the feed, and the company switch is called All locations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cad9713ac
commit
6d82287402
27 files changed
+390
-247
No files matched your search
+29
-3
@@ -431,12 +431,14 @@ CREATE TABLE IF NOT EXISTS agent_cv_vectors (
|
||||
|
||||
-- One agent's judge reading of a role against its CV. Its own table, since
|
||||
-- replace_scores rewrites scores every run and a judgement outlives that
|
||||
-- and the role closing. skills, experience and career are 0 to 100,
|
||||
-- cv_score their weighted total, strengths and gaps JSON lists. input_key
|
||||
-- and the role closing. skills, experience and career are 0 to 10 (0 to
|
||||
-- 100 until migration 33), cv_score their weighted total times 10 at the
|
||||
-- default weights (not read: app.models.cv_score is worked out when a role
|
||||
-- is served), strengths and gaps JSON lists. input_key
|
||||
-- is a hash of the CV, prompts, avoid text and the role's text it read: a
|
||||
-- different one is read again. musts is a JSON list of {id, text, verdict},
|
||||
-- the model's verdict on each of the agent's must-haves (one per line of its
|
||||
-- must text), broken how many are "broken": career counts as at most 39 then
|
||||
-- must text), broken how many are "broken": career counts as at most 4 then
|
||||
-- (app.models.BROKEN_CAP), applied when the role is served. tries counts
|
||||
-- replies that left the role without one since; at 3 it is given up until the agent is saved again. A
|
||||
-- row with judged_at NULL holds only tries.
|
||||
@@ -758,6 +760,9 @@ UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
|
||||
(32, "the cut: scores.fit and scores.cut, agents' limits reset to the cut's defaults, "
|
||||
"prefer gates gone, saved_filters, and enrich renamed fetch text",
|
||||
lambda conn: _add_cut(conn)),
|
||||
# A Python step: JSON limits, and a count for the log.
|
||||
(33, "the judge on 0 to 10: every judgement cleared to be made again, and summarise_top "
|
||||
"50 becomes 30", lambda conn: _judge_out_of_ten(conn)),
|
||||
)
|
||||
|
||||
#: What a file created from `SCHEMA` today is already at.
|
||||
@@ -1191,6 +1196,27 @@ def _add_cut(conn: sqlite3.Connection) -> None:
|
||||
"dropped", reset, dropped)
|
||||
|
||||
|
||||
def _judge_out_of_ten(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 33's step. The judge scores 0 to 10 rather than 0 to 100
|
||||
(`judge.FORMAT` 4), so every judgement is cleared: its numbers, the
|
||||
verdicts, strengths and gaps, `input_key`, `judged_at` and `tries`, and no
|
||||
old number is shown on the new scale. The rows stay, as rows of no
|
||||
judgement, and the judge reads every pair again. An agent whose
|
||||
`summarise_top` is 50, migration 32's default, takes 30, the new one.
|
||||
Runs twice without harm."""
|
||||
cleared = conn.execute(
|
||||
"""UPDATE role_judgements
|
||||
SET skills = NULL, experience = NULL, career = NULL, cv_score = NULL,
|
||||
strengths = '[]', gaps = '[]', musts = '[]', broken = 0,
|
||||
input_key = '', tries = 0, judged_at = NULL""").rowcount
|
||||
lowered = conn.execute(
|
||||
"""UPDATE agents SET limits = json_set(limits, '$.summarise_top', 30)
|
||||
WHERE json_valid(limits) AND json_type(limits) = 'object'
|
||||
AND json_extract(limits, '$.summarise_top') = 50""").rowcount
|
||||
log.info("migration 33: %d judgements cleared for the 0 to 10 scale, %d agents' "
|
||||
"summarise_top 50 set to 30", cleared, lowered)
|
||||
|
||||
|
||||
def _add_all_roles(conn: sqlite3.Connection) -> None:
|
||||
"""Migration 21's step. The column; the tag for every company that is a
|
||||
favourite of any agent, since favourite no longer widens what a pull
|
||||
|
||||
+75
-62
@@ -138,8 +138,9 @@ _WITH_JUDGEMENTS = ("LEFT JOIN role_judgements j ON j.uid = roles.uid AND j.agen
|
||||
|
||||
|
||||
def _cv_sql(weights: Weights | None) -> str:
|
||||
"""`cv_score` as SQL for one agent's weights, unrounded (`app.models.cv_score`
|
||||
rounds it): NULL for a role not judged, and for all three weights 0. Career
|
||||
"""`cv_score` as SQL for one agent's weights, 0 to 100 from the judge's
|
||||
three numbers 0 to 10, unrounded (`app.models.cv_score` rounds it): NULL
|
||||
for a role not judged, and for all three weights 0. Career
|
||||
counts as at most `BROKEN_CAP` when the judgement holds a broken
|
||||
must-have (`j.broken`), as `app.models.capped_career` has it. The
|
||||
numbers are the model's validated, finite floats, so they are written in
|
||||
@@ -150,7 +151,7 @@ def _cv_sql(weights: Weights | None) -> str:
|
||||
return "NULL"
|
||||
career = (f"(CASE WHEN j.broken > 0 AND j.career > {BROKEN_CAP} THEN {BROKEN_CAP} "
|
||||
"ELSE j.career END)")
|
||||
return (f"(({w.cv_skills!r} * j.skills + {w.cv_experience!r} * j.experience "
|
||||
return (f"(10.0 * ({w.cv_skills!r} * j.skills + {w.cv_experience!r} * j.experience "
|
||||
f"+ {w.cv_career!r} * {career}) / {total!r})")
|
||||
|
||||
|
||||
@@ -1134,7 +1135,7 @@ class Store:
|
||||
place: str | None = None, open_only: bool = True,
|
||||
q: str | None = None, function: str | None = None,
|
||||
remote: str | None = None, days: int | None = None,
|
||||
hide_muted: bool = False, include_read: bool = True,
|
||||
include_read: bool = True,
|
||||
tags: Sequence[str] = (), tag_mode: str = "any",
|
||||
agent: int | None = None, by_score: bool = True, gated: bool = False,
|
||||
fetch_gate: bool = False, judged: str | None = None, pay: str | None = None,
|
||||
@@ -1161,18 +1162,18 @@ class Store:
|
||||
|
||||
`agent` says whose votes, hidden companies and scores are meant. Each
|
||||
row carries that agent's `vote` and `voted_at`; `judged` (a key of
|
||||
`JUDGED`: liked, unjudged or passed) filters on them. `hide_muted`
|
||||
excludes the companies that agent hid, before `limit` is applied, in
|
||||
SQL rather than after the fact: a company that has published a lot,
|
||||
all at once — a fresh board added, a re-pull that finally reached
|
||||
it — can otherwise fill the whole page with roles that then all turn
|
||||
out to be from the one company someone hid, leaving nothing to show
|
||||
for a default query that would otherwise have plenty. With no agent
|
||||
`JUDGED`: liked, unjudged or passed) filters on them. The companies
|
||||
that agent hid are always left out, in every order and count: a
|
||||
hidden company's roles are never shown. That is done before `limit`,
|
||||
in SQL rather than after the fact: a company that has published a
|
||||
lot, all at once — a fresh board added, a re-pull that finally
|
||||
reached it — could otherwise fill the whole page with roles that then
|
||||
all turn out to be from the one company someone hid. With no agent
|
||||
every vote is None, nothing is hidden and `judged` reads as such.
|
||||
|
||||
`include_read` set False excludes a role `set_read` or `set_vote` has
|
||||
stamped, the same way and for the same reason as `hide_muted`:
|
||||
before `limit`, not after. `tags` keeps only roles carrying at least
|
||||
stamped, the same way and for the same reason as the hidden
|
||||
companies: before `limit`, not after. `tags` keeps only roles carrying at least
|
||||
one of them (`tag_mode="any"`, the default) or every one
|
||||
(`tag_mode="all"`), also before `limit`.
|
||||
|
||||
@@ -1201,7 +1202,7 @@ class Store:
|
||||
the whole page rather than one per role."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||
remote=remote, days=days, include_read=include_read,
|
||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||
fetch_gate=fetch_gate,
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
@@ -1253,7 +1254,7 @@ class Store:
|
||||
place: str | None = None, open_only: bool = True,
|
||||
q: str | None = None, function: str | None = None,
|
||||
remote: str | None = None, days: int | None = None,
|
||||
hide_muted: bool = False, include_read: bool = True,
|
||||
include_read: bool = True,
|
||||
tags: Sequence[str] = (), tag_mode: str = "any",
|
||||
agent: int | None = None, by_score: bool = True, gated: bool = False,
|
||||
fetch_gate: bool = False, judged: str | None = None, pay: str | None = None,
|
||||
@@ -1277,7 +1278,7 @@ class Store:
|
||||
column itself never crosses out of SQLite for a list."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||
remote=remote, days=days, include_read=include_read,
|
||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||
fetch_gate=fetch_gate,
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
@@ -1333,8 +1334,7 @@ class Store:
|
||||
def count_roles(self, company: str | None = None, place: str | None = None,
|
||||
open_only: bool = True, q: str | None = None,
|
||||
function: str | None = None, remote: str | None = None,
|
||||
days: int | None = None, hide_muted: bool = False,
|
||||
include_read: bool = True, tags: Sequence[str] = (),
|
||||
days: int | None = None, include_read: bool = True, tags: Sequence[str] = (),
|
||||
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
|
||||
gated: bool = False, fetch_gate: bool = False,
|
||||
judged: str | None = None,
|
||||
@@ -1345,7 +1345,7 @@ class Store:
|
||||
"""How many roles `roles` would list with the same filters and no limit."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, include_read=include_read,
|
||||
remote=remote, days=days, include_read=include_read,
|
||||
tags=tags, tag_mode=tag_mode, agent=agent, by_score=by_score, gated=gated,
|
||||
fetch_gate=fetch_gate,
|
||||
judged=judged, pay=pay, company_keys=company_keys, places=places,
|
||||
@@ -1357,8 +1357,7 @@ class Store:
|
||||
def role_facets(self, company: str | None = None, place: str | None = None,
|
||||
open_only: bool = True, q: str | None = None,
|
||||
function: str | None = None, remote: str | None = None,
|
||||
days: int | None = None, hide_muted: bool = False,
|
||||
include_read: bool = True, tags: Sequence[str] = (),
|
||||
days: int | None = None, include_read: bool = True, tags: Sequence[str] = (),
|
||||
tag_mode: str = "any", agent: int | None = None, by_score: bool = True,
|
||||
gated: bool = False, fetch_gate: bool = False,
|
||||
judged: str | None = None,
|
||||
@@ -1375,7 +1374,7 @@ class Store:
|
||||
and then `""`, no pay stated. A value no role has counts 0."""
|
||||
shared: dict[str, Any] = {
|
||||
"company": company, "place": place, "open_only": open_only, "q": q,
|
||||
"function": function, "remote": remote, "days": days, "hide_muted": hide_muted,
|
||||
"function": function, "remote": remote, "days": days,
|
||||
"include_read": include_read, "tags": tags, "tag_mode": tag_mode, "agent": agent,
|
||||
"by_score": by_score, "gated": gated, "fetch_gate": fetch_gate, "judged": judged,
|
||||
"company_keys": company_keys, "places": places, "closing": closing}
|
||||
@@ -1394,7 +1393,7 @@ class Store:
|
||||
|
||||
def _roles_from(self, *, company: str | None, place: str | None, open_only: bool,
|
||||
q: str | None, function: str | None, remote: str | None,
|
||||
days: int | None, hide_muted: bool, include_read: bool,
|
||||
days: int | None, include_read: bool,
|
||||
tags: Sequence[str], tag_mode: str, agent: int | None,
|
||||
by_score: bool, gated: bool, judged: str | None,
|
||||
fetch_gate: bool = False,
|
||||
@@ -1408,7 +1407,7 @@ class Store:
|
||||
(see `_WITH_VOTES`) and its judgements as `j` (`_WITH_JUDGEMENTS`);
|
||||
its scores as `s` when ordering by them or with `fetch_gate`, and
|
||||
then a role the agent's fetch gate rejects is left out unless
|
||||
`gated`. A copy of another role
|
||||
`gated`. A company the agent hid is always left out. A copy of another role
|
||||
(`rebuild_dupes`) is never listed: its kept role stands for it and
|
||||
counts its copies. `closing` keeps the roles whose deadline is
|
||||
today or within `CLOSING_DAYS` after it."""
|
||||
@@ -1451,7 +1450,7 @@ class Store:
|
||||
params += list(seniority)
|
||||
if open_only:
|
||||
where.append("closed_at IS NULL")
|
||||
if hide_muted and agent is not None:
|
||||
if agent is not None:
|
||||
where.append("company_key NOT IN (SELECT company_key FROM agent_companies "
|
||||
"WHERE agent_id = ? AND affinity = -1)")
|
||||
params.append(agent)
|
||||
@@ -1498,15 +1497,14 @@ class Store:
|
||||
return [g for g in found.gates if g.field == "country" and g.mode == "require"] \
|
||||
if found is not None else []
|
||||
|
||||
def tag_counts(self, agent_id: int | None = None,
|
||||
show_muted: bool = False) -> list[tuple[str, int, int]]:
|
||||
def tag_counts(self, agent_id: int | None = None) -> list[tuple[str, int, int]]:
|
||||
"""`(tag, open_count, unread_count)` over open roles, most-used tag
|
||||
first and then alphabetically. What `/api/filters` serves; the
|
||||
companies `agent_id` hid are left out unless `show_muted`, the same
|
||||
default as `roles`, and with no agent nothing is hidden."""
|
||||
companies `agent_id` hid are left out, as in `roles`, and with no
|
||||
agent nothing is hidden."""
|
||||
where = "r.closed_at IS NULL AND r.dup_of IS NULL"
|
||||
params: list[Any] = []
|
||||
if not show_muted and agent_id is not None:
|
||||
if agent_id is not None:
|
||||
where += (" AND r.company_key NOT IN (SELECT company_key FROM agent_companies "
|
||||
"WHERE agent_id = ? AND affinity = -1)")
|
||||
params.append(agent_id)
|
||||
@@ -1664,29 +1662,43 @@ class Store:
|
||||
# -------------------------------------------------------------- extract
|
||||
|
||||
def _summarise_top(self) -> tuple[str, list[Any]]:
|
||||
"""The `WHERE` fragment for a role among the best `summarise_top`
|
||||
final scores of an enabled agent with a prompt, open, no copy and
|
||||
passing that agent's fetch gate: the top of its feed. The rank is
|
||||
numbered per agent and the agent's limits ride out of the window
|
||||
subquery beside it, so each row is held to the limit of the agent
|
||||
that ranked it; a key the JSON lacks is the `Limits` default. The
|
||||
role is `r`. An agent without a prompt with text counts for nothing
|
||||
here: its scores have no fit, so they say how fresh a role is, not
|
||||
whether it is wanted."""
|
||||
return ("""r.uid IN (SELECT uid FROM (
|
||||
SELECT s.uid, a.limits, ROW_NUMBER() OVER (
|
||||
PARTITION BY s.agent_id
|
||||
ORDER BY s.score DESC, top.posted_at DESC, s.uid) AS n
|
||||
FROM scores s
|
||||
JOIN agents a ON a.id = s.agent_id AND a.enabled = 1
|
||||
AND EXISTS (SELECT 1 FROM agent_prompts p
|
||||
WHERE p.agent_id = a.id
|
||||
AND TRIM(p.text, ' ' || char(9, 10, 13)) <> '')
|
||||
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
||||
AND top.dup_of IS NULL
|
||||
WHERE s.gated_reason = '')
|
||||
WHERE n <= COALESCE(json_extract(limits, '$.summarise_top'), ?))""",
|
||||
[Limits().summarise_top])
|
||||
"""The `WHERE` fragment for a role in the top of an enabled agent's
|
||||
feed in either order, open, no copy, passing that agent's fetch gate
|
||||
and not of a company it hid: the best `summarise_top` (its `limits`)
|
||||
by the want feed score, the score order of `roles` with the vote
|
||||
applied (`_VOTED_SCORE`), and the best `summarise_top` by the match
|
||||
order, `cv_score` under the agent's weights, then `cv_fit`, then
|
||||
score (`_by_cv`). So at most twice `summarise_top` per agent. An
|
||||
agent without a prompt with text gives only its match top (its
|
||||
scores have no fit, so they say how fresh a role is, not whether it
|
||||
is wanted), one without a CV only its want top. The role is `r`; no
|
||||
agent that counts is a fragment that holds for no role."""
|
||||
arms: list[str] = []
|
||||
params: list[Any] = []
|
||||
for agent in self.agents(enabled_only=True):
|
||||
top = agent.limits.summarise_top
|
||||
orders = []
|
||||
if any(p.text.strip() for p in agent.prompts):
|
||||
orders.append(f"{_VOTED_SCORE} DESC")
|
||||
if agent.cv_text.strip():
|
||||
orders.append(_by_cv(_cv_sql(agent.weights)) + f"{_VOTED_SCORE} DESC")
|
||||
for order in orders:
|
||||
arms.append(f"""SELECT uid FROM (
|
||||
SELECT s.uid FROM scores s
|
||||
JOIN roles top ON top.uid = s.uid AND top.closed_at IS NULL
|
||||
AND top.dup_of IS NULL
|
||||
LEFT JOIN role_votes v ON v.uid = s.uid AND v.agent_id = s.agent_id
|
||||
LEFT JOIN role_judgements j ON j.uid = s.uid AND j.agent_id = s.agent_id
|
||||
AND j.judged_at IS NOT NULL
|
||||
WHERE s.agent_id = ? AND s.gated_reason = ''
|
||||
AND top.company_key NOT IN (
|
||||
SELECT company_key FROM agent_companies
|
||||
WHERE agent_id = s.agent_id AND affinity = -1)
|
||||
ORDER BY {order}, top.posted_at DESC, s.uid LIMIT ?)""")
|
||||
params += [agent.id, top]
|
||||
if not arms:
|
||||
return "0", []
|
||||
return f"r.uid IN ({' UNION '.join(arms)})", params
|
||||
|
||||
def _extract_scope(self, uids: Sequence[str] | None) -> tuple[str, list[Any]]:
|
||||
"""The `WHERE` for a role `extract` may read: open, never answered,
|
||||
@@ -1845,9 +1857,9 @@ class Store:
|
||||
some text to summarise. Given `uids`, those of them and nothing else,
|
||||
open or not and given up or not, because somebody asked for them.
|
||||
Otherwise open, not given up, and in the top of an enabled agent's
|
||||
feed (`_summarise_top`) or one the owner cares about whatever its
|
||||
rank: saved (it has an application) or voted up by an enabled
|
||||
agent."""
|
||||
feed in either order (`_summarise_top`) or one the owner cares about
|
||||
whatever its rank: saved (it has an application) or voted up by an
|
||||
enabled agent."""
|
||||
where = ["r.summary = ''",
|
||||
"(TRIM(r.article_text) <> '' OR TRIM(r.description) <> '')"]
|
||||
if uids is not None:
|
||||
@@ -1875,9 +1887,10 @@ class Store:
|
||||
return int(row["n"]) if row else 0
|
||||
|
||||
def summarise_waiting(self, limit: int, uids: Sequence[str] | None = None) -> list[Role]:
|
||||
"""Roles `summarise` has yet to write, newest first: the best
|
||||
`summarise_top` final scores of every enabled agent, so the backlog
|
||||
is bounded by the agents rather than by the number of open roles,
|
||||
"""Roles `summarise` has yet to write, newest first: the top
|
||||
`summarise_top` of every enabled agent's want order and of its match
|
||||
order (`_summarise_top`), so the backlog is bounded by the agents
|
||||
rather than by the number of open roles,
|
||||
and every open role that is saved or voted up by an enabled agent,
|
||||
whatever its rank; given `uids`, those still without a summary,
|
||||
whatever their rank. A batch asks again when it runs."""
|
||||
@@ -2288,7 +2301,7 @@ class Store:
|
||||
def score_candidates(self, agent_id: int, gates: Sequence[Gate]) -> list[Candidate]:
|
||||
"""Every open role of a company this agent has not hidden, copies
|
||||
(`rebuild_dupes`) aside, with the agent's affinity for the company,
|
||||
the company's All countries and All roles, and how the role meets
|
||||
the company's All locations and All roles, and how the role meets
|
||||
each gate: 1 match, 0 no match, -1 the column is empty. The gates are
|
||||
evaluated here, in SQL, so a `require` gate is the `WHERE` it reads
|
||||
as, written as a column so a gated role keeps its row and reason."""
|
||||
@@ -2467,7 +2480,7 @@ class Store:
|
||||
return self._company(key)
|
||||
|
||||
def set_all_countries(self, key: str, on: bool) -> Company:
|
||||
"""Switch a company's All countries override: its big boards are read
|
||||
"""Switch a company's All locations override: its big boards are read
|
||||
with the agents' wide reach, Europe today, rather than their places,
|
||||
from the next pull (`app/jobs/reach.py`). Global, not per agent.
|
||||
Raises KeyError for an unknown company."""
|
||||
@@ -2536,7 +2549,7 @@ class Store:
|
||||
def merge_companies(self, keep: str, other: str) -> Company:
|
||||
"""Fold company `other` into `keep`, in one transaction: its roles and
|
||||
subscriptions move to `keep`, each agent's stance moves unless the
|
||||
agent has one on `keep` already, the All countries and All roles
|
||||
agent has one on `keep` already, the All locations and All roles
|
||||
overrides carry over, its aliases and its name become aliases of
|
||||
`keep`, and its row goes. Copies are not recomputed (`rebuild_dupes`).
|
||||
Raises KeyError for an unknown company and ValueError for merging one
|
||||
|
||||
Reference in new issue
Block a user