128 Commits

Author SHA1 Message Date
11a8e93b77 feat(chat-manager): enhance message retrieval with pagination and time range filtering 2026-05-10 15:12:30 +08:00
8c0c76a232 fix(session): persist compression marker on retry, warn on storage/persist errors 2026-05-10 14:52:10 +08:00
709d70f828 docs: add incremental session recovery design and implementation plan 2026-05-10 14:46:27 +08:00
25d37bcdc1 feat(system-prompt): add history section prompting agent to use timeline_recall 2026-05-10 14:46:20 +08:00
3d29854079 feat(session): incremental recovery from storage using compressed timeline 2026-05-10 14:41:48 +08:00
e65130450e feat(compressor): return CompressionResult with created_timelines flag, record marker in handle_message and /compact 2026-05-10 14:40:13 +08:00
29543444da feat(storage): add load_messages_after_timestamp, load_session_timelines, get_max_message_seq 2026-05-10 14:36:40 +08:00
d022e30943 feat(storage): add last_compressed_message_at column to sessions table and Session struct 2026-05-10 14:35:21 +08:00
cb1140e9be refactor(memory): Timeline 按 session 隔离,拆分知识/摘要检索工具
- storage/memory: search_memories 和 search_memories_by_time 增加 session_id 过滤参数
- memory/manager: recall/recall_by_time 透传 session_id
- tools: MemoryStoreTool/MemoryRecallTool 锁定 Knowledge 类别,移除 category 参数
- tools: 新增 TimelineRecallTool 用于检索会话摘要,支持可选 session_id 过滤
- tools: 输出格式化增加 session 信息显示
- tests: 新增 test_session_id_filter 验证会话级过滤
2026-05-10 13:35:21 +08:00
f9ae4b2c69 fix(context): 全面修复和增强上下文压缩机制
Bug修复:
- fast_trim 死代码: 去掉 .clone() 使其真正修改原 history
- compress_once 边界错误: 第一条 user 重复 + 最后一条 user 丢失
- handle_cron_message 遗留的重复压缩调用

新特性:
- System prompt 不参与压缩,在压缩后注入
- 孤儿 tool 清理: compress_once 返回前修复 tool 对完整性
- Agent Loop 内每轮 token 检查: 80% 窗口阈值时预裁剪旧 tool 输出
- 上下文溢出恢复: 解析 LLM 错误中的实际 token limit 并降级重试
- 硬截断降级: tokens > 90% context_window 时 head+tail 保底
- parse_context_limit_from_error: 支持 OpenAI/Anthropic/llama.cpp 格式

测试: 新增 6 个单元测试覆盖上述所有场景
2026-05-10 12:23:26 +08:00
488e10dceb fix: advance last_consolidated_at after compression, update docs 2026-05-08 21:56:05 +08:00
81e9f1e7db clippy --fix: 合并嵌套if、简化map_or、移除冗余引用等机械性优化 2026-05-08 16:35:21 +08:00
ceb8234a30 飞书渠道剥离思维链内容,不显示<think>标签 2026-05-08 16:19:19 +08:00
5d62141658 1、修复和提升记忆系统 2、简化消息标记 2026-05-08 15:09:27 +08:00
2617558a27 记忆工具合并文件,改成记忆系统总是开启。 2026-05-08 10:28:34 +08:00
c602a0695d feat: add memory system with FTS5 search and context compression integration 2026-05-07 23:32:59 +08:00
618016ac43 chore: add .worktrees/ to .gitignore 2026-05-07 23:05:01 +08:00
06811160f0 docs: add memory system implementation plan 2026-05-07 23:02:47 +08:00
28ef813c37 docs: add memory system design document 2026-05-07 22:56:19 +08:00
2fe953cdad 改为短id 2026-05-07 16:28:54 +08:00
61d2fe9ef0 修复及完善cron任务 2026-05-07 16:24:13 +08:00
db609342f7 fix: char-boundary-safe name truncation in cron_add tool
The name fallback used byte-index slice on the prompt,
which panics on multi-byte UTF-8 characters like Chinese.
Use is_char_boundary() to find a safe truncation point.
2026-05-05 00:56:42 +08:00
62f4326131 refactor: move scheduler store to storage module, cron tools to tools module
- storage/scheduler.rs: ScheduledJob/JobRun types + CRUD on Storage
- tools/cron.rs: 6 cron agent tools (add/list/remove/enable/disable/update)
- scheduler/types.rs: keep only Schedule enum
- scheduler/mod.rs: use Arc<Storage> instead of raw SqlitePool
- gateway/mod.rs: inject Storage directly, replace pool field
- storage/mod.rs: scheduler tables in init_schema
2026-05-05 00:49:54 +08:00
0056bfbd23 chore: fix clippy warnings in scheduler module 2026-05-05 00:31:22 +08:00
5746668e36 test: add scheduler integration tests 2026-05-05 00:29:00 +08:00
f7b0a33e66 feat: add 6 cron agent tools (add/list/remove/enable/disable/update) 2026-05-05 00:27:27 +08:00
205b814933 feat: wire scheduler into GatewayState startup and message processing 2026-05-05 00:17:19 +08:00
3a94b9718f feat: add Scheduler run loop and next_run_for_schedule 2026-05-05 00:16:07 +08:00
0757638c6f feat: add SessionManager::handle_cron_message for scheduled task execution 2026-05-05 00:13:07 +08:00
8415e85026 feat: add SchedulerStore with SQLite schema and CRUD 2026-05-05 00:12:10 +08:00
eccae20a0a feat: add ChatMessage::user_with_source and Session::create_user_message_with_source 2026-05-05 00:09:00 +08:00
4e5f412c2d feat: add scheduler data types (Schedule, ScheduledJob, JobRun) 2026-05-05 00:08:00 +08:00
75b8f7b8a5 feat: add SchedulerConfig to GatewayConfig 2026-05-05 00:06:57 +08:00
46527edb7b deps: add cron and chrono-tz for scheduled tasks 2026-05-05 00:06:00 +08:00
0e146a8f2a 可观测性改善,llm api兼容性改善 2026-05-04 23:04:28 +08:00
98eb7bea3d 新增跨session消息发送能力 2026-05-04 00:32:24 +08:00
24d3407b05 fix(session): 所有时间显示改用本地时区而非 UTC
- /info 和 /sessions 中的时间戳通过 DateTime::from_timestamp_millis 后
  调用 with_timezone(&Local) 转换为本地时间
- dump_to_file 和 dump_as_markdown 导出的时间也改用本地时区
2026-04-29 23:04:01 +08:00
fe4088cd1f feat(session): 扩展 /info 命令显示更多 session 信息
新增:对话标题、模型名称、用户消息数/总消息数、创建时间、最后活跃时间
2026-04-29 22:59:49 +08:00
5c558027fa feat(session): 添加 /? 帮助命令,错误命令显示友好提示
- 新增 /? 和 /help 命令显示所有可用斜杠命令
- 未知命令不再报错,而是提示"未知命令:/xxx。输入 /? 获取帮助。"
- execute_slash_command 错误现在返回友好提示而非传播为服务器错误
2026-04-29 22:57:59 +08:00
e1681e0424 debug(session): 添加 handle_message 和 session 恢复的 tracing 日志
用于排查 restart 后 session 恢复和 TTL 刷新问题。
2026-04-29 22:51:50 +08:00
dcb2d552d9 chore(session): 将标题生成阈值从 10 条减至 5 条用户消息 2026-04-29 22:46:33 +08:00
228204517d fix(session): 每次 add_message 时同步更新 Storage 的 message_count
之前只持久化了消息内容,没有更新 SessionMeta.message_count,
导致重启后从 Storage 恢复时 message_count 低于实际值,
should_generate_title() 判断失败。
2026-04-29 22:45:04 +08:00
97e3be6d3a fix(session): 调用 generate_title 生成对话标题
之前 generate_title 函数已实现但从未被调用,导致对话标题
自动生成(10 条用户消息后)一直没有触发。
2026-04-29 22:34:02 +08:00
2f2631e36a fix(session): /new 后新对话被旧对话数据覆盖的问题
问题原因:execute_slash_command 执行 /new 后,错误地将旧 session 的数据
存储到新 session 的 key 下,导致 current_sessions 虽然指向新 session,
但 sessions 里面存的是旧数据。

解决方案:移除错误的 session 映射更新逻辑。create_session 已经正确地将
新 session 存入 sessions 并更新 current_sessions,不需要额外覆盖。
2026-04-29 22:32:58 +08:00
e2fd836794 fix(session): 消息持久化和恢复
问题:消息只写内存,重启后丢失。from_storage 恢复了 meta 但没加载消息。

修复:
- add_message 改为 async,同时写内存和 Storage
- compact 场景用 persist=false 避免重复持久化
- clear_session_history 同时清内存和 Storage 消息
- 所有调用点添加 .await 和错误转换
2026-04-28 23:10:53 +08:00
c48ed83a23 refactor(session): 移除 InboundMessage.dialog_id,dialog_id 完全由 SessionManager 管理
Channel 消息不再携带 dialog_id,完全由 SessionManager 通过
current_sessions 内部管理。/new 后下一条消息会自动路由到新 session。

改动:
- InboundMessage 移除 dialog_id 字段
- handle_message 移除 dialog_id 参数
- Feishu/CLI channel 创建 InboundMessage 时不再设置 dialog_id
- 路由逻辑简化为:current_sessions → find_active_session → 创建新 session
2026-04-28 23:05:06 +08:00
e235268133 fix(session): /new 后仍停留在旧对话的问题
问题原因:/new 创建新 session 后,客户端下次发消息仍带着旧的
dialog_id,导致服务端找到旧 session。

解决方案:在 SessionManager 中新增 current_sessions 跟踪
每个 channel:chat_id 的当前活跃 session:
- create_session / get_or_create_session 时更新 current_sessions
- switch_dialog / delete_dialog 时同步更新 current_sessions
- handle_message 无 dialog_id 时优先使用 current_sessions
2026-04-28 22:53:37 +08:00
7fac68b51c feat(session): Phase 4 - 斜杠命令完善
新增命令:
- /sessions — 列出 channel:chat_id 下最近 10 条对话
- /switch <dialog_id> — 切换到指定对话
- /rename <新标题> — 重命名当前对话

更新命令:
- /delete — 软删除后创建新对话
- /info — 显示 session_id + message_count

所有命令描述改为中文。
2026-04-28 22:30:22 +08:00
ac7576bb4b feat(session): Phase 3 - SessionManager 完善
- SessionManager::new 接收 Arc<Storage> 参数
- create_session / get_or_create_session 写入/恢复 Storage
- handle_message 支持无 dialog_id 时自动查找最近活跃 session 或创建新 session
- 实现 list_dialogs() — 从 Storage 读取最近 10 条
- 实现 switch_dialog() — 从 Storage 恢复 session
- 实现 delete_dialog() — 软删除 Storage + 内存移除
- 实现 rename_dialog() — 更新 Storage 和内存 title
- 实现 archive_dialog()(空实现,archive 概念已删除)
- 新增 start_cleanup_task() 后台 TTL 清理任务
- GatewayConfig 新增 session_db_path 和 cleanup_interval_minutes 配置
- Gateway::new 改为 async,创建 Storage 并启动清理任务
- rename_dialog / delete_dialog 改为 async(需 .await)
- WsOutbound::SystemNotification 已在 Phase 2 添加
2026-04-28 22:29:24 +08:00
5f7ffd28ef feat(session): Phase 2 - 扩展 Session 结构
- Session 新增字段: title, created_at, last_active_at,
  message_count, total_message_count, seq_counter,
  storage, routing_info
- Session::new 新增 storage/routing_info/title 参数
- 新增 Session::from_storage() 从 Storage 恢复 Session
- 新增 Session::add_message_and_persist() 持久化版本
- 新增 Session::send_system_notification() 不记历史的通知
- 新增 Session::persist_session_meta() 写回 Storage
- 新增 Session::should_generate_title() / generate_title()
- 新增 LLM title 自动生成(10 条消息后触发)
- SessionManager::create_session 新增 routing_info 参数
- WsOutbound 新增 SystemNotification variant
- Client mod.rs 处理 SystemNotification
2026-04-28 22:25:10 +08:00