ccsniff 1.1.6 → 1.1.7
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/src/cli.js +84 -3
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { toUnslothMessages, toShareGPT } from './unsloth.js';
|
|
|
4
4
|
import { parseTime, compileRegexes, buildFilter } from './filters.js';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
|
+
import os from 'os';
|
|
7
8
|
|
|
8
9
|
if (process.argv[2] === 'gui') {
|
|
9
10
|
const { createServer } = await import('./gui-server.js');
|
|
@@ -26,10 +27,10 @@ if (process.argv[2] === 'gui') {
|
|
|
26
27
|
} else {
|
|
27
28
|
|
|
28
29
|
const FLAGS = {
|
|
29
|
-
string: ['since', 'until', 'before', 'after', 'grep', 'igrep', 'cwd', 'project', 'role', 'type', 'tool', 'session', 'sid', 'parent', 'rollup', 'format', 'sort', 'unsloth', 'unsloth-format', 'exclude-sess', 'exclude-sid', 'exclude-cwd', 'exclude-project'],
|
|
30
|
+
string: ['since', 'until', 'before', 'after', 'grep', 'igrep', 'cwd', 'project', 'role', 'type', 'tool', 'session', 'sid', 'sess', 'parent', 'rollup', 'format', 'sort', 'unsloth', 'unsloth-format', 'exclude-sess', 'exclude-sid', 'exclude-cwd', 'exclude-project'],
|
|
30
31
|
multi: ['grep', 'igrep', 'role', 'type', 'tool', 'session', 'sid', 'project', 'cwd', 'exclude-sess', 'exclude-sid', 'exclude-cwd', 'exclude-project'],
|
|
31
|
-
number: ['limit', 'head', 'tail-n', 'ctx', 'truncate'],
|
|
32
|
-
bool: ['json', 'ndjson', 'tail', 'f', 'full', 'reverse', 'invert', 'no-subagents', 'only-subagents', 'no-meta', 'only-meta', 'list-sessions', 'list-projects', 'list-tools', 'bash-discipline', 'git-discipline', 'include-subagents', 'stats', 'count', 'help', 'h'],
|
|
32
|
+
number: ['limit', 'head', 'tail-n', 'ctx', 'truncate', 'days'],
|
|
33
|
+
bool: ['json', 'ndjson', 'tail', 'f', 'full', 'reverse', 'invert', 'no-subagents', 'only-subagents', 'no-meta', 'only-meta', 'list-sessions', 'list-projects', 'list-tools', 'bash-discipline', 'git-discipline', 'learning-xref', 'include-subagents', 'stats', 'count', 'help', 'h'],
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
function parseArgs(argv) {
|
|
@@ -63,6 +64,7 @@ USAGE
|
|
|
63
64
|
ccsniff --list-projects
|
|
64
65
|
ccsniff --list-tools
|
|
65
66
|
ccsniff --bash-discipline [--stats] Bash calls that should have used Read/Glob/Grep
|
|
67
|
+
ccsniff --learning-xref [--sess <id>] [--days N] join transcript turns to rs-learn recall/memorize
|
|
66
68
|
ccsniff --git-discipline [--stats] git push from a dirty/unwitnessed tree
|
|
67
69
|
(excludes subagents by default — --include-subagents to opt in;
|
|
68
70
|
excludes 'echo > .gm/exec-spool/in/...' as canonical spool-write)
|
|
@@ -352,6 +354,85 @@ if (opts['git-discipline']) {
|
|
|
352
354
|
process.exit(0);
|
|
353
355
|
}
|
|
354
356
|
|
|
357
|
+
// ---------- learning-xref (join transcript turns to gm-log rs_learn signals)
|
|
358
|
+
if (opts['learning-xref']) {
|
|
359
|
+
const days = opts.days || 1;
|
|
360
|
+
const wantSess = opts.sess || null;
|
|
361
|
+
const bySid = new Map();
|
|
362
|
+
for (const ev of all) {
|
|
363
|
+
if (!filter(ev)) continue;
|
|
364
|
+
if (wantSess && !ev.conversation?.id?.startsWith(wantSess)) continue;
|
|
365
|
+
const sid = ev.conversation?.id;
|
|
366
|
+
if (!sid) continue;
|
|
367
|
+
if (!bySid.has(sid)) bySid.set(sid, { cwd: ev.conversation.cwd, evs: [] });
|
|
368
|
+
bySid.get(sid).evs.push(ev);
|
|
369
|
+
}
|
|
370
|
+
const dates = [];
|
|
371
|
+
const now = Date.now();
|
|
372
|
+
for (let i = 0; i < days; i++) {
|
|
373
|
+
dates.push(new Date(now - i * 86400000).toISOString().slice(0, 10));
|
|
374
|
+
}
|
|
375
|
+
const gmLogDir = path.join(os.homedir(), '.claude', 'gm-log');
|
|
376
|
+
const rsLearn = [], bootstrap = [];
|
|
377
|
+
for (const d of dates) {
|
|
378
|
+
for (const [file, sink] of [['rs_learn.jsonl', rsLearn], ['bootstrap.jsonl', bootstrap]]) {
|
|
379
|
+
const fp = path.join(gmLogDir, d, file);
|
|
380
|
+
if (!fs.existsSync(fp)) continue;
|
|
381
|
+
const lines = fs.readFileSync(fp, 'utf8').split('\n');
|
|
382
|
+
for (const ln of lines) {
|
|
383
|
+
if (!ln.trim()) continue;
|
|
384
|
+
try {
|
|
385
|
+
const j = JSON.parse(ln);
|
|
386
|
+
const ts = typeof j.ts === 'number' ? j.ts : Date.parse(j.ts);
|
|
387
|
+
if (Number.isFinite(ts)) { j._ts = ts; sink.push(j); }
|
|
388
|
+
} catch {}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
rsLearn.sort((a, b) => a._ts - b._ts);
|
|
393
|
+
let totals = { turns: 0, tool_uses: 0, memorize: 0, recall: 0, hit: 0, miss: 0, embed_fail: 0 };
|
|
394
|
+
let anyMatched = 0;
|
|
395
|
+
for (const [sid, info] of bySid) {
|
|
396
|
+
info.evs.sort((a, b) => a.timestamp - b.timestamp);
|
|
397
|
+
const project = path.basename(info.cwd || '');
|
|
398
|
+
const skillTs = info.evs
|
|
399
|
+
.filter(e => e.block?.type === 'tool_use' && e.block?.name === 'Skill' && e.block?.input?.skill === 'gm-skill')
|
|
400
|
+
.map(e => e.timestamp);
|
|
401
|
+
if (!skillTs.length) continue;
|
|
402
|
+
const sessFirst = info.evs[0].timestamp;
|
|
403
|
+
const sessLast = info.evs[info.evs.length - 1].timestamp;
|
|
404
|
+
const bounds = [...skillTs, sessLast + 1];
|
|
405
|
+
process.stdout.write(`# session ${sid.slice(0, 8)} [${project}] turns=${skillTs.length}\n`);
|
|
406
|
+
for (let i = 0; i < skillTs.length; i++) {
|
|
407
|
+
const winStart = bounds[i];
|
|
408
|
+
const winEnd = bounds[i + 1];
|
|
409
|
+
const toolUses = info.evs.filter(e => e.timestamp >= winStart && e.timestamp < winEnd && e.block?.type === 'tool_use').length;
|
|
410
|
+
const rsInWin = rsLearn.filter(j => j._ts >= winStart && j._ts < winEnd && (!j.project || j.project === project) && (!wantSess || !j.sess || j.sess === sid || sid.startsWith(j.sess)));
|
|
411
|
+
let memorize = 0, recall = 0, hit = 0, miss = 0, embed_fail = 0;
|
|
412
|
+
for (const j of rsInWin) {
|
|
413
|
+
if (j.event === 'memorize') memorize++;
|
|
414
|
+
else if (j.event === 'recall') { recall++; if (j.hit) hit++; else miss++; }
|
|
415
|
+
else if (j.event === 'embed_fail' || /embed.*fail/i.test(j.event || '')) embed_fail++;
|
|
416
|
+
}
|
|
417
|
+
anyMatched += rsInWin.length;
|
|
418
|
+
totals.turns++;
|
|
419
|
+
totals.tool_uses += toolUses;
|
|
420
|
+
totals.memorize += memorize;
|
|
421
|
+
totals.recall += recall;
|
|
422
|
+
totals.hit += hit;
|
|
423
|
+
totals.miss += miss;
|
|
424
|
+
totals.embed_fail += embed_fail;
|
|
425
|
+
const ts = new Date(winStart).toISOString().slice(0, 19).replace('T', ' ');
|
|
426
|
+
process.stdout.write(`${ts} | tool_uses=${toolUses} | memorize=${memorize} | recall=${recall} (hit=${hit} miss=${miss}) | embed_fail=${embed_fail}\n`);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (anyMatched === 0 && wantSess) {
|
|
430
|
+
process.stdout.write(`# no rs-learn events for sess ${wantSess} — confirm bootstrap fires gm-log writes\n`);
|
|
431
|
+
}
|
|
432
|
+
process.stderr.write(`# totals: sessions=${bySid.size} turns=${totals.turns} tool_uses=${totals.tool_uses} memorize=${totals.memorize} recall=${totals.recall} (hit=${totals.hit} miss=${totals.miss}) embed_fail=${totals.embed_fail} (scanned ${dates.length}d, rs_learn=${rsLearn.length} bootstrap=${bootstrap.length})\n`);
|
|
433
|
+
process.exit(0);
|
|
434
|
+
}
|
|
435
|
+
|
|
355
436
|
// ---------- list-tools
|
|
356
437
|
if (opts['list-tools']) {
|
|
357
438
|
const tools = new Map();
|