Elffuss BraidHub

kikocis/continue public

6072b6346135 · 1.2 KiBRawPermalink
1import { createRuleMarkdown } from "@continuedev/config-yaml";
2import { ToolImpl } from ".";
3import { RuleWithSource } from "../..";
4import { createRuleFilePath } from "../../config/markdown/utils";
5
6export type CreateRuleBlockArgs = Pick<
7 Required<RuleWithSource>,
8 "rule" | "description" | "alwaysApply" | "name"
9> &
10 Pick<RuleWithSource, "globs" | "regex">;
11
12export const createRuleBlockImpl: ToolImpl = async (
13 args: CreateRuleBlockArgs,
14 extras,
15) => {
16 // Create options object with the fields that createRuleMarkdown expects
17 const options: any = {
18 description: args.description,
19 globs: args.globs,
20 };
21
22 // Add regex if provided
23 if (args.regex) {
24 options.regex = args.regex;
25 }
26
27 const fileContent = createRuleMarkdown(args.name, args.rule, options);
28
29 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
30 const ruleFilePath = createRuleFilePath(localContinueDir, args.name);
31
32 await extras.ide.writeFile(ruleFilePath, fileContent);
33 await extras.ide.openFile(ruleFilePath);
34
35 return [
36 {
37 name: "New Rule Block",
38 description: args.description || "",
39 uri: {
40 type: "file",
41 value: ruleFilePath,
42 },
43 content: `Rule created successfully`,
44 },
45 ];
46};