| 1 | import { createRuleMarkdown } from "@continuedev/config-yaml"; |
| 2 | import { ToolImpl } from "."; |
| 3 | import { RuleWithSource } from "../.."; |
| 4 | import { createRuleFilePath } from "../../config/markdown/utils"; |
| 5 | |
| 6 | export type CreateRuleBlockArgs = Pick< |
| 7 | Required<RuleWithSource>, |
| 8 | "rule" | "name" |
| 9 | > & |
| 10 | Pick<RuleWithSource, "globs" | "regex" | "description" | "alwaysApply">; |
| 11 | |
| 12 | export 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 | }; |