Closing the Loop: Universal Repository Representation with RPG-Encoder
Abstract
Current repository agents encounter a reasoning disconnect due to fragmented representations, as existing methods rely on isolated API documentation or dependency graphs that lack semantic depth. We consider repository comprehension and generation to be inverse processes within a unified cycle: generation expands intent into implementation, while comprehension compresses implementation back into intent. To address this, we propose RPG-Encoder, a framework that generalizes the Repository Planning Graph (RPG) from a static generative blueprint into a unified, high-fidelity representation. RPG-Encoder closes the reasoning loop through three mechanisms: (1) Encoding raw code into the RPG that combines lifted semantic features with code dependencies; (2) Evolving the topology incrementally to decouple maintenance costs from repository scale, reducing overhead by 95.7%; and (3) Operating as a unified interface for structure-aware navigation. In evaluations, RPG-Encoder establishes state-of-the-art repository understanding on SWE-bench Verified with 93.7% Acc@5 and exceeds the best baseline by over 10% on SWE-bench Live. These results highlight our superior fine-grained localization accuracy in complex codebases. Furthermore, it achieves 98.5% reconstruction coverage on RepoCraft, confirming RPG's high-fidelity capacity to mirror the original codebase and closing the loop between intent and implementation. Our code and data are available at https://github.com/microsoft/RPG-ZeroRepo.
Lay Summary
Modern AI programming assistants often struggle to understand large software projects. A project may contain many files, functions, and relationships, and existing tools usually look at only one part of the picture: either written documentation or low-level code connections. This can make it difficult for an assistant to know where to look, what each part of the project is meant to do, and how different pieces work together. This paper introduces RPG-Encoder, a method for turning an existing software project into a clearer and more organized map. The map connects the purpose of the code with its actual implementation, helping an AI assistant understand both the high-level intent and the detailed structure of the project. RPG-Encoder can also update this map efficiently when the project changes, instead of rebuilding everything from scratch. We evaluate RPG-Encoder on tasks that require understanding and navigating real software projects. The results show that it helps AI systems find relevant code more accurately and represent projects more faithfully. This suggests that better project-level representations can make AI programming assistants more reliable when working with complex codebases. Our code and data are available at https://github.com/microsoft/RPG-ZeroRepo.