MCPcopy Create free account
hub / github.com/Noumena-Network/code / processConditionedMdRules

Function processConditionedMdRules

src/utils/claudemd.ts:1522–1565  ·  view source on GitHub ↗
(
  targetPath: string,
  rulesDir: string,
  type: MemoryType,
  processedPaths: Set<string>,
  includeExternal: boolean,
)

Source from the content-addressed store, hash-verified

1520 * @returns Array of MemoryFileInfo objects that match the target path
1521 */
1522export async function processConditionedMdRules(
1523 targetPath: string,
1524 rulesDir: string,
1525 type: MemoryType,
1526 processedPaths: Set<string>,
1527 includeExternal: boolean,
1528): Promise<MemoryFileInfo[]> {
1529 const conditionedRuleMdFiles = await processMdRules({
1530 rulesDir,
1531 type,
1532 processedPaths,
1533 includeExternal,
1534 conditionalRule: true,
1535 })
1536
1537 // Filter to only include files whose globs patterns match the targetPath
1538 return conditionedRuleMdFiles.filter(file => {
1539 if (!file.globs || file.globs.length === 0) {
1540 return false
1541 }
1542
1543 // For Project rules: glob patterns are relative to the directory containing .claude
1544 // For Managed/User rules: glob patterns are relative to the original CWD
1545 const baseDir =
1546 type === 'Project'
1547 ? dirname(dirname(rulesDir)) // Parent of .claude
1548 : getOriginalCwd() // Project root for managed/user rules
1549
1550 const relativePath = isAbsolute(targetPath)
1551 ? relative(baseDir, targetPath)
1552 : targetPath
1553 // ignore() throws on empty strings, paths escaping the base (../),
1554 // and absolute paths (Windows cross-drive relative() returns absolute).
1555 // Files outside baseDir can't match baseDir-relative globs anyway.
1556 if (
1557 !relativePath ||
1558 relativePath.startsWith('..') ||
1559 isAbsolute(relativePath)
1560 ) {
1561 return false
1562 }
1563 return ignore().add(file.globs).ignores(relativePath)
1564 })
1565}
1566
1567export type ExternalClaudeMdInclude = {
1568 path: string

Calls 3

processMdRulesFunction · 0.85
getOriginalCwdFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected