-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Expand file tree
/
Copy pathfollowup-cadence.mjs
More file actions
403 lines (354 loc) · 14 KB
/
Copy pathfollowup-cadence.mjs
File metadata and controls
403 lines (354 loc) · 14 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env node
/**
* followup-cadence.mjs — Follow-up Cadence Tracker for career-ops
*
* Parses applications.md + follow-ups.md, calculates follow-up cadence
* for active applications, extracts contacts, and flags overdue entries.
*
* Run: node followup-cadence.mjs (JSON to stdout)
* node followup-cadence.mjs --summary (human-readable dashboard)
* node followup-cadence.mjs --overdue-only
* node followup-cadence.mjs --applied-days 10
*/
import { readFileSync, existsSync } from 'fs';
import { join, dirname, relative, sep } from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import yaml from 'js-yaml';
const CAREER_OPS = dirname(fileURLToPath(import.meta.url));
const APPS_FILE = existsSync(join(CAREER_OPS, 'data/applications.md'))
? join(CAREER_OPS, 'data/applications.md')
: join(CAREER_OPS, 'applications.md');
const FOLLOWUPS_FILE = join(CAREER_OPS, 'data/follow-ups.md');
const PROFILE_FILE = process.env.CAREER_OPS_PROFILE || join(CAREER_OPS, 'config/profile.yml');
// --- CLI args ---
const args = process.argv.slice(2);
const summaryMode = args.includes('--summary');
const overdueOnly = args.includes('--overdue-only');
const appliedDaysIdx = args.indexOf('--applied-days');
const appliedDaysOverride = appliedDaysIdx !== -1 ? parseInt(args[appliedDaysIdx + 1], 10) : null;
// --- Cadence config ---
export const DEFAULT_CADENCE = {
applied_first: 7,
applied_subsequent: 7,
applied_max_followups: 2,
responded_initial: 1,
responded_subsequent: 3,
interview_thankyou: 1,
};
const PROFILE_CADENCE_KEYS = {
applied_first_days: 'applied_first',
applied_subsequent_days: 'applied_subsequent',
applied_max_followups: 'applied_max_followups',
responded_initial_days: 'responded_initial',
responded_subsequent_days: 'responded_subsequent',
interview_thankyou_days: 'interview_thankyou',
};
function positiveInteger(value) {
const parsed = Number.parseInt(value, 10);
return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
}
export function loadProfileCadence(profilePath = PROFILE_FILE) {
if (!profilePath || !existsSync(profilePath)) return {};
let raw;
try {
raw = yaml.load(readFileSync(profilePath, 'utf-8')) || {};
} catch {
return {};
}
const source = raw.followup_cadence || {};
const cadence = {};
for (const [profileKey, cadenceKey] of Object.entries(PROFILE_CADENCE_KEYS)) {
const parsed = positiveInteger(source[profileKey]);
if (parsed !== null) cadence[cadenceKey] = parsed;
}
return cadence;
}
export function resolveCadenceConfig({ profilePath = PROFILE_FILE, appliedDays = appliedDaysOverride } = {}) {
const cadence = { ...DEFAULT_CADENCE, ...loadProfileCadence(profilePath) };
const cliApplied = positiveInteger(appliedDays);
if (cliApplied !== null) cadence.applied_first = cliApplied;
return cadence;
}
const CADENCE = resolveCadenceConfig();
// --- Status normalization (mirrors verify-pipeline.mjs) ---
const ALIASES = {
'evaluada': 'evaluated', 'condicional': 'evaluated', 'hold': 'evaluated',
'evaluar': 'evaluated', 'verificar': 'evaluated',
'aplicado': 'applied', 'enviada': 'applied', 'aplicada': 'applied',
'applied': 'applied', 'sent': 'applied',
'respondido': 'responded',
'entrevista': 'interview',
'oferta': 'offer',
'rechazado': 'rejected', 'rechazada': 'rejected',
'descartado': 'discarded', 'descartada': 'discarded',
'cerrada': 'discarded', 'cancelada': 'discarded',
'no aplicar': 'skip', 'no_aplicar': 'skip', 'monitor': 'skip', 'geo blocker': 'skip',
};
const ACTIONABLE_STATUSES = ['applied', 'responded', 'interview'];
export function normalizeStatus(raw) {
const clean = raw.replace(/\*\*/g, '').trim().toLowerCase()
.replace(/\s+\d{4}-\d{2}-\d{2}.*$/, '').trim();
return ALIASES[clean] || clean;
}
// --- Date helpers ---
function today() {
return new Date(new Date().toISOString().split('T')[0]);
}
export function parseDate(dateStr) {
if (!dateStr || !/^\d{4}-\d{2}-\d{2}$/.test(dateStr.trim())) return null;
return new Date(dateStr.trim());
}
// The tracker `date` column is often the evaluation date, while the real
// submission date is recorded in the notes as "Applied YYYY-MM-DD" (or
// "APPLIED ..."). Prefer that so cadence reflects when the application actually
// went out, not when the role was evaluated. Returns the first such date, or
// null when the notes don't carry one (caller falls back to the date column).
export function parseAppliedDate(notes) {
if (!notes) return null;
const m = String(notes).match(/\bapplied\s+(\d{4}-\d{2}-\d{2})/i);
return m ? m[1] : null;
}
export function daysBetween(d1, d2) {
return Math.floor((d2 - d1) / (1000 * 60 * 60 * 24));
}
export function addDays(date, days) {
const result = new Date(date);
result.setUTCDate(result.getUTCDate() + days);
return result.toISOString().split('T')[0];
}
// --- Parse applications.md ---
function parseTracker() {
if (!existsSync(APPS_FILE)) return [];
const content = readFileSync(APPS_FILE, 'utf-8');
const entries = [];
for (const line of content.split('\n')) {
if (!line.startsWith('|')) continue;
const parts = line.split('|').map(s => s.trim());
if (parts.length < 9) continue;
const num = parseInt(parts[1]);
if (isNaN(num)) continue;
entries.push({
num, date: parts[2], company: parts[3], role: parts[4],
score: parts[5], status: parts[6], pdf: parts[7], report: parts[8],
notes: parts[9] || '',
});
}
return entries;
}
// --- Parse follow-ups.md ---
function parseFollowups() {
if (!existsSync(FOLLOWUPS_FILE)) return [];
const content = readFileSync(FOLLOWUPS_FILE, 'utf-8');
const entries = [];
for (const line of content.split('\n')) {
if (!line.startsWith('|')) continue;
const parts = line.split('|').map(s => s.trim());
if (parts.length < 8) continue;
const num = parseInt(parts[1]);
if (isNaN(num)) continue;
entries.push({
num,
appNum: parseInt(parts[2]),
date: parts[3],
company: parts[4],
role: parts[5],
channel: parts[6],
contact: parts[7],
notes: parts[8] || '',
});
}
return entries;
}
// --- Extract contacts from notes ---
function extractContacts(notes) {
if (!notes) return [];
const contacts = [];
const emailRegex = /[\w.-]+@[\w.-]+\.\w+/g;
const emails = notes.match(emailRegex) || [];
for (const email of emails) {
// Try to extract name before email: "Emailed Name at" or "contact: Name"
let name = null;
const beforeEmail = notes.substring(0, notes.indexOf(email));
const nameMatch = beforeEmail.match(/(?:Emailed|emailed|contact[:\s]+|to\s+)([A-Z][a-z]+ ?[A-Z]?[a-z]*)\s*(?:at|@|$)/i);
if (nameMatch) name = nameMatch[1].trim();
contacts.push({ email, name });
}
return contacts;
}
// --- Resolve report path ---
export function resolveReportPath(reportField, appsFile = APPS_FILE, repoRoot = CAREER_OPS) {
const match = reportField.match(/\]\(([^)]+)\)/);
if (!match) return null;
// Report links in the tracker are normalized relative to the tracker file's
// own directory (see PR #760 — `merge-tracker.mjs --migrate`). Resolve against
// dirname(APPS_FILE), not the project root, otherwise relative paths like
// `../reports/...` (the data/applications.md layout) escape above the project.
const fullPath = join(dirname(appsFile), match[1]);
const repoRelative = relative(repoRoot, fullPath).split(sep).join('/');
if (repoRelative.startsWith('../') || repoRelative === '..' || !repoRelative.startsWith('reports/')) return null;
return existsSync(fullPath) ? repoRelative : null;
}
// --- Compute urgency ---
export function computeUrgency(status, daysSinceApp, daysSinceLastFollowup, followupCount) {
if (status === 'applied') {
if (followupCount >= CADENCE.applied_max_followups) return 'cold';
if (followupCount === 0 && daysSinceApp >= CADENCE.applied_first) return 'overdue';
if (followupCount > 0 && daysSinceLastFollowup !== null && daysSinceLastFollowup >= CADENCE.applied_subsequent) return 'overdue';
return 'waiting';
}
if (status === 'responded') {
if (daysSinceApp < CADENCE.responded_initial) return 'urgent';
if (daysSinceApp >= CADENCE.responded_subsequent) return 'overdue';
return 'waiting';
}
if (status === 'interview') {
if (daysSinceApp >= CADENCE.interview_thankyou) return 'overdue';
return 'waiting';
}
return 'waiting';
}
// --- Compute next follow-up date ---
export function computeNextFollowupDate(status, appDate, lastFollowupDate, followupCount) {
if (status === 'applied') {
if (followupCount >= CADENCE.applied_max_followups) return null; // cold
if (followupCount === 0) return addDays(parseDate(appDate), CADENCE.applied_first);
if (lastFollowupDate) return addDays(parseDate(lastFollowupDate), CADENCE.applied_subsequent);
return addDays(parseDate(appDate), CADENCE.applied_first);
}
if (status === 'responded') {
if (lastFollowupDate) return addDays(parseDate(lastFollowupDate), CADENCE.responded_subsequent);
return addDays(parseDate(appDate), CADENCE.responded_subsequent);
}
if (status === 'interview') {
return addDays(parseDate(appDate), CADENCE.interview_thankyou);
}
return null;
}
// --- Main analysis ---
function analyze() {
const apps = parseTracker();
if (apps.length === 0) {
return { error: 'No applications found in tracker.' };
}
const followups = parseFollowups();
// Group follow-ups by app number
const followupsByApp = new Map();
for (const fu of followups) {
if (!followupsByApp.has(fu.appNum)) followupsByApp.set(fu.appNum, []);
followupsByApp.get(fu.appNum).push(fu);
}
const now = today();
const entries = [];
for (const app of apps) {
const normalized = normalizeStatus(app.status);
if (!ACTIONABLE_STATUSES.includes(normalized)) continue;
// Prefer the "Applied YYYY-MM-DD" date from notes; fall back to the column.
const appliedDate = parseAppliedDate(app.notes) || app.date;
const appDate = parseDate(appliedDate);
if (!appDate) continue;
const daysSinceApp = daysBetween(appDate, now);
const appFollowups = followupsByApp.get(app.num) || [];
const followupCount = appFollowups.length;
// Find most recent follow-up
let lastFollowupDate = null;
let daysSinceLastFollowup = null;
if (appFollowups.length > 0) {
const sorted = appFollowups.sort((a, b) => (a.date > b.date ? -1 : 1));
lastFollowupDate = sorted[0].date;
const lastDate = parseDate(lastFollowupDate);
if (lastDate) daysSinceLastFollowup = daysBetween(lastDate, now);
}
const urgency = computeUrgency(normalized, daysSinceApp, daysSinceLastFollowup, followupCount);
const nextFollowupDate = computeNextFollowupDate(normalized, appliedDate, lastFollowupDate, followupCount);
const nextDate = nextFollowupDate ? parseDate(nextFollowupDate) : null;
const daysUntilNext = nextDate ? daysBetween(now, nextDate) : null;
const contacts = extractContacts(app.notes);
const reportPath = resolveReportPath(app.report);
entries.push({
num: app.num,
date: app.date,
appliedDate,
company: app.company,
role: app.role,
status: normalized,
score: app.score,
notes: app.notes,
reportPath,
contacts,
daysSinceApplication: daysSinceApp,
daysSinceLastFollowup,
followupCount,
urgency,
nextFollowupDate,
daysUntilNext,
});
}
// Sort by urgency priority: urgent > overdue > waiting > cold
const urgencyOrder = { urgent: 0, overdue: 1, waiting: 2, cold: 3 };
entries.sort((a, b) => (urgencyOrder[a.urgency] ?? 9) - (urgencyOrder[b.urgency] ?? 9));
const filtered = overdueOnly
? entries.filter(e => e.urgency === 'overdue' || e.urgency === 'urgent')
: entries;
return {
metadata: {
analysisDate: now.toISOString().split('T')[0],
totalTracked: apps.length,
actionable: entries.length,
overdue: entries.filter(e => e.urgency === 'overdue').length,
urgent: entries.filter(e => e.urgency === 'urgent').length,
cold: entries.filter(e => e.urgency === 'cold').length,
waiting: entries.filter(e => e.urgency === 'waiting').length,
},
entries: filtered,
cadenceConfig: CADENCE,
};
}
// --- Summary mode ---
function printSummary(result) {
if (result.error) {
console.log(`\n${result.error}\n`);
return;
}
const { metadata, entries } = result;
console.log(`\n${'='.repeat(70)}`);
console.log(` Follow-up Cadence Dashboard — ${metadata.analysisDate}`);
console.log(` ${metadata.totalTracked} total applications, ${metadata.actionable} actionable`);
console.log(`${'='.repeat(70)}\n`);
if (entries.length === 0) {
console.log(' No active applications to track. Apply to some roles first.\n');
return;
}
// Status summary
const urgencyIcon = { urgent: 'URGENT', overdue: 'OVERDUE', waiting: 'waiting', cold: 'COLD' };
console.log(` ${metadata.urgent} urgent | ${metadata.overdue} overdue | ${metadata.waiting} waiting | ${metadata.cold} cold\n`);
// Table header
console.log(' ' + '#'.padEnd(5) + 'Company'.padEnd(16) + 'Status'.padEnd(12) + 'Days'.padEnd(6) + 'F/U'.padEnd(5) + 'Next'.padEnd(13) + 'Urgency'.padEnd(10) + 'Contact');
console.log(' ' + '-'.repeat(80));
for (const e of entries) {
const urgLabel = urgencyIcon[e.urgency] || e.urgency;
const nextStr = e.nextFollowupDate || '-';
const contactStr = e.contacts.length > 0 ? e.contacts[0].email : '-';
console.log(
' ' +
String(e.num).padEnd(5) +
e.company.substring(0, 15).padEnd(16) +
e.status.padEnd(12) +
String(e.daysSinceApplication).padEnd(6) +
String(e.followupCount).padEnd(5) +
nextStr.padEnd(13) +
urgLabel.padEnd(10) +
contactStr
);
}
console.log('');
}
// --- Run (CLI only; guarded so the module is safely importable for tests) ---
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
const result = analyze();
if (summaryMode) {
printSummary(result);
} else {
console.log(JSON.stringify(result, null, 2));
}
if (result.error) process.exit(1);
}