by ear. also depends on the instrument im working on. by all means, i just have a LOOOT of reference material floating on my head. i have listened the source/reference material for years on end so i have a lot of nice applications in my head. nice arpeggio, very specific kind of modulation and whatnot.
piano? usually i have a fair idea of what i NEED to hear. arpeggio going up or down or both. one handed melody ? very special kind of dynamics? it all begins with trying to figure out a bass passage. or the leading melody. a coherent set of notes that tickle my idea. then its just a matter of spicing it up.
the way lack of theory shows up is that i cant really be fancy AF like a proper, real pianist would. my fingers are just used to the keybed and i absolutely can replicate whatevers floating on my head or what i hear.
its just minimalistic af.