forked from career-ops-hq/career-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch-tailor.mjs
More file actions
100 lines (79 loc) · 2.96 KB
/
Copy pathbatch-tailor.mjs
File metadata and controls
100 lines (79 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
import { readFileSync, existsSync, readdirSync } from 'fs';
import { resolve, join } from 'path';
import { spawnSync } from 'child_process';
import { fileURLToPath } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const batchStateFile = join(__dirname, 'batch', 'batch-state.tsv');
const reportsDir = join(__dirname, 'reports');
function usage() {
console.log(`career-ops batch tailor — bulk generate tailored CVs for high-scoring batch jobs
Usage:
node batch-tailor.mjs [--min-score=4.0]
Options:
--min-score=N Minimum score to tailor (default: 4.0)
`);
process.exit(0);
}
const args = process.argv.slice(2);
if (args.includes('-h') || args.includes('--help')) {
usage();
}
let minScore = 4.0;
for (const arg of args) {
if (arg.startsWith('--min-score=')) {
minScore = parseFloat(arg.split('=')[1]);
}
}
if (!existsSync(batchStateFile)) {
console.error(`ERROR: Batch state file not found at ${batchStateFile}`);
process.exit(1);
}
const lines = readFileSync(batchStateFile, 'utf-8').split('\n');
const toProcess = [];
for (const line of lines) {
if (!line || line.startsWith('id\t')) continue;
const parts = line.split('\t');
if (parts.length < 7) continue;
const id = parts[0];
const url = parts[1];
const status = parts[2];
const reportNum = parts[5];
const scoreStr = parts[6];
if (status === 'completed') {
const score = parseFloat(scoreStr);
if (!isNaN(score) && score >= minScore) {
toProcess.push({ id, url, reportNum, score });
}
}
}
if (toProcess.length === 0) {
console.log(`No completed roles found with score >= ${minScore}.`);
process.exit(0);
}
console.log(`Found ${toProcess.length} roles scoring >= ${minScore}. Beginning bulk tailoring...`);
const reports = existsSync(reportsDir) ? readdirSync(reportsDir) : [];
for (let i = 0; i < toProcess.length; i++) {
const job = toProcess[i];
console.log(`\n[${i + 1}/${toProcess.length}] Tailoring CV for Report ${job.reportNum} (Score: ${job.score}) — ${job.url}`);
// Try to find the local report file to pass to the agent
const matchingReport = reports.find(f => f.startsWith(`${job.reportNum}-`) && f.endsWith('.md'));
const reportContext = matchingReport ? `\nThe evaluation report is available at: reports/${matchingReport}` : '';
const prompt = `Tailor the CV for this role and generate the HTML and PDF CVs. \nURL: ${job.url}\nReport number: ${job.reportNum}${reportContext}`;
const claudeArgs = [
'-p',
'--dangerously-skip-permissions',
'--append-system-prompt-file',
'modes/pdf.md',
prompt
];
const res = spawnSync('claude', claudeArgs, { stdio: 'inherit' });
if (res.error) {
console.error(`Error running claude: ${res.error.message}`);
} else if (res.status !== 0) {
console.error(`Worker exited with status ${res.status}`);
} else {
console.log(`✅ Finished tailoring for Report ${job.reportNum}`);
}
}
console.log('\nBulk tailoring complete.');