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
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// agent-wrapped: detect harnesses → read logs locally → build wrapped.json → render one HTML file → open it.
|
|
3
|
+
// Nothing about your usage leaves this machine.
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { execFile, spawn } from 'node:child_process';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
9
|
+
import { readers } from './readers/index.mjs';
|
|
10
|
+
import { buildWrapped } from './stats/index.mjs';
|
|
11
|
+
import { render } from './render.mjs';
|
|
12
|
+
import { roastNumbersOk } from './stats/roast.mjs';
|
|
13
|
+
|
|
14
|
+
const run = promisify(execFile);
|
|
15
|
+
const HELP = `agent-wrapped — your year with AI coding agents, wrapped
|
|
16
|
+
|
|
17
|
+
usage: npx wrapped-agents [options]
|
|
18
|
+
|
|
19
|
+
--year <yyyy> year to wrap (default: this year)
|
|
20
|
+
--handle <name> GitHub username shown on the cards (default: detected)
|
|
21
|
+
--skin <name> wrapped | anthropic | claude-code | codex | opencode | pi | hermes | mistral-vibe | yours
|
|
22
|
+
--out <dir> where to write the page (default: ${path.join(os.tmpdir(), 'agent-wrapped')})
|
|
23
|
+
--json build wrapped.json only and print its path (for agents)
|
|
24
|
+
--from <file> render from an existing wrapped.json instead of reading logs
|
|
25
|
+
--roast "<line>" your agent's roast (≤ 12 words, numbers from this wrap)
|
|
26
|
+
--roast-by <name> who wrote it, e.g. "Claude Code" (shown under the roast)
|
|
27
|
+
--no-roast no roast slide
|
|
28
|
+
--show-projects show project names (hidden by default)
|
|
29
|
+
--no-git skip git commits / PRs
|
|
30
|
+
--no-open don't open the browser
|
|
31
|
+
-h, --help`;
|
|
32
|
+
|
|
33
|
+
function args(argv) {
|
|
34
|
+
const a = { year: new Date().getFullYear(), out: path.join(os.tmpdir(), 'agent-wrapped'), git: true, open: true };
|
|
35
|
+
for (let i = 0; i < argv.length; i++) {
|
|
36
|
+
const k = argv[i], v = () => argv[++i];
|
|
37
|
+
if (k === '-h' || k === '--help') a.help = true;
|
|
38
|
+
else if (k === '--year') a.year = +v();
|
|
39
|
+
else if (k === '--handle') a.handle = v();
|
|
40
|
+
else if (k === '--skin') a.skin = v();
|
|
41
|
+
else if (k === '--out') a.out = path.resolve(v());
|
|
42
|
+
else if (k === '--json') a.json = true;
|
|
43
|
+
else if (k === '--from') a.from = path.resolve(v());
|
|
44
|
+
else if (k === '--roast') a.roast = v();
|
|
45
|
+
else if (k === '--no-roast') a.roast = '';
|
|
46
|
+
else if (k === '--roast-by') a.roastBy = v();
|
|
47
|
+
else if (k === '--show-projects') a.showProjects = true;
|
|
48
|
+
else if (k === '--no-git') a.git = false;
|
|
49
|
+
else if (k === '--no-open') a.open = false;
|
|
50
|
+
else { console.error(`unknown option ${k}\n\n${HELP}`); process.exit(2); }
|
|
51
|
+
}
|
|
52
|
+
return a;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const log = (...m) => process.stderr.write(m.join(' ') + '\n');
|
|
56
|
+
|
|
57
|
+
/** GitHub username: gh (if already logged in) → git config github.user → null (the skill then asks) */
|
|
58
|
+
async function detectHandle() {
|
|
59
|
+
try { const { stdout } = await run('gh', ['api', 'user', '--jq', '.login'], { timeout: 5000 }); if (stdout.trim()) return stdout.trim(); } catch {}
|
|
60
|
+
try { const { stdout } = await run('git', ['config', '--global', 'github.user'], { timeout: 3000 }); if (stdout.trim()) return stdout.trim(); } catch {}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function openFile(file) {
|
|
65
|
+
const cmd = process.platform === 'darwin' ? ['open', [file]] : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', file]] : ['xdg-open', [file]];
|
|
66
|
+
try { spawn(cmd[0], cmd[1], { detached: true, stdio: 'ignore' }).unref(); return true; } catch { return false; }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function cleanRoast(s) {
|
|
70
|
+
const r = String(s || '').replace(/\s+/g, ' ').trim();
|
|
71
|
+
if (!r) return null;
|
|
72
|
+
const words = r.split(' ');
|
|
73
|
+
return words.length > 14 ? words.slice(0, 14).join(' ') + '…' : r;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function main() {
|
|
77
|
+
const a = args(process.argv.slice(2));
|
|
78
|
+
if (a.help) return console.log(HELP);
|
|
79
|
+
const env = { home: os.homedir(), platform: process.platform, now: new Date(), year: a.year };
|
|
80
|
+
let wrapped;
|
|
81
|
+
|
|
82
|
+
if (a.from) {
|
|
83
|
+
wrapped = JSON.parse(fs.readFileSync(a.from, 'utf8'));
|
|
84
|
+
} else {
|
|
85
|
+
const t0 = Date.now(), facts = [];
|
|
86
|
+
for (const r of readers) {
|
|
87
|
+
let d;
|
|
88
|
+
try { d = await r.detect(env); } catch (e) { log(` ${r.label}: skipped (${e.message})`); continue; }
|
|
89
|
+
if (!d?.found) continue;
|
|
90
|
+
log(` reading ${r.label}…`);
|
|
91
|
+
try { facts.push(await r.read(env, { year: a.year, onProgress: m => log(` ${m}`) })); }
|
|
92
|
+
catch (e) { log(` ${r.label}: could not read (${e.message})`); }
|
|
93
|
+
}
|
|
94
|
+
if (!facts.length) { log('No agent history found for', a.year, '(looked for Claude Code, Codex, Pi, Mistral Vibe).'); process.exit(1); }
|
|
95
|
+
let extras = null;
|
|
96
|
+
if (a.git) { try { const { collectExtras } = await import('./stats/git.mjs'); extras = await collectExtras({ home: env.home, year: a.year }); } catch (e) { log(` git: skipped (${e.message})`); } }
|
|
97
|
+
const handle = a.handle || await detectHandle();
|
|
98
|
+
wrapped = buildWrapped(facts, { year: a.year, extras, handle, now: env.now });
|
|
99
|
+
log(` done in ${((Date.now() - t0) / 1000).toFixed(1)} s`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (a.handle) wrapped.handle = { ...(wrapped.handle || {}), github: a.handle, display: a.handle };
|
|
103
|
+
if (a.skin) wrapped.theme = { ...(wrapped.theme || {}), skin: a.skin };
|
|
104
|
+
if (a.roast !== undefined) {
|
|
105
|
+
wrapped.roast = cleanRoast(a.roast);
|
|
106
|
+
wrapped.roastBy = a.roastBy || 'your agent';
|
|
107
|
+
// every number in the roast must exist in this wrap (agents sometimes reuse numbers from an older run)
|
|
108
|
+
if (wrapped.roast && !roastNumbersOk(wrapped, wrapped.roast)) log(`warning: the roast cites numbers that aren't in this wrap; please re-write it from wrapped-${wrapped.year}.json`);
|
|
109
|
+
}
|
|
110
|
+
if (a.showProjects) wrapped.privacy = { ...(wrapped.privacy || {}), projectsHidden: false };
|
|
111
|
+
|
|
112
|
+
fs.mkdirSync(a.out, { recursive: true });
|
|
113
|
+
const json = path.join(a.out, `wrapped-${wrapped.year}.json`);
|
|
114
|
+
fs.writeFileSync(json, JSON.stringify(wrapped, null, 1));
|
|
115
|
+
if (a.json) { console.log(json); return; }
|
|
116
|
+
|
|
117
|
+
const page = render(wrapped, { outDir: a.out });
|
|
118
|
+
console.log(page);
|
|
119
|
+
if (a.open && !openFile(page)) log('Open this file in your browser:', page);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main().catch(e => { log('agent-wrapped failed:', e.stack || e.message); process.exit(1); });
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"currency": "USD",
|
|
4
|
+
"unit": "per 1M tokens",
|
|
5
|
+
"tier": "standard (short context, no batch / fast / priority discounts or surcharges)",
|
|
6
|
+
"notes": [
|
|
7
|
+
"Spendings are what the year would cost at API list prices; they are not what the user paid.",
|
|
8
|
+
"estimated: true means at least one field is not on the provider's page and was derived: cacheWrite = 1.25 x input, cacheRead = 0.1 x input (Anthropic standard ratios); Mistral cached input = 0.1 x input ('cached input tokens cost 90% less'). estimatedFields lists which.",
|
|
9
|
+
"OpenAI long-context (> 272K input) and Mistral regional (+10%) surcharges are ignored: logs don't say which requests hit them.",
|
|
10
|
+
"Unknown models are never guessed: they go to spendings.unpriced. Local / open-weight models served without a provider cost $0 and go to spendings.local."
|
|
11
|
+
],
|
|
12
|
+
"models": {
|
|
13
|
+
"claude-opus-5-5": { "label": "Opus 5.5", "provider": "anthropic", "input": 4, "output": 20, "cacheWrite": 5, "cacheRead": 0.2, "estimated": true, "estimatedFields": ["cacheWrite"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
14
|
+
"claude-opus-5": { "label": "Opus 5", "provider": "anthropic", "input": 5, "output": 25, "cacheWrite": 6.25, "cacheRead": 0.5, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
15
|
+
"claude-opus-4-8": { "label": "Opus 4.8", "provider": "anthropic", "input": 5, "output": 25, "cacheWrite": 6.25, "cacheRead": 0.5, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
16
|
+
"claude-opus-4-7": { "label": "Opus 4.7", "provider": "anthropic", "input": 5, "output": 25, "cacheWrite": 6.25, "cacheRead": 0.5, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
17
|
+
"claude-fable-5": { "label": "Fable 5", "provider": "anthropic", "input": 10, "output": 50, "cacheWrite": 12.5, "cacheRead": 1, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
18
|
+
"claude-fable-5-1": { "label": "Fable 5.1", "provider": "anthropic", "input": 10, "output": 50, "cacheWrite": 12.5, "cacheRead": 1, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
19
|
+
"claude-fable-5-2": { "label": "Fable 5.2", "provider": "anthropic", "input": 8, "output": 40, "cacheWrite": 10, "cacheRead": 0.2, "estimated": true, "estimatedFields": ["cacheWrite"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
20
|
+
"claude-sonnet-5-5": { "label": "Sonnet 5.5", "provider": "anthropic", "input": 2, "output": 10, "cacheWrite": 2.5, "cacheRead": 0.1, "estimated": true, "estimatedFields": ["cacheWrite"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
21
|
+
"claude-sonnet-5": { "label": "Sonnet 5", "provider": "anthropic", "input": 2, "output": 10, "cacheWrite": 2.5, "cacheRead": 0.2, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
22
|
+
"claude-sonnet-4-6": { "label": "Sonnet 4.6", "provider": "anthropic", "input": 3, "output": 15, "cacheWrite": 3.75, "cacheRead": 0.3, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
23
|
+
"claude-haiku-5-5": { "label": "Haiku 5.5", "provider": "anthropic", "input": 0.1, "output": 0.5, "cacheWrite": 0.125, "cacheRead": 0.01, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
24
|
+
"claude-haiku-4-5": { "label": "Haiku 4.5", "provider": "anthropic", "input": 1, "output": 5, "cacheWrite": 1.25, "cacheRead": 0.1, "estimated": true, "estimatedFields": ["cacheWrite", "cacheRead"], "source": "https://docs.claude.com/en/docs/about-claude/pricing", "date": "2026-11-03" },
|
|
25
|
+
|
|
26
|
+
"gpt-6-astra": { "label": "GPT-6 Astra", "provider": "openai", "input": 10, "output": 50, "cacheWrite": 12.5, "cacheRead": 1, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
27
|
+
"gpt-6-sol": { "label": "GPT-6 Sol", "provider": "openai", "input": 2, "output": 10, "cacheWrite": 2.5, "cacheRead": 0.2, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
28
|
+
"gpt-6-luna": { "label": "GPT-6 Luna", "provider": "openai", "input": 0.1, "output": 0.5, "cacheWrite": 0.125, "cacheRead": 0.01, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
29
|
+
"gpt-6.1-sol": { "label": "GPT-6.1 Sol", "provider": "openai", "input": 2, "output": 10, "cacheWrite": 2.5, "cacheRead": 0.1, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
30
|
+
"gpt-6.1-terra": { "label": "GPT-6.1 Terra", "provider": "openai", "input": 1, "output": 5, "cacheWrite": 1.25, "cacheRead": 0.05, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
31
|
+
"gpt-6.2-astra": { "label": "GPT-6.2 Astra", "provider": "openai", "input": 8, "output": 40, "cacheWrite": 10, "cacheRead": 0.4, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
32
|
+
"gpt-6.2-sol": { "label": "GPT-6.2 Sol", "provider": "openai", "input": 2, "output": 10, "cacheWrite": 2.5, "cacheRead": 0.1, "estimated": false, "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
33
|
+
"gpt-5.3-codex": { "label": "GPT-5.3 Codex", "provider": "openai", "input": 1.75, "output": 14, "cacheWrite": 1.75, "cacheRead": 0.175, "estimated": true, "estimatedFields": ["cacheWrite"], "source": "https://developers.openai.com/api/docs/pricing", "date": "2026-12-04" },
|
|
34
|
+
|
|
35
|
+
"mistral-large-4": { "label": "Mistral Large 4", "provider": "mistral", "input": 0.7, "output": 2.1, "cacheWrite": 0.7, "cacheRead": 0.07, "estimated": false, "source": "https://docs.mistral.ai/inference/pricing", "date": "2026-12-04" },
|
|
36
|
+
"mistral-medium-3-5": { "label": "Mistral Medium 3.5", "provider": "mistral", "input": 1.5, "output": 7.5, "cacheWrite": 1.5, "cacheRead": 0.15, "estimated": true, "estimatedFields": ["cacheRead"], "source": "https://docs.mistral.ai/models/mistral-medium-3-5-26-04", "date": "2026-12-04" },
|
|
37
|
+
"devstral-2": { "label": "Devstral 2", "provider": "mistral", "input": 0.4, "output": 2, "cacheWrite": 0.4, "cacheRead": 0.04, "estimated": true, "estimatedFields": ["cacheRead"], "source": "https://docs.mistral.ai/models/devstral-2-25-12", "date": "2026-12-04" },
|
|
38
|
+
"devstral-small-2": { "label": "Devstral Small 2", "provider": "mistral", "input": 0.1, "output": 0.3, "cacheWrite": 0.1, "cacheRead": 0.01, "estimated": true, "estimatedFields": ["cacheRead"], "source": "https://mistral.ai/news/devstral-2-vibe-cli/", "date": "2026-12-04" },
|
|
39
|
+
"zai-glm-5-3": { "label": "GLM 5.3", "provider": "mistral", "input": 1.4, "output": 4.4, "cacheWrite": 1.4, "cacheRead": 0.14, "estimated": false, "source": "https://docs.mistral.ai/inference/pricing", "date": "2026-12-04" },
|
|
40
|
+
"zai-glm-5-3-flash": { "label": "GLM 5.3 Flash", "provider": "mistral", "input": 0.15, "output": 0.5, "cacheWrite": 0.15, "cacheRead": 0.03, "estimated": false, "source": "https://docs.mistral.ai/inference/pricing", "date": "2026-12-04" },
|
|
41
|
+
"deepseek-v4-1-flash-1017": { "label": "DeepSeek V4.1 Flash", "provider": "mistral", "input": 0.3, "output": 1.2, "cacheWrite": 0.3, "cacheRead": 0.007, "estimated": false, "source": "https://docs.mistral.ai/inference/pricing", "date": "2026-12-04" }
|
|
42
|
+
},
|
|
43
|
+
"aliases": {
|
|
44
|
+
"mistral-large-4-0": "mistral-large-4",
|
|
45
|
+
"mistral-large-latest": "mistral-large-4",
|
|
46
|
+
"mistral-medium-latest": "mistral-medium-3-5",
|
|
47
|
+
"mistral-medium": "mistral-medium-3-5",
|
|
48
|
+
"mistral-medium-3.5": "mistral-medium-3-5",
|
|
49
|
+
"mistral-vibe-cli-latest": "mistral-medium-3-5",
|
|
50
|
+
"devstral-2-25-12": "devstral-2",
|
|
51
|
+
"devstral-2512": "devstral-2",
|
|
52
|
+
"devstral-latest": "devstral-2",
|
|
53
|
+
"devstral-medium-latest": "devstral-2",
|
|
54
|
+
"devstral-small-latest": "devstral-small-2",
|
|
55
|
+
"glm-5-3": "zai-glm-5-3",
|
|
56
|
+
"zai-glm-5": "zai-glm-5-3",
|
|
57
|
+
"zai-glm-latest": "zai-glm-5-3",
|
|
58
|
+
"deepseek-v4-flash-1017": "deepseek-v4-1-flash-1017"
|
|
59
|
+
},
|
|
60
|
+
"labels": {
|
|
61
|
+
"codex-auto-review": "Codex Auto Review"
|
|
62
|
+
},
|
|
63
|
+
"local": {
|
|
64
|
+
"rule": "open-weight families with no provider prefix (or a model the reader marks local: true) ran on the user's machine: $0",
|
|
65
|
+
"patterns": ["^qwen", "^qwopus", "^gemma", "^llama", "^lfm", "^nemotron", "^phi-?\\d", "^gpt-oss", "^olmo", "^granite", "^smollm", "^deepseek-r1", "^mistral-nemo", "^ministral-\\d+b", "^codellama", "^starcoder", "^[a-z0-9.-]+:(\\d+(\\.\\d+)?b|latest)$"]
|
|
66
|
+
}
|
|
67
|
+
}
|
package/src/privacy.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Shared text helpers. Readers call these so prompt text never leaves the reader.
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
|
|
4
|
+
const STOP = new Set(`a an the and or but if then else of to in on at for from by with without into onto over under up down out is are was were be been being am do does did done have has had i you he she it we they me my your our their this that these those there here what which who whom whose when where why how all any some no not only also just so very can could should would will shall may might must let lets please thanks thank yes ok okay now still again more most less much many few same other such than too as about after before while because until via per vs etc i'm it's don't can't won't let's that's there's you're we're they're i've you've we've i'll you'll im dont cant wont thats theres youre them well like want need make made get got use using used one two way thing things something see look know think good new really maybe sure right okay yeah file files code`.split(/\s+/));
|
|
5
|
+
const CRED = /(pass(word|wd|phrase)?|secret|token|api[-_]?key|apikey|bearer|private[-_]?key|ssh-rsa|sk-[a-z0-9]|ghp_|github_pat|aws_|otp|pin\b|credential|auth)/i;
|
|
6
|
+
const SWEARS = ['fuck', 'fucking', 'shit', 'wtf', 'damn', 'crap', 'bullshit', 'hell', 'stupid', 'idiot'];
|
|
7
|
+
const UNDO = /\b(revert|undo|put it back|roll ?back|you broke|restore (it|that|the)|go back to (the )?(previous|old))\b/i;
|
|
8
|
+
const local = () => [os.userInfo().username, os.hostname()].filter(Boolean).map(s => s.toLowerCase());
|
|
9
|
+
|
|
10
|
+
/** words of a prompt, safe to count: lowercase, no stopwords, no credentials, paths, urls, emails, user/host names, numbers */
|
|
11
|
+
export function tokens(text, extraBlock = []) {
|
|
12
|
+
if (!text || CRED.test(text)) return [];
|
|
13
|
+
const block = new Set([...local(), ...extraBlock.map(s => String(s).toLowerCase())]);
|
|
14
|
+
return String(text).toLowerCase()
|
|
15
|
+
.replace(/https?:\/\/\S+|\S+@\S+\.\S+|[~.]?\/[^\s]+|`[^`]*`/g, ' ')
|
|
16
|
+
.split(/[^a-zÀ-ɏЀ-ӿႠ-ჿ']+/)
|
|
17
|
+
.filter(w => w.length > 2 && w.length < 24 && !STOP.has(w) && !block.has(w) && !/^\d/.test(w));
|
|
18
|
+
}
|
|
19
|
+
/** 2–3 word phrases built from safe tokens (adjacent in the filtered stream) */
|
|
20
|
+
export function phrases(text, extraBlock) {
|
|
21
|
+
const t = tokens(text, extraBlock), out = [];
|
|
22
|
+
for (let i = 0; i < t.length - 1; i++) { out.push(t[i] + ' ' + t[i + 1]); if (i < t.length - 2) out.push(t.slice(i, i + 3).join(' ')); }
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
export const words = text => (String(text || '').trim().match(/\S+/g) || []).length;
|
|
26
|
+
export const hasPlease = t => /\bplease\b|\bpls\b/i.test(t || '');
|
|
27
|
+
export const hasThanks = t => /\b(thanks|thank you|thx|ty)\b/i.test(t || '');
|
|
28
|
+
export const isCaps = t => { const l = (t || '').replace(/[^A-Za-z]/g, ''); return l.length >= 8 && l === l.toUpperCase(); };
|
|
29
|
+
export const swears = t => { const out = {}; const s = (t || '').toLowerCase(); for (const w of SWEARS) { const n = (s.match(new RegExp(`\\b${w}\\b`, 'g')) || []).length; if (n) out[w] = n; } return out; };
|
|
30
|
+
export const asksUndo = t => UNDO.test(t || '');
|
|
31
|
+
export const oneWord = t => { const w = String(t || '').trim().toLowerCase().replace(/[^a-z]/g, ''); return w && !/\s/.test(String(t).trim()) && w.length < 20 && !CRED.test(w) ? w : null; };
|
|
32
|
+
|
|
33
|
+
/** bounded top-N counter, so readers never grow unbounded maps */
|
|
34
|
+
export class Top {
|
|
35
|
+
constructor(n = 200) { this.n = n; this.m = new Map(); }
|
|
36
|
+
add(k, by = 1) { if (k) this.m.set(k, (this.m.get(k) || 0) + by); if (this.m.size > this.n * 20) this.trim(this.n * 5); }
|
|
37
|
+
trim(n) { this.m = new Map([...this.m].sort((a, b) => b[1] - a[1]).slice(0, n)); }
|
|
38
|
+
toJSON() { this.trim(this.n); return Object.fromEntries(this.m); }
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Parallel per-file work on worker_threads (built in; no dependencies).
|
|
2
|
+
// Each job: import(moduleUrl)[fn](file, ctx) → plain object, merged by onResult on the main thread.
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
|
|
5
|
+
export function threadCount(n) {
|
|
6
|
+
const cpus = (os.availableParallelism ? os.availableParallelism() : os.cpus().length) || 1;
|
|
7
|
+
return Math.max(1, Math.min(n ?? cpus - 1, 8, cpus));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** files: [{path,size}] · onResult(result, file) called in completion order */
|
|
11
|
+
export async function mapFiles(moduleUrl, fn, files, ctx, onResult, { threads, onProgress } = {}) {
|
|
12
|
+
const jobs = [...files].sort((a, b) => b.size - a.size); // largest first, for balance
|
|
13
|
+
let done = 0; const total = jobs.length;
|
|
14
|
+
const tick = () => { done++; if (onProgress && (done % 200 === 0 || done === total)) onProgress(`${done}/${total} files`); };
|
|
15
|
+
const n = Math.min(threadCount(threads), jobs.length);
|
|
16
|
+
let Worker = null;
|
|
17
|
+
if (n > 1) { try { ({ Worker } = await import('node:worker_threads')); } catch { Worker = null; } }
|
|
18
|
+
if (!Worker) { // inline fallback
|
|
19
|
+
const mod = await import(moduleUrl);
|
|
20
|
+
for (const f of jobs) { let r; try { r = await mod[fn](f.path, ctx); } catch { r = null; } if (r) onResult(r, f); tick(); }
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let next = 0;
|
|
24
|
+
await Promise.all(Array.from({ length: n }, () => new Promise((resolve, reject) => {
|
|
25
|
+
const w = new Worker(new URL('./_worker.mjs', import.meta.url), { workerData: { moduleUrl, fn, ctx } });
|
|
26
|
+
let cur = null;
|
|
27
|
+
const feed = () => { if (next >= jobs.length) { w.terminate(); resolve(); return; } cur = jobs[next++]; w.postMessage(cur.path); };
|
|
28
|
+
w.on('message', r => { if (r) { try { onResult(r, cur); } catch (e) { w.terminate(); reject(e); return; } } tick(); feed(); });
|
|
29
|
+
w.on('error', e => { w.terminate(); reject(e); });
|
|
30
|
+
feed();
|
|
31
|
+
})));
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Prompt text → counts. Text goes in, only numbers and privacy-filtered words come out.
|
|
2
|
+
import { tokens, phrases, words, hasPlease, hasThanks, isCaps, swears, asksUndo, oneWord, Top } from '../privacy.mjs';
|
|
3
|
+
|
|
4
|
+
const PLACEHOLDER = /\[(?:Pasted text|Image|Pasted image)[^\]]*\]/gi;
|
|
5
|
+
const TAGS = /<([a-zA-Z_-]+)[^>]*>[\s\S]*?<\/\1>/g;
|
|
6
|
+
const WALL = 120;
|
|
7
|
+
|
|
8
|
+
export class PromptStats {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.count = 0; this.wc = new Map(); this.short = 0; this.please = 0; this.thanks = 0; this.caps = 0; this.images = 0;
|
|
11
|
+
this.swearTotal = 0; this.swearBy = {}; this.undoAsks = 0;
|
|
12
|
+
this.one = new Top(20); this.words = new Top(200); this.phr = new Top(100); this.slash = {};
|
|
13
|
+
}
|
|
14
|
+
/** count one prompt; `text` is dropped after this call */
|
|
15
|
+
add(text, { images = 0 } = {}) {
|
|
16
|
+
this.count++; this.images += images;
|
|
17
|
+
const raw = String(text || '');
|
|
18
|
+
const t = raw.replace(TAGS, ' ').replace(PLACEHOLDER, ' ').trim();
|
|
19
|
+
const n = words(t);
|
|
20
|
+
this.wc.set(n, (this.wc.get(n) || 0) + 1);
|
|
21
|
+
if (n < 5) this.short++;
|
|
22
|
+
const sl = /^\/([a-z][a-z0-9:_-]{0,40})(?=\s|$)/.exec(t); // a command, not a path like /home/...
|
|
23
|
+
if (sl) { const k = '/' + sl[1]; this.slash[k] = (this.slash[k] || 0) + 1; return; }
|
|
24
|
+
if (hasPlease(t)) this.please++;
|
|
25
|
+
if (hasThanks(t)) this.thanks++;
|
|
26
|
+
if (isCaps(t)) this.caps++;
|
|
27
|
+
const sw = swears(t); for (const k in sw) { this.swearBy[k] = (this.swearBy[k] || 0) + sw[k]; this.swearTotal += sw[k]; }
|
|
28
|
+
if (asksUndo(t)) this.undoAsks++;
|
|
29
|
+
const one = oneWord(t); if (one) this.one.add(one);
|
|
30
|
+
if (n > WALL) return;
|
|
31
|
+
for (const w of new Set(tokens(t))) this.words.add(w);
|
|
32
|
+
for (const p of new Set(phrases(t))) this.phr.add(p);
|
|
33
|
+
}
|
|
34
|
+
median() {
|
|
35
|
+
if (!this.count) return null;
|
|
36
|
+
const ks = [...this.wc.keys()].sort((a, b) => a - b); const mid = (this.count - 1) / 2; let seen = 0, lo = null;
|
|
37
|
+
for (const k of ks) {
|
|
38
|
+
const c = this.wc.get(k);
|
|
39
|
+
if (lo === null && seen + c > Math.floor(mid)) lo = k;
|
|
40
|
+
if (seen + c > Math.ceil(mid)) return (lo + k) / 2;
|
|
41
|
+
seen += c;
|
|
42
|
+
}
|
|
43
|
+
return lo;
|
|
44
|
+
}
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
count: this.count, medianWords: this.median(), short: this.short,
|
|
48
|
+
wordHist: Object.fromEntries([...this.wc].sort((x, y) => x[0] - y[0])),
|
|
49
|
+
please: this.please, thanks: this.thanks, caps: this.caps, images: this.images,
|
|
50
|
+
swears: { total: this.swearTotal, byWord: this.swearBy }, undoAsks: this.undoAsks,
|
|
51
|
+
oneWord: this.one.toJSON(), words: this.words.toJSON(), phrases: this.phr.toJSON(),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Shared helpers for readers: streaming, dates, windows, small aggregates.
|
|
2
|
+
// Nothing here keeps prompt or response text.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import fsp from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import readline from 'node:readline';
|
|
7
|
+
|
|
8
|
+
/** call fn(line) for every line of a file, streamed (never loads the whole file) */
|
|
9
|
+
export async function eachLine(file, fn) {
|
|
10
|
+
let stream;
|
|
11
|
+
try { stream = fs.createReadStream(file, { encoding: 'utf8', highWaterMark: 1 << 20 }); } catch { return false; }
|
|
12
|
+
const rl = readline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
13
|
+
try {
|
|
14
|
+
for await (const line of rl) if (line) fn(line);
|
|
15
|
+
} catch { return false; } finally { rl.close(); stream.destroy(); }
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** JSON.parse that returns undefined instead of throwing */
|
|
20
|
+
export function parse(line) { try { return JSON.parse(line); } catch { return undefined; } }
|
|
21
|
+
|
|
22
|
+
/** read a small whole-JSON config/aggregate file (not a log) */
|
|
23
|
+
export async function readJSON(file) {
|
|
24
|
+
try { return JSON.parse(await fsp.readFile(file, 'utf8')); } catch { return undefined; }
|
|
25
|
+
}
|
|
26
|
+
export async function readText(file) { try { return await fsp.readFile(file, 'utf8'); } catch { return undefined; } }
|
|
27
|
+
export async function exists(p) { try { await fsp.access(p); return true; } catch { return false; } }
|
|
28
|
+
export async function isDir(p) { try { return (await fsp.stat(p)).isDirectory(); } catch { return false; } }
|
|
29
|
+
|
|
30
|
+
/** recursive file list, filtered by name; sizes included for scheduling */
|
|
31
|
+
export async function walk(root, keep = () => true, out = []) {
|
|
32
|
+
let ents;
|
|
33
|
+
try { ents = await fsp.readdir(root, { withFileTypes: true }); } catch { return out; }
|
|
34
|
+
await Promise.all(ents.map(async e => {
|
|
35
|
+
const p = path.join(root, e.name);
|
|
36
|
+
if (e.isDirectory()) await walk(p, keep, out);
|
|
37
|
+
else if (e.isFile() && keep(e.name, p)) {
|
|
38
|
+
let size = 0; try { size = (await fsp.stat(p)).size; } catch {}
|
|
39
|
+
out.push({ path: p, size });
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const pad = n => (n < 10 ? '0' : '') + n;
|
|
46
|
+
/** local YYYY-MM-DD for epoch ms */
|
|
47
|
+
export function localDate(ms) { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate()); }
|
|
48
|
+
export function localMonth(ms) { const d = new Date(ms); return d.getFullYear() + '-' + pad(d.getMonth() + 1); }
|
|
49
|
+
export const utcDate = ms => new Date(ms).toISOString().slice(0, 10);
|
|
50
|
+
|
|
51
|
+
/** epoch ms from ISO string / epoch s / epoch ms; NaN if unknown */
|
|
52
|
+
export function toMs(t) {
|
|
53
|
+
if (typeof t === 'number') return t > 1e12 ? t : t * 1000;
|
|
54
|
+
if (typeof t === 'string') return Date.parse(t);
|
|
55
|
+
return NaN;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** [start, end) of the year window, local time, end capped at now */
|
|
59
|
+
export function windowOf(env, opts = {}) {
|
|
60
|
+
const year = opts.year ?? env.year ?? new Date().getFullYear();
|
|
61
|
+
const now = env.now ? +new Date(env.now) : Date.now();
|
|
62
|
+
const start = +new Date(year, 0, 1);
|
|
63
|
+
const end = Math.min(now, +new Date(year + 1, 0, 1));
|
|
64
|
+
return { year, start, end };
|
|
65
|
+
}
|
|
66
|
+
export const inWin = (w, ms) => ms >= w.start && ms < w.end;
|
|
67
|
+
|
|
68
|
+
export const basename = p => { const s = String(p || '').replace(/[\\/]+$/, ''); return s.split(/[\\/]/).pop() || null; };
|
|
69
|
+
|
|
70
|
+
/** active time: sum of gaps between sorted timestamps, only gaps <= idle */
|
|
71
|
+
export function activeMs(sorted, idle = 30 * 60e3) {
|
|
72
|
+
let a = 0; for (let i = 1; i < sorted.length; i++) { const g = sorted[i] - sorted[i - 1]; if (g <= idle) a += g; } return a;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** max distinct sessions with a prompt inside a sliding window (default 10 min) */
|
|
76
|
+
export function maxConcurrent(events, winMs = 10 * 60e3) {
|
|
77
|
+
const ev = events.filter(e => e[1]).sort((a, b) => a[0] - b[0]);
|
|
78
|
+
const live = new Map(); let j = 0, best = 0;
|
|
79
|
+
for (const [t, s] of ev) {
|
|
80
|
+
live.set(s, (live.get(s) || 0) + 1);
|
|
81
|
+
while (ev[j][0] < t - winMs) { const k = ev[j][1]; const n = live.get(k) - 1; if (n) live.set(k, n); else live.delete(k); j++; }
|
|
82
|
+
if (live.size > best) best = live.size;
|
|
83
|
+
}
|
|
84
|
+
return ev.length ? best : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** git commands that undo work, from a shell command string */
|
|
88
|
+
const UNDO = {
|
|
89
|
+
revert: /\bgit\s+(?:-C\s+\S+\s+)?revert\b/,
|
|
90
|
+
reset: /\bgit\s+(?:-C\s+\S+\s+)?reset\b[^;&|\n]*--hard/,
|
|
91
|
+
restore: /\bgit\s+(?:-C\s+\S+\s+)?restore\b/,
|
|
92
|
+
checkout: /\bgit\s+(?:-C\s+\S+\s+)?checkout\b[^;&|\n]*\s--(?:\s|$)/,
|
|
93
|
+
stash: /\bgit\s+(?:-C\s+\S+\s+)?stash\b(?!\s+(?:list|show))/,
|
|
94
|
+
};
|
|
95
|
+
export function gitUndoKinds(cmd) {
|
|
96
|
+
if (!cmd || cmd.indexOf('git') < 0) return null;
|
|
97
|
+
const out = []; for (const k in UNDO) if (UNDO[k].test(cmd)) out.push(k); return out.length ? out : null;
|
|
98
|
+
}
|
|
99
|
+
export const emptyUndos = () => ({ reset: 0, checkout: 0, stash: 0, restore: 0, revert: 0 });
|
|
100
|
+
|
|
101
|
+
/** assistant phrases (counted, never kept) */
|
|
102
|
+
const PHR = {
|
|
103
|
+
youreRight: /\byou(?:'re| are) (?:\w+ )?right\b/gi,
|
|
104
|
+
absolutelyRight: /\byou(?:'re| are) absolutely right\b/gi,
|
|
105
|
+
perfect: /\bperfect!/gi,
|
|
106
|
+
greatQuestion: /\bgreat question\b/gi,
|
|
107
|
+
};
|
|
108
|
+
export function phraseCounts(text) {
|
|
109
|
+
if (!text) return null;
|
|
110
|
+
const t = text.indexOf('’') >= 0 ? text.replace(/’/g, "'") : text;
|
|
111
|
+
let out = null;
|
|
112
|
+
for (const k in PHR) { const m = t.match(PHR[k]); if (m) (out ||= {})[k] = m.length; }
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
export const emptyAssistant = () => ({ youreRight: 0, absolutelyRight: 0, perfect: 0, greatQuestion: 0 });
|
|
116
|
+
export function addPhrases(acc, c) { if (c) for (const k in c) acc[k] += c[k]; }
|
|
117
|
+
|
|
118
|
+
/** cheap 52-bit string hash (FNV-1a variant), for de-dup keys without keeping text */
|
|
119
|
+
export function hash(s) {
|
|
120
|
+
let h1 = 0x811c9dc5, h2 = 0x01000193;
|
|
121
|
+
for (let i = 0; i < s.length; i++) { const c = s.charCodeAt(i); h1 = Math.imul(h1 ^ c, 16777619); h2 = Math.imul(h2 ^ c, 2246822519); }
|
|
122
|
+
return (h1 >>> 0).toString(36) + (h2 >>> 0).toString(36) + s.length.toString(36);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const inc = (o, k, by = 1) => { if (k != null) o[k] = (o[k] || 0) + by; };
|
|
126
|
+
export function topN(obj, n) { return Object.fromEntries(Object.entries(obj).sort((a, b) => b[1] - a[1]).slice(0, n)); }
|
|
127
|
+
|
|
128
|
+
/** model token bucket */
|
|
129
|
+
export const tokBucket = () => ({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0, byMonth: {}, estimated: false });
|
|
130
|
+
export function addTok(models, model, ms, i, o, cr, cw) {
|
|
131
|
+
const b = models[model] ||= tokBucket();
|
|
132
|
+
b.input += i; b.output += o; b.cacheRead += cr; b.cacheWrite += cw;
|
|
133
|
+
if (ms != null) inc(b.byMonth, localMonth(ms), i + o + cr + cw);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** new empty HarnessFacts */
|
|
137
|
+
export function emptyFacts(id, label) {
|
|
138
|
+
return {
|
|
139
|
+
harness: id, label, version: null,
|
|
140
|
+
coverage: { from: null, to: null, sources: [], notes: [] },
|
|
141
|
+
days: {}, hours: Array(24).fill(0), weekdays: Array(7).fill(0), months: Array(12).fill(0),
|
|
142
|
+
sessions: { count: 0, longest: null, mostResumed: null, maxConcurrent: null },
|
|
143
|
+
prompts: null, models: {}, tools: {}, toolCalls: 0, skills: {}, mcp: {}, slash: {}, projects: {},
|
|
144
|
+
subagents: null, interrupts: null, compactions: null, rateLimits: null, lines: null,
|
|
145
|
+
gitUndos: null, rewinds: null, assistant: null, theme: null,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function day(f, ds) { return f.days[ds] ||= { prompts: 0, sessions: 0, tokens: 0 }; }
|
|
149
|
+
|
|
150
|
+
/** count one prompt timestamp into hours / weekdays / months / days */
|
|
151
|
+
export function countPromptTime(f, ms) {
|
|
152
|
+
const d = new Date(ms);
|
|
153
|
+
f.hours[d.getHours()]++; f.weekdays[(d.getDay() + 6) % 7]++; f.months[d.getMonth()]++;
|
|
154
|
+
day(f, localDate(ms)).prompts++;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** set coverage from/to from the days map */
|
|
158
|
+
export function finishCoverage(f) {
|
|
159
|
+
const ds = Object.keys(f.days).sort();
|
|
160
|
+
f.coverage.from = ds[0] || null; f.coverage.to = ds[ds.length - 1] || null;
|
|
161
|
+
f.days = Object.fromEntries(ds.map(d => [d, f.days[d]]));
|
|
162
|
+
f.toolCalls = f.toolCalls || Object.values(f.tools).reduce((a, b) => a + b, 0);
|
|
163
|
+
return f;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** longest session from a Map sid -> {t: number[], project} */
|
|
167
|
+
export function longestSession(sessions) {
|
|
168
|
+
let best = null;
|
|
169
|
+
for (const [, s] of sessions) {
|
|
170
|
+
if (!s.t.length) continue;
|
|
171
|
+
const t = s.t.sort((a, b) => a - b); const act = activeMs(t);
|
|
172
|
+
if (!best || act > best.act) best = { act, wall: t[t.length - 1] - t[0], project: s.project ?? null, start: t[0] };
|
|
173
|
+
}
|
|
174
|
+
return best && { activeHours: +(best.act / 3.6e6).toFixed(2), wallHours: +(best.wall / 3.6e6).toFixed(2), project: best.project, start: new Date(best.start).toISOString() };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** most resumed: distinct local days with prompts per session */
|
|
178
|
+
export function mostResumed(promptsBySession) {
|
|
179
|
+
let best = null;
|
|
180
|
+
for (const [, s] of promptsBySession) if (!best || s.days.size > best.days) best = { days: s.days.size, project: s.project ?? null };
|
|
181
|
+
return best && best.days ? best : null;
|
|
182
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
2
|
+
const mod = await import(workerData.moduleUrl);
|
|
3
|
+
parentPort.on('message', async file => {
|
|
4
|
+
let r = null;
|
|
5
|
+
try { r = await mod[workerData.fn](file, workerData.ctx); } catch { r = null; }
|
|
6
|
+
parentPort.postMessage(r);
|
|
7
|
+
});
|