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

Function getTargetRuleDirectory

src/services/rules/rules.ts:291–314  ·  view source on GitHub ↗
(cwd: string, input: Pick<CreateRuleInput, "scope" | "kind" | "modeSlug">)

Source from the content-addressed store, hash-verified

289}
290
291function getTargetRuleDirectory(cwd: string, input: Pick<CreateRuleInput, "scope" | "kind" | "modeSlug">): string {
292 if (input.scope !== "global" && input.scope !== "project") {
293 throw new Error("Invalid rule scope")
294 }
295
296 if (input.kind !== "generic" && input.kind !== "mode") {
297 throw new Error("Invalid rule kind")
298 }
299
300 if (input.kind === "mode" && !input.modeSlug) {
301 throw new Error("Mode-specific rules require a mode")
302 }
303
304 if (input.kind === "generic" && input.modeSlug) {
305 throw new Error("Generic rules cannot specify a mode")
306 }
307
308 if (input.scope === "project" && !cwd) {
309 throw new Error("Workspace rules require an open workspace")
310 }
311
312 const basePath = input.scope === "global" ? getGlobalRooDirectory() : getProjectRooDirectoryForCwd(cwd)
313 return path.join(basePath, input.kind === "generic" ? "rules" : `rules-${validateModeSlug(input.modeSlug!)}`)
314}
315
316function normalizeRuleFileName(fileName: string): string {
317 const trimmed = fileName.trim()

Callers 3

createRuleFunction · 0.85
resolveRuleFileFunction · 0.85
getRulesDirectoryPathFunction · 0.85

Calls 3

getGlobalRooDirectoryFunction · 0.90
validateModeSlugFunction · 0.85

Tested by

no test coverage detected