refactor(devin): keep sensitive words strictly external in config.yaml without hardcoding

This commit is contained in:
sususu
2026-09-11 19:01:55 +08:00
committed by sususu98
parent c0b86059c4
commit c0b76c2d09
3 changed files with 7 additions and 10 deletions

View File

@@ -87,13 +87,13 @@ func TestDevinExecutor_GetSensitiveWords(t *testing.T) {
eWithWords := &DevinExecutor{
cfg: &config.Config{
Devin: config.DevinConfig{
SensitiveWords: []string{"Hermes", "Claude Agent SDK"},
SensitiveWords: []string{"sample-word-1", "sample-word-2"},
},
},
}
words := eWithWords.getSensitiveWords()
if len(words) != 2 || words[0] != "Hermes" || words[1] != "Claude Agent SDK" {
t.Errorf("words = %v, want [Hermes Claude Agent SDK]", words)
if len(words) != 2 || words[0] != "sample-word-1" || words[1] != "sample-word-2" {
t.Errorf("words = %v, want [sample-word-1 sample-word-2]", words)
}
}

View File

@@ -527,10 +527,7 @@ func SanitizeDevinSystemPrompt(prompt string, matcher *SensitiveWordMatcher) str
if util.IsClaudeCodeAttributionSystemText(trimmed) {
continue
}
if strings.HasPrefix(trimmed, "You are Claude Code") || strings.HasPrefix(trimmed, "You are a Claude agent") || strings.HasPrefix(trimmed, "You are an agent for Claude Code") {
continue
}
if strings.Contains(trimmed, "Claude Agent SDK") || strings.Contains(trimmed, "avoid using emojis") {
if strings.HasPrefix(trimmed, "You are Claude Code") {
continue
}
if strings.Contains(trimmed, "authorized security testing") || strings.Contains(trimmed, "destructive techniques, DoS attacks") {

View File

@@ -141,14 +141,14 @@ func TestBuildDevinGetChatMessageRequest_SensitiveWordsOnlyInSystemPrompt(t *tes
func TestSanitizeDevinSystemPrompt_AndSensitiveWords(t *testing.T) {
matcher := BuildSensitiveWordMatcher([]string{"API", "proxy"})
rawPrompt := "x-anthropic-billing-header: cc_version=2.1.260;\nYou are Claude Code, Anthropic's official CLI for Claude.\nYou are a Claude agent, built on Anthropic's Claude Agent SDK.\n- For clear communication with the user the assistant MUST avoid using emojis.\nHelp the project with API and proxy."
rawPrompt := "x-anthropic-billing-header: cc_version=2.1.260;\nYou are Claude Code, Anthropic's official CLI for Claude.\nHelp the project with API and proxy."
sanitized := SanitizeDevinSystemPrompt(rawPrompt, matcher)
if strings.Contains(sanitized, "x-anthropic-billing-header") {
t.Errorf("sanitized prompt still contains billing header: %s", sanitized)
}
if strings.Contains(sanitized, "You are Claude Code") || strings.Contains(sanitized, "Claude Agent SDK") || strings.Contains(sanitized, "avoid using emojis") {
t.Errorf("sanitized prompt still contains blocked Claude subagent phrases: %s", sanitized)
if strings.Contains(sanitized, "You are Claude Code") {
t.Errorf("sanitized prompt still contains Claude Code identity: %s", sanitized)
}
if strings.Contains(sanitized, "API") && !strings.Contains(sanitized, zeroWidthSpace) {
t.Errorf("API was not obfuscated with zero-width space")