Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
fe170587
Commit
fe170587
authored
Jan 31, 2026
by
cyhhao
Browse files
refactor: limit OpenCode keyword replacement to tool descriptions
parent
602bf9c0
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/service/gateway_sanitize_test.go
View file @
fe170587
...
@@ -9,12 +9,12 @@ import (
...
@@ -9,12 +9,12 @@ import (
func
TestSanitizeOpenCodeText_RewritesCanonicalSentence
(
t
*
testing
.
T
)
{
func
TestSanitizeOpenCodeText_RewritesCanonicalSentence
(
t
*
testing
.
T
)
{
in
:=
"You are OpenCode, the best coding agent on the planet."
in
:=
"You are OpenCode, the best coding agent on the planet."
got
:=
sanitize
OpenCode
Text
(
in
)
got
:=
sanitize
System
Text
(
in
)
require
.
Equal
(
t
,
strings
.
TrimSpace
(
claudeCodeSystemPrompt
),
got
)
require
.
Equal
(
t
,
strings
.
TrimSpace
(
claudeCodeSystemPrompt
),
got
)
}
}
func
TestSanitize
OpenCode
Text_RewritesOpenCodeKeywords
(
t
*
testing
.
T
)
{
func
TestSanitize
Tool
Text_RewritesOpenCodeKeywords
(
t
*
testing
.
T
)
{
in
:=
"OpenCode and opencode are mentioned."
in
:=
"OpenCode and opencode are mentioned."
got
:=
sanitize
OpenCode
Text
(
in
)
got
:=
sanitize
Tool
Text
(
in
)
require
.
Equal
(
t
,
"Claude Code and Claude are mentioned."
,
got
)
require
.
Equal
(
t
,
"Claude Code and Claude are mentioned."
,
got
)
}
}
backend/internal/service/gateway_service.go
View file @
fe170587
...
@@ -697,7 +697,10 @@ func normalizeParamNameForOpenCode(name string, cache map[string]string) string
...
@@ -697,7 +697,10 @@ func normalizeParamNameForOpenCode(name string, cache map[string]string) string
return
name
return
name
}
}
func
sanitizeOpenCodeText
(
text
string
)
string
{
// sanitizeSystemText rewrites only the fixed OpenCode identity sentence (if present).
// We intentionally avoid broad keyword replacement in system prompts to prevent
// accidentally changing user-provided instructions.
func
sanitizeSystemText
(
text
string
)
string
{
if
text
==
""
{
if
text
==
""
{
return
text
return
text
}
}
...
@@ -709,6 +712,17 @@ func sanitizeOpenCodeText(text string) string {
...
@@ -709,6 +712,17 @@ func sanitizeOpenCodeText(text string) string {
"You are OpenCode, the best coding agent on the planet."
,
"You are OpenCode, the best coding agent on the planet."
,
strings
.
TrimSpace
(
claudeCodeSystemPrompt
),
strings
.
TrimSpace
(
claudeCodeSystemPrompt
),
)
)
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
=
strings
.
ReplaceAll
(
text
,
"OpenCode"
,
"Claude Code"
)
text
=
opencodeTextRe
.
ReplaceAllString
(
text
,
"Claude"
)
text
=
opencodeTextRe
.
ReplaceAllString
(
text
,
"Claude"
)
return
text
return
text
...
@@ -720,7 +734,7 @@ func sanitizeToolDescription(description string) string {
...
@@ -720,7 +734,7 @@ func sanitizeToolDescription(description string) string {
}
}
description
=
toolDescAbsPathRe
.
ReplaceAllString
(
description
,
"[path]"
)
description
=
toolDescAbsPathRe
.
ReplaceAllString
(
description
,
"[path]"
)
description
=
toolDescWinPathRe
.
ReplaceAllString
(
description
,
"[path]"
)
description
=
toolDescWinPathRe
.
ReplaceAllString
(
description
,
"[path]"
)
return
sanitize
OpenCode
Text
(
description
)
return
sanitize
Tool
Text
(
description
)
}
}
func
normalizeToolInputSchema
(
inputSchema
any
,
cache
map
[
string
]
string
)
{
func
normalizeToolInputSchema
(
inputSchema
any
,
cache
map
[
string
]
string
)
{
...
@@ -795,7 +809,7 @@ func normalizeClaudeOAuthRequestBody(body []byte, modelID string, opts claudeOAu
...
@@ -795,7 +809,7 @@ func normalizeClaudeOAuthRequestBody(body []byte, modelID string, opts claudeOAu
if
system
,
ok
:=
req
[
"system"
];
ok
{
if
system
,
ok
:=
req
[
"system"
];
ok
{
switch
v
:=
system
.
(
type
)
{
switch
v
:=
system
.
(
type
)
{
case
string
:
case
string
:
sanitized
:=
sanitize
OpenCode
Text
(
v
)
sanitized
:=
sanitize
System
Text
(
v
)
if
sanitized
!=
v
{
if
sanitized
!=
v
{
req
[
"system"
]
=
sanitized
req
[
"system"
]
=
sanitized
}
}
...
@@ -812,7 +826,7 @@ func normalizeClaudeOAuthRequestBody(body []byte, modelID string, opts claudeOAu
...
@@ -812,7 +826,7 @@ func normalizeClaudeOAuthRequestBody(body []byte, modelID string, opts claudeOAu
if
!
ok
||
text
==
""
{
if
!
ok
||
text
==
""
{
continue
continue
}
}
sanitized
:=
sanitize
OpenCode
Text
(
text
)
sanitized
:=
sanitize
System
Text
(
text
)
if
sanitized
!=
text
{
if
sanitized
!=
text
{
block
[
"text"
]
=
sanitized
block
[
"text"
]
=
sanitized
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment