rulecloud 0.0.0-stage → 0.1.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/README.md +44 -2
- package/dist/api.d.ts +30 -0
- package/dist/api.js +74 -0
- package/dist/autofix.d.ts +14 -0
- package/dist/autofix.js +159 -0
- package/dist/commands/check.d.ts +1 -0
- package/dist/commands/check.js +65 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +52 -0
- package/dist/commands/watch.d.ts +6 -0
- package/dist/commands/watch.js +257 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +67 -0
- package/dist/eval.d.ts +17 -0
- package/dist/eval.js +159 -0
- package/dist/exclusions.d.ts +4 -0
- package/dist/exclusions.js +50 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +63 -0
- package/dist/hud.d.ts +14 -0
- package/dist/hud.js +63 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +60 -0
- package/dist/rules-config.d.ts +10 -0
- package/dist/rules-config.js +33 -0
- package/dist/severity.d.ts +13 -0
- package/dist/severity.js +48 -0
- package/dist/walk.d.ts +1 -0
- package/dist/walk.js +52 -0
- package/package.json +43 -3
package/dist/hud.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { formatHudStatus, severityLabel, summarizeFindings } from "./severity.js";
|
|
3
|
+
function c(enabled, fn, s) {
|
|
4
|
+
return enabled ? fn(s) : s;
|
|
5
|
+
}
|
|
6
|
+
function timeStamp() {
|
|
7
|
+
const d = new Date();
|
|
8
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
9
|
+
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
|
|
10
|
+
}
|
|
11
|
+
export function printRulesWarning(reason, plain) {
|
|
12
|
+
const line = `⚠ ${reason}`;
|
|
13
|
+
console.log(plain ? line : pc.yellow(line));
|
|
14
|
+
}
|
|
15
|
+
export function printHeader(opts) {
|
|
16
|
+
const { plain, cloud, ruleCount, configLabel, findings } = opts;
|
|
17
|
+
const cloudLabel = cloud ? "ON" : "OFF";
|
|
18
|
+
const summary = summarizeFindings(findings);
|
|
19
|
+
const statusText = formatHudStatus(summary, plain);
|
|
20
|
+
const status = summary.kind === "pass"
|
|
21
|
+
? c(plain, pc.green, statusText)
|
|
22
|
+
: summary.kind === "blocked"
|
|
23
|
+
? c(plain, pc.red, statusText)
|
|
24
|
+
: c(plain, pc.yellow, statusText);
|
|
25
|
+
const bar = [
|
|
26
|
+
c(plain, pc.bold, "RuleCloud Watch"),
|
|
27
|
+
`Rules: ${ruleCount} loaded (${configLabel})`,
|
|
28
|
+
`Cloud Sync: ${cloudLabel}`,
|
|
29
|
+
`Status: ${status}`,
|
|
30
|
+
].join(" · ");
|
|
31
|
+
console.log(bar);
|
|
32
|
+
if (!plain && process.stdin.isTTY) {
|
|
33
|
+
console.log(pc.dim("r rescan · f ai-fix · c clear · q quit"));
|
|
34
|
+
}
|
|
35
|
+
console.log("");
|
|
36
|
+
}
|
|
37
|
+
export function printScanLine(rel, durationMs, count, plain) {
|
|
38
|
+
const ts = `[${timeStamp()}]`;
|
|
39
|
+
if (count === 0) {
|
|
40
|
+
console.log(`${ts} Scanned ${rel} (${durationMs}ms) — ${c(plain, pc.green, "✓ clean")}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const n = count === 1 ? "1 violation" : `${count} violations`;
|
|
44
|
+
console.log(`${ts} Scanned ${rel} (${durationMs}ms) — ${c(plain, pc.yellow, n)}`);
|
|
45
|
+
}
|
|
46
|
+
export function printFinding(f, plain) {
|
|
47
|
+
const label = severityLabel(f.severity);
|
|
48
|
+
const loc = `${f.file}:${f.line}`;
|
|
49
|
+
const color = label === "ERROR" ? pc.red : label === "WARN" ? pc.yellow : pc.dim;
|
|
50
|
+
const head = c(plain, color, ` ✖ [${label}] ${loc} ${f.id}`);
|
|
51
|
+
console.log(head);
|
|
52
|
+
console.log(c(plain, pc.dim, ` └─ ${f.message}`));
|
|
53
|
+
}
|
|
54
|
+
export function printStatusLine(findings, plain) {
|
|
55
|
+
const summary = summarizeFindings(findings);
|
|
56
|
+
const statusText = formatHudStatus(summary, plain);
|
|
57
|
+
const colored = summary.kind === "pass"
|
|
58
|
+
? c(plain, pc.green, statusText)
|
|
59
|
+
: summary.kind === "blocked"
|
|
60
|
+
? c(plain, pc.red, statusText)
|
|
61
|
+
: c(plain, pc.yellow, statusText);
|
|
62
|
+
console.log(c(plain, pc.dim, `Status: ${colored}`));
|
|
63
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { runInit } from "./commands/init.js";
|
|
4
|
+
import { runCheck } from "./commands/check.js";
|
|
5
|
+
import { runFixCommand } from "./autofix.js";
|
|
6
|
+
import { runWatch } from "./commands/watch.js";
|
|
7
|
+
import { loadConfig } from "./config.js";
|
|
8
|
+
function usage() {
|
|
9
|
+
console.log(`RuleCloud CLI — real-time AI agent guardrails
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
rulecloud init Pull Cloud Rulespacks + configure Cursor
|
|
13
|
+
rulecloud watch [--cloud] [--plain] [dir] Live HUD
|
|
14
|
+
rulecloud check [--staged] [--plain] [dir] One-shot scan
|
|
15
|
+
rulecloud fix [file] AI Auto-Fix via API (Pro)
|
|
16
|
+
|
|
17
|
+
Environment:
|
|
18
|
+
RULECLOUD_API_URL API base (default: production)
|
|
19
|
+
RULECLOUD_API_KEY Workspace API key (rc_live_...)
|
|
20
|
+
`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const argv = process.argv.slice(2);
|
|
24
|
+
const cmd = argv[0];
|
|
25
|
+
const positional = argv.slice(1).filter((a) => !a.startsWith("-"));
|
|
26
|
+
const cwd = (cmd === "check" || cmd === "watch") && positional[0]
|
|
27
|
+
? path.resolve(positional[0])
|
|
28
|
+
: process.cwd();
|
|
29
|
+
const fixFile = cmd === "fix" ? positional[0] : undefined;
|
|
30
|
+
if (!cmd || cmd === "-h" || cmd === "--help")
|
|
31
|
+
usage();
|
|
32
|
+
const cfg = loadConfig(cwd);
|
|
33
|
+
try {
|
|
34
|
+
if (cmd === "init") {
|
|
35
|
+
await runInit(cwd, cfg);
|
|
36
|
+
}
|
|
37
|
+
else if (cmd === "watch") {
|
|
38
|
+
const plain = argv.includes("--plain") || !process.stdout.isTTY;
|
|
39
|
+
const cloud = !argv.includes("--no-cloud") &&
|
|
40
|
+
(Boolean(cfg.apiKey) || argv.includes("--cloud"));
|
|
41
|
+
await runWatch(cwd, cfg, { cloud, plain });
|
|
42
|
+
}
|
|
43
|
+
else if (cmd === "fix") {
|
|
44
|
+
const plain = argv.includes("--plain");
|
|
45
|
+
await runFixCommand(cwd, cfg, fixFile, plain);
|
|
46
|
+
}
|
|
47
|
+
else if (cmd === "check") {
|
|
48
|
+
const staged = argv.includes("--staged");
|
|
49
|
+
const plain = argv.includes("--plain");
|
|
50
|
+
const code = runCheck(cwd, staged, plain);
|
|
51
|
+
process.exit(code);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
usage();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RuleDoc } from "./eval.js";
|
|
2
|
+
export type LoadedRules = {
|
|
3
|
+
configPath: string;
|
|
4
|
+
configLabel: string;
|
|
5
|
+
rulesText: string;
|
|
6
|
+
doc: RuleDoc;
|
|
7
|
+
ruleCount: number;
|
|
8
|
+
warnReason?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function loadRulesFromRepo(cwd: string): LoadedRules;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parseRulesYaml } from "./eval.js";
|
|
4
|
+
const CANDIDATES = [".guardrail.yml", "guardrail.yaml", "guardrail.yml"];
|
|
5
|
+
export function loadRulesFromRepo(cwd) {
|
|
6
|
+
for (const name of CANDIDATES) {
|
|
7
|
+
const configPath = path.join(cwd, name);
|
|
8
|
+
try {
|
|
9
|
+
const rulesText = readFileSync(configPath, "utf8");
|
|
10
|
+
const doc = parseRulesYaml(rulesText);
|
|
11
|
+
const ruleCount = doc.rules.length;
|
|
12
|
+
let warnReason;
|
|
13
|
+
if (ruleCount === 0) {
|
|
14
|
+
warnReason =
|
|
15
|
+
"Rules file parsed but the rules array is empty — no checks will run.";
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
configPath,
|
|
19
|
+
configLabel: name,
|
|
20
|
+
rulesText,
|
|
21
|
+
doc,
|
|
22
|
+
ruleCount,
|
|
23
|
+
warnReason,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err.code === "ENOENT")
|
|
28
|
+
continue;
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`No guardrail config found in ${cwd} (tried ${CANDIDATES.join(", ")}) — run rulecloud init`);
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Finding } from "./eval.js";
|
|
2
|
+
export type SeverityTier = "error" | "warn" | "info";
|
|
3
|
+
export declare function severityTier(sev: string): SeverityTier;
|
|
4
|
+
export declare function severityLabel(sev: string): string;
|
|
5
|
+
export type StatusSummary = {
|
|
6
|
+
kind: "pass" | "blocked" | "warnings";
|
|
7
|
+
errorCount: number;
|
|
8
|
+
warnCount: number;
|
|
9
|
+
total: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function summarizeFindings(findings: Finding[]): StatusSummary;
|
|
12
|
+
export declare function formatHudStatus(summary: StatusSummary, plain: boolean): string;
|
|
13
|
+
export declare function hasBlocking(findings: Finding[]): boolean;
|
package/dist/severity.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function severityTier(sev) {
|
|
2
|
+
const s = sev.toLowerCase();
|
|
3
|
+
if (s === "error" || s.includes("crit"))
|
|
4
|
+
return "error";
|
|
5
|
+
if (s === "high")
|
|
6
|
+
return "error";
|
|
7
|
+
return s === "medium" || s.includes("warn") ? "warn" : "info";
|
|
8
|
+
}
|
|
9
|
+
export function severityLabel(sev) {
|
|
10
|
+
const t = severityTier(sev);
|
|
11
|
+
if (t === "error")
|
|
12
|
+
return "ERROR";
|
|
13
|
+
if (t === "warn")
|
|
14
|
+
return "WARN";
|
|
15
|
+
return "INFO";
|
|
16
|
+
}
|
|
17
|
+
export function summarizeFindings(findings) {
|
|
18
|
+
let errorCount = 0;
|
|
19
|
+
let warnCount = 0;
|
|
20
|
+
for (const f of findings) {
|
|
21
|
+
const t = severityTier(f.severity);
|
|
22
|
+
if (t === "error")
|
|
23
|
+
errorCount += 1;
|
|
24
|
+
else
|
|
25
|
+
warnCount += 1;
|
|
26
|
+
}
|
|
27
|
+
const total = findings.length;
|
|
28
|
+
let kind = "pass";
|
|
29
|
+
if (errorCount > 0)
|
|
30
|
+
kind = "blocked";
|
|
31
|
+
else if (total > 0)
|
|
32
|
+
kind = "warnings";
|
|
33
|
+
return { kind, errorCount, warnCount, total };
|
|
34
|
+
}
|
|
35
|
+
export function formatHudStatus(summary, plain) {
|
|
36
|
+
if (summary.kind === "pass")
|
|
37
|
+
return plain ? "PASS (0)" : "PASS (0)";
|
|
38
|
+
if (summary.kind === "blocked") {
|
|
39
|
+
const n = summary.errorCount;
|
|
40
|
+
const label = n === 1 ? "1 error" : `${n} errors`;
|
|
41
|
+
return `BLOCKED (${label})`;
|
|
42
|
+
}
|
|
43
|
+
const n = summary.total;
|
|
44
|
+
return n === 1 ? "WARNINGS (1)" : `WARNINGS (${n})`;
|
|
45
|
+
}
|
|
46
|
+
export function hasBlocking(findings) {
|
|
47
|
+
return findings.some((f) => severityTier(f.severity) === "error");
|
|
48
|
+
}
|
package/dist/walk.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function walkSourceFiles(root: string, base?: string): string[];
|
package/dist/walk.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readdirSync, statSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { shouldIgnorePath } from "./eval.js";
|
|
4
|
+
const SCANNABLE_EXT = new Set([
|
|
5
|
+
".ts",
|
|
6
|
+
".tsx",
|
|
7
|
+
".js",
|
|
8
|
+
".jsx",
|
|
9
|
+
".py",
|
|
10
|
+
".cs",
|
|
11
|
+
".go",
|
|
12
|
+
".java",
|
|
13
|
+
".rb",
|
|
14
|
+
".php",
|
|
15
|
+
".rs",
|
|
16
|
+
".md",
|
|
17
|
+
".json",
|
|
18
|
+
".yaml",
|
|
19
|
+
".yml",
|
|
20
|
+
]);
|
|
21
|
+
export function walkSourceFiles(root, base = root) {
|
|
22
|
+
const out = [];
|
|
23
|
+
let entries;
|
|
24
|
+
try {
|
|
25
|
+
entries = readdirSync(root);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
for (const name of entries) {
|
|
31
|
+
const abs = path.join(root, name);
|
|
32
|
+
if (shouldIgnorePath(abs, base))
|
|
33
|
+
continue;
|
|
34
|
+
let st;
|
|
35
|
+
try {
|
|
36
|
+
st = statSync(abs);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (st.isDirectory()) {
|
|
42
|
+
out.push(...walkSourceFiles(abs, base));
|
|
43
|
+
}
|
|
44
|
+
else if (st.isFile()) {
|
|
45
|
+
const ext = path.extname(name).toLowerCase();
|
|
46
|
+
if (!ext || SCANNABLE_EXT.has(ext)) {
|
|
47
|
+
out.push(abs);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rulecloud",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Real-time RuleCloud guardrails for AI coding agents",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rulecloud",
|
|
7
|
+
"guardrails",
|
|
8
|
+
"cursor",
|
|
9
|
+
"ai",
|
|
10
|
+
"lint",
|
|
11
|
+
"mcp"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://rulecloud.vercel.app",
|
|
14
|
+
"bugs": "https://github.com/lemonbanan4/rulecloud/issues",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/lemonbanan4/rulecloud.git",
|
|
18
|
+
"directory": "cli"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"rulecloud": "dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc && chmod +x dist/index.js",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"chokidar": "^4.0.3",
|
|
33
|
+
"js-yaml": "^4.1.0",
|
|
34
|
+
"picocolors": "^1.1.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/js-yaml": "^4.0.9",
|
|
38
|
+
"@types/node": "^22.10.0",
|
|
39
|
+
"typescript": "^5.7.2"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
45
|
+
"license": "MIT"
|
|
6
46
|
}
|