Once you're in the "stalemate" situation, buying/upgrading into Rebuilds and Duchies is definitely the right play.
Okay, I realised Rebuild later too, but how to get there? If I trash my treasure I can'te get to $5. Upgrade costs $5 too. In what order are the buys then? Rebuild and then trash all treasures? Upgrade and then trash all treasures? I'm totally lost here.
Okay, first of all I agree with DG about the Ghost Ship. In most situations its attack is stronger than that of Margrave, but against a Scrying Pool deck much less so, and, more importantly, you really want the +buy to grab SP+FV and double FV, so skip Ghost Ship altogether here. The economy from FV is immune to Pirate Ship and should be enough to get you to 5-6 reliably.
You certainly don't want to prematurely trash all your treasure, you just have to make sure that you're adaptable enough that once your opponent goes for Pirate Ship, you can make him regret that decision with little cost to yourself (i.e. if you have just 2 Coppers and a Potion that you can easily get rid of, that's much better than having invested heavily in Golds). Once he's going for Pirate Ships, the absolute worst thing you can do is keep buying Golds, that's doing nothing but helping him even further, so just go for double FV (even single if you don't have the buy) until you have enough of them to get the $5 cards.
You'll also notice that the more adaptable you are, the less attractive it is for him to go for Pirate Ship in the first place, and it's important to exploit this adaptability by maximally tempting him to go for it without it actually being good. So if you have zero treasures left in your deck, that's when you can add a Gold, because while it's technically vulnerable, it's not enough for him to go for Pirate Ship. Just make sure that you're adaptable enough that you can guarantee that his Pirate Ships never become better than a terminal $1. You can then get away with adding some more treasures towards the end because switching to Pirate Ships becomes less and less attractive the longer the game lasts.
Not necessarily, when your opponent goes for Rebuild straight away I expect the engine to win without going for Rebuild itself.
I'm curious as to whether or not you'd consider adding Pirate ship to the engine if your opponent went straight for Rebuild.
I would certainly consider it and probably do it because between a Margrave attack every turn and trashing his few Silvers, the Rebuild player has just very little chance of winning.