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

Function saveRecentProject

cli/src/utils/recent-projects.ts:117–156  ·  view source on GitHub ↗
(projectPath: string)

Source from the content-addressed store, hash-verified

115 * Validates that the path exists before saving.
116 */
117export const saveRecentProject = (projectPath: string): void => {
118 // Validate path exists before saving
119 if (!fs.existsSync(projectPath)) {
120 logger.debug({ projectPath }, 'Skipping save for non-existent project path')
121 return
122 }
123
124 const configDir = getConfigDir()
125 const recentProjectsPath = getRecentProjectsPath()
126
127 try {
128 if (!fs.existsSync(configDir)) {
129 fs.mkdirSync(configDir, { recursive: true })
130 }
131
132 // Load existing projects
133 const existingProjects = loadRecentProjects()
134
135 // Remove the project if it already exists (we'll add it back at the top)
136 const filteredProjects = existingProjects.filter(
137 (p) => p.path !== projectPath,
138 )
139
140 // Add the new/updated project at the beginning
141 const updatedProjects: RecentProject[] = [
142 { path: projectPath, lastOpened: Date.now() },
143 ...filteredProjects,
144 ].slice(0, MAX_RECENT_PROJECTS)
145
146 fs.writeFileSync(
147 recentProjectsPath,
148 JSON.stringify(updatedProjects, null, 2),
149 )
150 } catch (error) {
151 logger.debug(
152 { error: error instanceof Error ? error.message : String(error) },
153 'Error saving recent project',
154 )
155 }
156}

Callers 1

AppWithAsyncAuthFunction · 0.90

Calls 3

getConfigDirFunction · 0.90
getRecentProjectsPathFunction · 0.85
loadRecentProjectsFunction · 0.85

Tested by

no test coverage detected