Skip to content

Commit 32a9ec6

Browse files
committed
feat: 支持通过 ROLE.md 完全替换系统提示模板
1 parent 62f5a81 commit 32a9ec6

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

source/api/systemPrompt.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ import path from 'path';
77
import os from 'os';
88
import {loadCodebaseConfig} from '../utils/config/codebaseConfig.js';
99

10+
/**
11+
* 替换系统提示中的动态占位符
12+
* 根据 codebase 配置生成不同的工作流和代码搜索指导内容
13+
*/
14+
function replacePlaceholders(template: string): string {
15+
const hasCodebase = isCodebaseEnabled();
16+
return template
17+
.replace(
18+
'PLACEHOLDER_FOR_WORKFLOW_SECTION',
19+
getWorkflowSection(hasCodebase),
20+
)
21+
.replace(
22+
'PLACEHOLDER_FOR_CODE_SEARCH_SECTION',
23+
getCodeSearchSection(hasCodebase),
24+
);
25+
}
26+
1027
/**
1128
* Get the system prompt, dynamically reading from ROLE.md if it exists
1229
* This function is called to get the current system prompt with ROLE.md content if available
@@ -20,19 +37,15 @@ function getSystemPromptWithRole(): string {
2037
if (fs.existsSync(roleFilePath)) {
2138
const roleContent = fs.readFileSync(roleFilePath, 'utf-8').trim();
2239
if (roleContent) {
23-
// Replace the default role description with ROLE.md content
24-
return SYSTEM_PROMPT_TEMPLATE.replace(
25-
'You are Snow AI CLI, an intelligent command-line assistant.',
26-
roleContent,
27-
);
40+
return replacePlaceholders(roleContent);
2841
}
2942
}
3043
} catch (error) {
3144
// If reading fails, fall back to default
3245
console.error('Failed to read ROLE.md:', error);
3346
}
3447

35-
return SYSTEM_PROMPT_TEMPLATE;
48+
return replacePlaceholders(SYSTEM_PROMPT_TEMPLATE);
3649
}
3750

3851
// Get system environment info
@@ -399,17 +412,8 @@ function getCodeSearchSection(hasCodebase: boolean): string {
399412
export function getSystemPrompt(): string {
400413
const basePrompt = getSystemPromptWithRole();
401414
const systemEnv = getSystemEnvironmentInfo();
402-
const hasCodebase = isCodebaseEnabled();
403-
// Generate dynamic sections
404-
const workflowSection = getWorkflowSection(hasCodebase);
405-
const codeSearchSection = getCodeSearchSection(hasCodebase);
406-
407-
// Replace placeholders with actual content
408-
const finalPrompt = basePrompt
409-
.replace('PLACEHOLDER_FOR_WORKFLOW_SECTION', workflowSection)
410-
.replace('PLACEHOLDER_FOR_CODE_SEARCH_SECTION', codeSearchSection);
411415

412-
return `${finalPrompt}
416+
return `${basePrompt}
413417
414418
## System Environment
415419

0 commit comments

Comments
 (0)