@@ -102,9 +102,9 @@ impl KnowledgeSubcommand {
102102 }
103103 }
104104
105- /// Get the current agent name from the session
106- fn get_agent_name ( session : & ChatSession ) -> Option < & str > {
107- session. conversation . agents . get_active ( ) . map ( |a| a . name . as_str ( ) )
105+ /// Get the current agent from the session
106+ fn get_agent ( session : & ChatSession ) -> Option < & crate :: cli :: Agent > {
107+ session. conversation . agents . get_active ( )
108108 }
109109
110110 async fn execute_operation ( & self , os : & Os , session : & mut ChatSession ) -> OperationResult {
@@ -132,7 +132,7 @@ impl KnowledgeSubcommand {
132132 }
133133
134134 async fn handle_show ( os : & Os , session : & mut ChatSession ) -> Result < ( ) , std:: io:: Error > {
135- let agent_name = Self :: get_agent_name ( session) . map ( |s| s . to_string ( ) ) ;
135+ let agent_name = Self :: get_agent ( session) . map ( |a| a . name . clone ( ) ) ;
136136
137137 // Show agent-specific knowledge
138138 if let Some ( agent) = agent_name {
@@ -144,7 +144,7 @@ impl KnowledgeSubcommand {
144144 style:: SetAttribute ( crossterm:: style:: Attribute :: Reset ) ,
145145 ) ?;
146146
147- match KnowledgeStore :: get_async_instance ( os, Some ( agent . as_str ( ) ) ) . await {
147+ match KnowledgeStore :: get_async_instance ( os, Self :: get_agent ( session ) ) . await {
148148 Ok ( store) => {
149149 let store = store. lock ( ) . await ;
150150 let contexts = store. get_all ( ) . await . unwrap_or_default ( ) ;
@@ -244,9 +244,9 @@ impl KnowledgeSubcommand {
244244 ) -> OperationResult {
245245 match Self :: validate_and_sanitize_path ( os, path) {
246246 Ok ( sanitized_path) => {
247- let agent_name = Self :: get_agent_name ( session) ;
247+ let agent = Self :: get_agent ( session) ;
248248
249- let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent_name ) . await {
249+ let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent ) . await {
250250 Ok ( store) => store,
251251 Err ( e) => return OperationResult :: Error ( format ! ( "Error accessing knowledge base: {}" , e) ) ,
252252 } ;
@@ -294,9 +294,9 @@ impl KnowledgeSubcommand {
294294 /// Handle remove operation
295295 async fn handle_remove ( os : & Os , session : & ChatSession , path : & str ) -> OperationResult {
296296 let sanitized_path = sanitize_path_tool_arg ( os, path) ;
297- let agent_name = Self :: get_agent_name ( session) ;
297+ let agent = Self :: get_agent ( session) ;
298298
299- let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent_name ) . await {
299+ let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent ) . await {
300300 Ok ( store) => store,
301301 Err ( e) => return OperationResult :: Error ( format ! ( "Error accessing knowledge base: {}" , e) ) ,
302302 } ;
@@ -324,8 +324,8 @@ impl KnowledgeSubcommand {
324324 async fn handle_update ( os : & Os , session : & ChatSession , path : & str ) -> OperationResult {
325325 match Self :: validate_and_sanitize_path ( os, path) {
326326 Ok ( sanitized_path) => {
327- let agent_name = Self :: get_agent_name ( session) ;
328- let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent_name ) . await {
327+ let agent = Self :: get_agent ( session) ;
328+ let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent ) . await {
329329 Ok ( store) => store,
330330 Err ( e) => {
331331 return OperationResult :: Error ( format ! ( "Error accessing knowledge base directory: {}" , e) ) ;
@@ -363,8 +363,8 @@ impl KnowledgeSubcommand {
363363 return OperationResult :: Info ( "Clear operation cancelled" . to_string ( ) ) ;
364364 }
365365
366- let agent_name = Self :: get_agent_name ( session) ;
367- let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent_name ) . await {
366+ let agent = Self :: get_agent ( session) ;
367+ let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent ) . await {
368368 Ok ( store) => store,
369369 Err ( e) => return OperationResult :: Error ( format ! ( "Error accessing knowledge base directory: {}" , e) ) ,
370370 } ;
@@ -398,8 +398,8 @@ impl KnowledgeSubcommand {
398398
399399 /// Handle status operation
400400 async fn handle_status ( os : & Os , session : & ChatSession ) -> OperationResult {
401- let agent_name = Self :: get_agent_name ( session) ;
402- let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent_name ) . await {
401+ let agent = Self :: get_agent ( session) ;
402+ let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent ) . await {
403403 Ok ( store) => store,
404404 Err ( e) => return OperationResult :: Error ( format ! ( "Error accessing knowledge base directory: {}" , e) ) ,
405405 } ;
@@ -510,8 +510,8 @@ impl KnowledgeSubcommand {
510510
511511 /// Handle cancel operation
512512 async fn handle_cancel ( os : & Os , session : & ChatSession , operation_id : Option < & str > ) -> OperationResult {
513- let agent_name = Self :: get_agent_name ( session) ;
514- let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent_name ) . await {
513+ let agent = Self :: get_agent ( session) ;
514+ let async_knowledge_store = match KnowledgeStore :: get_async_instance ( os, agent ) . await {
515515 Ok ( store) => store,
516516 Err ( e) => return OperationResult :: Error ( format ! ( "Error accessing knowledge base directory: {}" , e) ) ,
517517 } ;
0 commit comments