MCPcopy
hub / github.com/continuedev/continue / processRule

Function processRule

extensions/cli/src/hubLoader.ts:79–110  ·  view source on GitHub ↗
(ruleSpec: string)

Source from the content-addressed store, hash-verified

77 * Hub slug resolution has been removed.
78 */
79export async function processRule(ruleSpec: string): Promise<string> {
80 const trimmedRuleSpec = ruleSpec.trim();
81 const hasNewline = /[\r\n]/.test(ruleSpec);
82
83 // If it looks like a file path (single line, typical path indicators)
84 const looksLikePath =
85 !hasNewline &&
86 (trimmedRuleSpec.startsWith(".") ||
87 trimmedRuleSpec.startsWith("/") ||
88 trimmedRuleSpec.includes("\\") ||
89 /\.[a-zA-Z]+$/.test(trimmedRuleSpec));
90
91 if (looksLikePath) {
92 const fs = await import("fs");
93 const path = await import("path");
94
95 try {
96 const absolutePath = path.resolve(trimmedRuleSpec);
97 if (!fs.existsSync(absolutePath)) {
98 throw new Error(`Rule file not found: ${ruleSpec}`);
99 }
100 return fs.readFileSync(absolutePath, "utf-8");
101 } catch (error: any) {
102 throw new Error(
103 `Failed to read rule file "${ruleSpec}": ${error.message}`,
104 );
105 }
106 }
107
108 // Otherwise, treat it as direct string content
109 return ruleSpec;
110}
111
112export function isStringRule(rule: string) {
113 if (rule.includes(" ") || rule.includes("\n")) {

Callers 2

constructSystemMessageFunction · 0.85
processAndCombinePromptsFunction · 0.85

Calls 1

testMethod · 0.80

Tested by

no test coverage detected