Changesets · Branches · Tags · Compare
| Changeset | 4d749ae79abae4c7b57761fa17e498c4ce76f4a38266b2ba9c20c162927ece1a |
|---|---|
| Author | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-22 10:10 -07:00 |
| Committer | Patrick Erichsen <patrick.a.erichsen@gmail.com> · 2025-05-22 10:10 -07:00 |
| Parents | 6af5a28a34a5 |
7 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 +87 −23
| @@ -25,23 +25,26 @@ | ||
| 25 | 25 | |
| 26 | 26 | const result = await createRuleBlockImpl(args, mockExtras as any); |
| 27 | 27 | |
| 28 | - // Verify that writeFile was called with the correct YAML | |
| 28 | + // Verify that writeFile was called | |
| 29 | 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 | - }); | |
| 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(); | |
| 45 | 48 | }); |
| 46 | 49 | |
| 47 | 50 | it("should create a rule with glob pattern", async () => { |
| @@ -53,14 +56,22 @@ | ||
| 53 | 56 | |
| 54 | 57 | await createRuleBlockImpl(args, mockExtras as any); |
| 55 | 58 | |
| 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({ | |
| 62 | 69 | globs: "**/*.{ts,tsx}", |
| 63 | 70 | }); |
| 71 | + | |
| 72 | + // Verify the content has the rule | |
| 73 | + expect(fileContent).toContain("# TypeScript Rule"); | |
| 74 | + expect(fileContent).toContain("Use interfaces for object shapes"); | |
| 64 | 75 | }); |
| 65 | 76 | |
| 66 | 77 | it("should create a filename based on sanitized rule name", async () => { |
| @@ -73,6 +84,59 @@ | ||
| 73 | 84 | |
| 74 | 85 | // Check that the filename is sanitized |
| 75 | 86 | 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 | + }); | |
| 77 | 141 | }); |
| 78 | 142 | }); |
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"; |
| @@ -7,7 +6,7 @@ | ||
| 7 | 6 | name: string; |
| 8 | 7 | rule: string; |
| 9 | 8 | globs?: string; |
| 10 | - format?: "yaml" | "markdown"; // Add format option with yaml as default | |
| 9 | + description?: string; | |
| 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 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 @@ | ||
| 15 | 15 | faviconUrl: z.string().optional(), |
| 16 | 16 | args: z.array(z.string()).optional(), |
| 17 | 17 | env: z.record(z.string()).optional(), |
| 18 | - connectionTimeout: z.number().gt(0).optional() | |
| 18 | + connectionTimeout: z.number().gt(0).optional(), | |
| 19 | 19 | }); |
| 20 | 20 | |
| 21 | 21 | export type MCPServer = z.infer<typeof mcpServerSchema>; |
| @@ -39,6 +39,7 @@ | ||
| 39 | 39 | const ruleObjectSchema = z.object({ |
| 40 | 40 | name: z.string(), |
| 41 | 41 | rule: z.string(), |
| 42 | + description: z.string().optional(), | |
| 42 | 43 | globs: z.union([z.string(), z.array(z.string())]).optional(), |
| 43 | 44 | }); |
| 44 | 45 | const ruleSchema = z.union([z.string(), ruleObjectSchema]); |