Program: 158244
Project: 158244
Buggy source:
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject == null) {
    return false;
  }
  Map<UUID,Set<Card>> permanentsOwned=new HashMap<>();
  Collection<Permanent> permanents=game.getBattlefield().getAllActivePermanents();
  for (  Permanent permanent : permanents) {
    Set<Card> set=permanentsOwned.get(permanent.getOwnerId());
    if (set == null) {
      set=new LinkedHashSet<>();
    }
    set.add(permanent);
    permanentsOwned.put(permanent.getOwnerId(),set);
  }
  Map<UUID,Integer> permanentsCount=new HashMap<>();
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      Set<Card> set=permanentsOwned.remove(playerId);
      Integer count=0;
      if (set != null) {
        count=set.size();
        player.moveCards(set,Zone.LIBRARY,source,game);
      }
      if (count > 0) {
        player.shuffleLibrary(source,game);
      }
      permanentsCount.put(playerId,count);
    }
  }
  game.applyEffects();
  Map<UUID,CardsImpl> cardsRevealed=new HashMap<>();
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      Integer count=Math.min(permanentsCount.get(player.getId()),player.getLibrary().size());
      CardsImpl cards=new CardsImpl();
      for (int i=0; i < count; i++) {
        Card card=player.getLibrary().removeFromTop(game);
        if (card != null) {
          cards.add(card);
        }
      }
      player.revealCards(sourceObject.getIdName() + "String_Node_Str" + player.getName()+ "String_Node_Str",cards,game);
      cardsRevealed.put(player.getId(),cards);
    }
  }
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=cardsRevealed.get(player.getId());
      for (      Card card : cards.getCards(game)) {
        if (card != null && (card.getCardType().contains(CardType.ARTIFACT) || card.getCardType().contains(CardType.CREATURE) || card.getCardType().contains(CardType.LAND))) {
          card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),player.getId());
          cards.remove(card);
        }
      }
    }
  }
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=cardsRevealed.get(player.getId());
      for (      Card card : cards.getCards(game)) {
        if (card != null && card.getCardType().contains(CardType.ENCHANTMENT)) {
          card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),player.getId());
          cards.remove(card);
        }
      }
    }
  }
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=cardsRevealed.get(player.getId());
      player.putCardsOnBottomOfLibrary(cards,game,source,false);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject == null) {
    return false;
  }
  Map<UUID,Set<Card>> permanentsOwned=new HashMap<>();
  Collection<Permanent> permanents=game.getBattlefield().getAllActivePermanents();
  for (  Permanent permanent : permanents) {
    Set<Card> set=permanentsOwned.get(permanent.getOwnerId());
    if (set == null) {
      set=new LinkedHashSet<>();
    }
    set.add(permanent);
    permanentsOwned.put(permanent.getOwnerId(),set);
  }
  Map<UUID,Integer> permanentsCount=new HashMap<>();
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      Set<Card> set=permanentsOwned.remove(playerId);
      Integer count=0;
      if (set != null) {
        count=set.size();
        player.moveCards(set,Zone.LIBRARY,source,game);
      }
      if (count > 0) {
        player.shuffleLibrary(source,game);
      }
      permanentsCount.put(playerId,count);
    }
  }
  game.applyEffects();
  Map<UUID,CardsImpl> cardsRevealed=new HashMap<>();
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=new CardsImpl();
      cards.addAll(player.getLibrary().getTopCards(game,permanentsCount.get(player.getId())));
      player.revealCards(sourceObject.getIdName() + "String_Node_Str" + player.getName()+ "String_Node_Str",cards,game);
      cardsRevealed.put(player.getId(),cards);
    }
  }
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=cardsRevealed.get(player.getId());
      for (      Card card : cards.getCards(game)) {
        if (card != null && (card.getCardType().contains(CardType.ARTIFACT) || card.getCardType().contains(CardType.CREATURE) || card.getCardType().contains(CardType.LAND))) {
          card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),player.getId());
          cards.remove(card);
        }
      }
    }
  }
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=cardsRevealed.get(player.getId());
      for (      Card card : cards.getCards(game)) {
        if (card != null && card.getCardType().contains(CardType.ENCHANTMENT)) {
          card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),player.getId());
          cards.remove(card);
        }
      }
    }
  }
  for (  UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      CardsImpl cards=cardsRevealed.get(player.getId());
      player.putCardsOnBottomOfLibrary(cards,game,source,false);
    }
  }
  return true;
}