arXiv:2603.00822cs.SEcs.AI2026-03被引 6

将项目说明文档转化为可执行约束,防止AI代码代理违规。

ContextCov: Deriving and Enforcing Executable Constraints from Agent Instruction Files

  • 把自然语言指令编译成静态检查、运行时拦截和结构验证三重约束。
  • 在SWE-bench Lite上达成88.3%合规率,反馈成本降低3.4倍。
  • 适合需要自动化代码合规的AI开发团队使用。

随着大语言模型(LLM)代理越来越多地自主执行复杂软件工程任务,开发者依赖如AGENTS.md等自然语言指令文件来表达项目特定的编码规范、工具限制和架构边界。然而,这些指令仅是被动文本,代理常因上下文窗口饱和或局部上下文冲突而违反已记录的约束。在缺乏实时人工监督的自主环境中,此类违规会迅速累积为技术债务。为使自主代理扎根于仓库约束,我们提出ContextCov框架,将被动的自然语言指令转化为可执行的防护机制。与仅依赖提示或反思的合规方法不同,ContextCov将文档约束编译为三种互补检查:静态AST查询用于检测代码模式,运行时外壳封装拦截禁止命令,架构验证器强制执行结构规则。作为自动连续审查者,ContextCov能拦截代理行为并返回即时、可复现的违规轨迹,实现自我修正,防止不合规变更被提交。我们在SWE-bench Lite(12个仓库,300个任务)上评估了该框架。相比提示仅限和LLM反思基线,ContextCov达到88.3%的约束合规率(对比67.0%和50.3%),反馈成本降低3.4倍,同时保持功能正确性。源代码与评估结果见https://github.com/reSHARMA/ContextCov。

原文摘要 · Abstract (English)

As Large Language Model (LLM) agents increasingly execute complex, autonomous software engineering tasks, developers rely on natural language instruction files such as AGENTS.md to express project-specific coding conventions, tooling restrictions, and architectural boundaries. However, because these instructions remain passive text, agents frequently violate documented constraints due to context window saturation or conflicting local context. In autonomous settings without real-time human supervision, such violations rapidly compound into technical debt. To ground autonomous agents in repository constraints, we introduce ContextCov, a framework that transforms passive natural language instructions into executable guardrails. Unlike prompt-only or reflection-only compliance approaches, ContextCov compiles documented constraints into three complementary checks: static AST queries for code patterns, runtime shell shims that intercept prohibited commands, and architectural validators that enforce structural rules. Acting as an automated, continuous reviewer, ContextCov intercepts agent actions and returns immediate, reproducible violation traces, enabling self-correction before non-compliant changes are finalized. We evaluate ContextCov on SWE-bench Lite (12 repositories, 300 tasks). Compared to prompt-only and LLM reflection baselines, ContextCov achieves 88.3% constraint compliance (vs. 67.0% and 50.3%) with 3.4x lower feedback cost, while maintaining functional correctness. The source code and evaluation results are available at https://github.com/reSHARMA/ContextCov.

AI代理代码合规自动化审查

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。