@punks/cli 5.1.1 → 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.
Files changed (110) hide show
  1. package/AGENTS.md +28 -10
  2. package/dist/BASELINE_CHANGELOG.md +19 -1
  3. package/dist/CHANGELOG.md +49 -0
  4. package/dist/baseline/scaffold-baseline/baseline.json +5 -10
  5. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +1 -1
  6. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +0 -8
  7. package/dist/baseline/scaffold-baseline/data/hooks/format-edited-file.mjs +408 -309
  8. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +1 -0
  9. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +206 -58
  10. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +496 -29
  11. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.d.mts +55 -0
  12. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.mjs +323 -0
  13. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint-runner.test.ts +821 -0
  14. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.d.mts +97 -0
  15. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.mjs +658 -0
  16. package/dist/baseline/scaffold-baseline/data/scripts/managed-lint.test.ts +614 -0
  17. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents-validator.test.ts +39 -0
  18. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.mjs +8 -2
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/commands.md +6 -7
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +20 -19
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/define-handoffs.md +1 -1
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/model-state.md +1 -1
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/test-routes.md +1 -1
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/write-phases.md +2 -2
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/phases/write-router.md +1 -1
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/write-graph-based-skills/references/authoring-contract.md +8 -8
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/SKILL.md +1 -1
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/make-tsuite/SKILL.md +2 -2
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +21 -11
  32. package/dist/baseline/scaffold-baseline/skills/phases/debugging-phase/SKILL.md +3 -4
  33. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +2 -2
  34. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/debug.md +2 -2
  35. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/human-steering.md +25 -0
  36. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/implement.md +2 -2
  37. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +2 -2
  38. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +3 -2
  39. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/context-continuity.md +1 -1
  40. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/failure-continuity.md +1 -1
  41. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +4 -3
  42. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/AUTHORING-HANDOFF.md +9 -9
  43. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/SKILL.md +1 -1
  44. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/ensure-fog.md +1 -1
  45. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/grilling.md +1 -1
  46. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/human-steering.md +25 -0
  47. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/prototype.md +1 -1
  48. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/reconcile.md +1 -1
  49. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/research.md +1 -1
  50. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/router.md +1 -1
  51. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/state-graph.md +1 -1
  52. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/return-route.md +6 -5
  53. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/router.md +1 -1
  54. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +2 -1
  55. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +3 -3
  56. package/dist/baseline/scaffold-baseline.json +5 -5
  57. package/dist/baseline/scaffold-baseline.tgz +0 -0
  58. package/dist/data/AGENTS.md +22 -5
  59. package/dist/data/hooks/format-edited-file.mjs +237 -325
  60. package/dist/data/scripts/commit-gate-runner.mjs +206 -58
  61. package/dist/data/scripts/managed-lint-runner.d.mts +55 -0
  62. package/dist/data/scripts/managed-lint-runner.mjs +323 -0
  63. package/dist/data/scripts/managed-lint.d.mts +97 -0
  64. package/dist/data/scripts/managed-lint.mjs +658 -0
  65. package/dist/data/scripts/sync-subagents.mjs +8 -2
  66. package/dist/index.js +131 -153
  67. package/dist/skills/agnostic/cli/hi-cli/SKILL.md +2 -0
  68. package/dist/skills/agnostic/cli/hi-cli/references/commands.md +6 -7
  69. package/dist/skills/agnostic/cli/hi-cli/references/managed-lint.md +165 -0
  70. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +6 -5
  71. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/define-handoffs.md +1 -1
  72. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/model-state.md +1 -1
  73. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/test-routes.md +1 -1
  74. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/write-phases.md +2 -2
  75. package/dist/skills/agnostic/docs/write-graph-based-skills/phases/write-router.md +1 -1
  76. package/dist/skills/agnostic/docs/write-graph-based-skills/references/authoring-contract.md +8 -8
  77. package/dist/skills/agnostic/quality/autoreview/SKILL.md +1 -1
  78. package/dist/skills/agnostic/quality/make-tsuite/SKILL.md +2 -2
  79. package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +21 -11
  80. package/dist/skills/phases/debugging-phase/SKILL.md +3 -4
  81. package/dist/skills/phases/delivery-phase/SKILL.md +2 -2
  82. package/dist/skills/phases/delivery-phase/phases/debug.md +2 -2
  83. package/dist/skills/phases/delivery-phase/phases/human-steering.md +25 -0
  84. package/dist/skills/phases/delivery-phase/phases/implement.md +2 -2
  85. package/dist/skills/phases/delivery-phase/phases/review.md +2 -2
  86. package/dist/skills/phases/delivery-phase/phases/router.md +3 -2
  87. package/dist/skills/phases/delivery-phase/references/context-continuity.md +1 -1
  88. package/dist/skills/phases/delivery-phase/references/failure-continuity.md +1 -1
  89. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +4 -3
  90. package/dist/skills/phases/finder-phase/AUTHORING-HANDOFF.md +6 -6
  91. package/dist/skills/phases/finder-phase/SKILL.md +1 -1
  92. package/dist/skills/phases/finder-phase/phases/ensure-fog.md +1 -1
  93. package/dist/skills/phases/finder-phase/phases/grilling.md +1 -1
  94. package/dist/skills/phases/finder-phase/phases/human-steering.md +25 -0
  95. package/dist/skills/phases/finder-phase/phases/prototype.md +1 -1
  96. package/dist/skills/phases/finder-phase/phases/reconcile.md +1 -1
  97. package/dist/skills/phases/finder-phase/phases/research.md +1 -1
  98. package/dist/skills/phases/finder-phase/phases/router.md +1 -1
  99. package/dist/skills/phases/finder-phase/references/state-graph.md +1 -1
  100. package/dist/skills/phases/review-phase/phases/return-route.md +6 -5
  101. package/dist/skills/phases/review-phase/phases/router.md +1 -1
  102. package/dist/skills/phases/review-phase/phases/run-review.md +2 -1
  103. package/dist/skills/phases/review-phase/references/state-graph.md +3 -3
  104. package/package.json +12 -6
  105. package/dist/baseline/scaffold-baseline/skills/agnostic/generic/handback/SKILL.md +0 -27
  106. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/handback.md +0 -27
  107. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/handback.md +0 -29
  108. package/dist/skills/agnostic/generic/handback/SKILL.md +0 -27
  109. package/dist/skills/phases/delivery-phase/phases/handback.md +0 -27
  110. package/dist/skills/phases/finder-phase/phases/handback.md +0 -29
@@ -2,7 +2,11 @@
2
2
 
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import {
5
- accessSync,
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,33 @@ 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 commandExists(command) {
208
- const pathValue = process.env.PATH ?? process.env.Path;
209
- if (!pathValue) {
210
- return false;
211
- }
212
-
213
- const isWindows = os.platform() === "win32";
214
- const pathEntries = pathValue.split(isWindows ? ";" : ":").filter(Boolean);
215
- const pathExtensions = isWindows
216
- ? (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)
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 (
200
+ value.name !== tool ||
201
+ typeof bin !== "string" ||
202
+ path.isAbsolute(bin) ||
203
+ bin.split(/[\\/]/u).includes("..")
204
+ )
205
+ throw new Error(`Invalid repository-local ${tool} executable`);
206
+ return [path.resolve(path.dirname(manifest), bin), ...args];
232
207
  }
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";
265
- }
266
-
267
- return null;
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];
208
+ if (current === root || path.dirname(current) === current) break;
209
+ current = path.dirname(current);
290
210
  }
291
-
292
- return ["npx", tool, ...args];
211
+ // An intentionally missing local path becomes a normal operational failure in runCommand.
212
+ return [path.join(root || directory, "node_modules/.bin", tool), ...args];
293
213
  }
294
214
 
295
215
  function nearestPythonProject(root, relativePath) {
@@ -518,105 +438,258 @@ function normalizeDiagnostic(diagnostic, root, fallbackPath, temporaryPath = nul
518
438
  return normalized;
519
439
  }
520
440
 
521
- function parseLintDiagnostics(stdout, root, fallbackPath, temporaryPath = null) {
522
- let parsed;
523
- try {
524
- parsed = JSON.parse(stdout || "");
525
- } catch {
526
- return { ok: false, error: "Oxlint returned malformed JSON" };
527
- }
528
-
529
- if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.diagnostics)) {
530
- return { ok: false, error: "Oxlint JSON did not contain diagnostics" };
441
+ function normalizeManagedDiagnostics(report, root, scope, fallbackPath) {
442
+ if (!Array.isArray(report))
443
+ return { ok: false, error: "Oxlint did not return validated diagnostics" };
444
+ const diagnostics = [];
445
+ for (const diagnostic of report) {
446
+ let filename = fallbackPath;
447
+ if (typeof diagnostic.filename === "string" && diagnostic.filename.length > 0) {
448
+ filename = path
449
+ .relative(root, path.resolve(root, scope, diagnostic.filename))
450
+ .split(path.sep)
451
+ .join("/");
452
+ if (filename === ".." || filename.startsWith("../") || path.isAbsolute(filename))
453
+ return { ok: false, error: "Oxlint diagnostic escaped the managed repository" };
454
+ }
455
+ diagnostics.push(normalizeDiagnostic({ ...diagnostic, filename }, root, fallbackPath));
531
456
  }
457
+ return { ok: true, diagnostics };
458
+ }
532
459
 
533
- const diagnostics = parsed.diagnostics.map((diagnostic) =>
534
- normalizeDiagnostic(diagnostic, root, fallbackPath, temporaryPath),
460
+ async function lintRuntime(root) {
461
+ const canonical = path.join(root, ".agents/scripts/managed-lint-runner.mjs");
462
+ const local = new URL("../scripts/managed-lint-runner.mjs", import.meta.url);
463
+ const runner = await import(existsSync(canonical) ? pathToFileURL(canonical).href : local.href);
464
+ const resolver = await import(
465
+ existsSync(canonical)
466
+ ? pathToFileURL(path.join(root, ".agents/scripts/managed-lint.mjs")).href
467
+ : new URL("../scripts/managed-lint.mjs", import.meta.url).href
535
468
  );
536
- if (diagnostics.some((diagnostic) => diagnostic === null)) {
537
- return { ok: false, error: "Oxlint JSON contained an invalid diagnostic" };
469
+ return { ...runner, ...resolver };
470
+ }
471
+
472
+ async function selectedLint(root, filePaths) {
473
+ try {
474
+ const runtime = await lintRuntime(root);
475
+ const paths = filePaths.map((file) =>
476
+ path.relative(root, path.resolve(root, file)).split(path.sep).join("/"),
477
+ );
478
+ const resolution = await runtime.loadManagedLint(root, paths);
479
+ if (resolution.status === "disabled") return { runtime, routes: [] };
480
+ if (resolution.status !== "ready") throw new Error(resolution.diagnostics.join("\n"));
481
+ return { runtime, routes: resolution.routes };
482
+ } catch (error) {
483
+ return {
484
+ failure: emptyLintSummary("operational_failure", [
485
+ { stage: "config-load", command: "managed lint selection", message: error.message },
486
+ ]),
487
+ };
538
488
  }
489
+ }
539
490
 
540
- return { ok: true, diagnostics };
491
+ // Python shares quality exclusions, but does not require JavaScript owner selection.
492
+ function qualityExclusions(root) {
493
+ let settings;
494
+ try {
495
+ settings = JSON.parse(readFileSync(path.join(root, ".devpunks/settings.json"), "utf8"));
496
+ } catch (error) {
497
+ if (error?.code === "ENOENT") return [];
498
+ throw error;
499
+ }
500
+ const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
501
+ if (!record(settings) || (settings.lint !== undefined && !record(settings.lint))) {
502
+ throw new TypeError("Managed quality settings and lint must be objects");
503
+ }
504
+ const exclude = settings.lint?.exclude;
505
+ if (exclude === undefined) return [];
506
+ if (
507
+ !Array.isArray(exclude) ||
508
+ !exclude.every(
509
+ (pattern) =>
510
+ typeof pattern === "string" &&
511
+ pattern.length > 0 &&
512
+ !pattern.startsWith("!") &&
513
+ !pattern.includes("\\") &&
514
+ !path.posix.isAbsolute(pattern) &&
515
+ pattern.split("/").every((part) => part !== ".." && part !== "") &&
516
+ path.posix.normalize(pattern) === pattern,
517
+ )
518
+ )
519
+ throw new TypeError("lint.exclude must be a list of repository-relative patterns.");
520
+ return exclude;
541
521
  }
542
522
 
543
- function runSafeJavascriptLint(workspace, root, relativePath, content) {
544
- const workspacePath = workspaceRelativePath(workspace, root, relativePath);
545
- const directory = path.dirname(path.join(workspace, workspacePath));
546
- const temporaryDirectory = path.join(directory, `.hi-lint-stage-${randomUUID()}`);
547
- const temporaryPath = path.join(temporaryDirectory, path.basename(workspacePath));
548
- const temporaryRelativePath = path.relative(workspace, temporaryPath).split(path.sep).join("/");
523
+ async function selectedQuality(root, filePaths) {
524
+ const caseSemantics = pathCaseSemantics(root);
525
+ if (caseSemantics === "unknown") {
526
+ return {
527
+ failure: emptyLintSummary("operational_failure", [
528
+ {
529
+ stage: "config-load",
530
+ command: "path case semantics",
531
+ message: "Unable to determine path case semantics",
532
+ },
533
+ ]),
534
+ };
535
+ }
536
+
537
+ const caseInsensitivePaths = caseSemantics === "case-insensitive";
538
+ const managedPaths = loadManagedPaths(root, caseInsensitivePaths);
539
+ if (managedPaths === null) {
540
+ return {
541
+ failure: emptyLintSummary("operational_failure", [
542
+ {
543
+ stage: "config-load",
544
+ command: scaffoldManifestPath,
545
+ message: "Managed scaffold manifest is invalid",
546
+ },
547
+ ]),
548
+ };
549
+ }
549
550
 
550
551
  try {
551
- mkdirSync(temporaryDirectory, { mode: 0o700 });
552
- writeFileSync(temporaryPath, content, { flag: "wx", mode: 0o600 });
553
- const fixCommand = toolCommand(workspace, "oxlint", [
554
- "--fix",
555
- "--format",
556
- "json",
557
- temporaryRelativePath,
558
- ]);
559
- const fixResult = runCommand(workspace, fixCommand);
560
- if (fixResult.error !== undefined) {
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
- }
552
+ const runtime = await lintRuntime(root);
553
+ const exclude = qualityExclusions(root);
554
+ const eligible = [
555
+ ...new Set(
556
+ filePaths
557
+ .map((file) => normalizeRelativePath(root, file, managedPaths, caseInsensitivePaths))
558
+ .filter(
559
+ (file) =>
560
+ file !== null && !runtime.isManagedQualityPathExcluded({ path: file, exclude }),
561
+ ),
562
+ ),
563
+ ];
564
+ const nonPythonPaths = filePaths.filter((file) => !isPythonPath(file));
565
+ const selection =
566
+ nonPythonPaths.length > 0
567
+ ? await selectedLint(root, nonPythonPaths)
568
+ : { runtime, routes: [] };
569
+ // Keep raw resolver-owned dependency triggers, including scaffold metadata.
570
+ // The resolver handles excluded-only source; unrelated non-JS files stay independent.
571
+ const requiresSelection = nonPythonPaths.some((file) =>
572
+ javascriptFormattableSuffixes.has(path.extname(file)),
573
+ );
574
+ const javascriptPaths = selection.failure && !requiresSelection ? [] : nonPythonPaths;
575
+ const routes = selection.routes ?? [];
576
+ const selectedFiles = new Set(routes.flatMap((route) => route.files));
577
+ return {
578
+ runtime,
579
+ routes,
580
+ javascriptPaths,
581
+ files: eligible.filter((file) => isPythonPath(file) || selectedFiles.has(file)),
582
+ failures: javascriptPaths.length > 0 ? (selection.failure?.failures ?? []) : [],
583
+ };
584
+ } catch (error) {
585
+ return {
586
+ failure: emptyLintSummary("operational_failure", [
587
+ { stage: "config-load", command: "managed quality exclusions", message: error.message },
588
+ ]),
589
+ };
590
+ }
591
+ }
569
592
 
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
- };
593
+ function copyLintMirror(root, mirror) {
594
+ const visit = (source, destination) => {
595
+ mkdirSync(destination, { recursive: true });
596
+ for (const entry of readdirSync(source, { withFileTypes: true })) {
597
+ const relative = path.relative(root, path.join(source, entry.name)).split(path.sep).join("/");
598
+ if (
599
+ [".git", ".turbo", ".next", "coverage", "dist", "build", "__pycache__"].includes(
600
+ entry.name,
601
+ ) ||
602
+ /^(?:\.devpunks\/(?:delivery|cache|replaced-scaffold)|\.devpunks-cache)(?:\/|$)/u.test(
603
+ relative,
604
+ )
605
+ )
606
+ continue;
607
+ const from = path.join(source, entry.name);
608
+ const to = path.join(destination, entry.name);
609
+ if (entry.name === "node_modules") {
610
+ symlinkSync(realpathSync(from), to, "dir");
611
+ continue;
612
+ }
613
+ if (entry.isSymbolicLink()) {
614
+ const resolved = realpathSync(from);
615
+ const relativeTarget = path.relative(root, resolved);
616
+ if (
617
+ relativeTarget === ".." ||
618
+ relativeTarget.startsWith(`..${path.sep}`) ||
619
+ path.isAbsolute(relativeTarget)
620
+ )
621
+ throw new Error(
622
+ `Cannot prove temporary lint parity for external repository symlink: ${path.relative(root, from)}`,
623
+ );
624
+ const link = readlinkSync(from);
625
+ symlinkSync(path.isAbsolute(link) ? path.resolve(mirror, relativeTarget) : link, to);
626
+ continue;
627
+ }
628
+ if (entry.isDirectory()) visit(from, to);
629
+ else if (entry.isFile()) cpSync(from, to);
630
+ else
631
+ throw new Error(`Cannot mirror non-regular repository input: ${path.relative(root, from)}`);
585
632
  }
633
+ };
634
+ visit(root, mirror);
635
+ }
586
636
 
587
- const parsed = parseLintDiagnostics(
588
- verificationResult.stdout,
589
- root,
637
+ async function runSafeJavascriptLint(workspace, root, relativePath, content, route, runtime) {
638
+ const mirror = mkdtempSync(path.join(os.tmpdir(), "hi-lint-mirror-"));
639
+ let command;
640
+ try {
641
+ copyLintMirror(root, mirror);
642
+ for (const input of [route.config, ...route.inputs]) {
643
+ if (existsSync(path.join(root, input)) && !existsSync(path.join(mirror, input)))
644
+ throw new Error(`Required lint input is excluded from safe mirror: ${input}`);
645
+ }
646
+ const target = path.join(mirror, relativePath);
647
+ if (!lstatSync(target).isFile())
648
+ throw new Error("Temporary lint target must be a copied regular file");
649
+ writeFileSync(target, content);
650
+ command = await runtime.buildManagedLintCommand({
651
+ root: mirror,
652
+ route,
653
+ output: "json",
654
+ logicalSourcePath: relativePath,
655
+ physicalInputPath: target,
656
+ });
657
+ if (command.status !== "ready") throw new Error(command.diagnostics.join("\n"));
658
+ const fixed = runtime.executeManagedLintCommand({
659
+ root: mirror,
660
+ command: { ...command, args: ["--fix", ...command.args] },
661
+ });
662
+ if (fixed.code === 2)
663
+ throw new Error(["Oxlint fix failed", fixed.stdout, fixed.stderr].filter(Boolean).join("\n"));
664
+ const fixedDiagnostics = normalizeManagedDiagnostics(
665
+ fixed.diagnostics,
666
+ mirror,
667
+ route.scope,
590
668
  relativePath,
591
- temporaryRelativePath,
592
669
  );
593
- if (!parsed.ok) {
594
- return {
595
- ok: false,
596
- stage: "lint-verify",
597
- command: commandText(verificationCommand),
598
- exitCode: verificationResult.status,
599
- error: parsed.error,
600
- };
601
- }
602
-
603
- if (verificationResult.status !== 0 && parsed.diagnostics.length === 0) {
604
- return {
605
- ok: false,
606
- stage: "lint-verify",
607
- command: commandText(verificationCommand),
608
- exitCode: verificationResult.status,
609
- error: verificationResult.stderr || "Oxlint verification failed without diagnostics",
610
- };
611
- }
612
-
613
- return { ok: true, content: fixedContent, diagnostics: parsed.diagnostics };
670
+ if (!fixedDiagnostics.ok) throw new Error(fixedDiagnostics.error);
671
+ const result = runtime.executeManagedLintCommand({ root: mirror, command });
672
+ if (result.code === 2)
673
+ throw new Error(
674
+ ["Oxlint verification failed", result.stdout, result.stderr].filter(Boolean).join("\n"),
675
+ );
676
+ const parsed = normalizeManagedDiagnostics(
677
+ result.diagnostics,
678
+ mirror,
679
+ route.scope,
680
+ relativePath,
681
+ );
682
+ if (!parsed.ok) throw new Error(parsed.error);
683
+ return { ok: true, content: readFileSync(target), diagnostics: parsed.diagnostics };
684
+ } catch (error) {
685
+ return {
686
+ ok: false,
687
+ stage: "lint-verify",
688
+ command: command ? commandText([command.executable, ...command.args]) : "managed lint mirror",
689
+ error: error.message,
690
+ };
614
691
  } finally {
615
- try {
616
- rmSync(temporaryDirectory, { force: true, recursive: true });
617
- } catch {
618
- // The temporary stage is producer-owned; an absent file is already clean.
619
- }
692
+ rmSync(mirror, { force: true, recursive: true });
620
693
  }
621
694
  }
622
695
 
@@ -857,49 +930,16 @@ function commandText(command) {
857
930
  return Array.isArray(command) ? command.join(" ") : String(command ?? "");
858
931
  }
859
932
 
860
- function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
861
- const caseSemantics = pathCaseSemantics(root);
862
- if (caseSemantics === "unknown") {
863
- return emptyLintSummary("operational_failure", [
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
- }
933
+ async function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
934
+ const selection = await selectedQuality(root, filePaths);
935
+ if (selection.failure) return selection.failure;
936
+ const normalizedFiles = selection.files;
897
937
 
898
938
  const formatted = [];
899
939
  const formatFailed = [];
900
940
  const lintFailed = [];
901
941
  const diagnostics = [];
902
- const failures = [];
942
+ const failures = [...selection.failures];
903
943
 
904
944
  for (const relativePath of normalizedFiles) {
905
945
  const expectedFingerprint = expectedFingerprints?.[relativePath];
@@ -920,9 +960,23 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
920
960
  continue;
921
961
  }
922
962
 
923
- const workspace = owningWorkspace(root, relativePath);
963
+ const route = selection.routes.find((item) => item.files.includes(relativePath));
964
+ const workspace = isPythonPath(relativePath) ? root : path.resolve(root, route.scope);
924
965
  const workspacePath = workspaceRelativePath(workspace, root, relativePath);
925
- const formatCommand = formatCommandForPath(workspace, workspacePath);
966
+ let formatCommand;
967
+ try {
968
+ formatCommand = formatCommandForPath(workspace, workspacePath);
969
+ } catch (error) {
970
+ closeSync(target.descriptor);
971
+ failures.push({
972
+ kind: "format",
973
+ stage: "format",
974
+ file: relativePath,
975
+ command: "local formatter",
976
+ message: error.message,
977
+ });
978
+ continue;
979
+ }
926
980
 
927
981
  // Keep mutating tools off the live path; stage output before claiming the validated target.
928
982
  const formatResult = runTransformCommand(workspace, formatCommand, target.content);
@@ -941,7 +995,11 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
941
995
  continue;
942
996
  }
943
997
 
944
- const lintCommand = lintCommandForPath(workspace, workspacePath, true);
998
+ const lintCommand = isPythonPath(relativePath)
999
+ ? lintCommandForPath(workspace, workspacePath, true)
1000
+ : javascriptLintableSuffixes.has(path.extname(relativePath))
1001
+ ? ["managed lint"]
1002
+ : null;
945
1003
  let formattedContent = formatResult.output;
946
1004
  let lintResult = null;
947
1005
  if (lintCommand !== null && isPythonPath(relativePath)) {
@@ -950,7 +1008,14 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
950
1008
  formattedContent = lintResult.output;
951
1009
  }
952
1010
  } else if (lintCommand !== null) {
953
- lintResult = runSafeJavascriptLint(workspace, root, relativePath, formattedContent);
1011
+ lintResult = await runSafeJavascriptLint(
1012
+ workspace,
1013
+ root,
1014
+ relativePath,
1015
+ formattedContent,
1016
+ route,
1017
+ selection.runtime,
1018
+ );
954
1019
  if (lintResult.ok) {
955
1020
  formattedContent = lintResult.content;
956
1021
  diagnostics.push(...lintResult.diagnostics);
@@ -991,6 +1056,16 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
991
1056
  }
992
1057
  }
993
1058
 
1059
+ if (selection.routes.some((route) => route.triggered)) {
1060
+ const verified = await verifyLintFiles(root, filePaths);
1061
+ const known = new Set(diagnostics.map((diagnostic) => JSON.stringify(diagnostic)));
1062
+ for (const diagnostic of verified.diagnostics) {
1063
+ if (!known.has(JSON.stringify(diagnostic))) diagnostics.push(diagnostic);
1064
+ }
1065
+ failures.push(...verified.failures);
1066
+ for (const file of verified.lint_failed) if (!lintFailed.includes(file)) lintFailed.push(file);
1067
+ }
1068
+
994
1069
  const result =
995
1070
  failures.length > 0 ? "operational_failure" : diagnostics.length > 0 ? "findings" : "clean";
996
1071
  return {
@@ -1020,87 +1095,114 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
1020
1095
  };
1021
1096
  }
1022
1097
 
1023
- function verifyLintFiles(root, filePaths) {
1024
- const caseSemantics = pathCaseSemantics(root);
1025
- const managedPaths = loadManagedPaths(root, caseSemantics === "case-insensitive");
1026
- if (caseSemantics === "unknown" || managedPaths === null) {
1027
- return emptyLintSummary("operational_failure", [
1028
- {
1029
- stage: "config-load",
1030
- command: scaffoldManifestPath,
1031
- message: "Lint preview cannot validate repository state",
1032
- },
1033
- ]);
1034
- }
1035
-
1036
- const normalizedFiles = [
1037
- ...new Set(
1038
- filePaths
1039
- .map((filePath) =>
1040
- normalizeRelativePath(root, filePath, managedPaths, caseSemantics === "case-insensitive"),
1041
- )
1042
- .filter((filePath) => filePath && isLintablePath(filePath)),
1043
- ),
1098
+ function verifyPythonFile(root, relativePath) {
1099
+ const command = [
1100
+ "uv",
1101
+ "run",
1102
+ "--project",
1103
+ nearestPythonProject(root, relativePath),
1104
+ "ruff",
1105
+ "check",
1106
+ "--output-format",
1107
+ "json",
1108
+ "--stdin-filename",
1109
+ relativePath,
1110
+ "-",
1044
1111
  ];
1045
- const diagnostics = [];
1046
- const failures = [];
1047
- const lintFailed = new Set();
1048
-
1049
- for (const relativePath of normalizedFiles) {
1050
- const workspace = owningWorkspace(root, relativePath);
1051
- const workspacePath = workspaceRelativePath(workspace, root, relativePath);
1052
- const command = toolCommand(workspace, "oxlint", ["--format", "json", workspacePath]);
1053
- const result = runCommand(workspace, command);
1054
- if (result.error !== undefined) {
1055
- failures.push({
1056
- kind: "lint",
1112
+ const target = openFormattingTarget(path.join(root, relativePath));
1113
+ if (target === null)
1114
+ return {
1115
+ failure: {
1057
1116
  stage: "lint-verify",
1058
1117
  file: relativePath,
1059
1118
  command: commandText(command),
1060
- exitCode: result.status,
1061
- message: `Oxlint could not start: ${result.error.message}`,
1062
- });
1063
- continue;
1064
- }
1065
-
1066
- const parsed = parseLintDiagnostics(result.stdout, root, relativePath, workspacePath);
1067
- if (!parsed.ok) {
1068
- failures.push({
1069
- kind: "lint",
1119
+ message: "Edited file changed before verification",
1120
+ },
1121
+ };
1122
+ try {
1123
+ const result = runTransformCommand(root, command, target.content);
1124
+ if (result.error || ![0, 1].includes(result.status))
1125
+ throw new Error(result.error?.message ?? (result.stderr || "Ruff verification failed"));
1126
+ const report = JSON.parse(result.output.toString());
1127
+ if (
1128
+ !Array.isArray(report) ||
1129
+ report.some(
1130
+ (item) =>
1131
+ !item ||
1132
+ typeof item.message !== "string" ||
1133
+ typeof item.code !== "string" ||
1134
+ !Number.isInteger(item.location?.row) ||
1135
+ !Number.isInteger(item.location?.column),
1136
+ )
1137
+ )
1138
+ throw new Error("Ruff returned invalid diagnostics");
1139
+ if (result.status !== 0 && report.length === 0)
1140
+ throw new Error(result.stderr || "Ruff failed without diagnostics");
1141
+ return {
1142
+ diagnostics: report.map((item) => ({
1143
+ file: relativePath,
1144
+ rule: item.code,
1145
+ severity: "error",
1146
+ line: item.location.row,
1147
+ column: item.location.column,
1148
+ message: item.message,
1149
+ ...(typeof item.url === "string" ? { documentation: item.url } : {}),
1150
+ })),
1151
+ };
1152
+ } catch (error) {
1153
+ return {
1154
+ failure: {
1070
1155
  stage: "lint-verify",
1071
1156
  file: relativePath,
1072
1157
  command: commandText(command),
1073
- exitCode: result.status,
1074
- message: parsed.error,
1075
- });
1076
- continue;
1077
- }
1158
+ message: error.message,
1159
+ },
1160
+ };
1161
+ } finally {
1162
+ closeSync(target.descriptor);
1163
+ }
1164
+ }
1078
1165
 
1079
- if (result.status !== 0 && parsed.diagnostics.length === 0) {
1166
+ async function verifyLintFiles(root, filePaths) {
1167
+ const selection = await selectedQuality(root, filePaths);
1168
+ if (selection.failure) return selection.failure;
1169
+ const diagnostics = [];
1170
+ const failures = [...selection.failures];
1171
+ for (const file of selection.files.filter(isPythonPath)) {
1172
+ const verified = verifyPythonFile(root, file);
1173
+ if (verified.failure) failures.push(verified.failure);
1174
+ else diagnostics.push(...verified.diagnostics);
1175
+ }
1176
+ if (selection.javascriptPaths.length > 0 && selection.failures.length === 0) {
1177
+ const result = await selection.runtime.runManagedLint({
1178
+ root,
1179
+ paths: selection.javascriptPaths.map((file) =>
1180
+ path.relative(root, path.resolve(root, file)).split(path.sep).join("/"),
1181
+ ),
1182
+ output: "json",
1183
+ });
1184
+ for (const owner of result.results ?? []) {
1185
+ const parsed = normalizeManagedDiagnostics(owner.diagnostics, root, owner.scope, "");
1186
+ if (parsed.ok) diagnostics.push(...parsed.diagnostics);
1187
+ else failures.push({ stage: "lint-verify", command: "managed lint", message: parsed.error });
1188
+ }
1189
+ if (result.code === 2)
1080
1190
  failures.push({
1081
- kind: "lint",
1082
1191
  stage: "lint-verify",
1083
- file: relativePath,
1084
- command: commandText(command),
1085
- exitCode: result.status,
1086
- message: result.stderr || "Oxlint verification failed without diagnostics",
1192
+ command: "managed lint",
1193
+ message:
1194
+ result.diagnostics?.join("\n") ||
1195
+ result.results?.map((owner) => `${owner.stdout}\n${owner.stderr}`).join("\n") ||
1196
+ "Lint verification failed without diagnostics",
1087
1197
  });
1088
- continue;
1089
- }
1090
-
1091
- diagnostics.push(...parsed.diagnostics);
1092
- if (parsed.diagnostics.length > 0) {
1093
- lintFailed.add(relativePath);
1094
- }
1095
1198
  }
1096
-
1097
1199
  return {
1098
1200
  ...emptyLintSummary(
1099
- failures.length > 0 ? "operational_failure" : diagnostics.length > 0 ? "findings" : "clean",
1201
+ failures.length ? "operational_failure" : diagnostics.length ? "findings" : "clean",
1100
1202
  failures,
1101
1203
  ),
1102
1204
  diagnostics,
1103
- lint_failed: [...lintFailed],
1205
+ lint_failed: [...new Set(diagnostics.map((diagnostic) => diagnostic.file))],
1104
1206
  };
1105
1207
  }
1106
1208
 
@@ -1193,7 +1295,7 @@ function emitProviderFeedback(provider, summary) {
1193
1295
  }
1194
1296
  }
1195
1297
 
1196
- function runSingleFileMode(style) {
1298
+ async function runSingleFileMode(style) {
1197
1299
  const payload = readStdinJson();
1198
1300
  const root = repoRoot(process.cwd());
1199
1301
 
@@ -1206,7 +1308,7 @@ function runSingleFileMode(style) {
1206
1308
  return;
1207
1309
  }
1208
1310
 
1209
- const summary = formatAndLintFiles(root, [filePath]);
1311
+ const summary = await formatAndLintFiles(root, [filePath]);
1210
1312
  emitProviderFeedback(style, summary);
1211
1313
  }
1212
1314
 
@@ -1222,7 +1324,6 @@ function dirtyFiles(root) {
1222
1324
  .split("\n")
1223
1325
  .map((line) => line.trim())
1224
1326
  .filter(Boolean)
1225
- .filter((filePath) => formattableSuffixes.has(path.extname(filePath)))
1226
1327
  .filter((filePath) => !filePath.split("/").some((part) => ignoredParts.has(part))),
1227
1328
  ),
1228
1329
  ].sort();
@@ -1404,7 +1505,7 @@ function pruneProcessedFingerprints(state, current) {
1404
1505
  }
1405
1506
  }
1406
1507
 
1407
- function runCodexSnapshotMode(mode) {
1508
+ async function runCodexSnapshotMode(mode) {
1408
1509
  const payload = readStdinJson();
1409
1510
  const cwd = String(payload.cwd ?? process.cwd());
1410
1511
  const sessionId = String(payload.session_id ?? "");
@@ -1471,7 +1572,7 @@ function runCodexSnapshotMode(mode) {
1471
1572
  return;
1472
1573
  }
1473
1574
 
1474
- const summary = formatAndLintFiles(root, touched, current);
1575
+ const summary = await formatAndLintFiles(root, touched, current);
1475
1576
  if (summary.diagnostics.length > 0) {
1476
1577
  applyDiagnosticRetryLimit(state, summary);
1477
1578
  } else {
@@ -1616,29 +1717,27 @@ export const testHooks = {
1616
1717
  codexStateFilePath,
1617
1718
  formatCommandForPath,
1618
1719
  lintCommandForPath,
1619
- owningWorkspace,
1620
- parseLintDiagnostics,
1621
1720
  renderProviderFeedback,
1622
1721
  toolCommand,
1623
1722
  };
1624
1723
 
1625
- function main() {
1724
+ async function main() {
1626
1725
  const mode = process.argv[2] ?? "";
1627
1726
 
1628
1727
  if (mode === "session-start" || mode === "post") {
1629
- runCodexSnapshotMode(mode);
1728
+ await runCodexSnapshotMode(mode);
1630
1729
  return;
1631
1730
  }
1632
1731
 
1633
1732
  if (mode === "claude" || mode === "cursor" || mode === "opencode") {
1634
- runSingleFileMode(mode);
1733
+ await runSingleFileMode(mode);
1635
1734
  return;
1636
1735
  }
1637
1736
 
1638
1737
  if (mode === "files") {
1639
1738
  const root = repoRoot(process.cwd());
1640
1739
  const summary = root
1641
- ? formatAndLintFiles(root, process.argv.slice(3))
1740
+ ? await formatAndLintFiles(root, process.argv.slice(3))
1642
1741
  : emptyLintSummary("operational_failure", [
1643
1742
  {
1644
1743
  stage: "config-load",
@@ -1653,7 +1752,7 @@ function main() {
1653
1752
  if (mode === "preview") {
1654
1753
  const root = repoRoot(process.cwd());
1655
1754
  const summary = root
1656
- ? verifyLintFiles(root, process.argv.slice(3))
1755
+ ? await verifyLintFiles(root, process.argv.slice(3))
1657
1756
  : emptyLintSummary("operational_failure", [
1658
1757
  {
1659
1758
  stage: "config-load",
@@ -1669,5 +1768,5 @@ const invokedPath = process.argv[1] ? path.resolve(process.argv[1]) : "";
1669
1768
  const modulePath = fileURLToPath(import.meta.url);
1670
1769
 
1671
1770
  if (invokedPath && path.basename(invokedPath) === path.basename(modulePath)) {
1672
- main();
1771
+ await main();
1673
1772
  }