In biology, regeneration is a mysterious phenomenon that has inspired self-repairing systems, robots, and biobots. It is a collective computational process whereby cells communicate to achieve an anatomical set point and restore original function in regenerated tissue or the whole organism. Despite decades of research, the mechanisms involved in this process are still poorly understood. Likewise, the current algorithms are insufficient to overcome this knowledge barrier and enable advances in regenerative medicine, synthetic biology, and living machines/biobots. We propose a comprehensive conceptual framework for the engine of regeneration with hypotheses for the mechanisms and algorithms of stem cell-mediated regeneration that enables a system like the planarian flatworm to fully restore anatomical (form) and bioelectric (function) homeostasis from any small- or large-scale damage. The framework extends the available regeneration knowledge with novel hypotheses to propose collective intelligent self-repair machines, with multi-level feedback neural control systems, driven by somatic and stem cells. We computationally implemented the framework to demonstrate the robust recovery of both form and function (anatomical and bioelectric homeostasis) in an in silico worm that, in a simple way, resembles the planarian. In the absence of complete regeneration knowledge, the framework contributes to understanding and generating hypotheses for stem cell mediated form and function regeneration which may help advance regenerative medicine and synthetic biology. Further, as our framework is a bio-inspired and bio-computing self-repair machine, it may be useful for building self-repair robots/biobots and artificial self-repair systems.