@@ -13,21 +13,48 @@ export declare const REQUIRED_FRONTMATTER_FIELDS: string[]
1313
1414/**
1515 * Get the package root directory from a module's import.meta.url
16+ *
17+ * @param importMetaUrl - The import.meta.url of the calling module
18+ * @returns The package root directory path
1619 */
1720export function getPackageRoot ( importMetaUrl : string ) : string
1821
1922/**
2023 * Get the source directory containing agent markdown files.
24+ *
25+ * @param packageRoot - The package root directory
26+ * @returns Path to the agents source directory
2127 */
2228export function getAgentsSourceDir ( packageRoot : string ) : string
2329
2430/**
2531 * The target directory where agents are installed.
32+ * Located at ~/.config/opencode/agents/
2633 */
2734export declare const AGENTS_TARGET_DIR : string
2835
2936/**
3037 * Returns a user-friendly error message based on the error code.
38+ *
39+ * Translates Node.js filesystem error codes into human-readable messages
40+ * that help users understand and resolve installation issues.
41+ *
42+ * @param error - The error object from a failed fs operation
43+ * @param file - The filename being processed
44+ * @param targetPath - The target path for the file
45+ * @returns A helpful error message describing the issue and potential solution
46+ *
47+ * @example
48+ * // Permission denied error
49+ * const err = Object.assign(new Error(), { code: 'EACCES' })
50+ * getErrorMessage(err, 'agent.md', '/home/user/.config/opencode/agents/agent.md')
51+ * // Returns: "Permission denied. Check write permissions for /home/user/.config/opencode/agents"
52+ *
53+ * @example
54+ * // File not found error
55+ * const err = Object.assign(new Error(), { code: 'ENOENT' })
56+ * getErrorMessage(err, 'missing.md', '/target/missing.md')
57+ * // Returns: "Source file not found: missing.md"
3158 */
3259export function getErrorMessage (
3360 error : Error & { code ?: string } ,
@@ -40,6 +67,9 @@ export declare const TRANSIENT_ERROR_CODES: string[]
4067
4168/**
4269 * Checks if an error is a transient error that may succeed on retry.
70+ *
71+ * @param error - The error to check
72+ * @returns True if the error is transient (EAGAIN, EBUSY)
4373 */
4474export function isTransientError ( error : Error & { code ?: string } ) : boolean
4575
@@ -58,6 +88,23 @@ export interface RetryOptions {
5888 *
5989 * If the function throws a transient error (EAGAIN, EBUSY), it will be retried
6090 * up to the specified number of times with a delay between attempts.
91+ *
92+ * @template T - The return type of the function
93+ * @param fn - The function to execute
94+ * @param options - Retry options (retries, delayMs)
95+ * @returns The result of the function
96+ * @throws The last error if all retries fail
97+ *
98+ * @example
99+ * // Retry a file copy operation
100+ * await retryOnTransientError(() => copyFileSync(src, dest))
101+ *
102+ * @example
103+ * // Custom retry options
104+ * await retryOnTransientError(
105+ * () => unlinkSync(path),
106+ * { retries: 5, delayMs: 200 }
107+ * )
61108 */
62109export function retryOnTransientError < T > (
63110 fn : ( ) => T | Promise < T > ,
@@ -68,23 +115,31 @@ export function retryOnTransientError<T>(
68115 * Result of parsing YAML frontmatter from markdown content.
69116 */
70117export interface ParseFrontmatterResult {
118+ /** Whether frontmatter was found in the content */
71119 found : boolean
120+ /** Parsed key-value pairs from the frontmatter */
72121 fields : Record < string , string >
122+ /** Character index where the frontmatter ends (after closing ---\n) */
73123 endIndex : number
74124}
75125
76126/**
77127 * Parses YAML frontmatter from markdown content.
78128 *
79129 * Expects frontmatter to be delimited by --- at the start of the file.
130+ *
131+ * @param content - The file content to parse
132+ * @returns Parse result with found status, fields, and end index
80133 */
81134export function parseFrontmatter ( content : string ) : ParseFrontmatterResult
82135
83136/**
84137 * Result of validating agent content.
85138 */
86139export interface ValidateAgentContentResult {
140+ /** Whether the content is valid */
87141 valid : boolean
142+ /** Error message if validation failed */
88143 error ?: string
89144}
90145
@@ -96,6 +151,9 @@ export interface ValidateAgentContentResult {
96151 * 2. Starts with a markdown header (# ) after frontmatter
97152 * 3. Contains at least MIN_CONTENT_LENGTH characters
98153 * 4. Contains at least one of the expected keywords
154+ *
155+ * @param content - The agent file content to validate
156+ * @returns Validation result with valid status and optional error message
99157 */
100158export function validateAgentContent ( content : string ) : ValidateAgentContentResult
101159
@@ -114,6 +172,13 @@ export function validateAgentContent(content: string): ValidateAgentContentResul
114172 * @param required - The required version range (e.g., ">=0.1.0", "^1.0.0")
115173 * @param current - The current version to check (e.g., "1.2.3")
116174 * @returns True if current version satisfies the required range
175+ *
176+ * @example
177+ * checkVersionCompatibility(">=0.1.0", "0.2.0") // true
178+ * checkVersionCompatibility("^1.0.0", "1.5.0") // true
179+ * checkVersionCompatibility("^1.0.0", "2.0.0") // false
180+ * checkVersionCompatibility("~1.2.0", "1.2.5") // true
181+ * checkVersionCompatibility("~1.2.0", "1.3.0") // false
117182 */
118183export function checkVersionCompatibility ( required : string , current : string ) : boolean
119184
@@ -139,6 +204,19 @@ export interface CliFlags {
139204 *
140205 * @param argv - The command line arguments array (typically process.argv)
141206 * @returns Parsed flags object
207+ *
208+ * @example
209+ * // Parse process.argv
210+ * const flags = parseCliFlags(process.argv)
211+ * if (flags.help) {
212+ * console.log("Usage: ...")
213+ * process.exit(0)
214+ * }
215+ *
216+ * @example
217+ * // Parse custom arguments
218+ * const flags = parseCliFlags(["node", "script.js", "--verbose", "--dry-run"])
219+ * // flags = { dryRun: true, verbose: true, help: false }
142220 */
143221export function parseCliFlags ( argv : string [ ] ) : CliFlags
144222
@@ -160,6 +238,16 @@ export interface Logger {
160238 * - `verbose(message)`: Only logs when verbose mode is enabled, prefixed with [VERBOSE]
161239 *
162240 * @param verbose - Whether verbose logging is enabled
163- * @returns Logger object
241+ * @returns Logger object with log and verbose methods
242+ *
243+ * @example
244+ * const logger = createLogger(true)
245+ * logger.log("Installing agents...") // Always prints
246+ * logger.verbose("Source: /path/to/src") // Prints: [VERBOSE] Source: /path/to/src
247+ *
248+ * @example
249+ * const logger = createLogger(false)
250+ * logger.log("Installing agents...") // Prints
251+ * logger.verbose("Source: /path/to/src") // Does nothing (verbose disabled)
164252 */
165253export function createLogger ( verbose : boolean ) : Logger
0 commit comments