@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,420 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Quality Authority - Automated code quality review
|
|
3
|
-
*
|
|
4
|
-
* Checks for:
|
|
5
|
-
* - Code complexity (cyclomatic complexity)
|
|
6
|
-
* - Code smells
|
|
7
|
-
* - Best practices
|
|
8
|
-
* - Documentation coverage
|
|
9
|
-
* - Test coverage indicators
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
const crypto = require("crypto");
|
|
15
|
-
|
|
16
|
-
class QualityAuthority {
|
|
17
|
-
static description = "Code quality review";
|
|
18
|
-
static automated = true;
|
|
19
|
-
static tier = "pro";
|
|
20
|
-
|
|
21
|
-
constructor(options = {}) {
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.thresholds = {
|
|
24
|
-
maxFunctionLength: options.maxFunctionLength || 50,
|
|
25
|
-
maxFileLength: options.maxFileLength || 500,
|
|
26
|
-
maxComplexity: options.maxComplexity || 10,
|
|
27
|
-
maxNestedDepth: options.maxNestedDepth || 4,
|
|
28
|
-
...options.thresholds,
|
|
29
|
-
};
|
|
30
|
-
this.rules = this._initializeRules();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
_initializeRules() {
|
|
34
|
-
return {
|
|
35
|
-
codeSmells: [
|
|
36
|
-
{
|
|
37
|
-
name: "console-log",
|
|
38
|
-
pattern: /console\.(log|debug|info)\s*\(/,
|
|
39
|
-
message: "Console statements should be removed in production code",
|
|
40
|
-
severity: "low",
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "todo-fixme",
|
|
44
|
-
pattern: /\/\/\s*(TODO|FIXME|HACK|XXX|BUG):/i,
|
|
45
|
-
message: "Unresolved TODO/FIXME comment found",
|
|
46
|
-
severity: "low",
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "magic-number",
|
|
50
|
-
pattern: /[^a-zA-Z0-9_](?<!0[xX])\d{4,}[^a-zA-Z0-9_]/,
|
|
51
|
-
message: "Magic number detected - consider using named constants",
|
|
52
|
-
severity: "low",
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "empty-catch",
|
|
56
|
-
pattern: /catch\s*\([^)]*\)\s*{\s*}/,
|
|
57
|
-
message: "Empty catch block - errors should be handled or logged",
|
|
58
|
-
severity: "medium",
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
name: "any-type",
|
|
62
|
-
pattern: /:\s*any\b|as\s+any\b/,
|
|
63
|
-
message: "TypeScript 'any' type reduces type safety",
|
|
64
|
-
severity: "low",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "duplicate-string",
|
|
68
|
-
pattern: /(['"])[^'"]{20,}\1.*\1[^'"]{20,}\1/,
|
|
69
|
-
message: "Duplicate long string - consider extracting to constant",
|
|
70
|
-
severity: "low",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "hardcoded-timeout",
|
|
74
|
-
pattern: /setTimeout\s*\([^,]+,\s*\d{4,}\)/,
|
|
75
|
-
message: "Hardcoded timeout value - consider using named constant",
|
|
76
|
-
severity: "low",
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
complexity: [
|
|
80
|
-
{
|
|
81
|
-
name: "nested-callbacks",
|
|
82
|
-
pattern: /\)\s*=>\s*{[\s\S]*?\)\s*=>\s*{[\s\S]*?\)\s*=>\s*{/,
|
|
83
|
-
message: "Deeply nested callbacks detected - consider async/await or extracting functions",
|
|
84
|
-
severity: "medium",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "nested-ternary",
|
|
88
|
-
pattern: /\?[^:]+\?[^:]+:/,
|
|
89
|
-
message: "Nested ternary operators reduce readability",
|
|
90
|
-
severity: "low",
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "long-parameter-list",
|
|
94
|
-
pattern: /\([^)]*,\s*[^)]*,\s*[^)]*,\s*[^)]*,\s*[^)]*,/,
|
|
95
|
-
message: "Function has many parameters - consider using an options object",
|
|
96
|
-
severity: "low",
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
bestPractices: [
|
|
100
|
-
{
|
|
101
|
-
name: "var-usage",
|
|
102
|
-
pattern: /\bvar\s+\w+/,
|
|
103
|
-
message: "Use 'const' or 'let' instead of 'var'",
|
|
104
|
-
severity: "low",
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
name: "double-equals",
|
|
108
|
-
pattern: /[^!=]==[^=]/,
|
|
109
|
-
message: "Use strict equality (===) instead of loose equality (==)",
|
|
110
|
-
severity: "low",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: "async-no-await",
|
|
114
|
-
pattern: /async\s+(?:function\s+\w+|\([^)]*\)\s*=>|\w+\s*=>)\s*{[^}]*(?!await)[^}]*}/,
|
|
115
|
-
message: "Async function without await - consider removing async keyword",
|
|
116
|
-
severity: "low",
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: "promise-executor-async",
|
|
120
|
-
pattern: /new\s+Promise\s*\(\s*async/,
|
|
121
|
-
message: "Promise executor should not be async",
|
|
122
|
-
severity: "medium",
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: "floating-promise",
|
|
126
|
-
pattern: /^\s*\w+\.(then|catch)\s*\(/m,
|
|
127
|
-
message: "Floating promise - ensure proper error handling with await or .catch()",
|
|
128
|
-
severity: "medium",
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
documentation: [
|
|
132
|
-
{
|
|
133
|
-
name: "missing-jsdoc-export",
|
|
134
|
-
pattern: /^export\s+(async\s+)?function\s+\w+\s*\([^)]*\)/m,
|
|
135
|
-
inverse: true,
|
|
136
|
-
context: /\/\*\*[\s\S]*?\*\/\s*export/,
|
|
137
|
-
message: "Exported function missing JSDoc documentation",
|
|
138
|
-
severity: "low",
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
testing: [
|
|
142
|
-
{
|
|
143
|
-
name: "skip-test",
|
|
144
|
-
pattern: /\.(skip|only)\s*\(/,
|
|
145
|
-
context: /\.(test|spec)\.(ts|tsx|js|jsx)$/,
|
|
146
|
-
message: "Test skip/only found - should not be committed",
|
|
147
|
-
severity: "high",
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
name: "empty-test",
|
|
151
|
-
pattern: /it\s*\([^)]+,\s*\(\s*\)\s*=>\s*{\s*}\s*\)/,
|
|
152
|
-
context: /\.(test|spec)\.(ts|tsx|js|jsx)$/,
|
|
153
|
-
message: "Empty test case detected",
|
|
154
|
-
severity: "medium",
|
|
155
|
-
},
|
|
156
|
-
],
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async review(payload) {
|
|
161
|
-
const { files = [], diff = "", context = {} } = payload;
|
|
162
|
-
const findings = [];
|
|
163
|
-
const startTime = Date.now();
|
|
164
|
-
const metrics = {
|
|
165
|
-
totalLines: 0,
|
|
166
|
-
filesOverLength: 0,
|
|
167
|
-
functionsOverLength: 0,
|
|
168
|
-
complexFunctions: 0,
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// Analyze diff content
|
|
172
|
-
if (diff) {
|
|
173
|
-
findings.push(...this._analyzeDiff(diff));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Analyze files
|
|
177
|
-
for (const file of files) {
|
|
178
|
-
if (file.content) {
|
|
179
|
-
const fileFindings = this._analyzeFile(file.path || "unknown", file.content);
|
|
180
|
-
findings.push(...fileFindings);
|
|
181
|
-
|
|
182
|
-
// Collect metrics
|
|
183
|
-
const lines = file.content.split("\n").length;
|
|
184
|
-
metrics.totalLines += lines;
|
|
185
|
-
|
|
186
|
-
if (lines > this.thresholds.maxFileLength) {
|
|
187
|
-
metrics.filesOverLength++;
|
|
188
|
-
findings.push({
|
|
189
|
-
type: "quality-metric",
|
|
190
|
-
rule: "file-length",
|
|
191
|
-
severity: "medium",
|
|
192
|
-
message: `File exceeds ${this.thresholds.maxFileLength} lines (${lines} lines)`,
|
|
193
|
-
file: file.path,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Analyze function lengths
|
|
198
|
-
const functionLengthFindings = this._checkFunctionLengths(file.path, file.content);
|
|
199
|
-
findings.push(...functionLengthFindings);
|
|
200
|
-
metrics.functionsOverLength += functionLengthFindings.length;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Calculate quality score
|
|
205
|
-
const qualityScore = this._calculateQualityScore(findings, metrics);
|
|
206
|
-
|
|
207
|
-
// Determine approval status
|
|
208
|
-
const hasHigh = findings.some(f => f.severity === "high");
|
|
209
|
-
const hasMedium = findings.some(f => f.severity === "medium");
|
|
210
|
-
const lowCount = findings.filter(f => f.severity === "low").length;
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
approved: !hasHigh && !(hasMedium && lowCount > 10),
|
|
214
|
-
reason: hasHigh
|
|
215
|
-
? "Quality issues require attention before approval"
|
|
216
|
-
: hasMedium
|
|
217
|
-
? "Approved with quality warnings"
|
|
218
|
-
: findings.length > 0
|
|
219
|
-
? "Approved with minor quality suggestions"
|
|
220
|
-
: "Code quality looks excellent",
|
|
221
|
-
findings,
|
|
222
|
-
qualityScore,
|
|
223
|
-
metrics,
|
|
224
|
-
signature: this._sign(findings),
|
|
225
|
-
metadata: {
|
|
226
|
-
analysisTimeMs: Date.now() - startTime,
|
|
227
|
-
filesAnalyzed: files.length,
|
|
228
|
-
totalLines: metrics.totalLines,
|
|
229
|
-
rulesChecked: this._countRules(),
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
_analyzeDiff(diff) {
|
|
235
|
-
const findings = [];
|
|
236
|
-
const lines = diff.split("\n");
|
|
237
|
-
let currentFile = "unknown";
|
|
238
|
-
let lineNumber = 0;
|
|
239
|
-
|
|
240
|
-
for (const line of lines) {
|
|
241
|
-
if (line.startsWith("+++") || line.startsWith("---")) {
|
|
242
|
-
const match = line.match(/[ab]\/(.+)/);
|
|
243
|
-
if (match) currentFile = match[1];
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (line.startsWith("@@")) {
|
|
248
|
-
const match = line.match(/@@ -\d+(?:,\d+)? \+(\d+)/);
|
|
249
|
-
if (match) lineNumber = parseInt(match[1], 10);
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
254
|
-
const addedContent = line.slice(1);
|
|
255
|
-
|
|
256
|
-
for (const category of ["codeSmells", "complexity", "bestPractices", "testing"]) {
|
|
257
|
-
for (const rule of this.rules[category]) {
|
|
258
|
-
if (this._matchesRule(addedContent, currentFile, rule)) {
|
|
259
|
-
findings.push({
|
|
260
|
-
type: "quality-issue",
|
|
261
|
-
category,
|
|
262
|
-
rule: rule.name,
|
|
263
|
-
severity: rule.severity,
|
|
264
|
-
message: rule.message,
|
|
265
|
-
file: currentFile,
|
|
266
|
-
line: lineNumber,
|
|
267
|
-
evidence: addedContent.trim().slice(0, 80),
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
lineNumber++;
|
|
274
|
-
} else if (!line.startsWith("-")) {
|
|
275
|
-
lineNumber++;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return findings;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
_analyzeFile(filePath, content) {
|
|
283
|
-
const findings = [];
|
|
284
|
-
const lines = content.split("\n");
|
|
285
|
-
|
|
286
|
-
for (let i = 0; i < lines.length; i++) {
|
|
287
|
-
const line = lines[i];
|
|
288
|
-
|
|
289
|
-
for (const category of ["codeSmells", "complexity", "bestPractices", "testing"]) {
|
|
290
|
-
for (const rule of this.rules[category]) {
|
|
291
|
-
if (this._matchesRule(line, filePath, rule)) {
|
|
292
|
-
findings.push({
|
|
293
|
-
type: "quality-issue",
|
|
294
|
-
category,
|
|
295
|
-
rule: rule.name,
|
|
296
|
-
severity: rule.severity,
|
|
297
|
-
message: rule.message,
|
|
298
|
-
file: filePath,
|
|
299
|
-
line: i + 1,
|
|
300
|
-
evidence: line.trim().slice(0, 80),
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return findings;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
_matchesRule(content, filePath, rule) {
|
|
311
|
-
if (rule.context) {
|
|
312
|
-
if (rule.context instanceof RegExp) {
|
|
313
|
-
if (!rule.context.test(content) && !rule.context.test(filePath)) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const matches = rule.pattern.test(content);
|
|
320
|
-
|
|
321
|
-
if (rule.inverse) {
|
|
322
|
-
return !matches;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return matches;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
_checkFunctionLengths(filePath, content) {
|
|
329
|
-
const findings = [];
|
|
330
|
-
const functionPattern = /(?:function\s+\w+|(?:const|let|var)\s+\w+\s*=\s*(?:async\s+)?(?:function|\([^)]*\)\s*=>))/g;
|
|
331
|
-
const lines = content.split("\n");
|
|
332
|
-
|
|
333
|
-
let match;
|
|
334
|
-
while ((match = functionPattern.exec(content)) !== null) {
|
|
335
|
-
const startIndex = match.index;
|
|
336
|
-
const startLine = content.slice(0, startIndex).split("\n").length;
|
|
337
|
-
|
|
338
|
-
// Find the matching closing brace
|
|
339
|
-
let braceCount = 0;
|
|
340
|
-
let foundOpen = false;
|
|
341
|
-
let endLine = startLine;
|
|
342
|
-
|
|
343
|
-
for (let i = startLine - 1; i < lines.length; i++) {
|
|
344
|
-
const line = lines[i];
|
|
345
|
-
for (const char of line) {
|
|
346
|
-
if (char === "{") {
|
|
347
|
-
braceCount++;
|
|
348
|
-
foundOpen = true;
|
|
349
|
-
} else if (char === "}") {
|
|
350
|
-
braceCount--;
|
|
351
|
-
if (foundOpen && braceCount === 0) {
|
|
352
|
-
endLine = i + 1;
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
if (foundOpen && braceCount === 0) break;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
const functionLength = endLine - startLine;
|
|
361
|
-
if (functionLength > this.thresholds.maxFunctionLength) {
|
|
362
|
-
findings.push({
|
|
363
|
-
type: "quality-metric",
|
|
364
|
-
rule: "function-length",
|
|
365
|
-
severity: "medium",
|
|
366
|
-
message: `Function exceeds ${this.thresholds.maxFunctionLength} lines (${functionLength} lines)`,
|
|
367
|
-
file: filePath,
|
|
368
|
-
line: startLine,
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
return findings;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
_calculateQualityScore(findings, metrics) {
|
|
377
|
-
let score = 100;
|
|
378
|
-
|
|
379
|
-
// Deduct points for findings
|
|
380
|
-
for (const finding of findings) {
|
|
381
|
-
switch (finding.severity) {
|
|
382
|
-
case "critical":
|
|
383
|
-
score -= 20;
|
|
384
|
-
break;
|
|
385
|
-
case "high":
|
|
386
|
-
score -= 10;
|
|
387
|
-
break;
|
|
388
|
-
case "medium":
|
|
389
|
-
score -= 5;
|
|
390
|
-
break;
|
|
391
|
-
case "low":
|
|
392
|
-
score -= 1;
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// Bonus for small, focused files
|
|
398
|
-
if (metrics.filesOverLength === 0 && metrics.totalLines > 0) {
|
|
399
|
-
score = Math.min(100, score + 5);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return Math.max(0, Math.min(100, Math.round(score)));
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
_countRules() {
|
|
406
|
-
return Object.values(this.rules).reduce((sum, arr) => sum + arr.length, 0);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
_sign(findings) {
|
|
410
|
-
const timestamp = Date.now();
|
|
411
|
-
const hash = crypto
|
|
412
|
-
.createHash("sha256")
|
|
413
|
-
.update(JSON.stringify({ findings: findings.length, timestamp }))
|
|
414
|
-
.digest("hex")
|
|
415
|
-
.slice(0, 16);
|
|
416
|
-
return `qual_${timestamp}_${hash}_${findings.length}`;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
module.exports = { QualityAuthority };
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security Authority - Automated security review
|
|
3
|
-
*
|
|
4
|
-
* Checks for:
|
|
5
|
-
* - Hardcoded secrets in code/diffs
|
|
6
|
-
* - Dangerous patterns (eval, innerHTML, etc.)
|
|
7
|
-
* - SQL injection vulnerabilities
|
|
8
|
-
* - Command injection vulnerabilities
|
|
9
|
-
* - Path traversal risks
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
const crypto = require("crypto");
|
|
15
|
-
|
|
16
|
-
class SecurityAuthority {
|
|
17
|
-
static description = "Automated security review";
|
|
18
|
-
static automated = true;
|
|
19
|
-
static tier = "pro";
|
|
20
|
-
|
|
21
|
-
constructor(options = {}) {
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.patterns = this._initializePatterns();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_initializePatterns() {
|
|
27
|
-
return {
|
|
28
|
-
secrets: [
|
|
29
|
-
{ pattern: /password\s*[=:]\s*['"][^'"]{4,}['"]/gi, message: "Potential password detected" },
|
|
30
|
-
{ pattern: /api[_-]?key\s*[=:]\s*['"][^'"]{8,}['"]/gi, message: "Potential API key detected" },
|
|
31
|
-
{ pattern: /secret\s*[=:]\s*['"][^'"]{8,}['"]/gi, message: "Potential secret detected" },
|
|
32
|
-
{ pattern: /token\s*[=:]\s*['"][^'"]{8,}['"]/gi, message: "Potential token detected" },
|
|
33
|
-
{ pattern: /private[_-]?key\s*[=:]\s*['"][^'"]+['"]/gi, message: "Potential private key detected" },
|
|
34
|
-
{ pattern: /-----BEGIN\s+(RSA\s+)?PRIVATE\s+KEY-----/gi, message: "Private key detected" },
|
|
35
|
-
{ pattern: /aws[_-]?(access[_-]?key|secret)[_-]?(id|key)?\s*[=:]\s*['"][^'"]+['"]/gi, message: "AWS credential detected" },
|
|
36
|
-
{ pattern: /ghp_[a-zA-Z0-9]{36}/g, message: "GitHub personal access token detected" },
|
|
37
|
-
{ pattern: /sk-[a-zA-Z0-9]{48}/g, message: "OpenAI API key detected" },
|
|
38
|
-
{ pattern: /stripe[_-]?(secret|key)\s*[=:]\s*['"]sk_[^'"]+['"]/gi, message: "Stripe secret key detected" },
|
|
39
|
-
],
|
|
40
|
-
dangerous: [
|
|
41
|
-
{ pattern: /eval\s*\(/, message: "eval() usage detected", severity: "high" },
|
|
42
|
-
{ pattern: /innerHTML\s*=/, message: "innerHTML assignment detected", severity: "high" },
|
|
43
|
-
{ pattern: /dangerouslySetInnerHTML/, message: "React dangerouslySetInnerHTML detected", severity: "high" },
|
|
44
|
-
{ pattern: /document\.write\s*\(/, message: "document.write usage detected", severity: "medium" },
|
|
45
|
-
{ pattern: /new\s+Function\s*\(/, message: "Function constructor usage detected", severity: "high" },
|
|
46
|
-
{ pattern: /execSync\s*\(\s*[`$]/, message: "Command injection via shell interpolation", severity: "critical" },
|
|
47
|
-
{ pattern: /exec\s*\(\s*[`$]/, message: "Command injection risk", severity: "high" },
|
|
48
|
-
{ pattern: /child_process\.exec\s*\(.*\$\{/, message: "Command injection via template literal", severity: "critical" },
|
|
49
|
-
],
|
|
50
|
-
sqlInjection: [
|
|
51
|
-
{ pattern: /query\s*\(\s*[`$]/, message: "SQL injection via string interpolation", severity: "critical" },
|
|
52
|
-
{ pattern: /execute\s*\(\s*['"].*\+\s*/, message: "SQL injection via concatenation", severity: "critical" },
|
|
53
|
-
{ pattern: /\.raw\s*\(\s*[`$]/, message: "Raw SQL with interpolation", severity: "high" },
|
|
54
|
-
],
|
|
55
|
-
pathTraversal: [
|
|
56
|
-
{ pattern: /path\.join\s*\([^)]*req\./, message: "Path traversal via user input", severity: "high" },
|
|
57
|
-
{ pattern: /fs\.(read|write|unlink|rmdir).*req\.(params|query|body)/, message: "File operation with user input", severity: "high" },
|
|
58
|
-
{ pattern: /\.\.\/|\.\.\\/, message: "Potential path traversal sequence", severity: "medium" },
|
|
59
|
-
],
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async review(payload) {
|
|
64
|
-
const { files = [], diff = "", context = {} } = payload;
|
|
65
|
-
const findings = [];
|
|
66
|
-
const startTime = Date.now();
|
|
67
|
-
|
|
68
|
-
// Analyze diff content
|
|
69
|
-
if (diff) {
|
|
70
|
-
findings.push(...this._analyzeDiff(diff));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Analyze files content
|
|
74
|
-
for (const file of files) {
|
|
75
|
-
if (file.content) {
|
|
76
|
-
findings.push(...this._analyzeFile(file.path || "unknown", file.content));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Check for secrets
|
|
81
|
-
const secretFindings = this._checkSecrets(diff, files);
|
|
82
|
-
findings.push(...secretFindings);
|
|
83
|
-
|
|
84
|
-
// Determine approval status
|
|
85
|
-
const hasCritical = findings.some(f => f.severity === "critical");
|
|
86
|
-
const hasHigh = findings.some(f => f.severity === "high");
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
approved: !hasCritical,
|
|
90
|
-
reason: hasCritical
|
|
91
|
-
? "Critical security issues found - changes blocked"
|
|
92
|
-
: hasHigh
|
|
93
|
-
? "Approved with warnings - review high severity issues"
|
|
94
|
-
: findings.length > 0
|
|
95
|
-
? "Approved with minor warnings"
|
|
96
|
-
: "No security issues detected",
|
|
97
|
-
findings,
|
|
98
|
-
signature: this._sign(findings),
|
|
99
|
-
metadata: {
|
|
100
|
-
analysisTimeMs: Date.now() - startTime,
|
|
101
|
-
filesAnalyzed: files.length,
|
|
102
|
-
patternsChecked: this._countPatterns(),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
_analyzeDiff(diff) {
|
|
108
|
-
const findings = [];
|
|
109
|
-
const lines = diff.split("\n");
|
|
110
|
-
let currentFile = "unknown";
|
|
111
|
-
let lineNumber = 0;
|
|
112
|
-
|
|
113
|
-
for (const line of lines) {
|
|
114
|
-
// Track file context from diff header
|
|
115
|
-
if (line.startsWith("+++") || line.startsWith("---")) {
|
|
116
|
-
const match = line.match(/[ab]\/(.+)/);
|
|
117
|
-
if (match) currentFile = match[1];
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Track line numbers
|
|
122
|
-
if (line.startsWith("@@")) {
|
|
123
|
-
const match = line.match(/@@ -\d+(?:,\d+)? \+(\d+)/);
|
|
124
|
-
if (match) lineNumber = parseInt(match[1], 10);
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Only check added lines
|
|
129
|
-
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
130
|
-
const addedContent = line.slice(1);
|
|
131
|
-
|
|
132
|
-
// Check dangerous patterns
|
|
133
|
-
for (const category of ["dangerous", "sqlInjection", "pathTraversal"]) {
|
|
134
|
-
for (const { pattern, message, severity } of this.patterns[category]) {
|
|
135
|
-
if (pattern.test(addedContent)) {
|
|
136
|
-
findings.push({
|
|
137
|
-
type: `${category}-pattern`,
|
|
138
|
-
severity: severity || "high",
|
|
139
|
-
message,
|
|
140
|
-
file: currentFile,
|
|
141
|
-
line: lineNumber,
|
|
142
|
-
evidence: addedContent.trim().slice(0, 100),
|
|
143
|
-
});
|
|
144
|
-
// Reset lastIndex for global patterns
|
|
145
|
-
pattern.lastIndex = 0;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
lineNumber++;
|
|
150
|
-
} else if (!line.startsWith("-")) {
|
|
151
|
-
lineNumber++;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return findings;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
_analyzeFile(filePath, content) {
|
|
159
|
-
const findings = [];
|
|
160
|
-
const lines = content.split("\n");
|
|
161
|
-
|
|
162
|
-
for (let i = 0; i < lines.length; i++) {
|
|
163
|
-
const line = lines[i];
|
|
164
|
-
|
|
165
|
-
for (const category of ["dangerous", "sqlInjection", "pathTraversal"]) {
|
|
166
|
-
for (const { pattern, message, severity } of this.patterns[category]) {
|
|
167
|
-
if (pattern.test(line)) {
|
|
168
|
-
findings.push({
|
|
169
|
-
type: `${category}-pattern`,
|
|
170
|
-
severity: severity || "high",
|
|
171
|
-
message,
|
|
172
|
-
file: filePath,
|
|
173
|
-
line: i + 1,
|
|
174
|
-
evidence: line.trim().slice(0, 100),
|
|
175
|
-
});
|
|
176
|
-
pattern.lastIndex = 0;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return findings;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
_checkSecrets(diff, files) {
|
|
186
|
-
const findings = [];
|
|
187
|
-
const allContent = diff + files.map(f => f.content || "").join("\n");
|
|
188
|
-
|
|
189
|
-
for (const { pattern, message } of this.patterns.secrets) {
|
|
190
|
-
const matches = allContent.match(pattern);
|
|
191
|
-
if (matches) {
|
|
192
|
-
for (const match of matches) {
|
|
193
|
-
findings.push({
|
|
194
|
-
type: "secret-in-diff",
|
|
195
|
-
severity: "critical",
|
|
196
|
-
message,
|
|
197
|
-
evidence: this._redactSecret(match),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
pattern.lastIndex = 0;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return findings;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
_redactSecret(secret) {
|
|
208
|
-
// Show first 4 and last 2 chars, redact the rest
|
|
209
|
-
if (secret.length <= 10) return "***REDACTED***";
|
|
210
|
-
return secret.slice(0, 4) + "***REDACTED***" + secret.slice(-2);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
_countPatterns() {
|
|
214
|
-
return Object.values(this.patterns).reduce((sum, arr) => sum + arr.length, 0);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
_sign(findings) {
|
|
218
|
-
const timestamp = Date.now();
|
|
219
|
-
const hash = crypto
|
|
220
|
-
.createHash("sha256")
|
|
221
|
-
.update(JSON.stringify({ findings: findings.length, timestamp }))
|
|
222
|
-
.digest("hex")
|
|
223
|
-
.slice(0, 16);
|
|
224
|
-
return `sec_${timestamp}_${hash}_${findings.length}`;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
module.exports = { SecurityAuthority };
|