You can't defend against a perfectly-executed sneak attack. In any societal format.
"How to magically prevent all violence?" is not a problem to be solved. It's a straw man.
But also: I dunno, a personal drone swarm? Helmet? Don't carry your stuff around, or if you do, make sure it's all encrypted?