Elffuss BraidHub

kikocis/continue public

e4890227bbc5 · 1.0 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">;
11
12export const createRuleBlockImpl: ToolImpl = async (
13 args: CreateRuleBlockArgs,
14 extras,
15) => {
16 const fileContent = createRuleMarkdown(args.name, args.rule, {
17 description: args.description,
18 globs: args.globs,
19 });
20
21 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
22 const ruleFilePath = createRuleFilePath(localContinueDir, args.name);
23
24 await extras.ide.writeFile(ruleFilePath, fileContent);
25 await extras.ide.openFile(ruleFilePath);
26
27 return [
28 {
29 name: "New Rule Block",
30 description: args.description || "",
31 uri: {
32 type: "file",
33 value: ruleFilePath,
34 },
35 content: `Rule created successfully`,
36 },
37 ];
38};