anvil-engineering-workbench 1.0.9 → 1.1.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 (163) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +23 -18
  3. package/dist/ai/claude-code-provider.js +55 -9
  4. package/dist/ai/claude-code-provider.js.map +1 -1
  5. package/dist/ai/provider.js +1 -1
  6. package/dist/ai/provider.js.map +1 -1
  7. package/dist/cli.js +850 -278
  8. package/dist/cli.js.map +1 -1
  9. package/dist/core/adr-engine.js +9 -11
  10. package/dist/core/adr-engine.js.map +1 -1
  11. package/dist/core/agent-config-release.js +29 -13
  12. package/dist/core/agent-config-release.js.map +1 -1
  13. package/dist/core/agent-config-versioning.js +32 -17
  14. package/dist/core/agent-config-versioning.js.map +1 -1
  15. package/dist/core/agent-evaluation-intelligence.js +30 -38
  16. package/dist/core/agent-evaluation-intelligence.js.map +1 -1
  17. package/dist/core/agent-evolution.js +109 -20
  18. package/dist/core/agent-evolution.js.map +1 -1
  19. package/dist/core/agent-experiment-studio.js +19 -11
  20. package/dist/core/agent-experiment-studio.js.map +1 -1
  21. package/dist/core/agent-optimization.js +69 -14
  22. package/dist/core/agent-optimization.js.map +1 -1
  23. package/dist/core/agent-registry.js +87 -15
  24. package/dist/core/agent-registry.js.map +1 -1
  25. package/dist/core/agent-security-audit.js +21 -21
  26. package/dist/core/agent-security-audit.js.map +1 -1
  27. package/dist/core/agent-workspace-context.js +37 -6
  28. package/dist/core/agent-workspace-context.js.map +1 -1
  29. package/dist/core/ai-code-review.js +60 -12
  30. package/dist/core/ai-code-review.js.map +1 -1
  31. package/dist/core/anthropic-provider.js.map +1 -1
  32. package/dist/core/architecture-map.js +87 -24
  33. package/dist/core/architecture-map.js.map +1 -1
  34. package/dist/core/benchmark-engine.js +89 -21
  35. package/dist/core/benchmark-engine.js.map +1 -1
  36. package/dist/core/benchmark-matrix.js +215 -41
  37. package/dist/core/benchmark-matrix.js.map +1 -1
  38. package/dist/core/benchmark-regression.js +124 -18
  39. package/dist/core/benchmark-regression.js.map +1 -1
  40. package/dist/core/change-intelligence.js +102 -43
  41. package/dist/core/change-intelligence.js.map +1 -1
  42. package/dist/core/code-intelligence.js +40 -13
  43. package/dist/core/code-intelligence.js.map +1 -1
  44. package/dist/core/code-review.d.ts +8 -0
  45. package/dist/core/code-review.js +214 -19
  46. package/dist/core/code-review.js.map +1 -1
  47. package/dist/core/code-search.js +79 -39
  48. package/dist/core/code-search.js.map +1 -1
  49. package/dist/core/container-sandbox.js +87 -23
  50. package/dist/core/container-sandbox.js.map +1 -1
  51. package/dist/core/dashboard-server.js +379 -93
  52. package/dist/core/dashboard-server.js.map +1 -1
  53. package/dist/core/dependency-graph.js +75 -13
  54. package/dist/core/dependency-graph.js.map +1 -1
  55. package/dist/core/dependency-impact.js +132 -33
  56. package/dist/core/dependency-impact.js.map +1 -1
  57. package/dist/core/dependency-intelligence.js +153 -56
  58. package/dist/core/dependency-intelligence.js.map +1 -1
  59. package/dist/core/doctor.js +3 -3
  60. package/dist/core/doctor.js.map +1 -1
  61. package/dist/core/engineering-risk.js +75 -40
  62. package/dist/core/engineering-risk.js.map +1 -1
  63. package/dist/core/env-compat.js.map +1 -1
  64. package/dist/core/evaluation-engine.js +188 -42
  65. package/dist/core/evaluation-engine.js.map +1 -1
  66. package/dist/core/execution-trace.js +83 -29
  67. package/dist/core/execution-trace.js.map +1 -1
  68. package/dist/core/experiment-history.js +70 -20
  69. package/dist/core/experiment-history.js.map +1 -1
  70. package/dist/core/experiment-manifest.js +92 -13
  71. package/dist/core/experiment-manifest.js.map +1 -1
  72. package/dist/core/gemini-provider.js.map +1 -1
  73. package/dist/core/git-intelligence.js +68 -16
  74. package/dist/core/git-intelligence.js.map +1 -1
  75. package/dist/core/hook-engine.js +7 -3
  76. package/dist/core/hook-engine.js.map +1 -1
  77. package/dist/core/hosted-agent-provider.js +48 -8
  78. package/dist/core/hosted-agent-provider.js.map +1 -1
  79. package/dist/core/intelligence-timeline.js +92 -43
  80. package/dist/core/intelligence-timeline.js.map +1 -1
  81. package/dist/core/mcp-setup.js +12 -12
  82. package/dist/core/mcp-setup.js.map +1 -1
  83. package/dist/core/model-router.js +153 -37
  84. package/dist/core/model-router.js.map +1 -1
  85. package/dist/core/openai-compatible-provider.js +41 -10
  86. package/dist/core/openai-compatible-provider.js.map +1 -1
  87. package/dist/core/orchestrator.js +28 -23
  88. package/dist/core/orchestrator.js.map +1 -1
  89. package/dist/core/patch-application.js +88 -24
  90. package/dist/core/patch-application.js.map +1 -1
  91. package/dist/core/patch-approval.js +43 -15
  92. package/dist/core/patch-approval.js.map +1 -1
  93. package/dist/core/patch-validation.js +93 -15
  94. package/dist/core/patch-validation.js.map +1 -1
  95. package/dist/core/permission-policy.js +8 -5
  96. package/dist/core/permission-policy.js.map +1 -1
  97. package/dist/core/policy-engine.d.ts +96 -0
  98. package/dist/core/policy-engine.js +447 -0
  99. package/dist/core/policy-engine.js.map +1 -0
  100. package/dist/core/project-cleaner.js +143 -129
  101. package/dist/core/project-cleaner.js.map +1 -1
  102. package/dist/core/project-health.js +183 -21
  103. package/dist/core/project-health.js.map +1 -1
  104. package/dist/core/project-init.js +32 -20
  105. package/dist/core/project-init.js.map +1 -1
  106. package/dist/core/project-inspector.js +81 -32
  107. package/dist/core/project-inspector.js.map +1 -1
  108. package/dist/core/project-memory.js +41 -18
  109. package/dist/core/project-memory.js.map +1 -1
  110. package/dist/core/provider-diagnostics.js +65 -12
  111. package/dist/core/provider-diagnostics.js.map +1 -1
  112. package/dist/core/quality-audit.js +167 -28
  113. package/dist/core/quality-audit.js.map +1 -1
  114. package/dist/core/regression-intelligence.js +88 -8
  115. package/dist/core/regression-intelligence.js.map +1 -1
  116. package/dist/core/remediation-planner.js +112 -40
  117. package/dist/core/remediation-planner.js.map +1 -1
  118. package/dist/core/review-history.js +39 -7
  119. package/dist/core/review-history.js.map +1 -1
  120. package/dist/core/run-history-output.js.map +1 -1
  121. package/dist/core/run-replay.js +12 -10
  122. package/dist/core/run-replay.js.map +1 -1
  123. package/dist/core/run-store.js +48 -21
  124. package/dist/core/run-store.js.map +1 -1
  125. package/dist/core/sandbox-cleanup-audit.js +1 -1
  126. package/dist/core/sandbox-cleanup-audit.js.map +1 -1
  127. package/dist/core/sandbox-compliance.js +53 -9
  128. package/dist/core/sandbox-compliance.js.map +1 -1
  129. package/dist/core/sandbox-lifecycle.js +1 -1
  130. package/dist/core/sandbox-lifecycle.js.map +1 -1
  131. package/dist/core/sandbox-policy.js +27 -3
  132. package/dist/core/sandbox-policy.js.map +1 -1
  133. package/dist/core/sandbox-runtime.js +9 -5
  134. package/dist/core/sandbox-runtime.js.map +1 -1
  135. package/dist/core/sandbox-security-profiles.js +31 -12
  136. package/dist/core/sandbox-security-profiles.js.map +1 -1
  137. package/dist/core/sarif-formatter.d.ts +12 -4
  138. package/dist/core/sarif-formatter.js +262 -57
  139. package/dist/core/sarif-formatter.js.map +1 -1
  140. package/dist/core/security-scanner.js +40 -32
  141. package/dist/core/security-scanner.js.map +1 -1
  142. package/dist/core/skill-registry.js +83 -21
  143. package/dist/core/skill-registry.js.map +1 -1
  144. package/dist/core/staged-verification.js +25 -10
  145. package/dist/core/staged-verification.js.map +1 -1
  146. package/dist/core/verification-history.js +12 -7
  147. package/dist/core/verification-history.js.map +1 -1
  148. package/dist/core/verification.js +50 -19
  149. package/dist/core/verification.js.map +1 -1
  150. package/dist/core/workflow-store.js +16 -4
  151. package/dist/core/workflow-store.js.map +1 -1
  152. package/dist/core/workspace-browser.js +57 -10
  153. package/dist/core/workspace-browser.js.map +1 -1
  154. package/dist/core/workspace-scan-policy.js +26 -4
  155. package/dist/core/workspace-scan-policy.js.map +1 -1
  156. package/dist/core/workspace-tool-broker.d.ts +1 -1
  157. package/dist/core/workspace-tool-broker.js +25 -4
  158. package/dist/core/workspace-tool-broker.js.map +1 -1
  159. package/dist/mcp/server.js +148 -55
  160. package/dist/mcp/server.js.map +1 -1
  161. package/dist/mcp/workspace-path.js +2 -2
  162. package/dist/mcp/workspace-path.js.map +1 -1
  163. package/package.json +8 -5
@@ -4,14 +4,9 @@ import { execFile } from "node:child_process";
4
4
  import { promisify } from "node:util";
5
5
  import { isExcludedScanDirectory } from "./workspace-scan-policy.js";
6
6
  import { mapArchitecture } from "./architecture-map.js";
7
+ import ts from "typescript";
7
8
  const execFileAsync = promisify(execFile);
8
- const OS_JUNK = new Set([
9
- ".ds_store",
10
- "thumbs.db",
11
- "desktop.ini",
12
- "ehthumbs.db",
13
- "ehthumbs_vista.db"
14
- ]);
9
+ const OS_JUNK = new Set([".ds_store", "thumbs.db", "desktop.ini", "ehthumbs.db", "ehthumbs_vista.db"]);
15
10
  function classifyJunkFile(basename, relPath) {
16
11
  const lower = basename.toLowerCase();
17
12
  // OS Clutter
@@ -30,10 +25,23 @@ function classifyJunkFile(basename, relPath) {
30
25
  lower.endsWith(".part") ||
31
26
  lower.endsWith(".aria2") ||
32
27
  lower.endsWith(".download")) {
33
- return { category: lower.endsWith(".crdownload") || lower.endsWith(".part") || lower.endsWith(".aria2") || lower.endsWith(".download") ? "download" : "temporary", reason: "Incomplete download or temporary artifact" };
28
+ return {
29
+ category: lower.endsWith(".crdownload") ||
30
+ lower.endsWith(".part") ||
31
+ lower.endsWith(".aria2") ||
32
+ lower.endsWith(".download")
33
+ ? "download"
34
+ : "temporary",
35
+ reason: "Incomplete download or temporary artifact",
36
+ };
34
37
  }
35
38
  // Editor clutter
36
- if (lower.endsWith("~") || lower.endsWith(".swp") || lower.endsWith(".swo") || lower.endsWith(".bak") || lower.endsWith(".orig") || lower.endsWith(".rej")) {
39
+ if (lower.endsWith("~") ||
40
+ lower.endsWith(".swp") ||
41
+ lower.endsWith(".swo") ||
42
+ lower.endsWith(".bak") ||
43
+ lower.endsWith(".orig") ||
44
+ lower.endsWith(".rej")) {
37
45
  return { category: "editor", reason: "Editor backup, swap, or merge residue" };
38
46
  }
39
47
  // Python bytecode & caches
@@ -45,7 +53,11 @@ function classifyJunkFile(basename, relPath) {
45
53
  return { category: "cache", reason: "Compiled Java bytecode class file" };
46
54
  }
47
55
  // C / C++ / Rust / Windows object and debug files
48
- if (lower.endsWith(".o") || lower.endsWith(".obj") || lower.endsWith(".pdb") || lower.endsWith(".ilk") || lower.endsWith(".idb")) {
56
+ if (lower.endsWith(".o") ||
57
+ lower.endsWith(".obj") ||
58
+ lower.endsWith(".pdb") ||
59
+ lower.endsWith(".ilk") ||
60
+ lower.endsWith(".idb")) {
49
61
  return { category: "cache", reason: "Native object or debug symbol artifact" };
50
62
  }
51
63
  // Go test runner binaries
@@ -91,7 +103,7 @@ async function scanJunk(root, rel = "", items = [], emptyDirs = []) {
91
103
  category: "cache",
92
104
  reason: "Python runtime or test cache directory (regenerable)",
93
105
  sizeBytes: dirStat.size || 4096,
94
- isDirectory: true
106
+ isDirectory: true,
95
107
  });
96
108
  }
97
109
  catch {
@@ -110,7 +122,7 @@ async function scanJunk(root, rel = "", items = [], emptyDirs = []) {
110
122
  category: "cache",
111
123
  reason: "Test coverage report output (regenerable)",
112
124
  sizeBytes: dirStat.size || 4096,
113
- isDirectory: true
125
+ isDirectory: true,
114
126
  });
115
127
  }
116
128
  catch {
@@ -132,7 +144,7 @@ async function scanJunk(root, rel = "", items = [], emptyDirs = []) {
132
144
  category: classification.category,
133
145
  reason: classification.reason,
134
146
  sizeBytes: fileStat.size,
135
- isDirectory: false
147
+ isDirectory: false,
136
148
  });
137
149
  }
138
150
  catch {
@@ -146,12 +158,12 @@ async function scanJunk(root, rel = "", items = [], emptyDirs = []) {
146
158
  function parseNamedImports(namedBlock) {
147
159
  return namedBlock
148
160
  .split(",")
149
- .map(spec => spec.trim())
161
+ .map((spec) => spec.trim())
150
162
  .filter(Boolean)
151
- .map(spec => {
163
+ .map((spec) => {
152
164
  const isType = /^type\s+/.test(spec);
153
165
  const cleanSpec = spec.replace(/^type\s+/, "").trim();
154
- const parts = cleanSpec.split(/\s+as\s+/).map(p => p.trim());
166
+ const parts = cleanSpec.split(/\s+as\s+/).map((p) => p.trim());
155
167
  if (parts.length === 2 && parts[0] && parts[1]) {
156
168
  return { importedName: parts[0], localName: parts[1], isType };
157
169
  }
@@ -175,81 +187,53 @@ export function getProtectedMultilineLines(content, ext) {
175
187
  }
176
188
  const lines = content.split("\n");
177
189
  if (isJsTs) {
178
- let inBacktick = false;
179
- let inBlockComment = false;
180
- let templateBraceDepth = 0;
181
- for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
182
- const line = lines[lineIdx] ?? "";
183
- let i = 0;
184
- const startedInTemplate = inBacktick;
185
- while (i < line.length) {
186
- if (inBlockComment) {
187
- if (line.charAt(i) === "*" && line.charAt(i + 1) === "/") {
188
- inBlockComment = false;
189
- i += 2;
190
- }
191
- else {
192
- i++;
190
+ const isJsx = ext === ".tsx" || ext === ".jsx";
191
+ const scriptKind = ext === ".tsx"
192
+ ? ts.ScriptKind.TSX
193
+ : ext === ".jsx"
194
+ ? ts.ScriptKind.JSX
195
+ : ext === ".ts"
196
+ ? ts.ScriptKind.TS
197
+ : ts.ScriptKind.JS;
198
+ const sf = ts.createSourceFile("file" + ext, content, ts.ScriptTarget.Latest, true, scriptKind);
199
+ const getLine = (pos) => sf.getLineAndCharacterOfPosition(pos).line;
200
+ const visit = (node) => {
201
+ if (ts.isNoSubstitutionTemplateLiteral(node) ||
202
+ ts.isTemplateHead(node) ||
203
+ ts.isTemplateMiddle(node) ||
204
+ ts.isTemplateTail(node) ||
205
+ ts.isStringLiteral(node)) {
206
+ const startLine = getLine(node.getStart(sf));
207
+ const endLine = getLine(node.getEnd());
208
+ if (endLine > startLine ||
209
+ ts.isNoSubstitutionTemplateLiteral(node) ||
210
+ ts.isTemplateHead(node) ||
211
+ ts.isTemplateMiddle(node) ||
212
+ ts.isTemplateTail(node)) {
213
+ for (let l = startLine; l <= endLine; l++) {
214
+ protectedLines.add(l);
193
215
  }
194
- continue;
195
216
  }
196
- if (!inBacktick) {
197
- if (line.charAt(i) === "/" && line.charAt(i + 1) === "/") {
198
- break; // Single line comment
199
- }
200
- if (line.charAt(i) === "/" && line.charAt(i + 1) === "*") {
201
- inBlockComment = true;
202
- i += 2;
203
- continue;
204
- }
205
- if (line.charAt(i) === '"' || line.charAt(i) === "'") {
206
- const quote = line.charAt(i);
207
- i++;
208
- while (i < line.length && line.charAt(i) !== quote) {
209
- if (line.charAt(i) === "\\")
210
- i++;
211
- i++;
212
- }
213
- if (i < line.length)
214
- i++;
215
- continue;
216
- }
217
- if (line.charAt(i) === "`") {
218
- inBacktick = true;
219
- i++;
220
- continue;
221
- }
222
- }
223
- else {
224
- // Inside template literal
225
- if (line.charAt(i) === "\\") {
226
- i += 2;
227
- continue;
228
- }
229
- if (line.charAt(i) === "$" && line.charAt(i + 1) === "{") {
230
- templateBraceDepth++;
231
- i += 2;
232
- continue;
233
- }
234
- if (templateBraceDepth > 0) {
235
- if (line.charAt(i) === "{")
236
- templateBraceDepth++;
237
- else if (line.charAt(i) === "}")
238
- templateBraceDepth--;
239
- i++;
240
- continue;
241
- }
242
- if (line.charAt(i) === "`") {
243
- inBacktick = false;
244
- i++;
245
- continue;
217
+ }
218
+ ts.forEachChild(node, visit);
219
+ };
220
+ visit(sf);
221
+ // Also protect multiline comment trivia (/* ... */)
222
+ const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, isJsx ? ts.LanguageVariant.JSX : ts.LanguageVariant.Standard, content);
223
+ let token = scanner.scan();
224
+ while (token !== ts.SyntaxKind.EndOfFileToken) {
225
+ if (token === ts.SyntaxKind.MultiLineCommentTrivia) {
226
+ const start = scanner.getTokenPos();
227
+ const end = scanner.getTextPos();
228
+ if (content.slice(start, end).includes("\n")) {
229
+ const startLine = sf.getLineAndCharacterOfPosition(start).line;
230
+ const endLine = sf.getLineAndCharacterOfPosition(end).line;
231
+ for (let l = startLine; l <= endLine; l++) {
232
+ protectedLines.add(l);
246
233
  }
247
234
  }
248
- i++;
249
- }
250
- if (startedInTemplate || inBacktick) {
251
- protectedLines.add(lineIdx);
252
235
  }
236
+ token = scanner.scan();
253
237
  }
254
238
  }
255
239
  else if (isPython) {
@@ -362,7 +346,7 @@ export function autoFixCodeContent(content, filePath) {
362
346
  file: filePath,
363
347
  type: "whitespace",
364
348
  detail: "Trimmed trailing whitespace from lines (string literals preserved)",
365
- applied: true
349
+ applied: true,
366
350
  });
367
351
  }
368
352
  // 2. Blank line normalization: collapse 3+ consecutive newlines outside string literals
@@ -373,7 +357,7 @@ export function autoFixCodeContent(content, filePath) {
373
357
  file: filePath,
374
358
  type: "blank-lines",
375
359
  detail: "Collapsed excessive consecutive blank lines",
376
- applied: true
360
+ applied: true,
377
361
  });
378
362
  }
379
363
  }
@@ -407,7 +391,7 @@ export function autoFixCodeContent(content, filePath) {
407
391
  file: filePath,
408
392
  type: "blank-lines",
409
393
  detail: "Collapsed excessive consecutive blank lines outside string literals",
410
- applied: true
394
+ applied: true,
411
395
  });
412
396
  }
413
397
  }
@@ -446,8 +430,12 @@ export function autoFixCodeContent(content, filePath) {
446
430
  const wordRegex = new RegExp(`\\b${escaped}\\b`);
447
431
  if (isJsxProtected || wordRegex.test(contentWithoutImport)) {
448
432
  const formatted = spec.importedName === spec.localName
449
- ? (spec.isType ? `type ${spec.localName}` : spec.localName)
450
- : (spec.isType ? `type ${spec.importedName} as ${spec.localName}` : `${spec.importedName} as ${spec.localName}`);
433
+ ? spec.isType
434
+ ? `type ${spec.localName}`
435
+ : spec.localName
436
+ : spec.isType
437
+ ? `type ${spec.importedName} as ${spec.localName}`
438
+ : `${spec.importedName} as ${spec.localName}`;
451
439
  survivingSpecifiers.push(formatted);
452
440
  }
453
441
  else {
@@ -470,7 +458,7 @@ export function autoFixCodeContent(content, filePath) {
470
458
  file: filePath,
471
459
  type: "unused-import",
472
460
  detail: `Removed unused named import(s): ${removedSpecifiers.join(", ")} from "${fromPath}"`,
473
- applied: true
461
+ applied: true,
474
462
  });
475
463
  }
476
464
  }
@@ -507,13 +495,16 @@ export function autoFixCodeContent(content, filePath) {
507
495
  continue;
508
496
  if (rawSpecifiers.trim() === "*")
509
497
  continue;
510
- const specs = rawSpecifiers.split(",").map(s => s.trim()).filter(Boolean);
511
- const parsed = specs.map(s => {
512
- const parts = s.split(/\s+as\s+/).map(p => p.trim());
498
+ const specs = rawSpecifiers
499
+ .split(",")
500
+ .map((s) => s.trim())
501
+ .filter(Boolean);
502
+ const parsed = specs.map((s) => {
503
+ const parts = s.split(/\s+as\s+/).map((p) => p.trim());
513
504
  return {
514
505
  importedName: parts[0] || s,
515
506
  localName: parts[1] || parts[0] || s,
516
- raw: s
507
+ raw: s,
517
508
  };
518
509
  });
519
510
  const contentWithoutImport = updated.slice(0, match.index) + updated.slice(match.index + fullStatement.length);
@@ -543,7 +534,7 @@ export function autoFixCodeContent(content, filePath) {
543
534
  file: filePath,
544
535
  type: "unused-import",
545
536
  detail: `Removed unused Python import(s): ${removed.join(", ")} from "${fromModule}"`,
546
- applied: true
537
+ applied: true,
547
538
  });
548
539
  }
549
540
  }
@@ -569,7 +560,7 @@ async function createBackupSnapshot(root, junkToDelete, emptyDirsToDelete, files
569
560
  root,
570
561
  deletedFiles: [],
571
562
  deletedDirs: [...emptyDirsToDelete],
572
- modifiedFiles: []
563
+ modifiedFiles: [],
573
564
  };
574
565
  // 1. Back up junk files before deletion
575
566
  for (let i = 0; i < junkToDelete.length; i++) {
@@ -583,7 +574,7 @@ async function createBackupSnapshot(root, junkToDelete, emptyDirsToDelete, files
583
574
  manifest.deletedFiles.push({
584
575
  relPath: item.path,
585
576
  backupRelative: backupRel,
586
- sizeBytes: item.sizeBytes
577
+ sizeBytes: item.sizeBytes,
587
578
  });
588
579
  }
589
580
  catch {
@@ -599,7 +590,7 @@ async function createBackupSnapshot(root, junkToDelete, emptyDirsToDelete, files
599
590
  await writeFile(backupDest, item.originalContent, "utf8");
600
591
  manifest.modifiedFiles.push({
601
592
  relPath: item.file,
602
- backupRelative: backupRel
593
+ backupRelative: backupRel,
603
594
  });
604
595
  }
605
596
  catch {
@@ -628,7 +619,7 @@ export async function undoLastClean(inputPath) {
628
619
  restoredFiles: [],
629
620
  restoredDirs: [],
630
621
  revertedCodeFixes: [],
631
- errors: ["No previous ANVIL clean/fix backup found in this workspace."]
622
+ errors: ["No previous ANVIL clean/fix backup found in this workspace."],
632
623
  };
633
624
  }
634
625
  const backupRoot = pointer.backupRoot || path.join(root, ".anvil", "backups", pointer.backupId);
@@ -646,7 +637,7 @@ export async function undoLastClean(inputPath) {
646
637
  restoredFiles: [],
647
638
  restoredDirs: [],
648
639
  revertedCodeFixes: [],
649
- errors: [`Backup manifest not found or corrupted at ${manifestPath}`]
640
+ errors: [`Backup manifest not found or corrupted at ${manifestPath}`],
650
641
  };
651
642
  }
652
643
  const restoredFiles = [];
@@ -705,7 +696,7 @@ export async function undoLastClean(inputPath) {
705
696
  restoredFiles,
706
697
  restoredDirs,
707
698
  revertedCodeFixes,
708
- errors
699
+ errors,
709
700
  };
710
701
  }
711
702
  async function detectTestCommand(root) {
@@ -749,14 +740,14 @@ anvil clean --apply --json > /dev/null 2>&1 || true
749
740
  return {
750
741
  success: true,
751
742
  hookPath,
752
- detail: "Installed ANVIL pre-commit hook into .git/hooks/pre-commit"
743
+ detail: "Installed ANVIL pre-commit hook into .git/hooks/pre-commit",
753
744
  };
754
745
  }
755
746
  catch (err) {
756
747
  return {
757
748
  success: false,
758
749
  hookPath: path.join(gitHooksDir, "pre-commit"),
759
- detail: `Failed to install pre-commit hook: ${err?.message || String(err)}`
750
+ detail: `Failed to install pre-commit hook: ${err?.message || String(err)}`,
760
751
  };
761
752
  }
762
753
  }
@@ -770,7 +761,7 @@ export function formatUndoReport(result) {
770
761
  `- **Reverted code fixes:** \`${result.revertedCodeFixes.length}\` files restored to original content`,
771
762
  `- **Restored deleted files:** \`${result.restoredFiles.length}\` files recovered`,
772
763
  `- **Restored directories:** \`${result.restoredDirs.length}\` directories re-created`,
773
- ""
764
+ "",
774
765
  ];
775
766
  if (result.revertedCodeFixes.length > 0) {
776
767
  lines.push("## Reverted Code Fixes");
@@ -821,7 +812,7 @@ export async function cleanProject(inputPath, options = {}) {
821
812
  category: "empty-dir",
822
813
  reason: "Empty directory leftover",
823
814
  sizeBytes: 0,
824
- isDirectory: true
815
+ isDirectory: true,
825
816
  });
826
817
  }
827
818
  // 1. Scan for orphan source files using architecture mapping
@@ -843,7 +834,7 @@ export async function cleanProject(inputPath, options = {}) {
843
834
  orphanFiles.push({
844
835
  file: node.file,
845
836
  lines: node.lines,
846
- reason: "Source module with 0 incoming imports (unreferenced by mapped files)"
837
+ reason: "Source module with 0 incoming imports (unreferenced by mapped files)",
847
838
  });
848
839
  }
849
840
  }
@@ -869,17 +860,30 @@ export async function cleanProject(inputPath, options = {}) {
869
860
  for (const e of entries) {
870
861
  const childRel = rel ? path.join(rel, e.name) : e.name;
871
862
  if (e.isDirectory() && !isExcludedScanDirectory(e.name)) {
872
- res.push(...await collectSource(dir, childRel));
863
+ res.push(...(await collectSource(dir, childRel)));
873
864
  }
874
- else if (e.isFile() && [
875
- ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs",
876
- ".py", ".pyw",
877
- ".go",
878
- ".rs",
879
- ".java", ".kt",
880
- ".c", ".cpp", ".cc", ".cxx", ".h", ".hpp",
881
- ".cs"
882
- ].includes(path.extname(e.name).toLowerCase())) {
865
+ else if (e.isFile() &&
866
+ [
867
+ ".ts",
868
+ ".tsx",
869
+ ".js",
870
+ ".jsx",
871
+ ".mjs",
872
+ ".cjs",
873
+ ".py",
874
+ ".pyw",
875
+ ".go",
876
+ ".rs",
877
+ ".java",
878
+ ".kt",
879
+ ".c",
880
+ ".cpp",
881
+ ".cc",
882
+ ".cxx",
883
+ ".h",
884
+ ".hpp",
885
+ ".cs",
886
+ ].includes(path.extname(e.name).toLowerCase())) {
883
887
  res.push(childRel.split(path.sep).join("/"));
884
888
  }
885
889
  }
@@ -944,7 +948,7 @@ export async function cleanProject(inputPath, options = {}) {
944
948
  }
945
949
  // D. Self-Healing Verification Loop
946
950
  if (verify) {
947
- const testCmd = options.testCommand || await detectTestCommand(root);
951
+ const testCmd = options.testCommand || (await detectTestCommand(root));
948
952
  if (testCmd) {
949
953
  try {
950
954
  let stdout = "";
@@ -970,7 +974,7 @@ export async function cleanProject(inputPath, options = {}) {
970
974
  passed: true,
971
975
  rolledBack: false,
972
976
  command: testCmd,
973
- output: stdout.trim().slice(0, 500)
977
+ output: stdout.trim().slice(0, 500),
974
978
  };
975
979
  }
976
980
  catch (testErr) {
@@ -981,7 +985,7 @@ export async function cleanProject(inputPath, options = {}) {
981
985
  passed: false,
982
986
  rolledBack: true,
983
987
  command: testCmd,
984
- error: `Project tests failed after code repairs: ${testErr?.message || String(testErr)}. Workspace was automatically restored.`
988
+ error: `Project tests failed after code repairs: ${testErr?.message || String(testErr)}. Workspace was automatically restored.`,
985
989
  };
986
990
  warnings.push("Verification failed! Workspace was automatically rolled back to prevent regression.");
987
991
  }
@@ -991,7 +995,7 @@ export async function cleanProject(inputPath, options = {}) {
991
995
  }
992
996
  }
993
997
  }
994
- const codeFixesApplied = (apply && (!verification || !verification.rolledBack)) ? codeFixes.length : 0;
998
+ const codeFixesApplied = apply && (!verification || !verification.rolledBack) ? codeFixes.length : 0;
995
999
  return {
996
1000
  root,
997
1001
  generatedAt: new Date().toISOString(),
@@ -1004,13 +1008,13 @@ export async function cleanProject(inputPath, options = {}) {
1004
1008
  codeFixes,
1005
1009
  stats: {
1006
1010
  junkFound: junkItems.length,
1007
- junkDeleted: (apply && (!verification || !verification.rolledBack)) ? junkDeleted : 0,
1011
+ junkDeleted: apply && (!verification || !verification.rolledBack) ? junkDeleted : 0,
1008
1012
  bytesReclaimed,
1009
1013
  codeFixesFound: codeFixes.length,
1010
1014
  codeFixesApplied,
1011
- orphanFilesFound: orphanFiles.length
1015
+ orphanFilesFound: orphanFiles.length,
1012
1016
  },
1013
- warnings
1017
+ warnings,
1014
1018
  };
1015
1019
  }
1016
1020
  function formatBytes(bytes) {
@@ -1021,7 +1025,9 @@ function formatBytes(bytes) {
1021
1025
  return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
1022
1026
  }
1023
1027
  export function formatCleanReport(result) {
1024
- const modeText = result.applied ? "**APPLIED** (Deleted junk & saved fixes)" : "**DRY RUN** (Preview only — pass `--apply` to execute)";
1028
+ const modeText = result.applied
1029
+ ? "**APPLIED** (Deleted junk & saved fixes)"
1030
+ : "**DRY RUN** (Preview only — pass `--apply` to execute)";
1025
1031
  const lines = [
1026
1032
  "# ANVIL Workspace Clean & Repair",
1027
1033
  "",
@@ -1030,10 +1036,18 @@ export function formatCleanReport(result) {
1030
1036
  `- **Junk items:** \`${result.stats.junkFound}\` found (${formatBytes(result.stats.bytesReclaimed)} space)${result.applied ? ` · \`${result.stats.junkDeleted}\` deleted` : ""}`,
1031
1037
  `- **Code auto-fixes:** \`${result.stats.codeFixesFound}\` available${result.applied ? ` · \`${result.stats.codeFixesApplied}\` applied` : ""}`,
1032
1038
  `- **Orphan files detected:** \`${result.stats.orphanFilesFound}\``,
1033
- ...(result.backupId ? [`- **Rollback backup:** \`${result.backupId}\` (Run \`anvil undo\` to restore anytime)`] : []),
1034
- ...(result.verification ? [(result.verification.passed ? `- **Self-Healing Verification:** PASSED (\`${result.verification.command}\`)` : `- **Self-Healing Verification:** FAILED -> AUTO-ROLLED BACK (\`${result.verification.command}\`)`)] : []),
1039
+ ...(result.backupId
1040
+ ? [`- **Rollback backup:** \`${result.backupId}\` (Run \`anvil undo\` to restore anytime)`]
1041
+ : []),
1042
+ ...(result.verification
1043
+ ? [
1044
+ result.verification.passed
1045
+ ? `- **Self-Healing Verification:** PASSED (\`${result.verification.command}\`)`
1046
+ : `- **Self-Healing Verification:** FAILED -> AUTO-ROLLED BACK (\`${result.verification.command}\`)`,
1047
+ ]
1048
+ : []),
1035
1049
  `- **Timestamp:** \`${result.generatedAt}\``,
1036
- ""
1050
+ "",
1037
1051
  ];
1038
1052
  if (result.junkItems.length > 0) {
1039
1053
  lines.push("## Workspace Junk Artifacts");