Chat modes

This commit is contained in:
Matt Rubens
2025-01-03 22:39:52 -08:00
parent ae9a35b7b1
commit 344c796f2e
52 changed files with 6273 additions and 1500 deletions

View File

@@ -0,0 +1,52 @@
import fs from 'fs/promises'
import path from 'path'
export async function loadRuleFiles(cwd: string): Promise<string> {
const ruleFiles = ['.clinerules', '.cursorrules', '.windsurfrules']
let combinedRules = ''
for (const file of ruleFiles) {
try {
const content = await fs.readFile(path.join(cwd, file), 'utf-8')
if (content.trim()) {
combinedRules += `\n# Rules from ${file}:\n${content.trim()}\n`
}
} catch (err) {
// Silently skip if file doesn't exist
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
throw err
}
}
}
return combinedRules
}
export async function addCustomInstructions(customInstructions: string, cwd: string, preferredLanguage?: string): Promise<string> {
const ruleFileContent = await loadRuleFiles(cwd)
const allInstructions = []
if (preferredLanguage) {
allInstructions.push(`You should always speak and think in the ${preferredLanguage} language.`)
}
if (customInstructions.trim()) {
allInstructions.push(customInstructions.trim())
}
if (ruleFileContent && ruleFileContent.trim()) {
allInstructions.push(ruleFileContent.trim())
}
const joinedInstructions = allInstructions.join('\n\n')
return joinedInstructions ? `
====
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.
${joinedInstructions}`
: ""
}