@punks/cli 4.0.2 → 4.0.3

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 (156) hide show
  1. package/dist/BASELINE_CHANGELOG.md +24 -0
  2. package/dist/CHANGELOG.md +17 -0
  3. package/dist/baseline/scaffold-baseline/baseline.json +5 -5
  4. package/dist/baseline/scaffold-baseline/data/catalog/lint-assets.json +10 -4
  5. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +0 -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 +602 -101
  8. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.d.ts +11 -0
  9. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.mjs +103 -0
  10. package/dist/baseline/scaffold-baseline/data/scripts/commit-gate-runner.test.ts +144 -0
  11. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/claude.mjs +1 -0
  12. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/codex.mjs +1 -0
  13. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/cursor.mjs +1 -0
  14. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/opencode.mjs +1 -0
  15. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/contract.ts +24 -33
  16. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/core.mjs +4 -0
  17. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/core.test.ts +61 -0
  18. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/lint-feedback.test.ts +123 -0
  19. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/test-fixtures/claude/actions.json +1 -0
  20. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/test-fixtures/codex/actions.json +2 -1
  21. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/test-fixtures/cursor/projection.json +1 -0
  22. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/test-fixtures/opencode/projection.json +1 -0
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/docs-onboarding/SKILL.md +2 -2
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/SKILL.md +32 -32
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +7 -7
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/readiness.md +14 -13
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +26 -19
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/SKILL.md +2 -2
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/scripts/autoreview +3 -0
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/brainstorm/SKILL.md +12 -0
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
  32. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/EXAMPLES.md +9 -9
  33. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/REFERENCE.md +43 -55
  34. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/SKILL.md +68 -63
  35. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +26 -29
  36. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/story-shape.md +5 -5
  37. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +1 -1
  38. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +2 -2
  39. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +1 -1
  40. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +2 -2
  41. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/business-projection.md +19 -24
  42. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/delivery-status.md +17 -13
  43. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/fog-intake.md +45 -48
  44. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/functional-projection.md +16 -21
  45. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/normalization.md +14 -14
  46. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/project-context.md +32 -27
  47. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/providers/github.md +105 -150
  48. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/providers/linear.md +111 -181
  49. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/references/technical-projection.md +51 -47
  50. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/scripts/validate-task-blocker-graph.mjs +49 -35
  51. package/dist/baseline/scaffold-baseline/skills/agnostic/security/security-best-practices/references/javascript-typescript-vue-web-frontend-security.md +1 -1
  52. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/eas-update-insights/references/update-insights-schema.md +2 -6
  53. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/expo-skill-eval/SKILL.md +6 -7
  54. package/dist/baseline/scaffold-baseline/skills/frameworks/pulumi/pulumi-best-practices/SKILL.md +1 -3
  55. package/dist/baseline/scaffold-baseline/skills/frameworks/pulumi/pulumi-component/SKILL.md +2 -14
  56. package/dist/baseline/scaffold-baseline/skills/frameworks/tanstack-query/tanstack-query/references/best-practices.md +7 -1
  57. package/dist/baseline/scaffold-baseline/skills/frameworks/tanstack-query/tanstack-query/templates/devtools-setup.tsx +4 -0
  58. package/dist/baseline/scaffold-baseline/skills/frameworks/trpc/tanstack-query/references/best-practices.md +7 -1
  59. package/dist/baseline/scaffold-baseline/skills/frameworks/trpc/tanstack-query/templates/devtools-setup.tsx +4 -0
  60. package/dist/baseline/scaffold-baseline/skills/languages/typescript/quality-types/SKILL.md +1 -3
  61. package/dist/baseline/scaffold-baseline/skills/phases/business-finder/SKILL.md +29 -16
  62. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +10 -8
  63. package/dist/baseline/scaffold-baseline/skills/phases/design-phase/phases/backlog.md +26 -17
  64. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/AUTHORING-HANDOFF.md +51 -261
  65. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/SKILL.md +22 -25
  66. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/ensure-fog.md +13 -23
  67. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/grilling.md +40 -0
  68. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/handback.md +11 -18
  69. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/prototype.md +13 -21
  70. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/reconcile.md +21 -35
  71. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/research.md +13 -18
  72. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/return-target.md +14 -25
  73. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/router.md +22 -56
  74. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/entrypoint-contract.md +25 -26
  75. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/root-routing.md +12 -20
  76. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/runtime-handoff.md +17 -39
  77. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/references/state-graph.md +27 -49
  78. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/scripts/finder-contract.mjs +40 -359
  79. package/dist/baseline/scaffold-baseline/skills/phases/functional-finder/SKILL.md +29 -62
  80. package/dist/baseline/scaffold-baseline/skills/phases/requirements-phase/SKILL.md +49 -13
  81. package/dist/baseline/scaffold-baseline.json +5 -5
  82. package/dist/baseline/scaffold-baseline.tgz +0 -0
  83. package/dist/data/hooks/format-edited-file.d.mts +21 -0
  84. package/dist/data/hooks/format-edited-file.mjs +588 -98
  85. package/dist/data/scripts/commit-gate-runner.mjs +103 -0
  86. package/dist/data/scripts/harness-projection/adapters/claude.mjs +1 -0
  87. package/dist/data/scripts/harness-projection/adapters/codex.mjs +1 -0
  88. package/dist/data/scripts/harness-projection/adapters/cursor.mjs +1 -0
  89. package/dist/data/scripts/harness-projection/adapters/opencode.mjs +1 -0
  90. package/dist/data/scripts/harness-projection/core.mjs +4 -0
  91. package/dist/data/scripts/harness-projection/test-fixtures/claude/actions.json +1 -0
  92. package/dist/data/scripts/harness-projection/test-fixtures/codex/actions.json +2 -1
  93. package/dist/data/scripts/harness-projection/test-fixtures/cursor/projection.json +1 -0
  94. package/dist/data/scripts/harness-projection/test-fixtures/opencode/projection.json +1 -0
  95. package/dist/index.js +73 -58
  96. package/dist/skills/agnostic/docs/docs-onboarding/SKILL.md +2 -2
  97. package/dist/skills/agnostic/planning/create-spec/SKILL.md +32 -32
  98. package/dist/skills/agnostic/planning/create-spec/assets/SPEC-TEMPLATE.md +7 -7
  99. package/dist/skills/agnostic/planning/create-spec/references/readiness.md +14 -13
  100. package/dist/skills/agnostic/planning/create-spec/references/spec-quality-bar.md +26 -19
  101. package/dist/skills/agnostic/quality/autoreview/SKILL.md +2 -2
  102. package/dist/skills/agnostic/quality/autoreview/scripts/autoreview +3 -0
  103. package/dist/skills/agnostic/requirements/brainstorm/SKILL.md +12 -0
  104. package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +2 -1
  105. package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +9 -9
  106. package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +43 -55
  107. package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +68 -63
  108. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +26 -29
  109. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/story-shape.md +5 -5
  110. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +1 -1
  111. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +2 -2
  112. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +1 -1
  113. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +2 -2
  114. package/dist/skills/agnostic/requirements/write-backlog/references/business-projection.md +19 -24
  115. package/dist/skills/agnostic/requirements/write-backlog/references/delivery-status.md +17 -13
  116. package/dist/skills/agnostic/requirements/write-backlog/references/fog-intake.md +45 -48
  117. package/dist/skills/agnostic/requirements/write-backlog/references/functional-projection.md +16 -21
  118. package/dist/skills/agnostic/requirements/write-backlog/references/normalization.md +14 -14
  119. package/dist/skills/agnostic/requirements/write-backlog/references/project-context.md +32 -27
  120. package/dist/skills/agnostic/requirements/write-backlog/references/providers/github.md +97 -142
  121. package/dist/skills/agnostic/requirements/write-backlog/references/providers/linear.md +106 -176
  122. package/dist/skills/agnostic/requirements/write-backlog/references/technical-projection.md +51 -47
  123. package/dist/skills/agnostic/requirements/write-backlog/scripts/validate-task-blocker-graph.mjs +55 -31
  124. package/dist/skills/phases/business-finder/SKILL.md +29 -16
  125. package/dist/skills/phases/delivery-phase/phases/router.md +10 -8
  126. package/dist/skills/phases/design-phase/phases/backlog.md +26 -17
  127. package/dist/skills/phases/finder-phase/AUTHORING-HANDOFF.md +51 -261
  128. package/dist/skills/phases/finder-phase/SKILL.md +22 -25
  129. package/dist/skills/phases/finder-phase/phases/ensure-fog.md +13 -23
  130. package/dist/skills/phases/finder-phase/phases/grilling.md +40 -0
  131. package/dist/skills/phases/finder-phase/phases/handback.md +11 -18
  132. package/dist/skills/phases/finder-phase/phases/prototype.md +13 -21
  133. package/dist/skills/phases/finder-phase/phases/reconcile.md +21 -35
  134. package/dist/skills/phases/finder-phase/phases/research.md +13 -18
  135. package/dist/skills/phases/finder-phase/phases/return-target.md +14 -25
  136. package/dist/skills/phases/finder-phase/phases/router.md +22 -56
  137. package/dist/skills/phases/finder-phase/references/entrypoint-contract.md +25 -26
  138. package/dist/skills/phases/finder-phase/references/root-routing.md +12 -20
  139. package/dist/skills/phases/finder-phase/references/runtime-handoff.md +17 -39
  140. package/dist/skills/phases/finder-phase/references/state-graph.md +27 -49
  141. package/dist/skills/phases/finder-phase/scripts/finder-contract.mjs +44 -357
  142. package/dist/skills/phases/functional-finder/SKILL.md +29 -62
  143. package/dist/skills/phases/requirements-phase/SKILL.md +49 -13
  144. package/package.json +7 -5
  145. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/adopt-business-path.md +0 -52
  146. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/business-grilling.md +0 -68
  147. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/functional-grilling.md +0 -53
  148. package/dist/baseline/scaffold-baseline/skills/phases/finder-phase/phases/technical-grilling.md +0 -67
  149. package/dist/baseline/scaffold-baseline/skills/phases/technical-finder/SKILL.md +0 -74
  150. package/dist/baseline/scaffold-baseline/skills/phases/technical-finder/agents/openai.yaml +0 -2
  151. package/dist/skills/phases/finder-phase/phases/adopt-business-path.md +0 -52
  152. package/dist/skills/phases/finder-phase/phases/business-grilling.md +0 -68
  153. package/dist/skills/phases/finder-phase/phases/functional-grilling.md +0 -53
  154. package/dist/skills/phases/finder-phase/phases/technical-grilling.md +0 -67
  155. package/dist/skills/phases/technical-finder/SKILL.md +0 -74
  156. package/dist/skills/phases/technical-finder/agents/openai.yaml +0 -2
@@ -13,6 +13,7 @@ import {
13
13
  readSync,
14
14
  readFileSync,
15
15
  realpathSync,
16
+ rmSync,
16
17
  writeFileSync,
17
18
  } from "node:fs";
18
19
  import os from "node:os";
@@ -162,19 +163,47 @@ function isPythonPath(relativePath) {
162
163
  return pythonFormattableSuffixes.has(path.extname(relativePath));
163
164
  }
164
165
 
165
- function runCommand(root, args, stdio = "ignore") {
166
+ function runCommand(root, args, stdio = ["ignore", "pipe", "pipe"]) {
166
167
  const result = spawnSync(args[0], args.slice(1), {
167
168
  cwd: root,
168
169
  stdio,
169
- encoding: stdio === "ignore" ? undefined : "utf8",
170
+ encoding: "utf8",
171
+ maxBuffer: 16 * 1024 * 1024,
170
172
  });
171
173
 
172
174
  return {
173
175
  ok: result.status === 0,
176
+ status: result.status,
177
+ error: result.error,
174
178
  stdout: result.stdout ?? "",
179
+ stderr: result.stderr ?? "",
175
180
  };
176
181
  }
177
182
 
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
+ function workspaceRelativePath(workspace, root, relativePath) {
203
+ const workspacePath = path.relative(workspace, path.join(root, relativePath));
204
+ return workspacePath.split(path.sep).join("/");
205
+ }
206
+
178
207
  function commandExists(command) {
179
208
  const pathValue = process.env.PATH ?? process.env.Path;
180
209
  if (!pathValue) {
@@ -298,7 +327,7 @@ function formatCommandForPath(root, relativePath) {
298
327
  return toolCommand(root, "oxfmt", ["--stdin-filepath", relativePath]);
299
328
  }
300
329
 
301
- function lintCommandForPath(root, relativePath) {
330
+ function lintCommandForPath(root, relativePath, workspaceRelative = false) {
302
331
  if (isPythonPath(relativePath)) {
303
332
  return [
304
333
  "uv",
@@ -314,7 +343,10 @@ function lintCommandForPath(root, relativePath) {
314
343
  ];
315
344
  }
316
345
 
317
- if (!isLintablePath(relativePath)) {
346
+ if (!workspaceRelative && !isLintablePath(relativePath)) {
347
+ return null;
348
+ }
349
+ if (workspaceRelative && !javascriptLintableSuffixes.has(path.extname(relativePath))) {
318
350
  return null;
319
351
  }
320
352
 
@@ -432,15 +464,162 @@ function runTransformCommand(root, command, content) {
432
464
  cwd: root,
433
465
  input: content,
434
466
  maxBuffer: Math.max(16 * 1024 * 1024, content.length * 4),
435
- stdio: ["pipe", "pipe", "inherit"],
467
+ stdio: ["pipe", "pipe", "pipe"],
468
+ encoding: "buffer",
436
469
  });
437
470
 
438
471
  return {
439
472
  ok: result.status === 0,
473
+ status: result.status,
474
+ error: result.error,
475
+ stderr: result.stderr?.toString() ?? "",
440
476
  output: result.error === undefined && Buffer.isBuffer(result.stdout) ? result.stdout : content,
441
477
  };
442
478
  }
443
479
 
480
+ function lintDiagnosticRule(code) {
481
+ if (typeof code !== "string") {
482
+ return "";
483
+ }
484
+
485
+ const match = code.match(/\(([^()]+)\)$/);
486
+ return match?.[1] ?? code;
487
+ }
488
+
489
+ function normalizeDiagnostic(diagnostic, root, fallbackPath, temporaryPath = null) {
490
+ if (!diagnostic || typeof diagnostic !== "object") {
491
+ return null;
492
+ }
493
+
494
+ let file = typeof diagnostic.filename === "string" ? diagnostic.filename : fallbackPath;
495
+ if (temporaryPath && file === temporaryPath) {
496
+ file = fallbackPath;
497
+ }
498
+ const normalizedFile = normalizeEditedPath(file, root) ?? fallbackPath;
499
+ const label = Array.isArray(diagnostic.labels) ? diagnostic.labels[0] : null;
500
+ const span = label?.span && typeof label.span === "object" ? label.span : {};
501
+ const normalized = {
502
+ file: normalizedFile,
503
+ rule: lintDiagnosticRule(diagnostic.code),
504
+ severity: typeof diagnostic.severity === "string" ? diagnostic.severity : "error",
505
+ line: Number.isInteger(span.line) ? span.line : null,
506
+ column: Number.isInteger(span.column) ? span.column : null,
507
+ message: typeof diagnostic.message === "string" ? diagnostic.message : "Lint finding",
508
+ };
509
+
510
+ if (typeof diagnostic.help === "string" && diagnostic.help.length > 0) {
511
+ normalized.help = diagnostic.help;
512
+ }
513
+ if (typeof diagnostic.url === "string" && diagnostic.url.length > 0) {
514
+ normalized.documentation = diagnostic.url;
515
+ }
516
+ if (Number.isInteger(span.offset)) normalized.offset = span.offset;
517
+ if (Number.isInteger(span.length)) normalized.length = span.length;
518
+ return normalized;
519
+ }
520
+
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" };
531
+ }
532
+
533
+ const diagnostics = parsed.diagnostics.map((diagnostic) =>
534
+ normalizeDiagnostic(diagnostic, root, fallbackPath, temporaryPath),
535
+ );
536
+ if (diagnostics.some((diagnostic) => diagnostic === null)) {
537
+ return { ok: false, error: "Oxlint JSON contained an invalid diagnostic" };
538
+ }
539
+
540
+ return { ok: true, diagnostics };
541
+ }
542
+
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("/");
549
+
550
+ 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
+ }
569
+
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
+
587
+ const parsed = parseLintDiagnostics(
588
+ verificationResult.stdout,
589
+ root,
590
+ relativePath,
591
+ temporaryRelativePath,
592
+ );
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 };
614
+ } 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
+ }
620
+ }
621
+ }
622
+
444
623
  const publicationWorkerScript = `
445
624
  import { createHash } from "node:crypto";
446
625
  import {
@@ -653,16 +832,53 @@ function publishFormattedContent(filePath, target, content) {
653
832
  return result.error === undefined && result.status === 0;
654
833
  }
655
834
 
835
+ function emptyLintSummary(result = "clean", failures = []) {
836
+ const summary = {
837
+ format_failed: [],
838
+ formatted: [],
839
+ lint_failed: [],
840
+ diagnostics: [],
841
+ failures,
842
+ result,
843
+ exhausted: false,
844
+ status: result === "operational_failure" ? "operational-failure" : result,
845
+ files: [],
846
+ };
847
+ if (result === "operational_failure" && failures[0]) {
848
+ summary.stage = failures[0].stage ?? "lint-verify";
849
+ summary.command = failures[0].command ?? "";
850
+ if (Number.isInteger(failures[0].exitCode)) summary.exitCode = failures[0].exitCode;
851
+ summary.message = failures[0].message ?? "Lint operation failed";
852
+ }
853
+ return summary;
854
+ }
855
+
856
+ function commandText(command) {
857
+ return Array.isArray(command) ? command.join(" ") : String(command ?? "");
858
+ }
859
+
656
860
  function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
657
861
  const caseSemantics = pathCaseSemantics(root);
658
862
  if (caseSemantics === "unknown") {
659
- return { format_failed: [], formatted: [], lint_failed: [] };
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
+ ]);
660
870
  }
661
871
 
662
872
  const caseInsensitivePaths = caseSemantics === "case-insensitive";
663
873
  const managedPaths = loadManagedPaths(root, caseInsensitivePaths);
664
874
  if (managedPaths === null) {
665
- return { format_failed: [], formatted: [], lint_failed: [] };
875
+ return emptyLintSummary("operational_failure", [
876
+ {
877
+ stage: "config-load",
878
+ command: scaffoldManifestPath,
879
+ message: "Managed scaffold manifest is invalid",
880
+ },
881
+ ]);
666
882
  }
667
883
 
668
884
  const normalizedFiles = [];
@@ -682,6 +898,8 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
682
898
  const formatted = [];
683
899
  const formatFailed = [];
684
900
  const lintFailed = [];
901
+ const diagnostics = [];
902
+ const failures = [];
685
903
 
686
904
  for (const relativePath of normalizedFiles) {
687
905
  const expectedFingerprint = expectedFingerprints?.[relativePath];
@@ -692,48 +910,195 @@ function formatAndLintFiles(root, filePaths, expectedFingerprints = null) {
692
910
  const absolutePath = path.join(root, relativePath);
693
911
  const target = openFormattingTarget(absolutePath, expectedFingerprint);
694
912
  if (target === null) {
913
+ failures.push({
914
+ kind: "race",
915
+ stage: "lint-verify",
916
+ file: relativePath,
917
+ command: "open edited file",
918
+ message: "Edited file changed before formatting",
919
+ });
695
920
  continue;
696
921
  }
697
922
 
923
+ const workspace = owningWorkspace(root, relativePath);
924
+ const workspacePath = workspaceRelativePath(workspace, root, relativePath);
925
+ const formatCommand = formatCommandForPath(workspace, workspacePath);
926
+
698
927
  // Keep mutating tools off the live path; stage output before claiming the validated target.
699
928
  const formatResult = runTransformCommand(
700
- root,
701
- formatCommandForPath(root, relativePath),
929
+ workspace,
930
+ formatCommand,
702
931
  target.content,
703
932
  );
704
933
 
705
934
  if (!formatResult.ok) {
706
935
  closeSync(target.descriptor);
707
936
  formatFailed.push(relativePath);
937
+ failures.push({
938
+ kind: "format",
939
+ stage: "format",
940
+ file: relativePath,
941
+ command: commandText(formatCommand),
942
+ exitCode: formatResult.status,
943
+ message: formatResult.error?.message ?? (formatResult.stderr || "Oxfmt failed"),
944
+ });
945
+ continue;
946
+ }
947
+
948
+ const lintCommand = lintCommandForPath(workspace, workspacePath, true);
949
+ let formattedContent = formatResult.output;
950
+ let lintResult = null;
951
+ if (lintCommand !== null && isPythonPath(relativePath)) {
952
+ lintResult = runTransformCommand(workspace, lintCommand, formattedContent);
953
+ if (lintResult.ok) {
954
+ formattedContent = lintResult.output;
955
+ }
956
+ } else if (lintCommand !== null) {
957
+ lintResult = runSafeJavascriptLint(workspace, root, relativePath, formattedContent);
958
+ if (lintResult.ok) {
959
+ formattedContent = lintResult.content;
960
+ diagnostics.push(...lintResult.diagnostics);
961
+ }
962
+ }
963
+
964
+ if (lintResult !== null && !lintResult.ok) {
965
+ closeSync(target.descriptor);
966
+ failures.push({
967
+ kind: "lint",
968
+ stage: lintResult.stage ?? "lint-verify",
969
+ file: relativePath,
970
+ command: lintResult.command ?? commandText(lintCommand),
971
+ ...(Number.isInteger(lintResult.exitCode) ? { exitCode: lintResult.exitCode } : {}),
972
+ message: lintResult.error ?? lintResult.error?.message ?? (lintResult.stderr || "Oxlint failed"),
973
+ });
708
974
  continue;
709
975
  }
710
976
 
711
- const lintCommand = lintCommandForPath(root, relativePath);
712
- const lintResult =
713
- lintCommand !== null && isPythonPath(relativePath)
714
- ? runTransformCommand(root, lintCommand, formatResult.output)
715
- : null;
716
- const formattedContent = lintResult?.ok ? lintResult.output : formatResult.output;
717
977
  const published = publishFormattedContent(absolutePath, target, formattedContent);
718
978
  closeSync(target.descriptor);
719
979
  if (!published) {
980
+ failures.push({
981
+ kind: "publication",
982
+ stage: "lint-verify",
983
+ file: relativePath,
984
+ command: "atomic publication",
985
+ message: "Atomic publication failed",
986
+ });
720
987
  continue;
721
988
  }
722
989
 
723
990
  formatted.push(relativePath);
724
991
 
725
- if (
726
- (lintResult !== null && !lintResult.ok) ||
727
- (lintCommand !== null && lintResult === null && !runCommand(root, lintCommand).ok)
728
- ) {
992
+ if (lintResult !== null && lintResult.diagnostics?.length > 0) {
729
993
  lintFailed.push(relativePath);
730
994
  }
731
995
  }
732
996
 
997
+ const result =
998
+ failures.length > 0 ? "operational_failure" : diagnostics.length > 0 ? "findings" : "clean";
733
999
  return {
734
1000
  format_failed: formatFailed,
735
1001
  formatted,
736
1002
  lint_failed: lintFailed,
1003
+ diagnostics,
1004
+ failures,
1005
+ result,
1006
+ exhausted: false,
1007
+ status: result === "operational_failure" ? "operational-failure" : result,
1008
+ files: result === "findings" ? [...new Set(diagnostics.map((diagnostic) => diagnostic.file))] : formatted,
1009
+ ...(diagnostics.length > 0 ? { fingerprint: contentHash(JSON.stringify(diagnostics)), attempt: 1 } : {}),
1010
+ ...(failures.length > 0
1011
+ ? {
1012
+ stage: failures[0].stage ?? "lint-verify",
1013
+ command: failures[0].command ?? "",
1014
+ ...(Number.isInteger(failures[0].exitCode) ? { exitCode: failures[0].exitCode } : {}),
1015
+ message: failures[0].message ?? "Lint operation failed",
1016
+ }
1017
+ : {}),
1018
+ };
1019
+ }
1020
+
1021
+ function verifyLintFiles(root, filePaths) {
1022
+ const caseSemantics = pathCaseSemantics(root);
1023
+ const managedPaths = loadManagedPaths(root, caseSemantics === "case-insensitive");
1024
+ if (caseSemantics === "unknown" || managedPaths === null) {
1025
+ return emptyLintSummary("operational_failure", [
1026
+ {
1027
+ stage: "config-load",
1028
+ command: scaffoldManifestPath,
1029
+ message: "Lint preview cannot validate repository state",
1030
+ },
1031
+ ]);
1032
+ }
1033
+
1034
+ const normalizedFiles = [
1035
+ ...new Set(
1036
+ filePaths
1037
+ .map((filePath) =>
1038
+ normalizeRelativePath(root, filePath, managedPaths, caseSemantics === "case-insensitive"),
1039
+ )
1040
+ .filter((filePath) => filePath && isLintablePath(filePath)),
1041
+ ),
1042
+ ];
1043
+ const diagnostics = [];
1044
+ const failures = [];
1045
+ const lintFailed = new Set();
1046
+
1047
+ for (const relativePath of normalizedFiles) {
1048
+ const workspace = owningWorkspace(root, relativePath);
1049
+ const workspacePath = workspaceRelativePath(workspace, root, relativePath);
1050
+ const command = toolCommand(workspace, "oxlint", ["--format", "json", workspacePath]);
1051
+ const result = runCommand(workspace, command);
1052
+ if (result.error !== undefined) {
1053
+ failures.push({
1054
+ kind: "lint",
1055
+ stage: "lint-verify",
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);
1092
+ }
1093
+ }
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],
737
1102
  };
738
1103
  }
739
1104
 
@@ -749,23 +1114,81 @@ function extractSingleFilePath(payload) {
749
1114
  );
750
1115
  }
751
1116
 
752
- function emitClaudeFailure(message) {
753
- process.stdout.write(
754
- JSON.stringify({
755
- hookSpecificOutput: {
756
- hookEventName: "PostToolUse",
757
- additionalContext: message,
758
- },
759
- }),
760
- );
1117
+ function formatLintFinding(diagnostic) {
1118
+ const location =
1119
+ Number.isInteger(diagnostic.line) && Number.isInteger(diagnostic.column)
1120
+ ? `${diagnostic.file}:${diagnostic.line}:${diagnostic.column}`
1121
+ : diagnostic.file;
1122
+ const severity = diagnostic.severity ? ` (${diagnostic.severity})` : "";
1123
+ const rule = diagnostic.rule ? ` [${diagnostic.rule}]` : "";
1124
+ const help = diagnostic.help ? ` Help: ${diagnostic.help}` : "";
1125
+ const documentation = diagnostic.documentation ? ` Docs: ${diagnostic.documentation}` : "";
1126
+ return `${location}${severity}${rule} ${diagnostic.message}${help}${documentation}`;
761
1127
  }
762
1128
 
763
- function emitCursorFailure(message) {
764
- process.stdout.write(
765
- JSON.stringify({
766
- user_message: message,
767
- }),
1129
+ function providerFeedbackMessage(summary) {
1130
+ const findings = summary.diagnostics.map(formatLintFinding);
1131
+ const failures = summary.failures.map(
1132
+ (failure) => `${failure.file ? `${failure.file}: ` : ""}${failure.message}`,
768
1133
  );
1134
+ const formatFailures = summary.format_failed.map((file) => `${file}: formatting failed`);
1135
+ const lines = [...findings, ...formatFailures, ...failures];
1136
+ if (summary.exhausted) {
1137
+ return [
1138
+ "Lint repair exhausted after three unchanged attempts. Continue without another automatic repair request.",
1139
+ ...lines,
1140
+ ].join("\n");
1141
+ }
1142
+ return ["Lint feedback after edit. Fix these findings before continuing:", ...lines].join("\n");
1143
+ }
1144
+
1145
+ function renderProviderFeedback(provider, summary) {
1146
+ const hasFeedback =
1147
+ summary.diagnostics.length > 0 ||
1148
+ summary.failures.length > 0 ||
1149
+ summary.format_failed.length > 0;
1150
+ if (!hasFeedback) {
1151
+ return null;
1152
+ }
1153
+
1154
+ const message = providerFeedbackMessage(summary);
1155
+ switch (provider) {
1156
+ case "codex":
1157
+ return {
1158
+ ...(summary.exhausted ? {} : { decision: "block" }),
1159
+ hookSpecificOutput: {
1160
+ hookEventName: "PostToolUse",
1161
+ additionalContext: message,
1162
+ },
1163
+ systemMessage: message,
1164
+ };
1165
+ case "claude":
1166
+ return {
1167
+ hookSpecificOutput: {
1168
+ hookEventName: "PostToolUse",
1169
+ additionalContext: message,
1170
+ },
1171
+ };
1172
+ case "cursor":
1173
+ return { user_message: message };
1174
+ case "opencode":
1175
+ return {
1176
+ event: "lint-feedback",
1177
+ status: summary.exhausted ? "exhausted" : summary.status,
1178
+ diagnostics: summary.diagnostics,
1179
+ failures: summary.failures,
1180
+ repairRequested: !summary.exhausted,
1181
+ };
1182
+ default:
1183
+ throw new Error(`Unsupported lint feedback provider: ${provider}`);
1184
+ }
1185
+ }
1186
+
1187
+ function emitProviderFeedback(provider, summary) {
1188
+ const feedback = renderProviderFeedback(provider, summary);
1189
+ if (feedback !== null) {
1190
+ process.stdout.write(JSON.stringify(feedback));
1191
+ }
769
1192
  }
770
1193
 
771
1194
  function runSingleFileMode(style) {
@@ -782,30 +1205,7 @@ function runSingleFileMode(style) {
782
1205
  }
783
1206
 
784
1207
  const summary = formatAndLintFiles(root, [filePath]);
785
- const formatFailed = summary.format_failed[0] ?? "";
786
- const lintFailed = summary.lint_failed[0] ?? "";
787
-
788
- if (formatFailed) {
789
- const message = `Auto-format failed for ${filePath}. Review the file and format it manually if needed.`;
790
-
791
- if (style === "claude") {
792
- emitClaudeFailure(message);
793
- } else {
794
- emitCursorFailure(message);
795
- }
796
-
797
- return;
798
- }
799
-
800
- if (lintFailed) {
801
- const message = `Auto-lint failed for ${filePath}. Review the file and fix lint errors manually if needed.`;
802
-
803
- if (style === "claude") {
804
- emitClaudeFailure(message);
805
- } else {
806
- emitCursorFailure(message);
807
- }
808
- }
1208
+ emitProviderFeedback(style, summary);
809
1209
  }
810
1210
 
811
1211
  function dirtyFiles(root) {
@@ -830,10 +1230,42 @@ function fileHash(filePath) {
830
1230
  return contentHash(readFileSync(filePath));
831
1231
  }
832
1232
 
1233
+ function fingerprintPath(root, relativePath) {
1234
+ const normalizedPath = normalizeManagedPath(relativePath);
1235
+ if (!normalizedPath) {
1236
+ return null;
1237
+ }
1238
+
1239
+ const absolutePath = path.join(root, normalizedPath);
1240
+ let rootRealPath;
1241
+ let fileRealPath;
1242
+ try {
1243
+ const stats = lstatSync(absolutePath);
1244
+ if (!stats.isFile()) {
1245
+ return null;
1246
+ }
1247
+ rootRealPath = realpathSync.native(root);
1248
+ fileRealPath = realpathSync.native(absolutePath);
1249
+ } catch {
1250
+ return null;
1251
+ }
1252
+
1253
+ const relativeRealPath = path.relative(rootRealPath, fileRealPath);
1254
+ if (
1255
+ relativeRealPath === "" ||
1256
+ relativeRealPath.startsWith("..") ||
1257
+ path.isAbsolute(relativeRealPath)
1258
+ ) {
1259
+ return null;
1260
+ }
1261
+
1262
+ return absolutePath;
1263
+ }
1264
+
833
1265
  function codexStateFilePath(root, sessionId) {
834
- const repoName = path.basename(root) || "repo";
1266
+ const repositoryIdentity = contentHash(realpathSync.native(root));
835
1267
  const safeSessionId = sessionId.replaceAll("/", "_");
836
- const stateDir = path.join(os.tmpdir(), "codex-hooks", repoName, safeSessionId);
1268
+ const stateDir = path.join(os.tmpdir(), "codex-hooks", repositoryIdentity, safeSessionId);
837
1269
  mkdirSync(stateDir, { recursive: true });
838
1270
  return path.join(stateDir, "format-state.json");
839
1271
  }
@@ -842,8 +1274,8 @@ function fingerprints(root) {
842
1274
  const entries = {};
843
1275
 
844
1276
  for (const relativePath of dirtyFiles(root)) {
845
- const absolutePath = path.join(root, relativePath);
846
- if (existsSync(absolutePath)) {
1277
+ const absolutePath = fingerprintPath(root, relativePath);
1278
+ if (absolutePath !== null) {
847
1279
  entries[relativePath] = fileHash(absolutePath);
848
1280
  }
849
1281
  }
@@ -883,6 +1315,9 @@ function loadCodexState(filePath) {
883
1315
  const raw = loadJson(filePath);
884
1316
  return {
885
1317
  baseline: readFingerprintRecord(raw?.baseline),
1318
+ diagnosticAttempts: isFingerprintRecord(raw?.diagnosticAttempts)
1319
+ ? raw.diagnosticAttempts
1320
+ : {},
886
1321
  lastToolUseId: typeof raw?.lastToolUseId === "string" ? raw.lastToolUseId : "",
887
1322
  processed: readFingerprintRecord(raw?.processed),
888
1323
  };
@@ -893,12 +1328,52 @@ function saveCodexState(filePath, state) {
893
1328
  filePath,
894
1329
  JSON.stringify({
895
1330
  baseline: state.baseline,
1331
+ diagnosticAttempts: state.diagnosticAttempts,
896
1332
  lastToolUseId: state.lastToolUseId,
897
1333
  processed: state.processed,
898
1334
  }),
899
1335
  );
900
1336
  }
901
1337
 
1338
+ function applyDiagnosticRetryLimit(state, summary) {
1339
+ const byFile = new Map();
1340
+ for (const diagnostic of summary.diagnostics) {
1341
+ const existing = byFile.get(diagnostic.file) ?? [];
1342
+ existing.push(diagnostic);
1343
+ byFile.set(diagnostic.file, existing);
1344
+ }
1345
+
1346
+ let exhausted = false;
1347
+ let maximumAttempt = 0;
1348
+ for (const [relativePath, diagnostics] of byFile) {
1349
+ const fingerprint = contentHash(JSON.stringify(diagnostics));
1350
+ const previous = state.diagnosticAttempts[relativePath];
1351
+ const attempts =
1352
+ previous?.fingerprint === fingerprint && Number.isInteger(previous.attempts)
1353
+ ? Math.min(previous.attempts + 1, 3)
1354
+ : 1;
1355
+ state.diagnosticAttempts[relativePath] = { fingerprint, attempts };
1356
+ maximumAttempt = Math.max(maximumAttempt, attempts);
1357
+ if (attempts >= 3) {
1358
+ exhausted = true;
1359
+ }
1360
+ }
1361
+
1362
+ for (const relativePath of Object.keys(state.diagnosticAttempts)) {
1363
+ if (!byFile.has(relativePath)) {
1364
+ delete state.diagnosticAttempts[relativePath];
1365
+ }
1366
+ }
1367
+
1368
+ if (exhausted) {
1369
+ summary.exhausted = true;
1370
+ summary.result = "exhausted";
1371
+ }
1372
+ summary.status = "findings";
1373
+ summary.fingerprint = contentHash(JSON.stringify(summary.diagnostics));
1374
+ summary.attempt = maximumAttempt;
1375
+ }
1376
+
902
1377
  function updateProcessedFingerprints(root, state, filePaths) {
903
1378
  for (const relativePath of filePaths) {
904
1379
  const absolutePath = path.join(root, relativePath);
@@ -929,15 +1404,6 @@ function pruneProcessedFingerprints(state, current) {
929
1404
  }
930
1405
  }
931
1406
 
932
- function emitCodexFailure(kind, files) {
933
- const message =
934
- kind === "lint"
935
- ? `Auto-lint failed for ${files.join(", ")}. Review the file and fix lint errors manually if needed.`
936
- : `Auto-format failed for ${files.join(", ")}. Review the file and format it manually if needed.`;
937
-
938
- process.stdout.write(JSON.stringify({ systemMessage: message }));
939
- }
940
-
941
1407
  function runCodexSnapshotMode(mode) {
942
1408
  const payload = readStdinJson();
943
1409
  const cwd = String(payload.cwd ?? process.cwd());
@@ -953,6 +1419,7 @@ function runCodexSnapshotMode(mode) {
953
1419
  if (mode === "session-start") {
954
1420
  saveCodexState(stateFile, {
955
1421
  baseline: fingerprints(root),
1422
+ diagnosticAttempts: {},
956
1423
  lastToolUseId: "",
957
1424
  processed: {},
958
1425
  });
@@ -1005,15 +1472,22 @@ function runCodexSnapshotMode(mode) {
1005
1472
  }
1006
1473
 
1007
1474
  const summary = formatAndLintFiles(root, touched, current);
1475
+ if (summary.diagnostics.length > 0) {
1476
+ applyDiagnosticRetryLimit(state, summary);
1477
+ } else {
1478
+ for (const relativePath of touched) {
1479
+ delete state.diagnosticAttempts[relativePath];
1480
+ }
1481
+ }
1008
1482
  updateProcessedFingerprints(root, state, summary.formatted);
1009
1483
  saveCodexState(stateFile, state);
1010
1484
 
1011
- if (summary.format_failed.length > 0) {
1012
- emitCodexFailure("format", summary.format_failed);
1013
- }
1014
-
1015
- if (summary.lint_failed.length > 0) {
1016
- emitCodexFailure("lint", summary.lint_failed);
1485
+ if (
1486
+ summary.diagnostics.length > 0 ||
1487
+ summary.failures.length > 0 ||
1488
+ summary.format_failed.length > 0
1489
+ ) {
1490
+ emitProviderFeedback("codex", summary);
1017
1491
  }
1018
1492
  }
1019
1493
 
@@ -1103,31 +1577,30 @@ export const FormatAndLintPlugin = async ({ client, worktree }) => {
1103
1577
  ["ignore", "pipe", "ignore"],
1104
1578
  );
1105
1579
 
1106
- const summary = result.ok ? parseSummary(result.stdout) : {};
1107
- const formatFailed = Array.isArray(summary?.format_failed) ? summary.format_failed : [];
1108
- const lintFailed = Array.isArray(summary?.lint_failed) ? summary.lint_failed : [];
1109
-
1110
- for (const relativePath of formatFailed) {
1111
- await client.app.log({
1112
- body: {
1113
- service: "format-and-lint",
1114
- level: "warn",
1115
- message: "Auto-format failed after edit.",
1116
- extra: {
1117
- filePath: relativePath,
1118
- },
1119
- },
1120
- });
1121
- }
1122
-
1123
- for (const relativePath of lintFailed) {
1580
+ const parsedSummary = result.ok ? parseSummary(result.stdout) : {};
1581
+ const summary = {
1582
+ ...parsedSummary,
1583
+ status: typeof parsedSummary.status === "string" ? parsedSummary.status : "operational-failure",
1584
+ diagnostics: Array.isArray(parsedSummary.diagnostics) ? parsedSummary.diagnostics : [],
1585
+ failures: Array.isArray(parsedSummary.failures) ? parsedSummary.failures : [],
1586
+ format_failed: Array.isArray(parsedSummary.format_failed) ? parsedSummary.format_failed : [],
1587
+ exhausted: parsedSummary.exhausted === true,
1588
+ };
1589
+ if (
1590
+ summary.diagnostics.length > 0 ||
1591
+ summary.failures.length > 0 ||
1592
+ summary.format_failed.length > 0
1593
+ ) {
1124
1594
  await client.app.log({
1125
1595
  body: {
1126
1596
  service: "format-and-lint",
1127
1597
  level: "warn",
1128
- message: "Auto-lint failed after edit.",
1598
+ message: providerFeedbackMessage(summary),
1129
1599
  extra: {
1130
- filePath: relativePath,
1600
+ diagnostics: summary.diagnostics,
1601
+ failures: summary.failures,
1602
+ exhausted: summary.exhausted === true,
1603
+ repairRequested: summary.exhausted !== true,
1131
1604
  },
1132
1605
  },
1133
1606
  });
@@ -1137,8 +1610,12 @@ export const FormatAndLintPlugin = async ({ client, worktree }) => {
1137
1610
  };
1138
1611
 
1139
1612
  export const testHooks = {
1613
+ codexStateFilePath,
1140
1614
  formatCommandForPath,
1141
1615
  lintCommandForPath,
1616
+ owningWorkspace,
1617
+ parseLintDiagnostics,
1618
+ renderProviderFeedback,
1142
1619
  toolCommand,
1143
1620
  };
1144
1621
 
@@ -1150,7 +1627,7 @@ function main() {
1150
1627
  return;
1151
1628
  }
1152
1629
 
1153
- if (mode === "claude" || mode === "cursor") {
1630
+ if (mode === "claude" || mode === "cursor" || mode === "opencode") {
1154
1631
  runSingleFileMode(mode);
1155
1632
  return;
1156
1633
  }
@@ -1159,7 +1636,20 @@ function main() {
1159
1636
  const root = repoRoot(process.cwd());
1160
1637
  const summary = root
1161
1638
  ? formatAndLintFiles(root, process.argv.slice(3))
1162
- : { format_failed: [], formatted: [], lint_failed: [] };
1639
+ : emptyLintSummary("operational_failure", [
1640
+ { stage: "config-load", command: "git rev-parse --show-toplevel", message: "Not inside a Git repository" },
1641
+ ]);
1642
+ process.stdout.write(JSON.stringify(summary));
1643
+ return;
1644
+ }
1645
+
1646
+ if (mode === "preview") {
1647
+ const root = repoRoot(process.cwd());
1648
+ const summary = root
1649
+ ? verifyLintFiles(root, process.argv.slice(3))
1650
+ : emptyLintSummary("operational_failure", [
1651
+ { stage: "config-load", command: "git rev-parse --show-toplevel", message: "Not inside a Git repository" },
1652
+ ]);
1163
1653
  process.stdout.write(JSON.stringify(summary));
1164
1654
  }
1165
1655
  }