skrypt-ai 0.3.4 → 0.4.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/README.md +1 -1
- package/dist/auth/index.d.ts +0 -1
- package/dist/auth/index.js +3 -5
- package/dist/autofix/index.js +15 -3
- package/dist/cli.js +19 -4
- package/dist/commands/check-links.js +164 -174
- package/dist/commands/deploy.js +5 -2
- package/dist/commands/generate.js +206 -199
- package/dist/commands/i18n.js +3 -20
- package/dist/commands/init.js +47 -40
- package/dist/commands/lint.js +3 -20
- package/dist/commands/mcp.js +125 -122
- package/dist/commands/monitor.js +125 -108
- package/dist/commands/review-pr.js +1 -1
- package/dist/commands/sdk.js +1 -1
- package/dist/config/loader.js +21 -2
- package/dist/generator/organizer.d.ts +3 -0
- package/dist/generator/organizer.js +4 -9
- package/dist/generator/writer.js +2 -10
- package/dist/github/pr-comments.js +21 -8
- package/dist/plugins/index.js +1 -0
- package/dist/scanner/index.js +8 -2
- package/dist/template/docs.json +2 -1
- package/dist/template/next.config.mjs +2 -1
- package/dist/template/package.json +17 -15
- package/dist/template/public/favicon.svg +4 -0
- package/dist/template/public/search-index.json +1 -1
- package/dist/template/scripts/build-search-index.mjs +120 -25
- package/dist/template/src/app/api/chat/route.ts +11 -3
- package/dist/template/src/app/docs/README.md +28 -0
- package/dist/template/src/app/docs/[...slug]/page.tsx +139 -16
- package/dist/template/src/app/docs/auth/page.mdx +589 -0
- package/dist/template/src/app/docs/autofix/page.mdx +624 -0
- package/dist/template/src/app/docs/cli/page.mdx +217 -0
- package/dist/template/src/app/docs/config/page.mdx +428 -0
- package/dist/template/src/app/docs/configuration/page.mdx +86 -0
- package/dist/template/src/app/docs/deployment/page.mdx +112 -0
- package/dist/template/src/app/docs/error.tsx +20 -0
- package/dist/template/src/app/docs/generator/generator.md +504 -0
- package/dist/template/src/app/docs/generator/organizer.md +779 -0
- package/dist/template/src/app/docs/generator/page.mdx +613 -0
- package/dist/template/src/app/docs/github/page.mdx +502 -0
- package/dist/template/src/app/docs/llm/anthropic-client.md +549 -0
- package/dist/template/src/app/docs/llm/index.md +471 -0
- package/dist/template/src/app/docs/llm/page.mdx +428 -0
- package/dist/template/src/app/docs/llms-full.md +256 -0
- package/dist/template/src/app/docs/llms.txt +2971 -0
- package/dist/template/src/app/docs/not-found.tsx +23 -0
- package/dist/template/src/app/docs/page.mdx +0 -3
- package/dist/template/src/app/docs/plugins/page.mdx +1793 -0
- package/dist/template/src/app/docs/pro/page.mdx +121 -0
- package/dist/template/src/app/docs/quickstart/page.mdx +93 -0
- package/dist/template/src/app/docs/scanner/content-type.md +599 -0
- package/dist/template/src/app/docs/scanner/index.md +212 -0
- package/dist/template/src/app/docs/scanner/page.mdx +307 -0
- package/dist/template/src/app/docs/scanner/python.md +469 -0
- package/dist/template/src/app/docs/scanner/python_parser.md +1056 -0
- package/dist/template/src/app/docs/scanner/rust.md +325 -0
- package/dist/template/src/app/docs/scanner/typescript.md +201 -0
- package/dist/template/src/app/error.tsx +3 -3
- package/dist/template/src/app/icon.tsx +29 -0
- package/dist/template/src/app/layout.tsx +42 -0
- package/dist/template/src/app/not-found.tsx +35 -0
- package/dist/template/src/app/page.tsx +62 -28
- package/dist/template/src/components/ai-chat.tsx +26 -21
- package/dist/template/src/components/breadcrumbs.tsx +46 -2
- package/dist/template/src/components/copy-button.tsx +17 -3
- package/dist/template/src/components/docs-layout.tsx +142 -8
- package/dist/template/src/components/feedback.tsx +4 -2
- package/dist/template/src/components/footer.tsx +42 -0
- package/dist/template/src/components/header.tsx +29 -5
- package/dist/template/src/components/mdx/accordion.tsx +7 -6
- package/dist/template/src/components/mdx/card.tsx +19 -7
- package/dist/template/src/components/mdx/code-block.tsx +17 -3
- package/dist/template/src/components/mdx/code-group.tsx +65 -18
- package/dist/template/src/components/mdx/code-playground.tsx +3 -0
- package/dist/template/src/components/mdx/go-playground.tsx +3 -0
- package/dist/template/src/components/mdx/highlighted-code.tsx +171 -76
- package/dist/template/src/components/mdx/python-playground.tsx +2 -0
- package/dist/template/src/components/mdx/tabs.tsx +74 -6
- package/dist/template/src/components/page-header.tsx +19 -0
- package/dist/template/src/components/scroll-to-top.tsx +33 -0
- package/dist/template/src/components/search-dialog.tsx +206 -52
- package/dist/template/src/components/sidebar.tsx +136 -77
- package/dist/template/src/components/table-of-contents.tsx +23 -7
- package/dist/template/src/lib/highlight.ts +90 -31
- package/dist/template/src/lib/search.ts +14 -4
- package/dist/template/src/lib/theme-utils.ts +140 -0
- package/dist/template/src/styles/globals.css +307 -166
- package/dist/template/src/types/remark-gfm.d.ts +2 -0
- package/dist/utils/files.d.ts +9 -0
- package/dist/utils/files.js +33 -0
- package/dist/utils/validation.d.ts +4 -0
- package/dist/utils/validation.js +38 -0
- package/package.json +1 -4
|
@@ -0,0 +1,2971 @@
|
|
|
1
|
+
# Skrypt
|
|
2
|
+
|
|
3
|
+
> API documentation for Skrypt
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This project contains 81 documented API elements across 14 modules.
|
|
8
|
+
|
|
9
|
+
## Quick Reference
|
|
10
|
+
|
|
11
|
+
### index
|
|
12
|
+
|
|
13
|
+
- `getAuthConfig`: function - Use this to retrieve the current authentication configuration from the local auth file
|
|
14
|
+
- `saveAuthConfig`: function - Use this to persist authentication credentials to a local config file, ensuring the config directory
|
|
15
|
+
- `clearAuth`: function - Use this to log a user out by wiping stored authentication credentials from the local config file
|
|
16
|
+
- `checkPlan`: function - Use this to verify an API key's validity and retrieve the associated subscription plan details befor
|
|
17
|
+
- `requirePro`: function - Use this to gate CLI commands behind a Pro subscription — it checks the user's auth config and print
|
|
18
|
+
- `isProCommand`: function - Use this to check whether a given CLI command requires a Pro subscription before executing it, enabl
|
|
19
|
+
- `autoFixExample`: function - Use this to automatically repair broken or invalid code examples by iteratively applying LLM-powered
|
|
20
|
+
- `autoFixBatch`: function - Use this to automatically fix multiple broken code examples in a single batch operation, getting bac
|
|
21
|
+
- `createTypeScriptValidator`: function - Use this to validate TypeScript code strings at runtime — perfect for checking LLM-generated code, u
|
|
22
|
+
- `createPythonValidator`: function - Use this to validate Python code syntax and catch errors before execution, without needing a Python
|
|
23
|
+
- `createLLMClient`: function - Use this to initialize a typed LLM client for a specific AI provider (OpenAI, Anthropic, etc.) with
|
|
24
|
+
- `generateDocumentation`: function - Use this to automatically generate documentation for a code element (function, class, method, etc.)
|
|
25
|
+
- `fixCodeSample`: function - Use this to automatically repair broken code samples by sending them to an LLM with the error contex
|
|
26
|
+
- `PluginManager`: class - Use this to load, register, and execute documentation plugins that transform or extend your build pi
|
|
27
|
+
- `constructor`: method - Use this to initialize a `PluginManager` that coordinates documentation plugins, wiring together you
|
|
28
|
+
- `loadPlugins`: method - Use this to initialize and load plugins into a `PluginManager` instance from a configuration file, e
|
|
29
|
+
- `register`: method - Use this to manually register a plugin with the `PluginManager`, adding it to the active plugin list
|
|
30
|
+
- `runHook`: method - Use this to execute a named hook across all registered plugins in sequence, passing data through eac
|
|
31
|
+
- `onInit`: method - Use this to trigger the initialization lifecycle hook across all registered plugins in a `PluginMana
|
|
32
|
+
- `onBeforeScan`: method - Use this to trigger all registered plugins' `onBeforeScan` lifecycle hook — ideal for running pre-sc
|
|
33
|
+
- `onAfterScan`: method - Use this to run all registered plugins' `onAfterScan` hooks against a list of scanned elements, allo
|
|
34
|
+
- `onBeforeGenerate`: method - Use this to run all registered plugins' `onBeforeGenerate` hooks against a collection of elements be
|
|
35
|
+
- `onAfterGenerate`: method - Use this to run all registered plugins' `onAfterGenerate` hooks against a set of generated documenta
|
|
36
|
+
- `onBeforeWrite`: method - Use this to run all registered plugins' `onBeforeWrite` hooks against your generated docs array, all
|
|
37
|
+
- `onAfterWrite`: method - Use this to trigger all registered plugin hooks after documentation has been written to disk — ideal
|
|
38
|
+
- `transformContent`: method - Use this to pipe file content through a chain of registered plugins, each of which can modify the co
|
|
39
|
+
- `definePlugin`: function - Use this to define a type-safe plugin configuration object for the Skrypt plugin system
|
|
40
|
+
- `scanDirectory`: function - Use this to recursively scan a directory (or single file) and extract all API elements — functions,
|
|
41
|
+
- `scanFile`: function - Use this to analyze a single source file and extract structured metadata — functions, classes, types
|
|
42
|
+
|
|
43
|
+
### loader
|
|
44
|
+
|
|
45
|
+
- `findConfigFile`: function - Use this to locate a Skrypt configuration file by searching a directory for any of the supported con
|
|
46
|
+
- `loadConfig`: function - Use this to load a configuration file for autodocs, either from a specific path or by auto-discoveri
|
|
47
|
+
- `validateConfig`: function - Use this to validate a configuration object before using it, catching all errors upfront instead of
|
|
48
|
+
- `checkApiKey`: function - Use this to verify whether a required API key environment variable is set for a given LLM provider b
|
|
49
|
+
|
|
50
|
+
### generator
|
|
51
|
+
|
|
52
|
+
- `generateForElement`: function - Use this to generate documentation for a single API element using an LLM client, without running any
|
|
53
|
+
- `generateForElements`: function - Use this to batch-generate documentation for multiple API elements in a single call, processing an e
|
|
54
|
+
- `formatAsMarkdown`: function - Use this to convert an array of generated documentation objects into a formatted Markdown string, re
|
|
55
|
+
|
|
56
|
+
### organizer
|
|
57
|
+
|
|
58
|
+
- `organizeByTopic`: function - Use this to group a flat list of generated documentation objects into organized topic clusters — ide
|
|
59
|
+
- `detectCrossReferences`: function - Use this to automatically discover relationships between documented elements — for example, when one
|
|
60
|
+
- `getCrossRefsForElement`: function - Use this to filter a list of cross-references down to only those originating from a specific element
|
|
61
|
+
- `buildNavigation`: function - Use this to convert a flat list of documentation topics into a hierarchical navigation structure sui
|
|
62
|
+
- `generateSidebarConfig`: function - Use this to convert an array of documentation topics into a sidebar navigation configuration compati
|
|
63
|
+
- `mergeTopicConfig`: function - Use this to safely merge a partial user-provided topic configuration with a set of defaults, ensurin
|
|
64
|
+
|
|
65
|
+
### writer
|
|
66
|
+
|
|
67
|
+
- `writeLlmsTxt`: function - Use this to generate an `llms.txt` file for your API documentation, making it discoverable and consu
|
|
68
|
+
- `writeDocsToDirectory`: function - Use this to persist generated documentation to disk, writing markdown files into an output directory
|
|
69
|
+
- `groupDocsByFile`: function - Use this to organize a flat list of generated documentation objects into groups by their source file
|
|
70
|
+
- `writeDocsByTopic`: function - Use this to write generated documentation files to disk, organized into topic-based subdirectories —
|
|
71
|
+
|
|
72
|
+
### pr-comments
|
|
73
|
+
|
|
74
|
+
- `postPRComment`: function - Use this to automatically post documentation issue summaries as review comments on GitHub Pull Reque
|
|
75
|
+
- `postInlineComments`: function - Use this to post inline review comments on specific lines of a pull request, flagging documentation
|
|
76
|
+
- `analyzePRForDocs`: function - Use this to scan a pull request for documentation issues — missing docstrings, undocumented paramete
|
|
77
|
+
|
|
78
|
+
### anthropic-client
|
|
79
|
+
|
|
80
|
+
- `AnthropicClient`: class - Use this to send completion requests to Anthropic's Claude models with automatic retry logic and a s
|
|
81
|
+
- `constructor`: method - Use this to create an Anthropic-backed LLM client for sending completion requests, with built-in ret
|
|
82
|
+
- `isConfigured`: method - Use this to verify that an `AnthropicClient` instance is ready to make API calls before attempting c
|
|
83
|
+
- `complete`: method - Use this to send a conversation to Anthropic's Claude models and receive a completion response, hand
|
|
84
|
+
|
|
85
|
+
### openai-client
|
|
86
|
+
|
|
87
|
+
- `OpenAICompatibleClient`: class - Use this to connect to any OpenAI-compatible LLM provider — including OpenAI, DeepSeek, Ollama, Open
|
|
88
|
+
- `constructor`: method - Use this to create a unified LLM client that connects to any OpenAI-compatible API provider (OpenAI,
|
|
89
|
+
- `isConfigured`: method - Use this to verify that an `OpenAICompatibleClient` instance is ready to make API calls before attem
|
|
90
|
+
- `complete`: method - Use this to send a chat completion request to any OpenAI-compatible API endpoint (OpenAI, Azure, Gro
|
|
91
|
+
|
|
92
|
+
### content-type
|
|
93
|
+
|
|
94
|
+
- `classifyElement`: function - Use this to determine what type of documentation an API element needs — whether it should be documen
|
|
95
|
+
- `classifyElements`: function - Use this to sort a mixed list of documentation elements into typed groups — API references, guides,
|
|
96
|
+
- `getRecommendedStructure`: function - Use this to automatically organize a list of API elements into a recommended documentation structure
|
|
97
|
+
- `getPromptForContentType`: function - Use this to get the appropriate documentation generation prompt string for a given content type, so
|
|
98
|
+
|
|
99
|
+
### go
|
|
100
|
+
|
|
101
|
+
- `GoScanner`: class - Use this to scan Go source files and extract API elements — functions, methods, structs, and interfa
|
|
102
|
+
- `canHandle`: method - Use this to check whether a Go source file should be processed by the `GoScanner` — it returns `true
|
|
103
|
+
- `scanFile`: method - Use this to extract API elements from a Go source file, returning all discovered functions, types, a
|
|
104
|
+
|
|
105
|
+
### python
|
|
106
|
+
|
|
107
|
+
- `PythonScanner`: class - Use this to scan Python source files and extract structured metadata (functions, classes, imports, e
|
|
108
|
+
- `canHandle`: method - Use this to quickly check whether a given file path should be processed by the Python scanner before
|
|
109
|
+
- `scanFile`: method - Use this to scan a Python source file and extract structured metadata — functions, classes, imports,
|
|
110
|
+
|
|
111
|
+
### python_parser
|
|
112
|
+
|
|
113
|
+
- `get_docstring`: function - Use this to extract the docstring from any Python AST node (functions, classes, modules) when parsin
|
|
114
|
+
- `get_type_annotation`: function - Use this to convert a Python AST type annotation node into its human-readable string representation
|
|
115
|
+
- `get_default_value`: function - Use this to extract a human-readable string representation of a Python function parameter's default
|
|
116
|
+
- `extract_parameters`: function - Use this to convert Python AST function arguments into a structured list of parameter metadata — ide
|
|
117
|
+
- `build_signature`: function - Use this to reconstruct a human-readable function signature string from parsed AST components — usef
|
|
118
|
+
- `extract_function`: function - Use this to extract structured metadata from a Python function or method AST node — including its na
|
|
119
|
+
- `extract_class`: function - Use this to parse a Python AST `ClassDef` node and extract structured metadata about a class and all
|
|
120
|
+
- `scan_file`: function - Use this to extract all API elements from a Python source file — functions, classes, methods, import
|
|
121
|
+
|
|
122
|
+
### rust
|
|
123
|
+
|
|
124
|
+
- `RustScanner`: class - Use this to scan Rust source files and extract public API elements — functions, structs, enums, impl
|
|
125
|
+
- `canHandle`: method - Use this to quickly determine whether a given file path should be processed by the Rust scanner befo
|
|
126
|
+
- `scanFile`: method - Use this to extract API elements from a Rust source file, parsing its contents into a structured res
|
|
127
|
+
|
|
128
|
+
### typescript
|
|
129
|
+
|
|
130
|
+
- `TypeScriptScanner`: class - Use this to scan TypeScript and JavaScript source files and extract API elements (functions, classes
|
|
131
|
+
- `canHandle`: method - Use this to quickly check whether a file path is a TypeScript/JavaScript source file that the scanne
|
|
132
|
+
- `scanFile`: method - Use this to extract API elements (functions, classes, interfaces, types) from a TypeScript or JavaSc
|
|
133
|
+
|
|
134
|
+
## API Details
|
|
135
|
+
|
|
136
|
+
### getAuthConfig
|
|
137
|
+
|
|
138
|
+
**Type:** function
|
|
139
|
+
**File:** /Users/debmukherjee/autodocs/src/auth/index.ts
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
function getAuthConfig(): AuthConfig
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Use this to retrieve the current authentication configuration from the local auth file. This is the primary way to check if a user is logged in, access their stored credentials, or verify token expiration before making API calls.
|
|
146
|
+
|
|
147
|
+
Returns an `AuthConfig` object with the user's stored auth data, or an empty object `{}` if no auth file exists yet (unauthenticated state).
|
|
148
|
+
|
|
149
|
+
## Parameters
|
|
150
|
+
|
|
151
|
+
This function takes no parameters.
|
|
152
|
+
|
|
153
|
+
## Returns
|
|
154
|
+
|
|
155
|
+
| Field | Type | Description |
|
|
156
|
+
|-------|------|-------------|
|
|
157
|
+
|
|
|
158
|
+
|
|
159
|
+
**Example:**
|
|
160
|
+
```typescript
|
|
161
|
+
import { existsSync, readFileSync } from 'fs'
|
|
162
|
+
import { join } from 'path'
|
|
163
|
+
import { homedir } from 'os'
|
|
164
|
+
|
|
165
|
+
// Inline the AuthConfig type
|
|
166
|
+
type AuthConfig = {
|
|
167
|
+
token?: string
|
|
168
|
+
email?: string
|
|
169
|
+
expiresAt?: string
|
|
170
|
+
error?: string
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Inline the auth file path logic (mirrors the real implementation)
|
|
174
|
+
co
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### saveAuthConfig
|
|
178
|
+
|
|
179
|
+
**Type:** function
|
|
180
|
+
**File:** /Users/debmukherjee/autodocs/src/auth/index.ts
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
function saveAuthConfig(config: AuthConfig): void
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Use this to persist authentication credentials to a local config file, ensuring the config directory exists before writing.
|
|
187
|
+
|
|
188
|
+
Saves an `AuthConfig` object as formatted JSON to a file on disk. Automatically creates any missing parent directories in the config path before writing, so you don't need to pre-create the directory structure.
|
|
189
|
+
|
|
190
|
+
### Parameters
|
|
191
|
+
|
|
192
|
+
| Name | Type | Required | Description |
|
|
193
|
+
|------|------|----------|-------------|
|
|
194
|
+
| config | `AuthConfig` | ✅ | Authentication configuration object
|
|
195
|
+
|
|
196
|
+
**Example:**
|
|
197
|
+
```typescript
|
|
198
|
+
import { mkdirSync, writeFileSync, readFileSync, existsSync } from 'fs'
|
|
199
|
+
import { join } from 'path'
|
|
200
|
+
import { homedir } from 'os'
|
|
201
|
+
|
|
202
|
+
// --- Inline type definition ---
|
|
203
|
+
interface AuthConfig {
|
|
204
|
+
token: string
|
|
205
|
+
userId: string
|
|
206
|
+
expiresAt?: number
|
|
207
|
+
refreshToken?: string
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// --- Inline config path consta
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### clearAuth
|
|
214
|
+
|
|
215
|
+
**Type:** function
|
|
216
|
+
**File:** /Users/debmukherjee/autodocs/src/auth/index.ts
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
function clearAuth(): void
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Use this to log a user out by wiping stored authentication credentials from the local config file. Calling this resets the auth file to an empty state (`{}`) without deleting the file itself — safe to call even if no credentials have been saved yet.
|
|
223
|
+
|
|
224
|
+
**Parameters**
|
|
225
|
+
|
|
226
|
+
None.
|
|
227
|
+
|
|
228
|
+
**Returns**
|
|
229
|
+
|
|
230
|
+
`void` — no return value. The auth config file is overwritten with `{}` if it exists; if no file is found, the function exits silently.
|
|
231
|
+
|
|
232
|
+
**Behavior**
|
|
233
|
+
- ✅ Auth file exists → contents replaced with `{}`
|
|
234
|
+
- ✅ Auth fil
|
|
235
|
+
|
|
236
|
+
**Example:**
|
|
237
|
+
```typescript
|
|
238
|
+
import { existsSync, writeFileSync, readFileSync, mkdirSync } from 'fs'
|
|
239
|
+
import { join } from 'path'
|
|
240
|
+
import { homedir } from 'os'
|
|
241
|
+
|
|
242
|
+
// --- Inline config (mirrors autodocs internals) ---
|
|
243
|
+
const CONFIG_DIR = join(homedir(), '.config', 'autodocs-demo')
|
|
244
|
+
const AUTH_FILE = join(CONFIG_DIR, 'auth.json')
|
|
245
|
+
|
|
246
|
+
type
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### checkPlan
|
|
250
|
+
|
|
251
|
+
**Type:** function
|
|
252
|
+
**File:** /Users/debmukherjee/autodocs/src/auth/index.ts
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
async function checkPlan(apiKey: string): Promise<PlanCheckResponse>
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Use this to verify an API key's validity and retrieve the associated subscription plan details before making API calls.
|
|
259
|
+
|
|
260
|
+
`checkPlan` hits the `/v1/plan` endpoint with a Bearer token and returns plan metadata — useful for gating features, displaying plan info to users, or validating credentials at startup.
|
|
261
|
+
|
|
262
|
+
## Parameters
|
|
263
|
+
|
|
264
|
+
| Name | Type | Required | Description |
|
|
265
|
+
|------|------|----------|-------------|
|
|
266
|
+
| `apiKey` | `string` | ✅ Yes | The Bearer token used to authenticate against the API |
|
|
267
|
+
|
|
268
|
+
## Ret
|
|
269
|
+
|
|
270
|
+
**Example:**
|
|
271
|
+
```typescript
|
|
272
|
+
// Inline types — no external imports needed
|
|
273
|
+
type PlanCheckResponse = {
|
|
274
|
+
plan: string
|
|
275
|
+
valid: boolean
|
|
276
|
+
limits?: {
|
|
277
|
+
requests: number
|
|
278
|
+
storage: number
|
|
279
|
+
}
|
|
280
|
+
error?: string
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Self-contained implementation mirroring the real checkPlan behavior
|
|
284
|
+
async function checkPlan(apiKey: string): Promi
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### requirePro
|
|
288
|
+
|
|
289
|
+
**Type:** function
|
|
290
|
+
**File:** /Users/debmukherjee/autodocs/src/auth/index.ts
|
|
291
|
+
|
|
292
|
+
```
|
|
293
|
+
async function requirePro(commandName: string): Promise<boolean>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Use this to gate CLI commands behind a Pro subscription — it checks the user's auth config and prints a helpful upgrade message if they're not on a paid plan.
|
|
297
|
+
|
|
298
|
+
Call `requirePro` at the top of any command handler that requires a Pro account. It returns `true` if the user is authorized to proceed, or `false` (after printing an error) if they are not.
|
|
299
|
+
|
|
300
|
+
## Parameters
|
|
301
|
+
|
|
302
|
+
| Name | Type | Required | Description |
|
|
303
|
+
|------|------|----------|-------------|
|
|
304
|
+
| `commandName` | `string` | ✅ | The name of the CL
|
|
305
|
+
|
|
306
|
+
**Example:**
|
|
307
|
+
```typescript
|
|
308
|
+
import * as fs from 'fs'
|
|
309
|
+
import * as path from 'path'
|
|
310
|
+
import * as os from 'os'
|
|
311
|
+
|
|
312
|
+
// --- Inline types and helpers (self-contained, no external imports) ---
|
|
313
|
+
|
|
314
|
+
type AuthConfig = {
|
|
315
|
+
apiKey: string | null
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
type LicenseStatus = {
|
|
319
|
+
valid: boolean
|
|
320
|
+
plan: 'free' | 'pro'
|
|
321
|
+
email: string
|
|
322
|
+
error?: string
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### isProCommand
|
|
328
|
+
|
|
329
|
+
**Type:** function
|
|
330
|
+
**File:** /Users/debmukherjee/autodocs/src/auth/index.ts
|
|
331
|
+
|
|
332
|
+
```
|
|
333
|
+
function isProCommand(command: string): boolean
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Use this to check whether a given CLI command requires a Pro subscription before executing it, enabling you to gate features and show appropriate upgrade prompts.
|
|
337
|
+
|
|
338
|
+
## Parameters
|
|
339
|
+
|
|
340
|
+
| Name | Type | Required | Description |
|
|
341
|
+
|------|------|----------|-------------|
|
|
342
|
+
| command | string | Yes | The CLI command name to check against the list of Pro-only commands |
|
|
343
|
+
|
|
344
|
+
## Returns
|
|
345
|
+
|
|
346
|
+
- **`true`** — the command is Pro-only and requires an upgraded account
|
|
347
|
+
- **`false`** — the command is available on the free tier
|
|
348
|
+
|
|
349
|
+
**Example:**
|
|
350
|
+
```typescript
|
|
351
|
+
// Define the Pro commands list inline (mirrors the source)
|
|
352
|
+
const PRO_COMMANDS = ['gh-action', 'ci', 'mcp']
|
|
353
|
+
|
|
354
|
+
// Inline implementation of isProCommand
|
|
355
|
+
function isProCommand(command: string): boolean {
|
|
356
|
+
return PRO_COMMANDS.includes(command)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Simulate a user running a CLI command
|
|
360
|
+
function runComm
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### autoFixExample
|
|
364
|
+
|
|
365
|
+
**Type:** function
|
|
366
|
+
**File:** /Users/debmukherjee/autodocs/src/autofix/index.ts
|
|
367
|
+
|
|
368
|
+
```
|
|
369
|
+
async function autoFixExample(example: CodeExample, client: LLMClient, options: AutoFixOptions = {}): Promise<FixResult>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
Use this to automatically repair broken or invalid code examples by iteratively applying LLM-powered fixes until the code is valid or the maximum retry limit is reached.
|
|
373
|
+
|
|
374
|
+
This is ideal for CI pipelines, documentation generators, or developer tools that need to ensure code examples stay compilable and correct as APIs evolve.
|
|
375
|
+
|
|
376
|
+
## Parameters
|
|
377
|
+
|
|
378
|
+
| Name | Type | Required | Description |
|
|
379
|
+
|------|------|----------|-------------|
|
|
380
|
+
| `example` | `CodeExample` | ✅ | The code example to fix, including its sou
|
|
381
|
+
|
|
382
|
+
**Example:**
|
|
383
|
+
```typescript
|
|
384
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
385
|
+
|
|
386
|
+
type CodeExample = {
|
|
387
|
+
code: string
|
|
388
|
+
language: string
|
|
389
|
+
errorContext?: string
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
type AutoFixOptions = {
|
|
393
|
+
maxIterations?: number
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
type FixResult = {
|
|
397
|
+
success: boolean
|
|
398
|
+
fixedCode: string | null
|
|
399
|
+
iterations: number
|
|
400
|
+
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### autoFixBatch
|
|
404
|
+
|
|
405
|
+
**Type:** function
|
|
406
|
+
**File:** /Users/debmukherjee/autodocs/src/autofix/index.ts
|
|
407
|
+
|
|
408
|
+
```
|
|
409
|
+
async function autoFixBatch(examples: CodeExample[], client: LLMClient, options: AutoFixOptions = {}): Promise<Map<number, FixResult>>
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Use this to automatically fix multiple broken code examples in a single batch operation, getting back a map of results indexed by position.
|
|
413
|
+
|
|
414
|
+
This is the batch version of `autoFix` — ideal when you have a collection of code examples that need validation and repair, such as during a documentation build pipeline or CI check.
|
|
415
|
+
|
|
416
|
+
## Parameters
|
|
417
|
+
|
|
418
|
+
| Name | Type | Required | Description |
|
|
419
|
+
|------|------|----------|-------------|
|
|
420
|
+
| `examples` | `CodeExample[]` | ✅ Yes | Array of code examples to fix, each w
|
|
421
|
+
|
|
422
|
+
**Example:**
|
|
423
|
+
```typescript
|
|
424
|
+
// ── Inline types (do not import from autodocs) ──────────────────────────────
|
|
425
|
+
|
|
426
|
+
type CodeExample = {
|
|
427
|
+
code: string
|
|
428
|
+
language?: string
|
|
429
|
+
filename?: string
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
type FixResult = {
|
|
433
|
+
fixed: boolean
|
|
434
|
+
code: string
|
|
435
|
+
error?: string
|
|
436
|
+
attempts: number
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
type AutoFixOptions = {
|
|
440
|
+
maxRetries?: number
|
|
441
|
+
la
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### createTypeScriptValidator
|
|
445
|
+
|
|
446
|
+
**Type:** function
|
|
447
|
+
**File:** /Users/debmukherjee/autodocs/src/autofix/index.ts
|
|
448
|
+
|
|
449
|
+
```
|
|
450
|
+
function createTypeScriptValidator(): (code: string) => Promise<ValidationResult>
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Use this to validate TypeScript code strings at runtime — perfect for checking LLM-generated code, user-submitted snippets, or dynamically built TypeScript before execution.
|
|
454
|
+
|
|
455
|
+
Returns a validator function that accepts a TypeScript code string and resolves with a `ValidationResult` indicating whether the code is valid and any diagnostic errors found.
|
|
456
|
+
|
|
457
|
+
## Parameters
|
|
458
|
+
|
|
459
|
+
This factory function takes no parameters.
|
|
460
|
+
|
|
461
|
+
## Returned Validator Function
|
|
462
|
+
|
|
463
|
+
| Name | Type | Required | Description |
|
|
464
|
+
|------|------|-
|
|
465
|
+
|
|
466
|
+
**Example:**
|
|
467
|
+
```typescript
|
|
468
|
+
import * as ts from 'typescript'
|
|
469
|
+
|
|
470
|
+
// --- Inline types (do not import from autodocs) ---
|
|
471
|
+
interface ValidationResult {
|
|
472
|
+
valid: boolean
|
|
473
|
+
errors: string[]
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// --- Inline implementation matching the library's behavior ---
|
|
477
|
+
function createTypeScriptValidator(): (code: string) => Promise<ValidationResul
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### createPythonValidator
|
|
481
|
+
|
|
482
|
+
**Type:** function
|
|
483
|
+
**File:** /Users/debmukherjee/autodocs/src/autofix/index.ts
|
|
484
|
+
|
|
485
|
+
```
|
|
486
|
+
function createPythonValidator(): (code: string) => Promise<ValidationResult>
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Use this to validate Python code syntax and catch errors before execution, without needing a Python runtime wrapper or external validation service — just `python3` in your PATH.
|
|
490
|
+
|
|
491
|
+
Returns a reusable validator function you can call repeatedly with different code strings. Each call spawns a `python3` process to perform real syntax checking.
|
|
492
|
+
|
|
493
|
+
## Parameters
|
|
494
|
+
|
|
495
|
+
This factory function takes no parameters.
|
|
496
|
+
|
|
497
|
+
## Returns
|
|
498
|
+
|
|
499
|
+
| Return | Type | Description |
|
|
500
|
+
|--------|------|-------------|
|
|
501
|
+
| validator | `(code: st
|
|
502
|
+
|
|
503
|
+
**Example:**
|
|
504
|
+
```typescript
|
|
505
|
+
import { spawnSync } from 'child_process'
|
|
506
|
+
import { writeFileSync, unlinkSync } from 'fs'
|
|
507
|
+
import { join } from 'path'
|
|
508
|
+
import { tmpdir } from 'os'
|
|
509
|
+
|
|
510
|
+
// Inline the ValidationResult type (matches the library's shape)
|
|
511
|
+
type ValidationResult = {
|
|
512
|
+
valid: boolean
|
|
513
|
+
errors: string[]
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Self-contained imple
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### findConfigFile
|
|
520
|
+
|
|
521
|
+
**Type:** function
|
|
522
|
+
**File:** /Users/debmukherjee/autodocs/src/config/loader.ts
|
|
523
|
+
|
|
524
|
+
```
|
|
525
|
+
function findConfigFile(dir: string): string | null
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
Use this to locate a Skrypt configuration file by searching a directory for any of the supported config filenames (`.skrypt.yaml`, `.skrypt.yml`, `skrypt.yaml`, `skrypt.yml`).
|
|
529
|
+
|
|
530
|
+
Returns the **full path** to the first matching config file found, or `null` if none exist in the given directory. Useful for resolving config before initializing your toolchain, or for validating that a project is properly configured.
|
|
531
|
+
|
|
532
|
+
### Parameters
|
|
533
|
+
|
|
534
|
+
| Name | Type | Required | Description |
|
|
535
|
+
|------|------|----------|---
|
|
536
|
+
|
|
537
|
+
**Example:**
|
|
538
|
+
```typescript
|
|
539
|
+
import { existsSync } from 'fs'
|
|
540
|
+
import { join } from 'path'
|
|
541
|
+
|
|
542
|
+
// Supported config filenames (in priority order)
|
|
543
|
+
const CONFIG_FILENAMES = ['.skrypt.yaml', '.skrypt.yml', 'skrypt.yaml', 'skrypt.yml']
|
|
544
|
+
|
|
545
|
+
// Inline implementation of findConfigFile
|
|
546
|
+
function findConfigFile(dir: string): string | null {
|
|
547
|
+
for
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
### loadConfig
|
|
551
|
+
|
|
552
|
+
**Type:** function
|
|
553
|
+
**File:** /Users/debmukherjee/autodocs/src/config/loader.ts
|
|
554
|
+
|
|
555
|
+
```
|
|
556
|
+
function loadConfig(configPath?: string): Config
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
Use this to load a configuration file for autodocs, either from a specific path or by auto-discovering it from standard locations in your project.
|
|
560
|
+
|
|
561
|
+
Searches for config files in common locations (e.g., `autodocs.config.yml`, `.autodocs.yml`) when no path is provided. Throws an error if an explicit path is given but the file does not exist.
|
|
562
|
+
|
|
563
|
+
### Parameters
|
|
564
|
+
|
|
565
|
+
| Name | Type | Required | Description |
|
|
566
|
+
|------|------|----------|-------------|
|
|
567
|
+
| `configPath` | `string` | No | Absolute or relative path t
|
|
568
|
+
|
|
569
|
+
**Example:**
|
|
570
|
+
```typescript
|
|
571
|
+
import { existsSync, readFileSync } from 'fs'
|
|
572
|
+
import { join } from 'path'
|
|
573
|
+
|
|
574
|
+
// --- Inline types (mirrors autodocs internals) ---
|
|
575
|
+
type LLMProvider = 'openai' | 'anthropic' | 'gemini'
|
|
576
|
+
|
|
577
|
+
interface Config {
|
|
578
|
+
provider: LLMProvider
|
|
579
|
+
model: string
|
|
580
|
+
outputDir: string
|
|
581
|
+
include: string[]
|
|
582
|
+
exclude: string[]
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### validateConfig
|
|
586
|
+
|
|
587
|
+
**Type:** function
|
|
588
|
+
**File:** /Users/debmukherjee/autodocs/src/config/loader.ts
|
|
589
|
+
|
|
590
|
+
```
|
|
591
|
+
function validateConfig(config: Config): string[]
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
Use this to validate a configuration object before using it, catching all errors upfront instead of failing at runtime.
|
|
595
|
+
|
|
596
|
+
Returns an array of error message strings — an empty array means the config is valid. Each string describes a specific validation failure, making it easy to surface all problems at once rather than one at a time.
|
|
597
|
+
|
|
598
|
+
### Parameters
|
|
599
|
+
|
|
600
|
+
| Name | Type | Required | Description |
|
|
601
|
+
|------|------|----------|-------------|
|
|
602
|
+
| config | `Config` | ✅ | The configuration object to validate |
|
|
603
|
+
|
|
604
|
+
#
|
|
605
|
+
|
|
606
|
+
**Example:**
|
|
607
|
+
```typescript
|
|
608
|
+
// Inline type definition — mirrors the real Config shape
|
|
609
|
+
type LLMProvider = 'openai' | 'anthropic' | 'gemini'
|
|
610
|
+
|
|
611
|
+
type Config = {
|
|
612
|
+
version: number
|
|
613
|
+
provider?: LLMProvider
|
|
614
|
+
apiKey?: string
|
|
615
|
+
outputDir?: string
|
|
616
|
+
license?: string
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// Inline implementation — mirrors the real validation logic
|
|
620
|
+
functio
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
### checkApiKey
|
|
624
|
+
|
|
625
|
+
**Type:** function
|
|
626
|
+
**File:** /Users/debmukherjee/autodocs/src/config/loader.ts
|
|
627
|
+
|
|
628
|
+
```
|
|
629
|
+
function checkApiKey(provider: LLMProvider): { ok: boolean; envKey: string | null }
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
Use this to verify whether a required API key environment variable is set for a given LLM provider before making requests.
|
|
633
|
+
|
|
634
|
+
Returns `{ ok: true }` for providers that don't require an API key (e.g., Ollama), and checks the appropriate environment variable for cloud providers (e.g., OpenAI, Anthropic). Use this at startup or before inference calls to give users clear, actionable feedback when credentials are missing.
|
|
635
|
+
|
|
636
|
+
### Parameters
|
|
637
|
+
|
|
638
|
+
| Name | Type | Required | Description |
|
|
639
|
+
|------|------|--------
|
|
640
|
+
|
|
641
|
+
**Example:**
|
|
642
|
+
```typescript
|
|
643
|
+
// Inline types — do not import from autodocs
|
|
644
|
+
type LLMProvider = 'openai' | 'anthropic' | 'ollama' | 'gemini'
|
|
645
|
+
|
|
646
|
+
// Maps each provider to its required environment variable (null = no key needed)
|
|
647
|
+
const PROVIDER_ENV_KEYS: Record<LLMProvider, string | null> = {
|
|
648
|
+
openai: 'OPENAI_API_KEY',
|
|
649
|
+
anthropic: 'A
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
### generateForElement
|
|
653
|
+
|
|
654
|
+
**Type:** function
|
|
655
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/generator.ts
|
|
656
|
+
|
|
657
|
+
```
|
|
658
|
+
async function generateForElement(element: APIElement, client: LLMClient, options: GenerationOptions, onProgress?: (progress: GenerationProgress) => void): Promise<GeneratedDoc>
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
Use this to generate documentation for a single API element using an LLM client, without running any test validation on the output.
|
|
662
|
+
|
|
663
|
+
This is the core documentation generation function — pass it a parsed API element (function, class, type, etc.), an LLM client, and generation options to receive structured documentation. Optionally track progress in real time via the `onProgress` callback.
|
|
664
|
+
|
|
665
|
+
## Parameters
|
|
666
|
+
|
|
667
|
+
| Name | Type | Required | Description |
|
|
668
|
+
|------|------|----------|-------------|
|
|
669
|
+
| `element`
|
|
670
|
+
|
|
671
|
+
**Example:**
|
|
672
|
+
```typescript
|
|
673
|
+
// ─── Inline type definitions (no external imports needed) ───────────────────
|
|
674
|
+
|
|
675
|
+
type APIElement = {
|
|
676
|
+
name: string
|
|
677
|
+
kind: 'function' | 'class' | 'interface' | 'type'
|
|
678
|
+
signature: string
|
|
679
|
+
docstring?: string
|
|
680
|
+
filePath: string
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
type GenerationOptions = {
|
|
684
|
+
model: string
|
|
685
|
+
style: 'concise' | 'deta
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
### generateForElements
|
|
689
|
+
|
|
690
|
+
**Type:** function
|
|
691
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/generator.ts
|
|
692
|
+
|
|
693
|
+
```
|
|
694
|
+
async function generateForElements(elements: APIElement[], client: LLMClient, options: GenerationOptions): Promise<GeneratedDoc[]>
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
Use this to batch-generate documentation for multiple API elements in a single call, processing an entire scanned API surface and returning structured docs for each element.
|
|
698
|
+
|
|
699
|
+
This is the primary entry point for bulk documentation generation — pass in your parsed API elements, an LLM client, and generation options to get back a full array of generated documentation objects.
|
|
700
|
+
|
|
701
|
+
## Parameters
|
|
702
|
+
|
|
703
|
+
| Name | Type | Required | Description |
|
|
704
|
+
|------|------|----------|-------------|
|
|
705
|
+
| `elements` | `APIElement
|
|
706
|
+
|
|
707
|
+
**Example:**
|
|
708
|
+
```typescript
|
|
709
|
+
// ─── Inline type definitions (no external imports needed) ───────────────────
|
|
710
|
+
|
|
711
|
+
type APIElement = {
|
|
712
|
+
name: string
|
|
713
|
+
kind: 'function' | 'class' | 'type' | 'interface' | 'variable'
|
|
714
|
+
signature: string
|
|
715
|
+
docstring?: string
|
|
716
|
+
filePath: string
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
type GeneratedDoc = {
|
|
720
|
+
elementName: string
|
|
721
|
+
kind: APIE
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
### formatAsMarkdown
|
|
725
|
+
|
|
726
|
+
**Type:** function
|
|
727
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/generator.ts
|
|
728
|
+
|
|
729
|
+
```
|
|
730
|
+
function formatAsMarkdown(docs: GeneratedDoc[], title: string): string
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
Use this to convert an array of generated documentation objects into a formatted Markdown string, ready to write to a `.md` file or display in a docs site.
|
|
734
|
+
|
|
735
|
+
Takes structured doc data (functions, classes, methods) and a page title, and returns a complete Markdown document with sections organized by element type.
|
|
736
|
+
|
|
737
|
+
## Parameters
|
|
738
|
+
|
|
739
|
+
| Name | Type | Required | Description |
|
|
740
|
+
|------|------|----------|-------------|
|
|
741
|
+
| `docs` | `GeneratedDoc[]` | ✅ | Array of generated documentation objects, each containi
|
|
742
|
+
|
|
743
|
+
**Example:**
|
|
744
|
+
```typescript
|
|
745
|
+
// ---- Inline types (mirrors the real GeneratedDoc / APIElement shape) ----
|
|
746
|
+
type ElementKind = 'function' | 'class' | 'method'
|
|
747
|
+
|
|
748
|
+
interface APIElement {
|
|
749
|
+
name: string
|
|
750
|
+
kind: ElementKind
|
|
751
|
+
signature?: string
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
interface GeneratedDoc {
|
|
755
|
+
element: APIElement
|
|
756
|
+
documentation: string
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// ---- Inline
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
### organizeByTopic
|
|
763
|
+
|
|
764
|
+
**Type:** function
|
|
765
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/organizer.ts
|
|
766
|
+
|
|
767
|
+
```
|
|
768
|
+
function organizeByTopic(docs: GeneratedDoc[], config: TopicConfig = DEFAULT_TOPIC_CONFIG): Topic[]
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
Use this to group a flat list of generated documentation objects into organized topic clusters — ideal for building navigation menus, documentation sidebars, or categorized API references.
|
|
772
|
+
|
|
773
|
+
## Parameters
|
|
774
|
+
|
|
775
|
+
| Name | Type | Required | Description |
|
|
776
|
+
|------|------|----------|-------------|
|
|
777
|
+
| `docs` | `GeneratedDoc[]` | Yes | Array of generated documentation objects to organize |
|
|
778
|
+
| `config` | `TopicConfig` | No | Configuration controlling how topics are detected and grouped. Defaults to `DEFAULT_TOPI
|
|
779
|
+
|
|
780
|
+
**Example:**
|
|
781
|
+
```typescript
|
|
782
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
783
|
+
|
|
784
|
+
type GeneratedDoc = {
|
|
785
|
+
id: string
|
|
786
|
+
title: string
|
|
787
|
+
topic: string
|
|
788
|
+
content: string
|
|
789
|
+
slug: string
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
type Topic = {
|
|
793
|
+
label: string
|
|
794
|
+
slug: string
|
|
795
|
+
docs: GeneratedDoc[]
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
type TopicConfig = {
|
|
799
|
+
defaultTopic: string
|
|
800
|
+
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
### detectCrossReferences
|
|
804
|
+
|
|
805
|
+
**Type:** function
|
|
806
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/organizer.ts
|
|
807
|
+
|
|
808
|
+
```
|
|
809
|
+
function detectCrossReferences(docs: GeneratedDoc[]): CrossReference[]
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
Use this to automatically discover relationships between documented elements — for example, when one function references another by name in its parameters, return type, or description.
|
|
813
|
+
|
|
814
|
+
Given an array of generated documentation objects, this scans each element and identifies where one doc references another by name, returning a flat list of directed cross-references you can use to build navigation links, dependency graphs, or "See Also" sections.
|
|
815
|
+
|
|
816
|
+
## Parameters
|
|
817
|
+
|
|
818
|
+
| Name | Type | Required | Descri
|
|
819
|
+
|
|
820
|
+
**Example:**
|
|
821
|
+
```typescript
|
|
822
|
+
// ─── Inline types (do NOT import from autodocs) ───────────────────────────────
|
|
823
|
+
|
|
824
|
+
type DocElement = {
|
|
825
|
+
name: string;
|
|
826
|
+
params?: { type: string }[];
|
|
827
|
+
returnType?: string;
|
|
828
|
+
description?: string;
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
type GeneratedDoc = {
|
|
832
|
+
element: DocElement;
|
|
833
|
+
topics: string[];
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
type CrossReference = {
|
|
837
|
+
from
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
### getCrossRefsForElement
|
|
841
|
+
|
|
842
|
+
**Type:** function
|
|
843
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/organizer.ts
|
|
844
|
+
|
|
845
|
+
```
|
|
846
|
+
function getCrossRefsForElement(elementName: string, allRefs: CrossReference[]): CrossReference[]
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
Use this to filter a list of cross-references down to only those originating from a specific element — useful when building navigation, dependency graphs, or "see also" sections for a given function, class, or module.
|
|
850
|
+
|
|
851
|
+
Given an element name and a full list of cross-references, it returns only the references where `fromElement` matches the provided name.
|
|
852
|
+
|
|
853
|
+
### Parameters
|
|
854
|
+
|
|
855
|
+
| Name | Type | Required | Description |
|
|
856
|
+
|------|------|----------|-------------|
|
|
857
|
+
| `elementName` | `string` | ✅ | The name of
|
|
858
|
+
|
|
859
|
+
**Example:**
|
|
860
|
+
```typescript
|
|
861
|
+
// Inline the CrossReference type (matches the real shape from autodocs)
|
|
862
|
+
type CrossReference = {
|
|
863
|
+
fromElement: string
|
|
864
|
+
toElement: string
|
|
865
|
+
description?: string
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// Inline the function implementation
|
|
869
|
+
function getCrossRefsForElement(
|
|
870
|
+
elementName: string,
|
|
871
|
+
allRefs: CrossReference[]
|
|
872
|
+
): CrossRefer
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
### buildNavigation
|
|
876
|
+
|
|
877
|
+
**Type:** function
|
|
878
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/organizer.ts
|
|
879
|
+
|
|
880
|
+
```
|
|
881
|
+
function buildNavigation(topics: Topic[]): NavigationItem[]
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
Use this to convert a flat list of documentation topics into a hierarchical navigation structure suitable for rendering sidebars, menus, or breadcrumbs.
|
|
885
|
+
|
|
886
|
+
Given an array of `Topic` objects (each containing an ID, name, and associated docs), `buildNavigation` returns a nested `NavigationItem[]` where each top-level item maps to a topic and its children map to individual documented elements.
|
|
887
|
+
|
|
888
|
+
## Parameters
|
|
889
|
+
|
|
890
|
+
| Name | Type | Required | Description |
|
|
891
|
+
|------|------|----------|-------------|
|
|
892
|
+
| `topics`
|
|
893
|
+
|
|
894
|
+
**Example:**
|
|
895
|
+
```typescript
|
|
896
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
897
|
+
|
|
898
|
+
type DocElement = {
|
|
899
|
+
name: string;
|
|
900
|
+
description?: string;
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
type GeneratedDoc = {
|
|
904
|
+
element: DocElement;
|
|
905
|
+
markdown: string;
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
type Topic = {
|
|
909
|
+
id: string;
|
|
910
|
+
name: string;
|
|
911
|
+
docs: GeneratedDoc[];
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
type Navigatio
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
### generateSidebarConfig
|
|
918
|
+
|
|
919
|
+
**Type:** function
|
|
920
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/organizer.ts
|
|
921
|
+
|
|
922
|
+
```
|
|
923
|
+
function generateSidebarConfig(topics: Topic[]): object
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
Use this to convert an array of documentation topics into a sidebar navigation configuration compatible with multiple documentation platforms (Mintlify, Docusaurus, etc.).
|
|
927
|
+
|
|
928
|
+
The function maps each topic to a navigation group, with its documents as slugified page paths in the format `topicId/doc-name`.
|
|
929
|
+
|
|
930
|
+
## Parameters
|
|
931
|
+
|
|
932
|
+
| Name | Type | Required | Description |
|
|
933
|
+
|------|------|----------|-------------|
|
|
934
|
+
| `topics` | `Topic[]` | ✅ | Array of topic objects, each containing an `id`, `name`, and `docs` arr
|
|
935
|
+
|
|
936
|
+
**Example:**
|
|
937
|
+
```typescript
|
|
938
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
939
|
+
type DocElement = { name: string }
|
|
940
|
+
type GeneratedDoc = { element: DocElement }
|
|
941
|
+
type Topic = {
|
|
942
|
+
id: string
|
|
943
|
+
name: string
|
|
944
|
+
docs: GeneratedDoc[]
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// ── Inline slugify helper (mirrors the real implementation) ───────────
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
### mergeTopicConfig
|
|
951
|
+
|
|
952
|
+
**Type:** function
|
|
953
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/organizer.ts
|
|
954
|
+
|
|
955
|
+
```
|
|
956
|
+
function mergeTopicConfig(userConfig: Partial<TopicConfig>, defaults: TopicConfig = DEFAULT_TOPIC_CONFIG): TopicConfig
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
Use this to safely merge a partial user-provided topic configuration with a set of defaults, ensuring the resulting config is always complete and valid.
|
|
960
|
+
|
|
961
|
+
This is useful when users supply only a subset of configuration options (e.g., overriding a few topics) and you need to fill in the rest from sensible defaults without losing any required fields.
|
|
962
|
+
|
|
963
|
+
### Parameters
|
|
964
|
+
|
|
965
|
+
| Name | Type | Required | Description |
|
|
966
|
+
|------|------|----------|-------------|
|
|
967
|
+
| `userConfig` | `Partial<TopicConfig>` | Yes | The
|
|
968
|
+
|
|
969
|
+
**Example:**
|
|
970
|
+
```typescript
|
|
971
|
+
// Inline types (no external imports needed)
|
|
972
|
+
type Topic = {
|
|
973
|
+
label: string
|
|
974
|
+
description: string
|
|
975
|
+
color?: string
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
type TopicConfig = {
|
|
979
|
+
topics: Record<string, Topic>
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// Simulate DEFAULT_TOPIC_CONFIG
|
|
983
|
+
const DEFAULT_TOPIC_CONFIG: TopicConfig = {
|
|
984
|
+
topics: {
|
|
985
|
+
general: {
|
|
986
|
+
label: 'General'
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
### writeLlmsTxt
|
|
990
|
+
|
|
991
|
+
**Type:** function
|
|
992
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/writer.ts
|
|
993
|
+
|
|
994
|
+
```
|
|
995
|
+
async function writeLlmsTxt(docs: GeneratedDoc[], outputDir: string, options: { projectName?: string; description?: string } = {}): Promise<void>
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
Use this to generate an `llms.txt` file for your API documentation, making it discoverable and consumable by LLM-powered answer engines following the [llmstxt.org](https://llmstxt.org) convention.
|
|
999
|
+
|
|
1000
|
+
This is particularly useful for Answer Engine Optimization (AEO) — the equivalent of SEO but for AI assistants and LLM-based search tools.
|
|
1001
|
+
|
|
1002
|
+
## Parameters
|
|
1003
|
+
|
|
1004
|
+
| Name | Type | Required | Description |
|
|
1005
|
+
|------|------|----------|-------------|
|
|
1006
|
+
| `docs` | `GeneratedDoc[]` | Yes | Array of generated documentat
|
|
1007
|
+
|
|
1008
|
+
**Example:**
|
|
1009
|
+
```typescript
|
|
1010
|
+
import { mkdir, writeFile } from 'fs/promises'
|
|
1011
|
+
import { join } from 'path'
|
|
1012
|
+
import * as os from 'os'
|
|
1013
|
+
import * as path from 'path'
|
|
1014
|
+
|
|
1015
|
+
// --- Inline types (mirrors the real GeneratedDoc shape) ---
|
|
1016
|
+
type GeneratedDoc = {
|
|
1017
|
+
filePath: string
|
|
1018
|
+
elementName: string
|
|
1019
|
+
content: string
|
|
1020
|
+
description?: string
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
### writeDocsToDirectory
|
|
1027
|
+
|
|
1028
|
+
**Type:** function
|
|
1029
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/writer.ts
|
|
1030
|
+
|
|
1031
|
+
```
|
|
1032
|
+
async function writeDocsToDirectory(results: FileGenerationResult[], outputDir: string, sourceDir: string): Promise<{ filesWritten: number; totalDocs: number }>
|
|
1033
|
+
```
|
|
1034
|
+
|
|
1035
|
+
Use this to persist generated documentation to disk, writing markdown files into an output directory while preserving the relative structure of your source directory.
|
|
1036
|
+
|
|
1037
|
+
After generating docs for your source files, pass the results to this function to write them out as organized markdown files. It handles directory creation automatically and maps each source file to a corresponding output path.
|
|
1038
|
+
|
|
1039
|
+
### Parameters
|
|
1040
|
+
|
|
1041
|
+
| Name | Type | Required | Description |
|
|
1042
|
+
|------|------|----------|-------------|
|
|
1043
|
+
| `re
|
|
1044
|
+
|
|
1045
|
+
**Example:**
|
|
1046
|
+
```typescript
|
|
1047
|
+
import { mkdir, writeFile } from 'fs/promises'
|
|
1048
|
+
import { join, dirname, relative, basename } from 'path'
|
|
1049
|
+
|
|
1050
|
+
// --- Inline types (mirrors autodocs internals) ---
|
|
1051
|
+
interface GeneratedDoc {
|
|
1052
|
+
name: string
|
|
1053
|
+
kind: 'function' | 'class' | 'interface' | 'type'
|
|
1054
|
+
markdown: string
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
interface FileGenerationResu
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
### groupDocsByFile
|
|
1061
|
+
|
|
1062
|
+
**Type:** function
|
|
1063
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/writer.ts
|
|
1064
|
+
|
|
1065
|
+
```
|
|
1066
|
+
function groupDocsByFile(docs: GeneratedDoc[]): FileGenerationResult[]
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
Use this to organize a flat list of generated documentation objects into groups by their source file, making it easy to write one output file per source file.
|
|
1070
|
+
|
|
1071
|
+
This is the key step between generating individual doc entries and writing them to disk — it collapses a flat array into a file-keyed structure so you can iterate over files and write each one independently.
|
|
1072
|
+
|
|
1073
|
+
## Parameters
|
|
1074
|
+
|
|
1075
|
+
| Name | Type | Required | Description |
|
|
1076
|
+
|------|------|----------|-------------|
|
|
1077
|
+
| `docs` | `GeneratedDoc[]` | ✅ |
|
|
1078
|
+
|
|
1079
|
+
**Example:**
|
|
1080
|
+
```typescript
|
|
1081
|
+
// ── Inline types (do not import from autodocs) ──────────────────────────────
|
|
1082
|
+
|
|
1083
|
+
interface CodeElement {
|
|
1084
|
+
name: string
|
|
1085
|
+
filePath: string
|
|
1086
|
+
kind: 'function' | 'class' | 'interface' | 'type'
|
|
1087
|
+
signature: string
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
interface GeneratedDoc {
|
|
1091
|
+
element: CodeElement
|
|
1092
|
+
markdown: string
|
|
1093
|
+
generatedAt: Date
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
### writeDocsByTopic
|
|
1097
|
+
|
|
1098
|
+
**Type:** function
|
|
1099
|
+
**File:** /Users/debmukherjee/autodocs/src/generator/writer.ts
|
|
1100
|
+
|
|
1101
|
+
```
|
|
1102
|
+
async function writeDocsByTopic(docs: GeneratedDoc[], outputDir: string): Promise<{ filesWritten: number; totalDocs: number; topics: Topic[] }>
|
|
1103
|
+
```
|
|
1104
|
+
|
|
1105
|
+
Use this to write generated documentation files to disk, organized into topic-based subdirectories — ideal for creating structured doc sites where related functions and classes are grouped together.
|
|
1106
|
+
|
|
1107
|
+
Instead of dumping all docs into a flat directory, `writeDocsByTopic` automatically clusters your `GeneratedDoc` entries by topic and writes each one into the appropriate subfolder, returning a summary of what was written.
|
|
1108
|
+
|
|
1109
|
+
## Parameters
|
|
1110
|
+
|
|
1111
|
+
| Name | Type | Required | Description |
|
|
1112
|
+
|------|------|-----
|
|
1113
|
+
|
|
1114
|
+
**Example:**
|
|
1115
|
+
```typescript
|
|
1116
|
+
import fs from 'fs/promises'
|
|
1117
|
+
import path from 'path'
|
|
1118
|
+
import os from 'os'
|
|
1119
|
+
|
|
1120
|
+
// ── Inline types (mirrors autodocs internals) ────────────────────────────────
|
|
1121
|
+
|
|
1122
|
+
type GeneratedDoc = {
|
|
1123
|
+
elementName: string
|
|
1124
|
+
topic: string
|
|
1125
|
+
filePath: string
|
|
1126
|
+
markdown: string
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
type Topic = {
|
|
1130
|
+
name: string
|
|
1131
|
+
slug: strin
|
|
1132
|
+
```
|
|
1133
|
+
|
|
1134
|
+
### postPRComment
|
|
1135
|
+
|
|
1136
|
+
**Type:** function
|
|
1137
|
+
**File:** /Users/debmukherjee/autodocs/src/github/pr-comments.ts
|
|
1138
|
+
|
|
1139
|
+
```
|
|
1140
|
+
async function postPRComment(config: PRCommentConfig, issues: DocumentationIssue[]): Promise<CommentResult>
|
|
1141
|
+
```
|
|
1142
|
+
|
|
1143
|
+
Use this to automatically post documentation issue summaries as review comments on GitHub Pull Requests — ideal for CI pipelines that lint or validate docs on every PR.
|
|
1144
|
+
|
|
1145
|
+
## Parameters
|
|
1146
|
+
|
|
1147
|
+
| Name | Type | Required | Description |
|
|
1148
|
+
|------|------|----------|-------------|
|
|
1149
|
+
| `config` | `PRCommentConfig` | Yes | GitHub connection details including repo owner, repo name, PR number, and optional auth token |
|
|
1150
|
+
| `issues` | `DocumentationIssue[]` | Yes | Array of documentation issues to summarize in the PR c
|
|
1151
|
+
|
|
1152
|
+
**Example:**
|
|
1153
|
+
```typescript
|
|
1154
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
1155
|
+
|
|
1156
|
+
type PRCommentConfig = {
|
|
1157
|
+
owner: string
|
|
1158
|
+
repo: string
|
|
1159
|
+
prNumber: number
|
|
1160
|
+
token?: string
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
type DocumentationIssue = {
|
|
1164
|
+
file: string
|
|
1165
|
+
line?: number
|
|
1166
|
+
message: string
|
|
1167
|
+
severity: 'error' | 'warning'
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
type CommentR
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
### postInlineComments
|
|
1174
|
+
|
|
1175
|
+
**Type:** function
|
|
1176
|
+
**File:** /Users/debmukherjee/autodocs/src/github/pr-comments.ts
|
|
1177
|
+
|
|
1178
|
+
```
|
|
1179
|
+
async function postInlineComments(config: PRCommentConfig, issues: DocumentationIssue[]): Promise<CommentResult[]>
|
|
1180
|
+
```
|
|
1181
|
+
|
|
1182
|
+
Use this to post inline review comments on specific lines of a pull request, flagging documentation issues directly in the GitHub code review interface.
|
|
1183
|
+
|
|
1184
|
+
This function iterates over a list of documentation issues and attaches each as an inline comment to the relevant file and line in a PR — ideal for automated doc linters, CI checks, or code review bots.
|
|
1185
|
+
|
|
1186
|
+
## Parameters
|
|
1187
|
+
|
|
1188
|
+
| Name | Type | Required | Description |
|
|
1189
|
+
|------|------|----------|-------------|
|
|
1190
|
+
| `config` | `PRCommentConfig` | Yes | PR tar
|
|
1191
|
+
|
|
1192
|
+
**Example:**
|
|
1193
|
+
```typescript
|
|
1194
|
+
// ── Inline type definitions (no external imports needed) ──────────────────────
|
|
1195
|
+
|
|
1196
|
+
type PRCommentConfig = {
|
|
1197
|
+
token?: string
|
|
1198
|
+
owner: string
|
|
1199
|
+
repo: string
|
|
1200
|
+
pullNumber: number
|
|
1201
|
+
commitSha: string
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
type DocumentationIssue = {
|
|
1205
|
+
file: string
|
|
1206
|
+
line: number
|
|
1207
|
+
message: string
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
type CommentResult =
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
### analyzePRForDocs
|
|
1214
|
+
|
|
1215
|
+
**Type:** function
|
|
1216
|
+
**File:** /Users/debmukherjee/autodocs/src/github/pr-comments.ts
|
|
1217
|
+
|
|
1218
|
+
```
|
|
1219
|
+
async function analyzePRForDocs(config: PRCommentConfig, _options: { checkExamples?: boolean } = {}): Promise<DocumentationIssue[]>
|
|
1220
|
+
```
|
|
1221
|
+
|
|
1222
|
+
Use this to scan a pull request for documentation issues — missing docstrings, undocumented parameters, or incomplete return type descriptions — and get a structured list of problems to act on.
|
|
1223
|
+
|
|
1224
|
+
Accepts a `PRCommentConfig` object describing the GitHub PR to analyze, plus optional flags to control analysis depth. Returns a list of `DocumentationIssue` objects, each describing a specific documentation problem found in the PR's changed files.
|
|
1225
|
+
|
|
1226
|
+
### Parameters
|
|
1227
|
+
|
|
1228
|
+
| Name | Type | Required | Description
|
|
1229
|
+
|
|
1230
|
+
**Example:**
|
|
1231
|
+
```typescript
|
|
1232
|
+
// --- Inline types (do not import from autodocs) ---
|
|
1233
|
+
type PRCommentConfig = {
|
|
1234
|
+
token?: string
|
|
1235
|
+
owner: string
|
|
1236
|
+
repo: string
|
|
1237
|
+
prNumber: number
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
type DocumentationIssue = {
|
|
1241
|
+
file: string
|
|
1242
|
+
line: number
|
|
1243
|
+
severity: 'error' | 'warning' | 'info'
|
|
1244
|
+
message: string
|
|
1245
|
+
rule: string
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
// --- Simulated
|
|
1249
|
+
```
|
|
1250
|
+
|
|
1251
|
+
### AnthropicClient
|
|
1252
|
+
|
|
1253
|
+
**Type:** class
|
|
1254
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/anthropic-client.ts
|
|
1255
|
+
|
|
1256
|
+
```
|
|
1257
|
+
class AnthropicClient implements LLMClient
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
Use this to send completion requests to Anthropic's Claude models with automatic retry logic and a standardized LLM interface.
|
|
1261
|
+
|
|
1262
|
+
`AnthropicClient` wraps the Anthropic SDK and implements the `LLMClient` interface, giving you a consistent way to interact with Claude models alongside other LLM providers in your application.
|
|
1263
|
+
|
|
1264
|
+
## Constructor Parameters
|
|
1265
|
+
|
|
1266
|
+
| Name | Type | Required | Description |
|
|
1267
|
+
|------|------|----------|-------------|
|
|
1268
|
+
| `config.model` | `string` | Yes | The Claude model to use (e.g. `"
|
|
1269
|
+
|
|
1270
|
+
**Example:**
|
|
1271
|
+
```typescript
|
|
1272
|
+
// ─── Inline types (no imports from autodocs) ───────────────────────────────
|
|
1273
|
+
|
|
1274
|
+
type LLMProvider = 'anthropic' | 'openai' | 'gemini'
|
|
1275
|
+
|
|
1276
|
+
interface LLMClientConfig {
|
|
1277
|
+
model: string
|
|
1278
|
+
maxRetries?: number
|
|
1279
|
+
apiKey?: string
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
interface CompletionRequest {
|
|
1283
|
+
messages: Array<{ role: 'user' | 'assistant'; c
|
|
1284
|
+
```
|
|
1285
|
+
|
|
1286
|
+
### constructor
|
|
1287
|
+
|
|
1288
|
+
**Type:** method
|
|
1289
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/anthropic-client.ts
|
|
1290
|
+
|
|
1291
|
+
```
|
|
1292
|
+
constructor(config: LLMClientConfig)
|
|
1293
|
+
```
|
|
1294
|
+
|
|
1295
|
+
Use this to create an Anthropic-backed LLM client for sending completion requests, with built-in retry logic and model configuration.
|
|
1296
|
+
|
|
1297
|
+
The `AnthropicClient` constructor initializes a client that wraps the Anthropic SDK, binding it to a specific model and API key. It defaults to 3 retries on failure unless overridden.
|
|
1298
|
+
|
|
1299
|
+
### Parameters
|
|
1300
|
+
|
|
1301
|
+
| Name | Type | Required | Description |
|
|
1302
|
+
|------|------|----------|-------------|
|
|
1303
|
+
| `config` | `LLMClientConfig` | ✅ | Configuration object for the client |
|
|
1304
|
+
| `conf
|
|
1305
|
+
|
|
1306
|
+
**Example:**
|
|
1307
|
+
```typescript
|
|
1308
|
+
// Inline types — no library imports needed
|
|
1309
|
+
type LLMProvider = 'anthropic' | 'openai'
|
|
1310
|
+
|
|
1311
|
+
interface LLMClientConfig {
|
|
1312
|
+
apiKey: string
|
|
1313
|
+
model: string
|
|
1314
|
+
maxRetries?: number
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
interface CompletionRequest {
|
|
1318
|
+
prompt: string
|
|
1319
|
+
maxTokens?: number
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
interface CompletionResponse {
|
|
1323
|
+
text: string
|
|
1324
|
+
model: s
|
|
1325
|
+
```
|
|
1326
|
+
|
|
1327
|
+
### isConfigured
|
|
1328
|
+
|
|
1329
|
+
**Type:** method
|
|
1330
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/anthropic-client.ts
|
|
1331
|
+
|
|
1332
|
+
```
|
|
1333
|
+
isConfigured(): boolean
|
|
1334
|
+
```
|
|
1335
|
+
|
|
1336
|
+
Use this to verify that an `AnthropicClient` instance is ready to make API calls before attempting completions.
|
|
1337
|
+
|
|
1338
|
+
This method acts as a readiness check — it confirms the client has been initialized and the underlying Anthropic SDK has taken responsibility for credential validation. Call it as a guard before submitting requests in workflows where client configuration may be conditional or deferred.
|
|
1339
|
+
|
|
1340
|
+
**Returns**
|
|
1341
|
+
|
|
1342
|
+
| Value | Condition |
|
|
1343
|
+
|-------|-----------|
|
|
1344
|
+
| `true` | Always — the client is initiali
|
|
1345
|
+
|
|
1346
|
+
**Example:**
|
|
1347
|
+
```typescript
|
|
1348
|
+
// Inline types to simulate AnthropicClient behavior
|
|
1349
|
+
interface LLMClientConfig {
|
|
1350
|
+
apiKey: string
|
|
1351
|
+
model?: string
|
|
1352
|
+
timeout?: number
|
|
1353
|
+
maxRetries?: number
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// Simulated AnthropicClient class
|
|
1357
|
+
class AnthropicClient {
|
|
1358
|
+
private apiKey: string
|
|
1359
|
+
private model: string
|
|
1360
|
+
private timeout: number
|
|
1361
|
+
priva
|
|
1362
|
+
```
|
|
1363
|
+
|
|
1364
|
+
### complete
|
|
1365
|
+
|
|
1366
|
+
**Type:** method
|
|
1367
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/anthropic-client.ts
|
|
1368
|
+
|
|
1369
|
+
```
|
|
1370
|
+
async complete(request: CompletionRequest): Promise<CompletionResponse>
|
|
1371
|
+
```
|
|
1372
|
+
|
|
1373
|
+
Use this to send a conversation to Anthropic's Claude models and receive a completion response, handling system prompts and multi-turn message history automatically.
|
|
1374
|
+
|
|
1375
|
+
This method separates system messages from conversation messages internally, so you can pass a unified message array without pre-processing. It falls back to the client's default model if none is specified in the request.
|
|
1376
|
+
|
|
1377
|
+
## Parameters
|
|
1378
|
+
|
|
1379
|
+
| Name | Type | Required | Description |
|
|
1380
|
+
|------|------|----------|-------------|
|
|
1381
|
+
| `request` |
|
|
1382
|
+
|
|
1383
|
+
**Example:**
|
|
1384
|
+
```typescript
|
|
1385
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
1386
|
+
|
|
1387
|
+
type MessageRole = 'system' | 'user' | 'assistant'
|
|
1388
|
+
|
|
1389
|
+
interface Message {
|
|
1390
|
+
role: MessageRole
|
|
1391
|
+
content: string
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
interface CompletionRequest {
|
|
1395
|
+
messages: Message[]
|
|
1396
|
+
model?: string
|
|
1397
|
+
maxTokens?: number
|
|
1398
|
+
temperature?: n
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
### createLLMClient
|
|
1402
|
+
|
|
1403
|
+
**Type:** function
|
|
1404
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/index.ts
|
|
1405
|
+
|
|
1406
|
+
```
|
|
1407
|
+
function createLLMClient(config: {
|
|
1408
|
+
provider: LLMProvider
|
|
1409
|
+
model: string
|
|
1410
|
+
baseUrl?: string
|
|
1411
|
+
timeout?: number
|
|
1412
|
+
maxRetries?: number
|
|
1413
|
+
}): LLMClient
|
|
1414
|
+
```
|
|
1415
|
+
|
|
1416
|
+
Use this to initialize a typed LLM client for a specific AI provider (OpenAI, Anthropic, etc.) with retry and timeout handling built in.
|
|
1417
|
+
|
|
1418
|
+
This is your entry point for all LLM interactions — call it once at startup and reuse the returned `LLMClient` throughout your application.
|
|
1419
|
+
|
|
1420
|
+
## Parameters
|
|
1421
|
+
|
|
1422
|
+
| Name | Type | Required | Description |
|
|
1423
|
+
|------|------|----------|-------------|
|
|
1424
|
+
| `config.provider` | `LLMProvider` | ✅ Yes | The AI provider to use. Accepted values: `"openai"`, `"anthropic"`, `"azure"`
|
|
1425
|
+
|
|
1426
|
+
**Example:**
|
|
1427
|
+
```typescript
|
|
1428
|
+
// --- Inline types (do not import from autodocs) ---
|
|
1429
|
+
type LLMProvider = "openai" | "anthropic" | "azure"
|
|
1430
|
+
|
|
1431
|
+
interface LLMClientConfig {
|
|
1432
|
+
provider: LLMProvider
|
|
1433
|
+
model: string
|
|
1434
|
+
baseUrl?: string
|
|
1435
|
+
timeout?: number
|
|
1436
|
+
maxRetries?: number
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
interface ChatMessage {
|
|
1440
|
+
role: "user" | "assistant" | "system
|
|
1441
|
+
```
|
|
1442
|
+
|
|
1443
|
+
### generateDocumentation
|
|
1444
|
+
|
|
1445
|
+
**Type:** function
|
|
1446
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/index.ts
|
|
1447
|
+
|
|
1448
|
+
```
|
|
1449
|
+
async function generateDocumentation(client: LLMClient, element: ElementContext, options?: { multiLanguage?: boolean }): Promise<GeneratedDocResult>
|
|
1450
|
+
```
|
|
1451
|
+
|
|
1452
|
+
Use this to automatically generate documentation for a code element (function, class, method, etc.) using an LLM client, with optional multi-language support.
|
|
1453
|
+
|
|
1454
|
+
Takes a configured LLM client and a code element's context, then returns structured documentation output — useful for automating doc generation pipelines or IDE tooling.
|
|
1455
|
+
|
|
1456
|
+
### Parameters
|
|
1457
|
+
|
|
1458
|
+
| Name | Type | Required | Description |
|
|
1459
|
+
|------|------|----------|-------------|
|
|
1460
|
+
| `client` | `LLMClient` | ✅ Yes | A configured LLM client instance (e.
|
|
1461
|
+
|
|
1462
|
+
**Example:**
|
|
1463
|
+
```typescript
|
|
1464
|
+
// ── Inline type definitions (no external imports needed) ──────────────────────
|
|
1465
|
+
|
|
1466
|
+
type ElementKind = 'function' | 'class' | 'method' | 'interface'
|
|
1467
|
+
|
|
1468
|
+
interface ElementContext {
|
|
1469
|
+
name: string
|
|
1470
|
+
kind: ElementKind
|
|
1471
|
+
signature: string
|
|
1472
|
+
sourceCode: string
|
|
1473
|
+
filePath: string
|
|
1474
|
+
language: string
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
interfa
|
|
1478
|
+
```
|
|
1479
|
+
|
|
1480
|
+
### fixCodeSample
|
|
1481
|
+
|
|
1482
|
+
**Type:** function
|
|
1483
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/index.ts
|
|
1484
|
+
|
|
1485
|
+
```
|
|
1486
|
+
async function fixCodeSample(client: LLMClient, code: string, error: string, context: string, iteration: number = 1): Promise<string>
|
|
1487
|
+
```
|
|
1488
|
+
|
|
1489
|
+
Use this to automatically repair broken code samples by sending them to an LLM with the error context and receiving a corrected version. Ideal for iterative code generation pipelines where generated code fails validation or execution.
|
|
1490
|
+
|
|
1491
|
+
## Parameters
|
|
1492
|
+
|
|
1493
|
+
| Name | Type | Required | Description |
|
|
1494
|
+
|------|------|----------|-------------|
|
|
1495
|
+
| `client` | `LLMClient` | Yes | An initialized LLM client instance used to send the fix request |
|
|
1496
|
+
| `code` | `string` | Yes | The broken code sample that needs to be
|
|
1497
|
+
|
|
1498
|
+
**Example:**
|
|
1499
|
+
```typescript
|
|
1500
|
+
// --- Inline types (do not import from autodocs) ---
|
|
1501
|
+
interface LLMMessage {
|
|
1502
|
+
role: 'system' | 'user' | 'assistant'
|
|
1503
|
+
content: string
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
interface LLMClient {
|
|
1507
|
+
complete(messages: LLMMessage[]): Promise<string>
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// --- Inline implementation of fixCodeSample ---
|
|
1511
|
+
async function fixCodeSample(
|
|
1512
|
+
cli
|
|
1513
|
+
```
|
|
1514
|
+
|
|
1515
|
+
### OpenAICompatibleClient
|
|
1516
|
+
|
|
1517
|
+
**Type:** class
|
|
1518
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/openai-client.ts
|
|
1519
|
+
|
|
1520
|
+
```
|
|
1521
|
+
class OpenAICompatibleClient implements LLMClient
|
|
1522
|
+
```
|
|
1523
|
+
|
|
1524
|
+
Use this to connect to any OpenAI-compatible LLM provider — including OpenAI, DeepSeek, Ollama, OpenRouter, and Google Gemini — through a single unified client interface.
|
|
1525
|
+
|
|
1526
|
+
`OpenAICompatibleClient` normalizes provider differences (base URLs, auth headers, retry logic) so you can swap providers without changing your application code.
|
|
1527
|
+
|
|
1528
|
+
## Constructor Config
|
|
1529
|
+
|
|
1530
|
+
| Name | Type | Required | Description |
|
|
1531
|
+
|------|------|----------|-------------|
|
|
1532
|
+
| `provider` | `LLMProvider` | ✅ | Provider identifier (e.g.
|
|
1533
|
+
|
|
1534
|
+
### constructor
|
|
1535
|
+
|
|
1536
|
+
**Type:** method
|
|
1537
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/openai-client.ts
|
|
1538
|
+
|
|
1539
|
+
```
|
|
1540
|
+
constructor(config: LLMClientConfig)
|
|
1541
|
+
```
|
|
1542
|
+
|
|
1543
|
+
Use this to create a unified LLM client that connects to any OpenAI-compatible API provider (OpenAI, Anthropic, Mistral, local models, etc.) with automatic retry logic and provider-specific configuration.
|
|
1544
|
+
|
|
1545
|
+
## Parameters
|
|
1546
|
+
|
|
1547
|
+
| Name | Type | Required | Description |
|
|
1548
|
+
|------|------|----------|-------------|
|
|
1549
|
+
| `config` | `LLMClientConfig` | Yes | Configuration object for the LLM client |
|
|
1550
|
+
| `config.provider` | `LLMProvider` | Yes | The LLM provider identifier (e.g., `'openai'`, `'mistral'`, `'anthropic'
|
|
1551
|
+
|
|
1552
|
+
**Example:**
|
|
1553
|
+
```typescript
|
|
1554
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
1555
|
+
|
|
1556
|
+
type LLMProvider = 'openai' | 'mistral' | 'anthropic' | 'local'
|
|
1557
|
+
|
|
1558
|
+
interface LLMClientConfig {
|
|
1559
|
+
provider: LLMProvider
|
|
1560
|
+
model: string
|
|
1561
|
+
apiKey: string
|
|
1562
|
+
baseUrl?: string
|
|
1563
|
+
maxRetries?: number
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
const PROVIDER_BASE_URLS:
|
|
1567
|
+
```
|
|
1568
|
+
|
|
1569
|
+
### isConfigured
|
|
1570
|
+
|
|
1571
|
+
**Type:** method
|
|
1572
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/openai-client.ts
|
|
1573
|
+
|
|
1574
|
+
```
|
|
1575
|
+
isConfigured(): boolean
|
|
1576
|
+
```
|
|
1577
|
+
|
|
1578
|
+
Use this to verify that an `OpenAICompatibleClient` instance is ready to make API calls before attempting completions.
|
|
1579
|
+
|
|
1580
|
+
This method acts as a readiness check — it always returns `true` because the underlying OpenAI SDK handles API key validation and configuration errors at request time rather than at initialization. Use it in guard clauses or health checks to follow a consistent "is configured?" pattern across multiple LLM client types.
|
|
1581
|
+
|
|
1582
|
+
### Returns
|
|
1583
|
+
|
|
1584
|
+
| Condition | Value |
|
|
1585
|
+
|-----------|-------|
|
|
1586
|
+
|
|
|
1587
|
+
|
|
1588
|
+
**Example:**
|
|
1589
|
+
```typescript
|
|
1590
|
+
// Inline types to simulate the OpenAICompatibleClient behavior
|
|
1591
|
+
type LLMProvider = 'openai' | 'azure' | 'groq' | 'custom'
|
|
1592
|
+
|
|
1593
|
+
interface LLMClientConfig {
|
|
1594
|
+
apiKey: string
|
|
1595
|
+
provider: LLMProvider
|
|
1596
|
+
model?: string
|
|
1597
|
+
baseURL?: string
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// Simulated OpenAICompatibleClient
|
|
1601
|
+
class OpenAICompatibleClient {
|
|
1602
|
+
|
|
1603
|
+
```
|
|
1604
|
+
|
|
1605
|
+
### complete
|
|
1606
|
+
|
|
1607
|
+
**Type:** method
|
|
1608
|
+
**File:** /Users/debmukherjee/autodocs/src/llm/openai-client.ts
|
|
1609
|
+
|
|
1610
|
+
```
|
|
1611
|
+
async complete(request: CompletionRequest): Promise<CompletionResponse>
|
|
1612
|
+
```
|
|
1613
|
+
|
|
1614
|
+
Use this to send a chat completion request to any OpenAI-compatible API endpoint (OpenAI, Azure, Groq, Together AI, etc.) and receive a structured response with the generated text and token usage.
|
|
1615
|
+
|
|
1616
|
+
## Parameters
|
|
1617
|
+
|
|
1618
|
+
| Name | Type | Required | Description |
|
|
1619
|
+
|------|------|----------|-------------|
|
|
1620
|
+
| `request` | `CompletionRequest` | Yes | The completion request object containing messages, model, and generation settings |
|
|
1621
|
+
| `request.messages` | `Array<{role: string, content: string}>` | Yes | Convers
|
|
1622
|
+
|
|
1623
|
+
**Example:**
|
|
1624
|
+
```typescript
|
|
1625
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
1626
|
+
|
|
1627
|
+
type Message = { role: 'system' | 'user' | 'assistant'; content: string }
|
|
1628
|
+
|
|
1629
|
+
type CompletionRequest = {
|
|
1630
|
+
messages: Message[]
|
|
1631
|
+
model?: string
|
|
1632
|
+
temperature?: number
|
|
1633
|
+
maxTokens?: number
|
|
1634
|
+
systemPrompt?: string
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
type Com
|
|
1638
|
+
```
|
|
1639
|
+
|
|
1640
|
+
### PluginManager
|
|
1641
|
+
|
|
1642
|
+
**Type:** class
|
|
1643
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1644
|
+
|
|
1645
|
+
```
|
|
1646
|
+
class PluginManager
|
|
1647
|
+
```
|
|
1648
|
+
|
|
1649
|
+
Use this to load, register, and execute documentation plugins that transform or extend your build pipeline's source and output processing.
|
|
1650
|
+
|
|
1651
|
+
`PluginManager` orchestrates a collection of `SkryptPlugin` instances, providing each plugin with a shared context (paths, config, and a logger) so plugins can coordinate without direct coupling.
|
|
1652
|
+
|
|
1653
|
+
## Constructor Parameters
|
|
1654
|
+
|
|
1655
|
+
| Name | Type | Required | Description |
|
|
1656
|
+
|------|------|----------|-------------|
|
|
1657
|
+
| `sourcePath` | `string` | Yes | Absolute or relative
|
|
1658
|
+
|
|
1659
|
+
**Example:**
|
|
1660
|
+
```typescript
|
|
1661
|
+
// --- Inline types (no external imports needed) ---
|
|
1662
|
+
|
|
1663
|
+
type PluginContext = {
|
|
1664
|
+
sourcePath: string
|
|
1665
|
+
outputPath: string
|
|
1666
|
+
config: Record<string, unknown>
|
|
1667
|
+
logger: {
|
|
1668
|
+
info: (msg: string) => void
|
|
1669
|
+
warn: (msg: string) => void
|
|
1670
|
+
error: (msg: string) => void
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
type SkryptPlugin = {
|
|
1675
|
+
name: s
|
|
1676
|
+
```
|
|
1677
|
+
|
|
1678
|
+
### constructor
|
|
1679
|
+
|
|
1680
|
+
**Type:** method
|
|
1681
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1682
|
+
|
|
1683
|
+
```
|
|
1684
|
+
constructor(sourcePath: string, outputPath: string, config: Record<string, unknown> = {})
|
|
1685
|
+
```
|
|
1686
|
+
|
|
1687
|
+
Use this to initialize a `PluginManager` that coordinates documentation plugins, wiring together your source code directory, output destination, and any custom configuration options before plugins are registered and executed.
|
|
1688
|
+
|
|
1689
|
+
## Parameters
|
|
1690
|
+
|
|
1691
|
+
| Name | Type | Required | Description |
|
|
1692
|
+
|------|------|----------|-------------|
|
|
1693
|
+
| `sourcePath` | `string` | ✅ Yes | Absolute or relative path to the source code directory to be documented |
|
|
1694
|
+
| `outputPath` | `string` | ✅ Yes | Absolute or relative path to t
|
|
1695
|
+
|
|
1696
|
+
**Example:**
|
|
1697
|
+
```typescript
|
|
1698
|
+
// --- Inline types (mirroring autodocs internals) ---
|
|
1699
|
+
type Logger = {
|
|
1700
|
+
info: (msg: string) => void
|
|
1701
|
+
warn: (msg: string) => void
|
|
1702
|
+
error: (msg: string) => void
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
type PluginContext = {
|
|
1706
|
+
sourcePath: string
|
|
1707
|
+
outputPath: string
|
|
1708
|
+
config: Record<string, unknown>
|
|
1709
|
+
logger: Logger
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
type SkryptPlugi
|
|
1713
|
+
```
|
|
1714
|
+
|
|
1715
|
+
### loadPlugins
|
|
1716
|
+
|
|
1717
|
+
**Type:** method
|
|
1718
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1719
|
+
|
|
1720
|
+
```
|
|
1721
|
+
async loadPlugins(configPath?: string): Promise<void>
|
|
1722
|
+
```
|
|
1723
|
+
|
|
1724
|
+
Use this to initialize and load plugins into a `PluginManager` instance from a configuration file, enabling dynamic plugin discovery at startup.
|
|
1725
|
+
|
|
1726
|
+
This method reads from a `skrypt.config.js` or `skrypt.config.ts` file (auto-detected if no path is provided) and registers all declared plugins into the manager. Call it once during application bootstrap before executing any plugin-dependent logic.
|
|
1727
|
+
|
|
1728
|
+
### Parameters
|
|
1729
|
+
|
|
1730
|
+
| Name | Type | Required | Description |
|
|
1731
|
+
|------|------|----------|-------------|
|
|
1732
|
+
| `co
|
|
1733
|
+
|
|
1734
|
+
**Example:**
|
|
1735
|
+
```typescript
|
|
1736
|
+
// Inline types to simulate PluginManager behavior
|
|
1737
|
+
type Logger = {
|
|
1738
|
+
info: (msg: string) => void
|
|
1739
|
+
error: (msg: string) => void
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
type Plugin = {
|
|
1743
|
+
name: string
|
|
1744
|
+
setup: () => void
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
type PluginConfig = {
|
|
1748
|
+
plugins: Plugin[]
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
// Simulated PluginManager class (self-contained, no external imports)
|
|
1752
|
+
```
|
|
1753
|
+
|
|
1754
|
+
### register
|
|
1755
|
+
|
|
1756
|
+
**Type:** method
|
|
1757
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1758
|
+
|
|
1759
|
+
```
|
|
1760
|
+
register(plugin: SkryptPlugin): void
|
|
1761
|
+
```
|
|
1762
|
+
|
|
1763
|
+
Use this to manually register a plugin with the `PluginManager`, adding it to the active plugin list so its hooks can be executed during the build or runtime lifecycle.
|
|
1764
|
+
|
|
1765
|
+
This is the programmatic alternative to loading plugins from disk — ideal for built-in plugins, testing, or dynamically constructed plugin objects.
|
|
1766
|
+
|
|
1767
|
+
### Parameters
|
|
1768
|
+
|
|
1769
|
+
| Name | Type | Required | Description |
|
|
1770
|
+
|------|------|----------|-------------|
|
|
1771
|
+
| `plugin` | `SkryptPlugin` | ✅ Yes | The plugin object to register. Must have at l
|
|
1772
|
+
|
|
1773
|
+
**Example:**
|
|
1774
|
+
```typescript
|
|
1775
|
+
// Inline type definitions (no external imports needed)
|
|
1776
|
+
type SkryptPlugin = {
|
|
1777
|
+
name: string
|
|
1778
|
+
version?: string
|
|
1779
|
+
onBuildStart?: (...args: unknown[]) => unknown
|
|
1780
|
+
onBuildEnd?: (...args: unknown[]) => unknown
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// Inline PluginManager implementation
|
|
1784
|
+
class PluginManager {
|
|
1785
|
+
private plugins: SkryptPlu
|
|
1786
|
+
```
|
|
1787
|
+
|
|
1788
|
+
### runHook
|
|
1789
|
+
|
|
1790
|
+
**Type:** method
|
|
1791
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1792
|
+
|
|
1793
|
+
```
|
|
1794
|
+
async runHook<T>(hook: keyof SkryptPlugin, ...args: unknown[]): Promise<T | undefined>
|
|
1795
|
+
```
|
|
1796
|
+
|
|
1797
|
+
Use this to execute a named hook across all registered plugins in sequence, passing data through each plugin's implementation of that hook. This enables a plugin pipeline where each plugin can transform or augment the result before passing it to the next.
|
|
1798
|
+
|
|
1799
|
+
**Parameters**
|
|
1800
|
+
|
|
1801
|
+
| Name | Type | Required | Description |
|
|
1802
|
+
|------|------|----------|-------------|
|
|
1803
|
+
| `hook` | `keyof SkryptPlugin` | Yes | The name of the hook method to invoke on each registered plugin (e.g., `'beforeCompile'`, `'afterCompile'
|
|
1804
|
+
|
|
1805
|
+
**Example:**
|
|
1806
|
+
```typescript
|
|
1807
|
+
// --- Inline types (do not import from autodocs) ---
|
|
1808
|
+
interface SkryptPlugin {
|
|
1809
|
+
name: string
|
|
1810
|
+
version?: string
|
|
1811
|
+
beforeCompile?: (...args: unknown[]) => Promise<string> | string
|
|
1812
|
+
afterCompile?: (...args: unknown[]) => Promise<string> | string
|
|
1813
|
+
transform?: (...args: unknown[]) => Promise<string>
|
|
1814
|
+
```
|
|
1815
|
+
|
|
1816
|
+
### onInit
|
|
1817
|
+
|
|
1818
|
+
**Type:** method
|
|
1819
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1820
|
+
|
|
1821
|
+
```
|
|
1822
|
+
async onInit(): Promise<void>
|
|
1823
|
+
```
|
|
1824
|
+
|
|
1825
|
+
Use this to trigger the initialization lifecycle hook across all registered plugins in a `PluginManager` instance — typically called once at application startup before any scanning or processing begins.
|
|
1826
|
+
|
|
1827
|
+
When invoked, `onInit` runs the `'onInit'` hook on every registered plugin that implements it, allowing plugins to set up connections, load configuration, or prepare internal state.
|
|
1828
|
+
|
|
1829
|
+
## Parameters
|
|
1830
|
+
|
|
1831
|
+
This method takes no parameters.
|
|
1832
|
+
|
|
1833
|
+
## Returns
|
|
1834
|
+
|
|
1835
|
+
| Type | Description |
|
|
1836
|
+
|------|-------------|
|
|
1837
|
+
| `Pro
|
|
1838
|
+
|
|
1839
|
+
**Example:**
|
|
1840
|
+
```typescript
|
|
1841
|
+
// Inline types — no external imports needed
|
|
1842
|
+
type PluginHook = () => Promise<void>
|
|
1843
|
+
|
|
1844
|
+
interface Plugin {
|
|
1845
|
+
name: string
|
|
1846
|
+
onInit?: PluginHook
|
|
1847
|
+
onBeforeScan?: PluginHook
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
// Simulated PluginManager class matching the real implementation's behavior
|
|
1851
|
+
class PluginManager {
|
|
1852
|
+
private plugins: Plugin[] =
|
|
1853
|
+
```
|
|
1854
|
+
|
|
1855
|
+
### onBeforeScan
|
|
1856
|
+
|
|
1857
|
+
**Type:** method
|
|
1858
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1859
|
+
|
|
1860
|
+
```
|
|
1861
|
+
async onBeforeScan(): Promise<void>
|
|
1862
|
+
```
|
|
1863
|
+
|
|
1864
|
+
Use this to trigger all registered plugins' `onBeforeScan` lifecycle hook — ideal for running pre-scan setup logic (e.g., clearing caches, validating config, preparing output directories) before your autodocs scan begins.
|
|
1865
|
+
|
|
1866
|
+
This method iterates over every loaded plugin and calls their `onBeforeScan` handler in sequence. It resolves when all hooks have completed, making it safe to `await` before starting a scan.
|
|
1867
|
+
|
|
1868
|
+
### Parameters
|
|
1869
|
+
|
|
1870
|
+
_None_
|
|
1871
|
+
|
|
1872
|
+
### Returns
|
|
1873
|
+
|
|
1874
|
+
| Type | Description |
|
|
1875
|
+
|------|-------------|
|
|
1876
|
+
|
|
|
1877
|
+
|
|
1878
|
+
**Example:**
|
|
1879
|
+
```typescript
|
|
1880
|
+
// Inline types to simulate the PluginManager behavior
|
|
1881
|
+
type Plugin = {
|
|
1882
|
+
name: string
|
|
1883
|
+
onBeforeScan?: () => Promise<void>
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
// Simulated PluginManager class (self-contained, no external imports)
|
|
1887
|
+
class PluginManager {
|
|
1888
|
+
private plugins: Plugin[]
|
|
1889
|
+
|
|
1890
|
+
constructor(plugins: Plugin[]) {
|
|
1891
|
+
this.plugins
|
|
1892
|
+
```
|
|
1893
|
+
|
|
1894
|
+
### onAfterScan
|
|
1895
|
+
|
|
1896
|
+
**Type:** method
|
|
1897
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1898
|
+
|
|
1899
|
+
```
|
|
1900
|
+
async onAfterScan<T>(elements: T[]): Promise<T[]>
|
|
1901
|
+
```
|
|
1902
|
+
|
|
1903
|
+
Use this to run all registered plugins' `onAfterScan` hooks against a list of scanned elements, allowing plugins to filter, transform, or enrich the results before further processing.
|
|
1904
|
+
|
|
1905
|
+
This is called automatically by `PluginManager` after the scan phase completes. Each plugin that implements `onAfterScan` gets a chance to modify the elements array in sequence. If no plugin modifies the elements, the original array is returned unchanged.
|
|
1906
|
+
|
|
1907
|
+
## Parameters
|
|
1908
|
+
|
|
1909
|
+
| Name | Type | Required | Description |
|
|
1910
|
+
|-
|
|
1911
|
+
|
|
1912
|
+
**Example:**
|
|
1913
|
+
```typescript
|
|
1914
|
+
// Inline types to simulate PluginManager behavior
|
|
1915
|
+
type Plugin = {
|
|
1916
|
+
name: string
|
|
1917
|
+
onAfterScan?: <T>(elements: T[]) => Promise<T[]> | T[]
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
type ScannedFile = {
|
|
1921
|
+
path: string
|
|
1922
|
+
exported: boolean
|
|
1923
|
+
tags: string[]
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
// Simulated PluginManager with onAfterScan
|
|
1927
|
+
class PluginManager {
|
|
1928
|
+
private plugin
|
|
1929
|
+
```
|
|
1930
|
+
|
|
1931
|
+
### onBeforeGenerate
|
|
1932
|
+
|
|
1933
|
+
**Type:** method
|
|
1934
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1935
|
+
|
|
1936
|
+
```
|
|
1937
|
+
async onBeforeGenerate<T>(elements: T[]): Promise<T[]>
|
|
1938
|
+
```
|
|
1939
|
+
|
|
1940
|
+
Use this to run all registered plugins' `onBeforeGenerate` hooks against a collection of elements before documentation generation begins. This is the last chance to filter, transform, enrich, or reorder elements before the generation pipeline processes them.
|
|
1941
|
+
|
|
1942
|
+
If no plugin modifies the elements (or no plugins are registered), the original array is returned unchanged.
|
|
1943
|
+
|
|
1944
|
+
### Parameters
|
|
1945
|
+
|
|
1946
|
+
| Name | Type | Required | Description |
|
|
1947
|
+
|------|------|----------|-------------|
|
|
1948
|
+
| `elements` | `T[]` | Yes | The
|
|
1949
|
+
|
|
1950
|
+
**Example:**
|
|
1951
|
+
```typescript
|
|
1952
|
+
// Inline types — no external imports needed
|
|
1953
|
+
type HookName = 'onBeforeGenerate' | 'onAfterGenerate' | 'onAfterScan'
|
|
1954
|
+
|
|
1955
|
+
interface Plugin {
|
|
1956
|
+
name: string
|
|
1957
|
+
onBeforeGenerate?: <T>(elements: T[]) => Promise<T[]>
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
interface DocElement {
|
|
1961
|
+
name: string
|
|
1962
|
+
kind: 'function' | 'class' | 'interface'
|
|
1963
|
+
isInter
|
|
1964
|
+
```
|
|
1965
|
+
|
|
1966
|
+
### onAfterGenerate
|
|
1967
|
+
|
|
1968
|
+
**Type:** method
|
|
1969
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
1970
|
+
|
|
1971
|
+
```
|
|
1972
|
+
async onAfterGenerate<T>(docs: T[]): Promise<T[]>
|
|
1973
|
+
```
|
|
1974
|
+
|
|
1975
|
+
Use this to run all registered plugins' `onAfterGenerate` hooks against a set of generated documentation objects, allowing plugins to transform, filter, or enrich docs immediately after generation but before they are written to disk.
|
|
1976
|
+
|
|
1977
|
+
This is the second lifecycle hook in the documentation pipeline:
|
|
1978
|
+
1. `onBeforeGenerate` → elements are prepared
|
|
1979
|
+
2. **`onAfterGenerate`** → generated docs are post-processed ← you are here
|
|
1980
|
+
3. `onBeforeWrite` → docs are finalized before writing
|
|
1981
|
+
|
|
1982
|
+
If no plugin hook modi
|
|
1983
|
+
|
|
1984
|
+
**Example:**
|
|
1985
|
+
```typescript
|
|
1986
|
+
// Inline types to simulate the PluginManager behavior
|
|
1987
|
+
type Hook<T> = (data: T) => Promise<T> | T
|
|
1988
|
+
|
|
1989
|
+
interface Plugin {
|
|
1990
|
+
onAfterGenerate?: Hook<any[]>
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
interface GeneratedDoc {
|
|
1994
|
+
id: string
|
|
1995
|
+
title: string
|
|
1996
|
+
content: string
|
|
1997
|
+
tags?: string[]
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
// Simulated PluginManager with onAfterGenerate suppor
|
|
2001
|
+
```
|
|
2002
|
+
|
|
2003
|
+
### onBeforeWrite
|
|
2004
|
+
|
|
2005
|
+
**Type:** method
|
|
2006
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
2007
|
+
|
|
2008
|
+
```
|
|
2009
|
+
async onBeforeWrite<T>(docs: T[]): Promise<T[]>
|
|
2010
|
+
```
|
|
2011
|
+
|
|
2012
|
+
Use this to run all registered plugins' `onBeforeWrite` hooks against your generated docs array, allowing plugins to transform, filter, or enrich documents just before they are written to disk.
|
|
2013
|
+
|
|
2014
|
+
This is the last opportunity in the pipeline to mutate documentation objects before persistence. Each plugin in the manager can modify the array; if no plugin handles the hook, the original array is returned unchanged.
|
|
2015
|
+
|
|
2016
|
+
### Parameters
|
|
2017
|
+
|
|
2018
|
+
| Name | Type | Required | Description |
|
|
2019
|
+
|------|------|----------|--
|
|
2020
|
+
|
|
2021
|
+
**Example:**
|
|
2022
|
+
```typescript
|
|
2023
|
+
// Inline types to keep example self-contained
|
|
2024
|
+
type Doc = {
|
|
2025
|
+
id: string
|
|
2026
|
+
title: string
|
|
2027
|
+
content: string
|
|
2028
|
+
slug?: string
|
|
2029
|
+
writtenAt?: string
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
type Hook = 'onBeforeWrite' | 'onAfterGenerate' | 'onAfterWrite'
|
|
2033
|
+
|
|
2034
|
+
type Plugin = {
|
|
2035
|
+
name: string
|
|
2036
|
+
hooks?: Partial<Record<Hook, (data: unknown) => unknow
|
|
2037
|
+
```
|
|
2038
|
+
|
|
2039
|
+
### onAfterWrite
|
|
2040
|
+
|
|
2041
|
+
**Type:** method
|
|
2042
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
2043
|
+
|
|
2044
|
+
```
|
|
2045
|
+
async onAfterWrite(): Promise<void>
|
|
2046
|
+
```
|
|
2047
|
+
|
|
2048
|
+
Use this to trigger all registered plugin hooks after documentation has been written to disk — ideal for post-write tasks like cache invalidation, notifications, or cleanup.
|
|
2049
|
+
|
|
2050
|
+
`onAfterWrite` runs through every loaded plugin's `onAfterWrite` hook in sequence. It resolves when all hooks complete and does not return a value. If no plugins define this hook, it resolves immediately.
|
|
2051
|
+
|
|
2052
|
+
### Parameters
|
|
2053
|
+
|
|
2054
|
+
This method takes no parameters.
|
|
2055
|
+
|
|
2056
|
+
### Returns
|
|
2057
|
+
|
|
2058
|
+
| Type | Description |
|
|
2059
|
+
|------|-------------|
|
|
2060
|
+
| `Promise
|
|
2061
|
+
|
|
2062
|
+
**Example:**
|
|
2063
|
+
```typescript
|
|
2064
|
+
// Inline types to keep example self-contained
|
|
2065
|
+
type Hook = (...args: unknown[]) => Promise<unknown>
|
|
2066
|
+
|
|
2067
|
+
interface Plugin {
|
|
2068
|
+
name: string
|
|
2069
|
+
hooks: Record<string, Hook>
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
// Simulated PluginManager with onAfterWrite
|
|
2073
|
+
class PluginManager {
|
|
2074
|
+
private plugins: Plugin[] = []
|
|
2075
|
+
|
|
2076
|
+
register(plugin: Plugin): voi
|
|
2077
|
+
```
|
|
2078
|
+
|
|
2079
|
+
### transformContent
|
|
2080
|
+
|
|
2081
|
+
**Type:** method
|
|
2082
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
2083
|
+
|
|
2084
|
+
```
|
|
2085
|
+
async transformContent(content: string, filePath: string): Promise<string>
|
|
2086
|
+
```
|
|
2087
|
+
|
|
2088
|
+
Use this to pipe file content through a chain of registered plugins, each of which can modify the content before it's written to disk.
|
|
2089
|
+
|
|
2090
|
+
`transformContent` iterates over all registered plugins in order, passing the current content string to each plugin's `transformContent` method. The output of each plugin becomes the input for the next, making it a sequential transformation pipeline. If a plugin doesn't implement `transformContent`, it is skipped.
|
|
2091
|
+
|
|
2092
|
+
## Parameters
|
|
2093
|
+
|
|
2094
|
+
| Name | Type | Required | Descr
|
|
2095
|
+
|
|
2096
|
+
**Example:**
|
|
2097
|
+
```typescript
|
|
2098
|
+
// Inline plugin interface — no external imports needed
|
|
2099
|
+
interface Plugin {
|
|
2100
|
+
name: string;
|
|
2101
|
+
transformContent?: (content: string, filePath: string) => Promise<string>;
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
// Inline PluginManager implementation
|
|
2105
|
+
class PluginManager {
|
|
2106
|
+
private plugins: Plugin[] = [];
|
|
2107
|
+
|
|
2108
|
+
register(plugin: Plugin): void
|
|
2109
|
+
```
|
|
2110
|
+
|
|
2111
|
+
### definePlugin
|
|
2112
|
+
|
|
2113
|
+
**Type:** function
|
|
2114
|
+
**File:** /Users/debmukherjee/autodocs/src/plugins/index.ts
|
|
2115
|
+
|
|
2116
|
+
```
|
|
2117
|
+
function definePlugin(plugin: SkryptPlugin): SkryptPlugin
|
|
2118
|
+
```
|
|
2119
|
+
|
|
2120
|
+
Use this to define a type-safe plugin configuration object for the Skrypt plugin system. This is an identity function that provides TypeScript type inference and autocompletion when authoring plugins, ensuring your plugin object conforms to the `SkryptPlugin` interface at compile time.
|
|
2121
|
+
|
|
2122
|
+
### Parameters
|
|
2123
|
+
|
|
2124
|
+
| Name | Type | Required | Description |
|
|
2125
|
+
|------|------|----------|-------------|
|
|
2126
|
+
| plugin | `SkryptPlugin` | ✅ | The plugin configuration object to validate and return |
|
|
2127
|
+
|
|
2128
|
+
### Returns
|
|
2129
|
+
|
|
2130
|
+
Returns the
|
|
2131
|
+
|
|
2132
|
+
**Example:**
|
|
2133
|
+
```typescript
|
|
2134
|
+
// Inline the SkryptPlugin type (do not import from autodocs)
|
|
2135
|
+
type SkryptPlugin = {
|
|
2136
|
+
name: string
|
|
2137
|
+
version?: string
|
|
2138
|
+
setup?: (context: Record<string, unknown>) => void | Promise<void>
|
|
2139
|
+
teardown?: () => void | Promise<void>
|
|
2140
|
+
hooks?: {
|
|
2141
|
+
beforeRun?: () => void
|
|
2142
|
+
afterRun?: (result: unknown) =
|
|
2143
|
+
```
|
|
2144
|
+
|
|
2145
|
+
### classifyElement
|
|
2146
|
+
|
|
2147
|
+
**Type:** function
|
|
2148
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/content-type.ts
|
|
2149
|
+
|
|
2150
|
+
```
|
|
2151
|
+
function classifyElement(element: APIElement): ContentClassification
|
|
2152
|
+
```
|
|
2153
|
+
|
|
2154
|
+
Use this to determine what type of documentation an API element needs — whether it should be documented as an API reference, a guide, or a tutorial — so you can route elements to the correct documentation generator automatically.
|
|
2155
|
+
|
|
2156
|
+
This function analyzes an `APIElement` and returns a `ContentClassification` indicating the most appropriate documentation style, along with reasoning scores and explanations for the decision.
|
|
2157
|
+
|
|
2158
|
+
## Parameters
|
|
2159
|
+
|
|
2160
|
+
| Name | Type | Required | Description |
|
|
2161
|
+
|------|------|----
|
|
2162
|
+
|
|
2163
|
+
**Example:**
|
|
2164
|
+
```typescript
|
|
2165
|
+
// ---- Inline types (do not import from autodocs) ----
|
|
2166
|
+
type APIElementKind = 'function' | 'class' | 'interface' | 'type' | 'variable' | 'enum'
|
|
2167
|
+
|
|
2168
|
+
interface APIElement {
|
|
2169
|
+
name: string
|
|
2170
|
+
kind: APIElementKind
|
|
2171
|
+
description?: string
|
|
2172
|
+
parameters?: { name: string; type: string; description?: string }[]
|
|
2173
|
+
|
|
2174
|
+
```
|
|
2175
|
+
|
|
2176
|
+
### classifyElements
|
|
2177
|
+
|
|
2178
|
+
**Type:** function
|
|
2179
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/content-type.ts
|
|
2180
|
+
|
|
2181
|
+
```
|
|
2182
|
+
function classifyElements(elements: APIElement[]): Map<ContentType, APIElement[]>
|
|
2183
|
+
```
|
|
2184
|
+
|
|
2185
|
+
Use this to sort a mixed list of documentation elements into typed groups — API references, guides, tutorials, and overviews — in a single pass.
|
|
2186
|
+
|
|
2187
|
+
Instead of manually filtering arrays for each content type, `classifyElements` returns a `Map` keyed by content type so you can immediately access any group by name.
|
|
2188
|
+
|
|
2189
|
+
### Parameters
|
|
2190
|
+
|
|
2191
|
+
| Name | Type | Required | Description |
|
|
2192
|
+
|------|------|----------|-------------|
|
|
2193
|
+
| `elements` | `APIElement[]` | ✅ | Array of documentation elements to classify. Each ele
|
|
2194
|
+
|
|
2195
|
+
**Example:**
|
|
2196
|
+
```typescript
|
|
2197
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
2198
|
+
|
|
2199
|
+
type ContentType = 'api' | 'guide' | 'tutorial' | 'overview'
|
|
2200
|
+
|
|
2201
|
+
interface APIElement {
|
|
2202
|
+
id: string
|
|
2203
|
+
title: string
|
|
2204
|
+
kind: ContentType
|
|
2205
|
+
tags?: string[]
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
// ── Inline implementation matching the real function's behavior
|
|
2209
|
+
```
|
|
2210
|
+
|
|
2211
|
+
### getRecommendedStructure
|
|
2212
|
+
|
|
2213
|
+
**Type:** function
|
|
2214
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/content-type.ts
|
|
2215
|
+
|
|
2216
|
+
```
|
|
2217
|
+
function getRecommendedStructure(elements: APIElement[]): {
|
|
2218
|
+
sections: { name: string; type: ContentType; elements: APIElement[] }[]
|
|
2219
|
+
stats: { api: number; guide: number; tutorial: number; overview: number }
|
|
2220
|
+
}
|
|
2221
|
+
```
|
|
2222
|
+
|
|
2223
|
+
Use this to automatically organize a list of API elements into a recommended documentation structure — grouping them into logical sections (API reference, guides, tutorials, overviews) and providing a count breakdown by content type.
|
|
2224
|
+
|
|
2225
|
+
This is ideal when you have a mixed set of API elements and want a ready-made layout for generating a documentation site or navigation structure.
|
|
2226
|
+
|
|
2227
|
+
## Parameters
|
|
2228
|
+
|
|
2229
|
+
| Name | Type | Required | Description |
|
|
2230
|
+
|------|------|----------|-------------|
|
|
2231
|
+
| `elements` | `APIEl
|
|
2232
|
+
|
|
2233
|
+
**Example:**
|
|
2234
|
+
```typescript
|
|
2235
|
+
// ── Inline types (no external imports needed) ──────────────────────────────
|
|
2236
|
+
|
|
2237
|
+
type ContentType = 'api' | 'guide' | 'tutorial' | 'overview'
|
|
2238
|
+
|
|
2239
|
+
type APIElement = {
|
|
2240
|
+
name: string
|
|
2241
|
+
kind: 'function' | 'class' | 'interface' | 'type' | 'variable' | 'module'
|
|
2242
|
+
description?: string
|
|
2243
|
+
tags?: string[]
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
typ
|
|
2247
|
+
```
|
|
2248
|
+
|
|
2249
|
+
### getPromptForContentType
|
|
2250
|
+
|
|
2251
|
+
**Type:** function
|
|
2252
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/content-type.ts
|
|
2253
|
+
|
|
2254
|
+
```
|
|
2255
|
+
function getPromptForContentType(type: ContentType): string
|
|
2256
|
+
```
|
|
2257
|
+
|
|
2258
|
+
Use this to get the appropriate documentation generation prompt string for a given content type, so you can pass the right instructions to an LLM when auto-generating docs for APIs, components, functions, or other code elements.
|
|
2259
|
+
|
|
2260
|
+
This function acts as a prompt router — given a content type identifier, it returns a tailored prompt string that instructs a documentation generator on what to include and how to format the output for that specific type.
|
|
2261
|
+
|
|
2262
|
+
### Parameters
|
|
2263
|
+
|
|
2264
|
+
| Name | Type | Required | Desc
|
|
2265
|
+
|
|
2266
|
+
**Example:**
|
|
2267
|
+
```typescript
|
|
2268
|
+
// Inline the ContentType definition — no external imports needed
|
|
2269
|
+
type ContentType = 'api' | 'component' | 'function' | 'class'
|
|
2270
|
+
|
|
2271
|
+
// Self-contained implementation matching the autodocs behavior
|
|
2272
|
+
function getPromptForContentType(type: ContentType): string {
|
|
2273
|
+
switch (type) {
|
|
2274
|
+
case 'api':
|
|
2275
|
+
retur
|
|
2276
|
+
```
|
|
2277
|
+
|
|
2278
|
+
### GoScanner
|
|
2279
|
+
|
|
2280
|
+
**Type:** class
|
|
2281
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/go.ts
|
|
2282
|
+
|
|
2283
|
+
```
|
|
2284
|
+
class GoScanner implements Scanner
|
|
2285
|
+
```
|
|
2286
|
+
|
|
2287
|
+
Use this to scan Go source files and extract API elements — functions, methods, structs, and interfaces — for automated documentation generation pipelines.
|
|
2288
|
+
|
|
2289
|
+
`GoScanner` implements the `Scanner` interface and targets `.go` files, automatically skipping test files (`_test.go`).
|
|
2290
|
+
|
|
2291
|
+
## Methods
|
|
2292
|
+
|
|
2293
|
+
### `canHandle(filePath: string): boolean`
|
|
2294
|
+
Returns `true` if the file path ends in `.go` and is not a test file. Use this to check compatibility before scanning.
|
|
2295
|
+
|
|
2296
|
+
### `scanFile(filePath: string): Promise<ScanRe
|
|
2297
|
+
|
|
2298
|
+
### canHandle
|
|
2299
|
+
|
|
2300
|
+
**Type:** method
|
|
2301
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/go.ts
|
|
2302
|
+
|
|
2303
|
+
```
|
|
2304
|
+
canHandle(filePath: string): boolean
|
|
2305
|
+
```
|
|
2306
|
+
|
|
2307
|
+
Use this to check whether a Go source file should be processed by the `GoScanner` — it returns `true` for `.go` files that are **not** test files (`_test.go`).
|
|
2308
|
+
|
|
2309
|
+
This is useful when routing files through a scanner pipeline, letting you skip unsupported or test files before attempting a full scan.
|
|
2310
|
+
|
|
2311
|
+
### Parameters
|
|
2312
|
+
|
|
2313
|
+
| Name | Type | Required | Description |
|
|
2314
|
+
|------|------|----------|-------------|
|
|
2315
|
+
| `filePath` | `string` | ✅ | Absolute or relative path to the file being evaluated |
|
|
2316
|
+
|
|
2317
|
+
### Returns
|
|
2318
|
+
|
|
2319
|
+
| Va
|
|
2320
|
+
|
|
2321
|
+
**Example:**
|
|
2322
|
+
```typescript
|
|
2323
|
+
// Inline implementation of GoScanner.canHandle for a self-contained example
|
|
2324
|
+
class GoScanner {
|
|
2325
|
+
languages = ['go']
|
|
2326
|
+
|
|
2327
|
+
canHandle(filePath: string): boolean {
|
|
2328
|
+
return /\.go$/.test(filePath) && !filePath.includes('_test.go')
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
const scanner = new GoScanner()
|
|
2333
|
+
|
|
2334
|
+
const testCases: Array<{ path: str
|
|
2335
|
+
```
|
|
2336
|
+
|
|
2337
|
+
### scanFile
|
|
2338
|
+
|
|
2339
|
+
**Type:** method
|
|
2340
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/go.ts
|
|
2341
|
+
|
|
2342
|
+
```
|
|
2343
|
+
async scanFile(filePath: string): Promise<ScanResult>
|
|
2344
|
+
```
|
|
2345
|
+
|
|
2346
|
+
Use this to extract API elements from a Go source file, returning all discovered functions, types, and parameters in a structured result.
|
|
2347
|
+
|
|
2348
|
+
`scanFile` reads and parses a `.go` file (excluding test files), identifying exported API elements and collecting any parse errors encountered during scanning.
|
|
2349
|
+
|
|
2350
|
+
> **Note:** Only handles non-test Go files (`.go` extension, not `_test.go`). Use `canHandle(filePath)` to verify compatibility before calling.
|
|
2351
|
+
|
|
2352
|
+
## Parameters
|
|
2353
|
+
|
|
2354
|
+
| Name | Type | Required | Description |
|
|
2355
|
+
|
|
2356
|
+
**Example:**
|
|
2357
|
+
```typescript
|
|
2358
|
+
import { readFileSync, writeFileSync, unlinkSync } from 'fs'
|
|
2359
|
+
import { tmpdir } from 'os'
|
|
2360
|
+
import { join } from 'path'
|
|
2361
|
+
|
|
2362
|
+
// --- Inline types (mirrors the real library's types) ---
|
|
2363
|
+
interface Parameter {
|
|
2364
|
+
name: string
|
|
2365
|
+
type: string
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
interface APIElement {
|
|
2369
|
+
name: string
|
|
2370
|
+
kind: 'function' | 'type' |
|
|
2371
|
+
```
|
|
2372
|
+
|
|
2373
|
+
### scanDirectory
|
|
2374
|
+
|
|
2375
|
+
**Type:** function
|
|
2376
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/index.ts
|
|
2377
|
+
|
|
2378
|
+
```
|
|
2379
|
+
async function scanDirectory(dir: string, options: ScanOptions = {}): Promise<ScanAllResult>
|
|
2380
|
+
```
|
|
2381
|
+
|
|
2382
|
+
Use this to recursively scan a directory (or single file) and extract all API elements — functions, classes, types, and exports — across multiple languages including Python, TypeScript, JavaScript, Go, and Rust.
|
|
2383
|
+
|
|
2384
|
+
## Parameters
|
|
2385
|
+
|
|
2386
|
+
| Name | Type | Required | Description |
|
|
2387
|
+
|------|------|----------|-------------|
|
|
2388
|
+
| `dir` | `string` | ✅ Yes | Path to the directory or single file to scan |
|
|
2389
|
+
| `options` | `ScanOptions` | ❌ No | Configuration options to control which files are included or excluded |
|
|
2390
|
+
| `op
|
|
2391
|
+
|
|
2392
|
+
### scanFile
|
|
2393
|
+
|
|
2394
|
+
**Type:** function
|
|
2395
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/index.ts
|
|
2396
|
+
|
|
2397
|
+
```
|
|
2398
|
+
async function scanFile(filePath: string): Promise<ScanResult>
|
|
2399
|
+
```
|
|
2400
|
+
|
|
2401
|
+
Use this to analyze a single source file and extract structured metadata — functions, classes, types, and other code constructs — without scanning an entire directory.
|
|
2402
|
+
|
|
2403
|
+
`scanFile` automatically detects the file's language, selects the appropriate scanner, and returns a normalized `ScanResult` regardless of whether the file is Python, TypeScript, or another supported language.
|
|
2404
|
+
|
|
2405
|
+
## Parameters
|
|
2406
|
+
|
|
2407
|
+
| Name | Type | Required | Description |
|
|
2408
|
+
|------|------|----------|-------------|
|
|
2409
|
+
| `filePath` | `string`
|
|
2410
|
+
|
|
2411
|
+
**Example:**
|
|
2412
|
+
```typescript
|
|
2413
|
+
// Inline types to simulate the autodocs ScanResult shape
|
|
2414
|
+
type FunctionInfo = {
|
|
2415
|
+
name: string
|
|
2416
|
+
signature: string
|
|
2417
|
+
docstring?: string
|
|
2418
|
+
lineStart: number
|
|
2419
|
+
lineEnd: number
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
type ClassInfo = {
|
|
2423
|
+
name: string
|
|
2424
|
+
methods: FunctionInfo[]
|
|
2425
|
+
lineStart: number
|
|
2426
|
+
lineEnd: number
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
type ScanResult = {
|
|
2430
|
+
|
|
2431
|
+
```
|
|
2432
|
+
|
|
2433
|
+
### PythonScanner
|
|
2434
|
+
|
|
2435
|
+
**Type:** class
|
|
2436
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python.ts
|
|
2437
|
+
|
|
2438
|
+
```
|
|
2439
|
+
class PythonScanner implements Scanner
|
|
2440
|
+
```
|
|
2441
|
+
|
|
2442
|
+
Use this to scan Python source files and extract structured metadata (functions, classes, imports, etc.) by delegating parsing to a Python3 subprocess.
|
|
2443
|
+
|
|
2444
|
+
`PythonScanner` implements the `Scanner` interface and is the go-to handler for any `.py` file in an autodocs pipeline. It spawns a `python3` process running an internal parser script and returns a `ScanResult` with the extracted symbols and structure.
|
|
2445
|
+
|
|
2446
|
+
---
|
|
2447
|
+
|
|
2448
|
+
### Properties
|
|
2449
|
+
|
|
2450
|
+
| Property | Type | Description |
|
|
2451
|
+
|---|---|---|
|
|
2452
|
+
| `languages` | `string[
|
|
2453
|
+
|
|
2454
|
+
**Example:**
|
|
2455
|
+
```typescript
|
|
2456
|
+
import { spawn } from 'child_process'
|
|
2457
|
+
import { writeFileSync, unlinkSync } from 'fs'
|
|
2458
|
+
import { join } from 'path'
|
|
2459
|
+
import { tmpdir } from 'os'
|
|
2460
|
+
|
|
2461
|
+
// --- Inline types (mirrors autodocs Scanner interface) ---
|
|
2462
|
+
type ScanResult = {
|
|
2463
|
+
filePath: string
|
|
2464
|
+
language: string
|
|
2465
|
+
symbols?: Array<{ name: string; kind:
|
|
2466
|
+
```
|
|
2467
|
+
|
|
2468
|
+
### canHandle
|
|
2469
|
+
|
|
2470
|
+
**Type:** method
|
|
2471
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python.ts
|
|
2472
|
+
|
|
2473
|
+
```
|
|
2474
|
+
canHandle(filePath: string): boolean
|
|
2475
|
+
```
|
|
2476
|
+
|
|
2477
|
+
Use this to quickly check whether a given file path should be processed by the Python scanner before committing to a full file scan.
|
|
2478
|
+
|
|
2479
|
+
Call `canHandle` as a pre-flight check to filter out non-Python files in a pipeline, avoiding unnecessary scan overhead.
|
|
2480
|
+
|
|
2481
|
+
### Parameters
|
|
2482
|
+
|
|
2483
|
+
| Name | Type | Required | Description |
|
|
2484
|
+
|------|------|----------|-------------|
|
|
2485
|
+
| `filePath` | `string` | ✅ | The file path to evaluate. Can be a relative path, absolute path, or just a filename. |
|
|
2486
|
+
|
|
2487
|
+
### Returns
|
|
2488
|
+
|
|
2489
|
+
| Value | Cond
|
|
2490
|
+
|
|
2491
|
+
**Example:**
|
|
2492
|
+
```typescript
|
|
2493
|
+
// Inline implementation of PythonScanner.canHandle
|
|
2494
|
+
class PythonScanner {
|
|
2495
|
+
languages = ['python']
|
|
2496
|
+
|
|
2497
|
+
canHandle(filePath: string): boolean {
|
|
2498
|
+
return filePath.endsWith('.py')
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
// Simulate a list of files discovered in a project directory
|
|
2503
|
+
const discoveredFiles = [
|
|
2504
|
+
'/project/src/main.py',
|
|
2505
|
+
|
|
2506
|
+
```
|
|
2507
|
+
|
|
2508
|
+
### scanFile
|
|
2509
|
+
|
|
2510
|
+
**Type:** method
|
|
2511
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python.ts
|
|
2512
|
+
|
|
2513
|
+
```
|
|
2514
|
+
async scanFile(filePath: string): Promise<ScanResult>
|
|
2515
|
+
```
|
|
2516
|
+
|
|
2517
|
+
Use this to scan a Python source file and extract structured metadata — functions, classes, imports, and other code elements — by running a Python parser subprocess and returning the results asynchronously.
|
|
2518
|
+
|
|
2519
|
+
This is the core method of `PythonScanner`. It delegates parsing to a `python3` child process, making it suitable for deep, AST-level analysis of `.py` files without reimplementing Python parsing in TypeScript.
|
|
2520
|
+
|
|
2521
|
+
## Parameters
|
|
2522
|
+
|
|
2523
|
+
| Name | Type | Required | Description |
|
|
2524
|
+
|------|------|---------
|
|
2525
|
+
|
|
2526
|
+
**Example:**
|
|
2527
|
+
```typescript
|
|
2528
|
+
import { spawn } from 'child_process'
|
|
2529
|
+
import { writeFileSync, unlinkSync } from 'fs'
|
|
2530
|
+
import { tmpdir } from 'os'
|
|
2531
|
+
import { join } from 'path'
|
|
2532
|
+
|
|
2533
|
+
// --- Inline types (mirrors the real ScanResult shape) ---
|
|
2534
|
+
interface ScanResult {
|
|
2535
|
+
filePath: string
|
|
2536
|
+
language: string
|
|
2537
|
+
functions: string[]
|
|
2538
|
+
classes: stri
|
|
2539
|
+
```
|
|
2540
|
+
|
|
2541
|
+
### get_docstring
|
|
2542
|
+
|
|
2543
|
+
**Type:** function
|
|
2544
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2545
|
+
|
|
2546
|
+
```
|
|
2547
|
+
def get_docstring(node: ast.AST) -> str | None
|
|
2548
|
+
```
|
|
2549
|
+
|
|
2550
|
+
Use this to extract the docstring from any Python AST node (functions, classes, modules) when parsing or analyzing Python source code programmatically.
|
|
2551
|
+
|
|
2552
|
+
Returns the docstring as a `str` if one is present, or `None` if the node has no docstring.
|
|
2553
|
+
|
|
2554
|
+
## Parameters
|
|
2555
|
+
|
|
2556
|
+
| Name | Type | Required | Description |
|
|
2557
|
+
|------|------|----------|-------------|
|
|
2558
|
+
| node | `ast.AST` | ✅ | Any parsed AST node — typically a `Module`, `FunctionDef`, `AsyncFunctionDef`, or `ClassDef` |
|
|
2559
|
+
|
|
2560
|
+
## Returns
|
|
2561
|
+
|
|
2562
|
+
| Value | When |
|
|
2563
|
+
|------
|
|
2564
|
+
|
|
2565
|
+
**Example:**
|
|
2566
|
+
```python
|
|
2567
|
+
import ast
|
|
2568
|
+
|
|
2569
|
+
# Inline implementation of get_docstring
|
|
2570
|
+
def get_docstring(node: ast.AST) -> "str | None":
|
|
2571
|
+
"""Extract docstring from a node if present."""
|
|
2572
|
+
if not isinstance(node, (ast.Module, ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
2573
|
+
return None
|
|
2574
|
+
if not node.body:
|
|
2575
|
+
|
|
2576
|
+
```
|
|
2577
|
+
|
|
2578
|
+
### get_type_annotation
|
|
2579
|
+
|
|
2580
|
+
**Type:** function
|
|
2581
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2582
|
+
|
|
2583
|
+
```
|
|
2584
|
+
def get_type_annotation(annotation: ast.AST | None) -> str | None
|
|
2585
|
+
```
|
|
2586
|
+
|
|
2587
|
+
Use this to convert a Python AST type annotation node into its human-readable string representation — ideal for documentation generators, code analyzers, or any tool that needs to display type hints as readable text.
|
|
2588
|
+
|
|
2589
|
+
Returns `None` if the annotation is `None` or cannot be resolved. Returns a string like `"str"`, `"int"`, `"List[str]"`, or `"Optional[int]"` for valid annotations.
|
|
2590
|
+
|
|
2591
|
+
## Parameters
|
|
2592
|
+
|
|
2593
|
+
| Name | Type | Required | Description |
|
|
2594
|
+
|------|------|----------|-------------|
|
|
2595
|
+
| `annotation` | `a
|
|
2596
|
+
|
|
2597
|
+
**Example:**
|
|
2598
|
+
```python
|
|
2599
|
+
import ast
|
|
2600
|
+
|
|
2601
|
+
# Inline implementation of get_type_annotation
|
|
2602
|
+
def get_type_annotation(annotation: ast.AST | None) -> str | None:
|
|
2603
|
+
"""Convert type annotation AST to string."""
|
|
2604
|
+
if annotation is None:
|
|
2605
|
+
return None
|
|
2606
|
+
try:
|
|
2607
|
+
return ast.unparse(annotation)
|
|
2608
|
+
except Exception:
|
|
2609
|
+
|
|
2610
|
+
```
|
|
2611
|
+
|
|
2612
|
+
### get_default_value
|
|
2613
|
+
|
|
2614
|
+
**Type:** function
|
|
2615
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2616
|
+
|
|
2617
|
+
```
|
|
2618
|
+
def get_default_value(default: ast.AST | None) -> str | None
|
|
2619
|
+
```
|
|
2620
|
+
|
|
2621
|
+
Use this to extract a human-readable string representation of a Python function parameter's default value from its AST node — ideal for documentation generators, code analyzers, or introspection tools.
|
|
2622
|
+
|
|
2623
|
+
When parsing Python source code with the `ast` module, default values are stored as AST nodes. This function converts those nodes back into readable strings (e.g., `"42"`, `"'hello'"`, `"None"`). Returns `None` if no default value exists.
|
|
2624
|
+
|
|
2625
|
+
### Parameters
|
|
2626
|
+
|
|
2627
|
+
| Name | Type | Required | Description |
|
|
2628
|
+
|
|
2629
|
+
|
|
2630
|
+
**Example:**
|
|
2631
|
+
```python
|
|
2632
|
+
import ast
|
|
2633
|
+
|
|
2634
|
+
# Inline implementation of get_default_value
|
|
2635
|
+
def get_default_value(default: ast.AST | None) -> str | None:
|
|
2636
|
+
"""Convert default value AST to string."""
|
|
2637
|
+
if default is None:
|
|
2638
|
+
return None
|
|
2639
|
+
return ast.unparse(default)
|
|
2640
|
+
|
|
2641
|
+
# Helper: parse a function and extract its argument defau
|
|
2642
|
+
```
|
|
2643
|
+
|
|
2644
|
+
### extract_parameters
|
|
2645
|
+
|
|
2646
|
+
**Type:** function
|
|
2647
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2648
|
+
|
|
2649
|
+
```
|
|
2650
|
+
def extract_parameters(args: ast.arguments) -> list[dict[str, Any]]
|
|
2651
|
+
```
|
|
2652
|
+
|
|
2653
|
+
Use this to convert Python AST function arguments into a structured list of parameter metadata — ideal for building documentation generators, code analyzers, or introspection tools.
|
|
2654
|
+
|
|
2655
|
+
Given an `ast.arguments` object (obtained by parsing Python source code), this function returns a list of dictionaries, each describing one parameter: its name, type annotation (if any), and default value (if any).
|
|
2656
|
+
|
|
2657
|
+
### Parameters
|
|
2658
|
+
|
|
2659
|
+
| Name | Type | Required | Description |
|
|
2660
|
+
|------|------|----------|-------------|
|
|
2661
|
+
| `
|
|
2662
|
+
|
|
2663
|
+
**Example:**
|
|
2664
|
+
```python
|
|
2665
|
+
import ast
|
|
2666
|
+
from typing import Any
|
|
2667
|
+
|
|
2668
|
+
# ── Inline implementation of extract_parameters ──────────────────────────────
|
|
2669
|
+
|
|
2670
|
+
def extract_parameters(args: ast.arguments) -> list[dict[str, Any]]:
|
|
2671
|
+
"""Extract parameters from function arguments."""
|
|
2672
|
+
params: list[dict[str, Any]] = []
|
|
2673
|
+
|
|
2674
|
+
# Calculate offset
|
|
2675
|
+
```
|
|
2676
|
+
|
|
2677
|
+
### build_signature
|
|
2678
|
+
|
|
2679
|
+
**Type:** function
|
|
2680
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2681
|
+
|
|
2682
|
+
```
|
|
2683
|
+
def build_signature(name: str, args: ast.arguments, returns: ast.AST | None, is_async: bool) -> str
|
|
2684
|
+
```
|
|
2685
|
+
|
|
2686
|
+
Use this to reconstruct a human-readable function signature string from parsed AST components — useful when generating documentation, code analysis tools, or displaying function metadata without executing the code.
|
|
2687
|
+
|
|
2688
|
+
## Parameters
|
|
2689
|
+
|
|
2690
|
+
| Name | Type | Required | Description |
|
|
2691
|
+
|------|------|----------|-------------|
|
|
2692
|
+
| `name` | `str` | ✅ | The function name to include in the signature |
|
|
2693
|
+
| `args` | `ast.arguments` | ✅ | The parsed argument node from the AST, containing all parameter info (defaults, ann
|
|
2694
|
+
|
|
2695
|
+
**Example:**
|
|
2696
|
+
```python
|
|
2697
|
+
import ast
|
|
2698
|
+
|
|
2699
|
+
# Inline implementation of build_signature
|
|
2700
|
+
def build_signature(name: str, args: ast.arguments, returns: ast.AST | None, is_async: bool) -> str:
|
|
2701
|
+
"""Build the function signature as a string."""
|
|
2702
|
+
prefix = "async def" if is_async else "def"
|
|
2703
|
+
|
|
2704
|
+
# Build argument list
|
|
2705
|
+
arg_parts = [
|
|
2706
|
+
```
|
|
2707
|
+
|
|
2708
|
+
### extract_function
|
|
2709
|
+
|
|
2710
|
+
**Type:** function
|
|
2711
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2712
|
+
|
|
2713
|
+
```
|
|
2714
|
+
def extract_function(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, parent_class: str | None) -> dict[str, Any]
|
|
2715
|
+
```
|
|
2716
|
+
|
|
2717
|
+
Use this to extract structured metadata from a Python function or method AST node — including its name, signature, docstring, decorators, and source location — for use in code analysis, documentation generation, or static analysis tooling.
|
|
2718
|
+
|
|
2719
|
+
Given an AST node representing a function or async function, this returns a dictionary containing all relevant metadata about that function, ready for further processing or storage.
|
|
2720
|
+
|
|
2721
|
+
## Parameters
|
|
2722
|
+
|
|
2723
|
+
| Name | Type | Required | Description |
|
|
2724
|
+
|------|------|-----
|
|
2725
|
+
|
|
2726
|
+
**Example:**
|
|
2727
|
+
```python
|
|
2728
|
+
import ast
|
|
2729
|
+
from typing import Any
|
|
2730
|
+
|
|
2731
|
+
# Inline implementation of extract_function
|
|
2732
|
+
def extract_function(
|
|
2733
|
+
node: ast.FunctionDef | ast.AsyncFunctionDef,
|
|
2734
|
+
file_path: str,
|
|
2735
|
+
parent_class: str | None = None
|
|
2736
|
+
) -> dict[str, Any]:
|
|
2737
|
+
"""Extract structured metadata from a function or method AST node.""
|
|
2738
|
+
```
|
|
2739
|
+
|
|
2740
|
+
### extract_class
|
|
2741
|
+
|
|
2742
|
+
**Type:** function
|
|
2743
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2744
|
+
|
|
2745
|
+
```
|
|
2746
|
+
def extract_class(node: ast.ClassDef, file_path: str) -> list[dict[str, Any]]
|
|
2747
|
+
```
|
|
2748
|
+
|
|
2749
|
+
Use this to parse a Python AST `ClassDef` node and extract structured metadata about a class and all its methods into a flat list of dictionaries.
|
|
2750
|
+
|
|
2751
|
+
Each dictionary in the returned list represents either the class itself or one of its methods, making it easy to index, search, or analyze Python source code programmatically.
|
|
2752
|
+
|
|
2753
|
+
## Parameters
|
|
2754
|
+
|
|
2755
|
+
| Name | Type | Required | Description |
|
|
2756
|
+
|------|------|----------|-------------|
|
|
2757
|
+
| `node` | `ast.ClassDef` | Yes | The AST node representing the class definiti
|
|
2758
|
+
|
|
2759
|
+
**Example:**
|
|
2760
|
+
```python
|
|
2761
|
+
import ast
|
|
2762
|
+
from typing import Any
|
|
2763
|
+
|
|
2764
|
+
# ── Inline implementation of extract_class ────────────────────────────────────
|
|
2765
|
+
|
|
2766
|
+
def extract_class(node: ast.ClassDef, file_path: str) -> list[dict[str, Any]]:
|
|
2767
|
+
"""Extract a class and its methods into a flat list of metadata dicts."""
|
|
2768
|
+
results: list[dict[str
|
|
2769
|
+
```
|
|
2770
|
+
|
|
2771
|
+
### scan_file
|
|
2772
|
+
|
|
2773
|
+
**Type:** function
|
|
2774
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/python_parser.py
|
|
2775
|
+
|
|
2776
|
+
```
|
|
2777
|
+
def scan_file(file_path: str) -> dict[str, Any]
|
|
2778
|
+
```
|
|
2779
|
+
|
|
2780
|
+
Use this to extract all API elements from a Python source file — functions, classes, methods, imports, and metadata — in a single structured dictionary.
|
|
2781
|
+
|
|
2782
|
+
Ideal for building documentation generators, code analysis tools, static analyzers, or any workflow that needs to introspect a Python file programmatically.
|
|
2783
|
+
|
|
2784
|
+
## Parameters
|
|
2785
|
+
|
|
2786
|
+
| Name | Type | Required | Description |
|
|
2787
|
+
|------|------|----------|-------------|
|
|
2788
|
+
| `file_path` | `str` | ✅ Yes | Absolute or relative path to the `.py` file to scan |
|
|
2789
|
+
|
|
2790
|
+
## R
|
|
2791
|
+
|
|
2792
|
+
**Example:**
|
|
2793
|
+
```python
|
|
2794
|
+
import ast
|
|
2795
|
+
import os
|
|
2796
|
+
from typing import Any
|
|
2797
|
+
|
|
2798
|
+
# Inline implementation of scan_file — no external imports needed
|
|
2799
|
+
def scan_file(file_path: str) -> dict[str, Any]:
|
|
2800
|
+
"""Scan a Python file and extract all API elements."""
|
|
2801
|
+
result: dict[str, Any] = {
|
|
2802
|
+
"file": file_path,
|
|
2803
|
+
"functions": []
|
|
2804
|
+
```
|
|
2805
|
+
|
|
2806
|
+
### RustScanner
|
|
2807
|
+
|
|
2808
|
+
**Type:** class
|
|
2809
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/rust.ts
|
|
2810
|
+
|
|
2811
|
+
```
|
|
2812
|
+
class RustScanner implements Scanner
|
|
2813
|
+
```
|
|
2814
|
+
|
|
2815
|
+
Use this to scan Rust source files and extract public API elements — functions, structs, enums, impl blocks, and traits — for automated documentation generation.
|
|
2816
|
+
|
|
2817
|
+
`RustScanner` implements the `Scanner` interface and targets `.rs` files, automatically skipping test files in `/tests/` directories.
|
|
2818
|
+
|
|
2819
|
+
## Methods
|
|
2820
|
+
|
|
2821
|
+
### `canHandle(filePath: string): boolean`
|
|
2822
|
+
Determines whether this scanner should process a given file.
|
|
2823
|
+
|
|
2824
|
+
| Name | Type | Required | Description |
|
|
2825
|
+
|------|------|----------|-------------|
|
|
2826
|
+
| `
|
|
2827
|
+
|
|
2828
|
+
### canHandle
|
|
2829
|
+
|
|
2830
|
+
**Type:** method
|
|
2831
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/rust.ts
|
|
2832
|
+
|
|
2833
|
+
```
|
|
2834
|
+
canHandle(filePath: string): boolean
|
|
2835
|
+
```
|
|
2836
|
+
|
|
2837
|
+
Use this to quickly determine whether a given file path should be processed by the Rust scanner before committing to a full file scan.
|
|
2838
|
+
|
|
2839
|
+
`canHandle` returns `true` only when **both** conditions are met:
|
|
2840
|
+
- The file path ends with `.rs`
|
|
2841
|
+
- The file path does **not** contain `/tests/`
|
|
2842
|
+
|
|
2843
|
+
This acts as a fast pre-flight check, letting you skip incompatible files without reading them from disk.
|
|
2844
|
+
|
|
2845
|
+
### Parameters
|
|
2846
|
+
|
|
2847
|
+
| Name | Type | Required | Description |
|
|
2848
|
+
|------|------|----------|-------------|
|
|
2849
|
+
| `filePath`
|
|
2850
|
+
|
|
2851
|
+
**Example:**
|
|
2852
|
+
```typescript
|
|
2853
|
+
// Inline implementation matching RustScanner.canHandle behavior
|
|
2854
|
+
class RustScanner {
|
|
2855
|
+
languages = ['rust']
|
|
2856
|
+
|
|
2857
|
+
canHandle(filePath: string): boolean {
|
|
2858
|
+
return /\.rs$/.test(filePath) && !filePath.includes('/tests/')
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2862
|
+
const scanner = new RustScanner()
|
|
2863
|
+
|
|
2864
|
+
const filePaths = [
|
|
2865
|
+
'src/main.rs',
|
|
2866
|
+
```
|
|
2867
|
+
|
|
2868
|
+
### scanFile
|
|
2869
|
+
|
|
2870
|
+
**Type:** method
|
|
2871
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/rust.ts
|
|
2872
|
+
|
|
2873
|
+
```
|
|
2874
|
+
async scanFile(filePath: string): Promise<ScanResult>
|
|
2875
|
+
```
|
|
2876
|
+
|
|
2877
|
+
Use this to extract API elements from a Rust source file, parsing its contents into a structured result containing discovered elements and any errors encountered during scanning.
|
|
2878
|
+
|
|
2879
|
+
Handles `.rs` files outside of test directories (`/tests/`). Reads the file synchronously and returns a promise resolving to a structured scan result.
|
|
2880
|
+
|
|
2881
|
+
## Parameters
|
|
2882
|
+
|
|
2883
|
+
| Name | Type | Required | Description |
|
|
2884
|
+
|------|------|----------|-------------|
|
|
2885
|
+
| `filePath` | `string` | ✅ | Absolute or relative path to the `.rs` fi
|
|
2886
|
+
|
|
2887
|
+
**Example:**
|
|
2888
|
+
```typescript
|
|
2889
|
+
import { readFileSync } from 'fs'
|
|
2890
|
+
import { writeFileSync, mkdirSync } from 'fs'
|
|
2891
|
+
import { join } from 'path'
|
|
2892
|
+
import { tmpdir } from 'os'
|
|
2893
|
+
|
|
2894
|
+
// --- Inline types (mirrors the real library's types) ---
|
|
2895
|
+
interface Parameter {
|
|
2896
|
+
name: string
|
|
2897
|
+
type: string
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
interface APIElement {
|
|
2901
|
+
name: string
|
|
2902
|
+
kind: 'fu
|
|
2903
|
+
```
|
|
2904
|
+
|
|
2905
|
+
### TypeScriptScanner
|
|
2906
|
+
|
|
2907
|
+
**Type:** class
|
|
2908
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/typescript.ts
|
|
2909
|
+
|
|
2910
|
+
```
|
|
2911
|
+
class TypeScriptScanner implements Scanner
|
|
2912
|
+
```
|
|
2913
|
+
|
|
2914
|
+
Use this to scan TypeScript and JavaScript source files and extract API elements (functions, classes, parameters, and signatures) for automatic documentation generation.
|
|
2915
|
+
|
|
2916
|
+
`TypeScriptScanner` implements the `Scanner` interface and handles `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, and `.cjs` files. It skips declaration files (`.d.ts`) automatically.
|
|
2917
|
+
|
|
2918
|
+
## Properties
|
|
2919
|
+
|
|
2920
|
+
| Property | Type | Description |
|
|
2921
|
+
|---|---|---|
|
|
2922
|
+
| `languages` | `string[]` | Always `['typescript', 'javascript']` — the languages this sc
|
|
2923
|
+
|
|
2924
|
+
### canHandle
|
|
2925
|
+
|
|
2926
|
+
**Type:** method
|
|
2927
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/typescript.ts
|
|
2928
|
+
|
|
2929
|
+
```
|
|
2930
|
+
canHandle(filePath: string): boolean
|
|
2931
|
+
```
|
|
2932
|
+
|
|
2933
|
+
Use this to quickly check whether a file path is a TypeScript/JavaScript source file that the scanner can process — filtering out declaration files (`.d.ts`) automatically.
|
|
2934
|
+
|
|
2935
|
+
Returns `true` for `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, and `.cjs` files. Returns `false` for `.d.ts` declaration files and any other file types.
|
|
2936
|
+
|
|
2937
|
+
### Parameters
|
|
2938
|
+
|
|
2939
|
+
| Name | Type | Required | Description |
|
|
2940
|
+
|------|------|----------|-------------|
|
|
2941
|
+
| `filePath` | `string` | ✅ | Absolute or relative path to the file being evalua
|
|
2942
|
+
|
|
2943
|
+
**Example:**
|
|
2944
|
+
```typescript
|
|
2945
|
+
// Inline implementation matching TypeScriptScanner.canHandle behavior
|
|
2946
|
+
class TypeScriptScanner {
|
|
2947
|
+
languages = ['typescript', 'javascript']
|
|
2948
|
+
|
|
2949
|
+
canHandle(filePath: string): boolean {
|
|
2950
|
+
return /\.(ts|tsx|js|jsx|mjs|cjs)$/.test(filePath) && !filePath.includes('.d.ts')
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
const scanner = new TypeS
|
|
2955
|
+
```
|
|
2956
|
+
|
|
2957
|
+
### scanFile
|
|
2958
|
+
|
|
2959
|
+
**Type:** method
|
|
2960
|
+
**File:** /Users/debmukherjee/autodocs/src/scanner/typescript.ts
|
|
2961
|
+
|
|
2962
|
+
```
|
|
2963
|
+
async scanFile(filePath: string): Promise<ScanResult>
|
|
2964
|
+
```
|
|
2965
|
+
|
|
2966
|
+
Use this to extract API elements (functions, classes, interfaces, types) from a TypeScript or JavaScript source file, returning structured metadata about each discovered element.
|
|
2967
|
+
|
|
2968
|
+
`scanFile` analyzes a `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, or `.cjs` file and produces a `ScanResult` containing all documented API surface — parameters, return types, visibility, and more. Use it as the core step in building documentation pipelines, API audits, or code analysis tools.
|
|
2969
|
+
|
|
2970
|
+
> **Note:** Declaration files (
|
|
2971
|
+
|