diff --git a/src/command/handlers/session_query.rs b/src/command/handlers/session_query.rs index d63c88d..fced38c 100644 --- a/src/command/handlers/session_query.rs +++ b/src/command/handlers/session_query.rs @@ -49,9 +49,11 @@ async fn handle_list_sessions( include_archived: bool, ctx: CommandContext, ) -> Result { + // 使用当前通道名称查询会话,而不是硬编码 "cli" + let channel_name = &ctx.channel_name; let records = handler .cli_sessions - .list(include_archived) + .list_by_channel(channel_name, include_archived) .map_err(|e| CommandError::new("LIST_SESSIONS_ERROR", e.to_string()))?; let summaries: Vec = records @@ -131,7 +133,8 @@ mod tests { async fn test_list_sessions_empty() { let service = create_test_service(); let handler = SessionQueryCommandHandler::new(service); - let ctx = CommandContext::new("test", "test"); + // 使用 "cli" 通道,与 CliSessionService::create 一致 + let ctx = CommandContext::new("test", "cli"); let cmd = Command::ListSessions { include_archived: false, }; @@ -149,10 +152,11 @@ mod tests { let service = create_test_service(); let handler = SessionQueryCommandHandler::new(service.clone()); - // 创建一些会话 + // 创建一些会话(使用 cli 通道) service.create(Some("test session")).unwrap(); - let ctx = CommandContext::new("test", "test"); + // 使用 "cli" 通道查询,与创建会话的通道一致 + let ctx = CommandContext::new("test", "cli"); let cmd = Command::ListSessions { include_archived: false, }; diff --git a/src/gateway/cli_session.rs b/src/gateway/cli_session.rs index 35fb4ac..b5338dc 100644 --- a/src/gateway/cli_session.rs +++ b/src/gateway/cli_session.rs @@ -42,6 +42,17 @@ impl CliSessionService { .map_err(|err| AgentError::Other(format!("list sessions error: {}", err))) } + /// 列出指定通道的会话 + pub(crate) fn list_by_channel( + &self, + channel_name: &str, + include_archived: bool, + ) -> Result, AgentError> { + self.store + .list_sessions(channel_name, include_archived) + .map_err(|err| AgentError::Other(format!("list sessions error: {}", err))) + } + pub(crate) fn rename(&self, session_id: &str, title: &str) -> Result<(), AgentError> { self.store .rename_session(session_id, title)