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.
@@ -0,0 +1,257 @@
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import readline from "node:readline";
4
+ import pc from "picocolors";
5
+ import chokidar from "chokidar";
6
+ import { runAutofixForFile } from "../autofix.js";
7
+ import { postWatchEvent } from "../api.js";
8
+ import { evaluateFile } from "../eval.js";
9
+ import { printFinding, printHeader, printRulesWarning, printScanLine, printStatusLine, } from "../hud.js";
10
+ import { loadRulesFromRepo } from "../rules-config.js";
11
+ import { walkSourceFiles } from "../walk.js";
12
+ function readFileContent(absPath) {
13
+ try {
14
+ return readFileSync(absPath, "utf8");
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ export async function runWatch(cwd, cfg, opts) {
21
+ const loaded = loadRulesFromRepo(cwd);
22
+ const doc = loaded.doc;
23
+ const debounce = new Map();
24
+ const allByKey = new Map();
25
+ let lastRel = null;
26
+ let lastAbs = null;
27
+ let lastFindings = [];
28
+ const cloudOn = opts.cloud && Boolean(cfg.apiKey);
29
+ const allFindings = () => [...allByKey.values()];
30
+ const hudArgs = () => ({
31
+ plain: opts.plain,
32
+ cloud: cloudOn,
33
+ ruleCount: loaded.ruleCount,
34
+ configLabel: loaded.configLabel,
35
+ findings: allFindings(),
36
+ });
37
+ const syncCloud = (rel, findings, duration_ms) => {
38
+ if (!cloudOn || !findings.length)
39
+ return;
40
+ void postWatchEvent(cfg, {
41
+ file: rel,
42
+ findings: findings,
43
+ duration_ms,
44
+ repo_label: path.basename(cwd),
45
+ }).catch((err) => {
46
+ if (!opts.plain)
47
+ console.log(pc.dim(`cloud sync: ${err.message}`));
48
+ });
49
+ };
50
+ const mergeFindings = (rel, findings) => {
51
+ for (const [key, f] of [...allByKey.entries()]) {
52
+ if (f.file === rel)
53
+ allByKey.delete(key);
54
+ }
55
+ for (const f of findings) {
56
+ allByKey.set(`${f.id}:${f.file}:${f.line}`, f);
57
+ }
58
+ };
59
+ const renderViolations = (findings) => {
60
+ for (const f of findings) {
61
+ printFinding(f, opts.plain);
62
+ }
63
+ };
64
+ const scanFile = (absPath) => {
65
+ const rel = path.relative(cwd, absPath).replace(/\\/g, "/");
66
+ const content = readFileContent(absPath);
67
+ if (content === null)
68
+ return;
69
+ const start = Date.now();
70
+ const findings = evaluateFile(rel, content, doc);
71
+ const duration_ms = Date.now() - start;
72
+ mergeFindings(rel, findings);
73
+ lastRel = rel;
74
+ lastAbs = absPath;
75
+ lastFindings = findings;
76
+ printScanLine(rel, duration_ms, findings.length, opts.plain);
77
+ if (findings.length)
78
+ renderViolations(findings);
79
+ syncCloud(rel, findings, duration_ms);
80
+ printStatusLine(allFindings(), opts.plain);
81
+ };
82
+ const rescanAll = () => {
83
+ if (!opts.plain)
84
+ console.clear();
85
+ console.log(opts.plain
86
+ ? `Loaded ${loaded.configLabel} (${loaded.ruleCount} rules)`
87
+ : pc.cyan(`Loaded ${loaded.configLabel} (${loaded.ruleCount} rules)`));
88
+ allByKey.clear();
89
+ const files = walkSourceFiles(cwd);
90
+ let filesWithIssues = 0;
91
+ for (const abs of files) {
92
+ const rel = path.relative(cwd, abs).replace(/\\/g, "/");
93
+ const content = readFileContent(abs);
94
+ if (content === null)
95
+ continue;
96
+ const start = Date.now();
97
+ const findings = evaluateFile(rel, content, doc);
98
+ const duration_ms = Date.now() - start;
99
+ mergeFindings(rel, findings);
100
+ if (findings.length) {
101
+ filesWithIssues += 1;
102
+ printScanLine(rel, duration_ms, findings.length, opts.plain);
103
+ renderViolations(findings);
104
+ if (!lastRel) {
105
+ lastRel = rel;
106
+ lastAbs = abs;
107
+ lastFindings = findings;
108
+ }
109
+ }
110
+ }
111
+ if (filesWithIssues === 0) {
112
+ console.log(opts.plain
113
+ ? "Initial scan: all files clean"
114
+ : pc.green("Initial scan: all files clean"));
115
+ }
116
+ printHeader(hudArgs());
117
+ if (!opts.plain) {
118
+ console.log(pc.dim(`Watching ${files.length} files under ${cwd} (awaitWriteFinish 200ms)…`));
119
+ }
120
+ else {
121
+ console.log(`Watching ${files.length} files…`);
122
+ }
123
+ };
124
+ const runFix = async () => {
125
+ if (!lastAbs || !lastRel) {
126
+ console.log(opts.plain
127
+ ? "No recent file — save a file or press r to rescan first"
128
+ : pc.yellow("No recent file — save a file or press r to rescan first"));
129
+ return;
130
+ }
131
+ const content = readFileContent(lastAbs);
132
+ if (content === null)
133
+ return;
134
+ if (process.stdin.isTTY) {
135
+ try {
136
+ process.stdin.setRawMode(false);
137
+ }
138
+ catch {
139
+ /* noop */
140
+ }
141
+ }
142
+ const targets = lastFindings.length > 0
143
+ ? lastFindings
144
+ : evaluateFile(lastRel, content, doc);
145
+ try {
146
+ await runAutofixForFile({
147
+ cwd,
148
+ cfg,
149
+ relPath: lastRel,
150
+ absPath: lastAbs,
151
+ code: content,
152
+ findings: targets,
153
+ rulesYaml: loaded.rulesText,
154
+ plain: opts.plain,
155
+ interactive: true,
156
+ });
157
+ }
158
+ catch (err) {
159
+ const message = err instanceof Error ? err.message : "Auto-fix failed";
160
+ console.log(opts.plain
161
+ ? `✖ Auto-fix unavailable: ${message}`
162
+ : pc.red(`✖ Auto-fix unavailable: ${message}`));
163
+ }
164
+ finally {
165
+ if (process.stdin.isTTY && !opts.plain) {
166
+ readline.emitKeypressEvents(process.stdin);
167
+ process.stdin.setRawMode(true);
168
+ process.stdin.resume();
169
+ }
170
+ }
171
+ scanFile(lastAbs);
172
+ };
173
+ console.log(opts.plain
174
+ ? `Config: ${loaded.configLabel}`
175
+ : pc.bold(`Config: ${pc.white(loaded.configLabel)}`));
176
+ console.log(`Rules: ${loaded.ruleCount} active`);
177
+ if (loaded.warnReason) {
178
+ printRulesWarning(loaded.warnReason, opts.plain);
179
+ }
180
+ rescanAll();
181
+ const schedule = (absPath) => {
182
+ const prev = debounce.get(absPath);
183
+ if (prev)
184
+ clearTimeout(prev);
185
+ debounce.set(absPath, setTimeout(() => {
186
+ debounce.delete(absPath);
187
+ scanFile(absPath);
188
+ }, 200));
189
+ };
190
+ const watcher = chokidar.watch(cwd, {
191
+ ignored: (watchPath) => {
192
+ if (watchPath === cwd)
193
+ return false;
194
+ return path
195
+ .relative(cwd, watchPath)
196
+ .split(path.sep)
197
+ .some((p) => [
198
+ "node_modules",
199
+ ".git",
200
+ ".next",
201
+ "dist",
202
+ ".cursor",
203
+ "venv",
204
+ ".venv",
205
+ ].includes(p));
206
+ },
207
+ ignoreInitial: true,
208
+ persistent: true,
209
+ awaitWriteFinish: {
210
+ stabilityThreshold: 200,
211
+ pollInterval: 50,
212
+ },
213
+ atomic: true,
214
+ depth: 99,
215
+ });
216
+ watcher.on("change", schedule);
217
+ watcher.on("add", schedule);
218
+ const stop = async () => {
219
+ await watcher.close();
220
+ for (const t of debounce.values())
221
+ clearTimeout(t);
222
+ if (process.stdin.isTTY && !opts.plain) {
223
+ try {
224
+ process.stdin.setRawMode(false);
225
+ }
226
+ catch {
227
+ /* noop */
228
+ }
229
+ }
230
+ process.exit(0);
231
+ };
232
+ process.on("SIGINT", () => {
233
+ void stop();
234
+ });
235
+ if (process.stdin.isTTY && !opts.plain) {
236
+ readline.emitKeypressEvents(process.stdin);
237
+ process.stdin.setRawMode(true);
238
+ process.stdin.resume();
239
+ process.stdin.on("keypress", (str, key) => {
240
+ if (key?.ctrl && key.name === "c") {
241
+ void stop();
242
+ return;
243
+ }
244
+ const ch = (str || "").toLowerCase();
245
+ if (ch === "q")
246
+ void stop();
247
+ else if (ch === "c") {
248
+ console.clear();
249
+ printHeader(hudArgs());
250
+ }
251
+ else if (ch === "r")
252
+ rescanAll();
253
+ else if (ch === "f")
254
+ void runFix();
255
+ });
256
+ }
257
+ }
@@ -0,0 +1,6 @@
1
+ export type CliConfig = {
2
+ apiUrl: string;
3
+ apiKey: string;
4
+ };
5
+ export declare function loadConfig(cwd?: string): CliConfig;
6
+ export declare function requireApiKey(cfg: CliConfig): string;
package/dist/config.js ADDED
@@ -0,0 +1,67 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+ const ENV_URL = "RULECLOUD_API_URL";
5
+ const ENV_KEY = "RULECLOUD_API_KEY";
6
+ const LOCAL_RC = path.join(homedir(), ".rulecloudrc");
7
+ function loadDotEnv(cwd) {
8
+ for (const name of [".env", ".env.local"]) {
9
+ const p = path.join(cwd, name);
10
+ if (!existsSync(p))
11
+ continue;
12
+ try {
13
+ const raw = readFileSync(p, "utf8");
14
+ for (const line of raw.split(/\r?\n/)) {
15
+ const trimmed = line.trim();
16
+ if (!trimmed || trimmed.startsWith("#"))
17
+ continue;
18
+ const url = trimmed.match(/^RULECLOUD_API_URL=(.+)$/);
19
+ if (url)
20
+ process.env[ENV_URL] = url[1].trim().replace(/^["']|["']$/g, "");
21
+ const key = trimmed.match(/^RULECLOUD_API_KEY=(.+)$/);
22
+ if (key)
23
+ process.env[ENV_KEY] = key[1].trim().replace(/^["']|["']$/g, "");
24
+ }
25
+ }
26
+ catch {
27
+ /* ignore */
28
+ }
29
+ }
30
+ }
31
+ function loadProjectJson(cwd) {
32
+ const p = path.join(cwd, ".rulecloud.json");
33
+ if (!existsSync(p))
34
+ return {};
35
+ try {
36
+ const data = JSON.parse(readFileSync(p, "utf8"));
37
+ return {
38
+ apiUrl: data.apiUrl,
39
+ apiKey: data.apiKey,
40
+ };
41
+ }
42
+ catch {
43
+ return {};
44
+ }
45
+ }
46
+ export function loadConfig(cwd = process.cwd()) {
47
+ loadDotEnv(cwd);
48
+ const project = loadProjectJson(cwd);
49
+ const apiUrl = (project.apiUrl ||
50
+ process.env[ENV_URL] ||
51
+ process.env.NEXT_PUBLIC_API_URL ||
52
+ "https://rulecloud-production.up.railway.app").replace(/\/$/, "");
53
+ let apiKey = (project.apiKey || process.env[ENV_KEY] || "").trim();
54
+ if (!apiKey && existsSync(LOCAL_RC)) {
55
+ const raw = readFileSync(LOCAL_RC, "utf8");
56
+ const m = raw.match(/^RULECLOUD_API_KEY=(.+)$/m);
57
+ if (m)
58
+ apiKey = m[1].trim();
59
+ }
60
+ return { apiUrl, apiKey };
61
+ }
62
+ export function requireApiKey(cfg) {
63
+ if (!cfg.apiKey) {
64
+ throw new Error(`Missing API key. Set ${ENV_KEY}, add .rulecloud.json, .env, or ${LOCAL_RC}`);
65
+ }
66
+ return cfg.apiKey;
67
+ }
package/dist/eval.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { hasBlocking } from "./severity.js";
2
+ export type Finding = {
3
+ id: string;
4
+ message: string;
5
+ file: string;
6
+ line: number;
7
+ severity: string;
8
+ };
9
+ export type RuleDoc = {
10
+ include: string[];
11
+ exclude: string[];
12
+ rules: Record<string, unknown>[];
13
+ };
14
+ export declare function parseRulesYaml(text: string): RuleDoc;
15
+ export declare function evaluateFile(relpath: string, content: string, doc: RuleDoc): Finding[];
16
+ export declare function shouldIgnorePath(absPath: string, root: string): boolean;
17
+ export { hasBlocking as hasCritical, hasBlocking };
package/dist/eval.js ADDED
@@ -0,0 +1,159 @@
1
+ import yaml from "js-yaml";
2
+ import path from "node:path";
3
+ import { shouldEvaluateSourceFile } from "./exclusions.js";
4
+ import { expandExtensionIncludes, matchAny } from "./glob.js";
5
+ import { hasBlocking } from "./severity.js";
6
+ const SKIP_DIRS = new Set([
7
+ "node_modules",
8
+ ".git",
9
+ ".next",
10
+ "dist",
11
+ "venv",
12
+ ".venv",
13
+ "build",
14
+ "target",
15
+ "__pycache__",
16
+ ".cursor",
17
+ ]);
18
+ function rulePatterns(rule, include) {
19
+ for (const key of ["match", "include", "files"]) {
20
+ const val = rule[key];
21
+ if (typeof val === "string" && val.trim())
22
+ return [val.trim()];
23
+ if (Array.isArray(val) && val.length)
24
+ return val.map(String);
25
+ }
26
+ return include;
27
+ }
28
+ export function parseRulesYaml(text) {
29
+ const data = yaml.load(text);
30
+ const include = Array.isArray(data?.include)
31
+ ? data.include.map(String)
32
+ : ["**/*"];
33
+ const extFromKey = expandExtensionIncludes(data?.extensions);
34
+ const extFromInclude = expandExtensionIncludes(data?.["include.extensions"]);
35
+ for (const g of [...extFromKey, ...extFromInclude]) {
36
+ if (!include.includes(g))
37
+ include.push(g);
38
+ }
39
+ const exclude = Array.isArray(data?.exclude) ? data.exclude.map(String) : [];
40
+ const rules = Array.isArray(data?.rules)
41
+ ? data.rules.filter((r) => r?.id)
42
+ : [];
43
+ return { include, exclude, rules };
44
+ }
45
+ function evalRegex(rule, relpath, lines, patterns) {
46
+ if (!matchAny(patterns, relpath))
47
+ return [];
48
+ const raw = (rule.pattern || rule.regex);
49
+ if (!raw)
50
+ return [];
51
+ let pat = String(raw);
52
+ let flags = "";
53
+ if (pat.startsWith("(?i)")) {
54
+ pat = pat.slice(4);
55
+ flags = "i";
56
+ }
57
+ let rx;
58
+ try {
59
+ rx = new RegExp(pat, flags);
60
+ }
61
+ catch {
62
+ return [];
63
+ }
64
+ const rid = String(rule.id);
65
+ const msg = String(rule.message || rule.description || rid);
66
+ const sev = String(rule.severity || "warning");
67
+ const out = [];
68
+ for (let i = 0; i < lines.length; i++) {
69
+ if (rx.test(lines[i])) {
70
+ out.push({ id: rid, message: msg, file: relpath, line: i + 1, severity: sev });
71
+ }
72
+ }
73
+ return out;
74
+ }
75
+ function evalLayer(rule, relpath, lines) {
76
+ const from = rule.from;
77
+ const to = rule.to;
78
+ if (!from || !to)
79
+ return [];
80
+ if (!matchAny([from], relpath))
81
+ return [];
82
+ const rid = String(rule.id);
83
+ const msg = String(rule.message || "Forbidden layer dependency");
84
+ const sev = String(rule.severity || "medium");
85
+ const toNorm = to.replace(/\\/g, "/");
86
+ const importRe = /^\s*(import|from|using)\s+/;
87
+ const out = [];
88
+ for (let i = 0; i < lines.length; i++) {
89
+ const line = lines[i];
90
+ if (!importRe.test(line))
91
+ continue;
92
+ const ln = line.replace(/\\/g, "/");
93
+ const dataLayer = /\/data\//.test(toNorm) &&
94
+ /(?:from|import)\s+['"][^'"]*(\.\.\/)+data\/|(?:from|import)\s+['"][^'"]*\/data\//.test(ln);
95
+ const segment = toNorm.replace(/\*\*/g, "").replace(/^\/+/, "");
96
+ if (dataLayer || (segment && ln.includes(segment))) {
97
+ out.push({ id: rid, message: msg, file: relpath, line: i + 1, severity: sev });
98
+ }
99
+ }
100
+ return out;
101
+ }
102
+ function evalMaxLines(rule, relpath, lines, patterns) {
103
+ const max = rule.max_lines;
104
+ if (max == null || !matchAny(patterns, relpath))
105
+ return [];
106
+ const limit = Number(max);
107
+ if (Number.isNaN(limit) || lines.length <= limit)
108
+ return [];
109
+ return [
110
+ {
111
+ id: String(rule.id),
112
+ message: String(rule.message || `File exceeds ${limit} lines (${lines.length})`),
113
+ file: relpath,
114
+ line: 1,
115
+ severity: String(rule.severity || "warning"),
116
+ },
117
+ ];
118
+ }
119
+ export function evaluateFile(relpath, content, doc) {
120
+ if (!shouldEvaluateSourceFile(relpath, doc.rules))
121
+ return [];
122
+ if (doc.exclude.length && matchAny(doc.exclude, relpath))
123
+ return [];
124
+ if (!matchAny(doc.include, relpath))
125
+ return [];
126
+ if (!content.trim())
127
+ return [];
128
+ const lines = content.split(/\r?\n/);
129
+ const findings = [];
130
+ for (const rule of doc.rules) {
131
+ const patterns = rulePatterns(rule, doc.include);
132
+ const rtype = String(rule.type || "").toLowerCase();
133
+ if (rule.from && rule.to)
134
+ findings.push(...evalLayer(rule, relpath, lines));
135
+ if (rule.max_lines != null)
136
+ findings.push(...evalMaxLines(rule, relpath, lines, patterns));
137
+ if (rtype === "regex" || rule.pattern || rule.regex) {
138
+ findings.push(...evalRegex(rule, relpath, lines, patterns));
139
+ }
140
+ }
141
+ const seen = new Set();
142
+ return findings.filter((f) => {
143
+ const k = `${f.id}:${f.file}:${f.line}`;
144
+ if (seen.has(k))
145
+ return false;
146
+ seen.add(k);
147
+ return true;
148
+ });
149
+ }
150
+ export function shouldIgnorePath(absPath, root) {
151
+ const rel = path.relative(root, absPath);
152
+ if (!rel || rel === ".")
153
+ return false;
154
+ if (rel.startsWith(".."))
155
+ return true;
156
+ const parts = rel.split(path.sep);
157
+ return parts.some((p) => SKIP_DIRS.has(p));
158
+ }
159
+ export { hasBlocking as hasCritical, hasBlocking };
@@ -0,0 +1,4 @@
1
+ export declare function isDefaultExcludedPath(relpath: string): boolean;
2
+ /** True when a rule's match/include/files is narrower than a repo-wide glob. */
3
+ export declare function ruleExplicitlyTargets(rule: Record<string, unknown>, relpath: string): boolean;
4
+ export declare function shouldEvaluateSourceFile(relpath: string, rules: Record<string, unknown>[]): boolean;
@@ -0,0 +1,50 @@
1
+ import path from "node:path";
2
+ import { matchAny } from "./glob.js";
3
+ const CONFIG_NAMES = new Set([
4
+ ".guardrail.yml",
5
+ "guardrail.yaml",
6
+ "guardrail.yml",
7
+ ]);
8
+ const LOCKFILES = new Set([
9
+ "package-lock.json",
10
+ "yarn.lock",
11
+ "pnpm-lock.yaml",
12
+ "bun.lockb",
13
+ ]);
14
+ export function isDefaultExcludedPath(relpath) {
15
+ const norm = relpath.replace(/\\/g, "/");
16
+ const base = path.basename(norm);
17
+ if (CONFIG_NAMES.has(base))
18
+ return true;
19
+ if (LOCKFILES.has(base))
20
+ return true;
21
+ if (norm.endsWith(".md"))
22
+ return true;
23
+ if (norm.includes("/.guard/") || norm.startsWith(".guard/"))
24
+ return true;
25
+ return false;
26
+ }
27
+ /** True when a rule's match/include/files is narrower than a repo-wide glob. */
28
+ export function ruleExplicitlyTargets(rule, relpath) {
29
+ if (rule.from) {
30
+ return matchAny([String(rule.from)], relpath);
31
+ }
32
+ const patterns = [];
33
+ for (const key of ["match", "include", "files"]) {
34
+ const val = rule[key];
35
+ if (typeof val === "string" && val.trim())
36
+ patterns.push(val.trim());
37
+ if (Array.isArray(val))
38
+ patterns.push(...val.map(String));
39
+ }
40
+ const specific = patterns.filter((p) => {
41
+ const t = p.trim();
42
+ return t && t !== "**/*" && t !== "**" && t !== "*";
43
+ });
44
+ return specific.some((p) => matchAny([p], relpath));
45
+ }
46
+ export function shouldEvaluateSourceFile(relpath, rules) {
47
+ if (!isDefaultExcludedPath(relpath))
48
+ return true;
49
+ return rules.some((rule) => ruleExplicitlyTargets(rule, relpath));
50
+ }
package/dist/glob.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /** Glob → regex (aligned with server guardrail_eval semantics). */
2
+ export declare function globToRegex(pattern: string): RegExp;
3
+ export declare function globMatch(pattern: string, relpath: string): boolean;
4
+ export declare function matchAny(patterns: string[], relpath: string): boolean;
5
+ export declare function expandExtensionIncludes(extensions: unknown): string[];
package/dist/glob.js ADDED
@@ -0,0 +1,63 @@
1
+ /** Glob → regex (aligned with server guardrail_eval semantics). */
2
+ export function globToRegex(pattern) {
3
+ let p = pattern.replace(/\\/g, "/").trim();
4
+ if (p.startsWith("./"))
5
+ p = p.slice(2);
6
+ // *.ts at repo root should still match nested TypeScript files
7
+ if (/^\*\.[\w.+-]+$/.test(p)) {
8
+ p = `**/${p}`;
9
+ }
10
+ const parts = [];
11
+ let i = 0;
12
+ while (i < p.length) {
13
+ if (p.slice(i, i + 3) === "**/") {
14
+ parts.push("(?:.*/)?");
15
+ i += 3;
16
+ }
17
+ else if (p.slice(i, i + 2) === "**") {
18
+ parts.push(".*");
19
+ i += 2;
20
+ }
21
+ else if (p[i] === "*") {
22
+ parts.push("[^/]*");
23
+ i += 1;
24
+ }
25
+ else if (p[i] === "?") {
26
+ parts.push("[^/]");
27
+ i += 1;
28
+ }
29
+ else {
30
+ let j = i;
31
+ while (j < p.length && p[j] !== "*" && p[j] !== "?")
32
+ j += 1;
33
+ parts.push(p.slice(i, j).replace(/[.+^${}()|[\]\\]/g, "\\$&"));
34
+ i = j;
35
+ }
36
+ }
37
+ return new RegExp("^" + parts.join("") + "$", "i");
38
+ }
39
+ export function globMatch(pattern, relpath) {
40
+ const norm = relpath.replace(/\\/g, "/").replace(/^\.\//, "");
41
+ try {
42
+ return globToRegex(pattern).test(norm);
43
+ }
44
+ catch {
45
+ return norm.includes(pattern.replace(/\\/g, "/"));
46
+ }
47
+ }
48
+ export function matchAny(patterns, relpath) {
49
+ if (!patterns.length)
50
+ return true;
51
+ return patterns.some((p) => globMatch(p, relpath));
52
+ }
53
+ export function expandExtensionIncludes(extensions) {
54
+ if (!Array.isArray(extensions))
55
+ return [];
56
+ return extensions.map((raw) => {
57
+ const s = String(raw).trim();
58
+ if (!s)
59
+ return "";
60
+ const ext = s.startsWith(".") ? s : `.${s}`;
61
+ return `**/*${ext}`;
62
+ }).filter(Boolean);
63
+ }
package/dist/hud.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Finding } from "./eval.js";
2
+ export type HudOptions = {
3
+ plain: boolean;
4
+ cloud: boolean;
5
+ };
6
+ export declare function printRulesWarning(reason: string, plain: boolean): void;
7
+ export declare function printHeader(opts: HudOptions & {
8
+ ruleCount: number;
9
+ configLabel: string;
10
+ findings: Finding[];
11
+ }): void;
12
+ export declare function printScanLine(rel: string, durationMs: number, count: number, plain: boolean): void;
13
+ export declare function printFinding(f: Finding, plain: boolean): void;
14
+ export declare function printStatusLine(findings: Finding[], plain: boolean): void;