@vibecheckai/cli 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +532 -0
- package/dist/autopatch/verified-autopatch.d.ts +111 -0
- package/dist/autopatch/verified-autopatch.d.ts.map +1 -0
- package/dist/autopatch/verified-autopatch.js +503 -0
- package/dist/autopatch/verified-autopatch.js.map +1 -0
- package/dist/bundles/guardrail-core.js +25799 -0
- package/dist/bundles/guardrail-security.js +208687 -0
- package/dist/bundles/guardrail-ship.js +2318 -0
- package/dist/bundles/index.js +8 -0
- package/dist/commands/autopilot-decision.d.ts +24 -0
- package/dist/commands/autopilot-decision.d.ts.map +1 -0
- package/dist/commands/autopilot-decision.js +304 -0
- package/dist/commands/autopilot-decision.js.map +1 -0
- package/dist/commands/autopilot.d.ts +33 -0
- package/dist/commands/autopilot.d.ts.map +1 -0
- package/dist/commands/autopilot.js +1539 -0
- package/dist/commands/autopilot.js.map +1 -0
- package/dist/commands/baseline.d.ts +7 -0
- package/dist/commands/baseline.d.ts.map +1 -0
- package/dist/commands/baseline.js +79 -0
- package/dist/commands/baseline.js.map +1 -0
- package/dist/commands/cache.d.ts +13 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +165 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/checkpoint.d.ts +8 -0
- package/dist/commands/checkpoint.d.ts.map +1 -0
- package/dist/commands/checkpoint.js +35 -0
- package/dist/commands/checkpoint.js.map +1 -0
- package/dist/commands/context.d.ts +8 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +340 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/debug.d.ts +78 -0
- package/dist/commands/debug.d.ts.map +1 -0
- package/dist/commands/debug.js +381 -0
- package/dist/commands/debug.js.map +1 -0
- package/dist/commands/doctor.d.ts +17 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +226 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/evidence.d.ts +45 -0
- package/dist/commands/evidence.d.ts.map +1 -0
- package/dist/commands/evidence.js +197 -0
- package/dist/commands/evidence.js.map +1 -0
- package/dist/commands/explain.d.ts +8 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +52 -0
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/fix-consolidated.d.ts +19 -0
- package/dist/commands/fix-consolidated.d.ts.map +1 -0
- package/dist/commands/fix-consolidated.js +165 -0
- package/dist/commands/fix-consolidated.js.map +1 -0
- package/dist/commands/index.d.ts +8 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +15 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +125 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/launcher.d.ts +10 -0
- package/dist/commands/launcher.d.ts.map +1 -0
- package/dist/commands/launcher.js +174 -0
- package/dist/commands/launcher.js.map +1 -0
- package/dist/commands/on.d.ts +8 -0
- package/dist/commands/on.d.ts.map +1 -0
- package/dist/commands/on.js +123 -0
- package/dist/commands/on.js.map +1 -0
- package/dist/commands/preview.d.ts +54 -0
- package/dist/commands/preview.d.ts.map +1 -0
- package/dist/commands/preview.js +352 -0
- package/dist/commands/preview.js.map +1 -0
- package/dist/commands/quality/check.d.ts +31 -0
- package/dist/commands/quality/check.d.ts.map +1 -0
- package/dist/commands/quality/check.js +242 -0
- package/dist/commands/quality/check.js.map +1 -0
- package/dist/commands/quality/index.d.ts +8 -0
- package/dist/commands/quality/index.d.ts.map +1 -0
- package/dist/commands/quality/index.js +14 -0
- package/dist/commands/quality/index.js.map +1 -0
- package/dist/commands/quality/setup-quality.d.ts +23 -0
- package/dist/commands/quality/setup-quality.d.ts.map +1 -0
- package/dist/commands/quality/setup-quality.js +452 -0
- package/dist/commands/quality/setup-quality.js.map +1 -0
- package/dist/commands/quality/tidy.d.ts +41 -0
- package/dist/commands/quality/tidy.d.ts.map +1 -0
- package/dist/commands/quality/tidy.js +466 -0
- package/dist/commands/quality/tidy.js.map +1 -0
- package/dist/commands/quality/utils.d.ts +73 -0
- package/dist/commands/quality/utils.d.ts.map +1 -0
- package/dist/commands/quality/utils.js +158 -0
- package/dist/commands/quality/utils.js.map +1 -0
- package/dist/commands/replay.d.ts +8 -0
- package/dist/commands/replay.d.ts.map +1 -0
- package/dist/commands/replay.js +52 -0
- package/dist/commands/replay.js.map +1 -0
- package/dist/commands/scan-consolidated.d.ts +61 -0
- package/dist/commands/scan-consolidated.d.ts.map +1 -0
- package/dist/commands/scan-consolidated.js +243 -0
- package/dist/commands/scan-consolidated.js.map +1 -0
- package/dist/commands/scan-secrets.d.ts +47 -0
- package/dist/commands/scan-secrets.d.ts.map +1 -0
- package/dist/commands/scan-secrets.js +225 -0
- package/dist/commands/scan-secrets.js.map +1 -0
- package/dist/commands/scan-vulnerabilities-enhanced.d.ts +41 -0
- package/dist/commands/scan-vulnerabilities-enhanced.d.ts.map +1 -0
- package/dist/commands/scan-vulnerabilities-enhanced.js +368 -0
- package/dist/commands/scan-vulnerabilities-enhanced.js.map +1 -0
- package/dist/commands/scan-vulnerabilities-osv.d.ts +58 -0
- package/dist/commands/scan-vulnerabilities-osv.d.ts.map +1 -0
- package/dist/commands/scan-vulnerabilities-osv.js +716 -0
- package/dist/commands/scan-vulnerabilities-osv.js.map +1 -0
- package/dist/commands/scan-vulnerabilities.d.ts +32 -0
- package/dist/commands/scan-vulnerabilities.d.ts.map +1 -0
- package/dist/commands/scan-vulnerabilities.js +283 -0
- package/dist/commands/scan-vulnerabilities.js.map +1 -0
- package/dist/commands/secrets-allowlist.d.ts +7 -0
- package/dist/commands/secrets-allowlist.d.ts.map +1 -0
- package/dist/commands/secrets-allowlist.js +85 -0
- package/dist/commands/secrets-allowlist.js.map +1 -0
- package/dist/commands/ship-consolidated.d.ts +58 -0
- package/dist/commands/ship-consolidated.d.ts.map +1 -0
- package/dist/commands/ship-consolidated.js +515 -0
- package/dist/commands/ship-consolidated.js.map +1 -0
- package/dist/commands/stats.d.ts +8 -0
- package/dist/commands/stats.d.ts.map +1 -0
- package/dist/commands/stats.js +134 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/commands/upgrade.d.ts +8 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +30 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/fix/analytics.d.ts +121 -0
- package/dist/fix/analytics.d.ts.map +1 -0
- package/dist/fix/analytics.js +289 -0
- package/dist/fix/analytics.js.map +1 -0
- package/dist/fix/applicator.d.ts +44 -0
- package/dist/fix/applicator.d.ts.map +1 -0
- package/dist/fix/applicator.js +144 -0
- package/dist/fix/applicator.js.map +1 -0
- package/dist/fix/audit.d.ts +61 -0
- package/dist/fix/audit.d.ts.map +1 -0
- package/dist/fix/audit.js +149 -0
- package/dist/fix/audit.js.map +1 -0
- package/dist/fix/backup.d.ts +38 -0
- package/dist/fix/backup.d.ts.map +1 -0
- package/dist/fix/backup.js +154 -0
- package/dist/fix/backup.js.map +1 -0
- package/dist/fix/config.d.ts +78 -0
- package/dist/fix/config.d.ts.map +1 -0
- package/dist/fix/config.js +200 -0
- package/dist/fix/config.js.map +1 -0
- package/dist/fix/engine.d.ts +55 -0
- package/dist/fix/engine.d.ts.map +1 -0
- package/dist/fix/engine.js +285 -0
- package/dist/fix/engine.js.map +1 -0
- package/dist/fix/impact.d.ts +74 -0
- package/dist/fix/impact.d.ts.map +1 -0
- package/dist/fix/impact.js +281 -0
- package/dist/fix/impact.js.map +1 -0
- package/dist/fix/index.d.ts +5 -0
- package/dist/fix/index.d.ts.map +1 -0
- package/dist/fix/index.js +12 -0
- package/dist/fix/index.js.map +1 -0
- package/dist/fix/interactive.d.ts +22 -0
- package/dist/fix/interactive.d.ts.map +1 -0
- package/dist/fix/interactive.js +172 -0
- package/dist/fix/interactive.js.map +1 -0
- package/dist/fix/learning.d.ts +109 -0
- package/dist/fix/learning.d.ts.map +1 -0
- package/dist/fix/learning.js +296 -0
- package/dist/fix/learning.js.map +1 -0
- package/dist/fix/metrics.d.ts +106 -0
- package/dist/fix/metrics.d.ts.map +1 -0
- package/dist/fix/metrics.js +138 -0
- package/dist/fix/metrics.js.map +1 -0
- package/dist/fix/parallel.d.ts +69 -0
- package/dist/fix/parallel.d.ts.map +1 -0
- package/dist/fix/parallel.js +203 -0
- package/dist/fix/parallel.js.map +1 -0
- package/dist/fix/report.d.ts +40 -0
- package/dist/fix/report.d.ts.map +1 -0
- package/dist/fix/report.js +212 -0
- package/dist/fix/report.js.map +1 -0
- package/dist/fix/strategy.d.ts +53 -0
- package/dist/fix/strategy.d.ts.map +1 -0
- package/dist/fix/strategy.js +143 -0
- package/dist/fix/strategy.js.map +1 -0
- package/dist/fix/templates.d.ts +58 -0
- package/dist/fix/templates.d.ts.map +1 -0
- package/dist/fix/templates.js +259 -0
- package/dist/fix/templates.js.map +1 -0
- package/dist/fix/testing.d.ts +68 -0
- package/dist/fix/testing.d.ts.map +1 -0
- package/dist/fix/testing.js +245 -0
- package/dist/fix/testing.js.map +1 -0
- package/dist/fix/validation.d.ts +71 -0
- package/dist/fix/validation.d.ts.map +1 -0
- package/dist/fix/validation.js +267 -0
- package/dist/fix/validation.js.map +1 -0
- package/dist/fix/visualization.d.ts +73 -0
- package/dist/fix/visualization.d.ts.map +1 -0
- package/dist/fix/visualization.js +243 -0
- package/dist/fix/visualization.js.map +1 -0
- package/dist/formatters/index.d.ts +6 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +11 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/formatters/sarif-enhanced.d.ts +78 -0
- package/dist/formatters/sarif-enhanced.d.ts.map +1 -0
- package/dist/formatters/sarif-enhanced.js +144 -0
- package/dist/formatters/sarif-enhanced.js.map +1 -0
- package/dist/formatters/sarif-v2.d.ts +121 -0
- package/dist/formatters/sarif-v2.d.ts.map +1 -0
- package/dist/formatters/sarif-v2.js +356 -0
- package/dist/formatters/sarif-v2.js.map +1 -0
- package/dist/formatters/sarif.d.ts +72 -0
- package/dist/formatters/sarif.d.ts.map +1 -0
- package/dist/formatters/sarif.js +146 -0
- package/dist/formatters/sarif.js.map +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4455 -0
- package/dist/index.js.map +1 -0
- package/dist/init/ci-generator.d.ts +18 -0
- package/dist/init/ci-generator.d.ts.map +1 -0
- package/dist/init/ci-generator.js +317 -0
- package/dist/init/ci-generator.js.map +1 -0
- package/dist/init/detect-framework.d.ts +15 -0
- package/dist/init/detect-framework.d.ts.map +1 -0
- package/dist/init/detect-framework.js +301 -0
- package/dist/init/detect-framework.js.map +1 -0
- package/dist/init/hooks-installer.d.ts +22 -0
- package/dist/init/hooks-installer.d.ts.map +1 -0
- package/dist/init/hooks-installer.js +310 -0
- package/dist/init/hooks-installer.js.map +1 -0
- package/dist/init/index.d.ts +8 -0
- package/dist/init/index.d.ts.map +1 -0
- package/dist/init/index.js +22 -0
- package/dist/init/index.js.map +1 -0
- package/dist/init/templates.d.ts +401 -0
- package/dist/init/templates.d.ts.map +1 -0
- package/dist/init/templates.js +240 -0
- package/dist/init/templates.js.map +1 -0
- package/dist/mcp/server.d.ts +12 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +42 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/telemetry.d.ts +40 -0
- package/dist/mcp/telemetry.d.ts.map +1 -0
- package/dist/mcp/telemetry.js +98 -0
- package/dist/mcp/telemetry.js.map +1 -0
- package/dist/reality/no-dead-buttons/button-sweep-generator.d.ts +32 -0
- package/dist/reality/no-dead-buttons/button-sweep-generator.d.ts.map +1 -0
- package/dist/reality/no-dead-buttons/button-sweep-generator.js +236 -0
- package/dist/reality/no-dead-buttons/button-sweep-generator.js.map +1 -0
- package/dist/reality/no-dead-buttons/index.d.ts +11 -0
- package/dist/reality/no-dead-buttons/index.d.ts.map +1 -0
- package/dist/reality/no-dead-buttons/index.js +18 -0
- package/dist/reality/no-dead-buttons/index.js.map +1 -0
- package/dist/reality/no-dead-buttons/static-scanner.d.ts +34 -0
- package/dist/reality/no-dead-buttons/static-scanner.d.ts.map +1 -0
- package/dist/reality/no-dead-buttons/static-scanner.js +230 -0
- package/dist/reality/no-dead-buttons/static-scanner.js.map +1 -0
- package/dist/reality/reality-graph.d.ts +192 -0
- package/dist/reality/reality-graph.d.ts.map +1 -0
- package/dist/reality/reality-graph.js +600 -0
- package/dist/reality/reality-graph.js.map +1 -0
- package/dist/reality/reality-runner.d.ts +89 -0
- package/dist/reality/reality-runner.d.ts.map +1 -0
- package/dist/reality/reality-runner.js +540 -0
- package/dist/reality/reality-runner.js.map +1 -0
- package/dist/reality/receipt-generator.d.ts +152 -0
- package/dist/reality/receipt-generator.d.ts.map +1 -0
- package/dist/reality/receipt-generator.js +495 -0
- package/dist/reality/receipt-generator.js.map +1 -0
- package/dist/reality/runtime-tracer.d.ts +75 -0
- package/dist/reality/runtime-tracer.d.ts.map +1 -0
- package/dist/reality/runtime-tracer.js +109 -0
- package/dist/reality/runtime-tracer.js.map +1 -0
- package/dist/runtime/auth-utils.d.ts +43 -0
- package/dist/runtime/auth-utils.d.ts.map +1 -0
- package/dist/runtime/auth-utils.js +130 -0
- package/dist/runtime/auth-utils.js.map +1 -0
- package/dist/runtime/cli-errors.d.ts +38 -0
- package/dist/runtime/cli-errors.d.ts.map +1 -0
- package/dist/runtime/cli-errors.js +354 -0
- package/dist/runtime/cli-errors.js.map +1 -0
- package/dist/runtime/client.d.ts +74 -0
- package/dist/runtime/client.d.ts.map +1 -0
- package/dist/runtime/client.js +222 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/creds.d.ts +48 -0
- package/dist/runtime/creds.d.ts.map +1 -0
- package/dist/runtime/creds.js +245 -0
- package/dist/runtime/creds.js.map +1 -0
- package/dist/runtime/exit-codes.d.ts +49 -0
- package/dist/runtime/exit-codes.d.ts.map +1 -0
- package/dist/runtime/exit-codes.js +93 -0
- package/dist/runtime/exit-codes.js.map +1 -0
- package/dist/runtime/index.d.ts +9 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +25 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/json-output.d.ts +42 -0
- package/dist/runtime/json-output.d.ts.map +1 -0
- package/dist/runtime/json-output.js +59 -0
- package/dist/runtime/json-output.js.map +1 -0
- package/dist/runtime/owner-mode.d.ts +48 -0
- package/dist/runtime/owner-mode.d.ts.map +1 -0
- package/dist/runtime/owner-mode.js +284 -0
- package/dist/runtime/owner-mode.js.map +1 -0
- package/dist/runtime/semver.d.ts +37 -0
- package/dist/runtime/semver.d.ts.map +1 -0
- package/dist/runtime/semver.js +110 -0
- package/dist/runtime/semver.js.map +1 -0
- package/dist/scan/dead-ui-detector.d.ts +48 -0
- package/dist/scan/dead-ui-detector.d.ts.map +1 -0
- package/dist/scan/dead-ui-detector.js +170 -0
- package/dist/scan/dead-ui-detector.js.map +1 -0
- package/dist/scan/playwright-sweep.d.ts +40 -0
- package/dist/scan/playwright-sweep.d.ts.map +1 -0
- package/dist/scan/playwright-sweep.js +216 -0
- package/dist/scan/playwright-sweep.js.map +1 -0
- package/dist/scan/proof-bundle.d.ts +25 -0
- package/dist/scan/proof-bundle.d.ts.map +1 -0
- package/dist/scan/proof-bundle.js +203 -0
- package/dist/scan/proof-bundle.js.map +1 -0
- package/dist/scan/proof-graph.d.ts +59 -0
- package/dist/scan/proof-graph.d.ts.map +1 -0
- package/dist/scan/proof-graph.js +64 -0
- package/dist/scan/proof-graph.js.map +1 -0
- package/dist/scan/reality-sniff.d.ts +56 -0
- package/dist/scan/reality-sniff.d.ts.map +1 -0
- package/dist/scan/reality-sniff.js +200 -0
- package/dist/scan/reality-sniff.js.map +1 -0
- package/dist/scan/structural-verifier.d.ts +20 -0
- package/dist/scan/structural-verifier.d.ts.map +1 -0
- package/dist/scan/structural-verifier.js +112 -0
- package/dist/scan/structural-verifier.js.map +1 -0
- package/dist/scan/verification-engine.d.ts +47 -0
- package/dist/scan/verification-engine.d.ts.map +1 -0
- package/dist/scan/verification-engine.js +141 -0
- package/dist/scan/verification-engine.js.map +1 -0
- package/dist/scanner/baseline.d.ts +52 -0
- package/dist/scanner/baseline.d.ts.map +1 -0
- package/dist/scanner/baseline.js +85 -0
- package/dist/scanner/baseline.js.map +1 -0
- package/dist/scanner/incremental.d.ts +30 -0
- package/dist/scanner/incremental.d.ts.map +1 -0
- package/dist/scanner/incremental.js +82 -0
- package/dist/scanner/incremental.js.map +1 -0
- package/dist/scanner/index.d.ts +8 -0
- package/dist/scanner/index.d.ts.map +1 -0
- package/dist/scanner/index.js +15 -0
- package/dist/scanner/index.js.map +1 -0
- package/dist/scanner/parallel.d.ts +43 -0
- package/dist/scanner/parallel.d.ts.map +1 -0
- package/dist/scanner/parallel.js +99 -0
- package/dist/scanner/parallel.js.map +1 -0
- package/dist/scanner/placeholder-detector.d.ts +56 -0
- package/dist/scanner/placeholder-detector.d.ts.map +1 -0
- package/dist/scanner/placeholder-detector.js +220 -0
- package/dist/scanner/placeholder-detector.js.map +1 -0
- package/dist/scanner/route-detector.d.ts +100 -0
- package/dist/scanner/route-detector.d.ts.map +1 -0
- package/dist/scanner/route-detector.js +455 -0
- package/dist/scanner/route-detector.js.map +1 -0
- package/dist/scanner/scoring.d.ts +67 -0
- package/dist/scanner/scoring.d.ts.map +1 -0
- package/dist/scanner/scoring.js +284 -0
- package/dist/scanner/scoring.js.map +1 -0
- package/dist/ship-baseline.d.ts +56 -0
- package/dist/ship-baseline.d.ts.map +1 -0
- package/dist/ship-baseline.js +194 -0
- package/dist/ship-baseline.js.map +1 -0
- package/dist/ship-config.d.ts +91 -0
- package/dist/ship-config.d.ts.map +1 -0
- package/dist/ship-config.js +133 -0
- package/dist/ship-config.js.map +1 -0
- package/dist/ship-data-loader.d.ts +70 -0
- package/dist/ship-data-loader.d.ts.map +1 -0
- package/dist/ship-data-loader.js +301 -0
- package/dist/ship-data-loader.js.map +1 -0
- package/dist/standalone.d.ts +1 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +1 -0
- package/dist/standalone.js.map +1 -0
- package/dist/truth-pack/index.d.ts +102 -0
- package/dist/truth-pack/index.d.ts.map +1 -0
- package/dist/truth-pack/index.js +694 -0
- package/dist/truth-pack/index.js.map +1 -0
- package/dist/ui/frame.d.ts +68 -0
- package/dist/ui/frame.d.ts.map +1 -0
- package/dist/ui/frame.js +165 -0
- package/dist/ui/frame.js.map +1 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +16 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui.d.ts +36 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +45 -0
- package/dist/ui.js.map +1 -0
- package/dist/utils/ai-helpers.d.ts +72 -0
- package/dist/utils/ai-helpers.d.ts.map +1 -0
- package/dist/utils/ai-helpers.js +339 -0
- package/dist/utils/ai-helpers.js.map +1 -0
- package/dist/utils/validation.d.ts +34 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +160 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,694 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Truth Pack Generator
|
|
4
|
+
*
|
|
5
|
+
* Creates the relationship infrastructure that makes AI dependent on repo-truth.
|
|
6
|
+
* This is the moat - installed once, used 500x/day.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TruthPackGenerator = void 0;
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const child_process_1 = require("child_process");
|
|
13
|
+
const TRUTH_PACK_DIR = '.guardrail-context';
|
|
14
|
+
class TruthPackGenerator {
|
|
15
|
+
constructor(projectPath) {
|
|
16
|
+
this.projectPath = (0, path_1.resolve)(projectPath);
|
|
17
|
+
this.truthPackPath = (0, path_1.join)(this.projectPath, TRUTH_PACK_DIR);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate complete Truth Pack
|
|
21
|
+
*/
|
|
22
|
+
async generate() {
|
|
23
|
+
// Ensure directory exists
|
|
24
|
+
if (!(0, fs_1.existsSync)(this.truthPackPath)) {
|
|
25
|
+
(0, fs_1.mkdirSync)(this.truthPackPath, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
// Detect stack
|
|
28
|
+
const stack = this.detectStack();
|
|
29
|
+
// Generate all components
|
|
30
|
+
const [symbols, deps, graph, routes, risk, importance, patterns, antipatterns, vulnerabilities] = await Promise.all([
|
|
31
|
+
this.generateSymbols(),
|
|
32
|
+
this.generateDependencies(),
|
|
33
|
+
this.generateImportGraph(),
|
|
34
|
+
this.generateRoutes(),
|
|
35
|
+
this.generateRiskTags(),
|
|
36
|
+
this.generateImportance(),
|
|
37
|
+
this.generatePatterns(),
|
|
38
|
+
this.generateAntipatterns(),
|
|
39
|
+
this.generateVulnerabilities(),
|
|
40
|
+
]);
|
|
41
|
+
// Generate metadata
|
|
42
|
+
const metadata = this.generateMetadata();
|
|
43
|
+
// Create Truth Pack
|
|
44
|
+
const truthPack = {
|
|
45
|
+
version: '1.0.0',
|
|
46
|
+
generatedAt: new Date().toISOString(),
|
|
47
|
+
projectPath: this.projectPath,
|
|
48
|
+
stack,
|
|
49
|
+
metadata,
|
|
50
|
+
};
|
|
51
|
+
// Write all files
|
|
52
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'truthpack.json'), JSON.stringify(truthPack, null, 2));
|
|
53
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'symbols.json'), JSON.stringify(symbols, null, 2));
|
|
54
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'deps.json'), JSON.stringify(deps, null, 2));
|
|
55
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'graph.json'), JSON.stringify(graph, null, 2));
|
|
56
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'routes.json'), JSON.stringify(routes, null, 2));
|
|
57
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'risk.json'), JSON.stringify(risk, null, 2));
|
|
58
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'importance.json'), JSON.stringify(importance, null, 2));
|
|
59
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'patterns.json'), JSON.stringify(patterns, null, 2));
|
|
60
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'antipatterns.json'), JSON.stringify(antipatterns, null, 2));
|
|
61
|
+
(0, fs_1.writeFileSync)((0, path_1.join)(this.truthPackPath, 'vulnerabilities.json'), JSON.stringify(vulnerabilities, null, 2));
|
|
62
|
+
return truthPack;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if Truth Pack exists and is fresh
|
|
66
|
+
*/
|
|
67
|
+
isFresh(maxAgeHours = 24) {
|
|
68
|
+
const truthPackFile = (0, path_1.join)(this.truthPackPath, 'truthpack.json');
|
|
69
|
+
if (!(0, fs_1.existsSync)(truthPackFile)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const content = JSON.parse((0, fs_1.readFileSync)(truthPackFile, 'utf-8'));
|
|
74
|
+
const generatedAt = new Date(content.generatedAt);
|
|
75
|
+
const ageHours = (Date.now() - generatedAt.getTime()) / (1000 * 60 * 60);
|
|
76
|
+
return ageHours < maxAgeHours;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get Truth Pack path
|
|
84
|
+
*/
|
|
85
|
+
getPath() {
|
|
86
|
+
return this.truthPackPath;
|
|
87
|
+
}
|
|
88
|
+
detectStack() {
|
|
89
|
+
const packageJsonPath = (0, path_1.join)(this.projectPath, 'package.json');
|
|
90
|
+
const hasPackageJson = (0, fs_1.existsSync)(packageJsonPath);
|
|
91
|
+
let framework = 'unknown';
|
|
92
|
+
let language = 'unknown';
|
|
93
|
+
let packageManager = 'unknown';
|
|
94
|
+
let runtime;
|
|
95
|
+
if (hasPackageJson) {
|
|
96
|
+
try {
|
|
97
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
98
|
+
// Detect framework
|
|
99
|
+
if (pkg.dependencies?.['next'])
|
|
100
|
+
framework = 'nextjs';
|
|
101
|
+
else if (pkg.dependencies?.['react'])
|
|
102
|
+
framework = 'react';
|
|
103
|
+
else if (pkg.dependencies?.['vue'])
|
|
104
|
+
framework = 'vue';
|
|
105
|
+
else if (pkg.dependencies?.['@nestjs/core'])
|
|
106
|
+
framework = 'nestjs';
|
|
107
|
+
else if (pkg.dependencies?.['express'])
|
|
108
|
+
framework = 'express';
|
|
109
|
+
else if (pkg.dependencies?.['fastify'])
|
|
110
|
+
framework = 'fastify';
|
|
111
|
+
else if (pkg.dependencies?.['@angular/core'])
|
|
112
|
+
framework = 'angular';
|
|
113
|
+
// Detect package manager
|
|
114
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(this.projectPath, 'pnpm-lock.yaml')))
|
|
115
|
+
packageManager = 'pnpm';
|
|
116
|
+
else if ((0, fs_1.existsSync)((0, path_1.join)(this.projectPath, 'yarn.lock')))
|
|
117
|
+
packageManager = 'yarn';
|
|
118
|
+
else if ((0, fs_1.existsSync)((0, path_1.join)(this.projectPath, 'package-lock.json')))
|
|
119
|
+
packageManager = 'npm';
|
|
120
|
+
// Detect runtime
|
|
121
|
+
if (pkg.engines?.node)
|
|
122
|
+
runtime = `node ${pkg.engines.node}`;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// Ignore
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Detect language from files
|
|
129
|
+
const tsConfigPath = (0, path_1.join)(this.projectPath, 'tsconfig.json');
|
|
130
|
+
if ((0, fs_1.existsSync)(tsConfigPath)) {
|
|
131
|
+
language = 'typescript';
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// Check for .js files
|
|
135
|
+
try {
|
|
136
|
+
const result = (0, child_process_1.execSync)('find . -name "*.js" -type f | head -1', { cwd: this.projectPath, encoding: 'utf-8' });
|
|
137
|
+
if (result.trim())
|
|
138
|
+
language = 'javascript';
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// Ignore
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return { framework, language, packageManager, runtime };
|
|
145
|
+
}
|
|
146
|
+
async generateSymbols() {
|
|
147
|
+
const symbols = [];
|
|
148
|
+
const codeFiles = await this.findCodeFiles(['.ts', '.tsx', '.js', '.jsx']);
|
|
149
|
+
for (const file of codeFiles) {
|
|
150
|
+
try {
|
|
151
|
+
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
152
|
+
const relativePath = file.replace(this.projectPath + '/', '');
|
|
153
|
+
// Extract exports using regex (fallback if TypeScript API not available)
|
|
154
|
+
const exportPatterns = [
|
|
155
|
+
/export\s+(?:async\s+)?function\s+(\w+)/g,
|
|
156
|
+
/export\s+(?:default\s+)?class\s+(\w+)/g,
|
|
157
|
+
/export\s+(?:default\s+)?(?:const|let|var)\s+(\w+)/g,
|
|
158
|
+
/export\s+interface\s+(\w+)/g,
|
|
159
|
+
/export\s+type\s+(\w+)/g,
|
|
160
|
+
/export\s+enum\s+(\w+)/g,
|
|
161
|
+
];
|
|
162
|
+
const lines = content.split('\n');
|
|
163
|
+
lines.forEach((line, index) => {
|
|
164
|
+
for (const pattern of exportPatterns) {
|
|
165
|
+
const match = pattern.exec(line);
|
|
166
|
+
if (match) {
|
|
167
|
+
const name = match[1];
|
|
168
|
+
let type = 'function';
|
|
169
|
+
if (line.includes('class'))
|
|
170
|
+
type = 'class';
|
|
171
|
+
else if (line.includes('interface'))
|
|
172
|
+
type = 'interface';
|
|
173
|
+
else if (line.includes('type'))
|
|
174
|
+
type = 'type';
|
|
175
|
+
else if (line.includes('enum'))
|
|
176
|
+
type = 'enum';
|
|
177
|
+
else if (line.includes('const') || line.includes('let') || line.includes('var'))
|
|
178
|
+
type = 'variable';
|
|
179
|
+
symbols.push({
|
|
180
|
+
name,
|
|
181
|
+
type,
|
|
182
|
+
file: relativePath,
|
|
183
|
+
line: index + 1,
|
|
184
|
+
exported: true,
|
|
185
|
+
signature: this.extractSignature(line, content, index),
|
|
186
|
+
doc: this.extractDoc(content, index),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// Ignore files we can't read
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return symbols;
|
|
197
|
+
}
|
|
198
|
+
extractSignature(line, content, lineIndex) {
|
|
199
|
+
// Extract function/class signature
|
|
200
|
+
const lines = content.split('\n');
|
|
201
|
+
let signature = line.trim();
|
|
202
|
+
// If line ends with {, get more lines
|
|
203
|
+
if (signature.endsWith('{') || signature.includes('=>')) {
|
|
204
|
+
let i = lineIndex;
|
|
205
|
+
while (i < lines.length - 1 && !signature.includes('{') && !signature.includes('=>')) {
|
|
206
|
+
i++;
|
|
207
|
+
signature += ' ' + lines[i].trim();
|
|
208
|
+
if (signature.length > 200)
|
|
209
|
+
break; // Limit length
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return signature.length > 200 ? signature.substring(0, 200) + '...' : signature;
|
|
213
|
+
}
|
|
214
|
+
extractDoc(content, lineIndex) {
|
|
215
|
+
const lines = content.split('\n');
|
|
216
|
+
const docLines = [];
|
|
217
|
+
// Look backwards for JSDoc comments
|
|
218
|
+
for (let i = lineIndex - 1; i >= 0 && i >= lineIndex - 10; i--) {
|
|
219
|
+
const line = lines[i].trim();
|
|
220
|
+
if (line.startsWith('*') || line.startsWith('/**') || line.startsWith('//')) {
|
|
221
|
+
docLines.unshift(line.replace(/^\s*[*\/]+\s*/, ''));
|
|
222
|
+
}
|
|
223
|
+
else if (line.length > 0 && !line.startsWith('*')) {
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return docLines.length > 0 ? docLines.join(' ').substring(0, 200) : undefined;
|
|
228
|
+
}
|
|
229
|
+
async findCodeFiles(extensions) {
|
|
230
|
+
const files = [];
|
|
231
|
+
const exclude = ['node_modules', '.git', 'dist', 'build', '.next'];
|
|
232
|
+
const walk = (dir, depth = 0) => {
|
|
233
|
+
if (depth > 10)
|
|
234
|
+
return; // Limit depth
|
|
235
|
+
try {
|
|
236
|
+
const entries = (0, fs_1.readdirSync)(dir);
|
|
237
|
+
for (const entry of entries) {
|
|
238
|
+
const fullPath = (0, path_1.join)(dir, entry);
|
|
239
|
+
const stat = (0, fs_1.statSync)(fullPath);
|
|
240
|
+
if (stat.isDirectory()) {
|
|
241
|
+
if (!exclude.some(e => entry.includes(e))) {
|
|
242
|
+
walk(fullPath, depth + 1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else if (stat.isFile()) {
|
|
246
|
+
const ext = (0, path_1.extname)(entry);
|
|
247
|
+
if (extensions.includes(ext)) {
|
|
248
|
+
files.push(fullPath);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
// Ignore errors
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
walk(this.projectPath);
|
|
258
|
+
return files;
|
|
259
|
+
}
|
|
260
|
+
async generateDependencies() {
|
|
261
|
+
const packageJsonPath = (0, path_1.join)(this.projectPath, 'package.json');
|
|
262
|
+
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const pkg = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
267
|
+
const deps = [];
|
|
268
|
+
// Production dependencies
|
|
269
|
+
if (pkg.dependencies) {
|
|
270
|
+
for (const [name, version] of Object.entries(pkg.dependencies)) {
|
|
271
|
+
deps.push({
|
|
272
|
+
name,
|
|
273
|
+
version: version,
|
|
274
|
+
type: 'production',
|
|
275
|
+
registry: 'npm',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// Dev dependencies
|
|
280
|
+
if (pkg.devDependencies) {
|
|
281
|
+
for (const [name, version] of Object.entries(pkg.devDependencies)) {
|
|
282
|
+
deps.push({
|
|
283
|
+
name,
|
|
284
|
+
version: version,
|
|
285
|
+
type: 'dev',
|
|
286
|
+
registry: 'npm',
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return deps;
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
async generateImportGraph() {
|
|
297
|
+
const graph = {};
|
|
298
|
+
const codeFiles = await this.findCodeFiles(['.ts', '.tsx', '.js', '.jsx']);
|
|
299
|
+
for (const file of codeFiles) {
|
|
300
|
+
try {
|
|
301
|
+
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
302
|
+
const relativePath = file.replace(this.projectPath + '/', '');
|
|
303
|
+
const imports = [];
|
|
304
|
+
// Extract imports
|
|
305
|
+
const importPatterns = [
|
|
306
|
+
/import\s+.*?\s+from\s+['"]([^'"]+)['"]/g,
|
|
307
|
+
/require\s*\(['"]([^'"]+)['"]\)/g,
|
|
308
|
+
];
|
|
309
|
+
for (const pattern of importPatterns) {
|
|
310
|
+
let match;
|
|
311
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
312
|
+
const importPath = match[1];
|
|
313
|
+
// Only track internal imports (relative paths)
|
|
314
|
+
if (importPath.startsWith('.') || importPath.startsWith('/')) {
|
|
315
|
+
imports.push(importPath);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (imports.length > 0) {
|
|
320
|
+
graph[relativePath] = imports;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// Ignore files we can't read
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return graph;
|
|
328
|
+
}
|
|
329
|
+
async generateRoutes() {
|
|
330
|
+
const routes = [];
|
|
331
|
+
const codeFiles = await this.findCodeFiles(['.ts', '.tsx', '.js', '.jsx']);
|
|
332
|
+
for (const file of codeFiles) {
|
|
333
|
+
try {
|
|
334
|
+
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
335
|
+
const relativePath = file.replace(this.projectPath + '/', '');
|
|
336
|
+
const lines = content.split('\n');
|
|
337
|
+
// Express/Fastify routes: app.get('/path', handler) or fastify.get('/path', handler)
|
|
338
|
+
const expressPattern = /(?:app|router|fastify)\.(get|post|put|delete|patch|options|head)\s*\(\s*['"`]([^'"`]+)['"`]/gi;
|
|
339
|
+
let match;
|
|
340
|
+
while ((match = expressPattern.exec(content)) !== null) {
|
|
341
|
+
const lineNum = content.substring(0, match.index).split('\n').length;
|
|
342
|
+
routes.push({
|
|
343
|
+
path: match[2],
|
|
344
|
+
method: match[1].toUpperCase(),
|
|
345
|
+
file: relativePath,
|
|
346
|
+
line: lineNum,
|
|
347
|
+
handler: this.extractHandlerName(content, match.index),
|
|
348
|
+
auth: this.hasAuth(content, lineNum),
|
|
349
|
+
middleware: this.extractMiddleware(content, lineNum),
|
|
350
|
+
params: this.extractParams(match[2]),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
// Next.js API routes: export async function GET/POST/etc
|
|
354
|
+
if (file.includes('/api/') || file.includes('/route.')) {
|
|
355
|
+
const nextPattern = /export\s+(?:async\s+)?function\s+(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD)\s*\(/gi;
|
|
356
|
+
while ((match = nextPattern.exec(content)) !== null) {
|
|
357
|
+
const lineNum = content.substring(0, match.index).split('\n').length;
|
|
358
|
+
const routePath = this.extractNextJSRoutePath(file);
|
|
359
|
+
routes.push({
|
|
360
|
+
path: routePath,
|
|
361
|
+
method: match[1],
|
|
362
|
+
file: relativePath,
|
|
363
|
+
line: lineNum,
|
|
364
|
+
handler: match[1],
|
|
365
|
+
auth: this.hasAuth(content, lineNum),
|
|
366
|
+
middleware: [],
|
|
367
|
+
params: this.extractParams(routePath),
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
// Ignore files we can't read
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return routes;
|
|
377
|
+
}
|
|
378
|
+
extractHandlerName(content, index) {
|
|
379
|
+
// Extract handler function name from route definition
|
|
380
|
+
const afterMatch = content.substring(index);
|
|
381
|
+
const handlerMatch = afterMatch.match(/,\s*(\w+)\s*\)/);
|
|
382
|
+
return handlerMatch ? handlerMatch[1] : 'anonymous';
|
|
383
|
+
}
|
|
384
|
+
hasAuth(content, lineNum) {
|
|
385
|
+
const lines = content.split('\n');
|
|
386
|
+
const context = lines.slice(Math.max(0, lineNum - 10), lineNum + 5).join('\n');
|
|
387
|
+
return /auth|authenticate|requireAuth|isAuthenticated|middleware.*auth/i.test(context);
|
|
388
|
+
}
|
|
389
|
+
extractMiddleware(content, lineNum) {
|
|
390
|
+
const lines = content.split('\n');
|
|
391
|
+
const context = lines.slice(Math.max(0, lineNum - 10), lineNum + 5).join('\n');
|
|
392
|
+
const middleware = [];
|
|
393
|
+
if (/cors/i.test(context))
|
|
394
|
+
middleware.push('cors');
|
|
395
|
+
if (/helmet/i.test(context))
|
|
396
|
+
middleware.push('helmet');
|
|
397
|
+
if (/rateLimit/i.test(context))
|
|
398
|
+
middleware.push('rateLimit');
|
|
399
|
+
if (/validate|zod/i.test(context))
|
|
400
|
+
middleware.push('validation');
|
|
401
|
+
return middleware;
|
|
402
|
+
}
|
|
403
|
+
extractParams(path) {
|
|
404
|
+
// Extract path parameters like :id or [id]
|
|
405
|
+
const params = [];
|
|
406
|
+
const paramPattern = /[:[](\w+)[\]}]/g;
|
|
407
|
+
let match;
|
|
408
|
+
while ((match = paramPattern.exec(path)) !== null) {
|
|
409
|
+
params.push(match[1]);
|
|
410
|
+
}
|
|
411
|
+
return params;
|
|
412
|
+
}
|
|
413
|
+
extractNextJSRoutePath(filePath) {
|
|
414
|
+
// Convert /app/api/users/route.ts to /api/users
|
|
415
|
+
const apiMatch = filePath.match(/\/api\/(.+?)\/route\.(ts|tsx|js|jsx)$/);
|
|
416
|
+
if (apiMatch) {
|
|
417
|
+
return `/api/${apiMatch[1]}`;
|
|
418
|
+
}
|
|
419
|
+
// Convert /pages/api/users.ts to /api/users
|
|
420
|
+
const pagesMatch = filePath.match(/\/pages\/api\/(.+?)\.(ts|tsx|js|jsx)$/);
|
|
421
|
+
if (pagesMatch) {
|
|
422
|
+
return `/api/${pagesMatch[1]}`;
|
|
423
|
+
}
|
|
424
|
+
return '/api/unknown';
|
|
425
|
+
}
|
|
426
|
+
async generateRiskTags() {
|
|
427
|
+
const riskTags = [];
|
|
428
|
+
const codeFiles = await this.findCodeFiles(['.ts', '.tsx', '.js', '.jsx']);
|
|
429
|
+
for (const file of codeFiles) {
|
|
430
|
+
try {
|
|
431
|
+
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
432
|
+
const relativePath = file.replace(this.projectPath + '/', '');
|
|
433
|
+
const lines = content.split('\n');
|
|
434
|
+
lines.forEach((line, index) => {
|
|
435
|
+
const lineNum = index + 1;
|
|
436
|
+
// Auth risk
|
|
437
|
+
if (/password|token|jwt|session|auth|login|signin/i.test(line) &&
|
|
438
|
+
/process\.env|hardcoded|secret|key/i.test(line)) {
|
|
439
|
+
riskTags.push({
|
|
440
|
+
file: relativePath,
|
|
441
|
+
line: lineNum,
|
|
442
|
+
category: 'auth',
|
|
443
|
+
severity: 'critical',
|
|
444
|
+
description: 'Potential auth credential exposure',
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
// Payment risk
|
|
448
|
+
if (/stripe|payment|billing|charge|subscription|card|credit/i.test(line) &&
|
|
449
|
+
!line.includes('//') && !line.includes('test')) {
|
|
450
|
+
riskTags.push({
|
|
451
|
+
file: relativePath,
|
|
452
|
+
line: lineNum,
|
|
453
|
+
category: 'payment',
|
|
454
|
+
severity: 'high',
|
|
455
|
+
description: 'Payment processing detected',
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
// Database risk
|
|
459
|
+
if (/sql|query|database|db\.|prisma\.|mongoose\.|sequelize/i.test(line) &&
|
|
460
|
+
/SELECT|INSERT|UPDATE|DELETE|DROP/i.test(line.toUpperCase())) {
|
|
461
|
+
riskTags.push({
|
|
462
|
+
file: relativePath,
|
|
463
|
+
line: lineNum,
|
|
464
|
+
category: 'database',
|
|
465
|
+
severity: 'high',
|
|
466
|
+
description: 'Database operation detected',
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
// Security risk
|
|
470
|
+
if (/eval|exec|dangerouslySetInnerHTML|innerHTML|document\.write/i.test(line)) {
|
|
471
|
+
riskTags.push({
|
|
472
|
+
file: relativePath,
|
|
473
|
+
line: lineNum,
|
|
474
|
+
category: 'security',
|
|
475
|
+
severity: 'critical',
|
|
476
|
+
description: 'Potentially dangerous operation',
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
// Sensitive data
|
|
480
|
+
if (/ssn|social.*security|credit.*card|bank.*account|routing/i.test(line)) {
|
|
481
|
+
riskTags.push({
|
|
482
|
+
file: relativePath,
|
|
483
|
+
line: lineNum,
|
|
484
|
+
category: 'sensitive',
|
|
485
|
+
severity: 'critical',
|
|
486
|
+
description: 'Sensitive data handling detected',
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
catch {
|
|
492
|
+
// Ignore files we can't read
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return riskTags;
|
|
496
|
+
}
|
|
497
|
+
async generateImportance() {
|
|
498
|
+
const importance = {};
|
|
499
|
+
// Get risk tags and import graph
|
|
500
|
+
const [riskTags, importGraph] = await Promise.all([
|
|
501
|
+
this.generateRiskTags(),
|
|
502
|
+
this.generateImportGraph(),
|
|
503
|
+
]);
|
|
504
|
+
// Calculate centrality (how many files import this file)
|
|
505
|
+
const centrality = {};
|
|
506
|
+
for (const [file, imports] of Object.entries(importGraph)) {
|
|
507
|
+
centrality[file] = imports.length;
|
|
508
|
+
}
|
|
509
|
+
// Count how many files import each file
|
|
510
|
+
for (const imports of Object.values(importGraph)) {
|
|
511
|
+
for (const imp of imports) {
|
|
512
|
+
// Resolve import path to actual file
|
|
513
|
+
const resolvedFile = this.resolveImportPath(imp);
|
|
514
|
+
if (resolvedFile) {
|
|
515
|
+
centrality[resolvedFile] = (centrality[resolvedFile] || 0) + 1;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// Calculate importance = risk score × centrality
|
|
520
|
+
const riskByFile = {};
|
|
521
|
+
riskTags.forEach(tag => {
|
|
522
|
+
const riskScore = tag.severity === 'critical' ? 10 : tag.severity === 'high' ? 5 : tag.severity === 'medium' ? 2 : 1;
|
|
523
|
+
riskByFile[tag.file] = (riskByFile[tag.file] || 0) + riskScore;
|
|
524
|
+
});
|
|
525
|
+
// Combine risk and centrality
|
|
526
|
+
const allFiles = new Set([...Object.keys(centrality), ...Object.keys(riskByFile)]);
|
|
527
|
+
allFiles.forEach(file => {
|
|
528
|
+
const risk = riskByFile[file] || 1;
|
|
529
|
+
const cent = centrality[file] || 1;
|
|
530
|
+
importance[file] = risk * Math.log(cent + 1); // Log scale for centrality
|
|
531
|
+
});
|
|
532
|
+
return importance;
|
|
533
|
+
}
|
|
534
|
+
resolveImportPath(importPath) {
|
|
535
|
+
// Simple resolution - in production, would need proper module resolution
|
|
536
|
+
if (importPath.startsWith('.')) {
|
|
537
|
+
// Relative import - would need to resolve from importing file
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
return null; // External imports don't count
|
|
541
|
+
}
|
|
542
|
+
async generatePatterns() {
|
|
543
|
+
const patterns = [];
|
|
544
|
+
const codeFiles = await this.findCodeFiles(['.ts', '.tsx', '.js', '.jsx']);
|
|
545
|
+
// Look for common patterns (error handling, API structure, etc.)
|
|
546
|
+
for (const file of codeFiles) {
|
|
547
|
+
try {
|
|
548
|
+
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
549
|
+
const relativePath = file.replace(this.projectPath + '/', '');
|
|
550
|
+
// Error handling pattern
|
|
551
|
+
if (/try\s*\{[\s\S]*catch\s*\([\s\S]*\)\s*\{[\s\S]*\}/.test(content) &&
|
|
552
|
+
!content.includes('catch () {}') && // Not empty catch
|
|
553
|
+
content.includes('throw') || content.includes('error')) {
|
|
554
|
+
patterns.push({
|
|
555
|
+
name: 'Proper Error Handling',
|
|
556
|
+
type: 'golden',
|
|
557
|
+
file: relativePath,
|
|
558
|
+
line: 1,
|
|
559
|
+
description: 'Uses try-catch with proper error propagation',
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
// Type safety pattern
|
|
563
|
+
if (file.endsWith('.ts') && /:\s*\w+[\[\]<>]/.test(content)) {
|
|
564
|
+
patterns.push({
|
|
565
|
+
name: 'Type Safety',
|
|
566
|
+
type: 'golden',
|
|
567
|
+
file: relativePath,
|
|
568
|
+
line: 1,
|
|
569
|
+
description: 'Uses TypeScript type annotations',
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
catch {
|
|
574
|
+
// Ignore
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return patterns;
|
|
578
|
+
}
|
|
579
|
+
async generateAntipatterns() {
|
|
580
|
+
const antipatterns = [];
|
|
581
|
+
const codeFiles = await this.findCodeFiles(['.ts', '.tsx', '.js', '.jsx']);
|
|
582
|
+
for (const file of codeFiles) {
|
|
583
|
+
try {
|
|
584
|
+
const content = (0, fs_1.readFileSync)(file, 'utf-8');
|
|
585
|
+
const relativePath = file.replace(this.projectPath + '/', '');
|
|
586
|
+
const lines = content.split('\n');
|
|
587
|
+
lines.forEach((line, index) => {
|
|
588
|
+
// Empty catch
|
|
589
|
+
if (/catch\s*\([^)]*\)\s*\{\s*\}/.test(line)) {
|
|
590
|
+
antipatterns.push({
|
|
591
|
+
name: 'Empty Catch Block',
|
|
592
|
+
type: 'antipattern',
|
|
593
|
+
file: relativePath,
|
|
594
|
+
line: index + 1,
|
|
595
|
+
description: 'Swallows errors silently',
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
// Console.log in production
|
|
599
|
+
if (/console\.(log|error|warn)/.test(line) && !file.includes('test')) {
|
|
600
|
+
antipatterns.push({
|
|
601
|
+
name: 'Console in Production',
|
|
602
|
+
type: 'antipattern',
|
|
603
|
+
file: relativePath,
|
|
604
|
+
line: index + 1,
|
|
605
|
+
description: 'Console statements should use proper logging',
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
// Any types
|
|
609
|
+
if (/: any/.test(line)) {
|
|
610
|
+
antipatterns.push({
|
|
611
|
+
name: 'Any Type Usage',
|
|
612
|
+
type: 'antipattern',
|
|
613
|
+
file: relativePath,
|
|
614
|
+
line: index + 1,
|
|
615
|
+
description: 'Avoid any types for type safety',
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
catch {
|
|
621
|
+
// Ignore
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return antipatterns;
|
|
625
|
+
}
|
|
626
|
+
async generateVulnerabilities() {
|
|
627
|
+
const vulnerabilities = [];
|
|
628
|
+
// Check dependencies for known vulnerabilities
|
|
629
|
+
const deps = await this.generateDependencies();
|
|
630
|
+
// TODO: Integrate with OSV API or vulnerability database
|
|
631
|
+
// For now, check for known vulnerable packages
|
|
632
|
+
const knownVulnerable = [
|
|
633
|
+
'lodash@4.17.20', // Example
|
|
634
|
+
];
|
|
635
|
+
deps.forEach(dep => {
|
|
636
|
+
const depKey = `${dep.name}@${dep.version}`;
|
|
637
|
+
if (knownVulnerable.some(v => depKey.includes(v))) {
|
|
638
|
+
vulnerabilities.push({
|
|
639
|
+
package: dep.name,
|
|
640
|
+
version: dep.version,
|
|
641
|
+
severity: 'high',
|
|
642
|
+
description: 'Known vulnerability',
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
return vulnerabilities;
|
|
647
|
+
}
|
|
648
|
+
generateMetadata() {
|
|
649
|
+
let fileCount = 0;
|
|
650
|
+
let lineCount = 0;
|
|
651
|
+
let totalSize = 0;
|
|
652
|
+
const countFiles = (dir, depth = 0) => {
|
|
653
|
+
if (depth > 10)
|
|
654
|
+
return;
|
|
655
|
+
try {
|
|
656
|
+
const entries = (0, fs_1.readdirSync)(dir);
|
|
657
|
+
for (const entry of entries) {
|
|
658
|
+
const fullPath = (0, path_1.join)(dir, entry);
|
|
659
|
+
const stat = (0, fs_1.statSync)(fullPath);
|
|
660
|
+
if (stat.isDirectory()) {
|
|
661
|
+
if (!['node_modules', '.git', 'dist', 'build', '.next'].some(e => entry.includes(e))) {
|
|
662
|
+
countFiles(fullPath, depth + 1);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
else if (stat.isFile()) {
|
|
666
|
+
fileCount++;
|
|
667
|
+
totalSize += stat.size;
|
|
668
|
+
// Count lines for code files
|
|
669
|
+
if (['.ts', '.tsx', '.js', '.jsx', '.py', '.java'].includes((0, path_1.extname)(entry))) {
|
|
670
|
+
try {
|
|
671
|
+
const content = (0, fs_1.readFileSync)(fullPath, 'utf-8');
|
|
672
|
+
lineCount += content.split('\n').length;
|
|
673
|
+
}
|
|
674
|
+
catch {
|
|
675
|
+
// Ignore
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
catch {
|
|
682
|
+
// Ignore errors
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
countFiles(this.projectPath);
|
|
686
|
+
return {
|
|
687
|
+
fileCount,
|
|
688
|
+
lineCount,
|
|
689
|
+
totalSize,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
exports.TruthPackGenerator = TruthPackGenerator;
|
|
694
|
+
//# sourceMappingURL=index.js.map
|