anvil-engineering-workbench 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +23 -18
- package/dist/ai/claude-code-provider.js +55 -9
- package/dist/ai/claude-code-provider.js.map +1 -1
- package/dist/ai/provider.js +1 -1
- package/dist/ai/provider.js.map +1 -1
- package/dist/cli.js +837 -278
- package/dist/cli.js.map +1 -1
- package/dist/core/adr-engine.js +9 -11
- package/dist/core/adr-engine.js.map +1 -1
- package/dist/core/agent-config-release.js +29 -13
- package/dist/core/agent-config-release.js.map +1 -1
- package/dist/core/agent-config-versioning.js +32 -17
- package/dist/core/agent-config-versioning.js.map +1 -1
- package/dist/core/agent-evaluation-intelligence.js +30 -38
- package/dist/core/agent-evaluation-intelligence.js.map +1 -1
- package/dist/core/agent-evolution.js +109 -20
- package/dist/core/agent-evolution.js.map +1 -1
- package/dist/core/agent-experiment-studio.js +19 -11
- package/dist/core/agent-experiment-studio.js.map +1 -1
- package/dist/core/agent-optimization.js +69 -14
- package/dist/core/agent-optimization.js.map +1 -1
- package/dist/core/agent-registry.js +87 -15
- package/dist/core/agent-registry.js.map +1 -1
- package/dist/core/agent-security-audit.js +21 -21
- package/dist/core/agent-security-audit.js.map +1 -1
- package/dist/core/agent-workspace-context.js +37 -6
- package/dist/core/agent-workspace-context.js.map +1 -1
- package/dist/core/ai-code-review.js +60 -12
- package/dist/core/ai-code-review.js.map +1 -1
- package/dist/core/anthropic-provider.js.map +1 -1
- package/dist/core/architecture-map.js +87 -24
- package/dist/core/architecture-map.js.map +1 -1
- package/dist/core/benchmark-engine.js +89 -21
- package/dist/core/benchmark-engine.js.map +1 -1
- package/dist/core/benchmark-matrix.js +215 -41
- package/dist/core/benchmark-matrix.js.map +1 -1
- package/dist/core/benchmark-regression.js +124 -18
- package/dist/core/benchmark-regression.js.map +1 -1
- package/dist/core/change-intelligence.js +102 -43
- package/dist/core/change-intelligence.js.map +1 -1
- package/dist/core/code-intelligence.js +40 -13
- package/dist/core/code-intelligence.js.map +1 -1
- package/dist/core/code-review.js +145 -17
- package/dist/core/code-review.js.map +1 -1
- package/dist/core/code-search.js +79 -39
- package/dist/core/code-search.js.map +1 -1
- package/dist/core/container-sandbox.js +87 -23
- package/dist/core/container-sandbox.js.map +1 -1
- package/dist/core/dashboard-server.js +379 -93
- package/dist/core/dashboard-server.js.map +1 -1
- package/dist/core/dependency-graph.js +75 -13
- package/dist/core/dependency-graph.js.map +1 -1
- package/dist/core/dependency-impact.js +132 -33
- package/dist/core/dependency-impact.js.map +1 -1
- package/dist/core/dependency-intelligence.js +153 -56
- package/dist/core/dependency-intelligence.js.map +1 -1
- package/dist/core/doctor.js +3 -3
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/engineering-risk.js +75 -40
- package/dist/core/engineering-risk.js.map +1 -1
- package/dist/core/env-compat.js.map +1 -1
- package/dist/core/evaluation-engine.js +188 -42
- package/dist/core/evaluation-engine.js.map +1 -1
- package/dist/core/execution-trace.js +83 -29
- package/dist/core/execution-trace.js.map +1 -1
- package/dist/core/experiment-history.js +70 -20
- package/dist/core/experiment-history.js.map +1 -1
- package/dist/core/experiment-manifest.js +92 -13
- package/dist/core/experiment-manifest.js.map +1 -1
- package/dist/core/gemini-provider.js.map +1 -1
- package/dist/core/git-intelligence.js +68 -16
- package/dist/core/git-intelligence.js.map +1 -1
- package/dist/core/hook-engine.js +7 -3
- package/dist/core/hook-engine.js.map +1 -1
- package/dist/core/hosted-agent-provider.js +48 -8
- package/dist/core/hosted-agent-provider.js.map +1 -1
- package/dist/core/intelligence-timeline.js +92 -43
- package/dist/core/intelligence-timeline.js.map +1 -1
- package/dist/core/mcp-setup.js +12 -12
- package/dist/core/mcp-setup.js.map +1 -1
- package/dist/core/model-router.js +153 -37
- package/dist/core/model-router.js.map +1 -1
- package/dist/core/openai-compatible-provider.js +41 -10
- package/dist/core/openai-compatible-provider.js.map +1 -1
- package/dist/core/orchestrator.js +28 -23
- package/dist/core/orchestrator.js.map +1 -1
- package/dist/core/patch-application.js +88 -24
- package/dist/core/patch-application.js.map +1 -1
- package/dist/core/patch-approval.js +43 -15
- package/dist/core/patch-approval.js.map +1 -1
- package/dist/core/patch-validation.js +93 -15
- package/dist/core/patch-validation.js.map +1 -1
- package/dist/core/permission-policy.js +8 -5
- package/dist/core/permission-policy.js.map +1 -1
- package/dist/core/policy-engine.d.ts +76 -0
- package/dist/core/policy-engine.js +352 -0
- package/dist/core/policy-engine.js.map +1 -0
- package/dist/core/project-cleaner.js +143 -129
- package/dist/core/project-cleaner.js.map +1 -1
- package/dist/core/project-health.js +183 -21
- package/dist/core/project-health.js.map +1 -1
- package/dist/core/project-init.js +32 -20
- package/dist/core/project-init.js.map +1 -1
- package/dist/core/project-inspector.js +81 -32
- package/dist/core/project-inspector.js.map +1 -1
- package/dist/core/project-memory.js +41 -18
- package/dist/core/project-memory.js.map +1 -1
- package/dist/core/provider-diagnostics.js +65 -12
- package/dist/core/provider-diagnostics.js.map +1 -1
- package/dist/core/quality-audit.js +167 -28
- package/dist/core/quality-audit.js.map +1 -1
- package/dist/core/regression-intelligence.js +88 -8
- package/dist/core/regression-intelligence.js.map +1 -1
- package/dist/core/remediation-planner.js +112 -40
- package/dist/core/remediation-planner.js.map +1 -1
- package/dist/core/review-history.js +39 -7
- package/dist/core/review-history.js.map +1 -1
- package/dist/core/run-history-output.js.map +1 -1
- package/dist/core/run-replay.js +12 -10
- package/dist/core/run-replay.js.map +1 -1
- package/dist/core/run-store.js +48 -21
- package/dist/core/run-store.js.map +1 -1
- package/dist/core/sandbox-cleanup-audit.js +1 -1
- package/dist/core/sandbox-cleanup-audit.js.map +1 -1
- package/dist/core/sandbox-compliance.js +53 -9
- package/dist/core/sandbox-compliance.js.map +1 -1
- package/dist/core/sandbox-lifecycle.js +1 -1
- package/dist/core/sandbox-lifecycle.js.map +1 -1
- package/dist/core/sandbox-policy.js +27 -3
- package/dist/core/sandbox-policy.js.map +1 -1
- package/dist/core/sandbox-runtime.js +9 -5
- package/dist/core/sandbox-runtime.js.map +1 -1
- package/dist/core/sandbox-security-profiles.js +31 -12
- package/dist/core/sandbox-security-profiles.js.map +1 -1
- package/dist/core/sarif-formatter.d.ts +10 -3
- package/dist/core/sarif-formatter.js +172 -57
- package/dist/core/sarif-formatter.js.map +1 -1
- package/dist/core/security-scanner.js +40 -32
- package/dist/core/security-scanner.js.map +1 -1
- package/dist/core/skill-registry.js +83 -21
- package/dist/core/skill-registry.js.map +1 -1
- package/dist/core/staged-verification.js +25 -10
- package/dist/core/staged-verification.js.map +1 -1
- package/dist/core/verification-history.js +12 -7
- package/dist/core/verification-history.js.map +1 -1
- package/dist/core/verification.js +50 -19
- package/dist/core/verification.js.map +1 -1
- package/dist/core/workflow-store.js +16 -4
- package/dist/core/workflow-store.js.map +1 -1
- package/dist/core/workspace-browser.js +57 -10
- package/dist/core/workspace-browser.js.map +1 -1
- package/dist/core/workspace-scan-policy.js +26 -4
- package/dist/core/workspace-scan-policy.js.map +1 -1
- package/dist/core/workspace-tool-broker.d.ts +1 -1
- package/dist/core/workspace-tool-broker.js +25 -4
- package/dist/core/workspace-tool-broker.js.map +1 -1
- package/dist/mcp/server.js +148 -55
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/workspace-path.js +2 -2
- package/dist/mcp/workspace-path.js.map +1 -1
- 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 {
|
|
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("~") ||
|
|
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") ||
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
?
|
|
450
|
-
|
|
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
|
|
511
|
-
|
|
512
|
-
|
|
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
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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 =
|
|
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:
|
|
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
|
|
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
|
|
1034
|
-
|
|
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");
|