跳转至

规范优先的AI编码智能体收敛实践:在无测试预言机、无人工代码审查的情况下,对71.7万行代码库中189个文件的核心架构不变式进行拆解的案例研究

文章背景与核心概要

本文献全面展示了一个通过AI编码智能体执行的大规模架构重构案例研究。该智能体在严格的“规范优先”协议指导下,在没有预先存在的测试预言机(test oracles)且无人工代码审查的情况下,成功拆解了一个包含71.7万行TypeScript代码的庞大代码库中的核心生命周期不变式。

传统观念认为,这类任务需要进行彻底重写而非渐进式重构,但该智能体仅用时3天、花费2,430美元便成功完成了此项重大改造。在软件执行之前,该流程通过31轮审查排查并纠正了201处缺陷,实现了部署后零可见Bug的惊人成果。这一突破证明了结合形式化规范与自动化智能体循环在复杂软件工程中的巨大潜力。


📌 Summary

This paper presents a fully instrumented case study of a large-scale architectural refactoring executed entirely by an AI coding agent. Operating under a strict specification-first protocol, the agent dismantled a core lifetime invariant across a massive 717k-line TypeScript codebase without pre-existing test oracles and without human code review.

Traditionally considered a task requiring a complete rewrite rather than incremental refactoring, the agent successfully completed the overhaul in just three days at a cost of $2,430. The process caught and corrected 201 defects across 31 audit passes before the software was ever executed, resulting in zero observed bugs upon deployment.


🛠️ The Challenge

  • Codebase: A 717,725-line production TypeScript application spanning 3,648 files.
  • The Invariant: Dismantling the core lifetime guarantee that a UI panel must remain open for the duration of an AI request.
  • Target Behavior: Ensuring a streaming generation survives the closing of its UI panel and can seamlessly reattach upon reopening to the same live stream without loss or duplication.
  • Scale of Changes:
  • Touched 189 files (31 new).
  • Total combined commits (including extraction phase): 288 files, 34,770 insertions, and 16,422 deletions.

⚙️ The Protocol

Rather than traditional trial-and-error prompting, the refactoring followed a rigorous, multi-phase verification loop:

  1. Formal Specification: The agent generated a comprehensive specification of the target architectural behavior.
  2. Refinement Cycles: 14 audit cycles thoroughly checked the specification against the existing source code.
  3. Atomic Implementation: The code changes were executed systematically.
  4. Compile/Test Feedback Loop: Standard syntax and integration validation.
  5. Verification Cycles: 17 rigorous audit passes comparing the written code directly against the frozen specification.
  6. Empirical Convergence Criterion: The process only halted when two consecutive verification passes returned zero findings.

📊 Results & Evidence

  • Defect Prevention: Across 31 total audit passes, 201 defects were corrected entirely prior to human execution.
  • Reliability: Across the first and roughly thirty subsequent sessions, the software performed precisely as specified with zero bugs observed.
  • Time & Cost: Elapsed time of 3 days at a total API/compute cost of $2,430.
  • Transparency: The complete specification and raw session logs (over 1,500 pages, written in French) have been published as primary evidence to allow third-party auditing and consistency-checking via language models.