@brainfish-ai/devdoc 0.1.36 → 0.1.38

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.
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Rules for bootstrapping documentation with context memory and API spec detection
2
+ description: Rules for bootstrapping documentation with user-driven preferences and code memory mapping
3
3
  globs: ["**/README.md", "**/package.json", "**/src/**", "**/lib/**"]
4
4
  ---
5
5
 
@@ -7,131 +7,224 @@ globs: ["**/README.md", "**/package.json", "**/src/**", "**/lib/**"]
7
7
 
8
8
  When asked to bootstrap or generate initial documentation:
9
9
 
10
- ## Step 1: Check Context Memory
10
+ ## Step 1: Check Existing Context & Codebase
11
11
 
12
- **First, check if `.devdoc/context.json` exists:**
12
+ **Detect if codebase exists:**
13
+ - Look for: package.json, src/, lib/, app/, *.py, *.ts, *.go
13
14
 
14
- - **If populated:** Read and use existing context. Tell user: "Using existing product context."
15
- - **If empty/missing:** Run Discovery Flow below.
15
+ **If NO codebase:**
16
+ - "No codebase detected. Creating docs-only project."
17
+ - Skip code-graph, go to Step 2 → Step 6
16
18
 
17
- ## Step 2: Discovery Flow
19
+ **If codebase exists, check git:**
20
+ ```bash
21
+ git rev-parse HEAD # Current commit
22
+ ```
18
23
 
19
- ### 2a. Locate Project
24
+ **If `.devdoc/code-graph.json` exists:**
25
+ 1. Compare `git.commitHash` vs current HEAD
26
+ 2. **Same commit** → "Code graph up to date" → Skip to Step 6
27
+ 3. **Different commit** → "{N} files changed"
28
+ - Ask: "1. Full rescan 2. Incremental 3. Skip"
20
29
 
21
- - If `docs.json` exists you're in docs folder, source is in `../`
22
- - If `package.json` + `src/` exist you're at repo root
23
- - Otherwise, ask user for source code path
30
+ **If `.devdoc/context.json` exists:** Read and use it.
31
+ **If missing:** Proceed to ask user preferences first.
24
32
 
25
- ### 2b. Scan for API Specs
33
+ ## Step 2: Ask User Preferences First
26
34
 
27
- **Search for OpenAPI:**
28
- - `openapi.json`, `openapi.yaml`, `swagger.json`, `swagger.yaml`
29
- - `**/openapi.*`, `**/swagger.*`
35
+ **Don't auto-scan yet. Ask what they want:**
30
36
 
31
- **Search for GraphQL:**
32
- - `schema.graphql`, `schema.gql`
33
- - `**/*.graphql`
37
+ ### Question 1: Documentation Type
38
+ ```
39
+ What type of documentation are you creating?
34
40
 
35
- **Store paths for import prompt.**
41
+ 1. API Docs - REST/GraphQL API reference for developers
42
+ 2. Product Docs - Feature guides and tutorials for end users
43
+ 3. Internal Docs - Team setup, architecture, contribution guides
44
+ ```
36
45
 
37
- ### 2c. Auto-Discover
46
+ ### Question 2: API Type (if API Docs)
47
+ ```
48
+ What type of API do you have?
38
49
 
39
- Scan and extract:
40
- - **README.md:** Product name, description, features
41
- - **package.json:** Language, framework, dependencies
42
- - **OpenAPI:** API style, base URL, auth, endpoint count
43
- - **GraphQL:** Types, queries, mutations count
44
- - **Source structure:** Key directories, conventions
50
+ 1. OpenAPI/REST - I have an OpenAPI/Swagger spec
51
+ 2. GraphQL - I have a GraphQL schema
52
+ 3. Both - REST and GraphQL APIs
53
+ 4. Manual - I'll document manually (no spec)
54
+ ```
45
55
 
46
- ### 2d. Ask Key Questions
56
+ ### Question 3: Target Audience
57
+ ```
58
+ Who is your primary audience?
59
+ ```
47
60
 
48
- 1. **Documentation Type:**
49
- "What type of documentation?
50
- 1. **internal** - Team setup, architecture
51
- 2. **api** - API reference, SDKs for developers
52
- 3. **product** - Feature guides for end users"
61
+ ### Question 4: Code Examples Language
62
+ ```
63
+ What language for code examples? (TypeScript, Python, curl, etc.)
64
+ ```
53
65
 
54
- 2. **Import API Spec (if found):**
66
+ ## Step 3: Import API Spec (if applicable)
55
67
 
56
- **For OpenAPI:**
57
- "Found OpenAPI spec at `{path}` with {n} endpoints.
58
- 1. **Import** - Copy to api-reference/openapi.json
59
- 2. **Reference** - Point to existing location
60
- 3. **Skip** - Manual docs only"
68
+ **Ask user for spec path or search:**
61
69
 
62
- **For GraphQL:**
63
- "Found GraphQL schema at `{path}` with {n} types.
64
- 1. **Import** - Copy to api-reference/schema.graphql
65
- 2. **Reference** - Point to existing location
66
- 3. **Skip** - Manual docs only"
70
+ OpenAPI: `openapi.json`, `swagger.json`, `**/openapi.*`
71
+ GraphQL: `schema.graphql`, `schema.gql`, `**/*.graphql`
67
72
 
68
- **For Both:**
69
- "Found OpenAPI and GraphQL specs.
70
- 1. **OpenAPI** - REST API playground
71
- 2. **GraphQL** - GraphQL playground
72
- 3. **Both** - Separate tabs for each
73
- 4. **Skip** - Manual only"
73
+ 1. Copy spec to `api-reference/`
74
+ 2. Validate format
75
+ 3. Extract metadata (endpoints, auth, types)
74
76
 
75
- 3. **Target Audience:**
76
- "Who is your primary audience?"
77
+ ## Step 4: Build Code Graph (Optional)
77
78
 
78
- 4. **Terminology (optional):**
79
- "Any terms to use/avoid? Brand names? (Enter to skip)"
79
+ **Skip if:** No codebase, user chose skip, or docs-only project.
80
80
 
81
- 5. **Code Examples:**
82
- "Primary language for code examples?"
81
+ **If scanning, create `.devdoc/code-graph.json`:**
83
82
 
84
- ### 2e. Create Context Memory
83
+ ```
84
+ Scan and map:
85
+ ├── README.md → name, description, features
86
+ ├── package.json → language, framework, deps
87
+ ├── src/
88
+ │ ├── api/ → routes, controllers
89
+ │ ├── models/ → data schemas
90
+ │ ├── services/ → business logic
91
+ │ └── types/ → type definitions
92
+ ├── tests/ → code examples
93
+ └── examples/ → usage examples
94
+ ```
85
95
 
86
- Create `.devdoc/context.json`:
96
+ **For each module, extract:**
97
+ - All public functions with FULL signatures
98
+ - Class definitions with methods
99
+ - Type/interface definitions
100
+ - Exported constants
101
+ - Error types and codes
87
102
 
103
+ **Save to `.devdoc/code-graph.json`:**
88
104
  ```json
89
105
  {
90
- "$schema": "https://devdoc.sh/schemas/context.json",
106
+ "$schema": "https://devdoc.sh/schemas/code-graph.json",
91
107
  "version": "1.0",
92
- "lastUpdated": "[timestamp]",
93
- "product": {
94
- "name": "[discovered]",
95
- "description": "[discovered]",
96
- "type": "[api/sdk/platform/cli]",
97
- "targetAudience": "[from question]"
98
- },
99
- "api": {
100
- "style": "[REST/GraphQL if detected]",
101
- "specPath": "[imported spec path]",
102
- "baseUrl": "[from spec]",
103
- "authentication": { "type": "[from spec]" }
108
+ "generatedAt": "[timestamp]",
109
+ "git": {
110
+ "commitHash": "[full 40-char hash]",
111
+ "commitShort": "[7-char hash]",
112
+ "branch": "[branch name]",
113
+ "isDirty": false
104
114
  },
105
- "codebase": {
106
- "language": "[detected]",
107
- "framework": "[detected]",
108
- "sourceLocation": "../"
115
+ "project": {
116
+ "name": "[name]",
117
+ "language": "[lang]",
118
+ "framework": "[framework]",
119
+ "rootDir": "src/"
109
120
  },
110
- "documentation": {
111
- "voice": "[based on docType]",
112
- "codeExamples": { "primaryLanguage": "[from question]" },
113
- "templates": {
114
- "guide": ".devdoc/templates/guide.md",
115
- "apiReference": ".devdoc/templates/api-reference.md"
121
+ "modules": [
122
+ {
123
+ "name": "auth",
124
+ "path": "src/auth/",
125
+ "description": "Authentication",
126
+ "exports": [
127
+ {
128
+ "name": "login",
129
+ "type": "function",
130
+ "signature": "login(email: string, password: string): Promise<AuthToken>",
131
+ "params": [
132
+ { "name": "email", "type": "string" },
133
+ { "name": "password", "type": "string" }
134
+ ],
135
+ "returns": { "type": "Promise<AuthToken>" },
136
+ "async": true
137
+ }
138
+ ],
139
+ "docPriority": "high"
140
+ }
141
+ ],
142
+ "types": [
143
+ {
144
+ "name": "AuthToken",
145
+ "path": "src/types/auth.ts",
146
+ "kind": "interface",
147
+ "definition": "interface AuthToken { token: string; expiresAt: Date; }"
116
148
  }
149
+ ],
150
+ "examples": [
151
+ { "path": "examples/basic.ts", "description": "Basic usage", "tags": ["auth"] }
152
+ ],
153
+ "errors": [
154
+ { "name": "AuthError", "code": "AUTH_FAILED", "message": "Invalid credentials" }
155
+ ]
156
+ }
157
+ ```
158
+
159
+ ## Step 5: Save Context
160
+
161
+ Create `.devdoc/context.json`:
162
+ ```json
163
+ {
164
+ "preferences": {
165
+ "docType": "[api/product/internal]",
166
+ "apiType": "[openapi/graphql/both/manual]",
167
+ "audience": "[target audience]",
168
+ "codeLanguage": "[language]"
169
+ },
170
+ "product": {
171
+ "name": "[name]",
172
+ "description": "[desc]"
173
+ },
174
+ "api": {
175
+ "style": "[REST/GraphQL]",
176
+ "specPath": "[path if imported]"
117
177
  }
118
178
  }
119
179
  ```
120
180
 
121
- ## Step 3: Import API Spec
181
+ ## Step 6: Plan Structure Based on Preferences
122
182
 
123
- **For Import option:**
124
- 1. Copy spec to `api-reference/`
125
- 2. Validate spec format
126
- 3. Update context.json with spec info
183
+ ### API Docs
184
+ ```
185
+ docs/
186
+ ├── index.mdx
187
+ ├── quickstart.mdx
188
+ ├── authentication.mdx
189
+ ├── guides/
190
+ ├── api-reference/
191
+ │ ├── openapi.json (or schema.graphql)
192
+ │ └── introduction.mdx
193
+ └── sdks/
194
+ ```
127
195
 
128
- **For Reference option:**
129
- 1. Note relative path for docs.json
130
- 2. Update context.json with spec info
196
+ ### Product Docs
197
+ ```
198
+ docs/
199
+ ├── index.mdx
200
+ ├── getting-started/
201
+ ├── features/
202
+ ├── tutorials/
203
+ └── troubleshooting/
204
+ ```
205
+
206
+ ### Internal Docs
207
+ ```
208
+ docs/
209
+ ├── index.mdx
210
+ ├── getting-started/
211
+ ├── architecture/
212
+ ├── development/
213
+ └── contributing.mdx
214
+ ```
215
+
216
+ ## Step 7: Generate Documentation
217
+
218
+ **Use code graph for accuracy:**
131
219
 
132
- ## Step 4: Update docs.json
220
+ 1. Read `.devdoc/code-graph.json` before each page
221
+ 2. Use EXACT function signatures from exports
222
+ 3. Reference types from types array
223
+ 4. Extract examples from examples array
224
+ 5. Document errors from errors array
225
+ 6. Add TODO markers for uncertain sections
133
226
 
134
- Add `docType` and API reference:
227
+ ## Step 8: Update docs.json
135
228
 
136
229
  **OpenAPI:**
137
230
  ```json
@@ -149,84 +242,49 @@ Add `docType` and API reference:
149
242
  **GraphQL:**
150
243
  ```json
151
244
  {
152
- "docType": "api",
153
245
  "navigation": {
154
246
  "tabs": [
155
247
  { "tab": "Guides", "groups": [...] },
156
- { "tab": "GraphQL API", "type": "graphql", "schema": "api-reference/schema.graphql", "endpoint": "https://..." }
248
+ { "tab": "GraphQL API", "type": "graphql", "schema": "api-reference/schema.graphql" }
157
249
  ]
158
250
  }
159
251
  }
160
252
  ```
161
253
 
162
- ## Step 5: Generate Documentation
163
-
164
- **Before generating, always:**
165
- 1. Read `.devdoc/context.json`
166
- 2. Read appropriate template from `.devdoc/templates/`
167
- 3. Apply terminology from context
168
- 4. Use correct product name
169
- 5. Match voice to docType
170
- 6. Reference imported API spec
254
+ ## Step 9: Summary
171
255
 
172
- ### docType: "internal"
173
256
  ```
174
- docs/
175
- ├── .devdoc/context.json
176
- ├── docs.json (docType: "internal")
177
- ├── index.mdx
178
- ├── getting-started/
179
- ├── architecture/
180
- ├── development/
181
- └── contributing.mdx
182
- ```
183
- **Voice:** Technical, direct
257
+ ✅ Documentation Generated!
184
258
 
185
- ### docType: "api"
186
- ```
187
- docs/
188
- ├── .devdoc/context.json
189
- ├── docs.json (docType: "api")
190
- ├── index.mdx
191
- ├── quickstart.mdx
192
- ├── authentication.mdx
193
- ├── guides/
194
- ├── api-reference/
195
- │ ├── openapi.json # If imported
196
- │ └── schema.graphql # If imported
197
- ├── sdks/
198
- └── changelog.mdx
199
- ```
200
- **Voice:** Professional, code-focused
259
+ Preferences:
260
+ - Type: API Documentation
261
+ - API: OpenAPI/REST
262
+ - Audience: [audience]
263
+ - Code: [language]
201
264
 
202
- ### docType: "product"
203
- ```
204
- docs/
205
- ├── .devdoc/context.json
206
- ├── docs.json (docType: "product")
207
- ├── index.mdx
208
- ├── getting-started/
209
- ├── features/
210
- ├── tutorials/
211
- ├── troubleshooting/
212
- └── release-notes.mdx
265
+ Files created:
266
+ - .devdoc/context.json (preferences)
267
+ - .devdoc/code-graph.json (code analysis)
268
+ - docs.json
269
+ - [list of mdx files]
270
+
271
+ Next: Run `devdoc dev` to preview, then "whisk theme" for branding.
213
272
  ```
214
- **Voice:** Friendly, non-technical
215
273
 
216
- ## Content Guidelines
274
+ ## Key Principles
217
275
 
218
- | docType | Focus | Tone | Code |
219
- |---------|-------|------|------|
220
- | internal | Setup, architecture | Technical | Heavy |
221
- | api | Endpoints, auth, examples | Professional | Heavy |
222
- | product | Features, workflows | Friendly | Minimal |
276
+ | Principle | Description |
277
+ |-----------|-------------|
278
+ | Ask first | Get user preferences before scanning |
279
+ | Build code graph | Scan entire codebase with full signatures |
280
+ | Store the graph | Save to code-graph.json for updates |
281
+ | Real code only | Use exact signatures, never fabricate |
282
+ | Mark unknowns | Add TODO for sections needing review |
223
283
 
224
- ## Quality Guidelines
284
+ ## Code Graph Benefits
225
285
 
226
- - Use terminology from context.json consistently
227
- - Read templates before generating each page type
228
- - Extract real examples, don't fabricate
229
- - Add TODO for sections needing review
230
- - **Import existing API specs** instead of manual docs
231
- - **Validate specs** before importing
232
- - Update context.json if you learn new info
286
+ - **Accurate docs** - Exact function signatures
287
+ - **Complete coverage** - All exports documented
288
+ - **Easy updates** - Re-scan refreshes the graph
289
+ - **No hallucination** - Only document real code
290
+ - **Type safety** - Reference actual type definitions
@@ -7,9 +7,16 @@ globs: ["**/*.mdx", "**/docs.json"]
7
7
 
8
8
  When asked to create documentation:
9
9
 
10
- ## Step 0: Read Context
10
+ ## Step 0: Read Context & Code Graph
11
11
 
12
- Read `.devdoc/context.json` if exists for terminology, templates, and code language.
12
+ Read `.devdoc/context.json` for terminology, templates, and code language.
13
+
14
+ Read `.devdoc/code-graph.json` for:
15
+ - `modules[].exports` → Function signatures, params, returns
16
+ - `types[]` → Type definitions
17
+ - `examples[]` → Code examples to include
18
+ - `api.endpoints[]` → API routes
19
+ - `errors[]` → Error types to document
13
20
 
14
21
  ## Step 1: Understand What to Create
15
22
 
@@ -49,9 +56,14 @@ Read from `.devdoc/templates/`:
49
56
 
50
57
  1. Follow template structure
51
58
  2. Apply context (terminology, voice)
52
- 3. Include mermaid diagrams for flows
53
- 4. Add real code examples
54
- 5. Use MDX components (Steps, Cards, etc.)
59
+ 3. **Use code-graph.json for accuracy:**
60
+ - Get exact signatures from `modules[].exports`
61
+ - Get type definitions from `types[]`
62
+ - Find examples from `examples[]`
63
+ - Document errors from `errors[]`
64
+ 4. Include mermaid diagrams for flows
65
+ 5. Add real code examples from code-graph
66
+ 6. Use MDX components (Steps, Cards, etc.)
55
67
 
56
68
  ## Step 5: Save and Update Navigation
57
69
 
@@ -7,10 +7,16 @@ globs: ["**/*.mdx", "**/docs.json"]
7
7
 
8
8
  When asked to update documentation:
9
9
 
10
- ## Step 0: Read Context
10
+ ## Step 0: Read Context & Code Graph
11
11
 
12
12
  Read `.devdoc/context.json` for terminology and conventions.
13
13
 
14
+ Read `.devdoc/code-graph.json` to compare:
15
+ - Current exports vs documented functions
16
+ - Current types vs documented types
17
+ - New endpoints not in docs
18
+ - Removed features still documented
19
+
14
20
  ## Step 1: Understand What to Update
15
21
 
16
22
  Ask: "What would you like to update?
@@ -27,22 +33,33 @@ Ask: "What would you like to update?
27
33
  - Ask what changes needed
28
34
 
29
35
  **For Codebase Sync:**
30
- Compare docs vs code:
31
- - Function signatures changed?
32
- - New exports undocumented?
33
- - Removed features still documented?
34
- - Versions outdated?
36
+
37
+ 1. Re-scan codebase to update code-graph.json
38
+ 2. Compare docs vs code-graph.json:
39
+ - Signatures changed? (exports array)
40
+ - New exports undocumented?
41
+ - Removed exports still documented?
42
+ - Types changed?
43
+ - New endpoints? (api.endpoints)
35
44
 
36
45
  Generate sync report:
37
46
  ```
38
- ## Sync Report
47
+ ## Sync Report (from code-graph.json)
48
+
49
+ ### Signatures Changed
50
+ - `api/users.mdx`: createUser signature changed
51
+ - Documented: createUser(name, email)
52
+ - Code-graph: createUser(options: CreateUserInput)
53
+
54
+ ### New Exports (not documented)
55
+ - auth.refreshToken()
56
+ - users.deleteUser()
39
57
 
40
- ### Outdated
41
- - `api/users.mdx`: signature changed
42
- - `quickstart.mdx`: version outdated
58
+ ### Removed (documented but not in code-graph)
59
+ - legacyAuth() - removed
43
60
 
44
- ### Missing
45
- - New endpoint not documented
61
+ ### Types Changed
62
+ - User interface: added `role` property
46
63
 
47
64
  ### Up to Date ✓
48
65
  - `guides/auth.mdx`