Elffuss BraidHub

kikocis/continue public

9ea2d7361601 · 1.1 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" | "name"
9> &
10 Pick<RuleWithSource, "globs" | "regex" | "description" | "alwaysApply">;
11
12export const createRuleBlockImpl: ToolImpl = async (
13 { name, rule, ...otherArgs }: CreateRuleBlockArgs,
14 extras,
15) => {
16 if (!name || !rule) {
17 throw new Error(
18 "`name` and `rule` arguments are required to create a rule.",
19 );
20 }
21 const fileContent = createRuleMarkdown(name, rule, otherArgs);
22
23 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
24 const ruleFilePath = createRuleFilePath(localContinueDir, name);
25
26 await extras.ide.writeFile(ruleFilePath, fileContent);
27 await extras.ide.openFile(ruleFilePath);
28
29 return [
30 {
31 name: "New Rule Block",
32 description: otherArgs.description || "",
33 uri: {
34 type: "file",
35 value: ruleFilePath,
36 },
37 content: `Rule created successfully`,
38 },
39 ];
40};