Part II: Discovery Through Software Engineering and Vibe Coding
Chapter 16: AI-Assisted Implementation at Repository Scale

AI-Assisted Implementation at Repository Scale

"I can generate a thousand lines of code in ten seconds. Whether any of them belong together is a question I prefer not to answer under oath."

A Code Generator Facing Cross-Examination

Overview

Generating a single function is easy. Generating a coherent change that spans twelve files, respects existing architectural invariants, passes the test suite, and does not break three downstream services: that is the actual problem. This chapter treats multi-file code generation not as a parlor trick but as an engineering discipline with formal structure. We define what it means for a change to be consistent across a repository, build tools to analyze the impact of a proposed edit before committing it, and study the failure modes that turn promising patches into production incidents.

Section 16.1 tackles multi-file code generation: how to decompose a high-level task into a coordinated set of edits across multiple files, using dependency graphs and abstract syntax trees to maintain consistency. Section 16.2 introduces impact analysis and patch review, building a system that traces how a change in one file propagates through the dependency graph and flags potential breakage before a human ever reads the diff. Section 16.3 ties everything together in a complete recipe: executing a repository-scale change against a real open-source project, from task decomposition through impact analysis to validated patch submission.

This chapter connects backward to the context engineering techniques of Chapter 11 (which determine what the model sees) and the algorithm discovery methods of Chapter 15 (which generate candidate solutions). It connects forward to Chapter 17: Multi-Agent Software Teams, where multiple agents collaborate on changes too large for a single agent, and to Chapter 18: AI-Assisted Testing and QA, where the patches generated here are subjected to automated verification. The Discovery Workbench, introduced in Chapter 6, gains a change orchestration module that coordinates multi-file edits with impact-aware validation.

Prerequisites

This chapter assumes you have read Chapter 11: Context Engineering at Repository Scale (for understanding how agents gather repository context), Chapter 9: Vibe Coding as Specification, Steering, Verification (for the human-AI collaboration model), and Chapter 14: Discovery of Architectures (for dependency graph fundamentals). You should be comfortable with Python, basic graph algorithms (topological sort, reachability), and the git version control model (commits, diffs, branches). Familiarity with tree-sitter from Chapter 11 is helpful but not strictly required; we reintroduce the relevant APIs here.

Learning Outcomes

Sections

16.1 Multi-File Code Generation

Task decomposition into file-level edits. Dependency-ordered generation. Maintaining type consistency and import coherence across files. The edit graph abstraction. Failure modes: hallucinated imports, signature drift, circular dependencies. Claude Code SDK for orchestrated generation.

16.2 Impact Analysis and Patch Review

Change propagation through dependency graphs. Computing the blast radius of an edit. Static analysis with tree-sitter for reference tracking. Automated patch review: structural checks, test execution, LLM-based semantic review. Scoring patch quality and flagging regressions.

16.3 Building a Repository-Scale Change

Recipe: end-to-end multi-file change in a real open-source repository. Task specification, context gathering, edit plan generation, coordinated code generation, impact analysis, test validation, and pull request assembly. Integrating the Discovery Workbench change orchestration module.

What's Next

The change orchestration pipeline you build in this chapter generates multi-file patches and validates them against the dependency graph. But many real-world changes are too large or too complex for a single agent working alone. In Chapter 17: Multi-Agent Software Teams, we introduce architectures where multiple specialized agents (planner, coder, reviewer, tester) collaborate on repository-scale changes, using the impact analysis and patch review tools from this chapter as shared infrastructure. The techniques from Section 16.2 become the "eyes" that let a reviewer agent evaluate what a coder agent has produced, closing the loop on autonomous software engineering.

Bibliography

Foundational Papers

Jimenez, C. E., Yang, J., Wettig, A., Yao, S., Pei, K., Press, O., & Narasimhan, K. (2024). SWE-bench: Can language models resolve real-world GitHub issues? ICLR 2024.

The benchmark that established repository-scale code generation as a measurable problem, showing that resolving real GitHub issues requires multi-file reasoning and edit coordination.

Yang, J., Jimenez, C. E., Wettig, A., Liber, K., Yao, S., Narasimhan, K., & Press, O. (2024). SWE-agent: Agent-computer interfaces enable automated software engineering. NeurIPS 2024.

Introduces the agent-computer interface design that enables LLM agents to navigate repositories, edit files, and run tests, achieving state-of-the-art SWE-bench performance.

Anthropic. (2025). Claude Code: Best practices for agentic coding.

Practical guidance on orchestrating multi-step coding workflows with the Claude Code SDK, including sub-agent patterns and tool integration for repository-scale changes.

Tools & Libraries

Tree-sitter

Incremental parsing library that builds concrete syntax trees for dozens of languages, used here for dependency extraction, reference tracking, and impact analysis.

GitHub REST API

The API for programmatic repository access, pull request creation, and CI status checking, used in Section 16.3 for end-to-end change automation.

pytest

Python's dominant testing framework, used here for automated test execution and selective test running as part of the patch validation pipeline.

Claude Code SDK

The programmatic interface for invoking Claude Code as a subprocess, enabling orchestrated multi-file code generation within automated pipelines.

Tutorials & Surveys

Zhang, F., Chen, B., Zhang, Y., et al. (2023). RepoCoder: Repository-level code completion through iterative retrieval and generation. EMNLP 2023.

Demonstrates iterative retrieval-and-generation for repository-level completion, a key pattern for multi-file consistency.

Xia, C. S., Deng, Y., Dunn, S., & Zhang, L. (2024). Agentless: Demystifying LLM-based software engineering agents. arXiv preprint.

Shows that localization-then-repair pipelines without persistent agent state can match agent-based approaches, informing the decomposition strategies in Section 16.1.

Tao, W., et al. (2024). MAGIS: LLM-based multi-agent framework for GitHub issue resolution. arXiv preprint.

A multi-agent framework for resolving GitHub issues that decomposes the problem into planning, coding, and reviewing stages.

Zhang, J., et al. (2024). AutoCodeRover: Autonomous program improvement. ISSTA 2024.

Combines code search with spectrum-based fault localization and multi-file patching, achieving strong SWE-bench results through structured program analysis.

Datasets & Benchmarks

Zan, D., et al. (2024). SWE-bench-java: A GitHub issue resolving benchmark for Java. arXiv preprint.

Extends the SWE-bench methodology to Java repositories, demonstrating that multi-file change challenges are language-agnostic.