From 21f78907c357c7a8e817c84ced2b54196b2ec0c7 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Thu, 11 Sep 2025 10:12:20 -0700 Subject: [PATCH] feat: invokable rule --- core/commands/slash/ruleBlockSlashCommand.ts | 13 +++++++++++++ core/config/yaml/loadYaml.ts | 17 ++++++++++++++++- core/config/yaml/yamlToContinueConfig.ts | 2 ++ core/index.d.ts | 1 + packages/config-yaml/src/schemas/index.ts | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 core/commands/slash/ruleBlockSlashCommand.ts diff --git a/core/commands/slash/ruleBlockSlashCommand.ts b/core/commands/slash/ruleBlockSlashCommand.ts new file mode 100644 index 000000000..82670e022 --- /dev/null +++ b/core/commands/slash/ruleBlockSlashCommand.ts @@ -0,0 +1,13 @@ +import { RuleWithSource, SlashCommandWithSource } from "../.."; + +export function convertRuleBlockToSlashCommand( + rule: RuleWithSource, +): SlashCommandWithSource { + return { + name: rule.name || "Unnamed Rule", + description: rule.description ?? "", + prompt: rule.rule, + source: "invokable-rule", + promptFile: rule.ruleFile, + }; +} \ No newline at end of file diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 65cb5e0ff..3a634ddcb 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -24,6 +24,7 @@ import { modifyAnyConfigWithSharedConfig } from "../sharedConfig"; import { convertPromptBlockToSlashCommand } from "../../commands/slash/promptBlockSlashCommand"; import { slashCommandFromPromptFile } from "../../commands/slash/promptFileSlashCommand"; +import { convertRuleBlockToSlashCommand } from "../../commands/slash/ruleBlockSlashCommand"; import { getControlPlaneEnvSync } from "../../control-plane/env"; import { PolicySingleton } from "../../control-plane/PolicySingleton"; import { getBaseToolDefinitions } from "../../tools"; @@ -208,7 +209,21 @@ async function configYamlToContinueConfig(options: { } for (const rule of config.rules ?? []) { - continueConfig.rules.push(convertYamlRuleToContinueRule(rule)); + const convertedRule = convertYamlRuleToContinueRule(rule); + continueConfig.rules.push(convertedRule); + + // Convert invokable rules to slash commands + if (convertedRule.invokable) { + try { + const slashCommand = convertRuleBlockToSlashCommand(convertedRule); + continueConfig.slashCommands?.push(slashCommand); + } catch (e) { + localErrors.push({ + message: `Error converting invokable rule ${convertedRule.name} to slash command: ${e instanceof Error ? e.message : e}`, + fatal: false, + }); + } + } } continueConfig.data = config.data; diff --git a/core/config/yaml/yamlToContinueConfig.ts b/core/config/yaml/yamlToContinueConfig.ts index 8d61e06bc..f775646ef 100644 --- a/core/config/yaml/yamlToContinueConfig.ts +++ b/core/config/yaml/yamlToContinueConfig.ts @@ -13,8 +13,10 @@ export function convertYamlRuleToContinueRule(rule: Rule): RuleWithSource { rule: rule.rule, globs: rule.globs, name: rule.name, + description: rule.description, ruleFile: rule.sourceFile, alwaysApply: rule.alwaysApply, + invokable: rule.invokable, }; } } diff --git a/core/index.d.ts b/core/index.d.ts index 6e80bc5d3..073a55ae5 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1807,6 +1807,7 @@ export interface RuleWithSource { description?: string; ruleFile?: string; alwaysApply?: boolean; + invokable?: boolean; } export interface CompleteOnboardingPayload { mode: OnboardingModes; diff --git a/packages/config-yaml/src/schemas/index.ts b/packages/config-yaml/src/schemas/index.ts index 8e1c73224..e4a15d7bb 100644 --- a/packages/config-yaml/src/schemas/index.ts +++ b/packages/config-yaml/src/schemas/index.ts @@ -57,6 +57,7 @@ const ruleObjectSchema = z.object({ globs: z.union([z.string(), z.array(z.string())]).optional(), regex: z.union([z.string(), z.array(z.string())]).optional(), alwaysApply: z.boolean().optional(), + invokable: z.boolean().optional(), sourceFile: z.string().optional(), //TODO refactor RuleWithSource.ruleFile to align with sourceFile }); const ruleSchema = z.union([z.string(), ruleObjectSchema]);