Add a job leads inbox that finds and scores postings
Test and deploy / test (push) Successful in 1m55s
Test and deploy / deploy (push) Successful in 59s

The tracker recorded applications but could not find jobs. A new
pipeline (services/job_leads.go, job_sources.go) polls a watch list of
sources on a timer or on request, files unseen postings as leads, marks
which pass a keyword and location pre-filter, and has Claude score those
against a single search profile through a fourth internal Python route,
/internal/jobs/score.

Sources are Greenhouse, Lever and Ashby company boards (public JSON) and
Adzuna and Reed keyword searches (API keys). The two search fetchers are
written from the providers' documentation and tested only against stubs.

Leads are their own table, not a job status, and are not soft deleted:
the (source_kind, external_id) index is the dedup, so a dismissed lead
has to remain a row. A lead reaches the tracker only by promotion, which
goes through UpsertJobApplication. That upsert moves from the capture
handler into services so promotion and the fetcher can share it; the
capture endpoint's behaviour is unchanged.

/cv/leads is the page: inbox, watch list and profile form. The timer is
off unless JOB_LEADS_ENABLED=true and never runs at start-up, so a
deploy spends no Claude calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 15:03:46 +01:00
co-authored by Claude Opus 5.5
parent 810d3118b3
commit af50e6c8ab
40 changed files with 7295 additions and 407 deletions
+102
View File
@@ -0,0 +1,102 @@
/**
* Job leads for the inbox at /cv/leads: postings the server's fetcher found
* (backend/services/job_leads.go), which are dismissed or promoted into the
* tracker from that page.
*
* Not a createCrudStore(): leads are never created or edited from the browser.
* The mutations here move a lead between its three states, and each returns
* the lead so the local row is replaced rather than the list refetched.
*
* Error contract matches the CRUD stores: fetch() and fetchStatus() record a
* failure on `error` and never throw, because they run from lifecycle hooks
* and a poll timer; everything else throws.
*/
import { defineStore } from "pinia";
import { ref } from "vue";
import { gql } from "@/graphql";
// `description` is deliberately not here: it is the full text of the posting
// and is fetched per lead when asked for, as on the tracker.
const LEAD_FIELDS = `id createdAt sourceKind jobTitle company location url postedAt lastSeenAt matched state score scoreReasons jobAppId`;
export const useJobLeadsStore = defineStore("jobLeads", () => {
const leads = ref([]);
const loading = ref(false);
const error = ref(null);
// { running, lastRunAt, lastError } for the fetcher; null until first read.
const status = ref(null);
/**
* Load every lead, all states. `includeUnmatched` also returns the ones the
* keyword pre-filter rejected, which is most of a company board.
*/
async function fetch({ includeUnmatched = false } = {}) {
loading.value = true;
try {
const data = await gql(
`query JobLeads($includeUnmatched: Boolean) {
jobLeads(includeUnmatched: $includeUnmatched) { ${LEAD_FIELDS} }
}`,
{ includeUnmatched },
);
leads.value = data.jobLeads || [];
error.value = null;
} catch (err) {
error.value = err;
} finally {
loading.value = false;
}
}
function replace(lead) {
const idx = leads.value.findIndex((l) => l.id === lead.id);
if (idx >= 0) leads.value[idx] = lead;
return lead;
}
async function transition(mutation, id) {
const data = await gql(
`mutation ${mutation}($id: ID!) { ${mutation}(id: $id) { ${LEAD_FIELDS} } }`,
{ id },
);
return replace(data[mutation]);
}
/** Each returns the updated lead and throws on failure. */
const dismiss = (id) => transition("dismissJobLead", id);
const restore = (id) => transition("restoreJobLead", id);
/** Adds the lead to the tracker as a saved application. */
const promote = (id) => transition("promoteJobLead", id);
/** The posting text for one lead; `""` when the source gave none. Throws. */
async function fetchDescription(id) {
const data = await gql(
`query JobLeadDescription($id: ID!) { jobLead(id: $id) { description } }`,
{ id },
);
return data.jobLead?.description ?? "";
}
async function fetchStatus() {
try {
const data = await gql(`query JobLeadSyncStatus { jobLeadSyncStatus { running lastRunAt lastError } }`);
status.value = data.jobLeadSyncStatus;
} catch (err) {
error.value = err;
}
return status.value;
}
/**
* Start a fetch-and-score run on the server. Resolves at once — true if it
* started, false if one was already going — and the caller polls
* fetchStatus() to see it finish. Throws on failure.
*/
async function runSync() {
const data = await gql(`mutation RunJobLeadSync { runJobLeadSync }`);
return data.runJobLeadSync;
}
return { leads, loading, error, status, fetch, dismiss, restore, promote, fetchDescription, fetchStatus, runSync };
});