Skip to content

Commit e310b06

Browse files
authored
Merge pull request #6138 from continuedev/pe/rule-updates-2
feat: move rule parsing to `config-yaml`
2 parents 64151c1 + eaca464 commit e310b06

27 files changed

+459
-407
lines changed

core/config/markdown/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export * from "./createMarkdownRule";
21
export * from "./loadMarkdownRules";
3-
export * from "./parseMarkdownRule";

core/config/markdown/loadCodebaseRules.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { ConfigValidationError } from "@continuedev/config-yaml";
1+
import {
2+
ConfigValidationError,
3+
markdownToRule,
4+
} from "@continuedev/config-yaml";
25
import { IDE, RuleWithSource } from "../..";
36
import { walkDirs } from "../../indexing/walkDir";
47
import { RULES_MARKDOWN_FILENAME } from "../../llm/rules/constants";
58
import { getUriPathBasename } from "../../util/uri";
6-
import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
79

810
/**
911
* Loads rules from rules.md files colocated in the codebase
@@ -29,9 +31,9 @@ export async function loadCodebaseRules(ide: IDE): Promise<{
2931
for (const filePath of rulesMdFiles) {
3032
try {
3133
const content = await ide.readFile(filePath);
32-
const rule = convertMarkdownRuleToContinueRule(filePath, content);
34+
const rule = markdownToRule(content, { uriType: "file", filePath });
3335

34-
rules.push(rule);
36+
rules.push({ ...rule, source: "rules-block" });
3537
} catch (e) {
3638
errors.push({
3739
fatal: false,

core/config/markdown/loadCodebaseRules.vitest.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import { markdownToRule } from "@continuedev/config-yaml";
12
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
23
import { IDE } from "../..";
34
import { walkDirs } from "../../indexing/walkDir";
45
import { loadCodebaseRules } from "./loadCodebaseRules";
5-
import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
66

77
// Mock dependencies
88
vi.mock("../../indexing/walkDir", () => ({
99
walkDirs: vi.fn(),
1010
}));
1111

12-
vi.mock("./parseMarkdownRule", () => ({
13-
convertMarkdownRuleToContinueRule: vi.fn(),
12+
vi.mock("@continuedev/config-yaml", () => ({
13+
markdownToRule: vi.fn(),
1414
}));
1515

1616
describe("loadCodebaseRules", () => {
@@ -82,10 +82,10 @@ describe("loadCodebaseRules", () => {
8282
return Promise.resolve(mockRuleContent[path] || "");
8383
});
8484

85-
// Mock convertMarkdownRuleToContinueRule to return converted rules
86-
(convertMarkdownRuleToContinueRule as any).mockImplementation(
87-
(path: string, content: string) => {
88-
return mockConvertedRules[path];
85+
// Mock markdownToRule to return converted rules
86+
(markdownToRule as any).mockImplementation(
87+
(content: string, options: any) => {
88+
return mockConvertedRules[options.filePath];
8989
},
9090
);
9191
});
@@ -107,7 +107,7 @@ describe("loadCodebaseRules", () => {
107107
expect(mockIde.readFile).toHaveBeenCalledWith(".continue/rules.md");
108108

109109
// Should convert all rules
110-
expect(convertMarkdownRuleToContinueRule).toHaveBeenCalledTimes(4);
110+
expect(markdownToRule).toHaveBeenCalledTimes(4);
111111

112112
// Should return all rules
113113
expect(rules).toHaveLength(4);

core/config/markdown/loadMarkdownRules.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { ConfigValidationError } from "@continuedev/config-yaml";
1+
import {
2+
ConfigValidationError,
3+
markdownToRule,
4+
} from "@continuedev/config-yaml";
25
import { IDE, RuleWithSource } from "../..";
36
import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
4-
import { convertMarkdownRuleToContinueRule } from "./parseMarkdownRule";
57

68
/**
79
* Loads rules from markdown files in the .continue/rules directory
@@ -27,8 +29,11 @@ export async function loadMarkdownRules(ide: IDE): Promise<{
2729
// Process each markdown file
2830
for (const file of mdFiles) {
2931
try {
30-
const rule = convertMarkdownRuleToContinueRule(file.path, file.content);
31-
rules.push(rule);
32+
const rule = markdownToRule(file.content, {
33+
uriType: "file",
34+
filePath: file.path,
35+
});
36+
rules.push({ ...rule, source: "rules-block" });
3237
} catch (e) {
3338
errors.push({
3439
fatal: false,

core/config/markdown/parseMarkdownRule.test.ts

Lines changed: 0 additions & 192 deletions
This file was deleted.

core/config/markdown/utils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
RULE_FILE_EXTENSION,
3+
sanitizeRuleName,
4+
} from "@continuedev/config-yaml";
5+
import { joinPathsToUri } from "../../util/uri";
6+
7+
/**
8+
* Creates the file path for a rule in the workspace .continue/rules directory
9+
*/
10+
export function createRuleFilePath(
11+
workspaceDir: string,
12+
ruleName: string,
13+
): string {
14+
const safeRuleName = sanitizeRuleName(ruleName);
15+
return joinPathsToUri(
16+
workspaceDir,
17+
".continue",
18+
"rules",
19+
`${safeRuleName}.${RULE_FILE_EXTENSION}`,
20+
);
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from "vitest";
2+
import { createRuleFilePath } from "./utils";
3+
4+
describe("createRuleFilePath", () => {
5+
it("should create correct rule file path", () => {
6+
const result = createRuleFilePath("/workspace", "My Test Rule");
7+
expect(result).toBe("/workspace/.continue/rules/my-test-rule.md");
8+
});
9+
10+
it("should handle special characters in rule name", () => {
11+
const result = createRuleFilePath("/home/user", "Rule with @#$% chars");
12+
expect(result).toBe("/home/user/.continue/rules/rule-with-chars.md");
13+
});
14+
15+
it("should handle edge case rule names", () => {
16+
const result = createRuleFilePath("/test", " Multiple Spaces ");
17+
expect(result).toBe("/test/.continue/rules/multiple-spaces.md");
18+
});
19+
});

core/config/workspace/workspaceBlocks.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { BlockType } from "@continuedev/config-yaml";
1+
import { BlockType, RULE_FILE_EXTENSION } from "@continuedev/config-yaml";
22
import { describe, expect, test } from "@jest/globals";
3-
import { RULE_FILE_EXTENSION } from "../markdown";
43
import { findAvailableFilename, getFileContent } from "./workspaceBlocks";
54

65
describe("getFileContent", () => {
76
test("returns markdown content for rules block type", () => {
87
const result = getFileContent("rules");
9-
expect(result).toContain("# New Rule");
108
expect(result).toContain("Your rule content");
119
expect(result).toContain("A description of your rule");
1210
});

core/config/workspace/workspaceBlocks.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { BlockType, ConfigYaml } from "@continuedev/config-yaml";
1+
import {
2+
BlockType,
3+
ConfigYaml,
4+
createRuleMarkdown,
5+
RULE_FILE_EXTENSION,
6+
} from "@continuedev/config-yaml";
27
import * as YAML from "yaml";
38
import { IDE } from "../..";
49
import { joinPathsToUri } from "../../util/uri";
5-
import { RULE_FILE_EXTENSION, createRuleMarkdown } from "../markdown";
610

711
const BLOCK_TYPE_CONFIG: Record<
812
BlockType,

core/config/yaml/loadYaml.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ async function loadConfigYaml(options: {
134134
rootPath,
135135
}),
136136
{
137+
renderSecrets: true,
137138
currentUserSlug: "",
138139
onPremProxyUrl: null,
139140
orgScopeId,
@@ -142,9 +143,7 @@ async function loadConfigYaml(options: {
142143
controlPlaneClient,
143144
ide,
144145
),
145-
renderSecrets: true,
146146
injectBlocks: allLocalBlocks,
147-
asConfigResult: true,
148147
},
149148
);
150149
config = unrollResult.config;

0 commit comments

Comments
 (0)