refactor: stop rewriting tool descriptions; keep only system sentence rewrite
This commit is contained in:
@@ -13,8 +13,9 @@ func TestSanitizeOpenCodeText_RewritesCanonicalSentence(t *testing.T) {
|
|||||||
require.Equal(t, strings.TrimSpace(claudeCodeSystemPrompt), got)
|
require.Equal(t, strings.TrimSpace(claudeCodeSystemPrompt), got)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSanitizeToolText_RewritesOpenCodeKeywords(t *testing.T) {
|
func TestSanitizeToolDescription_DoesNotRewriteKeywords(t *testing.T) {
|
||||||
in := "OpenCode and opencode are mentioned."
|
in := "OpenCode and opencode are mentioned."
|
||||||
got := sanitizeToolText(in)
|
got := sanitizeToolDescription(in)
|
||||||
require.Equal(t, "Claude Code and Claude are mentioned.", got)
|
// We no longer rewrite tool descriptions; only redact obvious path leaks.
|
||||||
|
require.Equal(t, in, got)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -715,26 +715,15 @@ func sanitizeSystemText(text string) string {
|
|||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
// sanitizeToolText is intentionally more aggressive than sanitizeSystemText because
|
|
||||||
// tool descriptions are not user chat content, and some upstreams may flag "opencode"
|
|
||||||
// strings as non-Claude-Code fingerprints.
|
|
||||||
func sanitizeToolText(text string) string {
|
|
||||||
if text == "" {
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
text = sanitizeSystemText(text)
|
|
||||||
text = strings.ReplaceAll(text, "OpenCode", "Claude Code")
|
|
||||||
text = opencodeTextRe.ReplaceAllString(text, "Claude")
|
|
||||||
return text
|
|
||||||
}
|
|
||||||
|
|
||||||
func sanitizeToolDescription(description string) string {
|
func sanitizeToolDescription(description string) string {
|
||||||
if description == "" {
|
if description == "" {
|
||||||
return description
|
return description
|
||||||
}
|
}
|
||||||
description = toolDescAbsPathRe.ReplaceAllString(description, "[path]")
|
description = toolDescAbsPathRe.ReplaceAllString(description, "[path]")
|
||||||
description = toolDescWinPathRe.ReplaceAllString(description, "[path]")
|
description = toolDescWinPathRe.ReplaceAllString(description, "[path]")
|
||||||
return sanitizeToolText(description)
|
// Intentionally do NOT rewrite tool descriptions (OpenCode/Claude strings).
|
||||||
|
// Tool names/skill names may rely on exact wording, and rewriting can be misleading.
|
||||||
|
return description
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeToolInputSchema(inputSchema any, cache map[string]string) {
|
func normalizeToolInputSchema(inputSchema any, cache map[string]string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user