How ducan-ne/opencoder works
Project type and purpose
• OpenCoder is a single-package, terminal-based coding assistant that combines a React UI shell with an AI-driven core and a plugin system for “tools” (file I/O, grep, diagnostics, MCP like Playwright, web search).
• It’s distributed as an NPM/Bun CLI (npx opencoder), uses Vite for bundling, Vitest for tests, and the Vercel AI SDK for LLM integration.
File structure
• Top-level:
• package.json, tsconfig.json, vite.config.ts, vitest.config.ts → build & test configuration
• scripts/ → codegen & patch scripts
• public/assets (yoga.wasm) → WASM runtime for tree-sitter
• examples/ → usage examples showing custom tools & MCP setups
• src/ → main application code subdivided into:
– app/ + components/ → React UI and context
– core.tsx, app.tsx, main.tsx, mcp.tsx → bootstrapping & orchestration
– lib/ → utilities (storage, prompts, diff, logger, config, typescript diagnostics, etc.)
– tools/ → built-in and shared tools; tool registry
• test/ → Vitest suites for UI snapshots, chat flows, utils, tool confirmation
README insights
• Built on Vercel AI SDK (pluggable providers)
• Cross-platform shell via Deno
• High-FPS UI with React concurrent rendering
• Plugin system for MCP and custom tools
Main components
a. CLI/Runner Layer
• Entrypoint (src/main.tsx, src/app.tsx)
• Shell abstraction (Deno-backed cross-platform shell)
b. UI Layer
• React components (src/app/, src/components/)
• WASM asset loader (public/assets/yoga.wasm)
c. Core Logic & State
• Chat orchestration (src/core.tsx, src/app/chat.tsx)
• Context & store (src/app/context.tsx, src/lib/store/)
• Prompts & config (src/lib/prompts.ts, bump.config.ts)
d. AI SDK Integration
• Vercel AI SDK adapter (bundled under src/bundled/)
• Model providers (OpenAI, Anthropic, Ollama, etc.)
e. Tool Abstraction & Plugin System
• Tool registry & loader (src/tools/tools.ts)
• Built-in tools (read/write/edit files, grep, diagnostics)
• MCP tools (Playwright, web-search via src/mcp.tsx)
f. OS / External Services
• File system & process access (native Node/Bun + Deno shell)
• Network calls (LLM endpoints, auto-updater checks)
• Persistent storage (chat history via src/lib/storage.ts)
g. Build & Test Infrastructure
• Vite (bundling), Vitest (unit/UI tests), scripts for types & import rewriting
Relationships & interactions
• User types input → React UI component → dispatches to Core
• Core builds AI SDK request → Vercel AI SDK → external LLM → response
• Core inspects response for tool calls → invokes Tool modules → Tools interact with FS or external APIs → returns result to Core
• Core updates chat history (in-memory + persistent store) → UI re-renders updated chat
• Auto-updater component polls NPM registry for updates
• Examples folder is not part of runtime but illustrates extension points
Architectural patterns & technologies
• Plugin/Registry pattern for tools & MCP extensions
• Component-driven UI with React concurrent rendering
• Separation of concerns: UI vs Core vs Tools vs AI adapter vs OS boundary
• Dependency injection via user config (model provider, tool list)
• High performance via WASM (tree-sitter) and React Compiler
Elements
• Core & State (green rectangles)
• Tools & Plugins (orange)
• AI Providers (purple cloud)
• Annotations for key frameworks (React, Vite, Vitest, Deno shell)