Elffuss BraidHub

kikocis/continue public

Merge pull request #5799 from continuedev/pe/markdown-rule-desc

feat: `description` in markdown yaml
Changeset28841c20328a01efa4bfc8295d8cb02a700bbe59573e703ff9b5fe15d6ffb75d
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-23 19:16 -07:00
CommitterGitHub <noreply@github.com> · 2025-05-23 19:16 -07:00
Parents59f8d5e2e742, 611a42e81eb8

Browse the files at this changeset

6 files changed

modified core/config/markdown/parseMarkdownRule.test.ts +20 −0
@@ -151,4 +151,24 @@
151151 );
152152 expect(result.name).toBe("custom-rule");
153153 });
154+
155+ it("should include description from frontmatter", () => {
156+ const content = `---
157+globs: "**/test/**/*.kt"
158+name: Test Rule
159+description: This is a rule description from frontmatter
160+---
161+
162+# Test Rule
163+
164+This is the content of the rule.`;
165+
166+ const result = convertMarkdownRuleToContinueRule(
167+ "/path/to/rule.md",
168+ content,
169+ );
170+ expect(result.description).toBe(
171+ "This is a rule description from frontmatter",
172+ );
173+ });
154174 });
modified core/config/markdown/parseMarkdownRule.ts +2 −1
@@ -59,9 +59,10 @@
5959 }
6060
6161 return {
62+ name,
6263 rule: markdown,
6364 globs: frontmatter.globs,
64- name,
65+ description: frontmatter.description,
6566 source: "rules-block",
6667 ruleFile: path,
6768 };
modified core/tools/definitions/createRuleBlock.ts +4 −0
@@ -28,6 +28,10 @@
2828 description:
2929 "Clear, imperative instruction for future code generation (e.g. 'Use named exports', 'Add Python type hints'). Each rule should focus on one specific standard.",
3030 },
31+ description: {
32+ type: "string",
33+ description: "Short description of the rule",
34+ },
3135 globs: {
3236 type: "string",
3337 description:
modified core/tools/implementations/createRuleBlock.test.ts +54 −36
@@ -1,4 +1,4 @@
1-import * as YAML from "yaml";
1+import { parseMarkdownRule } from "../../config/markdown/parseMarkdownRule";
22 import { createRuleBlockImpl } from "./createRuleBlock";
33
44 // Mock the extras parameter with necessary functions
@@ -17,33 +17,6 @@
1717 jest.clearAllMocks();
1818 });
1919
20- it("should create a basic rule with name and rule content", async () => {
21- const args = {
22- name: "Test Rule",
23- rule: "Always write tests",
24- };
25-
26- const result = await createRuleBlockImpl(args, mockExtras as any);
27-
28- // Verify that writeFile was called with the correct YAML
29- expect(mockIde.writeFile).toHaveBeenCalled();
30- const yamlContent = mockIde.writeFile.mock.calls[0][1];
31- const parsedYaml = YAML.parse(yamlContent);
32-
33- // Verify the structure of the YAML
34- expect(parsedYaml).toEqual({
35- name: "Test Rule",
36- version: "0.0.1",
37- schema: "v1",
38- rules: [
39- {
40- name: "Test Rule",
41- rule: "Always write tests",
42- },
43- ],
44- });
45- });
46-
4720 it("should create a rule with glob pattern", async () => {
4821 const args = {
4922 name: "TypeScript Rule",
@@ -53,14 +26,16 @@
5326
5427 await createRuleBlockImpl(args, mockExtras as any);
5528
56- // Verify the YAML structure with globs
57- const yamlContent = mockIde.writeFile.mock.calls[0][1];
58- const parsedYaml = YAML.parse(yamlContent);
59- expect(parsedYaml.rules[0]).toEqual({
60- name: "TypeScript Rule",
61- rule: "Use interfaces for object shapes",
29+ const fileContent = mockIde.writeFile.mock.calls[0][1];
30+
31+ const { frontmatter, markdown } = parseMarkdownRule(fileContent);
32+
33+ expect(frontmatter).toEqual({
6234 globs: "**/*.{ts,tsx}",
6335 });
36+
37+ expect(markdown).toContain("# TypeScript Rule");
38+ expect(markdown).toContain("Use interfaces for object shapes");
6439 });
6540
6641 it("should create a filename based on sanitized rule name", async () => {
@@ -71,8 +46,51 @@
7146
7247 await createRuleBlockImpl(args, mockExtras as any);
7348
74- // Check that the filename is sanitized
7549 const fileUri = mockIde.writeFile.mock.calls[0][0];
76- expect(fileUri).toContain("special-chracters-spaces.yaml");
50+ expect(fileUri).toContain("special-chracters-spaces.md");
51+ });
52+
53+ it("should create a rule with description pattern", async () => {
54+ const args = {
55+ name: "Description Test",
56+ rule: "This is the rule content",
57+ description: "This is a detailed explanation of the rule",
58+ };
59+
60+ await createRuleBlockImpl(args, mockExtras as any);
61+
62+ const fileContent = mockIde.writeFile.mock.calls[0][1];
63+
64+ const { frontmatter, markdown } = parseMarkdownRule(fileContent);
65+
66+ expect(frontmatter).toEqual({
67+ description: "This is a detailed explanation of the rule",
68+ });
69+
70+ expect(markdown).toContain("# Description Test");
71+ expect(markdown).toContain("This is the rule content");
72+ });
73+
74+ it("should include both globs and description in frontmatter", async () => {
75+ const args = {
76+ name: "Complete Rule",
77+ rule: "Follow this standard",
78+ description: "This rule enforces our team standards",
79+ globs: "**/*.js",
80+ };
81+
82+ await createRuleBlockImpl(args, mockExtras as any);
83+
84+ const fileContent = mockIde.writeFile.mock.calls[0][1];
85+
86+ const { frontmatter, markdown } = parseMarkdownRule(fileContent);
87+
88+ expect(frontmatter).toEqual({
89+ description: "This rule enforces our team standards",
90+ globs: "**/*.js",
91+ });
92+
93+ expect(markdown).toContain("# Complete Rule");
94+ expect(markdown).toContain("Follow this standard");
7795 });
7896 });
modified core/tools/implementations/createRuleBlock.ts +16 −36
@@ -1,4 +1,3 @@
1-import { ConfigYaml } from "@continuedev/config-yaml";
21 import * as YAML from "yaml";
32 import { ToolImpl } from ".";
43 import { joinPathsToUri } from "../../util/uri";
@@ -6,8 +5,8 @@
65 export interface CreateRuleBlockArgs {
76 name: string;
87 rule: string;
8+ description: string;
99 globs?: string;
10- format?: "yaml" | "markdown"; // Add format option with yaml as default
1110 }
1211
1312 export const createRuleBlockImpl: ToolImpl = async (
@@ -20,26 +19,19 @@
2019 .replace(/[^a-z0-9\s-]/g, "")
2120 .replace(/\s+/g, "-");
2221
23- // Default to YAML format
24- const format = args.format ?? "yaml";
25- const fileExtension = format === "markdown" ? "md" : "yaml";
26-
27- const ruleObject = {
28- name: args.name,
29- rule: args.rule,
30- ...(args.globs ? { globs: args.globs.trim() } : {}),
31- };
32-
33- let fileContent: string;
34-
35- if (format === "markdown") {
36- // Generate markdown format with frontmatter
37- const frontmatter = {
38- ...(args.globs ? { globs: args.globs.trim() } : {}),
39- };
40-
41- const frontmatterYaml = YAML.stringify(frontmatter).trim();
42- fileContent = `---
22+ const fileExtension = "md";
23+
24+ const frontmatter: Record<string, string> = {};
25+
26+ if (args.globs) {
27+ frontmatter.globs = args.globs.trim();
28+ }
29+
30+ if (args.description) {
31+ frontmatter.description = args.description.trim();
32+ }
33+ const frontmatterYaml = YAML.stringify(frontmatter).trim();
34+ let fileContent = `---
4335 ${frontmatterYaml}
4436 ---
4537
@@ -47,18 +39,6 @@
4739
4840 ${args.rule}
4941 `;
50- } else {
51- // Generate YAML format
52- const ruleBlock: ConfigYaml = {
53- name: args.name,
54- version: "0.0.1",
55- schema: "v1",
56- rules: [ruleObject],
57- };
58-
59- fileContent = YAML.stringify(ruleBlock);
60- }
61-
6242 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
6343 const rulesDirUri = joinPathsToUri(
6444 localContinueDir,
@@ -73,12 +53,12 @@
7353 return [
7454 {
7555 name: "New Rule Block",
76- description: "", // No description throws an error in the GUI
56+ description: args.description || "",
7757 uri: {
7858 type: "file",
7959 value: rulesDirUri,
8060 },
81- content: `Rule created successfully in ${format} format`,
61+ content: `Rule created successfully`,
8262 },
8363 ];
8464 };
modified packages/config-yaml/src/schemas/index.ts +1 −0
@@ -42,6 +42,7 @@
4242 const ruleObjectSchema = z.object({
4343 name: z.string(),
4444 rule: z.string(),
45+ description: z.string().optional(),
4546 globs: z.union([z.string(), z.array(z.string())]).optional(),
4647 });
4748 const ruleSchema = z.union([z.string(), ruleObjectSchema]);