开发指南
开发环境搭建
搭建 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/ # IPC 处理器
│ │ ├── db/ # SQLite 数据库
│ │ ├── plugins/ # 消息平台插件
│ │ ├── cron/ # 定时任务
│ │ └── mcp/ # MCP 服务器
│ ├── preload/ # 预加载脚本
│ └── renderer/
│ └── src/
│ ├── lib/ # 核心库(agent、api、tools、preview)
│ ├── stores/ # Zustand stores
│ ├── hooks/ # React hooks
│ ├── components/ # UI 组件
│ └── locales/ # i18n 翻译文件
├── resources/
│ └── agents/ # 子代理定义(.md 文件)
├── electron.vite.config.ts
├── tsconfig.node.json # 主进程 TypeScript 配置
└── tsconfig.web.json # 渲染进程 TypeScript 配置类型检查 / 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 中。