Elffuss BraidHub

kikocis/continue public

feat: `description` in markdown yaml
Changeset4d749ae79abae4c7b57761fa17e498c4ce76f4a38266b2ba9c20c162927ece1a
AuthorPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-22 10:10 -07:00
CommitterPatrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-22 10:10 -07:00
Parents6af5a28a34a5

Browse the files at this changeset

7 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 +87 −23
@@ -25,23 +25,26 @@
2525
2626 const result = await createRuleBlockImpl(args, mockExtras as any);
2727
28- // Verify that writeFile was called with the correct YAML
28+ // Verify that writeFile was called
2929 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- });
30+
31+ // Verify the file name
32+ const fileUri = mockIde.writeFile.mock.calls[0][0];
33+ expect(fileUri).toContain("test-rule.md");
34+
35+ // Get the content
36+ const fileContent = mockIde.writeFile.mock.calls[0][1];
37+
38+ // Verify the content structure
39+ expect(fileContent).toContain("---");
40+ expect(fileContent).toContain("# Test Rule");
41+ expect(fileContent).toContain("Always write tests");
42+
43+ // Should have empty frontmatter - it will be "{}" not "" due to how YAML.stringify works with empty objects
44+ const parts = fileContent.split(/^---\s*$/m);
45+ expect(parts.length).toBeGreaterThanOrEqual(3);
46+ const frontmatterStr = parts[1].trim();
47+ expect(frontmatterStr === "" || frontmatterStr === "{}").toBeTruthy();
4548 });
4649
4750 it("should create a rule with glob pattern", async () => {
@@ -53,14 +56,22 @@
5356
5457 await createRuleBlockImpl(args, mockExtras as any);
5558
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",
59+ // Get the content
60+ const fileContent = mockIde.writeFile.mock.calls[0][1];
61+
62+ // Parse the frontmatter
63+ const parts = fileContent.split(/^---\s*$/m);
64+ const frontmatterStr = parts[1].trim();
65+ const frontmatter = YAML.parse(frontmatterStr);
66+
67+ // Verify the frontmatter contains globs
68+ expect(frontmatter).toEqual({
6269 globs: "**/*.{ts,tsx}",
6370 });
71+
72+ // Verify the content has the rule
73+ expect(fileContent).toContain("# TypeScript Rule");
74+ expect(fileContent).toContain("Use interfaces for object shapes");
6475 });
6576
6677 it("should create a filename based on sanitized rule name", async () => {
@@ -73,6 +84,59 @@
7384
7485 // Check that the filename is sanitized
7586 const fileUri = mockIde.writeFile.mock.calls[0][0];
76- expect(fileUri).toContain("special-chracters-spaces.yaml");
87+ expect(fileUri).toContain("special-chracters-spaces.md");
88+ });
89+
90+ it("should include description in frontmatter and content", async () => {
91+ const args = {
92+ name: "Description Test",
93+ rule: "This is the rule content",
94+ description: "This is a detailed explanation of the rule",
95+ };
96+
97+ await createRuleBlockImpl(args, mockExtras as any);
98+
99+ // Get the content
100+ const fileContent = mockIde.writeFile.mock.calls[0][1];
101+
102+ // Parse the frontmatter
103+ const parts = fileContent.split(/^---\s*$/m);
104+ const frontmatterStr = parts[1].trim();
105+ const frontmatter = YAML.parse(frontmatterStr);
106+
107+ // Verify the frontmatter contains description
108+ expect(frontmatter).toEqual({
109+ description: "This is a detailed explanation of the rule",
110+ });
111+
112+ // Verify the content structure includes description before rule
113+ expect(fileContent).toContain("# Description Test");
114+ expect(fileContent).toContain("This is a detailed explanation of the rule");
115+ expect(fileContent).toContain("This is the rule content");
116+ });
117+
118+ it("should include both globs and description in frontmatter", async () => {
119+ const args = {
120+ name: "Complete Rule",
121+ rule: "Follow this standard",
122+ description: "This rule enforces our team standards",
123+ globs: "**/*.js",
124+ };
125+
126+ await createRuleBlockImpl(args, mockExtras as any);
127+
128+ // Get the content
129+ const fileContent = mockIde.writeFile.mock.calls[0][1];
130+
131+ // Parse the frontmatter
132+ const parts = fileContent.split(/^---\s*$/m);
133+ const frontmatterStr = parts[1].trim();
134+ const frontmatter = YAML.parse(frontmatterStr);
135+
136+ // Verify the frontmatter contains both description and globs
137+ expect(frontmatter).toEqual({
138+ description: "This rule enforces our team standards",
139+ globs: "**/*.js",
140+ });
77141 });
78142 });
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";
@@ -7,7 +6,7 @@
76 name: string;
87 rule: string;
98 globs?: string;
10- format?: "yaml" | "markdown"; // Add format option with yaml as default
9+ description?: string;
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 extensions/vscode/package-lock.json +0 −0

Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.

modified packages/config-yaml/src/schemas/index.ts +2 −1
@@ -15,7 +15,7 @@
1515 faviconUrl: z.string().optional(),
1616 args: z.array(z.string()).optional(),
1717 env: z.record(z.string()).optional(),
18- connectionTimeout: z.number().gt(0).optional()
18+ connectionTimeout: z.number().gt(0).optional(),
1919 });
2020
2121 export type MCPServer = z.infer<typeof mcpServerSchema>;
@@ -39,6 +39,7 @@
3939 const ruleObjectSchema = z.object({
4040 name: z.string(),
4141 rule: z.string(),
42+ description: z.string().optional(),
4243 globs: z.union([z.string(), z.array(z.string())]).optional(),
4344 });
4445 const ruleSchema = z.union([z.string(), ruleObjectSchema]);