swarmdo 1.14.0 → 1.15.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.
@@ -515,7 +515,7 @@ function getCostFromStdin() {
515
515
  // misses, the displayed version is meaningful (matches what the user
516
516
  // installed), not a stale hard-coded string.
517
517
  function getPkgVersion() {
518
- let ver = '1.14.0';
518
+ let ver = '1.15.0';
519
519
  try {
520
520
  const home = os.homedir();
521
521
  const pkgPaths = [
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![swarmdo](swarmdo/assets/brand/logo-full.svg)](https://swarmdo.com)
4
4
 
5
- [![npm version (swarmdo)](https://img.shields.io/badge/npx%20swarmdo-v1.14.0-cb3837?style=for-the-badge&logo=npm&logoColor=white)](https://github.com/SwarmDo/swarmdo/releases)
5
+ [![npm version (swarmdo)](https://img.shields.io/badge/npx%20swarmdo-v1.15.0-cb3837?style=for-the-badge&logo=npm&logoColor=white)](https://github.com/SwarmDo/swarmdo/releases)
6
6
  [![MIT License](https://img.shields.io/badge/License-MIT-yellow?style=for-the-badge)](https://github.com/SwarmDo/swarmdo/blob/main/LICENSE)
7
7
  [![Website](https://img.shields.io/badge/swarmdo.com-e2a33c?style=for-the-badge&logoColor=black)](https://swarmdo.com)
8
8
  [![Star on GitHub](https://img.shields.io/github/stars/SwarmDo/swarmdo?style=for-the-badge&logo=github&color=gold)](https://github.com/SwarmDo/swarmdo)
@@ -283,6 +283,7 @@ The recent release train added a full day-to-day operations layer around the swa
283
283
  | `swarmdo env` | **Catch env-var drift before deploy** — statically scan code for `process.env.X` / `import.meta.env.X` / `Deno.env.get` / `os.getenv` references and reconcile against `.env` and `.env.example`: reports **missing** (used but undeclared), **unused**, and **undocumented**. `--ci` exits 1 on missing vars. Also an MCP tool (`env_check`). Deterministic |
284
284
  | `swarmdo license` | **Audit dependency licenses** — walk `node_modules`, resolve each package's SPDX license, and gate on an allow/deny policy so a GPL or unknown license can't slip into a permissive tree. `--allow MIT,Apache-2.0 --ci` fails the build; distinct from `security` (CVEs). Also an MCP tool (`license_check`). Deterministic |
285
285
  | `swarmdo sbom` | **Software Bill of Materials from the lockfile** — emit a CycloneDX (default) or SPDX JSON manifest of every dependency with version, purl, license, and integrity hash, for compliance/vuln tooling. `--spec spdx`, `-o sbom.json`, `--production`. Completes the env/license/sbom supply-chain trio. Deterministic |
286
+ | `swarmdo apply` | **A forgiving `git apply`** — apply a unified diff with fuzzy context matching, so an agent's patch lands even when line numbers have drifted or a context line is slightly off, and reports exactly which hunks couldn't. `--dry-run` to preview, `--fuzz N` to tolerate more drift. Also an MCP tool (`apply_patch`). Deterministic |
286
287
  | `swarmdo integrations` (alias `integrate`) | **Use swarmdo from Codex CLI, GitHub Copilot CLI, and pi** — one command wires AGENTS.md + each CLI's MCP config (idempotent, dry-run first, never touches your Claude Code setup) |
287
288
  | OpenRouter model pool | **Let swarms pick from any models you configure** — declare tier-mapped OpenRouter models in `swarmdo.config.json`; the router Thompson-samples among them per task and the execution layer dispatches the winner |
288
289
  | `swarmdo changelog` (alias `notes`) | **Release notes from conventional commits** — `--out NOTES.md` feeds `gh release create --notes-file` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swarmdo",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Swarmdo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,50 @@
1
+ /**
2
+ * apply.ts — apply a unified diff to source text with FUZZY context matching.
3
+ *
4
+ * LLM/agent-produced diffs frequently fail `git apply`: the model's context
5
+ * lines drift by a few lines, or whitespace differs, and git rejects the whole
6
+ * patch. This applier locates each hunk by searching for its context near the
7
+ * declared line (not only AT it), tolerates leading/trailing context drift up
8
+ * to a fuzz factor, and reports precisely which hunks couldn't land — instead
9
+ * of an all-or-nothing failure.
10
+ *
11
+ * Pure + deterministic: text in, text (or rejects) out. The fs read/write lives
12
+ * in ../commands/apply.ts.
13
+ */
14
+ export interface HunkLine {
15
+ /** ' ' context, '-' removal, '+' addition */
16
+ type: ' ' | '-' | '+';
17
+ content: string;
18
+ }
19
+ export interface Hunk {
20
+ oldStart: number;
21
+ newStart: number;
22
+ lines: HunkLine[];
23
+ }
24
+ export interface FilePatch {
25
+ oldPath: string;
26
+ newPath: string;
27
+ hunks: Hunk[];
28
+ }
29
+ /** Parse a unified diff into per-file patches. Pure. Tolerates `a/`+`b/` prefixes. */
30
+ export declare function parsePatch(text: string): FilePatch[];
31
+ export interface ApplyOptions {
32
+ /** max leading/trailing context lines to drop when the full block won't match (default 2) */
33
+ fuzz?: number;
34
+ }
35
+ export interface HunkResult {
36
+ hunk: Hunk;
37
+ applied: boolean;
38
+ /** 0-based line where it landed (if applied) */
39
+ at?: number;
40
+ /** how many context lines were trimmed to make it fit */
41
+ fuzzUsed?: number;
42
+ }
43
+ export interface ApplyResult {
44
+ ok: boolean;
45
+ result: string;
46
+ hunks: HunkResult[];
47
+ }
48
+ /** Apply one file's hunks to `source`. Pure. Hunks are applied top-to-bottom with offset tracking. */
49
+ export declare function applyPatch(source: string, patch: FilePatch, opts?: ApplyOptions): ApplyResult;
50
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1,186 @@
1
+ /**
2
+ * apply.ts — apply a unified diff to source text with FUZZY context matching.
3
+ *
4
+ * LLM/agent-produced diffs frequently fail `git apply`: the model's context
5
+ * lines drift by a few lines, or whitespace differs, and git rejects the whole
6
+ * patch. This applier locates each hunk by searching for its context near the
7
+ * declared line (not only AT it), tolerates leading/trailing context drift up
8
+ * to a fuzz factor, and reports precisely which hunks couldn't land — instead
9
+ * of an all-or-nothing failure.
10
+ *
11
+ * Pure + deterministic: text in, text (or rejects) out. The fs read/write lives
12
+ * in ../commands/apply.ts.
13
+ */
14
+ /** Parse a unified diff into per-file patches. Pure. Tolerates `a/`+`b/` prefixes. */
15
+ export function parsePatch(text) {
16
+ const files = [];
17
+ const lines = text.split('\n');
18
+ let cur = null;
19
+ let hunk = null;
20
+ const stripPrefix = (p) => p.replace(/^[ab]\//, '').replace(/\t.*$/, '').trim();
21
+ for (let i = 0; i < lines.length; i++) {
22
+ const line = lines[i];
23
+ if (line.startsWith('diff --git')) {
24
+ cur = null;
25
+ hunk = null;
26
+ continue;
27
+ }
28
+ if (line.startsWith('--- ')) {
29
+ const old = stripPrefix(line.slice(4));
30
+ const next = lines[i + 1] ?? '';
31
+ const neu = next.startsWith('+++ ') ? stripPrefix(next.slice(4)) : old;
32
+ cur = { oldPath: old === '/dev/null' ? neu : old, newPath: neu === '/dev/null' ? old : neu, hunks: [] };
33
+ files.push(cur);
34
+ hunk = null;
35
+ i++; // consume the +++ line
36
+ continue;
37
+ }
38
+ if (line.startsWith('@@')) {
39
+ const m = line.match(/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
40
+ if (m && cur) {
41
+ hunk = { oldStart: parseInt(m[1], 10), newStart: parseInt(m[2], 10), lines: [] };
42
+ cur.hunks.push(hunk);
43
+ }
44
+ continue;
45
+ }
46
+ if (hunk) {
47
+ if (line === '' && i === lines.length - 1)
48
+ continue; // trailing newline artifact
49
+ const t = line[0];
50
+ if (t === ' ' || t === '+' || t === '-') {
51
+ hunk.lines.push({ type: t, content: line.slice(1) });
52
+ }
53
+ else if (line === '') {
54
+ hunk.lines.push({ type: ' ', content: '' }); // blank context line written without the leading space
55
+ }
56
+ else if (line.startsWith('\\')) {
57
+ // "" — ignore
58
+ }
59
+ else {
60
+ hunk = null; // end of hunk block
61
+ }
62
+ }
63
+ }
64
+ return files;
65
+ }
66
+ /** The lines a hunk expects to find (context + removals), and produces (context + additions). */
67
+ function hunkBlocks(hunk) {
68
+ const oldBlock = [];
69
+ const newBlock = [];
70
+ for (const l of hunk.lines) {
71
+ if (l.type === ' ') {
72
+ oldBlock.push(l.content);
73
+ newBlock.push(l.content);
74
+ }
75
+ else if (l.type === '-')
76
+ oldBlock.push(l.content);
77
+ else
78
+ newBlock.push(l.content);
79
+ }
80
+ return { oldBlock, newBlock };
81
+ }
82
+ function blockMatchesAt(source, at, block) {
83
+ if (at < 0 || at + block.length > source.length)
84
+ return false;
85
+ for (let i = 0; i < block.length; i++)
86
+ if (source[at + i] !== block[i])
87
+ return false;
88
+ return true;
89
+ }
90
+ /**
91
+ * Find where `block` occurs in `source`, preferring the position nearest
92
+ * `expected` (0-based). Returns -1 if not found. Deterministic: on ties the
93
+ * lower index wins.
94
+ */
95
+ function findBlock(source, block, expected) {
96
+ if (block.length === 0)
97
+ return Math.max(0, Math.min(expected, source.length));
98
+ if (blockMatchesAt(source, expected, block))
99
+ return expected;
100
+ let best = -1;
101
+ let bestDist = Infinity;
102
+ for (let i = 0; i + block.length <= source.length; i++) {
103
+ if (!blockMatchesAt(source, i, block))
104
+ continue;
105
+ const dist = Math.abs(i - expected);
106
+ if (dist < bestDist) {
107
+ bestDist = dist;
108
+ best = i;
109
+ }
110
+ }
111
+ return best;
112
+ }
113
+ /** Apply one file's hunks to `source`. Pure. Hunks are applied top-to-bottom with offset tracking. */
114
+ export function applyPatch(source, patch, opts = {}) {
115
+ const fuzz = opts.fuzz ?? 2;
116
+ const trailingNewline = source.endsWith('\n');
117
+ const lines = source.split('\n');
118
+ if (trailingNewline)
119
+ lines.pop(); // drop the empty element from a trailing \n
120
+ let offset = 0;
121
+ const results = [];
122
+ for (const hunk of patch.hunks) {
123
+ const { oldBlock, newBlock } = hunkBlocks(hunk);
124
+ const expected = hunk.oldStart - 1 + offset;
125
+ // Try the full block, then progressively trim up to `fuzz` context lines
126
+ // off each end (patch fuzz) to tolerate drift.
127
+ let placed = -1;
128
+ let usedFuzz = 0;
129
+ let trimLead = 0;
130
+ let trimTail = 0;
131
+ outer: for (let f = 0; f <= fuzz; f++) {
132
+ for (let lead = 0; lead <= f; lead++) {
133
+ const tail = f - lead;
134
+ const leadTrimmable = countLeadingContext(hunk);
135
+ const tailTrimmable = countTrailingContext(hunk);
136
+ if (lead > leadTrimmable || tail > tailTrimmable)
137
+ continue;
138
+ const trimmed = oldBlock.slice(lead, oldBlock.length - tail);
139
+ const at = findBlock(lines, trimmed, expected + lead);
140
+ if (at >= 0) {
141
+ placed = at - lead;
142
+ usedFuzz = f;
143
+ trimLead = lead;
144
+ trimTail = tail;
145
+ break outer;
146
+ }
147
+ }
148
+ }
149
+ if (placed < 0) {
150
+ results.push({ hunk, applied: false });
151
+ continue;
152
+ }
153
+ // Splice: remove oldBlock.length lines at `placed`, insert newBlock.
154
+ // (trimLead/trimTail only affected *matching*, not what we replace.)
155
+ void trimLead;
156
+ void trimTail;
157
+ lines.splice(placed, oldBlock.length, ...newBlock);
158
+ offset += newBlock.length - oldBlock.length;
159
+ results.push({ hunk, applied: true, at: placed, fuzzUsed: usedFuzz });
160
+ }
161
+ let result = lines.join('\n');
162
+ if (trailingNewline)
163
+ result += '\n';
164
+ return { ok: results.every((r) => r.applied), result, hunks: results };
165
+ }
166
+ function countLeadingContext(hunk) {
167
+ let n = 0;
168
+ for (const l of hunk.lines) {
169
+ if (l.type === ' ')
170
+ n++;
171
+ else
172
+ break;
173
+ }
174
+ return n;
175
+ }
176
+ function countTrailingContext(hunk) {
177
+ let n = 0;
178
+ for (let i = hunk.lines.length - 1; i >= 0; i--) {
179
+ if (hunk.lines[i].type === ' ')
180
+ n++;
181
+ else
182
+ break;
183
+ }
184
+ return n;
185
+ }
186
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `swarmdo apply` — apply a unified diff to the working tree with fuzzy context
3
+ * matching. The forgiving counterpart to `git apply`: when an agent's diff has
4
+ * drifted line numbers or a slightly-off context line, this still lands the
5
+ * hunks it can and reports exactly which it couldn't, instead of rejecting the
6
+ * whole patch.
7
+ *
8
+ * swarmdo apply changes.patch # apply a patch file
9
+ * agent-output | swarmdo apply # apply a patch from stdin
10
+ * swarmdo apply --dry-run changes.patch # preview: what would apply/reject
11
+ * swarmdo apply --fuzz 3 changes.patch # tolerate more context drift
12
+ *
13
+ * Engine (../apply/apply.ts) is pure + tested; this reads/writes files.
14
+ */
15
+ import type { Command } from '../types.js';
16
+ export declare const applyCommand: Command;
17
+ export default applyCommand;
18
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1,118 @@
1
+ /**
2
+ * `swarmdo apply` — apply a unified diff to the working tree with fuzzy context
3
+ * matching. The forgiving counterpart to `git apply`: when an agent's diff has
4
+ * drifted line numbers or a slightly-off context line, this still lands the
5
+ * hunks it can and reports exactly which it couldn't, instead of rejecting the
6
+ * whole patch.
7
+ *
8
+ * swarmdo apply changes.patch # apply a patch file
9
+ * agent-output | swarmdo apply # apply a patch from stdin
10
+ * swarmdo apply --dry-run changes.patch # preview: what would apply/reject
11
+ * swarmdo apply --fuzz 3 changes.patch # tolerate more context drift
12
+ *
13
+ * Engine (../apply/apply.ts) is pure + tested; this reads/writes files.
14
+ */
15
+ import * as fs from 'node:fs';
16
+ import * as path from 'node:path';
17
+ import { output } from '../output.js';
18
+ import { parsePatch, applyPatch } from '../apply/apply.js';
19
+ function readStdin() {
20
+ return new Promise((resolve) => {
21
+ const chunks = [];
22
+ process.stdin.on('data', (c) => chunks.push(Buffer.from(c)));
23
+ process.stdin.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
24
+ process.stdin.on('error', () => resolve(Buffer.concat(chunks).toString('utf8')));
25
+ });
26
+ }
27
+ /** Resolve the file a patch targets, preferring the new path, then the old. */
28
+ function targetFile(root, fp) {
29
+ return path.resolve(root, fp.newPath && fp.newPath !== '/dev/null' ? fp.newPath : fp.oldPath);
30
+ }
31
+ async function run(ctx) {
32
+ const root = ctx.cwd || process.cwd();
33
+ const dryRun = ctx.flags['dry-run'] === true;
34
+ const partial = ctx.flags.partial === true;
35
+ const fuzz = typeof ctx.flags.fuzz === 'string' ? parseInt(ctx.flags.fuzz, 10) : 2;
36
+ // Read the patch: a file arg, or stdin.
37
+ let patchText;
38
+ if (ctx.args[0]) {
39
+ try {
40
+ patchText = fs.readFileSync(path.resolve(root, ctx.args[0]), 'utf8');
41
+ }
42
+ catch {
43
+ output.printError(`could not read patch file ${ctx.args[0]}`);
44
+ return { success: false, exitCode: 1 };
45
+ }
46
+ }
47
+ else {
48
+ if (process.stdin.isTTY) {
49
+ output.writeln(output.error('Usage: swarmdo apply <patch-file> OR <patch> | swarmdo apply'));
50
+ return { success: false, exitCode: 1 };
51
+ }
52
+ patchText = await readStdin();
53
+ }
54
+ const patches = parsePatch(patchText);
55
+ if (patches.length === 0) {
56
+ output.printError('no file patches found — is this a unified diff?');
57
+ return { success: false, exitCode: 1 };
58
+ }
59
+ let totalApplied = 0;
60
+ let totalRejected = 0;
61
+ const writes = [];
62
+ for (const fp of patches) {
63
+ const file = targetFile(root, fp);
64
+ const rel = path.relative(root, file);
65
+ let source;
66
+ try {
67
+ source = fs.readFileSync(file, 'utf8');
68
+ }
69
+ catch {
70
+ // New-file patch (--- /dev/null): treat missing source as empty.
71
+ if (fp.oldPath === '/dev/null' || !fs.existsSync(file))
72
+ source = '';
73
+ else {
74
+ output.printError(`cannot read ${rel}`);
75
+ totalRejected += fp.hunks.length;
76
+ continue;
77
+ }
78
+ }
79
+ const res = applyPatch(source, fp, { fuzz });
80
+ const applied = res.hunks.filter((h) => h.applied).length;
81
+ const rejected = res.hunks.length - applied;
82
+ totalApplied += applied;
83
+ totalRejected += rejected;
84
+ const fuzzy = res.hunks.filter((h) => h.applied && (h.fuzzUsed ?? 0) > 0).length;
85
+ const tag = rejected === 0 ? output.dim('ok') : output.bold(`${rejected} rejected`);
86
+ output.writeln(`${rel} ${applied}/${res.hunks.length} hunks${fuzzy ? output.dim(` (${fuzzy} fuzzy)`) : ''} ${tag}`);
87
+ if (rejected === 0 || partial) {
88
+ if (res.result !== source)
89
+ writes.push({ file, content: res.result });
90
+ }
91
+ }
92
+ if (!dryRun) {
93
+ for (const w of writes)
94
+ fs.writeFileSync(w.file, w.content);
95
+ }
96
+ const verb = dryRun ? 'would apply' : 'applied';
97
+ output.writeln(output.dim(`${verb} ${totalApplied} hunks, ${totalRejected} rejected${dryRun ? ' (dry run)' : ''}`));
98
+ // Exit 1 if anything was rejected — a CI/agent can branch on it.
99
+ const code = totalRejected > 0 ? 1 : 0;
100
+ return { success: code === 0, exitCode: code };
101
+ }
102
+ export const applyCommand = {
103
+ name: 'apply',
104
+ description: 'Apply a unified diff to the working tree with fuzzy context matching — a forgiving `git apply` for agent-produced patches',
105
+ options: [
106
+ { name: 'dry-run', description: 'report what would apply/reject without writing', type: 'boolean' },
107
+ { name: 'fuzz', description: 'max context lines to drop when matching a drifted hunk (default 2)', type: 'string' },
108
+ { name: 'partial', description: 'write files even when some of their hunks are rejected', type: 'boolean' },
109
+ ],
110
+ examples: [
111
+ { command: 'swarmdo apply changes.patch', description: 'Apply a patch file' },
112
+ { command: 'cat out.diff | swarmdo apply --dry-run', description: 'Preview a patch from stdin' },
113
+ { command: 'swarmdo apply --fuzz 3 changes.patch', description: 'Tolerate more context drift' },
114
+ ],
115
+ action: run,
116
+ };
117
+ export default applyCommand;
118
+ //# sourceMappingURL=apply.js.map
@@ -38,6 +38,9 @@ const commandLoaders = {
38
38
  // Software Bill of Materials from the lockfile (syft/cyclonedx demand) —
39
39
  // CycloneDX/SPDX JSON; completes the env/license/sbom supply-chain trio.
40
40
  sbom: () => import('./sbom.js'),
41
+ // Fuzzy unified-diff applier (agent-diff pain) — a forgiving `git apply` that
42
+ // lands hunks despite context drift and reports what it couldn't.
43
+ apply: () => import('./apply.js'),
41
44
  // Queryable exported-symbol index (codegraph demand) — where things are
42
45
  // defined without grep+read round-trips.
43
46
  codegraph: () => import('./codegraph.js'),
@@ -271,7 +274,7 @@ export async function getCommandsByCategory() {
271
274
  // three slots from 'statusline' onward (completionsCmd received the
272
275
  // statusline module, analyzeCmd received completions, …), scrambling the
273
276
  // categorized help. Every load now has a named slot.
274
- const [daemonCmd, doctorCmd, embeddingsCmd, neuralCmd, performanceCmd, securityCmd, swarmvectorCmd, hiveMindCmd, configCmd, statuslineCmd, compressCmd, efficiencyCmd, completionsCmd, migrateCmd, workflowCmd, analyzeCmd, routeCmd, progressCmd, providersCmd, pluginsCmd, deploymentCmd, claimsCmd, issuesCmd, updateCmd, processCmd, guidanceCmd, applianceCmd, cleanupCmd, autopilotCmd, demoCmd, usageCmd, repairCmd, hudCmd, compactCmd, codegraphCmd, redactCmd, packCmd, envCmd, licenseCmd, sbomCmd,] = await Promise.all([
277
+ const [daemonCmd, doctorCmd, embeddingsCmd, neuralCmd, performanceCmd, securityCmd, swarmvectorCmd, hiveMindCmd, configCmd, statuslineCmd, compressCmd, efficiencyCmd, completionsCmd, migrateCmd, workflowCmd, analyzeCmd, routeCmd, progressCmd, providersCmd, pluginsCmd, deploymentCmd, claimsCmd, issuesCmd, updateCmd, processCmd, guidanceCmd, applianceCmd, cleanupCmd, autopilotCmd, demoCmd, usageCmd, repairCmd, hudCmd, compactCmd, codegraphCmd, redactCmd, packCmd, envCmd, licenseCmd, sbomCmd, applyCmd,] = await Promise.all([
275
278
  loadCommand('daemon'), loadCommand('doctor'), loadCommand('embeddings'), loadCommand('neural'),
276
279
  loadCommand('performance'), loadCommand('security'), loadCommand('swarmvector'), loadCommand('hive-mind'),
277
280
  loadCommand('config'), loadCommand('statusline'), loadCommand('compress'), loadCommand('efficiency'),
@@ -279,7 +282,7 @@ export async function getCommandsByCategory() {
279
282
  loadCommand('analyze'), loadCommand('route'), loadCommand('progress'), loadCommand('providers'),
280
283
  loadCommand('plugins'), loadCommand('deployment'), loadCommand('claims'), loadCommand('issues'),
281
284
  loadCommand('update'), loadCommand('process'), loadCommand('guidance'), loadCommand('appliance'),
282
- loadCommand('cleanup'), loadCommand('autopilot'), loadCommand('demo'), loadCommand('usage'), loadCommand('repair'), loadCommand('hud'), loadCommand('compact'), loadCommand('codegraph'), loadCommand('redact'), loadCommand('pack'), loadCommand('env'), loadCommand('license'), loadCommand('sbom'),
285
+ loadCommand('cleanup'), loadCommand('autopilot'), loadCommand('demo'), loadCommand('usage'), loadCommand('repair'), loadCommand('hud'), loadCommand('compact'), loadCommand('codegraph'), loadCommand('redact'), loadCommand('pack'), loadCommand('env'), loadCommand('license'), loadCommand('sbom'), loadCommand('apply'),
283
286
  ]);
284
287
  return {
285
288
  primary: [
@@ -295,7 +298,7 @@ export async function getCommandsByCategory() {
295
298
  utility: [
296
299
  configCmd, doctorCmd, daemonCmd, completionsCmd,
297
300
  migrateCmd, workflowCmd, demoCmd,
298
- statuslineCmd, compressCmd, compactCmd, redactCmd, packCmd, envCmd, licenseCmd, sbomCmd, efficiencyCmd,
301
+ statuslineCmd, compressCmd, compactCmd, redactCmd, packCmd, envCmd, licenseCmd, sbomCmd, applyCmd, efficiencyCmd,
299
302
  ].filter(Boolean),
300
303
  analysis: [
301
304
  analyzeCmd, routeCmd, progressCmd, usageCmd, hudCmd, codegraphCmd,
@@ -23,6 +23,7 @@ import { codegraphTools } from './mcp-tools/codegraph-tools.js';
23
23
  import { redactTools } from './mcp-tools/redact-tools.js';
24
24
  import { envTools } from './mcp-tools/env-tools.js';
25
25
  import { licenseTools } from './mcp-tools/license-tools.js';
26
+ import { applyTools } from './mcp-tools/apply-tools.js';
26
27
  import { progressTools } from './mcp-tools/progress-tools.js';
27
28
  import { embeddingsTools } from './mcp-tools/embeddings-tools.js';
28
29
  import { claimsTools } from './mcp-tools/claims-tools.js';
@@ -110,6 +111,7 @@ const TOOL_GROUPS = {
110
111
  redact: () => redactTools,
111
112
  env: () => envTools,
112
113
  license: () => licenseTools,
114
+ apply: () => applyTools,
113
115
  progress: () => progressTools,
114
116
  embeddings: () => embeddingsTools,
115
117
  claims: () => claimsTools,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Apply MCP Tool
3
+ *
4
+ * Let an agent apply its own unified diff to a piece of source with fuzzy
5
+ * context matching — landing hunks even when line numbers drift — and get back
6
+ * the patched text plus exactly which hunks were rejected. String-in/string-out
7
+ * and deterministic; shares the pure engine in ../apply/apply.ts with the CLI.
8
+ */
9
+ import type { MCPTool } from './types.js';
10
+ export declare const applyTools: MCPTool[];
11
+ //# sourceMappingURL=apply-tools.d.ts.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Apply MCP Tool
3
+ *
4
+ * Let an agent apply its own unified diff to a piece of source with fuzzy
5
+ * context matching — landing hunks even when line numbers drift — and get back
6
+ * the patched text plus exactly which hunks were rejected. String-in/string-out
7
+ * and deterministic; shares the pure engine in ../apply/apply.ts with the CLI.
8
+ */
9
+ import { parsePatch, applyPatch } from '../apply/apply.js';
10
+ const applyPatchTool = {
11
+ name: 'apply_patch',
12
+ description: 'Apply a unified diff to a source string with fuzzy context matching (a forgiving `git apply`). Returns the patched text and per-hunk results — use this when a diff you produced might have drifted line numbers or slightly-off context, instead of hand-editing. Deterministic; pass the file content and the diff for a single file.',
13
+ category: 'apply',
14
+ tags: ['patch', 'diff', 'apply', 'edit'],
15
+ inputSchema: {
16
+ type: 'object',
17
+ properties: {
18
+ source: { type: 'string', description: 'the current file content the diff applies to' },
19
+ patch: { type: 'string', description: 'a unified diff (one file); a/ b/ prefixes are tolerated' },
20
+ fuzz: { type: 'number', description: 'max context lines to drop when matching a drifted hunk (default 2)', default: 2 },
21
+ },
22
+ required: ['source', 'patch'],
23
+ },
24
+ handler: async (params) => {
25
+ if (typeof params.source !== 'string')
26
+ return { error: true, message: 'source (string) is required' };
27
+ if (typeof params.patch !== 'string')
28
+ return { error: true, message: 'patch (string) is required' };
29
+ const patches = parsePatch(params.patch);
30
+ if (patches.length === 0)
31
+ return { error: true, message: 'no file patch found — is this a unified diff?' };
32
+ const fuzz = typeof params.fuzz === 'number' ? params.fuzz : 2;
33
+ const res = applyPatch(params.source, patches[0], { fuzz });
34
+ return {
35
+ ok: res.ok,
36
+ result: res.result,
37
+ applied: res.hunks.filter((h) => h.applied).length,
38
+ rejected: res.hunks.filter((h) => !h.applied).length,
39
+ hunks: res.hunks.map((h) => ({ applied: h.applied, at: h.at, fuzzUsed: h.fuzzUsed, oldStart: h.hunk.oldStart })),
40
+ };
41
+ },
42
+ };
43
+ export const applyTools = [applyPatchTool];
44
+ //# sourceMappingURL=apply-tools.js.map
@@ -19,6 +19,7 @@ export { codegraphTools } from './codegraph-tools.js';
19
19
  export { redactTools } from './redact-tools.js';
20
20
  export { envTools } from './env-tools.js';
21
21
  export { licenseTools } from './license-tools.js';
22
+ export { applyTools } from './apply-tools.js';
22
23
  export { progressTools } from './progress-tools.js';
23
24
  export { transferTools } from './transfer-tools.js';
24
25
  export { securityTools } from './security-tools.js';
@@ -18,6 +18,7 @@ export { codegraphTools } from './codegraph-tools.js';
18
18
  export { redactTools } from './redact-tools.js';
19
19
  export { envTools } from './env-tools.js';
20
20
  export { licenseTools } from './license-tools.js';
21
+ export { applyTools } from './apply-tools.js';
21
22
  export { progressTools } from './progress-tools.js';
22
23
  export { transferTools } from './transfer-tools.js';
23
24
  export { securityTools } from './security-tools.js';
@@ -25,6 +25,7 @@ const LEAN_GROUPS = [
25
25
  'codegraph', // codegraph_query / file / index — "where is X defined?"
26
26
  'redact', // redact_text / redact_scan — secret guard on the data path
27
27
  'env', // env_check — env-var drift (missing/unused/undocumented)
28
+ 'apply', // apply_patch — fuzzy unified-diff applier for agent edits
28
29
  ];
29
30
  /** Balanced = lean + orchestration/session/system the average user reaches for. */
30
31
  const BALANCED_EXTRA = [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarmdo/cli",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "type": "module",
5
5
  "description": "Swarmdo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",