Elffuss BraidHub

kikocis/continue public

6e4b7e9fc0a8 · 1017 BRawPermalink
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 const fileContent = createRuleMarkdown(name, rule, otherArgs);
17
18 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
19 const ruleFilePath = createRuleFilePath(localContinueDir, name);
20
21 await extras.ide.writeFile(ruleFilePath, fileContent);
22 await extras.ide.openFile(ruleFilePath);
23
24 return [
25 {
26 name: "New Rule Block",
27 description: otherArgs.description || "",
28 uri: {
29 type: "file",
30 value: ruleFilePath,
31 },
32 content: `Rule created successfully`,
33 },
34 ];
35};