wrapped-agents 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +41 -2
- package/SKILL.md +38 -0
- package/package.json +40 -4
- package/page/assets/fonts/NOTICE.md +1 -0
- package/page/assets/fonts/commit-mono/commit-mono-400-italic.woff2 +0 -0
- package/page/assets/fonts/commit-mono/commit-mono-400-normal.woff2 +0 -0
- package/page/assets/fonts/commit-mono/commit-mono-700-italic.woff2 +0 -0
- package/page/assets/fonts/commit-mono/commit-mono-700-normal.woff2 +0 -0
- package/page/assets/fonts/dm-mono/dm-mono-400-italic.woff2 +0 -0
- package/page/assets/fonts/dm-mono/dm-mono-400-normal.woff2 +0 -0
- package/page/assets/fonts/dm-mono/dm-mono-500-italic.woff2 +0 -0
- package/page/assets/fonts/dm-mono/dm-mono-500-normal.woff2 +0 -0
- package/page/assets/fonts/lora/lora-400-italic.woff2 +0 -0
- package/page/assets/fonts/lora/lora-400-normal.woff2 +0 -0
- package/page/assets/fonts/lora/lora-500-italic.woff2 +0 -0
- package/page/assets/fonts/lora/lora-500-normal.woff2 +0 -0
- package/page/assets/fonts/lora/lora-600-italic.woff2 +0 -0
- package/page/assets/fonts/lora/lora-600-normal.woff2 +0 -0
- package/page/assets/fonts/mona-sans/mona-sans-400-italic.woff2 +0 -0
- package/page/assets/fonts/mona-sans/mona-sans-400-normal.woff2 +0 -0
- package/page/assets/fonts/mona-sans/mona-sans-700-italic.woff2 +0 -0
- package/page/assets/fonts/mona-sans/mona-sans-700-normal.woff2 +0 -0
- package/page/assets/fonts/mona-sans/mona-sans-900-italic.woff2 +0 -0
- package/page/assets/fonts/mona-sans/mona-sans-900-normal.woff2 +0 -0
- package/page/assets/fonts/openmono/OFL.txt +94 -0
- package/page/assets/fonts/openmono/OpenMono-Bold.woff2 +0 -0
- package/page/assets/fonts/openmono/OpenMono-ExtraBold.woff2 +0 -0
- package/page/assets/fonts/openmono/OpenMono-Regular.woff2 +0 -0
- package/page/assets/fonts/oswald/oswald-400-normal.woff2 +0 -0
- package/page/assets/fonts/oswald/oswald-600-normal.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-400-italic.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-400-normal.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-600-italic.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-600-normal.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-700-italic.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-700-normal.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-800-italic.woff2 +0 -0
- package/page/assets/fonts/poppins/poppins-800-normal.woff2 +0 -0
- package/page/assets/fonts/source-serif-4/source-serif-4-400-italic.woff2 +0 -0
- package/page/assets/fonts/source-serif-4/source-serif-4-400-normal.woff2 +0 -0
- package/page/assets/fonts/source-serif-4/source-serif-4-600-italic.woff2 +0 -0
- package/page/assets/fonts/source-serif-4/source-serif-4-600-normal.woff2 +0 -0
- package/page/assets/logos/anthropic.svg +4 -0
- package/page/assets/logos/claude-code.svg +3 -0
- package/page/assets/logos/codex.svg +1 -0
- package/page/assets/logos/cursor.svg +1 -0
- package/page/assets/logos/gemini-cli.svg +1 -0
- package/page/assets/logos/github.svg +1 -0
- package/page/assets/logos/hermes.svg +1 -0
- package/page/assets/logos/mistral-vibe.svg +12 -0
- package/page/assets/logos/opencode.svg +16 -0
- package/page/assets/logos/pi.svg +6 -0
- package/page/assets/logos/qwen-code.svg +1 -0
- package/page/story.html +993 -0
- package/src/cli.mjs +122 -0
- package/src/data/prices.json +67 -0
- package/src/privacy.mjs +39 -0
- package/src/readers/_pool.mjs +32 -0
- package/src/readers/_prompts.mjs +54 -0
- package/src/readers/_util.mjs +182 -0
- package/src/readers/_worker.mjs +7 -0
- package/src/readers/claude-code.mjs +330 -0
- package/src/readers/codex.mjs +162 -0
- package/src/readers/index.mjs +8 -0
- package/src/readers/mistral-vibe.mjs +156 -0
- package/src/readers/pi.mjs +154 -0
- package/src/render.mjs +65 -0
- package/src/site.mjs +62 -0
- package/src/stats/age.mjs +36 -0
- package/src/stats/awards.mjs +132 -0
- package/src/stats/git.mjs +161 -0
- package/src/stats/index.mjs +253 -0
- package/src/stats/roast.mjs +6 -0
- package/src/stats/spendings.mjs +99 -0
- package/src/stats/tiers.mjs +16 -0
- package/src/stats/twin.mjs +37 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Mistral Vibe reader: ~/.vibe/logs/session/unified/<sessionId>/ (content-addressed chunks/*.json holding the
|
|
2
|
+
// session's history entries, journal/*.jsonl with entries not yet checkpointed, generations/*/projection-state.json)
|
|
3
|
+
// plus unified/.session-index.json (model, cwd, cumulative token usage per session). ~/.vibe/vibehistory is a capped
|
|
4
|
+
// prompt log without timestamps, used only when no session store exists. config.toml: model, theme.
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import fsp from 'node:fs/promises';
|
|
7
|
+
import {
|
|
8
|
+
eachLine, parse, readJSON, readText, isDir, exists, localDate, localMonth, toMs, windowOf, basename, maxConcurrent,
|
|
9
|
+
gitUndoKinds, emptyUndos, phraseCounts, emptyAssistant, addPhrases, inc, tokBucket, emptyFacts, day,
|
|
10
|
+
countPromptTime, finishCoverage, longestSession, mostResumed,
|
|
11
|
+
} from './_util.mjs';
|
|
12
|
+
import { PromptStats } from './_prompts.mjs';
|
|
13
|
+
import { mapFiles } from './_pool.mjs';
|
|
14
|
+
|
|
15
|
+
export const id = 'mistral-vibe';
|
|
16
|
+
export const label = 'Mistral Vibe';
|
|
17
|
+
|
|
18
|
+
const vibeDir = env => path.join(env.home, '.vibe');
|
|
19
|
+
const unified = env => path.join(vibeDir(env), 'logs', 'session', 'unified');
|
|
20
|
+
|
|
21
|
+
export async function detect(env) {
|
|
22
|
+
const roots = [];
|
|
23
|
+
if (await isDir(unified(env))) roots.push(unified(env));
|
|
24
|
+
if (await exists(path.join(vibeDir(env), 'vibehistory'))) roots.push(path.join(vibeDir(env), 'vibehistory'));
|
|
25
|
+
return { found: roots.length > 0, roots };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** one session directory (runs in a worker) */
|
|
29
|
+
export async function scanDir(dir, ctx) {
|
|
30
|
+
const r = { id: path.basename(dir), entries: {}, outcomes: {}, usage: null, meta: null };
|
|
31
|
+
const add = e => {
|
|
32
|
+
if (!e || typeof e !== 'object' || !e.id || !e.type || e.id in r.entries) return;
|
|
33
|
+
const ms = toMs(e.createdAt); const x = { type: e.type, ms, end: toMs(e.updatedAt) };
|
|
34
|
+
if (e.type === 'message' && e.role === 'user' && (e.source === 'turn_start' || e.source === 'turn_steer')) {
|
|
35
|
+
const c = Array.isArray(e.content) ? e.content : [];
|
|
36
|
+
x.prompt = c.filter(b => b && b.type === 'text').map(b => b.text || '').join(' ');
|
|
37
|
+
x.images = c.filter(b => b && b.type === 'image').length;
|
|
38
|
+
} else if (e.type === 'message' && e.role === 'assistant') {
|
|
39
|
+
x.phr = phraseCounts((Array.isArray(e.content) ? e.content : []).map(b => (b && b.text) || '').join(' '));
|
|
40
|
+
} else if (e.type === 'effect') {
|
|
41
|
+
const d = e.detail || {}; const st = e.state || {}; const inp = d.input || {};
|
|
42
|
+
x.tool = d.toolName || d.kind || '?'; x.ok = st.status === 'completed';
|
|
43
|
+
if (/bash|shell|process\.start/.test(x.tool)) x.undo = gitUndoKinds(String(inp.command || ''));
|
|
44
|
+
if (x.ok && /write_file$/.test(x.tool)) x.add = String(inp.content || '').split('\n').length;
|
|
45
|
+
if (x.ok && /\.edit$/.test(x.tool)) { x.add = lineCount(inp.new_string); x.rem = lineCount(inp.old_string); }
|
|
46
|
+
if (/^skill\./.test(x.tool)) x.skill = String(inp.name || '?');
|
|
47
|
+
} else if (e.type === 'checkpoint') x.kind = e.kind || null;
|
|
48
|
+
r.entries[e.id] = x;
|
|
49
|
+
};
|
|
50
|
+
let names = [];
|
|
51
|
+
try { names = await fsp.readdir(path.join(dir, 'chunks')); } catch {}
|
|
52
|
+
for (const n of names) {
|
|
53
|
+
if (!n.endsWith('.json')) continue;
|
|
54
|
+
let o; try { o = JSON.parse(await fsp.readFile(path.join(dir, 'chunks', n), 'utf8')); } catch { continue; }
|
|
55
|
+
if (Array.isArray(o)) for (const e of o) add(e);
|
|
56
|
+
}
|
|
57
|
+
let jn = [];
|
|
58
|
+
try { jn = await fsp.readdir(path.join(dir, 'journal')); } catch {}
|
|
59
|
+
for (const n of jn) if (n.endsWith('.jsonl')) await eachLine(path.join(dir, 'journal', n), line => {
|
|
60
|
+
if (!line.includes('append_entry')) return;
|
|
61
|
+
const o = parse(line); const delta = o && o.payload && o.payload.delta;
|
|
62
|
+
if (Array.isArray(delta)) for (const d of delta) if (d && d.op === 'append_entry') add(d.entry);
|
|
63
|
+
});
|
|
64
|
+
const cur = parse((await readText(path.join(dir, 'CURRENT'))) || '');
|
|
65
|
+
if (cur && cur.generation) {
|
|
66
|
+
const ps = await readJSON(path.join(dir, 'generations', cur.generation, 'projection-state.json'));
|
|
67
|
+
if (ps) {
|
|
68
|
+
for (const [k, v] of Object.entries((ps.session_api || {}).turn_outcomes || {})) r.outcomes[k] = (v && v.termination && v.termination.outcome) || null;
|
|
69
|
+
const s = ps.snapshot && ps.snapshot.session; if (s) r.usage = { tokenUsage: s.tokenUsage || null, createdAt: s.createdAt, updatedAt: s.updatedAt };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const meta = await readJSON(path.join(dir, 'meta.json'));
|
|
73
|
+
if (meta) r.meta = { model: (meta.config || {}).active_model || null, cwd: (meta.environment || {}).working_directory || null, start: meta.start_time || null, parent: meta.parent_session_id || null };
|
|
74
|
+
return r;
|
|
75
|
+
}
|
|
76
|
+
const lineCount = s => (s ? String(s).split('\n').length : 0);
|
|
77
|
+
|
|
78
|
+
export async function read(env, opts = {}) {
|
|
79
|
+
const w = windowOf(env, opts); const progress = opts.onProgress || (() => {});
|
|
80
|
+
const f = emptyFacts(id, label); const ps = new PromptStats();
|
|
81
|
+
const root = unified(env);
|
|
82
|
+
const index = await readJSON(path.join(root, '.session-index.json'));
|
|
83
|
+
const idx = new Map();
|
|
84
|
+
for (const e of (index && index.entries) || []) if (e && e.session_id) idx.set(e.session_id, e);
|
|
85
|
+
let dirs = [];
|
|
86
|
+
try { dirs = (await fsp.readdir(root, { withFileTypes: true })).filter(d => d.isDirectory() && !d.name.startsWith('.')).map(d => ({ path: path.join(root, d.name), size: 0 })); } catch {}
|
|
87
|
+
if (dirs.length) f.coverage.sources.push('logs/session/unified/*/chunks', '.session-index.json');
|
|
88
|
+
|
|
89
|
+
const sessions = new Map(); const bySession = new Map(); const concEv = [];
|
|
90
|
+
const undos = emptyUndos(); const assistant = emptyAssistant(); const lines = { added: 0, removed: 0 };
|
|
91
|
+
let interrupts = 0, compactions = 0, rewinds = 0, subagents = 0, roots = 0, benchSkipped = 0;
|
|
92
|
+
progress(`Mistral Vibe: ${dirs.length} sessions`);
|
|
93
|
+
await mapFiles(import.meta.url, 'scanDir', dirs, { start: w.start, end: w.end }, r => {
|
|
94
|
+
const ix = idx.get(r.id); const md = (ix && ix.metadata) || {}; const ss = (ix && ix.session) || {};
|
|
95
|
+
const isChild = ix ? (ix.identity && ix.identity.depth > 0) : !!(r.meta && r.meta.parent);
|
|
96
|
+
const model = md.active_model || (r.meta && r.meta.model) || '?';
|
|
97
|
+
const proj = basename(md.cwd || (r.meta && r.meta.cwd));
|
|
98
|
+
// benchmark / batch runs (vibe-bench-*) are not the user's sessions
|
|
99
|
+
if (/bench/i.test(String(r.id)) || /bench/i.test(String(proj || '')) || /bench/i.test(String((r.meta && r.meta.title) || ''))) { benchSkipped++; return; }
|
|
100
|
+
const created = toMs(ss.createdAt ?? (r.usage && r.usage.createdAt) ?? (r.meta && r.meta.start));
|
|
101
|
+
// tokens: cumulative per session (index first, else the latest projection snapshot)
|
|
102
|
+
const tu = ss.tokenUsage || (r.usage && r.usage.tokenUsage);
|
|
103
|
+
if (tu && created >= w.start && created < w.end) {
|
|
104
|
+
const inp = tu.inputTokens || 0, cached = Math.min(inp, tu.cachedInputTokens || 0), out = tu.outputTokens || 0;
|
|
105
|
+
const b = f.models[model] ||= tokBucket();
|
|
106
|
+
b.input += inp - cached; b.cacheRead += cached; b.output += out; inc(b.byMonth, localMonth(created), inp + out);
|
|
107
|
+
day(f, localDate(created)).tokens += inp + out;
|
|
108
|
+
}
|
|
109
|
+
if (isChild) subagents++; else roots++;
|
|
110
|
+
const times = [];
|
|
111
|
+
for (const k in r.entries) {
|
|
112
|
+
const e = r.entries[k]; if (!(e.ms >= w.start && e.ms < w.end)) continue;
|
|
113
|
+
times.push(e.ms); if (e.end > e.ms && e.end < w.end) times.push(e.end);
|
|
114
|
+
if (e.prompt !== undefined && !isChild) {
|
|
115
|
+
ps.add(e.prompt, { images: e.images }); countPromptTime(f, e.ms); concEv.push([e.ms, r.id]);
|
|
116
|
+
if (proj) inc(f.projects, proj);
|
|
117
|
+
const s = bySession.get(r.id) || { days: new Set(), project: proj }; s.days.add(localDate(e.ms)); bySession.set(r.id, s);
|
|
118
|
+
}
|
|
119
|
+
if (e.phr) addPhrases(assistant, e.phr);
|
|
120
|
+
if (e.tool) { inc(f.tools, e.tool); if (e.undo) for (const u of e.undo) undos[u]++; if (e.skill) inc(f.skills, e.skill); lines.added += e.add || 0; lines.removed += e.rem || 0; }
|
|
121
|
+
if (e.kind === 'compaction') compactions++; else if (e.kind === 'rewind') rewinds++;
|
|
122
|
+
}
|
|
123
|
+
for (const k in r.outcomes) if (r.outcomes[k] === 'cancelled') interrupts++;
|
|
124
|
+
if (!isChild && times.length) sessions.set(r.id, { t: times, project: proj });
|
|
125
|
+
}, { onProgress: m => progress('Mistral Vibe: ' + m) });
|
|
126
|
+
|
|
127
|
+
for (const [, s] of sessions) {
|
|
128
|
+
let mn = Infinity; for (const t of s.t) { if (t < mn) mn = t; day(f, localDate(t)); }
|
|
129
|
+
day(f, localDate(mn)).sessions++; f.sessions.count++;
|
|
130
|
+
}
|
|
131
|
+
// no session store: fall back to the capped prompt log (no timestamps, so text stats only)
|
|
132
|
+
const histFile = path.join(vibeDir(env), 'vibehistory');
|
|
133
|
+
if (!dirs.length && await exists(histFile)) {
|
|
134
|
+
f.coverage.sources.push('vibehistory');
|
|
135
|
+
await eachLine(histFile, line => { const s = parse(line); if (typeof s === 'string') ps.add(s); });
|
|
136
|
+
f.coverage.notes.push('prompts from vibehistory only (capped log without dates): no days, hours or sessions');
|
|
137
|
+
}
|
|
138
|
+
if (benchSkipped) f.coverage.notes.push(`${benchSkipped} benchmark/batch sessions skipped`);
|
|
139
|
+
f.sessions.longest = longestSession(sessions);
|
|
140
|
+
f.sessions.mostResumed = mostResumed(bySession);
|
|
141
|
+
f.sessions.maxConcurrent = maxConcurrent(concEv);
|
|
142
|
+
f.prompts = ps.toJSON(); f.slash = ps.slash;
|
|
143
|
+
f.subagents = subagents; f.interrupts = interrupts; f.compactions = compactions; f.rewinds = rewinds;
|
|
144
|
+
f.rateLimits = null; // no rate-limit marker found in the session store
|
|
145
|
+
f.lines = lines; f.gitUndos = undos; f.assistant = assistant;
|
|
146
|
+
f.projects = Object.fromEntries(Object.entries(f.projects).sort((a, b) => b[1] - a[1]).slice(0, 20));
|
|
147
|
+
|
|
148
|
+
const ui = await readJSON(path.join(vibeDir(env), 'ui_startup_config.json'));
|
|
149
|
+
if (ui && typeof ui.serverVersion === 'string') f.version = ui.serverVersion;
|
|
150
|
+
const cfg = await readText(path.join(vibeDir(env), 'config.toml'));
|
|
151
|
+
const tm = cfg && /^\s*theme\s*=\s*"([^"]+)"/m.exec(cfg);
|
|
152
|
+
const tname = (tm && tm[1]) || (ui && ui.theme) || null;
|
|
153
|
+
f.theme = tname ? { name: tname, builtin: /^(mistral-|dark$|light$|textual-)/.test(tname), colors: null } : null;
|
|
154
|
+
if (dirs.length) f.coverage.notes.push(`${roots} sessions in the unified store; tokens are per-session totals dated by session start`);
|
|
155
|
+
return finishCoverage(f);
|
|
156
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// Pi reader: ~/.pi/agent/sessions/<cwd-slug>/<ts>_<uuid>.jsonl (one file = one session, entries form a tree).
|
|
2
|
+
// Theme: ~/.pi/agent/settings.json `theme` + ~/.pi/agent/themes/<name>.json (vars resolved to hex).
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
eachLine, parse, readJSON, isDir, walk, localDate, toMs, windowOf, basename, maxConcurrent, gitUndoKinds,
|
|
6
|
+
emptyUndos, phraseCounts, emptyAssistant, addPhrases, inc, addTok, emptyFacts, day, countPromptTime,
|
|
7
|
+
finishCoverage, longestSession, mostResumed,
|
|
8
|
+
} from './_util.mjs';
|
|
9
|
+
import { PromptStats } from './_prompts.mjs';
|
|
10
|
+
import { mapFiles } from './_pool.mjs';
|
|
11
|
+
|
|
12
|
+
export const id = 'pi';
|
|
13
|
+
export const label = 'Pi';
|
|
14
|
+
|
|
15
|
+
const agentDir = env => path.join(env.home, '.pi', 'agent');
|
|
16
|
+
const BUILTIN = new Set(['dark', 'light']);
|
|
17
|
+
const SUBAGENT_TOOLS = /^(subagent|subagents|spawn_agent|task|agent)$/i;
|
|
18
|
+
|
|
19
|
+
export async function detect(env) {
|
|
20
|
+
const d = path.join(agentDir(env), 'sessions');
|
|
21
|
+
return (await isDir(d)) ? { found: true, roots: [d] } : { found: false, roots: [] };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function scanFile(file, ctx) {
|
|
25
|
+
const r = { sid: null, cwd: null, t: [], prompts: [], models: [], tools: [], aborted: 0, errors: [], compactions: 0,
|
|
26
|
+
added: 0, removed: 0, undo: [], phr: [], kids: [] };
|
|
27
|
+
const win = ms => ms >= ctx.start && ms < ctx.end;
|
|
28
|
+
const writes = new Map();
|
|
29
|
+
await eachLine(file, line => {
|
|
30
|
+
const o = parse(line); if (!o) return;
|
|
31
|
+
const t = o.type;
|
|
32
|
+
if (t === 'session') { r.sid = o.id || null; r.cwd = o.cwd || null; return; }
|
|
33
|
+
const ms = toMs(o.timestamp); if (!win(ms)) return;
|
|
34
|
+
if (t === 'compaction') { r.compactions++; return; }
|
|
35
|
+
if (t !== 'message') return;
|
|
36
|
+
const m = o.message || {}; const role = m.role; const ct = m.content;
|
|
37
|
+
r.t.push(ms);
|
|
38
|
+
if (role === 'user') {
|
|
39
|
+
const blocks = Array.isArray(ct) ? ct.filter(x => x && typeof x === 'object') : [];
|
|
40
|
+
if (typeof ct === 'string' || blocks.some(x => x.type === 'text')) {
|
|
41
|
+
const text = typeof ct === 'string' ? ct : blocks.filter(x => x.type === 'text').map(x => x.text || '').join(' ');
|
|
42
|
+
r.prompts.push([ms, text, blocks.filter(x => x.type === 'image').length]);
|
|
43
|
+
if (o.parentId) r.kids.push([o.parentId, o.id]);
|
|
44
|
+
}
|
|
45
|
+
} else if (role === 'assistant') {
|
|
46
|
+
const u = m.usage || {};
|
|
47
|
+
r.models.push([m.model || '?', ms, u.input || 0, u.output || 0, u.cacheRead || 0, u.cacheWrite || 0, m.provider || null]);
|
|
48
|
+
if (m.stopReason === 'aborted') r.aborted++;
|
|
49
|
+
else if (m.stopReason === 'error') {
|
|
50
|
+
const em = String(m.errorMessage || '').toLowerCase();
|
|
51
|
+
if (/429|rate.?limit|too many requests|quota/.test(em)) r.errors.push(ms);
|
|
52
|
+
}
|
|
53
|
+
for (const c of Array.isArray(ct) ? ct : []) {
|
|
54
|
+
if (!c || typeof c !== 'object') continue;
|
|
55
|
+
if (c.type === 'text') { const pc = phraseCounts(c.text); if (pc) r.phr.push(pc); }
|
|
56
|
+
else if (c.type === 'toolCall') {
|
|
57
|
+
r.tools.push(c.name || '?'); const a = c.arguments || {};
|
|
58
|
+
if (c.name === 'bash') { const u = gitUndoKinds(String(a.command || '')); if (u) r.undo.push(u); }
|
|
59
|
+
else if (c.name === 'write') writes.set(c.id, String(a.content || '').split('\n').length);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} else if (role === 'toolResult' && !m.isError) {
|
|
63
|
+
if (m.toolName === 'edit') {
|
|
64
|
+
for (const ln of String((m.details || {}).diff || '').split('\n')) { if (ln[0] === '+') r.added++; else if (ln[0] === '-') r.removed++; }
|
|
65
|
+
} else if (m.toolName === 'write' && writes.has(m.toolCallId)) r.added += writes.get(m.toolCallId);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return r;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function read(env, opts = {}) {
|
|
72
|
+
const w = windowOf(env, opts); const progress = opts.onProgress || (() => {});
|
|
73
|
+
const f = emptyFacts(id, label); const ps = new PromptStats();
|
|
74
|
+
const dir = path.join(agentDir(env), 'sessions');
|
|
75
|
+
const files = (await isDir(dir)) ? await walk(dir, n => n.endsWith('.jsonl')) : [];
|
|
76
|
+
if (files.length) f.coverage.sources.push('agent/sessions/*.jsonl');
|
|
77
|
+
const sessions = new Map(); const bySession = new Map(); const concEv = []; const kids = new Map();
|
|
78
|
+
const undos = emptyUndos(); const assistant = emptyAssistant(); const lines = { added: 0, removed: 0 };
|
|
79
|
+
const rlDays = new Set(); let rlHits = 0, interrupts = 0, compactions = 0, subagents = 0;
|
|
80
|
+
const local = await localProviders(env); const providers = {};
|
|
81
|
+
progress(`Pi: ${files.length} session files`);
|
|
82
|
+
await mapFiles(import.meta.url, 'scanFile', files, { start: w.start, end: w.end }, (r, file) => {
|
|
83
|
+
const sid = r.sid || file.path; const proj = basename(r.cwd);
|
|
84
|
+
if (r.t.length) { const s = sessions.get(sid) || { t: [], project: proj }; for (const t of r.t) s.t.push(t); sessions.set(sid, s); }
|
|
85
|
+
for (const [ms, text, images] of r.prompts) {
|
|
86
|
+
ps.add(text, { images }); countPromptTime(f, ms); concEv.push([ms, sid]);
|
|
87
|
+
if (proj) inc(f.projects, proj);
|
|
88
|
+
const s = bySession.get(sid) || { days: new Set(), project: proj }; s.days.add(localDate(ms)); bySession.set(sid, s);
|
|
89
|
+
}
|
|
90
|
+
for (const [m, ms, i, o, cr, cw, prov] of r.models) { addTok(f.models, m, ms, i, o, cr, cw); day(f, localDate(ms)).tokens += i + o + cr + cw; if (prov && !providers[m]) providers[m] = prov; }
|
|
91
|
+
for (const n of r.tools) { inc(f.tools, n); if (SUBAGENT_TOOLS.test(n)) subagents++; }
|
|
92
|
+
for (const u of r.undo) for (const k of u) undos[k]++;
|
|
93
|
+
for (const c of r.phr) addPhrases(assistant, c);
|
|
94
|
+
for (const ms of r.errors) { rlHits++; rlDays.add(localDate(ms)); }
|
|
95
|
+
for (const [p, c] of r.kids) { const s = kids.get(sid + p) || new Set(); s.add(c); kids.set(sid + p, s); }
|
|
96
|
+
interrupts += r.aborted; compactions += r.compactions; lines.added += r.added; lines.removed += r.removed;
|
|
97
|
+
}, { onProgress: m => progress('Pi: ' + m) });
|
|
98
|
+
|
|
99
|
+
for (const m in providers) { f.models[m].provider = providers[m]; if (local(providers[m])) f.models[m].local = true; }
|
|
100
|
+
for (const [, s] of sessions) {
|
|
101
|
+
let mn = Infinity; for (const t of s.t) { if (t < mn) mn = t; day(f, localDate(t)); }
|
|
102
|
+
day(f, localDate(mn)).sessions++; f.sessions.count++;
|
|
103
|
+
}
|
|
104
|
+
f.sessions.longest = longestSession(sessions);
|
|
105
|
+
f.sessions.mostResumed = mostResumed(bySession);
|
|
106
|
+
f.sessions.maxConcurrent = maxConcurrent(concEv);
|
|
107
|
+
f.prompts = ps.toJSON(); f.slash = ps.slash;
|
|
108
|
+
f.subagents = subagents; f.interrupts = interrupts; f.compactions = compactions;
|
|
109
|
+
f.rateLimits = { hits: rlHits, days: rlDays.size };
|
|
110
|
+
f.lines = lines; f.gitUndos = undos; f.assistant = assistant;
|
|
111
|
+
let rewinds = 0; for (const [, s] of kids) if (s.size > 1) rewinds += s.size - 1; f.rewinds = rewinds;
|
|
112
|
+
f.projects = Object.fromEntries(Object.entries(f.projects).sort((a, b) => b[1] - a[1]).slice(0, 20));
|
|
113
|
+
|
|
114
|
+
const settings = await readJSON(path.join(agentDir(env), 'settings.json'));
|
|
115
|
+
if (settings && typeof settings.lastChangelogVersion === 'string') f.version = settings.lastChangelogVersion;
|
|
116
|
+
f.theme = await readTheme(env, settings);
|
|
117
|
+
f.coverage.notes.push('interrupts = assistant turns stopped with Esc (stopReason aborted)');
|
|
118
|
+
return finishCoverage(f);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** provider name -> served on this machine? (models.json baseUrl on localhost, or a known local runtime name) */
|
|
122
|
+
async function localProviders(env) {
|
|
123
|
+
const cfg = await readJSON(path.join(agentDir(env), 'models.json')); const byUrl = {};
|
|
124
|
+
for (const [name, p] of Object.entries((cfg && cfg.providers) || {})) byUrl[name] = String((p && p.baseUrl) || '');
|
|
125
|
+
const LOCAL_URL = /^https?:\/\/(localhost|127\.|0\.0\.0\.0|\[::1\]|192\.168\.|10\.|host\.docker\.internal)/i;
|
|
126
|
+
const LOCAL_NAME = /llama|ollama|lm-?studio|vllm|mlx|local/i;
|
|
127
|
+
return prov => (prov in byUrl ? LOCAL_URL.test(byUrl[prov]) : LOCAL_NAME.test(prov));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** resolve a Pi theme into hex colors */
|
|
131
|
+
export async function readTheme(env, settings) {
|
|
132
|
+
const name = (settings && typeof settings.theme === 'string' && settings.theme) || 'dark';
|
|
133
|
+
const file = await readJSON(path.join(agentDir(env), 'themes', name + '.json'));
|
|
134
|
+
if (!file) return { name, builtin: BUILTIN.has(name), colors: null };
|
|
135
|
+
const vars = file.vars || {}; const colors = file.colors || {};
|
|
136
|
+
const resolve = (v, depth = 0) => {
|
|
137
|
+
if (typeof v !== 'string' || depth > 8) return null;
|
|
138
|
+
if (/^#[0-9a-f]{3,8}$/i.test(v)) return v.toLowerCase();
|
|
139
|
+
if (v in vars) return resolve(vars[v], depth + 1);
|
|
140
|
+
if (v in colors) return resolve(colors[v], depth + 1);
|
|
141
|
+
return null;
|
|
142
|
+
};
|
|
143
|
+
const pick = (...keys) => { for (const k of keys) { const c = resolve(colors[k]) || resolve(vars[k]); if (c) return c; } return null; };
|
|
144
|
+
const out = {
|
|
145
|
+
background: pick('background', 'pageBg') || resolve((file.export || {}).pageBg),
|
|
146
|
+
foreground: pick('foreground', 'text'),
|
|
147
|
+
primary: pick('primary', 'accent', 'borderAccent'),
|
|
148
|
+
accent: pick('accent', 'primary'),
|
|
149
|
+
surface: pick('surface', 'selectedBg') || resolve((file.export || {}).cardBg),
|
|
150
|
+
success: pick('success', 'toolDiffAdded'),
|
|
151
|
+
};
|
|
152
|
+
for (const k of ['surfaceAlt', 'muted', 'subtle', 'cream', 'secondary', 'error', 'warning']) { const c = pick(k); if (c) out[k] = c; }
|
|
153
|
+
return { name, builtin: false, colors: out };
|
|
154
|
+
}
|
package/src/render.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Inline the story template into ONE self-contained HTML file: data, fonts and logos embedded,
|
|
2
|
+
// so it opens from file:// with no server and no network.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
+
const PAGE = path.join(ROOT, 'page');
|
|
9
|
+
|
|
10
|
+
const FONT_FAMILIES = {
|
|
11
|
+
'poppins': 'Poppins', 'lora': 'Lora', 'mona-sans': 'Mona Sans', 'oswald': 'Oswald', 'dm-mono': 'DM Mono',
|
|
12
|
+
'source-serif-4': 'Source Serif 4', 'commit-mono': 'Commit Mono', 'openmono': 'OpenMono',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** @font-face rules with base64 data URLs for every bundled font */
|
|
16
|
+
export function fontCSS() {
|
|
17
|
+
const dir = path.join(PAGE, 'assets', 'fonts'), rules = [];
|
|
18
|
+
for (const [d, family] of Object.entries(FONT_FAMILIES)) {
|
|
19
|
+
const fd = path.join(dir, d);
|
|
20
|
+
if (!fs.existsSync(fd)) continue;
|
|
21
|
+
for (const f of fs.readdirSync(fd).filter(f => f.endsWith('.woff2')).sort()) {
|
|
22
|
+
let weight = 400, style = 'normal';
|
|
23
|
+
const m = f.match(/-(\d{3})-(normal|italic)\.woff2$/);
|
|
24
|
+
if (m) { weight = +m[1]; style = m[2]; }
|
|
25
|
+
else if (/ExtraBold/i.test(f)) weight = 800; else if (/Bold/i.test(f)) weight = 700;
|
|
26
|
+
const b64 = fs.readFileSync(path.join(fd, f)).toString('base64');
|
|
27
|
+
rules.push(`@font-face{font-family:'${family}';src:url(data:font/woff2;base64,${b64}) format('woff2');font-weight:${weight};font-style:${style};font-display:block}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return rules.join('\n');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** { 'claude-code': '<svg…>' } with width/height stripped so CSS sizes them */
|
|
34
|
+
export function logos() {
|
|
35
|
+
const dir = path.join(PAGE, 'assets', 'logos'), out = {};
|
|
36
|
+
for (const f of fs.readdirSync(dir).filter(f => f.endsWith('.svg'))) {
|
|
37
|
+
let s = fs.readFileSync(path.join(dir, f), 'utf8').replace(/<\?xml[^>]*\?>|<!--[\s\S]*?-->|<title>[\s\S]*?<\/title>/g, '').trim();
|
|
38
|
+
s = s.replace(/<svg\b[^>]*>/, tag => tag.replace(/\s(width|height|style)="[^"]*"/g, '').replace('<svg', '<svg style="width:100%;height:100%" preserveAspectRatio="xMidYMid meet"'));
|
|
39
|
+
out[f.replace(/\.svg$/, '')] = s.replace(/\s+/g, ' ');
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const safeJSON = v => JSON.stringify(v).replace(/</g, '\\u003c').replace(/[\u2028\u2029]/g, c => '\\u' + c.charCodeAt(0).toString(16));
|
|
45
|
+
|
|
46
|
+
/** build the page; returns the absolute path of the written file */
|
|
47
|
+
export function render(wrapped, { outDir, file = `agent-wrapped-${wrapped?.year || 'year'}.html` } = {}) {
|
|
48
|
+
const tpl = fs.readFileSync(path.join(PAGE, 'story.html'), 'utf8');
|
|
49
|
+
for (const marker of ['<style id="aw-fonts"></style>', '<script id="aw-data"></script>'])
|
|
50
|
+
if (!tpl.includes(marker)) throw new Error(`page/story.html is missing the marker ${marker}`);
|
|
51
|
+
const html = tpl
|
|
52
|
+
.replace('<style id="aw-fonts"></style>', () => `<style id="aw-fonts">${fontCSS()}</style>`)
|
|
53
|
+
.replace('<script id="aw-data"></script>', () => `<script id="aw-data">window.WRAPPED=${safeJSON(wrapped)};window.AW_LOGOS=${safeJSON(logos())};</script>`);
|
|
54
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
55
|
+
const out = path.join(outDir, file);
|
|
56
|
+
fs.writeFileSync(out, html);
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// dev: node src/render.mjs <wrapped.json> [outDir] → writes the page and prints its path
|
|
61
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
62
|
+
const src = process.argv[2] || path.join(ROOT, 'test', 'fixtures', 'sample-wrapped.json');
|
|
63
|
+
const out = render(JSON.parse(fs.readFileSync(src, 'utf8')), { outDir: process.argv[3] || path.join(ROOT, 'out') });
|
|
64
|
+
console.log(out);
|
|
65
|
+
}
|
package/src/site.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Build the GitHub Pages site into site/: demo story, #d= viewer, harness pages, privacy, llms.txt, sitemap.
|
|
2
|
+
// node src/site.mjs [demo-wrapped.json]
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { render } from './render.mjs';
|
|
7
|
+
|
|
8
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
|
+
const SITE = path.join(ROOT, 'site');
|
|
10
|
+
const BASE = 'https://leonardodaviti.github.io/agent-wrapped/';
|
|
11
|
+
const demo = JSON.parse(fs.readFileSync(process.argv[2] || path.join(ROOT, 'test', 'fixtures', 'sample-wrapped.json'), 'utf8'));
|
|
12
|
+
|
|
13
|
+
render(demo, { outDir: SITE, file: 'demo.html' }); // the hero story on the landing page
|
|
14
|
+
render(null, { outDir: SITE, file: 'w.html' }); // viewer for shared #d= links
|
|
15
|
+
fs.copyFileSync(path.join(ROOT, '.claude-plugin', 'icon.png'), path.join(SITE, 'icon.png'));
|
|
16
|
+
// the landing's own faces (OFL, served from site/fonts, no CDN): display, HUD mono, Pi's serif italic
|
|
17
|
+
const FONTS = ['mona-sans/mona-sans-900-normal.woff2', 'mona-sans/mona-sans-700-normal.woff2', 'commit-mono/commit-mono-400-normal.woff2', 'commit-mono/commit-mono-700-normal.woff2', 'source-serif-4/source-serif-4-600-italic.woff2'];
|
|
18
|
+
fs.mkdirSync(path.join(SITE, 'fonts'), { recursive: true });
|
|
19
|
+
for (const f of FONTS) fs.copyFileSync(path.join(ROOT, 'page', 'assets', 'fonts', f), path.join(SITE, 'fonts', path.basename(f)));
|
|
20
|
+
fs.copyFileSync(path.join(ROOT, 'page', 'assets', 'fonts', 'NOTICE.md'), path.join(SITE, 'fonts', 'NOTICE.md'));
|
|
21
|
+
|
|
22
|
+
const HARNESS = [
|
|
23
|
+
['claude-code', 'Claude Code', '~/.claude (history.jsonl, stats-cache.json, projects/)', 'Claude Code keeps transcripts for 30 days by default; Agent Wrapped still finds every prompt since you installed it in history.jsonl.'],
|
|
24
|
+
['codex', 'Codex', '~/.codex (session rollouts and the state database)', 'Subagent and review threads are counted once, not as copies of their parent.'],
|
|
25
|
+
['pi', 'Pi', '~/.pi/agent/sessions', 'Your custom Pi theme becomes the theme of your wrap.'],
|
|
26
|
+
['mistral-vibe', 'Mistral Vibe', '~/.vibe (vibehistory and session logs)', 'Wear the Mistral Vibe skin: the yellow-to-red pixel gradient.'],
|
|
27
|
+
];
|
|
28
|
+
const page = (id, name, where, note) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
29
|
+
<title>${name} Wrapped 2026 — your year with ${name}, wrapped · Agent Wrapped</title>
|
|
30
|
+
<meta name="description" content="${name} wrapped: your 2026 with ${name} as a Spotify-Wrapped-style story — prompts, tokens, streaks, model of the year, a roast. Runs locally.">
|
|
31
|
+
<link rel="canonical" href="${BASE}${id}-wrapped.html"><meta property="og:image" content="${BASE}og.png"><meta name="twitter:card" content="summary_large_image">
|
|
32
|
+
<style>body{background:#141413;color:#f3f0e8;font:17px/1.5 Inter,system-ui,sans-serif;max-width:760px;margin:0 auto;padding:48px 24px}a{color:#d77757}code{background:#0b0b0b;border:1px solid #d77757;border-radius:10px;padding:12px 14px;display:block;font:15px ui-monospace,monospace;margin:14px 0;overflow-wrap:anywhere}h1{font:800 46px/1.05 Inter,system-ui,sans-serif;letter-spacing:-.03em}</style></head><body>
|
|
33
|
+
<p><a href="./">■ Agent Wrapped</a></p><h1>${name} wrapped 2026</h1>
|
|
34
|
+
<p>Your year with ${name}: prompts, tokens, streak, model of the year, how often you said please and how often it said “you’re right”, your agentic age, and a roast written by your own agent.</p>
|
|
35
|
+
<p>Run it in a terminal, or paste it into ${name}:</p><code>npx wrapped-agents</code>
|
|
36
|
+
<p>It reads <b>${where}</b>, read-only. ${note} Your usage data never leaves your machine.</p>
|
|
37
|
+
<p><a href="./">See a demo wrap →</a> · <a href="https://github.com/leonardodaviti/agent-wrapped">GitHub</a></p></body></html>`;
|
|
38
|
+
for (const h of HARNESS) fs.writeFileSync(path.join(SITE, `${h[0]}-wrapped.html`), page(...h));
|
|
39
|
+
|
|
40
|
+
fs.writeFileSync(path.join(SITE, 'privacy.html'), `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Privacy · Agent Wrapped</title>
|
|
41
|
+
<style>body{background:#141413;color:#f3f0e8;font:17px/1.55 Inter,system-ui,sans-serif;max-width:720px;margin:0 auto;padding:48px 24px}a{color:#d77757}</style></head><body>
|
|
42
|
+
<p><a href="./">■ Agent Wrapped</a></p><h1>Privacy</h1>
|
|
43
|
+
<ul><li>Agent Wrapped runs on your computer and reads your agent logs read-only.</li>
|
|
44
|
+
<li>Prompt text is counted inside the reader and never stored or sent. Credentials, file paths, emails and your user and host names are dropped before counting.</li>
|
|
45
|
+
<li>Your usage data is never uploaded. The only network use: downloading the package itself, and (if <code>gh</code> is already signed in) asking GitHub for your username.</li>
|
|
46
|
+
<li>The QR code on the last slide puts only your totals into the link's #fragment, which browsers never send to a server. This site has no analytics.</li>
|
|
47
|
+
<li>Project names are hidden on cards unless you choose to show them.</li></ul></body></html>`);
|
|
48
|
+
|
|
49
|
+
fs.writeFileSync(path.join(SITE, 'llms.txt'), `# Agent Wrapped
|
|
50
|
+
> Year in review ("wrapped") for AI coding agents: Claude Code, Codex, Pi, Mistral Vibe. Runs locally; usage data never leaves the machine.
|
|
51
|
+
|
|
52
|
+
To make a user's wrapped: run \`npx -y wrapped-agents\` (opens the story in the browser). Agents may write the roast themselves: run \`npx -y wrapped-agents --json --no-open\`, read the printed wrapped-<year>.json, then \`npx -y wrapped-agents --from <file> --roast "<≤12 words citing its numbers>"\`. Skill: https://github.com/leonardodaviti/agent-wrapped/blob/main/SKILL.md
|
|
53
|
+
|
|
54
|
+
- [Repository](https://github.com/leonardodaviti/agent-wrapped)
|
|
55
|
+
- [SKILL.md](https://github.com/leonardodaviti/agent-wrapped/blob/main/SKILL.md)
|
|
56
|
+
- [Privacy](${BASE}privacy.html)
|
|
57
|
+
`);
|
|
58
|
+
fs.writeFileSync(path.join(SITE, 'robots.txt'), `User-agent: *\nAllow: /\nSitemap: ${BASE}sitemap.xml\n`);
|
|
59
|
+
const urls = ['', ...HARNESS.map(h => `${h[0]}-wrapped.html`), 'privacy.html'];
|
|
60
|
+
fs.writeFileSync(path.join(SITE, 'sitemap.xml'), `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.map(u => `<url><loc>${BASE}${u}</loc></url>`).join('\n')}\n</urlset>\n`);
|
|
61
|
+
fs.writeFileSync(path.join(SITE, '.nojekyll'), '');
|
|
62
|
+
console.log('site built:', fs.readdirSync(SITE).join(' '));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Agentic Age (spec §17, draft rule the owner edits). Deterministic, no LLM.
|
|
2
|
+
// start 30
|
|
3
|
+
// −2 per 10 pts of late-night share (22:00–05:00) above 10 %
|
|
4
|
+
// +0.5 per word of median prompt above 10 (max +10)
|
|
5
|
+
// −1 per 10 pts of prompts under 5 words
|
|
6
|
+
// −1 per 10 pts of weekend share above 20 %
|
|
7
|
+
// +1 per 10 days of longest streak
|
|
8
|
+
// +1 per 10 pts of "please" share
|
|
9
|
+
// Terms are continuous (no per-term rounding); the sum is rounded once, then clamped to 18–80.
|
|
10
|
+
// Owner 2026: 30 −2.05 +3.5 −2.13 −0.19 +3.5 +1.92 = 34.55 → 35.
|
|
11
|
+
|
|
12
|
+
const pct = x => Math.round(x * 100);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* p = { lateShare, medianWords, shortShare, weekendShare, streakDays, pleaseShare } (shares 0–1; null = unknown, term skipped)
|
|
16
|
+
* → { years, why: [chip…], raw, terms: [{ key, delta, chip }] } or null when nothing is known
|
|
17
|
+
*/
|
|
18
|
+
export function agenticAge(p) {
|
|
19
|
+
if (!p) return null;
|
|
20
|
+
const terms = [];
|
|
21
|
+
const add = (key, v, delta, chip) => { if (v != null && Number.isFinite(v)) terms.push({ key, delta, chip }); };
|
|
22
|
+
add('late', p.lateShare, -2 * Math.max(0, p.lateShare * 100 - 10) / 10, `${pct(p.lateShare)}% after 22:00`);
|
|
23
|
+
add('words', p.medianWords, Math.min(10, 0.5 * Math.max(0, p.medianWords - 10)), `${Math.round(p.medianWords)}-word prompts`);
|
|
24
|
+
add('short', p.shortShare, -1 * (p.shortShare * 100) / 10, `${pct(p.shortShare)}% under 5 words`);
|
|
25
|
+
add('weekend', p.weekendShare, -1 * Math.max(0, p.weekendShare * 100 - 20) / 10, `${pct(p.weekendShare)}% on weekends`);
|
|
26
|
+
add('streak', p.streakDays, (p.streakDays || 0) / 10, `${p.streakDays}-day streak`);
|
|
27
|
+
add('please', p.pleaseShare, (p.pleaseShare * 100) / 10, `${pct(p.pleaseShare)}% please`);
|
|
28
|
+
if (!terms.length) return null;
|
|
29
|
+
const raw = 30 + terms.reduce((a, t) => a + t.delta, 0);
|
|
30
|
+
const years = Math.min(80, Math.max(18, Math.round(raw)));
|
|
31
|
+
// chips: the four terms that moved the age most; ties keep rule order
|
|
32
|
+
const why = [...terms].map((t, i) => ({ ...t, i })).filter(t => Math.abs(t.delta) >= 0.05)
|
|
33
|
+
.sort((a, b) => Math.abs(b.delta) - Math.abs(a.delta) || a.i - b.i).slice(0, 4)
|
|
34
|
+
.sort((a, b) => a.i - b.i).map(t => t.chip);
|
|
35
|
+
return { years, why, raw: Math.round(raw * 100) / 100, terms: terms.map(t => ({ key: t.key, delta: Math.round(t.delta * 100) / 100, chip: t.chip })) };
|
|
36
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Awards (CONTRACT §4). Each award = { id, label, value, detail, source }, values are display strings.
|
|
2
|
+
// An award whose data is unknown (null) is omitted, never invented.
|
|
3
|
+
|
|
4
|
+
export const AWARD_IDS = ['harness', 'model', 'tokens', 'spendings', 'prompts', 'sessions', 'streak', 'marathon', 'swarm',
|
|
5
|
+
'peakHour', 'politeness', 'backseat', 'lines', 'mostResumed', 'wordOfYear', 'agentClass', 'tier', 'skill', 'rateLimits',
|
|
6
|
+
'age', 'twin', 'youreRight', 'modelRace', 'caps', 'screenshots', 'compactions', 'prs', 'ctrlZ', 'roast'];
|
|
7
|
+
|
|
8
|
+
export const num = n => Math.round(n).toLocaleString('en-US');
|
|
9
|
+
/** 3 significant digits with K / M / B / T: 67186477338 → 67.2B, 1071182 → 1.07M, 29429 → 29.4K */
|
|
10
|
+
export function compact(n) {
|
|
11
|
+
const a = Math.abs(n);
|
|
12
|
+
for (const [d, s] of [[1e12, 'T'], [1e9, 'B'], [1e6, 'M'], [1e3, 'K']]) {
|
|
13
|
+
if (a >= d * 0.9995) { const v = n / d; return (v >= 100 ? v.toFixed(0) : v >= 10 ? v.toFixed(1) : v.toFixed(2)).replace(/\.?0+$/, '') + s; }
|
|
14
|
+
}
|
|
15
|
+
return String(Math.round(n));
|
|
16
|
+
}
|
|
17
|
+
export const pctOf = (a, b) => `${Math.round(100 * a / b)}%`;
|
|
18
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
19
|
+
const shortDate = d => `${MONTHS[+d.slice(5, 7) - 1]} ${+d.slice(8, 10)}`;
|
|
20
|
+
const has = v => v != null && !(typeof v === 'number' && !Number.isFinite(v));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* ctx: the merged aggregate built by index.mjs (see buildWrapped) plus the finished wrapped sections.
|
|
24
|
+
*/
|
|
25
|
+
export function buildAwards(ctx) {
|
|
26
|
+
const { w, m } = ctx; // w = wrapped (totals, harnesses, models, tier, age, twin, spendings, roast), m = merged facts
|
|
27
|
+
const out = [];
|
|
28
|
+
const add = (id, label, value, detail, source) => { if (has(value) && value !== '') out.push({ id, label, value: String(value), detail: detail || '', source }); };
|
|
29
|
+
|
|
30
|
+
const h0 = w.harnesses[0];
|
|
31
|
+
if (h0 && h0.prompts > 0) add('harness', 'Harness of the Year', h0.label, `${Math.round(h0.share * 100)}% of prompts`, 'prompts per harness');
|
|
32
|
+
|
|
33
|
+
const m0 = w.models[0];
|
|
34
|
+
if (m0 && m0.tokens > 0) add('model', 'Model of the Year', m0.label, `${Math.round(m0.share * 100)}% of tokens`, 'tokens per model');
|
|
35
|
+
|
|
36
|
+
if (w.totals.tokens) add('tokens', 'Tokens', compact(w.totals.tokens),
|
|
37
|
+
w.totals.cacheShare != null ? `${Math.round(w.totals.cacheShare * 100)}% re-read from cache` : '', 'usage, de-duplicated');
|
|
38
|
+
|
|
39
|
+
const s = w.spendings;
|
|
40
|
+
if (s && s.usd != null) {
|
|
41
|
+
const value = s.usd === 0 ? '$0' : `≈ $${s.usd >= 1000 ? compact(s.usd) : num(s.usd)}`;
|
|
42
|
+
const detail = s.usd === 0 ? 'ran local' : `$${num(s.perDay)}/day at API list prices${s.priceDate ? ', ' + MONTHS[+s.priceDate.slice(5, 7) - 1] + ' ' + s.priceDate.slice(0, 4) : ''}`;
|
|
43
|
+
add('spendings', 'Spendings', value, detail, 'tokens × list price');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (w.totals.prompts) add('prompts', 'Prompts', num(w.totals.prompts), `across ${w.harnesses.filter(h => h.prompts > 0).length} harness${w.harnesses.filter(h => h.prompts > 0).length === 1 ? '' : 'es'}`, 'typed prompts');
|
|
47
|
+
|
|
48
|
+
if (w.totals.sessions) add('sessions', 'Sessions', num(w.totals.sessions), m.maxConcurrent ? `up to ${m.maxConcurrent} at once` : '', 'session files');
|
|
49
|
+
|
|
50
|
+
const st = w.totals.streak;
|
|
51
|
+
if (st && st.days) add('streak', 'Streak', `${st.days} day${st.days === 1 ? '' : 's'}`, st.days > 1 ? `${shortDate(st.from)} – ${shortDate(st.to)}` : shortDate(st.from), 'active days');
|
|
52
|
+
|
|
53
|
+
if (m.longest) add('marathon', 'Marathon', `${num(m.longest.activeHours)} h`, 'one session, active time', 'idle gaps excluded');
|
|
54
|
+
|
|
55
|
+
if (w.totals.subagents) add('swarm', 'Swarm', `${num(w.totals.subagents)} agents`,
|
|
56
|
+
w.totals.sessions ? `${(w.totals.subagents / w.totals.sessions).toFixed(1)} per session` : 'subagents spawned', 'subagent spawns');
|
|
57
|
+
|
|
58
|
+
const hours = m.hours, hTot = hours ? hours.reduce((a, b) => a + b, 0) : 0;
|
|
59
|
+
if (hTot) {
|
|
60
|
+
const peak = hours.indexOf(Math.max(...hours));
|
|
61
|
+
add('peakHour', 'Peak hour', `${String(peak).padStart(2, '0')}:00`, `${pctOf(hours.slice(0, 5).reduce((a, b) => a + b, 0), hTot)} after midnight`, 'prompt times');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (m.please != null && w.totals.prompts) add('politeness', 'Politeness', `${num(m.please)}× please`,
|
|
65
|
+
`${pctOf(m.please, w.totals.prompts)} of prompts${m.thanks ? `, ${num(m.thanks)}× thanks` : ''}`, 'prompt text, counted locally');
|
|
66
|
+
|
|
67
|
+
if (m.interrupts != null) add('backseat', 'Backseat driver', `${num(m.interrupts)}× Esc`, 'interrupted mid-answer', 'interrupt markers');
|
|
68
|
+
|
|
69
|
+
if (m.lines && m.lines.added != null) add('lines', 'Lines written', compact(m.lines.added),
|
|
70
|
+
`+${compact(m.lines.added)} / −${compact(m.lines.removed || 0)}`, 'edit diffs');
|
|
71
|
+
|
|
72
|
+
if (m.mostResumed) add('mostResumed', 'Most resumed', `${m.mostResumed.days} days`, 'one session, back again and again', 'session days');
|
|
73
|
+
|
|
74
|
+
const word = top(m.words), phrase = top(m.phrases);
|
|
75
|
+
if (word) add('wordOfYear', 'Word of the Year', `“${word[0]}”`, phrase ? `phrase: “${phrase[0]}”` : `in ${num(word[1])} prompts`, 'prompt words');
|
|
76
|
+
|
|
77
|
+
if (w.tier) {
|
|
78
|
+
add('agentClass', 'Agent class', w.tier.power, ctx.tierLine || '', 'tier');
|
|
79
|
+
add('tier', 'Top X%', w.tier.label, `score ${num(w.tier.score)}`, 'prompts × active days');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const sk = top(m.skills), mcp = top(m.mcp);
|
|
83
|
+
if (sk) add('skill', 'Skill of the Year', sk[0], `${num(sk[1])} runs`, 'skill calls');
|
|
84
|
+
else if (mcp) add('skill', 'Skill of the Year', mcp[0], `${num(mcp[1])} MCP calls`, 'MCP calls');
|
|
85
|
+
|
|
86
|
+
if (m.rateLimits) add('rateLimits', 'Rate limits', `${num(m.rateLimits.hits)} hit${m.rateLimits.hits === 1 ? '' : 's'}`,
|
|
87
|
+
m.rateLimits.days ? `on ${m.rateLimits.days}+ days` : '', 'limit messages');
|
|
88
|
+
|
|
89
|
+
if (w.age) add('age', 'Agentic Age', w.age.years, w.age.why.join(' · '), 'rule table');
|
|
90
|
+
if (w.twin) add('twin', 'Agent Twin', w.twin.name, `${w.twin.match}% match · ${w.twin.why}`, 'rule table');
|
|
91
|
+
|
|
92
|
+
if (m.assistant && m.assistant.youreRight != null) add('youreRight', '“You’re right”', `${num(m.assistant.youreRight)}×`,
|
|
93
|
+
m.assistant.absolutelyRight ? `${num(m.assistant.absolutelyRight)} absolutely` : '', 'assistant text');
|
|
94
|
+
|
|
95
|
+
if (ctx.raceWinners && ctx.raceWinners.length) {
|
|
96
|
+
const lbl = ctx.raceWinners, first = lbl.map(l => l.split(' ')[0]);
|
|
97
|
+
const same = first.every(f => f === first[0]) && lbl.every(l => l.includes(' '));
|
|
98
|
+
add('modelRace', 'Model race', (same ? lbl.map(l => l.slice(first[0].length + 1)) : lbl).join(' → '), 'monthly #1 by tokens', 'tokens per month');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (m.caps != null) add('caps', 'ALL CAPS', `${num(m.caps)}×`, '', 'prompt text');
|
|
102
|
+
if (m.images != null) add('screenshots', 'Screenshots', num(m.images), 'pasted', 'image blocks');
|
|
103
|
+
if (m.compactions != null) add('compactions', 'Compactions', num(m.compactions), '', 'compact events');
|
|
104
|
+
|
|
105
|
+
const x = ctx.extras;
|
|
106
|
+
if (x && x.prs && x.prs.total != null) {
|
|
107
|
+
const agentPrs = Object.values(x.prs.byAgent || {}).reduce((a, b) => a + b, 0);
|
|
108
|
+
const commits = x.commits ? Object.values(x.commits.coAuthored || {}).reduce((a, b) => a + b, 0) : 0;
|
|
109
|
+
add('prs', 'Shipped', `${num(agentPrs)} PRs`, commits ? `${num(commits)} co-authored commits` : `of ${num(x.prs.total)} PRs`, 'git + gh');
|
|
110
|
+
} else if (x && x.commits) {
|
|
111
|
+
const commits = Object.values(x.commits.coAuthored || {}).reduce((a, b) => a + b, 0);
|
|
112
|
+
if (commits) add('prs', 'Shipped', `${num(commits)} commits`, 'co-authored by agents', 'git log');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const gu = m.gitUndos ? Object.values(m.gitUndos).reduce((a, b) => a + b, 0) : null;
|
|
116
|
+
const undoParts = [gu, m.rewinds, m.undoAsks].filter(v => v != null);
|
|
117
|
+
if (undoParts.length) {
|
|
118
|
+
const total = undoParts.reduce((a, b) => a + b, 0);
|
|
119
|
+
const big = x && x.reverts && x.reverts.biggestLines ? `biggest cleanup ${num(x.reverts.biggestLines)} lines` : '';
|
|
120
|
+
add('ctrlZ', 'Ctrl+Z Award', `${num(total)} undos`, big, 'git undos + rewinds + asks');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (w.roast) add('roast', 'Roast', `“${w.roast}”`, 'written by your agent', 'wrapped.json');
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function top(map) {
|
|
128
|
+
if (!map) return null;
|
|
129
|
+
let best = null;
|
|
130
|
+
for (const [k, v] of Object.entries(map)) if (v > 0 && (!best || v > best[1])) best = [k, v];
|
|
131
|
+
return best;
|
|
132
|
+
}
|