As Large Language Model (LLM) agents increasingly execute complex, autonomous software engineering tasks, developers rely on natural language Agent Instructions (e.g., AGENTS.md) to enforce project-specific coding conventions, tooling, and architectural boundaries. However, these instructions are passive text. Agents frequently deviate from them due to context limitations or conflicting legacy code, a phenomenon we term Context Drift. Because agents operate without real-time human supervision, these silent violations rapidly compound into technical debt. To bridge this gap, we introduce ContextCov, a framework that transforms passive Agent Instructions into active, executable guardrails. ContextCov extracts natural language constraints and synthesizes enforcement checks across three domains: static AST analysis for code patterns, runtime shell shims that intercept prohibited commands, and architectural validators for structural and semantic constraints. Evaluations on 723 open-source repositories demonstrate that ContextCov successfully extracts over 46,000 executable checks with 99.997% syntax validity, providing a necessary automated compliance layer for safe, agent-driven development. Source code and evaluation results are available at https://anonymous.4open.science/r/ContextCov-4510/.
Alex: Welcome to another episode of ResearchPod.
Sam: Today we're looking at a paper called "ContextCov: Deriving and Enforcing Executable Constraints from Agent Instruction Files" by Reshabh K. Sharma from the University of Washington. AI agents that help with coding tasks often ignore rules in plain text files like AGENTS.md.
Alex: So these AI agents act like autonomous coders? And they forget guidelines in those files?
Sam: Yes. Developers write these files as rulebooks in everyday language. They say things like "use this build tool" or "keep code in specific folders" to guide agents that edit code without constant watching. But agents treat them as loose suggestions. Sharma calls this Context Drift—the AI breaks rules quietly due to overloaded instructions or old code patterns. For example, in Visual Studio Code rules, an agent fixing tests might run a forbidden command like "npm run compile," skipping checks and messing up the build.
Alex: Without supervision, those slip-ups build into bigger problems like bad code structure. And it happens silently with no real-time checks?
Sam: Exactly. Agents run for hours in the cloud, eroding the project's design—like chipping away at a building's foundation. The paper looks at real files in over 60,000 GitHub repos with rules on builds, styles, and folders. Agents deviate due to the Reality Gap: a split between instructions and actions, from conflicting files or AI memory limits. ContextCov fixes this by pulling rules from text files and turning them into runnable code that blocks violations instantly.
Alex: So ContextCov reads the rulebook and turns it into automatic enforcement—like a referee that doesn't miss calls. How does it handle different kinds of rules?
Sam: It parses instruction files, separating sections like build rules from style rules. Then it sorts them: process rules for commands, source rules for code style, architectural ones for structure. It generates custom checks for each. In the VS Code case, it spots "NEVER use npm run compile" and creates a blocker with feedback.
Alex: That sounds solid. But how does it avoid mixing up rules that depend on their place in the document?
Sam: Imagine a rulebook like a cookbook with chapters and subchapters. A simple reader might grab a bullet point and forget its section. ContextCov builds a tree map of the document—a Markdown Abstract Syntax Tree—showing how headings nest. For each rule, it traces the path above it, like breadcrumbs. An AI refines it into a clear sentence with that path—for example, "In backend testing, always use pytest."
Alex: So each rule gets its family tree to keep context. What happens next?
Sam: Refined rules get sorted by category: commands, code style, or structure. A classifier picks the fit and sends it to a specialist tool-maker. That outputs ready-to-run Python code—like a custom inspector. This domain-routed synthesis ensures high-quality checks.
Alex: No one-size-fits-all generator. Now, at runtime, how do these checks catch mistakes?
Sam: Three enforcers match rule types. For commands, it adds wrapper scripts to the PATH—like gatekeepers that check shell orders before they run, blocking forbidden ones. For code style, like extra parentheses on functions, it uses Tree-sitter: a parser that breaks files into trees for scanning patterns across languages, with line numbers and fixes.
Alex: Process gets intercepted upfront, source code gets tree-scanned. And architecture?
Sam: For structure, it builds graphs of files and dependencies—like "utilities only in the base layer." That catches wrong folders using graph checks. Trickier semantic rules, like not grabbing storage keys directly, use AI to flag for review. Across 723 repositories, it extracted over 46,000 checks with near-perfect validity, detecting violations in most codebases examined.
Alex: That's the full loop—from document tree to live guards. A meaningful way to close the reality gap.
Sam: Checks save to a JSON file with details: original rule, refined version, category, and Python code. Developers review, edit, or disable before use. This keeps runtime fast, no AI calls needed each time.
Alex: Like an editable checklist, not a black box. For fuzzier rules?
Sam: Graphs map file connections: nodes for modules, arrows for imports. Semantic ones prompt AI on snippets for warnings, not blocks. It catches patterns agents copy from messy code. Violations appeared in 81% of codebases, over 500,000 total.
Alex: Graphs for links, AI for intent. Solid utility.
Sam: When a check blocks, the error feeds back to the agent, letting it suggest instruction tweaks. This evolves rules without constant human input. It assumes good agents and prevents drift.
Alex: Agents help refine their rulebook. Smart feedback.
Sam: This turns passive text into checks that catch slips early. Evaluations show it works reliably on real code from hundreds of repos, preventing common violations. A step toward AI that respects project design.
Alex: Well put. Thanks for breaking it down, Sam. That's it for this look at ContextCov. Thanks for listening to ResearchPod.