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/mcp.js
CHANGED
|
@@ -1,109 +1,198 @@
|
|
|
1
|
-
// A Model Context Protocol server over stdio, so any MCP-capable agent
|
|
2
|
-
// (Claude Code, Cursor, Copilot, Codex, Gemini CLI, Windsurf, Cline, Zed,
|
|
3
|
-
// Goose…) can ask crossexam to check its summary before it says "done".
|
|
4
|
-
// Newline-delimited JSON-RPC 2.0, no dependencies. stdout is the protocol;
|
|
5
|
-
// anything human goes to stderr.
|
|
6
|
-
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import readline from 'node:readline';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1
|
+
// A Model Context Protocol server over stdio, so any MCP-capable agent
|
|
2
|
+
// (Claude Code, Cursor, Copilot, Codex, Gemini CLI, Windsurf, Cline, Zed,
|
|
3
|
+
// Goose…) can ask crossexam to check its summary before it says "done".
|
|
4
|
+
// Newline-delimited JSON-RPC 2.0, no dependencies. stdout is the protocol;
|
|
5
|
+
// anything human goes to stderr.
|
|
6
|
+
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import readline from 'node:readline';
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import { detectWorkClaims } from './claims.js';
|
|
12
|
+
import { detectCommands, verifyText } from './live.js';
|
|
13
|
+
import { STATUS, assessStrength, ledgerRecord, qualityOf } from './strength.js';
|
|
14
|
+
|
|
15
|
+
const SUPPORTED = ['2025-06-18', '2025-03-26', '2024-11-05'];
|
|
16
|
+
|
|
17
|
+
const INSTRUCTIONS = `crossexam checks claims against the repository. Before you tell the user a task is done, call verify_claims with the exact summary you are about to give and the absolute path of the workspace. If any claim comes back "contradicted", fix the problem or correct the summary before finishing. Never say tests, build, types or lint pass unless verify_claims verified it.`;
|
|
18
|
+
|
|
19
|
+
const TOOLS = [
|
|
20
|
+
{
|
|
21
|
+
name: 'verify_claims',
|
|
22
|
+
title: 'Verify completion claims',
|
|
23
|
+
description:
|
|
24
|
+
'Check what you are about to tell the user ("all tests pass", "build is clean", "renamed `foo` to `bar` everywhere", "bumped zod to 3.23.8") against the repository right now. Runs the project\'s own test/build/typecheck/lint commands and searches the code. Call this before reporting a task as done.',
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
summary: { type: 'string', description: 'The completion message you are about to send, verbatim.' },
|
|
29
|
+
cwd: { type: 'string', description: 'Absolute path of the workspace/repository root. Defaults to the server\'s working directory.' },
|
|
30
|
+
mutate: { type: 'boolean', description: 'Also grade how strong the tests behind a "tests pass" or "implemented/fixed" claim are, by planting small defects in the changed code (slower: runs the test suite once per mutant).' },
|
|
31
|
+
},
|
|
32
|
+
required: ['summary'],
|
|
33
|
+
},
|
|
34
|
+
annotations: { readOnlyHint: false, openWorldHint: false },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'assess_test_strength',
|
|
38
|
+
title: 'Assess test strength (mutation testing)',
|
|
39
|
+
description:
|
|
40
|
+
"Plant small deterministic defects (flipped comparisons, inverted conditions, swapped operators) in the code you changed, run the repo's tests against each one in an isolated copy, and report which defects the tests failed to notice. Your working tree is never modified. Use the surviving defects to write tests that would catch them.",
|
|
41
|
+
inputSchema: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
cwd: { type: 'string', description: 'Absolute path of the repository root.' },
|
|
45
|
+
base: { type: 'string', description: 'Git ref to compare against. Default: uncommitted changes, else the last commit.' },
|
|
46
|
+
files: { type: 'array', items: { type: 'string' }, description: 'Mutate these files (every line) instead of the diff.' },
|
|
47
|
+
max: { type: 'number', description: 'Most mutants to run in this call (default 15). Finished results are cached, so calling again continues.' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'list_checks',
|
|
54
|
+
title: 'List the checks crossexam would run',
|
|
55
|
+
description: 'Show which test, build, typecheck, lint and migration-status commands crossexam found for a repository.',
|
|
56
|
+
inputSchema: { type: 'object', properties: { cwd: { type: 'string', description: 'Absolute path of the repository root.' } } },
|
|
57
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
export function startMcpServer({ version, defaultCwd = process.cwd() }) {
|
|
62
|
+
let client = 'unknown';
|
|
63
|
+
const send = (msg) => process.stdout.write(JSON.stringify(msg) + '\n');
|
|
64
|
+
const reply = (id, result) => send({ jsonrpc: '2.0', id, result });
|
|
65
|
+
const fail = (id, code, message) => send({ jsonrpc: '2.0', id, error: { code, message } });
|
|
66
|
+
|
|
67
|
+
const rl = readline.createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
68
|
+
rl.on('line', async (line) => {
|
|
69
|
+
if (!line.trim()) return;
|
|
70
|
+
let msg;
|
|
71
|
+
try {
|
|
72
|
+
msg = JSON.parse(line);
|
|
73
|
+
} catch {
|
|
74
|
+
return fail(null, -32700, 'Parse error');
|
|
75
|
+
}
|
|
76
|
+
const { id, method, params = {} } = msg;
|
|
77
|
+
const isRequest = id !== undefined && id !== null;
|
|
78
|
+
try {
|
|
79
|
+
switch (method) {
|
|
80
|
+
case 'initialize':
|
|
81
|
+
client = agentFromClient(params.clientInfo?.name);
|
|
82
|
+
return reply(id, {
|
|
83
|
+
protocolVersion: SUPPORTED.includes(params.protocolVersion) ? params.protocolVersion : SUPPORTED[0],
|
|
84
|
+
capabilities: { tools: { listChanged: false } },
|
|
85
|
+
serverInfo: { name: 'crossexam', title: 'crossexam', version },
|
|
86
|
+
instructions: INSTRUCTIONS,
|
|
87
|
+
});
|
|
88
|
+
case 'ping':
|
|
89
|
+
return reply(id, {});
|
|
90
|
+
case 'tools/list':
|
|
91
|
+
return reply(id, { tools: TOOLS });
|
|
92
|
+
case 'tools/call':
|
|
93
|
+
return reply(id, await callTool(params.name, params.arguments || {}, defaultCwd, client));
|
|
94
|
+
default:
|
|
95
|
+
if (isRequest) return fail(id, -32601, `Method not found: ${method}`);
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (isRequest) fail(id, -32603, String(e?.message || e));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
rl.on('close', () => process.exit(0));
|
|
102
|
+
process.stderr.write(`crossexam MCP server ${version} ready (cwd ${defaultCwd})\n`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Keep MCP calls well inside client timeouts; results are cached, so the agent can call again.
|
|
106
|
+
const MCP_LIMITS = { max: 15, budgetSeconds: 120 };
|
|
107
|
+
|
|
108
|
+
async function callTool(name, args, defaultCwd, client = 'unknown') {
|
|
109
|
+
const cwd = path.resolve(typeof args.cwd === 'string' && args.cwd ? args.cwd : defaultCwd);
|
|
110
|
+
if (name === 'list_checks') {
|
|
111
|
+
const cmds = detectCommands(cwd);
|
|
112
|
+
const lines = ['tests', 'build', 'types', 'lint', 'migration'].map((k) => `${k.padEnd(9)} ${cmds[k] ? `${cmds[k].command} (from ${cmds[k].source})` : '—'}`);
|
|
113
|
+
return { content: [{ type: 'text', text: `Checks for ${cwd}\n\n${lines.join('\n')}` }], structuredContent: { cwd, commands: cmds } };
|
|
114
|
+
}
|
|
115
|
+
if (name === 'verify_claims') {
|
|
116
|
+
if (typeof args.summary !== 'string' || !args.summary.trim()) {
|
|
117
|
+
return { isError: true, content: [{ type: 'text', text: 'summary is required: pass the completion message you are about to send.' }] };
|
|
118
|
+
}
|
|
119
|
+
const r = await verifyText(args.summary, { cwd });
|
|
120
|
+
if (args.mutate === true && (r.results.some((x) => x.kind === 'tests') || detectWorkClaims(args.summary).length)) {
|
|
121
|
+
const strength = await assessStrength({ cwd, ...MCP_LIMITS });
|
|
122
|
+
r.strength = strength;
|
|
123
|
+
for (const x of r.results) if (x.kind === 'tests') x.quality = qualityOf(strength);
|
|
124
|
+
ledger(ledgerRecord(strength, { agent: client, claim: args.summary.slice(0, 280), source: 'mcp' }));
|
|
125
|
+
}
|
|
126
|
+
const text = formatForAgent(r) + (r.strength ? '\n\n' + formatStrengthForAgent(r.strength) : '');
|
|
127
|
+
return { content: [{ type: 'text', text }], structuredContent: { ok: r.ok, results: r.results, strength: r.strength ? qualityOf(r.strength) : undefined } };
|
|
128
|
+
}
|
|
129
|
+
if (name === 'assess_test_strength') {
|
|
130
|
+
const files = Array.isArray(args.files) ? args.files.filter((x) => typeof x === 'string') : undefined;
|
|
131
|
+
const max = Number.isFinite(args.max) ? Math.min(Math.max(1, args.max), 50) : MCP_LIMITS.max;
|
|
132
|
+
const strength = await assessStrength({ cwd, base: typeof args.base === 'string' ? args.base : undefined, files, max, budgetSeconds: MCP_LIMITS.budgetSeconds });
|
|
133
|
+
ledger(ledgerRecord(strength, { agent: client, source: 'mcp' }));
|
|
134
|
+
return {
|
|
135
|
+
content: [{ type: 'text', text: formatStrengthForAgent(strength) }],
|
|
136
|
+
structuredContent: { quality: qualityOf(strength), summary: strength.summary, survivors: strength.mutants.filter((m) => m.status === STATUS.SURVIVED) },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return { isError: true, content: [{ type: 'text', text: `Unknown tool: ${name}` }] };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function formatForAgent(r) {
|
|
143
|
+
if (!r.results.length) {
|
|
144
|
+
return 'No checkable claims found in that summary. If you are saying tests, build, types or lint pass, say so explicitly; if you renamed something, name it in `backticks`.';
|
|
145
|
+
}
|
|
146
|
+
const mark = { verified: '✓ verified', contradicted: '✗ CONTRADICTED', review: '◇ needs review', stale: '◷ stale', unbacked: '○ unbacked' };
|
|
147
|
+
const lines = r.results.map((x) => `${mark[x.verdict]}: "${x.claim}"\n ${x.reason.replace(/`/g, '')}${x.quality ? `\n test strength: ${x.quality.rating}${x.quality.score != null ? ` (${Math.round(x.quality.score * 100)}% of planted defects caught)` : ''}. This is separate from the verdict above.` : ''}${x.verdict === 'contradicted' && x.evidence?.excerpt ? `\n Output:\n${x.evidence.excerpt.split('\n').map((l) => ' ' + l).join('\n')}` : ''}`);
|
|
148
|
+
const head = r.ok
|
|
149
|
+
? 'No claim was contradicted. You may report these as checked.'
|
|
150
|
+
: 'At least one claim is FALSE. Do not report the task as done: fix the problem and verify again, or correct your summary to say what is actually true.';
|
|
151
|
+
return `${head}\n\n${lines.join('\n\n')}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** What an agent needs to act on: the gap, the exact surviving defects, and what to do next. */
|
|
155
|
+
export function formatStrengthForAgent(r) {
|
|
156
|
+
const s = r.summary;
|
|
157
|
+
const head = `Test strength: ${r.rating}${s.score != null ? ` (${s.killed} of ${s.killed + s.survived} planted defects caught)` : ''}. ${r.headline?.text ?? ''}`.trim();
|
|
158
|
+
const surv = r.mutants.filter((m) => m.status === STATUS.SURVIVED).slice(0, 10);
|
|
159
|
+
const lines = surv.map((m) => `- ${m.file}:${m.line} (${m.function || 'top level'}): changing\n ${m.before.split('\n')[0].trim()}\n to\n ${m.after.split('\n')[0].trim()}\n did not fail any test.`);
|
|
160
|
+
const next = surv.length
|
|
161
|
+
? 'Add or strengthen tests so each of these changes would fail them, then call assess_test_strength again. Do not describe the tests as thorough until it reports strong.'
|
|
162
|
+
: r.blocker
|
|
163
|
+
? ''
|
|
164
|
+
: 'The tests caught every planted defect in the changed code.';
|
|
165
|
+
const tail = [
|
|
166
|
+
r.remaining ? `${r.remaining} more mutants were not run in this call; call again to continue (finished ones are cached).` : '',
|
|
167
|
+
'A mutation score measures how well tests pin down the changed code, not whether the code is correct. The working tree was not modified.',
|
|
168
|
+
].filter(Boolean);
|
|
169
|
+
return [head, lines.join('\n'), next, ...tail].filter(Boolean).join('\n\n');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const CLIENTS = [
|
|
173
|
+
[/claude/i, 'claude-code'],
|
|
174
|
+
[/codex/i, 'codex'],
|
|
175
|
+
[/cursor/i, 'cursor'],
|
|
176
|
+
[/copilot|visual studio code|vscode/i, 'copilot'],
|
|
177
|
+
[/gemini/i, 'gemini'],
|
|
178
|
+
[/windsurf|codeium/i, 'windsurf'],
|
|
179
|
+
[/roo/i, 'roo-code'],
|
|
180
|
+
[/kilo/i, 'kilo-code'],
|
|
181
|
+
[/cline/i, 'cline'],
|
|
182
|
+
[/zed/i, 'zed'],
|
|
183
|
+
[/goose/i, 'goose'],
|
|
184
|
+
];
|
|
185
|
+
function agentFromClient(name = '') {
|
|
186
|
+
for (const [re, id] of CLIENTS) if (re.test(name)) return id;
|
|
187
|
+
return name ? String(name).toLowerCase().slice(0, 40) : 'unknown';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function ledger(rec) {
|
|
191
|
+
try {
|
|
192
|
+
const dir = (process.env.CROSSEXAM_HOME || path.join(os.homedir(), '.crossexam'));
|
|
193
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
194
|
+
fs.appendFileSync(path.join(dir, 'ledger.jsonl'), JSON.stringify(rec) + '\n');
|
|
195
|
+
} catch {
|
|
196
|
+
/* history is best effort */
|
|
197
|
+
}
|
|
198
|
+
}
|