agentsmd-check 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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # agentsmd-check
2
+
3
+ [![CI](https://github.com/7y-9/agentsmd-check/actions/workflows/ci.yml/badge.svg)](https://github.com/7y-9/agentsmd-check/actions/workflows/ci.yml)
4
+
5
+ <p align="center">
6
+ <img src="docs/assets/logo.png" alt="agentsmd-check logo" width="260">
7
+ </p>
8
+
9
+ Scan your repo. Diagnose whether `AGENTS.md` is accurate, executable, safe, and useful for coding agents.
10
+
11
+ `agentsmd-check` is a local diagnostic tool and CI checker for `AGENTS.md`.
12
+ It is not an agent framework, and it is not a general prompt management platform.
13
+
14
+ > Status: early v0 CLI. The checker can be installed, run, and fail with actionable diagnostics.
15
+
16
+ <p align="center">
17
+ <img src="docs/assets/overview.png" alt="agentsmd-check overview" width="820">
18
+ </p>
19
+
20
+ ## Why
21
+
22
+ `AGENTS.md` is becoming the README for AI coding agents: project overview, build commands, test commands, code style, safety notes, and repository-specific rules.
23
+
24
+ The problem is that these files go stale.
25
+
26
+ Common examples:
27
+
28
+ - `AGENTS.md` says `npm test`, but the repo now uses `pnpm test`
29
+ - it tells agents to run `make check`, but the `Makefile` has no `check` target
30
+ - it references `docs/architecture.md`, but the file no longer exists
31
+ - it asks agents to run unsafe shell patterns such as piping remote scripts into `sh`
32
+ - it gives broad instructions but misses the actual test or style commands agents need
33
+
34
+ `agentsmd-check` catches those problems before a human or coding agent follows stale instructions.
35
+
36
+ ## What It Checks Today
37
+
38
+ Current v0 checks:
39
+
40
+ | Area | What it diagnoses |
41
+ | --- | --- |
42
+ | File discovery | Missing root `AGENTS.md` |
43
+ | Markdown | Headings, list items, fenced code blocks, and inline code |
44
+ | Paths | Referenced files such as `docs/guide.md` or `.github/workflows/ci.yml` that are missing |
45
+ | Package commands | Lockfile package manager mismatches and missing `package.json` scripts |
46
+ | Safety | Dangerous command patterns such as `curl ... \| sh` |
47
+ | Coverage | Missing sections for tests, style, build, or safety notes |
48
+
49
+ The goal is not to grade writing style. The goal is to answer:
50
+
51
+ 1. Can an agent follow this file?
52
+ 2. Are the commands real?
53
+ 3. Are the referenced files real?
54
+ 4. Are the instructions safe enough to run in a coding workflow?
55
+
56
+ ## CLI
57
+
58
+ Requires Node.js 24 or newer.
59
+
60
+ ```bash
61
+ npm install --save-dev agentsmd-check
62
+ npm exec agentsmd-check check
63
+ npx agentsmd-check check
64
+ npx agentsmd-check check --format json
65
+ npx agentsmd-check check --fail-on-warning
66
+ ```
67
+
68
+ JSON output is stable for tool integrations. Every issue has these fields:
69
+
70
+ ```json
71
+ {
72
+ "code": "SCRIPT001",
73
+ "severity": "error",
74
+ "file": "AGENTS.md",
75
+ "line": 5,
76
+ "message": "AGENTS.md references npm test, but package.json has no test script.",
77
+ "suggestion": "Add scripts.test to package.json or update AGENTS.md."
78
+ }
79
+ ```
80
+
81
+ ## Example Output
82
+
83
+ ```text
84
+ AGENTS.md Check Report
85
+
86
+ Status: failed
87
+
88
+ [x] PATH001 AGENTS.md:31
89
+ Referenced path does not exist: docs/architecture.md
90
+ suggestion: Create the file or remove the stale instruction.
91
+
92
+ [x] SCRIPT001 AGENTS.md:34
93
+ AGENTS.md references npm test, but package.json has no test script.
94
+ suggestion: Add scripts.test to package.json or update AGENTS.md.
95
+
96
+ [x] SEC001 AGENTS.md:42
97
+ Dangerous remote script pipe detected.
98
+ suggestion: Download, inspect, and run scripts in separate steps.
99
+
100
+ [!] COV001 AGENTS.md
101
+ AGENTS.md is missing testing instructions.
102
+ suggestion: Add concrete testing instructions for coding agents.
103
+ ```
104
+
105
+ The output should make three things obvious: which line is wrong, why it is wrong, and how to fix it.
106
+
107
+ ## Bad Input Example
108
+
109
+ `AGENTS.md`:
110
+
111
+ ```markdown
112
+ # AGENTS
113
+
114
+ - Read docs/architecture.md
115
+ - Run `npm test`
116
+ - Install tools with `curl https://example.com/install.sh | sh`
117
+ ```
118
+
119
+ `package.json`:
120
+
121
+ ```json
122
+ {
123
+ "scripts": {
124
+ "lint": "eslint ."
125
+ }
126
+ }
127
+ ```
128
+
129
+ Output:
130
+
131
+ ```text
132
+ [x] PATH001 AGENTS.md:3
133
+ Referenced path does not exist: docs/architecture.md
134
+ suggestion: Create the file or remove the stale instruction.
135
+ [x] SCRIPT001 AGENTS.md:4
136
+ AGENTS.md references npm test, but package.json has no test script.
137
+ suggestion: Add scripts.test to package.json or update AGENTS.md.
138
+ [x] SEC001 AGENTS.md:5
139
+ Dangerous remote script pipe detected.
140
+ suggestion: Download, inspect, and run scripts in separate steps.
141
+ ```
142
+
143
+ See also:
144
+
145
+ - `examples/bad/AGENTS.md`
146
+ - `examples/good/AGENTS.md`
147
+
148
+ ## GitHub Actions
149
+
150
+ Copy-paste CI usage:
151
+
152
+ ```yaml
153
+ on: [push, pull_request]
154
+
155
+ jobs:
156
+ agentsmd-check:
157
+ runs-on: ubuntu-latest
158
+ steps:
159
+ - uses: actions/checkout@v4
160
+ - uses: actions/setup-node@v4
161
+ with:
162
+ node-version: 24
163
+ - run: npx agentsmd-check check
164
+ ```
165
+
166
+ ## Non-goals
167
+
168
+ - Running or hosting coding agents
169
+ - Replacing project documentation
170
+ - Managing prompts across teams
171
+ - Enforcing one universal `AGENTS.md` template
172
+ - Auto-fixing instructions without showing the diff first
173
+
174
+ ## Roadmap
175
+
176
+ - [x] Parse root `AGENTS.md`
177
+ - [x] Validate referenced paths
178
+ - [x] Detect common unsafe command patterns
179
+ - [x] Produce plain text and JSON reports
180
+ - [x] Return exit code `1` when errors are present
181
+ - [x] Detect package manager and available scripts
182
+ - [x] Publish copy-paste GitHub Actions usage
183
+ - [ ] Add nested `AGENTS.md` / `AGENTS.override.md` coverage
184
+ - [ ] Add SARIF output for GitHub code scanning
185
+ - [ ] Add `fix --dry-run`
186
+
187
+ ## Contributing
188
+
189
+ This is my first open source project. Small, practical contributions are welcome:
190
+
191
+ - examples of stale `AGENTS.md` instructions
192
+ - false positives and false negatives
193
+ - rule ideas with a real repository example
194
+ - documentation fixes
195
+
196
+ Please keep rules concrete. A good rule should point to a real line, explain the problem, and suggest a fix.
197
+
198
+ ## License
199
+
200
+ Apache-2.0
package/dist/check.js ADDED
@@ -0,0 +1,390 @@
1
+ import { access, readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ const AGENTS_FILE = "AGENTS.md";
37
+ const PACKAGE_FILE = "package.json";
38
+
39
+ export function parseMarkdown(markdown ) {
40
+ const facts = { headings: [], listItems: [], codeBlocks: [], inlineCode: [] };
41
+ const lines = markdown.split(/\r?\n/);
42
+ let codeBlock ;
43
+
44
+ lines.forEach((line, index) => {
45
+ const lineNumber = index + 1;
46
+ const fence = line.match(/^\s*```\s*([A-Za-z0-9_-]*)\s*$/);
47
+
48
+ if (fence) {
49
+ if (codeBlock) {
50
+ facts.codeBlocks.push({
51
+ line: codeBlock.line,
52
+ language: codeBlock.language,
53
+ text: codeBlock.lines.join("\n"),
54
+ });
55
+ codeBlock = undefined;
56
+ } else {
57
+ codeBlock = { line: lineNumber + 1, language: fence[1] ?? "", lines: [] };
58
+ }
59
+ return;
60
+ }
61
+
62
+ if (codeBlock) {
63
+ codeBlock.lines.push(line);
64
+ return;
65
+ }
66
+
67
+ const heading = line.match(/^\s{0,3}#{1,6}\s+(.+?)\s*#*\s*$/);
68
+ if (heading) facts.headings.push({ line: lineNumber, text: heading[1] });
69
+
70
+ const listItem = line.match(/^\s*(?:[-*+]|\d+\.)\s+(.+)$/);
71
+ if (listItem) facts.listItems.push({ line: lineNumber, text: listItem[1] });
72
+
73
+ for (const match of line.matchAll(/`([^`\n]+)`/g)) {
74
+ facts.inlineCode.push({ line: lineNumber, text: match[1] });
75
+ }
76
+ });
77
+
78
+ if (codeBlock) {
79
+ facts.codeBlocks.push({ line: codeBlock.line, language: codeBlock.language, text: codeBlock.lines.join("\n") });
80
+ }
81
+
82
+ return facts;
83
+ }
84
+
85
+ export async function checkProject(root , options = {}) {
86
+ const absoluteRoot = path.resolve(root);
87
+ const agentsPath = path.join(absoluteRoot, AGENTS_FILE);
88
+ const issues = [];
89
+
90
+ if (!(await exists(agentsPath))) {
91
+ issues.push(issue({
92
+ code: "FILE001",
93
+ severity: "error",
94
+ file: AGENTS_FILE,
95
+ message: "Root AGENTS.md was not found.",
96
+ suggestion: "Add AGENTS.md at the repository root.",
97
+ }));
98
+ return report(absoluteRoot, issues, options);
99
+ }
100
+
101
+ const markdown = await readFile(agentsPath, "utf8");
102
+ const facts = parseMarkdown(markdown);
103
+
104
+ issues.push(...(await checkPathReferences(absoluteRoot, markdown)));
105
+ issues.push(...checkSafety(markdown));
106
+ issues.push(...(await checkPackageCommands(absoluteRoot, markdown)));
107
+ issues.push(...checkCoverage(facts));
108
+
109
+ return report(absoluteRoot, issues, options);
110
+ }
111
+
112
+ export function formatPlain(report ) {
113
+ const lines = ["AGENTS.md Check Report", "", `Status: ${report.ok ? "ok" : "failed"}`, ""];
114
+
115
+ if (report.issues.length === 0) {
116
+ lines.push("[ok] no issues found");
117
+ return lines.join("\n");
118
+ }
119
+
120
+ for (const issue of report.issues) {
121
+ const marker = issue.severity === "error" ? "x" : issue.severity === "warning" ? "!" : "i";
122
+ const location = issue.line === null ? issue.file : `${issue.file}:${issue.line}`;
123
+ lines.push(`[${marker}] ${issue.code} ${location}`);
124
+ lines.push(` ${issue.message}`);
125
+ if (issue.suggestion) lines.push(` suggestion: ${issue.suggestion}`);
126
+ }
127
+
128
+ return lines.join("\n");
129
+ }
130
+
131
+ function report(root , issues , options ) {
132
+ const errors = issues.filter((issue) => issue.severity === "error").length;
133
+ const warnings = issues.filter((issue) => issue.severity === "warning").length;
134
+
135
+ return {
136
+ ok: errors === 0 && (!options.failOnWarning || warnings === 0),
137
+ root,
138
+ issues,
139
+ stats: { errors, warnings },
140
+ };
141
+ }
142
+
143
+ async function checkPathReferences(root , markdown ) {
144
+ const issues = [];
145
+ const seen = new Set ();
146
+ const lines = markdown.split(/\r?\n/);
147
+ const pathPattern = /(?:\.?\.?\/)?(?:[A-Za-z0-9_.-]+\/)+[A-Za-z0-9_.-]+\.[A-Za-z0-9]+/g;
148
+
149
+ for (const [index, line] of lines.entries()) {
150
+ for (const match of line.matchAll(pathPattern)) {
151
+ const candidate = match[0];
152
+ if (looksLikeUrlHost(candidate) || candidate.includes("://")) continue;
153
+
154
+ const resolved = path.resolve(root, candidate);
155
+ if (!isInside(root, resolved)) continue;
156
+
157
+ const key = `${index + 1}:${candidate}`;
158
+ if (seen.has(key)) continue;
159
+ seen.add(key);
160
+
161
+ if (!(await exists(resolved))) {
162
+ issues.push(issue({
163
+ code: "PATH001",
164
+ severity: "error",
165
+ file: AGENTS_FILE,
166
+ line: index + 1,
167
+ message: `Referenced path does not exist: ${candidate}`,
168
+ suggestion: "Create the file or remove the stale instruction.",
169
+ }));
170
+ }
171
+ }
172
+ }
173
+
174
+ return issues;
175
+ }
176
+
177
+ function checkSafety(markdown ) {
178
+ const issues = [];
179
+ const lines = markdown.split(/\r?\n/);
180
+
181
+ lines.forEach((line, index) => {
182
+ const lineNumber = index + 1;
183
+
184
+ if (/\b(?:curl|wget)\b[^|\n]*\|\s*(?:sh|bash)\b/i.test(line)) {
185
+ issues.push(issue({
186
+ code: "SEC001",
187
+ severity: "error",
188
+ file: AGENTS_FILE,
189
+ line: lineNumber,
190
+ message: "Dangerous remote script pipe detected.",
191
+ suggestion: "Download, inspect, and run scripts in separate steps.",
192
+ }));
193
+ }
194
+
195
+ if (/\brm\s+-[A-Za-z]*r[A-Za-z]*f[A-Za-z]*\s+["']?\/["']?(?:\s|$)/i.test(line)) {
196
+ issues.push(issue({
197
+ code: "SEC002",
198
+ severity: "error",
199
+ file: AGENTS_FILE,
200
+ line: lineNumber,
201
+ message: "Dangerous recursive root removal command detected.",
202
+ suggestion: "Remove this instruction or scope deletion to a safe project path.",
203
+ }));
204
+ }
205
+
206
+ if (/\b(?:token|api[_-]?key|secret|password)\s*[:=]\s*["']?[A-Za-z0-9_.-]{6,}/i.test(line)) {
207
+ issues.push(issue({
208
+ code: "SEC003",
209
+ severity: "error",
210
+ file: AGENTS_FILE,
211
+ line: lineNumber,
212
+ message: "Possible exposed credential detected.",
213
+ suggestion: "Remove the value and reference an environment variable instead.",
214
+ }));
215
+ }
216
+ });
217
+
218
+ return issues;
219
+ }
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+ async function checkPackageCommands(root , markdown ) {
231
+ const packagePath = path.join(root, PACKAGE_FILE);
232
+ if (!(await exists(packagePath))) return [];
233
+
234
+ let packageJson ;
235
+ try {
236
+ packageJson = JSON.parse(await readFile(packagePath, "utf8"));
237
+ } catch {
238
+ return [
239
+ issue({
240
+ code: "PKG001",
241
+ severity: "error",
242
+ file: PACKAGE_FILE,
243
+ message: "package.json could not be parsed.",
244
+ suggestion: "Fix package.json so AGENTS.md commands can be checked.",
245
+ }),
246
+ ];
247
+ }
248
+
249
+ const scriptsCandidate =
250
+ packageJson && typeof packageJson === "object" && "scripts" in packageJson
251
+ ? (packageJson ).scripts
252
+ : undefined;
253
+ const scripts =
254
+ scriptsCandidate && typeof scriptsCandidate === "object" && !Array.isArray(scriptsCandidate)
255
+ ? (scriptsCandidate )
256
+ : {};
257
+ const detectedManager = await detectPackageManager(root);
258
+ const issues = [];
259
+ const seen = new Set ();
260
+
261
+ for (const command of extractPackageCommands(markdown)) {
262
+ const key = `${command.line}:${command.text}`;
263
+ if (seen.has(key)) continue;
264
+ seen.add(key);
265
+
266
+ if (detectedManager && command.manager !== detectedManager.name) {
267
+ issues.push(
268
+ issue({
269
+ code: "PM001",
270
+ severity: "error",
271
+ file: AGENTS_FILE,
272
+ line: command.line,
273
+ message: `AGENTS.md references ${command.text}, but ${detectedManager.file} suggests ${detectedManager.name}.`,
274
+ suggestion: `Use ${detectedManager.name} for package commands or update the lockfile.`,
275
+ })
276
+ );
277
+ }
278
+
279
+ if (!Object.prototype.hasOwnProperty.call(scripts, command.script)) {
280
+ issues.push(
281
+ issue({
282
+ code: "SCRIPT001",
283
+ severity: "error",
284
+ file: AGENTS_FILE,
285
+ line: command.line,
286
+ message: `AGENTS.md references ${command.text}, but package.json has no ${command.script} script.`,
287
+ suggestion: `Add scripts.${command.script} to package.json or update AGENTS.md.`,
288
+ })
289
+ );
290
+ }
291
+ }
292
+
293
+ return issues;
294
+ }
295
+
296
+ async function detectPackageManager(root ) {
297
+ for (const [name, file] of [
298
+ ["pnpm", "pnpm-lock.yaml"],
299
+ ["yarn", "yarn.lock"],
300
+ ["npm", "package-lock.json"],
301
+ ] ) {
302
+ if (await exists(path.join(root, file))) return { name, file };
303
+ }
304
+ }
305
+
306
+ function extractPackageCommands(markdown ) {
307
+ const commands = [];
308
+ const lines = markdown.split(/\r?\n/);
309
+ const commandPattern = /\b(npm|pnpm|yarn)\s+(?:(run)\s+)?([A-Za-z0-9:_-]+)/g;
310
+
311
+ lines.forEach((line, index) => {
312
+ for (const match of line.matchAll(commandPattern)) {
313
+ const manager = match[1] ;
314
+ const script = scriptNameForCommand(manager, Boolean(match[2]), match[3]);
315
+ if (!script) continue;
316
+
317
+ commands.push({
318
+ manager,
319
+ script,
320
+ text: match[0],
321
+ line: index + 1,
322
+ });
323
+ }
324
+ });
325
+
326
+ return commands;
327
+ }
328
+
329
+ function scriptNameForCommand(manager , hasRun , command ) {
330
+ if (hasRun) return command;
331
+ if (command === "test") return "test";
332
+ if ((manager === "pnpm" || manager === "yarn") && ["build", "lint", "check", "format", "typecheck"].includes(command)) {
333
+ return command;
334
+ }
335
+ }
336
+
337
+ function checkCoverage(facts ) {
338
+ const text = [
339
+ ...facts.headings.map((item) => item.text),
340
+ ...facts.listItems.map((item) => item.text),
341
+ ...facts.inlineCode.map((item) => item.text),
342
+ ...facts.codeBlocks.map((item) => item.text),
343
+ ]
344
+ .join("\n")
345
+ .toLowerCase();
346
+
347
+ const required = [
348
+ ["COV001", "test", "testing instructions"],
349
+ ["COV002", "build", "build instructions"],
350
+ ["COV003", "lint", "style or lint instructions"],
351
+ ["COV004", "safe", "safety notes"],
352
+ ] ;
353
+
354
+ return required
355
+ .filter(([, token]) => !text.includes(token))
356
+ .map(([code, , label]) => issue({
357
+ code,
358
+ severity: "warning" ,
359
+ file: AGENTS_FILE,
360
+ message: `AGENTS.md is missing ${label}.`,
361
+ suggestion: `Add concrete ${label} for coding agents.`,
362
+ }));
363
+ }
364
+
365
+ async function exists(filePath ) {
366
+ try {
367
+ await access(filePath);
368
+ return true;
369
+ } catch {
370
+ return false;
371
+ }
372
+ }
373
+
374
+ function isInside(root , target ) {
375
+ const relative = path.relative(root, target);
376
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
377
+ }
378
+
379
+ function looksLikeUrlHost(candidate ) {
380
+ const firstSegment = candidate.split("/")[0];
381
+ return firstSegment.includes(".") && !firstSegment.startsWith(".");
382
+ }
383
+
384
+ function issue(input ) {
385
+ return {
386
+ line: null,
387
+ suggestion: null,
388
+ ...input,
389
+ };
390
+ }
package/dist/cli.js ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+ import { checkProject, formatPlain } from "./check.js";
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ async function main(argv ) {
12
+ const options = parseArgs(argv);
13
+
14
+ if (options.command !== "check") {
15
+ console.error("Usage: agentsmd-check check [--format plain|json] [--fail-on-warning] [--cwd <path>]");
16
+ return 2;
17
+ }
18
+
19
+ const report = await checkProject(options.cwd, { failOnWarning: options.failOnWarning });
20
+
21
+ if (options.format === "json") {
22
+ console.log(JSON.stringify(report, null, 2));
23
+ } else {
24
+ console.log(formatPlain(report));
25
+ }
26
+
27
+ return report.ok ? 0 : 1;
28
+ }
29
+
30
+ function parseArgs(argv ) {
31
+ const options = {
32
+ command: argv[0],
33
+ cwd: process.cwd(),
34
+ failOnWarning: false,
35
+ format: "plain",
36
+ };
37
+
38
+ for (let index = 1; index < argv.length; index += 1) {
39
+ const arg = argv[index];
40
+
41
+ if (arg === "--fail-on-warning") {
42
+ options.failOnWarning = true;
43
+ } else if (arg === "--format") {
44
+ const value = argv[++index];
45
+ if (value === "json" || value === "plain" || value === "text") {
46
+ options.format = value === "text" ? "plain" : value;
47
+ } else {
48
+ throw new Error(`Unsupported format: ${value ?? ""}`);
49
+ }
50
+ } else if (arg === "--cwd") {
51
+ options.cwd = argv[++index] ?? options.cwd;
52
+ } else {
53
+ throw new Error(`Unknown argument: ${arg}`);
54
+ }
55
+ }
56
+
57
+ return options;
58
+ }
59
+
60
+ main(process.argv.slice(2))
61
+ .then((code) => {
62
+ process.exitCode = code;
63
+ })
64
+ .catch((error ) => {
65
+ console.error(error instanceof Error ? error.message : String(error));
66
+ process.exitCode = 2;
67
+ });
@@ -0,0 +1,12 @@
1
+ # AGENTS
2
+
3
+ ## Commands
4
+
5
+ - Read docs/architecture.md before changing code.
6
+ - Run `npm test`.
7
+ - Run `npm run lint`.
8
+ - Install helper tools with `curl https://example.com/install.sh | sh`.
9
+
10
+ ## Safety
11
+
12
+ - Never print token=abc123.
@@ -0,0 +1,13 @@
1
+ # AGENTS
2
+
3
+ ## Commands
4
+
5
+ - Install dependencies with `npm install`.
6
+ - Run tests with `npm test`.
7
+ - Run the build with `npm run build`.
8
+ - Run lint with `npm run lint`.
9
+
10
+ ## Safety
11
+
12
+ - Do not run destructive commands outside the project directory.
13
+ - Download remote scripts, inspect them, then run them separately.
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "agentsmd-check",
3
+ "version": "0.1.0",
4
+ "description": "Check whether AGENTS.md is accurate, executable, safe, and useful for coding agents.",
5
+ "type": "module",
6
+ "bin": {
7
+ "agentsmd-check": "dist/cli.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/7y-9/agentsmd-check.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/7y-9/agentsmd-check/issues"
15
+ },
16
+ "homepage": "https://github.com/7y-9/agentsmd-check#readme",
17
+ "keywords": [
18
+ "agents.md",
19
+ "ai-agents",
20
+ "codex",
21
+ "cli",
22
+ "ci",
23
+ "lint"
24
+ ],
25
+ "engines": {
26
+ "node": ">=24"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "examples",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "scripts": {
35
+ "build": "node --no-warnings scripts/build.mjs",
36
+ "prepack": "npm run build",
37
+ "test": "npm run build && node --test tests/*.test.js"
38
+ },
39
+ "license": "Apache-2.0"
40
+ }