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

+101 -4
View File
@@ -385,10 +385,14 @@ CREATE TABLE IF NOT EXISTS role_votes (
PRIMARY KEY (agent_id, uid)
);
-- A role is scored per agent. A gated role keeps its row, with the reason.
-- prompt names the agent's prompt that gave the fit, '' when fit did not count.
-- cv_fit is how close the role is to the agent's CV, 0..1, NULL without a CV
-- or a vector and for a gated role; it is no term of score.
-- A role is scored per agent. A role the fetch gate rejects keeps its row,
-- with the reason. score is the final score, the feed's order. prompt names
-- the agent's prompt that gave the fit, '' when fit did not count. fit is the
-- prompt fit level and cv_fit how close the role is to the agent's CV, both
-- 0..1 before the affinity bonus, NULL without a prompt, a CV or a vector and
-- for a gated role. cut says why the role is in the agent's cut, the roles
-- that get fetch text, extract and judge: 'fit', 'cv', 'kept' (liked or
-- saved), or '' when it is not.
CREATE TABLE IF NOT EXISTS scores (
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
@@ -397,9 +401,23 @@ CREATE TABLE IF NOT EXISTS scores (
scored_at TEXT NOT NULL,
prompt TEXT NOT NULL DEFAULT '',
cv_fit REAL,
fit REAL,
cut TEXT NOT NULL DEFAULT '',
PRIMARY KEY (uid, agent_id)
);
-- The feed's filter settings saved under a name, per agent. query is the
-- feed's query string without the agent. Names are unique per agent
-- regardless of case; a change is a new row.
CREATE TABLE IF NOT EXISTS saved_filters (
id INTEGER PRIMARY KEY,
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
name TEXT NOT NULL,
query TEXT NOT NULL,
created_at TEXT NOT NULL,
UNIQUE (agent_id, name COLLATE NOCASE)
);
-- The vectors of an agent's CV, one per chunk in order, for scores.cv_fit.
-- vec_key is sha1 of the embedding model, the chunking and the CV text, the
-- same on every row of an agent, so an unchanged CV is not embedded again.
@@ -487,6 +505,9 @@ CREATE INDEX IF NOT EXISTS idx_roles_board ON roles(source, subscription_id
CREATE INDEX IF NOT EXISTS idx_application_events
ON application_events(application_id, at);
CREATE INDEX IF NOT EXISTS idx_scores_agent ON scores(agent_id, score DESC);
-- The roles in an agent's cut, which fetch text, extract and judge read.
-- Partial: most roles are in no cut.
CREATE INDEX IF NOT EXISTS idx_scores_cut ON scores(agent_id, uid) WHERE cut <> '';
CREATE INDEX IF NOT EXISTS idx_role_votes_agent ON role_votes(agent_id, vote);
CREATE INDEX IF NOT EXISTS idx_vectors_model ON vectors(model);
CREATE INDEX IF NOT EXISTS idx_role_tags_tag ON role_tags(tag);
@@ -731,6 +752,12 @@ UPDATE roles SET seniority = COALESCE(NULLIF(seniority_model, ''),
# missing. The next score fills them.
(31, "scores.cv_fit and agent_cv_vectors: how close each role is to the agent's CV",
lambda conn: _add_cv_fit(conn)),
# A Python step: gates and limits are JSON. The old limits were bars on
# the blended score and mean nothing on plain fit, so every agent takes
# the new defaults.
(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)),
)
#: What a file created from `SCHEMA` today is already at.
@@ -1094,6 +1121,76 @@ def _add_cv_fit(conn: sqlite3.Connection) -> None:
PRIMARY KEY (agent_id, position))""")
#: What migration 32 writes into every agent's `limits`: `models.Limits` as
#: it stood then, spelled out so a later change of the defaults does not
#: change what this migration did.
_V32_LIMITS = {"cut_fit_top": 500, "cut_fit_min": 0.6, "cut_cv_top": 150, "cut_cv_min": 0.6,
"summarise_top": 50}
_V32 = """
CREATE TABLE IF NOT EXISTS saved_filters (
id INTEGER PRIMARY KEY,
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
name TEXT NOT NULL,
query TEXT NOT NULL,
created_at TEXT NOT NULL,
UNIQUE (agent_id, name COLLATE NOCASE)
);
INSERT OR IGNORE INTO state (key, value)
SELECT 'stage:fetch_text', value FROM state WHERE key = 'stage:enrich';
DELETE FROM state WHERE key = 'stage:enrich';
"""
def _add_cut(conn: sqlite3.Connection) -> None:
"""Migration 32's step. `scores.fit` and `scores.cut`, NULL and empty
until the next score; every agent's `limits` reset to `_V32_LIMITS`;
the `prefer` gates dropped from every agent's `gates` and `weight` from
the others; `saved_filters`; the switch `stage:enrich` renamed
`stage:fetch_text`; and the queued `enrich` and `enrich_batch` jobs
deleted, with a schedule of `enrich` firing `fetch_text`. Runs twice
without harm: limits are reset when the columns are added, and after
that only where they still hold a key the cut does not know."""
columns = {r[1] for r in conn.execute("PRAGMA table_info(scores)")}
fresh = "cut" not in columns
if "fit" not in columns:
conn.execute("ALTER TABLE scores ADD COLUMN fit REAL")
if fresh:
conn.execute("ALTER TABLE scores ADD COLUMN cut TEXT NOT NULL DEFAULT ''")
reset = dropped = 0
for agent_id, raw_limits, raw_gates in conn.execute(
"SELECT id, limits, gates FROM agents").fetchall():
try:
limits = json.loads(raw_limits or "{}")
except ValueError:
limits = None
if fresh or not isinstance(limits, dict) or set(limits) - set(_V32_LIMITS):
conn.execute("UPDATE agents SET limits=? WHERE id=?",
(json.dumps(_V32_LIMITS), agent_id))
reset += 1
try:
gates = json.loads(raw_gates or "[]")
except ValueError:
continue
if not isinstance(gates, list):
continue
kept = [{k: v for k, v in g.items() if k != "weight"} for g in gates
if isinstance(g, dict) and g.get("mode") != "prefer"]
if kept != gates:
dropped += sum(1 for g in gates if isinstance(g, dict) and g.get("mode") == "prefer")
conn.execute("UPDATE agents SET gates=? WHERE id=?", (json.dumps(kept), agent_id))
for statement in _statements(_V32):
conn.execute(statement)
tables = {r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
if "jobs" in tables:
conn.execute("DELETE FROM jobs WHERE state = 'queued' "
"AND kind IN ('enrich', 'enrich_batch')")
if "schedules" in tables:
conn.execute("UPDATE schedules SET kind = 'fetch_text' WHERE kind = 'enrich'")
log.info("migration 32: %d agents' limits reset to the cut's defaults, %d prefer gates "
"dropped", reset, dropped)
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