Skip to content

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.

feat(jobs): classify and persist job description completeness

Khuram Niaz5f7cc0401e21
diff --git a/__tests__/createJobFromNames.spec.ts b/__tests__/createJobFromNames.spec.ts
index c15eec5..0eed21d 100644
--- a/__tests__/createJobFromNames.spec.ts
+++ b/__tests__/createJobFromNames.spec.ts
@@ -138,7 +138,7 @@ describe("createJobFromNames", () => {
company: "Acme",
});
expect(result.message).toContain("Duplicate detected");
- expect(result.message).toContain("Pass allowDuplicate: true to force create");
+ expect(result.message).toContain("update_job");
expect(createJobRecord).not.toHaveBeenCalled();
});
@@ -162,4 +162,29 @@ describe("createJobFromNames", () => {
expect(result.created).toBe(true);
expect(result.duplicateOf).toBeUndefined();
});
+
+ it("classifies and persists descriptionCompleteness from the raw description", async () => {
+ const full = Array.from({ length: 200 }, () => "word").join(" ");
+ const result = await createJobFromNames(
+ { ...baseInput, jobDescription: full },
+ userId,
+ );
+
+ expect(result.descriptionCompleteness).toBe("full");
+ expect(createJobRecord).toHaveBeenCalledWith(
+ expect.objectContaining({ descriptionCompleteness: "full" }),
+ );
+ });
+
+ it("marks a stub description as title-only", async () => {
+ const result = await createJobFromNames(
+ { ...baseInput, jobDescription: "Frontend Developer, $120k, Remote." },
+ userId,
+ );
+
+ expect(result.descriptionCompleteness).toBe("title-only");
+ expect(createJobRecord).toHaveBeenCalledWith(
+ expect.objectContaining({ descriptionCompleteness: "title-only" }),
+ );
+ });
});
diff --git a/__tests__/descriptionCompleteness.spec.ts b/__tests__/descriptionCompleteness.spec.ts
new file mode 100644
index 0000000..5c5b6c8
--- /dev/null
+++ b/__tests__/descriptionCompleteness.spec.ts
@@ -0,0 +1,41 @@
+import {
+ countWords,
+ classifyDescriptionCompleteness,
+} from "@/lib/jobs/descriptionCompleteness";
+
+const words = (n: number) => Array.from({ length: n }, () => "word").join(" ");
+
+describe("countWords", () => {
+ it("counts whitespace-separated words", () => {
+ expect(countWords("one two three")).toBe(3);
+ });
+
+ it("ignores runs of whitespace, newlines and padding", () => {
+ expect(countWords(" one \n\n two\t three ")).toBe(3);
+ });
+
+ it("returns 0 for empty or whitespace-only input", () => {
+ expect(countWords("")).toBe(0);
+ expect(countWords(" \n ")).toBe(0);
+ });
+});
+
+describe("classifyDescriptionCompleteness", () => {
+ it("classifies a stub as title-only", () => {
+ expect(classifyDescriptionCompleteness(words(39))).toBe("title-only");
+ });
+
+ it("classifies a mid-length description as partial", () => {
+ expect(classifyDescriptionCompleteness(words(40))).toBe("partial");
+ expect(classifyDescriptionCompleteness(words(149))).toBe("partial");
+ });
+
+ it("classifies a full posting as full", () => {
+ expect(classifyDescriptionCompleteness(words(150))).toBe("full");
+ expect(classifyDescriptionCompleteness(words(600))).toBe("full");
+ });
+
+ it("treats empty input as title-only", () => {
+ expect(classifyDescriptionCompleteness("")).toBe("title-only");
+ });
+});
diff --git a/prisma/migrations/20260722065252_job_description_completeness/migration.sql b/prisma/migrations/20260722065252_job_description_completeness/migration.sql
new file mode 100644
index 0000000..33b727e
--- /dev/null
+++ b/prisma/migrations/20260722065252_job_description_completeness/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "Job" ADD COLUMN "descriptionCompleteness" TEXT;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index d3dcbb4..0d02842 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -323,6 +323,9 @@ model Job {
// MCP provenance: which agent/token created this job (null = UI or automation)
createdVia String?
+ // Word-count classification of `description` at write time:
+ // "title-only" | "partial" | "full". Null for pre-existing/UI jobs.
+ descriptionCompleteness String?
@@index([userId, automationId])
@@index([userId, discoveryStatus])
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 48d274e..62f154a 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -106,7 +106,11 @@ export const APP_CONSTANTS = {
MCP_RATE_LIMIT_WINDOW_MS: 60 * 60 * 1000,
MCP_DEFAULT_JOB_TYPE: "Full-time",
MCP_DEFAULT_STATUS: "draft",
- MCP_MATCH_MIN_DESCRIPTION_LENGTH: 200,
+ // Word-count thresholds for job-description completeness. A real posting
+ // runs 300+ words; under 40 is a title/salary stub, not something a fit
+ // score can honestly be computed from.
+ DESCRIPTION_PARTIAL_MIN_WORDS: 40,
+ DESCRIPTION_FULL_MIN_WORDS: 150,
MCP_MATCH_PROVIDER_MARKER: "mcp",
MCP_REVIEW_MIN_RESUME_LENGTH: 400,
diff --git a/src/lib/jobs/createJobFromNames.ts b/src/lib/jobs/createJobFromNames.ts
index 1ca6aa0..fe72eae 100644
--- a/src/lib/jobs/createJobFromNames.ts
+++ b/src/lib/jobs/createJobFromNames.ts
@@ -4,6 +4,8 @@ import { APP_CONSTANTS } from "@/lib/constants";
import { normalizeJobUrl } from "@/lib/scraper/utils";
import { findExistingJobByUrl } from "@/lib/jobs/jobDedupe";
import { createJobRecord } from "@/lib/jobs/createJobRecord";
+import { classifyDescriptionCompleteness } from "@/lib/jobs/descriptionCompleteness";
+import type { DescriptionCompleteness } from "@/models/job.model";
import {
resolveCompany,
resolveJobTitle,
@@ -44,6 +46,7 @@ export interface CreateJobFromNamesResult {
jobId?: string;
duplicateOf?: { id: string; title: string; company: string };
resolutions: ResolvedEntity[];
+ descriptionCompleteness?: DescriptionCompleteness;
message: string;
}
@@ -121,6 +124,8 @@ export async function createJobFromNames(
// Default appliedDate if applied is true but no date provided
const resolvedAppliedDate = applied && !appliedDate ? new Date() : (appliedDate ?? null);
+ const descriptionCompleteness = classifyDescriptionCompleteness(jobDescription);
+
const job = await createJobRecord({
jobTitleId: resolvedTitle.id,
companyId: resolvedCompany.id,
@@ -141,6 +146,7 @@ export async function createJobFromNames(
applied,
tagIds: resolvedTagsResult.resolved.map((t) => t.id),
createdVia: createdVia ?? null,
+ descriptionCompleteness,
});
const message = buildSuccessMessage(resolutions, resolvedTagsResult.dropped, job.id);
@@ -149,6 +155,7 @@ export async function createJobFromNames(
created: true,
jobId: job.id,
resolutions,
+ descriptionCompleteness,
message,
};
}
@@ -213,6 +220,8 @@ function buildDuplicateMessage(
});
return (
`Duplicate detected — existing job "${dup.title}" at "${dup.company}" (id: ${dup.id}). ` +
- `Pass allowDuplicate: true to force create. Resolutions: ${parts.join("; ")}.`
+ `To enrich or correct it, call update_job with jobId "${dup.id}" instead of re-adding. ` +
+ `Pass allowDuplicate: true only if this is genuinely a different posting. ` +
+ `Resolutions: ${parts.join("; ")}.`
);
}
diff --git a/src/lib/jobs/createJobRecord.ts b/src/lib/jobs/createJobRecord.ts
index 7096572..04283ca 100644
--- a/src/lib/jobs/createJobRecord.ts
+++ b/src/lib/jobs/createJobRecord.ts
@@ -19,6 +19,7 @@ export async function createJobRecord(fields: {
coverLetterId?: string | null;
tagIds?: string[];
createdVia?: string | null;
+ descriptionCompleteness?: string | null;
}) {
const { tagIds = [], ...rest } = fields;
return prisma.job.create({
diff --git a/src/lib/jobs/descriptionCompleteness.ts b/src/lib/jobs/descriptionCompleteness.ts
new file mode 100644
index 0000000..e7d34bf
--- /dev/null
+++ b/src/lib/jobs/descriptionCompleteness.ts
@@ -0,0 +1,19 @@
+import { APP_CONSTANTS } from "@/lib/constants";
+import type { DescriptionCompleteness } from "@/models/job.model";
+
+export function countWords(text: string): number {
+ const trimmed = text.trim();
+ if (!trimmed) return 0;
+ return trimmed.split(/\s+/).length;
+}
+
+// Classified from the RAW submitted text, before markdown rendering, so
+// stored HTML tags can never inflate the count.
+export function classifyDescriptionCompleteness(
+ description: string,
+): DescriptionCompleteness {
+ const words = countWords(description);
+ if (words < APP_CONSTANTS.DESCRIPTION_PARTIAL_MIN_WORDS) return "title-only";
+ if (words < APP_CONSTANTS.DESCRIPTION_FULL_MIN_WORDS) return "partial";
+ return "full";
+}
diff --git a/src/models/job.model.ts b/src/models/job.model.ts
index f6a27fa..bd523f8 100644
--- a/src/models/job.model.ts
+++ b/src/models/job.model.ts
@@ -138,3 +138,5 @@ export function getWorkplaceTypeLabel(
if (!code) return fallback;
return (WORKPLACE_TYPES as Record<string, string>)[code] ?? fallback;
}
+
+export type DescriptionCompleteness = "title-only" | "partial" | "full";