wrapt-cli 0.1.6 → 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/README.md +22 -27
- package/assets/story/player.css +116 -0
- package/assets/story/player.js +298 -0
- package/dist/analyze.js +16 -1
- package/dist/cli.js +66 -6
- package/dist/format.js +42 -0
- package/dist/parse/reader.js +47 -1
- package/dist/play/story.js +106 -0
- package/dist/render/cards.js +38 -2
- package/dist/render/index.js +8 -6
- package/dist/render/theme.js +3 -0
- package/dist/share/page.js +5 -3
- package/dist/share/server.js +4 -3
- package/dist/site.js +2 -2
- package/dist/sources/index.js +13 -2
- package/dist/stats/engine.js +51 -1
- package/dist/stats/pricing.js +52 -0
- package/dist/stats/schema.js +36 -0
- package/package.json +2 -2
package/dist/stats/engine.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { messageCost } from "./pricing.js";
|
|
1
2
|
import { FILE_TOOLS, languageForPath } from "./languages.js";
|
|
2
3
|
import { SOURCE_NAMES } from "./schema.js";
|
|
3
4
|
import { extractWords, machineWords, normalizeShortPrompt, redactSecrets, truncate } from "./words.js";
|
|
@@ -16,6 +17,8 @@ export const MAX_WORD_HITS_PER_PROMPT = 3;
|
|
|
16
17
|
export const RHYTHM_THRESHOLDS = { night: 0.25, early: 0.2, weekend: 0.4 };
|
|
17
18
|
const NIGHT_HOURS = new Set([22, 23, 0, 1, 2, 3]);
|
|
18
19
|
const EARLY_HOURS = new Set([5, 6, 7, 8]);
|
|
20
|
+
const PLEASE = /\b(please|pls|plz)\b/i;
|
|
21
|
+
const THANKS = /\b(thank you|thank u|thanks|thx)\b/i;
|
|
19
22
|
/** Local calendar date as YYYY-MM-DD. */
|
|
20
23
|
export function localDate(d) {
|
|
21
24
|
const y = d.getFullYear();
|
|
@@ -59,6 +62,10 @@ export class StatsEngine {
|
|
|
59
62
|
repeats = new Map();
|
|
60
63
|
samples = [];
|
|
61
64
|
bySource = new Map();
|
|
65
|
+
receipts = { please: 0, thanks: 0, absolutelyRight: 0, interrupts: 0 };
|
|
66
|
+
transcriptsFrom = null;
|
|
67
|
+
historyPrompts = 0;
|
|
68
|
+
retentionDays;
|
|
62
69
|
first = null;
|
|
63
70
|
last = null;
|
|
64
71
|
constructor(opts) {
|
|
@@ -66,6 +73,7 @@ export class StatsEngine {
|
|
|
66
73
|
this.random = opts.random ?? Math.random;
|
|
67
74
|
this.now = opts.now ?? new Date();
|
|
68
75
|
this.excludeWords = opts.excludeWords ?? machineWords();
|
|
76
|
+
this.retentionDays = opts.retentionDays ?? null;
|
|
69
77
|
}
|
|
70
78
|
add(e) {
|
|
71
79
|
if (e.ts.getFullYear() !== this.year)
|
|
@@ -79,7 +87,17 @@ export class StatsEngine {
|
|
|
79
87
|
times.push(t);
|
|
80
88
|
this.sessionTimes.set(e.sessionId, times);
|
|
81
89
|
const src = this.source(e.source ?? "claude");
|
|
90
|
+
if ((e.source ?? "claude") === "claude" && !(e.kind === "prompt" && e.fromHistory)) {
|
|
91
|
+
if (!this.transcriptsFrom || t < this.transcriptsFrom.getTime())
|
|
92
|
+
this.transcriptsFrom = e.ts;
|
|
93
|
+
}
|
|
82
94
|
if (e.kind === "prompt") {
|
|
95
|
+
if (e.fromHistory)
|
|
96
|
+
this.historyPrompts++;
|
|
97
|
+
if (PLEASE.test(e.text))
|
|
98
|
+
this.receipts.please++;
|
|
99
|
+
if (THANKS.test(e.text))
|
|
100
|
+
this.receipts.thanks++;
|
|
83
101
|
src.prompts++;
|
|
84
102
|
src.sessions.add(e.sessionId);
|
|
85
103
|
this.addPrompt(e.ts, e.sessionId, e.project, e.text);
|
|
@@ -87,11 +105,16 @@ export class StatsEngine {
|
|
|
87
105
|
else if (e.kind === "assistant") {
|
|
88
106
|
src.sessions.add(e.sessionId);
|
|
89
107
|
src.turns.add(e.messageId);
|
|
108
|
+
if (e.absolutelyRight)
|
|
109
|
+
this.receipts.absolutelyRight++;
|
|
90
110
|
this.addAssistant(e);
|
|
91
111
|
}
|
|
92
112
|
else if (e.kind === "tool") {
|
|
93
113
|
this.addTools(e.tools, e.files);
|
|
94
114
|
}
|
|
115
|
+
else if (e.interrupt) {
|
|
116
|
+
this.receipts.interrupts++;
|
|
117
|
+
}
|
|
95
118
|
}
|
|
96
119
|
source(id) {
|
|
97
120
|
let s = this.bySource.get(id);
|
|
@@ -151,13 +174,15 @@ export class StatsEngine {
|
|
|
151
174
|
addAssistant(e) {
|
|
152
175
|
this.sessions.add(e.sessionId);
|
|
153
176
|
// Each content block of one API message is its own line with the same usage: keep the max.
|
|
154
|
-
const acc = this.messages.get(e.messageId) ?? { input: 0, output: 0, cacheCreation: 0, cacheRead: 0, model: e.model };
|
|
177
|
+
const acc = this.messages.get(e.messageId) ?? { input: 0, output: 0, cacheCreation: 0, cacheRead: 0, cacheCreation1h: 0, model: e.model };
|
|
155
178
|
const u = e.usage;
|
|
156
179
|
if (u) {
|
|
157
180
|
acc.input = Math.max(acc.input, u.input_tokens ?? 0);
|
|
158
181
|
acc.output = Math.max(acc.output, u.output_tokens ?? 0);
|
|
159
182
|
acc.cacheCreation = Math.max(acc.cacheCreation, u.cache_creation_input_tokens ?? 0);
|
|
160
183
|
acc.cacheRead = Math.max(acc.cacheRead, u.cache_read_input_tokens ?? 0);
|
|
184
|
+
const split = u.cache_creation;
|
|
185
|
+
acc.cacheCreation1h = Math.max(acc.cacheCreation1h, split?.ephemeral_1h_input_tokens ?? 0);
|
|
161
186
|
}
|
|
162
187
|
acc.model ??= e.model;
|
|
163
188
|
this.messages.set(e.messageId, acc);
|
|
@@ -213,7 +238,17 @@ export class StatsEngine {
|
|
|
213
238
|
finish(parse) {
|
|
214
239
|
const tokens = { input: 0, output: 0, cacheCreation: 0, cacheRead: 0, total: 0 };
|
|
215
240
|
const models = new Map();
|
|
241
|
+
const costs = new Map();
|
|
242
|
+
let unpricedTokens = 0;
|
|
216
243
|
for (const m of this.messages.values()) {
|
|
244
|
+
const all = m.input + m.output + m.cacheCreation + m.cacheRead;
|
|
245
|
+
const usd = m.model ? messageCost(m.model, m) : null;
|
|
246
|
+
if (usd === null) {
|
|
247
|
+
if (m.model && /claude/i.test(m.model) && m.model !== "<synthetic>")
|
|
248
|
+
unpricedTokens += all;
|
|
249
|
+
}
|
|
250
|
+
else
|
|
251
|
+
bump(costs, canonicalModel(m.model), usd);
|
|
217
252
|
tokens.input += m.input;
|
|
218
253
|
tokens.output += m.output;
|
|
219
254
|
tokens.cacheCreation += m.cacheCreation;
|
|
@@ -278,6 +313,21 @@ export class StatsEngine {
|
|
|
278
313
|
.filter(([, v]) => v.prompts > 0 || v.turns.size > 0)
|
|
279
314
|
.sort((a, b) => b[1].prompts - a[1].prompts)
|
|
280
315
|
.map(([id, v]) => ({ id, name: SOURCE_NAMES[id], prompts: v.prompts, sessions: v.sessions.size, assistantTurns: v.turns.size })),
|
|
316
|
+
receipts: { ...this.receipts },
|
|
317
|
+
apiCost: costs.size
|
|
318
|
+
? {
|
|
319
|
+
usd: Math.round([...costs.values()].reduce((a, b) => a + b, 0) * 100) / 100,
|
|
320
|
+
byModel: [...costs.entries()]
|
|
321
|
+
.sort((a, b) => b[1] - a[1])
|
|
322
|
+
.map(([name, usd]) => ({ name, usd: Math.round(usd * 100) / 100 })),
|
|
323
|
+
unpricedTokens,
|
|
324
|
+
}
|
|
325
|
+
: undefined,
|
|
326
|
+
coverage: {
|
|
327
|
+
transcriptsFrom: this.transcriptsFrom?.toISOString() ?? null,
|
|
328
|
+
historyPrompts: this.historyPrompts,
|
|
329
|
+
retentionDays: this.retentionDays,
|
|
330
|
+
},
|
|
281
331
|
parse,
|
|
282
332
|
};
|
|
283
333
|
return { stats, samples: this.samples };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const p = (input, output, read) => ({ input, output, write5m: input * 1.25, write1h: input * 2, read });
|
|
2
|
+
/** Keyed by family and version, as canonicalModel() spells them ("opus-5.5", "sonnet-4"). */
|
|
3
|
+
const PRICES = {
|
|
4
|
+
"fable-5.2": p(8, 40, 0.2),
|
|
5
|
+
"mythos-5.2": p(8, 40, 0.2),
|
|
6
|
+
"fable-5.1": p(10, 50, 0.25),
|
|
7
|
+
"mythos-5.1": p(10, 50, 0.25),
|
|
8
|
+
"fable-5": p(10, 50, 1),
|
|
9
|
+
"mythos-5": p(10, 50, 1),
|
|
10
|
+
"opus-5.5": p(4, 20, 0.2),
|
|
11
|
+
"opus-5": p(5, 25, 0.5),
|
|
12
|
+
"opus-4.8": p(5, 25, 0.5),
|
|
13
|
+
"opus-4.7": p(5, 25, 0.5),
|
|
14
|
+
"opus-4.6": p(5, 25, 0.5),
|
|
15
|
+
"opus-4.5": p(5, 25, 0.5),
|
|
16
|
+
"opus-4.1": p(15, 75, 1.5),
|
|
17
|
+
"opus-4": p(15, 75, 1.5),
|
|
18
|
+
"sonnet-5.5": p(2, 10, 0.1),
|
|
19
|
+
"sonnet-5": p(2, 10, 0.2),
|
|
20
|
+
"sonnet-4.6": p(3, 15, 0.3),
|
|
21
|
+
"sonnet-4.5": p(3, 15, 0.3),
|
|
22
|
+
"sonnet-4": p(3, 15, 0.3),
|
|
23
|
+
"haiku-4.5": p(1, 5, 0.1),
|
|
24
|
+
};
|
|
25
|
+
/** Claude Haiku 5.5 costs more once a prompt is over 100,000 tokens. */
|
|
26
|
+
const HAIKU_55 = { small: p(0.1, 0.5, 0.01), large: p(0.5, 2.5, 0.05), threshold: 100_000 };
|
|
27
|
+
/** "claude-opus-5-5", "claude-opus-5.5", "claude-sonnet-4-20250514", "anthropic/claude-haiku-4.5" → "opus-5.5" etc. */
|
|
28
|
+
export function priceKey(model) {
|
|
29
|
+
const m = /claude-(opus|sonnet|haiku|fable|mythos)-(\d+)(?:[-.](\d{1,2}))?(?:-\d{8})?(?:\b|$)/i.exec(model);
|
|
30
|
+
if (!m)
|
|
31
|
+
return null;
|
|
32
|
+
return `${m[1].toLowerCase()}-${m[2]}${m[3] ? `.${m[3]}` : ""}`;
|
|
33
|
+
}
|
|
34
|
+
/** What one API message would cost at list prices, or null for a model with no known Anthropic price. */
|
|
35
|
+
export function messageCost(model, t) {
|
|
36
|
+
const key = priceKey(model);
|
|
37
|
+
if (!key)
|
|
38
|
+
return null;
|
|
39
|
+
let price = PRICES[key];
|
|
40
|
+
if (key === "haiku-5.5") {
|
|
41
|
+
price = t.input + t.cacheCreation + t.cacheRead > HAIKU_55.threshold ? HAIKU_55.large : HAIKU_55.small;
|
|
42
|
+
}
|
|
43
|
+
if (!price)
|
|
44
|
+
return null;
|
|
45
|
+
const w1h = Math.min(t.cacheCreation1h ?? 0, t.cacheCreation);
|
|
46
|
+
const usd = t.input * price.input +
|
|
47
|
+
t.output * price.output +
|
|
48
|
+
(t.cacheCreation - w1h) * price.write5m +
|
|
49
|
+
w1h * price.write1h +
|
|
50
|
+
t.cacheRead * price.read;
|
|
51
|
+
return usd / 1e6;
|
|
52
|
+
}
|
package/dist/stats/schema.js
CHANGED
|
@@ -57,6 +57,42 @@ export const StatsSchema = z.object({
|
|
|
57
57
|
assistantTurns: z.number(),
|
|
58
58
|
}))
|
|
59
59
|
.optional(),
|
|
60
|
+
/** Manners and mayhem. Absent in stats.json files written before wrapt 0.2. */
|
|
61
|
+
receipts: z
|
|
62
|
+
.object({
|
|
63
|
+
/** Prompts that said please. */
|
|
64
|
+
please: z.number(),
|
|
65
|
+
/** Prompts that said thank you / thanks. */
|
|
66
|
+
thanks: z.number(),
|
|
67
|
+
/** Replies where Claude said "You're absolutely right". */
|
|
68
|
+
absolutelyRight: z.number(),
|
|
69
|
+
/** Times you stopped Claude mid-reply (Esc). */
|
|
70
|
+
interrupts: z.number(),
|
|
71
|
+
})
|
|
72
|
+
.optional(),
|
|
73
|
+
/**
|
|
74
|
+
* What the Claude tokens would have cost at Anthropic's pay-as-you-go API list prices. An estimate, not a bill.
|
|
75
|
+
* Absent before wrapt 0.2, and when no Claude model was used.
|
|
76
|
+
*/
|
|
77
|
+
apiCost: z
|
|
78
|
+
.object({
|
|
79
|
+
usd: z.number(),
|
|
80
|
+
byModel: z.array(z.object({ name: z.string(), usd: z.number() })),
|
|
81
|
+
/** Tokens from Claude models with no known price (retired 3.x models, say). */
|
|
82
|
+
unpricedTokens: z.number(),
|
|
83
|
+
})
|
|
84
|
+
.optional(),
|
|
85
|
+
/** How complete the Claude Code history is. Absent before wrapt 0.2. */
|
|
86
|
+
coverage: z
|
|
87
|
+
.object({
|
|
88
|
+
/** Earliest Claude Code session transcript in the year, or null. */
|
|
89
|
+
transcriptsFrom: z.string().nullable(),
|
|
90
|
+
/** Prompts recovered from history.jsonl because their transcripts were deleted. */
|
|
91
|
+
historyPrompts: z.number(),
|
|
92
|
+
/** cleanupPeriodDays from Claude Code's settings.json; null means the default (30 days). */
|
|
93
|
+
retentionDays: z.number().nullable(),
|
|
94
|
+
})
|
|
95
|
+
.optional(),
|
|
60
96
|
parse: z.object({
|
|
61
97
|
files: z.number(),
|
|
62
98
|
lines: z.number(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrapt-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Your year with Claude Code and GitHub Copilot, wrapped. Share cards made on your own computer.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dev": "tsx src/cli.ts",
|
|
20
20
|
"test": "vitest run",
|
|
21
21
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
22
|
-
"examples": "node dist/cli.js render --year 2026 --name Ada --show-projects --out ../../examples/demo && node scripts/contact-sheet.mjs ../../examples/demo/story
|
|
22
|
+
"examples": "node dist/cli.js render --year 2026 --name Ada --show-projects --out ../../examples/demo && node scripts/contact-sheet.mjs ../../examples/demo/story 3 360 640 ../../examples/story-preview.png && node scripts/contact-sheet.mjs ../../examples/demo/carousel 3 432 540 ../../examples/carousel-preview.png && node scripts/site-images.mjs"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@resvg/resvg-js": "^2.6.2",
|