So, I think I've got it.
Found another bug in the PutOnDeck() I wrote, obviously it did not put it on the deck but under it or wherever. Found the transferCardToTop(), but don't like that it doesn't say something. However, here's my putOnDeckPriority
putOnDeckPriority: (state, my) ->
# 1) If no actions left, put back best Action
# Take card from hand which are actions, sort them by ActionPriority
#
# 2) If not enough actions left, put back best Terminal you can't play
# Take cards from hand which are Actions and Terminals, sort them by ActionPriority
# Then, ignore as many terminals as you can play this turn, return the others
#
# 3) Put back as much money as you can
# First get a pessimistic estimate of the avaiable money this turn
# then find take the cost in coins of the highest priority card you can afford
# then put the treasures which are not needed in 'putBack' for discardPriority, most valuable first, Potion = 2.5 Coins
#
# Don't put last Potion back if Alchemists are in play
#
# 4) Put back the worst card (take priority for discard)
#
There is a lot sorting and estimating hardcoded in the function now, maybe one wants to subroutine them for reuse.
AND the whole mess will only work when you want to put back exactly 1 card, and also if you only have one buy. Have to think again how to handle GhostShip...