ADR-018-v4: CODI Dynamic Command Architecture - Part 1 (Narrative)
Document Specification Blockβ
Document: ADR-018-v4-codi-dynamic-command-architecture-part1-narrative
Version: 1.0.0
Purpose: Explain CODITECT's dynamic command loading architecture for business and technical stakeholders
Audience: Business leaders, developers, architects, DevOps engineers
Date Created: 2025-09-01
Date Modified: 2025-09-01
QA Review Date: Pending
Status: DRAFT
Table of Contentsβ
- Introduction
- Context and Problem Statement
- 2.1 The Challenge
- 2.2 Current State
- 2.3 Business Impact
- Decision
- 3.1 Core Concept
- 3.2 How It Works
- 3.3 Architecture Overview
- Key Capabilities
- 4.1 Dynamic Loading
- 4.2 Cross-Platform Support
- 4.3 Offline Operation
- 4.4 Command Extensibility
- Benefits
- 5.1 For Organizations
- 5.2 For Developers
- 5.3 For Operations
- Analogies and Examples
- Risks and Mitigations
- 7.1 Network Dependency
- 7.2 Cache Management
- 7.3 Security Concerns
- Success Criteria
- Related Standards
- References
- Conclusion
- Approval Signatures
1. Introductionβ
1.1 For Business Leadersβ
Imagine software that starts with just the essentialsβlike a Swiss Army knife with only a blade and corkscrewβbut can instantly grow new tools when you need them. That's CODI v2: a lightweight command-line tool that downloads exactly what you need, when you need it, rather than carrying around a heavy toolbox everywhere.
This transformation delivers remarkable results: 97.5% reduction in infrastructure costs (from $1000/month to $25/month), 80% smaller download size (25MB to 5MB), and instant access to unlimited features without reinstalling software.
Think of it as the difference between carrying a 100-pound toolbox versus having a smart device that can materialize any tool on demand. Your teams work faster, your costs plummet, and you can add new capabilities without disrupting users.
1.2 For Technical Leadersβ
CODI v2 transforms from a monolithic 25MB binary containing 100+ built-in commands to a lean 5MB core runtime with 8-10 essential commands. Additional functionality loads dynamically as JSON-defined command libraries with optional WebAssembly modules, cached locally using SQLite with environment-specific persistence strategies.
The architecture supports identical operation across Cloud Run containers, browser WebAssembly environments, and local development machines. Commands load in under 250ms on first use and execute from cache in under 105ms subsequently. Multi-environment storage abstraction ensures command libraries persist appropriately: GCS FUSE mounts for Cloud Run, IndexedDB for browsers, and local filesystem for development.
This approach eliminates the need for persistent containers, enables per-tenant command customization, and allows instant feature deployment without binary redistribution.
2. Context and Problem Statementβ
2.1 The Challengeβ
Modern CLI tools face critical scalability challenges:
- Binary Bloat: Tools grow to 15-25MB as features accumulate
- Slow Startup: Loading 100+ commands impacts user experience
- Update Friction: Any change requires rebuilding and redistributing binaries
- Wasted Resources: Users carry commands they never use
- Container Costs: Persistent containers needed just to preserve state
- Limited Extensibility: Adding features requires core changes
Additional complexities include:
- Multi-Platform Support: Different storage models for Cloud Run, WASM, local
- Offline Requirements: Must work when disconnected
- Per-Tenant Customization: Enterprise clients need specific commands
- Version Management: Supporting multiple command versions simultaneously
- Security Constraints: Dynamic loading introduces new attack vectors
2.2 Current Stateβ
Most CLI tools suffer from monolithic design:
- Large Downloads: 15-25MB binaries slow initial adoption
- Memory Overhead: Loading unused commands wastes RAM
- Slow Updates: Days or weeks to ship new features
- Platform Lock-in: Separate builds for each environment
- State Loss: Container restarts lose cached data
- Fixed Feature Set: One-size-fits-all approach
This results in:
- Poor user experience with slow startup times
- High infrastructure costs for persistent containers
- Delayed feature delivery and innovation
- Frustrated developers waiting for deployments
- Limited ability to customize per customer
2.3 Business Impactβ
The monolithic approach creates severe business consequences:
Financial Impact:
- Container Costs: $1000/month for 100 persistent containers
- Bandwidth Costs: Repeated 25MB downloads add up
- Development Costs: Slow release cycles increase engineering time
- Opportunity Costs: Competitors ship features faster
Organizational Impact:
- Developer Frustration: Slow tools kill productivity
- Customer Complaints: "Why is this so slow?"
- Limited Innovation: Fear of bloating the binary
- Technical Debt: Accumulating unused commands
3. Decisionβ
3.1 Core Conceptβ
CODI v2 implements a Dynamic Command Architecture that starts minimal and grows on demand. The core binary includes only essential commands (auth, log, config, help, connect, sync, session, mcp) in under 5MB. Additional commands load dynamically as JSON libraries with optional WebAssembly modules.
Core principles:
- Start Small: 5MB binary with 8 built-in commands
- Load on Demand: Fetch commands when first used
- Cache Forever: Store libraries locally for instant reuse
- Work Everywhere: Identical behavior across all platforms
- Stay Secure: Validate and sandbox all dynamic code
3.2 How It Worksβ
The dynamic loading process follows this flow:
Key aspects:
- Transparent Loading: Users don't know if commands are built-in or dynamic
- Smart Caching: Once loaded, commands work offline
- Fast Execution: Cached commands run in <100ms
- Progressive Enhancement: System gets smarter with use
3.3 Architecture Overviewβ
The system consists of several coordinating components:
4. Key Capabilitiesβ
4.1 Dynamic Loadingβ
Commands load transparently on first use:
- Automatic Detection: System knows which commands need loading
- Background Fetch: Downloads happen asynchronously
- Progress Indication: Users see loading status
- Intelligent Caching: Libraries stored based on environment
- Version Management: Supports multiple versions simultaneously
Example: When a user types codi agent list, the system:
- Checks if 'agent' commands are loaded
- Fetches 'agent-ops' library if needed (~25KB)
- Caches it appropriately for the environment
- Executes the command
- Future uses skip steps 2-3
4.2 Cross-Platform Supportβ
Identical functionality across all environments:
Cloud Run Containers:
- Uses GCS FUSE mount at
/var/lib/codi/cache.db - Survives container restarts
- Shared cache across instances
- Zero configuration required
Browser WebAssembly:
- Stores in IndexedDB + SQL.js
- Persists across page refreshes
- Works in all modern browsers
- No server dependency after load
Local Development:
- Standard filesystem storage
- Located at
~/.coditect/codi/cache.db - Fastest performance
- Full offline capability
4.3 Offline Operationβ
Once loaded, commands work without network:
- Persistent Cache: Libraries stored permanently
- Expiry Handling: Optional time-based refresh
- Offline Detection: Graceful degradation
- Sync on Reconnect: Updates when online
- Local-First Design: Network is enhancement, not requirement
This enables:
- Airplane mode development
- Disconnected environments
- Faster response times
- Reduced bandwidth usage
- Better reliability
4.4 Command Extensibilityβ
Easy to add new capabilities:
For Platform Team:
- Create JSON command definitions
- Optional WASM for complex logic
- Deploy instantly without rebuilds
- A/B test new commands
- Per-tenant customization
For Users:
- Install community commands
- Create custom workflows
- Share command libraries
- Version pin for stability
- Mix and match capabilities
For Enterprises:
- Private command libraries
- Custom business logic
- Compliance-specific tools
- Department variations
- Controlled rollout
5. Benefitsβ
5.1 For Organizationsβ
- 97.5% Cost Reduction: From $1000/month to $25/month infrastructure costs
- Instant Feature Delivery: Deploy new commands without user updates
- Customer Customization: Per-tenant command libraries
- Reduced Support Burden: Smaller downloads, faster starts
- Competitive Advantage: Ship features faster than competitors
5.2 For Developersβ
- Fast Tool Startup: 87ms vs 500ms for monolithic version
- Minimal Downloads: 5MB initial, then incremental
- Always Latest Features: Commands update transparently
- Work Offline: Full functionality after initial load
- Custom Commands: Extend with personal libraries
5.3 For Operationsβ
- Lower Bandwidth: 80% reduction in download size
- Simplified Deployment: No binary distribution
- Granular Updates: Change individual commands
- Better Monitoring: Track command usage patterns
- Security Control: Validate each library independently
6. Analogies and Examplesβ
6.1 The Smart Toolbox Analogyβ
Think of traditional CLI tools versus CODI v2:
Traditional CLI = Carrying a Giant Toolbox
- You carry 100+ tools everywhere
- Heavy and slow to move around
- Most tools never get used
- Adding tools makes it heavier
- Everyone gets the same toolbox
CODI v2 = Smart Digital Assistant
- Starts with just essentials
- "Need a hammer? Here it is!" (downloads on demand)
- Remembers tools you've used
- Works even offline (from memory)
- Each person gets exactly what they need
Just as smartphones replaced carrying cameras, GPS devices, music players, and calculators, CODI v2 replaces monolithic CLI tools with intelligent, on-demand functionality.
6.2 Real-World Scenarioβ
StartupCo's CODI Migration Story:
Before CODI v2:
- 50 developers downloading 25MB CLI weekly
- $1000/month for persistent containers
- 3-week cycle to add new commands
- Developers complaining about slow starts
- IT worried about bandwidth costs
Migration to CODI v2:
- Week 1: Deployed 5MB core binary
- Week 2: Developers amazed by instant startup
- Week 3: Added 5 new AI commands without updates
- Month 1: Costs dropped to $25/month
- Month 2: Custom commands for each team
Results:
- 97.5% infrastructure cost reduction
- 10x faster feature deployment
- 95% developer satisfaction score
- Zero downtime during migration
- Unlimited command additions
7. Risks and Mitigationsβ
7.1 Network Dependencyβ
- Risk: First use requires network connection
- Mitigation:
- Preload common libraries during install
- Bundle critical libraries with binary
- Graceful offline messages
- Regional CDN distribution
- Retry with exponential backoff
7.2 Cache Managementβ
- Risk: Cache corruption or excessive growth
- Mitigation:
- SHA256 integrity checks
- LRU eviction at 50 libraries
- One-command cache rebuild
- Automatic cleanup of old versions
- Storage quotas per environment
7.3 Security Concernsβ
- Risk: Malicious command libraries
- Mitigation:
- Digital signatures on all libraries
- Permission sandboxing
- WASM isolation
- Audit logging
- Secure transport (TLS 1.3)
8. Success Criteriaβ
8.1 Performance Metricsβ
- Binary Size: <5MB core executable
- Startup Time: <100ms to interactive prompt
- First Load: <250ms to load new library
- Cached Execution: <105ms for cached commands
- Memory Usage: <30MB idle, <80MB with 10 libraries
8.2 Business Metricsβ
- Cost Reduction: >95% infrastructure savings
- Deployment Speed: <5 minutes for new commands
- User Adoption: >80% prefer dynamic version
- Support Tickets: <50% reduction in performance complaints
- Feature Velocity: 10x faster command deployment
8.3 Test Coverage Requirementsβ
All components must meet quality standards:
- Unit Test Coverage: β₯95% of loading logic
- Integration Test Coverage: β₯90% of storage backends
- End-to-End Test Coverage: All platforms tested
- Performance Tests: Load time benchmarks
- Security Tests: Signature validation, sandbox escape attempts
8.4 User-Friendly Error Messagesβ
Clear communication when issues occur:
- Network Error: "Unable to download 'agent-ops' commands. Please check your internet connection or try again later. (Offline mode available for previously loaded commands)"
- Cache Full: "Command cache is full. Run 'codi cache clean' to remove unused commands, or increase cache size in settings."
- Version Conflict: "Command 'agent list' requires newer version. Update available - install now? [Y/n]"
- Permission Denied: "Command 'deploy production' requires admin permissions. Contact your administrator or use 'codi auth elevate'."
8.5 Logging Requirementsβ
Comprehensive logging for debugging and analytics:
- Load Events: Library fetch, cache hit/miss, load time
- Execution Metrics: Command run, duration, success/failure
- Cache Operations: Store, retrieve, evict, corrupt
- Network Activity: Requests, failures, retries
- Security Events: Validation, permission checks, violations
Example log entry:
{
"timestamp": "2025-09-01T10:30:45.123Z",
"event_type": "library_load",
"library": "prompt-engineering",
"version": "1.0.0",
"cache_hit": false,
"load_time_ms": 187,
"size_bytes": 24576,
"storage_type": "gcs_mount",
"user_id": "user123",
"session_id": "sess456"
}
8.6 Error Handling Patternsβ
Graceful degradation throughout:
- Network Failures: Fall back to cached commands
- Corrupted Cache: Automatic rebuild from server
- Version Mismatches: Offer upgrade or use compatible version
- Permission Errors: Clear explanation and resolution steps
- Storage Failures: Temporary in-memory operation
Error recovery flow:
- Detect error condition
- Log detailed context
- Attempt automatic recovery
- Provide user-friendly message
- Offer manual resolution
- Continue with degraded functionality
- Report telemetry for improvement
9. Related Standardsβ
- ADR-009-v4: CODI Command Interface - Core command structure
- ADR-016-v4: CODI Rust Implementation - Implementation details
- ADR-001-v4: Container Execution - Runtime environments
- ADR-002-v4: Storage Architecture - Persistence patterns
- LOGGING-STANDARD-v4 - Logging requirements
10. Referencesβ
- WebAssembly System Interface (WASI) - WASM runtime standards
- SQLite in the Browser - Browser-based SQL
- Cloud Run Volume Mounts - GCS FUSE documentation
- IndexedDB API - Browser storage
- JSON Schema - Command definition validation
Case Studiesβ
- Deno: Modular runtime with dynamic imports
- VS Code: Extension marketplace model
- Terraform: Provider plugin architecture
11. Conclusionβ
CODI's Dynamic Command Architecture represents a fundamental shift in how CLI tools are built and distributed. By starting small and growing on demand, we achieve the seemingly impossible: a tool that's both lighter and more powerful than traditional alternatives.
The 97.5% cost reduction alone justifies the architectural change, but the real value lies in the enhanced developer experience and unlimited extensibility. Teams can work faster, ship features instantly, and customize per customerβall while reducing operational overhead.
In an era where developer productivity determines business success, CODI v2's intelligent, dynamic approach provides a competitive advantage that compounds over time.
12. Approval Signaturesβ
Document Approvalβ
| Role | Name | Signature | Date |
|---|---|---|---|
| Author | Session5 (Claude) | β | 2025-09-01 |
| Technical Reviewer | Pending | - | - |
| Business Reviewer | Pending | - | - |
| Platform Architect | Pending | - | - |
| Final Approval | Pending | - | - |
Review Historyβ
| Version | Date | Reviewer | Status | Comments |
|---|---|---|---|---|
| 0.9.0 | 2025-08-29 | Original Author | SINGLE-PART | Original combined format |
| 1.0.0 | 2025-09-01 | Session5 | DUAL-PART | Converted to v4 standard format |