CLI Workflows
Relevant source files
The following files were used as context for generating this wiki page:
CLI Workflows in the DeepCode system represent the automated operational sequences used to transform high-level implementation plans into executable codebases. These workflows leverage a Model Context Protocol (MCP) architecture, where agents generate and execute shell commands to manage file systems, install dependencies, and implement source code. The core logic follows an iterative development cycle that prioritizes structural integrity and dependency-aware implementation.
Sources: workflows/code_implementation_workflow.py:16-35, prompts/code_prompts.py:512-530
Workflow Architecture and Implementation Cycle
The CLI workflow operates through a "Pure Code Implementation Loop." This loop is designed for long-running sessions that manage token limits while ensuring all parts of a research paper or requirement document are reproduced. The system utilizes specialized agents to handle different stages of the CLI lifecycle, including structure generation and code writing.
The Implementation Loop
The implementation process follows a standardized sequence managed by the CodeImplementationWorkflow class. It iterates through a maximum of 100 cycles or until a "completion" keyword is detected in the LLM response.
The diagram shows the iterative nature of the CLI implementation, transitioning from structural setup to repeated file generation and testing.
Sources: workflows/code_implementation_workflow.py:202-240, prompts/code_prompts.py:650-675
Core Components
| Component | Function | Implementation Detail |
|---|---|---|
| StructureGeneratorAgent | Creates the project skeleton. | Generates mkdir -p and touch commands. |
| CodeImplementationAgent | Writes actual logic. | Uses cat > file << EOF for code injection. |
| ConciseMemoryAgent | Manages context window. | Clears conversation history after each file write. |
| MCP Server | Tool execution environment. | Provides execute_bash and execute_python tools. |
Sources: workflows/code_implementation_workflow.py:146-155, workflows/agents/memory_agent_concise.py:25-45, prompts/code_prompts.py:485-500
CLI Tooling and Command Generation
The system relies on generating precise shell commands to interact with the workspace. This is achieved through specific system prompts that enforce production-grade standards and shell-escaping rules.
File Structure Generation
The STRUCTURE_GENERATOR_PROMPT directs the agent to analyze the reproduction plan and output a sequence of shell commands. The workflow creates directories before files and includes __init__.py files for Python packages to ensure the resulting tree is a valid module structure.
mkdir -p project/src/core
mkdir -p project/src/models
touch project/src/__init__.py
touch project/src/core/algorithm.py
Sources: prompts/code_prompts.py:490-508, workflows/codebase_index_workflow.py:100-130
Code Implementation Protocol
For writing code, the CODE_IMPLEMENTATION_PROMPT mandates the use of heredoc syntax. This ensures that complete, executable files are written to the workspace in a single operation, avoiding incremental edits that might lead to corruption.
The sequence shows how code is injected into the workspace using standard CLI redirection.
Sources: prompts/code_prompts.py:515-545, workflows/code_implementation_workflow.py:340-360
Memory and Context Management
A critical aspect of CLI workflows is the "Clean Slate" approach implemented by the ConciseMemoryAgent. Because codebases can grow large, the agent discards previous conversational clutter after every successful write_file operation.
Memory Optimization Strategy
- Preservation: The system prompt and initial reproduction plan are always kept in the context.
- Detection: The system monitors tool calls for
write_file. - Trigger: Once a file is written,
should_clear_memory_nextis set toTrue. - Compression: History is cleared, leaving only the plan, the latest code knowledge base (from
implement_code_summary.md), and the current round's tool results.
Sources: workflows/agents/memory_agent_concise.py:35-60, workflows/agents/memory_agent_concise.py:615-635
Conclusion
CLI Workflows provide a robust mechanism for automated software development by combining multi-agent orchestration with standard shell utilities. By utilizing MCP for tool execution and implementing strict memory management protocols, the system can autonomously build complex projects while maintaining high technical accuracy and token efficiency.
Sources: workflows/code_implementation_workflow.py:530-560, workflows/agents/memory_agent_concise.py:900-920