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

Function resolveSessionFilePath

src/utils/sessionStoragePortable.ts:403–466  ·  view source on GitHub ↗
(
  sessionId: string,
  dir?: string,
)

Source from the content-addressed store, hash-verified

401 * resolved path.
402 */
403export async function resolveSessionFilePath(
404 sessionId: string,
405 dir?: string,
406): Promise<
407 | { filePath: string; projectPath: string | undefined; fileSize: number }
408 | undefined
409> {
410 const fileName = `${sessionId}.jsonl`
411
412 if (dir) {
413 const canonical = await canonicalizePath(dir)
414 const projectDir = await findProjectDir(canonical)
415 if (projectDir) {
416 const filePath = join(projectDir, fileName)
417 try {
418 const s = await stat(filePath)
419 if (s.size > 0)
420 return { filePath, projectPath: canonical, fileSize: s.size }
421 } catch {
422 // ENOENT/EACCES — keep searching
423 }
424 }
425 // Worktree fallback — sessions may live under a different worktree root
426 let worktreePaths: string[]
427 try {
428 worktreePaths = await getWorktreePathsPortable(canonical)
429 } catch {
430 worktreePaths = []
431 }
432 for (const wt of worktreePaths) {
433 if (wt === canonical) continue
434 const wtProjectDir = await findProjectDir(wt)
435 if (!wtProjectDir) continue
436 const filePath = join(wtProjectDir, fileName)
437 try {
438 const s = await stat(filePath)
439 if (s.size > 0) return { filePath, projectPath: wt, fileSize: s.size }
440 } catch {
441 // ENOENT/EACCES — keep searching
442 }
443 }
444 return undefined
445 }
446
447 // No dir — scan all project directories
448 const projectsDir = getProjectsDir()
449 let dirents: string[]
450 try {
451 dirents = await readdir(projectsDir)
452 } catch {
453 return undefined
454 }
455 for (const name of dirents) {
456 const filePath = join(projectsDir, name, fileName)
457 try {
458 const s = await stat(filePath)
459 if (s.size > 0)
460 return { filePath, projectPath: undefined, fileSize: s.size }

Callers

nothing calls this directly

Calls 6

canonicalizePathFunction · 0.85
findProjectDirFunction · 0.85
statFunction · 0.85
getWorktreePathsPortableFunction · 0.85
readdirFunction · 0.85
getProjectsDirFunction · 0.70

Tested by

no test coverage detected