agents-md-gen 0.2.0 → 0.3.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/README.md CHANGED
@@ -47,12 +47,18 @@ npx agents-md-gen ./some/repo # target a different directory
47
47
  npx agents-md-gen --also-claude-md
48
48
  npx agents-md-gen --dry-run # print instead of writing
49
49
  npx agents-md-gen --force # overwrite an existing file
50
+ npx agents-md-gen --check # exit 1 if missing/stale, writes nothing (CI)
50
51
  ```
51
52
 
52
53
  It won't overwrite an existing `AGENTS.md`/`CLAUDE.md` unless you pass
53
54
  `--force` — this is meant to bootstrap a file you then edit by hand, not to
54
55
  clobber one you already wrote.
55
56
 
57
+ `--check` is for CI: it fails the build if `AGENTS.md` doesn't exist or no
58
+ longer matches what the repo would generate, so a stale file (say, a new
59
+ test framework got added but nobody regenerated it) gets caught instead of
60
+ silently rotting. Pair it with the GitHub Action below.
61
+
56
62
  ## Example
57
63
 
58
64
  Real output — this is what `npx agents-md-gen` produces when run against
package/bin/cli.js CHANGED
@@ -11,6 +11,7 @@ function main() {
11
11
  'also-claude-md': { type: 'boolean', default: false },
12
12
  force: { type: 'boolean', short: 'f', default: false },
13
13
  'dry-run': { type: 'boolean', default: false },
14
+ check: { type: 'boolean', default: false },
14
15
  help: { type: 'boolean', short: 'h', default: false },
15
16
  },
16
17
  allowPositionals: true,
@@ -26,6 +27,7 @@ Options:
26
27
  --also-claude-md Also write an identical CLAUDE.md
27
28
  -f, --force Overwrite existing file(s)
28
29
  --dry-run Print to stdout instead of writing
30
+ --check Exit 1 if the file is missing or out of date (CI use, writes nothing)
29
31
  -h, --help Show this help
30
32
  `);
31
33
  return;
@@ -33,6 +35,25 @@ Options:
33
35
 
34
36
  const cwd = positionals[0] ? path.resolve(positionals[0]) : process.cwd();
35
37
 
38
+ if (values.check) {
39
+ const { upToDate, existed, target } = run({
40
+ cwd,
41
+ output: values.output,
42
+ check: true,
43
+ });
44
+ if (upToDate) {
45
+ console.log(`${target} is up to date`);
46
+ return;
47
+ }
48
+ console.error(
49
+ existed
50
+ ? `${target} is out of date - run agents-md-gen --force to update it`
51
+ : `${target} does not exist - run agents-md-gen to create it`
52
+ );
53
+ process.exitCode = 1;
54
+ return;
55
+ }
56
+
36
57
  const { written, skipped } = run({
37
58
  cwd,
38
59
  output: values.output,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agents-md-gen",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Generate a solid AGENTS.md / CLAUDE.md for any repo by detecting its stack, commands, and structure",
5
5
  "license": "MIT",
6
6
  "bin": {
package/src/detect.js CHANGED
@@ -229,6 +229,11 @@ function detectRuby(root) {
229
229
  };
230
230
  }
231
231
 
232
+ // Excluded so re-running the generator doesn't see its own prior output as
233
+ // part of the repo's structure - otherwise the file it just wrote would
234
+ // never match a freshly rendered one, breaking `--check`.
235
+ const OWN_OUTPUT_FILES = new Set(['AGENTS.md', 'CLAUDE.md']);
236
+
232
237
  function listStructure(root) {
233
238
  let entries;
234
239
  try {
@@ -239,6 +244,7 @@ function listStructure(root) {
239
244
  return entries
240
245
  .filter((e) => !e.name.startsWith('.') || e.name === '.github')
241
246
  .filter((e) => !IGNORE_DIRS.has(e.name))
247
+ .filter((e) => !OWN_OUTPUT_FILES.has(e.name))
242
248
  .map((e) => (e.isDirectory() ? `${e.name}/` : e.name))
243
249
  .sort();
244
250
  }
package/src/index.js CHANGED
@@ -4,7 +4,7 @@ const path = require('path');
4
4
  const { detectProject } = require('./detect');
5
5
  const { renderAgentsMd } = require('./render');
6
6
 
7
- function run({ cwd, output, alsoClaudeMd, force, dryRun }) {
7
+ function run({ cwd, output, alsoClaudeMd, force, dryRun, check }) {
8
8
  const project = detectProject(cwd);
9
9
  const content = renderAgentsMd(project);
10
10
 
@@ -13,6 +13,13 @@ function run({ cwd, output, alsoClaudeMd, force, dryRun }) {
13
13
  return { written: [], skipped: [] };
14
14
  }
15
15
 
16
+ if (check) {
17
+ const fullPath = path.join(cwd, output);
18
+ const existing = fs.existsSync(fullPath) ? fs.readFileSync(fullPath, 'utf8') : null;
19
+ const upToDate = existing === content;
20
+ return { upToDate, existed: existing !== null, target: output };
21
+ }
22
+
16
23
  const targets = [output];
17
24
  if (alsoClaudeMd && !targets.includes('CLAUDE.md')) targets.push('CLAUDE.md');
18
25