(absolutePath: string)
| 108 | |
| 109 | // Check if file is within an agent memory directory (any scope). |
| 110 | export function isAgentMemoryPath(absolutePath: string): boolean { |
| 111 | // SECURITY: Normalize to prevent path traversal bypasses via .. segments |
| 112 | const normalizedPath = normalize(absolutePath) |
| 113 | const canonicalMemoryBase = getCanonicalNcodeConfigHomeDir() |
| 114 | const legacyMemoryBase = getLegacyClaudeConfigHomeDir() |
| 115 | |
| 116 | // User scope: check memory base (may be custom dir or config home) |
| 117 | if ( |
| 118 | normalizedPath.startsWith(join(canonicalMemoryBase, 'agent-memory') + sep) || |
| 119 | normalizedPath.startsWith(join(legacyMemoryBase, 'agent-memory') + sep) |
| 120 | ) { |
| 121 | return true |
| 122 | } |
| 123 | |
| 124 | // Project scope: always cwd-based (not redirected) |
| 125 | if ( |
| 126 | normalizedPath.startsWith(join(getCwd(), '.ncode', 'agent-memory') + sep) || |
| 127 | normalizedPath.startsWith(join(getCwd(), '.claude', 'agent-memory') + sep) |
| 128 | ) { |
| 129 | return true |
| 130 | } |
| 131 | |
| 132 | // Local scope: persisted to mount when CLAUDE_CODE_REMOTE_MEMORY_DIR is set, otherwise cwd-based |
| 133 | if (process.env.CLAUDE_CODE_REMOTE_MEMORY_DIR) { |
| 134 | if ( |
| 135 | normalizedPath.includes(sep + 'agent-memory-local' + sep) && |
| 136 | normalizedPath.startsWith( |
| 137 | join(process.env.CLAUDE_CODE_REMOTE_MEMORY_DIR, 'projects') + sep, |
| 138 | ) |
| 139 | ) { |
| 140 | return true |
| 141 | } |
| 142 | } else if ( |
| 143 | normalizedPath.startsWith( |
| 144 | join(getCwd(), '.ncode', 'agent-memory-local') + sep, |
| 145 | ) || |
| 146 | normalizedPath.startsWith( |
| 147 | join(getCwd(), '.claude', 'agent-memory-local') + sep, |
| 148 | ) |
| 149 | ) { |
| 150 | return true |
| 151 | } |
| 152 | |
| 153 | return false |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Returns the agent memory file path for a given agent type and scope. |
no test coverage detected