This directory contains comprehensive analysis of the AIWB codebase architecture, context management, and task distribution systems.
Start here based on your needs:
→ Read: ARCHITECTURE_ANALYSIS.md
- System overview and design
- Agent/model configuration
- Context management details
- Current limitations
- Performance characteristics
- Recommended improvements
→ Read: CONTEXT_FLOW_DIAGRAM.md
- Complete context processing pipeline (ASCII diagram)
- Memory model in Bash
- Performance characteristics by file size
- What's missing (caching, smart selection)
- Token estimation accuracy
→ Read: CODE_MAP.md
- All 8 core files with purposes
- Function listings by module
- Key code patterns and examples
- Configuration file formats
- Workspace structure
- Dependencies and requirements
→ Read: CONTEXT_LIMITATION_SOLUTION_ANALYSIS.md
- Complete analysis of context limitation solutions
- RAG (Retrieval-Augmented Generation) architecture
- Map-Reduce parallel processing
- Hierarchical summarization strategies
- Cost-benefit analysis for 100K+ LOC projects
- Implementation roadmap for AIWB v2.1+
→ Read: QUICK_START_RAG.md
- 5-minute implementation guide
- Step-by-step setup instructions
- Performance benchmarks
- Cost comparisons
- Example workflows
→ Read: TERMUX_MOBILE_STRATEGY.md
- Mobile-optimized approach (Hierarchical + SQLite)
- Why RAG is too heavy for mobile
- Battery-friendly indexing strategy
- Storage and performance comparisons
- Lightweight alternatives
→ Read: SWARM_MODE_USER_GUIDE.md
- Complete user guide with examples
- How to enable and configure swarm mode
- Cost comparisons and performance expectations
- Troubleshooting and best practices
- Real-world usage examples
→ Read: SWARM_MODE_IMPLEMENTATION.md
- Technical implementation design
- Menu structure and integration
- Code examples and patterns
- Implementation timeline
| Document | Size | Sections | Best For |
|---|---|---|---|
| ARCHITECTURE_ANALYSIS.md | 17 KB | 11 | Deep technical understanding |
| CONTEXT_FLOW_DIAGRAM.md | 18 KB | 6 | Visual learners, process flows |
| CODE_MAP.md | 16 KB | 12 | Code navigation, reference |
| CONTEXT_LIMITATION_SOLUTION_ANALYSIS.md | 64 KB | 9 | Scaling to 100K+ LOC codebases |
| QUICK_START_RAG.md | 8 KB | 8 | Quick RAG implementation |
| TERMUX_MOBILE_STRATEGY.md | 18 KB | 9 | Mobile/Termux optimization |
| SWARM_MODE_USER_GUIDE.md | 24 KB | 14 | Using swarm mode |
| SWARM_MODE_IMPLEMENTATION.md | 32 KB | 9 | Implementing swarm mode |
Total: 198 KB, 4,500+ lines of analysis
- 6,209 lines of Bash
- 6 main libraries + 1 entry point
- Modular design - excellent separation of concerns
- 6 AI providers - Gemini, Claude, OpenAI, Groq, xAI, Ollama
- Basic: Reads files into Bash variables
- No caching: Resends context every request
- No optimization: Takes first 5 files, head -20 lines
- Naive token estimation: 1 token ≈ 4 characters
- NONE: Completely sequential
- Single-threaded: All API calls block
- No task queues: Memory-only state
- Generator-Verifier: Sequential (not parallel)
- Small projects (< 1MB): Fast, works well
- Medium projects (1-100MB): Slow, may hit limits
- Large projects (> 100MB): Likely to fail
- Bottleneck: Bash variable size (~256KB limit)
- No intelligent context selection
- No parallel processing
- No caching or deduplication
- No automatic context compression
- Basic token counting (off by ~20%)
Q: How does context get assembled and sent to APIs? A: See CONTEXT_FLOW_DIAGRAM.md - Complete pipeline diagram shows the exact process.
Q: What are the scalability limitations? A: See ARCHITECTURE_ANALYSIS.md Section 4 - Hard limits, soft limits, and missing features.
Q: How does the code organize task distribution? A: See ARCHITECTURE_ANALYSIS.md Section 3 - It doesn't! Everything is sequential.
Q: Where should I look to understand context management? A: See lib/modes.sh lines 750-838 (mode_run function) - This is where the magic happens.
Q: Can I run parallel API calls? A: No - See Section 3.1. The roadmap (Phase 4) plans to add this in v3.0.
Q: How are large codebases handled? A: Poorly - See Section 4.2. Only first 5 files are scanned, only head -20 lines used.
| What | File | Lines | Function |
|---|---|---|---|
| Context assembly | lib/modes.sh | 750-838 | mode_run() |
| API dispatch | lib/api.sh | 1086-1135 | call_api() |
| Configuration | lib/config.sh | 176-212 | config_get/set |
| UI menus | lib/modes.sh | 92-420 | menu_* |
| Provider: Gemini | lib/api.sh | 199-312 | call_gemini() |
| Provider: Claude | lib/api.sh | 433-597 | call_claude() |
| Token estimation | lib/api.sh | 178-193 | estimate_tokens() |
| Cost calculation | lib/api.sh | 1198+ | calculate_cost() |
- Main executable:
/aiwb(1,886 lines) - Mode workflows:
lib/modes.sh(1,146 lines) - API integrations:
lib/api.sh(1,304 lines) - Configuration:
lib/config.sh(320 lines)
How AIWB compares to similar systems:
| Feature | AIWB | Claude Code | LangChain | LlamaIndex |
|---|---|---|---|---|
| CLI First | ✓ | ✓ | ✗ | ✗ |
| Multi-Provider | ✓ | Limited | ✓ | ✓ |
| Context Mgmt | Basic | Advanced | Advanced | RAG |
| Parallel Tasks | ✗ | ✗ | ✓ | Limited |
| Cost Tracking | ✓ | ✓ | ✗ | ✗ |
| Local Models | ✓ | ✗ | ✓ | ✓ |
| Lines of Code | 6.2K | Proprietary | 100K+ | 50K+ |
AIWB is smaller, simpler, CLI-focused, but limited in scalability.
- Smart Context Selection - Replace naive file picking with semantic relevance
- Caching Layer - Store and reuse context embeddings
- Context Compression - Summarize large files automatically
- Parallel Processing - Background cost estimation, parallel verification
- Better Token Management - Integrate real tokenizers, automatic truncation
- Task Queuing - Move to persistent task system (not memory-only)
- Distributed Execution - Support remote/cloud execution
- Advanced Workflows - Autonomous refinement loops
- Editor Integration - VS Code, Vim, Emacs plugins
I performed a comprehensive codebase analysis by:
-
Mapping the structure
- Listed all files (8 main files, 6,209 total lines)
- Identified modules and their purposes
- Created call graphs and dependencies
-
Understanding context flow
- Traced prompt assembly from user input to API call
- Identified context building algorithm
- Found all limitations and bottlenecks
-
Analyzing task distribution
- Checked for parallel processing (found none)
- Examined workflow execution model (sequential)
- Reviewed generator-verifier pattern (two sequential calls)
-
Documenting architecture
- Created 3 comprehensive analysis documents
- Included code examples and diagrams
- Added comparison tables and recommendations
-
Search for specific topics
# In your editor or grep grep -n "context" ARCHITECTURE_ANALYSIS.md grep -n "parallel" CONTEXT_FLOW_DIAGRAM.md grep -n "lib/modes.sh" CODE_MAP.md
-
Cross-reference
- Documents reference each other
- Look for "See: [Document] Section X"
- Follow to get deeper details
-
Focus on your area
- Architecture? → Start with Section 1 of ARCHITECTURE_ANALYSIS.md
- Context? → Full pipeline in CONTEXT_FLOW_DIAGRAM.md
- Code? → Find files in CODE_MAP.md
The key insight is that AIWB is designed for small-to-medium projects:
- ✓ Works great for: < 50 files, < 10 MB context
- ⚠ Struggles with: 50-500 files, 10-100 MB context
- ✗ Fails on: > 500 files, > 100 MB context
This is by design - it's a CLI tool prioritizing simplicity over scalability.
The roadmap (Phases 3-5) shows plans to address these limitations.
If you're planning to contribute, I recommend:
- Read ARCHITECTURE_ANALYSIS.md for overall design
- Check CODE_MAP.md to find where to make changes
- Study the relevant code section in detail
- Follow the patterns in CODE_MAP.md Section "Important Code Patterns"
The codebase is very well-documented and easy to modify thanks to its modular design.
These documents answer the most common questions about AIWB architecture, context management, and capabilities. If you need more details:
- For code specifics: Reference the actual files in
/home/user/AIworkbench/ - For design rationale: Read
docs/OVERVIEW.mdandDEVELOPER_GUIDE.md - For roadmap: See
docs/ROADMAP.md - For usage: See
docs/USAGE.mdandQUICKSTART.md
Created: November 10, 2025
By: Codebase Analysis Agent
Status: Complete & verified
All three documents are ready for immediate use!