agentfile-linter 0.0.1-rc.1 → 0.0.1-rc.2

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 CHANGED
@@ -24,27 +24,15 @@ Finished in 14ms on 3 files with 4 rules.
24
24
  Run the CLI from npm with Node.js 22.17 or newer.
25
25
 
26
26
  ```sh
27
+ # Run without adding a project dependency
27
28
  pnpx agentfile-linter
28
29
  npx agentfile-linter
29
- ```
30
-
31
- To pin the CLI in a project or run it from a package script, install it as a dev dependency.
32
30
 
33
- ```sh
31
+ # Pin it in a project or run it from a package script
34
32
  npm install --save-dev agentfile-linter
35
33
  npm exec -- agentfile-linter
36
34
  ```
37
35
 
38
- You can also build a standalone executable from source with [Bun](https://bun.sh).
39
-
40
- ```sh
41
- bun install
42
- bun run build # -> dist/agentfile-linter (current platform)
43
- bun run build:all # -> dist/agentfile-linter-<os>-<arch> for every supported target
44
- ```
45
-
46
- During development you can also run it from source: `bun run src/cli.ts .`
47
-
48
36
  ## Usage
49
37
 
50
38
  ```sh
@@ -58,7 +46,25 @@ agentfile-linter --init # create .agentfile-linterrc.json
58
46
  agentfile-linter --debug files # print the files that would be linted, then exit
59
47
  ```
60
48
 
61
- With no config file and no rule flags, every rule in the `recommended` category runs as an `error`.
49
+ With no config file and no rule flags, every rule marked as recommended in the table below runs as an `error`.
50
+
51
+ ### Rules
52
+
53
+ | Rule | Recommended | Category | Checks |
54
+ | -------------------------------------------------------------------------------- | ----------- | ----------- | ------------------------------------------------------------------------- |
55
+ | [`agentfile/no-missing-path`](#agentfileno-missing-path) | ✓ | correctness | Referenced files and directories exist |
56
+ | [`agentfile/no-missing-script`](#agentfileno-missing-script) | ✓ | correctness | Documented scripts and tasks (npm, make, just, uv, maven, cargo, …) exist |
57
+ | [`agentfile/no-broken-reference`](#agentfileno-broken-reference) | ✓ | correctness | Relative links, images, `#anchors` and `#L42` line fragments resolve |
58
+ | [`agentfile/no-agent-files-drift`](#agentfileno-agent-files-drift) | ✓ | suspicious | Agent files in one directory are identical or symlinked |
59
+ | [`agentfile/no-invalid-skill`](#agentfileno-invalid-skill) | ✓ | correctness | Skill directories have a valid layout and valid `SKILL.md` frontmatter |
60
+ | [`agentfile/no-misnamed-agent-file`](#agentfileno-misnamed-agent-file) | ✓ | correctness | Agent files are spelled in the exact case agents look for |
61
+ | [`agentfile/no-unnecessary-agent-files`](#agentfileno-unnecessary-agent-files) | | pedantic | No `CLAUDE.md` that only mirrors `AGENTS.md` |
62
+ | [`agentfile/keep-agents-file-up-to-date`](#agentfilekeep-agents-file-up-to-date) | | pedantic | Context files were changed recently |
63
+ | [`agentfile/limit-file-size`](#agentfilelimit-file-size) | | pedantic | Context files stay below a maximum number of characters |
64
+
65
+ The rules that aren't recommended are off until you enable them in `rules`, e.g. `"agentfile/keep-agents-file-up-to-date": "warn"`, or by their category.
66
+
67
+ Each rule belongs to one category, named as in [Oxlint](https://oxc.rs/docs/guide/usage/linter/rules.html): `correctness` (instructions that are wrong), `suspicious` (most likely wrong) and `pedantic` (stricter, with occasional false positives). `style`, `perf`, `restriction` and `nursery` have no rules yet. `"categories": { "pedantic": "warn" }` in the config or `-W pedantic` on the command line sets the severity of all rules in a category. `recommended` works the same way for the recommended rules.
62
68
 
63
69
  ### Linted files
64
70
 
@@ -87,7 +93,7 @@ Besides context files, [`agentfile/no-invalid-skill`](#agentfileno-invalid-skill
87
93
  | `--silent` | Print no diagnostics |
88
94
  | `--print-config` | Print the effective configuration |
89
95
  | `--debug=<options>` | Debug output, comma-separated. `files`: print the files that would be linted, then exit |
90
- | `--rules` | List all rules |
96
+ | `--rules` | List all rules, including those of `jsPlugins`. Config problems are printed below the list |
91
97
 
92
98
  `-A`/`-W`/`-D` are applied left to right, after the config file. A rule name can be written with or without its `agentfile/` prefix.
93
99
 
@@ -112,6 +118,10 @@ Besides context files, [`agentfile/no-invalid-skill`](#agentfileno-invalid-skill
112
118
  "reportUnnecessarySuppressions": true,
113
119
  // Replaces the default set of linted files
114
120
  "files": ["AGENTS.md", "CLAUDE.md", "GEMINI.md", ".github/copilot-instructions.md"],
121
+ // Plugins with custom rules, see "Plugins" below
122
+ "jsPlugins": ["./lint/agentfile-plugin.js"],
123
+ // Shared with all rules as `context.settings`
124
+ "settings": {},
115
125
  }
116
126
  ```
117
127
 
@@ -145,37 +155,24 @@ description: Deploys the app. Use when the user asks for a deployment.
145
155
  ---
146
156
  ```
147
157
 
148
- A directive with a name that isn't a rule (usually a typo, or a reason without the `--`
149
- separator) suppresses nothing for that name. agentfile-linter reports each such name as an `info`
150
- diagnostic, with a suggestion when the name is close to a rule. Infos don't count as warnings or
151
- errors, so they don't change the exit code, and `--quiet` hides them.
152
-
153
- Directives that suppress nothing are reported as `info` too: a directive without rule names where no
154
- rule reports a problem, or a listed rule that reports no problem where the directive applies. Only
155
- rules that checked the file count, so a directive for a rule that is off (or that doesn't check this
156
- kind of file) is never reported. Neither is a directive that
157
- [`agentfile/keep-agents-file-up-to-date`](#agentfilekeep-agents-file-up-to-date) may need, because
158
- its problems depend on the current date. Set `"reportUnnecessarySuppressions": false` in the config
159
- to turn these reports off.
160
-
161
- ## Rules
162
-
163
- | Rule | Category | Checks |
164
- | -------------------------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------- |
165
- | [`agentfile/no-missing-path`](#agentfileno-missing-path) | recommended | Referenced files and directories exist |
166
- | [`agentfile/no-missing-script`](#agentfileno-missing-script) | recommended | Documented scripts and tasks (npm, make, just, uv, maven, cargo, …) exist |
167
- | [`agentfile/no-broken-reference`](#agentfileno-broken-reference) | recommended | Relative links, images, `#anchors` and `#L42` line fragments resolve |
168
- | [`agentfile/no-agent-files-drift`](#agentfileno-agent-files-drift) | recommended | Agent files in one directory are identical or symlinked |
169
- | [`agentfile/no-invalid-skill`](#agentfileno-invalid-skill) | recommended | Skill directories have a valid layout and valid `SKILL.md` frontmatter |
170
- | [`agentfile/no-misnamed-agent-file`](#agentfileno-misnamed-agent-file) | recommended | Agent files are spelled in the exact case agents look for |
171
- | [`agentfile/no-unnecessary-agent-files`](#agentfileno-unnecessary-agent-files) | – | No `CLAUDE.md` that only mirrors `AGENTS.md` |
172
- | [`agentfile/keep-agents-file-up-to-date`](#agentfilekeep-agents-file-up-to-date) | – | Context files were changed recently |
173
-
174
- Rules in the `recommended` category run by default. The others are off until you enable them in `rules`, e.g. `"agentfile/keep-agents-file-up-to-date": "warn"`.
158
+ A directive with a name that isn't a rule (usually a typo, or a reason without the `--` separator) suppresses nothing for that name. agentfile-linter reports each such name as an `info` diagnostic, with a suggestion when the name is close to a rule. Infos don't count as warnings or errors, so they don't change the exit code, and `--quiet` hides them.
159
+
160
+ Directives that suppress nothing are reported as `info` too: a directive without rule names where no rule reports a problem, or a listed rule that reports no problem where the directive applies. Only rules that checked the file count, so a directive for a rule that is off (or that doesn't check this kind of file) is never reported. Neither is a directive that [`agentfile/keep-agents-file-up-to-date`](#agentfilekeep-agents-file-up-to-date) may need, because its problems depend on the current date. Set `"reportUnnecessarySuppressions": false` in the config to turn these reports off.
161
+
162
+ ## Plugins
163
+
164
+ Load custom rules with `jsPlugins` and enable them in `rules` using their`<plugin>/<rule>` names. The [plugin API guide](docs/plugin-api.md) covers configuration, plugin authoring, and compatibility with ESLint and Oxlint.
165
+
166
+ The npm package ships the guide at `node_modules/agentfile-linter/docs/plugin-api.md`, alongside the types for the installed version. Point your coding agent to that if they have trouble writing custom plugins.
167
+
168
+ ## Rule details
175
169
 
176
170
  ### `agentfile/no-missing-path`
177
171
 
178
- Checks inline code spans that look like paths, plus `@path/to/file.md` imports (the import syntax of Claude Code and Gemini CLI).
172
+ Checks path-like code spans and `@path/to/file.md` imports in context files.
173
+
174
+ <details>
175
+ <summary>Details and configuration options</summary>
179
176
 
180
177
  - **What counts as a path:** a span with a known file extension (`src/index.ts`, `package.json`), a `./` or `../` prefix, a trailing slash (`docs/`), a dotfile (`.env.example`), a well-known file name (`Makefile`, `Dockerfile`, …) or a glob (`src/**/*.test.ts`).
181
178
  - **Slash paths without an extension** (`src/components`) are checked only when their first segment exists. Module names like `react-dom/client` or `origin/main` are therefore ignored.
@@ -192,9 +189,14 @@ Checks inline code spans that look like paths, plus `@path/to/file.md` imports (
192
189
  | `allowSuffixMatch` | `true` | Accept paths that match the end of a project path |
193
190
  | `checkImports` | `true` | Check `@path` imports |
194
191
 
192
+ </details>
193
+
195
194
  ### `agentfile/no-missing-script`
196
195
 
197
- Finds task-runner commands in inline code and in shell code blocks (`sh`, `bash`, `console`, untagged, …). It then checks that the script, target or task exists where the command would run.
196
+ Finds documented task-runner commands and checks whether each script, target or task exists.
197
+
198
+ <details>
199
+ <summary>Details and configuration options</summary>
198
200
 
199
201
  - **Working directory:** the context file's directory. `cd dir && …` is followed, and so is `cd` across the lines of one code block. Relative directories (`cd apps/web`, `make -C sub`) are resolved from the file's directory first, then from its parent directories up to the project root.
200
202
  - **Config files are searched upward.** That covers `package.json`, `Makefile`, `justfile` and the others in the table below.
@@ -233,14 +235,18 @@ Each runner stays quiet when it can't decide statically. Examples: computed Make
233
235
  | `ignore` | `[]` | Glob patterns of script, target or task names to skip |
234
236
  | `ignoreRunners` | `[]` | Runners not to check, e.g. `["maven", "gradle"]`. Runner ids: `npm`, `pnpm`, `yarn`, `bun`, `deno`, `make`, `just`, `task`, `poetry`, `uv`, `pdm`, `rye`, `hatch`, `pipenv`, `poe`, `tox`, `nox`, `maven`, `gradle`, `composer`, `cargo` |
235
237
 
238
+ </details>
239
+
236
240
  ### `agentfile/no-broken-reference`
237
241
 
238
- Checks relative Markdown links, images, reference definitions and `href`/`src` in inline HTML.
242
+ Checks relative Markdown links, images, reference definitions and inline HTML link targets.
243
+
244
+ <details>
245
+ <summary>Details and configuration options</summary>
239
246
 
240
247
  - `#anchor` must match a heading in the same file, using GitHub-style slugs. Duplicate headings get `-1`, `-2` suffixes. Explicit `id`/`name` anchors also count.
241
248
  - `other.md#anchor` must match a heading in the target Markdown file.
242
- - Line fragments (`src/app.ts#L42`, `#L42-L50`, `#L42-50`, `#L10C5-L12C20`) must point at lines
243
- that exist in the target file. Line numbers start at 1, and a range must not end before it starts. GitHub renders Markdown files, so there `#L10` is checked as a heading anchor, unless the link opens the source view (`guide.md?plain=1#L10`, `?plain=1#L10` for the linted file). Directories, binary files, Git LFS pointers and git-ignored files (often generated) are not checked.
249
+ - Line fragments (`src/app.ts#L42`, `#L42-L50`, `#L42-50`, `#L10C5-L12C20`) must point at lines that exist in the target file. Line numbers start at 1, and a range must not end before it starts. GitHub renders Markdown files, so there `#L10` is checked as a heading anchor, unless the link opens the source view (`guide.md?plain=1#L10`, `?plain=1#L10` for the linted file). Directories, binary files, Git LFS pointers and git-ignored files (often generated) are not checked.
244
250
  - Root-relative links (`/docs/x.md`) resolve against the project root, as on GitHub.
245
251
  - External URLs (`https:`, `mailto:`, `//cdn…`) and git-ignored targets are skipped.
246
252
 
@@ -250,9 +256,16 @@ Checks relative Markdown links, images, reference definitions and `href`/`src` i
250
256
  | `checkLines` | `true` | Check `#L42` line fragments against the file length |
251
257
  | `ignore` | `[]` | Glob patterns of link targets to skip |
252
258
 
259
+ </details>
260
+
253
261
  ### `agentfile/no-agent-files-drift`
254
262
 
255
- The agent files in one directory (`AGENTS.md`, `AGENT.md`, `CLAUDE.md`, `GEMINI.md`) must have the same effective content. A file passes when it:
263
+ Checks that agent files in the same directory have the same effective content.
264
+
265
+ <details>
266
+ <summary>Details and configuration options</summary>
267
+
268
+ A file passes when it:
256
269
 
257
270
  - is a symlink to another file in the group,
258
271
  - has identical text (differences in BOM, line endings and trailing whitespace are ignored), or
@@ -265,9 +278,16 @@ The first existing file in `files` order is canonical. Every other file is compa
265
278
  | `files` | `["AGENTS.md", "AGENT.md", "CLAUDE.md", "GEMINI.md"]` | Files that must stay in sync, in order of precedence |
266
279
  | `allowImports` | `true` | Accept `@OTHER.md` pointer files |
267
280
 
281
+ </details>
282
+
268
283
  ### `agentfile/no-invalid-skill`
269
284
 
270
- Checks [Agent Skills](https://agentskills.io/specification) instead of context files. It looks for skills directories below the linted directories: `.claude/skills`, `.agents/skills`, `.github/skills`, `.codex/skills`, `.gemini/skills`, `.cursor/skills`, `.devin/skills`, `.windsurf/skills` and `.kiro/skills` at any depth. It also checks the `skills/` directory of every Claude Code plugin (a directory in the project with `.claude-plugin/plugin.json`). Git-ignored skills and skills matching `ignorePatterns` are skipped.
285
+ Checks Agent Skills directories for valid layout and `SKILL.md` frontmatter.
286
+
287
+ <details>
288
+ <summary>Details and configuration options</summary>
289
+
290
+ It looks for skills directories below the linted directories: `.claude/skills`, `.agents/skills`, `.github/skills`, `.codex/skills`, `.gemini/skills`, `.cursor/skills`, `.devin/skills`, `.windsurf/skills` and `.kiro/skills` at any depth. It also checks the `skills/` directory of every Claude Code plugin (a directory in the project with `.claude-plugin/plugin.json`). Git-ignored skills and skills matching `ignorePatterns` are skipped.
271
291
 
272
292
  Skills directories are matched by their path relative to the project root (the Git root, or the linted directory outside Git), never by directories above it. In a repository whose root is a `.claude` directory, configure `"directories": ["skills"]`.
273
293
 
@@ -297,8 +317,15 @@ Grouping folders (`skills/review/security/SKILL.md`, supported by Codex, Cursor
297
317
 
298
318
  `overrides` apply per skill. For example, `"files": [".claude/skills/legacy/**"]` changes the rule for one skill. An override can match the skill file or the skills root; one that matches the skills root (`"files": ["custom"]`) applies its severity and all options to every skill in it.
299
319
 
320
+ </details>
321
+
300
322
  ### `agentfile/no-misnamed-agent-file`
301
323
 
324
+ Reports context files whose names differ from the expected names by case.
325
+
326
+ <details>
327
+ <summary>Details and configuration options</summary>
328
+
302
329
  Agents look for `AGENTS.md`, `AGENT.md`, `CLAUDE.md`, `CLAUDE.local.md` and `GEMINI.md` by their exact name. On case-insensitive file systems (the macOS and Windows default), `agents.md` or `CLAUDE.MD` is found anyway, so the mistake goes unnoticed until a teammate or CI runs on Linux, where the file is silently ignored. This rule reports such files:
303
330
 
304
331
  - A name that only differs in the case of its extension (`AGENTS.MD`, `CLAUDE.Md`) is reported anywhere.
@@ -306,9 +333,16 @@ Agents look for `AGENTS.md`, `AGENT.md`, `CLAUDE.md`, `CLAUDE.local.md` and `GEM
306
333
 
307
334
  A file is never reported when the correctly named file exists next to it (possible on case-sensitive file systems) or when it matches the [`files`](#options) patterns, and git-ignored files are skipped unless named on the command line. A `SKILL.md` in the wrong case is reported by [`agentfile/no-invalid-skill`](#agentfileno-invalid-skill). Rename tracked files with `git mv`: on case-insensitive file systems, Git doesn't notice a plain rename that only changes case.
308
335
 
336
+ </details>
337
+
309
338
  ### `agentfile/no-unnecessary-agent-files`
310
339
 
311
- Off by default. Since v2.1.277, Claude Code reads `AGENTS.md` when there is no `CLAUDE.md`, so one `AGENTS.md` can serve all agents. This rule reports a `CLAUDE.md` that only mirrors the `AGENTS.md` in its directory. That is the case when `CLAUDE.md`:
340
+ Off by default. Reports a `CLAUDE.md` that only mirrors the `AGENTS.md` in its directory.
341
+
342
+ <details>
343
+ <summary>Details and configuration options</summary>
344
+
345
+ Since v2.1.277, Claude Code reads `AGENTS.md` when there is no `CLAUDE.md`, so one `AGENTS.md` can serve all agents. A `CLAUDE.md` is considered a mirror when it:
312
346
 
313
347
  - is a symlink to `AGENTS.md` (or the other way around, or both link to the same file),
314
348
  - has the same content (differences in BOM, line endings and trailing whitespace are ignored), or
@@ -320,9 +354,16 @@ The rule only looks inside the project (the Git repository), so it gives the sam
320
354
 
321
355
  Keep the `CLAUDE.md` if your team uses older Claude Code versions or sets "Project instructions"to `claude-md` in `/config`.
322
356
 
357
+ </details>
358
+
323
359
  ### `agentfile/keep-agents-file-up-to-date`
324
360
 
325
- Off by default. Reports context files that have not changed for more than `warnIfNotUpdatedForDays`. Agent instructions go stale as a project changes. Any change, even a small one, resets the timer: a commit in Git, otherwise any edit to the file.
361
+ Off by default. Reports context files not changed in more than `warnIfNotUpdatedForDays`.
362
+
363
+ <details>
364
+ <summary>Details and configuration options</summary>
365
+
366
+ Agent instructions go stale as a project changes. Any change, even a small one, resets the timer: a commit in Git, otherwise any edit to the file.
326
367
 
327
368
  ```jsonc
328
369
  "rules": {
@@ -343,6 +384,36 @@ Off by default. Reports context files that have not changed for more than `warnI
343
384
  | `warnIfNotUpdatedForDays` | `120` | Report files not changed for more than this many days (a number or a string like `"30"`) |
344
385
  | `warnOnlyForFilesLongerThanChars` | `0` | Skip files with at most this many characters (ignoring surrounding whitespace), e.g. pointers |
345
386
 
387
+ </details>
388
+
389
+ ### `agentfile/limit-file-size`
390
+
391
+ Off by default. Reports context files longer than `maxChars` characters.
392
+
393
+ <details>
394
+ <summary>Details and configuration options</summary>
395
+
396
+ Some agents also enforce limits: Codex stops reading `AGENTS.md` files once their combined size reaches 32 KiB (`project_doc_max_bytes`), and Claude Code warns about a `CLAUDE.md` with more than 40,000 characters.
397
+
398
+ ```jsonc
399
+ "rules": {
400
+ "agentfile/limit-file-size": ["warn", { "maxChars": 10000 }],
401
+ }
402
+ ```
403
+
404
+ - Characters are counted as they are displayed (Unicode grapheme clusters), not as bytes or UTF-16 code units: `é`, `日`, `👍🏽`, `🇦🇹` and `👨‍👩‍👧` count as one character each, whether a letter is precomposed or written with combining marks. A CRLF line break counts as one character, like LF, and a byte order mark doesn't count. Everything else counts, including whitespace, Markdown syntax, comments and frontmatter, since agents read them too.
405
+ - Characters are a model-independent stand-in for tokens. English text averages about 4 characters per token; Chinese, Japanese and Korean text uses more tokens per character, so consider a lower limit for such files.
406
+ - Each file is measured on its own: files it imports (`@path`) and context files in parent directories are not added.
407
+ - The problem is reported at the first character past the limit. Use [`overrides`](#configuration) to allow more characters in specific files.
408
+
409
+ | Option | Default | Description |
410
+ | ---------- | ------- | ----------------------------------------------------------------------------------- |
411
+ | `maxChars` | `20000` | Report files with more characters than this (an integer or a string like `"20000"`) |
412
+
413
+ The default is about 5,000 tokens of English text. It leaves room for the `AGENTS.md` files of parent directories within Codex's 32 KiB.
414
+
415
+ </details>
416
+
346
417
  ## Programmatic API
347
418
 
348
419
  ```ts
@@ -364,4 +435,12 @@ bun run schema # regenerate configuration_schema.json after changing rule o
364
435
  bun run lint:self # lint this repository's own AGENTS.md
365
436
  ```
366
437
 
438
+ Run the CLI from source with `bun run src/cli.ts .`. To build standalone executables with [Bun](https://bun.sh):
439
+
440
+ ```sh
441
+ bun install
442
+ bun run build # dist/agentfile-linter for the current platform
443
+ bun run build:all # dist/agentfile-linter-<os>-<arch> for every supported target
444
+ ```
445
+
367
446
  Imports outside the current directory use the `package.json` subpath imports `#src/*` and `#test/*`, e.g. `import { lint } from "#src/linter.ts"`.