@shadevkumar/agent-wrapped 0.2.0 → 0.3.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.
@@ -3,7 +3,7 @@
3
3
  // what gets saved as an image or a video.
4
4
  //
5
5
  // The same page plays two kinds of story: your own, built into the file on
6
- // your computer, and one someone shared, packed into the link after "#v1.".
6
+ // your computer, and one someone shared, packed into the link (see link.js).
7
7
 
8
8
  // ---------------------------------------------------------------- story data
9
9
 
@@ -38,6 +38,8 @@ if (SHARED) addEventListener("hashchange", () => location.reload());
38
38
  const D = OWN ?? (await openLink());
39
39
  if (!D) await new Promise(() => {}); // nothing to play; the page says why
40
40
  const YEAR = D.range?.to.slice(0, 4) ?? "";
41
+ // "My 2026 with AI agents", or "My month" for a story of the last 30 days.
42
+ const SPAN = D.period === "month" ? "month" : YEAR || "year";
41
43
 
42
44
  // The public page with no story in its link is the home page.
43
45
  async function openLink() {
@@ -48,7 +50,7 @@ async function openLink() {
48
50
  return null;
49
51
  }
50
52
  try {
51
- const d = await unpack(location.hash.replace(/^#v1\./, ""));
53
+ const d = await readLink(location.hash);
52
54
  if (typeof d?.prompts === "number" && typeof d.personality?.name === "string") {
53
55
  document.getElementById("player").hidden = false;
54
56
  return d;
@@ -62,7 +64,7 @@ async function openLink() {
62
64
  // "Watch Shadev's story" link plays, so the two always match. Everything it
63
65
  // uses lives inside it: it runs before the rest of the script.
64
66
  async function typeMoments() {
65
- const s = await unpack(document.getElementById("featured").hash.replace(/^#v1\./, ""));
67
+ const s = await readLink(document.getElementById("featured").hash);
66
68
  const n = (x) => x.toLocaleString("en-US");
67
69
  // The keys that differ from the right spelling stay lit.
68
70
  const wrong = (typed, word) => {
@@ -72,7 +74,7 @@ async function typeMoments() {
72
74
  // [what gets typed, which keys stay lit, what it is]
73
75
  const MOMENTS = [
74
76
  s.topTypo && [s.topTypo.spelling, wrong(s.topTypo.spelling, s.topTypo.word), `Shadev typed this ${n(s.topTypo.count)} times`],
75
- s.spellings && [s.spellings.spellings[0], wrong(s.spellings.spellings[0], s.spellings.word), `one of Shadev's ${s.spellings.spellings.length} ways to spell ${s.spellings.word}`],
77
+ s.spellings && [s.spellings.spellings[0], wrong(s.spellings.spellings[0], s.spellings.word), `one of Shadev's ${s.spellings.ways ?? s.spellings.spellings.length + 1} ways to spell ${s.spellings.word}`],
76
78
  s.topPrompts[0] && [s.topPrompts[0].text, [], "Shadev's most-sent prompt"],
77
79
  s.catchphrase && [s.catchphrase.text, [], `Shadev said this in ${n(s.catchphrase.sessions)} sessions`],
78
80
  s.night && [s.night.latest, [], "Shadev's latest prompt of the year"],
@@ -114,6 +116,15 @@ async function typeMoments() {
114
116
  }
115
117
  }
116
118
 
119
+ // "#v2." links hold the story's values only (link.js). Links shared before
120
+ // that, "#v1.", hold the whole story with its field names.
121
+ async function readLink(hash) {
122
+ const [, version, body] = hash.match(/^#v([12])\.(.+)$/) ?? [];
123
+ if (!body) return null;
124
+ const json = await unpack(body);
125
+ return version === "2" ? fromLink(json) : json;
126
+ }
127
+
117
128
  // JSON, compressed and written with link-safe characters.
118
129
  async function pack(data) {
119
130
  const stream = new Blob([JSON.stringify(data)]).stream().pipeThrough(new CompressionStream("deflate-raw"));
@@ -168,6 +179,7 @@ const fade = (t, at, dur = 0.45) => (REDUCED ? 1 : easeOut((t - at) / dur));
168
179
  const num = (n) => Math.round(n).toLocaleString("en-US");
169
180
  const day = (iso) =>
170
181
  new Date(`${iso}T12:00:00`).toLocaleDateString("en-US", { month: "short", day: "numeric" });
182
+ const month = (ym) => new Date(`${ym}-15T12:00:00`).toLocaleDateString("en-US", { month: "short" });
171
183
 
172
184
  function font(size, { family = "Newsreader", weight = 400, style = "normal" } = {}) {
173
185
  return `${style} ${weight} ${size}px "${family}"`;
@@ -187,6 +199,7 @@ function text(ctx, b, str, y, o = {}) {
187
199
  ctx.textBaseline = "alphabetic";
188
200
  const x = o.align === "center" ? b.x + b.w / 2 : o.align === "right" ? b.x + b.w : b.x;
189
201
  const lines = wrap(ctx, str, b.w);
202
+ if (!o.measure) countWords(str);
190
203
  if (!o.measure) lines.forEach((l, i) => ctx.fillText(l, x, y + size + i * lh));
191
204
  ctx.restore();
192
205
  return y + size + (lines.length - 1) * lh + size * 0.45;
@@ -276,6 +289,7 @@ function cap(ctx, cx, cy, w, h, label, o) {
276
289
  const total = o.lines.reduce((sum, l) => sum + l.size, 0) + gap * (o.lines.length - 1);
277
290
  let y = midY - total / 2;
278
291
  for (const l of o.lines) {
292
+ countWords(l.text);
279
293
  ctx.font = font(l.size, l);
280
294
  ctx.globalAlpha = (o.alpha ?? 1) * (l.alpha ?? 1);
281
295
  ctx.textAlign = o.left ? "left" : "center";
@@ -285,6 +299,7 @@ function cap(ctx, cx, cy, w, h, label, o) {
285
299
  ctx.globalAlpha = o.alpha ?? 1;
286
300
  }
287
301
  if (o.right) {
302
+ countWords(o.right.text);
288
303
  ctx.font = font(o.right.size, o.right);
289
304
  ctx.textAlign = "right";
290
305
  ctx.fillText(o.right.text, w - pad, midY);
@@ -350,12 +365,20 @@ function background(ctx) {
350
365
 
351
366
  // ---------------------------------------------------------------- sound
352
367
 
353
- // Synthesised clacks and a chime: no audio files, nothing downloaded.
368
+ // Synthesised keys, a chime and a lofi loop: no audio files, nothing downloaded.
369
+ // Keys and the chime sit in a small room; the music runs quietly underneath.
370
+ const LOFI = {
371
+ bpm: 72,
372
+ // One bar each, as MIDI notes: Fmaj7, Em7, Dm7, Cmaj7.
373
+ chords: [[53, 57, 60, 64], [52, 55, 59, 62], [50, 53, 57, 60], [48, 52, 55, 59]],
374
+ level: 0.17,
375
+ };
376
+ const hz = (note) => 440 * 2 ** ((note - 69) / 12);
377
+
354
378
  const Sound = {
355
379
  ctx: null,
356
380
  master: null,
357
381
  on: true,
358
- noise: null,
359
382
  init() {
360
383
  if (this.ctx) return;
361
384
  try {
@@ -363,58 +386,190 @@ const Sound = {
363
386
  } catch {
364
387
  return;
365
388
  }
366
- this.master = this.ctx.createGain();
389
+ const c = this.ctx;
390
+ this.master = c.createGain();
367
391
  this.master.gain.value = 0.55;
368
- this.master.connect(this.ctx.destination);
369
- const len = Math.floor(this.ctx.sampleRate * 0.05);
370
- this.noise = this.ctx.createBuffer(1, len, this.ctx.sampleRate);
371
- const data = this.noise.getChannelData(0);
372
- for (let i = 0; i < len; i++) data[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / len, 4);
392
+ this.master.connect(c.destination);
393
+ this.click = noise(c, 0.05, (i, n) => Math.pow(1 - i / n, 4));
394
+ this.hiss = noise(c, 0.4, () => 1);
395
+ // A short, dark room: decaying noise as its echo.
396
+ this.room = c.createConvolver();
397
+ this.room.buffer = noise(c, 1.4, (i, n) => Math.pow(1 - i / n, 3), 2);
398
+ const wet = c.createGain();
399
+ wet.gain.value = 0.22;
400
+ this.room.connect(wet).connect(this.master);
401
+ this.fx = c.createGain();
402
+ this.fx.connect(this.master);
403
+ this.fx.connect(this.room);
404
+ this.startMusic();
373
405
  },
374
406
  key() {
375
407
  if (!this.on || !this.ctx) return;
376
408
  const c = this.ctx;
377
409
  const now = c.currentTime;
378
410
  const src = c.createBufferSource();
379
- src.buffer = this.noise;
380
- src.playbackRate.value = 0.8 + Math.random() * 0.5;
381
- const band = c.createBiquadFilter();
382
- band.type = "bandpass";
383
- band.frequency.value = 1800 + Math.random() * 1400;
384
- band.Q.value = 1.2;
385
- const g = c.createGain();
386
- g.gain.value = 0.9;
387
- src.connect(band).connect(g).connect(this.master);
411
+ src.buffer = this.click;
412
+ src.playbackRate.value = 0.9 + Math.random() * 0.2;
413
+ const tone = c.createBiquadFilter();
414
+ tone.type = "lowpass";
415
+ tone.frequency.value = 2400 + Math.random() * 500;
416
+ const g = envelope(c, now, 0.42, 0.003, 0.06);
417
+ src.connect(tone).connect(g).connect(this.fx);
388
418
  src.start(now);
389
- // The low "thock" of the key bottoming out.
419
+ // The soft "thock" of the key bottoming out.
390
420
  const osc = c.createOscillator();
391
- const og = c.createGain();
392
- osc.frequency.setValueAtTime(190 + Math.random() * 40, now);
393
- osc.frequency.exponentialRampToValueAtTime(70, now + 0.05);
394
- og.gain.setValueAtTime(0.35, now);
395
- og.gain.exponentialRampToValueAtTime(0.001, now + 0.07);
396
- osc.connect(og).connect(this.master);
421
+ osc.frequency.setValueAtTime(165 + Math.random() * 20, now);
422
+ osc.frequency.exponentialRampToValueAtTime(62, now + 0.07);
423
+ osc.connect(envelope(c, now, 0.2, 0.004, 0.09)).connect(this.fx);
397
424
  osc.start(now);
398
- osc.stop(now + 0.08);
425
+ osc.stop(now + 0.12);
399
426
  },
400
427
  ding() {
401
428
  if (!this.on || !this.ctx) return;
402
429
  const c = this.ctx;
403
430
  const now = c.currentTime;
404
- for (const [f, v] of [[880, 0.22], [1320, 0.12], [1760, 0.06]]) {
431
+ for (const [f, v] of [[880, 0.13], [1320, 0.055], [1760, 0.022]]) {
405
432
  const osc = c.createOscillator();
406
- const g = c.createGain();
407
- osc.type = "sine";
408
433
  osc.frequency.value = f;
409
- g.gain.setValueAtTime(v, now);
410
- g.gain.exponentialRampToValueAtTime(0.0005, now + 1.1);
411
- osc.connect(g).connect(this.master);
434
+ osc.connect(envelope(c, now, v, 0.012, 1.4)).connect(this.fx);
412
435
  osc.start(now);
413
- osc.stop(now + 1.2);
436
+ osc.stop(now + 1.5);
437
+ }
438
+ },
439
+ // The Sound button turns the music down with the rest.
440
+ setOn(on) {
441
+ this.on = on;
442
+ if (!this.music) return;
443
+ const now = this.ctx.currentTime;
444
+ this.music.gain.cancelScheduledValues(now);
445
+ this.music.gain.setTargetAtTime(on ? LOFI.level : 0, now, 0.4);
446
+ },
447
+ startMusic() {
448
+ const c = this.ctx;
449
+ this.music = c.createGain();
450
+ this.music.gain.value = 0;
451
+ const warm = c.createBiquadFilter();
452
+ warm.type = "lowpass";
453
+ warm.frequency.value = 1500;
454
+ this.music.connect(warm).connect(this.master);
455
+ // Tape wobble: the piano drifts a few cents, slowly.
456
+ const wobble = c.createOscillator();
457
+ wobble.frequency.value = 0.33;
458
+ this.wobble = c.createGain();
459
+ this.wobble.gain.value = 7;
460
+ wobble.connect(this.wobble);
461
+ wobble.start();
462
+ // Vinyl crackle, looped.
463
+ const crackle = c.createBufferSource();
464
+ crackle.buffer = noise(c, 3, () => (Math.random() < 0.0007 ? 14 : 0.06));
465
+ crackle.loop = true;
466
+ const dust = c.createGain();
467
+ dust.gain.value = 0.05;
468
+ crackle.connect(dust).connect(this.music);
469
+ crackle.start();
470
+ this.beat = 0;
471
+ this.nextBeat = c.currentTime + 0.2;
472
+ // Notes are queued a little ahead. While paused the clock stops, and so does the queue.
473
+ setInterval(() => this.queue(), 100);
474
+ this.music.gain.setTargetAtTime(this.on ? LOFI.level : 0, c.currentTime, 1.2);
475
+ },
476
+ queue() {
477
+ const c = this.ctx;
478
+ const beat = 60 / LOFI.bpm;
479
+ // A tab in the background runs this late; pick up from now, not in a burst.
480
+ if (this.nextBeat < c.currentTime) this.nextBeat = c.currentTime + 0.05;
481
+ while (this.nextBeat < c.currentTime + 0.4) {
482
+ const t = this.nextBeat;
483
+ this.nextBeat += beat;
484
+ this.beat++;
485
+ if (!this.on) continue; // keeps time, so the loop comes back in step
486
+ const b = (this.beat - 1) % 16;
487
+ const chord = LOFI.chords[Math.floor(b / 4)];
488
+ if (b % 4 === 0) chord.forEach((note, i) => this.piano(note, t + i * 0.014, beat * 4));
489
+ if (b % 2 === 0) {
490
+ this.bass(chord[0] - 12, t, beat * 1.8);
491
+ this.kick(t);
492
+ } else this.snare(t);
493
+ this.hat(t, 0.02);
494
+ this.hat(t + beat * 0.6, 0.012); // swung: late, and softer
495
+ }
496
+ },
497
+ piano(note, t, len) {
498
+ const c = this.ctx;
499
+ const g = c.createGain();
500
+ g.gain.setValueAtTime(0, t);
501
+ g.gain.linearRampToValueAtTime(0.1, t + 0.02);
502
+ g.gain.exponentialRampToValueAtTime(0.03, t + 1.3);
503
+ g.gain.exponentialRampToValueAtTime(0.0008, t + len);
504
+ g.connect(this.music);
505
+ for (const [type, detune, level] of [["sine", -4, 1], ["triangle", 5, 0.3]]) {
506
+ const o = c.createOscillator();
507
+ o.type = type;
508
+ o.frequency.value = hz(note);
509
+ o.detune.value = detune;
510
+ this.wobble.connect(o.detune);
511
+ o.onended = () => this.wobble.disconnect(o.detune);
512
+ const og = c.createGain();
513
+ og.gain.value = level;
514
+ o.connect(og).connect(g);
515
+ o.start(t);
516
+ o.stop(t + len + 0.05);
414
517
  }
415
518
  },
519
+ bass(note, t, len) {
520
+ const o = this.ctx.createOscillator();
521
+ o.frequency.value = hz(note);
522
+ o.connect(envelope(this.ctx, t, 0.16, 0.02, len)).connect(this.music);
523
+ o.start(t);
524
+ o.stop(t + len + 0.05);
525
+ },
526
+ kick(t) {
527
+ const o = this.ctx.createOscillator();
528
+ o.frequency.setValueAtTime(110, t);
529
+ o.frequency.exponentialRampToValueAtTime(45, t + 0.16);
530
+ o.connect(envelope(this.ctx, t, 0.32, 0.004, 0.3)).connect(this.music);
531
+ o.start(t);
532
+ o.stop(t + 0.35);
533
+ },
534
+ snare(t) {
535
+ this.noiseHit(t, "bandpass", 1700, 0.07, 0.17);
536
+ },
537
+ hat(t, level) {
538
+ this.noiseHit(t, "highpass", 7000, level, 0.04);
539
+ },
540
+ noiseHit(t, type, frequency, level, decay) {
541
+ const c = this.ctx;
542
+ const src = c.createBufferSource();
543
+ src.buffer = this.hiss;
544
+ const f = c.createBiquadFilter();
545
+ f.type = type;
546
+ f.frequency.value = frequency;
547
+ src.connect(f).connect(envelope(c, t, level, 0.002, decay)).connect(this.music);
548
+ src.start(t);
549
+ src.stop(t + decay + 0.05);
550
+ },
416
551
  };
417
552
 
553
+ // A gain that rises to `peak` in `attack` seconds, then fades out by `end`.
554
+ function envelope(c, t, peak, attack, end) {
555
+ const g = c.createGain();
556
+ g.gain.setValueAtTime(0, t);
557
+ g.gain.linearRampToValueAtTime(peak, t + attack);
558
+ g.gain.exponentialRampToValueAtTime(0.0005, t + end);
559
+ return g;
560
+ }
561
+
562
+ // `seconds` of random noise, shaped by `shape(i, length)`.
563
+ function noise(c, seconds, shape, channels = 1) {
564
+ const n = Math.floor(c.sampleRate * seconds);
565
+ const buffer = c.createBuffer(channels, n, c.sampleRate);
566
+ for (let ch = 0; ch < channels; ch++) {
567
+ const data = buffer.getChannelData(ch);
568
+ for (let i = 0; i < n; i++) data[i] = (Math.random() * 2 - 1) * shape(i, n);
569
+ }
570
+ return buffer;
571
+ }
572
+
418
573
  // Fires sounds when playback crosses their moment, once per crossing.
419
574
  function effects(prev, t, live) {
420
575
  const crossed = (at) => live && prev < at && at <= t;
@@ -429,16 +584,30 @@ const SILENT = { key() {}, ding() {} };
429
584
 
430
585
  // Every part is drawn as draw(ctx, t, fx, cw, b): `b` is its box ({ x, w }),
431
586
  // and it starts at y = 0. The layout moves it into place afterwards.
587
+ // A card says when everything on it has appeared (`ready`), then stays long
588
+ // enough to read every word it draws at a relaxed pace.
589
+ const READING = 3.5; // words a second; some are read while the rest appear
590
+ let counted = null; // while set, text() and cap() add up the words they draw
591
+ function readTime(card) {
592
+ const c = document.createElement("canvas").getContext("2d");
593
+ counted = 0;
594
+ for (const part of [card.head, card.visual, card.words]) part?.(c, 1e6, SILENT, KEYS, shape.single);
595
+ const words = counted;
596
+ counted = null;
597
+ return card.ready + 1.5 + words / READING;
598
+ }
599
+ const countWords = (str) => counted !== null && (counted += String(str).split(/\s+/).filter(Boolean).length);
600
+
432
601
  function buildCards(D) {
433
602
  const cards = [];
434
- const add = (card) => cards.push({ cw: KEYS, ...card });
603
+ const add = (card) => cards.push({ cw: KEYS, ...card, dur: card.dur ?? readTime(card) });
435
604
  const chars = (s) => [...s];
436
605
  const narrow = (l) => l === "," || l === ":" || l === ".";
437
606
  const big = (size) => ({ family: "Geist", weight: 600, size });
438
607
  const say = (size = 50) => ({ size, style: "italic" });
439
608
 
440
609
  add({
441
- id: "intro", name: "Intro", dur: 6,
610
+ id: "intro", name: "Intro", ready: 2.6,
442
611
  alt: "Your agents have been talking about you.",
443
612
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, ["h", "e", "y"], 120, 210, t, 0.4, fx, cw, { step: 0.17 }),
444
613
  words(ctx, t, fx, cw, b) {
@@ -452,7 +621,7 @@ function buildCards(D) {
452
621
  });
453
622
 
454
623
  add({
455
- id: "prompts", name: "Prompts", dur: 6.5,
624
+ id: "prompts", name: "Prompts", ready: 2.3,
456
625
  alt: `You sent your agents ${num(D.prompts)} prompts over ${num(D.activeDays)} days.`,
457
626
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Prompts you sent us", 0, { ...say(54), color: cw.soft, alpha: fade(t, 0.2) }),
458
627
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(num(D.prompts)), 100, 168, t, 0.7, fx, cw, { narrow, step: 0.13 }),
@@ -462,10 +631,41 @@ function buildCards(D) {
462
631
  }),
463
632
  });
464
633
 
634
+ if (D.chapters) {
635
+ const list = D.chapters;
636
+ const months = (c) => (c.from === c.to ? month(c.from) : `${month(c.from)}–${month(c.to)}`);
637
+ const last = 0.6 + (list.length - 1) * 0.35;
638
+ add({
639
+ id: "chapters", name: "Chapters", ready: last + 1.3,
640
+ alt: `Your year in chapters: ${list.map((c) => `${months(c)}, ${c.name}`).join("; ")}.`,
641
+ head: (ctx, t, fx, cw, b) => text(ctx, b, "Your year in chapters", 0, { ...big(70), color: cw.ink }),
642
+ visual(ctx, t, fx, cw, b) {
643
+ // One text size for every row: the largest the longest name fits at.
644
+ const right = (c) => ({ text: months(c), size: 34, family: "Geist", weight: 400 });
645
+ const size = Math.min(
646
+ ...list.map((c) => {
647
+ const room = b.w - 100 - textWidth(ctx, right(c).text, 36, right(c));
648
+ return clamp((40 * room) / textWidth(ctx, c.name, 40, { family: "Geist", weight: 500 }), 26, 40);
649
+ }),
650
+ );
651
+ list.forEach((c, i) => {
652
+ const at = 0.6 + i * 0.35;
653
+ fx.key(at);
654
+ const local = REDUCED ? 9 : t - at;
655
+ if (local < 0) return;
656
+ const label = { text: c.name, size, family: "Geist", weight: 500 };
657
+ cap(ctx, b.x + b.w / 2, 70 + i * 160, b.w * easeOut(local / 0.5), 120, "", { ...cw, left: true, lines: [label], right: right(c), press: pressAt(local) });
658
+ });
659
+ },
660
+ words: (ctx, t, fx, cw, b) =>
661
+ text(ctx, b, "Named from a few words in each stretch, never your prompts.", 0, { size: 34, color: cw.faint, alpha: fade(t, last + 0.8) }),
662
+ });
663
+ }
664
+
465
665
  if (D.topTypo) {
466
666
  const tt = D.topTypo;
467
667
  add({
468
- id: "top-typo", name: "Top typo", dur: 6.5,
668
+ id: "top-typo", name: "Top typo", ready: 2.7,
469
669
  alt: `You typed ${tt.spelling} ${num(tt.count)} times. We read it as ${tt.word}.`,
470
670
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(tt.spelling), 120, 220, t, 0.4, fx, cw, { step: 0.16 }),
471
671
  words(ctx, t, fx, cw, b) {
@@ -478,12 +678,13 @@ function buildCards(D) {
478
678
  if (D.spellings) {
479
679
  const sp = D.spellings;
480
680
  const list = sp.spellings.slice(0, 24);
681
+ const ways = sp.ways ?? sp.spellings.length + 1; // older links have every spelling
481
682
  const each = clamp(5 / list.length, 0.14, 0.4);
482
683
  const t0 = 0.6;
483
684
  const settle = t0 + list.length * each;
484
685
  add({
485
- id: "spellings", name: "Spellings", dur: settle + 4,
486
- alt: `There are ${sp.spellings.length + 1} ways to spell ${sp.word}. You used all of them.`,
686
+ id: "spellings", name: "Spellings", ready: settle + 1.5,
687
+ alt: `There are ${ways} ways to spell ${sp.word}. You used all of them.`,
487
688
  head: (ctx, t, fx, cw, b) => text(ctx, b, `How you spell ${sp.word}`, 0, { ...big(70), color: cw.ink }),
488
689
  visual(ctx, t, fx, cw, b) {
489
690
  const i = REDUCED ? list.length : Math.floor((t - t0) / each);
@@ -506,7 +707,7 @@ function buildCards(D) {
506
707
  words(ctx, t, fx, cw, b) {
507
708
  // Drawn invisibly before it settles, so the layout keeps its place.
508
709
  const a = t >= settle || REDUCED ? 1 : 0;
509
- const y = text(ctx, b, `${sp.spellings.length + 1} ways to spell it.`, 0, {
710
+ const y = text(ctx, b, `${ways} ways to spell it.`, 0, {
510
711
  ...big(72), color: cw.ink, alpha: a * fade(t, settle + 0.2),
511
712
  });
512
713
  text(ctx, b, "We know, because you used all of them.", y + 16, { ...say(), color: cw.soft, alpha: a * fade(t, settle + 1) });
@@ -519,7 +720,7 @@ function buildCards(D) {
519
720
  const rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
520
721
  const taps = [1.4, 1.75, 2.1, 2.45];
521
722
  add({
522
- id: "slip", name: "Missed key", dur: 7,
723
+ id: "slip", name: "Missed key", ready: 3.3,
523
724
  alt: `You meant ${s.meant.toUpperCase()} and hit ${s.hit.toUpperCase()}, ${num(s.count)} times.`,
524
725
  head: (ctx, t, fx, cw, b) =>
525
726
  text(ctx, b, `You meant ${s.meant.toUpperCase()}.\nYou hit ${s.hit.toUpperCase()}.`, 0, { ...big(84), color: cw.ink }),
@@ -560,7 +761,7 @@ function buildCards(D) {
560
761
  const most = top[0].count;
561
762
  const last = 0.6 + (top.length - 1) * 0.35;
562
763
  add({
563
- id: "top-prompts", name: "Favourite prompts", dur: 6.5,
764
+ id: "top-prompts", name: "Favourite prompts", ready: last + 1,
564
765
  alt: `Your favourite things to say to us: ${top.map((p) => `${p.text}, ${p.count} times`).join("; ")}.`,
565
766
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Your favourite things to say to us", 0, { ...big(70), color: cw.ink }),
566
767
  visual(ctx, t, fx, cw, b) {
@@ -584,7 +785,7 @@ function buildCards(D) {
584
785
  if (D.catchphrase) {
585
786
  const c = D.catchphrase;
586
787
  add({
587
- id: "catchphrase", name: "Catchphrase", dur: 6,
788
+ id: "catchphrase", name: "Catchphrase", ready: 2.1,
588
789
  alt: `Your catchphrase: ${c.text}. You said it in ${c.sessions} different sessions.`,
589
790
  head(ctx, t, fx, cw, b) {
590
791
  fx.ding(0.5);
@@ -608,7 +809,7 @@ function buildCards(D) {
608
809
  k.checkIns >= 20 && `And you asked “okay?” ${num(k.checkIns)} times.`,
609
810
  ].filter(Boolean);
610
811
  add({
611
- id: "talk", name: "How you talk", dur: 7,
812
+ id: "talk", name: "How you talk", ready: 2.2 + (lines.length - 1) * 0.8,
612
813
  alt: `How you talk to us. ${lines.join(" ")}`,
613
814
  head: (ctx, t, fx, cw, b) => text(ctx, b, "How you talk to us", 0, { ...say(54), color: cw.soft }),
614
815
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(word), 120, 210, t, 0.4, fx, cw, { step: 0.16 }),
@@ -624,7 +825,7 @@ function buildCards(D) {
624
825
  if (D.night) {
625
826
  const n = D.night;
626
827
  add({
627
- id: "night", name: "Late night", dur: 6.5,
828
+ id: "night", name: "Late night", ready: 2.3,
628
829
  alt: `Your latest prompt after midnight was at ${n.latest}. ${num(n.prompts)} prompts after midnight.`,
629
830
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Your latest prompt after midnight", 0, { ...say(54), color: cw.soft }),
630
831
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(n.latest), 110, 190, t, 0.6, fx, cw, { narrow, step: 0.15 }),
@@ -639,7 +840,7 @@ function buildCards(D) {
639
840
  const step = clamp(2.4 / shown, 0.04, 0.12);
640
841
  const end = 0.4 + shown * step;
641
842
  add({
642
- id: "streak", name: "Streak", dur: 4 + shown * step,
843
+ id: "streak", name: "Streak", ready: end + 1.2,
643
844
  alt: `${s.days} days in a row, ${day(s.from)} to ${day(s.to)}.`,
644
845
  visual(ctx, t, fx, cw, b) {
645
846
  const gap = 20;
@@ -667,11 +868,14 @@ function buildCards(D) {
667
868
 
668
869
  if (D.agents) {
669
870
  const a = D.agents;
670
- const parts = [["Codex", a.codex], ["Claude", a.claude]].filter(([, v]) => v > 0);
871
+ const parts = [["Codex", a.codex], ["Claude", a.claude], ["Cursor", a.cursor ?? 0]].filter(([, v]) => v > 0);
872
+ const split = ["", "", ", split between two of us", ", split between three of us"][parts.length];
873
+ // Cursor doesn't log how long it worked, so a Cursor-only year has no hours.
874
+ const title = a.hours >= 1 ? `${num(a.hours)} hours of work${split}.` : `Your prompts${split || ", all to one of us"}.`;
671
875
  add({
672
- id: "agents", name: "Your agents", dur: 6.5,
673
- alt: `${num(a.hours)} hours of agent work. Codex ${Math.round(a.codex * 100)} percent, Claude ${Math.round(a.claude * 100)} percent.`,
674
- head: (ctx, t, fx, cw, b) => text(ctx, b, `${num(a.hours)} hours of work, split between two of us.`, 0, { ...big(72), color: cw.ink }),
876
+ id: "agents", name: "Your agents", ready: 2.5,
877
+ alt: `${num(a.hours)} hours of agent work. ${parts.map(([name, share]) => `${name} ${Math.round(share * 100)} percent`).join(", ")}.`,
878
+ head: (ctx, t, fx, cw, b) => text(ctx, b, title, 0, { ...big(72), color: cw.ink }),
675
879
  visual(ctx, t, fx, cw, b) {
676
880
  parts.forEach(([name, share], i) => {
677
881
  const at = 0.7 + i * 0.4;
@@ -686,7 +890,7 @@ function buildCards(D) {
686
890
  },
687
891
  words: (ctx, t, fx, cw, b) =>
688
892
  a.bothDays > 0 &&
689
- text(ctx, b, `Some days you needed both of us. ${num(a.bothDays)} of them, to be exact.`, 0, {
893
+ text(ctx, b, `Some days you needed ${parts.length > 2 ? "more than one" : "both"} of us. ${num(a.bothDays)} of them, to be exact.`, 0, {
690
894
  ...say(), color: cw.soft, alpha: fade(t, 2),
691
895
  }),
692
896
  });
@@ -698,7 +902,7 @@ function buildCards(D) {
698
902
  const most = Math.max(...rows.map(([, n]) => n));
699
903
  const last = 0.6 + (rows.length - 1) * 0.35;
700
904
  add({
701
- id: "work", name: "What we did", dur: 7,
905
+ id: "work", name: "What we did", ready: last + 1.7,
702
906
  alt: `What we got done, since ${day(w.since)}: ${rows.map(([what, n]) => `${what}, ${num(n)} times`).join("; ")}.${w.languages.length ? ` Mostly in ${w.languages.join(" and ")}.` : ""}`,
703
907
  head: (ctx, t, fx, cw, b) => text(ctx, b, "What we got done", 0, { ...big(70), color: cw.ink }),
704
908
  visual(ctx, t, fx, cw, b) {
@@ -725,10 +929,58 @@ function buildCards(D) {
725
929
  });
726
930
  }
727
931
 
932
+ if (D.shipped) {
933
+ const s = D.shipped;
934
+ const tiles = [[s.pushes, s.pushes === 1 ? "push" : "pushes"], [s.prs, s.prs === 1 ? "pull request" : "pull requests"], [s.deploys, s.deploys === 1 ? "deploy" : "deploys"]]
935
+ .filter(([n]) => n > 0);
936
+ const week = s.biggestWeek;
937
+ const last = 0.6 + (tiles.length - 1) * 0.3;
938
+ add({
939
+ id: "shipped", name: "What you shipped", ready: last + (week ? 2 : 1.2),
940
+ alt: `What you shipped: ${tiles.map(([n, what]) => `${num(n)} ${what}`).join(", ")}.${week ? ` Your biggest week was ${day(week.from)} to ${day(week.to)}, with ${num(week.commits)} commits.` : ""}`,
941
+ head: (ctx, t, fx, cw, b) => text(ctx, b, "What you shipped", 0, { ...big(70), color: cw.ink }),
942
+ visual(ctx, t, fx, cw, b) {
943
+ const gap = 24;
944
+ const tw = (b.w - gap * (tiles.length - 1)) / tiles.length;
945
+ const valueFont = { family: "Geist", weight: 600 };
946
+ // Every tile gets as many label lines as the longest, so the numbers line up.
947
+ ctx.save();
948
+ ctx.font = font(32, { family: "Geist" });
949
+ const labels = tiles.map(([, what]) => wrap(ctx, what, tw - 70));
950
+ ctx.restore();
951
+ const rows = Math.max(...labels.map((l) => l.length));
952
+ for (const l of labels) while (l.length < rows) l.push(" ");
953
+ tiles.forEach(([n], i) => {
954
+ const at = 0.6 + i * 0.3;
955
+ fx.key(at);
956
+ const local = REDUCED ? 9 : t - at;
957
+ if (local < 0) return;
958
+ const value = num(n);
959
+ const size = Math.min(76, (76 * (tw - 70)) / textWidth(ctx, value, 76, valueFont));
960
+ const label = labels[i];
961
+ cap(ctx, b.x + i * (tw + gap) + tw / 2, 130, tw, 260, "", {
962
+ ...cw,
963
+ left: true,
964
+ pad: 35,
965
+ lines: [{ text: value, size, ...valueFont }, ...label.map((l) => ({ text: l, size: 32, family: "Geist", alpha: 0.6 }))],
966
+ scale: 0.85 + 0.15 * easeBack(local / 0.25),
967
+ press: pressAt(local),
968
+ });
969
+ });
970
+ },
971
+ words(ctx, t, fx, cw, b) {
972
+ const y = week
973
+ ? text(ctx, b, `Your biggest week: ${day(week.from)} to ${day(week.to)}, with ${num(week.commits)} commits.`, 0, { ...say(), color: cw.soft, alpha: fade(t, last + 0.6) }) + 20
974
+ : 0;
975
+ text(ctx, b, `From the commands your agents ran, since ${day(s.since)}.`, y, { size: 34, color: cw.faint, alpha: fade(t, last + (week ? 1.4 : 0.6)) });
976
+ },
977
+ });
978
+ }
979
+
728
980
  if (D.money) {
729
981
  const m = D.money;
730
982
  add({
731
- id: "money", name: "API value", dur: 7,
983
+ id: "money", name: "API value", ready: 3.1,
732
984
  alt: `At least ${num(m.atLeastUsd)} US dollars of agent work at public API prices.`,
733
985
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Our work, at public API prices", 0, { ...say(54), color: cw.soft }),
734
986
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(`$${num(m.atLeastUsd)}`), 100, 150, t, 0.6, fx, cw, { narrow, step: 0.12 }),
@@ -746,7 +998,7 @@ function buildCards(D) {
746
998
  const p = D.personality;
747
999
  const reveal = 2.2;
748
1000
  add({
749
- id: "personality", name: "Personality", dur: 8,
1001
+ id: "personality", name: "Personality", ready: reveal + 2.1,
750
1002
  alt: `You are ${p.name}. ${p.line}`,
751
1003
  head: (ctx, t, fx, cw, b) => text(ctx, b, "So, who are you?", 0, { ...say(54), color: cw.soft }),
752
1004
  visual(ctx, t, fx, cw, b) {
@@ -773,8 +1025,9 @@ function buildCards(D) {
773
1025
  });
774
1026
 
775
1027
  const letterWords = D.letter?.text.split(/\s+/).length;
1028
+ const perWord = 1 / (READING + 0.6); // it writes a little faster than you read, then waits for you
776
1029
  if (D.letter) add({
777
- id: "letter", name: "Letter", dur: Math.max(10, letterWords * 0.28 + 3),
1030
+ id: "letter", name: "Letter", dur: 0.6 + letterWords * perWord + 3.5,
778
1031
  alt: `A note from your agents: ${D.letter.text}`,
779
1032
  head: (ctx, t, fx, cw, b) => text(ctx, b, "A note from your agents", 0, { family: "Geist", weight: 600, size: 60, color: cw.ink }),
780
1033
  words(ctx, t, fx, cw, b) {
@@ -792,7 +1045,7 @@ function buildCards(D) {
792
1045
  ctx.stroke();
793
1046
  ctx.restore();
794
1047
  // Words appear at reading pace.
795
- const shown = REDUCED ? letterWords : Math.floor(clamp((t - 0.6) / 0.22, 0, letterWords));
1048
+ const shown = REDUCED ? letterWords : Math.floor(clamp((t - 0.6) / perWord, 0, letterWords));
796
1049
  let n = 0;
797
1050
  const visible = D.letter.text
798
1051
  .split(/(\s+)/)
@@ -809,10 +1062,10 @@ function buildCards(D) {
809
1062
  D.night ? [D.night.latest, "latest prompt after midnight"] : D.streak ? [`${D.streak.days} days`, "longest streak"] : null,
810
1063
  ].filter(Boolean);
811
1064
  add({
812
- id: "summary", name: "Summary", dur: 8,
1065
+ id: "summary", name: "Summary", ready: 0.7 + tiles.length * 0.25,
813
1066
  alt: `Summary: ${p.name}. ${num(D.prompts)} prompts.`,
814
1067
  head(ctx, t, fx, cw, b) {
815
- const y = text(ctx, b, `My ${YEAR || "year"} with AI agents`, 0, { ...say(), color: cw.soft });
1068
+ const y = text(ctx, b, `My ${SPAN} with AI agents`, 0, { ...say(), color: cw.soft });
816
1069
  text(ctx, b, p.name, y + 10, { family: "Geist", weight: 700, size: 92, color: cw.ink, lh: 1.05 });
817
1070
  },
818
1071
  visual(ctx, t, fx, cw, b) {
@@ -944,9 +1197,37 @@ function fitShape() {
944
1197
  frame.dataset.shape = shape === SHAPES.wide ? "wide" : "tall";
945
1198
  }
946
1199
 
947
- const state = { index: 0, started: 0, playing: false, holdPaused: false, pausedAt: 0, prevT: 0, mode: "player" };
1200
+ const state = { index: 0, started: 0, playing: false, paused: false, holding: false, pausedAt: 0, prevT: 0, mode: "player" };
1201
+
1202
+ // Pausing stops the card's clock and its sound where they are.
1203
+ const pauseBtn = document.getElementById("pause");
1204
+ function pause() {
1205
+ if (!state.playing || state.paused) return;
1206
+ state.paused = true;
1207
+ state.pausedAt = performance.now();
1208
+ Sound.ctx?.suspend();
1209
+ renderPause();
1210
+ }
1211
+ function resume() {
1212
+ if (!state.paused) return;
1213
+ state.started += performance.now() - state.pausedAt;
1214
+ state.paused = false;
1215
+ Sound.ctx?.resume();
1216
+ renderPause();
1217
+ }
1218
+ function renderPause() {
1219
+ pauseBtn.setAttribute("aria-pressed", String(state.paused));
1220
+ pauseBtn.setAttribute("aria-label", state.paused ? "Play" : "Pause");
1221
+ wake();
1222
+ }
948
1223
 
949
1224
  function show(index) {
1225
+ // Moving to another card plays it.
1226
+ if (state.paused) {
1227
+ state.paused = false;
1228
+ Sound.ctx?.resume();
1229
+ renderPause();
1230
+ }
950
1231
  state.index = clamp(index, 0, cards.length - 1);
951
1232
  state.started = performance.now();
952
1233
  state.prevT = -1;
@@ -954,7 +1235,7 @@ function show(index) {
954
1235
  }
955
1236
 
956
1237
  function elapsed(now) {
957
- return ((state.holdPaused ? state.pausedAt : now) - state.started) / 1000;
1238
+ return ((state.paused ? state.pausedAt : now) - state.started) / 1000;
958
1239
  }
959
1240
 
960
1241
  function tick(now) {
@@ -962,12 +1243,12 @@ function tick(now) {
962
1243
  const card = cards[state.index];
963
1244
  // Before play, the first card shows finished behind the start button.
964
1245
  const t = state.playing ? elapsed(now) : card.dur;
965
- paint(stage, card, t, effects(state.prevT, t, state.playing && !state.holdPaused));
1246
+ paint(stage, card, t, effects(state.prevT, t, state.playing && !state.paused));
966
1247
  state.prevT = t;
967
1248
  [...bars.children].forEach((bar, i) => {
968
1249
  bar.firstChild.style.width = `${i < state.index ? 100 : i > state.index ? 0 : clamp(t / card.dur) * 100}%`;
969
1250
  });
970
- if (state.playing && !state.holdPaused && t >= card.dur) {
1251
+ if (state.playing && !state.paused && t >= card.dur) {
971
1252
  if (state.index === cards.length - 1) openShare();
972
1253
  else show(state.index + 1);
973
1254
  }
@@ -986,21 +1267,21 @@ document.getElementById("play").addEventListener("click", () => {
986
1267
  show(0);
987
1268
  });
988
1269
 
989
- // Tap right side: next. Tap left: back. Press and hold: pause.
1270
+ // Tap right side: next. Tap left: back. Press and hold: pause until you let go.
990
1271
  let holdTimer = 0;
991
1272
  stage.addEventListener("pointerdown", () => {
992
- if (!state.playing) return;
1273
+ if (!state.playing || state.paused) return;
993
1274
  holdTimer = setTimeout(() => {
994
- state.holdPaused = true;
995
- state.pausedAt = performance.now();
1275
+ state.holding = true;
1276
+ pause();
996
1277
  }, 220);
997
1278
  });
998
1279
  stage.addEventListener("pointerup", (e) => {
999
1280
  if (!state.playing) return;
1000
1281
  clearTimeout(holdTimer);
1001
- if (state.holdPaused) {
1002
- state.started += performance.now() - state.pausedAt;
1003
- state.holdPaused = false;
1282
+ if (state.holding) {
1283
+ state.holding = false;
1284
+ resume();
1004
1285
  return;
1005
1286
  }
1006
1287
  const rect = stage.getBoundingClientRect();
@@ -1014,8 +1295,11 @@ addEventListener("keydown", (e) => {
1014
1295
  return;
1015
1296
  }
1016
1297
  if (!state.playing) return;
1017
- if (e.key === "ArrowRight" || e.key === " ") {
1298
+ if (e.key === " ") {
1018
1299
  e.preventDefault();
1300
+ if (state.paused) resume();
1301
+ else pause();
1302
+ } else if (e.key === "ArrowRight") {
1019
1303
  if (state.index === cards.length - 1) openShare();
1020
1304
  else show(state.index + 1);
1021
1305
  } else if (e.key === "ArrowLeft") show(state.index - 1);
@@ -1032,17 +1316,20 @@ const renderSoundBtn = () => {
1032
1316
  };
1033
1317
  renderSoundBtn();
1034
1318
  soundBtn.addEventListener("click", () => {
1035
- Sound.on = !Sound.on;
1319
+ Sound.setOn(!Sound.on);
1036
1320
  try {
1037
1321
  localStorage.setItem("agent-wrapped-sound", Sound.on ? "on" : "off");
1038
1322
  } catch {}
1039
1323
  renderSoundBtn();
1040
1324
  });
1325
+ pauseBtn.addEventListener("click", () => (state.paused ? resume() : pause()));
1326
+ // Leaving the tab pauses the story, so you come back to where you were.
1327
+ document.addEventListener("visibilitychange", () => document.hidden && state.mode === "player" && pause());
1041
1328
  document.getElementById("skip").addEventListener("click", openShare);
1042
1329
  document.getElementById("save-now").addEventListener("click", saveCurrent);
1043
1330
  if (SHARED) {
1044
1331
  document.getElementById("play").textContent = "Play the story";
1045
- document.getElementById("start-note").textContent = "A year with AI coding agents, wrapped. Sound on for the full effect.";
1332
+ document.getElementById("start-note").textContent = `A ${D.period === "month" ? "month" : "year"} with AI coding agents, wrapped. Sound on for the full effect.`;
1046
1333
  document.getElementById("skip").textContent = "Skip to the end";
1047
1334
  }
1048
1335
 
@@ -1052,7 +1339,8 @@ let idleTimer = 0;
1052
1339
  function wake() {
1053
1340
  player.classList.remove("idle");
1054
1341
  clearTimeout(idleTimer);
1055
- idleTimer = setTimeout(() => state.playing && state.mode === "player" && player.classList.add("idle"), 2200);
1342
+ // While paused the buttons stay, so Play is always in reach.
1343
+ idleTimer = setTimeout(() => state.playing && !state.paused && state.mode === "player" && player.classList.add("idle"), 2200);
1056
1344
  }
1057
1345
  for (const ev of ["pointermove", "pointerdown", "keydown"]) addEventListener(ev, wake);
1058
1346
 
@@ -1073,10 +1361,12 @@ const postLinkedIn = document.getElementById("post-linkedin");
1073
1361
 
1074
1362
  // Cards you can leave out, and the part of the story each one needs.
1075
1363
  const LEAVABLE = {
1076
- "top-typo": "topTypo", spellings: "spellings", slip: "slip", "top-prompts": "topPrompts", catchphrase: "catchphrase",
1077
- talk: "talk", night: "night", streak: "streak", agents: "agents", work: "work", money: "money", letter: "letter",
1364
+ chapters: "chapters", "top-typo": "topTypo", spellings: "spellings", slip: "slip", "top-prompts": "topPrompts", catchphrase: "catchphrase",
1365
+ talk: "talk", night: "night", streak: "streak", agents: "agents", work: "work", shipped: "shipped", money: "money", letter: "letter",
1078
1366
  };
1079
- const left = new Set(); // ids of the cards left out
1367
+ // ids of the cards left out. Chapters say what you worked on, so they stay
1368
+ // out of a link unless you add them.
1369
+ const left = new Set(["chapters"]);
1080
1370
  let link = "";
1081
1371
  let linkFor = 0; // ignores a slower, older link if the choice changed meanwhile
1082
1372
 
@@ -1087,7 +1377,7 @@ function sharedData() {
1087
1377
  return d;
1088
1378
  }
1089
1379
 
1090
- const shareText = (d) => `My ${YEAR || "year"} with AI coding agents, wrapped. I'm ${d.personality.name}.`;
1380
+ const shareText = (d) => `My ${SPAN} with AI coding agents, wrapped. I'm ${d.personality.name}.`;
1091
1381
 
1092
1382
  function finalFrame(card, s) {
1093
1383
  return withShape(s, () => {
@@ -1123,7 +1413,7 @@ async function renderShare() {
1123
1413
  const data = sharedData();
1124
1414
  preview.src = finalFrame(summaryCard(), shape).toDataURL("image/png");
1125
1415
  preview.dataset.shape = shapeName(shape);
1126
- const next = PLAYER_URL ? `${PLAYER_URL}#v1.${await pack(data)}` : "";
1416
+ const next = PLAYER_URL ? `${PLAYER_URL}#v2.${await pack(toLink(data))}` : "";
1127
1417
  if (mine !== linkFor) return;
1128
1418
  link = next;
1129
1419
  const url = encodeURIComponent(link);
@@ -1158,6 +1448,7 @@ function renderChoices() {
1158
1448
 
1159
1449
  // Your own story ends on sharing; a shared one ends on how to make your own.
1160
1450
  function openShare() {
1451
+ resume();
1161
1452
  state.mode = "share";
1162
1453
  clearTimeout(idleTimer);
1163
1454
  player.hidden = true;