claude-rules-doctor 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ Catch dead Claude rules before they silently do nothing.
2
+
3
+ # 🩺 claude-rules-doctor
4
+
5
+ CLI that verifies `.claude/rules/*.md` `paths:` globs actually match files in your project.
6
+
7
+ ## Quickstart
8
+
9
+ ```bash
10
+ # One-off
11
+ npx claude-rules-doctor check --root .
12
+
13
+ # Or install globally
14
+ npm install -g claude-rules-doctor
15
+ rules-doctor check --root .
16
+ ```
17
+
18
+ ## Problem
19
+
20
+ Claude rules with `paths:` frontmatter can silently fail if:
21
+ - The glob pattern doesn't match any files
22
+ - File paths changed after the rule was created
23
+ - Typos in glob patterns
24
+
25
+ This tool scans all your rules and tells you which ones are "dead" (not applying to any files).
26
+
27
+ ## Usage
28
+
29
+ ### Check current project
30
+
31
+ ```bash
32
+ rules-doctor check
33
+ ```
34
+
35
+ ### CI mode (exit 1 if dead rules found)
36
+
37
+ ```bash
38
+ rules-doctor check --ci
39
+ ```
40
+
41
+ ### JSON output
42
+
43
+ ```bash
44
+ rules-doctor check --json
45
+ ```
46
+
47
+ ### Verbose mode (show matched files)
48
+
49
+ ```bash
50
+ rules-doctor check --verbose
51
+ ```
52
+
53
+ ### Check specific directory
54
+
55
+ ```bash
56
+ rules-doctor check --root /path/to/project
57
+ ```
58
+
59
+ ## Output
60
+
61
+ - ✅ **OK** — Rule is global (no paths) or paths match files
62
+ - ⚠️ **WARNING** — Paths match files, but there's a known platform bug
63
+ - ❌ **DEAD** — Paths specified, but 0 files match
64
+
65
+ ## Example output (test-suite/6-mixed)
66
+
67
+ ```bash
68
+ $ rules-doctor check
69
+
70
+ 🔍 Rules Doctor - Check Results
71
+
72
+ ✅ OK <root>/.claude/rules/valid.md
73
+ Matches 1 file(s)
74
+
75
+ ✅ OK <root>/.claude/rules/global.md
76
+ Global rule (no paths specified)
77
+
78
+ ❌ DEAD <root>/.claude/rules/dead.md
79
+ No files match the specified paths
80
+
81
+ Summary:
82
+ Total rules: 3
83
+ ✅ OK: 2
84
+ ⚠️ WARNING: 0
85
+ ❌ DEAD: 1
86
+
87
+ ⚠️ Found 1 dead rule(s). These rules won't apply to any files.
88
+ ```
89
+
90
+ ## CI (GitHub Actions)
91
+
92
+ ```yaml
93
+ name: rules-doctor
94
+ on: [push, pull_request]
95
+
96
+ jobs:
97
+ rules:
98
+ runs-on: ubuntu-latest
99
+ steps:
100
+ - uses: actions/checkout@v4
101
+ - uses: actions/setup-node@v4
102
+ with:
103
+ node-version: 20
104
+ - run: npx claude-rules-doctor check --ci
105
+ ```
106
+
107
+ ## Why not cclint?
108
+
109
+ cclint validates frontmatter schema. We validate reality: do your globs actually match files in your repo?
110
+
111
+ ## License
112
+
113
+ MIT
@@ -0,0 +1,4 @@
1
+ import type { RuleFile, RuleCheckResult } from './types.js';
2
+ export declare function checkRule(rule: RuleFile, rootDir: string): Promise<RuleCheckResult>;
3
+ export declare function checkAllRules(rules: RuleFile[], rootDir: string): Promise<RuleCheckResult[]>;
4
+ //# sourceMappingURL=checker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAc,MAAM,YAAY,CAAC;AAGxE,wBAAsB,SAAS,CAC7B,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,CAAC,CAkF1B;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,eAAe,EAAE,CAAC,CAE5B"}
@@ -0,0 +1,81 @@
1
+ import { glob } from 'glob';
2
+ import { RuleStatus as Status } from './types.js';
3
+ export async function checkRule(rule, rootDir) {
4
+ // Global rule (no paths specified)
5
+ if (!rule.frontmatter || !rule.frontmatter.paths) {
6
+ return {
7
+ rule,
8
+ status: Status.OK,
9
+ matchedFiles: [],
10
+ message: 'Global rule (no paths specified)',
11
+ };
12
+ }
13
+ const paths = rule.frontmatter.paths;
14
+ if (!Array.isArray(paths) || paths.length === 0) {
15
+ return {
16
+ rule,
17
+ status: Status.OK,
18
+ matchedFiles: [],
19
+ message: 'No valid paths array',
20
+ };
21
+ }
22
+ // Filter out non-string values and warn about them
23
+ const invalidPaths = [];
24
+ const validPaths = [];
25
+ for (const path of paths) {
26
+ if (typeof path === 'string') {
27
+ validPaths.push(path);
28
+ }
29
+ else {
30
+ invalidPaths.push(path);
31
+ }
32
+ }
33
+ // If there are non-string values, return WARNING
34
+ if (invalidPaths.length > 0) {
35
+ const invalidTypes = invalidPaths
36
+ .map(p => (p === null ? 'null' : typeof p))
37
+ .join(', ');
38
+ return {
39
+ rule,
40
+ status: Status.WARNING,
41
+ matchedFiles: [],
42
+ message: `Invalid types in paths array: ${invalidTypes}. Only strings are allowed.`,
43
+ };
44
+ }
45
+ // Check each glob pattern
46
+ const allMatches = new Set();
47
+ for (const pattern of validPaths) {
48
+ try {
49
+ const matches = await glob(pattern, {
50
+ cwd: rootDir,
51
+ nodir: true,
52
+ ignore: ['node_modules/**', '.git/**'],
53
+ });
54
+ matches.forEach(file => allMatches.add(file));
55
+ }
56
+ catch (error) {
57
+ // Invalid glob pattern - treat as no matches
58
+ continue;
59
+ }
60
+ }
61
+ const matchedFiles = Array.from(allMatches).sort();
62
+ if (matchedFiles.length === 0) {
63
+ return {
64
+ rule,
65
+ status: Status.DEAD,
66
+ matchedFiles: [],
67
+ message: 'No files match the specified paths',
68
+ };
69
+ }
70
+ // For now, we don't detect platform bugs, so just return OK
71
+ return {
72
+ rule,
73
+ status: Status.OK,
74
+ matchedFiles,
75
+ message: `Matches ${matchedFiles.length} file(s)`,
76
+ };
77
+ }
78
+ export async function checkAllRules(rules, rootDir) {
79
+ return Promise.all(rules.map(rule => checkRule(rule, rootDir)));
80
+ }
81
+ //# sourceMappingURL=checker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checker.js","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAc,EACd,OAAe;IAEf,mCAAmC;IACnC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACjD,OAAO;YACL,IAAI;YACJ,MAAM,EAAE,MAAM,CAAC,EAAE;YACjB,YAAY,EAAE,EAAE;YAChB,OAAO,EAAE,kCAA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CAAC,OAAO,EAAE;gBAClC,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,CAAC,iBAAiB,EAAE,SAAS,CAAC;aACvC,CAAC,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,6CAA6C;YAC7C,SAAS;QACX,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;IAEnD,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO;YACL,IAAI;YACJ,MAAM,EAAE,MAAM,CAAC,IAAI;YACnB,YAAY,EAAE,EAAE;YAChB,OAAO,EAAE,oCAAoC;SAC9C,CAAC;IACJ,CAAC;IAED,4DAA4D;IAC5D,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,MAAM,CAAC,EAAE;QACjB,YAAY;QACZ,OAAO,EAAE,WAAW,YAAY,CAAC,MAAM,UAAU;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAAiB,EACjB,OAAe;IAEf,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { resolve, join } from 'path';
4
+ import { existsSync } from 'fs';
5
+ import { parseAllRules } from './parser.js';
6
+ import { checkAllRules } from './checker.js';
7
+ import { generateReport, printConsoleReport, printJsonReport } from './reporter.js';
8
+ const program = new Command();
9
+ program
10
+ .name('rules-doctor')
11
+ .description('CLI for checking .claude/rules/*.md files')
12
+ .version('1.0.0');
13
+ program
14
+ .command('check')
15
+ .description('Check all rules in .claude/rules/')
16
+ .option('--root <path>', 'Root directory to check', process.cwd())
17
+ .option('--ci', 'Exit with code 1 if dead rules found', false)
18
+ .option('--json', 'Output results as JSON', false)
19
+ .option('--verbose', 'Show matched files for each rule', false)
20
+ .action(async (options) => {
21
+ try {
22
+ const rootDir = resolve(options.root);
23
+ const rulesDir = join(rootDir, '.claude', 'rules');
24
+ // Check if .claude/rules/ directory exists
25
+ if (!existsSync(rulesDir)) {
26
+ console.log('Directory .claude/rules/ does not exist');
27
+ process.exit(0);
28
+ }
29
+ // Parse all rules
30
+ const rules = await parseAllRules(rootDir);
31
+ if (rules.length === 0) {
32
+ console.log('No rules found in .claude/rules/ (directory is empty)');
33
+ process.exit(0);
34
+ }
35
+ // Check all rules
36
+ const results = await checkAllRules(rules, rootDir);
37
+ // Generate report
38
+ const report = generateReport(results);
39
+ // Output
40
+ if (options.json) {
41
+ printJsonReport(report);
42
+ }
43
+ else {
44
+ printConsoleReport(report, options.verbose);
45
+ }
46
+ // CI mode: exit 1 if dead rules found
47
+ if (options.ci && report.deadCount > 0) {
48
+ process.exit(1);
49
+ }
50
+ }
51
+ catch (error) {
52
+ console.error('Error:', error instanceof Error ? error.message : error);
53
+ process.exit(1);
54
+ }
55
+ });
56
+ program.parse();
57
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EA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,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,kBAAkB;QAClB,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAEpD,kBAAkB;QAClB,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;QAEvC,SAAS;QACT,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,eAAe,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QAED,sCAAsC;QACtC,IAAI,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './parser.js';
3
+ export * from './checker.js';
4
+ export * from './reporter.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './parser.js';
3
+ export * from './checker.js';
4
+ export * from './reporter.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { RuleFile } from './types.js';
2
+ export declare function findRuleFiles(rootDir: string): Promise<string[]>;
3
+ export declare function parseRuleFile(filePath: string): Promise<RuleFile>;
4
+ export declare function parseAllRules(rootDir: string): Promise<RuleFile[]>;
5
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,YAAY,CAAC;AAI5D,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAItE;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQvE;AAiBD,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAMxE"}
package/dist/parser.js ADDED
@@ -0,0 +1,36 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { glob } from 'glob';
3
+ import { parse as parseYaml } from 'yaml';
4
+ const FRONTMATTER_REGEX = /^\s*---\s*\n([\s\S]*?)\n---/;
5
+ export async function findRuleFiles(rootDir) {
6
+ const pattern = `${rootDir}/.claude/rules/**/*.md`;
7
+ const files = await glob(pattern, { nodir: true });
8
+ return files;
9
+ }
10
+ export async function parseRuleFile(filePath) {
11
+ const content = await readFile(filePath, 'utf-8');
12
+ const frontmatter = extractFrontmatter(content);
13
+ return {
14
+ filePath,
15
+ frontmatter,
16
+ };
17
+ }
18
+ function extractFrontmatter(content) {
19
+ const match = content.match(FRONTMATTER_REGEX);
20
+ if (!match) {
21
+ return null;
22
+ }
23
+ try {
24
+ const parsed = parseYaml(match[1]);
25
+ return parsed;
26
+ }
27
+ catch (error) {
28
+ return null;
29
+ }
30
+ }
31
+ export async function parseAllRules(rootDir) {
32
+ const filePaths = await findRuleFiles(rootDir);
33
+ const rules = await Promise.all(filePaths.map(filePath => parseRuleFile(filePath)));
34
+ return rules;
35
+ }
36
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAG1C,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe;IACjD,MAAM,OAAO,GAAG,GAAG,OAAO,wBAAwB,CAAC;IACnD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACnD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,QAAgB;IAClD,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAEhD,OAAO;QACL,QAAQ;QACR,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAe;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAE/C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,OAAO,MAAyB,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe;IACjD,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAC7B,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CACnD,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { RuleCheckResult, CheckReport } from './types.js';
2
+ export declare function generateReport(results: RuleCheckResult[]): CheckReport;
3
+ export declare function printConsoleReport(report: CheckReport, verbose: boolean): void;
4
+ export declare function printJsonReport(report: CheckReport): void;
5
+ //# sourceMappingURL=reporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG/D,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,WAAW,CAwBtE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAwC9E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAEzD"}
@@ -0,0 +1,79 @@
1
+ import chalk from 'chalk';
2
+ import { RuleStatus } from './types.js';
3
+ export function generateReport(results) {
4
+ const report = {
5
+ totalRules: results.length,
6
+ okCount: 0,
7
+ warningCount: 0,
8
+ deadCount: 0,
9
+ results,
10
+ };
11
+ for (const result of results) {
12
+ switch (result.status) {
13
+ case RuleStatus.OK:
14
+ report.okCount++;
15
+ break;
16
+ case RuleStatus.WARNING:
17
+ report.warningCount++;
18
+ break;
19
+ case RuleStatus.DEAD:
20
+ report.deadCount++;
21
+ break;
22
+ }
23
+ }
24
+ return report;
25
+ }
26
+ export function printConsoleReport(report, verbose) {
27
+ console.log(chalk.bold('\n🔍 Rules Doctor - Check Results\n'));
28
+ for (const result of report.results) {
29
+ const statusIcon = getStatusIcon(result.status);
30
+ const statusColor = getStatusColor(result.status);
31
+ const relativePath = result.rule.filePath;
32
+ console.log(`${statusIcon} ${statusColor(result.status.padEnd(7))} ${chalk.gray(relativePath)}`);
33
+ console.log(` ${chalk.dim(result.message)}`);
34
+ if (verbose && result.matchedFiles.length > 0) {
35
+ console.log(chalk.dim(` Matched files (${result.matchedFiles.length}):`));
36
+ result.matchedFiles.slice(0, 10).forEach(file => {
37
+ console.log(chalk.dim(` - ${file}`));
38
+ });
39
+ if (result.matchedFiles.length > 10) {
40
+ console.log(chalk.dim(` ... and ${result.matchedFiles.length - 10} more`));
41
+ }
42
+ }
43
+ console.log();
44
+ }
45
+ console.log(chalk.bold('Summary:'));
46
+ console.log(` Total rules: ${report.totalRules}`);
47
+ console.log(` ${chalk.green('✅ OK')}: ${report.okCount}`);
48
+ console.log(` ${chalk.yellow('⚠️ WARNING')}: ${report.warningCount}`);
49
+ console.log(` ${chalk.red('❌ DEAD')}: ${report.deadCount}`);
50
+ console.log();
51
+ if (report.deadCount > 0) {
52
+ console.log(chalk.yellow(`⚠️ Found ${report.deadCount} dead rule(s). These rules won't apply to any files.`));
53
+ console.log();
54
+ }
55
+ }
56
+ export function printJsonReport(report) {
57
+ console.log(JSON.stringify(report, null, 2));
58
+ }
59
+ function getStatusIcon(status) {
60
+ switch (status) {
61
+ case RuleStatus.OK:
62
+ return chalk.green('✅');
63
+ case RuleStatus.WARNING:
64
+ return chalk.yellow('⚠️');
65
+ case RuleStatus.DEAD:
66
+ return chalk.red('❌');
67
+ }
68
+ }
69
+ function getStatusColor(status) {
70
+ switch (status) {
71
+ case RuleStatus.OK:
72
+ return chalk.green;
73
+ case RuleStatus.WARNING:
74
+ return chalk.yellow;
75
+ case RuleStatus.DEAD:
76
+ return chalk.red;
77
+ }
78
+ }
79
+ //# sourceMappingURL=reporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reporter.js","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,UAAU,cAAc,CAAC,OAA0B;IACvD,MAAM,MAAM,GAAgB;QAC1B,UAAU,EAAE,OAAO,CAAC,MAAM;QAC1B,OAAO,EAAE,CAAC;QACV,YAAY,EAAE,CAAC;QACf,SAAS,EAAE,CAAC;QACZ,OAAO;KACR,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;YACtB,KAAK,UAAU,CAAC,EAAE;gBAChB,MAAM,CAAC,OAAO,EAAE,CAAC;gBACjB,MAAM;YACR,KAAK,UAAU,CAAC,OAAO;gBACrB,MAAM,CAAC,YAAY,EAAE,CAAC;gBACtB,MAAM;YACR,KAAK,UAAU,CAAC,IAAI;gBAClB,MAAM,CAAC,SAAS,EAAE,CAAC;gBACnB,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAmB,EAAE,OAAgB;IACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,CAAC;IAE/D,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,E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,KAAK,UAAU,CAAC,EAAE;YAChB,OAAO,KAAK,CAAC,KAAK,CAAC;QACrB,KAAK,UAAU,CAAC,OAAO;YACrB,OAAO,KAAK,CAAC,MAAM,CAAC;QACtB,KAAK,UAAU,CAAC,IAAI;YAClB,OAAO,KAAK,CAAC,GAAG,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ export interface RuleFrontmatter {
2
+ paths?: string[];
3
+ [key: string]: unknown;
4
+ }
5
+ export interface RuleFile {
6
+ filePath: string;
7
+ frontmatter: RuleFrontmatter | null;
8
+ }
9
+ export declare enum RuleStatus {
10
+ OK = "OK",
11
+ WARNING = "WARNING",
12
+ DEAD = "DEAD"
13
+ }
14
+ export interface RuleCheckResult {
15
+ rule: RuleFile;
16
+ status: RuleStatus;
17
+ matchedFiles: string[];
18
+ message: string;
19
+ }
20
+ export interface CheckOptions {
21
+ root: string;
22
+ ci: boolean;
23
+ json: boolean;
24
+ verbose: boolean;
25
+ }
26
+ export interface CheckReport {
27
+ totalRules: number;
28
+ okCount: number;
29
+ warningCount: number;
30
+ deadCount: number;
31
+ results: RuleCheckResult[];
32
+ }
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,eAAe,GAAG,IAAI,CAAC;CACrC;AAED,oBAAY,UAAU;IACpB,EAAE,OAAO;IACT,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ export var RuleStatus;
2
+ (function (RuleStatus) {
3
+ RuleStatus["OK"] = "OK";
4
+ RuleStatus["WARNING"] = "WARNING";
5
+ RuleStatus["DEAD"] = "DEAD";
6
+ })(RuleStatus || (RuleStatus = {}));
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAUA,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,uBAAS,CAAA;IACT,iCAAmB,CAAA;IACnB,2BAAa,CAAA;AACf,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "claude-rules-doctor",
3
+ "version": "0.1.1",
4
+ "description": "Your Claude Code rules silently fail. We catch them.",
5
+ "type": "module",
6
+ "bin": {
7
+ "rules-doctor": "dist/cli.js",
8
+ "claude-rules-doctor": "dist/cli.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/nulone/claude-rules-doctor.git"
13
+ },
14
+ "homepage": "https://github.com/nulone/claude-rules-doctor#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/nulone/claude-rules-doctor/issues"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc",
20
+ "dev": "tsc --watch",
21
+ "prepublishOnly": "npm run build"
22
+ },
23
+ "keywords": [
24
+ "claude-code",
25
+ "claude",
26
+ "rules",
27
+ "linter",
28
+ "cli",
29
+ "glob",
30
+ "validation",
31
+ "dead-rules"
32
+ ],
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "author": "",
39
+ "license": "MIT",
40
+ "dependencies": {
41
+ "chalk": "^5.3.0",
42
+ "commander": "^12.0.0",
43
+ "glob": "^10.3.10",
44
+ "yaml": "^2.3.4"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^20.11.0",
48
+ "typescript": "^5.3.3"
49
+ },
50
+ "engines": {
51
+ "node": ">=18.0.0"
52
+ }
53
+ }