MCPcopy Index your code
hub / github.com/codeaashu/claude-code / findProjectDir

Function findProjectDir

src/utils/sessionStoragePortable.ts:354–380  ·  view source on GitHub ↗
(
  projectPath: string,
)

Source from the content-addressed store, hash-verified

352 * prefix-based scanning when the exact match doesn't exist.
353 */
354export async function findProjectDir(
355 projectPath: string,
356): Promise<string | undefined> {
357 const exact = getProjectDir(projectPath)
358 try {
359 await readdir(exact)
360 return exact
361 } catch {
362 // Exact match failed — for short paths this means no sessions exist.
363 // For long paths, try prefix matching to handle hash mismatches.
364 const sanitized = sanitizePath(projectPath)
365 if (sanitized.length <= MAX_SANITIZED_LENGTH) {
366 return undefined
367 }
368 const prefix = sanitized.slice(0, MAX_SANITIZED_LENGTH)
369 const projectsDir = getProjectsDir()
370 try {
371 const dirents = await readdir(projectsDir, { withFileTypes: true })
372 const match = dirents.find(
373 d => d.isDirectory() && d.name.startsWith(prefix + '-'),
374 )
375 return match ? join(projectsDir, match.name) : undefined
376 } catch {
377 return undefined
378 }
379 }
380}
381
382/**
383 * Resolve a sessionId to its on-disk JSONL file path.

Callers 2

gatherProjectCandidatesFunction · 0.85
resolveSessionFilePathFunction · 0.85

Calls 4

readdirFunction · 0.85
getProjectDirFunction · 0.70
sanitizePathFunction · 0.70
getProjectsDirFunction · 0.70

Tested by

no test coverage detected