@cubicecho/agent-docs 0.1.0 → 0.2.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 +0 -0
- package/README.md +6 -6
- package/_agents/docs/01-install.md +6 -4
- package/_agents/docs/checks.md +3 -2
- package/_agents/docs/ci.md +52 -11
- package/_agents/docs/cli.md +1 -1
- package/_agents/docs/common-mistakes.md +10 -5
- package/_agents/docs/config.md +0 -0
- package/dist/bin.d.ts +0 -0
- package/dist/bin.js +0 -0
- package/dist/check/check-agent-docs.d.ts +3 -2
- package/dist/check/check-agent-docs.js +74 -14
- package/dist/check/generation.d.ts +37 -0
- package/dist/check/generation.js +86 -0
- package/dist/cli/run.d.ts +0 -0
- package/dist/cli/run.js +0 -0
- package/dist/consts.d.ts +0 -0
- package/dist/consts.js +0 -0
- package/dist/core/config.d.ts +0 -0
- package/dist/core/config.js +0 -0
- package/dist/core/errors.d.ts +0 -0
- package/dist/core/errors.js +0 -0
- package/dist/core/files.d.ts +0 -0
- package/dist/core/files.js +0 -0
- package/dist/core/json.d.ts +0 -0
- package/dist/core/json.js +0 -0
- package/dist/core/package-manifest.d.ts +2 -0
- package/dist/core/package-manifest.js +13 -0
- package/dist/defaults.d.ts +0 -0
- package/dist/defaults.js +0 -0
- package/dist/exports/entry-points.d.ts +0 -0
- package/dist/exports/entry-points.js +0 -0
- package/dist/exports/export-index.d.ts +0 -0
- package/dist/exports/export-index.js +0 -0
- package/dist/exports/module-source.d.ts +0 -0
- package/dist/exports/module-source.js +0 -0
- package/dist/exports/scan.d.ts +0 -0
- package/dist/exports/scan.js +0 -0
- package/dist/exports/summary.d.ts +0 -0
- package/dist/exports/summary.js +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/llms/identity.d.ts +0 -0
- package/dist/llms/identity.js +0 -0
- package/dist/llms/plan.d.ts +0 -0
- package/dist/llms/plan.js +0 -0
- package/dist/llms/sync.d.ts +0 -0
- package/dist/llms/sync.js +0 -0
- package/dist/markdown/anchors.d.ts +0 -0
- package/dist/markdown/anchors.js +0 -0
- package/dist/markdown/page.d.ts +0 -0
- package/dist/markdown/page.js +0 -0
- package/llms.txt +3 -3
- package/package.json +3 -4
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -24,22 +24,22 @@ Node 22 or later. No runtime dependencies.
|
|
|
24
24
|
{
|
|
25
25
|
"scripts": {
|
|
26
26
|
"llms": "agent-docs llms",
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"docs:check": "agent-docs check",
|
|
28
|
+
"prepack": "npm run build && agent-docs llms"
|
|
29
29
|
},
|
|
30
30
|
"files": ["dist", "llms.txt", "_agents/docs"]
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
```sh
|
|
35
|
-
|
|
36
|
-
npm run llms
|
|
37
|
-
npm run docs:check
|
|
35
|
+
echo /llms.txt >> .gitignore # prepack writes it on every publish, so git doesn't track it
|
|
36
|
+
npm run llms # in CI: fails on a page without a title or summary
|
|
37
|
+
npm run docs:check # in CI: fails when the docs fall short of the standard
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Documentation
|
|
41
41
|
|
|
42
|
-
- [llms.txt](https://
|
|
42
|
+
- [llms.txt](https://cdn.jsdelivr.net/npm/@cubicecho/agent-docs/llms.txt), the index of everything below, as the latest release ships it
|
|
43
43
|
- [Install and wire up](https://github.com/cubicecho/agent-docs/blob/main/_agents/docs/01-install.md)
|
|
44
44
|
- [The agent-docs command](https://github.com/cubicecho/agent-docs/blob/main/_agents/docs/cli.md)
|
|
45
45
|
- [`_agents/llms.json`](https://github.com/cubicecho/agent-docs/blob/main/_agents/docs/config.md)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Install and wire up
|
|
2
2
|
|
|
3
|
-
Add `@cubicecho/agent-docs` as a dev dependency, then give the package three npm scripts: `llms` writes `llms.txt`, `
|
|
3
|
+
Add `@cubicecho/agent-docs` as a dev dependency, then give the package three npm scripts: `llms` writes `llms.txt`, `prepack` runs it on every pack and publish so the file never goes stale, and `docs:check` checks the rest of the agent docs standard.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npm i -D @cubicecho/agent-docs
|
|
@@ -10,8 +10,8 @@ npm i -D @cubicecho/agent-docs
|
|
|
10
10
|
{
|
|
11
11
|
"scripts": {
|
|
12
12
|
"llms": "agent-docs llms",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"docs:check": "agent-docs check",
|
|
14
|
+
"prepack": "npm run build && agent-docs llms"
|
|
15
15
|
},
|
|
16
16
|
"files": ["dist", "llms.txt", "_agents/docs"]
|
|
17
17
|
}
|
|
@@ -32,7 +32,9 @@ npx agent-docs llms
|
|
|
32
32
|
npx agent-docs check
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
Don't commit `llms.txt`: add `/llms.txt` (and `/_agents/docs/exports/`, written when the index is too big for llms.txt) to `.gitignore`. `check` fails a package that packs llms.txt but lets git track it. Then add both commands to CI, as [the CI page](ci.md) shows.
|
|
36
|
+
|
|
37
|
+
A package installed straight from its repo, with nothing that packs it (a HACS integration, a git dependency), is the exception: commit llms.txt there and run `agent-docs llms --check` in CI.
|
|
36
38
|
|
|
37
39
|
## From code
|
|
38
40
|
|
package/_agents/docs/checks.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# What check enforces
|
|
2
2
|
|
|
3
|
-
`agent-docs check` holds a package to
|
|
3
|
+
`agent-docs check` holds a package to ten rules and prints one line per broken one, saying what to change. A private workspace root (`private: true` with `workspaces`) is held to the repo-level rules only: links, CLAUDE.md and `.agents/`.
|
|
4
4
|
|
|
5
5
|
1. **Page size.** Each page in the docs folder is at most 25 KB. Skills servers and file tools truncate larger reads.
|
|
6
6
|
2. **Contents list.** A page over 100 lines lists every `##` heading as a `(#anchor)` link above its first `##`.
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
6. **No hidden `.agents/`.** Only `.agents/skills/` may exist, because search tools skip dot-folders.
|
|
11
11
|
7. **`files`.** A published `package.json` with a `files` list includes `llms.txt` and the docs folder, and not all of `_agents`.
|
|
12
12
|
8. **LICENSE.** A published package has a `LICENSE`, `LICENCE` or `COPYING` file, and a package that is not a workspace root has at least one page.
|
|
13
|
-
9. **haxelib.** With `haxelib.json` and a `.releaserc.json`, the `semantic-release-haxelib` plugin's `additionalFiles` lists `llms.txt` and every page, every listed file exists, and `LICENSE.md` exists. The plugin takes files, not folders, and skips a missing path silently.
|
|
13
|
+
9. **haxelib.** With `haxelib.json` and a `.releaserc.json`, the `semantic-release-haxelib` plugin's `additionalFiles` lists `llms.txt` and every page, every listed file exists, and `LICENSE.md` exists. The plugin takes files, not folders, and skips a missing path silently. A missing `llms.txt` is fine when a release step writes it (rule 10).
|
|
14
|
+
10. **Generated on pack.** A published `package.json` that ships `llms.txt` has a `prepack` (or `prepublishOnly`) that runs `agent-docs llms`, directly or through `npm run`; `--check` and `--stdout` don't count. A semantic-release-haxelib release lists an `@semantic-release/exec` `prepareCmd` that runs it before the haxelib plugin. Either way, `.gitignore` holds `llms.txt` or `/llms.txt`. A package that nothing packs commits llms.txt instead, and this rule leaves it alone.
|
|
14
15
|
|
|
15
16
|
`agent-docs llms` fails on its own problems: a page without a `# Title` or a summary paragraph, a manifest without a name or description, an `exports` entry whose `src/` file is missing, a re-export of a missing module, an `export` statement it can't read (such as `export =`), and an llms.txt over 25 KB.
|
package/_agents/docs/ci.md
CHANGED
|
@@ -1,30 +1,71 @@
|
|
|
1
1
|
# CI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate `llms.txt` at pack time instead of committing it, run `llms` and `check` wherever the repo already runs its checks, and check what `npm pack` would ship after the build.
|
|
4
|
+
|
|
5
|
+
## npm
|
|
6
|
+
|
|
7
|
+
`prepack` writes llms.txt before every `npm pack` and `npm publish`, semantic-release's included, so the published copy always matches the pages and the source. Git doesn't track it.
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
"scripts": {
|
|
11
|
+
"llms": "agent-docs llms",
|
|
12
|
+
"docs:check": "agent-docs check",
|
|
13
|
+
"prepack": "npm run build && agent-docs llms"
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```gitignore
|
|
18
|
+
/llms.txt
|
|
19
|
+
/_agents/docs/exports/
|
|
20
|
+
```
|
|
4
21
|
|
|
5
22
|
```yaml
|
|
6
23
|
- run: npm ci
|
|
24
|
+
- run: npm run build
|
|
7
25
|
- name: Agent docs
|
|
8
26
|
run: |
|
|
9
|
-
npx agent-docs llms
|
|
27
|
+
npx agent-docs llms
|
|
10
28
|
npx agent-docs check
|
|
11
|
-
- run: npm run build
|
|
12
29
|
- name: The package ships the agent docs
|
|
13
30
|
run: |
|
|
14
31
|
npm pack --dry-run --ignore-scripts 2>&1 | tee pack.log
|
|
15
32
|
grep -q ' llms.txt$' pack.log && grep -q '_agents/docs/' pack.log
|
|
16
33
|
```
|
|
17
34
|
|
|
18
|
-
`--ignore-scripts` keeps `prepack` from building a second time. In a matrix workflow, run the docs
|
|
35
|
+
Running `llms` in CI fails on a page without a title or summary paragraph, and leaves an llms.txt whose links `check` then follows. `--ignore-scripts` keeps `prepack` from building a second time. In a matrix workflow, run the docs steps in one leg: they don't depend on the Node version.
|
|
36
|
+
|
|
37
|
+
## haxelib
|
|
38
|
+
|
|
39
|
+
`semantic-release-haxelib` zips the files on disk in its prepare step, so llms.txt must be written by a plugin listed before it. `@semantic-release/exec` runs its `prepareCmd` in that same step, in plugin order:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
"plugins": [
|
|
43
|
+
"@semantic-release/commit-analyzer",
|
|
44
|
+
"@semantic-release/release-notes-generator",
|
|
45
|
+
["@semantic-release/exec", { "prepareCmd": "npx -y @cubicecho/agent-docs llms" }],
|
|
46
|
+
["semantic-release-haxelib", { "additionalFiles": ["llms.txt", "_agents/docs/01-install.md"] }]
|
|
47
|
+
]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Add `@semantic-release/exec` to the release job's dependencies, and run `npx -y @cubicecho/agent-docs llms` then `check` in CI as for npm. A package on both registries keeps the npm `prepack` as well.
|
|
51
|
+
|
|
52
|
+
## Installed from git
|
|
53
|
+
|
|
54
|
+
A package with nothing that packs it, such as a HACS integration or a git dependency, ships the repo itself. There, commit llms.txt and fail CI when it is stale:
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
- run: npx -y @cubicecho/agent-docs llms --check
|
|
58
|
+
- run: npx -y @cubicecho/agent-docs check
|
|
59
|
+
```
|
|
19
60
|
|
|
20
|
-
## Moving off a
|
|
61
|
+
## Moving off a committed llms.txt
|
|
21
62
|
|
|
22
|
-
1. Delete `scripts/llms-txt.mjs`
|
|
23
|
-
2.
|
|
24
|
-
3.
|
|
25
|
-
4.
|
|
26
|
-
5.
|
|
63
|
+
1. Delete any copied `scripts/llms-txt.mjs` and `scripts/check-agent-docs.mjs`.
|
|
64
|
+
2. Set the scripts above, and drop `llms:check` and any `git diff --exit-code -- llms.txt` step.
|
|
65
|
+
3. Add `"_agents/docs"` and `"llms.txt"` to `files`.
|
|
66
|
+
4. Add `/llms.txt` to `.gitignore`, then `git rm --cached llms.txt` in the same commit.
|
|
67
|
+
5. Point the README's llms.txt link at the published copy: `https://cdn.jsdelivr.net/npm/<package>/llms.txt`.
|
|
27
68
|
|
|
28
69
|
## Monorepos
|
|
29
70
|
|
|
30
|
-
Run both commands in each published package's folder (`npm run docs:check --workspaces`), and `agent-docs check` once at the root for the repo-level rules.
|
|
71
|
+
Run both commands in each published package's folder (`npm run docs:check --workspaces`), give each package its own `prepack`, and run `agent-docs check` once at the root for the repo-level rules.
|
package/_agents/docs/cli.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
agent-docs llms # write llms.txt
|
|
9
|
-
agent-docs llms --check # CI: exit 1 if
|
|
9
|
+
agent-docs llms --check # CI, in a repo that commits llms.txt: exit 1 if it or an export page is stale
|
|
10
10
|
agent-docs llms --stdout # print what would be written, write nothing
|
|
11
11
|
agent-docs llms --base-url https://org.github.io/pkg/ # add a "Base URL:" line
|
|
12
12
|
```
|
|
@@ -2,18 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
The mistakes that make `llms` or `check` fail, or let a stale index through, each with its fix.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Committing llms.txt in a package that is packed
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The committed copy drifts from the pages between releases, and a `git diff` after a regenerating build passes every time. Generate it in `prepack` and keep it out of git:
|
|
8
8
|
|
|
9
9
|
```json
|
|
10
|
-
"
|
|
11
|
-
"llms:check": "agent-docs llms --check"
|
|
10
|
+
"prepack": "npm run build && agent-docs llms"
|
|
12
11
|
```
|
|
13
12
|
|
|
13
|
+
```gitignore
|
|
14
|
+
/llms.txt
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Only a package installed straight from its repo commits llms.txt and runs `llms --check`.
|
|
18
|
+
|
|
14
19
|
## Editing llms.txt or a generated export page by hand
|
|
15
20
|
|
|
16
|
-
The next `llms` run
|
|
21
|
+
The next `llms` run, and every `prepack`, overwrites it. Change the page in `_agents/docs/` or the doc comment in `src/`, then rerun `agent-docs llms`. A hand-written page placed in `_agents/docs/exports/` stops `llms` with "was written by hand"; move it to another folder.
|
|
17
22
|
|
|
18
23
|
## A blank line between a doc comment and its declaration
|
|
19
24
|
|
package/_agents/docs/config.md
CHANGED
|
File without changes
|
package/dist/bin.d.ts
CHANGED
|
File without changes
|
package/dist/bin.js
CHANGED
|
File without changes
|
|
@@ -16,7 +16,8 @@ export interface CheckResult {
|
|
|
16
16
|
* @remarks
|
|
17
17
|
* The rules: pages within `pageLimitKb`, a contents list on a page over `contentsAfterLines`, relative links that
|
|
18
18
|
* resolve inside the repo (README has none but `#anchor`s), the README's hidden pointer, CLAUDE.md as a link to
|
|
19
|
-
* AGENTS.md, no hidden `.agents/`, a LICENSE and the right `files` for a published package,
|
|
20
|
-
* semantic-release-haxelib file list.
|
|
19
|
+
* AGENTS.md, no hidden `.agents/`, a LICENSE and the right `files` for a published package, the
|
|
20
|
+
* semantic-release-haxelib file list, and llms.txt generated when the package is packed and kept out of git. A
|
|
21
|
+
* private workspace root is held to the repo-level rules only.
|
|
21
22
|
*/
|
|
22
23
|
export declare function checkAgentDocs(root: string, overrides?: Partial<LimitSettings>): CheckResult;
|
|
@@ -8,6 +8,7 @@ import { isJsonObject, readJsonFile } from '../core/json.js';
|
|
|
8
8
|
import { readPackageManifest } from '../core/package-manifest.js';
|
|
9
9
|
import { LIMIT_DEFAULTS } from '../defaults.js';
|
|
10
10
|
import { headings, links } from '../markdown/anchors.js';
|
|
11
|
+
import { EXEC_PLUGIN, EXEC_SUGGESTION, ignoresLlms, npmGeneratesLlms, PREPACK_SUGGESTION, releaseGeneratesLlms, } from './generation.js';
|
|
11
12
|
const URL_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
12
13
|
const LICENSE_FILE = /^(LICEN[CS]E|COPYING)(\.|$)/i;
|
|
13
14
|
const HAXELIB_PLUGIN = 'semantic-release-haxelib';
|
|
@@ -23,8 +24,9 @@ const LINKED_FILES = [LLMS_FILE, 'README.md', 'AGENTS.md'];
|
|
|
23
24
|
* @remarks
|
|
24
25
|
* The rules: pages within `pageLimitKb`, a contents list on a page over `contentsAfterLines`, relative links that
|
|
25
26
|
* resolve inside the repo (README has none but `#anchor`s), the README's hidden pointer, CLAUDE.md as a link to
|
|
26
|
-
* AGENTS.md, no hidden `.agents/`, a LICENSE and the right `files` for a published package,
|
|
27
|
-
* semantic-release-haxelib file list.
|
|
27
|
+
* AGENTS.md, no hidden `.agents/`, a LICENSE and the right `files` for a published package, the
|
|
28
|
+
* semantic-release-haxelib file list, and llms.txt generated when the package is packed and kept out of git. A
|
|
29
|
+
* private workspace root is held to the repo-level rules only.
|
|
28
30
|
*/
|
|
29
31
|
export function checkAgentDocs(root, overrides = {}) {
|
|
30
32
|
const limits = { ...LIMIT_DEFAULTS, ...overrides };
|
|
@@ -37,7 +39,7 @@ export function checkAgentDocs(root, overrides = {}) {
|
|
|
37
39
|
if (pages.length === 0 && isWorkspaceRoot === false) {
|
|
38
40
|
problems.push(`${docsDir}/ has no pages: write the agent docs there, starting with 01-install.md.`);
|
|
39
41
|
}
|
|
40
|
-
problems.push(...pageProblems(root, pages, limits), ...linkProblems(root, pages, isWorkspaceRoot), ...repoProblems(root, isWorkspaceRoot), ...packageProblems(root, docsDir), ...haxelibProblems(root, pages));
|
|
42
|
+
problems.push(...pageProblems(root, pages, limits), ...linkProblems(root, pages, isWorkspaceRoot), ...repoProblems(root, isWorkspaceRoot), ...packageProblems(root, docsDir), ...haxelibProblems(root, pages), ...generationProblems(root));
|
|
41
43
|
return { problems, pageCount: pages.length };
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
@@ -220,22 +222,18 @@ function packageProblems(root, docsDir) {
|
|
|
220
222
|
* exist, so a page missing from the list never ships.
|
|
221
223
|
*/
|
|
222
224
|
function haxelibProblems(root, pages) {
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
if (isHaxelib === false || releaseFile === undefined) {
|
|
225
|
+
const release = readHaxelibRelease(root);
|
|
226
|
+
if (release === undefined) {
|
|
226
227
|
return [];
|
|
227
228
|
}
|
|
229
|
+
const { releaseFile, plugins, haxelibIndex, isJson } = release;
|
|
228
230
|
const found = [];
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
release = readJsonFile(root, releaseFile);
|
|
232
|
-
}
|
|
233
|
-
catch {
|
|
231
|
+
if (isJson === false) {
|
|
234
232
|
found.push(`${releaseFile} is not JSON, so the haxelib file list can't be checked: write it as JSON.`);
|
|
235
233
|
}
|
|
236
|
-
const
|
|
237
|
-
const haxelib = plugins.find((plugin) => Array.isArray(plugin) && plugin[0] === HAXELIB_PLUGIN);
|
|
234
|
+
const haxelib = plugins[haxelibIndex];
|
|
238
235
|
if (Array.isArray(haxelib)) {
|
|
236
|
+
const generates = releaseGeneratesLlms(plugins, haxelibIndex);
|
|
239
237
|
const options = isJsonObject(haxelib[1]) ? haxelib[1] : {};
|
|
240
238
|
const listedFiles = Array.isArray(options.additionalFiles) ? options.additionalFiles : [];
|
|
241
239
|
const listed = new Set(listedFiles.filter((f) => typeof f === 'string').map((f) => f.replace(/^\.\//, '')));
|
|
@@ -243,7 +241,9 @@ function haxelibProblems(root, pages) {
|
|
|
243
241
|
for (const file of wanted.filter((f) => listed.has(f) === false)) {
|
|
244
242
|
found.push(`${releaseFile} ${HAXELIB_PLUGIN} "additionalFiles" lacks "${file}", so the haxelib zip won't contain it: add it.`);
|
|
245
243
|
}
|
|
246
|
-
|
|
244
|
+
// A release step writes llms.txt before the plugin zips, so a clone without it is fine.
|
|
245
|
+
const isMissing = (f) => generates && f === LLMS_FILE ? false : existsSync(join(root, f)) === false;
|
|
246
|
+
for (const file of [...listed].filter(isMissing)) {
|
|
247
247
|
found.push(`${releaseFile} lists "${file}" in "additionalFiles", but it doesn't exist (the plugin skips it silently): fix or remove the entry.`);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
@@ -252,3 +252,63 @@ function haxelibProblems(root, pages) {
|
|
|
252
252
|
}
|
|
253
253
|
return found;
|
|
254
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Reads the release config of a package that has haxelib.json.
|
|
257
|
+
*
|
|
258
|
+
* @param root - Package root.
|
|
259
|
+
* @returns The config, or undefined without haxelib.json or a release config.
|
|
260
|
+
*/
|
|
261
|
+
function readHaxelibRelease(root) {
|
|
262
|
+
const releaseFile = ['.releaserc.json', '.releaserc'].find((file) => existsSync(join(root, file)));
|
|
263
|
+
if (existsSync(join(root, 'haxelib.json')) === false || releaseFile === undefined) {
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
let release;
|
|
267
|
+
let isJson = true;
|
|
268
|
+
try {
|
|
269
|
+
release = readJsonFile(root, releaseFile);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
isJson = false;
|
|
273
|
+
}
|
|
274
|
+
const plugins = isJsonObject(release) && Array.isArray(release.plugins) ? release.plugins : [];
|
|
275
|
+
const haxelibIndex = plugins.findIndex((plugin) => Array.isArray(plugin) && plugin[0] === HAXELIB_PLUGIN);
|
|
276
|
+
return { releaseFile, plugins, haxelibIndex, isJson };
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Rule 10: whatever packs the package writes llms.txt first, and git doesn't track it.
|
|
280
|
+
*
|
|
281
|
+
* @param root - Package root.
|
|
282
|
+
* @returns One line per problem; none for a package nothing packs, such as one installed from git.
|
|
283
|
+
*
|
|
284
|
+
* @remarks
|
|
285
|
+
* npm runs `prepack` (or `prepublishOnly`) before it builds the tarball, and semantic-release-haxelib zips in its
|
|
286
|
+
* prepare step, so an `@semantic-release/exec` `prepareCmd` listed before it runs in time. A package installed
|
|
287
|
+
* straight from the repo, such as a HACS integration, commits llms.txt instead and runs `llms --check` in CI.
|
|
288
|
+
*/
|
|
289
|
+
function generationProblems(root) {
|
|
290
|
+
const manifest = readPackageManifest(root);
|
|
291
|
+
const isNpm = manifest !== undefined && manifest.isPrivate === false && shipsLlms(manifest);
|
|
292
|
+
const release = readHaxelibRelease(root);
|
|
293
|
+
const isHaxelib = release !== undefined && release.haxelibIndex !== -1;
|
|
294
|
+
const found = [];
|
|
295
|
+
if (isNpm && npmGeneratesLlms(manifest) === false) {
|
|
296
|
+
found.push(`package.json has no prepack that writes ${LLMS_FILE}, so a publish can ship a stale one: add ${PREPACK_SUGGESTION}.`);
|
|
297
|
+
}
|
|
298
|
+
if (isHaxelib && releaseGeneratesLlms(release.plugins, release.haxelibIndex) === false) {
|
|
299
|
+
found.push(`${release.releaseFile} writes no ${LLMS_FILE} before ${HAXELIB_PLUGIN} zips: add ${EXEC_SUGGESTION} before it, and "${EXEC_PLUGIN}" to devDependencies.`);
|
|
300
|
+
}
|
|
301
|
+
if ((isNpm || isHaxelib) && ignoresLlms(root) === false) {
|
|
302
|
+
found.push(`${LLMS_FILE} is generated when the package is packed, so git shouldn't track it: add it to .gitignore and run "git rm --cached ${LLMS_FILE}".`);
|
|
303
|
+
}
|
|
304
|
+
return found;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Whether a published package.json ships llms.txt: npm's default of everything, or `files` listing it.
|
|
308
|
+
*
|
|
309
|
+
* @param manifest - The package manifest.
|
|
310
|
+
* @returns True when the tarball would hold llms.txt.
|
|
311
|
+
*/
|
|
312
|
+
function shipsLlms(manifest) {
|
|
313
|
+
return manifest.files === undefined || manifest.files.some((f) => f.replace(/^\.\//, '') === LLMS_FILE);
|
|
314
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PackageManifest } from '../core/package-manifest.ts';
|
|
2
|
+
/** The semantic-release plugin that runs shell commands at each release step. */
|
|
3
|
+
export declare const EXEC_PLUGIN = "@semantic-release/exec";
|
|
4
|
+
/** The prepack script a failing check suggests. */
|
|
5
|
+
export declare const PREPACK_SUGGESTION = "\"prepack\": \"npm run build && agent-docs llms\"";
|
|
6
|
+
/** The plugin entry a failing haxelib check suggests. */
|
|
7
|
+
export declare const EXEC_SUGGESTION = "[\"@semantic-release/exec\", { \"prepareCmd\": \"npx -y @cubicecho/agent-docs llms\" }]";
|
|
8
|
+
/**
|
|
9
|
+
* Whether a shell command writes llms.txt: `agent-docs llms` without `--check` or `--stdout`.
|
|
10
|
+
*
|
|
11
|
+
* @param command - A script or command line.
|
|
12
|
+
* @param isSelf - The package being checked is this one, whose scripts run its own `bin.js` or `bin.ts`.
|
|
13
|
+
* @returns True when one of its commands writes llms.txt.
|
|
14
|
+
*/
|
|
15
|
+
export declare function writesLlms(command: string, isSelf?: boolean): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether npm regenerates llms.txt each time it packs the package.
|
|
18
|
+
*
|
|
19
|
+
* @param manifest - The package manifest.
|
|
20
|
+
* @returns True when `prepack` or `prepublishOnly` writes llms.txt, directly or through `npm run`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function npmGeneratesLlms(manifest: PackageManifest): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a semantic-release plugin list writes llms.txt before `beforePlugin` runs its prepare step.
|
|
25
|
+
*
|
|
26
|
+
* @param plugins - The `plugins` list of a release config.
|
|
27
|
+
* @param beforeIndex - Index of the plugin that must find llms.txt on disk.
|
|
28
|
+
* @returns True when an earlier `@semantic-release/exec` entry's `prepareCmd` writes llms.txt.
|
|
29
|
+
*/
|
|
30
|
+
export declare function releaseGeneratesLlms(plugins: readonly unknown[], beforeIndex: number): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the repo's root `.gitignore` ignores llms.txt.
|
|
33
|
+
*
|
|
34
|
+
* @param root - Package root.
|
|
35
|
+
* @returns True for a `llms.txt` or `/llms.txt` line.
|
|
36
|
+
*/
|
|
37
|
+
export declare function ignoresLlms(root: string): boolean;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { LLMS_FILE, PACKAGE_NAME } from '../consts.js';
|
|
4
|
+
import { isJsonObject } from '../core/json.js';
|
|
5
|
+
/** npm lifecycle scripts that run before `npm publish` and `npm pack` build the tarball. */
|
|
6
|
+
const PACK_SCRIPTS = ['prepack', 'prepublishOnly'];
|
|
7
|
+
/** The semantic-release plugin that runs shell commands at each release step. */
|
|
8
|
+
export const EXEC_PLUGIN = '@semantic-release/exec';
|
|
9
|
+
/** The prepack script a failing check suggests. */
|
|
10
|
+
export const PREPACK_SUGGESTION = '"prepack": "npm run build && agent-docs llms"';
|
|
11
|
+
/** The plugin entry a failing haxelib check suggests. */
|
|
12
|
+
export const EXEC_SUGGESTION = `["${EXEC_PLUGIN}", { "prepareCmd": "npx -y ${PACKAGE_NAME} llms" }]`;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a shell command writes llms.txt: `agent-docs llms` without `--check` or `--stdout`.
|
|
15
|
+
*
|
|
16
|
+
* @param command - A script or command line.
|
|
17
|
+
* @param isSelf - The package being checked is this one, whose scripts run its own `bin.js` or `bin.ts`.
|
|
18
|
+
* @returns True when one of its commands writes llms.txt.
|
|
19
|
+
*/
|
|
20
|
+
export function writesLlms(command, isSelf = false) {
|
|
21
|
+
const runner = isSelf ? /(agent-docs(@\S*)?|\bbin\.[jt]s)\s+llms\b/ : /agent-docs(@\S*)?\s+llms\b/;
|
|
22
|
+
return command.split(/&&|\|\||;|\n/).some((part) => runner.test(part) && /--(check|stdout)\b/.test(part) === false);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Whether an npm script writes llms.txt, following `npm run <name>` into the scripts it calls.
|
|
26
|
+
*
|
|
27
|
+
* @param scripts - package.json `scripts`.
|
|
28
|
+
* @param name - The script to start from.
|
|
29
|
+
* @param isSelf - Passed to {@link writesLlms}.
|
|
30
|
+
* @param seen - Scripts already followed, so a loop ends; appended to in place.
|
|
31
|
+
* @returns True when the script, or one it runs, writes llms.txt.
|
|
32
|
+
*/
|
|
33
|
+
function scriptWritesLlms(scripts, name, isSelf, seen = new Set()) {
|
|
34
|
+
const command = scripts[name];
|
|
35
|
+
if (command === undefined || seen.has(name)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
seen.add(name);
|
|
39
|
+
if (writesLlms(command, isSelf)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
const called = [...command.matchAll(/npm run(?:-script)? ([\w:.-]+)/g)].map((match) => match[1]);
|
|
43
|
+
return called.some((next) => next !== undefined && scriptWritesLlms(scripts, next, isSelf, seen));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Whether npm regenerates llms.txt each time it packs the package.
|
|
47
|
+
*
|
|
48
|
+
* @param manifest - The package manifest.
|
|
49
|
+
* @returns True when `prepack` or `prepublishOnly` writes llms.txt, directly or through `npm run`.
|
|
50
|
+
*/
|
|
51
|
+
export function npmGeneratesLlms(manifest) {
|
|
52
|
+
const isSelf = manifest.name === PACKAGE_NAME;
|
|
53
|
+
return PACK_SCRIPTS.some((name) => scriptWritesLlms(manifest.scripts, name, isSelf));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether a semantic-release plugin list writes llms.txt before `beforePlugin` runs its prepare step.
|
|
57
|
+
*
|
|
58
|
+
* @param plugins - The `plugins` list of a release config.
|
|
59
|
+
* @param beforeIndex - Index of the plugin that must find llms.txt on disk.
|
|
60
|
+
* @returns True when an earlier `@semantic-release/exec` entry's `prepareCmd` writes llms.txt.
|
|
61
|
+
*/
|
|
62
|
+
export function releaseGeneratesLlms(plugins, beforeIndex) {
|
|
63
|
+
return plugins.slice(0, beforeIndex).some((plugin) => {
|
|
64
|
+
if (Array.isArray(plugin) === false || plugin[0] !== EXEC_PLUGIN || isJsonObject(plugin[1]) === false) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const command = plugin[1].prepareCmd;
|
|
68
|
+
return typeof command === 'string' && writesLlms(command);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether the repo's root `.gitignore` ignores llms.txt.
|
|
73
|
+
*
|
|
74
|
+
* @param root - Package root.
|
|
75
|
+
* @returns True for a `llms.txt` or `/llms.txt` line.
|
|
76
|
+
*/
|
|
77
|
+
export function ignoresLlms(root) {
|
|
78
|
+
const path = join(root, '.gitignore');
|
|
79
|
+
if (existsSync(path) === false) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return readFileSync(path, 'utf8')
|
|
83
|
+
.split('\n')
|
|
84
|
+
.map((line) => line.trim())
|
|
85
|
+
.some((line) => line === LLMS_FILE || line === `/${LLMS_FILE}`);
|
|
86
|
+
}
|
package/dist/cli/run.d.ts
CHANGED
|
File without changes
|
package/dist/cli/run.js
CHANGED
|
File without changes
|
package/dist/consts.d.ts
CHANGED
|
File without changes
|
package/dist/consts.js
CHANGED
|
File without changes
|
package/dist/core/config.d.ts
CHANGED
|
File without changes
|
package/dist/core/config.js
CHANGED
|
File without changes
|
package/dist/core/errors.d.ts
CHANGED
|
File without changes
|
package/dist/core/errors.js
CHANGED
|
File without changes
|
package/dist/core/files.d.ts
CHANGED
|
File without changes
|
package/dist/core/files.js
CHANGED
|
File without changes
|
package/dist/core/json.d.ts
CHANGED
|
File without changes
|
package/dist/core/json.js
CHANGED
|
File without changes
|
|
@@ -25,6 +25,8 @@ export interface PackageManifest {
|
|
|
25
25
|
nodeRange?: string;
|
|
26
26
|
/** `peerDependencies`, in the order written. */
|
|
27
27
|
peers: PeerDependency[];
|
|
28
|
+
/** `scripts`, keeping only string-valued entries. */
|
|
29
|
+
scripts: Record<string, string>;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Reads package.json at the package root.
|
|
@@ -23,6 +23,7 @@ export function readPackageManifest(root) {
|
|
|
23
23
|
exports: parsed.exports,
|
|
24
24
|
nodeRange: stringField(engines, 'node'),
|
|
25
25
|
peers: peerDependencies(parsed),
|
|
26
|
+
scripts: stringEntries(parsed.scripts),
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
@@ -43,3 +44,15 @@ function peerDependencies(manifest) {
|
|
|
43
44
|
return [{ name, range, isOptional }];
|
|
44
45
|
});
|
|
45
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The string-valued fields of a JSON object, such as `scripts`.
|
|
49
|
+
*
|
|
50
|
+
* @param value - The parsed field.
|
|
51
|
+
* @returns Its string entries; empty when it is not an object.
|
|
52
|
+
*/
|
|
53
|
+
function stringEntries(value) {
|
|
54
|
+
if (isJsonObject(value) === false) {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === 'string'));
|
|
58
|
+
}
|
package/dist/defaults.d.ts
CHANGED
|
File without changes
|
package/dist/defaults.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/exports/scan.d.ts
CHANGED
|
File without changes
|
package/dist/exports/scan.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/exports/summary.js
CHANGED
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Generates and checks the agent docs a package ships.
|
|
3
3
|
*
|
|
4
4
|
* `planLlms` works out llms.txt from the `_agents/docs/` pages and, for TypeScript, the doc comments behind each
|
|
5
|
-
* package.json `exports` entry; `writeLlms` writes it and `findStaleFiles` compares it with the
|
|
5
|
+
* package.json `exports` entry; `writeLlms` writes it and `findStaleFiles` compares it with the copy on disk.
|
|
6
6
|
* `checkAgentDocs` checks the README, AGENTS.md, links, page sizes and package contents against the standard. The
|
|
7
7
|
* `agent-docs` command runs the same functions.
|
|
8
8
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Generates and checks the agent docs a package ships.
|
|
3
3
|
*
|
|
4
4
|
* `planLlms` works out llms.txt from the `_agents/docs/` pages and, for TypeScript, the doc comments behind each
|
|
5
|
-
* package.json `exports` entry; `writeLlms` writes it and `findStaleFiles` compares it with the
|
|
5
|
+
* package.json `exports` entry; `writeLlms` writes it and `findStaleFiles` compares it with the copy on disk.
|
|
6
6
|
* `checkAgentDocs` checks the README, AGENTS.md, links, page sizes and package contents against the standard. The
|
|
7
7
|
* `agent-docs` command runs the same functions.
|
|
8
8
|
*/
|
package/dist/llms/identity.d.ts
CHANGED
|
File without changes
|
package/dist/llms/identity.js
CHANGED
|
File without changes
|
package/dist/llms/plan.d.ts
CHANGED
|
File without changes
|
package/dist/llms/plan.js
CHANGED
|
File without changes
|
package/dist/llms/sync.d.ts
CHANGED
|
File without changes
|
package/dist/llms/sync.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/markdown/anchors.js
CHANGED
|
File without changes
|
package/dist/markdown/page.d.ts
CHANGED
|
File without changes
|
package/dist/markdown/page.js
CHANGED
|
File without changes
|
package/llms.txt
CHANGED
|
@@ -8,9 +8,9 @@ Requires Node >=22.
|
|
|
8
8
|
|
|
9
9
|
## Docs
|
|
10
10
|
|
|
11
|
-
- [Install and wire up](_agents/docs/01-install.md): Add `@cubicecho/agent-docs` as a dev dependency, then give the package three npm scripts: `llms` writes `llms.txt`, `
|
|
12
|
-
- [What check enforces](_agents/docs/checks.md): `agent-docs check` holds a package to
|
|
13
|
-
- [CI](_agents/docs/ci.md):
|
|
11
|
+
- [Install and wire up](_agents/docs/01-install.md): Add `@cubicecho/agent-docs` as a dev dependency, then give the package three npm scripts: `llms` writes `llms.txt`, `prepack` runs it on every pack and publish so the file never goes stale, and `docs:check` checks the rest of the agent docs standard.
|
|
12
|
+
- [What check enforces](_agents/docs/checks.md): `agent-docs check` holds a package to ten rules and prints one line per broken one, saying what to change. A private workspace root (`private: true` with `workspaces`) is held to the repo-level rules only: links, CLAUDE.md and `.agents/`.
|
|
13
|
+
- [CI](_agents/docs/ci.md): Generate `llms.txt` at pack time instead of committing it, run `llms` and `check` wherever the repo already runs its checks, and check what `npm pack` would ship after the build.
|
|
14
14
|
- [The agent-docs command](_agents/docs/cli.md): `agent-docs llms` writes or checks `llms.txt`, and `agent-docs check` checks the package against the agent docs standard. Each prints one line per problem and exits 1 when there is any; otherwise it exits 0.
|
|
15
15
|
- [Common mistakes](_agents/docs/common-mistakes.md): The mistakes that make `llms` or `check` fail, or let a stale index through, each with its fix.
|
|
16
16
|
- [_agents/llms.json](_agents/docs/config.md): `_agents/llms.json` is the optional overrides file both commands read; without it, every field takes its default.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cubicecho/agent-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Generates and checks the agent docs a package ships: llms.txt from _agents/docs/ pages and each package export's doc comments, and the checks that keep README, AGENTS.md and the package contents to the standard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"llms.txt",
|
|
@@ -43,14 +43,13 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "tsc -p tsconfig.build.json",
|
|
46
|
-
"prepack": "npm run build",
|
|
47
|
-
"check": "npm run check:biome && npm run check:types && npm run llms
|
|
46
|
+
"prepack": "npm run build && node dist/bin.js llms",
|
|
47
|
+
"check": "npm run check:biome && npm run check:types && npm run llms && npm run docs:check",
|
|
48
48
|
"check:biome": "biome check --write .",
|
|
49
49
|
"check:types": "tsc --noEmit",
|
|
50
50
|
"test": "vitest run",
|
|
51
51
|
"test:watch": "vitest",
|
|
52
52
|
"llms": "node src/bin.ts llms",
|
|
53
|
-
"llms:check": "node src/bin.ts llms --check",
|
|
54
53
|
"docs:check": "node src/bin.ts check",
|
|
55
54
|
"coverage": "vitest run --coverage"
|
|
56
55
|
},
|