@shadevkumar/agent-wrapped 0.0.0-stage → 0.2.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/LICENSE +25 -0
- package/README.md +71 -2
- package/dist/build.js +50 -0
- package/dist/cli.js +48 -0
- package/dist/files.js +114 -0
- package/dist/letter.js +64 -0
- package/dist/moments.js +324 -0
- package/dist/personality.js +65 -0
- package/dist/pricing.js +97 -0
- package/dist/sources/claude.js +139 -0
- package/dist/sources/codex.js +196 -0
- package/dist/story/fonts/OFL-Geist.txt +93 -0
- package/dist/story/fonts/OFL-Newsreader.txt +93 -0
- package/dist/story/fonts/geist-normal.woff2 +0 -0
- package/dist/story/fonts/newsreader-italic.woff2 +0 -0
- package/dist/story/fonts/newsreader-normal.woff2 +0 -0
- package/dist/story/index.html +318 -0
- package/dist/story/story.js +1274 -0
- package/dist/story.js +47 -0
- package/dist/types.js +33 -0
- package/dist/words.js +234 -0
- package/package.json +46 -4
package/dist/moments.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { localDay } from "./files.js";
|
|
2
|
+
import { apiCost, PRICES_AS_OF } from "./pricing.js";
|
|
3
|
+
import { usageTokens } from "./types.js";
|
|
4
|
+
import { findTypos, keySlips, tokenize, Words } from "./words.js";
|
|
5
|
+
const LATE_NIGHT_END_HOUR = 5;
|
|
6
|
+
// Repeats under a second apart are the logs writing a message twice, not a person.
|
|
7
|
+
const DOUBLE_SEND_MIN_MS = 1_000;
|
|
8
|
+
const DOUBLE_SEND_MAX_MS = 120_000;
|
|
9
|
+
// The same ten words in a row in three or more prompts is pasted text, not habit.
|
|
10
|
+
const PASTE_WINDOW = 10;
|
|
11
|
+
const PASTE_MIN_PROMPTS = 3;
|
|
12
|
+
const LEXICON = {
|
|
13
|
+
okay: ["okay", "ok"],
|
|
14
|
+
please: ["please", "pls", "plz"],
|
|
15
|
+
thanks: ["thanks", "thank", "thx"],
|
|
16
|
+
sorry: ["sorry"],
|
|
17
|
+
bro: ["bro", "dude", "man"],
|
|
18
|
+
why: ["why"],
|
|
19
|
+
again: ["again"],
|
|
20
|
+
wait: ["wait"],
|
|
21
|
+
perfect: ["perfect", "great", "awesome", "nice"],
|
|
22
|
+
};
|
|
23
|
+
const NICKNAMES = ["dude", "bro", "man", "buddy", "mate", "bhai", "boss", "chief", "fam"];
|
|
24
|
+
const CHECK_IN = /\b(okay|ok|right)\s*\?/i;
|
|
25
|
+
// File types that are code, by the language they're written in.
|
|
26
|
+
const LANGUAGES = {
|
|
27
|
+
".py": "Python", ".ts": "TypeScript", ".tsx": "TypeScript", ".js": "JavaScript", ".jsx": "JavaScript",
|
|
28
|
+
".mjs": "JavaScript", ".cjs": "JavaScript", ".go": "Go", ".rs": "Rust", ".rb": "Ruby", ".java": "Java",
|
|
29
|
+
".kt": "Kotlin", ".swift": "Swift", ".c": "C", ".h": "C", ".cpp": "C++", ".cc": "C++", ".hpp": "C++",
|
|
30
|
+
".cs": "C#", ".php": "PHP", ".dart": "Dart", ".scala": "Scala", ".ex": "Elixir", ".exs": "Elixir",
|
|
31
|
+
".lua": "Lua", ".sql": "SQL", ".sh": "Shell", ".css": "CSS", ".scss": "CSS", ".html": "HTML",
|
|
32
|
+
".vue": "Vue", ".svelte": "Svelte",
|
|
33
|
+
};
|
|
34
|
+
export function computeWrapped(h, words = new Words(h.privateNames)) {
|
|
35
|
+
const prompts = [...h.prompts].sort((a, b) => a.at.getTime() - b.at.getTime());
|
|
36
|
+
const tokenized = prompts.map((p) => tokenize(p.text));
|
|
37
|
+
const counts = new Map();
|
|
38
|
+
for (const toks of tokenized)
|
|
39
|
+
for (const w of toks)
|
|
40
|
+
counts.set(w, (counts.get(w) ?? 0) + 1);
|
|
41
|
+
const { families, canonical } = findTypos(counts, words);
|
|
42
|
+
const canon = (toks) => toks.map((w) => canonical.get(w) ?? w);
|
|
43
|
+
const canonPrompts = tokenized.map(canon);
|
|
44
|
+
const pasted = pastedTokens(canonPrompts);
|
|
45
|
+
const lengths = tokenized.map((t) => t.length).sort((a, b) => a - b);
|
|
46
|
+
const days = [...new Set(prompts.map((p) => localDay(p.at)))].sort();
|
|
47
|
+
const cost = apiCost(h.usage, h.totals);
|
|
48
|
+
const agents = { claude: agentStats("claude", h), codex: agentStats("codex", h) };
|
|
49
|
+
return {
|
|
50
|
+
coverage: h.coverage.map((c) => ({
|
|
51
|
+
agent: c.agent,
|
|
52
|
+
source: c.source,
|
|
53
|
+
count: c.count,
|
|
54
|
+
from: c.from ? localDay(c.from) : null,
|
|
55
|
+
to: c.to ? localDay(c.to) : null,
|
|
56
|
+
})),
|
|
57
|
+
totals: {
|
|
58
|
+
prompts: prompts.length,
|
|
59
|
+
sessions: agents.claude.sessions + agents.codex.sessions,
|
|
60
|
+
activeDays: days.length,
|
|
61
|
+
firstDay: days[0] ?? null,
|
|
62
|
+
lastDay: days.at(-1) ?? null,
|
|
63
|
+
agentHours: round(agents.claude.agentHours + agents.codex.agentHours, 1),
|
|
64
|
+
tokens: agents.claude.tokens + agents.codex.tokens,
|
|
65
|
+
},
|
|
66
|
+
agents,
|
|
67
|
+
cost: { ...cost, pricesAsOf: PRICES_AS_OF },
|
|
68
|
+
rhythm: rhythm(prompts, days),
|
|
69
|
+
voice: {
|
|
70
|
+
topPrompts: topPrompts(canonPrompts, words, canonical),
|
|
71
|
+
catchphrases: catchphrases(prompts, canonPrompts, pasted, words, canonical),
|
|
72
|
+
typos: families.slice(0, 10),
|
|
73
|
+
typoCount: families.reduce((s, f) => s + f.total, 0),
|
|
74
|
+
topTypo: topTypo(families),
|
|
75
|
+
keySlips: keySlips(families),
|
|
76
|
+
shortShare: share(tokenized.filter((t) => t.length > 0 && t.length <= 3).length, prompts.length),
|
|
77
|
+
medianWords: lengths[Math.floor(lengths.length / 2)] ?? 0,
|
|
78
|
+
pastedShare: share(pasted.filter((flags) => flags.some(Boolean)).length, prompts.length),
|
|
79
|
+
doubleSends: doubleSends(prompts),
|
|
80
|
+
lexicon: lexicon(tokenized),
|
|
81
|
+
nicknames: nicknames(tokenized),
|
|
82
|
+
checkIns: prompts.filter((p) => CHECK_IN.test(p.text)).length,
|
|
83
|
+
},
|
|
84
|
+
loyalty: {
|
|
85
|
+
claudeShare: share(agents.claude.prompts, prompts.length),
|
|
86
|
+
codexShare: share(agents.codex.prompts, prompts.length),
|
|
87
|
+
bothAgentDays: bothAgentDays(prompts),
|
|
88
|
+
},
|
|
89
|
+
work: work(h),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function nicknames(tokenized) {
|
|
93
|
+
const counts = new Map(NICKNAMES.map((w) => [w, 0]));
|
|
94
|
+
for (const toks of tokenized)
|
|
95
|
+
for (const w of toks)
|
|
96
|
+
if (counts.has(w))
|
|
97
|
+
counts.set(w, counts.get(w) + 1);
|
|
98
|
+
return [...counts].filter(([, n]) => n > 0).map(([word, count]) => ({ word, count })).sort((a, b) => b.count - a.count);
|
|
99
|
+
}
|
|
100
|
+
function work(h) {
|
|
101
|
+
const count = (kind) => h.actions.filter((a) => a.kind === kind).length;
|
|
102
|
+
const byLanguage = new Map();
|
|
103
|
+
for (const a of h.actions) {
|
|
104
|
+
const name = a.kind === "edit" && a.ext ? LANGUAGES[a.ext] : undefined;
|
|
105
|
+
if (name)
|
|
106
|
+
byLanguage.set(name, (byLanguage.get(name) ?? 0) + 1);
|
|
107
|
+
}
|
|
108
|
+
// Stops are kept far longer than the rest, so they don't move the start.
|
|
109
|
+
const first = h.actions.reduce((min, a) => (a.kind !== "stop" && (!min || a.at < min) ? a.at : min), null);
|
|
110
|
+
return {
|
|
111
|
+
since: first ? localDay(first) : null,
|
|
112
|
+
tests: count("test"),
|
|
113
|
+
commits: count("commit"),
|
|
114
|
+
edits: count("edit"),
|
|
115
|
+
stops: count("stop"),
|
|
116
|
+
languages: [...byLanguage].map(([name, edits]) => ({ name, edits })).sort((a, b) => b.edits - a.edits),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function agentStats(agent, h) {
|
|
120
|
+
const prompts = h.prompts.filter((p) => p.agent === agent);
|
|
121
|
+
const turns = h.turns.filter((t) => t.agent === agent);
|
|
122
|
+
const byModel = new Map();
|
|
123
|
+
for (const u of h.usage)
|
|
124
|
+
if (u.agent === agent)
|
|
125
|
+
byModel.set(u.model, (byModel.get(u.model) ?? 0) + usageTokens(u));
|
|
126
|
+
for (const t of h.totals)
|
|
127
|
+
if (t.agent === agent)
|
|
128
|
+
byModel.set(t.model, (byModel.get(t.model) ?? 0) + t.tokens);
|
|
129
|
+
const models = [...byModel].map(([model, tokens]) => ({ model, tokens })).sort((a, b) => b.tokens - a.tokens);
|
|
130
|
+
return {
|
|
131
|
+
prompts: prompts.length,
|
|
132
|
+
sessions: new Set(prompts.map((p) => p.session)).size,
|
|
133
|
+
tokens: models.reduce((s, m) => s + m.tokens, 0),
|
|
134
|
+
agentHours: round(turns.reduce((s, t) => s + t.durationMs, 0) / 3_600_000, 1),
|
|
135
|
+
longestTurnMinutes: round(Math.max(0, ...turns.map((t) => t.durationMs)) / 60_000, 1),
|
|
136
|
+
models,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function rhythm(prompts, days) {
|
|
140
|
+
const byHour = new Array(24).fill(0);
|
|
141
|
+
const byWeekday = new Array(7).fill(0);
|
|
142
|
+
const perDay = new Map();
|
|
143
|
+
let late = 0;
|
|
144
|
+
let latestMinute = -1;
|
|
145
|
+
for (const p of prompts) {
|
|
146
|
+
const hour = p.at.getHours();
|
|
147
|
+
byHour[hour]++;
|
|
148
|
+
byWeekday[p.at.getDay()]++;
|
|
149
|
+
const day = localDay(p.at);
|
|
150
|
+
perDay.set(day, (perDay.get(day) ?? 0) + 1);
|
|
151
|
+
if (hour < LATE_NIGHT_END_HOUR) {
|
|
152
|
+
late++;
|
|
153
|
+
latestMinute = Math.max(latestMinute, hour * 60 + p.at.getMinutes());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const busiest = [...perDay].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0];
|
|
157
|
+
return {
|
|
158
|
+
byHour,
|
|
159
|
+
byWeekday,
|
|
160
|
+
busiestDay: busiest ? { day: busiest[0], prompts: busiest[1] } : null,
|
|
161
|
+
longestStreak: longestStreak(days),
|
|
162
|
+
lateNight: {
|
|
163
|
+
prompts: late,
|
|
164
|
+
share: share(late, prompts.length),
|
|
165
|
+
latest: latestMinute < 0 ? null : `${pad(Math.floor(latestMinute / 60))}:${pad(latestMinute % 60)}`,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// `days` are sorted, unique local days (YYYY-MM-DD).
|
|
170
|
+
export function longestStreak(days) {
|
|
171
|
+
if (days.length === 0)
|
|
172
|
+
return null;
|
|
173
|
+
let best = { days: 1, from: days[0], to: days[0] };
|
|
174
|
+
let run = { days: 1, from: days[0] };
|
|
175
|
+
for (let i = 1; i < days.length; i++) {
|
|
176
|
+
const gap = (Date.parse(days[i]) - Date.parse(days[i - 1])) / 86_400_000;
|
|
177
|
+
run = gap === 1 ? { days: run.days + 1, from: run.from } : { days: 1, from: days[i] };
|
|
178
|
+
if (run.days > best.days)
|
|
179
|
+
best = { days: run.days, from: run.from, to: days[i] };
|
|
180
|
+
}
|
|
181
|
+
return best;
|
|
182
|
+
}
|
|
183
|
+
function topPrompts(canonPrompts, words, typos) {
|
|
184
|
+
const counts = new Map();
|
|
185
|
+
for (const toks of canonPrompts) {
|
|
186
|
+
if (toks.length === 0 || toks.length > 6)
|
|
187
|
+
continue;
|
|
188
|
+
const key = toks.join(" ");
|
|
189
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
190
|
+
}
|
|
191
|
+
return [...counts]
|
|
192
|
+
.filter(([, n]) => n >= 3)
|
|
193
|
+
.sort((a, b) => b[1] - a[1])
|
|
194
|
+
.flatMap(([text, count]) => {
|
|
195
|
+
const safe = words.safeQuote(text, typos);
|
|
196
|
+
return safe ? [{ text: safe, count }] : [];
|
|
197
|
+
})
|
|
198
|
+
.slice(0, 8);
|
|
199
|
+
}
|
|
200
|
+
// For each prompt, which words belong to text that was pasted into other prompts.
|
|
201
|
+
export function pastedTokens(canonPrompts) {
|
|
202
|
+
const windowsPerPrompt = canonPrompts.map((toks) => {
|
|
203
|
+
const set = new Set();
|
|
204
|
+
for (let s = 0; s + PASTE_WINDOW <= toks.length; s++)
|
|
205
|
+
set.add(toks.slice(s, s + PASTE_WINDOW).join(" "));
|
|
206
|
+
return set;
|
|
207
|
+
});
|
|
208
|
+
const seenIn = new Map();
|
|
209
|
+
for (const set of windowsPerPrompt)
|
|
210
|
+
for (const w of set)
|
|
211
|
+
seenIn.set(w, (seenIn.get(w) ?? 0) + 1);
|
|
212
|
+
return canonPrompts.map((toks) => {
|
|
213
|
+
const flags = new Array(toks.length).fill(false);
|
|
214
|
+
for (let s = 0; s + PASTE_WINDOW <= toks.length; s++) {
|
|
215
|
+
if ((seenIn.get(toks.slice(s, s + PASTE_WINDOW).join(" ")) ?? 0) >= PASTE_MIN_PROMPTS) {
|
|
216
|
+
flags.fill(true, s, s + PASTE_WINDOW);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return flags;
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
// Phrases of 3-5 words typed in at least three different sessions. Pasted text
|
|
223
|
+
// doesn't count. A longer phrase replaces a shorter one inside it when it
|
|
224
|
+
// explains most of its uses.
|
|
225
|
+
function catchphrases(prompts, canonPrompts, pasted, words, typos) {
|
|
226
|
+
const grams = new Map();
|
|
227
|
+
canonPrompts.forEach((toks, i) => {
|
|
228
|
+
const seen = new Set();
|
|
229
|
+
for (let n = 3; n <= 5; n++) {
|
|
230
|
+
for (let s = 0; s + n <= toks.length; s++) {
|
|
231
|
+
if (pasted[i].slice(s, s + n).some(Boolean))
|
|
232
|
+
continue;
|
|
233
|
+
const g = toks.slice(s, s + n);
|
|
234
|
+
if (words.isStopword(g[0]) || words.isStopword(g.at(-1)))
|
|
235
|
+
continue;
|
|
236
|
+
const key = g.join(" ");
|
|
237
|
+
if (seen.has(key))
|
|
238
|
+
continue;
|
|
239
|
+
seen.add(key);
|
|
240
|
+
const entry = grams.get(key) ?? { n, sessions: new Set(), uses: 0 };
|
|
241
|
+
entry.sessions.add(`${prompts[i].agent}:${prompts[i].session}`);
|
|
242
|
+
entry.uses++;
|
|
243
|
+
grams.set(key, entry);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
const candidates = [...grams]
|
|
248
|
+
.filter(([, g]) => g.sessions.size >= 3 && g.uses >= 4)
|
|
249
|
+
.sort((a, b) => b[1].n - a[1].n);
|
|
250
|
+
const kept = [];
|
|
251
|
+
for (const [text, g] of candidates) {
|
|
252
|
+
const covered = kept.some(([longer, sessions]) => ` ${longer} `.includes(` ${text} `) && sessions >= g.sessions.size * 0.8);
|
|
253
|
+
if (!covered)
|
|
254
|
+
kept.push([text, g.sessions.size]);
|
|
255
|
+
}
|
|
256
|
+
return kept
|
|
257
|
+
.sort((a, b) => b[1] - a[1])
|
|
258
|
+
.flatMap(([text, sessions]) => {
|
|
259
|
+
const safe = words.safeQuote(text, typos);
|
|
260
|
+
return safe ? [{ text: safe, sessions }] : [];
|
|
261
|
+
})
|
|
262
|
+
.slice(0, 10);
|
|
263
|
+
}
|
|
264
|
+
function topTypo(families) {
|
|
265
|
+
let best = null;
|
|
266
|
+
for (const f of families) {
|
|
267
|
+
for (const s of f.spellings)
|
|
268
|
+
if (!best || s.count > best.count)
|
|
269
|
+
best = { spelling: s.spelling, word: f.word, count: s.count };
|
|
270
|
+
}
|
|
271
|
+
return best;
|
|
272
|
+
}
|
|
273
|
+
// The same message sent again in the same session within two minutes.
|
|
274
|
+
export function doubleSends(sorted) {
|
|
275
|
+
const last = new Map();
|
|
276
|
+
let count = 0;
|
|
277
|
+
for (const p of sorted) {
|
|
278
|
+
const key = `${p.agent}:${p.session}`;
|
|
279
|
+
const prev = last.get(key);
|
|
280
|
+
const gap = prev ? p.at.getTime() - prev.at.getTime() : -1;
|
|
281
|
+
if (prev && prev.text.trim() === p.text.trim() && gap >= DOUBLE_SEND_MIN_MS && gap <= DOUBLE_SEND_MAX_MS) {
|
|
282
|
+
count++;
|
|
283
|
+
}
|
|
284
|
+
last.set(key, p);
|
|
285
|
+
}
|
|
286
|
+
return count;
|
|
287
|
+
}
|
|
288
|
+
function lexicon(tokenized) {
|
|
289
|
+
const out = {};
|
|
290
|
+
const lookup = new Map();
|
|
291
|
+
for (const [group, list] of Object.entries(LEXICON)) {
|
|
292
|
+
out[group] = 0;
|
|
293
|
+
for (const w of list)
|
|
294
|
+
lookup.set(w, group);
|
|
295
|
+
}
|
|
296
|
+
for (const toks of tokenized) {
|
|
297
|
+
for (const w of toks) {
|
|
298
|
+
const group = lookup.get(w);
|
|
299
|
+
if (group)
|
|
300
|
+
out[group]++;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
function bothAgentDays(prompts) {
|
|
306
|
+
const byDay = new Map();
|
|
307
|
+
for (const p of prompts) {
|
|
308
|
+
const day = localDay(p.at);
|
|
309
|
+
const set = byDay.get(day) ?? new Set();
|
|
310
|
+
set.add(p.agent);
|
|
311
|
+
byDay.set(day, set);
|
|
312
|
+
}
|
|
313
|
+
return [...byDay.values()].filter((s) => s.size === 2).length;
|
|
314
|
+
}
|
|
315
|
+
function share(part, whole) {
|
|
316
|
+
return whole ? round(part / whole, 3) : 0;
|
|
317
|
+
}
|
|
318
|
+
function round(n, digits) {
|
|
319
|
+
const f = 10 ** digits;
|
|
320
|
+
return Math.round(n * f) / f;
|
|
321
|
+
}
|
|
322
|
+
function pad(n) {
|
|
323
|
+
return String(n).padStart(2, "0");
|
|
324
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const n = (x) => Math.round(x).toLocaleString("en-US");
|
|
2
|
+
const pct = (x) => `${Math.round(x * 100)}%`;
|
|
3
|
+
const perPrompt = (w, count) => (w.totals.prompts ? count / w.totals.prompts : 0);
|
|
4
|
+
const TRAITS = [
|
|
5
|
+
{
|
|
6
|
+
id: "midnight-foreman",
|
|
7
|
+
name: "The Midnight Foreman",
|
|
8
|
+
score: (w) => w.rhythm.lateNight.share / 0.08,
|
|
9
|
+
line: (w) => `You gave ${n(w.rhythm.lateNight.prompts)} orders after midnight, and your agents kept working while the city slept.`,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
id: "one-word-director",
|
|
13
|
+
name: "The One-Word Director",
|
|
14
|
+
score: (w) => w.voice.shortShare / 0.25,
|
|
15
|
+
line: (w) => `${pct(w.voice.shortShare)} of your prompts were three words or fewer. Your agents learned to read minds.`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "copy-paste-architect",
|
|
19
|
+
name: "The Copy-Paste Architect",
|
|
20
|
+
score: (w) => w.voice.pastedShare / 0.15,
|
|
21
|
+
line: (w) => `${pct(w.voice.pastedShare)} of your prompts reused text you had pasted before. You don't repeat yourself. You reuse yourself.`,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "fast-fingers",
|
|
25
|
+
name: "Fast Fingers",
|
|
26
|
+
score: (w) => (perPrompt(w, w.voice.typoCount) * 100) / 15,
|
|
27
|
+
line: (w) => `${n(w.voice.typoCount)} typos and your agents understood every one. Speed over spelling.`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "polite-commander",
|
|
31
|
+
name: "The Polite Commander",
|
|
32
|
+
score: (w) => perPrompt(w, (w.voice.lexicon.please ?? 0) + (w.voice.lexicon.thanks ?? 0)) / 0.15,
|
|
33
|
+
line: (w) => `You said please ${n(w.voice.lexicon.please ?? 0)} times. When the machines rise, they will remember you kindly.`,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "interrogator",
|
|
37
|
+
name: "The Interrogator",
|
|
38
|
+
score: (w) => perPrompt(w, (w.voice.lexicon.why ?? 0) + (w.voice.lexicon.again ?? 0)) / 0.15,
|
|
39
|
+
line: (w) => `You asked why ${n(w.voice.lexicon.why ?? 0)} times. No answer went unchecked.`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "marathoner",
|
|
43
|
+
name: "The Marathoner",
|
|
44
|
+
score: (w) => (w.rhythm.longestStreak?.days ?? 0) / 21,
|
|
45
|
+
line: (w) => `${w.rhythm.longestStreak?.days ?? 0} days in a row without a single day off from your agents.`,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "two-timer",
|
|
49
|
+
name: "The Two-Timer",
|
|
50
|
+
score: (w) => Math.min(w.loyalty.claudeShare, w.loyalty.codexShare) / 0.35,
|
|
51
|
+
line: (w) => `Claude and Codex both on ${n(w.loyalty.bothAgentDays)} days. Neither of them knows about the other.`,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
export function pickPersonality(w) {
|
|
55
|
+
const ranked = TRAITS.map((t) => ({ t, s: t.score(w) }))
|
|
56
|
+
.filter((x) => Number.isFinite(x.s))
|
|
57
|
+
.sort((a, b) => b.s - a.s);
|
|
58
|
+
const top = ranked[0].t;
|
|
59
|
+
return {
|
|
60
|
+
id: top.id,
|
|
61
|
+
name: top.name,
|
|
62
|
+
line: top.line(w),
|
|
63
|
+
traits: ranked.slice(1, 3).filter((x) => x.s >= 1).map((x) => x.t.name),
|
|
64
|
+
};
|
|
65
|
+
}
|
package/dist/pricing.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { usageTokens } from "./types.js";
|
|
2
|
+
// What the same work would cost on the public API, in USD per million tokens.
|
|
3
|
+
// Standard tier, short context. Prices from the official pages, read 2026-10-28:
|
|
4
|
+
// https://platform.claude.com/docs/en/about-claude/pricing
|
|
5
|
+
// https://developers.openai.com/api/docs/pricing
|
|
6
|
+
// Long-context surcharges are not applied, so every figure here is a floor.
|
|
7
|
+
export const PRICES_AS_OF = "2026-10-28";
|
|
8
|
+
const claude = (input, w5m, w1h, read, output) => ({
|
|
9
|
+
input,
|
|
10
|
+
cacheRead: read,
|
|
11
|
+
cacheWrite: w5m,
|
|
12
|
+
cacheWrite1h: w1h,
|
|
13
|
+
output,
|
|
14
|
+
});
|
|
15
|
+
// OpenAI doesn't charge extra to write the cache.
|
|
16
|
+
const openai = (input, cached, output) => ({
|
|
17
|
+
input,
|
|
18
|
+
cacheRead: cached,
|
|
19
|
+
cacheWrite: input,
|
|
20
|
+
cacheWrite1h: input,
|
|
21
|
+
output,
|
|
22
|
+
});
|
|
23
|
+
// Matched by prefix, so dated ids like claude-opus-4-5-20251101 find their row.
|
|
24
|
+
const PRICES = [
|
|
25
|
+
["claude-fable-5-1", claude(10, 12.5, 20, 0.25, 50)],
|
|
26
|
+
["claude-fable-5", claude(10, 12.5, 20, 1, 50)],
|
|
27
|
+
["claude-opus-5-5", claude(4, 5, 8, 0.2, 20)],
|
|
28
|
+
["claude-opus-5", claude(5, 6.25, 10, 0.5, 25)],
|
|
29
|
+
["claude-opus-4-8", claude(5, 6.25, 10, 0.5, 25)],
|
|
30
|
+
["claude-opus-4-7", claude(5, 6.25, 10, 0.5, 25)],
|
|
31
|
+
["claude-opus-4-6", claude(5, 6.25, 10, 0.5, 25)],
|
|
32
|
+
["claude-opus-4-5", claude(5, 6.25, 10, 0.5, 25)],
|
|
33
|
+
["claude-sonnet-5-5", claude(2, 2.5, 4, 0.1, 10)],
|
|
34
|
+
["claude-sonnet-5", claude(2, 2.5, 4, 0.2, 10)],
|
|
35
|
+
["claude-sonnet-4-6", claude(3, 3.75, 6, 0.3, 15)],
|
|
36
|
+
["claude-sonnet-4-5", claude(3, 3.75, 6, 0.3, 15)],
|
|
37
|
+
["claude-haiku-5-5", claude(0.1, 0.125, 0.2, 0.01, 0.5)],
|
|
38
|
+
["claude-haiku-4-5", claude(1, 1.25, 2, 0.1, 5)],
|
|
39
|
+
["gpt-6-astra", openai(10, 1, 50)],
|
|
40
|
+
["gpt-6.1-sol", openai(2, 0.1, 10)],
|
|
41
|
+
["gpt-6.1-terra", openai(1, 0.05, 5)],
|
|
42
|
+
["gpt-6-sol", openai(2, 0.2, 10)],
|
|
43
|
+
["gpt-6-luna", openai(0.1, 0.01, 0.5)],
|
|
44
|
+
["gpt-5.6-sol", openai(4, 0.4, 20)], // promotional price, at least until 2026-11-21
|
|
45
|
+
["gpt-5.6-terra", openai(2, 0.2, 12)],
|
|
46
|
+
["gpt-5.6-luna", openai(0.2, 0.02, 1.2)],
|
|
47
|
+
["gpt-5.5", openai(5, 0.5, 30)],
|
|
48
|
+
["gpt-5.4", openai(2.5, 0.25, 15)],
|
|
49
|
+
];
|
|
50
|
+
export function priceFor(model) {
|
|
51
|
+
// Longest prefix first, so "claude-opus-5-5" wins over "claude-opus-5".
|
|
52
|
+
const hit = [...PRICES]
|
|
53
|
+
.sort((a, b) => b[0].length - a[0].length)
|
|
54
|
+
.find(([prefix]) => model === prefix || model.startsWith(prefix + "-"));
|
|
55
|
+
return hit ? hit[1] : null;
|
|
56
|
+
}
|
|
57
|
+
export function apiCost(usage, totals) {
|
|
58
|
+
const c = {
|
|
59
|
+
exactUsd: 0,
|
|
60
|
+
exactTokens: 0,
|
|
61
|
+
floorUsd: 0,
|
|
62
|
+
floorTokens: 0,
|
|
63
|
+
unpricedTokens: 0,
|
|
64
|
+
unpricedModels: [],
|
|
65
|
+
atLeastUsd: 0,
|
|
66
|
+
};
|
|
67
|
+
const unpriced = new Set();
|
|
68
|
+
for (const u of usage) {
|
|
69
|
+
const p = priceFor(u.model);
|
|
70
|
+
if (!p) {
|
|
71
|
+
c.unpricedTokens += usageTokens(u);
|
|
72
|
+
unpriced.add(u.model);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
c.exactTokens += usageTokens(u);
|
|
76
|
+
c.exactUsd +=
|
|
77
|
+
(u.input * p.input +
|
|
78
|
+
u.cacheRead * p.cacheRead +
|
|
79
|
+
u.cacheWrite * p.cacheWrite +
|
|
80
|
+
u.cacheWrite1h * p.cacheWrite1h +
|
|
81
|
+
u.output * p.output) /
|
|
82
|
+
1e6;
|
|
83
|
+
}
|
|
84
|
+
for (const t of totals) {
|
|
85
|
+
const p = priceFor(t.model);
|
|
86
|
+
if (!p) {
|
|
87
|
+
c.unpricedTokens += t.tokens;
|
|
88
|
+
unpriced.add(t.model);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
c.floorTokens += t.tokens;
|
|
92
|
+
c.floorUsd += (t.tokens * p.cacheRead) / 1e6;
|
|
93
|
+
}
|
|
94
|
+
c.unpricedModels = [...unpriced].sort();
|
|
95
|
+
c.atLeastUsd = c.exactUsd + c.floorUsd;
|
|
96
|
+
return c;
|
|
97
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { extname, join } from "node:path";
|
|
2
|
+
import { coverage, findFiles, localDay, namesFromPath, readJson, readJsonl, toDate } from "../files.js";
|
|
3
|
+
import { commandKind, emptyHarvest } from "../types.js";
|
|
4
|
+
// Claude Code keeps three things in ~/.claude:
|
|
5
|
+
// - history.jsonl: every prompt typed, kept long term
|
|
6
|
+
// - stats-cache.json: older token totals per model, up to `lastComputedDate`
|
|
7
|
+
// - projects/**/*.jsonl: full transcripts, cleaned up after about 30 days
|
|
8
|
+
export function harvestClaude(home) {
|
|
9
|
+
const root = join(home, ".claude");
|
|
10
|
+
const h = emptyHarvest();
|
|
11
|
+
for (const row of readJsonl(join(root, "history.jsonl"))) {
|
|
12
|
+
if (typeof row.project === "string")
|
|
13
|
+
addNames(h, namesFromPath(row.project));
|
|
14
|
+
const at = toDate(row.timestamp);
|
|
15
|
+
const text = cleanClaudePrompt(String(row.display ?? ""));
|
|
16
|
+
if (!at || !text)
|
|
17
|
+
continue;
|
|
18
|
+
h.prompts.push({ agent: "claude", text, at, session: String(row.sessionId ?? "") });
|
|
19
|
+
}
|
|
20
|
+
h.coverage.push(coverage("claude", "prompts", h.prompts.map((p) => p.at)));
|
|
21
|
+
// Transcript replies on or before this day are already inside the stats totals.
|
|
22
|
+
const stats = readJson(join(root, "stats-cache.json"));
|
|
23
|
+
const statsDay = typeof stats?.lastComputedDate === "string" ? stats.lastComputedDate : null;
|
|
24
|
+
const statsAt = statsDay ? toDate(`${statsDay}T12:00:00`) : null;
|
|
25
|
+
if (stats && statsAt) {
|
|
26
|
+
for (const [model, u] of Object.entries(stats.modelUsage ?? {})) {
|
|
27
|
+
h.usage.push({
|
|
28
|
+
agent: "claude",
|
|
29
|
+
model,
|
|
30
|
+
at: statsAt,
|
|
31
|
+
input: num(u.inputTokens),
|
|
32
|
+
cacheRead: num(u.cacheReadInputTokens),
|
|
33
|
+
cacheWrite: num(u.cacheCreationInputTokens),
|
|
34
|
+
cacheWrite1h: 0,
|
|
35
|
+
output: num(u.outputTokens),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const days = (stats.dailyActivity ?? []).map((d) => toDate(`${d?.date}T12:00:00`)).filter(Boolean);
|
|
39
|
+
h.coverage.push(coverage("claude", "older token totals", days));
|
|
40
|
+
}
|
|
41
|
+
// Claude Code writes one line per content block, each repeating the reply's
|
|
42
|
+
// usage, and copies history into resumed sessions. Count each reply once.
|
|
43
|
+
const replies = new Map();
|
|
44
|
+
const turnIds = new Set();
|
|
45
|
+
const actionIds = new Set();
|
|
46
|
+
// Only replies, turn timings and stops matter here; tool output and
|
|
47
|
+
// attachments, most of each file, are skipped without being decoded.
|
|
48
|
+
const relevant = (line) => line.includes('"type":"assistant"') || line.includes('"turn_duration"') || line.includes(INTERRUPTED);
|
|
49
|
+
for (const file of findFiles(join(root, "projects"), ".jsonl")) {
|
|
50
|
+
for (const row of readJsonl(file, relevant)) {
|
|
51
|
+
if (typeof row.cwd === "string")
|
|
52
|
+
addNames(h, namesFromPath(row.cwd));
|
|
53
|
+
const at = toDate(row.timestamp);
|
|
54
|
+
if (!at)
|
|
55
|
+
continue;
|
|
56
|
+
// What the agent did, and when it was stopped, counts once each, even
|
|
57
|
+
// when a resumed session copies it.
|
|
58
|
+
for (const [id, action] of actionsIn(row)) {
|
|
59
|
+
if (actionIds.has(id))
|
|
60
|
+
continue;
|
|
61
|
+
actionIds.add(id);
|
|
62
|
+
h.actions.push({ agent: "claude", at, ...action });
|
|
63
|
+
}
|
|
64
|
+
if (statsDay && localDay(at) <= statsDay)
|
|
65
|
+
continue;
|
|
66
|
+
if (row.type === "system" && row.subtype === "turn_duration" && num(row.durationMs) > 0) {
|
|
67
|
+
const id = String(row.uuid ?? `${row.sessionId}|${row.timestamp}`);
|
|
68
|
+
if (!turnIds.has(id)) {
|
|
69
|
+
turnIds.add(id);
|
|
70
|
+
h.turns.push({ agent: "claude", at, durationMs: num(row.durationMs) });
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const m = row.type === "assistant" ? row.message : null;
|
|
75
|
+
if (!m?.usage || typeof m.model !== "string" || m.model === "<synthetic>")
|
|
76
|
+
continue;
|
|
77
|
+
const writes = num(m.usage.cache_creation_input_tokens);
|
|
78
|
+
const writes1h = Math.min(writes, num(m.usage.cache_creation?.ephemeral_1h_input_tokens));
|
|
79
|
+
const usage = {
|
|
80
|
+
agent: "claude",
|
|
81
|
+
model: m.model,
|
|
82
|
+
at,
|
|
83
|
+
input: num(m.usage.input_tokens),
|
|
84
|
+
cacheRead: num(m.usage.cache_read_input_tokens),
|
|
85
|
+
cacheWrite: writes - writes1h,
|
|
86
|
+
cacheWrite1h: writes1h,
|
|
87
|
+
output: num(m.usage.output_tokens),
|
|
88
|
+
};
|
|
89
|
+
const key = `${m.id ?? row.uuid}|${row.requestId ?? ""}`;
|
|
90
|
+
const seen = replies.get(key);
|
|
91
|
+
if (!seen || usage.output >= seen.output)
|
|
92
|
+
replies.set(key, usage);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
h.usage.push(...replies.values());
|
|
96
|
+
h.coverage.push(coverage("claude", "replies", [...replies.values()].map((u) => u.at)));
|
|
97
|
+
return h;
|
|
98
|
+
}
|
|
99
|
+
const INTERRUPTED = "[Request interrupted by user";
|
|
100
|
+
const EDIT_TOOLS = new Set(["Edit", "MultiEdit", "Write", "NotebookEdit"]);
|
|
101
|
+
// The tests, commits and edits in a reply, and a stop in a user line, each
|
|
102
|
+
// with an id to count it once by.
|
|
103
|
+
function actionsIn(row) {
|
|
104
|
+
const content = row.message?.content;
|
|
105
|
+
if (row.type === "user") {
|
|
106
|
+
const text = typeof content === "string" ? content : Array.isArray(content) ? content.map((b) => b?.text ?? "").join("") : "";
|
|
107
|
+
return text.includes(INTERRUPTED) ? [[`stop|${row.uuid ?? row.timestamp}`, { kind: "stop" }]] : [];
|
|
108
|
+
}
|
|
109
|
+
if (row.type !== "assistant" || !Array.isArray(content))
|
|
110
|
+
return [];
|
|
111
|
+
const out = [];
|
|
112
|
+
for (const b of content) {
|
|
113
|
+
if (b?.type !== "tool_use" || typeof b.id !== "string")
|
|
114
|
+
continue;
|
|
115
|
+
const path = b.input?.file_path ?? b.input?.notebook_path;
|
|
116
|
+
if (EDIT_TOOLS.has(b.name) && typeof path === "string")
|
|
117
|
+
out.push([b.id, { kind: "edit", ext: extname(path).toLowerCase() }]);
|
|
118
|
+
const kind = b.name === "Bash" ? commandKind(String(b.input?.command ?? "")) : null;
|
|
119
|
+
if (kind)
|
|
120
|
+
out.push([b.id, { kind }]);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
// Drops slash and shell commands and paste placeholders; keeps what was typed.
|
|
125
|
+
export function cleanClaudePrompt(raw) {
|
|
126
|
+
const text = raw
|
|
127
|
+
.replace(/\[(Pasted text|Image) #\d+[^\]]*\]/g, "")
|
|
128
|
+
.trim();
|
|
129
|
+
if (!text || text.startsWith("/") || text.startsWith("!"))
|
|
130
|
+
return null;
|
|
131
|
+
return text;
|
|
132
|
+
}
|
|
133
|
+
function addNames(h, names) {
|
|
134
|
+
for (const n of names)
|
|
135
|
+
h.privateNames.add(n);
|
|
136
|
+
}
|
|
137
|
+
function num(v) {
|
|
138
|
+
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
139
|
+
}
|