@vibecheckai/cli 3.5.0 → 3.5.2
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/bin/registry.js +214 -237
- package/bin/runners/cli-utils.js +33 -2
- package/bin/runners/context/analyzer.js +52 -1
- package/bin/runners/context/generators/cursor.js +2 -49
- package/bin/runners/context/git-context.js +3 -1
- package/bin/runners/context/team-conventions.js +33 -7
- package/bin/runners/lib/analysis-core.js +25 -5
- package/bin/runners/lib/analyzers.js +431 -481
- package/bin/runners/lib/default-config.js +127 -0
- package/bin/runners/lib/doctor/modules/security.js +3 -1
- package/bin/runners/lib/engine/ast-cache.js +210 -0
- package/bin/runners/lib/engine/auth-extractor.js +211 -0
- package/bin/runners/lib/engine/billing-extractor.js +112 -0
- package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
- package/bin/runners/lib/engine/env-extractor.js +207 -0
- package/bin/runners/lib/engine/express-extractor.js +208 -0
- package/bin/runners/lib/engine/extractors.js +849 -0
- package/bin/runners/lib/engine/index.js +207 -0
- package/bin/runners/lib/engine/repo-index.js +514 -0
- package/bin/runners/lib/engine/types.js +124 -0
- package/bin/runners/lib/engines/accessibility-engine.js +18 -218
- package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
- package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
- package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
- package/bin/runners/lib/engines/mock-data-engine.js +10 -53
- package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
- package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
- package/bin/runners/lib/engines/type-aware-engine.js +39 -263
- package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
- package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
- package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
- package/bin/runners/lib/entitlements-v2.js +73 -97
- package/bin/runners/lib/error-handler.js +44 -3
- package/bin/runners/lib/error-messages.js +289 -0
- package/bin/runners/lib/evidence-pack.js +7 -1
- package/bin/runners/lib/finding-id.js +69 -0
- package/bin/runners/lib/finding-sorter.js +89 -0
- package/bin/runners/lib/html-proof-report.js +700 -350
- package/bin/runners/lib/missions/plan.js +6 -46
- package/bin/runners/lib/missions/templates.js +0 -232
- package/bin/runners/lib/next-action.js +560 -0
- package/bin/runners/lib/prerequisites.js +149 -0
- package/bin/runners/lib/route-detection.js +137 -68
- package/bin/runners/lib/scan-output.js +91 -76
- package/bin/runners/lib/scan-runner.js +135 -0
- package/bin/runners/lib/schemas/ajv-validator.js +464 -0
- package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
- package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
- package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
- package/bin/runners/lib/schemas/run-request.schema.json +108 -0
- package/bin/runners/lib/schemas/validator.js +27 -0
- package/bin/runners/lib/schemas/verdict.schema.json +140 -0
- package/bin/runners/lib/ship-output-enterprise.js +23 -23
- package/bin/runners/lib/ship-output.js +75 -31
- package/bin/runners/lib/terminal-ui.js +6 -113
- package/bin/runners/lib/truth.js +351 -10
- package/bin/runners/lib/unified-cli-output.js +430 -603
- package/bin/runners/lib/unified-output.js +13 -9
- package/bin/runners/runAIAgent.js +10 -5
- package/bin/runners/runAgent.js +0 -3
- package/bin/runners/runAllowlist.js +389 -0
- package/bin/runners/runApprove.js +0 -33
- package/bin/runners/runAuth.js +73 -45
- package/bin/runners/runCheckpoint.js +51 -11
- package/bin/runners/runClassify.js +85 -21
- package/bin/runners/runContext.js +0 -3
- package/bin/runners/runDoctor.js +41 -28
- package/bin/runners/runEvidencePack.js +362 -0
- package/bin/runners/runFirewall.js +0 -3
- package/bin/runners/runFirewallHook.js +0 -3
- package/bin/runners/runFix.js +66 -76
- package/bin/runners/runGuard.js +18 -411
- package/bin/runners/runInit.js +113 -30
- package/bin/runners/runLabs.js +424 -0
- package/bin/runners/runMcp.js +19 -25
- package/bin/runners/runPolish.js +64 -240
- package/bin/runners/runPromptFirewall.js +12 -5
- package/bin/runners/runProve.js +57 -22
- package/bin/runners/runQuickstart.js +531 -0
- package/bin/runners/runReality.js +59 -68
- package/bin/runners/runReport.js +38 -33
- package/bin/runners/runRuntime.js +8 -5
- package/bin/runners/runScan.js +1413 -190
- package/bin/runners/runShip.js +113 -719
- package/bin/runners/runTruth.js +0 -3
- package/bin/runners/runValidate.js +13 -9
- package/bin/runners/runWatch.js +23 -14
- package/bin/scan.js +6 -1
- package/bin/vibecheck.js +204 -185
- package/mcp-server/deprecation-middleware.js +282 -0
- package/mcp-server/handlers/index.ts +15 -0
- package/mcp-server/handlers/tool-handler.ts +554 -0
- package/mcp-server/index-v1.js +698 -0
- package/mcp-server/index.js +210 -238
- package/mcp-server/lib/cache-wrapper.cjs +383 -0
- package/mcp-server/lib/error-envelope.js +138 -0
- package/mcp-server/lib/executor.ts +499 -0
- package/mcp-server/lib/index.ts +19 -0
- package/mcp-server/lib/rate-limiter.js +166 -0
- package/mcp-server/lib/sandbox.test.ts +519 -0
- package/mcp-server/lib/sandbox.ts +395 -0
- package/mcp-server/lib/types.ts +267 -0
- package/mcp-server/package.json +12 -3
- package/mcp-server/registry/tool-registry.js +794 -0
- package/mcp-server/registry/tools.json +605 -0
- package/mcp-server/registry.test.ts +334 -0
- package/mcp-server/tests/tier-gating.test.js +297 -0
- package/mcp-server/tier-auth.js +378 -45
- package/mcp-server/tools-v3.js +353 -442
- package/mcp-server/tsconfig.json +37 -0
- package/mcp-server/vibecheck-2.0-tools.js +14 -1
- package/package.json +1 -1
- package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
- package/bin/runners/lib/audit-logger.js +0 -532
- package/bin/runners/lib/authority/authorities/architecture.js +0 -364
- package/bin/runners/lib/authority/authorities/compliance.js +0 -341
- package/bin/runners/lib/authority/authorities/human.js +0 -343
- package/bin/runners/lib/authority/authorities/quality.js +0 -420
- package/bin/runners/lib/authority/authorities/security.js +0 -228
- package/bin/runners/lib/authority/index.js +0 -293
- package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
- package/bin/runners/lib/cli-charts.js +0 -368
- package/bin/runners/lib/cli-config-display.js +0 -405
- package/bin/runners/lib/cli-demo.js +0 -275
- package/bin/runners/lib/cli-errors.js +0 -438
- package/bin/runners/lib/cli-help-formatter.js +0 -439
- package/bin/runners/lib/cli-interactive-menu.js +0 -509
- package/bin/runners/lib/cli-prompts.js +0 -441
- package/bin/runners/lib/cli-scan-cards.js +0 -362
- package/bin/runners/lib/compliance-reporter.js +0 -710
- package/bin/runners/lib/conductor/index.js +0 -671
- package/bin/runners/lib/easy/README.md +0 -123
- package/bin/runners/lib/easy/index.js +0 -140
- package/bin/runners/lib/easy/interactive-wizard.js +0 -788
- package/bin/runners/lib/easy/one-click-firewall.js +0 -564
- package/bin/runners/lib/easy/zero-config-reality.js +0 -714
- package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
- package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
- package/bin/runners/lib/engines/confidence-scoring.js +0 -276
- package/bin/runners/lib/engines/context-detection.js +0 -264
- package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
- package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
- package/bin/runners/lib/engines/env-variables-engine.js +0 -458
- package/bin/runners/lib/engines/error-handling-engine.js +0 -437
- package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
- package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
- package/bin/runners/lib/engines/framework-detection.js +0 -508
- package/bin/runners/lib/engines/import-order-engine.js +0 -429
- package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
- package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
- package/bin/runners/lib/engines/orchestrator.js +0 -334
- package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
- package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
- package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
- package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
- package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
- package/bin/runners/lib/enhanced-features/index.js +0 -305
- package/bin/runners/lib/enhanced-output.js +0 -631
- package/bin/runners/lib/enterprise.js +0 -300
- package/bin/runners/lib/firewall/command-validator.js +0 -351
- package/bin/runners/lib/firewall/config.js +0 -341
- package/bin/runners/lib/firewall/content-validator.js +0 -519
- package/bin/runners/lib/firewall/index.js +0 -101
- package/bin/runners/lib/firewall/path-validator.js +0 -256
- package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
- package/bin/runners/lib/mcp-utils.js +0 -425
- package/bin/runners/lib/output/index.js +0 -1022
- package/bin/runners/lib/policy-engine.js +0 -652
- package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
- package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
- package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
- package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
- package/bin/runners/lib/polish/autofix/index.js +0 -200
- package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
- package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
- package/bin/runners/lib/polish/backend-checks.js +0 -148
- package/bin/runners/lib/polish/documentation-checks.js +0 -111
- package/bin/runners/lib/polish/frontend-checks.js +0 -168
- package/bin/runners/lib/polish/index.js +0 -71
- package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
- package/bin/runners/lib/polish/library-detection.js +0 -175
- package/bin/runners/lib/polish/performance-checks.js +0 -100
- package/bin/runners/lib/polish/security-checks.js +0 -148
- package/bin/runners/lib/polish/utils.js +0 -203
- package/bin/runners/lib/prompt-builder.js +0 -540
- package/bin/runners/lib/proof-certificate.js +0 -634
- package/bin/runners/lib/reality/accessibility-audit.js +0 -946
- package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
- package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
- package/bin/runners/lib/reality/performance-tracker.js +0 -1077
- package/bin/runners/lib/reality/scenario-generator.js +0 -1404
- package/bin/runners/lib/reality/visual-regression.js +0 -852
- package/bin/runners/lib/reality-profiler.js +0 -717
- package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
- package/bin/runners/lib/review/ai-code-review.js +0 -832
- package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
- package/bin/runners/lib/sbom-generator.js +0 -641
- package/bin/runners/lib/scan-output-enhanced.js +0 -512
- package/bin/runners/lib/security/owasp-scanner.js +0 -939
- package/bin/runners/lib/validators/contract-validator.js +0 -283
- package/bin/runners/lib/validators/dead-export-detector.js +0 -279
- package/bin/runners/lib/validators/dep-audit.js +0 -245
- package/bin/runners/lib/validators/env-validator.js +0 -319
- package/bin/runners/lib/validators/index.js +0 -120
- package/bin/runners/lib/validators/license-checker.js +0 -252
- package/bin/runners/lib/validators/route-validator.js +0 -290
- package/bin/runners/runAuthority.js +0 -528
- package/bin/runners/runConductor.js +0 -772
- package/bin/runners/runContainer.js +0 -366
- package/bin/runners/runEasy.js +0 -410
- package/bin/runners/runIaC.js +0 -372
- package/bin/runners/runVibe.js +0 -791
- package/mcp-server/tools.js +0 -495
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Polish Auto-Fix Passes
|
|
3
|
-
*
|
|
4
|
-
* Collection of automated code fixes for production readiness.
|
|
5
|
-
* Each pass transforms code using Babel AST without requiring an LLM.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* vibecheck polish # Dry-run (show what would change)
|
|
9
|
-
* vibecheck polish --apply # Apply changes
|
|
10
|
-
* vibecheck polish --passes remove-consoles,dead-code
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
"use strict";
|
|
14
|
-
|
|
15
|
-
const { removeConsoles } = require("./remove-consoles");
|
|
16
|
-
const { strengthenTypes } = require("./strengthen-types");
|
|
17
|
-
const { wrapAsyncHandlers } = require("./async-handlers");
|
|
18
|
-
const { removeDeadCode } = require("./dead-code");
|
|
19
|
-
const { fixAccessibility } = require("./accessibility-fixes");
|
|
20
|
-
const { optimizeImports } = require("./imports-optimizer");
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* All available polish passes
|
|
24
|
-
* Order matters - some passes should run before others
|
|
25
|
-
*/
|
|
26
|
-
const POLISH_PASSES = [
|
|
27
|
-
{
|
|
28
|
-
id: "remove-consoles",
|
|
29
|
-
name: "Remove console statements",
|
|
30
|
-
description: "Remove console.log/debug/info (keep error/warn)",
|
|
31
|
-
fn: removeConsoles,
|
|
32
|
-
category: "cleanup",
|
|
33
|
-
safe: true, // Safe to auto-apply
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
id: "dead-code",
|
|
37
|
-
name: "Remove dead code",
|
|
38
|
-
description: "Remove unused imports and unreachable code",
|
|
39
|
-
fn: removeDeadCode,
|
|
40
|
-
category: "cleanup",
|
|
41
|
-
safe: true,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
id: "optimize-imports",
|
|
45
|
-
name: "Optimize imports",
|
|
46
|
-
description: "Sort, dedupe, and organize imports",
|
|
47
|
-
fn: optimizeImports,
|
|
48
|
-
category: "style",
|
|
49
|
-
safe: true,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
id: "strengthen-types",
|
|
53
|
-
name: "Strengthen types",
|
|
54
|
-
description: "Replace `any` with inferred types where possible",
|
|
55
|
-
fn: strengthenTypes,
|
|
56
|
-
category: "types",
|
|
57
|
-
safe: false, // Review recommended
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: "async-handlers",
|
|
61
|
-
name: "Wrap async handlers",
|
|
62
|
-
description: "Add try-catch to unhandled async functions",
|
|
63
|
-
fn: wrapAsyncHandlers,
|
|
64
|
-
category: "error-handling",
|
|
65
|
-
safe: false, // Review recommended
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
id: "accessibility",
|
|
69
|
-
name: "Fix accessibility",
|
|
70
|
-
description: "Add missing alt, aria-label, and role attributes",
|
|
71
|
-
fn: fixAccessibility,
|
|
72
|
-
category: "accessibility",
|
|
73
|
-
safe: false, // Review recommended - may add empty placeholders
|
|
74
|
-
},
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Get all available passes
|
|
79
|
-
*/
|
|
80
|
-
function getAvailablePasses() {
|
|
81
|
-
return POLISH_PASSES.map(({ id, name, description, category, safe }) => ({
|
|
82
|
-
id,
|
|
83
|
-
name,
|
|
84
|
-
description,
|
|
85
|
-
category,
|
|
86
|
-
safe,
|
|
87
|
-
}));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get passes by category
|
|
92
|
-
*/
|
|
93
|
-
function getPassesByCategory(category) {
|
|
94
|
-
return POLISH_PASSES.filter((p) => p.category === category);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Get safe passes only (can be auto-applied)
|
|
99
|
-
*/
|
|
100
|
-
function getSafePasses() {
|
|
101
|
-
return POLISH_PASSES.filter((p) => p.safe);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Run specified polish passes
|
|
106
|
-
*
|
|
107
|
-
* @param {string} targetPath - Directory to process
|
|
108
|
-
* @param {Object} options
|
|
109
|
-
* @param {boolean} options.dryRun - If true, don't modify files
|
|
110
|
-
* @param {string[]} options.passes - Pass IDs to run (default: all)
|
|
111
|
-
* @param {boolean} options.safeOnly - Only run safe passes
|
|
112
|
-
* @returns {Object} Results from all passes
|
|
113
|
-
*/
|
|
114
|
-
async function runPolishPasses(targetPath, options = {}) {
|
|
115
|
-
const {
|
|
116
|
-
dryRun = true,
|
|
117
|
-
passes = null,
|
|
118
|
-
safeOnly = false,
|
|
119
|
-
verbose = false,
|
|
120
|
-
} = options;
|
|
121
|
-
|
|
122
|
-
// Determine which passes to run
|
|
123
|
-
let passesToRun = POLISH_PASSES;
|
|
124
|
-
|
|
125
|
-
if (safeOnly) {
|
|
126
|
-
passesToRun = passesToRun.filter((p) => p.safe);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (passes && passes.length > 0) {
|
|
130
|
-
passesToRun = passesToRun.filter((p) => passes.includes(p.id));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const results = {
|
|
134
|
-
passes: [],
|
|
135
|
-
totalChanges: 0,
|
|
136
|
-
totalFilesModified: new Set(),
|
|
137
|
-
errors: [],
|
|
138
|
-
dryRun,
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
for (const pass of passesToRun) {
|
|
142
|
-
const startTime = Date.now();
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const passResult = await pass.fn(targetPath, { dryRun });
|
|
146
|
-
|
|
147
|
-
results.passes.push({
|
|
148
|
-
id: pass.id,
|
|
149
|
-
name: pass.name,
|
|
150
|
-
changes: passResult.changes.length,
|
|
151
|
-
files: passResult.files,
|
|
152
|
-
errors: passResult.errors || [],
|
|
153
|
-
duration: Date.now() - startTime,
|
|
154
|
-
summary: passResult.summary,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
results.totalChanges += passResult.changes.length;
|
|
158
|
-
passResult.files.forEach((f) => results.totalFilesModified.add(f));
|
|
159
|
-
|
|
160
|
-
if (passResult.errors?.length > 0) {
|
|
161
|
-
results.errors.push(...passResult.errors.map((e) => ({ pass: pass.id, ...e })));
|
|
162
|
-
}
|
|
163
|
-
} catch (err) {
|
|
164
|
-
results.passes.push({
|
|
165
|
-
id: pass.id,
|
|
166
|
-
name: pass.name,
|
|
167
|
-
changes: 0,
|
|
168
|
-
files: [],
|
|
169
|
-
errors: [{ error: err.message }],
|
|
170
|
-
duration: Date.now() - startTime,
|
|
171
|
-
failed: true,
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
results.errors.push({
|
|
175
|
-
pass: pass.id,
|
|
176
|
-
error: err.message,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Convert Set to Array
|
|
182
|
-
results.totalFilesModified = Array.from(results.totalFilesModified);
|
|
183
|
-
|
|
184
|
-
return results;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
module.exports = {
|
|
188
|
-
POLISH_PASSES,
|
|
189
|
-
runPolishPasses,
|
|
190
|
-
getAvailablePasses,
|
|
191
|
-
getPassesByCategory,
|
|
192
|
-
getSafePasses,
|
|
193
|
-
// Individual passes
|
|
194
|
-
removeConsoles,
|
|
195
|
-
strengthenTypes,
|
|
196
|
-
wrapAsyncHandlers,
|
|
197
|
-
removeDeadCode,
|
|
198
|
-
fixAccessibility,
|
|
199
|
-
optimizeImports,
|
|
200
|
-
};
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove Console Statements - Auto-fix Polish Pass
|
|
3
|
-
*
|
|
4
|
-
* Removes console.log, console.debug, console.info, console.trace
|
|
5
|
-
* Preserves console.error, console.warn (these are intentional)
|
|
6
|
-
*
|
|
7
|
-
* Uses Babel AST transformation for safe, accurate modifications.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
"use strict";
|
|
11
|
-
|
|
12
|
-
const { parse } = require("@babel/parser");
|
|
13
|
-
const traverse = require("@babel/traverse").default || require("@babel/traverse");
|
|
14
|
-
const generate = require("@babel/generator").default || require("@babel/generator");
|
|
15
|
-
const fs = require("fs");
|
|
16
|
-
const path = require("path");
|
|
17
|
-
const { findAllFilesSync, readFileSafeSync } = require("../utils");
|
|
18
|
-
|
|
19
|
-
// Console methods to REMOVE (development/debug)
|
|
20
|
-
const REMOVE_METHODS = new Set([
|
|
21
|
-
"log",
|
|
22
|
-
"debug",
|
|
23
|
-
"info",
|
|
24
|
-
"trace",
|
|
25
|
-
"dir",
|
|
26
|
-
"dirxml",
|
|
27
|
-
"table",
|
|
28
|
-
"count",
|
|
29
|
-
"countReset",
|
|
30
|
-
"group",
|
|
31
|
-
"groupCollapsed",
|
|
32
|
-
"groupEnd",
|
|
33
|
-
"time",
|
|
34
|
-
"timeEnd",
|
|
35
|
-
"timeLog",
|
|
36
|
-
"timeStamp",
|
|
37
|
-
"profile",
|
|
38
|
-
"profileEnd",
|
|
39
|
-
"clear",
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
// Console methods to KEEP (production-appropriate)
|
|
43
|
-
const KEEP_METHODS = new Set(["error", "warn", "assert"]);
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Parse JavaScript/TypeScript code into AST
|
|
47
|
-
*/
|
|
48
|
-
function parseCode(code, filePath) {
|
|
49
|
-
const isTypeScript = filePath.endsWith(".ts") || filePath.endsWith(".tsx");
|
|
50
|
-
const isJSX = filePath.endsWith(".jsx") || filePath.endsWith(".tsx");
|
|
51
|
-
|
|
52
|
-
const plugins = ["decorators-legacy", "classProperties", "classPrivateProperties", "classPrivateMethods"];
|
|
53
|
-
|
|
54
|
-
if (isTypeScript) {
|
|
55
|
-
plugins.push("typescript");
|
|
56
|
-
}
|
|
57
|
-
if (isJSX || isTypeScript) {
|
|
58
|
-
plugins.push("jsx");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return parse(code, {
|
|
62
|
-
sourceType: "module",
|
|
63
|
-
plugins,
|
|
64
|
-
errorRecovery: true, // Continue parsing even with errors
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Remove console statements from a single file
|
|
70
|
-
* @param {string} filePath - Path to file
|
|
71
|
-
* @param {Object} options - { dryRun: boolean }
|
|
72
|
-
* @returns {Object} - { changes: Array, modified: boolean }
|
|
73
|
-
*/
|
|
74
|
-
function processFile(filePath, options = {}) {
|
|
75
|
-
const { dryRun = true } = options;
|
|
76
|
-
const changes = [];
|
|
77
|
-
|
|
78
|
-
const code = readFileSafeSync(filePath);
|
|
79
|
-
if (!code) return { changes: [], modified: false };
|
|
80
|
-
|
|
81
|
-
// Skip if file doesn't contain console
|
|
82
|
-
if (!code.includes("console.")) {
|
|
83
|
-
return { changes: [], modified: false };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let ast;
|
|
87
|
-
try {
|
|
88
|
-
ast = parseCode(code, filePath);
|
|
89
|
-
} catch (err) {
|
|
90
|
-
// Can't parse, skip file
|
|
91
|
-
return { changes: [], modified: false, error: `Parse error: ${err.message}` };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let modified = false;
|
|
95
|
-
const relativePath = path.relative(process.cwd(), filePath);
|
|
96
|
-
|
|
97
|
-
traverse(ast, {
|
|
98
|
-
CallExpression(nodePath) {
|
|
99
|
-
const { node } = nodePath;
|
|
100
|
-
|
|
101
|
-
// Check for console.method() pattern
|
|
102
|
-
if (
|
|
103
|
-
node.callee.type === "MemberExpression" &&
|
|
104
|
-
node.callee.object.type === "Identifier" &&
|
|
105
|
-
node.callee.object.name === "console" &&
|
|
106
|
-
node.callee.property.type === "Identifier"
|
|
107
|
-
) {
|
|
108
|
-
const method = node.callee.property.name;
|
|
109
|
-
|
|
110
|
-
// Should we remove this method?
|
|
111
|
-
if (REMOVE_METHODS.has(method)) {
|
|
112
|
-
const line = node.loc?.start?.line || "?";
|
|
113
|
-
const column = node.loc?.start?.column || "?";
|
|
114
|
-
|
|
115
|
-
changes.push({
|
|
116
|
-
file: relativePath,
|
|
117
|
-
line,
|
|
118
|
-
column,
|
|
119
|
-
type: "remove-console",
|
|
120
|
-
detail: `console.${method}`,
|
|
121
|
-
code: code.substring(node.start, Math.min(node.end, node.start + 60)),
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// Remove the entire expression statement
|
|
125
|
-
if (nodePath.parentPath.type === "ExpressionStatement") {
|
|
126
|
-
nodePath.parentPath.remove();
|
|
127
|
-
} else {
|
|
128
|
-
// If it's used as a value (rare), replace with undefined
|
|
129
|
-
nodePath.replaceWith({ type: "Identifier", name: "undefined" });
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
modified = true;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Write changes if not dry run and file was modified
|
|
139
|
-
if (modified && !dryRun) {
|
|
140
|
-
try {
|
|
141
|
-
const output = generate(
|
|
142
|
-
ast,
|
|
143
|
-
{
|
|
144
|
-
retainLines: true,
|
|
145
|
-
compact: false,
|
|
146
|
-
concise: false,
|
|
147
|
-
},
|
|
148
|
-
code
|
|
149
|
-
);
|
|
150
|
-
fs.writeFileSync(filePath, output.code, "utf8");
|
|
151
|
-
} catch (err) {
|
|
152
|
-
return { changes, modified: false, error: `Generate error: ${err.message}` };
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return { changes, modified };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Remove console statements from all files in a directory
|
|
161
|
-
* @param {string} targetPath - Directory to process
|
|
162
|
-
* @param {Object} options - { dryRun: boolean }
|
|
163
|
-
* @returns {Object} - { changes: Array, files: Array }
|
|
164
|
-
*/
|
|
165
|
-
async function removeConsoles(targetPath, options = {}) {
|
|
166
|
-
const { dryRun = true } = options;
|
|
167
|
-
|
|
168
|
-
// Find all JavaScript/TypeScript files
|
|
169
|
-
const pattern = /\.(js|jsx|ts|tsx|mjs|cjs)$/;
|
|
170
|
-
const files = findAllFilesSync(targetPath, pattern);
|
|
171
|
-
|
|
172
|
-
const allChanges = [];
|
|
173
|
-
const modifiedFiles = [];
|
|
174
|
-
const errors = [];
|
|
175
|
-
|
|
176
|
-
for (const file of files) {
|
|
177
|
-
const result = processFile(file, { dryRun });
|
|
178
|
-
|
|
179
|
-
if (result.error) {
|
|
180
|
-
errors.push({ file, error: result.error });
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (result.changes.length > 0) {
|
|
184
|
-
allChanges.push(...result.changes);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (result.modified) {
|
|
188
|
-
modifiedFiles.push(path.relative(process.cwd(), file));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
changes: allChanges,
|
|
194
|
-
files: modifiedFiles,
|
|
195
|
-
errors,
|
|
196
|
-
summary: {
|
|
197
|
-
filesScanned: files.length,
|
|
198
|
-
filesModified: modifiedFiles.length,
|
|
199
|
-
statementsRemoved: allChanges.length,
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
module.exports = {
|
|
205
|
-
removeConsoles,
|
|
206
|
-
processFile,
|
|
207
|
-
REMOVE_METHODS,
|
|
208
|
-
KEEP_METHODS,
|
|
209
|
-
};
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Strengthen Types - Auto-fix Polish Pass
|
|
3
|
-
*
|
|
4
|
-
* Replaces `any` types with more specific types where inferrable:
|
|
5
|
-
* - Function parameters with usage patterns
|
|
6
|
-
* - Return types from return statements
|
|
7
|
-
* - Variable declarations with assignments
|
|
8
|
-
*
|
|
9
|
-
* Uses Babel AST transformation with TypeScript plugin.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
const { parse } = require("@babel/parser");
|
|
15
|
-
const traverse = require("@babel/traverse").default || require("@babel/traverse");
|
|
16
|
-
const generate = require("@babel/generator").default || require("@babel/generator");
|
|
17
|
-
const t = require("@babel/types");
|
|
18
|
-
const fs = require("fs");
|
|
19
|
-
const path = require("path");
|
|
20
|
-
const { findAllFilesSync, readFileSafeSync } = require("../utils");
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Infer type from a value expression
|
|
24
|
-
*/
|
|
25
|
-
function inferTypeFromValue(node) {
|
|
26
|
-
if (!node) return null;
|
|
27
|
-
|
|
28
|
-
switch (node.type) {
|
|
29
|
-
case "StringLiteral":
|
|
30
|
-
case "TemplateLiteral":
|
|
31
|
-
return t.tsStringKeyword();
|
|
32
|
-
|
|
33
|
-
case "NumericLiteral":
|
|
34
|
-
return t.tsNumberKeyword();
|
|
35
|
-
|
|
36
|
-
case "BooleanLiteral":
|
|
37
|
-
return t.tsBooleanKeyword();
|
|
38
|
-
|
|
39
|
-
case "NullLiteral":
|
|
40
|
-
return t.tsNullKeyword();
|
|
41
|
-
|
|
42
|
-
case "ArrayExpression":
|
|
43
|
-
if (node.elements.length > 0) {
|
|
44
|
-
const elementType = inferTypeFromValue(node.elements[0]);
|
|
45
|
-
if (elementType) {
|
|
46
|
-
return t.tsArrayType(elementType);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return t.tsArrayType(t.tsUnknownKeyword());
|
|
50
|
-
|
|
51
|
-
case "ObjectExpression":
|
|
52
|
-
return t.tsTypeLiteral([]);
|
|
53
|
-
|
|
54
|
-
case "ArrowFunctionExpression":
|
|
55
|
-
case "FunctionExpression":
|
|
56
|
-
return t.tsFunctionType(null, [], t.tsVoidKeyword());
|
|
57
|
-
|
|
58
|
-
case "CallExpression":
|
|
59
|
-
// Common patterns
|
|
60
|
-
if (node.callee.type === "Identifier") {
|
|
61
|
-
if (node.callee.name === "Promise") {
|
|
62
|
-
return t.tsTypeReference(t.identifier("Promise"), t.tsTypeParameterInstantiation([t.tsUnknownKeyword()]));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
|
|
67
|
-
case "NewExpression":
|
|
68
|
-
if (node.callee.type === "Identifier") {
|
|
69
|
-
const typeName = node.callee.name;
|
|
70
|
-
if (["Date", "Map", "Set", "WeakMap", "WeakSet", "RegExp", "Error"].includes(typeName)) {
|
|
71
|
-
return t.tsTypeReference(t.identifier(typeName));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return null;
|
|
75
|
-
|
|
76
|
-
default:
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Parse TypeScript code into AST
|
|
83
|
-
*/
|
|
84
|
-
function parseCode(code, filePath) {
|
|
85
|
-
return parse(code, {
|
|
86
|
-
sourceType: "module",
|
|
87
|
-
plugins: ["typescript", "jsx", "decorators-legacy", "classProperties"],
|
|
88
|
-
errorRecovery: true,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Process a single TypeScript file
|
|
94
|
-
*/
|
|
95
|
-
function processFile(filePath, options = {}) {
|
|
96
|
-
const { dryRun = true } = options;
|
|
97
|
-
const changes = [];
|
|
98
|
-
|
|
99
|
-
// Only process TypeScript files
|
|
100
|
-
if (!filePath.endsWith(".ts") && !filePath.endsWith(".tsx")) {
|
|
101
|
-
return { changes: [], modified: false };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const code = readFileSafeSync(filePath);
|
|
105
|
-
if (!code) return { changes: [], modified: false };
|
|
106
|
-
|
|
107
|
-
// Quick check - does file contain 'any'
|
|
108
|
-
if (!code.includes(": any") && !code.includes(":any")) {
|
|
109
|
-
return { changes: [], modified: false };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let ast;
|
|
113
|
-
try {
|
|
114
|
-
ast = parseCode(code, filePath);
|
|
115
|
-
} catch (err) {
|
|
116
|
-
return { changes: [], modified: false, error: `Parse error: ${err.message}` };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
let modified = false;
|
|
120
|
-
const relativePath = path.relative(process.cwd(), filePath);
|
|
121
|
-
|
|
122
|
-
traverse(ast, {
|
|
123
|
-
// Variable declarations: const x: any = "value" -> const x: string = "value"
|
|
124
|
-
VariableDeclarator(nodePath) {
|
|
125
|
-
const { node } = nodePath;
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
node.id.type === "Identifier" &&
|
|
129
|
-
node.id.typeAnnotation?.typeAnnotation?.type === "TSAnyKeyword" &&
|
|
130
|
-
node.init
|
|
131
|
-
) {
|
|
132
|
-
const inferredType = inferTypeFromValue(node.init);
|
|
133
|
-
if (inferredType) {
|
|
134
|
-
const line = node.loc?.start?.line || "?";
|
|
135
|
-
changes.push({
|
|
136
|
-
file: relativePath,
|
|
137
|
-
line,
|
|
138
|
-
type: "strengthen-type",
|
|
139
|
-
detail: `${node.id.name}: any -> inferred type`,
|
|
140
|
-
from: "any",
|
|
141
|
-
to: generate(inferredType).code,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
node.id.typeAnnotation.typeAnnotation = inferredType;
|
|
145
|
-
modified = true;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
// Function parameters: Replace (x: any) with (x: unknown) as safer default
|
|
151
|
-
TSAnyKeyword(nodePath) {
|
|
152
|
-
const parent = nodePath.parent;
|
|
153
|
-
const grandParent = nodePath.parentPath?.parent;
|
|
154
|
-
|
|
155
|
-
// Skip if it's in a type assertion or generic
|
|
156
|
-
if (parent.type === "TSTypeAssertion" || parent.type === "TSAsExpression") {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// For parameters without clear inference, use `unknown` (safer than `any`)
|
|
161
|
-
if (
|
|
162
|
-
parent.type === "TSTypeAnnotation" &&
|
|
163
|
-
grandParent?.type === "Identifier" &&
|
|
164
|
-
nodePath.parentPath?.parentPath?.parent?.type === "FunctionDeclaration"
|
|
165
|
-
) {
|
|
166
|
-
const line = nodePath.node.loc?.start?.line || "?";
|
|
167
|
-
|
|
168
|
-
// Only replace if it's a standalone `any` parameter
|
|
169
|
-
changes.push({
|
|
170
|
-
file: relativePath,
|
|
171
|
-
line,
|
|
172
|
-
type: "strengthen-type",
|
|
173
|
-
detail: `Parameter type: any -> unknown`,
|
|
174
|
-
suggestion: "Consider using a more specific type",
|
|
175
|
-
from: "any",
|
|
176
|
-
to: "unknown",
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
// Replace any with unknown (safer)
|
|
180
|
-
nodePath.replaceWith(t.tsUnknownKeyword());
|
|
181
|
-
modified = true;
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// Write changes if not dry run
|
|
187
|
-
if (modified && !dryRun) {
|
|
188
|
-
try {
|
|
189
|
-
const output = generate(ast, { retainLines: true }, code);
|
|
190
|
-
fs.writeFileSync(filePath, output.code, "utf8");
|
|
191
|
-
} catch (err) {
|
|
192
|
-
return { changes, modified: false, error: `Generate error: ${err.message}` };
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return { changes, modified };
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Strengthen types in all TypeScript files
|
|
201
|
-
*/
|
|
202
|
-
async function strengthenTypes(targetPath, options = {}) {
|
|
203
|
-
const { dryRun = true } = options;
|
|
204
|
-
|
|
205
|
-
// Only TypeScript files
|
|
206
|
-
const pattern = /\.(ts|tsx)$/;
|
|
207
|
-
const files = findAllFilesSync(targetPath, pattern);
|
|
208
|
-
|
|
209
|
-
const allChanges = [];
|
|
210
|
-
const modifiedFiles = [];
|
|
211
|
-
const errors = [];
|
|
212
|
-
|
|
213
|
-
for (const file of files) {
|
|
214
|
-
const result = processFile(file, { dryRun });
|
|
215
|
-
|
|
216
|
-
if (result.error) {
|
|
217
|
-
errors.push({ file, error: result.error });
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (result.changes.length > 0) {
|
|
221
|
-
allChanges.push(...result.changes);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (result.modified) {
|
|
225
|
-
modifiedFiles.push(path.relative(process.cwd(), file));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
changes: allChanges,
|
|
231
|
-
files: modifiedFiles,
|
|
232
|
-
errors,
|
|
233
|
-
summary: {
|
|
234
|
-
filesScanned: files.length,
|
|
235
|
-
filesModified: modifiedFiles.length,
|
|
236
|
-
typesStrengthened: allChanges.length,
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
module.exports = {
|
|
242
|
-
strengthenTypes,
|
|
243
|
-
processFile,
|
|
244
|
-
inferTypeFromValue,
|
|
245
|
-
};
|