oc-pilot 0.103.0 → 0.105.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.
@@ -0,0 +1,161 @@
1
+ import { collectChangedFiles } from "./diff.js";
2
+ import { PilotError } from "./errors.js";
3
+ import { runShellCommand } from "./command.js";
4
+ import { runGit } from "./git.js";
5
+ import { analyzeImpact } from "./impact.js";
6
+ import { detectTestCommand } from "./project.js";
7
+ import { createShadow, writeShadowDiff } from "./shadow.js";
8
+ const DEFAULT_TIMEOUT_MS = 180_000;
9
+ const MAX_OUTPUT = 5_000;
10
+ function cap(output) {
11
+ return output.length > MAX_OUTPUT ? output.slice(-MAX_OUTPUT) : output;
12
+ }
13
+ export function parseScalpelHypothesis(text) {
14
+ const start = text.indexOf("{");
15
+ const end = text.lastIndexOf("}");
16
+ if (start === -1 || end <= start)
17
+ return undefined;
18
+ let parsed;
19
+ try {
20
+ parsed = JSON.parse(text.slice(start, end + 1));
21
+ }
22
+ catch {
23
+ return undefined;
24
+ }
25
+ if (!parsed || typeof parsed !== "object")
26
+ return undefined;
27
+ const record = parsed;
28
+ const patch = typeof record.patch === "string" ? record.patch.trim() : "";
29
+ const reason = typeof record.reason === "string" ? record.reason.trim() : "";
30
+ if (!reason)
31
+ return undefined;
32
+ return { patch, reason };
33
+ }
34
+ export function buildScalpelPrompt(failure, currentDiff, context) {
35
+ const cappedFailure = failure.length > 40_000 ? failure.slice(-40_000) : failure;
36
+ const cappedDiff = currentDiff.length > 60_000 ? currentDiff.slice(0, 60_000) : currentDiff;
37
+ return [
38
+ "You are a surgeon. A test is failing, and the current diff is already applied on top of HEAD.",
39
+ "Produce the smallest unified diff that fixes the failure and applies on top of the current worktree.",
40
+ "Rules: no new dependencies, no deleting or skipping tests, no unrelated refactors, keep the public API unless the fix requires it, touch as few files as possible.",
41
+ "Return strict JSON only, with no markdown and no prose outside the object:",
42
+ '{"patch":"diff --git a/src/x.ts b/src/x.ts\\n...","reason":"why this is the minimal fix"}',
43
+ "If you cannot fix it minimally, return an empty patch and explain why.",
44
+ context ? `Extra context from the author:\n${context}` : "",
45
+ "",
46
+ "FAILURE:",
47
+ cappedFailure,
48
+ "",
49
+ "CURRENT DIFF:",
50
+ cappedDiff,
51
+ ]
52
+ .filter((line) => line.length > 0)
53
+ .join("\n");
54
+ }
55
+ function applyPatch(dir, patch, label) {
56
+ const temp = writeShadowDiff(patch);
57
+ try {
58
+ const check = runGit(["apply", "--check", temp.path], dir);
59
+ if (check.status !== 0) {
60
+ throw new PilotError(`${label}: патч не применился`, {
61
+ hint: check.stderr.trim() || check.stdout.trim() || undefined,
62
+ exitCode: 2,
63
+ });
64
+ }
65
+ const applied = runGit(["apply", temp.path], dir);
66
+ if (applied.status !== 0) {
67
+ throw new PilotError(`${label}: не удалось применить патч`, {
68
+ hint: applied.stderr.trim() || applied.stdout.trim() || undefined,
69
+ exitCode: 2,
70
+ });
71
+ }
72
+ }
73
+ finally {
74
+ temp.cleanup();
75
+ }
76
+ }
77
+ /** Applies the current diff plus the proposed fix in a shadow worktree and runs tests. */
78
+ export async function verifyScalpel(cwd, currentDiff, hypothesis, options = {}) {
79
+ const files = collectChangedFiles(hypothesis.patch).filter((path) => path !== "(unknown)" && path !== "(diff)");
80
+ if (!hypothesis.patch) {
81
+ return {
82
+ status: "rejected",
83
+ reason: hypothesis.reason,
84
+ patch: "",
85
+ files,
86
+ tests: "skipped",
87
+ summary: "[SCALPEL REJECTED]: модель не предложила патч.",
88
+ content: "",
89
+ };
90
+ }
91
+ const runTests = options.runTests !== false;
92
+ const testCommand = options.testCommand?.trim() || detectTestCommand(cwd)?.command;
93
+ if (runTests && !testCommand) {
94
+ return {
95
+ status: "unverified",
96
+ reason: hypothesis.reason,
97
+ patch: hypothesis.patch,
98
+ files,
99
+ tests: "skipped",
100
+ summary: "[SCALPEL UNVERIFIED]: не удалось определить тестовую команду.",
101
+ content: "",
102
+ };
103
+ }
104
+ const timeoutMs = Math.max(1_000, Math.min(900_000, options.timeoutMs ?? DEFAULT_TIMEOUT_MS));
105
+ const shadow = createShadow(cwd, "scalpel", "HEAD");
106
+ try {
107
+ if (currentDiff.trim())
108
+ applyPatch(shadow.dir, currentDiff, "Текущий diff");
109
+ applyPatch(shadow.dir, hypothesis.patch, "Патч scalpel");
110
+ let tests = "skipped";
111
+ let testOutput;
112
+ if (runTests && testCommand) {
113
+ const run = await runShellCommand(testCommand, shadow.dir, { timeoutMs });
114
+ tests = run.exitCode === 0 && !run.timedOut ? "pass" : "fail";
115
+ testOutput = cap(run.output);
116
+ }
117
+ const status = tests === "pass" ? "fixed" : tests === "fail" ? "rejected" : "unverified";
118
+ const summary = status === "fixed"
119
+ ? "[SCALPEL FIXED]: минимальный патч применён, тесты проходят."
120
+ : status === "rejected"
121
+ ? "[SCALPEL REJECTED]: патч не чинит тесты."
122
+ : "[SCALPEL UNVERIFIED]: патч применён, но тесты не запускались.";
123
+ const impact = analyzeImpact(cwd, hypothesis.patch, files);
124
+ const report = {
125
+ status,
126
+ reason: hypothesis.reason,
127
+ patch: hypothesis.patch,
128
+ files,
129
+ tests,
130
+ testOutput,
131
+ impact,
132
+ summary,
133
+ content: "",
134
+ };
135
+ report.content = renderScalpel(report);
136
+ return report;
137
+ }
138
+ finally {
139
+ shadow.cleanup();
140
+ }
141
+ }
142
+ export function renderScalpel(report) {
143
+ const lines = [
144
+ `Scalpel: ${report.status}`,
145
+ `Reason: ${report.reason}`,
146
+ `Files: ${String(report.files.length)}`,
147
+ ...report.files.map((file) => ` ${file}`),
148
+ `Tests: ${report.tests}`,
149
+ ];
150
+ if (report.testOutput)
151
+ lines.push("Output:", report.testOutput.trimEnd());
152
+ if (report.impact) {
153
+ lines.push(`Blast radius: ${String(report.impact.symbols.length)} symbol(s), ${String(report.impact.references.length)} reference(s)`);
154
+ for (const reference of report.impact.references.slice(0, 10)) {
155
+ lines.push(` ${reference.symbol} -> ${reference.file}:${String(reference.line)}`);
156
+ }
157
+ }
158
+ lines.push("", report.summary);
159
+ return `${lines.join("\n")}\n`;
160
+ }
161
+ //# sourceMappingURL=scalpel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalpel.js","sourceRoot":"","sources":["../../src/core/scalpel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,aAAa,EAAqB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA2B5D,MAAM,kBAAkB,GAAG,OAAO,CAAC;AACnC,MAAM,UAAU,GAAG,KAAK,CAAC;AAEzB,SAAS,GAAG,CAAC,MAAc;IACzB,OAAO,MAAM,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACzE,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,GAAG,IAAI,KAAK;QAAE,OAAO,SAAS,CAAC;IACnD,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,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CAAC,MAAM,EAAE;QAC3B,WAAW,MAAM,CAAC,MAAM,EAAE;QAC1B,UAAU,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;QACvC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;QAC1C,UAAU,MAAM,CAAC,KAAK,EAAE;KACzB,CAAC;IACF,IAAI,MAAM,CAAC,UAAU;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1E,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,iBAAiB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QACvI,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YAC9D,KAAK,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,OAAO,SAAS,CAAC,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrF,CAAC;IACH,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC"}
@@ -0,0 +1,132 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import { buildScalpelPrompt, parseScalpelHypothesis, renderScalpel, verifyScalpel, } from "./scalpel.js";
8
+ function git(args, cwd) {
9
+ const result = spawnSync("git", args, { cwd, encoding: "utf8" });
10
+ if (result.status !== 0)
11
+ throw new Error(`git ${args.join(" ")} failed: ${result.stderr}`);
12
+ return result.stdout;
13
+ }
14
+ function makeRepo(withTest = true) {
15
+ const dir = mkdtempSync(join(tmpdir(), "oc-pilot-scalpel-"));
16
+ git(["init", "-q"], dir);
17
+ git(["config", "user.email", "test@example.com"], dir);
18
+ git(["config", "user.name", "Test"], dir);
19
+ git(["config", "core.autocrlf", "false"], dir);
20
+ writeFileSync(join(dir, "app.mjs"), "export const value = 1;\n", "utf8");
21
+ if (withTest) {
22
+ writeFileSync(join(dir, "app.test.mjs"), [
23
+ 'import test from "node:test";',
24
+ 'import assert from "node:assert/strict";',
25
+ 'import { value } from "./app.mjs";',
26
+ 'test("value", () => { assert.equal(value, 2); });',
27
+ "",
28
+ ].join("\n"), "utf8");
29
+ }
30
+ git(["add", "."], dir);
31
+ git(["commit", "-m", "init"], dir);
32
+ return dir;
33
+ }
34
+ function patch(value) {
35
+ return [
36
+ "diff --git a/app.mjs b/app.mjs",
37
+ "--- a/app.mjs",
38
+ "+++ b/app.mjs",
39
+ "@@ -1,1 +1,1 @@",
40
+ "-export const value = 1;",
41
+ `+export const value = ${String(value)};`,
42
+ "",
43
+ ].join("\n");
44
+ }
45
+ test("parseScalpelHypothesis accepts JSON with a patch and a reason", () => {
46
+ const parsed = parseScalpelHypothesis('```json\n{"patch":"diff --git a/x b/x","reason":"fix"}\n```');
47
+ assert.deepEqual(parsed, { patch: "diff --git a/x b/x", reason: "fix" });
48
+ assert.equal(parseScalpelHypothesis("not json"), undefined);
49
+ assert.equal(parseScalpelHypothesis('{"patch":"x"}'), undefined);
50
+ assert.deepEqual(parseScalpelHypothesis('{"patch":"","reason":"cannot"}'), { patch: "", reason: "cannot" });
51
+ });
52
+ test("buildScalpelPrompt asks for a minimal patch and includes the failure", () => {
53
+ const prompt = buildScalpelPrompt("1 !== 2", "diff --git a/app.mjs b/app.mjs", "off by one");
54
+ assert.match(prompt, /smallest unified diff/);
55
+ assert.match(prompt, /strict JSON/);
56
+ assert.match(prompt, /1 !== 2/);
57
+ assert.match(prompt, /off by one/);
58
+ assert.match(prompt, /diff --git a\/app\.mjs/);
59
+ });
60
+ test("verifyScalpel accepts a minimal patch that makes the failing test pass", async () => {
61
+ const dir = makeRepo();
62
+ try {
63
+ const report = await verifyScalpel(dir, "", { patch: patch(2), reason: "value should be 2" }, { testCommand: "node --test app.test.mjs", timeoutMs: 20_000 });
64
+ assert.equal(report.status, "fixed", report.summary);
65
+ assert.equal(report.tests, "pass");
66
+ assert.match(report.summary, /\[SCALPEL FIXED\]/);
67
+ assert.ok(report.impact);
68
+ }
69
+ finally {
70
+ rmSync(dir, { recursive: true, force: true });
71
+ }
72
+ });
73
+ test("verifyScalpel rejects a patch that does not fix the test", async () => {
74
+ const dir = makeRepo();
75
+ try {
76
+ const report = await verifyScalpel(dir, "", { patch: patch(3), reason: "wrong value" }, { testCommand: "node --test app.test.mjs", timeoutMs: 20_000 });
77
+ assert.equal(report.status, "rejected");
78
+ assert.equal(report.tests, "fail");
79
+ assert.match(report.summary, /\[SCALPEL REJECTED\]/);
80
+ }
81
+ finally {
82
+ rmSync(dir, { recursive: true, force: true });
83
+ }
84
+ });
85
+ test("verifyScalpel applies the current diff before the fix", async () => {
86
+ const dir = makeRepo(false);
87
+ try {
88
+ writeFileSync(join(dir, "app.test.mjs"), [
89
+ 'import test from "node:test";',
90
+ 'import assert from "node:assert/strict";',
91
+ 'import { value } from "./app.mjs";',
92
+ 'test("value", () => { assert.equal(value, 2); });',
93
+ "",
94
+ ].join("\n"), "utf8");
95
+ git(["add", "-N", "app.test.mjs"], dir);
96
+ const currentDiff = git(["diff"], dir);
97
+ const report = await verifyScalpel(dir, currentDiff, { patch: patch(2), reason: "value should be 2" }, { testCommand: "node --test app.test.mjs", timeoutMs: 20_000 });
98
+ assert.equal(report.status, "fixed", report.summary);
99
+ }
100
+ finally {
101
+ rmSync(dir, { recursive: true, force: true });
102
+ }
103
+ });
104
+ test("verifyScalpel rejects an empty patch and reports an unverified fix without tests", async () => {
105
+ const dir = makeRepo();
106
+ try {
107
+ const empty = await verifyScalpel(dir, "", { patch: "", reason: "cannot fix" }, { timeoutMs: 20_000 });
108
+ assert.equal(empty.status, "rejected");
109
+ assert.match(empty.summary, /не предложила патч/);
110
+ const noTests = await verifyScalpel(dir, "", { patch: patch(2), reason: "fix" }, { runTests: false });
111
+ assert.equal(noTests.status, "unverified");
112
+ assert.match(noTests.summary, /\[SCALPEL UNVERIFIED\]/);
113
+ }
114
+ finally {
115
+ rmSync(dir, { recursive: true, force: true });
116
+ }
117
+ });
118
+ test("renderScalpel shows the reason, files, tests and blast radius", async () => {
119
+ const dir = makeRepo();
120
+ try {
121
+ const report = await verifyScalpel(dir, "", { patch: patch(2), reason: "value should be 2" }, { testCommand: "node --test app.test.mjs", timeoutMs: 20_000 });
122
+ const text = renderScalpel(report);
123
+ assert.match(text, /Scalpel: fixed/);
124
+ assert.match(text, /app\.mjs/);
125
+ assert.match(text, /Tests: pass/);
126
+ assert.match(text, /Blast radius/);
127
+ }
128
+ finally {
129
+ rmSync(dir, { recursive: true, force: true });
130
+ }
131
+ });
132
+ //# sourceMappingURL=scalpel.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalpel.test.js","sourceRoot":"","sources":["../../src/core/scalpel.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;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AAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,mBAAmB,EAAE,EAChD,EAAE,WAAW,EAAE,0BAA0B,EAAE,SAAS,EAAE,MAAM,EAAE,CAC/D,CAAC;QACF,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC/B,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACrC,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -59,6 +59,8 @@ test("MCP advertises prompts and renders them with arguments", () => {
59
59
  "split-the-diff",
60
60
  "check-the-criteria",
61
61
  "interrogate-the-intent",
62
+ "operate-with-a-scalpel",
63
+ "declare-mayday",
62
64
  "prune-senescent-code",
63
65
  "scan-for-injection",
64
66
  "compile-hologram",
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-prompts.test.js","sourceRoot":"","sources":["../src/mcp-prompts.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,GAAG,GAAG,OAAO,CAAC,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  },
1350
1350
  },
1351
1351
  },
1352
+ {
1353
+ name: "scalpel",
1354
+ description: "Given a failing test log and the current diff, ask the model for the smallest patch, apply the current diff plus the patch in a shadow worktree, run tests and report the blast radius. Model-backed; apply writes to the worktree and needs --allow-write.",
1355
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
1356
+ inputSchema: {
1357
+ type: "object",
1358
+ additionalProperties: false,
1359
+ properties: {
1360
+ log: { type: "string", description: "Captured failing test output" },
1361
+ error: { type: "string", description: "Error text instead of a log" },
1362
+ command: { type: "string", description: "Command that reproduces the failure" },
1363
+ context: { type: "string", description: "What the code is supposed to do" },
1364
+ apply: { type: "boolean", description: "Apply a verified patch to the worktree" },
1365
+ test_command: { type: "string", description: "Test command; defaults to detection" },
1366
+ test_timeout_ms: { type: "integer", minimum: 1000, maximum: 900000 },
1367
+ no_test: { type: "boolean", description: "Skip tests; result becomes unverified" },
1368
+ diff: { type: "string", description: "Unified diff text; omit to use the project's git diff" },
1369
+ base: { type: "string" },
1370
+ staged: { type: "boolean" },
1371
+ unstaged: { type: "boolean" },
1372
+ include_untracked: { type: "boolean" },
1373
+ ...RESULT_PROPERTIES,
1374
+ },
1375
+ },
1376
+ },
1377
+ {
1378
+ name: "mayday",
1379
+ description: "Incident response: bisect history to find the first bad commit, or prepare a tested rollback branch with git revert. bisect is read-only; rollback creates a branch, needs --allow-write and confirm=true.",
1380
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
1381
+ inputSchema: {
1382
+ type: "object",
1383
+ additionalProperties: false,
1384
+ required: ["action"],
1385
+ properties: {
1386
+ action: { type: "string", enum: ["bisect", "rollback"] },
1387
+ good: { type: "string", description: "Last known good ref for bisect" },
1388
+ bad: { type: "string", description: "Bad ref for bisect; default HEAD" },
1389
+ to: { type: "string", description: "Rollback target ref" },
1390
+ command: { type: "string", description: "Check command for bisect" },
1391
+ test_command: { type: "string", description: "Test command for rollback" },
1392
+ test_timeout_ms: { type: "integer", minimum: 1000, maximum: 900000 },
1393
+ max_steps: { type: "integer", minimum: 1, maximum: 64 },
1394
+ branch: { type: "string", description: "Rollback branch name" },
1395
+ confirm: { type: "boolean", description: "Required for rollback" },
1396
+ force: { type: "boolean", description: "Overwrite an existing branch" },
1397
+ no_test: { type: "boolean", description: "Skip tests for rollback" },
1398
+ ...RESULT_PROPERTIES,
1399
+ },
1400
+ },
1401
+ },
1352
1402
  {
1353
1403
  name: "apoptosis",
1354
1404
  description: "Scan functions marked /* @lifespan: 30d */ and report [Senescent] when the marker is older than the lifespan and the symbol has no references. With action=apply and confirm=true, comment the senescent functions out in a shadow git worktree, run tests and land the diff only if the suite is green. Apply writes files and needs --allow-write.",
@@ -1593,6 +1643,22 @@ const PROMPTS = [
1593
1643
  { name: "context", description: "What is already known", required: false },
1594
1644
  ],
1595
1645
  },
1646
+ {
1647
+ name: "operate-with-a-scalpel",
1648
+ title: "Fix a failure with the smallest patch",
1649
+ description: "Propose a minimal patch for a failing test, prove it in a shadow worktree and show the blast radius before applying anything.",
1650
+ arguments: [
1651
+ { name: "context", description: "What the code is supposed to do", required: false },
1652
+ ],
1653
+ },
1654
+ {
1655
+ name: "declare-mayday",
1656
+ title: "Find the bad commit and prepare a rollback",
1657
+ description: "Bisect history with a real check, identify the first bad commit and prepare a tested rollback branch without rewriting history.",
1658
+ arguments: [
1659
+ { name: "context", description: "What is broken in production", required: false },
1660
+ ],
1661
+ },
1596
1662
  {
1597
1663
  name: "prune-senescent-code",
1598
1664
  title: "Prune senescent AI code",
@@ -3696,6 +3762,88 @@ async function callIntent(input, cwd) {
3696
3762
  temp.cleanup();
3697
3763
  }
3698
3764
  }
3765
+ async function callScalpel(input, cwd) {
3766
+ const temp = new TempFiles();
3767
+ try {
3768
+ const args = ["scalpel", "--json"];
3769
+ const log = stringArg(input, "log");
3770
+ if (log)
3771
+ args.push("--log", log);
3772
+ const error = stringArg(input, "error");
3773
+ if (error)
3774
+ args.push("--error", error);
3775
+ const command = stringArg(input, "command");
3776
+ if (command)
3777
+ args.push("--command", command);
3778
+ const context = stringArg(input, "context");
3779
+ if (context)
3780
+ args.push("--context", context);
3781
+ if (booleanArg(input, "apply"))
3782
+ args.push("--apply");
3783
+ const testCommand = stringArg(input, "test_command");
3784
+ if (testCommand)
3785
+ args.push("--test-command", testCommand);
3786
+ const timeout = integerArg(input, "test_timeout_ms");
3787
+ if (timeout !== undefined)
3788
+ args.push("--test-timeout", String(Math.max(1, Math.round(timeout / 1000))) + "s");
3789
+ if (booleanArg(input, "no_test"))
3790
+ args.push("--no-test");
3791
+ const diff = stringArg(input, "diff");
3792
+ if (diff)
3793
+ args.push("--diff", temp.write("scalpel.diff", diff));
3794
+ const base = baseArg(input);
3795
+ if (base)
3796
+ args.push("--base", base);
3797
+ if (booleanArg(input, "staged"))
3798
+ args.push("--staged");
3799
+ if (booleanArg(input, "unstaged"))
3800
+ args.push("--unstaged");
3801
+ if (booleanArg(input, "include_untracked"))
3802
+ args.push("--include-untracked");
3803
+ return toToolResult(await runCli(args, cwd));
3804
+ }
3805
+ finally {
3806
+ temp.cleanup();
3807
+ }
3808
+ }
3809
+ async function callMayday(input, cwd) {
3810
+ const action = stringArg(input, "action", true);
3811
+ if (action === "rollback" && !booleanArg(input, "confirm")) {
3812
+ throw new ToolInputError("mayday rollback needs confirm=true");
3813
+ }
3814
+ const args = ["mayday", action, "--json"];
3815
+ const good = stringArg(input, "good");
3816
+ if (good)
3817
+ args.push("--good", good);
3818
+ const bad = stringArg(input, "bad");
3819
+ if (bad)
3820
+ args.push("--bad", bad);
3821
+ const to = stringArg(input, "to");
3822
+ if (to)
3823
+ args.push("--to", to);
3824
+ const command = stringArg(input, "command");
3825
+ if (command)
3826
+ args.push("--command", command);
3827
+ const testCommand = stringArg(input, "test_command");
3828
+ if (testCommand)
3829
+ args.push("--test-command", testCommand);
3830
+ const timeout = integerArg(input, "test_timeout_ms");
3831
+ if (timeout !== undefined)
3832
+ args.push("--test-timeout", String(Math.max(1, Math.round(timeout / 1000))) + "s");
3833
+ const maxSteps = integerArg(input, "max_steps");
3834
+ if (maxSteps !== undefined)
3835
+ args.push("--max-steps", String(maxSteps));
3836
+ const branch = stringArg(input, "branch");
3837
+ if (branch)
3838
+ args.push("--branch", branch);
3839
+ if (action === "rollback")
3840
+ args.push("--confirm");
3841
+ if (booleanArg(input, "force"))
3842
+ args.push("--force");
3843
+ if (booleanArg(input, "no_test"))
3844
+ args.push("--no-test");
3845
+ return toToolResult(await runCli(args, cwd));
3846
+ }
3699
3847
  async function callApoptosis(input, cwd) {
3700
3848
  const action = stringArg(input, "action") ?? "scan";
3701
3849
  const args = ["apoptosis", action, "--json"];
@@ -3920,6 +4068,12 @@ async function dispatchTool(name, input, cwd, readOnly) {
3920
4068
  if (name === "mitosis" && stringArg(input, "action") === "apply") {
3921
4069
  throw new ToolInputError("mitosis apply creates commits and a branch and is disabled in read-only mode; start the MCP server with --allow-write");
3922
4070
  }
4071
+ if (name === "scalpel" && booleanArg(input, "apply")) {
4072
+ throw new ToolInputError("scalpel apply writes to the worktree and is disabled in read-only mode; start the MCP server with --allow-write");
4073
+ }
4074
+ if (name === "mayday" && stringArg(input, "action") === "rollback") {
4075
+ throw new ToolInputError("mayday rollback creates a branch and is disabled in read-only mode; start the MCP server with --allow-write");
4076
+ }
3923
4077
  if (name === "honeypot" && (stringArg(input, "action") === "deploy" || stringArg(input, "action") === "remove")) {
3924
4078
  throw new ToolInputError("honeypot deploy/remove writes files and is disabled in read-only mode; start the MCP server with --allow-write");
3925
4079
  }
@@ -4045,6 +4199,10 @@ async function dispatchTool(name, input, cwd, readOnly) {
4045
4199
  return callMitosis(input, cwd);
4046
4200
  case "intent":
4047
4201
  return callIntent(input, cwd);
4202
+ case "scalpel":
4203
+ return callScalpel(input, cwd);
4204
+ case "mayday":
4205
+ return callMayday(input, cwd);
4048
4206
  case "apoptosis":
4049
4207
  return callApoptosis(input, cwd);
4050
4208
  case "scan_injection":
@@ -4124,6 +4282,21 @@ function summarizeResult(value) {
4124
4282
  if (typeof value.status === "string" && Array.isArray(value.removed) && typeof value.summary === "string") {
4125
4283
  return `oc-pilot: apoptosis ${value.status}, ${String(value.removed.length)} removed`;
4126
4284
  }
4285
+ if (typeof value.status === "string" && Array.isArray(value.steps) && typeof value.good === "string") {
4286
+ const first = value.firstBad && typeof value.firstBad === "object"
4287
+ ? value.firstBad.sha
4288
+ : undefined;
4289
+ return `oc-pilot: mayday bisect ${value.status}${typeof first === "string" ? `, first bad ${first.slice(0, 8)}` : ""}`;
4290
+ }
4291
+ if (typeof value.status === "string" && typeof value.reverted === "number" && typeof value.to === "string") {
4292
+ return `oc-pilot: mayday rollback ${value.status}, ${String(value.reverted)} reverted`;
4293
+ }
4294
+ if (typeof value.status === "string" &&
4295
+ ["fixed", "rejected", "unverified", "error"].includes(value.status) &&
4296
+ Array.isArray(value.files) &&
4297
+ typeof value.tests === "string") {
4298
+ return `oc-pilot: scalpel ${value.status}, ${String(value.files.length)} file(s), tests ${value.tests}`;
4299
+ }
4127
4300
  if (typeof value.status === "string" && Array.isArray(value.results) && value.counts && typeof value.counts === "object") {
4128
4301
  const counts = value.counts;
4129
4302
  return `oc-pilot: intent ${value.status}, ${String(counts.unmet ?? 0)} unmet`;
@@ -4436,6 +4609,10 @@ function promptBody(name, args) {
4436
4609
  return `Call the oc-pilot "skeptic" tool on the proposed diff. Read the hypothesis reason and the exact status. If it returns bug, stop and quote the failing test output: the generated test fails on the diff and passes on HEAD, so the change is falsified. Fix the code or the test expectation, then rerun; do not delete the test, do not weaken the assertion and do not claim a bug from a test that also fails on HEAD. If it returns clean, say that the hypothesis was rejected, not that the code is proven correct. If it returns unfalsifiable, explain that the test did not distinguish the diff from HEAD. If it returns error, report the infrastructure failure instead of guessing.${suffix}`;
4437
4610
  case "stamp-the-passport":
4438
4611
  return `Call the oc-pilot "passport" tool with action=write after the checks you actually ran, then action=verify. Record only real checks as name=pass|warn|fail|skip, the real agent/model and the commit. If verify returns [PASSPORT STALE] or [PASSPORT TAMPERED], stop: the manifest no longer matches the tree; rewrite it from the current state or investigate the change. Never mark a check as pass without running it, never edit the manifest by hand to hide a mismatch, and never claim that a passport proves correctness: it proves what was recorded and that the files still match. write/clear need --allow-write.${suffix}`;
4612
+ case "declare-mayday":
4613
+ return `Call the oc-pilot "mayday" tool with action=bisect and the last good/bad refs plus the check command. Read the first bad commit and its diff. Then call action=rollback with confirm=true and the good ref to create a tested rollback branch. Do not reset --hard, do not force-push, do not rewrite history, and do not claim the rollback is safe if tests were skipped or failed. Tell humans exactly which commits will be reverted. rollback needs --allow-write.${suffix}`;
4614
+ case "operate-with-a-scalpel":
4615
+ return `Call the oc-pilot "scalpel" tool with the failing log, or a command that reproduces it, and the proposed diff. Read the patch and the blast radius. If it returns [SCALPEL FIXED], review the patch and apply it only with explicit approval. If it returns [SCALPEL REJECTED], do not apply it and do not weaken the test. If it returns [SCALPEL UNVERIFIED], run the tests yourself before claiming a fix. Never delete a failing test, never skip it, and never let the patch touch unrelated files. apply needs --allow-write.${suffix}`;
4439
4616
  case "check-the-criteria":
4440
4617
  return `Call the oc-pilot "intent" tool with action=check and the acceptance criteria for this change. Read every criterion as met, partial, unmet or unverifiable. If any is unmet, stop and quote the criterion and the evidence: the diff does not do what was promised. Fix the code or the criterion, never mark it met without evidence. Partial is not done, and unverifiable means the diff cannot prove it. Model-backed and read-only.${suffix}`;
4441
4618
  case "interrogate-the-intent":