MCPcopy Index your code
hub / github.com/Noumena-Network/code / isMemoryDirectory

Function isMemoryDirectory

src/utils/memoryFileDetection.ts:152–215  ·  view source on GitHub ↗
(dirPath: string)

Source from the content-addressed store, hash-verified

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.
152export 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 const isInstructionRulesDir =
194 normalizedCmp.includes('/.claude/rules') || normalizedCmp.includes('/.ncode/rules')
195 const isInstructionConfigDir =
196 normalizedCmp.endsWith('/.claude') || normalizedCmp.endsWith('/.ncode')
197
198 if (isInstructionRulesDir || isInstructionConfigDir) {
199 return true
200 }
201
202 if (!underConfig && !underMemoryBase) {
203 return false
204 }
205 if (normalizedCmp.includes('/session-memory/')) {
206 return true
207 }
208 if (underConfig && normalizedCmp.includes('/projects/')) {
209 return true

Callers 2

isMemorySearchFunction · 0.85

Calls 4

toComparableFunction · 0.85
isAutoMemoryEnabledFunction · 0.85
getMemoryBaseDirFunction · 0.85
normalizeFunction · 0.50

Tested by

no test coverage detected