PostHog 开发的 Agentic Development Environment,通过 AI 代理自动化产品工程师日常任务,支持云-本地混合执行。项目基于 ACP 协议,提供 Claude/Codex 适配器,具备会话恢复和堆叠 PR 管理能力。
项目定位#
Twig 是 PostHog 开发的 Agentic Development Environment,旨在通过 AI 代理将产品工程师从日常干扰中解放出来,专注于构建核心功能。项目目前处于 pre-alpha 阶段,官方明确标注 "not production-ready"。
核心组件#
| 组件 | 类型 | 描述 |
|---|---|---|
| Twig Desktop | Electron 桌面应用 | PostHog 桌面任务管理器,React + Vite 构建 |
| Mobile App | React Native 应用 | 移动端支持(Expo 框架) |
| CLI | 命令行工具 | 基于 Jujutsu 的堆叠 PR 管理 |
| @posthog/agent | TypeScript SDK | 代理框架,支持 Claude/Codex 适配器 |
代理框架能力#
- ACP 协议支持: 基于 Agent Client Protocol 标准化代理-客户端通信
- 多适配器: Claude(进程内实现)、Codex(子进程 stdin/stdout)
- 权限模式: Always ask(默认)/ Accept edits / Plan mode / Bypass permissions
- 执行环境: 云端沙箱 + 本地进程内双模式
- 会话恢复: SessionLogWriter + ResumeSaga 原子操作与自动回滚
- 树状态追踪: TreeTracker 捕获 git worktree 快照,支持云↔本地切换
架构设计#
Main Process (Node.js) Renderer Process (React)
┌───────────────────────┐ ┌───────────────────────────┐
│ DI Container │ │ DI Container │
│ ├── GitService │◄─tRPC──►│ ├── TRPCClient │
│ └── ... │ (ipc) │ └── TaskService, ... │
├───────────────────────┤ ├───────────────────────────┤
│ System I/O │ │ Zustand Stores (state) │
│ (fs, git, shell) │ │ │
└───────────────────────┘ └───────────────────────────┘
技术选型: Electron + React + TypeScript (98.3%) + Tailwind CSS + Zustand + Vite + InversifyJS + tRPC + Zod
安装部署#
前置条件: Node.js 22+, pnpm 10.23.0
npm install -g pnpm
pnpm install
cp .env.example .env
pnpm dev # 并行运行代理和 twig 应用
Agent SDK 使用#
import { Agent } from "@posthog/agent/agent"
const agent = new Agent({
posthog: {
apiUrl: "https://app.posthog.com",
getApiKey: () => process.env.POSTHOG_PERSONAL_API_KEY!,
projectId: 12345,
},
})
const connection = await agent.run(taskId, runId, {
repositoryPath: "/path/to/repo",
adapter: "claude", // 或 "codex"
})
关键配置#
环境变量: POSTHOG_API_KEY, POSTHOG_API_HOST, POSTHOG_PERSONAL_API_KEY, POSTHOG_PROJECT_ID, JWT_PUBLIC_KEY
工作区配置 (twig.json):
{
"scripts": {
"init": "npm install",
"start": ["npm run server", "npm run client"],
"destroy": "docker-compose down"
}
}
项目活跃度#
- 当前版本: v0.27.15
- 发布数: 286+ releases
- 贡献者: 18+
- 开发组织: PostHog Inc.
- 联系邮箱: jonathan@posthog.com