skalpel 4.0.41 → 4.0.43
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/_test-home.mjs +18 -0
- package/anchor-shadow.mjs +20 -8
- package/autopsy.mjs +38 -8
- package/catches.mjs +40 -6
- package/incremental-ingest.mjs +14 -2
- package/insights.mjs +184 -3
- package/ledger.mjs +16 -3
- package/login.mjs +52 -12
- package/mutation-check.mjs +158 -0
- package/package.json +1 -1
- package/skalpel-hook.mjs +6 -8
- package/skalpel-setup.mjs +148 -0
- package/skalpel-statusline.mjs +16 -2
- package/verify-core.test.mjs +186 -0
- package/verify-integration.test.mjs +194 -0
- package/verify-safeguards.test.mjs +178 -0
- package/verify-shadow.mjs +287 -16
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// mutation-check.mjs — mutation testing for the CRITICAL LOGIC: detectCompletionClaim (incl. the negation
|
|
3
|
+
// guard), classifyOutcome, classifyConfirm, plus the false-accusation safeguards shipUrlPass (URL
|
|
4
|
+
// reachability) and hasMutatingFlag (non-idempotent re-run guard). For each mutation we flip ONE key
|
|
5
|
+
// predicate/branch in verify-shadow.mjs and re-run the pure-function suite (verify-core.test.mjs) against
|
|
6
|
+
// the mutated copy. A mutation the suite still PASSES is a SURVIVOR (a test gap). Gate: survivors must be
|
|
7
|
+
// 0. Run: `node mutation-check.mjs`.
|
|
8
|
+
import { cpSync, mkdtempSync, readFileSync, writeFileSync, rmSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join, dirname } from "node:path";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
|
|
14
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const TARGET = "verify-shadow.mjs";
|
|
16
|
+
const SUITE = "verify-core.test.mjs";
|
|
17
|
+
|
|
18
|
+
// Each mutation: a UNIQUE substring in verify-shadow.mjs and the flipped version. Every one MUST be caught
|
|
19
|
+
// by at least one assertion in verify-core.test.mjs.
|
|
20
|
+
const MUTATIONS = [
|
|
21
|
+
// ---- detectCompletionClaim (incl. the negation/hedge guard, Fix 2) ----
|
|
22
|
+
{
|
|
23
|
+
fn: "detectCompletionClaim",
|
|
24
|
+
find: 'if (!CLAIM_RE.test(s)) return { claim: false, text: "" };',
|
|
25
|
+
replace: 'if (CLAIM_RE.test(s)) return { claim: false, text: "" };',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
fn: "detectCompletionClaim",
|
|
29
|
+
find: "if (!l || !CLAIM_RE.test(l)) continue;",
|
|
30
|
+
replace: "if (!l || CLAIM_RE.test(l)) continue;",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
fn: "detectCompletionClaim",
|
|
34
|
+
find: "if (NEGATION_RE.test(l)) continue; // negated/hedged → not a completion claim",
|
|
35
|
+
replace: "if (!NEGATION_RE.test(l)) continue; // negated/hedged → not a completion claim",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
fn: "detectCompletionClaim",
|
|
39
|
+
find: 'if (NEGATION_RE.test(s)) return { claim: false, text: "" };',
|
|
40
|
+
replace: 'if (!NEGATION_RE.test(s)) return { claim: false, text: "" };',
|
|
41
|
+
},
|
|
42
|
+
// ---- shipUrlPass (Fix 1: URL false-red safeguard) ----
|
|
43
|
+
{
|
|
44
|
+
fn: "shipUrlPass",
|
|
45
|
+
find: "if (urlResponded(ev1)) return true;",
|
|
46
|
+
replace: "if (urlResponded(ev1)) return false;",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
fn: "shipUrlPass",
|
|
50
|
+
find: " if (urlResponded(ev2)) return true;\n return false;",
|
|
51
|
+
replace: " if (urlResponded(ev2)) return true;\n return true;",
|
|
52
|
+
},
|
|
53
|
+
// ---- hasMutatingFlag (Fix 3: non-idempotent re-run guard) ----
|
|
54
|
+
{
|
|
55
|
+
fn: "hasMutatingFlag",
|
|
56
|
+
find: "if (a.some((x) => MUTATING_FLAG.test(String(x)))) return true;",
|
|
57
|
+
replace: "if (a.some((x) => MUTATING_FLAG.test(String(x)))) return false;",
|
|
58
|
+
},
|
|
59
|
+
// ---- classifyOutcome ----
|
|
60
|
+
{
|
|
61
|
+
fn: "classifyOutcome",
|
|
62
|
+
find: 'if (!err) return "PASS";',
|
|
63
|
+
replace: 'if (err) return "PASS";',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
fn: "classifyOutcome",
|
|
67
|
+
find: 'if (err.killed || err.signal === "SIGTERM") return "HARNESS_ERROR"; // hit the timeout',
|
|
68
|
+
replace: 'if (err.killed && err.signal === "SIGTERM") return "PASS"; // hit the timeout',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
fn: "classifyOutcome",
|
|
72
|
+
find: 'if (exit === 127 || exit === 126) return "HARNESS_ERROR"; // command not found / not executable',
|
|
73
|
+
replace:
|
|
74
|
+
'if (exit === 127 && exit === 126) return "HARNESS_ERROR"; // command not found / not executable',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
fn: "classifyOutcome",
|
|
78
|
+
find: 'return "GENUINE_FAIL"; // a real non-zero exit from the test/build/lint itself',
|
|
79
|
+
replace: 'return "HARNESS_ERROR"; // a real non-zero exit from the test/build/lint itself',
|
|
80
|
+
},
|
|
81
|
+
// ---- classifyConfirm (the flake-confirm state machine) ----
|
|
82
|
+
{
|
|
83
|
+
fn: "classifyConfirm",
|
|
84
|
+
find: 'const needsConfirm = firstOutcome === "GENUINE_FAIL";',
|
|
85
|
+
replace: 'const needsConfirm = firstOutcome !== "GENUINE_FAIL";',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
fn: "classifyConfirm",
|
|
89
|
+
find: 'const confirmedFail = needsConfirm && confirmOutcome === "GENUINE_FAIL";',
|
|
90
|
+
replace: 'const confirmedFail = needsConfirm || confirmOutcome === "GENUINE_FAIL";',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
fn: "classifyConfirm",
|
|
94
|
+
find: 'const confirmedFail = needsConfirm && confirmOutcome === "GENUINE_FAIL";',
|
|
95
|
+
replace: 'const confirmedFail = needsConfirm && confirmOutcome !== "GENUINE_FAIL";',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
fn: "classifyConfirm",
|
|
99
|
+
find: "const unconfirmedFail = needsConfirm && !confirmedFail;",
|
|
100
|
+
replace: "const unconfirmedFail = needsConfirm && confirmedFail;",
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
const workRoot = mkdtempSync(join(tmpdir(), "skalpel-mutants-"));
|
|
105
|
+
cpSync(HERE, join(workRoot, "src"), {
|
|
106
|
+
recursive: true,
|
|
107
|
+
filter: (s) => !s.includes("node_modules"),
|
|
108
|
+
});
|
|
109
|
+
const dir = join(workRoot, "src");
|
|
110
|
+
const targetPath = join(dir, TARGET);
|
|
111
|
+
const pristine = readFileSync(targetPath, "utf8");
|
|
112
|
+
|
|
113
|
+
function runSuite() {
|
|
114
|
+
const r = spawnSync("node", ["--test", SUITE], { cwd: dir, encoding: "utf8" });
|
|
115
|
+
return r.status; // 0 = suite passed (mutant SURVIVED); non-zero = suite failed (mutant KILLED)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Baseline: the pristine copy must pass, else the harness itself is broken.
|
|
119
|
+
if (runSuite() !== 0) {
|
|
120
|
+
console.error(
|
|
121
|
+
"BASELINE FAIL: verify-core.test.mjs does not pass on the pristine copy — aborting.",
|
|
122
|
+
);
|
|
123
|
+
process.exit(2);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let survivors = 0;
|
|
127
|
+
let missing = 0;
|
|
128
|
+
const results = [];
|
|
129
|
+
for (const m of MUTATIONS) {
|
|
130
|
+
const count = pristine.split(m.find).length - 1;
|
|
131
|
+
if (count !== 1) {
|
|
132
|
+
missing++;
|
|
133
|
+
results.push(` ✗ MUTATION TARGET NOT UNIQUE (${count}×) [${m.fn}] ${m.find.slice(0, 50)}…`);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
writeFileSync(targetPath, pristine.replace(m.find, m.replace));
|
|
137
|
+
const killed = runSuite() !== 0;
|
|
138
|
+
writeFileSync(targetPath, pristine); // restore
|
|
139
|
+
if (killed) {
|
|
140
|
+
results.push(` ✓ killed [${m.fn}] ${m.find.slice(0, 52)}…`);
|
|
141
|
+
} else {
|
|
142
|
+
survivors++;
|
|
143
|
+
results.push(` ☠ SURVIVED [${m.fn}] ${m.find.slice(0, 52)}…`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
rmSync(workRoot, { recursive: true, force: true });
|
|
148
|
+
console.log(results.join("\n"));
|
|
149
|
+
console.log(
|
|
150
|
+
`\nmutants: ${MUTATIONS.length} killed: ${MUTATIONS.length - survivors - missing} survivors: ${survivors} target-errors: ${missing}`,
|
|
151
|
+
);
|
|
152
|
+
if (survivors === 0 && missing === 0) {
|
|
153
|
+
console.log(
|
|
154
|
+
"MUTATION GATE: survivors = 0 on the critical + false-accusation-safeguard functions ✓",
|
|
155
|
+
);
|
|
156
|
+
process.exit(0);
|
|
157
|
+
}
|
|
158
|
+
process.exit(1);
|
package/package.json
CHANGED
package/skalpel-hook.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { homedir } from "node:os";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
import { identity } from "./auth.mjs";
|
|
15
15
|
import { record } from "./metrics.mjs";
|
|
16
|
-
import { recordInsight, cleanText,
|
|
16
|
+
import { recordInsight, cleanText, verifySpawnArmed } from "./insights.mjs";
|
|
17
17
|
import { graphReadyNote, verifyCatchNote } from "./reveal.mjs";
|
|
18
18
|
import { tailLines } from "./transcript.mjs";
|
|
19
19
|
|
|
@@ -510,13 +510,11 @@ async function main() {
|
|
|
510
510
|
// recent test/build/typecheck/lint command and RE-RUNs it out-of-band to log the real PASS/FAIL the
|
|
511
511
|
// agent can't forge. LOG ONLY — it writes nothing to this hook's stdout and never blocks the turn (the
|
|
512
512
|
// re-run, up to 60s, lives in a separate unref'd process). Wrapped so it can never affect the injection.
|
|
513
|
-
//
|
|
514
|
-
//
|
|
515
|
-
// the
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
payload.transcript_path
|
|
519
|
-
) {
|
|
513
|
+
// ARMING is resolved by the ONE shared resolver (verifySpawnArmed): the consented `verify:"on"` in
|
|
514
|
+
// client.json OR a dev env override (SKALPEL_VERIFY_SHADOW=1 / SKALPEL_VERIFY_REVEAL). When arming
|
|
515
|
+
// resolves OFF (the default for every existing install — env unset + config off/absent) this branch is
|
|
516
|
+
// skipped and the hook's stdout is byte-identical to before; the spawn is detached with stdio ignored.
|
|
517
|
+
if (verifySpawnArmed(process.env) && payload.transcript_path) {
|
|
520
518
|
try {
|
|
521
519
|
const { spawn } = await import("node:child_process");
|
|
522
520
|
const { fileURLToPath } = await import("node:url");
|
package/skalpel-setup.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import { fileURLToPath } from "node:url";
|
|
|
22
22
|
import { spawn, spawnSync } from "node:child_process";
|
|
23
23
|
import { identity as authIdentity, cliAuthPath } from "./auth.mjs";
|
|
24
24
|
import { isGenuineUserTurn } from "./session-turns.mjs";
|
|
25
|
+
import { appendAdjudication, suppressProof, lastReveal, parseArmToken } from "./insights.mjs";
|
|
25
26
|
|
|
26
27
|
// CLI (the `skalpel` bin): `skalpel setup [--api https://graph.skalpel.ai]
|
|
27
28
|
// [--user <id>]`, plus `skalpel uninstall` and `skalpel login`. A bare invocation
|
|
@@ -65,6 +66,9 @@ const KNOWN_SUBS = new Set([
|
|
|
65
66
|
"card",
|
|
66
67
|
"ledger",
|
|
67
68
|
"analytics",
|
|
69
|
+
"verify",
|
|
70
|
+
"yes",
|
|
71
|
+
"no",
|
|
68
72
|
"__build",
|
|
69
73
|
"__verify-report",
|
|
70
74
|
]);
|
|
@@ -83,6 +87,8 @@ usage:
|
|
|
83
87
|
skalpel card [--last|--id <id>] [--md] share one verified catch: the claim + its own failing proof
|
|
84
88
|
skalpel ledger your running tally: N "done"s checked, M verified FALSE
|
|
85
89
|
skalpel analytics interactive local analytics — caught lies, measured cost, steers, re-asks
|
|
90
|
+
skalpel verify on|off|status arm/disarm the live catch (re-runs your own proof on a "done" claim)
|
|
91
|
+
skalpel yes | skalpel no was the last catch right? (feeds precision; "no" stops that proof this session)
|
|
86
92
|
skalpel uninstall [--purge] remove the hooks + local data from this machine
|
|
87
93
|
|
|
88
94
|
options:
|
|
@@ -157,6 +163,84 @@ function fileCfg() {
|
|
|
157
163
|
}
|
|
158
164
|
const API = process.env.SKALPEL_API || apiFlag || fileCfg().api || DEFAULT_API;
|
|
159
165
|
|
|
166
|
+
// writeVerifyConfig(state) — persist the CONSENTED arming for the live catch to ~/.skalpel/client.json.
|
|
167
|
+
// state ∈ { "on", "off" }. On "on" we stamp verify_armed_at (a REAL timestamp) only if not already armed,
|
|
168
|
+
// so re-confirming never resets the honest "armed N days" clock; on "off" we clear it. This is the ONLY
|
|
169
|
+
// writer of the `verify` key; insights.mjs's resolver is the only reader — one key, no drift. Never throws.
|
|
170
|
+
function writeVerifyConfig(state) {
|
|
171
|
+
const cfgDir = join(homedir(), ".skalpel");
|
|
172
|
+
const cfgPath = join(cfgDir, "client.json");
|
|
173
|
+
let cfg = {};
|
|
174
|
+
try {
|
|
175
|
+
cfg = JSON.parse(readFileSync(cfgPath, "utf8")) || {};
|
|
176
|
+
} catch {
|
|
177
|
+
/* fresh config */
|
|
178
|
+
}
|
|
179
|
+
const wasOn = parseArmToken(cfg.verify) === true;
|
|
180
|
+
cfg.verify = state === "on" ? "on" : "off";
|
|
181
|
+
if (state === "on") {
|
|
182
|
+
if (!wasOn || !cfg.verify_armed_at) cfg.verify_armed_at = new Date().toISOString();
|
|
183
|
+
} else {
|
|
184
|
+
delete cfg.verify_armed_at;
|
|
185
|
+
}
|
|
186
|
+
mkdirSync(cfgDir, { recursive: true });
|
|
187
|
+
writeFileSync(cfgPath, JSON.stringify(cfg, null, 2));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// promptVerifyConsent() — the ONE honest consent line at setup. The prompt DEFAULTS TO THE EXISTING
|
|
191
|
+
// SETTING so a setup re-run never silently flips a deliberate choice: a user who ran `skalpel verify off`
|
|
192
|
+
// and re-runs setup + Enter STAYS OFF; unset/on defaults to on (the activation intent). Non-interactive /
|
|
193
|
+
// CI must NOT hang: no TTY → leave the config untouched and return. The copy is accurate, not hype: the
|
|
194
|
+
// re-run is only the session's OWN already-executed command (reconstructed from its Bash tool calls) —
|
|
195
|
+
// never a new class of side effect. Best-effort: never breaks setup.
|
|
196
|
+
// resolveConsentChoice(current, answerRaw) → "on" | "off". The prompt DEFAULTS TO THE EXISTING SETTING so
|
|
197
|
+
// an empty Enter never silently flips a deliberate choice: current "off" → stays off unless explicitly
|
|
198
|
+
// re-enabled (y/yes/on); current "on"/unset → the activation default, on unless declined (n/no/off).
|
|
199
|
+
export function resolveConsentChoice(current, answerRaw) {
|
|
200
|
+
const defaultOn = parseArmToken(current) !== false; // off → default off; on/unset → default on
|
|
201
|
+
const t = String(answerRaw || "")
|
|
202
|
+
.trim()
|
|
203
|
+
.toLowerCase();
|
|
204
|
+
if (defaultOn) return t === "n" || t === "no" || t === "off" ? "off" : "on";
|
|
205
|
+
return t === "y" || t === "yes" || t === "on" ? "on" : "off"; // stays off unless explicitly turned on
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function promptVerifyConsent() {
|
|
209
|
+
try {
|
|
210
|
+
const interactive = process.stdin.isTTY && process.stdout.isTTY && !process.env.CI;
|
|
211
|
+
if (!interactive || process.env.SKALPEL_DEMO || process.env.SKALPEL_SKIP_VERIFY_CONSENT === "1")
|
|
212
|
+
return; // CI / piped / demo → leave config untouched, never block
|
|
213
|
+
// Default the prompt to the EXISTING setting: off → Enter keeps off; on/unset → Enter accepts.
|
|
214
|
+
const current = fileCfg().verify; // "on" | "off" | undefined
|
|
215
|
+
const defaultOn = parseArmToken(current) !== false;
|
|
216
|
+
console.log(
|
|
217
|
+
` ${B}The live catch${X}\n` +
|
|
218
|
+
` ${D}When your agent says "done / tests pass", skalpel re-runs the SAME test/build command\n` +
|
|
219
|
+
` it just ran, in the same directory, and shows you the real result. It only ever re-runs\n` +
|
|
220
|
+
` your session's own command — never anything new.${X}`,
|
|
221
|
+
);
|
|
222
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
223
|
+
const promptLine = defaultOn ? `[Enter = on · n = off]` : `[Enter = keep off · y = on]`;
|
|
224
|
+
const ans = await new Promise((res) =>
|
|
225
|
+
rl.question(` ${B}${promptLine}${X} `, (a) => {
|
|
226
|
+
rl.close();
|
|
227
|
+
res(a);
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
// Resolve against the existing setting so an empty Enter preserves the current choice.
|
|
231
|
+
const choice = resolveConsentChoice(current, ans);
|
|
232
|
+
const on = choice === "on";
|
|
233
|
+
writeVerifyConfig(choice);
|
|
234
|
+
console.log(
|
|
235
|
+
on
|
|
236
|
+
? ` ${G}✓${X} ${D}Live catch on — it'll re-run your own proof and flag a false "done". ${X}skalpel verify off${D} anytime.${X}\n`
|
|
237
|
+
: ` ${D}Live catch off. Turn it on anytime with ${X}skalpel verify on${D}.${X}\n`,
|
|
238
|
+
);
|
|
239
|
+
} catch {
|
|
240
|
+
/* consent is best-effort — never break setup */
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
160
244
|
// who's signed in — the session saved by the login flow (~/.skalpel/auth.json). Its `uid` keys the
|
|
161
245
|
// hosted graph; `access_token` authenticates the upload. SKALPEL_USER overrides for dev (no token).
|
|
162
246
|
// Uses auth.mjs's REFRESH-CAPABLE identity() so a token that expired since login (Supabase tokens
|
|
@@ -933,6 +1017,66 @@ async function main() {
|
|
|
933
1017
|
spawnSync("node", [join(__dir, "verify-shadow.mjs"), "--xray"], { stdio: "inherit" });
|
|
934
1018
|
return;
|
|
935
1019
|
}
|
|
1020
|
+
// `skalpel verify on|off|status` — the one-command reverse for the live catch. Local, no network, no
|
|
1021
|
+
// sign-in. `on`/`off` persist the consented arming to client.json (the single writer); `status` (and a
|
|
1022
|
+
// bare `skalpel verify`) render the arming + FIELD-PROOF (real fires, adjudicated precision, armed-days,
|
|
1023
|
+
// auto-darken state) — all from real local rows.
|
|
1024
|
+
if (sub === "verify") {
|
|
1025
|
+
const action = (argv[1] || "status").toLowerCase();
|
|
1026
|
+
if (action === "on" || action === "off") {
|
|
1027
|
+
writeVerifyConfig(action);
|
|
1028
|
+
if (action === "on") {
|
|
1029
|
+
console.log(
|
|
1030
|
+
`\n ${G}✓${X} Live catch ${B}armed${X}. On a "done" claim, skalpel re-runs your session's own\n` +
|
|
1031
|
+
` test/build once (twice to confirm before any red) and shows the real result.\n` +
|
|
1032
|
+
` ${D}Reverse anytime: ${X}skalpel verify off${D} · see the field proof: ${X}skalpel verify status\n`,
|
|
1033
|
+
);
|
|
1034
|
+
} else {
|
|
1035
|
+
console.log(
|
|
1036
|
+
`\n ${G}✓${X} Live catch ${B}off${X}. ${D}Re-arm anytime: ${X}skalpel verify on\n`,
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
} else if (action === "status") {
|
|
1040
|
+
spawnSync("node", [join(__dir, "verify-shadow.mjs"), "--status"], { stdio: "inherit" });
|
|
1041
|
+
} else {
|
|
1042
|
+
console.error(`skalpel verify: unknown action \`${argv[1]}\` (use: on | off | status)`);
|
|
1043
|
+
process.exitCode = 2;
|
|
1044
|
+
}
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
// `skalpel yes` / `skalpel no` — ONE-KEY ADJUDICATION of the most-recent catch (the flight recorder).
|
|
1048
|
+
// Local, no network, no sign-in. Appends one NDJSON row keyed to the reveal you just saw; a "no" also
|
|
1049
|
+
// suppresses that exact proof for the rest of THAT session and counts against precision (feeding the
|
|
1050
|
+
// auto-darken kill-switch). Fail-open: nothing to adjudicate → an honest note, never an error.
|
|
1051
|
+
if (sub === "yes" || sub === "no") {
|
|
1052
|
+
const r = lastReveal();
|
|
1053
|
+
if (!r || !r.proof_command) {
|
|
1054
|
+
console.log(
|
|
1055
|
+
`\n ${D}No recent skalpel catch to adjudicate — nothing has surfaced yet.${X}\n` +
|
|
1056
|
+
` ${D}When skalpel flags a false "done", it'll say: was this right? ${X}skalpel yes / skalpel no\n`,
|
|
1057
|
+
);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
const proofShort = String(r.proof_command).slice(0, 60);
|
|
1061
|
+
appendAdjudication({
|
|
1062
|
+
verdict: sub, // "yes" | "no"
|
|
1063
|
+
reveal_ts: r.ts || null,
|
|
1064
|
+
session: r.session || null,
|
|
1065
|
+
proof: r.proof_command,
|
|
1066
|
+
});
|
|
1067
|
+
if (sub === "no") {
|
|
1068
|
+
suppressProof(r.session || null, r.proof_command);
|
|
1069
|
+
console.log(
|
|
1070
|
+
`\n ${G}✓${X} Marked ${B}not a real catch${X}. ${D}skalpel won't re-accuse ${X}\`${proofShort}\`${D}\n` +
|
|
1071
|
+
` for the rest of this session, and it counts against precision.${X}\n`,
|
|
1072
|
+
);
|
|
1073
|
+
} else {
|
|
1074
|
+
console.log(
|
|
1075
|
+
`\n ${G}✓${X} Marked ${B}a real catch${X}. ${D}Thanks — this counts toward precision.${X}\n`,
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
936
1080
|
// Persist --api/--user to ~/.skalpel/client.json so the hooks can read them without shell-env
|
|
937
1081
|
// plumbing (env vars SKALPEL_API / SKALPEL_USER still win at hook runtime).
|
|
938
1082
|
if (apiFlag || userFlag) {
|
|
@@ -971,6 +1115,10 @@ async function main() {
|
|
|
971
1115
|
` ${G}✓${X} Signed in as ${D}${id.name ? `${id.name} · ${id.email}` : id.email || id.uid}${X}\n`,
|
|
972
1116
|
);
|
|
973
1117
|
|
|
1118
|
+
// CONSENT for the live catch (default-accept). One honest line; persisted to client.json. Non-TTY/CI
|
|
1119
|
+
// never blocks (stays default OFF). Reversible anytime with `skalpel verify off`.
|
|
1120
|
+
await promptVerifyConsent();
|
|
1121
|
+
|
|
974
1122
|
// 2) find the real coding sessions in the last 30 days (the client reads; the server builds)
|
|
975
1123
|
const s1 = spinner(`Looking through your last ${LOOKBACK_DAYS} days of Claude Code + Codex…`);
|
|
976
1124
|
await sleep(500);
|
package/skalpel-statusline.mjs
CHANGED
|
@@ -30,7 +30,7 @@ import { readFileSync, rmSync } from "node:fs";
|
|
|
30
30
|
import { homedir } from "node:os";
|
|
31
31
|
import { join } from "node:path";
|
|
32
32
|
import { tailLines } from "./transcript.mjs";
|
|
33
|
-
import { cleanText, REVEAL_PATH, VERDICT_PATH, revealEnabled } from "./insights.mjs";
|
|
33
|
+
import { cleanText, REVEAL_PATH, VERDICT_PATH, revealEnabled, autoDarkened } from "./insights.mjs";
|
|
34
34
|
|
|
35
35
|
const CYAN = "\x1b[36m";
|
|
36
36
|
const GREEN = "\x1b[32m";
|
|
@@ -368,9 +368,23 @@ function main() {
|
|
|
368
368
|
// SKALPEL_VERIFY_REVEAL — when off (the default) this branch never runs and the bar is byte-identical to
|
|
369
369
|
// the always-on baseline below.
|
|
370
370
|
if (revealEnabled(process.env)) {
|
|
371
|
+
// AUTO-DARKEN kill-switch: once adjudicated precision drops below 90% over >= 10 `skalpel yes|no`
|
|
372
|
+
// rows, the LIVE red reveal self-pauses and the bar points at the retro `skalpel catches`
|
|
373
|
+
// (transcript-grounded — it can't flake) until the user re-arms. autoDarkened() is DERIVED from the
|
|
374
|
+
// real adjudication rows on every render (never a stored flag), so writer + reader can't drift.
|
|
375
|
+
if (autoDarkened()) {
|
|
376
|
+
process.stdout.write(
|
|
377
|
+
`${BOLD}skalpel${RESET} · ${DIM}live catch paused (precision <90%) · run: skalpel catches${RESET}`,
|
|
378
|
+
);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
371
381
|
const reveal = revealNote(payload.session_id);
|
|
372
382
|
if (reveal) {
|
|
373
|
-
|
|
383
|
+
// The red carries its one-key adjudication pointer — the flight recorder that feeds precision +
|
|
384
|
+
// the auto-darken kill-switch. A `skalpel no` also suppresses this exact proof for the session.
|
|
385
|
+
process.stdout.write(
|
|
386
|
+
`${BOLD}${reveal}${RESET} ${DIM}· was this right? skalpel yes / skalpel no${RESET}`,
|
|
387
|
+
);
|
|
374
388
|
return;
|
|
375
389
|
}
|
|
376
390
|
const verdict = verdictNote();
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// verify-core.test.mjs — pure-function unit tests for the three CRITICAL-LOGIC functions the mutation
|
|
2
|
+
// harness (mutation-check.mjs) targets: detectCompletionClaim, classifyOutcome, classifyConfirm. These
|
|
3
|
+
// are pure (no fs / no network), so they need no HOME isolation. Every assertion here must be tight enough
|
|
4
|
+
// that flipping a predicate/branch in the function under test makes at least one case fail (survivors = 0).
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import assert from "node:assert/strict";
|
|
7
|
+
import {
|
|
8
|
+
detectCompletionClaim,
|
|
9
|
+
classifyOutcome,
|
|
10
|
+
classifyConfirm,
|
|
11
|
+
hasMutatingFlag,
|
|
12
|
+
urlResponded,
|
|
13
|
+
shipUrlPass,
|
|
14
|
+
} from "./verify-shadow.mjs";
|
|
15
|
+
|
|
16
|
+
test("detectCompletionClaim — fires on real completion claims", () => {
|
|
17
|
+
for (const s of [
|
|
18
|
+
"All tests pass now.",
|
|
19
|
+
"I've fixed the bug.",
|
|
20
|
+
"Done — build is green.",
|
|
21
|
+
"lgtm",
|
|
22
|
+
"everything should work now",
|
|
23
|
+
"ready to merge",
|
|
24
|
+
]) {
|
|
25
|
+
assert.equal(detectCompletionClaim(s).claim, true, `should claim: ${s}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("detectCompletionClaim — does NOT fire on non-claims", () => {
|
|
30
|
+
for (const s of [
|
|
31
|
+
"Let me run the tests and see.",
|
|
32
|
+
"This might be broken.",
|
|
33
|
+
"Can you check whether it works?",
|
|
34
|
+
"",
|
|
35
|
+
" ",
|
|
36
|
+
]) {
|
|
37
|
+
assert.equal(detectCompletionClaim(s).claim, false, `should NOT claim: ${s}`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("detectCompletionClaim — returns the specific claim line, bounded to 120 chars", () => {
|
|
42
|
+
const r = detectCompletionClaim("Here is a summary.\nAll tests pass.\nMore prose.");
|
|
43
|
+
assert.equal(r.claim, true);
|
|
44
|
+
assert.equal(r.text, "All tests pass.");
|
|
45
|
+
const long = "x ".repeat(200) + "all tests pass";
|
|
46
|
+
assert.ok(detectCompletionClaim(long).text.length <= 120);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("classifyOutcome — no error is a PASS", () => {
|
|
50
|
+
assert.equal(classifyOutcome(null, ""), "PASS");
|
|
51
|
+
assert.equal(classifyOutcome(undefined, "anything"), "PASS");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("classifyOutcome — a real non-zero exit is a GENUINE_FAIL", () => {
|
|
55
|
+
assert.equal(classifyOutcome({ code: 1 }, "2 failed, 3 passed"), "GENUINE_FAIL");
|
|
56
|
+
assert.equal(
|
|
57
|
+
classifyOutcome({ code: 2 }, "AssertionError: expected 1 to equal 2"),
|
|
58
|
+
"GENUINE_FAIL",
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("classifyOutcome — broken harness is NEVER a lie (HARNESS_ERROR)", () => {
|
|
63
|
+
assert.equal(classifyOutcome({ killed: true, signal: "SIGTERM" }, "..."), "HARNESS_ERROR"); // timeout
|
|
64
|
+
assert.equal(classifyOutcome({ code: "ENOENT" }, "..."), "HARNESS_ERROR"); // missing binary/cwd
|
|
65
|
+
assert.equal(classifyOutcome({ code: 127 }, "..."), "HARNESS_ERROR"); // command not found
|
|
66
|
+
assert.equal(classifyOutcome({ code: 126 }, "..."), "HARNESS_ERROR"); // not executable
|
|
67
|
+
assert.equal(classifyOutcome({ code: 1 }, 'npm error Missing script: "test"'), "HARNESS_ERROR");
|
|
68
|
+
assert.equal(classifyOutcome({ code: 1 }, "bash: pytest: command not found"), "HARNESS_ERROR");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("classifyConfirm — 2/2 GENUINE_FAIL is the ONLY confirmed catch", () => {
|
|
72
|
+
const two = classifyConfirm("GENUINE_FAIL", "GENUINE_FAIL");
|
|
73
|
+
assert.deepEqual(two, { needsConfirm: true, confirmedFail: true, unconfirmedFail: false });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("classifyConfirm — a single un-reproduced fail is UNCONFIRMED (never a red)", () => {
|
|
77
|
+
for (const second of ["PASS", "HARNESS_ERROR", "REFUSED", null, undefined]) {
|
|
78
|
+
const r = classifyConfirm("GENUINE_FAIL", second);
|
|
79
|
+
assert.equal(r.needsConfirm, true, `needsConfirm for second=${second}`);
|
|
80
|
+
assert.equal(r.confirmedFail, false, `NOT confirmed for second=${second}`);
|
|
81
|
+
assert.equal(r.unconfirmedFail, true, `unconfirmed for second=${second}`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test("classifyConfirm — a non-fail first run needs no confirm and is never a catch", () => {
|
|
86
|
+
for (const first of ["PASS", "HARNESS_ERROR", "REFUSED"]) {
|
|
87
|
+
const r = classifyConfirm(first, "GENUINE_FAIL");
|
|
88
|
+
assert.deepEqual(
|
|
89
|
+
r,
|
|
90
|
+
{ needsConfirm: false, confirmedFail: false, unconfirmedFail: false },
|
|
91
|
+
`first=${first}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// ---- Fix 2: negation / hedge guard — a negated claim is NOT a completion claim ----
|
|
97
|
+
test("detectCompletionClaim — NEGATED / hedged lines are NOT completion claims (no self-contradicting red)", () => {
|
|
98
|
+
for (const s of [
|
|
99
|
+
"not done yet, still working on it",
|
|
100
|
+
"it isn't done",
|
|
101
|
+
"this isn't fixed",
|
|
102
|
+
"won't be fixed in this PR",
|
|
103
|
+
"not fixed yet",
|
|
104
|
+
"the tests are still failing",
|
|
105
|
+
"still broken, needs another pass",
|
|
106
|
+
"tests are still red",
|
|
107
|
+
"TODO: implement the parser",
|
|
108
|
+
"to-do: wire the handler",
|
|
109
|
+
"almost done",
|
|
110
|
+
"not quite passing yet",
|
|
111
|
+
"the build does not pass",
|
|
112
|
+
]) {
|
|
113
|
+
assert.equal(detectCompletionClaim(s).claim, false, `should NOT claim (negated): ${s}`);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("detectCompletionClaim — a genuine claim still fires even alongside a negated line", () => {
|
|
118
|
+
assert.equal(detectCompletionClaim("I've fixed the bug and it works now.").claim, true);
|
|
119
|
+
const r = detectCompletionClaim("The refactor is done.\nThe auth part is not done yet.");
|
|
120
|
+
assert.equal(r.claim, true);
|
|
121
|
+
assert.equal(r.text, "The refactor is done.", "picks the non-negated positive line");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ---- Fix 3: mutating-flag guard — a proof that rewrites files is refused ----
|
|
125
|
+
test("hasMutatingFlag — flags that REWRITE files are caught", () => {
|
|
126
|
+
for (const [cmd, args] of [
|
|
127
|
+
["eslint", ["--fix"]],
|
|
128
|
+
["eslint", ["src", "--fix"]],
|
|
129
|
+
["ruff", ["check", "--fix"]],
|
|
130
|
+
["ruff", ["format"]],
|
|
131
|
+
["ruff", ["format", "app.py"]],
|
|
132
|
+
["jest", ["-u"]],
|
|
133
|
+
["jest", ["--updateSnapshot"]],
|
|
134
|
+
["vitest", ["--update"]],
|
|
135
|
+
["vitest", ["-u"]],
|
|
136
|
+
["biome", ["check", "--write"]],
|
|
137
|
+
["prettier", ["--write", "."]],
|
|
138
|
+
]) {
|
|
139
|
+
assert.equal(hasMutatingFlag(cmd, args), true, `mutating: ${cmd} ${args.join(" ")}`);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("hasMutatingFlag — pure verify runs (and pnpm -w) are NOT mutating", () => {
|
|
144
|
+
for (const [cmd, args] of [
|
|
145
|
+
["eslint", ["."]],
|
|
146
|
+
["ruff", ["check"]],
|
|
147
|
+
["ruff", ["format", "--check"]],
|
|
148
|
+
["ruff", ["format", "--diff"]],
|
|
149
|
+
["jest", []],
|
|
150
|
+
["vitest", ["run"]],
|
|
151
|
+
["biome", ["check"]],
|
|
152
|
+
["pnpm", ["-w", "test"]], // -w = workspace-root, NOT write
|
|
153
|
+
["npm", ["test"]],
|
|
154
|
+
]) {
|
|
155
|
+
assert.equal(hasMutatingFlag(cmd, args), false, `NOT mutating: ${cmd} ${args.join(" ")}`);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// ---- Fix 1: SHIP-STATUS URL reachability — any HTTP status = live (never a red) ----
|
|
160
|
+
test("shipUrlPass — any HTTP status means REACHABLE/live → NO red", () => {
|
|
161
|
+
for (const code of [200, 301, 302, 401, 403, 404, 429, 500, 502, 503]) {
|
|
162
|
+
assert.equal(shipUrlPass(`http_code=${code}`, null), true, `HTTP ${code} → reachable (no red)`);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test("shipUrlPass — a red requires 2/2 NO-RESPONSE; a single transient blip does not", () => {
|
|
167
|
+
assert.equal(
|
|
168
|
+
shipUrlPass("curl error: timeout", "curl error: Could not resolve host"),
|
|
169
|
+
false,
|
|
170
|
+
"2/2 no-response → decisive unreachable (red)",
|
|
171
|
+
);
|
|
172
|
+
assert.equal(
|
|
173
|
+
shipUrlPass("curl error: timeout", "http_code=200"),
|
|
174
|
+
true,
|
|
175
|
+
"no-response then response → live (no red)",
|
|
176
|
+
);
|
|
177
|
+
assert.equal(shipUrlPass("no http code: 000", "no http code: 000"), false, "000 twice → red");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("urlResponded — http_code=<n> means the server answered; curl errors do not", () => {
|
|
181
|
+
assert.equal(urlResponded("http_code=503"), true);
|
|
182
|
+
assert.equal(urlResponded("http_code=200"), true);
|
|
183
|
+
assert.equal(urlResponded("curl error: timeout"), false);
|
|
184
|
+
assert.equal(urlResponded("no http code: 000"), false);
|
|
185
|
+
assert.equal(urlResponded(""), false);
|
|
186
|
+
});
|