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

Function constructSystemMessage

extensions/cli/src/systemMessage.ts:161–269  ·  view source on GitHub ↗
(
  mode: PermissionMode,
  additionalRules?: string[],
  format?: "json",
  headless?: boolean,
)

Source from the content-addressed store, hash-verified

159 * @returns The comprehensive system message with base message and rules section
160 */
161export async function constructSystemMessage(
162 mode: PermissionMode,
163 additionalRules?: string[],
164 format?: "json",
165 headless?: boolean,
166): Promise<string> {
167 const agentFiles = ["AGENTS.md", "AGENT.md", "CLAUDE.md", "CODEX.md"];
168
169 let agentContent = "";
170
171 try {
172 for (const fileName of agentFiles) {
173 const filePath = path.join(process.cwd(), fileName);
174
175 if (fs.existsSync(filePath)) {
176 agentContent = fs.readFileSync(filePath, "utf-8");
177 break; // Use the first found agent file
178 }
179 }
180 } catch (error) {
181 // If there's any error reading the file, continue without agent content
182 console.warn("Warning: Could not read agent configuration file:", error);
183 }
184
185 // Process additional rules from --rule flags
186 const processedRules: string[] = [];
187 if (additionalRules && additionalRules.length > 0) {
188 for (const ruleSpec of additionalRules) {
189 try {
190 const processedRule = await processRule(ruleSpec);
191 processedRules.push(processedRule);
192 } catch (error: any) {
193 console.warn(
194 `Warning: Failed to process rule "${ruleSpec}": ${error.message}`,
195 );
196 }
197 }
198 }
199
200 const configYamlRules = await getConfigYamlRules();
201 processedRules.push(...configYamlRules);
202
203 // Load markdown rules from .continue/rules/ directories
204 const markdownRules = loadMarkdownRulesWithMetadata();
205 // Deduplicate against already-loaded rules
206 const existingRulesSet = new Set(processedRules);
207 for (const rule of markdownRules) {
208 if (!existingRulesSet.has(rule.rule)) {
209 processedRules.push(rule.rule);
210 existingRulesSet.add(rule.rule);
211 }
212 }
213
214 // Construct the comprehensive system message
215 let systemMessage = baseSystemMessage;
216
217 // Add plan mode specific instructions if in plan mode
218 if (mode === "plan") {

Callers 3

serveFunction · 0.85
getSystemMessageMethod · 0.85

Calls 6

processRuleFunction · 0.85
getConfigYamlRulesFunction · 0.85
warnMethod · 0.80
pushMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected