MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / loadRecentProjects

Function loadRecentProjects

cli/src/utils/recent-projects.ts:25–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23 * @returns Array of recent projects, sorted by most recent first
24 */
25export const loadRecentProjects = (): RecentProject[] => {
26 const recentProjectsPath = getRecentProjectsPath()
27
28 if (!fs.existsSync(recentProjectsPath)) {
29 return []
30 }
31
32 try {
33 const fileContent = fs.readFileSync(recentProjectsPath, 'utf8')
34 const parsed = JSON.parse(fileContent)
35
36 if (!Array.isArray(parsed)) {
37 return []
38 }
39
40 // Validate and filter entries
41 const validProjects = parsed.filter(
42 (item): item is RecentProject =>
43 typeof item === 'object' &&
44 item !== null &&
45 typeof item.path === 'string' &&
46 typeof item.lastOpened === 'number',
47 )
48
49 // Filter out projects that no longer exist on disk
50 const existingProjects = validProjects.filter((project) => {
51 try {
52 return fs.existsSync(project.path)
53 } catch {
54 return false
55 }
56 })
57
58 // Sort by most recent first
59 return existingProjects.sort((a, b) => b.lastOpened - a.lastOpened)
60 } catch (error) {
61 logger.debug(
62 { error: error instanceof Error ? error.message : String(error) },
63 'Error reading recent projects',
64 )
65 return []
66 }
67}
68
69/**
70 * Clear all recent projects

Callers 3

ProjectPickerScreenFunction · 0.90
removeRecentProjectFunction · 0.85
saveRecentProjectFunction · 0.85

Calls 2

getRecentProjectsPathFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected