@@ -4,8 +4,24 @@ import fs from "fs/promises"
44
55/**
66 * Gets the global .roo directory path based on the current platform
7- * macOS/Linux: ~/.roo/
8- * Windows: %USERPROFILE%\.roo\
7+ *
8+ * @returns The absolute path to the global .roo directory
9+ *
10+ * @example Platform-specific paths:
11+ * ```
12+ * // macOS/Linux: ~/.roo/
13+ * // Example: /Users/john/.roo
14+ *
15+ * // Windows: %USERPROFILE%\.roo\
16+ * // Example: C:\Users\john\.roo
17+ * ```
18+ *
19+ * @example Usage:
20+ * ```typescript
21+ * const globalDir = getGlobalRooDirectory()
22+ * // Returns: "/Users/john/.roo" (on macOS/Linux)
23+ * // Returns: "C:\\Users\\john\\.roo" (on Windows)
24+ * ```
925 */
1026export function getGlobalRooDirectory ( ) : string {
1127 const homeDir = os . homedir ( )
@@ -14,6 +30,32 @@ export function getGlobalRooDirectory(): string {
1430
1531/**
1632 * Gets the project-local .roo directory path for a given cwd
33+ *
34+ * @param cwd - Current working directory (project path)
35+ * @returns The absolute path to the project-local .roo directory
36+ *
37+ * @example
38+ * ```typescript
39+ * const projectDir = getProjectRooDirectoryForCwd('/Users/john/my-project')
40+ * // Returns: "/Users/john/my-project/.roo"
41+ *
42+ * const windowsProjectDir = getProjectRooDirectoryForCwd('C:\\Users\\john\\my-project')
43+ * // Returns: "C:\\Users\\john\\my-project\\.roo"
44+ * ```
45+ *
46+ * @example Directory structure:
47+ * ```
48+ * /Users/john/my-project/
49+ * ├── .roo/ # Project-local configuration directory
50+ * │ ├── rules/
51+ * │ │ └── rules.md
52+ * │ ├── custom-instructions.md
53+ * │ └── config/
54+ * │ └── settings.json
55+ * ├── src/
56+ * │ └── index.ts
57+ * └── package.json
58+ * ```
1759 */
1860export function getProjectRooDirectoryForCwd ( cwd : string ) : string {
1961 return path . join ( cwd , ".roo" )
@@ -71,8 +113,36 @@ export async function readFileIfExists(filePath: string): Promise<string | null>
71113
72114/**
73115 * Gets the ordered list of .roo directories to check (global first, then project-local)
116+ *
74117 * @param cwd - Current working directory (project path)
75118 * @returns Array of directory paths to check in order [global, project-local]
119+ *
120+ * @example
121+ * ```typescript
122+ * // For a project at /Users/john/my-project
123+ * const directories = getRooDirectoriesForCwd('/Users/john/my-project')
124+ * // Returns:
125+ * // [
126+ * // '/Users/john/.roo', // Global directory
127+ * // '/Users/john/my-project/.roo' // Project-local directory
128+ * // ]
129+ * ```
130+ *
131+ * @example Directory structure:
132+ * ```
133+ * /Users/john/
134+ * ├── .roo/ # Global configuration
135+ * │ ├── rules/
136+ * │ │ └── rules.md
137+ * │ └── custom-instructions.md
138+ * └── my-project/
139+ * ├── .roo/ # Project-specific configuration
140+ * │ ├── rules/
141+ * │ │ └── rules.md # Overrides global rules
142+ * │ └── project-notes.md
143+ * └── src/
144+ * └── index.ts
145+ * ```
76146 */
77147export function getRooDirectoriesForCwd ( cwd : string ) : string [ ] {
78148 const directories : string [ ] = [ ]
@@ -88,9 +158,54 @@ export function getRooDirectoriesForCwd(cwd: string): string[] {
88158
89159/**
90160 * Loads configuration from multiple .roo directories with project overriding global
161+ *
91162 * @param relativePath - The relative path within each .roo directory (e.g., 'rules/rules.md')
92163 * @param cwd - Current working directory (project path)
93164 * @returns Object with global and project content, plus merged content
165+ *
166+ * @example
167+ * ```typescript
168+ * // Load rules configuration for a project
169+ * const config = await loadConfiguration('rules/rules.md', '/Users/john/my-project')
170+ *
171+ * // Returns:
172+ * // {
173+ * // global: "Global rules content...", // From ~/.roo/rules/rules.md
174+ * // project: "Project rules content...", // From /Users/john/my-project/.roo/rules/rules.md
175+ * // merged: "Global rules content...\n\n# Project-specific rules (override global):\n\nProject rules content..."
176+ * // }
177+ * ```
178+ *
179+ * @example File paths resolved:
180+ * ```
181+ * relativePath: 'rules/rules.md'
182+ * cwd: '/Users/john/my-project'
183+ *
184+ * Reads from:
185+ * - Global: /Users/john/.roo/rules/rules.md
186+ * - Project: /Users/john/my-project/.roo/rules/rules.md
187+ *
188+ * Other common relativePath examples:
189+ * - 'custom-instructions.md'
190+ * - 'config/settings.json'
191+ * - 'templates/component.tsx'
192+ * ```
193+ *
194+ * @example Merging behavior:
195+ * ```
196+ * // If only global exists:
197+ * { global: "content", project: null, merged: "content" }
198+ *
199+ * // If only project exists:
200+ * { global: null, project: "content", merged: "content" }
201+ *
202+ * // If both exist:
203+ * {
204+ * global: "global content",
205+ * project: "project content",
206+ * merged: "global content\n\n# Project-specific rules (override global):\n\nproject content"
207+ * }
208+ * ```
94209 */
95210export async function loadConfiguration (
96211 relativePath : string ,
@@ -134,4 +249,4 @@ export async function loadConfiguration(
134249}
135250
136251// Export with backward compatibility alias
137- export const loadRooConfiguration = loadConfiguration
252+ export const loadRooConfiguration : typeof loadConfiguration = loadConfiguration
0 commit comments