( organizationId: string | null, projectId: string, gitBranch: string, baseUrl: string, authToken: string, folderPath: string )
| 261 | |
| 262 | // Main operations |
| 263 | async function indexFiles( |
| 264 | organizationId: string | null, |
| 265 | projectId: string, |
| 266 | gitBranch: string, |
| 267 | baseUrl: string, |
| 268 | authToken: string, |
| 269 | folderPath: string |
| 270 | ): Promise<void> { |
| 271 | console.log('🚀 Starting code indexing...'); |
| 272 | console.log(` Organization ID: ${organizationId}`); |
| 273 | console.log(` Project ID: ${projectId}`); |
| 274 | console.log(` Git Branch: ${gitBranch}`); |
| 275 | console.log(` Base URL: ${baseUrl}`); |
| 276 | console.log(''); |
| 277 | |
| 278 | // Fetch existing manifest to check which files need updating |
| 279 | console.log('📋 Fetching existing manifest...'); |
| 280 | let existingManifest: ManifestResponse; |
| 281 | try { |
| 282 | existingManifest = await fetchManifest( |
| 283 | organizationId, |
| 284 | projectId, |
| 285 | gitBranch, |
| 286 | baseUrl, |
| 287 | authToken |
| 288 | ); |
| 289 | console.log( |
| 290 | ` Found ${Object.keys(existingManifest.files).length} files in existing manifest` |
| 291 | ); |
| 292 | } catch (error) { |
| 293 | console.error( |
| 294 | ' ⚠️ Could not fetch manifest:', |
| 295 | error instanceof Error ? error.message : error |
| 296 | ); |
| 297 | console.log(' Proceeding to index all files...'); |
| 298 | existingManifest = { |
| 299 | organizationId, |
| 300 | projectId, |
| 301 | gitBranch, |
| 302 | files: {}, |
| 303 | totalFiles: 0, |
| 304 | lastUpdated: new Date().toISOString(), |
| 305 | }; |
| 306 | } |
| 307 | console.log(''); |
| 308 | |
| 309 | // Create a map of file paths to their file hash signatures |
| 310 | // Note: manifest is fileHash -> filePath, but we need filePath -> fileHash |
| 311 | // If a file appears multiple times with different hashes, we keep the most recent (last one) |
| 312 | const manifestMap = new Map<string, string>(); |
| 313 | for (const [fileHash, filePath] of Object.entries(existingManifest.files)) { |
| 314 | manifestMap.set(filePath, fileHash); |
| 315 | } |
| 316 | |
| 317 | // Resolve the folder path (handle relative, absolute, and ~/ paths) |
| 318 | let srcDir: string; |
| 319 | if (folderPath.startsWith('~/')) { |
| 320 | srcDir = join(homedir(), folderPath.slice(2)); |
no test coverage detected