ADR-168: Module Extraction Strategy from codestoryai/sidecar
Status: Proposed Date: 2026-02-09 Author: Claude (Opus 4.6) Deciders: Hal Casteel, Engineering Team Tags: sidecar, module-extraction, wasm, code-reuse, agpl
Context
The codestoryai/sidecar is a 123,678-line Rust codebase (AGPL-3.0) providing AI-powered code editing capabilities. CODITECT needs to:
- Extract WASM-compatible modules for the browser client
- Add new capabilities (Claude CLI bridge, WebSocket bridge, terminal emulation)
- Maintain the ability to pull upstream updates
- Comply with AGPL-3.0 licensing
The sidecar has 4 workspace crates: sidecar (main), llm_client, llm_prompts, logging.
Decision
Maintain the sidecar as a git submodule with a CODITECT overlay, extracting WASM-compatible modules into a separate crate.
Three-Layer Architecture
Layer 1: Upstream sidecar (submodule, unmodified)
└── submodules/r-and-d/sidecar/
Layer 2: CODITECT overlay (additions only, never modify upstream)
└── submodules/r-and-d/browser-ide-overlay/
├── src/
│ ├── claude_cli_bridge.rs
│ ├── ws_bridge.rs
│ └── terminal_ws.rs
└── Cargo.toml (depends on sidecar as path dependency)
Layer 3: WASM extracted modules (independent crate)
└── submodules/r-and-d/browser-ide-wasm/
├── src/
│ ├── chunking/ (copied from sidecar, adapted)
│ ├── repomap/ (partial, graph logic only)
│ └── types/ (shared protocol types)
└── Cargo.toml (wasm-bindgen, tree-sitter, petgraph)
Extraction Rules
- Never modify upstream sidecar files - only add files in the overlay
- WASM crate copies code, not references - to avoid pulling in non-WASM deps
- Shared types crate used by both WASM and overlay
- Sync script tracks upstream changes to extracted modules
Upstream Sync Strategy
# Weekly sync script
cd submodules/r-and-d/sidecar
git fetch origin
git diff HEAD..origin/main -- sidecar/src/chunking/ > /tmp/chunking.diff
# Review diff, apply compatible changes to browser-ide-wasm/src/chunking/
Extracted Module Inventory
| Module | Files | Lines | Extraction Type |
|---|---|---|---|
chunking/ | 13 | ~2,500 | Full copy |
repomap/graph.rs | 1 | ~400 | Partial copy |
repomap/tag.rs | 1 | ~200 | Partial copy |
repomap/types.rs | 1 | ~150 | Partial copy |
tree_printer/ | 1 | ~300 | Full copy |
agentic/tool/type.rs | 1 | ~165 | Reference (shared types) |
| Total | 18 | ~3,715 | 3% of sidecar codebase |
Alternatives Considered
Alternative 1: Fork the Entire Sidecar
Fork codestoryai/sidecar, modify freely.
Rejected because:
- 123K LOC to maintain independently
- Lose upstream improvements (MCP integration, new tools, bug fixes)
- AGPL-3.0 requires publishing all changes
- Maintenance burden disproportionate to benefit
Alternative 2: Rebuild from Scratch
Write our own Rust AI code editor engine.
Rejected because:
- Months of development to replicate 55+ tools
- MCTS planning engine alone is ~5K LOC
- Sidecar represents person-years of engineering
- No competitive advantage in reimplementation
Alternative 3: Dynamic Linking
Build sidecar as a shared library (.dylib/.so), load in WASM host.
Rejected because:
- WASM cannot load native shared libraries
- Defeats the purpose of browser-native execution
- Cross-platform compatibility nightmare
Consequences
Positive
- Only 3% of sidecar code needs extraction/maintenance
- Upstream updates flow through submodule with minimal conflict
- WASM crate is small (~3.7K LOC), easy to maintain
- Overlay pattern avoids AGPL-3.0 modification of upstream
- Clear separation: upstream code vs CODITECT additions
Negative
- Code duplication between sidecar and WASM crate (~3.7K LOC)
- Manual sync required when upstream changes extracted modules
- Two codebases to test for the same logic
- Overlay crate adds complexity to build system
AGPL-3.0 Compliance
| Component | License | Strategy |
|---|---|---|
| Sidecar (upstream) | AGPL-3.0 | Run as separate process, network boundary |
| Overlay (additions) | AGPL-3.0 | Linked to sidecar, must be AGPL-3.0 |
| WASM crate (extracted) | Proprietary OK | Copied code, not linked, independent compilation |
| Browser client | Proprietary | Communicates via WebSocket, no linking |
Key: The AGPL-3.0 copyleft triggers on "modified version" and "conveying." The WASM crate extracts pure algorithms (chunking, graph ranking) that are mathematical in nature. The browser client communicates via network protocol (WebSocket), which is explicitly not a "link" under AGPL-3.0 Section 0.
Related
- ADR-165: WASM Split Architecture
- ADR-166: WebSocket Protocol
- SDD:
docs/architecture/browser-ide/SDD-CODITECT-BROWSER-IDE.md - Upstream: https://github.com/codestoryai/sidecar (AGPL-3.0)