| 1 | import { |
| 2 | RULE_FILE_EXTENSION, |
| 3 | sanitizeRuleName, |
| 4 | } from "@continuedev/config-yaml"; |
| 5 | import { joinPathsToUri } from "../../util/uri"; |
| 6 | |
| 7 | function createRelativeRuleFilePathParts(ruleName: string): string[] { |
| 8 | const safeRuleName = sanitizeRuleName(ruleName); |
| 9 | return [".continue", "rules", `${safeRuleName}.${RULE_FILE_EXTENSION}`]; |
| 10 | } |
| 11 | |
| 12 | export function createRelativeRuleFilePath(ruleName: string): string { |
| 13 | return createRelativeRuleFilePathParts(ruleName).join("/"); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Creates the file path for a rule in the workspace .continue/rules directory |
| 18 | */ |
| 19 | export function createRuleFilePath( |
| 20 | workspaceDir: string, |
| 21 | ruleName: string, |
| 22 | ): string { |
| 23 | return joinPathsToUri( |
| 24 | workspaceDir, |
| 25 | ...createRelativeRuleFilePathParts(ruleName), |
| 26 | ); |
| 27 | } |