@@ -15,6 +15,7 @@ import (
1515 "github.com/DevSymphony/sym-cli/internal/git"
1616 "github.com/DevSymphony/sym-cli/internal/llm"
1717 "github.com/DevSymphony/sym-cli/internal/policy"
18+ "github.com/DevSymphony/sym-cli/internal/roles"
1819 "github.com/DevSymphony/sym-cli/internal/validator"
1920 "github.com/DevSymphony/sym-cli/pkg/schema"
2021 sdkmcp "github.com/modelcontextprotocol/go-sdk/mcp"
@@ -446,9 +447,16 @@ func (s *Server) handleQueryConventions(params map[string]interface{}) (interfac
446447 }
447448 textContent += "\n "
448449 }
449- textContent += "\n ✓ Next Step: Implement your code following these conventions. After completion, MUST call validate_code to verify compliance."
450450 }
451451
452+ // Add RBAC information if available
453+ rbacInfo := s .getRBACInfo ()
454+ if rbacInfo != "" {
455+ textContent += "\n \n " + rbacInfo
456+ }
457+
458+ textContent += "\n ✓ Next Step: Implement your code following these conventions. After completion, MUST call validate_code to verify compliance."
459+
452460 // Return MCP-compliant response with content array
453461 return map [string ]interface {}{
454462 "content" : []map [string ]interface {}{
@@ -635,11 +643,15 @@ func (s *Server) handleValidateCode(params map[string]interface{}) (interface{},
635643 }
636644
637645 llmClient := llm .NewClient (apiKey )
638- llmValidator := validator .NewLLMValidator (llmClient , validationPolicy )
639646
640- // Validate git changes
647+ // Create unified validator that handles all engines + RBAC
648+ v := validator .NewValidator (validationPolicy , false ) // verbose=false for MCP
649+ v .SetLLMClient (llmClient )
650+ defer v .Close ()
651+
652+ // Validate git changes using unified validator
641653 ctx := context .Background ()
642- result , err := llmValidator . Validate (ctx , changes )
654+ result , err := v . ValidateChanges (ctx , changes )
643655 if err != nil {
644656 return nil , & RPCError {
645657 Code : - 32000 ,
@@ -904,3 +916,70 @@ func (s *Server) needsConversion(codePolicyPath string) bool {
904916func (s * Server ) convertUserPolicy (userPolicyPath , codePolicyPath string ) error {
905917 return ConvertPolicyWithLLM (userPolicyPath , codePolicyPath )
906918}
919+
920+ // getRBACInfo returns RBAC information for the current user
921+ func (s * Server ) getRBACInfo () string {
922+ // Try to get current user
923+ username , err := git .GetCurrentUser ()
924+ if err != nil {
925+ // Not in a git environment or user not configured
926+ return ""
927+ }
928+
929+ // Get user's role
930+ userRole , err := roles .GetUserRole (username )
931+ if err != nil {
932+ // Roles not configured
933+ return ""
934+ }
935+
936+ if userRole == "none" {
937+ return fmt .Sprintf ("⚠️ RBAC: User '%s' has no assigned role. You may not have permission to modify files." , username )
938+ }
939+
940+ // Load user policy to get RBAC details
941+ userPolicy , err := roles .LoadUserPolicyFromRepo ()
942+ if err != nil {
943+ // User policy not available
944+ return fmt .Sprintf ("🔐 RBAC: Current user '%s' has role '%s'" , username , userRole )
945+ }
946+
947+ // Check if RBAC is defined
948+ if userPolicy .RBAC == nil || userPolicy .RBAC .Roles == nil {
949+ return fmt .Sprintf ("🔐 RBAC: Current user '%s' has role '%s' (no restrictions defined)" , username , userRole )
950+ }
951+
952+ // Get role configuration
953+ roleConfig , exists := userPolicy .RBAC .Roles [userRole ]
954+ if ! exists {
955+ return fmt .Sprintf ("⚠️ RBAC: User '%s' has role '%s', but role is not defined in policy" , username , userRole )
956+ }
957+
958+ // Build RBAC info message
959+ var rbacMsg strings.Builder
960+ rbacMsg .WriteString ("🔐 RBAC Information:\n " )
961+ rbacMsg .WriteString (fmt .Sprintf (" User: %s\n " , username ))
962+ rbacMsg .WriteString (fmt .Sprintf (" Role: %s\n " , userRole ))
963+
964+ if len (roleConfig .AllowWrite ) > 0 {
965+ rbacMsg .WriteString (fmt .Sprintf (" Allowed paths: %s\n " , strings .Join (roleConfig .AllowWrite , ", " )))
966+ } else {
967+ rbacMsg .WriteString (" Allowed paths: All files (no restrictions)\n " )
968+ }
969+
970+ if len (roleConfig .DenyWrite ) > 0 {
971+ rbacMsg .WriteString (fmt .Sprintf (" Denied paths: %s\n " , strings .Join (roleConfig .DenyWrite , ", " )))
972+ }
973+
974+ if roleConfig .CanEditPolicy {
975+ rbacMsg .WriteString (" Can edit policy: Yes\n " )
976+ }
977+
978+ if roleConfig .CanEditRoles {
979+ rbacMsg .WriteString (" Can edit roles: Yes\n " )
980+ }
981+
982+ rbacMsg .WriteString ("\n ⚠️ Note: Modifications to denied paths will be blocked during validation." )
983+
984+ return rbacMsg .String ()
985+ }
0 commit comments