feat: deterministic email-driven status suggestions
New EmailStatusClassifier scans a message subject/body for outcome
signals (interview invite, offer, rejection) and suggests a canonical
pipeline status. Priority-ordered so a rejection that mentions the prior
interview still classifies as Rejected. Deterministic - no AI - so it is
instant, reproducible, and safe.
- GET /api/jobapplications/{id}/status-suggestion reads the job's latest
inbound correspondence (incl. Gmail imports) and suggests a forward
status move, suppressed when already in/past that stage
- always human-confirmed via the existing PATCH .../status
- 7 classifier unit tests + 2 endpoint integration tests; backend green (133)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1604,6 +1604,57 @@ Canonical profile:
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
public sealed record StatusSuggestionDto(
|
||||
bool HasSuggestion,
|
||||
string? SuggestedStatus,
|
||||
string? CurrentStatus,
|
||||
string? Signal,
|
||||
string? Confidence,
|
||||
DateTime? MessageDate,
|
||||
string? MessageSubject);
|
||||
|
||||
/// <summary>
|
||||
/// Suggests a pipeline status from the job's most recent inbound message (e.g. an interview
|
||||
/// invite or rejection). Deterministic and always human-confirmed via PATCH .../status.
|
||||
/// </summary>
|
||||
[HttpGet("{id:int}/status-suggestion")]
|
||||
public async Task<ActionResult<StatusSuggestionDto>> GetStatusSuggestion([FromRoute] int id, CancellationToken cancellationToken)
|
||||
{
|
||||
var job = await _db.JobApplications.FirstOrDefaultAsync(j => j.Id == id, cancellationToken);
|
||||
if (job is null) return NotFound();
|
||||
|
||||
var none = new StatusSuggestionDto(false, null, job.Status, null, null, null, null);
|
||||
|
||||
var latestInbound = await _db.Correspondences
|
||||
.AsNoTracking()
|
||||
.Where(c => c.JobApplicationId == id
|
||||
&& c.Direction != "outbound"
|
||||
&& c.From != "Me")
|
||||
.OrderByDescending(c => c.Date)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (latestInbound is null) return Ok(none);
|
||||
|
||||
var suggestion = EmailStatusClassifier.Classify(latestInbound.Subject, latestInbound.Content);
|
||||
if (suggestion is null) return Ok(none);
|
||||
|
||||
// Don't nag when the job is already in (or past) the suggested stage.
|
||||
var currentOrder = JobPipeline.OrderOf(job.Status);
|
||||
var suggestedOrder = JobPipeline.OrderOf(suggestion.SuggestedStatus);
|
||||
if (JobPipeline.Normalize(job.Status) == suggestion.SuggestedStatus || currentOrder >= suggestedOrder)
|
||||
{
|
||||
return Ok(none);
|
||||
}
|
||||
|
||||
return Ok(new StatusSuggestionDto(
|
||||
HasSuggestion: true,
|
||||
SuggestedStatus: suggestion.SuggestedStatus,
|
||||
CurrentStatus: job.Status,
|
||||
Signal: suggestion.Signal,
|
||||
Confidence: suggestion.Confidence,
|
||||
MessageDate: latestInbound.Date,
|
||||
MessageSubject: latestInbound.Subject));
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("{id:int}/refresh-ai")]
|
||||
public async Task<ActionResult<JobApplicationDto>> RefreshAi([FromRoute] int id, CancellationToken cancellationToken)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
namespace JobTrackerApi.Services
|
||||
{
|
||||
public sealed record EmailStatusSuggestion(string SuggestedStatus, string Signal, string Confidence);
|
||||
|
||||
/// <summary>
|
||||
/// Deterministic email → pipeline-status classifier. Scans subject/body for outcome signals and
|
||||
/// suggests a canonical status. No AI: instant, reproducible, and safe (the user always confirms).
|
||||
/// Priority matters — a rejection email often still mentions "interview", so rejection wins.
|
||||
/// </summary>
|
||||
public static class EmailStatusClassifier
|
||||
{
|
||||
// Ordered highest-priority first. Each stage lists lowercase phrases to look for.
|
||||
private static readonly (string Status, string Confidence, string[] Phrases)[] Rules =
|
||||
{
|
||||
("Rejected", "high", new[]
|
||||
{
|
||||
"regret to inform", "we regret", "unfortunately, we", "not moving forward",
|
||||
"not be moving forward", "decided not to proceed", "will not be proceeding",
|
||||
"not to proceed", "not been selected", "will not be progressing",
|
||||
"unable to offer", "position has been filled", "no longer being considered",
|
||||
"decided to move forward with other", "pursue other candidates",
|
||||
"not to move forward", "were not successful", "was not successful",
|
||||
}),
|
||||
("Offer", "high", new[]
|
||||
{
|
||||
"pleased to offer", "delighted to offer", "happy to offer", "offer of employment",
|
||||
"job offer", "we would like to offer", "formal offer", "extend an offer",
|
||||
"offer letter", "excited to offer",
|
||||
}),
|
||||
("Interview", "medium", new[]
|
||||
{
|
||||
"invite you to interview", "invite you to an interview", "schedule an interview",
|
||||
"would like to invite you", "phone screen", "phone interview", "video interview",
|
||||
"technical interview", "next steps in the", "your availability for a call",
|
||||
"availability for an interview", "set up a call", "set up an interview",
|
||||
"meet the team", "book a time", "invitation to interview", "interview invitation",
|
||||
"like to speak with you", "move to the interview",
|
||||
}),
|
||||
};
|
||||
|
||||
// Weaker single-word cues only fire when no strong phrase matched (kept low-confidence).
|
||||
private static readonly string[] InterviewWeakCues = { "interview", "assessment", "coding challenge", "take-home" };
|
||||
|
||||
public static EmailStatusSuggestion? Classify(string? subject, string? body)
|
||||
{
|
||||
var text = $"{subject}\n{body}".ToLowerInvariant();
|
||||
if (string.IsNullOrWhiteSpace(text)) return null;
|
||||
|
||||
foreach (var (status, confidence, phrases) in Rules)
|
||||
{
|
||||
var hit = phrases.FirstOrDefault(p => text.Contains(p, StringComparison.Ordinal));
|
||||
if (hit is not null) return new EmailStatusSuggestion(status, hit, confidence);
|
||||
}
|
||||
|
||||
var weak = InterviewWeakCues.FirstOrDefault(c => text.Contains(c, StringComparison.Ordinal));
|
||||
if (weak is not null) return new EmailStatusSuggestion("Interview", weak, "low");
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user