Nightly categorization of new supplier products

Node · Node · intermediate · modification

Adds the nightly product categorization job. `src/catalog/categorize.js` holds the system prompt (it lists the taxonomy slugs), builds the per-product prompt from the title and description, and maps the model's answer to a known slug or `null`; `test/catalog/categorize.test.js` covers those three helpers. `src/jobs/categorizeProducts.js` reads up to 200 pending products, asks the model for each one through the shared `complete` helper with a 16-token cap, saves the result with the model id and a timestamp, and leaves a product pending when its call fails. `src/llm/models.js` gains a `categorize` entry with the validated snapshot, and `src/jobs/index.js` schedules the job for 02:30 UTC.

Shelfwise, an Express 4 back office for a home-goods store, on Node 22 in CommonJS JavaScript; `@anthropic-ai/sdk` 1.4.0. Scheduled jobs run in a separate worker process (`src/worker.js`, unchanged), which calls `registerJobs(scheduler)`; the existing scheduler takes 5-field cron expressions in UTC and never starts a job while its previous run is still going. `src/llm/client.js` (unchanged) builds the one `Anthropic` client. `src/llm/complete.js` (unchanged) exports `complete({ system, user, model = MODELS.default, maxTokens = 256 })`, which calls `anthropic.messages.create` with that `model`, `system`, `max_tokens: maxTokens`, `temperature: 0` and a single user message, and returns the text of the reply's text blocks joined (`''` when there is none); it does not catch errors. `src/repos/productRepo.js` (MongoDB driver 6.x, unchanged): `findPending(limit)` returns up to `limit` products without a `categorization` field, oldest first, as `{ _id, title, description }`; `saveCategorization(id, { category, model, categorizedAt })` sets `categorization` only if the product still has none and returns whether it did; nothing but this job sets `categorization` on a pending product. Products come from contracted suppliers through the existing feed importer, which enforces a `title` of 1 to 200 characters and a `description` of 0 to 2,000 characters; a misplaced product is corrected by hand in the admin. `src/catalog/taxonomy.js` (unchanged) exports `CATEGORIES`, the store's slugs (lower-case letters and hyphens), among them `kitchen-cookware` and `garden-tools`. `src/logger.js` and `src/jobs/purgeSessions.js` are unchanged. Anthropic's model policy ("Model IDs and versioning" docs page): models before the 4.6 generation carry a date in the ID, and a dated model ID such as `claude-haiku-4-5-20251001` is a pinned version whose underlying model stays constant for the lifetime of the ID; on the Claude API these models also have a shorter alias (`claude-haiku-4-5`) that points to the most recent dated snapshot for that minor version, and that guarantee does not cover the alias. From the 4.6 generation on, a dateless ID such as `claude-sonnet-5-5` is itself the pinned snapshot.

Requirements

Files touched

Review this PR

Node practice