forked from santifer/career-ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfollowup-cadence.mjs
More file actions
339 lines (296 loc) · 11 KB
/
Copy pathfollowup-cadence.mjs
File metadata and controls
339 lines (296 loc) · 11 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
#!/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 } from 'path';
import { fileURLToPath } from 'url';
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');
// --- 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 APPLIED_FIRST = appliedDaysIdx !== -1 ? parseInt(args[appliedDaysIdx + 1]) || 7 : 7;
// --- Cadence config ---
const CADENCE = {
applied_first: APPLIED_FIRST,
applied_subsequent: 7,
applied_max_followups: 2,
responded_initial: 1,
responded_subsequent: 3,
interview_thankyou: 1,
};
// --- 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'];
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]);
}
function parseDate(dateStr) {
if (!dateStr || !/^\d{4}-\d{2}-\d{2}$/.test(dateStr.trim())) return null;
return new Date(dateStr.trim());
}
function daysBetween(d1, d2) {
return Math.floor((d2 - d1) / (1000 * 60 * 60 * 24));
}
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 ---
function resolveReportPath(reportField) {
const match = reportField.match(/\]\(([^)]+)\)/);
if (!match) return null;
const fullPath = join(CAREER_OPS, match[1]);
return existsSync(fullPath) ? match[1] : null;
}
// --- Compute urgency ---
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 ---
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;
const appDate = parseDate(app.date);
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, app.date, 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,
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 ---
const result = analyze();
if (summaryMode) {
printSummary(result);
} else {
console.log(JSON.stringify(result, null, 2));
}
if (result.error) process.exit(1);