oc-pilot 0.101.0 → 0.102.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,256 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { runShellCommand } from "./command.js";
4
+ import { splitDiffBlocks } from "./diff.js";
5
+ import { PilotError } from "./errors.js";
6
+ import { runGit } from "./git.js";
7
+ import { detectTestCommand } from "./project.js";
8
+ import { createShadow } from "./shadow.js";
9
+ import { isTestFile } from "./slop/source.js";
10
+ const MAX_OUTPUT = 4_000;
11
+ const DEFAULT_MAX_FILES = 20;
12
+ function cap(output) {
13
+ return output.length > MAX_OUTPUT ? output.slice(-MAX_OUTPUT) : output;
14
+ }
15
+ function isDoc(path) {
16
+ return /^(?:docs\/|readme|changelog|contributing|license)/i.test(path) || /\.(?:md|mdx|rst)$/i.test(path);
17
+ }
18
+ function isManifest(path) {
19
+ return (/(?:^|\/)(?:package\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?|tsconfig[^/]*\.json|Cargo\.toml|Cargo\.lock|go\.mod|go\.sum|requirements[^/]*\.txt|pyproject\.toml|Gemfile|Gemfile\.lock|Dockerfile|Makefile|\.github\/)/i.test(path) || /\.config\.[^/]+$/i.test(path));
20
+ }
21
+ function typeKey(path) {
22
+ if (isManifest(path))
23
+ return "config";
24
+ if (isDoc(path))
25
+ return "docs";
26
+ if (isTestFile(path))
27
+ return "tests";
28
+ return "source";
29
+ }
30
+ function dirKey(path) {
31
+ const parts = path.split("/");
32
+ if (parts.length === 1)
33
+ return `root/${typeKey(path)}`;
34
+ if (parts[0] === "src" && parts.length >= 3)
35
+ return `src/${parts[1]}`;
36
+ if (parts[0] === "packages" && parts.length >= 3)
37
+ return `packages/${parts[1]}`;
38
+ return parts[0];
39
+ }
40
+ function statsOf(text) {
41
+ let additions = 0;
42
+ let deletions = 0;
43
+ for (const raw of text.split(/\r?\n/)) {
44
+ if (raw.startsWith("+++") || raw.startsWith("---"))
45
+ continue;
46
+ if (raw.startsWith("+"))
47
+ additions += 1;
48
+ else if (raw.startsWith("-"))
49
+ deletions += 1;
50
+ }
51
+ return { additions, deletions };
52
+ }
53
+ function groupTitle(strategy, key, count, prefix) {
54
+ if (strategy === "file")
55
+ return `${prefix}: update ${key}`;
56
+ if (strategy === "type")
57
+ return `${prefix}: update ${key} (${String(count)} file(s))`;
58
+ return `${prefix}: update ${key} (${String(count)} file(s))`;
59
+ }
60
+ function groupRank(strategy, key) {
61
+ if (strategy !== "type")
62
+ return 0;
63
+ return key === "config" ? 0 : key === "source" ? 1 : key === "tests" ? 2 : 3;
64
+ }
65
+ /** Splits a unified diff into reviewable, independently applicable commits. */
66
+ export function buildMitosisPlan(diff, options = {}) {
67
+ const strategy = options.strategy ?? "dir";
68
+ const prefix = options.prefix?.trim() || "mitosis";
69
+ const maxFiles = Math.max(1, Math.min(500, options.maxFiles ?? DEFAULT_MAX_FILES));
70
+ const blocks = splitDiffBlocks(diff).filter((block) => block.path !== "(unknown)" && block.path !== "(diff)");
71
+ const groups = new Map();
72
+ for (const block of blocks) {
73
+ const key = strategy === "file" ? block.path : strategy === "dir" ? dirKey(block.path) : typeKey(block.path);
74
+ const group = groups.get(key) ?? { key, blocks: [] };
75
+ group.blocks.push(block);
76
+ groups.set(key, group);
77
+ }
78
+ const ordered = [...groups.values()].sort((left, right) => groupRank(strategy, left.key) - groupRank(strategy, right.key) ||
79
+ left.key.localeCompare(right.key));
80
+ const commits = [];
81
+ for (const group of ordered) {
82
+ const sorted = [...group.blocks].sort((left, right) => left.path.localeCompare(right.path));
83
+ const chunks = [];
84
+ for (let index = 0; index < sorted.length; index += maxFiles) {
85
+ chunks.push(sorted.slice(index, index + maxFiles));
86
+ }
87
+ for (const [chunkIndex, chunk] of chunks.entries()) {
88
+ const files = chunk.map((block) => block.path);
89
+ const patch = chunk.map((block) => block.text).join("\n") + "\n";
90
+ const stats = statsOf(patch);
91
+ const baseTitle = groupTitle(strategy, group.key, chunk.length, prefix);
92
+ const title = chunks.length > 1 ? `${baseTitle} [${String(chunkIndex + 1)}/${String(chunks.length)}]` : baseTitle;
93
+ commits.push({
94
+ index: commits.length + 1,
95
+ title,
96
+ files,
97
+ patch,
98
+ additions: stats.additions,
99
+ deletions: stats.deletions,
100
+ });
101
+ }
102
+ }
103
+ const plan = {
104
+ strategy,
105
+ commits,
106
+ files: blocks.length,
107
+ additions: commits.reduce((sum, commit) => sum + commit.additions, 0),
108
+ deletions: commits.reduce((sum, commit) => sum + commit.deletions, 0),
109
+ content: "",
110
+ };
111
+ plan.content = renderMitosisPlan(plan);
112
+ return plan;
113
+ }
114
+ export function renderMitosisPlan(plan) {
115
+ const lines = [
116
+ `Mitosis plan: ${String(plan.commits.length)} commit(s), ${String(plan.files)} file(s), +${String(plan.additions)}/-${String(plan.deletions)}`,
117
+ `Strategy: ${plan.strategy}`,
118
+ "",
119
+ ];
120
+ for (const commit of plan.commits) {
121
+ lines.push(`${String(commit.index)}. ${commit.title} (${String(commit.files.length)} file(s), +${String(commit.additions)}/-${String(commit.deletions)})`);
122
+ for (const file of commit.files)
123
+ lines.push(` ${file}`);
124
+ }
125
+ return `${lines.join("\n")}\n`;
126
+ }
127
+ export function renderMitosisPlanMarkdown(plan) {
128
+ const lines = [
129
+ "## oc-pilot mitosis plan",
130
+ "",
131
+ `- **Commits:** ${String(plan.commits.length)}`,
132
+ `- **Files:** ${String(plan.files)}`,
133
+ `- **Changes:** +${String(plan.additions)}/-${String(plan.deletions)}`,
134
+ `- **Strategy:** ${plan.strategy}`,
135
+ "",
136
+ ];
137
+ for (const commit of plan.commits) {
138
+ lines.push(`### ${String(commit.index)}. ${commit.title}`, "");
139
+ lines.push(`+${String(commit.additions)}/-${String(commit.deletions)}`, "");
140
+ for (const file of commit.files)
141
+ lines.push(`- \`${file}\``);
142
+ lines.push("");
143
+ }
144
+ return `${lines.join("\n")}\n`;
145
+ }
146
+ function slug(value) {
147
+ return (value
148
+ .toLowerCase()
149
+ .replace(/[^a-z0-9]+/g, "-")
150
+ .replace(/^-+|-+$/g, "")
151
+ .slice(0, 40) || "commit");
152
+ }
153
+ function timestamp() {
154
+ return new Date().toISOString().replace(/[-:]/g, "").replace("T", "-").slice(0, 15);
155
+ }
156
+ function branchExists(cwd, branch) {
157
+ return runGit(["rev-parse", "--verify", `refs/heads/${branch}`], cwd).status === 0;
158
+ }
159
+ /** Applies the plan as a sequence of commits in a shadow worktree and exposes a branch. */
160
+ export async function applyMitosis(cwd, diff, options = {}) {
161
+ const plan = buildMitosisPlan(diff, options);
162
+ const branch = options.branch?.trim() || `oc-pilot/mitosis-${timestamp()}`;
163
+ if (branchExists(cwd, branch) && !options.force) {
164
+ throw new PilotError(`Ветка уже существует: ${branch}`, {
165
+ hint: "Укажите другую --branch или добавьте --force.",
166
+ exitCode: 2,
167
+ });
168
+ }
169
+ const testCommand = options.testCommand?.trim() || detectTestCommand(cwd)?.command;
170
+ const runTests = options.runTests !== false && Boolean(testCommand);
171
+ const timeoutMs = Math.max(1_000, Math.min(1_800_000, options.timeoutMs ?? 300_000));
172
+ const shadow = createShadow(cwd, "mitosis-worktree", "HEAD");
173
+ const patchDir = join(cwd, ".oc-pilot", "mitosis");
174
+ mkdirSync(patchDir, { recursive: true });
175
+ const applied = [];
176
+ try {
177
+ for (const commit of plan.commits) {
178
+ const patchFile = join(patchDir, `${String(commit.index).padStart(2, "0")}-${slug(commit.title)}.patch`);
179
+ writeFileSync(patchFile, commit.patch, "utf8");
180
+ const check = runGit(["apply", "--check", patchFile], shadow.dir);
181
+ if (check.status !== 0) {
182
+ throw new PilotError(`Патч ${String(commit.index)} не применился`, {
183
+ hint: check.stderr.trim() || check.stdout.trim() || undefined,
184
+ exitCode: 2,
185
+ });
186
+ }
187
+ const apply = runGit(["apply", patchFile], shadow.dir);
188
+ if (apply.status !== 0) {
189
+ throw new PilotError(`Не удалось применить патч ${String(commit.index)}`, {
190
+ hint: apply.stderr.trim() || apply.stdout.trim() || undefined,
191
+ exitCode: 2,
192
+ });
193
+ }
194
+ runGit(["add", "-A"], shadow.dir);
195
+ const result = runGit(["commit", "-m", commit.title], shadow.dir);
196
+ if (result.status !== 0) {
197
+ throw new PilotError("Не удалось создать коммит в shadow worktree", {
198
+ hint: result.stderr.trim() || "Проверьте git user.name и user.email.",
199
+ exitCode: 2,
200
+ });
201
+ }
202
+ const sha = runGit(["rev-parse", "HEAD"], shadow.dir).stdout.trim();
203
+ let tests = "skipped";
204
+ let output;
205
+ if (runTests && testCommand) {
206
+ const run = await runShellCommand(testCommand, shadow.dir, { timeoutMs });
207
+ tests = run.exitCode === 0 && !run.timedOut ? "pass" : "fail";
208
+ output = cap(run.output);
209
+ }
210
+ applied.push({ sha, title: commit.title, files: commit.files, tests, output, patchFile });
211
+ if (tests === "fail")
212
+ break;
213
+ }
214
+ const last = applied[applied.length - 1];
215
+ if (last) {
216
+ const branchArgs = options.force
217
+ ? ["branch", "-f", branch, last.sha]
218
+ : ["branch", branch, last.sha];
219
+ const branchResult = runGit(branchArgs, cwd);
220
+ if (branchResult.status !== 0) {
221
+ throw new PilotError(`Не удалось создать ветку ${branch}`, {
222
+ hint: branchResult.stderr.trim() || undefined,
223
+ exitCode: 2,
224
+ });
225
+ }
226
+ }
227
+ const failed = applied.some((commit) => commit.tests === "fail");
228
+ const status = failed ? "failed" : "applied";
229
+ const summary = failed
230
+ ? `[MITOSIS FAILED]: тесты упали на коммите ${String(applied.findIndex((commit) => commit.tests === "fail") + 1)} из ${String(plan.commits.length)}.`
231
+ : `[MITOSIS APPLIED]: ${String(applied.length)} коммитов в ветке ${branch}.`;
232
+ const lines = [
233
+ `Mitosis: ${status}`,
234
+ `Branch: ${branch}`,
235
+ `Commits: ${String(applied.length)} из ${String(plan.commits.length)}`,
236
+ runTests ? `Tests: ${testCommand}` : "Tests: skipped",
237
+ ];
238
+ for (const commit of applied) {
239
+ lines.push(` ${commit.sha.slice(0, 8)} [${commit.tests}] ${commit.title}`);
240
+ if (commit.tests === "fail" && commit.output)
241
+ lines.push(` ${commit.output.trimEnd()}`);
242
+ }
243
+ lines.push("", summary);
244
+ return {
245
+ status,
246
+ branch,
247
+ commits: applied,
248
+ summary,
249
+ content: `${lines.join("\n")}\n`,
250
+ };
251
+ }
252
+ finally {
253
+ shadow.cleanup();
254
+ }
255
+ }
256
+ //# sourceMappingURL=mitosis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mitosis.js","sourceRoot":"","sources":["../../src/core/mitosis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAkB,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAuD9C,MAAM,UAAU,GAAG,KAAK,CAAC;AACzB,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,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,SAAS,KAAK,CAAC,IAAY;IACzB,OAAO,oDAAoD,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5G,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,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spawnSync } from "node:child_process";
3
+ import { existsSync, 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 { applyMitosis, buildMitosisPlan, renderMitosisPlan, renderMitosisPlanMarkdown, } from "./mitosis.js";
8
+ const PLAN_DIFF = [
9
+ "diff --git a/package.json b/package.json",
10
+ "--- a/package.json",
11
+ "+++ b/package.json",
12
+ "@@ -1,1 +1,2 @@",
13
+ " {",
14
+ '+ "zod": "^3.23.8",',
15
+ "diff --git a/src/core/a.ts b/src/core/a.ts",
16
+ "--- a/src/core/a.ts",
17
+ "+++ b/src/core/a.ts",
18
+ "@@ -1,1 +1,2 @@",
19
+ " export const a = 1;",
20
+ "+export const aa = 2;",
21
+ "diff --git a/src/core/b.ts b/src/core/b.ts",
22
+ "--- a/src/core/b.ts",
23
+ "+++ b/src/core/b.ts",
24
+ "@@ -1,1 +1,2 @@",
25
+ " export const b = 1;",
26
+ "+export const bb = 2;",
27
+ "diff --git a/src/core/a.test.ts b/src/core/a.test.ts",
28
+ "new file mode 100644",
29
+ "--- /dev/null",
30
+ "+++ b/src/core/a.test.ts",
31
+ "@@ -0,0 +1,1 @@",
32
+ '+test("a", () => {});',
33
+ "diff --git a/README.md b/README.md",
34
+ "--- a/README.md",
35
+ "+++ b/README.md",
36
+ "@@ -1,1 +1,2 @@",
37
+ " # Title",
38
+ "+More docs.",
39
+ "",
40
+ ].join("\n");
41
+ function git(args, cwd) {
42
+ const result = spawnSync("git", args, { cwd, encoding: "utf8" });
43
+ if (result.status !== 0)
44
+ throw new Error(`git ${args.join(" ")} failed: ${result.stderr}`);
45
+ return result.stdout;
46
+ }
47
+ function makeRepo() {
48
+ const dir = mkdtempSync(join(tmpdir(), "oc-pilot-mitosis-"));
49
+ git(["init", "-q"], dir);
50
+ git(["config", "user.email", "test@example.com"], dir);
51
+ git(["config", "user.name", "Test"], dir);
52
+ git(["config", "core.autocrlf", "false"], dir);
53
+ writeFileSync(join(dir, "a.txt"), "one\n", "utf8");
54
+ writeFileSync(join(dir, "b.txt"), "one\n", "utf8");
55
+ git(["add", "."], dir);
56
+ git(["commit", "-m", "init"], dir);
57
+ writeFileSync(join(dir, "a.txt"), "two\n", "utf8");
58
+ writeFileSync(join(dir, "b.txt"), "two\n", "utf8");
59
+ return { dir, diff: git(["diff"], dir) };
60
+ }
61
+ test("buildMitosisPlan groups by directory with config and docs apart", () => {
62
+ const plan = buildMitosisPlan(PLAN_DIFF, { strategy: "dir" });
63
+ assert.equal(plan.files, 5);
64
+ assert.equal(plan.commits.length, 3);
65
+ assert.deepEqual(plan.commits.map((commit) => commit.files), [["package.json"], ["README.md"], ["src/core/a.test.ts", "src/core/a.ts", "src/core/b.ts"]]);
66
+ assert.match(plan.commits[2]?.title ?? "", /src\/core/);
67
+ assert.equal(plan.additions, 5);
68
+ assert.equal(plan.deletions, 0);
69
+ });
70
+ test("buildMitosisPlan supports file and type strategies and max-files chunks", () => {
71
+ const byFile = buildMitosisPlan(PLAN_DIFF, { strategy: "file" });
72
+ assert.equal(byFile.commits.length, 5);
73
+ assert.ok(byFile.commits.every((commit) => commit.files.length === 1));
74
+ const byType = buildMitosisPlan(PLAN_DIFF, { strategy: "type" });
75
+ assert.deepEqual(byType.commits.map((commit) => commit.files), [["package.json"], ["src/core/a.ts", "src/core/b.ts"], ["src/core/a.test.ts"], ["README.md"]]);
76
+ const chunked = buildMitosisPlan(PLAN_DIFF, { strategy: "dir", maxFiles: 2 });
77
+ const core = chunked.commits.filter((commit) => commit.files.some((file) => file.startsWith("src/core")));
78
+ assert.equal(core.length, 2);
79
+ assert.match(core[0]?.title ?? "", /\[1\/2\]/);
80
+ assert.match(core[1]?.title ?? "", /\[2\/2\]/);
81
+ });
82
+ test("renderMitosisPlan and renderMitosisPlanMarkdown show commits and files", () => {
83
+ const plan = buildMitosisPlan(PLAN_DIFF, { strategy: "type" });
84
+ const text = renderMitosisPlan(plan);
85
+ assert.match(text, /Mitosis plan: 4 commit/);
86
+ assert.match(text, /package\.json/);
87
+ assert.match(text, /README\.md/);
88
+ const markdown = renderMitosisPlanMarkdown(plan);
89
+ assert.match(markdown, /## oc-pilot mitosis plan/);
90
+ assert.match(markdown, /`src\/core\/a\.ts`/);
91
+ });
92
+ test("applyMitosis creates a branch with one commit per file and patch files", async () => {
93
+ const repo = makeRepo();
94
+ try {
95
+ const result = await applyMitosis(repo.dir, repo.diff, {
96
+ strategy: "file",
97
+ branch: "oc-pilot/mitosis-test",
98
+ runTests: false,
99
+ });
100
+ assert.equal(result.status, "applied", result.summary);
101
+ assert.equal(result.commits.length, 2);
102
+ assert.match(result.summary, /\[MITOSIS APPLIED\]/);
103
+ const branch = git(["rev-parse", "--verify", "refs/heads/oc-pilot/mitosis-test"], repo.dir).trim();
104
+ assert.equal(branch, result.commits[1]?.sha);
105
+ const subjects = git(["log", "--format=%s", "-2", "oc-pilot/mitosis-test"], repo.dir).trim().split(/\r?\n/);
106
+ assert.deepEqual(subjects, ["mitosis: update b.txt", "mitosis: update a.txt"]);
107
+ assert.ok(result.commits.every((commit) => existsSync(commit.patchFile)));
108
+ assert.ok(existsSync(join(repo.dir, ".oc-pilot", "mitosis")));
109
+ }
110
+ finally {
111
+ rmSync(repo.dir, { recursive: true, force: true });
112
+ }
113
+ });
114
+ test("applyMitosis stops on a failing test and still exposes the branch", async () => {
115
+ const repo = makeRepo();
116
+ try {
117
+ const result = await applyMitosis(repo.dir, repo.diff, {
118
+ strategy: "file",
119
+ branch: "oc-pilot/mitosis-failing",
120
+ testCommand: 'node -e "process.exit(1)"',
121
+ });
122
+ assert.equal(result.status, "failed");
123
+ assert.equal(result.commits.length, 1);
124
+ assert.equal(result.commits[0]?.tests, "fail");
125
+ assert.match(result.summary, /\[MITOSIS FAILED\]/);
126
+ assert.equal(git(["rev-parse", "--verify", "refs/heads/oc-pilot/mitosis-failing"], repo.dir).trim(), result.commits[0]?.sha);
127
+ }
128
+ finally {
129
+ rmSync(repo.dir, { recursive: true, force: true });
130
+ }
131
+ });
132
+ test("applyMitosis refuses an existing branch without force", async () => {
133
+ const repo = makeRepo();
134
+ try {
135
+ await applyMitosis(repo.dir, repo.diff, {
136
+ strategy: "file",
137
+ branch: "oc-pilot/mitosis-existing",
138
+ runTests: false,
139
+ });
140
+ await assert.rejects(() => applyMitosis(repo.dir, repo.diff, {
141
+ strategy: "file",
142
+ branch: "oc-pilot/mitosis-existing",
143
+ runTests: false,
144
+ }), /Ветка уже существует/);
145
+ }
146
+ finally {
147
+ rmSync(repo.dir, { recursive: true, force: true });
148
+ }
149
+ });
150
+ //# sourceMappingURL=mitosis.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mitosis.test.js","sourceRoot":"","sources":["../../src/core/mitosis.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAEtB,MAAM,SAAS,GAAG;IAChB,0CAA0C;IAC1C,oBAAoB;IACpB,oBAAoB;IACpB,iBAAiB;IACjB,IAAI;IACJ,sBAAsB;IACtB,4CAA4C;IAC5C,qBAAqB;IACrB,qBAAqB;IACrB,iBAAiB;IACjB,sBAAsB;IACtB,uBAAuB;IACvB,4CAA4C;IAC5C,qBAAqB;IACrB,qBAAqB;IACrB,iBAAiB;IACjB,sBAAsB;IACtB,uBAAuB;IACvB,sDAAsD;IACtD,sBAAsB;IACtB,eAAe;IACf,0BAA0B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,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -56,6 +56,7 @@ test("MCP advertises prompts and renders them with arguments", () => {
56
56
  "stamp-the-passport",
57
57
  "compare-the-behavior",
58
58
  "inoculate-the-fix",
59
+ "split-the-diff",
59
60
  "prune-senescent-code",
60
61
  "scan-for-injection",
61
62
  "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,aAAa,CAAC,CAAC;AASnC,SAAS,SAAS,CAChB,GAAW,EACX,QAAmB,EACnB,OAAiB,EAAE;IAEnB,MAAM,KAAK,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACnF,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE;QACvE,KAAK;QACL,QAAQ,EAAE,MAAM;QAChB,OAAO,EAAE,MAAM;QACf,SAAS,EA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C,EAAE,MAA4D,CAAC;QACzF,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAClC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;QAExD,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,MAA4D,CAAC;QAC1F,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;IAC3D,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"}
package/dist/mcp.js CHANGED
@@ -1294,6 +1294,35 @@ const TOOLS = [
1294
1294
  },
1295
1295
  },
1296
1296
  },
1297
+ {
1298
+ name: "mitosis",
1299
+ description: "Split a large diff into reviewable commits grouped by file, directory or change type. plan is read-only; apply creates commits in a shadow worktree, optionally runs tests after each, and exposes a branch plus patch files. apply needs --allow-write and confirm=true.",
1300
+ annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false },
1301
+ inputSchema: {
1302
+ type: "object",
1303
+ additionalProperties: false,
1304
+ required: ["action"],
1305
+ properties: {
1306
+ action: { type: "string", enum: ["plan", "apply"] },
1307
+ strategy: { type: "string", enum: ["file", "dir", "type"] },
1308
+ max_files: { type: "integer", minimum: 1, maximum: 500 },
1309
+ prefix: { type: "string", description: "Commit message prefix; default mitosis" },
1310
+ branch: { type: "string", description: "Branch to create for apply" },
1311
+ test_command: { type: "string", description: "Test command after each commit" },
1312
+ test_timeout_ms: { type: "integer", minimum: 1000, maximum: 1800000 },
1313
+ no_test: { type: "boolean", description: "Skip tests after commits" },
1314
+ confirm: { type: "boolean", description: "Required for apply" },
1315
+ force: { type: "boolean", description: "Overwrite an existing branch" },
1316
+ markdown: { type: "boolean", description: "Render the plan as Markdown" },
1317
+ diff: { type: "string", description: "Unified diff text; omit to use the project's git diff" },
1318
+ base: { type: "string" },
1319
+ staged: { type: "boolean" },
1320
+ unstaged: { type: "boolean" },
1321
+ include_untracked: { type: "boolean" },
1322
+ ...RESULT_PROPERTIES,
1323
+ },
1324
+ },
1325
+ },
1297
1326
  {
1298
1327
  name: "apoptosis",
1299
1328
  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.",
@@ -1514,6 +1543,14 @@ const PROMPTS = [
1514
1543
  { name: "context", description: "What broke and why the fix is correct", required: false },
1515
1544
  ],
1516
1545
  },
1546
+ {
1547
+ name: "split-the-diff",
1548
+ title: "Split a large diff into reviewable commits",
1549
+ description: "Partition a diff into small commits by file, directory or type, apply them in a shadow worktree, run tests after each and expose a branch for review.",
1550
+ arguments: [
1551
+ { name: "context", description: "Why the change is being split", required: false },
1552
+ ],
1553
+ },
1517
1554
  {
1518
1555
  name: "prune-senescent-code",
1519
1556
  title: "Prune senescent AI code",
@@ -3521,6 +3558,58 @@ async function callVaccine(input, cwd) {
3521
3558
  args.push("--force");
3522
3559
  return toToolResult(await runCli(args, cwd));
3523
3560
  }
3561
+ async function callMitosis(input, cwd) {
3562
+ const temp = new TempFiles();
3563
+ try {
3564
+ const action = stringArg(input, "action", true);
3565
+ if (action === "apply" && !booleanArg(input, "confirm")) {
3566
+ throw new ToolInputError("mitosis apply needs confirm=true");
3567
+ }
3568
+ const args = ["mitosis", action, "--json"];
3569
+ const strategy = stringArg(input, "strategy");
3570
+ if (strategy)
3571
+ args.push("--strategy", strategy);
3572
+ const maxFiles = integerArg(input, "max_files");
3573
+ if (maxFiles !== undefined)
3574
+ args.push("--max-files", String(maxFiles));
3575
+ const prefix = stringArg(input, "prefix");
3576
+ if (prefix)
3577
+ args.push("--prefix", prefix);
3578
+ const branch = stringArg(input, "branch");
3579
+ if (branch)
3580
+ args.push("--branch", branch);
3581
+ const testCommand = stringArg(input, "test_command");
3582
+ if (testCommand)
3583
+ args.push("--test-command", testCommand);
3584
+ const timeout = integerArg(input, "test_timeout_ms");
3585
+ if (timeout !== undefined)
3586
+ args.push("--test-timeout", String(Math.max(1, Math.round(timeout / 1000))) + "s");
3587
+ if (booleanArg(input, "no_test"))
3588
+ args.push("--no-test");
3589
+ if (action === "apply")
3590
+ args.push("--confirm");
3591
+ if (booleanArg(input, "force"))
3592
+ args.push("--force");
3593
+ if (booleanArg(input, "markdown"))
3594
+ args.push("--markdown");
3595
+ const diff = stringArg(input, "diff");
3596
+ if (diff)
3597
+ args.push("--diff", temp.write("mitosis.diff", diff));
3598
+ const base = baseArg(input);
3599
+ if (base)
3600
+ args.push("--base", base);
3601
+ if (booleanArg(input, "staged"))
3602
+ args.push("--staged");
3603
+ if (booleanArg(input, "unstaged"))
3604
+ args.push("--unstaged");
3605
+ if (booleanArg(input, "include_untracked"))
3606
+ args.push("--include-untracked");
3607
+ return toToolResult(await runCli(args, cwd));
3608
+ }
3609
+ finally {
3610
+ temp.cleanup();
3611
+ }
3612
+ }
3524
3613
  async function callApoptosis(input, cwd) {
3525
3614
  const action = stringArg(input, "action") ?? "scan";
3526
3615
  const args = ["apoptosis", action, "--json"];
@@ -3742,6 +3831,9 @@ async function dispatchTool(name, input, cwd, readOnly) {
3742
3831
  if (name === "vaccine" && ["create", "forget", "clear"].includes(stringArg(input, "action") ?? "")) {
3743
3832
  throw new ToolInputError("vaccine create/forget/clear write .oc-pilot/vaccines and are disabled in read-only mode; start the MCP server with --allow-write");
3744
3833
  }
3834
+ if (name === "mitosis" && stringArg(input, "action") === "apply") {
3835
+ throw new ToolInputError("mitosis apply creates commits and a branch and is disabled in read-only mode; start the MCP server with --allow-write");
3836
+ }
3745
3837
  if (name === "honeypot" && (stringArg(input, "action") === "deploy" || stringArg(input, "action") === "remove")) {
3746
3838
  throw new ToolInputError("honeypot deploy/remove writes files and is disabled in read-only mode; start the MCP server with --allow-write");
3747
3839
  }
@@ -3863,6 +3955,8 @@ async function dispatchTool(name, input, cwd, readOnly) {
3863
3955
  return callOracle(input, cwd);
3864
3956
  case "vaccine":
3865
3957
  return callVaccine(input, cwd);
3958
+ case "mitosis":
3959
+ return callMitosis(input, cwd);
3866
3960
  case "apoptosis":
3867
3961
  return callApoptosis(input, cwd);
3868
3962
  case "scan_injection":
@@ -3942,6 +4036,12 @@ function summarizeResult(value) {
3942
4036
  if (typeof value.status === "string" && Array.isArray(value.removed) && typeof value.summary === "string") {
3943
4037
  return `oc-pilot: apoptosis ${value.status}, ${String(value.removed.length)} removed`;
3944
4038
  }
4039
+ if (typeof value.status === "string" && typeof value.branch === "string" && Array.isArray(value.commits)) {
4040
+ return `oc-pilot: mitosis ${value.status}, ${String(value.commits.length)} commit(s) on ${value.branch}`;
4041
+ }
4042
+ if (Array.isArray(value.commits) && typeof value.files === "number" && typeof value.additions === "number") {
4043
+ return `oc-pilot: mitosis plan ${String(value.commits.length)} commit(s), ${String(value.files)} file(s)`;
4044
+ }
3945
4045
  if (typeof value.total === "number" && typeof value.passed === "number" && Array.isArray(value.results)) {
3946
4046
  return `oc-pilot: vaccines ${String(value.passed)}/${String(value.total)} passed`;
3947
4047
  }
@@ -4241,6 +4341,8 @@ function promptBody(name, args) {
4241
4341
  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}`;
4242
4342
  case "stamp-the-passport":
4243
4343
  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}`;
4344
+ case "split-the-diff":
4345
+ return `Call the oc-pilot "mitosis" tool with action=plan on the proposed diff and read the commit sequence. Check that every commit is independently applicable and that config changes come before the code that needs them. Then call action=apply with confirm=true, a branch name and the project test command; read the test status after each commit. If a commit fails tests, stop: the split is wrong or the change is incomplete; fix the split and rerun. Do not delete failing commits, do not squash everything into one commit to hide the failure, and do not claim the branch is safe when tests were skipped. apply writes a branch and patch files and needs --allow-write.${suffix}`;
4244
4346
  case "inoculate-the-fix":
4245
4347
  return `Call the oc-pilot "vaccine" tool with action=create for the fix commit and its buggy parent. Read the verification: only verified means the test fails on the bug and passes on the fix. If it is rejected, do not store it: the test does not distinguish the two trees; explain why and try a sharper test. If it is error, report the infrastructure failure. Then call action=run to prove the stored vaccines still pass on HEAD. Never mark a rejected test as a vaccine, never weaken the assertion to force a pass, and never delete a failing vaccine to make the suite green. create/forget/clear need --allow-write.${suffix}`;
4246
4348
  case "compare-the-behavior":