Elffuss BraidHub

kikocis/continue public

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