@shadevkumar/agent-wrapped 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist/build.js +21 -4
- package/dist/chapters.js +46 -0
- package/dist/claude-cli.js +27 -0
- package/dist/cli.js +65 -21
- package/dist/letter.js +6 -18
- package/dist/moments.js +83 -6
- package/dist/personality.js +12 -2
- package/dist/read-worker.js +18 -0
- package/dist/screen.js +78 -0
- package/dist/sources/claude.js +4 -4
- package/dist/sources/codex.js +2 -3
- package/dist/sources/cursor.js +81 -0
- package/dist/story/index.html +12 -7
- package/dist/story/link.d.ts +4 -0
- package/dist/story/link.js +53 -0
- package/dist/story/story.js +372 -81
- package/dist/story.js +15 -3
- package/dist/types.js +25 -9
- package/dist/words.js +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,9 @@ Your life with AI coding agents, wrapped.
|
|
|
6
6
|
npx @shadevkumar/agent-wrapped
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
It reads your Claude Code and
|
|
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.
|
|
10
|
+
|
|
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.
|
|
10
12
|
|
|
11
13
|
Then you share it. One link plays your whole story for anyone who opens it, keys and sound included, and ends by showing them how to make their own. You can leave cards out first, or save a video for places that don't take links. While you watch, the buttons fade away so a screenshot shows only the card, and pressing S saves the card on screen.
|
|
12
14
|
|
|
@@ -17,6 +19,7 @@ Nothing is uploaded. The story is one HTML file written to your computer's temp
|
|
|
17
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.
|
|
18
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.
|
|
19
21
|
- **You see the story before you share it,** and a card you leave out is not in the link at all.
|
|
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.
|
|
20
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.
|
|
21
24
|
|
|
22
25
|
## What it reads
|
|
@@ -29,8 +32,9 @@ Nothing is uploaded. The story is one HTML file written to your computer's temp
|
|
|
29
32
|
| Codex | `~/.codex/thread_history_*.sqlite` | the prompts you typed, how long each request took, and the same tests, commits, edits and stops |
|
|
30
33
|
| Codex | `~/.codex/state_*.sqlite` | token totals per thread |
|
|
31
34
|
| Codex | `~/.codex/sessions/**/*.jsonl` | token splits for recent threads |
|
|
35
|
+
| Cursor | `~/.cursor/projects/*/agent-transcripts/*/*.jsonl` | the prompts you typed to Cursor's agent, and the same tests, commits and edits |
|
|
32
36
|
|
|
33
|
-
Everything is opened read-only. For what the agents did, only the kind is kept (a test run, a commit, a stop) and, for an edit, the file type: never a command, a file name or any output. Claude Code deletes full transcripts after about 30 days, so older Claude token use and work can be missing. The prompts themselves go back further.
|
|
37
|
+
Everything is opened read-only. For what the agents did, only the kind is kept (a test run, a commit, a push, a pull request, a deploy, a stop) and, for an edit, the file type: never a command, a file name or any output. Cursor doesn't log tokens or how long its agent worked, so Cursor adds prompts and work but no hours or cost. Claude Code deletes full transcripts after about 30 days, so older Claude token use and work can be missing. The prompts themselves go back further.
|
|
34
38
|
|
|
35
39
|
## How the cost is worked out
|
|
36
40
|
|
|
@@ -46,14 +50,16 @@ Prices are in `src/pricing.ts`, with the date they were read and their source pa
|
|
|
46
50
|
|
|
47
51
|
| Flag | What it does |
|
|
48
52
|
| --- | --- |
|
|
49
|
-
| `--
|
|
53
|
+
| `--last-month` | Make the story from the last 30 days only |
|
|
54
|
+
| `--everything` | Make it from everything so far, without asking |
|
|
55
|
+
| `--no-ai` | Don't ask your `claude` command: a template letter, and chapters named by their top words |
|
|
50
56
|
| `--no-open` | Write the story file without opening it |
|
|
51
57
|
| `--json` | Print the numbers behind the story instead of making it |
|
|
52
58
|
|
|
53
59
|
## Needs
|
|
54
60
|
|
|
55
61
|
- Node.js 22.13 or newer
|
|
56
|
-
- Claude Code, Codex
|
|
62
|
+
- Claude Code, Codex or Cursor, used on this computer
|
|
57
63
|
- macOS is where it's tested. It uses the system dictionary in `/usr/share/dict/words` to tell typos from words; without one, quotes are mostly left out.
|
|
58
64
|
|
|
59
65
|
## Develop
|
package/dist/build.js
CHANGED
|
@@ -15,6 +15,8 @@ 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="preload" href="/fonts/geist-normal.woff2" as="font" type="font/woff2" crossorigin>
|
|
19
|
+
<link rel="preload" href="/fonts/newsreader-italic.woff2" as="font" type="font/woff2" crossorigin>
|
|
18
20
|
<script>
|
|
19
21
|
window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
|
|
20
22
|
window.va("beforeSend", (event) => {
|
|
@@ -24,27 +26,42 @@ window.va("beforeSend", (event) => {
|
|
|
24
26
|
});
|
|
25
27
|
</script>
|
|
26
28
|
<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.
|
|
32
|
+
const HOME_FIRST = `<script>
|
|
33
|
+
if (!location.hash) {
|
|
34
|
+
document.documentElement.classList.add("home");
|
|
35
|
+
document.fonts.load("480 1em Geist").finally(() => document.documentElement.classList.add("fonts-in"));
|
|
36
|
+
}
|
|
37
|
+
</script>`;
|
|
27
38
|
// One self-contained HTML file: fonts, script and data inlined, nothing
|
|
28
39
|
// fetched from the internet when it opens. Without data it is the public
|
|
29
|
-
// player, which reads the story from its link
|
|
40
|
+
// player, which reads the story from its link; it loads the fonts as
|
|
41
|
+
// separate files from /fonts/, so the page itself is small and phones show
|
|
42
|
+
// it sooner, and the fonts stay cached between visits.
|
|
30
43
|
export function buildHtml(data, playerUrl = PLAYER_URL) {
|
|
31
|
-
|
|
44
|
+
// link.js is a module of its own for the site build; on the page it runs inline.
|
|
45
|
+
const link = readFileSync(join(STORY_DIR, "link.js"), "utf8").replace(/^export /gm, "");
|
|
46
|
+
const script = `${link}\n${readFileSync(join(STORY_DIR, "story.js"), "utf8")}`;
|
|
47
|
+
const font = (file) => data ? `data:font/woff2;base64,${readFileSync(join(STORY_DIR, "fonts", file)).toString("base64")}` : `/fonts/${file}`;
|
|
32
48
|
const fonts = [
|
|
33
49
|
["Geist", "geist-normal.woff2", "normal", "100 900"],
|
|
34
50
|
["Newsreader", "newsreader-normal.woff2", "normal", "300 700"],
|
|
35
51
|
["Newsreader", "newsreader-italic.woff2", "italic", "300 700"],
|
|
36
52
|
]
|
|
37
|
-
.map(([family, file, style, weight]) => `@font-face{font-family:"${family}";src:url(
|
|
53
|
+
.map(([family, file, style, weight]) => `@font-face{font-family:"${family}";src:url(${font(file)}) format("woff2");font-style:${style};font-weight:${weight};font-display:block}`)
|
|
38
54
|
.join("\n");
|
|
39
55
|
// Escape "<" so no value can close the script tag it sits in.
|
|
40
56
|
const json = JSON.stringify(data).replace(/</g, "\\u003c");
|
|
41
57
|
return readFileSync(join(STORY_DIR, "index.html"), "utf8")
|
|
42
58
|
.replace("<!--HEAD-->", () => (data ? "" : PUBLIC_HEAD))
|
|
59
|
+
.replace("<!--HOME-->", () => (data ? "" : HOME_FIRST))
|
|
43
60
|
// The public page doesn't know yet whether its link holds a story, so its
|
|
44
61
|
// player starts hidden instead of flashing an empty frame.
|
|
45
62
|
.replace('<main class="player" id="player">', (tag) => (data ? tag : '<main class="player" id="player" hidden>'))
|
|
46
63
|
.replace("/*FONTS*/", () => fonts)
|
|
47
64
|
.replace("/*DATA*/", () => json)
|
|
48
65
|
.replace("/*PLAYER_URL*/", () => JSON.stringify(playerUrl).replace(/</g, "\\u003c"))
|
|
49
|
-
.replace("/*SCRIPT*/", () =>
|
|
66
|
+
.replace("/*SCRIPT*/", () => script);
|
|
50
67
|
}
|
package/dist/chapters.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { askClaude } from "./claude-cli.js";
|
|
2
|
+
import { tokenize } from "./words.js";
|
|
3
|
+
// Names each chapter of the year. The person's own `claude` command gets only
|
|
4
|
+
// each chapter's standout words, which already passed the topic-word check,
|
|
5
|
+
// never a prompt. A name it writes is used only if every word in it passes
|
|
6
|
+
// that same check or is one of the chapter's words; otherwise, and with no
|
|
7
|
+
// AI, the chapter is named by its top words.
|
|
8
|
+
const SYSTEM = `You name the chapters of someone's year working with AI coding agents.
|
|
9
|
+
For each chapter you get the words that set it apart. Write a short name for what they seemed to work on.
|
|
10
|
+
Rules:
|
|
11
|
+
- 2 to 5 words and at most 45 characters, lowercase except the first letter, no punctuation at the end.
|
|
12
|
+
- Use the given words and plain everyday words only. No names of people, companies, products or places.
|
|
13
|
+
- Describe the work, not the person. Don't guess beyond the words.
|
|
14
|
+
- Reply with a JSON array of strings only, one per chapter, in the same order.`;
|
|
15
|
+
export function plainName(words) {
|
|
16
|
+
return words.slice(0, 3).join(" · ");
|
|
17
|
+
}
|
|
18
|
+
export async function nameChapters(chapters, words, useAi) {
|
|
19
|
+
const plain = chapters.map((c) => plainName(c.words));
|
|
20
|
+
if (!useAi || chapters.length === 0)
|
|
21
|
+
return plain;
|
|
22
|
+
const reply = await askClaude(SYSTEM, chapters.map((c, i) => `Chapter ${i + 1}: ${c.words.join(", ")}`).join("\n"), 60_000);
|
|
23
|
+
const named = reply ? parseNames(reply, chapters.length) : null;
|
|
24
|
+
return plain.map((fallback, i) => (named && safeName(named[i], chapters[i].words, words)) || fallback);
|
|
25
|
+
}
|
|
26
|
+
export function parseNames(raw, count) {
|
|
27
|
+
try {
|
|
28
|
+
const list = JSON.parse(raw.slice(raw.indexOf("["), raw.lastIndexOf("]") + 1));
|
|
29
|
+
return Array.isArray(list) && list.length === count && list.every((n) => typeof n === "string") ? list : null;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// The name, tidied, if every word in it is safe to show; otherwise null.
|
|
36
|
+
export function safeName(name, chapterWords, words) {
|
|
37
|
+
const text = name.trim().replace(/[.!]+$/, "");
|
|
38
|
+
const parts = tokenize(text);
|
|
39
|
+
// Longer names don't fit a row of the card.
|
|
40
|
+
if (parts.length < 2 || parts.length > 6 || text.length > 48)
|
|
41
|
+
return null;
|
|
42
|
+
if (/[^A-Za-z '\-]/.test(text))
|
|
43
|
+
return null;
|
|
44
|
+
const ok = parts.every((w) => chapterWords.includes(w) || words.isTopicWord(w) || words.isStopword(w));
|
|
45
|
+
return ok ? text[0].toUpperCase() + text.slice(1) : null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
// Asks the person's own `claude` command, with no tools, no project
|
|
4
|
+
// instructions and nothing saved. Resolves to its reply, or null if Claude
|
|
5
|
+
// isn't installed, fails or takes too long.
|
|
6
|
+
export function askClaude(system, input, timeoutMs) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const args = [
|
|
9
|
+
"-p",
|
|
10
|
+
"--model", "sonnet",
|
|
11
|
+
"--tools", "",
|
|
12
|
+
"--strict-mcp-config",
|
|
13
|
+
"--disable-slash-commands",
|
|
14
|
+
"--no-session-persistence",
|
|
15
|
+
"--setting-sources", "",
|
|
16
|
+
"--system-prompt", system,
|
|
17
|
+
];
|
|
18
|
+
// Run outside any project so no project instructions are loaded.
|
|
19
|
+
const child = spawn("claude", args, { cwd: tmpdir(), stdio: ["pipe", "pipe", "ignore"], timeout: timeoutMs });
|
|
20
|
+
let out = "";
|
|
21
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => (out += chunk));
|
|
22
|
+
child.on("error", () => resolve(null));
|
|
23
|
+
child.on("close", (code) => resolve(code === 0 ? out : null));
|
|
24
|
+
child.stdin.on("error", () => { }); // Claude missing: the "error" above answers
|
|
25
|
+
child.stdin.end(input);
|
|
26
|
+
});
|
|
27
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -4,45 +4,89 @@ import { mkdirSync, writeFileSync } from "node:fs";
|
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { buildHtml } from "./build.js";
|
|
7
|
+
import { nameChapters } from "./chapters.js";
|
|
7
8
|
import { localDay } from "./files.js";
|
|
8
9
|
import { templateLetter, writeLetter } from "./letter.js";
|
|
9
10
|
import { computeWrapped } from "./moments.js";
|
|
10
11
|
import { pickPersonality } from "./personality.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { bold, choose, dim, line, step } from "./screen.js";
|
|
13
|
+
import { readInBackground } from "./read-worker.js";
|
|
13
14
|
import { storyData } from "./story.js";
|
|
14
|
-
import { mergeHarvests } from "./types.js";
|
|
15
|
+
import { harvestSince, mergeHarvests } from "./types.js";
|
|
16
|
+
import { Words } from "./words.js";
|
|
17
|
+
const HELP = `Agent Wrapped 2026: your year with Claude Code, Codex and Cursor, played back in keyboard keys.
|
|
18
|
+
|
|
19
|
+
Usage: npx @shadevkumar/agent-wrapped [options]
|
|
20
|
+
|
|
21
|
+
--last-month Make the story from the last 30 days only
|
|
22
|
+
--everything Make it from everything so far, without asking
|
|
23
|
+
--no-ai Don't ask your claude command: a template letter, and chapters named by their top words
|
|
24
|
+
--no-open Write the story file without opening it
|
|
25
|
+
--json Print the numbers behind the story instead of making it
|
|
26
|
+
-h, --help Show this`;
|
|
15
27
|
const args = new Set(process.argv.slice(2));
|
|
28
|
+
if (args.has("--help") || args.has("-h")) {
|
|
29
|
+
console.log(HELP);
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
16
32
|
const home = homedir();
|
|
17
|
-
|
|
18
|
-
const
|
|
33
|
+
const useAi = !args.has("--no-ai");
|
|
34
|
+
const n = (x) => Math.round(x).toLocaleString("en-US");
|
|
35
|
+
line();
|
|
36
|
+
line(` ${bold("Agent Wrapped 2026")}`);
|
|
37
|
+
line(` ${dim("Reads your agents' logs on this computer. Nothing is uploaded.")}`);
|
|
38
|
+
line();
|
|
39
|
+
const span = args.has("--last-month")
|
|
40
|
+
? "month"
|
|
41
|
+
: args.has("--everything") || args.has("--json")
|
|
42
|
+
? "year"
|
|
43
|
+
: await choose("Which stretch should your story cover?", [
|
|
44
|
+
{ label: "Everything so far", value: "year" },
|
|
45
|
+
{ label: "The last 30 days", value: "month" },
|
|
46
|
+
]);
|
|
47
|
+
const since = span === "month" ? new Date(Date.now() - 30 * 86_400_000) : null;
|
|
48
|
+
// All three are read at once; each line ticks when its agent is done.
|
|
49
|
+
const reading = ["claude", "codex", "cursor"].map((source) => readInBackground(source, home));
|
|
50
|
+
const parts = [];
|
|
51
|
+
for (const [i, name] of ["Claude Code", "Codex", "Cursor"].entries()) {
|
|
52
|
+
parts.push(await step(`Reading ${name}`, async () => (since ? harvestSince(await reading[i], since) : reading[i]), (h) => `${name} ${dim(h.prompts.length ? `${n(h.prompts.length)} prompts` : "none on this computer")}`));
|
|
53
|
+
}
|
|
54
|
+
const harvest = mergeHarvests(parts);
|
|
55
|
+
const words = new Words(harvest.privateNames);
|
|
56
|
+
const wrapped = computeWrapped(harvest, words);
|
|
19
57
|
if (args.has("--json")) {
|
|
20
58
|
console.log(JSON.stringify(wrapped, null, 2));
|
|
21
59
|
process.exit(0);
|
|
22
60
|
}
|
|
23
61
|
if (wrapped.totals.prompts === 0) {
|
|
24
|
-
|
|
62
|
+
line();
|
|
63
|
+
line(since
|
|
64
|
+
? " No prompts from the last 30 days on this computer. Try it without --last-month."
|
|
65
|
+
: " No Claude Code, Codex or Cursor prompts on this computer, so there's no story yet.");
|
|
25
66
|
process.exit(1);
|
|
26
67
|
}
|
|
27
68
|
const personality = pickPersonality(wrapped);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.log("Claude wasn't available, so your agents wrote a shorter note instead.");
|
|
37
|
-
}
|
|
69
|
+
if (useAi)
|
|
70
|
+
line(` ${dim("Your claude command writes the letter and names the chapters. It sees your stats and a few words, never your prompts.")}`);
|
|
71
|
+
const [letter, chapterNames] = await step(useAi ? "Writing your letter" : "Writing a short letter", () => Promise.all([
|
|
72
|
+
useAi ? writeLetter(wrapped, personality, span) : { text: templateLetter(wrapped, personality), by: "template" },
|
|
73
|
+
nameChapters(wrapped.chapters, words, useAi),
|
|
74
|
+
]), ([l]) => l.by === "claude"
|
|
75
|
+
? `Letter and chapters ${dim("written by your Claude")}`
|
|
76
|
+
: `Letter ${dim(useAi ? "Claude wasn't available, so your agents wrote a shorter note" : "a short one, from a template")}`);
|
|
38
77
|
const dir = join(tmpdir(), "agent-wrapped");
|
|
39
78
|
mkdirSync(dir, { recursive: true });
|
|
40
|
-
const file = join(dir, `agent-wrapped-${localDay(new Date())}.html`);
|
|
41
|
-
writeFileSync(file, buildHtml(storyData(wrapped, personality, letter)));
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(
|
|
79
|
+
const file = join(dir, `agent-wrapped-${localDay(new Date())}${span === "month" ? "-last-30-days" : ""}.html`);
|
|
80
|
+
writeFileSync(file, buildHtml(storyData(wrapped, personality, letter, chapterNames, span)));
|
|
81
|
+
const hours = wrapped.totals.agentHours >= 1 ? `, ${n(wrapped.totals.agentHours)} hours of agent work` : "";
|
|
82
|
+
line();
|
|
83
|
+
console.log(` You are ${bold(personality.name)}.`);
|
|
84
|
+
console.log(` ${n(wrapped.totals.prompts)} prompts${hours}.`);
|
|
85
|
+
line();
|
|
86
|
+
console.log(` Your story: ${file}`);
|
|
45
87
|
if (!args.has("--no-open")) {
|
|
88
|
+
console.log(` ${dim("Opening it in your browser. Share it from the last screen; anyone with your link can watch it.")}`);
|
|
46
89
|
const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "explorer" : "xdg-open";
|
|
47
90
|
spawn(opener, [file], { detached: true, stdio: "ignore" }).unref();
|
|
48
91
|
}
|
|
92
|
+
line();
|
package/dist/letter.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const SYSTEM = `You write the closing card of "Agent Wrapped", a year-in-review of someone's work with AI coding agents.
|
|
1
|
+
import { askClaude } from "./claude-cli.js";
|
|
2
|
+
const SYSTEM = `You write the closing card of "Agent Wrapped", a look back at someone's work with AI coding agents.
|
|
4
3
|
Write a short letter from their agents to them. Rules:
|
|
5
4
|
- 70 to 100 words, plain text, no markdown, no emoji, no greeting line like "Dear".
|
|
6
5
|
- Warm, funny, a little roasting, never mean. Sound like a coworker, not a greeting card.
|
|
7
6
|
- Use two or three of the facts given, quoting their words exactly as given.
|
|
8
7
|
- Never invent numbers, names, projects or events that are not in the facts.
|
|
9
8
|
- End with a short sign-off line from "your agents".`;
|
|
10
|
-
export function factsFor(w, p) {
|
|
9
|
+
export function factsFor(w, p, span = "year") {
|
|
11
10
|
const facts = [
|
|
11
|
+
span === "month" ? "This story covers only their last 30 days." : "This story covers their year so far.",
|
|
12
12
|
`Their personality: ${p.name}. ${p.line}`,
|
|
13
13
|
`${w.totals.prompts} prompts over ${w.totals.activeDays} days; their agents worked ${Math.round(w.totals.agentHours)} hours.`,
|
|
14
14
|
w.rhythm.lateNight.latest ? `Latest prompt after midnight: ${w.rhythm.lateNight.latest}.` : "",
|
|
@@ -23,20 +23,8 @@ export function factsFor(w, p) {
|
|
|
23
23
|
];
|
|
24
24
|
return facts.filter(Boolean).join("\n");
|
|
25
25
|
}
|
|
26
|
-
export function writeLetter(w, p) {
|
|
27
|
-
const
|
|
28
|
-
"-p",
|
|
29
|
-
"--model", "sonnet",
|
|
30
|
-
"--tools", "",
|
|
31
|
-
"--strict-mcp-config",
|
|
32
|
-
"--disable-slash-commands",
|
|
33
|
-
"--no-session-persistence",
|
|
34
|
-
"--setting-sources", "",
|
|
35
|
-
"--system-prompt", SYSTEM,
|
|
36
|
-
],
|
|
37
|
-
// Run outside any project so no project instructions are loaded.
|
|
38
|
-
{ cwd: tmpdir(), input: `Facts:\n${factsFor(w, p)}`, encoding: "utf8", timeout: 90_000 });
|
|
39
|
-
const text = cleanLetter(run.status === 0 ? run.stdout : "");
|
|
26
|
+
export async function writeLetter(w, p, span = "year") {
|
|
27
|
+
const text = cleanLetter((await askClaude(SYSTEM, `Facts:\n${factsFor(w, p, span)}`, 90_000)) ?? "");
|
|
40
28
|
return text ? { text, by: "claude" } : { text: templateLetter(w, p), by: "template" };
|
|
41
29
|
}
|
|
42
30
|
function cleanLetter(raw) {
|
package/dist/moments.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { localDay } from "./files.js";
|
|
2
2
|
import { apiCost, PRICES_AS_OF } from "./pricing.js";
|
|
3
|
-
import { usageTokens } from "./types.js";
|
|
3
|
+
import { AGENTS, usageTokens } from "./types.js";
|
|
4
4
|
import { findTypos, keySlips, tokenize, Words } from "./words.js";
|
|
5
5
|
const LATE_NIGHT_END_HOUR = 5;
|
|
6
6
|
// Repeats under a second apart are the logs writing a message twice, not a person.
|
|
@@ -45,7 +45,8 @@ export function computeWrapped(h, words = new Words(h.privateNames)) {
|
|
|
45
45
|
const lengths = tokenized.map((t) => t.length).sort((a, b) => a - b);
|
|
46
46
|
const days = [...new Set(prompts.map((p) => localDay(p.at)))].sort();
|
|
47
47
|
const cost = apiCost(h.usage, h.totals);
|
|
48
|
-
const agents =
|
|
48
|
+
const agents = Object.fromEntries(AGENTS.map((a) => [a, agentStats(a, h)]));
|
|
49
|
+
const sum = (key) => AGENTS.reduce((s, a) => s + agents[a][key], 0);
|
|
49
50
|
return {
|
|
50
51
|
coverage: h.coverage.map((c) => ({
|
|
51
52
|
agent: c.agent,
|
|
@@ -56,12 +57,12 @@ export function computeWrapped(h, words = new Words(h.privateNames)) {
|
|
|
56
57
|
})),
|
|
57
58
|
totals: {
|
|
58
59
|
prompts: prompts.length,
|
|
59
|
-
sessions:
|
|
60
|
+
sessions: sum("sessions"),
|
|
60
61
|
activeDays: days.length,
|
|
61
62
|
firstDay: days[0] ?? null,
|
|
62
63
|
lastDay: days.at(-1) ?? null,
|
|
63
|
-
agentHours: round(
|
|
64
|
-
tokens:
|
|
64
|
+
agentHours: round(sum("agentHours"), 1),
|
|
65
|
+
tokens: sum("tokens"),
|
|
65
66
|
},
|
|
66
67
|
agents,
|
|
67
68
|
cost: { ...cost, pricesAsOf: PRICES_AS_OF },
|
|
@@ -84,11 +85,69 @@ export function computeWrapped(h, words = new Words(h.privateNames)) {
|
|
|
84
85
|
loyalty: {
|
|
85
86
|
claudeShare: share(agents.claude.prompts, prompts.length),
|
|
86
87
|
codexShare: share(agents.codex.prompts, prompts.length),
|
|
88
|
+
cursorShare: share(agents.cursor.prompts, prompts.length),
|
|
87
89
|
bothAgentDays: bothAgentDays(prompts),
|
|
88
90
|
},
|
|
91
|
+
chapters: chapters(prompts, tokenized, words),
|
|
89
92
|
work: work(h),
|
|
90
93
|
};
|
|
91
94
|
}
|
|
95
|
+
const MAX_CHAPTERS = 5;
|
|
96
|
+
// Words every kind of work uses; they say nothing about which work it was.
|
|
97
|
+
const PLAIN = new Set(("also just like make sure check need want what when where which there here then them they this that with " +
|
|
98
|
+
"from have will would could should about into over after before than only even each other same more most " +
|
|
99
|
+
"some very really still again done next first please thanks okay right time thing things work working way " +
|
|
100
|
+
"good great well know think look looks show tell give take keep let lets used using use going doing").split(" "));
|
|
101
|
+
// Splits the active months into up to five stretches with similar amounts of
|
|
102
|
+
// prompts, then finds the words each stretch uses far more than the others.
|
|
103
|
+
function chapters(prompts, tokenized, words) {
|
|
104
|
+
const months = new Map();
|
|
105
|
+
prompts.forEach((p, i) => {
|
|
106
|
+
const seen = new Set(tokenized[i].filter((w) => w.length >= 4 && !PLAIN.has(w) && words.isTopicWord(w)));
|
|
107
|
+
const month = localDay(p.at).slice(0, 7);
|
|
108
|
+
months.set(month, [...(months.get(month) ?? []), seen]);
|
|
109
|
+
});
|
|
110
|
+
// A month joins the stretch its middle prompt falls in, so stretches hold
|
|
111
|
+
// similar amounts of work and a quiet month never stands alone.
|
|
112
|
+
const target = prompts.length / MAX_CHAPTERS;
|
|
113
|
+
const groups = [];
|
|
114
|
+
let before = 0;
|
|
115
|
+
let lastIndex = -1;
|
|
116
|
+
for (const [month, list] of [...months].sort(([a], [b]) => a.localeCompare(b))) {
|
|
117
|
+
const index = Math.min(MAX_CHAPTERS - 1, Math.floor((before + list.length / 2) / target));
|
|
118
|
+
before += list.length;
|
|
119
|
+
if (index === lastIndex) {
|
|
120
|
+
groups.at(-1).months.push(month);
|
|
121
|
+
groups.at(-1).prompts.push(...list);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
groups.push({ months: [month], prompts: [...list] });
|
|
125
|
+
lastIndex = index;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const total = new Map();
|
|
129
|
+
const counts = groups.map((g) => {
|
|
130
|
+
const c = new Map();
|
|
131
|
+
for (const seen of g.prompts)
|
|
132
|
+
for (const w of seen)
|
|
133
|
+
c.set(w, (c.get(w) ?? 0) + 1);
|
|
134
|
+
for (const [w, n] of c)
|
|
135
|
+
total.set(w, (total.get(w) ?? 0) + n);
|
|
136
|
+
return c;
|
|
137
|
+
});
|
|
138
|
+
return groups
|
|
139
|
+
.map((g, i) => {
|
|
140
|
+
const rest = prompts.length - g.prompts.length;
|
|
141
|
+
const scored = [...counts[i]]
|
|
142
|
+
.filter(([, n]) => n >= 5)
|
|
143
|
+
// How much more often this stretch uses the word than the rest of the year.
|
|
144
|
+
.map(([w, n]) => ({ w, s: n / g.prompts.length / ((total.get(w) - n + 1) / (rest + 1)) }))
|
|
145
|
+
.filter((x) => x.s >= 2)
|
|
146
|
+
.sort((a, b) => b.s - a.s);
|
|
147
|
+
return { from: g.months[0], to: g.months.at(-1), prompts: g.prompts.length, words: scored.slice(0, 6).map((x) => x.w) };
|
|
148
|
+
})
|
|
149
|
+
.filter((c) => c.words.length >= 3);
|
|
150
|
+
}
|
|
92
151
|
function nicknames(tokenized) {
|
|
93
152
|
const counts = new Map(NICKNAMES.map((w) => [w, 0]));
|
|
94
153
|
for (const toks of tokenized)
|
|
@@ -114,8 +173,26 @@ function work(h) {
|
|
|
114
173
|
edits: count("edit"),
|
|
115
174
|
stops: count("stop"),
|
|
116
175
|
languages: [...byLanguage].map(([name, edits]) => ({ name, edits })).sort((a, b) => b.edits - a.edits),
|
|
176
|
+
pushes: count("push"),
|
|
177
|
+
prs: count("pr"),
|
|
178
|
+
deploys: count("deploy"),
|
|
179
|
+
biggestWeek: biggestWeek(h.actions.filter((a) => a.kind === "commit").map((a) => a.at)),
|
|
117
180
|
};
|
|
118
181
|
}
|
|
182
|
+
function biggestWeek(commits) {
|
|
183
|
+
const weeks = new Map();
|
|
184
|
+
for (const at of commits) {
|
|
185
|
+
const monday = new Date(at.getFullYear(), at.getMonth(), at.getDate() - ((at.getDay() + 6) % 7), 12);
|
|
186
|
+
const key = localDay(monday);
|
|
187
|
+
weeks.set(key, (weeks.get(key) ?? 0) + 1);
|
|
188
|
+
}
|
|
189
|
+
const [from, n] = [...weeks].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0] ?? [];
|
|
190
|
+
if (!from || !n)
|
|
191
|
+
return null;
|
|
192
|
+
const sunday = new Date(`${from}T12:00:00`);
|
|
193
|
+
sunday.setDate(sunday.getDate() + 6);
|
|
194
|
+
return { from, to: localDay(sunday), commits: n };
|
|
195
|
+
}
|
|
119
196
|
function agentStats(agent, h) {
|
|
120
197
|
const prompts = h.prompts.filter((p) => p.agent === agent);
|
|
121
198
|
const turns = h.turns.filter((t) => t.agent === agent);
|
|
@@ -310,7 +387,7 @@ function bothAgentDays(prompts) {
|
|
|
310
387
|
set.add(p.agent);
|
|
311
388
|
byDay.set(day, set);
|
|
312
389
|
}
|
|
313
|
-
return [...byDay.values()].filter((s) => s.size
|
|
390
|
+
return [...byDay.values()].filter((s) => s.size >= 2).length;
|
|
314
391
|
}
|
|
315
392
|
function share(part, whole) {
|
|
316
393
|
return whole ? round(part / whole, 3) : 0;
|
package/dist/personality.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
const n = (x) => Math.round(x).toLocaleString("en-US");
|
|
2
|
+
// The two agents you used most, most first.
|
|
3
|
+
function topTwo(w) {
|
|
4
|
+
const { claudeShare, codexShare, cursorShare } = w.loyalty;
|
|
5
|
+
return [{ name: "Claude", share: claudeShare }, { name: "Codex", share: codexShare }, { name: "Cursor", share: cursorShare }]
|
|
6
|
+
.sort((x, y) => y.share - x.share)
|
|
7
|
+
.slice(0, 2);
|
|
8
|
+
}
|
|
2
9
|
const pct = (x) => `${Math.round(x * 100)}%`;
|
|
3
10
|
const perPrompt = (w, count) => (w.totals.prompts ? count / w.totals.prompts : 0);
|
|
4
11
|
const TRAITS = [
|
|
@@ -47,8 +54,11 @@ const TRAITS = [
|
|
|
47
54
|
{
|
|
48
55
|
id: "two-timer",
|
|
49
56
|
name: "The Two-Timer",
|
|
50
|
-
score: (w) =>
|
|
51
|
-
line: (w) =>
|
|
57
|
+
score: (w) => (topTwo(w)[1]?.share ?? 0) / 0.35,
|
|
58
|
+
line: (w) => {
|
|
59
|
+
const [a, b] = topTwo(w);
|
|
60
|
+
return `${a.name} and ${b.name} both on ${n(w.loyalty.bothAgentDays)} days. Neither of them knows about the other.`;
|
|
61
|
+
},
|
|
52
62
|
},
|
|
53
63
|
];
|
|
54
64
|
export function pickPersonality(w) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parentPort, Worker, workerData } from "node:worker_threads";
|
|
2
|
+
import { harvestClaude } from "./sources/claude.js";
|
|
3
|
+
import { harvestCodex } from "./sources/codex.js";
|
|
4
|
+
import { harvestCursor } from "./sources/cursor.js";
|
|
5
|
+
// Reads one agent's logs on a thread of its own, so the screen keeps moving
|
|
6
|
+
// while a large log is read, and all the agents are read at once.
|
|
7
|
+
const SOURCES = { claude: harvestClaude, codex: harvestCodex, cursor: harvestCursor };
|
|
8
|
+
export function readInBackground(source, home) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
// This same file, as .ts in development and .js once built.
|
|
11
|
+
const worker = new Worker(new URL(import.meta.url), { workerData: { source, home } });
|
|
12
|
+
worker.once("message", resolve);
|
|
13
|
+
worker.once("error", reject);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (parentPort && workerData?.source) {
|
|
17
|
+
parentPort.postMessage(SOURCES[workerData.source](workerData.home));
|
|
18
|
+
}
|
package/dist/screen.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { emitKeypressEvents } from "node:readline";
|
|
2
|
+
// What the command shows while it runs, on stderr, so --json output stays
|
|
3
|
+
// clean. In a terminal each step updates in place; piped, it prints plain lines.
|
|
4
|
+
const out = process.stderr;
|
|
5
|
+
const live = out.isTTY === true;
|
|
6
|
+
const color = live && !process.env.NO_COLOR;
|
|
7
|
+
const paint = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
8
|
+
export const dim = paint("2");
|
|
9
|
+
export const bold = paint("1");
|
|
10
|
+
const green = paint("32");
|
|
11
|
+
export function line(text = "") {
|
|
12
|
+
out.write(`${text}\n`);
|
|
13
|
+
}
|
|
14
|
+
function redraw(text) {
|
|
15
|
+
if (live)
|
|
16
|
+
out.write(`\r\x1b[2K${text}`);
|
|
17
|
+
}
|
|
18
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
19
|
+
// Shows `doing` while `work` runs (with a spinner when the work lets the
|
|
20
|
+
// screen redraw), then a tick and what was done.
|
|
21
|
+
export async function step(doing, work, done) {
|
|
22
|
+
const started = Date.now();
|
|
23
|
+
let frame = 0;
|
|
24
|
+
redraw(` ${dim(FRAMES[0])} ${doing}`);
|
|
25
|
+
const spin = live ? setInterval(() => redraw(` ${dim(FRAMES[++frame % FRAMES.length])} ${doing}`), 80) : undefined;
|
|
26
|
+
// Let the first frame draw before work that holds the process.
|
|
27
|
+
await new Promise((r) => setImmediate(r));
|
|
28
|
+
try {
|
|
29
|
+
const result = await work();
|
|
30
|
+
const seconds = (Date.now() - started) / 1000;
|
|
31
|
+
const text = ` ${green("✓")} ${done(result)}${seconds >= 2 ? dim(` ${seconds.toFixed(0)}s`) : ""}`;
|
|
32
|
+
if (live)
|
|
33
|
+
redraw(`${text}\n`);
|
|
34
|
+
else
|
|
35
|
+
line(text);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
clearInterval(spin);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// A choice made with the arrow keys and Enter. Without a terminal to ask in,
|
|
43
|
+
// the first option is the answer.
|
|
44
|
+
export async function choose(question, options) {
|
|
45
|
+
const input = process.stdin;
|
|
46
|
+
if (!live || !input.isTTY)
|
|
47
|
+
return options[0].value;
|
|
48
|
+
let at = 0;
|
|
49
|
+
const draw = () => redraw(` ${bold("?")} ${question} ${options.map((o, i) => (i === at ? bold(`❯ ${o.label}`) : dim(` ${o.label}`))).join(" ")} ${dim("← → Enter")}`);
|
|
50
|
+
emitKeypressEvents(input);
|
|
51
|
+
input.setRawMode(true);
|
|
52
|
+
input.resume();
|
|
53
|
+
draw();
|
|
54
|
+
const value = await new Promise((resolve) => {
|
|
55
|
+
const onKey = (_, key) => {
|
|
56
|
+
if (key.ctrl && key.name === "c") {
|
|
57
|
+
input.setRawMode(false);
|
|
58
|
+
line();
|
|
59
|
+
process.exit(130);
|
|
60
|
+
}
|
|
61
|
+
if (["left", "up"].includes(key.name ?? ""))
|
|
62
|
+
at = (at + options.length - 1) % options.length;
|
|
63
|
+
else if (["right", "down", "tab"].includes(key.name ?? ""))
|
|
64
|
+
at = (at + 1) % options.length;
|
|
65
|
+
else if (key.name === "return") {
|
|
66
|
+
input.off("keypress", onKey);
|
|
67
|
+
resolve(options[at].value);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
draw();
|
|
71
|
+
};
|
|
72
|
+
input.on("keypress", onKey);
|
|
73
|
+
});
|
|
74
|
+
input.setRawMode(false);
|
|
75
|
+
input.pause();
|
|
76
|
+
redraw(` ${green("✓")} ${question} ${dim(options[at].label)}\n`);
|
|
77
|
+
return value;
|
|
78
|
+
}
|
package/dist/sources/claude.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extname, join } from "node:path";
|
|
2
2
|
import { coverage, findFiles, localDay, namesFromPath, readJson, readJsonl, toDate } from "../files.js";
|
|
3
|
-
import {
|
|
3
|
+
import { commandKinds, emptyHarvest } from "../types.js";
|
|
4
4
|
// Claude Code keeps three things in ~/.claude:
|
|
5
5
|
// - history.jsonl: every prompt typed, kept long term
|
|
6
6
|
// - stats-cache.json: older token totals per model, up to `lastComputedDate`
|
|
@@ -115,9 +115,9 @@ function actionsIn(row) {
|
|
|
115
115
|
const path = b.input?.file_path ?? b.input?.notebook_path;
|
|
116
116
|
if (EDIT_TOOLS.has(b.name) && typeof path === "string")
|
|
117
117
|
out.push([b.id, { kind: "edit", ext: extname(path).toLowerCase() }]);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
if (b.name === "Bash")
|
|
119
|
+
for (const kind of commandKinds(String(b.input?.command ?? "")))
|
|
120
|
+
out.push([`${b.id}|${kind}`, { kind }]);
|
|
121
121
|
}
|
|
122
122
|
return out;
|
|
123
123
|
}
|
package/dist/sources/codex.js
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import { extname, join } from "node:path";
|
|
3
3
|
import { DatabaseSync } from "node:sqlite";
|
|
4
4
|
import { coverage, lastJsonLine, namesFromGitUrl, namesFromPath, toDate } from "../files.js";
|
|
5
|
-
import {
|
|
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
|
|
8
8
|
// - thread_history_N.sqlite: every message and turn, kept long term
|
|
@@ -110,8 +110,7 @@ export function harvestCodex(home) {
|
|
|
110
110
|
h.actions.push({ agent: "codex", at, kind: "edit", ext: extname(path).toLowerCase() });
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
const kind
|
|
114
|
-
if (kind)
|
|
113
|
+
for (const kind of commandKinds(firstString(item.head, "command") ?? ""))
|
|
115
114
|
h.actions.push({ agent: "codex", at, kind });
|
|
116
115
|
}
|
|
117
116
|
}
|