@ak--47/dungeon-master 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.claude/skills/create-dungeon/SKILL.md +139 -46
  2. package/.claude/skills/verify-dungeon/references/counting-semantics.md +31 -6
  3. package/.claude/skills/verify-dungeon/references/sql-recipes.md +44 -25
  4. package/.claude/skills/write-hooks/SKILL.md +31 -3
  5. package/CHANGELOG.md +85 -0
  6. package/HOOKS.md +13 -0
  7. package/dungeons/technical/ad-spend.js +41 -49
  8. package/dungeons/technical/anonymous-users.js +38 -36
  9. package/dungeons/technical/array-of-object-lookup.js +136 -153
  10. package/dungeons/technical/datagen-v15-verify.js +24 -11
  11. package/dungeons/technical/experiments.js +42 -40
  12. package/dungeons/technical/foobar.js +114 -118
  13. package/dungeons/technical/group-analytics.js +42 -40
  14. package/dungeons/technical/hook-helpers-verify.js +69 -50
  15. package/dungeons/technical/identity-model-verify.js +22 -12
  16. package/dungeons/technical/mirror-strategies.js +37 -39
  17. package/dungeons/technical/nested-objects.js +119 -118
  18. package/dungeons/technical/pattern-aggregate-by-bin.js +21 -8
  19. package/dungeons/technical/pattern-attributed-by-source.js +23 -9
  20. package/dungeons/technical/pattern-frequency-by-frequency.js +21 -8
  21. package/dungeons/technical/pattern-funnel-frequency.js +30 -15
  22. package/dungeons/technical/pattern-ttc-by-segment.js +21 -8
  23. package/dungeons/technical/retention-cadence.js +115 -112
  24. package/dungeons/technical/sanity.js +86 -80
  25. package/dungeons/technical/scale-test.js +34 -38
  26. package/dungeons/technical/scd.js +111 -128
  27. package/dungeons/technical/simple.js +134 -141
  28. package/dungeons/technical/simplest.js +54 -62
  29. package/dungeons/technical/text-generation.js +110 -146
  30. package/dungeons/vertical/ai-platform.js +296 -333
  31. package/dungeons/vertical/community.js +284 -255
  32. package/dungeons/vertical/crypto.js +395 -391
  33. package/dungeons/vertical/dating.js +411 -378
  34. package/dungeons/vertical/devtools.js +336 -298
  35. package/dungeons/vertical/ecommerce.js +316 -394
  36. package/dungeons/vertical/education.js +369 -325
  37. package/dungeons/vertical/fintech.js +358 -325
  38. package/dungeons/vertical/fitness.js +335 -291
  39. package/dungeons/vertical/food-delivery.js +343 -307
  40. package/dungeons/vertical/gaming.js +480 -444
  41. package/dungeons/vertical/healthcare.js +306 -262
  42. package/dungeons/vertical/insurance-application.js +427 -409
  43. package/dungeons/vertical/logistics.js +271 -252
  44. package/dungeons/vertical/marketplace.js +333 -323
  45. package/dungeons/vertical/media.js +382 -335
  46. package/dungeons/vertical/real-estate.js +395 -346
  47. package/dungeons/vertical/sass.js +319 -333
  48. package/dungeons/vertical/social.js +368 -316
  49. package/dungeons/vertical/travel.js +297 -295
  50. package/index.js +46 -4
  51. package/lib/core/config-validator.js +126 -28
  52. package/lib/generators/funnels.js +4 -1
  53. package/lib/orchestrators/mixpanel-sender.js +7 -0
  54. package/lib/orchestrators/user-loop.js +132 -31
  55. package/lib/templates/defaults.js +59 -59
  56. package/lib/templates/macro-presets.js +14 -2
  57. package/lib/utils/dataset-context.js +103 -0
  58. package/lib/utils/retention-curve.js +140 -0
  59. package/lib/utils/utils.js +149 -38
  60. package/lib/verify/counting.js +40 -0
  61. package/lib/verify/emulate-breakdown.js +20 -1
  62. package/lib/verify/index.js +1 -0
  63. package/lib/verify/schema-validator.js +3 -1
  64. package/package.json +11 -2
  65. package/scripts/run-dungeon.mjs +12 -1
  66. package/types.d.ts +117 -1
@@ -1,56 +1,51 @@
1
- // ── TWEAK THESE ──
2
- const SEED = "harness-social";
3
- const num_days = 120;
4
- const num_users = 10_000;
5
- const avg_events_per_user_per_day = 1.2;
6
- let token = "your-mixpanel-token";
7
-
8
- // ── env overrides ──
9
- if (process.env.MP_TOKEN) token = process.env.MP_TOKEN;
10
-
1
+ // ── IMPORTS ──
11
2
  import dayjs from "dayjs";
12
3
  import utc from "dayjs/plugin/utc.js";
4
+ dayjs.extend(utc);
13
5
  import "dotenv/config";
14
6
  import * as u from "../../lib/utils/utils.js";
15
7
  import * as v from "ak-tools";
16
-
17
- dayjs.extend(utc);
18
- const chance = u.initChance(SEED);
19
-
20
8
  /** @typedef {import("../../types").Dungeon} Config */
21
9
 
10
+ // ── OVERVIEW ──
22
11
  /*
23
- * =====================================================================================
24
- * DATASET OVERVIEW
25
- * =====================================================================================
26
- *
27
- * Chirp A Twitter+Instagram-style social media platform with algorithmic feed,
28
- * creator monetization, communities, and direct messaging.
29
- *
30
- * CORE LOOP:
31
- * Users sign up, build a profile, follow people, consume content in their feed,
32
- * create their own posts/stories, and engage via likes, shares, and comments.
33
- * Power users become "creators" with subscriber tiers. Monetization through
34
- * native ads woven into feed and story placements.
35
- *
36
- * - 5,000 users over 100 days
37
- * - 600,000 base events across 18 event types
38
- * - 8 funnels (onboarding, engagement, discovery, creator journey, ads)
39
- * - Group analytics (100 communities)
40
- * - Account types: personal, creator, business
41
- * =====================================================================================
12
+ * NAME: Chirp
13
+ * APP: Twitter+Instagram-style social media platform with algorithmic
14
+ * feed, creator monetization, communities, and direct messaging.
15
+ * Power users become "creators" with subscriber tiers; native ads
16
+ * woven into feed and story placements.
17
+ * SCALE: 10,000 users, ~1.4M events, 121 days (2026-01-01 → 2026-05-01)
18
+ * CORE LOOP: account created → profile updated → post created → consume + engage
19
+ *
20
+ * EVENTS (18):
21
+ * post viewed (30) > post liked (18) > story viewed (15) > post created (12)
22
+ * > notification received (12) > comment posted (10) > ad viewed (10)
23
+ * > user followed (8) > dm sent (8) > search performed (7) > post shared (6)
24
+ * > story created (5) > profile updated (3) > user unfollowed (2)
25
+ * > ad clicked (2) > creator subscription started (2) > report submitted (1)
26
+ * > account created (1)
27
+ *
28
+ * FUNNELS (8):
29
+ * - Onboarding: account created profile updated → post created (70%)
30
+ * - Feed Engagement: post viewed → post liked → comment posted (45%)
31
+ * - Content Cycle: post created → post viewed → post liked → post shared (30%)
32
+ * - Stories: story created → story viewed → dm sent (40%)
33
+ * - Discovery: search performed → post viewed → user followed (35%)
34
+ * - Notifications: notification received → post viewed → post liked (50%)
35
+ * - Creator Monetize: profile updated → creator subscription started → post created (15%)
36
+ * - Ad Moderation: ad viewed → ad clicked → report submitted (20%)
37
+ *
38
+ * USER PROPS: app_version, account_type, follower_count, following_count,
39
+ * bio_length, verified, content_niche
40
+ * SUPER PROPS: app_version, account_type
41
+ * SCD PROPS: account_type (personal/creator/business/verified, monthly fuzzy, max 6),
42
+ * community_status (new/growing/established/featured, monthly fixed,
43
+ * max 6, community_id-scoped)
44
+ * GROUPS: community_id (100 communities)
42
45
  */
43
46
 
47
+ // ── HOOK STORIES ──
44
48
  /*
45
- * =====================================================================================
46
- * ANALYTICS HOOKS (10 hooks)
47
- *
48
- * Adds 10. ONBOARDING TIME-TO-CONVERT: creator/business 0.71x faster, personal
49
- * 1.25x slower (funnel-post). Discover via Onboarding funnel median TTC by account_type.
50
- * NOTE (funnel-post measurement): visible only via Mixpanel funnel median TTC.
51
- * Cross-event MIN→MIN SQL queries on raw events do NOT show this.
52
- * =====================================================================================
53
- *
54
49
  * NOTE: All cohort effects are HIDDEN — discoverable only via behavioral cohorts
55
50
  * (count an event per user, then measure downstream). No cohort flag is stamped
56
51
  * on events. Algorithm-change source flips and engagement-bait short durations
@@ -272,6 +267,9 @@ const chance = u.initChance(SEED);
272
267
  * - Breakdown: "account_type" (superProp)
273
268
  * - Expected: creator/business ~ 0.71x baseline; personal ~ 1.25x baseline
274
269
  *
270
+ * NOTE (funnel-post measurement): visible only via Mixpanel funnel median
271
+ * TTC. Cross-event MIN→MIN SQL queries on raw events do NOT show this.
272
+ *
275
273
  * REAL-WORLD ANALOGUE: Creators and businesses arrive with clear intent
276
274
  * and complete profile setup faster; personal users browse casually and
277
275
  * take longer to commit to their first post.
@@ -296,35 +294,341 @@ const chance = u.initChance(SEED);
296
294
  * =====================================================================================
297
295
  */
298
296
 
297
+ // ── SCALE ──
298
+ const SEED = "harness-social";
299
+ const NUM_USERS = 10_000;
300
+ const DATASET_START = "2026-01-01T00:00:00Z";
301
+ const DATASET_END = "2026-05-01T23:59:59Z";
302
+ const EVENTS_PER_DAY = 1.2;
303
+ const token = process.env.MP_TOKEN || "your-mixpanel-token";
304
+
305
+ const chance = u.initChance(SEED);
306
+
307
+ // ── KNOBS (tweak these to reshape stories) ──
308
+ const VIRAL_POST_THRESHOLD = 10;
309
+ const VIRAL_USER_LIKELIHOOD = 5;
310
+ const VIRAL_CLONES_MIN = 60;
311
+ const VIRAL_CLONES_MAX = 120;
312
+
313
+ const FOLLOW_SNOWBALL_THRESHOLD = 5;
314
+ const FOLLOW_SNOWBALL_LIKELIHOOD = 50;
315
+
316
+ const ALGORITHM_CHANGE_DAY = 45;
317
+ const ALGORITHM_FLIP_LIKELIHOOD = 70;
318
+
319
+ const ENGAGEMENT_BAIT_LIKELIHOOD = 20;
320
+
321
+ const REENGAGEMENT_START_DAY = 30;
322
+ const REENGAGEMENT_LIKELIHOOD = 30;
323
+
324
+ const CREATOR_POST_CLONES = 2;
325
+ const CREATOR_STORY_CLONES = 2;
326
+ const CREATOR_VIEW_CLONE_LIKELIHOOD = 25;
327
+
328
+ const TOXICITY_THRESHOLD = 2;
329
+ const TOXICITY_CUTOFF_DAYS = 30;
330
+ const TOXICITY_DROP_LIKELIHOOD = 60;
331
+
332
+ const WEEKEND_CLONE_LIKELIHOOD = 30;
333
+
334
+ const POST_SWEET_MIN = 3;
335
+ const POST_SWEET_MAX = 7;
336
+ const POST_OVER_THRESHOLD = 8;
337
+ const POST_SWEET_COMMENT_BOOST = 1.4;
338
+ const POST_OVER_COMMENT_FACTOR = 0.7;
339
+
340
+ const ONBOARDING_TTC_FAST = 0.71;
341
+ const ONBOARDING_TTC_SLOW = 1.25;
342
+
343
+ // ── DATA ARRAYS ──
299
344
  // Generate consistent post IDs for lookup tables
300
345
  const postIds = v.range(1, 1001).map(n => `post_${v.uid(8)}`);
301
346
 
347
+ // ── HELPER FUNCTIONS ──
348
+ function handleFunnelPostHooks(record, meta) {
349
+ // H10: ONBOARDING TIME-TO-CONVERT — creator/business 0.71x faster,
350
+ // personal 1.25x slower. Scales inter-step gaps via timestamp rewrite.
351
+ const segment = meta?.profile?.account_type;
352
+ if (Array.isArray(record) && record.length > 1) {
353
+ const factor = (
354
+ segment === "creator" || segment === "business" ? ONBOARDING_TTC_FAST :
355
+ segment === "personal" ? ONBOARDING_TTC_SLOW :
356
+ 1.0
357
+ );
358
+ if (factor !== 1.0) {
359
+ for (let i = 1; i < record.length; i++) {
360
+ const prev = dayjs(record[i - 1].time);
361
+ const newGap = Math.round(dayjs(record[i].time).diff(prev) * factor);
362
+ record[i].time = prev.add(newGap, "milliseconds").toISOString();
363
+ }
364
+ }
365
+ }
366
+ return record;
367
+ }
368
+
369
+ function handleEverythingHooks(record, meta) {
370
+ const datasetStart = dayjs.unix(meta.datasetStart);
371
+ const userEvents = record;
372
+ if (!userEvents || userEvents.length === 0) return record;
373
+
374
+ // Stamp superProps from profile for consistency
375
+ const profile = meta.profile;
376
+ userEvents.forEach(e => {
377
+ e.app_version = profile.app_version;
378
+ e.account_type = profile.account_type;
379
+ });
380
+
381
+ // First pass: identify behavioral patterns (no flags written)
382
+ let postCreatedCount = 0;
383
+ let followReceivedCount = 0;
384
+ let reportSubmittedCount = 0;
385
+ let hasCreatorSubscription = false;
386
+ let isViralCreator = false;
387
+
388
+ userEvents.forEach((event) => {
389
+ if (event.event === "post created") postCreatedCount++;
390
+ if (event.event === "user followed") followReceivedCount++;
391
+ if (event.event === "report submitted") reportSubmittedCount++;
392
+ if (event.event === "creator subscription started") hasCreatorSubscription = true;
393
+ });
394
+
395
+ if (postCreatedCount >= VIRAL_POST_THRESHOLD && chance.bool({ likelihood: VIRAL_USER_LIKELIHOOD })) {
396
+ isViralCreator = true;
397
+ }
398
+
399
+ // Second pass: inject cloned events (no behavioral cohort flags)
400
+ for (let idx = userEvents.length - 1; idx >= 0; idx--) {
401
+ const event = userEvents[idx];
402
+ const eventTime = dayjs(event.time);
403
+
404
+ // H1: VIRAL CONTENT CASCADE — clone 60-120 view/like/share per post.
405
+ // Discovery: bin users by post-created count, observe per-user view/like/share volume.
406
+ if (isViralCreator && event.event === "post created") {
407
+ const viralViews = chance.integer({ min: VIRAL_CLONES_MIN, max: VIRAL_CLONES_MAX });
408
+ const viralLikes = chance.integer({ min: VIRAL_CLONES_MIN, max: VIRAL_CLONES_MAX });
409
+ const viralShares = chance.integer({ min: VIRAL_CLONES_MIN, max: VIRAL_CLONES_MAX });
410
+ const injected = [];
411
+
412
+ const viewTemplate = userEvents.find(e => e.event === "post viewed");
413
+ const likeTemplate = userEvents.find(e => e.event === "post liked");
414
+ const shareTemplate = userEvents.find(e => e.event === "post shared");
415
+
416
+ for (let i = 0; i < viralViews; i++) {
417
+ injected.push({
418
+ ...(viewTemplate || event),
419
+ event: "post viewed",
420
+ time: eventTime.add(chance.integer({ min: 1, max: 180 }), 'minutes').toISOString(),
421
+ user_id: event.user_id,
422
+ post_type: event.post_type || "text",
423
+ source: chance.pickone(["feed", "explore", "search"]),
424
+ view_duration_sec: chance.integer({ min: 5, max: 90 }),
425
+ });
426
+ }
427
+ for (let i = 0; i < viralLikes; i++) {
428
+ injected.push({
429
+ ...(likeTemplate || event),
430
+ event: "post liked",
431
+ time: eventTime.add(chance.integer({ min: 2, max: 240 }), 'minutes').toISOString(),
432
+ user_id: event.user_id,
433
+ post_type: event.post_type || "text",
434
+ });
435
+ }
436
+ for (let i = 0; i < viralShares; i++) {
437
+ injected.push({
438
+ ...(shareTemplate || event),
439
+ event: "post shared",
440
+ time: eventTime.add(chance.integer({ min: 5, max: 300 }), 'minutes').toISOString(),
441
+ user_id: event.user_id,
442
+ share_destination: chance.pickone(["repost", "dm", "external", "copy_link"]),
443
+ });
444
+ }
445
+
446
+ userEvents.splice(idx + 1, 0, ...injected);
447
+ }
448
+
449
+ // H2: FOLLOW-BACK SNOWBALL — extra post + comment per user-followed cluster.
450
+ // Discovery: cohort users with >=5 user-followed events, compare posts/user.
451
+ if (followReceivedCount >= FOLLOW_SNOWBALL_THRESHOLD && event.event === "post created") {
452
+ if (chance.bool({ likelihood: FOLLOW_SNOWBALL_LIKELIHOOD })) {
453
+ const commentTemplate = userEvents.find(e => e.event === "comment posted");
454
+ const duplicatePost = {
455
+ ...event,
456
+ time: eventTime.add(chance.integer({ min: 30, max: 240 }), 'minutes').toISOString(),
457
+ user_id: event.user_id,
458
+ post_type: chance.pickone(["text", "image", "video"]),
459
+ character_count: chance.integer({ min: 10, max: 280 }),
460
+ has_media: chance.bool({ likelihood: 60 }),
461
+ hashtag_count: chance.integer({ min: 0, max: 5 }),
462
+ };
463
+ const extraComment = {
464
+ ...(commentTemplate || event),
465
+ event: "comment posted",
466
+ time: eventTime.add(chance.integer({ min: 10, max: 120 }), 'minutes').toISOString(),
467
+ user_id: event.user_id,
468
+ comment_length: chance.integer({ min: 5, max: 200 }),
469
+ has_mention: chance.bool({ likelihood: 40 }),
470
+ };
471
+ userEvents.splice(idx + 1, 0, duplicatePost, extraComment);
472
+ }
473
+ }
474
+
475
+ // H6: CREATOR MONETIZATION — 3x post/story rate for subscribers.
476
+ // Discovery: cohort users with creator-subscription-started event, compare posts/user.
477
+ if (hasCreatorSubscription && event.event === "post created") {
478
+ for (let i = 0; i < CREATOR_POST_CLONES; i++) {
479
+ const extraPost = {
480
+ ...event,
481
+ time: eventTime.add(chance.integer({ min: 1, max: 12 }), 'hours').toISOString(),
482
+ user_id: event.user_id,
483
+ post_type: chance.pickone(["text", "image", "video", "link"]),
484
+ character_count: chance.integer({ min: 20, max: 280 }),
485
+ has_media: chance.bool({ likelihood: 70 }),
486
+ hashtag_count: chance.integer({ min: 1, max: 8 }),
487
+ };
488
+ userEvents.splice(idx + 1, 0, extraPost);
489
+ }
490
+ }
491
+ if (hasCreatorSubscription && event.event === "story created") {
492
+ for (let i = 0; i < CREATOR_STORY_CLONES; i++) {
493
+ const extraStory = {
494
+ ...event,
495
+ time: eventTime.add(chance.integer({ min: 1, max: 8 }), 'hours').toISOString(),
496
+ user_id: event.user_id,
497
+ story_type: chance.pickone(["photo", "video", "text"]),
498
+ has_filter: chance.bool({ likelihood: 60 }),
499
+ has_sticker: chance.bool({ likelihood: 40 }),
500
+ };
501
+ userEvents.splice(idx + 1, 0, extraStory);
502
+ }
503
+ }
504
+ if (hasCreatorSubscription && event.event === "post viewed") {
505
+ if (chance.bool({ likelihood: CREATOR_VIEW_CLONE_LIKELIHOOD })) {
506
+ const analyticsView = {
507
+ ...event,
508
+ time: eventTime.add(chance.integer({ min: 1, max: 30 }), 'minutes').toISOString(),
509
+ user_id: event.user_id,
510
+ post_type: event.post_type || "text",
511
+ source: "profile",
512
+ view_duration_sec: chance.integer({ min: 10, max: 60 }),
513
+ };
514
+ userEvents.splice(idx + 1, 0, analyticsView);
515
+ }
516
+ }
517
+ }
518
+
519
+ // H8: WEEKEND CONTENT SURGE — duplicate weekend posts/stories with offset.
520
+ // Discovery: line chart by day-of-week shows Sat/Sun bump.
521
+ for (let idx = userEvents.length - 1; idx >= 0; idx--) {
522
+ const event = userEvents[idx];
523
+ if (event.event === "post created" || event.event === "story created") {
524
+ const dow = new Date(event.time).getUTCDay();
525
+ if ((dow === 0 || dow === 6) && chance.bool({ likelihood: WEEKEND_CLONE_LIKELIHOOD })) {
526
+ const etime = dayjs(event.time);
527
+ const dup = {
528
+ ...event,
529
+ time: etime.add(chance.integer({ min: 1, max: 3 }), 'hours').toISOString(),
530
+ };
531
+ userEvents.splice(idx + 1, 0, dup);
532
+ }
533
+ }
534
+ }
535
+
536
+ // H3: ALGORITHM CHANGE — day 45 flips feed → explore on post viewed.
537
+ // H4: ENGAGEMENT BAIT — 20% of post-viewed events get crushed duration.
538
+ // H5: NOTIFICATION RE-ENGAGEMENT — after day 30, 30% of views → notification.
539
+ // All three run AFTER injection passes so they apply to cloned events too.
540
+ const algorithmChangeDay = datasetStart.add(ALGORITHM_CHANGE_DAY, 'days');
541
+ const reengagementStart = datasetStart.add(REENGAGEMENT_START_DAY, 'days');
542
+ userEvents.forEach(e => {
543
+ if (e.event === "post viewed") {
544
+ const eventTime = dayjs(e.time);
545
+
546
+ // H3: Algorithm Change
547
+ if (eventTime.isAfter(algorithmChangeDay)) {
548
+ if (chance.bool({ likelihood: ALGORITHM_FLIP_LIKELIHOOD })) {
549
+ e.source = "explore";
550
+ }
551
+ } else {
552
+ if (chance.bool({ likelihood: ALGORITHM_FLIP_LIKELIHOOD })) {
553
+ e.source = "feed";
554
+ }
555
+ }
556
+
557
+ // H4: Engagement Bait — 20% crushed view duration
558
+ if (chance.bool({ likelihood: ENGAGEMENT_BAIT_LIKELIHOOD })) {
559
+ e.view_duration_sec = chance.integer({ min: 1, max: 5 });
560
+ }
561
+
562
+ // H5: Notification Re-engagement (runs after #3 so can override)
563
+ if (eventTime.isAfter(reengagementStart) && chance.bool({ likelihood: REENGAGEMENT_LIKELIHOOD })) {
564
+ e.source = "notification";
565
+ }
566
+ }
567
+ });
568
+
569
+ // H7: TOXICITY CHURN — drop 60% of activity after day 30 for high reporters.
570
+ // Discovery: cohort users with >=2 report-submitted events, observe retention drop.
571
+ if (reportSubmittedCount >= TOXICITY_THRESHOLD) {
572
+ const churnCutoff = datasetStart.add(TOXICITY_CUTOFF_DAYS, 'days');
573
+ for (let i = userEvents.length - 1; i >= 0; i--) {
574
+ const evt = userEvents[i];
575
+ if (dayjs(evt.time).isAfter(churnCutoff) && chance.bool({ likelihood: TOXICITY_DROP_LIKELIHOOD })) {
576
+ userEvents.splice(i, 1);
577
+ }
578
+ }
579
+ }
580
+
581
+ // H9: POST-CREATED MAGIC NUMBER (no flags)
582
+ // Sweet 3-7 posts → +40% on comment_length on the user's comment events.
583
+ // Over 8+ → -30% comment_length (engagement burnout).
584
+ if (postCreatedCount >= POST_SWEET_MIN && postCreatedCount <= POST_SWEET_MAX) {
585
+ userEvents.forEach(e => {
586
+ if (e.event === 'comment posted' && typeof e.comment_length === 'number') {
587
+ e.comment_length = Math.round(e.comment_length * POST_SWEET_COMMENT_BOOST);
588
+ }
589
+ });
590
+ } else if (postCreatedCount >= POST_OVER_THRESHOLD) {
591
+ userEvents.forEach(e => {
592
+ if (e.event === 'comment posted' && typeof e.comment_length === 'number') {
593
+ e.comment_length = Math.round(e.comment_length * POST_OVER_COMMENT_FACTOR);
594
+ }
595
+ });
596
+ }
597
+
598
+ return record;
599
+ }
600
+
601
+ // ── CONFIG ──
302
602
  /** @type {Config} */
303
603
  const config = {
304
604
  version: 2,
305
- token,
306
605
  seed: SEED,
307
- datasetStart: "2026-01-01T00:00:00Z",
308
- datasetEnd: "2026-05-01T23:59:59Z",
606
+ datasetStart: DATASET_START,
607
+ datasetEnd: DATASET_END,
309
608
  soup: { dayOfWeekWeights: [1.0, 1.0, 1.0, 1.0, 1.0, 1.2, 1.2] },
310
- // numDays: num_days,
311
- avgEventsPerUserPerDay: avg_events_per_user_per_day,
312
- numUsers: num_users,
313
- hasAnonIds: true,
314
- avgDevicePerUser: 2,
315
- hasSessionIds: true,
609
+ avgEventsPerUserPerDay: EVENTS_PER_DAY,
610
+ numUsers: NUM_USERS,
316
611
  format: "json",
317
612
  gzip: true,
318
- alsoInferFunnels: false,
319
- hasLocation: true,
320
- hasAndroidDevices: true,
321
- hasIOSDevices: true,
322
- hasDesktopDevices: true,
323
- hasBrowser: false,
324
- hasCampaigns: false,
325
- isAnonymous: false,
326
- hasAdSpend: false,
327
- hasAvatar: true,
613
+ credentials: {
614
+ token,
615
+ },
616
+ switches: {
617
+ hasSessionIds: true,
618
+ alsoInferFunnels: false,
619
+ hasLocation: true,
620
+ hasAndroidDevices: true,
621
+ hasIOSDevices: true,
622
+ hasDesktopDevices: true,
623
+ hasBrowser: false,
624
+ hasCampaigns: false,
625
+ isAnonymous: false,
626
+ hasAdSpend: false,
627
+ hasAvatar: true,
628
+ },
629
+ identity: {
630
+ avgDevicePerUser: 2,
631
+ },
328
632
  concurrency: 1,
329
633
  writeToDisk: false,
330
634
  scdProps: {
@@ -590,261 +894,9 @@ const config = {
590
894
 
591
895
  lookupTables: [],
592
896
 
593
- hook: function (record, type, meta) {
594
- // Hook #10 (T2C): ONBOARDING TIME-TO-CONVERT (funnel-post)
595
- // Creator/business account_type users complete onboarding 1.4x
596
- // faster (factor 0.71); personal accounts 1.25x slower (factor 1.25).
597
- if (type === "funnel-post") {
598
- const segment = meta?.profile?.account_type;
599
- if (Array.isArray(record) && record.length > 1) {
600
- const factor = (
601
- segment === "creator" || segment === "business" ? 0.71 :
602
- segment === "personal" ? 1.25 :
603
- 1.0
604
- );
605
- if (factor !== 1.0) {
606
- for (let i = 1; i < record.length; i++) {
607
- const prev = dayjs(record[i - 1].time);
608
- const newGap = Math.round(dayjs(record[i].time).diff(prev) * factor);
609
- record[i].time = prev.add(newGap, "milliseconds").toISOString();
610
- }
611
- }
612
- }
613
- }
614
-
615
-
616
- // ─── EVERYTHING-LEVEL HOOKS ──────────────────────────────────────
617
-
618
- if (type === "everything") {
619
- const datasetStart = dayjs.unix(meta.datasetStart);
620
- const userEvents = record;
621
- if (!userEvents || userEvents.length === 0) return record;
622
-
623
- // Stamp superProps from profile for consistency
624
- const profile = meta.profile;
625
- userEvents.forEach(e => {
626
- e.app_version = profile.app_version;
627
- e.account_type = profile.account_type;
628
- });
629
-
630
- // First pass: identify behavioral patterns (no flags written)
631
- let postCreatedCount = 0;
632
- let followReceivedCount = 0;
633
- let reportSubmittedCount = 0;
634
- let hasCreatorSubscription = false;
635
- let isViralCreator = false;
636
-
637
- userEvents.forEach((event) => {
638
- if (event.event === "post created") postCreatedCount++;
639
- if (event.event === "user followed") followReceivedCount++;
640
- if (event.event === "report submitted") reportSubmittedCount++;
641
- if (event.event === "creator subscription started") hasCreatorSubscription = true;
642
- });
643
-
644
- if (postCreatedCount >= 10 && chance.bool({ likelihood: 5 })) {
645
- isViralCreator = true;
646
- }
647
-
648
- // Second pass: inject cloned events (no behavioral cohort flags)
649
- for (let idx = userEvents.length - 1; idx >= 0; idx--) {
650
- const event = userEvents[idx];
651
- const eventTime = dayjs(event.time);
652
-
653
- // Hook #1: VIRAL CONTENT CASCADE — clone 10-20 view/like/share per post.
654
- // Discovery: bin users by post-created count, observe per-user view/like/share volume.
655
- if (isViralCreator && event.event === "post created") {
656
- const viralViews = chance.integer({ min: 60, max: 120 });
657
- const viralLikes = chance.integer({ min: 60, max: 120 });
658
- const viralShares = chance.integer({ min: 60, max: 120 });
659
- const injected = [];
660
-
661
- const viewTemplate = userEvents.find(e => e.event === "post viewed");
662
- const likeTemplate = userEvents.find(e => e.event === "post liked");
663
- const shareTemplate = userEvents.find(e => e.event === "post shared");
664
-
665
- for (let i = 0; i < viralViews; i++) {
666
- injected.push({
667
- ...(viewTemplate || event),
668
- event: "post viewed",
669
- time: eventTime.add(chance.integer({ min: 1, max: 180 }), 'minutes').toISOString(),
670
- user_id: event.user_id,
671
- post_type: event.post_type || "text",
672
- source: chance.pickone(["feed", "explore", "search"]),
673
- view_duration_sec: chance.integer({ min: 5, max: 90 }),
674
- });
675
- }
676
- for (let i = 0; i < viralLikes; i++) {
677
- injected.push({
678
- ...(likeTemplate || event),
679
- event: "post liked",
680
- time: eventTime.add(chance.integer({ min: 2, max: 240 }), 'minutes').toISOString(),
681
- user_id: event.user_id,
682
- post_type: event.post_type || "text",
683
- });
684
- }
685
- for (let i = 0; i < viralShares; i++) {
686
- injected.push({
687
- ...(shareTemplate || event),
688
- event: "post shared",
689
- time: eventTime.add(chance.integer({ min: 5, max: 300 }), 'minutes').toISOString(),
690
- user_id: event.user_id,
691
- share_destination: chance.pickone(["repost", "dm", "external", "copy_link"]),
692
- });
693
- }
694
-
695
- userEvents.splice(idx + 1, 0, ...injected);
696
- }
697
-
698
- // Hook #2: FOLLOW-BACK SNOWBALL — extra post + comment per user-followed cluster.
699
- // Discovery: cohort users with >=5 user-followed events, compare posts/user.
700
- if (followReceivedCount >= 5 && event.event === "post created") {
701
- if (chance.bool({ likelihood: 50 })) {
702
- const commentTemplate = userEvents.find(e => e.event === "comment posted");
703
- const duplicatePost = {
704
- ...event,
705
- time: eventTime.add(chance.integer({ min: 30, max: 240 }), 'minutes').toISOString(),
706
- user_id: event.user_id,
707
- post_type: chance.pickone(["text", "image", "video"]),
708
- character_count: chance.integer({ min: 10, max: 280 }),
709
- has_media: chance.bool({ likelihood: 60 }),
710
- hashtag_count: chance.integer({ min: 0, max: 5 }),
711
- };
712
- const extraComment = {
713
- ...(commentTemplate || event),
714
- event: "comment posted",
715
- time: eventTime.add(chance.integer({ min: 10, max: 120 }), 'minutes').toISOString(),
716
- user_id: event.user_id,
717
- comment_length: chance.integer({ min: 5, max: 200 }),
718
- has_mention: chance.bool({ likelihood: 40 }),
719
- };
720
- userEvents.splice(idx + 1, 0, duplicatePost, extraComment);
721
- }
722
- }
723
-
724
- // Hook #6: CREATOR MONETIZATION — 3x post/story rate for subscribers.
725
- // Discovery: cohort users with creator-subscription-started event, compare posts/user.
726
- if (hasCreatorSubscription && event.event === "post created") {
727
- for (let i = 0; i < 2; i++) {
728
- const extraPost = {
729
- ...event,
730
- time: eventTime.add(chance.integer({ min: 1, max: 12 }), 'hours').toISOString(),
731
- user_id: event.user_id,
732
- post_type: chance.pickone(["text", "image", "video", "link"]),
733
- character_count: chance.integer({ min: 20, max: 280 }),
734
- has_media: chance.bool({ likelihood: 70 }),
735
- hashtag_count: chance.integer({ min: 1, max: 8 }),
736
- };
737
- userEvents.splice(idx + 1, 0, extraPost);
738
- }
739
- }
740
- if (hasCreatorSubscription && event.event === "story created") {
741
- for (let i = 0; i < 2; i++) {
742
- const extraStory = {
743
- ...event,
744
- time: eventTime.add(chance.integer({ min: 1, max: 8 }), 'hours').toISOString(),
745
- user_id: event.user_id,
746
- story_type: chance.pickone(["photo", "video", "text"]),
747
- has_filter: chance.bool({ likelihood: 60 }),
748
- has_sticker: chance.bool({ likelihood: 40 }),
749
- };
750
- userEvents.splice(idx + 1, 0, extraStory);
751
- }
752
- }
753
- if (hasCreatorSubscription && event.event === "post viewed") {
754
- if (chance.bool({ likelihood: 25 })) {
755
- const analyticsView = {
756
- ...event,
757
- time: eventTime.add(chance.integer({ min: 1, max: 30 }), 'minutes').toISOString(),
758
- user_id: event.user_id,
759
- post_type: event.post_type || "text",
760
- source: "profile",
761
- view_duration_sec: chance.integer({ min: 10, max: 60 }),
762
- };
763
- userEvents.splice(idx + 1, 0, analyticsView);
764
- }
765
- }
766
- }
767
-
768
- // Hook #8: WEEKEND CONTENT SURGE — duplicate weekend posts/stories with offset.
769
- // Discovery: line chart by day-of-week shows Sat/Sun bump.
770
- for (let idx = userEvents.length - 1; idx >= 0; idx--) {
771
- const event = userEvents[idx];
772
- if (event.event === "post created" || event.event === "story created") {
773
- const dow = new Date(event.time).getUTCDay();
774
- if ((dow === 0 || dow === 6) && chance.bool({ likelihood: 30 })) {
775
- const etime = dayjs(event.time);
776
- const dup = {
777
- ...event,
778
- time: etime.add(chance.integer({ min: 1, max: 3 }), 'hours').toISOString(),
779
- };
780
- userEvents.splice(idx + 1, 0, dup);
781
- }
782
- }
783
- }
784
-
785
- // Hook #3: ALGORITHM CHANGE — day 45 flips feed → explore on post viewed.
786
- // Hook #4: ENGAGEMENT BAIT — 20% of post-viewed events get crushed duration.
787
- // Hook #5: NOTIFICATION RE-ENGAGEMENT — after day 30, 30% of views → notification.
788
- // All three run AFTER injection passes so they apply to cloned events too.
789
- const ALGORITHM_CHANGE_DAY = datasetStart.add(45, 'days');
790
- const REENGAGEMENT_START = datasetStart.add(30, 'days');
791
- userEvents.forEach(e => {
792
- if (e.event === "post viewed") {
793
- const eventTime = dayjs(e.time);
794
-
795
- // Hook #3: Algorithm Change
796
- if (eventTime.isAfter(ALGORITHM_CHANGE_DAY)) {
797
- if (chance.bool({ likelihood: 70 })) {
798
- e.source = "explore";
799
- }
800
- } else {
801
- if (chance.bool({ likelihood: 70 })) {
802
- e.source = "feed";
803
- }
804
- }
805
-
806
- // Hook #4: Engagement Bait — 20% crushed view duration
807
- if (chance.bool({ likelihood: 20 })) {
808
- e.view_duration_sec = chance.integer({ min: 1, max: 5 });
809
- }
810
-
811
- // Hook #5: Notification Re-engagement (runs after #3 so can override)
812
- if (eventTime.isAfter(REENGAGEMENT_START) && chance.bool({ likelihood: 30 })) {
813
- e.source = "notification";
814
- }
815
- }
816
- });
817
-
818
- // Hook #7: TOXICITY CHURN — drop 60% of activity after day 30 for high reporters.
819
- // Discovery: cohort users with >=2 report-submitted events, observe retention drop.
820
- if (reportSubmittedCount >= 2) {
821
- const churnCutoff = datasetStart.add(30, 'days');
822
- for (let i = userEvents.length - 1; i >= 0; i--) {
823
- const evt = userEvents[i];
824
- if (dayjs(evt.time).isAfter(churnCutoff) && chance.bool({ likelihood: 60 })) {
825
- userEvents.splice(i, 1);
826
- }
827
- }
828
- }
829
-
830
- // Hook #9: POST-CREATED MAGIC NUMBER (no flags)
831
- // Sweet 3-7 posts → +40% on comment_length on the user's comment events.
832
- // Over 8+ → drop 30% of like/comment events (engagement burnout).
833
- if (postCreatedCount >= 3 && postCreatedCount <= 7) {
834
- userEvents.forEach(e => {
835
- if (e.event === 'comment posted' && typeof e.comment_length === 'number') {
836
- e.comment_length = Math.round(e.comment_length * 1.4);
837
- }
838
- });
839
- } else if (postCreatedCount >= 8) {
840
- userEvents.forEach(e => {
841
- if (e.event === 'comment posted' && typeof e.comment_length === 'number') {
842
- e.comment_length = Math.round(e.comment_length * 0.7);
843
- }
844
- });
845
- }
846
- }
847
-
897
+ hook(record, type, meta) {
898
+ if (type === "funnel-post") return handleFunnelPostHooks(record, meta);
899
+ if (type === "everything") return handleEverythingHooks(record, meta);
848
900
  return record;
849
901
  }
850
902
  };