This file provides guidance for AI coding agents working with the Anycode codebase.
Anycode is a web-based IDE with a Rust backend and React frontend. It provides code editing, file management, terminal emulation, LSP integration, and AI agent support via the Agent Client Protocol (ACP).
anycode_refactor/
├── anycode/ # React frontend application
├── anycode-base/ # Core editor library (TypeScript, Tree-Sitter)
├── anycode-react/ # React wrapper for the editor
├── anycode-backend/ # Rust backend (Axum, Tokio, Socket.IO)
└── anycode-example/ # Example usage of the editor library
- React 19, TypeScript, Vite
- Tree-Sitter (WASM) for syntax parsing
- Socket.IO for WebSocket communication
- xterm.js for terminal emulation
- Rust with Axum web framework
- Tokio async runtime
- Socket.IO for real-time communication
- LSP integration for language intelligence
- ACP for AI agent integration
pnpm install # Install dependencies
pnpm dev # Start dev server (localhost:5173)
pnpm build # Production buildcargo build --release # Build release binary
cargo run --release # Run the backend server
cargo test # Run testspnpm install # Install dependencies
pnpm build # Build the library
pnpm test # Run testsApp.tsx- Main React component, manages all UI statetypes.ts- TypeScript interfacesagents.ts- AI agent configurationcomponents/agent/- ACP dialog and message components
main.rs- Entry point, server setupapp_state.rs- Shared application statehandlers/io_handler.rs- File I/O operationshandlers/lsp_handler.rs- LSP request handlinghandlers/terminal_handler.rs- Terminal managementhandlers/acp_handler.rs- ACP message handlinglsp.rs- LSP process managementacp.rs- ACP client implementationterminal.rs- PTY management
editor.ts- Main editor classrenderer.ts- Virtual rendering enginecode.ts- Code manipulationactions.ts- Editor actionslangs/- Language configurations
All frontend-backend communication uses Socket.IO WebSockets with event-based messaging:
- File operations:
open_file,save_file,create_file,delete_file - LSP:
lsp_completion,lsp_definition,lsp_hover,lsp_references - Terminal:
create_terminal,terminal_input,resize_terminal - ACP:
acp_start,acp_stop,acp_send,acp_message
- Frontend uses React state with persistence via localStorage
- Backend maintains shared state via
Arc<AppState>with Tokio mutexes
The editor uses a virtual rendering approach for performance:
- Tree-Sitter parses code into AST
- Only visible lines are rendered to DOM
- Scroll events trigger re-render of visible region
- Functional components with hooks
- TypeScript strict mode
- CSS modules for styling
- Standard Rust formatting (
cargo fmt) - Error handling with
anyhowandthiserror - Async/await with Tokio
cd anycode-base && pnpm test # Editor library testscd anycode-backend && cargo test # Rust tests- Define handler in appropriate
handlers/*.rsfile - Register handler in
main.rssocket setup - Add corresponding frontend emit/listener in React components
- Add language server binary/command to
lsp.rs - Add language configuration in
anycode-base/src/langs/ - Map file extension to language ID
- Add agent configuration in
anycode/agents.ts - Ensure ACP compatibility in backend
acp.rs
- The editor is custom-built, not Monaco/CodeMirror - changes require understanding Tree-Sitter and virtual rendering
- WebSocket events are the primary communication method - REST is not used
- The backend serves the frontend in production (files copied to
dist/) - LSP processes are spawned per-language and reused across files