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

Function getMostRecentChatDir

cli/src/project-files.ts:59–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57 * Returns null if no chat directories exist
58 */
59export function getMostRecentChatDir(): string | null {
60 try {
61 const chatsDir = path.join(getProjectDataDir(), 'chats')
62 if (!statSync(chatsDir, { throwIfNoEntry: false })) {
63 return null
64 }
65
66 const chatDirs = readdirSync(chatsDir)
67 .map((name) => {
68 const fullPath = path.join(chatsDir, name)
69 try {
70 const stat = statSync(fullPath)
71 return { name, fullPath, mtime: stat.mtime }
72 } catch {
73 return null
74 }
75 })
76 .filter(
77 (item): item is { name: string; fullPath: string; mtime: Date } =>
78 item !== null && statSync(item.fullPath).isDirectory(),
79 )
80
81 if (chatDirs.length === 0) {
82 return null
83 }
84
85 // Sort by modification time, most recent first
86 chatDirs.sort((a, b) => b.mtime.getTime() - a.mtime.getTime())
87 return chatDirs[0].fullPath
88 } catch {
89 return null
90 }
91}
92
93export function getCurrentChatDir(): string {
94 const chatId = getCurrentChatId()

Callers 1

loadMostRecentChatStateFunction · 0.90

Calls 1

getProjectDataDirFunction · 0.85

Tested by

no test coverage detected