instrlint 0.1.0
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 +21 -0
- package/README.md +185 -0
- package/README.zh-TW.md +191 -0
- package/dist/cli.cjs +2943 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +2916 -0
- package/dist/cli.js.map +1 -0
- package/package.json +74 -0
- package/skills/claude-code/SKILL.md +69 -0
- package/skills/codex/SKILL.md +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jed Lin
|
|
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,185 @@
|
|
|
1
|
+
# instrlint
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/instrlint)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://github.com/jed1978/instrlint/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
[繁體中文](README.zh-TW.md) | English
|
|
8
|
+
|
|
9
|
+
**instrlint lints itself.**
|
|
10
|
+
|
|
11
|
+
Lint and optimize your `CLAUDE.md` / `AGENTS.md` — find dead rules, token waste, and structural issues. One command, one score, one report.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
**Global install (recommended):**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g instrlint
|
|
19
|
+
instrlint
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Install once, run from any project. Or use `npx` to run without installing:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx instrlint
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Run from your project root where `CLAUDE.md` or `AGENTS.md` lives.
|
|
29
|
+
|
|
30
|
+
## Output example
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
╭──────────────────────────────────────────────────╮
|
|
34
|
+
│ instrlint ─ sample-project │
|
|
35
|
+
│ claude-code · measured │
|
|
36
|
+
├──────────────────────────────────────────────────┤
|
|
37
|
+
│ ███████████████░░░░░░░░░░░░░░░ 50/100 F │
|
|
38
|
+
╰──────────────────────────────────────────────────╯
|
|
39
|
+
|
|
40
|
+
── BUDGET ──────────────────────────────────────────
|
|
41
|
+
18,957 / 200,000 tokens (9%) █░░░░░░░░░░░░░
|
|
42
|
+
|
|
43
|
+
── FINDINGS ────────────────────────────────────────
|
|
44
|
+
Contradictions ✖ 1
|
|
45
|
+
Budget ⚠ 1
|
|
46
|
+
Dead rules ⚠ 5
|
|
47
|
+
Duplicates ⚠ 1 ℹ 1
|
|
48
|
+
Stale refs ⚠ 2
|
|
49
|
+
Structure ℹ 11
|
|
50
|
+
|
|
51
|
+
── TOP ISSUES ──────────────────────────────────────
|
|
52
|
+
1. ✖ Contradicting rules: "Use exceptions for error handling. Throw error…
|
|
53
|
+
2. ⚠ Root instruction file is 206 lines (recommended: < 200)
|
|
54
|
+
3. ⚠ Rule "Always use TypeScript strict mode. Enable all strict checks to…
|
|
55
|
+
4. ⚠ Rule "Use 2-space indentation for all files. Never use tabs." is alr…
|
|
56
|
+
5. ⚠ Rule "Always use semicolons at the end of statements." is already en…
|
|
57
|
+
… and 17 more (run instrlint <command> for details)
|
|
58
|
+
|
|
59
|
+
── 1 critical · 9 warnings · 12 suggestions ────────
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Features
|
|
63
|
+
|
|
64
|
+
**Token Budget** — counts tokens across all your instruction files using `cl100k_base` encoding (falls back to character estimation). Flags files over 200 lines and baseline context over 25% of your window.
|
|
65
|
+
|
|
66
|
+
**Dead Rules** — detects rules already enforced by your config files. ~15 overlap patterns covering TypeScript strict mode, Prettier formatting, ESLint rules, conventional commits, EditorConfig, and more.
|
|
67
|
+
|
|
68
|
+
**Structure** — finds contradicting rules, stale file references, exact and near-duplicate rules, and path-scoping opportunities.
|
|
69
|
+
|
|
70
|
+
**Auto-fix** — `--fix` safely removes dead rules, stale refs, and exact duplicates. Requires a clean git working tree.
|
|
71
|
+
|
|
72
|
+
**CI Integration** — `instrlint ci` exits 0 or 1 based on findings severity, with SARIF output for GitHub Code Scanning.
|
|
73
|
+
|
|
74
|
+
## Supported tools
|
|
75
|
+
|
|
76
|
+
| Tool | Root file | Config dir |
|
|
77
|
+
|------|-----------|------------|
|
|
78
|
+
| Claude Code | `CLAUDE.md` | `.claude/` |
|
|
79
|
+
| Codex | `AGENTS.md` | `.agents/`, `.codex/` |
|
|
80
|
+
| Cursor | `.cursorrules` | `.cursor/` |
|
|
81
|
+
|
|
82
|
+
Auto-detected from project structure. Override with `--tool`.
|
|
83
|
+
|
|
84
|
+
## Commands
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
instrlint # Full health check — score, grade, top issues
|
|
88
|
+
instrlint budget # Token budget analysis only
|
|
89
|
+
instrlint deadrules # Dead rule detection only
|
|
90
|
+
instrlint structure # Structural analysis only
|
|
91
|
+
instrlint --fix # Auto-fix safe issues
|
|
92
|
+
instrlint --fix --force # Skip git clean check
|
|
93
|
+
|
|
94
|
+
instrlint --format json # JSON output (for CI, scripts)
|
|
95
|
+
instrlint --format markdown # Markdown output (for PR comments)
|
|
96
|
+
instrlint --lang zh-TW # Traditional Chinese output
|
|
97
|
+
|
|
98
|
+
instrlint ci # CI mode: exit 1 on critical findings
|
|
99
|
+
instrlint ci --fail-on warning # Exit 1 on warnings too
|
|
100
|
+
instrlint ci --format sarif # SARIF output for GitHub Code Scanning
|
|
101
|
+
instrlint ci --output report.sarif # Write to file
|
|
102
|
+
|
|
103
|
+
instrlint init-ci --github # Generate .github/workflows/instrlint.yml
|
|
104
|
+
instrlint init-ci --gitlab # Print GitLab CI snippet to stdout
|
|
105
|
+
|
|
106
|
+
instrlint install --claude-code # Install as global Claude Code skill
|
|
107
|
+
instrlint install --claude-code --project # Install into project
|
|
108
|
+
instrlint install --codex # Install as Codex skill
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## CI Integration
|
|
112
|
+
|
|
113
|
+
### GitHub Actions
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npx instrlint init-ci --github
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This creates `.github/workflows/instrlint.yml` with:
|
|
120
|
+
- Triggers on changes to `CLAUDE.md`, `.claude/**`, `AGENTS.md`, etc.
|
|
121
|
+
- Runs `instrlint ci --fail-on warning --format sarif`
|
|
122
|
+
- Uploads SARIF to GitHub Code Scanning
|
|
123
|
+
|
|
124
|
+
Or add it to your existing CI:
|
|
125
|
+
|
|
126
|
+
```yaml
|
|
127
|
+
- name: Run instrlint
|
|
128
|
+
run: npx instrlint@latest ci --fail-on warning
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### GitLab CI
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npx instrlint init-ci --gitlab
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Skill installation
|
|
138
|
+
|
|
139
|
+
Use instrlint directly from Claude Code or Codex without leaving the editor:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Claude Code (global)
|
|
143
|
+
npx instrlint install --claude-code
|
|
144
|
+
|
|
145
|
+
# Claude Code (project only)
|
|
146
|
+
npx instrlint install --claude-code --project
|
|
147
|
+
|
|
148
|
+
# Codex
|
|
149
|
+
npx instrlint install --codex
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Then in your editor:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
/instrlint
|
|
156
|
+
/instrlint --fix
|
|
157
|
+
/instrlint ci --fail-on warning
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Score and grade
|
|
161
|
+
|
|
162
|
+
| Grade | Score | Meaning |
|
|
163
|
+
|-------|-------|---------|
|
|
164
|
+
| A | 90–100 | Excellent |
|
|
165
|
+
| B | 80–89 | Good |
|
|
166
|
+
| C | 70–79 | Fair |
|
|
167
|
+
| D | 60–69 | Poor |
|
|
168
|
+
| F | < 60 | Critical |
|
|
169
|
+
|
|
170
|
+
Deductions: critical finding −10 (cap −40), warning −5 (cap −30), info −1 (cap −10). Budget penalty: −5 if baseline > 25% of context, −15 if > 50%.
|
|
171
|
+
|
|
172
|
+
## Contributing
|
|
173
|
+
|
|
174
|
+
The primary differentiator is the config overlap patterns in `src/detectors/config-overlap.ts`. To add a new pattern:
|
|
175
|
+
|
|
176
|
+
1. Add a new entry to the `OVERLAP_PATTERNS` array
|
|
177
|
+
2. Map the rule keywords to the config file + field that enforces them
|
|
178
|
+
3. Add a test fixture in `tests/fixtures/sample-project/` that triggers the pattern
|
|
179
|
+
4. Add a test case in `tests/detectors/config-overlap.test.ts`
|
|
180
|
+
|
|
181
|
+
See [CLAUDE.md](CLAUDE.md) for full architecture documentation.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT — see [LICENSE](LICENSE)
|
package/README.zh-TW.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# instrlint
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/instrlint)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://github.com/jed1978/instrlint/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
[English](README.md) | 繁體中文
|
|
8
|
+
|
|
9
|
+
**instrlint 會 lint 自己。**
|
|
10
|
+
|
|
11
|
+
Lint 並優化你的 `CLAUDE.md` / `AGENTS.md` — 找出冗餘規則、token 浪費和結構問題。一個指令、一個分數、一份報告。
|
|
12
|
+
|
|
13
|
+
## 快速開始
|
|
14
|
+
|
|
15
|
+
**全域安裝(建議):**
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g instrlint
|
|
19
|
+
instrlint
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
安裝一次,在任何專案都能直接使用。或用 `npx` 免安裝執行:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx instrlint
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
在含有 `CLAUDE.md` 或 `AGENTS.md` 的專案根目錄執行即可。
|
|
29
|
+
|
|
30
|
+
## 輸出範例
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
╭──────────────────────────────────────────────────╮
|
|
34
|
+
│ instrlint ─ sample-project │
|
|
35
|
+
│ claude-code · measured │
|
|
36
|
+
├──────────────────────────────────────────────────┤
|
|
37
|
+
│ ███████████████░░░░░░░░░░░░░░░ 50/100 F │
|
|
38
|
+
╰──────────────────────────────────────────────────╯
|
|
39
|
+
|
|
40
|
+
── 預算 ──────────────────────────────────────────────
|
|
41
|
+
18,957 / 200,000 tokens (9%) █░░░░░░░░░░░░░
|
|
42
|
+
|
|
43
|
+
── 問題總覽 ────────────────────────────────────────────
|
|
44
|
+
Contradictions ✖ 1
|
|
45
|
+
Budget ⚠ 1
|
|
46
|
+
Dead rules ⚠ 5
|
|
47
|
+
Duplicates ⚠ 1 ℹ 1
|
|
48
|
+
Stale refs ⚠ 2
|
|
49
|
+
Structure ℹ 11
|
|
50
|
+
|
|
51
|
+
── 首要問題 ────────────────────────────────────────────
|
|
52
|
+
1. ✖ 規則矛盾:「Use exceptions for error handling. Throw errors with descrip..…
|
|
53
|
+
2. ⚠ 根指令檔有 206 行(建議:< 200 行)
|
|
54
|
+
3. ⚠ 規則「Always use TypeScript strict mode. Enable all strict checks to ca…
|
|
55
|
+
4. ⚠ 規則「Use 2-space indentation for all files. Never use tabs.」已由 .editor…
|
|
56
|
+
5. ⚠ 規則「Always use semicolons at the end of statements.」已由 .prettierrc (s…
|
|
57
|
+
… 還有 17 個(執行 instrlint <command> 查看詳情)
|
|
58
|
+
|
|
59
|
+
── 1 個嚴重問題 · 9 個警告 · 12 個建議 ────────────────────────
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
加上 `--lang zh-TW` 即可取得完整繁體中文輸出:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npx instrlint --lang zh-TW
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 功能特色
|
|
69
|
+
|
|
70
|
+
**Token 預算** — 使用 `cl100k_base` encoding 計算所有指令檔的 token 用量(無法載入時自動降級為字元估算)。標記超過 200 行的檔案,以及 baseline context 超過視窗 25% 的情況。
|
|
71
|
+
|
|
72
|
+
**冗餘規則偵測** — 偵測已被 config 檔強制執行的規則。涵蓋 TypeScript strict mode、Prettier 格式化、ESLint 規則、conventional commits、EditorConfig 等約 15 種重疊模式。
|
|
73
|
+
|
|
74
|
+
**結構分析** — 找出互相矛盾的規則、過時的檔案參照、完全相同和高度相似的重複規則,以及路徑範圍化的優化機會。
|
|
75
|
+
|
|
76
|
+
**自動修復** — `--fix` 安全地移除冗餘規則、過時參照和完全重複的規則。需要乾淨的 git 工作目錄。
|
|
77
|
+
|
|
78
|
+
**CI 整合** — `instrlint ci` 依 findings 嚴重程度回傳 exit code 0 或 1,並支援 SARIF 輸出供 GitHub Code Scanning 使用。
|
|
79
|
+
|
|
80
|
+
## 支援工具
|
|
81
|
+
|
|
82
|
+
| 工具 | 根指令檔 | 設定目錄 |
|
|
83
|
+
|------|----------|----------|
|
|
84
|
+
| Claude Code | `CLAUDE.md` | `.claude/` |
|
|
85
|
+
| Codex | `AGENTS.md` | `.agents/`, `.codex/` |
|
|
86
|
+
| Cursor | `.cursorrules` | `.cursor/` |
|
|
87
|
+
|
|
88
|
+
從專案結構自動偵測。可用 `--tool` 強制指定。
|
|
89
|
+
|
|
90
|
+
## 指令
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
instrlint # 完整健康檢查 — 分數、等級、首要問題
|
|
94
|
+
instrlint budget # 僅 token 預算分析
|
|
95
|
+
instrlint deadrules # 僅冗餘規則偵測
|
|
96
|
+
instrlint structure # 僅結構分析
|
|
97
|
+
instrlint --fix # 自動修復安全問題
|
|
98
|
+
instrlint --fix --force # 跳過 git clean 檢查
|
|
99
|
+
|
|
100
|
+
instrlint --format json # JSON 輸出(供 CI、腳本使用)
|
|
101
|
+
instrlint --format markdown # Markdown 輸出(供 PR 留言使用)
|
|
102
|
+
instrlint --lang zh-TW # 繁體中文輸出
|
|
103
|
+
|
|
104
|
+
instrlint ci # CI 模式:嚴重問題時 exit 1
|
|
105
|
+
instrlint ci --fail-on warning # 警告也 exit 1
|
|
106
|
+
instrlint ci --format sarif # SARIF 輸出供 GitHub Code Scanning
|
|
107
|
+
instrlint ci --output report.sarif # 寫入檔案
|
|
108
|
+
|
|
109
|
+
instrlint init-ci --github # 產生 .github/workflows/instrlint.yml
|
|
110
|
+
instrlint init-ci --gitlab # 輸出 GitLab CI 設定片段
|
|
111
|
+
|
|
112
|
+
instrlint install --claude-code # 安裝為全域 Claude Code skill
|
|
113
|
+
instrlint install --claude-code --project # 安裝到專案
|
|
114
|
+
instrlint install --codex # 安裝為 Codex skill
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## CI 整合
|
|
118
|
+
|
|
119
|
+
### GitHub Actions
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
npx instrlint init-ci --github
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
此指令會建立 `.github/workflows/instrlint.yml`,包含:
|
|
126
|
+
- 在 `CLAUDE.md`、`.claude/**`、`AGENTS.md` 等檔案變更時觸發
|
|
127
|
+
- 執行 `instrlint ci --fail-on warning --format sarif`
|
|
128
|
+
- 上傳 SARIF 至 GitHub Code Scanning
|
|
129
|
+
|
|
130
|
+
或加入現有 CI:
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
- name: Run instrlint
|
|
134
|
+
run: npx instrlint@latest ci --fail-on warning
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### GitLab CI
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx instrlint init-ci --gitlab
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Skill 安裝
|
|
144
|
+
|
|
145
|
+
不離開編輯器直接從 Claude Code 或 Codex 使用 instrlint:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Claude Code(全域)
|
|
149
|
+
npx instrlint install --claude-code
|
|
150
|
+
|
|
151
|
+
# Claude Code(僅專案)
|
|
152
|
+
npx instrlint install --claude-code --project
|
|
153
|
+
|
|
154
|
+
# Codex
|
|
155
|
+
npx instrlint install --codex
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
安裝後在編輯器中使用:
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
/instrlint
|
|
162
|
+
/instrlint --fix
|
|
163
|
+
/instrlint ci --fail-on warning
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 分數與等級
|
|
167
|
+
|
|
168
|
+
| 等級 | 分數 | 說明 |
|
|
169
|
+
|------|------|------|
|
|
170
|
+
| A | 90–100 | 優秀 |
|
|
171
|
+
| B | 80–89 | 良好 |
|
|
172
|
+
| C | 70–79 | 尚可 |
|
|
173
|
+
| D | 60–69 | 較差 |
|
|
174
|
+
| F | < 60 | 嚴重 |
|
|
175
|
+
|
|
176
|
+
扣分規則:嚴重問題 −10(上限 −40)、警告 −5(上限 −30)、建議 −1(上限 −10)。預算懲罰:baseline 超過 context 的 25% 扣 −5,超過 50% 扣 −15。
|
|
177
|
+
|
|
178
|
+
## 貢獻
|
|
179
|
+
|
|
180
|
+
核心差異化功能是 `src/detectors/config-overlap.ts` 中的 config 重疊規則。新增規則的方式:
|
|
181
|
+
|
|
182
|
+
1. 在 `OVERLAP_PATTERNS` 陣列新增一筆
|
|
183
|
+
2. 將規則關鍵字對應到強制執行它的 config 檔 + 欄位
|
|
184
|
+
3. 在 `tests/fixtures/sample-project/` 新增觸發該規則的 fixture
|
|
185
|
+
4. 在 `tests/detectors/config-overlap.test.ts` 新增測試案例
|
|
186
|
+
|
|
187
|
+
完整架構文件請參閱 [CLAUDE.md](CLAUDE.md)。
|
|
188
|
+
|
|
189
|
+
## 授權
|
|
190
|
+
|
|
191
|
+
MIT — 詳見 [LICENSE](LICENSE)
|