@guiho/xdocs 0.1.3 → 0.2.1
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/CHANGELOG.md +21 -0
- package/DOCS.md +522 -0
- package/README.md +36 -12
- package/jsr.json +3 -1
- package/library/agents.d.ts +74 -0
- package/library/agents.d.ts.map +1 -0
- package/library/agents.js +195 -0
- package/library/cli.d.ts.map +1 -1
- package/library/cli.js +11 -1
- package/library/commands/agents.d.ts +7 -0
- package/library/commands/agents.d.ts.map +1 -0
- package/library/commands/agents.js +64 -0
- package/library/commands/init.d.ts +1 -1
- package/library/commands/init.d.ts.map +1 -1
- package/library/commands/init.js +46 -38
- package/library/commands/scan.d.ts.map +1 -1
- package/library/commands/scan.js +2 -1
- package/library/config.d.ts +5 -1
- package/library/config.d.ts.map +1 -1
- package/library/config.js +37 -0
- package/library/flags.d.ts.map +1 -1
- package/library/flags.js +1 -0
- package/library/guiho-xdocs.d.ts +3 -2
- package/library/guiho-xdocs.d.ts.map +1 -1
- package/library/guiho-xdocs.js +3 -1
- package/library/help.d.ts.map +1 -1
- package/library/help.js +38 -3
- package/library/types.d.ts +41 -1
- package/library/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/skills/guiho-as-xdocs/SKILL.md +258 -0
package/CHANGELOG.md
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
1
|
# GUIHO XDocs Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Clarify the repository model: a repository has exactly one `XDOCS.md` (no frontmatter) that indexes its packages and applications, and each package/application has its own root `.xdocs.md` (with frontmatter and `parent: null`) that tops its tree.
|
|
6
|
+
- `xdocs init` now scaffolds `XDOCS.md` as that frontmatter-less repo root index (with `## Packages` / `## Applications` sections).
|
|
7
|
+
- `xdocs scan` reports the root `XDOCS.md` as `[root index]` instead of `[incomplete]`.
|
|
8
|
+
- Update the `guiho-as-xdocs` skill and `DOCS.md` to describe the one-`XDOCS.md`-per-repo model.
|
|
9
|
+
|
|
10
|
+
## 0.2.0
|
|
11
|
+
|
|
12
|
+
- The `guiho-as-xdocs` skill now mandates **automatic xdocs maintenance**: an agent creates or updates a directory's `.xdocs.md` (purpose, files with their key functions/exports, and `parent`/`children` links) whenever it creates or changes a module, as part of the definition of done -- the user no longer has to ask. `[ai].mode` governs how docs are written, not whether.
|
|
13
|
+
- Add `DOCS.md`, the canonical full documentation for `@guiho/xdocs`, shipped in the package.
|
|
14
|
+
- `AGENTS.md` now requires updating `DOCS.md` before each release, written the same way as the changelog.
|
|
15
|
+
|
|
16
|
+
## 0.1.4
|
|
17
|
+
|
|
18
|
+
- Add the `guiho-as-xdocs` agent skill, bundled in the package and embedded in the CLI binary.
|
|
19
|
+
- Add the `xdocs agents` command: `install <local|global> [--tool <agents|claude|all>]` and `instructions`.
|
|
20
|
+
- `xdocs init` now installs the skill and writes a skill-aware xdocs section into `AGENTS.md`.
|
|
21
|
+
- Add the `[agents]` config section (`auto_agents_md`, `auto_skill_install`, `skill_tool`) and config-gated automation that keeps the `AGENTS.md` section fresh and installs the global skill when missing.
|
|
22
|
+
- Default to the standard target (`AGENTS.md` + `.agents/skills`); the non-standard Claude target (`.claude/skills`) is used only when requested via `--tool` or detected (`.claude/` or `CLAUDE.md`).
|
package/DOCS.md
ADDED
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
# GUIHO XDocs Documentation -- @guiho/xdocs
|
|
2
|
+
|
|
3
|
+
GUIHO XDocs is a deterministic CLI and TypeScript library for structured documentation of codebases. Each directory carries a small Markdown file with YAML frontmatter that describes its subject, purpose, files, and place in a parent-child hierarchy, so an AI agent (or a human) can understand a project without reading every source file.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
source tree -> xdocs files (.docs.md / .xdocs.md) -> tree + metadata -> AI-readable map
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
XDocs is a documentation tool, not a versioning tool. It never bumps versions or mutates `package.json` version fields. Versioning for this project is handled separately by GUIHO Mirror.
|
|
10
|
+
|
|
11
|
+
## Package Overview
|
|
12
|
+
|
|
13
|
+
- Package name: `@guiho/xdocs`
|
|
14
|
+
- Runtime target: Bun (ESM)
|
|
15
|
+
- Package type: ESM
|
|
16
|
+
- Library entrypoint: `source/guiho-xdocs.ts`
|
|
17
|
+
- CLI entrypoint: `source/guiho-xdocs-bin.ts`
|
|
18
|
+
- TypeScript build output: `library/` (used by `main` and `types`)
|
|
19
|
+
- Standalone binary output: `bin/xdocs` or `bin/xdocs.exe`
|
|
20
|
+
- Dependencies: `smol-toml` (TOML config parsing), `yaml` (YAML frontmatter parsing)
|
|
21
|
+
|
|
22
|
+
The public package exposes a CLI named `xdocs` and a TypeScript API for discovering xdocs files, parsing metadata, building the hierarchy tree, generating documentation, and installing the agent skill.
|
|
23
|
+
|
|
24
|
+
## Core Model
|
|
25
|
+
|
|
26
|
+
XDocs describes a repository as a containment hierarchy of documented modules.
|
|
27
|
+
|
|
28
|
+
- Project: the repository being documented.
|
|
29
|
+
- xdocs file: a Markdown file with YAML frontmatter that documents one directory/module.
|
|
30
|
+
- Repository root index: exactly one `XDOCS.md` per repository, at the repo root. It has **no frontmatter** and is not a tree node; it is a plain index that lists the repository's packages and applications.
|
|
31
|
+
- 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.
|
|
32
|
+
- Tree: a parent-child containment hierarchy (not a dependency graph) assembled from each `.xdocs.md` / `.docs.md` file's `subject` / `parent` / `children` fields.
|
|
33
|
+
- AI mode: how an agent should behave when documentation needs updating, configured by `[ai].mode`.
|
|
34
|
+
|
|
35
|
+
The tree is the main mental model. A module's xdocs file names the module (`subject`), points up to its container (`parent`), and lists the modules it contains (`children`). A package root sets `parent: null`. Reading metadata first, and the body only when needed, lets an agent navigate a project cheaply.
|
|
36
|
+
|
|
37
|
+
## xdocs Files and Metadata
|
|
38
|
+
|
|
39
|
+
A module's xdocs file is Markdown with a YAML frontmatter block delimited by `---`. The body below the frontmatter is free-form Markdown. (The repository's single `XDOCS.md` is the one exception — it has no frontmatter and is just an index.)
|
|
40
|
+
|
|
41
|
+
```markdown
|
|
42
|
+
---
|
|
43
|
+
subject: auth
|
|
44
|
+
description: Authentication and session handling.
|
|
45
|
+
parent: src
|
|
46
|
+
children:
|
|
47
|
+
- login
|
|
48
|
+
- register
|
|
49
|
+
files:
|
|
50
|
+
login.ts: Email/password login handler.
|
|
51
|
+
session.ts: Session creation and validation.
|
|
52
|
+
tags:
|
|
53
|
+
- security
|
|
54
|
+
flags: []
|
|
55
|
+
status: stable
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
Longer prose about the module goes here.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Frontmatter fields:
|
|
62
|
+
|
|
63
|
+
| Field | Type | Meaning |
|
|
64
|
+
| ------------- | ------------------- | ------------------------------------------------------------ |
|
|
65
|
+
| `subject` | string | Unique identifier/name of this module in the tree. |
|
|
66
|
+
| `description` | string | One-line summary of what the module does. |
|
|
67
|
+
| `parent` | string \| null | `subject` of the containing module; `null` for a package/application root. |
|
|
68
|
+
| `children` | string[] | `subject`s of directly contained modules. |
|
|
69
|
+
| `files` | map<string,string> | Filename -> short description of each significant file. |
|
|
70
|
+
| `tags` | string[] | Free-form classification labels. |
|
|
71
|
+
| `flags` | string[] | Behavioral markers for tools/agents. |
|
|
72
|
+
| `status` | string (optional) | Lifecycle marker, for example `stable`, `draft`, `deprecated`. |
|
|
73
|
+
|
|
74
|
+
Keep `subject` values unique across the project, keep `parent`/`children` consistent in both directions, and keep `files` in sync with what is on disk.
|
|
75
|
+
|
|
76
|
+
## File Discovery and Extensions
|
|
77
|
+
|
|
78
|
+
XDocs discovers documentation files by extension. The default recognized extensions are `.docs.md` and `.xdocs.md`, configurable in `[extensions].supported`. The root `XDOCS.md` is always recognized.
|
|
79
|
+
|
|
80
|
+
Scanning walks the project tree and skips directories listed in `[scan].exclude`. The default exclusions are `node_modules`, `.git`, `dist`, `build`, `library`, `bin`, and `bundle`.
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
Install XDocs as a development dependency:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
bun add -d @guiho/xdocs
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Or with npm:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install -D @guiho/xdocs
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Use the CLI through the package manager or through the installed `xdocs` binary.
|
|
97
|
+
|
|
98
|
+
## Quick Start
|
|
99
|
+
|
|
100
|
+
Initialize XDocs in a project:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
xdocs init
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Report documentation coverage:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
xdocs scan
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Show the module hierarchy:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
xdocs tree
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Draft documentation for a directory:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
xdocs generate ./src/auth
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Print a ready-made AI prompt:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
xdocs prompt --name=write
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## CLI Reference
|
|
131
|
+
|
|
132
|
+
### Global Flags
|
|
133
|
+
|
|
134
|
+
- `-h`, `--help`: Show help for the CLI or a command.
|
|
135
|
+
- `-v`, `--version`: Show the xdocs version.
|
|
136
|
+
- `--cwd <path>`: Run as if XDocs started in this directory.
|
|
137
|
+
- `--config <path>`: Use an explicit `xdocs.config.toml` path.
|
|
138
|
+
- `--format <text|json|markdown>`: Output format (command-dependent; defaults to `text`).
|
|
139
|
+
- `--verbose`: Show detailed output, including tree validation warnings.
|
|
140
|
+
|
|
141
|
+
### `xdocs init`
|
|
142
|
+
|
|
143
|
+
Initializes XDocs in a project. It:
|
|
144
|
+
|
|
145
|
+
- Creates `xdocs.config.toml` with defaults (skips if it already exists).
|
|
146
|
+
- Creates the root `XDOCS.md` (skips if it already exists).
|
|
147
|
+
- Updates `AGENTS.md` with the xdocs section that points AI agents at the `guiho-as-xdocs` skill (creates `AGENTS.md` if absent; refreshes the section in place if present).
|
|
148
|
+
- Installs the `guiho-as-xdocs` skill to the standard `.agents/skills` location.
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
xdocs init
|
|
152
|
+
xdocs init --tool all # also install non-standard targets explicitly
|
|
153
|
+
xdocs init --global # install the skill under the user home directory
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Flags: `--tool <agents|claude|all>`, `--global`, `--cwd`, `--verbose`.
|
|
157
|
+
|
|
158
|
+
### `xdocs scan`
|
|
159
|
+
|
|
160
|
+
Walks every directory (respecting `[scan].exclude`), matches files against the configured extensions, and reports coverage: total files, total directories, covered vs uncovered directories, and the discovered xdocs files with validity status. Use `--verbose` to list per-file errors and uncovered directories.
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
xdocs scan
|
|
164
|
+
xdocs scan --format json
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Flags: `--format <text|json>`, `--cwd`, `--config`, `--verbose`.
|
|
168
|
+
|
|
169
|
+
### `xdocs generate [path]`
|
|
170
|
+
|
|
171
|
+
Generates Markdown documentation. With no path, it produces a project-level document containing the hierarchy and a section per module. With a path, it produces a module-level document for that directory. Output goes to stdout unless `--output <path>` is given.
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
xdocs generate # whole project to stdout
|
|
175
|
+
xdocs generate ./src/auth # one module to stdout
|
|
176
|
+
xdocs generate --output PROJECT.md # write to a file
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Flags: `--output <path>`, `--cwd`, `--config`, `--verbose`.
|
|
180
|
+
|
|
181
|
+
### `xdocs merge [path]`
|
|
182
|
+
|
|
183
|
+
Concatenates all xdocs files within a directory into a single Markdown document, each section prefixed with a `<!-- source: ... -->` marker. Output goes to stdout unless `--output <path>` is given.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
xdocs merge ./src/domain
|
|
187
|
+
xdocs merge ./src/domain --output DOMAIN.md
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Flags: `--output <path>`, `--cwd`, `--config`, `--verbose`.
|
|
191
|
+
|
|
192
|
+
### `xdocs tree`
|
|
193
|
+
|
|
194
|
+
Scans all xdocs files, reads their metadata, and assembles the parent-child hierarchy (modules only, not individual files). With `--verbose`, tree integrity warnings and errors (duplicate subjects, orphans, missing children) are printed to stderr.
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
xdocs tree
|
|
198
|
+
xdocs tree --format markdown
|
|
199
|
+
xdocs tree --format json --output tree.json
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Flags: `--format <text|markdown|json>`, `--output <path>`, `--cwd`, `--config`, `--verbose`.
|
|
203
|
+
|
|
204
|
+
### `xdocs list [path]`
|
|
205
|
+
|
|
206
|
+
Lists every documented file in a scope with a short description pulled from the `files` metadata field.
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
xdocs list
|
|
210
|
+
xdocs list ./src/auth
|
|
211
|
+
xdocs list --format json
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Flags: `--format <text|json>`, `--cwd`, `--config`.
|
|
215
|
+
|
|
216
|
+
### `xdocs prompt --name=<name>`
|
|
217
|
+
|
|
218
|
+
Outputs a ready-made, self-contained instruction prompt for an AI agent. The prompt is printed to stdout for piping into an agent.
|
|
219
|
+
|
|
220
|
+
Available prompts:
|
|
221
|
+
|
|
222
|
+
- `write`: Scan a directory and write xdocs documentation.
|
|
223
|
+
- `update`: Update existing xdocs files after code changes.
|
|
224
|
+
- `agents`: Update `AGENTS.md` with xdocs instructions.
|
|
225
|
+
- `generate`: Generate comprehensive documentation.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
xdocs prompt --name=write
|
|
229
|
+
xdocs prompt --name update
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Both `--name=value` and `--name value` forms are supported.
|
|
233
|
+
|
|
234
|
+
### `xdocs agents`
|
|
235
|
+
|
|
236
|
+
Installs the `guiho-as-xdocs` agent skill and maintains the `AGENTS.md` instruction section.
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
xdocs agents install local # install under the project (.agents/skills)
|
|
240
|
+
xdocs agents install global # install under ~/.agents/skills
|
|
241
|
+
xdocs agents install local --tool claude # explicit non-standard Claude target
|
|
242
|
+
xdocs agents install local --tool all # standard + claude
|
|
243
|
+
xdocs agents instructions # insert/refresh the AGENTS.md section
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
- `install local`: Writes the skill under the current project's skills directory.
|
|
247
|
+
- `install global`: Writes the skill under the user home skills directory.
|
|
248
|
+
- `instructions`: Creates or refreshes the xdocs section in `AGENTS.md`.
|
|
249
|
+
|
|
250
|
+
Flags: `--tool <agents|claude|all>`, `--format <text|json>`, `--cwd`.
|
|
251
|
+
|
|
252
|
+
When `--tool` is omitted, XDocs installs the standard target and adds the Claude target only when a `.claude/` directory or `CLAUDE.md` is detected in the project. Global skill installation uses the user home directory; tests and automation can override that home root with `XDOCS_AGENT_HOME`.
|
|
253
|
+
|
|
254
|
+
## Configuration Reference
|
|
255
|
+
|
|
256
|
+
XDocs discovers configuration in this order:
|
|
257
|
+
|
|
258
|
+
1. Explicit `--config <path>`
|
|
259
|
+
2. `xdocs.config.toml` in the effective current working directory
|
|
260
|
+
3. `config/xdocs.config.toml` in the effective current working directory
|
|
261
|
+
|
|
262
|
+
Root configuration takes precedence over the nested `config/xdocs.config.toml`.
|
|
263
|
+
|
|
264
|
+
Full configuration example:
|
|
265
|
+
|
|
266
|
+
```toml
|
|
267
|
+
schema = 1
|
|
268
|
+
|
|
269
|
+
[extensions]
|
|
270
|
+
supported = [".docs.md", ".xdocs.md"]
|
|
271
|
+
|
|
272
|
+
[ai]
|
|
273
|
+
mode = "prompt"
|
|
274
|
+
|
|
275
|
+
[scan]
|
|
276
|
+
exclude = ["node_modules", ".git", "dist", "build", "library", "bin", "bundle"]
|
|
277
|
+
|
|
278
|
+
[project]
|
|
279
|
+
name = "my-project"
|
|
280
|
+
|
|
281
|
+
[agents]
|
|
282
|
+
auto_agents_md = true
|
|
283
|
+
auto_skill_install = true
|
|
284
|
+
skill_tool = "agents"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### `schema`
|
|
288
|
+
|
|
289
|
+
Optional. When present, must be `1`.
|
|
290
|
+
|
|
291
|
+
### `[extensions]`
|
|
292
|
+
|
|
293
|
+
- `supported`: Array of file extensions recognized as xdocs files. Default: `[".docs.md", ".xdocs.md"]`.
|
|
294
|
+
|
|
295
|
+
### `[ai]`
|
|
296
|
+
|
|
297
|
+
- `mode`: How an AI agent handles documentation updates. `"prompt"` (default) means the agent announces the updates it would make and waits for confirmation; `"auto"` means the agent updates documentation immediately.
|
|
298
|
+
|
|
299
|
+
### `[scan]`
|
|
300
|
+
|
|
301
|
+
- `exclude`: Array of directory names to skip while scanning. Default: `["node_modules", ".git", "dist", "build", "library", "bin", "bundle"]`.
|
|
302
|
+
|
|
303
|
+
### `[project]`
|
|
304
|
+
|
|
305
|
+
- `name`: Project name used in the root `XDOCS.md` and tree output. Defaults to the current directory name.
|
|
306
|
+
|
|
307
|
+
### `[agents]`
|
|
308
|
+
|
|
309
|
+
Agent settings control skill installation and the automation that runs on data commands.
|
|
310
|
+
|
|
311
|
+
- `auto_agents_md`: Keep the `AGENTS.md` xdocs section fresh on normal commands when `AGENTS.md` already exists. Default: `true`.
|
|
312
|
+
- `auto_skill_install`: Install the standard skill globally when it is missing. Default: `true`.
|
|
313
|
+
- `skill_tool`: Default target for auto-install. Supported values are `agents` (standard) and `claude`. Default: `agents`.
|
|
314
|
+
|
|
315
|
+
## Agent Skills and Automation
|
|
316
|
+
|
|
317
|
+
XDocs ships the `guiho-as-xdocs` skill inside the package at `skills/guiho-as-xdocs/SKILL.md`. The skill is a large, on-demand instruction document; a small section in `AGENTS.md` tells an agent to load it.
|
|
318
|
+
|
|
319
|
+
Installation is standard-first:
|
|
320
|
+
|
|
321
|
+
| Target | Skill location | When installed |
|
|
322
|
+
| ------------------------- | ------------------------------------------- | --------------------------------------------------------------- |
|
|
323
|
+
| `agents` (standard) | `.agents/skills/guiho-as-xdocs/SKILL.md` | Always (default). Read by OpenCode, Codex, Jules, and any AGENTS.md tool. |
|
|
324
|
+
| `claude` (non-standard) | `.claude/skills/guiho-as-xdocs/SKILL.md` | Only when requested via `--tool`, or detected (a `.claude/` directory or `CLAUDE.md`). |
|
|
325
|
+
|
|
326
|
+
`local` scope installs under the project root; `global` scope installs under the user home directory (`~/.agents/skills/...`).
|
|
327
|
+
|
|
328
|
+
The rule is: default to the standard target. Only write non-standard files (`.claude`, `CLAUDE.md`, etc.) when the user asks for them or when those files already exist.
|
|
329
|
+
|
|
330
|
+
### Automation
|
|
331
|
+
|
|
332
|
+
When an `xdocs.config.toml` is present, the data commands (`scan`, `generate`, `merge`, `tree`, `list`) run config-gated agent automation before executing:
|
|
333
|
+
|
|
334
|
+
- If `auto_agents_md` is true and `AGENTS.md` exists, the xdocs section is kept fresh.
|
|
335
|
+
- If `auto_skill_install` is true and the global skill is missing, XDocs installs it for the configured `skill_tool` and prints a one-line notice to stderr.
|
|
336
|
+
|
|
337
|
+
Automation does nothing outside an xdocs project (no config discovered). `init` and `agents` do not run this automation; they manage agent files explicitly.
|
|
338
|
+
|
|
339
|
+
## AI Usage Workflow
|
|
340
|
+
|
|
341
|
+
Maintaining xdocs files is an automatic responsibility for an agent working in an xdocs project, not something the user has to request. The intended workflow:
|
|
342
|
+
|
|
343
|
+
1. On entering a project, read `XDOCS.md`, run `xdocs tree`, and run `xdocs scan` to understand the structure and coverage.
|
|
344
|
+
2. On navigating to a module, read that module's xdocs file (frontmatter first, body only if needed) instead of reading every source file.
|
|
345
|
+
3. On creating a new module or subdirectory, create that directory's xdocs file (for example `<name>.xdocs.md`) describing its purpose, its files (with their key functions/exports), and its `parent`/`children` links — as part of the same change, without being asked.
|
|
346
|
+
4. On modifying a module (adding, renaming, moving, or removing files, or changing what it does), update its xdocs file and the affected parent/child links so the documentation matches reality.
|
|
347
|
+
5. `[ai].mode` governs only how the agent writes: `prompt` announces the xdocs changes then writes them; `auto` writes immediately. It never makes documentation optional. A code change is not complete until the affected xdocs files are updated and `xdocs tree` is consistent.
|
|
348
|
+
6. On request, use `xdocs generate`, `xdocs merge`, and `xdocs tree` to produce documentation artifacts.
|
|
349
|
+
|
|
350
|
+
## Prompts
|
|
351
|
+
|
|
352
|
+
Prompt templates live in `prompts/*.md` and are embedded at build time via Bun text imports. Each prompt file has its own YAML frontmatter with `name` and `description`. The CLI exposes them through `xdocs prompt --name=<name>`. Available names: `write`, `update`, `agents`, `generate`.
|
|
353
|
+
|
|
354
|
+
## TypeScript API
|
|
355
|
+
|
|
356
|
+
XDocs exports types and functions from `source/guiho-xdocs.ts`.
|
|
357
|
+
|
|
358
|
+
Discovery and tree:
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
import { loadConfigOrDefaults, scanProject, buildTree, renderTree } from '@guiho/xdocs'
|
|
362
|
+
|
|
363
|
+
const config = await loadConfigOrDefaults({ cwd: process.cwd(), format: 'text', verbose: false })
|
|
364
|
+
const scan = await scanProject(config)
|
|
365
|
+
const tree = buildTree(scan.xdocsFiles)
|
|
366
|
+
|
|
367
|
+
console.log(renderTree(tree))
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Metadata parsing:
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
import { extractFrontmatter, parseXDocsFile, validateMetadata } from '@guiho/xdocs'
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
Agent skill and AGENTS.md automation:
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
import { installSkill, ensureAgentsInstructions, runAgentAutomation } from '@guiho/xdocs'
|
|
380
|
+
|
|
381
|
+
await installSkill('agents', 'local', { cwd: process.cwd() })
|
|
382
|
+
await ensureAgentsInstructions(process.cwd(), true)
|
|
383
|
+
await runAgentAutomation({ cwd: process.cwd(), format: 'text', verbose: false })
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
Configuration:
|
|
387
|
+
|
|
388
|
+
```ts
|
|
389
|
+
import { discoverConfig, loadConfig, defaultConfig, normalizeConfig } from '@guiho/xdocs'
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
The API uses the same configuration discovery and validation as the CLI.
|
|
393
|
+
|
|
394
|
+
## Internal Source Map
|
|
395
|
+
|
|
396
|
+
- `source/guiho-xdocs.ts`: public library export surface.
|
|
397
|
+
- `source/guiho-xdocs-bin.ts`: CLI binary entrypoint.
|
|
398
|
+
- `source/cli.ts`: argument parsing, command dispatch, config-gated automation, and process-facing error handling.
|
|
399
|
+
- `source/config.ts`: TOML discovery, schema validation, defaulting, default config generation, and agent-settings normalization.
|
|
400
|
+
- `source/discovery.ts`: filesystem scanning and xdocs file matching.
|
|
401
|
+
- `source/metadata.ts`: YAML frontmatter extraction and metadata validation.
|
|
402
|
+
- `source/tree.ts`: tree assembly, integrity checks, and rendering (text, markdown).
|
|
403
|
+
- `source/prompts.ts`: prompt loader (imports `prompts/*.md` as text via Bun).
|
|
404
|
+
- `source/help.ts`: help text and version display.
|
|
405
|
+
- `source/flags.ts`: argument/flag parsing utilities.
|
|
406
|
+
- `source/errors.ts`: `XDocsError` with stable exit codes and the `invariant` helper.
|
|
407
|
+
- `source/types.ts`: public and internal TypeScript types.
|
|
408
|
+
- `source/agents.ts`: agent skill installation (standard/claude, local/global), AGENTS.md section management, detection, and config-gated automation. Embeds `skills/guiho-as-xdocs/SKILL.md` via a Bun text import.
|
|
409
|
+
- `source/commands/*.ts`: one file per CLI command (`init`, `scan`, `generate`, `prompt`, `merge`, `tree`, `list`, `agents`).
|
|
410
|
+
- `prompts/*.md`: prompt templates embedded at build time.
|
|
411
|
+
- `skills/guiho-as-xdocs/SKILL.md`: bundled AI-agent skill installed by `xdocs agents` commands.
|
|
412
|
+
|
|
413
|
+
## Development Workflow
|
|
414
|
+
|
|
415
|
+
Run package commands from `xdocs/`.
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
bun install
|
|
419
|
+
bun run typecheck
|
|
420
|
+
bun test
|
|
421
|
+
bun run build
|
|
422
|
+
bun run binary
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Generated outputs are ignored and should not be hand-edited.
|
|
426
|
+
|
|
427
|
+
- `library/`: TypeScript build output used by `main` and `types`.
|
|
428
|
+
- `bin/`: compiled standalone CLI binary output.
|
|
429
|
+
- `bundle/`: optional bundled output.
|
|
430
|
+
|
|
431
|
+
There is no lint or formatter config. Existing source style is strict TypeScript, ESM imports, single quotes, and no semicolons.
|
|
432
|
+
|
|
433
|
+
## Testing
|
|
434
|
+
|
|
435
|
+
The test suite uses `bun test` and `bun:test`.
|
|
436
|
+
|
|
437
|
+
Current tests cover:
|
|
438
|
+
|
|
439
|
+
- CLI flag parsing and short aliases.
|
|
440
|
+
- YAML frontmatter extraction and metadata validation.
|
|
441
|
+
- Tree construction, rendering, and integrity validation.
|
|
442
|
+
- Config discovery, validation, and defaulting.
|
|
443
|
+
- Agent settings normalization, skill path resolution, skill installation (local/global), tool detection, and AGENTS.md section insertion.
|
|
444
|
+
|
|
445
|
+
Run all tests:
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
bun test
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
Run one file:
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
bun test source/guiho-xdocs.spec.ts
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## Build and Binary
|
|
458
|
+
|
|
459
|
+
Build the library:
|
|
460
|
+
|
|
461
|
+
```bash
|
|
462
|
+
bun run build
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
Compile the standalone binary:
|
|
466
|
+
|
|
467
|
+
```bash
|
|
468
|
+
bun run binary
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
The compiled binary embeds the prompt templates and the `guiho-as-xdocs` skill via Bun text imports, so `xdocs prompt` and `xdocs agents install` work without adjacent package files.
|
|
472
|
+
|
|
473
|
+
## Documentation Requirement Before Publishing
|
|
474
|
+
|
|
475
|
+
This file (`DOCS.md`) is the canonical, full documentation for `@guiho/xdocs`. It must describe the behavior that actually ships.
|
|
476
|
+
|
|
477
|
+
Before publishing a new version, update `DOCS.md` the same way a changelog entry is written: capture every behavior change in this release. This includes changes to CLI commands and flags, configuration fields, the metadata schema, the TypeScript API, agent skill installation and automation, package contents, and operational workflows.
|
|
478
|
+
|
|
479
|
+
Treat `DOCS.md` as a release artifact. If a code change does not require a documentation update, the release preparation should still state why none was needed. Do not publish a new version when `DOCS.md` is stale relative to the code being released.
|
|
480
|
+
|
|
481
|
+
## Publishing Checklist
|
|
482
|
+
|
|
483
|
+
Before publishing a new version:
|
|
484
|
+
|
|
485
|
+
1. Confirm intended changes are committed.
|
|
486
|
+
2. Update `DOCS.md` to reflect all changed behavior.
|
|
487
|
+
3. Update the changelog (`../CHANGELOG.md`) and other relevant docs (`README.md`, `ARCHITECTURE.md`, `AGENTS.md`) when applicable.
|
|
488
|
+
4. Run `bun run typecheck`.
|
|
489
|
+
5. Run `bun test`.
|
|
490
|
+
6. Run `bun run build`.
|
|
491
|
+
7. Run `bun run binary` when the CLI binary is part of release validation.
|
|
492
|
+
8. Build the Mirror release plan: `bun x @guiho/mirror version plan <target>`.
|
|
493
|
+
9. Commit release-documentation updates before applying the version bump.
|
|
494
|
+
10. Apply the bump with GUIHO Mirror: `bun x @guiho/mirror version apply <target> --yes`.
|
|
495
|
+
|
|
496
|
+
Versioning itself is handled by GUIHO Mirror via `mirror.config.toml`; XDocs never edits version fields directly.
|
|
497
|
+
|
|
498
|
+
## Troubleshooting
|
|
499
|
+
|
|
500
|
+
### Configuration not found
|
|
501
|
+
|
|
502
|
+
Run `xdocs init` from the project root, or pass `--config <path>`.
|
|
503
|
+
|
|
504
|
+
### A directory shows as uncovered
|
|
505
|
+
|
|
506
|
+
Add an xdocs file (`.docs.md` or `.xdocs.md`) to the directory, or adjust `[extensions].supported`. Confirm the directory is not in `[scan].exclude`.
|
|
507
|
+
|
|
508
|
+
### Tree warnings or errors
|
|
509
|
+
|
|
510
|
+
Run `xdocs tree --verbose`. Resolve duplicate `subject` values, orphaned modules (a `parent` that does not exist), and `children` that reference missing subjects. Every `subject` must be unique and every parent/child link must be consistent in both directions.
|
|
511
|
+
|
|
512
|
+
### The skill was not installed where expected
|
|
513
|
+
|
|
514
|
+
The standard target is `.agents/skills` (or `~/.agents/skills` for `--global`). The Claude target (`.claude/skills`) is only used with `--tool claude`/`all` or when a `.claude/` directory or `CLAUDE.md` is detected. Use `XDOCS_AGENT_HOME` to redirect the global home in tests.
|
|
515
|
+
|
|
516
|
+
### A normal command modified AGENTS.md or installed a global skill unexpectedly
|
|
517
|
+
|
|
518
|
+
That is the config-gated automation. Set `[agents].auto_agents_md = false` to stop AGENTS.md edits, and `[agents].auto_skill_install = false` to stop global skill installation.
|
|
519
|
+
|
|
520
|
+
### Prompt not found
|
|
521
|
+
|
|
522
|
+
Run `xdocs prompt` with one of the supported names: `write`, `update`, `agents`, or `generate`.
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ This creates:
|
|
|
34
34
|
- `XDOCS.md` -- the root documentation file for the project
|
|
35
35
|
- `xdocs.config.toml` -- configuration with sensible defaults
|
|
36
36
|
- Updates `AGENTS.md` with instructions for AI agents
|
|
37
|
-
- Installs agent skill
|
|
37
|
+
- Installs the `guiho-as-xdocs` agent skill (standard `.agents/skills`)
|
|
38
38
|
|
|
39
39
|
### Typical Workflow
|
|
40
40
|
|
|
@@ -130,7 +130,7 @@ The CLI validates tree integrity: no orphan subjects, no missing parents, no cyc
|
|
|
130
130
|
|
|
131
131
|
#### `xdocs init`
|
|
132
132
|
|
|
133
|
-
Initializes xdocs in a project. Creates the root `XDOCS.md`, the `xdocs.config.toml` configuration, updates `AGENTS.md`, and installs
|
|
133
|
+
Initializes xdocs in a project. Creates the root `XDOCS.md`, the `xdocs.config.toml` configuration, updates `AGENTS.md`, and installs the `guiho-as-xdocs` skill to the standard `.agents/skills` location.
|
|
134
134
|
|
|
135
135
|
#### `xdocs scan`
|
|
136
136
|
|
|
@@ -189,6 +189,18 @@ Lists files in a scope with descriptions pulled from xdocs metadata.
|
|
|
189
189
|
xdocs list ./src/auth
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
+
#### `xdocs agents`
|
|
193
|
+
|
|
194
|
+
Installs the `guiho-as-xdocs` agent skill and maintains the `AGENTS.md` section.
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
xdocs agents install local # install the skill under the project (.agents/skills)
|
|
198
|
+
xdocs agents install global # install the skill under ~/.agents/skills
|
|
199
|
+
xdocs agents instructions # insert/refresh the xdocs section in AGENTS.md
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Accepts `--tool <agents|claude|all>`. See [Agent Skills](#agent-skills) for details.
|
|
203
|
+
|
|
192
204
|
#### Global Flags
|
|
193
205
|
|
|
194
206
|
All commands accept:
|
|
@@ -229,22 +241,34 @@ exclude = ["node_modules", ".git", "dist", "build", "library", "bin", "bundle"]
|
|
|
229
241
|
[project]
|
|
230
242
|
# Project name. Used in the root XDOCS.md and tree output.
|
|
231
243
|
name = "my-project"
|
|
244
|
+
|
|
245
|
+
[agents]
|
|
246
|
+
# Keep the xdocs section in AGENTS.md fresh on normal commands. Default: true
|
|
247
|
+
auto_agents_md = true
|
|
248
|
+
# Install the standard skill globally when missing. Default: true
|
|
249
|
+
auto_skill_install = true
|
|
250
|
+
# Default target for skill auto-install: "agents" (standard) or "claude". Default: "agents"
|
|
251
|
+
skill_tool = "agents"
|
|
232
252
|
```
|
|
233
253
|
|
|
234
|
-
### Agent Skills
|
|
254
|
+
### Agent Skills
|
|
255
|
+
|
|
256
|
+
xdocs ships the `guiho-as-xdocs` agent skill that teaches AI tools how to work with xdocs -- when to create, update, or regenerate documentation, how to use the CLI, and how to respect the configured AI behavior mode. The skill is large and loaded on demand; a small section in `AGENTS.md` points the agent at it.
|
|
235
257
|
|
|
236
|
-
|
|
258
|
+
Installation is **standard-first**:
|
|
237
259
|
|
|
238
|
-
|
|
260
|
+
| Target | Location | When installed |
|
|
261
|
+
| ------------------------- | --------------------------------------------------- | --------------------------------------------------------------- |
|
|
262
|
+
| **agents** (standard) | `.agents/skills/guiho-as-xdocs/SKILL.md` | Always (default). Read by OpenCode, Codex, Jules, and any AGENTS.md tool. |
|
|
263
|
+
| **claude** (non-standard) | `.claude/skills/guiho-as-xdocs/SKILL.md` | When `--tool claude` is given, or a `.claude/` dir or `CLAUDE.md` is detected. |
|
|
239
264
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
| **Google Jules** | Instructions file in the tool's expected location |
|
|
265
|
+
```bash
|
|
266
|
+
xdocs agents install local # standard target, under the project
|
|
267
|
+
xdocs agents install global # standard target, under ~/.agents/skills
|
|
268
|
+
xdocs agents instructions # insert/refresh the AGENTS.md section
|
|
269
|
+
```
|
|
246
270
|
|
|
247
|
-
`xdocs init`
|
|
271
|
+
`xdocs init` runs this automatically for the standard target (`local` scope). `local` scope installs under the project; `global` installs under your home directory. The default is always the standard target -- non-standard files are written only when you ask (`--tool`) or when they are already present.
|
|
248
272
|
|
|
249
273
|
---
|
|
250
274
|
|
package/jsr.json
CHANGED