How Repository-Level AI Agents Work in the Terminal: Architecture, Permissions, and Verification

    This article explains how repository-level AI agents operating in the terminal differ architecturally from IDE autocomplete tools. It covers the shift from single-shot Q&A to a continuous agent loop, permission boundaries as a first-class design, context isolation through sub-agent specialization, and verification loops that turn generated code into deliverable changes. It also outlines common engineering requirements for cloud deployment, current limitations, and practical guidance for teams on starting small, designing permissions early, and investing in verification.

    1. The Problem: Why “Being Able to Write Code” Is Not “Being Able to Modify a Repository”

    Over the past two years, the industry’s understanding of AI coding capability has shifted noticeably. Early discussions focused on whether a model could generate a usable snippet of code. Today, the more important question is whether it can safely complete a task inside a real, large repository burdened with legacy history. These two problems are not on the same difficulty level.

    Generating a snippet is essentially local reasoning. Completing a change inside a repository requires answering at least these questions:

    • Which modules does the requirement touch, and where are the boundaries?
    • What implicit conventions and legacy constraints are undocumented?
    • Will the change break existing tests or downstream dependents?
    • Which actions are irreversible and must be confirmed first?
    • When verification fails, which layer is the problem in?

    The emerging consensus is this: what matters for a repository-level agent is not “writing,” but “seeing clearly before acting, and verifying after acting.” This is also the fundamental architectural divide between terminal-based agentic coding tools and in-IDE completion tools. The former is designed as a continuously running executor; the latter is designed as an assistant within an interaction.


    2. Layer One: A Paradigm Shift in the Main Loop

    1. From “One Question, One Answer” to a Continuous Agent Loop

    In-IDE completion and conversational generation are typically stateless interactions: one request, one output. A repository-level agent instead runs a continuous loop, which can be abstracted as:

    1. read context → make a plan → call tools → observe results → revise the plan → (loop until verification passes)

    This loop introduces three key differences.

    First, tools are first-class citizens of the loop. Reading and writing files, running commands, executing tests, and searching code are abstracted into callable tools. The model does not directly “output an answer”; it changes repository state by calling tools and reads the returned results as input for the next round.

    Second, the plan is a revisable intermediate artifact. The plan is not a one-time document shown to the user. It is state inside the loop that is continuously corrected by observations. When a test fails, the loop folds the failure information back into the context and forms a new plan branch.

    Third, state is externalized. The real execution state lives in the file system, command output, and test reports, not in the model’s implicit memory. This makes the whole process observable and replayable.

    2. A Simplified Loop Sketch

    1. # Pseudocode: skeleton of a repository-level agent main loop
    2. plan = planner.build(goal, repo_snapshot)
    3. while not done(plan):
    4. observation = context.collect(repo_state, recent_logs)
    5. plan = planner.revise(plan, observation)
    6. action = policy.choose_next(plan, allowed_tools)
    7. if requires_confirmation(action):
    8. human.ask(action) # hand control back for high-risk actions
    9. result = executor.run(action) # read file / write file / run command / run tests
    10. memory.append(action, result)
    11. if tests_pass(result) and reviewer.accepts(diff_of(result)):
    12. done = True
    13. return summary_and_diff()

    The value of this pseudocode is not in the details but in two frequently overlooked design choices it reveals: the verification condition is written into the loop’s termination condition, and high-risk actions are explicitly handed to a human.


    3. Layer Two: Permission Boundaries as a First-Class Design

    1. The Real Risk Is Not “Unable to Write” but “Writing Beyond Authority”

    In engineering practice, AI-related incidents are usually not syntax errors but:

    • Modifying files that were not asked to be modified;
    • Running commands with side effects (bulk refactors, deletions, overwrites);
    • Operating on the wrong branch or in the wrong directory;
    • Introducing unconfirmed dependencies or configuration changes.

    For this reason, a mature repository-level agent does not grant permissions by default. It models permissions as an independent layer, usually split along two dimensions:

    Dimension Example values Meaning
    Interaction mode Read-only exploration / auto-accept edits / plan then execute / confirm each step / restricted execution Determines the set of actions allowed in the current round
    Tool granularity Read file, write file, run command, web search, sub-agent invocation Determines whether an individual action needs extra approval

    The most notable is the plan-then-execute mode: once the agent enters this mode, it only reads code and studies the approach, writing no files until the plan is confirmed. This design essentially reduces the probability of “fixing A while breaking B” by making the model gather evidence first and take on write operations second.

    Teams can start from these conventions:

    1. Default to read-only exploration; writing must be explicitly enabled;
    2. Execution commands must be explainable, stating the purpose and side-effect scope of each command;
    3. Present changes as a minimal diff set so they are easy for a human to review;
    4. Force human confirmation for high-risk actions, including deletion, overwrite, dependency changes, and remote writes;
    5. Keep the whole process auditable, retaining the action sequence and corresponding output for later review.

    Notably, permission boundaries should not be implemented only at the product layer but also hardened at the engineering layer: for example, running in a container or sandbox, restricting the writable scope of the file system, limiting network egress, and layering these on top of the team’s existing branch protection, code review, and continuous integration policies. An agent does not replace permission governance; it must obey it.


    4. Layer Three: Context Isolation and Sub-Agent Division of Labor

    1. Context Pollution Is the Main Failure Mode for Repository-Level Tasks

    The most typical way a large model breaks down on an engineering task is cramming “finding clues, reading the repository, writing the implementation, running verification, and explaining the cause” into a single context window. As interaction rounds accumulate, the context fills up with:

    • Large amounts of file fragments irrelevant to the current decision;
    • Intermediate conclusions that have already been overturned;
    • Lengthy command output and failure logs;
    • Mutually contradictory assumptions.

    The result is degraded instruction following and diluted key constraints, and the model begins to “forget the original goal.” This is context pollution.

    2. The Essence of Sub-Agents: Context Isolation

    The common industry practice is to split one large, messy task into several smaller execution units with cleaner contexts. Each unit has:

    • An independent context window: loading only information relevant to its task;
    • Independent tool constraints: exploration units are read-only, and only execution units have write permission;
    • An independent return contract: sending back only conclusions, evidence, and a diff summary to the main session, rather than all raw material.

    A typical division of roles:

    Role Responsibility Typical permissions
    Explorer Locate relevant files, map call relationships, summarize the current state Read-only
    Planner Break down the task, assess impact scope, produce a plan and risk points Read-only
    Executor Modify code per the approved plan, run tests Read + write + command execution
    Reviewer Review the diff, flag potential regressions and omissions Read-only

    The main session therefore stays lean: it retains only key decisions, confirmed constraints, and milestone conclusions, no longer occupied by intermediate noise. This is the structural reason such tools are more stable than “single-session approaches” in large repositories. It does not rely on a bigger window to brute-force the problem; it maintains judgment through a cleaner information flow.


    5. Layer Four: A Verification Loop, from “Generation” to “Deliverable”

    The endpoint of generation should not be “looks correct” but “verified as correct.” A complete verification loop usually has multiple layers, with increasing cost and increasing confidence:

    1. Static checks: formatting, static analysis, type checking. Lowest cost, run first;
    2. Unit tests: fast regression for the changed modules;
    3. Integration and end-to-end verification: confirming cross-module behavior and interface contracts are not broken;
    4. Build artifact validation: confirming packaging, dependency, and configuration changes introduce no hidden failures;
    5. Human review: the final gate for semantic correctness, architectural soundness, and business fit.

    The key to making the loop work is having the agent treat a “failure log” as new input rather than an endpoint. An actionable loop termination condition:

    1. static checks pass
    2. AND all relevant tests pass
    3. AND the diff set contains only expected files
    4. AND human review has approved

    Two engineering points also matter. First, evidence first: conclusions should be traceable to specific commands and output, not the model’s self-report. Second, failures must be attributable: when verification fails, it should be possible to distinguish a misunderstanding of the requirement, a missed change, or a problem in the environment itself.


    6. Cloud Deployment and the Baidu AI Cloud Perspective

    Moving a repository-level agent from a single-machine trial to routine team usage raises a set of common engineering problems that usually need to be solved at the cloud infrastructure level:

    • Isolation and elasticity: assign an independent sandbox and on-demand compute to each task to avoid interference;
    • Key and credential governance: unify identity authentication and least-privilege authorization to avoid scattered credentials;
    • Observability: use logging services and monitoring/alerting to record task traces, duration, and failure rates;
    • Artifact and version management: persist code snapshots, diff sets, and test reports via object storage and similar means;
    • Task orchestration and concurrency: container platforms host execution environments, while message queues and task queues handle scheduling and peak shaving;
    • Cost control: aggregate usage and manage quotas for model calls, compute, and storage.

    In related practice at Baidu AI Cloud, such capabilities are typically provided as combinations of general cloud services: compute and containerization host the execution environment, object storage keeps build and test artifacts, logging and monitoring services provide full-chain observability, and the identity and permission system ensures least privilege is actually enforced. For development teams, the value is not replacing a specific coding assistant but turning “agents participating in development” from an individual skill into governable, auditable, and reusable organizational capability.


    7. Limitations and Selection Advice

    Staying objective matters just as much. Repository-level agents still have clear capability boundaries:

    • For cross-system changes with sparse test coverage, verification signals are insufficient and risk is high;
    • For legacy repositories dense with implicit conventions, the cost of understanding is far higher than for a new project;
    • There is a tendency toward overconfident modification, which must be backstopped by permissions and review;
    • The cost and latency of long tasks cannot be ignored and require quota and priority management.

    Three pragmatic recommendations for teams:

    1. Start with small, low-risk tasks, such as adding tests, fixing documentation, or doing local refactors, to build trust and process first;
    2. Design permissions and review up front, rather than tightening them after something goes wrong;
    3. Invest in the verification system first; test coverage and automated check capability directly determine the usable proportion of agent output.

    8. Conclusion

    Back to the original question: the “technical principle” of these tools is not mysterious. It is not a single breakthrough but a combination of four engineering constraints:

    A continuously running main loop + a clear set of permission boundaries + a context-isolation division-of-labor mechanism + a verification loop that ends in verification.

    What really separates the strong from the weak is not the model’s generation ability but whether this system of constraints is taken seriously. Understanding this has more long-term value than memorizing the operational details of any tool: the threshold for AI entering the engineering workflow has never been “whether it can produce code,” but “whether it can deliver a verifiable result within boundaries.”