ccsniff 1.1.5 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +127 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccsniff",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Watch Claude Code JSONL output files and emit structured events as a Node.js EventEmitter",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
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', '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,8 @@ 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
68
+ ccsniff --git-discipline [--stats] git push from a dirty/unwitnessed tree
66
69
  (excludes subagents by default — --include-subagents to opt in;
67
70
  excludes 'echo > .gm/exec-spool/in/...' as canonical spool-write)
68
71
  ccsniff --stats [filters]
@@ -309,6 +312,127 @@ if (opts['bash-discipline']) {
309
312
  process.exit(0);
310
313
  }
311
314
 
315
+ if (opts['git-discipline']) {
316
+ const includeSubagents = opts['include-subagents'];
317
+ const PUSH = /\bgit\s+push\b/;
318
+ const PORCELAIN_CLEAN = /\bgit\s+status\s+(--porcelain|-s)\b/;
319
+ const bySid = new Map();
320
+ for (const ev of all) {
321
+ if (!filter(ev)) continue;
322
+ if (ev.block?.type !== 'tool_use' || ev.block?.name !== 'Bash') continue;
323
+ if (!includeSubagents && ev.conversation?.isSubagent) continue;
324
+ const sid = ev.conversation.id;
325
+ if (!bySid.has(sid)) bySid.set(sid, []);
326
+ bySid.get(sid).push(ev);
327
+ }
328
+ const violations = [];
329
+ for (const [sid, evs] of bySid) {
330
+ evs.sort((a, b) => a.timestamp - b.timestamp);
331
+ for (let i = 0; i < evs.length; i++) {
332
+ const ev = evs[i];
333
+ const cmd = ev.block?.input?.command || '';
334
+ if (!PUSH.test(cmd)) continue;
335
+ const lookback = evs.slice(Math.max(0, i - 20), i);
336
+ const witnessed = lookback.some(e => PORCELAIN_CLEAN.test(e.block?.input?.command || ''));
337
+ if (witnessed) continue;
338
+ violations.push({ ts: ev.timestamp, sid, project: path.basename(ev.conversation.cwd || ''), kind: 'push-no-porcelain-witness', cmd: cmd.slice(0, 200) });
339
+ }
340
+ }
341
+ if (opts.stats || opts.count) {
342
+ if (opts.count) { process.stdout.write(`${violations.length}\n`); process.exit(0); }
343
+ process.stdout.write(`# ${violations.length} git-discipline violations\n`);
344
+ const byProj = new Map();
345
+ for (const v of violations) byProj.set(v.project, (byProj.get(v.project) || 0) + 1);
346
+ process.stdout.write(`# by project\n`);
347
+ for (const [p, c] of [...byProj.entries()].sort((a, b) => b[1] - a[1])) process.stdout.write(` ${String(c).padStart(6)} ${p}\n`);
348
+ process.exit(0);
349
+ }
350
+ for (const v of violations) {
351
+ process.stdout.write(`${new Date(v.ts).toISOString().slice(0, 19)} ${v.sid.slice(0, 8)} ${v.kind.padEnd(28)} [${v.project}] ${v.cmd}\n`);
352
+ }
353
+ process.stderr.write(`# ${violations.length} violations (push-no-porcelain-witness)\n`);
354
+ process.exit(0);
355
+ }
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
+
312
436
  // ---------- list-tools
313
437
  if (opts['list-tools']) {
314
438
  const tools = new Map();