Elffuss BraidHub

kikocis/continue public

d077bc7a38b2 · 998 BRawPermalink
1import { ToolImpl } from ".";
2import { RuleWithSource } from "../..";
3import { createRuleFilePath, createRuleMarkdown } from "../../config/markdown";
4
5export type CreateRuleBlockArgs = Pick<
6 Required<RuleWithSource>,
7 "rule" | "description" | "alwaysApply" | "name"
8> &
9 Pick<RuleWithSource, "globs">;
10
11export const createRuleBlockImpl: ToolImpl = async (
12 args: CreateRuleBlockArgs,
13 extras,
14) => {
15 const fileContent = createRuleMarkdown(args.name, args.rule, {
16 description: args.description,
17 globs: args.globs,
18 });
19
20 const [localContinueDir] = await extras.ide.getWorkspaceDirs();
21 const ruleFilePath = createRuleFilePath(localContinueDir, args.name);
22
23 await extras.ide.writeFile(ruleFilePath, fileContent);
24 await extras.ide.openFile(ruleFilePath);
25
26 return [
27 {
28 name: "New Rule Block",
29 description: args.description || "",
30 uri: {
31 type: "file",
32 value: ruleFilePath,
33 },
34 content: `Rule created successfully`,
35 },
36 ];
37};