MCPcopy Create free account
hub / github.com/continuedev/continue / loadCodebaseRules

Function loadCodebaseRules

core/config/markdown/loadCodebaseRules.ts:67–129  ·  view source on GitHub ↗
(ide: IDE)

Source from the content-addressed store, hash-verified

65 * Loads rules from rules.md files colocated in the codebase
66 */
67export async function loadCodebaseRules(ide: IDE): Promise<{
68 rules: RuleWithSource[];
69 errors: ConfigValidationError[];
70}> {
71 const errors: ConfigValidationError[] = [];
72 const rules: RuleWithSource[] = [];
73
74 try {
75 // Get all files from the workspace
76 const allFiles = await walkDirs(ide);
77
78 // Filter to just rules.md files
79 const rulesMdFiles = allFiles.filter((file) => {
80 const filename = getUriPathBasename(file);
81 return filename === RULES_MARKDOWN_FILENAME;
82 });
83
84 // Process each rules.md file
85 for (const filePath of rulesMdFiles) {
86 try {
87 const content = await ide.readFile(filePath);
88 const { relativePathOrBasename, foundInDir, uri } = findUriInDirs(
89 filePath,
90 await ide.getWorkspaceDirs(),
91 );
92 if (foundInDir) {
93 const lastSlashIndex = relativePathOrBasename.lastIndexOf("/");
94 const parentDir = relativePathOrBasename.substring(0, lastSlashIndex);
95 const rule = markdownToRule(
96 content,
97 {
98 uriType: "file",
99 fileUri: uri,
100 },
101 parentDir,
102 );
103
104 rules.push({
105 ...rule,
106 source: "colocated-markdown",
107 sourceFile: filePath,
108 });
109 } else {
110 console.warn(
111 `Failed to load codebase rule ${uri}: URI not found in workspace dirs`,
112 );
113 }
114 } catch (e) {
115 errors.push({
116 fatal: false,
117 message: `Failed to parse colocated rule file ${filePath}: ${e instanceof Error ? e.message : e}`,
118 });
119 }
120 }
121 } catch (e) {
122 errors.push({
123 fatal: false,
124 message: `Error loading colocated rule files: ${e instanceof Error ? e.message : e}`,

Callers 2

refreshMethod · 0.85

Calls 8

walkDirsFunction · 0.90
getUriPathBasenameFunction · 0.90
findUriInDirsFunction · 0.90
markdownToRuleFunction · 0.90
warnMethod · 0.80
readFileMethod · 0.65
getWorkspaceDirsMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected