oneshot-gtm-server 0.2.0 → 0.4.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.
- package/dist/bin.mjs +2232 -1211
- package/dist/bin.mjs.map +1 -1
- package/dist/web/assets/Badge-B2tW85qr.js +1 -0
- package/dist/web/assets/Button-C-XcKplu.js +1 -0
- package/dist/web/assets/EmptyNote-zvLnRLPo.js +1 -0
- package/dist/web/assets/Field-BxSk5tbg.js +1 -0
- package/dist/web/assets/Modal-CU0ZPvE2.js +1 -0
- package/dist/web/assets/Skeleton-DNAfO8PV.js +1 -0
- package/dist/web/assets/StrategistPanel-DMjQbPlQ.js +6 -0
- package/dist/web/assets/cadences-CvBPoULf.js +1 -0
- package/dist/web/assets/chevron-down-CDjJN-YY.js +1 -0
- package/dist/web/assets/chevron-right-BTFaTdbr.js +1 -0
- package/dist/web/assets/cn-CS0Arupu.js +1 -0
- package/dist/web/assets/inbox-CzzgtWQf.js +1 -0
- package/dist/web/assets/index-B_nrqLlS.js +54 -0
- package/dist/web/assets/index-Ya_svHJk.css +2 -0
- package/dist/web/assets/loader-circle-CKkt6cSn.js +1 -0
- package/dist/web/assets/measure-CEgySDdR.js +1 -0
- package/dist/web/assets/plays-CuudkOHb.js +1 -0
- package/dist/web/assets/queue-C7vGtsQ5.js +1 -0
- package/dist/web/assets/receipts-B5u3oLpw.js +1 -0
- package/dist/web/assets/refresh-cw-Bz4Kdt55.js +1 -0
- package/dist/web/assets/routes-DHC_we4Z.js +1 -0
- package/dist/web/assets/run._playName-B9sG9Msq.js +4 -0
- package/dist/web/assets/send-Bv2Dd-HU.js +1 -0
- package/dist/web/assets/setup-BRVBiCEX.js +1 -0
- package/dist/web/assets/{summarizeRun-BsPt7szF.js → summarizeRun-CVWcweeA.js} +1 -2
- package/dist/web/assets/x-CPdidoxn.js +1 -0
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/dist/web/assets/Badge-DE7L41a6.js +0 -2
- package/dist/web/assets/Badge-DE7L41a6.js.map +0 -1
- package/dist/web/assets/Button-NJ1UVzeB.js +0 -2
- package/dist/web/assets/Button-NJ1UVzeB.js.map +0 -1
- package/dist/web/assets/EmptyNote-DkmaZWuo.js +0 -2
- package/dist/web/assets/EmptyNote-DkmaZWuo.js.map +0 -1
- package/dist/web/assets/Field-B4mT8TGa.js +0 -2
- package/dist/web/assets/Field-B4mT8TGa.js.map +0 -1
- package/dist/web/assets/Modal-frAt7msr.js +0 -2
- package/dist/web/assets/Modal-frAt7msr.js.map +0 -1
- package/dist/web/assets/Skeleton-d2p06ghN.js +0 -2
- package/dist/web/assets/Skeleton-d2p06ghN.js.map +0 -1
- package/dist/web/assets/cadences-CsU8vKw2.js +0 -2
- package/dist/web/assets/cadences-CsU8vKw2.js.map +0 -1
- package/dist/web/assets/chevron-right-BXb7J1cp.js +0 -2
- package/dist/web/assets/chevron-right-BXb7J1cp.js.map +0 -1
- package/dist/web/assets/inbox-Dzd9QYT4.js +0 -2
- package/dist/web/assets/inbox-Dzd9QYT4.js.map +0 -1
- package/dist/web/assets/index-ByTPAanr.css +0 -2
- package/dist/web/assets/index-CzTgATNQ.js +0 -60
- package/dist/web/assets/index-CzTgATNQ.js.map +0 -1
- package/dist/web/assets/loader-circle-BylpxA-u.js +0 -2
- package/dist/web/assets/loader-circle-BylpxA-u.js.map +0 -1
- package/dist/web/assets/measure-S3BWSb2L.js +0 -2
- package/dist/web/assets/measure-S3BWSb2L.js.map +0 -1
- package/dist/web/assets/plays-DHIZA49D.js +0 -2
- package/dist/web/assets/plays-DHIZA49D.js.map +0 -1
- package/dist/web/assets/queue-ClVxfeJ0.js +0 -2
- package/dist/web/assets/queue-ClVxfeJ0.js.map +0 -1
- package/dist/web/assets/receipts-BgXV3-De.js +0 -2
- package/dist/web/assets/receipts-BgXV3-De.js.map +0 -1
- package/dist/web/assets/refresh-cw-BpMRSA9y.js +0 -2
- package/dist/web/assets/refresh-cw-BpMRSA9y.js.map +0 -1
- package/dist/web/assets/routes-B9L9tBMF.js +0 -2
- package/dist/web/assets/routes-B9L9tBMF.js.map +0 -1
- package/dist/web/assets/run._playName-a3eeybKs.js +0 -5
- package/dist/web/assets/run._playName-a3eeybKs.js.map +0 -1
- package/dist/web/assets/setup-fs0DMLq4.js +0 -2
- package/dist/web/assets/setup-fs0DMLq4.js.map +0 -1
- package/dist/web/assets/summarizeRun-BsPt7szF.js.map +0 -1
package/dist/bin.mjs
CHANGED
|
@@ -32,6 +32,10 @@ const DEFAULTS = {
|
|
|
32
32
|
sendingDomain: null,
|
|
33
33
|
icpOneLiner: null,
|
|
34
34
|
cadenceOverrides: null,
|
|
35
|
+
founderCredentials: null,
|
|
36
|
+
productPortfolio: null,
|
|
37
|
+
partners: null,
|
|
38
|
+
mobileSignature: false,
|
|
35
39
|
clientId: null
|
|
36
40
|
};
|
|
37
41
|
function configDir() {
|
|
@@ -147,6 +151,15 @@ function oneshotEnvReady() {
|
|
|
147
151
|
//#endregion
|
|
148
152
|
//#region ../../packages/core/src/ledger.ts
|
|
149
153
|
const DEFAULT_DB_PATH = join(configDir(), "ledger.sqlite");
|
|
154
|
+
/**
|
|
155
|
+
* Canonical form for matching prospect emails — trim + lowercase. Inbound reply
|
|
156
|
+
* addresses (cadence inbox poll) are normalized the same way, so a prospect
|
|
157
|
+
* stored from a mixed-case address still matches when they reply. Applied on
|
|
158
|
+
* both store (upsertProspect) and every lookup so the two never diverge.
|
|
159
|
+
*/
|
|
160
|
+
function canonEmail(email) {
|
|
161
|
+
return email.trim().toLowerCase();
|
|
162
|
+
}
|
|
150
163
|
var Ledger = class {
|
|
151
164
|
db;
|
|
152
165
|
constructor(path = DEFAULT_DB_PATH) {
|
|
@@ -168,6 +181,9 @@ var Ledger = class {
|
|
|
168
181
|
);
|
|
169
182
|
CREATE INDEX IF NOT EXISTS idx_receipts_play ON receipts(play_name);
|
|
170
183
|
CREATE INDEX IF NOT EXISTS idx_receipts_created ON receipts(created_at);
|
|
184
|
+
-- listReceipts / spend rollups filter (play_name, created_at) together and
|
|
185
|
+
-- sort by created_at; the composite serves both without a separate sort scan.
|
|
186
|
+
CREATE INDEX IF NOT EXISTS idx_receipts_play_created ON receipts(play_name, created_at);
|
|
171
187
|
|
|
172
188
|
CREATE TABLE IF NOT EXISTS prospects (
|
|
173
189
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -193,6 +209,15 @@ var Ledger = class {
|
|
|
193
209
|
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
194
210
|
FOREIGN KEY(prospect_id) REFERENCES prospects(id)
|
|
195
211
|
);
|
|
212
|
+
-- sequence_events is read by listColdProspects (MAX(created_at) per
|
|
213
|
+
-- prospect), per-play send counts, and cadence scans — all by
|
|
214
|
+
-- prospect_id and/or created_at. Without this it's a full table scan.
|
|
215
|
+
CREATE INDEX IF NOT EXISTS idx_sequence_events_prospect_created ON sequence_events(prospect_id, created_at);
|
|
216
|
+
-- listSequenceEventsForProspectPlay (per-row in /api/cadences toView)
|
|
217
|
+
-- and listSequenceEventsForCadences (bulk variant) both filter on
|
|
218
|
+
-- (prospect_id, play_name) and ORDER BY step_index — composite index
|
|
219
|
+
-- serves both the seek and the sort, no temp B-tree.
|
|
220
|
+
CREATE INDEX IF NOT EXISTS idx_sequence_events_prospect_play ON sequence_events(prospect_id, play_name, step_index);
|
|
196
221
|
|
|
197
222
|
CREATE TABLE IF NOT EXISTS interviews (
|
|
198
223
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -249,6 +274,9 @@ var Ledger = class {
|
|
|
249
274
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_queue_dedupe ON target_queue(play_name, dedupe_key);
|
|
250
275
|
CREATE INDEX IF NOT EXISTS idx_queue_status ON target_queue(status);
|
|
251
276
|
CREATE INDEX IF NOT EXISTS idx_queue_play ON target_queue(play_name);
|
|
277
|
+
-- The /queue page filters by (status, play) together; the composite
|
|
278
|
+
-- serves that pair without falling back to a single-column scan.
|
|
279
|
+
CREATE INDEX IF NOT EXISTS idx_queue_status_play ON target_queue(status, play_name);
|
|
252
280
|
|
|
253
281
|
CREATE TABLE IF NOT EXISTS triggers (
|
|
254
282
|
name TEXT PRIMARY KEY,
|
|
@@ -275,6 +303,8 @@ var Ledger = class {
|
|
|
275
303
|
this.addColumnIfMissing("target_queue", "last_draft_json", "TEXT");
|
|
276
304
|
this.addColumnIfMissing("target_queue", "last_drafted_at", "TEXT");
|
|
277
305
|
this.addColumnIfMissing("target_queue", "drain_claimed_at", "TEXT");
|
|
306
|
+
this.addColumnIfMissing("cadence_state", "next_step_draft_json", "TEXT");
|
|
307
|
+
this.addColumnIfMissing("cadence_state", "next_step_drafted_at", "TEXT");
|
|
278
308
|
}
|
|
279
309
|
addColumnIfMissing(table, column, type) {
|
|
280
310
|
const ident = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -314,21 +344,78 @@ var Ledger = class {
|
|
|
314
344
|
JOIN prospects p ON p.id = c.prospect_id
|
|
315
345
|
ORDER BY c.status ASC, c.next_due_at ASC NULLS LAST
|
|
316
346
|
`).all();
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Single cadence (joined with its prospect) by (prospect_id, play_name) — an
|
|
350
|
+
* index seek on the `cadence_state` PRIMARY KEY. Replaces the O(n)
|
|
351
|
+
* `listAllCadences().find(...)` scan callers used to do per row.
|
|
352
|
+
*/
|
|
353
|
+
getCadence(prospectId, playName) {
|
|
354
|
+
return this.db.query(`
|
|
355
|
+
SELECT c.*, p.email AS prospect_email, p.name AS prospect_name, p.company AS prospect_company
|
|
356
|
+
FROM cadence_state c
|
|
357
|
+
JOIN prospects p ON p.id = c.prospect_id
|
|
358
|
+
WHERE c.prospect_id = ? AND c.play_name = ?
|
|
359
|
+
`).get(prospectId, playName) ?? null;
|
|
360
|
+
}
|
|
361
|
+
/** All cadences for one prospect — index seek on cadence_state.prospect_id (PK prefix). */
|
|
362
|
+
listCadencesForProspect(prospectId) {
|
|
363
|
+
return this.db.query(`
|
|
364
|
+
SELECT c.*, p.email AS prospect_email, p.name AS prospect_name, p.company AS prospect_company
|
|
365
|
+
FROM cadence_state c
|
|
366
|
+
JOIN prospects p ON p.id = c.prospect_id
|
|
367
|
+
WHERE c.prospect_id = ?
|
|
368
|
+
ORDER BY c.status ASC, c.next_due_at ASC NULLS LAST
|
|
369
|
+
`).all(prospectId);
|
|
317
370
|
}
|
|
318
371
|
advanceCadence(input) {
|
|
319
372
|
this.db.prepare(`UPDATE cadence_state
|
|
320
|
-
SET current_step = ?, next_due_at = ?, last_polled_at = datetime('now')
|
|
373
|
+
SET current_step = ?, next_due_at = ?, last_polled_at = datetime('now'),
|
|
374
|
+
next_step_draft_json = NULL, next_step_drafted_at = NULL
|
|
321
375
|
WHERE prospect_id = ? AND play_name = ?`).run(input.newStep, input.nextDueAt, input.prospectId, input.playName);
|
|
322
376
|
}
|
|
323
377
|
setCadenceStatus(input) {
|
|
324
|
-
this.db.prepare(`UPDATE cadence_state
|
|
378
|
+
this.db.prepare(`UPDATE cadence_state
|
|
379
|
+
SET status = ?,
|
|
380
|
+
next_step_draft_json = CASE WHEN ? = 'active' THEN next_step_draft_json ELSE NULL END,
|
|
381
|
+
next_step_drafted_at = CASE WHEN ? = 'active' THEN next_step_drafted_at ELSE NULL END
|
|
382
|
+
WHERE prospect_id = ? AND play_name = ?`).run(input.status, input.status, input.status, input.prospectId, input.playName);
|
|
383
|
+
}
|
|
384
|
+
setCadenceDraft(input) {
|
|
385
|
+
const draftedAtIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
386
|
+
const json = JSON.stringify({
|
|
387
|
+
...input.draft,
|
|
388
|
+
draftedAt: draftedAtIso
|
|
389
|
+
});
|
|
390
|
+
this.db.prepare(`UPDATE cadence_state
|
|
391
|
+
SET next_step_draft_json = ?, next_step_drafted_at = ?
|
|
392
|
+
WHERE prospect_id = ? AND play_name = ?`).run(json, draftedAtIso, input.prospectId, input.playName);
|
|
393
|
+
}
|
|
394
|
+
getCadenceDraft(input) {
|
|
395
|
+
const row = this.db.query(`SELECT next_step_draft_json AS j FROM cadence_state
|
|
396
|
+
WHERE prospect_id = ? AND play_name = ?`).get(input.prospectId, input.playName);
|
|
397
|
+
if (!row?.j) return null;
|
|
398
|
+
try {
|
|
399
|
+
return JSON.parse(row.j);
|
|
400
|
+
} catch {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
clearCadenceDraft(input) {
|
|
405
|
+
this.db.prepare(`UPDATE cadence_state
|
|
406
|
+
SET next_step_draft_json = NULL, next_step_drafted_at = NULL
|
|
407
|
+
WHERE prospect_id = ? AND play_name = ?`).run(input.prospectId, input.playName);
|
|
325
408
|
}
|
|
326
409
|
findProspectByEmail(email) {
|
|
327
|
-
return this.db.query("SELECT id FROM prospects WHERE email = ?").get(email) ?? null;
|
|
410
|
+
return this.db.query("SELECT id FROM prospects WHERE email = ?").get(canonEmail(email)) ?? null;
|
|
328
411
|
}
|
|
329
412
|
/** Full prospect record by email — used to attach name/company to inbox replies. */
|
|
330
413
|
getProspectByEmail(email) {
|
|
331
|
-
return this.db.query("SELECT * FROM prospects WHERE email = ?").get(email) ?? null;
|
|
414
|
+
return this.db.query("SELECT * FROM prospects WHERE email = ?").get(canonEmail(email)) ?? null;
|
|
415
|
+
}
|
|
416
|
+
/** Full prospect record by id (PK seek). Avoids loading every prospect to find one. */
|
|
417
|
+
getProspectById(id) {
|
|
418
|
+
return this.db.query("SELECT * FROM prospects WHERE id = ?").get(id) ?? null;
|
|
332
419
|
}
|
|
333
420
|
/** Cached enrichProfile result for an email (profiles are stable; reused with a TTL). */
|
|
334
421
|
getCachedEnrichment(email) {
|
|
@@ -366,14 +453,15 @@ var Ledger = class {
|
|
|
366
453
|
return this.db.query(sql).all(...args);
|
|
367
454
|
}
|
|
368
455
|
upsertProspect(input) {
|
|
369
|
-
|
|
370
|
-
|
|
456
|
+
const email = input.email ? canonEmail(input.email) : null;
|
|
457
|
+
if (email) {
|
|
458
|
+
const existing = this.db.query("SELECT id FROM prospects WHERE email = ?").get(email);
|
|
371
459
|
if (existing) return existing.id;
|
|
372
460
|
}
|
|
373
461
|
const result = this.db.prepare(`
|
|
374
462
|
INSERT INTO prospects(name, email, phone, company, linkedin_url, dossier_json, source)
|
|
375
463
|
VALUES(?, ?, ?, ?, ?, ?, ?)
|
|
376
|
-
`).run(input.name ?? null,
|
|
464
|
+
`).run(input.name ?? null, email, input.phone ?? null, input.company ?? null, input.linkedin_url ?? null, input.dossier_json ?? null, input.source ?? null);
|
|
377
465
|
return Number(result.lastInsertRowid);
|
|
378
466
|
}
|
|
379
467
|
recordOutcome(input) {
|
|
@@ -448,6 +536,37 @@ var Ledger = class {
|
|
|
448
536
|
AND status IN ('sent','delivered','replied')
|
|
449
537
|
ORDER BY step_index ASC, id ASC`).all(prospectId, playName);
|
|
450
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Bulk variant of listSequenceEventsForProspectPlay: one SQL round-trip for
|
|
541
|
+
* many (prospect_id, play_name) pairs. Returns a Map keyed by
|
|
542
|
+
* `${prospect_id}|${play_name}` so callers can index in O(1). The
|
|
543
|
+
* per-key arrays preserve the same (step_index ASC, id ASC) ordering the
|
|
544
|
+
* single-row method returns. Empty input → empty map (no query).
|
|
545
|
+
*
|
|
546
|
+
* Index-served by idx_sequence_events_prospect_play; the OR-chain is
|
|
547
|
+
* expanded into per-pair index seeks by the query planner.
|
|
548
|
+
*/
|
|
549
|
+
listSequenceEventsForCadences(pairs) {
|
|
550
|
+
const map = /* @__PURE__ */ new Map();
|
|
551
|
+
if (pairs.length === 0) return map;
|
|
552
|
+
const conditions = pairs.map(() => "(prospect_id = ? AND play_name = ?)").join(" OR ");
|
|
553
|
+
const args = [];
|
|
554
|
+
for (const p of pairs) args.push(p.prospectId, p.playName);
|
|
555
|
+
const rows = this.db.query(`SELECT * FROM sequence_events
|
|
556
|
+
WHERE (${conditions})
|
|
557
|
+
AND status IN ('sent','delivered','replied')
|
|
558
|
+
ORDER BY prospect_id ASC, play_name ASC, step_index ASC, id ASC`).all(...args);
|
|
559
|
+
for (const r of rows) {
|
|
560
|
+
const key = `${r.prospect_id}|${r.play_name}`;
|
|
561
|
+
let list = map.get(key);
|
|
562
|
+
if (!list) {
|
|
563
|
+
list = [];
|
|
564
|
+
map.set(key, list);
|
|
565
|
+
}
|
|
566
|
+
list.push(r);
|
|
567
|
+
}
|
|
568
|
+
return map;
|
|
569
|
+
}
|
|
451
570
|
recordInterview(input) {
|
|
452
571
|
const result = this.db.prepare(`
|
|
453
572
|
INSERT INTO interviews(person, transcript_path, jtbd, pain_quotes_json)
|
|
@@ -940,6 +1059,46 @@ async function listInbox(opts) {
|
|
|
940
1059
|
if (opts?.limit) out.limit = opts.limit;
|
|
941
1060
|
return agent.inboxList(out);
|
|
942
1061
|
}
|
|
1062
|
+
async function sendSms(input, ctx) {
|
|
1063
|
+
const agent = await getAgent();
|
|
1064
|
+
const opts = {
|
|
1065
|
+
to_number: input.to,
|
|
1066
|
+
message: input.message
|
|
1067
|
+
};
|
|
1068
|
+
if (input.maxCost) opts.maxCost = input.maxCost;
|
|
1069
|
+
const result = await agent.sms(opts);
|
|
1070
|
+
return {
|
|
1071
|
+
result,
|
|
1072
|
+
receiptId: getLedger().recordReceipt({
|
|
1073
|
+
playName: ctx.playName,
|
|
1074
|
+
callType: "sms.send",
|
|
1075
|
+
signedReceipt: result,
|
|
1076
|
+
costUsd: result.cost,
|
|
1077
|
+
oneshotRequestId: result.details[0]?.message_sid ?? void 0
|
|
1078
|
+
})
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
async function voiceCall(input, ctx) {
|
|
1082
|
+
const agent = await getAgent();
|
|
1083
|
+
const opts = {
|
|
1084
|
+
objective: input.objective,
|
|
1085
|
+
target_number: input.to
|
|
1086
|
+
};
|
|
1087
|
+
if (input.callerPersona) opts.caller_persona = input.callerPersona;
|
|
1088
|
+
if (input.context) opts.context = input.context;
|
|
1089
|
+
if (input.maxDurationMinutes) opts.max_duration_minutes = input.maxDurationMinutes;
|
|
1090
|
+
if (input.maxCost) opts.maxCost = input.maxCost;
|
|
1091
|
+
const result = await agent.voice(opts);
|
|
1092
|
+
return {
|
|
1093
|
+
result,
|
|
1094
|
+
receiptId: getLedger().recordReceipt({
|
|
1095
|
+
playName: ctx.playName,
|
|
1096
|
+
callType: "voice.call",
|
|
1097
|
+
costUsd: result.cost,
|
|
1098
|
+
signedReceipt: result
|
|
1099
|
+
})
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
943
1102
|
async function webSearch(input, ctx) {
|
|
944
1103
|
const agent = await getAgent();
|
|
945
1104
|
const opts = { query: input.query };
|
|
@@ -1057,6 +1216,35 @@ function resolveClientId() {
|
|
|
1057
1216
|
return cachedClientId;
|
|
1058
1217
|
}
|
|
1059
1218
|
//#endregion
|
|
1219
|
+
//#region ../../packages/core/src/parallel.ts
|
|
1220
|
+
/**
|
|
1221
|
+
* Run `fn` over `items` with at most `concurrency` Promises in flight at once.
|
|
1222
|
+
* Preserves input order in the result array. Errors propagate via Promise.all
|
|
1223
|
+
* — caller is expected to catch per-item internally if partial success matters.
|
|
1224
|
+
*
|
|
1225
|
+
* Worker-pool implementation: spawn `concurrency` workers that pull from a
|
|
1226
|
+
* shared cursor. Cheaper than a chunked Promise.all (which stalls on the
|
|
1227
|
+
* slowest item per chunk) and avoids the dependency surface of p-limit.
|
|
1228
|
+
*
|
|
1229
|
+
* Lives in core so both `find` (candidate pipelines) and `plays` (batch send
|
|
1230
|
+
* loops) can share it without a cross-package dependency.
|
|
1231
|
+
*/
|
|
1232
|
+
async function parallelMap(items, concurrency, fn) {
|
|
1233
|
+
const out = Array.from({ length: items.length });
|
|
1234
|
+
if (items.length === 0) return out;
|
|
1235
|
+
const workers = Math.max(1, Math.min(concurrency, items.length));
|
|
1236
|
+
let cursor = 0;
|
|
1237
|
+
async function worker() {
|
|
1238
|
+
while (true) {
|
|
1239
|
+
const i = cursor++;
|
|
1240
|
+
if (i >= items.length) return;
|
|
1241
|
+
out[i] = await fn(items[i], i);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
await Promise.all(Array.from({ length: workers }, () => worker()));
|
|
1245
|
+
return out;
|
|
1246
|
+
}
|
|
1247
|
+
//#endregion
|
|
1060
1248
|
//#region src/api/home.ts
|
|
1061
1249
|
function homeMetrics(req) {
|
|
1062
1250
|
const ledger = getLedger();
|
|
@@ -1080,169 +1268,6 @@ function homeMetrics(req) {
|
|
|
1080
1268
|
}, 200, req);
|
|
1081
1269
|
}
|
|
1082
1270
|
//#endregion
|
|
1083
|
-
//#region src/api/cadences.ts
|
|
1084
|
-
function toView$3(row) {
|
|
1085
|
-
return {
|
|
1086
|
-
prospectId: row.prospect_id,
|
|
1087
|
-
prospectEmail: row.prospect_email,
|
|
1088
|
-
prospectName: row.prospect_name,
|
|
1089
|
-
prospectCompany: row.prospect_company,
|
|
1090
|
-
playName: row.play_name,
|
|
1091
|
-
status: row.status,
|
|
1092
|
-
currentStep: row.current_step,
|
|
1093
|
-
enrolledAt: row.enrolled_at,
|
|
1094
|
-
nextDueAt: row.next_due_at,
|
|
1095
|
-
lastPolledAt: row.last_polled_at
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
function listCadences(req) {
|
|
1099
|
-
const all = new URL(req.url).searchParams.get("all") === "1";
|
|
1100
|
-
const ledger = getLedger();
|
|
1101
|
-
return jsonResponse({ cadences: (all ? ledger.listAllCadences() : ledger.listActiveCadences()).map(toView$3) }, 200, req);
|
|
1102
|
-
}
|
|
1103
|
-
function getCadence(req, params) {
|
|
1104
|
-
const id = Number.parseInt(params["id"] ?? "", 10);
|
|
1105
|
-
if (!Number.isFinite(id)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
1106
|
-
const all = getLedger().listAllCadences().filter((c) => c.prospect_id === id);
|
|
1107
|
-
if (all.length === 0) return jsonResponse({ error: "no cadences for prospect" }, 404, req);
|
|
1108
|
-
return jsonResponse({ cadences: all.map(toView$3) }, 200, req);
|
|
1109
|
-
}
|
|
1110
|
-
function stopCadence(req, params) {
|
|
1111
|
-
const id = Number.parseInt(params["id"] ?? "", 10);
|
|
1112
|
-
if (!Number.isFinite(id)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
1113
|
-
const playName = new URL(req.url).searchParams.get("play");
|
|
1114
|
-
const ledger = getLedger();
|
|
1115
|
-
const cadences = ledger.listAllCadences().filter((c) => {
|
|
1116
|
-
if (c.prospect_id !== id) return false;
|
|
1117
|
-
if (playName && c.play_name !== playName) return false;
|
|
1118
|
-
return c.status === "active";
|
|
1119
|
-
});
|
|
1120
|
-
for (const cad of cadences) ledger.setCadenceStatus({
|
|
1121
|
-
prospectId: id,
|
|
1122
|
-
playName: cad.play_name,
|
|
1123
|
-
status: "completed"
|
|
1124
|
-
});
|
|
1125
|
-
return jsonResponse({ stopped: cadences.length }, 200, req);
|
|
1126
|
-
}
|
|
1127
|
-
//#endregion
|
|
1128
|
-
//#region src/api/receipts.ts
|
|
1129
|
-
function toView$2(row) {
|
|
1130
|
-
return {
|
|
1131
|
-
id: row.id,
|
|
1132
|
-
playName: row.play_name,
|
|
1133
|
-
callType: row.call_type,
|
|
1134
|
-
costUsd: row.cost_usd,
|
|
1135
|
-
oneshotRequestId: row.oneshot_request_id,
|
|
1136
|
-
createdAt: row.created_at
|
|
1137
|
-
};
|
|
1138
|
-
}
|
|
1139
|
-
function listReceipts(req) {
|
|
1140
|
-
const url = new URL(req.url);
|
|
1141
|
-
const playName = url.searchParams.get("play") ?? void 0;
|
|
1142
|
-
const sinceDays = Number.parseInt(url.searchParams.get("sinceDays") ?? "", 10);
|
|
1143
|
-
const limit = Math.min(500, Number.parseInt(url.searchParams.get("limit") ?? "200", 10) || 200);
|
|
1144
|
-
const sinceIso = Number.isFinite(sinceDays) ? (/* @__PURE__ */ new Date(Date.now() - sinceDays * 24 * 3600 * 1e3)).toISOString() : void 0;
|
|
1145
|
-
return jsonResponse({ receipts: getLedger().listReceipts({
|
|
1146
|
-
...playName ? { playName } : {},
|
|
1147
|
-
...sinceIso ? { sinceIso } : {},
|
|
1148
|
-
limit
|
|
1149
|
-
}).map(toView$2) }, 200, req);
|
|
1150
|
-
}
|
|
1151
|
-
function getReceipt(req, params) {
|
|
1152
|
-
const id = Number.parseInt(params["id"] ?? "", 10);
|
|
1153
|
-
if (!Number.isFinite(id)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
1154
|
-
const r = getLedger().getReceipt(id);
|
|
1155
|
-
if (!r) return jsonResponse({ error: "not found" }, 404, req);
|
|
1156
|
-
let parsed = null;
|
|
1157
|
-
if (r.signed_receipt) try {
|
|
1158
|
-
parsed = JSON.parse(r.signed_receipt);
|
|
1159
|
-
} catch {
|
|
1160
|
-
parsed = r.signed_receipt;
|
|
1161
|
-
}
|
|
1162
|
-
return jsonResponse({ receipt: {
|
|
1163
|
-
id: r.id,
|
|
1164
|
-
playName: r.play_name,
|
|
1165
|
-
callType: r.call_type,
|
|
1166
|
-
costUsd: r.cost_usd,
|
|
1167
|
-
oneshotRequestId: r.oneshot_request_id,
|
|
1168
|
-
createdAt: r.created_at,
|
|
1169
|
-
signedReceipt: parsed
|
|
1170
|
-
} }, 200, req);
|
|
1171
|
-
}
|
|
1172
|
-
//#endregion
|
|
1173
|
-
//#region src/api/inbox.ts
|
|
1174
|
-
/** "Jane Doe <jane@x.com>" → "jane@x.com"; bare addresses pass through. */
|
|
1175
|
-
function normalizeFrom(raw) {
|
|
1176
|
-
const m = raw.match(/<([^>]+)>/);
|
|
1177
|
-
return (m ? m[1] ?? raw : raw).trim().toLowerCase();
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Read-only view of the OneShot inbox (replies to outreach). Each email is
|
|
1181
|
-
* matched to a known prospect by sender address, annotated with the play +
|
|
1182
|
-
* cadence status when available. Live fetch — no storage. The SDK exposes only
|
|
1183
|
-
* inboxList (no reply/markRead), so this is read-only.
|
|
1184
|
-
*/
|
|
1185
|
-
async function listInboxRoute(req) {
|
|
1186
|
-
const ledger = getLedger();
|
|
1187
|
-
let emails;
|
|
1188
|
-
try {
|
|
1189
|
-
emails = (await listInbox({ limit: 50 })).emails;
|
|
1190
|
-
} catch (err) {
|
|
1191
|
-
logEvent("inbox.list_failed", { message_120: (err?.message ?? "").slice(0, 120) }, "warn");
|
|
1192
|
-
return jsonResponse({
|
|
1193
|
-
replies: [],
|
|
1194
|
-
hasMore: false,
|
|
1195
|
-
error: "couldn't reach the inbox"
|
|
1196
|
-
}, 200, req);
|
|
1197
|
-
}
|
|
1198
|
-
const byEmail = /* @__PURE__ */ new Map();
|
|
1199
|
-
for (const c of ledger.listAllCadences()) {
|
|
1200
|
-
if (!c.prospect_email) continue;
|
|
1201
|
-
const key = c.prospect_email.trim().toLowerCase();
|
|
1202
|
-
const existing = byEmail.get(key);
|
|
1203
|
-
if (!existing || c.status === "replied" || c.status === "active" && existing.status !== "replied") byEmail.set(key, {
|
|
1204
|
-
name: c.prospect_name,
|
|
1205
|
-
company: c.prospect_company,
|
|
1206
|
-
playName: c.play_name,
|
|
1207
|
-
status: c.status
|
|
1208
|
-
});
|
|
1209
|
-
}
|
|
1210
|
-
const replies = emails.map((e) => {
|
|
1211
|
-
const fromEmail = normalizeFrom(e.from);
|
|
1212
|
-
let matched = null;
|
|
1213
|
-
const cadence = byEmail.get(fromEmail);
|
|
1214
|
-
if (cadence) matched = {
|
|
1215
|
-
name: cadence.name,
|
|
1216
|
-
company: cadence.company,
|
|
1217
|
-
playName: cadence.playName,
|
|
1218
|
-
cadenceStatus: cadence.status
|
|
1219
|
-
};
|
|
1220
|
-
else {
|
|
1221
|
-
const p = ledger.getProspectByEmail(fromEmail);
|
|
1222
|
-
if (p) matched = {
|
|
1223
|
-
name: p.name,
|
|
1224
|
-
company: p.company,
|
|
1225
|
-
playName: p.source,
|
|
1226
|
-
cadenceStatus: null
|
|
1227
|
-
};
|
|
1228
|
-
}
|
|
1229
|
-
return {
|
|
1230
|
-
id: e.id,
|
|
1231
|
-
fromEmail,
|
|
1232
|
-
fromRaw: e.from,
|
|
1233
|
-
subject: e.subject,
|
|
1234
|
-
receivedAt: e.received_at,
|
|
1235
|
-
body: e.body ?? "",
|
|
1236
|
-
matched
|
|
1237
|
-
};
|
|
1238
|
-
});
|
|
1239
|
-
const selfDomain = (loadConfig().sendingDomain ?? "").trim().toLowerCase();
|
|
1240
|
-
return jsonResponse({
|
|
1241
|
-
replies: replies.filter((r) => !selfDomain || !r.fromEmail.endsWith(`@${selfDomain}`)).toSorted((a, b) => a.receivedAt < b.receivedAt ? 1 : a.receivedAt > b.receivedAt ? -1 : 0),
|
|
1242
|
-
hasMore: false
|
|
1243
|
-
}, 200, req);
|
|
1244
|
-
}
|
|
1245
|
-
//#endregion
|
|
1246
1271
|
//#region ../../packages/intel/src/prompts.ts
|
|
1247
1272
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
1248
1273
|
const candidates = [
|
|
@@ -1594,18 +1619,41 @@ function signatureDirective() {
|
|
|
1594
1619
|
const cfg = loadConfig();
|
|
1595
1620
|
const domain = (cfg.productDomain ?? "").trim();
|
|
1596
1621
|
if (!domain) return "";
|
|
1622
|
+
const name = (cfg.founderName ?? "").trim() || "[founder name]";
|
|
1623
|
+
const mobile = cfg.mobileSignature === true;
|
|
1624
|
+
const sigLines = [name, domain];
|
|
1625
|
+
if (mobile) sigLines.push("Sent from my iPhone");
|
|
1597
1626
|
return [
|
|
1598
1627
|
"",
|
|
1599
1628
|
"",
|
|
1600
1629
|
"## Signature (binding — overrides any sign-off rule above)",
|
|
1601
|
-
"End the email with the founder's name, then their domain on the very next line:",
|
|
1630
|
+
mobile ? "End the email with the founder's name, then their domain, then a literal 'Sent from my iPhone' line. Three lines total, in this order:" : "End the email with the founder's name, then their domain on the very next line:",
|
|
1602
1631
|
"",
|
|
1603
|
-
|
|
1604
|
-
domain,
|
|
1632
|
+
...sigLines,
|
|
1605
1633
|
"",
|
|
1606
|
-
`Always include the domain line, even if a rule above says "no links" or "no tagline" — a bare domain beneath the name is the signature, not an inline link. Write it plain: no "https://", no "www.", no hyperlink, no text after it
|
|
1634
|
+
`Always include the domain line, even if a rule above says "no links" or "no tagline" — a bare domain beneath the name is the signature, not an inline link. Write it plain: no "https://", no "www.", no hyperlink, no text after it.`,
|
|
1635
|
+
...mobile ? [`The "Sent from my iPhone" line is a literal proof-of-human artifact. Always exactly that string, no variation, no quotes.`] : []
|
|
1607
1636
|
].join("\n");
|
|
1608
1637
|
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Build a SOCIAL PROOF input block from the founder's three optional config
|
|
1640
|
+
* fields. Returns null when none are set — callers skip the line entirely
|
|
1641
|
+
* so the prompt's "if SOCIAL PROOF is in the inputs" conditional kicks in.
|
|
1642
|
+
* Each prompt should weave AT MOST ONE beat (credentials OR built-with OR
|
|
1643
|
+
* partners) into the email, not stack them.
|
|
1644
|
+
*/
|
|
1645
|
+
function socialProofBlock() {
|
|
1646
|
+
const cfg = loadConfig();
|
|
1647
|
+
const lines = [];
|
|
1648
|
+
const cred = cfg.founderCredentials?.trim();
|
|
1649
|
+
const built = cfg.productPortfolio?.trim();
|
|
1650
|
+
const partners = cfg.partners?.trim();
|
|
1651
|
+
if (cred) lines.push(`CREDENTIALS: ${cred}`);
|
|
1652
|
+
if (built) lines.push(`PORTFOLIO: ${built}`);
|
|
1653
|
+
if (partners) lines.push(`PARTNERS: ${partners}`);
|
|
1654
|
+
if (lines.length === 0) return null;
|
|
1655
|
+
return ["SOCIAL PROOF (pick the ONE beat that best fits this play — CREDENTIALS for founder-trust, PORTFOLIO for peer-founder, PARTNERS for brand-recognition; never stack two):", ...lines].join("\n");
|
|
1656
|
+
}
|
|
1609
1657
|
async function draftEmailFromPrompt(opts) {
|
|
1610
1658
|
return humanizeDraft(parseSubjectBody((await complete({
|
|
1611
1659
|
messages: [{
|
|
@@ -1669,6 +1717,12 @@ async function sendDraftedEmail(opts) {
|
|
|
1669
1717
|
sent
|
|
1670
1718
|
};
|
|
1671
1719
|
}
|
|
1720
|
+
/** Domain portion of an email address, or undefined if it has no `@`. */
|
|
1721
|
+
function emailDomain(email) {
|
|
1722
|
+
const at = email.indexOf("@");
|
|
1723
|
+
if (at < 0) return void 0;
|
|
1724
|
+
return email.slice(at + 1);
|
|
1725
|
+
}
|
|
1672
1726
|
/**
|
|
1673
1727
|
* Verify a batch of target emails BEFORE drafting + sending. Used by
|
|
1674
1728
|
* direct-input entry points (CLI motion commands + dashboard /run) where
|
|
@@ -1776,6 +1830,55 @@ const playSequences = /* @__PURE__ */ new Map();
|
|
|
1776
1830
|
function registerSequence(seq) {
|
|
1777
1831
|
playSequences.set(seq.playName, seq);
|
|
1778
1832
|
}
|
|
1833
|
+
/**
|
|
1834
|
+
* "Does this label name a breakup step?" — single source of truth for the
|
|
1835
|
+
* label-substring check. Used by isBreakupStepAt for the cadence-final
|
|
1836
|
+
* semantic check AND by /plays for per-step rendering where each row is
|
|
1837
|
+
* already a step.
|
|
1838
|
+
*/
|
|
1839
|
+
function isBreakupLabel(label) {
|
|
1840
|
+
return Boolean(label && label.toLowerCase().includes("breakup"));
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Centralized breakup-step detection for cadence-progress semantics. A
|
|
1844
|
+
* step is "the breakup" iff (a) it sits at the END of the sequence and
|
|
1845
|
+
* (b) its label is a breakup label. Both clauses matter: the
|
|
1846
|
+
* breakup-email PROMPT is also used as accelerator-batch's only
|
|
1847
|
+
* follow-up — at index 0 — and that one isn't semantically a breakup
|
|
1848
|
+
* for cadence UX purposes (no value follow-up preceded it).
|
|
1849
|
+
*/
|
|
1850
|
+
function isBreakupStepAt(seq, stepEntryIndex) {
|
|
1851
|
+
if (stepEntryIndex !== seq.steps.length - 1) return false;
|
|
1852
|
+
return isBreakupLabel(seq.steps[stepEntryIndex]?.label);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Number of follow-up steps registered for this play (excludes day-0).
|
|
1856
|
+
* Always returns the registered total regardless of current_step — the UI
|
|
1857
|
+
* uses `playFollowupCount + 1` for the StepProgress dot count which should
|
|
1858
|
+
* be stable for completed cadences too.
|
|
1859
|
+
*/
|
|
1860
|
+
function playFollowupCount(playName) {
|
|
1861
|
+
return effectiveSequence(playName)?.steps.length ?? 0;
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Given a play + the cadence's current_step, describe the NEXT step
|
|
1865
|
+
* scheduled to fire. Returns null when the cadence is at or past the
|
|
1866
|
+
* last step (no more steps to send). Source of truth for both the
|
|
1867
|
+
* server's CadenceView and the /cadences UI — avoids hardcoded
|
|
1868
|
+
* play→step-count Records in the web layer.
|
|
1869
|
+
*/
|
|
1870
|
+
function nextStepInfo(playName, currentStep) {
|
|
1871
|
+
const seq = effectiveSequence(playName);
|
|
1872
|
+
if (!seq) return null;
|
|
1873
|
+
const nextIndex = currentStep + 1;
|
|
1874
|
+
const stepEntryIndex = nextIndex - 1;
|
|
1875
|
+
if (stepEntryIndex < 0 || stepEntryIndex >= seq.steps.length) return null;
|
|
1876
|
+
return {
|
|
1877
|
+
label: seq.steps[stepEntryIndex]?.label ?? null,
|
|
1878
|
+
isBreakup: isBreakupStepAt(seq, stepEntryIndex),
|
|
1879
|
+
nextStepNumber: nextIndex
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1779
1882
|
function getSequence(playName) {
|
|
1780
1883
|
return effectiveSequence(playName);
|
|
1781
1884
|
}
|
|
@@ -1819,10 +1922,367 @@ function enrollInCadence(input) {
|
|
|
1819
1922
|
nextDueAt: dueAt
|
|
1820
1923
|
});
|
|
1821
1924
|
}
|
|
1925
|
+
/**
|
|
1926
|
+
* Per-prospect cadence step runner. Single source of truth for both the
|
|
1927
|
+
* batch `advanceCadence` (CLI) and the per-row /cadences UI (preview + send).
|
|
1928
|
+
* Caller decides dryRun (no send) or persistedPayload (send a previously
|
|
1929
|
+
* built draft verbatim). On a successful send, advances `current_step`
|
|
1930
|
+
* to `nextIndex` and sets `next_due_at` to the next step's offset; clears
|
|
1931
|
+
* any persisted preview draft via ledger.advanceCadence.
|
|
1932
|
+
*/
|
|
1933
|
+
async function runCadenceStepForProspect(opts) {
|
|
1934
|
+
const ledger = getLedger();
|
|
1935
|
+
const cfg = loadConfig();
|
|
1936
|
+
const cadence = ledger.getCadence(opts.prospectId, opts.playName);
|
|
1937
|
+
if (!cadence) return {
|
|
1938
|
+
action: "skipped",
|
|
1939
|
+
payload: null,
|
|
1940
|
+
receiptIds: [],
|
|
1941
|
+
note: "no cadence"
|
|
1942
|
+
};
|
|
1943
|
+
if (cadence.status !== "active") return {
|
|
1944
|
+
action: "skipped",
|
|
1945
|
+
payload: null,
|
|
1946
|
+
receiptIds: [],
|
|
1947
|
+
note: `cadence is ${cadence.status}`
|
|
1948
|
+
};
|
|
1949
|
+
const seq = effectiveSequence(opts.playName);
|
|
1950
|
+
if (!seq) return {
|
|
1951
|
+
action: "skipped",
|
|
1952
|
+
payload: null,
|
|
1953
|
+
receiptIds: [],
|
|
1954
|
+
note: "no registered sequence"
|
|
1955
|
+
};
|
|
1956
|
+
const nextIndex = cadence.current_step + 1;
|
|
1957
|
+
const stepEntryIndex = nextIndex - 1;
|
|
1958
|
+
if (stepEntryIndex < 0 || stepEntryIndex >= seq.steps.length) {
|
|
1959
|
+
ledger.setCadenceStatus({
|
|
1960
|
+
prospectId: opts.prospectId,
|
|
1961
|
+
playName: opts.playName,
|
|
1962
|
+
status: "completed"
|
|
1963
|
+
});
|
|
1964
|
+
return {
|
|
1965
|
+
action: "completed",
|
|
1966
|
+
payload: null,
|
|
1967
|
+
receiptIds: []
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
const step = seq.steps[stepEntryIndex];
|
|
1971
|
+
if (!step) return {
|
|
1972
|
+
action: "skipped",
|
|
1973
|
+
payload: null,
|
|
1974
|
+
receiptIds: []
|
|
1975
|
+
};
|
|
1976
|
+
const prospect = loadProspect(opts.prospectId);
|
|
1977
|
+
if (!prospect) return {
|
|
1978
|
+
action: "skipped",
|
|
1979
|
+
payload: null,
|
|
1980
|
+
receiptIds: [],
|
|
1981
|
+
note: "prospect not found"
|
|
1982
|
+
};
|
|
1983
|
+
const built = opts.persistedPayload ? opts.persistedPayload : await step.builder({
|
|
1984
|
+
prospect,
|
|
1985
|
+
cfg,
|
|
1986
|
+
metadata: {}
|
|
1987
|
+
});
|
|
1988
|
+
if (!built) {
|
|
1989
|
+
const next = seq.steps[stepEntryIndex + 1];
|
|
1990
|
+
ledger.advanceCadence({
|
|
1991
|
+
prospectId: opts.prospectId,
|
|
1992
|
+
playName: opts.playName,
|
|
1993
|
+
newStep: nextIndex,
|
|
1994
|
+
nextDueAt: next ? new Date(Date.now() + next.dayOffset * 24 * 3600 * 1e3).toISOString() : null
|
|
1995
|
+
});
|
|
1996
|
+
if (!next) {
|
|
1997
|
+
ledger.setCadenceStatus({
|
|
1998
|
+
prospectId: opts.prospectId,
|
|
1999
|
+
playName: opts.playName,
|
|
2000
|
+
status: "completed"
|
|
2001
|
+
});
|
|
2002
|
+
return {
|
|
2003
|
+
action: "completed",
|
|
2004
|
+
payload: null,
|
|
2005
|
+
receiptIds: [],
|
|
2006
|
+
note: step.label ?? `step ${nextIndex} builder returned null`
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
return {
|
|
2010
|
+
action: "skipped",
|
|
2011
|
+
payload: null,
|
|
2012
|
+
receiptIds: [],
|
|
2013
|
+
note: step.label ?? `step ${nextIndex} builder returned null`
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
const receiptIds = [];
|
|
2017
|
+
if (!opts.dryRun) {
|
|
2018
|
+
const channelOutcome = await dispatchStep({
|
|
2019
|
+
playName: opts.playName,
|
|
2020
|
+
prospectId: opts.prospectId,
|
|
2021
|
+
prospectEmail: cadence.prospect_email,
|
|
2022
|
+
stepIndex: nextIndex,
|
|
2023
|
+
step,
|
|
2024
|
+
payload: built,
|
|
2025
|
+
...step.label !== void 0 ? { label: step.label } : {}
|
|
2026
|
+
});
|
|
2027
|
+
if (channelOutcome.skipReason) return {
|
|
2028
|
+
action: "skipped",
|
|
2029
|
+
payload: built,
|
|
2030
|
+
receiptIds: [],
|
|
2031
|
+
note: channelOutcome.skipReason
|
|
2032
|
+
};
|
|
2033
|
+
receiptIds.push(...channelOutcome.receiptIds);
|
|
2034
|
+
}
|
|
2035
|
+
if (isBreakupStepAt(seq, stepEntryIndex)) {
|
|
2036
|
+
ledger.setCadenceStatus({
|
|
2037
|
+
prospectId: opts.prospectId,
|
|
2038
|
+
playName: opts.playName,
|
|
2039
|
+
status: "breakup"
|
|
2040
|
+
});
|
|
2041
|
+
return {
|
|
2042
|
+
action: "breakup",
|
|
2043
|
+
payload: built,
|
|
2044
|
+
receiptIds,
|
|
2045
|
+
note: step.label ?? `step ${nextIndex}`
|
|
2046
|
+
};
|
|
2047
|
+
}
|
|
2048
|
+
const next = seq.steps[stepEntryIndex + 1];
|
|
2049
|
+
ledger.advanceCadence({
|
|
2050
|
+
prospectId: opts.prospectId,
|
|
2051
|
+
playName: opts.playName,
|
|
2052
|
+
newStep: nextIndex,
|
|
2053
|
+
nextDueAt: next ? new Date(Date.now() + next.dayOffset * 24 * 3600 * 1e3).toISOString() : null
|
|
2054
|
+
});
|
|
2055
|
+
if (!next) ledger.setCadenceStatus({
|
|
2056
|
+
prospectId: opts.prospectId,
|
|
2057
|
+
playName: opts.playName,
|
|
2058
|
+
status: "completed"
|
|
2059
|
+
});
|
|
2060
|
+
return {
|
|
2061
|
+
action: "step-sent",
|
|
2062
|
+
payload: built,
|
|
2063
|
+
receiptIds,
|
|
2064
|
+
note: step.label ?? `step ${nextIndex}`
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Build the next step's draft and persist it via setCadenceDraft. Never
|
|
2069
|
+
* sends. Mirrors the /queue regenerate route — the founder reviews on
|
|
2070
|
+
* /cadences, then clicks Send next which calls sendCadenceStep.
|
|
2071
|
+
*/
|
|
2072
|
+
async function previewCadenceStep(input) {
|
|
2073
|
+
const ledger = getLedger();
|
|
2074
|
+
const cfg = loadConfig();
|
|
2075
|
+
const cadence = ledger.getCadence(input.prospectId, input.playName);
|
|
2076
|
+
if (!cadence) throw new Error("no cadence for that prospect+play");
|
|
2077
|
+
if (cadence.status !== "active") throw new Error(`cadence is ${cadence.status}, can only preview an active cadence`);
|
|
2078
|
+
const seq = effectiveSequence(input.playName);
|
|
2079
|
+
if (!seq) throw new Error(`no registered sequence for play '${input.playName}'`);
|
|
2080
|
+
const stepEntryIndex = cadence.current_step + 1 - 1;
|
|
2081
|
+
if (stepEntryIndex < 0 || stepEntryIndex >= seq.steps.length) throw new Error("no next step (cadence is at or past the last step)");
|
|
2082
|
+
const step = seq.steps[stepEntryIndex];
|
|
2083
|
+
if (!step) throw new Error("step undefined");
|
|
2084
|
+
const prospect = loadProspect(input.prospectId);
|
|
2085
|
+
if (!prospect) throw new Error("prospect not found");
|
|
2086
|
+
const built = await step.builder({
|
|
2087
|
+
prospect,
|
|
2088
|
+
cfg,
|
|
2089
|
+
metadata: {}
|
|
2090
|
+
});
|
|
2091
|
+
if (!built) throw new Error("builder returned null — nothing to preview");
|
|
2092
|
+
const subject = built.kind === "email" ? built.subject : "(non-email step)";
|
|
2093
|
+
const body = built.kind === "email" ? built.body : built.kind === "sms" ? built.message : built.kind === "voice" ? built.objective : "";
|
|
2094
|
+
const flags = built.kind === "email" ? lintEmail(subject, body, 100) : [];
|
|
2095
|
+
ledger.setCadenceDraft({
|
|
2096
|
+
prospectId: input.prospectId,
|
|
2097
|
+
playName: input.playName,
|
|
2098
|
+
draft: {
|
|
2099
|
+
subject,
|
|
2100
|
+
body,
|
|
2101
|
+
flags,
|
|
2102
|
+
payload: built
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
return {
|
|
2106
|
+
subject,
|
|
2107
|
+
body,
|
|
2108
|
+
flags,
|
|
2109
|
+
payload: built,
|
|
2110
|
+
draftedAt: ledger.getCadenceDraft({
|
|
2111
|
+
prospectId: input.prospectId,
|
|
2112
|
+
playName: input.playName
|
|
2113
|
+
})?.draftedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
2114
|
+
stepLabel: step.label ?? null,
|
|
2115
|
+
isBreakup: isBreakupStepAt(seq, stepEntryIndex)
|
|
2116
|
+
};
|
|
2117
|
+
}
|
|
2118
|
+
/**
|
|
2119
|
+
* Send a previously-previewed cadence step verbatim. Reads the persisted
|
|
2120
|
+
* draft (or 409s if none), dispatches it through runCadenceStepForProspect,
|
|
2121
|
+
* and advances the cadence. The advance clears the persisted draft so a
|
|
2122
|
+
* subsequent Preview rebuilds against the new current_step.
|
|
2123
|
+
*/
|
|
2124
|
+
async function sendCadenceStep(input) {
|
|
2125
|
+
const draft = getLedger().getCadenceDraft(input);
|
|
2126
|
+
if (!draft) throw new Error("no persisted preview — click Preview first");
|
|
2127
|
+
return runCadenceStepForProspect({
|
|
2128
|
+
prospectId: input.prospectId,
|
|
2129
|
+
playName: input.playName,
|
|
2130
|
+
dryRun: false,
|
|
2131
|
+
persistedPayload: draft.payload
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Parallel preview of a list of cadence rows (concurrency 3). Each
|
|
2136
|
+
* per-prospect failure is captured in the result array — the batch never
|
|
2137
|
+
* throws. `parallelMap` preserves input order so the returned array matches
|
|
2138
|
+
* `items` 1:1. Concurrency mirrors `runEmailPlay` + `advanceCadence`; the
|
|
2139
|
+
* founder is waiting at the UI, so 3× speedup on a 10-row preview drops
|
|
2140
|
+
* wall-clock from ~100s to ~35s.
|
|
2141
|
+
*/
|
|
2142
|
+
async function previewCadenceStepBatch(items) {
|
|
2143
|
+
return parallelMap(items, 3, async (item) => {
|
|
2144
|
+
try {
|
|
2145
|
+
const preview = await previewCadenceStep(item);
|
|
2146
|
+
return {
|
|
2147
|
+
prospectId: item.prospectId,
|
|
2148
|
+
playName: item.playName,
|
|
2149
|
+
ok: true,
|
|
2150
|
+
preview
|
|
2151
|
+
};
|
|
2152
|
+
} catch (err) {
|
|
2153
|
+
return {
|
|
2154
|
+
prospectId: item.prospectId,
|
|
2155
|
+
playName: item.playName,
|
|
2156
|
+
ok: false,
|
|
2157
|
+
error: (err?.message ?? "preview failed").slice(0, 120)
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Serial send of a list of previewed cadence rows. Each per-prospect failure
|
|
2164
|
+
* is captured; the batch never throws. Used by `POST /api/cadences/send-batch`
|
|
2165
|
+
* as a background promise — caller returns 202 immediately and the UI sees
|
|
2166
|
+
* progress via subsequent `/api/cadences` refetches (the existing
|
|
2167
|
+
* `advanceCadence` clears `next_step_draft_json` as each row completes).
|
|
2168
|
+
*
|
|
2169
|
+
* Sends stay serial (unlike previewCadenceStepBatch) for two reasons: the
|
|
2170
|
+
* `onItemSettled` callback drives the in-flight UI badge per row (parallel
|
|
2171
|
+
* would batch-flash all rows at once), and parallel SMTP to the same
|
|
2172
|
+
* domain risks soft-bounces.
|
|
2173
|
+
*/
|
|
2174
|
+
async function sendCadenceStepBatch(items, onItemSettled) {
|
|
2175
|
+
const out = [];
|
|
2176
|
+
for (const item of items) {
|
|
2177
|
+
let result;
|
|
2178
|
+
try {
|
|
2179
|
+
const r = await sendCadenceStep(item);
|
|
2180
|
+
result = {
|
|
2181
|
+
prospectId: item.prospectId,
|
|
2182
|
+
playName: item.playName,
|
|
2183
|
+
ok: true,
|
|
2184
|
+
action: r.action,
|
|
2185
|
+
receiptIds: r.receiptIds
|
|
2186
|
+
};
|
|
2187
|
+
} catch (err) {
|
|
2188
|
+
result = {
|
|
2189
|
+
prospectId: item.prospectId,
|
|
2190
|
+
playName: item.playName,
|
|
2191
|
+
ok: false,
|
|
2192
|
+
error: (err?.message ?? "send failed").slice(0, 120)
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
out.push(result);
|
|
2196
|
+
onItemSettled?.(item, result);
|
|
2197
|
+
}
|
|
2198
|
+
return out;
|
|
2199
|
+
}
|
|
2200
|
+
async function dispatchStep(input) {
|
|
2201
|
+
const ledger = getLedger();
|
|
2202
|
+
const receiptIds = [];
|
|
2203
|
+
if (input.payload.kind === "email") {
|
|
2204
|
+
if (!input.prospectEmail) return {
|
|
2205
|
+
receiptIds,
|
|
2206
|
+
skipReason: "prospect has no email"
|
|
2207
|
+
};
|
|
2208
|
+
const send = await sendEmail({
|
|
2209
|
+
to: input.prospectEmail,
|
|
2210
|
+
subject: input.payload.subject,
|
|
2211
|
+
body: input.payload.body
|
|
2212
|
+
}, { playName: input.playName });
|
|
2213
|
+
receiptIds.push(send.receiptId);
|
|
2214
|
+
ledger.recordSequenceEvent({
|
|
2215
|
+
prospectId: input.prospectId,
|
|
2216
|
+
playName: input.playName,
|
|
2217
|
+
stepIndex: input.stepIndex,
|
|
2218
|
+
channel: "email",
|
|
2219
|
+
status: "sent",
|
|
2220
|
+
metadata: {
|
|
2221
|
+
subject: input.payload.subject,
|
|
2222
|
+
body: input.payload.body,
|
|
2223
|
+
label: input.label
|
|
2224
|
+
}
|
|
2225
|
+
});
|
|
2226
|
+
return { receiptIds };
|
|
2227
|
+
}
|
|
2228
|
+
if (input.payload.kind === "sms") {
|
|
2229
|
+
if (!input.payload.toPhone) return {
|
|
2230
|
+
receiptIds,
|
|
2231
|
+
skipReason: "prospect has no phone for SMS"
|
|
2232
|
+
};
|
|
2233
|
+
const send = await sendSms({
|
|
2234
|
+
to: input.payload.toPhone,
|
|
2235
|
+
message: input.payload.message
|
|
2236
|
+
}, { playName: input.playName });
|
|
2237
|
+
receiptIds.push(send.receiptId);
|
|
2238
|
+
ledger.recordSequenceEvent({
|
|
2239
|
+
prospectId: input.prospectId,
|
|
2240
|
+
playName: input.playName,
|
|
2241
|
+
stepIndex: input.stepIndex,
|
|
2242
|
+
channel: "sms",
|
|
2243
|
+
status: "sent",
|
|
2244
|
+
metadata: { label: input.label }
|
|
2245
|
+
});
|
|
2246
|
+
return { receiptIds };
|
|
2247
|
+
}
|
|
2248
|
+
if (input.payload.kind === "voice") {
|
|
2249
|
+
if (!input.payload.toPhone) return {
|
|
2250
|
+
receiptIds,
|
|
2251
|
+
skipReason: "prospect has no phone for voice"
|
|
2252
|
+
};
|
|
2253
|
+
const call = await voiceCall({
|
|
2254
|
+
objective: input.payload.objective,
|
|
2255
|
+
to: input.payload.toPhone,
|
|
2256
|
+
...input.payload.context ? { context: input.payload.context } : {},
|
|
2257
|
+
...input.payload.maxDurationMinutes ? { maxDurationMinutes: input.payload.maxDurationMinutes } : {}
|
|
2258
|
+
}, { playName: input.playName });
|
|
2259
|
+
receiptIds.push(call.receiptId);
|
|
2260
|
+
ledger.recordSequenceEvent({
|
|
2261
|
+
prospectId: input.prospectId,
|
|
2262
|
+
playName: input.playName,
|
|
2263
|
+
stepIndex: input.stepIndex,
|
|
2264
|
+
channel: "voice",
|
|
2265
|
+
status: "sent",
|
|
2266
|
+
metadata: {
|
|
2267
|
+
label: input.label,
|
|
2268
|
+
ended_reason: call.result.ended_reason ?? null
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
return { receiptIds };
|
|
2272
|
+
}
|
|
2273
|
+
return {
|
|
2274
|
+
receiptIds,
|
|
2275
|
+
skipReason: "unknown step payload kind"
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
function loadProspect(id) {
|
|
2279
|
+
return getLedger().getProspectById(id);
|
|
2280
|
+
}
|
|
1822
2281
|
function buildFollowUpEmail(opts) {
|
|
1823
2282
|
return async (ctx) => {
|
|
1824
2283
|
const system = loadPrompt(opts.promptName) + signatureDirective();
|
|
1825
2284
|
const priorBlock = buildPriorEmailsBlock(ctx.prospect.id, opts.playName);
|
|
2285
|
+
const proofBlock = socialProofBlock();
|
|
1826
2286
|
const user = [
|
|
1827
2287
|
`FOUNDER: ${ctx.cfg.founderName}`,
|
|
1828
2288
|
`PRODUCT: ${ctx.cfg.productOneLiner}`,
|
|
@@ -1830,7 +2290,8 @@ function buildFollowUpEmail(opts) {
|
|
|
1830
2290
|
`EMAIL: ${ctx.prospect.email ?? ""}`,
|
|
1831
2291
|
`COMPANY: ${ctx.prospect.company ?? "(unknown)"}`,
|
|
1832
2292
|
...opts.contextLines,
|
|
1833
|
-
...priorBlock ? ["", priorBlock] : []
|
|
2293
|
+
...priorBlock ? ["", priorBlock] : [],
|
|
2294
|
+
...proofBlock ? ["", proofBlock] : []
|
|
1834
2295
|
].join("\n");
|
|
1835
2296
|
const parsed = tryParseJsonObject((await complete({
|
|
1836
2297
|
messages: [{
|
|
@@ -1844,744 +2305,798 @@ function buildFollowUpEmail(opts) {
|
|
|
1844
2305
|
maxTokens: 500
|
|
1845
2306
|
})).content, {});
|
|
1846
2307
|
if (!parsed.subject || !parsed.body) return null;
|
|
1847
|
-
|
|
1848
|
-
kind: "email",
|
|
2308
|
+
const cleaned = humanizeDraft({
|
|
1849
2309
|
subject: parsed.subject.trim(),
|
|
1850
2310
|
body: parsed.body.trim()
|
|
2311
|
+
});
|
|
2312
|
+
return {
|
|
2313
|
+
kind: "email",
|
|
2314
|
+
subject: cleaned.subject,
|
|
2315
|
+
body: cleaned.body
|
|
1851
2316
|
};
|
|
1852
2317
|
};
|
|
1853
2318
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
2319
|
+
/**
|
|
2320
|
+
* Parse a prospect's prior sends for a given play into clean per-step rows.
|
|
2321
|
+
* Source of truth shared by the LLM PRIOR-EMAILS injection (which filters
|
|
2322
|
+
* legacy rows) and the /api/cadences view (which surfaces them with a
|
|
2323
|
+
* "body not captured" placeholder).
|
|
2324
|
+
*/
|
|
2325
|
+
function getPriorStepsForProspect(prospectId, playName) {
|
|
2326
|
+
if (!prospectId) return [];
|
|
1856
2327
|
let rows;
|
|
1857
2328
|
try {
|
|
1858
2329
|
rows = getLedger().listSequenceEventsForProspectPlay(prospectId, playName);
|
|
1859
2330
|
} catch {
|
|
1860
|
-
return
|
|
2331
|
+
return [];
|
|
1861
2332
|
}
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
2333
|
+
return rows.map(rowToPriorStep);
|
|
2334
|
+
}
|
|
2335
|
+
function rowToPriorStep(r) {
|
|
2336
|
+
const meta = tryParseJsonObject(r.metadata_json ?? "", {});
|
|
2337
|
+
return {
|
|
2338
|
+
stepIndex: r.step_index,
|
|
2339
|
+
label: meta.label ?? (r.step_index === 0 ? "initial send" : "follow-up"),
|
|
2340
|
+
subject: meta.subject ?? "(no subject)",
|
|
2341
|
+
body: meta.body ?? null,
|
|
2342
|
+
sentAt: r.created_at,
|
|
2343
|
+
status: r.status ?? "sent"
|
|
2344
|
+
};
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Bulk variant of getPriorStepsForProspect: one SQL round-trip for many
|
|
2348
|
+
* (prospect_id, play_name) pairs. Returns a Map keyed by
|
|
2349
|
+
* `${prospectId}|${playName}` so /api/cadences's toView can index in O(1)
|
|
2350
|
+
* instead of issuing one query per row. Pairs the founder hasn't sent for
|
|
2351
|
+
* are absent from the map (callers should default to []).
|
|
2352
|
+
*/
|
|
2353
|
+
function getPriorStepsBulk(pairs) {
|
|
2354
|
+
if (pairs.length === 0) return /* @__PURE__ */ new Map();
|
|
2355
|
+
let bulk;
|
|
2356
|
+
try {
|
|
2357
|
+
bulk = getLedger().listSequenceEventsForCadences(pairs);
|
|
2358
|
+
} catch {
|
|
2359
|
+
return /* @__PURE__ */ new Map();
|
|
2360
|
+
}
|
|
2361
|
+
const out = /* @__PURE__ */ new Map();
|
|
2362
|
+
for (const [key, rows] of bulk) out.set(key, rows.map(rowToPriorStep));
|
|
2363
|
+
return out;
|
|
2364
|
+
}
|
|
2365
|
+
function buildPriorEmailsBlock(prospectId, playName) {
|
|
2366
|
+
const prior = getPriorStepsForProspect(prospectId, playName).filter((r) => r.body !== null && r.body.length > 0);
|
|
2367
|
+
if (prior.length === 0) return null;
|
|
1873
2368
|
const lines = ["PRIOR EMAILS (your previous touches to this prospect on this play; do not repeat their angles, hooks, openers, or closes):"];
|
|
1874
|
-
for (const row of
|
|
1875
|
-
lines.push(`--- step ${row.
|
|
2369
|
+
for (const row of prior) {
|
|
2370
|
+
lines.push(`--- step ${row.stepIndex} (${row.label}) ---`);
|
|
1876
2371
|
lines.push(`Subject: ${row.subject}`);
|
|
1877
2372
|
lines.push(row.body);
|
|
1878
2373
|
}
|
|
1879
2374
|
return lines.join("\n");
|
|
1880
2375
|
}
|
|
1881
2376
|
//#endregion
|
|
1882
|
-
//#region ../../packages/plays/src/
|
|
1883
|
-
|
|
1884
|
-
|
|
2377
|
+
//#region ../../packages/plays/src/_run-play.ts
|
|
2378
|
+
/**
|
|
2379
|
+
* Run an email play over its targets. Behavior-preserving extraction of the
|
|
2380
|
+
* per-target loop that every email play used to hand-roll: enrich/research →
|
|
2381
|
+
* draft → lint → send → (optional) cadence enroll, with a per-target try/catch
|
|
2382
|
+
* so one bad target can't kill the batch.
|
|
2383
|
+
*/
|
|
2384
|
+
async function runEmailPlay(def, opts) {
|
|
1885
2385
|
const cfg = loadConfig();
|
|
1886
2386
|
if (!cfg.founderName || !cfg.productOneLiner) throw new Error("founder profile incomplete. Run: oneshot-gtm config founder");
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
2387
|
+
const emails = opts.targets.map((t) => def.toEmail(t).trim().toLowerCase());
|
|
2388
|
+
const concurrency = new Set(emails).size !== emails.length ? 1 : 3;
|
|
2389
|
+
return { drafted: await parallelMap(opts.targets, concurrency, async (target) => {
|
|
2390
|
+
try {
|
|
2391
|
+
const prep = await def.prepare(target, opts.dryRun);
|
|
2392
|
+
const proof = socialProofBlock();
|
|
2393
|
+
const inputBlock = proof ? `${def.buildInputBlock(target, prep, cfg)}\n\n${proof}` : def.buildInputBlock(target, prep, cfg);
|
|
2394
|
+
const draft = await draftEmailFromPrompt({
|
|
2395
|
+
promptName: def.promptName,
|
|
2396
|
+
inputBlock
|
|
2397
|
+
});
|
|
2398
|
+
const flags = lintEmail(draft.subject, draft.body, def.maxBodyWords);
|
|
2399
|
+
const send = await sendDraftedEmail({
|
|
2400
|
+
playName: def.playName,
|
|
2401
|
+
to: def.toEmail(target),
|
|
2402
|
+
draft,
|
|
2403
|
+
flags,
|
|
2404
|
+
prospectMeta: def.prospectMeta(target),
|
|
2405
|
+
...def.metadata ? { metadata: def.metadata(target) } : {},
|
|
2406
|
+
dryRun: opts.dryRun
|
|
2407
|
+
});
|
|
2408
|
+
if (send.sent && def.enrollCadence) {
|
|
2409
|
+
const prospect = getLedger().findProspectByEmail(def.toEmail(target));
|
|
2410
|
+
if (prospect) enrollInCadence({
|
|
2411
|
+
prospectId: prospect.id,
|
|
2412
|
+
playName: def.playName
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
return {
|
|
2416
|
+
target,
|
|
2417
|
+
subject: draft.subject,
|
|
2418
|
+
body: draft.body,
|
|
2419
|
+
receiptIds: [...prep.receiptIds, ...send.receiptIds],
|
|
2420
|
+
sent: send.sent,
|
|
2421
|
+
flags,
|
|
2422
|
+
...prep.extra ?? {}
|
|
2423
|
+
};
|
|
2424
|
+
} catch (err) {
|
|
2425
|
+
return {
|
|
2426
|
+
target,
|
|
2427
|
+
...errorDraft(err?.message),
|
|
2428
|
+
...def.errorExtra ?? {}
|
|
2429
|
+
};
|
|
1903
2430
|
}
|
|
1904
|
-
|
|
1905
|
-
promptName: "show-hn-email",
|
|
1906
|
-
inputBlock: [
|
|
1907
|
-
`FOUNDER: ${cfg.founderName}`,
|
|
1908
|
-
`PRODUCT: ${cfg.productOneLiner}`,
|
|
1909
|
-
`SHOW HN: ${target.postTitle}`,
|
|
1910
|
-
`URL: ${target.postUrl}`,
|
|
1911
|
-
`HOOK: ${target.hookSummary}`,
|
|
1912
|
-
`DOSSIER:\n${dossier || "(dry-run; rely on the hook only)"}`
|
|
1913
|
-
].join("\n")
|
|
1914
|
-
});
|
|
1915
|
-
const flags = lintEmail(draft.subject, draft.body, 90);
|
|
1916
|
-
const send = await sendDraftedEmail({
|
|
1917
|
-
playName: PLAY_NAME$20,
|
|
1918
|
-
to: target.founderEmail,
|
|
1919
|
-
draft,
|
|
1920
|
-
flags,
|
|
1921
|
-
prospectMeta: {
|
|
1922
|
-
name: target.founderName,
|
|
1923
|
-
email: target.founderEmail,
|
|
1924
|
-
company: extractCompany(target.postTitle),
|
|
1925
|
-
linkedin_url: target.linkedinUrl ?? null,
|
|
1926
|
-
phone: target.phone ?? null,
|
|
1927
|
-
source: "show-hn"
|
|
1928
|
-
},
|
|
1929
|
-
metadata: {
|
|
1930
|
-
postUrl: target.postUrl,
|
|
1931
|
-
postTitle: target.postTitle
|
|
1932
|
-
},
|
|
1933
|
-
dryRun: opts.dryRun
|
|
1934
|
-
});
|
|
1935
|
-
drafted.push({
|
|
1936
|
-
target,
|
|
1937
|
-
subject: draft.subject,
|
|
1938
|
-
body: draft.body,
|
|
1939
|
-
receiptIds: [...receiptIds, ...send.receiptIds],
|
|
1940
|
-
sent: send.sent,
|
|
1941
|
-
flags
|
|
1942
|
-
});
|
|
1943
|
-
} catch (err) {
|
|
1944
|
-
drafted.push({
|
|
1945
|
-
target,
|
|
1946
|
-
...errorDraft(err?.message)
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
return { drafted };
|
|
2431
|
+
}) };
|
|
1950
2432
|
}
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
2433
|
+
/**
|
|
2434
|
+
* The common `prepare` body for plays that personalize via `safeEnrich` (cached
|
|
2435
|
+
* by email, never throws) and, on real sends only, a `deepResearch` dossier.
|
|
2436
|
+
* Pass `research` only when you want the research call to fire — callers gate it
|
|
2437
|
+
* on `!dryRun` (and, for accelerator-batch, on a launch URL being present).
|
|
2438
|
+
*/
|
|
2439
|
+
async function standardEnrich(opts) {
|
|
2440
|
+
const receiptIds = [];
|
|
2441
|
+
const enr = await safeEnrich(opts.enrichInput, { playName: opts.playName });
|
|
2442
|
+
if (enr.receiptId) receiptIds.push(enr.receiptId);
|
|
2443
|
+
let dossier = JSON.stringify(enr.result, null, 2).slice(0, opts.enrichSlice);
|
|
2444
|
+
if (opts.research) {
|
|
2445
|
+
const research = await deepResearch({
|
|
2446
|
+
topic: opts.research.topic,
|
|
2447
|
+
depth: "quick"
|
|
2448
|
+
}, { playName: opts.playName });
|
|
2449
|
+
receiptIds.push(research.receiptId);
|
|
2450
|
+
dossier += "\n\n---\n\n" + JSON.stringify(research.result, null, 2).slice(0, opts.research.slice ?? 4e3);
|
|
2451
|
+
}
|
|
2452
|
+
return {
|
|
2453
|
+
receiptIds,
|
|
2454
|
+
dossier
|
|
2455
|
+
};
|
|
1954
2456
|
}
|
|
1955
2457
|
//#endregion
|
|
1956
|
-
//#region ../../packages/plays/src/
|
|
1957
|
-
const PLAY_NAME$
|
|
1958
|
-
|
|
1959
|
-
const
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
topic: `Public posts, talks, and recent decisions by ${target.name} (joined ${target.newCompany} as ${target.newRole}, formerly ${target.previousRole ?? "?"} at ${target.previousCompany ?? "?"})`,
|
|
1974
|
-
depth: "quick"
|
|
1975
|
-
}, { playName: PLAY_NAME$19 });
|
|
1976
|
-
receiptIds.push(research.receiptId);
|
|
1977
|
-
dossier += "\n\n---\n\n" + JSON.stringify(research.result, null, 2).slice(0, 4e3);
|
|
1978
|
-
}
|
|
1979
|
-
const draft = await draftEmailFromPrompt({
|
|
1980
|
-
promptName: "job-change-email",
|
|
1981
|
-
inputBlock: [
|
|
1982
|
-
`FOUNDER: ${cfg.founderName}`,
|
|
1983
|
-
`PRODUCT: ${cfg.productOneLiner}`,
|
|
1984
|
-
`PROSPECT: ${target.name}`,
|
|
1985
|
-
`NEW ROLE: ${target.newRole} at ${target.newCompany}`,
|
|
1986
|
-
`PREVIOUS: ${target.previousRole ?? "unknown"} at ${target.previousCompany ?? "unknown"}`,
|
|
1987
|
-
`DOSSIER:\n${dossier || "(dry-run; rely on the trigger only)"}`
|
|
1988
|
-
].join("\n")
|
|
1989
|
-
});
|
|
1990
|
-
const flags = lintEmail(draft.subject, draft.body, 100);
|
|
1991
|
-
const send = await sendDraftedEmail({
|
|
1992
|
-
playName: PLAY_NAME$19,
|
|
1993
|
-
to: target.email,
|
|
1994
|
-
draft,
|
|
1995
|
-
flags,
|
|
1996
|
-
prospectMeta: {
|
|
1997
|
-
name: target.name,
|
|
1998
|
-
email: target.email,
|
|
1999
|
-
company: target.newCompany,
|
|
2000
|
-
linkedin_url: target.linkedinUrl ?? null,
|
|
2001
|
-
phone: target.phone ?? null,
|
|
2002
|
-
source: "job-change"
|
|
2003
|
-
},
|
|
2004
|
-
metadata: {
|
|
2005
|
-
newRole: target.newRole,
|
|
2006
|
-
newCompany: target.newCompany
|
|
2458
|
+
//#region ../../packages/plays/src/accelerator-batch.ts
|
|
2459
|
+
const PLAY_NAME$22 = "accelerator-batch";
|
|
2460
|
+
function runAcceleratorBatch(opts) {
|
|
2461
|
+
const senderCohortFor = (t) => (t.senderCohort?.trim() || opts.senderCohort || "").trim();
|
|
2462
|
+
const offerFor = (t) => t.freeForCohortOffer ?? opts.freeForCohortOffer;
|
|
2463
|
+
return runEmailPlay({
|
|
2464
|
+
playName: PLAY_NAME$22,
|
|
2465
|
+
promptName: "accelerator-batch-email",
|
|
2466
|
+
maxBodyWords: 100,
|
|
2467
|
+
enrollCadence: true,
|
|
2468
|
+
toEmail: (t) => t.email,
|
|
2469
|
+
prepare: (t, dryRun) => standardEnrich({
|
|
2470
|
+
playName: PLAY_NAME$22,
|
|
2471
|
+
enrichInput: {
|
|
2472
|
+
...t.email ? { email: t.email } : {},
|
|
2473
|
+
...t.linkedinUrl ? { linkedinUrl: t.linkedinUrl } : {},
|
|
2474
|
+
name: t.name
|
|
2007
2475
|
},
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
})
|
|
2030
|
-
|
|
2031
|
-
|
|
2476
|
+
enrichSlice: 3500,
|
|
2477
|
+
...!dryRun && t.launchUrl ? { research: { topic: `Recent public work and decisions by ${t.name} at ${t.company} (${t.cohort}). Pull launch context from ${t.launchUrl}.` } } : {}
|
|
2478
|
+
}),
|
|
2479
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
2480
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2481
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2482
|
+
`SENDER COHORT: ${senderCohortFor(t) || "(unspecified)"}`,
|
|
2483
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2484
|
+
`PROSPECT COHORT: ${t.cohort}`,
|
|
2485
|
+
`PROSPECT PRODUCT: ${t.productOneLiner ?? "(unknown)"}`,
|
|
2486
|
+
`LAUNCH URL: ${t.launchUrl ?? "(none)"}`,
|
|
2487
|
+
`FREE-FOR-COHORT OFFER: ${offerFor(t) ?? "(no active offer for this cohort)"}`,
|
|
2488
|
+
`DOSSIER:\n${prep.dossier || "(dry-run; rely on the cohort match only)"}`
|
|
2489
|
+
].join("\n"),
|
|
2490
|
+
prospectMeta: (t) => ({
|
|
2491
|
+
name: t.name,
|
|
2492
|
+
email: t.email,
|
|
2493
|
+
company: t.company,
|
|
2494
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2495
|
+
phone: t.phone ?? null,
|
|
2496
|
+
source: `accelerator-${t.cohort}`
|
|
2497
|
+
}),
|
|
2498
|
+
metadata: (t) => ({
|
|
2499
|
+
senderCohort: senderCohortFor(t),
|
|
2500
|
+
prospectCohort: t.cohort
|
|
2501
|
+
})
|
|
2502
|
+
}, opts);
|
|
2032
2503
|
}
|
|
2033
2504
|
registerSequence({
|
|
2034
|
-
playName: PLAY_NAME$
|
|
2505
|
+
playName: PLAY_NAME$22,
|
|
2035
2506
|
steps: [{
|
|
2036
2507
|
dayOffset: 5,
|
|
2037
2508
|
channel: "email",
|
|
2038
2509
|
breakOnReply: true,
|
|
2039
|
-
label: "
|
|
2510
|
+
label: "single follow-up + breakup",
|
|
2040
2511
|
builder: buildFollowUpEmail({
|
|
2041
|
-
playName: PLAY_NAME$
|
|
2042
|
-
promptName: "
|
|
2043
|
-
contextLines: [`
|
|
2044
|
-
})
|
|
2045
|
-
}, {
|
|
2046
|
-
dayOffset: 9,
|
|
2047
|
-
channel: "email",
|
|
2048
|
-
breakOnReply: true,
|
|
2049
|
-
label: "breakup",
|
|
2050
|
-
builder: buildFollowUpEmail({
|
|
2051
|
-
playName: PLAY_NAME$19,
|
|
2052
|
-
promptName: "breakup-email",
|
|
2053
|
-
contextLines: [`PLAY: job-change. Sender is closing the file.`]
|
|
2512
|
+
playName: PLAY_NAME$22,
|
|
2513
|
+
promptName: "breakup-email",
|
|
2514
|
+
contextLines: [`PLAY: accelerator-batch. The accelerator-batch motion is one-touch + one breakup; this is the final note. Lean very short.`]
|
|
2054
2515
|
})
|
|
2055
2516
|
}]
|
|
2056
2517
|
});
|
|
2057
2518
|
//#endregion
|
|
2058
|
-
//#region ../../packages/plays/src/
|
|
2059
|
-
const PLAY_NAME$
|
|
2060
|
-
async function
|
|
2519
|
+
//#region ../../packages/plays/src/breakup-revive.ts
|
|
2520
|
+
const PLAY_NAME$21 = "breakup-revive";
|
|
2521
|
+
async function runBreakupRevive(opts) {
|
|
2061
2522
|
const cfg = loadConfig();
|
|
2062
2523
|
if (!cfg.founderName || !cfg.productOneLiner) throw new Error("founder profile incomplete. Run: oneshot-gtm config founder");
|
|
2524
|
+
const targets = opts.targets ?? ledgerScanTargets(opts);
|
|
2063
2525
|
const drafted = [];
|
|
2064
|
-
for (const
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
}
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
playName: PLAY_NAME$18
|
|
2526
|
+
for (const t of targets) {
|
|
2527
|
+
if (!t.email) continue;
|
|
2528
|
+
try {
|
|
2529
|
+
const draft = await draftEmailFromPrompt({
|
|
2530
|
+
promptName: "breakup-revive-email",
|
|
2531
|
+
inputBlock: [
|
|
2532
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2533
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2534
|
+
`PROSPECT: ${t.name ?? "(unknown)"} at ${t.company ?? "(unknown)"}`,
|
|
2535
|
+
`DAYS SINCE LAST ACTIVITY: ${t.daysCold}`,
|
|
2536
|
+
`OPTIONAL VALUE DROP: ${opts.valueDrop ?? "(none — go with a probe question instead)"}`
|
|
2537
|
+
].join("\n")
|
|
2538
|
+
});
|
|
2539
|
+
const flags = lintEmail(draft.subject, draft.body, 80);
|
|
2540
|
+
const send = await sendDraftedEmail({
|
|
2541
|
+
playName: PLAY_NAME$21,
|
|
2542
|
+
to: t.email,
|
|
2543
|
+
draft,
|
|
2544
|
+
flags,
|
|
2545
|
+
prospectMeta: {
|
|
2546
|
+
name: t.name,
|
|
2547
|
+
email: t.email,
|
|
2548
|
+
company: t.company,
|
|
2549
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2550
|
+
phone: t.phone ?? null,
|
|
2551
|
+
source: "breakup-revive"
|
|
2552
|
+
},
|
|
2553
|
+
metadata: {
|
|
2554
|
+
daysCold: t.daysCold,
|
|
2555
|
+
lastEventAt: t.lastEventAt
|
|
2556
|
+
},
|
|
2557
|
+
dryRun: opts.dryRun
|
|
2558
|
+
});
|
|
2559
|
+
drafted.push({
|
|
2560
|
+
prospectEmail: t.email,
|
|
2561
|
+
prospectName: t.name,
|
|
2562
|
+
daysCold: t.daysCold,
|
|
2563
|
+
subject: draft.subject,
|
|
2564
|
+
body: draft.body,
|
|
2565
|
+
receiptIds: send.receiptIds,
|
|
2566
|
+
sent: send.sent,
|
|
2567
|
+
flags
|
|
2568
|
+
});
|
|
2569
|
+
} catch (err) {
|
|
2570
|
+
const stub = errorDraft(err?.message);
|
|
2571
|
+
drafted.push({
|
|
2572
|
+
prospectEmail: t.email,
|
|
2573
|
+
prospectName: t.name,
|
|
2574
|
+
daysCold: t.daysCold,
|
|
2575
|
+
subject: stub.subject,
|
|
2576
|
+
body: stub.body,
|
|
2577
|
+
receiptIds: stub.receiptIds,
|
|
2578
|
+
sent: stub.sent,
|
|
2579
|
+
flags: stub.flags
|
|
2119
2580
|
});
|
|
2120
2581
|
}
|
|
2121
|
-
drafted.push({
|
|
2122
|
-
target,
|
|
2123
|
-
subject: draft.subject,
|
|
2124
|
-
body: draft.body,
|
|
2125
|
-
receiptIds: [...receiptIds, ...send.receiptIds],
|
|
2126
|
-
sent: send.sent,
|
|
2127
|
-
flags
|
|
2128
|
-
});
|
|
2129
|
-
} catch (err) {
|
|
2130
|
-
drafted.push({
|
|
2131
|
-
target,
|
|
2132
|
-
...errorDraft(err?.message)
|
|
2133
|
-
});
|
|
2134
2582
|
}
|
|
2135
2583
|
return { drafted };
|
|
2136
2584
|
}
|
|
2585
|
+
function ledgerScanTargets(opts) {
|
|
2586
|
+
return getLedger().listColdProspects({
|
|
2587
|
+
minDaysSinceLastEvent: opts.minDays ?? 60,
|
|
2588
|
+
maxDaysSinceLastEvent: opts.maxDays ?? 90,
|
|
2589
|
+
...opts.limit ? { limit: opts.limit } : {}
|
|
2590
|
+
}).filter((p) => p.email != null).map((p) => ({
|
|
2591
|
+
name: p.name,
|
|
2592
|
+
email: p.email,
|
|
2593
|
+
company: p.company,
|
|
2594
|
+
daysCold: p.last_event_at ? Math.floor((Date.now() - new Date(p.last_event_at).getTime()) / (24 * 3600 * 1e3)) : 0,
|
|
2595
|
+
lastEventAt: p.last_event_at,
|
|
2596
|
+
linkedinUrl: p.linkedin_url ?? null,
|
|
2597
|
+
phone: p.phone ?? null
|
|
2598
|
+
}));
|
|
2599
|
+
}
|
|
2600
|
+
//#endregion
|
|
2601
|
+
//#region ../../packages/plays/src/competitor-switch.ts
|
|
2602
|
+
const PLAY_NAME$20 = "competitor-switch";
|
|
2603
|
+
function runCompetitorSwitch(opts) {
|
|
2604
|
+
return runEmailPlay({
|
|
2605
|
+
playName: PLAY_NAME$20,
|
|
2606
|
+
promptName: "competitor-switch-email",
|
|
2607
|
+
maxBodyWords: 100,
|
|
2608
|
+
enrollCadence: true,
|
|
2609
|
+
toEmail: (t) => t.email,
|
|
2610
|
+
prepare: async (t, dryRun) => {
|
|
2611
|
+
const receiptIds = [];
|
|
2612
|
+
let scrapedEvidence;
|
|
2613
|
+
const enr = await safeEnrich({
|
|
2614
|
+
...t.email ? { email: t.email } : {},
|
|
2615
|
+
name: t.name,
|
|
2616
|
+
companyDomain: emailDomain(t.email)
|
|
2617
|
+
}, { playName: PLAY_NAME$20 });
|
|
2618
|
+
if (enr.receiptId) receiptIds.push(enr.receiptId);
|
|
2619
|
+
const dossier = JSON.stringify(enr.result, null, 2).slice(0, 3500);
|
|
2620
|
+
if (!dryRun) {
|
|
2621
|
+
const haveEvidenceText = typeof t.evidenceText === "string" && t.evidenceText.trim().length > 0;
|
|
2622
|
+
if (t.evidenceUrl && !opts.skipBrowserScrape && !haveEvidenceText) {
|
|
2623
|
+
const browse = await browserTask({
|
|
2624
|
+
task: `Read the page at ${t.evidenceUrl} and extract: (1) any specific complaints or pain points the user mentioned about ${t.competitor}, (2) any mentions of features they wished existed, (3) any context about company size or use case. Return concise structured JSON.`,
|
|
2625
|
+
startUrl: t.evidenceUrl,
|
|
2626
|
+
outputSchema: {
|
|
2627
|
+
type: "object",
|
|
2628
|
+
properties: {
|
|
2629
|
+
pain_points: {
|
|
2630
|
+
type: "array",
|
|
2631
|
+
items: { type: "string" }
|
|
2632
|
+
},
|
|
2633
|
+
wished_features: {
|
|
2634
|
+
type: "array",
|
|
2635
|
+
items: { type: "string" }
|
|
2636
|
+
},
|
|
2637
|
+
use_case_context: { type: "string" }
|
|
2638
|
+
}
|
|
2639
|
+
},
|
|
2640
|
+
maxSteps: 12
|
|
2641
|
+
}, { playName: PLAY_NAME$20 });
|
|
2642
|
+
receiptIds.push(browse.receiptId);
|
|
2643
|
+
scrapedEvidence = typeof browse.result.output === "string" ? browse.result.output : JSON.stringify(browse.result.output ?? {});
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
return {
|
|
2647
|
+
receiptIds,
|
|
2648
|
+
dossier,
|
|
2649
|
+
...scrapedEvidence ? { extra: { scrapedEvidence } } : {}
|
|
2650
|
+
};
|
|
2651
|
+
},
|
|
2652
|
+
buildInputBlock: (t, prep, cfg) => {
|
|
2653
|
+
const evidence = prep.extra?.scrapedEvidence ?? t.evidenceText ?? "(no evidence supplied)";
|
|
2654
|
+
return [
|
|
2655
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2656
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2657
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2658
|
+
`COMPETITOR: ${t.competitor}`,
|
|
2659
|
+
`EVIDENCE: ${evidence}`,
|
|
2660
|
+
`YOUR EDGE: ${t.yourEdge}`,
|
|
2661
|
+
`DOSSIER:\n${prep.dossier || "(dry-run)"}`
|
|
2662
|
+
].join("\n");
|
|
2663
|
+
},
|
|
2664
|
+
prospectMeta: (t) => ({
|
|
2665
|
+
name: t.name,
|
|
2666
|
+
email: t.email,
|
|
2667
|
+
company: t.company,
|
|
2668
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2669
|
+
phone: t.phone ?? null,
|
|
2670
|
+
source: "competitor-switch"
|
|
2671
|
+
}),
|
|
2672
|
+
metadata: (t) => ({
|
|
2673
|
+
competitor: t.competitor,
|
|
2674
|
+
evidenceUrl: t.evidenceUrl ?? null
|
|
2675
|
+
})
|
|
2676
|
+
}, opts);
|
|
2677
|
+
}
|
|
2137
2678
|
registerSequence({
|
|
2138
|
-
playName: PLAY_NAME$
|
|
2679
|
+
playName: PLAY_NAME$20,
|
|
2139
2680
|
steps: [{
|
|
2140
|
-
dayOffset:
|
|
2681
|
+
dayOffset: 3,
|
|
2141
2682
|
channel: "email",
|
|
2142
2683
|
breakOnReply: true,
|
|
2143
|
-
label: "
|
|
2684
|
+
label: "value follow-up",
|
|
2144
2685
|
builder: buildFollowUpEmail({
|
|
2145
|
-
playName: PLAY_NAME$
|
|
2146
|
-
promptName: "
|
|
2147
|
-
contextLines: [`
|
|
2686
|
+
playName: PLAY_NAME$20,
|
|
2687
|
+
promptName: "competitor-switch-followup",
|
|
2688
|
+
contextLines: [`PLAY: competitor-switch. Day-3 value follow-up after the migration-honesty pitch.`]
|
|
2148
2689
|
})
|
|
2149
2690
|
}, {
|
|
2150
|
-
dayOffset:
|
|
2691
|
+
dayOffset: 8,
|
|
2151
2692
|
channel: "email",
|
|
2152
2693
|
breakOnReply: true,
|
|
2153
2694
|
label: "breakup",
|
|
2154
2695
|
builder: buildFollowUpEmail({
|
|
2155
|
-
playName: PLAY_NAME$
|
|
2696
|
+
playName: PLAY_NAME$20,
|
|
2156
2697
|
promptName: "breakup-email",
|
|
2157
|
-
contextLines: [`PLAY:
|
|
2698
|
+
contextLines: [`PLAY: competitor-switch. Final breakup after the migration-honesty pitch.`]
|
|
2158
2699
|
})
|
|
2159
2700
|
}]
|
|
2160
2701
|
});
|
|
2161
2702
|
//#endregion
|
|
2162
|
-
//#region ../../packages/plays/src/
|
|
2163
|
-
const PLAY_NAME$
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2703
|
+
//#region ../../packages/plays/src/hiring-signal.ts
|
|
2704
|
+
const PLAY_NAME$19 = "hiring-signal";
|
|
2705
|
+
const NO_HOOK = "(no specific job post phrase scraped)";
|
|
2706
|
+
function runHiringSignal(opts) {
|
|
2707
|
+
return runEmailPlay({
|
|
2708
|
+
playName: PLAY_NAME$19,
|
|
2709
|
+
promptName: "hiring-signal-email",
|
|
2710
|
+
maxBodyWords: 100,
|
|
2711
|
+
enrollCadence: true,
|
|
2712
|
+
errorExtra: { jobPostHook: "(error)" },
|
|
2713
|
+
toEmail: (t) => t.email,
|
|
2714
|
+
prepare: async (t, dryRun) => {
|
|
2715
|
+
const receiptIds = [];
|
|
2716
|
+
let jobPostHook = NO_HOOK;
|
|
2717
|
+
if (!dryRun) {
|
|
2718
|
+
let jobUrl = t.jobPostUrl;
|
|
2719
|
+
if (!jobUrl && !opts.skipScrape) {
|
|
2720
|
+
const search = await webSearch({
|
|
2721
|
+
query: `${t.company} careers ${t.jobTitle} site:lever.co OR site:greenhouse.io OR site:workable.com OR site:ashbyhq.com`,
|
|
2722
|
+
maxResults: 5
|
|
2723
|
+
}, { playName: PLAY_NAME$19 });
|
|
2724
|
+
receiptIds.push(search.receiptId);
|
|
2725
|
+
jobUrl = search.result.results[0]?.url;
|
|
2726
|
+
}
|
|
2727
|
+
if (jobUrl) {
|
|
2728
|
+
const read = await webRead({ url: jobUrl }, { playName: PLAY_NAME$19 });
|
|
2729
|
+
receiptIds.push(read.receiptId);
|
|
2730
|
+
const md = read.result.markdown ?? "";
|
|
2731
|
+
jobPostHook = (md.match(/(?:About the role|Responsibilities|Requirements|What you[' ]?ll do)[^\n]*\n+([\s\S]{40,300})/i)?.[1] ?? md.slice(0, 400)).replace(/\s+/g, " ").trim();
|
|
2732
|
+
}
|
|
2185
2733
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
source: `accelerator-${target.cohort}`
|
|
2214
|
-
},
|
|
2215
|
-
metadata: {
|
|
2216
|
-
senderCohort: opts.senderCohort,
|
|
2217
|
-
prospectCohort: target.cohort
|
|
2218
|
-
},
|
|
2219
|
-
dryRun: opts.dryRun
|
|
2220
|
-
});
|
|
2221
|
-
if (send.sent) {
|
|
2222
|
-
const prospect = getLedger().findProspectByEmail(target.email);
|
|
2223
|
-
if (prospect) enrollInCadence({
|
|
2224
|
-
prospectId: prospect.id,
|
|
2225
|
-
playName: PLAY_NAME$17
|
|
2226
|
-
});
|
|
2227
|
-
}
|
|
2228
|
-
drafted.push({
|
|
2229
|
-
target,
|
|
2230
|
-
subject: draft.subject,
|
|
2231
|
-
body: draft.body,
|
|
2232
|
-
receiptIds: [...receiptIds, ...send.receiptIds],
|
|
2233
|
-
sent: send.sent,
|
|
2234
|
-
flags
|
|
2235
|
-
});
|
|
2236
|
-
} catch (err) {
|
|
2237
|
-
drafted.push({
|
|
2238
|
-
target,
|
|
2239
|
-
...errorDraft(err?.message)
|
|
2240
|
-
});
|
|
2241
|
-
}
|
|
2242
|
-
return { drafted };
|
|
2734
|
+
return {
|
|
2735
|
+
receiptIds,
|
|
2736
|
+
dossier: "",
|
|
2737
|
+
extra: { jobPostHook }
|
|
2738
|
+
};
|
|
2739
|
+
},
|
|
2740
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
2741
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2742
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2743
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2744
|
+
`JOB TITLE: ${t.jobTitle}`,
|
|
2745
|
+
`JOB POST HOOK (real phrase from the post): ${prep.extra?.jobPostHook ?? NO_HOOK}`,
|
|
2746
|
+
`YOUR CLAIM: ${t.yourClaim}`
|
|
2747
|
+
].join("\n"),
|
|
2748
|
+
prospectMeta: (t) => ({
|
|
2749
|
+
name: t.name,
|
|
2750
|
+
email: t.email,
|
|
2751
|
+
company: t.company,
|
|
2752
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2753
|
+
phone: t.phone ?? null,
|
|
2754
|
+
source: "hiring-signal"
|
|
2755
|
+
}),
|
|
2756
|
+
metadata: (t) => ({
|
|
2757
|
+
jobTitle: t.jobTitle,
|
|
2758
|
+
jobPostUrl: t.jobPostUrl ?? null
|
|
2759
|
+
})
|
|
2760
|
+
}, opts);
|
|
2243
2761
|
}
|
|
2244
2762
|
registerSequence({
|
|
2245
|
-
playName: PLAY_NAME$
|
|
2763
|
+
playName: PLAY_NAME$19,
|
|
2246
2764
|
steps: [{
|
|
2247
|
-
dayOffset:
|
|
2765
|
+
dayOffset: 3,
|
|
2248
2766
|
channel: "email",
|
|
2249
2767
|
breakOnReply: true,
|
|
2250
|
-
label: "
|
|
2768
|
+
label: "value follow-up",
|
|
2251
2769
|
builder: buildFollowUpEmail({
|
|
2252
|
-
playName: PLAY_NAME$
|
|
2253
|
-
promptName: "
|
|
2254
|
-
contextLines: [`PLAY:
|
|
2770
|
+
playName: PLAY_NAME$19,
|
|
2771
|
+
promptName: "hiring-signal-followup",
|
|
2772
|
+
contextLines: [`PLAY: hiring-signal. Day-3 value follow-up about the open role.`]
|
|
2255
2773
|
})
|
|
2256
|
-
}
|
|
2257
|
-
|
|
2258
|
-
//#endregion
|
|
2259
|
-
//#region ../../packages/plays/src/demo-no-show.ts
|
|
2260
|
-
const PLAY_NAME$16 = "demo-no-show";
|
|
2261
|
-
registerSequence({
|
|
2262
|
-
playName: PLAY_NAME$16,
|
|
2263
|
-
steps: [{
|
|
2264
|
-
dayOffset: 3,
|
|
2774
|
+
}, {
|
|
2775
|
+
dayOffset: 8,
|
|
2265
2776
|
channel: "email",
|
|
2266
2777
|
breakOnReply: true,
|
|
2267
|
-
label: "
|
|
2778
|
+
label: "breakup",
|
|
2268
2779
|
builder: buildFollowUpEmail({
|
|
2269
|
-
playName: PLAY_NAME$
|
|
2270
|
-
promptName: "
|
|
2271
|
-
contextLines: [`PLAY:
|
|
2780
|
+
playName: PLAY_NAME$19,
|
|
2781
|
+
promptName: "breakup-email",
|
|
2782
|
+
contextLines: [`PLAY: hiring-signal. Final breakup.`]
|
|
2272
2783
|
})
|
|
2273
2784
|
}]
|
|
2274
2785
|
});
|
|
2275
2786
|
//#endregion
|
|
2276
|
-
//#region ../../packages/plays/src/
|
|
2277
|
-
const PLAY_NAME$
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2787
|
+
//#region ../../packages/plays/src/job-change.ts
|
|
2788
|
+
const PLAY_NAME$18 = "job-change";
|
|
2789
|
+
const jobChangeDef = {
|
|
2790
|
+
playName: PLAY_NAME$18,
|
|
2791
|
+
promptName: "job-change-email",
|
|
2792
|
+
maxBodyWords: 100,
|
|
2793
|
+
enrollCadence: true,
|
|
2794
|
+
toEmail: (t) => t.email,
|
|
2795
|
+
prepare: (t, dryRun) => standardEnrich({
|
|
2796
|
+
playName: PLAY_NAME$18,
|
|
2797
|
+
enrichInput: {
|
|
2286
2798
|
...t.email ? { email: t.email } : {},
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
},
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
const evidence = scrapedEvidence ?? t.evidenceText ?? "(no evidence supplied)";
|
|
2319
|
-
const draft = await draftEmailFromPrompt({
|
|
2320
|
-
promptName: "competitor-switch-email",
|
|
2321
|
-
inputBlock: [
|
|
2322
|
-
`FOUNDER: ${cfg.founderName}`,
|
|
2323
|
-
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2324
|
-
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2325
|
-
`COMPETITOR: ${t.competitor}`,
|
|
2326
|
-
`EVIDENCE: ${evidence}`,
|
|
2327
|
-
`YOUR EDGE: ${t.yourEdge}`,
|
|
2328
|
-
`DOSSIER:\n${dossier || "(dry-run)"}`
|
|
2329
|
-
].join("\n")
|
|
2330
|
-
});
|
|
2331
|
-
const flags = lintEmail(draft.subject, draft.body, 100);
|
|
2332
|
-
const send = await sendDraftedEmail({
|
|
2333
|
-
playName: PLAY_NAME$15,
|
|
2334
|
-
to: t.email,
|
|
2335
|
-
draft,
|
|
2336
|
-
flags,
|
|
2337
|
-
prospectMeta: {
|
|
2338
|
-
name: t.name,
|
|
2339
|
-
email: t.email,
|
|
2340
|
-
company: t.company,
|
|
2341
|
-
linkedin_url: t.linkedinUrl ?? null,
|
|
2342
|
-
phone: t.phone ?? null,
|
|
2343
|
-
source: "competitor-switch"
|
|
2344
|
-
},
|
|
2345
|
-
metadata: {
|
|
2346
|
-
competitor: t.competitor,
|
|
2347
|
-
evidenceUrl: t.evidenceUrl ?? null
|
|
2348
|
-
},
|
|
2349
|
-
dryRun: opts.dryRun
|
|
2350
|
-
});
|
|
2351
|
-
if (send.sent) {
|
|
2352
|
-
const prospect = getLedger().findProspectByEmail(t.email);
|
|
2353
|
-
if (prospect) enrollInCadence({
|
|
2354
|
-
prospectId: prospect.id,
|
|
2355
|
-
playName: PLAY_NAME$15
|
|
2356
|
-
});
|
|
2357
|
-
}
|
|
2358
|
-
drafted.push({
|
|
2359
|
-
target: t,
|
|
2360
|
-
subject: draft.subject,
|
|
2361
|
-
body: draft.body,
|
|
2362
|
-
receiptIds: [...receiptIds, ...send.receiptIds],
|
|
2363
|
-
sent: send.sent,
|
|
2364
|
-
flags,
|
|
2365
|
-
...scrapedEvidence ? { scrapedEvidence } : {}
|
|
2366
|
-
});
|
|
2367
|
-
} catch (err) {
|
|
2368
|
-
drafted.push({
|
|
2369
|
-
target: t,
|
|
2370
|
-
...errorDraft(err?.message)
|
|
2371
|
-
});
|
|
2372
|
-
}
|
|
2373
|
-
return { drafted };
|
|
2374
|
-
}
|
|
2375
|
-
function extractDomain$1(email) {
|
|
2376
|
-
const at = email.indexOf("@");
|
|
2377
|
-
if (at < 0) return void 0;
|
|
2378
|
-
return email.slice(at + 1);
|
|
2799
|
+
...t.linkedinUrl ? { linkedinUrl: t.linkedinUrl } : {},
|
|
2800
|
+
name: t.name
|
|
2801
|
+
},
|
|
2802
|
+
enrichSlice: 4e3,
|
|
2803
|
+
...dryRun ? {} : { research: { topic: `Public posts, talks, and recent decisions by ${t.name} (joined ${t.newCompany} as ${t.newRole}, formerly ${t.previousRole ?? "?"} at ${t.previousCompany ?? "?"})` } }
|
|
2804
|
+
}),
|
|
2805
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
2806
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2807
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2808
|
+
`PROSPECT: ${t.name}`,
|
|
2809
|
+
`NEW ROLE: ${t.newRole} at ${t.newCompany}`,
|
|
2810
|
+
`PREVIOUS: ${t.previousRole ?? "unknown"} at ${t.previousCompany ?? "unknown"}`,
|
|
2811
|
+
`DOSSIER:\n${prep.dossier || "(dry-run; rely on the trigger only)"}`
|
|
2812
|
+
].join("\n"),
|
|
2813
|
+
prospectMeta: (t) => ({
|
|
2814
|
+
name: t.name,
|
|
2815
|
+
email: t.email,
|
|
2816
|
+
company: t.newCompany,
|
|
2817
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2818
|
+
phone: t.phone ?? null,
|
|
2819
|
+
source: "job-change"
|
|
2820
|
+
}),
|
|
2821
|
+
metadata: (t) => ({
|
|
2822
|
+
newRole: t.newRole,
|
|
2823
|
+
newCompany: t.newCompany
|
|
2824
|
+
})
|
|
2825
|
+
};
|
|
2826
|
+
function runJobChange(opts) {
|
|
2827
|
+
return runEmailPlay(jobChangeDef, opts);
|
|
2379
2828
|
}
|
|
2380
2829
|
registerSequence({
|
|
2381
|
-
playName: PLAY_NAME$
|
|
2830
|
+
playName: PLAY_NAME$18,
|
|
2382
2831
|
steps: [{
|
|
2383
|
-
dayOffset:
|
|
2832
|
+
dayOffset: 5,
|
|
2384
2833
|
channel: "email",
|
|
2385
2834
|
breakOnReply: true,
|
|
2386
2835
|
label: "value follow-up",
|
|
2387
2836
|
builder: buildFollowUpEmail({
|
|
2388
|
-
playName: PLAY_NAME$
|
|
2389
|
-
promptName: "
|
|
2390
|
-
contextLines: [`
|
|
2837
|
+
playName: PLAY_NAME$18,
|
|
2838
|
+
promptName: "job-change-followup",
|
|
2839
|
+
contextLines: [`CONTEXT: prospect recently joined a new role; first email went unanswered ~5 days ago.`]
|
|
2391
2840
|
})
|
|
2392
2841
|
}, {
|
|
2393
|
-
dayOffset:
|
|
2842
|
+
dayOffset: 9,
|
|
2394
2843
|
channel: "email",
|
|
2395
2844
|
breakOnReply: true,
|
|
2396
2845
|
label: "breakup",
|
|
2397
2846
|
builder: buildFollowUpEmail({
|
|
2398
|
-
playName: PLAY_NAME$
|
|
2847
|
+
playName: PLAY_NAME$18,
|
|
2399
2848
|
promptName: "breakup-email",
|
|
2400
|
-
contextLines: [`PLAY:
|
|
2849
|
+
contextLines: [`PLAY: job-change. Sender is closing the file.`]
|
|
2401
2850
|
})
|
|
2402
2851
|
}]
|
|
2403
2852
|
});
|
|
2404
2853
|
//#endregion
|
|
2405
|
-
//#region ../../packages/plays/src/
|
|
2406
|
-
const PLAY_NAME$
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
if (prospect) enrollInCadence({
|
|
2454
|
-
prospectId: prospect.id,
|
|
2455
|
-
playName: PLAY_NAME$14
|
|
2456
|
-
});
|
|
2457
|
-
}
|
|
2458
|
-
drafted.push({
|
|
2459
|
-
target: t,
|
|
2460
|
-
subject: draft.subject,
|
|
2461
|
-
body: draft.body,
|
|
2462
|
-
receiptIds: [...receiptIds, ...send.receiptIds],
|
|
2463
|
-
sent: send.sent,
|
|
2464
|
-
flags
|
|
2465
|
-
});
|
|
2466
|
-
} catch (err) {
|
|
2467
|
-
drafted.push({
|
|
2468
|
-
target: t,
|
|
2469
|
-
...errorDraft(err?.message)
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2472
|
-
return { drafted };
|
|
2854
|
+
//#region ../../packages/plays/src/podcast-guest.ts
|
|
2855
|
+
const PLAY_NAME$17 = "podcast-guest";
|
|
2856
|
+
function runPodcastGuest(opts) {
|
|
2857
|
+
return runEmailPlay({
|
|
2858
|
+
playName: PLAY_NAME$17,
|
|
2859
|
+
promptName: "podcast-guest-email",
|
|
2860
|
+
maxBodyWords: 90,
|
|
2861
|
+
enrollCadence: true,
|
|
2862
|
+
toEmail: (t) => t.email,
|
|
2863
|
+
prepare: async (t, dryRun) => {
|
|
2864
|
+
const receiptIds = [];
|
|
2865
|
+
let dossier = "";
|
|
2866
|
+
if (!dryRun && !opts.skipSearch) {
|
|
2867
|
+
const s = await webSearch({
|
|
2868
|
+
query: `${t.name} ${t.podcast} "${t.episodeTitle}" notes OR transcript`,
|
|
2869
|
+
maxResults: 3
|
|
2870
|
+
}, { playName: PLAY_NAME$17 });
|
|
2871
|
+
receiptIds.push(s.receiptId);
|
|
2872
|
+
dossier = s.result.results.slice(0, 2).map((r) => `- ${r.title}: ${r.description}`).join("\n");
|
|
2873
|
+
}
|
|
2874
|
+
return {
|
|
2875
|
+
receiptIds,
|
|
2876
|
+
dossier
|
|
2877
|
+
};
|
|
2878
|
+
},
|
|
2879
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
2880
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2881
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2882
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2883
|
+
`PODCAST: ${t.podcast}`,
|
|
2884
|
+
`EPISODE: ${t.episodeTitle}`,
|
|
2885
|
+
`HOOK QUOTE: ${t.hookQuote}`,
|
|
2886
|
+
`BRIDGE TO YOUR WORK: ${t.bridge ?? "(none — keep the email purely about their point)"}`,
|
|
2887
|
+
`EXTRA CONTEXT FROM SEARCH:\n${prep.dossier || "(none)"}`
|
|
2888
|
+
].join("\n"),
|
|
2889
|
+
prospectMeta: (t) => ({
|
|
2890
|
+
name: t.name,
|
|
2891
|
+
email: t.email,
|
|
2892
|
+
company: t.company,
|
|
2893
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2894
|
+
phone: t.phone ?? null,
|
|
2895
|
+
source: "podcast-guest"
|
|
2896
|
+
}),
|
|
2897
|
+
metadata: (t) => ({
|
|
2898
|
+
podcast: t.podcast,
|
|
2899
|
+
episodeTitle: t.episodeTitle
|
|
2900
|
+
})
|
|
2901
|
+
}, opts);
|
|
2473
2902
|
}
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2903
|
+
registerSequence({
|
|
2904
|
+
playName: PLAY_NAME$17,
|
|
2905
|
+
steps: []
|
|
2906
|
+
});
|
|
2907
|
+
//#endregion
|
|
2908
|
+
//#region ../../packages/plays/src/post-funding.ts
|
|
2909
|
+
const PLAY_NAME$16 = "post-funding";
|
|
2910
|
+
const postFundingDef = {
|
|
2911
|
+
playName: PLAY_NAME$16,
|
|
2912
|
+
promptName: "post-funding-email",
|
|
2913
|
+
maxBodyWords: 100,
|
|
2914
|
+
enrollCadence: true,
|
|
2915
|
+
toEmail: (t) => t.email,
|
|
2916
|
+
prepare: (t, dryRun) => standardEnrich({
|
|
2917
|
+
playName: PLAY_NAME$16,
|
|
2918
|
+
enrichInput: {
|
|
2919
|
+
...t.email ? { email: t.email } : {},
|
|
2920
|
+
...t.linkedinUrl ? { linkedinUrl: t.linkedinUrl } : {},
|
|
2921
|
+
name: t.name
|
|
2922
|
+
},
|
|
2923
|
+
enrichSlice: 3500,
|
|
2924
|
+
...dryRun ? {} : { research: { topic: `${t.company} ${t.round} announcement: open job postings, hiring page, public roadmap, named challenges in the press release. Source: ${t.sourceUrl}` } }
|
|
2925
|
+
}),
|
|
2926
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
2927
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2928
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2929
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2930
|
+
`ROUND: ${t.round} ($${t.amountUsd.toLocaleString()})`,
|
|
2931
|
+
`LEAD INVESTOR: ${t.leadInvestor ?? "(unspecified)"}`,
|
|
2932
|
+
`SOURCE: ${t.sourceUrl}`,
|
|
2933
|
+
`DOSSIER:\n${prep.dossier || "(dry-run; rely on the round details only)"}`
|
|
2934
|
+
].join("\n"),
|
|
2935
|
+
prospectMeta: (t) => ({
|
|
2936
|
+
name: t.name,
|
|
2937
|
+
email: t.email,
|
|
2938
|
+
company: t.company,
|
|
2939
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
2940
|
+
phone: t.phone ?? null,
|
|
2941
|
+
source: "post-funding"
|
|
2942
|
+
}),
|
|
2943
|
+
metadata: (t) => ({
|
|
2944
|
+
round: t.round,
|
|
2945
|
+
amountUsd: t.amountUsd,
|
|
2946
|
+
leadInvestor: t.leadInvestor
|
|
2947
|
+
})
|
|
2948
|
+
};
|
|
2949
|
+
function runPostFunding(opts) {
|
|
2950
|
+
return runEmailPlay(postFundingDef, opts);
|
|
2478
2951
|
}
|
|
2479
2952
|
registerSequence({
|
|
2480
|
-
playName: PLAY_NAME$
|
|
2953
|
+
playName: PLAY_NAME$16,
|
|
2481
2954
|
steps: [{
|
|
2482
|
-
dayOffset:
|
|
2955
|
+
dayOffset: 9,
|
|
2483
2956
|
channel: "email",
|
|
2484
2957
|
breakOnReply: true,
|
|
2485
|
-
label: "
|
|
2958
|
+
label: "case-study follow-up",
|
|
2486
2959
|
builder: buildFollowUpEmail({
|
|
2487
|
-
playName: PLAY_NAME$
|
|
2488
|
-
promptName: "
|
|
2489
|
-
contextLines: [`
|
|
2960
|
+
playName: PLAY_NAME$16,
|
|
2961
|
+
promptName: "post-funding-followup",
|
|
2962
|
+
contextLines: [`CONTEXT: prospect's company recently raised; first email sent ~9 days ago, no reply.`]
|
|
2490
2963
|
})
|
|
2491
2964
|
}, {
|
|
2492
|
-
dayOffset:
|
|
2965
|
+
dayOffset: 9,
|
|
2493
2966
|
channel: "email",
|
|
2494
2967
|
breakOnReply: true,
|
|
2495
2968
|
label: "breakup",
|
|
2496
2969
|
builder: buildFollowUpEmail({
|
|
2497
|
-
playName: PLAY_NAME$
|
|
2970
|
+
playName: PLAY_NAME$16,
|
|
2498
2971
|
promptName: "breakup-email",
|
|
2499
|
-
contextLines: [`PLAY:
|
|
2972
|
+
contextLines: [`PLAY: post-funding.`]
|
|
2500
2973
|
})
|
|
2501
2974
|
}]
|
|
2502
2975
|
});
|
|
2503
2976
|
//#endregion
|
|
2504
|
-
//#region ../../packages/plays/src/
|
|
2505
|
-
const PLAY_NAME$
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
}
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
return
|
|
2977
|
+
//#region ../../packages/plays/src/repo-interest.ts
|
|
2978
|
+
const PLAY_NAME$15 = "repo-interest";
|
|
2979
|
+
const repoInterestDef = {
|
|
2980
|
+
playName: PLAY_NAME$15,
|
|
2981
|
+
promptName: "repo-interest-email",
|
|
2982
|
+
maxBodyWords: 90,
|
|
2983
|
+
toEmail: (t) => t.email,
|
|
2984
|
+
prepare: (t) => standardEnrich({
|
|
2985
|
+
playName: PLAY_NAME$15,
|
|
2986
|
+
enrichInput: {
|
|
2987
|
+
...t.email ? { email: t.email } : {},
|
|
2988
|
+
name: t.name,
|
|
2989
|
+
companyDomain: emailDomain(t.email)
|
|
2990
|
+
},
|
|
2991
|
+
enrichSlice: 3500
|
|
2992
|
+
}),
|
|
2993
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
2994
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
2995
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
2996
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
2997
|
+
`STARRED REPO: ${t.repoLabel ?? t.repo}`,
|
|
2998
|
+
`YOUR EDGE: ${t.yourEdge}`,
|
|
2999
|
+
`DOSSIER:\n${prep.dossier || "(dry-run)"}`
|
|
3000
|
+
].join("\n"),
|
|
3001
|
+
prospectMeta: (t) => ({
|
|
3002
|
+
name: t.name,
|
|
3003
|
+
email: t.email,
|
|
3004
|
+
company: t.company,
|
|
3005
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
3006
|
+
phone: t.phone ?? null,
|
|
3007
|
+
source: "repo-interest"
|
|
3008
|
+
}),
|
|
3009
|
+
metadata: (t) => ({ repo: t.repo })
|
|
3010
|
+
};
|
|
3011
|
+
function runRepoInterest(opts) {
|
|
3012
|
+
return runEmailPlay(repoInterestDef, opts);
|
|
3013
|
+
}
|
|
3014
|
+
//#endregion
|
|
3015
|
+
//#region ../../packages/plays/src/show-hn.ts
|
|
3016
|
+
const PLAY_NAME$14 = "show-hn";
|
|
3017
|
+
const showHnDef = {
|
|
3018
|
+
playName: PLAY_NAME$14,
|
|
3019
|
+
promptName: "show-hn-email",
|
|
3020
|
+
maxBodyWords: 90,
|
|
3021
|
+
toEmail: (t) => t.founderEmail,
|
|
3022
|
+
prepare: (t, dryRun) => standardEnrich({
|
|
3023
|
+
playName: PLAY_NAME$14,
|
|
3024
|
+
enrichInput: {
|
|
3025
|
+
email: t.founderEmail,
|
|
3026
|
+
name: t.founderName
|
|
3027
|
+
},
|
|
3028
|
+
enrichSlice: 3500,
|
|
3029
|
+
...dryRun ? {} : { research: { topic: `Recent public work and engineering decisions by ${t.founderName} on ${t.postTitle}` } }
|
|
3030
|
+
}),
|
|
3031
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
3032
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
3033
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
3034
|
+
`SHOW HN: ${t.postTitle}`,
|
|
3035
|
+
`URL: ${t.postUrl}`,
|
|
3036
|
+
`HOOK: ${t.hookSummary}`,
|
|
3037
|
+
`DOSSIER:\n${prep.dossier || "(dry-run; rely on the hook only)"}`
|
|
3038
|
+
].join("\n"),
|
|
3039
|
+
prospectMeta: (t) => ({
|
|
3040
|
+
name: t.founderName,
|
|
3041
|
+
email: t.founderEmail,
|
|
3042
|
+
company: extractCompany(t.postTitle),
|
|
3043
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
3044
|
+
phone: t.phone ?? null,
|
|
3045
|
+
source: "show-hn"
|
|
3046
|
+
}),
|
|
3047
|
+
metadata: (t) => ({
|
|
3048
|
+
postUrl: t.postUrl,
|
|
3049
|
+
postTitle: t.postTitle
|
|
3050
|
+
})
|
|
3051
|
+
};
|
|
3052
|
+
function runShowHn(opts) {
|
|
3053
|
+
return runEmailPlay(showHnDef, opts);
|
|
3054
|
+
}
|
|
3055
|
+
function extractCompany(title) {
|
|
3056
|
+
const m = title.match(/Show HN:\s*([^\s—–:|-]+)/i);
|
|
3057
|
+
return m ? m[1] ?? null : null;
|
|
3058
|
+
}
|
|
3059
|
+
//#endregion
|
|
3060
|
+
//#region ../../packages/plays/src/stack-consolidation.ts
|
|
3061
|
+
const PLAY_NAME$13 = "stack-consolidation";
|
|
3062
|
+
const stackConsolidationDef = {
|
|
3063
|
+
playName: PLAY_NAME$13,
|
|
3064
|
+
promptName: "stack-consolidation-email",
|
|
3065
|
+
maxBodyWords: 100,
|
|
3066
|
+
enrollCadence: true,
|
|
3067
|
+
toEmail: (t) => t.email,
|
|
3068
|
+
prepare: (t) => standardEnrich({
|
|
3069
|
+
playName: PLAY_NAME$13,
|
|
3070
|
+
enrichInput: {
|
|
3071
|
+
...t.email ? { email: t.email } : {},
|
|
3072
|
+
name: t.name,
|
|
3073
|
+
companyDomain: emailDomain(t.email)
|
|
3074
|
+
},
|
|
3075
|
+
enrichSlice: 3500
|
|
3076
|
+
}),
|
|
3077
|
+
buildInputBlock: (t, prep, cfg) => [
|
|
3078
|
+
`FOUNDER: ${cfg.founderName}`,
|
|
3079
|
+
`PRODUCT: ${cfg.productOneLiner}`,
|
|
3080
|
+
`PROSPECT: ${t.name} at ${t.company}`,
|
|
3081
|
+
`STACK: ${t.vendorStack}`,
|
|
3082
|
+
`YOUR EDGE: ${t.yourEdge}`,
|
|
3083
|
+
`DOSSIER:\n${prep.dossier || "(dry-run)"}`
|
|
3084
|
+
].join("\n"),
|
|
3085
|
+
prospectMeta: (t) => ({
|
|
3086
|
+
name: t.name,
|
|
3087
|
+
email: t.email,
|
|
3088
|
+
company: t.company,
|
|
3089
|
+
linkedin_url: t.linkedinUrl ?? null,
|
|
3090
|
+
phone: t.phone ?? null,
|
|
3091
|
+
source: "stack-consolidation"
|
|
3092
|
+
}),
|
|
3093
|
+
metadata: (t) => ({
|
|
3094
|
+
vendorStack: t.vendorStack,
|
|
3095
|
+
evidenceUrl: t.evidenceUrl ?? null
|
|
3096
|
+
})
|
|
3097
|
+
};
|
|
3098
|
+
function runStackConsolidation(opts) {
|
|
3099
|
+
return runEmailPlay(stackConsolidationDef, opts);
|
|
2585
3100
|
}
|
|
2586
3101
|
registerSequence({
|
|
2587
3102
|
playName: PLAY_NAME$13,
|
|
@@ -2592,8 +3107,8 @@ registerSequence({
|
|
|
2592
3107
|
label: "value follow-up",
|
|
2593
3108
|
builder: buildFollowUpEmail({
|
|
2594
3109
|
playName: PLAY_NAME$13,
|
|
2595
|
-
promptName: "
|
|
2596
|
-
contextLines: [`PLAY:
|
|
3110
|
+
promptName: "stack-consolidation-followup",
|
|
3111
|
+
contextLines: [`PLAY: stack-consolidation. Day-3 value follow-up after the consolidation-honesty pitch.`]
|
|
2597
3112
|
})
|
|
2598
3113
|
}, {
|
|
2599
3114
|
dayOffset: 8,
|
|
@@ -2603,171 +3118,406 @@ registerSequence({
|
|
|
2603
3118
|
builder: buildFollowUpEmail({
|
|
2604
3119
|
playName: PLAY_NAME$13,
|
|
2605
3120
|
promptName: "breakup-email",
|
|
2606
|
-
contextLines: [`PLAY:
|
|
3121
|
+
contextLines: [`PLAY: stack-consolidation. Final breakup after the consolidation-honesty pitch.`]
|
|
2607
3122
|
})
|
|
2608
3123
|
}]
|
|
2609
3124
|
});
|
|
2610
3125
|
//#endregion
|
|
2611
|
-
//#region ../../packages/plays/src/
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
const prospect = getLedger().findProspectByEmail(t.email);
|
|
2665
|
-
if (prospect) enrollInCadence({
|
|
2666
|
-
prospectId: prospect.id,
|
|
2667
|
-
playName: PLAY_NAME$12
|
|
2668
|
-
});
|
|
2669
|
-
}
|
|
2670
|
-
drafted.push({
|
|
2671
|
-
target: t,
|
|
2672
|
-
subject: draft.subject,
|
|
2673
|
-
body: draft.body,
|
|
2674
|
-
receiptIds: [...receiptIds, ...send.receiptIds],
|
|
2675
|
-
sent: send.sent,
|
|
2676
|
-
flags
|
|
2677
|
-
});
|
|
2678
|
-
} catch (err) {
|
|
2679
|
-
drafted.push({
|
|
2680
|
-
target: t,
|
|
2681
|
-
...errorDraft(err?.message)
|
|
2682
|
-
});
|
|
2683
|
-
}
|
|
2684
|
-
return { drafted };
|
|
3126
|
+
//#region ../../packages/plays/src/registry.ts
|
|
3127
|
+
/**
|
|
3128
|
+
* Single source of truth mapping a play name → its runner. Both the server's
|
|
3129
|
+
* `/api/run` dispatch and the queue drainer look plays up here, so adding a
|
|
3130
|
+
* play means registering it once (its file + this table) instead of editing
|
|
3131
|
+
* two parallel switch statements that silently drifted apart.
|
|
3132
|
+
*/
|
|
3133
|
+
const PLAYS = {
|
|
3134
|
+
"show-hn": { run: (o) => runShowHn({
|
|
3135
|
+
dryRun: o.dryRun,
|
|
3136
|
+
targets: o.targets
|
|
3137
|
+
}) },
|
|
3138
|
+
"job-change": { run: (o) => runJobChange({
|
|
3139
|
+
dryRun: o.dryRun,
|
|
3140
|
+
targets: o.targets
|
|
3141
|
+
}) },
|
|
3142
|
+
"post-funding": { run: (o) => runPostFunding({
|
|
3143
|
+
dryRun: o.dryRun,
|
|
3144
|
+
targets: o.targets
|
|
3145
|
+
}) },
|
|
3146
|
+
"accelerator-batch": { run: (o) => runAcceleratorBatch({
|
|
3147
|
+
dryRun: o.dryRun,
|
|
3148
|
+
targets: o.targets,
|
|
3149
|
+
...o.senderCohort ? { senderCohort: o.senderCohort } : {},
|
|
3150
|
+
...o.freeForCohortOffer ? { freeForCohortOffer: o.freeForCohortOffer } : {}
|
|
3151
|
+
}) },
|
|
3152
|
+
"hiring-signal": { run: (o) => runHiringSignal({
|
|
3153
|
+
dryRun: o.dryRun,
|
|
3154
|
+
targets: o.targets
|
|
3155
|
+
}) },
|
|
3156
|
+
"podcast-guest": { run: (o) => runPodcastGuest({
|
|
3157
|
+
dryRun: o.dryRun,
|
|
3158
|
+
targets: o.targets
|
|
3159
|
+
}) },
|
|
3160
|
+
"competitor-switch": { run: (o) => runCompetitorSwitch({
|
|
3161
|
+
dryRun: o.dryRun,
|
|
3162
|
+
targets: o.targets
|
|
3163
|
+
}) },
|
|
3164
|
+
"stack-consolidation": { run: (o) => runStackConsolidation({
|
|
3165
|
+
dryRun: o.dryRun,
|
|
3166
|
+
targets: o.targets
|
|
3167
|
+
}) },
|
|
3168
|
+
"repo-interest": { run: (o) => runRepoInterest({
|
|
3169
|
+
dryRun: o.dryRun,
|
|
3170
|
+
targets: o.targets
|
|
3171
|
+
}) },
|
|
3172
|
+
"breakup-revive": { run: (o) => runBreakupRevive({
|
|
3173
|
+
dryRun: o.dryRun,
|
|
3174
|
+
targets: o.targets
|
|
3175
|
+
}) }
|
|
3176
|
+
};
|
|
3177
|
+
function isSupportedPlay(name) {
|
|
3178
|
+
return Object.prototype.hasOwnProperty.call(PLAYS, name);
|
|
2685
3179
|
}
|
|
3180
|
+
//#endregion
|
|
3181
|
+
//#region ../../packages/plays/src/demo-no-show.ts
|
|
3182
|
+
const PLAY_NAME$12 = "demo-no-show";
|
|
2686
3183
|
registerSequence({
|
|
2687
3184
|
playName: PLAY_NAME$12,
|
|
2688
|
-
steps: [
|
|
3185
|
+
steps: [{
|
|
3186
|
+
dayOffset: 3,
|
|
3187
|
+
channel: "email",
|
|
3188
|
+
breakOnReply: true,
|
|
3189
|
+
label: "day-3 follow-up",
|
|
3190
|
+
builder: buildFollowUpEmail({
|
|
3191
|
+
playName: PLAY_NAME$12,
|
|
3192
|
+
promptName: "demo-no-show-followup",
|
|
3193
|
+
contextLines: [`PLAY: demo-no-show day-3 follow-up. After this, drop the lead.`]
|
|
3194
|
+
})
|
|
3195
|
+
}]
|
|
2689
3196
|
});
|
|
2690
3197
|
//#endregion
|
|
2691
|
-
//#region
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
email: t.email,
|
|
2720
|
-
company: t.company,
|
|
2721
|
-
linkedin_url: t.linkedinUrl ?? null,
|
|
2722
|
-
phone: t.phone ?? null,
|
|
2723
|
-
source: "breakup-revive"
|
|
2724
|
-
},
|
|
2725
|
-
metadata: {
|
|
2726
|
-
daysCold: t.daysCold,
|
|
2727
|
-
lastEventAt: t.lastEventAt
|
|
2728
|
-
},
|
|
2729
|
-
dryRun: opts.dryRun
|
|
2730
|
-
});
|
|
2731
|
-
drafted.push({
|
|
2732
|
-
prospectEmail: t.email,
|
|
2733
|
-
prospectName: t.name,
|
|
2734
|
-
daysCold: t.daysCold,
|
|
2735
|
-
subject: draft.subject,
|
|
2736
|
-
body: draft.body,
|
|
2737
|
-
receiptIds: send.receiptIds,
|
|
2738
|
-
sent: send.sent,
|
|
2739
|
-
flags
|
|
3198
|
+
//#region src/api/cadences.ts
|
|
3199
|
+
/**
|
|
3200
|
+
* In-process tracker of cadence steps that have a fire-and-forget send in
|
|
3201
|
+
* flight. Populated by sendCadenceStepRoute + sendCadenceBatchRoute when
|
|
3202
|
+
* they kick off the background SDK send (~2 min per row), cleared per-row
|
|
3203
|
+
* as each send settles. Used by `toView` to surface `isSending: true` so
|
|
3204
|
+
* /cadences can visually mark in-flight rows AND gate them out of the
|
|
3205
|
+
* sendable-rows count. Lost on server restart (acceptable — in-flight SDK
|
|
3206
|
+
* calls die with the process anyway).
|
|
3207
|
+
*/
|
|
3208
|
+
const inFlightSends = /* @__PURE__ */ new Set();
|
|
3209
|
+
const inFlightKey = (prospectId, playName) => `${prospectId}|${playName}`;
|
|
3210
|
+
function buildPlayInfoMap(rows) {
|
|
3211
|
+
const map = /* @__PURE__ */ new Map();
|
|
3212
|
+
for (const row of rows) {
|
|
3213
|
+
let info = map.get(row.play_name);
|
|
3214
|
+
if (!info) {
|
|
3215
|
+
info = {
|
|
3216
|
+
nextLabelByStep: /* @__PURE__ */ new Map(),
|
|
3217
|
+
followupCount: playFollowupCount(row.play_name)
|
|
3218
|
+
};
|
|
3219
|
+
map.set(row.play_name, info);
|
|
3220
|
+
}
|
|
3221
|
+
if (!info.nextLabelByStep.has(row.current_step)) {
|
|
3222
|
+
const next = nextStepInfo(row.play_name, row.current_step);
|
|
3223
|
+
info.nextLabelByStep.set(row.current_step, {
|
|
3224
|
+
label: next?.label ?? null,
|
|
3225
|
+
isBreakup: next?.isBreakup ?? false
|
|
2740
3226
|
});
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
return map;
|
|
3230
|
+
}
|
|
3231
|
+
function toView$3(row, priorByKey, playInfo) {
|
|
3232
|
+
let nextStepDraft = null;
|
|
3233
|
+
if (row.next_step_draft_json) try {
|
|
3234
|
+
const parsed = JSON.parse(row.next_step_draft_json);
|
|
3235
|
+
nextStepDraft = {
|
|
3236
|
+
subject: parsed.subject,
|
|
3237
|
+
body: parsed.body,
|
|
3238
|
+
flags: parsed.flags ?? [],
|
|
3239
|
+
draftedAt: parsed.draftedAt
|
|
3240
|
+
};
|
|
3241
|
+
} catch {
|
|
3242
|
+
nextStepDraft = null;
|
|
3243
|
+
}
|
|
3244
|
+
const info = playInfo.get(row.play_name);
|
|
3245
|
+
const next = info?.nextLabelByStep.get(row.current_step) ?? null;
|
|
3246
|
+
const followupCount = info?.followupCount ?? 0;
|
|
3247
|
+
const priorSteps = (priorByKey.get(`${row.prospect_id}|${row.play_name}`) ?? []).map((s) => ({
|
|
3248
|
+
stepIndex: s.stepIndex,
|
|
3249
|
+
label: s.label,
|
|
3250
|
+
subject: s.subject,
|
|
3251
|
+
body: s.body,
|
|
3252
|
+
sentAt: s.sentAt
|
|
3253
|
+
}));
|
|
3254
|
+
return {
|
|
3255
|
+
prospectId: row.prospect_id,
|
|
3256
|
+
prospectEmail: row.prospect_email,
|
|
3257
|
+
prospectName: row.prospect_name,
|
|
3258
|
+
prospectCompany: row.prospect_company,
|
|
3259
|
+
playName: row.play_name,
|
|
3260
|
+
status: row.status,
|
|
3261
|
+
currentStep: row.current_step,
|
|
3262
|
+
enrolledAt: row.enrolled_at,
|
|
3263
|
+
nextDueAt: row.next_due_at,
|
|
3264
|
+
lastPolledAt: row.last_polled_at,
|
|
3265
|
+
nextStepDraft,
|
|
3266
|
+
nextStepLabel: next?.label ?? null,
|
|
3267
|
+
nextStepIsBreakup: next?.isBreakup ?? false,
|
|
3268
|
+
followupCount,
|
|
3269
|
+
priorSteps,
|
|
3270
|
+
isSending: inFlightSends.has(inFlightKey(row.prospect_id, row.play_name))
|
|
3271
|
+
};
|
|
3272
|
+
}
|
|
3273
|
+
function viewsForRows(rows) {
|
|
3274
|
+
const priorByKey = getPriorStepsBulk(rows.map((r) => ({
|
|
3275
|
+
prospectId: r.prospect_id,
|
|
3276
|
+
playName: r.play_name
|
|
3277
|
+
})));
|
|
3278
|
+
const playInfo = buildPlayInfoMap(rows);
|
|
3279
|
+
return rows.map((r) => toView$3(r, priorByKey, playInfo));
|
|
3280
|
+
}
|
|
3281
|
+
function listCadences(req) {
|
|
3282
|
+
const all = new URL(req.url).searchParams.get("all") === "1";
|
|
3283
|
+
const ledger = getLedger();
|
|
3284
|
+
return jsonResponse({ cadences: viewsForRows(all ? ledger.listAllCadences() : ledger.listActiveCadences()) }, 200, req);
|
|
3285
|
+
}
|
|
3286
|
+
function getCadence(req, params) {
|
|
3287
|
+
const id = Number.parseInt(params["id"] ?? "", 10);
|
|
3288
|
+
if (!Number.isFinite(id)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
3289
|
+
const all = getLedger().listCadencesForProspect(id);
|
|
3290
|
+
if (all.length === 0) return jsonResponse({ error: "no cadences for prospect" }, 404, req);
|
|
3291
|
+
return jsonResponse({ cadences: viewsForRows(all) }, 200, req);
|
|
3292
|
+
}
|
|
3293
|
+
function stopCadence(req, params) {
|
|
3294
|
+
const id = Number.parseInt(params["id"] ?? "", 10);
|
|
3295
|
+
if (!Number.isFinite(id)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
3296
|
+
const playName = new URL(req.url).searchParams.get("play");
|
|
3297
|
+
const ledger = getLedger();
|
|
3298
|
+
const cadences = ledger.listCadencesForProspect(id).filter((c) => {
|
|
3299
|
+
if (playName && c.play_name !== playName) return false;
|
|
3300
|
+
return c.status === "active";
|
|
3301
|
+
});
|
|
3302
|
+
for (const cad of cadences) ledger.setCadenceStatus({
|
|
3303
|
+
prospectId: id,
|
|
3304
|
+
playName: cad.play_name,
|
|
3305
|
+
status: "completed"
|
|
3306
|
+
});
|
|
3307
|
+
return jsonResponse({ stopped: cadences.length }, 200, req);
|
|
3308
|
+
}
|
|
3309
|
+
function parseProspectAndPlay(req, params) {
|
|
3310
|
+
const prospectId = Number.parseInt(params["id"] ?? "", 10);
|
|
3311
|
+
if (!Number.isFinite(prospectId)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
3312
|
+
const playName = new URL(req.url).searchParams.get("play") ?? "";
|
|
3313
|
+
if (!playName) return jsonResponse({ error: "play query param required" }, 400, req);
|
|
3314
|
+
return {
|
|
3315
|
+
prospectId,
|
|
3316
|
+
playName
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
async function previewCadenceStepRoute(req, params) {
|
|
3320
|
+
const parsed = parseProspectAndPlay(req, params);
|
|
3321
|
+
if (parsed instanceof Response) return parsed;
|
|
3322
|
+
try {
|
|
3323
|
+
const preview = await previewCadenceStep(parsed);
|
|
3324
|
+
return jsonResponse({
|
|
3325
|
+
subject: preview.subject,
|
|
3326
|
+
body: preview.body,
|
|
3327
|
+
flags: preview.flags,
|
|
3328
|
+
draftedAt: preview.draftedAt,
|
|
3329
|
+
stepLabel: preview.stepLabel,
|
|
3330
|
+
isBreakup: preview.isBreakup
|
|
3331
|
+
}, 200, req);
|
|
3332
|
+
} catch (err) {
|
|
3333
|
+
const msg = err.message ?? "preview failed";
|
|
3334
|
+
const status = msg.startsWith("no cadence") || msg.startsWith("cadence is") ? 409 : 500;
|
|
3335
|
+
return jsonResponse({ error: msg }, status, req);
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
async function sendCadenceStepRoute(req, params) {
|
|
3339
|
+
const parsed = parseProspectAndPlay(req, params);
|
|
3340
|
+
if (parsed instanceof Response) return parsed;
|
|
3341
|
+
try {
|
|
3342
|
+
if (!getLedger().getCadenceDraft(parsed)) return jsonResponse({ error: "no persisted preview — click Preview first" }, 409, req);
|
|
3343
|
+
} catch (err) {
|
|
3344
|
+
return jsonResponse({ error: err.message ?? "send failed" }, 500, req);
|
|
3345
|
+
}
|
|
3346
|
+
const key = inFlightKey(parsed.prospectId, parsed.playName);
|
|
3347
|
+
inFlightSends.add(key);
|
|
3348
|
+
(async () => {
|
|
3349
|
+
try {
|
|
3350
|
+
await sendCadenceStep(parsed);
|
|
2741
3351
|
} catch (err) {
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
3352
|
+
logEvent("cadence.send.failed", {
|
|
3353
|
+
prospect_id: parsed.prospectId,
|
|
3354
|
+
play_name: parsed.playName,
|
|
3355
|
+
message_120: (err?.message ?? "").slice(0, 120)
|
|
3356
|
+
}, "error");
|
|
3357
|
+
} finally {
|
|
3358
|
+
inFlightSends.delete(key);
|
|
3359
|
+
}
|
|
3360
|
+
})();
|
|
3361
|
+
return jsonResponse({ accepted: true }, 202, req);
|
|
3362
|
+
}
|
|
3363
|
+
async function parseBatchItems(req) {
|
|
3364
|
+
let body;
|
|
3365
|
+
try {
|
|
3366
|
+
body = await req.json();
|
|
3367
|
+
} catch {
|
|
3368
|
+
return jsonResponse({ error: "invalid JSON body" }, 400, req);
|
|
3369
|
+
}
|
|
3370
|
+
if (!Array.isArray(body.items)) return jsonResponse({ error: "items: array required" }, 400, req);
|
|
3371
|
+
const items = [];
|
|
3372
|
+
for (const raw of body.items) if (raw && typeof raw === "object" && "prospectId" in raw && "playName" in raw) {
|
|
3373
|
+
const it = raw;
|
|
3374
|
+
if (typeof it.prospectId === "number" && typeof it.playName === "string") items.push({
|
|
3375
|
+
prospectId: it.prospectId,
|
|
3376
|
+
playName: it.playName
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
if (items.length === 0) return jsonResponse({ error: "no valid items in body" }, 400, req);
|
|
3380
|
+
return items;
|
|
3381
|
+
}
|
|
3382
|
+
async function previewCadenceBatchRoute(req) {
|
|
3383
|
+
const itemsOrErr = await parseBatchItems(req);
|
|
3384
|
+
if (itemsOrErr instanceof Response) return itemsOrErr;
|
|
3385
|
+
return jsonResponse({ results: await previewCadenceStepBatch(itemsOrErr) }, 200, req);
|
|
3386
|
+
}
|
|
3387
|
+
async function sendCadenceBatchRoute(req) {
|
|
3388
|
+
const itemsOrErr = await parseBatchItems(req);
|
|
3389
|
+
if (itemsOrErr instanceof Response) return itemsOrErr;
|
|
3390
|
+
const items = itemsOrErr;
|
|
3391
|
+
for (const item of items) inFlightSends.add(inFlightKey(item.prospectId, item.playName));
|
|
3392
|
+
(async () => {
|
|
3393
|
+
try {
|
|
3394
|
+
await sendCadenceStepBatch(items, (item) => {
|
|
3395
|
+
inFlightSends.delete(inFlightKey(item.prospectId, item.playName));
|
|
2752
3396
|
});
|
|
3397
|
+
} catch (err) {
|
|
3398
|
+
for (const item of items) inFlightSends.delete(inFlightKey(item.prospectId, item.playName));
|
|
3399
|
+
logEvent("cadence.batch.failed", { message_120: (err?.message ?? "").slice(0, 120) }, "error");
|
|
2753
3400
|
}
|
|
3401
|
+
})();
|
|
3402
|
+
return jsonResponse({ accepted: items.length }, 202, req);
|
|
3403
|
+
}
|
|
3404
|
+
//#endregion
|
|
3405
|
+
//#region src/api/receipts.ts
|
|
3406
|
+
function toView$2(row) {
|
|
3407
|
+
return {
|
|
3408
|
+
id: row.id,
|
|
3409
|
+
playName: row.play_name,
|
|
3410
|
+
callType: row.call_type,
|
|
3411
|
+
costUsd: row.cost_usd,
|
|
3412
|
+
oneshotRequestId: row.oneshot_request_id,
|
|
3413
|
+
createdAt: row.created_at
|
|
3414
|
+
};
|
|
3415
|
+
}
|
|
3416
|
+
function listReceipts(req) {
|
|
3417
|
+
const url = new URL(req.url);
|
|
3418
|
+
const playName = url.searchParams.get("play") ?? void 0;
|
|
3419
|
+
const sinceDays = Number.parseInt(url.searchParams.get("sinceDays") ?? "", 10);
|
|
3420
|
+
const limit = Math.min(500, Number.parseInt(url.searchParams.get("limit") ?? "200", 10) || 200);
|
|
3421
|
+
const sinceIso = Number.isFinite(sinceDays) ? (/* @__PURE__ */ new Date(Date.now() - sinceDays * 24 * 3600 * 1e3)).toISOString() : void 0;
|
|
3422
|
+
return jsonResponse({ receipts: getLedger().listReceipts({
|
|
3423
|
+
...playName ? { playName } : {},
|
|
3424
|
+
...sinceIso ? { sinceIso } : {},
|
|
3425
|
+
limit
|
|
3426
|
+
}).map(toView$2) }, 200, req);
|
|
3427
|
+
}
|
|
3428
|
+
function getReceipt(req, params) {
|
|
3429
|
+
const id = Number.parseInt(params["id"] ?? "", 10);
|
|
3430
|
+
if (!Number.isFinite(id)) return jsonResponse({ error: "bad id" }, 400, req);
|
|
3431
|
+
const r = getLedger().getReceipt(id);
|
|
3432
|
+
if (!r) return jsonResponse({ error: "not found" }, 404, req);
|
|
3433
|
+
let parsed = null;
|
|
3434
|
+
if (r.signed_receipt) try {
|
|
3435
|
+
parsed = JSON.parse(r.signed_receipt);
|
|
3436
|
+
} catch {
|
|
3437
|
+
parsed = r.signed_receipt;
|
|
2754
3438
|
}
|
|
2755
|
-
return {
|
|
3439
|
+
return jsonResponse({ receipt: {
|
|
3440
|
+
id: r.id,
|
|
3441
|
+
playName: r.play_name,
|
|
3442
|
+
callType: r.call_type,
|
|
3443
|
+
costUsd: r.cost_usd,
|
|
3444
|
+
oneshotRequestId: r.oneshot_request_id,
|
|
3445
|
+
createdAt: r.created_at,
|
|
3446
|
+
signedReceipt: parsed
|
|
3447
|
+
} }, 200, req);
|
|
2756
3448
|
}
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
3449
|
+
//#endregion
|
|
3450
|
+
//#region src/api/inbox.ts
|
|
3451
|
+
/** "Jane Doe <jane@x.com>" → "jane@x.com"; bare addresses pass through. */
|
|
3452
|
+
function normalizeFrom(raw) {
|
|
3453
|
+
const m = raw.match(/<([^>]+)>/);
|
|
3454
|
+
return (m ? m[1] ?? raw : raw).trim().toLowerCase();
|
|
3455
|
+
}
|
|
3456
|
+
/**
|
|
3457
|
+
* Read-only view of the OneShot inbox (replies to outreach). Each email is
|
|
3458
|
+
* matched to a known prospect by sender address, annotated with the play +
|
|
3459
|
+
* cadence status when available. Live fetch — no storage. The SDK exposes only
|
|
3460
|
+
* inboxList (no reply/markRead), so this is read-only.
|
|
3461
|
+
*/
|
|
3462
|
+
async function listInboxRoute(req) {
|
|
3463
|
+
const ledger = getLedger();
|
|
3464
|
+
let emails;
|
|
3465
|
+
try {
|
|
3466
|
+
emails = (await listInbox({ limit: 50 })).emails;
|
|
3467
|
+
} catch (err) {
|
|
3468
|
+
logEvent("inbox.list_failed", { message_120: (err?.message ?? "").slice(0, 120) }, "warn");
|
|
3469
|
+
return jsonResponse({
|
|
3470
|
+
replies: [],
|
|
3471
|
+
hasMore: false,
|
|
3472
|
+
error: "couldn't reach the inbox"
|
|
3473
|
+
}, 200, req);
|
|
3474
|
+
}
|
|
3475
|
+
const byEmail = /* @__PURE__ */ new Map();
|
|
3476
|
+
for (const c of ledger.listAllCadences()) {
|
|
3477
|
+
if (!c.prospect_email) continue;
|
|
3478
|
+
const key = c.prospect_email.trim().toLowerCase();
|
|
3479
|
+
const existing = byEmail.get(key);
|
|
3480
|
+
if (!existing || c.status === "replied" || c.status === "active" && existing.status !== "replied") byEmail.set(key, {
|
|
3481
|
+
name: c.prospect_name,
|
|
3482
|
+
company: c.prospect_company,
|
|
3483
|
+
playName: c.play_name,
|
|
3484
|
+
status: c.status
|
|
3485
|
+
});
|
|
3486
|
+
}
|
|
3487
|
+
const replies = emails.map((e) => {
|
|
3488
|
+
const fromEmail = normalizeFrom(e.from);
|
|
3489
|
+
let matched = null;
|
|
3490
|
+
const cadence = byEmail.get(fromEmail);
|
|
3491
|
+
if (cadence) matched = {
|
|
3492
|
+
name: cadence.name,
|
|
3493
|
+
company: cadence.company,
|
|
3494
|
+
playName: cadence.playName,
|
|
3495
|
+
cadenceStatus: cadence.status
|
|
3496
|
+
};
|
|
3497
|
+
else {
|
|
3498
|
+
const p = ledger.getProspectByEmail(fromEmail);
|
|
3499
|
+
if (p) matched = {
|
|
3500
|
+
name: p.name,
|
|
3501
|
+
company: p.company,
|
|
3502
|
+
playName: p.source,
|
|
3503
|
+
cadenceStatus: null
|
|
3504
|
+
};
|
|
3505
|
+
}
|
|
3506
|
+
return {
|
|
3507
|
+
id: e.id,
|
|
3508
|
+
fromEmail,
|
|
3509
|
+
fromRaw: e.from,
|
|
3510
|
+
subject: e.subject,
|
|
3511
|
+
receivedAt: e.received_at,
|
|
3512
|
+
body: e.body ?? "",
|
|
3513
|
+
matched
|
|
3514
|
+
};
|
|
3515
|
+
});
|
|
3516
|
+
const selfDomain = (loadConfig().sendingDomain ?? "").trim().toLowerCase();
|
|
3517
|
+
return jsonResponse({
|
|
3518
|
+
replies: replies.filter((r) => !selfDomain || !r.fromEmail.endsWith(`@${selfDomain}`)).toSorted((a, b) => a.receivedAt < b.receivedAt ? 1 : a.receivedAt > b.receivedAt ? -1 : 0),
|
|
3519
|
+
hasMore: false
|
|
3520
|
+
}, 200, req);
|
|
2771
3521
|
}
|
|
2772
3522
|
//#endregion
|
|
2773
3523
|
//#region src/api/plays.ts
|
|
@@ -2804,6 +3554,10 @@ const PLAY_CATALOG = [
|
|
|
2804
3554
|
name: "stack-consolidation",
|
|
2805
3555
|
cli: "oneshot-gtm find watch # fed by the github-topics finder, drained from /queue"
|
|
2806
3556
|
},
|
|
3557
|
+
{
|
|
3558
|
+
name: "repo-interest",
|
|
3559
|
+
cli: "oneshot-gtm find watch # fed by the github-stars finder (adjacent repos), drained from /queue"
|
|
3560
|
+
},
|
|
2807
3561
|
{
|
|
2808
3562
|
name: "hiring-signal",
|
|
2809
3563
|
cli: "oneshot-gtm motion hiring-signal --target ./examples/hiring-signal.json"
|
|
@@ -2828,12 +3582,13 @@ function listPlays(req) {
|
|
|
2828
3582
|
const seq = getSequence(p.name);
|
|
2829
3583
|
const channels = seq ? Array.from(new Set(seq.steps.map((s) => s.channel))) : ["email"];
|
|
2830
3584
|
const followupCount = seq?.steps.length ?? 0;
|
|
2831
|
-
const hasBreakup = seq
|
|
3585
|
+
const hasBreakup = seq ? isBreakupStepAt(seq, seq.steps.length - 1) : false;
|
|
2832
3586
|
const days = cumulativeDays(seq);
|
|
2833
3587
|
const steps = (seq?.steps ?? []).map((s, i) => ({
|
|
2834
3588
|
day: days[i] ?? 0,
|
|
2835
3589
|
label: s.label ?? `step ${i + 1}`,
|
|
2836
|
-
channel: s.channel
|
|
3590
|
+
channel: s.channel,
|
|
3591
|
+
isBreakup: isBreakupLabel(s.label)
|
|
2837
3592
|
}));
|
|
2838
3593
|
return {
|
|
2839
3594
|
name: p.name,
|
|
@@ -3004,6 +3759,10 @@ async function setup(req) {
|
|
|
3004
3759
|
sendingDomain: mergeString(body.sendingDomain, current.sendingDomain),
|
|
3005
3760
|
icpOneLiner: mergeString(body.icpOneLiner, current.icpOneLiner),
|
|
3006
3761
|
cadenceOverrides: current.cadenceOverrides,
|
|
3762
|
+
founderCredentials: mergeString(body.founderCredentials, current.founderCredentials),
|
|
3763
|
+
productPortfolio: mergeString(body.productPortfolio, current.productPortfolio),
|
|
3764
|
+
partners: mergeString(body.partners, current.partners),
|
|
3765
|
+
mobileSignature: body.mobileSignature ?? current.mobileSignature,
|
|
3007
3766
|
clientId: current.clientId
|
|
3008
3767
|
});
|
|
3009
3768
|
if (body.secrets && Object.keys(body.secrets).length > 0) saveSecrets(body.secrets);
|
|
@@ -3022,7 +3781,7 @@ function mergeString(incoming, current) {
|
|
|
3022
3781
|
}
|
|
3023
3782
|
//#endregion
|
|
3024
3783
|
//#region src/api/derive-icp.ts
|
|
3025
|
-
const PLAY_NAME$
|
|
3784
|
+
const PLAY_NAME$11 = "config:icp";
|
|
3026
3785
|
async function deriveIcpRoute(req) {
|
|
3027
3786
|
startRun();
|
|
3028
3787
|
let body = {};
|
|
@@ -3041,7 +3800,7 @@ async function deriveIcpRoute(req) {
|
|
|
3041
3800
|
const readStartedAt = Date.now();
|
|
3042
3801
|
logEvent("derive_icp.read.start", { host });
|
|
3043
3802
|
try {
|
|
3044
|
-
const read = await webRead({ url }, { playName: PLAY_NAME$
|
|
3803
|
+
const read = await webRead({ url }, { playName: PLAY_NAME$11 });
|
|
3045
3804
|
markdown = (read.result.markdown ?? "").trim();
|
|
3046
3805
|
const c = read.result.cost;
|
|
3047
3806
|
if (typeof c === "number") costUsd += c;
|
|
@@ -3389,7 +4148,7 @@ function shouldSkipFindEmail(input) {
|
|
|
3389
4148
|
* the founder sees these signals in /queue review and the prospect row carries
|
|
3390
4149
|
* them after drain.
|
|
3391
4150
|
*/
|
|
3392
|
-
const PLAY_NAME$
|
|
4151
|
+
const PLAY_NAME$10 = "linkedin-lookup";
|
|
3393
4152
|
/** Match `linkedin.com/in/<slug>` profile URLs. The slug class is permissive
|
|
3394
4153
|
* enough to cover URL-encoded unicode slugs (e.g. `%E7%8E%8B`) which LinkedIn
|
|
3395
4154
|
* does serve for non-Latin display names. */
|
|
@@ -3436,7 +4195,7 @@ async function findLinkedInUrl(args) {
|
|
|
3436
4195
|
const search = await webSearch({
|
|
3437
4196
|
query,
|
|
3438
4197
|
maxResults: 5
|
|
3439
|
-
}, { playName: PLAY_NAME$
|
|
4198
|
+
}, { playName: PLAY_NAME$10 });
|
|
3440
4199
|
args.accumCost(search.result.cost ?? 0);
|
|
3441
4200
|
for (const r of search.result.results ?? []) {
|
|
3442
4201
|
const url = typeof r.url === "string" ? r.url : "";
|
|
@@ -3536,7 +4295,7 @@ async function enrichVerifiedContact(email, opts) {
|
|
|
3536
4295
|
//#endregion
|
|
3537
4296
|
//#region ../../packages/find/src/show-hn.ts
|
|
3538
4297
|
const HN_ALGOLIA = "https://hn.algolia.com/api/v1/search_by_date";
|
|
3539
|
-
const PLAY_NAME$
|
|
4298
|
+
const PLAY_NAME$9 = "show-hn";
|
|
3540
4299
|
const SOURCE$6 = "find:show-hn";
|
|
3541
4300
|
/**
|
|
3542
4301
|
* Pulls Show HN posts from HN Algolia, ICP-filters them, enriches founder
|
|
@@ -3559,7 +4318,7 @@ async function runShowHnFinder(opts) {
|
|
|
3559
4318
|
costUsd: 0
|
|
3560
4319
|
};
|
|
3561
4320
|
logEvent("finder.start", {
|
|
3562
|
-
name: PLAY_NAME$
|
|
4321
|
+
name: PLAY_NAME$9,
|
|
3563
4322
|
since_days: sinceDays,
|
|
3564
4323
|
limit
|
|
3565
4324
|
});
|
|
@@ -3569,22 +4328,29 @@ async function runShowHnFinder(opts) {
|
|
|
3569
4328
|
const data = await res.json();
|
|
3570
4329
|
result.candidates = data.hits.length;
|
|
3571
4330
|
logEvent("finder.fetched", {
|
|
3572
|
-
name: PLAY_NAME$
|
|
4331
|
+
name: PLAY_NAME$9,
|
|
3573
4332
|
candidates: result.candidates
|
|
3574
4333
|
});
|
|
3575
|
-
|
|
3576
|
-
|
|
4334
|
+
const concurrency = opts.concurrency ?? 3;
|
|
4335
|
+
let halted = false;
|
|
4336
|
+
await parallelMap(data.hits, concurrency, async (hit) => {
|
|
4337
|
+
if (halted) return;
|
|
4338
|
+
if (result.enqueued >= limit) {
|
|
4339
|
+
halted = true;
|
|
4340
|
+
return;
|
|
4341
|
+
}
|
|
3577
4342
|
if (opts.maxCostUsd != null && result.costUsd >= opts.maxCostUsd) {
|
|
3578
4343
|
result.halted = `max-cost cap (${opts.maxCostUsd})`;
|
|
3579
|
-
|
|
4344
|
+
halted = true;
|
|
4345
|
+
return;
|
|
3580
4346
|
}
|
|
3581
4347
|
if (hit.points < minPoints) {
|
|
3582
4348
|
result.droppedLowSignal = (result.droppedLowSignal ?? 0) + 1;
|
|
3583
|
-
|
|
4349
|
+
return;
|
|
3584
4350
|
}
|
|
3585
|
-
if (ledger.isQueueDuplicate(PLAY_NAME$
|
|
4351
|
+
if (ledger.isQueueDuplicate(PLAY_NAME$9, hit.objectID)) {
|
|
3586
4352
|
result.droppedDuplicate++;
|
|
3587
|
-
|
|
4353
|
+
return;
|
|
3588
4354
|
}
|
|
3589
4355
|
const filter = await icpFilter({
|
|
3590
4356
|
icp,
|
|
@@ -3598,7 +4364,7 @@ async function runShowHnFinder(opts) {
|
|
|
3598
4364
|
if (!filter.match) {
|
|
3599
4365
|
result.droppedIcp++;
|
|
3600
4366
|
if (!opts.dryRun) ledger.enqueueTarget({
|
|
3601
|
-
playName: PLAY_NAME$
|
|
4367
|
+
playName: PLAY_NAME$9,
|
|
3602
4368
|
payload: {
|
|
3603
4369
|
postTitle: hit.title,
|
|
3604
4370
|
postUrl: hit.url,
|
|
@@ -3609,16 +4375,16 @@ async function runShowHnFinder(opts) {
|
|
|
3609
4375
|
initialStatus: "rejected",
|
|
3610
4376
|
notes: `auto: ICP — ${filter.reason}`
|
|
3611
4377
|
});
|
|
3612
|
-
|
|
4378
|
+
return;
|
|
3613
4379
|
}
|
|
3614
4380
|
if (opts.dryRun) {
|
|
3615
4381
|
result.enqueued++;
|
|
3616
|
-
|
|
4382
|
+
return;
|
|
3617
4383
|
}
|
|
3618
4384
|
const domain = urlDomain(hit.url);
|
|
3619
4385
|
if (!domain) {
|
|
3620
4386
|
result.droppedEnrichment++;
|
|
3621
|
-
|
|
4387
|
+
return;
|
|
3622
4388
|
}
|
|
3623
4389
|
const fullName = hit.author && hit.author.length > 0 ? hit.author : void 0;
|
|
3624
4390
|
const skip = shouldSkipFindEmail({
|
|
@@ -3628,37 +4394,37 @@ async function runShowHnFinder(opts) {
|
|
|
3628
4394
|
if (!skip.ok) {
|
|
3629
4395
|
result.droppedEnrichment++;
|
|
3630
4396
|
logEvent("finder.skipped_findemail", {
|
|
3631
|
-
name: PLAY_NAME$
|
|
4397
|
+
name: PLAY_NAME$9,
|
|
3632
4398
|
reason: skip.reason
|
|
3633
4399
|
}, "info");
|
|
3634
|
-
|
|
4400
|
+
return;
|
|
3635
4401
|
}
|
|
3636
4402
|
const findInput = { companyDomain: domain };
|
|
3637
4403
|
if (fullName) findInput.fullName = fullName;
|
|
3638
|
-
const found = await findEmail(findInput, { playName: PLAY_NAME$
|
|
4404
|
+
const found = await findEmail(findInput, { playName: PLAY_NAME$9 });
|
|
3639
4405
|
result.costUsd += found.result.cost ?? 0;
|
|
3640
4406
|
if (!found.result.found || !found.result.email) {
|
|
3641
4407
|
result.droppedEnrichment++;
|
|
3642
|
-
|
|
4408
|
+
return;
|
|
3643
4409
|
}
|
|
3644
4410
|
const email = found.result.email;
|
|
3645
|
-
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$
|
|
4411
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$9 });
|
|
3646
4412
|
result.costUsd += verified.result.cost ?? 0;
|
|
3647
4413
|
if (!verified.result.deliverable) {
|
|
3648
4414
|
result.droppedEnrichment++;
|
|
3649
|
-
|
|
4415
|
+
return;
|
|
3650
4416
|
}
|
|
3651
4417
|
if (isDuplicate({
|
|
3652
|
-
playName: PLAY_NAME$
|
|
4418
|
+
playName: PLAY_NAME$9,
|
|
3653
4419
|
dedupeKey: hit.objectID,
|
|
3654
4420
|
prospectEmail: email
|
|
3655
4421
|
})) {
|
|
3656
4422
|
result.droppedDuplicate++;
|
|
3657
|
-
|
|
4423
|
+
return;
|
|
3658
4424
|
}
|
|
3659
4425
|
let hookSummary = (hit.story_text ?? "").trim().slice(0, 280);
|
|
3660
4426
|
if (hookSummary.length < 40 && hit.url) try {
|
|
3661
|
-
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$
|
|
4427
|
+
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$9 });
|
|
3662
4428
|
result.costUsd += read.result.cost ?? 0;
|
|
3663
4429
|
hookSummary = (read.result.markdown ?? "").trim().slice(0, 280);
|
|
3664
4430
|
} catch (err) {
|
|
@@ -3670,7 +4436,7 @@ async function runShowHnFinder(opts) {
|
|
|
3670
4436
|
if (!hookSummary || hookSummary.length < 20) hookSummary = `Show HN post: ${hit.title}. ${hit.points} points.`;
|
|
3671
4437
|
const founderName = found.result.full_name ?? hit.author;
|
|
3672
4438
|
const enr = await enrichVerifiedContact(email, {
|
|
3673
|
-
playName: PLAY_NAME$
|
|
4439
|
+
playName: PLAY_NAME$9,
|
|
3674
4440
|
errKindPrefix: "show-hn"
|
|
3675
4441
|
});
|
|
3676
4442
|
result.costUsd += enr.costUsd;
|
|
@@ -3694,16 +4460,16 @@ async function runShowHnFinder(opts) {
|
|
|
3694
4460
|
...phone ? { phone } : {}
|
|
3695
4461
|
};
|
|
3696
4462
|
if (ledger.enqueueTarget({
|
|
3697
|
-
playName: PLAY_NAME$
|
|
4463
|
+
playName: PLAY_NAME$9,
|
|
3698
4464
|
payload: target,
|
|
3699
4465
|
dedupeKey: hit.objectID,
|
|
3700
4466
|
source: SOURCE$6,
|
|
3701
4467
|
notes: filter.reason
|
|
3702
4468
|
}) != null) result.enqueued++;
|
|
3703
4469
|
else result.droppedDuplicate++;
|
|
3704
|
-
}
|
|
4470
|
+
});
|
|
3705
4471
|
logEvent("finder.done", {
|
|
3706
|
-
name: PLAY_NAME$
|
|
4472
|
+
name: PLAY_NAME$9,
|
|
3707
4473
|
candidates: result.candidates,
|
|
3708
4474
|
enqueued: result.enqueued,
|
|
3709
4475
|
dropped_icp: result.droppedIcp,
|
|
@@ -3717,7 +4483,7 @@ async function runShowHnFinder(opts) {
|
|
|
3717
4483
|
}
|
|
3718
4484
|
//#endregion
|
|
3719
4485
|
//#region ../../packages/find/src/post-funding.ts
|
|
3720
|
-
const PLAY_NAME$
|
|
4486
|
+
const PLAY_NAME$8 = "post-funding";
|
|
3721
4487
|
const SOURCE$5 = "find:post-funding";
|
|
3722
4488
|
const ROUND_MAP = {
|
|
3723
4489
|
"Pre-Seed": "Pre-Seed",
|
|
@@ -3758,7 +4524,7 @@ async function runPostFundingFinder(opts) {
|
|
|
3758
4524
|
result.halted = `max-cost cap (${opts.maxCostUsd})`;
|
|
3759
4525
|
break;
|
|
3760
4526
|
}
|
|
3761
|
-
if (ledger.isQueueDuplicate(PLAY_NAME$
|
|
4527
|
+
if (ledger.isQueueDuplicate(PLAY_NAME$8, url)) {
|
|
3762
4528
|
result.droppedDuplicate++;
|
|
3763
4529
|
continue;
|
|
3764
4530
|
}
|
|
@@ -3768,7 +4534,7 @@ async function runPostFundingFinder(opts) {
|
|
|
3768
4534
|
}
|
|
3769
4535
|
let extract;
|
|
3770
4536
|
try {
|
|
3771
|
-
const read = await webRead({ url }, { playName: PLAY_NAME$
|
|
4537
|
+
const read = await webRead({ url }, { playName: PLAY_NAME$8 });
|
|
3772
4538
|
result.costUsd += read.result.cost ?? 0;
|
|
3773
4539
|
extract = parsePostFundingExtract((await complete({
|
|
3774
4540
|
messages: [{
|
|
@@ -3804,7 +4570,7 @@ async function runPostFundingFinder(opts) {
|
|
|
3804
4570
|
if (!filter.match) {
|
|
3805
4571
|
result.droppedIcp++;
|
|
3806
4572
|
ledger.enqueueTarget({
|
|
3807
|
-
playName: PLAY_NAME$
|
|
4573
|
+
playName: PLAY_NAME$8,
|
|
3808
4574
|
payload: {
|
|
3809
4575
|
company: extract.company,
|
|
3810
4576
|
round: extract.round,
|
|
@@ -3826,7 +4592,7 @@ async function runPostFundingFinder(opts) {
|
|
|
3826
4592
|
if (!skip.ok) {
|
|
3827
4593
|
result.droppedEnrichment++;
|
|
3828
4594
|
logEvent("finder.skipped_findemail", {
|
|
3829
|
-
name: PLAY_NAME$
|
|
4595
|
+
name: PLAY_NAME$8,
|
|
3830
4596
|
reason: skip.reason
|
|
3831
4597
|
}, "info");
|
|
3832
4598
|
continue;
|
|
@@ -3834,7 +4600,7 @@ async function runPostFundingFinder(opts) {
|
|
|
3834
4600
|
const found = await findEmail({
|
|
3835
4601
|
fullName: extract.founderName,
|
|
3836
4602
|
companyDomain: extract.companyDomain
|
|
3837
|
-
}, { playName: PLAY_NAME$
|
|
4603
|
+
}, { playName: PLAY_NAME$8 });
|
|
3838
4604
|
result.costUsd += found.result.cost ?? 0;
|
|
3839
4605
|
if (!found.result.found || !found.result.email) {
|
|
3840
4606
|
result.droppedEnrichment++;
|
|
@@ -3842,21 +4608,21 @@ async function runPostFundingFinder(opts) {
|
|
|
3842
4608
|
}
|
|
3843
4609
|
const email = found.result.email;
|
|
3844
4610
|
if (isDuplicate({
|
|
3845
|
-
playName: PLAY_NAME$
|
|
4611
|
+
playName: PLAY_NAME$8,
|
|
3846
4612
|
dedupeKey: url,
|
|
3847
4613
|
prospectEmail: email
|
|
3848
4614
|
})) {
|
|
3849
4615
|
result.droppedDuplicate++;
|
|
3850
4616
|
continue;
|
|
3851
4617
|
}
|
|
3852
|
-
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$
|
|
4618
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$8 });
|
|
3853
4619
|
result.costUsd += verified.result.cost ?? 0;
|
|
3854
4620
|
if (!verified.result.deliverable) {
|
|
3855
4621
|
result.droppedEnrichment++;
|
|
3856
4622
|
continue;
|
|
3857
4623
|
}
|
|
3858
4624
|
const enr = await enrichVerifiedContact(email, {
|
|
3859
|
-
playName: PLAY_NAME$
|
|
4625
|
+
playName: PLAY_NAME$8,
|
|
3860
4626
|
errKindPrefix: "post-funding"
|
|
3861
4627
|
});
|
|
3862
4628
|
result.costUsd += enr.costUsd;
|
|
@@ -3883,7 +4649,7 @@ async function runPostFundingFinder(opts) {
|
|
|
3883
4649
|
...phone ? { phone } : {}
|
|
3884
4650
|
};
|
|
3885
4651
|
if (ledger.enqueueTarget({
|
|
3886
|
-
playName: PLAY_NAME$
|
|
4652
|
+
playName: PLAY_NAME$8,
|
|
3887
4653
|
payload: target,
|
|
3888
4654
|
dedupeKey: url,
|
|
3889
4655
|
source: SOURCE$5,
|
|
@@ -3959,7 +4725,7 @@ async function harvestAutoUrls(args) {
|
|
|
3959
4725
|
const search = await webSearch({
|
|
3960
4726
|
query,
|
|
3961
4727
|
maxResults: Math.min(20, Math.max(5, args.limit - urls.length))
|
|
3962
|
-
}, { playName: PLAY_NAME$
|
|
4728
|
+
}, { playName: PLAY_NAME$8 });
|
|
3963
4729
|
costUsd += search.result.cost ?? 0;
|
|
3964
4730
|
for (const hit of search.result.results ?? []) {
|
|
3965
4731
|
if (urls.length >= args.limit) break;
|
|
@@ -4072,7 +4838,7 @@ function deriveIndustryHint(icp) {
|
|
|
4072
4838
|
* Less reliable than the yc-oss adapter (search recall depends on the
|
|
4073
4839
|
* accelerator's web presence) but works without per-accelerator scrapers.
|
|
4074
4840
|
*/
|
|
4075
|
-
const PLAY_NAME$
|
|
4841
|
+
const PLAY_NAME$7 = "accelerator-batch";
|
|
4076
4842
|
/**
|
|
4077
4843
|
* Build the three search queries from a human-readable cohort label.
|
|
4078
4844
|
* Founders supply `cohortLabel: "YC W26"` or `"Techstars Toronto Spring 2025"`
|
|
@@ -4141,7 +4907,7 @@ async function fetchAcceleratorSearch(_cohort, cohortLabel, limit) {
|
|
|
4141
4907
|
const search = await webSearch({
|
|
4142
4908
|
query,
|
|
4143
4909
|
maxResults: Math.min(15, limit)
|
|
4144
|
-
}, { playName: PLAY_NAME$
|
|
4910
|
+
}, { playName: PLAY_NAME$7 });
|
|
4145
4911
|
costUsd += search.result.cost ?? 0;
|
|
4146
4912
|
for (const raw of search.result.results ?? []) {
|
|
4147
4913
|
if (!raw.url || seen.has(raw.url)) continue;
|
|
@@ -4170,7 +4936,7 @@ async function fetchAcceleratorSearch(_cohort, cohortLabel, limit) {
|
|
|
4170
4936
|
for (const hit of hits.slice(0, limit)) {
|
|
4171
4937
|
let extract = null;
|
|
4172
4938
|
try {
|
|
4173
|
-
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$
|
|
4939
|
+
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$7 });
|
|
4174
4940
|
costUsd += read.result.cost ?? 0;
|
|
4175
4941
|
extract = parseAcceleratorLaunchExtract((await complete({
|
|
4176
4942
|
messages: [{
|
|
@@ -4256,32 +5022,6 @@ function parseAcceleratorLaunchExtract(raw) {
|
|
|
4256
5022
|
});
|
|
4257
5023
|
}
|
|
4258
5024
|
//#endregion
|
|
4259
|
-
//#region ../../packages/find/src/_parallel.ts
|
|
4260
|
-
/**
|
|
4261
|
-
* Run `fn` over `items` with at most `concurrency` Promises in flight at once.
|
|
4262
|
-
* Preserves input order in the result array. Errors propagate via Promise.all
|
|
4263
|
-
* — caller is expected to catch per-item internally if partial success matters.
|
|
4264
|
-
*
|
|
4265
|
-
* Worker-pool implementation: spawn `concurrency` workers that pull from a
|
|
4266
|
-
* shared cursor. Cheaper than a chunked Promise.all (which stalls on the
|
|
4267
|
-
* slowest item per chunk) and avoids the dependency surface of p-limit.
|
|
4268
|
-
*/
|
|
4269
|
-
async function parallelMap(items, concurrency, fn) {
|
|
4270
|
-
const out = Array.from({ length: items.length });
|
|
4271
|
-
if (items.length === 0) return out;
|
|
4272
|
-
const workers = Math.max(1, Math.min(concurrency, items.length));
|
|
4273
|
-
let cursor = 0;
|
|
4274
|
-
async function worker() {
|
|
4275
|
-
while (true) {
|
|
4276
|
-
const i = cursor++;
|
|
4277
|
-
if (i >= items.length) return;
|
|
4278
|
-
out[i] = await fn(items[i], i);
|
|
4279
|
-
}
|
|
4280
|
-
}
|
|
4281
|
-
await Promise.all(Array.from({ length: workers }, () => worker()));
|
|
4282
|
-
return out;
|
|
4283
|
-
}
|
|
4284
|
-
//#endregion
|
|
4285
5025
|
//#region ../../packages/find/src/_yc-oss-adapter.ts
|
|
4286
5026
|
/**
|
|
4287
5027
|
* Adapter for the [yc-oss/api](https://github.com/yc-oss/api) public dataset.
|
|
@@ -4468,7 +5208,7 @@ function mapYcOssCompany(c) {
|
|
|
4468
5208
|
* verifyEmail → enqueue, all under `parallelMap` (concurrency 3, mirrors
|
|
4469
5209
|
* github-topics).
|
|
4470
5210
|
*/
|
|
4471
|
-
const PLAY_NAME$
|
|
5211
|
+
const PLAY_NAME$6 = "accelerator-batch";
|
|
4472
5212
|
/**
|
|
4473
5213
|
* Normalize the legacy single-cohort opts shape into the new multi-cohort
|
|
4474
5214
|
* list. Old trigger rows with `{cohort, cohortLabel}` keep working — they
|
|
@@ -4650,7 +5390,7 @@ async function runAcceleratorBatchFinder(opts) {
|
|
|
4650
5390
|
return;
|
|
4651
5391
|
}
|
|
4652
5392
|
const dedupeKey = makeDedupeKey(record, record.cohort);
|
|
4653
|
-
if (ledger.isQueueDuplicate(PLAY_NAME$
|
|
5393
|
+
if (ledger.isQueueDuplicate(PLAY_NAME$6, dedupeKey)) {
|
|
4654
5394
|
result.droppedDuplicate++;
|
|
4655
5395
|
return;
|
|
4656
5396
|
}
|
|
@@ -4669,7 +5409,7 @@ async function runAcceleratorBatchFinder(opts) {
|
|
|
4669
5409
|
if (!filter.match) {
|
|
4670
5410
|
result.droppedIcp++;
|
|
4671
5411
|
ledger.enqueueTarget({
|
|
4672
|
-
playName: PLAY_NAME$
|
|
5412
|
+
playName: PLAY_NAME$6,
|
|
4673
5413
|
payload: rejectionPayload(record, record.cohort),
|
|
4674
5414
|
dedupeKey,
|
|
4675
5415
|
source,
|
|
@@ -4704,7 +5444,7 @@ async function runAcceleratorBatchFinder(opts) {
|
|
|
4704
5444
|
if (!skip.ok) {
|
|
4705
5445
|
result.droppedEnrichment++;
|
|
4706
5446
|
logEvent("finder.skipped_findemail", {
|
|
4707
|
-
name: PLAY_NAME$
|
|
5447
|
+
name: PLAY_NAME$6,
|
|
4708
5448
|
reason: skip.reason
|
|
4709
5449
|
}, "info");
|
|
4710
5450
|
return;
|
|
@@ -4712,7 +5452,7 @@ async function runAcceleratorBatchFinder(opts) {
|
|
|
4712
5452
|
const found = await findEmail({
|
|
4713
5453
|
fullName: founderName,
|
|
4714
5454
|
companyDomain: domain
|
|
4715
|
-
}, { playName: PLAY_NAME$
|
|
5455
|
+
}, { playName: PLAY_NAME$6 });
|
|
4716
5456
|
result.costUsd += found.result.cost ?? 0;
|
|
4717
5457
|
if (!found.result.found || !found.result.email) {
|
|
4718
5458
|
result.droppedEnrichment++;
|
|
@@ -4721,21 +5461,21 @@ async function runAcceleratorBatchFinder(opts) {
|
|
|
4721
5461
|
const email = found.result.email;
|
|
4722
5462
|
const fullName = found.result.full_name?.trim() || founderName;
|
|
4723
5463
|
if (isDuplicate({
|
|
4724
|
-
playName: PLAY_NAME$
|
|
5464
|
+
playName: PLAY_NAME$6,
|
|
4725
5465
|
dedupeKey,
|
|
4726
5466
|
prospectEmail: email
|
|
4727
5467
|
})) {
|
|
4728
5468
|
result.droppedDuplicate++;
|
|
4729
5469
|
return;
|
|
4730
5470
|
}
|
|
4731
|
-
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$
|
|
5471
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$6 });
|
|
4732
5472
|
result.costUsd += verified.result.cost ?? 0;
|
|
4733
5473
|
if (!verified.result.deliverable) {
|
|
4734
5474
|
result.droppedEnrichment++;
|
|
4735
5475
|
return;
|
|
4736
5476
|
}
|
|
4737
5477
|
const enr = await enrichVerifiedContact(email, {
|
|
4738
|
-
playName: PLAY_NAME$
|
|
5478
|
+
playName: PLAY_NAME$6,
|
|
4739
5479
|
errKindPrefix: "accelerator-batch"
|
|
4740
5480
|
});
|
|
4741
5481
|
result.costUsd += enr.costUsd;
|
|
@@ -4757,10 +5497,12 @@ async function runAcceleratorBatchFinder(opts) {
|
|
|
4757
5497
|
...record.ycUrl ? { launchUrl: record.ycUrl } : record.website ? { launchUrl: record.website } : {},
|
|
4758
5498
|
...record.oneLiner ? { productOneLiner: record.oneLiner } : {},
|
|
4759
5499
|
...linkedinUrl ? { linkedinUrl } : {},
|
|
4760
|
-
...phone ? { phone } : {}
|
|
5500
|
+
...phone ? { phone } : {},
|
|
5501
|
+
...opts.senderCohort ? { senderCohort: opts.senderCohort } : {},
|
|
5502
|
+
...opts.freeForCohortOffer ? { freeForCohortOffer: opts.freeForCohortOffer } : {}
|
|
4761
5503
|
};
|
|
4762
5504
|
if (ledger.enqueueTarget({
|
|
4763
|
-
playName: PLAY_NAME$
|
|
5505
|
+
playName: PLAY_NAME$6,
|
|
4764
5506
|
payload: target,
|
|
4765
5507
|
dedupeKey,
|
|
4766
5508
|
source,
|
|
@@ -4818,7 +5560,7 @@ async function resolveFounderName(record) {
|
|
|
4818
5560
|
};
|
|
4819
5561
|
let costUsd = 0;
|
|
4820
5562
|
try {
|
|
4821
|
-
const read = await webRead({ url }, { playName: PLAY_NAME$
|
|
5563
|
+
const read = await webRead({ url }, { playName: PLAY_NAME$6 });
|
|
4822
5564
|
costUsd += read.result.cost ?? 0;
|
|
4823
5565
|
const extract = parseAcceleratorLaunchExtract((await complete({
|
|
4824
5566
|
messages: [{
|
|
@@ -4858,7 +5600,7 @@ async function resolveFounderName(record) {
|
|
|
4858
5600
|
}
|
|
4859
5601
|
//#endregion
|
|
4860
5602
|
//#region ../../packages/find/src/job-change.ts
|
|
4861
|
-
const PLAY_NAME$
|
|
5603
|
+
const PLAY_NAME$5 = "job-change";
|
|
4862
5604
|
const SOURCE$4 = "find:job-change";
|
|
4863
5605
|
const DEFAULT_PERSONAS = [
|
|
4864
5606
|
"VP Engineering",
|
|
@@ -4892,7 +5634,7 @@ async function runJobChangeFinder(opts) {
|
|
|
4892
5634
|
const search = await webSearch({
|
|
4893
5635
|
query,
|
|
4894
5636
|
maxResults: Math.min(15, limit)
|
|
4895
|
-
}, { playName: PLAY_NAME$
|
|
5637
|
+
}, { playName: PLAY_NAME$5 });
|
|
4896
5638
|
result.costUsd += search.result.cost ?? 0;
|
|
4897
5639
|
for (const hit of search.result.results ?? []) {
|
|
4898
5640
|
if (!hit.url || seenUrls.has(hit.url)) continue;
|
|
@@ -4918,7 +5660,7 @@ async function runJobChangeFinder(opts) {
|
|
|
4918
5660
|
result.halted = `max-cost cap (${opts.maxCostUsd})`;
|
|
4919
5661
|
break;
|
|
4920
5662
|
}
|
|
4921
|
-
if (ledger.isQueueDuplicate(PLAY_NAME$
|
|
5663
|
+
if (ledger.isQueueDuplicate(PLAY_NAME$5, hit.url)) {
|
|
4922
5664
|
result.droppedDuplicate++;
|
|
4923
5665
|
continue;
|
|
4924
5666
|
}
|
|
@@ -4937,7 +5679,7 @@ async function runJobChangeFinder(opts) {
|
|
|
4937
5679
|
if (!filter.match) {
|
|
4938
5680
|
result.droppedIcp++;
|
|
4939
5681
|
ledger.enqueueTarget({
|
|
4940
|
-
playName: PLAY_NAME$
|
|
5682
|
+
playName: PLAY_NAME$5,
|
|
4941
5683
|
payload: {
|
|
4942
5684
|
title: hit.title,
|
|
4943
5685
|
url: hit.url,
|
|
@@ -4991,7 +5733,7 @@ async function runJobChangeFinder(opts) {
|
|
|
4991
5733
|
if (!skip.ok) {
|
|
4992
5734
|
result.droppedEnrichment++;
|
|
4993
5735
|
logEvent("finder.skipped_findemail", {
|
|
4994
|
-
name: PLAY_NAME$
|
|
5736
|
+
name: PLAY_NAME$5,
|
|
4995
5737
|
reason: skip.reason
|
|
4996
5738
|
}, "info");
|
|
4997
5739
|
continue;
|
|
@@ -4999,7 +5741,7 @@ async function runJobChangeFinder(opts) {
|
|
|
4999
5741
|
const found = await findEmail({
|
|
5000
5742
|
fullName: extract.fullName,
|
|
5001
5743
|
companyDomain: domain
|
|
5002
|
-
}, { playName: PLAY_NAME$
|
|
5744
|
+
}, { playName: PLAY_NAME$5 });
|
|
5003
5745
|
result.costUsd += found.result.cost ?? 0;
|
|
5004
5746
|
if (!found.result.found || !found.result.email) {
|
|
5005
5747
|
result.droppedEnrichment++;
|
|
@@ -5007,21 +5749,21 @@ async function runJobChangeFinder(opts) {
|
|
|
5007
5749
|
}
|
|
5008
5750
|
const email = found.result.email;
|
|
5009
5751
|
if (isDuplicate({
|
|
5010
|
-
playName: PLAY_NAME$
|
|
5752
|
+
playName: PLAY_NAME$5,
|
|
5011
5753
|
dedupeKey: hit.url,
|
|
5012
5754
|
prospectEmail: email
|
|
5013
5755
|
})) {
|
|
5014
5756
|
result.droppedDuplicate++;
|
|
5015
5757
|
continue;
|
|
5016
5758
|
}
|
|
5017
|
-
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$
|
|
5759
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$5 });
|
|
5018
5760
|
result.costUsd += verified.result.cost ?? 0;
|
|
5019
5761
|
if (!verified.result.deliverable) {
|
|
5020
5762
|
result.droppedEnrichment++;
|
|
5021
5763
|
continue;
|
|
5022
5764
|
}
|
|
5023
5765
|
const enr = await enrichVerifiedContact(email, {
|
|
5024
|
-
playName: PLAY_NAME$
|
|
5766
|
+
playName: PLAY_NAME$5,
|
|
5025
5767
|
errKindPrefix: "job-change"
|
|
5026
5768
|
});
|
|
5027
5769
|
result.costUsd += enr.costUsd;
|
|
@@ -5047,7 +5789,7 @@ async function runJobChangeFinder(opts) {
|
|
|
5047
5789
|
...phone ? { phone } : {}
|
|
5048
5790
|
};
|
|
5049
5791
|
if (ledger.enqueueTarget({
|
|
5050
|
-
playName: PLAY_NAME$
|
|
5792
|
+
playName: PLAY_NAME$5,
|
|
5051
5793
|
payload: target,
|
|
5052
5794
|
dedupeKey: hit.url,
|
|
5053
5795
|
source: SOURCE$4,
|
|
@@ -5072,7 +5814,7 @@ function parseJobChangeExtract(raw) {
|
|
|
5072
5814
|
}
|
|
5073
5815
|
//#endregion
|
|
5074
5816
|
//#region ../../packages/find/src/hiring-signal.ts
|
|
5075
|
-
const PLAY_NAME$
|
|
5817
|
+
const PLAY_NAME$4 = "hiring-signal";
|
|
5076
5818
|
const SOURCE$3 = "find:hiring-signal";
|
|
5077
5819
|
const ATS_DOMAIN_HINTS = [
|
|
5078
5820
|
"boards.greenhouse.io",
|
|
@@ -5086,7 +5828,6 @@ const DEFAULT_ROLES = [
|
|
|
5086
5828
|
"ML Engineer",
|
|
5087
5829
|
"Solutions Engineer"
|
|
5088
5830
|
];
|
|
5089
|
-
const DEFAULT_CLAIM = "we cut new-hire ramp time by ~30% on the team they're hiring for — happy to share how";
|
|
5090
5831
|
async function runHiringSignalFinder(opts) {
|
|
5091
5832
|
const limit = opts.limit ?? 25;
|
|
5092
5833
|
const sinceDays = opts.sinceDays ?? 14;
|
|
@@ -5094,7 +5835,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5094
5835
|
const ledger = getLedger();
|
|
5095
5836
|
const system = loadPrompt("hiring-signal-extract");
|
|
5096
5837
|
const roles = opts.roles && opts.roles.length > 0 ? opts.roles : DEFAULT_ROLES;
|
|
5097
|
-
const yourClaim = opts.yourClaim ??
|
|
5838
|
+
const yourClaim = (opts.yourClaim ?? "").trim();
|
|
5098
5839
|
const result = {
|
|
5099
5840
|
source: SOURCE$3,
|
|
5100
5841
|
candidates: 0,
|
|
@@ -5104,6 +5845,10 @@ async function runHiringSignalFinder(opts) {
|
|
|
5104
5845
|
enqueued: 0,
|
|
5105
5846
|
costUsd: 0
|
|
5106
5847
|
};
|
|
5848
|
+
if (!yourClaim) {
|
|
5849
|
+
result.halted = "set `yourClaim` in the hiring-signal config";
|
|
5850
|
+
return result;
|
|
5851
|
+
}
|
|
5107
5852
|
const seen = /* @__PURE__ */ new Set();
|
|
5108
5853
|
const hits = [];
|
|
5109
5854
|
const sincePhrase = sinceDays <= 7 ? "this week" : `last ${sinceDays} days`;
|
|
@@ -5115,7 +5860,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5115
5860
|
const search = await webSearch({
|
|
5116
5861
|
query,
|
|
5117
5862
|
maxResults: Math.min(15, limit)
|
|
5118
|
-
}, { playName: PLAY_NAME$
|
|
5863
|
+
}, { playName: PLAY_NAME$4 });
|
|
5119
5864
|
result.costUsd += search.result.cost ?? 0;
|
|
5120
5865
|
for (const hit of search.result.results ?? []) {
|
|
5121
5866
|
if (!hit.url || seen.has(hit.url) || !isAtsUrl(hit.url)) continue;
|
|
@@ -5141,7 +5886,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5141
5886
|
result.halted = `max-cost cap (${opts.maxCostUsd})`;
|
|
5142
5887
|
break;
|
|
5143
5888
|
}
|
|
5144
|
-
if (ledger.isQueueDuplicate(PLAY_NAME$
|
|
5889
|
+
if (ledger.isQueueDuplicate(PLAY_NAME$4, hit.url)) {
|
|
5145
5890
|
result.droppedDuplicate++;
|
|
5146
5891
|
continue;
|
|
5147
5892
|
}
|
|
@@ -5160,7 +5905,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5160
5905
|
if (!filter.match) {
|
|
5161
5906
|
result.droppedIcp++;
|
|
5162
5907
|
ledger.enqueueTarget({
|
|
5163
|
-
playName: PLAY_NAME$
|
|
5908
|
+
playName: PLAY_NAME$4,
|
|
5164
5909
|
payload: {
|
|
5165
5910
|
title: hit.title,
|
|
5166
5911
|
url: hit.url,
|
|
@@ -5175,7 +5920,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5175
5920
|
}
|
|
5176
5921
|
let extract;
|
|
5177
5922
|
try {
|
|
5178
|
-
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$
|
|
5923
|
+
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$4 });
|
|
5179
5924
|
result.costUsd += read.result.cost ?? 0;
|
|
5180
5925
|
extract = parseHiringSignalExtract((await complete({
|
|
5181
5926
|
messages: [{
|
|
@@ -5221,7 +5966,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5221
5966
|
if (!skip.ok) {
|
|
5222
5967
|
result.droppedEnrichment++;
|
|
5223
5968
|
logEvent("finder.skipped_findemail", {
|
|
5224
|
-
name: PLAY_NAME$
|
|
5969
|
+
name: PLAY_NAME$4,
|
|
5225
5970
|
reason: skip.reason
|
|
5226
5971
|
}, "info");
|
|
5227
5972
|
continue;
|
|
@@ -5229,7 +5974,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5229
5974
|
const found = await findEmail(managerName ? {
|
|
5230
5975
|
fullName: managerName,
|
|
5231
5976
|
companyDomain: domain
|
|
5232
|
-
} : { companyDomain: domain }, { playName: PLAY_NAME$
|
|
5977
|
+
} : { companyDomain: domain }, { playName: PLAY_NAME$4 });
|
|
5233
5978
|
result.costUsd += found.result.cost ?? 0;
|
|
5234
5979
|
if (!found.result.found || !found.result.email) {
|
|
5235
5980
|
result.droppedEnrichment++;
|
|
@@ -5237,14 +5982,14 @@ async function runHiringSignalFinder(opts) {
|
|
|
5237
5982
|
}
|
|
5238
5983
|
const email = found.result.email;
|
|
5239
5984
|
if (isDuplicate({
|
|
5240
|
-
playName: PLAY_NAME$
|
|
5985
|
+
playName: PLAY_NAME$4,
|
|
5241
5986
|
dedupeKey: hit.url,
|
|
5242
5987
|
prospectEmail: email
|
|
5243
5988
|
})) {
|
|
5244
5989
|
result.droppedDuplicate++;
|
|
5245
5990
|
continue;
|
|
5246
5991
|
}
|
|
5247
|
-
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$
|
|
5992
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$4 });
|
|
5248
5993
|
result.costUsd += verified.result.cost ?? 0;
|
|
5249
5994
|
if (!verified.result.deliverable) {
|
|
5250
5995
|
result.droppedEnrichment++;
|
|
@@ -5252,7 +5997,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5252
5997
|
}
|
|
5253
5998
|
const recipientName = extract.hiringManagerName ?? found.result.full_name ?? null;
|
|
5254
5999
|
const enr = await enrichVerifiedContact(email, {
|
|
5255
|
-
playName: PLAY_NAME$
|
|
6000
|
+
playName: PLAY_NAME$4,
|
|
5256
6001
|
errKindPrefix: "hiring-signal"
|
|
5257
6002
|
});
|
|
5258
6003
|
result.costUsd += enr.costUsd;
|
|
@@ -5278,7 +6023,7 @@ async function runHiringSignalFinder(opts) {
|
|
|
5278
6023
|
...phone ? { phone } : {}
|
|
5279
6024
|
};
|
|
5280
6025
|
if (ledger.enqueueTarget({
|
|
5281
|
-
playName: PLAY_NAME$
|
|
6026
|
+
playName: PLAY_NAME$4,
|
|
5282
6027
|
payload: target,
|
|
5283
6028
|
dedupeKey: hit.url,
|
|
5284
6029
|
source: SOURCE$3,
|
|
@@ -5331,7 +6076,7 @@ async function resolveCorporateDomain(company, jobUrl, cache) {
|
|
|
5331
6076
|
const search = await webSearch({
|
|
5332
6077
|
query: `"${company}" official site`,
|
|
5333
6078
|
maxResults: 5
|
|
5334
|
-
}, { playName: PLAY_NAME$
|
|
6079
|
+
}, { playName: PLAY_NAME$4 });
|
|
5335
6080
|
costUsd += search.result.cost ?? 0;
|
|
5336
6081
|
for (const hit of search.result.results ?? []) {
|
|
5337
6082
|
const host = pickCorporateHost(hit.url);
|
|
@@ -5383,7 +6128,7 @@ function parseHiringSignalExtract(raw) {
|
|
|
5383
6128
|
}
|
|
5384
6129
|
//#endregion
|
|
5385
6130
|
//#region ../../packages/find/src/podcast-guest.ts
|
|
5386
|
-
const PLAY_NAME$
|
|
6131
|
+
const PLAY_NAME$3 = "podcast-guest";
|
|
5387
6132
|
const SOURCE$2 = "find:podcast-guest";
|
|
5388
6133
|
const DEFAULT_PODCASTS = [
|
|
5389
6134
|
"Latent Space",
|
|
@@ -5418,7 +6163,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5418
6163
|
const search = await webSearch({
|
|
5419
6164
|
query,
|
|
5420
6165
|
maxResults: Math.min(15, limit)
|
|
5421
|
-
}, { playName: PLAY_NAME$
|
|
6166
|
+
}, { playName: PLAY_NAME$3 });
|
|
5422
6167
|
result.costUsd += search.result.cost ?? 0;
|
|
5423
6168
|
for (const hit of search.result.results ?? []) {
|
|
5424
6169
|
if (!hit.url || seen.has(hit.url)) continue;
|
|
@@ -5444,7 +6189,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5444
6189
|
result.halted = `max-cost cap (${opts.maxCostUsd})`;
|
|
5445
6190
|
break;
|
|
5446
6191
|
}
|
|
5447
|
-
if (ledger.isQueueDuplicate(PLAY_NAME$
|
|
6192
|
+
if (ledger.isQueueDuplicate(PLAY_NAME$3, hit.url)) {
|
|
5448
6193
|
result.droppedDuplicate++;
|
|
5449
6194
|
continue;
|
|
5450
6195
|
}
|
|
@@ -5463,7 +6208,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5463
6208
|
if (!filter.match) {
|
|
5464
6209
|
result.droppedIcp++;
|
|
5465
6210
|
ledger.enqueueTarget({
|
|
5466
|
-
playName: PLAY_NAME$
|
|
6211
|
+
playName: PLAY_NAME$3,
|
|
5467
6212
|
payload: {
|
|
5468
6213
|
title: hit.title,
|
|
5469
6214
|
url: hit.url,
|
|
@@ -5484,7 +6229,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5484
6229
|
description: hit.description
|
|
5485
6230
|
};
|
|
5486
6231
|
if (!opts.skipRead) {
|
|
5487
|
-
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$
|
|
6232
|
+
const read = await webRead({ url: hit.url }, { playName: PLAY_NAME$3 });
|
|
5488
6233
|
result.costUsd += read.result.cost ?? 0;
|
|
5489
6234
|
payload = {
|
|
5490
6235
|
...payload,
|
|
@@ -5521,7 +6266,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5521
6266
|
if (!skip.ok) {
|
|
5522
6267
|
result.droppedEnrichment++;
|
|
5523
6268
|
logEvent("finder.skipped_findemail", {
|
|
5524
|
-
name: PLAY_NAME$
|
|
6269
|
+
name: PLAY_NAME$3,
|
|
5525
6270
|
reason: skip.reason
|
|
5526
6271
|
}, "info");
|
|
5527
6272
|
continue;
|
|
@@ -5529,7 +6274,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5529
6274
|
const found = await findEmail({
|
|
5530
6275
|
fullName: extract.guestName,
|
|
5531
6276
|
companyDomain: extract.guestCompanyDomain
|
|
5532
|
-
}, { playName: PLAY_NAME$
|
|
6277
|
+
}, { playName: PLAY_NAME$3 });
|
|
5533
6278
|
result.costUsd += found.result.cost ?? 0;
|
|
5534
6279
|
if (!found.result.found || !found.result.email) {
|
|
5535
6280
|
result.droppedEnrichment++;
|
|
@@ -5537,21 +6282,21 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5537
6282
|
}
|
|
5538
6283
|
const email = found.result.email;
|
|
5539
6284
|
if (isDuplicate({
|
|
5540
|
-
playName: PLAY_NAME$
|
|
6285
|
+
playName: PLAY_NAME$3,
|
|
5541
6286
|
dedupeKey: hit.url,
|
|
5542
6287
|
prospectEmail: email
|
|
5543
6288
|
})) {
|
|
5544
6289
|
result.droppedDuplicate++;
|
|
5545
6290
|
continue;
|
|
5546
6291
|
}
|
|
5547
|
-
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$
|
|
6292
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME$3 });
|
|
5548
6293
|
result.costUsd += verified.result.cost ?? 0;
|
|
5549
6294
|
if (!verified.result.deliverable) {
|
|
5550
6295
|
result.droppedEnrichment++;
|
|
5551
6296
|
continue;
|
|
5552
6297
|
}
|
|
5553
6298
|
const enr = await enrichVerifiedContact(email, {
|
|
5554
|
-
playName: PLAY_NAME$
|
|
6299
|
+
playName: PLAY_NAME$3,
|
|
5555
6300
|
errKindPrefix: "podcast-guest"
|
|
5556
6301
|
});
|
|
5557
6302
|
result.costUsd += enr.costUsd;
|
|
@@ -5577,7 +6322,7 @@ async function runPodcastGuestFinder(opts) {
|
|
|
5577
6322
|
...phone ? { phone } : {}
|
|
5578
6323
|
};
|
|
5579
6324
|
if (ledger.enqueueTarget({
|
|
5580
|
-
playName: PLAY_NAME$
|
|
6325
|
+
playName: PLAY_NAME$3,
|
|
5581
6326
|
payload: target,
|
|
5582
6327
|
dedupeKey: hit.url,
|
|
5583
6328
|
source: SOURCE$2,
|
|
@@ -5604,7 +6349,7 @@ function parsePodcastGuestExtract(raw) {
|
|
|
5604
6349
|
}
|
|
5605
6350
|
//#endregion
|
|
5606
6351
|
//#region ../../packages/find/src/breakup-revive.ts
|
|
5607
|
-
const PLAY_NAME$
|
|
6352
|
+
const PLAY_NAME$2 = "breakup-revive";
|
|
5608
6353
|
const SOURCE$1 = "find:breakup-revive";
|
|
5609
6354
|
/**
|
|
5610
6355
|
* Scan the local ledger for cold prospects (no activity in the last
|
|
@@ -5640,7 +6385,7 @@ function runBreakupReviveFinder(opts) {
|
|
|
5640
6385
|
}
|
|
5641
6386
|
const dedupeKey = `prospect:${p.id}`;
|
|
5642
6387
|
if (isDuplicate({
|
|
5643
|
-
playName: PLAY_NAME$
|
|
6388
|
+
playName: PLAY_NAME$2,
|
|
5644
6389
|
dedupeKey,
|
|
5645
6390
|
prospectEmail: void 0
|
|
5646
6391
|
})) {
|
|
@@ -5662,7 +6407,7 @@ function runBreakupReviveFinder(opts) {
|
|
|
5662
6407
|
continue;
|
|
5663
6408
|
}
|
|
5664
6409
|
const id = ledger.enqueueTarget({
|
|
5665
|
-
playName: PLAY_NAME$
|
|
6410
|
+
playName: PLAY_NAME$2,
|
|
5666
6411
|
payload: target,
|
|
5667
6412
|
dedupeKey,
|
|
5668
6413
|
source: SOURCE$1,
|
|
@@ -6098,7 +6843,7 @@ function parseEnvKeys(content) {
|
|
|
6098
6843
|
* directly from package.json / pyproject.toml / requirements.txt /
|
|
6099
6844
|
* .env.example via the GitHub Contents API. Free, fast, deterministic.
|
|
6100
6845
|
*/
|
|
6101
|
-
const PLAY_NAME = "stack-consolidation";
|
|
6846
|
+
const PLAY_NAME$1 = "stack-consolidation";
|
|
6102
6847
|
/**
|
|
6103
6848
|
* Process a single candidate through the full pipeline. Mutates ctx.result.
|
|
6104
6849
|
* Never throws — internal exceptions become droppedEnrichment increments via
|
|
@@ -6140,7 +6885,7 @@ async function processRepoCandidate(hit, ctx) {
|
|
|
6140
6885
|
if (!snippetFilter.match) {
|
|
6141
6886
|
result.droppedIcp++;
|
|
6142
6887
|
ledger.enqueueTarget({
|
|
6143
|
-
playName: PLAY_NAME,
|
|
6888
|
+
playName: PLAY_NAME$1,
|
|
6144
6889
|
payload: {
|
|
6145
6890
|
repoUrl: hit.url,
|
|
6146
6891
|
title: hit.title,
|
|
@@ -6288,7 +7033,7 @@ async function processRepoCandidate(hit, ctx) {
|
|
|
6288
7033
|
async function resolveContact(args) {
|
|
6289
7034
|
const { extract, repoUrl, ghUser, accumCost, useDeepResearch } = args;
|
|
6290
7035
|
const errKindPrefix = args.errKindPrefix ?? "repo-pipeline";
|
|
6291
|
-
const playName = args.playName ?? PLAY_NAME;
|
|
7036
|
+
const playName = args.playName ?? PLAY_NAME$1;
|
|
6292
7037
|
const extractDomain = extract.companyDomain ?? extract.personalDomain ?? null;
|
|
6293
7038
|
let discoveredLinkedinUrl = null;
|
|
6294
7039
|
if (extractDomain) {
|
|
@@ -6620,6 +7365,323 @@ async function runGitHubTopicsFinder(opts) {
|
|
|
6620
7365
|
return result;
|
|
6621
7366
|
}
|
|
6622
7367
|
//#endregion
|
|
7368
|
+
//#region ../../packages/find/src/_stargazers.ts
|
|
7369
|
+
/** Parse one `application/vnd.github.star+json` stargazer row. */
|
|
7370
|
+
function parseStarRow(raw) {
|
|
7371
|
+
if (!raw || typeof raw !== "object") return null;
|
|
7372
|
+
const r = raw;
|
|
7373
|
+
const starredAt = typeof r["starred_at"] === "string" ? r["starred_at"] : null;
|
|
7374
|
+
const user = r["user"];
|
|
7375
|
+
if (!starredAt || !user || typeof user !== "object") return null;
|
|
7376
|
+
const u = user;
|
|
7377
|
+
const login = typeof u["login"] === "string" ? u["login"] : null;
|
|
7378
|
+
if (!login) return null;
|
|
7379
|
+
return {
|
|
7380
|
+
login,
|
|
7381
|
+
userUrl: (typeof u["html_url"] === "string" ? u["html_url"] : null) ?? `https://github.com/${login}`,
|
|
7382
|
+
starredAt
|
|
7383
|
+
};
|
|
7384
|
+
}
|
|
7385
|
+
/** Read the `page=N>; rel="last"` page number from a GitHub `Link` header. */
|
|
7386
|
+
function parseLastPage(link) {
|
|
7387
|
+
if (!link) return 1;
|
|
7388
|
+
const m = link.match(/[?&]page=(\d+)>;\s*rel="last"/);
|
|
7389
|
+
return m ? Math.max(1, Number.parseInt(m[1] ?? "1", 10)) : 1;
|
|
7390
|
+
}
|
|
7391
|
+
/**
|
|
7392
|
+
* Recent stargazers of a public repo. GitHub returns stargazers oldest-first,
|
|
7393
|
+
* so the newest stars live on the LAST page — we read the `Link: rel="last"`
|
|
7394
|
+
* page number, then page backward (newest → older), collecting stars with
|
|
7395
|
+
* `starredAt >= sinceIso` and stopping as soon as a page has none fresh (every
|
|
7396
|
+
* earlier page is older still) or `maxPages` is hit. Fault-tolerant like
|
|
7397
|
+
* `searchTopicRepos`: returns `{ stargazers: [], error }` on any non-2xx /
|
|
7398
|
+
* network / parse failure so the caller logs + continues to the next repo.
|
|
7399
|
+
*
|
|
7400
|
+
* Requires `GITHUB_TOKEN` for any real volume (5,000 req/hr core); without it
|
|
7401
|
+
* GitHub rate-limits hard at 60/hr.
|
|
7402
|
+
*/
|
|
7403
|
+
async function recentStargazers(repo, opts) {
|
|
7404
|
+
const maxPages = Math.max(1, opts.maxPages ?? 20);
|
|
7405
|
+
const headers = {
|
|
7406
|
+
...githubHeaders(),
|
|
7407
|
+
Accept: "application/vnd.github.star+json"
|
|
7408
|
+
};
|
|
7409
|
+
const base = `https://api.github.com/repos/${repo}/stargazers?per_page=100`;
|
|
7410
|
+
try {
|
|
7411
|
+
const firstRes = await fetch(`${base}&page=1`, { headers });
|
|
7412
|
+
if (!firstRes.ok) {
|
|
7413
|
+
logEvent("github.stargazers", {
|
|
7414
|
+
repo,
|
|
7415
|
+
ok: false,
|
|
7416
|
+
status: firstRes.status
|
|
7417
|
+
}, "warn");
|
|
7418
|
+
return {
|
|
7419
|
+
stargazers: [],
|
|
7420
|
+
error: `status ${firstRes.status}`
|
|
7421
|
+
};
|
|
7422
|
+
}
|
|
7423
|
+
const lastPage = parseLastPage(firstRes.headers.get("link"));
|
|
7424
|
+
const page1Rows = await firstRes.json() ?? [];
|
|
7425
|
+
const out = [];
|
|
7426
|
+
let pagesFetched = 1;
|
|
7427
|
+
for (let page = lastPage; page >= 1 && pagesFetched <= maxPages; page--) {
|
|
7428
|
+
let rows;
|
|
7429
|
+
if (page === 1) rows = page1Rows;
|
|
7430
|
+
else {
|
|
7431
|
+
const res = await fetch(`${base}&page=${page}`, { headers });
|
|
7432
|
+
pagesFetched++;
|
|
7433
|
+
if (!res.ok) break;
|
|
7434
|
+
rows = await res.json() ?? [];
|
|
7435
|
+
}
|
|
7436
|
+
const parsed = rows.map(parseStarRow).filter((s) => s !== null && s.starredAt >= opts.sinceIso);
|
|
7437
|
+
out.push(...parsed);
|
|
7438
|
+
if (parsed.length === 0) break;
|
|
7439
|
+
}
|
|
7440
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7441
|
+
const stargazers = out.filter((s) => {
|
|
7442
|
+
const key = s.login.toLowerCase();
|
|
7443
|
+
if (seen.has(key)) return false;
|
|
7444
|
+
seen.add(key);
|
|
7445
|
+
return true;
|
|
7446
|
+
});
|
|
7447
|
+
logEvent("github.stargazers", {
|
|
7448
|
+
repo,
|
|
7449
|
+
ok: true,
|
|
7450
|
+
fresh: stargazers.length,
|
|
7451
|
+
last_page: lastPage,
|
|
7452
|
+
pages_fetched: pagesFetched
|
|
7453
|
+
});
|
|
7454
|
+
return { stargazers };
|
|
7455
|
+
} catch (err) {
|
|
7456
|
+
const message = (err.message ?? "").slice(0, 120);
|
|
7457
|
+
logEvent("github.stargazers", {
|
|
7458
|
+
repo,
|
|
7459
|
+
ok: false,
|
|
7460
|
+
message_120: message
|
|
7461
|
+
}, "warn");
|
|
7462
|
+
return {
|
|
7463
|
+
stargazers: [],
|
|
7464
|
+
error: message
|
|
7465
|
+
};
|
|
7466
|
+
}
|
|
7467
|
+
}
|
|
7468
|
+
//#endregion
|
|
7469
|
+
//#region ../../packages/find/src/github-stars.ts
|
|
7470
|
+
const PLAY_NAME = "github-stars";
|
|
7471
|
+
function deriveLabel(repo) {
|
|
7472
|
+
return repo.split("/")[1]?.trim() || repo;
|
|
7473
|
+
}
|
|
7474
|
+
function sourceFor(repo) {
|
|
7475
|
+
return `find:${PLAY_NAME}:${repo}`;
|
|
7476
|
+
}
|
|
7477
|
+
/**
|
|
7478
|
+
* github-stars finder: recent stargazers of watched repos → prospects, routed
|
|
7479
|
+
* by each repo's founder-tagged `rel`. A `competitor` repo's stargazers become
|
|
7480
|
+
* `competitor-switch` rows ("why teams switch from X"); an `adjacent` repo's
|
|
7481
|
+
* become `repo-interest` rows ("you're into X — my product helps"). Reuses the
|
|
7482
|
+
* shared finder stack (ICP filter, findEmail/verify/enrich, dedupe, prescreen)
|
|
7483
|
+
* and the soft-cap loop pattern from show-hn / accelerator-batch.
|
|
7484
|
+
*/
|
|
7485
|
+
async function runGitHubStarsFinder(opts) {
|
|
7486
|
+
const limit = opts.limit ?? 25;
|
|
7487
|
+
const concurrency = Math.max(1, opts.concurrency ?? 3);
|
|
7488
|
+
const sinceDays = opts.sinceDays ?? 30;
|
|
7489
|
+
const sinceIso = (/* @__PURE__ */ new Date(Date.now() - sinceDays * 24 * 3600 * 1e3)).toISOString();
|
|
7490
|
+
const icp = resolveIcp(opts.icpOverride);
|
|
7491
|
+
const ledger = getLedger();
|
|
7492
|
+
const result = {
|
|
7493
|
+
source: `find:${PLAY_NAME}`,
|
|
7494
|
+
candidates: 0,
|
|
7495
|
+
droppedIcp: 0,
|
|
7496
|
+
droppedDuplicate: 0,
|
|
7497
|
+
droppedEnrichment: 0,
|
|
7498
|
+
enqueued: 0,
|
|
7499
|
+
costUsd: 0
|
|
7500
|
+
};
|
|
7501
|
+
logEvent("finder.start", {
|
|
7502
|
+
name: PLAY_NAME,
|
|
7503
|
+
repos: opts.repos.length,
|
|
7504
|
+
since_days: sinceDays,
|
|
7505
|
+
limit
|
|
7506
|
+
});
|
|
7507
|
+
const tagged = [];
|
|
7508
|
+
let anyRepoOk = false;
|
|
7509
|
+
for (const w of opts.repos) {
|
|
7510
|
+
const { stargazers, error } = await recentStargazers(w.repo, { sinceIso });
|
|
7511
|
+
if (!error) anyRepoOk = true;
|
|
7512
|
+
const label = w.label?.trim() || deriveLabel(w.repo);
|
|
7513
|
+
for (const s of stargazers) tagged.push({
|
|
7514
|
+
...s,
|
|
7515
|
+
repo: w.repo,
|
|
7516
|
+
rel: w.rel,
|
|
7517
|
+
label
|
|
7518
|
+
});
|
|
7519
|
+
}
|
|
7520
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7521
|
+
const candidates = tagged.filter((c) => {
|
|
7522
|
+
const k = c.login.toLowerCase();
|
|
7523
|
+
if (seen.has(k)) return false;
|
|
7524
|
+
seen.add(k);
|
|
7525
|
+
return true;
|
|
7526
|
+
});
|
|
7527
|
+
result.candidates = candidates.length;
|
|
7528
|
+
if (candidates.length === 0) {
|
|
7529
|
+
result.halted = anyRepoOk ? "no recent stargazers in the window" : "all repos failed (check GITHUB_TOKEN / repo names)";
|
|
7530
|
+
logEvent("finder.done", {
|
|
7531
|
+
name: PLAY_NAME,
|
|
7532
|
+
candidates: 0,
|
|
7533
|
+
halted: result.halted
|
|
7534
|
+
});
|
|
7535
|
+
return result;
|
|
7536
|
+
}
|
|
7537
|
+
let halted = false;
|
|
7538
|
+
await parallelMap(candidates, concurrency, async (c) => {
|
|
7539
|
+
if (halted) return;
|
|
7540
|
+
if (result.enqueued >= limit) {
|
|
7541
|
+
halted = true;
|
|
7542
|
+
return;
|
|
7543
|
+
}
|
|
7544
|
+
if (opts.maxCostUsd != null && result.costUsd >= opts.maxCostUsd) {
|
|
7545
|
+
result.halted = `max-cost cap (${opts.maxCostUsd})`;
|
|
7546
|
+
halted = true;
|
|
7547
|
+
return;
|
|
7548
|
+
}
|
|
7549
|
+
const playName = c.rel === "competitor" ? "competitor-switch" : "repo-interest";
|
|
7550
|
+
const dedupeKey = `${PLAY_NAME}:${c.repo}:${c.login}`;
|
|
7551
|
+
if (ledger.isQueueDuplicate(playName, dedupeKey)) {
|
|
7552
|
+
result.droppedDuplicate++;
|
|
7553
|
+
return;
|
|
7554
|
+
}
|
|
7555
|
+
const user = await fetchGitHubUser(c.login);
|
|
7556
|
+
if (!user) {
|
|
7557
|
+
result.droppedEnrichment++;
|
|
7558
|
+
return;
|
|
7559
|
+
}
|
|
7560
|
+
const fullName = user.name ?? c.login;
|
|
7561
|
+
const filter = await icpFilter({
|
|
7562
|
+
icp,
|
|
7563
|
+
candidate: {
|
|
7564
|
+
title: fullName,
|
|
7565
|
+
url: c.userUrl,
|
|
7566
|
+
summary: [user.company, `starred ${c.repo}`].filter(Boolean).join(" · ")
|
|
7567
|
+
}
|
|
7568
|
+
});
|
|
7569
|
+
if (!filter.match) {
|
|
7570
|
+
result.droppedIcp++;
|
|
7571
|
+
if (!opts.dryRun) ledger.enqueueTarget({
|
|
7572
|
+
playName,
|
|
7573
|
+
payload: {
|
|
7574
|
+
name: fullName,
|
|
7575
|
+
company: user.company ?? "",
|
|
7576
|
+
repo: c.repo
|
|
7577
|
+
},
|
|
7578
|
+
dedupeKey,
|
|
7579
|
+
source: sourceFor(c.repo),
|
|
7580
|
+
initialStatus: "rejected",
|
|
7581
|
+
notes: `auto: ICP — ${filter.reason}`
|
|
7582
|
+
});
|
|
7583
|
+
return;
|
|
7584
|
+
}
|
|
7585
|
+
if (opts.dryRun) {
|
|
7586
|
+
result.enqueued++;
|
|
7587
|
+
return;
|
|
7588
|
+
}
|
|
7589
|
+
let email = user.email;
|
|
7590
|
+
if (!email) {
|
|
7591
|
+
const domain = user.blogDomain;
|
|
7592
|
+
if (!domain) {
|
|
7593
|
+
result.droppedEnrichment++;
|
|
7594
|
+
return;
|
|
7595
|
+
}
|
|
7596
|
+
const skip = shouldSkipFindEmail({
|
|
7597
|
+
fullName,
|
|
7598
|
+
companyDomain: domain
|
|
7599
|
+
});
|
|
7600
|
+
if (!skip.ok) {
|
|
7601
|
+
result.droppedEnrichment++;
|
|
7602
|
+
logEvent("finder.skipped_findemail", {
|
|
7603
|
+
name: PLAY_NAME,
|
|
7604
|
+
reason: skip.reason
|
|
7605
|
+
}, "info");
|
|
7606
|
+
return;
|
|
7607
|
+
}
|
|
7608
|
+
const found = await findEmail({
|
|
7609
|
+
companyDomain: domain,
|
|
7610
|
+
fullName
|
|
7611
|
+
}, { playName: PLAY_NAME });
|
|
7612
|
+
result.costUsd += found.result.cost ?? 0;
|
|
7613
|
+
if (!found.result.found || !found.result.email) {
|
|
7614
|
+
result.droppedEnrichment++;
|
|
7615
|
+
return;
|
|
7616
|
+
}
|
|
7617
|
+
email = found.result.email;
|
|
7618
|
+
}
|
|
7619
|
+
const verified = await verifyEmail({ email }, { playName: PLAY_NAME });
|
|
7620
|
+
result.costUsd += verified.result.cost ?? 0;
|
|
7621
|
+
if (!verified.result.deliverable) {
|
|
7622
|
+
result.droppedEnrichment++;
|
|
7623
|
+
return;
|
|
7624
|
+
}
|
|
7625
|
+
if (isDuplicate({
|
|
7626
|
+
playName,
|
|
7627
|
+
dedupeKey,
|
|
7628
|
+
prospectEmail: email
|
|
7629
|
+
})) {
|
|
7630
|
+
result.droppedDuplicate++;
|
|
7631
|
+
return;
|
|
7632
|
+
}
|
|
7633
|
+
const enr = await enrichVerifiedContact(email, {
|
|
7634
|
+
playName: PLAY_NAME,
|
|
7635
|
+
errKindPrefix: PLAY_NAME
|
|
7636
|
+
});
|
|
7637
|
+
result.costUsd += enr.costUsd;
|
|
7638
|
+
const company = user.company?.trim() || "(unknown)";
|
|
7639
|
+
const repoUrl = `https://github.com/${c.repo}`;
|
|
7640
|
+
const contactExtras = {
|
|
7641
|
+
...enr.linkedinUrl ? { linkedinUrl: enr.linkedinUrl } : {},
|
|
7642
|
+
...enr.phone ? { phone: enr.phone } : {}
|
|
7643
|
+
};
|
|
7644
|
+
const target = c.rel === "competitor" ? {
|
|
7645
|
+
name: fullName,
|
|
7646
|
+
email,
|
|
7647
|
+
company,
|
|
7648
|
+
competitor: c.label,
|
|
7649
|
+
evidenceUrl: repoUrl,
|
|
7650
|
+
evidenceText: `Starred ${c.label}'s repo (${c.repo}) on ${c.starredAt.slice(0, 10)} — actively evaluating tools in this space.`,
|
|
7651
|
+
yourEdge: opts.yourEdge,
|
|
7652
|
+
...contactExtras
|
|
7653
|
+
} : {
|
|
7654
|
+
name: fullName,
|
|
7655
|
+
email,
|
|
7656
|
+
company,
|
|
7657
|
+
repo: c.repo,
|
|
7658
|
+
repoLabel: c.label,
|
|
7659
|
+
yourEdge: opts.yourEdge,
|
|
7660
|
+
evidenceUrl: repoUrl,
|
|
7661
|
+
...contactExtras
|
|
7662
|
+
};
|
|
7663
|
+
if (ledger.enqueueTarget({
|
|
7664
|
+
playName,
|
|
7665
|
+
payload: target,
|
|
7666
|
+
dedupeKey,
|
|
7667
|
+
source: sourceFor(c.repo),
|
|
7668
|
+
notes: filter.reason
|
|
7669
|
+
}) != null) result.enqueued++;
|
|
7670
|
+
else result.droppedDuplicate++;
|
|
7671
|
+
});
|
|
7672
|
+
logEvent("finder.done", {
|
|
7673
|
+
name: PLAY_NAME,
|
|
7674
|
+
candidates: result.candidates,
|
|
7675
|
+
enqueued: result.enqueued,
|
|
7676
|
+
dropped_icp: result.droppedIcp,
|
|
7677
|
+
dropped_dup: result.droppedDuplicate,
|
|
7678
|
+
dropped_enrich: result.droppedEnrichment,
|
|
7679
|
+
cost_usd: result.costUsd,
|
|
7680
|
+
halted: result.halted ?? null
|
|
7681
|
+
});
|
|
7682
|
+
return result;
|
|
7683
|
+
}
|
|
7684
|
+
//#endregion
|
|
6623
7685
|
//#region ../../packages/find/src/registry.ts
|
|
6624
7686
|
/** Evaluate a spec's readiness fn (defaulting to ready when absent). */
|
|
6625
7687
|
function checkReadiness(spec, config) {
|
|
@@ -6717,7 +7779,7 @@ const TRIGGERS = [
|
|
|
6717
7779
|
limit: 25,
|
|
6718
7780
|
maxCostUsd: 15
|
|
6719
7781
|
},
|
|
6720
|
-
configBrief: "Sweeps every known incubator (YC, Techstars, Antler, 500 Global, AI Grant, SPC, Neo) at its latest + previous-latest cohorts in one run. Config: `cohorts` (array of `{cohort, cohortLabel}` — defaults to the 14-entry curated list; edit to add/remove batches as new cohorts announce), optional `cohort` + `cohortLabel` (legacy single-cohort shape; still accepted), optional `adapter` (`yc-oss` | `websearch`; auto-picked per cohort — yc-* tags use the free yc-oss/api directory, everything else falls back to web search), `limit` (global enqueue cap across all cohorts), `maxCostUsd`. Per-cohort failures (spotty incubator, network blip) log and continue; the run only halts when EVERY cohort returns 0 candidates. ROTATION: the default list goes stale within ~3 months — edit when YC announces W27, Techstars rolls Fall 2026, etc. STRATEGIST DUTY: when the founder's ICP overlaps strongly with one incubator population, narrow the cohorts list rather than sweeping all seven — e.g. AI/infra startups → keep yc-* + ai-grant-*, drop the rest.",
|
|
7782
|
+
configBrief: "Sweeps every known incubator (YC, Techstars, Antler, 500 Global, AI Grant, SPC, Neo) at its latest + previous-latest cohorts in one run. Config: `cohorts` (array of `{cohort, cohortLabel}` — defaults to the 14-entry curated list; edit to add/remove batches as new cohorts announce), optional `cohort` + `cohortLabel` (legacy single-cohort shape; still accepted), optional `adapter` (`yc-oss` | `websearch`; auto-picked per cohort — yc-* tags use the free yc-oss/api directory, everything else falls back to web search), `senderCohort` (YOUR own cohort tag, e.g. `yc-w23` — the peer angle the email is built on; REQUIRED, stamped onto every enqueued row so rows draft inline), `freeForCohortOffer` (optional time-bound offer, also stamped onto rows), `limit` (global enqueue cap across all cohorts), `maxCostUsd`. Per-cohort failures (spotty incubator, network blip) log and continue; the run only halts when EVERY cohort returns 0 candidates. ROTATION: the default list goes stale within ~3 months — edit when YC announces W27, Techstars rolls Fall 2026, etc. STRATEGIST DUTY: when the founder's ICP overlaps strongly with one incubator population, narrow the cohorts list rather than sweeping all seven — e.g. AI/infra startups → keep yc-* + ai-grant-*, drop the rest.",
|
|
6721
7783
|
readiness: (cfg) => {
|
|
6722
7784
|
const cohorts = Array.isArray(cfg["cohorts"]) ? cfg["cohorts"] : null;
|
|
6723
7785
|
const legacyCohort = typeof cfg["cohort"] === "string" ? cfg["cohort"].trim() : "";
|
|
@@ -6725,6 +7787,10 @@ const TRIGGERS = [
|
|
|
6725
7787
|
ready: false,
|
|
6726
7788
|
reason: "set `cohorts[]` (or legacy `cohort`)"
|
|
6727
7789
|
};
|
|
7790
|
+
if ((typeof cfg["senderCohort"] === "string" ? cfg["senderCohort"].trim() : "").length === 0) return {
|
|
7791
|
+
ready: false,
|
|
7792
|
+
reason: "set `senderCohort` (your own cohort tag, e.g. yc-w23)"
|
|
7793
|
+
};
|
|
6728
7794
|
return { ready: true };
|
|
6729
7795
|
},
|
|
6730
7796
|
run: (cfg) => {
|
|
@@ -6749,6 +7815,8 @@ const TRIGGERS = [
|
|
|
6749
7815
|
cohortLabel: legacyLabel
|
|
6750
7816
|
} : {},
|
|
6751
7817
|
...cfg["adapter"] === "yc-oss" || cfg["adapter"] === "websearch" ? { adapter: cfg["adapter"] } : {},
|
|
7818
|
+
...typeof cfg["senderCohort"] === "string" && cfg["senderCohort"].trim().length > 0 ? { senderCohort: cfg["senderCohort"].trim() } : {},
|
|
7819
|
+
...typeof cfg["freeForCohortOffer"] === "string" && cfg["freeForCohortOffer"].trim().length > 0 ? { freeForCohortOffer: cfg["freeForCohortOffer"].trim() } : {},
|
|
6752
7820
|
limit: cfg["limit"] ?? 25,
|
|
6753
7821
|
maxCostUsd: cfg["maxCostUsd"] ?? 15
|
|
6754
7822
|
});
|
|
@@ -6813,7 +7881,13 @@ const TRIGGERS = [
|
|
|
6813
7881
|
limit: 25,
|
|
6814
7882
|
maxCostUsd: 5
|
|
6815
7883
|
},
|
|
6816
|
-
configBrief: "Scans Greenhouse / Lever / Workable / Ashby ATS pages for open roles that signal the company would buy THIS product. Config: `roles` (job titles whose existence implies a need for the product — e.g. 'Founding ML Engineer' for AI-infra products, 'Head of Compliance' for compliance products), `companies` (optional whitelist), `yourClaim` (one-sentence pitch about why your product makes that role's first 90 days easier — fed into the email), `sinceDays`, `limit`, `maxCostUsd`. The roles + yourClaim need to be tightly coupled to the product.",
|
|
7884
|
+
configBrief: "Scans Greenhouse / Lever / Workable / Ashby ATS pages for open roles that signal the company would buy THIS product. Config: `roles` (job titles whose existence implies a need for the product — e.g. 'Founding ML Engineer' for AI-infra products, 'Head of Compliance' for compliance products), `companies` (optional whitelist), `yourClaim` (one-sentence pitch about why your product makes that role's first 90 days easier — fed into the email; REQUIRED), `sinceDays`, `limit`, `maxCostUsd`. The roles + yourClaim need to be tightly coupled to the product.",
|
|
7885
|
+
readiness: (cfg) => {
|
|
7886
|
+
return (typeof cfg["yourClaim"] === "string" ? cfg["yourClaim"].trim() : "").length > 0 ? { ready: true } : {
|
|
7887
|
+
ready: false,
|
|
7888
|
+
reason: "set `yourClaim` (your one-line pitch)"
|
|
7889
|
+
};
|
|
7890
|
+
},
|
|
6817
7891
|
run: (cfg) => runHiringSignalFinder({
|
|
6818
7892
|
dryRun: false,
|
|
6819
7893
|
...Array.isArray(cfg["roles"]) ? { roles: cfg["roles"] } : {},
|
|
@@ -6904,6 +7978,60 @@ const TRIGGERS = [
|
|
|
6904
7978
|
});
|
|
6905
7979
|
}
|
|
6906
7980
|
},
|
|
7981
|
+
{
|
|
7982
|
+
name: "github-stars",
|
|
7983
|
+
defaultIntervalMs: 12 * ONE_HOUR,
|
|
7984
|
+
enabledByDefault: false,
|
|
7985
|
+
defaultConfig: {
|
|
7986
|
+
repos: [],
|
|
7987
|
+
yourEdge: "",
|
|
7988
|
+
sinceDays: 30,
|
|
7989
|
+
concurrency: 3,
|
|
7990
|
+
limit: 25,
|
|
7991
|
+
maxCostUsd: 5
|
|
7992
|
+
},
|
|
7993
|
+
configBrief: "Finds recent stargazers of repos you watch and turns them into prospects. Config: `repos` (array of `{repo:\"owner/name\", rel:\"competitor\"|\"adjacent\", label?}` — tag a repo `competitor` to pitch a switch (→ competitor-switch) or `adjacent` for a complementary intro (→ repo-interest); `label` is the human name, else derived from the repo), `yourEdge` (one-line pitch fed to whichever play, REQUIRED), `sinceDays` (recency window, default 30), `limit`, `maxCostUsd`. Needs `GITHUB_TOKEN` for any volume. STRATEGIST DUTY: pick repos your buyers' current tools live in; tag the ones you replace as `competitor`, the rest `adjacent`.",
|
|
7994
|
+
readiness: (cfg) => {
|
|
7995
|
+
if ((Array.isArray(cfg["repos"]) ? cfg["repos"] : []).filter((r) => {
|
|
7996
|
+
if (!r || typeof r !== "object") return false;
|
|
7997
|
+
const e = r;
|
|
7998
|
+
return typeof e["repo"] === "string" && e["repo"].trim().length > 0 && (e["rel"] === "competitor" || e["rel"] === "adjacent");
|
|
7999
|
+
}).length === 0) return {
|
|
8000
|
+
ready: false,
|
|
8001
|
+
reason: "set `repos` (each `{repo, rel:'competitor'|'adjacent'}`)"
|
|
8002
|
+
};
|
|
8003
|
+
const edge = cfg["yourEdge"];
|
|
8004
|
+
if (typeof edge !== "string" || edge.trim().length === 0) return {
|
|
8005
|
+
ready: false,
|
|
8006
|
+
reason: "set `yourEdge` — your one-line pitch"
|
|
8007
|
+
};
|
|
8008
|
+
return { ready: true };
|
|
8009
|
+
},
|
|
8010
|
+
run: (cfg) => {
|
|
8011
|
+
return runGitHubStarsFinder({
|
|
8012
|
+
dryRun: false,
|
|
8013
|
+
repos: (Array.isArray(cfg["repos"]) ? cfg["repos"] : []).map((r) => {
|
|
8014
|
+
if (!r || typeof r !== "object") return null;
|
|
8015
|
+
const e = r;
|
|
8016
|
+
const repo = typeof e["repo"] === "string" ? e["repo"].trim() : "";
|
|
8017
|
+
const rel = e["rel"];
|
|
8018
|
+
if (repo.length === 0 || rel !== "competitor" && rel !== "adjacent") return null;
|
|
8019
|
+
const label = typeof e["label"] === "string" ? e["label"].trim() : "";
|
|
8020
|
+
const watch = {
|
|
8021
|
+
repo,
|
|
8022
|
+
rel
|
|
8023
|
+
};
|
|
8024
|
+
if (label) watch.label = label;
|
|
8025
|
+
return watch;
|
|
8026
|
+
}).filter((r) => r !== null),
|
|
8027
|
+
yourEdge: typeof cfg["yourEdge"] === "string" ? cfg["yourEdge"] : "",
|
|
8028
|
+
sinceDays: cfg["sinceDays"] ?? 30,
|
|
8029
|
+
concurrency: cfg["concurrency"] ?? 3,
|
|
8030
|
+
limit: cfg["limit"] ?? 25,
|
|
8031
|
+
maxCostUsd: cfg["maxCostUsd"] ?? 5
|
|
8032
|
+
});
|
|
8033
|
+
}
|
|
8034
|
+
},
|
|
6907
8035
|
{
|
|
6908
8036
|
name: "breakup-revive",
|
|
6909
8037
|
defaultIntervalMs: 168 * ONE_HOUR,
|
|
@@ -7264,13 +8392,6 @@ async function drainQueue(opts) {
|
|
|
7264
8392
|
errors: []
|
|
7265
8393
|
};
|
|
7266
8394
|
if (rows.length === 0) return outcome;
|
|
7267
|
-
if (opts.playName === "accelerator-batch" && !opts.senderCohort) {
|
|
7268
|
-
outcome.errors.push({
|
|
7269
|
-
id: -1,
|
|
7270
|
-
message: "--sender-cohort is required for draining accelerator-batch"
|
|
7271
|
-
});
|
|
7272
|
-
return outcome;
|
|
7273
|
-
}
|
|
7274
8395
|
if (!isSupportedPlay(opts.playName)) {
|
|
7275
8396
|
outcome.errors.push({
|
|
7276
8397
|
id: -1,
|
|
@@ -7329,89 +8450,16 @@ async function drainQueue(opts) {
|
|
|
7329
8450
|
if (opts.dryRun) outcome.sent = rows.length;
|
|
7330
8451
|
return outcome;
|
|
7331
8452
|
}
|
|
7332
|
-
const SUPPORTED_PLAYS = new Set([
|
|
7333
|
-
"show-hn",
|
|
7334
|
-
"job-change",
|
|
7335
|
-
"post-funding",
|
|
7336
|
-
"accelerator-batch",
|
|
7337
|
-
"hiring-signal",
|
|
7338
|
-
"podcast-guest",
|
|
7339
|
-
"breakup-revive",
|
|
7340
|
-
"competitor-switch",
|
|
7341
|
-
"stack-consolidation"
|
|
7342
|
-
]);
|
|
7343
|
-
function isSupportedPlay(name) {
|
|
7344
|
-
return SUPPORTED_PLAYS.has(name);
|
|
7345
|
-
}
|
|
7346
8453
|
async function dispatchOneTarget(opts, row) {
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
}
|
|
7355
|
-
|
|
7356
|
-
const target = JSON.parse(row.payload_json);
|
|
7357
|
-
return firstDraft((await runJobChange({
|
|
7358
|
-
dryRun: opts.dryRun,
|
|
7359
|
-
targets: [target]
|
|
7360
|
-
})).drafted);
|
|
7361
|
-
}
|
|
7362
|
-
case "post-funding": {
|
|
7363
|
-
const target = JSON.parse(row.payload_json);
|
|
7364
|
-
return firstDraft((await runPostFunding({
|
|
7365
|
-
dryRun: opts.dryRun,
|
|
7366
|
-
targets: [target]
|
|
7367
|
-
})).drafted);
|
|
7368
|
-
}
|
|
7369
|
-
case "accelerator-batch": {
|
|
7370
|
-
const target = JSON.parse(row.payload_json);
|
|
7371
|
-
return firstDraft((await runAcceleratorBatch({
|
|
7372
|
-
dryRun: opts.dryRun,
|
|
7373
|
-
targets: [target],
|
|
7374
|
-
senderCohort: opts.senderCohort,
|
|
7375
|
-
...opts.freeForCohortOffer ? { freeForCohortOffer: opts.freeForCohortOffer } : {}
|
|
7376
|
-
})).drafted);
|
|
7377
|
-
}
|
|
7378
|
-
case "hiring-signal": {
|
|
7379
|
-
const target = JSON.parse(row.payload_json);
|
|
7380
|
-
return firstDraft((await runHiringSignal({
|
|
7381
|
-
dryRun: opts.dryRun,
|
|
7382
|
-
targets: [target]
|
|
7383
|
-
})).drafted);
|
|
7384
|
-
}
|
|
7385
|
-
case "podcast-guest": {
|
|
7386
|
-
const target = JSON.parse(row.payload_json);
|
|
7387
|
-
return firstDraft((await runPodcastGuest({
|
|
7388
|
-
dryRun: opts.dryRun,
|
|
7389
|
-
targets: [target]
|
|
7390
|
-
})).drafted);
|
|
7391
|
-
}
|
|
7392
|
-
case "breakup-revive": {
|
|
7393
|
-
const target = JSON.parse(row.payload_json);
|
|
7394
|
-
return firstDraft((await runBreakupRevive({
|
|
7395
|
-
dryRun: opts.dryRun,
|
|
7396
|
-
targets: [target]
|
|
7397
|
-
})).drafted);
|
|
7398
|
-
}
|
|
7399
|
-
case "competitor-switch": {
|
|
7400
|
-
const target = JSON.parse(row.payload_json);
|
|
7401
|
-
return firstDraft((await runCompetitorSwitch({
|
|
7402
|
-
dryRun: opts.dryRun,
|
|
7403
|
-
targets: [target]
|
|
7404
|
-
})).drafted);
|
|
7405
|
-
}
|
|
7406
|
-
case "stack-consolidation": {
|
|
7407
|
-
const target = JSON.parse(row.payload_json);
|
|
7408
|
-
return firstDraft((await runStackConsolidation({
|
|
7409
|
-
dryRun: opts.dryRun,
|
|
7410
|
-
targets: [target]
|
|
7411
|
-
})).drafted);
|
|
7412
|
-
}
|
|
7413
|
-
default: throw new Error(`drain: unsupported play '${opts.playName}'`);
|
|
7414
|
-
}
|
|
8454
|
+
const play = PLAYS[opts.playName];
|
|
8455
|
+
if (!play) throw new Error(`drain: unsupported play '${opts.playName}'`);
|
|
8456
|
+
const target = JSON.parse(row.payload_json);
|
|
8457
|
+
return firstDraft((await play.run({
|
|
8458
|
+
dryRun: opts.dryRun,
|
|
8459
|
+
targets: [target],
|
|
8460
|
+
...opts.senderCohort ? { senderCohort: opts.senderCohort } : {},
|
|
8461
|
+
...opts.freeForCohortOffer ? { freeForCohortOffer: opts.freeForCohortOffer } : {}
|
|
8462
|
+
})).drafted);
|
|
7415
8463
|
}
|
|
7416
8464
|
function firstDraft(drafted) {
|
|
7417
8465
|
const d = drafted[0];
|
|
@@ -7777,49 +8825,17 @@ function toDraftedView(d) {
|
|
|
7777
8825
|
/**
|
|
7778
8826
|
* Dispatch a play by name and return one DraftedView per target (in order).
|
|
7779
8827
|
* Shared by the SSE /api/run endpoint (multi-target) and the /queue
|
|
7780
|
-
* regenerate endpoint (single-target dry-run). Throws on unsupported plays
|
|
7781
|
-
* and on accelerator-batch without a senderCohort.
|
|
8828
|
+
* regenerate endpoint (single-target dry-run). Throws on unsupported plays.
|
|
7782
8829
|
*/
|
|
7783
8830
|
async function dispatchPlay(playName, body) {
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
})).drafted.map(toDraftedView);
|
|
7793
|
-
case "post-funding": return (await runPostFunding({
|
|
7794
|
-
dryRun: body.dryRun,
|
|
7795
|
-
targets: body.targets
|
|
7796
|
-
})).drafted.map(toDraftedView);
|
|
7797
|
-
case "accelerator-batch":
|
|
7798
|
-
if (!body.senderCohort || body.senderCohort.length === 0) throw new Error("accelerator-batch requires senderCohort");
|
|
7799
|
-
return (await runAcceleratorBatch({
|
|
7800
|
-
dryRun: body.dryRun,
|
|
7801
|
-
targets: body.targets,
|
|
7802
|
-
senderCohort: body.senderCohort,
|
|
7803
|
-
...body.freeForCohortOffer ? { freeForCohortOffer: body.freeForCohortOffer } : {}
|
|
7804
|
-
})).drafted.map(toDraftedView);
|
|
7805
|
-
case "hiring-signal": return (await runHiringSignal({
|
|
7806
|
-
dryRun: body.dryRun,
|
|
7807
|
-
targets: body.targets
|
|
7808
|
-
})).drafted.map(toDraftedView);
|
|
7809
|
-
case "podcast-guest": return (await runPodcastGuest({
|
|
7810
|
-
dryRun: body.dryRun,
|
|
7811
|
-
targets: body.targets
|
|
7812
|
-
})).drafted.map(toDraftedView);
|
|
7813
|
-
case "competitor-switch": return (await runCompetitorSwitch({
|
|
7814
|
-
dryRun: body.dryRun,
|
|
7815
|
-
targets: body.targets
|
|
7816
|
-
})).drafted.map(toDraftedView);
|
|
7817
|
-
case "stack-consolidation": return (await runStackConsolidation({
|
|
7818
|
-
dryRun: body.dryRun,
|
|
7819
|
-
targets: body.targets
|
|
7820
|
-
})).drafted.map(toDraftedView);
|
|
7821
|
-
default: throw new Error(`unsupported play: ${playName}`);
|
|
7822
|
-
}
|
|
8831
|
+
const play = PLAYS[playName];
|
|
8832
|
+
if (!play) throw new Error(`unsupported play: ${playName}`);
|
|
8833
|
+
return (await play.run({
|
|
8834
|
+
dryRun: body.dryRun,
|
|
8835
|
+
targets: body.targets,
|
|
8836
|
+
...body.senderCohort ? { senderCohort: body.senderCohort } : {},
|
|
8837
|
+
...body.freeForCohortOffer ? { freeForCohortOffer: body.freeForCohortOffer } : {}
|
|
8838
|
+
})).drafted.map(toDraftedView);
|
|
7823
8839
|
}
|
|
7824
8840
|
//#endregion
|
|
7825
8841
|
//#region src/api/run.ts
|
|
@@ -7831,7 +8847,8 @@ const SUPPORTED = new Set([
|
|
|
7831
8847
|
"hiring-signal",
|
|
7832
8848
|
"podcast-guest",
|
|
7833
8849
|
"competitor-switch",
|
|
7834
|
-
"stack-consolidation"
|
|
8850
|
+
"stack-consolidation",
|
|
8851
|
+
"repo-interest"
|
|
7835
8852
|
]);
|
|
7836
8853
|
async function runPlay(req, params) {
|
|
7837
8854
|
const playName = params["playName"] ?? "";
|
|
@@ -8439,6 +9456,10 @@ const routes = [
|
|
|
8439
9456
|
route("GET", "/api/cadences", listCadences),
|
|
8440
9457
|
route("GET", "/api/cadences/:id", getCadence),
|
|
8441
9458
|
route("POST", "/api/cadences/:id/stop", stopCadence),
|
|
9459
|
+
route("POST", "/api/cadences/:id/preview-next", previewCadenceStepRoute),
|
|
9460
|
+
route("POST", "/api/cadences/:id/send-next", sendCadenceStepRoute),
|
|
9461
|
+
route("POST", "/api/cadences/preview-batch", previewCadenceBatchRoute),
|
|
9462
|
+
route("POST", "/api/cadences/send-batch", sendCadenceBatchRoute),
|
|
8442
9463
|
route("GET", "/api/receipts", listReceipts),
|
|
8443
9464
|
route("GET", "/api/receipts/:id", getReceipt),
|
|
8444
9465
|
route("GET", "/api/inbox", listInboxRoute),
|