Building AI Coding Agents for the Terminal: Scaffolding, Harness, Context Engineering, and Lessons Learned

This paper introduces OPENDEV, an open-source, terminal-native AI coding agent that ensures secure and efficient autonomous software engineering through a compound architecture featuring specialized model routing, a dual-agent planning-execution separation, adaptive context compaction, and an automated memory system to counteract instruction fade-out.

Nghi D. Q. Bui

Published 2026-03-06
📖 6 min read🧠 Deep dive

Imagine you have a brilliant, hyper-intelligent assistant who knows how to code better than anyone else. But there's a catch: this assistant has a very short attention span (a "limited memory"), gets easily distracted, and if you let them loose on your computer without supervision, they might accidentally delete your entire hard drive.

OPENDEV is a new, open-source project designed to solve these problems. It's a "terminal-native" AI agent, meaning it lives in your command line (the black screen where developers type commands) rather than inside a fancy visual editor.

Here is the story of how OPENDEV works, explained through simple analogies.

1. The Problem: The "Amnesiac" Genius

Most AI coding tools today are like a genius student who can solve a math problem instantly but forgets the first step of the problem by the time they reach the tenth step. If you ask them to build a complex app, they might start well, but after 20 steps, they forget what the goal was, get confused by the massive amount of text they've read, or accidentally run a command that deletes your files.

OPENDEV was built to fix three main issues:

  • Memory: It can't remember everything forever.
  • Safety: It can't be trusted to do anything without a safety net.
  • Focus: It tends to rush into action instead of thinking.

2. The Solution: The "Swiss Army Knife" Factory

Instead of relying on one giant brain to do everything, OPENDEV is built like a well-organized factory with different specialized workers.

The "Scaffolding" (The Blueprint)

Before the AI even sees your first question, the system builds a custom team for you. It's like a construction site manager who sets up the tools, hires the right specialists, and draws the safety lines before the work starts.

  • The Main Agent: The project manager.
  • The Sub-Agents: Specialized workers. One is a "Code Explorer" (just looks at code, never touches it), another is a "Planner" (draws the blueprint), and another is a "Security Reviewer."
  • The Magic: If you need a web developer, the system hires a web specialist. If you need a database expert, it hires that person. They all speak the same language but have different toolkits.

The "Harness" (The Safety Harness)

Once the team is built, the "Harness" takes over. This is the runtime system that keeps everything running smoothly and safely.

  • The "Thinking" Phase: Before the AI is allowed to touch your code, it is forced to take a "thinking break." It's like a chef who must write down the recipe and check the ingredients before turning on the stove. This prevents the AI from rushing and making mistakes.
  • The "Self-Critique" Phase: After thinking, the AI asks itself, "Did I miss anything?" It's like a second pair of eyes reviewing the plan before execution.

3. The "Memory" Problem: The Filing Cabinet vs. The Trash Can

The biggest challenge for AI is that its "context window" (its working memory) is limited. Imagine trying to read a 500-page book, but you can only hold 5 pages in your hands at a time. As you read, you have to put pages down.

OPENDEV uses a clever system called Adaptive Context Compaction:

  • The "Faded" Files: When the AI reads a file 20 minutes ago, the system doesn't throw it away. Instead, it replaces the full text with a tiny note: "Read 'database.py' earlier. It had 50 lines. We discussed the login function." This saves space.
  • The "Scratch Pad": If a command produces a huge log (like 10,000 lines of error messages), the AI doesn't stuff all of it into its memory. It writes the full log to a temporary file on your hard drive and just keeps a note saying, "The log is saved in file X. Read it if you need details."
  • The "Reminders": As the conversation gets long, the AI starts to forget the rules (like "always run tests after editing"). OPENDEV acts like a helpful coach who whispers, "Hey, don't forget to run the tests!" right at the moment the AI is about to move on.

4. The Safety Net: The "Five-Layer" Castle

Since the AI can run commands that delete files, OPENDEV doesn't just say "Please be nice." It builds a fortress with five layers of defense:

  1. The Rulebook (Prompt): The AI is told, "You are a helpful assistant, not a hacker."
  2. The Tool Chest (Schema): The AI is literally not given the keys to dangerous tools unless it's in "Plan Mode." If the tool doesn't exist in its list, it can't use it.
  3. The Gatekeeper (Approval): For dangerous actions (like deleting a file), the system stops and asks you: "Are you sure?"
  4. The Inspector (Validation): Before a command runs, the system checks, "Is this command trying to delete the whole hard drive? If yes, block it."
  5. The Undo Button (Persistence): If the AI makes a mistake, you can hit "Undo," and the system uses a hidden "time machine" (a shadow git repository) to restore your files exactly how they were before.

5. The "Lazy" Discovery

Imagine you have a library with 10,000 books. If you ask the AI to "read the library," it would take forever and waste time.
OPENDEV is lazy in a good way. It doesn't load all 10,000 books into its brain at startup. It only loads the "Table of Contents." When you ask, "How do I connect to a database?", then it goes and fetches the specific "Database" book. This keeps the AI fast and focused.

The Big Picture

OPENDEV is a blueprint for how to build AI that is safe, smart, and actually useful for real-world software engineering.

Instead of a "magic black box" that sometimes works and sometimes deletes your data, OPENDEV is a structured, transparent, and safe environment. It treats the AI like a brilliant but clumsy intern:

  • Give them a clear plan.
  • Let them think before they act.
  • Give them specialized tools.
  • Watch them closely with safety nets.
  • And always, always have an "Undo" button ready.

It's not just about writing code; it's about building a system where humans and AI can work together without the AI accidentally burning down the house.

Get papers like this in your inbox

Personalized daily or weekly digests matching your interests. Gists or technical summaries, in your language.

Try Digest →