BitFun is an AI agent-driven programming environment built with Rust and TypeScript, using multi-platform architecture (Desktop/CLI/Server) sharing a common core library.
- src/crates/events - Event definitions (platform-agnostic)
- src/crates/core - Core business logic (95%+ code reuse)
agentic/- Agent system (session, tools, execution)service/- Workspace, Config, FileSystem, Terminal, Gitinfrastructure/- AI client, storage, logging, events
- src/crates/transport - Transport adapters (CLI, Tauri, WebSocket)
- src/crates/api-layer - Platform-agnostic handlers
- src/apps/desktop - Tauri 2.0 desktop app
- src/apps/cli - Terminal UI(WIP)
- src/apps/server - Web server (Axum + WebSocket)(WIP)
- src/web-ui - React frontend
infrastructure/- Theme, I18n, Config, State management, API adapterscomponent-library/- Shared UI componentstools/- Feature modules (editor, git, terminal, mermaid...)flow_chat/- Chat UIlocales/- Translation files (en-US, zh-CN)
- Dependency Injection - Services receive dependencies via constructors
- EventEmitter Pattern - Use
Arc<dyn EventEmitter>notAppHandle - TransportAdapter Pattern - Abstract communication across platforms
- Platform Agnostic Core - No platform-specific dependencies in core
- Backend: Rust 2021, Tokio, Tauri 2.0, Axum
- Frontend: React 18, TypeScript, Vite, Zustand
# Desktop
pnpm run desktop:dev # Dev mode
# E2E
pnpm run e2e:testRules: English only, no emojis, structured data, avoid verbose logging
- Frontend:
src/web-ui/LOGGING.md- UsecreateLogger('ModuleName') - Backend:
src/crates/LOGGING.md- Uselog::{info, debug, ...}macros
Never use platform-specific APIs in core code:
- ❌
use tauri::AppHandle - ✅
use bitfun_events::EventEmitter
Naming: Commands snake_case, Rust snake_case, TypeScript camelCase
Always use structured request format:
#[tauri::command]
pub async fn your_command(
state: State<'_, AppState>,
request: YourRequest,
) -> Result<YourResponse, String>await api.invoke('your_command', { request: { ... } });When developing frontend features, reuse existing infrastructure:
- Theme:
infrastructure/theme/- useTheme, useThemeToggle - I18n:
infrastructure/i18n/+locales/- useI18n, t() - Components:
component-library/- shared UI components - State: Zustand stores in each module
SessionManager → Session → DialogTurn → ModelRound
ConversationCoordinator- Orchestrates turnsExecutionEngine- Multi-round loopToolPipeline- Tool execution with concurrency
Location: .bitfun/sessions/{session_id}/
Register in agentic/tools/registry.rs:
- Implement
Tooltrait - Define input/output types
- Handle streaming if applicable
In agentic/agents/:
- Create agent file
- Define prompt in
prompts/ - Register in
registry.rs
A local log receiver server is available at scripts/debug-log-server.mjs.
Start the server:
node scripts/debug-log-server.mjs
# Listens on http://127.0.0.1:7469, writes logs to debug-agent.logInstrument code (one-liner fetch):
fetch('http://127.0.0.1:7469/log',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({location:'file.ts:LINE',message:'desc',data:{k:v},timestamp:Date.now()})}).catch(()=>{});Clear logs between runs:
# Via HTTP
curl -X POST http://127.0.0.1:7469/clearLogs are written to debug-agent.log in project root as NDJSON. The agent reads this file directly — no copy-paste needed.