Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat: Add topK and saveUnanalyzed configuration for Greenhouse automation
Khuram Niazdd08469fa10e
diff --git a/__tests__/automationSourceConfig.schema.spec.ts b/__tests__/automationSourceConfig.schema.spec.tsindex eae02e2..dee49ff 100644--- a/__tests__/automationSourceConfig.schema.spec.ts+++ b/__tests__/automationSourceConfig.schema.spec.ts@@ -48,4 +48,47 @@ describe("CreateAutomationSchema conditional validation", () => {});expect(result.success).toBe(true);});++ it("greenhouse accepts topK within 1-50 and a saveUnanalyzed boolean", () => {+ const result = CreateAutomationSchema.safeParse({+ ...base,+ jobBoard: "greenhouse",+ sourceConfig: {+ greenhouse: {+ companies: [{ name: "Anthropic", token: "anthropic" }],+ topK: 25,+ saveUnanalyzed: false,+ },+ },+ });+ expect(result.success).toBe(true);+ });++ it("greenhouse rejects topK of 0", () => {+ const result = CreateAutomationSchema.safeParse({+ ...base,+ jobBoard: "greenhouse",+ sourceConfig: {+ greenhouse: {+ companies: [{ name: "Anthropic", token: "anthropic" }],+ topK: 0,+ },+ },+ });+ expect(result.success).toBe(false);+ });++ it("greenhouse rejects topK of 51", () => {+ const result = CreateAutomationSchema.safeParse({+ ...base,+ jobBoard: "greenhouse",+ sourceConfig: {+ greenhouse: {+ companies: [{ name: "Anthropic", token: "anthropic" }],+ topK: 51,+ },+ },+ });+ expect(result.success).toBe(false);+ });});diff --git a/__tests__/greenhouse-runner.spec.ts b/__tests__/greenhouse-runner.spec.tsindex 88c5b46..53d71eb 100644--- a/__tests__/greenhouse-runner.spec.ts+++ b/__tests__/greenhouse-runner.spec.ts@@ -240,6 +240,71 @@ describe("runAutomation (greenhouse)", () => {expect(byKey.dedup).toBe(1);});+ function automationWithGreenhouseConfig(+ overrides: Record<string, unknown>,+ ): Automation {+ return {+ ...automation,+ sourceConfig: JSON.stringify({+ greenhouse: {+ companies: [{ name: "Acme", token: "acme" }],+ targetTitles: ["Frontend Engineer"],+ keywords: [],+ locations: [],+ strictLocation: false,+ ...overrides,+ },+ }),+ };+ }++ it("does not save floor survivors beyond top-K when saveUnanalyzed is false", async () => {+ const auto = automationWithGreenhouseConfig({+ topK: 2,+ saveUnanalyzed: false,+ });+ (searchGreenhouseJobs as any).mockResolvedValue({+ jobs: [+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ ],+ errors: [],+ });++ const result = await runAutomation(auto);++ expect(result.status).toBe("completed");+ // Only the top-2 analyzed jobs saved; the other 2 floor survivors dropped.+ expect((prisma.job.create as any).mock.calls).toHaveLength(2);+ expect(result.jobsSaved).toBe(2);+ expect((generateText as any).mock.calls.length).toBe(2);+ });++ it("custom topK controls how many jobs get LLM analysis vs saved unanalyzed", async () => {+ const auto = automationWithGreenhouseConfig({ topK: 3 });+ (searchGreenhouseJobs as any).mockResolvedValue({+ jobs: [+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ makeJob("Frontend Engineer", "React"),+ ],+ errors: [],+ });++ const result = await runAutomation(auto);++ expect(result.status).toBe("completed");+ expect((generateText as any).mock.calls.length).toBe(3);+ // All 5 saved: 3 analyzed + 2 unanalyzed floor survivors (saveUnanalyzed+ // defaults to true).+ expect((prisma.job.create as any).mock.calls).toHaveLength(5);+ expect(result.jobsSaved).toBe(5);+ });+// Concurrency semantics (bounded p-limit dispatch, provider-gated).// Ollama forces concurrency 1 (see beforeEach's default userSettings mock// of null -> defaultUserSettings.ai, which is Ollama), so these testsdiff --git a/src/components/automations/AutomationList.tsx b/src/components/automations/AutomationList.tsxindex bfb10e5..946263e 100644--- a/src/components/automations/AutomationList.tsx+++ b/src/components/automations/AutomationList.tsx@@ -40,6 +40,7 @@ import {pauseAutomation,resumeAutomation,} from "@/actions/automation.actions";+import { APP_CONSTANTS } from "@/lib/constants";import Link from "next/link";interface AutomationListProps {@@ -148,6 +149,11 @@ export function AutomationList({greenhouse?.companies ?? [];const ghTitles: string[] = greenhouse?.targetTitles ?? [];const ghLocations: string[] = greenhouse?.locations ?? [];+ const ghKeywords: string[] = greenhouse?.keywords ?? [];+ const ghTopK: number =+ greenhouse?.topK ?? APP_CONSTANTS.MAX_JOBS_PER_RUN;+ const ghSaveUnanalyzed: boolean =+ greenhouse?.saveUnanalyzed !== false;return (<div@@ -202,6 +208,12 @@ export function AutomationList({</span>{" "}{ghTitles.length ? ghTitles.join(", ") : "Any"}</span>+ <span>+ <span className="font-medium text-foreground">+ Keywords:+ </span>{" "}+ {ghKeywords.length ? ghKeywords.join(", ") : "Any"}+ </span><span><span className="font-medium text-foreground">Location:@@ -210,6 +222,18 @@ export function AutomationList({? ghLocations.join(", "): "Any location"}</span>+ <span>+ <span className="font-medium text-foreground">+ Analyzed/run:+ </span>{" "}+ {ghTopK}+ </span>+ <span>+ <span className="font-medium text-foreground">+ Extra listings:+ </span>{" "}+ {ghSaveUnanalyzed ? "on" : "off"}+ </span>{automation.resume && (<span><span className="font-medium text-foreground">diff --git a/src/components/automations/AutomationWizard.tsx b/src/components/automations/AutomationWizard.tsxindex c7ad512..5636b83 100644--- a/src/components/automations/AutomationWizard.tsx+++ b/src/components/automations/AutomationWizard.tsx@@ -41,6 +41,7 @@ import type {} from "@/models/automation.model";import { GreenhouseSearchStep } from "./GreenhouseSearchStep";import { ChevronLeft, ChevronRight, Loader2 } from "lucide-react";+import { APP_CONSTANTS } from "@/lib/constants";const EMPTY_GREENHOUSE: GreenhouseSourceConfig = {companies: [],@@ -48,6 +49,8 @@ const EMPTY_GREENHOUSE: GreenhouseSourceConfig = {keywords: [],locations: [],strictLocation: false,+ topK: APP_CONSTANTS.MAX_JOBS_PER_RUN,+ saveUnanalyzed: true,};function parseEditSourceConfig(@@ -458,6 +461,22 @@ export function AutomationWizard({: "Any location"}</span></div>+ <div className="flex justify-between gap-4">+ <span className="text-muted-foreground">+ Jobs analyzed per run+ </span>+ <span className="font-medium text-right">+ {greenhouseConfig.topK ?? APP_CONSTANTS.MAX_JOBS_PER_RUN}+ </span>+ </div>+ <div className="flex justify-between gap-4">+ <span className="text-muted-foreground">+ Save additional listings+ </span>+ <span className="font-medium text-right">+ {greenhouseConfig.saveUnanalyzed !== false ? "Yes" : "No"}+ </span>+ </div></>) : (<>diff --git a/src/components/automations/GreenhouseSearchStep.tsx b/src/components/automations/GreenhouseSearchStep.tsxindex feb7694..e2e0d5b 100644--- a/src/components/automations/GreenhouseSearchStep.tsx+++ b/src/components/automations/GreenhouseSearchStep.tsx@@ -15,6 +15,7 @@ import { Label } from "@/components/ui/label";import { Button } from "@/components/ui/button";import { Badge } from "@/components/ui/badge";import { Switch } from "@/components/ui/switch";+import { Slider } from "@/components/ui/slider";import {Command,CommandEmpty,@@ -522,6 +523,42 @@ export function GreenhouseSearchStep({}/></div>++ <div className="space-y-2">+ <Label>+ Jobs analyzed per run:{" "}+ {value.topK ?? APP_CONSTANTS.MAX_JOBS_PER_RUN}+ </Label>+ <Slider+ min={1}+ max={APP_CONSTANTS.GREENHOUSE_LISTING_CAP}+ step={1}+ value={[value.topK ?? APP_CONSTANTS.MAX_JOBS_PER_RUN]}+ onValueChange={(next) => onChange({ ...value, topK: next[0] })}+ />+ <p className="text-sm text-muted-foreground">+ The number of listings that get full AI match analysis each run.+ Higher means more coverage but slower, costlier runs.+ </p>+ </div>++ <div className="flex items-start justify-between gap-4 rounded-lg border p-3">+ <div className="space-y-1">+ <Label>Save additional relevant listings</Label>+ <p className="text-sm text-muted-foreground">+ When on, listings that are relevant but didn't make the+ top-K are also saved, lexically-ranked but not yet AI-scored.+ They can be analyzed on-demand later from the discovered jobs+ list.+ </p>+ </div>+ <Switch+ checked={value.saveUnanalyzed !== false}+ onCheckedChange={(checked) =>+ onChange({ ...value, saveUnanalyzed: checked })+ }+ />+ </div></div>);}diff --git a/src/lib/scraper/runner.ts b/src/lib/scraper/runner.tsindex 6f41078..7f4a8bb 100644--- a/src/lib/scraper/runner.ts+++ b/src/lib/scraper/runner.ts@@ -637,6 +637,8 @@ interface GreenhouseRunConfig {keywords: string[];locations: string[];strictLocation: boolean;+ topK: number;+ saveUnanalyzed: boolean;}function parseGreenhouseConfig(@@ -653,6 +655,11 @@ function parseGreenhouseConfig(keywords: Array.isArray(gh.keywords) ? gh.keywords : [],locations: Array.isArray(gh.locations) ? gh.locations : [],strictLocation: !!gh.strictLocation,+ topK:+ typeof gh.topK === "number" && gh.topK > 0+ ? gh.topK+ : APP_CONSTANTS.MAX_JOBS_PER_RUN,+ saveUnanalyzed: gh.saveUnanalyzed !== false,};} catch {return null;@@ -792,6 +799,7 @@ async function runGreenhouseRun(const resumeSkills = extractResumeSkills(resume);const pipeline = runGreenhousePipeline(dedupedJobs, config, resumeSkills, {corpus: jobs,+ k: config.topK,});if (config.strictLocation && config.locations.length > 0) {@@ -880,22 +888,24 @@ async function runGreenhouseRun("[Greenhouse] Run aborted by user",);}- for (const scored of pipeline.toSaveUnanalyzed) {- if (signal?.aborted) break;- try {- await persistDiscoveredJob(- automation,- scored.job,- scalePrerank(scored.score),- {- prerankScore: scored.score,- prerankComponents: scored.components,- analyzed: false,- },- );- jobsSaved++;- } catch (err) {- console.error("[Greenhouse] Failed to save listing:", err);+ if (config.saveUnanalyzed) {+ for (const scored of pipeline.toSaveUnanalyzed) {+ if (signal?.aborted) break;+ try {+ await persistDiscoveredJob(+ automation,+ scored.job,+ scalePrerank(scored.score),+ {+ prerankScore: scored.score,+ prerankComponents: scored.components,+ analyzed: false,+ },+ );+ jobsSaved++;+ } catch (err) {+ console.error("[Greenhouse] Failed to save listing:", err);+ }}}diff --git a/src/models/automation.model.ts b/src/models/automation.model.tsindex 189456b..0d74267 100644--- a/src/models/automation.model.ts+++ b/src/models/automation.model.ts@@ -24,6 +24,8 @@ export interface GreenhouseSourceConfig {keywords?: string[];locations?: string[];strictLocation?: boolean;+ topK?: number;+ saveUnanalyzed?: boolean;}export interface SourceConfig {diff --git a/src/models/automation.schema.ts b/src/models/automation.schema.tsindex 174e161..43a4726 100644--- a/src/models/automation.schema.ts+++ b/src/models/automation.schema.ts@@ -29,6 +29,8 @@ export const GreenhouseSourceConfigSchema = z.object({keywords: z.array(z.string().min(1).max(100)).optional(),locations: z.array(z.string().min(1).max(100)).optional(),strictLocation: z.boolean().optional(),+ topK: z.number().int().min(1).max(APP_CONSTANTS.GREENHOUSE_LISTING_CAP).optional(),+ saveUnanalyzed: z.boolean().optional(),});export const SourceConfigSchema = z.object({