@punks/cli 5.2.0 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BASELINE_CHANGELOG.md +9 -1
- package/dist/CHANGELOG.md +17 -0
- package/dist/baseline/scaffold-baseline/baseline.json +5 -5
- package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +408 -309
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +1 -0
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +98 -27
- package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +156 -8
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.mjs +323 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +821 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.d.mts +97 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.mjs +658 -0
- package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.test.ts +614 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +6 -7
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +20 -19
- package/dist/baseline/scaffold-baseline.json +5 -5
- package/dist/baseline/scaffold-baseline.tgz +0 -0
- package/dist/data/hooks/format-edited-file.mjs +237 -325
- package/dist/data/scripts/commit-gate-runner.mjs +98 -27
- package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
- package/dist/data/scripts/managed-lint-runner.mjs +323 -0
- package/dist/data/scripts/managed-lint.d.mts +97 -0
- package/dist/data/scripts/managed-lint.mjs +658 -0
- package/dist/index.js +72 -97
- package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
- package/dist/skills/agnostic/cli/hi-cli/references/commands.md +6 -7
- package/dist/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
- package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +6 -5
- package/package.json +1 -1
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
cpSync,
|
|
6
|
+
mkdtempSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
readlinkSync,
|
|
9
|
+
symlinkSync,
|
|
6
10
|
closeSync,
|
|
7
11
|
constants,
|
|
8
12
|
existsSync,
|
|
@@ -19,7 +23,7 @@ import {
|
|
|
19
23
|
import os from "node:os";
|
|
20
24
|
import path from "node:path";
|
|
21
25
|
import { spawnSync } from "node:child_process";
|
|
22
|
-
import { fileURLToPath } from "node:url";
|
|
26
|
+
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
23
27
|
|
|
24
28
|
const javascriptFormattableSuffixes = new Set([
|
|
25
29
|
".ts",
|
|
@@ -39,7 +43,6 @@ const formattableSuffixes = new Set([
|
|
|
39
43
|
const ignoredParts = new Set([".git", "node_modules", ".next", "dist"]);
|
|
40
44
|
const scaffoldManifestPath = ".devpunks/scaffold-manifest.json";
|
|
41
45
|
const productRoots = new Set(["apps", "packages"]);
|
|
42
|
-
const packageManagers = new Set(["bun", "pnpm", "npm", "yarn"]);
|
|
43
46
|
const backendWorkspaceSegments = new Set(["api", "backend", "server", "services"]);
|
|
44
47
|
|
|
45
48
|
function readStdinJson() {
|
|
@@ -180,116 +183,27 @@ function runCommand(root, args, stdio = ["ignore", "pipe", "pipe"]) {
|
|
|
180
183
|
};
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
function owningWorkspace(root, relativePath) {
|
|
184
|
-
const absolutePath = path.join(root, relativePath);
|
|
185
|
-
let current = path.dirname(absolutePath);
|
|
186
|
-
|
|
187
|
-
while (current === root || !path.relative(root, current).startsWith("..")) {
|
|
188
|
-
if (existsSync(path.join(current, "package.json"))) {
|
|
189
|
-
return current;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const parent = path.dirname(current);
|
|
193
|
-
if (parent === current) {
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
current = parent;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return root;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
186
|
function workspaceRelativePath(workspace, root, relativePath) {
|
|
203
187
|
const workspacePath = path.relative(workspace, path.join(root, relativePath));
|
|
204
188
|
return workspacePath.split(path.sep).join("/");
|
|
205
189
|
}
|
|
206
190
|
|
|
207
|
-
function
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
: [""];
|
|
218
|
-
const commandExtensions = isWindows && path.extname(command) === "" ? pathExtensions : [""];
|
|
219
|
-
const hasPathSegment = command.includes("/") || command.includes("\\");
|
|
220
|
-
const candidates = (hasPathSegment ? [""] : pathEntries).flatMap((entry) =>
|
|
221
|
-
commandExtensions.map((extension) =>
|
|
222
|
-
hasPathSegment ? `${command}${extension}` : path.join(entry, `${command}${extension}`),
|
|
223
|
-
),
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
return candidates.some((candidate) => {
|
|
227
|
-
try {
|
|
228
|
-
accessSync(candidate, isWindows ? constants.F_OK : constants.X_OK);
|
|
229
|
-
return true;
|
|
230
|
-
} catch {
|
|
231
|
-
return false;
|
|
191
|
+
function toolCommand(directory, tool, args) {
|
|
192
|
+
const root = repoRoot(directory);
|
|
193
|
+
let current = directory;
|
|
194
|
+
while (true) {
|
|
195
|
+
const manifest = path.join(current, "node_modules", tool, "package.json");
|
|
196
|
+
if (existsSync(manifest)) {
|
|
197
|
+
const value = JSON.parse(readFileSync(manifest, "utf8"));
|
|
198
|
+
const bin = typeof value.bin === "string" ? value.bin : value.bin?.[tool];
|
|
199
|
+
if (value.name !== tool || typeof bin !== "string" || path.isAbsolute(bin) || bin.split(/[\\/]/u).includes("..")) throw new Error(`Invalid repository-local ${tool} executable`);
|
|
200
|
+
return [path.resolve(path.dirname(manifest), bin), ...args];
|
|
232
201
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
function packageManagerFromPackageJson(root) {
|
|
237
|
-
const packageManager = loadJson(path.join(root, "package.json"))?.packageManager;
|
|
238
|
-
|
|
239
|
-
if (typeof packageManager !== "string") {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const name = packageManager.split("@")[0];
|
|
244
|
-
return packageManagers.has(name) ? name : null;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function packageManagerFromLockfile(root) {
|
|
248
|
-
if (existsSync(path.join(root, "bun.lock")) || existsSync(path.join(root, "bun.lockb"))) {
|
|
249
|
-
return "bun";
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (
|
|
253
|
-
existsSync(path.join(root, "pnpm-lock.yaml")) ||
|
|
254
|
-
existsSync(path.join(root, "pnpm-workspace.yaml"))
|
|
255
|
-
) {
|
|
256
|
-
return "pnpm";
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (existsSync(path.join(root, "yarn.lock"))) {
|
|
260
|
-
return "yarn";
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (existsSync(path.join(root, "package-lock.json"))) {
|
|
264
|
-
return "npm";
|
|
202
|
+
if (current === root || path.dirname(current) === current) break;
|
|
203
|
+
current = path.dirname(current);
|
|
265
204
|
}
|
|
266
|
-
|
|
267
|
-
return
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function toolCommand(root, tool, args) {
|
|
271
|
-
switch (packageManagerFromPackageJson(root) ?? packageManagerFromLockfile(root)) {
|
|
272
|
-
case "bun":
|
|
273
|
-
return ["bunx", tool, ...args];
|
|
274
|
-
case "pnpm":
|
|
275
|
-
return ["pnpm", "exec", tool, ...args];
|
|
276
|
-
case "yarn":
|
|
277
|
-
return ["yarn", "exec", tool, ...args];
|
|
278
|
-
case "npm":
|
|
279
|
-
return ["npm", "exec", "--", tool, ...args];
|
|
280
|
-
default:
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (commandExists("bunx")) {
|
|
285
|
-
return ["bunx", tool, ...args];
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (commandExists("pnpm")) {
|
|
289
|
-
return ["pnpm", "exec", tool, ...args];
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return ["npx", tool, ...args];
|
|
205
|
+
// An intentionally missing local path becomes a normal operational failure in runCommand.
|
|
206
|
+
return [path.join(root || directory, "node_modules/.bin", tool), ...args];
|
|
293
207
|
}
|
|
294
208
|
|
|
295
209
|
function nearestPythonProject(root, relativePath) {
|
|
@@ -518,106 +432,169 @@ function normalizeDiagnostic(diagnostic, root, fallbackPath, temporaryPath = nul
|
|
|
518
432
|
return normalized;
|
|
519
433
|
}
|
|
520
434
|
|
|
521
|
-
function
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
435
|
+
function normalizeManagedDiagnostics(report, root, scope, fallbackPath) {
|
|
436
|
+
if (!Array.isArray(report)) return {ok: false, error: "Oxlint did not return validated diagnostics"};
|
|
437
|
+
const diagnostics = [];
|
|
438
|
+
for (const diagnostic of report) {
|
|
439
|
+
let filename = fallbackPath;
|
|
440
|
+
if (typeof diagnostic.filename === "string" && diagnostic.filename.length > 0) {
|
|
441
|
+
filename = path.relative(root, path.resolve(root, scope, diagnostic.filename)).split(path.sep).join("/");
|
|
442
|
+
if (filename === ".." || filename.startsWith("../") || path.isAbsolute(filename)) return {ok: false, error: "Oxlint diagnostic escaped the managed repository"};
|
|
443
|
+
}
|
|
444
|
+
diagnostics.push(normalizeDiagnostic({...diagnostic, filename}, root, fallbackPath));
|
|
527
445
|
}
|
|
446
|
+
return {ok: true, diagnostics};
|
|
447
|
+
}
|
|
528
448
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
449
|
+
async function lintRuntime(root) {
|
|
450
|
+
const canonical = path.join(root, ".agents/scripts/managed-lint-runner.mjs");
|
|
451
|
+
const local = new URL("../scripts/managed-lint-runner.mjs", import.meta.url);
|
|
452
|
+
const runner = await import(existsSync(canonical) ? pathToFileURL(canonical).href : local.href);
|
|
453
|
+
const resolver = await import(existsSync(canonical) ? pathToFileURL(path.join(root, ".agents/scripts/managed-lint.mjs")).href : new URL("../scripts/managed-lint.mjs", import.meta.url).href);
|
|
454
|
+
return { ...runner, ...resolver };
|
|
455
|
+
}
|
|
532
456
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
457
|
+
async function selectedLint(root, filePaths) {
|
|
458
|
+
try {
|
|
459
|
+
const runtime = await lintRuntime(root);
|
|
460
|
+
const paths = filePaths.map((file) => path.relative(root, path.resolve(root, file)).split(path.sep).join("/"));
|
|
461
|
+
const resolution = await runtime.loadManagedLint(root, paths);
|
|
462
|
+
if (resolution.status === "disabled") return { runtime, routes: [] };
|
|
463
|
+
if (resolution.status !== "ready") throw new Error(resolution.diagnostics.join("\n"));
|
|
464
|
+
return { runtime, routes: resolution.routes };
|
|
465
|
+
} catch (error) {
|
|
466
|
+
return { failure: emptyLintSummary("operational_failure", [{ stage: "config-load", command: "managed lint selection", message: error.message }]) };
|
|
538
467
|
}
|
|
468
|
+
}
|
|
539
469
|
|
|
540
|
-
|
|
470
|
+
// Python shares quality exclusions, but does not require JavaScript owner selection.
|
|
471
|
+
function qualityExclusions(root) {
|
|
472
|
+
let settings;
|
|
473
|
+
try {
|
|
474
|
+
settings = JSON.parse(readFileSync(path.join(root, ".devpunks/settings.json"), "utf8"));
|
|
475
|
+
} catch (error) {
|
|
476
|
+
if (error?.code === "ENOENT") return [];
|
|
477
|
+
throw error;
|
|
478
|
+
}
|
|
479
|
+
const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
480
|
+
if (!record(settings) || (settings.lint !== undefined && !record(settings.lint))) {
|
|
481
|
+
throw new TypeError("Managed quality settings and lint must be objects");
|
|
482
|
+
}
|
|
483
|
+
const exclude = settings.lint?.exclude;
|
|
484
|
+
if (exclude === undefined) return [];
|
|
485
|
+
if (!Array.isArray(exclude) || !exclude.every((pattern) =>
|
|
486
|
+
typeof pattern === "string" && pattern.length > 0 && !pattern.startsWith("!") &&
|
|
487
|
+
!pattern.includes("\\") && !path.posix.isAbsolute(pattern) &&
|
|
488
|
+
pattern.split("/").every((part) => part !== ".." && part !== "") &&
|
|
489
|
+
path.posix.normalize(pattern) === pattern
|
|
490
|
+
)) throw new TypeError("lint.exclude must be a list of repository-relative patterns.");
|
|
491
|
+
return exclude;
|
|
541
492
|
}
|
|
542
493
|
|
|
543
|
-
function
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
494
|
+
async function selectedQuality(root, filePaths) {
|
|
495
|
+
const caseSemantics = pathCaseSemantics(root);
|
|
496
|
+
if (caseSemantics === "unknown") {
|
|
497
|
+
return {failure: emptyLintSummary("operational_failure", [
|
|
498
|
+
{
|
|
499
|
+
stage: "config-load",
|
|
500
|
+
command: "path case semantics",
|
|
501
|
+
message: "Unable to determine path case semantics",
|
|
502
|
+
},
|
|
503
|
+
])};
|
|
504
|
+
}
|
|
549
505
|
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
return {
|
|
562
|
-
ok: false,
|
|
563
|
-
stage: "lint-fix",
|
|
564
|
-
command: commandText(fixCommand),
|
|
565
|
-
exitCode: fixResult.status,
|
|
566
|
-
error: `Oxlint could not start: ${fixResult.error.message}`,
|
|
567
|
-
};
|
|
568
|
-
}
|
|
506
|
+
const caseInsensitivePaths = caseSemantics === "case-insensitive";
|
|
507
|
+
const managedPaths = loadManagedPaths(root, caseInsensitivePaths);
|
|
508
|
+
if (managedPaths === null) {
|
|
509
|
+
return {failure: emptyLintSummary("operational_failure", [
|
|
510
|
+
{
|
|
511
|
+
stage: "config-load",
|
|
512
|
+
command: scaffoldManifestPath,
|
|
513
|
+
message: "Managed scaffold manifest is invalid",
|
|
514
|
+
},
|
|
515
|
+
])};
|
|
516
|
+
}
|
|
569
517
|
|
|
570
|
-
const fixedContent = readFileSync(temporaryPath);
|
|
571
|
-
const verificationCommand = toolCommand(workspace, "oxlint", [
|
|
572
|
-
"--format",
|
|
573
|
-
"json",
|
|
574
|
-
temporaryRelativePath,
|
|
575
|
-
]);
|
|
576
|
-
const verificationResult = runCommand(workspace, verificationCommand);
|
|
577
|
-
if (verificationResult.error !== undefined) {
|
|
578
|
-
return {
|
|
579
|
-
ok: false,
|
|
580
|
-
stage: "lint-verify",
|
|
581
|
-
command: commandText(verificationCommand),
|
|
582
|
-
exitCode: verificationResult.status,
|
|
583
|
-
error: `Oxlint could not start: ${verificationResult.error.message}`,
|
|
584
|
-
};
|
|
585
|
-
}
|
|
586
518
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
519
|
+
try {
|
|
520
|
+
const runtime = await lintRuntime(root);
|
|
521
|
+
const exclude = qualityExclusions(root);
|
|
522
|
+
const eligible = [...new Set(filePaths.map((file) =>
|
|
523
|
+
normalizeRelativePath(root, file, managedPaths, caseInsensitivePaths)
|
|
524
|
+
).filter((file) => file !== null && !runtime.isManagedQualityPathExcluded({path: file, exclude})))];
|
|
525
|
+
const nonPythonPaths = filePaths.filter((file) => !isPythonPath(file));
|
|
526
|
+
const selection = nonPythonPaths.length > 0
|
|
527
|
+
? await selectedLint(root, nonPythonPaths)
|
|
528
|
+
: {runtime, routes: []};
|
|
529
|
+
// Keep raw resolver-owned dependency triggers, including scaffold metadata.
|
|
530
|
+
// The resolver handles excluded-only source; unrelated non-JS files stay independent.
|
|
531
|
+
const requiresSelection = nonPythonPaths.some((file) =>
|
|
532
|
+
javascriptFormattableSuffixes.has(path.extname(file))
|
|
592
533
|
);
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
534
|
+
const javascriptPaths = selection.failure && !requiresSelection
|
|
535
|
+
? [] : nonPythonPaths;
|
|
536
|
+
const routes = selection.routes ?? [];
|
|
537
|
+
const selectedFiles = new Set(routes.flatMap((route) => route.files));
|
|
538
|
+
return {
|
|
539
|
+
runtime, routes, javascriptPaths,
|
|
540
|
+
files: eligible.filter((file) => isPythonPath(file) || selectedFiles.has(file)),
|
|
541
|
+
failures: javascriptPaths.length > 0 ? selection.failure?.failures ?? [] : [],
|
|
542
|
+
};
|
|
543
|
+
} catch (error) {
|
|
544
|
+
return {failure: emptyLintSummary("operational_failure", [{stage: "config-load", command: "managed quality exclusions", message: error.message}])};
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function copyLintMirror(root, mirror) {
|
|
549
|
+
const visit = (source, destination) => {
|
|
550
|
+
mkdirSync(destination, {recursive: true});
|
|
551
|
+
for (const entry of readdirSync(source, {withFileTypes: true})) {
|
|
552
|
+
const relative = path.relative(root, path.join(source, entry.name)).split(path.sep).join("/");
|
|
553
|
+
if ([".git", ".turbo", ".next", "coverage", "dist", "build", "__pycache__"].includes(entry.name) || /^(?:\.devpunks\/(?:delivery|cache|replaced-scaffold)|\.devpunks-cache)(?:\/|$)/u.test(relative)) continue;
|
|
554
|
+
const from = path.join(source, entry.name);
|
|
555
|
+
const to = path.join(destination, entry.name);
|
|
556
|
+
if (entry.name === "node_modules") { symlinkSync(realpathSync(from), to, "dir"); continue; }
|
|
557
|
+
if (entry.isSymbolicLink()) {
|
|
558
|
+
const resolved = realpathSync(from);
|
|
559
|
+
const relativeTarget = path.relative(root, resolved);
|
|
560
|
+
if (relativeTarget === ".." || relativeTarget.startsWith(`..${path.sep}`) || path.isAbsolute(relativeTarget)) throw new Error(`Cannot prove temporary lint parity for external repository symlink: ${path.relative(root, from)}`);
|
|
561
|
+
const link = readlinkSync(from);
|
|
562
|
+
symlinkSync(path.isAbsolute(link) ? path.resolve(mirror, relativeTarget) : link, to);
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (entry.isDirectory()) visit(from, to);
|
|
566
|
+
else if (entry.isFile()) cpSync(from, to);
|
|
567
|
+
else throw new Error(`Cannot mirror non-regular repository input: ${path.relative(root, from)}`);
|
|
611
568
|
}
|
|
569
|
+
};
|
|
570
|
+
visit(root, mirror);
|
|
571
|
+
}
|
|
612
572
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
573
|
+
async function runSafeJavascriptLint(workspace, root, relativePath, content, route, runtime) {
|
|
574
|
+
const mirror = mkdtempSync(path.join(os.tmpdir(), "hi-lint-mirror-"));
|
|
575
|
+
let command;
|
|
576
|
+
try {
|
|
577
|
+
copyLintMirror(root, mirror);
|
|
578
|
+
for (const input of [route.config, ...route.inputs]) {
|
|
579
|
+
if (existsSync(path.join(root, input)) && !existsSync(path.join(mirror, input))) throw new Error(`Required lint input is excluded from safe mirror: ${input}`);
|
|
619
580
|
}
|
|
620
|
-
|
|
581
|
+
const target = path.join(mirror, relativePath);
|
|
582
|
+
if (!lstatSync(target).isFile()) throw new Error("Temporary lint target must be a copied regular file");
|
|
583
|
+
writeFileSync(target, content);
|
|
584
|
+
command = await runtime.buildManagedLintCommand({root: mirror, route, output: "json", logicalSourcePath: relativePath, physicalInputPath: target});
|
|
585
|
+
if (command.status !== "ready") throw new Error(command.diagnostics.join("\n"));
|
|
586
|
+
const fixed = runtime.executeManagedLintCommand({root: mirror, command: {...command, args: ["--fix", ...command.args]}});
|
|
587
|
+
if (fixed.code === 2) throw new Error(["Oxlint fix failed", fixed.stdout, fixed.stderr].filter(Boolean).join("\n"));
|
|
588
|
+
const fixedDiagnostics = normalizeManagedDiagnostics(fixed.diagnostics, mirror, route.scope, relativePath);
|
|
589
|
+
if (!fixedDiagnostics.ok) throw new Error(fixedDiagnostics.error);
|
|
590
|
+
const result = runtime.executeManagedLintCommand({root: mirror, command});
|
|
591
|
+
if (result.code === 2) throw new Error(["Oxlint verification failed", result.stdout, result.stderr].filter(Boolean).join("\n"));
|
|
592
|
+
const parsed = normalizeManagedDiagnostics(result.diagnostics, mirror, route.scope, relativePath);
|
|
593
|
+
if (!parsed.ok) throw new Error(parsed.error);
|
|
594
|
+
return {ok: true, content: readFileSync(target), diagnostics: parsed.diagnostics};
|
|
595
|
+
} catch (error) {
|
|
596
|
+
return {ok: false, stage: "lint-verify", command: command ? commandText([command.executable, ...command.args]) : "managed lint mirror", error: error.message};
|
|
597
|
+
} finally { rmSync(mirror, {force: true, recursive: true}); }
|
|
621
598
|
}
|
|
622
599
|
|
|
623
600
|
const publicationWorkerScript = `
|
|
@@ -857,49 +834,16 @@ function commandText(command) {
|
|
|
857
834
|
return Array.isArray(command) ? command.join(" ") : String(command ?? "");
|
|
858
835
|
}
|
|
859
836
|
|
|
860
|
-
function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
861
|
-
const
|
|
862
|
-
if (
|
|
863
|
-
|
|
864
|
-
{
|
|
865
|
-
stage: "config-load",
|
|
866
|
-
command: "path case semantics",
|
|
867
|
-
message: "Unable to determine path case semantics",
|
|
868
|
-
},
|
|
869
|
-
]);
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
const caseInsensitivePaths = caseSemantics === "case-insensitive";
|
|
873
|
-
const managedPaths = loadManagedPaths(root, caseInsensitivePaths);
|
|
874
|
-
if (managedPaths === null) {
|
|
875
|
-
return emptyLintSummary("operational_failure", [
|
|
876
|
-
{
|
|
877
|
-
stage: "config-load",
|
|
878
|
-
command: scaffoldManifestPath,
|
|
879
|
-
message: "Managed scaffold manifest is invalid",
|
|
880
|
-
},
|
|
881
|
-
]);
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
const normalizedFiles = [];
|
|
885
|
-
|
|
886
|
-
for (const filePath of filePaths) {
|
|
887
|
-
const normalizedPath = normalizeRelativePath(
|
|
888
|
-
root,
|
|
889
|
-
filePath,
|
|
890
|
-
managedPaths,
|
|
891
|
-
caseInsensitivePaths,
|
|
892
|
-
);
|
|
893
|
-
if (normalizedPath && !normalizedFiles.includes(normalizedPath)) {
|
|
894
|
-
normalizedFiles.push(normalizedPath);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
837
|
+
async function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
838
|
+
const selection = await selectedQuality(root, filePaths);
|
|
839
|
+
if (selection.failure) return selection.failure;
|
|
840
|
+
const normalizedFiles = selection.files;
|
|
897
841
|
|
|
898
842
|
const formatted = [];
|
|
899
843
|
const formatFailed = [];
|
|
900
844
|
const lintFailed = [];
|
|
901
845
|
const diagnostics = [];
|
|
902
|
-
const failures = [];
|
|
846
|
+
const failures = [...selection.failures];
|
|
903
847
|
|
|
904
848
|
for (const relativePath of normalizedFiles) {
|
|
905
849
|
const expectedFingerprint = expectedFingerprints?.[relativePath];
|
|
@@ -920,9 +864,16 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
|
920
864
|
continue;
|
|
921
865
|
}
|
|
922
866
|
|
|
923
|
-
const
|
|
867
|
+
const route = selection.routes.find((item) => item.files.includes(relativePath));
|
|
868
|
+
const workspace = isPythonPath(relativePath) ? root : path.resolve(root, route.scope);
|
|
924
869
|
const workspacePath = workspaceRelativePath(workspace, root, relativePath);
|
|
925
|
-
|
|
870
|
+
let formatCommand;
|
|
871
|
+
try { formatCommand = formatCommandForPath(workspace, workspacePath); }
|
|
872
|
+
catch (error) {
|
|
873
|
+
closeSync(target.descriptor);
|
|
874
|
+
failures.push({kind: "format", stage: "format", file: relativePath, command: "local formatter", message: error.message});
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
926
877
|
|
|
927
878
|
// Keep mutating tools off the live path; stage output before claiming the validated target.
|
|
928
879
|
const formatResult = runTransformCommand(
|
|
@@ -945,7 +896,7 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
|
945
896
|
continue;
|
|
946
897
|
}
|
|
947
898
|
|
|
948
|
-
const lintCommand = lintCommandForPath(workspace, workspacePath, true);
|
|
899
|
+
const lintCommand = isPythonPath(relativePath) ? lintCommandForPath(workspace, workspacePath, true) : javascriptLintableSuffixes.has(path.extname(relativePath)) ? ["managed lint"] : null;
|
|
949
900
|
let formattedContent = formatResult.output;
|
|
950
901
|
let lintResult = null;
|
|
951
902
|
if (lintCommand !== null && isPythonPath(relativePath)) {
|
|
@@ -954,7 +905,7 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
|
954
905
|
formattedContent = lintResult.output;
|
|
955
906
|
}
|
|
956
907
|
} else if (lintCommand !== null) {
|
|
957
|
-
lintResult = runSafeJavascriptLint(workspace, root, relativePath, formattedContent);
|
|
908
|
+
lintResult = await runSafeJavascriptLint(workspace, root, relativePath, formattedContent, route, selection.runtime);
|
|
958
909
|
if (lintResult.ok) {
|
|
959
910
|
formattedContent = lintResult.content;
|
|
960
911
|
diagnostics.push(...lintResult.diagnostics);
|
|
@@ -994,6 +945,16 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
|
994
945
|
}
|
|
995
946
|
}
|
|
996
947
|
|
|
948
|
+
if (selection.routes.some((route) => route.triggered)) {
|
|
949
|
+
const verified = await verifyLintFiles(root, filePaths);
|
|
950
|
+
const known = new Set(diagnostics.map((diagnostic) => JSON.stringify(diagnostic)));
|
|
951
|
+
for (const diagnostic of verified.diagnostics) {
|
|
952
|
+
if (!known.has(JSON.stringify(diagnostic))) diagnostics.push(diagnostic);
|
|
953
|
+
}
|
|
954
|
+
failures.push(...verified.failures);
|
|
955
|
+
for (const file of verified.lint_failed) if (!lintFailed.includes(file)) lintFailed.push(file);
|
|
956
|
+
}
|
|
957
|
+
|
|
997
958
|
const result =
|
|
998
959
|
failures.length > 0 ? "operational_failure" : diagnostics.length > 0 ? "findings" : "clean";
|
|
999
960
|
return {
|
|
@@ -1018,88 +979,42 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
|
|
|
1018
979
|
};
|
|
1019
980
|
}
|
|
1020
981
|
|
|
1021
|
-
function
|
|
1022
|
-
const
|
|
1023
|
-
const
|
|
1024
|
-
if (
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
}
|
|
982
|
+
function verifyPythonFile(root, relativePath) {
|
|
983
|
+
const command = ["uv", "run", "--project", nearestPythonProject(root, relativePath), "ruff", "check", "--output-format", "json", "--stdin-filename", relativePath, "-"];
|
|
984
|
+
const target = openFormattingTarget(path.join(root, relativePath));
|
|
985
|
+
if (target === null) return {failure: {stage: "lint-verify", file: relativePath, command: commandText(command), message: "Edited file changed before verification"}};
|
|
986
|
+
try {
|
|
987
|
+
const result = runTransformCommand(root, command, target.content);
|
|
988
|
+
if (result.error || ![0, 1].includes(result.status)) throw new Error(result.error?.message ?? (result.stderr || "Ruff verification failed"));
|
|
989
|
+
const report = JSON.parse(result.output.toString());
|
|
990
|
+
if (!Array.isArray(report) || report.some((item) => !item || typeof item.message !== "string" || typeof item.code !== "string" || !Number.isInteger(item.location?.row) || !Number.isInteger(item.location?.column))) throw new Error("Ruff returned invalid diagnostics");
|
|
991
|
+
if (result.status !== 0 && report.length === 0) throw new Error(result.stderr || "Ruff failed without diagnostics");
|
|
992
|
+
return {diagnostics: report.map((item) => ({file: relativePath, rule: item.code, severity: "error", line: item.location.row, column: item.location.column, message: item.message, ...(typeof item.url === "string" ? {documentation: item.url} : {})}))};
|
|
993
|
+
} catch (error) {
|
|
994
|
+
return {failure: {stage: "lint-verify", file: relativePath, command: commandText(command), message: error.message}};
|
|
995
|
+
} finally { closeSync(target.descriptor); }
|
|
996
|
+
}
|
|
1033
997
|
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
.map((filePath) =>
|
|
1038
|
-
normalizeRelativePath(root, filePath, managedPaths, caseSemantics === "case-insensitive"),
|
|
1039
|
-
)
|
|
1040
|
-
.filter((filePath) => filePath && isLintablePath(filePath)),
|
|
1041
|
-
),
|
|
1042
|
-
];
|
|
998
|
+
async function verifyLintFiles(root, filePaths) {
|
|
999
|
+
const selection = await selectedQuality(root, filePaths);
|
|
1000
|
+
if (selection.failure) return selection.failure;
|
|
1043
1001
|
const diagnostics = [];
|
|
1044
|
-
const failures = [];
|
|
1045
|
-
const
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
const result =
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
file: relativePath,
|
|
1057
|
-
command: commandText(command),
|
|
1058
|
-
exitCode: result.status,
|
|
1059
|
-
message: `Oxlint could not start: ${result.error.message}`,
|
|
1060
|
-
});
|
|
1061
|
-
continue;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
const parsed = parseLintDiagnostics(result.stdout, root, relativePath, workspacePath);
|
|
1065
|
-
if (!parsed.ok) {
|
|
1066
|
-
failures.push({
|
|
1067
|
-
kind: "lint",
|
|
1068
|
-
stage: "lint-verify",
|
|
1069
|
-
file: relativePath,
|
|
1070
|
-
command: commandText(command),
|
|
1071
|
-
exitCode: result.status,
|
|
1072
|
-
message: parsed.error,
|
|
1073
|
-
});
|
|
1074
|
-
continue;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
if (result.status !== 0 && parsed.diagnostics.length === 0) {
|
|
1078
|
-
failures.push({
|
|
1079
|
-
kind: "lint",
|
|
1080
|
-
stage: "lint-verify",
|
|
1081
|
-
file: relativePath,
|
|
1082
|
-
command: commandText(command),
|
|
1083
|
-
exitCode: result.status,
|
|
1084
|
-
message: result.stderr || "Oxlint verification failed without diagnostics",
|
|
1085
|
-
});
|
|
1086
|
-
continue;
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
diagnostics.push(...parsed.diagnostics);
|
|
1090
|
-
if (parsed.diagnostics.length > 0) {
|
|
1091
|
-
lintFailed.add(relativePath);
|
|
1002
|
+
const failures = [...selection.failures];
|
|
1003
|
+
for (const file of selection.files.filter(isPythonPath)) {
|
|
1004
|
+
const verified = verifyPythonFile(root, file);
|
|
1005
|
+
if (verified.failure) failures.push(verified.failure);
|
|
1006
|
+
else diagnostics.push(...verified.diagnostics);
|
|
1007
|
+
}
|
|
1008
|
+
if (selection.javascriptPaths.length > 0 && selection.failures.length === 0) {
|
|
1009
|
+
const result = await selection.runtime.runManagedLint({root, paths: selection.javascriptPaths.map((file) => path.relative(root, path.resolve(root, file)).split(path.sep).join("/")), output: "json"});
|
|
1010
|
+
for (const owner of result.results ?? []) {
|
|
1011
|
+
const parsed = normalizeManagedDiagnostics(owner.diagnostics, root, owner.scope, "");
|
|
1012
|
+
if (parsed.ok) diagnostics.push(...parsed.diagnostics);
|
|
1013
|
+
else failures.push({stage: "lint-verify", command: "managed lint", message: parsed.error});
|
|
1092
1014
|
}
|
|
1015
|
+
if (result.code === 2) failures.push({stage: "lint-verify", command: "managed lint", message: result.diagnostics?.join("\n") || result.results?.map((owner) => `${owner.stdout}\n${owner.stderr}`).join("\n") || "Lint verification failed without diagnostics"});
|
|
1093
1016
|
}
|
|
1094
|
-
|
|
1095
|
-
return {
|
|
1096
|
-
...emptyLintSummary(
|
|
1097
|
-
failures.length > 0 ? "operational_failure" : diagnostics.length > 0 ? "findings" : "clean",
|
|
1098
|
-
failures,
|
|
1099
|
-
),
|
|
1100
|
-
diagnostics,
|
|
1101
|
-
lint_failed: [...lintFailed],
|
|
1102
|
-
};
|
|
1017
|
+
return {...emptyLintSummary(failures.length ? "operational_failure" : diagnostics.length ? "findings" : "clean", failures), diagnostics, lint_failed: [...new Set(diagnostics.map((diagnostic) => diagnostic.file))]};
|
|
1103
1018
|
}
|
|
1104
1019
|
|
|
1105
1020
|
function extractSingleFilePath(payload) {
|
|
@@ -1191,7 +1106,7 @@ function emitProviderFeedback(provider, summary) {
|
|
|
1191
1106
|
}
|
|
1192
1107
|
}
|
|
1193
1108
|
|
|
1194
|
-
function runSingleFileMode(style) {
|
|
1109
|
+
async function runSingleFileMode(style) {
|
|
1195
1110
|
const payload = readStdinJson();
|
|
1196
1111
|
const root = repoRoot(process.cwd());
|
|
1197
1112
|
|
|
@@ -1204,7 +1119,7 @@ function runSingleFileMode(style) {
|
|
|
1204
1119
|
return;
|
|
1205
1120
|
}
|
|
1206
1121
|
|
|
1207
|
-
const summary = formatAndLintFiles(root, [filePath]);
|
|
1122
|
+
const summary = await formatAndLintFiles(root, [filePath]);
|
|
1208
1123
|
emitProviderFeedback(style, summary);
|
|
1209
1124
|
}
|
|
1210
1125
|
|
|
@@ -1220,7 +1135,6 @@ function dirtyFiles(root) {
|
|
|
1220
1135
|
.split("\n")
|
|
1221
1136
|
.map((line) => line.trim())
|
|
1222
1137
|
.filter(Boolean)
|
|
1223
|
-
.filter((filePath) => formattableSuffixes.has(path.extname(filePath)))
|
|
1224
1138
|
.filter((filePath) => !filePath.split("/").some((part) => ignoredParts.has(part))),
|
|
1225
1139
|
),
|
|
1226
1140
|
].sort();
|
|
@@ -1404,7 +1318,7 @@ function pruneProcessedFingerprints(state, current) {
|
|
|
1404
1318
|
}
|
|
1405
1319
|
}
|
|
1406
1320
|
|
|
1407
|
-
function runCodexSnapshotMode(mode) {
|
|
1321
|
+
async function runCodexSnapshotMode(mode) {
|
|
1408
1322
|
const payload = readStdinJson();
|
|
1409
1323
|
const cwd = String(payload.cwd ?? process.cwd());
|
|
1410
1324
|
const sessionId = String(payload.session_id ?? "");
|
|
@@ -1471,7 +1385,7 @@ function runCodexSnapshotMode(mode) {
|
|
|
1471
1385
|
return;
|
|
1472
1386
|
}
|
|
1473
1387
|
|
|
1474
|
-
const summary = formatAndLintFiles(root, touched, current);
|
|
1388
|
+
const summary = await formatAndLintFiles(root, touched, current);
|
|
1475
1389
|
if (summary.diagnostics.length > 0) {
|
|
1476
1390
|
applyDiagnosticRetryLimit(state, summary);
|
|
1477
1391
|
} else {
|
|
@@ -1613,29 +1527,27 @@ export const testHooks = {
|
|
|
1613
1527
|
codexStateFilePath,
|
|
1614
1528
|
formatCommandForPath,
|
|
1615
1529
|
lintCommandForPath,
|
|
1616
|
-
owningWorkspace,
|
|
1617
|
-
parseLintDiagnostics,
|
|
1618
1530
|
renderProviderFeedback,
|
|
1619
1531
|
toolCommand,
|
|
1620
1532
|
};
|
|
1621
1533
|
|
|
1622
|
-
function main() {
|
|
1534
|
+
async function main() {
|
|
1623
1535
|
const mode = process.argv[2] ?? "";
|
|
1624
1536
|
|
|
1625
1537
|
if (mode === "session-start" || mode === "post") {
|
|
1626
|
-
runCodexSnapshotMode(mode);
|
|
1538
|
+
await runCodexSnapshotMode(mode);
|
|
1627
1539
|
return;
|
|
1628
1540
|
}
|
|
1629
1541
|
|
|
1630
1542
|
if (mode === "claude" || mode === "cursor" || mode === "opencode") {
|
|
1631
|
-
runSingleFileMode(mode);
|
|
1543
|
+
await runSingleFileMode(mode);
|
|
1632
1544
|
return;
|
|
1633
1545
|
}
|
|
1634
1546
|
|
|
1635
1547
|
if (mode === "files") {
|
|
1636
1548
|
const root = repoRoot(process.cwd());
|
|
1637
1549
|
const summary = root
|
|
1638
|
-
? formatAndLintFiles(root, process.argv.slice(3))
|
|
1550
|
+
? await formatAndLintFiles(root, process.argv.slice(3))
|
|
1639
1551
|
: emptyLintSummary("operational_failure", [
|
|
1640
1552
|
{ stage: "config-load", command: "git rev-parse --show-toplevel", message: "Not inside a Git repository" },
|
|
1641
1553
|
]);
|
|
@@ -1646,7 +1558,7 @@ function main() {
|
|
|
1646
1558
|
if (mode === "preview") {
|
|
1647
1559
|
const root = repoRoot(process.cwd());
|
|
1648
1560
|
const summary = root
|
|
1649
|
-
? verifyLintFiles(root, process.argv.slice(3))
|
|
1561
|
+
? await verifyLintFiles(root, process.argv.slice(3))
|
|
1650
1562
|
: emptyLintSummary("operational_failure", [
|
|
1651
1563
|
{ stage: "config-load", command: "git rev-parse --show-toplevel", message: "Not inside a Git repository" },
|
|
1652
1564
|
]);
|
|
@@ -1658,5 +1570,5 @@ const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
|
|
|
1658
1570
|
const modulePath = fileURLToPath(import.meta.url);
|
|
1659
1571
|
|
|
1660
1572
|
if (invokedPath && path.basename(invokedPath) === path.basename(modulePath)) {
|
|
1661
|
-
main();
|
|
1573
|
+
await main();
|
|
1662
1574
|
}
|