开发环境搭建
搭建 OpenCowork 本地开发环境。
开发环境搭建 / Development Setup
前置要求 / Prerequisites
| 工具 | 版本 | 说明 |
|---|---|---|
| Node.js | 18+ | 推荐使用 LTS 版本 |
| npm | 9+ | 随 Node.js 安装 |
| Git | 任意 | 版本控制 |
克隆与安装 / Clone & Install
git clone https://github.com/AIDotNet/OpenCowork.git
cd OpenCowork
npm install启动开发模式 / Start Dev Mode
npm run dev这会同时启动:
- Electron 主进程
- Vite 开发服务器(渲染进程,支持 HMR)
项目结构 / Project Structure
OpenCowork/
├── src/
│ ├── main/ # Electron 主进程
│ │ ├── index.ts # 入口
│ │ ├── ipc/ # 30+ IPC 处理器
│ │ ├── db/ # SQLite 数据库(DAO + 迁移)
│ │ ├── channels/ # 消息平台插件(8 个平台)
│ │ ├── cron/ # 定时任务调度器
│ │ ├── mcp/ # MCP 服务器管理器
│ │ └── ssh/ # SSH 连接管理
│ ├── preload/ # 预加载桥接脚本
│ ├── renderer/
│ │ └── src/
│ │ ├── lib/ # 核心库(agent / api / tools / preview)
│ │ ├── stores/ # 15+ Zustand stores
│ │ ├── hooks/ # React hooks
│ │ ├── components/ # UI 组件
│ │ └── locales/ # i18n(en/zh 7 个命名空间)
│ └── shared/ # 主进程/渲染进程共享类型
├── resources/
│ └── agents/ # 子代理定义(.md 文件)
├── docs/ # Fumadocs 文档站点
├── electron.vite.config.ts
├── tsconfig.node.json # 主进程 TS 配置
└── tsconfig.web.json # 渲染进程 TS 配置类型检查 / Type Checking
# 检查所有进程
npm run typecheck
# 仅检查主进程
npm run typecheck:node
# 仅检查渲染进程
npm run typecheck:web代码规范 / Code Style
# Lint 检查
npm run lint
# 格式化
npm run format路径别名 / Path Aliases
渲染进程使用 @renderer/* 别名:
// 等价于 src/renderer/src/lib/agent/agent-loop.ts
import { runAgentLoop } from '@renderer/lib/agent/agent-loop'配置在 tsconfig.web.json 和 electron.vite.config.ts 中。