Refactoring Codebases through Library Design

📅 2025-05-26
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
While code agents excel at solving isolated programming tasks, they struggle with cross-task code reuse—particularly for library-level refactoring. Method: This paper proposes Librarian, an automated library-level refactoring framework that integrates semantic equivalence verification, multi-solution joint abstraction, and a large language model–driven re-ranking mechanism. It is the first to systematically evaluate code agents’ trade-off between compression ratio and correctness on the Minicode benchmark. Contribution/Results: Experiments demonstrate that Librarian achieves a 1.6×–2× improvement in compression ratio over state-of-the-art code agents while significantly enhancing refactoring correctness. Both the implementation and the Minicode benchmark are open-sourced, establishing a new paradigm for AI-driven, maintainable software engineering.

Technology Category

Application Category

📝 Abstract
Maintainable and general software allows developers to build robust applications efficiently, yet achieving these qualities often requires refactoring specialized solutions into reusable components. This challenge becomes particularly relevant as code agents become increasingly accurate at solving isolated programming problems. We investigate code agents' capacity to refactor code in ways supporting growth and reusability. We present both a method and a benchmark for refactoring: Librarian, a sample-and-rerank method for generating reusable libraries, and Minicode, a benchmark where code agents must minimize and refactor multiple independent solutions into a joint library. Compared to state-of-the-art code agents, Librarian achieves strong results on both compression and correctness on Minicode, obtaining compression rates 1.6-2x better than coding agents while also improving correctness. We open-source our code and benchmark at https://code-refactor.github.io/.
Problem

Research questions and friction points this paper is trying to address.

Refactor specialized code into reusable components
Assess code agents' refactoring for growth and reusability
Develop benchmark and method for library generation
Innovation

Methods, ideas, or system contributions that make the work stand out.

Sample-and-rerank method for reusable libraries
Benchmark for minimizing and refactoring code
Improved compression and correctness rates
Z
Ziga Kovacic
Cornell University
Celine Lee
Celine Lee
Cornell University
J
Justin T. Chiu
Cohere
W
Wenting Zhao
Cornell University
Kevin Ellis
Kevin Ellis
Cornell