How can AI edit code without regenerating the entire program?

Code editing is not merely code generation with a shorter prompt: it combines an intended change with a preservation contract. This guide distinguishes full generation, automated program repair, infilling and edit models, grammar-constrained decoding, and hierarchical latent control. It explains how to evaluate outside-region change, editable-region freedom, syntax, structural invariants, functional evidence, diversity, and uncertainty without treating parse rate as proof of correctness.