Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
74 lines (61 loc) · 2.1 KB
/
Copy pathcli.js
File metadata and controls
74 lines (61 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
// cli.js
const fs = require("fs");
const path = require("path");
const chalk = require("chalk");
const { runDetector } = require("./engine");
const args = process.argv.slice(2);
const command = args[0];
const target = args[1];
const runFull = args.includes("--full"); // browser + LLM rules bhi chalao
if (command !== "detect" || !target) {
console.log("Usage: node cli.js detect <file.html> [--full]");
process.exit(1);
}
if (!fs.existsSync(target)) {
console.error(chalk.red(`File not found: ${target}`));
process.exit(1);
}
const html = fs.readFileSync(target, "utf-8");
const results = runDetector(html);
async function runExtras() {
if (!runFull) return;
console.log(chalk.cyan("\nRunning browser-based rules (Puppeteer)..."));
const { runBrowserRules } = require("./browser-rules");
const browserFindings = await runBrowserRules(html, false);
for (const f of browserFindings) {
console.log(chalk.red(`✗ [browser] ${f.rule}`));
console.log(chalk.gray(` ${f.message}`));
}
console.log(chalk.cyan("\nRunning LLM-based rules (needs ANTHROPIC_API_KEY)..."));
try {
const { runLlmRules } = require("./llm-rules");
const llmFindings = await runLlmRules(html, false);
for (const f of llmFindings) {
console.log(chalk.red(`✗ [llm] ${f.rule}`));
console.log(chalk.gray(` ${f.message}`));
}
} catch (e) {
console.log(chalk.yellow(` Skipped: ${e.message}`));
}
}
const flagged = results.filter((r) => r.status === "flagged");
const skipped = results.filter((r) => r.status === "skipped");
const clean = results.filter((r) => r.status === "clean");
console.log(chalk.bold(`\nScanning ${target}...\n`));
if (flagged.length === 0) {
console.log(chalk.green("No AI-slop patterns detected. 🎉"));
} else {
for (const r of flagged) {
console.log(chalk.red(`✗ [${r.category}] ${r.id}`));
for (const f of r.findings) {
console.log(chalk.gray(` ${f.message}`));
}
}
}
console.log(
chalk.bold(
`\n${flagged.length} flagged, ${clean.length} clean, ${skipped.length} skipped (LLM/browser-only rules)\n`
)
);
runExtras();