As somebody who have been in and out mental hospitals, this is very familiar. At one point in my early twenties, I was literally thinking about killing myself every single waking second. Finally I decided to throw in the towel, and got around to planning my end. Sat there, ran through various scenarios in my head. All the way up to putting the gun in my mouth and pulling the trigger. My imagination always terminated…
The part that resonates with me is the need to see a third alternative between death and the status quo. It is easy to feel trapped and without agency, and this leads to a downward spiral. In my experience and opinion, the key to finding a way out is reclaiming agency and belief that you have the power to change. Willpower is a tricky thing. If you think you have it you do, and if you don't think you have it you don't. It is largely a mystery to me how people go from one to the other.
In my case, one thing that helped is realizing I had choices and wasn't as trapped as I felt. I could leave my family, and my job if I wanted. I could always quit it all and live in a shack somewhere reading books. Just knowing I had the power of choice and wasn't trapped gave me the strength to make progress.
I now think trained helplessness and philosophies that view humans only as a product of their environment are extremely dangerous.