tl;dr: How do I make this wiring meet code, or at least safer?
The pic below is inside one of my kitchen cabinets. Once upon a time the stove was located below these cabinets, and that wire must have run to an exhaust fan (note the metal vent in the pic). The stove had been moved to another spot by the time I bought the house, but the wire is still in the cabinet and still live.
When I bought the house the wire (old 2-wire NM, no ground) ran to a light fixture on the underside of the cabinet, but there was no junction box at all. Just exposed pigtails inside the cabinet. I'd like to improve things here, so what can I do, short of running a brand new wire with a ground through the wall? I figure putting the pigtails in an actual junction box would be a good place to start.
I plan on staying in the house for a few more years, so I'm more concerned with safety than exactly meeting code.