( targetPath: string, rulesDir: string, type: MemoryType, processedPaths: Set<string>, includeExternal: boolean, )
| 1352 | * @returns Array of MemoryFileInfo objects that match the target path |
| 1353 | */ |
| 1354 | export async function processConditionedMdRules( |
| 1355 | targetPath: string, |
| 1356 | rulesDir: string, |
| 1357 | type: MemoryType, |
| 1358 | processedPaths: Set<string>, |
| 1359 | includeExternal: boolean, |
| 1360 | ): Promise<MemoryFileInfo[]> { |
| 1361 | const conditionedRuleMdFiles = await processMdRules({ |
| 1362 | rulesDir, |
| 1363 | type, |
| 1364 | processedPaths, |
| 1365 | includeExternal, |
| 1366 | conditionalRule: true, |
| 1367 | }) |
| 1368 | |
| 1369 | // Filter to only include files whose globs patterns match the targetPath |
| 1370 | return conditionedRuleMdFiles.filter(file => { |
| 1371 | if (!file.globs || file.globs.length === 0) { |
| 1372 | return false |
| 1373 | } |
| 1374 | |
| 1375 | // For Project rules: glob patterns are relative to the directory containing .claude |
| 1376 | // For Managed/User rules: glob patterns are relative to the original CWD |
| 1377 | const baseDir = |
| 1378 | type === 'Project' |
| 1379 | ? dirname(dirname(rulesDir)) // Parent of .claude |
| 1380 | : getOriginalCwd() // Project root for managed/user rules |
| 1381 | |
| 1382 | const relativePath = isAbsolute(targetPath) |
| 1383 | ? relative(baseDir, targetPath) |
| 1384 | : targetPath |
| 1385 | // ignore() throws on empty strings, paths escaping the base (../), |
| 1386 | // and absolute paths (Windows cross-drive relative() returns absolute). |
| 1387 | // Files outside baseDir can't match baseDir-relative globs anyway. |
| 1388 | if ( |
| 1389 | !relativePath || |
| 1390 | relativePath.startsWith('..') || |
| 1391 | isAbsolute(relativePath) |
| 1392 | ) { |
| 1393 | return false |
| 1394 | } |
| 1395 | return ignore().add(file.globs).ignores(relativePath) |
| 1396 | }) |
| 1397 | } |
| 1398 | |
| 1399 | export type ExternalClaudeMdInclude = { |
| 1400 | path: string |
no test coverage detected