@guiho/xdocs 0.3.1 → 0.4.9

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 (52) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/DOCS.md +108 -37
  3. package/README.md +108 -33
  4. package/docs/2026-07-05-xdocs-document-model.md +77 -0
  5. package/docs/decisions/2026-07-09-package-launcher-source-fallback.md +65 -0
  6. package/docs/decisions/decisions.xdocs.md +22 -0
  7. package/docs/docs.xdocs.md +23 -0
  8. package/jsr.json +1 -1
  9. package/library/agents.d.ts +1 -1
  10. package/library/agents.d.ts.map +1 -1
  11. package/library/agents.js +10 -6
  12. package/library/commands/generate.d.ts.map +1 -1
  13. package/library/commands/generate.js +23 -1
  14. package/library/commands/list.d.ts.map +1 -1
  15. package/library/commands/list.js +14 -4
  16. package/library/commands/merge.d.ts.map +1 -1
  17. package/library/commands/merge.js +12 -1
  18. package/library/commands/scan.d.ts.map +1 -1
  19. package/library/commands/scan.js +13 -2
  20. package/library/config.d.ts.map +1 -1
  21. package/library/config.js +7 -3
  22. package/library/discovery.d.ts +8 -4
  23. package/library/discovery.d.ts.map +1 -1
  24. package/library/discovery.js +107 -17
  25. package/library/flags.d.ts +1 -1
  26. package/library/flags.js +1 -1
  27. package/library/guiho-xdocs-bin.d.ts +1 -1
  28. package/library/guiho-xdocs-bin.js +1 -1
  29. package/library/guiho-xdocs.d.ts +2 -2
  30. package/library/guiho-xdocs.d.ts.map +1 -1
  31. package/library/guiho-xdocs.js +1 -1
  32. package/library/help.js +16 -15
  33. package/library/metadata.d.ts +1 -1
  34. package/library/metadata.d.ts.map +1 -1
  35. package/library/metadata.js +23 -3
  36. package/library/tree.d.ts +1 -1
  37. package/library/tree.d.ts.map +1 -1
  38. package/library/tree.js +2 -2
  39. package/library/types.d.ts +14 -2
  40. package/library/types.d.ts.map +1 -1
  41. package/package.json +5 -3
  42. package/prompts/agents.md +9 -2
  43. package/prompts/generate.md +10 -2
  44. package/prompts/prompts.xdocs.md +27 -0
  45. package/prompts/update.md +19 -7
  46. package/prompts/write.md +18 -5
  47. package/scripts/install-package.ts +42 -22
  48. package/scripts/scripts.xdocs.md +10 -3
  49. package/scripts/xdocs-bin.ts +16 -2
  50. package/skills/guiho-s-xdocs/SKILL.md +133 -32
  51. package/skills/guiho-s-xdocs/guiho-s-xdocs.xdocs.md +26 -0
  52. package/skills/skills.xdocs.md +9 -4
@@ -0,0 +1,27 @@
1
+ ---
2
+ subject: xdocs-prompts
3
+ description: Runtime prompt templates used by xdocs prompt commands and embedded into native binaries.
4
+ parent: xdocs-package
5
+ children: []
6
+ files: {}
7
+ documents:
8
+ agents.md: Prompt for updating AGENTS.md with xdocs instructions.
9
+ generate.md: Prompt for generating comprehensive documentation from xdocs metadata.
10
+ update.md: Prompt for updating existing xdocs descriptors after code or document changes.
11
+ write.md: Prompt for writing a named xdocs descriptor for a module.
12
+ tags:
13
+ - prompts
14
+ - ai
15
+ - documentation
16
+ keywords:
17
+ - prompts
18
+ - AI instructions
19
+ - documentation generation
20
+ flags: []
21
+ status: stable
22
+ ---
23
+
24
+ The `prompts/` directory contains Markdown prompt templates loaded by
25
+ `source/prompts.ts` at runtime and embedded by `source/embedded-resources.ts` for
26
+ native binaries. They are plain companion documents, so this descriptor lists
27
+ each prompt under `documents`.
package/prompts/update.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  name: update
3
- description: Update existing xdocs files after code changes.
3
+ description: Update existing xdocs descriptors after code or document changes.
4
+ keywords:
5
+ - update descriptor
6
+ - synchronize metadata
7
+ - documentation maintenance
4
8
  ---
5
9
 
6
10
  # xdocs: Update Documentation
@@ -10,22 +14,30 @@ You are an AI assistant tasked with updating existing xdocs documentation after
10
14
  ## Instructions
11
15
 
12
16
  1. Identify which files have changed in the recent modifications.
13
- 2. Find the xdocs files that document the directories containing those changes.
14
- 3. For each affected xdocs file:
17
+ 2. Find the named `*.xdocs.md` descriptor files that document the directories
18
+ containing those changes. There must be exactly one descriptor per directory,
19
+ and it must not be named only `.xdocs.md`.
20
+ 3. For each affected xdocs descriptor:
15
21
  a. Re-read the files listed in the metadata to check if descriptions are still accurate.
16
22
  b. Check if new files were added that need to be listed.
17
23
  c. Check if files were removed that should be unlisted.
18
- d. Update the description if the module's purpose has changed.
19
- e. Update children if subdirectories were added or removed.
20
- f. Update the body content if significant changes occurred.
21
- 4. Preserve the existing structure and style of the xdocs file.
24
+ d. Check if sibling plain `*.md` documents were added or removed, and keep
25
+ the `documents` metadata map exact.
26
+ e. Update the description if the module's purpose has changed.
27
+ f. Update `keywords` if the module's searchable concepts changed.
28
+ g. Update children if subdirectories were added or removed.
29
+ h. Update the body content if significant changes occurred.
30
+ 4. Preserve the existing structure and style of the xdocs descriptor.
22
31
  5. Do not remove information that is still accurate.
23
32
 
24
33
  ## Checklist
25
34
 
26
35
  - [ ] All new files are listed in the files metadata
27
36
  - [ ] Removed files are no longer listed
37
+ - [ ] All sibling plain Markdown documents are listed in the documents metadata
38
+ - [ ] Removed Markdown documents are no longer listed
28
39
  - [ ] File descriptions are accurate
29
40
  - [ ] Module description reflects current state
41
+ - [ ] Keywords reflect current searchable concepts
30
42
  - [ ] Children list matches actual subdirectories
31
43
  - [ ] Parent reference is still correct
package/prompts/write.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ---
2
2
  name: write
3
- description: Scan a directory and write a new xdocs documentation file for it.
3
+ description: Scan a directory and write a new named xdocs descriptor for it.
4
+ keywords:
5
+ - write descriptor
6
+ - xdocs metadata
7
+ - module documentation
4
8
  ---
5
9
 
6
10
  # xdocs: Write Documentation
@@ -12,19 +16,25 @@ You are an AI assistant tasked with writing xdocs documentation for a directory/
12
16
  1. Scan the target directory and all its subdirectories.
13
17
  2. Read every source file to understand what it does.
14
18
  3. Identify the purpose of this module/directory.
15
- 4. Create an xdocs file with YAML frontmatter containing:
19
+ 4. Create a named xdocs descriptor with YAML frontmatter containing:
16
20
  - subject: A short identifier for this module
17
21
  - description: A concise description of what this module does
18
22
  - parent: The parent module's subject (or null if this is a root module)
19
23
  - children: List of child module subjects
20
24
  - files: Map of filename to short description for each file
25
+ - documents: Map of same-directory plain Markdown filename to short description
21
26
  - tags: Relevant tags (empty array if none)
27
+ - keywords: Search terms and concepts that should help agents match requests
22
28
  - flags: Relevant flags (empty array if none)
23
29
  5. Write a Markdown body below the frontmatter with:
24
30
  - An overview section explaining the module in more detail
25
31
  - Usage examples if relevant
26
32
  - Any important notes or caveats
27
- 6. Name the file as `<module-name>.xdocs.md` in the target directory.
33
+ 6. Name the file as `<module-name>.xdocs.md` in the target directory. Never name
34
+ a file only `.xdocs.md`; `.xdocs.md` is the extension, not the full filename.
35
+ 7. Use only `.xdocs.md` for xdocs descriptors. Do not create `.docs.md` files.
36
+ 8. If the directory contains sibling plain `*.md` files, list each one under
37
+ `documents` in this descriptor.
28
38
 
29
39
  ## Frontmatter Template
30
40
 
@@ -37,9 +47,12 @@ children:
37
47
  - child-a
38
48
  - child-b
39
49
  files:
40
- - file-a.ts: What file-a does.
41
- - file-b.ts: What file-b does.
50
+ file-a.ts: What file-a does.
51
+ file-b.ts: What file-b does.
52
+ documents:
53
+ implementation-notes.md: What this companion document explains.
42
54
  tags: []
55
+ keywords: []
43
56
  flags: []
44
57
  ---
45
58
  ```
@@ -23,33 +23,47 @@ if (await sourceEntrypoint.exists()) {
23
23
 
24
24
  const version = process.env['XDOCS_VERSION'] ?? packageJson.version ?? 'latest'
25
25
  const repo = process.env['XDOCS_REPO'] ?? 'CGuiho/xdocs'
26
- const asset = detectAsset()
27
- const bundledAsset = Bun.file(new URL(`../bin/${asset}`, import.meta.url))
26
+ const candidates = detectAssetCandidates()
28
27
  const destination = new URL(`../vendor/xdocs${process.platform === 'win32' ? '.exe' : ''}`, import.meta.url)
29
28
 
30
- if (await bundledAsset.exists()) {
31
- await Bun.write(destination, bundledAsset)
32
- await makeExecutable(destination)
33
- console.log(`installed bundled xdocs native binary: ${asset}`)
34
- process.exit(0)
29
+ for (const asset of candidates) {
30
+ const bundledAsset = Bun.file(new URL(`../bin/${asset}`, import.meta.url))
31
+
32
+ if (await bundledAsset.exists()) {
33
+ await Bun.write(destination, bundledAsset)
34
+ await makeExecutable(destination)
35
+ console.log(`installed bundled xdocs native binary: ${asset}`)
36
+ process.exit(0)
37
+ }
35
38
  }
36
39
 
37
- const tag = version === 'latest' ? 'latest' : `@guiho/xdocs@${version}`
38
- const url = tag === 'latest'
39
- ? `https://github.com/${repo}/releases/latest/download/${asset}`
40
- : `https://github.com/${repo}/releases/download/${encodeURIComponent(tag)}/${asset}`
40
+ for (const asset of candidates) {
41
+ const tag = version === 'latest' ? 'latest' : `@guiho/xdocs@${version}`
42
+ const url = tag === 'latest'
43
+ ? `https://github.com/${repo}/releases/latest/download/${asset}`
44
+ : `https://github.com/${repo}/releases/download/${encodeURIComponent(tag)}/${asset}`
41
45
 
42
- const response = await fetch(url)
46
+ console.log(` Downloading ${asset} from GitHub Releases...`)
47
+ const response = await fetch(url)
43
48
 
44
- if (!response.ok) {
45
- console.error(`error: failed to download ${url}`)
46
- console.error(`status: ${response.status} ${response.statusText}`)
47
- process.exit(1)
49
+ if (!response.ok) {
50
+ if (candidates.length > 1 && asset !== candidates[candidates.length - 1]) {
51
+ console.log(` ${asset} not available (${response.status}), trying next variant...`)
52
+ continue
53
+ }
54
+ console.error(`error: failed to download ${url}`)
55
+ console.error(`status: ${response.status} ${response.statusText}`)
56
+ process.exit(1)
57
+ }
58
+
59
+ await Bun.write(destination, response)
60
+ await makeExecutable(destination)
61
+ console.log(`installed xdocs native binary: ${asset}`)
62
+ process.exit(0)
48
63
  }
49
64
 
50
- await Bun.write(destination, response)
51
- await makeExecutable(destination)
52
- console.log(`installed xdocs native binary: ${asset}`)
65
+ console.error('error: no compatible xdocs binary found for this platform')
66
+ process.exit(1)
53
67
 
54
68
  async function makeExecutable(path: URL) {
55
69
  if (process.platform === 'win32') return
@@ -66,10 +80,16 @@ async function makeExecutable(path: URL) {
66
80
  }
67
81
  }
68
82
 
69
- function detectAsset() {
83
+ function detectAssetCandidates() {
70
84
  const os = detectOs()
71
85
  const arch = detectArch()
72
- return `xdocs-${os}-${arch}${os === 'windows' ? '.exe' : ''}`
86
+ const ext = os === 'windows' ? '.exe' : ''
87
+
88
+ if (arch === 'x64') {
89
+ return [`xdocs-${os}-x64-baseline${ext}`, `xdocs-${os}-x64${ext}`, `xdocs-${os}-x64-modern${ext}`]
90
+ }
91
+
92
+ return [`xdocs-${os}-${arch}${ext}`]
73
93
  }
74
94
 
75
95
  function detectOs() {
@@ -85,4 +105,4 @@ function detectArch() {
85
105
  if (process.arch === 'arm64') return 'arm64'
86
106
  console.error(`error: unsupported architecture: ${process.arch}`)
87
107
  process.exit(1)
88
- }
108
+ }
@@ -4,17 +4,24 @@ description: Package-manager launcher and installation scripts for executing the
4
4
  parent: xdocs-package
5
5
  children: []
6
6
  files:
7
- xdocs-bin.ts: Shipped Bun launcher used as the package bin; installs the native binary on first run when needed and delegates to it.
7
+ xdocs-bin.ts: Shipped Bun launcher used as the package bin; delegates to an installed native binary, falls back to the TypeScript CLI in source checkouts, and installs the native binary on first run for published packages.
8
8
  install-package.ts: Package-manager install helper that downloads or copies the matching GitHub Release native binary into vendor/xdocs or vendor/xdocs.exe.
9
+ documents: {}
9
10
  tags:
10
11
  - install
11
12
  - native-binary
12
13
  - package-manager
14
+ keywords:
15
+ - package launcher
16
+ - native binary
17
+ - vendor install
13
18
  flags: []
14
19
  status: stable
15
20
  ---
16
21
 
17
22
  The `scripts/` directory contains the package-manager launcher and install
18
23
  helper. Package-manager and `bunx` execution start in `xdocs-bin.ts`; if the
19
- native binary is missing, it runs `install-package.ts` and then delegates to the
20
- downloaded binary in `vendor/`. Direct installers remain the no-Bun runtime path.
24
+ native binary is missing in a published package, it runs `install-package.ts` and
25
+ then delegates to the downloaded binary in `vendor/`. Source checkouts run the
26
+ TypeScript CLI directly when no vendor binary exists. Direct installers remain
27
+ the no-Bun runtime path.
@@ -6,10 +6,24 @@
6
6
  */
7
7
 
8
8
  const binaryPath = new URL(`../vendor/xdocs${process.platform === 'win32' ? '.exe' : ''}`, import.meta.url)
9
+ const sourceEntrypointPath = new URL('../source/guiho-xdocs-bin.ts', import.meta.url)
9
10
  const executablePath = Bun.fileURLToPath(binaryPath)
10
11
  const binary = Bun.file(binaryPath)
12
+ const args = process.argv.slice(2)
11
13
 
12
14
  if (!(await binary.exists())) {
15
+ const sourceEntrypoint = Bun.file(sourceEntrypointPath)
16
+
17
+ if (await sourceEntrypoint.exists()) {
18
+ const proc = Bun.spawn([process.execPath, Bun.fileURLToPath(sourceEntrypointPath), ...args], {
19
+ stdin: 'inherit',
20
+ stdout: 'inherit',
21
+ stderr: 'inherit',
22
+ })
23
+
24
+ process.exit(await proc.exited)
25
+ }
26
+
13
27
  const installerPath = new URL('install-package.ts', import.meta.url)
14
28
  const proc = Bun.spawn([process.execPath, Bun.fileURLToPath(installerPath)], {
15
29
  stdin: 'inherit',
@@ -24,10 +38,10 @@ if (!(await binary.exists())) {
24
38
  }
25
39
  }
26
40
 
27
- const proc = Bun.spawn([executablePath, ...process.argv.slice(2)], {
41
+ const proc = Bun.spawn([executablePath, ...args], {
28
42
  stdin: 'inherit',
29
43
  stdout: 'inherit',
30
44
  stderr: 'inherit',
31
45
  })
32
46
 
33
- process.exit(await proc.exited)
47
+ process.exit(await proc.exited)
@@ -1,15 +1,30 @@
1
1
  ---
2
2
  name: guiho-s-xdocs
3
- version: 0.3.0
4
- description: Use this skill whenever the user works with xdocs (`@guiho/xdocs`) structured documentation, AND proactively whenever you create a new module or subdirectory or add/change/remove files in a directory of an xdocs project, so you create or update that directory's `.xdocs.md` as part of the change. This includes creating, updating, or regenerating `.docs.md` / `.xdocs.md` files, the root `XDOCS.md`, the project tree, scanning documentation coverage, merging docs, or maintaining xdocs metadata and AGENTS.md guidance, even when the user only says "document this module", "update the docs", or "what does this folder do" without naming xdocs.
3
+ version: 0.4.0
4
+ purpose: Teach AI agents how to maintain xdocs descriptor files, companion Markdown documents, metadata, and tree integrity.
5
+ description: Use this skill whenever the user works with xdocs (`@guiho/xdocs`) structured documentation, AND proactively whenever you create a new module or subdirectory or add/change/remove files in a directory of an xdocs project, so you create or update that directory's named `*.xdocs.md` descriptor as part of the change. This includes creating, updating, or regenerating `*.xdocs.md` descriptor files, companion Markdown documents, the root `XDOCS.md`, the project tree, scanning documentation coverage, merging docs, or maintaining xdocs metadata and AGENTS.md guidance, even when the user only says "document this module", "update the docs", or "what does this folder do" without naming xdocs.
6
+ created: 2026-07-06
7
+ flags:
8
+ - automatic-documentation-maintenance
9
+ - companion-document-metadata
10
+ tags:
11
+ - xdocs
12
+ - documentation
13
+ - agents
14
+ keywords:
15
+ - xdocs
16
+ - structured documentation
17
+ - companion documents
18
+ - agent workflow
19
+ owner: xdocs-guiho-s-xdocs-skill
5
20
  ---
6
21
 
7
22
  # GUIHO XDocs
8
23
 
9
- GUIHO XDocs is a deterministic CLI and TypeScript library for **structured documentation of codebases**. It lets an AI agent understand a project without reading every source file: each directory carries a small Markdown file with YAML frontmatter that describes its subject, purpose, files, and place in a parent-child hierarchy.
24
+ GUIHO XDocs is a deterministic CLI and TypeScript library for **structured documentation of codebases**. It lets an AI agent understand a project without reading every source file: each documented directory carries one named `*.xdocs.md` descriptor with YAML frontmatter that describes its subject, purpose, files, companion Markdown documents, and place in a parent-child hierarchy.
10
25
 
11
26
  ```text
12
- source tree -> xdocs files (.docs.md / .xdocs.md) -> tree + metadata -> AI-readable map
27
+ source tree -> named *.xdocs.md descriptors + companion *.md documents -> tree + metadata -> AI-readable map
13
28
  ```
14
29
 
15
30
  Use xdocs for documentation work instead of ad hoc README sprawl or re-reading the whole codebase. The value of xdocs is that the structure (subjects, descriptions, files, parent/child links) is machine-readable and stays close to the code it describes.
@@ -28,15 +43,16 @@ xdocs is a Bun/TypeScript ESM tool. Bun is the recommended runtime. The CLI neve
28
43
 
29
44
  ## Core Concepts
30
45
 
31
- - **xdocs file**: a Markdown file with YAML frontmatter that documents one directory/module. Default extensions are `.docs.md` and `.xdocs.md`. Extensions are configurable in `xdocs.config.toml`.
46
+ - **xdocs descriptor**: a named Markdown file ending in `.xdocs.md` with YAML frontmatter that documents one directory/module. There is exactly one descriptor per documented directory. The file must have a name such as `authentication.xdocs.md`; a file named only `.xdocs.md` is invalid.
47
+ - **Companion document**: a same-directory plain Markdown file ending in `.md` but not `.xdocs.md` and not `XDOCS.md`. Every companion document must be listed in the descriptor's `documents` metadata map, and ordinary companion documents should carry their own YAML frontmatter with `name`, `purpose`, `description`, `created`, `flags`, `tags`, `keywords`, and `owner`.
32
48
  - **Repository root index**: there is exactly one `XDOCS.md` per repository, at the repo root. It has **no frontmatter** — it is a plain index that lists the repository's packages and applications, and it is not itself a tree node.
33
49
  - **Package/application root**: each package or application has its own root `.xdocs.md` file (with frontmatter and `parent: null`) that is the top of that package's documentation tree. `XDOCS.md` lists these package roots.
34
- - **Tree**: a parent-child **containment** hierarchy (not a dependency graph), assembled from each `.xdocs.md` / `.docs.md` file's `subject` / `parent` / `children` fields. A module's `parent` is the `subject` of the module that contains it; a package/application root uses `parent: null`.
50
+ - **Tree**: a parent-child **containment** hierarchy (not a dependency graph), assembled from each `.xdocs.md` descriptor's `subject` / `parent` / `children` fields. A module's `parent` is the `subject` of the module that contains it; a package/application root uses `parent: null`.
35
51
  - **AI mode**: `xdocs.config.toml` `[ai].mode` is either `"prompt"` (announce the documentation updates, then write them) or `"auto"` (write immediately). It governs *how* you write docs, not *whether* — documenting a changed module is always required (see Automatic Documentation Maintenance).
36
52
 
37
53
  ### Metadata schema (YAML frontmatter)
38
54
 
39
- Every `.xdocs.md` / `.docs.md` file carries frontmatter with these fields. The repository's single `XDOCS.md` is the exception: it has no frontmatter and is just an index.
55
+ Every `*.xdocs.md` descriptor carries frontmatter with these fields. The repository's single `XDOCS.md` is the exception: it has no frontmatter and is just an index.
40
56
 
41
57
  | Field | Type | Meaning |
42
58
  | ------------- | --------------------- | ------------------------------------------------------------ |
@@ -45,29 +61,74 @@ Every `.xdocs.md` / `.docs.md` file carries frontmatter with these fields. The r
45
61
  | `parent` | string \| null | `subject` of the containing module; `null` for a package/application root. |
46
62
  | `children` | string[] | `subject`s of directly contained modules. |
47
63
  | `files` | map<string,string> | Filename -> short description of each significant file. |
64
+ | `documents` | map<string,string> | Same-directory plain Markdown filename -> short description. |
48
65
  | `tags` | string[] | Free-form classification labels. |
66
+ | `keywords` | string[] | Search terms and concepts agents can use to match requests. |
49
67
  | `flags` | string[] | Behavioral markers for tools/agents. |
50
68
  | `status` | string (optional) | Lifecycle marker (e.g. `stable`, `draft`, `deprecated`). |
51
69
 
52
- Keep `subject` values unique across the project, keep `parent`/`children` consistent in both directions, and keep `files` in sync with what is actually on disk.
70
+ Keep `subject` values unique across the project, keep `parent`/`children` consistent in both directions, keep `files` in sync with implementation files, and keep `documents` in sync with same-directory plain Markdown files.
71
+
72
+ ### Companion document metadata (YAML frontmatter)
73
+
74
+ Ordinary same-directory companion Markdown documents also use YAML frontmatter.
75
+ This metadata makes the document useful before an agent reads the whole body.
76
+ The `owner` field must be the `subject` of the same-directory xdocs descriptor
77
+ that owns the document.
78
+
79
+ ```yaml
80
+ ---
81
+ name: authentication-implementation
82
+ purpose: Explain the implementation details and decisions behind authentication.
83
+ description: Detailed notes for login, password verification, and session behavior.
84
+ created: 2026-07-06
85
+ flags: []
86
+ tags:
87
+ - security
88
+ keywords:
89
+ - login
90
+ - password verification
91
+ - sessions
92
+ owner: auth
93
+ ---
94
+ ```
95
+
96
+ Companion document fields:
97
+
98
+ | Field | Type | Meaning |
99
+ | ------------- | ---------- | -------------------------------------------------------------- |
100
+ | `name` | string | Stable document name or title. |
101
+ | `purpose` | string | Why this document exists and what question it answers. |
102
+ | `description` | string | One-line summary of the document's contents. |
103
+ | `created` | string | Creation date in `YYYY-MM-DD` format. |
104
+ | `flags` | string[] | Behavioral markers for tools/agents. |
105
+ | `tags` | string[] | Free-form classification labels. |
106
+ | `keywords` | string[] | Search terms and concepts agents can use to match requests. |
107
+ | `owner` | string | Owning xdocs descriptor `subject` in the same directory. |
108
+
109
+ Special-purpose Markdown files that already have a required host schema, such
110
+ as prompt templates or `SKILL.md`, must preserve their required host fields.
111
+ When compatible, add the companion metadata fields as well.
53
112
 
54
113
  ## Automatic Documentation Maintenance (core responsibility)
55
114
 
56
- Maintaining xdocs files is an **automatic, built-in responsibility — not a task the user has to request.** Treat it as part of the definition of done for every code change in an xdocs project. The user should never have to ask you to document a module; you do it as a reflex whenever you touch one.
115
+ Maintaining xdocs descriptors is an **automatic, built-in responsibility — not a task the user has to request.** Treat it as part of the definition of done for every code change in an xdocs project. The user should never have to ask you to document a module; you do it as a reflex whenever you touch one.
57
116
 
58
- **Trigger.** Whenever you, as the agent, do any of the following, you must create or update the affected directory's xdocs file in the *same unit of work*, before you consider the task finished:
117
+ **Trigger.** Whenever you, as the agent, do any of the following, you must create or update the affected directory's named xdocs descriptor in the *same unit of work*, before you consider the task finished:
59
118
 
60
119
  - Create a new directory, module, or subpackage.
61
120
  - Add, rename, move, or delete significant files in a directory.
121
+ - Add, rename, move, or delete sibling plain Markdown documents in a directory.
62
122
  - Change what a module does, what it exposes, or how it relates to its parent or children.
63
123
 
64
124
  **Action.**
65
125
 
66
- - If the directory has **no** xdocs file, create one (for example `<name>.xdocs.md`) in that directory.
67
- - If it **already** has one, update it so it matches the new reality.
126
+ - If the directory has **no** xdocs descriptor, create one named `<name>.xdocs.md` in that directory.
127
+ - If it **already** has one, update it so it matches the new reality. If there is more than one descriptor, consolidate to one.
128
+ - Never create or keep a descriptor named only `.xdocs.md`. `.xdocs.md` is the extension, not the whole filename.
68
129
  - Then fix the parent/child links and verify with `<xdocs> tree`.
69
130
 
70
- **What every module's xdocs file must capture:**
131
+ **What every module's xdocs descriptor must capture:**
71
132
 
72
133
  - `subject` — the module's unique name in the tree.
73
134
  - `description` — the module's **purpose**: what it is for and what it does.
@@ -75,12 +136,16 @@ Maintaining xdocs files is an **automatic, built-in responsibility — not a tas
75
136
  - `parent` — the `subject` of the containing module (and add this module to that parent's `children`).
76
137
  - `children` — the `subject`s of the modules contained inside this one.
77
138
 
78
- **Do not wait to be asked.** After you finish creating or modifying a module or directory, create or update its xdocs file as part of the same change. A code change that adds or alters a module is **not complete** until its xdocs file and the affected parent/child links are updated.
139
+ Every descriptor also includes `documents`, a map from each same-directory plain Markdown filename to the purpose of that companion document.
140
+ Each ordinary companion document listed there should include its own frontmatter
141
+ with `owner` equal to this descriptor's `subject`.
142
+
143
+ **Do not wait to be asked.** After you finish creating or modifying a module or directory, create or update its xdocs descriptor as part of the same change. A code change that adds or alters a module is **not complete** until its xdocs descriptor, companion-document list, and affected parent/child links are updated.
79
144
 
80
145
  **How `[ai].mode` applies.** The mode controls only *how* you write the docs, never *whether* you write them and never whether the user must ask first:
81
146
 
82
- - `auto` — create/update the xdocs files immediately as part of the change, then report what changed.
83
- - `prompt` — state exactly which xdocs files you are creating or updating, then write them (honoring any pending confirmation). Announcing is for transparency; it does not make documentation optional and the user never has to request it.
147
+ - `auto` — create/update the xdocs descriptors immediately as part of the change, then report what changed.
148
+ - `prompt` — state exactly which xdocs descriptors you are creating or updating, then write them (honoring any pending confirmation). Announcing is for transparency; it does not make documentation optional and the user never has to request it.
84
149
 
85
150
  ### Example: documenting a new module
86
151
 
@@ -95,8 +160,14 @@ children: []
95
160
  files:
96
161
  login.ts: Email/password login flow; exports `login()` and `verifyPassword()`.
97
162
  session.ts: Session lifecycle; exports `createSession()` and `validateSession()`.
163
+ documents:
164
+ authentication-implementation.md: Companion notes that explain implementation details and decisions.
98
165
  tags:
99
166
  - security
167
+ keywords:
168
+ - authentication
169
+ - login
170
+ - sessions
100
171
  flags: []
101
172
  status: stable
102
173
  ---
@@ -105,7 +176,31 @@ Auth validates credentials and issues sessions. `login()` delegates password
105
176
  checks to `verifyPassword()`; sessions are created and validated in `session.ts`.
106
177
  ```
107
178
 
108
- Then add `auth` to the `children` list of the `src` module's xdocs file so the tree stays consistent.
179
+ Then create or update `src/auth/authentication-implementation.md` with
180
+ companion-document frontmatter:
181
+
182
+ ```markdown
183
+ ---
184
+ name: authentication-implementation
185
+ purpose: Explain authentication implementation details and decisions.
186
+ description: Detailed notes for login, password verification, and session behavior.
187
+ created: 2026-07-06
188
+ flags: []
189
+ tags:
190
+ - security
191
+ keywords:
192
+ - authentication
193
+ - password verification
194
+ - session lifecycle
195
+ owner: auth
196
+ ---
197
+
198
+ # Authentication Implementation
199
+
200
+ Describe the implementation details that are too long for `auth.xdocs.md`.
201
+ ```
202
+
203
+ Then add `auth` to the `children` list of the `src` module's xdocs descriptor so the tree stays consistent.
109
204
 
110
205
  If the directory you are documenting is the **root of a package or application** (not a sub-module), set `parent: null` instead, and list that package's root `.xdocs.md` in the repository's single `XDOCS.md` index rather than in a parent module's `children`.
111
206
 
@@ -115,23 +210,26 @@ When you start working in a project that uses xdocs:
115
210
 
116
211
  1. Read the root `XDOCS.md` to learn the project's top-level subject and structure.
117
212
  2. Run `<xdocs> tree` to see the module hierarchy.
118
- 3. Run `<xdocs> scan` to see documentation coverage and which directories are missing xdocs files.
119
- 4. Read `xdocs.config.toml` and note `[ai].mode`, the supported `[extensions]`, and `[scan].exclude`.
120
- 5. When you navigate into a module, read that module's xdocs file (frontmatter first, body only if you need more) instead of reading every source file.
213
+ 3. Run `<xdocs> scan` to see documentation coverage, invalid descriptors, and companion-document coverage.
214
+ 4. Read `xdocs.config.toml` and note `[ai].mode` and `[scan].exclude`; xdocs descriptors always use the `.xdocs.md` suffix.
215
+ 5. When you navigate into a module, read that module's named `*.xdocs.md` descriptor frontmatter first. Read listed companion documents only when their descriptions show they are relevant.
121
216
 
122
217
  ## Documentation Workflow (writing and updating)
123
218
 
124
219
  Follow this whenever the automatic trigger above fires, or when the user asks to document a directory:
125
220
 
126
- 1. Determine the target directory and whether it already has an xdocs file (`<xdocs> scan` or `<xdocs> list <path>`).
221
+ 1. Determine the target directory and whether it already has exactly one named `*.xdocs.md` descriptor (`<xdocs> scan` or `<xdocs> list <path>`).
127
222
  2. Read the directory's actual files so the documentation reflects reality. Never invent files, modules, or behavior that is not present.
128
223
  3. Respect `[ai].mode` (it controls how you write, not whether you write):
129
- - **prompt mode**: state exactly which xdocs files you are creating or updating, then write them (honor a pending confirmation, but never skip the documentation).
130
- - **auto mode**: create or update the xdocs files immediately, then report what changed.
131
- 4. Write or update the xdocs file with correct frontmatter:
132
- - Set `subject` (unique), `description` (the module's purpose), and `files` (each real file -> short purpose, including key functions/exports).
224
+ - **prompt mode**: state exactly which xdocs descriptors you are creating or updating, then write them (honor a pending confirmation, but never skip the documentation).
225
+ - **auto mode**: create or update the xdocs descriptors immediately, then report what changed.
226
+ 4. Write or update the xdocs descriptor with correct frontmatter:
227
+ - Set `subject` (unique), `description` (the module's purpose), and `files` (each real implementation/configuration file -> short purpose, including key functions/exports).
228
+ - Set `documents` to every same-directory plain Markdown file -> short purpose. Use `{}` when there are no companion documents.
229
+ - Set `keywords` to search terms and concepts that should help agents match user requests to the module.
230
+ - For each ordinary companion document, add or update frontmatter with `name`, `purpose`, `description`, `created`, `flags`, `tags`, `keywords`, and `owner`; set `owner` to the descriptor's `subject`.
133
231
  - Set `parent` to the containing module's `subject`, and add this `subject` to that parent's `children`.
134
- - Use `tags`/`flags`/`status` where useful.
232
+ - Use `tags`/`keywords`/`flags`/`status` where useful.
135
233
  5. Keep the tree consistent: if you add a module, update its parent's `children`; if you remove one, update both sides.
136
234
  6. Validate with `<xdocs> tree` (it reports duplicate subjects, orphans, and missing children) and fix any reported issues.
137
235
 
@@ -150,7 +248,8 @@ When generating from scratch, prefer `<xdocs> generate <path>` (one directory) o
150
248
 
151
249
  ## Safety Rules
152
250
 
153
- - Never leave a new or changed module undocumented. Creating or updating its xdocs file is part of finishing the work, not a separate request the user must make.
251
+ - Never leave a new or changed module undocumented. Creating or updating its xdocs descriptor is part of finishing the work, not a separate request the user must make.
252
+ - Never leave an ordinary companion Markdown document without useful frontmatter; it should identify its `owner`, purpose, tags, keywords, and flags.
154
253
  - Never fabricate files, modules, descriptions, or relationships. Documentation must match the repository.
155
254
  - Never edit generated or build outputs (`library/`, `bundle/`, `bin/`, `*.tgz`). They are ignored and regenerated.
156
255
  - In prompt mode, announce the xdocs changes you will make and honor a pending confirmation — but still treat documenting the change as required, never optional.
@@ -166,7 +265,7 @@ xdocs searches for configuration via `--config <path>`, `./xdocs.config.toml`, o
166
265
  schema = 1
167
266
 
168
267
  [extensions]
169
- supported = [".docs.md", ".xdocs.md"]
268
+ supported = [".xdocs.md"]
170
269
 
171
270
  [ai]
172
271
  mode = "prompt" # "prompt" (announce and wait) or "auto" (update immediately)
@@ -185,15 +284,17 @@ skill_tool = "agents" # default tool for auto-install: agents (standard) or
185
284
 
186
285
  Agent automation options default to true. A bare `xdocs` invocation and normal data commands always bootstrap the standard global skill when no config is present; with config, set `auto_agents_md = false` to stop xdocs from touching AGENTS.md, and `auto_skill_install = false` to stop xdocs from installing or refreshing `guiho-s-xdocs` globally.
187
286
 
287
+ The `[extensions]` section is retained for config compatibility, but the only supported descriptor suffix is `.xdocs.md`.
288
+
188
289
  ## CLI Reference
189
290
 
190
291
  ```bash
191
292
  xdocs init # create XDOCS.md + xdocs.config.toml, update AGENTS.md, install the skill
192
- xdocs scan # report xdocs coverage across the project
293
+ xdocs scan # report descriptor and companion-document coverage
193
294
  xdocs tree # print the module hierarchy
194
- xdocs list <path> # list files in a scope with descriptions
295
+ xdocs list <path> # list files and companion documents with descriptions
195
296
  xdocs generate [path] # draft documentation for a directory or the whole project
196
- xdocs merge [path] # merge a directory's xdocs files into one document
297
+ xdocs merge [path] # merge a directory's xdocs descriptors into one document
197
298
  xdocs prompt --name=<name> # print a ready-made AI prompt (write|update|agents|generate)
198
299
  xdocs agents install local # install guiho-s-xdocs into this project (.agents/skills/...)
199
300
  xdocs agents install global # install guiho-s-xdocs into the user home skills directory
@@ -252,7 +353,7 @@ await ensureAgentsInstructions(process.cwd(), true)
252
353
  When reporting an xdocs result, include:
253
354
 
254
355
  - The command that ran and the target path.
255
- - Which xdocs files were created or changed, if any.
356
+ - Which xdocs descriptors and companion documents were created or changed, if any.
256
357
  - Tree/coverage status (subjects added, orphans or duplicates resolved).
257
358
  - The configured AI mode, and — in prompt mode — exactly what you are waiting to write.
258
359
 
@@ -0,0 +1,26 @@
1
+ ---
2
+ subject: xdocs-guiho-s-xdocs-skill
3
+ description: Packaged guiho-s-xdocs agent skill that teaches AI agents how to maintain xdocs projects.
4
+ parent: xdocs-skills
5
+ children: []
6
+ files: {}
7
+ documents:
8
+ SKILL.md: Versioned xdocs workflow skill installed into .agents/skills or .claude/skills; defines descriptor, companion-document metadata, scan, tree, and maintenance rules.
9
+ tags:
10
+ - skills
11
+ - agents
12
+ - documentation
13
+ keywords:
14
+ - xdocs skill
15
+ - companion metadata
16
+ - agent workflow
17
+ flags: []
18
+ status: stable
19
+ ---
20
+
21
+ The `guiho-s-xdocs/` directory contains the bundled agent skill shipped with the
22
+ package. The installer treats `SKILL.md` as the source of truth and refreshes
23
+ installed copies when the bundled version or content changes.
24
+ The skill also documents the standard frontmatter fields expected on ordinary
25
+ companion Markdown documents: `name`, `purpose`, `description`, `created`,
26
+ `flags`, `tags`, `keywords`, and `owner`.
@@ -2,13 +2,18 @@
2
2
  subject: xdocs-skills
3
3
  description: Bundled AI-agent skills shipped with @guiho/xdocs and installed by the xdocs agents commands.
4
4
  parent: xdocs-package
5
- children: []
6
- files:
7
- guiho-s-xdocs/SKILL.md: Versioned xdocs workflow skill installed into .agents/skills or .claude/skills; replaces legacy guiho-as-xdocs installs when refreshed.
5
+ children:
6
+ - xdocs-guiho-s-xdocs-skill
7
+ files: {}
8
+ documents: {}
8
9
  tags:
9
10
  - skills
10
11
  - agents
11
12
  - documentation
13
+ keywords:
14
+ - agent skills
15
+ - bundled skill
16
+ - skill installation
12
17
  flags: []
13
18
  status: stable
14
19
  ---
@@ -16,4 +21,4 @@ status: stable
16
21
  The `skills/` directory contains the bundled `guiho-s-xdocs` agent skill. The
17
22
  installer treats this packaged skill as the current source of truth, removes
18
23
  legacy `guiho-as-xdocs` install directories, and refreshes installed copies when
19
- their frontmatter version or content differs from the bundled file.
24
+ their frontmatter version or content differs from the bundled file.