@shadevkumar/agent-wrapped 0.1.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,16 +3,11 @@
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
 
10
- const PLAYER_URL = JSON.parse(document.getElementById("player-url").textContent);
11
- const OWN = JSON.parse(document.getElementById("data").textContent);
12
- const SHARED = !OWN;
13
- const D = OWN ?? (await openLink());
14
- if (!D) await new Promise(() => {}); // nothing to play; the page says why
15
- const YEAR = D.range?.to.slice(0, 4) ?? "";
10
+ const COMMAND = "npx @shadevkumar/agent-wrapped";
16
11
 
17
12
  const toast = document.getElementById("toast");
18
13
  let toastTimer = 0;
@@ -23,25 +18,39 @@ function notify(message, { stay = false } = {}) {
23
18
  if (!stay) toastTimer = setTimeout(() => toast.classList.remove("show"), 2800);
24
19
  }
25
20
 
26
- // Wired first: the home page has no story, so the script stops early there.
21
+ // Everything the home page needs is set up above the line where the script
22
+ // stops for a link with no story in it.
27
23
  for (const btn of document.querySelectorAll("[data-copy-command]")) btn.addEventListener("click", async () => {
28
24
  try {
29
- await navigator.clipboard.writeText("npx @shadevkumar/agent-wrapped");
30
- notify("Copied. Paste it into your terminal.");
25
+ await navigator.clipboard.writeText(COMMAND);
26
+ btn.textContent = "Copied";
27
+ setTimeout(() => (btn.textContent = "Copy"), 1800);
31
28
  } catch {
32
- notify("Couldn't copy it. Type npx @shadevkumar/agent-wrapped in your terminal.");
29
+ notify(`Couldn't copy it. Type ${COMMAND} in your terminal.`);
33
30
  }
34
31
  });
35
32
 
33
+ const PLAYER_URL = JSON.parse(document.getElementById("player-url").textContent);
34
+ const OWN = JSON.parse(document.getElementById("data").textContent);
35
+ const SHARED = !OWN;
36
+ // A new link in the same tab, like "Watch Shadev's story", starts over.
37
+ if (SHARED) addEventListener("hashchange", () => location.reload());
38
+ const D = OWN ?? (await openLink());
39
+ if (!D) await new Promise(() => {}); // nothing to play; the page says why
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";
43
+
36
44
  // The public page with no story in its link is the home page.
37
45
  async function openLink() {
38
46
  document.getElementById("player").hidden = true;
39
47
  if (!location.hash) {
40
48
  document.getElementById("home").hidden = false;
49
+ typeMoments();
41
50
  return null;
42
51
  }
43
52
  try {
44
- const d = await unpack(location.hash.replace(/^#v1\./, ""));
53
+ const d = await readLink(location.hash);
45
54
  if (typeof d?.prompts === "number" && typeof d.personality?.name === "string") {
46
55
  document.getElementById("player").hidden = false;
47
56
  return d;
@@ -51,6 +60,71 @@ async function openLink() {
51
60
  return null;
52
61
  }
53
62
 
63
+ // The home page's keys type moments from Shadev's story, the one its
64
+ // "Watch Shadev's story" link plays, so the two always match. Everything it
65
+ // uses lives inside it: it runs before the rest of the script.
66
+ async function typeMoments() {
67
+ const s = await readLink(document.getElementById("featured").hash);
68
+ const n = (x) => x.toLocaleString("en-US");
69
+ // The keys that differ from the right spelling stay lit.
70
+ const wrong = (typed, word) => {
71
+ const at = [...typed].flatMap((ch, i) => (ch === word[i] ? [] : [i]));
72
+ return typed.length === word.length ? at : at.slice(0, 1);
73
+ };
74
+ // [what gets typed, which keys stay lit, what it is]
75
+ const MOMENTS = [
76
+ s.topTypo && [s.topTypo.spelling, wrong(s.topTypo.spelling, s.topTypo.word), `Shadev typed this ${n(s.topTypo.count)} times`],
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}`],
78
+ s.topPrompts[0] && [s.topPrompts[0].text, [], "Shadev's most-sent prompt"],
79
+ s.catchphrase && [s.catchphrase.text, [], `Shadev said this in ${n(s.catchphrase.sessions)} sessions`],
80
+ s.night && [s.night.latest, [], "Shadev's latest prompt of the year"],
81
+ ].filter((m) => m && m[0].length <= 10);
82
+ const row = document.getElementById("home-keys");
83
+ const note = document.getElementById("home-note");
84
+ const wait = (ms) => new Promise((r) => setTimeout(r, ms));
85
+ const key = (ch) => {
86
+ const k = document.createElement("span");
87
+ k.className = ch === " " ? "key space" : "key";
88
+ k.textContent = ch;
89
+ return k;
90
+ };
91
+ const show = ([word, lit, what]) => {
92
+ row.replaceChildren(...[...word].map(key));
93
+ for (const i of lit) row.children[i].classList.add("lit");
94
+ note.textContent = what;
95
+ };
96
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) return show(MOMENTS[0]);
97
+ for (let m = 0; ; m = (m + 1) % MOMENTS.length) {
98
+ const [word, lit, what] = MOMENTS[m];
99
+ for (const [i, ch] of [...word].entries()) {
100
+ const k = row.appendChild(key(ch));
101
+ k.classList.add("down");
102
+ await wait(70);
103
+ k.classList.remove("down");
104
+ if (lit.includes(i)) k.classList.add("lit");
105
+ await wait(60 + Math.random() * 90);
106
+ }
107
+ note.textContent = what;
108
+ note.classList.add("show");
109
+ await wait(2600);
110
+ note.classList.remove("show");
111
+ while (row.lastChild) {
112
+ row.lastChild.remove();
113
+ await wait(38);
114
+ }
115
+ await wait(450);
116
+ }
117
+ }
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
+
54
128
  // JSON, compressed and written with link-safe characters.
55
129
  async function pack(data) {
56
130
  const stream = new Blob([JSON.stringify(data)]).stream().pipeThrough(new CompressionStream("deflate-raw"));
@@ -105,6 +179,7 @@ const fade = (t, at, dur = 0.45) => (REDUCED ? 1 : easeOut((t - at) / dur));
105
179
  const num = (n) => Math.round(n).toLocaleString("en-US");
106
180
  const day = (iso) =>
107
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" });
108
183
 
109
184
  function font(size, { family = "Newsreader", weight = 400, style = "normal" } = {}) {
110
185
  return `${style} ${weight} ${size}px "${family}"`;
@@ -124,6 +199,7 @@ function text(ctx, b, str, y, o = {}) {
124
199
  ctx.textBaseline = "alphabetic";
125
200
  const x = o.align === "center" ? b.x + b.w / 2 : o.align === "right" ? b.x + b.w : b.x;
126
201
  const lines = wrap(ctx, str, b.w);
202
+ if (!o.measure) countWords(str);
127
203
  if (!o.measure) lines.forEach((l, i) => ctx.fillText(l, x, y + size + i * lh));
128
204
  ctx.restore();
129
205
  return y + size + (lines.length - 1) * lh + size * 0.45;
@@ -213,6 +289,7 @@ function cap(ctx, cx, cy, w, h, label, o) {
213
289
  const total = o.lines.reduce((sum, l) => sum + l.size, 0) + gap * (o.lines.length - 1);
214
290
  let y = midY - total / 2;
215
291
  for (const l of o.lines) {
292
+ countWords(l.text);
216
293
  ctx.font = font(l.size, l);
217
294
  ctx.globalAlpha = (o.alpha ?? 1) * (l.alpha ?? 1);
218
295
  ctx.textAlign = o.left ? "left" : "center";
@@ -222,6 +299,7 @@ function cap(ctx, cx, cy, w, h, label, o) {
222
299
  ctx.globalAlpha = o.alpha ?? 1;
223
300
  }
224
301
  if (o.right) {
302
+ countWords(o.right.text);
225
303
  ctx.font = font(o.right.size, o.right);
226
304
  ctx.textAlign = "right";
227
305
  ctx.fillText(o.right.text, w - pad, midY);
@@ -269,7 +347,7 @@ function initials(name) {
269
347
  }
270
348
 
271
349
  function watermark(ctx, cw) {
272
- text(ctx, { x: 0, w: shape.W }, "made with npx @shadevkumar/agent-wrapped", shape.H - (shape === SHAPES.wide ? 84 : 124), {
350
+ text(ctx, { x: 0, w: shape.W }, `made with ${COMMAND}`, shape.H - (shape === SHAPES.wide ? 84 : 124), {
273
351
  family: "Geist", weight: 500, size: 26, color: cw.faint, align: "center",
274
352
  });
275
353
  }
@@ -287,12 +365,20 @@ function background(ctx) {
287
365
 
288
366
  // ---------------------------------------------------------------- sound
289
367
 
290
- // 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
+
291
378
  const Sound = {
292
379
  ctx: null,
293
380
  master: null,
294
381
  on: true,
295
- noise: null,
296
382
  init() {
297
383
  if (this.ctx) return;
298
384
  try {
@@ -300,58 +386,190 @@ const Sound = {
300
386
  } catch {
301
387
  return;
302
388
  }
303
- this.master = this.ctx.createGain();
389
+ const c = this.ctx;
390
+ this.master = c.createGain();
304
391
  this.master.gain.value = 0.55;
305
- this.master.connect(this.ctx.destination);
306
- const len = Math.floor(this.ctx.sampleRate * 0.05);
307
- this.noise = this.ctx.createBuffer(1, len, this.ctx.sampleRate);
308
- const data = this.noise.getChannelData(0);
309
- 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();
310
405
  },
311
406
  key() {
312
407
  if (!this.on || !this.ctx) return;
313
408
  const c = this.ctx;
314
409
  const now = c.currentTime;
315
410
  const src = c.createBufferSource();
316
- src.buffer = this.noise;
317
- src.playbackRate.value = 0.8 + Math.random() * 0.5;
318
- const band = c.createBiquadFilter();
319
- band.type = "bandpass";
320
- band.frequency.value = 1800 + Math.random() * 1400;
321
- band.Q.value = 1.2;
322
- const g = c.createGain();
323
- g.gain.value = 0.9;
324
- 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);
325
418
  src.start(now);
326
- // The low "thock" of the key bottoming out.
419
+ // The soft "thock" of the key bottoming out.
327
420
  const osc = c.createOscillator();
328
- const og = c.createGain();
329
- osc.frequency.setValueAtTime(190 + Math.random() * 40, now);
330
- osc.frequency.exponentialRampToValueAtTime(70, now + 0.05);
331
- og.gain.setValueAtTime(0.35, now);
332
- og.gain.exponentialRampToValueAtTime(0.001, now + 0.07);
333
- 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);
334
424
  osc.start(now);
335
- osc.stop(now + 0.08);
425
+ osc.stop(now + 0.12);
336
426
  },
337
427
  ding() {
338
428
  if (!this.on || !this.ctx) return;
339
429
  const c = this.ctx;
340
430
  const now = c.currentTime;
341
- 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]]) {
342
432
  const osc = c.createOscillator();
343
- const g = c.createGain();
344
- osc.type = "sine";
345
433
  osc.frequency.value = f;
346
- g.gain.setValueAtTime(v, now);
347
- g.gain.exponentialRampToValueAtTime(0.0005, now + 1.1);
348
- osc.connect(g).connect(this.master);
434
+ osc.connect(envelope(c, now, v, 0.012, 1.4)).connect(this.fx);
349
435
  osc.start(now);
350
- osc.stop(now + 1.2);
436
+ osc.stop(now + 1.5);
351
437
  }
352
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);
517
+ }
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
+ },
353
551
  };
354
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
+
355
573
  // Fires sounds when playback crosses their moment, once per crossing.
356
574
  function effects(prev, t, live) {
357
575
  const crossed = (at) => live && prev < at && at <= t;
@@ -366,16 +584,30 @@ const SILENT = { key() {}, ding() {} };
366
584
 
367
585
  // Every part is drawn as draw(ctx, t, fx, cw, b): `b` is its box ({ x, w }),
368
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
+
369
601
  function buildCards(D) {
370
602
  const cards = [];
371
- const add = (card) => cards.push({ cw: KEYS, ...card });
603
+ const add = (card) => cards.push({ cw: KEYS, ...card, dur: card.dur ?? readTime(card) });
372
604
  const chars = (s) => [...s];
373
605
  const narrow = (l) => l === "," || l === ":" || l === ".";
374
606
  const big = (size) => ({ family: "Geist", weight: 600, size });
375
607
  const say = (size = 50) => ({ size, style: "italic" });
376
608
 
377
609
  add({
378
- id: "intro", name: "Intro", dur: 6,
610
+ id: "intro", name: "Intro", ready: 2.6,
379
611
  alt: "Your agents have been talking about you.",
380
612
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, ["h", "e", "y"], 120, 210, t, 0.4, fx, cw, { step: 0.17 }),
381
613
  words(ctx, t, fx, cw, b) {
@@ -389,7 +621,7 @@ function buildCards(D) {
389
621
  });
390
622
 
391
623
  add({
392
- id: "prompts", name: "Prompts", dur: 6.5,
624
+ id: "prompts", name: "Prompts", ready: 2.3,
393
625
  alt: `You sent your agents ${num(D.prompts)} prompts over ${num(D.activeDays)} days.`,
394
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) }),
395
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 }),
@@ -399,10 +631,41 @@ function buildCards(D) {
399
631
  }),
400
632
  });
401
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
+
402
665
  if (D.topTypo) {
403
666
  const tt = D.topTypo;
404
667
  add({
405
- id: "top-typo", name: "Top typo", dur: 6.5,
668
+ id: "top-typo", name: "Top typo", ready: 2.7,
406
669
  alt: `You typed ${tt.spelling} ${num(tt.count)} times. We read it as ${tt.word}.`,
407
670
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(tt.spelling), 120, 220, t, 0.4, fx, cw, { step: 0.16 }),
408
671
  words(ctx, t, fx, cw, b) {
@@ -415,12 +678,13 @@ function buildCards(D) {
415
678
  if (D.spellings) {
416
679
  const sp = D.spellings;
417
680
  const list = sp.spellings.slice(0, 24);
681
+ const ways = sp.ways ?? sp.spellings.length + 1; // older links have every spelling
418
682
  const each = clamp(5 / list.length, 0.14, 0.4);
419
683
  const t0 = 0.6;
420
684
  const settle = t0 + list.length * each;
421
685
  add({
422
- id: "spellings", name: "Spellings", dur: settle + 4,
423
- 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.`,
424
688
  head: (ctx, t, fx, cw, b) => text(ctx, b, `How you spell ${sp.word}`, 0, { ...big(70), color: cw.ink }),
425
689
  visual(ctx, t, fx, cw, b) {
426
690
  const i = REDUCED ? list.length : Math.floor((t - t0) / each);
@@ -443,7 +707,7 @@ function buildCards(D) {
443
707
  words(ctx, t, fx, cw, b) {
444
708
  // Drawn invisibly before it settles, so the layout keeps its place.
445
709
  const a = t >= settle || REDUCED ? 1 : 0;
446
- 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, {
447
711
  ...big(72), color: cw.ink, alpha: a * fade(t, settle + 0.2),
448
712
  });
449
713
  text(ctx, b, "We know, because you used all of them.", y + 16, { ...say(), color: cw.soft, alpha: a * fade(t, settle + 1) });
@@ -456,7 +720,7 @@ function buildCards(D) {
456
720
  const rows = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
457
721
  const taps = [1.4, 1.75, 2.1, 2.45];
458
722
  add({
459
- id: "slip", name: "Missed key", dur: 7,
723
+ id: "slip", name: "Missed key", ready: 3.3,
460
724
  alt: `You meant ${s.meant.toUpperCase()} and hit ${s.hit.toUpperCase()}, ${num(s.count)} times.`,
461
725
  head: (ctx, t, fx, cw, b) =>
462
726
  text(ctx, b, `You meant ${s.meant.toUpperCase()}.\nYou hit ${s.hit.toUpperCase()}.`, 0, { ...big(84), color: cw.ink }),
@@ -497,7 +761,7 @@ function buildCards(D) {
497
761
  const most = top[0].count;
498
762
  const last = 0.6 + (top.length - 1) * 0.35;
499
763
  add({
500
- id: "top-prompts", name: "Favourite prompts", dur: 6.5,
764
+ id: "top-prompts", name: "Favourite prompts", ready: last + 1,
501
765
  alt: `Your favourite things to say to us: ${top.map((p) => `${p.text}, ${p.count} times`).join("; ")}.`,
502
766
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Your favourite things to say to us", 0, { ...big(70), color: cw.ink }),
503
767
  visual(ctx, t, fx, cw, b) {
@@ -521,7 +785,7 @@ function buildCards(D) {
521
785
  if (D.catchphrase) {
522
786
  const c = D.catchphrase;
523
787
  add({
524
- id: "catchphrase", name: "Catchphrase", dur: 6,
788
+ id: "catchphrase", name: "Catchphrase", ready: 2.1,
525
789
  alt: `Your catchphrase: ${c.text}. You said it in ${c.sessions} different sessions.`,
526
790
  head(ctx, t, fx, cw, b) {
527
791
  fx.ding(0.5);
@@ -535,10 +799,33 @@ function buildCards(D) {
535
799
  });
536
800
  }
537
801
 
802
+ if (D.talk) {
803
+ const k = D.talk;
804
+ const word = k.nickname?.word ?? "please";
805
+ const lines = [
806
+ k.nickname ? `You called us “${k.nickname.word}” ${num(k.nickname.count)} times.` : `You said please ${num(k.please)} times.`,
807
+ k.nickname && k.please + k.thanks > 0 && `Please ${num(k.please)} times. Thanks ${num(k.thanks)}.${k.thanks * 3 < k.please ? " We noticed." : ""}`,
808
+ !k.nickname && `And thanks ${num(k.thanks)} times.`,
809
+ k.checkIns >= 20 && `And you asked “okay?” ${num(k.checkIns)} times.`,
810
+ ].filter(Boolean);
811
+ add({
812
+ id: "talk", name: "How you talk", ready: 2.2 + (lines.length - 1) * 0.8,
813
+ alt: `How you talk to us. ${lines.join(" ")}`,
814
+ head: (ctx, t, fx, cw, b) => text(ctx, b, "How you talk to us", 0, { ...say(54), color: cw.soft }),
815
+ visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(word), 120, 210, t, 0.4, fx, cw, { step: 0.16 }),
816
+ words(ctx, t, fx, cw, b) {
817
+ let y = text(ctx, b, lines[0], 0, { ...big(72), color: cw.ink, alpha: fade(t, 1.4) });
818
+ lines.slice(1).forEach((line, i) => {
819
+ y = text(ctx, b, line, y + 18, { ...say(), color: cw.soft, alpha: fade(t, 2.2 + i * 0.8) });
820
+ });
821
+ },
822
+ });
823
+ }
824
+
538
825
  if (D.night) {
539
826
  const n = D.night;
540
827
  add({
541
- id: "night", name: "Late night", dur: 6.5,
828
+ id: "night", name: "Late night", ready: 2.3,
542
829
  alt: `Your latest prompt after midnight was at ${n.latest}. ${num(n.prompts)} prompts after midnight.`,
543
830
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Your latest prompt after midnight", 0, { ...say(54), color: cw.soft }),
544
831
  visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(n.latest), 110, 190, t, 0.6, fx, cw, { narrow, step: 0.15 }),
@@ -553,7 +840,7 @@ function buildCards(D) {
553
840
  const step = clamp(2.4 / shown, 0.04, 0.12);
554
841
  const end = 0.4 + shown * step;
555
842
  add({
556
- id: "streak", name: "Streak", dur: 4 + shown * step,
843
+ id: "streak", name: "Streak", ready: end + 1.2,
557
844
  alt: `${s.days} days in a row, ${day(s.from)} to ${day(s.to)}.`,
558
845
  visual(ctx, t, fx, cw, b) {
559
846
  const gap = 20;
@@ -581,11 +868,14 @@ function buildCards(D) {
581
868
 
582
869
  if (D.agents) {
583
870
  const a = D.agents;
584
- 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"}.`;
585
875
  add({
586
- id: "agents", name: "Your agents", dur: 6.5,
587
- alt: `${num(a.hours)} hours of agent work. Codex ${Math.round(a.codex * 100)} percent, Claude ${Math.round(a.claude * 100)} percent.`,
588
- 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 }),
589
879
  visual(ctx, t, fx, cw, b) {
590
880
  parts.forEach(([name, share], i) => {
591
881
  const at = 0.7 + i * 0.4;
@@ -600,16 +890,97 @@ function buildCards(D) {
600
890
  },
601
891
  words: (ctx, t, fx, cw, b) =>
602
892
  a.bothDays > 0 &&
603
- 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, {
604
894
  ...say(), color: cw.soft, alpha: fade(t, 2),
605
895
  }),
606
896
  });
607
897
  }
608
898
 
899
+ if (D.work) {
900
+ const w = D.work;
901
+ const rows = [["ran your tests", w.tests], ["made commits", w.commits], ["got stopped by you", w.stops]].filter(([, n]) => n > 0);
902
+ const most = Math.max(...rows.map(([, n]) => n));
903
+ const last = 0.6 + (rows.length - 1) * 0.35;
904
+ add({
905
+ id: "work", name: "What we did", ready: last + 1.7,
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 ")}.` : ""}`,
907
+ head: (ctx, t, fx, cw, b) => text(ctx, b, "What we got done", 0, { ...big(70), color: cw.ink }),
908
+ visual(ctx, t, fx, cw, b) {
909
+ rows.forEach(([what, n], i) => {
910
+ const at = 0.6 + i * 0.35;
911
+ fx.key(at);
912
+ const local = REDUCED ? 9 : t - at;
913
+ if (local < 0) return;
914
+ const label = { text: what, size: 44, family: "Geist", weight: 500 };
915
+ const right = { text: `${num(n)}×`, size: 40, family: "Geist", weight: 400 };
916
+ const least = textWidth(ctx, label.text, 46, label) + textWidth(ctx, right.text, 46, right) + 140;
917
+ const width = Math.min(b.w, least + (b.w - least) * (n / most) * easeOut(local / 0.5));
918
+ cap(ctx, b.x + width / 2, 80 + i * 190, width, 140, "", { ...cw, left: true, lines: [label], right, press: pressAt(local) });
919
+ });
920
+ },
921
+ words(ctx, t, fx, cw, b) {
922
+ const y = w.languages.length
923
+ ? text(ctx, b, `Mostly in ${w.languages.join(" and ")}.`, 0, { ...say(), color: cw.soft, alpha: fade(t, last + 0.5) }) + 20
924
+ : 0;
925
+ text(ctx, b, `Counted from the logs your agents keep, since ${day(w.since)}.`, y, {
926
+ size: 34, color: cw.faint, alpha: fade(t, last + 1.2),
927
+ });
928
+ },
929
+ });
930
+ }
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
+
609
980
  if (D.money) {
610
981
  const m = D.money;
611
982
  add({
612
- id: "money", name: "API value", dur: 7,
983
+ id: "money", name: "API value", ready: 3.1,
613
984
  alt: `At least ${num(m.atLeastUsd)} US dollars of agent work at public API prices.`,
614
985
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Our work, at public API prices", 0, { ...say(54), color: cw.soft }),
615
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 }),
@@ -627,7 +998,7 @@ function buildCards(D) {
627
998
  const p = D.personality;
628
999
  const reveal = 2.2;
629
1000
  add({
630
- id: "personality", name: "Personality", dur: 8,
1001
+ id: "personality", name: "Personality", ready: reveal + 2.1,
631
1002
  alt: `You are ${p.name}. ${p.line}`,
632
1003
  head: (ctx, t, fx, cw, b) => text(ctx, b, "So, who are you?", 0, { ...say(54), color: cw.soft }),
633
1004
  visual(ctx, t, fx, cw, b) {
@@ -654,8 +1025,9 @@ function buildCards(D) {
654
1025
  });
655
1026
 
656
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
657
1029
  if (D.letter) add({
658
- id: "letter", name: "Letter", dur: Math.max(10, letterWords * 0.28 + 3),
1030
+ id: "letter", name: "Letter", dur: 0.6 + letterWords * perWord + 3.5,
659
1031
  alt: `A note from your agents: ${D.letter.text}`,
660
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 }),
661
1033
  words(ctx, t, fx, cw, b) {
@@ -673,7 +1045,7 @@ function buildCards(D) {
673
1045
  ctx.stroke();
674
1046
  ctx.restore();
675
1047
  // Words appear at reading pace.
676
- 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));
677
1049
  let n = 0;
678
1050
  const visible = D.letter.text
679
1051
  .split(/(\s+)/)
@@ -690,10 +1062,10 @@ function buildCards(D) {
690
1062
  D.night ? [D.night.latest, "latest prompt after midnight"] : D.streak ? [`${D.streak.days} days`, "longest streak"] : null,
691
1063
  ].filter(Boolean);
692
1064
  add({
693
- id: "summary", name: "Summary", dur: 8,
1065
+ id: "summary", name: "Summary", ready: 0.7 + tiles.length * 0.25,
694
1066
  alt: `Summary: ${p.name}. ${num(D.prompts)} prompts.`,
695
1067
  head(ctx, t, fx, cw, b) {
696
- 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 });
697
1069
  text(ctx, b, p.name, y + 10, { family: "Geist", weight: 700, size: 92, color: cw.ink, lh: 1.05 });
698
1070
  },
699
1071
  visual(ctx, t, fx, cw, b) {
@@ -825,9 +1197,37 @@ function fitShape() {
825
1197
  frame.dataset.shape = shape === SHAPES.wide ? "wide" : "tall";
826
1198
  }
827
1199
 
828
- 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
+ }
829
1223
 
830
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
+ }
831
1231
  state.index = clamp(index, 0, cards.length - 1);
832
1232
  state.started = performance.now();
833
1233
  state.prevT = -1;
@@ -835,7 +1235,7 @@ function show(index) {
835
1235
  }
836
1236
 
837
1237
  function elapsed(now) {
838
- return ((state.holdPaused ? state.pausedAt : now) - state.started) / 1000;
1238
+ return ((state.paused ? state.pausedAt : now) - state.started) / 1000;
839
1239
  }
840
1240
 
841
1241
  function tick(now) {
@@ -843,12 +1243,12 @@ function tick(now) {
843
1243
  const card = cards[state.index];
844
1244
  // Before play, the first card shows finished behind the start button.
845
1245
  const t = state.playing ? elapsed(now) : card.dur;
846
- 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));
847
1247
  state.prevT = t;
848
1248
  [...bars.children].forEach((bar, i) => {
849
1249
  bar.firstChild.style.width = `${i < state.index ? 100 : i > state.index ? 0 : clamp(t / card.dur) * 100}%`;
850
1250
  });
851
- if (state.playing && !state.holdPaused && t >= card.dur) {
1251
+ if (state.playing && !state.paused && t >= card.dur) {
852
1252
  if (state.index === cards.length - 1) openShare();
853
1253
  else show(state.index + 1);
854
1254
  }
@@ -867,21 +1267,21 @@ document.getElementById("play").addEventListener("click", () => {
867
1267
  show(0);
868
1268
  });
869
1269
 
870
- // 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.
871
1271
  let holdTimer = 0;
872
1272
  stage.addEventListener("pointerdown", () => {
873
- if (!state.playing) return;
1273
+ if (!state.playing || state.paused) return;
874
1274
  holdTimer = setTimeout(() => {
875
- state.holdPaused = true;
876
- state.pausedAt = performance.now();
1275
+ state.holding = true;
1276
+ pause();
877
1277
  }, 220);
878
1278
  });
879
1279
  stage.addEventListener("pointerup", (e) => {
880
1280
  if (!state.playing) return;
881
1281
  clearTimeout(holdTimer);
882
- if (state.holdPaused) {
883
- state.started += performance.now() - state.pausedAt;
884
- state.holdPaused = false;
1282
+ if (state.holding) {
1283
+ state.holding = false;
1284
+ resume();
885
1285
  return;
886
1286
  }
887
1287
  const rect = stage.getBoundingClientRect();
@@ -895,8 +1295,11 @@ addEventListener("keydown", (e) => {
895
1295
  return;
896
1296
  }
897
1297
  if (!state.playing) return;
898
- if (e.key === "ArrowRight" || e.key === " ") {
1298
+ if (e.key === " ") {
899
1299
  e.preventDefault();
1300
+ if (state.paused) resume();
1301
+ else pause();
1302
+ } else if (e.key === "ArrowRight") {
900
1303
  if (state.index === cards.length - 1) openShare();
901
1304
  else show(state.index + 1);
902
1305
  } else if (e.key === "ArrowLeft") show(state.index - 1);
@@ -913,17 +1316,20 @@ const renderSoundBtn = () => {
913
1316
  };
914
1317
  renderSoundBtn();
915
1318
  soundBtn.addEventListener("click", () => {
916
- Sound.on = !Sound.on;
1319
+ Sound.setOn(!Sound.on);
917
1320
  try {
918
1321
  localStorage.setItem("agent-wrapped-sound", Sound.on ? "on" : "off");
919
1322
  } catch {}
920
1323
  renderSoundBtn();
921
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());
922
1328
  document.getElementById("skip").addEventListener("click", openShare);
923
1329
  document.getElementById("save-now").addEventListener("click", saveCurrent);
924
1330
  if (SHARED) {
925
1331
  document.getElementById("play").textContent = "Play the story";
926
- 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.`;
927
1333
  document.getElementById("skip").textContent = "Skip to the end";
928
1334
  }
929
1335
 
@@ -933,7 +1339,8 @@ let idleTimer = 0;
933
1339
  function wake() {
934
1340
  player.classList.remove("idle");
935
1341
  clearTimeout(idleTimer);
936
- 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);
937
1344
  }
938
1345
  for (const ev of ["pointermove", "pointerdown", "keydown"]) addEventListener(ev, wake);
939
1346
 
@@ -954,10 +1361,12 @@ const postLinkedIn = document.getElementById("post-linkedin");
954
1361
 
955
1362
  // Cards you can leave out, and the part of the story each one needs.
956
1363
  const LEAVABLE = {
957
- "top-typo": "topTypo", spellings: "spellings", slip: "slip", "top-prompts": "topPrompts", catchphrase: "catchphrase",
958
- night: "night", streak: "streak", agents: "agents", 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",
959
1366
  };
960
- 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"]);
961
1370
  let link = "";
962
1371
  let linkFor = 0; // ignores a slower, older link if the choice changed meanwhile
963
1372
 
@@ -968,7 +1377,7 @@ function sharedData() {
968
1377
  return d;
969
1378
  }
970
1379
 
971
- 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}.`;
972
1381
 
973
1382
  function finalFrame(card, s) {
974
1383
  return withShape(s, () => {
@@ -1004,7 +1413,7 @@ async function renderShare() {
1004
1413
  const data = sharedData();
1005
1414
  preview.src = finalFrame(summaryCard(), shape).toDataURL("image/png");
1006
1415
  preview.dataset.shape = shapeName(shape);
1007
- const next = PLAYER_URL ? `${PLAYER_URL}#v1.${await pack(data)}` : "";
1416
+ const next = PLAYER_URL ? `${PLAYER_URL}#v2.${await pack(toLink(data))}` : "";
1008
1417
  if (mine !== linkFor) return;
1009
1418
  link = next;
1010
1419
  const url = encodeURIComponent(link);
@@ -1039,6 +1448,7 @@ function renderChoices() {
1039
1448
 
1040
1449
  // Your own story ends on sharing; a shared one ends on how to make your own.
1041
1450
  function openShare() {
1451
+ resume();
1042
1452
  state.mode = "share";
1043
1453
  clearTimeout(idleTimer);
1044
1454
  player.hidden = true;