| 1 | import { ConfigValidationError } from "@continuedev/config-yaml"; |
| 2 | import { IDE, RuleWithSource } from ".."; |
| 3 | import { joinPathsToUri } from "../util/uri"; |
| 4 | export const SYSTEM_PROMPT_DOT_FILE = ".continuerules"; |
| 5 | |
| 6 | export async function getWorkspaceContinueRuleDotFiles(ide: IDE) { |
| 7 | const dirs = await ide.getWorkspaceDirs(); |
| 8 | |
| 9 | const errors: ConfigValidationError[] = []; |
| 10 | const rules: RuleWithSource[] = []; |
| 11 | for (const dir of dirs) { |
| 12 | try { |
| 13 | const dotFile = joinPathsToUri(dir, SYSTEM_PROMPT_DOT_FILE); |
| 14 | const exists = await ide.fileExists(dotFile); |
| 15 | if (exists) { |
| 16 | const content = await ide.readFile(dotFile); |
| 17 | rules.push({ |
| 18 | rule: content, |
| 19 | ruleFile: dotFile, |
| 20 | source: ".continuerules", |
| 21 | }); |
| 22 | } |
| 23 | } catch (e) { |
| 24 | errors.push({ |
| 25 | fatal: false, |
| 26 | message: `Failed to load system prompt dot file from workspace ${dir}: ${e instanceof Error ? e.message : e}`, |
| 27 | }); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | return { rules, errors }; |
| 32 | } |