@@ -13,7 +13,7 @@ use crate::{
1313 routes:: memory:: { api_err, api_err_typed} ,
1414 state:: AppState ,
1515} ;
16- use memoria_core:: TrustTier ;
16+ use memoria_core:: { MemoriaError , TrustTier } ;
1717use memoria_git:: GitForDataService ;
1818use std:: sync:: Arc ;
1919
@@ -66,6 +66,27 @@ async fn git_call(
6666 Ok ( json ! ( { "result" : text } ) )
6767}
6868
69+ async fn git_call_pick (
70+ state : & AppState ,
71+ user_id : & str ,
72+ args : serde_json:: Value ,
73+ ) -> Result < serde_json:: Value , ( StatusCode , String ) > {
74+ let result =
75+ memoria_mcp:: git_tools:: call ( "memory_pick" , args, & state. git , & state. service , user_id)
76+ . await
77+ . map_err ( |e| match e {
78+ MemoriaError :: Validation ( msg) if msg. starts_with ( "Conflict:" ) => {
79+ ( StatusCode :: CONFLICT , msg)
80+ }
81+ other => api_err_typed ( other) ,
82+ } ) ?;
83+ let text = result[ "content" ] [ 0 ] [ "text" ]
84+ . as_str ( )
85+ . unwrap_or ( "" )
86+ . to_string ( ) ;
87+ Ok ( json ! ( { "result" : text } ) )
88+ }
89+
6990async fn user_snapshot_store (
7091 state : & AppState ,
7192 user_id : & str ,
@@ -687,6 +708,26 @@ pub async fn diff_branch(
687708 Ok ( Json ( r) )
688709}
689710
711+ pub async fn pick_branch (
712+ State ( state) : State < AppState > ,
713+ AuthUser { user_id, .. } : AuthUser ,
714+ Path ( name) : Path < String > ,
715+ Json ( req) : Json < PickRequest > ,
716+ ) -> Result < Json < serde_json:: Value > , ( StatusCode , String ) > {
717+ let r = git_call_pick (
718+ & state,
719+ & user_id,
720+ json ! ( {
721+ "source" : name,
722+ "target" : req. target,
723+ "strategy" : req. strategy,
724+ "selector" : req. selector,
725+ } ) ,
726+ )
727+ . await ?;
728+ Ok ( Json ( r) )
729+ }
730+
690731pub async fn delete_branch (
691732 State ( state) : State < AppState > ,
692733 AuthUser { user_id, .. } : AuthUser ,
0 commit comments