ccsniff 1.1.11 → 1.1.12

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 +58 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccsniff",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
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
@@ -30,7 +30,7 @@ const FLAGS = {
30
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'],
31
31
  multi: ['grep', 'igrep', 'role', 'type', 'tool', 'session', 'sid', 'project', 'cwd', 'exclude-sess', 'exclude-sid', 'exclude-cwd', 'exclude-project'],
32
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
+ 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', 'search-discipline', 'learning-xref', 'include-subagents', 'stats', 'count', 'help', 'h'],
34
34
  };
35
35
 
36
36
  function parseArgs(argv) {
@@ -66,6 +66,7 @@ USAGE
66
66
  ccsniff --bash-discipline [--stats] Bash calls that should have used Read/Glob/Grep
67
67
  ccsniff --learning-xref [--sess <id>] [--days N] join transcript turns to rs-learn recall/memorize
68
68
  ccsniff --git-discipline [--stats] git push from a dirty/unwitnessed tree
69
+ ccsniff --search-discipline [--stats] native search (Grep/Glob/Explore/find) instead of codesearch/recall
69
70
  (excludes subagents by default — --include-subagents to opt in;
70
71
  excludes 'echo > .gm/exec-spool/in/...' as canonical spool-write)
71
72
  ccsniff --stats [filters]
@@ -369,6 +370,62 @@ if (opts['git-discipline']) {
369
370
  process.exit(0);
370
371
  }
371
372
 
373
+ // ---------- search-discipline (flag native search that should have been codesearch/recall)
374
+ // A native-search bypass (Grep/Glob, the Explore/Task search subagent, or bash grep/rg/find/ag)
375
+ // emits NO plugkit deviation because it never touches the spool — it is invisible to gmsniff and
376
+ // the watcher ledger. ccsniff reads the tool-call stream directly, so it is the only surface that
377
+ // can catch the SKILL.md class-rule violation: code/file/symbol search routes through codesearch,
378
+ // prior-knowledge through recall, never a host-native search tool.
379
+ if (opts['search-discipline']) {
380
+ const includeSubagents = opts['include-subagents'];
381
+ const BASH_SEARCH = /(^|[|&;]|\s)(rg|grep|find|ag|ack|fd|fgrep|egrep)\s/;
382
+ const violations = [];
383
+ for (const ev of all) {
384
+ if (!filter(ev)) continue;
385
+ if (ev.block?.type !== 'tool_use') continue;
386
+ if (!includeSubagents && ev.conversation?.isSubagent) continue;
387
+ const name = ev.block?.name || '';
388
+ const project = path.basename(ev.conversation?.cwd || '');
389
+ const ts = ev.timestamp, sid = ev.conversation?.id || '';
390
+ let kind = null, detail = '';
391
+ if (name === 'Grep' || name === 'Glob') {
392
+ kind = `native-search-${name.toLowerCase()}`;
393
+ detail = (ev.block?.input?.pattern || ev.block?.input?.query || '').slice(0, 120);
394
+ } else if (name === 'Task' || name === 'Agent') {
395
+ const sub = (ev.block?.input?.subagent_type || ev.block?.input?.description || '').toLowerCase();
396
+ if (/explore|search|general-purpose/.test(sub)) {
397
+ kind = 'native-search-subagent';
398
+ detail = sub.slice(0, 120);
399
+ }
400
+ } else if (name === 'Bash') {
401
+ const cmd = ev.block?.input?.command || '';
402
+ if (BASH_SEARCH.test(cmd)) {
403
+ kind = 'native-search-bash';
404
+ // show the line that actually invokes the search tool, not line 1 (often a cd)
405
+ const hit = cmd.split('\n').find(l => BASH_SEARCH.test(l)) || cmd;
406
+ detail = hit.trim().slice(0, 120);
407
+ }
408
+ }
409
+ if (kind) violations.push({ ts, sid, project, kind, detail });
410
+ }
411
+ if (opts.stats || opts.count) {
412
+ if (opts.count) { process.stdout.write(`${violations.length}\n`); process.exit(0); }
413
+ process.stdout.write(`# ${violations.length} search-discipline violations (native search instead of codesearch/recall)\n`);
414
+ const byKind = new Map(), byProj = new Map();
415
+ for (const v of violations) { byKind.set(v.kind, (byKind.get(v.kind) || 0) + 1); byProj.set(v.project, (byProj.get(v.project) || 0) + 1); }
416
+ process.stdout.write(`# by kind\n`);
417
+ for (const [k, c] of [...byKind.entries()].sort((a, b) => b[1] - a[1])) process.stdout.write(` ${String(c).padStart(6)} ${k}\n`);
418
+ process.stdout.write(`# by project\n`);
419
+ for (const [p, c] of [...byProj.entries()].sort((a, b) => b[1] - a[1])) process.stdout.write(` ${String(c).padStart(6)} ${p}\n`);
420
+ process.exit(0);
421
+ }
422
+ for (const v of violations) {
423
+ process.stdout.write(`${new Date(v.ts).toISOString().slice(0, 19)} ${v.sid.slice(0, 8)} ${v.kind.padEnd(24)} [${v.project}] ${v.detail}\n`);
424
+ }
425
+ process.stderr.write(`# ${violations.length} violations — use codesearch (code/file/symbol) or recall (prior knowledge) instead\n`);
426
+ process.exit(0);
427
+ }
428
+
372
429
  // ---------- learning-xref (join transcript turns to gm-log rs_learn signals)
373
430
  if (opts['learning-xref']) {
374
431
  const days = opts.days || 1;