localmcp-cli 0.0.1 → 0.0.11

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,454 @@
1
+ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ const BEGIN_PATCH = "*** Begin Patch";
5
+ const END_PATCH = "*** End Patch";
6
+ const ADD_FILE = "*** Add File: ";
7
+ const DELETE_FILE = "*** Delete File: ";
8
+ const UPDATE_FILE = "*** Update File: ";
9
+ const MOVE_TO = "*** Move to: ";
10
+ const END_OF_FILE = "*** End of File";
11
+
12
+ function normalizeNewlines(text) {
13
+ return String(text ?? "").replace(/\r\n/g, "\n");
14
+ }
15
+
16
+ function detectEol(text) {
17
+ return text.includes("\r\n") ? "\r\n" : "\n";
18
+ }
19
+
20
+ function splitLinesPreserveFinal(text) {
21
+ const normalized = normalizeNewlines(text);
22
+ const hadTrailingNewline = normalized.endsWith("\n");
23
+ const lines = normalized === "" ? [] : normalized.split("\n");
24
+ if (hadTrailingNewline) lines.pop();
25
+ return { lines, hadTrailingNewline };
26
+ }
27
+
28
+ function joinLinesPreserveFinal(lines, hadTrailingNewline, eol) {
29
+ if (lines.length === 0) return "";
30
+ const body = lines.join(eol);
31
+ return hadTrailingNewline ? body + eol : body;
32
+ }
33
+
34
+ function parseCodexPatch(patchText) {
35
+ const rawLines = normalizeNewlines(patchText).split("\n");
36
+ const startIdx = rawLines.findIndex(line => line.trim() === BEGIN_PATCH);
37
+ if (startIdx === -1) {
38
+ throw new Error("Codex patch must start with '*** Begin Patch'.");
39
+ }
40
+ const endIdx = rawLines.findIndex((line, idx) => idx > startIdx && line.trim() === END_PATCH);
41
+ if (endIdx === -1) {
42
+ throw new Error("Codex patch must end with '*** End Patch'.");
43
+ }
44
+
45
+ const lines = rawLines.slice(startIdx + 1, endIdx);
46
+ const operations = [];
47
+ let i = 0;
48
+
49
+ while (i < lines.length) {
50
+ const line = lines[i];
51
+ if (line.trim() === "") {
52
+ i += 1;
53
+ continue;
54
+ }
55
+
56
+ if (line.startsWith(ADD_FILE)) {
57
+ const targetPath = line.slice(ADD_FILE.length).trim();
58
+ if (!targetPath) throw new Error("Add File operation is missing a path.");
59
+ i += 1;
60
+ const contentLines = [];
61
+ while (i < lines.length && !lines[i].startsWith("*** ")) {
62
+ if (!lines[i].startsWith("+")) {
63
+ throw new Error(`Invalid Add File line for "${targetPath}": expected '+' prefix.`);
64
+ }
65
+ contentLines.push(lines[i].slice(1));
66
+ i += 1;
67
+ }
68
+ operations.push({ action: "add", path: targetPath, lines: contentLines });
69
+ continue;
70
+ }
71
+
72
+ if (line.startsWith(DELETE_FILE)) {
73
+ const targetPath = line.slice(DELETE_FILE.length).trim();
74
+ if (!targetPath) throw new Error("Delete File operation is missing a path.");
75
+ operations.push({ action: "delete", path: targetPath });
76
+ i += 1;
77
+ continue;
78
+ }
79
+
80
+ if (line.startsWith(UPDATE_FILE)) {
81
+ const targetPath = line.slice(UPDATE_FILE.length).trim();
82
+ if (!targetPath) throw new Error("Update File operation is missing a path.");
83
+ i += 1;
84
+ let moveTo = null;
85
+ if (i < lines.length && lines[i].startsWith(MOVE_TO)) {
86
+ moveTo = lines[i].slice(MOVE_TO.length).trim();
87
+ if (!moveTo) throw new Error(`Move to target is empty for "${targetPath}".`);
88
+ i += 1;
89
+ }
90
+
91
+ const hunks = [];
92
+ let currentHunk = null;
93
+ while (i < lines.length) {
94
+ const cur = lines[i];
95
+ if (cur.startsWith(ADD_FILE) || cur.startsWith(DELETE_FILE) || cur.startsWith(UPDATE_FILE)) {
96
+ break;
97
+ }
98
+ if (cur === END_OF_FILE) {
99
+ if (currentHunk) currentHunk.isEndOfFile = true;
100
+ i += 1;
101
+ continue;
102
+ }
103
+ if (cur.startsWith("@@")) {
104
+ currentHunk = {
105
+ header: cur.slice(2).trim(),
106
+ oldLines: [],
107
+ newLines: [],
108
+ isEndOfFile: false,
109
+ };
110
+ hunks.push(currentHunk);
111
+ i += 1;
112
+ continue;
113
+ }
114
+ if (!currentHunk) {
115
+ if (cur.trim() === "") {
116
+ i += 1;
117
+ continue;
118
+ }
119
+ currentHunk = { header: "", oldLines: [], newLines: [], isEndOfFile: false };
120
+ hunks.push(currentHunk);
121
+ }
122
+ const prefix = cur[0];
123
+ const body = cur.slice(1);
124
+ if (prefix === " ") {
125
+ currentHunk.oldLines.push(body);
126
+ currentHunk.newLines.push(body);
127
+ } else if (prefix === "-") {
128
+ currentHunk.oldLines.push(body);
129
+ } else if (prefix === "+") {
130
+ currentHunk.newLines.push(body);
131
+ } else if (cur === "") {
132
+ currentHunk.oldLines.push("");
133
+ currentHunk.newLines.push("");
134
+ } else {
135
+ throw new Error(`Invalid hunk line in "${targetPath}": "${cur}"`);
136
+ }
137
+ i += 1;
138
+ }
139
+
140
+ if (hunks.length === 0 && !moveTo) {
141
+ throw new Error(`Update File "${targetPath}" has no hunks and no Move to target.`);
142
+ }
143
+ operations.push({ action: "update", path: targetPath, moveTo, hunks });
144
+ continue;
145
+ }
146
+
147
+ throw new Error(`Unexpected patch directive: "${line}"`);
148
+ }
149
+
150
+ if (operations.length === 0) {
151
+ throw new Error("Patch contains no file operations.");
152
+ }
153
+ return { format: "codex", operations };
154
+ }
155
+
156
+ function stripDiffPrefix(rawPath) {
157
+ const cleaned = rawPath.split("\t")[0].trim();
158
+ if (cleaned === "/dev/null") return "/dev/null";
159
+ if (cleaned.startsWith("a/") || cleaned.startsWith("b/")) return cleaned.slice(2);
160
+ return cleaned;
161
+ }
162
+
163
+ function parseUnifiedDiff(patchText) {
164
+ const lines = normalizeNewlines(patchText).split("\n");
165
+ const operations = [];
166
+ let i = 0;
167
+
168
+ while (i < lines.length) {
169
+ if (lines[i].startsWith("diff --git ")) {
170
+ i += 1;
171
+ continue;
172
+ }
173
+ if (!lines[i].startsWith("--- ")) {
174
+ i += 1;
175
+ continue;
176
+ }
177
+ const oldPath = stripDiffPrefix(lines[i].slice(4));
178
+ i += 1;
179
+ if (i >= lines.length || !lines[i].startsWith("+++ ")) {
180
+ throw new Error(`Unified diff missing '+++' header after '--- ${oldPath}'.`);
181
+ }
182
+ const newPath = stripDiffPrefix(lines[i].slice(4));
183
+ i += 1;
184
+
185
+ const hunks = [];
186
+ while (i < lines.length && !lines[i].startsWith("--- ") && !lines[i].startsWith("diff --git ")) {
187
+ const line = lines[i];
188
+ if (!line.startsWith("@@")) {
189
+ i += 1;
190
+ continue;
191
+ }
192
+ const match = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)$/.exec(line);
193
+ if (!match) {
194
+ throw new Error(`Invalid unified diff hunk header: "${line}"`);
195
+ }
196
+ const hunk = {
197
+ header: match[5].trim(),
198
+ oldStart: Number(match[1]),
199
+ oldLines: [],
200
+ newLines: [],
201
+ isEndOfFile: false,
202
+ };
203
+ i += 1;
204
+ while (i < lines.length) {
205
+ const cur = lines[i];
206
+ if (cur.startsWith("@@") || cur.startsWith("--- ") || cur.startsWith("diff --git ")) break;
207
+ if (cur.startsWith("\")) {
208
+ i += 1;
209
+ continue;
210
+ }
211
+ const prefix = cur[0];
212
+ const body = cur.slice(1);
213
+ if (prefix === " ") {
214
+ hunk.oldLines.push(body);
215
+ hunk.newLines.push(body);
216
+ } else if (prefix === "-") {
217
+ hunk.oldLines.push(body);
218
+ } else if (prefix === "+") {
219
+ hunk.newLines.push(body);
220
+ } else if (cur === "" && i === lines.length - 1) {
221
+ i += 1;
222
+ break;
223
+ } else {
224
+ break;
225
+ }
226
+ i += 1;
227
+ }
228
+ hunks.push(hunk);
229
+ }
230
+
231
+ if (oldPath === "/dev/null" && newPath !== "/dev/null") {
232
+ const addedLines = hunks.flatMap(h => h.newLines);
233
+ operations.push({ action: "add", path: newPath, lines: addedLines });
234
+ } else if (newPath === "/dev/null" && oldPath !== "/dev/null") {
235
+ operations.push({ action: "delete", path: oldPath });
236
+ } else {
237
+ operations.push({
238
+ action: "update",
239
+ path: oldPath,
240
+ moveTo: newPath !== oldPath ? newPath : null,
241
+ hunks,
242
+ });
243
+ }
244
+ }
245
+
246
+ if (operations.length === 0) {
247
+ throw new Error("Could not parse any valid patch operations. Use Codex '*** Begin Patch' or standard unified diff.");
248
+ }
249
+ return { format: "unified", operations };
250
+ }
251
+
252
+ export function parsePatch(patchText) {
253
+ const text = String(patchText ?? "");
254
+ if (text.includes(BEGIN_PATCH)) {
255
+ return parseCodexPatch(text);
256
+ }
257
+ return parseUnifiedDiff(text);
258
+ }
259
+
260
+ function findSequence(haystack, needle, startAt, { fuzzy = false, preferEnd = false } = {}) {
261
+ if (needle.length === 0) return preferEnd ? haystack.length : Math.min(startAt, haystack.length);
262
+ const maxStart = haystack.length - needle.length;
263
+ if (maxStart < 0) return -1;
264
+
265
+ const eq = fuzzy
266
+ ? (a, b) => a.trimEnd() === b.trimEnd()
267
+ : (a, b) => a === b;
268
+
269
+ const matchesAt = (idx) => {
270
+ for (let j = 0; j < needle.length; j += 1) {
271
+ if (!eq(haystack[idx + j], needle[j])) return false;
272
+ }
273
+ return true;
274
+ };
275
+
276
+ if (preferEnd && matchesAt(maxStart)) return maxStart;
277
+
278
+ const clampedStart = Math.max(0, Math.min(startAt, maxStart));
279
+ for (let i = clampedStart; i <= maxStart; i += 1) {
280
+ if (matchesAt(i)) return i;
281
+ }
282
+ for (let i = 0; i < clampedStart; i += 1) {
283
+ if (matchesAt(i)) return i;
284
+ }
285
+ return -1;
286
+ }
287
+
288
+ function applyHunksToLines(originalLines, hunks, displayPath) {
289
+ let lines = [...originalLines];
290
+ let cursor = 0;
291
+ let linesAdded = 0;
292
+ let linesRemoved = 0;
293
+
294
+ for (let idx = 0; idx < hunks.length; idx += 1) {
295
+ const hunk = hunks[idx];
296
+ let searchStart = cursor;
297
+
298
+ if (typeof hunk.oldStart === "number" && hunk.oldStart > 0) {
299
+ searchStart = Math.max(0, hunk.oldStart - 1);
300
+ } else if (hunk.header) {
301
+ const anchorIdx = findSequence(lines, [hunk.header], cursor, { fuzzy: true });
302
+ if (anchorIdx !== -1) searchStart = anchorIdx;
303
+ }
304
+
305
+ let matchIdx = findSequence(lines, hunk.oldLines, searchStart, {
306
+ fuzzy: false,
307
+ preferEnd: hunk.isEndOfFile,
308
+ });
309
+ if (matchIdx === -1) {
310
+ matchIdx = findSequence(lines, hunk.oldLines, searchStart, {
311
+ fuzzy: true,
312
+ preferEnd: hunk.isEndOfFile,
313
+ });
314
+ }
315
+ if (matchIdx === -1) {
316
+ const preview = hunk.oldLines.slice(0, 3).join(" | ");
317
+ throw new Error(
318
+ `Failed to match hunk #${idx + 1} in "${displayPath}". Expected context starting with: ${preview}`
319
+ );
320
+ }
321
+
322
+ lines.splice(matchIdx, hunk.oldLines.length, ...hunk.newLines);
323
+ cursor = matchIdx + hunk.newLines.length;
324
+ linesRemoved += hunk.oldLines.length;
325
+ linesAdded += hunk.newLines.length;
326
+ }
327
+
328
+ return { lines, linesAdded, linesRemoved };
329
+ }
330
+
331
+ export async function applyPatchOperations({ patch, cwd, dryRun = false, resolvePath }) {
332
+ const { format, operations } = parsePatch(patch);
333
+ const baseDir = cwd ? await resolvePath(cwd, { mustExist: true }) : null;
334
+ const resolveTarget = (rawPath, opts) => {
335
+ const full = baseDir && !path.isAbsolute(rawPath) ? path.join(baseDir, rawPath) : rawPath;
336
+ return resolvePath(full, opts);
337
+ };
338
+
339
+ // Virtual file state ensures multi-operation patches validate atomically before touching disk.
340
+ const virtualFiles = new Map();
341
+ const stagedWrites = new Map();
342
+ const stagedDeletes = new Set();
343
+ const report = [];
344
+ const summary = { added: 0, updated: 0, moved: 0, deleted: 0 };
345
+
346
+ const readVirtual = async (absPath) => {
347
+ if (virtualFiles.has(absPath)) {
348
+ const entry = virtualFiles.get(absPath);
349
+ if (entry === null) throw new Error(`File "${absPath}" was already deleted by an earlier patch operation.`);
350
+ return entry;
351
+ }
352
+ const raw = await readFile(absPath, "utf8");
353
+ const entry = { raw, eol: detectEol(raw) };
354
+ virtualFiles.set(absPath, entry);
355
+ return entry;
356
+ };
357
+
358
+ for (const op of operations) {
359
+ if (op.action === "add") {
360
+ const absPath = await resolveTarget(op.path, { mustExist: false });
361
+ const content = op.lines.length > 0 ? op.lines.join("\n") + "\n" : "";
362
+ virtualFiles.set(absPath, { raw: content, eol: "\n" });
363
+ stagedWrites.set(absPath, content);
364
+ stagedDeletes.delete(absPath);
365
+ summary.added += 1;
366
+ report.push({
367
+ action: "add",
368
+ path: absPath,
369
+ hunksApplied: 1,
370
+ linesAdded: op.lines.length,
371
+ linesRemoved: 0,
372
+ });
373
+ continue;
374
+ }
375
+
376
+ if (op.action === "delete") {
377
+ const absPath = await resolveTarget(op.path, { mustExist: true });
378
+ await readVirtual(absPath);
379
+ virtualFiles.set(absPath, null);
380
+ stagedWrites.delete(absPath);
381
+ stagedDeletes.add(absPath);
382
+ summary.deleted += 1;
383
+ report.push({
384
+ action: "delete",
385
+ path: absPath,
386
+ hunksApplied: 0,
387
+ linesAdded: 0,
388
+ linesRemoved: 0,
389
+ });
390
+ continue;
391
+ }
392
+
393
+ if (op.action === "update") {
394
+ const absPath = await resolveTarget(op.path, { mustExist: true });
395
+ const current = await readVirtual(absPath);
396
+ const { lines, hadTrailingNewline } = splitLinesPreserveFinal(current.raw);
397
+ const applied = op.hunks.length > 0
398
+ ? applyHunksToLines(lines, op.hunks, op.path)
399
+ : { lines, linesAdded: 0, linesRemoved: 0 };
400
+ const nextContent = joinLinesPreserveFinal(applied.lines, hadTrailingNewline, current.eol);
401
+
402
+ if (op.moveTo) {
403
+ const destPath = await resolveTarget(op.moveTo, { mustExist: false });
404
+ virtualFiles.set(absPath, null);
405
+ virtualFiles.set(destPath, { raw: nextContent, eol: current.eol });
406
+ if (destPath !== absPath) {
407
+ stagedWrites.delete(absPath);
408
+ stagedDeletes.add(absPath);
409
+ }
410
+ stagedWrites.set(destPath, nextContent);
411
+ stagedDeletes.delete(destPath);
412
+ summary.moved += 1;
413
+ report.push({
414
+ action: "move",
415
+ path: absPath,
416
+ moveTo: destPath,
417
+ hunksApplied: op.hunks.length,
418
+ linesAdded: applied.linesAdded,
419
+ linesRemoved: applied.linesRemoved,
420
+ });
421
+ } else {
422
+ virtualFiles.set(absPath, { raw: nextContent, eol: current.eol });
423
+ stagedWrites.set(absPath, nextContent);
424
+ stagedDeletes.delete(absPath);
425
+ summary.updated += 1;
426
+ report.push({
427
+ action: "update",
428
+ path: absPath,
429
+ hunksApplied: op.hunks.length,
430
+ linesAdded: applied.linesAdded,
431
+ linesRemoved: applied.linesRemoved,
432
+ });
433
+ }
434
+ }
435
+ }
436
+
437
+ if (!dryRun) {
438
+ for (const [absPath, content] of stagedWrites.entries()) {
439
+ await mkdir(path.dirname(absPath), { recursive: true });
440
+ await writeFile(absPath, content, "utf8");
441
+ }
442
+ for (const absPath of stagedDeletes) {
443
+ await rm(absPath, { force: true });
444
+ }
445
+ }
446
+
447
+ return {
448
+ ok: true,
449
+ dryRun: Boolean(dryRun),
450
+ format,
451
+ summary,
452
+ files: report,
453
+ };
454
+ }
@@ -0,0 +1,158 @@
1
+ import { childEnvironment } from "../core/config.js";
2
+ import { execFile } from "node:child_process";
3
+ import { existsSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { promisify } from "node:util";
6
+ import { CONTROL_SECURITY_SCHEMES, okResult, toolMeta } from "../core/protocol.js";
7
+
8
+ const execFileAsync = promisify(execFile);
9
+ const MAX_DIAGNOSTICS = 200;
10
+
11
+ async function execTool(argv, cwd, timeoutMs) {
12
+ try {
13
+ const result = await execFileAsync(argv[0], argv.slice(1), {
14
+ cwd,
15
+ timeout: timeoutMs,
16
+ maxBuffer: 16 * 1024 * 1024,
17
+ env: childEnvironment(),
18
+ });
19
+ return { exitCode: 0, stdout: result.stdout ?? "", stderr: result.stderr ?? "" };
20
+ } catch (error) {
21
+ if (error && typeof error === "object" && "stdout" in error) {
22
+ return {
23
+ exitCode: typeof error.code === "number" ? error.code : 1,
24
+ stdout: error.stdout ?? "",
25
+ stderr: error.stderr ?? String(error.message ?? ""),
26
+ };
27
+ }
28
+ throw error;
29
+ }
30
+ }
31
+
32
+ function parseTsc(output) {
33
+ const findings = [];
34
+ const rx = /^(.+?)\((\d+),(\d+)\):\s+(error|warning)\s+([^:\s]+):\s+(.*)$/;
35
+ for (const line of String(output || "").split(/\r?\n/)) {
36
+ const m = line.match(rx);
37
+ if (m) {
38
+ findings.push({
39
+ file: m[1],
40
+ line: Number(m[2]),
41
+ column: Number(m[3]),
42
+ severity: m[4],
43
+ code: m[5],
44
+ message: m[6],
45
+ source: "tsc",
46
+ });
47
+ }
48
+ }
49
+ return findings;
50
+ }
51
+
52
+ function parseEslint(text) {
53
+ try {
54
+ return JSON.parse(text).flatMap((entry) =>
55
+ (entry.messages || []).map((msg) => ({
56
+ file: entry.filePath,
57
+ line: msg.line ?? 1,
58
+ column: msg.column ?? 1,
59
+ severity: msg.severity === 2 ? "error" : "warning",
60
+ code: String(msg.ruleId ?? ""),
61
+ message: msg.message,
62
+ source: "eslint",
63
+ }))
64
+ );
65
+ } catch {
66
+ return [];
67
+ }
68
+ }
69
+
70
+ function parseRuff(text) {
71
+ try {
72
+ return JSON.parse(text).map((item) => ({
73
+ file: item.filename ?? "",
74
+ line: item.location?.row ?? item.row ?? 1,
75
+ column: item.location?.column ?? item.column ?? 1,
76
+ severity: String(item.code ?? "").startsWith("E") ? "error" : "warning",
77
+ code: String(item.code ?? ""),
78
+ message: item.message ?? "",
79
+ source: "ruff",
80
+ }));
81
+ } catch {
82
+ return [];
83
+ }
84
+ }
85
+
86
+ export function createDiagnosticsTools({ config, auth }) {
87
+ return [
88
+ {
89
+ name: "code_diagnostics",
90
+ title: "Code diagnostics",
91
+ description:
92
+ "Run local project checkers (tsc, ESLint, ruff) on a project folder and return structured diagnostics: file, line, severity, code, message.",
93
+ inputSchema: {
94
+ type: "object",
95
+ properties: {
96
+ path: { type: "string", description: "Project folder to inspect. Relative paths resolve from server cwd." },
97
+ timeoutMs: { type: "integer", minimum: 1000, maximum: 120000 },
98
+ },
99
+ additionalProperties: false,
100
+ },
101
+ annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false, idempotentHint: false },
102
+ _meta: toolMeta("Checking project code diagnostics", "Code diagnostics ready", CONTROL_SECURITY_SCHEMES),
103
+ async handler(args, { authContext }) {
104
+ auth.requireCapability("ALLOW_SHELL", config.state.allowShell, args.control_pin, authContext);
105
+ const projectPath = await config.resolveAllowedPath(args.path || ".", { mustExist: true });
106
+ const timeoutMs = Math.min(Math.max(Number(args.timeoutMs ?? 60000) || 60000, 1000), 120000);
107
+ const checks = [];
108
+ const diagnostics = [];
109
+
110
+ const runOne = async (name, argv, parser) => {
111
+ try {
112
+ const res = await execTool(argv, projectPath, timeoutMs);
113
+ const parsed = parser(res.stdout);
114
+ checks.push({ name, ran: true, detail: `${parsed.length} finding(s), exit code ${res.exitCode}` });
115
+ for (const item of parsed) {
116
+ if (diagnostics.length >= MAX_DIAGNOSTICS) break;
117
+ diagnostics.push(item);
118
+ }
119
+ } catch (error) {
120
+ checks.push({ name, ran: false, detail: error instanceof Error ? error.message : String(error) });
121
+ }
122
+ };
123
+
124
+ const tscBin = path.join(projectPath, "node_modules", "typescript", "bin", "tsc");
125
+ const eslintBin = path.join(projectPath, "node_modules", "eslint", "bin", "eslint.js");
126
+ if (existsSync(path.join(projectPath, "package.json")) && existsSync(tscBin)) {
127
+ await runOne("tsc", [process.execPath, tscBin, "--noEmit", "--pretty", "false"], parseTsc);
128
+ } else {
129
+ checks.push({ name: "tsc", ran: false, detail: "TypeScript not installed in this project." });
130
+ }
131
+
132
+ if (existsSync(eslintBin)) {
133
+ await runOne("eslint", [process.execPath, eslintBin, "-f", "json", "."], parseEslint);
134
+ } else {
135
+ checks.push({ name: "eslint", ran: false, detail: "ESLint not installed in this project." });
136
+ }
137
+
138
+ const hasRuff =
139
+ existsSync(path.join(projectPath, "ruff.toml")) ||
140
+ existsSync(path.join(projectPath, ".ruff.toml")) ||
141
+ existsSync(path.join(projectPath, "pyproject.toml"));
142
+ if (hasRuff) {
143
+ await runOne("ruff", ["python", "-m", "ruff", "check", "--output-format", "json", "."], parseRuff);
144
+ } else {
145
+ checks.push({ name: "ruff", ran: false, detail: "No ruff.toml or pyproject.toml found." });
146
+ }
147
+
148
+ const payload = {
149
+ path: projectPath,
150
+ checks,
151
+ diagnostics,
152
+ truncated: diagnostics.length >= MAX_DIAGNOSTICS,
153
+ };
154
+ return okResult(JSON.stringify(payload, null, 2), payload);
155
+ },
156
+ },
157
+ ];
158
+ }