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:
WolfandClaude Opus 5.5 committed 2026-10-04 21:40:32 +02:00
1 parent 6cad9713ac
commit 6d82287402
27 files changed
+390 -247

No files matched your search

+2 -2
View File
@@ -55,8 +55,8 @@ class ExtractConfig(ModelTaskConfig):
class SummariseConfig(ModelTaskConfig):
"""About 60 words on a role, for the list and the read page. See
app/jobs/summarise.py. Off by default like extract; on, a pull summarises
the best `summarise_top` final scores of each enabled agent (its
`limits`), so the cost is bounded whatever the backlog, and every role
the top `summarise_top` (its `limits`) of each enabled agent's want order
and of its match order, so the cost is bounded whatever the backlog, and every role
that is saved or liked, whatever its rank. The read page's Summarise button asks for one
role whether this is on or not."""
+3 -2
View File
@@ -22,8 +22,9 @@ it filled none, `step` passes over all three. Extract reads the cut; the
score after it applies the fetch gate and the cut again with the columns
extract filled, so a role can drop out or enter (one that enters is
extracted on the next pull). Judge reads each agent's cut as recomputed,
against its CV. Summarise runs last, on the top of each agent's feed by
final score and the roles liked or saved: it is no part of any score.
against its CV. Summarise runs last, on the top of each agent's feed in
the want order and in the match order, and the roles liked or saved: it is
no part of any score.
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
+30 -21
View File
@@ -2,15 +2,17 @@
A `ModelTask` beside `summarise`, after the `/rank` of
github.com/MadsLorentzen/ai-job-search: the model reads a posting against a
written profile and scores skills, experience and career 0 to 100, with one
to three strengths and gaps. The total is `app.models.cv_score`, the three
numbers under the agent's `cv_*` weights, worked out when a role is served and
not stored, so the weights are no part of `input_key`; it is what the feed's
CV match sorts by. The model also reports a verdict on each of the
written profile and scores skills, experience and career 0 to 10, with one
to three strengths and gaps. A model's rating is an estimate, so the scale is
coarse. The total is `app.models.cv_score`, the three numbers under the
agent's `cv_*` weights times 10, so 0 to 100, worked out when a role is served
and not stored, so the weights are no part of `input_key`; it is what the
feed's CV match sorts by. The model also reports a verdict on each of the
agent's must-haves (one per line of its must text, numbered M1..Mn in the
prompt); it does not apply them. The rule is code's: a "broken" one makes
career count as at most `app.models.BROKEN_CAP`, when the role is served. Culture and location are left out: the first
is guessed from ad text, the second is what the fetch gate does.
career count as at most `app.models.BROKEN_CAP` (4), when the role is
served. Culture and location are left out: the first is guessed from ad text,
the second is what the fetch gate does.
The work is pairs, `(agent, role)`: an enabled agent with a CV and a prompt,
and an open role in its cut (`scores.cut`, see `app.jobs.score`: the best by
@@ -63,7 +65,8 @@ EXCERPT = 8000
#: 2: the verdict on each numbered must-have (`musts`), the cap in code.
#: 3: what the person likes (`like_text`) beside what they do not, and the
#: career rubric reading both.
FORMAT = 3
#: 4: the three numbers 0 to 10 rather than 0 to 100.
FORMAT = 4
#: How many strengths and gaps are kept, and how long each may be.
MOST, LONGEST = 3, 300
@@ -75,20 +78,20 @@ what they do not like (the work, the workplace, situations), and their
must-haves and deal-breakers when they gave any. Each item is one posting with a key, its title, company, place
and text. Answer one judgement per item.
Score three dimensions, each 0 to 100:
- skills: 80-100 the core requirements are the person's primary skills; 60-79
most requirements match, with 1-2 gaps that are learnable; 40-59 a partial
match, significant upskilling needed; 0-39 a fundamental mismatch.
Score three dimensions, each a whole number from 0 to 10:
- skills: 8-10 the core requirements are the person's primary skills; 6-7
most requirements match, with 1-2 gaps that are learnable; 4-5 a partial
match, significant upskilling needed; 0-3 a fundamental mismatch.
- experience: match on the function and nature of the work performed, not the
literal job title, and on its level. 80-100 direct experience in the same
domain and role type; 60-79 related, with transferable skills clear; 40-59
adjacent, the person would need to make the case; 0-39 unrelated.
literal job title, and on its level. 8-10 direct experience in the same
domain and role type; 6-7 related, with transferable skills clear; 4-5
adjacent, the person would need to make the case; 0-3 unrelated.
- career: against what the person wants (the prompts), what they like and
what they do not like. 80-100 strongly
aligned with their direction, with clear growth; 60-79 a good role, partly
aligned; 40-59 a decent job that does not build toward their goals; 0-39 a
dead end or a step backwards. Judge whether the tasks and the setting would
energise them, not only whether they could do them.
what they do not like. 8-10 strongly aligned with their direction, with
clear growth; 6-7 a good role, partly aligned; 4-5 a decent job that does
not build toward their goals; 0-3 a dead end or a step backwards. Judge
whether the tasks and the setting would energise them, not only whether
they could do them.
Their must-haves and deal-breakers are numbered M1, M2 and so on. Give a
verdict on every one of them, in `musts`, for each item:
@@ -269,10 +272,16 @@ def build_batch(config: Config, store: Store, limit: int = 5,
# -------------------------------------------------------------------- answer
#: The top of the judge's scale.
TOP = 10
def _mark(value: Any) -> int | None:
"""One of the three numbers, rounded and held to 0..`TOP`; None for
anything not a number."""
if isinstance(value, bool) or not isinstance(value, int | float):
return None
return max(0, min(100, round(value)))
return max(0, min(TOP, round(value)))
def _lines(value: Any) -> list[str]:
+9 -9
View File
@@ -10,7 +10,7 @@ on. Computed once per pull (`plan`) and handed to each board's batch as the
empty, or holds any other member (a function, a remote value other than
`remote`, a place the gazetteer does not know), can take a role from
anywhere, so the base reach is then everywhere.
- **Wide reach, for the companies set to All countries**
- **Wide reach, for the companies set to All locations**
(`companies.all_countries`, global): the union over the enabled agents of
their `require` reach, the intersection of each one's `require` gates on
country and place, Europe today, expanded to its countries through the
@@ -272,7 +272,7 @@ class Plan:
def why(self, sub: Subscription) -> tuple[Reach, str]:
"""The reach `sub` is read with, and why: `override`, `small`,
`unknown` (a board never read whole), `countries` (its company is
set to All countries) or `agents`."""
set to All locations) or `agents`."""
if OVERRIDE_KEYS & set(sub.params or {}):
return EVERYWHERE, "override"
size = self.sizes.get(sub.target)
@@ -296,7 +296,7 @@ class Plan:
def for_subscription(self, sub: Subscription) -> dict[str, Any] | None:
"""The `reach` a board's batch hands `ask_for`; None for none. With
fetch terms, and unless its company is set to All roles, a big board
carries them, and `wide` when its company is set to All countries, for
carries them, and `wide` when its company is set to All locations, for
`ask_for` to decide which side gives way over `MAX_SERIES` (see the
module docstring). A board with no size carries
`unsized` and `small`, and the reach of a big board unless its params
@@ -360,7 +360,7 @@ def plan(store: Store, subs: Iterable[Subscription] | None = None) -> Plan:
base = wide = EVERYWHERE
subs = list(store.subscriptions(source="ats") if subs is None else subs)
rows = store.companies()
# All countries never reads less than the board would without it: the
# All locations never reads less than the board would without it: the
# base's remote, which a `require` of Europe does not name, is kept.
return Plan(base, wide | base, sizes(store, subs),
all_countries=frozenset(c.key for c in rows if c.all_countries),
@@ -380,7 +380,7 @@ def reaches(store: Store, subs: Iterable[Subscription]) -> Mapping[str, dict[str
#: Why a board is read whole, as the Companies list says it.
_WHOLE = {"small": f"under {SMALL} roles", "unknown": "size not known yet",
"override": "set here", "countries": "all countries (everywhere)",
"override": "set here", "countries": "all locations (everywhere)",
"agents": "an agent takes any place"}
@@ -452,8 +452,8 @@ def line(found: Plan, sub: Subscription) -> str:
"follows agents: DK, SE, remote · follows agents' terms: engineer,
product", "follows agents: DK, SE, remote · all roles" (a company set to
All roles, or a reader without a query, or terms over `MAX_SERIES`),
"all countries (Europe) · follows agents' terms: engineer, product,
data", "all countries (Europe) · all roles", "set here: DE · all roles",
"all locations (Europe) · follows agents' terms: engineer, product,
data", "all locations (Europe) · all roles", "set here: DE · all roles",
"all places, too many countries to ask · follows agents' terms:
engineer", or, for a board read whole, why: "under 300 roles: read
whole", "Greenhouse cannot filter: read whole". A board with no size yet
@@ -485,13 +485,13 @@ def line(found: Plan, sub: Subscription) -> str:
else "")
if why == "countries":
named = found.wide_names or f"{len(found.wide.countries)} countries"
return f"all countries ({named}){unasked} · {roles}"
return f"all locations ({named}){unasked} · {roles}"
if why == "override":
return f"set here: {_places(ask)}{unasked} · {roles}"
return f"follows agents: {_places(ask)}{unasked} · {roles}"
if ask.terms:
if given.everywhere:
what = "all countries (everywhere)" if why == "countries" else _WHOLE[why]
what = "all locations (everywhere)" if why == "countries" else _WHOLE[why]
return f"{what} · {roles}"
return f"all places, too many countries to ask · {roles}"
if why in ("agents", "countries") and given.everywhere:
+4 -4
View File
@@ -10,7 +10,7 @@ good for a given search. Each agent first applies its fetch gate:
any gates one group, the place part: a role that matches none of
them, and has the column filled for at least one, is
gated ("none of country DK / remote remote"); skipped for
a company set to All countries
a company set to All locations
exclude gates a role that matches one of the values keeps its row, with
score 0 and the value ("title account executive"); those
on `title` are skipped for a company set to All roles
@@ -42,8 +42,8 @@ all there is, when it is gated as "no vector". An agent with no votes scores
every role without `taste`; the direction is newsdesk's
`centroid(liked) - centroid(disliked)`. An agent with no prompt that has
text has no `fit` either, so nothing of it enters the cut by fit and its
scores do not decide what summarise reads (`Store._summarise_top`); a run
names such agents in one notice.
want order does not decide what summarise reads (`Store._summarise_top`); a
run names such agents in one notice.
Beside the score, `fit` is stored as it is, and for an agent with a CV,
`cv_fit`: how close the role is to the CV, the best cosine between the role
@@ -181,7 +181,7 @@ def failed_gates(candidate: Candidate, gates: Sequence[Gate]) -> list[str]:
it fails, every exclude gate it matches, and the `any` group when it
matches none of them. A gate with an empty column (state -1) neither
passes nor fails, so the group fails only when some member had evidence.
A company set to All countries skips the `any` group, the place part,
A company set to All locations skips the `any` group, the place part,
and one set to All roles the exclude gates on `title`, the titles to
leave out; the require gates, the region, apply to every company."""
states = list(zip(gates, candidate.gates, strict=True))
+4 -2
View File
@@ -7,8 +7,10 @@ answer), and running it is `desk.modeltask`'s.
A role is waiting while it has no summary, has some text, is open and no copy,
and is either in the top of an enabled agent's feed, the best `summarise_top`
final scores among the roles its fetch gate passes (its `limits`), or one the
owner cares about whatever its rank: saved (it has an application, the star)
(its `limits`, 30 by default) by the want feed score and the best
`summarise_top` by the match order (CV match, then CV closeness) among the
roles its fetch gate passes, so at most twice that many, or one the owner
cares about whatever its rank: saved (it has an application, the star)
or voted up by an enabled agent. Summarise is no part of any score and runs
last in the pull, once the final scores are set. The limit keeps the cost
flat: a pull summarises the roles somebody will look at, not the 30k that are
+24 -17
View File
@@ -1008,11 +1008,12 @@ def language_flag(required: list[RoleLanguage],
return "", ""
#: What career counts as at most when a posting breaks one of the agent's
#: must-haves: the top of the rubric's 0-39 band for a dead end. The model
#: What career counts as at most, on the judge's 0 to 10, when a posting
#: breaks one of the agent's must-haves: the foot of the rubric's 4-5 band,
#: a decent job that does not build toward the person's goals. The model
#: reports whether each must-have is met; this cap is applied in code, when a
#: role is served (`cv_score`, `Store.judgement`, `store._cv_sql`).
BROKEN_CAP = 39
BROKEN_CAP = 4
#: A must-have's verdict, as the judge answers it.
MUST_VERDICTS = ("met", "broken", "unclear")
@@ -1040,17 +1041,18 @@ def capped_career(career: int, broken: int = 0) -> int:
def cv_score(skills: int, experience: int, career: int,
weights: Weights | None = None, broken: int = 0) -> float | None:
"""The one number of a CV match, 0 to 100: the three numbers of the
judge averaged by the agent's `cv_skills`, `cv_experience` and
`cv_career` weights (30, 25 and 30 by default), career as
`capped_career` has it. None when all three weights are 0."""
"""The one number of a CV match, 0 to 100 for sorting and display: the
judge's three numbers, each 0 to 10, averaged by the agent's
`cv_skills`, `cv_experience` and `cv_career` weights (30, 25 and 30 by
default), career as `capped_career` has it, times 10. None when all
three weights are 0."""
w = weights or Weights()
total = w.cv_skills + w.cv_experience + w.cv_career
if not total:
return None
career = capped_career(career, broken)
return round((w.cv_skills * skills + w.cv_experience * experience
+ w.cv_career * career) / total, 1)
return round(10 * (w.cv_skills * skills + w.cv_experience * experience
+ w.cv_career * career) / total, 1)
class Must(Model):
@@ -1064,8 +1066,9 @@ class Must(Model):
class Judgement(Model):
"""What `judge` read of one role for one agent (`role_judgements`): the
three dimensions 0 to 100 as the model gave them, `cv_score`
(`cv_score`) and 1 to 3 strengths and gaps grounded in the posting.
three dimensions 0 to 10 as the model gave them, `cv_score`
(`cv_score`, 0 to 100) and 1 to 3 strengths and gaps grounded in the
posting.
`musts` is the verdict on each must-have and `broken` how many are
broken; any makes `career_capped` the lower of `career` and
`BROKEN_CAP`. `cv_score` and `career_capped` are not read from the
@@ -1387,7 +1390,8 @@ class Company(Model):
#: not on that list.
hand_reason: str = ""
#: The two fetch overrides (`app/jobs/reach.py`), global rather than an
#: agent's, since fetching is shared. `all_countries` 1: every big board
#: agent's, since fetching is shared. `all_countries` 1 (All locations,
#: as the switch is called; the column keeps its name): every big board
#: of the company is read with the agents' wide reach, Europe today,
#: rather than their places. `all_roles` 1: no role-type narrowing, no
#: fetch terms today, on any of its boards.
@@ -1459,7 +1463,7 @@ class Gate(Model):
fails it (the row is kept with the reason); the `any` gates together are
one group a role must match at least one of ("in Denmark, or remote");
`exclude` gates a role that matches any of its values ("title account
executive"). A company set to All countries skips the `any` group and one
executive"). A company set to All locations skips the `any` group and one
set to All roles skips the `exclude` gates on `title` (`score.failed_gates`).
A gate rejects on evidence only: a role whose column is empty is not
rejected, since `extract` fills the column later for the roles in the
@@ -1497,14 +1501,16 @@ class Limits(Model):
leaves out, then every role liked or saved. Both levels are calibrated
(`score.scale`) with the company's affinity as a small bonus, so a
minimum means the same in every run. For a broad agent the count stops a
list, for a narrow one the minimum. Summarise reads the best
`summarise_top` by final score, and every role liked or saved."""
list, for a narrow one the minimum. Summarise reads the top
`summarise_top` of the want feed score (the score order) and the top
`summarise_top` of the match order (CV match, then CV closeness), so at
most twice as many, and every role liked or saved."""
cut_fit_top: int = Field(500, ge=0)
cut_fit_min: float = Field(0.6, ge=0, le=1)
cut_cv_top: int = Field(150, ge=0)
cut_cv_min: float = Field(0.6, ge=0, le=1)
summarise_top: int = Field(50, ge=0)
summarise_top: int = Field(30, ge=0)
class Prompt(Model):
@@ -1616,7 +1622,8 @@ class Candidate(Model):
uid: str
posted_at: str
affinity: int = 0
#: `companies.all_countries`: the `any` group (the place part) is skipped.
#: `companies.all_countries`, All locations: the `any` group (the place
#: part) is skipped.
all_countries: bool = False
#: `companies.all_roles`: the `exclude` gates on `title` are skipped.
all_roles: bool = False
+29 -3
View File
@@ -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
View File
@@ -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
+20 -18
View File
@@ -70,7 +70,6 @@ def _feed_filters(
function: str = "",
remote: str = "",
days: int | None = None,
show_muted: bool = False,
include_read: bool = True,
tags: list[str] = Query(default=[]),
tag_mode: Literal["any", "all"] = "any",
@@ -96,7 +95,8 @@ def _feed_filters(
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`). A request that names an agent keeps to its fetch gate in
every order, newest included (`fetch_gate`), unless `gated`."""
every order, newest included (`fetch_gate`), unless `gated`, and never
shows a company the agent hid."""
for token in tokens:
if not places.known(token):
raise HTTPException(422, f"No place is known as {token!r}.")
@@ -115,7 +115,7 @@ def _feed_filters(
return {
"q": q or None, "company": company or None, "place": place or None,
"function": function or None, "remote": remote or None, "days": days,
"hide_muted": not show_muted, "include_read": include_read, "tags": tags,
"include_read": include_read, "tags": tags,
"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,
@@ -155,7 +155,8 @@ def role_facets(store: StoreDep, filters: FeedFilters) -> Facets:
def get_role(uid: str, store: StoreDep, agent: int | None = None) -> ScoredRole:
"""One role, open or closed, for the read page, with `agent`'s vote and
score, the prompt that gave its fit, its `judgement` against the agent's
CV and the language flag (the default agent's when absent;
CV (`skills`, `experience` and `career` 0 to 10, `cv_score` 0 to 100)
and the language flag (the default agent's when absent;
None when there is no agent). `copies` lists the open copies of a kept
role (`RoleCopy`, for "Also posted"); a copy itself opens too, with
`dup_of` naming its kept role."""
@@ -235,9 +236,9 @@ def list_roles(
`Store.roles` for what each filter does.
`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. Every order keeps to the roles that agent's fetch gate passes,
role carries that agent's `vote`; a company it hid is always left out,
in every order, the total and the facets; `judged` keeps the liked, the
unjudged or the 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
@@ -255,8 +256,8 @@ def list_roles(
as well. `closing=1` keeps the roles whose `deadline` is today or in
the next four days (Closing soon).
Each row carries `deadline`, the agent's `cv_score` (None when not
judged), and `lang_flag` and `lang_note`, the posting's languages
Each row carries `deadline`, the agent's `cv_score` (0 to 100, None
when not judged), and `lang_flag` and `lang_note`, the posting's languages
against the agent's (`app.models.language_flag`).
`company` and `place` are substrings, kept for links from other pages.
@@ -290,14 +291,13 @@ class FiltersOut(BaseModel):
@router.get("/filters")
def list_filters(store: StoreDep, show_muted: bool = False,
agent: int | None = None) -> FiltersOut:
def list_filters(store: StoreDep, agent: int | None = None) -> FiltersOut:
"""The tag vocabulary for the feed's filter row, most-used first. The
companies `agent` hid (the default agent's without one) are left out
unless `show_muted`, matching `/api/roles`."""
companies `agent` hid (the default agent's without one) are left out,
matching `/api/roles`."""
hidden_for = _agent_id(store, agent)
return FiltersOut(tags=[TagCount(tag=tag, count=count, unread=unread)
for tag, count, unread in store.tag_counts(hidden_for, show_muted)])
for tag, count, unread in store.tag_counts(hidden_for)])
# ------------------------------------------------------------ suggestions
@@ -506,9 +506,10 @@ class CompanyOut(BaseModel):
`careers_opened_at` are the Watchlist's (`Company`'s), the latter also
when a person last looked at the careers page. `by_hand` marks a company
with no board shown that is not `from_search`, and `hand_reason` says why
it is read by hand (`app.models.HAND_REASONS`). `all_countries` and
`all_roles` are the company's two fetch overrides: its big boards read
with the agents' wide reach, and with no role-type narrowing. `target` is
it is read by hand (`app.models.HAND_REASONS`). `all_countries` (All
locations) and `all_roles` (All roles) are the company's two fetch
overrides: its big boards read with the agents' wide reach, and with no
role-type narrowing. `target` is
the attached board in full, `host:slug`, where `board` is its host alone;
the page compares it with the board typed to know whether a replacement
closes anything. `ats_slug` cannot stand in for it, since the careers site
@@ -826,7 +827,8 @@ def _override(store: Store, queue: Any, key: str, on: bool, setter: str) -> Comp
@router.post("/companies/{key}/all-countries")
def set_all_countries(key: str, body: OverrideBody, store: StoreDep,
queue: QueueDep) -> Company:
"""All countries on or off: global, apart from affinity. On, the
"""All locations on or off (the field and the path keep the name
`all_countries`): global, apart from affinity. On, the
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