[論文レビュー] CodePlan: Repository-level Coding using LLMs and Planning
CodePlan は、段階的な依存関係および影響分析を通じて複数ステップの編集をオーケストレーションすることで、LLM を用いてリポジトリ全体にまたがる複雑なコード変更を自動化する計画ベースのフレームワークである。依存関係のあるファイル間で必要な変更を動的に特定・伝搬することで、6つのリポジトリのうち5つが正当性チェックに合格し、ベースラインがすべて失敗するのを上回った。
Software engineering activities such as package migration, fixing errors reports from static analysis or testing, and adding type annotations or other specifications to a codebase, involve pervasively editing the entire repository of code. We formulate these activities as repository-level coding tasks. Recent tools like GitHub Copilot, which are powered by Large Language Models (LLMs), have succeeded in offering high-quality solutions to localized coding problems. Repository-level coding tasks are more involved and cannot be solved directly using LLMs, since code within a repository is inter-dependent and the entire repository may be too large to fit into the prompt. We frame repository-level coding as a planning problem and present a task-agnostic framework, called CodePlan to solve it. CodePlan synthesizes a multi-step chain of edits (plan), where each step results in a call to an LLM on a code location with context derived from the entire repository, previous code changes and task-specific instructions. CodePlan is based on a novel combination of an incremental dependency analysis, a change may-impact analysis and an adaptive planning algorithm. We evaluate the effectiveness of CodePlan on two repository-level tasks: package migration (C#) and temporal code edits (Python). Each task is evaluated on multiple code repositories, each of which requires inter-dependent changes to many files (between 2-97 files). Coding tasks of this level of complexity have not been automated using LLMs before. Our results show that CodePlan has better match with the ground truth compared to baselines. CodePlan is able to get 5/6 repositories to pass the validity checks (e.g., to build without errors and make correct code edits) whereas the baselines (without planning but with the same type of contextual information as CodePlan) cannot get any of the repositories to pass them.
研究の動機と目的
- 現在の LLM ベースのツールがカバーできない範囲の、リポジトリ全体にわたる大規模かつ相互に依存するコード変更を自動化する課題に対処すること。
- コンテキスト窓の制限とコードの相互依存性のため、LLM がリポジトリ全体の編集を処理する際に抱える制限を克服すること。
- コードの依存関係と変更の影響を動的分析することで、ガイドラインに従った編集の連鎖を生成する、タスクに依存しないフレームワークを設計すること。
- 計画と LLM 生成を統合することで、自動コード移行およびリファクタリングにおける正確性と信頼性を向上させること。
提案手法
- CodePlan は、リポジトリレベルのコーディングを計画問題として定式化し、編集を文脈に配慮した LLM 呼び出しの原子的シーケンスに分解する。
- コードベース内のファイル間の構文的および意味的関係を追跡するために、段階的な依存関係分析を実行する。
- 各編集がどのコード領域に影響を与えるかを予測するための「変更義務」を生成するために、変更の影響範囲分析を適用する。
- 依存関係順序と影響の伝搬に基づいて、編集の優先順位と順序を決定する適応的計画アルゴリズムを用いる。
- 正しさを保証するために、完全なリポジトリ、過去の編集、タスク固有の指示を含むカスタマイズされたコンテキストを各 LLM 呼び出しに提供する。
- 各編集を段階的に検証し、次のステップに進む前に構文的および意味的な整合性を保証する。
実験結果
リサーチクエスチョン
- RQ1計画ベースのフレームワークは、複数のファイルにまたがる広範な相互依存する変更を要するリポジトリレベルのコーディングタスクを効果的に自動化できるか?
- RQ2コンテキストが単一のプロンプトでは収まりきらない大規模なコードベースにおいて、LLM が正しい一貫性のある編集を行うようにどのように導けるか?
- RQ3動的影響分析は、マルチステップのコード変換におけるエラーを低減し、正確性を向上させるために果たす役割は何か?
- RQ4モノリシックなコードコンテキストに対して直接 LLM をプロンプトするのと比較して、適応的計画は成功確率をどのように向上させるか?
- RQ5タスクに依存しないフレームワークは、API 移行や時系列的編集を含む多様なリポジトリレベルのタスクをどの程度処理できるか?
主な発見
- CodePlan は、6つのリポジトリのうち5つが正当性チェック(例:コンパイルおよび正しい意味的変更)に合格したが、同じコンテキスト情報を有するベースラインはすべて失敗した。
- フレームワークは、特にファイル境界を越えた推移的依存関係の処理において、ベースライン手法と比較して真値編集との整合性が著しく優れていた。
- 影響分析により、LLM の干渉前に影響を受けるコード領域を特定することで、誤ったまたは重複する編集の数を顕著に削減した。
- 段階的依存関係追跡の活用により、複雑なコールグラフとデータ依存関係を介した正確な変更伝搬が可能になった。
- 適応的計画戦略により、非計画ベースのベースラインと比較して収束性が向上し、失敗する編集シーケンスの数が減少した。
- C# および Python の両方のリポジトリ(2〜97ファイルの編集が連携して必要)を処理でき、スケーラビリティと耐障害性を実証した。
より良い研究を、今すぐ始めましょう
論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。