crossexamdev 0.2.0 → 0.3.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/README.md +7 -2
- package/bin/crossexam.js +88 -4
- package/package.json +1 -1
- package/src/claims.js +138 -120
- package/src/github.js +93 -69
- package/src/mcp.js +198 -109
- package/src/mutate.js +443 -0
- package/src/report.js +194 -99
- package/src/sandbox.js +627 -0
- package/src/strength.js +628 -0
package/src/report.js
CHANGED
|
@@ -1,99 +1,194 @@
|
|
|
1
|
-
// Aggregate claims into a reliability report and print it for humans.
|
|
2
|
-
|
|
3
|
-
export const VERDICTS = ['verified', 'contradicted', 'stale', 'unbacked', 'review'];
|
|
4
|
-
|
|
5
|
-
export function buildReport(claims, meta = {}) {
|
|
6
|
-
const tally = (key) => {
|
|
7
|
-
const m = {};
|
|
8
|
-
for (const c of claims) {
|
|
9
|
-
const k = typeof key === 'function' ? key(c) : c[key];
|
|
10
|
-
m[k] ??= { claims: 0, verified: 0, contradicted: 0, stale: 0, unbacked: 0, review: 0 };
|
|
11
|
-
m[k].claims++;
|
|
12
|
-
m[k][c.verdict]++;
|
|
13
|
-
}
|
|
14
|
-
for (const v of Object.values(m)) Object.assign(v, rates(v));
|
|
15
|
-
return m;
|
|
16
|
-
};
|
|
17
|
-
const totals = tally(() => 'all').all ?? { claims: 0, ...rates({}) };
|
|
18
|
-
return {
|
|
19
|
-
version: 1,
|
|
20
|
-
generatedAt: new Date().toISOString(),
|
|
21
|
-
...meta,
|
|
22
|
-
totals,
|
|
23
|
-
byAgent: tally('agent'),
|
|
24
|
-
byModel: tally('model'),
|
|
25
|
-
byRepo: tally('repo'),
|
|
26
|
-
byKind: tally('kind'),
|
|
27
|
-
byTaskType: tally('taskType'),
|
|
28
|
-
matrix: tally((c) => `${c.agent}|${c.kind}`),
|
|
29
|
-
claims: claims.sort((a, b) => String(b.at).localeCompare(String(a.at))),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function rates(v) {
|
|
34
|
-
const checked = (v.verified || 0) + (v.contradicted || 0) + (v.stale || 0);
|
|
35
|
-
const settled = checked + (v.unbacked || 0);
|
|
36
|
-
return {
|
|
37
|
-
// Of claims that had a check behind them, how many were false or out of date.
|
|
38
|
-
falseDoneRate: checked ? round(((v.contradicted || 0) + (v.stale || 0)) / checked) : 0,
|
|
39
|
-
// Of all settled claims, how many were backed by a passing check.
|
|
40
|
-
trustRate: settled ? round((v.verified || 0) / settled) : 0,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const round = (n) => Math.round(n * 1000) / 1000;
|
|
45
|
-
|
|
46
|
-
// ---------- terminal output ----------
|
|
47
|
-
|
|
48
|
-
const tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
49
|
-
const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
50
|
-
export const c = { dim: paint('2'), bold: paint('1'), red: paint('31'), green: paint('32'), yellow: paint('33'), blue: paint('34'), gray: paint('90') };
|
|
51
|
-
|
|
52
|
-
const MARK = { verified: c.green('✓ verified'), contradicted: c.red('✗ contradicted'), stale: c.yellow('◷ stale'), unbacked: c.gray('○ unbacked'), review: c.blue('◇ review') };
|
|
53
|
-
|
|
54
|
-
export function printReport(r, { limit = 8 } = {}) {
|
|
55
|
-
const t = r.totals;
|
|
56
|
-
const line = (s = '') => process.stdout.write(s + '\n');
|
|
57
|
-
line();
|
|
58
|
-
line(` ${c.bold('crossexam')} ${c.dim('· cross-examined ' + r.sessions + ' sessions, ' + r.turns + ' turns')}`);
|
|
59
|
-
line();
|
|
60
|
-
if (!t.claims) {
|
|
61
|
-
line(c.dim(' No completion claims found. Agents that never say "done" are hard to catch lying.'));
|
|
62
|
-
line();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
line(` ${pad(t.claims, 5)} claims ${c.green(pad(t.verified, 4))} verified ${c.red(pad(t.contradicted, 4))} contradicted ${c.yellow(pad(t.stale, 4))} stale ${c.gray(pad(t.unbacked, 4))} unbacked ${c.blue(pad(t.review, 4))} review`);
|
|
66
|
-
line();
|
|
67
|
-
line(` ${c.bold(pct(t.falseDoneRate))} of checked claims were false or stale ${c.dim('(contradicted + stale) / (verified + contradicted + stale)')}`);
|
|
68
|
-
if (r.ranCheckTurns) line(` ${c.bold(r.contradictedTurns + ' of ' + r.ranCheckTurns)} turns that ran a check ended with a contradicted claim ${c.dim('(' + pct(r.contradictedTurns / r.ranCheckTurns) + ')')}`);
|
|
69
|
-
line();
|
|
70
|
-
|
|
71
|
-
const table = (title, m) => {
|
|
72
|
-
const rows = Object.entries(m).sort((a, b) => b[1].claims - a[1].claims).slice(0, 6);
|
|
73
|
-
if (!rows.length) return;
|
|
74
|
-
line(c.dim(` ${title.padEnd(26)} claims trust false-done`));
|
|
75
|
-
for (const [k, v] of rows) line(` ${k.slice(0, 26).padEnd(26)} ${pad(v.claims, 6)} ${pad(pct(v.trustRate), 5)} ${v.falseDoneRate > 0.1 ? c.red(pad(pct(v.falseDoneRate), 5)) : pad(pct(v.falseDoneRate), 5)}`);
|
|
76
|
-
line();
|
|
77
|
-
};
|
|
78
|
-
table('by agent', r.byAgent);
|
|
79
|
-
table('by model', r.byModel);
|
|
80
|
-
table('by claim', r.byKind);
|
|
81
|
-
table('by repo', r.byRepo);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
line(c.bold('
|
|
86
|
-
line();
|
|
87
|
-
for (const
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
// Aggregate claims into a reliability report and print it for humans.
|
|
2
|
+
|
|
3
|
+
export const VERDICTS = ['verified', 'contradicted', 'stale', 'unbacked', 'review'];
|
|
4
|
+
|
|
5
|
+
export function buildReport(claims, meta = {}) {
|
|
6
|
+
const tally = (key) => {
|
|
7
|
+
const m = {};
|
|
8
|
+
for (const c of claims) {
|
|
9
|
+
const k = typeof key === 'function' ? key(c) : c[key];
|
|
10
|
+
m[k] ??= { claims: 0, verified: 0, contradicted: 0, stale: 0, unbacked: 0, review: 0 };
|
|
11
|
+
m[k].claims++;
|
|
12
|
+
m[k][c.verdict]++;
|
|
13
|
+
}
|
|
14
|
+
for (const v of Object.values(m)) Object.assign(v, rates(v));
|
|
15
|
+
return m;
|
|
16
|
+
};
|
|
17
|
+
const totals = tally(() => 'all').all ?? { claims: 0, ...rates({}) };
|
|
18
|
+
return {
|
|
19
|
+
version: 1,
|
|
20
|
+
generatedAt: new Date().toISOString(),
|
|
21
|
+
...meta,
|
|
22
|
+
totals,
|
|
23
|
+
byAgent: tally('agent'),
|
|
24
|
+
byModel: tally('model'),
|
|
25
|
+
byRepo: tally('repo'),
|
|
26
|
+
byKind: tally('kind'),
|
|
27
|
+
byTaskType: tally('taskType'),
|
|
28
|
+
matrix: tally((c) => `${c.agent}|${c.kind}`),
|
|
29
|
+
claims: claims.sort((a, b) => String(b.at).localeCompare(String(a.at))),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function rates(v) {
|
|
34
|
+
const checked = (v.verified || 0) + (v.contradicted || 0) + (v.stale || 0);
|
|
35
|
+
const settled = checked + (v.unbacked || 0);
|
|
36
|
+
return {
|
|
37
|
+
// Of claims that had a check behind them, how many were false or out of date.
|
|
38
|
+
falseDoneRate: checked ? round(((v.contradicted || 0) + (v.stale || 0)) / checked) : 0,
|
|
39
|
+
// Of all settled claims, how many were backed by a passing check.
|
|
40
|
+
trustRate: settled ? round((v.verified || 0) / settled) : 0,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const round = (n) => Math.round(n * 1000) / 1000;
|
|
45
|
+
|
|
46
|
+
// ---------- terminal output ----------
|
|
47
|
+
|
|
48
|
+
const tty = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
49
|
+
const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
50
|
+
export const c = { dim: paint('2'), bold: paint('1'), red: paint('31'), green: paint('32'), yellow: paint('33'), blue: paint('34'), gray: paint('90') };
|
|
51
|
+
|
|
52
|
+
const MARK = { verified: c.green('✓ verified'), contradicted: c.red('✗ contradicted'), stale: c.yellow('◷ stale'), unbacked: c.gray('○ unbacked'), review: c.blue('◇ review') };
|
|
53
|
+
|
|
54
|
+
export function printReport(r, { limit = 8 } = {}) {
|
|
55
|
+
const t = r.totals;
|
|
56
|
+
const line = (s = '') => process.stdout.write(s + '\n');
|
|
57
|
+
line();
|
|
58
|
+
line(` ${c.bold('crossexam')} ${c.dim('· cross-examined ' + r.sessions + ' sessions, ' + r.turns + ' turns')}`);
|
|
59
|
+
line();
|
|
60
|
+
if (!t.claims) {
|
|
61
|
+
line(c.dim(' No completion claims found. Agents that never say "done" are hard to catch lying.'));
|
|
62
|
+
line();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
line(` ${pad(t.claims, 5)} claims ${c.green(pad(t.verified, 4))} verified ${c.red(pad(t.contradicted, 4))} contradicted ${c.yellow(pad(t.stale, 4))} stale ${c.gray(pad(t.unbacked, 4))} unbacked ${c.blue(pad(t.review, 4))} review`);
|
|
66
|
+
line();
|
|
67
|
+
line(` ${c.bold(pct(t.falseDoneRate))} of checked claims were false or stale ${c.dim('(contradicted + stale) / (verified + contradicted + stale)')}`);
|
|
68
|
+
if (r.ranCheckTurns) line(` ${c.bold(r.contradictedTurns + ' of ' + r.ranCheckTurns)} turns that ran a check ended with a contradicted claim ${c.dim('(' + pct(r.contradictedTurns / r.ranCheckTurns) + ')')}`);
|
|
69
|
+
line();
|
|
70
|
+
|
|
71
|
+
const table = (title, m) => {
|
|
72
|
+
const rows = Object.entries(m).sort((a, b) => b[1].claims - a[1].claims).slice(0, 6);
|
|
73
|
+
if (!rows.length) return;
|
|
74
|
+
line(c.dim(` ${title.padEnd(26)} claims trust false-done`));
|
|
75
|
+
for (const [k, v] of rows) line(` ${k.slice(0, 26).padEnd(26)} ${pad(v.claims, 6)} ${pad(pct(v.trustRate), 5)} ${v.falseDoneRate > 0.1 ? c.red(pad(pct(v.falseDoneRate), 5)) : pad(pct(v.falseDoneRate), 5)}`);
|
|
76
|
+
line();
|
|
77
|
+
};
|
|
78
|
+
table('by agent', r.byAgent);
|
|
79
|
+
table('by model', r.byModel);
|
|
80
|
+
table('by claim', r.byKind);
|
|
81
|
+
table('by repo', r.byRepo);
|
|
82
|
+
|
|
83
|
+
if (r.mutation) {
|
|
84
|
+
const m = r.mutation;
|
|
85
|
+
line(` ${c.bold('Test strength')} ${c.dim(`· ${m.runs} mutation run${m.runs === 1 ? '' : 's'}, ${pct(m.score)} of ${m.killed + m.survived} planted defects caught · separate from the verdicts above`)}`);
|
|
86
|
+
line(c.dim(` ${'by agent'.padEnd(26)} runs caught weak runs`));
|
|
87
|
+
for (const [k, v] of Object.entries(m.byAgent).sort((a, b) => b[1].runs - a[1].runs).slice(0, 6)) {
|
|
88
|
+
line(` ${k.slice(0, 26).padEnd(26)} ${pad(v.runs, 4)} ${(v.score < 0.6 ? c.red : v.score < 0.8 ? c.yellow : c.green)(pad(pct(v.score), 5))} ${pad(v.weakRuns, 4)}`);
|
|
89
|
+
}
|
|
90
|
+
line();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const bad = r.claims.filter((x) => x.verdict === 'contradicted' || x.verdict === 'stale').slice(0, limit);
|
|
94
|
+
if (bad.length) {
|
|
95
|
+
line(c.bold(' Most recent false "done"s'));
|
|
96
|
+
line();
|
|
97
|
+
for (const x of bad) printClaim(x, line);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function printClaim(x, line = (s = '') => process.stdout.write(s + '\n')) {
|
|
102
|
+
line(` ${MARK[x.verdict]} ${c.dim(x.repo + ' · ' + x.agent + ' · ' + (x.at || '').slice(0, 10))}`);
|
|
103
|
+
line(` “${x.claim.length > 140 ? x.claim.slice(0, 137) + '…' : x.claim}”`);
|
|
104
|
+
line(` ${c.dim('→ ' + x.reason)}`);
|
|
105
|
+
line();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const pad = (v, n) => String(v).padStart(n);
|
|
109
|
+
const pct = (n) => `${(n * 100).toFixed(n && n < 0.1 ? 1 : 0)}%`;
|
|
110
|
+
|
|
111
|
+
// ---------- test strength ----------
|
|
112
|
+
|
|
113
|
+
const RATING = { strong: c.green('strong'), moderate: c.yellow('moderate'), weak: c.red('weak'), inconclusive: c.gray('inconclusive') };
|
|
114
|
+
const SHORT = { MUTATION_KILLED: c.green('killed'), MUTATION_SURVIVED: c.red('survived'), MUTATION_INVALID: c.gray('invalid'), MUTATION_UNRESOLVED: c.yellow('unresolved') };
|
|
115
|
+
|
|
116
|
+
export function printStrength(r, { line = (s = '') => process.stdout.write(s + '\n'), limit = 8 } = {}) {
|
|
117
|
+
const s = r.summary;
|
|
118
|
+
const secs = (ms) => `${(ms / 1000).toFixed(1)}s`;
|
|
119
|
+
line();
|
|
120
|
+
const iso = r.isolation || {};
|
|
121
|
+
const isoLabel = !iso.method ? c.yellow('not run: no sandbox') : iso.sandboxed ? c.green(`sandboxed (${iso.method})`) : c.red(c.bold('NOT SANDBOXED'));
|
|
122
|
+
line(` ${c.bold('crossexam')} ${c.dim('· test strength · ' + r.repo + ' · ' + r.scope + ' · ')}${isoLabel}`);
|
|
123
|
+
line();
|
|
124
|
+
if (r.headline) {
|
|
125
|
+
const tone = r.headline.tone === 'good' ? c.green : r.headline.tone === 'warn' ? c.red : c.dim;
|
|
126
|
+
line(` ${RATING[r.rating]}${s.score != null ? c.dim(` · mutation score ${Math.round(s.score * 100)}%`) : ''}`);
|
|
127
|
+
line(` ${tone(r.headline.text)}`);
|
|
128
|
+
line();
|
|
129
|
+
}
|
|
130
|
+
if (s.attempted) {
|
|
131
|
+
line(` ${pad(s.attempted, 3)} attempted ${pad(s.valid, 3)} valid ${c.green(pad(s.killed, 3))} killed ${c.red(pad(s.survived, 3))} survived ${c.gray(pad(s.invalid, 3))} invalid ${c.yellow(pad(s.unresolved, 3))} unresolved`);
|
|
132
|
+
line(c.dim(` ${secs(s.ms)} total${r.baseline ? ` · baseline ${secs(r.baseline.ms)}` : ''}${s.cachedResults ? ` · ${s.cachedResults} from cache` : ''} · ${r.testCommand}`));
|
|
133
|
+
line();
|
|
134
|
+
}
|
|
135
|
+
const fns = r.functions.filter((f) => f.killed + f.survived);
|
|
136
|
+
if (fns.length) {
|
|
137
|
+
line(c.dim(' function file caught'));
|
|
138
|
+
for (const f of fns.slice(0, 10)) {
|
|
139
|
+
const total = f.killed + f.survived;
|
|
140
|
+
const bar = c.green('█'.repeat(f.killed)) + c.red('█'.repeat(f.survived));
|
|
141
|
+
line(` ${(f.name || '(top level)').slice(0, 32).padEnd(32)} ${`${f.file}:${f.line}`.slice(-28).padEnd(28)} ${pad(f.killed + '/' + total, 5)} ${bar}`);
|
|
142
|
+
}
|
|
143
|
+
line();
|
|
144
|
+
}
|
|
145
|
+
const surv = r.mutants.filter((m) => m.status === 'MUTATION_SURVIVED');
|
|
146
|
+
if (surv.length) {
|
|
147
|
+
line(c.bold(' Defects the tests did not notice'));
|
|
148
|
+
line();
|
|
149
|
+
for (const m of surv.slice(0, limit)) {
|
|
150
|
+
line(` ${SHORT[m.status]} ${m.file}:${m.line} ${c.dim((m.function || 'top level') + ' · ' + m.operator)}`);
|
|
151
|
+
if (m.before != null) line(c.dim(` - ${m.before.split('\n')[0].slice(0, 110)}`));
|
|
152
|
+
if (m.after != null) line(` ${c.red('+ ' + m.after.split('\n')[0].slice(0, 110))}`);
|
|
153
|
+
line(` ${c.dim('→ ' + m.why)}`);
|
|
154
|
+
line();
|
|
155
|
+
}
|
|
156
|
+
if (surv.length > limit) line(c.dim(` …and ${surv.length - limit} more (--json for all)\n`));
|
|
157
|
+
}
|
|
158
|
+
const tests = r.associatedTests.map((t) => t.file);
|
|
159
|
+
if (r.files.length) line(c.dim(` Tests that touch the changed code: ${tests.length ? tests.slice(0, 6).join(', ') + (tests.length > 6 ? ` +${tests.length - 6}` : '') : 'none found'}`));
|
|
160
|
+
if (r.skippedFiles.length) line(c.dim(` Not mutated: ${r.skippedFiles.slice(0, 5).map((f) => `${f.file} (${f.reason})`).join(', ')}${r.skippedFiles.length > 5 ? ` +${r.skippedFiles.length - 5}` : ''}`));
|
|
161
|
+
for (const n of r.notes) if (n !== r.headline?.text) line(c.dim(` ${n}`));
|
|
162
|
+
line();
|
|
163
|
+
printExecution(r, line);
|
|
164
|
+
line(c.dim(' A mutation score says how well the tests pin down the changed code, not whether the code is correct.'));
|
|
165
|
+
line();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** What crossexam actually did, in plain words, so nobody has to read the source to know. */
|
|
169
|
+
export function printExecution(r, line = (s = '') => process.stdout.write(s + '\n')) {
|
|
170
|
+
const e = r.execution || {};
|
|
171
|
+
const iso = r.isolation || {};
|
|
172
|
+
const row = (k, v) => line(` ${c.dim(k.padEnd(14))} ${v}`);
|
|
173
|
+
line(c.bold(' What crossexam did'));
|
|
174
|
+
row('repository', `${e.repository ?? r.repo} ${c.dim(r.cwd || '')}`);
|
|
175
|
+
row('compared', r.scope);
|
|
176
|
+
row('files', r.files.length ? `${r.files.length} evaluated: ${r.files.slice(0, 4).map((f) => f.file).join(', ')}${r.files.length > 4 ? ` +${r.files.length - 4}` : ''}` : 'none');
|
|
177
|
+
row('mutations', `${e.mutantsGenerated ?? 0} generated, ${r.summary.attempted - r.summary.cachedResults} run now, ${r.summary.cachedResults} from cache, ${r.remaining} left for later`);
|
|
178
|
+
row('test runs', `${e.testRuns ?? 0}${r.testCommand ? ` ${c.dim(r.testCommand)}` : ''}`);
|
|
179
|
+
if (!iso.method) row('isolation', c.yellow('none available, so nothing was executed'));
|
|
180
|
+
else {
|
|
181
|
+
row('isolation', iso.sandboxed ? c.green(iso.method) : c.red(c.bold('NOT SANDBOXED') + ' (you passed --unsandboxed)'));
|
|
182
|
+
row(' filesystem', iso.filesystem);
|
|
183
|
+
row(' network', iso.network);
|
|
184
|
+
row(' environment', iso.environment);
|
|
185
|
+
const l = iso.limits || {};
|
|
186
|
+
row(' limits', [l.timeoutSeconds ? `${l.timeoutSeconds}s per run` : null, l.memoryMb ? `${l.memoryMb} MB memory` : null, l.cpuSeconds ? `${l.cpuSeconds}s CPU` : null, l.cpus ? `${l.cpus} CPUs` : null].filter(Boolean).join(', ') || 'timeout only');
|
|
187
|
+
}
|
|
188
|
+
row('duration', `${((e.durationMs ?? r.summary.ms) / 1000).toFixed(1)}s`);
|
|
189
|
+
const cl = e.cleanup || {};
|
|
190
|
+
row('cleanup', cl.status === 'removed' ? c.green('temporary copy removed') : cl.status === 'incomplete' ? c.yellow(`copy left at ${cl.path}`) : c.dim('nothing was created'));
|
|
191
|
+
if (e.staleCopiesRemoved) row('', c.dim(`also removed ${e.staleCopiesRemoved} copy left by an interrupted earlier run`));
|
|
192
|
+
if (r.workingTreeUntouched != null) row('your repo', r.workingTreeUntouched ? c.green('unchanged (every file hash, HEAD, refs, stash and status match)') : c.yellow('changed during the run, not by crossexam'));
|
|
193
|
+
line();
|
|
194
|
+
}
|