It's a wisdom that took a while to fully develop, probably over a year or two. It's both learning from trial and error (e.g. "being at the grocery store for X minutes only triggers PEM if I had already done another errand the day before"), and eventually learning to "tune in" to specific bodily signals during the activity that correlate quite well with whether I'm going to experience PEM later. It's a bit hard to describe the second part in words--It's like knowing that a torrential downpour is coming just from sensing slight changes in atmospheric pressure. In a similar way, I can sense that I'm approaching my "limit", and if I keep pushing myself beyond that point, PEM will follow.
Unfortunately that process had to be relearned all over again when my baseline severity changed. I think it is much easier to notice and keep track of the patterns if your overall illness is rather consistent for long periods of time--if you have fluctuations, or some additional comorbidity throwing a wrench into the mix, I'm sure that keeping track of patterns just becomes infeasible.