feat: invokable rule
This commit is contained in:
parent
759c89ea46
commit
21f78907c3
5 changed files with 33 additions and 1 deletions
13
core/commands/slash/ruleBlockSlashCommand.ts
Normal file
13
core/commands/slash/ruleBlockSlashCommand.ts
Normal file
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -1807,6 +1807,7 @@ export interface RuleWithSource {
|
|||
description?: string;
|
||||
ruleFile?: string;
|
||||
alwaysApply?: boolean;
|
||||
invokable?: boolean;
|
||||
}
|
||||
export interface CompleteOnboardingPayload {
|
||||
mode: OnboardingModes;
|
||||
|
|
|
|||
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue