Changesets · Branches · Tags · Compare
| Changeset | 28841c20328a01efa4bfc8295d8cb02a700bbe59573e703ff9b5fe15d6ffb75d |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-23 19:16 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-05-23 19:16 -07:00 |
| Parents | 59f8d5e2e742, 611a42e81eb8 |
6 files changed
modified core/config/markdown/parseMarkdownRule.test.ts +20 −0
| @@ -151,4 +151,24 @@ | ||
| 151 | 151 | ); |
| 152 | 152 | expect(result.name).toBe("custom-rule"); |
| 153 | 153 | }); |
| 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 | + }); | |
| 154 | 174 | }); |
modified core/config/markdown/parseMarkdownRule.ts +2 −1
| @@ -59,9 +59,10 @@ | ||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | return { |
| 62 | + name, | |
| 62 | 63 | rule: markdown, |
| 63 | 64 | globs: frontmatter.globs, |
| 64 | - name, | |
| 65 | + description: frontmatter.description, | |
| 65 | 66 | source: "rules-block", |
| 66 | 67 | ruleFile: path, |
| 67 | 68 | }; |
modified core/tools/definitions/createRuleBlock.ts +4 −0
| @@ -28,6 +28,10 @@ | ||
| 28 | 28 | description: |
| 29 | 29 | "Clear, imperative instruction for future code generation (e.g. 'Use named exports', 'Add Python type hints'). Each rule should focus on one specific standard.", |
| 30 | 30 | }, |
| 31 | + description: { | |
| 32 | + type: "string", | |
| 33 | + description: "Short description of the rule", | |
| 34 | + }, | |
| 31 | 35 | globs: { |
| 32 | 36 | type: "string", |
| 33 | 37 | 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"; | |
| 2 | 2 | import { createRuleBlockImpl } from "./createRuleBlock"; |
| 3 | 3 | |
| 4 | 4 | // Mock the extras parameter with necessary functions |
| @@ -17,33 +17,6 @@ | ||
| 17 | 17 | jest.clearAllMocks(); |
| 18 | 18 | }); |
| 19 | 19 | |
| 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 | - | |
| 47 | 20 | it("should create a rule with glob pattern", async () => { |
| 48 | 21 | const args = { |
| 49 | 22 | name: "TypeScript Rule", |
| @@ -53,14 +26,16 @@ | ||
| 53 | 26 | |
| 54 | 27 | await createRuleBlockImpl(args, mockExtras as any); |
| 55 | 28 | |
| 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({ | |
| 62 | 34 | globs: "**/*.{ts,tsx}", |
| 63 | 35 | }); |
| 36 | + | |
| 37 | + expect(markdown).toContain("# TypeScript Rule"); | |
| 38 | + expect(markdown).toContain("Use interfaces for object shapes"); | |
| 64 | 39 | }); |
| 65 | 40 | |
| 66 | 41 | it("should create a filename based on sanitized rule name", async () => { |
| @@ -71,8 +46,51 @@ | ||
| 71 | 46 | |
| 72 | 47 | await createRuleBlockImpl(args, mockExtras as any); |
| 73 | 48 | |
| 74 | - // Check that the filename is sanitized | |
| 75 | 49 | 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"); | |
| 77 | 95 | }); |
| 78 | 96 | }); |
modified core/tools/implementations/createRuleBlock.ts +16 −36
| @@ -1,4 +1,3 @@ | ||
| 1 | -import { ConfigYaml } from "@continuedev/config-yaml"; | |
| 2 | 1 | import * as YAML from "yaml"; |
| 3 | 2 | import { ToolImpl } from "."; |
| 4 | 3 | import { joinPathsToUri } from "../../util/uri"; |
| @@ -6,8 +5,8 @@ | ||
| 6 | 5 | export interface CreateRuleBlockArgs { |
| 7 | 6 | name: string; |
| 8 | 7 | rule: string; |
| 8 | + description: string; | |
| 9 | 9 | globs?: string; |
| 10 | - format?: "yaml" | "markdown"; // Add format option with yaml as default | |
| 11 | 10 | } |
| 12 | 11 | |
| 13 | 12 | export const createRuleBlockImpl: ToolImpl = async ( |
| @@ -20,26 +19,19 @@ | ||
| 20 | 19 | .replace(/[^a-z0-9\s-]/g, "") |
| 21 | 20 | .replace(/\s+/g, "-"); |
| 22 | 21 | |
| 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 = `--- | |
| 43 | 35 | ${frontmatterYaml} |
| 44 | 36 | --- |
| 45 | 37 | |
| @@ -47,18 +39,6 @@ | ||
| 47 | 39 | |
| 48 | 40 | ${args.rule} |
| 49 | 41 | `; |
| 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 | - | |
| 62 | 42 | const [localContinueDir] = await extras.ide.getWorkspaceDirs(); |
| 63 | 43 | const rulesDirUri = joinPathsToUri( |
| 64 | 44 | localContinueDir, |
| @@ -73,12 +53,12 @@ | ||
| 73 | 53 | return [ |
| 74 | 54 | { |
| 75 | 55 | name: "New Rule Block", |
| 76 | - description: "", // No description throws an error in the GUI | |
| 56 | + description: args.description || "", | |
| 77 | 57 | uri: { |
| 78 | 58 | type: "file", |
| 79 | 59 | value: rulesDirUri, |
| 80 | 60 | }, |
| 81 | - content: `Rule created successfully in ${format} format`, | |
| 61 | + content: `Rule created successfully`, | |
| 82 | 62 | }, |
| 83 | 63 | ]; |
| 84 | 64 | }; |
modified packages/config-yaml/src/schemas/index.ts +1 −0
| @@ -42,6 +42,7 @@ | ||
| 42 | 42 | const ruleObjectSchema = z.object({ |
| 43 | 43 | name: z.string(), |
| 44 | 44 | rule: z.string(), |
| 45 | + description: z.string().optional(), | |
| 45 | 46 | globs: z.union([z.string(), z.array(z.string())]).optional(), |
| 46 | 47 | }); |
| 47 | 48 | const ruleSchema = z.union([z.string(), ruleObjectSchema]); |