#!/usr/bin/env node import { createRequire } from "module"; import { checkForUpdate } from "./utils/update-check.js"; const require = createRequire(import.meta.url); const pkg = require("../package.json") as { version: string }; // Fire-and-forget update notification (writes to stderr if newer version exists). // Skipped when GUARDVIBE_NO_UPDATE_CHECK=1, NO_UPDATE_NOTIFIER=1, or CI=true. checkForUpdate(pkg.version); // ── Scan entry point detection ────────────────────────────────────── const SCAN_SCRIPT_DETECTED = process.argv[1]?.endsWith("guardvibe-scan") || process.argv[1]?.endsWith("guardvibe-scan.js"); if (SCAN_SCRIPT_DETECTED) { const scanArgs = process.argv.slice(2); if (scanArgs.includes("--version") || scanArgs.includes("-V")) { console.log(pkg.version); } else if (scanArgs.includes("--help") || scanArgs.includes("-h")) { printUsage(); } else { const { runScan } = await import("./cli/scan.js"); await runScan(); } } else { await main(); } // ── Help ──────────────────────────────────────────────────────────── function printUsage(): void { console.log(` GuardVibe Security - CLI Commands: npx guardvibe scan [path] Scan a directory for security issues npx guardvibe diff [base] Scan changed files; reports only newly-introduced issues (--all-lines for whole files) npx guardvibe check Scan a single file for security issues npx guardvibe doctor [path] Run host security audit npx guardvibe audit [path] Full security audit with PASS/FAIL verdict npx guardvibe explain Get detailed remediation guidance for a rule npx guardvibe fix Get security fix suggestions for a file npx guardvibe secure-this Scan, apply verified fixes, re-verify (--write to apply) npx guardvibe check-cmd "" Check if a shell command is safe to execute npx guardvibe auth-coverage [path] Auth coverage analysis (Next.js routes) npx guardvibe compliance [path] Compliance report (--framework SOC2|GDPR|...) npx guardvibe deep-scan LLM-powered deep scan (IDOR, business logic, race conditions) npx guardvibe slopscan [path] Detect AI-hallucinated / slopsquatted packages (--offline = deterministic-only) npx guardvibe init Setup MCP server configuration npx guardvibe hook install Install pre-commit security hook npx guardvibe hook uninstall Remove pre-commit security hook npx guardvibe ci github [--pr] Generate GitHub Actions workflow (--pr: diff-aware PR review with inline comments) Scan CLI (used by pre-commit hook and CI): npx guardvibe-scan Scan git-staged files npx guardvibe-scan --format sarif --output results.sarif Options: --format Output format: markdown (default), json, sarif, buddy, agent agent = guardvibe.agent.v1 (finding + exact edit + confidence + verify) --output Write results to file instead of stdout --fail-on Exit 1 when findings at this level or above exist critical (default) | high | medium | low | none --baseline Compare against a previous scan JSON for fix tracking --save-baseline Save current scan as baseline (.guardvibe-baseline.json) --all-lines (diff) Report all findings in changed files, not just newly-added lines --version, -V Print version and exit --help, -h Show this help message Doctor Options: --scope project (default) | host | full project: only project config files host: + shell profiles, global MCP configs full: + home dir configs, npm global MCP Platforms: claude Claude Code (.claude.json + CLAUDE.md + hooks) cursor Cursor (.cursor/mcp.json + .cursorrules) gemini Gemini CLI (~/.gemini/settings.json + GEMINI.md) all All platforms at once Supported File Types: .js .jsx .mjs .cjs .ts .tsx .mts .cts .py .go .html .sql .sh .bash .yml .yaml .tf .toml .json Dockerfile Examples: npx guardvibe scan . npx guardvibe scan ./src --format json npx guardvibe doctor npx guardvibe doctor --scope host npx guardvibe doctor --scope full --format json npx guardvibe check src/app/api/route.ts npx guardvibe init claude npx guardvibe hook install npx guardvibe ci github `); } // ── Main dispatcher ───────────────────────────────────────────────── async function main(): Promise { const args = process.argv.slice(2); if (args.includes("--version") || args.includes("-V")) { console.log(pkg.version); process.exit(0); } if (args[0] === "--help" || args[0] === "-h") { printUsage(); process.exit(0); } // No args: if stdin is a pipe, start MCP server; if TTY, show help if (args.length === 0) { if (process.stdin.isTTY) { printUsage(); process.exit(0); } else { const { startMcpServer } = await import("./index.js"); await startMcpServer(); return; } } const command = args[0]; const subArgs = args.slice(1); if (command === "init") { const { runInit } = await import("./cli/init.js"); runInit(subArgs); } else if (command === "hook") { const { runHook } = await import("./cli/hook.js"); runHook(subArgs); } else if (command === "scan") { const { handleScanCommand } = await import("./cli/scan.js"); await handleScanCommand(subArgs); } else if (command === "diff") { const { handleDiffCommand } = await import("./cli/scan.js"); await handleDiffCommand(subArgs); } else if (command === "check") { const { handleCheckCommand } = await import("./cli/scan.js"); await handleCheckCommand(subArgs); } else if (command === "ci") { const { runCi } = await import("./cli/ci.js"); runCi(subArgs); } else if (command === "doctor") { const { runDoctor } = await import("./cli/doctor.js"); await runDoctor(subArgs); } else if (command === "audit") { const { runAudit } = await import("./cli/audit.js"); await runAudit(subArgs); } else if (command === "explain") { const { runExplain } = await import("./cli/explain.js"); await runExplain(subArgs); } else if (command === "fix") { const { runFix } = await import("./cli/fix.js"); await runFix(subArgs); } else if (command === "secure-this" || command === "secure_this") { const { runSecureThis } = await import("./cli/secure-this.js"); await runSecureThis(subArgs); } else if (command === "check-cmd") { const { runCheckCmd } = await import("./cli/check-cmd.js"); await runCheckCmd(subArgs); } else if (command === "auth-coverage") { const { runAuthCoverage } = await import("./cli/auth-coverage.js"); await runAuthCoverage(subArgs); } else if (command === "compliance") { const { runCompliance } = await import("./cli/compliance.js"); await runCompliance(subArgs); } else if (command === "deep-scan") { const { runDeepScan } = await import("./cli/deep-scan.js"); await runDeepScan(subArgs); } else if (command === "slopscan") { const { runSlopscan } = await import("./cli/slopscan.js"); await runSlopscan(subArgs); } else { console.error(` Unknown command: ${command}`); printUsage(); process.exit(1); } }