Add browser job capture to the job tracker
Deploy with Docker Compose / deploy (push) Successful in 1m31s
Deploy with Docker Compose / deploy (push) Successful in 1m31s
A Violentmonkey userscript, served by the site and installed from /cv/jobs, adds the posting open in the browser (LinkedIn, an ATS, any company page) to the tracker. Claude reads the title, company and location off the page text. - Three token-guarded REST routes under /api/jobs/capture (status, extract, upsert). They take a bearer token, JOB_CAPTURE_TOKEN, because the auth cookies are SameSite=Lax and never sent from another origin. An unset token switches the routes off. - The upsert matches on a canonical posting URL, then (company, job title), so a capture and the email pipeline do not make two rows for one job. - The Claude call is a new internal Python route, /internal/jobs/extract, alongside the rowing reader; the client and fence stripping they share move to python/app/claude.py. - New "saved" status ranked below "applied", and a description column holding the posting text, shown per row on the tracker. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -2,7 +2,7 @@ package services
|
||||
|
||||
import "testing"
|
||||
|
||||
// These tests cover the status progression rule only — statusAdvances, the
|
||||
// These tests cover the status progression rule only — StatusAdvances, the
|
||||
// predicate extracted out of updateJobApplication. The rest of
|
||||
// updateJobApplication (note appending, the DB.Save, the returned counters)
|
||||
// needs a live *gorm.DB and the only driver in go.mod is postgres, so it is
|
||||
@@ -34,6 +34,10 @@ func TestStatusAdvances(t *testing.T) {
|
||||
// ranks above rejected, so this single pair is allowed.
|
||||
{"rejected may still become withdrawn because withdrawn ranks higher", "rejected", "withdrawn", true},
|
||||
|
||||
// saved is a browser capture that has not been applied to yet.
|
||||
{"a saved posting advances once the application is confirmed", "saved", "applied", true},
|
||||
{"an applied row cannot fall back to saved", "applied", "saved", false},
|
||||
|
||||
{"an unknown new status is never applied", "applied", "hired", false},
|
||||
{"an empty new status is never applied", "applied", "", false},
|
||||
{"an unknown new status cannot escape a terminal state either", "rejected", "ghosted", false},
|
||||
@@ -43,8 +47,8 @@ func TestStatusAdvances(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
if got := statusAdvances(c.current, c.next); got != c.want {
|
||||
t.Errorf("statusAdvances(%q, %q) = %v, want %v", c.current, c.next, got, c.want)
|
||||
if got := StatusAdvances(c.current, c.next); got != c.want {
|
||||
t.Errorf("StatusAdvances(%q, %q) = %v, want %v", c.current, c.next, got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -66,7 +70,7 @@ func TestTerminalStatusesRankHighest(t *testing.T) {
|
||||
|
||||
// NormalizeStatus is the guard that keeps Claude's occasional casing drift
|
||||
// ("Interview", "on hold") out of the status column: an unrecognised value
|
||||
// stored verbatim makes statusAdvances treat the row's current status as
|
||||
// stored verbatim makes StatusAdvances treat the row's current status as
|
||||
// unknown, which switches the forward-only rule off for that row entirely.
|
||||
func TestNormalizeStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
@@ -75,6 +79,7 @@ func TestNormalizeStatus(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"a tracked status passes through", "interviewing", "interviewing"},
|
||||
{"saved is tracked, so a capture keeps it", "saved", "saved"},
|
||||
{"casing drift is lowered, not rejected", "Interviewing", "interviewing"},
|
||||
{"surrounding whitespace is trimmed", " offer ", "offer"},
|
||||
{"an untracked status falls back to the pipeline default", "on hold", "applied"},
|
||||
|
||||
@@ -151,14 +151,19 @@ var senderDomains = []string{
|
||||
// map is treated as unknown and never applied. Note that "rejected" and
|
||||
// "withdrawn" sit at the top, so once an application reaches them nothing can
|
||||
// move it back.
|
||||
//
|
||||
// "saved" is the one status no email can produce: it marks a posting captured
|
||||
// from the browser but not applied to yet (handlers/handle_job_capture.go).
|
||||
// It ranks lowest so that the "thanks for applying" email advances the row.
|
||||
var statusOrder = map[string]int{
|
||||
"applied": 0,
|
||||
"screening": 1,
|
||||
"assessment": 2,
|
||||
"interviewing": 3,
|
||||
"offer": 4,
|
||||
"rejected": 5,
|
||||
"withdrawn": 6,
|
||||
"saved": 0,
|
||||
"applied": 1,
|
||||
"screening": 2,
|
||||
"assessment": 3,
|
||||
"interviewing": 4,
|
||||
"offer": 5,
|
||||
"rejected": 6,
|
||||
"withdrawn": 7,
|
||||
}
|
||||
|
||||
// Token persistence
|
||||
@@ -744,27 +749,36 @@ func (s *EmailSyncService) createJobApplication(analysis *EmailAnalysis) (string
|
||||
return "created", &app.ID, nil
|
||||
}
|
||||
|
||||
// statusAdvances reports whether next is a forward move from current through
|
||||
// StatusAdvances reports whether next is a forward move from current through
|
||||
// statusOrder. Emails commonly arrive out of order (a delayed "thanks for
|
||||
// applying" after an interview invite), and this is what stops a stale email
|
||||
// dragging an application backwards. An unknown next status is never applied;
|
||||
// an unknown current status is treated as "anywhere before the start", so any
|
||||
// recognised status can take over from it.
|
||||
func statusAdvances(current, next string) bool {
|
||||
//
|
||||
// Exported because the browser capture endpoint applies the same rule.
|
||||
func StatusAdvances(current, next string) bool {
|
||||
nextOrder, nextExists := statusOrder[next]
|
||||
currentOrder, currentExists := statusOrder[current]
|
||||
return nextExists && (!currentExists || nextOrder > currentOrder)
|
||||
}
|
||||
|
||||
// updateJobApplication advances an existing application's status, but only
|
||||
// ever forwards (see statusAdvances).
|
||||
// ever forwards (see StatusAdvances).
|
||||
func (s *EmailSyncService) updateJobApplication(existing *models.JobApplication, analysis *EmailAnalysis) (string, *uint, error) {
|
||||
if !statusAdvances(existing.Status, analysis.Status) {
|
||||
if !StatusAdvances(existing.Status, analysis.Status) {
|
||||
return "skipped", &existing.ID, nil
|
||||
}
|
||||
|
||||
existing.Status = analysis.Status
|
||||
|
||||
// A row captured as "saved" has no applied date; the email that moves it
|
||||
// to "applied" is the best evidence of when that happened.
|
||||
if existing.AppliedAt == nil && existing.Status == "applied" {
|
||||
now := time.Now()
|
||||
existing.AppliedAt = &now
|
||||
}
|
||||
|
||||
// Append to notes if Claude provided any
|
||||
if analysis.Notes != nil && *analysis.Notes != "" {
|
||||
if existing.Notes != nil && *existing.Notes != "" {
|
||||
@@ -864,7 +878,8 @@ func truncate(s string, maxLen int) string {
|
||||
|
||||
// emailClassificationPrompt must stay in sync with the EmailAnalysis struct:
|
||||
// every key it names is a field there, and the status values it lists are the
|
||||
// keys of statusOrder.
|
||||
// keys of statusOrder — all but "saved", which only the browser capture sets
|
||||
// and no email can mean.
|
||||
const emailClassificationPrompt = `You are an email classifier for job applications. You will receive the subject line, sender, and body of an email. Determine if this email is related to a job application, and if so, extract structured data.
|
||||
|
||||
Return ONLY a JSON object with these exact keys:
|
||||
|
||||
Reference in New Issue
Block a user