Commit Graph

15 Commits

Author SHA1 Message Date
huangzhenting
a84dfd6d03 feat: 实现 db_enabled/db_path 热重载支持,修复文档格式
- logger-db.ts: 新增 closeDb(),修复 initDb() 支持安全重复调用
- logger.ts: 注册 onConfigReload 回调,db_enabled/db_path 变更后无需重启
- config.yaml.example: 删除「需重启」警告注释,补充热重载说明
- README.md: 修复环境变量表格被 blockquote 截断的格式问题,更新热重载说明
- vue-ui/README.md: 删除「需重启服务」错误说明
- ConfigDrawer.vue: 删除「需重启」提示
2026-03-23 08:45:21 +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
小海
7c2422ce60 feat: add TOOLS_PASSTHROUGH env var override for Docker support 2026-03-20 09:18:13 +08:00
小海
70d077b27a docs: add passthrough option to config.yaml.example 2026-03-20 09:16:33 +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
小海
8a5117bbb1 v2.7.4: 截断安全 + 代理续写禁用 + 日志提示词对比视图
- 截断时跳过工具解析,防止损坏的工具调用(写入半截文件)
- maxAutoContinue 默认 0,交由 Claude Code 原生续写
- 系统提示词身份声明清除(防 prompt injection 拒绝)
- 流式热身窗口 96→300 chars(拒绝检测前不释放文本)
- 日志查看器「提示词对比」视图:原始 vs Cursor 转换后
- 转换摘要面板:工具数/消息数/上下文大小一目了然
- 标题提取增强:通用 XML 标签清除 + 更多引导语过滤
2026-03-18 11:56:26 +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
小海
447dad8c03 fix: thinking 未配置时不再自动注入,跟随客户端请求
Made-with: Cursor
2026-03-17 14:42:33 +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
小海
5b4210a270 chore: 默认关闭 thinking 2026-03-17 09:43:05 +08:00
小海
222485ca93 chore: 移除 config.yaml 跟踪 + 更新 README 使用说明
- config.yaml 加入 .gitignore(含敏感 token,不再上传)
- 新增 config.yaml.example 作为配置模板
- README 新增:日志查看器功能介绍、配置表格、环境变量参考
- README 更新:项目结构增加 public/ 目录说明
- .gitignore 清理重复条目 + 排除截图文件
2026-03-17 09:37:34 +08:00