ccsniff 1.1.10 → 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.
- package/package.json +1 -1
- package/src/cli.js +58 -1
- package/src/index.js +11 -9
package/package.json
CHANGED
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;
|
package/src/index.js
CHANGED
|
@@ -124,17 +124,19 @@ export class JsonlWatcher extends EventEmitter {
|
|
|
124
124
|
this.emit('streaming_complete', { conversationId: conv.id, conversation: conv, seq: this._seq(sid), timestamp: Date.now() });
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
_push(conv, sid, block, role) {
|
|
128
|
-
|
|
127
|
+
_push(conv, sid, block, role, eventTs) {
|
|
128
|
+
const ts = eventTs != null ? eventTs : Date.now();
|
|
129
|
+
this.emit('streaming_progress', { conversationId: conv.id, conversation: conv, block, role, seq: this._seq(sid), timestamp: ts });
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
_route(conv, sid, e) {
|
|
132
133
|
if (e.type === 'queue-operation' || e.type === 'last-prompt') return;
|
|
134
|
+
const ets = e.timestamp ? Date.parse(e.timestamp) : null;
|
|
133
135
|
if (e.type === 'user' && e.isMeta) {
|
|
134
136
|
this._startStreaming(conv, sid);
|
|
135
137
|
const content = e.message?.content;
|
|
136
138
|
const text = typeof content === 'string' ? content : (Array.isArray(content) ? content.filter(b => b?.type === 'text').map(b => b.text).join('') : '');
|
|
137
|
-
if (text.trim()) this._push(conv, sid, { type: 'text', text, isMeta: true }, 'user');
|
|
139
|
+
if (text.trim()) this._push(conv, sid, { type: 'text', text, isMeta: true }, 'user', ets);
|
|
138
140
|
return;
|
|
139
141
|
}
|
|
140
142
|
|
|
@@ -147,7 +149,7 @@ export class JsonlWatcher extends EventEmitter {
|
|
|
147
149
|
if (e.subtype === 'init') { this._startStreaming(conv, sid); return; }
|
|
148
150
|
if (e.subtype === 'turn_duration' || e.subtype === 'stop_hook_summary') { this._endStreaming(conv, sid); return; }
|
|
149
151
|
this._startStreaming(conv, sid);
|
|
150
|
-
this._push(conv, sid, { type: 'system', subtype: e.subtype, model: e.model, cwd: e.cwd, tools: e.tools }, 'system');
|
|
152
|
+
this._push(conv, sid, { type: 'system', subtype: e.subtype, model: e.model, cwd: e.cwd, tools: e.tools }, 'system', ets);
|
|
151
153
|
return;
|
|
152
154
|
}
|
|
153
155
|
|
|
@@ -158,7 +160,7 @@ export class JsonlWatcher extends EventEmitter {
|
|
|
158
160
|
const newBlocks = e.message.content.slice(prev);
|
|
159
161
|
if (newBlocks.length > 0) {
|
|
160
162
|
this._emitted.set(key, e.message.content.length);
|
|
161
|
-
for (const b of newBlocks) if (b?.type) this._push(conv, sid, b, 'assistant');
|
|
163
|
+
for (const b of newBlocks) if (b?.type) this._push(conv, sid, b, 'assistant', ets);
|
|
162
164
|
}
|
|
163
165
|
if (e.message.stop_reason) this._emitted.delete(key);
|
|
164
166
|
return;
|
|
@@ -168,19 +170,19 @@ export class JsonlWatcher extends EventEmitter {
|
|
|
168
170
|
this._startStreaming(conv, sid);
|
|
169
171
|
const content = e.message.content;
|
|
170
172
|
if (typeof content === 'string') {
|
|
171
|
-
if (content.trim()) this._push(conv, sid, { type: 'text', text: content }, 'user');
|
|
173
|
+
if (content.trim()) this._push(conv, sid, { type: 'text', text: content }, 'user', ets);
|
|
172
174
|
} else if (Array.isArray(content)) {
|
|
173
175
|
for (const b of content) {
|
|
174
176
|
if (!b || !b.type) continue;
|
|
175
|
-
if (b.type === 'tool_result') this._push(conv, sid, b, 'tool_result');
|
|
176
|
-
else this._push(conv, sid, b, 'user');
|
|
177
|
+
if (b.type === 'tool_result') this._push(conv, sid, b, 'tool_result', ets);
|
|
178
|
+
else this._push(conv, sid, b, 'user', ets);
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
181
|
return;
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
if (e.type === 'result') {
|
|
183
|
-
this._push(conv, sid, { type: 'result', result: e.result, subtype: e.subtype, duration_ms: e.duration_ms, total_cost_usd: e.total_cost_usd, is_error: e.is_error || false }, 'result');
|
|
185
|
+
this._push(conv, sid, { type: 'result', result: e.result, subtype: e.subtype, duration_ms: e.duration_ms, total_cost_usd: e.total_cost_usd, is_error: e.is_error || false }, 'result', ets);
|
|
184
186
|
this._endStreaming(conv, sid);
|
|
185
187
|
}
|
|
186
188
|
}
|