slopcard 1.0.0 → 1.1.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/package.json +1 -1
- package/slopcard.mjs +50 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slopcard",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Proof of slop. A badge for sites built with AI agents: the prompts, agent hours and days behind the site, counted from Claude Code and Codex logs.",
|
|
5
5
|
"keywords": ["claude-code", "codex", "ai", "badge", "vibe-coding"],
|
|
6
6
|
"homepage": "https://taylor.fyi/slopcard",
|
package/slopcard.mjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Slopcard: count the work behind a site from your coding agents' own logs. Proof of slop.
|
|
3
3
|
//
|
|
4
|
-
// npx slopcard
|
|
5
|
-
// npx slopcard submit
|
|
4
|
+
// npx slopcard count this repo's agent work
|
|
5
|
+
// npx slopcard submit count, show what will be sent, send it, print the badge
|
|
6
6
|
// npx slopcard badge print the badge snippet again
|
|
7
7
|
//
|
|
8
|
+
// The first send writes slopcard.json in the repo: the site's address and card, no counts. Commit it. Later sends (the
|
|
9
|
+
// git hook's) read it and leave it as it is.
|
|
10
|
+
//
|
|
8
11
|
// Reads Claude Code logs (~/.claude/projects) and Codex logs (~/.codex/sessions) on this machine.
|
|
9
12
|
// Keeps counts only. No prompt text, file names or code ever leave this machine.
|
|
10
13
|
// Claude Code deletes old logs, so every run banks per-session counts in ~/.slopcard first.
|
|
@@ -389,19 +392,34 @@ function summarize(bank, root) {
|
|
|
389
392
|
|
|
390
393
|
const fmt = (n) => n >= 1e9 ? (n / 1e9).toFixed(1) + 'B' : n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e3 ? Math.round(n / 1e3) + 'K' : String(n);
|
|
391
394
|
|
|
395
|
+
// ---------- slopcard.json: the site's settings ----------
|
|
396
|
+
// The address, name and card, and any --also folders, kept in the site's folder so later sends (the git hook's) need no
|
|
397
|
+
// flags. No counts: those live on the card and in ~/.slopcard. So the file changes only when a setting does, and a send
|
|
398
|
+
// leaves the repo exactly as it was.
|
|
399
|
+
const SITE_KEYS = ['url', 'name', 'slug', 'page', 'badge'];
|
|
400
|
+
|
|
401
|
+
function readSettings(file) {
|
|
402
|
+
const f = readJSON(file, null) || {};
|
|
403
|
+
// (1.0 wrote the counts here too, with the settings under "site")
|
|
404
|
+
const s = f.site || (f.slug ? f : null);
|
|
405
|
+
return { site: s && Object.fromEntries(SITE_KEYS.map((k) => [k, s[k]])), also: Array.isArray(f.also) ? f.also : [] };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function saveSettings(file, { site, also }) {
|
|
409
|
+
const now = readSettings(file);
|
|
410
|
+
// compared as values, not text, so a file someone's formatter re-indented stays as it is
|
|
411
|
+
if (JSON.stringify(now.site) === JSON.stringify(site) && JSON.stringify(now.also) === JSON.stringify(also)) return;
|
|
412
|
+
writeJSON(file, { slopcard: 2, ...site, ...(also.length ? { also } : {}) });
|
|
413
|
+
}
|
|
414
|
+
|
|
392
415
|
async function measure(root, opts = {}) {
|
|
393
416
|
if (!opts.quiet) process.stderr.write(`${NAME}: reading your agent logs for ${path.basename(root)}...\n`);
|
|
394
417
|
const bank = await scan(root, opts);
|
|
395
418
|
const r = summarize(bank, root);
|
|
396
|
-
const file = arg('out') ? path.resolve(arg('out')) : path.join(root, 'slopcard.json');
|
|
397
|
-
const prev = readJSON(file, {});
|
|
398
|
-
if (prev.site) r.site = prev.site;
|
|
399
|
-
if (ALSO.length) r.also = ALSO;
|
|
400
|
-
writeJSON(file, r);
|
|
401
419
|
if (!opts.quiet && !r.days) console.log(`No Claude Code or Codex work found for ${path.basename(root)} in this computer's logs.`);
|
|
402
420
|
else if (!opts.quiet) {
|
|
403
421
|
console.log(`${r.prompts} prompt${r.prompts === 1 ? '' : 's'} · ${r.hours} agent hours · ${r.days} day${r.days === 1 ? '' : 's'} · ${fmt(r.tokens_written)} tokens written`);
|
|
404
|
-
console.log(`${r.first ?? '-'} to ${r.last ?? '-'} · ${r.sessions} session${r.sessions === 1 ? '' : 's'}
|
|
422
|
+
console.log(`${r.first ?? '-'} to ${r.last ?? '-'} · ${r.sessions} session${r.sessions === 1 ? '' : 's'}`);
|
|
405
423
|
}
|
|
406
424
|
return r;
|
|
407
425
|
}
|
|
@@ -439,12 +457,12 @@ async function submit(root) {
|
|
|
439
457
|
console.error(`\nNo agent work found for ${path.basename(root)}, so there's nothing to send. Run this in the folder the site was built in.`);
|
|
440
458
|
process.exit(1);
|
|
441
459
|
}
|
|
442
|
-
const
|
|
443
|
-
const url = normalizeUrl(arg('url') ||
|
|
460
|
+
const saved = SETTINGS.site;
|
|
461
|
+
const url = normalizeUrl(arg('url') || saved?.url);
|
|
444
462
|
if (!url) { console.error('\nAdd the site\'s address: npx slopcard submit --url https://yoursite.com'); process.exit(1); }
|
|
445
|
-
const name = (arg('name') ||
|
|
463
|
+
const name = (arg('name') || (saved?.url === url && saved.name) || new URL(url).hostname.replace(/^www\./, '')).slice(0, 60);
|
|
446
464
|
const keys = readJSON(path.join(STORE, 'keys.json'), {});
|
|
447
|
-
if (
|
|
465
|
+
if (saved?.slug && saved.url === url && !keys[url]) {
|
|
448
466
|
// made on another computer: its key lives there, so don't start a second slopcard for the same site
|
|
449
467
|
console.error(`\n${url} already has a slopcard, made on another computer. Send updates from that one.`);
|
|
450
468
|
process.exit(1);
|
|
@@ -468,17 +486,24 @@ async function submit(root) {
|
|
|
468
486
|
const body = await res.json().catch(() => ({}));
|
|
469
487
|
if (!res.ok) { console.error(`\nNot sent: ${body.error || res.status}`); process.exit(1); }
|
|
470
488
|
if (body.key) { keys[url] = body.key; writeJSON(path.join(STORE, 'keys.json'), keys, 0o600); }
|
|
471
|
-
|
|
472
|
-
|
|
489
|
+
const site = { url, name, slug: body.slug, page: body.page, badge: body.badge };
|
|
490
|
+
saveSettings(FILE, { site, also: ALSO });
|
|
473
491
|
console.log(`\nSent. Slopcard: ${body.page}`);
|
|
474
492
|
console.log(body.listed ? `Listed at ${BASE}/directory.` : `It joins the directory at ${BASE}/directory by itself the first time the badge loads on ${url}.`);
|
|
475
|
-
printBadge(r);
|
|
493
|
+
printBadge(site, r);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// the badge again, any time: the numbers for its alt text come from the card itself
|
|
497
|
+
async function badge() {
|
|
498
|
+
const s = SETTINGS.site;
|
|
499
|
+
if (!s || !s.slug) { console.error('Send it first: npx slopcard submit --url https://yoursite.com'); process.exit(1); }
|
|
500
|
+
let r = null;
|
|
501
|
+
try { const res = await fetch(`${BASE}/api/r/${encodeURIComponent(s.slug)}`); if (res.ok) r = await res.json(); } catch { /* offline: plain alt text */ }
|
|
502
|
+
printBadge(s, r);
|
|
476
503
|
}
|
|
477
504
|
|
|
478
|
-
function printBadge(r) {
|
|
479
|
-
const
|
|
480
|
-
if (!s || !s.slug) { console.error('Submit first: npx slopcard submit --url https://yoursite.com'); process.exit(1); }
|
|
481
|
-
const alt = `Slopcard: ${r.prompts} prompt${r.prompts === 1 ? '' : 's'}, ${r.days} day${r.days === 1 ? '' : 's'}`;
|
|
505
|
+
function printBadge(s, r) {
|
|
506
|
+
const alt = r && r.days ? `Slopcard: ${r.prompts} prompt${r.prompts === 1 ? '' : 's'}, ${r.days} day${r.days === 1 ? '' : 's'}` : 'Slopcard';
|
|
482
507
|
console.log('\nPut this where the site has room, usually the footer. The badge opens the slopcard in a modal:\n');
|
|
483
508
|
console.log(`<a href="${s.page}"><img src="${s.badge}" alt="${alt}" height="24"></a>`);
|
|
484
509
|
console.log(`<script async src="${BASE}/embed.js"></script>`);
|
|
@@ -493,10 +518,12 @@ try {
|
|
|
493
518
|
} catch { /* read-only home, or run from a URL: the counts don't need the copy */ }
|
|
494
519
|
const cmd = process.argv[2] && !process.argv[2].startsWith('--') ? process.argv[2] : 'measure';
|
|
495
520
|
const root = arg('repo') ? path.resolve(arg('repo')) : repoRoot();
|
|
496
|
-
|
|
497
|
-
const
|
|
498
|
-
|
|
521
|
+
const FILE = arg('out') ? path.resolve(arg('out')) : path.join(root, 'slopcard.json');
|
|
522
|
+
const SETTINGS = readSettings(FILE);
|
|
523
|
+
// --also is kept in slopcard.json, so a later plain `submit --yes` (the git hook) counts the same folders
|
|
524
|
+
const ALSO = (arg('also') ?? SETTINGS.also.join(',')).split(',').map((x) => x.trim()).filter(Boolean);
|
|
525
|
+
if (arg('also') !== undefined) saveSettings(FILE, { site: SETTINGS.site, also: ALSO });
|
|
499
526
|
if (cmd === 'measure') await measure(root);
|
|
500
527
|
else if (cmd === 'submit') await submit(root);
|
|
501
|
-
else if (cmd === 'badge')
|
|
528
|
+
else if (cmd === 'badge') await badge();
|
|
502
529
|
else { console.error(`Unknown command: ${cmd}. Try: measure, submit, badge`); process.exit(1); }
|