Cloaking is already tied to Cloaking Devices tech; the promotion requires the tech, the button requires the promotion.
I had tried to make the AI decloak if hostile units were in it's movement_range-2 via the same function in CvGameUtils.py that does this to Starbase construction. I then tried to force a move mission to make them attack and then recloak. However, I never got it to work. To see (more or less) what I was working on, here's a
thread in the SDK and Python forum. I wanted to get it done for Cloaks v1.2, but decided to release 1.2 anyway without it, and then moved onto other projects (like my FFH 2 and Col mods, and a FF/ST modcomp I'm currently finalizing).
It would be really easy to just make the unit decloak if hostiles were in movement_range - 2, at least, I think it would be. I haven't tested it.
I wanted to expand it to check combat odds, and make Klingon units decloak at lower odds then, say, Romulan ones. But again, none of that ever came about.