(dirPath: string)
| 150 | // Used by Grep/Glob which take a directory `path` rather than a specific file. |
| 151 | // Checks both configDir and memoryBaseDir to handle custom memory dir paths. |
| 152 | export function isMemoryDirectory(dirPath: string): boolean { |
| 153 | // SECURITY: Normalize to prevent path traversal bypasses via .. segments. |
| 154 | // On Windows this produces backslashes; toComparable flips them back for |
| 155 | // string matching. MinGW /c/... paths are converted to native before |
| 156 | // reaching here (extraction-time in isShellCommandTargetingMemory), so |
| 157 | // normalize() never sees them. |
| 158 | const normalizedPath = normalize(dirPath) |
| 159 | const normalizedCmp = toComparable(normalizedPath) |
| 160 | // Agent memory directories can be under cwd (project scope), configDir, or memoryBaseDir |
| 161 | if ( |
| 162 | isAutoMemoryEnabled() && |
| 163 | (normalizedCmp.includes('/agent-memory/') || |
| 164 | normalizedCmp.includes('/agent-memory-local/')) |
| 165 | ) { |
| 166 | return true |
| 167 | } |
| 168 | // Team memory directories live under <autoMemPath>/team/ |
| 169 | if ( |
| 170 | feature('TEAMMEM') && |
| 171 | teamMemPaths!.isTeamMemoryEnabled() && |
| 172 | teamMemPaths!.isTeamMemPath(normalizedPath) |
| 173 | ) { |
| 174 | return true |
| 175 | } |
| 176 | // Check the auto-memory path override (CLAUDE_COWORK_MEMORY_PATH_OVERRIDE) |
| 177 | if (isAutoMemoryEnabled()) { |
| 178 | const autoMemPath = getAutoMemPath() |
| 179 | const autoMemDirCmp = toComparable(autoMemPath.replace(/[/\\]+$/, '')) |
| 180 | const autoMemPathCmp = toComparable(autoMemPath) |
| 181 | if ( |
| 182 | normalizedCmp === autoMemDirCmp || |
| 183 | normalizedCmp.startsWith(autoMemPathCmp) |
| 184 | ) { |
| 185 | return true |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | const configDirCmp = toComparable(getClaudeConfigHomeDir()) |
| 190 | const memoryBaseCmp = toComparable(getMemoryBaseDir()) |
| 191 | const underConfig = normalizedCmp.startsWith(configDirCmp) |
| 192 | const underMemoryBase = normalizedCmp.startsWith(memoryBaseCmp) |
| 193 | |
| 194 | if (!underConfig && !underMemoryBase) { |
| 195 | return false |
| 196 | } |
| 197 | if (normalizedCmp.includes('/session-memory/')) { |
| 198 | return true |
| 199 | } |
| 200 | if (underConfig && normalizedCmp.includes('/projects/')) { |
| 201 | return true |
| 202 | } |
| 203 | if (isAutoMemoryEnabled() && normalizedCmp.includes('/memory/')) { |
| 204 | return true |
| 205 | } |
| 206 | return false |
| 207 | } |
| 208 | |
| 209 | /** |
no test coverage detected