feat: description in markdown yaml
This commit is contained in:
parent
2bad1383bd
commit
e4b70dbfd8
7 changed files with 129 additions and 59 deletions
|
|
@ -151,4 +151,24 @@ This is a test rule without a heading.`;
|
|||
);
|
||||
expect(result.name).toBe("custom-rule");
|
||||
});
|
||||
|
||||
it("should include description from frontmatter", () => {
|
||||
const content = `---
|
||||
globs: "**/test/**/*.kt"
|
||||
name: Test Rule
|
||||
description: This is a rule description from frontmatter
|
||||
---
|
||||
|
||||
# Test Rule
|
||||
|
||||
This is the content of the rule.`;
|
||||
|
||||
const result = convertMarkdownRuleToContinueRule(
|
||||
"/path/to/rule.md",
|
||||
content,
|
||||
);
|
||||
expect(result.description).toBe(
|
||||
"This is a rule description from frontmatter",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -59,9 +59,10 @@ export function convertMarkdownRuleToContinueRule(
|
|||
}
|
||||
|
||||
return {
|
||||
name,
|
||||
rule: markdown,
|
||||
globs: frontmatter.globs,
|
||||
name,
|
||||
description: frontmatter.description,
|
||||
source: "rules-block",
|
||||
ruleFile: path,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ export const createRuleBlock: Tool = {
|
|||
description:
|
||||
"Clear, imperative instruction for future code generation (e.g. 'Use named exports', 'Add Python type hints'). Each rule should focus on one specific standard.",
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
description: "Short description of the rule",
|
||||
},
|
||||
globs: {
|
||||
type: "string",
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -25,23 +25,26 @@ describe("createRuleBlockImpl", () => {
|
|||
|
||||
const result = await createRuleBlockImpl(args, mockExtras as any);
|
||||
|
||||
// Verify that writeFile was called with the correct YAML
|
||||
// Verify that writeFile was called
|
||||
expect(mockIde.writeFile).toHaveBeenCalled();
|
||||
const yamlContent = mockIde.writeFile.mock.calls[0][1];
|
||||
const parsedYaml = YAML.parse(yamlContent);
|
||||
|
||||
// Verify the structure of the YAML
|
||||
expect(parsedYaml).toEqual({
|
||||
name: "Test Rule",
|
||||
version: "0.0.1",
|
||||
schema: "v1",
|
||||
rules: [
|
||||
{
|
||||
name: "Test Rule",
|
||||
rule: "Always write tests",
|
||||
},
|
||||
],
|
||||
});
|
||||
// Verify the file name
|
||||
const fileUri = mockIde.writeFile.mock.calls[0][0];
|
||||
expect(fileUri).toContain("test-rule.md");
|
||||
|
||||
// Get the content
|
||||
const fileContent = mockIde.writeFile.mock.calls[0][1];
|
||||
|
||||
// Verify the content structure
|
||||
expect(fileContent).toContain("---");
|
||||
expect(fileContent).toContain("# Test Rule");
|
||||
expect(fileContent).toContain("Always write tests");
|
||||
|
||||
// Should have empty frontmatter - it will be "{}" not "" due to how YAML.stringify works with empty objects
|
||||
const parts = fileContent.split(/^---\s*$/m);
|
||||
expect(parts.length).toBeGreaterThanOrEqual(3);
|
||||
const frontmatterStr = parts[1].trim();
|
||||
expect(frontmatterStr === "" || frontmatterStr === "{}").toBeTruthy();
|
||||
});
|
||||
|
||||
it("should create a rule with glob pattern", async () => {
|
||||
|
|
@ -53,14 +56,22 @@ describe("createRuleBlockImpl", () => {
|
|||
|
||||
await createRuleBlockImpl(args, mockExtras as any);
|
||||
|
||||
// Verify the YAML structure with globs
|
||||
const yamlContent = mockIde.writeFile.mock.calls[0][1];
|
||||
const parsedYaml = YAML.parse(yamlContent);
|
||||
expect(parsedYaml.rules[0]).toEqual({
|
||||
name: "TypeScript Rule",
|
||||
rule: "Use interfaces for object shapes",
|
||||
// Get the content
|
||||
const fileContent = mockIde.writeFile.mock.calls[0][1];
|
||||
|
||||
// Parse the frontmatter
|
||||
const parts = fileContent.split(/^---\s*$/m);
|
||||
const frontmatterStr = parts[1].trim();
|
||||
const frontmatter = YAML.parse(frontmatterStr);
|
||||
|
||||
// Verify the frontmatter contains globs
|
||||
expect(frontmatter).toEqual({
|
||||
globs: "**/*.{ts,tsx}",
|
||||
});
|
||||
|
||||
// Verify the content has the rule
|
||||
expect(fileContent).toContain("# TypeScript Rule");
|
||||
expect(fileContent).toContain("Use interfaces for object shapes");
|
||||
});
|
||||
|
||||
it("should create a filename based on sanitized rule name", async () => {
|
||||
|
|
@ -73,6 +84,59 @@ describe("createRuleBlockImpl", () => {
|
|||
|
||||
// Check that the filename is sanitized
|
||||
const fileUri = mockIde.writeFile.mock.calls[0][0];
|
||||
expect(fileUri).toContain("special-chracters-spaces.yaml");
|
||||
expect(fileUri).toContain("special-chracters-spaces.md");
|
||||
});
|
||||
|
||||
it("should include description in frontmatter and content", async () => {
|
||||
const args = {
|
||||
name: "Description Test",
|
||||
rule: "This is the rule content",
|
||||
description: "This is a detailed explanation of the rule",
|
||||
};
|
||||
|
||||
await createRuleBlockImpl(args, mockExtras as any);
|
||||
|
||||
// Get the content
|
||||
const fileContent = mockIde.writeFile.mock.calls[0][1];
|
||||
|
||||
// Parse the frontmatter
|
||||
const parts = fileContent.split(/^---\s*$/m);
|
||||
const frontmatterStr = parts[1].trim();
|
||||
const frontmatter = YAML.parse(frontmatterStr);
|
||||
|
||||
// Verify the frontmatter contains description
|
||||
expect(frontmatter).toEqual({
|
||||
description: "This is a detailed explanation of the rule",
|
||||
});
|
||||
|
||||
// Verify the content structure includes description before rule
|
||||
expect(fileContent).toContain("# Description Test");
|
||||
expect(fileContent).toContain("This is a detailed explanation of the rule");
|
||||
expect(fileContent).toContain("This is the rule content");
|
||||
});
|
||||
|
||||
it("should include both globs and description in frontmatter", async () => {
|
||||
const args = {
|
||||
name: "Complete Rule",
|
||||
rule: "Follow this standard",
|
||||
description: "This rule enforces our team standards",
|
||||
globs: "**/*.js",
|
||||
};
|
||||
|
||||
await createRuleBlockImpl(args, mockExtras as any);
|
||||
|
||||
// Get the content
|
||||
const fileContent = mockIde.writeFile.mock.calls[0][1];
|
||||
|
||||
// Parse the frontmatter
|
||||
const parts = fileContent.split(/^---\s*$/m);
|
||||
const frontmatterStr = parts[1].trim();
|
||||
const frontmatter = YAML.parse(frontmatterStr);
|
||||
|
||||
// Verify the frontmatter contains both description and globs
|
||||
expect(frontmatter).toEqual({
|
||||
description: "This rule enforces our team standards",
|
||||
globs: "**/*.js",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { ConfigYaml } from "@continuedev/config-yaml";
|
||||
import * as YAML from "yaml";
|
||||
import { ToolImpl } from ".";
|
||||
import { joinPathsToUri } from "../../util/uri";
|
||||
|
|
@ -7,7 +6,7 @@ export interface CreateRuleBlockArgs {
|
|||
name: string;
|
||||
rule: string;
|
||||
globs?: string;
|
||||
format?: "yaml" | "markdown"; // Add format option with yaml as default
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export const createRuleBlockImpl: ToolImpl = async (
|
||||
|
|
@ -20,26 +19,19 @@ export const createRuleBlockImpl: ToolImpl = async (
|
|||
.replace(/[^a-z0-9\s-]/g, "")
|
||||
.replace(/\s+/g, "-");
|
||||
|
||||
// Default to YAML format
|
||||
const format = args.format ?? "yaml";
|
||||
const fileExtension = format === "markdown" ? "md" : "yaml";
|
||||
const fileExtension = "md";
|
||||
|
||||
const ruleObject = {
|
||||
name: args.name,
|
||||
rule: args.rule,
|
||||
...(args.globs ? { globs: args.globs.trim() } : {}),
|
||||
};
|
||||
const frontmatter: Record<string, string> = {};
|
||||
|
||||
let fileContent: string;
|
||||
if (args.globs) {
|
||||
frontmatter.globs = args.globs.trim();
|
||||
}
|
||||
|
||||
if (format === "markdown") {
|
||||
// Generate markdown format with frontmatter
|
||||
const frontmatter = {
|
||||
...(args.globs ? { globs: args.globs.trim() } : {}),
|
||||
};
|
||||
|
||||
const frontmatterYaml = YAML.stringify(frontmatter).trim();
|
||||
fileContent = `---
|
||||
if (args.description) {
|
||||
frontmatter.description = args.description.trim();
|
||||
}
|
||||
const frontmatterYaml = YAML.stringify(frontmatter).trim();
|
||||
let fileContent = `---
|
||||
${frontmatterYaml}
|
||||
---
|
||||
|
||||
|
|
@ -47,18 +39,6 @@ ${frontmatterYaml}
|
|||
|
||||
${args.rule}
|
||||
`;
|
||||
} else {
|
||||
// Generate YAML format
|
||||
const ruleBlock: ConfigYaml = {
|
||||
name: args.name,
|
||||
version: "0.0.1",
|
||||
schema: "v1",
|
||||
rules: [ruleObject],
|
||||
};
|
||||
|
||||
fileContent = YAML.stringify(ruleBlock);
|
||||
}
|
||||
|
||||
const [localContinueDir] = await extras.ide.getWorkspaceDirs();
|
||||
const rulesDirUri = joinPathsToUri(
|
||||
localContinueDir,
|
||||
|
|
@ -73,12 +53,12 @@ ${args.rule}
|
|||
return [
|
||||
{
|
||||
name: "New Rule Block",
|
||||
description: "", // No description throws an error in the GUI
|
||||
description: args.description || "",
|
||||
uri: {
|
||||
type: "file",
|
||||
value: rulesDirUri,
|
||||
},
|
||||
content: `Rule created successfully in ${format} format`,
|
||||
content: `Rule created successfully`,
|
||||
},
|
||||
];
|
||||
};
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.36",
|
||||
"version": "1.1.38",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.36",
|
||||
"version": "1.1.38",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/config-types": "^1.0.14",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const mcpServerSchema = z.object({
|
|||
faviconUrl: z.string().optional(),
|
||||
args: z.array(z.string()).optional(),
|
||||
env: z.record(z.string()).optional(),
|
||||
connectionTimeout: z.number().gt(0).optional()
|
||||
connectionTimeout: z.number().gt(0).optional(),
|
||||
});
|
||||
|
||||
export type MCPServer = z.infer<typeof mcpServerSchema>;
|
||||
|
|
@ -39,6 +39,7 @@ export type DocsConfig = z.infer<typeof docSchema>;
|
|||
const ruleObjectSchema = z.object({
|
||||
name: z.string(),
|
||||
rule: z.string(),
|
||||
description: z.string().optional(),
|
||||
globs: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
});
|
||||
const ruleSchema = z.union([z.string(), ruleObjectSchema]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue