@cubicecho/agent-docs 0.0.0-stage → 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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/_agents/docs/01-install.md +55 -0
  4. package/_agents/docs/checks.md +16 -0
  5. package/_agents/docs/ci.md +71 -0
  6. package/_agents/docs/cli.md +39 -0
  7. package/_agents/docs/common-mistakes.md +54 -0
  8. package/_agents/docs/config.md +25 -0
  9. package/dist/bin.d.ts +7 -0
  10. package/dist/bin.js +11 -0
  11. package/dist/check/check-agent-docs.d.ts +23 -0
  12. package/dist/check/check-agent-docs.js +314 -0
  13. package/dist/check/generation.d.ts +37 -0
  14. package/dist/check/generation.js +86 -0
  15. package/dist/cli/run.d.ts +24 -0
  16. package/dist/cli/run.js +131 -0
  17. package/dist/consts.d.ts +16 -0
  18. package/dist/consts.js +16 -0
  19. package/dist/core/config.d.ts +31 -0
  20. package/dist/core/config.js +69 -0
  21. package/dist/core/errors.d.ts +17 -0
  22. package/dist/core/errors.js +21 -0
  23. package/dist/core/files.d.ts +28 -0
  24. package/dist/core/files.js +67 -0
  25. package/dist/core/json.d.ts +26 -0
  26. package/dist/core/json.js +44 -0
  27. package/dist/core/package-manifest.d.ts +38 -0
  28. package/dist/core/package-manifest.js +58 -0
  29. package/dist/defaults.d.ts +26 -0
  30. package/dist/defaults.js +14 -0
  31. package/dist/exports/entry-points.d.ts +30 -0
  32. package/dist/exports/entry-points.js +119 -0
  33. package/dist/exports/export-index.d.ts +44 -0
  34. package/dist/exports/export-index.js +233 -0
  35. package/dist/exports/module-source.d.ts +74 -0
  36. package/dist/exports/module-source.js +161 -0
  37. package/dist/exports/scan.d.ts +29 -0
  38. package/dist/exports/scan.js +156 -0
  39. package/dist/exports/summary.d.ts +36 -0
  40. package/dist/exports/summary.js +84 -0
  41. package/dist/index.d.ts +16 -0
  42. package/dist/index.js +16 -0
  43. package/dist/llms/identity.d.ts +21 -0
  44. package/dist/llms/identity.js +67 -0
  45. package/dist/llms/plan.d.ts +53 -0
  46. package/dist/llms/plan.js +318 -0
  47. package/dist/llms/sync.d.ts +16 -0
  48. package/dist/llms/sync.js +36 -0
  49. package/dist/markdown/anchors.d.ts +35 -0
  50. package/dist/markdown/anchors.js +66 -0
  51. package/dist/markdown/page.d.ts +20 -0
  52. package/dist/markdown/page.js +57 -0
  53. package/llms.txt +42 -0
  54. package/package.json +64 -4
@@ -0,0 +1,66 @@
1
+ const FENCE = /^\s*```/;
2
+ const HEADING = /^(#{1,6}) (.*)$/;
3
+ const LINK_TARGET = /\]\(([^)\s]+)\)/g;
4
+ const CODE_SPAN = /`[^`]*`/g;
5
+ /**
6
+ * GitHub's heading anchor: lower case, punctuation dropped, spaces to hyphens.
7
+ *
8
+ * @param heading - Heading text without its `#` marks.
9
+ * @returns The anchor without `#`; underscores and hyphens are kept.
10
+ */
11
+ export function slug(heading) {
12
+ return heading
13
+ .trim()
14
+ .toLowerCase()
15
+ .replace(/`/g, '')
16
+ .replace(/[^\p{L}\p{N}\s_-]/gu, '')
17
+ .replace(/\s/g, '-');
18
+ }
19
+ /**
20
+ * The lines of a markdown text that sit outside code fences.
21
+ *
22
+ * @param text - Markdown source.
23
+ * @returns The lines in order, fence lines themselves left out.
24
+ */
25
+ export function proseLines(text) {
26
+ const out = [];
27
+ let isFenced = false;
28
+ for (const line of text.split('\n')) {
29
+ if (FENCE.test(line)) {
30
+ isFenced = isFenced === false;
31
+ continue;
32
+ }
33
+ if (isFenced === false) {
34
+ out.push(line);
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ /**
40
+ * Every heading outside code fences, anchored the way GitHub anchors them.
41
+ *
42
+ * @param text - Markdown source.
43
+ * @returns The headings in order.
44
+ */
45
+ export function headings(text) {
46
+ const seen = new Map();
47
+ return proseLines(text).flatMap((line) => {
48
+ const match = line.match(HEADING);
49
+ if (match === null) {
50
+ return [];
51
+ }
52
+ const base = slug(match[2]);
53
+ const count = seen.get(base) ?? 0;
54
+ seen.set(base, count + 1);
55
+ return [{ level: match[1].length, anchor: count === 0 ? base : `${base}-${count}` }];
56
+ });
57
+ }
58
+ /**
59
+ * Link targets outside code fences and code spans.
60
+ *
61
+ * @param text - Markdown source.
62
+ * @returns Each `](target)` target, in order.
63
+ */
64
+ export function links(text) {
65
+ return proseLines(text).flatMap((line) => [...line.replace(CODE_SPAN, '``').matchAll(LINK_TARGET)].map((match) => match[1]));
66
+ }
@@ -0,0 +1,20 @@
1
+ /** What llms.txt says about one page. */
2
+ export interface PageSummary {
3
+ /** The page's `# H1`, the link text. */
4
+ title: string;
5
+ /** The first plain paragraph under it, on one line with its links reduced to their text. */
6
+ note: string;
7
+ }
8
+ /**
9
+ * Reads a page's title and its one-paragraph summary.
10
+ *
11
+ * @param path - The page's path, for messages.
12
+ * @param text - The page's markdown.
13
+ * @returns The title and the note.
14
+ * @throws {@link AgentDocsError} If the page has no `# Title` line or no paragraph under it.
15
+ *
16
+ * @remarks
17
+ * HTML comments, code fences, lists, quotes, tables and headings are skipped on the way to the paragraph.
18
+ * Links become their text, because a relative link from a page breaks once copied into llms.txt.
19
+ */
20
+ export declare function describePage(path: string, text: string): PageSummary;
@@ -0,0 +1,57 @@
1
+ import { AgentDocsError } from '../core/errors.js';
2
+ const H1 = /^# \S/;
3
+ const NOT_PROSE = /^(#|>|[-*|]|\d+\.|<|```)/;
4
+ const MARKDOWN_LINK = /\[([^\]]+)\]\([^)]*\)/g;
5
+ /**
6
+ * Reads a page's title and its one-paragraph summary.
7
+ *
8
+ * @param path - The page's path, for messages.
9
+ * @param text - The page's markdown.
10
+ * @returns The title and the note.
11
+ * @throws {@link AgentDocsError} If the page has no `# Title` line or no paragraph under it.
12
+ *
13
+ * @remarks
14
+ * HTML comments, code fences, lists, quotes, tables and headings are skipped on the way to the paragraph.
15
+ * Links become their text, because a relative link from a page breaks once copied into llms.txt.
16
+ */
17
+ export function describePage(path, text) {
18
+ const lines = text.split('\n');
19
+ const h1Index = lines.findIndex((line) => H1.test(line));
20
+ if (h1Index === -1) {
21
+ throw new AgentDocsError([`${path} has no "# Title" line: start the page with one.`]);
22
+ }
23
+ const title = lines[h1Index].slice(2).trim();
24
+ const paragraph = [];
25
+ let inFence = false;
26
+ let inComment = false;
27
+ for (const line of lines.slice(h1Index + 1)) {
28
+ if (line.startsWith('```')) {
29
+ inFence = inFence === false;
30
+ }
31
+ const opensComment = inFence === false && line.includes('<!--');
32
+ if (opensComment) {
33
+ inComment = true;
34
+ }
35
+ if (inComment) {
36
+ if (line.includes('-->')) {
37
+ inComment = false;
38
+ }
39
+ if (paragraph.length > 0) {
40
+ break;
41
+ }
42
+ continue;
43
+ }
44
+ const trimmed = line.trim();
45
+ const isProse = inFence === false && trimmed !== '' && NOT_PROSE.test(trimmed) === false;
46
+ if (isProse) {
47
+ paragraph.push(trimmed);
48
+ }
49
+ else if (paragraph.length > 0) {
50
+ break;
51
+ }
52
+ }
53
+ if (paragraph.length === 0) {
54
+ throw new AgentDocsError([`${path} needs a one-paragraph summary under its title.`]);
55
+ }
56
+ return { title, note: paragraph.join(' ').replace(MARKDOWN_LINK, '$1') };
57
+ }
package/llms.txt ADDED
@@ -0,0 +1,42 @@
1
+ # @cubicecho/agent-docs
2
+
3
+ > 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.
4
+
5
+ Agent-facing docs for @cubicecho/agent-docs: one task or concept per page, then what each package.json "exports" entry exports. Generated from _agents/docs/ and the doc comments in src/ by @cubicecho/agent-docs; edit those, not this file.
6
+
7
+ Requires Node >=22.
8
+
9
+ ## Docs
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`, `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
+ - [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
+ - [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
+ - [_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.
17
+
18
+ ## Exports: @cubicecho/agent-docs
19
+
20
+ Generates and checks the agent docs a package ships.
21
+
22
+ - `CheckResult` (type): What checkAgentDocs found.
23
+ - `checkAgentDocs`: Checks a package against the agent documentation standard, changing nothing.
24
+ - `CliOutput` (type): Where the CLI prints.
25
+ - `ExitCode`: The process exit codes the CLI returns.
26
+ - `runCli`: Runs one CLI command against a package.
27
+ - `LlmsConfig` (type): `_agents/llms.json`, the overrides both commands share, with its defaults filled in.
28
+ - `loadLlmsConfig`: Reads `_agents/llms.json`, or the defaults when it is absent.
29
+ - `AgentDocsError`: The docs or the package can't be read or generated as they stand.
30
+ - `LAYOUT_DEFAULTS`: The layout the agent docs standard and the cubicecho build use.
31
+ - `LayoutSettings` (type): Where the docs and the source they index are found.
32
+ - `LIMIT_DEFAULTS`: The limits the agent docs standard sets.
33
+ - `LimitSettings` (type): The size limits both commands hold the docs to.
34
+ - `firstSentence`: The first sentence of a paragraph.
35
+ - `summarize`: The one-line summary a doc comment gives the index.
36
+ - `ExportPlacement`: Where the export index went.
37
+ - `GeneratedFile` (type): One file the plan writes.
38
+ - `LlmsOptions` (type): What planLlms reads.
39
+ - `LlmsPlan` (type): Everything one run of `llms` writes, before anything is written.
40
+ - `planLlms`: Works out llms.txt, and the export pages when there are any, without writing anything.
41
+ - `findStaleFiles`: Compares a plan with the files on disk, for CI.
42
+ - `writeLlms`: Writes a plan's files and deletes the export pages it no longer generates.
package/package.json CHANGED
@@ -1,6 +1,66 @@
1
1
  {
2
2
  "name": "@cubicecho/agent-docs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
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
+ "keywords": [
6
+ "llms.txt",
7
+ "agents",
8
+ "documentation",
9
+ "tsdoc",
10
+ "ci",
11
+ "typescript"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Benjamin Van Treese <vantreeseba@gmail.com>",
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/cubicecho/agent-docs.git"
22
+ },
23
+ "homepage": "https://github.com/cubicecho/agent-docs#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/cubicecho/agent-docs/issues"
26
+ },
27
+ "bin": {
28
+ "agent-docs": "dist/bin.js"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "llms.txt",
39
+ "_agents/docs"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc -p tsconfig.build.json",
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
+ "check:biome": "biome check --write .",
49
+ "check:types": "tsc --noEmit",
50
+ "test": "vitest run",
51
+ "test:watch": "vitest",
52
+ "llms": "node src/bin.ts llms",
53
+ "docs:check": "node src/bin.ts check",
54
+ "coverage": "vitest run --coverage"
55
+ },
56
+ "devDependencies": {
57
+ "@biomejs/biome": "2.5.12",
58
+ "@semantic-release/changelog": "^7.0.0",
59
+ "@semantic-release/git": "^11.0.1",
60
+ "@types/node": "^26.6.11",
61
+ "@vitest/coverage-v8": "^4.1.12",
62
+ "semantic-release": "^25.0.9",
63
+ "typescript": "^7.0.2",
64
+ "vitest": "^4.1.12"
65
+ }
66
+ }