MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / resolveRuleFile

Function resolveRuleFile

src/services/rules/rules.ts:119–141  ·  view source on GitHub ↗
(cwd: string, input: RuleLookupInput)

Source from the content-addressed store, hash-verified

117}
118
119export async function resolveRuleFile(cwd: string, input: RuleLookupInput): Promise<string | undefined> {
120 const directoryPath = getTargetRuleDirectory(cwd, input)
121 const relativePath = normalizeRelativeRulePath(input.relativePath)
122 const filePath = path.resolve(directoryPath, relativePath)
123
124 assertPathInsideDirectory(filePath, directoryPath)
125
126 try {
127 const stats = await fs.lstat(filePath)
128 if (stats.isFile() || stats.isSymbolicLink()) {
129 await assertRealPathInsideDirectory(filePath, directoryPath)
130 return filePath
131 }
132 } catch (error) {
133 if (["ENOENT", "ENOTDIR"].includes((error as NodeJS.ErrnoException).code ?? "")) {
134 return undefined
135 }
136
137 throw error
138 }
139
140 return undefined
141}
142
143export function getRulesDirectoryPath(
144 cwd: string,

Callers 3

handleOpenRuleFileFunction · 0.90
deleteRuleFunction · 0.85
rules.spec.tsFile · 0.85

Calls 4

getTargetRuleDirectoryFunction · 0.85

Tested by

no test coverage detected