55 Commits

Author SHA1 Message Date
oudecheng
c7ee6bb519 fix: 修复并发 sub-agent 持久化时 SQLite database is locked 错误
将 7 个写事务从 BEGIN DEFERRED 改为 BEGIN IMMEDIATE,在事务开始即获取写锁,消除多 sub-agent 并发写入时的死锁路径。同时将 busy_timeout 从 5s 提升至 30s,为并发写者排队提供 100 倍余量。

根因:BEGIN DEFERRED 下多个事务可同时读 MAX(seq) 不持写锁,提交时互相阻塞,5s timeout 耗尽后返回 SQLITE_BUSY。BEGIN IMMEDIATE 强制写者串行排队,顺带消除 MAX(seq)+1 竞态导致的 UNIQUE 约束冲突。
2026-08-03 22:15:13 +08:00
oudecheng
7f05545488 fix: session pool 锁范围收敛与 replace_todos 原子性
- SessionPool.ensure_session_internal 改为 double-checked locking:
  先短暂持锁检查存在性,释放锁后执行耗时的 session 创建(含配置加载、
  agent 工厂构造),再次持锁插入并处理竞态。避免跨 session_factory.create().await
  持有全局锁导致所有 channel 的 session 访问串行化。
- storage::replace_todos 用 transaction() 包裹 DELETE + INSERT,保证原子性:
  中途失败自动回滚,避免 todos 列表丢失且无法恢复。事务内复用同一连接
  查询返回值,消除 drop(conn) 后重新 pool.get() 的冗余。
2026-07-31 08:23:13 +08:00
oudecheng
4baa8e7a6b fix: 内存历史按 topic_id 键化,新增 replace_topic_history 修复 DB 压缩覆盖
- SessionHistory.chat_histories 改为 topic_histories 按 topic_id 键化,消除多话题并发时内存历史互相覆盖的根因

- is_current_turn 改用 current_topic == original_topic_id 直接比较,替代失效的内存最新消息匹配判断

- 新增 ConversationRepository::replace_topic_history 按 topic 删除/插入消息,解决 replace_active_history 删除整个 session 消息的 pre-existing 问题

- compaction 路径改用 replace_topic_history,避免压缩时覆盖其他 topic 的 DB 消息

- switch_topic 不再 remove_history,不同 topic 历史独立存储互斥

- append_persisted_message 仅当 topic_id == current_topic 时更新内存,防止延迟消息污染新话题历史
2026-07-28 15:32:42 +08:00
oudecheng
c8660df14b refactor: 拆分 storage/mod.rs 与 ConfigPage.tsx (P2)
storage/mod.rs (2957 -> 1834 行):
- 抽出 tests.rs: 17 个测试函数
- 抽出 row_mapping.rs: 8 个 row<->record 映射与单记录查询函数
- 抽出 migrations.rs: 7 个 schema 迁移函数 (ensure_*_schema, has_column, add_column_if_missing)

ConfigPage.tsx (1568 -> 1235 行):
- 抽出 types.ts: 所有接口/类型定义
- 抽出 constants.ts: TABS, inputCls, selectCls, TIMEZONE_OPTIONS
- 抽出 ui.tsx: Field, Toggle, TagEditor, SectionCard, SourceEditor, MapEntryHeader
- 抽出 api/expert.ts: getSelectedExpert, selectExpert (经 ConfigPage 再导出保持兼容)

验证: cargo build, cargo test --lib storage:: 17/17, npm run build
对抗性检查: 8/8 通过 (无丢失/重复函数, 无循环依赖, 无未使用导入)
2026-07-07 18:36:23 +08:00
oudecheng
4766f838a2 fix: 过滤 subagent session 避免污染会话列表
subagent session(id 形如 sub:...)存入 DB 时 channel_name=websocket,会被 list_sessions 查出并显示在前端右上角。SQL 添加 AND id NOT LIKE 'sub:%' 过滤。
2026-07-03 19:32:28 +08:00
oudecheng
7e24e57af4 fix: 修复 persistent_session_id 前缀重复累积问题 2026-07-03 16:32:24 +08:00
oudecheng
2a02adc7c3 feat: 将 StreamingAccumulator 中的 tool_calls 类型从 HashMap 更改为 BTreeMap;在 SkillSource 中添加自定义源支持 2026-07-03 11:34:30 +08:00
oudecheng
51e06c8f73 feat: 实现两段历史压缩的同步处理,替换会话的活动历史记录 2026-07-03 09:52:45 +08:00
oudecheng
7f262c9af2 feat(todos): 在 todos 表中添加 created_by_message_id 字段以支持消息关联 2026-06-23 17:37:54 +08:00
oudecheng
3be9c1e646 feat(storage): 添加 todos 表的 created_by_message_id 字段迁移
- 检查 todos 表中是否存在 created_by_message_id 列
- 若不存在则添加该列,类型为 TEXT
- 记录添加列的迁移过程日志
- 确保数据库表结构更新完成后返回成功状态
2026-06-22 14:55:13 +08:00
oudecheng
4efc8b51e7 feat(todo): 添加待办项关联的创建消息ID并支持消息高亮
- 在待办相关数据结构和存储中新增 created_by_message_id 字段
- 记录待办项创建时对应的消息ID,支持追溯来源
- 在前端待办列表项增加点击事件,点击后滚动并高亮对应消息
- 在消息列表组件中实现高亮动画及自动滚动功能
- 更新相关工具、协议和数据库查询,确保新字段正确传递和存储
- 增加 CSS 动画实现待办对应消息的高亮闪烁效果
- 优化前端状态管理,支持设置与获取高亮消息ID
2026-06-22 14:50:37 +08:00
oudecheng
edc1a50d1c feat(todos): 修改 todos 表结构,迁移至复合主键并添加索引 2026-06-16 16:17:12 +08:00
oudecheng
6f8c4a7ce8 feat: 更新 load_messages_for_topic 方法,支持按 session_id 过滤消息 2026-06-12 19:05:06 +08:00
oudecheng
881fcace47 feat: 添加 todo_write 工具,支持全量替换和增量合并两种模式
- Tool: 纯内存实现 (Arc<RwLock<HashMap>>),零 DB 依赖,解耦持久化
- 状态机: pending → in_progress → completed/cancelled,单 in_progress 约束
- merge=false: 全量替换模式(默认)
- merge=true: 增量更新模式,只传变更的项,其余保留
- 隔离: scope_key = topic_id.unwrap_or(session_id),topic 和子代理隔离
- 持久化: TodoRepository trait + SessionStore SQLite 实现,在 Session 拦截器层完成
- 前端推送: WsOutbound::TodoList 事件
- Prompt: TodoPromptProvider 中文指令,子代理模板也包含
- 测试: 16 个单元测试,全部通过

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 14:19:07 +08:00
c0d4f65de4 feat: 更新数据库连接管理,使用连接池优化会话存储,添加新的错误处理 2026-06-07 21:35:47 +08:00
cf1152571d feat: 实现内存记录的去重和统一 scope_key 为 "default" 2026-06-06 15:07:06 +08:00
abb2d596f4 feat: 统一记忆 scope_key 为 "default",简化上下文依赖 2026-06-06 14:52:54 +08:00
oudecheng
2f529e96d0 feat: 添加滚动控制功能,支持回到顶部和回到底部的按钮 2026-06-04 16:00:43 +08:00
oudecheng
025c355c7d feat: 在消息查询中添加工具执行时长字段,增强消息记录功能 2026-06-02 17:27:29 +08:00
oudecheng
590ea9abb0 feat: 添加工具执行时长字段到消息存储,增强消息记录功能 2026-06-02 17:17:06 +08:00
oudecheng
4d6d989247 feat: 添加工具执行时长字段,增强消息处理功能 2026-06-02 16:52:47 +08:00
1288ba268f feat: 限定记忆命名空间为7种分类
- 新增 ALLOWED_MEMORY_NAMESPACES 常量定义允许的命名空间
- 添加 namespace 验证函数 is_valid_namespace()
- memory_manage 工具 schema 使用 enum 限制 namespace
- memory_search 工具 schema 使用 enum 提示可用 namespace
- 更新系统提示词添加命名空间分类说明
- 更新记忆维护提示词添加命名空间分类说明
- 修复测试中使用旧 namespace 的问题

命名空间分类:
- user: 用户记忆
- semantic: 语义记忆
- episodic: 情景记忆
- skill: 技能记忆
- environment: 环境记忆
- reflection: 反思记忆
- other: 其他记忆
2026-05-30 13:06:55 +08:00
oudecheng
3b0b4c1f2e refactor: 消息持久化改为批量单事务插入
- 新增 append_messages_batch 方法,所有消息在一个事务内插入
- session_history 移除逐条 append_persisted_message,统一走批量路径
- 子智能体消息保存从 for 循环改为批量调用

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 13:02:15 +08:00
oudecheng
4cb26b5b67 feat: 子智能体任务消息查看,实时广播工具调用事件
- 新增 LoadTaskMessages 命令,加载子智能体任务的历史消息
- SubAgentEmitter 通过 MessageBus 实时广播子智能体工具调用
- 前端新增子智能体视图,支持导航进入/退出子智能体会话
- 外部渠道过滤子智能体事件,避免推送到飞书/微信
- ToolCall/ToolResult 新增 subagent_task_id 字段

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 11:15:38 +08:00
oudecheng
598d425c28 feat: 话题添加描述字段,工具消息按 tool_call_id 合并展示
- TopicSummary 新增 description 字段,侧边栏优先显示描述
- ToolPanel 使用 toolCallId 将 tool_call 和 tool_result 配对合并展示
- 保存消息时同步更新 topics 表的 message_count 和 last_active_at
- ChatMessage 新增 toolCallId 字段

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-28 14:30:21 +08:00
0732b31e6b feat: 添加主题描述生成和更新功能,优化会话信息展示 2026-05-24 08:32:34 +08:00
b6f2de053d refactor: 移除会话重置逻辑中的 reset_cutoff_seq 字段,优化会话管理和历史压缩逻辑 2026-05-23 18:38:34 +08:00
oudecheng
8d530dcd6b feat: 添加确保会话存在的功能,优化子智能体会话管理 2026-05-20 17:21:14 +08:00
oudecheng
8f82009c32 feat: 重命名工具名称,简化工具调用接口 2026-05-19 15:18:04 +08:00
4eb6193d0c feat: 添加获取话题消息数量的方法,优化话题列表和切换话题的反馈信息 2026-05-16 22:03:32 +08:00
oudecheng
2e13f6932c feat: Enhance session management with topic support
- Added topic management capabilities, allowing users to create, switch, and query topics within sessions.
- Updated command structure to include new commands: SwitchSession and GetCurrentSession.
- Introduced TopicRecord for managing topic data in the storage layer.
- Modified session handlers to accommodate topic operations, including listing and loading topics.
- Enhanced database schema to support topics, including new tables and relationships.
- Updated input adapters to recognize new commands and handle topic-related actions.
- Improved logging for session and topic operations to aid in debugging and monitoring.
2026-05-15 15:01:58 +08:00
5eb9a26843 feat: 添加会话查询命令处理器,支持列出和加载会话功能 2026-05-14 23:27:23 +08:00
oudecheng
7238bd20d8 feat: 添加恢复中断调度任务的功能,支持从上次会话中恢复运行中的任务 2026-05-12 16:18:45 +08:00
597881f72e feat: Implement WeChatBot SDK with error handling and message protocol
- Add WeChatBotError enum for error handling with various error types.
- Create a Result type alias for easier error management.
- Implement ILinkClient for low-level API interactions including QR code generation, message sending, and updates retrieval.
- Define message types and structures for handling incoming messages and media content.
- Add tests for error handling and message parsing to ensure reliability.

Co-authored-by: Copilot <copilot@github.com>
2026-05-06 14:18:47 +08:00
3f5ed6e4e4 feat: 移除不必要的 list_memory_scope_keys_updated_since 方法及其测试,优化代码结构 2026-05-05 19:53:55 +08:00
891830779f feat: 重构存储逻辑,使用 ConversationRepository 和 PromptInjectionRepository 替代 SessionStore,优化会话和提示注入管理
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 15:55:27 +08:00
396504dffb Refactor agent and storage components to introduce SkillProvider and repository patterns
- Introduced `SkillProvider` trait to abstract skill-related functionalities.
- Replaced `SkillRuntime` with `EmptySkillProvider` in `AgentLoop` for default behavior.
- Updated `AgentFactory` to accept `SkillProvider` instead of `SkillRuntime`.
- Created `SessionHistory` struct to manage chat histories and interactions.
- Added `MemoryRepository`, `SchedulerJobRepository`, and `SkillEventRepository` traits for better storage abstraction.
- Refactored tools to use new repository traits for memory and scheduler management.
- Cleaned up session management logic by consolidating chat history handling into `SessionHistory`.

Co-authored-by: Copilot <copilot@github.com>
2026-04-28 15:12:45 +08:00
8f27bd2735 feat: 重构工具和协议模块,添加工具注册和会话管理逻辑,优化消息处理 2026-04-28 14:16:30 +08:00
af7860f2fd feat: 重构消息模块,添加 ContentBlock 和 ToolCall 结构,优化消息处理逻辑
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 14:04:59 +08:00
73dab09bfe Refactor code for improved readability and consistency
- Adjusted formatting and indentation in various files for better clarity.
- Consolidated multi-line statements into single lines where appropriate.
- Enhanced error handling messages for better debugging.
- Added a new InboundProcessor struct to handle inbound messages more effectively.
- Updated test cases to ensure they align with the new code structure.
2026-04-28 10:33:31 +08:00
4fb102644e feat: 更新调度配置以每4小时执行内存维护,并添加根据更新时间过滤内存范围的功能 2026-04-27 13:05:55 +08:00
3045a6b596 feat: Enhance ChatMessage with system context and background compaction
- Added `system_context` field to `ChatMessage` for better message context handling.
- Introduced constants for system context prompts in `message.rs`.
- Updated `Session` to manage background history compaction, including methods to start and finish compaction.
- Implemented logic to schedule background compaction after message processing in `SessionManager`.
- Enhanced database schema to support new `system_context` field in messages.
- Added functionality to compact active history, preserving system messages and summaries.
- Updated tests to validate new compaction logic and ensure message integrity.
- Removed unused functions and cleaned up code in various modules for better maintainability.

Co-authored-by: Copilot <copilot@github.com>
2026-04-26 09:31:13 +08:00
95c53fa830 feat: 添加推理内容支持到聊天消息,增强消息处理能力 2026-04-24 17:42:19 +08:00
3d241544c5 feat(memory): 添加内置记忆维护作业,增强调度功能并支持有效作业合并 2026-04-23 14:16:22 +08:00
a3ae8acde5 feat: add DB-backed scheduler for heartbeat, delayed jobs, interval jobs, and cron jobs
- Add scheduler module with SQLite persistence
- Support schedule types: delay, interval, at, cron
- Support job kinds: internal_event, outbound_message
- Add scheduler_manage tool for runtime management
- Add session_cleanup internal event for expired sessions
- Update memory tool usage prompt for better context awareness
- Add chrono and cron dependencies
2026-04-22 20:32:18 +08:00
038b5eccc6 feat: Enhance tool execution handling with pending user action state
- Introduced ToolMessageState enum to represent tool execution states (Completed, PendingUserAction).
- Updated ChatMessage struct to include tool_state for tracking tool execution status.
- Modified AgentLoop to handle tool results and pending actions, providing appropriate responses to users.
- Enhanced BashTool to detect when commands require user interaction, returning a pending state with hints.
- Updated WebSocket protocol to support tool pending messages, allowing clients to handle pending actions effectively.
- Refactored related tests to ensure proper functionality of new pending state handling.
2026-04-22 14:49:50 +08:00
9cda2ab8d5 feat(memory_manage): 更新记忆管理工具描述,增强搜索关键词的双语支持和内容匹配说明 2026-04-22 11:37:15 +08:00
9d15d50b09 feat(session): 更新聊天加载逻辑,确保初始代理提示并添加活跃用户消息计数功能 2026-04-22 10:09:39 +08:00
0dfa615ca9 feat(agent_profile): 实现代理配置文件的注入与周期性重注入机制 2026-04-22 09:45:19 +08:00
d35e89a44c # 2026-04-22 06:57:22 +08:00