20 Commits

Author SHA1 Message Date
BaskDuan
0f8b3246ed feat: 内置 stealth-proxy 到 Docker 镜像,一个容器搞定 Vercel Bot Protection
- Dockerfile 从 alpine 切换到 slim (Debian) 以支持 Playwright Chromium
- 新增 start.sh 入口脚本,ENABLE_STEALTH=true 时自动启动内置 stealth-proxy
- docker-compose.yml 简化为单容器方案,默认启用 stealth 模式
- 新增 cookie/stealth_proxy/system_prompt 配置项及环境变量支持
- deploy-all.sh 加入 .gitignore(含敏感服务器信息)
- 更新默认指纹为 macOS Chrome 146

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 15:44:32 +08:00
小海
0716b602ac feat: v2.7.8 - 新增三大防截断机制
- 上下文压力膨胀(context_pressure):虚增 input_tokens 让客户端提前触发自动压缩
- 自适应历史预算(tools.adaptive_budget):工具数量越多,自动预留越多输出空间
- 工具结果智能截断(tools.smart_truncation):按工具类型差异化截断(Read/Bash/Search)
- 三个功能均默认关闭,支持 config.yaml 和环境变量控制
- 更新 config.yaml.example、docker-compose.yml、README 更新日志
2026-03-27 11:48:37 +08:00
huangzhenting
1bc91cac24 feat: 新增 SQLite 持久化支持 + Vue UI 后端过滤与分页优化
- 新增 src/logger-db.ts:SQLite 封装层(WAL 模式,支持写入/分页/状态计数/按需 payload 查询)
- logger.ts:双写 SQLite+JSONL,启动时 db_enabled 模式跳过 JSONL 读取避免 OOM,新增游标分页和后端过滤函数
- config.ts/config-api.ts:新增 db_enabled/db_path 配置字段及 LOG_DB_ENABLED/LOG_DB_PATH 环境变量
- log-viewer.ts/index.ts:新增 /api/requests/more 支持 status/keyword/since 后端过滤
- Vue UI:搜索框 400ms 防抖,状态/时间筛选立即触发后端查询,statusCounts 不受状态筛选影响,SSE 实时推送时增量更新计数
- 新增迁移工具 test/migrate-jsonl-to-sqlite.mjs 和单元测试 test/unit-logger-db.mjs
- 完善 README.md、config.yaml.example、docker-compose.yml、vue-ui/README.md 文档
2026-03-22 21:10:26 +08:00
huangzhenting
c4b81f33d1 fix: improve token budget accuracy and add TokenDiff logging
- converter: replace rough overhead formula (tools*70+350) with actual
  estimateTokens on built few-shot messages + Cursor hidden overhead
  (1300 base + perTool by schema_mode); remove 16000 output reservation
- cursor-client: sendCursorRequestFull now returns {text, usage?} to
  capture real Cursor inputTokens/outputTokens from messageMetadata
- handler: add estimateCursorReqTokens() and [TokenDiff] log to compare
  tiktoken estimate vs actual Cursor usage; fix non-stream retry paths
  to update usage from retry result; skip auto-continue when response < 200 chars
- openai-handler: update 4 call sites for new sendCursorRequestFull return type
- config: raise default maxHistoryTokens from 130000 to 150000
- docs/config: remove incorrect 'tiktoken underestimates 10~20%' claim;
  update overhead description and reference range to 130000~170000
2026-03-22 02:35:04 +08:00
huangzhenting
b542d554c6 feat: add max_history_tokens to trim context by token budget
Introduce js-tiktoken (cl100k_base) based token estimation to replace
the naive chars/3 approach. Add max_history_tokens config option that
trims oldest messages when the estimated token budget is exceeded.

- src/tokenizer.ts: new module wrapping js-tiktoken getEncoding
- src/config.ts/config-api.ts: YAML parse, env var, hot-reload, default 130000
- src/converter.ts: token budget trimming after max_history_messages pass
- src/handler.ts: replace estimateInputTokens with tiktoken-based version
- config.yaml.example/docker-compose.yml/README.md: docs and examples
- vue-ui: ConfigDrawer field, HotConfig type, README table row
2026-03-21 18:41:45 +08:00
majorcheng
310fd8672d fix: complete OpenAI logs and default persisted logs to summary 2026-03-20 14:06:46 +08:00
小海
4a026b6b98 feat: add tools.disabled mode to skip all tool injection for max context savings
- tools.disabled: true completely skips tool definitions + few-shot injection
- Response-side parseToolCalls still works if model outputs action blocks
- Env var: TOOLS_DISABLED=true|false
- Updated config.yaml.example and docker-compose.yml
2026-03-20 09:23:15 +08:00
小海
90be75ff9f feat: add tool passthrough mode, identity leak sanitization & enhanced tool_choice=any
1. Tool passthrough mode (config: tools.passthrough: true)
   - Bypasses multi-namespace few-shot injection
   - Embeds raw tool definitions in <tools> tags with minimal 1-shot example
   - Cleans conflicting client prompts (provider-native tool calling, XML markup)
   - Ideal for Roo Code / Cline clients

2. Enhanced Cursor identity leak sanitization
   - New refusal detection patterns for "currently in Cursor context" leaks
   - 4 new sanitizeResponse regexes targeting full context leak paragraphs
   - Covers "I apologize - it appears I'm in Cursor support assistant context"

3. Enhanced tool_choice=any force message
   - Lists available tool names (up to 15) with format example
   - Uses collaborative guidance tone to avoid triggering refusal
   - Stream and non-stream paths aligned
2026-03-20 09:14:28 +08:00
小海
14aa65349c feat: v2.7.5 — 常量集中管理 + 自定义拒绝规则 + 响应清洗开关
🏗️ 常量集中管理
- 新增 constants.ts,提取 REFUSAL_PATTERNS、IDENTITY_PROBE_PATTERNS、
  TOOL_CAPABILITY_PATTERNS、CLAUDE_IDENTITY_RESPONSE、CLAUDE_TOOLS_RESPONSE
- isRefusal() 统一导出,内置 + 自定义规则合并检测

🔧 自定义拒绝检测规则 (config.yaml: refusal_patterns)
- 用户可添加自定义正则匹配规则,追加到内置列表
- 无效正则自动退化为字面量匹配
- 缓存编译 + 热重载支持

🔀 响应内容清洗开关 (config.yaml: sanitize_response)
- 控制 sanitizeResponse() 是否替换 Cursor 身份引用为 Claude
- 默认关闭,关闭时零开销
- 支持环境变量 SANITIZE_RESPONSE 覆盖
2026-03-19 09:44:21 +08:00
小海
18c90e0720 feat: 续写次数可配置 + 历史消息条数硬限制 (#61)
采纳社区建议,新增两个配置项:

1. max_auto_continue(默认 3,设 0 禁用)
   - 替换了 handler.ts 中 4 处硬编码的 MAX_AUTO_CONTINUE = 3
   - 设为 0 时 while 循环直接短路,完全禁用自动续写
   - 用户可在对话中自行要求续写,往往更精准

2. max_history_messages(默认 100,-1 不限制)
   - 在 converter.ts 消息转换后、压缩步骤前执行裁剪
   - 保留 few-shot 示例(工具模式前 2 条),删除最早的非 few-shot 消息
   - 防止 800+ 条消息导致请求体积过大、响应变慢

两项配置均支持 config.yaml 和环境变量(MAX_AUTO_CONTINUE / MAX_HISTORY_MESSAGES)
2026-03-18 09:10:08 +08:00
小海
a0af1c8934 feat: 可配置工具处理 + 修复 URL 图片兼容性
tools 配置:
- schema_mode: compact/full/names_only 三种 Schema 呈现模式
- description_max_length: 工具描述截断长度 (0=不截断)
- include_only/exclude: 工具白名单/黑名单过滤
- 启动 banner 显示 tools 配置摘要
- 日志记录完整工具描述(不再截断200字符)

图片 URL 修复:
- 归一化 Anthropic API source.url → source.data
- 支持 image/input_image 等多种客户端格式
- 图片下载添加 User-Agent 头(解决 Telegram 403)
- 增强日志:记录每张图片下载过程和结果
2026-03-17 10:13:09 +08:00
小海
d388fefa21 feat(log-viewer): 日夜主题切换 + 标题提取修复
- 新增日/夜主题切换按钮(☀️/🌙),支持 localStorage 持久化,首次自动检测系统偏好
- 完整暗色主题 CSS 变量覆盖,所有 UI 元素适配
- 修复标题提取:过滤 <system-reminder> 注入内容和 Claude Code 引导语
- 日志页面前端重构为独立 HTML/CSS/JS 静态文件
- 登录页面样式同步更新为现代玻璃态主题
- Express 静态文件服务配置修复(兼容 v5 path-to-regexp)
2026-03-17 09:33:00 +08:00
小海
a7994ccbd5 feat: add thinking toggle in config.yaml with highest priority
- Add `thinking.enabled` config option to globally control thinking on/off
- Config priority: env THINKING_ENABLED > config.yaml > client request
- When disabled, removes thinking param even if client requests it
- Applies to both Anthropic and OpenAI format handlers
2026-03-16 18:25:53 +08:00
小海
d366125a56 feat(v2.7.1): 智能压缩算法 + 可配置压缩系统 + 日志鉴权 + Thinking 修复
🗜️ 智能历史压缩算法:
- 修复 JSON Action 块截断: 工具调用消息摘要化, 不再切断代码块
- 工具结果 60% 头 + 40% 尾保留, 错误信息不丢失
- 修复非工具模式 few-shot 偏移量 Bug
- 普通文本在自然边界(换行符)处截断

⚙️ 可配置压缩系统 (config.yaml):
- compression.enabled: 开关
- compression.level: 1(轻度) / 2(中等) / 3(激进)
- compression.keep_recent / early_msg_max_chars: 高级覆盖
- 支持 COMPRESSION_ENABLED / COMPRESSION_LEVEL 环境变量

🔐 日志查看器鉴权:
- 配置 auth_tokens 后 /logs 及 API 端点需验证
- 精美登录页, token 缓存到 localStorage
- 支持 query/header/x-api-key 三种传入方式

🧠 Thinking 修复:
- 拒绝检测先剥离 <thinking> 标签, 防止误判
- OpenAI 格式默认启用 thinking
2026-03-16 17:11:01 +08:00
小海
3458de0ac8 feat: 支持 Claude Code thinking 显示 (adaptive 模式)
- 修复 thinking 类型检测:支持 Claude Code 的 `adaptive` 类型(之前只检查 `enabled`)
- 区分 GUI/CLI thinking 策略:GUI(enabled)发 content block,CLI(adaptive)保留标签在正文中
- few-shot 示例包含 thinking:当 thinking 启用时,assistant 回复中演示 `<thinking>` 标签
- 优化短响应重试:仅在响应 <3 字符且不含数字时重试,避免 `2` `25岁` 等短回答被误判
- 验证发现 Claude Code signature 为密码学签名,无法伪造
2026-03-16 16:48:58 +08:00
小海
48de59cba7 feat: v2.7.0 — API鉴权 + Thinking支持 + 动态预算 + response_format + Vision独立代理 + 拒绝模式更新
 新功能:
- API Token 鉴权 (auth_tokens): 公网部署安全,Bearer token / x-api-key 双模式
- Thinking 支持 (客户端驱动): Anthropic thinking block + OpenAI reasoning_content
- response_format 支持: json_object / json_schema + markdown 自动剥离
- Vision 独立代理 (vision.proxy): 图片API走代理,Cursor API保持直连

🔧 优化:
- 已知工具跳过描述 (WELL_KNOWN_TOOLS): 减少 ~30% 工具指令输入
- 动态工具结果预算 (getToolResultBudget): 替代固定 15K 限制
- isTruncated 重写: 消除反引号误判导致的无限重试
- 计费头清除: 清除 x-anthropic-billing-header 防注入警告

🛡️ 防御:
- 新增 4 个 Cursor 拒绝措辞匹配模式
2026-03-16 09:44:15 +08:00
小海
c072795528 feat: 修复流式中断 + JSON 解析 + tool_choice 强制工具调用
核心修复:
- cursor-client.ts: 固定总超时 → 空闲超时,防止长输出被截断 (#12)
- converter.ts: tolerantParse 三级修复策略,处理截断 JSON (#13)
- types.ts: 新增 AnthropicToolChoice 类型,补齐 tool_choice 字段
- converter.ts: buildToolInstructions 支持 tool_choice,注入 MANDATORY 约束
- handler.ts: tool_choice=any 时检测无工具调用 → 自动追加强制消息重试

测试覆盖:
- test/unit-tolerant-parse.mjs: 18 个单元测试(tolerantParse/parseToolCalls)
- test/e2e-chat.mjs: 16 个 E2E 测试(基础问答、工具调用、流式、边界防御)
- test/e2e-agentic.mjs: 7 个 Agentic 压测(完整 Claude Code 工具链模拟)
- package.json: 新增 test:unit / test:e2e / test:agentic 快捷命令
2026-03-10 15:11:51 +08:00
小海
2a7c23416f feat(vision): add zero-config local OCR and external vision api fallback for image payloads 2026-03-06 11:00:50 +08:00
小海
184cabf5cc refactor: remove dead x-is-human token generation system
Cursor no longer validates the x-is-human header, so the entire token
generation pipeline was dead code producing only error logs.

Removed:
- loadScripts(), fetchCursorScript(), generateToken(), replenishPool(),
  getXIsHumanToken() and token pool management from cursor-client.ts
- scriptUrl config field and SCRIPT_URL env var support
- unmaskedVendorWebGL/unmaskedRendererWebGL fingerprint fields
- jscode/ script loading (env.js, main.js templates)
- script_url and WebGL fields from config.yaml

Kept:
- Chrome TLS fingerprint headers (user-agent, sec-ch-ua, etc.)
- x-is-human header sent as empty string (Cursor accepts it)
2026-03-05 17:20:51 +08:00
小海
5fdaeb934b feat: cursor2api v2 - TypeScript 重构
- Node.js/TypeScript 全新架构
- Anthropic Messages API 完整兼容(流式/非流式)
- 提示词注入实现工具调用能力(XML 格式)
- Chrome TLS 指纹模拟 + x-is-human token
- 支持 Claude Code 直接对接
2026-03-04 15:05:00 +08:00