@forwardimpact/basecamp 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/config/scheduler.json +5 -0
  2. package/package.json +1 -1
  3. package/src/basecamp.js +288 -57
  4. package/template/.claude/agents/chief-of-staff.md +6 -2
  5. package/template/.claude/agents/concierge.md +2 -3
  6. package/template/.claude/agents/librarian.md +4 -6
  7. package/template/.claude/agents/recruiter.md +222 -0
  8. package/template/.claude/settings.json +0 -4
  9. package/template/.claude/skills/analyze-cv/SKILL.md +267 -0
  10. package/template/.claude/skills/create-presentations/SKILL.md +2 -2
  11. package/template/.claude/skills/create-presentations/references/slide.css +1 -1
  12. package/template/.claude/skills/create-presentations/scripts/convert-to-pdf.mjs +47 -0
  13. package/template/.claude/skills/draft-emails/SKILL.md +85 -123
  14. package/template/.claude/skills/draft-emails/scripts/scan-emails.mjs +66 -0
  15. package/template/.claude/skills/draft-emails/scripts/send-email.mjs +118 -0
  16. package/template/.claude/skills/extract-entities/SKILL.md +2 -2
  17. package/template/.claude/skills/extract-entities/scripts/state.mjs +130 -0
  18. package/template/.claude/skills/manage-tasks/SKILL.md +242 -0
  19. package/template/.claude/skills/organize-files/SKILL.md +3 -3
  20. package/template/.claude/skills/organize-files/scripts/organize-by-type.mjs +105 -0
  21. package/template/.claude/skills/organize-files/scripts/summarize.mjs +84 -0
  22. package/template/.claude/skills/process-hyprnote/SKILL.md +2 -2
  23. package/template/.claude/skills/send-chat/SKILL.md +170 -0
  24. package/template/.claude/skills/sync-apple-calendar/SKILL.md +5 -5
  25. package/template/.claude/skills/sync-apple-calendar/scripts/sync.mjs +325 -0
  26. package/template/.claude/skills/sync-apple-mail/SKILL.md +6 -6
  27. package/template/.claude/skills/sync-apple-mail/scripts/parse-emlx.mjs +374 -0
  28. package/template/.claude/skills/sync-apple-mail/scripts/sync.mjs +629 -0
  29. package/template/.claude/skills/track-candidates/SKILL.md +375 -0
  30. package/template/.claude/skills/weekly-update/SKILL.md +250 -0
  31. package/template/CLAUDE.md +63 -40
  32. package/template/.claude/skills/create-presentations/scripts/convert-to-pdf.js +0 -32
  33. package/template/.claude/skills/draft-emails/scripts/scan-emails.sh +0 -34
  34. package/template/.claude/skills/extract-entities/scripts/state.py +0 -100
  35. package/template/.claude/skills/organize-files/scripts/organize-by-type.sh +0 -42
  36. package/template/.claude/skills/organize-files/scripts/summarize.sh +0 -21
  37. package/template/.claude/skills/sync-apple-calendar/scripts/sync.py +0 -242
  38. package/template/.claude/skills/sync-apple-mail/scripts/parse-emlx.py +0 -104
  39. package/template/.claude/skills/sync-apple-mail/scripts/sync.py +0 -455
@@ -0,0 +1,374 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Parse a macOS Mail .emlx or .partial.emlx file and output the plain text body.
4
+ *
5
+ * The .emlx format is: first line = byte count, then RFC822 message, then Apple
6
+ * plist. This script reads the RFC822 portion, walks MIME parts to find
7
+ * text/plain, and prints it to stdout. If the email is HTML-only, falls back to
8
+ * stripping tags and decoding entities.
9
+ *
10
+ * Also exports `parseEmlx()` and `extractBody()` for use by sync-apple-mail.
11
+ */
12
+
13
+ if (process.argv.includes("-h") || process.argv.includes("--help")) {
14
+ console.log(`parse-emlx — extract plain text from .emlx files
15
+
16
+ Usage: node scripts/parse-emlx.mjs <path-to-emlx-file> [-h|--help]
17
+
18
+ Parses a macOS Mail .emlx or .partial.emlx file and prints the plain text
19
+ body to stdout. Falls back to stripping HTML tags for HTML-only emails.`);
20
+ process.exit(0);
21
+ }
22
+
23
+ import { readFileSync } from "node:fs";
24
+
25
+ /**
26
+ * Strip HTML tags and convert to plain text.
27
+ * @param {string} html
28
+ * @returns {string}
29
+ */
30
+ export function htmlToText(html) {
31
+ let text = html;
32
+ // Remove style and script blocks
33
+ text = text.replace(/<(style|script)[^>]*>[\s\S]*?<\/\1>/gi, "");
34
+ // Replace br and p tags with newlines
35
+ text = text.replace(/<br\s*\/?>/gi, "\n");
36
+ text = text.replace(/<\/p>/gi, "\n");
37
+ // Strip remaining tags
38
+ text = text.replace(/<[^>]+>/g, "");
39
+ // Decode common HTML entities
40
+ text = decodeEntities(text);
41
+ // Collapse whitespace
42
+ text = text.replace(/[ \t]+/g, " ");
43
+ text = text.replace(/\n{3,}/g, "\n\n");
44
+ return text.trim();
45
+ }
46
+
47
+ /**
48
+ * Decode HTML entities. Handles named entities and numeric references.
49
+ * @param {string} text
50
+ * @returns {string}
51
+ */
52
+ function decodeEntities(text) {
53
+ const named = {
54
+ amp: "&",
55
+ lt: "<",
56
+ gt: ">",
57
+ quot: '"',
58
+ apos: "'",
59
+ nbsp: " ",
60
+ ndash: "–",
61
+ mdash: "—",
62
+ lsquo: "\u2018",
63
+ rsquo: "\u2019",
64
+ ldquo: "\u201C",
65
+ rdquo: "\u201D",
66
+ hellip: "…",
67
+ copy: "©",
68
+ reg: "®",
69
+ trade: "™",
70
+ bull: "•",
71
+ middot: "·",
72
+ ensp: "\u2002",
73
+ emsp: "\u2003",
74
+ thinsp: "\u2009",
75
+ zwnj: "\u200C",
76
+ zwj: "\u200D",
77
+ };
78
+ return text.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (match, ref) => {
79
+ if (ref.startsWith("#x") || ref.startsWith("#X")) {
80
+ const code = parseInt(ref.slice(2), 16);
81
+ return code ? String.fromCodePoint(code) : match;
82
+ }
83
+ if (ref.startsWith("#")) {
84
+ const code = parseInt(ref.slice(1), 10);
85
+ return code ? String.fromCodePoint(code) : match;
86
+ }
87
+ return named[ref.toLowerCase()] ?? match;
88
+ });
89
+ }
90
+
91
+ /**
92
+ * Parse MIME headers from a raw buffer.
93
+ * Returns { headers: Map<lowercase-name, value[]>, bodyOffset }.
94
+ * @param {Buffer} raw
95
+ * @returns {{ headers: Map<string, string[]>, bodyOffset: number }}
96
+ */
97
+ function parseHeaders(raw) {
98
+ const headers = new Map();
99
+ let i = 0;
100
+ let currentName = "";
101
+ let currentValue = "";
102
+
103
+ while (i < raw.length) {
104
+ // Find end of line
105
+ let eol = raw.indexOf(0x0a, i); // \n
106
+ if (eol === -1) eol = raw.length;
107
+ const lineEnd = eol > i && raw[eol - 1] === 0x0d ? eol - 1 : eol; // strip \r
108
+ const line = raw.subarray(i, lineEnd).toString("utf-8");
109
+ i = eol + 1;
110
+
111
+ // Empty line = end of headers
112
+ if (line === "") {
113
+ if (currentName) {
114
+ const arr = headers.get(currentName) ?? [];
115
+ arr.push(currentValue);
116
+ headers.set(currentName, arr);
117
+ }
118
+ return { headers, bodyOffset: i };
119
+ }
120
+
121
+ // Continuation line (starts with whitespace)
122
+ if (line[0] === " " || line[0] === "\t") {
123
+ currentValue += " " + line.trimStart();
124
+ continue;
125
+ }
126
+
127
+ // New header — save previous
128
+ if (currentName) {
129
+ const arr = headers.get(currentName) ?? [];
130
+ arr.push(currentValue);
131
+ headers.set(currentName, arr);
132
+ }
133
+
134
+ const colonIdx = line.indexOf(":");
135
+ if (colonIdx === -1) continue;
136
+ currentName = line.slice(0, colonIdx).toLowerCase().trim();
137
+ currentValue = line.slice(colonIdx + 1).trim();
138
+ }
139
+
140
+ if (currentName) {
141
+ const arr = headers.get(currentName) ?? [];
142
+ arr.push(currentValue);
143
+ headers.set(currentName, arr);
144
+ }
145
+ return { headers, bodyOffset: raw.length };
146
+ }
147
+
148
+ /**
149
+ * Parse Content-Type header value.
150
+ * @param {string} value - e.g. 'text/plain; charset="utf-8"; boundary="abc"'
151
+ * @returns {{ type: string, params: Record<string, string> }}
152
+ */
153
+ function parseContentType(value) {
154
+ const parts = value.split(";");
155
+ const type = (parts[0] ?? "").trim().toLowerCase();
156
+ const params = {};
157
+ for (let k = 1; k < parts.length; k++) {
158
+ const eq = parts[k].indexOf("=");
159
+ if (eq === -1) continue;
160
+ const name = parts[k].slice(0, eq).trim().toLowerCase();
161
+ let val = parts[k].slice(eq + 1).trim();
162
+ if (val.startsWith('"') && val.endsWith('"')) val = val.slice(1, -1);
163
+ params[name] = val;
164
+ }
165
+ return { type, params };
166
+ }
167
+
168
+ /**
169
+ * Decode a MIME body payload according to Content-Transfer-Encoding.
170
+ * @param {Buffer} data
171
+ * @param {string} encoding
172
+ * @returns {Buffer}
173
+ */
174
+ function decodePayload(data, encoding) {
175
+ const enc = (encoding ?? "").toLowerCase().trim();
176
+ if (enc === "base64") {
177
+ return Buffer.from(data.toString("ascii").replace(/\s/g, ""), "base64");
178
+ }
179
+ if (enc === "quoted-printable") {
180
+ const str = data.toString("ascii");
181
+ const bytes = [];
182
+ for (let j = 0; j < str.length; j++) {
183
+ if (str[j] === "=" && j + 2 < str.length) {
184
+ if (str[j + 1] === "\r" || str[j + 1] === "\n") {
185
+ // Soft line break
186
+ j++; // skip \r or \n
187
+ if (str[j] === "\r" && j + 1 < str.length && str[j + 1] === "\n") j++;
188
+ continue;
189
+ }
190
+ const hex = str.slice(j + 1, j + 3);
191
+ const code = parseInt(hex, 16);
192
+ if (!isNaN(code)) {
193
+ bytes.push(code);
194
+ j += 2;
195
+ continue;
196
+ }
197
+ }
198
+ bytes.push(str.charCodeAt(j));
199
+ }
200
+ return Buffer.from(bytes);
201
+ }
202
+ return data;
203
+ }
204
+
205
+ /**
206
+ * Decode text from a buffer using the given charset.
207
+ * @param {Buffer} data
208
+ * @param {string} [charset]
209
+ * @returns {string}
210
+ */
211
+ function decodeText(data, charset) {
212
+ const cs = (charset ?? "utf-8").toLowerCase().replace(/^(x-|iso_)/i, "iso-");
213
+ try {
214
+ const decoder = new TextDecoder(cs, { fatal: false });
215
+ return decoder.decode(data);
216
+ } catch {
217
+ return data.toString("utf-8");
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Parse a MIME part from raw bytes. Returns { contentType, charset, body }.
223
+ * @param {Buffer} raw
224
+ * @returns {{ contentType: string, charset: string, body: Buffer, headers: Map<string, string[]> }}
225
+ */
226
+ function parsePart(raw) {
227
+ const { headers, bodyOffset } = parseHeaders(raw);
228
+ const ctHeader = (headers.get("content-type") ?? ["text/plain"])[0];
229
+ const { type, params } = parseContentType(ctHeader);
230
+ const encoding = (headers.get("content-transfer-encoding") ?? ["7bit"])[0];
231
+ const bodyRaw = raw.subarray(bodyOffset);
232
+ const body = decodePayload(bodyRaw, encoding);
233
+ return {
234
+ contentType: type,
235
+ charset: params.charset,
236
+ body,
237
+ headers,
238
+ boundary: params.boundary,
239
+ };
240
+ }
241
+
242
+ /**
243
+ * Walk all MIME parts of a message (like Python's email.walk()).
244
+ * @param {Buffer} raw
245
+ * @returns {Array<{ contentType: string, charset: string, body: Buffer }>}
246
+ */
247
+ function walkParts(raw) {
248
+ const part = parsePart(raw);
249
+ if (!part.contentType.startsWith("multipart/")) {
250
+ return [part];
251
+ }
252
+
253
+ const boundary = part.boundary;
254
+ if (!boundary) return [part];
255
+
256
+ const delim = Buffer.from(`--${boundary}`);
257
+ const bodyStart = raw.indexOf(delim);
258
+ if (bodyStart === -1) return [part];
259
+
260
+ const parts = [];
261
+ let pos = bodyStart;
262
+
263
+ while (pos < raw.length) {
264
+ const start = raw.indexOf(delim, pos);
265
+ if (start === -1) break;
266
+ let afterDelim = start + delim.length;
267
+ // Check for terminal --
268
+ if (
269
+ afterDelim + 1 < raw.length &&
270
+ raw[afterDelim] === 0x2d &&
271
+ raw[afterDelim + 1] === 0x2d
272
+ ) {
273
+ break;
274
+ }
275
+ // Skip to start of part content (after CRLF or LF)
276
+ while (
277
+ afterDelim < raw.length &&
278
+ (raw[afterDelim] === 0x0d || raw[afterDelim] === 0x0a)
279
+ ) {
280
+ afterDelim++;
281
+ }
282
+ // Find next boundary
283
+ const nextBoundary = raw.indexOf(delim, afterDelim);
284
+ const partEnd = nextBoundary === -1 ? raw.length : nextBoundary;
285
+
286
+ // Trim trailing CRLF before boundary
287
+ let trimEnd = partEnd;
288
+ if (trimEnd > 0 && raw[trimEnd - 1] === 0x0a) trimEnd--;
289
+ if (trimEnd > 0 && raw[trimEnd - 1] === 0x0d) trimEnd--;
290
+
291
+ const subRaw = raw.subarray(afterDelim, trimEnd);
292
+ // Recurse for nested multipart
293
+ parts.push(...walkParts(subRaw));
294
+ pos = nextBoundary === -1 ? raw.length : nextBoundary;
295
+ }
296
+
297
+ return parts;
298
+ }
299
+
300
+ /**
301
+ * Extract plain text body from raw RFC822 bytes, with HTML fallback.
302
+ * @param {Buffer} raw
303
+ * @returns {string | null}
304
+ */
305
+ export function extractBody(raw) {
306
+ const parts = walkParts(raw);
307
+ let textBody = null;
308
+ let htmlBody = null;
309
+
310
+ for (const part of parts) {
311
+ if (part.contentType === "text/plain" && textBody === null) {
312
+ textBody = decodeText(part.body, part.charset);
313
+ } else if (part.contentType === "text/html" && htmlBody === null) {
314
+ htmlBody = decodeText(part.body, part.charset);
315
+ }
316
+ }
317
+
318
+ if (textBody) return textBody;
319
+ if (htmlBody) return htmlToText(htmlBody);
320
+ return null;
321
+ }
322
+
323
+ /**
324
+ * Parse an .emlx file and return the body text.
325
+ * @param {string} filePath
326
+ * @returns {string | null}
327
+ */
328
+ export function parseEmlx(filePath) {
329
+ const data = readFileSync(filePath);
330
+ // First line is the byte count
331
+ const newline = data.indexOf(0x0a);
332
+ const byteCount = parseInt(data.subarray(0, newline).toString("ascii"), 10);
333
+ const raw = data.subarray(newline + 1, newline + 1 + byteCount);
334
+ return extractBody(raw);
335
+ }
336
+
337
+ /**
338
+ * Parse an .emlx file and print From, Date, body to stdout.
339
+ * @param {string} filePath
340
+ */
341
+ function parseAndPrint(filePath) {
342
+ const data = readFileSync(filePath);
343
+ const newline = data.indexOf(0x0a);
344
+ const byteCount = parseInt(data.subarray(0, newline).toString("ascii"), 10);
345
+ const raw = data.subarray(newline + 1, newline + 1 + byteCount);
346
+ const { headers } = parseHeaders(raw);
347
+
348
+ const from = (headers.get("from") ?? ["Unknown"])[0];
349
+ const date = (headers.get("date") ?? [""])[0];
350
+ console.log(`From: ${from}`);
351
+ console.log(`Date: ${date}`);
352
+ console.log("---");
353
+
354
+ const body = extractBody(raw);
355
+ if (body) console.log(body);
356
+ }
357
+
358
+ // --- CLI ---
359
+ if (
360
+ process.argv[1] &&
361
+ (process.argv[1].endsWith("parse-emlx.mjs") ||
362
+ process.argv[1].endsWith("parse-emlx"))
363
+ ) {
364
+ if (process.argv.length !== 3) {
365
+ console.error("Usage: node scripts/parse-emlx.mjs <path>");
366
+ process.exit(1);
367
+ }
368
+ try {
369
+ parseAndPrint(process.argv[2]);
370
+ } catch (err) {
371
+ console.error(`Error: ${err.message}`);
372
+ process.exit(1);
373
+ }
374
+ }