@shadevkumar/agent-wrapped 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Your life with AI coding agents, wrapped.
6
6
  npx @shadevkumar/agent-wrapped
7
7
  ```
8
8
 
9
- It reads your Claude Code, Codex and Cursor logs on your computer and turns them into a short animated story made of keyboard keys, with a quiet lofi loop underneath: your year in chapters, your most-typed typo, every way you've spelled "everything", the key you hit when you meant another, how you talk to your agents, your latest prompt after midnight, your streak, what your agents got done, what you shipped, and what all that work would cost at public API prices. It ends with your personality and a letter from your agents.
9
+ It reads your Claude Code, Codex and Cursor logs on your computer and turns them into a short animated story made of keyboard keys, with a quiet lofi loop underneath: your year in chapters, your most-typed typo, every way you've spelled "everything", the key you hit when you meant another, how you talk to your agents, your crashouts, your latest prompt after midnight, your streak, what your agents got done, what you shipped, and what all that work would cost at public API prices. It ends with your personality and a letter from your agents.
10
10
 
11
11
  It asks whether to cover everything so far or only the last 30 days. Each card stays up long enough to read it; press Space, the pause button, or press and hold to stop on one.
12
12
 
@@ -14,10 +14,10 @@ Then you share it. One link plays your whole story for anyone who opens it, keys
14
14
 
15
15
  ## What stays private
16
16
 
17
- Nothing is uploaded. The story is one HTML file written to your computer's temp folder and opened in your browser.
17
+ Nothing is uploaded unless you share. The story is one HTML file written to your computer's temp folder and opened in your browser.
18
18
 
19
19
  - **Your prompts never leave your computer.** The story only quotes everyday words. A quote with a name, a link, a file path, an email, a key or a word the dictionary doesn't know is left out, and so are your folder, repo and organisation names.
20
- - **Nothing is shared until you share it.** A share link carries your story inside it, after the `#`, which browsers never send to the server. So the public page that plays it never receives or stores your story. Anyone you give the link to can watch it.
20
+ - **Nothing is shared until you share it.** When you share, the site saves what's on your cards so the link can be short. Your prompts and logs never leave your computer. If the site can't be reached, you get a long link that carries the story inside it instead. Anyone you give the link to can watch it.
21
21
  - **You see the story before you share it,** and a card you leave out is not in the link at all.
22
22
  - **Your year in chapters** splits your year into stretches, each named from the everyday words that set it apart, found on your computer. Words that could be a person's or a private name are left out. Your `claude` command turns those few words into short names; it never sees a prompt. Chapters say what you worked on, so they are left out of a share link unless you add them. With `--no-ai`, a chapter is named by its top words.
23
23
  - **The letter** is written by your own `claude` command, if you have one. It gets your numbers and a few quotes that passed the same privacy check as the cards, never your prompts or logs. It doesn't save a session or load any project files. Run with `--no-ai` to use a template letter instead.
package/dist/build.js CHANGED
@@ -15,6 +15,7 @@ const PUBLIC_HEAD = `<meta name="description" content="A year with AI coding age
15
15
  <meta property="og:url" content="${PLAYER_URL}">
16
16
  <meta property="og:type" content="website">
17
17
  <meta name="twitter:card" content="summary_large_image">
18
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png">
18
19
  <link rel="preload" href="/fonts/geist-normal.woff2" as="font" type="font/woff2" crossorigin>
19
20
  <link rel="preload" href="/fonts/newsreader-italic.woff2" as="font" type="font/woff2" crossorigin>
20
21
  <script>
@@ -26,11 +27,11 @@ window.va("beforeSend", (event) => {
26
27
  });
27
28
  </script>
28
29
  <script defer src="/_vercel/insights/script.js"></script>`;
29
- // On the public page with no story in its link, the home page shows as soon
30
- // as its title's font is in, without waiting for the page's script to run,
31
- // and never shows its boxes before its words.
30
+ // On the public page with no story in its link (no #code, not /s/<name>),
31
+ // the home page shows as soon as its title's font is in, without waiting for
32
+ // the page's script to run, and never shows its boxes before its words.
32
33
  const HOME_FIRST = `<script>
33
- if (!location.hash) {
34
+ if (!location.hash && !location.pathname.startsWith("/s/")) {
34
35
  document.documentElement.classList.add("home");
35
36
  document.fonts.load("480 1em Geist").finally(() => document.documentElement.classList.add("fonts-in"));
36
37
  }
package/dist/files.js CHANGED
@@ -3,10 +3,8 @@ import { basename, join } from "node:path";
3
3
  // Parse a JSONL file, skipping malformed lines. A missing file is empty.
4
4
  // `keep` skips decoding lines that can't matter, which is most of a big log.
5
5
  export function readJsonl(path, keep) {
6
- if (!existsSync(path))
7
- return [];
8
6
  const rows = [];
9
- for (const line of readFileSync(path, "utf8").split("\n")) {
7
+ for (const line of linesOf(path)) {
10
8
  if (!line.trim() || (keep && !keep(line)))
11
9
  continue;
12
10
  try {
@@ -60,6 +58,47 @@ export function lastJsonLine(path, needle, accept) {
60
58
  closeSync(fd);
61
59
  }
62
60
  }
61
+ // The first line containing `needle` that parses and passes `accept`.
62
+ export function firstJsonLine(path, needle, accept) {
63
+ for (const line of linesOf(path)) {
64
+ if (!line.includes(needle))
65
+ continue;
66
+ try {
67
+ const row = JSON.parse(line);
68
+ if (row && accept(row))
69
+ return row;
70
+ }
71
+ catch {
72
+ // A malformed line; keep looking.
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+ // A file's lines, read from the start a chunk at a time, so a log of any size
78
+ // fits in memory: Node can't hold more than about 512 MB as one string.
79
+ function* linesOf(path) {
80
+ if (!existsSync(path))
81
+ return;
82
+ const fd = openSync(path, "r");
83
+ try {
84
+ const chunk = 1 << 20;
85
+ const size = fstatSync(fd).size;
86
+ let rest = Buffer.alloc(0);
87
+ for (let at = 0; at < size; at += chunk) {
88
+ const buf = Buffer.alloc(Math.min(chunk, size - at));
89
+ readSync(fd, buf, 0, buf.length, at);
90
+ const data = Buffer.concat([rest, buf]);
91
+ // A line cut at the chunk edge waits for the next read. Split on bytes,
92
+ // so a character cut in half is never decoded.
93
+ const end = at + buf.length >= size ? data.length : data.lastIndexOf(0x0a) + 1;
94
+ yield* data.subarray(0, end).toString("utf8").split("\n");
95
+ rest = data.subarray(end);
96
+ }
97
+ }
98
+ finally {
99
+ closeSync(fd);
100
+ }
101
+ }
63
102
  export function readJson(path) {
64
103
  if (!existsSync(path))
65
104
  return null;
package/dist/letter.js CHANGED
@@ -6,12 +6,14 @@ Write a short letter from their agents to them. Rules:
6
6
  - Use two or three of the facts given, quoting their words exactly as given.
7
7
  - Never invent numbers, names, projects or events that are not in the facts.
8
8
  - End with a short sign-off line from "your agents".`;
9
+ // "02:34" -> "2:34 AM". Late-night times run from midnight to 5 AM.
10
+ export const clock = (hhmm) => `${Number(hhmm.slice(0, 2)) % 12 || 12}:${hhmm.slice(3)} AM`;
9
11
  export function factsFor(w, p, span = "year") {
10
12
  const facts = [
11
13
  span === "month" ? "This story covers only their last 30 days." : "This story covers their year so far.",
12
14
  `Their personality: ${p.name}. ${p.line}`,
13
15
  `${w.totals.prompts} prompts over ${w.totals.activeDays} days; their agents worked ${Math.round(w.totals.agentHours)} hours.`,
14
- w.rhythm.lateNight.latest ? `Latest prompt after midnight: ${w.rhythm.lateNight.latest}.` : "",
16
+ w.rhythm.lateNight.latest ? `Latest they were still prompting, after midnight: ${clock(w.rhythm.lateNight.latest)}.` : "",
15
17
  w.rhythm.longestStreak ? `Longest streak: ${w.rhythm.longestStreak.days} days in a row.` : "",
16
18
  ...w.voice.topPrompts.slice(0, 3).map((t) => `They typed "${t.text}" ${t.count} times.`),
17
19
  ...w.voice.catchphrases.slice(0, 2).map((c) => `Catchphrase "${c.text}" in ${c.sessions} sessions.`),
@@ -44,7 +46,7 @@ export function templateLetter(w, p) {
44
46
  `${w.totals.prompts.toLocaleString("en-US")} prompts. We read every one.`,
45
47
  top ? `Some of them just said “${top.text}”. We got it every time.` : "",
46
48
  typo ? `We also know what “${typo.spellings[0]?.spelling}” means now. It means ${typo.word}.` : "",
47
- w.rhythm.lateNight.latest ? `See you at ${w.rhythm.lateNight.latest} again soon.` : "See you tomorrow.",
49
+ w.rhythm.lateNight.latest ? `See you at ${clock(w.rhythm.lateNight.latest)} again soon.` : "See you tomorrow.",
48
50
  "",
49
51
  `Yours, from the other side of the prompt, your agents`,
50
52
  ];
package/dist/moments.js CHANGED
@@ -20,6 +20,15 @@ const LEXICON = {
20
20
  wait: ["wait"],
21
21
  perfect: ["perfect", "great", "awesome", "nice"],
22
22
  };
23
+ const SWEARS = [
24
+ ["wtf", /\bwtf+\b/i],
25
+ ["fuck", /\bfu+ck\w*/i],
26
+ ["shit", /\bshit\w*/i],
27
+ ["damn", /\bdamn\w*/i],
28
+ ["ffs", /\bffs\b/i],
29
+ ["crap", /\bcrap\b/i],
30
+ ];
31
+ const TEMPER = /[!?]{3,}|\bwhy{3,}\b|\bwhat the hell\b|\bstill (not working|broken|failing|the same)\b|\bnot working again\b/i;
23
32
  const NICKNAMES = ["dude", "bro", "man", "buddy", "mate", "bhai", "boss", "chief", "fam"];
24
33
  const CHECK_IN = /\b(okay|ok|right)\s*\?/i;
25
34
  // File types that are code, by the language they're written in.
@@ -81,6 +90,7 @@ export function computeWrapped(h, words = new Words(h.privateNames)) {
81
90
  lexicon: lexicon(tokenized),
82
91
  nicknames: nicknames(tokenized),
83
92
  checkIns: prompts.filter((p) => CHECK_IN.test(p.text)).length,
93
+ crashouts: crashouts(prompts),
84
94
  },
85
95
  loyalty: {
86
96
  claudeShare: share(agents.claude.prompts, prompts.length),
@@ -89,7 +99,7 @@ export function computeWrapped(h, words = new Words(h.privateNames)) {
89
99
  bothAgentDays: bothAgentDays(prompts),
90
100
  },
91
101
  chapters: chapters(prompts, tokenized, words),
92
- work: work(h),
102
+ work: work(h, days.at(-1) ?? null),
93
103
  };
94
104
  }
95
105
  const MAX_CHAPTERS = 5;
@@ -148,6 +158,30 @@ function chapters(prompts, tokenized, words) {
148
158
  })
149
159
  .filter((c) => c.words.length >= 3);
150
160
  }
161
+ // Mostly capitals, with a few whole words in them: shouting, not an acronym.
162
+ function shouting(text) {
163
+ const letters = text.replace(/[^A-Za-z]/g, "");
164
+ const upper = letters.replace(/[^A-Z]/g, "").length;
165
+ return letters.length >= 12 && (text.match(/\b[A-Z]{3,}\b/g) ?? []).length >= 3 && upper / letters.length >= 0.7;
166
+ }
167
+ function crashouts(prompts) {
168
+ const perDay = new Map();
169
+ const swears = new Map();
170
+ let count = 0;
171
+ for (const p of prompts) {
172
+ const sworn = SWEARS.filter(([, re]) => re.test(p.text)).map(([word]) => word);
173
+ if (!sworn.length && !TEMPER.test(p.text) && !shouting(p.text))
174
+ continue;
175
+ count++;
176
+ const day = localDay(p.at);
177
+ perDay.set(day, (perDay.get(day) ?? 0) + 1);
178
+ for (const word of sworn)
179
+ swears.set(word, (swears.get(word) ?? 0) + 1);
180
+ }
181
+ const top = (m) => [...m].sort((a, b) => b[1] - a[1] || String(a[0]).localeCompare(String(b[0])))[0];
182
+ const worst = top(perDay);
183
+ return { count, worstDay: worst ? { day: worst[0], count: worst[1] } : null, word: top(swears)?.[0] ?? null };
184
+ }
151
185
  function nicknames(tokenized) {
152
186
  const counts = new Map(NICKNAMES.map((w) => [w, 0]));
153
187
  for (const toks of tokenized)
@@ -156,7 +190,7 @@ function nicknames(tokenized) {
156
190
  counts.set(w, counts.get(w) + 1);
157
191
  return [...counts].filter(([, n]) => n > 0).map(([word, count]) => ({ word, count })).sort((a, b) => b.count - a.count);
158
192
  }
159
- function work(h) {
193
+ function work(h, lastDay) {
160
194
  const count = (kind) => h.actions.filter((a) => a.kind === kind).length;
161
195
  const byLanguage = new Map();
162
196
  for (const a of h.actions) {
@@ -176,10 +210,11 @@ function work(h) {
176
210
  pushes: count("push"),
177
211
  prs: count("pr"),
178
212
  deploys: count("deploy"),
179
- biggestWeek: biggestWeek(h.actions.filter((a) => a.kind === "commit").map((a) => a.at)),
213
+ biggestWeek: biggestWeek(h.actions.filter((a) => a.kind === "commit").map((a) => a.at), lastDay),
180
214
  };
181
215
  }
182
- function biggestWeek(commits) {
216
+ // A week still going ends on the last day in the logs, never in the future.
217
+ function biggestWeek(commits, lastDay) {
183
218
  const weeks = new Map();
184
219
  for (const at of commits) {
185
220
  const monday = new Date(at.getFullYear(), at.getMonth(), at.getDate() - ((at.getDay() + 6) % 7), 12);
@@ -191,7 +226,8 @@ function biggestWeek(commits) {
191
226
  return null;
192
227
  const sunday = new Date(`${from}T12:00:00`);
193
228
  sunday.setDate(sunday.getDate() + 6);
194
- return { from, to: localDay(sunday), commits: n };
229
+ const to = localDay(sunday);
230
+ return { from, to: lastDay && lastDay < to && lastDay >= from ? lastDay : to, commits: n };
195
231
  }
196
232
  function agentStats(agent, h) {
197
233
  const prompts = h.prompts.filter((p) => p.agent === agent);
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readdirSync } from "node:fs";
2
2
  import { extname, join } from "node:path";
3
3
  import { DatabaseSync } from "node:sqlite";
4
- import { coverage, lastJsonLine, namesFromGitUrl, namesFromPath, toDate } from "../files.js";
4
+ import { coverage, firstJsonLine, lastJsonLine, namesFromGitUrl, namesFromPath, toDate } from "../files.js";
5
5
  import { commandKinds, emptyHarvest } from "../types.js";
6
6
  // Codex keeps, in ~/.codex:
7
7
  // - state_N.sqlite `threads`: one row per thread, with its token total
@@ -13,6 +13,7 @@ export function harvestCodex(home) {
13
13
  const root = join(home, ".codex");
14
14
  const h = emptyHarvest();
15
15
  const human = new Map(); // thread id -> started by a person
16
+ const forks = forkedThreads(root);
16
17
  const state = openLatest(root, "state");
17
18
  if (state) {
18
19
  try {
@@ -37,7 +38,7 @@ export function harvestCodex(home) {
37
38
  if (split) {
38
39
  h.usage.push({ agent: "codex", model, at, ...split });
39
40
  }
40
- else if (Number(t.tokens_used) > 0) {
41
+ else if (Number(t.tokens_used) > 0 && !forks.has(t.id)) {
41
42
  h.totals.push({ agent: "codex", model, at, tokens: Number(t.tokens_used) });
42
43
  }
43
44
  }
@@ -160,21 +161,48 @@ function messageText(json) {
160
161
  return "";
161
162
  }
162
163
  }
163
- // The thread's final running total. `input_tokens` includes cached tokens.
164
+ // A forked or resumed thread's running total starts from the total of the
165
+ // thread it came from, which is already counted there. Its own tokens are
166
+ // its final total less what it started with, before its first turn.
164
167
  function rolloutUsage(path) {
165
- const row = lastJsonLine(path, '"token_count"', (r) => r.type === "event_msg" && r.payload?.type === "token_count" && !!r.payload.info?.total_token_usage);
166
- const total = row?.payload.info.total_token_usage;
167
- if (!total)
168
+ const isCount = (r) => r.type === "event_msg" && r.payload?.type === "token_count" && !!r.payload.info?.total_token_usage;
169
+ const last = lastJsonLine(path, '"token_count"', isCount)?.payload.info;
170
+ if (!last)
168
171
  return null;
169
- const cached = total.cached_input_tokens ?? 0;
172
+ const first = firstJsonLine(path, '"token_count"', isCount)?.payload.info;
173
+ // `input_tokens` includes cached tokens.
174
+ const own = (key) => (last.total_token_usage[key] ?? 0) - (first.total_token_usage[key] ?? 0) + (first.last_token_usage?.[key] ?? first.total_token_usage[key] ?? 0);
175
+ const cached = own("cached_input_tokens");
170
176
  return {
171
- input: (total.input_tokens ?? 0) - cached,
177
+ input: own("input_tokens") - cached,
172
178
  cacheRead: cached,
173
- cacheWrite: total.cache_write_input_tokens ?? 0,
179
+ cacheWrite: own("cache_write_input_tokens"),
174
180
  cacheWrite1h: 0,
175
- output: total.output_tokens ?? 0,
181
+ output: own("output_tokens"),
176
182
  };
177
183
  }
184
+ // Threads forked from another, whose log starts with the other thread's
185
+ // history (their first item sits far into it). Their totals include the
186
+ // other thread's tokens, with no way left to tell how many, so a thread
187
+ // known only by its total is left unpriced: the cost stays a floor.
188
+ const FORKED_AFTER_ORDINAL = 100;
189
+ function forkedThreads(root) {
190
+ const history = openLatest(root, "thread_history");
191
+ if (!history)
192
+ return new Set();
193
+ try {
194
+ const rows = history
195
+ .prepare("select thread_id from thread_items group by thread_id having min(rollout_ordinal) > ?")
196
+ .all(FORKED_AFTER_ORDINAL);
197
+ return new Set(rows.map((r) => String(r.thread_id)));
198
+ }
199
+ catch {
200
+ return new Set();
201
+ }
202
+ finally {
203
+ history.close();
204
+ }
205
+ }
178
206
  // Codex numbers its database files (state_5.sqlite); open the newest, read-only.
179
207
  function openLatest(root, prefix) {
180
208
  if (!existsSync(root))
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
6
6
  <title>Agent Wrapped 2026</title>
7
- <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect x='4' y='6' width='56' height='54' rx='12' fill='%23131416'/%3E%3Crect x='6' y='4' width='52' height='50' rx='11' fill='%2336383D'/%3E%3Ctext x='32' y='38' font-family='system-ui,sans-serif' font-size='26' font-weight='600' fill='%23F1F1EF' text-anchor='middle'%3EAW%3C/text%3E%3C/svg%3E">
7
+ <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cdefs%3E%3ClinearGradient id='t' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%2334363C'/%3E%3Cstop offset='1' stop-color='%23141518'/%3E%3C/linearGradient%3E%3ClinearGradient id='k' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23FBFBF8'/%3E%3Cstop offset='1' stop-color='%23E2E2DD'/%3E%3C/linearGradient%3E%3ClinearGradient id='s' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0' stop-color='%23A9AAA6'/%3E%3Cstop offset='1' stop-color='%237C7D7A'/%3E%3C/linearGradient%3E%3Cfilter id='f' x='-30%25' y='-30%25' width='160%25' height='160%25'%3E%3CfeGaussianBlur stdDeviation='2.4'/%3E%3C/filter%3E%3C/defs%3E%3Crect width='64' height='64' rx='14' fill='url(%23t)'/%3E%3Crect x='.5' y='.5' width='63' height='63' rx='13.5' fill='none' stroke='%23fff' stroke-opacity='.08'/%3E%3Crect x='11' y='16' width='42' height='40' rx='9' fill='%23000' opacity='.5' filter='url(%23f)'/%3E%3Crect x='10' y='14' width='44' height='40' rx='9' fill='url(%23s)'/%3E%3Crect x='10' y='10' width='44' height='40' rx='9' fill='url(%23k)'/%3E%3Crect x='10.5' y='10.5' width='43' height='39' rx='8.5' fill='none' stroke='%23fff' stroke-opacity='.9'/%3E%3Cpath d='M40 21v10.5H23.5M29 25.5l-6 6 6 6' fill='none' stroke='%2325272B' stroke-width='3.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E">
8
8
  <!--HEAD-->
9
9
  <style>
10
10
  /*FONTS*/
@@ -250,13 +250,13 @@ html.home:not(.fonts-in) #home { visibility: hidden; }
250
250
  <img id="share-preview" alt="Your story's summary card">
251
251
  <div>
252
252
  <h1 id="share-title" tabindex="-1">Share your story</h1>
253
- <p class="lede">Anyone with the link can watch it play, keys and sound included. The story travels inside the link itself, so it isn't stored anywhere.</p>
253
+ <p class="lede">Anyone with the link can watch it play, keys and sound included. Sharing saves what's on these cards on agent-wrapped.shadev.space, so the link can be short. Nothing else from your logs leaves your computer.</p>
254
254
  <p class="note" id="offline" hidden>Share links turn on once the public player page is online. For now, save the video or the card.</p>
255
255
  <div class="row">
256
256
  <button class="primary" id="copy-link" data-needs-link>Copy link</button>
257
257
  <button id="share-link" hidden>Share</button>
258
- <a class="button" id="post-x" target="_blank" rel="noopener" data-needs-link>Post on X</a>
259
- <a class="button" id="post-linkedin" target="_blank" rel="noopener" data-needs-link>Post on LinkedIn</a>
258
+ <a class="button" id="post-x" href="#" data-needs-link>Post on X</a>
259
+ <a class="button" id="post-linkedin" href="#" data-needs-link>Post on LinkedIn</a>
260
260
  </div>
261
261
  <fieldset class="choices">
262
262
  <legend>Cards in your story. Tap one to leave it out of the link.</legend>
@@ -28,6 +28,7 @@ const FIELDS = [
28
28
  ["letter", ["text"]],
29
29
  "period",
30
30
  ["shipped", ["since", "pushes", "prs", "deploys", ["biggestWeek", ["from", "to", "commits"]]]],
31
+ ["crashouts", ["count", ["worstDay", ["day", "count"]], "word"]],
31
32
  ];
32
33
 
33
34
  export function toLink(data, fields = FIELDS) {
@@ -38,24 +38,31 @@ 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
+ const DAYS = D.range ? Math.round((new Date(D.range.to) - new Date(D.range.from)) / 86_400_000) + 1 : 0;
42
+ const SHORT = D.period !== "month" && DAYS > 0 && DAYS < 60; // logs that only go back a few weeks
43
+ // "My 2026 with AI agents", "My month" for a story of the last 30 days, or
44
+ // "My 17 days" when that's all the logs hold.
45
+ const SPAN = D.period === "month" ? "month" : SHORT ? `${DAYS} ${DAYS === 1 ? "day" : "days"}` : YEAR || "year";
43
46
 
44
47
  // The public page with no story in its link is the home page.
45
48
  async function openLink() {
46
49
  document.getElementById("player").hidden = true;
50
+ // A short link, /s/<name>: the site keeps its story.
51
+ const name = location.pathname.match(/^\/s\/([0-9A-Za-z]{10})$/)?.[1];
52
+ if (name) return playable(await fetch(`/api/share?name=${name}`).then((r) => (r.ok ? r.text() : "")).then((code) => readLink(`#${code}`)).catch(() => null));
47
53
  if (!location.hash) {
48
54
  document.getElementById("home").hidden = false;
49
55
  typeMoments();
50
56
  return null;
51
57
  }
52
- try {
53
- const d = await readLink(location.hash);
54
- if (typeof d?.prompts === "number" && typeof d.personality?.name === "string") {
55
- document.getElementById("player").hidden = false;
56
- return d;
57
- }
58
- } catch {}
58
+ return playable(await readLink(location.hash).catch(() => null));
59
+ }
60
+
61
+ function playable(d) {
62
+ if (typeof d?.prompts === "number" && typeof d.personality?.name === "string") {
63
+ document.getElementById("player").hidden = false;
64
+ return d;
65
+ }
59
66
  document.getElementById("missing").hidden = false;
60
67
  return null;
61
68
  }
@@ -66,6 +73,7 @@ async function openLink() {
66
73
  async function typeMoments() {
67
74
  const s = await readLink(document.getElementById("featured").hash);
68
75
  const n = (x) => x.toLocaleString("en-US");
76
+ const late = (hhmm) => `${Number(hhmm.slice(0, 2)) % 12 || 12}:${hhmm.slice(3)} AM`;
69
77
  // The keys that differ from the right spelling stay lit.
70
78
  const wrong = (typed, word) => {
71
79
  const at = [...typed].flatMap((ch, i) => (ch === word[i] ? [] : [i]));
@@ -77,7 +85,7 @@ async function typeMoments() {
77
85
  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
86
  s.topPrompts[0] && [s.topPrompts[0].text, [], "Shadev's most-sent prompt"],
79
87
  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"],
88
+ s.night && [late(s.night.latest), [], "how late Shadev was still prompting"],
81
89
  ].filter((m) => m && m[0].length <= 10);
82
90
  const row = document.getElementById("home-keys");
83
91
  const note = document.getElementById("home-note");
@@ -179,6 +187,8 @@ const fade = (t, at, dur = 0.45) => (REDUCED ? 1 : easeOut((t - at) / dur));
179
187
  const num = (n) => Math.round(n).toLocaleString("en-US");
180
188
  const day = (iso) =>
181
189
  new Date(`${iso}T12:00:00`).toLocaleDateString("en-US", { month: "short", day: "numeric" });
190
+ // "02:34" -> "2:34 AM". Late-night times run from midnight to 5 AM.
191
+ const clock = (hhmm) => `${Number(hhmm.slice(0, 2)) % 12 || 12}:${hhmm.slice(3)} AM`;
182
192
  const month = (ym) => new Date(`${ym}-15T12:00:00`).toLocaleDateString("en-US", { month: "short" });
183
193
 
184
194
  function font(size, { family = "Newsreader", weight = 400, style = "normal" } = {}) {
@@ -309,10 +319,14 @@ function cap(ctx, cx, cy, w, h, label, o) {
309
319
 
310
320
  const pressAt = (local) => (local >= 0 && local < 0.14 ? 1 - local / 0.14 : 0);
311
321
 
312
- // Types `labels` onto a row of caps centred in box `b`, one key every `step` seconds.
322
+ // Types `labels` onto a row of caps centred in box `b`, one key every `step`
323
+ // seconds. A `plain` label, like a comma or a colon, is typed between the
324
+ // keys without a key of its own.
313
325
  function typeRow(ctx, b, labels, cy, size, t, t0, fx, cw, o = {}) {
314
326
  const gap = size * 0.14;
315
- const widths = labels.map((l) => (o.narrow?.(l) ? size * 0.55 : size));
327
+ const glyph = { family: "Geist", weight: 500 };
328
+ const glyphSize = size * 0.4;
329
+ const widths = labels.map((l) => (o.plain?.(l) ? Math.max(size * 0.2, textWidth(ctx, l.trim(), glyphSize, glyph) + gap) : size));
316
330
  let total = widths.reduce((a, c) => a + c, 0) + gap * (labels.length - 1);
317
331
  const fit = Math.min(1, b.w / total);
318
332
  total *= fit;
@@ -323,7 +337,16 @@ function typeRow(ctx, b, labels, cy, size, t, t0, fx, cw, o = {}) {
323
337
  const at = t0 + i * step;
324
338
  fx.key(at);
325
339
  const local = REDUCED ? 9 : t - at;
326
- if (local >= 0) {
340
+ if (local >= 0 && o.plain?.(label)) {
341
+ ctx.save();
342
+ ctx.globalAlpha = clamp(local / 0.08);
343
+ ctx.fillStyle = cw.ink;
344
+ ctx.font = font(glyphSize * fit, glyph);
345
+ ctx.textAlign = "center";
346
+ ctx.textBaseline = "middle";
347
+ ctx.fillText(label.trim(), x + w / 2, cy - size * fit * 0.03);
348
+ ctx.restore();
349
+ } else if (local >= 0) {
327
350
  cap(ctx, x + w / 2, cy, w, size * fit, label, {
328
351
  ...cw,
329
352
  scale: 0.7 + 0.3 * easeBack(local / 0.2),
@@ -335,15 +358,341 @@ function typeRow(ctx, b, labels, cy, size, t, t0, fx, cw, o = {}) {
335
358
  });
336
359
  }
337
360
 
338
- // "The Midnight Foreman" -> "MF"
339
- function initials(name) {
340
- return name
341
- .replace(/^The /, "")
342
- .split(/[\s-]+/)
343
- .map((w) => w[0])
344
- .join("")
345
- .slice(0, 2)
346
- .toUpperCase();
361
+ // ---------------------------------------------------------------- personas
362
+
363
+ // Every personality is a character: the light key with a face, and props
364
+ // that loop. Drawn here, so it works offline and lands in saved cards.
365
+ // `box` is how far it reaches above and below its centre, in key sizes.
366
+ const loop = (t, period, offset = 0) => ((((t + offset) % period) + period) % period) / period;
367
+
368
+ function face(ctx, cx, cy, s, t, o = {}) {
369
+ const ey = cy - s * 0.1;
370
+ const r = s * 0.05;
371
+ const [lx, ly] = o.look ?? [0, 0];
372
+ const blink = !REDUCED && t % 3.4 > 3.28;
373
+ ctx.save();
374
+ ctx.fillStyle = ctx.strokeStyle = KEYS.plate;
375
+ ctx.lineWidth = s * 0.03;
376
+ ctx.lineCap = "round";
377
+ for (const side of [-1, 1]) {
378
+ const x = cx + side * s * 0.15 + lx * r * 0.6;
379
+ const y = ey + ly * r * 0.6;
380
+ const eyes = blink ? "closed" : o.eyes === "suspicious" ? (side < 0 ? "open" : "closed") : o.eyes ?? "open";
381
+ ctx.beginPath();
382
+ if (eyes === "focused") {
383
+ // Open eyes under brows angled down to the middle.
384
+ ctx.arc(x, y, r, 0, Math.PI * 2);
385
+ ctx.fill();
386
+ ctx.beginPath();
387
+ ctx.moveTo(x + side * r * 1.3, y - r * 2.3);
388
+ ctx.lineTo(x - side * r * 1.1, y - r * 1.5);
389
+ ctx.stroke();
390
+ } else if (eyes === "open") {
391
+ ctx.arc(x, y, r, 0, Math.PI * 2);
392
+ ctx.fill();
393
+ } else if (eyes === "sleepy") {
394
+ ctx.arc(x, y, r, 0, Math.PI);
395
+ ctx.fill();
396
+ } else if (eyes === "happy") {
397
+ ctx.arc(x, y + r * 0.6, r * 0.9, Math.PI * 1.15, Math.PI * 1.85);
398
+ ctx.stroke();
399
+ } else if (eyes === "squint") {
400
+ ctx.moveTo(x - r, y - side * r * 0.5);
401
+ ctx.lineTo(x + r, y + side * r * 0.5);
402
+ ctx.stroke();
403
+ } else {
404
+ ctx.moveTo(x - r, y);
405
+ ctx.lineTo(x + r, y);
406
+ ctx.stroke();
407
+ }
408
+ }
409
+ if (o.eyes === "suspicious") {
410
+ ctx.beginPath();
411
+ ctx.moveTo(cx - s * 0.22, ey - r * 2.2);
412
+ ctx.lineTo(cx - s * 0.08, ey - r * 1.6);
413
+ ctx.stroke();
414
+ }
415
+ const my = cy + s * 0.09;
416
+ ctx.beginPath();
417
+ if (o.mouth === "o") {
418
+ ctx.ellipse(cx, my, s * 0.04, s * 0.05, 0, 0, Math.PI * 2);
419
+ ctx.fill();
420
+ } else if (o.mouth === "flat") {
421
+ ctx.moveTo(cx - s * 0.06, my);
422
+ ctx.lineTo(cx + s * 0.06, my);
423
+ ctx.stroke();
424
+ } else {
425
+ ctx.arc(cx, my - s * 0.05, s * 0.08, Math.PI * 0.2, Math.PI * 0.8);
426
+ ctx.stroke();
427
+ }
428
+ ctx.restore();
429
+ }
430
+
431
+ const body = (ctx, cx, cy, s, o = {}) => cap(ctx, cx, cy, s, s, "", { ...LIT, ...o });
432
+
433
+ function fill(ctx, color, draw) {
434
+ ctx.fillStyle = color;
435
+ ctx.beginPath();
436
+ draw();
437
+ ctx.fill();
438
+ }
439
+
440
+ function glyph(ctx, str, x, y, size, alpha, color = KEYS.ink) {
441
+ ctx.save();
442
+ ctx.globalAlpha = clamp(alpha);
443
+ ctx.fillStyle = color;
444
+ ctx.font = font(size, { family: "Geist", weight: 700 });
445
+ ctx.textAlign = "center";
446
+ ctx.textBaseline = "middle";
447
+ ctx.fillText(str, x, y);
448
+ ctx.restore();
449
+ }
450
+
451
+ // The two agents you used most, most first.
452
+ const topAgents = (a) =>
453
+ [["Claude", a?.claude ?? 0], ["Codex", a?.codex ?? 0], ["Cursor", a?.cursor ?? 0]].sort((x, y) => y[1] - x[1]).slice(0, 2).map(([n]) => n);
454
+
455
+ const CHARACTERS = {
456
+ // A hard hat, half-shut eyes, the moon and a few z's.
457
+ "The Midnight Foreman": {
458
+ box: [-0.85, 0.55],
459
+ draw(ctx, cx, cy, s, t) {
460
+ const mx = cx + s * 0.78;
461
+ const my = cy - s * 0.55 + Math.sin(t * 1.2) * s * 0.03;
462
+ ctx.save();
463
+ ctx.beginPath();
464
+ ctx.rect(mx - s, my - s, s * 2, s * 2);
465
+ ctx.arc(mx + s * 0.06, my - s * 0.04, s * 0.11, 0, Math.PI * 2);
466
+ ctx.clip("evenodd");
467
+ fill(ctx, KEYS.ink, () => ctx.arc(mx, my, s * 0.13, 0, Math.PI * 2));
468
+ ctx.restore();
469
+ for (let i = 0; i < 3; i++) {
470
+ const p = loop(t, 2.4, i * 0.8);
471
+ glyph(ctx, "z", cx + s * (0.4 + p * 0.25), cy - s * (0.15 + p * 0.5), s * (0.1 + p * 0.08), Math.sin(p * Math.PI));
472
+ }
473
+ const y = cy + Math.sin(t * 1.5) * s * 0.015;
474
+ body(ctx, cx, y, s);
475
+ face(ctx, cx, y, s, t, { eyes: "sleepy", mouth: "flat" });
476
+ const top = y - s * 0.47;
477
+ fill(ctx, KEYS.soft, () => ctx.ellipse(cx, top + s * 0.02, s * 0.3, s * 0.24, 0, Math.PI, 0));
478
+ fill(ctx, KEYS.soft, () => ctx.roundRect(cx - s * 0.42, top - s * 0.01, s * 0.84, s * 0.07, s * 0.03));
479
+ fill(ctx, KEYS.cap, () => ctx.rect(cx - s * 0.03, top - s * 0.2, s * 0.06, s * 0.2));
480
+ },
481
+ },
482
+ // A beret and a megaphone that only ever says one word.
483
+ "The One-Word Director": {
484
+ box: [-0.7, 0.55],
485
+ draw(ctx, cx, cy, s, t) {
486
+ const p = loop(t, 1.4);
487
+ const shout = p < 0.45;
488
+ const x = cx - s * 0.2;
489
+ body(ctx, x, cy, s, { press: shout ? 0.3 : 0 });
490
+ face(ctx, x, cy, s, t, { mouth: shout ? "o" : "smile" });
491
+ ctx.save();
492
+ ctx.translate(x - s * 0.08, cy - s * 0.5);
493
+ ctx.rotate(-0.18);
494
+ fill(ctx, KEYS.soft, () => ctx.ellipse(0, 0, s * 0.34, s * 0.1, 0, 0, Math.PI * 2));
495
+ fill(ctx, KEYS.soft, () => ctx.rect(-s * 0.02, -s * 0.16, s * 0.04, s * 0.08));
496
+ ctx.restore();
497
+ const hx = x + s * 0.5;
498
+ const hy = cy + s * 0.08;
499
+ fill(ctx, KEYS.soft, () => {
500
+ ctx.moveTo(hx - s * 0.04, hy - s * 0.06);
501
+ ctx.lineTo(hx + s * 0.3, hy - s * 0.19);
502
+ ctx.lineTo(hx + s * 0.3, hy + s * 0.19);
503
+ ctx.lineTo(hx - s * 0.04, hy + s * 0.06);
504
+ });
505
+ glyph(ctx, "ok", hx + s * (0.46 + p * 0.3), hy, s * (0.15 + p * 0.12), 1 - p);
506
+ },
507
+ },
508
+ // Copies of itself slide out on either side: ⌘C, ⌘V.
509
+ "The Copy-Paste Architect": {
510
+ box: [-0.75, 0.55],
511
+ draw(ctx, cx, cy, s, t) {
512
+ const p = loop(t, 2.6);
513
+ const out = easeOut(clamp(p / 0.35)) * (1 - easeOut(clamp((p - 0.8) / 0.2)));
514
+ for (const [side, key] of [[-1, "⌘C"], [1, "⌘V"]]) {
515
+ const x = cx + side * s * 0.6 * out;
516
+ body(ctx, x, cy + s * 0.05, s * 0.8, { alpha: 0.45 * out });
517
+ ctx.save();
518
+ ctx.globalAlpha = 0.45 * out;
519
+ face(ctx, x, cy + s * 0.05, s * 0.8, t, { mouth: "smile" });
520
+ ctx.restore();
521
+ glyph(ctx, key, x + side * s * 0.12, cy - s * 0.6, s * 0.13, out);
522
+ }
523
+ body(ctx, cx, cy, s, { press: p < 0.12 ? 1 - p / 0.12 : 0 });
524
+ face(ctx, cx, cy, s, t, { eyes: "happy", mouth: "smile" });
525
+ },
526
+ },
527
+ // On fire, shaking, keys flying off.
528
+ "Fast Fingers": {
529
+ box: [-0.95, 0.55],
530
+ draw(ctx, cx, cy, s, t) {
531
+ for (let i = -1; i <= 1; i++) {
532
+ const h = s * (0.42 + 0.1 * Math.sin(t * 14 + i * 2)) * (i === 0 ? 1.3 : 0.9);
533
+ const x = cx + i * s * 0.2;
534
+ const base = cy - s * 0.36;
535
+ const tip = x + Math.sin(t * 9 + i) * s * 0.06;
536
+ const g = ctx.createLinearGradient(0, base, 0, base - h);
537
+ g.addColorStop(0, LIT.top);
538
+ g.addColorStop(0.55, "rgba(246,246,243,0.75)");
539
+ g.addColorStop(1, "rgba(246,246,243,0)");
540
+ fill(ctx, g, () => {
541
+ ctx.moveTo(x - s * 0.13, base);
542
+ ctx.quadraticCurveTo(x - s * 0.14, base - h * 0.55, tip, base - h);
543
+ ctx.quadraticCurveTo(x + s * 0.14, base - h * 0.55, x + s * 0.13, base);
544
+ });
545
+ }
546
+ ["f", "j", "d", "k"].forEach((label, i) => {
547
+ const p = loop(t, 1.1, i * 0.275);
548
+ const side = i % 2 ? 1 : -1;
549
+ const x = cx + side * s * (0.5 + p * 0.6);
550
+ const y = cy - s * 0.2 - Math.sin(p * Math.PI) * s * 0.45 + p * s * 0.35;
551
+ cap(ctx, x, y, s * 0.26, s * 0.26, label, { ...LIT, alpha: 1 - p * p });
552
+ });
553
+ const x = cx + (REDUCED ? 0 : Math.sin(t * 47) * s * 0.012);
554
+ body(ctx, x, cy, s, { press: (t * 7) % 1 < 0.3 ? 0.4 : 0 });
555
+ face(ctx, x, cy, s, t, { eyes: "focused", mouth: "smile" });
556
+ },
557
+ },
558
+ // A bow tie, and a top hat it tips to you.
559
+ "The Polite Commander": {
560
+ box: [-1.05, 0.55],
561
+ draw(ctx, cx, cy, s, t) {
562
+ const p = loop(t, 3);
563
+ const lift = Math.sin(clamp((p - 0.15) / 0.5) * Math.PI);
564
+ body(ctx, cx, cy, s);
565
+ face(ctx, cx, cy, s, t, { eyes: lift > 0.3 ? "happy" : "open", mouth: "smile" });
566
+ const by = cy + s * 0.27;
567
+ for (const side of [-1, 1]) {
568
+ fill(ctx, KEYS.plate, () => {
569
+ ctx.moveTo(cx, by);
570
+ ctx.lineTo(cx + side * s * 0.13, by - s * 0.07);
571
+ ctx.lineTo(cx + side * s * 0.13, by + s * 0.07);
572
+ });
573
+ }
574
+ fill(ctx, KEYS.plate, () => ctx.arc(cx, by, s * 0.03, 0, Math.PI * 2));
575
+ ctx.save();
576
+ ctx.translate(cx + s * 0.12 * lift, cy - s * 0.47 - s * 0.2 * lift);
577
+ ctx.rotate(0.35 * lift);
578
+ fill(ctx, KEYS.cap, () => ctx.roundRect(-s * 0.32, -s * 0.05, s * 0.64, s * 0.07, s * 0.03));
579
+ fill(ctx, KEYS.cap, () => ctx.roundRect(-s * 0.21, -s * 0.42, s * 0.42, s * 0.4, s * 0.03));
580
+ fill(ctx, KEYS.soft, () => ctx.rect(-s * 0.21, -s * 0.13, s * 0.42, s * 0.06));
581
+ ctx.restore();
582
+ },
583
+ },
584
+ // Under a swinging lamp, one eyebrow up, question marks all around.
585
+ "The Interrogator": {
586
+ box: [-1.1, 0.6],
587
+ draw(ctx, cx, cy, s, t) {
588
+ const a = Math.sin(t * 1.6) * 0.3;
589
+ const py = cy - s * 1.05;
590
+ const lx = cx + Math.sin(a) * s * 0.4;
591
+ const ly = py + Math.cos(a) * s * 0.4;
592
+ const light = ctx.createLinearGradient(0, ly, 0, cy + s * 0.55);
593
+ light.addColorStop(0, "rgba(255,255,255,0.22)");
594
+ light.addColorStop(1, "rgba(255,255,255,0)");
595
+ fill(ctx, light, () => {
596
+ ctx.moveTo(lx - s * 0.1, ly);
597
+ ctx.lineTo(lx + s * 0.1, ly);
598
+ ctx.lineTo(cx + s * 0.7 + Math.sin(a) * s * 0.5, cy + s * 0.55);
599
+ ctx.lineTo(cx - s * 0.7 + Math.sin(a) * s * 0.5, cy + s * 0.55);
600
+ });
601
+ ctx.save();
602
+ ctx.strokeStyle = KEYS.soft;
603
+ ctx.lineWidth = s * 0.015;
604
+ ctx.beginPath();
605
+ ctx.moveTo(cx, py);
606
+ ctx.lineTo(lx, ly);
607
+ ctx.stroke();
608
+ ctx.translate(lx, ly);
609
+ ctx.rotate(-a);
610
+ fill(ctx, KEYS.soft, () => {
611
+ ctx.moveTo(-s * 0.05, -s * 0.03);
612
+ ctx.lineTo(s * 0.05, -s * 0.03);
613
+ ctx.lineTo(s * 0.13, s * 0.08);
614
+ ctx.lineTo(-s * 0.13, s * 0.08);
615
+ });
616
+ ctx.restore();
617
+ body(ctx, cx, cy, s);
618
+ face(ctx, cx, cy, s, t, { eyes: "suspicious", mouth: "flat" });
619
+ [[-0.72, -0.2], [0.74, 0], [-0.64, 0.35]].forEach(([x, y], i) => {
620
+ const p = loop(t, 2.1, i * 0.7);
621
+ glyph(ctx, "?", cx + x * s, cy + y * s, s * (0.18 + p * 0.06), Math.sin(p * Math.PI));
622
+ });
623
+ },
624
+ },
625
+ // A sweatband, running on the spot.
626
+ "The Marathoner": {
627
+ box: [-0.6, 0.85],
628
+ draw(ctx, cx, cy, s, t) {
629
+ const stride = Math.sin(t * 9);
630
+ const y = cy - Math.abs(Math.cos(t * 9)) * s * 0.04;
631
+ const ground = cy + s * 0.8;
632
+ ctx.save();
633
+ ctx.strokeStyle = KEYS.faint;
634
+ ctx.lineWidth = s * 0.014;
635
+ ctx.lineCap = "round";
636
+ const span = s * 2.1;
637
+ for (let i = 0; i < 6; i++) {
638
+ const x = cx - span / 2 + ((((i * span) / 6 - t * s * 1.2) % span) + span) % span;
639
+ ctx.beginPath();
640
+ ctx.moveTo(x, ground);
641
+ ctx.lineTo(x + s * 0.14, ground);
642
+ ctx.stroke();
643
+ }
644
+ ctx.strokeStyle = KEYS.ink;
645
+ ctx.lineWidth = s * 0.045;
646
+ for (const side of [-1, 1]) {
647
+ const hx = cx + side * s * 0.14;
648
+ const hy = y + s * 0.4;
649
+ const ang = side * stride * 0.6;
650
+ const fx = hx + Math.sin(ang) * s * 0.34;
651
+ const fy = Math.min(ground - s * 0.03, hy + Math.cos(ang) * s * 0.34);
652
+ ctx.beginPath();
653
+ ctx.moveTo(hx, hy);
654
+ ctx.lineTo(fx, fy);
655
+ ctx.lineTo(fx + s * 0.08, fy);
656
+ ctx.stroke();
657
+ }
658
+ ctx.restore();
659
+ body(ctx, cx, y, s);
660
+ face(ctx, cx, y, s, t, { eyes: "squint", mouth: "o" });
661
+ fill(ctx, KEYS.cap, () => ctx.roundRect(cx - s * 0.48, y - s * 0.38, s * 0.96, s * 0.1, s * 0.02));
662
+ fill(ctx, KEYS.soft, () => ctx.rect(cx - s * 0.48, y - s * 0.345, s * 0.96, s * 0.025));
663
+ const p = loop(t, 1.3);
664
+ fill(ctx, `rgba(241,241,239,${1 - p})`, () => ctx.arc(cx + s * (0.55 + p * 0.3), cy - s * 0.25 + p * p * s * 0.4, s * 0.035, 0, Math.PI * 2));
665
+ },
666
+ },
667
+ // Juggling the two agents, eyes on whichever is up.
668
+ "The Two-Timer": {
669
+ box: [-1.05, 0.55],
670
+ draw(ctx, cx, cy, s, t) {
671
+ const at = topAgents(D.agents).map((name, i) => {
672
+ const a = loop(t, 1.8, i * 0.9) * Math.PI * 2;
673
+ return { name, x: cx + Math.cos(a) * s * 0.6, y: cy - s * 0.6 - Math.abs(Math.sin(a)) * s * 0.4 };
674
+ });
675
+ const up = at.reduce((hi, o) => (o.y < hi.y ? o : hi), at[0]);
676
+ body(ctx, cx, cy, s);
677
+ face(ctx, cx, cy, s, t, { look: [(up.x - cx) / (s * 0.6), -1], mouth: "smile" });
678
+ for (const o of at) cap(ctx, o.x, o.y, s * 0.46, s * 0.2, o.name, { ...KEYS, fontSize: s * 0.085 });
679
+ },
680
+ },
681
+ };
682
+
683
+ // Draws `name`'s character at (cx, cy), `s` wide, `t` seconds into its loop.
684
+ function character(ctx, name, cx, cy, s, t, scale = 1) {
685
+ const c = CHARACTERS[name];
686
+ ctx.save();
687
+ ctx.translate(cx, cy);
688
+ ctx.scale(scale, scale);
689
+ ctx.translate(-cx, -cy);
690
+ if (c) c.draw(ctx, cx, cy, s, REDUCED ? 1.2 : t);
691
+ else {
692
+ body(ctx, cx, cy, s);
693
+ face(ctx, cx, cy, s, t);
694
+ }
695
+ ctx.restore();
347
696
  }
348
697
 
349
698
  function watermark(ctx, cw) {
@@ -602,7 +951,7 @@ function buildCards(D) {
602
951
  const cards = [];
603
952
  const add = (card) => cards.push({ cw: KEYS, ...card, dur: card.dur ?? readTime(card) });
604
953
  const chars = (s) => [...s];
605
- const narrow = (l) => l === "," || l === ":" || l === ".";
954
+ const plain = (l) => l === "," || l === ":" || l === "." || l === " AM";
606
955
  const big = (size) => ({ family: "Geist", weight: 600, size });
607
956
  const say = (size = 50) => ({ size, style: "italic" });
608
957
 
@@ -624,7 +973,7 @@ function buildCards(D) {
624
973
  id: "prompts", name: "Prompts", ready: 2.3,
625
974
  alt: `You sent your agents ${num(D.prompts)} prompts over ${num(D.activeDays)} days.`,
626
975
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Prompts you sent us", 0, { ...say(54), color: cw.soft, alpha: fade(t, 0.2) }),
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 }),
976
+ visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(num(D.prompts)), 100, 168, t, 0.7, fx, cw, { plain, step: 0.13 }),
628
977
  words: (ctx, t, fx, cw, b) =>
629
978
  text(ctx, b, `Over ${num(D.activeDays)} days and ${num(D.sessions)} sessions.`, 0, {
630
979
  ...big(72), color: cw.ink, alpha: fade(t, 1.8),
@@ -822,15 +1171,34 @@ function buildCards(D) {
822
1171
  });
823
1172
  }
824
1173
 
1174
+ if (D.crashouts) {
1175
+ const c = D.crashouts;
1176
+ const lines = [
1177
+ c.worstDay && `Worst day: ${day(c.worstDay.day)}, with ${num(c.worstDay.count)}.`,
1178
+ c.word && `Your go-to: “${c.word}”.`,
1179
+ ].filter(Boolean);
1180
+ add({
1181
+ id: "crashouts", name: "Crashouts", ready: 2.4 + lines.length * 0.7,
1182
+ alt: `Crashouts: ${num(c.count)} times you lost it a little. ${lines.join(" ")} We didn't take it personally.`,
1183
+ head: (ctx, t, fx, cw, b) => text(ctx, b, "Crashouts", 0, { ...big(70), color: cw.ink }),
1184
+ visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(num(c.count)), 100, 190, t, 0.6, fx, cw, { plain, step: 0.14 }),
1185
+ words(ctx, t, fx, cw, b) {
1186
+ let y = text(ctx, b, `${num(c.count)} times you lost it a little.`, 0, { ...big(68), color: cw.ink, alpha: fade(t, 1.4) });
1187
+ if (lines.length) y = text(ctx, b, lines.join(" "), y + 18, { ...say(), color: cw.soft, alpha: fade(t, 2.1) });
1188
+ text(ctx, b, "We didn't take it personally.", y + 18, { size: 34, color: cw.faint, alpha: fade(t, 2.1 + lines.length * 0.7) });
1189
+ },
1190
+ });
1191
+ }
1192
+
825
1193
  if (D.night) {
826
1194
  const n = D.night;
827
1195
  add({
828
- id: "night", name: "Late night", ready: 2.3,
829
- alt: `Your latest prompt after midnight was at ${n.latest}. ${num(n.prompts)} prompts after midnight.`,
830
- head: (ctx, t, fx, cw, b) => text(ctx, b, "Your latest prompt after midnight", 0, { ...say(54), color: cw.soft }),
831
- visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(n.latest), 110, 190, t, 0.6, fx, cw, { narrow, step: 0.15 }),
1196
+ id: "night", name: "Late night", ready: 2.5,
1197
+ alt: `The latest you were still prompting: ${clock(n.latest)}. ${num(n.prompts)} prompts between midnight and 5 AM.`,
1198
+ head: (ctx, t, fx, cw, b) => text(ctx, b, "The latest you were still prompting", 0, { ...say(54), color: cw.soft }),
1199
+ visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, [...chars(clock(n.latest).slice(0, -3)), " AM"], 110, 190, t, 0.6, fx, cw, { plain, step: 0.15 }),
832
1200
  words: (ctx, t, fx, cw, b) =>
833
- text(ctx, b, `${num(n.prompts)} prompts after 12 a.m. We were up too.`, 0, { ...big(68), color: cw.ink, alpha: fade(t, 1.8) }),
1201
+ text(ctx, b, `${num(n.prompts)} prompts between midnight and 5 AM. We were up too.`, 0, { ...big(68), color: cw.ink, alpha: fade(t, 1.9) }),
834
1202
  });
835
1203
  }
836
1204
 
@@ -972,7 +1340,8 @@ function buildCards(D) {
972
1340
  const y = week
973
1341
  ? 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
1342
  : 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)) });
1343
+ const deploys = s.deploys > 0 ? " A deploy is a command like npm publish or vercel --prod." : "";
1344
+ text(ctx, b, `Counted from the commands your agents ran, since ${day(s.since)}.${deploys}`, y, { size: 34, color: cw.faint, alpha: fade(t, last + (week ? 1.4 : 0.6)) });
976
1345
  },
977
1346
  });
978
1347
  }
@@ -983,7 +1352,7 @@ function buildCards(D) {
983
1352
  id: "money", name: "API value", ready: 3.1,
984
1353
  alt: `At least ${num(m.atLeastUsd)} US dollars of agent work at public API prices.`,
985
1354
  head: (ctx, t, fx, cw, b) => text(ctx, b, "Our work, at public API prices", 0, { ...say(54), color: cw.soft }),
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 }),
1355
+ visual: (ctx, t, fx, cw, b) => typeRow(ctx, b, chars(`$${num(m.atLeastUsd)}`), 100, 150, t, 0.6, fx, cw, { plain, step: 0.12 }),
987
1356
  words(ctx, t, fx, cw, b) {
988
1357
  const y = text(ctx, b, "At least. We priced what we could count exactly, and the rest at the cheapest rate.", 0, {
989
1358
  ...say(), color: cw.soft, alpha: fade(t, 1.8),
@@ -997,20 +1366,27 @@ function buildCards(D) {
997
1366
 
998
1367
  const p = D.personality;
999
1368
  const reveal = 2.2;
1369
+ const PERSONA = 280;
1370
+ const PERSONA_Y = 300;
1371
+ const [above, below] = CHARACTERS[p.name]?.box ?? [-0.55, 0.55];
1000
1372
  add({
1001
1373
  id: "personality", name: "Personality", ready: reveal + 2.1,
1374
+ visualBox: { top: PERSONA_Y + above * PERSONA, bottom: PERSONA_Y + below * PERSONA },
1002
1375
  alt: `You are ${p.name}. ${p.line}`,
1003
1376
  head: (ctx, t, fx, cw, b) => text(ctx, b, "So, who are you?", 0, { ...say(54), color: cw.soft }),
1004
1377
  visual(ctx, t, fx, cw, b) {
1005
1378
  [0.5, 0.8, 1.05, 1.25, 1.42, 1.56, 1.68, 1.78].forEach((at) => fx.key(at));
1006
1379
  fx.ding(reveal);
1007
- const revealed = t >= reveal || REDUCED;
1008
- cap(ctx, b.x + b.w / 2, 150, 280, 280, revealed ? initials(p.name) : "?", {
1009
- ...(revealed ? LIT : cw),
1380
+ if (t >= reveal || REDUCED) {
1381
+ character(ctx, p.name, b.x + b.w / 2, PERSONA_Y, PERSONA, t - reveal, 0.9 + 0.1 * easeBack((t - reveal) / 0.3));
1382
+ return;
1383
+ }
1384
+ cap(ctx, b.x + b.w / 2, PERSONA_Y, PERSONA, PERSONA, "?", {
1385
+ ...cw,
1010
1386
  fontSize: 104,
1011
1387
  weight: 600,
1012
- scale: revealed ? 0.9 + 0.1 * easeBack((t - reveal) / 0.3) : 1 + Math.sin(t * 40) * 0.04,
1013
- press: !revealed && (t * 6) % 1 < 0.3 ? 1 : 0,
1388
+ scale: 1 + Math.sin(t * 40) * 0.04,
1389
+ press: (t * 6) % 1 < 0.3 ? 1 : 0,
1014
1390
  });
1015
1391
  },
1016
1392
  words(ctx, t, fx, cw, b) {
@@ -1059,7 +1435,7 @@ function buildCards(D) {
1059
1435
  [num(D.prompts), "prompts"],
1060
1436
  D.agents ? [num(D.agents.hours), "hours of agent work"] : null,
1061
1437
  D.topTypo ? [`${D.topTypo.spelling} ×${num(D.topTypo.count)}`, "my favourite typo"] : null,
1062
- D.night ? [D.night.latest, "latest prompt after midnight"] : D.streak ? [`${D.streak.days} days`, "longest streak"] : null,
1438
+ D.night ? [clock(D.night.latest), "latest you were still prompting"] : D.streak ? [`${D.streak.days} days`, "longest streak"] : null,
1063
1439
  ].filter(Boolean);
1064
1440
  add({
1065
1441
  id: "summary", name: "Summary", ready: 0.7 + tiles.length * 0.25,
@@ -1132,7 +1508,10 @@ function measure(card, part, b) {
1132
1508
  // Places parts in a column, centred as one block in the shape's space.
1133
1509
  function stack(card, parts, b) {
1134
1510
  const placed = [];
1135
- const sized = parts.map((part) => ({ part, box: measure(card, part, b) })).filter((x) => x.box);
1511
+ // A visual that moves past its last frame says how far it reaches.
1512
+ const sized = parts
1513
+ .map((part) => ({ part, box: part === card.visual && card.visualBox ? card.visualBox : measure(card, part, b) }))
1514
+ .filter((x) => x.box);
1136
1515
  const total = sized.reduce((s, x) => s + (x.box.bottom - x.box.top), 0) + shape.gap * (sized.length - 1);
1137
1516
  const [top, bottom] = shape.space;
1138
1517
  let y = Math.max(top, (top + bottom) / 2 - total / 2);
@@ -1329,7 +1708,7 @@ document.getElementById("skip").addEventListener("click", openShare);
1329
1708
  document.getElementById("save-now").addEventListener("click", saveCurrent);
1330
1709
  if (SHARED) {
1331
1710
  document.getElementById("play").textContent = "Play the story";
1332
- document.getElementById("start-note").textContent = `A ${D.period === "month" ? "month" : "year"} with AI coding agents, wrapped. Sound on for the full effect.`;
1711
+ document.getElementById("start-note").textContent = `${D.period === "month" ? "A month" : SHORT ? SPAN : "A year"} with AI coding agents, wrapped. Sound on for the full effect.`;
1333
1712
  document.getElementById("skip").textContent = "Skip to the end";
1334
1713
  }
1335
1714
 
@@ -1362,7 +1741,7 @@ const postLinkedIn = document.getElementById("post-linkedin");
1362
1741
  // Cards you can leave out, and the part of the story each one needs.
1363
1742
  const LEAVABLE = {
1364
1743
  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",
1744
+ talk: "talk", crashouts: "crashouts", night: "night", streak: "streak", agents: "agents", work: "work", shipped: "shipped", money: "money", letter: "letter",
1366
1745
  };
1367
1746
  // ids of the cards left out. Chapters say what you worked on, so they stay
1368
1747
  // out of a link unless you add them.
@@ -1416,9 +1795,6 @@ async function renderShare() {
1416
1795
  const next = PLAYER_URL ? `${PLAYER_URL}#v2.${await pack(toLink(data))}` : "";
1417
1796
  if (mine !== linkFor) return;
1418
1797
  link = next;
1419
- const url = encodeURIComponent(link);
1420
- postX.href = `https://x.com/intent/post?text=${encodeURIComponent(shareText(data))}&url=${url}`;
1421
- postLinkedIn.href = `https://www.linkedin.com/sharing/share-offsite/?url=${url}`;
1422
1798
  for (const el of document.querySelectorAll("[data-needs-link]")) el.hidden = !link;
1423
1799
  document.getElementById("share-link").hidden = !link || typeof navigator.share !== "function";
1424
1800
  document.getElementById("offline").hidden = !!link;
@@ -1463,9 +1839,33 @@ function openShare() {
1463
1839
  document.getElementById("share-title").focus();
1464
1840
  }
1465
1841
 
1842
+ // The short link for the story as it is now: the site saves the story's
1843
+ // code and names it. Without the site, the long link still works.
1844
+ let short = { for: "", url: "" };
1845
+ async function shortLink() {
1846
+ const mine = link;
1847
+ if (short.for === mine) return short.url;
1848
+ try {
1849
+ const res = await fetch(new URL("/api/share", PLAYER_URL), { method: "POST", body: mine.slice(mine.indexOf("#") + 1) });
1850
+ if (!res.ok) return mine;
1851
+ const { name } = await res.json();
1852
+ short = { for: mine, url: new URL(`/s/${name}`, PLAYER_URL).href };
1853
+ return short.url;
1854
+ } catch {
1855
+ return mine;
1856
+ }
1857
+ }
1858
+
1466
1859
  document.getElementById("copy-link").addEventListener("click", async () => {
1860
+ const url = shortLink();
1467
1861
  try {
1468
- await navigator.clipboard.writeText(link);
1862
+ // Handing the clipboard a promise keeps the click's permission to copy
1863
+ // while the short link is made.
1864
+ try {
1865
+ await navigator.clipboard.write([new ClipboardItem({ "text/plain": url.then((u) => new Blob([u], { type: "text/plain" })) })]);
1866
+ } catch {
1867
+ await navigator.clipboard.writeText(await url);
1868
+ }
1469
1869
  notify("Link copied. Paste it anywhere.");
1470
1870
  } catch {
1471
1871
  notify("Couldn't copy the link. Try Share instead.");
@@ -1474,12 +1874,31 @@ document.getElementById("copy-link").addEventListener("click", async () => {
1474
1874
 
1475
1875
  document.getElementById("share-link").addEventListener("click", async () => {
1476
1876
  try {
1477
- await navigator.share({ title: "Agent Wrapped", text: shareText(sharedData()), url: link });
1877
+ await navigator.share({ title: "Agent Wrapped", text: shareText(sharedData()), url: await shortLink() });
1478
1878
  } catch (err) {
1479
- if (err?.name !== "AbortError") notify("Couldn't open sharing. Copy the link instead.");
1879
+ // Some browsers only open sharing straight after a tap. The short link
1880
+ // is ready now, so a second tap opens it at once.
1881
+ if (err?.name === "NotAllowedError") notify("Tap Share again to open it.");
1882
+ else if (err?.name !== "AbortError") notify("Couldn't open sharing. Copy the link instead.");
1480
1883
  }
1481
1884
  });
1482
1885
 
1886
+ // The post opens in a new tab straight away, so it isn't blocked, and moves
1887
+ // to the post once the short link is ready.
1888
+ for (const [el, post] of [
1889
+ [postX, (url) => `https://x.com/intent/post?text=${encodeURIComponent(shareText(sharedData()))}&url=${encodeURIComponent(url)}`],
1890
+ [postLinkedIn, (url) => `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`],
1891
+ ]) {
1892
+ el.addEventListener("click", async (e) => {
1893
+ e.preventDefault();
1894
+ const tab = open("about:blank", "_blank");
1895
+ const url = post(await shortLink());
1896
+ if (!tab) return open(url, "_blank", "noopener");
1897
+ tab.opener = null;
1898
+ tab.location.href = url;
1899
+ });
1900
+ }
1901
+
1483
1902
  document.getElementById("save-image").addEventListener("click", async () => {
1484
1903
  download(await pngOf(finalFrame(summaryCard(), shape)), `agent-wrapped-${shapeName(shape)}.png`);
1485
1904
  notify("Saved the card to your Downloads folder.");
package/dist/story.js CHANGED
@@ -7,6 +7,10 @@ export function pickCatchphrase(list) {
7
7
  const SPELLINGS_SHOWN = 16;
8
8
  // Pushes, pull requests and deploys together, before they make a card.
9
9
  const SHIPPED = 5;
10
+ // Crashouts before they make a card.
11
+ const CRASHOUTS = 5;
12
+ // "wtf" -> "w*f", "fuck" -> "f**k".
13
+ export const starred = (word) => word[0] + "*".repeat(word.length - 2) + word.at(-1);
10
14
  // A count this small isn't a habit yet.
11
15
  const HABIT = 20;
12
16
  // `chapterNames` come from `nameChapters`; without them a chapter is named by its top words.
@@ -55,5 +59,8 @@ export function storyData(w, personality, letter, chapterNames = w.chapters.map(
55
59
  personality,
56
60
  letter,
57
61
  period: span,
62
+ crashouts: w.voice.crashouts.count >= CRASHOUTS
63
+ ? { ...w.voice.crashouts, word: w.voice.crashouts.word && starred(w.voice.crashouts.word) }
64
+ : null,
58
65
  };
59
66
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shadevkumar/agent-wrapped",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Your year with AI coding agents, played back in keyboard keys. Reads Claude Code and Codex logs on your computer.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -43,6 +43,10 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^26.6.5",
46
+ "@vercel/blob": "2.8.2",
46
47
  "typescript": "^7.0.2"
48
+ },
49
+ "overrides": {
50
+ "zod": "4.6.7"
47
51
  }
48
52
  }