MCPcopy Create free account
hub / github.com/WJX20/claude-code / getStatOnlyLogsForWorktrees

Function getStatOnlyLogsForWorktrees

src/utils/sessionStorage.ts:4114–4182  ·  view source on GitHub ↗

* Gets stat-only logs for worktree paths (no file reads).

(
  worktreePaths: string[],
  limit?: number,
)

Source from the content-addressed store, hash-verified

4112 * Gets stat-only logs for worktree paths (no file reads).
4113 */
4114async function getStatOnlyLogsForWorktrees(
4115 worktreePaths: string[],
4116 limit?: number,
4117): Promise<LogOption[]> {
4118 const projectsDir = getProjectsDir()
4119
4120 if (worktreePaths.length <= 1) {
4121 const cwd = getOriginalCwd()
4122 const projectDir = getProjectDir(cwd)
4123 return getSessionFilesLite(projectDir, undefined, cwd)
4124 }
4125
4126 // On Windows, drive letter case can differ between git worktree list
4127 // output (e.g. C:/Users/...) and how paths were stored in project
4128 // directories (e.g. c:/Users/...). Use case-insensitive comparison.
4129 const caseInsensitive = process.platform === 'win32'
4130
4131 // Sort worktree paths by sanitized prefix length (longest first) so
4132 // more specific matches take priority over shorter ones. Without this,
4133 // a short prefix like -code-myrepo could match -code-myrepo-worktree1
4134 // before the longer, more specific prefix gets a chance.
4135 const indexed = worktreePaths.map(wt => {
4136 const sanitized = sanitizePath(wt)
4137 return {
4138 path: wt,
4139 prefix: caseInsensitive ? sanitized.toLowerCase() : sanitized,
4140 }
4141 })
4142 indexed.sort((a, b) => b.prefix.length - a.prefix.length)
4143
4144 const allLogs: LogOption[] = []
4145 const seenDirs = new Set<string>()
4146
4147 let allDirents: Dirent[]
4148 try {
4149 allDirents = await readdir(projectsDir, { withFileTypes: true })
4150 } catch (e) {
4151 // Fall back to current project
4152 logForDebugging(
4153 `Failed to read projects dir ${projectsDir}, falling back to current project: ${e}`,
4154 )
4155 const projectDir = getProjectDir(getOriginalCwd())
4156 return getSessionFilesLite(projectDir, limit, getOriginalCwd())
4157 }
4158
4159 for (const dirent of allDirents) {
4160 if (!dirent.isDirectory()) continue
4161 const dirName = caseInsensitive ? dirent.name.toLowerCase() : dirent.name
4162 if (seenDirs.has(dirName)) continue
4163
4164 for (const { path: wtPath, prefix } of indexed) {
4165 if (dirName === prefix || dirName.startsWith(prefix + '-')) {
4166 seenDirs.add(dirName)
4167 allLogs.push(
4168 ...(await getSessionFilesLite(
4169 join(projectsDir, dirent.name),
4170 undefined,
4171 wtPath,

Callers 2

Calls 10

getOriginalCwdFunction · 0.85
getSessionFilesLiteFunction · 0.85
readdirFunction · 0.85
logForDebuggingFunction · 0.85
getProjectsDirFunction · 0.70
getProjectDirFunction · 0.70
sanitizePathFunction · 0.70
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected