mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-10-09 03:17:58 +00:00
* Strongly type our settings use composition where possible * Update src/core/contextProxy.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Update src/core/contextProxy.ts Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * Add comment, tweak function name * Add changeset * Clean up toolGroup types * Comments tweak * Remove unused type * More type safety * Improve import / export, add translations --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
103 lines
3 KiB
TypeScript
103 lines
3 KiB
TypeScript
import fs from "fs/promises"
|
|
import path from "path"
|
|
|
|
import { LANGUAGES } from "../../../shared/language"
|
|
import { isLanguage } from "../../../shared/globalState"
|
|
|
|
async function safeReadFile(filePath: string): Promise<string> {
|
|
try {
|
|
const content = await fs.readFile(filePath, "utf-8")
|
|
return content.trim()
|
|
} catch (err) {
|
|
const errorCode = (err as NodeJS.ErrnoException).code
|
|
if (!errorCode || !["ENOENT", "EISDIR"].includes(errorCode)) {
|
|
throw err
|
|
}
|
|
return ""
|
|
}
|
|
}
|
|
|
|
export async function loadRuleFiles(cwd: string): Promise<string> {
|
|
const ruleFiles = [".clinerules", ".cursorrules", ".windsurfrules"]
|
|
let combinedRules = ""
|
|
|
|
for (const file of ruleFiles) {
|
|
const content = await safeReadFile(path.join(cwd, file))
|
|
if (content) {
|
|
combinedRules += `\n# Rules from ${file}:\n${content}\n`
|
|
}
|
|
}
|
|
|
|
return combinedRules
|
|
}
|
|
|
|
export async function addCustomInstructions(
|
|
modeCustomInstructions: string,
|
|
globalCustomInstructions: string,
|
|
cwd: string,
|
|
mode: string,
|
|
options: { language?: string; rooIgnoreInstructions?: string } = {},
|
|
): Promise<string> {
|
|
const sections = []
|
|
|
|
// Load mode-specific rules if mode is provided
|
|
let modeRuleContent = ""
|
|
if (mode) {
|
|
const modeRuleFile = `.clinerules-${mode}`
|
|
modeRuleContent = await safeReadFile(path.join(cwd, modeRuleFile))
|
|
}
|
|
|
|
// Add language preference if provided
|
|
if (options.language) {
|
|
const languageName = isLanguage(options.language) ? LANGUAGES[options.language] : options.language
|
|
sections.push(
|
|
`Language Preference:\nYou should always speak and think in the "${languageName}" (${options.language}) language unless the user gives you instructions below to do otherwise.`,
|
|
)
|
|
}
|
|
|
|
// Add global instructions first
|
|
if (typeof globalCustomInstructions === "string" && globalCustomInstructions.trim()) {
|
|
sections.push(`Global Instructions:\n${globalCustomInstructions.trim()}`)
|
|
}
|
|
|
|
// Add mode-specific instructions after
|
|
if (typeof modeCustomInstructions === "string" && modeCustomInstructions.trim()) {
|
|
sections.push(`Mode-specific Instructions:\n${modeCustomInstructions.trim()}`)
|
|
}
|
|
|
|
// Add rules - include both mode-specific and generic rules if they exist
|
|
const rules = []
|
|
|
|
// Add mode-specific rules first if they exist
|
|
if (modeRuleContent && modeRuleContent.trim()) {
|
|
const modeRuleFile = `.clinerules-${mode}`
|
|
rules.push(`# Rules from ${modeRuleFile}:\n${modeRuleContent}`)
|
|
}
|
|
|
|
if (options.rooIgnoreInstructions) {
|
|
rules.push(options.rooIgnoreInstructions)
|
|
}
|
|
|
|
// Add generic rules
|
|
const genericRuleContent = await loadRuleFiles(cwd)
|
|
if (genericRuleContent && genericRuleContent.trim()) {
|
|
rules.push(genericRuleContent.trim())
|
|
}
|
|
|
|
if (rules.length > 0) {
|
|
sections.push(`Rules:\n\n${rules.join("\n\n")}`)
|
|
}
|
|
|
|
const joinedSections = sections.join("\n\n")
|
|
|
|
return joinedSections
|
|
? `
|
|
====
|
|
|
|
USER'S CUSTOM INSTRUCTIONS
|
|
|
|
The following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.
|
|
|
|
${joinedSections}`
|
|
: ""
|
|
}
|