@guiho/xdocs 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +347 -0
- package/jsr.json +1 -1
- package/library/guiho-xdocs-bin.js +0 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# XDocs
|
|
2
|
+
|
|
3
|
+
**Structured documentation system for codebases. Helps AI make sense of projects.**
|
|
4
|
+
|
|
5
|
+
xdocs is a CLI and TypeScript library that places structured documentation files throughout your project so that AI agents (and humans) can navigate, understand, and work within a codebase without reading every file. Each xdocs file describes the directory it lives in -- its purpose, its files, and how it fits into the project hierarchy.
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
codebase -> xdocs files -> AI understands the project
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
xdocs runs on **Bun** and **Node >= 20**. It ships as a compiled binary, a thin JS loader for `npx`/`bunx`, and a fully-typed TypeScript library.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -D @guiho/xdocs
|
|
21
|
+
# or
|
|
22
|
+
bun add -d @guiho/xdocs
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Initializing
|
|
26
|
+
|
|
27
|
+
Set up xdocs in your project:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
xdocs init
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This creates:
|
|
34
|
+
- `XDOCS.md` -- the root documentation file for the project
|
|
35
|
+
- `xdocs.config.toml` -- configuration with sensible defaults
|
|
36
|
+
- Updates `AGENTS.md` with instructions for AI agents
|
|
37
|
+
- Installs agent skill files for your AI tool
|
|
38
|
+
|
|
39
|
+
### Typical Workflow
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Scan the project for existing xdocs files
|
|
43
|
+
xdocs scan
|
|
44
|
+
|
|
45
|
+
# Generate documentation for a specific module
|
|
46
|
+
xdocs generate ./src/auth
|
|
47
|
+
|
|
48
|
+
# View the project hierarchy
|
|
49
|
+
xdocs tree
|
|
50
|
+
|
|
51
|
+
# Get a ready-made prompt for AI to write documentation
|
|
52
|
+
xdocs prompt --name=write
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
### The Problem
|
|
60
|
+
|
|
61
|
+
When AI works on a codebase, most of the structural knowledge lives in the head of the person who built it. The AI has no understanding of _why_ files exist, _what purpose_ a directory serves, or _how_ modules relate to each other. To figure this out, it must read every file and piece things together -- slow, expensive, and error-prone.
|
|
62
|
+
|
|
63
|
+
### The Solution
|
|
64
|
+
|
|
65
|
+
xdocs solves this by placing documentation files throughout the project. Each xdocs file describes the directory it lives in, acting as a self-contained map of that module. Instead of opening every file to understand a directory, the AI reads its xdocs file.
|
|
66
|
+
|
|
67
|
+
### File Format
|
|
68
|
+
|
|
69
|
+
xdocs files are Markdown with YAML frontmatter. A file is recognized as an xdocs file if it ends with one of the configured extensions (default: `.docs.md`, `.xdocs.md`).
|
|
70
|
+
|
|
71
|
+
```markdown
|
|
72
|
+
---
|
|
73
|
+
subject: authentication
|
|
74
|
+
description: Handles user login, registration, password reset, and session management.
|
|
75
|
+
parent: domain-core
|
|
76
|
+
children:
|
|
77
|
+
- login
|
|
78
|
+
- registration
|
|
79
|
+
- password-reset
|
|
80
|
+
files:
|
|
81
|
+
authenticate.ts: Validates credentials and returns a session token.
|
|
82
|
+
register.ts: Creates a new user account with email verification.
|
|
83
|
+
session.ts: Manages session creation, validation, and expiration.
|
|
84
|
+
tags: []
|
|
85
|
+
flags: []
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Overview
|
|
89
|
+
|
|
90
|
+
The authentication module handles all identity verification flows...
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Metadata Fields
|
|
94
|
+
|
|
95
|
+
| Field | Type | Required | Description |
|
|
96
|
+
| ------------- | --------------------- | -------- | ------------------------------------------------------------- |
|
|
97
|
+
| `subject` | `string` | Yes | The name of this module/subject. |
|
|
98
|
+
| `description` | `string` | Yes | A short description the AI reads first to understand the module. |
|
|
99
|
+
| `parent` | `string \| null` | Yes | The parent subject in the hierarchy. `null` for the root. |
|
|
100
|
+
| `children` | `string[]` | Yes | Child subjects (submodules) contained within this module. |
|
|
101
|
+
| `files` | `map<string, string>` | Yes | Files in this directory. Key = filename, value = description. |
|
|
102
|
+
| `tags` | `string[]` | Yes | Tags for categorization and search. |
|
|
103
|
+
| `flags` | `string[]` | Yes | Flags for marking attributes or states. |
|
|
104
|
+
| `status` | `string` | No | Module status (e.g., `active`, `deprecated`, `experimental`). |
|
|
105
|
+
|
|
106
|
+
### The Tree
|
|
107
|
+
|
|
108
|
+
xdocs files form a hierarchy through their `subject`, `parent`, and `children` fields. The tree represents containment -- not dependencies -- and is computed by scanning all xdocs files.
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
project (root)
|
|
112
|
+
domain-core
|
|
113
|
+
authentication
|
|
114
|
+
login
|
|
115
|
+
registration
|
|
116
|
+
password-reset
|
|
117
|
+
user
|
|
118
|
+
profile
|
|
119
|
+
preferences
|
|
120
|
+
domain-supply
|
|
121
|
+
supply
|
|
122
|
+
product
|
|
123
|
+
catalog
|
|
124
|
+
inventory
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The CLI validates tree integrity: no orphan subjects, no missing parents, no cycles.
|
|
128
|
+
|
|
129
|
+
### CLI Commands
|
|
130
|
+
|
|
131
|
+
#### `xdocs init`
|
|
132
|
+
|
|
133
|
+
Initializes xdocs in a project. Creates the root `XDOCS.md`, the `xdocs.config.toml` configuration, updates `AGENTS.md`, and installs agent skills.
|
|
134
|
+
|
|
135
|
+
#### `xdocs scan`
|
|
136
|
+
|
|
137
|
+
Scans the project for xdocs files. Reports which directories have coverage and which are missing documentation.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
xdocs scan
|
|
141
|
+
xdocs scan --format json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### `xdocs generate [path]`
|
|
145
|
+
|
|
146
|
+
Generates documentation for a directory or the entire project.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Generate docs for a specific module
|
|
150
|
+
xdocs generate ./src/auth
|
|
151
|
+
|
|
152
|
+
# Generate docs for the entire project
|
|
153
|
+
xdocs generate
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### `xdocs prompt --name=<name>`
|
|
157
|
+
|
|
158
|
+
Outputs a ready-made prompt for AI agents. Each prompt is a self-contained instruction for a specific xdocs task. Prompts are selected by the `--name` flag, not by subcommand.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
xdocs prompt --name=write # How to write xdocs documentation
|
|
162
|
+
xdocs prompt --name=update # How to update existing xdocs files
|
|
163
|
+
xdocs prompt --name=agents # How to update AGENTS.md
|
|
164
|
+
xdocs prompt --name=generate # How to generate comprehensive docs
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### `xdocs merge [path]`
|
|
168
|
+
|
|
169
|
+
Merges xdocs files from a directory into a single consolidated document.
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
xdocs merge ./src/domain
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `xdocs tree`
|
|
176
|
+
|
|
177
|
+
Displays the project hierarchy tree assembled from xdocs metadata.
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
xdocs tree
|
|
181
|
+
xdocs tree --format markdown --output tree.md
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### `xdocs list [path]`
|
|
185
|
+
|
|
186
|
+
Lists files in a scope with descriptions pulled from xdocs metadata.
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
xdocs list ./src/auth
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### Global Flags
|
|
193
|
+
|
|
194
|
+
All commands accept:
|
|
195
|
+
|
|
196
|
+
| Flag | Description |
|
|
197
|
+
| ----------------- | -------------------------------------------- |
|
|
198
|
+
| `-h`, `--help` | Show help for a command |
|
|
199
|
+
| `-v`, `--version` | Show the xdocs version |
|
|
200
|
+
| `--cwd <path>` | Run as if started in the given directory |
|
|
201
|
+
| `--config <path>` | Path to `xdocs.config.toml` |
|
|
202
|
+
| `--format <fmt>` | Output format: `text`, `json`, or `markdown` |
|
|
203
|
+
| `--verbose` | Show detailed output |
|
|
204
|
+
|
|
205
|
+
### Configuration (`xdocs.config.toml`)
|
|
206
|
+
|
|
207
|
+
xdocs looks for configuration at `./xdocs.config.toml`, `./config/xdocs.config.toml`, or the path given by `--config`.
|
|
208
|
+
|
|
209
|
+
```toml
|
|
210
|
+
schema = 1
|
|
211
|
+
|
|
212
|
+
[extensions]
|
|
213
|
+
# File extensions recognized as xdocs files.
|
|
214
|
+
# Default: [".docs.md", ".xdocs.md"]
|
|
215
|
+
supported = [".docs.md", ".xdocs.md"]
|
|
216
|
+
|
|
217
|
+
[ai]
|
|
218
|
+
# How the AI handles documentation updates.
|
|
219
|
+
# "prompt" = AI announces updates needed, waits for user to confirm.
|
|
220
|
+
# "auto" = AI updates documentation automatically on any change.
|
|
221
|
+
# Default: "prompt"
|
|
222
|
+
mode = "prompt"
|
|
223
|
+
|
|
224
|
+
[scan]
|
|
225
|
+
# Directories to exclude from scanning.
|
|
226
|
+
# Default: ["node_modules", ".git", "dist", "build", "library", "bin", "bundle"]
|
|
227
|
+
exclude = ["node_modules", ".git", "dist", "build", "library", "bin", "bundle"]
|
|
228
|
+
|
|
229
|
+
[project]
|
|
230
|
+
# Project name. Used in the root XDOCS.md and tree output.
|
|
231
|
+
name = "my-project"
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Agent Skills and Plugins
|
|
235
|
+
|
|
236
|
+
xdocs ships agent skill files that teach 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.
|
|
237
|
+
|
|
238
|
+
Supported tools:
|
|
239
|
+
|
|
240
|
+
| Tool | Plugin Format |
|
|
241
|
+
| ---------------- | ------------------------------------------------- |
|
|
242
|
+
| **OpenCode** | `SKILL.md` in the skills directory |
|
|
243
|
+
| **Claude Code** | `CLAUDE.md` in the project root or `.claude/` |
|
|
244
|
+
| **OpenAI Codex** | Instructions file in the tool's expected location |
|
|
245
|
+
| **Google Jules** | Instructions file in the tool's expected location |
|
|
246
|
+
|
|
247
|
+
`xdocs init` generates the correct file for your chosen tool. Multiple tools can be supported simultaneously.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## API Reference
|
|
252
|
+
|
|
253
|
+
xdocs exposes a fully-typed TypeScript API for programmatic use.
|
|
254
|
+
|
|
255
|
+
### Configuration
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
import { loadConfig, loadConfigOrDefaults, defaultConfig } from '@guiho/xdocs'
|
|
259
|
+
|
|
260
|
+
// Load config from xdocs.config.toml (throws if not found)
|
|
261
|
+
const config = await loadConfig({ cwd: process.cwd(), format: 'text', verbose: false })
|
|
262
|
+
|
|
263
|
+
// Load config or fall back to defaults
|
|
264
|
+
const configOrDefaults = await loadConfigOrDefaults({ cwd: process.cwd(), format: 'text', verbose: false })
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Discovery and Scanning
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import { scanProject, scanDirectory, isXDocsFile } from '@guiho/xdocs'
|
|
271
|
+
|
|
272
|
+
// Scan the entire project
|
|
273
|
+
const result = await scanProject(config)
|
|
274
|
+
console.log(result.totalFiles) // Total files found
|
|
275
|
+
console.log(result.xdocsFiles) // Array of XDocsFile objects
|
|
276
|
+
console.log(result.uncoveredPaths) // Directories without xdocs coverage
|
|
277
|
+
|
|
278
|
+
// Check if a file is an xdocs file
|
|
279
|
+
isXDocsFile('auth.xdocs.md', ['.docs.md', '.xdocs.md']) // true
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Metadata Parsing
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
import { parseXDocsFile, extractFrontmatter, validateMetadata } from '@guiho/xdocs'
|
|
286
|
+
|
|
287
|
+
// Parse an xdocs file from disk
|
|
288
|
+
const file = await parseXDocsFile('/path/to/auth.xdocs.md', process.cwd())
|
|
289
|
+
console.log(file.metadata?.subject) // "authentication"
|
|
290
|
+
console.log(file.metadata?.description) // "Handles user login..."
|
|
291
|
+
console.log(file.valid) // true if metadata is complete
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Tree Operations
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { buildTree, renderTree, renderTreeMarkdown, validateTree } from '@guiho/xdocs'
|
|
298
|
+
|
|
299
|
+
// Build the hierarchy tree from scanned files
|
|
300
|
+
const tree = buildTree(result.xdocsFiles)
|
|
301
|
+
|
|
302
|
+
// Render as indented text
|
|
303
|
+
console.log(renderTree(tree))
|
|
304
|
+
|
|
305
|
+
// Render as Markdown
|
|
306
|
+
console.log(renderTreeMarkdown(tree))
|
|
307
|
+
|
|
308
|
+
// Validate tree integrity
|
|
309
|
+
const validation = validateTree(result.xdocsFiles)
|
|
310
|
+
console.log(validation.valid) // true if no orphans or cycles
|
|
311
|
+
console.log(validation.errors) // Array of error messages
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Prompts
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
import { getPrompt, getPromptNames } from '@guiho/xdocs'
|
|
318
|
+
|
|
319
|
+
// List all available prompt names
|
|
320
|
+
console.log(getPromptNames()) // ["write", "update", "agents", "generate"]
|
|
321
|
+
|
|
322
|
+
// Get a specific prompt
|
|
323
|
+
const prompt = getPrompt('write')
|
|
324
|
+
console.log(prompt?.description)
|
|
325
|
+
console.log(prompt?.body)
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## Development
|
|
331
|
+
|
|
332
|
+
Development requires Bun. Run from the `xdocs/` directory:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
cd xdocs
|
|
336
|
+
bun install
|
|
337
|
+
bun run typecheck
|
|
338
|
+
bun test
|
|
339
|
+
bun run build
|
|
340
|
+
bun run binary
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
## License
|
|
346
|
+
|
|
347
|
+
MIT -- see [LICENSE.md](xdocs/LICENSE.md).
|
package/jsr.json
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guiho/xdocs",
|
|
3
3
|
"description": "Structured documentation system for codebases. Helps AI make sense of projects.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./library/guiho-xdocs.js",
|
|
7
7
|
"types": "./library/guiho-xdocs.d.ts",
|