refactor: extract magic numbers to constants, fix audit issues

- Centralize all magic numbers/strings in lib/constants.mjs
- Fix double-replaced import names in filter.mjs
- Consolidate duplicate fs imports in job_applier/job_searcher
- Remove empty JSDoc block in job_searcher
- Update keywords.mjs model from claude-3-haiku to claude-haiku-4-5
- Extract Anthropic API URLs to constants
- Convert :has-text() selectors to page.locator() API
- Fix SIGTERM handler conflict — move partial-run notification into lock.onShutdown
- Remove unused exports (LOCAL_USER_AGENT, DEFAULT_REVIEW_WINDOW_MINUTES)
- Fix variable shadowing (b -> v) in job_filter reduce callback
- Replace SKILL.md PM2 references with system cron

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 08:45:09 -08:00
parent 3a52bdc72e
commit b1528ac0ad
12 changed files with 67 additions and 80 deletions

View File

@@ -6,8 +6,7 @@
*/
import { loadEnv } from './lib/env.mjs';
loadEnv(); // load .env before anything else
/**
*/
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
@@ -35,15 +34,6 @@ async function main() {
const settings = loadConfig(resolve(__dir, 'config/settings.json'));
// Send notification even if SIGTERM kills the process mid-run
process.once('SIGTERM', async () => {
if (totalAdded > 0) {
const summary = formatSearchSummary(totalAdded, totalSeen - totalAdded, platformsRun.length ? platformsRun : ['LinkedIn']);
await sendTelegram(settings, summary + '\n_(partial run — timed out)_').catch(() => {});
}
process.exit(0);
});
const writeLastRun = (finished = false) => {
const entry = {
started_at: startedAt,
@@ -68,9 +58,13 @@ async function main() {
writeFileSync(runsPath, JSON.stringify(runs, null, 2));
};
lock.onShutdown(() => {
lock.onShutdown(async () => {
console.log(' Writing partial results to last-run file...');
writeLastRun(false);
if (totalAdded > 0) {
const summary = formatSearchSummary(totalAdded, totalSeen - totalAdded, platformsRun.length ? platformsRun : ['LinkedIn']);
await sendTelegram(settings, summary + '\n_(partial run — interrupted)_').catch(() => {});
}
});
// Load config