Changesets · Branches · Tags · Compare
| Changeset | 20af267413942281fedc78925cc576cdb794c60e9ea3288bc6553ef6be1ba6eb |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-06-10 20:50 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-06-10 20:50 -07:00 |
| Parents | f6d482c84614, 429106e8234f |
6 files changed
modified core/config/profile/doLoadConfig.ts +24 −10
| @@ -14,12 +14,14 @@ | ||
| 14 | 14 | IDE, |
| 15 | 15 | IdeSettings, |
| 16 | 16 | ILLMLogger, |
| 17 | + RuleWithSource, | |
| 17 | 18 | SerializedContinueConfig, |
| 18 | 19 | Tool, |
| 19 | 20 | } from "../../"; |
| 20 | 21 | import { constructMcpSlashCommand } from "../../commands/slash/mcp"; |
| 21 | 22 | import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton"; |
| 22 | 23 | import MCPContextProvider from "../../context/providers/MCPContextProvider"; |
| 24 | +import RulesContextProvider from "../../context/providers/RulesContextProvider"; | |
| 23 | 25 | import { ControlPlaneProxyInfo } from "../../control-plane/analytics/IAnalyticsProvider.js"; |
| 24 | 26 | import { ControlPlaneClient } from "../../control-plane/client.js"; |
| 25 | 27 | import { getControlPlaneEnv } from "../../control-plane/env.js"; |
| @@ -39,6 +41,24 @@ | ||
| 39 | 41 | import { rectifySelectedModelsFromGlobalContext } from "../selectedModels"; |
| 40 | 42 | import { loadContinueConfigFromYaml } from "../yaml/loadYaml"; |
| 41 | 43 | |
| 44 | +async function loadRules(ide: IDE) { | |
| 45 | + const rules: RuleWithSource[] = []; | |
| 46 | + const errors = []; | |
| 47 | + | |
| 48 | + // Add rules from .continuerules files | |
| 49 | + const { rules: yamlRules, errors: continueRulesErrors } = | |
| 50 | + await getWorkspaceContinueRuleDotFiles(ide); | |
| 51 | + rules.unshift(...yamlRules); | |
| 52 | + errors.push(...continueRulesErrors); | |
| 53 | + | |
| 54 | + // Add rules from markdown files in .continue/rules | |
| 55 | + const { rules: markdownRules, errors: markdownRulesErrors } = | |
| 56 | + await loadMarkdownRules(ide); | |
| 57 | + rules.unshift(...markdownRules); | |
| 58 | + errors.push(...markdownRulesErrors); | |
| 59 | + | |
| 60 | + return { rules, errors }; | |
| 61 | +} | |
| 42 | 62 | export default async function doLoadConfig(options: { |
| 43 | 63 | ide: IDE; |
| 44 | 64 | ideSettingsPromise: Promise<IdeSettings>; |
| @@ -125,17 +145,11 @@ | ||
| 125 | 145 | // Remove ability have undefined errors, just have an array |
| 126 | 146 | errors = [...(errors ?? [])]; |
| 127 | 147 | |
| 128 | - // Add rules from .continuerules files | |
| 129 | - const { rules, errors: continueRulesErrors } = | |
| 130 | - await getWorkspaceContinueRuleDotFiles(ide); | |
| 148 | + // Load rules and always include the RulesContextProvider | |
| 149 | + const { rules, errors: rulesErrors } = await loadRules(ide); | |
| 150 | + errors.push(...rulesErrors); | |
| 131 | 151 | newConfig.rules.unshift(...rules); |
| 132 | - errors.push(...continueRulesErrors); | |
| 133 | - | |
| 134 | - // Add rules from markdown files in .continue/rules | |
| 135 | - const { rules: markdownRules, errors: markdownRulesErrors } = | |
| 136 | - await loadMarkdownRules(ide); | |
| 137 | - newConfig.rules.unshift(...markdownRules); | |
| 138 | - errors.push(...markdownRulesErrors); | |
| 152 | + newConfig.contextProviders.push(new RulesContextProvider({})); | |
| 139 | 153 | |
| 140 | 154 | // Rectify model selections for each role |
| 141 | 155 | newConfig = rectifySelectedModelsFromGlobalContext(newConfig, profileId); |
added core/context/providers/RulesContextProvider.ts +91 −0
| @@ -0,0 +1,91 @@ | ||
| 1 | +import { BaseContextProvider } from ".."; | |
| 2 | +import { | |
| 3 | + ContextItem, | |
| 4 | + ContextItemUri, | |
| 5 | + ContextProviderDescription, | |
| 6 | + ContextProviderExtras, | |
| 7 | + ContextSubmenuItem, | |
| 8 | + LoadSubmenuItemsArgs, | |
| 9 | + RuleWithSource, | |
| 10 | +} from "../.."; | |
| 11 | +import { getControlPlaneEnv } from "../../control-plane/env"; | |
| 12 | + | |
| 13 | +class RulesContextProvider extends BaseContextProvider { | |
| 14 | + static description: ContextProviderDescription = { | |
| 15 | + title: "rules", | |
| 16 | + displayTitle: "Rules", | |
| 17 | + description: "Mention rules files", | |
| 18 | + type: "submenu", | |
| 19 | + renderInlineAs: "", | |
| 20 | + }; | |
| 21 | + | |
| 22 | + // This is only used within this class. Worst case if there are exact duplicates is that one always calls the other, but this is an extreme edge case | |
| 23 | + // Can eventually pull in more metadata, but this is experimental | |
| 24 | + private getIdFromRule(rule: RuleWithSource): string { | |
| 25 | + return rule.ruleFile ?? rule.slug ?? rule.name ?? rule.rule; | |
| 26 | + } | |
| 27 | + | |
| 28 | + private getNameFromRule(rule: RuleWithSource): string { | |
| 29 | + return rule.name ?? rule.slug ?? rule.ruleFile ?? rule.source; | |
| 30 | + } | |
| 31 | + | |
| 32 | + private getDescriptionFromRule(rule: RuleWithSource): string { | |
| 33 | + return rule.description ?? rule.name ?? ""; | |
| 34 | + } | |
| 35 | + | |
| 36 | + private getUriFromRule( | |
| 37 | + rule: RuleWithSource, | |
| 38 | + appUrl: string, | |
| 39 | + ): ContextItemUri | undefined { | |
| 40 | + if (rule.ruleFile) { | |
| 41 | + return { | |
| 42 | + type: "file", | |
| 43 | + value: rule.ruleFile, | |
| 44 | + }; | |
| 45 | + } | |
| 46 | + | |
| 47 | + if (rule.slug) { | |
| 48 | + let url = `${appUrl}${rule.slug}`; | |
| 49 | + return { | |
| 50 | + type: "url", | |
| 51 | + value: url, | |
| 52 | + }; | |
| 53 | + } | |
| 54 | + | |
| 55 | + return undefined; | |
| 56 | + } | |
| 57 | + | |
| 58 | + async getContextItems( | |
| 59 | + query: string, | |
| 60 | + extras: ContextProviderExtras, | |
| 61 | + ): Promise<ContextItem[]> { | |
| 62 | + const rule = extras.config.rules.find( | |
| 63 | + (rule) => this.getIdFromRule(rule) === query, | |
| 64 | + ); | |
| 65 | + if (!rule) { | |
| 66 | + return []; | |
| 67 | + } | |
| 68 | + | |
| 69 | + const env = await getControlPlaneEnv(extras.ide.getIdeSettings()); | |
| 70 | + return [ | |
| 71 | + { | |
| 72 | + name: this.getNameFromRule(rule), | |
| 73 | + content: rule.rule, | |
| 74 | + description: this.getDescriptionFromRule(rule), | |
| 75 | + uri: this.getUriFromRule(rule, env.APP_URL), | |
| 76 | + }, | |
| 77 | + ]; | |
| 78 | + } | |
| 79 | + | |
| 80 | + async loadSubmenuItems( | |
| 81 | + args: LoadSubmenuItemsArgs, | |
| 82 | + ): Promise<ContextSubmenuItem[]> { | |
| 83 | + return args.config.rules.map((rule) => ({ | |
| 84 | + id: this.getIdFromRule(rule), | |
| 85 | + description: this.getDescriptionFromRule(rule), | |
| 86 | + title: this.getNameFromRule(rule), | |
| 87 | + })); | |
| 88 | + } | |
| 89 | +} | |
| 90 | + | |
| 91 | +export default RulesContextProvider; |
modified core/context/providers/index.ts +2 −0
| @@ -25,6 +25,7 @@ | ||
| 25 | 25 | import PostgresContextProvider from "./PostgresContextProvider"; |
| 26 | 26 | import ProblemsContextProvider from "./ProblemsContextProvider"; |
| 27 | 27 | import RepoMapContextProvider from "./RepoMapContextProvider"; |
| 28 | +import RulesContextProvider from "./RulesContextProvider"; | |
| 28 | 29 | import SearchContextProvider from "./SearchContextProvider"; |
| 29 | 30 | import TerminalContextProvider from "./TerminalContextProvider"; |
| 30 | 31 | import URLContextProvider from "./URLContextProvider"; |
| @@ -66,6 +67,7 @@ | ||
| 66 | 67 | MCPContextProvider, |
| 67 | 68 | GitCommitContextProvider, |
| 68 | 69 | ClipboardContextProvider, |
| 70 | + RulesContextProvider, | |
| 69 | 71 | ]; |
| 70 | 72 | |
| 71 | 73 | export function contextProviderClassFromName( |
modified extensions/vscode/package-lock.json +0 −0
Not shown: the file is larger than the hub shows, or this page holds as much as it shows. View the file.
modified gui/src/components/mainInput/AtMentionDropdown/index.tsx +20 −0
| @@ -292,6 +292,26 @@ | ||
| 292 | 292 | }, |
| 293 | 293 | description: "Create a new .prompt file", |
| 294 | 294 | }); |
| 295 | + } else if (subMenuTitle === "Mention rules files") { | |
| 296 | + items.push({ | |
| 297 | + title: "Add new rule", | |
| 298 | + type: "action", | |
| 299 | + action: () => { | |
| 300 | + void ideMessenger.request("config/addLocalWorkspaceBlock", { | |
| 301 | + blockType: "rules", | |
| 302 | + }); | |
| 303 | + const { tr } = props.editor.view.state; | |
| 304 | + const text = tr.doc.textBetween(0, tr.selection.from); | |
| 305 | + const start = text.lastIndexOf("@"); | |
| 306 | + if (start !== -1) { | |
| 307 | + props.editor.view.dispatch( | |
| 308 | + tr.delete(start, tr.selection.from).scrollIntoView(), | |
| 309 | + ); | |
| 310 | + } | |
| 311 | + props.onClose(); // Escape the mention list after creating a new rule | |
| 312 | + }, | |
| 313 | + description: "Creates a rule file", | |
| 314 | + }); | |
| 295 | 315 | } |
| 296 | 316 | setLoadingSubmenuItem(items.find((item) => item.id === "loading")); |
| 297 | 317 | setAllItems(items.filter((item) => item.id !== "loading")); |
modified gui/src/components/mainInput/icons.ts +2 −0
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | GlobeAltIcon, |
| 15 | 15 | MagnifyingGlassIcon, |
| 16 | 16 | PaperClipIcon, |
| 17 | + PencilIcon, | |
| 17 | 18 | PlusIcon, |
| 18 | 19 | SparklesIcon, |
| 19 | 20 | TrashIcon, |
| @@ -42,6 +43,7 @@ | ||
| 42 | 43 | debugger: BugAntIcon, |
| 43 | 44 | os: CpuChipIcon, |
| 44 | 45 | tree: Bars3BottomLeftIcon, |
| 46 | + rules: PencilIcon, | |
| 45 | 47 | "prompt-files": DocumentTextIcon, |
| 46 | 48 | "repo-map": FolderIcon, |
| 47 | 49 | "/clear": TrashIcon, |