crossexamdev 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +17 -2
- package/bin/crossexam.js +291 -0
- package/package.json +43 -4
- package/src/analyze.js +194 -0
- package/src/claims.js +120 -0
- package/src/evidence.js +130 -0
- package/src/github.js +69 -0
- package/src/init.js +103 -0
- package/src/live.js +235 -0
- package/src/mcp.js +109 -0
- package/src/readers.js +297 -0
- package/src/report.js +99 -0
- package/src/transcripts.js +230 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zack Telsem
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# crossexamdev
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Your agents say done. We check.**
|
|
4
|
+
|
|
5
|
+
crossexam cross-examines what coding agents claim ("all tests pass", "every caller updated", "migration applied", "bumped zod to 3.23.8") against what actually happened in your repo. It works with any agent: Claude Code, Codex, Cursor, Copilot, Gemini CLI, Windsurf, Cline, Aider, Devin and the rest.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx crossexamdev scan # how often have your agents been wrong?
|
|
9
|
+
npx crossexamdev verify "All tests pass." # re-check any agent's summary right now
|
|
10
|
+
npx crossexamdev init --mcp # make every agent in this repo check itself
|
|
11
|
+
npx crossexamdev mcp # MCP server with a verify_claims tool
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Node 18.17+, zero dependencies, runs entirely on your machine. Once installed, the command is also available as `crossexam`.
|
|
15
|
+
|
|
16
|
+
Full docs, the GitHub Action and the dashboard: https://github.com/zackt223/crossexam
|
|
17
|
+
|
|
18
|
+
Free and open source under the MIT license. Built by [Zack Telsem](https://zacktelsem.com).
|
package/bin/crossexam.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { analyzeSession } from '../src/analyze.js';
|
|
7
|
+
import { emitActions, readPullRequest } from '../src/github.js';
|
|
8
|
+
import { globalSnippets, runInit } from '../src/init.js';
|
|
9
|
+
import { detectCommands, verifyText } from '../src/live.js';
|
|
10
|
+
import { formatForAgent, startMcpServer } from '../src/mcp.js';
|
|
11
|
+
import { discoverAider, discoverMore } from '../src/readers.js';
|
|
12
|
+
import { buildReport, c, printReport } from '../src/report.js';
|
|
13
|
+
import { AGENTS, defaultSources, findTranscripts, readSession } from '../src/transcripts.js';
|
|
14
|
+
|
|
15
|
+
const VERSION = '0.2.0';
|
|
16
|
+
const HELP = `
|
|
17
|
+
${c.bold('crossexam')} — cross-examine what your coding agents claim
|
|
18
|
+
|
|
19
|
+
${c.bold('Works with any agent')}
|
|
20
|
+
crossexam verify "<summary>" check any agent's "done" message against the repo right now
|
|
21
|
+
crossexam mcp MCP server: any MCP agent calls verify_claims before it says done
|
|
22
|
+
crossexam init [--mcp] add the rule to AGENTS.md (and MCP configs) so agents check themselves
|
|
23
|
+
crossexam verify --github in CI: check the claims in an agent's pull request description
|
|
24
|
+
|
|
25
|
+
${c.bold('History')}
|
|
26
|
+
crossexam scan check local transcripts: Claude Code, Codex, Gemini CLI, Cline,
|
|
27
|
+
Roo Code, Kilo Code, Aider and the open format
|
|
28
|
+
crossexam hook Claude Code Stop hook: send a false "done" back to the agent
|
|
29
|
+
crossexam install add that hook to ~/.claude/settings.json
|
|
30
|
+
|
|
31
|
+
${c.bold('verify')}
|
|
32
|
+
<text> | --file <path> | stdin the summary to check
|
|
33
|
+
--cwd <dir> repository to check (default: current directory)
|
|
34
|
+
--dry-run show which checks would run, run nothing
|
|
35
|
+
--json machine-readable result
|
|
36
|
+
--fail-on <contradicted|none> exit 1 when a claim is contradicted (default: contradicted)
|
|
37
|
+
--timeout <seconds> per command (default 300)
|
|
38
|
+
|
|
39
|
+
${c.bold('scan')}
|
|
40
|
+
--since <30d|12h|all> how far back to look (default 30d)
|
|
41
|
+
--agent <name> one of: ${AGENTS.join(', ')}
|
|
42
|
+
--repo <name> only one repo
|
|
43
|
+
--path <dir> also look for Aider history here (repeatable; cwd is always checked)
|
|
44
|
+
--file <path> one transcript (with --agent)
|
|
45
|
+
--json [out.json] write the full report; open it in the dashboard
|
|
46
|
+
--limit <n> false "done"s to print (default 8)
|
|
47
|
+
|
|
48
|
+
${c.bold('hook / install / init')}
|
|
49
|
+
--rerun re-run the test command before trusting a "tests pass"
|
|
50
|
+
--project install into ./.claude/settings.json instead
|
|
51
|
+
--mcp init: also write project MCP configs (Claude Code, Cursor, VS Code, Gemini CLI, Roo Code)
|
|
52
|
+
--dry-run print the change, write nothing
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const VALUED = new Set(['since', 'agent', 'repo', 'file', 'json', 'limit', 'path', 'cwd', 'fail-on', 'timeout']);
|
|
56
|
+
const args = process.argv.slice(2);
|
|
57
|
+
const cmd = args[0] && !args[0].startsWith('-') ? args.shift() : 'scan';
|
|
58
|
+
const flag = (name) => args.includes(`--${name}`);
|
|
59
|
+
const opt = (name, fallback) => {
|
|
60
|
+
const i = args.indexOf(`--${name}`);
|
|
61
|
+
if (i < 0) return fallback;
|
|
62
|
+
const v = args[i + 1];
|
|
63
|
+
return v && !v.startsWith('--') ? v : true;
|
|
64
|
+
};
|
|
65
|
+
const opts = (name) => args.flatMap((a, i) => (a === `--${name}` && args[i + 1] && !args[i + 1].startsWith('--') ? [args[i + 1]] : []));
|
|
66
|
+
const positional = () => args.filter((a, i) => !a.startsWith('--') && !(i > 0 && args[i - 1].startsWith('--') && VALUED.has(args[i - 1].slice(2))));
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
if (flag('help') || cmd === 'help') process.stdout.write(HELP + '\n');
|
|
70
|
+
else if (flag('version') || cmd === 'version') console.log(VERSION);
|
|
71
|
+
else if (cmd === 'scan') await scan();
|
|
72
|
+
else if (cmd === 'verify') await verify();
|
|
73
|
+
else if (cmd === 'mcp') startMcpServer({ version: VERSION, defaultCwd: path.resolve(String(opt('cwd', process.cwd()))) });
|
|
74
|
+
else if (cmd === 'init') init();
|
|
75
|
+
else if (cmd === 'hook') await hook();
|
|
76
|
+
else if (cmd === 'install') install();
|
|
77
|
+
else {
|
|
78
|
+
process.stderr.write(`Unknown command "${cmd}".\n${HELP}\n`);
|
|
79
|
+
process.exitCode = 2;
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
// A verifier must never take the agent down with it.
|
|
83
|
+
process.stderr.write(`crossexam: ${cmd === 'hook' ? e?.stack || e : e?.message || e}\n`);
|
|
84
|
+
process.exitCode = cmd === 'hook' ? 0 : 2;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function scan() {
|
|
88
|
+
const since = parseSince(opt('since', '30d'));
|
|
89
|
+
const onlyAgent = opt('agent');
|
|
90
|
+
const onlyRepo = opt('repo');
|
|
91
|
+
const single = opt('file');
|
|
92
|
+
|
|
93
|
+
let files = [];
|
|
94
|
+
if (typeof single === 'string') files = [{ agent: typeof onlyAgent === 'string' ? onlyAgent : 'claude-code', file: path.resolve(single) }];
|
|
95
|
+
else {
|
|
96
|
+
for (const src of defaultSources()) for (const f of findTranscripts(src.root, since)) files.push({ agent: src.agent, file: f });
|
|
97
|
+
files.push(...discoverMore(since), ...discoverAider([process.cwd(), ...opts('path').map((p) => path.resolve(p))], since));
|
|
98
|
+
if (typeof onlyAgent === 'string') files = files.filter((f) => f.agent === onlyAgent);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const claims = [];
|
|
102
|
+
let turns = 0;
|
|
103
|
+
let ranCheckTurns = 0;
|
|
104
|
+
let contradictedTurns = 0;
|
|
105
|
+
let sessions = 0;
|
|
106
|
+
const agents = new Set();
|
|
107
|
+
for (const { agent, file } of files) {
|
|
108
|
+
let s;
|
|
109
|
+
try {
|
|
110
|
+
s = await readSession(agent, file);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
// One unreadable transcript (an agent mid-write, a format change) shouldn't sink the scan.
|
|
113
|
+
process.stderr.write(c.dim(` skipped ${file}: ${e.message}\n`));
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (onlyRepo && s.repo !== onlyRepo) continue;
|
|
117
|
+
if (!s.turns.length) continue;
|
|
118
|
+
sessions++;
|
|
119
|
+
agents.add(s.agent);
|
|
120
|
+
const r = analyzeSession(s);
|
|
121
|
+
turns += r.turns;
|
|
122
|
+
ranCheckTurns += r.ranCheckTurns;
|
|
123
|
+
contradictedTurns += new Set(r.claims.filter((x) => x.verdict === 'contradicted').map((x) => x.turn)).size;
|
|
124
|
+
claims.push(...r.claims);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const report = buildReport(claims, { sessions, turns, ranCheckTurns, contradictedTurns, agents: [...agents], since: since ? new Date(since).toISOString() : null });
|
|
128
|
+
const json = opt('json');
|
|
129
|
+
if (json) {
|
|
130
|
+
const out = typeof json === 'string' ? json : 'crossexam-report.json';
|
|
131
|
+
fs.writeFileSync(out, JSON.stringify(report, null, 2));
|
|
132
|
+
printReport(report, { limit: Number(opt('limit', 8)) });
|
|
133
|
+
console.log(` ${c.dim('Report written to')} ${path.resolve(out)}`);
|
|
134
|
+
console.log(` ${c.dim('Drop it on the dashboard to see reliability by agent, model and repo.')}\n`);
|
|
135
|
+
} else {
|
|
136
|
+
printReport(report, { limit: Number(opt('limit', 8)) });
|
|
137
|
+
console.log(c.dim(' Run with --json to save the full report for the dashboard.\n'));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function verify() {
|
|
142
|
+
const cwd = path.resolve(String(opt('cwd', process.cwd())));
|
|
143
|
+
const github = flag('github');
|
|
144
|
+
const pr = github ? readPullRequest() : null;
|
|
145
|
+
if (github && !pr) throw new Error('--github needs a pull_request event (GITHUB_EVENT_PATH).');
|
|
146
|
+
|
|
147
|
+
let text = pr ? `${pr.title}\n\n${pr.body}` : positional().join(' ');
|
|
148
|
+
const file = opt('file');
|
|
149
|
+
if (!text && typeof file === 'string') text = fs.readFileSync(file, 'utf8');
|
|
150
|
+
if (!text) text = await readStdin();
|
|
151
|
+
if (!text.trim()) throw new Error('Nothing to verify. Pass the summary as an argument, with --file, or on stdin.');
|
|
152
|
+
|
|
153
|
+
const json = flag('json');
|
|
154
|
+
const r = await verifyText(text, {
|
|
155
|
+
cwd,
|
|
156
|
+
run: !flag('dry-run'),
|
|
157
|
+
timeoutMs: opt('timeout') ? Number(opt('timeout')) * 1000 : undefined,
|
|
158
|
+
onRun: (command) => !json && process.stderr.write(c.dim(` running ${command}…\n`)),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
if (json) process.stdout.write(JSON.stringify({ ...r, pr }, null, 2) + '\n');
|
|
162
|
+
else if (github) emitActions(pr, r);
|
|
163
|
+
else {
|
|
164
|
+
console.log();
|
|
165
|
+
console.log(formatForAgent(r).replace(/^/gm, ' '));
|
|
166
|
+
if (!r.results.length && Object.keys(r.commands).length) console.log(c.dim(`\n Checks available here: ${Object.entries(r.commands).map(([k, v]) => `${k} (${v.command})`).join(', ')}`));
|
|
167
|
+
console.log();
|
|
168
|
+
}
|
|
169
|
+
if (opt('fail-on', 'contradicted') !== 'none' && !r.ok) process.exitCode = 1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function init() {
|
|
173
|
+
const cwd = path.resolve(String(opt('cwd', process.cwd())));
|
|
174
|
+
const { cli, server } = selfCommands();
|
|
175
|
+
const changes = runInit({ cwd, cliCmd: cli, serverCmd: server, mcp: flag('mcp'), dryRun: flag('dry-run') });
|
|
176
|
+
console.log(`\n ${c.bold('crossexam init')} ${c.dim(cwd)}${flag('dry-run') ? c.dim(' (dry run, nothing written)') : ''}\n`);
|
|
177
|
+
for (const ch of changes) console.log(` ${ch.action === 'unchanged' ? c.dim('·') : c.green('✓')} ${ch.file.padEnd(24)} ${c.dim(ch.action)}`);
|
|
178
|
+
const cmds = detectCommands(cwd);
|
|
179
|
+
console.log(`\n ${c.bold('Checks found')} ${['tests', 'build', 'types', 'lint', 'migration'].map((k) => (cmds[k] ? `${k}: ${cmds[k].command}` : c.dim(`${k}: —`))).join(c.dim(' · '))}`);
|
|
180
|
+
if (!cmds.migration) console.log(c.dim(' Migrations are only checked through a read-only status command you name in crossexam.json.'));
|
|
181
|
+
if (!flag('mcp')) console.log(c.dim('\n Add --mcp to also write MCP configs for Claude Code, Cursor, VS Code/Copilot, Gemini CLI and Roo Code.'));
|
|
182
|
+
console.log(`\n ${c.bold('Per-user MCP setup for other agents')}`);
|
|
183
|
+
for (const [name, snippet] of globalSnippets(server)) console.log(`\n ${c.dim(name)}\n${indent(snippet, ' ')}`);
|
|
184
|
+
console.log();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function hook() {
|
|
188
|
+
const raw = await readStdin();
|
|
189
|
+
let input = {};
|
|
190
|
+
try {
|
|
191
|
+
input = JSON.parse(raw || '{}');
|
|
192
|
+
} catch {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (!input.transcript_path || !fs.existsSync(input.transcript_path)) return;
|
|
196
|
+
|
|
197
|
+
const s = await readSession('claude-code', input.transcript_path);
|
|
198
|
+
const cwd = input.cwd || s.cwd || process.cwd();
|
|
199
|
+
const { claims } = analyzeSession(s, { onlyLastTurn: true, live: { cwd, rerun: flag('rerun') } });
|
|
200
|
+
if (!claims.length) return;
|
|
201
|
+
ledger(claims);
|
|
202
|
+
|
|
203
|
+
const bad = claims.filter((x) => x.verdict === 'contradicted' || x.verdict === 'stale');
|
|
204
|
+
if (!bad.length) return;
|
|
205
|
+
|
|
206
|
+
const lines = bad.map((x) => `- You said: "${x.claim}"\n crossexam: ${x.reason}${x.evidence?.excerpt ? `\n Output:\n${indent(x.evidence.excerpt, ' ')}` : ''}`);
|
|
207
|
+
if (input.stop_hook_active) {
|
|
208
|
+
// Already sent back once this turn; tell the human instead of looping.
|
|
209
|
+
process.stdout.write(JSON.stringify({ systemMessage: `crossexam: ${bad.length} claim${bad.length > 1 ? 's' : ''} still not backed by a passing check.\n${lines.join('\n')}` }));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
process.stdout.write(
|
|
213
|
+
JSON.stringify({
|
|
214
|
+
decision: 'block',
|
|
215
|
+
reason: `crossexam checked your summary against what actually ran this turn, and ${bad.length === 1 ? 'one claim does' : bad.length + ' claims do'} not hold up:\n${lines.join('\n')}\n\nFix the problem and re-run the check, or correct your summary to say what is actually true.`,
|
|
216
|
+
}),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function install() {
|
|
221
|
+
const file = flag('project') ? path.resolve('.claude', 'settings.json') : path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'), 'settings.json');
|
|
222
|
+
const { cli } = selfCommands();
|
|
223
|
+
const command = `${cli} hook${flag('rerun') ? ' --rerun' : ''}`;
|
|
224
|
+
|
|
225
|
+
let settings = {};
|
|
226
|
+
if (fs.existsSync(file)) settings = JSON.parse(fs.readFileSync(file, 'utf8') || '{}');
|
|
227
|
+
settings.hooks ??= {};
|
|
228
|
+
settings.hooks.Stop ??= [];
|
|
229
|
+
const already = settings.hooks.Stop.some((g) => g.hooks?.some((h) => /crossexam/.test(h.command || '')));
|
|
230
|
+
if (already) {
|
|
231
|
+
console.log(`\n ${c.green('✓')} crossexam is already a Stop hook in ${file}\n`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
settings.hooks.Stop.push({ hooks: [{ type: 'command', command, timeout: flag('rerun') ? 240 : 30 }] });
|
|
235
|
+
|
|
236
|
+
if (flag('dry-run')) {
|
|
237
|
+
console.log(`\n Would write ${file}:\n`);
|
|
238
|
+
console.log(indent(JSON.stringify({ hooks: { Stop: settings.hooks.Stop } }, null, 2), ' '));
|
|
239
|
+
console.log();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
243
|
+
if (fs.existsSync(file)) fs.copyFileSync(file, file + '.bak');
|
|
244
|
+
fs.writeFileSync(file, JSON.stringify(settings, null, 2) + '\n');
|
|
245
|
+
console.log(`\n ${c.green('✓')} Added crossexam as a Stop hook in ${file}`);
|
|
246
|
+
console.log(` ${c.dim('When Claude Code says it is done and the evidence disagrees, the turn is sent back with the failing output.')}\n`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ---------- helpers ----------
|
|
250
|
+
|
|
251
|
+
/** How this copy of crossexam should be invoked by agents and configs. */
|
|
252
|
+
function selfCommands() {
|
|
253
|
+
const self = fileURLToPath(import.meta.url).replace(/\\/g, '/');
|
|
254
|
+
// Published on npm as "crossexamdev" (the bare name was taken).
|
|
255
|
+
if (/\/_npx\/|\/node_modules\/crossexamdev\//.test(self)) return { cli: 'npx -y crossexamdev', server: ['npx', '-y', 'crossexamdev', 'mcp'] };
|
|
256
|
+
return { cli: `node "${self}"`, server: ['node', self, 'mcp'] };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function parseSince(v) {
|
|
260
|
+
if (v === 'all' || v === true) return 0;
|
|
261
|
+
const m = String(v).match(/^(\d+)\s*([hdw])$/);
|
|
262
|
+
if (!m) return 0;
|
|
263
|
+
const ms = { h: 3600e3, d: 86400e3, w: 7 * 86400e3 }[m[2]];
|
|
264
|
+
return Date.now() - Number(m[1]) * ms;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function ledger(claims) {
|
|
268
|
+
try {
|
|
269
|
+
const dir = path.join(os.homedir(), '.crossexam');
|
|
270
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
271
|
+
fs.appendFileSync(path.join(dir, 'ledger.jsonl'), claims.map((x) => JSON.stringify(x)).join('\n') + '\n');
|
|
272
|
+
} catch {
|
|
273
|
+
/* history is best effort */
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function readStdin() {
|
|
278
|
+
return new Promise((resolve) => {
|
|
279
|
+
if (process.stdin.isTTY) return resolve('');
|
|
280
|
+
let data = '';
|
|
281
|
+
process.stdin.setEncoding('utf8');
|
|
282
|
+
process.stdin.on('data', (d) => (data += d));
|
|
283
|
+
process.stdin.on('end', () => resolve(data));
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// A declaration, not a const: the commands above run at module top level
|
|
288
|
+
// before a const down here would be initialised.
|
|
289
|
+
function indent(s, p) {
|
|
290
|
+
return s.split('\n').map((l) => p + l).join('\n');
|
|
291
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crossexamdev",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Cross-examine what any coding agent claims: verify CLI, MCP server, GitHub Action and transcript history for Claude Code, Codex, Gemini CLI, Cline, Aider and more.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"crossexamdev": "bin/crossexam.js",
|
|
8
|
+
"crossexam": "bin/crossexam.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18.17"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "node --test test/*.test.js"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"mcp",
|
|
22
|
+
"cursor",
|
|
23
|
+
"copilot",
|
|
24
|
+
"gemini",
|
|
25
|
+
"aider",
|
|
26
|
+
"cline",
|
|
27
|
+
"ai",
|
|
28
|
+
"agents",
|
|
29
|
+
"claude-code",
|
|
30
|
+
"codex",
|
|
31
|
+
"verification",
|
|
32
|
+
"code-review"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"author": "Zack Telsem (https://zacktelsem.com)",
|
|
36
|
+
"homepage": "https://github.com/zackt223/crossexam#readme",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/zackt223/crossexam.git",
|
|
40
|
+
"directory": "cli"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/zackt223/crossexam/issues"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/analyze.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// The verifier: line each claim up against what actually ran before it.
|
|
2
|
+
//
|
|
3
|
+
// Verdicts
|
|
4
|
+
// verified the most recent relevant check passed and nothing changed since
|
|
5
|
+
// contradicted the most recent relevant check failed, or a live re-check disagrees
|
|
6
|
+
// stale a check passed, then files were edited before the claim was made
|
|
7
|
+
// unbacked nothing that could back the claim ran at all
|
|
8
|
+
// review evidence exists but can't settle it (masked exit, subset run, security)
|
|
9
|
+
|
|
10
|
+
import { detectClaims, taskTypeOf } from './claims.js';
|
|
11
|
+
import { RUNNERS, SEARCH, excerpt, isEdit, judgeRun, runsCheck } from './evidence.js';
|
|
12
|
+
import { detectCommands, grepRepo, manifestVersion, runCommandSync, versionMatches } from './live.js';
|
|
13
|
+
|
|
14
|
+
/** Which runner families can back which claim kind. */
|
|
15
|
+
const BACKED_BY = {
|
|
16
|
+
tests: ['tests'],
|
|
17
|
+
build: ['build'],
|
|
18
|
+
types: ['types', 'build'],
|
|
19
|
+
lint: ['lint'],
|
|
20
|
+
migration: ['migration'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const SUBSET = /\s(?:[\w./\\-]+\.(?:test|spec)\.[cm]?[jt]sx?|[\w./\\-]+_test\.(?:go|py)|[\w./\\-]*test_\w+\.py)\b|\s-t\s|\s--testNamePattern|\s--grep\s|\s-k\s|::\w|\s-run\s|\s--filter\b/;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {object} session normalised session from transcripts.js
|
|
27
|
+
* @param {{live?: {cwd: string, rerun?: boolean, timeoutMs?: number}, onlyLastTurn?: boolean}} [opts]
|
|
28
|
+
*/
|
|
29
|
+
export function analyzeSession(session, opts = {}) {
|
|
30
|
+
const claims = [];
|
|
31
|
+
// One flat timeline so a claim can lean on a check from the previous turn
|
|
32
|
+
// when nothing was edited in between ("tests still pass").
|
|
33
|
+
const timeline = [];
|
|
34
|
+
for (const t of session.turns) for (const it of t.items) timeline.push({ ...it, turn: t.index });
|
|
35
|
+
|
|
36
|
+
const firstTurn = opts.onlyLastTurn ? session.turns.length - 1 : 0;
|
|
37
|
+
let ranCheckTurns = 0;
|
|
38
|
+
|
|
39
|
+
for (const t of session.turns.slice(Math.max(0, firstTurn))) {
|
|
40
|
+
const startPos = timeline.findIndex((e) => e.turn === t.index);
|
|
41
|
+
if (startPos < 0) continue;
|
|
42
|
+
const turnItems = timeline.filter((e) => e.turn === t.index);
|
|
43
|
+
if (turnItems.some((e) => e.kind === 'tool' && !e.denied && e.command && Object.keys(RUNNERS).some((f) => runsCheck(f, e.command)))) ranCheckTurns++;
|
|
44
|
+
|
|
45
|
+
const seen = new Map();
|
|
46
|
+
turnItems.forEach((item, k) => {
|
|
47
|
+
if (item.kind !== 'text') return;
|
|
48
|
+
const pos = startPos + k;
|
|
49
|
+
for (const c of detectClaims(item.text)) {
|
|
50
|
+
// Keep the last statement of each kind in a turn: that's what the agent signed off on.
|
|
51
|
+
seen.set(c.kind + (c.subject?.from || c.subject?.pkg || ''), { c, pos });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
for (const { c, pos } of seen.values()) {
|
|
56
|
+
const v = judge(c, pos, t.index, timeline, opts.live);
|
|
57
|
+
claims.push({
|
|
58
|
+
id: `${session.agent}:${session.id.slice(0, 8)}:${t.index}:${c.kind}${c.subject?.from ? ':' + c.subject.from : ''}`,
|
|
59
|
+
agent: session.agent,
|
|
60
|
+
model: t.model || session.model || 'unknown',
|
|
61
|
+
repo: session.repo,
|
|
62
|
+
session: session.id,
|
|
63
|
+
turn: t.index,
|
|
64
|
+
at: timeline[pos].at || t.at,
|
|
65
|
+
taskType: taskTypeOf(t.prompt),
|
|
66
|
+
prompt: t.prompt.slice(0, 160),
|
|
67
|
+
kind: c.kind,
|
|
68
|
+
claim: c.sentence,
|
|
69
|
+
verdict: v.verdict,
|
|
70
|
+
reason: v.reason,
|
|
71
|
+
evidence: v.evidence,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { claims, turns: session.turns.length - Math.max(0, firstTurn), ranCheckTurns };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function judge(claim, pos, turnIndex, timeline, live) {
|
|
79
|
+
const before = timeline.slice(0, pos);
|
|
80
|
+
const lastEditIdx = findLastIndex(before, isEdit);
|
|
81
|
+
|
|
82
|
+
if (claim.kind === 'security') {
|
|
83
|
+
return { verdict: 'review', reason: 'Security fixes always go to a human reviewer.', evidence: null };
|
|
84
|
+
}
|
|
85
|
+
if (claim.kind === 'refactor') return judgeRefactor(claim, before, lastEditIdx, turnIndex, live);
|
|
86
|
+
if (claim.kind === 'deps') return judgeDeps(claim, before, turnIndex, live);
|
|
87
|
+
|
|
88
|
+
const families = BACKED_BY[claim.kind];
|
|
89
|
+
// Look back through this turn and the one before it.
|
|
90
|
+
const runIdx = findLastIndex(before, (e) => e.kind === 'tool' && !e.denied && e.command && e.turn >= turnIndex - 1 && families.some((f) => runsCheck(f, e.command)));
|
|
91
|
+
|
|
92
|
+
if (live?.rerun && claim.kind === 'tests') {
|
|
93
|
+
// Only ever run the repo's own test command (package.json, crossexam.json…),
|
|
94
|
+
// never a string from the transcript. A transcript command may be one the
|
|
95
|
+
// sandbox or a guard hook stopped, with extra segments chained on
|
|
96
|
+
// ("npm test; curl … | sh"); replaying it here would run it unconfined.
|
|
97
|
+
const cmd = detectCommands(live.cwd).tests?.command;
|
|
98
|
+
if (cmd) {
|
|
99
|
+
const res = runCommandSync(cmd, { cwd: live.cwd, timeoutMs: live.timeoutMs ?? 180000 });
|
|
100
|
+
const j = judgeRun(res);
|
|
101
|
+
const ev = { command: cmd, exitCode: res.exitCode, excerpt: excerpt(res.output), rerun: true };
|
|
102
|
+
if (j.status === 'fail') return { verdict: 'contradicted', reason: `Re-ran \`${short(cmd)}\` just now: ${j.why}.`, evidence: ev };
|
|
103
|
+
if (j.status === 'pass') return { verdict: 'verified', reason: `Re-ran \`${short(cmd)}\` just now and it passed.`, evidence: ev };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (runIdx < 0) {
|
|
108
|
+
return { verdict: 'unbacked', reason: UNBACKED[claim.kind], evidence: null };
|
|
109
|
+
}
|
|
110
|
+
const run = before[runIdx];
|
|
111
|
+
const j = judgeRun(run);
|
|
112
|
+
const ev = { command: run.command, exitCode: run.exitCode, excerpt: excerpt(run.output) };
|
|
113
|
+
|
|
114
|
+
if (j.status === 'fail') {
|
|
115
|
+
return { verdict: 'contradicted', reason: `Last \`${short(run.command)}\` before the claim failed: ${j.why}.`, evidence: ev };
|
|
116
|
+
}
|
|
117
|
+
if (lastEditIdx > runIdx) {
|
|
118
|
+
const edits = before.slice(runIdx + 1).filter(isEdit).length;
|
|
119
|
+
return { verdict: 'stale', reason: `\`${short(run.command)}\` passed, then ${edits} edit${edits === 1 ? '' : 's'} landed before the claim, with no re-run.`, evidence: ev };
|
|
120
|
+
}
|
|
121
|
+
if (j.status === 'masked') {
|
|
122
|
+
return { verdict: 'review', reason: `\`${short(run.command)}\`: ${j.why}.`, evidence: ev };
|
|
123
|
+
}
|
|
124
|
+
if (claim.kind === 'tests' && /\ball\b|\bevery\b|\bfull\b|\bwhole\b/i.test(claim.sentence) && SUBSET.test(' ' + run.command)) {
|
|
125
|
+
return { verdict: 'review', reason: `Claimed the whole suite passes; only a subset ran (\`${short(run.command)}\`).`, evidence: ev };
|
|
126
|
+
}
|
|
127
|
+
return { verdict: 'verified', reason: `\`${short(run.command)}\` passed after the last edit.`, evidence: ev };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function judgeRefactor(claim, before, lastEditIdx, turnIndex, live) {
|
|
131
|
+
const sym = claim.subject?.from;
|
|
132
|
+
if (live && sym) {
|
|
133
|
+
const hits = grepRepo(live.cwd, sym, claim.subject?.to);
|
|
134
|
+
if (hits) {
|
|
135
|
+
if (hits.length) {
|
|
136
|
+
return { verdict: 'contradicted', reason: `\`${sym}\` is still referenced in ${hits.length} place${hits.length === 1 ? '' : 's'}.`, evidence: { command: `git grep -nw ${sym}`, exitCode: 0, excerpt: hits.slice(0, 6).join('\n') } };
|
|
137
|
+
}
|
|
138
|
+
return { verdict: 'verified', reason: `No references to \`${sym}\` remain in the repo.`, evidence: { command: `git grep -nw ${sym}`, exitCode: 1, excerpt: '' } };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const searches = before.filter((e, i) => i > lastEditIdx && e.turn >= turnIndex - 1 && e.kind === 'tool' && !e.denied && (e.name === 'Grep' || (e.command && SEARCH.test(e.command))));
|
|
142
|
+
if (!searches.length) {
|
|
143
|
+
return { verdict: 'unbacked', reason: `Said every reference was updated, but never searched after the last edit${sym ? ` for \`${sym}\`` : ''}.`, evidence: null };
|
|
144
|
+
}
|
|
145
|
+
const relevant = sym ? searches.filter((e) => e.command?.includes(sym)) : searches;
|
|
146
|
+
const last = (relevant.length ? relevant : searches).at(-1);
|
|
147
|
+
const empty = !last.output.trim() || /no (?:matches|files) found|found 0 (?:files|matches)|^0$/i.test(last.output.trim());
|
|
148
|
+
const ev = { command: last.command, exitCode: last.exitCode, excerpt: excerpt(last.output) };
|
|
149
|
+
if (sym && relevant.length && !empty && !(claim.subject?.to && last.output.split('\n').every((l) => !l.trim() || l.includes(claim.subject.to)))) {
|
|
150
|
+
return { verdict: 'contradicted', reason: `The last search for \`${sym}\` after editing still returned matches.`, evidence: ev };
|
|
151
|
+
}
|
|
152
|
+
if (empty) return { verdict: 'verified', reason: `A search after the last edit came back empty.`, evidence: ev };
|
|
153
|
+
return { verdict: 'review', reason: 'Searched after editing, but the results need a human to read them.', evidence: ev };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function judgeDeps(claim, before, turnIndex, live) {
|
|
157
|
+
const { pkg, version } = claim.subject || {};
|
|
158
|
+
if (live && pkg && version) {
|
|
159
|
+
const found = manifestVersion(live.cwd, pkg);
|
|
160
|
+
if (found) {
|
|
161
|
+
const ev = { command: `read ${found.file}`, exitCode: 0, excerpt: `${pkg} ${found.version}` };
|
|
162
|
+
return versionMatches(found.version, version)
|
|
163
|
+
? { verdict: 'verified', reason: `${found.file} has ${pkg} at ${found.version}.`, evidence: ev }
|
|
164
|
+
: { verdict: 'contradicted', reason: `Claimed ${pkg} ${version}, but ${found.file} still has ${found.version}.`, evidence: ev };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const idx = findLastIndex(before, (e) => e.kind === 'tool' && !e.denied && e.command && e.turn >= turnIndex - 1 && runsCheck('deps', e.command) && (!pkg || e.command.includes(pkg)));
|
|
168
|
+
if (idx < 0) return { verdict: 'unbacked', reason: `No install or lockfile update for ${pkg || 'the package'} ran.`, evidence: null };
|
|
169
|
+
const run = before[idx];
|
|
170
|
+
const j = judgeRun(run);
|
|
171
|
+
const ev = { command: run.command, exitCode: run.exitCode, excerpt: excerpt(run.output) };
|
|
172
|
+
if (j.status === 'fail') return { verdict: 'contradicted', reason: `\`${short(run.command)}\` failed: ${j.why}.`, evidence: ev };
|
|
173
|
+
return { verdict: 'verified', reason: `\`${short(run.command)}\` completed.`, evidence: ev };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ---------- helpers ----------
|
|
177
|
+
|
|
178
|
+
const UNBACKED = {
|
|
179
|
+
tests: 'Said the tests pass, but no test command ran.',
|
|
180
|
+
build: 'Said the build passes, but no build ran.',
|
|
181
|
+
types: 'Said types check, but no typecheck ran.',
|
|
182
|
+
lint: 'Said lint is clean, but no linter ran.',
|
|
183
|
+
migration: 'Said the migration applied, but no migration command ran.',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
function short(cmd = '') {
|
|
187
|
+
const one = cmd.replace(/\s+/g, ' ').trim();
|
|
188
|
+
return one.length > 60 ? one.slice(0, 57) + '…' : one;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function findLastIndex(arr, fn) {
|
|
192
|
+
for (let i = arr.length - 1; i >= 0; i--) if (fn(arr[i])) return i;
|
|
193
|
+
return -1;
|
|
194
|
+
}
|