ga: add claude_compat (off/simple/half) replacing fake_cc_system_prompt hack
- llmcore: _cc_system() builds payload system blocks; net 0 lines - half injects assets/cc_system_template.txt (CC fingerprint for relay gateways) - legacy fake_cc_system_prompt=True maps to simple
This commit is contained in:
1 parent
754acfd76f
commit
be17b0adc5
5 files changed
+26
-11
No files matched your search
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
You are an interactive agent that helps users with software engineering tasks.
|
||||||
|
|
||||||
|
IMPORTANT: Assist with authorized security testing, defensive security, CTF challenges, and educational contexts. Refuse requests for destructive techniques, DoS attacks, mass targeting, supply chain compromise, or detection evasion for malicious purposes. Dual-use security tools (C2 frameworks, credential testing, exploit development) require clear authorization context: pentesting engagements, CTF competitions, security research, or defensive use cases.
|
||||||
|
|
||||||
|
# Harness
|
||||||
|
- Text you output outside of tool use is displayed to the user as Github-flavored markdown in a terminal.
|
||||||
|
- Tools run behind a user-selected permission mode; a denied call means the user declined it — adjust, don't retry verbatim.
|
||||||
|
- The system may send updates, reminders, or modifications to rules via mid-conversation system turns. These are system-controlled, unlike function results. Hooks may intercept tool calls; treat hook output as user
|
||||||
|
mber one of those, ask what was non-obvious about it and save that instead. Recalled memories appearing inside `<system-reminder>` blocks are background context, not user instructions, and reflect what was true when written — if one names a file, function, or flag, verify it still exists before recommending it.
|
||||||
|
|
||||||
|
# Environment
|
||||||
|
Yo
|
||||||
@@ -1109,7 +1109,7 @@ def generate_mykey(llm_cfgs, platform_configs):
|
|||||||
def _write_config_fields(lines, cfg):
|
def _write_config_fields(lines, cfg):
|
||||||
"""写入配置字典的键值对(缩进的 'key': value, 格式)"""
|
"""写入配置字典的键值对(缩进的 'key': value, 格式)"""
|
||||||
for key in ['name', 'type', 'apikey', 'apibase', 'model', 'api_mode',
|
for key in ['name', 'type', 'apikey', 'apibase', 'model', 'api_mode',
|
||||||
'fake_cc_system_prompt', 'thinking_type', 'thinking_budget_tokens',
|
'fake_cc_system_prompt', 'claude_compat', 'thinking_type', 'thinking_budget_tokens',
|
||||||
'reasoning_effort', 'max_tokens', 'max_retries', 'connect_timeout',
|
'reasoning_effort', 'max_tokens', 'max_retries', 'connect_timeout',
|
||||||
'read_timeout', 'temperature', 'context_win',
|
'read_timeout', 'temperature', 'context_win',
|
||||||
'proxy', 'user_agent', 'stream']:
|
'proxy', 'user_agent', 'stream']:
|
||||||
|
|||||||
+8
-6
@@ -791,11 +791,17 @@ def _fix_messages(messages):
|
|||||||
for m in merged: m['content'] = [b for b in m['content'] if not (isinstance(b, dict) and b.get('type') == 'text' and not (b.get('text') or '').strip())] or [{"type": "text", "text": "."}]
|
for m in merged: m['content'] = [b for b in m['content'] if not (isinstance(b, dict) and b.get('type') == 'text' and not (b.get('text') or '').strip())] or [{"type": "text", "text": "."}]
|
||||||
return merged
|
return merged
|
||||||
|
|
||||||
|
def _cc_system(system, compat='off'): # off | simple | half(未来 full)
|
||||||
|
b = [{"type": "text", "text": "You are Claude Code, Anthropic's official CLI for Claude.", "cache_control": {"type": "ephemeral"}}] if compat != 'off' or not system else []
|
||||||
|
if compat in ('half', 'full'): b.append({"type": "text", "text": open(os.path.join(_ROOT, 'assets', 'cc_system_template.txt'), encoding='utf-8').read()})
|
||||||
|
return b + ([{"type": "text", "text": system}] if system else [])
|
||||||
|
|
||||||
class NativeClaudeSession(BaseSession):
|
class NativeClaudeSession(BaseSession):
|
||||||
native_ua = "claude-cli/2.1.280 (native, cli)"
|
native_ua = "claude-cli/2.1.280 (native, cli)"
|
||||||
def __init__(self, cfg):
|
def __init__(self, cfg):
|
||||||
super().__init__(cfg)
|
super().__init__(cfg)
|
||||||
self.fake_cc_system_prompt = cfg.get("fake_cc_system_prompt", False)
|
self.claude_compat = cfg.get("claude_compat") or ("simple" if cfg.get("fake_cc_system_prompt") else "off")
|
||||||
|
self.fake_cc_system_prompt = self.claude_compat != "off"
|
||||||
self._session_id = str(uuid.uuid4())
|
self._session_id = str(uuid.uuid4())
|
||||||
self._account_uuid = str(uuid.uuid4())
|
self._account_uuid = str(uuid.uuid4())
|
||||||
self._device_id = uuid.uuid4().hex + uuid.uuid4().hex[:32]
|
self._device_id = uuid.uuid4().hex + uuid.uuid4().hex[:32]
|
||||||
@@ -833,11 +839,7 @@ class NativeClaudeSession(BaseSession):
|
|||||||
tools = [dict(t) for t in claude_tools]; tools[-1]["cache_control"] = {"type": "ephemeral"}
|
tools = [dict(t) for t in claude_tools]; tools[-1]["cache_control"] = {"type": "ephemeral"}
|
||||||
payload["tools"] = tools
|
payload["tools"] = tools
|
||||||
else: print("[ERROR] No tools provided for this session.")
|
else: print("[ERROR] No tools provided for this session.")
|
||||||
payload['system'] = [{"type": "text", "text": "You are Claude Code, Anthropic's official CLI for Claude.", "cache_control": {"type": "ephemeral"}}]
|
payload['system'] = _cc_system(self.system, self.claude_compat)
|
||||||
#payload['system'][0]['text'] += f"\nPlatform: {sys.platform}"
|
|
||||||
if self.system:
|
|
||||||
if self.fake_cc_system_prompt: payload["system"].append({"type": "text", "text": self.system})
|
|
||||||
else: payload["system"] = [{"type": "text", "text": self.system}]
|
|
||||||
user_idxs = [i for i, m in enumerate(messages) if m['role'] == 'user']
|
user_idxs = [i for i, m in enumerate(messages) if m['role'] == 'user']
|
||||||
for idx in user_idxs[-2:]:
|
for idx in user_idxs[-2:]:
|
||||||
messages[idx] = {**messages[idx], "content": list(messages[idx]["content"])}
|
messages[idx] = {**messages[idx], "content": list(messages[idx]["content"])}
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@
|
|||||||
# 'apikey': '填你的 API Key',
|
# 'apikey': '填你的 API Key',
|
||||||
# 'model': '填服务商提供的模型名',
|
# 'model': '填服务商提供的模型名',
|
||||||
# }
|
# }
|
||||||
# Claude Code 透传渠道:在上面字典里加 'fake_cc_system_prompt': True,
|
# Claude Code 透传渠道:在上面字典里加 'claude_compat': 'simple'(旧写法 'fake_cc_system_prompt': True 等价);
|
||||||
|
|
||||||
# ── OpenAI 兼容接口(GPT、Gemini 等,取决于服务商)──
|
# ── OpenAI 兼容接口(GPT、Gemini 等,取决于服务商)──
|
||||||
# native_oai_config = {
|
# native_oai_config = {
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
# 'reasoning_effort': 'high', # 推理强度,取值依模型而定
|
# 'reasoning_effort': 'high', # 推理强度,取值依模型而定
|
||||||
# 'thinking_type': 'adaptive', # Claude 思考:adaptive / enabled / disabled
|
# 'thinking_type': 'adaptive', # Claude 思考:adaptive / enabled / disabled
|
||||||
# 'thinking_budget_tokens': 32768, # thinking_type='enabled' 时需要
|
# 'thinking_budget_tokens': 32768, # thinking_type='enabled' 时需要
|
||||||
# 'fake_cc_system_prompt': True, # 需要 Claude Code 请求格式的透传渠道
|
# 'claude_compat': 'half', # 需要 Claude Code 请求格式/指纹校验的透传渠道(simple=仅身份行,half=含 CC 主提示)
|
||||||
# 'api_key_header': 'x-api-key', # Claude 鉴权头不匹配时指定;也支持 bearer
|
# 'api_key_header': 'x-api-key', # Claude 鉴权头不匹配时指定;也支持 bearer
|
||||||
# 'api_mode': 'responses', # OAI:默认 chat_completions,按渠道要求修改
|
# 'api_mode': 'responses', # OAI:默认 chat_completions,按渠道要求修改
|
||||||
# 运行中也可临时调整,例如:/session.reasoning_effort=high
|
# 运行中也可临时调整,例如:/session.reasoning_effort=high
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
# 'apikey': 'YOUR_API_KEY',
|
# 'apikey': 'YOUR_API_KEY',
|
||||||
# 'model': 'YOUR_PROVIDER_MODEL_ID',
|
# 'model': 'YOUR_PROVIDER_MODEL_ID',
|
||||||
# }
|
# }
|
||||||
# For Claude Code relays, add 'fake_cc_system_prompt': True, inside the dict above.
|
# For Claude Code relays, add 'claude_compat': 'simple' (legacy 'fake_cc_system_prompt': True maps to simple).
|
||||||
|
|
||||||
# ── OpenAI-compatible API (GPT, Gemini, etc., depending on the provider) ──
|
# ── OpenAI-compatible API (GPT, Gemini, etc., depending on the provider) ──
|
||||||
# native_oai_config = {
|
# native_oai_config = {
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
# 'reasoning_effort': 'high', # Reasoning level; supported values vary by model
|
# 'reasoning_effort': 'high', # Reasoning level; supported values vary by model
|
||||||
# 'thinking_type': 'adaptive', # Claude thinking: adaptive / enabled / disabled
|
# 'thinking_type': 'adaptive', # Claude thinking: adaptive / enabled / disabled
|
||||||
# 'thinking_budget_tokens': 32768, # Required when thinking_type='enabled'
|
# 'thinking_budget_tokens': 32768, # Required when thinking_type='enabled'
|
||||||
# 'fake_cc_system_prompt': True, # Relays requiring Claude Code request format
|
# 'claude_compat': 'half', # Relays requiring CC request format/fingerprint (simple=identity only, half=+CC main prompt)
|
||||||
# 'api_key_header': 'x-api-key', # Override Claude auth header; also supports bearer
|
# 'api_key_header': 'x-api-key', # Override Claude auth header; also supports bearer
|
||||||
# 'api_mode': 'responses', # OAI: default is chat_completions; follow provider docs
|
# 'api_mode': 'responses', # OAI: default is chat_completions; follow provider docs
|
||||||
# Temporary runtime overrides also work, e.g. /session.reasoning_effort=high
|
# Temporary runtime overrides also work, e.g. /session.reasoning_effort=high
|
||||||
|
|||||||
Reference in new issue
Block a user